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