All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] usb: gadget: u_ether: Fix host MAC address case
@ 2023-04-25 12:58 Konrad Gräfe
  2023-04-25 13:04 ` Greg KH
  0 siblings, 1 reply; 7+ messages in thread
From: Konrad Gräfe @ 2023-04-25 12:58 UTC (permalink / raw)
  To: gregkh; +Cc: linux-usb


[-- Attachment #1.1.1: Type: text/plain, Size: 876 bytes --]


As the CDC-ECM specification states the host MAC address must be sent to
the host as an uppercase hexadecimal string:
     The Unicode character is chosen from the set of values 30h through
     39h and 41h through 46h (0-9 and A-F).

However, snprintf(.., "%pm", ..) generates a lowercase MAC address
string. While most host drivers are tolerant to this, UsbNcm.sys on
Windows 10 is not. Instead it uses a different MAC address with all
bytes set to zero including and after the first byte containing a
lowercase letter. On Windows 11 Microsoft fixed it, but apparently they
did not backport the fix.

This change fixes the issue by upper-casing the MAC to comply with the
specification.

Signed-off-by: Konrad Gräfe <k.graefe@gateware.de>
---
  drivers/usb/gadget/function/u_ether.c | 10 +++++++++-
  1 file changed, 9 insertions(+), 1 deletion(-)



[-- Attachment #1.1.2: 0001-usb-gadget-u_ether-Fix-host-MAC-address-case.patch --]
[-- Type: text/x-patch, Size: 812 bytes --]

diff --git drivers/usb/gadget/function/u_ether.c drivers/usb/gadget/function/u_ether.c
index 6956ad8ba8dd..49d29b04ef93 100644
--- drivers/usb/gadget/function/u_ether.c
+++ drivers/usb/gadget/function/u_ether.c
@@ -958,6 +958,7 @@ EXPORT_SYMBOL_GPL(gether_get_host_addr);
 int gether_get_host_addr_cdc(struct net_device *net, char *host_addr, int len)
 {
 	struct eth_dev *dev;
+	int i, slen;
 
 	if (len < 13)
 		return -EINVAL;
@@ -965,7 +966,14 @@ int gether_get_host_addr_cdc(struct net_device *net, char *host_addr, int len)
 	dev = netdev_priv(net);
 	snprintf(host_addr, len, "%pm", dev->host_mac);
 
-	return strlen(host_addr);
+
+	slen = strlen(host_addr);
+
+	for(i = 0; i < slen; i++) {
+		host_addr[i] = toupper(host_addr[i]);
+	}
+
+	return slen;
 }
 EXPORT_SYMBOL_GPL(gether_get_host_addr_cdc);
 


[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 840 bytes --]

^ permalink raw reply related	[flat|nested] 7+ messages in thread
* [PATCH] usb: gadget: u_ether: Fix host MAC address case
@ 2023-04-25 13:15 Konrad Gräfe
  2023-04-25 13:37 ` Greg KH
  0 siblings, 1 reply; 7+ messages in thread
From: Konrad Gräfe @ 2023-04-25 13:15 UTC (permalink / raw)
  To: gregkh; +Cc: linux-usb

[-- Attachment #1: Type: text/plain, Size: 851 bytes --]


As the CDC-ECM specification states the host MAC address must be sent to
the host as an uppercase hexadecimal string:
     The Unicode character is chosen from the set of values 30h through
     39h and 41h through 46h (0-9 and A-F).

However, snprintf(.., "%pm", ..) generates a lowercase MAC address
string. While most host drivers are tolerant to this, UsbNcm.sys on
Windows 10 is not. Instead it uses a different MAC address with all
bytes set to zero including and after the first byte containing a
lowercase letter. On Windows 11 Microsoft fixed it, but apparently they
did not backport the fix.

This change fixes the issue by upper-casing the MAC to comply with the
specification.

Signed-off-by: Konrad Gräfe <k.graefe@gateware.de>
---
  drivers/usb/gadget/function/u_ether.c | 9 ++++++++-
  1 file changed, 8 insertions(+), 1 deletion(-)


[-- Attachment #2: 0001-usb-gadget-u_ether-Fix-host-MAC-address-case.patch --]
[-- Type: text/x-patch, Size: 815 bytes --]

diff --git a/drivers/usb/gadget/function/u_ether.c b/drivers/usb/gadget/function/u_ether.c
index 6956ad8ba8dd..250734e090fc 100644
--- a/drivers/usb/gadget/function/u_ether.c
+++ b/drivers/usb/gadget/function/u_ether.c
@@ -958,6 +958,7 @@ EXPORT_SYMBOL_GPL(gether_get_host_addr);
 int gether_get_host_addr_cdc(struct net_device *net, char *host_addr, int len)
 {
 	struct eth_dev *dev;
+	int i, slen;
 
 	if (len < 13)
 		return -EINVAL;
@@ -965,7 +966,13 @@ int gether_get_host_addr_cdc(struct net_device *net, char *host_addr, int len)
 	dev = netdev_priv(net);
 	snprintf(host_addr, len, "%pm", dev->host_mac);
 
-	return strlen(host_addr);
+
+	slen = strlen(host_addr);
+
+	for (i = 0; i < slen; i++)
+		host_addr[i] = toupper(host_addr[i]);
+
+	return slen;
 }
 EXPORT_SYMBOL_GPL(gether_get_host_addr_cdc);
 


^ permalink raw reply related	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2023-04-26 11:49 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-04-25 12:58 [PATCH] usb: gadget: u_ether: Fix host MAC address case Konrad Gräfe
2023-04-25 13:04 ` Greg KH
  -- strict thread matches above, loose matches on Subject: below --
2023-04-25 13:15 Konrad Gräfe
2023-04-25 13:37 ` Greg KH
2023-04-26 10:17   ` Konrad Gräfe
2023-04-26 11:49     ` Quentin Schulz
2023-04-26 11:49     ` Greg KH

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.