blob: e2d2e3b862275f928cdae8be11f35829ba70e12a [file] [log] [blame]
yuezonghe824eb0c2024-06-27 02:32:26 -07001/*
2 * RNDIS MSG parser
3 *
4 * Authors: Benedikt Spranger, Pengutronix
5 * Robert Schwebel, Pengutronix
6 *
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.
10 *
11 * This software was originally developed in conformance with
12 * Microsoft's Remote NDIS Specification License Agreement.
13 *
14 * 03/12/2004 Kai-Uwe Bloem <linux-development@auerswald.de>
15 * Fixed message length bug in init_response
16 *
17 * 03/25/2004 Kai-Uwe Bloem <linux-development@auerswald.de>
18 * Fixed rndis_rm_hdr length bug.
19 *
20 * Copyright (C) 2004 by David Brownell
21 * updates to merge with Linux 2.6, better match RNDIS spec
22 */
23
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/slab.h>
32#include <linux/seq_file.h>
33#include <linux/netdevice.h>
34
35#include <asm/io.h>
36#include <asm/byteorder.h>
37#include <asm/unaligned.h>
38
39
40#undef VERBOSE_DEBUG
41
42#include "rndis.h"
43#include "u_ether.h"
44
45
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).
48 *
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.
51 */
52
53#if 0
54static int rndis_debug = 0;
55module_param (rndis_debug, int, 0);
56MODULE_PARM_DESC (rndis_debug, "enable debugging");
57#else
58#define rndis_debug 0
59#endif
60extern unsigned int get_panic_flag(void);
61
62#define RNDIS_MAX_CONFIGS 1
63extern void usb_notify_up(usb_notify_event notify_type, void* puf);
64
65
66static rndis_params rndis_per_dev_params[RNDIS_MAX_CONFIGS];
67
68/* Driver Version */
69static const __le32 rndis_driver_version = cpu_to_le32(1);
70
71/* Function Prototypes */
72static rndis_resp_t *rndis_add_response(int configNr, u32 length);
73
74
75/* supported OIDs */
76static const u32 oid_supported_list[] =
77{
78 /* the general stuff */
79 OID_GEN_SUPPORTED_LIST,
80 OID_GEN_HARDWARE_STATUS,
81 OID_GEN_MEDIA_SUPPORTED,
82 OID_GEN_MEDIA_IN_USE,
83 OID_GEN_MAXIMUM_FRAME_SIZE,
84 OID_GEN_LINK_SPEED,
85 OID_GEN_TRANSMIT_BLOCK_SIZE,
86 OID_GEN_RECEIVE_BLOCK_SIZE,
87 OID_GEN_VENDOR_ID,
88 OID_GEN_VENDOR_DESCRIPTION,
89 OID_GEN_VENDOR_DRIVER_VERSION,
90 OID_GEN_CURRENT_PACKET_FILTER,
91 OID_GEN_MAXIMUM_TOTAL_SIZE,
92 OID_GEN_MEDIA_CONNECT_STATUS,
93 OID_GEN_PHYSICAL_MEDIUM,
94
95/* RNDIS¿ØÖÆÏûÏ¢¾«¼ò£¬ÓÅ»¯FTPʱÁ÷Á¿²»Îȶ¨ÎÊÌâ */
96#if 0
97 /* the statistical stuff */
98 OID_GEN_XMIT_OK,
99 OID_GEN_RCV_OK,
100 OID_GEN_XMIT_ERROR,
101 OID_GEN_RCV_ERROR,
102 OID_GEN_RCV_NO_BUFFER,
103#endif
104
105
106#ifdef RNDIS_OPTIONAL_STATS
107 OID_GEN_DIRECTED_BYTES_XMIT,
108 OID_GEN_DIRECTED_FRAMES_XMIT,
109 OID_GEN_MULTICAST_BYTES_XMIT,
110 OID_GEN_MULTICAST_FRAMES_XMIT,
111 OID_GEN_BROADCAST_BYTES_XMIT,
112 OID_GEN_BROADCAST_FRAMES_XMIT,
113 OID_GEN_DIRECTED_BYTES_RCV,
114 OID_GEN_DIRECTED_FRAMES_RCV,
115 OID_GEN_MULTICAST_BYTES_RCV,
116 OID_GEN_MULTICAST_FRAMES_RCV,
117 OID_GEN_BROADCAST_BYTES_RCV,
118 OID_GEN_BROADCAST_FRAMES_RCV,
119 OID_GEN_RCV_CRC_ERROR,
120 OID_GEN_TRANSMIT_QUEUE_LENGTH,
121#endif /* RNDIS_OPTIONAL_STATS */
122
123 /* mandatory 802.3 */
124 /* the general stuff */
125 OID_802_3_PERMANENT_ADDRESS,
126 OID_802_3_CURRENT_ADDRESS,
127 OID_802_3_MULTICAST_LIST,
128 OID_802_3_MAC_OPTIONS,
129 OID_802_3_MAXIMUM_LIST_SIZE,
130
131 /* the statistical stuff */
132 OID_802_3_RCV_ERROR_ALIGNMENT,
133 OID_802_3_XMIT_ONE_COLLISION,
134 OID_802_3_XMIT_MORE_COLLISIONS,
135#ifdef RNDIS_OPTIONAL_STATS
136 OID_802_3_XMIT_DEFERRED,
137 OID_802_3_XMIT_MAX_COLLISIONS,
138 OID_802_3_RCV_OVERRUN,
139 OID_802_3_XMIT_UNDERRUN,
140 OID_802_3_XMIT_HEARTBEAT_FAILURE,
141 OID_802_3_XMIT_TIMES_CRS_LOST,
142 OID_802_3_XMIT_LATE_COLLISIONS,
143#endif /* RNDIS_OPTIONAL_STATS */
144
145#ifdef RNDIS_PM
146 /* PM and wakeup are "mandatory" for USB, but the RNDIS specs
147 * don't say what they mean ... and the NDIS specs are often
148 * confusing and/or ambiguous in this context. (That is, more
149 * so than their specs for the other OIDs.)
150 *
151 * FIXME someone who knows what these should do, please
152 * implement them!
153 */
154
155 /* power management */
156 OID_PNP_CAPABILITIES,
157 OID_PNP_QUERY_POWER,
158 OID_PNP_SET_POWER,
159
160#ifdef RNDIS_WAKEUP
161 /* wake up host */
162 OID_PNP_ENABLE_WAKE_UP,
163 OID_PNP_ADD_WAKE_UP_PATTERN,
164 OID_PNP_REMOVE_WAKE_UP_PATTERN,
165#endif /* RNDIS_WAKEUP */
166#endif /* RNDIS_PM */
167};
168
169extern struct eth_dev alloc_dev;
170
171/* NDIS Functions */
172static int gen_ndis_query_resp(int configNr, u32 OID, u8 *buf,
173 unsigned buf_len, rndis_resp_t *r)
174{
175 int retval = -ENOTSUPP;
176 u32 length = 4; /* usually */
177 __le32 *outbuf;
178 int i, count;
179 rndis_query_cmplt_type *resp;
180 struct net_device *net;
181 struct rtnl_link_stats64 temp;
182 const struct rtnl_link_stats64 *stats;
183
184 if (!r) return -ENOMEM;
185 resp = (rndis_query_cmplt_type *)r->buf;
186
187 if (!resp) return -ENOMEM;
188
189 if (buf_len && rndis_debug > 1) {
190 pr_debug("query OID %08x value, len %d:\n", OID, buf_len);
191 for (i = 0; i < buf_len; i += 16) {
192 pr_debug("%03d: %08x %08x %08x %08x\n", i,
193 get_unaligned_le32(&buf[i]),
194 get_unaligned_le32(&buf[i + 4]),
195 get_unaligned_le32(&buf[i + 8]),
196 get_unaligned_le32(&buf[i + 12]));
197 }
198 }
199
200 /* response goes here, right after the header */
201 outbuf = (__le32 *)&resp[1];
202 resp->InformationBufferOffset = cpu_to_le32(16);
203
204 net = rndis_per_dev_params[configNr].dev;
205 stats = dev_get_stats(net, &temp);
206
207 switch (OID) {
208
209 /* general oids (table 4-1) */
210
211 /* mandatory */
212 case OID_GEN_SUPPORTED_LIST:
213 pr_debug("%s: OID_GEN_SUPPORTED_LIST\n", __func__);
214 length = sizeof(oid_supported_list);
215 count = length / sizeof(u32);
216 for (i = 0; i < count; i++)
217 outbuf[i] = cpu_to_le32(oid_supported_list[i]);
218 retval = 0;
219 break;
220
221 /* mandatory */
222 case OID_GEN_HARDWARE_STATUS:
223 pr_debug("%s: OID_GEN_HARDWARE_STATUS\n", __func__);
224 /* Bogus question!
225 * Hardware must be ready to receive high level protocols.
226 * BTW:
227 * reddite ergo quae sunt Caesaris Caesari
228 * et quae sunt Dei Deo!
229 */
230 *outbuf = cpu_to_le32(0);
231 retval = 0;
232 break;
233
234 /* mandatory */
235 case OID_GEN_MEDIA_SUPPORTED:
236 pr_debug("%s: OID_GEN_MEDIA_SUPPORTED\n", __func__);
237 *outbuf = cpu_to_le32(rndis_per_dev_params[configNr].medium);
238 retval = 0;
239 break;
240
241 /* mandatory */
242 case OID_GEN_MEDIA_IN_USE:
243 pr_debug("%s: OID_GEN_MEDIA_IN_USE\n", __func__);
244 /* one medium, one transport... (maybe you do it better) */
245 *outbuf = cpu_to_le32(rndis_per_dev_params[configNr].medium);
246 retval = 0;
247 break;
248
249 /* mandatory */
250 case OID_GEN_MAXIMUM_FRAME_SIZE:
251 pr_debug("%s: OID_GEN_MAXIMUM_FRAME_SIZE\n", __func__);
252 if (rndis_per_dev_params[configNr].dev) {
253 *outbuf = cpu_to_le32(
254 rndis_per_dev_params[configNr].dev->mtu);
255 retval = 0;
256 }
257 break;
258
259 /* mandatory */
260 case OID_GEN_LINK_SPEED:
261 if (rndis_debug > 1)
262 pr_debug("%s: OID_GEN_LINK_SPEED\n", __func__);
263#if 0
264 if (rndis_per_dev_params[configNr].media_state
265 == NDIS_MEDIA_STATE_DISCONNECTED)
266 *outbuf = cpu_to_le32(0);
267 else
268#endif
269 *outbuf = cpu_to_le32(
270 rndis_per_dev_params[configNr].speed);
271 retval = 0;
272 break;
273
274 /* mandatory */
275 case OID_GEN_TRANSMIT_BLOCK_SIZE:
276 pr_debug("%s: OID_GEN_TRANSMIT_BLOCK_SIZE\n", __func__);
277 if (rndis_per_dev_params[configNr].dev) {
278 *outbuf = cpu_to_le32(
279 rndis_per_dev_params[configNr].dev->mtu);
280 retval = 0;
281 }
282 break;
283
284 /* mandatory */
285 case OID_GEN_RECEIVE_BLOCK_SIZE:
286 pr_debug("%s: OID_GEN_RECEIVE_BLOCK_SIZE\n", __func__);
287 if (rndis_per_dev_params[configNr].dev) {
288 *outbuf = cpu_to_le32(
289 rndis_per_dev_params[configNr].dev->mtu);
290 retval = 0;
291 }
292 break;
293
294 /* mandatory */
295 case OID_GEN_VENDOR_ID:
296 pr_debug("%s: OID_GEN_VENDOR_ID\n", __func__);
297 *outbuf = cpu_to_le32(
298 rndis_per_dev_params[configNr].vendorID);
299 retval = 0;
300 break;
301
302 /* mandatory */
303 case OID_GEN_VENDOR_DESCRIPTION:
304 pr_debug("%s: OID_GEN_VENDOR_DESCRIPTION\n", __func__);
305 if (rndis_per_dev_params[configNr].vendorDescr) {
306 length = strlen(rndis_per_dev_params[configNr].
307 vendorDescr);
308 memcpy(outbuf,
309 rndis_per_dev_params[configNr].vendorDescr,
310 length);
311 } else {
312 outbuf[0] = 0;
313 }
314 retval = 0;
315 break;
316
317 case OID_GEN_VENDOR_DRIVER_VERSION:
318 pr_debug("%s: OID_GEN_VENDOR_DRIVER_VERSION\n", __func__);
319 /* Created as LE */
320 *outbuf = rndis_driver_version;
321 retval = 0;
322 break;
323
324 /* mandatory */
325 case OID_GEN_CURRENT_PACKET_FILTER:
326 pr_debug("%s: OID_GEN_CURRENT_PACKET_FILTER\n", __func__);
327 *outbuf = cpu_to_le32(*rndis_per_dev_params[configNr].filter);
328 retval = 0;
329 break;
330
331 /* mandatory */
332 case OID_GEN_MAXIMUM_TOTAL_SIZE:
333 pr_debug("%s: OID_GEN_MAXIMUM_TOTAL_SIZE\n", __func__);
334 *outbuf = cpu_to_le32(RNDIS_MAX_TOTAL_SIZE);
335 retval = 0;
336 break;
337
338 /* mandatory */
339 case OID_GEN_MEDIA_CONNECT_STATUS:
340 if (rndis_debug > 1)
341 pr_debug("%s: OID_GEN_MEDIA_CONNECT_STATUS\n", __func__);
342 *outbuf = cpu_to_le32(rndis_per_dev_params[configNr]
343 .media_state);
344 retval = 0;
345 break;
346
347 case OID_GEN_PHYSICAL_MEDIUM:
348 pr_debug("%s: OID_GEN_PHYSICAL_MEDIUM\n", __func__);
349 *outbuf = cpu_to_le32(0);
350 retval = 0;
351 break;
352
353 /* The RNDIS specification is incomplete/wrong. Some versions
354 * of MS-Windows expect OIDs that aren't specified there. Other
355 * versions emit undefined RNDIS messages. DOCUMENT ALL THESE!
356 */
357 case OID_GEN_MAC_OPTIONS: /* from WinME */
358 pr_debug("%s: OID_GEN_MAC_OPTIONS\n", __func__);
359 *outbuf = cpu_to_le32(
360 NDIS_MAC_OPTION_RECEIVE_SERIALIZED
361 | NDIS_MAC_OPTION_FULL_DUPLEX);
362 retval = 0;
363 break;
364
365 /* statistics OIDs (table 4-2) */
366
367 /* mandatory */
368 case OID_GEN_XMIT_OK:
369 if (rndis_debug > 1)
370 pr_debug("%s: OID_GEN_XMIT_OK\n", __func__);
371 if (stats) {
372 *outbuf = cpu_to_le32(stats->tx_packets
373 - stats->tx_errors - stats->tx_dropped);
374 retval = 0;
375 }
376 break;
377
378 /* mandatory */
379 case OID_GEN_RCV_OK:
380 if (rndis_debug > 1)
381 pr_debug("%s: OID_GEN_RCV_OK\n", __func__);
382 if (stats) {
383 *outbuf = cpu_to_le32(stats->rx_packets
384 - stats->rx_errors - stats->rx_dropped);
385 retval = 0;
386 }
387 break;
388
389 /* mandatory */
390 case OID_GEN_XMIT_ERROR:
391 if (rndis_debug > 1)
392 pr_debug("%s: OID_GEN_XMIT_ERROR\n", __func__);
393 if (stats) {
394 *outbuf = cpu_to_le32(stats->tx_errors);
395 retval = 0;
396 }
397 break;
398
399 /* mandatory */
400 case OID_GEN_RCV_ERROR:
401 if (rndis_debug > 1)
402 pr_debug("%s: OID_GEN_RCV_ERROR\n", __func__);
403 if (stats) {
404 *outbuf = cpu_to_le32(stats->rx_errors);
405 retval = 0;
406 }
407 break;
408
409 /* mandatory */
410 case OID_GEN_RCV_NO_BUFFER:
411 pr_debug("%s: OID_GEN_RCV_NO_BUFFER\n", __func__);
412 if (stats) {
413 *outbuf = cpu_to_le32(stats->rx_dropped);
414 retval = 0;
415 }
416 break;
417
418 /* ieee802.3 OIDs (table 4-3) */
419
420 /* mandatory */
421 case OID_802_3_PERMANENT_ADDRESS:
422 pr_debug("%s: OID_802_3_PERMANENT_ADDRESS\n", __func__);
423 if (rndis_per_dev_params[configNr].dev) {
424 length = ETH_ALEN;
425 memcpy(outbuf,
426 rndis_per_dev_params[configNr].host_mac,
427 length);
428 retval = 0;
429 }
430 break;
431
432 /* mandatory */
433 case OID_802_3_CURRENT_ADDRESS:
434 pr_debug("%s: OID_802_3_CURRENT_ADDRESS\n", __func__);
435 if (rndis_per_dev_params[configNr].dev) {
436 length = ETH_ALEN;
437 memcpy(outbuf,
438 rndis_per_dev_params [configNr].host_mac,
439 length);
440 retval = 0;
441 }
442 break;
443
444 /* mandatory */
445 case OID_802_3_MULTICAST_LIST:
446 pr_debug("%s: OID_802_3_MULTICAST_LIST\n", __func__);
447 /* Multicast base address only */
448 *outbuf = cpu_to_le32(0xE0000000);
449 retval = 0;
450 break;
451
452 /* mandatory */
453 case OID_802_3_MAXIMUM_LIST_SIZE:
454 pr_debug("%s: OID_802_3_MAXIMUM_LIST_SIZE\n", __func__);
455 /* Multicast base address only */
456 *outbuf = cpu_to_le32(1);
457 retval = 0;
458 break;
459
460 case OID_802_3_MAC_OPTIONS:
461 pr_debug("%s: OID_802_3_MAC_OPTIONS\n", __func__);
462 *outbuf = cpu_to_le32(0);
463 retval = 0;
464 break;
465
466 /* ieee802.3 statistics OIDs (table 4-4) */
467
468 /* mandatory */
469 case OID_802_3_RCV_ERROR_ALIGNMENT:
470 pr_debug("%s: OID_802_3_RCV_ERROR_ALIGNMENT\n", __func__);
471 if (stats) {
472 *outbuf = cpu_to_le32(stats->rx_frame_errors);
473 retval = 0;
474 }
475 break;
476
477 /* mandatory */
478 case OID_802_3_XMIT_ONE_COLLISION:
479 pr_debug("%s: OID_802_3_XMIT_ONE_COLLISION\n", __func__);
480 *outbuf = cpu_to_le32(0);
481 retval = 0;
482 break;
483
484 /* mandatory */
485 case OID_802_3_XMIT_MORE_COLLISIONS:
486 pr_debug("%s: OID_802_3_XMIT_MORE_COLLISIONS\n", __func__);
487 *outbuf = cpu_to_le32(0);
488 retval = 0;
489 break;
490
491 default:
492 pr_warning("%s: query unknown OID 0x%08X\n",
493 __func__, OID);
494 }
495 if (retval < 0)
496 length = 0;
497
498 resp->InformationBufferLength = cpu_to_le32(length);
499 r->length = length + sizeof(*resp);
500 resp->MessageLength = cpu_to_le32(r->length);
501 return retval;
502}
503
504static int gen_ndis_set_resp(u8 configNr, u32 OID, u8 *buf, u32 buf_len,
505 rndis_resp_t *r)
506{
507 rndis_set_cmplt_type *resp;
508 int i, retval = -ENOTSUPP;
509 struct rndis_params *params;
510
511 if (!r)
512 return -ENOMEM;
513 resp = (rndis_set_cmplt_type *)r->buf;
514 if (!resp)
515 return -ENOMEM;
516
517 if (buf_len && rndis_debug > 1) {
518 pr_debug("set OID %08x value, len %d:\n", OID, buf_len);
519 for (i = 0; i < buf_len; i += 16) {
520 pr_debug("%03d: %08x %08x %08x %08x\n", i,
521 get_unaligned_le32(&buf[i]),
522 get_unaligned_le32(&buf[i + 4]),
523 get_unaligned_le32(&buf[i + 8]),
524 get_unaligned_le32(&buf[i + 12]));
525 }
526 }
527
528 params = &rndis_per_dev_params[configNr];
529 switch (OID) {
530 case OID_GEN_CURRENT_PACKET_FILTER:
531
532 /* these NDIS_PACKET_TYPE_* bitflags are shared with
533 * cdc_filter; it's not RNDIS-specific
534 * NDIS_PACKET_TYPE_x == USB_CDC_PACKET_TYPE_x for x in:
535 * PROMISCUOUS, DIRECTED,
536 * MULTICAST, ALL_MULTICAST, BROADCAST
537 */
538 *params->filter = (u16)get_unaligned_le32(buf);
539 pr_debug("%s: OID_GEN_CURRENT_PACKET_FILTER %08x\n",
540 __func__, *params->filter);
541
542 /* this call has a significant side effect: it's
543 * what makes the packet flow start and stop, like
544 * activating the CDC Ethernet altsetting.
545 */
546 retval = 0;
547 if (*params->filter) {
548 // if(params->media_state == NDIS_MEDIA_STATE_CONNECTED)
549 {
550 printk("media_state connected\n");
551 // }else{
552 params->state = RNDIS_DATA_INITIALIZED;
553 netif_carrier_on(params->dev);
554 gether_uevent_eth_switch(params->dev, 1);
555 if (netif_running(params->dev))
556 netif_wake_queue(params->dev);
557 }
558 } else {
559 params->state = RNDIS_INITIALIZED;
560 netif_carrier_off(params->dev);
561 gether_uevent_eth_switch(params->dev, 0);
562 netif_stop_queue(params->dev);
563 }
564 break;
565
566 case OID_802_3_MULTICAST_LIST:
567 /* I think we can ignore this */
568 pr_debug("%s: OID_802_3_MULTICAST_LIST\n", __func__);
569 retval = 0;
570 break;
571
572 default:
573 pr_warning("%s: set unknown OID 0x%08X, size %d\n",
574 __func__, OID, buf_len);
575 }
576
577 return retval;
578}
579
580/*
581 * Response Functions
582 */
583
584static int rndis_init_response(int configNr, rndis_init_msg_type *buf)
585{
586 rndis_init_cmplt_type *resp;
587 rndis_resp_t *r;
588 struct rndis_params *params = rndis_per_dev_params + configNr;
589
590 if (!params->dev)
591 return -ENOTSUPP;
592
593 r = rndis_add_response(configNr, sizeof(rndis_init_cmplt_type));
594 if (!r)
595 return -ENOMEM;
596 resp = (rndis_init_cmplt_type *)r->buf;
597
598 resp->MessageType = cpu_to_le32(REMOTE_NDIS_INITIALIZE_CMPLT);
599 resp->MessageLength = cpu_to_le32(52);
600 resp->RequestID = buf->RequestID; /* Still LE in msg buffer */
601 resp->Status = cpu_to_le32(RNDIS_STATUS_SUCCESS);
602 resp->MajorVersion = cpu_to_le32(RNDIS_MAJOR_VERSION);
603 resp->MinorVersion = cpu_to_le32(RNDIS_MINOR_VERSION);
604 resp->DeviceFlags = cpu_to_le32(RNDIS_DF_CONNECTIONLESS);
605 resp->Medium = cpu_to_le32(RNDIS_MEDIUM_802_3);
606
607#if 1
608 resp->MaxPacketsPerTransfer = cpu_to_le32(multi_packet_get_maxnum());//cpu_to_le32(1);
609 resp->MaxTransferSize = 1568*multi_packet_get_maxnum();
610#else
611 resp->MaxPacketsPerTransfer = cpu_to_le32(1);
612 resp->MaxTransferSize = cpu_to_le32(
613 params->dev->mtu
614 + sizeof(struct ethhdr)
615 + sizeof(struct rndis_packet_msg_type)
616 + 22);
617#endif
618 resp->PacketAlignmentFactor = cpu_to_le32(2);
619 resp->AFListOffset = cpu_to_le32(0);
620 resp->AFListSize = cpu_to_le32(0);
621
622 params->resp_avail(params->v);
623 return 0;
624}
625
626static int rndis_query_response(int configNr, rndis_query_msg_type *buf)
627{
628 rndis_query_cmplt_type *resp;
629 rndis_resp_t *r;
630 struct rndis_params *params = rndis_per_dev_params + configNr;
631
632 /* pr_debug("%s: OID = %08X\n", __func__, cpu_to_le32(buf->OID)); */
633 if (!params->dev)
634 return -ENOTSUPP;
635
636 /*
637 * we need more memory:
638 * gen_ndis_query_resp expects enough space for
639 * rndis_query_cmplt_type followed by data.
640 * oid_supported_list is the largest data reply
641 */
642 r = rndis_add_response(configNr,
643 sizeof(oid_supported_list) + sizeof(rndis_query_cmplt_type));
644 if (!r)
645 return -ENOMEM;
646 resp = (rndis_query_cmplt_type *)r->buf;
647
648 resp->MessageType = cpu_to_le32(REMOTE_NDIS_QUERY_CMPLT);
649 resp->RequestID = buf->RequestID; /* Still LE in msg buffer */
650
651 if (gen_ndis_query_resp(configNr, le32_to_cpu(buf->OID),
652 le32_to_cpu(buf->InformationBufferOffset)
653 + 8 + (u8 *)buf,
654 le32_to_cpu(buf->InformationBufferLength),
655 r)) {
656 /* OID not supported */
657 resp->Status = cpu_to_le32(RNDIS_STATUS_NOT_SUPPORTED);
658 resp->MessageLength = cpu_to_le32(sizeof *resp);
659 resp->InformationBufferLength = cpu_to_le32(0);
660 resp->InformationBufferOffset = cpu_to_le32(0);
661 } else
662 resp->Status = cpu_to_le32(RNDIS_STATUS_SUCCESS);
663
664 params->resp_avail(params->v);
665 return 0;
666}
667
668static int rndis_set_response(int configNr, rndis_set_msg_type *buf)
669{
670 u32 BufLength, BufOffset;
671 rndis_set_cmplt_type *resp;
672 rndis_resp_t *r;
673 struct rndis_params *params = rndis_per_dev_params + configNr;
674
675 BufLength = le32_to_cpu(buf->InformationBufferLength);
676 BufOffset = le32_to_cpu(buf->InformationBufferOffset);
677 if ((BufLength > RNDIS_MAX_TOTAL_SIZE) ||
678 (BufOffset + 8 >= RNDIS_MAX_TOTAL_SIZE))
679 return -EINVAL;
680
681 r = rndis_add_response(configNr, sizeof(rndis_set_cmplt_type));
682 if (!r)
683 return -ENOMEM;
684 resp = (rndis_set_cmplt_type *)r->buf;
685
686#ifdef VERBOSE_DEBUG
687 pr_debug("%s: Length: %d\n", __func__, BufLength);
688 pr_debug("%s: Offset: %d\n", __func__, BufOffset);
689 pr_debug("%s: InfoBuffer: ", __func__);
690
691 for (i = 0; i < BufLength; i++) {
692 pr_debug("%02x ", *(((u8 *) buf) + i + 8 + BufOffset));
693 }
694
695 pr_debug("\n");
696#endif
697
698 resp->MessageType = cpu_to_le32(REMOTE_NDIS_SET_CMPLT);
699 resp->MessageLength = cpu_to_le32(16);
700 resp->RequestID = buf->RequestID; /* Still LE in msg buffer */
701 if (gen_ndis_set_resp(configNr, le32_to_cpu(buf->OID),
702 ((u8 *)buf) + 8 + BufOffset, BufLength, r))
703 resp->Status = cpu_to_le32(RNDIS_STATUS_NOT_SUPPORTED);
704 else
705 resp->Status = cpu_to_le32(RNDIS_STATUS_SUCCESS);
706
707 params->resp_avail(params->v);
708 return 0;
709}
710
711static int rndis_reset_response(int configNr, rndis_reset_msg_type *buf)
712{
713 rndis_reset_cmplt_type *resp;
714 rndis_resp_t *r;
715 u8 *xbuf = NULL;
716 u32 length = 0;
717 struct rndis_params *params = &rndis_per_dev_params[configNr];
718 //u32 panic_flag = get_panic_flag();
719 /* drain the response queue */
720 while ((xbuf = rndis_get_next_response(configNr, &length))){
721 //printk("reset_response,free, type:0x%x\n", );
722 rndis_free_response(configNr, xbuf);
723 }
724
725 //if(params->media_state == NDIS_MEDIA_STATE_CONNECTED)
726 {
727 printk("got reset_response,now re plugout/in\n");
728 usb_notify_up(USB_DEVICE_EXCEPT_RESET, NULL);
729 }
730#if 0
731 r = rndis_add_response(configNr, sizeof(rndis_reset_cmplt_type));
732 if (!r)
733 return -ENOMEM;
734
735 resp = (rndis_reset_cmplt_type *)r->buf;
736
737 resp->MessageType = cpu_to_le32(REMOTE_NDIS_RESET_CMPLT);
738 resp->MessageLength = cpu_to_le32(16);
739 resp->Status = cpu_to_le32(RNDIS_STATUS_SUCCESS);
740 /* resent information */
741 resp->AddressingReset = cpu_to_le32(1);
742
743 params->resp_avail(params->v);
744#endif
745 return 0;
746}
747
748static int rndis_keepalive_response(int configNr,
749 rndis_keepalive_msg_type *buf)
750{
751 rndis_keepalive_cmplt_type *resp;
752 rndis_resp_t *r;
753 struct rndis_params *params = rndis_per_dev_params + configNr;
754
755 /* host "should" check only in RNDIS_DATA_INITIALIZED state */
756
757 r = rndis_add_response(configNr, sizeof(rndis_keepalive_cmplt_type));
758 if (!r)
759 return -ENOMEM;
760 resp = (rndis_keepalive_cmplt_type *)r->buf;
761
762 resp->MessageType = cpu_to_le32(
763 REMOTE_NDIS_KEEPALIVE_CMPLT);
764 resp->MessageLength = cpu_to_le32(16);
765 resp->RequestID = buf->RequestID; /* Still LE in msg buffer */
766 resp->Status = cpu_to_le32(RNDIS_STATUS_SUCCESS);
767
768 params->resp_avail(params->v);
769 return 0;
770}
771
772
773/*
774 * Device to Host Comunication
775 */
776static int rndis_indicate_status_msg(int configNr, u32 status)
777{
778 rndis_indicate_status_msg_type *resp;
779 rndis_resp_t *r;
780 struct rndis_params *params = rndis_per_dev_params + configNr;
781
782 if (params->state == RNDIS_UNINITIALIZED)
783 return -ENOTSUPP;
784
785 r = rndis_add_response(configNr,
786 sizeof(rndis_indicate_status_msg_type));
787 if (!r)
788 return -ENOMEM;
789 resp = (rndis_indicate_status_msg_type *)r->buf;
790
791 resp->MessageType = cpu_to_le32(REMOTE_NDIS_INDICATE_STATUS_MSG);
792 resp->MessageLength = cpu_to_le32(20);
793 resp->Status = cpu_to_le32(status);
794 resp->StatusBufferLength = cpu_to_le32(0);
795 resp->StatusBufferOffset = cpu_to_le32(0);
796
797 params->resp_avail(params->v);
798 return 0;
799}
800
801int rndis_signal_connect(int configNr)
802{
803
804 rndis_per_dev_params[configNr].media_state
805 = NDIS_MEDIA_STATE_CONNECTED;
806 return rndis_indicate_status_msg(configNr,
807 RNDIS_STATUS_MEDIA_CONNECT);
808}
809
810int rndis_signal_disconnect(int configNr)
811{
812 rndis_per_dev_params[configNr].media_state
813 = NDIS_MEDIA_STATE_DISCONNECTED;
814 return rndis_indicate_status_msg(configNr,
815 RNDIS_STATUS_MEDIA_DISCONNECT);
816}
817
818void rndis_uninit(int configNr)
819{
820 u8 *buf;
821 u32 length;
822
823 if (configNr >= RNDIS_MAX_CONFIGS)
824 return;
825 rndis_per_dev_params[configNr].state = RNDIS_UNINITIALIZED;
826
827 /* drain the response queue */
828 while ((buf = rndis_get_next_response(configNr, &length)))
829 rndis_free_response(configNr, buf);
830}
831
832void rndis_set_host_mac(int configNr, const u8 *addr)
833{
834 rndis_per_dev_params[configNr].host_mac = addr;
835}
836
837#ifdef CONFIG_ARCH_ZX297520V3_MDL
838
839int chcek_query_oid(u32 oid)
840{
841 switch(oid){
842 case OID_GEN_SUPPORTED_LIST:
843 case OID_GEN_HARDWARE_STATUS:
844 case OID_GEN_MEDIA_SUPPORTED:
845 case OID_GEN_MEDIA_IN_USE:
846 case OID_GEN_MAXIMUM_FRAME_SIZE:
847 case OID_GEN_LINK_SPEED:
848 case OID_GEN_TRANSMIT_BLOCK_SIZE:
849 case OID_GEN_RECEIVE_BLOCK_SIZE:
850 case OID_GEN_VENDOR_ID:
851 case OID_GEN_VENDOR_DESCRIPTION:
852 case OID_GEN_VENDOR_DRIVER_VERSION:
853 case OID_GEN_CURRENT_PACKET_FILTER:
854 case OID_GEN_MAXIMUM_TOTAL_SIZE:
855 case OID_GEN_MEDIA_CONNECT_STATUS:
856 case OID_GEN_PHYSICAL_MEDIUM:
857 case OID_GEN_MAC_OPTIONS:
858 case OID_GEN_XMIT_OK:
859 case OID_GEN_RCV_OK:
860 case OID_GEN_XMIT_ERROR:
861 case OID_GEN_RCV_ERROR:
862 case OID_GEN_RCV_NO_BUFFER:
863 case OID_802_3_PERMANENT_ADDRESS:
864 case OID_802_3_CURRENT_ADDRESS:
865 case OID_802_3_MULTICAST_LIST:
866 case OID_802_3_MAXIMUM_LIST_SIZE:
867 case OID_802_3_MAC_OPTIONS:
868 case OID_802_3_RCV_ERROR_ALIGNMENT:
869 case OID_802_3_XMIT_ONE_COLLISION:
870 case OID_802_3_XMIT_MORE_COLLISIONS:
871 printk("oid match :0x%08x", oid);
872 return 0;
873 default:
874 printk("%s: query unknown OID 0x%08X\n",
875 __func__, oid);
876 }
877
878 return -1;
879}
880/*we suppose that got a msg lost the 4 byte head,
881 *
882 */
883int rndis_msg_patch(u8 *buf, int len)
884{
885 u8* temp_buf = NULL;
886 __le32 *temp;
887 temp_buf = (u8*)kmalloc(len, GFP_KERNEL);
888 if(!temp_buf){
889 printk("rndis_msg_patch malloc fail\n");
890 return -1;
891 }
892 memset(temp_buf, 0 , len);
893 temp = (__le32 *)temp_buf;
894 *temp = cpu_to_le32(REMOTE_NDIS_QUERY_MSG);
895 memcpy(temp_buf+4, buf, len -4);
896 memcpy(buf, temp_buf, len);
897 kfree(temp_buf);
898 temp_buf = NULL;
899 return 0;
900}
901#endif
902/*
903 * Message Parser
904 */
905int rndis_msg_parser(u8 configNr, u8 *buf)
906{
907 u32 MsgType, MsgLength,tmp_oid;
908 __le32 *tmp;
909 struct rndis_params *params;
910 struct gether *link;
911
912 if (!buf)
913 return -ENOMEM;
914
915 tmp = (__le32 *)buf;
916 MsgType = get_unaligned_le32(tmp++);
917 MsgLength = get_unaligned_le32(tmp++);
918
919 if (configNr >= RNDIS_MAX_CONFIGS){
920 USBSTACK_DBG("%s, %u error", __func__, __LINE__);
921 return -ENOTSUPP;
922 }
923 params = &rndis_per_dev_params[configNr];
924
925 /* NOTE: RNDIS is *EXTREMELY* chatty ... Windows constantly polls for
926 * rx/tx statistics and link status, in addition to KEEPALIVE traffic
927 * and normal HC level polling to see if there's any IN traffic.
928 */
929
930 /* For USB: responses may take up to 10 seconds */
931
932
933
934 switch (MsgType) {
935 case REMOTE_NDIS_INITIALIZE_MSG:
936 pr_debug("%s: REMOTE_NDIS_INITIALIZE_MSG\n",
937 __func__);
938 if(params->media_state == NDIS_MEDIA_STATE_CONNECTED && params->state == RNDIS_DATA_INITIALIZED){
939 printk("----gsn--,init msg got again,do nothing\n");
940 } else
941 params->state = RNDIS_INITIALIZED;
942 return rndis_init_response(configNr,
943 (rndis_init_msg_type *)buf);
944
945 case REMOTE_NDIS_HALT_MSG:
946 pr_debug("%s: REMOTE_NDIS_HALT_MSG\n",
947 __func__);
948 params->state = RNDIS_UNINITIALIZED;
949 if (params->dev) {
950 netif_carrier_off(params->dev);
951 gether_uevent_eth_switch(params->dev, 0);
952 netif_stop_queue(params->dev);
953 }
954 return 0;
955
956 case REMOTE_NDIS_QUERY_MSG:
957 return rndis_query_response(configNr,
958 (rndis_query_msg_type *)buf);
959
960 case REMOTE_NDIS_SET_MSG:
961 return rndis_set_response(configNr,
962 (rndis_set_msg_type *)buf);
963
964 case REMOTE_NDIS_RESET_MSG:
965 pr_debug("%s: REMOTE_NDIS_RESET_MSG\n",
966 __func__);
967 return rndis_reset_response(configNr,
968 (rndis_reset_msg_type *)buf);
969
970 case REMOTE_NDIS_KEEPALIVE_MSG:
971 /* For USB: host does this every 5 seconds */
972 if (rndis_debug > 1)
973 pr_debug("%s: REMOTE_NDIS_KEEPALIVE_MSG\n",
974 __func__);
975 return rndis_keepalive_response(configNr,
976 (rndis_keepalive_msg_type *)
977 buf);
978
979 default:
980 /* At least Windows XP emits some undefined RNDIS messages.
981 * In one case those messages seemed to relate to the host
982 * suspending itself.
983 */
984 USBSTACK_DBG("%s: unknown RNDIS message 0x%08X len %d\n",
985 __func__, MsgType, MsgLength);
986 printk("%s: unknown RNDIS message 0x%08X len %d\n",
987 __func__, MsgType, MsgLength);
988 if (MsgLength > 32)
989 MsgLength = 32;
990 {
991 unsigned i;
992 for (i = 0; i < MsgLength; i += 16) {
993 printk("%03d: "
994 " %02x %02x %02x %02x"
995 " %02x %02x %02x %02x"
996 " %02x %02x %02x %02x"
997 " %02x %02x %02x %02x"
998 "\n",
999 i,
1000 buf[i], buf [i+1],
1001 buf[i+2], buf[i+3],
1002 buf[i+4], buf [i+5],
1003 buf[i+6], buf[i+7],
1004 buf[i+8], buf [i+9],
1005 buf[i+10], buf[i+11],
1006 buf[i+12], buf [i+13],
1007 buf[i+14], buf[i+15]);
1008
1009 }
1010 }
1011
1012#ifdef CONFIG_ARCH_ZX297520V3_MDL
1013 //this msg lost 4 byte,we patch it
1014 tmp_oid = get_unaligned_le32(tmp);
1015 if(chcek_query_oid(tmp_oid) == 0){
1016 printk("rndis_msg_parser, need patchlen:0x%x, oid:0x%u\n", MsgType, tmp_oid);
1017 goto rndis_patch;
1018 }
1019#endif
1020 return MsgType;
1021 }
1022
1023#ifdef CONFIG_ARCH_ZX297520V3_MDL
1024rndis_patch:
1025 /*we suppose that this msg lost the 4 byte head, and will patching this msg*/
1026 if(rndis_msg_patch(buf, MsgType) == 0){
1027 return rndis_query_response(configNr,
1028 (rndis_query_msg_type *)buf);
1029 }
1030#endif
1031 return -ENOTSUPP;
1032}
1033
1034int rndis_register(void (*resp_avail)(void *v), void *v)
1035{
1036 u8 i;
1037
1038 if (!resp_avail)
1039 return -EINVAL;
1040
1041 for (i = 0; i < RNDIS_MAX_CONFIGS; i++) {
1042 if (!rndis_per_dev_params[i].used) {
1043 rndis_per_dev_params[i].used = 1;
1044 rndis_per_dev_params[i].resp_avail = resp_avail;
1045 rndis_per_dev_params[i].v = v;
1046 pr_debug("%s: configNr = %d\n", __func__, i);
1047 return i;
1048 }
1049 }
1050 pr_debug("failed\n");
1051
1052 return -ENODEV;
1053}
1054
1055void rndis_deregister(int configNr)
1056{
1057 pr_debug("%s:\n", __func__);
1058
1059 if (configNr >= RNDIS_MAX_CONFIGS) return;
1060 rndis_per_dev_params[configNr].used = 0;
1061}
1062
1063int rndis_set_param_dev(u8 configNr, struct net_device *dev, u16 *cdc_filter)
1064{
1065 pr_debug("%s:\n", __func__);
1066 if (!dev)
1067 return -EINVAL;
1068 if (configNr >= RNDIS_MAX_CONFIGS) return -1;
1069
1070 rndis_per_dev_params[configNr].dev = dev;
1071 rndis_per_dev_params[configNr].filter = cdc_filter;
1072
1073 return 0;
1074}
1075
1076int rndis_set_param_vendor(u8 configNr, u32 vendorID, const char *vendorDescr)
1077{
1078 pr_debug("%s:\n", __func__);
1079 if (!vendorDescr) return -1;
1080 if (configNr >= RNDIS_MAX_CONFIGS) return -1;
1081
1082 rndis_per_dev_params[configNr].vendorID = vendorID;
1083 rndis_per_dev_params[configNr].vendorDescr = vendorDescr;
1084
1085 return 0;
1086}
1087
1088int rndis_set_param_medium(u8 configNr, u32 medium, u32 speed)
1089{
1090 pr_debug("%s: %u %u\n", __func__, medium, speed);
1091 if (configNr >= RNDIS_MAX_CONFIGS) return -1;
1092
1093 rndis_per_dev_params[configNr].medium = medium;
1094 //set speed in rndis_init
1095 //rndis_per_dev_params[configNr].speed = speed;
1096
1097 return 0;
1098}
1099
1100void rndis_add_hdr(struct sk_buff *skb)
1101{
1102 struct rndis_packet_msg_type *header;
1103
1104 if (!skb)
1105 return;
1106 header = (void *)skb_push(skb, sizeof(*header));
1107 memset(header, 0, sizeof *header);
1108 header->MessageType = cpu_to_le32(REMOTE_NDIS_PACKET_MSG);
1109 header->MessageLength = cpu_to_le32(skb->len);
1110 header->DataOffset = cpu_to_le32(36);
1111 header->DataLength = cpu_to_le32(skb->len - sizeof(*header));
1112}
1113
1114void rndis_free_response(int configNr, u8 *buf)
1115{
1116 rndis_resp_t *r;
1117 struct list_head *act, *tmp;
1118
1119 list_for_each_safe(act, tmp,
1120 &(rndis_per_dev_params[configNr].resp_queue))
1121 {
1122 r = list_entry(act, rndis_resp_t, list);
1123 if (r->buf == buf) {
1124 list_del(&r->list);
1125 kfree(r);
1126 }
1127 }
1128}
1129
1130u8 *rndis_get_next_response(int configNr, u32 *length)
1131{
1132 rndis_resp_t *r;
1133 struct list_head *act, *tmp;
1134
1135 if (!length) return NULL;
1136
1137 list_for_each_safe(act, tmp,
1138 &(rndis_per_dev_params[configNr].resp_queue))
1139 {
1140 r = list_entry(act, rndis_resp_t, list);
1141 if (!r->send) {
1142 r->send = 1;
1143 *length = r->length;
1144 return r->buf;
1145 }
1146 }
1147
1148 return NULL;
1149}
1150
1151static rndis_resp_t *rndis_add_response(int configNr, u32 length)
1152{
1153 rndis_resp_t *r;
1154
1155 /* NOTE: this gets copied into ether.c USB_BUFSIZ bytes ... */
1156 r = kmalloc(sizeof(rndis_resp_t) + length, GFP_ATOMIC);
1157 if (!r) return NULL;
1158
1159 r->buf = (u8 *)(r + 1);
1160 r->length = length;
1161 r->send = 0;
1162
1163 list_add_tail(&r->list,
1164 &(rndis_per_dev_params[configNr].resp_queue));
1165 return r;
1166}
1167
1168int rndis_rm_hdr(struct gether *port,
1169 struct sk_buff *skb,
1170 struct sk_buff_head *list)
1171{
1172 /* tmp points to a struct rndis_packet_msg_type */
1173 __le32 *tmp = (void *)skb->data;
1174
1175 /* MessageType, MessageLength */
1176 if (cpu_to_le32(REMOTE_NDIS_PACKET_MSG)
1177 != get_unaligned(tmp++)) {
1178 dev_kfree_skb_any(skb);
1179 return -EINVAL;
1180 }
1181 tmp++;
1182
1183 /* DataOffset, DataLength */
1184 if (!skb_pull(skb, get_unaligned_le32(tmp++) + 8)) {
1185 dev_kfree_skb_any(skb);
1186 return -EOVERFLOW;
1187 }
1188 skb_trim(skb, get_unaligned_le32(tmp++));
1189
1190 skb_queue_tail(list, skb);
1191 return 0;
1192}
1193
1194#ifdef CONFIG_USB_GADGET_DEBUG_FILES
1195
1196static int rndis_proc_show(struct seq_file *m, void *v)
1197{
1198 rndis_params *param = m->private;
1199
1200 seq_printf(m,
1201 "Config Nr. %d\n"
1202 "used : %s\n"
1203 "state : %s\n"
1204 "medium : 0x%08X\n"
1205 "speed : %d\n"
1206 "cable : %s\n"
1207 "vendor ID : 0x%08X\n"
1208 "vendor : %s\n",
1209 param->confignr, (param->used) ? "y" : "n",
1210 ({ char *s = "?";
1211 switch (param->state) {
1212 case RNDIS_UNINITIALIZED:
1213 s = "RNDIS_UNINITIALIZED"; break;
1214 case RNDIS_INITIALIZED:
1215 s = "RNDIS_INITIALIZED"; break;
1216 case RNDIS_DATA_INITIALIZED:
1217 s = "RNDIS_DATA_INITIALIZED"; break;
1218 }; s; }),
1219 param->medium,
1220 (param->media_state) ? 0 : param->speed*100,
1221 (param->media_state) ? "disconnected" : "connected",
1222 param->vendorID, param->vendorDescr);
1223 return 0;
1224}
1225
1226static ssize_t rndis_proc_write(struct file *file, const char __user *buffer,
1227 size_t count, loff_t *ppos)
1228{
1229 rndis_params *p = PDE(file->f_path.dentry->d_inode)->data;
1230 u32 speed = 0;
1231 int i, fl_speed = 0;
1232
1233 for (i = 0; i < count; i++) {
1234 char c;
1235 if (get_user(c, buffer))
1236 return -EFAULT;
1237 switch (c) {
1238 case '0':
1239 case '1':
1240 case '2':
1241 case '3':
1242 case '4':
1243 case '5':
1244 case '6':
1245 case '7':
1246 case '8':
1247 case '9':
1248 fl_speed = 1;
1249 speed = speed * 10 + c - '0';
1250 break;
1251 case 'C':
1252 case 'c':
1253 rndis_signal_connect(p->confignr);
1254 break;
1255 case 'D':
1256 case 'd':
1257 rndis_signal_disconnect(p->confignr);
1258 break;
1259 default:
1260 if (fl_speed) p->speed = speed;
1261 else pr_debug("%c is not valid\n", c);
1262 break;
1263 }
1264
1265 buffer++;
1266 }
1267
1268 return count;
1269}
1270
1271static int rndis_proc_open(struct inode *inode, struct file *file)
1272{
1273 return single_open(file, rndis_proc_show, PDE(inode)->data);
1274}
1275
1276static const struct file_operations rndis_proc_fops = {
1277 .owner = THIS_MODULE,
1278 .open = rndis_proc_open,
1279 .read = seq_read,
1280 .llseek = seq_lseek,
1281 .release = single_release,
1282 .write = rndis_proc_write,
1283};
1284
1285#define NAME_TEMPLATE "driver/rndis-%03d"
1286
1287static struct proc_dir_entry *rndis_connect_state [RNDIS_MAX_CONFIGS];
1288
1289#endif /* CONFIG_USB_GADGET_DEBUG_FILES */
1290
1291static bool rndis_initialized;
1292
1293int rndis_init(void)
1294{
1295 u8 i;
1296
1297 if (rndis_initialized)
1298 return 0;
1299
1300 for (i = 0; i < RNDIS_MAX_CONFIGS; i++) {
1301#ifdef CONFIG_USB_GADGET_DEBUG_FILES
1302 char name [20];
1303
1304 sprintf(name, NAME_TEMPLATE, i);
1305 rndis_connect_state[i] = proc_create_data(name, 0660, NULL,
1306 &rndis_proc_fops,
1307 (void *)(rndis_per_dev_params + i));
1308 if (!rndis_connect_state[i]) {
1309 pr_debug("%s: remove entries", __func__);
1310 while (i) {
1311 sprintf(name, NAME_TEMPLATE, --i);
1312 remove_proc_entry(name, NULL);
1313 }
1314 pr_debug("\n");
1315 return -EIO;
1316 }
1317#endif
1318 rndis_per_dev_params[i].confignr = i;
1319 rndis_per_dev_params[i].used = 0;
1320 rndis_per_dev_params[i].state = RNDIS_UNINITIALIZED;
1321 rndis_per_dev_params[i].media_state
1322 = NDIS_MEDIA_STATE_DISCONNECTED;
1323 //set speed in rndis_init
1324 rndis_per_dev_params[i].speed = (LTE_CAT4_SPEED/100);
1325 INIT_LIST_HEAD(&(rndis_per_dev_params[i].resp_queue));
1326 }
1327
1328 rndis_initialized = true;
1329 return 0;
1330}
1331
1332void rndis_exit(void)
1333{
1334#ifdef CONFIG_USB_GADGET_DEBUG_FILES
1335 u8 i;
1336 char name[20];
1337#endif
1338
1339 if (!rndis_initialized)
1340 return;
1341 rndis_initialized = false;
1342
1343#ifdef CONFIG_USB_GADGET_DEBUG_FILES
1344 for (i = 0; i < RNDIS_MAX_CONFIGS; i++) {
1345 sprintf(name, NAME_TEMPLATE, i);
1346 remove_proc_entry(name, NULL);
1347 }
1348#endif
1349}