I've been doing some more testing on newer OpenBSD releases (namely 6.4) and have picked up a couple of problems with this patch. There are a couple of cleanups needed (a duplicated conditional in umsm.c for example, and small formatting issues ) as a result of bringing this patch forward, and I've got to work out why the reattach isn't happening on OpenBSD 6.4+.
If anyone has any feedback in the meantime, that would be very much appreciated, but until then, I'll be working on diagnosing. Best, James On Mon, Jan 21, 2019 at 05:04:02PM +1100, James Hebden wrote: > Hello tech@, > > Given this is my first email to the list, and the first patch I have > submitted to the OpenBSD project, I am very open to feedback on > the attached patch and context provided! > > Below I have included a patch I have been working on to modify some of > the logic when handling E-series Huawei USB mobile broadband dongles. > > These devices are able to operate in several modes, the most compatible > and performant mode being as a USB networking device ('HiLink' mode), > providing a NAT'ed connection to the mobile broadband service of the > connected provider. > > Using this mode requires no additional software, other than a DHCP > client in OpenBSD. Even that is optional, give you could statically > configure the interface. > > This patch refactors lightly some of the logic around handling E-Series > devices, and moves the original device definitions for the E303 to a > generic 'E-Series' device definition, given all E-Series devices seem to > share the parts of the intialisation and the USB product and vendor IDs > which OpenBSD currently assigns to the E303 device. > > I have also added additional logic to identify the E8372, which is the > device I am testing with, as additional logic is required to switch it > into HiLink mode. This should work for other E-Series HiLink devices > supporting the same mode. If anyone with one (or more!) of these > devices (say, the E3372, which appears to be almost identical) > could test this patch, it would be very much appreciated. > > I have tested this patch and it applies cleanly against -current, 6.4 > and 6.3. I am currently using this on the 6.3 kernel as my > home router, and so far it has proved reliable. > > Best Regards, > James "ec0" Hebden > > Patch follows - > > Index: dev/usb/if_cdce.c > =================================================================== > RCS file: /cvs/src/sys/dev/usb/if_cdce.c,v > retrieving revision 1.75 > diff -u -p -u -p -r1.75 if_cdce.c > --- dev/usb/if_cdce.c 2 Oct 2018 19:49:10 -0000 1.75 > +++ dev/usb/if_cdce.c 21 Jan 2019 05:42:47 -0000 > @@ -103,6 +103,7 @@ const struct cdce_type cdce_devs[] = { > {{ USB_VENDOR_NETCHIP, USB_PRODUCT_NETCHIP_ETHERNETGADGET }, 0 }, > {{ USB_VENDOR_COMPAQ, USB_PRODUCT_COMPAQ_IPAQLINUX }, 0 }, > {{ USB_VENDOR_AMBIT, USB_PRODUCT_AMBIT_NTL_250 }, CDCE_SWAPUNION }, > + {{ USB_VENDOR_HUAWEI, USB_PRODUCT_HUAWEI_E8372 }, 0 }, > }; > #define cdce_lookup(v, p) \ > ((const struct cdce_type *)usb_lookup(cdce_devs, v, p)) > @@ -134,6 +135,18 @@ cdce_match(struct device *parent, void * > > if (cdce_lookup(uaa->vendor, uaa->product) != NULL) > return (UMATCH_VENDOR_PRODUCT); > + > + if (uaa->vendor == USB_VENDOR_HUAWEI && > + uaa->product == USB_PRODUCT_HUAWEI_E8372) > + { > + return (UMATCH_IFACECLASS_IFACESUBCLASS_IFACEPROTO); > + } > + > + if (uaa->vendor == USB_VENDOR_HUAWEI && > + uaa->product == USB_PRODUCT_HUAWEI_E8372) > + { > + return (UMATCH_IFACECLASS_IFACESUBCLASS_IFACEPROTO); > + } > > if (id->bInterfaceClass == UICLASS_CDC && > (id->bInterfaceSubClass == > Index: dev/usb/umsm.c > =================================================================== > RCS file: /cvs/src/sys/dev/usb/umsm.c,v > retrieving revision 1.114 > diff -u -p -u -p -r1.114 umsm.c > --- dev/usb/umsm.c 15 Aug 2018 14:13:07 -0000 1.114 > +++ dev/usb/umsm.c 21 Jan 2019 05:42:48 -0000 > @@ -133,7 +133,7 @@ static const struct umsm_type umsm_devs[ > {{ USB_VENDOR_HUAWEI, USB_PRODUCT_HUAWEI_E182 }, DEV_UMASS5}, > {{ USB_VENDOR_HUAWEI, USB_PRODUCT_HUAWEI_E1820 }, DEV_UMASS5}, > {{ USB_VENDOR_HUAWEI, USB_PRODUCT_HUAWEI_E220 }, DEV_HUAWEI}, > - {{ USB_VENDOR_HUAWEI, USB_PRODUCT_HUAWEI_E303 }, DEV_UMASS5}, > + {{ USB_VENDOR_HUAWEI, USB_PRODUCT_HUAWEI_ESERIES_INIT }, DEV_UMASS5}, > {{ USB_VENDOR_HUAWEI, USB_PRODUCT_HUAWEI_E353_INIT }, DEV_UMASS5}, > {{ USB_VENDOR_HUAWEI, USB_PRODUCT_HUAWEI_E510 }, DEV_HUAWEI}, > {{ USB_VENDOR_HUAWEI, USB_PRODUCT_HUAWEI_E618 }, DEV_HUAWEI}, > @@ -150,6 +150,7 @@ static const struct umsm_type umsm_devs[ > {{ USB_VENDOR_HUAWEI, USB_PRODUCT_HUAWEI_E1750 }, DEV_UMASS5}, > {{ USB_VENDOR_HUAWEI, USB_PRODUCT_HUAWEI_E1752 }, 0}, > {{ USB_VENDOR_HUAWEI, USB_PRODUCT_HUAWEI_E3372 }, DEV_UMASS5}, > + {{ USB_VENDOR_HUAWEI, USB_PRODUCT_HUAWEI_E8372 }, DEV_UMASS5}, > > {{ USB_VENDOR_HYUNDAI, USB_PRODUCT_HYUNDAI_UM175 }, 0}, > > @@ -313,7 +314,10 @@ umsm_match(struct device *parent, void * > return UMATCH_VENDOR_IFACESUBCLASS; > else > return UMATCH_NONE; > - } else if (flag & DEV_UMASS) { > + } else if (flag & DEV_UMASS5) { > + return UMATCH_NONE; > + } > + else if (flag & DEV_UMASS) { > return UMATCH_VENDOR_IFACESUBCLASS; > } else if (flag & DEV_TRUINSTALL) { > return UMATCH_VENDOR_IFACESUBCLASS; > @@ -374,6 +378,8 @@ umsm_attach(struct device *parent, struc > printf("%s: truinstall mode. need to reattach\n", > sc->sc_dev.dv_xname); > } else if ((sc->sc_flag & DEV_UMASS) && uaa->ifaceno == 0) { > + printf("%s: 3g umass mode. need to reattach\n", > + sc->sc_dev.dv_xname); > umsm_umass_changemode(sc); > } > > @@ -710,6 +716,10 @@ umsm_umass_changemode(struct umsm_softc > cbw.bCBWFlags = CBWFLAGS_OUT; > cbw.CBWCDB[0] = 0x11; > cbw.CBWCDB[1] = 0x06; > + cbw.CBWCDB[2] = 0x20; > + cbw.CBWCDB[5] = 0x01; > + cbw.CBWCDB[6] = 0x01; > + cbw.CBWCDB[8] = 0x01; > break; > case DEV_UMASS6: /* ZTE */ > USETDW(cbw.dCBWDataTransferLength, 0x20); > Index: dev/usb/usbdevs > =================================================================== > RCS file: /cvs/src/sys/dev/usb/usbdevs,v > retrieving revision 1.692 > diff -u -p -u -p -r1.692 usbdevs > --- dev/usb/usbdevs 22 Aug 2018 15:30:20 -0000 1.692 > +++ dev/usb/usbdevs 21 Jan 2019 05:42:52 -0000 > @@ -2218,6 +2218,7 @@ product HUAWEI E181 0x1414 HUAWEI Mobil > product HUAWEI E1752 0x1417 HUAWEI Mobile Modem > product HUAWEI E182 0x1429 HUAWEI Mobile Modem > product HUAWEI E3372 0x1442 HUAWEI Mobile Modem > +product HUAWEI E8372 0x14db HUAWEI Mobile Modem > product HUAWEI E161 0x1446 HUAWEI Mobile Modem > product HUAWEI K3765 0x1465 HUAWEI Mobile K3765 > product HUAWEI K3772 0x14cf HUAWEI Mobile K3772 > @@ -2231,7 +2232,7 @@ product HUAWEI K3772_INIT 0x1526 HUAWEI > product HUAWEI MU609 0x1573 HUAWEI Mobile ME906 > product HUAWEI E173S 0x1c05 HUAWEI Mobile E173s > product HUAWEI E173S_INIT 0x1c0b HUAWEI Mobile E173s Initial > -product HUAWEI E303 0x1f01 HUAWEI Mobile E303 > +product HUAWEI ESERIES_INIT 0x1f01 HUAWEI Mobile ESeries Initial > > /* HUMAX products */ > product HUMAX PVRSMART 0x138c PVR-SMART > Index: dev/usb/usbdevs.h > =================================================================== > RCS file: /cvs/src/sys/dev/usb/usbdevs.h,v > retrieving revision 1.704 > diff -u -p -u -p -r1.704 usbdevs.h > --- dev/usb/usbdevs.h 22 Aug 2018 15:31:05 -0000 1.704 > +++ dev/usb/usbdevs.h 21 Jan 2019 05:42:59 -0000 > @@ -2225,6 +2225,7 @@ > #define USB_PRODUCT_HUAWEI_E1752 0x1417 /* HUAWEI > Mobile Modem */ > #define USB_PRODUCT_HUAWEI_E182 0x1429 /* HUAWEI Mobile Modem > */ > #define USB_PRODUCT_HUAWEI_E3372 0x1442 /* HUAWEI > Mobile Modem */ > +#define USB_PRODUCT_HUAWEI_E8372 0x14db /* HUAWEI > Mobile Modem */ > #define USB_PRODUCT_HUAWEI_E161 0x1446 /* HUAWEI Mobile Modem > */ > #define USB_PRODUCT_HUAWEI_K3765 0x1465 /* HUAWEI > Mobile K3765 */ > #define USB_PRODUCT_HUAWEI_K3772 0x14cf /* HUAWEI > Mobile K3772 */ > @@ -2238,7 +2239,7 @@ > #define USB_PRODUCT_HUAWEI_MU609 0x1573 /* HUAWEI > Mobile ME906 */ > #define USB_PRODUCT_HUAWEI_E173S 0x1c05 /* HUAWEI > Mobile E173s */ > #define USB_PRODUCT_HUAWEI_E173S_INIT 0x1c0b /* HUAWEI > Mobile E173s Initial */ > -#define USB_PRODUCT_HUAWEI_E303 0x1f01 /* HUAWEI Mobile E303 */ > +#define USB_PRODUCT_HUAWEI_ESERIES_INIT 0x1f01 /* HUAWEI > Mobile ESeries Generic Init */ > > /* HUMAX products */ > #define USB_PRODUCT_HUMAX_PVRSMART 0x138c /* PVR-SMART */ > Index: dev/usb/usbdevs_data.h > =================================================================== > RCS file: /cvs/src/sys/dev/usb/usbdevs_data.h,v > retrieving revision 1.698 > diff -u -p -u -p -r1.698 usbdevs_data.h > --- dev/usb/usbdevs_data.h 22 Aug 2018 15:31:05 -0000 1.698 > +++ dev/usb/usbdevs_data.h 21 Jan 2019 05:43:06 -0000 > @@ -4694,6 +4694,10 @@ const struct usb_known_product usb_known > "HUAWEI Mobile Modem", > }, > { > + USB_VENDOR_HUAWEI, USB_PRODUCT_HUAWEI_E8372, > + "HUAWEI Mobile Modem", > + }, > + { > USB_VENDOR_HUAWEI, USB_PRODUCT_HUAWEI_E161, > "HUAWEI Mobile Modem", > }, > @@ -4746,8 +4750,8 @@ const struct usb_known_product usb_known > "HUAWEI Mobile E173s Initial", > }, > { > - USB_VENDOR_HUAWEI, USB_PRODUCT_HUAWEI_E303, > - "HUAWEI Mobile E303", > + USB_VENDOR_HUAWEI, USB_PRODUCT_HUAWEI_ESERIES_INIT, > + "HUAWEI Mobile ESeries Generic Initial", > }, > { > USB_VENDOR_HUMAX, USB_PRODUCT_HUMAX_PVRSMART,