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