blob: 708657c89132068f2bfdbb8cc7f3552cbc182cbe [file] [log] [blame]
David Brownell7e27f182006-06-13 09:54:40 -07001/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07002 * RNDIS MSG parser
David Brownell7e27f182006-06-13 09:54:40 -07003 *
Linus Torvalds1da177e2005-04-16 15:20:36 -07004 * Version: $Id: rndis.c,v 1.19 2004/03/25 21:33:46 robert Exp $
David Brownell7e27f182006-06-13 09:54:40 -07005 *
Linus Torvalds1da177e2005-04-16 15:20:36 -07006 * Authors: Benedikt Spranger, Pengutronix
David Brownell7e27f182006-06-13 09:54:40 -07007 * Robert Schwebel, Pengutronix
8 *
Linus Torvalds1da177e2005-04-16 15:20:36 -07009 * This program is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU General Public License
David Brownell7e27f182006-06-13 09:54:40 -070011 * version 2, as published by the Free Software Foundation.
12 *
Linus Torvalds1da177e2005-04-16 15:20:36 -070013 * This software was originally developed in conformance with
14 * Microsoft's Remote NDIS Specification License Agreement.
David Brownell7e27f182006-06-13 09:54:40 -070015 *
Linus Torvalds1da177e2005-04-16 15:20:36 -070016 * 03/12/2004 Kai-Uwe Bloem <linux-development@auerswald.de>
17 * Fixed message length bug in init_response
David Brownell7e27f182006-06-13 09:54:40 -070018 *
Linus Torvalds1da177e2005-04-16 15:20:36 -070019 * 03/25/2004 Kai-Uwe Bloem <linux-development@auerswald.de>
David Brownell7e27f182006-06-13 09:54:40 -070020 * Fixed rndis_rm_hdr length bug.
Linus Torvalds1da177e2005-04-16 15:20:36 -070021 *
22 * Copyright (C) 2004 by David Brownell
23 * updates to merge with Linux 2.6, better match RNDIS spec
24 */
25
Linus Torvalds1da177e2005-04-16 15:20:36 -070026#include <linux/module.h>
27#include <linux/moduleparam.h>
28#include <linux/kernel.h>
29#include <linux/errno.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070030#include <linux/init.h>
31#include <linux/list.h>
32#include <linux/proc_fs.h>
33#include <linux/netdevice.h>
34
35#include <asm/io.h>
36#include <asm/byteorder.h>
37#include <asm/system.h>
David Brownell6cdee102005-04-18 17:39:34 -070038#include <asm/unaligned.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070039
40
41#undef RNDIS_PM
David Brownell340600a2005-04-28 13:45:25 -070042#undef RNDIS_WAKEUP
Linus Torvalds1da177e2005-04-16 15:20:36 -070043#undef VERBOSE
44
45#include "rndis.h"
46
47
48/* The driver for your USB chip needs to support ep0 OUT to work with
49 * RNDIS, plus all three CDC Ethernet endpoints (interrupt not optional).
50 *
51 * Windows hosts need an INF file like Documentation/usb/linux.inf
52 * and will be happier if you provide the host_addr module parameter.
53 */
54
55#if 0
56#define DEBUG(str,args...) do { \
57 if (rndis_debug) \
58 printk(KERN_DEBUG str , ## args ); \
59 } while (0)
60static int rndis_debug = 0;
61
David Brownell340600a2005-04-28 13:45:25 -070062module_param (rndis_debug, int, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -070063MODULE_PARM_DESC (rndis_debug, "enable debugging");
64
65#else
66
67#define rndis_debug 0
68#define DEBUG(str,args...) do{}while(0)
69#endif
70
71#define RNDIS_MAX_CONFIGS 1
72
73
74static rndis_params rndis_per_dev_params [RNDIS_MAX_CONFIGS];
75
76/* Driver Version */
77static const __le32 rndis_driver_version = __constant_cpu_to_le32 (1);
78
79/* Function Prototypes */
Linus Torvalds1da177e2005-04-16 15:20:36 -070080static rndis_resp_t *rndis_add_response (int configNr, u32 length);
81
82
David Brownell340600a2005-04-28 13:45:25 -070083/* supported OIDs */
David Brownell7e27f182006-06-13 09:54:40 -070084static const u32 oid_supported_list [] =
David Brownell340600a2005-04-28 13:45:25 -070085{
86 /* the general stuff */
87 OID_GEN_SUPPORTED_LIST,
88 OID_GEN_HARDWARE_STATUS,
89 OID_GEN_MEDIA_SUPPORTED,
90 OID_GEN_MEDIA_IN_USE,
91 OID_GEN_MAXIMUM_FRAME_SIZE,
92 OID_GEN_LINK_SPEED,
93 OID_GEN_TRANSMIT_BLOCK_SIZE,
94 OID_GEN_RECEIVE_BLOCK_SIZE,
95 OID_GEN_VENDOR_ID,
96 OID_GEN_VENDOR_DESCRIPTION,
97 OID_GEN_VENDOR_DRIVER_VERSION,
98 OID_GEN_CURRENT_PACKET_FILTER,
99 OID_GEN_MAXIMUM_TOTAL_SIZE,
100 OID_GEN_MEDIA_CONNECT_STATUS,
101 OID_GEN_PHYSICAL_MEDIUM,
102#if 0
103 OID_GEN_RNDIS_CONFIG_PARAMETER,
104#endif
David Brownell7e27f182006-06-13 09:54:40 -0700105
David Brownell340600a2005-04-28 13:45:25 -0700106 /* the statistical stuff */
107 OID_GEN_XMIT_OK,
108 OID_GEN_RCV_OK,
109 OID_GEN_XMIT_ERROR,
110 OID_GEN_RCV_ERROR,
111 OID_GEN_RCV_NO_BUFFER,
112#ifdef RNDIS_OPTIONAL_STATS
113 OID_GEN_DIRECTED_BYTES_XMIT,
114 OID_GEN_DIRECTED_FRAMES_XMIT,
115 OID_GEN_MULTICAST_BYTES_XMIT,
116 OID_GEN_MULTICAST_FRAMES_XMIT,
117 OID_GEN_BROADCAST_BYTES_XMIT,
118 OID_GEN_BROADCAST_FRAMES_XMIT,
119 OID_GEN_DIRECTED_BYTES_RCV,
120 OID_GEN_DIRECTED_FRAMES_RCV,
121 OID_GEN_MULTICAST_BYTES_RCV,
122 OID_GEN_MULTICAST_FRAMES_RCV,
123 OID_GEN_BROADCAST_BYTES_RCV,
124 OID_GEN_BROADCAST_FRAMES_RCV,
125 OID_GEN_RCV_CRC_ERROR,
126 OID_GEN_TRANSMIT_QUEUE_LENGTH,
127#endif /* RNDIS_OPTIONAL_STATS */
128
David Brownell7e27f182006-06-13 09:54:40 -0700129 /* mandatory 802.3 */
David Brownell340600a2005-04-28 13:45:25 -0700130 /* the general stuff */
131 OID_802_3_PERMANENT_ADDRESS,
132 OID_802_3_CURRENT_ADDRESS,
133 OID_802_3_MULTICAST_LIST,
134 OID_802_3_MAC_OPTIONS,
135 OID_802_3_MAXIMUM_LIST_SIZE,
David Brownell7e27f182006-06-13 09:54:40 -0700136
David Brownell340600a2005-04-28 13:45:25 -0700137 /* the statistical stuff */
138 OID_802_3_RCV_ERROR_ALIGNMENT,
139 OID_802_3_XMIT_ONE_COLLISION,
140 OID_802_3_XMIT_MORE_COLLISIONS,
141#ifdef RNDIS_OPTIONAL_STATS
142 OID_802_3_XMIT_DEFERRED,
143 OID_802_3_XMIT_MAX_COLLISIONS,
144 OID_802_3_RCV_OVERRUN,
145 OID_802_3_XMIT_UNDERRUN,
146 OID_802_3_XMIT_HEARTBEAT_FAILURE,
147 OID_802_3_XMIT_TIMES_CRS_LOST,
148 OID_802_3_XMIT_LATE_COLLISIONS,
149#endif /* RNDIS_OPTIONAL_STATS */
150
151#ifdef RNDIS_PM
152 /* PM and wakeup are mandatory for USB: */
153
154 /* power management */
155 OID_PNP_CAPABILITIES,
156 OID_PNP_QUERY_POWER,
157 OID_PNP_SET_POWER,
158
159#ifdef RNDIS_WAKEUP
160 /* wake up host */
161 OID_PNP_ENABLE_WAKE_UP,
162 OID_PNP_ADD_WAKE_UP_PATTERN,
163 OID_PNP_REMOVE_WAKE_UP_PATTERN,
164#endif /* RNDIS_WAKEUP */
165#endif /* RNDIS_PM */
166};
167
168
Linus Torvalds1da177e2005-04-16 15:20:36 -0700169/* NDIS Functions */
David Brownell340600a2005-04-28 13:45:25 -0700170static int
171gen_ndis_query_resp (int configNr, u32 OID, u8 *buf, unsigned buf_len,
172 rndis_resp_t *r)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700173{
David Brownell7e27f182006-06-13 09:54:40 -0700174 int retval = -ENOTSUPP;
175 u32 length = 4; /* usually */
David Brownell340600a2005-04-28 13:45:25 -0700176 __le32 *outbuf;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700177 int i, count;
178 rndis_query_cmplt_type *resp;
179
180 if (!r) return -ENOMEM;
181 resp = (rndis_query_cmplt_type *) r->buf;
182
183 if (!resp) return -ENOMEM;
David Brownell340600a2005-04-28 13:45:25 -0700184
185 if (buf_len && rndis_debug > 1) {
186 DEBUG("query OID %08x value, len %d:\n", OID, buf_len);
187 for (i = 0; i < buf_len; i += 16) {
188 DEBUG ("%03d: %08x %08x %08x %08x\n", i,
David Brownell01ee7d72007-05-25 20:40:14 -0700189 le32_to_cpu(get_unaligned((__le32 *)
190 &buf[i])),
191 le32_to_cpu(get_unaligned((__le32 *)
192 &buf[i + 4])),
193 le32_to_cpu(get_unaligned((__le32 *)
194 &buf[i + 8])),
195 le32_to_cpu(get_unaligned((__le32 *)
196 &buf[i + 12])));
David Brownell340600a2005-04-28 13:45:25 -0700197 }
198 }
199
200 /* response goes here, right after the header */
201 outbuf = (__le32 *) &resp[1];
202 resp->InformationBufferOffset = __constant_cpu_to_le32 (16);
203
Linus Torvalds1da177e2005-04-16 15:20:36 -0700204 switch (OID) {
205
206 /* general oids (table 4-1) */
207
208 /* mandatory */
209 case OID_GEN_SUPPORTED_LIST:
210 DEBUG ("%s: OID_GEN_SUPPORTED_LIST\n", __FUNCTION__);
211 length = sizeof (oid_supported_list);
212 count = length / sizeof (u32);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700213 for (i = 0; i < count; i++)
David Brownell340600a2005-04-28 13:45:25 -0700214 outbuf[i] = cpu_to_le32 (oid_supported_list[i]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700215 retval = 0;
216 break;
David Brownell7e27f182006-06-13 09:54:40 -0700217
Linus Torvalds1da177e2005-04-16 15:20:36 -0700218 /* mandatory */
219 case OID_GEN_HARDWARE_STATUS:
220 DEBUG("%s: OID_GEN_HARDWARE_STATUS\n", __FUNCTION__);
David Brownell7e27f182006-06-13 09:54:40 -0700221 /* Bogus question!
Linus Torvalds1da177e2005-04-16 15:20:36 -0700222 * Hardware must be ready to receive high level protocols.
David Brownell7e27f182006-06-13 09:54:40 -0700223 * BTW:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700224 * reddite ergo quae sunt Caesaris Caesari
225 * et quae sunt Dei Deo!
226 */
David Brownell340600a2005-04-28 13:45:25 -0700227 *outbuf = __constant_cpu_to_le32 (0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700228 retval = 0;
229 break;
David Brownell7e27f182006-06-13 09:54:40 -0700230
Linus Torvalds1da177e2005-04-16 15:20:36 -0700231 /* mandatory */
232 case OID_GEN_MEDIA_SUPPORTED:
233 DEBUG("%s: OID_GEN_MEDIA_SUPPORTED\n", __FUNCTION__);
David Brownell340600a2005-04-28 13:45:25 -0700234 *outbuf = cpu_to_le32 (rndis_per_dev_params [configNr].medium);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700235 retval = 0;
236 break;
David Brownell7e27f182006-06-13 09:54:40 -0700237
Linus Torvalds1da177e2005-04-16 15:20:36 -0700238 /* mandatory */
239 case OID_GEN_MEDIA_IN_USE:
240 DEBUG("%s: OID_GEN_MEDIA_IN_USE\n", __FUNCTION__);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700241 /* one medium, one transport... (maybe you do it better) */
David Brownell340600a2005-04-28 13:45:25 -0700242 *outbuf = cpu_to_le32 (rndis_per_dev_params [configNr].medium);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700243 retval = 0;
244 break;
David Brownell7e27f182006-06-13 09:54:40 -0700245
Linus Torvalds1da177e2005-04-16 15:20:36 -0700246 /* mandatory */
247 case OID_GEN_MAXIMUM_FRAME_SIZE:
248 DEBUG("%s: OID_GEN_MAXIMUM_FRAME_SIZE\n", __FUNCTION__);
249 if (rndis_per_dev_params [configNr].dev) {
David Brownell340600a2005-04-28 13:45:25 -0700250 *outbuf = cpu_to_le32 (
Linus Torvalds1da177e2005-04-16 15:20:36 -0700251 rndis_per_dev_params [configNr].dev->mtu);
252 retval = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700253 }
254 break;
David Brownell7e27f182006-06-13 09:54:40 -0700255
Linus Torvalds1da177e2005-04-16 15:20:36 -0700256 /* mandatory */
257 case OID_GEN_LINK_SPEED:
David Brownell340600a2005-04-28 13:45:25 -0700258 if (rndis_debug > 1)
259 DEBUG("%s: OID_GEN_LINK_SPEED\n", __FUNCTION__);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700260 if (rndis_per_dev_params [configNr].media_state
David Brownell340600a2005-04-28 13:45:25 -0700261 == NDIS_MEDIA_STATE_DISCONNECTED)
262 *outbuf = __constant_cpu_to_le32 (0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700263 else
David Brownell340600a2005-04-28 13:45:25 -0700264 *outbuf = cpu_to_le32 (
Linus Torvalds1da177e2005-04-16 15:20:36 -0700265 rndis_per_dev_params [configNr].speed);
266 retval = 0;
267 break;
268
269 /* mandatory */
270 case OID_GEN_TRANSMIT_BLOCK_SIZE:
271 DEBUG("%s: OID_GEN_TRANSMIT_BLOCK_SIZE\n", __FUNCTION__);
272 if (rndis_per_dev_params [configNr].dev) {
David Brownell340600a2005-04-28 13:45:25 -0700273 *outbuf = cpu_to_le32 (
Linus Torvalds1da177e2005-04-16 15:20:36 -0700274 rndis_per_dev_params [configNr].dev->mtu);
275 retval = 0;
276 }
277 break;
David Brownell7e27f182006-06-13 09:54:40 -0700278
Linus Torvalds1da177e2005-04-16 15:20:36 -0700279 /* mandatory */
280 case OID_GEN_RECEIVE_BLOCK_SIZE:
281 DEBUG("%s: OID_GEN_RECEIVE_BLOCK_SIZE\n", __FUNCTION__);
282 if (rndis_per_dev_params [configNr].dev) {
David Brownell340600a2005-04-28 13:45:25 -0700283 *outbuf = cpu_to_le32 (
Linus Torvalds1da177e2005-04-16 15:20:36 -0700284 rndis_per_dev_params [configNr].dev->mtu);
285 retval = 0;
286 }
287 break;
David Brownell7e27f182006-06-13 09:54:40 -0700288
Linus Torvalds1da177e2005-04-16 15:20:36 -0700289 /* mandatory */
290 case OID_GEN_VENDOR_ID:
291 DEBUG("%s: OID_GEN_VENDOR_ID\n", __FUNCTION__);
David Brownell340600a2005-04-28 13:45:25 -0700292 *outbuf = cpu_to_le32 (
Linus Torvalds1da177e2005-04-16 15:20:36 -0700293 rndis_per_dev_params [configNr].vendorID);
294 retval = 0;
295 break;
David Brownell7e27f182006-06-13 09:54:40 -0700296
Linus Torvalds1da177e2005-04-16 15:20:36 -0700297 /* mandatory */
298 case OID_GEN_VENDOR_DESCRIPTION:
299 DEBUG("%s: OID_GEN_VENDOR_DESCRIPTION\n", __FUNCTION__);
300 length = strlen (rndis_per_dev_params [configNr].vendorDescr);
David Brownell340600a2005-04-28 13:45:25 -0700301 memcpy (outbuf,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700302 rndis_per_dev_params [configNr].vendorDescr, length);
303 retval = 0;
304 break;
305
306 case OID_GEN_VENDOR_DRIVER_VERSION:
307 DEBUG("%s: OID_GEN_VENDOR_DRIVER_VERSION\n", __FUNCTION__);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700308 /* Created as LE */
David Brownell340600a2005-04-28 13:45:25 -0700309 *outbuf = rndis_driver_version;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700310 retval = 0;
311 break;
312
313 /* mandatory */
314 case OID_GEN_CURRENT_PACKET_FILTER:
315 DEBUG("%s: OID_GEN_CURRENT_PACKET_FILTER\n", __FUNCTION__);
David Brownell340600a2005-04-28 13:45:25 -0700316 *outbuf = cpu_to_le32 (*rndis_per_dev_params[configNr].filter);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700317 retval = 0;
318 break;
319
320 /* mandatory */
321 case OID_GEN_MAXIMUM_TOTAL_SIZE:
322 DEBUG("%s: OID_GEN_MAXIMUM_TOTAL_SIZE\n", __FUNCTION__);
David Brownell340600a2005-04-28 13:45:25 -0700323 *outbuf = __constant_cpu_to_le32(RNDIS_MAX_TOTAL_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700324 retval = 0;
325 break;
326
327 /* mandatory */
328 case OID_GEN_MEDIA_CONNECT_STATUS:
David Brownell340600a2005-04-28 13:45:25 -0700329 if (rndis_debug > 1)
330 DEBUG("%s: OID_GEN_MEDIA_CONNECT_STATUS\n", __FUNCTION__);
331 *outbuf = cpu_to_le32 (rndis_per_dev_params [configNr]
Linus Torvalds1da177e2005-04-16 15:20:36 -0700332 .media_state);
333 retval = 0;
334 break;
335
336 case OID_GEN_PHYSICAL_MEDIUM:
337 DEBUG("%s: OID_GEN_PHYSICAL_MEDIUM\n", __FUNCTION__);
David Brownell340600a2005-04-28 13:45:25 -0700338 *outbuf = __constant_cpu_to_le32 (0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700339 retval = 0;
340 break;
341
342 /* The RNDIS specification is incomplete/wrong. Some versions
343 * of MS-Windows expect OIDs that aren't specified there. Other
344 * versions emit undefined RNDIS messages. DOCUMENT ALL THESE!
345 */
346 case OID_GEN_MAC_OPTIONS: /* from WinME */
347 DEBUG("%s: OID_GEN_MAC_OPTIONS\n", __FUNCTION__);
David Brownell340600a2005-04-28 13:45:25 -0700348 *outbuf = __constant_cpu_to_le32(
Linus Torvalds1da177e2005-04-16 15:20:36 -0700349 NDIS_MAC_OPTION_RECEIVE_SERIALIZED
350 | NDIS_MAC_OPTION_FULL_DUPLEX);
351 retval = 0;
352 break;
353
354 /* statistics OIDs (table 4-2) */
355
356 /* mandatory */
357 case OID_GEN_XMIT_OK:
David Brownell340600a2005-04-28 13:45:25 -0700358 if (rndis_debug > 1)
359 DEBUG("%s: OID_GEN_XMIT_OK\n", __FUNCTION__);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700360 if (rndis_per_dev_params [configNr].stats) {
David Brownell340600a2005-04-28 13:45:25 -0700361 *outbuf = cpu_to_le32 (
David Brownell7e27f182006-06-13 09:54:40 -0700362 rndis_per_dev_params [configNr].stats->tx_packets -
Linus Torvalds1da177e2005-04-16 15:20:36 -0700363 rndis_per_dev_params [configNr].stats->tx_errors -
364 rndis_per_dev_params [configNr].stats->tx_dropped);
365 retval = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700366 }
367 break;
368
369 /* mandatory */
370 case OID_GEN_RCV_OK:
David Brownell340600a2005-04-28 13:45:25 -0700371 if (rndis_debug > 1)
372 DEBUG("%s: OID_GEN_RCV_OK\n", __FUNCTION__);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700373 if (rndis_per_dev_params [configNr].stats) {
David Brownell340600a2005-04-28 13:45:25 -0700374 *outbuf = cpu_to_le32 (
David Brownell7e27f182006-06-13 09:54:40 -0700375 rndis_per_dev_params [configNr].stats->rx_packets -
Linus Torvalds1da177e2005-04-16 15:20:36 -0700376 rndis_per_dev_params [configNr].stats->rx_errors -
377 rndis_per_dev_params [configNr].stats->rx_dropped);
378 retval = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700379 }
380 break;
David Brownell7e27f182006-06-13 09:54:40 -0700381
Linus Torvalds1da177e2005-04-16 15:20:36 -0700382 /* mandatory */
383 case OID_GEN_XMIT_ERROR:
David Brownell340600a2005-04-28 13:45:25 -0700384 if (rndis_debug > 1)
385 DEBUG("%s: OID_GEN_XMIT_ERROR\n", __FUNCTION__);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700386 if (rndis_per_dev_params [configNr].stats) {
David Brownell340600a2005-04-28 13:45:25 -0700387 *outbuf = cpu_to_le32 (rndis_per_dev_params [configNr]
Linus Torvalds1da177e2005-04-16 15:20:36 -0700388 .stats->tx_errors);
389 retval = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700390 }
391 break;
David Brownell7e27f182006-06-13 09:54:40 -0700392
Linus Torvalds1da177e2005-04-16 15:20:36 -0700393 /* mandatory */
394 case OID_GEN_RCV_ERROR:
David Brownell340600a2005-04-28 13:45:25 -0700395 if (rndis_debug > 1)
396 DEBUG("%s: OID_GEN_RCV_ERROR\n", __FUNCTION__);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700397 if (rndis_per_dev_params [configNr].stats) {
David Brownell340600a2005-04-28 13:45:25 -0700398 *outbuf = cpu_to_le32 (rndis_per_dev_params [configNr]
Linus Torvalds1da177e2005-04-16 15:20:36 -0700399 .stats->rx_errors);
400 retval = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700401 }
402 break;
David Brownell7e27f182006-06-13 09:54:40 -0700403
Linus Torvalds1da177e2005-04-16 15:20:36 -0700404 /* mandatory */
405 case OID_GEN_RCV_NO_BUFFER:
406 DEBUG("%s: OID_GEN_RCV_NO_BUFFER\n", __FUNCTION__);
407 if (rndis_per_dev_params [configNr].stats) {
David Brownell340600a2005-04-28 13:45:25 -0700408 *outbuf = cpu_to_le32 (rndis_per_dev_params [configNr]
Linus Torvalds1da177e2005-04-16 15:20:36 -0700409 .stats->rx_dropped);
410 retval = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700411 }
412 break;
413
414#ifdef RNDIS_OPTIONAL_STATS
415 case OID_GEN_DIRECTED_BYTES_XMIT:
416 DEBUG("%s: OID_GEN_DIRECTED_BYTES_XMIT\n", __FUNCTION__);
David Brownell7e27f182006-06-13 09:54:40 -0700417 /*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700418 * Aunt Tilly's size of shoes
419 * minus antarctica count of penguins
420 * divided by weight of Alpha Centauri
421 */
422 if (rndis_per_dev_params [configNr].stats) {
David Brownell340600a2005-04-28 13:45:25 -0700423 *outbuf = cpu_to_le32 (
Linus Torvalds1da177e2005-04-16 15:20:36 -0700424 (rndis_per_dev_params [configNr]
David Brownell7e27f182006-06-13 09:54:40 -0700425 .stats->tx_packets -
Linus Torvalds1da177e2005-04-16 15:20:36 -0700426 rndis_per_dev_params [configNr]
427 .stats->tx_errors -
428 rndis_per_dev_params [configNr]
429 .stats->tx_dropped)
430 * 123);
431 retval = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700432 }
433 break;
David Brownell7e27f182006-06-13 09:54:40 -0700434
Linus Torvalds1da177e2005-04-16 15:20:36 -0700435 case OID_GEN_DIRECTED_FRAMES_XMIT:
436 DEBUG("%s: OID_GEN_DIRECTED_FRAMES_XMIT\n", __FUNCTION__);
437 /* dito */
438 if (rndis_per_dev_params [configNr].stats) {
David Brownell340600a2005-04-28 13:45:25 -0700439 *outbuf = cpu_to_le32 (
Linus Torvalds1da177e2005-04-16 15:20:36 -0700440 (rndis_per_dev_params [configNr]
David Brownell7e27f182006-06-13 09:54:40 -0700441 .stats->tx_packets -
Linus Torvalds1da177e2005-04-16 15:20:36 -0700442 rndis_per_dev_params [configNr]
443 .stats->tx_errors -
444 rndis_per_dev_params [configNr]
445 .stats->tx_dropped)
446 / 123);
447 retval = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700448 }
449 break;
David Brownell7e27f182006-06-13 09:54:40 -0700450
Linus Torvalds1da177e2005-04-16 15:20:36 -0700451 case OID_GEN_MULTICAST_BYTES_XMIT:
452 DEBUG("%s: OID_GEN_MULTICAST_BYTES_XMIT\n", __FUNCTION__);
453 if (rndis_per_dev_params [configNr].stats) {
David Brownell340600a2005-04-28 13:45:25 -0700454 *outbuf = cpu_to_le32 (rndis_per_dev_params [configNr]
Linus Torvalds1da177e2005-04-16 15:20:36 -0700455 .stats->multicast*1234);
456 retval = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700457 }
458 break;
David Brownell7e27f182006-06-13 09:54:40 -0700459
Linus Torvalds1da177e2005-04-16 15:20:36 -0700460 case OID_GEN_MULTICAST_FRAMES_XMIT:
461 DEBUG("%s: OID_GEN_MULTICAST_FRAMES_XMIT\n", __FUNCTION__);
462 if (rndis_per_dev_params [configNr].stats) {
David Brownell340600a2005-04-28 13:45:25 -0700463 *outbuf = cpu_to_le32 (rndis_per_dev_params [configNr]
Linus Torvalds1da177e2005-04-16 15:20:36 -0700464 .stats->multicast);
465 retval = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700466 }
467 break;
David Brownell7e27f182006-06-13 09:54:40 -0700468
Linus Torvalds1da177e2005-04-16 15:20:36 -0700469 case OID_GEN_BROADCAST_BYTES_XMIT:
470 DEBUG("%s: OID_GEN_BROADCAST_BYTES_XMIT\n", __FUNCTION__);
471 if (rndis_per_dev_params [configNr].stats) {
David Brownell340600a2005-04-28 13:45:25 -0700472 *outbuf = cpu_to_le32 (rndis_per_dev_params [configNr]
Linus Torvalds1da177e2005-04-16 15:20:36 -0700473 .stats->tx_packets/42*255);
474 retval = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700475 }
476 break;
David Brownell7e27f182006-06-13 09:54:40 -0700477
Linus Torvalds1da177e2005-04-16 15:20:36 -0700478 case OID_GEN_BROADCAST_FRAMES_XMIT:
479 DEBUG("%s: OID_GEN_BROADCAST_FRAMES_XMIT\n", __FUNCTION__);
480 if (rndis_per_dev_params [configNr].stats) {
David Brownell340600a2005-04-28 13:45:25 -0700481 *outbuf = cpu_to_le32 (rndis_per_dev_params [configNr]
Linus Torvalds1da177e2005-04-16 15:20:36 -0700482 .stats->tx_packets/42);
483 retval = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700484 }
485 break;
David Brownell7e27f182006-06-13 09:54:40 -0700486
Linus Torvalds1da177e2005-04-16 15:20:36 -0700487 case OID_GEN_DIRECTED_BYTES_RCV:
488 DEBUG("%s: OID_GEN_DIRECTED_BYTES_RCV\n", __FUNCTION__);
David Brownell340600a2005-04-28 13:45:25 -0700489 *outbuf = __constant_cpu_to_le32 (0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700490 retval = 0;
491 break;
David Brownell7e27f182006-06-13 09:54:40 -0700492
Linus Torvalds1da177e2005-04-16 15:20:36 -0700493 case OID_GEN_DIRECTED_FRAMES_RCV:
494 DEBUG("%s: OID_GEN_DIRECTED_FRAMES_RCV\n", __FUNCTION__);
David Brownell340600a2005-04-28 13:45:25 -0700495 *outbuf = __constant_cpu_to_le32 (0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700496 retval = 0;
497 break;
David Brownell7e27f182006-06-13 09:54:40 -0700498
Linus Torvalds1da177e2005-04-16 15:20:36 -0700499 case OID_GEN_MULTICAST_BYTES_RCV:
500 DEBUG("%s: OID_GEN_MULTICAST_BYTES_RCV\n", __FUNCTION__);
501 if (rndis_per_dev_params [configNr].stats) {
David Brownell340600a2005-04-28 13:45:25 -0700502 *outbuf = cpu_to_le32 (rndis_per_dev_params [configNr]
Linus Torvalds1da177e2005-04-16 15:20:36 -0700503 .stats->multicast * 1111);
504 retval = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700505 }
506 break;
David Brownell7e27f182006-06-13 09:54:40 -0700507
Linus Torvalds1da177e2005-04-16 15:20:36 -0700508 case OID_GEN_MULTICAST_FRAMES_RCV:
509 DEBUG("%s: OID_GEN_MULTICAST_FRAMES_RCV\n", __FUNCTION__);
510 if (rndis_per_dev_params [configNr].stats) {
David Brownell340600a2005-04-28 13:45:25 -0700511 *outbuf = cpu_to_le32 (rndis_per_dev_params [configNr]
Linus Torvalds1da177e2005-04-16 15:20:36 -0700512 .stats->multicast);
513 retval = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700514 }
515 break;
David Brownell7e27f182006-06-13 09:54:40 -0700516
Linus Torvalds1da177e2005-04-16 15:20:36 -0700517 case OID_GEN_BROADCAST_BYTES_RCV:
518 DEBUG("%s: OID_GEN_BROADCAST_BYTES_RCV\n", __FUNCTION__);
519 if (rndis_per_dev_params [configNr].stats) {
David Brownell340600a2005-04-28 13:45:25 -0700520 *outbuf = cpu_to_le32 (rndis_per_dev_params [configNr]
Linus Torvalds1da177e2005-04-16 15:20:36 -0700521 .stats->rx_packets/42*255);
522 retval = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700523 }
524 break;
David Brownell7e27f182006-06-13 09:54:40 -0700525
Linus Torvalds1da177e2005-04-16 15:20:36 -0700526 case OID_GEN_BROADCAST_FRAMES_RCV:
527 DEBUG("%s: OID_GEN_BROADCAST_FRAMES_RCV\n", __FUNCTION__);
528 if (rndis_per_dev_params [configNr].stats) {
David Brownell340600a2005-04-28 13:45:25 -0700529 *outbuf = cpu_to_le32 (rndis_per_dev_params [configNr]
Linus Torvalds1da177e2005-04-16 15:20:36 -0700530 .stats->rx_packets/42);
531 retval = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700532 }
533 break;
David Brownell7e27f182006-06-13 09:54:40 -0700534
Linus Torvalds1da177e2005-04-16 15:20:36 -0700535 case OID_GEN_RCV_CRC_ERROR:
536 DEBUG("%s: OID_GEN_RCV_CRC_ERROR\n", __FUNCTION__);
537 if (rndis_per_dev_params [configNr].stats) {
David Brownell340600a2005-04-28 13:45:25 -0700538 *outbuf = cpu_to_le32 (rndis_per_dev_params [configNr]
Linus Torvalds1da177e2005-04-16 15:20:36 -0700539 .stats->rx_crc_errors);
540 retval = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700541 }
542 break;
David Brownell7e27f182006-06-13 09:54:40 -0700543
Linus Torvalds1da177e2005-04-16 15:20:36 -0700544 case OID_GEN_TRANSMIT_QUEUE_LENGTH:
545 DEBUG("%s: OID_GEN_TRANSMIT_QUEUE_LENGTH\n", __FUNCTION__);
David Brownell340600a2005-04-28 13:45:25 -0700546 *outbuf = __constant_cpu_to_le32 (0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700547 retval = 0;
548 break;
549#endif /* RNDIS_OPTIONAL_STATS */
550
551 /* ieee802.3 OIDs (table 4-3) */
552
553 /* mandatory */
554 case OID_802_3_PERMANENT_ADDRESS:
555 DEBUG("%s: OID_802_3_PERMANENT_ADDRESS\n", __FUNCTION__);
556 if (rndis_per_dev_params [configNr].dev) {
557 length = ETH_ALEN;
David Brownell340600a2005-04-28 13:45:25 -0700558 memcpy (outbuf,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700559 rndis_per_dev_params [configNr].host_mac,
560 length);
561 retval = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700562 }
563 break;
David Brownell7e27f182006-06-13 09:54:40 -0700564
Linus Torvalds1da177e2005-04-16 15:20:36 -0700565 /* mandatory */
566 case OID_802_3_CURRENT_ADDRESS:
567 DEBUG("%s: OID_802_3_CURRENT_ADDRESS\n", __FUNCTION__);
568 if (rndis_per_dev_params [configNr].dev) {
569 length = ETH_ALEN;
David Brownell340600a2005-04-28 13:45:25 -0700570 memcpy (outbuf,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700571 rndis_per_dev_params [configNr].host_mac,
572 length);
573 retval = 0;
574 }
575 break;
David Brownell7e27f182006-06-13 09:54:40 -0700576
Linus Torvalds1da177e2005-04-16 15:20:36 -0700577 /* mandatory */
578 case OID_802_3_MULTICAST_LIST:
579 DEBUG("%s: OID_802_3_MULTICAST_LIST\n", __FUNCTION__);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700580 /* Multicast base address only */
David Brownell340600a2005-04-28 13:45:25 -0700581 *outbuf = __constant_cpu_to_le32 (0xE0000000);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700582 retval = 0;
583 break;
David Brownell7e27f182006-06-13 09:54:40 -0700584
Linus Torvalds1da177e2005-04-16 15:20:36 -0700585 /* mandatory */
586 case OID_802_3_MAXIMUM_LIST_SIZE:
587 DEBUG("%s: OID_802_3_MAXIMUM_LIST_SIZE\n", __FUNCTION__);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700588 /* Multicast base address only */
David Brownell340600a2005-04-28 13:45:25 -0700589 *outbuf = __constant_cpu_to_le32 (1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700590 retval = 0;
591 break;
David Brownell7e27f182006-06-13 09:54:40 -0700592
Linus Torvalds1da177e2005-04-16 15:20:36 -0700593 case OID_802_3_MAC_OPTIONS:
594 DEBUG("%s: OID_802_3_MAC_OPTIONS\n", __FUNCTION__);
595 break;
596
597 /* ieee802.3 statistics OIDs (table 4-4) */
598
599 /* mandatory */
600 case OID_802_3_RCV_ERROR_ALIGNMENT:
601 DEBUG("%s: OID_802_3_RCV_ERROR_ALIGNMENT\n", __FUNCTION__);
David Brownell340600a2005-04-28 13:45:25 -0700602 if (rndis_per_dev_params [configNr].stats) {
603 *outbuf = cpu_to_le32 (rndis_per_dev_params [configNr]
Linus Torvalds1da177e2005-04-16 15:20:36 -0700604 .stats->rx_frame_errors);
605 retval = 0;
606 }
607 break;
David Brownell7e27f182006-06-13 09:54:40 -0700608
Linus Torvalds1da177e2005-04-16 15:20:36 -0700609 /* mandatory */
610 case OID_802_3_XMIT_ONE_COLLISION:
611 DEBUG("%s: OID_802_3_XMIT_ONE_COLLISION\n", __FUNCTION__);
David Brownell340600a2005-04-28 13:45:25 -0700612 *outbuf = __constant_cpu_to_le32 (0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700613 retval = 0;
614 break;
David Brownell7e27f182006-06-13 09:54:40 -0700615
Linus Torvalds1da177e2005-04-16 15:20:36 -0700616 /* mandatory */
617 case OID_802_3_XMIT_MORE_COLLISIONS:
618 DEBUG("%s: OID_802_3_XMIT_MORE_COLLISIONS\n", __FUNCTION__);
David Brownell340600a2005-04-28 13:45:25 -0700619 *outbuf = __constant_cpu_to_le32 (0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700620 retval = 0;
621 break;
David Brownell7e27f182006-06-13 09:54:40 -0700622
Linus Torvalds1da177e2005-04-16 15:20:36 -0700623#ifdef RNDIS_OPTIONAL_STATS
624 case OID_802_3_XMIT_DEFERRED:
625 DEBUG("%s: OID_802_3_XMIT_DEFERRED\n", __FUNCTION__);
626 /* TODO */
627 break;
David Brownell7e27f182006-06-13 09:54:40 -0700628
Linus Torvalds1da177e2005-04-16 15:20:36 -0700629 case OID_802_3_XMIT_MAX_COLLISIONS:
630 DEBUG("%s: OID_802_3_XMIT_MAX_COLLISIONS\n", __FUNCTION__);
631 /* TODO */
632 break;
David Brownell7e27f182006-06-13 09:54:40 -0700633
Linus Torvalds1da177e2005-04-16 15:20:36 -0700634 case OID_802_3_RCV_OVERRUN:
635 DEBUG("%s: OID_802_3_RCV_OVERRUN\n", __FUNCTION__);
636 /* TODO */
637 break;
David Brownell7e27f182006-06-13 09:54:40 -0700638
Linus Torvalds1da177e2005-04-16 15:20:36 -0700639 case OID_802_3_XMIT_UNDERRUN:
640 DEBUG("%s: OID_802_3_XMIT_UNDERRUN\n", __FUNCTION__);
641 /* TODO */
642 break;
David Brownell7e27f182006-06-13 09:54:40 -0700643
Linus Torvalds1da177e2005-04-16 15:20:36 -0700644 case OID_802_3_XMIT_HEARTBEAT_FAILURE:
645 DEBUG("%s: OID_802_3_XMIT_HEARTBEAT_FAILURE\n", __FUNCTION__);
646 /* TODO */
647 break;
David Brownell7e27f182006-06-13 09:54:40 -0700648
Linus Torvalds1da177e2005-04-16 15:20:36 -0700649 case OID_802_3_XMIT_TIMES_CRS_LOST:
650 DEBUG("%s: OID_802_3_XMIT_TIMES_CRS_LOST\n", __FUNCTION__);
651 /* TODO */
652 break;
David Brownell7e27f182006-06-13 09:54:40 -0700653
Linus Torvalds1da177e2005-04-16 15:20:36 -0700654 case OID_802_3_XMIT_LATE_COLLISIONS:
655 DEBUG("%s: OID_802_3_XMIT_LATE_COLLISIONS\n", __FUNCTION__);
656 /* TODO */
David Brownell7e27f182006-06-13 09:54:40 -0700657 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700658#endif /* RNDIS_OPTIONAL_STATS */
659
660#ifdef RNDIS_PM
661 /* power management OIDs (table 4-5) */
662 case OID_PNP_CAPABILITIES:
663 DEBUG("%s: OID_PNP_CAPABILITIES\n", __FUNCTION__);
664
David Brownell340600a2005-04-28 13:45:25 -0700665 /* for now, no wakeup capabilities */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700666 length = sizeof (struct NDIS_PNP_CAPABILITIES);
David Brownell340600a2005-04-28 13:45:25 -0700667 memset(outbuf, 0, length);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700668 retval = 0;
669 break;
670 case OID_PNP_QUERY_POWER:
David Brownell340600a2005-04-28 13:45:25 -0700671 DEBUG("%s: OID_PNP_QUERY_POWER D%d\n", __FUNCTION__,
David Brownell01ee7d72007-05-25 20:40:14 -0700672 le32_to_cpu(get_unaligned((__le32 *)buf)) - 1);
David Brownell340600a2005-04-28 13:45:25 -0700673 /* only suspend is a real power state, and
674 * it can't be entered by OID_PNP_SET_POWER...
675 */
676 length = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700677 retval = 0;
678 break;
679#endif
680
681 default:
David Brownell7e27f182006-06-13 09:54:40 -0700682 printk (KERN_WARNING "%s: query unknown OID 0x%08X\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700683 __FUNCTION__, OID);
684 }
David Brownell340600a2005-04-28 13:45:25 -0700685 if (retval < 0)
686 length = 0;
David Brownell7e27f182006-06-13 09:54:40 -0700687
Linus Torvalds1da177e2005-04-16 15:20:36 -0700688 resp->InformationBufferLength = cpu_to_le32 (length);
David Brownell340600a2005-04-28 13:45:25 -0700689 r->length = length + sizeof *resp;
690 resp->MessageLength = cpu_to_le32 (r->length);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700691 return retval;
692}
693
David Brownell7e27f182006-06-13 09:54:40 -0700694static int gen_ndis_set_resp (u8 configNr, u32 OID, u8 *buf, u32 buf_len,
695 rndis_resp_t *r)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700696{
697 rndis_set_cmplt_type *resp;
David Brownell7e27f182006-06-13 09:54:40 -0700698 int i, retval = -ENOTSUPP;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700699 struct rndis_params *params;
700
701 if (!r)
702 return -ENOMEM;
703 resp = (rndis_set_cmplt_type *) r->buf;
704 if (!resp)
705 return -ENOMEM;
706
David Brownell340600a2005-04-28 13:45:25 -0700707 if (buf_len && rndis_debug > 1) {
708 DEBUG("set OID %08x value, len %d:\n", OID, buf_len);
709 for (i = 0; i < buf_len; i += 16) {
710 DEBUG ("%03d: %08x %08x %08x %08x\n", i,
David Brownell01ee7d72007-05-25 20:40:14 -0700711 le32_to_cpu(get_unaligned((__le32 *)
712 &buf[i])),
713 le32_to_cpu(get_unaligned((__le32 *)
714 &buf[i + 4])),
715 le32_to_cpu(get_unaligned((__le32 *)
716 &buf[i + 8])),
717 le32_to_cpu(get_unaligned((__le32 *)
718 &buf[i + 12])));
David Brownell340600a2005-04-28 13:45:25 -0700719 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700720 }
721
David Brownell340600a2005-04-28 13:45:25 -0700722 params = &rndis_per_dev_params [configNr];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700723 switch (OID) {
724 case OID_GEN_CURRENT_PACKET_FILTER:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700725
David Brownell340600a2005-04-28 13:45:25 -0700726 /* these NDIS_PACKET_TYPE_* bitflags are shared with
727 * cdc_filter; it's not RNDIS-specific
Linus Torvalds1da177e2005-04-16 15:20:36 -0700728 * NDIS_PACKET_TYPE_x == USB_CDC_PACKET_TYPE_x for x in:
729 * PROMISCUOUS, DIRECTED,
730 * MULTICAST, ALL_MULTICAST, BROADCAST
731 */
David Brownell01ee7d72007-05-25 20:40:14 -0700732 *params->filter = (u16) le32_to_cpu(get_unaligned(
733 (__le32 *)buf));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700734 DEBUG("%s: OID_GEN_CURRENT_PACKET_FILTER %08x\n",
David Brownell340600a2005-04-28 13:45:25 -0700735 __FUNCTION__, *params->filter);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700736
737 /* this call has a significant side effect: it's
738 * what makes the packet flow start and stop, like
739 * activating the CDC Ethernet altsetting.
740 */
David Brownell340600a2005-04-28 13:45:25 -0700741#ifdef RNDIS_PM
742update_linkstate:
743#endif
744 retval = 0;
745 if (*params->filter) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700746 params->state = RNDIS_DATA_INITIALIZED;
747 netif_carrier_on(params->dev);
748 if (netif_running(params->dev))
749 netif_wake_queue (params->dev);
750 } else {
751 params->state = RNDIS_INITIALIZED;
752 netif_carrier_off (params->dev);
753 netif_stop_queue (params->dev);
754 }
755 break;
David Brownell7e27f182006-06-13 09:54:40 -0700756
Linus Torvalds1da177e2005-04-16 15:20:36 -0700757 case OID_802_3_MULTICAST_LIST:
David Brownell7e27f182006-06-13 09:54:40 -0700758 /* I think we can ignore this */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700759 DEBUG("%s: OID_802_3_MULTICAST_LIST\n", __FUNCTION__);
760 retval = 0;
761 break;
762#if 0
763 case OID_GEN_RNDIS_CONFIG_PARAMETER:
764 {
765 struct rndis_config_parameter *param;
766 param = (struct rndis_config_parameter *) buf;
767 DEBUG("%s: OID_GEN_RNDIS_CONFIG_PARAMETER '%*s'\n",
768 __FUNCTION__,
769 min(cpu_to_le32(param->ParameterNameLength),80),
770 buf + param->ParameterNameOffset);
771 retval = 0;
772 }
773 break;
774#endif
775
776#ifdef RNDIS_PM
777 case OID_PNP_SET_POWER:
David Brownell340600a2005-04-28 13:45:25 -0700778 /* The only real power state is USB suspend, and RNDIS requests
779 * can't enter it; this one isn't really about power. After
780 * resuming, Windows forces a reset, and then SET_POWER D0.
781 * FIXME ... then things go batty; Windows wedges itself.
782 */
David Brownell01ee7d72007-05-25 20:40:14 -0700783 i = le32_to_cpu(get_unaligned((__le32 *)buf));
David Brownell340600a2005-04-28 13:45:25 -0700784 DEBUG("%s: OID_PNP_SET_POWER D%d\n", __FUNCTION__, i - 1);
785 switch (i) {
786 case NdisDeviceStateD0:
787 *params->filter = params->saved_filter;
788 goto update_linkstate;
789 case NdisDeviceStateD3:
790 case NdisDeviceStateD2:
791 case NdisDeviceStateD1:
792 params->saved_filter = *params->filter;
793 retval = 0;
794 break;
795 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700796 break;
797
David Brownell340600a2005-04-28 13:45:25 -0700798#ifdef RNDIS_WAKEUP
799 // no wakeup support advertised, so wakeup OIDs always fail:
800 // - OID_PNP_ENABLE_WAKE_UP
801 // - OID_PNP_{ADD,REMOVE}_WAKE_UP_PATTERN
Linus Torvalds1da177e2005-04-16 15:20:36 -0700802#endif
803
David Brownell340600a2005-04-28 13:45:25 -0700804#endif /* RNDIS_PM */
805
Linus Torvalds1da177e2005-04-16 15:20:36 -0700806 default:
David Brownell7e27f182006-06-13 09:54:40 -0700807 printk (KERN_WARNING "%s: set unknown OID 0x%08X, size %d\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700808 __FUNCTION__, OID, buf_len);
809 }
David Brownell7e27f182006-06-13 09:54:40 -0700810
Linus Torvalds1da177e2005-04-16 15:20:36 -0700811 return retval;
812}
813
David Brownell7e27f182006-06-13 09:54:40 -0700814/*
815 * Response Functions
Linus Torvalds1da177e2005-04-16 15:20:36 -0700816 */
817
818static int rndis_init_response (int configNr, rndis_init_msg_type *buf)
819{
David Brownell7e27f182006-06-13 09:54:40 -0700820 rndis_init_cmplt_type *resp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700821 rndis_resp_t *r;
David Brownell7e27f182006-06-13 09:54:40 -0700822
Linus Torvalds1da177e2005-04-16 15:20:36 -0700823 if (!rndis_per_dev_params [configNr].dev) return -ENOTSUPP;
David Brownell7e27f182006-06-13 09:54:40 -0700824
Linus Torvalds1da177e2005-04-16 15:20:36 -0700825 r = rndis_add_response (configNr, sizeof (rndis_init_cmplt_type));
David Brownell340600a2005-04-28 13:45:25 -0700826 if (!r)
827 return -ENOMEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700828 resp = (rndis_init_cmplt_type *) r->buf;
David Brownell7e27f182006-06-13 09:54:40 -0700829
Linus Torvalds1da177e2005-04-16 15:20:36 -0700830 resp->MessageType = __constant_cpu_to_le32 (
831 REMOTE_NDIS_INITIALIZE_CMPLT);
832 resp->MessageLength = __constant_cpu_to_le32 (52);
833 resp->RequestID = buf->RequestID; /* Still LE in msg buffer */
834 resp->Status = __constant_cpu_to_le32 (RNDIS_STATUS_SUCCESS);
835 resp->MajorVersion = __constant_cpu_to_le32 (RNDIS_MAJOR_VERSION);
836 resp->MinorVersion = __constant_cpu_to_le32 (RNDIS_MINOR_VERSION);
837 resp->DeviceFlags = __constant_cpu_to_le32 (RNDIS_DF_CONNECTIONLESS);
838 resp->Medium = __constant_cpu_to_le32 (RNDIS_MEDIUM_802_3);
839 resp->MaxPacketsPerTransfer = __constant_cpu_to_le32 (1);
840 resp->MaxTransferSize = cpu_to_le32 (
841 rndis_per_dev_params [configNr].dev->mtu
842 + sizeof (struct ethhdr)
843 + sizeof (struct rndis_packet_msg_type)
844 + 22);
845 resp->PacketAlignmentFactor = __constant_cpu_to_le32 (0);
846 resp->AFListOffset = __constant_cpu_to_le32 (0);
847 resp->AFListSize = __constant_cpu_to_le32 (0);
David Brownell7e27f182006-06-13 09:54:40 -0700848
Linus Torvalds1da177e2005-04-16 15:20:36 -0700849 if (rndis_per_dev_params [configNr].ack)
David Brownell7e27f182006-06-13 09:54:40 -0700850 rndis_per_dev_params [configNr].ack (
851 rndis_per_dev_params [configNr].dev);
852
Linus Torvalds1da177e2005-04-16 15:20:36 -0700853 return 0;
854}
855
856static int rndis_query_response (int configNr, rndis_query_msg_type *buf)
857{
858 rndis_query_cmplt_type *resp;
859 rndis_resp_t *r;
David Brownell7e27f182006-06-13 09:54:40 -0700860
Linus Torvalds1da177e2005-04-16 15:20:36 -0700861 // DEBUG("%s: OID = %08X\n", __FUNCTION__, cpu_to_le32(buf->OID));
862 if (!rndis_per_dev_params [configNr].dev) return -ENOTSUPP;
David Brownell7e27f182006-06-13 09:54:40 -0700863
Shaun Tancheff87637162006-02-22 19:47:19 -0800864 /*
865 * we need more memory:
866 * gen_ndis_query_resp expects enough space for
867 * rndis_query_cmplt_type followed by data.
868 * oid_supported_list is the largest data reply
Linus Torvalds1da177e2005-04-16 15:20:36 -0700869 */
Shaun Tancheff87637162006-02-22 19:47:19 -0800870 r = rndis_add_response (configNr,
871 sizeof (oid_supported_list) + sizeof(rndis_query_cmplt_type));
David Brownell340600a2005-04-28 13:45:25 -0700872 if (!r)
873 return -ENOMEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700874 resp = (rndis_query_cmplt_type *) r->buf;
David Brownell7e27f182006-06-13 09:54:40 -0700875
Linus Torvalds1da177e2005-04-16 15:20:36 -0700876 resp->MessageType = __constant_cpu_to_le32 (REMOTE_NDIS_QUERY_CMPLT);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700877 resp->RequestID = buf->RequestID; /* Still LE in msg buffer */
David Brownell7e27f182006-06-13 09:54:40 -0700878
David Brownell340600a2005-04-28 13:45:25 -0700879 if (gen_ndis_query_resp (configNr, le32_to_cpu (buf->OID),
880 le32_to_cpu(buf->InformationBufferOffset)
881 + 8 + (u8 *) buf,
882 le32_to_cpu(buf->InformationBufferLength),
883 r)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700884 /* OID not supported */
885 resp->Status = __constant_cpu_to_le32 (
886 RNDIS_STATUS_NOT_SUPPORTED);
David Brownell340600a2005-04-28 13:45:25 -0700887 resp->MessageLength = __constant_cpu_to_le32 (sizeof *resp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700888 resp->InformationBufferLength = __constant_cpu_to_le32 (0);
889 resp->InformationBufferOffset = __constant_cpu_to_le32 (0);
890 } else
891 resp->Status = __constant_cpu_to_le32 (RNDIS_STATUS_SUCCESS);
David Brownell7e27f182006-06-13 09:54:40 -0700892
Linus Torvalds1da177e2005-04-16 15:20:36 -0700893 if (rndis_per_dev_params [configNr].ack)
David Brownell7e27f182006-06-13 09:54:40 -0700894 rndis_per_dev_params [configNr].ack (
895 rndis_per_dev_params [configNr].dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700896 return 0;
897}
898
899static int rndis_set_response (int configNr, rndis_set_msg_type *buf)
900{
901 u32 BufLength, BufOffset;
902 rndis_set_cmplt_type *resp;
903 rndis_resp_t *r;
David Brownell7e27f182006-06-13 09:54:40 -0700904
Linus Torvalds1da177e2005-04-16 15:20:36 -0700905 r = rndis_add_response (configNr, sizeof (rndis_set_cmplt_type));
David Brownell340600a2005-04-28 13:45:25 -0700906 if (!r)
907 return -ENOMEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700908 resp = (rndis_set_cmplt_type *) r->buf;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700909
910 BufLength = le32_to_cpu (buf->InformationBufferLength);
911 BufOffset = le32_to_cpu (buf->InformationBufferOffset);
912
913#ifdef VERBOSE
914 DEBUG("%s: Length: %d\n", __FUNCTION__, BufLength);
915 DEBUG("%s: Offset: %d\n", __FUNCTION__, BufOffset);
916 DEBUG("%s: InfoBuffer: ", __FUNCTION__);
David Brownell7e27f182006-06-13 09:54:40 -0700917
Linus Torvalds1da177e2005-04-16 15:20:36 -0700918 for (i = 0; i < BufLength; i++) {
919 DEBUG ("%02x ", *(((u8 *) buf) + i + 8 + BufOffset));
920 }
David Brownell7e27f182006-06-13 09:54:40 -0700921
Linus Torvalds1da177e2005-04-16 15:20:36 -0700922 DEBUG ("\n");
923#endif
David Brownell7e27f182006-06-13 09:54:40 -0700924
Linus Torvalds1da177e2005-04-16 15:20:36 -0700925 resp->MessageType = __constant_cpu_to_le32 (REMOTE_NDIS_SET_CMPLT);
926 resp->MessageLength = __constant_cpu_to_le32 (16);
927 resp->RequestID = buf->RequestID; /* Still LE in msg buffer */
David Brownell7e27f182006-06-13 09:54:40 -0700928 if (gen_ndis_set_resp (configNr, le32_to_cpu (buf->OID),
929 ((u8 *) buf) + 8 + BufOffset, BufLength, r))
930 resp->Status = __constant_cpu_to_le32 (RNDIS_STATUS_NOT_SUPPORTED);
931 else
932 resp->Status = __constant_cpu_to_le32 (RNDIS_STATUS_SUCCESS);
933
Linus Torvalds1da177e2005-04-16 15:20:36 -0700934 if (rndis_per_dev_params [configNr].ack)
David Brownell7e27f182006-06-13 09:54:40 -0700935 rndis_per_dev_params [configNr].ack (
936 rndis_per_dev_params [configNr].dev);
937
Linus Torvalds1da177e2005-04-16 15:20:36 -0700938 return 0;
939}
940
941static int rndis_reset_response (int configNr, rndis_reset_msg_type *buf)
942{
943 rndis_reset_cmplt_type *resp;
944 rndis_resp_t *r;
David Brownell7e27f182006-06-13 09:54:40 -0700945
Linus Torvalds1da177e2005-04-16 15:20:36 -0700946 r = rndis_add_response (configNr, sizeof (rndis_reset_cmplt_type));
David Brownell340600a2005-04-28 13:45:25 -0700947 if (!r)
948 return -ENOMEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700949 resp = (rndis_reset_cmplt_type *) r->buf;
David Brownell7e27f182006-06-13 09:54:40 -0700950
Linus Torvalds1da177e2005-04-16 15:20:36 -0700951 resp->MessageType = __constant_cpu_to_le32 (REMOTE_NDIS_RESET_CMPLT);
952 resp->MessageLength = __constant_cpu_to_le32 (16);
953 resp->Status = __constant_cpu_to_le32 (RNDIS_STATUS_SUCCESS);
954 /* resent information */
955 resp->AddressingReset = __constant_cpu_to_le32 (1);
David Brownell7e27f182006-06-13 09:54:40 -0700956
Linus Torvalds1da177e2005-04-16 15:20:36 -0700957 if (rndis_per_dev_params [configNr].ack)
David Brownell7e27f182006-06-13 09:54:40 -0700958 rndis_per_dev_params [configNr].ack (
959 rndis_per_dev_params [configNr].dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700960
961 return 0;
962}
963
964static int rndis_keepalive_response (int configNr,
David Brownell7e27f182006-06-13 09:54:40 -0700965 rndis_keepalive_msg_type *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700966{
967 rndis_keepalive_cmplt_type *resp;
968 rndis_resp_t *r;
969
970 /* host "should" check only in RNDIS_DATA_INITIALIZED state */
971
972 r = rndis_add_response (configNr, sizeof (rndis_keepalive_cmplt_type));
David Brownell340600a2005-04-28 13:45:25 -0700973 if (!r)
974 return -ENOMEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700975 resp = (rndis_keepalive_cmplt_type *) r->buf;
David Brownell7e27f182006-06-13 09:54:40 -0700976
Linus Torvalds1da177e2005-04-16 15:20:36 -0700977 resp->MessageType = __constant_cpu_to_le32 (
978 REMOTE_NDIS_KEEPALIVE_CMPLT);
979 resp->MessageLength = __constant_cpu_to_le32 (16);
980 resp->RequestID = buf->RequestID; /* Still LE in msg buffer */
981 resp->Status = __constant_cpu_to_le32 (RNDIS_STATUS_SUCCESS);
David Brownell7e27f182006-06-13 09:54:40 -0700982
Linus Torvalds1da177e2005-04-16 15:20:36 -0700983 if (rndis_per_dev_params [configNr].ack)
David Brownell7e27f182006-06-13 09:54:40 -0700984 rndis_per_dev_params [configNr].ack (
985 rndis_per_dev_params [configNr].dev);
986
Linus Torvalds1da177e2005-04-16 15:20:36 -0700987 return 0;
988}
989
990
David Brownell7e27f182006-06-13 09:54:40 -0700991/*
992 * Device to Host Comunication
Linus Torvalds1da177e2005-04-16 15:20:36 -0700993 */
994static int rndis_indicate_status_msg (int configNr, u32 status)
995{
David Brownell7e27f182006-06-13 09:54:40 -0700996 rndis_indicate_status_msg_type *resp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700997 rndis_resp_t *r;
David Brownell7e27f182006-06-13 09:54:40 -0700998
Linus Torvalds1da177e2005-04-16 15:20:36 -0700999 if (rndis_per_dev_params [configNr].state == RNDIS_UNINITIALIZED)
David Brownell7e27f182006-06-13 09:54:40 -07001000 return -ENOTSUPP;
1001
1002 r = rndis_add_response (configNr,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001003 sizeof (rndis_indicate_status_msg_type));
David Brownell340600a2005-04-28 13:45:25 -07001004 if (!r)
1005 return -ENOMEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001006 resp = (rndis_indicate_status_msg_type *) r->buf;
David Brownell7e27f182006-06-13 09:54:40 -07001007
Linus Torvalds1da177e2005-04-16 15:20:36 -07001008 resp->MessageType = __constant_cpu_to_le32 (
1009 REMOTE_NDIS_INDICATE_STATUS_MSG);
1010 resp->MessageLength = __constant_cpu_to_le32 (20);
1011 resp->Status = cpu_to_le32 (status);
1012 resp->StatusBufferLength = __constant_cpu_to_le32 (0);
1013 resp->StatusBufferOffset = __constant_cpu_to_le32 (0);
David Brownell7e27f182006-06-13 09:54:40 -07001014
1015 if (rndis_per_dev_params [configNr].ack)
1016 rndis_per_dev_params [configNr].ack (
1017 rndis_per_dev_params [configNr].dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001018 return 0;
1019}
1020
1021int rndis_signal_connect (int configNr)
1022{
1023 rndis_per_dev_params [configNr].media_state
1024 = NDIS_MEDIA_STATE_CONNECTED;
David Brownell7e27f182006-06-13 09:54:40 -07001025 return rndis_indicate_status_msg (configNr,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001026 RNDIS_STATUS_MEDIA_CONNECT);
1027}
1028
1029int rndis_signal_disconnect (int configNr)
1030{
1031 rndis_per_dev_params [configNr].media_state
1032 = NDIS_MEDIA_STATE_DISCONNECTED;
1033 return rndis_indicate_status_msg (configNr,
1034 RNDIS_STATUS_MEDIA_DISCONNECT);
1035}
1036
David Brownell340600a2005-04-28 13:45:25 -07001037void rndis_uninit (int configNr)
1038{
David Brownell486e2df2005-05-24 17:51:52 -07001039 u8 *buf;
1040 u32 length;
1041
David Brownell340600a2005-04-28 13:45:25 -07001042 if (configNr >= RNDIS_MAX_CONFIGS)
1043 return;
1044 rndis_per_dev_params [configNr].used = 0;
1045 rndis_per_dev_params [configNr].state = RNDIS_UNINITIALIZED;
David Brownell486e2df2005-05-24 17:51:52 -07001046
1047 /* drain the response queue */
1048 while ((buf = rndis_get_next_response(configNr, &length)))
1049 rndis_free_response(configNr, buf);
David Brownell340600a2005-04-28 13:45:25 -07001050}
1051
Linus Torvalds1da177e2005-04-16 15:20:36 -07001052void rndis_set_host_mac (int configNr, const u8 *addr)
1053{
1054 rndis_per_dev_params [configNr].host_mac = addr;
1055}
1056
David Brownell7e27f182006-06-13 09:54:40 -07001057/*
1058 * Message Parser
Linus Torvalds1da177e2005-04-16 15:20:36 -07001059 */
1060int rndis_msg_parser (u8 configNr, u8 *buf)
1061{
1062 u32 MsgType, MsgLength;
1063 __le32 *tmp;
1064 struct rndis_params *params;
David Brownell7e27f182006-06-13 09:54:40 -07001065
Linus Torvalds1da177e2005-04-16 15:20:36 -07001066 if (!buf)
1067 return -ENOMEM;
David Brownell7e27f182006-06-13 09:54:40 -07001068
1069 tmp = (__le32 *) buf;
David Brownell01ee7d72007-05-25 20:40:14 -07001070 MsgType = le32_to_cpu(get_unaligned(tmp++));
1071 MsgLength = le32_to_cpu(get_unaligned(tmp++));
David Brownell7e27f182006-06-13 09:54:40 -07001072
Linus Torvalds1da177e2005-04-16 15:20:36 -07001073 if (configNr >= RNDIS_MAX_CONFIGS)
1074 return -ENOTSUPP;
1075 params = &rndis_per_dev_params [configNr];
David Brownell7e27f182006-06-13 09:54:40 -07001076
David Brownell340600a2005-04-28 13:45:25 -07001077 /* NOTE: RNDIS is *EXTREMELY* chatty ... Windows constantly polls for
1078 * rx/tx statistics and link status, in addition to KEEPALIVE traffic
1079 * and normal HC level polling to see if there's any IN traffic.
1080 */
1081
Linus Torvalds1da177e2005-04-16 15:20:36 -07001082 /* For USB: responses may take up to 10 seconds */
David Brownell340600a2005-04-28 13:45:25 -07001083 switch (MsgType) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001084 case REMOTE_NDIS_INITIALIZE_MSG:
David Brownell7e27f182006-06-13 09:54:40 -07001085 DEBUG("%s: REMOTE_NDIS_INITIALIZE_MSG\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07001086 __FUNCTION__ );
1087 params->state = RNDIS_INITIALIZED;
1088 return rndis_init_response (configNr,
David Brownell7e27f182006-06-13 09:54:40 -07001089 (rndis_init_msg_type *) buf);
1090
Linus Torvalds1da177e2005-04-16 15:20:36 -07001091 case REMOTE_NDIS_HALT_MSG:
1092 DEBUG("%s: REMOTE_NDIS_HALT_MSG\n",
1093 __FUNCTION__ );
1094 params->state = RNDIS_UNINITIALIZED;
1095 if (params->dev) {
1096 netif_carrier_off (params->dev);
1097 netif_stop_queue (params->dev);
1098 }
1099 return 0;
David Brownell7e27f182006-06-13 09:54:40 -07001100
Linus Torvalds1da177e2005-04-16 15:20:36 -07001101 case REMOTE_NDIS_QUERY_MSG:
David Brownell7e27f182006-06-13 09:54:40 -07001102 return rndis_query_response (configNr,
1103 (rndis_query_msg_type *) buf);
1104
Linus Torvalds1da177e2005-04-16 15:20:36 -07001105 case REMOTE_NDIS_SET_MSG:
David Brownell7e27f182006-06-13 09:54:40 -07001106 return rndis_set_response (configNr,
1107 (rndis_set_msg_type *) buf);
1108
Linus Torvalds1da177e2005-04-16 15:20:36 -07001109 case REMOTE_NDIS_RESET_MSG:
David Brownell7e27f182006-06-13 09:54:40 -07001110 DEBUG("%s: REMOTE_NDIS_RESET_MSG\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07001111 __FUNCTION__ );
1112 return rndis_reset_response (configNr,
David Brownell7e27f182006-06-13 09:54:40 -07001113 (rndis_reset_msg_type *) buf);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001114
1115 case REMOTE_NDIS_KEEPALIVE_MSG:
1116 /* For USB: host does this every 5 seconds */
David Brownell340600a2005-04-28 13:45:25 -07001117 if (rndis_debug > 1)
David Brownell7e27f182006-06-13 09:54:40 -07001118 DEBUG("%s: REMOTE_NDIS_KEEPALIVE_MSG\n",
David Brownell340600a2005-04-28 13:45:25 -07001119 __FUNCTION__ );
Linus Torvalds1da177e2005-04-16 15:20:36 -07001120 return rndis_keepalive_response (configNr,
David Brownell7e27f182006-06-13 09:54:40 -07001121 (rndis_keepalive_msg_type *)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001122 buf);
David Brownell7e27f182006-06-13 09:54:40 -07001123
1124 default:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001125 /* At least Windows XP emits some undefined RNDIS messages.
1126 * In one case those messages seemed to relate to the host
1127 * suspending itself.
1128 */
1129 printk (KERN_WARNING
David Brownell7e27f182006-06-13 09:54:40 -07001130 "%s: unknown RNDIS message 0x%08X len %d\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07001131 __FUNCTION__ , MsgType, MsgLength);
1132 {
1133 unsigned i;
1134 for (i = 0; i < MsgLength; i += 16) {
1135 DEBUG ("%03d: "
1136 " %02x %02x %02x %02x"
1137 " %02x %02x %02x %02x"
1138 " %02x %02x %02x %02x"
1139 " %02x %02x %02x %02x"
1140 "\n",
1141 i,
1142 buf[i], buf [i+1],
1143 buf[i+2], buf[i+3],
1144 buf[i+4], buf [i+5],
1145 buf[i+6], buf[i+7],
1146 buf[i+8], buf [i+9],
1147 buf[i+10], buf[i+11],
1148 buf[i+12], buf [i+13],
1149 buf[i+14], buf[i+15]);
1150 }
1151 }
1152 break;
1153 }
David Brownell7e27f182006-06-13 09:54:40 -07001154
Linus Torvalds1da177e2005-04-16 15:20:36 -07001155 return -ENOTSUPP;
1156}
1157
1158int rndis_register (int (* rndis_control_ack) (struct net_device *))
1159{
1160 u8 i;
David Brownell7e27f182006-06-13 09:54:40 -07001161
Linus Torvalds1da177e2005-04-16 15:20:36 -07001162 for (i = 0; i < RNDIS_MAX_CONFIGS; i++) {
1163 if (!rndis_per_dev_params [i].used) {
1164 rndis_per_dev_params [i].used = 1;
1165 rndis_per_dev_params [i].ack = rndis_control_ack;
1166 DEBUG("%s: configNr = %d\n", __FUNCTION__, i);
1167 return i;
1168 }
1169 }
1170 DEBUG("failed\n");
David Brownell7e27f182006-06-13 09:54:40 -07001171
Linus Torvalds1da177e2005-04-16 15:20:36 -07001172 return -1;
1173}
1174
1175void rndis_deregister (int configNr)
1176{
1177 DEBUG("%s: \n", __FUNCTION__ );
David Brownell7e27f182006-06-13 09:54:40 -07001178
Linus Torvalds1da177e2005-04-16 15:20:36 -07001179 if (configNr >= RNDIS_MAX_CONFIGS) return;
1180 rndis_per_dev_params [configNr].used = 0;
David Brownell7e27f182006-06-13 09:54:40 -07001181
Linus Torvalds1da177e2005-04-16 15:20:36 -07001182 return;
1183}
1184
David Brownell7e27f182006-06-13 09:54:40 -07001185int rndis_set_param_dev (u8 configNr, struct net_device *dev,
David Brownell340600a2005-04-28 13:45:25 -07001186 struct net_device_stats *stats,
1187 u16 *cdc_filter)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001188{
1189 DEBUG("%s:\n", __FUNCTION__ );
1190 if (!dev || !stats) return -1;
1191 if (configNr >= RNDIS_MAX_CONFIGS) return -1;
David Brownell7e27f182006-06-13 09:54:40 -07001192
Linus Torvalds1da177e2005-04-16 15:20:36 -07001193 rndis_per_dev_params [configNr].dev = dev;
1194 rndis_per_dev_params [configNr].stats = stats;
David Brownell340600a2005-04-28 13:45:25 -07001195 rndis_per_dev_params [configNr].filter = cdc_filter;
David Brownell7e27f182006-06-13 09:54:40 -07001196
Linus Torvalds1da177e2005-04-16 15:20:36 -07001197 return 0;
1198}
1199
1200int rndis_set_param_vendor (u8 configNr, u32 vendorID, const char *vendorDescr)
1201{
1202 DEBUG("%s:\n", __FUNCTION__ );
1203 if (!vendorDescr) return -1;
1204 if (configNr >= RNDIS_MAX_CONFIGS) return -1;
David Brownell7e27f182006-06-13 09:54:40 -07001205
Linus Torvalds1da177e2005-04-16 15:20:36 -07001206 rndis_per_dev_params [configNr].vendorID = vendorID;
1207 rndis_per_dev_params [configNr].vendorDescr = vendorDescr;
David Brownell7e27f182006-06-13 09:54:40 -07001208
Linus Torvalds1da177e2005-04-16 15:20:36 -07001209 return 0;
1210}
1211
1212int rndis_set_param_medium (u8 configNr, u32 medium, u32 speed)
1213{
David Brownell340600a2005-04-28 13:45:25 -07001214 DEBUG("%s: %u %u\n", __FUNCTION__, medium, speed);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001215 if (configNr >= RNDIS_MAX_CONFIGS) return -1;
David Brownell7e27f182006-06-13 09:54:40 -07001216
Linus Torvalds1da177e2005-04-16 15:20:36 -07001217 rndis_per_dev_params [configNr].medium = medium;
1218 rndis_per_dev_params [configNr].speed = speed;
David Brownell7e27f182006-06-13 09:54:40 -07001219
Linus Torvalds1da177e2005-04-16 15:20:36 -07001220 return 0;
1221}
1222
1223void rndis_add_hdr (struct sk_buff *skb)
1224{
1225 struct rndis_packet_msg_type *header;
1226
1227 if (!skb)
1228 return;
1229 header = (void *) skb_push (skb, sizeof *header);
1230 memset (header, 0, sizeof *header);
David Brownell6cdee102005-04-18 17:39:34 -07001231 header->MessageType = __constant_cpu_to_le32(REMOTE_NDIS_PACKET_MSG);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001232 header->MessageLength = cpu_to_le32(skb->len);
1233 header->DataOffset = __constant_cpu_to_le32 (36);
David Brownell6cdee102005-04-18 17:39:34 -07001234 header->DataLength = cpu_to_le32(skb->len - sizeof *header);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001235}
1236
1237void rndis_free_response (int configNr, u8 *buf)
1238{
1239 rndis_resp_t *r;
1240 struct list_head *act, *tmp;
David Brownell7e27f182006-06-13 09:54:40 -07001241
1242 list_for_each_safe (act, tmp,
1243 &(rndis_per_dev_params [configNr].resp_queue))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001244 {
1245 r = list_entry (act, rndis_resp_t, list);
1246 if (r && r->buf == buf) {
1247 list_del (&r->list);
1248 kfree (r);
1249 }
1250 }
1251}
1252
1253u8 *rndis_get_next_response (int configNr, u32 *length)
1254{
1255 rndis_resp_t *r;
David Brownell7e27f182006-06-13 09:54:40 -07001256 struct list_head *act, *tmp;
1257
Linus Torvalds1da177e2005-04-16 15:20:36 -07001258 if (!length) return NULL;
David Brownell7e27f182006-06-13 09:54:40 -07001259
1260 list_for_each_safe (act, tmp,
1261 &(rndis_per_dev_params [configNr].resp_queue))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001262 {
1263 r = list_entry (act, rndis_resp_t, list);
1264 if (!r->send) {
1265 r->send = 1;
1266 *length = r->length;
1267 return r->buf;
1268 }
1269 }
David Brownell7e27f182006-06-13 09:54:40 -07001270
Linus Torvalds1da177e2005-04-16 15:20:36 -07001271 return NULL;
1272}
1273
1274static rndis_resp_t *rndis_add_response (int configNr, u32 length)
1275{
1276 rndis_resp_t *r;
David Brownell7e27f182006-06-13 09:54:40 -07001277
David Brownell340600a2005-04-28 13:45:25 -07001278 /* NOTE: this gets copied into ether.c USB_BUFSIZ bytes ... */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001279 r = kmalloc (sizeof (rndis_resp_t) + length, GFP_ATOMIC);
1280 if (!r) return NULL;
David Brownell7e27f182006-06-13 09:54:40 -07001281
Linus Torvalds1da177e2005-04-16 15:20:36 -07001282 r->buf = (u8 *) (r + 1);
1283 r->length = length;
1284 r->send = 0;
David Brownell7e27f182006-06-13 09:54:40 -07001285
1286 list_add_tail (&r->list,
1287 &(rndis_per_dev_params [configNr].resp_queue));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001288 return r;
1289}
1290
David Brownell6cdee102005-04-18 17:39:34 -07001291int rndis_rm_hdr(struct sk_buff *skb)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001292{
David Brownell6cdee102005-04-18 17:39:34 -07001293 /* tmp points to a struct rndis_packet_msg_type */
1294 __le32 *tmp = (void *) skb->data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001295
David Brownell6cdee102005-04-18 17:39:34 -07001296 /* MessageType, MessageLength */
1297 if (__constant_cpu_to_le32(REMOTE_NDIS_PACKET_MSG)
1298 != get_unaligned(tmp++))
1299 return -EINVAL;
1300 tmp++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001301
David Brownell6cdee102005-04-18 17:39:34 -07001302 /* DataOffset, DataLength */
1303 if (!skb_pull(skb, le32_to_cpu(get_unaligned(tmp++))
1304 + 8 /* offset of DataOffset */))
1305 return -EOVERFLOW;
1306 skb_trim(skb, le32_to_cpu(get_unaligned(tmp++)));
1307
Linus Torvalds1da177e2005-04-16 15:20:36 -07001308 return 0;
1309}
1310
1311#ifdef CONFIG_USB_GADGET_DEBUG_FILES
1312
David Brownell7e27f182006-06-13 09:54:40 -07001313static int rndis_proc_read (char *page, char **start, off_t off, int count, int *eof,
1314 void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001315{
1316 char *out = page;
1317 int len;
1318 rndis_params *param = (rndis_params *) data;
David Brownell7e27f182006-06-13 09:54:40 -07001319
1320 out += snprintf (out, count,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001321 "Config Nr. %d\n"
1322 "used : %s\n"
1323 "state : %s\n"
1324 "medium : 0x%08X\n"
1325 "speed : %d\n"
1326 "cable : %s\n"
1327 "vendor ID : 0x%08X\n"
David Brownell7e27f182006-06-13 09:54:40 -07001328 "vendor : %s\n",
1329 param->confignr, (param->used) ? "y" : "n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07001330 ({ char *s = "?";
1331 switch (param->state) {
1332 case RNDIS_UNINITIALIZED:
1333 s = "RNDIS_UNINITIALIZED"; break;
1334 case RNDIS_INITIALIZED:
1335 s = "RNDIS_INITIALIZED"; break;
1336 case RNDIS_DATA_INITIALIZED:
1337 s = "RNDIS_DATA_INITIALIZED"; break;
1338 }; s; }),
David Brownell7e27f182006-06-13 09:54:40 -07001339 param->medium,
1340 (param->media_state) ? 0 : param->speed*100,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001341 (param->media_state) ? "disconnected" : "connected",
David Brownell7e27f182006-06-13 09:54:40 -07001342 param->vendorID, param->vendorDescr);
1343
Linus Torvalds1da177e2005-04-16 15:20:36 -07001344 len = out - page;
1345 len -= off;
David Brownell7e27f182006-06-13 09:54:40 -07001346
Linus Torvalds1da177e2005-04-16 15:20:36 -07001347 if (len < count) {
1348 *eof = 1;
1349 if (len <= 0)
1350 return 0;
1351 } else
1352 len = count;
David Brownell7e27f182006-06-13 09:54:40 -07001353
Linus Torvalds1da177e2005-04-16 15:20:36 -07001354 *start = page + off;
1355 return len;
1356}
1357
David Brownell7e27f182006-06-13 09:54:40 -07001358static int rndis_proc_write (struct file *file, const char __user *buffer,
1359 unsigned long count, void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001360{
1361 rndis_params *p = data;
1362 u32 speed = 0;
1363 int i, fl_speed = 0;
David Brownell7e27f182006-06-13 09:54:40 -07001364
Linus Torvalds1da177e2005-04-16 15:20:36 -07001365 for (i = 0; i < count; i++) {
1366 char c;
1367 if (get_user(c, buffer))
1368 return -EFAULT;
1369 switch (c) {
1370 case '0':
1371 case '1':
1372 case '2':
1373 case '3':
1374 case '4':
1375 case '5':
1376 case '6':
1377 case '7':
1378 case '8':
1379 case '9':
1380 fl_speed = 1;
1381 speed = speed*10 + c - '0';
1382 break;
1383 case 'C':
1384 case 'c':
1385 rndis_signal_connect (p->confignr);
1386 break;
1387 case 'D':
1388 case 'd':
1389 rndis_signal_disconnect(p->confignr);
1390 break;
David Brownell7e27f182006-06-13 09:54:40 -07001391 default:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001392 if (fl_speed) p->speed = speed;
1393 else DEBUG ("%c is not valid\n", c);
1394 break;
1395 }
David Brownell7e27f182006-06-13 09:54:40 -07001396
Linus Torvalds1da177e2005-04-16 15:20:36 -07001397 buffer++;
1398 }
David Brownell7e27f182006-06-13 09:54:40 -07001399
Linus Torvalds1da177e2005-04-16 15:20:36 -07001400 return count;
1401}
1402
1403#define NAME_TEMPLATE "driver/rndis-%03d"
1404
1405static struct proc_dir_entry *rndis_connect_state [RNDIS_MAX_CONFIGS];
1406
1407#endif /* CONFIG_USB_GADGET_DEBUG_FILES */
1408
1409
David Brownella3536782006-07-06 15:48:53 -07001410int __devinit rndis_init (void)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001411{
1412 u8 i;
1413
1414 for (i = 0; i < RNDIS_MAX_CONFIGS; i++) {
1415#ifdef CONFIG_USB_GADGET_DEBUG_FILES
1416 char name [20];
1417
1418 sprintf (name, NAME_TEMPLATE, i);
1419 if (!(rndis_connect_state [i]
David Brownell7e27f182006-06-13 09:54:40 -07001420 = create_proc_entry (name, 0660, NULL)))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001421 {
1422 DEBUG ("%s :remove entries", __FUNCTION__);
1423 while (i) {
1424 sprintf (name, NAME_TEMPLATE, --i);
1425 remove_proc_entry (name, NULL);
1426 }
1427 DEBUG ("\n");
1428 return -EIO;
1429 }
1430
Linus Torvalds1da177e2005-04-16 15:20:36 -07001431 rndis_connect_state [i]->write_proc = rndis_proc_write;
1432 rndis_connect_state [i]->read_proc = rndis_proc_read;
1433 rndis_connect_state [i]->data = (void *)
1434 (rndis_per_dev_params + i);
1435#endif
1436 rndis_per_dev_params [i].confignr = i;
1437 rndis_per_dev_params [i].used = 0;
1438 rndis_per_dev_params [i].state = RNDIS_UNINITIALIZED;
1439 rndis_per_dev_params [i].media_state
1440 = NDIS_MEDIA_STATE_DISCONNECTED;
1441 INIT_LIST_HEAD (&(rndis_per_dev_params [i].resp_queue));
1442 }
David Brownell7e27f182006-06-13 09:54:40 -07001443
Linus Torvalds1da177e2005-04-16 15:20:36 -07001444 return 0;
1445}
1446
1447void rndis_exit (void)
1448{
1449#ifdef CONFIG_USB_GADGET_DEBUG_FILES
1450 u8 i;
1451 char name [20];
David Brownell7e27f182006-06-13 09:54:40 -07001452
Linus Torvalds1da177e2005-04-16 15:20:36 -07001453 for (i = 0; i < RNDIS_MAX_CONFIGS; i++) {
1454 sprintf (name, NAME_TEMPLATE, i);
1455 remove_proc_entry (name, NULL);
1456 }
1457#endif
1458}
1459