blob: 773a5cd38c5aa7773f5b7f1837351a8945b3f084 [file] [log] [blame]
Dan Williams281b0642008-12-14 12:39:22 -05001/*
2 * Driver for Option High Speed Mobile Devices.
3 *
4 * (c) 2008 Dan Williams <dcbw@redhat.com>
5 *
6 * Inspiration taken from sierra_ms.c by Kevin Lloyd <klloyd@sierrawireless.com>
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful, but
14 * WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License along
19 * with this program; if not, write to the Free Software Foundation, Inc.,
20 * 675 Mass Ave, Cambridge, MA 02139, USA.
21 */
22
23#include <linux/usb.h>
24
25#include "usb.h"
26#include "transport.h"
27#include "option_ms.h"
28#include "debug.h"
29
30#define ZCD_FORCE_MODEM 0x01
31#define ZCD_ALLOW_MS 0x02
32
33static unsigned int option_zero_cd = ZCD_FORCE_MODEM;
34module_param(option_zero_cd, uint, S_IRUGO | S_IWUSR);
35MODULE_PARM_DESC(option_zero_cd, "ZeroCD mode (1=Force Modem (default),"
36 " 2=Allow CD-Rom");
37
38#define RESPONSE_LEN 1024
39
Josua Dietze32ebbe72009-05-24 23:21:42 +020040static int option_rezero(struct us_data *us)
Dan Williams281b0642008-12-14 12:39:22 -050041{
42 const unsigned char rezero_msg[] = {
43 0x55, 0x53, 0x42, 0x43, 0x78, 0x56, 0x34, 0x12,
44 0x01, 0x00, 0x00, 0x00, 0x80, 0x00, 0x06, 0x01,
45 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
46 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
47 };
48 char *buffer;
49 int result;
50
51 US_DEBUGP("Option MS: %s", "DEVICE MODE SWITCH\n");
52
53 buffer = kzalloc(RESPONSE_LEN, GFP_KERNEL);
54 if (buffer == NULL)
55 return USB_STOR_TRANSPORT_ERROR;
56
Josua Dietze32ebbe72009-05-24 23:21:42 +020057 memcpy(buffer, rezero_msg, sizeof(rezero_msg));
Dan Williams281b0642008-12-14 12:39:22 -050058 result = usb_stor_bulk_transfer_buf(us,
Josua Dietze32ebbe72009-05-24 23:21:42 +020059 us->send_bulk_pipe,
60 buffer, sizeof(rezero_msg), NULL);
Dan Williams281b0642008-12-14 12:39:22 -050061 if (result != USB_STOR_XFER_GOOD) {
62 result = USB_STOR_XFER_ERROR;
63 goto out;
64 }
65
66 /* Some of the devices need to be asked for a response, but we don't
67 * care what that response is.
68 */
Josua Dietze32ebbe72009-05-24 23:21:42 +020069 usb_stor_bulk_transfer_buf(us,
70 us->recv_bulk_pipe,
Dan Williams281b0642008-12-14 12:39:22 -050071 buffer, RESPONSE_LEN, NULL);
Josua Dietze32ebbe72009-05-24 23:21:42 +020072
73 /* Read the CSW */
74 usb_stor_bulk_transfer_buf(us,
75 us->recv_bulk_pipe,
76 buffer, 13, NULL);
77
Dan Williams281b0642008-12-14 12:39:22 -050078 result = USB_STOR_XFER_GOOD;
79
80out:
81 kfree(buffer);
82 return result;
83}
84
Josua Dietze32ebbe72009-05-24 23:21:42 +020085static int option_inquiry(struct us_data *us)
86{
87 const unsigned char inquiry_msg[] = {
88 0x55, 0x53, 0x42, 0x43, 0x12, 0x34, 0x56, 0x78,
89 0x24, 0x00, 0x00, 0x00, 0x80, 0x00, 0x06, 0x12,
90 0x00, 0x00, 0x00, 0x24, 0x00, 0x00, 0x00, 0x00,
91 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
92 };
93 char *buffer;
94 int result;
95
96 US_DEBUGP("Option MS: %s", "device inquiry for vendor name\n");
97
98 buffer = kzalloc(0x24, GFP_KERNEL);
99 if (buffer == NULL)
100 return USB_STOR_TRANSPORT_ERROR;
101
102 memcpy(buffer, inquiry_msg, sizeof(inquiry_msg));
103 result = usb_stor_bulk_transfer_buf(us,
104 us->send_bulk_pipe,
105 buffer, sizeof(inquiry_msg), NULL);
106 if (result != USB_STOR_XFER_GOOD) {
107 result = USB_STOR_XFER_ERROR;
108 goto out;
109 }
110
111 result = usb_stor_bulk_transfer_buf(us,
112 us->recv_bulk_pipe,
113 buffer, 0x24, NULL);
114 if (result != USB_STOR_XFER_GOOD) {
115 result = USB_STOR_XFER_ERROR;
116 goto out;
117 }
118
119 result = memcmp(buffer+8, "Option", 6);
120
Jonathan McDowell2ab21782009-07-05 12:29:51 +0100121 if (result != 0)
122 result = memcmp(buffer+8, "ZCOPTION", 8);
123
Josua Dietze32ebbe72009-05-24 23:21:42 +0200124 /* Read the CSW */
125 usb_stor_bulk_transfer_buf(us,
126 us->recv_bulk_pipe,
127 buffer, 13, NULL);
128
129out:
130 kfree(buffer);
131 return result;
132}
133
134
Dan Williams281b0642008-12-14 12:39:22 -0500135int option_ms_init(struct us_data *us)
136{
Josua Dietze32ebbe72009-05-24 23:21:42 +0200137 int result;
Dan Williams281b0642008-12-14 12:39:22 -0500138
139 US_DEBUGP("Option MS: option_ms_init called\n");
140
Josua Dietze32ebbe72009-05-24 23:21:42 +0200141 /* Additional test for vendor information via INQUIRY,
142 * because some vendor/product IDs are ambiguous
143 */
144 result = option_inquiry(us);
145 if (result != 0) {
146 US_DEBUGP("Option MS: vendor is not Option or not determinable,"
147 " no action taken\n");
Alan Sternbe475d92009-05-21 17:37:58 -0400148 return 0;
Josua Dietze32ebbe72009-05-24 23:21:42 +0200149 } else
150 US_DEBUGP("Option MS: this is a genuine Option device,"
151 " proceeding\n");
Dan Williams281b0642008-12-14 12:39:22 -0500152
153 /* Force Modem mode */
154 if (option_zero_cd == ZCD_FORCE_MODEM) {
155 US_DEBUGP("Option MS: %s", "Forcing Modem Mode\n");
Josua Dietze32ebbe72009-05-24 23:21:42 +0200156 result = option_rezero(us);
Dan Williams281b0642008-12-14 12:39:22 -0500157 if (result != USB_STOR_XFER_GOOD)
158 US_DEBUGP("Option MS: Failed to switch to modem mode.\n");
159 return -EIO;
160 } else if (option_zero_cd == ZCD_ALLOW_MS) {
161 /* Allow Mass Storage mode (keep CD-Rom) */
162 US_DEBUGP("Option MS: %s", "Allowing Mass Storage Mode if device"
163 " requests it\n");
164 }
165
Alan Sternbe475d92009-05-21 17:37:58 -0400166 return 0;
Dan Williams281b0642008-12-14 12:39:22 -0500167}
168