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