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