Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

[PATCH] USB: rndis updates (mostly cleanup)

Some bugfixes and lots of cleanup (net code shrink):

- On reset, force the RNDIS state machine its initial state

- Hook up the RNDIS (outgoing) filters to the CDC mechanism

- Lots of cleanup:
* Eliminate duplicate copy of OID table;
* Unify handlying of the OID "query" response data pointer;
* Reduce code duplication for calculating query response lengths;
* Remove some checks for "can't happen" errors;
* Get rid of debugging #ifdefs by making the debug flag an integer level

Most of the patch, by volume, relates to those query response cleanups.
It incidentally shaves off a few hundred bytes of object code.

Signed-off-by: David Brownell <dbrownell@users.sourceforge.net>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>

authored by

David Brownell and committed by
Greg Kroah-Hartman
340600ab 247f3105

+285 -344
+7 -4
drivers/usb/gadget/ether.c
··· 94 94 #ifdef CONFIG_USB_ETH_RNDIS 95 95 #include "rndis.h" 96 96 #else 97 - #define rndis_init() 0 98 - #define rndis_exit() do{}while(0) 97 + #define rndis_init() 0 98 + #define rndis_uninit(x) do{}while(0) 99 + #define rndis_exit() do{}while(0) 99 100 #endif 100 101 101 102 /* CDC and RNDIS support the same host-chosen outgoing packet filters. */ ··· 396 395 #define STRING_SUBSET 8 397 396 #define STRING_RNDIS 9 398 397 399 - #define USB_BUFSIZ 256 /* holds our biggest descriptor */ 398 + /* holds our biggest descriptor (or RNDIS response) */ 399 + #define USB_BUFSIZ 256 400 400 401 401 /* 402 402 * This device advertises one configuration, eth_config, unless RNDIS ··· 1126 1124 1127 1125 netif_stop_queue (dev->net); 1128 1126 netif_carrier_off (dev->net); 1127 + rndis_uninit(dev->rndis_config); 1129 1128 1130 1129 /* disable endpoints, forcing (synchronous) completion of 1131 1130 * pending i/o. then free the requests. ··· 2568 2565 /* these set up a lot of the OIDs that RNDIS needs */ 2569 2566 rndis_set_host_mac (dev->rndis_config, dev->host_mac); 2570 2567 if (rndis_set_param_dev (dev->rndis_config, dev->net, 2571 - &dev->stats)) 2568 + &dev->stats, &dev->cdc_filter)) 2572 2569 goto fail0; 2573 2570 if (rndis_set_param_vendor (dev->rndis_config, vendorID, 2574 2571 manufacturer))
+7 -7
drivers/usb/gadget/ndis.h
··· 47 47 #define NDIS_DEVICE_WAKE_ON_MAGIC_PACKET_ENABLE 0x00000004 48 48 49 49 struct NDIS_PNP_CAPABILITIES { 50 - u32 Flags; 50 + __le32 Flags; 51 51 struct NDIS_PM_WAKE_UP_CAPABILITIES WakeUpCapabilities; 52 52 }; 53 53 54 54 struct NDIS_PM_PACKET_PATTERN { 55 - u32 Priority; 56 - u32 Reserved; 57 - u32 MaskSize; 58 - u32 PatternOffset; 59 - u32 PatternSize; 60 - u32 PatternFlags; 55 + __le32 Priority; 56 + __le32 Reserved; 57 + __le32 MaskSize; 58 + __le32 PatternOffset; 59 + __le32 PatternSize; 60 + __le32 PatternFlags; 61 61 }; 62 62 63 63
+263 -246
drivers/usb/gadget/rndis.c
··· 41 41 42 42 43 43 #undef RNDIS_PM 44 + #undef RNDIS_WAKEUP 44 45 #undef VERBOSE 45 46 46 47 #include "rndis.h" ··· 61 60 } while (0) 62 61 static int rndis_debug = 0; 63 62 64 - module_param (rndis_debug, bool, 0); 63 + module_param (rndis_debug, int, 0); 65 64 MODULE_PARM_DESC (rndis_debug, "enable debugging"); 66 65 67 66 #else ··· 79 78 static const __le32 rndis_driver_version = __constant_cpu_to_le32 (1); 80 79 81 80 /* Function Prototypes */ 82 - static int rndis_init_response (int configNr, rndis_init_msg_type *buf); 83 - static int rndis_query_response (int configNr, rndis_query_msg_type *buf); 84 - static int rndis_set_response (int configNr, rndis_set_msg_type *buf); 85 - static int rndis_reset_response (int configNr, rndis_reset_msg_type *buf); 86 - static int rndis_keepalive_response (int configNr, 87 - rndis_keepalive_msg_type *buf); 88 - 89 81 static rndis_resp_t *rndis_add_response (int configNr, u32 length); 90 82 91 83 84 + /* supported OIDs */ 85 + static const u32 oid_supported_list [] = 86 + { 87 + /* the general stuff */ 88 + OID_GEN_SUPPORTED_LIST, 89 + OID_GEN_HARDWARE_STATUS, 90 + OID_GEN_MEDIA_SUPPORTED, 91 + OID_GEN_MEDIA_IN_USE, 92 + OID_GEN_MAXIMUM_FRAME_SIZE, 93 + OID_GEN_LINK_SPEED, 94 + OID_GEN_TRANSMIT_BLOCK_SIZE, 95 + OID_GEN_RECEIVE_BLOCK_SIZE, 96 + OID_GEN_VENDOR_ID, 97 + OID_GEN_VENDOR_DESCRIPTION, 98 + OID_GEN_VENDOR_DRIVER_VERSION, 99 + OID_GEN_CURRENT_PACKET_FILTER, 100 + OID_GEN_MAXIMUM_TOTAL_SIZE, 101 + OID_GEN_MEDIA_CONNECT_STATUS, 102 + OID_GEN_PHYSICAL_MEDIUM, 103 + #if 0 104 + OID_GEN_RNDIS_CONFIG_PARAMETER, 105 + #endif 106 + 107 + /* the statistical stuff */ 108 + OID_GEN_XMIT_OK, 109 + OID_GEN_RCV_OK, 110 + OID_GEN_XMIT_ERROR, 111 + OID_GEN_RCV_ERROR, 112 + OID_GEN_RCV_NO_BUFFER, 113 + #ifdef RNDIS_OPTIONAL_STATS 114 + OID_GEN_DIRECTED_BYTES_XMIT, 115 + OID_GEN_DIRECTED_FRAMES_XMIT, 116 + OID_GEN_MULTICAST_BYTES_XMIT, 117 + OID_GEN_MULTICAST_FRAMES_XMIT, 118 + OID_GEN_BROADCAST_BYTES_XMIT, 119 + OID_GEN_BROADCAST_FRAMES_XMIT, 120 + OID_GEN_DIRECTED_BYTES_RCV, 121 + OID_GEN_DIRECTED_FRAMES_RCV, 122 + OID_GEN_MULTICAST_BYTES_RCV, 123 + OID_GEN_MULTICAST_FRAMES_RCV, 124 + OID_GEN_BROADCAST_BYTES_RCV, 125 + OID_GEN_BROADCAST_FRAMES_RCV, 126 + OID_GEN_RCV_CRC_ERROR, 127 + OID_GEN_TRANSMIT_QUEUE_LENGTH, 128 + #endif /* RNDIS_OPTIONAL_STATS */ 129 + 130 + /* mandatory 802.3 */ 131 + /* the general stuff */ 132 + OID_802_3_PERMANENT_ADDRESS, 133 + OID_802_3_CURRENT_ADDRESS, 134 + OID_802_3_MULTICAST_LIST, 135 + OID_802_3_MAC_OPTIONS, 136 + OID_802_3_MAXIMUM_LIST_SIZE, 137 + 138 + /* the statistical stuff */ 139 + OID_802_3_RCV_ERROR_ALIGNMENT, 140 + OID_802_3_XMIT_ONE_COLLISION, 141 + OID_802_3_XMIT_MORE_COLLISIONS, 142 + #ifdef RNDIS_OPTIONAL_STATS 143 + OID_802_3_XMIT_DEFERRED, 144 + OID_802_3_XMIT_MAX_COLLISIONS, 145 + OID_802_3_RCV_OVERRUN, 146 + OID_802_3_XMIT_UNDERRUN, 147 + OID_802_3_XMIT_HEARTBEAT_FAILURE, 148 + OID_802_3_XMIT_TIMES_CRS_LOST, 149 + OID_802_3_XMIT_LATE_COLLISIONS, 150 + #endif /* RNDIS_OPTIONAL_STATS */ 151 + 152 + #ifdef RNDIS_PM 153 + /* PM and wakeup are mandatory for USB: */ 154 + 155 + /* power management */ 156 + OID_PNP_CAPABILITIES, 157 + OID_PNP_QUERY_POWER, 158 + OID_PNP_SET_POWER, 159 + 160 + #ifdef RNDIS_WAKEUP 161 + /* wake up host */ 162 + OID_PNP_ENABLE_WAKE_UP, 163 + OID_PNP_ADD_WAKE_UP_PATTERN, 164 + OID_PNP_REMOVE_WAKE_UP_PATTERN, 165 + #endif /* RNDIS_WAKEUP */ 166 + #endif /* RNDIS_PM */ 167 + }; 168 + 169 + 92 170 /* NDIS Functions */ 93 - static int gen_ndis_query_resp (int configNr, u32 OID, rndis_resp_t *r) 171 + static int 172 + gen_ndis_query_resp (int configNr, u32 OID, u8 *buf, unsigned buf_len, 173 + rndis_resp_t *r) 94 174 { 95 175 int retval = -ENOTSUPP; 96 - u32 length = 0; 97 - __le32 *tmp; 176 + u32 length = 4; /* usually */ 177 + __le32 *outbuf; 98 178 int i, count; 99 179 rndis_query_cmplt_type *resp; 100 180 ··· 183 101 resp = (rndis_query_cmplt_type *) r->buf; 184 102 185 103 if (!resp) return -ENOMEM; 186 - 104 + 105 + if (buf_len && rndis_debug > 1) { 106 + DEBUG("query OID %08x value, len %d:\n", OID, buf_len); 107 + for (i = 0; i < buf_len; i += 16) { 108 + DEBUG ("%03d: %08x %08x %08x %08x\n", i, 109 + le32_to_cpup((__le32 *)&buf[i]), 110 + le32_to_cpup((__le32 *)&buf[i + 4]), 111 + le32_to_cpup((__le32 *)&buf[i + 8]), 112 + le32_to_cpup((__le32 *)&buf[i + 12])); 113 + } 114 + } 115 + 116 + /* response goes here, right after the header */ 117 + outbuf = (__le32 *) &resp[1]; 118 + resp->InformationBufferOffset = __constant_cpu_to_le32 (16); 119 + 187 120 switch (OID) { 188 121 189 122 /* general oids (table 4-1) */ ··· 208 111 DEBUG ("%s: OID_GEN_SUPPORTED_LIST\n", __FUNCTION__); 209 112 length = sizeof (oid_supported_list); 210 113 count = length / sizeof (u32); 211 - tmp = (__le32 *) ((u8 *)resp + 24); 212 114 for (i = 0; i < count; i++) 213 - tmp[i] = cpu_to_le32 (oid_supported_list[i]); 115 + outbuf[i] = cpu_to_le32 (oid_supported_list[i]); 214 116 retval = 0; 215 117 break; 216 118 217 119 /* mandatory */ 218 120 case OID_GEN_HARDWARE_STATUS: 219 121 DEBUG("%s: OID_GEN_HARDWARE_STATUS\n", __FUNCTION__); 220 - length = 4; 221 122 /* Bogus question! 222 123 * Hardware must be ready to receive high level protocols. 223 124 * BTW: 224 125 * reddite ergo quae sunt Caesaris Caesari 225 126 * et quae sunt Dei Deo! 226 127 */ 227 - *((__le32 *) resp + 6) = __constant_cpu_to_le32 (0); 128 + *outbuf = __constant_cpu_to_le32 (0); 228 129 retval = 0; 229 130 break; 230 131 231 132 /* mandatory */ 232 133 case OID_GEN_MEDIA_SUPPORTED: 233 134 DEBUG("%s: OID_GEN_MEDIA_SUPPORTED\n", __FUNCTION__); 234 - length = 4; 235 - *((__le32 *) resp + 6) = cpu_to_le32 ( 236 - rndis_per_dev_params [configNr].medium); 135 + *outbuf = cpu_to_le32 (rndis_per_dev_params [configNr].medium); 237 136 retval = 0; 238 137 break; 239 138 240 139 /* mandatory */ 241 140 case OID_GEN_MEDIA_IN_USE: 242 141 DEBUG("%s: OID_GEN_MEDIA_IN_USE\n", __FUNCTION__); 243 - length = 4; 244 142 /* one medium, one transport... (maybe you do it better) */ 245 - *((__le32 *) resp + 6) = cpu_to_le32 ( 246 - rndis_per_dev_params [configNr].medium); 143 + *outbuf = cpu_to_le32 (rndis_per_dev_params [configNr].medium); 247 144 retval = 0; 248 145 break; 249 146 ··· 245 154 case OID_GEN_MAXIMUM_FRAME_SIZE: 246 155 DEBUG("%s: OID_GEN_MAXIMUM_FRAME_SIZE\n", __FUNCTION__); 247 156 if (rndis_per_dev_params [configNr].dev) { 248 - length = 4; 249 - *((__le32 *) resp + 6) = cpu_to_le32 ( 157 + *outbuf = cpu_to_le32 ( 250 158 rndis_per_dev_params [configNr].dev->mtu); 251 - retval = 0; 252 - } else { 253 - *((__le32 *) resp + 6) = __constant_cpu_to_le32 (0); 254 159 retval = 0; 255 160 } 256 161 break; 257 162 258 163 /* mandatory */ 259 164 case OID_GEN_LINK_SPEED: 260 - // DEBUG("%s: OID_GEN_LINK_SPEED\n", __FUNCTION__); 261 - length = 4; 165 + if (rndis_debug > 1) 166 + DEBUG("%s: OID_GEN_LINK_SPEED\n", __FUNCTION__); 262 167 if (rndis_per_dev_params [configNr].media_state 263 - == NDIS_MEDIA_STATE_DISCONNECTED) 264 - *((__le32 *) resp + 6) = __constant_cpu_to_le32 (0); 168 + == NDIS_MEDIA_STATE_DISCONNECTED) 169 + *outbuf = __constant_cpu_to_le32 (0); 265 170 else 266 - *((__le32 *) resp + 6) = cpu_to_le32 ( 171 + *outbuf = cpu_to_le32 ( 267 172 rndis_per_dev_params [configNr].speed); 268 173 retval = 0; 269 174 break; ··· 268 181 case OID_GEN_TRANSMIT_BLOCK_SIZE: 269 182 DEBUG("%s: OID_GEN_TRANSMIT_BLOCK_SIZE\n", __FUNCTION__); 270 183 if (rndis_per_dev_params [configNr].dev) { 271 - length = 4; 272 - *((__le32 *) resp + 6) = cpu_to_le32 ( 184 + *outbuf = cpu_to_le32 ( 273 185 rndis_per_dev_params [configNr].dev->mtu); 274 186 retval = 0; 275 187 } ··· 278 192 case OID_GEN_RECEIVE_BLOCK_SIZE: 279 193 DEBUG("%s: OID_GEN_RECEIVE_BLOCK_SIZE\n", __FUNCTION__); 280 194 if (rndis_per_dev_params [configNr].dev) { 281 - length = 4; 282 - *((__le32 *) resp + 6) = cpu_to_le32 ( 195 + *outbuf = cpu_to_le32 ( 283 196 rndis_per_dev_params [configNr].dev->mtu); 284 197 retval = 0; 285 198 } ··· 287 202 /* mandatory */ 288 203 case OID_GEN_VENDOR_ID: 289 204 DEBUG("%s: OID_GEN_VENDOR_ID\n", __FUNCTION__); 290 - length = 4; 291 - *((__le32 *) resp + 6) = cpu_to_le32 ( 205 + *outbuf = cpu_to_le32 ( 292 206 rndis_per_dev_params [configNr].vendorID); 293 207 retval = 0; 294 208 break; ··· 296 212 case OID_GEN_VENDOR_DESCRIPTION: 297 213 DEBUG("%s: OID_GEN_VENDOR_DESCRIPTION\n", __FUNCTION__); 298 214 length = strlen (rndis_per_dev_params [configNr].vendorDescr); 299 - memcpy ((u8 *) resp + 24, 215 + memcpy (outbuf, 300 216 rndis_per_dev_params [configNr].vendorDescr, length); 301 217 retval = 0; 302 218 break; 303 219 304 220 case OID_GEN_VENDOR_DRIVER_VERSION: 305 221 DEBUG("%s: OID_GEN_VENDOR_DRIVER_VERSION\n", __FUNCTION__); 306 - length = 4; 307 222 /* Created as LE */ 308 - *((__le32 *) resp + 6) = rndis_driver_version; 223 + *outbuf = rndis_driver_version; 309 224 retval = 0; 310 225 break; 311 226 312 227 /* mandatory */ 313 228 case OID_GEN_CURRENT_PACKET_FILTER: 314 229 DEBUG("%s: OID_GEN_CURRENT_PACKET_FILTER\n", __FUNCTION__); 315 - length = 4; 316 - *((__le32 *) resp + 6) = cpu_to_le32 ( 317 - rndis_per_dev_params[configNr].filter); 230 + *outbuf = cpu_to_le32 (*rndis_per_dev_params[configNr].filter); 318 231 retval = 0; 319 232 break; 320 233 321 234 /* mandatory */ 322 235 case OID_GEN_MAXIMUM_TOTAL_SIZE: 323 236 DEBUG("%s: OID_GEN_MAXIMUM_TOTAL_SIZE\n", __FUNCTION__); 324 - length = 4; 325 - *((__le32 *) resp + 6) = __constant_cpu_to_le32( 326 - RNDIS_MAX_TOTAL_SIZE); 237 + *outbuf = __constant_cpu_to_le32(RNDIS_MAX_TOTAL_SIZE); 327 238 retval = 0; 328 239 break; 329 240 330 241 /* mandatory */ 331 242 case OID_GEN_MEDIA_CONNECT_STATUS: 332 - DEBUG("%s: OID_GEN_MEDIA_CONNECT_STATUS\n", __FUNCTION__); 333 - length = 4; 334 - *((__le32 *) resp + 6) = cpu_to_le32 ( 335 - rndis_per_dev_params [configNr] 243 + if (rndis_debug > 1) 244 + DEBUG("%s: OID_GEN_MEDIA_CONNECT_STATUS\n", __FUNCTION__); 245 + *outbuf = cpu_to_le32 (rndis_per_dev_params [configNr] 336 246 .media_state); 337 247 retval = 0; 338 248 break; 339 249 340 250 case OID_GEN_PHYSICAL_MEDIUM: 341 251 DEBUG("%s: OID_GEN_PHYSICAL_MEDIUM\n", __FUNCTION__); 342 - length = 4; 343 - *((__le32 *) resp + 6) = __constant_cpu_to_le32 (0); 252 + *outbuf = __constant_cpu_to_le32 (0); 344 253 retval = 0; 345 254 break; 346 255 ··· 343 266 */ 344 267 case OID_GEN_MAC_OPTIONS: /* from WinME */ 345 268 DEBUG("%s: OID_GEN_MAC_OPTIONS\n", __FUNCTION__); 346 - length = 4; 347 - *((__le32 *) resp + 6) = __constant_cpu_to_le32( 269 + *outbuf = __constant_cpu_to_le32( 348 270 NDIS_MAC_OPTION_RECEIVE_SERIALIZED 349 271 | NDIS_MAC_OPTION_FULL_DUPLEX); 350 272 retval = 0; ··· 353 277 354 278 /* mandatory */ 355 279 case OID_GEN_XMIT_OK: 356 - DEBUG("%s: OID_GEN_XMIT_OK\n", __FUNCTION__); 280 + if (rndis_debug > 1) 281 + DEBUG("%s: OID_GEN_XMIT_OK\n", __FUNCTION__); 357 282 if (rndis_per_dev_params [configNr].stats) { 358 - length = 4; 359 - *((__le32 *) resp + 6) = cpu_to_le32 ( 283 + *outbuf = cpu_to_le32 ( 360 284 rndis_per_dev_params [configNr].stats->tx_packets - 361 285 rndis_per_dev_params [configNr].stats->tx_errors - 362 286 rndis_per_dev_params [configNr].stats->tx_dropped); 363 - retval = 0; 364 - } else { 365 - *((__le32 *) resp + 6) = __constant_cpu_to_le32 (0); 366 287 retval = 0; 367 288 } 368 289 break; 369 290 370 291 /* mandatory */ 371 292 case OID_GEN_RCV_OK: 372 - DEBUG("%s: OID_GEN_RCV_OK\n", __FUNCTION__); 293 + if (rndis_debug > 1) 294 + DEBUG("%s: OID_GEN_RCV_OK\n", __FUNCTION__); 373 295 if (rndis_per_dev_params [configNr].stats) { 374 - length = 4; 375 - *((__le32 *) resp + 6) = cpu_to_le32 ( 296 + *outbuf = cpu_to_le32 ( 376 297 rndis_per_dev_params [configNr].stats->rx_packets - 377 298 rndis_per_dev_params [configNr].stats->rx_errors - 378 299 rndis_per_dev_params [configNr].stats->rx_dropped); 379 - retval = 0; 380 - } else { 381 - *((__le32 *) resp + 6) = __constant_cpu_to_le32 (0); 382 300 retval = 0; 383 301 } 384 302 break; 385 303 386 304 /* mandatory */ 387 305 case OID_GEN_XMIT_ERROR: 388 - DEBUG("%s: OID_GEN_XMIT_ERROR\n", __FUNCTION__); 306 + if (rndis_debug > 1) 307 + DEBUG("%s: OID_GEN_XMIT_ERROR\n", __FUNCTION__); 389 308 if (rndis_per_dev_params [configNr].stats) { 390 - length = 4; 391 - *((__le32 *) resp + 6) = cpu_to_le32 ( 392 - rndis_per_dev_params [configNr] 309 + *outbuf = cpu_to_le32 (rndis_per_dev_params [configNr] 393 310 .stats->tx_errors); 394 - retval = 0; 395 - } else { 396 - *((__le32 *) resp + 6) = __constant_cpu_to_le32 (0); 397 311 retval = 0; 398 312 } 399 313 break; 400 314 401 315 /* mandatory */ 402 316 case OID_GEN_RCV_ERROR: 403 - DEBUG("%s: OID_GEN_RCV_ERROR\n", __FUNCTION__); 317 + if (rndis_debug > 1) 318 + DEBUG("%s: OID_GEN_RCV_ERROR\n", __FUNCTION__); 404 319 if (rndis_per_dev_params [configNr].stats) { 405 - *((__le32 *) resp + 6) = cpu_to_le32 ( 406 - rndis_per_dev_params [configNr] 320 + *outbuf = cpu_to_le32 (rndis_per_dev_params [configNr] 407 321 .stats->rx_errors); 408 - retval = 0; 409 - } else { 410 - *((__le32 *) resp + 6) = __constant_cpu_to_le32 (0); 411 322 retval = 0; 412 323 } 413 324 break; ··· 403 340 case OID_GEN_RCV_NO_BUFFER: 404 341 DEBUG("%s: OID_GEN_RCV_NO_BUFFER\n", __FUNCTION__); 405 342 if (rndis_per_dev_params [configNr].stats) { 406 - *((__le32 *) resp + 6) = cpu_to_le32 ( 407 - rndis_per_dev_params [configNr] 343 + *outbuf = cpu_to_le32 (rndis_per_dev_params [configNr] 408 344 .stats->rx_dropped); 409 - retval = 0; 410 - } else { 411 - *((__le32 *) resp + 6) = __constant_cpu_to_le32 (0); 412 345 retval = 0; 413 346 } 414 347 break; ··· 418 359 * divided by weight of Alpha Centauri 419 360 */ 420 361 if (rndis_per_dev_params [configNr].stats) { 421 - length = 4; 422 - *((__le32 *) resp + 6) = cpu_to_le32 ( 362 + *outbuf = cpu_to_le32 ( 423 363 (rndis_per_dev_params [configNr] 424 364 .stats->tx_packets - 425 365 rndis_per_dev_params [configNr] ··· 427 369 .stats->tx_dropped) 428 370 * 123); 429 371 retval = 0; 430 - } else { 431 - *((__le32 *) resp + 6) = __constant_cpu_to_le32 (0); 432 - retval = 0; 433 372 } 434 373 break; 435 374 ··· 434 379 DEBUG("%s: OID_GEN_DIRECTED_FRAMES_XMIT\n", __FUNCTION__); 435 380 /* dito */ 436 381 if (rndis_per_dev_params [configNr].stats) { 437 - length = 4; 438 - *((__le32 *) resp + 6) = cpu_to_le32 ( 382 + *outbuf = cpu_to_le32 ( 439 383 (rndis_per_dev_params [configNr] 440 384 .stats->tx_packets - 441 385 rndis_per_dev_params [configNr] ··· 443 389 .stats->tx_dropped) 444 390 / 123); 445 391 retval = 0; 446 - } else { 447 - *((__le32 *) resp + 6) = __constant_cpu_to_le32 (0); 448 - retval = 0; 449 392 } 450 393 break; 451 394 452 395 case OID_GEN_MULTICAST_BYTES_XMIT: 453 396 DEBUG("%s: OID_GEN_MULTICAST_BYTES_XMIT\n", __FUNCTION__); 454 397 if (rndis_per_dev_params [configNr].stats) { 455 - *((__le32 *) resp + 6) = cpu_to_le32 ( 456 - rndis_per_dev_params [configNr] 398 + *outbuf = cpu_to_le32 (rndis_per_dev_params [configNr] 457 399 .stats->multicast*1234); 458 - retval = 0; 459 - } else { 460 - *((__le32 *) resp + 6) = __constant_cpu_to_le32 (0); 461 400 retval = 0; 462 401 } 463 402 break; ··· 458 411 case OID_GEN_MULTICAST_FRAMES_XMIT: 459 412 DEBUG("%s: OID_GEN_MULTICAST_FRAMES_XMIT\n", __FUNCTION__); 460 413 if (rndis_per_dev_params [configNr].stats) { 461 - *((__le32 *) resp + 6) = cpu_to_le32 ( 462 - rndis_per_dev_params [configNr] 414 + *outbuf = cpu_to_le32 (rndis_per_dev_params [configNr] 463 415 .stats->multicast); 464 - retval = 0; 465 - } else { 466 - *((__le32 *) resp + 6) = __constant_cpu_to_le32 (0); 467 416 retval = 0; 468 417 } 469 418 break; ··· 467 424 case OID_GEN_BROADCAST_BYTES_XMIT: 468 425 DEBUG("%s: OID_GEN_BROADCAST_BYTES_XMIT\n", __FUNCTION__); 469 426 if (rndis_per_dev_params [configNr].stats) { 470 - *((__le32 *) resp + 6) = cpu_to_le32 ( 471 - rndis_per_dev_params [configNr] 427 + *outbuf = cpu_to_le32 (rndis_per_dev_params [configNr] 472 428 .stats->tx_packets/42*255); 473 - retval = 0; 474 - } else { 475 - *((__le32 *) resp + 6) = __constant_cpu_to_le32 (0); 476 429 retval = 0; 477 430 } 478 431 break; ··· 476 437 case OID_GEN_BROADCAST_FRAMES_XMIT: 477 438 DEBUG("%s: OID_GEN_BROADCAST_FRAMES_XMIT\n", __FUNCTION__); 478 439 if (rndis_per_dev_params [configNr].stats) { 479 - *((__le32 *) resp + 6) = cpu_to_le32 ( 480 - rndis_per_dev_params [configNr] 440 + *outbuf = cpu_to_le32 (rndis_per_dev_params [configNr] 481 441 .stats->tx_packets/42); 482 - retval = 0; 483 - } else { 484 - *((__le32 *) resp + 6) = __constant_cpu_to_le32 (0); 485 442 retval = 0; 486 443 } 487 444 break; 488 445 489 446 case OID_GEN_DIRECTED_BYTES_RCV: 490 447 DEBUG("%s: OID_GEN_DIRECTED_BYTES_RCV\n", __FUNCTION__); 491 - *((__le32 *) resp + 6) = __constant_cpu_to_le32 (0); 448 + *outbuf = __constant_cpu_to_le32 (0); 492 449 retval = 0; 493 450 break; 494 451 495 452 case OID_GEN_DIRECTED_FRAMES_RCV: 496 453 DEBUG("%s: OID_GEN_DIRECTED_FRAMES_RCV\n", __FUNCTION__); 497 - *((__le32 *) resp + 6) = __constant_cpu_to_le32 (0); 454 + *outbuf = __constant_cpu_to_le32 (0); 498 455 retval = 0; 499 456 break; 500 457 501 458 case OID_GEN_MULTICAST_BYTES_RCV: 502 459 DEBUG("%s: OID_GEN_MULTICAST_BYTES_RCV\n", __FUNCTION__); 503 460 if (rndis_per_dev_params [configNr].stats) { 504 - *((__le32 *) resp + 6) = cpu_to_le32 ( 505 - rndis_per_dev_params [configNr] 461 + *outbuf = cpu_to_le32 (rndis_per_dev_params [configNr] 506 462 .stats->multicast * 1111); 507 - retval = 0; 508 - } else { 509 - *((__le32 *) resp + 6) = __constant_cpu_to_le32 (0); 510 463 retval = 0; 511 464 } 512 465 break; ··· 506 475 case OID_GEN_MULTICAST_FRAMES_RCV: 507 476 DEBUG("%s: OID_GEN_MULTICAST_FRAMES_RCV\n", __FUNCTION__); 508 477 if (rndis_per_dev_params [configNr].stats) { 509 - *((__le32 *) resp + 6) = cpu_to_le32 ( 510 - rndis_per_dev_params [configNr] 478 + *outbuf = cpu_to_le32 (rndis_per_dev_params [configNr] 511 479 .stats->multicast); 512 - retval = 0; 513 - } else { 514 - *((__le32 *) resp + 6) = __constant_cpu_to_le32 (0); 515 480 retval = 0; 516 481 } 517 482 break; ··· 515 488 case OID_GEN_BROADCAST_BYTES_RCV: 516 489 DEBUG("%s: OID_GEN_BROADCAST_BYTES_RCV\n", __FUNCTION__); 517 490 if (rndis_per_dev_params [configNr].stats) { 518 - *((__le32 *) resp + 6) = cpu_to_le32 ( 519 - rndis_per_dev_params [configNr] 491 + *outbuf = cpu_to_le32 (rndis_per_dev_params [configNr] 520 492 .stats->rx_packets/42*255); 521 - retval = 0; 522 - } else { 523 - *((__le32 *) resp + 6) = __constant_cpu_to_le32 (0); 524 493 retval = 0; 525 494 } 526 495 break; ··· 524 501 case OID_GEN_BROADCAST_FRAMES_RCV: 525 502 DEBUG("%s: OID_GEN_BROADCAST_FRAMES_RCV\n", __FUNCTION__); 526 503 if (rndis_per_dev_params [configNr].stats) { 527 - *((__le32 *) resp + 6) = cpu_to_le32 ( 528 - rndis_per_dev_params [configNr] 504 + *outbuf = cpu_to_le32 (rndis_per_dev_params [configNr] 529 505 .stats->rx_packets/42); 530 - retval = 0; 531 - } else { 532 - *((__le32 *) resp + 6) = __constant_cpu_to_le32 (0); 533 506 retval = 0; 534 507 } 535 508 break; ··· 533 514 case OID_GEN_RCV_CRC_ERROR: 534 515 DEBUG("%s: OID_GEN_RCV_CRC_ERROR\n", __FUNCTION__); 535 516 if (rndis_per_dev_params [configNr].stats) { 536 - *((__le32 *) resp + 6) = cpu_to_le32 ( 537 - rndis_per_dev_params [configNr] 517 + *outbuf = cpu_to_le32 (rndis_per_dev_params [configNr] 538 518 .stats->rx_crc_errors); 539 - retval = 0; 540 - } else { 541 - *((__le32 *) resp + 6) = __constant_cpu_to_le32 (0); 542 519 retval = 0; 543 520 } 544 521 break; 545 522 546 523 case OID_GEN_TRANSMIT_QUEUE_LENGTH: 547 524 DEBUG("%s: OID_GEN_TRANSMIT_QUEUE_LENGTH\n", __FUNCTION__); 548 - *((__le32 *) resp + 6) = __constant_cpu_to_le32 (0); 525 + *outbuf = __constant_cpu_to_le32 (0); 549 526 retval = 0; 550 527 break; 551 528 #endif /* RNDIS_OPTIONAL_STATS */ ··· 553 538 DEBUG("%s: OID_802_3_PERMANENT_ADDRESS\n", __FUNCTION__); 554 539 if (rndis_per_dev_params [configNr].dev) { 555 540 length = ETH_ALEN; 556 - memcpy ((u8 *) resp + 24, 541 + memcpy (outbuf, 557 542 rndis_per_dev_params [configNr].host_mac, 558 543 length); 559 - retval = 0; 560 - } else { 561 - *((__le32 *) resp + 6) = __constant_cpu_to_le32 (0); 562 544 retval = 0; 563 545 } 564 546 break; ··· 565 553 DEBUG("%s: OID_802_3_CURRENT_ADDRESS\n", __FUNCTION__); 566 554 if (rndis_per_dev_params [configNr].dev) { 567 555 length = ETH_ALEN; 568 - memcpy ((u8 *) resp + 24, 556 + memcpy (outbuf, 569 557 rndis_per_dev_params [configNr].host_mac, 570 558 length); 571 559 retval = 0; ··· 575 563 /* mandatory */ 576 564 case OID_802_3_MULTICAST_LIST: 577 565 DEBUG("%s: OID_802_3_MULTICAST_LIST\n", __FUNCTION__); 578 - length = 4; 579 566 /* Multicast base address only */ 580 - *((__le32 *) resp + 6) = __constant_cpu_to_le32 (0xE0000000); 567 + *outbuf = __constant_cpu_to_le32 (0xE0000000); 581 568 retval = 0; 582 569 break; 583 570 584 571 /* mandatory */ 585 572 case OID_802_3_MAXIMUM_LIST_SIZE: 586 573 DEBUG("%s: OID_802_3_MAXIMUM_LIST_SIZE\n", __FUNCTION__); 587 - length = 4; 588 574 /* Multicast base address only */ 589 - *((__le32 *) resp + 6) = __constant_cpu_to_le32 (1); 575 + *outbuf = __constant_cpu_to_le32 (1); 590 576 retval = 0; 591 577 break; 592 578 ··· 597 587 /* mandatory */ 598 588 case OID_802_3_RCV_ERROR_ALIGNMENT: 599 589 DEBUG("%s: OID_802_3_RCV_ERROR_ALIGNMENT\n", __FUNCTION__); 600 - if (rndis_per_dev_params [configNr].stats) 601 - { 602 - length = 4; 603 - *((__le32 *) resp + 6) = cpu_to_le32 ( 604 - rndis_per_dev_params [configNr] 590 + if (rndis_per_dev_params [configNr].stats) { 591 + *outbuf = cpu_to_le32 (rndis_per_dev_params [configNr] 605 592 .stats->rx_frame_errors); 606 593 retval = 0; 607 594 } ··· 607 600 /* mandatory */ 608 601 case OID_802_3_XMIT_ONE_COLLISION: 609 602 DEBUG("%s: OID_802_3_XMIT_ONE_COLLISION\n", __FUNCTION__); 610 - length = 4; 611 - *((__le32 *) resp + 6) = __constant_cpu_to_le32 (0); 603 + *outbuf = __constant_cpu_to_le32 (0); 612 604 retval = 0; 613 605 break; 614 606 615 607 /* mandatory */ 616 608 case OID_802_3_XMIT_MORE_COLLISIONS: 617 609 DEBUG("%s: OID_802_3_XMIT_MORE_COLLISIONS\n", __FUNCTION__); 618 - length = 4; 619 - *((__le32 *) resp + 6) = __constant_cpu_to_le32 (0); 610 + *outbuf = __constant_cpu_to_le32 (0); 620 611 retval = 0; 621 612 break; 622 613 ··· 660 655 case OID_PNP_CAPABILITIES: 661 656 DEBUG("%s: OID_PNP_CAPABILITIES\n", __FUNCTION__); 662 657 663 - /* just PM, and remote wakeup on link status change 664 - * (not magic packet or pattern match) 665 - */ 658 + /* for now, no wakeup capabilities */ 666 659 length = sizeof (struct NDIS_PNP_CAPABILITIES); 667 - memset (resp, 0, length); 668 - { 669 - struct NDIS_PNP_CAPABILITIES *caps = (void *) resp; 670 - 671 - caps->Flags = NDIS_DEVICE_WAKE_UP_ENABLE; 672 - caps->WakeUpCapabilities.MinLinkChangeWakeUp 673 - = NdisDeviceStateD3; 674 - 675 - /* FIXME then use usb_gadget_wakeup(), and 676 - * set USB_CONFIG_ATT_WAKEUP in config desc 677 - */ 678 - } 660 + memset(outbuf, 0, length); 679 661 retval = 0; 680 662 break; 681 663 case OID_PNP_QUERY_POWER: 682 - DEBUG("%s: OID_PNP_QUERY_POWER\n", __FUNCTION__); 683 - /* sure, handle any power state that maps to USB suspend */ 664 + DEBUG("%s: OID_PNP_QUERY_POWER D%d\n", __FUNCTION__, 665 + le32_to_cpup((__le32 *) buf) - 1); 666 + /* only suspend is a real power state, and 667 + * it can't be entered by OID_PNP_SET_POWER... 668 + */ 669 + length = 0; 684 670 retval = 0; 685 671 break; 686 672 #endif ··· 680 684 printk (KERN_WARNING "%s: query unknown OID 0x%08X\n", 681 685 __FUNCTION__, OID); 682 686 } 687 + if (retval < 0) 688 + length = 0; 683 689 684 - resp->InformationBufferOffset = __constant_cpu_to_le32 (16); 685 690 resp->InformationBufferLength = cpu_to_le32 (length); 686 - resp->MessageLength = cpu_to_le32 (24 + length); 687 - r->length = 24 + length; 691 + r->length = length + sizeof *resp; 692 + resp->MessageLength = cpu_to_le32 (r->length); 688 693 return retval; 689 694 } 690 695 ··· 702 705 if (!resp) 703 706 return -ENOMEM; 704 707 705 - DEBUG("set OID %08x value, len %d:\n", OID, buf_len); 706 - for (i = 0; i < buf_len; i += 16) { 707 - DEBUG ("%03d: " 708 - " %02x %02x %02x %02x" 709 - " %02x %02x %02x %02x" 710 - " %02x %02x %02x %02x" 711 - " %02x %02x %02x %02x" 712 - "\n", 713 - i, 714 - buf[i], buf [i+1], 715 - buf[i+2], buf[i+3], 716 - buf[i+4], buf [i+5], 717 - buf[i+6], buf[i+7], 718 - buf[i+8], buf [i+9], 719 - buf[i+10], buf[i+11], 720 - buf[i+12], buf [i+13], 721 - buf[i+14], buf[i+15]); 708 + if (buf_len && rndis_debug > 1) { 709 + DEBUG("set OID %08x value, len %d:\n", OID, buf_len); 710 + for (i = 0; i < buf_len; i += 16) { 711 + DEBUG ("%03d: %08x %08x %08x %08x\n", i, 712 + le32_to_cpup((__le32 *)&buf[i]), 713 + le32_to_cpup((__le32 *)&buf[i + 4]), 714 + le32_to_cpup((__le32 *)&buf[i + 8]), 715 + le32_to_cpup((__le32 *)&buf[i + 12])); 716 + } 722 717 } 723 718 719 + params = &rndis_per_dev_params [configNr]; 724 720 switch (OID) { 725 721 case OID_GEN_CURRENT_PACKET_FILTER: 726 - params = &rndis_per_dev_params [configNr]; 727 - retval = 0; 728 722 729 - /* FIXME use these NDIS_PACKET_TYPE_* bitflags to 730 - * set the cdc_filter; it's not RNDIS-specific 723 + /* these NDIS_PACKET_TYPE_* bitflags are shared with 724 + * cdc_filter; it's not RNDIS-specific 731 725 * NDIS_PACKET_TYPE_x == USB_CDC_PACKET_TYPE_x for x in: 732 726 * PROMISCUOUS, DIRECTED, 733 727 * MULTICAST, ALL_MULTICAST, BROADCAST 734 728 */ 735 - params->filter = le32_to_cpup((__le32 *)buf); 729 + *params->filter = (u16) le32_to_cpup((__le32 *)buf); 736 730 DEBUG("%s: OID_GEN_CURRENT_PACKET_FILTER %08x\n", 737 - __FUNCTION__, params->filter); 731 + __FUNCTION__, *params->filter); 738 732 739 733 /* this call has a significant side effect: it's 740 734 * what makes the packet flow start and stop, like 741 735 * activating the CDC Ethernet altsetting. 742 736 */ 743 - if (params->filter) { 737 + #ifdef RNDIS_PM 738 + update_linkstate: 739 + #endif 740 + retval = 0; 741 + if (*params->filter) { 744 742 params->state = RNDIS_DATA_INITIALIZED; 745 743 netif_carrier_on(params->dev); 746 744 if (netif_running(params->dev)) ··· 768 776 769 777 #ifdef RNDIS_PM 770 778 case OID_PNP_SET_POWER: 771 - DEBUG ("OID_PNP_SET_POWER\n"); 772 - /* sure, handle any power state that maps to USB suspend */ 773 - retval = 0; 779 + /* The only real power state is USB suspend, and RNDIS requests 780 + * can't enter it; this one isn't really about power. After 781 + * resuming, Windows forces a reset, and then SET_POWER D0. 782 + * FIXME ... then things go batty; Windows wedges itself. 783 + */ 784 + i = le32_to_cpup((__force __le32 *)buf); 785 + DEBUG("%s: OID_PNP_SET_POWER D%d\n", __FUNCTION__, i - 1); 786 + switch (i) { 787 + case NdisDeviceStateD0: 788 + *params->filter = params->saved_filter; 789 + goto update_linkstate; 790 + case NdisDeviceStateD3: 791 + case NdisDeviceStateD2: 792 + case NdisDeviceStateD1: 793 + params->saved_filter = *params->filter; 794 + retval = 0; 795 + break; 796 + } 774 797 break; 775 798 776 - case OID_PNP_ENABLE_WAKE_UP: 777 - /* always-connected ... */ 778 - DEBUG ("OID_PNP_ENABLE_WAKE_UP\n"); 779 - retval = 0; 780 - break; 781 - 782 - // no PM resume patterns supported (specified where?) 783 - // so OID_PNP_{ADD,REMOVE}_WAKE_UP_PATTERN always fails 799 + #ifdef RNDIS_WAKEUP 800 + // no wakeup support advertised, so wakeup OIDs always fail: 801 + // - OID_PNP_ENABLE_WAKE_UP 802 + // - OID_PNP_{ADD,REMOVE}_WAKE_UP_PATTERN 784 803 #endif 804 + 805 + #endif /* RNDIS_PM */ 785 806 786 807 default: 787 808 printk (KERN_WARNING "%s: set unknown OID 0x%08X, size %d\n", ··· 816 811 if (!rndis_per_dev_params [configNr].dev) return -ENOTSUPP; 817 812 818 813 r = rndis_add_response (configNr, sizeof (rndis_init_cmplt_type)); 819 - 820 - if (!r) return -ENOMEM; 821 - 814 + if (!r) 815 + return -ENOMEM; 822 816 resp = (rndis_init_cmplt_type *) r->buf; 823 - 824 - if (!resp) return -ENOMEM; 825 817 826 818 resp->MessageType = __constant_cpu_to_le32 ( 827 819 REMOTE_NDIS_INITIALIZE_CMPLT); ··· 859 857 * oid_supported_list is the largest answer 860 858 */ 861 859 r = rndis_add_response (configNr, sizeof (oid_supported_list)); 862 - 863 - if (!r) return -ENOMEM; 860 + if (!r) 861 + return -ENOMEM; 864 862 resp = (rndis_query_cmplt_type *) r->buf; 865 863 866 - if (!resp) return -ENOMEM; 867 - 868 864 resp->MessageType = __constant_cpu_to_le32 (REMOTE_NDIS_QUERY_CMPLT); 869 - resp->MessageLength = __constant_cpu_to_le32 (24); 870 865 resp->RequestID = buf->RequestID; /* Still LE in msg buffer */ 871 - 872 - if (gen_ndis_query_resp (configNr, le32_to_cpu (buf->OID), r)) { 866 + 867 + if (gen_ndis_query_resp (configNr, le32_to_cpu (buf->OID), 868 + le32_to_cpu(buf->InformationBufferOffset) 869 + + 8 + (u8 *) buf, 870 + le32_to_cpu(buf->InformationBufferLength), 871 + r)) { 873 872 /* OID not supported */ 874 873 resp->Status = __constant_cpu_to_le32 ( 875 874 RNDIS_STATUS_NOT_SUPPORTED); 875 + resp->MessageLength = __constant_cpu_to_le32 (sizeof *resp); 876 876 resp->InformationBufferLength = __constant_cpu_to_le32 (0); 877 877 resp->InformationBufferOffset = __constant_cpu_to_le32 (0); 878 878 } else ··· 893 889 rndis_resp_t *r; 894 890 895 891 r = rndis_add_response (configNr, sizeof (rndis_set_cmplt_type)); 896 - 897 - if (!r) return -ENOMEM; 892 + if (!r) 893 + return -ENOMEM; 898 894 resp = (rndis_set_cmplt_type *) r->buf; 899 - if (!resp) return -ENOMEM; 900 895 901 896 BufLength = le32_to_cpu (buf->InformationBufferLength); 902 897 BufOffset = le32_to_cpu (buf->InformationBufferOffset); ··· 933 930 rndis_resp_t *r; 934 931 935 932 r = rndis_add_response (configNr, sizeof (rndis_reset_cmplt_type)); 936 - 937 - if (!r) return -ENOMEM; 933 + if (!r) 934 + return -ENOMEM; 938 935 resp = (rndis_reset_cmplt_type *) r->buf; 939 - if (!resp) return -ENOMEM; 940 936 941 937 resp->MessageType = __constant_cpu_to_le32 (REMOTE_NDIS_RESET_CMPLT); 942 938 resp->MessageLength = __constant_cpu_to_le32 (16); ··· 959 957 /* host "should" check only in RNDIS_DATA_INITIALIZED state */ 960 958 961 959 r = rndis_add_response (configNr, sizeof (rndis_keepalive_cmplt_type)); 960 + if (!r) 961 + return -ENOMEM; 962 962 resp = (rndis_keepalive_cmplt_type *) r->buf; 963 - if (!resp) return -ENOMEM; 964 963 965 964 resp->MessageType = __constant_cpu_to_le32 ( 966 965 REMOTE_NDIS_KEEPALIVE_CMPLT); ··· 990 987 991 988 r = rndis_add_response (configNr, 992 989 sizeof (rndis_indicate_status_msg_type)); 993 - if (!r) return -ENOMEM; 994 - 990 + if (!r) 991 + return -ENOMEM; 995 992 resp = (rndis_indicate_status_msg_type *) r->buf; 996 - if (!resp) return -ENOMEM; 997 993 998 994 resp->MessageType = __constant_cpu_to_le32 ( 999 995 REMOTE_NDIS_INDICATE_STATUS_MSG); ··· 1023 1021 RNDIS_STATUS_MEDIA_DISCONNECT); 1024 1022 } 1025 1023 1024 + void rndis_uninit (int configNr) 1025 + { 1026 + if (configNr >= RNDIS_MAX_CONFIGS) 1027 + return; 1028 + rndis_per_dev_params [configNr].used = 0; 1029 + rndis_per_dev_params [configNr].state = RNDIS_UNINITIALIZED; 1030 + return; 1031 + } 1032 + 1026 1033 void rndis_set_host_mac (int configNr, const u8 *addr) 1027 1034 { 1028 1035 rndis_per_dev_params [configNr].host_mac = addr; ··· 1057 1046 return -ENOTSUPP; 1058 1047 params = &rndis_per_dev_params [configNr]; 1059 1048 1049 + /* NOTE: RNDIS is *EXTREMELY* chatty ... Windows constantly polls for 1050 + * rx/tx statistics and link status, in addition to KEEPALIVE traffic 1051 + * and normal HC level polling to see if there's any IN traffic. 1052 + */ 1053 + 1060 1054 /* For USB: responses may take up to 10 seconds */ 1061 - switch (MsgType) 1062 - { 1055 + switch (MsgType) { 1063 1056 case REMOTE_NDIS_INITIALIZE_MSG: 1064 1057 DEBUG("%s: REMOTE_NDIS_INITIALIZE_MSG\n", 1065 1058 __FUNCTION__ ); ··· 1097 1082 1098 1083 case REMOTE_NDIS_KEEPALIVE_MSG: 1099 1084 /* For USB: host does this every 5 seconds */ 1100 - #ifdef VERBOSE 1101 - DEBUG("%s: REMOTE_NDIS_KEEPALIVE_MSG\n", 1102 - __FUNCTION__ ); 1103 - #endif 1085 + if (rndis_debug > 1) 1086 + DEBUG("%s: REMOTE_NDIS_KEEPALIVE_MSG\n", 1087 + __FUNCTION__ ); 1104 1088 return rndis_keepalive_response (configNr, 1105 1089 (rndis_keepalive_msg_type *) 1106 1090 buf); ··· 1166 1152 } 1167 1153 1168 1154 int rndis_set_param_dev (u8 configNr, struct net_device *dev, 1169 - struct net_device_stats *stats) 1155 + struct net_device_stats *stats, 1156 + u16 *cdc_filter) 1170 1157 { 1171 1158 DEBUG("%s:\n", __FUNCTION__ ); 1172 1159 if (!dev || !stats) return -1; ··· 1175 1160 1176 1161 rndis_per_dev_params [configNr].dev = dev; 1177 1162 rndis_per_dev_params [configNr].stats = stats; 1163 + rndis_per_dev_params [configNr].filter = cdc_filter; 1178 1164 1179 1165 return 0; 1180 1166 } ··· 1194 1178 1195 1179 int rndis_set_param_medium (u8 configNr, u32 medium, u32 speed) 1196 1180 { 1197 - DEBUG("%s:\n", __FUNCTION__ ); 1181 + DEBUG("%s: %u %u\n", __FUNCTION__, medium, speed); 1198 1182 if (configNr >= RNDIS_MAX_CONFIGS) return -1; 1199 1183 1200 1184 rndis_per_dev_params [configNr].medium = medium; ··· 1258 1242 { 1259 1243 rndis_resp_t *r; 1260 1244 1245 + /* NOTE: this gets copied into ether.c USB_BUFSIZ bytes ... */ 1261 1246 r = kmalloc (sizeof (rndis_resp_t) + length, GFP_ATOMIC); 1262 1247 if (!r) return NULL; 1263 1248
+8 -87
drivers/usb/gadget/rndis.h
··· 69 69 #define OID_PNP_ENABLE_WAKE_UP 0xFD010106 70 70 71 71 72 - /* supported OIDs */ 73 - static const u32 oid_supported_list [] = 74 - { 75 - /* the general stuff */ 76 - OID_GEN_SUPPORTED_LIST, 77 - OID_GEN_HARDWARE_STATUS, 78 - OID_GEN_MEDIA_SUPPORTED, 79 - OID_GEN_MEDIA_IN_USE, 80 - OID_GEN_MAXIMUM_FRAME_SIZE, 81 - OID_GEN_LINK_SPEED, 82 - OID_GEN_TRANSMIT_BLOCK_SIZE, 83 - OID_GEN_RECEIVE_BLOCK_SIZE, 84 - OID_GEN_VENDOR_ID, 85 - OID_GEN_VENDOR_DESCRIPTION, 86 - OID_GEN_VENDOR_DRIVER_VERSION, 87 - OID_GEN_CURRENT_PACKET_FILTER, 88 - OID_GEN_MAXIMUM_TOTAL_SIZE, 89 - OID_GEN_MEDIA_CONNECT_STATUS, 90 - OID_GEN_PHYSICAL_MEDIUM, 91 - #if 0 92 - OID_GEN_RNDIS_CONFIG_PARAMETER, 93 - #endif 94 - 95 - /* the statistical stuff */ 96 - OID_GEN_XMIT_OK, 97 - OID_GEN_RCV_OK, 98 - OID_GEN_XMIT_ERROR, 99 - OID_GEN_RCV_ERROR, 100 - OID_GEN_RCV_NO_BUFFER, 101 - #ifdef RNDIS_OPTIONAL_STATS 102 - OID_GEN_DIRECTED_BYTES_XMIT, 103 - OID_GEN_DIRECTED_FRAMES_XMIT, 104 - OID_GEN_MULTICAST_BYTES_XMIT, 105 - OID_GEN_MULTICAST_FRAMES_XMIT, 106 - OID_GEN_BROADCAST_BYTES_XMIT, 107 - OID_GEN_BROADCAST_FRAMES_XMIT, 108 - OID_GEN_DIRECTED_BYTES_RCV, 109 - OID_GEN_DIRECTED_FRAMES_RCV, 110 - OID_GEN_MULTICAST_BYTES_RCV, 111 - OID_GEN_MULTICAST_FRAMES_RCV, 112 - OID_GEN_BROADCAST_BYTES_RCV, 113 - OID_GEN_BROADCAST_FRAMES_RCV, 114 - OID_GEN_RCV_CRC_ERROR, 115 - OID_GEN_TRANSMIT_QUEUE_LENGTH, 116 - #endif /* RNDIS_OPTIONAL_STATS */ 117 - 118 - /* mandatory 802.3 */ 119 - /* the general stuff */ 120 - OID_802_3_PERMANENT_ADDRESS, 121 - OID_802_3_CURRENT_ADDRESS, 122 - OID_802_3_MULTICAST_LIST, 123 - OID_802_3_MAC_OPTIONS, 124 - OID_802_3_MAXIMUM_LIST_SIZE, 125 - 126 - /* the statistical stuff */ 127 - OID_802_3_RCV_ERROR_ALIGNMENT, 128 - OID_802_3_XMIT_ONE_COLLISION, 129 - OID_802_3_XMIT_MORE_COLLISIONS, 130 - #ifdef RNDIS_OPTIONAL_STATS 131 - OID_802_3_XMIT_DEFERRED, 132 - OID_802_3_XMIT_MAX_COLLISIONS, 133 - OID_802_3_RCV_OVERRUN, 134 - OID_802_3_XMIT_UNDERRUN, 135 - OID_802_3_XMIT_HEARTBEAT_FAILURE, 136 - OID_802_3_XMIT_TIMES_CRS_LOST, 137 - OID_802_3_XMIT_LATE_COLLISIONS, 138 - #endif /* RNDIS_OPTIONAL_STATS */ 139 - 140 - #ifdef RNDIS_PM 141 - /* PM and wakeup are mandatory for USB: */ 142 - 143 - /* power management */ 144 - OID_PNP_CAPABILITIES, 145 - OID_PNP_QUERY_POWER, 146 - OID_PNP_SET_POWER, 147 - 148 - /* wake up host */ 149 - OID_PNP_ENABLE_WAKE_UP, 150 - OID_PNP_ADD_WAKE_UP_PATTERN, 151 - OID_PNP_REMOVE_WAKE_UP_PATTERN, 152 - #endif 153 - }; 154 - 155 - 156 72 typedef struct rndis_init_msg_type 157 73 { 158 74 __le32 MessageType; ··· 225 309 typedef struct rndis_params 226 310 { 227 311 u8 confignr; 228 - int used; 312 + u8 used; 313 + u16 saved_filter; 229 314 enum rndis_state state; 230 - u32 filter; 231 315 u32 medium; 232 316 u32 speed; 233 317 u32 media_state; 318 + 234 319 const u8 *host_mac; 320 + u16 *filter; 235 321 struct net_device *dev; 236 322 struct net_device_stats *stats; 323 + 237 324 u32 vendorID; 238 325 const char *vendorDescr; 239 326 int (*ack) (struct net_device *); ··· 248 329 int rndis_register (int (*rndis_control_ack) (struct net_device *)); 249 330 void rndis_deregister (int configNr); 250 331 int rndis_set_param_dev (u8 configNr, struct net_device *dev, 251 - struct net_device_stats *stats); 332 + struct net_device_stats *stats, 333 + u16 *cdc_filter); 252 334 int rndis_set_param_vendor (u8 configNr, u32 vendorID, 253 335 const char *vendorDescr); 254 336 int rndis_set_param_medium (u8 configNr, u32 medium, u32 speed); ··· 258 338 u8 *rndis_get_next_response (int configNr, u32 *length); 259 339 void rndis_free_response (int configNr, u8 *buf); 260 340 341 + void rndis_uninit (int configNr); 261 342 int rndis_signal_connect (int configNr); 262 343 int rndis_signal_disconnect (int configNr); 263 344 int rndis_state (int configNr);