David Brownell | 7e27f18 | 2006-06-13 09:54:40 -0700 | [diff] [blame] | 1 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2 | * RNDIS MSG parser |
David Brownell | 7e27f18 | 2006-06-13 09:54:40 -0700 | [diff] [blame] | 3 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4 | * Version: $Id: rndis.c,v 1.19 2004/03/25 21:33:46 robert Exp $ |
David Brownell | 7e27f18 | 2006-06-13 09:54:40 -0700 | [diff] [blame] | 5 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6 | * Authors: Benedikt Spranger, Pengutronix |
David Brownell | 7e27f18 | 2006-06-13 09:54:40 -0700 | [diff] [blame] | 7 | * Robert Schwebel, Pengutronix |
| 8 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9 | * This program is free software; you can redistribute it and/or |
| 10 | * modify it under the terms of the GNU General Public License |
David Brownell | 7e27f18 | 2006-06-13 09:54:40 -0700 | [diff] [blame] | 11 | * version 2, as published by the Free Software Foundation. |
| 12 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13 | * This software was originally developed in conformance with |
| 14 | * Microsoft's Remote NDIS Specification License Agreement. |
David Brownell | 7e27f18 | 2006-06-13 09:54:40 -0700 | [diff] [blame] | 15 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 16 | * 03/12/2004 Kai-Uwe Bloem <linux-development@auerswald.de> |
| 17 | * Fixed message length bug in init_response |
David Brownell | 7e27f18 | 2006-06-13 09:54:40 -0700 | [diff] [blame] | 18 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 19 | * 03/25/2004 Kai-Uwe Bloem <linux-development@auerswald.de> |
David Brownell | 7e27f18 | 2006-06-13 09:54:40 -0700 | [diff] [blame] | 20 | * Fixed rndis_rm_hdr length bug. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 21 | * |
| 22 | * Copyright (C) 2004 by David Brownell |
| 23 | * updates to merge with Linux 2.6, better match RNDIS spec |
| 24 | */ |
| 25 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 26 | #include <linux/module.h> |
| 27 | #include <linux/moduleparam.h> |
| 28 | #include <linux/kernel.h> |
| 29 | #include <linux/errno.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 30 | #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 Brownell | 6cdee10 | 2005-04-18 17:39:34 -0700 | [diff] [blame] | 38 | #include <asm/unaligned.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 39 | |
| 40 | |
| 41 | #undef RNDIS_PM |
David Brownell | 340600a | 2005-04-28 13:45:25 -0700 | [diff] [blame] | 42 | #undef RNDIS_WAKEUP |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 43 | #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) |
| 60 | static int rndis_debug = 0; |
| 61 | |
David Brownell | 340600a | 2005-04-28 13:45:25 -0700 | [diff] [blame] | 62 | module_param (rndis_debug, int, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 63 | MODULE_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 | |
| 74 | static rndis_params rndis_per_dev_params [RNDIS_MAX_CONFIGS]; |
| 75 | |
| 76 | /* Driver Version */ |
| 77 | static const __le32 rndis_driver_version = __constant_cpu_to_le32 (1); |
| 78 | |
| 79 | /* Function Prototypes */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 80 | static rndis_resp_t *rndis_add_response (int configNr, u32 length); |
| 81 | |
| 82 | |
David Brownell | 340600a | 2005-04-28 13:45:25 -0700 | [diff] [blame] | 83 | /* supported OIDs */ |
David Brownell | 7e27f18 | 2006-06-13 09:54:40 -0700 | [diff] [blame] | 84 | static const u32 oid_supported_list [] = |
David Brownell | 340600a | 2005-04-28 13:45:25 -0700 | [diff] [blame] | 85 | { |
| 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 Brownell | 7e27f18 | 2006-06-13 09:54:40 -0700 | [diff] [blame] | 105 | |
David Brownell | 340600a | 2005-04-28 13:45:25 -0700 | [diff] [blame] | 106 | /* 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 Brownell | 7e27f18 | 2006-06-13 09:54:40 -0700 | [diff] [blame] | 129 | /* mandatory 802.3 */ |
David Brownell | 340600a | 2005-04-28 13:45:25 -0700 | [diff] [blame] | 130 | /* 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 Brownell | 7e27f18 | 2006-06-13 09:54:40 -0700 | [diff] [blame] | 136 | |
David Brownell | 340600a | 2005-04-28 13:45:25 -0700 | [diff] [blame] | 137 | /* 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 Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 169 | /* NDIS Functions */ |
David Brownell | 340600a | 2005-04-28 13:45:25 -0700 | [diff] [blame] | 170 | static int |
| 171 | gen_ndis_query_resp (int configNr, u32 OID, u8 *buf, unsigned buf_len, |
| 172 | rndis_resp_t *r) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 173 | { |
David Brownell | 7e27f18 | 2006-06-13 09:54:40 -0700 | [diff] [blame] | 174 | int retval = -ENOTSUPP; |
| 175 | u32 length = 4; /* usually */ |
David Brownell | 340600a | 2005-04-28 13:45:25 -0700 | [diff] [blame] | 176 | __le32 *outbuf; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 177 | 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 Brownell | 340600a | 2005-04-28 13:45:25 -0700 | [diff] [blame] | 184 | |
| 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, |
| 189 | le32_to_cpup((__le32 *)&buf[i]), |
| 190 | le32_to_cpup((__le32 *)&buf[i + 4]), |
| 191 | le32_to_cpup((__le32 *)&buf[i + 8]), |
| 192 | le32_to_cpup((__le32 *)&buf[i + 12])); |
| 193 | } |
| 194 | } |
| 195 | |
| 196 | /* response goes here, right after the header */ |
| 197 | outbuf = (__le32 *) &resp[1]; |
| 198 | resp->InformationBufferOffset = __constant_cpu_to_le32 (16); |
| 199 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 200 | switch (OID) { |
| 201 | |
| 202 | /* general oids (table 4-1) */ |
| 203 | |
| 204 | /* mandatory */ |
| 205 | case OID_GEN_SUPPORTED_LIST: |
| 206 | DEBUG ("%s: OID_GEN_SUPPORTED_LIST\n", __FUNCTION__); |
| 207 | length = sizeof (oid_supported_list); |
| 208 | count = length / sizeof (u32); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 209 | for (i = 0; i < count; i++) |
David Brownell | 340600a | 2005-04-28 13:45:25 -0700 | [diff] [blame] | 210 | outbuf[i] = cpu_to_le32 (oid_supported_list[i]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 211 | retval = 0; |
| 212 | break; |
David Brownell | 7e27f18 | 2006-06-13 09:54:40 -0700 | [diff] [blame] | 213 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 214 | /* mandatory */ |
| 215 | case OID_GEN_HARDWARE_STATUS: |
| 216 | DEBUG("%s: OID_GEN_HARDWARE_STATUS\n", __FUNCTION__); |
David Brownell | 7e27f18 | 2006-06-13 09:54:40 -0700 | [diff] [blame] | 217 | /* Bogus question! |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 218 | * Hardware must be ready to receive high level protocols. |
David Brownell | 7e27f18 | 2006-06-13 09:54:40 -0700 | [diff] [blame] | 219 | * BTW: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 220 | * reddite ergo quae sunt Caesaris Caesari |
| 221 | * et quae sunt Dei Deo! |
| 222 | */ |
David Brownell | 340600a | 2005-04-28 13:45:25 -0700 | [diff] [blame] | 223 | *outbuf = __constant_cpu_to_le32 (0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 224 | retval = 0; |
| 225 | break; |
David Brownell | 7e27f18 | 2006-06-13 09:54:40 -0700 | [diff] [blame] | 226 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 227 | /* mandatory */ |
| 228 | case OID_GEN_MEDIA_SUPPORTED: |
| 229 | DEBUG("%s: OID_GEN_MEDIA_SUPPORTED\n", __FUNCTION__); |
David Brownell | 340600a | 2005-04-28 13:45:25 -0700 | [diff] [blame] | 230 | *outbuf = cpu_to_le32 (rndis_per_dev_params [configNr].medium); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 231 | retval = 0; |
| 232 | break; |
David Brownell | 7e27f18 | 2006-06-13 09:54:40 -0700 | [diff] [blame] | 233 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 234 | /* mandatory */ |
| 235 | case OID_GEN_MEDIA_IN_USE: |
| 236 | DEBUG("%s: OID_GEN_MEDIA_IN_USE\n", __FUNCTION__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 237 | /* one medium, one transport... (maybe you do it better) */ |
David Brownell | 340600a | 2005-04-28 13:45:25 -0700 | [diff] [blame] | 238 | *outbuf = cpu_to_le32 (rndis_per_dev_params [configNr].medium); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 239 | retval = 0; |
| 240 | break; |
David Brownell | 7e27f18 | 2006-06-13 09:54:40 -0700 | [diff] [blame] | 241 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 242 | /* mandatory */ |
| 243 | case OID_GEN_MAXIMUM_FRAME_SIZE: |
| 244 | DEBUG("%s: OID_GEN_MAXIMUM_FRAME_SIZE\n", __FUNCTION__); |
| 245 | if (rndis_per_dev_params [configNr].dev) { |
David Brownell | 340600a | 2005-04-28 13:45:25 -0700 | [diff] [blame] | 246 | *outbuf = cpu_to_le32 ( |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 247 | rndis_per_dev_params [configNr].dev->mtu); |
| 248 | retval = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 249 | } |
| 250 | break; |
David Brownell | 7e27f18 | 2006-06-13 09:54:40 -0700 | [diff] [blame] | 251 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 252 | /* mandatory */ |
| 253 | case OID_GEN_LINK_SPEED: |
David Brownell | 340600a | 2005-04-28 13:45:25 -0700 | [diff] [blame] | 254 | if (rndis_debug > 1) |
| 255 | DEBUG("%s: OID_GEN_LINK_SPEED\n", __FUNCTION__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 256 | if (rndis_per_dev_params [configNr].media_state |
David Brownell | 340600a | 2005-04-28 13:45:25 -0700 | [diff] [blame] | 257 | == NDIS_MEDIA_STATE_DISCONNECTED) |
| 258 | *outbuf = __constant_cpu_to_le32 (0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 259 | else |
David Brownell | 340600a | 2005-04-28 13:45:25 -0700 | [diff] [blame] | 260 | *outbuf = cpu_to_le32 ( |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 261 | rndis_per_dev_params [configNr].speed); |
| 262 | retval = 0; |
| 263 | break; |
| 264 | |
| 265 | /* mandatory */ |
| 266 | case OID_GEN_TRANSMIT_BLOCK_SIZE: |
| 267 | DEBUG("%s: OID_GEN_TRANSMIT_BLOCK_SIZE\n", __FUNCTION__); |
| 268 | if (rndis_per_dev_params [configNr].dev) { |
David Brownell | 340600a | 2005-04-28 13:45:25 -0700 | [diff] [blame] | 269 | *outbuf = cpu_to_le32 ( |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 270 | rndis_per_dev_params [configNr].dev->mtu); |
| 271 | retval = 0; |
| 272 | } |
| 273 | break; |
David Brownell | 7e27f18 | 2006-06-13 09:54:40 -0700 | [diff] [blame] | 274 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 275 | /* mandatory */ |
| 276 | case OID_GEN_RECEIVE_BLOCK_SIZE: |
| 277 | DEBUG("%s: OID_GEN_RECEIVE_BLOCK_SIZE\n", __FUNCTION__); |
| 278 | if (rndis_per_dev_params [configNr].dev) { |
David Brownell | 340600a | 2005-04-28 13:45:25 -0700 | [diff] [blame] | 279 | *outbuf = cpu_to_le32 ( |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 280 | rndis_per_dev_params [configNr].dev->mtu); |
| 281 | retval = 0; |
| 282 | } |
| 283 | break; |
David Brownell | 7e27f18 | 2006-06-13 09:54:40 -0700 | [diff] [blame] | 284 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 285 | /* mandatory */ |
| 286 | case OID_GEN_VENDOR_ID: |
| 287 | DEBUG("%s: OID_GEN_VENDOR_ID\n", __FUNCTION__); |
David Brownell | 340600a | 2005-04-28 13:45:25 -0700 | [diff] [blame] | 288 | *outbuf = cpu_to_le32 ( |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 289 | rndis_per_dev_params [configNr].vendorID); |
| 290 | retval = 0; |
| 291 | break; |
David Brownell | 7e27f18 | 2006-06-13 09:54:40 -0700 | [diff] [blame] | 292 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 293 | /* mandatory */ |
| 294 | case OID_GEN_VENDOR_DESCRIPTION: |
| 295 | DEBUG("%s: OID_GEN_VENDOR_DESCRIPTION\n", __FUNCTION__); |
| 296 | length = strlen (rndis_per_dev_params [configNr].vendorDescr); |
David Brownell | 340600a | 2005-04-28 13:45:25 -0700 | [diff] [blame] | 297 | memcpy (outbuf, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 298 | rndis_per_dev_params [configNr].vendorDescr, length); |
| 299 | retval = 0; |
| 300 | break; |
| 301 | |
| 302 | case OID_GEN_VENDOR_DRIVER_VERSION: |
| 303 | DEBUG("%s: OID_GEN_VENDOR_DRIVER_VERSION\n", __FUNCTION__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 304 | /* Created as LE */ |
David Brownell | 340600a | 2005-04-28 13:45:25 -0700 | [diff] [blame] | 305 | *outbuf = rndis_driver_version; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 306 | retval = 0; |
| 307 | break; |
| 308 | |
| 309 | /* mandatory */ |
| 310 | case OID_GEN_CURRENT_PACKET_FILTER: |
| 311 | DEBUG("%s: OID_GEN_CURRENT_PACKET_FILTER\n", __FUNCTION__); |
David Brownell | 340600a | 2005-04-28 13:45:25 -0700 | [diff] [blame] | 312 | *outbuf = cpu_to_le32 (*rndis_per_dev_params[configNr].filter); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 313 | retval = 0; |
| 314 | break; |
| 315 | |
| 316 | /* mandatory */ |
| 317 | case OID_GEN_MAXIMUM_TOTAL_SIZE: |
| 318 | DEBUG("%s: OID_GEN_MAXIMUM_TOTAL_SIZE\n", __FUNCTION__); |
David Brownell | 340600a | 2005-04-28 13:45:25 -0700 | [diff] [blame] | 319 | *outbuf = __constant_cpu_to_le32(RNDIS_MAX_TOTAL_SIZE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 320 | retval = 0; |
| 321 | break; |
| 322 | |
| 323 | /* mandatory */ |
| 324 | case OID_GEN_MEDIA_CONNECT_STATUS: |
David Brownell | 340600a | 2005-04-28 13:45:25 -0700 | [diff] [blame] | 325 | if (rndis_debug > 1) |
| 326 | DEBUG("%s: OID_GEN_MEDIA_CONNECT_STATUS\n", __FUNCTION__); |
| 327 | *outbuf = cpu_to_le32 (rndis_per_dev_params [configNr] |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 328 | .media_state); |
| 329 | retval = 0; |
| 330 | break; |
| 331 | |
| 332 | case OID_GEN_PHYSICAL_MEDIUM: |
| 333 | DEBUG("%s: OID_GEN_PHYSICAL_MEDIUM\n", __FUNCTION__); |
David Brownell | 340600a | 2005-04-28 13:45:25 -0700 | [diff] [blame] | 334 | *outbuf = __constant_cpu_to_le32 (0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 335 | retval = 0; |
| 336 | break; |
| 337 | |
| 338 | /* The RNDIS specification is incomplete/wrong. Some versions |
| 339 | * of MS-Windows expect OIDs that aren't specified there. Other |
| 340 | * versions emit undefined RNDIS messages. DOCUMENT ALL THESE! |
| 341 | */ |
| 342 | case OID_GEN_MAC_OPTIONS: /* from WinME */ |
| 343 | DEBUG("%s: OID_GEN_MAC_OPTIONS\n", __FUNCTION__); |
David Brownell | 340600a | 2005-04-28 13:45:25 -0700 | [diff] [blame] | 344 | *outbuf = __constant_cpu_to_le32( |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 345 | NDIS_MAC_OPTION_RECEIVE_SERIALIZED |
| 346 | | NDIS_MAC_OPTION_FULL_DUPLEX); |
| 347 | retval = 0; |
| 348 | break; |
| 349 | |
| 350 | /* statistics OIDs (table 4-2) */ |
| 351 | |
| 352 | /* mandatory */ |
| 353 | case OID_GEN_XMIT_OK: |
David Brownell | 340600a | 2005-04-28 13:45:25 -0700 | [diff] [blame] | 354 | if (rndis_debug > 1) |
| 355 | DEBUG("%s: OID_GEN_XMIT_OK\n", __FUNCTION__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 356 | if (rndis_per_dev_params [configNr].stats) { |
David Brownell | 340600a | 2005-04-28 13:45:25 -0700 | [diff] [blame] | 357 | *outbuf = cpu_to_le32 ( |
David Brownell | 7e27f18 | 2006-06-13 09:54:40 -0700 | [diff] [blame] | 358 | rndis_per_dev_params [configNr].stats->tx_packets - |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 359 | rndis_per_dev_params [configNr].stats->tx_errors - |
| 360 | rndis_per_dev_params [configNr].stats->tx_dropped); |
| 361 | retval = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 362 | } |
| 363 | break; |
| 364 | |
| 365 | /* mandatory */ |
| 366 | case OID_GEN_RCV_OK: |
David Brownell | 340600a | 2005-04-28 13:45:25 -0700 | [diff] [blame] | 367 | if (rndis_debug > 1) |
| 368 | DEBUG("%s: OID_GEN_RCV_OK\n", __FUNCTION__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 369 | if (rndis_per_dev_params [configNr].stats) { |
David Brownell | 340600a | 2005-04-28 13:45:25 -0700 | [diff] [blame] | 370 | *outbuf = cpu_to_le32 ( |
David Brownell | 7e27f18 | 2006-06-13 09:54:40 -0700 | [diff] [blame] | 371 | rndis_per_dev_params [configNr].stats->rx_packets - |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 372 | rndis_per_dev_params [configNr].stats->rx_errors - |
| 373 | rndis_per_dev_params [configNr].stats->rx_dropped); |
| 374 | retval = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 375 | } |
| 376 | break; |
David Brownell | 7e27f18 | 2006-06-13 09:54:40 -0700 | [diff] [blame] | 377 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 378 | /* mandatory */ |
| 379 | case OID_GEN_XMIT_ERROR: |
David Brownell | 340600a | 2005-04-28 13:45:25 -0700 | [diff] [blame] | 380 | if (rndis_debug > 1) |
| 381 | DEBUG("%s: OID_GEN_XMIT_ERROR\n", __FUNCTION__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 382 | if (rndis_per_dev_params [configNr].stats) { |
David Brownell | 340600a | 2005-04-28 13:45:25 -0700 | [diff] [blame] | 383 | *outbuf = cpu_to_le32 (rndis_per_dev_params [configNr] |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 384 | .stats->tx_errors); |
| 385 | retval = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 386 | } |
| 387 | break; |
David Brownell | 7e27f18 | 2006-06-13 09:54:40 -0700 | [diff] [blame] | 388 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 389 | /* mandatory */ |
| 390 | case OID_GEN_RCV_ERROR: |
David Brownell | 340600a | 2005-04-28 13:45:25 -0700 | [diff] [blame] | 391 | if (rndis_debug > 1) |
| 392 | DEBUG("%s: OID_GEN_RCV_ERROR\n", __FUNCTION__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 393 | if (rndis_per_dev_params [configNr].stats) { |
David Brownell | 340600a | 2005-04-28 13:45:25 -0700 | [diff] [blame] | 394 | *outbuf = cpu_to_le32 (rndis_per_dev_params [configNr] |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 395 | .stats->rx_errors); |
| 396 | retval = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 397 | } |
| 398 | break; |
David Brownell | 7e27f18 | 2006-06-13 09:54:40 -0700 | [diff] [blame] | 399 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 400 | /* mandatory */ |
| 401 | case OID_GEN_RCV_NO_BUFFER: |
| 402 | DEBUG("%s: OID_GEN_RCV_NO_BUFFER\n", __FUNCTION__); |
| 403 | if (rndis_per_dev_params [configNr].stats) { |
David Brownell | 340600a | 2005-04-28 13:45:25 -0700 | [diff] [blame] | 404 | *outbuf = cpu_to_le32 (rndis_per_dev_params [configNr] |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 405 | .stats->rx_dropped); |
| 406 | retval = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 407 | } |
| 408 | break; |
| 409 | |
| 410 | #ifdef RNDIS_OPTIONAL_STATS |
| 411 | case OID_GEN_DIRECTED_BYTES_XMIT: |
| 412 | DEBUG("%s: OID_GEN_DIRECTED_BYTES_XMIT\n", __FUNCTION__); |
David Brownell | 7e27f18 | 2006-06-13 09:54:40 -0700 | [diff] [blame] | 413 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 414 | * Aunt Tilly's size of shoes |
| 415 | * minus antarctica count of penguins |
| 416 | * divided by weight of Alpha Centauri |
| 417 | */ |
| 418 | if (rndis_per_dev_params [configNr].stats) { |
David Brownell | 340600a | 2005-04-28 13:45:25 -0700 | [diff] [blame] | 419 | *outbuf = cpu_to_le32 ( |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 420 | (rndis_per_dev_params [configNr] |
David Brownell | 7e27f18 | 2006-06-13 09:54:40 -0700 | [diff] [blame] | 421 | .stats->tx_packets - |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 422 | rndis_per_dev_params [configNr] |
| 423 | .stats->tx_errors - |
| 424 | rndis_per_dev_params [configNr] |
| 425 | .stats->tx_dropped) |
| 426 | * 123); |
| 427 | retval = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 428 | } |
| 429 | break; |
David Brownell | 7e27f18 | 2006-06-13 09:54:40 -0700 | [diff] [blame] | 430 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 431 | case OID_GEN_DIRECTED_FRAMES_XMIT: |
| 432 | DEBUG("%s: OID_GEN_DIRECTED_FRAMES_XMIT\n", __FUNCTION__); |
| 433 | /* dito */ |
| 434 | if (rndis_per_dev_params [configNr].stats) { |
David Brownell | 340600a | 2005-04-28 13:45:25 -0700 | [diff] [blame] | 435 | *outbuf = cpu_to_le32 ( |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 436 | (rndis_per_dev_params [configNr] |
David Brownell | 7e27f18 | 2006-06-13 09:54:40 -0700 | [diff] [blame] | 437 | .stats->tx_packets - |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 438 | rndis_per_dev_params [configNr] |
| 439 | .stats->tx_errors - |
| 440 | rndis_per_dev_params [configNr] |
| 441 | .stats->tx_dropped) |
| 442 | / 123); |
| 443 | retval = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 444 | } |
| 445 | break; |
David Brownell | 7e27f18 | 2006-06-13 09:54:40 -0700 | [diff] [blame] | 446 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 447 | case OID_GEN_MULTICAST_BYTES_XMIT: |
| 448 | DEBUG("%s: OID_GEN_MULTICAST_BYTES_XMIT\n", __FUNCTION__); |
| 449 | if (rndis_per_dev_params [configNr].stats) { |
David Brownell | 340600a | 2005-04-28 13:45:25 -0700 | [diff] [blame] | 450 | *outbuf = cpu_to_le32 (rndis_per_dev_params [configNr] |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 451 | .stats->multicast*1234); |
| 452 | retval = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 453 | } |
| 454 | break; |
David Brownell | 7e27f18 | 2006-06-13 09:54:40 -0700 | [diff] [blame] | 455 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 456 | case OID_GEN_MULTICAST_FRAMES_XMIT: |
| 457 | DEBUG("%s: OID_GEN_MULTICAST_FRAMES_XMIT\n", __FUNCTION__); |
| 458 | if (rndis_per_dev_params [configNr].stats) { |
David Brownell | 340600a | 2005-04-28 13:45:25 -0700 | [diff] [blame] | 459 | *outbuf = cpu_to_le32 (rndis_per_dev_params [configNr] |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 460 | .stats->multicast); |
| 461 | retval = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 462 | } |
| 463 | break; |
David Brownell | 7e27f18 | 2006-06-13 09:54:40 -0700 | [diff] [blame] | 464 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 465 | case OID_GEN_BROADCAST_BYTES_XMIT: |
| 466 | DEBUG("%s: OID_GEN_BROADCAST_BYTES_XMIT\n", __FUNCTION__); |
| 467 | if (rndis_per_dev_params [configNr].stats) { |
David Brownell | 340600a | 2005-04-28 13:45:25 -0700 | [diff] [blame] | 468 | *outbuf = cpu_to_le32 (rndis_per_dev_params [configNr] |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 469 | .stats->tx_packets/42*255); |
| 470 | retval = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 471 | } |
| 472 | break; |
David Brownell | 7e27f18 | 2006-06-13 09:54:40 -0700 | [diff] [blame] | 473 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 474 | case OID_GEN_BROADCAST_FRAMES_XMIT: |
| 475 | DEBUG("%s: OID_GEN_BROADCAST_FRAMES_XMIT\n", __FUNCTION__); |
| 476 | if (rndis_per_dev_params [configNr].stats) { |
David Brownell | 340600a | 2005-04-28 13:45:25 -0700 | [diff] [blame] | 477 | *outbuf = cpu_to_le32 (rndis_per_dev_params [configNr] |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 478 | .stats->tx_packets/42); |
| 479 | retval = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 480 | } |
| 481 | break; |
David Brownell | 7e27f18 | 2006-06-13 09:54:40 -0700 | [diff] [blame] | 482 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 483 | case OID_GEN_DIRECTED_BYTES_RCV: |
| 484 | DEBUG("%s: OID_GEN_DIRECTED_BYTES_RCV\n", __FUNCTION__); |
David Brownell | 340600a | 2005-04-28 13:45:25 -0700 | [diff] [blame] | 485 | *outbuf = __constant_cpu_to_le32 (0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 486 | retval = 0; |
| 487 | break; |
David Brownell | 7e27f18 | 2006-06-13 09:54:40 -0700 | [diff] [blame] | 488 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 489 | case OID_GEN_DIRECTED_FRAMES_RCV: |
| 490 | DEBUG("%s: OID_GEN_DIRECTED_FRAMES_RCV\n", __FUNCTION__); |
David Brownell | 340600a | 2005-04-28 13:45:25 -0700 | [diff] [blame] | 491 | *outbuf = __constant_cpu_to_le32 (0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 492 | retval = 0; |
| 493 | break; |
David Brownell | 7e27f18 | 2006-06-13 09:54:40 -0700 | [diff] [blame] | 494 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 495 | case OID_GEN_MULTICAST_BYTES_RCV: |
| 496 | DEBUG("%s: OID_GEN_MULTICAST_BYTES_RCV\n", __FUNCTION__); |
| 497 | if (rndis_per_dev_params [configNr].stats) { |
David Brownell | 340600a | 2005-04-28 13:45:25 -0700 | [diff] [blame] | 498 | *outbuf = cpu_to_le32 (rndis_per_dev_params [configNr] |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 499 | .stats->multicast * 1111); |
| 500 | retval = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 501 | } |
| 502 | break; |
David Brownell | 7e27f18 | 2006-06-13 09:54:40 -0700 | [diff] [blame] | 503 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 504 | case OID_GEN_MULTICAST_FRAMES_RCV: |
| 505 | DEBUG("%s: OID_GEN_MULTICAST_FRAMES_RCV\n", __FUNCTION__); |
| 506 | if (rndis_per_dev_params [configNr].stats) { |
David Brownell | 340600a | 2005-04-28 13:45:25 -0700 | [diff] [blame] | 507 | *outbuf = cpu_to_le32 (rndis_per_dev_params [configNr] |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 508 | .stats->multicast); |
| 509 | retval = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 510 | } |
| 511 | break; |
David Brownell | 7e27f18 | 2006-06-13 09:54:40 -0700 | [diff] [blame] | 512 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 513 | case OID_GEN_BROADCAST_BYTES_RCV: |
| 514 | DEBUG("%s: OID_GEN_BROADCAST_BYTES_RCV\n", __FUNCTION__); |
| 515 | if (rndis_per_dev_params [configNr].stats) { |
David Brownell | 340600a | 2005-04-28 13:45:25 -0700 | [diff] [blame] | 516 | *outbuf = cpu_to_le32 (rndis_per_dev_params [configNr] |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 517 | .stats->rx_packets/42*255); |
| 518 | retval = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 519 | } |
| 520 | break; |
David Brownell | 7e27f18 | 2006-06-13 09:54:40 -0700 | [diff] [blame] | 521 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 522 | case OID_GEN_BROADCAST_FRAMES_RCV: |
| 523 | DEBUG("%s: OID_GEN_BROADCAST_FRAMES_RCV\n", __FUNCTION__); |
| 524 | if (rndis_per_dev_params [configNr].stats) { |
David Brownell | 340600a | 2005-04-28 13:45:25 -0700 | [diff] [blame] | 525 | *outbuf = cpu_to_le32 (rndis_per_dev_params [configNr] |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 526 | .stats->rx_packets/42); |
| 527 | retval = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 528 | } |
| 529 | break; |
David Brownell | 7e27f18 | 2006-06-13 09:54:40 -0700 | [diff] [blame] | 530 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 531 | case OID_GEN_RCV_CRC_ERROR: |
| 532 | DEBUG("%s: OID_GEN_RCV_CRC_ERROR\n", __FUNCTION__); |
| 533 | if (rndis_per_dev_params [configNr].stats) { |
David Brownell | 340600a | 2005-04-28 13:45:25 -0700 | [diff] [blame] | 534 | *outbuf = cpu_to_le32 (rndis_per_dev_params [configNr] |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 535 | .stats->rx_crc_errors); |
| 536 | retval = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 537 | } |
| 538 | break; |
David Brownell | 7e27f18 | 2006-06-13 09:54:40 -0700 | [diff] [blame] | 539 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 540 | case OID_GEN_TRANSMIT_QUEUE_LENGTH: |
| 541 | DEBUG("%s: OID_GEN_TRANSMIT_QUEUE_LENGTH\n", __FUNCTION__); |
David Brownell | 340600a | 2005-04-28 13:45:25 -0700 | [diff] [blame] | 542 | *outbuf = __constant_cpu_to_le32 (0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 543 | retval = 0; |
| 544 | break; |
| 545 | #endif /* RNDIS_OPTIONAL_STATS */ |
| 546 | |
| 547 | /* ieee802.3 OIDs (table 4-3) */ |
| 548 | |
| 549 | /* mandatory */ |
| 550 | case OID_802_3_PERMANENT_ADDRESS: |
| 551 | DEBUG("%s: OID_802_3_PERMANENT_ADDRESS\n", __FUNCTION__); |
| 552 | if (rndis_per_dev_params [configNr].dev) { |
| 553 | length = ETH_ALEN; |
David Brownell | 340600a | 2005-04-28 13:45:25 -0700 | [diff] [blame] | 554 | memcpy (outbuf, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 555 | rndis_per_dev_params [configNr].host_mac, |
| 556 | length); |
| 557 | retval = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 558 | } |
| 559 | break; |
David Brownell | 7e27f18 | 2006-06-13 09:54:40 -0700 | [diff] [blame] | 560 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 561 | /* mandatory */ |
| 562 | case OID_802_3_CURRENT_ADDRESS: |
| 563 | DEBUG("%s: OID_802_3_CURRENT_ADDRESS\n", __FUNCTION__); |
| 564 | if (rndis_per_dev_params [configNr].dev) { |
| 565 | length = ETH_ALEN; |
David Brownell | 340600a | 2005-04-28 13:45:25 -0700 | [diff] [blame] | 566 | memcpy (outbuf, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 567 | rndis_per_dev_params [configNr].host_mac, |
| 568 | length); |
| 569 | retval = 0; |
| 570 | } |
| 571 | break; |
David Brownell | 7e27f18 | 2006-06-13 09:54:40 -0700 | [diff] [blame] | 572 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 573 | /* mandatory */ |
| 574 | case OID_802_3_MULTICAST_LIST: |
| 575 | DEBUG("%s: OID_802_3_MULTICAST_LIST\n", __FUNCTION__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 576 | /* Multicast base address only */ |
David Brownell | 340600a | 2005-04-28 13:45:25 -0700 | [diff] [blame] | 577 | *outbuf = __constant_cpu_to_le32 (0xE0000000); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 578 | retval = 0; |
| 579 | break; |
David Brownell | 7e27f18 | 2006-06-13 09:54:40 -0700 | [diff] [blame] | 580 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 581 | /* mandatory */ |
| 582 | case OID_802_3_MAXIMUM_LIST_SIZE: |
| 583 | DEBUG("%s: OID_802_3_MAXIMUM_LIST_SIZE\n", __FUNCTION__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 584 | /* Multicast base address only */ |
David Brownell | 340600a | 2005-04-28 13:45:25 -0700 | [diff] [blame] | 585 | *outbuf = __constant_cpu_to_le32 (1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 586 | retval = 0; |
| 587 | break; |
David Brownell | 7e27f18 | 2006-06-13 09:54:40 -0700 | [diff] [blame] | 588 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 589 | case OID_802_3_MAC_OPTIONS: |
| 590 | DEBUG("%s: OID_802_3_MAC_OPTIONS\n", __FUNCTION__); |
| 591 | break; |
| 592 | |
| 593 | /* ieee802.3 statistics OIDs (table 4-4) */ |
| 594 | |
| 595 | /* mandatory */ |
| 596 | case OID_802_3_RCV_ERROR_ALIGNMENT: |
| 597 | DEBUG("%s: OID_802_3_RCV_ERROR_ALIGNMENT\n", __FUNCTION__); |
David Brownell | 340600a | 2005-04-28 13:45:25 -0700 | [diff] [blame] | 598 | if (rndis_per_dev_params [configNr].stats) { |
| 599 | *outbuf = cpu_to_le32 (rndis_per_dev_params [configNr] |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 600 | .stats->rx_frame_errors); |
| 601 | retval = 0; |
| 602 | } |
| 603 | break; |
David Brownell | 7e27f18 | 2006-06-13 09:54:40 -0700 | [diff] [blame] | 604 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 605 | /* mandatory */ |
| 606 | case OID_802_3_XMIT_ONE_COLLISION: |
| 607 | DEBUG("%s: OID_802_3_XMIT_ONE_COLLISION\n", __FUNCTION__); |
David Brownell | 340600a | 2005-04-28 13:45:25 -0700 | [diff] [blame] | 608 | *outbuf = __constant_cpu_to_le32 (0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 609 | retval = 0; |
| 610 | break; |
David Brownell | 7e27f18 | 2006-06-13 09:54:40 -0700 | [diff] [blame] | 611 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 612 | /* mandatory */ |
| 613 | case OID_802_3_XMIT_MORE_COLLISIONS: |
| 614 | DEBUG("%s: OID_802_3_XMIT_MORE_COLLISIONS\n", __FUNCTION__); |
David Brownell | 340600a | 2005-04-28 13:45:25 -0700 | [diff] [blame] | 615 | *outbuf = __constant_cpu_to_le32 (0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 616 | retval = 0; |
| 617 | break; |
David Brownell | 7e27f18 | 2006-06-13 09:54:40 -0700 | [diff] [blame] | 618 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 619 | #ifdef RNDIS_OPTIONAL_STATS |
| 620 | case OID_802_3_XMIT_DEFERRED: |
| 621 | DEBUG("%s: OID_802_3_XMIT_DEFERRED\n", __FUNCTION__); |
| 622 | /* TODO */ |
| 623 | break; |
David Brownell | 7e27f18 | 2006-06-13 09:54:40 -0700 | [diff] [blame] | 624 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 625 | case OID_802_3_XMIT_MAX_COLLISIONS: |
| 626 | DEBUG("%s: OID_802_3_XMIT_MAX_COLLISIONS\n", __FUNCTION__); |
| 627 | /* TODO */ |
| 628 | break; |
David Brownell | 7e27f18 | 2006-06-13 09:54:40 -0700 | [diff] [blame] | 629 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 630 | case OID_802_3_RCV_OVERRUN: |
| 631 | DEBUG("%s: OID_802_3_RCV_OVERRUN\n", __FUNCTION__); |
| 632 | /* TODO */ |
| 633 | break; |
David Brownell | 7e27f18 | 2006-06-13 09:54:40 -0700 | [diff] [blame] | 634 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 635 | case OID_802_3_XMIT_UNDERRUN: |
| 636 | DEBUG("%s: OID_802_3_XMIT_UNDERRUN\n", __FUNCTION__); |
| 637 | /* TODO */ |
| 638 | break; |
David Brownell | 7e27f18 | 2006-06-13 09:54:40 -0700 | [diff] [blame] | 639 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 640 | case OID_802_3_XMIT_HEARTBEAT_FAILURE: |
| 641 | DEBUG("%s: OID_802_3_XMIT_HEARTBEAT_FAILURE\n", __FUNCTION__); |
| 642 | /* TODO */ |
| 643 | break; |
David Brownell | 7e27f18 | 2006-06-13 09:54:40 -0700 | [diff] [blame] | 644 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 645 | case OID_802_3_XMIT_TIMES_CRS_LOST: |
| 646 | DEBUG("%s: OID_802_3_XMIT_TIMES_CRS_LOST\n", __FUNCTION__); |
| 647 | /* TODO */ |
| 648 | break; |
David Brownell | 7e27f18 | 2006-06-13 09:54:40 -0700 | [diff] [blame] | 649 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 650 | case OID_802_3_XMIT_LATE_COLLISIONS: |
| 651 | DEBUG("%s: OID_802_3_XMIT_LATE_COLLISIONS\n", __FUNCTION__); |
| 652 | /* TODO */ |
David Brownell | 7e27f18 | 2006-06-13 09:54:40 -0700 | [diff] [blame] | 653 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 654 | #endif /* RNDIS_OPTIONAL_STATS */ |
| 655 | |
| 656 | #ifdef RNDIS_PM |
| 657 | /* power management OIDs (table 4-5) */ |
| 658 | case OID_PNP_CAPABILITIES: |
| 659 | DEBUG("%s: OID_PNP_CAPABILITIES\n", __FUNCTION__); |
| 660 | |
David Brownell | 340600a | 2005-04-28 13:45:25 -0700 | [diff] [blame] | 661 | /* for now, no wakeup capabilities */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 662 | length = sizeof (struct NDIS_PNP_CAPABILITIES); |
David Brownell | 340600a | 2005-04-28 13:45:25 -0700 | [diff] [blame] | 663 | memset(outbuf, 0, length); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 664 | retval = 0; |
| 665 | break; |
| 666 | case OID_PNP_QUERY_POWER: |
David Brownell | 340600a | 2005-04-28 13:45:25 -0700 | [diff] [blame] | 667 | DEBUG("%s: OID_PNP_QUERY_POWER D%d\n", __FUNCTION__, |
| 668 | le32_to_cpup((__le32 *) buf) - 1); |
| 669 | /* only suspend is a real power state, and |
| 670 | * it can't be entered by OID_PNP_SET_POWER... |
| 671 | */ |
| 672 | length = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 673 | retval = 0; |
| 674 | break; |
| 675 | #endif |
| 676 | |
| 677 | default: |
David Brownell | 7e27f18 | 2006-06-13 09:54:40 -0700 | [diff] [blame] | 678 | printk (KERN_WARNING "%s: query unknown OID 0x%08X\n", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 679 | __FUNCTION__, OID); |
| 680 | } |
David Brownell | 340600a | 2005-04-28 13:45:25 -0700 | [diff] [blame] | 681 | if (retval < 0) |
| 682 | length = 0; |
David Brownell | 7e27f18 | 2006-06-13 09:54:40 -0700 | [diff] [blame] | 683 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 684 | resp->InformationBufferLength = cpu_to_le32 (length); |
David Brownell | 340600a | 2005-04-28 13:45:25 -0700 | [diff] [blame] | 685 | r->length = length + sizeof *resp; |
| 686 | resp->MessageLength = cpu_to_le32 (r->length); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 687 | return retval; |
| 688 | } |
| 689 | |
David Brownell | 7e27f18 | 2006-06-13 09:54:40 -0700 | [diff] [blame] | 690 | static int gen_ndis_set_resp (u8 configNr, u32 OID, u8 *buf, u32 buf_len, |
| 691 | rndis_resp_t *r) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 692 | { |
| 693 | rndis_set_cmplt_type *resp; |
David Brownell | 7e27f18 | 2006-06-13 09:54:40 -0700 | [diff] [blame] | 694 | int i, retval = -ENOTSUPP; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 695 | struct rndis_params *params; |
| 696 | |
| 697 | if (!r) |
| 698 | return -ENOMEM; |
| 699 | resp = (rndis_set_cmplt_type *) r->buf; |
| 700 | if (!resp) |
| 701 | return -ENOMEM; |
| 702 | |
David Brownell | 340600a | 2005-04-28 13:45:25 -0700 | [diff] [blame] | 703 | if (buf_len && rndis_debug > 1) { |
| 704 | DEBUG("set OID %08x value, len %d:\n", OID, buf_len); |
| 705 | for (i = 0; i < buf_len; i += 16) { |
| 706 | DEBUG ("%03d: %08x %08x %08x %08x\n", i, |
| 707 | le32_to_cpup((__le32 *)&buf[i]), |
| 708 | le32_to_cpup((__le32 *)&buf[i + 4]), |
| 709 | le32_to_cpup((__le32 *)&buf[i + 8]), |
| 710 | le32_to_cpup((__le32 *)&buf[i + 12])); |
| 711 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 712 | } |
| 713 | |
David Brownell | 340600a | 2005-04-28 13:45:25 -0700 | [diff] [blame] | 714 | params = &rndis_per_dev_params [configNr]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 715 | switch (OID) { |
| 716 | case OID_GEN_CURRENT_PACKET_FILTER: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 717 | |
David Brownell | 340600a | 2005-04-28 13:45:25 -0700 | [diff] [blame] | 718 | /* these NDIS_PACKET_TYPE_* bitflags are shared with |
| 719 | * cdc_filter; it's not RNDIS-specific |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 720 | * NDIS_PACKET_TYPE_x == USB_CDC_PACKET_TYPE_x for x in: |
| 721 | * PROMISCUOUS, DIRECTED, |
| 722 | * MULTICAST, ALL_MULTICAST, BROADCAST |
| 723 | */ |
David Brownell | 340600a | 2005-04-28 13:45:25 -0700 | [diff] [blame] | 724 | *params->filter = (u16) le32_to_cpup((__le32 *)buf); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 725 | DEBUG("%s: OID_GEN_CURRENT_PACKET_FILTER %08x\n", |
David Brownell | 340600a | 2005-04-28 13:45:25 -0700 | [diff] [blame] | 726 | __FUNCTION__, *params->filter); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 727 | |
| 728 | /* this call has a significant side effect: it's |
| 729 | * what makes the packet flow start and stop, like |
| 730 | * activating the CDC Ethernet altsetting. |
| 731 | */ |
David Brownell | 340600a | 2005-04-28 13:45:25 -0700 | [diff] [blame] | 732 | #ifdef RNDIS_PM |
| 733 | update_linkstate: |
| 734 | #endif |
| 735 | retval = 0; |
| 736 | if (*params->filter) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 737 | params->state = RNDIS_DATA_INITIALIZED; |
| 738 | netif_carrier_on(params->dev); |
| 739 | if (netif_running(params->dev)) |
| 740 | netif_wake_queue (params->dev); |
| 741 | } else { |
| 742 | params->state = RNDIS_INITIALIZED; |
| 743 | netif_carrier_off (params->dev); |
| 744 | netif_stop_queue (params->dev); |
| 745 | } |
| 746 | break; |
David Brownell | 7e27f18 | 2006-06-13 09:54:40 -0700 | [diff] [blame] | 747 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 748 | case OID_802_3_MULTICAST_LIST: |
David Brownell | 7e27f18 | 2006-06-13 09:54:40 -0700 | [diff] [blame] | 749 | /* I think we can ignore this */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 750 | DEBUG("%s: OID_802_3_MULTICAST_LIST\n", __FUNCTION__); |
| 751 | retval = 0; |
| 752 | break; |
| 753 | #if 0 |
| 754 | case OID_GEN_RNDIS_CONFIG_PARAMETER: |
| 755 | { |
| 756 | struct rndis_config_parameter *param; |
| 757 | param = (struct rndis_config_parameter *) buf; |
| 758 | DEBUG("%s: OID_GEN_RNDIS_CONFIG_PARAMETER '%*s'\n", |
| 759 | __FUNCTION__, |
| 760 | min(cpu_to_le32(param->ParameterNameLength),80), |
| 761 | buf + param->ParameterNameOffset); |
| 762 | retval = 0; |
| 763 | } |
| 764 | break; |
| 765 | #endif |
| 766 | |
| 767 | #ifdef RNDIS_PM |
| 768 | case OID_PNP_SET_POWER: |
David Brownell | 340600a | 2005-04-28 13:45:25 -0700 | [diff] [blame] | 769 | /* The only real power state is USB suspend, and RNDIS requests |
| 770 | * can't enter it; this one isn't really about power. After |
| 771 | * resuming, Windows forces a reset, and then SET_POWER D0. |
| 772 | * FIXME ... then things go batty; Windows wedges itself. |
| 773 | */ |
| 774 | i = le32_to_cpup((__force __le32 *)buf); |
| 775 | DEBUG("%s: OID_PNP_SET_POWER D%d\n", __FUNCTION__, i - 1); |
| 776 | switch (i) { |
| 777 | case NdisDeviceStateD0: |
| 778 | *params->filter = params->saved_filter; |
| 779 | goto update_linkstate; |
| 780 | case NdisDeviceStateD3: |
| 781 | case NdisDeviceStateD2: |
| 782 | case NdisDeviceStateD1: |
| 783 | params->saved_filter = *params->filter; |
| 784 | retval = 0; |
| 785 | break; |
| 786 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 787 | break; |
| 788 | |
David Brownell | 340600a | 2005-04-28 13:45:25 -0700 | [diff] [blame] | 789 | #ifdef RNDIS_WAKEUP |
| 790 | // no wakeup support advertised, so wakeup OIDs always fail: |
| 791 | // - OID_PNP_ENABLE_WAKE_UP |
| 792 | // - OID_PNP_{ADD,REMOVE}_WAKE_UP_PATTERN |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 793 | #endif |
| 794 | |
David Brownell | 340600a | 2005-04-28 13:45:25 -0700 | [diff] [blame] | 795 | #endif /* RNDIS_PM */ |
| 796 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 797 | default: |
David Brownell | 7e27f18 | 2006-06-13 09:54:40 -0700 | [diff] [blame] | 798 | printk (KERN_WARNING "%s: set unknown OID 0x%08X, size %d\n", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 799 | __FUNCTION__, OID, buf_len); |
| 800 | } |
David Brownell | 7e27f18 | 2006-06-13 09:54:40 -0700 | [diff] [blame] | 801 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 802 | return retval; |
| 803 | } |
| 804 | |
David Brownell | 7e27f18 | 2006-06-13 09:54:40 -0700 | [diff] [blame] | 805 | /* |
| 806 | * Response Functions |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 807 | */ |
| 808 | |
| 809 | static int rndis_init_response (int configNr, rndis_init_msg_type *buf) |
| 810 | { |
David Brownell | 7e27f18 | 2006-06-13 09:54:40 -0700 | [diff] [blame] | 811 | rndis_init_cmplt_type *resp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 812 | rndis_resp_t *r; |
David Brownell | 7e27f18 | 2006-06-13 09:54:40 -0700 | [diff] [blame] | 813 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 814 | if (!rndis_per_dev_params [configNr].dev) return -ENOTSUPP; |
David Brownell | 7e27f18 | 2006-06-13 09:54:40 -0700 | [diff] [blame] | 815 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 816 | r = rndis_add_response (configNr, sizeof (rndis_init_cmplt_type)); |
David Brownell | 340600a | 2005-04-28 13:45:25 -0700 | [diff] [blame] | 817 | if (!r) |
| 818 | return -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 819 | resp = (rndis_init_cmplt_type *) r->buf; |
David Brownell | 7e27f18 | 2006-06-13 09:54:40 -0700 | [diff] [blame] | 820 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 821 | resp->MessageType = __constant_cpu_to_le32 ( |
| 822 | REMOTE_NDIS_INITIALIZE_CMPLT); |
| 823 | resp->MessageLength = __constant_cpu_to_le32 (52); |
| 824 | resp->RequestID = buf->RequestID; /* Still LE in msg buffer */ |
| 825 | resp->Status = __constant_cpu_to_le32 (RNDIS_STATUS_SUCCESS); |
| 826 | resp->MajorVersion = __constant_cpu_to_le32 (RNDIS_MAJOR_VERSION); |
| 827 | resp->MinorVersion = __constant_cpu_to_le32 (RNDIS_MINOR_VERSION); |
| 828 | resp->DeviceFlags = __constant_cpu_to_le32 (RNDIS_DF_CONNECTIONLESS); |
| 829 | resp->Medium = __constant_cpu_to_le32 (RNDIS_MEDIUM_802_3); |
| 830 | resp->MaxPacketsPerTransfer = __constant_cpu_to_le32 (1); |
| 831 | resp->MaxTransferSize = cpu_to_le32 ( |
| 832 | rndis_per_dev_params [configNr].dev->mtu |
| 833 | + sizeof (struct ethhdr) |
| 834 | + sizeof (struct rndis_packet_msg_type) |
| 835 | + 22); |
| 836 | resp->PacketAlignmentFactor = __constant_cpu_to_le32 (0); |
| 837 | resp->AFListOffset = __constant_cpu_to_le32 (0); |
| 838 | resp->AFListSize = __constant_cpu_to_le32 (0); |
David Brownell | 7e27f18 | 2006-06-13 09:54:40 -0700 | [diff] [blame] | 839 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 840 | if (rndis_per_dev_params [configNr].ack) |
David Brownell | 7e27f18 | 2006-06-13 09:54:40 -0700 | [diff] [blame] | 841 | rndis_per_dev_params [configNr].ack ( |
| 842 | rndis_per_dev_params [configNr].dev); |
| 843 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 844 | return 0; |
| 845 | } |
| 846 | |
| 847 | static int rndis_query_response (int configNr, rndis_query_msg_type *buf) |
| 848 | { |
| 849 | rndis_query_cmplt_type *resp; |
| 850 | rndis_resp_t *r; |
David Brownell | 7e27f18 | 2006-06-13 09:54:40 -0700 | [diff] [blame] | 851 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 852 | // DEBUG("%s: OID = %08X\n", __FUNCTION__, cpu_to_le32(buf->OID)); |
| 853 | if (!rndis_per_dev_params [configNr].dev) return -ENOTSUPP; |
David Brownell | 7e27f18 | 2006-06-13 09:54:40 -0700 | [diff] [blame] | 854 | |
Shaun Tancheff | 8763716 | 2006-02-22 19:47:19 -0800 | [diff] [blame] | 855 | /* |
| 856 | * we need more memory: |
| 857 | * gen_ndis_query_resp expects enough space for |
| 858 | * rndis_query_cmplt_type followed by data. |
| 859 | * oid_supported_list is the largest data reply |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 860 | */ |
Shaun Tancheff | 8763716 | 2006-02-22 19:47:19 -0800 | [diff] [blame] | 861 | r = rndis_add_response (configNr, |
| 862 | sizeof (oid_supported_list) + sizeof(rndis_query_cmplt_type)); |
David Brownell | 340600a | 2005-04-28 13:45:25 -0700 | [diff] [blame] | 863 | if (!r) |
| 864 | return -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 865 | resp = (rndis_query_cmplt_type *) r->buf; |
David Brownell | 7e27f18 | 2006-06-13 09:54:40 -0700 | [diff] [blame] | 866 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 867 | resp->MessageType = __constant_cpu_to_le32 (REMOTE_NDIS_QUERY_CMPLT); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 868 | resp->RequestID = buf->RequestID; /* Still LE in msg buffer */ |
David Brownell | 7e27f18 | 2006-06-13 09:54:40 -0700 | [diff] [blame] | 869 | |
David Brownell | 340600a | 2005-04-28 13:45:25 -0700 | [diff] [blame] | 870 | if (gen_ndis_query_resp (configNr, le32_to_cpu (buf->OID), |
| 871 | le32_to_cpu(buf->InformationBufferOffset) |
| 872 | + 8 + (u8 *) buf, |
| 873 | le32_to_cpu(buf->InformationBufferLength), |
| 874 | r)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 875 | /* OID not supported */ |
| 876 | resp->Status = __constant_cpu_to_le32 ( |
| 877 | RNDIS_STATUS_NOT_SUPPORTED); |
David Brownell | 340600a | 2005-04-28 13:45:25 -0700 | [diff] [blame] | 878 | resp->MessageLength = __constant_cpu_to_le32 (sizeof *resp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 879 | resp->InformationBufferLength = __constant_cpu_to_le32 (0); |
| 880 | resp->InformationBufferOffset = __constant_cpu_to_le32 (0); |
| 881 | } else |
| 882 | resp->Status = __constant_cpu_to_le32 (RNDIS_STATUS_SUCCESS); |
David Brownell | 7e27f18 | 2006-06-13 09:54:40 -0700 | [diff] [blame] | 883 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 884 | if (rndis_per_dev_params [configNr].ack) |
David Brownell | 7e27f18 | 2006-06-13 09:54:40 -0700 | [diff] [blame] | 885 | rndis_per_dev_params [configNr].ack ( |
| 886 | rndis_per_dev_params [configNr].dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 887 | return 0; |
| 888 | } |
| 889 | |
| 890 | static int rndis_set_response (int configNr, rndis_set_msg_type *buf) |
| 891 | { |
| 892 | u32 BufLength, BufOffset; |
| 893 | rndis_set_cmplt_type *resp; |
| 894 | rndis_resp_t *r; |
David Brownell | 7e27f18 | 2006-06-13 09:54:40 -0700 | [diff] [blame] | 895 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 896 | r = rndis_add_response (configNr, sizeof (rndis_set_cmplt_type)); |
David Brownell | 340600a | 2005-04-28 13:45:25 -0700 | [diff] [blame] | 897 | if (!r) |
| 898 | return -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 899 | resp = (rndis_set_cmplt_type *) r->buf; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 900 | |
| 901 | BufLength = le32_to_cpu (buf->InformationBufferLength); |
| 902 | BufOffset = le32_to_cpu (buf->InformationBufferOffset); |
| 903 | |
| 904 | #ifdef VERBOSE |
| 905 | DEBUG("%s: Length: %d\n", __FUNCTION__, BufLength); |
| 906 | DEBUG("%s: Offset: %d\n", __FUNCTION__, BufOffset); |
| 907 | DEBUG("%s: InfoBuffer: ", __FUNCTION__); |
David Brownell | 7e27f18 | 2006-06-13 09:54:40 -0700 | [diff] [blame] | 908 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 909 | for (i = 0; i < BufLength; i++) { |
| 910 | DEBUG ("%02x ", *(((u8 *) buf) + i + 8 + BufOffset)); |
| 911 | } |
David Brownell | 7e27f18 | 2006-06-13 09:54:40 -0700 | [diff] [blame] | 912 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 913 | DEBUG ("\n"); |
| 914 | #endif |
David Brownell | 7e27f18 | 2006-06-13 09:54:40 -0700 | [diff] [blame] | 915 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 916 | resp->MessageType = __constant_cpu_to_le32 (REMOTE_NDIS_SET_CMPLT); |
| 917 | resp->MessageLength = __constant_cpu_to_le32 (16); |
| 918 | resp->RequestID = buf->RequestID; /* Still LE in msg buffer */ |
David Brownell | 7e27f18 | 2006-06-13 09:54:40 -0700 | [diff] [blame] | 919 | if (gen_ndis_set_resp (configNr, le32_to_cpu (buf->OID), |
| 920 | ((u8 *) buf) + 8 + BufOffset, BufLength, r)) |
| 921 | resp->Status = __constant_cpu_to_le32 (RNDIS_STATUS_NOT_SUPPORTED); |
| 922 | else |
| 923 | resp->Status = __constant_cpu_to_le32 (RNDIS_STATUS_SUCCESS); |
| 924 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 925 | if (rndis_per_dev_params [configNr].ack) |
David Brownell | 7e27f18 | 2006-06-13 09:54:40 -0700 | [diff] [blame] | 926 | rndis_per_dev_params [configNr].ack ( |
| 927 | rndis_per_dev_params [configNr].dev); |
| 928 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 929 | return 0; |
| 930 | } |
| 931 | |
| 932 | static int rndis_reset_response (int configNr, rndis_reset_msg_type *buf) |
| 933 | { |
| 934 | rndis_reset_cmplt_type *resp; |
| 935 | rndis_resp_t *r; |
David Brownell | 7e27f18 | 2006-06-13 09:54:40 -0700 | [diff] [blame] | 936 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 937 | r = rndis_add_response (configNr, sizeof (rndis_reset_cmplt_type)); |
David Brownell | 340600a | 2005-04-28 13:45:25 -0700 | [diff] [blame] | 938 | if (!r) |
| 939 | return -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 940 | resp = (rndis_reset_cmplt_type *) r->buf; |
David Brownell | 7e27f18 | 2006-06-13 09:54:40 -0700 | [diff] [blame] | 941 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 942 | resp->MessageType = __constant_cpu_to_le32 (REMOTE_NDIS_RESET_CMPLT); |
| 943 | resp->MessageLength = __constant_cpu_to_le32 (16); |
| 944 | resp->Status = __constant_cpu_to_le32 (RNDIS_STATUS_SUCCESS); |
| 945 | /* resent information */ |
| 946 | resp->AddressingReset = __constant_cpu_to_le32 (1); |
David Brownell | 7e27f18 | 2006-06-13 09:54:40 -0700 | [diff] [blame] | 947 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 948 | if (rndis_per_dev_params [configNr].ack) |
David Brownell | 7e27f18 | 2006-06-13 09:54:40 -0700 | [diff] [blame] | 949 | rndis_per_dev_params [configNr].ack ( |
| 950 | rndis_per_dev_params [configNr].dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 951 | |
| 952 | return 0; |
| 953 | } |
| 954 | |
| 955 | static int rndis_keepalive_response (int configNr, |
David Brownell | 7e27f18 | 2006-06-13 09:54:40 -0700 | [diff] [blame] | 956 | rndis_keepalive_msg_type *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 957 | { |
| 958 | rndis_keepalive_cmplt_type *resp; |
| 959 | rndis_resp_t *r; |
| 960 | |
| 961 | /* host "should" check only in RNDIS_DATA_INITIALIZED state */ |
| 962 | |
| 963 | r = rndis_add_response (configNr, sizeof (rndis_keepalive_cmplt_type)); |
David Brownell | 340600a | 2005-04-28 13:45:25 -0700 | [diff] [blame] | 964 | if (!r) |
| 965 | return -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 966 | resp = (rndis_keepalive_cmplt_type *) r->buf; |
David Brownell | 7e27f18 | 2006-06-13 09:54:40 -0700 | [diff] [blame] | 967 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 968 | resp->MessageType = __constant_cpu_to_le32 ( |
| 969 | REMOTE_NDIS_KEEPALIVE_CMPLT); |
| 970 | resp->MessageLength = __constant_cpu_to_le32 (16); |
| 971 | resp->RequestID = buf->RequestID; /* Still LE in msg buffer */ |
| 972 | resp->Status = __constant_cpu_to_le32 (RNDIS_STATUS_SUCCESS); |
David Brownell | 7e27f18 | 2006-06-13 09:54:40 -0700 | [diff] [blame] | 973 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 974 | if (rndis_per_dev_params [configNr].ack) |
David Brownell | 7e27f18 | 2006-06-13 09:54:40 -0700 | [diff] [blame] | 975 | rndis_per_dev_params [configNr].ack ( |
| 976 | rndis_per_dev_params [configNr].dev); |
| 977 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 978 | return 0; |
| 979 | } |
| 980 | |
| 981 | |
David Brownell | 7e27f18 | 2006-06-13 09:54:40 -0700 | [diff] [blame] | 982 | /* |
| 983 | * Device to Host Comunication |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 984 | */ |
| 985 | static int rndis_indicate_status_msg (int configNr, u32 status) |
| 986 | { |
David Brownell | 7e27f18 | 2006-06-13 09:54:40 -0700 | [diff] [blame] | 987 | rndis_indicate_status_msg_type *resp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 988 | rndis_resp_t *r; |
David Brownell | 7e27f18 | 2006-06-13 09:54:40 -0700 | [diff] [blame] | 989 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 990 | if (rndis_per_dev_params [configNr].state == RNDIS_UNINITIALIZED) |
David Brownell | 7e27f18 | 2006-06-13 09:54:40 -0700 | [diff] [blame] | 991 | return -ENOTSUPP; |
| 992 | |
| 993 | r = rndis_add_response (configNr, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 994 | sizeof (rndis_indicate_status_msg_type)); |
David Brownell | 340600a | 2005-04-28 13:45:25 -0700 | [diff] [blame] | 995 | if (!r) |
| 996 | return -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 997 | resp = (rndis_indicate_status_msg_type *) r->buf; |
David Brownell | 7e27f18 | 2006-06-13 09:54:40 -0700 | [diff] [blame] | 998 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 999 | resp->MessageType = __constant_cpu_to_le32 ( |
| 1000 | REMOTE_NDIS_INDICATE_STATUS_MSG); |
| 1001 | resp->MessageLength = __constant_cpu_to_le32 (20); |
| 1002 | resp->Status = cpu_to_le32 (status); |
| 1003 | resp->StatusBufferLength = __constant_cpu_to_le32 (0); |
| 1004 | resp->StatusBufferOffset = __constant_cpu_to_le32 (0); |
David Brownell | 7e27f18 | 2006-06-13 09:54:40 -0700 | [diff] [blame] | 1005 | |
| 1006 | if (rndis_per_dev_params [configNr].ack) |
| 1007 | rndis_per_dev_params [configNr].ack ( |
| 1008 | rndis_per_dev_params [configNr].dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1009 | return 0; |
| 1010 | } |
| 1011 | |
| 1012 | int rndis_signal_connect (int configNr) |
| 1013 | { |
| 1014 | rndis_per_dev_params [configNr].media_state |
| 1015 | = NDIS_MEDIA_STATE_CONNECTED; |
David Brownell | 7e27f18 | 2006-06-13 09:54:40 -0700 | [diff] [blame] | 1016 | return rndis_indicate_status_msg (configNr, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1017 | RNDIS_STATUS_MEDIA_CONNECT); |
| 1018 | } |
| 1019 | |
| 1020 | int rndis_signal_disconnect (int configNr) |
| 1021 | { |
| 1022 | rndis_per_dev_params [configNr].media_state |
| 1023 | = NDIS_MEDIA_STATE_DISCONNECTED; |
| 1024 | return rndis_indicate_status_msg (configNr, |
| 1025 | RNDIS_STATUS_MEDIA_DISCONNECT); |
| 1026 | } |
| 1027 | |
David Brownell | 340600a | 2005-04-28 13:45:25 -0700 | [diff] [blame] | 1028 | void rndis_uninit (int configNr) |
| 1029 | { |
David Brownell | 486e2df | 2005-05-24 17:51:52 -0700 | [diff] [blame] | 1030 | u8 *buf; |
| 1031 | u32 length; |
| 1032 | |
David Brownell | 340600a | 2005-04-28 13:45:25 -0700 | [diff] [blame] | 1033 | if (configNr >= RNDIS_MAX_CONFIGS) |
| 1034 | return; |
| 1035 | rndis_per_dev_params [configNr].used = 0; |
| 1036 | rndis_per_dev_params [configNr].state = RNDIS_UNINITIALIZED; |
David Brownell | 486e2df | 2005-05-24 17:51:52 -0700 | [diff] [blame] | 1037 | |
| 1038 | /* drain the response queue */ |
| 1039 | while ((buf = rndis_get_next_response(configNr, &length))) |
| 1040 | rndis_free_response(configNr, buf); |
David Brownell | 340600a | 2005-04-28 13:45:25 -0700 | [diff] [blame] | 1041 | } |
| 1042 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1043 | void rndis_set_host_mac (int configNr, const u8 *addr) |
| 1044 | { |
| 1045 | rndis_per_dev_params [configNr].host_mac = addr; |
| 1046 | } |
| 1047 | |
David Brownell | 7e27f18 | 2006-06-13 09:54:40 -0700 | [diff] [blame] | 1048 | /* |
| 1049 | * Message Parser |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1050 | */ |
| 1051 | int rndis_msg_parser (u8 configNr, u8 *buf) |
| 1052 | { |
| 1053 | u32 MsgType, MsgLength; |
| 1054 | __le32 *tmp; |
| 1055 | struct rndis_params *params; |
David Brownell | 7e27f18 | 2006-06-13 09:54:40 -0700 | [diff] [blame] | 1056 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1057 | if (!buf) |
| 1058 | return -ENOMEM; |
David Brownell | 7e27f18 | 2006-06-13 09:54:40 -0700 | [diff] [blame] | 1059 | |
| 1060 | tmp = (__le32 *) buf; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1061 | MsgType = le32_to_cpup(tmp++); |
| 1062 | MsgLength = le32_to_cpup(tmp++); |
David Brownell | 7e27f18 | 2006-06-13 09:54:40 -0700 | [diff] [blame] | 1063 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1064 | if (configNr >= RNDIS_MAX_CONFIGS) |
| 1065 | return -ENOTSUPP; |
| 1066 | params = &rndis_per_dev_params [configNr]; |
David Brownell | 7e27f18 | 2006-06-13 09:54:40 -0700 | [diff] [blame] | 1067 | |
David Brownell | 340600a | 2005-04-28 13:45:25 -0700 | [diff] [blame] | 1068 | /* NOTE: RNDIS is *EXTREMELY* chatty ... Windows constantly polls for |
| 1069 | * rx/tx statistics and link status, in addition to KEEPALIVE traffic |
| 1070 | * and normal HC level polling to see if there's any IN traffic. |
| 1071 | */ |
| 1072 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1073 | /* For USB: responses may take up to 10 seconds */ |
David Brownell | 340600a | 2005-04-28 13:45:25 -0700 | [diff] [blame] | 1074 | switch (MsgType) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1075 | case REMOTE_NDIS_INITIALIZE_MSG: |
David Brownell | 7e27f18 | 2006-06-13 09:54:40 -0700 | [diff] [blame] | 1076 | DEBUG("%s: REMOTE_NDIS_INITIALIZE_MSG\n", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1077 | __FUNCTION__ ); |
| 1078 | params->state = RNDIS_INITIALIZED; |
| 1079 | return rndis_init_response (configNr, |
David Brownell | 7e27f18 | 2006-06-13 09:54:40 -0700 | [diff] [blame] | 1080 | (rndis_init_msg_type *) buf); |
| 1081 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1082 | case REMOTE_NDIS_HALT_MSG: |
| 1083 | DEBUG("%s: REMOTE_NDIS_HALT_MSG\n", |
| 1084 | __FUNCTION__ ); |
| 1085 | params->state = RNDIS_UNINITIALIZED; |
| 1086 | if (params->dev) { |
| 1087 | netif_carrier_off (params->dev); |
| 1088 | netif_stop_queue (params->dev); |
| 1089 | } |
| 1090 | return 0; |
David Brownell | 7e27f18 | 2006-06-13 09:54:40 -0700 | [diff] [blame] | 1091 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1092 | case REMOTE_NDIS_QUERY_MSG: |
David Brownell | 7e27f18 | 2006-06-13 09:54:40 -0700 | [diff] [blame] | 1093 | return rndis_query_response (configNr, |
| 1094 | (rndis_query_msg_type *) buf); |
| 1095 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1096 | case REMOTE_NDIS_SET_MSG: |
David Brownell | 7e27f18 | 2006-06-13 09:54:40 -0700 | [diff] [blame] | 1097 | return rndis_set_response (configNr, |
| 1098 | (rndis_set_msg_type *) buf); |
| 1099 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1100 | case REMOTE_NDIS_RESET_MSG: |
David Brownell | 7e27f18 | 2006-06-13 09:54:40 -0700 | [diff] [blame] | 1101 | DEBUG("%s: REMOTE_NDIS_RESET_MSG\n", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1102 | __FUNCTION__ ); |
| 1103 | return rndis_reset_response (configNr, |
David Brownell | 7e27f18 | 2006-06-13 09:54:40 -0700 | [diff] [blame] | 1104 | (rndis_reset_msg_type *) buf); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1105 | |
| 1106 | case REMOTE_NDIS_KEEPALIVE_MSG: |
| 1107 | /* For USB: host does this every 5 seconds */ |
David Brownell | 340600a | 2005-04-28 13:45:25 -0700 | [diff] [blame] | 1108 | if (rndis_debug > 1) |
David Brownell | 7e27f18 | 2006-06-13 09:54:40 -0700 | [diff] [blame] | 1109 | DEBUG("%s: REMOTE_NDIS_KEEPALIVE_MSG\n", |
David Brownell | 340600a | 2005-04-28 13:45:25 -0700 | [diff] [blame] | 1110 | __FUNCTION__ ); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1111 | return rndis_keepalive_response (configNr, |
David Brownell | 7e27f18 | 2006-06-13 09:54:40 -0700 | [diff] [blame] | 1112 | (rndis_keepalive_msg_type *) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1113 | buf); |
David Brownell | 7e27f18 | 2006-06-13 09:54:40 -0700 | [diff] [blame] | 1114 | |
| 1115 | default: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1116 | /* At least Windows XP emits some undefined RNDIS messages. |
| 1117 | * In one case those messages seemed to relate to the host |
| 1118 | * suspending itself. |
| 1119 | */ |
| 1120 | printk (KERN_WARNING |
David Brownell | 7e27f18 | 2006-06-13 09:54:40 -0700 | [diff] [blame] | 1121 | "%s: unknown RNDIS message 0x%08X len %d\n", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1122 | __FUNCTION__ , MsgType, MsgLength); |
| 1123 | { |
| 1124 | unsigned i; |
| 1125 | for (i = 0; i < MsgLength; i += 16) { |
| 1126 | DEBUG ("%03d: " |
| 1127 | " %02x %02x %02x %02x" |
| 1128 | " %02x %02x %02x %02x" |
| 1129 | " %02x %02x %02x %02x" |
| 1130 | " %02x %02x %02x %02x" |
| 1131 | "\n", |
| 1132 | i, |
| 1133 | buf[i], buf [i+1], |
| 1134 | buf[i+2], buf[i+3], |
| 1135 | buf[i+4], buf [i+5], |
| 1136 | buf[i+6], buf[i+7], |
| 1137 | buf[i+8], buf [i+9], |
| 1138 | buf[i+10], buf[i+11], |
| 1139 | buf[i+12], buf [i+13], |
| 1140 | buf[i+14], buf[i+15]); |
| 1141 | } |
| 1142 | } |
| 1143 | break; |
| 1144 | } |
David Brownell | 7e27f18 | 2006-06-13 09:54:40 -0700 | [diff] [blame] | 1145 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1146 | return -ENOTSUPP; |
| 1147 | } |
| 1148 | |
| 1149 | int rndis_register (int (* rndis_control_ack) (struct net_device *)) |
| 1150 | { |
| 1151 | u8 i; |
David Brownell | 7e27f18 | 2006-06-13 09:54:40 -0700 | [diff] [blame] | 1152 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1153 | for (i = 0; i < RNDIS_MAX_CONFIGS; i++) { |
| 1154 | if (!rndis_per_dev_params [i].used) { |
| 1155 | rndis_per_dev_params [i].used = 1; |
| 1156 | rndis_per_dev_params [i].ack = rndis_control_ack; |
| 1157 | DEBUG("%s: configNr = %d\n", __FUNCTION__, i); |
| 1158 | return i; |
| 1159 | } |
| 1160 | } |
| 1161 | DEBUG("failed\n"); |
David Brownell | 7e27f18 | 2006-06-13 09:54:40 -0700 | [diff] [blame] | 1162 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1163 | return -1; |
| 1164 | } |
| 1165 | |
| 1166 | void rndis_deregister (int configNr) |
| 1167 | { |
| 1168 | DEBUG("%s: \n", __FUNCTION__ ); |
David Brownell | 7e27f18 | 2006-06-13 09:54:40 -0700 | [diff] [blame] | 1169 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1170 | if (configNr >= RNDIS_MAX_CONFIGS) return; |
| 1171 | rndis_per_dev_params [configNr].used = 0; |
David Brownell | 7e27f18 | 2006-06-13 09:54:40 -0700 | [diff] [blame] | 1172 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1173 | return; |
| 1174 | } |
| 1175 | |
David Brownell | 7e27f18 | 2006-06-13 09:54:40 -0700 | [diff] [blame] | 1176 | int rndis_set_param_dev (u8 configNr, struct net_device *dev, |
David Brownell | 340600a | 2005-04-28 13:45:25 -0700 | [diff] [blame] | 1177 | struct net_device_stats *stats, |
| 1178 | u16 *cdc_filter) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1179 | { |
| 1180 | DEBUG("%s:\n", __FUNCTION__ ); |
| 1181 | if (!dev || !stats) return -1; |
| 1182 | if (configNr >= RNDIS_MAX_CONFIGS) return -1; |
David Brownell | 7e27f18 | 2006-06-13 09:54:40 -0700 | [diff] [blame] | 1183 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1184 | rndis_per_dev_params [configNr].dev = dev; |
| 1185 | rndis_per_dev_params [configNr].stats = stats; |
David Brownell | 340600a | 2005-04-28 13:45:25 -0700 | [diff] [blame] | 1186 | rndis_per_dev_params [configNr].filter = cdc_filter; |
David Brownell | 7e27f18 | 2006-06-13 09:54:40 -0700 | [diff] [blame] | 1187 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1188 | return 0; |
| 1189 | } |
| 1190 | |
| 1191 | int rndis_set_param_vendor (u8 configNr, u32 vendorID, const char *vendorDescr) |
| 1192 | { |
| 1193 | DEBUG("%s:\n", __FUNCTION__ ); |
| 1194 | if (!vendorDescr) return -1; |
| 1195 | if (configNr >= RNDIS_MAX_CONFIGS) return -1; |
David Brownell | 7e27f18 | 2006-06-13 09:54:40 -0700 | [diff] [blame] | 1196 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1197 | rndis_per_dev_params [configNr].vendorID = vendorID; |
| 1198 | rndis_per_dev_params [configNr].vendorDescr = vendorDescr; |
David Brownell | 7e27f18 | 2006-06-13 09:54:40 -0700 | [diff] [blame] | 1199 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1200 | return 0; |
| 1201 | } |
| 1202 | |
| 1203 | int rndis_set_param_medium (u8 configNr, u32 medium, u32 speed) |
| 1204 | { |
David Brownell | 340600a | 2005-04-28 13:45:25 -0700 | [diff] [blame] | 1205 | DEBUG("%s: %u %u\n", __FUNCTION__, medium, speed); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1206 | if (configNr >= RNDIS_MAX_CONFIGS) return -1; |
David Brownell | 7e27f18 | 2006-06-13 09:54:40 -0700 | [diff] [blame] | 1207 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1208 | rndis_per_dev_params [configNr].medium = medium; |
| 1209 | rndis_per_dev_params [configNr].speed = speed; |
David Brownell | 7e27f18 | 2006-06-13 09:54:40 -0700 | [diff] [blame] | 1210 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1211 | return 0; |
| 1212 | } |
| 1213 | |
| 1214 | void rndis_add_hdr (struct sk_buff *skb) |
| 1215 | { |
| 1216 | struct rndis_packet_msg_type *header; |
| 1217 | |
| 1218 | if (!skb) |
| 1219 | return; |
| 1220 | header = (void *) skb_push (skb, sizeof *header); |
| 1221 | memset (header, 0, sizeof *header); |
David Brownell | 6cdee10 | 2005-04-18 17:39:34 -0700 | [diff] [blame] | 1222 | header->MessageType = __constant_cpu_to_le32(REMOTE_NDIS_PACKET_MSG); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1223 | header->MessageLength = cpu_to_le32(skb->len); |
| 1224 | header->DataOffset = __constant_cpu_to_le32 (36); |
David Brownell | 6cdee10 | 2005-04-18 17:39:34 -0700 | [diff] [blame] | 1225 | header->DataLength = cpu_to_le32(skb->len - sizeof *header); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1226 | } |
| 1227 | |
| 1228 | void rndis_free_response (int configNr, u8 *buf) |
| 1229 | { |
| 1230 | rndis_resp_t *r; |
| 1231 | struct list_head *act, *tmp; |
David Brownell | 7e27f18 | 2006-06-13 09:54:40 -0700 | [diff] [blame] | 1232 | |
| 1233 | list_for_each_safe (act, tmp, |
| 1234 | &(rndis_per_dev_params [configNr].resp_queue)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1235 | { |
| 1236 | r = list_entry (act, rndis_resp_t, list); |
| 1237 | if (r && r->buf == buf) { |
| 1238 | list_del (&r->list); |
| 1239 | kfree (r); |
| 1240 | } |
| 1241 | } |
| 1242 | } |
| 1243 | |
| 1244 | u8 *rndis_get_next_response (int configNr, u32 *length) |
| 1245 | { |
| 1246 | rndis_resp_t *r; |
David Brownell | 7e27f18 | 2006-06-13 09:54:40 -0700 | [diff] [blame] | 1247 | struct list_head *act, *tmp; |
| 1248 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1249 | if (!length) return NULL; |
David Brownell | 7e27f18 | 2006-06-13 09:54:40 -0700 | [diff] [blame] | 1250 | |
| 1251 | list_for_each_safe (act, tmp, |
| 1252 | &(rndis_per_dev_params [configNr].resp_queue)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1253 | { |
| 1254 | r = list_entry (act, rndis_resp_t, list); |
| 1255 | if (!r->send) { |
| 1256 | r->send = 1; |
| 1257 | *length = r->length; |
| 1258 | return r->buf; |
| 1259 | } |
| 1260 | } |
David Brownell | 7e27f18 | 2006-06-13 09:54:40 -0700 | [diff] [blame] | 1261 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1262 | return NULL; |
| 1263 | } |
| 1264 | |
| 1265 | static rndis_resp_t *rndis_add_response (int configNr, u32 length) |
| 1266 | { |
| 1267 | rndis_resp_t *r; |
David Brownell | 7e27f18 | 2006-06-13 09:54:40 -0700 | [diff] [blame] | 1268 | |
David Brownell | 340600a | 2005-04-28 13:45:25 -0700 | [diff] [blame] | 1269 | /* NOTE: this gets copied into ether.c USB_BUFSIZ bytes ... */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1270 | r = kmalloc (sizeof (rndis_resp_t) + length, GFP_ATOMIC); |
| 1271 | if (!r) return NULL; |
David Brownell | 7e27f18 | 2006-06-13 09:54:40 -0700 | [diff] [blame] | 1272 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1273 | r->buf = (u8 *) (r + 1); |
| 1274 | r->length = length; |
| 1275 | r->send = 0; |
David Brownell | 7e27f18 | 2006-06-13 09:54:40 -0700 | [diff] [blame] | 1276 | |
| 1277 | list_add_tail (&r->list, |
| 1278 | &(rndis_per_dev_params [configNr].resp_queue)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1279 | return r; |
| 1280 | } |
| 1281 | |
David Brownell | 6cdee10 | 2005-04-18 17:39:34 -0700 | [diff] [blame] | 1282 | int rndis_rm_hdr(struct sk_buff *skb) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1283 | { |
David Brownell | 6cdee10 | 2005-04-18 17:39:34 -0700 | [diff] [blame] | 1284 | /* tmp points to a struct rndis_packet_msg_type */ |
| 1285 | __le32 *tmp = (void *) skb->data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1286 | |
David Brownell | 6cdee10 | 2005-04-18 17:39:34 -0700 | [diff] [blame] | 1287 | /* MessageType, MessageLength */ |
| 1288 | if (__constant_cpu_to_le32(REMOTE_NDIS_PACKET_MSG) |
| 1289 | != get_unaligned(tmp++)) |
| 1290 | return -EINVAL; |
| 1291 | tmp++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1292 | |
David Brownell | 6cdee10 | 2005-04-18 17:39:34 -0700 | [diff] [blame] | 1293 | /* DataOffset, DataLength */ |
| 1294 | if (!skb_pull(skb, le32_to_cpu(get_unaligned(tmp++)) |
| 1295 | + 8 /* offset of DataOffset */)) |
| 1296 | return -EOVERFLOW; |
| 1297 | skb_trim(skb, le32_to_cpu(get_unaligned(tmp++))); |
| 1298 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1299 | return 0; |
| 1300 | } |
| 1301 | |
| 1302 | #ifdef CONFIG_USB_GADGET_DEBUG_FILES |
| 1303 | |
David Brownell | 7e27f18 | 2006-06-13 09:54:40 -0700 | [diff] [blame] | 1304 | static int rndis_proc_read (char *page, char **start, off_t off, int count, int *eof, |
| 1305 | void *data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1306 | { |
| 1307 | char *out = page; |
| 1308 | int len; |
| 1309 | rndis_params *param = (rndis_params *) data; |
David Brownell | 7e27f18 | 2006-06-13 09:54:40 -0700 | [diff] [blame] | 1310 | |
| 1311 | out += snprintf (out, count, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1312 | "Config Nr. %d\n" |
| 1313 | "used : %s\n" |
| 1314 | "state : %s\n" |
| 1315 | "medium : 0x%08X\n" |
| 1316 | "speed : %d\n" |
| 1317 | "cable : %s\n" |
| 1318 | "vendor ID : 0x%08X\n" |
David Brownell | 7e27f18 | 2006-06-13 09:54:40 -0700 | [diff] [blame] | 1319 | "vendor : %s\n", |
| 1320 | param->confignr, (param->used) ? "y" : "n", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1321 | ({ char *s = "?"; |
| 1322 | switch (param->state) { |
| 1323 | case RNDIS_UNINITIALIZED: |
| 1324 | s = "RNDIS_UNINITIALIZED"; break; |
| 1325 | case RNDIS_INITIALIZED: |
| 1326 | s = "RNDIS_INITIALIZED"; break; |
| 1327 | case RNDIS_DATA_INITIALIZED: |
| 1328 | s = "RNDIS_DATA_INITIALIZED"; break; |
| 1329 | }; s; }), |
David Brownell | 7e27f18 | 2006-06-13 09:54:40 -0700 | [diff] [blame] | 1330 | param->medium, |
| 1331 | (param->media_state) ? 0 : param->speed*100, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1332 | (param->media_state) ? "disconnected" : "connected", |
David Brownell | 7e27f18 | 2006-06-13 09:54:40 -0700 | [diff] [blame] | 1333 | param->vendorID, param->vendorDescr); |
| 1334 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1335 | len = out - page; |
| 1336 | len -= off; |
David Brownell | 7e27f18 | 2006-06-13 09:54:40 -0700 | [diff] [blame] | 1337 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1338 | if (len < count) { |
| 1339 | *eof = 1; |
| 1340 | if (len <= 0) |
| 1341 | return 0; |
| 1342 | } else |
| 1343 | len = count; |
David Brownell | 7e27f18 | 2006-06-13 09:54:40 -0700 | [diff] [blame] | 1344 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1345 | *start = page + off; |
| 1346 | return len; |
| 1347 | } |
| 1348 | |
David Brownell | 7e27f18 | 2006-06-13 09:54:40 -0700 | [diff] [blame] | 1349 | static int rndis_proc_write (struct file *file, const char __user *buffer, |
| 1350 | unsigned long count, void *data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1351 | { |
| 1352 | rndis_params *p = data; |
| 1353 | u32 speed = 0; |
| 1354 | int i, fl_speed = 0; |
David Brownell | 7e27f18 | 2006-06-13 09:54:40 -0700 | [diff] [blame] | 1355 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1356 | for (i = 0; i < count; i++) { |
| 1357 | char c; |
| 1358 | if (get_user(c, buffer)) |
| 1359 | return -EFAULT; |
| 1360 | switch (c) { |
| 1361 | case '0': |
| 1362 | case '1': |
| 1363 | case '2': |
| 1364 | case '3': |
| 1365 | case '4': |
| 1366 | case '5': |
| 1367 | case '6': |
| 1368 | case '7': |
| 1369 | case '8': |
| 1370 | case '9': |
| 1371 | fl_speed = 1; |
| 1372 | speed = speed*10 + c - '0'; |
| 1373 | break; |
| 1374 | case 'C': |
| 1375 | case 'c': |
| 1376 | rndis_signal_connect (p->confignr); |
| 1377 | break; |
| 1378 | case 'D': |
| 1379 | case 'd': |
| 1380 | rndis_signal_disconnect(p->confignr); |
| 1381 | break; |
David Brownell | 7e27f18 | 2006-06-13 09:54:40 -0700 | [diff] [blame] | 1382 | default: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1383 | if (fl_speed) p->speed = speed; |
| 1384 | else DEBUG ("%c is not valid\n", c); |
| 1385 | break; |
| 1386 | } |
David Brownell | 7e27f18 | 2006-06-13 09:54:40 -0700 | [diff] [blame] | 1387 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1388 | buffer++; |
| 1389 | } |
David Brownell | 7e27f18 | 2006-06-13 09:54:40 -0700 | [diff] [blame] | 1390 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1391 | return count; |
| 1392 | } |
| 1393 | |
| 1394 | #define NAME_TEMPLATE "driver/rndis-%03d" |
| 1395 | |
| 1396 | static struct proc_dir_entry *rndis_connect_state [RNDIS_MAX_CONFIGS]; |
| 1397 | |
| 1398 | #endif /* CONFIG_USB_GADGET_DEBUG_FILES */ |
| 1399 | |
| 1400 | |
David Brownell | a353678 | 2006-07-06 15:48:53 -0700 | [diff] [blame] | 1401 | int __devinit rndis_init (void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1402 | { |
| 1403 | u8 i; |
| 1404 | |
| 1405 | for (i = 0; i < RNDIS_MAX_CONFIGS; i++) { |
| 1406 | #ifdef CONFIG_USB_GADGET_DEBUG_FILES |
| 1407 | char name [20]; |
| 1408 | |
| 1409 | sprintf (name, NAME_TEMPLATE, i); |
| 1410 | if (!(rndis_connect_state [i] |
David Brownell | 7e27f18 | 2006-06-13 09:54:40 -0700 | [diff] [blame] | 1411 | = create_proc_entry (name, 0660, NULL))) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1412 | { |
| 1413 | DEBUG ("%s :remove entries", __FUNCTION__); |
| 1414 | while (i) { |
| 1415 | sprintf (name, NAME_TEMPLATE, --i); |
| 1416 | remove_proc_entry (name, NULL); |
| 1417 | } |
| 1418 | DEBUG ("\n"); |
| 1419 | return -EIO; |
| 1420 | } |
| 1421 | |
| 1422 | rndis_connect_state [i]->nlink = 1; |
| 1423 | rndis_connect_state [i]->write_proc = rndis_proc_write; |
| 1424 | rndis_connect_state [i]->read_proc = rndis_proc_read; |
| 1425 | rndis_connect_state [i]->data = (void *) |
| 1426 | (rndis_per_dev_params + i); |
| 1427 | #endif |
| 1428 | rndis_per_dev_params [i].confignr = i; |
| 1429 | rndis_per_dev_params [i].used = 0; |
| 1430 | rndis_per_dev_params [i].state = RNDIS_UNINITIALIZED; |
| 1431 | rndis_per_dev_params [i].media_state |
| 1432 | = NDIS_MEDIA_STATE_DISCONNECTED; |
| 1433 | INIT_LIST_HEAD (&(rndis_per_dev_params [i].resp_queue)); |
| 1434 | } |
David Brownell | 7e27f18 | 2006-06-13 09:54:40 -0700 | [diff] [blame] | 1435 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1436 | return 0; |
| 1437 | } |
| 1438 | |
| 1439 | void rndis_exit (void) |
| 1440 | { |
| 1441 | #ifdef CONFIG_USB_GADGET_DEBUG_FILES |
| 1442 | u8 i; |
| 1443 | char name [20]; |
David Brownell | 7e27f18 | 2006-06-13 09:54:40 -0700 | [diff] [blame] | 1444 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1445 | for (i = 0; i < RNDIS_MAX_CONFIGS; i++) { |
| 1446 | sprintf (name, NAME_TEMPLATE, i); |
| 1447 | remove_proc_entry (name, NULL); |
| 1448 | } |
| 1449 | #endif |
| 1450 | } |
| 1451 | |