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