1 From 69a9efb689b43fedf5f19431f1889aa6b8d35d55 Mon Sep 17 00:00:00 2001
2 From: Lech Perczak <lech.perczak@gmail.com>
3 Date: Fri, 1 Apr 2022 22:04:01 +0200
4 Subject: [PATCH 2/3] rndis_host: enable the bogus MAC fixup for ZTE devices
7 Content-Type: text/plain; charset=UTF-8
8 Content-Transfer-Encoding: 8bit
10 Certain ZTE modems, namely: MF823. MF831, MF910, built-in modem from
11 MF286R, expose both CDC-ECM and RNDIS network interfaces.
12 They have a trait of ignoring the locally-administered MAC address
13 configured on the interface both in CDC-ECM and RNDIS part,
14 and this leads to dropping of incoming traffic by the host.
15 However, the workaround was only present in CDC-ECM, and MF286R
16 explicitly requires it in RNDIS mode.
18 Re-use the workaround in rndis_host as well, to fix operation of MF286R
19 module, some versions of which expose only the RNDIS interface. Do so by
20 introducing new flag, RNDIS_DRIVER_DATA_DST_MAC_FIXUP, and testing for it
21 in rndis_rx_fixup. This is required, as RNDIS uses frame batching, and all
22 of the packets inside the batch need the fixup. This might introduce a
23 performance penalty, because test is done for every returned Ethernet
26 Apply the workaround to both "flavors" of RNDIS interfaces, as older ZTE
27 modems, like MF823 found in the wild, report the USB_CLASS_COMM class
28 interfaces, while MF286R reports USB_CLASS_WIRELESS_CONTROLLER.
30 Suggested-by: Bjørn Mork <bjorn@mork.no>
31 Cc: Kristian Evensen <kristian.evensen@gmail.com>
32 Cc: Oliver Neukum <oliver@neukum.org>
33 Signed-off-by: Lech Perczak <lech.perczak@gmail.com>
35 drivers/net/usb/rndis_host.c | 32 ++++++++++++++++++++++++++++++++
36 include/linux/usb/rndis_host.h | 1 +
37 2 files changed, 33 insertions(+)
39 --- a/drivers/net/usb/rndis_host.c
40 +++ b/drivers/net/usb/rndis_host.c
41 @@ -486,10 +486,14 @@ EXPORT_SYMBOL_GPL(rndis_unbind);
43 int rndis_rx_fixup(struct usbnet *dev, struct sk_buff *skb)
47 /* This check is no longer done by usbnet */
48 if (skb->len < dev->net->hard_header_len)
51 + dst_mac_fixup = !!(dev->driver_info->data & RNDIS_DRIVER_DATA_DST_MAC_FIXUP);
53 /* peripheral may have batched packets to us... */
54 while (likely(skb->len)) {
55 struct rndis_data_hdr *hdr = (void *)skb->data;
56 @@ -524,10 +528,17 @@ int rndis_rx_fixup(struct usbnet *dev, s
58 skb_pull(skb, msg_len - sizeof *hdr);
59 skb_trim(skb2, data_len);
61 + if (unlikely(dst_mac_fixup))
62 + usbnet_cdc_zte_rx_fixup(dev, skb2);
64 usbnet_skb_return(dev, skb2);
67 /* caller will usbnet_skb_return the remaining packet */
68 + if (unlikely(dst_mac_fixup))
69 + usbnet_cdc_zte_rx_fixup(dev, skb);
73 EXPORT_SYMBOL_GPL(rndis_rx_fixup);
74 @@ -601,6 +612,17 @@ static const struct driver_info rndis_po
75 .tx_fixup = rndis_tx_fixup,
78 +static const struct driver_info zte_rndis_info = {
79 + .description = "ZTE RNDIS device",
80 + .flags = FLAG_ETHER | FLAG_POINTTOPOINT | FLAG_FRAMING_RN | FLAG_NO_SETINT,
81 + .data = RNDIS_DRIVER_DATA_DST_MAC_FIXUP,
83 + .unbind = rndis_unbind,
84 + .status = rndis_status,
85 + .rx_fixup = rndis_rx_fixup,
86 + .tx_fixup = rndis_tx_fixup,
89 /*-------------------------------------------------------------------------*/
91 static const struct usb_device_id products [] = {
92 @@ -610,6 +632,16 @@ static const struct usb_device_id produc
93 USB_CLASS_COMM, 2 /* ACM */, 0x0ff),
94 .driver_info = (unsigned long) &rndis_poll_status_info,
96 + /* ZTE WWAN modules */
97 + USB_VENDOR_AND_INTERFACE_INFO(0x19d2,
98 + USB_CLASS_WIRELESS_CONTROLLER, 1, 3),
99 + .driver_info = (unsigned long)&zte_rndis_info,
101 + /* ZTE WWAN modules, ACM flavour */
102 + USB_VENDOR_AND_INTERFACE_INFO(0x19d2,
103 + USB_CLASS_COMM, 2 /* ACM */, 0x0ff),
104 + .driver_info = (unsigned long)&zte_rndis_info,
106 /* Hytera Communications DMR radios' "Radio to PC Network" */
107 USB_VENDOR_AND_INTERFACE_INFO(0x238b,
108 USB_CLASS_COMM, 2 /* ACM */, 0x0ff),
109 --- a/include/linux/usb/rndis_host.h
110 +++ b/include/linux/usb/rndis_host.h
111 @@ -197,6 +197,7 @@ struct rndis_keepalive_c { /* IN (option
113 /* Flags for driver_info::data */
114 #define RNDIS_DRIVER_DATA_POLL_STATUS 1 /* poll status before control */
115 +#define RNDIS_DRIVER_DATA_DST_MAC_FIXUP 2 /* device ignores configured MAC address */
117 extern void rndis_status(struct usbnet *dev, struct urb *urb);