blob: 8b01176e56e7223854a1040a0c48edba1e5ecfc6 [file] [log] [blame]
Ofir Cohenaef90b72012-07-31 12:37:04 +02001/*
2 * f_qc_rndis.c -- RNDIS link function driver
3 *
4 * Copyright (C) 2003-2005,2008 David Brownell
5 * Copyright (C) 2003-2004 Robert Schwebel, Benedikt Spranger
6 * Copyright (C) 2008 Nokia Corporation
7 * Copyright (C) 2009 Samsung Electronics
8 * Author: Michal Nazarewicz (mina86@mina86.com)
Amit Blayf9b352b2013-03-04 15:01:40 +02009 * Copyright (c) 2012-2013, The Linux Foundation. All rights reserved.
Ofir Cohenaef90b72012-07-31 12:37:04 +020010 *
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License version 2
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 */
23
24/* #define VERBOSE_DEBUG */
25
26#include <linux/slab.h>
27#include <linux/kernel.h>
28#include <linux/device.h>
29#include <linux/etherdevice.h>
30
31#include <linux/atomic.h>
32
33#include "u_ether.h"
34#include "u_qc_ether.h"
35#include "rndis.h"
36
37
38/*
39 * This function is an RNDIS Ethernet port -- a Microsoft protocol that's
40 * been promoted instead of the standard CDC Ethernet. The published RNDIS
41 * spec is ambiguous, incomplete, and needlessly complex. Variants such as
42 * ActiveSync have even worse status in terms of specification.
43 *
44 * In short: it's a protocol controlled by (and for) Microsoft, not for an
45 * Open ecosystem or markets. Linux supports it *only* because Microsoft
46 * doesn't support the CDC Ethernet standard.
47 *
48 * The RNDIS data transfer model is complex, with multiple Ethernet packets
49 * per USB message, and out of band data. The control model is built around
50 * what's essentially an "RNDIS RPC" protocol. It's all wrapped in a CDC ACM
51 * (modem, not Ethernet) veneer, with those ACM descriptors being entirely
52 * useless (they're ignored). RNDIS expects to be the only function in its
53 * configuration, so it's no real help if you need composite devices; and
54 * it expects to be the first configuration too.
55 *
56 * There is a single technical advantage of RNDIS over CDC Ethernet, if you
57 * discount the fluff that its RPC can be made to deliver: it doesn't need
58 * a NOP altsetting for the data interface. That lets it work on some of the
59 * "so smart it's stupid" hardware which takes over configuration changes
60 * from the software, and adds restrictions like "no altsettings".
61 *
62 * Unfortunately MSFT's RNDIS drivers are buggy. They hang or oops, and
63 * have all sorts of contrary-to-specification oddities that can prevent
64 * them from working sanely. Since bugfixes (or accurate specs, letting
65 * Linux work around those bugs) are unlikely to ever come from MSFT, you
66 * may want to avoid using RNDIS on purely operational grounds.
67 *
68 * Omissions from the RNDIS 1.0 specification include:
69 *
70 * - Power management ... references data that's scattered around lots
71 * of other documentation, which is incorrect/incomplete there too.
72 *
73 * - There are various undocumented protocol requirements, like the need
74 * to send garbage in some control-OUT messages.
75 *
76 * - MS-Windows drivers sometimes emit undocumented requests.
77 *
78 * This function is based on RNDIS link function driver and
79 * contains MSM specific implementation.
80 */
81
82struct f_rndis_qc {
83 struct qc_gether port;
84 u8 ctrl_id, data_id;
85 u8 ethaddr[ETH_ALEN];
86 u32 vendorID;
87 u8 max_pkt_per_xfer;
Anna Perelce47ed42012-12-05 14:31:07 +020088 u32 max_pkt_size;
Ofir Cohenaef90b72012-07-31 12:37:04 +020089 const char *manufacturer;
90 int config;
91 atomic_t ioctl_excl;
92 atomic_t open_excl;
93
94 struct usb_ep *notify;
95 struct usb_request *notify_req;
96 atomic_t notify_count;
Anna Perela6d730742012-12-17 09:43:16 +020097 struct data_port bam_port;
Ofir Cohenaef90b72012-07-31 12:37:04 +020098};
99
100static inline struct f_rndis_qc *func_to_rndis_qc(struct usb_function *f)
101{
102 return container_of(f, struct f_rndis_qc, port.func);
103}
104
105/* peak (theoretical) bulk transfer rate in bits-per-second */
106static unsigned int rndis_qc_bitrate(struct usb_gadget *g)
107{
108 if (gadget_is_superspeed(g) && g->speed == USB_SPEED_SUPER)
109 return 13 * 1024 * 8 * 1000 * 8;
110 else if (gadget_is_dualspeed(g) && g->speed == USB_SPEED_HIGH)
111 return 13 * 512 * 8 * 1000 * 8;
112 else
113 return 19 * 64 * 1 * 1000 * 8;
114}
115
116/*-------------------------------------------------------------------------*/
117
118#define RNDIS_QC_LOG2_STATUS_INTERVAL_MSEC 5 /* 1 << 5 == 32 msec */
119#define RNDIS_QC_STATUS_BYTECOUNT 8 /* 8 bytes data */
120
Anna Perela6d730742012-12-17 09:43:16 +0200121/* currently only one rndis instance is supported - port
122 * index 0.
123 */
124#define RNDIS_QC_NO_PORTS 1
125#define RNDIS_QC_ACTIVE_PORT 0
Ofir Cohenaef90b72012-07-31 12:37:04 +0200126
127/* default max packets per tarnsfer value */
128#define DEFAULT_MAX_PKT_PER_XFER 15
129
130
131#define RNDIS_QC_IOCTL_MAGIC 'i'
132#define RNDIS_QC_GET_MAX_PKT_PER_XFER _IOR(RNDIS_QC_IOCTL_MAGIC, 1, u8)
Anna Perelce47ed42012-12-05 14:31:07 +0200133#define RNDIS_QC_GET_MAX_PKT_SIZE _IOR(RNDIS_QC_IOCTL_MAGIC, 2, u32)
Ofir Cohenaef90b72012-07-31 12:37:04 +0200134
135
136/* interface descriptor: */
137
138static struct usb_interface_descriptor rndis_qc_control_intf = {
139 .bLength = sizeof rndis_qc_control_intf,
140 .bDescriptorType = USB_DT_INTERFACE,
141
142 /* .bInterfaceNumber = DYNAMIC */
143 /* status endpoint is optional; this could be patched later */
144 .bNumEndpoints = 1,
145 .bInterfaceClass = USB_CLASS_COMM,
146 .bInterfaceSubClass = USB_CDC_SUBCLASS_ACM,
147 .bInterfaceProtocol = USB_CDC_ACM_PROTO_VENDOR,
148 /* .iInterface = DYNAMIC */
149};
150
151static struct usb_cdc_header_desc rndis_qc_header_desc = {
152 .bLength = sizeof rndis_qc_header_desc,
153 .bDescriptorType = USB_DT_CS_INTERFACE,
154 .bDescriptorSubType = USB_CDC_HEADER_TYPE,
155
156 .bcdCDC = cpu_to_le16(0x0110),
157};
158
159static struct usb_cdc_call_mgmt_descriptor rndis_qc_call_mgmt_descriptor = {
160 .bLength = sizeof rndis_qc_call_mgmt_descriptor,
161 .bDescriptorType = USB_DT_CS_INTERFACE,
162 .bDescriptorSubType = USB_CDC_CALL_MANAGEMENT_TYPE,
163
164 .bmCapabilities = 0x00,
165 .bDataInterface = 0x01,
166};
167
168static struct usb_cdc_acm_descriptor rndis_qc_acm_descriptor = {
169 .bLength = sizeof rndis_qc_acm_descriptor,
170 .bDescriptorType = USB_DT_CS_INTERFACE,
171 .bDescriptorSubType = USB_CDC_ACM_TYPE,
172
173 .bmCapabilities = 0x00,
174};
175
176static struct usb_cdc_union_desc rndis_qc_union_desc = {
177 .bLength = sizeof(rndis_qc_union_desc),
178 .bDescriptorType = USB_DT_CS_INTERFACE,
179 .bDescriptorSubType = USB_CDC_UNION_TYPE,
180 /* .bMasterInterface0 = DYNAMIC */
181 /* .bSlaveInterface0 = DYNAMIC */
182};
183
184/* the data interface has two bulk endpoints */
185
186static struct usb_interface_descriptor rndis_qc_data_intf = {
187 .bLength = sizeof rndis_qc_data_intf,
188 .bDescriptorType = USB_DT_INTERFACE,
189
190 /* .bInterfaceNumber = DYNAMIC */
191 .bNumEndpoints = 2,
192 .bInterfaceClass = USB_CLASS_CDC_DATA,
193 .bInterfaceSubClass = 0,
194 .bInterfaceProtocol = 0,
195 /* .iInterface = DYNAMIC */
196};
197
198
199static struct usb_interface_assoc_descriptor
200rndis_qc_iad_descriptor = {
201 .bLength = sizeof rndis_qc_iad_descriptor,
202 .bDescriptorType = USB_DT_INTERFACE_ASSOCIATION,
203 .bFirstInterface = 0, /* XXX, hardcoded */
204 .bInterfaceCount = 2, /* control + data */
205 .bFunctionClass = USB_CLASS_COMM,
206 .bFunctionSubClass = USB_CDC_SUBCLASS_ETHERNET,
207 .bFunctionProtocol = USB_CDC_PROTO_NONE,
208 /* .iFunction = DYNAMIC */
209};
210
211/* full speed support: */
212
213static struct usb_endpoint_descriptor rndis_qc_fs_notify_desc = {
214 .bLength = USB_DT_ENDPOINT_SIZE,
215 .bDescriptorType = USB_DT_ENDPOINT,
216
217 .bEndpointAddress = USB_DIR_IN,
218 .bmAttributes = USB_ENDPOINT_XFER_INT,
219 .wMaxPacketSize = cpu_to_le16(RNDIS_QC_STATUS_BYTECOUNT),
220 .bInterval = 1 << RNDIS_QC_LOG2_STATUS_INTERVAL_MSEC,
221};
222
223static struct usb_endpoint_descriptor rndis_qc_fs_in_desc = {
224 .bLength = USB_DT_ENDPOINT_SIZE,
225 .bDescriptorType = USB_DT_ENDPOINT,
226
227 .bEndpointAddress = USB_DIR_IN,
228 .bmAttributes = USB_ENDPOINT_XFER_BULK,
229};
230
231static struct usb_endpoint_descriptor rndis_qc_fs_out_desc = {
232 .bLength = USB_DT_ENDPOINT_SIZE,
233 .bDescriptorType = USB_DT_ENDPOINT,
234
235 .bEndpointAddress = USB_DIR_OUT,
236 .bmAttributes = USB_ENDPOINT_XFER_BULK,
237};
238
239static struct usb_descriptor_header *eth_qc_fs_function[] = {
240 (struct usb_descriptor_header *) &rndis_qc_iad_descriptor,
241 /* control interface matches ACM, not Ethernet */
242 (struct usb_descriptor_header *) &rndis_qc_control_intf,
243 (struct usb_descriptor_header *) &rndis_qc_header_desc,
244 (struct usb_descriptor_header *) &rndis_qc_call_mgmt_descriptor,
245 (struct usb_descriptor_header *) &rndis_qc_acm_descriptor,
246 (struct usb_descriptor_header *) &rndis_qc_union_desc,
247 (struct usb_descriptor_header *) &rndis_qc_fs_notify_desc,
248 /* data interface has no altsetting */
249 (struct usb_descriptor_header *) &rndis_qc_data_intf,
250 (struct usb_descriptor_header *) &rndis_qc_fs_in_desc,
251 (struct usb_descriptor_header *) &rndis_qc_fs_out_desc,
252 NULL,
253};
254
255/* high speed support: */
256
257static struct usb_endpoint_descriptor rndis_qc_hs_notify_desc = {
258 .bLength = USB_DT_ENDPOINT_SIZE,
259 .bDescriptorType = USB_DT_ENDPOINT,
260
261 .bEndpointAddress = USB_DIR_IN,
262 .bmAttributes = USB_ENDPOINT_XFER_INT,
263 .wMaxPacketSize = cpu_to_le16(RNDIS_QC_STATUS_BYTECOUNT),
264 .bInterval = RNDIS_QC_LOG2_STATUS_INTERVAL_MSEC + 4,
265};
266static struct usb_endpoint_descriptor rndis_qc_hs_in_desc = {
267 .bLength = USB_DT_ENDPOINT_SIZE,
268 .bDescriptorType = USB_DT_ENDPOINT,
269
270 .bEndpointAddress = USB_DIR_IN,
271 .bmAttributes = USB_ENDPOINT_XFER_BULK,
272 .wMaxPacketSize = cpu_to_le16(512),
273};
274
275static struct usb_endpoint_descriptor rndis_qc_hs_out_desc = {
276 .bLength = USB_DT_ENDPOINT_SIZE,
277 .bDescriptorType = USB_DT_ENDPOINT,
278
279 .bEndpointAddress = USB_DIR_OUT,
280 .bmAttributes = USB_ENDPOINT_XFER_BULK,
281 .wMaxPacketSize = cpu_to_le16(512),
282};
283
284static struct usb_descriptor_header *eth_qc_hs_function[] = {
285 (struct usb_descriptor_header *) &rndis_qc_iad_descriptor,
286 /* control interface matches ACM, not Ethernet */
287 (struct usb_descriptor_header *) &rndis_qc_control_intf,
288 (struct usb_descriptor_header *) &rndis_qc_header_desc,
289 (struct usb_descriptor_header *) &rndis_qc_call_mgmt_descriptor,
290 (struct usb_descriptor_header *) &rndis_qc_acm_descriptor,
291 (struct usb_descriptor_header *) &rndis_qc_union_desc,
292 (struct usb_descriptor_header *) &rndis_qc_hs_notify_desc,
293 /* data interface has no altsetting */
294 (struct usb_descriptor_header *) &rndis_qc_data_intf,
295 (struct usb_descriptor_header *) &rndis_qc_hs_in_desc,
296 (struct usb_descriptor_header *) &rndis_qc_hs_out_desc,
297 NULL,
298};
299
300/* super speed support: */
301
302static struct usb_endpoint_descriptor rndis_qc_ss_notify_desc = {
303 .bLength = USB_DT_ENDPOINT_SIZE,
304 .bDescriptorType = USB_DT_ENDPOINT,
305
306 .bEndpointAddress = USB_DIR_IN,
307 .bmAttributes = USB_ENDPOINT_XFER_INT,
308 .wMaxPacketSize = cpu_to_le16(STATUS_BYTECOUNT),
309 .bInterval = LOG2_STATUS_INTERVAL_MSEC + 4,
310};
311
312static struct usb_ss_ep_comp_descriptor rndis_qc_ss_intr_comp_desc = {
313 .bLength = sizeof ss_intr_comp_desc,
314 .bDescriptorType = USB_DT_SS_ENDPOINT_COMP,
315
316 /* the following 3 values can be tweaked if necessary */
317 /* .bMaxBurst = 0, */
318 /* .bmAttributes = 0, */
319 .wBytesPerInterval = cpu_to_le16(STATUS_BYTECOUNT),
320};
321
322static struct usb_endpoint_descriptor rndis_qc_ss_in_desc = {
323 .bLength = USB_DT_ENDPOINT_SIZE,
324 .bDescriptorType = USB_DT_ENDPOINT,
325
326 .bEndpointAddress = USB_DIR_IN,
327 .bmAttributes = USB_ENDPOINT_XFER_BULK,
328 .wMaxPacketSize = cpu_to_le16(1024),
329};
330
331static struct usb_endpoint_descriptor rndis_qc_ss_out_desc = {
332 .bLength = USB_DT_ENDPOINT_SIZE,
333 .bDescriptorType = USB_DT_ENDPOINT,
334
335 .bEndpointAddress = USB_DIR_OUT,
336 .bmAttributes = USB_ENDPOINT_XFER_BULK,
337 .wMaxPacketSize = cpu_to_le16(1024),
338};
339
340static struct usb_ss_ep_comp_descriptor rndis_qc_ss_bulk_comp_desc = {
341 .bLength = sizeof ss_bulk_comp_desc,
342 .bDescriptorType = USB_DT_SS_ENDPOINT_COMP,
343
344 /* the following 2 values can be tweaked if necessary */
345 /* .bMaxBurst = 0, */
346 /* .bmAttributes = 0, */
347};
348
349static struct usb_descriptor_header *eth_qc_ss_function[] = {
350 (struct usb_descriptor_header *) &rndis_iad_descriptor,
351
352 /* control interface matches ACM, not Ethernet */
353 (struct usb_descriptor_header *) &rndis_qc_control_intf,
354 (struct usb_descriptor_header *) &rndis_qc_header_desc,
355 (struct usb_descriptor_header *) &rndis_qc_call_mgmt_descriptor,
356 (struct usb_descriptor_header *) &rndis_qc_acm_descriptor,
357 (struct usb_descriptor_header *) &rndis_qc_union_desc,
358 (struct usb_descriptor_header *) &rndis_qc_ss_notify_desc,
359 (struct usb_descriptor_header *) &rndis_qc_ss_intr_comp_desc,
360
361 /* data interface has no altsetting */
362 (struct usb_descriptor_header *) &rndis_qc_data_intf,
363 (struct usb_descriptor_header *) &rndis_qc_ss_in_desc,
364 (struct usb_descriptor_header *) &rndis_qc_ss_bulk_comp_desc,
365 (struct usb_descriptor_header *) &rndis_qc_ss_out_desc,
366 (struct usb_descriptor_header *) &rndis_qc_ss_bulk_comp_desc,
367 NULL,
368};
369
370/* string descriptors: */
371
372static struct usb_string rndis_qc_string_defs[] = {
373 [0].s = "RNDIS Communications Control",
374 [1].s = "RNDIS Ethernet Data",
375 [2].s = "RNDIS",
376 { } /* end of list */
377};
378
379static struct usb_gadget_strings rndis_qc_string_table = {
380 .language = 0x0409, /* en-us */
381 .strings = rndis_qc_string_defs,
382};
383
384static struct usb_gadget_strings *rndis_qc_strings[] = {
385 &rndis_qc_string_table,
386 NULL,
387};
388
389struct f_rndis_qc *_rndis_qc;
390
391static inline int rndis_qc_lock(atomic_t *excl)
392{
393 if (atomic_inc_return(excl) == 1) {
394 return 0;
395 } else {
396 atomic_dec(excl);
397 return -EBUSY;
398 }
399}
400
401static inline void rndis_qc_unlock(atomic_t *excl)
402{
403 atomic_dec(excl);
404}
405
406/* MSM bam support */
Ofir Cohenaef90b72012-07-31 12:37:04 +0200407
408static int rndis_qc_bam_setup(void)
409{
410 int ret;
411
412 ret = bam_data_setup(RNDIS_QC_NO_PORTS);
413 if (ret) {
414 pr_err("bam_data_setup failed err: %d\n", ret);
415 return ret;
416 }
417
418 return 0;
419}
420
421static int rndis_qc_bam_connect(struct f_rndis_qc *dev)
422{
423 int ret;
Shimrit Malichidbf43d72013-03-16 03:32:27 +0200424 u8 src_connection_idx, dst_connection_idx;
425 struct usb_composite_dev *cdev = dev->port.func.config->cdev;
426 struct usb_gadget *gadget = cdev->gadget;
Ofir Cohenaef90b72012-07-31 12:37:04 +0200427
Shimrit Malichidbf43d72013-03-16 03:32:27 +0200428 dev->bam_port.cdev = cdev;
Anna Perela6d730742012-12-17 09:43:16 +0200429 dev->bam_port.in = dev->port.in_ep;
430 dev->bam_port.out = dev->port.out_ep;
Ofir Cohenaef90b72012-07-31 12:37:04 +0200431
432 /* currently we use the first connection */
Shimrit Malichidbf43d72013-03-16 03:32:27 +0200433 src_connection_idx = usb_bam_get_connection_idx(gadget->name, A2_P_BAM,
434 USB_TO_PEER_PERIPHERAL, 0);
435 dst_connection_idx = usb_bam_get_connection_idx(gadget->name, A2_P_BAM,
436 PEER_PERIPHERAL_TO_USB, 0);
437 if (src_connection_idx < 0 || dst_connection_idx < 0) {
438 pr_err("%s: usb_bam_get_connection_idx failed\n", __func__);
439 return ret;
440 }
Amit Blayf9b352b2013-03-04 15:01:40 +0200441 ret = bam_data_connect(&dev->bam_port, 0, USB_GADGET_XPORT_BAM2BAM,
Shimrit Malichidbf43d72013-03-16 03:32:27 +0200442 src_connection_idx, dst_connection_idx, USB_FUNC_RNDIS);
Ofir Cohenaef90b72012-07-31 12:37:04 +0200443 if (ret) {
444 pr_err("bam_data_connect failed: err:%d\n",
445 ret);
446 return ret;
Ofir Cohenaef90b72012-07-31 12:37:04 +0200447 }
448
Shimrit Malichidbf43d72013-03-16 03:32:27 +0200449 pr_info("rndis bam connected\n");
450
Ofir Cohenaef90b72012-07-31 12:37:04 +0200451 return 0;
452}
453
454static int rndis_qc_bam_disconnect(struct f_rndis_qc *dev)
455{
Amit Blay51bebe92012-12-25 18:48:10 +0200456 pr_debug("dev:%p. %s Disconnect BAM.\n", dev, __func__);
457
458 bam_data_disconnect(&dev->bam_port, 0);
Ofir Cohenaef90b72012-07-31 12:37:04 +0200459
460 return 0;
461}
462
463/*-------------------------------------------------------------------------*/
464
465static struct sk_buff *rndis_qc_add_header(struct qc_gether *port,
466 struct sk_buff *skb)
467{
468 struct sk_buff *skb2;
469
470 skb2 = skb_realloc_headroom(skb, sizeof(struct rndis_packet_msg_type));
471 if (skb2)
472 rndis_add_hdr(skb2);
473
474 dev_kfree_skb_any(skb);
475 return skb2;
476}
477
478int rndis_qc_rm_hdr(struct qc_gether *port,
479 struct sk_buff *skb,
480 struct sk_buff_head *list)
481{
482 /* tmp points to a struct rndis_packet_msg_type */
483 __le32 *tmp = (void *)skb->data;
484
485 /* MessageType, MessageLength */
486 if (cpu_to_le32(REMOTE_NDIS_PACKET_MSG)
487 != get_unaligned(tmp++)) {
488 dev_kfree_skb_any(skb);
489 return -EINVAL;
490 }
491 tmp++;
492
493 /* DataOffset, DataLength */
494 if (!skb_pull(skb, get_unaligned_le32(tmp++) + 8)) {
495 dev_kfree_skb_any(skb);
496 return -EOVERFLOW;
497 }
498 skb_trim(skb, get_unaligned_le32(tmp++));
499
500 skb_queue_tail(list, skb);
501 return 0;
502}
503
504
505static void rndis_qc_response_available(void *_rndis)
506{
507 struct f_rndis_qc *rndis = _rndis;
508 struct usb_request *req = rndis->notify_req;
509 __le32 *data = req->buf;
510 int status;
511
512 if (atomic_inc_return(&rndis->notify_count) != 1)
513 return;
514
515 /* Send RNDIS RESPONSE_AVAILABLE notification; a
516 * USB_CDC_NOTIFY_RESPONSE_AVAILABLE "should" work too
517 *
518 * This is the only notification defined by RNDIS.
519 */
520 data[0] = cpu_to_le32(1);
521 data[1] = cpu_to_le32(0);
522
523 status = usb_ep_queue(rndis->notify, req, GFP_ATOMIC);
524 if (status) {
525 atomic_dec(&rndis->notify_count);
526 pr_info("notify/0 --> %d\n", status);
527 }
528}
529
530static void rndis_qc_response_complete(struct usb_ep *ep,
531 struct usb_request *req)
532{
Jack Pham0ad82e62012-09-27 17:31:08 -0700533 struct f_rndis_qc *rndis = req->context;
Ofir Cohenaef90b72012-07-31 12:37:04 +0200534 int status = req->status;
Jack Pham0ad82e62012-09-27 17:31:08 -0700535 struct usb_composite_dev *cdev = rndis->port.func.config->cdev;
Ofir Cohenaef90b72012-07-31 12:37:04 +0200536
537 /* after TX:
538 * - USB_CDC_GET_ENCAPSULATED_RESPONSE (ep0/control)
539 * - RNDIS_RESPONSE_AVAILABLE (status/irq)
540 */
541 switch (status) {
542 case -ECONNRESET:
543 case -ESHUTDOWN:
544 /* connection gone */
545 atomic_set(&rndis->notify_count, 0);
546 break;
547 default:
548 pr_info("RNDIS %s response error %d, %d/%d\n",
549 ep->name, status,
550 req->actual, req->length);
551 /* FALLTHROUGH */
552 case 0:
553 if (ep != rndis->notify)
554 break;
555
556 /* handle multiple pending RNDIS_RESPONSE_AVAILABLE
557 * notifications by resending until we're done
558 */
559 if (atomic_dec_and_test(&rndis->notify_count))
560 break;
561 status = usb_ep_queue(rndis->notify, req, GFP_ATOMIC);
562 if (status) {
563 atomic_dec(&rndis->notify_count);
564 DBG(cdev, "notify/1 --> %d\n", status);
565 }
566 break;
567 }
568}
569
570static void rndis_qc_command_complete(struct usb_ep *ep,
571 struct usb_request *req)
572{
Anna Perelce47ed42012-12-05 14:31:07 +0200573 struct f_rndis_qc *rndis = req->context;
Ofir Cohenaef90b72012-07-31 12:37:04 +0200574 int status;
Anna Perelce47ed42012-12-05 14:31:07 +0200575 rndis_init_msg_type *buf;
Ofir Cohenaef90b72012-07-31 12:37:04 +0200576
577 /* received RNDIS command from USB_CDC_SEND_ENCAPSULATED_COMMAND */
578 status = rndis_msg_parser(rndis->config, (u8 *) req->buf);
579 if (status < 0)
580 pr_err("RNDIS command error %d, %d/%d\n",
581 status, req->actual, req->length);
Anna Perelce47ed42012-12-05 14:31:07 +0200582
583 buf = (rndis_init_msg_type *)req->buf;
584
585 if (buf->MessageType == REMOTE_NDIS_INITIALIZE_MSG) {
586 rndis->max_pkt_size = buf->MaxTransferSize;
587 pr_debug("MaxTransferSize: %d\n", buf->MaxTransferSize);
588 }
Ofir Cohenaef90b72012-07-31 12:37:04 +0200589}
590
591static int
592rndis_qc_setup(struct usb_function *f, const struct usb_ctrlrequest *ctrl)
593{
594 struct f_rndis_qc *rndis = func_to_rndis_qc(f);
595 struct usb_composite_dev *cdev = f->config->cdev;
596 struct usb_request *req = cdev->req;
597 int value = -EOPNOTSUPP;
598 u16 w_index = le16_to_cpu(ctrl->wIndex);
599 u16 w_value = le16_to_cpu(ctrl->wValue);
600 u16 w_length = le16_to_cpu(ctrl->wLength);
601
602 /* composite driver infrastructure handles everything except
603 * CDC class messages; interface activation uses set_alt().
604 */
605 switch ((ctrl->bRequestType << 8) | ctrl->bRequest) {
606
607 /* RNDIS uses the CDC command encapsulation mechanism to implement
608 * an RPC scheme, with much getting/setting of attributes by OID.
609 */
610 case ((USB_DIR_OUT | USB_TYPE_CLASS | USB_RECIP_INTERFACE) << 8)
611 | USB_CDC_SEND_ENCAPSULATED_COMMAND:
612 if (w_value || w_index != rndis->ctrl_id)
613 goto invalid;
614 /* read the request; process it later */
615 value = w_length;
616 req->complete = rndis_qc_command_complete;
617 req->context = rndis;
618 /* later, rndis_response_available() sends a notification */
619 break;
620
621 case ((USB_DIR_IN | USB_TYPE_CLASS | USB_RECIP_INTERFACE) << 8)
622 | USB_CDC_GET_ENCAPSULATED_RESPONSE:
623 if (w_value || w_index != rndis->ctrl_id)
624 goto invalid;
625 else {
626 u8 *buf;
627 u32 n;
628
629 /* return the result */
630 buf = rndis_get_next_response(rndis->config, &n);
631 if (buf) {
632 memcpy(req->buf, buf, n);
633 req->complete = rndis_qc_response_complete;
634 rndis_free_response(rndis->config, buf);
635 value = n;
636 }
637 /* else stalls ... spec says to avoid that */
638 }
639 break;
640
641 default:
642invalid:
643 VDBG(cdev, "invalid control req%02x.%02x v%04x i%04x l%d\n",
644 ctrl->bRequestType, ctrl->bRequest,
645 w_value, w_index, w_length);
646 }
647
648 /* respond with data transfer or status phase? */
649 if (value >= 0) {
650 DBG(cdev, "rndis req%02x.%02x v%04x i%04x l%d\n",
651 ctrl->bRequestType, ctrl->bRequest,
652 w_value, w_index, w_length);
653 req->zero = (value < w_length);
654 req->length = value;
655 value = usb_ep_queue(cdev->gadget->ep0, req, GFP_ATOMIC);
656 if (value < 0)
657 pr_err("rndis response on err %d\n", value);
658 }
659
660 /* device either stalls (value < 0) or reports success */
661 return value;
662}
663
664
665static int rndis_qc_set_alt(struct usb_function *f, unsigned intf, unsigned alt)
666{
667 struct f_rndis_qc *rndis = func_to_rndis_qc(f);
668 struct usb_composite_dev *cdev = f->config->cdev;
669
670 /* we know alt == 0 */
671
672 if (intf == rndis->ctrl_id) {
673 if (rndis->notify->driver_data) {
674 VDBG(cdev, "reset rndis control %d\n", intf);
675 usb_ep_disable(rndis->notify);
676 }
677 if (!rndis->notify->desc) {
678 VDBG(cdev, "init rndis ctrl %d\n", intf);
679 if (config_ep_by_speed(cdev->gadget, f, rndis->notify))
680 goto fail;
681 }
682 usb_ep_enable(rndis->notify);
683 rndis->notify->driver_data = rndis;
684
685 } else if (intf == rndis->data_id) {
686 struct net_device *net;
687
688 if (rndis->port.in_ep->driver_data) {
689 DBG(cdev, "reset rndis\n");
Amit Blay51bebe92012-12-25 18:48:10 +0200690 /* rndis->port is needed for disconnecting the BAM data
691 * path. Only after the BAM data path is disconnected,
692 * we can disconnect the port from the network layer.
693 */
Ofir Cohenaef90b72012-07-31 12:37:04 +0200694 rndis_qc_bam_disconnect(rndis);
Amit Blay51bebe92012-12-25 18:48:10 +0200695 gether_qc_disconnect_name(&rndis->port, "rndis0");
Ofir Cohenaef90b72012-07-31 12:37:04 +0200696 }
697
698 if (!rndis->port.in_ep->desc || !rndis->port.out_ep->desc) {
699 DBG(cdev, "init rndis\n");
700 if (config_ep_by_speed(cdev->gadget, f,
701 rndis->port.in_ep) ||
702 config_ep_by_speed(cdev->gadget, f,
703 rndis->port.out_ep)) {
704 rndis->port.in_ep->desc = NULL;
705 rndis->port.out_ep->desc = NULL;
706 goto fail;
707 }
708 }
709
710 /* Avoid ZLPs; they can be troublesome. */
711 rndis->port.is_zlp_ok = false;
712
713 /* RNDIS should be in the "RNDIS uninitialized" state,
714 * either never activated or after rndis_uninit().
715 *
716 * We don't want data to flow here until a nonzero packet
717 * filter is set, at which point it enters "RNDIS data
718 * initialized" state ... but we do want the endpoints
719 * to be activated. It's a strange little state.
720 *
721 * REVISIT the RNDIS gadget code has done this wrong for a
722 * very long time. We need another call to the link layer
723 * code -- gether_updown(...bool) maybe -- to do it right.
724 */
725 rndis->port.cdc_filter = 0;
726
727 DBG(cdev, "RNDIS RX/TX early activation ...\n");
Amit Blayd6d690a2012-10-16 13:37:42 +0200728 net = gether_qc_connect_name(&rndis->port, "rndis0");
Ofir Cohenaef90b72012-07-31 12:37:04 +0200729 if (IS_ERR(net))
730 return PTR_ERR(net);
731
732 if (rndis_qc_bam_connect(rndis))
733 goto fail;
734
735 rndis_set_param_dev(rndis->config, net,
736 &rndis->port.cdc_filter);
737 } else
738 goto fail;
739
740 return 0;
741fail:
742 return -EINVAL;
743}
744
745static void rndis_qc_disable(struct usb_function *f)
746{
747 struct f_rndis_qc *rndis = func_to_rndis_qc(f);
748
749 if (!rndis->notify->driver_data)
750 return;
751
752 pr_info("rndis deactivated\n");
753
754 rndis_uninit(rndis->config);
Ofir Cohenaef90b72012-07-31 12:37:04 +0200755 rndis_qc_bam_disconnect(rndis);
Amit Blay51bebe92012-12-25 18:48:10 +0200756 gether_qc_disconnect_name(&rndis->port, "rndis0");
Ofir Cohenaef90b72012-07-31 12:37:04 +0200757
758 usb_ep_disable(rndis->notify);
759 rndis->notify->driver_data = NULL;
760}
761
Anna Perela6d730742012-12-17 09:43:16 +0200762static void rndis_qc_suspend(struct usb_function *f)
763{
764 pr_debug("%s: rndis suspended\n", __func__);
765
766 bam_data_suspend(RNDIS_QC_ACTIVE_PORT);
767}
768
769static void rndis_qc_resume(struct usb_function *f)
770{
771 pr_debug("%s: rndis resumed\n", __func__);
772
773 bam_data_resume(RNDIS_QC_ACTIVE_PORT);
774}
775
Ofir Cohenaef90b72012-07-31 12:37:04 +0200776/*-------------------------------------------------------------------------*/
777
778/*
779 * This isn't quite the same mechanism as CDC Ethernet, since the
780 * notification scheme passes less data, but the same set of link
781 * states must be tested. A key difference is that altsettings are
782 * not used to tell whether the link should send packets or not.
783 */
784
785static void rndis_qc_open(struct qc_gether *geth)
786{
787 struct f_rndis_qc *rndis = func_to_rndis_qc(&geth->func);
788 struct usb_composite_dev *cdev = geth->func.config->cdev;
789
790 DBG(cdev, "%s\n", __func__);
791
792 rndis_set_param_medium(rndis->config, NDIS_MEDIUM_802_3,
793 rndis_qc_bitrate(cdev->gadget) / 100);
794 rndis_signal_connect(rndis->config);
795}
796
797static void rndis_qc_close(struct qc_gether *geth)
798{
799 struct f_rndis_qc *rndis = func_to_rndis_qc(&geth->func);
800
801 DBG(geth->func.config->cdev, "%s\n", __func__);
802
803 rndis_set_param_medium(rndis->config, NDIS_MEDIUM_802_3, 0);
804 rndis_signal_disconnect(rndis->config);
805}
806
807/*-------------------------------------------------------------------------*/
808
809/* ethernet function driver setup/binding */
810
811static int
812rndis_qc_bind(struct usb_configuration *c, struct usb_function *f)
813{
814 struct usb_composite_dev *cdev = c->cdev;
815 struct f_rndis_qc *rndis = func_to_rndis_qc(f);
816 int status;
817 struct usb_ep *ep;
818
819 /* allocate instance-specific interface IDs */
820 status = usb_interface_id(c, f);
821 if (status < 0)
822 goto fail;
823 rndis->ctrl_id = status;
824 rndis_qc_iad_descriptor.bFirstInterface = status;
825
826 rndis_qc_control_intf.bInterfaceNumber = status;
827 rndis_qc_union_desc.bMasterInterface0 = status;
828
829 status = usb_interface_id(c, f);
830 if (status < 0)
831 goto fail;
832 rndis->data_id = status;
833
834 rndis_qc_data_intf.bInterfaceNumber = status;
835 rndis_qc_union_desc.bSlaveInterface0 = status;
836
837 status = -ENODEV;
838
839 /* allocate instance-specific endpoints */
840 ep = usb_ep_autoconfig(cdev->gadget, &rndis_qc_fs_in_desc);
841 if (!ep)
842 goto fail;
843 rndis->port.in_ep = ep;
844 ep->driver_data = cdev; /* claim */
845
846 ep = usb_ep_autoconfig(cdev->gadget, &rndis_qc_fs_out_desc);
847 if (!ep)
848 goto fail;
849 rndis->port.out_ep = ep;
850 ep->driver_data = cdev; /* claim */
851
852 /* NOTE: a status/notification endpoint is, strictly speaking,
853 * optional. We don't treat it that way though! It's simpler,
854 * and some newer profiles don't treat it as optional.
855 */
856 ep = usb_ep_autoconfig(cdev->gadget, &rndis_qc_fs_notify_desc);
857 if (!ep)
858 goto fail;
859 rndis->notify = ep;
860 ep->driver_data = cdev; /* claim */
861
862 status = -ENOMEM;
863
864 /* allocate notification request and buffer */
865 rndis->notify_req = usb_ep_alloc_request(ep, GFP_KERNEL);
866 if (!rndis->notify_req)
867 goto fail;
868 rndis->notify_req->buf = kmalloc(RNDIS_QC_STATUS_BYTECOUNT, GFP_KERNEL);
869 if (!rndis->notify_req->buf)
870 goto fail;
871 rndis->notify_req->length = RNDIS_QC_STATUS_BYTECOUNT;
872 rndis->notify_req->context = rndis;
873 rndis->notify_req->complete = rndis_qc_response_complete;
874
875 /* copy descriptors, and track endpoint copies */
876 f->descriptors = usb_copy_descriptors(eth_qc_fs_function);
877 if (!f->descriptors)
878 goto fail;
879
880 /* support all relevant hardware speeds... we expect that when
881 * hardware is dual speed, all bulk-capable endpoints work at
882 * both speeds
883 */
884 if (gadget_is_dualspeed(c->cdev->gadget)) {
885 rndis_qc_hs_in_desc.bEndpointAddress =
886 rndis_qc_fs_in_desc.bEndpointAddress;
887 rndis_qc_hs_out_desc.bEndpointAddress =
888 rndis_qc_fs_out_desc.bEndpointAddress;
889 rndis_qc_hs_notify_desc.bEndpointAddress =
890 rndis_qc_fs_notify_desc.bEndpointAddress;
891
892 /* copy descriptors, and track endpoint copies */
893 f->hs_descriptors = usb_copy_descriptors(eth_qc_hs_function);
894
895 if (!f->hs_descriptors)
896 goto fail;
897 }
898
899 if (gadget_is_superspeed(c->cdev->gadget)) {
900 rndis_qc_ss_in_desc.bEndpointAddress =
901 rndis_qc_fs_in_desc.bEndpointAddress;
902 rndis_qc_ss_out_desc.bEndpointAddress =
903 rndis_qc_fs_out_desc.bEndpointAddress;
904 rndis_qc_ss_notify_desc.bEndpointAddress =
905 rndis_qc_fs_notify_desc.bEndpointAddress;
906
907 /* copy descriptors, and track endpoint copies */
908 f->ss_descriptors = usb_copy_descriptors(eth_qc_ss_function);
909 if (!f->ss_descriptors)
910 goto fail;
911 }
912
913 rndis->port.open = rndis_qc_open;
914 rndis->port.close = rndis_qc_close;
915
916 status = rndis_register(rndis_qc_response_available, rndis);
917 if (status < 0)
918 goto fail;
919 rndis->config = status;
920
921 rndis_set_param_medium(rndis->config, NDIS_MEDIUM_802_3, 0);
922 rndis_set_host_mac(rndis->config, rndis->ethaddr);
923
924 if (rndis_set_param_vendor(rndis->config, rndis->vendorID,
925 rndis->manufacturer))
926 goto fail;
927
928 rndis_set_max_pkt_xfer(rndis->config, rndis->max_pkt_per_xfer);
929
Ofir Cohen76624ed2012-09-09 10:27:58 +0300930 /* In case of aggregated packets QC device will request
931 * aliment to 4 (2^2).
932 */
933 rndis_set_pkt_alignment_factor(rndis->config, 2);
934
Ofir Cohenaef90b72012-07-31 12:37:04 +0200935 /* NOTE: all that is done without knowing or caring about
936 * the network link ... which is unavailable to this code
937 * until we're activated via set_alt().
938 */
939
940 DBG(cdev, "RNDIS: %s speed IN/%s OUT/%s NOTIFY/%s\n",
941 gadget_is_superspeed(c->cdev->gadget) ? "super" :
942 gadget_is_dualspeed(c->cdev->gadget) ? "dual" : "full",
943 rndis->port.in_ep->name, rndis->port.out_ep->name,
944 rndis->notify->name);
945 return 0;
946
947fail:
948 if (gadget_is_superspeed(c->cdev->gadget) && f->ss_descriptors)
949 usb_free_descriptors(f->ss_descriptors);
950 if (gadget_is_dualspeed(c->cdev->gadget) && f->hs_descriptors)
951 usb_free_descriptors(f->hs_descriptors);
952 if (f->descriptors)
953 usb_free_descriptors(f->descriptors);
954
955 if (rndis->notify_req) {
956 kfree(rndis->notify_req->buf);
957 usb_ep_free_request(rndis->notify, rndis->notify_req);
958 }
959
960 /* we might as well release our claims on endpoints */
961 if (rndis->notify)
962 rndis->notify->driver_data = NULL;
963 if (rndis->port.out_ep->desc)
964 rndis->port.out_ep->driver_data = NULL;
965 if (rndis->port.in_ep->desc)
966 rndis->port.in_ep->driver_data = NULL;
967
968 pr_err("%s: can't bind, err %d\n", f->name, status);
969
970 return status;
971}
972
973static void
974rndis_qc_unbind(struct usb_configuration *c, struct usb_function *f)
975{
976 struct f_rndis_qc *rndis = func_to_rndis_qc(f);
977
978 rndis_deregister(rndis->config);
979 rndis_exit();
980
981 if (gadget_is_dualspeed(c->cdev->gadget))
982 usb_free_descriptors(f->hs_descriptors);
983 usb_free_descriptors(f->descriptors);
984
985 kfree(rndis->notify_req->buf);
986 usb_ep_free_request(rndis->notify, rndis->notify_req);
987
988 kfree(rndis);
989}
990
991/* Some controllers can't support RNDIS ... */
992static inline bool can_support_rndis_qc(struct usb_configuration *c)
993{
994 /* everything else is *presumably* fine */
995 return true;
996}
997
998/**
999 * rndis_qc_bind_config - add RNDIS network link to a configuration
1000 * @c: the configuration to support the network link
1001 * @ethaddr: a buffer in which the ethernet address of the host side
1002 * side of the link was recorded
1003 * Context: single threaded during gadget setup
1004 *
1005 * Returns zero on success, else negative errno.
1006 *
1007 * Caller must have called @gether_setup(). Caller is also responsible
1008 * for calling @gether_cleanup() before module unload.
1009 */
1010int
1011rndis_qc_bind_config(struct usb_configuration *c, u8 ethaddr[ETH_ALEN])
1012{
1013 return rndis_qc_bind_config_vendor(c, ethaddr, 0, NULL, 1);
1014}
1015
1016int
1017rndis_qc_bind_config_vendor(struct usb_configuration *c, u8 ethaddr[ETH_ALEN],
1018 u32 vendorID, const char *manufacturer,
1019 u8 max_pkt_per_xfer)
1020{
1021 struct f_rndis_qc *rndis;
1022 int status;
1023
1024 if (!can_support_rndis_qc(c) || !ethaddr)
1025 return -EINVAL;
1026
1027 /* setup RNDIS itself */
1028 status = rndis_init();
1029 if (status < 0)
1030 return status;
1031
1032 status = rndis_qc_bam_setup();
1033 if (status) {
1034 pr_err("bam setup failed");
1035 return status;
1036 }
1037
1038 /* maybe allocate device-global string IDs */
1039 if (rndis_qc_string_defs[0].id == 0) {
1040
1041 /* control interface label */
1042 status = usb_string_id(c->cdev);
1043 if (status < 0)
1044 return status;
1045 rndis_qc_string_defs[0].id = status;
1046 rndis_qc_control_intf.iInterface = status;
1047
1048 /* data interface label */
1049 status = usb_string_id(c->cdev);
1050 if (status < 0)
1051 return status;
1052 rndis_qc_string_defs[1].id = status;
1053 rndis_qc_data_intf.iInterface = status;
1054
1055 /* IAD iFunction label */
1056 status = usb_string_id(c->cdev);
1057 if (status < 0)
1058 return status;
1059 rndis_qc_string_defs[2].id = status;
1060 rndis_qc_iad_descriptor.iFunction = status;
1061 }
1062
1063 /* allocate and initialize one new instance */
1064 status = -ENOMEM;
1065 rndis = kzalloc(sizeof *rndis, GFP_KERNEL);
1066 if (!rndis)
1067 goto fail;
1068
1069 memcpy(rndis->ethaddr, ethaddr, ETH_ALEN);
1070 rndis->vendorID = vendorID;
1071 rndis->manufacturer = manufacturer;
1072
1073 /* if max_pkt_per_xfer was not configured set to default value */
1074 rndis->max_pkt_per_xfer =
1075 max_pkt_per_xfer ? max_pkt_per_xfer : DEFAULT_MAX_PKT_PER_XFER;
1076
1077 /* RNDIS activates when the host changes this filter */
1078 rndis->port.cdc_filter = 0;
1079
1080 /* RNDIS has special (and complex) framing */
1081 rndis->port.header_len = sizeof(struct rndis_packet_msg_type);
1082 rndis->port.wrap = rndis_qc_add_header;
1083 rndis->port.unwrap = rndis_qc_rm_hdr;
1084
1085 rndis->port.func.name = "rndis";
1086 rndis->port.func.strings = rndis_qc_strings;
1087 /* descriptors are per-instance copies */
1088 rndis->port.func.bind = rndis_qc_bind;
1089 rndis->port.func.unbind = rndis_qc_unbind;
1090 rndis->port.func.set_alt = rndis_qc_set_alt;
1091 rndis->port.func.setup = rndis_qc_setup;
1092 rndis->port.func.disable = rndis_qc_disable;
Anna Perela6d730742012-12-17 09:43:16 +02001093 rndis->port.func.suspend = rndis_qc_suspend;
1094 rndis->port.func.resume = rndis_qc_resume;
Ofir Cohenaef90b72012-07-31 12:37:04 +02001095
1096 _rndis_qc = rndis;
1097
1098 status = usb_add_function(c, &rndis->port.func);
1099 if (status) {
1100 kfree(rndis);
1101fail:
1102 rndis_exit();
1103 }
1104 return status;
1105}
1106
1107static int rndis_qc_open_dev(struct inode *ip, struct file *fp)
1108{
1109 pr_info("Open rndis QC driver\n");
1110
1111 if (!_rndis_qc) {
1112 pr_err("rndis_qc_dev not created yet\n");
1113 return -ENODEV;
1114 }
1115
1116 if (rndis_qc_lock(&_rndis_qc->open_excl)) {
1117 pr_err("Already opened\n");
1118 return -EBUSY;
1119 }
1120
1121 fp->private_data = _rndis_qc;
1122 pr_info("rndis QC file opened\n");
1123
1124 return 0;
1125}
1126
1127static int rndis_qc_release_dev(struct inode *ip, struct file *fp)
1128{
1129 struct f_rndis_qc *rndis = fp->private_data;
1130
1131 pr_info("Close rndis QC file");
1132 rndis_qc_unlock(&rndis->open_excl);
1133
1134 return 0;
1135}
1136
1137static long rndis_qc_ioctl(struct file *fp, unsigned cmd, unsigned long arg)
1138{
1139 struct f_rndis_qc *rndis = fp->private_data;
1140 int ret = 0;
1141
1142 pr_info("Received command %d", cmd);
1143
1144 if (rndis_qc_lock(&rndis->ioctl_excl))
1145 return -EBUSY;
1146
1147 switch (cmd) {
1148 case RNDIS_QC_GET_MAX_PKT_PER_XFER:
1149 ret = copy_to_user((void __user *)arg,
1150 &rndis->max_pkt_per_xfer,
1151 sizeof(rndis->max_pkt_per_xfer));
1152 if (ret) {
1153 pr_err("copying to user space failed");
1154 ret = -EFAULT;
1155 }
1156 pr_info("Sent max packets per xfer %d",
1157 rndis->max_pkt_per_xfer);
1158 break;
Anna Perelce47ed42012-12-05 14:31:07 +02001159 case RNDIS_QC_GET_MAX_PKT_SIZE:
1160 ret = copy_to_user((void __user *)arg,
1161 &rndis->max_pkt_size,
1162 sizeof(rndis->max_pkt_size));
1163 if (ret) {
1164 pr_err("copying to user space failed");
1165 ret = -EFAULT;
1166 }
1167 pr_debug("Sent max packet size %d",
1168 rndis->max_pkt_size);
1169 break;
Ofir Cohenaef90b72012-07-31 12:37:04 +02001170 default:
1171 pr_err("Unsupported IOCTL");
1172 ret = -EINVAL;
1173 }
1174
1175 rndis_qc_unlock(&rndis->ioctl_excl);
1176
1177 return ret;
1178}
1179
1180static const struct file_operations rndis_qc_fops = {
1181 .owner = THIS_MODULE,
1182 .open = rndis_qc_open_dev,
1183 .release = rndis_qc_release_dev,
1184 .unlocked_ioctl = rndis_qc_ioctl,
1185};
1186
1187static struct miscdevice rndis_qc_device = {
1188 .minor = MISC_DYNAMIC_MINOR,
1189 .name = "android_rndis_qc",
1190 .fops = &rndis_qc_fops,
1191};
1192
1193static int rndis_qc_init(void)
1194{
1195 int ret;
1196
1197 pr_info("initialize rndis QC instance\n");
1198
1199 ret = misc_register(&rndis_qc_device);
1200 if (ret)
1201 pr_err("rndis QC driver failed to register");
1202
1203 return ret;
1204}
1205
1206static void rndis_qc_cleanup(void)
1207{
1208 pr_info("rndis QC cleanup");
1209
1210 misc_deregister(&rndis_qc_device);
1211 _rndis_qc = NULL;
1212}
1213
1214