1 /*
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/idr.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 #include "u_rndis.h"
40
41 #undef VERBOSE_DEBUG
42
43 #include "rndis.h"
44
45 int rndis_ul_max_pkt_per_xfer_rcvd;
46 module_param(rndis_ul_max_pkt_per_xfer_rcvd, int, S_IRUGO);
47 MODULE_PARM_DESC(rndis_ul_max_pkt_per_xfer_rcvd,
48 "Max num of REMOTE_NDIS_PACKET_MSGs received in a single transfer");
49
50 int rndis_ul_max_xfer_size_rcvd;
51 module_param(rndis_ul_max_xfer_size_rcvd, int, S_IRUGO);
52 MODULE_PARM_DESC(rndis_ul_max_xfer_size_rcvd,
53 "Max size of bus transfer received");
54
55
56 /* The driver for your USB chip needs to support ep0 OUT to work with
57 * RNDIS, plus all three CDC Ethernet endpoints (interrupt not optional).
58 *
59 * Windows hosts need an INF file like Documentation/usb/linux.inf
60 * and will be happier if you provide the host_addr module parameter.
61 */
62
63 #if 0
64 static int rndis_debug = 0;
65 module_param (rndis_debug, int, 0);
66 MODULE_PARM_DESC (rndis_debug, "enable debugging");
67 #else
68 #define rndis_debug 0
69 #endif
70
71 #ifdef CONFIG_USB_GADGET_DEBUG_FILES
72
73 #define NAME_TEMPLATE "driver/rndis-%03d"
74
75 #endif /* CONFIG_USB_GADGET_DEBUG_FILES */
76
77 static DEFINE_IDA(rndis_ida);
78
79 /* Driver Version */
80 static const __le32 rndis_driver_version = cpu_to_le32(1);
81
82 /* Function Prototypes */
83 static rndis_resp_t *rndis_add_response(struct rndis_params *params,
84 u32 length);
85
86 #ifdef CONFIG_USB_GADGET_DEBUG_FILES
87
88 static const struct file_operations rndis_proc_fops;
89
90 #endif /* CONFIG_USB_GADGET_DEBUG_FILES */
91
92 /* supported OIDs */
93 static const u32 oid_supported_list[] =
94 {
95 /* the general stuff */
96 RNDIS_OID_GEN_SUPPORTED_LIST,
97 RNDIS_OID_GEN_HARDWARE_STATUS,
98 RNDIS_OID_GEN_MEDIA_SUPPORTED,
99 RNDIS_OID_GEN_MEDIA_IN_USE,
100 RNDIS_OID_GEN_MAXIMUM_FRAME_SIZE,
101 RNDIS_OID_GEN_LINK_SPEED,
102 RNDIS_OID_GEN_TRANSMIT_BLOCK_SIZE,
103 RNDIS_OID_GEN_RECEIVE_BLOCK_SIZE,
104 RNDIS_OID_GEN_VENDOR_ID,
105 RNDIS_OID_GEN_VENDOR_DESCRIPTION,
106 RNDIS_OID_GEN_VENDOR_DRIVER_VERSION,
107 RNDIS_OID_GEN_CURRENT_PACKET_FILTER,
108 RNDIS_OID_GEN_MAXIMUM_TOTAL_SIZE,
109 RNDIS_OID_GEN_MEDIA_CONNECT_STATUS,
110 RNDIS_OID_GEN_PHYSICAL_MEDIUM,
111
112 /* the statistical stuff */
113 RNDIS_OID_GEN_XMIT_OK,
114 RNDIS_OID_GEN_RCV_OK,
115 RNDIS_OID_GEN_XMIT_ERROR,
116 RNDIS_OID_GEN_RCV_ERROR,
117 RNDIS_OID_GEN_RCV_NO_BUFFER,
118 #ifdef RNDIS_OPTIONAL_STATS
119 RNDIS_OID_GEN_DIRECTED_BYTES_XMIT,
120 RNDIS_OID_GEN_DIRECTED_FRAMES_XMIT,
121 RNDIS_OID_GEN_MULTICAST_BYTES_XMIT,
122 RNDIS_OID_GEN_MULTICAST_FRAMES_XMIT,
123 RNDIS_OID_GEN_BROADCAST_BYTES_XMIT,
124 RNDIS_OID_GEN_BROADCAST_FRAMES_XMIT,
125 RNDIS_OID_GEN_DIRECTED_BYTES_RCV,
126 RNDIS_OID_GEN_DIRECTED_FRAMES_RCV,
127 RNDIS_OID_GEN_MULTICAST_BYTES_RCV,
128 RNDIS_OID_GEN_MULTICAST_FRAMES_RCV,
129 RNDIS_OID_GEN_BROADCAST_BYTES_RCV,
130 RNDIS_OID_GEN_BROADCAST_FRAMES_RCV,
131 RNDIS_OID_GEN_RCV_CRC_ERROR,
132 RNDIS_OID_GEN_TRANSMIT_QUEUE_LENGTH,
133 #endif /* RNDIS_OPTIONAL_STATS */
134
135 /* mandatory 802.3 */
136 /* the general stuff */
137 RNDIS_OID_802_3_PERMANENT_ADDRESS,
138 RNDIS_OID_802_3_CURRENT_ADDRESS,
139 RNDIS_OID_802_3_MULTICAST_LIST,
140 RNDIS_OID_802_3_MAC_OPTIONS,
141 RNDIS_OID_802_3_MAXIMUM_LIST_SIZE,
142
143 /* the statistical stuff */
144 RNDIS_OID_802_3_RCV_ERROR_ALIGNMENT,
145 RNDIS_OID_802_3_XMIT_ONE_COLLISION,
146 RNDIS_OID_802_3_XMIT_MORE_COLLISIONS,
147 #ifdef RNDIS_OPTIONAL_STATS
148 RNDIS_OID_802_3_XMIT_DEFERRED,
149 RNDIS_OID_802_3_XMIT_MAX_COLLISIONS,
150 RNDIS_OID_802_3_RCV_OVERRUN,
151 RNDIS_OID_802_3_XMIT_UNDERRUN,
152 RNDIS_OID_802_3_XMIT_HEARTBEAT_FAILURE,
153 RNDIS_OID_802_3_XMIT_TIMES_CRS_LOST,
154 RNDIS_OID_802_3_XMIT_LATE_COLLISIONS,
155 #endif /* RNDIS_OPTIONAL_STATS */
156
157 #ifdef RNDIS_PM
158 /* PM and wakeup are "mandatory" for USB, but the RNDIS specs
159 * don't say what they mean ... and the NDIS specs are often
160 * confusing and/or ambiguous in this context. (That is, more
161 * so than their specs for the other OIDs.)
162 *
163 * FIXME someone who knows what these should do, please
164 * implement them!
165 */
166
167 /* power management */
168 OID_PNP_CAPABILITIES,
169 OID_PNP_QUERY_POWER,
170 OID_PNP_SET_POWER,
171
172 #ifdef RNDIS_WAKEUP
173 /* wake up host */
174 OID_PNP_ENABLE_WAKE_UP,
175 OID_PNP_ADD_WAKE_UP_PATTERN,
176 OID_PNP_REMOVE_WAKE_UP_PATTERN,
177 #endif /* RNDIS_WAKEUP */
178 #endif /* RNDIS_PM */
179 };
180
181
182 /* NDIS Functions */
gen_ndis_query_resp(struct rndis_params * params,u32 OID,u8 * buf,unsigned buf_len,rndis_resp_t * r)183 static int gen_ndis_query_resp(struct rndis_params *params, u32 OID, u8 *buf,
184 unsigned buf_len, rndis_resp_t *r)
185 {
186 int retval = -ENOTSUPP;
187 u32 length = 4; /* usually */
188 __le32 *outbuf;
189 int i, count;
190 rndis_query_cmplt_type *resp;
191 struct net_device *net;
192 struct rtnl_link_stats64 temp;
193 const struct rtnl_link_stats64 *stats;
194
195 if (!r) return -ENOMEM;
196 resp = (rndis_query_cmplt_type *)r->buf;
197
198 if (!resp) return -ENOMEM;
199
200 if (buf_len && rndis_debug > 1) {
201 pr_debug("query OID %08x value, len %d:\n", OID, buf_len);
202 for (i = 0; i < buf_len; i += 16) {
203 pr_debug("%03d: %08x %08x %08x %08x\n", i,
204 get_unaligned_le32(&buf[i]),
205 get_unaligned_le32(&buf[i + 4]),
206 get_unaligned_le32(&buf[i + 8]),
207 get_unaligned_le32(&buf[i + 12]));
208 }
209 }
210
211 /* response goes here, right after the header */
212 outbuf = (__le32 *)&resp[1];
213 resp->InformationBufferOffset = cpu_to_le32(16);
214
215 net = params->dev;
216 stats = dev_get_stats(net, &temp);
217
218 switch (OID) {
219
220 /* general oids (table 4-1) */
221
222 /* mandatory */
223 case RNDIS_OID_GEN_SUPPORTED_LIST:
224 pr_debug("%s: RNDIS_OID_GEN_SUPPORTED_LIST\n", __func__);
225 length = sizeof(oid_supported_list);
226 count = length / sizeof(u32);
227 for (i = 0; i < count; i++)
228 outbuf[i] = cpu_to_le32(oid_supported_list[i]);
229 retval = 0;
230 break;
231
232 /* mandatory */
233 case RNDIS_OID_GEN_HARDWARE_STATUS:
234 pr_debug("%s: RNDIS_OID_GEN_HARDWARE_STATUS\n", __func__);
235 /* Bogus question!
236 * Hardware must be ready to receive high level protocols.
237 * BTW:
238 * reddite ergo quae sunt Caesaris Caesari
239 * et quae sunt Dei Deo!
240 */
241 *outbuf = cpu_to_le32(0);
242 retval = 0;
243 break;
244
245 /* mandatory */
246 case RNDIS_OID_GEN_MEDIA_SUPPORTED:
247 pr_debug("%s: RNDIS_OID_GEN_MEDIA_SUPPORTED\n", __func__);
248 *outbuf = cpu_to_le32(params->medium);
249 retval = 0;
250 break;
251
252 /* mandatory */
253 case RNDIS_OID_GEN_MEDIA_IN_USE:
254 pr_debug("%s: RNDIS_OID_GEN_MEDIA_IN_USE\n", __func__);
255 /* one medium, one transport... (maybe you do it better) */
256 *outbuf = cpu_to_le32(params->medium);
257 retval = 0;
258 break;
259
260 /* mandatory */
261 case RNDIS_OID_GEN_MAXIMUM_FRAME_SIZE:
262 pr_debug("%s: RNDIS_OID_GEN_MAXIMUM_FRAME_SIZE\n", __func__);
263 if (params->dev) {
264 *outbuf = cpu_to_le32(params->dev->mtu);
265 retval = 0;
266 }
267 break;
268
269 /* mandatory */
270 case RNDIS_OID_GEN_LINK_SPEED:
271 if (rndis_debug > 1)
272 pr_debug("%s: RNDIS_OID_GEN_LINK_SPEED\n", __func__);
273 if (params->media_state == RNDIS_MEDIA_STATE_DISCONNECTED)
274 *outbuf = cpu_to_le32(0);
275 else
276 *outbuf = cpu_to_le32(params->speed);
277 retval = 0;
278 break;
279
280 /* mandatory */
281 case RNDIS_OID_GEN_TRANSMIT_BLOCK_SIZE:
282 pr_debug("%s: RNDIS_OID_GEN_TRANSMIT_BLOCK_SIZE\n", __func__);
283 if (params->dev) {
284 *outbuf = cpu_to_le32(params->dev->mtu);
285 retval = 0;
286 }
287 break;
288
289 /* mandatory */
290 case RNDIS_OID_GEN_RECEIVE_BLOCK_SIZE:
291 pr_debug("%s: RNDIS_OID_GEN_RECEIVE_BLOCK_SIZE\n", __func__);
292 if (params->dev) {
293 *outbuf = cpu_to_le32(params->dev->mtu);
294 retval = 0;
295 }
296 break;
297
298 /* mandatory */
299 case RNDIS_OID_GEN_VENDOR_ID:
300 pr_debug("%s: RNDIS_OID_GEN_VENDOR_ID\n", __func__);
301 *outbuf = cpu_to_le32(params->vendorID);
302 retval = 0;
303 break;
304
305 /* mandatory */
306 case RNDIS_OID_GEN_VENDOR_DESCRIPTION:
307 pr_debug("%s: RNDIS_OID_GEN_VENDOR_DESCRIPTION\n", __func__);
308 if (params->vendorDescr) {
309 length = strlen(params->vendorDescr);
310 memcpy(outbuf, params->vendorDescr, length);
311 } else {
312 outbuf[0] = 0;
313 }
314 retval = 0;
315 break;
316
317 case RNDIS_OID_GEN_VENDOR_DRIVER_VERSION:
318 pr_debug("%s: RNDIS_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 RNDIS_OID_GEN_CURRENT_PACKET_FILTER:
326 pr_debug("%s: RNDIS_OID_GEN_CURRENT_PACKET_FILTER\n", __func__);
327 *outbuf = cpu_to_le32(*params->filter);
328 retval = 0;
329 break;
330
331 /* mandatory */
332 case RNDIS_OID_GEN_MAXIMUM_TOTAL_SIZE:
333 pr_debug("%s: RNDIS_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 RNDIS_OID_GEN_MEDIA_CONNECT_STATUS:
340 if (rndis_debug > 1)
341 pr_debug("%s: RNDIS_OID_GEN_MEDIA_CONNECT_STATUS\n", __func__);
342 *outbuf = cpu_to_le32(params->media_state);
343 retval = 0;
344 break;
345
346 case RNDIS_OID_GEN_PHYSICAL_MEDIUM:
347 pr_debug("%s: RNDIS_OID_GEN_PHYSICAL_MEDIUM\n", __func__);
348 *outbuf = cpu_to_le32(0);
349 retval = 0;
350 break;
351
352 /* The RNDIS specification is incomplete/wrong. Some versions
353 * of MS-Windows expect OIDs that aren't specified there. Other
354 * versions emit undefined RNDIS messages. DOCUMENT ALL THESE!
355 */
356 case RNDIS_OID_GEN_MAC_OPTIONS: /* from WinME */
357 pr_debug("%s: RNDIS_OID_GEN_MAC_OPTIONS\n", __func__);
358 *outbuf = cpu_to_le32(
359 RNDIS_MAC_OPTION_RECEIVE_SERIALIZED
360 | RNDIS_MAC_OPTION_FULL_DUPLEX);
361 retval = 0;
362 break;
363
364 /* statistics OIDs (table 4-2) */
365
366 /* mandatory */
367 case RNDIS_OID_GEN_XMIT_OK:
368 if (rndis_debug > 1)
369 pr_debug("%s: RNDIS_OID_GEN_XMIT_OK\n", __func__);
370 if (stats) {
371 *outbuf = cpu_to_le32(stats->tx_packets
372 - stats->tx_errors - stats->tx_dropped);
373 retval = 0;
374 }
375 break;
376
377 /* mandatory */
378 case RNDIS_OID_GEN_RCV_OK:
379 if (rndis_debug > 1)
380 pr_debug("%s: RNDIS_OID_GEN_RCV_OK\n", __func__);
381 if (stats) {
382 *outbuf = cpu_to_le32(stats->rx_packets
383 - stats->rx_errors - stats->rx_dropped);
384 retval = 0;
385 }
386 break;
387
388 /* mandatory */
389 case RNDIS_OID_GEN_XMIT_ERROR:
390 if (rndis_debug > 1)
391 pr_debug("%s: RNDIS_OID_GEN_XMIT_ERROR\n", __func__);
392 if (stats) {
393 *outbuf = cpu_to_le32(stats->tx_errors);
394 retval = 0;
395 }
396 break;
397
398 /* mandatory */
399 case RNDIS_OID_GEN_RCV_ERROR:
400 if (rndis_debug > 1)
401 pr_debug("%s: RNDIS_OID_GEN_RCV_ERROR\n", __func__);
402 if (stats) {
403 *outbuf = cpu_to_le32(stats->rx_errors);
404 retval = 0;
405 }
406 break;
407
408 /* mandatory */
409 case RNDIS_OID_GEN_RCV_NO_BUFFER:
410 pr_debug("%s: RNDIS_OID_GEN_RCV_NO_BUFFER\n", __func__);
411 if (stats) {
412 *outbuf = cpu_to_le32(stats->rx_dropped);
413 retval = 0;
414 }
415 break;
416
417 /* ieee802.3 OIDs (table 4-3) */
418
419 /* mandatory */
420 case RNDIS_OID_802_3_PERMANENT_ADDRESS:
421 pr_debug("%s: RNDIS_OID_802_3_PERMANENT_ADDRESS\n", __func__);
422 if (params->dev) {
423 length = ETH_ALEN;
424 memcpy(outbuf, params->host_mac, length);
425 retval = 0;
426 }
427 break;
428
429 /* mandatory */
430 case RNDIS_OID_802_3_CURRENT_ADDRESS:
431 pr_debug("%s: RNDIS_OID_802_3_CURRENT_ADDRESS\n", __func__);
432 if (params->dev) {
433 length = ETH_ALEN;
434 memcpy(outbuf, params->host_mac, length);
435 retval = 0;
436 }
437 break;
438
439 /* mandatory */
440 case RNDIS_OID_802_3_MULTICAST_LIST:
441 pr_debug("%s: RNDIS_OID_802_3_MULTICAST_LIST\n", __func__);
442 /* Multicast base address only */
443 *outbuf = cpu_to_le32(0xE0000000);
444 retval = 0;
445 break;
446
447 /* mandatory */
448 case RNDIS_OID_802_3_MAXIMUM_LIST_SIZE:
449 pr_debug("%s: RNDIS_OID_802_3_MAXIMUM_LIST_SIZE\n", __func__);
450 /* Multicast base address only */
451 *outbuf = cpu_to_le32(1);
452 retval = 0;
453 break;
454
455 case RNDIS_OID_802_3_MAC_OPTIONS:
456 pr_debug("%s: RNDIS_OID_802_3_MAC_OPTIONS\n", __func__);
457 *outbuf = cpu_to_le32(0);
458 retval = 0;
459 break;
460
461 /* ieee802.3 statistics OIDs (table 4-4) */
462
463 /* mandatory */
464 case RNDIS_OID_802_3_RCV_ERROR_ALIGNMENT:
465 pr_debug("%s: RNDIS_OID_802_3_RCV_ERROR_ALIGNMENT\n", __func__);
466 if (stats) {
467 *outbuf = cpu_to_le32(stats->rx_frame_errors);
468 retval = 0;
469 }
470 break;
471
472 /* mandatory */
473 case RNDIS_OID_802_3_XMIT_ONE_COLLISION:
474 pr_debug("%s: RNDIS_OID_802_3_XMIT_ONE_COLLISION\n", __func__);
475 *outbuf = cpu_to_le32(0);
476 retval = 0;
477 break;
478
479 /* mandatory */
480 case RNDIS_OID_802_3_XMIT_MORE_COLLISIONS:
481 pr_debug("%s: RNDIS_OID_802_3_XMIT_MORE_COLLISIONS\n", __func__);
482 *outbuf = cpu_to_le32(0);
483 retval = 0;
484 break;
485
486 default:
487 pr_warning("%s: query unknown OID 0x%08X\n",
488 __func__, OID);
489 }
490 if (retval < 0)
491 length = 0;
492
493 resp->InformationBufferLength = cpu_to_le32(length);
494 r->length = length + sizeof(*resp);
495 resp->MessageLength = cpu_to_le32(r->length);
496 return retval;
497 }
498
gen_ndis_set_resp(struct rndis_params * params,u32 OID,u8 * buf,u32 buf_len,rndis_resp_t * r)499 static int gen_ndis_set_resp(struct rndis_params *params, u32 OID,
500 u8 *buf, u32 buf_len, rndis_resp_t *r)
501 {
502 rndis_set_cmplt_type *resp;
503 int i, retval = -ENOTSUPP;
504
505 if (!r)
506 return -ENOMEM;
507 resp = (rndis_set_cmplt_type *)r->buf;
508 if (!resp)
509 return -ENOMEM;
510
511 if (buf_len && rndis_debug > 1) {
512 pr_debug("set OID %08x value, len %d:\n", OID, buf_len);
513 for (i = 0; i < buf_len; i += 16) {
514 pr_debug("%03d: %08x %08x %08x %08x\n", i,
515 get_unaligned_le32(&buf[i]),
516 get_unaligned_le32(&buf[i + 4]),
517 get_unaligned_le32(&buf[i + 8]),
518 get_unaligned_le32(&buf[i + 12]));
519 }
520 }
521
522 switch (OID) {
523 case RNDIS_OID_GEN_CURRENT_PACKET_FILTER:
524
525 /* these NDIS_PACKET_TYPE_* bitflags are shared with
526 * cdc_filter; it's not RNDIS-specific
527 * NDIS_PACKET_TYPE_x == USB_CDC_PACKET_TYPE_x for x in:
528 * PROMISCUOUS, DIRECTED,
529 * MULTICAST, ALL_MULTICAST, BROADCAST
530 */
531 *params->filter = (u16)get_unaligned_le32(buf);
532 pr_debug("%s: RNDIS_OID_GEN_CURRENT_PACKET_FILTER %08x\n",
533 __func__, *params->filter);
534
535 /* this call has a significant side effect: it's
536 * what makes the packet flow start and stop, like
537 * activating the CDC Ethernet altsetting.
538 */
539 retval = 0;
540 if (*params->filter) {
541 params->state = RNDIS_DATA_INITIALIZED;
542 netif_carrier_on(params->dev);
543 if (netif_running(params->dev))
544 netif_wake_queue(params->dev);
545 } else {
546 params->state = RNDIS_INITIALIZED;
547 netif_carrier_off(params->dev);
548 netif_stop_queue(params->dev);
549 }
550 break;
551
552 case RNDIS_OID_802_3_MULTICAST_LIST:
553 /* I think we can ignore this */
554 pr_debug("%s: RNDIS_OID_802_3_MULTICAST_LIST\n", __func__);
555 retval = 0;
556 break;
557
558 default:
559 pr_warning("%s: set unknown OID 0x%08X, size %d\n",
560 __func__, OID, buf_len);
561 }
562
563 return retval;
564 }
565
566 /*
567 * Response Functions
568 */
569
rndis_init_response(struct rndis_params * params,rndis_init_msg_type * buf)570 static int rndis_init_response(struct rndis_params *params,
571 rndis_init_msg_type *buf)
572 {
573 rndis_init_cmplt_type *resp;
574 rndis_resp_t *r;
575
576 if (!params->dev)
577 return -ENOTSUPP;
578
579 r = rndis_add_response(params, sizeof(rndis_init_cmplt_type));
580 if (!r)
581 return -ENOMEM;
582 resp = (rndis_init_cmplt_type *)r->buf;
583
584 resp->MessageType = cpu_to_le32(RNDIS_MSG_INIT_C);
585 resp->MessageLength = cpu_to_le32(52);
586 resp->RequestID = buf->RequestID; /* Still LE in msg buffer */
587 resp->Status = cpu_to_le32(RNDIS_STATUS_SUCCESS);
588 resp->MajorVersion = cpu_to_le32(RNDIS_MAJOR_VERSION);
589 resp->MinorVersion = cpu_to_le32(RNDIS_MINOR_VERSION);
590 resp->DeviceFlags = cpu_to_le32(RNDIS_DF_CONNECTIONLESS);
591 resp->Medium = cpu_to_le32(RNDIS_MEDIUM_802_3);
592 resp->MaxPacketsPerTransfer = cpu_to_le32(params->max_pkt_per_xfer);
593 resp->MaxTransferSize = cpu_to_le32(params->max_pkt_per_xfer *
594 (params->dev->mtu
595 + sizeof(struct ethhdr)
596 + sizeof(struct rndis_packet_msg_type)
597 + 22));
598 resp->PacketAlignmentFactor = cpu_to_le32(0);
599 resp->AFListOffset = cpu_to_le32(0);
600 resp->AFListSize = cpu_to_le32(0);
601
602 params->resp_avail(params->v);
603 return 0;
604 }
605
rndis_query_response(struct rndis_params * params,rndis_query_msg_type * buf)606 static int rndis_query_response(struct rndis_params *params,
607 rndis_query_msg_type *buf)
608 {
609 rndis_query_cmplt_type *resp;
610 rndis_resp_t *r;
611
612 /* pr_debug("%s: OID = %08X\n", __func__, cpu_to_le32(buf->OID)); */
613 if (!params->dev)
614 return -ENOTSUPP;
615
616 /*
617 * we need more memory:
618 * gen_ndis_query_resp expects enough space for
619 * rndis_query_cmplt_type followed by data.
620 * oid_supported_list is the largest data reply
621 */
622 r = rndis_add_response(params,
623 sizeof(oid_supported_list) + sizeof(rndis_query_cmplt_type));
624 if (!r)
625 return -ENOMEM;
626 resp = (rndis_query_cmplt_type *)r->buf;
627
628 resp->MessageType = cpu_to_le32(RNDIS_MSG_QUERY_C);
629 resp->RequestID = buf->RequestID; /* Still LE in msg buffer */
630
631 if (gen_ndis_query_resp(params, le32_to_cpu(buf->OID),
632 le32_to_cpu(buf->InformationBufferOffset)
633 + 8 + (u8 *)buf,
634 le32_to_cpu(buf->InformationBufferLength),
635 r)) {
636 /* OID not supported */
637 resp->Status = cpu_to_le32(RNDIS_STATUS_NOT_SUPPORTED);
638 resp->MessageLength = cpu_to_le32(sizeof *resp);
639 resp->InformationBufferLength = cpu_to_le32(0);
640 resp->InformationBufferOffset = cpu_to_le32(0);
641 } else
642 resp->Status = cpu_to_le32(RNDIS_STATUS_SUCCESS);
643
644 params->resp_avail(params->v);
645 return 0;
646 }
647
rndis_set_response(struct rndis_params * params,rndis_set_msg_type * buf)648 static int rndis_set_response(struct rndis_params *params,
649 rndis_set_msg_type *buf)
650 {
651 u32 BufLength, BufOffset;
652 rndis_set_cmplt_type *resp;
653 rndis_resp_t *r;
654
655 r = rndis_add_response(params, sizeof(rndis_set_cmplt_type));
656 if (!r)
657 return -ENOMEM;
658 resp = (rndis_set_cmplt_type *)r->buf;
659
660 BufLength = le32_to_cpu(buf->InformationBufferLength);
661 BufOffset = le32_to_cpu(buf->InformationBufferOffset);
662
663 #ifdef VERBOSE_DEBUG
664 pr_debug("%s: Length: %d\n", __func__, BufLength);
665 pr_debug("%s: Offset: %d\n", __func__, BufOffset);
666 pr_debug("%s: InfoBuffer: ", __func__);
667
668 for (i = 0; i < BufLength; i++) {
669 pr_debug("%02x ", *(((u8 *) buf) + i + 8 + BufOffset));
670 }
671
672 pr_debug("\n");
673 #endif
674
675 resp->MessageType = cpu_to_le32(RNDIS_MSG_SET_C);
676 resp->MessageLength = cpu_to_le32(16);
677 resp->RequestID = buf->RequestID; /* Still LE in msg buffer */
678 if (gen_ndis_set_resp(params, le32_to_cpu(buf->OID),
679 ((u8 *)buf) + 8 + BufOffset, BufLength, r))
680 resp->Status = cpu_to_le32(RNDIS_STATUS_NOT_SUPPORTED);
681 else
682 resp->Status = cpu_to_le32(RNDIS_STATUS_SUCCESS);
683
684 params->resp_avail(params->v);
685 return 0;
686 }
687
rndis_reset_response(struct rndis_params * params,rndis_reset_msg_type * buf)688 static int rndis_reset_response(struct rndis_params *params,
689 rndis_reset_msg_type *buf)
690 {
691 rndis_reset_cmplt_type *resp;
692 rndis_resp_t *r;
693 u8 *xbuf;
694 u32 length;
695
696 /* drain the response queue */
697 while ((xbuf = rndis_get_next_response(params, &length)))
698 rndis_free_response(params, xbuf);
699
700 r = rndis_add_response(params, sizeof(rndis_reset_cmplt_type));
701 if (!r)
702 return -ENOMEM;
703 resp = (rndis_reset_cmplt_type *)r->buf;
704
705 resp->MessageType = cpu_to_le32(RNDIS_MSG_RESET_C);
706 resp->MessageLength = cpu_to_le32(16);
707 resp->Status = cpu_to_le32(RNDIS_STATUS_SUCCESS);
708 /* resent information */
709 resp->AddressingReset = cpu_to_le32(1);
710
711 params->resp_avail(params->v);
712 return 0;
713 }
714
rndis_keepalive_response(struct rndis_params * params,rndis_keepalive_msg_type * buf)715 static int rndis_keepalive_response(struct rndis_params *params,
716 rndis_keepalive_msg_type *buf)
717 {
718 rndis_keepalive_cmplt_type *resp;
719 rndis_resp_t *r;
720
721 /* host "should" check only in RNDIS_DATA_INITIALIZED state */
722
723 r = rndis_add_response(params, sizeof(rndis_keepalive_cmplt_type));
724 if (!r)
725 return -ENOMEM;
726 resp = (rndis_keepalive_cmplt_type *)r->buf;
727
728 resp->MessageType = cpu_to_le32(RNDIS_MSG_KEEPALIVE_C);
729 resp->MessageLength = cpu_to_le32(16);
730 resp->RequestID = buf->RequestID; /* Still LE in msg buffer */
731 resp->Status = cpu_to_le32(RNDIS_STATUS_SUCCESS);
732
733 params->resp_avail(params->v);
734 return 0;
735 }
736
737
738 /*
739 * Device to Host Comunication
740 */
rndis_indicate_status_msg(struct rndis_params * params,u32 status)741 static int rndis_indicate_status_msg(struct rndis_params *params, u32 status)
742 {
743 rndis_indicate_status_msg_type *resp;
744 rndis_resp_t *r;
745
746 if (params->state == RNDIS_UNINITIALIZED)
747 return -ENOTSUPP;
748
749 r = rndis_add_response(params, sizeof(rndis_indicate_status_msg_type));
750 if (!r)
751 return -ENOMEM;
752 resp = (rndis_indicate_status_msg_type *)r->buf;
753
754 resp->MessageType = cpu_to_le32(RNDIS_MSG_INDICATE);
755 resp->MessageLength = cpu_to_le32(20);
756 resp->Status = cpu_to_le32(status);
757 resp->StatusBufferLength = cpu_to_le32(0);
758 resp->StatusBufferOffset = cpu_to_le32(0);
759
760 params->resp_avail(params->v);
761 return 0;
762 }
763
rndis_signal_connect(struct rndis_params * params)764 int rndis_signal_connect(struct rndis_params *params)
765 {
766 params->media_state = RNDIS_MEDIA_STATE_CONNECTED;
767 return rndis_indicate_status_msg(params, RNDIS_STATUS_MEDIA_CONNECT);
768 }
769 EXPORT_SYMBOL_GPL(rndis_signal_connect);
770
rndis_signal_disconnect(struct rndis_params * params)771 int rndis_signal_disconnect(struct rndis_params *params)
772 {
773 params->media_state = RNDIS_MEDIA_STATE_DISCONNECTED;
774 return rndis_indicate_status_msg(params, RNDIS_STATUS_MEDIA_DISCONNECT);
775 }
776 EXPORT_SYMBOL_GPL(rndis_signal_disconnect);
777
rndis_uninit(struct rndis_params * params)778 void rndis_uninit(struct rndis_params *params)
779 {
780 u8 *buf;
781 u32 length;
782
783 if (!params)
784 return;
785 params->state = RNDIS_UNINITIALIZED;
786
787 /* drain the response queue */
788 while ((buf = rndis_get_next_response(params, &length)))
789 rndis_free_response(params, buf);
790 }
791 EXPORT_SYMBOL_GPL(rndis_uninit);
792
rndis_set_host_mac(struct rndis_params * params,const u8 * addr)793 void rndis_set_host_mac(struct rndis_params *params, const u8 *addr)
794 {
795 params->host_mac = addr;
796 }
797 EXPORT_SYMBOL_GPL(rndis_set_host_mac);
798
799 /*
800 * Message Parser
801 */
rndis_msg_parser(struct rndis_params * params,u8 * buf)802 int rndis_msg_parser(struct rndis_params *params, u8 *buf)
803 {
804 u32 MsgType, MsgLength;
805 __le32 *tmp;
806
807 if (!buf)
808 return -ENOMEM;
809
810 tmp = (__le32 *)buf;
811 MsgType = get_unaligned_le32(tmp++);
812 MsgLength = get_unaligned_le32(tmp++);
813
814 if (!params)
815 return -ENOTSUPP;
816
817 /* NOTE: RNDIS is *EXTREMELY* chatty ... Windows constantly polls for
818 * rx/tx statistics and link status, in addition to KEEPALIVE traffic
819 * and normal HC level polling to see if there's any IN traffic.
820 */
821
822 /* For USB: responses may take up to 10 seconds */
823 switch (MsgType) {
824 case RNDIS_MSG_INIT:
825 pr_debug("%s: RNDIS_MSG_INIT\n",
826 __func__);
827 params->state = RNDIS_INITIALIZED;
828 return rndis_init_response(params, (rndis_init_msg_type *)buf);
829
830 case RNDIS_MSG_HALT:
831 pr_debug("%s: RNDIS_MSG_HALT\n",
832 __func__);
833 params->state = RNDIS_UNINITIALIZED;
834 if (params->dev) {
835 netif_carrier_off(params->dev);
836 netif_stop_queue(params->dev);
837 }
838 return 0;
839
840 case RNDIS_MSG_QUERY:
841 return rndis_query_response(params,
842 (rndis_query_msg_type *)buf);
843
844 case RNDIS_MSG_SET:
845 return rndis_set_response(params, (rndis_set_msg_type *)buf);
846
847 case RNDIS_MSG_RESET:
848 pr_debug("%s: RNDIS_MSG_RESET\n",
849 __func__);
850 return rndis_reset_response(params,
851 (rndis_reset_msg_type *)buf);
852
853 case RNDIS_MSG_KEEPALIVE:
854 /* For USB: host does this every 5 seconds */
855 if (rndis_debug > 1)
856 pr_debug("%s: RNDIS_MSG_KEEPALIVE\n",
857 __func__);
858 return rndis_keepalive_response(params,
859 (rndis_keepalive_msg_type *)
860 buf);
861
862 default:
863 /* At least Windows XP emits some undefined RNDIS messages.
864 * In one case those messages seemed to relate to the host
865 * suspending itself.
866 */
867 pr_warning("%s: unknown RNDIS message 0x%08X len %d\n",
868 __func__, MsgType, MsgLength);
869 print_hex_dump_bytes(__func__, DUMP_PREFIX_OFFSET,
870 buf, MsgLength);
871 break;
872 }
873
874 return -ENOTSUPP;
875 }
876 EXPORT_SYMBOL_GPL(rndis_msg_parser);
877
rndis_get_nr(void)878 static inline int rndis_get_nr(void)
879 {
880 return ida_simple_get(&rndis_ida, 0, 0, GFP_KERNEL);
881 }
882
rndis_put_nr(int nr)883 static inline void rndis_put_nr(int nr)
884 {
885 ida_simple_remove(&rndis_ida, nr);
886 }
887
rndis_register(void (* resp_avail)(void * v),void * v)888 struct rndis_params *rndis_register(void (*resp_avail)(void *v), void *v)
889 {
890 struct rndis_params *params;
891 int i;
892
893 if (!resp_avail)
894 return ERR_PTR(-EINVAL);
895
896 i = rndis_get_nr();
897 if (i < 0) {
898 pr_debug("failed\n");
899
900 return ERR_PTR(-ENODEV);
901 }
902
903 params = kzalloc(sizeof(*params), GFP_KERNEL);
904 if (!params) {
905 rndis_put_nr(i);
906
907 return ERR_PTR(-ENOMEM);
908 }
909
910 #ifdef CONFIG_USB_GADGET_DEBUG_FILES
911 {
912 struct proc_dir_entry *proc_entry;
913 char name[20];
914
915 sprintf(name, NAME_TEMPLATE, i);
916 proc_entry = proc_create_data(name, 0660, NULL,
917 &rndis_proc_fops, params);
918 if (!proc_entry) {
919 kfree(params);
920 rndis_put_nr(i);
921
922 return ERR_PTR(-EIO);
923 }
924 }
925 #endif
926
927 params->confignr = i;
928 params->used = 1;
929 params->state = RNDIS_UNINITIALIZED;
930 params->media_state = RNDIS_MEDIA_STATE_DISCONNECTED;
931 params->resp_avail = resp_avail;
932 params->v = v;
933 INIT_LIST_HEAD(&(params->resp_queue));
934 pr_debug("%s: configNr = %d\n", __func__, i);
935
936 return params;
937 }
938 EXPORT_SYMBOL_GPL(rndis_register);
939
rndis_deregister(struct rndis_params * params)940 void rndis_deregister(struct rndis_params *params)
941 {
942 int i;
943
944 pr_debug("%s:\n", __func__);
945
946 if (!params)
947 return;
948
949 i = params->confignr;
950
951 #ifdef CONFIG_USB_GADGET_DEBUG_FILES
952 {
953 char name[20];
954
955 sprintf(name, NAME_TEMPLATE, i);
956 remove_proc_entry(name, NULL);
957 }
958 #endif
959
960 kfree(params);
961 rndis_put_nr(i);
962 }
963 EXPORT_SYMBOL_GPL(rndis_deregister);
rndis_set_param_dev(struct rndis_params * params,struct net_device * dev,u16 * cdc_filter)964 int rndis_set_param_dev(struct rndis_params *params, struct net_device *dev,
965 u16 *cdc_filter)
966 {
967 pr_debug("%s:\n", __func__);
968 if (!dev)
969 return -EINVAL;
970 if (!params)
971 return -1;
972
973 params->dev = dev;
974 params->filter = cdc_filter;
975
976 rndis_ul_max_xfer_size_rcvd = 0;
977 rndis_ul_max_pkt_per_xfer_rcvd = 0;
978 return 0;
979 }
980 EXPORT_SYMBOL_GPL(rndis_set_param_dev);
981
rndis_set_param_vendor(struct rndis_params * params,u32 vendorID,const char * vendorDescr)982 int rndis_set_param_vendor(struct rndis_params *params, u32 vendorID,
983 const char *vendorDescr)
984 {
985 pr_debug("%s:\n", __func__);
986 if (!vendorDescr) return -1;
987 if (!params)
988 return -1;
989
990 params->vendorID = vendorID;
991 params->vendorDescr = vendorDescr;
992
993 return 0;
994 }
995 EXPORT_SYMBOL_GPL(rndis_set_param_vendor);
996
rndis_set_param_medium(struct rndis_params * params,u32 medium,u32 speed)997 int rndis_set_param_medium(struct rndis_params *params, u32 medium, u32 speed)
998 {
999 pr_debug("%s: %u %u\n", __func__, medium, speed);
1000 if (!params)
1001 return -1;
1002
1003 params->medium = medium;
1004 params->speed = speed;
1005
1006 return 0;
1007 }
1008 EXPORT_SYMBOL_GPL(rndis_set_param_medium);
1009
rndis_set_max_pkt_xfer(struct rndis_params * params,u8 max_pkt_per_xfer)1010 void rndis_set_max_pkt_xfer(struct rndis_params *params, u8 max_pkt_per_xfer)
1011 {
1012 pr_debug("%s:\n", __func__);
1013
1014 params->max_pkt_per_xfer = max_pkt_per_xfer;
1015 }
1016
rndis_add_hdr(struct sk_buff * skb)1017 void rndis_add_hdr(struct sk_buff *skb)
1018 {
1019 struct rndis_packet_msg_type *header;
1020
1021 if (!skb)
1022 return;
1023 header = (void *)skb_push(skb, sizeof(*header));
1024 memset(header, 0, sizeof *header);
1025 header->MessageType = cpu_to_le32(RNDIS_MSG_PACKET);
1026 header->MessageLength = cpu_to_le32(skb->len);
1027 header->DataOffset = cpu_to_le32(36);
1028 header->DataLength = cpu_to_le32(skb->len - sizeof(*header));
1029 }
1030 EXPORT_SYMBOL_GPL(rndis_add_hdr);
1031
rndis_free_response(struct rndis_params * params,u8 * buf)1032 void rndis_free_response(struct rndis_params *params, u8 *buf)
1033 {
1034 rndis_resp_t *r;
1035 struct list_head *act, *tmp;
1036
1037 list_for_each_safe(act, tmp, &(params->resp_queue))
1038 {
1039 r = list_entry(act, rndis_resp_t, list);
1040 if (r && r->buf == buf) {
1041 list_del(&r->list);
1042 kfree(r);
1043 }
1044 }
1045 }
1046 EXPORT_SYMBOL_GPL(rndis_free_response);
1047
rndis_get_next_response(struct rndis_params * params,u32 * length)1048 u8 *rndis_get_next_response(struct rndis_params *params, u32 *length)
1049 {
1050 rndis_resp_t *r;
1051 struct list_head *act, *tmp;
1052
1053 if (!length) return NULL;
1054
1055 list_for_each_safe(act, tmp, &(params->resp_queue))
1056 {
1057 r = list_entry(act, rndis_resp_t, list);
1058 if (!r->send) {
1059 r->send = 1;
1060 *length = r->length;
1061 return r->buf;
1062 }
1063 }
1064
1065 return NULL;
1066 }
1067 EXPORT_SYMBOL_GPL(rndis_get_next_response);
1068
rndis_add_response(struct rndis_params * params,u32 length)1069 static rndis_resp_t *rndis_add_response(struct rndis_params *params, u32 length)
1070 {
1071 rndis_resp_t *r;
1072
1073 /* NOTE: this gets copied into ether.c USB_BUFSIZ bytes ... */
1074 r = kmalloc(sizeof(rndis_resp_t) + length, GFP_ATOMIC);
1075 if (!r) return NULL;
1076
1077 r->buf = (u8 *)(r + 1);
1078 r->length = length;
1079 r->send = 0;
1080
1081 list_add_tail(&r->list, &(params->resp_queue));
1082 return r;
1083 }
1084
rndis_rm_hdr(struct gether * port,struct sk_buff * skb,struct sk_buff_head * list)1085 int rndis_rm_hdr(struct gether *port,
1086 struct sk_buff *skb,
1087 struct sk_buff_head *list)
1088 {
1089 int num_pkts = 1;
1090
1091 if (skb->len > rndis_ul_max_xfer_size_rcvd)
1092 rndis_ul_max_xfer_size_rcvd = skb->len;
1093
1094 while (skb->len) {
1095 struct rndis_packet_msg_type *hdr;
1096 struct sk_buff *skb2;
1097 u32 msg_len, data_offset, data_len;
1098
1099 /* some rndis hosts send extra byte to avoid zlp, ignore it */
1100 if (skb->len == 1) {
1101 dev_kfree_skb_any(skb);
1102 return 0;
1103 }
1104
1105 if (skb->len < sizeof *hdr) {
1106 pr_err("invalid rndis pkt: skblen:%u hdr_len:%zu",
1107 skb->len, sizeof *hdr);
1108 dev_kfree_skb_any(skb);
1109 return -EINVAL;
1110 }
1111
1112 hdr = (void *)skb->data;
1113 msg_len = le32_to_cpu(hdr->MessageLength);
1114 data_offset = le32_to_cpu(hdr->DataOffset);
1115 data_len = le32_to_cpu(hdr->DataLength);
1116
1117 if (skb->len < msg_len ||
1118 ((data_offset + data_len + 8) > msg_len)) {
1119 pr_err("invalid rndis message: %d/%d/%d/%d, len:%d\n",
1120 le32_to_cpu(hdr->MessageType),
1121 msg_len, data_offset, data_len, skb->len);
1122 dev_kfree_skb_any(skb);
1123 return -EOVERFLOW;
1124 }
1125 if (le32_to_cpu(hdr->MessageType) != RNDIS_MSG_PACKET) {
1126 pr_err("invalid rndis message: %d/%d/%d/%d, len:%d\n",
1127 le32_to_cpu(hdr->MessageType),
1128 msg_len, data_offset, data_len, skb->len);
1129 dev_kfree_skb_any(skb);
1130 return -EINVAL;
1131 }
1132
1133 skb_pull(skb, data_offset + 8);
1134
1135 if (msg_len == skb->len) {
1136 skb_trim(skb, data_len);
1137 break;
1138 }
1139
1140 skb2 = skb_clone(skb, GFP_ATOMIC);
1141 if (!skb2) {
1142 pr_err("%s:skb clone failed\n", __func__);
1143 dev_kfree_skb_any(skb);
1144 return -ENOMEM;
1145 }
1146
1147 skb_pull(skb, msg_len - sizeof *hdr);
1148 skb_trim(skb2, data_len);
1149 skb_queue_tail(list, skb2);
1150
1151 num_pkts++;
1152 }
1153
1154 if (num_pkts > rndis_ul_max_pkt_per_xfer_rcvd)
1155 rndis_ul_max_pkt_per_xfer_rcvd = num_pkts;
1156
1157 skb_queue_tail(list, skb);
1158 return 0;
1159 }
1160 EXPORT_SYMBOL_GPL(rndis_rm_hdr);
1161
1162 #ifdef CONFIG_USB_GADGET_DEBUG_FILES
1163
rndis_proc_show(struct seq_file * m,void * v)1164 static int rndis_proc_show(struct seq_file *m, void *v)
1165 {
1166 rndis_params *param = m->private;
1167
1168 seq_printf(m,
1169 "Config Nr. %d\n"
1170 "used : %s\n"
1171 "state : %s\n"
1172 "medium : 0x%08X\n"
1173 "speed : %d\n"
1174 "cable : %s\n"
1175 "vendor ID : 0x%08X\n"
1176 "vendor : %s\n",
1177 param->confignr, (param->used) ? "y" : "n",
1178 ({ char *s = "?";
1179 switch (param->state) {
1180 case RNDIS_UNINITIALIZED:
1181 s = "RNDIS_UNINITIALIZED"; break;
1182 case RNDIS_INITIALIZED:
1183 s = "RNDIS_INITIALIZED"; break;
1184 case RNDIS_DATA_INITIALIZED:
1185 s = "RNDIS_DATA_INITIALIZED"; break;
1186 } s; }),
1187 param->medium,
1188 (param->media_state) ? 0 : param->speed*100,
1189 (param->media_state) ? "disconnected" : "connected",
1190 param->vendorID, param->vendorDescr);
1191 return 0;
1192 }
1193
rndis_proc_write(struct file * file,const char __user * buffer,size_t count,loff_t * ppos)1194 static ssize_t rndis_proc_write(struct file *file, const char __user *buffer,
1195 size_t count, loff_t *ppos)
1196 {
1197 rndis_params *p = PDE_DATA(file_inode(file));
1198 u32 speed = 0;
1199 int i, fl_speed = 0;
1200
1201 for (i = 0; i < count; i++) {
1202 char c;
1203 if (get_user(c, buffer))
1204 return -EFAULT;
1205 switch (c) {
1206 case '0':
1207 case '1':
1208 case '2':
1209 case '3':
1210 case '4':
1211 case '5':
1212 case '6':
1213 case '7':
1214 case '8':
1215 case '9':
1216 fl_speed = 1;
1217 speed = speed * 10 + c - '0';
1218 break;
1219 case 'C':
1220 case 'c':
1221 rndis_signal_connect(p);
1222 break;
1223 case 'D':
1224 case 'd':
1225 rndis_signal_disconnect(p);
1226 break;
1227 default:
1228 if (fl_speed) p->speed = speed;
1229 else pr_debug("%c is not valid\n", c);
1230 break;
1231 }
1232
1233 buffer++;
1234 }
1235
1236 return count;
1237 }
1238
rndis_proc_open(struct inode * inode,struct file * file)1239 static int rndis_proc_open(struct inode *inode, struct file *file)
1240 {
1241 return single_open(file, rndis_proc_show, PDE_DATA(inode));
1242 }
1243
1244 static const struct file_operations rndis_proc_fops = {
1245 .owner = THIS_MODULE,
1246 .open = rndis_proc_open,
1247 .read = seq_read,
1248 .llseek = seq_lseek,
1249 .release = single_release,
1250 .write = rndis_proc_write,
1251 };
1252
1253 #define NAME_TEMPLATE "driver/rndis-%03d"
1254
1255 #endif /* CONFIG_USB_GADGET_DEBUG_FILES */
1256