[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>
diff --git a/src/core/acpimac.c b/src/core/acpimac.c
index 5920480..e0074ba 100644
--- a/src/core/acpimac.c
+++ b/src/core/acpimac.c
@@ -29,6 +29,7 @@
#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 @@
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,
+};