blob: bd58dd504f6f4ec144048432b51a8d8737047751 [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
Linus Torvalds1da177e2005-04-16 15:20:36 -070056static int rndis_debug = 0;
David Brownell340600a2005-04-28 13:45:25 -070057module_param (rndis_debug, int, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -070058MODULE_PARM_DESC (rndis_debug, "enable debugging");
Linus Torvalds1da177e2005-04-16 15:20:36 -070059#else
Linus Torvalds1da177e2005-04-16 15:20:36 -070060#define rndis_debug 0
Linus Torvalds1da177e2005-04-16 15:20:36 -070061#endif
62
David Brownell00274922007-11-19 12:58:36 -080063#define DBG(str,args...) do { \
64 if (rndis_debug) \
65 pr_debug(str , ## args); \
66 } while (0)
67
Linus Torvalds1da177e2005-04-16 15:20:36 -070068#define RNDIS_MAX_CONFIGS 1
69
70
71static rndis_params rndis_per_dev_params [RNDIS_MAX_CONFIGS];
72
73/* Driver Version */
74static const __le32 rndis_driver_version = __constant_cpu_to_le32 (1);
75
76/* Function Prototypes */
Linus Torvalds1da177e2005-04-16 15:20:36 -070077static rndis_resp_t *rndis_add_response (int configNr, u32 length);
78
79
David Brownell340600a2005-04-28 13:45:25 -070080/* supported OIDs */
David Brownell7e27f182006-06-13 09:54:40 -070081static const u32 oid_supported_list [] =
David Brownell340600a2005-04-28 13:45:25 -070082{
83 /* the general stuff */
84 OID_GEN_SUPPORTED_LIST,
85 OID_GEN_HARDWARE_STATUS,
86 OID_GEN_MEDIA_SUPPORTED,
87 OID_GEN_MEDIA_IN_USE,
88 OID_GEN_MAXIMUM_FRAME_SIZE,
89 OID_GEN_LINK_SPEED,
90 OID_GEN_TRANSMIT_BLOCK_SIZE,
91 OID_GEN_RECEIVE_BLOCK_SIZE,
92 OID_GEN_VENDOR_ID,
93 OID_GEN_VENDOR_DESCRIPTION,
94 OID_GEN_VENDOR_DRIVER_VERSION,
95 OID_GEN_CURRENT_PACKET_FILTER,
96 OID_GEN_MAXIMUM_TOTAL_SIZE,
97 OID_GEN_MEDIA_CONNECT_STATUS,
98 OID_GEN_PHYSICAL_MEDIUM,
99#if 0
100 OID_GEN_RNDIS_CONFIG_PARAMETER,
101#endif
David Brownell7e27f182006-06-13 09:54:40 -0700102
David Brownell340600a2005-04-28 13:45:25 -0700103 /* the statistical stuff */
104 OID_GEN_XMIT_OK,
105 OID_GEN_RCV_OK,
106 OID_GEN_XMIT_ERROR,
107 OID_GEN_RCV_ERROR,
108 OID_GEN_RCV_NO_BUFFER,
109#ifdef RNDIS_OPTIONAL_STATS
110 OID_GEN_DIRECTED_BYTES_XMIT,
111 OID_GEN_DIRECTED_FRAMES_XMIT,
112 OID_GEN_MULTICAST_BYTES_XMIT,
113 OID_GEN_MULTICAST_FRAMES_XMIT,
114 OID_GEN_BROADCAST_BYTES_XMIT,
115 OID_GEN_BROADCAST_FRAMES_XMIT,
116 OID_GEN_DIRECTED_BYTES_RCV,
117 OID_GEN_DIRECTED_FRAMES_RCV,
118 OID_GEN_MULTICAST_BYTES_RCV,
119 OID_GEN_MULTICAST_FRAMES_RCV,
120 OID_GEN_BROADCAST_BYTES_RCV,
121 OID_GEN_BROADCAST_FRAMES_RCV,
122 OID_GEN_RCV_CRC_ERROR,
123 OID_GEN_TRANSMIT_QUEUE_LENGTH,
124#endif /* RNDIS_OPTIONAL_STATS */
125
David Brownell7e27f182006-06-13 09:54:40 -0700126 /* mandatory 802.3 */
David Brownell340600a2005-04-28 13:45:25 -0700127 /* the general stuff */
128 OID_802_3_PERMANENT_ADDRESS,
129 OID_802_3_CURRENT_ADDRESS,
130 OID_802_3_MULTICAST_LIST,
131 OID_802_3_MAC_OPTIONS,
132 OID_802_3_MAXIMUM_LIST_SIZE,
David Brownell7e27f182006-06-13 09:54:40 -0700133
David Brownell340600a2005-04-28 13:45:25 -0700134 /* the statistical stuff */
135 OID_802_3_RCV_ERROR_ALIGNMENT,
136 OID_802_3_XMIT_ONE_COLLISION,
137 OID_802_3_XMIT_MORE_COLLISIONS,
138#ifdef RNDIS_OPTIONAL_STATS
139 OID_802_3_XMIT_DEFERRED,
140 OID_802_3_XMIT_MAX_COLLISIONS,
141 OID_802_3_RCV_OVERRUN,
142 OID_802_3_XMIT_UNDERRUN,
143 OID_802_3_XMIT_HEARTBEAT_FAILURE,
144 OID_802_3_XMIT_TIMES_CRS_LOST,
145 OID_802_3_XMIT_LATE_COLLISIONS,
146#endif /* RNDIS_OPTIONAL_STATS */
147
148#ifdef RNDIS_PM
149 /* PM and wakeup are mandatory for USB: */
150
151 /* power management */
152 OID_PNP_CAPABILITIES,
153 OID_PNP_QUERY_POWER,
154 OID_PNP_SET_POWER,
155
156#ifdef RNDIS_WAKEUP
157 /* wake up host */
158 OID_PNP_ENABLE_WAKE_UP,
159 OID_PNP_ADD_WAKE_UP_PATTERN,
160 OID_PNP_REMOVE_WAKE_UP_PATTERN,
161#endif /* RNDIS_WAKEUP */
162#endif /* RNDIS_PM */
163};
164
165
Linus Torvalds1da177e2005-04-16 15:20:36 -0700166/* NDIS Functions */
David Brownell340600a2005-04-28 13:45:25 -0700167static int
168gen_ndis_query_resp (int configNr, u32 OID, u8 *buf, unsigned buf_len,
169 rndis_resp_t *r)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700170{
David Brownell7e27f182006-06-13 09:54:40 -0700171 int retval = -ENOTSUPP;
172 u32 length = 4; /* usually */
David Brownell340600a2005-04-28 13:45:25 -0700173 __le32 *outbuf;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700174 int i, count;
175 rndis_query_cmplt_type *resp;
176
177 if (!r) return -ENOMEM;
178 resp = (rndis_query_cmplt_type *) r->buf;
179
180 if (!resp) return -ENOMEM;
David Brownell340600a2005-04-28 13:45:25 -0700181
182 if (buf_len && rndis_debug > 1) {
David Brownell70790f62007-07-01 17:35:28 -0700183 DBG("query OID %08x value, len %d:\n", OID, buf_len);
David Brownell340600a2005-04-28 13:45:25 -0700184 for (i = 0; i < buf_len; i += 16) {
David Brownell70790f62007-07-01 17:35:28 -0700185 DBG("%03d: %08x %08x %08x %08x\n", i,
David Brownell01ee7d72007-05-25 20:40:14 -0700186 le32_to_cpu(get_unaligned((__le32 *)
187 &buf[i])),
188 le32_to_cpu(get_unaligned((__le32 *)
189 &buf[i + 4])),
190 le32_to_cpu(get_unaligned((__le32 *)
191 &buf[i + 8])),
192 le32_to_cpu(get_unaligned((__le32 *)
193 &buf[i + 12])));
David Brownell340600a2005-04-28 13:45:25 -0700194 }
195 }
196
197 /* response goes here, right after the header */
198 outbuf = (__le32 *) &resp[1];
199 resp->InformationBufferOffset = __constant_cpu_to_le32 (16);
200
Linus Torvalds1da177e2005-04-16 15:20:36 -0700201 switch (OID) {
202
203 /* general oids (table 4-1) */
204
205 /* mandatory */
206 case OID_GEN_SUPPORTED_LIST:
Harvey Harrison441b62c2008-03-03 16:08:34 -0800207 DBG("%s: OID_GEN_SUPPORTED_LIST\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700208 length = sizeof (oid_supported_list);
209 count = length / sizeof (u32);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700210 for (i = 0; i < count; i++)
David Brownell340600a2005-04-28 13:45:25 -0700211 outbuf[i] = cpu_to_le32 (oid_supported_list[i]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700212 retval = 0;
213 break;
David Brownell7e27f182006-06-13 09:54:40 -0700214
Linus Torvalds1da177e2005-04-16 15:20:36 -0700215 /* mandatory */
216 case OID_GEN_HARDWARE_STATUS:
Harvey Harrison441b62c2008-03-03 16:08:34 -0800217 DBG("%s: OID_GEN_HARDWARE_STATUS\n", __func__);
David Brownell7e27f182006-06-13 09:54:40 -0700218 /* Bogus question!
Linus Torvalds1da177e2005-04-16 15:20:36 -0700219 * Hardware must be ready to receive high level protocols.
David Brownell7e27f182006-06-13 09:54:40 -0700220 * BTW:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700221 * reddite ergo quae sunt Caesaris Caesari
222 * et quae sunt Dei Deo!
223 */
David Brownell340600a2005-04-28 13:45:25 -0700224 *outbuf = __constant_cpu_to_le32 (0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700225 retval = 0;
226 break;
David Brownell7e27f182006-06-13 09:54:40 -0700227
Linus Torvalds1da177e2005-04-16 15:20:36 -0700228 /* mandatory */
229 case OID_GEN_MEDIA_SUPPORTED:
Harvey Harrison441b62c2008-03-03 16:08:34 -0800230 DBG("%s: OID_GEN_MEDIA_SUPPORTED\n", __func__);
David Brownell340600a2005-04-28 13:45:25 -0700231 *outbuf = cpu_to_le32 (rndis_per_dev_params [configNr].medium);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700232 retval = 0;
233 break;
David Brownell7e27f182006-06-13 09:54:40 -0700234
Linus Torvalds1da177e2005-04-16 15:20:36 -0700235 /* mandatory */
236 case OID_GEN_MEDIA_IN_USE:
Harvey Harrison441b62c2008-03-03 16:08:34 -0800237 DBG("%s: OID_GEN_MEDIA_IN_USE\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700238 /* one medium, one transport... (maybe you do it better) */
David Brownell340600a2005-04-28 13:45:25 -0700239 *outbuf = cpu_to_le32 (rndis_per_dev_params [configNr].medium);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700240 retval = 0;
241 break;
David Brownell7e27f182006-06-13 09:54:40 -0700242
Linus Torvalds1da177e2005-04-16 15:20:36 -0700243 /* mandatory */
244 case OID_GEN_MAXIMUM_FRAME_SIZE:
Harvey Harrison441b62c2008-03-03 16:08:34 -0800245 DBG("%s: OID_GEN_MAXIMUM_FRAME_SIZE\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700246 if (rndis_per_dev_params [configNr].dev) {
David Brownell340600a2005-04-28 13:45:25 -0700247 *outbuf = cpu_to_le32 (
Linus Torvalds1da177e2005-04-16 15:20:36 -0700248 rndis_per_dev_params [configNr].dev->mtu);
249 retval = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700250 }
251 break;
David Brownell7e27f182006-06-13 09:54:40 -0700252
Linus Torvalds1da177e2005-04-16 15:20:36 -0700253 /* mandatory */
254 case OID_GEN_LINK_SPEED:
David Brownell340600a2005-04-28 13:45:25 -0700255 if (rndis_debug > 1)
Harvey Harrison441b62c2008-03-03 16:08:34 -0800256 DBG("%s: OID_GEN_LINK_SPEED\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700257 if (rndis_per_dev_params [configNr].media_state
David Brownell340600a2005-04-28 13:45:25 -0700258 == NDIS_MEDIA_STATE_DISCONNECTED)
259 *outbuf = __constant_cpu_to_le32 (0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700260 else
David Brownell340600a2005-04-28 13:45:25 -0700261 *outbuf = cpu_to_le32 (
Linus Torvalds1da177e2005-04-16 15:20:36 -0700262 rndis_per_dev_params [configNr].speed);
263 retval = 0;
264 break;
265
266 /* mandatory */
267 case OID_GEN_TRANSMIT_BLOCK_SIZE:
Harvey Harrison441b62c2008-03-03 16:08:34 -0800268 DBG("%s: OID_GEN_TRANSMIT_BLOCK_SIZE\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700269 if (rndis_per_dev_params [configNr].dev) {
David Brownell340600a2005-04-28 13:45:25 -0700270 *outbuf = cpu_to_le32 (
Linus Torvalds1da177e2005-04-16 15:20:36 -0700271 rndis_per_dev_params [configNr].dev->mtu);
272 retval = 0;
273 }
274 break;
David Brownell7e27f182006-06-13 09:54:40 -0700275
Linus Torvalds1da177e2005-04-16 15:20:36 -0700276 /* mandatory */
277 case OID_GEN_RECEIVE_BLOCK_SIZE:
Harvey Harrison441b62c2008-03-03 16:08:34 -0800278 DBG("%s: OID_GEN_RECEIVE_BLOCK_SIZE\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700279 if (rndis_per_dev_params [configNr].dev) {
David Brownell340600a2005-04-28 13:45:25 -0700280 *outbuf = cpu_to_le32 (
Linus Torvalds1da177e2005-04-16 15:20:36 -0700281 rndis_per_dev_params [configNr].dev->mtu);
282 retval = 0;
283 }
284 break;
David Brownell7e27f182006-06-13 09:54:40 -0700285
Linus Torvalds1da177e2005-04-16 15:20:36 -0700286 /* mandatory */
287 case OID_GEN_VENDOR_ID:
Harvey Harrison441b62c2008-03-03 16:08:34 -0800288 DBG("%s: OID_GEN_VENDOR_ID\n", __func__);
David Brownell340600a2005-04-28 13:45:25 -0700289 *outbuf = cpu_to_le32 (
Linus Torvalds1da177e2005-04-16 15:20:36 -0700290 rndis_per_dev_params [configNr].vendorID);
291 retval = 0;
292 break;
David Brownell7e27f182006-06-13 09:54:40 -0700293
Linus Torvalds1da177e2005-04-16 15:20:36 -0700294 /* mandatory */
295 case OID_GEN_VENDOR_DESCRIPTION:
Harvey Harrison441b62c2008-03-03 16:08:34 -0800296 DBG("%s: OID_GEN_VENDOR_DESCRIPTION\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700297 length = strlen (rndis_per_dev_params [configNr].vendorDescr);
David Brownell340600a2005-04-28 13:45:25 -0700298 memcpy (outbuf,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700299 rndis_per_dev_params [configNr].vendorDescr, length);
300 retval = 0;
301 break;
302
303 case OID_GEN_VENDOR_DRIVER_VERSION:
Harvey Harrison441b62c2008-03-03 16:08:34 -0800304 DBG("%s: OID_GEN_VENDOR_DRIVER_VERSION\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700305 /* Created as LE */
David Brownell340600a2005-04-28 13:45:25 -0700306 *outbuf = rndis_driver_version;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700307 retval = 0;
308 break;
309
310 /* mandatory */
311 case OID_GEN_CURRENT_PACKET_FILTER:
Harvey Harrison441b62c2008-03-03 16:08:34 -0800312 DBG("%s: OID_GEN_CURRENT_PACKET_FILTER\n", __func__);
David Brownell340600a2005-04-28 13:45:25 -0700313 *outbuf = cpu_to_le32 (*rndis_per_dev_params[configNr].filter);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700314 retval = 0;
315 break;
316
317 /* mandatory */
318 case OID_GEN_MAXIMUM_TOTAL_SIZE:
Harvey Harrison441b62c2008-03-03 16:08:34 -0800319 DBG("%s: OID_GEN_MAXIMUM_TOTAL_SIZE\n", __func__);
David Brownell340600a2005-04-28 13:45:25 -0700320 *outbuf = __constant_cpu_to_le32(RNDIS_MAX_TOTAL_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700321 retval = 0;
322 break;
323
324 /* mandatory */
325 case OID_GEN_MEDIA_CONNECT_STATUS:
David Brownell340600a2005-04-28 13:45:25 -0700326 if (rndis_debug > 1)
Harvey Harrison441b62c2008-03-03 16:08:34 -0800327 DBG("%s: OID_GEN_MEDIA_CONNECT_STATUS\n", __func__);
David Brownell340600a2005-04-28 13:45:25 -0700328 *outbuf = cpu_to_le32 (rndis_per_dev_params [configNr]
Linus Torvalds1da177e2005-04-16 15:20:36 -0700329 .media_state);
330 retval = 0;
331 break;
332
333 case OID_GEN_PHYSICAL_MEDIUM:
Harvey Harrison441b62c2008-03-03 16:08:34 -0800334 DBG("%s: OID_GEN_PHYSICAL_MEDIUM\n", __func__);
David Brownell340600a2005-04-28 13:45:25 -0700335 *outbuf = __constant_cpu_to_le32 (0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700336 retval = 0;
337 break;
338
339 /* The RNDIS specification is incomplete/wrong. Some versions
340 * of MS-Windows expect OIDs that aren't specified there. Other
341 * versions emit undefined RNDIS messages. DOCUMENT ALL THESE!
342 */
343 case OID_GEN_MAC_OPTIONS: /* from WinME */
Harvey Harrison441b62c2008-03-03 16:08:34 -0800344 DBG("%s: OID_GEN_MAC_OPTIONS\n", __func__);
David Brownell340600a2005-04-28 13:45:25 -0700345 *outbuf = __constant_cpu_to_le32(
Linus Torvalds1da177e2005-04-16 15:20:36 -0700346 NDIS_MAC_OPTION_RECEIVE_SERIALIZED
347 | NDIS_MAC_OPTION_FULL_DUPLEX);
348 retval = 0;
349 break;
350
351 /* statistics OIDs (table 4-2) */
352
353 /* mandatory */
354 case OID_GEN_XMIT_OK:
David Brownell340600a2005-04-28 13:45:25 -0700355 if (rndis_debug > 1)
Harvey Harrison441b62c2008-03-03 16:08:34 -0800356 DBG("%s: OID_GEN_XMIT_OK\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700357 if (rndis_per_dev_params [configNr].stats) {
David Brownell340600a2005-04-28 13:45:25 -0700358 *outbuf = cpu_to_le32 (
David Brownell7e27f182006-06-13 09:54:40 -0700359 rndis_per_dev_params [configNr].stats->tx_packets -
Linus Torvalds1da177e2005-04-16 15:20:36 -0700360 rndis_per_dev_params [configNr].stats->tx_errors -
361 rndis_per_dev_params [configNr].stats->tx_dropped);
362 retval = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700363 }
364 break;
365
366 /* mandatory */
367 case OID_GEN_RCV_OK:
David Brownell340600a2005-04-28 13:45:25 -0700368 if (rndis_debug > 1)
Harvey Harrison441b62c2008-03-03 16:08:34 -0800369 DBG("%s: OID_GEN_RCV_OK\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700370 if (rndis_per_dev_params [configNr].stats) {
David Brownell340600a2005-04-28 13:45:25 -0700371 *outbuf = cpu_to_le32 (
David Brownell7e27f182006-06-13 09:54:40 -0700372 rndis_per_dev_params [configNr].stats->rx_packets -
Linus Torvalds1da177e2005-04-16 15:20:36 -0700373 rndis_per_dev_params [configNr].stats->rx_errors -
374 rndis_per_dev_params [configNr].stats->rx_dropped);
375 retval = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700376 }
377 break;
David Brownell7e27f182006-06-13 09:54:40 -0700378
Linus Torvalds1da177e2005-04-16 15:20:36 -0700379 /* mandatory */
380 case OID_GEN_XMIT_ERROR:
David Brownell340600a2005-04-28 13:45:25 -0700381 if (rndis_debug > 1)
Harvey Harrison441b62c2008-03-03 16:08:34 -0800382 DBG("%s: OID_GEN_XMIT_ERROR\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700383 if (rndis_per_dev_params [configNr].stats) {
David Brownell340600a2005-04-28 13:45:25 -0700384 *outbuf = cpu_to_le32 (rndis_per_dev_params [configNr]
Linus Torvalds1da177e2005-04-16 15:20:36 -0700385 .stats->tx_errors);
386 retval = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700387 }
388 break;
David Brownell7e27f182006-06-13 09:54:40 -0700389
Linus Torvalds1da177e2005-04-16 15:20:36 -0700390 /* mandatory */
391 case OID_GEN_RCV_ERROR:
David Brownell340600a2005-04-28 13:45:25 -0700392 if (rndis_debug > 1)
Harvey Harrison441b62c2008-03-03 16:08:34 -0800393 DBG("%s: OID_GEN_RCV_ERROR\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700394 if (rndis_per_dev_params [configNr].stats) {
David Brownell340600a2005-04-28 13:45:25 -0700395 *outbuf = cpu_to_le32 (rndis_per_dev_params [configNr]
Linus Torvalds1da177e2005-04-16 15:20:36 -0700396 .stats->rx_errors);
397 retval = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700398 }
399 break;
David Brownell7e27f182006-06-13 09:54:40 -0700400
Linus Torvalds1da177e2005-04-16 15:20:36 -0700401 /* mandatory */
402 case OID_GEN_RCV_NO_BUFFER:
Harvey Harrison441b62c2008-03-03 16:08:34 -0800403 DBG("%s: OID_GEN_RCV_NO_BUFFER\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700404 if (rndis_per_dev_params [configNr].stats) {
David Brownell340600a2005-04-28 13:45:25 -0700405 *outbuf = cpu_to_le32 (rndis_per_dev_params [configNr]
Linus Torvalds1da177e2005-04-16 15:20:36 -0700406 .stats->rx_dropped);
407 retval = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700408 }
409 break;
410
411#ifdef RNDIS_OPTIONAL_STATS
412 case OID_GEN_DIRECTED_BYTES_XMIT:
Harvey Harrison441b62c2008-03-03 16:08:34 -0800413 DBG("%s: OID_GEN_DIRECTED_BYTES_XMIT\n", __func__);
David Brownell7e27f182006-06-13 09:54:40 -0700414 /*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700415 * Aunt Tilly's size of shoes
416 * minus antarctica count of penguins
417 * divided by weight of Alpha Centauri
418 */
419 if (rndis_per_dev_params [configNr].stats) {
David Brownell340600a2005-04-28 13:45:25 -0700420 *outbuf = cpu_to_le32 (
Linus Torvalds1da177e2005-04-16 15:20:36 -0700421 (rndis_per_dev_params [configNr]
David Brownell7e27f182006-06-13 09:54:40 -0700422 .stats->tx_packets -
Linus Torvalds1da177e2005-04-16 15:20:36 -0700423 rndis_per_dev_params [configNr]
424 .stats->tx_errors -
425 rndis_per_dev_params [configNr]
426 .stats->tx_dropped)
427 * 123);
428 retval = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700429 }
430 break;
David Brownell7e27f182006-06-13 09:54:40 -0700431
Linus Torvalds1da177e2005-04-16 15:20:36 -0700432 case OID_GEN_DIRECTED_FRAMES_XMIT:
Harvey Harrison441b62c2008-03-03 16:08:34 -0800433 DBG("%s: OID_GEN_DIRECTED_FRAMES_XMIT\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700434 /* dito */
435 if (rndis_per_dev_params [configNr].stats) {
David Brownell340600a2005-04-28 13:45:25 -0700436 *outbuf = cpu_to_le32 (
Linus Torvalds1da177e2005-04-16 15:20:36 -0700437 (rndis_per_dev_params [configNr]
David Brownell7e27f182006-06-13 09:54:40 -0700438 .stats->tx_packets -
Linus Torvalds1da177e2005-04-16 15:20:36 -0700439 rndis_per_dev_params [configNr]
440 .stats->tx_errors -
441 rndis_per_dev_params [configNr]
442 .stats->tx_dropped)
443 / 123);
444 retval = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700445 }
446 break;
David Brownell7e27f182006-06-13 09:54:40 -0700447
Linus Torvalds1da177e2005-04-16 15:20:36 -0700448 case OID_GEN_MULTICAST_BYTES_XMIT:
Harvey Harrison441b62c2008-03-03 16:08:34 -0800449 DBG("%s: OID_GEN_MULTICAST_BYTES_XMIT\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700450 if (rndis_per_dev_params [configNr].stats) {
David Brownell340600a2005-04-28 13:45:25 -0700451 *outbuf = cpu_to_le32 (rndis_per_dev_params [configNr]
Linus Torvalds1da177e2005-04-16 15:20:36 -0700452 .stats->multicast*1234);
453 retval = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700454 }
455 break;
David Brownell7e27f182006-06-13 09:54:40 -0700456
Linus Torvalds1da177e2005-04-16 15:20:36 -0700457 case OID_GEN_MULTICAST_FRAMES_XMIT:
Harvey Harrison441b62c2008-03-03 16:08:34 -0800458 DBG("%s: OID_GEN_MULTICAST_FRAMES_XMIT\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700459 if (rndis_per_dev_params [configNr].stats) {
David Brownell340600a2005-04-28 13:45:25 -0700460 *outbuf = cpu_to_le32 (rndis_per_dev_params [configNr]
Linus Torvalds1da177e2005-04-16 15:20:36 -0700461 .stats->multicast);
462 retval = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700463 }
464 break;
David Brownell7e27f182006-06-13 09:54:40 -0700465
Linus Torvalds1da177e2005-04-16 15:20:36 -0700466 case OID_GEN_BROADCAST_BYTES_XMIT:
Harvey Harrison441b62c2008-03-03 16:08:34 -0800467 DBG("%s: OID_GEN_BROADCAST_BYTES_XMIT\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700468 if (rndis_per_dev_params [configNr].stats) {
David Brownell340600a2005-04-28 13:45:25 -0700469 *outbuf = cpu_to_le32 (rndis_per_dev_params [configNr]
Linus Torvalds1da177e2005-04-16 15:20:36 -0700470 .stats->tx_packets/42*255);
471 retval = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700472 }
473 break;
David Brownell7e27f182006-06-13 09:54:40 -0700474
Linus Torvalds1da177e2005-04-16 15:20:36 -0700475 case OID_GEN_BROADCAST_FRAMES_XMIT:
Harvey Harrison441b62c2008-03-03 16:08:34 -0800476 DBG("%s: OID_GEN_BROADCAST_FRAMES_XMIT\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700477 if (rndis_per_dev_params [configNr].stats) {
David Brownell340600a2005-04-28 13:45:25 -0700478 *outbuf = cpu_to_le32 (rndis_per_dev_params [configNr]
Linus Torvalds1da177e2005-04-16 15:20:36 -0700479 .stats->tx_packets/42);
480 retval = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700481 }
482 break;
David Brownell7e27f182006-06-13 09:54:40 -0700483
Linus Torvalds1da177e2005-04-16 15:20:36 -0700484 case OID_GEN_DIRECTED_BYTES_RCV:
Harvey Harrison441b62c2008-03-03 16:08:34 -0800485 DBG("%s: OID_GEN_DIRECTED_BYTES_RCV\n", __func__);
David Brownell340600a2005-04-28 13:45:25 -0700486 *outbuf = __constant_cpu_to_le32 (0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700487 retval = 0;
488 break;
David Brownell7e27f182006-06-13 09:54:40 -0700489
Linus Torvalds1da177e2005-04-16 15:20:36 -0700490 case OID_GEN_DIRECTED_FRAMES_RCV:
Harvey Harrison441b62c2008-03-03 16:08:34 -0800491 DBG("%s: OID_GEN_DIRECTED_FRAMES_RCV\n", __func__);
David Brownell340600a2005-04-28 13:45:25 -0700492 *outbuf = __constant_cpu_to_le32 (0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700493 retval = 0;
494 break;
David Brownell7e27f182006-06-13 09:54:40 -0700495
Linus Torvalds1da177e2005-04-16 15:20:36 -0700496 case OID_GEN_MULTICAST_BYTES_RCV:
Harvey Harrison441b62c2008-03-03 16:08:34 -0800497 DBG("%s: OID_GEN_MULTICAST_BYTES_RCV\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700498 if (rndis_per_dev_params [configNr].stats) {
David Brownell340600a2005-04-28 13:45:25 -0700499 *outbuf = cpu_to_le32 (rndis_per_dev_params [configNr]
Linus Torvalds1da177e2005-04-16 15:20:36 -0700500 .stats->multicast * 1111);
501 retval = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700502 }
503 break;
David Brownell7e27f182006-06-13 09:54:40 -0700504
Linus Torvalds1da177e2005-04-16 15:20:36 -0700505 case OID_GEN_MULTICAST_FRAMES_RCV:
Harvey Harrison441b62c2008-03-03 16:08:34 -0800506 DBG("%s: OID_GEN_MULTICAST_FRAMES_RCV\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700507 if (rndis_per_dev_params [configNr].stats) {
David Brownell340600a2005-04-28 13:45:25 -0700508 *outbuf = cpu_to_le32 (rndis_per_dev_params [configNr]
Linus Torvalds1da177e2005-04-16 15:20:36 -0700509 .stats->multicast);
510 retval = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700511 }
512 break;
David Brownell7e27f182006-06-13 09:54:40 -0700513
Linus Torvalds1da177e2005-04-16 15:20:36 -0700514 case OID_GEN_BROADCAST_BYTES_RCV:
Harvey Harrison441b62c2008-03-03 16:08:34 -0800515 DBG("%s: OID_GEN_BROADCAST_BYTES_RCV\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700516 if (rndis_per_dev_params [configNr].stats) {
David Brownell340600a2005-04-28 13:45:25 -0700517 *outbuf = cpu_to_le32 (rndis_per_dev_params [configNr]
Linus Torvalds1da177e2005-04-16 15:20:36 -0700518 .stats->rx_packets/42*255);
519 retval = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700520 }
521 break;
David Brownell7e27f182006-06-13 09:54:40 -0700522
Linus Torvalds1da177e2005-04-16 15:20:36 -0700523 case OID_GEN_BROADCAST_FRAMES_RCV:
Harvey Harrison441b62c2008-03-03 16:08:34 -0800524 DBG("%s: OID_GEN_BROADCAST_FRAMES_RCV\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700525 if (rndis_per_dev_params [configNr].stats) {
David Brownell340600a2005-04-28 13:45:25 -0700526 *outbuf = cpu_to_le32 (rndis_per_dev_params [configNr]
Linus Torvalds1da177e2005-04-16 15:20:36 -0700527 .stats->rx_packets/42);
528 retval = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700529 }
530 break;
David Brownell7e27f182006-06-13 09:54:40 -0700531
Linus Torvalds1da177e2005-04-16 15:20:36 -0700532 case OID_GEN_RCV_CRC_ERROR:
Harvey Harrison441b62c2008-03-03 16:08:34 -0800533 DBG("%s: OID_GEN_RCV_CRC_ERROR\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700534 if (rndis_per_dev_params [configNr].stats) {
David Brownell340600a2005-04-28 13:45:25 -0700535 *outbuf = cpu_to_le32 (rndis_per_dev_params [configNr]
Linus Torvalds1da177e2005-04-16 15:20:36 -0700536 .stats->rx_crc_errors);
537 retval = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700538 }
539 break;
David Brownell7e27f182006-06-13 09:54:40 -0700540
Linus Torvalds1da177e2005-04-16 15:20:36 -0700541 case OID_GEN_TRANSMIT_QUEUE_LENGTH:
Harvey Harrison441b62c2008-03-03 16:08:34 -0800542 DBG("%s: OID_GEN_TRANSMIT_QUEUE_LENGTH\n", __func__);
David Brownell340600a2005-04-28 13:45:25 -0700543 *outbuf = __constant_cpu_to_le32 (0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700544 retval = 0;
545 break;
546#endif /* RNDIS_OPTIONAL_STATS */
547
548 /* ieee802.3 OIDs (table 4-3) */
549
550 /* mandatory */
551 case OID_802_3_PERMANENT_ADDRESS:
Harvey Harrison441b62c2008-03-03 16:08:34 -0800552 DBG("%s: OID_802_3_PERMANENT_ADDRESS\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700553 if (rndis_per_dev_params [configNr].dev) {
554 length = ETH_ALEN;
David Brownell340600a2005-04-28 13:45:25 -0700555 memcpy (outbuf,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700556 rndis_per_dev_params [configNr].host_mac,
557 length);
558 retval = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700559 }
560 break;
David Brownell7e27f182006-06-13 09:54:40 -0700561
Linus Torvalds1da177e2005-04-16 15:20:36 -0700562 /* mandatory */
563 case OID_802_3_CURRENT_ADDRESS:
Harvey Harrison441b62c2008-03-03 16:08:34 -0800564 DBG("%s: OID_802_3_CURRENT_ADDRESS\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700565 if (rndis_per_dev_params [configNr].dev) {
566 length = ETH_ALEN;
David Brownell340600a2005-04-28 13:45:25 -0700567 memcpy (outbuf,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700568 rndis_per_dev_params [configNr].host_mac,
569 length);
570 retval = 0;
571 }
572 break;
David Brownell7e27f182006-06-13 09:54:40 -0700573
Linus Torvalds1da177e2005-04-16 15:20:36 -0700574 /* mandatory */
575 case OID_802_3_MULTICAST_LIST:
Harvey Harrison441b62c2008-03-03 16:08:34 -0800576 DBG("%s: OID_802_3_MULTICAST_LIST\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700577 /* Multicast base address only */
David Brownell340600a2005-04-28 13:45:25 -0700578 *outbuf = __constant_cpu_to_le32 (0xE0000000);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700579 retval = 0;
580 break;
David Brownell7e27f182006-06-13 09:54:40 -0700581
Linus Torvalds1da177e2005-04-16 15:20:36 -0700582 /* mandatory */
583 case OID_802_3_MAXIMUM_LIST_SIZE:
Harvey Harrison441b62c2008-03-03 16:08:34 -0800584 DBG("%s: OID_802_3_MAXIMUM_LIST_SIZE\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700585 /* Multicast base address only */
David Brownell340600a2005-04-28 13:45:25 -0700586 *outbuf = __constant_cpu_to_le32 (1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700587 retval = 0;
588 break;
David Brownell7e27f182006-06-13 09:54:40 -0700589
Linus Torvalds1da177e2005-04-16 15:20:36 -0700590 case OID_802_3_MAC_OPTIONS:
Harvey Harrison441b62c2008-03-03 16:08:34 -0800591 DBG("%s: OID_802_3_MAC_OPTIONS\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700592 break;
593
594 /* ieee802.3 statistics OIDs (table 4-4) */
595
596 /* mandatory */
597 case OID_802_3_RCV_ERROR_ALIGNMENT:
Harvey Harrison441b62c2008-03-03 16:08:34 -0800598 DBG("%s: OID_802_3_RCV_ERROR_ALIGNMENT\n", __func__);
David Brownell340600a2005-04-28 13:45:25 -0700599 if (rndis_per_dev_params [configNr].stats) {
600 *outbuf = cpu_to_le32 (rndis_per_dev_params [configNr]
Linus Torvalds1da177e2005-04-16 15:20:36 -0700601 .stats->rx_frame_errors);
602 retval = 0;
603 }
604 break;
David Brownell7e27f182006-06-13 09:54:40 -0700605
Linus Torvalds1da177e2005-04-16 15:20:36 -0700606 /* mandatory */
607 case OID_802_3_XMIT_ONE_COLLISION:
Harvey Harrison441b62c2008-03-03 16:08:34 -0800608 DBG("%s: OID_802_3_XMIT_ONE_COLLISION\n", __func__);
David Brownell340600a2005-04-28 13:45:25 -0700609 *outbuf = __constant_cpu_to_le32 (0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700610 retval = 0;
611 break;
David Brownell7e27f182006-06-13 09:54:40 -0700612
Linus Torvalds1da177e2005-04-16 15:20:36 -0700613 /* mandatory */
614 case OID_802_3_XMIT_MORE_COLLISIONS:
Harvey Harrison441b62c2008-03-03 16:08:34 -0800615 DBG("%s: OID_802_3_XMIT_MORE_COLLISIONS\n", __func__);
David Brownell340600a2005-04-28 13:45:25 -0700616 *outbuf = __constant_cpu_to_le32 (0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700617 retval = 0;
618 break;
David Brownell7e27f182006-06-13 09:54:40 -0700619
Linus Torvalds1da177e2005-04-16 15:20:36 -0700620#ifdef RNDIS_OPTIONAL_STATS
621 case OID_802_3_XMIT_DEFERRED:
Harvey Harrison441b62c2008-03-03 16:08:34 -0800622 DBG("%s: OID_802_3_XMIT_DEFERRED\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700623 /* TODO */
624 break;
David Brownell7e27f182006-06-13 09:54:40 -0700625
Linus Torvalds1da177e2005-04-16 15:20:36 -0700626 case OID_802_3_XMIT_MAX_COLLISIONS:
Harvey Harrison441b62c2008-03-03 16:08:34 -0800627 DBG("%s: OID_802_3_XMIT_MAX_COLLISIONS\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700628 /* TODO */
629 break;
David Brownell7e27f182006-06-13 09:54:40 -0700630
Linus Torvalds1da177e2005-04-16 15:20:36 -0700631 case OID_802_3_RCV_OVERRUN:
Harvey Harrison441b62c2008-03-03 16:08:34 -0800632 DBG("%s: OID_802_3_RCV_OVERRUN\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700633 /* TODO */
634 break;
David Brownell7e27f182006-06-13 09:54:40 -0700635
Linus Torvalds1da177e2005-04-16 15:20:36 -0700636 case OID_802_3_XMIT_UNDERRUN:
Harvey Harrison441b62c2008-03-03 16:08:34 -0800637 DBG("%s: OID_802_3_XMIT_UNDERRUN\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700638 /* TODO */
639 break;
David Brownell7e27f182006-06-13 09:54:40 -0700640
Linus Torvalds1da177e2005-04-16 15:20:36 -0700641 case OID_802_3_XMIT_HEARTBEAT_FAILURE:
Harvey Harrison441b62c2008-03-03 16:08:34 -0800642 DBG("%s: OID_802_3_XMIT_HEARTBEAT_FAILURE\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700643 /* TODO */
644 break;
David Brownell7e27f182006-06-13 09:54:40 -0700645
Linus Torvalds1da177e2005-04-16 15:20:36 -0700646 case OID_802_3_XMIT_TIMES_CRS_LOST:
Harvey Harrison441b62c2008-03-03 16:08:34 -0800647 DBG("%s: OID_802_3_XMIT_TIMES_CRS_LOST\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700648 /* TODO */
649 break;
David Brownell7e27f182006-06-13 09:54:40 -0700650
Linus Torvalds1da177e2005-04-16 15:20:36 -0700651 case OID_802_3_XMIT_LATE_COLLISIONS:
Harvey Harrison441b62c2008-03-03 16:08:34 -0800652 DBG("%s: OID_802_3_XMIT_LATE_COLLISIONS\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700653 /* TODO */
David Brownell7e27f182006-06-13 09:54:40 -0700654 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700655#endif /* RNDIS_OPTIONAL_STATS */
656
657#ifdef RNDIS_PM
658 /* power management OIDs (table 4-5) */
659 case OID_PNP_CAPABILITIES:
Harvey Harrison441b62c2008-03-03 16:08:34 -0800660 DBG("%s: OID_PNP_CAPABILITIES\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700661
David Brownell340600a2005-04-28 13:45:25 -0700662 /* for now, no wakeup capabilities */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700663 length = sizeof (struct NDIS_PNP_CAPABILITIES);
David Brownell340600a2005-04-28 13:45:25 -0700664 memset(outbuf, 0, length);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700665 retval = 0;
666 break;
667 case OID_PNP_QUERY_POWER:
Harvey Harrison441b62c2008-03-03 16:08:34 -0800668 DBG("%s: OID_PNP_QUERY_POWER D%d\n", __func__,
David Brownell01ee7d72007-05-25 20:40:14 -0700669 le32_to_cpu(get_unaligned((__le32 *)buf)) - 1);
David Brownell340600a2005-04-28 13:45:25 -0700670 /* only suspend is a real power state, and
671 * it can't be entered by OID_PNP_SET_POWER...
672 */
673 length = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700674 retval = 0;
675 break;
676#endif
677
678 default:
David Brownell00274922007-11-19 12:58:36 -0800679 pr_warning("%s: query unknown OID 0x%08X\n",
Harvey Harrison441b62c2008-03-03 16:08:34 -0800680 __func__, OID);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700681 }
David Brownell340600a2005-04-28 13:45:25 -0700682 if (retval < 0)
683 length = 0;
David Brownell7e27f182006-06-13 09:54:40 -0700684
Linus Torvalds1da177e2005-04-16 15:20:36 -0700685 resp->InformationBufferLength = cpu_to_le32 (length);
David Brownell340600a2005-04-28 13:45:25 -0700686 r->length = length + sizeof *resp;
687 resp->MessageLength = cpu_to_le32 (r->length);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700688 return retval;
689}
690
David Brownell7e27f182006-06-13 09:54:40 -0700691static int gen_ndis_set_resp (u8 configNr, u32 OID, u8 *buf, u32 buf_len,
692 rndis_resp_t *r)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700693{
694 rndis_set_cmplt_type *resp;
David Brownell7e27f182006-06-13 09:54:40 -0700695 int i, retval = -ENOTSUPP;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700696 struct rndis_params *params;
697
698 if (!r)
699 return -ENOMEM;
700 resp = (rndis_set_cmplt_type *) r->buf;
701 if (!resp)
702 return -ENOMEM;
703
David Brownell340600a2005-04-28 13:45:25 -0700704 if (buf_len && rndis_debug > 1) {
David Brownell70790f62007-07-01 17:35:28 -0700705 DBG("set OID %08x value, len %d:\n", OID, buf_len);
David Brownell340600a2005-04-28 13:45:25 -0700706 for (i = 0; i < buf_len; i += 16) {
David Brownell70790f62007-07-01 17:35:28 -0700707 DBG("%03d: %08x %08x %08x %08x\n", i,
David Brownell01ee7d72007-05-25 20:40:14 -0700708 le32_to_cpu(get_unaligned((__le32 *)
709 &buf[i])),
710 le32_to_cpu(get_unaligned((__le32 *)
711 &buf[i + 4])),
712 le32_to_cpu(get_unaligned((__le32 *)
713 &buf[i + 8])),
714 le32_to_cpu(get_unaligned((__le32 *)
715 &buf[i + 12])));
David Brownell340600a2005-04-28 13:45:25 -0700716 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700717 }
718
David Brownell340600a2005-04-28 13:45:25 -0700719 params = &rndis_per_dev_params [configNr];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700720 switch (OID) {
721 case OID_GEN_CURRENT_PACKET_FILTER:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700722
David Brownell340600a2005-04-28 13:45:25 -0700723 /* these NDIS_PACKET_TYPE_* bitflags are shared with
724 * cdc_filter; it's not RNDIS-specific
Linus Torvalds1da177e2005-04-16 15:20:36 -0700725 * NDIS_PACKET_TYPE_x == USB_CDC_PACKET_TYPE_x for x in:
726 * PROMISCUOUS, DIRECTED,
727 * MULTICAST, ALL_MULTICAST, BROADCAST
728 */
David Brownell01ee7d72007-05-25 20:40:14 -0700729 *params->filter = (u16) le32_to_cpu(get_unaligned(
730 (__le32 *)buf));
David Brownell70790f62007-07-01 17:35:28 -0700731 DBG("%s: OID_GEN_CURRENT_PACKET_FILTER %08x\n",
Harvey Harrison441b62c2008-03-03 16:08:34 -0800732 __func__, *params->filter);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700733
734 /* this call has a significant side effect: it's
735 * what makes the packet flow start and stop, like
736 * activating the CDC Ethernet altsetting.
737 */
David Brownell340600a2005-04-28 13:45:25 -0700738#ifdef RNDIS_PM
739update_linkstate:
740#endif
741 retval = 0;
742 if (*params->filter) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700743 params->state = RNDIS_DATA_INITIALIZED;
744 netif_carrier_on(params->dev);
745 if (netif_running(params->dev))
746 netif_wake_queue (params->dev);
747 } else {
748 params->state = RNDIS_INITIALIZED;
749 netif_carrier_off (params->dev);
750 netif_stop_queue (params->dev);
751 }
752 break;
David Brownell7e27f182006-06-13 09:54:40 -0700753
Linus Torvalds1da177e2005-04-16 15:20:36 -0700754 case OID_802_3_MULTICAST_LIST:
David Brownell7e27f182006-06-13 09:54:40 -0700755 /* I think we can ignore this */
Harvey Harrison441b62c2008-03-03 16:08:34 -0800756 DBG("%s: OID_802_3_MULTICAST_LIST\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700757 retval = 0;
758 break;
759#if 0
760 case OID_GEN_RNDIS_CONFIG_PARAMETER:
761 {
762 struct rndis_config_parameter *param;
763 param = (struct rndis_config_parameter *) buf;
David Brownell70790f62007-07-01 17:35:28 -0700764 DBG("%s: OID_GEN_RNDIS_CONFIG_PARAMETER '%*s'\n",
Harvey Harrison441b62c2008-03-03 16:08:34 -0800765 __func__,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700766 min(cpu_to_le32(param->ParameterNameLength),80),
767 buf + param->ParameterNameOffset);
768 retval = 0;
769 }
770 break;
771#endif
772
773#ifdef RNDIS_PM
774 case OID_PNP_SET_POWER:
David Brownell340600a2005-04-28 13:45:25 -0700775 /* The only real power state is USB suspend, and RNDIS requests
776 * can't enter it; this one isn't really about power. After
777 * resuming, Windows forces a reset, and then SET_POWER D0.
778 * FIXME ... then things go batty; Windows wedges itself.
779 */
David Brownell01ee7d72007-05-25 20:40:14 -0700780 i = le32_to_cpu(get_unaligned((__le32 *)buf));
Harvey Harrison441b62c2008-03-03 16:08:34 -0800781 DBG("%s: OID_PNP_SET_POWER D%d\n", __func__, i - 1);
David Brownell340600a2005-04-28 13:45:25 -0700782 switch (i) {
783 case NdisDeviceStateD0:
784 *params->filter = params->saved_filter;
785 goto update_linkstate;
786 case NdisDeviceStateD3:
787 case NdisDeviceStateD2:
788 case NdisDeviceStateD1:
789 params->saved_filter = *params->filter;
790 retval = 0;
791 break;
792 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700793 break;
794
David Brownell340600a2005-04-28 13:45:25 -0700795#ifdef RNDIS_WAKEUP
796 // no wakeup support advertised, so wakeup OIDs always fail:
797 // - OID_PNP_ENABLE_WAKE_UP
798 // - OID_PNP_{ADD,REMOVE}_WAKE_UP_PATTERN
Linus Torvalds1da177e2005-04-16 15:20:36 -0700799#endif
800
David Brownell340600a2005-04-28 13:45:25 -0700801#endif /* RNDIS_PM */
802
Linus Torvalds1da177e2005-04-16 15:20:36 -0700803 default:
David Brownell00274922007-11-19 12:58:36 -0800804 pr_warning("%s: set unknown OID 0x%08X, size %d\n",
Harvey Harrison441b62c2008-03-03 16:08:34 -0800805 __func__, OID, buf_len);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700806 }
David Brownell7e27f182006-06-13 09:54:40 -0700807
Linus Torvalds1da177e2005-04-16 15:20:36 -0700808 return retval;
809}
810
David Brownell7e27f182006-06-13 09:54:40 -0700811/*
812 * Response Functions
Linus Torvalds1da177e2005-04-16 15:20:36 -0700813 */
814
815static int rndis_init_response (int configNr, rndis_init_msg_type *buf)
816{
David Brownell7e27f182006-06-13 09:54:40 -0700817 rndis_init_cmplt_type *resp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700818 rndis_resp_t *r;
David Brownell7e27f182006-06-13 09:54:40 -0700819
Linus Torvalds1da177e2005-04-16 15:20:36 -0700820 if (!rndis_per_dev_params [configNr].dev) return -ENOTSUPP;
David Brownell7e27f182006-06-13 09:54:40 -0700821
Linus Torvalds1da177e2005-04-16 15:20:36 -0700822 r = rndis_add_response (configNr, sizeof (rndis_init_cmplt_type));
David Brownell340600a2005-04-28 13:45:25 -0700823 if (!r)
824 return -ENOMEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700825 resp = (rndis_init_cmplt_type *) r->buf;
David Brownell7e27f182006-06-13 09:54:40 -0700826
Linus Torvalds1da177e2005-04-16 15:20:36 -0700827 resp->MessageType = __constant_cpu_to_le32 (
828 REMOTE_NDIS_INITIALIZE_CMPLT);
829 resp->MessageLength = __constant_cpu_to_le32 (52);
830 resp->RequestID = buf->RequestID; /* Still LE in msg buffer */
831 resp->Status = __constant_cpu_to_le32 (RNDIS_STATUS_SUCCESS);
832 resp->MajorVersion = __constant_cpu_to_le32 (RNDIS_MAJOR_VERSION);
833 resp->MinorVersion = __constant_cpu_to_le32 (RNDIS_MINOR_VERSION);
834 resp->DeviceFlags = __constant_cpu_to_le32 (RNDIS_DF_CONNECTIONLESS);
835 resp->Medium = __constant_cpu_to_le32 (RNDIS_MEDIUM_802_3);
836 resp->MaxPacketsPerTransfer = __constant_cpu_to_le32 (1);
837 resp->MaxTransferSize = cpu_to_le32 (
838 rndis_per_dev_params [configNr].dev->mtu
839 + sizeof (struct ethhdr)
840 + sizeof (struct rndis_packet_msg_type)
841 + 22);
842 resp->PacketAlignmentFactor = __constant_cpu_to_le32 (0);
843 resp->AFListOffset = __constant_cpu_to_le32 (0);
844 resp->AFListSize = __constant_cpu_to_le32 (0);
David Brownell7e27f182006-06-13 09:54:40 -0700845
Linus Torvalds1da177e2005-04-16 15:20:36 -0700846 if (rndis_per_dev_params [configNr].ack)
David Brownell7e27f182006-06-13 09:54:40 -0700847 rndis_per_dev_params [configNr].ack (
848 rndis_per_dev_params [configNr].dev);
849
Linus Torvalds1da177e2005-04-16 15:20:36 -0700850 return 0;
851}
852
853static int rndis_query_response (int configNr, rndis_query_msg_type *buf)
854{
855 rndis_query_cmplt_type *resp;
856 rndis_resp_t *r;
David Brownell7e27f182006-06-13 09:54:40 -0700857
Harvey Harrison441b62c2008-03-03 16:08:34 -0800858 // DBG("%s: OID = %08X\n", __func__, cpu_to_le32(buf->OID));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700859 if (!rndis_per_dev_params [configNr].dev) return -ENOTSUPP;
David Brownell7e27f182006-06-13 09:54:40 -0700860
Shaun Tancheff87637162006-02-22 19:47:19 -0800861 /*
862 * we need more memory:
863 * gen_ndis_query_resp expects enough space for
864 * rndis_query_cmplt_type followed by data.
865 * oid_supported_list is the largest data reply
Linus Torvalds1da177e2005-04-16 15:20:36 -0700866 */
Shaun Tancheff87637162006-02-22 19:47:19 -0800867 r = rndis_add_response (configNr,
868 sizeof (oid_supported_list) + sizeof(rndis_query_cmplt_type));
David Brownell340600a2005-04-28 13:45:25 -0700869 if (!r)
870 return -ENOMEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700871 resp = (rndis_query_cmplt_type *) r->buf;
David Brownell7e27f182006-06-13 09:54:40 -0700872
Linus Torvalds1da177e2005-04-16 15:20:36 -0700873 resp->MessageType = __constant_cpu_to_le32 (REMOTE_NDIS_QUERY_CMPLT);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700874 resp->RequestID = buf->RequestID; /* Still LE in msg buffer */
David Brownell7e27f182006-06-13 09:54:40 -0700875
David Brownell340600a2005-04-28 13:45:25 -0700876 if (gen_ndis_query_resp (configNr, le32_to_cpu (buf->OID),
877 le32_to_cpu(buf->InformationBufferOffset)
878 + 8 + (u8 *) buf,
879 le32_to_cpu(buf->InformationBufferLength),
880 r)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700881 /* OID not supported */
882 resp->Status = __constant_cpu_to_le32 (
883 RNDIS_STATUS_NOT_SUPPORTED);
David Brownell340600a2005-04-28 13:45:25 -0700884 resp->MessageLength = __constant_cpu_to_le32 (sizeof *resp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700885 resp->InformationBufferLength = __constant_cpu_to_le32 (0);
886 resp->InformationBufferOffset = __constant_cpu_to_le32 (0);
887 } else
888 resp->Status = __constant_cpu_to_le32 (RNDIS_STATUS_SUCCESS);
David Brownell7e27f182006-06-13 09:54:40 -0700889
Linus Torvalds1da177e2005-04-16 15:20:36 -0700890 if (rndis_per_dev_params [configNr].ack)
David Brownell7e27f182006-06-13 09:54:40 -0700891 rndis_per_dev_params [configNr].ack (
892 rndis_per_dev_params [configNr].dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700893 return 0;
894}
895
896static int rndis_set_response (int configNr, rndis_set_msg_type *buf)
897{
898 u32 BufLength, BufOffset;
899 rndis_set_cmplt_type *resp;
900 rndis_resp_t *r;
David Brownell7e27f182006-06-13 09:54:40 -0700901
Linus Torvalds1da177e2005-04-16 15:20:36 -0700902 r = rndis_add_response (configNr, sizeof (rndis_set_cmplt_type));
David Brownell340600a2005-04-28 13:45:25 -0700903 if (!r)
904 return -ENOMEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700905 resp = (rndis_set_cmplt_type *) r->buf;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700906
907 BufLength = le32_to_cpu (buf->InformationBufferLength);
908 BufOffset = le32_to_cpu (buf->InformationBufferOffset);
909
910#ifdef VERBOSE
Harvey Harrison441b62c2008-03-03 16:08:34 -0800911 DBG("%s: Length: %d\n", __func__, BufLength);
912 DBG("%s: Offset: %d\n", __func__, BufOffset);
913 DBG("%s: InfoBuffer: ", __func__);
David Brownell7e27f182006-06-13 09:54:40 -0700914
Linus Torvalds1da177e2005-04-16 15:20:36 -0700915 for (i = 0; i < BufLength; i++) {
David Brownell70790f62007-07-01 17:35:28 -0700916 DBG("%02x ", *(((u8 *) buf) + i + 8 + BufOffset));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700917 }
David Brownell7e27f182006-06-13 09:54:40 -0700918
David Brownell70790f62007-07-01 17:35:28 -0700919 DBG("\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700920#endif
David Brownell7e27f182006-06-13 09:54:40 -0700921
Linus Torvalds1da177e2005-04-16 15:20:36 -0700922 resp->MessageType = __constant_cpu_to_le32 (REMOTE_NDIS_SET_CMPLT);
923 resp->MessageLength = __constant_cpu_to_le32 (16);
924 resp->RequestID = buf->RequestID; /* Still LE in msg buffer */
David Brownell7e27f182006-06-13 09:54:40 -0700925 if (gen_ndis_set_resp (configNr, le32_to_cpu (buf->OID),
926 ((u8 *) buf) + 8 + BufOffset, BufLength, r))
927 resp->Status = __constant_cpu_to_le32 (RNDIS_STATUS_NOT_SUPPORTED);
928 else
929 resp->Status = __constant_cpu_to_le32 (RNDIS_STATUS_SUCCESS);
930
Linus Torvalds1da177e2005-04-16 15:20:36 -0700931 if (rndis_per_dev_params [configNr].ack)
David Brownell7e27f182006-06-13 09:54:40 -0700932 rndis_per_dev_params [configNr].ack (
933 rndis_per_dev_params [configNr].dev);
934
Linus Torvalds1da177e2005-04-16 15:20:36 -0700935 return 0;
936}
937
938static int rndis_reset_response (int configNr, rndis_reset_msg_type *buf)
939{
940 rndis_reset_cmplt_type *resp;
941 rndis_resp_t *r;
David Brownell7e27f182006-06-13 09:54:40 -0700942
Linus Torvalds1da177e2005-04-16 15:20:36 -0700943 r = rndis_add_response (configNr, sizeof (rndis_reset_cmplt_type));
David Brownell340600a2005-04-28 13:45:25 -0700944 if (!r)
945 return -ENOMEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700946 resp = (rndis_reset_cmplt_type *) r->buf;
David Brownell7e27f182006-06-13 09:54:40 -0700947
Linus Torvalds1da177e2005-04-16 15:20:36 -0700948 resp->MessageType = __constant_cpu_to_le32 (REMOTE_NDIS_RESET_CMPLT);
949 resp->MessageLength = __constant_cpu_to_le32 (16);
950 resp->Status = __constant_cpu_to_le32 (RNDIS_STATUS_SUCCESS);
951 /* resent information */
952 resp->AddressingReset = __constant_cpu_to_le32 (1);
David Brownell7e27f182006-06-13 09:54:40 -0700953
Linus Torvalds1da177e2005-04-16 15:20:36 -0700954 if (rndis_per_dev_params [configNr].ack)
David Brownell7e27f182006-06-13 09:54:40 -0700955 rndis_per_dev_params [configNr].ack (
956 rndis_per_dev_params [configNr].dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700957
958 return 0;
959}
960
961static int rndis_keepalive_response (int configNr,
David Brownell7e27f182006-06-13 09:54:40 -0700962 rndis_keepalive_msg_type *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700963{
964 rndis_keepalive_cmplt_type *resp;
965 rndis_resp_t *r;
966
967 /* host "should" check only in RNDIS_DATA_INITIALIZED state */
968
969 r = rndis_add_response (configNr, sizeof (rndis_keepalive_cmplt_type));
David Brownell340600a2005-04-28 13:45:25 -0700970 if (!r)
971 return -ENOMEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700972 resp = (rndis_keepalive_cmplt_type *) r->buf;
David Brownell7e27f182006-06-13 09:54:40 -0700973
Linus Torvalds1da177e2005-04-16 15:20:36 -0700974 resp->MessageType = __constant_cpu_to_le32 (
975 REMOTE_NDIS_KEEPALIVE_CMPLT);
976 resp->MessageLength = __constant_cpu_to_le32 (16);
977 resp->RequestID = buf->RequestID; /* Still LE in msg buffer */
978 resp->Status = __constant_cpu_to_le32 (RNDIS_STATUS_SUCCESS);
David Brownell7e27f182006-06-13 09:54:40 -0700979
Linus Torvalds1da177e2005-04-16 15:20:36 -0700980 if (rndis_per_dev_params [configNr].ack)
David Brownell7e27f182006-06-13 09:54:40 -0700981 rndis_per_dev_params [configNr].ack (
982 rndis_per_dev_params [configNr].dev);
983
Linus Torvalds1da177e2005-04-16 15:20:36 -0700984 return 0;
985}
986
987
David Brownell7e27f182006-06-13 09:54:40 -0700988/*
989 * Device to Host Comunication
Linus Torvalds1da177e2005-04-16 15:20:36 -0700990 */
991static int rndis_indicate_status_msg (int configNr, u32 status)
992{
David Brownell7e27f182006-06-13 09:54:40 -0700993 rndis_indicate_status_msg_type *resp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700994 rndis_resp_t *r;
David Brownell7e27f182006-06-13 09:54:40 -0700995
Linus Torvalds1da177e2005-04-16 15:20:36 -0700996 if (rndis_per_dev_params [configNr].state == RNDIS_UNINITIALIZED)
David Brownell7e27f182006-06-13 09:54:40 -0700997 return -ENOTSUPP;
998
999 r = rndis_add_response (configNr,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001000 sizeof (rndis_indicate_status_msg_type));
David Brownell340600a2005-04-28 13:45:25 -07001001 if (!r)
1002 return -ENOMEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001003 resp = (rndis_indicate_status_msg_type *) r->buf;
David Brownell7e27f182006-06-13 09:54:40 -07001004
Linus Torvalds1da177e2005-04-16 15:20:36 -07001005 resp->MessageType = __constant_cpu_to_le32 (
1006 REMOTE_NDIS_INDICATE_STATUS_MSG);
1007 resp->MessageLength = __constant_cpu_to_le32 (20);
1008 resp->Status = cpu_to_le32 (status);
1009 resp->StatusBufferLength = __constant_cpu_to_le32 (0);
1010 resp->StatusBufferOffset = __constant_cpu_to_le32 (0);
David Brownell7e27f182006-06-13 09:54:40 -07001011
1012 if (rndis_per_dev_params [configNr].ack)
1013 rndis_per_dev_params [configNr].ack (
1014 rndis_per_dev_params [configNr].dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001015 return 0;
1016}
1017
1018int rndis_signal_connect (int configNr)
1019{
1020 rndis_per_dev_params [configNr].media_state
1021 = NDIS_MEDIA_STATE_CONNECTED;
David Brownell7e27f182006-06-13 09:54:40 -07001022 return rndis_indicate_status_msg (configNr,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001023 RNDIS_STATUS_MEDIA_CONNECT);
1024}
1025
1026int rndis_signal_disconnect (int configNr)
1027{
1028 rndis_per_dev_params [configNr].media_state
1029 = NDIS_MEDIA_STATE_DISCONNECTED;
1030 return rndis_indicate_status_msg (configNr,
1031 RNDIS_STATUS_MEDIA_DISCONNECT);
1032}
1033
David Brownell340600a2005-04-28 13:45:25 -07001034void rndis_uninit (int configNr)
1035{
David Brownell486e2df2005-05-24 17:51:52 -07001036 u8 *buf;
1037 u32 length;
1038
David Brownell340600a2005-04-28 13:45:25 -07001039 if (configNr >= RNDIS_MAX_CONFIGS)
1040 return;
1041 rndis_per_dev_params [configNr].used = 0;
1042 rndis_per_dev_params [configNr].state = RNDIS_UNINITIALIZED;
David Brownell486e2df2005-05-24 17:51:52 -07001043
1044 /* drain the response queue */
1045 while ((buf = rndis_get_next_response(configNr, &length)))
1046 rndis_free_response(configNr, buf);
David Brownell340600a2005-04-28 13:45:25 -07001047}
1048
Linus Torvalds1da177e2005-04-16 15:20:36 -07001049void rndis_set_host_mac (int configNr, const u8 *addr)
1050{
1051 rndis_per_dev_params [configNr].host_mac = addr;
1052}
1053
David Brownell7e27f182006-06-13 09:54:40 -07001054/*
1055 * Message Parser
Linus Torvalds1da177e2005-04-16 15:20:36 -07001056 */
1057int rndis_msg_parser (u8 configNr, u8 *buf)
1058{
1059 u32 MsgType, MsgLength;
1060 __le32 *tmp;
1061 struct rndis_params *params;
David Brownell7e27f182006-06-13 09:54:40 -07001062
Linus Torvalds1da177e2005-04-16 15:20:36 -07001063 if (!buf)
1064 return -ENOMEM;
David Brownell7e27f182006-06-13 09:54:40 -07001065
1066 tmp = (__le32 *) buf;
David Brownell01ee7d72007-05-25 20:40:14 -07001067 MsgType = le32_to_cpu(get_unaligned(tmp++));
1068 MsgLength = le32_to_cpu(get_unaligned(tmp++));
David Brownell7e27f182006-06-13 09:54:40 -07001069
Linus Torvalds1da177e2005-04-16 15:20:36 -07001070 if (configNr >= RNDIS_MAX_CONFIGS)
1071 return -ENOTSUPP;
1072 params = &rndis_per_dev_params [configNr];
David Brownell7e27f182006-06-13 09:54:40 -07001073
David Brownell340600a2005-04-28 13:45:25 -07001074 /* NOTE: RNDIS is *EXTREMELY* chatty ... Windows constantly polls for
1075 * rx/tx statistics and link status, in addition to KEEPALIVE traffic
1076 * and normal HC level polling to see if there's any IN traffic.
1077 */
1078
Linus Torvalds1da177e2005-04-16 15:20:36 -07001079 /* For USB: responses may take up to 10 seconds */
David Brownell340600a2005-04-28 13:45:25 -07001080 switch (MsgType) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001081 case REMOTE_NDIS_INITIALIZE_MSG:
David Brownell70790f62007-07-01 17:35:28 -07001082 DBG("%s: REMOTE_NDIS_INITIALIZE_MSG\n",
Harvey Harrison441b62c2008-03-03 16:08:34 -08001083 __func__ );
Linus Torvalds1da177e2005-04-16 15:20:36 -07001084 params->state = RNDIS_INITIALIZED;
1085 return rndis_init_response (configNr,
David Brownell7e27f182006-06-13 09:54:40 -07001086 (rndis_init_msg_type *) buf);
1087
Linus Torvalds1da177e2005-04-16 15:20:36 -07001088 case REMOTE_NDIS_HALT_MSG:
David Brownell70790f62007-07-01 17:35:28 -07001089 DBG("%s: REMOTE_NDIS_HALT_MSG\n",
Harvey Harrison441b62c2008-03-03 16:08:34 -08001090 __func__ );
Linus Torvalds1da177e2005-04-16 15:20:36 -07001091 params->state = RNDIS_UNINITIALIZED;
1092 if (params->dev) {
1093 netif_carrier_off (params->dev);
1094 netif_stop_queue (params->dev);
1095 }
1096 return 0;
David Brownell7e27f182006-06-13 09:54:40 -07001097
Linus Torvalds1da177e2005-04-16 15:20:36 -07001098 case REMOTE_NDIS_QUERY_MSG:
David Brownell7e27f182006-06-13 09:54:40 -07001099 return rndis_query_response (configNr,
1100 (rndis_query_msg_type *) buf);
1101
Linus Torvalds1da177e2005-04-16 15:20:36 -07001102 case REMOTE_NDIS_SET_MSG:
David Brownell7e27f182006-06-13 09:54:40 -07001103 return rndis_set_response (configNr,
1104 (rndis_set_msg_type *) buf);
1105
Linus Torvalds1da177e2005-04-16 15:20:36 -07001106 case REMOTE_NDIS_RESET_MSG:
David Brownell70790f62007-07-01 17:35:28 -07001107 DBG("%s: REMOTE_NDIS_RESET_MSG\n",
Harvey Harrison441b62c2008-03-03 16:08:34 -08001108 __func__ );
Linus Torvalds1da177e2005-04-16 15:20:36 -07001109 return rndis_reset_response (configNr,
David Brownell7e27f182006-06-13 09:54:40 -07001110 (rndis_reset_msg_type *) buf);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001111
1112 case REMOTE_NDIS_KEEPALIVE_MSG:
1113 /* For USB: host does this every 5 seconds */
David Brownell340600a2005-04-28 13:45:25 -07001114 if (rndis_debug > 1)
David Brownell70790f62007-07-01 17:35:28 -07001115 DBG("%s: REMOTE_NDIS_KEEPALIVE_MSG\n",
Harvey Harrison441b62c2008-03-03 16:08:34 -08001116 __func__ );
Linus Torvalds1da177e2005-04-16 15:20:36 -07001117 return rndis_keepalive_response (configNr,
David Brownell7e27f182006-06-13 09:54:40 -07001118 (rndis_keepalive_msg_type *)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001119 buf);
David Brownell7e27f182006-06-13 09:54:40 -07001120
1121 default:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001122 /* At least Windows XP emits some undefined RNDIS messages.
1123 * In one case those messages seemed to relate to the host
1124 * suspending itself.
1125 */
David Brownell00274922007-11-19 12:58:36 -08001126 pr_warning("%s: unknown RNDIS message 0x%08X len %d\n",
Harvey Harrison441b62c2008-03-03 16:08:34 -08001127 __func__ , MsgType, MsgLength);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001128 {
1129 unsigned i;
1130 for (i = 0; i < MsgLength; i += 16) {
David Brownell70790f62007-07-01 17:35:28 -07001131 DBG("%03d: "
Linus Torvalds1da177e2005-04-16 15:20:36 -07001132 " %02x %02x %02x %02x"
1133 " %02x %02x %02x %02x"
1134 " %02x %02x %02x %02x"
1135 " %02x %02x %02x %02x"
1136 "\n",
1137 i,
1138 buf[i], buf [i+1],
1139 buf[i+2], buf[i+3],
1140 buf[i+4], buf [i+5],
1141 buf[i+6], buf[i+7],
1142 buf[i+8], buf [i+9],
1143 buf[i+10], buf[i+11],
1144 buf[i+12], buf [i+13],
1145 buf[i+14], buf[i+15]);
1146 }
1147 }
1148 break;
1149 }
David Brownell7e27f182006-06-13 09:54:40 -07001150
Linus Torvalds1da177e2005-04-16 15:20:36 -07001151 return -ENOTSUPP;
1152}
1153
1154int rndis_register (int (* rndis_control_ack) (struct net_device *))
1155{
1156 u8 i;
David Brownell7e27f182006-06-13 09:54:40 -07001157
Linus Torvalds1da177e2005-04-16 15:20:36 -07001158 for (i = 0; i < RNDIS_MAX_CONFIGS; i++) {
1159 if (!rndis_per_dev_params [i].used) {
1160 rndis_per_dev_params [i].used = 1;
1161 rndis_per_dev_params [i].ack = rndis_control_ack;
Harvey Harrison441b62c2008-03-03 16:08:34 -08001162 DBG("%s: configNr = %d\n", __func__, i);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001163 return i;
1164 }
1165 }
David Brownell70790f62007-07-01 17:35:28 -07001166 DBG("failed\n");
David Brownell7e27f182006-06-13 09:54:40 -07001167
Linus Torvalds1da177e2005-04-16 15:20:36 -07001168 return -1;
1169}
1170
1171void rndis_deregister (int configNr)
1172{
Harvey Harrison441b62c2008-03-03 16:08:34 -08001173 DBG("%s: \n", __func__ );
David Brownell7e27f182006-06-13 09:54:40 -07001174
Linus Torvalds1da177e2005-04-16 15:20:36 -07001175 if (configNr >= RNDIS_MAX_CONFIGS) return;
1176 rndis_per_dev_params [configNr].used = 0;
David Brownell7e27f182006-06-13 09:54:40 -07001177
Linus Torvalds1da177e2005-04-16 15:20:36 -07001178 return;
1179}
1180
David Brownell7e27f182006-06-13 09:54:40 -07001181int rndis_set_param_dev (u8 configNr, struct net_device *dev,
David Brownell340600a2005-04-28 13:45:25 -07001182 struct net_device_stats *stats,
1183 u16 *cdc_filter)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001184{
Harvey Harrison441b62c2008-03-03 16:08:34 -08001185 DBG("%s:\n", __func__ );
Linus Torvalds1da177e2005-04-16 15:20:36 -07001186 if (!dev || !stats) return -1;
1187 if (configNr >= RNDIS_MAX_CONFIGS) return -1;
David Brownell7e27f182006-06-13 09:54:40 -07001188
Linus Torvalds1da177e2005-04-16 15:20:36 -07001189 rndis_per_dev_params [configNr].dev = dev;
1190 rndis_per_dev_params [configNr].stats = stats;
David Brownell340600a2005-04-28 13:45:25 -07001191 rndis_per_dev_params [configNr].filter = cdc_filter;
David Brownell7e27f182006-06-13 09:54:40 -07001192
Linus Torvalds1da177e2005-04-16 15:20:36 -07001193 return 0;
1194}
1195
1196int rndis_set_param_vendor (u8 configNr, u32 vendorID, const char *vendorDescr)
1197{
Harvey Harrison441b62c2008-03-03 16:08:34 -08001198 DBG("%s:\n", __func__ );
Linus Torvalds1da177e2005-04-16 15:20:36 -07001199 if (!vendorDescr) return -1;
1200 if (configNr >= RNDIS_MAX_CONFIGS) return -1;
David Brownell7e27f182006-06-13 09:54:40 -07001201
Linus Torvalds1da177e2005-04-16 15:20:36 -07001202 rndis_per_dev_params [configNr].vendorID = vendorID;
1203 rndis_per_dev_params [configNr].vendorDescr = vendorDescr;
David Brownell7e27f182006-06-13 09:54:40 -07001204
Linus Torvalds1da177e2005-04-16 15:20:36 -07001205 return 0;
1206}
1207
1208int rndis_set_param_medium (u8 configNr, u32 medium, u32 speed)
1209{
Harvey Harrison441b62c2008-03-03 16:08:34 -08001210 DBG("%s: %u %u\n", __func__, medium, speed);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001211 if (configNr >= RNDIS_MAX_CONFIGS) return -1;
David Brownell7e27f182006-06-13 09:54:40 -07001212
Linus Torvalds1da177e2005-04-16 15:20:36 -07001213 rndis_per_dev_params [configNr].medium = medium;
1214 rndis_per_dev_params [configNr].speed = speed;
David Brownell7e27f182006-06-13 09:54:40 -07001215
Linus Torvalds1da177e2005-04-16 15:20:36 -07001216 return 0;
1217}
1218
1219void rndis_add_hdr (struct sk_buff *skb)
1220{
1221 struct rndis_packet_msg_type *header;
1222
1223 if (!skb)
1224 return;
1225 header = (void *) skb_push (skb, sizeof *header);
1226 memset (header, 0, sizeof *header);
David Brownell6cdee102005-04-18 17:39:34 -07001227 header->MessageType = __constant_cpu_to_le32(REMOTE_NDIS_PACKET_MSG);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001228 header->MessageLength = cpu_to_le32(skb->len);
1229 header->DataOffset = __constant_cpu_to_le32 (36);
David Brownell6cdee102005-04-18 17:39:34 -07001230 header->DataLength = cpu_to_le32(skb->len - sizeof *header);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001231}
1232
1233void rndis_free_response (int configNr, u8 *buf)
1234{
1235 rndis_resp_t *r;
1236 struct list_head *act, *tmp;
David Brownell7e27f182006-06-13 09:54:40 -07001237
1238 list_for_each_safe (act, tmp,
1239 &(rndis_per_dev_params [configNr].resp_queue))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001240 {
1241 r = list_entry (act, rndis_resp_t, list);
1242 if (r && r->buf == buf) {
1243 list_del (&r->list);
1244 kfree (r);
1245 }
1246 }
1247}
1248
1249u8 *rndis_get_next_response (int configNr, u32 *length)
1250{
1251 rndis_resp_t *r;
David Brownell7e27f182006-06-13 09:54:40 -07001252 struct list_head *act, *tmp;
1253
Linus Torvalds1da177e2005-04-16 15:20:36 -07001254 if (!length) return NULL;
David Brownell7e27f182006-06-13 09:54:40 -07001255
1256 list_for_each_safe (act, tmp,
1257 &(rndis_per_dev_params [configNr].resp_queue))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001258 {
1259 r = list_entry (act, rndis_resp_t, list);
1260 if (!r->send) {
1261 r->send = 1;
1262 *length = r->length;
1263 return r->buf;
1264 }
1265 }
David Brownell7e27f182006-06-13 09:54:40 -07001266
Linus Torvalds1da177e2005-04-16 15:20:36 -07001267 return NULL;
1268}
1269
1270static rndis_resp_t *rndis_add_response (int configNr, u32 length)
1271{
1272 rndis_resp_t *r;
David Brownell7e27f182006-06-13 09:54:40 -07001273
David Brownell340600a2005-04-28 13:45:25 -07001274 /* NOTE: this gets copied into ether.c USB_BUFSIZ bytes ... */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001275 r = kmalloc (sizeof (rndis_resp_t) + length, GFP_ATOMIC);
1276 if (!r) return NULL;
David Brownell7e27f182006-06-13 09:54:40 -07001277
Linus Torvalds1da177e2005-04-16 15:20:36 -07001278 r->buf = (u8 *) (r + 1);
1279 r->length = length;
1280 r->send = 0;
David Brownell7e27f182006-06-13 09:54:40 -07001281
1282 list_add_tail (&r->list,
1283 &(rndis_per_dev_params [configNr].resp_queue));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001284 return r;
1285}
1286
David Brownell6cdee102005-04-18 17:39:34 -07001287int rndis_rm_hdr(struct sk_buff *skb)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001288{
David Brownell6cdee102005-04-18 17:39:34 -07001289 /* tmp points to a struct rndis_packet_msg_type */
1290 __le32 *tmp = (void *) skb->data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001291
David Brownell6cdee102005-04-18 17:39:34 -07001292 /* MessageType, MessageLength */
1293 if (__constant_cpu_to_le32(REMOTE_NDIS_PACKET_MSG)
1294 != get_unaligned(tmp++))
1295 return -EINVAL;
1296 tmp++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001297
David Brownell6cdee102005-04-18 17:39:34 -07001298 /* DataOffset, DataLength */
1299 if (!skb_pull(skb, le32_to_cpu(get_unaligned(tmp++))
1300 + 8 /* offset of DataOffset */))
1301 return -EOVERFLOW;
1302 skb_trim(skb, le32_to_cpu(get_unaligned(tmp++)));
1303
Linus Torvalds1da177e2005-04-16 15:20:36 -07001304 return 0;
1305}
1306
1307#ifdef CONFIG_USB_GADGET_DEBUG_FILES
1308
David Brownell7e27f182006-06-13 09:54:40 -07001309static int rndis_proc_read (char *page, char **start, off_t off, int count, int *eof,
1310 void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001311{
1312 char *out = page;
1313 int len;
1314 rndis_params *param = (rndis_params *) data;
David Brownell7e27f182006-06-13 09:54:40 -07001315
1316 out += snprintf (out, count,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001317 "Config Nr. %d\n"
1318 "used : %s\n"
1319 "state : %s\n"
1320 "medium : 0x%08X\n"
1321 "speed : %d\n"
1322 "cable : %s\n"
1323 "vendor ID : 0x%08X\n"
David Brownell7e27f182006-06-13 09:54:40 -07001324 "vendor : %s\n",
1325 param->confignr, (param->used) ? "y" : "n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07001326 ({ char *s = "?";
1327 switch (param->state) {
1328 case RNDIS_UNINITIALIZED:
1329 s = "RNDIS_UNINITIALIZED"; break;
1330 case RNDIS_INITIALIZED:
1331 s = "RNDIS_INITIALIZED"; break;
1332 case RNDIS_DATA_INITIALIZED:
1333 s = "RNDIS_DATA_INITIALIZED"; break;
1334 }; s; }),
David Brownell7e27f182006-06-13 09:54:40 -07001335 param->medium,
1336 (param->media_state) ? 0 : param->speed*100,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001337 (param->media_state) ? "disconnected" : "connected",
David Brownell7e27f182006-06-13 09:54:40 -07001338 param->vendorID, param->vendorDescr);
1339
Linus Torvalds1da177e2005-04-16 15:20:36 -07001340 len = out - page;
1341 len -= off;
David Brownell7e27f182006-06-13 09:54:40 -07001342
Linus Torvalds1da177e2005-04-16 15:20:36 -07001343 if (len < count) {
1344 *eof = 1;
1345 if (len <= 0)
1346 return 0;
1347 } else
1348 len = count;
David Brownell7e27f182006-06-13 09:54:40 -07001349
Linus Torvalds1da177e2005-04-16 15:20:36 -07001350 *start = page + off;
1351 return len;
1352}
1353
David Brownell7e27f182006-06-13 09:54:40 -07001354static int rndis_proc_write (struct file *file, const char __user *buffer,
1355 unsigned long count, void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001356{
1357 rndis_params *p = data;
1358 u32 speed = 0;
1359 int i, fl_speed = 0;
David Brownell7e27f182006-06-13 09:54:40 -07001360
Linus Torvalds1da177e2005-04-16 15:20:36 -07001361 for (i = 0; i < count; i++) {
1362 char c;
1363 if (get_user(c, buffer))
1364 return -EFAULT;
1365 switch (c) {
1366 case '0':
1367 case '1':
1368 case '2':
1369 case '3':
1370 case '4':
1371 case '5':
1372 case '6':
1373 case '7':
1374 case '8':
1375 case '9':
1376 fl_speed = 1;
1377 speed = speed*10 + c - '0';
1378 break;
1379 case 'C':
1380 case 'c':
1381 rndis_signal_connect (p->confignr);
1382 break;
1383 case 'D':
1384 case 'd':
1385 rndis_signal_disconnect(p->confignr);
1386 break;
David Brownell7e27f182006-06-13 09:54:40 -07001387 default:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001388 if (fl_speed) p->speed = speed;
David Brownell70790f62007-07-01 17:35:28 -07001389 else DBG("%c is not valid\n", c);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001390 break;
1391 }
David Brownell7e27f182006-06-13 09:54:40 -07001392
Linus Torvalds1da177e2005-04-16 15:20:36 -07001393 buffer++;
1394 }
David Brownell7e27f182006-06-13 09:54:40 -07001395
Linus Torvalds1da177e2005-04-16 15:20:36 -07001396 return count;
1397}
1398
1399#define NAME_TEMPLATE "driver/rndis-%03d"
1400
1401static struct proc_dir_entry *rndis_connect_state [RNDIS_MAX_CONFIGS];
1402
1403#endif /* CONFIG_USB_GADGET_DEBUG_FILES */
1404
1405
David Brownell0e530b42008-04-05 14:17:14 -07001406int __init rndis_init (void)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001407{
1408 u8 i;
1409
1410 for (i = 0; i < RNDIS_MAX_CONFIGS; i++) {
1411#ifdef CONFIG_USB_GADGET_DEBUG_FILES
1412 char name [20];
1413
1414 sprintf (name, NAME_TEMPLATE, i);
1415 if (!(rndis_connect_state [i]
David Brownell7e27f182006-06-13 09:54:40 -07001416 = create_proc_entry (name, 0660, NULL)))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001417 {
Harvey Harrison441b62c2008-03-03 16:08:34 -08001418 DBG("%s :remove entries", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001419 while (i) {
1420 sprintf (name, NAME_TEMPLATE, --i);
1421 remove_proc_entry (name, NULL);
1422 }
David Brownell70790f62007-07-01 17:35:28 -07001423 DBG("\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001424 return -EIO;
1425 }
1426
Linus Torvalds1da177e2005-04-16 15:20:36 -07001427 rndis_connect_state [i]->write_proc = rndis_proc_write;
1428 rndis_connect_state [i]->read_proc = rndis_proc_read;
1429 rndis_connect_state [i]->data = (void *)
1430 (rndis_per_dev_params + i);
1431#endif
1432 rndis_per_dev_params [i].confignr = i;
1433 rndis_per_dev_params [i].used = 0;
1434 rndis_per_dev_params [i].state = RNDIS_UNINITIALIZED;
1435 rndis_per_dev_params [i].media_state
1436 = NDIS_MEDIA_STATE_DISCONNECTED;
1437 INIT_LIST_HEAD (&(rndis_per_dev_params [i].resp_queue));
1438 }
David Brownell7e27f182006-06-13 09:54:40 -07001439
Linus Torvalds1da177e2005-04-16 15:20:36 -07001440 return 0;
1441}
1442
1443void rndis_exit (void)
1444{
1445#ifdef CONFIG_USB_GADGET_DEBUG_FILES
1446 u8 i;
1447 char name [20];
David Brownell7e27f182006-06-13 09:54:40 -07001448
Linus Torvalds1da177e2005-04-16 15:20:36 -07001449 for (i = 0; i < RNDIS_MAX_CONFIGS; i++) {
1450 sprintf (name, NAME_TEMPLATE, i);
1451 remove_proc_entry (name, NULL);
1452 }
1453#endif
1454}
1455