1 // SPDX-License-Identifier: GPL-2.0+
3 * Driver for Option High Speed Mobile Devices.
5 * (c) 2008 Dan Williams <dcbw@redhat.com>
7 * Inspiration taken from sierra_ms.c by Kevin Lloyd <klloyd@sierrawireless.com>
10 #include <linux/usb.h>
11 #include <linux/slab.h>
12 #include <linux/module.h>
15 #include "transport.h"
16 #include "option_ms.h"
19 #define ZCD_FORCE_MODEM 0x01
20 #define ZCD_ALLOW_MS 0x02
22 static unsigned int option_zero_cd = ZCD_FORCE_MODEM;
23 module_param(option_zero_cd, uint, S_IRUGO | S_IWUSR);
24 MODULE_PARM_DESC(option_zero_cd, "ZeroCD mode (1=Force Modem (default),"
27 #define RESPONSE_LEN 1024
29 static int option_rezero(struct us_data *us)
31 static const unsigned char rezero_msg[] = {
32 0x55, 0x53, 0x42, 0x43, 0x78, 0x56, 0x34, 0x12,
33 0x01, 0x00, 0x00, 0x00, 0x80, 0x00, 0x06, 0x01,
34 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
35 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
40 usb_stor_dbg(us, "Option MS: %s\n", "DEVICE MODE SWITCH");
42 buffer = kzalloc(RESPONSE_LEN, GFP_KERNEL);
44 return USB_STOR_TRANSPORT_ERROR;
46 memcpy(buffer, rezero_msg, sizeof(rezero_msg));
47 result = usb_stor_bulk_transfer_buf(us,
49 buffer, sizeof(rezero_msg), NULL);
50 if (result != USB_STOR_XFER_GOOD) {
51 result = USB_STOR_XFER_ERROR;
56 * Some of the devices need to be asked for a response, but we don't
57 * care what that response is.
59 usb_stor_bulk_transfer_buf(us,
61 buffer, RESPONSE_LEN, NULL);
64 usb_stor_bulk_transfer_buf(us,
68 result = USB_STOR_XFER_GOOD;
75 static int option_inquiry(struct us_data *us)
77 static const unsigned char inquiry_msg[] = {
78 0x55, 0x53, 0x42, 0x43, 0x12, 0x34, 0x56, 0x78,
79 0x24, 0x00, 0x00, 0x00, 0x80, 0x00, 0x06, 0x12,
80 0x00, 0x00, 0x00, 0x24, 0x00, 0x00, 0x00, 0x00,
81 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
86 usb_stor_dbg(us, "Option MS: %s\n", "device inquiry for vendor name");
88 buffer = kzalloc(0x24, GFP_KERNEL);
90 return USB_STOR_TRANSPORT_ERROR;
92 memcpy(buffer, inquiry_msg, sizeof(inquiry_msg));
93 result = usb_stor_bulk_transfer_buf(us,
95 buffer, sizeof(inquiry_msg), NULL);
96 if (result != USB_STOR_XFER_GOOD) {
97 result = USB_STOR_XFER_ERROR;
101 result = usb_stor_bulk_transfer_buf(us,
104 if (result != USB_STOR_XFER_GOOD) {
105 result = USB_STOR_XFER_ERROR;
109 result = memcmp(buffer+8, "Option", 6);
112 result = memcmp(buffer+8, "ZCOPTION", 8);
115 usb_stor_bulk_transfer_buf(us,
125 int option_ms_init(struct us_data *us)
129 usb_stor_dbg(us, "Option MS: %s\n", "option_ms_init called");
132 * Additional test for vendor information via INQUIRY,
133 * because some vendor/product IDs are ambiguous
135 result = option_inquiry(us);
137 usb_stor_dbg(us, "Option MS: %s\n",
138 "vendor is not Option or not determinable, no action taken");
141 usb_stor_dbg(us, "Option MS: %s\n",
142 "this is a genuine Option device, proceeding");
144 /* Force Modem mode */
145 if (option_zero_cd == ZCD_FORCE_MODEM) {
146 usb_stor_dbg(us, "Option MS: %s\n", "Forcing Modem Mode");
147 result = option_rezero(us);
148 if (result != USB_STOR_XFER_GOOD)
149 usb_stor_dbg(us, "Option MS: %s\n",
150 "Failed to switch to modem mode");
152 } else if (option_zero_cd == ZCD_ALLOW_MS) {
153 /* Allow Mass Storage mode (keep CD-Rom) */
154 usb_stor_dbg(us, "Option MS: %s\n",
155 "Allowing Mass Storage Mode if device requests it");