mirror of https://github.com/ipxe/ipxe.git
[acpi] Expose system MAC address via ${sysmac} setting
Expose the system MAC address (if any) via the ${sysmac} setting. This allows scripts to access the system MAC address even when iPXE has decided not to apply it to a network device (e.g. because the cached DHCPACK MAC address was selected in order to match the behaviour of a previous boot stage). The setting is named ${sysmac} rather than ${acpimac} in order to allow for forward compatibility with non-ACPI mechanisms that may exist in future for specifying a system MAC address. Signed-off-by: Michael Brown <mcb30@ipxe.org>pull/136/head
parent
d72c8fdc90
commit
d3c8944d5c
|
@ -29,6 +29,7 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
|
|||
#include <ipxe/base16.h>
|
||||
#include <ipxe/ethernet.h>
|
||||
#include <ipxe/if_ether.h>
|
||||
#include <ipxe/settings.h>
|
||||
#include <ipxe/acpimac.h>
|
||||
|
||||
/** @file
|
||||
|
@ -249,3 +250,39 @@ int acpi_mac ( uint8_t *hw_addr ) {
|
|||
|
||||
return -ENOENT;
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetch system MAC address setting
|
||||
*
|
||||
* @v data Buffer to fill with setting data
|
||||
* @v len Length of buffer
|
||||
* @ret len Length of setting data, or negative error
|
||||
*/
|
||||
static int sysmac_fetch ( void *data, size_t len ) {
|
||||
uint8_t mac[ETH_ALEN];
|
||||
int rc;
|
||||
|
||||
/* Try fetching ACPI MAC address */
|
||||
if ( ( rc = acpi_mac ( mac ) ) != 0 )
|
||||
return rc;
|
||||
|
||||
/* Return MAC address */
|
||||
if ( len > sizeof ( mac ) )
|
||||
len = sizeof ( mac );
|
||||
memcpy ( data, mac, len );
|
||||
return ( sizeof ( mac ) );
|
||||
}
|
||||
|
||||
/** System MAC address setting */
|
||||
const struct setting sysmac_setting __setting ( SETTING_MISC, sysmac ) = {
|
||||
.name = "sysmac",
|
||||
.description = "System MAC",
|
||||
.type = &setting_type_hex,
|
||||
.scope = &builtin_scope,
|
||||
};
|
||||
|
||||
/** System MAC address built-in setting */
|
||||
struct builtin_setting sysmac_builtin_setting __builtin_setting = {
|
||||
.setting = &sysmac_setting,
|
||||
.fetch = sysmac_fetch,
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue