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