| David Brownell | 7e27f18 | 2006-06-13 09:54:40 -0700 | [diff] [blame] | 1 | /* | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2 |  * RNDIS MSG parser | 
| David Brownell | 7e27f18 | 2006-06-13 09:54:40 -0700 | [diff] [blame] | 3 |  * | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4 |  * Authors:	Benedikt Spranger, Pengutronix | 
| David Brownell | 7e27f18 | 2006-06-13 09:54:40 -0700 | [diff] [blame] | 5 |  *		Robert Schwebel, Pengutronix | 
 | 6 |  * | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7 |  *              This program is free software; you can redistribute it and/or | 
 | 8 |  *              modify it under the terms of the GNU General Public License | 
| David Brownell | 7e27f18 | 2006-06-13 09:54:40 -0700 | [diff] [blame] | 9 |  *              version 2, as published by the Free Software Foundation. | 
 | 10 |  * | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11 |  *		This software was originally developed in conformance with | 
 | 12 |  *		Microsoft's Remote NDIS Specification License Agreement. | 
| David Brownell | 7e27f18 | 2006-06-13 09:54:40 -0700 | [diff] [blame] | 13 |  * | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14 |  * 03/12/2004 Kai-Uwe Bloem <linux-development@auerswald.de> | 
 | 15 |  *		Fixed message length bug in init_response | 
| David Brownell | 7e27f18 | 2006-06-13 09:54:40 -0700 | [diff] [blame] | 16 |  * | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 17 |  * 03/25/2004 Kai-Uwe Bloem <linux-development@auerswald.de> | 
| David Brownell | 7e27f18 | 2006-06-13 09:54:40 -0700 | [diff] [blame] | 18 |  *		Fixed rndis_rm_hdr length bug. | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 19 |  * | 
 | 20 |  * Copyright (C) 2004 by David Brownell | 
 | 21 |  *		updates to merge with Linux 2.6, better match RNDIS spec | 
 | 22 |  */ | 
 | 23 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 24 | #include <linux/module.h> | 
 | 25 | #include <linux/moduleparam.h> | 
 | 26 | #include <linux/kernel.h> | 
 | 27 | #include <linux/errno.h> | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 28 | #include <linux/init.h> | 
 | 29 | #include <linux/list.h> | 
 | 30 | #include <linux/proc_fs.h> | 
| Alexey Dobriyan | e184d5f | 2008-05-14 16:25:13 -0700 | [diff] [blame] | 31 | #include <linux/seq_file.h> | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 32 | #include <linux/netdevice.h> | 
 | 33 |  | 
 | 34 | #include <asm/io.h> | 
 | 35 | #include <asm/byteorder.h> | 
 | 36 | #include <asm/system.h> | 
| David Brownell | 6cdee10 | 2005-04-18 17:39:34 -0700 | [diff] [blame] | 37 | #include <asm/unaligned.h> | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 38 |  | 
 | 39 |  | 
| 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 |  | 
 | 63 | static rndis_params rndis_per_dev_params [RNDIS_MAX_CONFIGS]; | 
 | 64 |  | 
 | 65 | /* Driver Version */ | 
| Harvey Harrison | 35c26c2 | 2009-02-14 22:56:56 -0800 | [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 */ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 69 | static rndis_resp_t *rndis_add_response (int configNr, u32 length); | 
 | 70 |  | 
 | 71 |  | 
| David Brownell | 340600a | 2005-04-28 13:45:25 -0700 | [diff] [blame] | 72 | /* supported OIDs */ | 
| David Brownell | 7e27f18 | 2006-06-13 09:54:40 -0700 | [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 */ | 
| David Brownell | 340600a | 2005-04-28 13:45:25 -0700 | [diff] [blame] | 163 | static int | 
 | 164 | gen_ndis_query_resp (int configNr, u32 OID, u8 *buf, unsigned buf_len, | 
 | 165 | 		rndis_resp_t *r) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 166 | { | 
| David Brownell | 7e27f18 | 2006-06-13 09:54:40 -0700 | [diff] [blame] | 167 | 	int			retval = -ENOTSUPP; | 
 | 168 | 	u32			length = 4;	/* usually */ | 
| David Brownell | 340600a | 2005-04-28 13:45:25 -0700 | [diff] [blame] | 169 | 	__le32			*outbuf; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 170 | 	int			i, count; | 
 | 171 | 	rndis_query_cmplt_type	*resp; | 
| David Brownell | 15b2d2b | 2008-06-19 18:19:16 -0700 | [diff] [blame] | 172 | 	struct net_device	*net; | 
| Stephen Hemminger | b555649 | 2009-03-20 19:35:59 +0000 | [diff] [blame] | 173 | 	const struct net_device_stats	*stats; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 174 |  | 
 | 175 | 	if (!r) return -ENOMEM; | 
 | 176 | 	resp = (rndis_query_cmplt_type *) r->buf; | 
 | 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 */ | 
 | 192 | 	outbuf = (__le32 *) &resp[1]; | 
| Harvey Harrison | 35c26c2 | 2009-02-14 22:56:56 -0800 | [diff] [blame] | 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; | 
| Stephen Hemminger | b555649 | 2009-03-20 19:35:59 +0000 | [diff] [blame] | 196 | 	stats = dev_get_stats(net); | 
| 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__); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [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++) | 
| David Brownell | 340600a | 2005-04-28 13:45:25 -0700 | [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 | 		 */ | 
| Harvey Harrison | 35c26c2 | 2009-02-14 22:56:56 -0800 | [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__); | 
| David Brownell | 340600a | 2005-04-28 13:45:25 -0700 | [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) */ | 
| David Brownell | 340600a | 2005-04-28 13:45:25 -0700 | [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__); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 243 | 		if (rndis_per_dev_params [configNr].dev) { | 
| David Brownell | 340600a | 2005-04-28 13:45:25 -0700 | [diff] [blame] | 244 | 			*outbuf = cpu_to_le32 ( | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 245 | 				rndis_per_dev_params [configNr].dev->mtu); | 
 | 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__); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [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) | 
| Harvey Harrison | 35c26c2 | 2009-02-14 22:56:56 -0800 | [diff] [blame] | 256 | 			*outbuf = cpu_to_le32 (0); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 257 | 		else | 
| David Brownell | 340600a | 2005-04-28 13:45:25 -0700 | [diff] [blame] | 258 | 			*outbuf = cpu_to_le32 ( | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 259 | 				rndis_per_dev_params [configNr].speed); | 
 | 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__); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 266 | 		if (rndis_per_dev_params [configNr].dev) { | 
| David Brownell | 340600a | 2005-04-28 13:45:25 -0700 | [diff] [blame] | 267 | 			*outbuf = cpu_to_le32 ( | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 268 | 				rndis_per_dev_params [configNr].dev->mtu); | 
 | 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__); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 276 | 		if (rndis_per_dev_params [configNr].dev) { | 
| David Brownell | 340600a | 2005-04-28 13:45:25 -0700 | [diff] [blame] | 277 | 			*outbuf = cpu_to_le32 ( | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 278 | 				rndis_per_dev_params [configNr].dev->mtu); | 
 | 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__); | 
| David Brownell | 340600a | 2005-04-28 13:45:25 -0700 | [diff] [blame] | 286 | 		*outbuf = cpu_to_le32 ( | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 287 | 			rndis_per_dev_params [configNr].vendorID); | 
 | 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__); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 294 | 		length = strlen (rndis_per_dev_params [configNr].vendorDescr); | 
| David Brownell | 340600a | 2005-04-28 13:45:25 -0700 | [diff] [blame] | 295 | 		memcpy (outbuf, | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 296 | 			rndis_per_dev_params [configNr].vendorDescr, length); | 
 | 297 | 		retval = 0; | 
 | 298 | 		break; | 
 | 299 |  | 
 | 300 | 	case OID_GEN_VENDOR_DRIVER_VERSION: | 
| David Brownell | 33376c1 | 2008-08-18 17:45:07 -0700 | [diff] [blame] | 301 | 		pr_debug("%s: OID_GEN_VENDOR_DRIVER_VERSION\n", __func__); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 302 | 		/* Created as LE */ | 
| David Brownell | 340600a | 2005-04-28 13:45:25 -0700 | [diff] [blame] | 303 | 		*outbuf = rndis_driver_version; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 304 | 		retval = 0; | 
 | 305 | 		break; | 
 | 306 |  | 
 | 307 | 	/* mandatory */ | 
 | 308 | 	case OID_GEN_CURRENT_PACKET_FILTER: | 
| David Brownell | 33376c1 | 2008-08-18 17:45:07 -0700 | [diff] [blame] | 309 | 		pr_debug("%s: OID_GEN_CURRENT_PACKET_FILTER\n", __func__); | 
| David Brownell | 340600a | 2005-04-28 13:45:25 -0700 | [diff] [blame] | 310 | 		*outbuf = cpu_to_le32 (*rndis_per_dev_params[configNr].filter); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 311 | 		retval = 0; | 
 | 312 | 		break; | 
 | 313 |  | 
 | 314 | 	/* mandatory */ | 
 | 315 | 	case OID_GEN_MAXIMUM_TOTAL_SIZE: | 
| David Brownell | 33376c1 | 2008-08-18 17:45:07 -0700 | [diff] [blame] | 316 | 		pr_debug("%s: OID_GEN_MAXIMUM_TOTAL_SIZE\n", __func__); | 
| Harvey Harrison | 35c26c2 | 2009-02-14 22:56:56 -0800 | [diff] [blame] | 317 | 		*outbuf = cpu_to_le32(RNDIS_MAX_TOTAL_SIZE); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 318 | 		retval = 0; | 
 | 319 | 		break; | 
 | 320 |  | 
 | 321 | 	/* mandatory */ | 
 | 322 | 	case OID_GEN_MEDIA_CONNECT_STATUS: | 
| David Brownell | 340600a | 2005-04-28 13:45:25 -0700 | [diff] [blame] | 323 | 		if (rndis_debug > 1) | 
| David Brownell | 33376c1 | 2008-08-18 17:45:07 -0700 | [diff] [blame] | 324 | 			pr_debug("%s: OID_GEN_MEDIA_CONNECT_STATUS\n", __func__); | 
| David Brownell | 340600a | 2005-04-28 13:45:25 -0700 | [diff] [blame] | 325 | 		*outbuf = cpu_to_le32 (rndis_per_dev_params [configNr] | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 326 | 						.media_state); | 
 | 327 | 		retval = 0; | 
 | 328 | 		break; | 
 | 329 |  | 
 | 330 | 	case OID_GEN_PHYSICAL_MEDIUM: | 
| David Brownell | 33376c1 | 2008-08-18 17:45:07 -0700 | [diff] [blame] | 331 | 		pr_debug("%s: OID_GEN_PHYSICAL_MEDIUM\n", __func__); | 
| Harvey Harrison | 35c26c2 | 2009-02-14 22:56:56 -0800 | [diff] [blame] | 332 | 		*outbuf = cpu_to_le32 (0); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 333 | 		retval = 0; | 
 | 334 | 		break; | 
 | 335 |  | 
 | 336 | 	/* The RNDIS specification is incomplete/wrong.   Some versions | 
 | 337 | 	 * of MS-Windows expect OIDs that aren't specified there.  Other | 
 | 338 | 	 * versions emit undefined RNDIS messages. DOCUMENT ALL THESE! | 
 | 339 | 	 */ | 
 | 340 | 	case OID_GEN_MAC_OPTIONS:		/* from WinME */ | 
| David Brownell | 33376c1 | 2008-08-18 17:45:07 -0700 | [diff] [blame] | 341 | 		pr_debug("%s: OID_GEN_MAC_OPTIONS\n", __func__); | 
| Harvey Harrison | 35c26c2 | 2009-02-14 22:56:56 -0800 | [diff] [blame] | 342 | 		*outbuf = cpu_to_le32( | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 343 | 			  NDIS_MAC_OPTION_RECEIVE_SERIALIZED | 
 | 344 | 			| NDIS_MAC_OPTION_FULL_DUPLEX); | 
 | 345 | 		retval = 0; | 
 | 346 | 		break; | 
 | 347 |  | 
 | 348 | 	/* statistics OIDs (table 4-2) */ | 
 | 349 |  | 
 | 350 | 	/* mandatory */ | 
 | 351 | 	case OID_GEN_XMIT_OK: | 
| David Brownell | 340600a | 2005-04-28 13:45:25 -0700 | [diff] [blame] | 352 | 		if (rndis_debug > 1) | 
| David Brownell | 33376c1 | 2008-08-18 17:45:07 -0700 | [diff] [blame] | 353 | 			pr_debug("%s: OID_GEN_XMIT_OK\n", __func__); | 
| David Brownell | 15b2d2b | 2008-06-19 18:19:16 -0700 | [diff] [blame] | 354 | 		if (stats) { | 
 | 355 | 			*outbuf = cpu_to_le32(stats->tx_packets | 
 | 356 | 				- stats->tx_errors - stats->tx_dropped); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 357 | 			retval = 0; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 358 | 		} | 
 | 359 | 		break; | 
 | 360 |  | 
 | 361 | 	/* mandatory */ | 
 | 362 | 	case OID_GEN_RCV_OK: | 
| David Brownell | 340600a | 2005-04-28 13:45:25 -0700 | [diff] [blame] | 363 | 		if (rndis_debug > 1) | 
| David Brownell | 33376c1 | 2008-08-18 17:45:07 -0700 | [diff] [blame] | 364 | 			pr_debug("%s: OID_GEN_RCV_OK\n", __func__); | 
| David Brownell | 15b2d2b | 2008-06-19 18:19:16 -0700 | [diff] [blame] | 365 | 		if (stats) { | 
 | 366 | 			*outbuf = cpu_to_le32(stats->rx_packets | 
 | 367 | 				- stats->rx_errors - stats->rx_dropped); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 368 | 			retval = 0; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 369 | 		} | 
 | 370 | 		break; | 
| David Brownell | 7e27f18 | 2006-06-13 09:54:40 -0700 | [diff] [blame] | 371 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 372 | 	/* mandatory */ | 
 | 373 | 	case OID_GEN_XMIT_ERROR: | 
| David Brownell | 340600a | 2005-04-28 13:45:25 -0700 | [diff] [blame] | 374 | 		if (rndis_debug > 1) | 
| David Brownell | 33376c1 | 2008-08-18 17:45:07 -0700 | [diff] [blame] | 375 | 			pr_debug("%s: OID_GEN_XMIT_ERROR\n", __func__); | 
| David Brownell | 15b2d2b | 2008-06-19 18:19:16 -0700 | [diff] [blame] | 376 | 		if (stats) { | 
 | 377 | 			*outbuf = cpu_to_le32(stats->tx_errors); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 378 | 			retval = 0; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 379 | 		} | 
 | 380 | 		break; | 
| David Brownell | 7e27f18 | 2006-06-13 09:54:40 -0700 | [diff] [blame] | 381 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 382 | 	/* mandatory */ | 
 | 383 | 	case OID_GEN_RCV_ERROR: | 
| David Brownell | 340600a | 2005-04-28 13:45:25 -0700 | [diff] [blame] | 384 | 		if (rndis_debug > 1) | 
| David Brownell | 33376c1 | 2008-08-18 17:45:07 -0700 | [diff] [blame] | 385 | 			pr_debug("%s: OID_GEN_RCV_ERROR\n", __func__); | 
| David Brownell | 15b2d2b | 2008-06-19 18:19:16 -0700 | [diff] [blame] | 386 | 		if (stats) { | 
 | 387 | 			*outbuf = cpu_to_le32(stats->rx_errors); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 388 | 			retval = 0; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 389 | 		} | 
 | 390 | 		break; | 
| David Brownell | 7e27f18 | 2006-06-13 09:54:40 -0700 | [diff] [blame] | 391 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 392 | 	/* mandatory */ | 
 | 393 | 	case OID_GEN_RCV_NO_BUFFER: | 
| David Brownell | 33376c1 | 2008-08-18 17:45:07 -0700 | [diff] [blame] | 394 | 		pr_debug("%s: OID_GEN_RCV_NO_BUFFER\n", __func__); | 
| David Brownell | 15b2d2b | 2008-06-19 18:19:16 -0700 | [diff] [blame] | 395 | 		if (stats) { | 
 | 396 | 			*outbuf = cpu_to_le32(stats->rx_dropped); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 397 | 			retval = 0; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 398 | 		} | 
 | 399 | 		break; | 
 | 400 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 401 | 	/* ieee802.3 OIDs (table 4-3) */ | 
 | 402 |  | 
 | 403 | 	/* mandatory */ | 
 | 404 | 	case OID_802_3_PERMANENT_ADDRESS: | 
| David Brownell | 33376c1 | 2008-08-18 17:45:07 -0700 | [diff] [blame] | 405 | 		pr_debug("%s: OID_802_3_PERMANENT_ADDRESS\n", __func__); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 406 | 		if (rndis_per_dev_params [configNr].dev) { | 
 | 407 | 			length = ETH_ALEN; | 
| David Brownell | 340600a | 2005-04-28 13:45:25 -0700 | [diff] [blame] | 408 | 			memcpy (outbuf, | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 409 | 				rndis_per_dev_params [configNr].host_mac, | 
 | 410 | 				length); | 
 | 411 | 			retval = 0; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 412 | 		} | 
 | 413 | 		break; | 
| David Brownell | 7e27f18 | 2006-06-13 09:54:40 -0700 | [diff] [blame] | 414 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 415 | 	/* mandatory */ | 
 | 416 | 	case OID_802_3_CURRENT_ADDRESS: | 
| David Brownell | 33376c1 | 2008-08-18 17:45:07 -0700 | [diff] [blame] | 417 | 		pr_debug("%s: OID_802_3_CURRENT_ADDRESS\n", __func__); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 418 | 		if (rndis_per_dev_params [configNr].dev) { | 
 | 419 | 			length = ETH_ALEN; | 
| David Brownell | 340600a | 2005-04-28 13:45:25 -0700 | [diff] [blame] | 420 | 			memcpy (outbuf, | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 421 | 				rndis_per_dev_params [configNr].host_mac, | 
 | 422 | 				length); | 
 | 423 | 			retval = 0; | 
 | 424 | 		} | 
 | 425 | 		break; | 
| David Brownell | 7e27f18 | 2006-06-13 09:54:40 -0700 | [diff] [blame] | 426 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 427 | 	/* mandatory */ | 
 | 428 | 	case OID_802_3_MULTICAST_LIST: | 
| David Brownell | 33376c1 | 2008-08-18 17:45:07 -0700 | [diff] [blame] | 429 | 		pr_debug("%s: OID_802_3_MULTICAST_LIST\n", __func__); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 430 | 		/* Multicast base address only */ | 
| Harvey Harrison | 35c26c2 | 2009-02-14 22:56:56 -0800 | [diff] [blame] | 431 | 		*outbuf = cpu_to_le32 (0xE0000000); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 432 | 		retval = 0; | 
 | 433 | 		break; | 
| David Brownell | 7e27f18 | 2006-06-13 09:54:40 -0700 | [diff] [blame] | 434 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 435 | 	/* mandatory */ | 
 | 436 | 	case OID_802_3_MAXIMUM_LIST_SIZE: | 
| David Brownell | 33376c1 | 2008-08-18 17:45:07 -0700 | [diff] [blame] | 437 | 		pr_debug("%s: OID_802_3_MAXIMUM_LIST_SIZE\n", __func__); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 438 | 		/* Multicast base address only */ | 
| Harvey Harrison | 35c26c2 | 2009-02-14 22:56:56 -0800 | [diff] [blame] | 439 | 		*outbuf = cpu_to_le32 (1); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 440 | 		retval = 0; | 
 | 441 | 		break; | 
| David Brownell | 7e27f18 | 2006-06-13 09:54:40 -0700 | [diff] [blame] | 442 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 443 | 	case OID_802_3_MAC_OPTIONS: | 
| David Brownell | 33376c1 | 2008-08-18 17:45:07 -0700 | [diff] [blame] | 444 | 		pr_debug("%s: OID_802_3_MAC_OPTIONS\n", __func__); | 
| Qiuping Chen | 6bc2146 | 2009-07-01 03:49:29 -0700 | [diff] [blame] | 445 | 		*outbuf = cpu_to_le32(0); | 
 | 446 | 		retval = 0; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 447 | 		break; | 
 | 448 |  | 
 | 449 | 	/* ieee802.3 statistics OIDs (table 4-4) */ | 
 | 450 |  | 
 | 451 | 	/* mandatory */ | 
 | 452 | 	case OID_802_3_RCV_ERROR_ALIGNMENT: | 
| David Brownell | 33376c1 | 2008-08-18 17:45:07 -0700 | [diff] [blame] | 453 | 		pr_debug("%s: OID_802_3_RCV_ERROR_ALIGNMENT\n", __func__); | 
| David Brownell | 15b2d2b | 2008-06-19 18:19:16 -0700 | [diff] [blame] | 454 | 		if (stats) { | 
 | 455 | 			*outbuf = cpu_to_le32(stats->rx_frame_errors); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 456 | 			retval = 0; | 
 | 457 | 		} | 
 | 458 | 		break; | 
| David Brownell | 7e27f18 | 2006-06-13 09:54:40 -0700 | [diff] [blame] | 459 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 460 | 	/* mandatory */ | 
 | 461 | 	case OID_802_3_XMIT_ONE_COLLISION: | 
| David Brownell | 33376c1 | 2008-08-18 17:45:07 -0700 | [diff] [blame] | 462 | 		pr_debug("%s: OID_802_3_XMIT_ONE_COLLISION\n", __func__); | 
| Harvey Harrison | 35c26c2 | 2009-02-14 22:56:56 -0800 | [diff] [blame] | 463 | 		*outbuf = cpu_to_le32 (0); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 464 | 		retval = 0; | 
 | 465 | 		break; | 
| David Brownell | 7e27f18 | 2006-06-13 09:54:40 -0700 | [diff] [blame] | 466 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 467 | 	/* mandatory */ | 
 | 468 | 	case OID_802_3_XMIT_MORE_COLLISIONS: | 
| David Brownell | 33376c1 | 2008-08-18 17:45:07 -0700 | [diff] [blame] | 469 | 		pr_debug("%s: OID_802_3_XMIT_MORE_COLLISIONS\n", __func__); | 
| Harvey Harrison | 35c26c2 | 2009-02-14 22:56:56 -0800 | [diff] [blame] | 470 | 		*outbuf = cpu_to_le32 (0); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 471 | 		retval = 0; | 
 | 472 | 		break; | 
| David Brownell | 7e27f18 | 2006-06-13 09:54:40 -0700 | [diff] [blame] | 473 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 474 | 	default: | 
| David Brownell | 0027492 | 2007-11-19 12:58:36 -0800 | [diff] [blame] | 475 | 		pr_warning("%s: query unknown OID 0x%08X\n", | 
| Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 476 | 			 __func__, OID); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 477 | 	} | 
| David Brownell | 340600a | 2005-04-28 13:45:25 -0700 | [diff] [blame] | 478 | 	if (retval < 0) | 
 | 479 | 		length = 0; | 
| David Brownell | 7e27f18 | 2006-06-13 09:54:40 -0700 | [diff] [blame] | 480 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 481 | 	resp->InformationBufferLength = cpu_to_le32 (length); | 
| David Brownell | 340600a | 2005-04-28 13:45:25 -0700 | [diff] [blame] | 482 | 	r->length = length + sizeof *resp; | 
 | 483 | 	resp->MessageLength = cpu_to_le32 (r->length); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 484 | 	return retval; | 
 | 485 | } | 
 | 486 |  | 
| David Brownell | 7e27f18 | 2006-06-13 09:54:40 -0700 | [diff] [blame] | 487 | static int gen_ndis_set_resp (u8 configNr, u32 OID, u8 *buf, u32 buf_len, | 
 | 488 | 			rndis_resp_t *r) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 489 | { | 
 | 490 | 	rndis_set_cmplt_type		*resp; | 
| David Brownell | 7e27f18 | 2006-06-13 09:54:40 -0700 | [diff] [blame] | 491 | 	int				i, retval = -ENOTSUPP; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 492 | 	struct rndis_params		*params; | 
 | 493 |  | 
 | 494 | 	if (!r) | 
 | 495 | 		return -ENOMEM; | 
 | 496 | 	resp = (rndis_set_cmplt_type *) r->buf; | 
 | 497 | 	if (!resp) | 
 | 498 | 		return -ENOMEM; | 
 | 499 |  | 
| David Brownell | 340600a | 2005-04-28 13:45:25 -0700 | [diff] [blame] | 500 | 	if (buf_len && rndis_debug > 1) { | 
| David Brownell | 33376c1 | 2008-08-18 17:45:07 -0700 | [diff] [blame] | 501 | 		pr_debug("set OID %08x value, len %d:\n", OID, buf_len); | 
| David Brownell | 340600a | 2005-04-28 13:45:25 -0700 | [diff] [blame] | 502 | 		for (i = 0; i < buf_len; i += 16) { | 
| David Brownell | 33376c1 | 2008-08-18 17:45:07 -0700 | [diff] [blame] | 503 | 			pr_debug("%03d: %08x %08x %08x %08x\n", i, | 
| Harvey Harrison | a5abdea | 2008-04-29 01:03:40 -0700 | [diff] [blame] | 504 | 				get_unaligned_le32(&buf[i]), | 
 | 505 | 				get_unaligned_le32(&buf[i + 4]), | 
 | 506 | 				get_unaligned_le32(&buf[i + 8]), | 
 | 507 | 				get_unaligned_le32(&buf[i + 12])); | 
| David Brownell | 340600a | 2005-04-28 13:45:25 -0700 | [diff] [blame] | 508 | 		} | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 509 | 	} | 
 | 510 |  | 
| David Brownell | 340600a | 2005-04-28 13:45:25 -0700 | [diff] [blame] | 511 | 	params = &rndis_per_dev_params [configNr]; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 512 | 	switch (OID) { | 
 | 513 | 	case OID_GEN_CURRENT_PACKET_FILTER: | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 514 |  | 
| David Brownell | 340600a | 2005-04-28 13:45:25 -0700 | [diff] [blame] | 515 | 		/* these NDIS_PACKET_TYPE_* bitflags are shared with | 
 | 516 | 		 * cdc_filter; it's not RNDIS-specific | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 517 | 		 * NDIS_PACKET_TYPE_x == USB_CDC_PACKET_TYPE_x for x in: | 
 | 518 | 		 *	PROMISCUOUS, DIRECTED, | 
 | 519 | 		 *	MULTICAST, ALL_MULTICAST, BROADCAST | 
 | 520 | 		 */ | 
| Harvey Harrison | a5abdea | 2008-04-29 01:03:40 -0700 | [diff] [blame] | 521 | 		*params->filter = (u16)get_unaligned_le32(buf); | 
| David Brownell | 33376c1 | 2008-08-18 17:45:07 -0700 | [diff] [blame] | 522 | 		pr_debug("%s: OID_GEN_CURRENT_PACKET_FILTER %08x\n", | 
| Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 523 | 			__func__, *params->filter); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 524 |  | 
 | 525 | 		/* this call has a significant side effect:  it's | 
 | 526 | 		 * what makes the packet flow start and stop, like | 
 | 527 | 		 * activating the CDC Ethernet altsetting. | 
 | 528 | 		 */ | 
| David Brownell | 340600a | 2005-04-28 13:45:25 -0700 | [diff] [blame] | 529 | 		retval = 0; | 
 | 530 | 		if (*params->filter) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 531 | 			params->state = RNDIS_DATA_INITIALIZED; | 
 | 532 | 			netif_carrier_on(params->dev); | 
 | 533 | 			if (netif_running(params->dev)) | 
 | 534 | 				netif_wake_queue (params->dev); | 
 | 535 | 		} else { | 
 | 536 | 			params->state = RNDIS_INITIALIZED; | 
 | 537 | 			netif_carrier_off (params->dev); | 
 | 538 | 			netif_stop_queue (params->dev); | 
 | 539 | 		} | 
 | 540 | 		break; | 
| David Brownell | 7e27f18 | 2006-06-13 09:54:40 -0700 | [diff] [blame] | 541 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 542 | 	case OID_802_3_MULTICAST_LIST: | 
| David Brownell | 7e27f18 | 2006-06-13 09:54:40 -0700 | [diff] [blame] | 543 | 		/* I think we can ignore this */ | 
| David Brownell | 33376c1 | 2008-08-18 17:45:07 -0700 | [diff] [blame] | 544 | 		pr_debug("%s: OID_802_3_MULTICAST_LIST\n", __func__); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 545 | 		retval = 0; | 
 | 546 | 		break; | 
| David Brownell | 340600a | 2005-04-28 13:45:25 -0700 | [diff] [blame] | 547 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 548 | 	default: | 
| David Brownell | 0027492 | 2007-11-19 12:58:36 -0800 | [diff] [blame] | 549 | 		pr_warning("%s: set unknown OID 0x%08X, size %d\n", | 
| Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 550 | 			 __func__, OID, buf_len); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 551 | 	} | 
| David Brownell | 7e27f18 | 2006-06-13 09:54:40 -0700 | [diff] [blame] | 552 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 553 | 	return retval; | 
 | 554 | } | 
 | 555 |  | 
| David Brownell | 7e27f18 | 2006-06-13 09:54:40 -0700 | [diff] [blame] | 556 | /* | 
 | 557 |  * Response Functions | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 558 |  */ | 
 | 559 |  | 
 | 560 | static int rndis_init_response (int configNr, rndis_init_msg_type *buf) | 
 | 561 | { | 
| David Brownell | 7e27f18 | 2006-06-13 09:54:40 -0700 | [diff] [blame] | 562 | 	rndis_init_cmplt_type	*resp; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 563 | 	rndis_resp_t            *r; | 
| David Brownell | 15b2d2b | 2008-06-19 18:19:16 -0700 | [diff] [blame] | 564 | 	struct rndis_params	*params = rndis_per_dev_params + configNr; | 
| David Brownell | 7e27f18 | 2006-06-13 09:54:40 -0700 | [diff] [blame] | 565 |  | 
| David Brownell | 15b2d2b | 2008-06-19 18:19:16 -0700 | [diff] [blame] | 566 | 	if (!params->dev) | 
 | 567 | 		return -ENOTSUPP; | 
| David Brownell | 7e27f18 | 2006-06-13 09:54:40 -0700 | [diff] [blame] | 568 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 569 | 	r = rndis_add_response (configNr, sizeof (rndis_init_cmplt_type)); | 
| David Brownell | 340600a | 2005-04-28 13:45:25 -0700 | [diff] [blame] | 570 | 	if (!r) | 
 | 571 | 		return -ENOMEM; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 572 | 	resp = (rndis_init_cmplt_type *) r->buf; | 
| David Brownell | 7e27f18 | 2006-06-13 09:54:40 -0700 | [diff] [blame] | 573 |  | 
| Harvey Harrison | 35c26c2 | 2009-02-14 22:56:56 -0800 | [diff] [blame] | 574 | 	resp->MessageType = cpu_to_le32 ( | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 575 | 			REMOTE_NDIS_INITIALIZE_CMPLT); | 
| Harvey Harrison | 35c26c2 | 2009-02-14 22:56:56 -0800 | [diff] [blame] | 576 | 	resp->MessageLength = cpu_to_le32 (52); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 577 | 	resp->RequestID = buf->RequestID; /* Still LE in msg buffer */ | 
| Harvey Harrison | 35c26c2 | 2009-02-14 22:56:56 -0800 | [diff] [blame] | 578 | 	resp->Status = cpu_to_le32 (RNDIS_STATUS_SUCCESS); | 
 | 579 | 	resp->MajorVersion = cpu_to_le32 (RNDIS_MAJOR_VERSION); | 
 | 580 | 	resp->MinorVersion = cpu_to_le32 (RNDIS_MINOR_VERSION); | 
 | 581 | 	resp->DeviceFlags = cpu_to_le32 (RNDIS_DF_CONNECTIONLESS); | 
 | 582 | 	resp->Medium = cpu_to_le32 (RNDIS_MEDIUM_802_3); | 
 | 583 | 	resp->MaxPacketsPerTransfer = cpu_to_le32 (1); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 584 | 	resp->MaxTransferSize = cpu_to_le32 ( | 
| David Brownell | 15b2d2b | 2008-06-19 18:19:16 -0700 | [diff] [blame] | 585 | 		  params->dev->mtu | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 586 | 		+ sizeof (struct ethhdr) | 
 | 587 | 		+ sizeof (struct rndis_packet_msg_type) | 
 | 588 | 		+ 22); | 
| Harvey Harrison | 35c26c2 | 2009-02-14 22:56:56 -0800 | [diff] [blame] | 589 | 	resp->PacketAlignmentFactor = cpu_to_le32 (0); | 
 | 590 | 	resp->AFListOffset = cpu_to_le32 (0); | 
 | 591 | 	resp->AFListSize = cpu_to_le32 (0); | 
| David Brownell | 7e27f18 | 2006-06-13 09:54:40 -0700 | [diff] [blame] | 592 |  | 
| David Brownell | 15b2d2b | 2008-06-19 18:19:16 -0700 | [diff] [blame] | 593 | 	params->resp_avail(params->v); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 594 | 	return 0; | 
 | 595 | } | 
 | 596 |  | 
 | 597 | static int rndis_query_response (int configNr, rndis_query_msg_type *buf) | 
 | 598 | { | 
 | 599 | 	rndis_query_cmplt_type *resp; | 
 | 600 | 	rndis_resp_t            *r; | 
| David Brownell | 15b2d2b | 2008-06-19 18:19:16 -0700 | [diff] [blame] | 601 | 	struct rndis_params	*params = rndis_per_dev_params + configNr; | 
| David Brownell | 7e27f18 | 2006-06-13 09:54:40 -0700 | [diff] [blame] | 602 |  | 
| David Brownell | 33376c1 | 2008-08-18 17:45:07 -0700 | [diff] [blame] | 603 | 	/* pr_debug("%s: OID = %08X\n", __func__, cpu_to_le32(buf->OID)); */ | 
| David Brownell | 15b2d2b | 2008-06-19 18:19:16 -0700 | [diff] [blame] | 604 | 	if (!params->dev) | 
 | 605 | 		return -ENOTSUPP; | 
| David Brownell | 7e27f18 | 2006-06-13 09:54:40 -0700 | [diff] [blame] | 606 |  | 
| Shaun Tancheff | 8763716 | 2006-02-22 19:47:19 -0800 | [diff] [blame] | 607 | 	/* | 
 | 608 | 	 * we need more memory: | 
 | 609 | 	 * gen_ndis_query_resp expects enough space for | 
 | 610 | 	 * rndis_query_cmplt_type followed by data. | 
 | 611 | 	 * oid_supported_list is the largest data reply | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 612 | 	 */ | 
| Shaun Tancheff | 8763716 | 2006-02-22 19:47:19 -0800 | [diff] [blame] | 613 | 	r = rndis_add_response (configNr, | 
 | 614 | 		sizeof (oid_supported_list) + sizeof(rndis_query_cmplt_type)); | 
| David Brownell | 340600a | 2005-04-28 13:45:25 -0700 | [diff] [blame] | 615 | 	if (!r) | 
 | 616 | 		return -ENOMEM; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 617 | 	resp = (rndis_query_cmplt_type *) r->buf; | 
| David Brownell | 7e27f18 | 2006-06-13 09:54:40 -0700 | [diff] [blame] | 618 |  | 
| Harvey Harrison | 35c26c2 | 2009-02-14 22:56:56 -0800 | [diff] [blame] | 619 | 	resp->MessageType = cpu_to_le32 (REMOTE_NDIS_QUERY_CMPLT); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 620 | 	resp->RequestID = buf->RequestID; /* Still LE in msg buffer */ | 
| David Brownell | 7e27f18 | 2006-06-13 09:54:40 -0700 | [diff] [blame] | 621 |  | 
| David Brownell | 340600a | 2005-04-28 13:45:25 -0700 | [diff] [blame] | 622 | 	if (gen_ndis_query_resp (configNr, le32_to_cpu (buf->OID), | 
 | 623 | 			le32_to_cpu(buf->InformationBufferOffset) | 
 | 624 | 					+ 8 + (u8 *) buf, | 
 | 625 | 			le32_to_cpu(buf->InformationBufferLength), | 
 | 626 | 			r)) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 627 | 		/* OID not supported */ | 
| Harvey Harrison | 35c26c2 | 2009-02-14 22:56:56 -0800 | [diff] [blame] | 628 | 		resp->Status = cpu_to_le32 ( | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 629 | 				RNDIS_STATUS_NOT_SUPPORTED); | 
| Harvey Harrison | 35c26c2 | 2009-02-14 22:56:56 -0800 | [diff] [blame] | 630 | 		resp->MessageLength = cpu_to_le32 (sizeof *resp); | 
 | 631 | 		resp->InformationBufferLength = cpu_to_le32 (0); | 
 | 632 | 		resp->InformationBufferOffset = cpu_to_le32 (0); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 633 | 	} else | 
| Harvey Harrison | 35c26c2 | 2009-02-14 22:56:56 -0800 | [diff] [blame] | 634 | 		resp->Status = cpu_to_le32 (RNDIS_STATUS_SUCCESS); | 
| David Brownell | 7e27f18 | 2006-06-13 09:54:40 -0700 | [diff] [blame] | 635 |  | 
| David Brownell | 15b2d2b | 2008-06-19 18:19:16 -0700 | [diff] [blame] | 636 | 	params->resp_avail(params->v); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 637 | 	return 0; | 
 | 638 | } | 
 | 639 |  | 
 | 640 | static int rndis_set_response (int configNr, rndis_set_msg_type *buf) | 
 | 641 | { | 
 | 642 | 	u32			BufLength, BufOffset; | 
 | 643 | 	rndis_set_cmplt_type	*resp; | 
 | 644 | 	rndis_resp_t		*r; | 
| David Brownell | 15b2d2b | 2008-06-19 18:19:16 -0700 | [diff] [blame] | 645 | 	struct rndis_params	*params = rndis_per_dev_params + configNr; | 
| David Brownell | 7e27f18 | 2006-06-13 09:54:40 -0700 | [diff] [blame] | 646 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 647 | 	r = rndis_add_response (configNr, sizeof (rndis_set_cmplt_type)); | 
| David Brownell | 340600a | 2005-04-28 13:45:25 -0700 | [diff] [blame] | 648 | 	if (!r) | 
 | 649 | 		return -ENOMEM; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 650 | 	resp = (rndis_set_cmplt_type *) r->buf; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 651 |  | 
 | 652 | 	BufLength = le32_to_cpu (buf->InformationBufferLength); | 
 | 653 | 	BufOffset = le32_to_cpu (buf->InformationBufferOffset); | 
 | 654 |  | 
| David Brownell | 15b2d2b | 2008-06-19 18:19:16 -0700 | [diff] [blame] | 655 | #ifdef	VERBOSE_DEBUG | 
| David Brownell | 33376c1 | 2008-08-18 17:45:07 -0700 | [diff] [blame] | 656 | 	pr_debug("%s: Length: %d\n", __func__, BufLength); | 
 | 657 | 	pr_debug("%s: Offset: %d\n", __func__, BufOffset); | 
 | 658 | 	pr_debug("%s: InfoBuffer: ", __func__); | 
| David Brownell | 7e27f18 | 2006-06-13 09:54:40 -0700 | [diff] [blame] | 659 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 660 | 	for (i = 0; i < BufLength; i++) { | 
| David Brownell | 33376c1 | 2008-08-18 17:45:07 -0700 | [diff] [blame] | 661 | 		pr_debug("%02x ", *(((u8 *) buf) + i + 8 + BufOffset)); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 662 | 	} | 
| David Brownell | 7e27f18 | 2006-06-13 09:54:40 -0700 | [diff] [blame] | 663 |  | 
| David Brownell | 33376c1 | 2008-08-18 17:45:07 -0700 | [diff] [blame] | 664 | 	pr_debug("\n"); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 665 | #endif | 
| David Brownell | 7e27f18 | 2006-06-13 09:54:40 -0700 | [diff] [blame] | 666 |  | 
| Harvey Harrison | 35c26c2 | 2009-02-14 22:56:56 -0800 | [diff] [blame] | 667 | 	resp->MessageType = cpu_to_le32 (REMOTE_NDIS_SET_CMPLT); | 
 | 668 | 	resp->MessageLength = cpu_to_le32 (16); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 669 | 	resp->RequestID = buf->RequestID; /* Still LE in msg buffer */ | 
| David Brownell | 7e27f18 | 2006-06-13 09:54:40 -0700 | [diff] [blame] | 670 | 	if (gen_ndis_set_resp (configNr, le32_to_cpu (buf->OID), | 
 | 671 | 			((u8 *) buf) + 8 + BufOffset, BufLength, r)) | 
| Harvey Harrison | 35c26c2 | 2009-02-14 22:56:56 -0800 | [diff] [blame] | 672 | 		resp->Status = cpu_to_le32 (RNDIS_STATUS_NOT_SUPPORTED); | 
| David Brownell | 7e27f18 | 2006-06-13 09:54:40 -0700 | [diff] [blame] | 673 | 	else | 
| Harvey Harrison | 35c26c2 | 2009-02-14 22:56:56 -0800 | [diff] [blame] | 674 | 		resp->Status = cpu_to_le32 (RNDIS_STATUS_SUCCESS); | 
| David Brownell | 7e27f18 | 2006-06-13 09:54:40 -0700 | [diff] [blame] | 675 |  | 
| David Brownell | 15b2d2b | 2008-06-19 18:19:16 -0700 | [diff] [blame] | 676 | 	params->resp_avail(params->v); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 677 | 	return 0; | 
 | 678 | } | 
 | 679 |  | 
 | 680 | static int rndis_reset_response (int configNr, rndis_reset_msg_type *buf) | 
 | 681 | { | 
 | 682 | 	rndis_reset_cmplt_type	*resp; | 
 | 683 | 	rndis_resp_t		*r; | 
| David Brownell | 15b2d2b | 2008-06-19 18:19:16 -0700 | [diff] [blame] | 684 | 	struct rndis_params	*params = rndis_per_dev_params + configNr; | 
| David Brownell | 7e27f18 | 2006-06-13 09:54:40 -0700 | [diff] [blame] | 685 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 686 | 	r = rndis_add_response (configNr, sizeof (rndis_reset_cmplt_type)); | 
| David Brownell | 340600a | 2005-04-28 13:45:25 -0700 | [diff] [blame] | 687 | 	if (!r) | 
 | 688 | 		return -ENOMEM; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 689 | 	resp = (rndis_reset_cmplt_type *) r->buf; | 
| David Brownell | 7e27f18 | 2006-06-13 09:54:40 -0700 | [diff] [blame] | 690 |  | 
| Harvey Harrison | 35c26c2 | 2009-02-14 22:56:56 -0800 | [diff] [blame] | 691 | 	resp->MessageType = cpu_to_le32 (REMOTE_NDIS_RESET_CMPLT); | 
 | 692 | 	resp->MessageLength = cpu_to_le32 (16); | 
 | 693 | 	resp->Status = cpu_to_le32 (RNDIS_STATUS_SUCCESS); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 694 | 	/* resent information */ | 
| Harvey Harrison | 35c26c2 | 2009-02-14 22:56:56 -0800 | [diff] [blame] | 695 | 	resp->AddressingReset = cpu_to_le32 (1); | 
| David Brownell | 7e27f18 | 2006-06-13 09:54:40 -0700 | [diff] [blame] | 696 |  | 
| David Brownell | 15b2d2b | 2008-06-19 18:19:16 -0700 | [diff] [blame] | 697 | 	params->resp_avail(params->v); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 698 | 	return 0; | 
 | 699 | } | 
 | 700 |  | 
 | 701 | static int rndis_keepalive_response (int configNr, | 
| David Brownell | 7e27f18 | 2006-06-13 09:54:40 -0700 | [diff] [blame] | 702 | 				rndis_keepalive_msg_type *buf) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 703 | { | 
 | 704 | 	rndis_keepalive_cmplt_type	*resp; | 
 | 705 | 	rndis_resp_t			*r; | 
| David Brownell | 15b2d2b | 2008-06-19 18:19:16 -0700 | [diff] [blame] | 706 | 	struct rndis_params	*params = rndis_per_dev_params + configNr; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 707 |  | 
 | 708 | 	/* host "should" check only in RNDIS_DATA_INITIALIZED state */ | 
 | 709 |  | 
 | 710 | 	r = rndis_add_response (configNr, sizeof (rndis_keepalive_cmplt_type)); | 
| David Brownell | 340600a | 2005-04-28 13:45:25 -0700 | [diff] [blame] | 711 | 	if (!r) | 
 | 712 | 		return -ENOMEM; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 713 | 	resp = (rndis_keepalive_cmplt_type *) r->buf; | 
| David Brownell | 7e27f18 | 2006-06-13 09:54:40 -0700 | [diff] [blame] | 714 |  | 
| Harvey Harrison | 35c26c2 | 2009-02-14 22:56:56 -0800 | [diff] [blame] | 715 | 	resp->MessageType = cpu_to_le32 ( | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 716 | 			REMOTE_NDIS_KEEPALIVE_CMPLT); | 
| Harvey Harrison | 35c26c2 | 2009-02-14 22:56:56 -0800 | [diff] [blame] | 717 | 	resp->MessageLength = cpu_to_le32 (16); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 718 | 	resp->RequestID = buf->RequestID; /* Still LE in msg buffer */ | 
| Harvey Harrison | 35c26c2 | 2009-02-14 22:56:56 -0800 | [diff] [blame] | 719 | 	resp->Status = cpu_to_le32 (RNDIS_STATUS_SUCCESS); | 
| David Brownell | 7e27f18 | 2006-06-13 09:54:40 -0700 | [diff] [blame] | 720 |  | 
| David Brownell | 15b2d2b | 2008-06-19 18:19:16 -0700 | [diff] [blame] | 721 | 	params->resp_avail(params->v); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 722 | 	return 0; | 
 | 723 | } | 
 | 724 |  | 
 | 725 |  | 
| David Brownell | 7e27f18 | 2006-06-13 09:54:40 -0700 | [diff] [blame] | 726 | /* | 
 | 727 |  * Device to Host Comunication | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 728 |  */ | 
 | 729 | static int rndis_indicate_status_msg (int configNr, u32 status) | 
 | 730 | { | 
| David Brownell | 7e27f18 | 2006-06-13 09:54:40 -0700 | [diff] [blame] | 731 | 	rndis_indicate_status_msg_type	*resp; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 732 | 	rndis_resp_t			*r; | 
| David Brownell | 15b2d2b | 2008-06-19 18:19:16 -0700 | [diff] [blame] | 733 | 	struct rndis_params	*params = rndis_per_dev_params + configNr; | 
| David Brownell | 7e27f18 | 2006-06-13 09:54:40 -0700 | [diff] [blame] | 734 |  | 
| David Brownell | 15b2d2b | 2008-06-19 18:19:16 -0700 | [diff] [blame] | 735 | 	if (params->state == RNDIS_UNINITIALIZED) | 
| David Brownell | 7e27f18 | 2006-06-13 09:54:40 -0700 | [diff] [blame] | 736 | 		return -ENOTSUPP; | 
 | 737 |  | 
 | 738 | 	r = rndis_add_response (configNr, | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 739 | 				sizeof (rndis_indicate_status_msg_type)); | 
| David Brownell | 340600a | 2005-04-28 13:45:25 -0700 | [diff] [blame] | 740 | 	if (!r) | 
 | 741 | 		return -ENOMEM; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 742 | 	resp = (rndis_indicate_status_msg_type *) r->buf; | 
| David Brownell | 7e27f18 | 2006-06-13 09:54:40 -0700 | [diff] [blame] | 743 |  | 
| Harvey Harrison | 35c26c2 | 2009-02-14 22:56:56 -0800 | [diff] [blame] | 744 | 	resp->MessageType = cpu_to_le32 ( | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 745 | 			REMOTE_NDIS_INDICATE_STATUS_MSG); | 
| Harvey Harrison | 35c26c2 | 2009-02-14 22:56:56 -0800 | [diff] [blame] | 746 | 	resp->MessageLength = cpu_to_le32 (20); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 747 | 	resp->Status = cpu_to_le32 (status); | 
| Harvey Harrison | 35c26c2 | 2009-02-14 22:56:56 -0800 | [diff] [blame] | 748 | 	resp->StatusBufferLength = cpu_to_le32 (0); | 
 | 749 | 	resp->StatusBufferOffset = cpu_to_le32 (0); | 
| David Brownell | 7e27f18 | 2006-06-13 09:54:40 -0700 | [diff] [blame] | 750 |  | 
| David Brownell | 15b2d2b | 2008-06-19 18:19:16 -0700 | [diff] [blame] | 751 | 	params->resp_avail(params->v); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 752 | 	return 0; | 
 | 753 | } | 
 | 754 |  | 
 | 755 | int rndis_signal_connect (int configNr) | 
 | 756 | { | 
 | 757 | 	rndis_per_dev_params [configNr].media_state | 
 | 758 | 			= NDIS_MEDIA_STATE_CONNECTED; | 
| David Brownell | 7e27f18 | 2006-06-13 09:54:40 -0700 | [diff] [blame] | 759 | 	return rndis_indicate_status_msg (configNr, | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 760 | 					  RNDIS_STATUS_MEDIA_CONNECT); | 
 | 761 | } | 
 | 762 |  | 
 | 763 | int rndis_signal_disconnect (int configNr) | 
 | 764 | { | 
 | 765 | 	rndis_per_dev_params [configNr].media_state | 
 | 766 | 			= NDIS_MEDIA_STATE_DISCONNECTED; | 
 | 767 | 	return rndis_indicate_status_msg (configNr, | 
 | 768 | 					  RNDIS_STATUS_MEDIA_DISCONNECT); | 
 | 769 | } | 
 | 770 |  | 
| David Brownell | 340600a | 2005-04-28 13:45:25 -0700 | [diff] [blame] | 771 | void rndis_uninit (int configNr) | 
 | 772 | { | 
| David Brownell | 486e2df | 2005-05-24 17:51:52 -0700 | [diff] [blame] | 773 | 	u8 *buf; | 
 | 774 | 	u32 length; | 
 | 775 |  | 
| David Brownell | 340600a | 2005-04-28 13:45:25 -0700 | [diff] [blame] | 776 | 	if (configNr >= RNDIS_MAX_CONFIGS) | 
 | 777 | 		return; | 
| David Brownell | 340600a | 2005-04-28 13:45:25 -0700 | [diff] [blame] | 778 | 	rndis_per_dev_params [configNr].state = RNDIS_UNINITIALIZED; | 
| David Brownell | 486e2df | 2005-05-24 17:51:52 -0700 | [diff] [blame] | 779 |  | 
 | 780 | 	/* drain the response queue */ | 
 | 781 | 	while ((buf = rndis_get_next_response(configNr, &length))) | 
 | 782 | 		rndis_free_response(configNr, buf); | 
| David Brownell | 340600a | 2005-04-28 13:45:25 -0700 | [diff] [blame] | 783 | } | 
 | 784 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 785 | void rndis_set_host_mac (int configNr, const u8 *addr) | 
 | 786 | { | 
 | 787 | 	rndis_per_dev_params [configNr].host_mac = addr; | 
 | 788 | } | 
 | 789 |  | 
| David Brownell | 7e27f18 | 2006-06-13 09:54:40 -0700 | [diff] [blame] | 790 | /* | 
 | 791 |  * Message Parser | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 792 |  */ | 
 | 793 | int rndis_msg_parser (u8 configNr, u8 *buf) | 
 | 794 | { | 
 | 795 | 	u32 MsgType, MsgLength; | 
 | 796 | 	__le32 *tmp; | 
 | 797 | 	struct rndis_params		*params; | 
| David Brownell | 7e27f18 | 2006-06-13 09:54:40 -0700 | [diff] [blame] | 798 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 799 | 	if (!buf) | 
 | 800 | 		return -ENOMEM; | 
| David Brownell | 7e27f18 | 2006-06-13 09:54:40 -0700 | [diff] [blame] | 801 |  | 
 | 802 | 	tmp = (__le32 *) buf; | 
| Harvey Harrison | a5abdea | 2008-04-29 01:03:40 -0700 | [diff] [blame] | 803 | 	MsgType   = get_unaligned_le32(tmp++); | 
 | 804 | 	MsgLength = get_unaligned_le32(tmp++); | 
| David Brownell | 7e27f18 | 2006-06-13 09:54:40 -0700 | [diff] [blame] | 805 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 806 | 	if (configNr >= RNDIS_MAX_CONFIGS) | 
 | 807 | 		return -ENOTSUPP; | 
 | 808 | 	params = &rndis_per_dev_params [configNr]; | 
| David Brownell | 7e27f18 | 2006-06-13 09:54:40 -0700 | [diff] [blame] | 809 |  | 
| David Brownell | 340600a | 2005-04-28 13:45:25 -0700 | [diff] [blame] | 810 | 	/* NOTE: RNDIS is *EXTREMELY* chatty ... Windows constantly polls for | 
 | 811 | 	 * rx/tx statistics and link status, in addition to KEEPALIVE traffic | 
 | 812 | 	 * and normal HC level polling to see if there's any IN traffic. | 
 | 813 | 	 */ | 
 | 814 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 815 | 	/* For USB: responses may take up to 10 seconds */ | 
| David Brownell | 340600a | 2005-04-28 13:45:25 -0700 | [diff] [blame] | 816 | 	switch (MsgType) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 817 | 	case REMOTE_NDIS_INITIALIZE_MSG: | 
| David Brownell | 33376c1 | 2008-08-18 17:45:07 -0700 | [diff] [blame] | 818 | 		pr_debug("%s: REMOTE_NDIS_INITIALIZE_MSG\n", | 
| Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 819 | 			__func__ ); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 820 | 		params->state = RNDIS_INITIALIZED; | 
 | 821 | 		return  rndis_init_response (configNr, | 
| David Brownell | 7e27f18 | 2006-06-13 09:54:40 -0700 | [diff] [blame] | 822 | 					(rndis_init_msg_type *) buf); | 
 | 823 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 824 | 	case REMOTE_NDIS_HALT_MSG: | 
| David Brownell | 33376c1 | 2008-08-18 17:45:07 -0700 | [diff] [blame] | 825 | 		pr_debug("%s: REMOTE_NDIS_HALT_MSG\n", | 
| Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 826 | 			__func__ ); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 827 | 		params->state = RNDIS_UNINITIALIZED; | 
 | 828 | 		if (params->dev) { | 
 | 829 | 			netif_carrier_off (params->dev); | 
 | 830 | 			netif_stop_queue (params->dev); | 
 | 831 | 		} | 
 | 832 | 		return 0; | 
| 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_QUERY_MSG: | 
| David Brownell | 7e27f18 | 2006-06-13 09:54:40 -0700 | [diff] [blame] | 835 | 		return rndis_query_response (configNr, | 
 | 836 | 					(rndis_query_msg_type *) buf); | 
 | 837 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 838 | 	case REMOTE_NDIS_SET_MSG: | 
| David Brownell | 7e27f18 | 2006-06-13 09:54:40 -0700 | [diff] [blame] | 839 | 		return rndis_set_response (configNr, | 
 | 840 | 					(rndis_set_msg_type *) buf); | 
 | 841 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 842 | 	case REMOTE_NDIS_RESET_MSG: | 
| David Brownell | 33376c1 | 2008-08-18 17:45:07 -0700 | [diff] [blame] | 843 | 		pr_debug("%s: REMOTE_NDIS_RESET_MSG\n", | 
| Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 844 | 			__func__ ); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 845 | 		return rndis_reset_response (configNr, | 
| David Brownell | 7e27f18 | 2006-06-13 09:54:40 -0700 | [diff] [blame] | 846 | 					(rndis_reset_msg_type *) buf); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 847 |  | 
 | 848 | 	case REMOTE_NDIS_KEEPALIVE_MSG: | 
 | 849 | 		/* For USB: host does this every 5 seconds */ | 
| David Brownell | 340600a | 2005-04-28 13:45:25 -0700 | [diff] [blame] | 850 | 		if (rndis_debug > 1) | 
| David Brownell | 33376c1 | 2008-08-18 17:45:07 -0700 | [diff] [blame] | 851 | 			pr_debug("%s: REMOTE_NDIS_KEEPALIVE_MSG\n", | 
| Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 852 | 				__func__ ); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 853 | 		return rndis_keepalive_response (configNr, | 
| David Brownell | 7e27f18 | 2006-06-13 09:54:40 -0700 | [diff] [blame] | 854 | 						 (rndis_keepalive_msg_type *) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 855 | 						 buf); | 
| David Brownell | 7e27f18 | 2006-06-13 09:54:40 -0700 | [diff] [blame] | 856 |  | 
 | 857 | 	default: | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 858 | 		/* At least Windows XP emits some undefined RNDIS messages. | 
 | 859 | 		 * In one case those messages seemed to relate to the host | 
 | 860 | 		 * suspending itself. | 
 | 861 | 		 */ | 
| David Brownell | 0027492 | 2007-11-19 12:58:36 -0800 | [diff] [blame] | 862 | 		pr_warning("%s: unknown RNDIS message 0x%08X len %d\n", | 
| Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 863 | 			__func__ , MsgType, MsgLength); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 864 | 		{ | 
 | 865 | 			unsigned i; | 
 | 866 | 			for (i = 0; i < MsgLength; i += 16) { | 
| David Brownell | 33376c1 | 2008-08-18 17:45:07 -0700 | [diff] [blame] | 867 | 				pr_debug("%03d: " | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 868 | 					" %02x %02x %02x %02x" | 
 | 869 | 					" %02x %02x %02x %02x" | 
 | 870 | 					" %02x %02x %02x %02x" | 
 | 871 | 					" %02x %02x %02x %02x" | 
 | 872 | 					"\n", | 
 | 873 | 					i, | 
 | 874 | 					buf[i], buf [i+1], | 
 | 875 | 						buf[i+2], buf[i+3], | 
 | 876 | 					buf[i+4], buf [i+5], | 
 | 877 | 						buf[i+6], buf[i+7], | 
 | 878 | 					buf[i+8], buf [i+9], | 
 | 879 | 						buf[i+10], buf[i+11], | 
 | 880 | 					buf[i+12], buf [i+13], | 
 | 881 | 						buf[i+14], buf[i+15]); | 
 | 882 | 			} | 
 | 883 | 		} | 
 | 884 | 		break; | 
 | 885 | 	} | 
| David Brownell | 7e27f18 | 2006-06-13 09:54:40 -0700 | [diff] [blame] | 886 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 887 | 	return -ENOTSUPP; | 
 | 888 | } | 
 | 889 |  | 
| David Brownell | 15b2d2b | 2008-06-19 18:19:16 -0700 | [diff] [blame] | 890 | int rndis_register(void (*resp_avail)(void *v), void *v) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 891 | { | 
 | 892 | 	u8 i; | 
| David Brownell | 7e27f18 | 2006-06-13 09:54:40 -0700 | [diff] [blame] | 893 |  | 
| David Brownell | 15b2d2b | 2008-06-19 18:19:16 -0700 | [diff] [blame] | 894 | 	if (!resp_avail) | 
 | 895 | 		return -EINVAL; | 
 | 896 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 897 | 	for (i = 0; i < RNDIS_MAX_CONFIGS; i++) { | 
 | 898 | 		if (!rndis_per_dev_params [i].used) { | 
 | 899 | 			rndis_per_dev_params [i].used = 1; | 
| David Brownell | 15b2d2b | 2008-06-19 18:19:16 -0700 | [diff] [blame] | 900 | 			rndis_per_dev_params [i].resp_avail = resp_avail; | 
 | 901 | 			rndis_per_dev_params [i].v = v; | 
| David Brownell | 33376c1 | 2008-08-18 17:45:07 -0700 | [diff] [blame] | 902 | 			pr_debug("%s: configNr = %d\n", __func__, i); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 903 | 			return i; | 
 | 904 | 		} | 
 | 905 | 	} | 
| David Brownell | 33376c1 | 2008-08-18 17:45:07 -0700 | [diff] [blame] | 906 | 	pr_debug("failed\n"); | 
| David Brownell | 7e27f18 | 2006-06-13 09:54:40 -0700 | [diff] [blame] | 907 |  | 
| David Brownell | 15b2d2b | 2008-06-19 18:19:16 -0700 | [diff] [blame] | 908 | 	return -ENODEV; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 909 | } | 
 | 910 |  | 
 | 911 | void rndis_deregister (int configNr) | 
 | 912 | { | 
| David Brownell | 33376c1 | 2008-08-18 17:45:07 -0700 | [diff] [blame] | 913 | 	pr_debug("%s: \n", __func__); | 
| David Brownell | 7e27f18 | 2006-06-13 09:54:40 -0700 | [diff] [blame] | 914 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 915 | 	if (configNr >= RNDIS_MAX_CONFIGS) return; | 
 | 916 | 	rndis_per_dev_params [configNr].used = 0; | 
| David Brownell | 7e27f18 | 2006-06-13 09:54:40 -0700 | [diff] [blame] | 917 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 918 | 	return; | 
 | 919 | } | 
 | 920 |  | 
| David Brownell | 15b2d2b | 2008-06-19 18:19:16 -0700 | [diff] [blame] | 921 | 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] | 922 | { | 
| David Brownell | 33376c1 | 2008-08-18 17:45:07 -0700 | [diff] [blame] | 923 | 	pr_debug("%s:\n", __func__); | 
| David Brownell | 15b2d2b | 2008-06-19 18:19:16 -0700 | [diff] [blame] | 924 | 	if (!dev) | 
 | 925 | 		return -EINVAL; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 926 | 	if (configNr >= RNDIS_MAX_CONFIGS) return -1; | 
| David Brownell | 7e27f18 | 2006-06-13 09:54:40 -0700 | [diff] [blame] | 927 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 928 | 	rndis_per_dev_params [configNr].dev = dev; | 
| David Brownell | 340600a | 2005-04-28 13:45:25 -0700 | [diff] [blame] | 929 | 	rndis_per_dev_params [configNr].filter = cdc_filter; | 
| David Brownell | 7e27f18 | 2006-06-13 09:54:40 -0700 | [diff] [blame] | 930 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 931 | 	return 0; | 
 | 932 | } | 
 | 933 |  | 
 | 934 | int rndis_set_param_vendor (u8 configNr, u32 vendorID, const char *vendorDescr) | 
 | 935 | { | 
| David Brownell | 33376c1 | 2008-08-18 17:45:07 -0700 | [diff] [blame] | 936 | 	pr_debug("%s:\n", __func__); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 937 | 	if (!vendorDescr) return -1; | 
 | 938 | 	if (configNr >= RNDIS_MAX_CONFIGS) return -1; | 
| David Brownell | 7e27f18 | 2006-06-13 09:54:40 -0700 | [diff] [blame] | 939 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 940 | 	rndis_per_dev_params [configNr].vendorID = vendorID; | 
 | 941 | 	rndis_per_dev_params [configNr].vendorDescr = vendorDescr; | 
| David Brownell | 7e27f18 | 2006-06-13 09:54:40 -0700 | [diff] [blame] | 942 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 943 | 	return 0; | 
 | 944 | } | 
 | 945 |  | 
 | 946 | int rndis_set_param_medium (u8 configNr, u32 medium, u32 speed) | 
 | 947 | { | 
| David Brownell | 33376c1 | 2008-08-18 17:45:07 -0700 | [diff] [blame] | 948 | 	pr_debug("%s: %u %u\n", __func__, medium, speed); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 949 | 	if (configNr >= RNDIS_MAX_CONFIGS) return -1; | 
| David Brownell | 7e27f18 | 2006-06-13 09:54:40 -0700 | [diff] [blame] | 950 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 951 | 	rndis_per_dev_params [configNr].medium = medium; | 
 | 952 | 	rndis_per_dev_params [configNr].speed = speed; | 
| David Brownell | 7e27f18 | 2006-06-13 09:54:40 -0700 | [diff] [blame] | 953 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 954 | 	return 0; | 
 | 955 | } | 
 | 956 |  | 
 | 957 | void rndis_add_hdr (struct sk_buff *skb) | 
 | 958 | { | 
 | 959 | 	struct rndis_packet_msg_type	*header; | 
 | 960 |  | 
 | 961 | 	if (!skb) | 
 | 962 | 		return; | 
 | 963 | 	header = (void *) skb_push (skb, sizeof *header); | 
 | 964 | 	memset (header, 0, sizeof *header); | 
| Harvey Harrison | 35c26c2 | 2009-02-14 22:56:56 -0800 | [diff] [blame] | 965 | 	header->MessageType = cpu_to_le32(REMOTE_NDIS_PACKET_MSG); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 966 | 	header->MessageLength = cpu_to_le32(skb->len); | 
| Harvey Harrison | 35c26c2 | 2009-02-14 22:56:56 -0800 | [diff] [blame] | 967 | 	header->DataOffset = cpu_to_le32 (36); | 
| David Brownell | 6cdee10 | 2005-04-18 17:39:34 -0700 | [diff] [blame] | 968 | 	header->DataLength = cpu_to_le32(skb->len - sizeof *header); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 969 | } | 
 | 970 |  | 
 | 971 | void rndis_free_response (int configNr, u8 *buf) | 
 | 972 | { | 
 | 973 | 	rndis_resp_t		*r; | 
 | 974 | 	struct list_head	*act, *tmp; | 
| David Brownell | 7e27f18 | 2006-06-13 09:54:40 -0700 | [diff] [blame] | 975 |  | 
 | 976 | 	list_for_each_safe (act, tmp, | 
 | 977 | 			&(rndis_per_dev_params [configNr].resp_queue)) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 978 | 	{ | 
 | 979 | 		r = list_entry (act, rndis_resp_t, list); | 
 | 980 | 		if (r && r->buf == buf) { | 
 | 981 | 			list_del (&r->list); | 
 | 982 | 			kfree (r); | 
 | 983 | 		} | 
 | 984 | 	} | 
 | 985 | } | 
 | 986 |  | 
 | 987 | u8 *rndis_get_next_response (int configNr, u32 *length) | 
 | 988 | { | 
 | 989 | 	rndis_resp_t		*r; | 
| David Brownell | 7e27f18 | 2006-06-13 09:54:40 -0700 | [diff] [blame] | 990 | 	struct list_head	*act, *tmp; | 
 | 991 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 992 | 	if (!length) return NULL; | 
| David Brownell | 7e27f18 | 2006-06-13 09:54:40 -0700 | [diff] [blame] | 993 |  | 
 | 994 | 	list_for_each_safe (act, tmp, | 
 | 995 | 			&(rndis_per_dev_params [configNr].resp_queue)) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 996 | 	{ | 
 | 997 | 		r = list_entry (act, rndis_resp_t, list); | 
 | 998 | 		if (!r->send) { | 
 | 999 | 			r->send = 1; | 
 | 1000 | 			*length = r->length; | 
 | 1001 | 			return r->buf; | 
 | 1002 | 		} | 
 | 1003 | 	} | 
| David Brownell | 7e27f18 | 2006-06-13 09:54:40 -0700 | [diff] [blame] | 1004 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1005 | 	return NULL; | 
 | 1006 | } | 
 | 1007 |  | 
 | 1008 | static rndis_resp_t *rndis_add_response (int configNr, u32 length) | 
 | 1009 | { | 
 | 1010 | 	rndis_resp_t	*r; | 
| David Brownell | 7e27f18 | 2006-06-13 09:54:40 -0700 | [diff] [blame] | 1011 |  | 
| David Brownell | 340600a | 2005-04-28 13:45:25 -0700 | [diff] [blame] | 1012 | 	/* NOTE:  this gets copied into ether.c USB_BUFSIZ bytes ... */ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1013 | 	r = kmalloc (sizeof (rndis_resp_t) + length, GFP_ATOMIC); | 
 | 1014 | 	if (!r) return NULL; | 
| David Brownell | 7e27f18 | 2006-06-13 09:54:40 -0700 | [diff] [blame] | 1015 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1016 | 	r->buf = (u8 *) (r + 1); | 
 | 1017 | 	r->length = length; | 
 | 1018 | 	r->send = 0; | 
| David Brownell | 7e27f18 | 2006-06-13 09:54:40 -0700 | [diff] [blame] | 1019 |  | 
 | 1020 | 	list_add_tail (&r->list, | 
 | 1021 | 		&(rndis_per_dev_params [configNr].resp_queue)); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1022 | 	return r; | 
 | 1023 | } | 
 | 1024 |  | 
| Brian Niebuhr | 9b39e9d | 2009-08-14 10:04:22 -0500 | [diff] [blame] | 1025 | int rndis_rm_hdr(struct gether *port, | 
 | 1026 | 			struct sk_buff *skb, | 
 | 1027 | 			struct sk_buff_head *list) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1028 | { | 
| David Brownell | 6cdee10 | 2005-04-18 17:39:34 -0700 | [diff] [blame] | 1029 | 	/* tmp points to a struct rndis_packet_msg_type */ | 
 | 1030 | 	__le32		*tmp = (void *) skb->data; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1031 |  | 
| David Brownell | 6cdee10 | 2005-04-18 17:39:34 -0700 | [diff] [blame] | 1032 | 	/* MessageType, MessageLength */ | 
| Harvey Harrison | 35c26c2 | 2009-02-14 22:56:56 -0800 | [diff] [blame] | 1033 | 	if (cpu_to_le32(REMOTE_NDIS_PACKET_MSG) | 
| Brian Niebuhr | 9b39e9d | 2009-08-14 10:04:22 -0500 | [diff] [blame] | 1034 | 			!= get_unaligned(tmp++)) { | 
 | 1035 | 		dev_kfree_skb_any(skb); | 
| David Brownell | 6cdee10 | 2005-04-18 17:39:34 -0700 | [diff] [blame] | 1036 | 		return -EINVAL; | 
| Brian Niebuhr | 9b39e9d | 2009-08-14 10:04:22 -0500 | [diff] [blame] | 1037 | 	} | 
| David Brownell | 6cdee10 | 2005-04-18 17:39:34 -0700 | [diff] [blame] | 1038 | 	tmp++; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1039 |  | 
| David Brownell | 6cdee10 | 2005-04-18 17:39:34 -0700 | [diff] [blame] | 1040 | 	/* DataOffset, DataLength */ | 
| Brian Niebuhr | 9b39e9d | 2009-08-14 10:04:22 -0500 | [diff] [blame] | 1041 | 	if (!skb_pull(skb, get_unaligned_le32(tmp++) + 8)) { | 
 | 1042 | 		dev_kfree_skb_any(skb); | 
| David Brownell | 6cdee10 | 2005-04-18 17:39:34 -0700 | [diff] [blame] | 1043 | 		return -EOVERFLOW; | 
| Brian Niebuhr | 9b39e9d | 2009-08-14 10:04:22 -0500 | [diff] [blame] | 1044 | 	} | 
| Harvey Harrison | a5abdea | 2008-04-29 01:03:40 -0700 | [diff] [blame] | 1045 | 	skb_trim(skb, get_unaligned_le32(tmp++)); | 
| David Brownell | 6cdee10 | 2005-04-18 17:39:34 -0700 | [diff] [blame] | 1046 |  | 
| Brian Niebuhr | 9b39e9d | 2009-08-14 10:04:22 -0500 | [diff] [blame] | 1047 | 	skb_queue_tail(list, skb); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1048 | 	return 0; | 
 | 1049 | } | 
 | 1050 |  | 
 | 1051 | #ifdef	CONFIG_USB_GADGET_DEBUG_FILES | 
 | 1052 |  | 
| Alexey Dobriyan | e184d5f | 2008-05-14 16:25:13 -0700 | [diff] [blame] | 1053 | static int rndis_proc_show(struct seq_file *m, void *v) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1054 | { | 
| Alexey Dobriyan | e184d5f | 2008-05-14 16:25:13 -0700 | [diff] [blame] | 1055 | 	rndis_params *param = m->private; | 
| David Brownell | 7e27f18 | 2006-06-13 09:54:40 -0700 | [diff] [blame] | 1056 |  | 
| Alexey Dobriyan | e184d5f | 2008-05-14 16:25:13 -0700 | [diff] [blame] | 1057 | 	seq_printf(m, | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1058 | 			 "Config Nr. %d\n" | 
 | 1059 | 			 "used      : %s\n" | 
 | 1060 | 			 "state     : %s\n" | 
 | 1061 | 			 "medium    : 0x%08X\n" | 
 | 1062 | 			 "speed     : %d\n" | 
 | 1063 | 			 "cable     : %s\n" | 
 | 1064 | 			 "vendor ID : 0x%08X\n" | 
| David Brownell | 7e27f18 | 2006-06-13 09:54:40 -0700 | [diff] [blame] | 1065 | 			 "vendor    : %s\n", | 
 | 1066 | 			 param->confignr, (param->used) ? "y" : "n", | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1067 | 			 ({ char *s = "?"; | 
 | 1068 | 			 switch (param->state) { | 
 | 1069 | 			 case RNDIS_UNINITIALIZED: | 
 | 1070 | 				s = "RNDIS_UNINITIALIZED"; break; | 
 | 1071 | 			 case RNDIS_INITIALIZED: | 
 | 1072 | 				s = "RNDIS_INITIALIZED"; break; | 
 | 1073 | 			 case RNDIS_DATA_INITIALIZED: | 
 | 1074 | 				s = "RNDIS_DATA_INITIALIZED"; break; | 
 | 1075 | 			}; s; }), | 
| David Brownell | 7e27f18 | 2006-06-13 09:54:40 -0700 | [diff] [blame] | 1076 | 			 param->medium, | 
 | 1077 | 			 (param->media_state) ? 0 : param->speed*100, | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1078 | 			 (param->media_state) ? "disconnected" : "connected", | 
| David Brownell | 7e27f18 | 2006-06-13 09:54:40 -0700 | [diff] [blame] | 1079 | 			 param->vendorID, param->vendorDescr); | 
| Alexey Dobriyan | e184d5f | 2008-05-14 16:25:13 -0700 | [diff] [blame] | 1080 | 	return 0; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1081 | } | 
 | 1082 |  | 
| Alexey Dobriyan | e184d5f | 2008-05-14 16:25:13 -0700 | [diff] [blame] | 1083 | static ssize_t rndis_proc_write(struct file *file, const char __user *buffer, | 
 | 1084 | 		size_t count, loff_t *ppos) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1085 | { | 
| Alexey Dobriyan | e184d5f | 2008-05-14 16:25:13 -0700 | [diff] [blame] | 1086 | 	rndis_params *p = PDE(file->f_path.dentry->d_inode)->data; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1087 | 	u32 speed = 0; | 
 | 1088 | 	int i, fl_speed = 0; | 
| David Brownell | 7e27f18 | 2006-06-13 09:54:40 -0700 | [diff] [blame] | 1089 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1090 | 	for (i = 0; i < count; i++) { | 
 | 1091 | 		char c; | 
 | 1092 | 		if (get_user(c, buffer)) | 
 | 1093 | 			return -EFAULT; | 
 | 1094 | 		switch (c) { | 
 | 1095 | 		case '0': | 
 | 1096 | 		case '1': | 
 | 1097 | 		case '2': | 
 | 1098 | 		case '3': | 
 | 1099 | 		case '4': | 
 | 1100 | 		case '5': | 
 | 1101 | 		case '6': | 
 | 1102 | 		case '7': | 
 | 1103 | 		case '8': | 
 | 1104 | 		case '9': | 
 | 1105 | 			fl_speed = 1; | 
 | 1106 | 			speed = speed*10 + c - '0'; | 
 | 1107 | 			break; | 
 | 1108 | 		case 'C': | 
 | 1109 | 		case 'c': | 
 | 1110 | 			rndis_signal_connect (p->confignr); | 
 | 1111 | 			break; | 
 | 1112 | 		case 'D': | 
 | 1113 | 		case 'd': | 
 | 1114 | 			rndis_signal_disconnect(p->confignr); | 
 | 1115 | 			break; | 
| David Brownell | 7e27f18 | 2006-06-13 09:54:40 -0700 | [diff] [blame] | 1116 | 		default: | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1117 | 			if (fl_speed) p->speed = speed; | 
| David Brownell | 33376c1 | 2008-08-18 17:45:07 -0700 | [diff] [blame] | 1118 | 			else pr_debug("%c is not valid\n", c); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1119 | 			break; | 
 | 1120 | 		} | 
| David Brownell | 7e27f18 | 2006-06-13 09:54:40 -0700 | [diff] [blame] | 1121 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1122 | 		buffer++; | 
 | 1123 | 	} | 
| David Brownell | 7e27f18 | 2006-06-13 09:54:40 -0700 | [diff] [blame] | 1124 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1125 | 	return count; | 
 | 1126 | } | 
 | 1127 |  | 
| Alexey Dobriyan | e184d5f | 2008-05-14 16:25:13 -0700 | [diff] [blame] | 1128 | static int rndis_proc_open(struct inode *inode, struct file *file) | 
 | 1129 | { | 
 | 1130 | 	return single_open(file, rndis_proc_show, PDE(inode)->data); | 
 | 1131 | } | 
 | 1132 |  | 
 | 1133 | static const struct file_operations rndis_proc_fops = { | 
 | 1134 | 	.owner		= THIS_MODULE, | 
 | 1135 | 	.open		= rndis_proc_open, | 
 | 1136 | 	.read		= seq_read, | 
 | 1137 | 	.llseek		= seq_lseek, | 
 | 1138 | 	.release	= single_release, | 
 | 1139 | 	.write		= rndis_proc_write, | 
 | 1140 | }; | 
 | 1141 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1142 | #define	NAME_TEMPLATE	"driver/rndis-%03d" | 
 | 1143 |  | 
 | 1144 | static struct proc_dir_entry *rndis_connect_state [RNDIS_MAX_CONFIGS]; | 
 | 1145 |  | 
 | 1146 | #endif	/* CONFIG_USB_GADGET_DEBUG_FILES */ | 
 | 1147 |  | 
 | 1148 |  | 
| David Brownell | 0e530b4 | 2008-04-05 14:17:14 -0700 | [diff] [blame] | 1149 | int __init rndis_init (void) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1150 | { | 
 | 1151 | 	u8 i; | 
 | 1152 |  | 
 | 1153 | 	for (i = 0; i < RNDIS_MAX_CONFIGS; i++) { | 
 | 1154 | #ifdef	CONFIG_USB_GADGET_DEBUG_FILES | 
 | 1155 | 		char name [20]; | 
 | 1156 |  | 
 | 1157 | 		sprintf (name, NAME_TEMPLATE, i); | 
 | 1158 | 		if (!(rndis_connect_state [i] | 
| Alexey Dobriyan | e184d5f | 2008-05-14 16:25:13 -0700 | [diff] [blame] | 1159 | 				= proc_create_data(name, 0660, NULL, | 
 | 1160 | 					&rndis_proc_fops, | 
 | 1161 | 					(void *)(rndis_per_dev_params + i)))) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1162 | 		{ | 
| David Brownell | 33376c1 | 2008-08-18 17:45:07 -0700 | [diff] [blame] | 1163 | 			pr_debug("%s :remove entries", __func__); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1164 | 			while (i) { | 
 | 1165 | 				sprintf (name, NAME_TEMPLATE, --i); | 
 | 1166 | 				remove_proc_entry (name, NULL); | 
 | 1167 | 			} | 
| David Brownell | 33376c1 | 2008-08-18 17:45:07 -0700 | [diff] [blame] | 1168 | 			pr_debug("\n"); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1169 | 			return -EIO; | 
 | 1170 | 		} | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1171 | #endif | 
 | 1172 | 		rndis_per_dev_params [i].confignr = i; | 
 | 1173 | 		rndis_per_dev_params [i].used = 0; | 
 | 1174 | 		rndis_per_dev_params [i].state = RNDIS_UNINITIALIZED; | 
 | 1175 | 		rndis_per_dev_params [i].media_state | 
 | 1176 | 				= NDIS_MEDIA_STATE_DISCONNECTED; | 
 | 1177 | 		INIT_LIST_HEAD (&(rndis_per_dev_params [i].resp_queue)); | 
 | 1178 | 	} | 
| David Brownell | 7e27f18 | 2006-06-13 09:54:40 -0700 | [diff] [blame] | 1179 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1180 | 	return 0; | 
 | 1181 | } | 
 | 1182 |  | 
 | 1183 | void rndis_exit (void) | 
 | 1184 | { | 
 | 1185 | #ifdef	CONFIG_USB_GADGET_DEBUG_FILES | 
 | 1186 | 	u8 i; | 
 | 1187 | 	char name [20]; | 
| David Brownell | 7e27f18 | 2006-06-13 09:54:40 -0700 | [diff] [blame] | 1188 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1189 | 	for (i = 0; i < RNDIS_MAX_CONFIGS; i++) { | 
 | 1190 | 		sprintf (name, NAME_TEMPLATE, i); | 
 | 1191 | 		remove_proc_entry (name, NULL); | 
 | 1192 | 	} | 
 | 1193 | #endif | 
 | 1194 | } | 
 | 1195 |  |