Greg Kroah-Hartman | 5fd54ac | 2017-11-03 11:28:30 +0100 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Jussi Kivilinna | 7517579 | 2008-01-26 00:51:12 +0200 | [diff] [blame] | 2 | /* |
| 3 | * Host Side support for RNDIS Networking Links |
| 4 | * Copyright (C) 2005 by David Brownell |
| 5 | * |
| 6 | * This program is free software; you can redistribute it and/or modify |
| 7 | * it under the terms of the GNU General Public License as published by |
| 8 | * the Free Software Foundation; either version 2 of the License, or |
| 9 | * (at your option) any later version. |
| 10 | * |
| 11 | * This program is distributed in the hope that it will be useful, |
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 | * GNU General Public License for more details. |
| 15 | * |
| 16 | * You should have received a copy of the GNU General Public License |
| 17 | * along with this program; if not, write to the Free Software |
| 18 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 19 | */ |
| 20 | |
Robert P. J. Day | dda43a0 | 2008-03-07 13:45:32 -0500 | [diff] [blame] | 21 | #ifndef __LINUX_USB_RNDIS_HOST_H |
| 22 | #define __LINUX_USB_RNDIS_HOST_H |
Jussi Kivilinna | 7517579 | 2008-01-26 00:51:12 +0200 | [diff] [blame] | 23 | |
Linus Walleij | 7591157 | 2012-05-11 22:15:50 +0000 | [diff] [blame] | 24 | #include <linux/rndis.h> |
| 25 | |
Jussi Kivilinna | 7517579 | 2008-01-26 00:51:12 +0200 | [diff] [blame] | 26 | /* |
| 27 | * CONTROL uses CDC "encapsulated commands" with funky notifications. |
| 28 | * - control-out: SEND_ENCAPSULATED |
| 29 | * - interrupt-in: RESPONSE_AVAILABLE |
| 30 | * - control-in: GET_ENCAPSULATED |
| 31 | * |
| 32 | * We'll try to ignore the RESPONSE_AVAILABLE notifications. |
| 33 | * |
| 34 | * REVISIT some RNDIS implementations seem to have curious issues still |
| 35 | * to be resolved. |
| 36 | */ |
| 37 | struct rndis_msg_hdr { |
| 38 | __le32 msg_type; /* RNDIS_MSG_* */ |
| 39 | __le32 msg_len; |
Greg Kroah-Hartman | 0858a3a | 2010-05-17 10:58:12 -0700 | [diff] [blame] | 40 | /* followed by data that varies between messages */ |
Jussi Kivilinna | 7517579 | 2008-01-26 00:51:12 +0200 | [diff] [blame] | 41 | __le32 request_id; |
| 42 | __le32 status; |
Greg Kroah-Hartman | 0858a3a | 2010-05-17 10:58:12 -0700 | [diff] [blame] | 43 | /* ... and more */ |
Jussi Kivilinna | 7517579 | 2008-01-26 00:51:12 +0200 | [diff] [blame] | 44 | } __attribute__ ((packed)); |
| 45 | |
| 46 | /* MS-Windows uses this strange size, but RNDIS spec says 1024 minimum */ |
| 47 | #define CONTROL_BUFFER_SIZE 1025 |
| 48 | |
| 49 | /* RNDIS defines an (absurdly huge) 10 second control timeout, |
| 50 | * but ActiveSync seems to use a more usual 5 second timeout |
| 51 | * (which matches the USB 2.0 spec). |
| 52 | */ |
| 53 | #define RNDIS_CONTROL_TIMEOUT_MS (5 * 1000) |
| 54 | |
Jussi Kivilinna | 7517579 | 2008-01-26 00:51:12 +0200 | [diff] [blame] | 55 | struct rndis_data_hdr { |
| 56 | __le32 msg_type; /* RNDIS_MSG_PACKET */ |
Greg Kroah-Hartman | 0858a3a | 2010-05-17 10:58:12 -0700 | [diff] [blame] | 57 | __le32 msg_len; /* rndis_data_hdr + data_len + pad */ |
| 58 | __le32 data_offset; /* 36 -- right after header */ |
| 59 | __le32 data_len; /* ... real packet size */ |
Jussi Kivilinna | 7517579 | 2008-01-26 00:51:12 +0200 | [diff] [blame] | 60 | |
Greg Kroah-Hartman | 0858a3a | 2010-05-17 10:58:12 -0700 | [diff] [blame] | 61 | __le32 oob_data_offset; /* zero */ |
| 62 | __le32 oob_data_len; /* zero */ |
| 63 | __le32 num_oob; /* zero */ |
| 64 | __le32 packet_data_offset; /* zero */ |
Jussi Kivilinna | 7517579 | 2008-01-26 00:51:12 +0200 | [diff] [blame] | 65 | |
Greg Kroah-Hartman | 0858a3a | 2010-05-17 10:58:12 -0700 | [diff] [blame] | 66 | __le32 packet_data_len; /* zero */ |
| 67 | __le32 vc_handle; /* zero */ |
| 68 | __le32 reserved; /* zero */ |
Jussi Kivilinna | 7517579 | 2008-01-26 00:51:12 +0200 | [diff] [blame] | 69 | } __attribute__ ((packed)); |
| 70 | |
| 71 | struct rndis_init { /* OUT */ |
Greg Kroah-Hartman | 0858a3a | 2010-05-17 10:58:12 -0700 | [diff] [blame] | 72 | /* header and: */ |
Jussi Kivilinna | 7517579 | 2008-01-26 00:51:12 +0200 | [diff] [blame] | 73 | __le32 msg_type; /* RNDIS_MSG_INIT */ |
Greg Kroah-Hartman | 0858a3a | 2010-05-17 10:58:12 -0700 | [diff] [blame] | 74 | __le32 msg_len; /* 24 */ |
Jussi Kivilinna | 7517579 | 2008-01-26 00:51:12 +0200 | [diff] [blame] | 75 | __le32 request_id; |
Greg Kroah-Hartman | 0858a3a | 2010-05-17 10:58:12 -0700 | [diff] [blame] | 76 | __le32 major_version; /* of rndis (1.0) */ |
Jussi Kivilinna | 7517579 | 2008-01-26 00:51:12 +0200 | [diff] [blame] | 77 | __le32 minor_version; |
| 78 | __le32 max_transfer_size; |
| 79 | } __attribute__ ((packed)); |
| 80 | |
| 81 | struct rndis_init_c { /* IN */ |
Greg Kroah-Hartman | 0858a3a | 2010-05-17 10:58:12 -0700 | [diff] [blame] | 82 | /* header and: */ |
Jussi Kivilinna | 7517579 | 2008-01-26 00:51:12 +0200 | [diff] [blame] | 83 | __le32 msg_type; /* RNDIS_MSG_INIT_C */ |
| 84 | __le32 msg_len; |
| 85 | __le32 request_id; |
| 86 | __le32 status; |
Greg Kroah-Hartman | 0858a3a | 2010-05-17 10:58:12 -0700 | [diff] [blame] | 87 | __le32 major_version; /* of rndis (1.0) */ |
Jussi Kivilinna | 7517579 | 2008-01-26 00:51:12 +0200 | [diff] [blame] | 88 | __le32 minor_version; |
| 89 | __le32 device_flags; |
Greg Kroah-Hartman | 0858a3a | 2010-05-17 10:58:12 -0700 | [diff] [blame] | 90 | __le32 medium; /* zero == 802.3 */ |
Jussi Kivilinna | 7517579 | 2008-01-26 00:51:12 +0200 | [diff] [blame] | 91 | __le32 max_packets_per_message; |
| 92 | __le32 max_transfer_size; |
Greg Kroah-Hartman | 0858a3a | 2010-05-17 10:58:12 -0700 | [diff] [blame] | 93 | __le32 packet_alignment; /* max 7; (1<<n) bytes */ |
| 94 | __le32 af_list_offset; /* zero */ |
| 95 | __le32 af_list_size; /* zero */ |
Jussi Kivilinna | 7517579 | 2008-01-26 00:51:12 +0200 | [diff] [blame] | 96 | } __attribute__ ((packed)); |
| 97 | |
| 98 | struct rndis_halt { /* OUT (no reply) */ |
Greg Kroah-Hartman | 0858a3a | 2010-05-17 10:58:12 -0700 | [diff] [blame] | 99 | /* header and: */ |
Jussi Kivilinna | 7517579 | 2008-01-26 00:51:12 +0200 | [diff] [blame] | 100 | __le32 msg_type; /* RNDIS_MSG_HALT */ |
| 101 | __le32 msg_len; |
| 102 | __le32 request_id; |
| 103 | } __attribute__ ((packed)); |
| 104 | |
| 105 | struct rndis_query { /* OUT */ |
Greg Kroah-Hartman | 0858a3a | 2010-05-17 10:58:12 -0700 | [diff] [blame] | 106 | /* header and: */ |
Jussi Kivilinna | 7517579 | 2008-01-26 00:51:12 +0200 | [diff] [blame] | 107 | __le32 msg_type; /* RNDIS_MSG_QUERY */ |
| 108 | __le32 msg_len; |
| 109 | __le32 request_id; |
| 110 | __le32 oid; |
| 111 | __le32 len; |
| 112 | __le32 offset; |
Greg Kroah-Hartman | 0858a3a | 2010-05-17 10:58:12 -0700 | [diff] [blame] | 113 | /*?*/ __le32 handle; /* zero */ |
Jussi Kivilinna | 7517579 | 2008-01-26 00:51:12 +0200 | [diff] [blame] | 114 | } __attribute__ ((packed)); |
| 115 | |
| 116 | struct rndis_query_c { /* IN */ |
Greg Kroah-Hartman | 0858a3a | 2010-05-17 10:58:12 -0700 | [diff] [blame] | 117 | /* header and: */ |
Jussi Kivilinna | 7517579 | 2008-01-26 00:51:12 +0200 | [diff] [blame] | 118 | __le32 msg_type; /* RNDIS_MSG_QUERY_C */ |
| 119 | __le32 msg_len; |
| 120 | __le32 request_id; |
| 121 | __le32 status; |
| 122 | __le32 len; |
| 123 | __le32 offset; |
| 124 | } __attribute__ ((packed)); |
| 125 | |
| 126 | struct rndis_set { /* OUT */ |
Greg Kroah-Hartman | 0858a3a | 2010-05-17 10:58:12 -0700 | [diff] [blame] | 127 | /* header and: */ |
Jussi Kivilinna | 7517579 | 2008-01-26 00:51:12 +0200 | [diff] [blame] | 128 | __le32 msg_type; /* RNDIS_MSG_SET */ |
| 129 | __le32 msg_len; |
| 130 | __le32 request_id; |
| 131 | __le32 oid; |
| 132 | __le32 len; |
| 133 | __le32 offset; |
Greg Kroah-Hartman | 0858a3a | 2010-05-17 10:58:12 -0700 | [diff] [blame] | 134 | /*?*/ __le32 handle; /* zero */ |
Jussi Kivilinna | 7517579 | 2008-01-26 00:51:12 +0200 | [diff] [blame] | 135 | } __attribute__ ((packed)); |
| 136 | |
| 137 | struct rndis_set_c { /* IN */ |
Greg Kroah-Hartman | 0858a3a | 2010-05-17 10:58:12 -0700 | [diff] [blame] | 138 | /* header and: */ |
Jussi Kivilinna | 7517579 | 2008-01-26 00:51:12 +0200 | [diff] [blame] | 139 | __le32 msg_type; /* RNDIS_MSG_SET_C */ |
| 140 | __le32 msg_len; |
| 141 | __le32 request_id; |
| 142 | __le32 status; |
| 143 | } __attribute__ ((packed)); |
| 144 | |
| 145 | struct rndis_reset { /* IN */ |
Greg Kroah-Hartman | 0858a3a | 2010-05-17 10:58:12 -0700 | [diff] [blame] | 146 | /* header and: */ |
Jussi Kivilinna | 7517579 | 2008-01-26 00:51:12 +0200 | [diff] [blame] | 147 | __le32 msg_type; /* RNDIS_MSG_RESET */ |
| 148 | __le32 msg_len; |
| 149 | __le32 reserved; |
| 150 | } __attribute__ ((packed)); |
| 151 | |
| 152 | struct rndis_reset_c { /* OUT */ |
Greg Kroah-Hartman | 0858a3a | 2010-05-17 10:58:12 -0700 | [diff] [blame] | 153 | /* header and: */ |
Jussi Kivilinna | 7517579 | 2008-01-26 00:51:12 +0200 | [diff] [blame] | 154 | __le32 msg_type; /* RNDIS_MSG_RESET_C */ |
| 155 | __le32 msg_len; |
| 156 | __le32 status; |
| 157 | __le32 addressing_lost; |
| 158 | } __attribute__ ((packed)); |
| 159 | |
| 160 | struct rndis_indicate { /* IN (unrequested) */ |
Greg Kroah-Hartman | 0858a3a | 2010-05-17 10:58:12 -0700 | [diff] [blame] | 161 | /* header and: */ |
Jussi Kivilinna | 7517579 | 2008-01-26 00:51:12 +0200 | [diff] [blame] | 162 | __le32 msg_type; /* RNDIS_MSG_INDICATE */ |
| 163 | __le32 msg_len; |
| 164 | __le32 status; |
| 165 | __le32 length; |
| 166 | __le32 offset; |
| 167 | /**/ __le32 diag_status; |
| 168 | __le32 error_offset; |
| 169 | /**/ __le32 message; |
| 170 | } __attribute__ ((packed)); |
| 171 | |
| 172 | struct rndis_keepalive { /* OUT (optionally IN) */ |
Greg Kroah-Hartman | 0858a3a | 2010-05-17 10:58:12 -0700 | [diff] [blame] | 173 | /* header and: */ |
Jussi Kivilinna | 7517579 | 2008-01-26 00:51:12 +0200 | [diff] [blame] | 174 | __le32 msg_type; /* RNDIS_MSG_KEEPALIVE */ |
| 175 | __le32 msg_len; |
| 176 | __le32 request_id; |
| 177 | } __attribute__ ((packed)); |
| 178 | |
| 179 | struct rndis_keepalive_c { /* IN (optionally OUT) */ |
Greg Kroah-Hartman | 0858a3a | 2010-05-17 10:58:12 -0700 | [diff] [blame] | 180 | /* header and: */ |
Jussi Kivilinna | 7517579 | 2008-01-26 00:51:12 +0200 | [diff] [blame] | 181 | __le32 msg_type; /* RNDIS_MSG_KEEPALIVE_C */ |
| 182 | __le32 msg_len; |
| 183 | __le32 request_id; |
| 184 | __le32 status; |
| 185 | } __attribute__ ((packed)); |
| 186 | |
Jussi Kivilinna | 7517579 | 2008-01-26 00:51:12 +0200 | [diff] [blame] | 187 | /* default filter used with RNDIS devices */ |
| 188 | #define RNDIS_DEFAULT_FILTER ( \ |
| 189 | RNDIS_PACKET_TYPE_DIRECTED | \ |
| 190 | RNDIS_PACKET_TYPE_BROADCAST | \ |
| 191 | RNDIS_PACKET_TYPE_ALL_MULTICAST | \ |
| 192 | RNDIS_PACKET_TYPE_PROMISCUOUS) |
| 193 | |
Jussi Kivilinna | 039ee17 | 2008-01-27 23:34:33 +0200 | [diff] [blame] | 194 | /* Flags to require specific physical medium type for generic_rndis_bind() */ |
| 195 | #define FLAG_RNDIS_PHYM_NOT_WIRELESS 0x0001 |
| 196 | #define FLAG_RNDIS_PHYM_WIRELESS 0x0002 |
| 197 | |
Ben Hutchings | 4d42d41 | 2011-04-13 14:48:55 -0700 | [diff] [blame] | 198 | /* Flags for driver_info::data */ |
| 199 | #define RNDIS_DRIVER_DATA_POLL_STATUS 1 /* poll status before control */ |
Jussi Kivilinna | 5665998 | 2008-01-26 00:51:17 +0200 | [diff] [blame] | 200 | |
| 201 | extern void rndis_status(struct usbnet *dev, struct urb *urb); |
Jussi Kivilinna | 818727b | 2008-06-18 15:40:12 +0300 | [diff] [blame] | 202 | extern int |
| 203 | rndis_command(struct usbnet *dev, struct rndis_msg_hdr *buf, int buflen); |
Jussi Kivilinna | 039ee17 | 2008-01-27 23:34:33 +0200 | [diff] [blame] | 204 | extern int |
| 205 | generic_rndis_bind(struct usbnet *dev, struct usb_interface *intf, int flags); |
Jussi Kivilinna | 5665998 | 2008-01-26 00:51:17 +0200 | [diff] [blame] | 206 | extern void rndis_unbind(struct usbnet *dev, struct usb_interface *intf); |
| 207 | extern int rndis_rx_fixup(struct usbnet *dev, struct sk_buff *skb); |
| 208 | extern struct sk_buff * |
| 209 | rndis_tx_fixup(struct usbnet *dev, struct sk_buff *skb, gfp_t flags); |
| 210 | |
Robert P. J. Day | dda43a0 | 2008-03-07 13:45:32 -0500 | [diff] [blame] | 211 | #endif /* __LINUX_USB_RNDIS_HOST_H */ |