tech-kern archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
Adding ruminit(4)
Hi tech-kernel@,
as some of you may have noticed, I just added a USB ID to the rum(4)
driver [1]. It is for a device called "Windy 31" from Synet Electronics,
product name MW-P54SS [2] (yes it's old).
As it happens (and as documented in the manual page) it attaches first
as a mass storage device, much like u3g(4) has to deal with:
umass0 at uhub1 port 2 configuration 1 interface 0
umass0: Ralink product 0x2578, rev 2.00/0.01, addr 12
umass0: using SCSI over Bulk-Only
scsibus0 at umass0: 2 targets, 1 lun per target
cd0 at scsibus0 target 0 lun 0: <Ralink, RT73 WirelessLan, > cdrom removable
u3g(4) works around it with an intermediate u3ginit(4) driver. So I went
ahead and added ruminit(4) [3]. It works right away now:
ruminit0 at uhub1 port 1: Switching to Wireless mode
ruminit0: detached
ruminit0: at uhub1 port 1 (addr 11) disconnected
rum0 at uhub1 port 1
rum0: Ralink , rev 2.00/0.01, addr 11
rum0: MAC/BBP RT2573 (rev 0x2573a), RF RT2528, address 00:0e:2e:fb:d1:86
rum0: 11b rates: 1Mbps 2Mbps 5.5Mbps 11Mbps
rum0: 11g rates: 1Mbps 2Mbps 5.5Mbps 11Mbps 6Mbps 9Mbps 12Mbps 18Mbps 24Mbps 36Mbps 48Mbps 54Mbps
but I had to copy and paste code from u3g(4) and I don't like it :(
Any hints, suggestions about how to improve the patch? (attached)
Or is it good enough to commit as it is?
(I'll remove the remaining #if 0 of course)
[1] http://mail-index.netbsd.org/source-changes/2017/05/23/msg084652.html
[2] https://www.cnet.com/products/synet-windy31-usb-wireless-router/review/
[3]
https://git.edgebsd.org/gitweb/?p=src.git;a=shortlog;h=refs/heads/khorben/edgebsd-7/ruminit
Cheers,
--
khorben
diff --git a/share/man/man4/rum.4 b/share/man/man4/rum.4
index 823338465aca..ebf48fb5a21d 100644
--- a/share/man/man4/rum.4
+++ b/share/man/man4/rum.4
@@ -23,6 +23,7 @@
.Nm rum
.Nd Ralink Technology USB IEEE 802.11a/b/g wireless network device
.Sh SYNOPSIS
+.Cd "ruminit* at uhub? port ?"
.Cd "rum* at uhub? port ?"
.Sh DESCRIPTION
The
diff --git a/sys/arch/amd64/conf/ALL b/sys/arch/amd64/conf/ALL
index 0b8832923625..e2f1da182846 100644
--- a/sys/arch/amd64/conf/ALL
+++ b/sys/arch/amd64/conf/ALL
@@ -1173,6 +1173,7 @@ atu* at uhub? port ? # Atmel AT76C50XX based adapters
athn* at uhub? port ? # Atheros AR9002U
otus* at uhub? port ? # Atheros AR9001U
ural* at uhub? port ? # Ralink Technology RT2500USB 802.11a/b/g
+ruminit* at uhub? port ?
rum* at uhub? port ? # Ralink Technology RT2501/RT2601 802.11a/b/g
run* at uhub? port ? # Ralink Technology RT(2[78]|30)00 802.11a/b/g/n
upgt* at uhub? port ? # Intersil PrismGT
diff --git a/sys/arch/amd64/conf/GENERIC b/sys/arch/amd64/conf/GENERIC
index 037964ffe65d..eda8fb2ba315 100644
--- a/sys/arch/amd64/conf/GENERIC
+++ b/sys/arch/amd64/conf/GENERIC
@@ -999,6 +999,7 @@ athn* at uhub? port ? # Atheros AR9002U
atu* at uhub? port ? # Atmel at76c50x 802.11b
otus* at uhub? port ? # Atheros AR9001U
ural* at uhub? port ? # Ralink Technology RT2500USB 802.11a/b/g
+ruminit* at uhub? port ?
rum* at uhub? port ? # Ralink Technology RT2501/RT2601 802.11a/b/g
run* at uhub? port ? # Ralink Technology RT(2[78]|30)00 802.11a/b/g/n
urtw* at uhub? port ? # Realtek RTL8187/RTL8187B 802.11b/g
diff --git a/sys/arch/amd64/conf/XEN3_DOM0 b/sys/arch/amd64/conf/XEN3_DOM0
index 6789c8da3f1b..f155a7cece90 100644
--- a/sys/arch/amd64/conf/XEN3_DOM0
+++ b/sys/arch/amd64/conf/XEN3_DOM0
@@ -649,6 +649,7 @@ urndis* at uhub? port ? # Microsoft RNDIS specification
# USB 802.11 adapters
atu* at uhub? port ? # Atmel AT76C50XX based adapters
ural* at uhub? port ? # Ralink Technology RT2500USB 802.11a/b/g
+ruminit* at uhub? port ?
rum* at uhub? port ? # Ralink Technology RT2501/RT2601 802.11a/b/g
urtw* at uhub? port ? # Realtek RTL8187/RTL8187B 802.11b/g
diff --git a/sys/arch/evbarm/conf/HPT5325 b/sys/arch/evbarm/conf/HPT5325
index 6e39d257e0bc..a9b3f7de38a0 100644
--- a/sys/arch/evbarm/conf/HPT5325
+++ b/sys/arch/evbarm/conf/HPT5325
@@ -327,6 +327,7 @@ url* at uhub? port ? # Realtek RTL8150L based adapters
# USB 802.11 adapters
atu* at uhub? port ? # Atmel AT76C50XX based adapters
ural* at uhub? port ? # Ralink Technology RT2500USB 802.11a/b/g
+ruminit* at uhub? port ?
rum* at uhub? port ? # Ralink Technology RT2501/RT2601 802.11a/b/g
zyd* at uhub? port ? # Zydas ZD1211
diff --git a/sys/arch/evbarm/conf/MMNET_GENERIC b/sys/arch/evbarm/conf/MMNET_GENERIC
index 8a2d27a3c9df..9644fdab2b46 100644
--- a/sys/arch/evbarm/conf/MMNET_GENERIC
+++ b/sys/arch/evbarm/conf/MMNET_GENERIC
@@ -455,6 +455,7 @@ url* at uhub? port ? # Realtek RTL8150L based adapters
# USB 802.11 adapters
atu* at uhub? port ? # Atmel AT76C50XX based adapters
ural* at uhub? port ? # Ralink Technology RT2500USB 802.11a/b/g
+ruminit* at uhub? port ?
rum* at uhub? port ? # Ralink Technology RT2501/RT2601 802.11a/b/g
# Prolific PL2301/PL2302 host-to-host adapter
diff --git a/sys/arch/evbarm/conf/MPCSA_GENERIC b/sys/arch/evbarm/conf/MPCSA_GENERIC
index 934d57f2eb64..25ffcc2f21e9 100644
--- a/sys/arch/evbarm/conf/MPCSA_GENERIC
+++ b/sys/arch/evbarm/conf/MPCSA_GENERIC
@@ -513,6 +513,7 @@ url* at uhub? port ? # Realtek RTL8150L based adapters
# USB 802.11 adapters
atu* at uhub? port ? # Atmel AT76C50XX based adapters
ural* at uhub? port ? # Ralink Technology RT2500USB 802.11a/b/g
+ruminit* at uhub? port ?
rum* at uhub? port ? # Ralink Technology RT2501/RT2601 802.11a/b/g
# Prolific PL2301/PL2302 host-to-host adapter
diff --git a/sys/arch/evbarm/conf/OPENBLOCKS_A6 b/sys/arch/evbarm/conf/OPENBLOCKS_A6
index d2d090a715b6..7c949f1cb4fa 100644
--- a/sys/arch/evbarm/conf/OPENBLOCKS_A6
+++ b/sys/arch/evbarm/conf/OPENBLOCKS_A6
@@ -272,6 +272,7 @@ url* at uhub? port ? # Realtek RTL8150L based adapters
# USB 802.11 adapters
atu* at uhub? port ? # Atmel AT76C50XX based adapters
ural* at uhub? port ? # Ralink Technology RT2500USB 802.11a/b/g
+ruminit* at uhub? port ?
rum* at uhub? port ? # Ralink Technology RT2501/RT2601 802.11a/b/g
zyd* at uhub? port ? # Zydas ZD1211
diff --git a/sys/arch/evbarm/conf/SHEEVAPLUG b/sys/arch/evbarm/conf/SHEEVAPLUG
index 1b97af4971a0..fe8b3242cba6 100644
--- a/sys/arch/evbarm/conf/SHEEVAPLUG
+++ b/sys/arch/evbarm/conf/SHEEVAPLUG
@@ -326,6 +326,7 @@ url* at uhub? port ? # Realtek RTL8150L based adapters
# USB 802.11 adapters
atu* at uhub? port ? # Atmel AT76C50XX based adapters
ural* at uhub? port ? # Ralink Technology RT2500USB 802.11a/b/g
+ruminit* at uhub? port ?
rum* at uhub? port ? # Ralink Technology RT2501/RT2601 802.11a/b/g
zyd* at uhub? port ? # Zydas ZD1211
diff --git a/sys/arch/evbppc/conf/OPENBLOCKS266_OPT b/sys/arch/evbppc/conf/OPENBLOCKS266_OPT
index 206afd7df24b..2a82843ecc16 100644
--- a/sys/arch/evbppc/conf/OPENBLOCKS266_OPT
+++ b/sys/arch/evbppc/conf/OPENBLOCKS266_OPT
@@ -220,6 +220,7 @@ url* at uhub? port ? # Realtek RTL8150L based adapters
# USB 802.11b adapters
atu* at uhub? port ? # Atmel AT76C50XX based adapters
ural* at uhub? port ? # Ralink Technology RT2500USB 802.11a/b/g
+ruminit* at uhub? port ?
rum* at uhub? port ? # Ralink Technology RT2501/RT2601 802.11a/b/g
zyd* at uhub? port ? # Zydas ZD1211
diff --git a/sys/arch/hpcarm/conf/WZERO3 b/sys/arch/hpcarm/conf/WZERO3
index b01961f14239..57b1db7a5876 100644
--- a/sys/arch/hpcarm/conf/WZERO3
+++ b/sys/arch/hpcarm/conf/WZERO3
@@ -253,6 +253,7 @@ urlphy* at mii? phy ? # Realtek RTL8150L internal PHYs
# USB 802.11 adapters
atu* at uhub? port ? # Atmel AT76C50XX based adapters
ural* at uhub? port ? # Ralink Technology RT2500USB 802.11a/b/g
+ruminit* at uhub? port ?
rum* at uhub? port ? # Ralink Technology RT2501/RT2601 802.11a/b/g
upgt* at uhub? port ? # Intersil PrismGT
zyd* at uhub? port ? # Zydas ZD1211
diff --git a/sys/arch/hppa/conf/GENERIC b/sys/arch/hppa/conf/GENERIC
index fdee7891b9bd..051d2fcf7b84 100644
--- a/sys/arch/hppa/conf/GENERIC
+++ b/sys/arch/hppa/conf/GENERIC
@@ -633,6 +633,7 @@ url* at uhub? port ? # Realtek RTL8150L based adapters
# USB 802.11 adapters
atu* at uhub? port ? # Atmel AT76C50XX based adapters
ural* at uhub? port ? # Ralink Technology RT2500USB 802.11a/b/g
+ruminit* at uhub? port ?
rum* at uhub? port ? # Ralink Technology RT2501/RT2601 802.11a/b/g
zyd* at uhub? port ? # Zydas ZD1211
diff --git a/sys/arch/i386/conf/ALL b/sys/arch/i386/conf/ALL
index f4d8b8a87a5d..dbe63db43870 100644
--- a/sys/arch/i386/conf/ALL
+++ b/sys/arch/i386/conf/ALL
@@ -1322,6 +1322,7 @@ atu* at uhub? port ? # Atmel AT76C50XX based adapters
athn* at uhub? port ? # Atheros AR9002U
otus* at uhub? port ? # Atheros AR9001U
ural* at uhub? port ? # Ralink Technology RT2500USB 802.11a/b/g
+ruminit* at uhub? port ?
rum* at uhub? port ? # Ralink Technology RT2501/RT2601 802.11a/b/g
run* at uhub? port ? # Ralink Technology RT(2[78]|30)00 802.11a/b/g/n
upgt* at uhub? port ? # Intersil PrismGT
diff --git a/sys/arch/i386/conf/GENERIC b/sys/arch/i386/conf/GENERIC
index 47e25f5bf47e..def57281044d 100644
--- a/sys/arch/i386/conf/GENERIC
+++ b/sys/arch/i386/conf/GENERIC
@@ -1261,6 +1261,7 @@ athn* at uhub? port ? # Atheros AR9002U
atu* at uhub? port ? # Atmel AT76C50XX based adapters
otus* at uhub? port ? # Atheros AR9001U
ural* at uhub? port ? # Ralink Technology RT2500USB 802.11a/b/g
+ruminit* at uhub? port ?
rum* at uhub? port ? # Ralink Technology RT2501/RT2601 802.11a/b/g
run* at uhub? port ? # Ralink Technology RT(2[78]|30)00 802.11a/b/g/n
upgt* at uhub? port ? # Intersil PrismGT
diff --git a/sys/arch/i386/conf/XEN3_DOM0 b/sys/arch/i386/conf/XEN3_DOM0
index 40b6cec8ed8d..829e4c3aade7 100644
--- a/sys/arch/i386/conf/XEN3_DOM0
+++ b/sys/arch/i386/conf/XEN3_DOM0
@@ -625,6 +625,7 @@ urndis* at uhub? port ? # Microsoft RNDIS specification
# USB 802.11 adapters
atu* at uhub? port ? # Atmel AT76C50XX based adapters
ural* at uhub? port ? # Ralink Technology RT2500USB 802.11a/b/g
+ruminit* at uhub? port ?
rum* at uhub? port ? # Ralink Technology RT2501/RT2601 802.11a/b/g
urtw* at uhub? port ? # Realtek RTL8187/RTL8187B 802.11b/g
diff --git a/sys/arch/macppc/conf/GENERIC b/sys/arch/macppc/conf/GENERIC
index f91ee12ed3af..3416e9a5fc6c 100644
--- a/sys/arch/macppc/conf/GENERIC
+++ b/sys/arch/macppc/conf/GENERIC
@@ -534,6 +534,7 @@ ugen* at uhub? port ? configuration ? interface ? # USB Generic driver
atu* at uhub? port ? # Atmel at76c50x 802.11b
otus* at uhub? port ? # Atheros AR9001U
ural* at uhub? port ? # Ralink Technology RT2500USB 802.11a/b/g
+ruminit* at uhub? port ?
rum* at uhub? port ? # Ralink Technology RT2501/RT2601 802.11a/b/g
#zyd* at uhub? port ? # Zydas ZD1211
diff --git a/sys/dev/usb/files.usb b/sys/dev/usb/files.usb
index 57d3c2451375..83770f1b0dd5 100644
--- a/sys/dev/usb/files.usb
+++ b/sys/dev/usb/files.usb
@@ -484,7 +484,9 @@ file dev/usb/if_ural.c ural
device rum: ether, ifnet, arp, wlan, firmload
attach rum at usbdevif
-file dev/usb/if_rum.c rum
+device ruminit
+attach ruminit at usbdevif
+file dev/usb/if_rum.c rum | ruminit
# Topfield digital PVRs
device utoppy
diff --git a/sys/dev/usb/if_rum.c b/sys/dev/usb/if_rum.c
index 709d2363fcdc..64364a053c7c 100644
--- a/sys/dev/usb/if_rum.c
+++ b/sys/dev/usb/if_rum.c
@@ -250,6 +250,16 @@ extern struct cfdriver rum_cd;
CFATTACH_DECL_NEW(rum, sizeof(struct rum_softc), rum_match, rum_attach,
rum_detach, rum_activate);
+
+/* ruminit */
+static int ruminit_bulk_scsi_eject(struct usbd_device *);
+
+static int ruminit_match(device_t, cfdata_t, void *);
+static void ruminit_attach(device_t, device_t, void *);
+static int ruminit_detach(device_t, int);
+CFATTACH_DECL2_NEW(ruminit, 0, ruminit_match, ruminit_attach, ruminit_detach,
+ NULL, NULL, NULL);
+
static int
rum_match(device_t parent, cfdata_t match, void *aux)
{
@@ -2321,3 +2331,174 @@ if_rum_modcmd(modcmd_t cmd, void *aux)
return ENOTTY;
}
}
+
+
+/*
+ * ruminit
+ */
+static int
+send_bulkmsg(struct usbd_device *dev, void *cmd, size_t cmdlen)
+{
+ struct usbd_interface *iface;
+ usb_interface_descriptor_t *id;
+ usb_endpoint_descriptor_t *ed;
+ struct usbd_pipe *pipe;
+ struct usbd_xfer *xfer;
+ int err, i;
+
+ /* Move the device into the configured state. */
+ err = usbd_set_config_index(dev, 0, 0);
+ if (err) {
+ aprint_error("ruminit: failed to set config index\n");
+ return UMATCH_NONE;
+ }
+
+ err = usbd_device2interface_handle(dev, 0, &iface);
+ if (err != 0) {
+ aprint_error("ruminit: failed to get interface\n");
+ return UMATCH_NONE;
+ }
+
+ id = usbd_get_interface_descriptor(iface);
+ ed = NULL;
+ for (i = 0 ; i < id->bNumEndpoints ; i++) {
+ ed = usbd_interface2endpoint_descriptor(iface, i);
+ if (ed == NULL)
+ continue;
+ if (UE_GET_DIR(ed->bEndpointAddress) != UE_DIR_OUT)
+ continue;
+ if ((ed->bmAttributes & UE_XFERTYPE) == UE_BULK)
+ break;
+ }
+
+ if (i == id->bNumEndpoints)
+ return UMATCH_NONE;
+
+ err = usbd_open_pipe(iface, ed->bEndpointAddress,
+ USBD_EXCLUSIVE_USE, &pipe);
+ if (err != 0) {
+ aprint_error("ruminit: failed to open bulk transfer pipe %d\n",
+ ed->bEndpointAddress);
+ return UMATCH_NONE;
+ }
+
+ int error = usbd_create_xfer(pipe, cmdlen, 0, 0, &xfer);
+ if (!error) {
+
+ usbd_setup_xfer(xfer, NULL, cmd, cmdlen,
+ USBD_SYNCHRONOUS, USBD_DEFAULT_TIMEOUT, NULL);
+
+ err = usbd_transfer(xfer);
+
+#if 0 /* XXXpooka: at least my huawei "fails" this always, but still detaches */
+ if (err)
+ aprint_error("ruminit: transfer failed\n");
+#else
+ err = 0;
+#endif
+ usbd_destroy_xfer(xfer);
+ } else {
+ aprint_error("ruminit: failed to allocate xfer\n");
+ err = USBD_NOMEM;
+ }
+
+ usbd_abort_pipe(pipe);
+ usbd_close_pipe(pipe);
+
+ return err == USBD_NORMAL_COMPLETION ? UMATCH_HIGHEST : UMATCH_NONE;
+}
+
+/* Byte 0..3: Command Block Wrapper (CBW) signature */
+static void
+set_cbw(unsigned char *cmd)
+{
+ cmd[0] = 0x55;
+ cmd[1] = 0x53;
+ cmd[2] = 0x42;
+ cmd[3] = 0x43;
+}
+
+static int
+ruminit_bulk_scsi_eject(struct usbd_device *dev)
+{
+ unsigned char cmd[31];
+
+ memset(cmd, 0, sizeof(cmd));
+ /* Byte 0..3: Command Block Wrapper (CBW) signature */
+ set_cbw(cmd);
+ /* 4..7: CBW Tag, has to unique, but only a single transfer used. */
+ cmd[4] = 0x01;
+ /* 8..11: CBW Transfer Length, no data here */
+ /* 12: CBW Flag: output, so 0 */
+ /* 13: CBW Lun: 0 */
+ /* 14: CBW Length */
+ cmd[14] = 0x06;
+
+ /* Rest is the SCSI payload */
+
+ /* 0: SCSI START/STOP opcode */
+ cmd[15] = 0x1b;
+ /* 1..3 unused */
+ /* 4 Load/Eject command */
+ cmd[19] = 0x02;
+ /* 5: unused */
+
+ return send_bulkmsg(dev, cmd, sizeof(cmd));
+}
+
+static int
+ruminit_match(device_t parent, cfdata_t match, void *aux)
+{
+ struct usb_attach_arg *uaa = aux;
+
+ /*
+ * Huawei changes product when it is configured as a modem.
+ */
+ switch (uaa->uaa_vendor) {
+ case USB_VENDOR_RALINK:
+ switch (uaa->uaa_product){
+ case USB_PRODUCT_RALINK_RT73:
+ return ruminit_bulk_scsi_eject(uaa->uaa_device);
+ break;
+ default:
+ break;
+ }
+ break;
+
+ default:
+ break;
+ }
+
+ return UMATCH_NONE;
+}
+
+static void
+ruminit_attach(device_t parent, device_t self, void *aux)
+{
+ struct usb_attach_arg *uaa = aux;
+
+ aprint_naive("\n");
+ aprint_normal(": Switching to Wireless mode\n");
+
+ if (uaa->uaa_vendor == USB_VENDOR_RALINK) {
+ switch (uaa->uaa_product) {
+#if 0
+ case USB_PRODUCT_RALINK_RT73:
+ /* About to disappear... */
+ return;
+ break;
+#endif
+ default:
+ break;
+ }
+ }
+
+ /* Move the device into the configured state. */
+ (void) usbd_set_config_index(uaa->uaa_device, 0, 1);
+}
+
+static int
+ruminit_detach(device_t self, int flags)
+{
+ return 0;
+}
diff --git a/sys/dev/usb/usbdevs b/sys/dev/usb/usbdevs
index 264247b0bf1a..14be7f3f7357 100644
--- a/sys/dev/usb/usbdevs
+++ b/sys/dev/usb/usbdevs
@@ -2716,6 +2716,7 @@ product RALINK RT2570 0x1706 RT2570
product RALINK RT2070 0x2070 RT2070
product RALINK RT2570_2 0x2570 RT2570
product RALINK RT2573 0x2573 RT2573
+product RALINK RT73 0x2578 RT73
product RALINK RT2671 0x2671 RT2671
product RALINK RT2770 0x2770 RT2770
product RALINK RT2870 0x2870 RT2870
diff --git a/sys/dev/usb/usbdevs.h b/sys/dev/usb/usbdevs.h
index ed5f76c8a1f8..f81f93958efe 100644
--- a/sys/dev/usb/usbdevs.h
+++ b/sys/dev/usb/usbdevs.h
@@ -2723,6 +2723,7 @@
#define USB_PRODUCT_RALINK_RT2070 0x2070 /* RT2070 */
#define USB_PRODUCT_RALINK_RT2570_2 0x2570 /* RT2570 */
#define USB_PRODUCT_RALINK_RT2573 0x2573 /* RT2573 */
+#define USB_PRODUCT_RALINK_RT73 0x2578 /* RT73 */
#define USB_PRODUCT_RALINK_RT2671 0x2671 /* RT2671 */
#define USB_PRODUCT_RALINK_RT2770 0x2770 /* RT2770 */
#define USB_PRODUCT_RALINK_RT2870 0x2870 /* RT2870 */
diff --git a/sys/dev/usb/usbdevs_data.h b/sys/dev/usb/usbdevs_data.h
index fadcaff98461..7b04b8cf9c2e 100644
--- a/sys/dev/usb/usbdevs_data.h
+++ b/sys/dev/usb/usbdevs_data.h
@@ -8331,6 +8331,10 @@ const struct usb_product usb_products[] = {
"RT2573",
},
{
+ USB_VENDOR_RALINK, USB_PRODUCT_RALINK_RT73,
+ "RT73",
+ },
+ {
USB_VENDOR_RALINK, USB_PRODUCT_RALINK_RT2671,
"RT2671",
},
@@ -10575,4 +10579,4 @@ const struct usb_product usb_products[] = {
"Prestige",
},
};
-const int usb_nproducts = 2093;
+const int usb_nproducts = 2094;
Home |
Main Index |
Thread Index |
Old Index