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