1 /* $FreeBSD$ */ 2 /* $OpenBSD: if_urndisreg.h,v 1.19 2013/11/21 14:08:05 mpi Exp $ */ 3 4 /* 5 * Copyright (c) 2010 Jonathan Armani <armani@openbsd.org> 6 * Copyright (c) 2010 Fabien Romano <fabien@openbsd.org> 7 * Copyright (c) 2010 Michael Knudsen <mk@openbsd.org> 8 * All rights reserved. 9 * 10 * Permission to use, copy, modify, and distribute this software for any 11 * purpose with or without fee is hereby granted, provided that the above 12 * copyright notice and this permission notice appear in all copies. 13 * 14 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 15 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 16 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 17 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 18 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 19 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 20 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 21 */ 22 23 #ifndef _IF_URNDISREG_H_ 24 #define _IF_URNDISREG_H_ 25 26 #include "implementation/global_implementation.h" 27 #include "usb_ethernet.h" 28 29 #define RNDIS_RESPONSE_LEN 1024 /* bytes */ 30 #define RNDIS_RX_MAXLEN (16 * 1024) 31 #define RNDIS_TX_FRAMES_MAX 8 32 #define RNDIS_TX_MAXLEN MCLBYTES 33 #define ETHER_ALIGN 2 /* driver adjust for IP hdr alignment */ 34 35 /* 36 * Structure of a DEC/Intel/Xerox or 802.3 Ethernet header. 37 */ 38 struct ether_header { 39 uint8_t ether_dhost[NETIF_MAX_HWADDR_LEN]; 40 uint8_t ether_shost[NETIF_MAX_HWADDR_LEN]; 41 uint16_t ether_type; 42 }; 43 44 enum { 45 URNDIS_BULK_RX, 46 URNDIS_BULK_TX, 47 URNDIS_INTR_RX, 48 URNDIS_N_TRANSFER, 49 }; 50 51 struct urndis_softc { 52 struct usb_ether sc_ue; 53 struct mtx sc_mtx; 54 55 /* RNDIS device info */ 56 uint32_t sc_lim_pktsz; 57 uint32_t sc_filter; 58 59 struct usb_device *sc_udev; 60 struct usb_xfer *sc_xfer[URNDIS_N_TRANSFER]; 61 62 uint8_t sc_ifaceno_ctl; 63 uint8_t sc_response_buf[RNDIS_RESPONSE_LEN] __aligned(4); 64 }; 65 66 #define URNDIS_LOCK(sc) mtx_lock(&(sc)->sc_mtx) 67 #define URNDIS_UNLOCK(sc) mtx_unlock(&(sc)->sc_mtx) 68 #define URNDIS_LOCK_ASSERT(sc, what) mtx_assert(&(sc)->sc_mtx, (what)) 69 70 #define RNDIS_STATUS_BUFFER_OVERFLOW 0x80000005L 71 #define RNDIS_STATUS_FAILURE 0xC0000001L 72 #define RNDIS_STATUS_INVALID_DATA 0xC0010015L 73 #define RNDIS_STATUS_MEDIA_CONNECT 0x4001000BL 74 #define RNDIS_STATUS_MEDIA_DISCONNECT 0x4001000CL 75 #define RNDIS_STATUS_NOT_SUPPORTED 0xC00000BBL 76 #define RNDIS_STATUS_PENDING STATUS_PENDING /* XXX */ 77 #define RNDIS_STATUS_RESOURCES 0xC000009AL 78 #define RNDIS_STATUS_SUCCESS 0x00000000L 79 80 #define OID_GEN_SUPPORTED_LIST 0x00010101 81 #define OID_GEN_HARDWARE_STATUS 0x00010102 82 #define OID_GEN_MEDIA_SUPPORTED 0x00010103 83 #define OID_GEN_MEDIA_IN_USE 0x00010104 84 #define OID_GEN_MAXIMUM_LOOKAHEAD 0x00010105 85 #define OID_GEN_MAXIMUM_FRAME_SIZE 0x00010106 86 #define OID_GEN_LINK_SPEED 0x00010107 87 #define OID_GEN_TRANSMIT_BUFFER_SPACE 0x00010108 88 #define OID_GEN_RECEIVE_BUFFER_SPACE 0x00010109 89 #define OID_GEN_TRANSMIT_BLOCK_SIZE 0x0001010A 90 #define OID_GEN_RECEIVE_BLOCK_SIZE 0x0001010B 91 #define OID_GEN_VENDOR_ID 0x0001010C 92 #define OID_GEN_VENDOR_DESCRIPTION 0x0001010D 93 #define OID_GEN_CURRENT_PACKET_FILTER 0x0001010E 94 #define OID_GEN_CURRENT_LOOKAHEAD 0x0001010F 95 #define OID_GEN_DRIVER_VERSION 0x00010110 96 #define OID_GEN_MAXIMUM_TOTAL_SIZE 0x00010111 97 #define OID_GEN_PROTOCOL_OPTIONS 0x00010112 98 #define OID_GEN_MAC_OPTIONS 0x00010113 99 #define OID_GEN_MEDIA_CONNECT_STATUS 0x00010114 100 #define OID_GEN_MAXIMUM_SEND_PACKETS 0x00010115 101 #define OID_GEN_VENDOR_DRIVER_VERSION 0x00010116 102 #define OID_GEN_SUPPORTED_GUIDS 0x00010117 103 #define OID_GEN_NETWORK_LAYER_ADDRESSES 0x00010118 104 #define OID_GEN_TRANSPORT_HEADER_OFFSET 0x00010119 105 #define OID_GEN_MACHINE_NAME 0x0001021A 106 #define OID_GEN_RNDIS_CONFIG_PARAMETER 0x0001021B 107 #define OID_GEN_VLAN_ID 0x0001021C 108 109 #define OID_802_3_PERMANENT_ADDRESS 0x01010101 110 #define OID_802_3_CURRENT_ADDRESS 0x01010102 111 #define OID_802_3_MULTICAST_LIST 0x01010103 112 #define OID_802_3_MAXIMUM_LIST_SIZE 0x01010104 113 #define OID_802_3_MAC_OPTIONS 0x01010105 114 #define OID_802_3_RCV_ERROR_ALIGNMENT 0x01020101 115 #define OID_802_3_XMIT_ONE_COLLISION 0x01020102 116 #define OID_802_3_XMIT_MORE_COLLISIONS 0x01020103 117 #define OID_802_3_XMIT_DEFERRED 0x01020201 118 #define OID_802_3_XMIT_MAX_COLLISIONS 0x01020202 119 #define OID_802_3_RCV_OVERRUN 0x01020203 120 #define OID_802_3_XMIT_UNDERRUN 0x01020204 121 #define OID_802_3_XMIT_HEARTBEAT_FAILURE 0x01020205 122 #define OID_802_3_XMIT_TIMES_CRS_LOST 0x01020206 123 #define OID_802_3_XMIT_LATE_COLLISIONS 0x01020207 124 125 #define RNDIS_MEDIUM_802_3 0x00000000 126 127 /* Device flags */ 128 #define RNDIS_DF_CONNECTIONLESS 0x00000001 129 #define RNDIS_DF_CONNECTION_ORIENTED 0x00000002 130 131 /* 132 * RNDIS data message 133 */ 134 #define REMOTE_NDIS_PACKET_MSG 0x00000001 135 136 struct urndis_packet_msg { 137 uint32_t rm_type; 138 uint32_t rm_len; 139 uint32_t rm_dataoffset; 140 uint32_t rm_datalen; 141 uint32_t rm_oobdataoffset; 142 uint32_t rm_oobdatalen; 143 uint32_t rm_oobdataelements; 144 uint32_t rm_pktinfooffset; 145 uint32_t rm_pktinfolen; 146 uint32_t rm_vchandle; 147 uint32_t rm_reserved; 148 }; 149 150 /* 151 * RNDIS control messages 152 */ 153 struct urndis_comp_hdr { 154 uint32_t rm_type; 155 uint32_t rm_len; 156 uint32_t rm_rid; 157 uint32_t rm_status; 158 }; 159 160 /* Initialize the device. */ 161 #define REMOTE_NDIS_INITIALIZE_MSG 0x00000002 162 #define REMOTE_NDIS_INITIALIZE_CMPLT 0x80000002 163 164 struct urndis_init_req { 165 uint32_t rm_type; 166 uint32_t rm_len; 167 uint32_t rm_rid; 168 uint32_t rm_ver_major; 169 uint32_t rm_ver_minor; 170 uint32_t rm_max_xfersz; 171 }; 172 173 struct urndis_init_comp { 174 uint32_t rm_type; 175 uint32_t rm_len; 176 uint32_t rm_rid; 177 uint32_t rm_status; 178 uint32_t rm_ver_major; 179 uint32_t rm_ver_minor; 180 uint32_t rm_devflags; 181 uint32_t rm_medium; 182 uint32_t rm_pktmaxcnt; 183 uint32_t rm_pktmaxsz; 184 uint32_t rm_align; 185 uint32_t rm_aflistoffset; 186 uint32_t rm_aflistsz; 187 }; 188 189 /* Halt the device. No response sent. */ 190 #define REMOTE_NDIS_HALT_MSG 0x00000003 191 192 struct urndis_halt_req { 193 uint32_t rm_type; 194 uint32_t rm_len; 195 uint32_t rm_rid; 196 }; 197 198 /* Send a query object. */ 199 #define REMOTE_NDIS_QUERY_MSG 0x00000004 200 #define REMOTE_NDIS_QUERY_CMPLT 0x80000004 201 202 struct urndis_query_req { 203 uint32_t rm_type; 204 uint32_t rm_len; 205 uint32_t rm_rid; 206 uint32_t rm_oid; 207 uint32_t rm_infobuflen; 208 uint32_t rm_infobufoffset; 209 uint32_t rm_devicevchdl; 210 }; 211 212 struct urndis_query_comp { 213 uint32_t rm_type; 214 uint32_t rm_len; 215 uint32_t rm_rid; 216 uint32_t rm_status; 217 uint32_t rm_infobuflen; 218 uint32_t rm_infobufoffset; 219 }; 220 221 /* Send a set object request. */ 222 #define REMOTE_NDIS_SET_MSG 0x00000005 223 #define REMOTE_NDIS_SET_CMPLT 0x80000005 224 225 struct urndis_set_req { 226 uint32_t rm_type; 227 uint32_t rm_len; 228 uint32_t rm_rid; 229 uint32_t rm_oid; 230 uint32_t rm_infobuflen; 231 uint32_t rm_infobufoffset; 232 uint32_t rm_devicevchdl; 233 }; 234 235 struct urndis_set_comp { 236 uint32_t rm_type; 237 uint32_t rm_len; 238 uint32_t rm_rid; 239 uint32_t rm_status; 240 }; 241 242 #define REMOTE_NDIS_SET_PARAM_NUMERIC 0x00000000 243 #define REMOTE_NDIS_SET_PARAM_STRING 0x00000002 244 245 struct urndis_set_parameter { 246 uint32_t rm_nameoffset; 247 uint32_t rm_namelen; 248 uint32_t rm_type; 249 uint32_t rm_valueoffset; 250 uint32_t rm_valuelen; 251 }; 252 253 /* Perform a soft reset on the device. */ 254 #define REMOTE_NDIS_RESET_MSG 0x00000006 255 #define REMOTE_NDIS_RESET_CMPLT 0x80000006 256 257 struct urndis_reset_req { 258 uint32_t rm_type; 259 uint32_t rm_len; 260 uint32_t rm_rid; 261 }; 262 263 struct urndis_reset_comp { 264 uint32_t rm_type; 265 uint32_t rm_len; 266 uint32_t rm_status; 267 uint32_t rm_adrreset; 268 }; 269 270 /* 802.3 link-state or undefined message error. */ 271 #define REMOTE_NDIS_INDICATE_STATUS_MSG 0x00000007 272 273 /* Keepalive messsage. May be sent by device. */ 274 #define REMOTE_NDIS_KEEPALIVE_MSG 0x00000008 275 #define REMOTE_NDIS_KEEPALIVE_CMPLT 0x80000008 276 277 struct urndis_keepalive_req { 278 uint32_t rm_type; 279 uint32_t rm_len; 280 uint32_t rm_rid; 281 }; 282 283 struct urndis_keepalive_comp { 284 uint32_t rm_type; 285 uint32_t rm_len; 286 uint32_t rm_rid; 287 uint32_t rm_status; 288 }; 289 290 /* packet filter bits used by OID_GEN_CURRENT_PACKET_FILTER */ 291 #define RNDIS_PACKET_TYPE_DIRECTED 0x00000001 292 #define RNDIS_PACKET_TYPE_MULTICAST 0x00000002 293 #define RNDIS_PACKET_TYPE_ALL_MULTICAST 0x00000004 294 #define RNDIS_PACKET_TYPE_BROADCAST 0x00000008 295 #define RNDIS_PACKET_TYPE_SOURCE_ROUTING 0x00000010 296 #define RNDIS_PACKET_TYPE_PROMISCUOUS 0x00000020 297 #define RNDIS_PACKET_TYPE_SMT 0x00000040 298 #define RNDIS_PACKET_TYPE_ALL_LOCAL 0x00000080 299 #define RNDIS_PACKET_TYPE_GROUP 0x00001000 300 #define RNDIS_PACKET_TYPE_ALL_FUNCTIONAL 0x00002000 301 #define RNDIS_PACKET_TYPE_FUNCTIONAL 0x00004000 302 #define RNDIS_PACKET_TYPE_MAC_FRAME 0x00008000 303 304 /* RNDIS offsets */ 305 #define RNDIS_HEADER_OFFSET 8 /* bytes */ 306 #define RNDIS_DATA_OFFSET ((uint32_t)(sizeof(struct urndis_packet_msg) - RNDIS_HEADER_OFFSET)) 307 308 #endif /* _IF_URNDISREG_H_ */ 309