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