2008-06-20 01:20:04 +00:00
|
|
|
/*
|
|
|
|
* f_rndis.c -- RNDIS link function driver
|
|
|
|
*
|
|
|
|
* Copyright (C) 2003-2005,2008 David Brownell
|
|
|
|
* Copyright (C) 2003-2004 Robert Schwebel, Benedikt Spranger
|
|
|
|
* Copyright (C) 2008 Nokia Corporation
|
2009-10-28 15:57:30 +00:00
|
|
|
* Copyright (C) 2009 Samsung Electronics
|
2012-01-13 14:05:16 +00:00
|
|
|
* Author: Michal Nazarewicz (mina86@mina86.com)
|
2008-06-20 01:20:04 +00:00
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* #define VERBOSE_DEBUG */
|
|
|
|
|
include cleanup: Update gfp.h and slab.h includes to prepare for breaking implicit slab.h inclusion from percpu.h
percpu.h is included by sched.h and module.h and thus ends up being
included when building most .c files. percpu.h includes slab.h which
in turn includes gfp.h making everything defined by the two files
universally available and complicating inclusion dependencies.
percpu.h -> slab.h dependency is about to be removed. Prepare for
this change by updating users of gfp and slab facilities include those
headers directly instead of assuming availability. As this conversion
needs to touch large number of source files, the following script is
used as the basis of conversion.
http://userweb.kernel.org/~tj/misc/slabh-sweep.py
The script does the followings.
* Scan files for gfp and slab usages and update includes such that
only the necessary includes are there. ie. if only gfp is used,
gfp.h, if slab is used, slab.h.
* When the script inserts a new include, it looks at the include
blocks and try to put the new include such that its order conforms
to its surrounding. It's put in the include block which contains
core kernel includes, in the same order that the rest are ordered -
alphabetical, Christmas tree, rev-Xmas-tree or at the end if there
doesn't seem to be any matching order.
* If the script can't find a place to put a new include (mostly
because the file doesn't have fitting include block), it prints out
an error message indicating which .h file needs to be added to the
file.
The conversion was done in the following steps.
1. The initial automatic conversion of all .c files updated slightly
over 4000 files, deleting around 700 includes and adding ~480 gfp.h
and ~3000 slab.h inclusions. The script emitted errors for ~400
files.
2. Each error was manually checked. Some didn't need the inclusion,
some needed manual addition while adding it to implementation .h or
embedding .c file was more appropriate for others. This step added
inclusions to around 150 files.
3. The script was run again and the output was compared to the edits
from #2 to make sure no file was left behind.
4. Several build tests were done and a couple of problems were fixed.
e.g. lib/decompress_*.c used malloc/free() wrappers around slab
APIs requiring slab.h to be added manually.
5. The script was run on all .h files but without automatically
editing them as sprinkling gfp.h and slab.h inclusions around .h
files could easily lead to inclusion dependency hell. Most gfp.h
inclusion directives were ignored as stuff from gfp.h was usually
wildly available and often used in preprocessor macros. Each
slab.h inclusion directive was examined and added manually as
necessary.
6. percpu.h was updated not to include slab.h.
7. Build test were done on the following configurations and failures
were fixed. CONFIG_GCOV_KERNEL was turned off for all tests (as my
distributed build env didn't work with gcov compiles) and a few
more options had to be turned off depending on archs to make things
build (like ipr on powerpc/64 which failed due to missing writeq).
* x86 and x86_64 UP and SMP allmodconfig and a custom test config.
* powerpc and powerpc64 SMP allmodconfig
* sparc and sparc64 SMP allmodconfig
* ia64 SMP allmodconfig
* s390 SMP allmodconfig
* alpha SMP allmodconfig
* um on x86_64 SMP allmodconfig
8. percpu.h modifications were reverted so that it could be applied as
a separate patch and serve as bisection point.
Given the fact that I had only a couple of failures from tests on step
6, I'm fairly confident about the coverage of this conversion patch.
If there is a breakage, it's likely to be something in one of the arch
headers which should be easily discoverable easily on most builds of
the specific arch.
Signed-off-by: Tejun Heo <tj@kernel.org>
Guess-its-ok-by: Christoph Lameter <cl@linux-foundation.org>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Lee Schermerhorn <Lee.Schermerhorn@hp.com>
2010-03-24 08:04:11 +00:00
|
|
|
#include <linux/slab.h>
|
2008-06-20 01:20:04 +00:00
|
|
|
#include <linux/kernel.h>
|
|
|
|
#include <linux/device.h>
|
|
|
|
#include <linux/etherdevice.h>
|
|
|
|
|
2011-07-26 23:09:06 +00:00
|
|
|
#include <linux/atomic.h>
|
2008-06-20 01:20:04 +00:00
|
|
|
|
|
|
|
#include "u_ether.h"
|
|
|
|
#include "rndis.h"
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* This function is an RNDIS Ethernet port -- a Microsoft protocol that's
|
|
|
|
* been promoted instead of the standard CDC Ethernet. The published RNDIS
|
|
|
|
* spec is ambiguous, incomplete, and needlessly complex. Variants such as
|
|
|
|
* ActiveSync have even worse status in terms of specification.
|
|
|
|
*
|
|
|
|
* In short: it's a protocol controlled by (and for) Microsoft, not for an
|
|
|
|
* Open ecosystem or markets. Linux supports it *only* because Microsoft
|
|
|
|
* doesn't support the CDC Ethernet standard.
|
|
|
|
*
|
|
|
|
* The RNDIS data transfer model is complex, with multiple Ethernet packets
|
|
|
|
* per USB message, and out of band data. The control model is built around
|
|
|
|
* what's essentially an "RNDIS RPC" protocol. It's all wrapped in a CDC ACM
|
|
|
|
* (modem, not Ethernet) veneer, with those ACM descriptors being entirely
|
|
|
|
* useless (they're ignored). RNDIS expects to be the only function in its
|
|
|
|
* configuration, so it's no real help if you need composite devices; and
|
|
|
|
* it expects to be the first configuration too.
|
|
|
|
*
|
|
|
|
* There is a single technical advantage of RNDIS over CDC Ethernet, if you
|
|
|
|
* discount the fluff that its RPC can be made to deliver: it doesn't need
|
|
|
|
* a NOP altsetting for the data interface. That lets it work on some of the
|
|
|
|
* "so smart it's stupid" hardware which takes over configuration changes
|
|
|
|
* from the software, and adds restrictions like "no altsettings".
|
|
|
|
*
|
|
|
|
* Unfortunately MSFT's RNDIS drivers are buggy. They hang or oops, and
|
|
|
|
* have all sorts of contrary-to-specification oddities that can prevent
|
|
|
|
* them from working sanely. Since bugfixes (or accurate specs, letting
|
|
|
|
* Linux work around those bugs) are unlikely to ever come from MSFT, you
|
|
|
|
* may want to avoid using RNDIS on purely operational grounds.
|
|
|
|
*
|
|
|
|
* Omissions from the RNDIS 1.0 specification include:
|
|
|
|
*
|
|
|
|
* - Power management ... references data that's scattered around lots
|
|
|
|
* of other documentation, which is incorrect/incomplete there too.
|
|
|
|
*
|
|
|
|
* - There are various undocumented protocol requirements, like the need
|
|
|
|
* to send garbage in some control-OUT messages.
|
|
|
|
*
|
|
|
|
* - MS-Windows drivers sometimes emit undocumented requests.
|
|
|
|
*/
|
|
|
|
|
|
|
|
struct f_rndis {
|
|
|
|
struct gether port;
|
|
|
|
u8 ctrl_id, data_id;
|
|
|
|
u8 ethaddr[ETH_ALEN];
|
2012-05-10 08:08:04 +00:00
|
|
|
u32 vendorID;
|
|
|
|
const char *manufacturer;
|
2008-06-20 01:20:04 +00:00
|
|
|
int config;
|
|
|
|
|
|
|
|
struct usb_ep *notify;
|
|
|
|
struct usb_request *notify_req;
|
|
|
|
atomic_t notify_count;
|
|
|
|
};
|
|
|
|
|
|
|
|
static inline struct f_rndis *func_to_rndis(struct usb_function *f)
|
|
|
|
{
|
|
|
|
return container_of(f, struct f_rndis, port.func);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* peak (theoretical) bulk transfer rate in bits-per-second */
|
|
|
|
static unsigned int bitrate(struct usb_gadget *g)
|
|
|
|
{
|
2011-06-27 21:13:18 +00:00
|
|
|
if (gadget_is_superspeed(g) && g->speed == USB_SPEED_SUPER)
|
|
|
|
return 13 * 1024 * 8 * 1000 * 8;
|
|
|
|
else if (gadget_is_dualspeed(g) && g->speed == USB_SPEED_HIGH)
|
2008-06-20 01:20:04 +00:00
|
|
|
return 13 * 512 * 8 * 1000 * 8;
|
|
|
|
else
|
2011-06-27 21:13:18 +00:00
|
|
|
return 19 * 64 * 1 * 1000 * 8;
|
2008-06-20 01:20:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*-------------------------------------------------------------------------*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#define LOG2_STATUS_INTERVAL_MSEC 5 /* 1 << 5 == 32 msec */
|
|
|
|
#define STATUS_BYTECOUNT 8 /* 8 bytes data */
|
|
|
|
|
|
|
|
|
|
|
|
/* interface descriptor: */
|
|
|
|
|
2010-05-05 10:53:13 +00:00
|
|
|
static struct usb_interface_descriptor rndis_control_intf = {
|
2008-06-20 01:20:04 +00:00
|
|
|
.bLength = sizeof rndis_control_intf,
|
|
|
|
.bDescriptorType = USB_DT_INTERFACE,
|
|
|
|
|
|
|
|
/* .bInterfaceNumber = DYNAMIC */
|
|
|
|
/* status endpoint is optional; this could be patched later */
|
|
|
|
.bNumEndpoints = 1,
|
|
|
|
.bInterfaceClass = USB_CLASS_COMM,
|
|
|
|
.bInterfaceSubClass = USB_CDC_SUBCLASS_ACM,
|
|
|
|
.bInterfaceProtocol = USB_CDC_ACM_PROTO_VENDOR,
|
|
|
|
/* .iInterface = DYNAMIC */
|
|
|
|
};
|
|
|
|
|
2010-05-05 10:53:13 +00:00
|
|
|
static struct usb_cdc_header_desc header_desc = {
|
2008-06-20 01:20:04 +00:00
|
|
|
.bLength = sizeof header_desc,
|
|
|
|
.bDescriptorType = USB_DT_CS_INTERFACE,
|
|
|
|
.bDescriptorSubType = USB_CDC_HEADER_TYPE,
|
|
|
|
|
2009-02-11 22:11:36 +00:00
|
|
|
.bcdCDC = cpu_to_le16(0x0110),
|
2008-06-20 01:20:04 +00:00
|
|
|
};
|
|
|
|
|
2010-05-05 10:53:13 +00:00
|
|
|
static struct usb_cdc_call_mgmt_descriptor call_mgmt_descriptor = {
|
2008-06-20 01:20:04 +00:00
|
|
|
.bLength = sizeof call_mgmt_descriptor,
|
|
|
|
.bDescriptorType = USB_DT_CS_INTERFACE,
|
|
|
|
.bDescriptorSubType = USB_CDC_CALL_MANAGEMENT_TYPE,
|
|
|
|
|
|
|
|
.bmCapabilities = 0x00,
|
|
|
|
.bDataInterface = 0x01,
|
|
|
|
};
|
|
|
|
|
2010-05-05 10:53:13 +00:00
|
|
|
static struct usb_cdc_acm_descriptor rndis_acm_descriptor = {
|
2009-10-28 15:57:30 +00:00
|
|
|
.bLength = sizeof rndis_acm_descriptor,
|
2008-06-20 01:20:04 +00:00
|
|
|
.bDescriptorType = USB_DT_CS_INTERFACE,
|
|
|
|
.bDescriptorSubType = USB_CDC_ACM_TYPE,
|
|
|
|
|
|
|
|
.bmCapabilities = 0x00,
|
|
|
|
};
|
|
|
|
|
2010-05-05 10:53:13 +00:00
|
|
|
static struct usb_cdc_union_desc rndis_union_desc = {
|
2008-06-20 01:20:04 +00:00
|
|
|
.bLength = sizeof(rndis_union_desc),
|
|
|
|
.bDescriptorType = USB_DT_CS_INTERFACE,
|
|
|
|
.bDescriptorSubType = USB_CDC_UNION_TYPE,
|
|
|
|
/* .bMasterInterface0 = DYNAMIC */
|
|
|
|
/* .bSlaveInterface0 = DYNAMIC */
|
|
|
|
};
|
|
|
|
|
|
|
|
/* the data interface has two bulk endpoints */
|
|
|
|
|
2010-05-05 10:53:13 +00:00
|
|
|
static struct usb_interface_descriptor rndis_data_intf = {
|
2008-06-20 01:20:04 +00:00
|
|
|
.bLength = sizeof rndis_data_intf,
|
|
|
|
.bDescriptorType = USB_DT_INTERFACE,
|
|
|
|
|
|
|
|
/* .bInterfaceNumber = DYNAMIC */
|
|
|
|
.bNumEndpoints = 2,
|
|
|
|
.bInterfaceClass = USB_CLASS_CDC_DATA,
|
|
|
|
.bInterfaceSubClass = 0,
|
|
|
|
.bInterfaceProtocol = 0,
|
|
|
|
/* .iInterface = DYNAMIC */
|
|
|
|
};
|
|
|
|
|
2009-10-28 15:57:30 +00:00
|
|
|
|
|
|
|
static struct usb_interface_assoc_descriptor
|
|
|
|
rndis_iad_descriptor = {
|
|
|
|
.bLength = sizeof rndis_iad_descriptor,
|
|
|
|
.bDescriptorType = USB_DT_INTERFACE_ASSOCIATION,
|
|
|
|
|
|
|
|
.bFirstInterface = 0, /* XXX, hardcoded */
|
|
|
|
.bInterfaceCount = 2, // control + data
|
|
|
|
.bFunctionClass = USB_CLASS_COMM,
|
|
|
|
.bFunctionSubClass = USB_CDC_SUBCLASS_ETHERNET,
|
|
|
|
.bFunctionProtocol = USB_CDC_PROTO_NONE,
|
|
|
|
/* .iFunction = DYNAMIC */
|
|
|
|
};
|
|
|
|
|
2008-06-20 01:20:04 +00:00
|
|
|
/* full speed support: */
|
|
|
|
|
2010-05-05 10:53:13 +00:00
|
|
|
static struct usb_endpoint_descriptor fs_notify_desc = {
|
2008-06-20 01:20:04 +00:00
|
|
|
.bLength = USB_DT_ENDPOINT_SIZE,
|
|
|
|
.bDescriptorType = USB_DT_ENDPOINT,
|
|
|
|
|
|
|
|
.bEndpointAddress = USB_DIR_IN,
|
|
|
|
.bmAttributes = USB_ENDPOINT_XFER_INT,
|
2009-02-11 22:11:36 +00:00
|
|
|
.wMaxPacketSize = cpu_to_le16(STATUS_BYTECOUNT),
|
2008-06-20 01:20:04 +00:00
|
|
|
.bInterval = 1 << LOG2_STATUS_INTERVAL_MSEC,
|
|
|
|
};
|
|
|
|
|
2010-05-05 10:53:13 +00:00
|
|
|
static struct usb_endpoint_descriptor fs_in_desc = {
|
2008-06-20 01:20:04 +00:00
|
|
|
.bLength = USB_DT_ENDPOINT_SIZE,
|
|
|
|
.bDescriptorType = USB_DT_ENDPOINT,
|
|
|
|
|
|
|
|
.bEndpointAddress = USB_DIR_IN,
|
|
|
|
.bmAttributes = USB_ENDPOINT_XFER_BULK,
|
|
|
|
};
|
|
|
|
|
2010-05-05 10:53:13 +00:00
|
|
|
static struct usb_endpoint_descriptor fs_out_desc = {
|
2008-06-20 01:20:04 +00:00
|
|
|
.bLength = USB_DT_ENDPOINT_SIZE,
|
|
|
|
.bDescriptorType = USB_DT_ENDPOINT,
|
|
|
|
|
|
|
|
.bEndpointAddress = USB_DIR_OUT,
|
|
|
|
.bmAttributes = USB_ENDPOINT_XFER_BULK,
|
|
|
|
};
|
|
|
|
|
2010-05-05 10:53:13 +00:00
|
|
|
static struct usb_descriptor_header *eth_fs_function[] = {
|
2009-10-28 15:57:30 +00:00
|
|
|
(struct usb_descriptor_header *) &rndis_iad_descriptor,
|
2011-06-27 21:13:18 +00:00
|
|
|
|
2008-06-20 01:20:04 +00:00
|
|
|
/* control interface matches ACM, not Ethernet */
|
|
|
|
(struct usb_descriptor_header *) &rndis_control_intf,
|
|
|
|
(struct usb_descriptor_header *) &header_desc,
|
|
|
|
(struct usb_descriptor_header *) &call_mgmt_descriptor,
|
2009-10-28 15:57:30 +00:00
|
|
|
(struct usb_descriptor_header *) &rndis_acm_descriptor,
|
2008-06-20 01:20:04 +00:00
|
|
|
(struct usb_descriptor_header *) &rndis_union_desc,
|
|
|
|
(struct usb_descriptor_header *) &fs_notify_desc,
|
2011-06-27 21:13:18 +00:00
|
|
|
|
2008-06-20 01:20:04 +00:00
|
|
|
/* data interface has no altsetting */
|
|
|
|
(struct usb_descriptor_header *) &rndis_data_intf,
|
|
|
|
(struct usb_descriptor_header *) &fs_in_desc,
|
|
|
|
(struct usb_descriptor_header *) &fs_out_desc,
|
|
|
|
NULL,
|
|
|
|
};
|
|
|
|
|
|
|
|
/* high speed support: */
|
|
|
|
|
2010-05-05 10:53:13 +00:00
|
|
|
static struct usb_endpoint_descriptor hs_notify_desc = {
|
2008-06-20 01:20:04 +00:00
|
|
|
.bLength = USB_DT_ENDPOINT_SIZE,
|
|
|
|
.bDescriptorType = USB_DT_ENDPOINT,
|
|
|
|
|
|
|
|
.bEndpointAddress = USB_DIR_IN,
|
|
|
|
.bmAttributes = USB_ENDPOINT_XFER_INT,
|
2009-02-11 22:11:36 +00:00
|
|
|
.wMaxPacketSize = cpu_to_le16(STATUS_BYTECOUNT),
|
2008-06-20 01:20:04 +00:00
|
|
|
.bInterval = LOG2_STATUS_INTERVAL_MSEC + 4,
|
|
|
|
};
|
2011-06-27 21:13:18 +00:00
|
|
|
|
2010-05-05 10:53:13 +00:00
|
|
|
static struct usb_endpoint_descriptor hs_in_desc = {
|
2008-06-20 01:20:04 +00:00
|
|
|
.bLength = USB_DT_ENDPOINT_SIZE,
|
|
|
|
.bDescriptorType = USB_DT_ENDPOINT,
|
|
|
|
|
|
|
|
.bEndpointAddress = USB_DIR_IN,
|
|
|
|
.bmAttributes = USB_ENDPOINT_XFER_BULK,
|
2009-02-11 22:11:36 +00:00
|
|
|
.wMaxPacketSize = cpu_to_le16(512),
|
2008-06-20 01:20:04 +00:00
|
|
|
};
|
|
|
|
|
2010-05-05 10:53:13 +00:00
|
|
|
static struct usb_endpoint_descriptor hs_out_desc = {
|
2008-06-20 01:20:04 +00:00
|
|
|
.bLength = USB_DT_ENDPOINT_SIZE,
|
|
|
|
.bDescriptorType = USB_DT_ENDPOINT,
|
|
|
|
|
|
|
|
.bEndpointAddress = USB_DIR_OUT,
|
|
|
|
.bmAttributes = USB_ENDPOINT_XFER_BULK,
|
2009-02-11 22:11:36 +00:00
|
|
|
.wMaxPacketSize = cpu_to_le16(512),
|
2008-06-20 01:20:04 +00:00
|
|
|
};
|
|
|
|
|
2010-05-05 10:53:13 +00:00
|
|
|
static struct usb_descriptor_header *eth_hs_function[] = {
|
2009-10-28 15:57:30 +00:00
|
|
|
(struct usb_descriptor_header *) &rndis_iad_descriptor,
|
2011-06-27 21:13:18 +00:00
|
|
|
|
2008-06-20 01:20:04 +00:00
|
|
|
/* control interface matches ACM, not Ethernet */
|
|
|
|
(struct usb_descriptor_header *) &rndis_control_intf,
|
|
|
|
(struct usb_descriptor_header *) &header_desc,
|
|
|
|
(struct usb_descriptor_header *) &call_mgmt_descriptor,
|
2009-10-28 15:57:30 +00:00
|
|
|
(struct usb_descriptor_header *) &rndis_acm_descriptor,
|
2008-06-20 01:20:04 +00:00
|
|
|
(struct usb_descriptor_header *) &rndis_union_desc,
|
|
|
|
(struct usb_descriptor_header *) &hs_notify_desc,
|
2011-06-27 21:13:18 +00:00
|
|
|
|
2008-06-20 01:20:04 +00:00
|
|
|
/* data interface has no altsetting */
|
|
|
|
(struct usb_descriptor_header *) &rndis_data_intf,
|
|
|
|
(struct usb_descriptor_header *) &hs_in_desc,
|
|
|
|
(struct usb_descriptor_header *) &hs_out_desc,
|
|
|
|
NULL,
|
|
|
|
};
|
|
|
|
|
2011-06-27 21:13:18 +00:00
|
|
|
/* super speed support: */
|
|
|
|
|
|
|
|
static struct usb_endpoint_descriptor ss_notify_desc = {
|
|
|
|
.bLength = USB_DT_ENDPOINT_SIZE,
|
|
|
|
.bDescriptorType = USB_DT_ENDPOINT,
|
|
|
|
|
|
|
|
.bEndpointAddress = USB_DIR_IN,
|
|
|
|
.bmAttributes = USB_ENDPOINT_XFER_INT,
|
|
|
|
.wMaxPacketSize = cpu_to_le16(STATUS_BYTECOUNT),
|
|
|
|
.bInterval = LOG2_STATUS_INTERVAL_MSEC + 4,
|
|
|
|
};
|
|
|
|
|
|
|
|
static struct usb_ss_ep_comp_descriptor ss_intr_comp_desc = {
|
|
|
|
.bLength = sizeof ss_intr_comp_desc,
|
|
|
|
.bDescriptorType = USB_DT_SS_ENDPOINT_COMP,
|
|
|
|
|
|
|
|
/* the following 3 values can be tweaked if necessary */
|
|
|
|
/* .bMaxBurst = 0, */
|
|
|
|
/* .bmAttributes = 0, */
|
|
|
|
.wBytesPerInterval = cpu_to_le16(STATUS_BYTECOUNT),
|
|
|
|
};
|
|
|
|
|
|
|
|
static struct usb_endpoint_descriptor ss_in_desc = {
|
|
|
|
.bLength = USB_DT_ENDPOINT_SIZE,
|
|
|
|
.bDescriptorType = USB_DT_ENDPOINT,
|
|
|
|
|
|
|
|
.bEndpointAddress = USB_DIR_IN,
|
|
|
|
.bmAttributes = USB_ENDPOINT_XFER_BULK,
|
|
|
|
.wMaxPacketSize = cpu_to_le16(1024),
|
|
|
|
};
|
|
|
|
|
|
|
|
static struct usb_endpoint_descriptor ss_out_desc = {
|
|
|
|
.bLength = USB_DT_ENDPOINT_SIZE,
|
|
|
|
.bDescriptorType = USB_DT_ENDPOINT,
|
|
|
|
|
|
|
|
.bEndpointAddress = USB_DIR_OUT,
|
|
|
|
.bmAttributes = USB_ENDPOINT_XFER_BULK,
|
|
|
|
.wMaxPacketSize = cpu_to_le16(1024),
|
|
|
|
};
|
|
|
|
|
|
|
|
static struct usb_ss_ep_comp_descriptor ss_bulk_comp_desc = {
|
|
|
|
.bLength = sizeof ss_bulk_comp_desc,
|
|
|
|
.bDescriptorType = USB_DT_SS_ENDPOINT_COMP,
|
|
|
|
|
|
|
|
/* the following 2 values can be tweaked if necessary */
|
|
|
|
/* .bMaxBurst = 0, */
|
|
|
|
/* .bmAttributes = 0, */
|
|
|
|
};
|
|
|
|
|
|
|
|
static struct usb_descriptor_header *eth_ss_function[] = {
|
|
|
|
(struct usb_descriptor_header *) &rndis_iad_descriptor,
|
|
|
|
|
|
|
|
/* control interface matches ACM, not Ethernet */
|
|
|
|
(struct usb_descriptor_header *) &rndis_control_intf,
|
|
|
|
(struct usb_descriptor_header *) &header_desc,
|
|
|
|
(struct usb_descriptor_header *) &call_mgmt_descriptor,
|
|
|
|
(struct usb_descriptor_header *) &rndis_acm_descriptor,
|
|
|
|
(struct usb_descriptor_header *) &rndis_union_desc,
|
|
|
|
(struct usb_descriptor_header *) &ss_notify_desc,
|
|
|
|
(struct usb_descriptor_header *) &ss_intr_comp_desc,
|
|
|
|
|
|
|
|
/* data interface has no altsetting */
|
|
|
|
(struct usb_descriptor_header *) &rndis_data_intf,
|
|
|
|
(struct usb_descriptor_header *) &ss_in_desc,
|
|
|
|
(struct usb_descriptor_header *) &ss_bulk_comp_desc,
|
|
|
|
(struct usb_descriptor_header *) &ss_out_desc,
|
|
|
|
(struct usb_descriptor_header *) &ss_bulk_comp_desc,
|
|
|
|
NULL,
|
|
|
|
};
|
|
|
|
|
2008-06-20 01:20:04 +00:00
|
|
|
/* string descriptors: */
|
|
|
|
|
|
|
|
static struct usb_string rndis_string_defs[] = {
|
|
|
|
[0].s = "RNDIS Communications Control",
|
|
|
|
[1].s = "RNDIS Ethernet Data",
|
2009-10-28 15:57:30 +00:00
|
|
|
[2].s = "RNDIS",
|
2008-06-20 01:20:04 +00:00
|
|
|
{ } /* end of list */
|
|
|
|
};
|
|
|
|
|
|
|
|
static struct usb_gadget_strings rndis_string_table = {
|
|
|
|
.language = 0x0409, /* en-us */
|
|
|
|
.strings = rndis_string_defs,
|
|
|
|
};
|
|
|
|
|
|
|
|
static struct usb_gadget_strings *rndis_strings[] = {
|
|
|
|
&rndis_string_table,
|
|
|
|
NULL,
|
|
|
|
};
|
|
|
|
|
|
|
|
/*-------------------------------------------------------------------------*/
|
|
|
|
|
2009-08-14 15:04:22 +00:00
|
|
|
static struct sk_buff *rndis_add_header(struct gether *port,
|
|
|
|
struct sk_buff *skb)
|
2008-06-20 01:20:04 +00:00
|
|
|
{
|
2009-08-14 15:04:22 +00:00
|
|
|
struct sk_buff *skb2;
|
|
|
|
|
|
|
|
skb2 = skb_realloc_headroom(skb, sizeof(struct rndis_packet_msg_type));
|
|
|
|
if (skb2)
|
|
|
|
rndis_add_hdr(skb2);
|
|
|
|
|
|
|
|
dev_kfree_skb_any(skb);
|
|
|
|
return skb2;
|
2008-06-20 01:20:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void rndis_response_available(void *_rndis)
|
|
|
|
{
|
|
|
|
struct f_rndis *rndis = _rndis;
|
|
|
|
struct usb_request *req = rndis->notify_req;
|
|
|
|
struct usb_composite_dev *cdev = rndis->port.func.config->cdev;
|
|
|
|
__le32 *data = req->buf;
|
|
|
|
int status;
|
|
|
|
|
2008-11-16 03:53:24 +00:00
|
|
|
if (atomic_inc_return(&rndis->notify_count) != 1)
|
2008-06-20 01:20:04 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
/* Send RNDIS RESPONSE_AVAILABLE notification; a
|
|
|
|
* USB_CDC_NOTIFY_RESPONSE_AVAILABLE "should" work too
|
|
|
|
*
|
|
|
|
* This is the only notification defined by RNDIS.
|
|
|
|
*/
|
|
|
|
data[0] = cpu_to_le32(1);
|
|
|
|
data[1] = cpu_to_le32(0);
|
|
|
|
|
|
|
|
status = usb_ep_queue(rndis->notify, req, GFP_ATOMIC);
|
|
|
|
if (status) {
|
|
|
|
atomic_dec(&rndis->notify_count);
|
|
|
|
DBG(cdev, "notify/0 --> %d\n", status);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void rndis_response_complete(struct usb_ep *ep, struct usb_request *req)
|
|
|
|
{
|
|
|
|
struct f_rndis *rndis = req->context;
|
|
|
|
struct usb_composite_dev *cdev = rndis->port.func.config->cdev;
|
|
|
|
int status = req->status;
|
|
|
|
|
|
|
|
/* after TX:
|
|
|
|
* - USB_CDC_GET_ENCAPSULATED_RESPONSE (ep0/control)
|
|
|
|
* - RNDIS_RESPONSE_AVAILABLE (status/irq)
|
|
|
|
*/
|
|
|
|
switch (status) {
|
|
|
|
case -ECONNRESET:
|
|
|
|
case -ESHUTDOWN:
|
|
|
|
/* connection gone */
|
|
|
|
atomic_set(&rndis->notify_count, 0);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
DBG(cdev, "RNDIS %s response error %d, %d/%d\n",
|
|
|
|
ep->name, status,
|
|
|
|
req->actual, req->length);
|
|
|
|
/* FALLTHROUGH */
|
|
|
|
case 0:
|
|
|
|
if (ep != rndis->notify)
|
|
|
|
break;
|
|
|
|
|
|
|
|
/* handle multiple pending RNDIS_RESPONSE_AVAILABLE
|
|
|
|
* notifications by resending until we're done
|
|
|
|
*/
|
|
|
|
if (atomic_dec_and_test(&rndis->notify_count))
|
|
|
|
break;
|
|
|
|
status = usb_ep_queue(rndis->notify, req, GFP_ATOMIC);
|
|
|
|
if (status) {
|
|
|
|
atomic_dec(&rndis->notify_count);
|
|
|
|
DBG(cdev, "notify/1 --> %d\n", status);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void rndis_command_complete(struct usb_ep *ep, struct usb_request *req)
|
|
|
|
{
|
|
|
|
struct f_rndis *rndis = req->context;
|
|
|
|
struct usb_composite_dev *cdev = rndis->port.func.config->cdev;
|
|
|
|
int status;
|
|
|
|
|
|
|
|
/* received RNDIS command from USB_CDC_SEND_ENCAPSULATED_COMMAND */
|
|
|
|
// spin_lock(&dev->lock);
|
|
|
|
status = rndis_msg_parser(rndis->config, (u8 *) req->buf);
|
|
|
|
if (status < 0)
|
|
|
|
ERROR(cdev, "RNDIS command error %d, %d/%d\n",
|
|
|
|
status, req->actual, req->length);
|
|
|
|
// spin_unlock(&dev->lock);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
rndis_setup(struct usb_function *f, const struct usb_ctrlrequest *ctrl)
|
|
|
|
{
|
|
|
|
struct f_rndis *rndis = func_to_rndis(f);
|
|
|
|
struct usb_composite_dev *cdev = f->config->cdev;
|
|
|
|
struct usb_request *req = cdev->req;
|
|
|
|
int value = -EOPNOTSUPP;
|
|
|
|
u16 w_index = le16_to_cpu(ctrl->wIndex);
|
|
|
|
u16 w_value = le16_to_cpu(ctrl->wValue);
|
|
|
|
u16 w_length = le16_to_cpu(ctrl->wLength);
|
|
|
|
|
|
|
|
/* composite driver infrastructure handles everything except
|
|
|
|
* CDC class messages; interface activation uses set_alt().
|
|
|
|
*/
|
|
|
|
switch ((ctrl->bRequestType << 8) | ctrl->bRequest) {
|
|
|
|
|
|
|
|
/* RNDIS uses the CDC command encapsulation mechanism to implement
|
|
|
|
* an RPC scheme, with much getting/setting of attributes by OID.
|
|
|
|
*/
|
|
|
|
case ((USB_DIR_OUT | USB_TYPE_CLASS | USB_RECIP_INTERFACE) << 8)
|
|
|
|
| USB_CDC_SEND_ENCAPSULATED_COMMAND:
|
2011-05-13 13:53:48 +00:00
|
|
|
if (w_value || w_index != rndis->ctrl_id)
|
2008-06-20 01:20:04 +00:00
|
|
|
goto invalid;
|
|
|
|
/* read the request; process it later */
|
|
|
|
value = w_length;
|
|
|
|
req->complete = rndis_command_complete;
|
|
|
|
req->context = rndis;
|
|
|
|
/* later, rndis_response_available() sends a notification */
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ((USB_DIR_IN | USB_TYPE_CLASS | USB_RECIP_INTERFACE) << 8)
|
|
|
|
| USB_CDC_GET_ENCAPSULATED_RESPONSE:
|
|
|
|
if (w_value || w_index != rndis->ctrl_id)
|
|
|
|
goto invalid;
|
|
|
|
else {
|
|
|
|
u8 *buf;
|
|
|
|
u32 n;
|
|
|
|
|
|
|
|
/* return the result */
|
|
|
|
buf = rndis_get_next_response(rndis->config, &n);
|
|
|
|
if (buf) {
|
|
|
|
memcpy(req->buf, buf, n);
|
|
|
|
req->complete = rndis_response_complete;
|
2012-02-10 08:54:51 +00:00
|
|
|
req->context = rndis;
|
2008-06-20 01:20:04 +00:00
|
|
|
rndis_free_response(rndis->config, buf);
|
|
|
|
value = n;
|
|
|
|
}
|
|
|
|
/* else stalls ... spec says to avoid that */
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
invalid:
|
|
|
|
VDBG(cdev, "invalid control req%02x.%02x v%04x i%04x l%d\n",
|
|
|
|
ctrl->bRequestType, ctrl->bRequest,
|
|
|
|
w_value, w_index, w_length);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* respond with data transfer or status phase? */
|
|
|
|
if (value >= 0) {
|
|
|
|
DBG(cdev, "rndis req%02x.%02x v%04x i%04x l%d\n",
|
|
|
|
ctrl->bRequestType, ctrl->bRequest,
|
|
|
|
w_value, w_index, w_length);
|
2009-03-20 08:08:20 +00:00
|
|
|
req->zero = (value < w_length);
|
2008-06-20 01:20:04 +00:00
|
|
|
req->length = value;
|
|
|
|
value = usb_ep_queue(cdev->gadget->ep0, req, GFP_ATOMIC);
|
|
|
|
if (value < 0)
|
|
|
|
ERROR(cdev, "rndis response on err %d\n", value);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* device either stalls (value < 0) or reports success */
|
|
|
|
return value;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static int rndis_set_alt(struct usb_function *f, unsigned intf, unsigned alt)
|
|
|
|
{
|
|
|
|
struct f_rndis *rndis = func_to_rndis(f);
|
|
|
|
struct usb_composite_dev *cdev = f->config->cdev;
|
|
|
|
|
|
|
|
/* we know alt == 0 */
|
|
|
|
|
|
|
|
if (intf == rndis->ctrl_id) {
|
|
|
|
if (rndis->notify->driver_data) {
|
|
|
|
VDBG(cdev, "reset rndis control %d\n", intf);
|
|
|
|
usb_ep_disable(rndis->notify);
|
2011-06-28 13:33:50 +00:00
|
|
|
}
|
|
|
|
if (!rndis->notify->desc) {
|
2008-06-20 01:20:04 +00:00
|
|
|
VDBG(cdev, "init rndis ctrl %d\n", intf);
|
2011-06-28 13:33:50 +00:00
|
|
|
if (config_ep_by_speed(cdev->gadget, f, rndis->notify))
|
|
|
|
goto fail;
|
2008-06-20 01:20:04 +00:00
|
|
|
}
|
2011-06-28 13:33:48 +00:00
|
|
|
usb_ep_enable(rndis->notify);
|
2008-06-20 01:20:04 +00:00
|
|
|
rndis->notify->driver_data = rndis;
|
|
|
|
|
|
|
|
} else if (intf == rndis->data_id) {
|
|
|
|
struct net_device *net;
|
|
|
|
|
|
|
|
if (rndis->port.in_ep->driver_data) {
|
|
|
|
DBG(cdev, "reset rndis\n");
|
|
|
|
gether_disconnect(&rndis->port);
|
2009-05-29 13:04:40 +00:00
|
|
|
}
|
|
|
|
|
2011-06-28 13:33:50 +00:00
|
|
|
if (!rndis->port.in_ep->desc || !rndis->port.out_ep->desc) {
|
2008-06-20 01:20:04 +00:00
|
|
|
DBG(cdev, "init rndis\n");
|
2011-06-28 13:33:50 +00:00
|
|
|
if (config_ep_by_speed(cdev->gadget, f,
|
|
|
|
rndis->port.in_ep) ||
|
|
|
|
config_ep_by_speed(cdev->gadget, f,
|
|
|
|
rndis->port.out_ep)) {
|
|
|
|
rndis->port.in_ep->desc = NULL;
|
|
|
|
rndis->port.out_ep->desc = NULL;
|
|
|
|
goto fail;
|
|
|
|
}
|
2008-06-20 01:20:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Avoid ZLPs; they can be troublesome. */
|
|
|
|
rndis->port.is_zlp_ok = false;
|
|
|
|
|
|
|
|
/* RNDIS should be in the "RNDIS uninitialized" state,
|
|
|
|
* either never activated or after rndis_uninit().
|
|
|
|
*
|
|
|
|
* We don't want data to flow here until a nonzero packet
|
|
|
|
* filter is set, at which point it enters "RNDIS data
|
|
|
|
* initialized" state ... but we do want the endpoints
|
|
|
|
* to be activated. It's a strange little state.
|
|
|
|
*
|
|
|
|
* REVISIT the RNDIS gadget code has done this wrong for a
|
|
|
|
* very long time. We need another call to the link layer
|
|
|
|
* code -- gether_updown(...bool) maybe -- to do it right.
|
|
|
|
*/
|
|
|
|
rndis->port.cdc_filter = 0;
|
|
|
|
|
|
|
|
DBG(cdev, "RNDIS RX/TX early activation ... \n");
|
|
|
|
net = gether_connect(&rndis->port);
|
|
|
|
if (IS_ERR(net))
|
|
|
|
return PTR_ERR(net);
|
|
|
|
|
|
|
|
rndis_set_param_dev(rndis->config, net,
|
|
|
|
&rndis->port.cdc_filter);
|
|
|
|
} else
|
|
|
|
goto fail;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
fail:
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void rndis_disable(struct usb_function *f)
|
|
|
|
{
|
|
|
|
struct f_rndis *rndis = func_to_rndis(f);
|
|
|
|
struct usb_composite_dev *cdev = f->config->cdev;
|
|
|
|
|
|
|
|
if (!rndis->notify->driver_data)
|
|
|
|
return;
|
|
|
|
|
|
|
|
DBG(cdev, "rndis deactivated\n");
|
|
|
|
|
|
|
|
rndis_uninit(rndis->config);
|
|
|
|
gether_disconnect(&rndis->port);
|
|
|
|
|
|
|
|
usb_ep_disable(rndis->notify);
|
|
|
|
rndis->notify->driver_data = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*-------------------------------------------------------------------------*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* This isn't quite the same mechanism as CDC Ethernet, since the
|
|
|
|
* notification scheme passes less data, but the same set of link
|
|
|
|
* states must be tested. A key difference is that altsettings are
|
|
|
|
* not used to tell whether the link should send packets or not.
|
|
|
|
*/
|
|
|
|
|
|
|
|
static void rndis_open(struct gether *geth)
|
|
|
|
{
|
|
|
|
struct f_rndis *rndis = func_to_rndis(&geth->func);
|
|
|
|
struct usb_composite_dev *cdev = geth->func.config->cdev;
|
|
|
|
|
|
|
|
DBG(cdev, "%s\n", __func__);
|
|
|
|
|
2012-05-11 22:16:39 +00:00
|
|
|
rndis_set_param_medium(rndis->config, RNDIS_MEDIUM_802_3,
|
2008-06-20 01:20:04 +00:00
|
|
|
bitrate(cdev->gadget) / 100);
|
|
|
|
rndis_signal_connect(rndis->config);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void rndis_close(struct gether *geth)
|
|
|
|
{
|
|
|
|
struct f_rndis *rndis = func_to_rndis(&geth->func);
|
|
|
|
|
|
|
|
DBG(geth->func.config->cdev, "%s\n", __func__);
|
|
|
|
|
2012-05-11 22:16:39 +00:00
|
|
|
rndis_set_param_medium(rndis->config, RNDIS_MEDIUM_802_3, 0);
|
2008-06-20 01:20:04 +00:00
|
|
|
rndis_signal_disconnect(rndis->config);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*-------------------------------------------------------------------------*/
|
|
|
|
|
|
|
|
/* ethernet function driver setup/binding */
|
|
|
|
|
2010-05-05 10:53:13 +00:00
|
|
|
static int
|
2008-06-20 01:20:04 +00:00
|
|
|
rndis_bind(struct usb_configuration *c, struct usb_function *f)
|
|
|
|
{
|
|
|
|
struct usb_composite_dev *cdev = c->cdev;
|
|
|
|
struct f_rndis *rndis = func_to_rndis(f);
|
|
|
|
int status;
|
|
|
|
struct usb_ep *ep;
|
|
|
|
|
|
|
|
/* allocate instance-specific interface IDs */
|
|
|
|
status = usb_interface_id(c, f);
|
|
|
|
if (status < 0)
|
|
|
|
goto fail;
|
|
|
|
rndis->ctrl_id = status;
|
2009-10-28 15:57:30 +00:00
|
|
|
rndis_iad_descriptor.bFirstInterface = status;
|
2008-06-20 01:20:04 +00:00
|
|
|
|
|
|
|
rndis_control_intf.bInterfaceNumber = status;
|
|
|
|
rndis_union_desc.bMasterInterface0 = status;
|
|
|
|
|
|
|
|
status = usb_interface_id(c, f);
|
|
|
|
if (status < 0)
|
|
|
|
goto fail;
|
|
|
|
rndis->data_id = status;
|
|
|
|
|
|
|
|
rndis_data_intf.bInterfaceNumber = status;
|
|
|
|
rndis_union_desc.bSlaveInterface0 = status;
|
|
|
|
|
|
|
|
status = -ENODEV;
|
|
|
|
|
|
|
|
/* allocate instance-specific endpoints */
|
|
|
|
ep = usb_ep_autoconfig(cdev->gadget, &fs_in_desc);
|
|
|
|
if (!ep)
|
|
|
|
goto fail;
|
|
|
|
rndis->port.in_ep = ep;
|
|
|
|
ep->driver_data = cdev; /* claim */
|
|
|
|
|
|
|
|
ep = usb_ep_autoconfig(cdev->gadget, &fs_out_desc);
|
|
|
|
if (!ep)
|
|
|
|
goto fail;
|
|
|
|
rndis->port.out_ep = ep;
|
|
|
|
ep->driver_data = cdev; /* claim */
|
|
|
|
|
|
|
|
/* NOTE: a status/notification endpoint is, strictly speaking,
|
|
|
|
* optional. We don't treat it that way though! It's simpler,
|
|
|
|
* and some newer profiles don't treat it as optional.
|
|
|
|
*/
|
|
|
|
ep = usb_ep_autoconfig(cdev->gadget, &fs_notify_desc);
|
|
|
|
if (!ep)
|
|
|
|
goto fail;
|
|
|
|
rndis->notify = ep;
|
|
|
|
ep->driver_data = cdev; /* claim */
|
|
|
|
|
|
|
|
status = -ENOMEM;
|
|
|
|
|
|
|
|
/* allocate notification request and buffer */
|
|
|
|
rndis->notify_req = usb_ep_alloc_request(ep, GFP_KERNEL);
|
|
|
|
if (!rndis->notify_req)
|
|
|
|
goto fail;
|
|
|
|
rndis->notify_req->buf = kmalloc(STATUS_BYTECOUNT, GFP_KERNEL);
|
|
|
|
if (!rndis->notify_req->buf)
|
|
|
|
goto fail;
|
|
|
|
rndis->notify_req->length = STATUS_BYTECOUNT;
|
|
|
|
rndis->notify_req->context = rndis;
|
|
|
|
rndis->notify_req->complete = rndis_response_complete;
|
|
|
|
|
|
|
|
/* copy descriptors, and track endpoint copies */
|
|
|
|
f->descriptors = usb_copy_descriptors(eth_fs_function);
|
|
|
|
if (!f->descriptors)
|
|
|
|
goto fail;
|
|
|
|
|
|
|
|
/* support all relevant hardware speeds... we expect that when
|
|
|
|
* hardware is dual speed, all bulk-capable endpoints work at
|
|
|
|
* both speeds
|
|
|
|
*/
|
|
|
|
if (gadget_is_dualspeed(c->cdev->gadget)) {
|
|
|
|
hs_in_desc.bEndpointAddress =
|
|
|
|
fs_in_desc.bEndpointAddress;
|
|
|
|
hs_out_desc.bEndpointAddress =
|
|
|
|
fs_out_desc.bEndpointAddress;
|
2008-11-25 07:11:03 +00:00
|
|
|
hs_notify_desc.bEndpointAddress =
|
|
|
|
fs_notify_desc.bEndpointAddress;
|
2008-06-20 01:20:04 +00:00
|
|
|
|
|
|
|
/* copy descriptors, and track endpoint copies */
|
|
|
|
f->hs_descriptors = usb_copy_descriptors(eth_hs_function);
|
|
|
|
if (!f->hs_descriptors)
|
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
|
2011-06-27 21:13:18 +00:00
|
|
|
if (gadget_is_superspeed(c->cdev->gadget)) {
|
|
|
|
ss_in_desc.bEndpointAddress =
|
|
|
|
fs_in_desc.bEndpointAddress;
|
|
|
|
ss_out_desc.bEndpointAddress =
|
|
|
|
fs_out_desc.bEndpointAddress;
|
|
|
|
ss_notify_desc.bEndpointAddress =
|
|
|
|
fs_notify_desc.bEndpointAddress;
|
|
|
|
|
|
|
|
/* copy descriptors, and track endpoint copies */
|
|
|
|
f->ss_descriptors = usb_copy_descriptors(eth_ss_function);
|
|
|
|
if (!f->ss_descriptors)
|
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
|
2008-06-20 01:20:04 +00:00
|
|
|
rndis->port.open = rndis_open;
|
|
|
|
rndis->port.close = rndis_close;
|
|
|
|
|
|
|
|
status = rndis_register(rndis_response_available, rndis);
|
|
|
|
if (status < 0)
|
|
|
|
goto fail;
|
|
|
|
rndis->config = status;
|
|
|
|
|
2012-05-11 22:16:39 +00:00
|
|
|
rndis_set_param_medium(rndis->config, RNDIS_MEDIUM_802_3, 0);
|
2008-06-20 01:20:04 +00:00
|
|
|
rndis_set_host_mac(rndis->config, rndis->ethaddr);
|
|
|
|
|
2012-05-10 08:08:04 +00:00
|
|
|
if (rndis->manufacturer && rndis->vendorID &&
|
|
|
|
rndis_set_param_vendor(rndis->config, rndis->vendorID,
|
|
|
|
rndis->manufacturer))
|
|
|
|
goto fail;
|
2008-06-20 01:20:04 +00:00
|
|
|
|
|
|
|
/* NOTE: all that is done without knowing or caring about
|
|
|
|
* the network link ... which is unavailable to this code
|
|
|
|
* until we're activated via set_alt().
|
|
|
|
*/
|
|
|
|
|
|
|
|
DBG(cdev, "RNDIS: %s speed IN/%s OUT/%s NOTIFY/%s\n",
|
2011-06-27 21:13:18 +00:00
|
|
|
gadget_is_superspeed(c->cdev->gadget) ? "super" :
|
2008-06-20 01:20:04 +00:00
|
|
|
gadget_is_dualspeed(c->cdev->gadget) ? "dual" : "full",
|
|
|
|
rndis->port.in_ep->name, rndis->port.out_ep->name,
|
|
|
|
rndis->notify->name);
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
fail:
|
2011-06-27 21:13:18 +00:00
|
|
|
if (gadget_is_superspeed(c->cdev->gadget) && f->ss_descriptors)
|
|
|
|
usb_free_descriptors(f->ss_descriptors);
|
2008-06-20 01:20:04 +00:00
|
|
|
if (gadget_is_dualspeed(c->cdev->gadget) && f->hs_descriptors)
|
|
|
|
usb_free_descriptors(f->hs_descriptors);
|
|
|
|
if (f->descriptors)
|
|
|
|
usb_free_descriptors(f->descriptors);
|
|
|
|
|
|
|
|
if (rndis->notify_req) {
|
|
|
|
kfree(rndis->notify_req->buf);
|
|
|
|
usb_ep_free_request(rndis->notify, rndis->notify_req);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* we might as well release our claims on endpoints */
|
|
|
|
if (rndis->notify)
|
|
|
|
rndis->notify->driver_data = NULL;
|
2011-06-28 13:33:48 +00:00
|
|
|
if (rndis->port.out_ep->desc)
|
2008-06-20 01:20:04 +00:00
|
|
|
rndis->port.out_ep->driver_data = NULL;
|
2011-06-28 13:33:48 +00:00
|
|
|
if (rndis->port.in_ep->desc)
|
2008-06-20 01:20:04 +00:00
|
|
|
rndis->port.in_ep->driver_data = NULL;
|
|
|
|
|
|
|
|
ERROR(cdev, "%s: can't bind, err %d\n", f->name, status);
|
|
|
|
|
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
rndis_unbind(struct usb_configuration *c, struct usb_function *f)
|
|
|
|
{
|
|
|
|
struct f_rndis *rndis = func_to_rndis(f);
|
|
|
|
|
|
|
|
rndis_deregister(rndis->config);
|
|
|
|
rndis_exit();
|
2012-05-10 08:08:03 +00:00
|
|
|
rndis_string_defs[0].id = 0;
|
2008-06-20 01:20:04 +00:00
|
|
|
|
2011-06-27 21:13:18 +00:00
|
|
|
if (gadget_is_superspeed(c->cdev->gadget))
|
|
|
|
usb_free_descriptors(f->ss_descriptors);
|
2008-06-20 01:20:04 +00:00
|
|
|
if (gadget_is_dualspeed(c->cdev->gadget))
|
|
|
|
usb_free_descriptors(f->hs_descriptors);
|
|
|
|
usb_free_descriptors(f->descriptors);
|
|
|
|
|
|
|
|
kfree(rndis->notify_req->buf);
|
|
|
|
usb_ep_free_request(rndis->notify, rndis->notify_req);
|
|
|
|
|
|
|
|
kfree(rndis);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Some controllers can't support RNDIS ... */
|
|
|
|
static inline bool can_support_rndis(struct usb_configuration *c)
|
|
|
|
{
|
|
|
|
/* everything else is *presumably* fine */
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2010-05-05 10:53:13 +00:00
|
|
|
int
|
2012-05-10 08:08:04 +00:00
|
|
|
rndis_bind_config_vendor(struct usb_configuration *c, u8 ethaddr[ETH_ALEN],
|
|
|
|
u32 vendorID, const char *manufacturer)
|
2008-06-20 01:20:04 +00:00
|
|
|
{
|
|
|
|
struct f_rndis *rndis;
|
|
|
|
int status;
|
|
|
|
|
|
|
|
if (!can_support_rndis(c) || !ethaddr)
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
/* maybe allocate device-global string IDs */
|
|
|
|
if (rndis_string_defs[0].id == 0) {
|
|
|
|
|
|
|
|
/* ... and setup RNDIS itself */
|
|
|
|
status = rndis_init();
|
|
|
|
if (status < 0)
|
|
|
|
return status;
|
|
|
|
|
|
|
|
/* control interface label */
|
|
|
|
status = usb_string_id(c->cdev);
|
|
|
|
if (status < 0)
|
|
|
|
return status;
|
|
|
|
rndis_string_defs[0].id = status;
|
|
|
|
rndis_control_intf.iInterface = status;
|
|
|
|
|
|
|
|
/* data interface label */
|
|
|
|
status = usb_string_id(c->cdev);
|
|
|
|
if (status < 0)
|
|
|
|
return status;
|
|
|
|
rndis_string_defs[1].id = status;
|
|
|
|
rndis_data_intf.iInterface = status;
|
2009-10-28 15:57:30 +00:00
|
|
|
|
|
|
|
/* IAD iFunction label */
|
|
|
|
status = usb_string_id(c->cdev);
|
|
|
|
if (status < 0)
|
|
|
|
return status;
|
|
|
|
rndis_string_defs[2].id = status;
|
|
|
|
rndis_iad_descriptor.iFunction = status;
|
2008-06-20 01:20:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* allocate and initialize one new instance */
|
|
|
|
status = -ENOMEM;
|
|
|
|
rndis = kzalloc(sizeof *rndis, GFP_KERNEL);
|
|
|
|
if (!rndis)
|
|
|
|
goto fail;
|
|
|
|
|
|
|
|
memcpy(rndis->ethaddr, ethaddr, ETH_ALEN);
|
2012-05-10 08:08:04 +00:00
|
|
|
rndis->vendorID = vendorID;
|
|
|
|
rndis->manufacturer = manufacturer;
|
2008-06-20 01:20:04 +00:00
|
|
|
|
|
|
|
/* RNDIS activates when the host changes this filter */
|
|
|
|
rndis->port.cdc_filter = 0;
|
|
|
|
|
|
|
|
/* RNDIS has special (and complex) framing */
|
|
|
|
rndis->port.header_len = sizeof(struct rndis_packet_msg_type);
|
|
|
|
rndis->port.wrap = rndis_add_header;
|
|
|
|
rndis->port.unwrap = rndis_rm_hdr;
|
|
|
|
|
|
|
|
rndis->port.func.name = "rndis";
|
|
|
|
rndis->port.func.strings = rndis_strings;
|
|
|
|
/* descriptors are per-instance copies */
|
|
|
|
rndis->port.func.bind = rndis_bind;
|
|
|
|
rndis->port.func.unbind = rndis_unbind;
|
|
|
|
rndis->port.func.set_alt = rndis_set_alt;
|
|
|
|
rndis->port.func.setup = rndis_setup;
|
|
|
|
rndis->port.func.disable = rndis_disable;
|
|
|
|
|
|
|
|
status = usb_add_function(c, &rndis->port.func);
|
|
|
|
if (status) {
|
|
|
|
kfree(rndis);
|
|
|
|
fail:
|
|
|
|
rndis_exit();
|
|
|
|
}
|
|
|
|
return status;
|
|
|
|
}
|