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