4 * Authors: Benedikt Spranger, Pengutronix
5 * Robert Schwebel, Pengutronix
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * version 2, as published by the Free Software Foundation.
11 * This software was originally developed in conformance with
12 * Microsoft's Remote NDIS Specification License Agreement.
14 * 03/12/2004 Kai-Uwe Bloem <linux-development@auerswald.de>
15 * Fixed message length bug in init_response
17 * 03/25/2004 Kai-Uwe Bloem <linux-development@auerswald.de>
18 * Fixed rndis_rm_hdr length bug.
20 * Copyright (C) 2004 by David Brownell
21 * updates to merge with Linux 2.6, better match RNDIS spec
24 #include <linux/module.h>
25 #include <linux/moduleparam.h>
26 #include <linux/kernel.h>
27 #include <linux/errno.h>
28 #include <linux/init.h>
29 #include <linux/list.h>
30 #include <linux/proc_fs.h>
31 #include <linux/netdevice.h>
34 #include <asm/byteorder.h>
35 #include <asm/system.h>
36 #include <asm/unaligned.h>
46 /* The driver for your USB chip needs to support ep0 OUT to work with
47 * RNDIS, plus all three CDC Ethernet endpoints (interrupt not optional).
49 * Windows hosts need an INF file like Documentation/usb/linux.inf
50 * and will be happier if you provide the host_addr module parameter.
54 static int rndis_debug
= 0;
55 module_param (rndis_debug
, int, 0);
56 MODULE_PARM_DESC (rndis_debug
, "enable debugging");
61 #define DBG(str,args...) do { \
63 pr_debug(str , ## args); \
66 #define RNDIS_MAX_CONFIGS 1
69 static rndis_params rndis_per_dev_params
[RNDIS_MAX_CONFIGS
];
72 static const __le32 rndis_driver_version
= __constant_cpu_to_le32 (1);
74 /* Function Prototypes */
75 static rndis_resp_t
*rndis_add_response (int configNr
, u32 length
);
79 static const u32 oid_supported_list
[] =
81 /* the general stuff */
82 OID_GEN_SUPPORTED_LIST
,
83 OID_GEN_HARDWARE_STATUS
,
84 OID_GEN_MEDIA_SUPPORTED
,
86 OID_GEN_MAXIMUM_FRAME_SIZE
,
88 OID_GEN_TRANSMIT_BLOCK_SIZE
,
89 OID_GEN_RECEIVE_BLOCK_SIZE
,
91 OID_GEN_VENDOR_DESCRIPTION
,
92 OID_GEN_VENDOR_DRIVER_VERSION
,
93 OID_GEN_CURRENT_PACKET_FILTER
,
94 OID_GEN_MAXIMUM_TOTAL_SIZE
,
95 OID_GEN_MEDIA_CONNECT_STATUS
,
96 OID_GEN_PHYSICAL_MEDIUM
,
98 OID_GEN_RNDIS_CONFIG_PARAMETER
,
101 /* the statistical stuff */
106 OID_GEN_RCV_NO_BUFFER
,
107 #ifdef RNDIS_OPTIONAL_STATS
108 OID_GEN_DIRECTED_BYTES_XMIT
,
109 OID_GEN_DIRECTED_FRAMES_XMIT
,
110 OID_GEN_MULTICAST_BYTES_XMIT
,
111 OID_GEN_MULTICAST_FRAMES_XMIT
,
112 OID_GEN_BROADCAST_BYTES_XMIT
,
113 OID_GEN_BROADCAST_FRAMES_XMIT
,
114 OID_GEN_DIRECTED_BYTES_RCV
,
115 OID_GEN_DIRECTED_FRAMES_RCV
,
116 OID_GEN_MULTICAST_BYTES_RCV
,
117 OID_GEN_MULTICAST_FRAMES_RCV
,
118 OID_GEN_BROADCAST_BYTES_RCV
,
119 OID_GEN_BROADCAST_FRAMES_RCV
,
120 OID_GEN_RCV_CRC_ERROR
,
121 OID_GEN_TRANSMIT_QUEUE_LENGTH
,
122 #endif /* RNDIS_OPTIONAL_STATS */
124 /* mandatory 802.3 */
125 /* the general stuff */
126 OID_802_3_PERMANENT_ADDRESS
,
127 OID_802_3_CURRENT_ADDRESS
,
128 OID_802_3_MULTICAST_LIST
,
129 OID_802_3_MAC_OPTIONS
,
130 OID_802_3_MAXIMUM_LIST_SIZE
,
132 /* the statistical stuff */
133 OID_802_3_RCV_ERROR_ALIGNMENT
,
134 OID_802_3_XMIT_ONE_COLLISION
,
135 OID_802_3_XMIT_MORE_COLLISIONS
,
136 #ifdef RNDIS_OPTIONAL_STATS
137 OID_802_3_XMIT_DEFERRED
,
138 OID_802_3_XMIT_MAX_COLLISIONS
,
139 OID_802_3_RCV_OVERRUN
,
140 OID_802_3_XMIT_UNDERRUN
,
141 OID_802_3_XMIT_HEARTBEAT_FAILURE
,
142 OID_802_3_XMIT_TIMES_CRS_LOST
,
143 OID_802_3_XMIT_LATE_COLLISIONS
,
144 #endif /* RNDIS_OPTIONAL_STATS */
147 /* PM and wakeup are mandatory for USB: */
149 /* power management */
150 OID_PNP_CAPABILITIES
,
156 OID_PNP_ENABLE_WAKE_UP
,
157 OID_PNP_ADD_WAKE_UP_PATTERN
,
158 OID_PNP_REMOVE_WAKE_UP_PATTERN
,
159 #endif /* RNDIS_WAKEUP */
160 #endif /* RNDIS_PM */
166 gen_ndis_query_resp (int configNr
, u32 OID
, u8
*buf
, unsigned buf_len
,
169 int retval
= -ENOTSUPP
;
170 u32 length
= 4; /* usually */
173 rndis_query_cmplt_type
*resp
;
175 if (!r
) return -ENOMEM
;
176 resp
= (rndis_query_cmplt_type
*) r
->buf
;
178 if (!resp
) return -ENOMEM
;
180 if (buf_len
&& rndis_debug
> 1) {
181 DBG("query OID %08x value, len %d:\n", OID
, buf_len
);
182 for (i
= 0; i
< buf_len
; i
+= 16) {
183 DBG("%03d: %08x %08x %08x %08x\n", i
,
184 get_unaligned_le32(&buf
[i
]),
185 get_unaligned_le32(&buf
[i
+ 4]),
186 get_unaligned_le32(&buf
[i
+ 8]),
187 get_unaligned_le32(&buf
[i
+ 12]));
191 /* response goes here, right after the header */
192 outbuf
= (__le32
*) &resp
[1];
193 resp
->InformationBufferOffset
= __constant_cpu_to_le32 (16);
197 /* general oids (table 4-1) */
200 case OID_GEN_SUPPORTED_LIST
:
201 DBG("%s: OID_GEN_SUPPORTED_LIST\n", __func__
);
202 length
= sizeof (oid_supported_list
);
203 count
= length
/ sizeof (u32
);
204 for (i
= 0; i
< count
; i
++)
205 outbuf
[i
] = cpu_to_le32 (oid_supported_list
[i
]);
210 case OID_GEN_HARDWARE_STATUS
:
211 DBG("%s: OID_GEN_HARDWARE_STATUS\n", __func__
);
213 * Hardware must be ready to receive high level protocols.
215 * reddite ergo quae sunt Caesaris Caesari
216 * et quae sunt Dei Deo!
218 *outbuf
= __constant_cpu_to_le32 (0);
223 case OID_GEN_MEDIA_SUPPORTED
:
224 DBG("%s: OID_GEN_MEDIA_SUPPORTED\n", __func__
);
225 *outbuf
= cpu_to_le32 (rndis_per_dev_params
[configNr
].medium
);
230 case OID_GEN_MEDIA_IN_USE
:
231 DBG("%s: OID_GEN_MEDIA_IN_USE\n", __func__
);
232 /* one medium, one transport... (maybe you do it better) */
233 *outbuf
= cpu_to_le32 (rndis_per_dev_params
[configNr
].medium
);
238 case OID_GEN_MAXIMUM_FRAME_SIZE
:
239 DBG("%s: OID_GEN_MAXIMUM_FRAME_SIZE\n", __func__
);
240 if (rndis_per_dev_params
[configNr
].dev
) {
241 *outbuf
= cpu_to_le32 (
242 rndis_per_dev_params
[configNr
].dev
->mtu
);
248 case OID_GEN_LINK_SPEED
:
250 DBG("%s: OID_GEN_LINK_SPEED\n", __func__
);
251 if (rndis_per_dev_params
[configNr
].media_state
252 == NDIS_MEDIA_STATE_DISCONNECTED
)
253 *outbuf
= __constant_cpu_to_le32 (0);
255 *outbuf
= cpu_to_le32 (
256 rndis_per_dev_params
[configNr
].speed
);
261 case OID_GEN_TRANSMIT_BLOCK_SIZE
:
262 DBG("%s: OID_GEN_TRANSMIT_BLOCK_SIZE\n", __func__
);
263 if (rndis_per_dev_params
[configNr
].dev
) {
264 *outbuf
= cpu_to_le32 (
265 rndis_per_dev_params
[configNr
].dev
->mtu
);
271 case OID_GEN_RECEIVE_BLOCK_SIZE
:
272 DBG("%s: OID_GEN_RECEIVE_BLOCK_SIZE\n", __func__
);
273 if (rndis_per_dev_params
[configNr
].dev
) {
274 *outbuf
= cpu_to_le32 (
275 rndis_per_dev_params
[configNr
].dev
->mtu
);
281 case OID_GEN_VENDOR_ID
:
282 DBG("%s: OID_GEN_VENDOR_ID\n", __func__
);
283 *outbuf
= cpu_to_le32 (
284 rndis_per_dev_params
[configNr
].vendorID
);
289 case OID_GEN_VENDOR_DESCRIPTION
:
290 DBG("%s: OID_GEN_VENDOR_DESCRIPTION\n", __func__
);
291 length
= strlen (rndis_per_dev_params
[configNr
].vendorDescr
);
293 rndis_per_dev_params
[configNr
].vendorDescr
, length
);
297 case OID_GEN_VENDOR_DRIVER_VERSION
:
298 DBG("%s: OID_GEN_VENDOR_DRIVER_VERSION\n", __func__
);
300 *outbuf
= rndis_driver_version
;
305 case OID_GEN_CURRENT_PACKET_FILTER
:
306 DBG("%s: OID_GEN_CURRENT_PACKET_FILTER\n", __func__
);
307 *outbuf
= cpu_to_le32 (*rndis_per_dev_params
[configNr
].filter
);
312 case OID_GEN_MAXIMUM_TOTAL_SIZE
:
313 DBG("%s: OID_GEN_MAXIMUM_TOTAL_SIZE\n", __func__
);
314 *outbuf
= __constant_cpu_to_le32(RNDIS_MAX_TOTAL_SIZE
);
319 case OID_GEN_MEDIA_CONNECT_STATUS
:
321 DBG("%s: OID_GEN_MEDIA_CONNECT_STATUS\n", __func__
);
322 *outbuf
= cpu_to_le32 (rndis_per_dev_params
[configNr
]
327 case OID_GEN_PHYSICAL_MEDIUM
:
328 DBG("%s: OID_GEN_PHYSICAL_MEDIUM\n", __func__
);
329 *outbuf
= __constant_cpu_to_le32 (0);
333 /* The RNDIS specification is incomplete/wrong. Some versions
334 * of MS-Windows expect OIDs that aren't specified there. Other
335 * versions emit undefined RNDIS messages. DOCUMENT ALL THESE!
337 case OID_GEN_MAC_OPTIONS
: /* from WinME */
338 DBG("%s: OID_GEN_MAC_OPTIONS\n", __func__
);
339 *outbuf
= __constant_cpu_to_le32(
340 NDIS_MAC_OPTION_RECEIVE_SERIALIZED
341 | NDIS_MAC_OPTION_FULL_DUPLEX
);
345 /* statistics OIDs (table 4-2) */
348 case OID_GEN_XMIT_OK
:
350 DBG("%s: OID_GEN_XMIT_OK\n", __func__
);
351 if (rndis_per_dev_params
[configNr
].stats
) {
352 *outbuf
= cpu_to_le32 (
353 rndis_per_dev_params
[configNr
].stats
->tx_packets
-
354 rndis_per_dev_params
[configNr
].stats
->tx_errors
-
355 rndis_per_dev_params
[configNr
].stats
->tx_dropped
);
363 DBG("%s: OID_GEN_RCV_OK\n", __func__
);
364 if (rndis_per_dev_params
[configNr
].stats
) {
365 *outbuf
= cpu_to_le32 (
366 rndis_per_dev_params
[configNr
].stats
->rx_packets
-
367 rndis_per_dev_params
[configNr
].stats
->rx_errors
-
368 rndis_per_dev_params
[configNr
].stats
->rx_dropped
);
374 case OID_GEN_XMIT_ERROR
:
376 DBG("%s: OID_GEN_XMIT_ERROR\n", __func__
);
377 if (rndis_per_dev_params
[configNr
].stats
) {
378 *outbuf
= cpu_to_le32 (rndis_per_dev_params
[configNr
]
385 case OID_GEN_RCV_ERROR
:
387 DBG("%s: OID_GEN_RCV_ERROR\n", __func__
);
388 if (rndis_per_dev_params
[configNr
].stats
) {
389 *outbuf
= cpu_to_le32 (rndis_per_dev_params
[configNr
]
396 case OID_GEN_RCV_NO_BUFFER
:
397 DBG("%s: OID_GEN_RCV_NO_BUFFER\n", __func__
);
398 if (rndis_per_dev_params
[configNr
].stats
) {
399 *outbuf
= cpu_to_le32 (rndis_per_dev_params
[configNr
]
405 #ifdef RNDIS_OPTIONAL_STATS
406 case OID_GEN_DIRECTED_BYTES_XMIT
:
407 DBG("%s: OID_GEN_DIRECTED_BYTES_XMIT\n", __func__
);
409 * Aunt Tilly's size of shoes
410 * minus antarctica count of penguins
411 * divided by weight of Alpha Centauri
413 if (rndis_per_dev_params
[configNr
].stats
) {
414 *outbuf
= cpu_to_le32 (
415 (rndis_per_dev_params
[configNr
]
417 rndis_per_dev_params
[configNr
]
419 rndis_per_dev_params
[configNr
]
426 case OID_GEN_DIRECTED_FRAMES_XMIT
:
427 DBG("%s: OID_GEN_DIRECTED_FRAMES_XMIT\n", __func__
);
429 if (rndis_per_dev_params
[configNr
].stats
) {
430 *outbuf
= cpu_to_le32 (
431 (rndis_per_dev_params
[configNr
]
433 rndis_per_dev_params
[configNr
]
435 rndis_per_dev_params
[configNr
]
442 case OID_GEN_MULTICAST_BYTES_XMIT
:
443 DBG("%s: OID_GEN_MULTICAST_BYTES_XMIT\n", __func__
);
444 if (rndis_per_dev_params
[configNr
].stats
) {
445 *outbuf
= cpu_to_le32 (rndis_per_dev_params
[configNr
]
446 .stats
->multicast
*1234);
451 case OID_GEN_MULTICAST_FRAMES_XMIT
:
452 DBG("%s: OID_GEN_MULTICAST_FRAMES_XMIT\n", __func__
);
453 if (rndis_per_dev_params
[configNr
].stats
) {
454 *outbuf
= cpu_to_le32 (rndis_per_dev_params
[configNr
]
460 case OID_GEN_BROADCAST_BYTES_XMIT
:
461 DBG("%s: OID_GEN_BROADCAST_BYTES_XMIT\n", __func__
);
462 if (rndis_per_dev_params
[configNr
].stats
) {
463 *outbuf
= cpu_to_le32 (rndis_per_dev_params
[configNr
]
464 .stats
->tx_packets
/42*255);
469 case OID_GEN_BROADCAST_FRAMES_XMIT
:
470 DBG("%s: OID_GEN_BROADCAST_FRAMES_XMIT\n", __func__
);
471 if (rndis_per_dev_params
[configNr
].stats
) {
472 *outbuf
= cpu_to_le32 (rndis_per_dev_params
[configNr
]
473 .stats
->tx_packets
/42);
478 case OID_GEN_DIRECTED_BYTES_RCV
:
479 DBG("%s: OID_GEN_DIRECTED_BYTES_RCV\n", __func__
);
480 *outbuf
= __constant_cpu_to_le32 (0);
484 case OID_GEN_DIRECTED_FRAMES_RCV
:
485 DBG("%s: OID_GEN_DIRECTED_FRAMES_RCV\n", __func__
);
486 *outbuf
= __constant_cpu_to_le32 (0);
490 case OID_GEN_MULTICAST_BYTES_RCV
:
491 DBG("%s: OID_GEN_MULTICAST_BYTES_RCV\n", __func__
);
492 if (rndis_per_dev_params
[configNr
].stats
) {
493 *outbuf
= cpu_to_le32 (rndis_per_dev_params
[configNr
]
494 .stats
->multicast
* 1111);
499 case OID_GEN_MULTICAST_FRAMES_RCV
:
500 DBG("%s: OID_GEN_MULTICAST_FRAMES_RCV\n", __func__
);
501 if (rndis_per_dev_params
[configNr
].stats
) {
502 *outbuf
= cpu_to_le32 (rndis_per_dev_params
[configNr
]
508 case OID_GEN_BROADCAST_BYTES_RCV
:
509 DBG("%s: OID_GEN_BROADCAST_BYTES_RCV\n", __func__
);
510 if (rndis_per_dev_params
[configNr
].stats
) {
511 *outbuf
= cpu_to_le32 (rndis_per_dev_params
[configNr
]
512 .stats
->rx_packets
/42*255);
517 case OID_GEN_BROADCAST_FRAMES_RCV
:
518 DBG("%s: OID_GEN_BROADCAST_FRAMES_RCV\n", __func__
);
519 if (rndis_per_dev_params
[configNr
].stats
) {
520 *outbuf
= cpu_to_le32 (rndis_per_dev_params
[configNr
]
521 .stats
->rx_packets
/42);
526 case OID_GEN_RCV_CRC_ERROR
:
527 DBG("%s: OID_GEN_RCV_CRC_ERROR\n", __func__
);
528 if (rndis_per_dev_params
[configNr
].stats
) {
529 *outbuf
= cpu_to_le32 (rndis_per_dev_params
[configNr
]
530 .stats
->rx_crc_errors
);
535 case OID_GEN_TRANSMIT_QUEUE_LENGTH
:
536 DBG("%s: OID_GEN_TRANSMIT_QUEUE_LENGTH\n", __func__
);
537 *outbuf
= __constant_cpu_to_le32 (0);
540 #endif /* RNDIS_OPTIONAL_STATS */
542 /* ieee802.3 OIDs (table 4-3) */
545 case OID_802_3_PERMANENT_ADDRESS
:
546 DBG("%s: OID_802_3_PERMANENT_ADDRESS\n", __func__
);
547 if (rndis_per_dev_params
[configNr
].dev
) {
550 rndis_per_dev_params
[configNr
].host_mac
,
557 case OID_802_3_CURRENT_ADDRESS
:
558 DBG("%s: OID_802_3_CURRENT_ADDRESS\n", __func__
);
559 if (rndis_per_dev_params
[configNr
].dev
) {
562 rndis_per_dev_params
[configNr
].host_mac
,
569 case OID_802_3_MULTICAST_LIST
:
570 DBG("%s: OID_802_3_MULTICAST_LIST\n", __func__
);
571 /* Multicast base address only */
572 *outbuf
= __constant_cpu_to_le32 (0xE0000000);
577 case OID_802_3_MAXIMUM_LIST_SIZE
:
578 DBG("%s: OID_802_3_MAXIMUM_LIST_SIZE\n", __func__
);
579 /* Multicast base address only */
580 *outbuf
= __constant_cpu_to_le32 (1);
584 case OID_802_3_MAC_OPTIONS
:
585 DBG("%s: OID_802_3_MAC_OPTIONS\n", __func__
);
588 /* ieee802.3 statistics OIDs (table 4-4) */
591 case OID_802_3_RCV_ERROR_ALIGNMENT
:
592 DBG("%s: OID_802_3_RCV_ERROR_ALIGNMENT\n", __func__
);
593 if (rndis_per_dev_params
[configNr
].stats
) {
594 *outbuf
= cpu_to_le32 (rndis_per_dev_params
[configNr
]
595 .stats
->rx_frame_errors
);
601 case OID_802_3_XMIT_ONE_COLLISION
:
602 DBG("%s: OID_802_3_XMIT_ONE_COLLISION\n", __func__
);
603 *outbuf
= __constant_cpu_to_le32 (0);
608 case OID_802_3_XMIT_MORE_COLLISIONS
:
609 DBG("%s: OID_802_3_XMIT_MORE_COLLISIONS\n", __func__
);
610 *outbuf
= __constant_cpu_to_le32 (0);
614 #ifdef RNDIS_OPTIONAL_STATS
615 case OID_802_3_XMIT_DEFERRED
:
616 DBG("%s: OID_802_3_XMIT_DEFERRED\n", __func__
);
620 case OID_802_3_XMIT_MAX_COLLISIONS
:
621 DBG("%s: OID_802_3_XMIT_MAX_COLLISIONS\n", __func__
);
625 case OID_802_3_RCV_OVERRUN
:
626 DBG("%s: OID_802_3_RCV_OVERRUN\n", __func__
);
630 case OID_802_3_XMIT_UNDERRUN
:
631 DBG("%s: OID_802_3_XMIT_UNDERRUN\n", __func__
);
635 case OID_802_3_XMIT_HEARTBEAT_FAILURE
:
636 DBG("%s: OID_802_3_XMIT_HEARTBEAT_FAILURE\n", __func__
);
640 case OID_802_3_XMIT_TIMES_CRS_LOST
:
641 DBG("%s: OID_802_3_XMIT_TIMES_CRS_LOST\n", __func__
);
645 case OID_802_3_XMIT_LATE_COLLISIONS
:
646 DBG("%s: OID_802_3_XMIT_LATE_COLLISIONS\n", __func__
);
649 #endif /* RNDIS_OPTIONAL_STATS */
652 /* power management OIDs (table 4-5) */
653 case OID_PNP_CAPABILITIES
:
654 DBG("%s: OID_PNP_CAPABILITIES\n", __func__
);
656 /* for now, no wakeup capabilities */
657 length
= sizeof (struct NDIS_PNP_CAPABILITIES
);
658 memset(outbuf
, 0, length
);
661 case OID_PNP_QUERY_POWER
:
662 DBG("%s: OID_PNP_QUERY_POWER D%d\n", __func__
,
663 get_unaligned_le32(buf
) - 1);
664 /* only suspend is a real power state, and
665 * it can't be entered by OID_PNP_SET_POWER...
673 pr_warning("%s: query unknown OID 0x%08X\n",
679 resp
->InformationBufferLength
= cpu_to_le32 (length
);
680 r
->length
= length
+ sizeof *resp
;
681 resp
->MessageLength
= cpu_to_le32 (r
->length
);
685 static int gen_ndis_set_resp (u8 configNr
, u32 OID
, u8
*buf
, u32 buf_len
,
688 rndis_set_cmplt_type
*resp
;
689 int i
, retval
= -ENOTSUPP
;
690 struct rndis_params
*params
;
694 resp
= (rndis_set_cmplt_type
*) r
->buf
;
698 if (buf_len
&& rndis_debug
> 1) {
699 DBG("set OID %08x value, len %d:\n", OID
, buf_len
);
700 for (i
= 0; i
< buf_len
; i
+= 16) {
701 DBG("%03d: %08x %08x %08x %08x\n", i
,
702 get_unaligned_le32(&buf
[i
]),
703 get_unaligned_le32(&buf
[i
+ 4]),
704 get_unaligned_le32(&buf
[i
+ 8]),
705 get_unaligned_le32(&buf
[i
+ 12]));
709 params
= &rndis_per_dev_params
[configNr
];
711 case OID_GEN_CURRENT_PACKET_FILTER
:
713 /* these NDIS_PACKET_TYPE_* bitflags are shared with
714 * cdc_filter; it's not RNDIS-specific
715 * NDIS_PACKET_TYPE_x == USB_CDC_PACKET_TYPE_x for x in:
716 * PROMISCUOUS, DIRECTED,
717 * MULTICAST, ALL_MULTICAST, BROADCAST
719 *params
->filter
= (u16
)get_unaligned_le32(buf
);
720 DBG("%s: OID_GEN_CURRENT_PACKET_FILTER %08x\n",
721 __func__
, *params
->filter
);
723 /* this call has a significant side effect: it's
724 * what makes the packet flow start and stop, like
725 * activating the CDC Ethernet altsetting.
731 if (*params
->filter
) {
732 params
->state
= RNDIS_DATA_INITIALIZED
;
733 netif_carrier_on(params
->dev
);
734 if (netif_running(params
->dev
))
735 netif_wake_queue (params
->dev
);
737 params
->state
= RNDIS_INITIALIZED
;
738 netif_carrier_off (params
->dev
);
739 netif_stop_queue (params
->dev
);
743 case OID_802_3_MULTICAST_LIST
:
744 /* I think we can ignore this */
745 DBG("%s: OID_802_3_MULTICAST_LIST\n", __func__
);
749 case OID_GEN_RNDIS_CONFIG_PARAMETER
:
751 struct rndis_config_parameter
*param
;
752 param
= (struct rndis_config_parameter
*) buf
;
753 DBG("%s: OID_GEN_RNDIS_CONFIG_PARAMETER '%*s'\n",
755 min(cpu_to_le32(param
->ParameterNameLength
),80),
756 buf
+ param
->ParameterNameOffset
);
763 case OID_PNP_SET_POWER
:
764 /* The only real power state is USB suspend, and RNDIS requests
765 * can't enter it; this one isn't really about power. After
766 * resuming, Windows forces a reset, and then SET_POWER D0.
767 * FIXME ... then things go batty; Windows wedges itself.
769 i
= get_unaligned_le32(buf
);
770 DBG("%s: OID_PNP_SET_POWER D%d\n", __func__
, i
- 1);
772 case NdisDeviceStateD0
:
773 *params
->filter
= params
->saved_filter
;
774 goto update_linkstate
;
775 case NdisDeviceStateD3
:
776 case NdisDeviceStateD2
:
777 case NdisDeviceStateD1
:
778 params
->saved_filter
= *params
->filter
;
785 // no wakeup support advertised, so wakeup OIDs always fail:
786 // - OID_PNP_ENABLE_WAKE_UP
787 // - OID_PNP_{ADD,REMOVE}_WAKE_UP_PATTERN
790 #endif /* RNDIS_PM */
793 pr_warning("%s: set unknown OID 0x%08X, size %d\n",
794 __func__
, OID
, buf_len
);
804 static int rndis_init_response (int configNr
, rndis_init_msg_type
*buf
)
806 rndis_init_cmplt_type
*resp
;
809 if (!rndis_per_dev_params
[configNr
].dev
) return -ENOTSUPP
;
811 r
= rndis_add_response (configNr
, sizeof (rndis_init_cmplt_type
));
814 resp
= (rndis_init_cmplt_type
*) r
->buf
;
816 resp
->MessageType
= __constant_cpu_to_le32 (
817 REMOTE_NDIS_INITIALIZE_CMPLT
);
818 resp
->MessageLength
= __constant_cpu_to_le32 (52);
819 resp
->RequestID
= buf
->RequestID
; /* Still LE in msg buffer */
820 resp
->Status
= __constant_cpu_to_le32 (RNDIS_STATUS_SUCCESS
);
821 resp
->MajorVersion
= __constant_cpu_to_le32 (RNDIS_MAJOR_VERSION
);
822 resp
->MinorVersion
= __constant_cpu_to_le32 (RNDIS_MINOR_VERSION
);
823 resp
->DeviceFlags
= __constant_cpu_to_le32 (RNDIS_DF_CONNECTIONLESS
);
824 resp
->Medium
= __constant_cpu_to_le32 (RNDIS_MEDIUM_802_3
);
825 resp
->MaxPacketsPerTransfer
= __constant_cpu_to_le32 (1);
826 resp
->MaxTransferSize
= cpu_to_le32 (
827 rndis_per_dev_params
[configNr
].dev
->mtu
828 + sizeof (struct ethhdr
)
829 + sizeof (struct rndis_packet_msg_type
)
831 resp
->PacketAlignmentFactor
= __constant_cpu_to_le32 (0);
832 resp
->AFListOffset
= __constant_cpu_to_le32 (0);
833 resp
->AFListSize
= __constant_cpu_to_le32 (0);
835 if (rndis_per_dev_params
[configNr
].ack
)
836 rndis_per_dev_params
[configNr
].ack (
837 rndis_per_dev_params
[configNr
].dev
);
842 static int rndis_query_response (int configNr
, rndis_query_msg_type
*buf
)
844 rndis_query_cmplt_type
*resp
;
847 // DBG("%s: OID = %08X\n", __func__, cpu_to_le32(buf->OID));
848 if (!rndis_per_dev_params
[configNr
].dev
) return -ENOTSUPP
;
851 * we need more memory:
852 * gen_ndis_query_resp expects enough space for
853 * rndis_query_cmplt_type followed by data.
854 * oid_supported_list is the largest data reply
856 r
= rndis_add_response (configNr
,
857 sizeof (oid_supported_list
) + sizeof(rndis_query_cmplt_type
));
860 resp
= (rndis_query_cmplt_type
*) r
->buf
;
862 resp
->MessageType
= __constant_cpu_to_le32 (REMOTE_NDIS_QUERY_CMPLT
);
863 resp
->RequestID
= buf
->RequestID
; /* Still LE in msg buffer */
865 if (gen_ndis_query_resp (configNr
, le32_to_cpu (buf
->OID
),
866 le32_to_cpu(buf
->InformationBufferOffset
)
868 le32_to_cpu(buf
->InformationBufferLength
),
870 /* OID not supported */
871 resp
->Status
= __constant_cpu_to_le32 (
872 RNDIS_STATUS_NOT_SUPPORTED
);
873 resp
->MessageLength
= __constant_cpu_to_le32 (sizeof *resp
);
874 resp
->InformationBufferLength
= __constant_cpu_to_le32 (0);
875 resp
->InformationBufferOffset
= __constant_cpu_to_le32 (0);
877 resp
->Status
= __constant_cpu_to_le32 (RNDIS_STATUS_SUCCESS
);
879 if (rndis_per_dev_params
[configNr
].ack
)
880 rndis_per_dev_params
[configNr
].ack (
881 rndis_per_dev_params
[configNr
].dev
);
885 static int rndis_set_response (int configNr
, rndis_set_msg_type
*buf
)
887 u32 BufLength
, BufOffset
;
888 rndis_set_cmplt_type
*resp
;
891 r
= rndis_add_response (configNr
, sizeof (rndis_set_cmplt_type
));
894 resp
= (rndis_set_cmplt_type
*) r
->buf
;
896 BufLength
= le32_to_cpu (buf
->InformationBufferLength
);
897 BufOffset
= le32_to_cpu (buf
->InformationBufferOffset
);
900 DBG("%s: Length: %d\n", __func__
, BufLength
);
901 DBG("%s: Offset: %d\n", __func__
, BufOffset
);
902 DBG("%s: InfoBuffer: ", __func__
);
904 for (i
= 0; i
< BufLength
; i
++) {
905 DBG("%02x ", *(((u8
*) buf
) + i
+ 8 + BufOffset
));
911 resp
->MessageType
= __constant_cpu_to_le32 (REMOTE_NDIS_SET_CMPLT
);
912 resp
->MessageLength
= __constant_cpu_to_le32 (16);
913 resp
->RequestID
= buf
->RequestID
; /* Still LE in msg buffer */
914 if (gen_ndis_set_resp (configNr
, le32_to_cpu (buf
->OID
),
915 ((u8
*) buf
) + 8 + BufOffset
, BufLength
, r
))
916 resp
->Status
= __constant_cpu_to_le32 (RNDIS_STATUS_NOT_SUPPORTED
);
918 resp
->Status
= __constant_cpu_to_le32 (RNDIS_STATUS_SUCCESS
);
920 if (rndis_per_dev_params
[configNr
].ack
)
921 rndis_per_dev_params
[configNr
].ack (
922 rndis_per_dev_params
[configNr
].dev
);
927 static int rndis_reset_response (int configNr
, rndis_reset_msg_type
*buf
)
929 rndis_reset_cmplt_type
*resp
;
932 r
= rndis_add_response (configNr
, sizeof (rndis_reset_cmplt_type
));
935 resp
= (rndis_reset_cmplt_type
*) r
->buf
;
937 resp
->MessageType
= __constant_cpu_to_le32 (REMOTE_NDIS_RESET_CMPLT
);
938 resp
->MessageLength
= __constant_cpu_to_le32 (16);
939 resp
->Status
= __constant_cpu_to_le32 (RNDIS_STATUS_SUCCESS
);
940 /* resent information */
941 resp
->AddressingReset
= __constant_cpu_to_le32 (1);
943 if (rndis_per_dev_params
[configNr
].ack
)
944 rndis_per_dev_params
[configNr
].ack (
945 rndis_per_dev_params
[configNr
].dev
);
950 static int rndis_keepalive_response (int configNr
,
951 rndis_keepalive_msg_type
*buf
)
953 rndis_keepalive_cmplt_type
*resp
;
956 /* host "should" check only in RNDIS_DATA_INITIALIZED state */
958 r
= rndis_add_response (configNr
, sizeof (rndis_keepalive_cmplt_type
));
961 resp
= (rndis_keepalive_cmplt_type
*) r
->buf
;
963 resp
->MessageType
= __constant_cpu_to_le32 (
964 REMOTE_NDIS_KEEPALIVE_CMPLT
);
965 resp
->MessageLength
= __constant_cpu_to_le32 (16);
966 resp
->RequestID
= buf
->RequestID
; /* Still LE in msg buffer */
967 resp
->Status
= __constant_cpu_to_le32 (RNDIS_STATUS_SUCCESS
);
969 if (rndis_per_dev_params
[configNr
].ack
)
970 rndis_per_dev_params
[configNr
].ack (
971 rndis_per_dev_params
[configNr
].dev
);
978 * Device to Host Comunication
980 static int rndis_indicate_status_msg (int configNr
, u32 status
)
982 rndis_indicate_status_msg_type
*resp
;
985 if (rndis_per_dev_params
[configNr
].state
== RNDIS_UNINITIALIZED
)
988 r
= rndis_add_response (configNr
,
989 sizeof (rndis_indicate_status_msg_type
));
992 resp
= (rndis_indicate_status_msg_type
*) r
->buf
;
994 resp
->MessageType
= __constant_cpu_to_le32 (
995 REMOTE_NDIS_INDICATE_STATUS_MSG
);
996 resp
->MessageLength
= __constant_cpu_to_le32 (20);
997 resp
->Status
= cpu_to_le32 (status
);
998 resp
->StatusBufferLength
= __constant_cpu_to_le32 (0);
999 resp
->StatusBufferOffset
= __constant_cpu_to_le32 (0);
1001 if (rndis_per_dev_params
[configNr
].ack
)
1002 rndis_per_dev_params
[configNr
].ack (
1003 rndis_per_dev_params
[configNr
].dev
);
1007 int rndis_signal_connect (int configNr
)
1009 rndis_per_dev_params
[configNr
].media_state
1010 = NDIS_MEDIA_STATE_CONNECTED
;
1011 return rndis_indicate_status_msg (configNr
,
1012 RNDIS_STATUS_MEDIA_CONNECT
);
1015 int rndis_signal_disconnect (int configNr
)
1017 rndis_per_dev_params
[configNr
].media_state
1018 = NDIS_MEDIA_STATE_DISCONNECTED
;
1019 return rndis_indicate_status_msg (configNr
,
1020 RNDIS_STATUS_MEDIA_DISCONNECT
);
1023 void rndis_uninit (int configNr
)
1028 if (configNr
>= RNDIS_MAX_CONFIGS
)
1030 rndis_per_dev_params
[configNr
].used
= 0;
1031 rndis_per_dev_params
[configNr
].state
= RNDIS_UNINITIALIZED
;
1033 /* drain the response queue */
1034 while ((buf
= rndis_get_next_response(configNr
, &length
)))
1035 rndis_free_response(configNr
, buf
);
1038 void rndis_set_host_mac (int configNr
, const u8
*addr
)
1040 rndis_per_dev_params
[configNr
].host_mac
= addr
;
1046 int rndis_msg_parser (u8 configNr
, u8
*buf
)
1048 u32 MsgType
, MsgLength
;
1050 struct rndis_params
*params
;
1055 tmp
= (__le32
*) buf
;
1056 MsgType
= get_unaligned_le32(tmp
++);
1057 MsgLength
= get_unaligned_le32(tmp
++);
1059 if (configNr
>= RNDIS_MAX_CONFIGS
)
1061 params
= &rndis_per_dev_params
[configNr
];
1063 /* NOTE: RNDIS is *EXTREMELY* chatty ... Windows constantly polls for
1064 * rx/tx statistics and link status, in addition to KEEPALIVE traffic
1065 * and normal HC level polling to see if there's any IN traffic.
1068 /* For USB: responses may take up to 10 seconds */
1070 case REMOTE_NDIS_INITIALIZE_MSG
:
1071 DBG("%s: REMOTE_NDIS_INITIALIZE_MSG\n",
1073 params
->state
= RNDIS_INITIALIZED
;
1074 return rndis_init_response (configNr
,
1075 (rndis_init_msg_type
*) buf
);
1077 case REMOTE_NDIS_HALT_MSG
:
1078 DBG("%s: REMOTE_NDIS_HALT_MSG\n",
1080 params
->state
= RNDIS_UNINITIALIZED
;
1082 netif_carrier_off (params
->dev
);
1083 netif_stop_queue (params
->dev
);
1087 case REMOTE_NDIS_QUERY_MSG
:
1088 return rndis_query_response (configNr
,
1089 (rndis_query_msg_type
*) buf
);
1091 case REMOTE_NDIS_SET_MSG
:
1092 return rndis_set_response (configNr
,
1093 (rndis_set_msg_type
*) buf
);
1095 case REMOTE_NDIS_RESET_MSG
:
1096 DBG("%s: REMOTE_NDIS_RESET_MSG\n",
1098 return rndis_reset_response (configNr
,
1099 (rndis_reset_msg_type
*) buf
);
1101 case REMOTE_NDIS_KEEPALIVE_MSG
:
1102 /* For USB: host does this every 5 seconds */
1103 if (rndis_debug
> 1)
1104 DBG("%s: REMOTE_NDIS_KEEPALIVE_MSG\n",
1106 return rndis_keepalive_response (configNr
,
1107 (rndis_keepalive_msg_type
*)
1111 /* At least Windows XP emits some undefined RNDIS messages.
1112 * In one case those messages seemed to relate to the host
1113 * suspending itself.
1115 pr_warning("%s: unknown RNDIS message 0x%08X len %d\n",
1116 __func__
, MsgType
, MsgLength
);
1119 for (i
= 0; i
< MsgLength
; i
+= 16) {
1121 " %02x %02x %02x %02x"
1122 " %02x %02x %02x %02x"
1123 " %02x %02x %02x %02x"
1124 " %02x %02x %02x %02x"
1129 buf
[i
+4], buf
[i
+5],
1131 buf
[i
+8], buf
[i
+9],
1132 buf
[i
+10], buf
[i
+11],
1133 buf
[i
+12], buf
[i
+13],
1134 buf
[i
+14], buf
[i
+15]);
1143 int rndis_register (int (* rndis_control_ack
) (struct net_device
*))
1147 for (i
= 0; i
< RNDIS_MAX_CONFIGS
; i
++) {
1148 if (!rndis_per_dev_params
[i
].used
) {
1149 rndis_per_dev_params
[i
].used
= 1;
1150 rndis_per_dev_params
[i
].ack
= rndis_control_ack
;
1151 DBG("%s: configNr = %d\n", __func__
, i
);
1160 void rndis_deregister (int configNr
)
1162 DBG("%s: \n", __func__
);
1164 if (configNr
>= RNDIS_MAX_CONFIGS
) return;
1165 rndis_per_dev_params
[configNr
].used
= 0;
1170 int rndis_set_param_dev (u8 configNr
, struct net_device
*dev
,
1171 struct net_device_stats
*stats
,
1174 DBG("%s:\n", __func__
);
1175 if (!dev
|| !stats
) return -1;
1176 if (configNr
>= RNDIS_MAX_CONFIGS
) return -1;
1178 rndis_per_dev_params
[configNr
].dev
= dev
;
1179 rndis_per_dev_params
[configNr
].stats
= stats
;
1180 rndis_per_dev_params
[configNr
].filter
= cdc_filter
;
1185 int rndis_set_param_vendor (u8 configNr
, u32 vendorID
, const char *vendorDescr
)
1187 DBG("%s:\n", __func__
);
1188 if (!vendorDescr
) return -1;
1189 if (configNr
>= RNDIS_MAX_CONFIGS
) return -1;
1191 rndis_per_dev_params
[configNr
].vendorID
= vendorID
;
1192 rndis_per_dev_params
[configNr
].vendorDescr
= vendorDescr
;
1197 int rndis_set_param_medium (u8 configNr
, u32 medium
, u32 speed
)
1199 DBG("%s: %u %u\n", __func__
, medium
, speed
);
1200 if (configNr
>= RNDIS_MAX_CONFIGS
) return -1;
1202 rndis_per_dev_params
[configNr
].medium
= medium
;
1203 rndis_per_dev_params
[configNr
].speed
= speed
;
1208 void rndis_add_hdr (struct sk_buff
*skb
)
1210 struct rndis_packet_msg_type
*header
;
1214 header
= (void *) skb_push (skb
, sizeof *header
);
1215 memset (header
, 0, sizeof *header
);
1216 header
->MessageType
= __constant_cpu_to_le32(REMOTE_NDIS_PACKET_MSG
);
1217 header
->MessageLength
= cpu_to_le32(skb
->len
);
1218 header
->DataOffset
= __constant_cpu_to_le32 (36);
1219 header
->DataLength
= cpu_to_le32(skb
->len
- sizeof *header
);
1222 void rndis_free_response (int configNr
, u8
*buf
)
1225 struct list_head
*act
, *tmp
;
1227 list_for_each_safe (act
, tmp
,
1228 &(rndis_per_dev_params
[configNr
].resp_queue
))
1230 r
= list_entry (act
, rndis_resp_t
, list
);
1231 if (r
&& r
->buf
== buf
) {
1232 list_del (&r
->list
);
1238 u8
*rndis_get_next_response (int configNr
, u32
*length
)
1241 struct list_head
*act
, *tmp
;
1243 if (!length
) return NULL
;
1245 list_for_each_safe (act
, tmp
,
1246 &(rndis_per_dev_params
[configNr
].resp_queue
))
1248 r
= list_entry (act
, rndis_resp_t
, list
);
1251 *length
= r
->length
;
1259 static rndis_resp_t
*rndis_add_response (int configNr
, u32 length
)
1263 /* NOTE: this gets copied into ether.c USB_BUFSIZ bytes ... */
1264 r
= kmalloc (sizeof (rndis_resp_t
) + length
, GFP_ATOMIC
);
1265 if (!r
) return NULL
;
1267 r
->buf
= (u8
*) (r
+ 1);
1271 list_add_tail (&r
->list
,
1272 &(rndis_per_dev_params
[configNr
].resp_queue
));
1276 int rndis_rm_hdr(struct sk_buff
*skb
)
1278 /* tmp points to a struct rndis_packet_msg_type */
1279 __le32
*tmp
= (void *) skb
->data
;
1281 /* MessageType, MessageLength */
1282 if (__constant_cpu_to_le32(REMOTE_NDIS_PACKET_MSG
)
1283 != get_unaligned(tmp
++))
1287 /* DataOffset, DataLength */
1288 if (!skb_pull(skb
, get_unaligned_le32(tmp
++) + 8))
1290 skb_trim(skb
, get_unaligned_le32(tmp
++));
1295 #ifdef CONFIG_USB_GADGET_DEBUG_FILES
1297 static int rndis_proc_read (char *page
, char **start
, off_t off
, int count
, int *eof
,
1302 rndis_params
*param
= (rndis_params
*) data
;
1304 out
+= snprintf (out
, count
,
1311 "vendor ID : 0x%08X\n"
1313 param
->confignr
, (param
->used
) ? "y" : "n",
1315 switch (param
->state
) {
1316 case RNDIS_UNINITIALIZED
:
1317 s
= "RNDIS_UNINITIALIZED"; break;
1318 case RNDIS_INITIALIZED
:
1319 s
= "RNDIS_INITIALIZED"; break;
1320 case RNDIS_DATA_INITIALIZED
:
1321 s
= "RNDIS_DATA_INITIALIZED"; break;
1324 (param
->media_state
) ? 0 : param
->speed
*100,
1325 (param
->media_state
) ? "disconnected" : "connected",
1326 param
->vendorID
, param
->vendorDescr
);
1338 *start
= page
+ off
;
1342 static int rndis_proc_write (struct file
*file
, const char __user
*buffer
,
1343 unsigned long count
, void *data
)
1345 rndis_params
*p
= data
;
1347 int i
, fl_speed
= 0;
1349 for (i
= 0; i
< count
; i
++) {
1351 if (get_user(c
, buffer
))
1365 speed
= speed
*10 + c
- '0';
1369 rndis_signal_connect (p
->confignr
);
1373 rndis_signal_disconnect(p
->confignr
);
1376 if (fl_speed
) p
->speed
= speed
;
1377 else DBG("%c is not valid\n", c
);
1387 #define NAME_TEMPLATE "driver/rndis-%03d"
1389 static struct proc_dir_entry
*rndis_connect_state
[RNDIS_MAX_CONFIGS
];
1391 #endif /* CONFIG_USB_GADGET_DEBUG_FILES */
1394 int __init
rndis_init (void)
1398 for (i
= 0; i
< RNDIS_MAX_CONFIGS
; i
++) {
1399 #ifdef CONFIG_USB_GADGET_DEBUG_FILES
1402 sprintf (name
, NAME_TEMPLATE
, i
);
1403 if (!(rndis_connect_state
[i
]
1404 = create_proc_entry (name
, 0660, NULL
)))
1406 DBG("%s :remove entries", __func__
);
1408 sprintf (name
, NAME_TEMPLATE
, --i
);
1409 remove_proc_entry (name
, NULL
);
1415 rndis_connect_state
[i
]->write_proc
= rndis_proc_write
;
1416 rndis_connect_state
[i
]->read_proc
= rndis_proc_read
;
1417 rndis_connect_state
[i
]->data
= (void *)
1418 (rndis_per_dev_params
+ i
);
1420 rndis_per_dev_params
[i
].confignr
= i
;
1421 rndis_per_dev_params
[i
].used
= 0;
1422 rndis_per_dev_params
[i
].state
= RNDIS_UNINITIALIZED
;
1423 rndis_per_dev_params
[i
].media_state
1424 = NDIS_MEDIA_STATE_DISCONNECTED
;
1425 INIT_LIST_HEAD (&(rndis_per_dev_params
[i
].resp_queue
));
1431 void rndis_exit (void)
1433 #ifdef CONFIG_USB_GADGET_DEBUG_FILES
1437 for (i
= 0; i
< RNDIS_MAX_CONFIGS
; i
++) {
1438 sprintf (name
, NAME_TEMPLATE
, i
);
1439 remove_proc_entry (name
, NULL
);