blob: 437198b6d8fa74e70adc2ec1b35c57a13a3ace98 [file] [log] [blame]
David Brownell45fe3b82008-06-19 18:20:04 -07001/*
2 * f_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
Michal Nazarewiczb97503f2009-10-28 16:57:30 +01007 * Copyright (C) 2009 Samsung Electronics
Michal Nazarewicz54b83602012-01-13 15:05:16 +01008 * Author: Michal Nazarewicz (mina86@mina86.com)
David Brownell45fe3b82008-06-19 18:20:04 -07009 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
David Brownell45fe3b82008-06-19 18:20:04 -070014 */
15
16/* #define VERBOSE_DEBUG */
17
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090018#include <linux/slab.h>
David Brownell45fe3b82008-06-19 18:20:04 -070019#include <linux/kernel.h>
Andrzej Pietrasiewiczf466c632013-05-28 09:15:57 +020020#include <linux/module.h>
David Brownell45fe3b82008-06-19 18:20:04 -070021#include <linux/device.h>
22#include <linux/etherdevice.h>
23
Arun Sharma600634972011-07-26 16:09:06 -070024#include <linux/atomic.h>
David Brownell45fe3b82008-06-19 18:20:04 -070025
26#include "u_ether.h"
Andrzej Pietrasiewiczf466c632013-05-28 09:15:57 +020027#include "u_rndis.h"
David Brownell45fe3b82008-06-19 18:20:04 -070028#include "rndis.h"
29
David Brownell45fe3b82008-06-19 18:20:04 -070030/*
31 * This function is an RNDIS Ethernet port -- a Microsoft protocol that's
32 * been promoted instead of the standard CDC Ethernet. The published RNDIS
33 * spec is ambiguous, incomplete, and needlessly complex. Variants such as
34 * ActiveSync have even worse status in terms of specification.
35 *
36 * In short: it's a protocol controlled by (and for) Microsoft, not for an
37 * Open ecosystem or markets. Linux supports it *only* because Microsoft
38 * doesn't support the CDC Ethernet standard.
39 *
40 * The RNDIS data transfer model is complex, with multiple Ethernet packets
41 * per USB message, and out of band data. The control model is built around
42 * what's essentially an "RNDIS RPC" protocol. It's all wrapped in a CDC ACM
43 * (modem, not Ethernet) veneer, with those ACM descriptors being entirely
44 * useless (they're ignored). RNDIS expects to be the only function in its
45 * configuration, so it's no real help if you need composite devices; and
46 * it expects to be the first configuration too.
47 *
48 * There is a single technical advantage of RNDIS over CDC Ethernet, if you
49 * discount the fluff that its RPC can be made to deliver: it doesn't need
50 * a NOP altsetting for the data interface. That lets it work on some of the
51 * "so smart it's stupid" hardware which takes over configuration changes
52 * from the software, and adds restrictions like "no altsettings".
53 *
54 * Unfortunately MSFT's RNDIS drivers are buggy. They hang or oops, and
55 * have all sorts of contrary-to-specification oddities that can prevent
56 * them from working sanely. Since bugfixes (or accurate specs, letting
57 * Linux work around those bugs) are unlikely to ever come from MSFT, you
58 * may want to avoid using RNDIS on purely operational grounds.
59 *
60 * Omissions from the RNDIS 1.0 specification include:
61 *
62 * - Power management ... references data that's scattered around lots
63 * of other documentation, which is incorrect/incomplete there too.
64 *
65 * - There are various undocumented protocol requirements, like the need
66 * to send garbage in some control-OUT messages.
67 *
68 * - MS-Windows drivers sometimes emit undocumented requests.
69 */
70
David Brownell45fe3b82008-06-19 18:20:04 -070071struct f_rndis {
72 struct gether port;
73 u8 ctrl_id, data_id;
74 u8 ethaddr[ETH_ALEN];
Benoit Goby1fbfeff2012-05-10 10:08:04 +020075 u32 vendorID;
76 const char *manufacturer;
David Brownell45fe3b82008-06-19 18:20:04 -070077 int config;
78
David Brownell45fe3b82008-06-19 18:20:04 -070079 struct usb_ep *notify;
David Brownell45fe3b82008-06-19 18:20:04 -070080 struct usb_request *notify_req;
81 atomic_t notify_count;
82};
83
84static inline struct f_rndis *func_to_rndis(struct usb_function *f)
85{
86 return container_of(f, struct f_rndis, port.func);
87}
88
89/* peak (theoretical) bulk transfer rate in bits-per-second */
90static unsigned int bitrate(struct usb_gadget *g)
91{
Paul Zimmerman04617db2011-06-27 14:13:18 -070092 if (gadget_is_superspeed(g) && g->speed == USB_SPEED_SUPER)
93 return 13 * 1024 * 8 * 1000 * 8;
94 else if (gadget_is_dualspeed(g) && g->speed == USB_SPEED_HIGH)
David Brownell45fe3b82008-06-19 18:20:04 -070095 return 13 * 512 * 8 * 1000 * 8;
96 else
Paul Zimmerman04617db2011-06-27 14:13:18 -070097 return 19 * 64 * 1 * 1000 * 8;
David Brownell45fe3b82008-06-19 18:20:04 -070098}
99
100/*-------------------------------------------------------------------------*/
101
102/*
103 */
104
Sebastian Andrzej Siewiorbcb2f992012-10-22 22:14:57 +0200105#define RNDIS_STATUS_INTERVAL_MS 32
David Brownell45fe3b82008-06-19 18:20:04 -0700106#define STATUS_BYTECOUNT 8 /* 8 bytes data */
107
108
109/* interface descriptor: */
110
Michal Nazarewicz28824b12010-05-05 12:53:13 +0200111static struct usb_interface_descriptor rndis_control_intf = {
David Brownell45fe3b82008-06-19 18:20:04 -0700112 .bLength = sizeof rndis_control_intf,
113 .bDescriptorType = USB_DT_INTERFACE,
114
115 /* .bInterfaceNumber = DYNAMIC */
116 /* status endpoint is optional; this could be patched later */
117 .bNumEndpoints = 1,
118 .bInterfaceClass = USB_CLASS_COMM,
119 .bInterfaceSubClass = USB_CDC_SUBCLASS_ACM,
120 .bInterfaceProtocol = USB_CDC_ACM_PROTO_VENDOR,
121 /* .iInterface = DYNAMIC */
122};
123
Michal Nazarewicz28824b12010-05-05 12:53:13 +0200124static struct usb_cdc_header_desc header_desc = {
David Brownell45fe3b82008-06-19 18:20:04 -0700125 .bLength = sizeof header_desc,
126 .bDescriptorType = USB_DT_CS_INTERFACE,
127 .bDescriptorSubType = USB_CDC_HEADER_TYPE,
128
Harvey Harrison551509d2009-02-11 14:11:36 -0800129 .bcdCDC = cpu_to_le16(0x0110),
David Brownell45fe3b82008-06-19 18:20:04 -0700130};
131
Michal Nazarewicz28824b12010-05-05 12:53:13 +0200132static struct usb_cdc_call_mgmt_descriptor call_mgmt_descriptor = {
David Brownell45fe3b82008-06-19 18:20:04 -0700133 .bLength = sizeof call_mgmt_descriptor,
134 .bDescriptorType = USB_DT_CS_INTERFACE,
135 .bDescriptorSubType = USB_CDC_CALL_MANAGEMENT_TYPE,
136
137 .bmCapabilities = 0x00,
138 .bDataInterface = 0x01,
139};
140
Michal Nazarewicz28824b12010-05-05 12:53:13 +0200141static struct usb_cdc_acm_descriptor rndis_acm_descriptor = {
Michal Nazarewiczb97503f2009-10-28 16:57:30 +0100142 .bLength = sizeof rndis_acm_descriptor,
David Brownell45fe3b82008-06-19 18:20:04 -0700143 .bDescriptorType = USB_DT_CS_INTERFACE,
144 .bDescriptorSubType = USB_CDC_ACM_TYPE,
145
146 .bmCapabilities = 0x00,
147};
148
Michal Nazarewicz28824b12010-05-05 12:53:13 +0200149static struct usb_cdc_union_desc rndis_union_desc = {
David Brownell45fe3b82008-06-19 18:20:04 -0700150 .bLength = sizeof(rndis_union_desc),
151 .bDescriptorType = USB_DT_CS_INTERFACE,
152 .bDescriptorSubType = USB_CDC_UNION_TYPE,
153 /* .bMasterInterface0 = DYNAMIC */
154 /* .bSlaveInterface0 = DYNAMIC */
155};
156
157/* the data interface has two bulk endpoints */
158
Michal Nazarewicz28824b12010-05-05 12:53:13 +0200159static struct usb_interface_descriptor rndis_data_intf = {
David Brownell45fe3b82008-06-19 18:20:04 -0700160 .bLength = sizeof rndis_data_intf,
161 .bDescriptorType = USB_DT_INTERFACE,
162
163 /* .bInterfaceNumber = DYNAMIC */
David Brownell45fe3b82008-06-19 18:20:04 -0700164 .bNumEndpoints = 2,
165 .bInterfaceClass = USB_CLASS_CDC_DATA,
166 .bInterfaceSubClass = 0,
167 .bInterfaceProtocol = 0,
168 /* .iInterface = DYNAMIC */
169};
170
Michal Nazarewiczb97503f2009-10-28 16:57:30 +0100171
172static struct usb_interface_assoc_descriptor
173rndis_iad_descriptor = {
174 .bLength = sizeof rndis_iad_descriptor,
175 .bDescriptorType = USB_DT_INTERFACE_ASSOCIATION,
176
177 .bFirstInterface = 0, /* XXX, hardcoded */
178 .bInterfaceCount = 2, // control + data
179 .bFunctionClass = USB_CLASS_COMM,
180 .bFunctionSubClass = USB_CDC_SUBCLASS_ETHERNET,
181 .bFunctionProtocol = USB_CDC_PROTO_NONE,
182 /* .iFunction = DYNAMIC */
183};
184
David Brownell45fe3b82008-06-19 18:20:04 -0700185/* full speed support: */
186
Michal Nazarewicz28824b12010-05-05 12:53:13 +0200187static struct usb_endpoint_descriptor fs_notify_desc = {
David Brownell45fe3b82008-06-19 18:20:04 -0700188 .bLength = USB_DT_ENDPOINT_SIZE,
189 .bDescriptorType = USB_DT_ENDPOINT,
190
191 .bEndpointAddress = USB_DIR_IN,
192 .bmAttributes = USB_ENDPOINT_XFER_INT,
Harvey Harrison551509d2009-02-11 14:11:36 -0800193 .wMaxPacketSize = cpu_to_le16(STATUS_BYTECOUNT),
Sebastian Andrzej Siewiorbcb2f992012-10-22 22:14:57 +0200194 .bInterval = RNDIS_STATUS_INTERVAL_MS,
David Brownell45fe3b82008-06-19 18:20:04 -0700195};
196
Michal Nazarewicz28824b12010-05-05 12:53:13 +0200197static struct usb_endpoint_descriptor fs_in_desc = {
David Brownell45fe3b82008-06-19 18:20:04 -0700198 .bLength = USB_DT_ENDPOINT_SIZE,
199 .bDescriptorType = USB_DT_ENDPOINT,
200
201 .bEndpointAddress = USB_DIR_IN,
202 .bmAttributes = USB_ENDPOINT_XFER_BULK,
203};
204
Michal Nazarewicz28824b12010-05-05 12:53:13 +0200205static struct usb_endpoint_descriptor fs_out_desc = {
David Brownell45fe3b82008-06-19 18:20:04 -0700206 .bLength = USB_DT_ENDPOINT_SIZE,
207 .bDescriptorType = USB_DT_ENDPOINT,
208
209 .bEndpointAddress = USB_DIR_OUT,
210 .bmAttributes = USB_ENDPOINT_XFER_BULK,
211};
212
Michal Nazarewicz28824b12010-05-05 12:53:13 +0200213static struct usb_descriptor_header *eth_fs_function[] = {
Michal Nazarewiczb97503f2009-10-28 16:57:30 +0100214 (struct usb_descriptor_header *) &rndis_iad_descriptor,
Paul Zimmerman04617db2011-06-27 14:13:18 -0700215
David Brownell45fe3b82008-06-19 18:20:04 -0700216 /* control interface matches ACM, not Ethernet */
217 (struct usb_descriptor_header *) &rndis_control_intf,
218 (struct usb_descriptor_header *) &header_desc,
219 (struct usb_descriptor_header *) &call_mgmt_descriptor,
Michal Nazarewiczb97503f2009-10-28 16:57:30 +0100220 (struct usb_descriptor_header *) &rndis_acm_descriptor,
David Brownell45fe3b82008-06-19 18:20:04 -0700221 (struct usb_descriptor_header *) &rndis_union_desc,
222 (struct usb_descriptor_header *) &fs_notify_desc,
Paul Zimmerman04617db2011-06-27 14:13:18 -0700223
David Brownell45fe3b82008-06-19 18:20:04 -0700224 /* data interface has no altsetting */
225 (struct usb_descriptor_header *) &rndis_data_intf,
226 (struct usb_descriptor_header *) &fs_in_desc,
227 (struct usb_descriptor_header *) &fs_out_desc,
228 NULL,
229};
230
231/* high speed support: */
232
Michal Nazarewicz28824b12010-05-05 12:53:13 +0200233static struct usb_endpoint_descriptor hs_notify_desc = {
David Brownell45fe3b82008-06-19 18:20:04 -0700234 .bLength = USB_DT_ENDPOINT_SIZE,
235 .bDescriptorType = USB_DT_ENDPOINT,
236
237 .bEndpointAddress = USB_DIR_IN,
238 .bmAttributes = USB_ENDPOINT_XFER_INT,
Harvey Harrison551509d2009-02-11 14:11:36 -0800239 .wMaxPacketSize = cpu_to_le16(STATUS_BYTECOUNT),
Sebastian Andrzej Siewiorbcb2f992012-10-22 22:14:57 +0200240 .bInterval = USB_MS_TO_HS_INTERVAL(RNDIS_STATUS_INTERVAL_MS)
David Brownell45fe3b82008-06-19 18:20:04 -0700241};
Paul Zimmerman04617db2011-06-27 14:13:18 -0700242
Michal Nazarewicz28824b12010-05-05 12:53:13 +0200243static struct usb_endpoint_descriptor hs_in_desc = {
David Brownell45fe3b82008-06-19 18:20:04 -0700244 .bLength = USB_DT_ENDPOINT_SIZE,
245 .bDescriptorType = USB_DT_ENDPOINT,
246
247 .bEndpointAddress = USB_DIR_IN,
248 .bmAttributes = USB_ENDPOINT_XFER_BULK,
Harvey Harrison551509d2009-02-11 14:11:36 -0800249 .wMaxPacketSize = cpu_to_le16(512),
David Brownell45fe3b82008-06-19 18:20:04 -0700250};
251
Michal Nazarewicz28824b12010-05-05 12:53:13 +0200252static struct usb_endpoint_descriptor hs_out_desc = {
David Brownell45fe3b82008-06-19 18:20:04 -0700253 .bLength = USB_DT_ENDPOINT_SIZE,
254 .bDescriptorType = USB_DT_ENDPOINT,
255
256 .bEndpointAddress = USB_DIR_OUT,
257 .bmAttributes = USB_ENDPOINT_XFER_BULK,
Harvey Harrison551509d2009-02-11 14:11:36 -0800258 .wMaxPacketSize = cpu_to_le16(512),
David Brownell45fe3b82008-06-19 18:20:04 -0700259};
260
Michal Nazarewicz28824b12010-05-05 12:53:13 +0200261static struct usb_descriptor_header *eth_hs_function[] = {
Michal Nazarewiczb97503f2009-10-28 16:57:30 +0100262 (struct usb_descriptor_header *) &rndis_iad_descriptor,
Paul Zimmerman04617db2011-06-27 14:13:18 -0700263
David Brownell45fe3b82008-06-19 18:20:04 -0700264 /* control interface matches ACM, not Ethernet */
265 (struct usb_descriptor_header *) &rndis_control_intf,
266 (struct usb_descriptor_header *) &header_desc,
267 (struct usb_descriptor_header *) &call_mgmt_descriptor,
Michal Nazarewiczb97503f2009-10-28 16:57:30 +0100268 (struct usb_descriptor_header *) &rndis_acm_descriptor,
David Brownell45fe3b82008-06-19 18:20:04 -0700269 (struct usb_descriptor_header *) &rndis_union_desc,
270 (struct usb_descriptor_header *) &hs_notify_desc,
Paul Zimmerman04617db2011-06-27 14:13:18 -0700271
David Brownell45fe3b82008-06-19 18:20:04 -0700272 /* data interface has no altsetting */
273 (struct usb_descriptor_header *) &rndis_data_intf,
274 (struct usb_descriptor_header *) &hs_in_desc,
275 (struct usb_descriptor_header *) &hs_out_desc,
276 NULL,
277};
278
Paul Zimmerman04617db2011-06-27 14:13:18 -0700279/* super speed support: */
280
281static struct usb_endpoint_descriptor ss_notify_desc = {
282 .bLength = USB_DT_ENDPOINT_SIZE,
283 .bDescriptorType = USB_DT_ENDPOINT,
284
285 .bEndpointAddress = USB_DIR_IN,
286 .bmAttributes = USB_ENDPOINT_XFER_INT,
287 .wMaxPacketSize = cpu_to_le16(STATUS_BYTECOUNT),
Sebastian Andrzej Siewiorbcb2f992012-10-22 22:14:57 +0200288 .bInterval = USB_MS_TO_HS_INTERVAL(RNDIS_STATUS_INTERVAL_MS)
Paul Zimmerman04617db2011-06-27 14:13:18 -0700289};
290
291static struct usb_ss_ep_comp_descriptor ss_intr_comp_desc = {
292 .bLength = sizeof ss_intr_comp_desc,
293 .bDescriptorType = USB_DT_SS_ENDPOINT_COMP,
294
295 /* the following 3 values can be tweaked if necessary */
296 /* .bMaxBurst = 0, */
297 /* .bmAttributes = 0, */
298 .wBytesPerInterval = cpu_to_le16(STATUS_BYTECOUNT),
299};
300
301static struct usb_endpoint_descriptor ss_in_desc = {
302 .bLength = USB_DT_ENDPOINT_SIZE,
303 .bDescriptorType = USB_DT_ENDPOINT,
304
305 .bEndpointAddress = USB_DIR_IN,
306 .bmAttributes = USB_ENDPOINT_XFER_BULK,
307 .wMaxPacketSize = cpu_to_le16(1024),
308};
309
310static struct usb_endpoint_descriptor ss_out_desc = {
311 .bLength = USB_DT_ENDPOINT_SIZE,
312 .bDescriptorType = USB_DT_ENDPOINT,
313
314 .bEndpointAddress = USB_DIR_OUT,
315 .bmAttributes = USB_ENDPOINT_XFER_BULK,
316 .wMaxPacketSize = cpu_to_le16(1024),
317};
318
319static struct usb_ss_ep_comp_descriptor ss_bulk_comp_desc = {
320 .bLength = sizeof ss_bulk_comp_desc,
321 .bDescriptorType = USB_DT_SS_ENDPOINT_COMP,
322
323 /* the following 2 values can be tweaked if necessary */
324 /* .bMaxBurst = 0, */
325 /* .bmAttributes = 0, */
326};
327
328static struct usb_descriptor_header *eth_ss_function[] = {
329 (struct usb_descriptor_header *) &rndis_iad_descriptor,
330
331 /* control interface matches ACM, not Ethernet */
332 (struct usb_descriptor_header *) &rndis_control_intf,
333 (struct usb_descriptor_header *) &header_desc,
334 (struct usb_descriptor_header *) &call_mgmt_descriptor,
335 (struct usb_descriptor_header *) &rndis_acm_descriptor,
336 (struct usb_descriptor_header *) &rndis_union_desc,
337 (struct usb_descriptor_header *) &ss_notify_desc,
338 (struct usb_descriptor_header *) &ss_intr_comp_desc,
339
340 /* data interface has no altsetting */
341 (struct usb_descriptor_header *) &rndis_data_intf,
342 (struct usb_descriptor_header *) &ss_in_desc,
343 (struct usb_descriptor_header *) &ss_bulk_comp_desc,
344 (struct usb_descriptor_header *) &ss_out_desc,
345 (struct usb_descriptor_header *) &ss_bulk_comp_desc,
346 NULL,
347};
348
David Brownell45fe3b82008-06-19 18:20:04 -0700349/* string descriptors: */
350
351static struct usb_string rndis_string_defs[] = {
352 [0].s = "RNDIS Communications Control",
353 [1].s = "RNDIS Ethernet Data",
Michal Nazarewiczb97503f2009-10-28 16:57:30 +0100354 [2].s = "RNDIS",
David Brownell45fe3b82008-06-19 18:20:04 -0700355 { } /* end of list */
356};
357
358static struct usb_gadget_strings rndis_string_table = {
359 .language = 0x0409, /* en-us */
360 .strings = rndis_string_defs,
361};
362
363static struct usb_gadget_strings *rndis_strings[] = {
364 &rndis_string_table,
365 NULL,
366};
367
368/*-------------------------------------------------------------------------*/
369
Brian Niebuhr9b39e9d2009-08-14 10:04:22 -0500370static struct sk_buff *rndis_add_header(struct gether *port,
371 struct sk_buff *skb)
David Brownell45fe3b82008-06-19 18:20:04 -0700372{
Brian Niebuhr9b39e9d2009-08-14 10:04:22 -0500373 struct sk_buff *skb2;
374
375 skb2 = skb_realloc_headroom(skb, sizeof(struct rndis_packet_msg_type));
376 if (skb2)
377 rndis_add_hdr(skb2);
378
379 dev_kfree_skb_any(skb);
380 return skb2;
David Brownell45fe3b82008-06-19 18:20:04 -0700381}
382
383static void rndis_response_available(void *_rndis)
384{
385 struct f_rndis *rndis = _rndis;
386 struct usb_request *req = rndis->notify_req;
387 struct usb_composite_dev *cdev = rndis->port.func.config->cdev;
388 __le32 *data = req->buf;
389 int status;
390
Richard Röjforsff349502008-11-15 19:53:24 -0800391 if (atomic_inc_return(&rndis->notify_count) != 1)
David Brownell45fe3b82008-06-19 18:20:04 -0700392 return;
393
394 /* Send RNDIS RESPONSE_AVAILABLE notification; a
395 * USB_CDC_NOTIFY_RESPONSE_AVAILABLE "should" work too
396 *
397 * This is the only notification defined by RNDIS.
398 */
399 data[0] = cpu_to_le32(1);
400 data[1] = cpu_to_le32(0);
401
402 status = usb_ep_queue(rndis->notify, req, GFP_ATOMIC);
403 if (status) {
404 atomic_dec(&rndis->notify_count);
405 DBG(cdev, "notify/0 --> %d\n", status);
406 }
407}
408
409static void rndis_response_complete(struct usb_ep *ep, struct usb_request *req)
410{
411 struct f_rndis *rndis = req->context;
412 struct usb_composite_dev *cdev = rndis->port.func.config->cdev;
413 int status = req->status;
414
415 /* after TX:
416 * - USB_CDC_GET_ENCAPSULATED_RESPONSE (ep0/control)
417 * - RNDIS_RESPONSE_AVAILABLE (status/irq)
418 */
419 switch (status) {
420 case -ECONNRESET:
421 case -ESHUTDOWN:
422 /* connection gone */
423 atomic_set(&rndis->notify_count, 0);
424 break;
425 default:
426 DBG(cdev, "RNDIS %s response error %d, %d/%d\n",
427 ep->name, status,
428 req->actual, req->length);
429 /* FALLTHROUGH */
430 case 0:
431 if (ep != rndis->notify)
432 break;
433
434 /* handle multiple pending RNDIS_RESPONSE_AVAILABLE
435 * notifications by resending until we're done
436 */
437 if (atomic_dec_and_test(&rndis->notify_count))
438 break;
439 status = usb_ep_queue(rndis->notify, req, GFP_ATOMIC);
440 if (status) {
441 atomic_dec(&rndis->notify_count);
442 DBG(cdev, "notify/1 --> %d\n", status);
443 }
444 break;
445 }
446}
447
448static void rndis_command_complete(struct usb_ep *ep, struct usb_request *req)
449{
450 struct f_rndis *rndis = req->context;
David Brownell45fe3b82008-06-19 18:20:04 -0700451 int status;
452
453 /* received RNDIS command from USB_CDC_SEND_ENCAPSULATED_COMMAND */
454// spin_lock(&dev->lock);
455 status = rndis_msg_parser(rndis->config, (u8 *) req->buf);
456 if (status < 0)
Truls Bengtsson967baed2013-03-20 14:02:25 +0100457 pr_err("RNDIS command error %d, %d/%d\n",
David Brownell45fe3b82008-06-19 18:20:04 -0700458 status, req->actual, req->length);
459// spin_unlock(&dev->lock);
460}
461
462static int
463rndis_setup(struct usb_function *f, const struct usb_ctrlrequest *ctrl)
464{
465 struct f_rndis *rndis = func_to_rndis(f);
466 struct usb_composite_dev *cdev = f->config->cdev;
467 struct usb_request *req = cdev->req;
468 int value = -EOPNOTSUPP;
469 u16 w_index = le16_to_cpu(ctrl->wIndex);
470 u16 w_value = le16_to_cpu(ctrl->wValue);
471 u16 w_length = le16_to_cpu(ctrl->wLength);
472
473 /* composite driver infrastructure handles everything except
474 * CDC class messages; interface activation uses set_alt().
475 */
476 switch ((ctrl->bRequestType << 8) | ctrl->bRequest) {
477
478 /* RNDIS uses the CDC command encapsulation mechanism to implement
479 * an RPC scheme, with much getting/setting of attributes by OID.
480 */
481 case ((USB_DIR_OUT | USB_TYPE_CLASS | USB_RECIP_INTERFACE) << 8)
482 | USB_CDC_SEND_ENCAPSULATED_COMMAND:
Felipe Balbi472b9122011-05-13 16:53:48 +0300483 if (w_value || w_index != rndis->ctrl_id)
David Brownell45fe3b82008-06-19 18:20:04 -0700484 goto invalid;
485 /* read the request; process it later */
486 value = w_length;
487 req->complete = rndis_command_complete;
488 req->context = rndis;
489 /* later, rndis_response_available() sends a notification */
490 break;
491
492 case ((USB_DIR_IN | USB_TYPE_CLASS | USB_RECIP_INTERFACE) << 8)
493 | USB_CDC_GET_ENCAPSULATED_RESPONSE:
494 if (w_value || w_index != rndis->ctrl_id)
495 goto invalid;
496 else {
497 u8 *buf;
498 u32 n;
499
500 /* return the result */
501 buf = rndis_get_next_response(rndis->config, &n);
502 if (buf) {
503 memcpy(req->buf, buf, n);
504 req->complete = rndis_response_complete;
Lukasz Majewskif1356172012-02-10 09:54:51 +0100505 req->context = rndis;
David Brownell45fe3b82008-06-19 18:20:04 -0700506 rndis_free_response(rndis->config, buf);
507 value = n;
508 }
509 /* else stalls ... spec says to avoid that */
510 }
511 break;
512
513 default:
514invalid:
515 VDBG(cdev, "invalid control req%02x.%02x v%04x i%04x l%d\n",
516 ctrl->bRequestType, ctrl->bRequest,
517 w_value, w_index, w_length);
518 }
519
520 /* respond with data transfer or status phase? */
521 if (value >= 0) {
522 DBG(cdev, "rndis req%02x.%02x v%04x i%04x l%d\n",
523 ctrl->bRequestType, ctrl->bRequest,
524 w_value, w_index, w_length);
David Brownell090b9012009-03-20 01:08:20 -0700525 req->zero = (value < w_length);
David Brownell45fe3b82008-06-19 18:20:04 -0700526 req->length = value;
527 value = usb_ep_queue(cdev->gadget->ep0, req, GFP_ATOMIC);
528 if (value < 0)
529 ERROR(cdev, "rndis response on err %d\n", value);
530 }
531
532 /* device either stalls (value < 0) or reports success */
533 return value;
534}
535
536
537static int rndis_set_alt(struct usb_function *f, unsigned intf, unsigned alt)
538{
539 struct f_rndis *rndis = func_to_rndis(f);
540 struct usb_composite_dev *cdev = f->config->cdev;
541
542 /* we know alt == 0 */
543
544 if (intf == rndis->ctrl_id) {
545 if (rndis->notify->driver_data) {
546 VDBG(cdev, "reset rndis control %d\n", intf);
547 usb_ep_disable(rndis->notify);
Tatyana Brokhmanea2a1df2011-06-28 16:33:50 +0300548 }
549 if (!rndis->notify->desc) {
David Brownell45fe3b82008-06-19 18:20:04 -0700550 VDBG(cdev, "init rndis ctrl %d\n", intf);
Tatyana Brokhmanea2a1df2011-06-28 16:33:50 +0300551 if (config_ep_by_speed(cdev->gadget, f, rndis->notify))
552 goto fail;
David Brownell45fe3b82008-06-19 18:20:04 -0700553 }
Tatyana Brokhman72c973d2011-06-28 16:33:48 +0300554 usb_ep_enable(rndis->notify);
David Brownell45fe3b82008-06-19 18:20:04 -0700555 rndis->notify->driver_data = rndis;
556
557 } else if (intf == rndis->data_id) {
558 struct net_device *net;
559
560 if (rndis->port.in_ep->driver_data) {
561 DBG(cdev, "reset rndis\n");
562 gether_disconnect(&rndis->port);
Maulik Mankad830d1b12009-05-29 18:34:40 +0530563 }
564
Tatyana Brokhmanea2a1df2011-06-28 16:33:50 +0300565 if (!rndis->port.in_ep->desc || !rndis->port.out_ep->desc) {
David Brownell45fe3b82008-06-19 18:20:04 -0700566 DBG(cdev, "init rndis\n");
Tatyana Brokhmanea2a1df2011-06-28 16:33:50 +0300567 if (config_ep_by_speed(cdev->gadget, f,
568 rndis->port.in_ep) ||
569 config_ep_by_speed(cdev->gadget, f,
570 rndis->port.out_ep)) {
571 rndis->port.in_ep->desc = NULL;
572 rndis->port.out_ep->desc = NULL;
573 goto fail;
574 }
David Brownell45fe3b82008-06-19 18:20:04 -0700575 }
576
577 /* Avoid ZLPs; they can be troublesome. */
578 rndis->port.is_zlp_ok = false;
579
580 /* RNDIS should be in the "RNDIS uninitialized" state,
581 * either never activated or after rndis_uninit().
582 *
583 * We don't want data to flow here until a nonzero packet
584 * filter is set, at which point it enters "RNDIS data
585 * initialized" state ... but we do want the endpoints
586 * to be activated. It's a strange little state.
587 *
588 * REVISIT the RNDIS gadget code has done this wrong for a
589 * very long time. We need another call to the link layer
590 * code -- gether_updown(...bool) maybe -- to do it right.
591 */
592 rndis->port.cdc_filter = 0;
593
594 DBG(cdev, "RNDIS RX/TX early activation ... \n");
595 net = gether_connect(&rndis->port);
596 if (IS_ERR(net))
597 return PTR_ERR(net);
598
599 rndis_set_param_dev(rndis->config, net,
600 &rndis->port.cdc_filter);
601 } else
602 goto fail;
603
604 return 0;
605fail:
606 return -EINVAL;
607}
608
609static void rndis_disable(struct usb_function *f)
610{
611 struct f_rndis *rndis = func_to_rndis(f);
612 struct usb_composite_dev *cdev = f->config->cdev;
613
614 if (!rndis->notify->driver_data)
615 return;
616
617 DBG(cdev, "rndis deactivated\n");
618
619 rndis_uninit(rndis->config);
620 gether_disconnect(&rndis->port);
621
622 usb_ep_disable(rndis->notify);
623 rndis->notify->driver_data = NULL;
624}
625
626/*-------------------------------------------------------------------------*/
627
628/*
629 * This isn't quite the same mechanism as CDC Ethernet, since the
630 * notification scheme passes less data, but the same set of link
631 * states must be tested. A key difference is that altsettings are
632 * not used to tell whether the link should send packets or not.
633 */
634
635static void rndis_open(struct gether *geth)
636{
637 struct f_rndis *rndis = func_to_rndis(&geth->func);
638 struct usb_composite_dev *cdev = geth->func.config->cdev;
639
640 DBG(cdev, "%s\n", __func__);
641
Linus Walleij17c51b62012-05-11 22:16:39 +0000642 rndis_set_param_medium(rndis->config, RNDIS_MEDIUM_802_3,
David Brownell45fe3b82008-06-19 18:20:04 -0700643 bitrate(cdev->gadget) / 100);
644 rndis_signal_connect(rndis->config);
645}
646
647static void rndis_close(struct gether *geth)
648{
649 struct f_rndis *rndis = func_to_rndis(&geth->func);
650
651 DBG(geth->func.config->cdev, "%s\n", __func__);
652
Linus Walleij17c51b62012-05-11 22:16:39 +0000653 rndis_set_param_medium(rndis->config, RNDIS_MEDIUM_802_3, 0);
David Brownell45fe3b82008-06-19 18:20:04 -0700654 rndis_signal_disconnect(rndis->config);
655}
656
657/*-------------------------------------------------------------------------*/
658
Andrzej Pietrasiewiczf466c632013-05-28 09:15:57 +0200659/* Some controllers can't support RNDIS ... */
660static inline bool can_support_rndis(struct usb_configuration *c)
661{
662 /* everything else is *presumably* fine */
663 return true;
664}
665
David Brownell45fe3b82008-06-19 18:20:04 -0700666/* ethernet function driver setup/binding */
667
Michal Nazarewicz28824b12010-05-05 12:53:13 +0200668static int
David Brownell45fe3b82008-06-19 18:20:04 -0700669rndis_bind(struct usb_configuration *c, struct usb_function *f)
670{
671 struct usb_composite_dev *cdev = c->cdev;
672 struct f_rndis *rndis = func_to_rndis(f);
673 int status;
674 struct usb_ep *ep;
675
Andrzej Pietrasiewiczf466c632013-05-28 09:15:57 +0200676#ifndef USB_FRNDIS_INCLUDED
677 struct f_rndis_opts *rndis_opts;
678
679 if (!can_support_rndis(c))
680 return -EINVAL;
681
682 rndis_opts = container_of(f->fi, struct f_rndis_opts, func_inst);
683
684 /*
685 * in drivers/usb/gadget/configfs.c:configfs_composite_bind()
686 * configurations are bound in sequence with list_for_each_entry,
687 * in each configuration its functions are bound in sequence
688 * with list_for_each_entry, so we assume no race condition
689 * with regard to rndis_opts->bound access
690 */
691 if (!rndis_opts->bound) {
692 gether_set_gadget(rndis_opts->net, cdev->gadget);
693 status = gether_register_netdev(rndis_opts->net);
694 if (status)
695 return status;
696 rndis_opts->bound = true;
697 }
698#endif
699
700 if (rndis_string_defs[0].id == 0) {
701 /* ... and setup RNDIS itself */
702 status = rndis_init();
703 if (status < 0)
704 return status;
705
706 status = usb_string_ids_tab(c->cdev, rndis_string_defs);
707 if (status)
708 return status;
709
710 rndis_control_intf.iInterface = rndis_string_defs[0].id;
711 rndis_data_intf.iInterface = rndis_string_defs[1].id;
712 rndis_iad_descriptor.iFunction = rndis_string_defs[2].id;
713 }
714
David Brownell45fe3b82008-06-19 18:20:04 -0700715 /* allocate instance-specific interface IDs */
716 status = usb_interface_id(c, f);
717 if (status < 0)
718 goto fail;
719 rndis->ctrl_id = status;
Michal Nazarewiczb97503f2009-10-28 16:57:30 +0100720 rndis_iad_descriptor.bFirstInterface = status;
David Brownell45fe3b82008-06-19 18:20:04 -0700721
722 rndis_control_intf.bInterfaceNumber = status;
723 rndis_union_desc.bMasterInterface0 = status;
724
725 status = usb_interface_id(c, f);
726 if (status < 0)
727 goto fail;
728 rndis->data_id = status;
729
730 rndis_data_intf.bInterfaceNumber = status;
731 rndis_union_desc.bSlaveInterface0 = status;
732
733 status = -ENODEV;
734
735 /* allocate instance-specific endpoints */
736 ep = usb_ep_autoconfig(cdev->gadget, &fs_in_desc);
737 if (!ep)
738 goto fail;
739 rndis->port.in_ep = ep;
740 ep->driver_data = cdev; /* claim */
741
742 ep = usb_ep_autoconfig(cdev->gadget, &fs_out_desc);
743 if (!ep)
744 goto fail;
745 rndis->port.out_ep = ep;
746 ep->driver_data = cdev; /* claim */
747
748 /* NOTE: a status/notification endpoint is, strictly speaking,
749 * optional. We don't treat it that way though! It's simpler,
750 * and some newer profiles don't treat it as optional.
751 */
752 ep = usb_ep_autoconfig(cdev->gadget, &fs_notify_desc);
753 if (!ep)
754 goto fail;
755 rndis->notify = ep;
756 ep->driver_data = cdev; /* claim */
757
758 status = -ENOMEM;
759
760 /* allocate notification request and buffer */
761 rndis->notify_req = usb_ep_alloc_request(ep, GFP_KERNEL);
762 if (!rndis->notify_req)
763 goto fail;
764 rndis->notify_req->buf = kmalloc(STATUS_BYTECOUNT, GFP_KERNEL);
765 if (!rndis->notify_req->buf)
766 goto fail;
767 rndis->notify_req->length = STATUS_BYTECOUNT;
768 rndis->notify_req->context = rndis;
769 rndis->notify_req->complete = rndis_response_complete;
770
David Brownell45fe3b82008-06-19 18:20:04 -0700771 /* support all relevant hardware speeds... we expect that when
772 * hardware is dual speed, all bulk-capable endpoints work at
773 * both speeds
774 */
Sebastian Andrzej Siewior10287ba2012-10-22 22:15:06 +0200775 hs_in_desc.bEndpointAddress = fs_in_desc.bEndpointAddress;
776 hs_out_desc.bEndpointAddress = fs_out_desc.bEndpointAddress;
777 hs_notify_desc.bEndpointAddress = fs_notify_desc.bEndpointAddress;
David Brownell45fe3b82008-06-19 18:20:04 -0700778
Sebastian Andrzej Siewior10287ba2012-10-22 22:15:06 +0200779 ss_in_desc.bEndpointAddress = fs_in_desc.bEndpointAddress;
780 ss_out_desc.bEndpointAddress = fs_out_desc.bEndpointAddress;
781 ss_notify_desc.bEndpointAddress = fs_notify_desc.bEndpointAddress;
David Brownell45fe3b82008-06-19 18:20:04 -0700782
Sebastian Andrzej Siewior10287ba2012-10-22 22:15:06 +0200783 status = usb_assign_descriptors(f, eth_fs_function, eth_hs_function,
784 eth_ss_function);
785 if (status)
786 goto fail;
Paul Zimmerman04617db2011-06-27 14:13:18 -0700787
David Brownell45fe3b82008-06-19 18:20:04 -0700788 rndis->port.open = rndis_open;
789 rndis->port.close = rndis_close;
790
Andrzej Pietrasiewiczf466c632013-05-28 09:15:57 +0200791#ifdef USB_FRNDIS_INCLUDED
David Brownell45fe3b82008-06-19 18:20:04 -0700792 status = rndis_register(rndis_response_available, rndis);
793 if (status < 0)
794 goto fail;
795 rndis->config = status;
Andrzej Pietrasiewiczf466c632013-05-28 09:15:57 +0200796#endif
David Brownell45fe3b82008-06-19 18:20:04 -0700797
Linus Walleij17c51b62012-05-11 22:16:39 +0000798 rndis_set_param_medium(rndis->config, RNDIS_MEDIUM_802_3, 0);
David Brownell45fe3b82008-06-19 18:20:04 -0700799 rndis_set_host_mac(rndis->config, rndis->ethaddr);
800
Benoit Goby1fbfeff2012-05-10 10:08:04 +0200801 if (rndis->manufacturer && rndis->vendorID &&
802 rndis_set_param_vendor(rndis->config, rndis->vendorID,
803 rndis->manufacturer))
804 goto fail;
David Brownell45fe3b82008-06-19 18:20:04 -0700805
806 /* NOTE: all that is done without knowing or caring about
807 * the network link ... which is unavailable to this code
808 * until we're activated via set_alt().
809 */
810
811 DBG(cdev, "RNDIS: %s speed IN/%s OUT/%s NOTIFY/%s\n",
Paul Zimmerman04617db2011-06-27 14:13:18 -0700812 gadget_is_superspeed(c->cdev->gadget) ? "super" :
David Brownell45fe3b82008-06-19 18:20:04 -0700813 gadget_is_dualspeed(c->cdev->gadget) ? "dual" : "full",
814 rndis->port.in_ep->name, rndis->port.out_ep->name,
815 rndis->notify->name);
816 return 0;
817
818fail:
Sebastian Andrzej Siewior10287ba2012-10-22 22:15:06 +0200819 usb_free_all_descriptors(f);
David Brownell45fe3b82008-06-19 18:20:04 -0700820
821 if (rndis->notify_req) {
822 kfree(rndis->notify_req->buf);
823 usb_ep_free_request(rndis->notify, rndis->notify_req);
824 }
825
826 /* we might as well release our claims on endpoints */
827 if (rndis->notify)
828 rndis->notify->driver_data = NULL;
Sebastian Andrzej Siewiore79cc612012-10-22 22:15:00 +0200829 if (rndis->port.out_ep)
David Brownell45fe3b82008-06-19 18:20:04 -0700830 rndis->port.out_ep->driver_data = NULL;
Sebastian Andrzej Siewiore79cc612012-10-22 22:15:00 +0200831 if (rndis->port.in_ep)
David Brownell45fe3b82008-06-19 18:20:04 -0700832 rndis->port.in_ep->driver_data = NULL;
833
834 ERROR(cdev, "%s: can't bind, err %d\n", f->name, status);
835
836 return status;
837}
838
Andrzej Pietrasiewiczf466c632013-05-28 09:15:57 +0200839#ifdef USB_FRNDIS_INCLUDED
840
David Brownell45fe3b82008-06-19 18:20:04 -0700841static void
Andrzej Pietrasiewiczf466c632013-05-28 09:15:57 +0200842rndis_old_unbind(struct usb_configuration *c, struct usb_function *f)
David Brownell45fe3b82008-06-19 18:20:04 -0700843{
844 struct f_rndis *rndis = func_to_rndis(f);
845
846 rndis_deregister(rndis->config);
847 rndis_exit();
848
Sebastian Andrzej Siewior1616e992012-10-22 22:15:10 +0200849 rndis_string_defs[0].id = 0;
Sebastian Andrzej Siewior10287ba2012-10-22 22:15:06 +0200850 usb_free_all_descriptors(f);
David Brownell45fe3b82008-06-19 18:20:04 -0700851
852 kfree(rndis->notify_req->buf);
853 usb_ep_free_request(rndis->notify, rndis->notify_req);
854
855 kfree(rndis);
856}
857
Michal Nazarewicz28824b12010-05-05 12:53:13 +0200858int
Benoit Goby1fbfeff2012-05-10 10:08:04 +0200859rndis_bind_config_vendor(struct usb_configuration *c, u8 ethaddr[ETH_ALEN],
Sebastian Andrzej Siewiord6a01432012-12-23 21:10:12 +0100860 u32 vendorID, const char *manufacturer, struct eth_dev *dev)
David Brownell45fe3b82008-06-19 18:20:04 -0700861{
862 struct f_rndis *rndis;
863 int status;
864
David Brownell45fe3b82008-06-19 18:20:04 -0700865 /* allocate and initialize one new instance */
866 status = -ENOMEM;
867 rndis = kzalloc(sizeof *rndis, GFP_KERNEL);
868 if (!rndis)
869 goto fail;
870
871 memcpy(rndis->ethaddr, ethaddr, ETH_ALEN);
Benoit Goby1fbfeff2012-05-10 10:08:04 +0200872 rndis->vendorID = vendorID;
873 rndis->manufacturer = manufacturer;
David Brownell45fe3b82008-06-19 18:20:04 -0700874
Sebastian Andrzej Siewiord6a01432012-12-23 21:10:12 +0100875 rndis->port.ioport = dev;
David Brownell45fe3b82008-06-19 18:20:04 -0700876 /* RNDIS activates when the host changes this filter */
877 rndis->port.cdc_filter = 0;
878
879 /* RNDIS has special (and complex) framing */
880 rndis->port.header_len = sizeof(struct rndis_packet_msg_type);
881 rndis->port.wrap = rndis_add_header;
882 rndis->port.unwrap = rndis_rm_hdr;
883
884 rndis->port.func.name = "rndis";
885 rndis->port.func.strings = rndis_strings;
886 /* descriptors are per-instance copies */
887 rndis->port.func.bind = rndis_bind;
Andrzej Pietrasiewiczf466c632013-05-28 09:15:57 +0200888 rndis->port.func.unbind = rndis_old_unbind;
David Brownell45fe3b82008-06-19 18:20:04 -0700889 rndis->port.func.set_alt = rndis_set_alt;
890 rndis->port.func.setup = rndis_setup;
891 rndis->port.func.disable = rndis_disable;
892
893 status = usb_add_function(c, &rndis->port.func);
894 if (status) {
895 kfree(rndis);
896fail:
897 rndis_exit();
898 }
899 return status;
900}
Andrzej Pietrasiewiczf466c632013-05-28 09:15:57 +0200901
902#else
903
904void rndis_borrow_net(struct usb_function_instance *f, struct net_device *net)
905{
906 struct f_rndis_opts *opts;
907
908 opts = container_of(f, struct f_rndis_opts, func_inst);
909 if (opts->bound)
910 gether_cleanup(netdev_priv(opts->net));
911 else
912 free_netdev(opts->net);
913 opts->borrowed_net = opts->bound = true;
914 opts->net = net;
915}
916EXPORT_SYMBOL(rndis_borrow_net);
917
918static void rndis_free_inst(struct usb_function_instance *f)
919{
920 struct f_rndis_opts *opts;
921
922 opts = container_of(f, struct f_rndis_opts, func_inst);
923 if (!opts->borrowed_net) {
924 if (opts->bound)
925 gether_cleanup(netdev_priv(opts->net));
926 else
927 free_netdev(opts->net);
928 }
929 kfree(opts);
930}
931
932static struct usb_function_instance *rndis_alloc_inst(void)
933{
934 struct f_rndis_opts *opts;
935
936 opts = kzalloc(sizeof(*opts), GFP_KERNEL);
937 if (!opts)
938 return ERR_PTR(-ENOMEM);
939
940 opts->func_inst.free_func_inst = rndis_free_inst;
941 opts->net = gether_setup_default();
942 if (IS_ERR(opts->net))
943 return ERR_CAST(opts->net);
944
945 return &opts->func_inst;
946}
947
948static void rndis_free(struct usb_function *f)
949{
950 struct f_rndis *rndis;
951
952 rndis = func_to_rndis(f);
953 rndis_deregister(rndis->config);
954 kfree(rndis);
955}
956
957static void rndis_unbind(struct usb_configuration *c, struct usb_function *f)
958{
959 struct f_rndis *rndis = func_to_rndis(f);
960
961 rndis_exit();
962 rndis_string_defs[0].id = 0;
963 usb_free_all_descriptors(f);
964
965 kfree(rndis->notify_req->buf);
966 usb_ep_free_request(rndis->notify, rndis->notify_req);
967}
968
969static struct usb_function *rndis_alloc(struct usb_function_instance *fi)
970{
971 struct f_rndis *rndis;
972 struct f_rndis_opts *opts;
973 int status;
974
975 /* allocate and initialize one new instance */
976 rndis = kzalloc(sizeof(*rndis), GFP_KERNEL);
977 if (!rndis) {
978 rndis_exit();
979 return ERR_PTR(-ENOMEM);
980 }
981
982 opts = container_of(fi, struct f_rndis_opts, func_inst);
983
984 gether_get_host_addr_u8(opts->net, rndis->ethaddr);
985 rndis->vendorID = opts->vendor_id;
986 rndis->manufacturer = opts->manufacturer;
987
988 rndis->port.ioport = netdev_priv(opts->net);
989 /* RNDIS activates when the host changes this filter */
990 rndis->port.cdc_filter = 0;
991
992 /* RNDIS has special (and complex) framing */
993 rndis->port.header_len = sizeof(struct rndis_packet_msg_type);
994 rndis->port.wrap = rndis_add_header;
995 rndis->port.unwrap = rndis_rm_hdr;
996
997 rndis->port.func.name = "rndis";
998 rndis->port.func.strings = rndis_strings;
999 /* descriptors are per-instance copies */
1000 rndis->port.func.bind = rndis_bind;
1001 rndis->port.func.unbind = rndis_unbind;
1002 rndis->port.func.set_alt = rndis_set_alt;
1003 rndis->port.func.setup = rndis_setup;
1004 rndis->port.func.disable = rndis_disable;
1005 rndis->port.func.free_func = rndis_free;
1006
1007 status = rndis_register(rndis_response_available, rndis);
1008 if (status < 0) {
1009 kfree(rndis);
1010 return ERR_PTR(status);
1011 }
1012 rndis->config = status;
1013
1014 return &rndis->port.func;
1015}
1016
1017DECLARE_USB_FUNCTION_INIT(rndis, rndis_alloc_inst, rndis_alloc);
1018MODULE_LICENSE("GPL");
1019MODULE_AUTHOR("David Brownell");
1020
1021#endif