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) { |
Mayank Rana | 02ecd42 | 2016-05-10 14:11:27 -0700 | [diff] [blame] | 541 | pr_debug("%s(): disable flow control\n", __func__); |
| 542 | rndis_flow_control(params, false); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 543 | } else { |
Mayank Rana | 02ecd42 | 2016-05-10 14:11:27 -0700 | [diff] [blame] | 544 | pr_err("%s(): enable flow control\n", __func__); |
| 545 | rndis_flow_control(params, true); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 546 | } |
| 547 | break; |
David Brownell | 7e27f18 | 2006-06-13 09:54:40 -0700 | [diff] [blame] | 548 | |
Linus Walleij | 4cc6c4d | 2012-05-11 22:16:16 +0000 | [diff] [blame] | 549 | case RNDIS_OID_802_3_MULTICAST_LIST: |
David Brownell | 7e27f18 | 2006-06-13 09:54:40 -0700 | [diff] [blame] | 550 | /* I think we can ignore this */ |
Linus Walleij | 4cc6c4d | 2012-05-11 22:16:16 +0000 | [diff] [blame] | 551 | pr_debug("%s: RNDIS_OID_802_3_MULTICAST_LIST\n", __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 552 | retval = 0; |
| 553 | break; |
David Brownell | 340600a | 2005-04-28 13:45:25 -0700 | [diff] [blame] | 554 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 555 | default: |
David Brownell | 0027492 | 2007-11-19 12:58:36 -0800 | [diff] [blame] | 556 | pr_warning("%s: set unknown OID 0x%08X, size %d\n", |
Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 557 | __func__, OID, buf_len); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 558 | } |
David Brownell | 7e27f18 | 2006-06-13 09:54:40 -0700 | [diff] [blame] | 559 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 560 | return retval; |
| 561 | } |
| 562 | |
David Brownell | 7e27f18 | 2006-06-13 09:54:40 -0700 | [diff] [blame] | 563 | /* |
| 564 | * Response Functions |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 565 | */ |
| 566 | |
Andrzej Pietrasiewicz | 83210e5 | 2015-03-20 08:18:47 +0100 | [diff] [blame] | 567 | static int rndis_init_response(struct rndis_params *params, |
| 568 | rndis_init_msg_type *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 569 | { |
Mihai Donțu | a1df4e4 | 2010-09-08 02:54:02 +0300 | [diff] [blame] | 570 | rndis_init_cmplt_type *resp; |
| 571 | rndis_resp_t *r; |
David Brownell | 7e27f18 | 2006-06-13 09:54:40 -0700 | [diff] [blame] | 572 | |
David Brownell | 15b2d2b | 2008-06-19 18:19:16 -0700 | [diff] [blame] | 573 | if (!params->dev) |
| 574 | return -ENOTSUPP; |
David Brownell | 7e27f18 | 2006-06-13 09:54:40 -0700 | [diff] [blame] | 575 | |
Andrzej Pietrasiewicz | 83210e5 | 2015-03-20 08:18:47 +0100 | [diff] [blame] | 576 | r = rndis_add_response(params, sizeof(rndis_init_cmplt_type)); |
David Brownell | 340600a | 2005-04-28 13:45:25 -0700 | [diff] [blame] | 577 | if (!r) |
| 578 | return -ENOMEM; |
Mihai Donțu | a1df4e4 | 2010-09-08 02:54:02 +0300 | [diff] [blame] | 579 | resp = (rndis_init_cmplt_type *)r->buf; |
David Brownell | 7e27f18 | 2006-06-13 09:54:40 -0700 | [diff] [blame] | 580 | |
Linus Walleij | 5149116 | 2012-05-11 22:17:07 +0000 | [diff] [blame] | 581 | resp->MessageType = cpu_to_le32(RNDIS_MSG_INIT_C); |
Mihai Donțu | a1df4e4 | 2010-09-08 02:54:02 +0300 | [diff] [blame] | 582 | resp->MessageLength = cpu_to_le32(52); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 583 | resp->RequestID = buf->RequestID; /* Still LE in msg buffer */ |
Mihai Donțu | a1df4e4 | 2010-09-08 02:54:02 +0300 | [diff] [blame] | 584 | resp->Status = cpu_to_le32(RNDIS_STATUS_SUCCESS); |
| 585 | resp->MajorVersion = cpu_to_le32(RNDIS_MAJOR_VERSION); |
| 586 | resp->MinorVersion = cpu_to_le32(RNDIS_MINOR_VERSION); |
| 587 | resp->DeviceFlags = cpu_to_le32(RNDIS_DF_CONNECTIONLESS); |
| 588 | resp->Medium = cpu_to_le32(RNDIS_MEDIUM_802_3); |
xerox_lin | 72ffa18 | 2014-08-14 14:48:44 +0800 | [diff] [blame] | 589 | resp->MaxPacketsPerTransfer = cpu_to_le32(params->max_pkt_per_xfer); |
| 590 | resp->MaxTransferSize = cpu_to_le32(params->max_pkt_per_xfer * |
| 591 | (params->dev->mtu |
Mihai Donțu | a1df4e4 | 2010-09-08 02:54:02 +0300 | [diff] [blame] | 592 | + sizeof(struct ethhdr) |
| 593 | + sizeof(struct rndis_packet_msg_type) |
xerox_lin | 72ffa18 | 2014-08-14 14:48:44 +0800 | [diff] [blame] | 594 | + 22)); |
Hemant Kumar | 6ccd55c | 2016-02-01 18:54:16 -0800 | [diff] [blame] | 595 | resp->PacketAlignmentFactor = cpu_to_le32(params->pkt_alignment_factor); |
Mihai Donțu | a1df4e4 | 2010-09-08 02:54:02 +0300 | [diff] [blame] | 596 | resp->AFListOffset = cpu_to_le32(0); |
| 597 | resp->AFListSize = cpu_to_le32(0); |
David Brownell | 7e27f18 | 2006-06-13 09:54:40 -0700 | [diff] [blame] | 598 | |
Chandana Kishori Chiluveru | 50a2184 | 2017-11-06 14:54:24 +0530 | [diff] [blame] | 599 | params->ul_max_xfer_size = le32_to_cpu(resp->MaxTransferSize); |
David Brownell | 15b2d2b | 2008-06-19 18:19:16 -0700 | [diff] [blame] | 600 | params->resp_avail(params->v); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 601 | return 0; |
| 602 | } |
| 603 | |
Andrzej Pietrasiewicz | 83210e5 | 2015-03-20 08:18:47 +0100 | [diff] [blame] | 604 | static int rndis_query_response(struct rndis_params *params, |
| 605 | rndis_query_msg_type *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 606 | { |
| 607 | rndis_query_cmplt_type *resp; |
Mihai Donțu | a1df4e4 | 2010-09-08 02:54:02 +0300 | [diff] [blame] | 608 | rndis_resp_t *r; |
David Brownell | 7e27f18 | 2006-06-13 09:54:40 -0700 | [diff] [blame] | 609 | |
David Brownell | 33376c1 | 2008-08-18 17:45:07 -0700 | [diff] [blame] | 610 | /* pr_debug("%s: OID = %08X\n", __func__, cpu_to_le32(buf->OID)); */ |
David Brownell | 15b2d2b | 2008-06-19 18:19:16 -0700 | [diff] [blame] | 611 | if (!params->dev) |
| 612 | return -ENOTSUPP; |
David Brownell | 7e27f18 | 2006-06-13 09:54:40 -0700 | [diff] [blame] | 613 | |
Shaun Tancheff | 8763716 | 2006-02-22 19:47:19 -0800 | [diff] [blame] | 614 | /* |
| 615 | * we need more memory: |
| 616 | * gen_ndis_query_resp expects enough space for |
| 617 | * rndis_query_cmplt_type followed by data. |
| 618 | * oid_supported_list is the largest data reply |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 619 | */ |
Andrzej Pietrasiewicz | 83210e5 | 2015-03-20 08:18:47 +0100 | [diff] [blame] | 620 | r = rndis_add_response(params, |
Mihai Donțu | a1df4e4 | 2010-09-08 02:54:02 +0300 | [diff] [blame] | 621 | sizeof(oid_supported_list) + sizeof(rndis_query_cmplt_type)); |
David Brownell | 340600a | 2005-04-28 13:45:25 -0700 | [diff] [blame] | 622 | if (!r) |
| 623 | return -ENOMEM; |
Mihai Donțu | a1df4e4 | 2010-09-08 02:54:02 +0300 | [diff] [blame] | 624 | resp = (rndis_query_cmplt_type *)r->buf; |
David Brownell | 7e27f18 | 2006-06-13 09:54:40 -0700 | [diff] [blame] | 625 | |
Linus Walleij | 5149116 | 2012-05-11 22:17:07 +0000 | [diff] [blame] | 626 | resp->MessageType = cpu_to_le32(RNDIS_MSG_QUERY_C); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 627 | resp->RequestID = buf->RequestID; /* Still LE in msg buffer */ |
David Brownell | 7e27f18 | 2006-06-13 09:54:40 -0700 | [diff] [blame] | 628 | |
Andrzej Pietrasiewicz | 83210e5 | 2015-03-20 08:18:47 +0100 | [diff] [blame] | 629 | if (gen_ndis_query_resp(params, le32_to_cpu(buf->OID), |
David Brownell | 340600a | 2005-04-28 13:45:25 -0700 | [diff] [blame] | 630 | le32_to_cpu(buf->InformationBufferOffset) |
Mihai Donțu | a1df4e4 | 2010-09-08 02:54:02 +0300 | [diff] [blame] | 631 | + 8 + (u8 *)buf, |
David Brownell | 340600a | 2005-04-28 13:45:25 -0700 | [diff] [blame] | 632 | le32_to_cpu(buf->InformationBufferLength), |
| 633 | r)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 634 | /* OID not supported */ |
Mihai Donțu | a1df4e4 | 2010-09-08 02:54:02 +0300 | [diff] [blame] | 635 | resp->Status = cpu_to_le32(RNDIS_STATUS_NOT_SUPPORTED); |
| 636 | resp->MessageLength = cpu_to_le32(sizeof *resp); |
| 637 | resp->InformationBufferLength = cpu_to_le32(0); |
| 638 | resp->InformationBufferOffset = cpu_to_le32(0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 639 | } else |
Mihai Donțu | a1df4e4 | 2010-09-08 02:54:02 +0300 | [diff] [blame] | 640 | resp->Status = cpu_to_le32(RNDIS_STATUS_SUCCESS); |
David Brownell | 7e27f18 | 2006-06-13 09:54:40 -0700 | [diff] [blame] | 641 | |
David Brownell | 15b2d2b | 2008-06-19 18:19:16 -0700 | [diff] [blame] | 642 | params->resp_avail(params->v); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 643 | return 0; |
| 644 | } |
| 645 | |
Andrzej Pietrasiewicz | 83210e5 | 2015-03-20 08:18:47 +0100 | [diff] [blame] | 646 | static int rndis_set_response(struct rndis_params *params, |
| 647 | rndis_set_msg_type *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 648 | { |
Mihai Donțu | a1df4e4 | 2010-09-08 02:54:02 +0300 | [diff] [blame] | 649 | u32 BufLength, BufOffset; |
| 650 | rndis_set_cmplt_type *resp; |
| 651 | rndis_resp_t *r; |
David Brownell | 7e27f18 | 2006-06-13 09:54:40 -0700 | [diff] [blame] | 652 | |
Andrzej Pietrasiewicz | 83210e5 | 2015-03-20 08:18:47 +0100 | [diff] [blame] | 653 | r = rndis_add_response(params, sizeof(rndis_set_cmplt_type)); |
David Brownell | 340600a | 2005-04-28 13:45:25 -0700 | [diff] [blame] | 654 | if (!r) |
| 655 | return -ENOMEM; |
Mihai Donțu | a1df4e4 | 2010-09-08 02:54:02 +0300 | [diff] [blame] | 656 | resp = (rndis_set_cmplt_type *)r->buf; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 657 | |
Mihai Donțu | a1df4e4 | 2010-09-08 02:54:02 +0300 | [diff] [blame] | 658 | BufLength = le32_to_cpu(buf->InformationBufferLength); |
| 659 | BufOffset = le32_to_cpu(buf->InformationBufferOffset); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 660 | |
David Brownell | 15b2d2b | 2008-06-19 18:19:16 -0700 | [diff] [blame] | 661 | #ifdef VERBOSE_DEBUG |
David Brownell | 33376c1 | 2008-08-18 17:45:07 -0700 | [diff] [blame] | 662 | pr_debug("%s: Length: %d\n", __func__, BufLength); |
| 663 | pr_debug("%s: Offset: %d\n", __func__, BufOffset); |
| 664 | pr_debug("%s: InfoBuffer: ", __func__); |
David Brownell | 7e27f18 | 2006-06-13 09:54:40 -0700 | [diff] [blame] | 665 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 666 | for (i = 0; i < BufLength; i++) { |
David Brownell | 33376c1 | 2008-08-18 17:45:07 -0700 | [diff] [blame] | 667 | pr_debug("%02x ", *(((u8 *) buf) + i + 8 + BufOffset)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 668 | } |
David Brownell | 7e27f18 | 2006-06-13 09:54:40 -0700 | [diff] [blame] | 669 | |
David Brownell | 33376c1 | 2008-08-18 17:45:07 -0700 | [diff] [blame] | 670 | pr_debug("\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 671 | #endif |
David Brownell | 7e27f18 | 2006-06-13 09:54:40 -0700 | [diff] [blame] | 672 | |
Linus Walleij | 5149116 | 2012-05-11 22:17:07 +0000 | [diff] [blame] | 673 | resp->MessageType = cpu_to_le32(RNDIS_MSG_SET_C); |
Mihai Donțu | a1df4e4 | 2010-09-08 02:54:02 +0300 | [diff] [blame] | 674 | resp->MessageLength = cpu_to_le32(16); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 675 | resp->RequestID = buf->RequestID; /* Still LE in msg buffer */ |
Andrzej Pietrasiewicz | 83210e5 | 2015-03-20 08:18:47 +0100 | [diff] [blame] | 676 | if (gen_ndis_set_resp(params, le32_to_cpu(buf->OID), |
Mihai Donțu | a1df4e4 | 2010-09-08 02:54:02 +0300 | [diff] [blame] | 677 | ((u8 *)buf) + 8 + BufOffset, BufLength, r)) |
| 678 | resp->Status = cpu_to_le32(RNDIS_STATUS_NOT_SUPPORTED); |
David Brownell | 7e27f18 | 2006-06-13 09:54:40 -0700 | [diff] [blame] | 679 | else |
Mihai Donțu | a1df4e4 | 2010-09-08 02:54:02 +0300 | [diff] [blame] | 680 | resp->Status = cpu_to_le32(RNDIS_STATUS_SUCCESS); |
David Brownell | 7e27f18 | 2006-06-13 09:54:40 -0700 | [diff] [blame] | 681 | |
David Brownell | 15b2d2b | 2008-06-19 18:19:16 -0700 | [diff] [blame] | 682 | params->resp_avail(params->v); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 683 | return 0; |
| 684 | } |
| 685 | |
Andrzej Pietrasiewicz | 83210e5 | 2015-03-20 08:18:47 +0100 | [diff] [blame] | 686 | static int rndis_reset_response(struct rndis_params *params, |
| 687 | rndis_reset_msg_type *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 688 | { |
Mihai Donțu | a1df4e4 | 2010-09-08 02:54:02 +0300 | [diff] [blame] | 689 | rndis_reset_cmplt_type *resp; |
| 690 | rndis_resp_t *r; |
xerox_lin | 90de740 | 2014-08-18 21:54:23 +0800 | [diff] [blame] | 691 | |
Andrzej Pietrasiewicz | 83210e5 | 2015-03-20 08:18:47 +0100 | [diff] [blame] | 692 | r = rndis_add_response(params, sizeof(rndis_reset_cmplt_type)); |
David Brownell | 340600a | 2005-04-28 13:45:25 -0700 | [diff] [blame] | 693 | if (!r) |
| 694 | return -ENOMEM; |
Mihai Donțu | a1df4e4 | 2010-09-08 02:54:02 +0300 | [diff] [blame] | 695 | resp = (rndis_reset_cmplt_type *)r->buf; |
David Brownell | 7e27f18 | 2006-06-13 09:54:40 -0700 | [diff] [blame] | 696 | |
Linus Walleij | 5149116 | 2012-05-11 22:17:07 +0000 | [diff] [blame] | 697 | resp->MessageType = cpu_to_le32(RNDIS_MSG_RESET_C); |
Mihai Donțu | a1df4e4 | 2010-09-08 02:54:02 +0300 | [diff] [blame] | 698 | resp->MessageLength = cpu_to_le32(16); |
| 699 | resp->Status = cpu_to_le32(RNDIS_STATUS_SUCCESS); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 700 | /* resent information */ |
Mihai Donțu | a1df4e4 | 2010-09-08 02:54:02 +0300 | [diff] [blame] | 701 | resp->AddressingReset = cpu_to_le32(1); |
David Brownell | 7e27f18 | 2006-06-13 09:54:40 -0700 | [diff] [blame] | 702 | |
David Brownell | 15b2d2b | 2008-06-19 18:19:16 -0700 | [diff] [blame] | 703 | params->resp_avail(params->v); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 704 | return 0; |
| 705 | } |
| 706 | |
Andrzej Pietrasiewicz | 83210e5 | 2015-03-20 08:18:47 +0100 | [diff] [blame] | 707 | static int rndis_keepalive_response(struct rndis_params *params, |
Mihai Donțu | a1df4e4 | 2010-09-08 02:54:02 +0300 | [diff] [blame] | 708 | rndis_keepalive_msg_type *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 709 | { |
Mihai Donțu | a1df4e4 | 2010-09-08 02:54:02 +0300 | [diff] [blame] | 710 | rndis_keepalive_cmplt_type *resp; |
| 711 | rndis_resp_t *r; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 712 | |
| 713 | /* host "should" check only in RNDIS_DATA_INITIALIZED state */ |
| 714 | |
Andrzej Pietrasiewicz | 83210e5 | 2015-03-20 08:18:47 +0100 | [diff] [blame] | 715 | r = rndis_add_response(params, sizeof(rndis_keepalive_cmplt_type)); |
David Brownell | 340600a | 2005-04-28 13:45:25 -0700 | [diff] [blame] | 716 | if (!r) |
| 717 | return -ENOMEM; |
Mihai Donțu | a1df4e4 | 2010-09-08 02:54:02 +0300 | [diff] [blame] | 718 | resp = (rndis_keepalive_cmplt_type *)r->buf; |
David Brownell | 7e27f18 | 2006-06-13 09:54:40 -0700 | [diff] [blame] | 719 | |
Linus Walleij | 5149116 | 2012-05-11 22:17:07 +0000 | [diff] [blame] | 720 | resp->MessageType = cpu_to_le32(RNDIS_MSG_KEEPALIVE_C); |
Mihai Donțu | a1df4e4 | 2010-09-08 02:54:02 +0300 | [diff] [blame] | 721 | resp->MessageLength = cpu_to_le32(16); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 722 | resp->RequestID = buf->RequestID; /* Still LE in msg buffer */ |
Mihai Donțu | a1df4e4 | 2010-09-08 02:54:02 +0300 | [diff] [blame] | 723 | resp->Status = cpu_to_le32(RNDIS_STATUS_SUCCESS); |
David Brownell | 7e27f18 | 2006-06-13 09:54:40 -0700 | [diff] [blame] | 724 | |
David Brownell | 15b2d2b | 2008-06-19 18:19:16 -0700 | [diff] [blame] | 725 | params->resp_avail(params->v); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 726 | return 0; |
| 727 | } |
| 728 | |
| 729 | |
David Brownell | 7e27f18 | 2006-06-13 09:54:40 -0700 | [diff] [blame] | 730 | /* |
| 731 | * Device to Host Comunication |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 732 | */ |
Andrzej Pietrasiewicz | 83210e5 | 2015-03-20 08:18:47 +0100 | [diff] [blame] | 733 | static int rndis_indicate_status_msg(struct rndis_params *params, u32 status) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 734 | { |
Mihai Donțu | a1df4e4 | 2010-09-08 02:54:02 +0300 | [diff] [blame] | 735 | rndis_indicate_status_msg_type *resp; |
| 736 | rndis_resp_t *r; |
David Brownell | 7e27f18 | 2006-06-13 09:54:40 -0700 | [diff] [blame] | 737 | |
David Brownell | 15b2d2b | 2008-06-19 18:19:16 -0700 | [diff] [blame] | 738 | if (params->state == RNDIS_UNINITIALIZED) |
David Brownell | 7e27f18 | 2006-06-13 09:54:40 -0700 | [diff] [blame] | 739 | return -ENOTSUPP; |
| 740 | |
Andrzej Pietrasiewicz | 83210e5 | 2015-03-20 08:18:47 +0100 | [diff] [blame] | 741 | r = rndis_add_response(params, sizeof(rndis_indicate_status_msg_type)); |
David Brownell | 340600a | 2005-04-28 13:45:25 -0700 | [diff] [blame] | 742 | if (!r) |
| 743 | return -ENOMEM; |
Mihai Donțu | a1df4e4 | 2010-09-08 02:54:02 +0300 | [diff] [blame] | 744 | resp = (rndis_indicate_status_msg_type *)r->buf; |
David Brownell | 7e27f18 | 2006-06-13 09:54:40 -0700 | [diff] [blame] | 745 | |
Linus Walleij | 5149116 | 2012-05-11 22:17:07 +0000 | [diff] [blame] | 746 | resp->MessageType = cpu_to_le32(RNDIS_MSG_INDICATE); |
Mihai Donțu | a1df4e4 | 2010-09-08 02:54:02 +0300 | [diff] [blame] | 747 | resp->MessageLength = cpu_to_le32(20); |
| 748 | resp->Status = cpu_to_le32(status); |
| 749 | resp->StatusBufferLength = cpu_to_le32(0); |
| 750 | resp->StatusBufferOffset = cpu_to_le32(0); |
David Brownell | 7e27f18 | 2006-06-13 09:54:40 -0700 | [diff] [blame] | 751 | |
David Brownell | 15b2d2b | 2008-06-19 18:19:16 -0700 | [diff] [blame] | 752 | params->resp_avail(params->v); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 753 | return 0; |
| 754 | } |
| 755 | |
Andrzej Pietrasiewicz | 83210e5 | 2015-03-20 08:18:47 +0100 | [diff] [blame] | 756 | int rndis_signal_connect(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_CONNECTED; |
| 759 | return rndis_indicate_status_msg(params, RNDIS_STATUS_MEDIA_CONNECT); |
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_connect); |
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 | int rndis_signal_disconnect(struct rndis_params *params) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 764 | { |
Andrzej Pietrasiewicz | 83210e5 | 2015-03-20 08:18:47 +0100 | [diff] [blame] | 765 | params->media_state = RNDIS_MEDIA_STATE_DISCONNECTED; |
| 766 | return rndis_indicate_status_msg(params, RNDIS_STATUS_MEDIA_DISCONNECT); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 767 | } |
Felipe Balbi | 0700faa | 2014-04-01 13:19:32 -0500 | [diff] [blame] | 768 | EXPORT_SYMBOL_GPL(rndis_signal_disconnect); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 769 | |
Andrzej Pietrasiewicz | 83210e5 | 2015-03-20 08:18:47 +0100 | [diff] [blame] | 770 | void rndis_uninit(struct rndis_params *params) |
David Brownell | 340600a | 2005-04-28 13:45:25 -0700 | [diff] [blame] | 771 | { |
David Brownell | 486e2df | 2005-05-24 17:51:52 -0700 | [diff] [blame] | 772 | u8 *buf; |
| 773 | u32 length; |
| 774 | |
Andrzej Pietrasiewicz | 83210e5 | 2015-03-20 08:18:47 +0100 | [diff] [blame] | 775 | if (!params) |
David Brownell | 340600a | 2005-04-28 13:45:25 -0700 | [diff] [blame] | 776 | return; |
Andrzej Pietrasiewicz | 83210e5 | 2015-03-20 08:18:47 +0100 | [diff] [blame] | 777 | params->state = RNDIS_UNINITIALIZED; |
David Brownell | 486e2df | 2005-05-24 17:51:52 -0700 | [diff] [blame] | 778 | |
| 779 | /* drain the response queue */ |
Andrzej Pietrasiewicz | 83210e5 | 2015-03-20 08:18:47 +0100 | [diff] [blame] | 780 | while ((buf = rndis_get_next_response(params, &length))) |
| 781 | rndis_free_response(params, buf); |
David Brownell | 340600a | 2005-04-28 13:45:25 -0700 | [diff] [blame] | 782 | } |
Felipe Balbi | 0700faa | 2014-04-01 13:19:32 -0500 | [diff] [blame] | 783 | EXPORT_SYMBOL_GPL(rndis_uninit); |
David Brownell | 340600a | 2005-04-28 13:45:25 -0700 | [diff] [blame] | 784 | |
Andrzej Pietrasiewicz | 83210e5 | 2015-03-20 08:18:47 +0100 | [diff] [blame] | 785 | void rndis_set_host_mac(struct rndis_params *params, const u8 *addr) |
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 | params->host_mac = addr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 788 | } |
Felipe Balbi | 0700faa | 2014-04-01 13:19:32 -0500 | [diff] [blame] | 789 | EXPORT_SYMBOL_GPL(rndis_set_host_mac); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 790 | |
David Brownell | 7e27f18 | 2006-06-13 09:54:40 -0700 | [diff] [blame] | 791 | /* |
| 792 | * Message Parser |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 793 | */ |
Andrzej Pietrasiewicz | 83210e5 | 2015-03-20 08:18:47 +0100 | [diff] [blame] | 794 | int rndis_msg_parser(struct rndis_params *params, u8 *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 795 | { |
| 796 | u32 MsgType, MsgLength; |
| 797 | __le32 *tmp; |
David Brownell | 7e27f18 | 2006-06-13 09:54:40 -0700 | [diff] [blame] | 798 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 799 | if (!buf) |
| 800 | return -ENOMEM; |
David Brownell | 7e27f18 | 2006-06-13 09:54:40 -0700 | [diff] [blame] | 801 | |
Mihai Donțu | a1df4e4 | 2010-09-08 02:54:02 +0300 | [diff] [blame] | 802 | tmp = (__le32 *)buf; |
Harvey Harrison | a5abdea | 2008-04-29 01:03:40 -0700 | [diff] [blame] | 803 | MsgType = get_unaligned_le32(tmp++); |
| 804 | MsgLength = get_unaligned_le32(tmp++); |
David Brownell | 7e27f18 | 2006-06-13 09:54:40 -0700 | [diff] [blame] | 805 | |
Andrzej Pietrasiewicz | 83210e5 | 2015-03-20 08:18:47 +0100 | [diff] [blame] | 806 | if (!params) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 807 | return -ENOTSUPP; |
David Brownell | 7e27f18 | 2006-06-13 09:54:40 -0700 | [diff] [blame] | 808 | |
David Brownell | 340600a | 2005-04-28 13:45:25 -0700 | [diff] [blame] | 809 | /* NOTE: RNDIS is *EXTREMELY* chatty ... Windows constantly polls for |
| 810 | * rx/tx statistics and link status, in addition to KEEPALIVE traffic |
| 811 | * and normal HC level polling to see if there's any IN traffic. |
| 812 | */ |
| 813 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 814 | /* For USB: responses may take up to 10 seconds */ |
David Brownell | 340600a | 2005-04-28 13:45:25 -0700 | [diff] [blame] | 815 | switch (MsgType) { |
Linus Walleij | 5149116 | 2012-05-11 22:17:07 +0000 | [diff] [blame] | 816 | case RNDIS_MSG_INIT: |
Mayank Rana | 057e475 | 2017-09-20 13:55:11 -0700 | [diff] [blame] | 817 | pr_debug("%s: RNDIS_MSG_INIT\n", __func__); |
| 818 | tmp++; /* to get RequestID */ |
| 819 | params->host_rndis_major_ver = get_unaligned_le32(tmp++); |
| 820 | params->host_rndis_minor_ver = get_unaligned_le32(tmp++); |
| 821 | params->dl_max_xfer_size = get_unaligned_le32(tmp++); |
| 822 | |
| 823 | pr_debug("%s(): RNDIS Host Major:%d Minor:%d version\n", |
| 824 | __func__, params->host_rndis_major_ver, |
| 825 | params->host_rndis_minor_ver); |
| 826 | pr_debug("%s(): DL Max Transfer size:%x\n", |
| 827 | __func__, params->dl_max_xfer_size); |
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__); |
Hemant Kumar | 8b06029 | 2016-12-06 15:58:20 -0800 | [diff] [blame] | 834 | if (params->state == RNDIS_DATA_INITIALIZED) { |
| 835 | if (params->flow_ctrl_enable) { |
| 836 | params->flow_ctrl_enable(true, params); |
| 837 | } else { |
| 838 | if (params->dev) { |
| 839 | netif_carrier_off(params->dev); |
| 840 | netif_stop_queue(params->dev); |
| 841 | } |
| 842 | } |
| 843 | params->state = RNDIS_UNINITIALIZED; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 844 | } |
| 845 | return 0; |
David Brownell | 7e27f18 | 2006-06-13 09:54:40 -0700 | [diff] [blame] | 846 | |
Linus Walleij | 5149116 | 2012-05-11 22:17:07 +0000 | [diff] [blame] | 847 | case RNDIS_MSG_QUERY: |
Andrzej Pietrasiewicz | 83210e5 | 2015-03-20 08:18:47 +0100 | [diff] [blame] | 848 | return rndis_query_response(params, |
Mihai Donțu | a1df4e4 | 2010-09-08 02:54:02 +0300 | [diff] [blame] | 849 | (rndis_query_msg_type *)buf); |
David Brownell | 7e27f18 | 2006-06-13 09:54:40 -0700 | [diff] [blame] | 850 | |
Linus Walleij | 5149116 | 2012-05-11 22:17:07 +0000 | [diff] [blame] | 851 | case RNDIS_MSG_SET: |
Andrzej Pietrasiewicz | 83210e5 | 2015-03-20 08:18:47 +0100 | [diff] [blame] | 852 | return rndis_set_response(params, (rndis_set_msg_type *)buf); |
David Brownell | 7e27f18 | 2006-06-13 09:54:40 -0700 | [diff] [blame] | 853 | |
Linus Walleij | 5149116 | 2012-05-11 22:17:07 +0000 | [diff] [blame] | 854 | case RNDIS_MSG_RESET: |
| 855 | pr_debug("%s: RNDIS_MSG_RESET\n", |
Mihai Donțu | a1df4e4 | 2010-09-08 02:54:02 +0300 | [diff] [blame] | 856 | __func__); |
Andrzej Pietrasiewicz | 83210e5 | 2015-03-20 08:18:47 +0100 | [diff] [blame] | 857 | return rndis_reset_response(params, |
Mihai Donțu | a1df4e4 | 2010-09-08 02:54:02 +0300 | [diff] [blame] | 858 | (rndis_reset_msg_type *)buf); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 859 | |
Linus Walleij | 5149116 | 2012-05-11 22:17:07 +0000 | [diff] [blame] | 860 | case RNDIS_MSG_KEEPALIVE: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 861 | /* For USB: host does this every 5 seconds */ |
David Brownell | 340600a | 2005-04-28 13:45:25 -0700 | [diff] [blame] | 862 | if (rndis_debug > 1) |
Linus Walleij | 5149116 | 2012-05-11 22:17:07 +0000 | [diff] [blame] | 863 | pr_debug("%s: RNDIS_MSG_KEEPALIVE\n", |
Mihai Donțu | a1df4e4 | 2010-09-08 02:54:02 +0300 | [diff] [blame] | 864 | __func__); |
Andrzej Pietrasiewicz | 83210e5 | 2015-03-20 08:18:47 +0100 | [diff] [blame] | 865 | return rndis_keepalive_response(params, |
David Brownell | 7e27f18 | 2006-06-13 09:54:40 -0700 | [diff] [blame] | 866 | (rndis_keepalive_msg_type *) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 867 | buf); |
David Brownell | 7e27f18 | 2006-06-13 09:54:40 -0700 | [diff] [blame] | 868 | |
| 869 | default: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 870 | /* At least Windows XP emits some undefined RNDIS messages. |
| 871 | * In one case those messages seemed to relate to the host |
| 872 | * suspending itself. |
| 873 | */ |
David Brownell | 0027492 | 2007-11-19 12:58:36 -0800 | [diff] [blame] | 874 | pr_warning("%s: unknown RNDIS message 0x%08X len %d\n", |
Mihai Donțu | a1df4e4 | 2010-09-08 02:54:02 +0300 | [diff] [blame] | 875 | __func__, MsgType, MsgLength); |
Andy Shevchenko | d3091cf | 2012-08-07 19:07:58 +0300 | [diff] [blame] | 876 | print_hex_dump_bytes(__func__, DUMP_PREFIX_OFFSET, |
| 877 | buf, MsgLength); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 878 | break; |
| 879 | } |
David Brownell | 7e27f18 | 2006-06-13 09:54:40 -0700 | [diff] [blame] | 880 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 881 | return -ENOTSUPP; |
| 882 | } |
Felipe Balbi | 0700faa | 2014-04-01 13:19:32 -0500 | [diff] [blame] | 883 | EXPORT_SYMBOL_GPL(rndis_msg_parser); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 884 | |
Andrzej Pietrasiewicz | d6d2292 | 2015-02-06 13:43:30 +0100 | [diff] [blame] | 885 | static inline int rndis_get_nr(void) |
| 886 | { |
| 887 | return ida_simple_get(&rndis_ida, 0, 0, GFP_KERNEL); |
| 888 | } |
| 889 | |
| 890 | static inline void rndis_put_nr(int nr) |
| 891 | { |
| 892 | ida_simple_remove(&rndis_ida, nr); |
| 893 | } |
| 894 | |
Hemant Kumar | 8b06029 | 2016-12-06 15:58:20 -0800 | [diff] [blame] | 895 | struct rndis_params *rndis_register(void (*resp_avail)(void *v), void *v, |
| 896 | void (*flow_ctrl_enable)(bool enable, struct rndis_params *params)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 897 | { |
Andrzej Pietrasiewicz | d6d2292 | 2015-02-06 13:43:30 +0100 | [diff] [blame] | 898 | struct rndis_params *params; |
Andrzej Pietrasiewicz | 81dff86 | 2015-05-18 17:40:04 +0200 | [diff] [blame] | 899 | int i; |
David Brownell | 7e27f18 | 2006-06-13 09:54:40 -0700 | [diff] [blame] | 900 | |
David Brownell | 15b2d2b | 2008-06-19 18:19:16 -0700 | [diff] [blame] | 901 | if (!resp_avail) |
Andrzej Pietrasiewicz | 83210e5 | 2015-03-20 08:18:47 +0100 | [diff] [blame] | 902 | return ERR_PTR(-EINVAL); |
David Brownell | 15b2d2b | 2008-06-19 18:19:16 -0700 | [diff] [blame] | 903 | |
Andrzej Pietrasiewicz | d6d2292 | 2015-02-06 13:43:30 +0100 | [diff] [blame] | 904 | i = rndis_get_nr(); |
| 905 | if (i < 0) { |
| 906 | pr_debug("failed\n"); |
| 907 | |
| 908 | return ERR_PTR(-ENODEV); |
| 909 | } |
| 910 | |
| 911 | params = kzalloc(sizeof(*params), GFP_KERNEL); |
| 912 | if (!params) { |
| 913 | rndis_put_nr(i); |
| 914 | |
| 915 | return ERR_PTR(-ENOMEM); |
| 916 | } |
| 917 | |
| 918 | #ifdef CONFIG_USB_GADGET_DEBUG_FILES |
| 919 | { |
| 920 | struct proc_dir_entry *proc_entry; |
| 921 | char name[20]; |
| 922 | |
| 923 | sprintf(name, NAME_TEMPLATE, i); |
| 924 | proc_entry = proc_create_data(name, 0660, NULL, |
| 925 | &rndis_proc_fops, params); |
| 926 | if (!proc_entry) { |
| 927 | kfree(params); |
| 928 | rndis_put_nr(i); |
| 929 | |
| 930 | return ERR_PTR(-EIO); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 931 | } |
| 932 | } |
Andrzej Pietrasiewicz | d6d2292 | 2015-02-06 13:43:30 +0100 | [diff] [blame] | 933 | #endif |
David Brownell | 7e27f18 | 2006-06-13 09:54:40 -0700 | [diff] [blame] | 934 | |
Andrzej Pietrasiewicz | d6d2292 | 2015-02-06 13:43:30 +0100 | [diff] [blame] | 935 | params->confignr = i; |
| 936 | params->used = 1; |
| 937 | params->state = RNDIS_UNINITIALIZED; |
| 938 | params->media_state = RNDIS_MEDIA_STATE_DISCONNECTED; |
| 939 | params->resp_avail = resp_avail; |
Hemant Kumar | 8b06029 | 2016-12-06 15:58:20 -0800 | [diff] [blame] | 940 | params->flow_ctrl_enable = flow_ctrl_enable; |
Andrzej Pietrasiewicz | d6d2292 | 2015-02-06 13:43:30 +0100 | [diff] [blame] | 941 | params->v = v; |
Geliang Tang | f6281af | 2015-12-19 00:34:33 +0800 | [diff] [blame] | 942 | INIT_LIST_HEAD(¶ms->resp_queue); |
Andrzej Pietrasiewicz | d6d2292 | 2015-02-06 13:43:30 +0100 | [diff] [blame] | 943 | pr_debug("%s: configNr = %d\n", __func__, i); |
| 944 | |
| 945 | return params; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 946 | } |
Felipe Balbi | 0700faa | 2014-04-01 13:19:32 -0500 | [diff] [blame] | 947 | EXPORT_SYMBOL_GPL(rndis_register); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 948 | |
Andrzej Pietrasiewicz | 83210e5 | 2015-03-20 08:18:47 +0100 | [diff] [blame] | 949 | void rndis_deregister(struct rndis_params *params) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 950 | { |
Andrzej Pietrasiewicz | 81dff86 | 2015-05-18 17:40:04 +0200 | [diff] [blame] | 951 | int i; |
Andrzej Pietrasiewicz | d6d2292 | 2015-02-06 13:43:30 +0100 | [diff] [blame] | 952 | |
Mihai Donțu | a1df4e4 | 2010-09-08 02:54:02 +0300 | [diff] [blame] | 953 | pr_debug("%s:\n", __func__); |
David Brownell | 7e27f18 | 2006-06-13 09:54:40 -0700 | [diff] [blame] | 954 | |
Andrzej Pietrasiewicz | 83210e5 | 2015-03-20 08:18:47 +0100 | [diff] [blame] | 955 | if (!params) |
| 956 | return; |
Andrzej Pietrasiewicz | d6d2292 | 2015-02-06 13:43:30 +0100 | [diff] [blame] | 957 | |
| 958 | i = params->confignr; |
| 959 | |
| 960 | #ifdef CONFIG_USB_GADGET_DEBUG_FILES |
| 961 | { |
Andrzej Pietrasiewicz | d6d2292 | 2015-02-06 13:43:30 +0100 | [diff] [blame] | 962 | char name[20]; |
| 963 | |
| 964 | sprintf(name, NAME_TEMPLATE, i); |
| 965 | remove_proc_entry(name, NULL); |
| 966 | } |
| 967 | #endif |
| 968 | |
| 969 | kfree(params); |
| 970 | rndis_put_nr(i); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 971 | } |
Felipe Balbi | 0700faa | 2014-04-01 13:19:32 -0500 | [diff] [blame] | 972 | EXPORT_SYMBOL_GPL(rndis_deregister); |
Andrzej Pietrasiewicz | 83210e5 | 2015-03-20 08:18:47 +0100 | [diff] [blame] | 973 | int rndis_set_param_dev(struct rndis_params *params, struct net_device *dev, |
| 974 | u16 *cdc_filter) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 975 | { |
David Brownell | 33376c1 | 2008-08-18 17:45:07 -0700 | [diff] [blame] | 976 | pr_debug("%s:\n", __func__); |
David Brownell | 15b2d2b | 2008-06-19 18:19:16 -0700 | [diff] [blame] | 977 | if (!dev) |
| 978 | return -EINVAL; |
Andrzej Pietrasiewicz | 83210e5 | 2015-03-20 08:18:47 +0100 | [diff] [blame] | 979 | if (!params) |
| 980 | return -1; |
David Brownell | 7e27f18 | 2006-06-13 09:54:40 -0700 | [diff] [blame] | 981 | |
Andrzej Pietrasiewicz | 83210e5 | 2015-03-20 08:18:47 +0100 | [diff] [blame] | 982 | params->dev = dev; |
| 983 | params->filter = cdc_filter; |
David Brownell | 7e27f18 | 2006-06-13 09:54:40 -0700 | [diff] [blame] | 984 | |
xerox_lin | 72ffa18 | 2014-08-14 14:48:44 +0800 | [diff] [blame] | 985 | rndis_ul_max_xfer_size_rcvd = 0; |
| 986 | rndis_ul_max_pkt_per_xfer_rcvd = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 987 | return 0; |
| 988 | } |
Felipe Balbi | 0700faa | 2014-04-01 13:19:32 -0500 | [diff] [blame] | 989 | EXPORT_SYMBOL_GPL(rndis_set_param_dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 990 | |
Andrzej Pietrasiewicz | 83210e5 | 2015-03-20 08:18:47 +0100 | [diff] [blame] | 991 | int rndis_set_param_vendor(struct rndis_params *params, u32 vendorID, |
| 992 | const char *vendorDescr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 993 | { |
David Brownell | 33376c1 | 2008-08-18 17:45:07 -0700 | [diff] [blame] | 994 | pr_debug("%s:\n", __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 995 | if (!vendorDescr) return -1; |
Andrzej Pietrasiewicz | 83210e5 | 2015-03-20 08:18:47 +0100 | [diff] [blame] | 996 | if (!params) |
| 997 | return -1; |
David Brownell | 7e27f18 | 2006-06-13 09:54:40 -0700 | [diff] [blame] | 998 | |
Andrzej Pietrasiewicz | 83210e5 | 2015-03-20 08:18:47 +0100 | [diff] [blame] | 999 | params->vendorID = vendorID; |
| 1000 | params->vendorDescr = vendorDescr; |
David Brownell | 7e27f18 | 2006-06-13 09:54:40 -0700 | [diff] [blame] | 1001 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1002 | return 0; |
| 1003 | } |
Felipe Balbi | 0700faa | 2014-04-01 13:19:32 -0500 | [diff] [blame] | 1004 | EXPORT_SYMBOL_GPL(rndis_set_param_vendor); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1005 | |
Andrzej Pietrasiewicz | 83210e5 | 2015-03-20 08:18:47 +0100 | [diff] [blame] | 1006 | 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] | 1007 | { |
David Brownell | 33376c1 | 2008-08-18 17:45:07 -0700 | [diff] [blame] | 1008 | pr_debug("%s: %u %u\n", __func__, medium, speed); |
Andrzej Pietrasiewicz | 83210e5 | 2015-03-20 08:18:47 +0100 | [diff] [blame] | 1009 | if (!params) |
| 1010 | return -1; |
David Brownell | 7e27f18 | 2006-06-13 09:54:40 -0700 | [diff] [blame] | 1011 | |
Andrzej Pietrasiewicz | 83210e5 | 2015-03-20 08:18:47 +0100 | [diff] [blame] | 1012 | params->medium = medium; |
| 1013 | params->speed = speed; |
David Brownell | 7e27f18 | 2006-06-13 09:54:40 -0700 | [diff] [blame] | 1014 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1015 | return 0; |
| 1016 | } |
Felipe Balbi | 0700faa | 2014-04-01 13:19:32 -0500 | [diff] [blame] | 1017 | EXPORT_SYMBOL_GPL(rndis_set_param_medium); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1018 | |
Chandana Kishori Chiluveru | 50a2184 | 2017-11-06 14:54:24 +0530 | [diff] [blame] | 1019 | u32 rndis_get_dl_max_xfer_size(struct rndis_params *params) |
| 1020 | { |
| 1021 | pr_debug("%s:\n", __func__); |
| 1022 | return params->dl_max_xfer_size; |
| 1023 | } |
| 1024 | |
| 1025 | u32 rndis_get_ul_max_xfer_size(struct rndis_params *params) |
| 1026 | { |
| 1027 | pr_debug("%s:\n", __func__); |
| 1028 | return params->ul_max_xfer_size; |
| 1029 | } |
| 1030 | |
Amit Pundir | d29237a | 2015-12-21 14:03:15 +0530 | [diff] [blame] | 1031 | void rndis_set_max_pkt_xfer(struct rndis_params *params, u8 max_pkt_per_xfer) |
xerox_lin | 72ffa18 | 2014-08-14 14:48:44 +0800 | [diff] [blame] | 1032 | { |
| 1033 | pr_debug("%s:\n", __func__); |
| 1034 | |
Amit Pundir | d29237a | 2015-12-21 14:03:15 +0530 | [diff] [blame] | 1035 | params->max_pkt_per_xfer = max_pkt_per_xfer; |
xerox_lin | 72ffa18 | 2014-08-14 14:48:44 +0800 | [diff] [blame] | 1036 | } |
| 1037 | |
Hemant Kumar | 8b06029 | 2016-12-06 15:58:20 -0800 | [diff] [blame] | 1038 | /** |
| 1039 | * rndis_flow_control: enable/disable flow control with USB RNDIS interface |
| 1040 | * params - RNDIS network parameter |
| 1041 | * enable_flow_control - true: perform flow control, false: disable flow control |
| 1042 | * |
| 1043 | * In hw accelerated mode, this function triggers functionality to start/stop |
| 1044 | * endless transfers, otherwise it enables/disables RNDIS network interface. |
| 1045 | */ |
| 1046 | void rndis_flow_control(struct rndis_params *params, bool enable_flow_control) |
| 1047 | { |
| 1048 | if (!params) { |
| 1049 | pr_err("%s: failed, params NULL\n", __func__); |
| 1050 | return; |
| 1051 | } |
| 1052 | |
| 1053 | pr_debug("%s(): params->state:%x\n", __func__, params->state); |
| 1054 | |
| 1055 | if (enable_flow_control) { |
| 1056 | if (params->state == RNDIS_DATA_INITIALIZED) { |
| 1057 | if (params->flow_ctrl_enable) { |
| 1058 | params->flow_ctrl_enable(enable_flow_control, |
| 1059 | params); |
| 1060 | } else { |
| 1061 | netif_carrier_off(params->dev); |
| 1062 | netif_stop_queue(params->dev); |
| 1063 | } |
| 1064 | } |
| 1065 | params->state = RNDIS_INITIALIZED; |
| 1066 | } else { |
| 1067 | if (params->state != RNDIS_DATA_INITIALIZED) { |
| 1068 | if (params->flow_ctrl_enable) { |
| 1069 | params->flow_ctrl_enable(enable_flow_control, |
| 1070 | params); |
| 1071 | } else { |
| 1072 | netif_carrier_on(params->dev); |
| 1073 | if (netif_running(params->dev)) |
| 1074 | netif_wake_queue(params->dev); |
| 1075 | } |
| 1076 | } |
| 1077 | params->state = RNDIS_DATA_INITIALIZED; |
| 1078 | } |
| 1079 | } |
| 1080 | |
Mihai Donțu | a1df4e4 | 2010-09-08 02:54:02 +0300 | [diff] [blame] | 1081 | void rndis_add_hdr(struct sk_buff *skb) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1082 | { |
Mihai Donțu | a1df4e4 | 2010-09-08 02:54:02 +0300 | [diff] [blame] | 1083 | struct rndis_packet_msg_type *header; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1084 | |
| 1085 | if (!skb) |
| 1086 | return; |
Mihai Donțu | a1df4e4 | 2010-09-08 02:54:02 +0300 | [diff] [blame] | 1087 | header = (void *)skb_push(skb, sizeof(*header)); |
| 1088 | memset(header, 0, sizeof *header); |
Linus Walleij | 5149116 | 2012-05-11 22:17:07 +0000 | [diff] [blame] | 1089 | header->MessageType = cpu_to_le32(RNDIS_MSG_PACKET); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1090 | header->MessageLength = cpu_to_le32(skb->len); |
Mihai Donțu | a1df4e4 | 2010-09-08 02:54:02 +0300 | [diff] [blame] | 1091 | header->DataOffset = cpu_to_le32(36); |
| 1092 | header->DataLength = cpu_to_le32(skb->len - sizeof(*header)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1093 | } |
Felipe Balbi | 0700faa | 2014-04-01 13:19:32 -0500 | [diff] [blame] | 1094 | EXPORT_SYMBOL_GPL(rndis_add_hdr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1095 | |
Andrzej Pietrasiewicz | 83210e5 | 2015-03-20 08:18:47 +0100 | [diff] [blame] | 1096 | void rndis_free_response(struct rndis_params *params, u8 *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1097 | { |
Geliang Tang | f6281af | 2015-12-19 00:34:33 +0800 | [diff] [blame] | 1098 | rndis_resp_t *r, *n; |
David Brownell | 7e27f18 | 2006-06-13 09:54:40 -0700 | [diff] [blame] | 1099 | |
Geliang Tang | f6281af | 2015-12-19 00:34:33 +0800 | [diff] [blame] | 1100 | list_for_each_entry_safe(r, n, ¶ms->resp_queue, list) { |
Julia Lawall | 1c17a35 | 2016-01-25 16:21:54 +0100 | [diff] [blame] | 1101 | if (r->buf == buf) { |
Mihai Donțu | a1df4e4 | 2010-09-08 02:54:02 +0300 | [diff] [blame] | 1102 | list_del(&r->list); |
| 1103 | kfree(r); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1104 | } |
| 1105 | } |
| 1106 | } |
Felipe Balbi | 0700faa | 2014-04-01 13:19:32 -0500 | [diff] [blame] | 1107 | EXPORT_SYMBOL_GPL(rndis_free_response); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1108 | |
Andrzej Pietrasiewicz | 83210e5 | 2015-03-20 08:18:47 +0100 | [diff] [blame] | 1109 | u8 *rndis_get_next_response(struct rndis_params *params, u32 *length) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1110 | { |
Geliang Tang | f6281af | 2015-12-19 00:34:33 +0800 | [diff] [blame] | 1111 | rndis_resp_t *r, *n; |
David Brownell | 7e27f18 | 2006-06-13 09:54:40 -0700 | [diff] [blame] | 1112 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1113 | if (!length) return NULL; |
David Brownell | 7e27f18 | 2006-06-13 09:54:40 -0700 | [diff] [blame] | 1114 | |
Geliang Tang | f6281af | 2015-12-19 00:34:33 +0800 | [diff] [blame] | 1115 | list_for_each_entry_safe(r, n, ¶ms->resp_queue, list) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1116 | if (!r->send) { |
| 1117 | r->send = 1; |
| 1118 | *length = r->length; |
| 1119 | return r->buf; |
| 1120 | } |
| 1121 | } |
David Brownell | 7e27f18 | 2006-06-13 09:54:40 -0700 | [diff] [blame] | 1122 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1123 | return NULL; |
| 1124 | } |
Felipe Balbi | 0700faa | 2014-04-01 13:19:32 -0500 | [diff] [blame] | 1125 | EXPORT_SYMBOL_GPL(rndis_get_next_response); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1126 | |
Andrzej Pietrasiewicz | 83210e5 | 2015-03-20 08:18:47 +0100 | [diff] [blame] | 1127 | 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] | 1128 | { |
Mihai Donțu | a1df4e4 | 2010-09-08 02:54:02 +0300 | [diff] [blame] | 1129 | rndis_resp_t *r; |
David Brownell | 7e27f18 | 2006-06-13 09:54:40 -0700 | [diff] [blame] | 1130 | |
Mihai Donțu | a1df4e4 | 2010-09-08 02:54:02 +0300 | [diff] [blame] | 1131 | /* NOTE: this gets copied into ether.c USB_BUFSIZ bytes ... */ |
| 1132 | r = kmalloc(sizeof(rndis_resp_t) + length, GFP_ATOMIC); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1133 | if (!r) return NULL; |
David Brownell | 7e27f18 | 2006-06-13 09:54:40 -0700 | [diff] [blame] | 1134 | |
Mihai Donțu | a1df4e4 | 2010-09-08 02:54:02 +0300 | [diff] [blame] | 1135 | r->buf = (u8 *)(r + 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1136 | r->length = length; |
| 1137 | r->send = 0; |
David Brownell | 7e27f18 | 2006-06-13 09:54:40 -0700 | [diff] [blame] | 1138 | |
Geliang Tang | f6281af | 2015-12-19 00:34:33 +0800 | [diff] [blame] | 1139 | list_add_tail(&r->list, ¶ms->resp_queue); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1140 | return r; |
| 1141 | } |
| 1142 | |
Brian Niebuhr | 9b39e9d | 2009-08-14 10:04:22 -0500 | [diff] [blame] | 1143 | int rndis_rm_hdr(struct gether *port, |
| 1144 | struct sk_buff *skb, |
| 1145 | struct sk_buff_head *list) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1146 | { |
xerox_lin | 72ffa18 | 2014-08-14 14:48:44 +0800 | [diff] [blame] | 1147 | int num_pkts = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1148 | |
xerox_lin | 72ffa18 | 2014-08-14 14:48:44 +0800 | [diff] [blame] | 1149 | if (skb->len > rndis_ul_max_xfer_size_rcvd) |
| 1150 | rndis_ul_max_xfer_size_rcvd = skb->len; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1151 | |
xerox_lin | 72ffa18 | 2014-08-14 14:48:44 +0800 | [diff] [blame] | 1152 | while (skb->len) { |
| 1153 | struct rndis_packet_msg_type *hdr; |
| 1154 | struct sk_buff *skb2; |
| 1155 | u32 msg_len, data_offset, data_len; |
| 1156 | |
| 1157 | /* some rndis hosts send extra byte to avoid zlp, ignore it */ |
| 1158 | if (skb->len == 1) { |
| 1159 | dev_kfree_skb_any(skb); |
| 1160 | return 0; |
| 1161 | } |
| 1162 | |
| 1163 | if (skb->len < sizeof *hdr) { |
Amit Pundir | 928b59a | 2015-12-30 03:05:44 +0530 | [diff] [blame] | 1164 | pr_err("invalid rndis pkt: skblen:%u hdr_len:%zu", |
xerox_lin | 72ffa18 | 2014-08-14 14:48:44 +0800 | [diff] [blame] | 1165 | skb->len, sizeof *hdr); |
| 1166 | dev_kfree_skb_any(skb); |
| 1167 | return -EINVAL; |
| 1168 | } |
| 1169 | |
| 1170 | hdr = (void *)skb->data; |
| 1171 | msg_len = le32_to_cpu(hdr->MessageLength); |
| 1172 | data_offset = le32_to_cpu(hdr->DataOffset); |
| 1173 | data_len = le32_to_cpu(hdr->DataLength); |
| 1174 | |
| 1175 | if (skb->len < msg_len || |
| 1176 | ((data_offset + data_len + 8) > msg_len)) { |
| 1177 | pr_err("invalid rndis message: %d/%d/%d/%d, len:%d\n", |
| 1178 | le32_to_cpu(hdr->MessageType), |
| 1179 | msg_len, data_offset, data_len, skb->len); |
| 1180 | dev_kfree_skb_any(skb); |
| 1181 | return -EOVERFLOW; |
| 1182 | } |
| 1183 | if (le32_to_cpu(hdr->MessageType) != RNDIS_MSG_PACKET) { |
| 1184 | pr_err("invalid rndis message: %d/%d/%d/%d, len:%d\n", |
| 1185 | le32_to_cpu(hdr->MessageType), |
| 1186 | msg_len, data_offset, data_len, skb->len); |
| 1187 | dev_kfree_skb_any(skb); |
| 1188 | return -EINVAL; |
| 1189 | } |
| 1190 | |
| 1191 | skb_pull(skb, data_offset + 8); |
| 1192 | |
| 1193 | if (msg_len == skb->len) { |
| 1194 | skb_trim(skb, data_len); |
| 1195 | break; |
| 1196 | } |
| 1197 | |
| 1198 | skb2 = skb_clone(skb, GFP_ATOMIC); |
| 1199 | if (!skb2) { |
| 1200 | pr_err("%s:skb clone failed\n", __func__); |
| 1201 | dev_kfree_skb_any(skb); |
| 1202 | return -ENOMEM; |
| 1203 | } |
| 1204 | |
| 1205 | skb_pull(skb, msg_len - sizeof *hdr); |
| 1206 | skb_trim(skb2, data_len); |
| 1207 | skb_queue_tail(list, skb2); |
| 1208 | |
| 1209 | num_pkts++; |
Brian Niebuhr | 9b39e9d | 2009-08-14 10:04:22 -0500 | [diff] [blame] | 1210 | } |
xerox_lin | 72ffa18 | 2014-08-14 14:48:44 +0800 | [diff] [blame] | 1211 | |
| 1212 | if (num_pkts > rndis_ul_max_pkt_per_xfer_rcvd) |
| 1213 | rndis_ul_max_pkt_per_xfer_rcvd = num_pkts; |
David Brownell | 6cdee10 | 2005-04-18 17:39:34 -0700 | [diff] [blame] | 1214 | |
Brian Niebuhr | 9b39e9d | 2009-08-14 10:04:22 -0500 | [diff] [blame] | 1215 | skb_queue_tail(list, skb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1216 | return 0; |
| 1217 | } |
Felipe Balbi | 0700faa | 2014-04-01 13:19:32 -0500 | [diff] [blame] | 1218 | EXPORT_SYMBOL_GPL(rndis_rm_hdr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1219 | |
Hemant Kumar | 6ccd55c | 2016-02-01 18:54:16 -0800 | [diff] [blame] | 1220 | void rndis_set_pkt_alignment_factor(struct rndis_params *params, |
| 1221 | u8 pkt_alignment_factor) |
| 1222 | { |
| 1223 | pr_debug("%s:\n", __func__); |
| 1224 | |
| 1225 | if (!params) { |
| 1226 | pr_err("%s: failed, params NULL\n", __func__); |
| 1227 | return; |
| 1228 | } |
| 1229 | |
| 1230 | params->pkt_alignment_factor = pkt_alignment_factor; |
| 1231 | } |
| 1232 | |
Mihai Donțu | a1df4e4 | 2010-09-08 02:54:02 +0300 | [diff] [blame] | 1233 | #ifdef CONFIG_USB_GADGET_DEBUG_FILES |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1234 | |
Alexey Dobriyan | e184d5f | 2008-05-14 16:25:13 -0700 | [diff] [blame] | 1235 | static int rndis_proc_show(struct seq_file *m, void *v) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1236 | { |
Alexey Dobriyan | e184d5f | 2008-05-14 16:25:13 -0700 | [diff] [blame] | 1237 | rndis_params *param = m->private; |
David Brownell | 7e27f18 | 2006-06-13 09:54:40 -0700 | [diff] [blame] | 1238 | |
Alexey Dobriyan | e184d5f | 2008-05-14 16:25:13 -0700 | [diff] [blame] | 1239 | seq_printf(m, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1240 | "Config Nr. %d\n" |
| 1241 | "used : %s\n" |
| 1242 | "state : %s\n" |
| 1243 | "medium : 0x%08X\n" |
| 1244 | "speed : %d\n" |
| 1245 | "cable : %s\n" |
| 1246 | "vendor ID : 0x%08X\n" |
David Brownell | 7e27f18 | 2006-06-13 09:54:40 -0700 | [diff] [blame] | 1247 | "vendor : %s\n", |
| 1248 | param->confignr, (param->used) ? "y" : "n", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1249 | ({ char *s = "?"; |
| 1250 | switch (param->state) { |
| 1251 | case RNDIS_UNINITIALIZED: |
| 1252 | s = "RNDIS_UNINITIALIZED"; break; |
| 1253 | case RNDIS_INITIALIZED: |
| 1254 | s = "RNDIS_INITIALIZED"; break; |
| 1255 | case RNDIS_DATA_INITIALIZED: |
| 1256 | s = "RNDIS_DATA_INITIALIZED"; break; |
Joe Perches | 2b84f92 | 2013-10-08 16:01:37 -0700 | [diff] [blame] | 1257 | } s; }), |
David Brownell | 7e27f18 | 2006-06-13 09:54:40 -0700 | [diff] [blame] | 1258 | param->medium, |
| 1259 | (param->media_state) ? 0 : param->speed*100, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1260 | (param->media_state) ? "disconnected" : "connected", |
David Brownell | 7e27f18 | 2006-06-13 09:54:40 -0700 | [diff] [blame] | 1261 | param->vendorID, param->vendorDescr); |
Alexey Dobriyan | e184d5f | 2008-05-14 16:25:13 -0700 | [diff] [blame] | 1262 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1263 | } |
| 1264 | |
Alexey Dobriyan | e184d5f | 2008-05-14 16:25:13 -0700 | [diff] [blame] | 1265 | 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] | 1266 | size_t count, loff_t *ppos) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1267 | { |
Al Viro | d9dda78 | 2013-03-31 18:16:14 -0400 | [diff] [blame] | 1268 | rndis_params *p = PDE_DATA(file_inode(file)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1269 | u32 speed = 0; |
| 1270 | int i, fl_speed = 0; |
David Brownell | 7e27f18 | 2006-06-13 09:54:40 -0700 | [diff] [blame] | 1271 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1272 | for (i = 0; i < count; i++) { |
| 1273 | char c; |
| 1274 | if (get_user(c, buffer)) |
| 1275 | return -EFAULT; |
| 1276 | switch (c) { |
| 1277 | case '0': |
| 1278 | case '1': |
| 1279 | case '2': |
| 1280 | case '3': |
| 1281 | case '4': |
| 1282 | case '5': |
| 1283 | case '6': |
| 1284 | case '7': |
| 1285 | case '8': |
| 1286 | case '9': |
| 1287 | fl_speed = 1; |
Mihai Donțu | a1df4e4 | 2010-09-08 02:54:02 +0300 | [diff] [blame] | 1288 | speed = speed * 10 + c - '0'; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1289 | break; |
| 1290 | case 'C': |
| 1291 | case 'c': |
Andrzej Pietrasiewicz | 868055f | 2015-05-18 17:40:02 +0200 | [diff] [blame] | 1292 | rndis_signal_connect(p); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1293 | break; |
| 1294 | case 'D': |
| 1295 | case 'd': |
Andrzej Pietrasiewicz | 868055f | 2015-05-18 17:40:02 +0200 | [diff] [blame] | 1296 | rndis_signal_disconnect(p); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1297 | break; |
David Brownell | 7e27f18 | 2006-06-13 09:54:40 -0700 | [diff] [blame] | 1298 | default: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1299 | if (fl_speed) p->speed = speed; |
David Brownell | 33376c1 | 2008-08-18 17:45:07 -0700 | [diff] [blame] | 1300 | else pr_debug("%c is not valid\n", c); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1301 | break; |
| 1302 | } |
David Brownell | 7e27f18 | 2006-06-13 09:54:40 -0700 | [diff] [blame] | 1303 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1304 | buffer++; |
| 1305 | } |
David Brownell | 7e27f18 | 2006-06-13 09:54:40 -0700 | [diff] [blame] | 1306 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1307 | return count; |
| 1308 | } |
| 1309 | |
Alexey Dobriyan | e184d5f | 2008-05-14 16:25:13 -0700 | [diff] [blame] | 1310 | static int rndis_proc_open(struct inode *inode, struct file *file) |
| 1311 | { |
Al Viro | d9dda78 | 2013-03-31 18:16:14 -0400 | [diff] [blame] | 1312 | return single_open(file, rndis_proc_show, PDE_DATA(inode)); |
Alexey Dobriyan | e184d5f | 2008-05-14 16:25:13 -0700 | [diff] [blame] | 1313 | } |
| 1314 | |
| 1315 | static const struct file_operations rndis_proc_fops = { |
| 1316 | .owner = THIS_MODULE, |
| 1317 | .open = rndis_proc_open, |
| 1318 | .read = seq_read, |
| 1319 | .llseek = seq_lseek, |
| 1320 | .release = single_release, |
| 1321 | .write = rndis_proc_write, |
| 1322 | }; |
| 1323 | |
Mihai Donțu | a1df4e4 | 2010-09-08 02:54:02 +0300 | [diff] [blame] | 1324 | #define NAME_TEMPLATE "driver/rndis-%03d" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1325 | |
Mihai Donțu | a1df4e4 | 2010-09-08 02:54:02 +0300 | [diff] [blame] | 1326 | #endif /* CONFIG_USB_GADGET_DEBUG_FILES */ |