iwlwifi: introduce host commands callbacks
[linux/fpc-iii.git] / drivers / usb / gadget / rndis.c
blob3d036647431fdbd8f409a30cf327d74acceb82c5
1 /*
2 * RNDIS MSG parser
4 * Version: $Id: rndis.c,v 1.19 2004/03/25 21:33:46 robert Exp $
6 * Authors: Benedikt Spranger, Pengutronix
7 * Robert Schwebel, Pengutronix
9 * This program is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU General Public License
11 * version 2, as published by the Free Software Foundation.
13 * This software was originally developed in conformance with
14 * Microsoft's Remote NDIS Specification License Agreement.
16 * 03/12/2004 Kai-Uwe Bloem <linux-development@auerswald.de>
17 * Fixed message length bug in init_response
19 * 03/25/2004 Kai-Uwe Bloem <linux-development@auerswald.de>
20 * Fixed rndis_rm_hdr length bug.
22 * Copyright (C) 2004 by David Brownell
23 * updates to merge with Linux 2.6, better match RNDIS spec
26 #include <linux/module.h>
27 #include <linux/moduleparam.h>
28 #include <linux/kernel.h>
29 #include <linux/errno.h>
30 #include <linux/init.h>
31 #include <linux/list.h>
32 #include <linux/proc_fs.h>
33 #include <linux/netdevice.h>
35 #include <asm/io.h>
36 #include <asm/byteorder.h>
37 #include <asm/system.h>
38 #include <asm/unaligned.h>
41 #undef RNDIS_PM
42 #undef RNDIS_WAKEUP
43 #undef VERBOSE
45 #include "rndis.h"
48 /* The driver for your USB chip needs to support ep0 OUT to work with
49 * RNDIS, plus all three CDC Ethernet endpoints (interrupt not optional).
51 * Windows hosts need an INF file like Documentation/usb/linux.inf
52 * and will be happier if you provide the host_addr module parameter.
55 #if 0
56 static int rndis_debug = 0;
57 module_param (rndis_debug, int, 0);
58 MODULE_PARM_DESC (rndis_debug, "enable debugging");
59 #else
60 #define rndis_debug 0
61 #endif
63 #define DBG(str,args...) do { \
64 if (rndis_debug) \
65 pr_debug(str , ## args); \
66 } while (0)
68 #define RNDIS_MAX_CONFIGS 1
71 static rndis_params rndis_per_dev_params [RNDIS_MAX_CONFIGS];
73 /* Driver Version */
74 static const __le32 rndis_driver_version = __constant_cpu_to_le32 (1);
76 /* Function Prototypes */
77 static rndis_resp_t *rndis_add_response (int configNr, u32 length);
80 /* supported OIDs */
81 static const u32 oid_supported_list [] =
83 /* the general stuff */
84 OID_GEN_SUPPORTED_LIST,
85 OID_GEN_HARDWARE_STATUS,
86 OID_GEN_MEDIA_SUPPORTED,
87 OID_GEN_MEDIA_IN_USE,
88 OID_GEN_MAXIMUM_FRAME_SIZE,
89 OID_GEN_LINK_SPEED,
90 OID_GEN_TRANSMIT_BLOCK_SIZE,
91 OID_GEN_RECEIVE_BLOCK_SIZE,
92 OID_GEN_VENDOR_ID,
93 OID_GEN_VENDOR_DESCRIPTION,
94 OID_GEN_VENDOR_DRIVER_VERSION,
95 OID_GEN_CURRENT_PACKET_FILTER,
96 OID_GEN_MAXIMUM_TOTAL_SIZE,
97 OID_GEN_MEDIA_CONNECT_STATUS,
98 OID_GEN_PHYSICAL_MEDIUM,
99 #if 0
100 OID_GEN_RNDIS_CONFIG_PARAMETER,
101 #endif
103 /* the statistical stuff */
104 OID_GEN_XMIT_OK,
105 OID_GEN_RCV_OK,
106 OID_GEN_XMIT_ERROR,
107 OID_GEN_RCV_ERROR,
108 OID_GEN_RCV_NO_BUFFER,
109 #ifdef RNDIS_OPTIONAL_STATS
110 OID_GEN_DIRECTED_BYTES_XMIT,
111 OID_GEN_DIRECTED_FRAMES_XMIT,
112 OID_GEN_MULTICAST_BYTES_XMIT,
113 OID_GEN_MULTICAST_FRAMES_XMIT,
114 OID_GEN_BROADCAST_BYTES_XMIT,
115 OID_GEN_BROADCAST_FRAMES_XMIT,
116 OID_GEN_DIRECTED_BYTES_RCV,
117 OID_GEN_DIRECTED_FRAMES_RCV,
118 OID_GEN_MULTICAST_BYTES_RCV,
119 OID_GEN_MULTICAST_FRAMES_RCV,
120 OID_GEN_BROADCAST_BYTES_RCV,
121 OID_GEN_BROADCAST_FRAMES_RCV,
122 OID_GEN_RCV_CRC_ERROR,
123 OID_GEN_TRANSMIT_QUEUE_LENGTH,
124 #endif /* RNDIS_OPTIONAL_STATS */
126 /* mandatory 802.3 */
127 /* the general stuff */
128 OID_802_3_PERMANENT_ADDRESS,
129 OID_802_3_CURRENT_ADDRESS,
130 OID_802_3_MULTICAST_LIST,
131 OID_802_3_MAC_OPTIONS,
132 OID_802_3_MAXIMUM_LIST_SIZE,
134 /* the statistical stuff */
135 OID_802_3_RCV_ERROR_ALIGNMENT,
136 OID_802_3_XMIT_ONE_COLLISION,
137 OID_802_3_XMIT_MORE_COLLISIONS,
138 #ifdef RNDIS_OPTIONAL_STATS
139 OID_802_3_XMIT_DEFERRED,
140 OID_802_3_XMIT_MAX_COLLISIONS,
141 OID_802_3_RCV_OVERRUN,
142 OID_802_3_XMIT_UNDERRUN,
143 OID_802_3_XMIT_HEARTBEAT_FAILURE,
144 OID_802_3_XMIT_TIMES_CRS_LOST,
145 OID_802_3_XMIT_LATE_COLLISIONS,
146 #endif /* RNDIS_OPTIONAL_STATS */
148 #ifdef RNDIS_PM
149 /* PM and wakeup are mandatory for USB: */
151 /* power management */
152 OID_PNP_CAPABILITIES,
153 OID_PNP_QUERY_POWER,
154 OID_PNP_SET_POWER,
156 #ifdef RNDIS_WAKEUP
157 /* wake up host */
158 OID_PNP_ENABLE_WAKE_UP,
159 OID_PNP_ADD_WAKE_UP_PATTERN,
160 OID_PNP_REMOVE_WAKE_UP_PATTERN,
161 #endif /* RNDIS_WAKEUP */
162 #endif /* RNDIS_PM */
166 /* NDIS Functions */
167 static int
168 gen_ndis_query_resp (int configNr, u32 OID, u8 *buf, unsigned buf_len,
169 rndis_resp_t *r)
171 int retval = -ENOTSUPP;
172 u32 length = 4; /* usually */
173 __le32 *outbuf;
174 int i, count;
175 rndis_query_cmplt_type *resp;
177 if (!r) return -ENOMEM;
178 resp = (rndis_query_cmplt_type *) r->buf;
180 if (!resp) return -ENOMEM;
182 if (buf_len && rndis_debug > 1) {
183 DBG("query OID %08x value, len %d:\n", OID, buf_len);
184 for (i = 0; i < buf_len; i += 16) {
185 DBG("%03d: %08x %08x %08x %08x\n", i,
186 le32_to_cpu(get_unaligned((__le32 *)
187 &buf[i])),
188 le32_to_cpu(get_unaligned((__le32 *)
189 &buf[i + 4])),
190 le32_to_cpu(get_unaligned((__le32 *)
191 &buf[i + 8])),
192 le32_to_cpu(get_unaligned((__le32 *)
193 &buf[i + 12])));
197 /* response goes here, right after the header */
198 outbuf = (__le32 *) &resp[1];
199 resp->InformationBufferOffset = __constant_cpu_to_le32 (16);
201 switch (OID) {
203 /* general oids (table 4-1) */
205 /* mandatory */
206 case OID_GEN_SUPPORTED_LIST:
207 DBG("%s: OID_GEN_SUPPORTED_LIST\n", __FUNCTION__);
208 length = sizeof (oid_supported_list);
209 count = length / sizeof (u32);
210 for (i = 0; i < count; i++)
211 outbuf[i] = cpu_to_le32 (oid_supported_list[i]);
212 retval = 0;
213 break;
215 /* mandatory */
216 case OID_GEN_HARDWARE_STATUS:
217 DBG("%s: OID_GEN_HARDWARE_STATUS\n", __FUNCTION__);
218 /* Bogus question!
219 * Hardware must be ready to receive high level protocols.
220 * BTW:
221 * reddite ergo quae sunt Caesaris Caesari
222 * et quae sunt Dei Deo!
224 *outbuf = __constant_cpu_to_le32 (0);
225 retval = 0;
226 break;
228 /* mandatory */
229 case OID_GEN_MEDIA_SUPPORTED:
230 DBG("%s: OID_GEN_MEDIA_SUPPORTED\n", __FUNCTION__);
231 *outbuf = cpu_to_le32 (rndis_per_dev_params [configNr].medium);
232 retval = 0;
233 break;
235 /* mandatory */
236 case OID_GEN_MEDIA_IN_USE:
237 DBG("%s: OID_GEN_MEDIA_IN_USE\n", __FUNCTION__);
238 /* one medium, one transport... (maybe you do it better) */
239 *outbuf = cpu_to_le32 (rndis_per_dev_params [configNr].medium);
240 retval = 0;
241 break;
243 /* mandatory */
244 case OID_GEN_MAXIMUM_FRAME_SIZE:
245 DBG("%s: OID_GEN_MAXIMUM_FRAME_SIZE\n", __FUNCTION__);
246 if (rndis_per_dev_params [configNr].dev) {
247 *outbuf = cpu_to_le32 (
248 rndis_per_dev_params [configNr].dev->mtu);
249 retval = 0;
251 break;
253 /* mandatory */
254 case OID_GEN_LINK_SPEED:
255 if (rndis_debug > 1)
256 DBG("%s: OID_GEN_LINK_SPEED\n", __FUNCTION__);
257 if (rndis_per_dev_params [configNr].media_state
258 == NDIS_MEDIA_STATE_DISCONNECTED)
259 *outbuf = __constant_cpu_to_le32 (0);
260 else
261 *outbuf = cpu_to_le32 (
262 rndis_per_dev_params [configNr].speed);
263 retval = 0;
264 break;
266 /* mandatory */
267 case OID_GEN_TRANSMIT_BLOCK_SIZE:
268 DBG("%s: OID_GEN_TRANSMIT_BLOCK_SIZE\n", __FUNCTION__);
269 if (rndis_per_dev_params [configNr].dev) {
270 *outbuf = cpu_to_le32 (
271 rndis_per_dev_params [configNr].dev->mtu);
272 retval = 0;
274 break;
276 /* mandatory */
277 case OID_GEN_RECEIVE_BLOCK_SIZE:
278 DBG("%s: OID_GEN_RECEIVE_BLOCK_SIZE\n", __FUNCTION__);
279 if (rndis_per_dev_params [configNr].dev) {
280 *outbuf = cpu_to_le32 (
281 rndis_per_dev_params [configNr].dev->mtu);
282 retval = 0;
284 break;
286 /* mandatory */
287 case OID_GEN_VENDOR_ID:
288 DBG("%s: OID_GEN_VENDOR_ID\n", __FUNCTION__);
289 *outbuf = cpu_to_le32 (
290 rndis_per_dev_params [configNr].vendorID);
291 retval = 0;
292 break;
294 /* mandatory */
295 case OID_GEN_VENDOR_DESCRIPTION:
296 DBG("%s: OID_GEN_VENDOR_DESCRIPTION\n", __FUNCTION__);
297 length = strlen (rndis_per_dev_params [configNr].vendorDescr);
298 memcpy (outbuf,
299 rndis_per_dev_params [configNr].vendorDescr, length);
300 retval = 0;
301 break;
303 case OID_GEN_VENDOR_DRIVER_VERSION:
304 DBG("%s: OID_GEN_VENDOR_DRIVER_VERSION\n", __FUNCTION__);
305 /* Created as LE */
306 *outbuf = rndis_driver_version;
307 retval = 0;
308 break;
310 /* mandatory */
311 case OID_GEN_CURRENT_PACKET_FILTER:
312 DBG("%s: OID_GEN_CURRENT_PACKET_FILTER\n", __FUNCTION__);
313 *outbuf = cpu_to_le32 (*rndis_per_dev_params[configNr].filter);
314 retval = 0;
315 break;
317 /* mandatory */
318 case OID_GEN_MAXIMUM_TOTAL_SIZE:
319 DBG("%s: OID_GEN_MAXIMUM_TOTAL_SIZE\n", __FUNCTION__);
320 *outbuf = __constant_cpu_to_le32(RNDIS_MAX_TOTAL_SIZE);
321 retval = 0;
322 break;
324 /* mandatory */
325 case OID_GEN_MEDIA_CONNECT_STATUS:
326 if (rndis_debug > 1)
327 DBG("%s: OID_GEN_MEDIA_CONNECT_STATUS\n", __FUNCTION__);
328 *outbuf = cpu_to_le32 (rndis_per_dev_params [configNr]
329 .media_state);
330 retval = 0;
331 break;
333 case OID_GEN_PHYSICAL_MEDIUM:
334 DBG("%s: OID_GEN_PHYSICAL_MEDIUM\n", __FUNCTION__);
335 *outbuf = __constant_cpu_to_le32 (0);
336 retval = 0;
337 break;
339 /* The RNDIS specification is incomplete/wrong. Some versions
340 * of MS-Windows expect OIDs that aren't specified there. Other
341 * versions emit undefined RNDIS messages. DOCUMENT ALL THESE!
343 case OID_GEN_MAC_OPTIONS: /* from WinME */
344 DBG("%s: OID_GEN_MAC_OPTIONS\n", __FUNCTION__);
345 *outbuf = __constant_cpu_to_le32(
346 NDIS_MAC_OPTION_RECEIVE_SERIALIZED
347 | NDIS_MAC_OPTION_FULL_DUPLEX);
348 retval = 0;
349 break;
351 /* statistics OIDs (table 4-2) */
353 /* mandatory */
354 case OID_GEN_XMIT_OK:
355 if (rndis_debug > 1)
356 DBG("%s: OID_GEN_XMIT_OK\n", __FUNCTION__);
357 if (rndis_per_dev_params [configNr].stats) {
358 *outbuf = cpu_to_le32 (
359 rndis_per_dev_params [configNr].stats->tx_packets -
360 rndis_per_dev_params [configNr].stats->tx_errors -
361 rndis_per_dev_params [configNr].stats->tx_dropped);
362 retval = 0;
364 break;
366 /* mandatory */
367 case OID_GEN_RCV_OK:
368 if (rndis_debug > 1)
369 DBG("%s: OID_GEN_RCV_OK\n", __FUNCTION__);
370 if (rndis_per_dev_params [configNr].stats) {
371 *outbuf = cpu_to_le32 (
372 rndis_per_dev_params [configNr].stats->rx_packets -
373 rndis_per_dev_params [configNr].stats->rx_errors -
374 rndis_per_dev_params [configNr].stats->rx_dropped);
375 retval = 0;
377 break;
379 /* mandatory */
380 case OID_GEN_XMIT_ERROR:
381 if (rndis_debug > 1)
382 DBG("%s: OID_GEN_XMIT_ERROR\n", __FUNCTION__);
383 if (rndis_per_dev_params [configNr].stats) {
384 *outbuf = cpu_to_le32 (rndis_per_dev_params [configNr]
385 .stats->tx_errors);
386 retval = 0;
388 break;
390 /* mandatory */
391 case OID_GEN_RCV_ERROR:
392 if (rndis_debug > 1)
393 DBG("%s: OID_GEN_RCV_ERROR\n", __FUNCTION__);
394 if (rndis_per_dev_params [configNr].stats) {
395 *outbuf = cpu_to_le32 (rndis_per_dev_params [configNr]
396 .stats->rx_errors);
397 retval = 0;
399 break;
401 /* mandatory */
402 case OID_GEN_RCV_NO_BUFFER:
403 DBG("%s: OID_GEN_RCV_NO_BUFFER\n", __FUNCTION__);
404 if (rndis_per_dev_params [configNr].stats) {
405 *outbuf = cpu_to_le32 (rndis_per_dev_params [configNr]
406 .stats->rx_dropped);
407 retval = 0;
409 break;
411 #ifdef RNDIS_OPTIONAL_STATS
412 case OID_GEN_DIRECTED_BYTES_XMIT:
413 DBG("%s: OID_GEN_DIRECTED_BYTES_XMIT\n", __FUNCTION__);
415 * Aunt Tilly's size of shoes
416 * minus antarctica count of penguins
417 * divided by weight of Alpha Centauri
419 if (rndis_per_dev_params [configNr].stats) {
420 *outbuf = cpu_to_le32 (
421 (rndis_per_dev_params [configNr]
422 .stats->tx_packets -
423 rndis_per_dev_params [configNr]
424 .stats->tx_errors -
425 rndis_per_dev_params [configNr]
426 .stats->tx_dropped)
427 * 123);
428 retval = 0;
430 break;
432 case OID_GEN_DIRECTED_FRAMES_XMIT:
433 DBG("%s: OID_GEN_DIRECTED_FRAMES_XMIT\n", __FUNCTION__);
434 /* dito */
435 if (rndis_per_dev_params [configNr].stats) {
436 *outbuf = cpu_to_le32 (
437 (rndis_per_dev_params [configNr]
438 .stats->tx_packets -
439 rndis_per_dev_params [configNr]
440 .stats->tx_errors -
441 rndis_per_dev_params [configNr]
442 .stats->tx_dropped)
443 / 123);
444 retval = 0;
446 break;
448 case OID_GEN_MULTICAST_BYTES_XMIT:
449 DBG("%s: OID_GEN_MULTICAST_BYTES_XMIT\n", __FUNCTION__);
450 if (rndis_per_dev_params [configNr].stats) {
451 *outbuf = cpu_to_le32 (rndis_per_dev_params [configNr]
452 .stats->multicast*1234);
453 retval = 0;
455 break;
457 case OID_GEN_MULTICAST_FRAMES_XMIT:
458 DBG("%s: OID_GEN_MULTICAST_FRAMES_XMIT\n", __FUNCTION__);
459 if (rndis_per_dev_params [configNr].stats) {
460 *outbuf = cpu_to_le32 (rndis_per_dev_params [configNr]
461 .stats->multicast);
462 retval = 0;
464 break;
466 case OID_GEN_BROADCAST_BYTES_XMIT:
467 DBG("%s: OID_GEN_BROADCAST_BYTES_XMIT\n", __FUNCTION__);
468 if (rndis_per_dev_params [configNr].stats) {
469 *outbuf = cpu_to_le32 (rndis_per_dev_params [configNr]
470 .stats->tx_packets/42*255);
471 retval = 0;
473 break;
475 case OID_GEN_BROADCAST_FRAMES_XMIT:
476 DBG("%s: OID_GEN_BROADCAST_FRAMES_XMIT\n", __FUNCTION__);
477 if (rndis_per_dev_params [configNr].stats) {
478 *outbuf = cpu_to_le32 (rndis_per_dev_params [configNr]
479 .stats->tx_packets/42);
480 retval = 0;
482 break;
484 case OID_GEN_DIRECTED_BYTES_RCV:
485 DBG("%s: OID_GEN_DIRECTED_BYTES_RCV\n", __FUNCTION__);
486 *outbuf = __constant_cpu_to_le32 (0);
487 retval = 0;
488 break;
490 case OID_GEN_DIRECTED_FRAMES_RCV:
491 DBG("%s: OID_GEN_DIRECTED_FRAMES_RCV\n", __FUNCTION__);
492 *outbuf = __constant_cpu_to_le32 (0);
493 retval = 0;
494 break;
496 case OID_GEN_MULTICAST_BYTES_RCV:
497 DBG("%s: OID_GEN_MULTICAST_BYTES_RCV\n", __FUNCTION__);
498 if (rndis_per_dev_params [configNr].stats) {
499 *outbuf = cpu_to_le32 (rndis_per_dev_params [configNr]
500 .stats->multicast * 1111);
501 retval = 0;
503 break;
505 case OID_GEN_MULTICAST_FRAMES_RCV:
506 DBG("%s: OID_GEN_MULTICAST_FRAMES_RCV\n", __FUNCTION__);
507 if (rndis_per_dev_params [configNr].stats) {
508 *outbuf = cpu_to_le32 (rndis_per_dev_params [configNr]
509 .stats->multicast);
510 retval = 0;
512 break;
514 case OID_GEN_BROADCAST_BYTES_RCV:
515 DBG("%s: OID_GEN_BROADCAST_BYTES_RCV\n", __FUNCTION__);
516 if (rndis_per_dev_params [configNr].stats) {
517 *outbuf = cpu_to_le32 (rndis_per_dev_params [configNr]
518 .stats->rx_packets/42*255);
519 retval = 0;
521 break;
523 case OID_GEN_BROADCAST_FRAMES_RCV:
524 DBG("%s: OID_GEN_BROADCAST_FRAMES_RCV\n", __FUNCTION__);
525 if (rndis_per_dev_params [configNr].stats) {
526 *outbuf = cpu_to_le32 (rndis_per_dev_params [configNr]
527 .stats->rx_packets/42);
528 retval = 0;
530 break;
532 case OID_GEN_RCV_CRC_ERROR:
533 DBG("%s: OID_GEN_RCV_CRC_ERROR\n", __FUNCTION__);
534 if (rndis_per_dev_params [configNr].stats) {
535 *outbuf = cpu_to_le32 (rndis_per_dev_params [configNr]
536 .stats->rx_crc_errors);
537 retval = 0;
539 break;
541 case OID_GEN_TRANSMIT_QUEUE_LENGTH:
542 DBG("%s: OID_GEN_TRANSMIT_QUEUE_LENGTH\n", __FUNCTION__);
543 *outbuf = __constant_cpu_to_le32 (0);
544 retval = 0;
545 break;
546 #endif /* RNDIS_OPTIONAL_STATS */
548 /* ieee802.3 OIDs (table 4-3) */
550 /* mandatory */
551 case OID_802_3_PERMANENT_ADDRESS:
552 DBG("%s: OID_802_3_PERMANENT_ADDRESS\n", __FUNCTION__);
553 if (rndis_per_dev_params [configNr].dev) {
554 length = ETH_ALEN;
555 memcpy (outbuf,
556 rndis_per_dev_params [configNr].host_mac,
557 length);
558 retval = 0;
560 break;
562 /* mandatory */
563 case OID_802_3_CURRENT_ADDRESS:
564 DBG("%s: OID_802_3_CURRENT_ADDRESS\n", __FUNCTION__);
565 if (rndis_per_dev_params [configNr].dev) {
566 length = ETH_ALEN;
567 memcpy (outbuf,
568 rndis_per_dev_params [configNr].host_mac,
569 length);
570 retval = 0;
572 break;
574 /* mandatory */
575 case OID_802_3_MULTICAST_LIST:
576 DBG("%s: OID_802_3_MULTICAST_LIST\n", __FUNCTION__);
577 /* Multicast base address only */
578 *outbuf = __constant_cpu_to_le32 (0xE0000000);
579 retval = 0;
580 break;
582 /* mandatory */
583 case OID_802_3_MAXIMUM_LIST_SIZE:
584 DBG("%s: OID_802_3_MAXIMUM_LIST_SIZE\n", __FUNCTION__);
585 /* Multicast base address only */
586 *outbuf = __constant_cpu_to_le32 (1);
587 retval = 0;
588 break;
590 case OID_802_3_MAC_OPTIONS:
591 DBG("%s: OID_802_3_MAC_OPTIONS\n", __FUNCTION__);
592 break;
594 /* ieee802.3 statistics OIDs (table 4-4) */
596 /* mandatory */
597 case OID_802_3_RCV_ERROR_ALIGNMENT:
598 DBG("%s: OID_802_3_RCV_ERROR_ALIGNMENT\n", __FUNCTION__);
599 if (rndis_per_dev_params [configNr].stats) {
600 *outbuf = cpu_to_le32 (rndis_per_dev_params [configNr]
601 .stats->rx_frame_errors);
602 retval = 0;
604 break;
606 /* mandatory */
607 case OID_802_3_XMIT_ONE_COLLISION:
608 DBG("%s: OID_802_3_XMIT_ONE_COLLISION\n", __FUNCTION__);
609 *outbuf = __constant_cpu_to_le32 (0);
610 retval = 0;
611 break;
613 /* mandatory */
614 case OID_802_3_XMIT_MORE_COLLISIONS:
615 DBG("%s: OID_802_3_XMIT_MORE_COLLISIONS\n", __FUNCTION__);
616 *outbuf = __constant_cpu_to_le32 (0);
617 retval = 0;
618 break;
620 #ifdef RNDIS_OPTIONAL_STATS
621 case OID_802_3_XMIT_DEFERRED:
622 DBG("%s: OID_802_3_XMIT_DEFERRED\n", __FUNCTION__);
623 /* TODO */
624 break;
626 case OID_802_3_XMIT_MAX_COLLISIONS:
627 DBG("%s: OID_802_3_XMIT_MAX_COLLISIONS\n", __FUNCTION__);
628 /* TODO */
629 break;
631 case OID_802_3_RCV_OVERRUN:
632 DBG("%s: OID_802_3_RCV_OVERRUN\n", __FUNCTION__);
633 /* TODO */
634 break;
636 case OID_802_3_XMIT_UNDERRUN:
637 DBG("%s: OID_802_3_XMIT_UNDERRUN\n", __FUNCTION__);
638 /* TODO */
639 break;
641 case OID_802_3_XMIT_HEARTBEAT_FAILURE:
642 DBG("%s: OID_802_3_XMIT_HEARTBEAT_FAILURE\n", __FUNCTION__);
643 /* TODO */
644 break;
646 case OID_802_3_XMIT_TIMES_CRS_LOST:
647 DBG("%s: OID_802_3_XMIT_TIMES_CRS_LOST\n", __FUNCTION__);
648 /* TODO */
649 break;
651 case OID_802_3_XMIT_LATE_COLLISIONS:
652 DBG("%s: OID_802_3_XMIT_LATE_COLLISIONS\n", __FUNCTION__);
653 /* TODO */
654 break;
655 #endif /* RNDIS_OPTIONAL_STATS */
657 #ifdef RNDIS_PM
658 /* power management OIDs (table 4-5) */
659 case OID_PNP_CAPABILITIES:
660 DBG("%s: OID_PNP_CAPABILITIES\n", __FUNCTION__);
662 /* for now, no wakeup capabilities */
663 length = sizeof (struct NDIS_PNP_CAPABILITIES);
664 memset(outbuf, 0, length);
665 retval = 0;
666 break;
667 case OID_PNP_QUERY_POWER:
668 DBG("%s: OID_PNP_QUERY_POWER D%d\n", __FUNCTION__,
669 le32_to_cpu(get_unaligned((__le32 *)buf)) - 1);
670 /* only suspend is a real power state, and
671 * it can't be entered by OID_PNP_SET_POWER...
673 length = 0;
674 retval = 0;
675 break;
676 #endif
678 default:
679 pr_warning("%s: query unknown OID 0x%08X\n",
680 __FUNCTION__, OID);
682 if (retval < 0)
683 length = 0;
685 resp->InformationBufferLength = cpu_to_le32 (length);
686 r->length = length + sizeof *resp;
687 resp->MessageLength = cpu_to_le32 (r->length);
688 return retval;
691 static int gen_ndis_set_resp (u8 configNr, u32 OID, u8 *buf, u32 buf_len,
692 rndis_resp_t *r)
694 rndis_set_cmplt_type *resp;
695 int i, retval = -ENOTSUPP;
696 struct rndis_params *params;
698 if (!r)
699 return -ENOMEM;
700 resp = (rndis_set_cmplt_type *) r->buf;
701 if (!resp)
702 return -ENOMEM;
704 if (buf_len && rndis_debug > 1) {
705 DBG("set OID %08x value, len %d:\n", OID, buf_len);
706 for (i = 0; i < buf_len; i += 16) {
707 DBG("%03d: %08x %08x %08x %08x\n", i,
708 le32_to_cpu(get_unaligned((__le32 *)
709 &buf[i])),
710 le32_to_cpu(get_unaligned((__le32 *)
711 &buf[i + 4])),
712 le32_to_cpu(get_unaligned((__le32 *)
713 &buf[i + 8])),
714 le32_to_cpu(get_unaligned((__le32 *)
715 &buf[i + 12])));
719 params = &rndis_per_dev_params [configNr];
720 switch (OID) {
721 case OID_GEN_CURRENT_PACKET_FILTER:
723 /* these NDIS_PACKET_TYPE_* bitflags are shared with
724 * cdc_filter; it's not RNDIS-specific
725 * NDIS_PACKET_TYPE_x == USB_CDC_PACKET_TYPE_x for x in:
726 * PROMISCUOUS, DIRECTED,
727 * MULTICAST, ALL_MULTICAST, BROADCAST
729 *params->filter = (u16) le32_to_cpu(get_unaligned(
730 (__le32 *)buf));
731 DBG("%s: OID_GEN_CURRENT_PACKET_FILTER %08x\n",
732 __FUNCTION__, *params->filter);
734 /* this call has a significant side effect: it's
735 * what makes the packet flow start and stop, like
736 * activating the CDC Ethernet altsetting.
738 #ifdef RNDIS_PM
739 update_linkstate:
740 #endif
741 retval = 0;
742 if (*params->filter) {
743 params->state = RNDIS_DATA_INITIALIZED;
744 netif_carrier_on(params->dev);
745 if (netif_running(params->dev))
746 netif_wake_queue (params->dev);
747 } else {
748 params->state = RNDIS_INITIALIZED;
749 netif_carrier_off (params->dev);
750 netif_stop_queue (params->dev);
752 break;
754 case OID_802_3_MULTICAST_LIST:
755 /* I think we can ignore this */
756 DBG("%s: OID_802_3_MULTICAST_LIST\n", __FUNCTION__);
757 retval = 0;
758 break;
759 #if 0
760 case OID_GEN_RNDIS_CONFIG_PARAMETER:
762 struct rndis_config_parameter *param;
763 param = (struct rndis_config_parameter *) buf;
764 DBG("%s: OID_GEN_RNDIS_CONFIG_PARAMETER '%*s'\n",
765 __FUNCTION__,
766 min(cpu_to_le32(param->ParameterNameLength),80),
767 buf + param->ParameterNameOffset);
768 retval = 0;
770 break;
771 #endif
773 #ifdef RNDIS_PM
774 case OID_PNP_SET_POWER:
775 /* The only real power state is USB suspend, and RNDIS requests
776 * can't enter it; this one isn't really about power. After
777 * resuming, Windows forces a reset, and then SET_POWER D0.
778 * FIXME ... then things go batty; Windows wedges itself.
780 i = le32_to_cpu(get_unaligned((__le32 *)buf));
781 DBG("%s: OID_PNP_SET_POWER D%d\n", __FUNCTION__, i - 1);
782 switch (i) {
783 case NdisDeviceStateD0:
784 *params->filter = params->saved_filter;
785 goto update_linkstate;
786 case NdisDeviceStateD3:
787 case NdisDeviceStateD2:
788 case NdisDeviceStateD1:
789 params->saved_filter = *params->filter;
790 retval = 0;
791 break;
793 break;
795 #ifdef RNDIS_WAKEUP
796 // no wakeup support advertised, so wakeup OIDs always fail:
797 // - OID_PNP_ENABLE_WAKE_UP
798 // - OID_PNP_{ADD,REMOVE}_WAKE_UP_PATTERN
799 #endif
801 #endif /* RNDIS_PM */
803 default:
804 pr_warning("%s: set unknown OID 0x%08X, size %d\n",
805 __FUNCTION__, OID, buf_len);
808 return retval;
812 * Response Functions
815 static int rndis_init_response (int configNr, rndis_init_msg_type *buf)
817 rndis_init_cmplt_type *resp;
818 rndis_resp_t *r;
820 if (!rndis_per_dev_params [configNr].dev) return -ENOTSUPP;
822 r = rndis_add_response (configNr, sizeof (rndis_init_cmplt_type));
823 if (!r)
824 return -ENOMEM;
825 resp = (rndis_init_cmplt_type *) r->buf;
827 resp->MessageType = __constant_cpu_to_le32 (
828 REMOTE_NDIS_INITIALIZE_CMPLT);
829 resp->MessageLength = __constant_cpu_to_le32 (52);
830 resp->RequestID = buf->RequestID; /* Still LE in msg buffer */
831 resp->Status = __constant_cpu_to_le32 (RNDIS_STATUS_SUCCESS);
832 resp->MajorVersion = __constant_cpu_to_le32 (RNDIS_MAJOR_VERSION);
833 resp->MinorVersion = __constant_cpu_to_le32 (RNDIS_MINOR_VERSION);
834 resp->DeviceFlags = __constant_cpu_to_le32 (RNDIS_DF_CONNECTIONLESS);
835 resp->Medium = __constant_cpu_to_le32 (RNDIS_MEDIUM_802_3);
836 resp->MaxPacketsPerTransfer = __constant_cpu_to_le32 (1);
837 resp->MaxTransferSize = cpu_to_le32 (
838 rndis_per_dev_params [configNr].dev->mtu
839 + sizeof (struct ethhdr)
840 + sizeof (struct rndis_packet_msg_type)
841 + 22);
842 resp->PacketAlignmentFactor = __constant_cpu_to_le32 (0);
843 resp->AFListOffset = __constant_cpu_to_le32 (0);
844 resp->AFListSize = __constant_cpu_to_le32 (0);
846 if (rndis_per_dev_params [configNr].ack)
847 rndis_per_dev_params [configNr].ack (
848 rndis_per_dev_params [configNr].dev);
850 return 0;
853 static int rndis_query_response (int configNr, rndis_query_msg_type *buf)
855 rndis_query_cmplt_type *resp;
856 rndis_resp_t *r;
858 // DBG("%s: OID = %08X\n", __FUNCTION__, cpu_to_le32(buf->OID));
859 if (!rndis_per_dev_params [configNr].dev) return -ENOTSUPP;
862 * we need more memory:
863 * gen_ndis_query_resp expects enough space for
864 * rndis_query_cmplt_type followed by data.
865 * oid_supported_list is the largest data reply
867 r = rndis_add_response (configNr,
868 sizeof (oid_supported_list) + sizeof(rndis_query_cmplt_type));
869 if (!r)
870 return -ENOMEM;
871 resp = (rndis_query_cmplt_type *) r->buf;
873 resp->MessageType = __constant_cpu_to_le32 (REMOTE_NDIS_QUERY_CMPLT);
874 resp->RequestID = buf->RequestID; /* Still LE in msg buffer */
876 if (gen_ndis_query_resp (configNr, le32_to_cpu (buf->OID),
877 le32_to_cpu(buf->InformationBufferOffset)
878 + 8 + (u8 *) buf,
879 le32_to_cpu(buf->InformationBufferLength),
880 r)) {
881 /* OID not supported */
882 resp->Status = __constant_cpu_to_le32 (
883 RNDIS_STATUS_NOT_SUPPORTED);
884 resp->MessageLength = __constant_cpu_to_le32 (sizeof *resp);
885 resp->InformationBufferLength = __constant_cpu_to_le32 (0);
886 resp->InformationBufferOffset = __constant_cpu_to_le32 (0);
887 } else
888 resp->Status = __constant_cpu_to_le32 (RNDIS_STATUS_SUCCESS);
890 if (rndis_per_dev_params [configNr].ack)
891 rndis_per_dev_params [configNr].ack (
892 rndis_per_dev_params [configNr].dev);
893 return 0;
896 static int rndis_set_response (int configNr, rndis_set_msg_type *buf)
898 u32 BufLength, BufOffset;
899 rndis_set_cmplt_type *resp;
900 rndis_resp_t *r;
902 r = rndis_add_response (configNr, sizeof (rndis_set_cmplt_type));
903 if (!r)
904 return -ENOMEM;
905 resp = (rndis_set_cmplt_type *) r->buf;
907 BufLength = le32_to_cpu (buf->InformationBufferLength);
908 BufOffset = le32_to_cpu (buf->InformationBufferOffset);
910 #ifdef VERBOSE
911 DBG("%s: Length: %d\n", __FUNCTION__, BufLength);
912 DBG("%s: Offset: %d\n", __FUNCTION__, BufOffset);
913 DBG("%s: InfoBuffer: ", __FUNCTION__);
915 for (i = 0; i < BufLength; i++) {
916 DBG("%02x ", *(((u8 *) buf) + i + 8 + BufOffset));
919 DBG("\n");
920 #endif
922 resp->MessageType = __constant_cpu_to_le32 (REMOTE_NDIS_SET_CMPLT);
923 resp->MessageLength = __constant_cpu_to_le32 (16);
924 resp->RequestID = buf->RequestID; /* Still LE in msg buffer */
925 if (gen_ndis_set_resp (configNr, le32_to_cpu (buf->OID),
926 ((u8 *) buf) + 8 + BufOffset, BufLength, r))
927 resp->Status = __constant_cpu_to_le32 (RNDIS_STATUS_NOT_SUPPORTED);
928 else
929 resp->Status = __constant_cpu_to_le32 (RNDIS_STATUS_SUCCESS);
931 if (rndis_per_dev_params [configNr].ack)
932 rndis_per_dev_params [configNr].ack (
933 rndis_per_dev_params [configNr].dev);
935 return 0;
938 static int rndis_reset_response (int configNr, rndis_reset_msg_type *buf)
940 rndis_reset_cmplt_type *resp;
941 rndis_resp_t *r;
943 r = rndis_add_response (configNr, sizeof (rndis_reset_cmplt_type));
944 if (!r)
945 return -ENOMEM;
946 resp = (rndis_reset_cmplt_type *) r->buf;
948 resp->MessageType = __constant_cpu_to_le32 (REMOTE_NDIS_RESET_CMPLT);
949 resp->MessageLength = __constant_cpu_to_le32 (16);
950 resp->Status = __constant_cpu_to_le32 (RNDIS_STATUS_SUCCESS);
951 /* resent information */
952 resp->AddressingReset = __constant_cpu_to_le32 (1);
954 if (rndis_per_dev_params [configNr].ack)
955 rndis_per_dev_params [configNr].ack (
956 rndis_per_dev_params [configNr].dev);
958 return 0;
961 static int rndis_keepalive_response (int configNr,
962 rndis_keepalive_msg_type *buf)
964 rndis_keepalive_cmplt_type *resp;
965 rndis_resp_t *r;
967 /* host "should" check only in RNDIS_DATA_INITIALIZED state */
969 r = rndis_add_response (configNr, sizeof (rndis_keepalive_cmplt_type));
970 if (!r)
971 return -ENOMEM;
972 resp = (rndis_keepalive_cmplt_type *) r->buf;
974 resp->MessageType = __constant_cpu_to_le32 (
975 REMOTE_NDIS_KEEPALIVE_CMPLT);
976 resp->MessageLength = __constant_cpu_to_le32 (16);
977 resp->RequestID = buf->RequestID; /* Still LE in msg buffer */
978 resp->Status = __constant_cpu_to_le32 (RNDIS_STATUS_SUCCESS);
980 if (rndis_per_dev_params [configNr].ack)
981 rndis_per_dev_params [configNr].ack (
982 rndis_per_dev_params [configNr].dev);
984 return 0;
989 * Device to Host Comunication
991 static int rndis_indicate_status_msg (int configNr, u32 status)
993 rndis_indicate_status_msg_type *resp;
994 rndis_resp_t *r;
996 if (rndis_per_dev_params [configNr].state == RNDIS_UNINITIALIZED)
997 return -ENOTSUPP;
999 r = rndis_add_response (configNr,
1000 sizeof (rndis_indicate_status_msg_type));
1001 if (!r)
1002 return -ENOMEM;
1003 resp = (rndis_indicate_status_msg_type *) r->buf;
1005 resp->MessageType = __constant_cpu_to_le32 (
1006 REMOTE_NDIS_INDICATE_STATUS_MSG);
1007 resp->MessageLength = __constant_cpu_to_le32 (20);
1008 resp->Status = cpu_to_le32 (status);
1009 resp->StatusBufferLength = __constant_cpu_to_le32 (0);
1010 resp->StatusBufferOffset = __constant_cpu_to_le32 (0);
1012 if (rndis_per_dev_params [configNr].ack)
1013 rndis_per_dev_params [configNr].ack (
1014 rndis_per_dev_params [configNr].dev);
1015 return 0;
1018 int rndis_signal_connect (int configNr)
1020 rndis_per_dev_params [configNr].media_state
1021 = NDIS_MEDIA_STATE_CONNECTED;
1022 return rndis_indicate_status_msg (configNr,
1023 RNDIS_STATUS_MEDIA_CONNECT);
1026 int rndis_signal_disconnect (int configNr)
1028 rndis_per_dev_params [configNr].media_state
1029 = NDIS_MEDIA_STATE_DISCONNECTED;
1030 return rndis_indicate_status_msg (configNr,
1031 RNDIS_STATUS_MEDIA_DISCONNECT);
1034 void rndis_uninit (int configNr)
1036 u8 *buf;
1037 u32 length;
1039 if (configNr >= RNDIS_MAX_CONFIGS)
1040 return;
1041 rndis_per_dev_params [configNr].used = 0;
1042 rndis_per_dev_params [configNr].state = RNDIS_UNINITIALIZED;
1044 /* drain the response queue */
1045 while ((buf = rndis_get_next_response(configNr, &length)))
1046 rndis_free_response(configNr, buf);
1049 void rndis_set_host_mac (int configNr, const u8 *addr)
1051 rndis_per_dev_params [configNr].host_mac = addr;
1055 * Message Parser
1057 int rndis_msg_parser (u8 configNr, u8 *buf)
1059 u32 MsgType, MsgLength;
1060 __le32 *tmp;
1061 struct rndis_params *params;
1063 if (!buf)
1064 return -ENOMEM;
1066 tmp = (__le32 *) buf;
1067 MsgType = le32_to_cpu(get_unaligned(tmp++));
1068 MsgLength = le32_to_cpu(get_unaligned(tmp++));
1070 if (configNr >= RNDIS_MAX_CONFIGS)
1071 return -ENOTSUPP;
1072 params = &rndis_per_dev_params [configNr];
1074 /* NOTE: RNDIS is *EXTREMELY* chatty ... Windows constantly polls for
1075 * rx/tx statistics and link status, in addition to KEEPALIVE traffic
1076 * and normal HC level polling to see if there's any IN traffic.
1079 /* For USB: responses may take up to 10 seconds */
1080 switch (MsgType) {
1081 case REMOTE_NDIS_INITIALIZE_MSG:
1082 DBG("%s: REMOTE_NDIS_INITIALIZE_MSG\n",
1083 __FUNCTION__ );
1084 params->state = RNDIS_INITIALIZED;
1085 return rndis_init_response (configNr,
1086 (rndis_init_msg_type *) buf);
1088 case REMOTE_NDIS_HALT_MSG:
1089 DBG("%s: REMOTE_NDIS_HALT_MSG\n",
1090 __FUNCTION__ );
1091 params->state = RNDIS_UNINITIALIZED;
1092 if (params->dev) {
1093 netif_carrier_off (params->dev);
1094 netif_stop_queue (params->dev);
1096 return 0;
1098 case REMOTE_NDIS_QUERY_MSG:
1099 return rndis_query_response (configNr,
1100 (rndis_query_msg_type *) buf);
1102 case REMOTE_NDIS_SET_MSG:
1103 return rndis_set_response (configNr,
1104 (rndis_set_msg_type *) buf);
1106 case REMOTE_NDIS_RESET_MSG:
1107 DBG("%s: REMOTE_NDIS_RESET_MSG\n",
1108 __FUNCTION__ );
1109 return rndis_reset_response (configNr,
1110 (rndis_reset_msg_type *) buf);
1112 case REMOTE_NDIS_KEEPALIVE_MSG:
1113 /* For USB: host does this every 5 seconds */
1114 if (rndis_debug > 1)
1115 DBG("%s: REMOTE_NDIS_KEEPALIVE_MSG\n",
1116 __FUNCTION__ );
1117 return rndis_keepalive_response (configNr,
1118 (rndis_keepalive_msg_type *)
1119 buf);
1121 default:
1122 /* At least Windows XP emits some undefined RNDIS messages.
1123 * In one case those messages seemed to relate to the host
1124 * suspending itself.
1126 pr_warning("%s: unknown RNDIS message 0x%08X len %d\n",
1127 __FUNCTION__ , MsgType, MsgLength);
1129 unsigned i;
1130 for (i = 0; i < MsgLength; i += 16) {
1131 DBG("%03d: "
1132 " %02x %02x %02x %02x"
1133 " %02x %02x %02x %02x"
1134 " %02x %02x %02x %02x"
1135 " %02x %02x %02x %02x"
1136 "\n",
1138 buf[i], buf [i+1],
1139 buf[i+2], buf[i+3],
1140 buf[i+4], buf [i+5],
1141 buf[i+6], buf[i+7],
1142 buf[i+8], buf [i+9],
1143 buf[i+10], buf[i+11],
1144 buf[i+12], buf [i+13],
1145 buf[i+14], buf[i+15]);
1148 break;
1151 return -ENOTSUPP;
1154 int rndis_register (int (* rndis_control_ack) (struct net_device *))
1156 u8 i;
1158 for (i = 0; i < RNDIS_MAX_CONFIGS; i++) {
1159 if (!rndis_per_dev_params [i].used) {
1160 rndis_per_dev_params [i].used = 1;
1161 rndis_per_dev_params [i].ack = rndis_control_ack;
1162 DBG("%s: configNr = %d\n", __FUNCTION__, i);
1163 return i;
1166 DBG("failed\n");
1168 return -1;
1171 void rndis_deregister (int configNr)
1173 DBG("%s: \n", __FUNCTION__ );
1175 if (configNr >= RNDIS_MAX_CONFIGS) return;
1176 rndis_per_dev_params [configNr].used = 0;
1178 return;
1181 int rndis_set_param_dev (u8 configNr, struct net_device *dev,
1182 struct net_device_stats *stats,
1183 u16 *cdc_filter)
1185 DBG("%s:\n", __FUNCTION__ );
1186 if (!dev || !stats) return -1;
1187 if (configNr >= RNDIS_MAX_CONFIGS) return -1;
1189 rndis_per_dev_params [configNr].dev = dev;
1190 rndis_per_dev_params [configNr].stats = stats;
1191 rndis_per_dev_params [configNr].filter = cdc_filter;
1193 return 0;
1196 int rndis_set_param_vendor (u8 configNr, u32 vendorID, const char *vendorDescr)
1198 DBG("%s:\n", __FUNCTION__ );
1199 if (!vendorDescr) return -1;
1200 if (configNr >= RNDIS_MAX_CONFIGS) return -1;
1202 rndis_per_dev_params [configNr].vendorID = vendorID;
1203 rndis_per_dev_params [configNr].vendorDescr = vendorDescr;
1205 return 0;
1208 int rndis_set_param_medium (u8 configNr, u32 medium, u32 speed)
1210 DBG("%s: %u %u\n", __FUNCTION__, medium, speed);
1211 if (configNr >= RNDIS_MAX_CONFIGS) return -1;
1213 rndis_per_dev_params [configNr].medium = medium;
1214 rndis_per_dev_params [configNr].speed = speed;
1216 return 0;
1219 void rndis_add_hdr (struct sk_buff *skb)
1221 struct rndis_packet_msg_type *header;
1223 if (!skb)
1224 return;
1225 header = (void *) skb_push (skb, sizeof *header);
1226 memset (header, 0, sizeof *header);
1227 header->MessageType = __constant_cpu_to_le32(REMOTE_NDIS_PACKET_MSG);
1228 header->MessageLength = cpu_to_le32(skb->len);
1229 header->DataOffset = __constant_cpu_to_le32 (36);
1230 header->DataLength = cpu_to_le32(skb->len - sizeof *header);
1233 void rndis_free_response (int configNr, u8 *buf)
1235 rndis_resp_t *r;
1236 struct list_head *act, *tmp;
1238 list_for_each_safe (act, tmp,
1239 &(rndis_per_dev_params [configNr].resp_queue))
1241 r = list_entry (act, rndis_resp_t, list);
1242 if (r && r->buf == buf) {
1243 list_del (&r->list);
1244 kfree (r);
1249 u8 *rndis_get_next_response (int configNr, u32 *length)
1251 rndis_resp_t *r;
1252 struct list_head *act, *tmp;
1254 if (!length) return NULL;
1256 list_for_each_safe (act, tmp,
1257 &(rndis_per_dev_params [configNr].resp_queue))
1259 r = list_entry (act, rndis_resp_t, list);
1260 if (!r->send) {
1261 r->send = 1;
1262 *length = r->length;
1263 return r->buf;
1267 return NULL;
1270 static rndis_resp_t *rndis_add_response (int configNr, u32 length)
1272 rndis_resp_t *r;
1274 /* NOTE: this gets copied into ether.c USB_BUFSIZ bytes ... */
1275 r = kmalloc (sizeof (rndis_resp_t) + length, GFP_ATOMIC);
1276 if (!r) return NULL;
1278 r->buf = (u8 *) (r + 1);
1279 r->length = length;
1280 r->send = 0;
1282 list_add_tail (&r->list,
1283 &(rndis_per_dev_params [configNr].resp_queue));
1284 return r;
1287 int rndis_rm_hdr(struct sk_buff *skb)
1289 /* tmp points to a struct rndis_packet_msg_type */
1290 __le32 *tmp = (void *) skb->data;
1292 /* MessageType, MessageLength */
1293 if (__constant_cpu_to_le32(REMOTE_NDIS_PACKET_MSG)
1294 != get_unaligned(tmp++))
1295 return -EINVAL;
1296 tmp++;
1298 /* DataOffset, DataLength */
1299 if (!skb_pull(skb, le32_to_cpu(get_unaligned(tmp++))
1300 + 8 /* offset of DataOffset */))
1301 return -EOVERFLOW;
1302 skb_trim(skb, le32_to_cpu(get_unaligned(tmp++)));
1304 return 0;
1307 #ifdef CONFIG_USB_GADGET_DEBUG_FILES
1309 static int rndis_proc_read (char *page, char **start, off_t off, int count, int *eof,
1310 void *data)
1312 char *out = page;
1313 int len;
1314 rndis_params *param = (rndis_params *) data;
1316 out += snprintf (out, count,
1317 "Config Nr. %d\n"
1318 "used : %s\n"
1319 "state : %s\n"
1320 "medium : 0x%08X\n"
1321 "speed : %d\n"
1322 "cable : %s\n"
1323 "vendor ID : 0x%08X\n"
1324 "vendor : %s\n",
1325 param->confignr, (param->used) ? "y" : "n",
1326 ({ char *s = "?";
1327 switch (param->state) {
1328 case RNDIS_UNINITIALIZED:
1329 s = "RNDIS_UNINITIALIZED"; break;
1330 case RNDIS_INITIALIZED:
1331 s = "RNDIS_INITIALIZED"; break;
1332 case RNDIS_DATA_INITIALIZED:
1333 s = "RNDIS_DATA_INITIALIZED"; break;
1334 }; s; }),
1335 param->medium,
1336 (param->media_state) ? 0 : param->speed*100,
1337 (param->media_state) ? "disconnected" : "connected",
1338 param->vendorID, param->vendorDescr);
1340 len = out - page;
1341 len -= off;
1343 if (len < count) {
1344 *eof = 1;
1345 if (len <= 0)
1346 return 0;
1347 } else
1348 len = count;
1350 *start = page + off;
1351 return len;
1354 static int rndis_proc_write (struct file *file, const char __user *buffer,
1355 unsigned long count, void *data)
1357 rndis_params *p = data;
1358 u32 speed = 0;
1359 int i, fl_speed = 0;
1361 for (i = 0; i < count; i++) {
1362 char c;
1363 if (get_user(c, buffer))
1364 return -EFAULT;
1365 switch (c) {
1366 case '0':
1367 case '1':
1368 case '2':
1369 case '3':
1370 case '4':
1371 case '5':
1372 case '6':
1373 case '7':
1374 case '8':
1375 case '9':
1376 fl_speed = 1;
1377 speed = speed*10 + c - '0';
1378 break;
1379 case 'C':
1380 case 'c':
1381 rndis_signal_connect (p->confignr);
1382 break;
1383 case 'D':
1384 case 'd':
1385 rndis_signal_disconnect(p->confignr);
1386 break;
1387 default:
1388 if (fl_speed) p->speed = speed;
1389 else DBG("%c is not valid\n", c);
1390 break;
1393 buffer++;
1396 return count;
1399 #define NAME_TEMPLATE "driver/rndis-%03d"
1401 static struct proc_dir_entry *rndis_connect_state [RNDIS_MAX_CONFIGS];
1403 #endif /* CONFIG_USB_GADGET_DEBUG_FILES */
1406 int __devinit rndis_init (void)
1408 u8 i;
1410 for (i = 0; i < RNDIS_MAX_CONFIGS; i++) {
1411 #ifdef CONFIG_USB_GADGET_DEBUG_FILES
1412 char name [20];
1414 sprintf (name, NAME_TEMPLATE, i);
1415 if (!(rndis_connect_state [i]
1416 = create_proc_entry (name, 0660, NULL)))
1418 DBG("%s :remove entries", __FUNCTION__);
1419 while (i) {
1420 sprintf (name, NAME_TEMPLATE, --i);
1421 remove_proc_entry (name, NULL);
1423 DBG("\n");
1424 return -EIO;
1427 rndis_connect_state [i]->write_proc = rndis_proc_write;
1428 rndis_connect_state [i]->read_proc = rndis_proc_read;
1429 rndis_connect_state [i]->data = (void *)
1430 (rndis_per_dev_params + i);
1431 #endif
1432 rndis_per_dev_params [i].confignr = i;
1433 rndis_per_dev_params [i].used = 0;
1434 rndis_per_dev_params [i].state = RNDIS_UNINITIALIZED;
1435 rndis_per_dev_params [i].media_state
1436 = NDIS_MEDIA_STATE_DISCONNECTED;
1437 INIT_LIST_HEAD (&(rndis_per_dev_params [i].resp_queue));
1440 return 0;
1443 void rndis_exit (void)
1445 #ifdef CONFIG_USB_GADGET_DEBUG_FILES
1446 u8 i;
1447 char name [20];
1449 for (i = 0; i < RNDIS_MAX_CONFIGS; i++) {
1450 sprintf (name, NAME_TEMPLATE, i);
1451 remove_proc_entry (name, NULL);
1453 #endif