platform/x86: thinkpad_acpi: sysfs interface to auxmac
Subsystems (2)
PATCH v2 1/1 platform/x86: thinkpad_acpi: sysfs interface to auxmac
Newer Thinkpads have a feature called Mac Address Passthrough. This patch provides a sysfs interface that userspace can use to get this auxiliary mac address.
Changes in v2:
- Added documentation
- All handling of the auxmac value is done in the _init function.
--- .../admin-guide/laptops/thinkpad-acpi.rst | 20 +++++ drivers/platform/x86/thinkpad_acpi.c | 78 +++++++++++++++++++ 2 files changed, 98 insertions(+)
Documentation/admin-guide/laptops/thinkpad-acpi.rst +20 -0
@@ -53,6 +53,7 @@ detailed description): - Lap mode sensor - Setting keyboard language - WWAN Antenna type + - Auxmac A compatibility table by model and feature is maintained on the web site, http://ibm-acpi.sf.net/. I appreciate any success or failure
@@ -1511,6 +1512,25 @@ Currently 2 antenna types are supported as mentioned below: The property is read-only. If the platform doesn't have support the sysfs class is not created. +Auxmac +------ + +sysfs: auxmac + +Some newer Thinkpads have a feature called MAC Address Passthrough. This +feature is implemented by the system firmware to provide a system unique MAC, +that can override a dock or USB ethernet dongle MAC, when connected to a +network. This property enables user-space to easily determine the MAC address +if the feature is enabled. + +The values of this auxiliary MAC are: + + cat /sys/devices/platform/thinkpad_acpi/auxmac + +If the feature is disabled, the value will be 'disabled'. + +This property is read-only. + Adaptive keyboard -----------------
drivers/platform/x86/thinkpad_acpi.c +78 -0
96 lines not on this page · raw message
Signature · 1 line
2.25.1
Ilpo Järvinen
maintainerQuoted 79 lines · Fernando Eckhardt Valle
Newer Thinkpads have a feature called Mac Address Passthrough. This patch provides a sysfs interface that userspace can use to get this auxiliary mac address.
Changes in v2:
- Added documentation
- All handling of the auxmac value is done in the_initfunction.Signed-off-by Fernando Eckhardt Valle <[email protected]>--- .../admin-guide/laptops/thinkpad-acpi.rst | 20 +++++ drivers/platform/x86/thinkpad_acpi.c | 78 +++++++++++++++++++ 2 files changed, 98 insertions(+)Documentation/admin-guide/laptops/thinkpad-acpi.rst +20
-0@@ -53,6 +53,7 @@ detailed description): - Lap mode sensor - Setting keyboard language - WWAN Antenna type + - Auxmac A compatibility table by model and feature is maintained on the web site, http://ibm-acpi.sf.net/. I appreciate any success or failure@@ -1511,6 +1512,25 @@ Currently 2 antenna types are supported as mentioned below: The property is read-only. If the platform doesn't have support the sysfs class is not created. +Auxmac +------ + +sysfs: auxmac + +Some newer Thinkpads have a feature called MAC Address Passthrough. This +feature is implemented by the system firmware to provide a system unique MAC, +that can override a dock or USB ethernet dongle MAC, when connected to a +network. This property enables user-space to easily determine the MAC address +if the feature is enabled. + +The values of this auxiliary MAC are: + + cat /sys/devices/platform/thinkpad_acpi/auxmac + +If the feature is disabled, the value will be 'disabled'. + +This property is read-only. + Adaptive keyboard -----------------drivers/platform/x86/thinkpad_acpi.c +19
-0@@ -10785,6 +10785,79 @@ static struct ibm_struct dprc_driver_data = { .name = "dprc", }; +/* +* Auxmac +* +* This auxiliary mac address is enabled in the bios through the +* Mac Address Passthrough feature. In most cases, there are three +* possibilities: Internal Mac, Second Mac, and disabled. +* +*/ + +#define AUXMAC_LEN 12 +#define AUXMAC_START 9 +#define AUXMAC_STRLEN 22 +static char auxmac[AUXMAC_LEN ]; + +static int auxmac_init (struct ibm_init_struct *iibm) +{ +acpi_status status; +struct acpi_buffer buffer = {ACPI_ALLOCATE_BUFFER ,NULL }; +union acpi_object *obj;
drivers/platform/x86/thinkpad_acpi.c static struct ibm_struct dprc_driver_data = { · line 10816
Quoted 10 lines
drivers/platform/x86/thinkpad_acpi.c +10
-0+ + status =acpi_evaluate_object (NULL ,"\\MACA" ,NULL , &buffer); + +if (ACPI_FAILURE (status)) +return -ENODEV ; + + obj = (union acpi_object *)buffer.pointer; + +if (obj->type !=ACPI_TYPE_STRING || obj->string.length !=AUXMAC_STRLEN ) { +pr_info ("Invalid buffer for mac addr passthrough.\n" );
MAC address
drivers/platform/x86/thinkpad_acpi.c static struct ibm_struct dprc_driver_data = { · line 10821
Quoted 5 lines
drivers/platform/x86/thinkpad_acpi.c +5
-0+ goto auxmacinvalid; + } + +if (strncmp (obj->string.pointer +0x8 ,"#" ,1 ) !=0 || +strncmp (obj->string.pointer +0x15 ,"#" ,1 ) !=0 ) {
Why use strncmp with (..., 1)? These offsets should defines above and not use literals.
drivers/platform/x86/thinkpad_acpi.c static struct ibm_struct dprc_driver_data = { · line 10822
Quoted 1 line
drivers/platform/x86/thinkpad_acpi.c +1
-0+pr_info ("Invalid header for mac addr passthrough.\n" );
MAC address
drivers/platform/x86/thinkpad_acpi.c static struct ibm_struct dprc_driver_data = { · line 10826
Quoted 4 lines
drivers/platform/x86/thinkpad_acpi.c +4
-0+ goto auxmacinvalid; + } + +if (strncmp (obj->string.pointer +0x9 ,"XXXXXXXXXXXX" ,AUXMAC_LEN ) ==0 )
Why you're not using AUXMAC_START here?
It's also bit confusing that some of the offset are hex and some non-hex numbers.
drivers/platform/x86/thinkpad_acpi.c static struct ibm_struct dprc_driver_data = { · line 10827
Quoted 1 line
drivers/platform/x86/thinkpad_acpi.c +1
-0+memcpy (auxmac,"disabled" ,9 );
Don't use memcpy() for copying a string.
drivers/platform/x86/thinkpad_acpi.c static struct ibm_struct dprc_driver_data = { · line 10829
Quoted 2 lines
drivers/platform/x86/thinkpad_acpi.c +2
-0+else +memcpy (auxmac, obj->string.pointer +AUXMAC_START ,AUXMAC_LEN );
What about the termination of auxmac? It's given
drivers/platform/x86/thinkpad_acpi.c static struct ibm_struct dprc_driver_data = { · line 10836
Quoted 7 lines
drivers/platform/x86/thinkpad_acpi.c +7
-0+ +kfree (obj); +return 0 ; + +auxmacinvalid: +kfree (obj); +memcpy (auxmac,"unavailable" ,11 );
Again, don't use memcpy() to copy a string. You even got it wrong here compared with the other case where you copied also the zero terminator.
drivers/platform/x86/thinkpad_acpi.c static struct ibm_struct dprc_driver_data = { · line 10848
Quoted 12 lines
drivers/platform/x86/thinkpad_acpi.c +12
-0+return 0 ; +} + +static struct ibm_struct auxmac_data = { + .name ="auxmac" , +}; + +static ssize_t auxmac_show (struct device *dev, +struct device_attribute *attr, +char *buf) +{ +return sysfs_emit (buf,"%s\n" , auxmac);
This requires proper termination for the string but you didn't ensure it above.
Signature · 1 line
i.
Quoted 35 lines
drivers/platform/x86/thinkpad_acpi.c +17
-0+} +static DEVICE_ATTR_RO (auxmac); + +static struct attribute *auxmac_attributes[] = { + &dev_attr_auxmac.attr, +NULL +}; + +static const struct attribute_group auxmac_attr_group = { + .attrs = auxmac_attributes, +}; +/* --------------------------------------------------------------------- */ static struct attribute *tpacpi_driver_attributes[] = {@@ -10843,6 +10916,7 @@ static const struct attribute_group *tpacpi_groups[] = { &proxsensor_attr_group, &kbdlang_attr_group, &dprc_attr_group, + &auxmac_attr_group, NULL, };@@ -11414,6 +11488,10 @@ static struct ibm_init_struct ibms_init[] __initdata = { .init = tpacpi_dprc_init, .data = &dprc_driver_data, }, + { + .init = auxmac_init, + .data = &auxmac_data, + }, };static int __init set_ibm_param (const char *val,const struct kernel_param *kp)
Thanks for the review Ilpo, I will do a v3 with your feedback.
Regards,
Fernando.
________________________________________
From: Ilpo Järvinen <[email protected]>
Sent: Friday, September 15, 2023 1:18 PM
To: Fernando Eckhardt Valle (FIPT)
Cc: Hans de Goede; Mark Pearson; [email protected]; [email protected]; [email protected]; [email protected]; LKML; [email protected]; [email protected]
Subject: Re: [PATCH v2] platform/x86: thinkpad_acpi: sysfs interface to auxmac
Quoted 79 lines · Fernando Eckhardt Valle
Newer Thinkpads have a feature called Mac Address Passthrough. This patch provides a sysfs interface that userspace can use to get this auxiliary mac address.
Changes in v2:
- Added documentation
- All handling of the auxmac value is done in the_initfunction.Signed-off-by Fernando Eckhardt Valle <[email protected]>--- .../admin-guide/laptops/thinkpad-acpi.rst | 20 +++++ drivers/platform/x86/thinkpad_acpi.c | 78 +++++++++++++++++++ 2 files changed, 98 insertions(+)Documentation/admin-guide/laptops/thinkpad-acpi.rst +20
-0@@ -53,6 +53,7 @@ detailed description): - Lap mode sensor - Setting keyboard language - WWAN Antenna type + - Auxmac A compatibility table by model and feature is maintained on the web site, http://ibm-acpi.sf.net/. I appreciate any success or failure@@ -1511,6 +1512,25 @@ Currently 2 antenna types are supported as mentioned below: The property is read-only. If the platform doesn't have support the sysfs class is not created. +Auxmac +------ + +sysfs: auxmac + +Some newer Thinkpads have a feature called MAC Address Passthrough. This +feature is implemented by the system firmware to provide a system unique MAC, +that can override a dock or USB ethernet dongle MAC, when connected to a +network. This property enables user-space to easily determine the MAC address +if the feature is enabled. + +The values of this auxiliary MAC are: + + cat /sys/devices/platform/thinkpad_acpi/auxmac + +If the feature is disabled, the value will be 'disabled'. + +This property is read-only. + Adaptive keyboard -----------------drivers/platform/x86/thinkpad_acpi.c +19
-0@@ -10785,6 +10785,79 @@ static struct ibm_struct dprc_driver_data = { .name = "dprc", }; +/* +* Auxmac +* +* This auxiliary mac address is enabled in the bios through the +* Mac Address Passthrough feature. In most cases, there are three +* possibilities: Internal Mac, Second Mac, and disabled. +* +*/ + +#define AUXMAC_LEN 12 +#define AUXMAC_START 9 +#define AUXMAC_STRLEN 22 +static char auxmac[AUXMAC_LEN ]; + +static int auxmac_init (struct ibm_init_struct *iibm) +{ +acpi_status status; +struct acpi_buffer buffer = {ACPI_ALLOCATE_BUFFER ,NULL }; +union acpi_object *obj;
drivers/platform/x86/thinkpad_acpi.c static struct ibm_struct dprc_driver_data = { · line 10816
Quoted 10 lines
drivers/platform/x86/thinkpad_acpi.c +10
-0+ + status =acpi_evaluate_object (NULL ,"\\MACA" ,NULL , &buffer); + +if (ACPI_FAILURE (status)) +return -ENODEV ; + + obj = (union acpi_object *)buffer.pointer; + +if (obj->type !=ACPI_TYPE_STRING || obj->string.length !=AUXMAC_STRLEN ) { +pr_info ("Invalid buffer for mac addr passthrough.\n" );
MAC address
drivers/platform/x86/thinkpad_acpi.c static struct ibm_struct dprc_driver_data = { · line 10821
Quoted 5 lines
drivers/platform/x86/thinkpad_acpi.c +5
-0+ goto auxmacinvalid; + } + +if (strncmp (obj->string.pointer +0x8 ,"#" ,1 ) !=0 || +strncmp (obj->string.pointer +0x15 ,"#" ,1 ) !=0 ) {
Why use strncmp with (..., 1)? These offsets should defines above and not use literals.
drivers/platform/x86/thinkpad_acpi.c static struct ibm_struct dprc_driver_data = { · line 10822
Quoted 1 line
drivers/platform/x86/thinkpad_acpi.c +1
-0+pr_info ("Invalid header for mac addr passthrough.\n" );
MAC address
drivers/platform/x86/thinkpad_acpi.c static struct ibm_struct dprc_driver_data = { · line 10826
Quoted 4 lines
drivers/platform/x86/thinkpad_acpi.c +4
-0+ goto auxmacinvalid; + } + +if (strncmp (obj->string.pointer +0x9 ,"XXXXXXXXXXXX" ,AUXMAC_LEN ) ==0 )
Why you're not using AUXMAC_START here?
It's also bit confusing that some of the offset are hex and some non-hex numbers.
drivers/platform/x86/thinkpad_acpi.c static struct ibm_struct dprc_driver_data = { · line 10827
Quoted 1 line
drivers/platform/x86/thinkpad_acpi.c +1
-0+memcpy (auxmac,"disabled" ,9 );
Don't use memcpy() for copying a string.
drivers/platform/x86/thinkpad_acpi.c static struct ibm_struct dprc_driver_data = { · line 10829
Quoted 2 lines
drivers/platform/x86/thinkpad_acpi.c +2
-0+else +memcpy (auxmac, obj->string.pointer +AUXMAC_START ,AUXMAC_LEN );
What about the termination of auxmac? It's given
drivers/platform/x86/thinkpad_acpi.c static struct ibm_struct dprc_driver_data = { · line 10836
Quoted 7 lines
drivers/platform/x86/thinkpad_acpi.c +7
-0+ +kfree (obj); +return 0 ; + +auxmacinvalid: +kfree (obj); +memcpy (auxmac,"unavailable" ,11 );
Again, don't use memcpy() to copy a string. You even got it wrong here compared with the other case where you copied also the zero terminator.
drivers/platform/x86/thinkpad_acpi.c static struct ibm_struct dprc_driver_data = { · line 10848
Quoted 12 lines
drivers/platform/x86/thinkpad_acpi.c +12
-0+return 0 ; +} + +static struct ibm_struct auxmac_data = { + .name ="auxmac" , +}; + +static ssize_t auxmac_show (struct device *dev, +struct device_attribute *attr, +char *buf) +{ +return sysfs_emit (buf,"%s\n" , auxmac);
This requires proper termination for the string but you didn't ensure it above.
--
i.
Quoted 35 lines
drivers/platform/x86/thinkpad_acpi.c +17
-0+} +static DEVICE_ATTR_RO (auxmac); + +static struct attribute *auxmac_attributes[] = { + &dev_attr_auxmac.attr, +NULL +}; + +static const struct attribute_group auxmac_attr_group = { + .attrs = auxmac_attributes, +}; +/* --------------------------------------------------------------------- */ static struct attribute *tpacpi_driver_attributes[] = {@@ -10843,6 +10916,7 @@ static const struct attribute_group *tpacpi_groups[] = { &proxsensor_attr_group, &kbdlang_attr_group, &dprc_attr_group, + &auxmac_attr_group, NULL, };@@ -11414,6 +11488,10 @@ static struct ibm_init_struct ibms_init[] __initdata = { .init = tpacpi_dprc_init, .data = &dprc_driver_data, }, + { + .init = auxmac_init, + .data = &auxmac_data, + }, };static int __init set_ibm_param (const char *val,const struct kernel_param *kp)
Hi,
Quoted 1 line · Ilpo Järvinen
On Fri, 15 Sep 2023, Fernando Eckhardt Valle wrote:
<snip>
Quoted 8 lines
drivers/platform/x86/thinkpad_acpi.c static struct ibm_struct dprc_driver_data = { · line 10821
Quoted 5 lines
drivers/platform/x86/thinkpad_acpi.c +5
-0+ goto auxmacinvalid; + } + +if (strncmp (obj->string.pointer +0x8 ,"#" ,1 ) !=0 || +strncmp (obj->string.pointer +0x15 ,"#" ,1 ) !=0 ) {Why use strncmp with (..., 1)? These offsets should defines above and not use literals.
Right, good point.
To be extra clear here, this should be replaced by != '#' statements, e.g.:
if (obj->string.pointer[AUXMAC_BEGIN_MARKER] != '#' ||
obj->string.pointer[AUXMAC_END_MARKER] != '#') {
...Regards,
Hans