Vitaly Kuzmichev | 7612a43 | 2011-02-11 18:18:34 +0300 | [diff] [blame] | 1 | /* |
| 2 | * RNDIS Definitions for Remote NDIS |
| 3 | * |
| 4 | * Authors: Benedikt Spranger, Pengutronix |
| 5 | * Robert Schwebel, Pengutronix |
| 6 | * |
Vitaly Kuzmichev | 7612a43 | 2011-02-11 18:18:34 +0300 | [diff] [blame] | 7 | * This software was originally developed in conformance with |
| 8 | * Microsoft's Remote NDIS Specification License Agreement. |
Tom Rini | 5b8031c | 2016-01-14 22:05:13 -0500 | [diff] [blame] | 9 | * |
| 10 | * SPDX-License-Identifier: GPL-2.0 |
Vitaly Kuzmichev | 7612a43 | 2011-02-11 18:18:34 +0300 | [diff] [blame] | 11 | */ |
| 12 | |
| 13 | #ifndef _USBGADGET_RNDIS_H |
| 14 | #define _USBGADGET_RNDIS_H |
| 15 | |
| 16 | #include "ndis.h" |
| 17 | |
Vitaly Kuzmichev | e4ae666 | 2011-02-11 18:18:35 +0300 | [diff] [blame] | 18 | /* |
| 19 | * By default rndis_signal_disconnect does not send status message about |
| 20 | * RNDIS disconnection to USB host (indicated as cable disconnected). |
| 21 | * Define RNDIS_COMPLETE_SIGNAL_DISCONNECT to send it. |
| 22 | * However, this will cause 1 sec delay on Ethernet device halt. |
| 23 | * Usually you do not need to define it. Mostly usable for debugging. |
| 24 | */ |
| 25 | |
Vitaly Kuzmichev | 7612a43 | 2011-02-11 18:18:34 +0300 | [diff] [blame] | 26 | #define RNDIS_MAXIMUM_FRAME_SIZE 1518 |
| 27 | #define RNDIS_MAX_TOTAL_SIZE 1558 |
| 28 | |
| 29 | /* Remote NDIS Versions */ |
| 30 | #define RNDIS_MAJOR_VERSION 1 |
| 31 | #define RNDIS_MINOR_VERSION 0 |
| 32 | |
| 33 | /* Status Values */ |
| 34 | #define RNDIS_STATUS_SUCCESS 0x00000000U /* Success */ |
| 35 | #define RNDIS_STATUS_FAILURE 0xC0000001U /* Unspecified error */ |
| 36 | #define RNDIS_STATUS_INVALID_DATA 0xC0010015U /* Invalid data */ |
| 37 | #define RNDIS_STATUS_NOT_SUPPORTED 0xC00000BBU /* Unsupported request */ |
| 38 | #define RNDIS_STATUS_MEDIA_CONNECT 0x4001000BU /* Device connected */ |
| 39 | #define RNDIS_STATUS_MEDIA_DISCONNECT 0x4001000CU /* Device disconnected */ |
| 40 | /* |
| 41 | * For all not specified status messages: |
| 42 | * RNDIS_STATUS_Xxx -> NDIS_STATUS_Xxx |
| 43 | */ |
| 44 | |
| 45 | /* Message Set for Connectionless (802.3) Devices */ |
| 46 | #define REMOTE_NDIS_PACKET_MSG 0x00000001U |
| 47 | #define REMOTE_NDIS_INITIALIZE_MSG 0x00000002U /* Initialize device */ |
| 48 | #define REMOTE_NDIS_HALT_MSG 0x00000003U |
| 49 | #define REMOTE_NDIS_QUERY_MSG 0x00000004U |
| 50 | #define REMOTE_NDIS_SET_MSG 0x00000005U |
| 51 | #define REMOTE_NDIS_RESET_MSG 0x00000006U |
| 52 | #define REMOTE_NDIS_INDICATE_STATUS_MSG 0x00000007U |
| 53 | #define REMOTE_NDIS_KEEPALIVE_MSG 0x00000008U |
| 54 | |
| 55 | /* Message completion */ |
| 56 | #define REMOTE_NDIS_INITIALIZE_CMPLT 0x80000002U |
| 57 | #define REMOTE_NDIS_QUERY_CMPLT 0x80000004U |
| 58 | #define REMOTE_NDIS_SET_CMPLT 0x80000005U |
| 59 | #define REMOTE_NDIS_RESET_CMPLT 0x80000006U |
| 60 | #define REMOTE_NDIS_KEEPALIVE_CMPLT 0x80000008U |
| 61 | |
| 62 | /* Device Flags */ |
| 63 | #define RNDIS_DF_CONNECTIONLESS 0x00000001U |
| 64 | #define RNDIS_DF_CONNECTION_ORIENTED 0x00000002U |
| 65 | |
| 66 | #define RNDIS_MEDIUM_802_3 0x00000000U |
| 67 | |
| 68 | /* from drivers/net/sk98lin/h/skgepnmi.h */ |
| 69 | #define OID_PNP_CAPABILITIES 0xFD010100 |
| 70 | #define OID_PNP_SET_POWER 0xFD010101 |
| 71 | #define OID_PNP_QUERY_POWER 0xFD010102 |
| 72 | #define OID_PNP_ADD_WAKE_UP_PATTERN 0xFD010103 |
| 73 | #define OID_PNP_REMOVE_WAKE_UP_PATTERN 0xFD010104 |
| 74 | #define OID_PNP_ENABLE_WAKE_UP 0xFD010106 |
| 75 | |
| 76 | |
| 77 | typedef struct rndis_init_msg_type { |
| 78 | __le32 MessageType; |
| 79 | __le32 MessageLength; |
| 80 | __le32 RequestID; |
| 81 | __le32 MajorVersion; |
| 82 | __le32 MinorVersion; |
| 83 | __le32 MaxTransferSize; |
| 84 | } rndis_init_msg_type; |
| 85 | |
| 86 | typedef struct rndis_init_cmplt_type { |
| 87 | __le32 MessageType; |
| 88 | __le32 MessageLength; |
| 89 | __le32 RequestID; |
| 90 | __le32 Status; |
| 91 | __le32 MajorVersion; |
| 92 | __le32 MinorVersion; |
| 93 | __le32 DeviceFlags; |
| 94 | __le32 Medium; |
| 95 | __le32 MaxPacketsPerTransfer; |
| 96 | __le32 MaxTransferSize; |
| 97 | __le32 PacketAlignmentFactor; |
| 98 | __le32 AFListOffset; |
| 99 | __le32 AFListSize; |
| 100 | } rndis_init_cmplt_type; |
| 101 | |
| 102 | typedef struct rndis_halt_msg_type { |
| 103 | __le32 MessageType; |
| 104 | __le32 MessageLength; |
| 105 | __le32 RequestID; |
| 106 | } rndis_halt_msg_type; |
| 107 | |
| 108 | typedef struct rndis_query_msg_type { |
| 109 | __le32 MessageType; |
| 110 | __le32 MessageLength; |
| 111 | __le32 RequestID; |
| 112 | __le32 OID; |
| 113 | __le32 InformationBufferLength; |
| 114 | __le32 InformationBufferOffset; |
| 115 | __le32 DeviceVcHandle; |
| 116 | } rndis_query_msg_type; |
| 117 | |
| 118 | typedef struct rndis_query_cmplt_type { |
| 119 | __le32 MessageType; |
| 120 | __le32 MessageLength; |
| 121 | __le32 RequestID; |
| 122 | __le32 Status; |
| 123 | __le32 InformationBufferLength; |
| 124 | __le32 InformationBufferOffset; |
| 125 | } rndis_query_cmplt_type; |
| 126 | |
| 127 | typedef struct rndis_set_msg_type { |
| 128 | __le32 MessageType; |
| 129 | __le32 MessageLength; |
| 130 | __le32 RequestID; |
| 131 | __le32 OID; |
| 132 | __le32 InformationBufferLength; |
| 133 | __le32 InformationBufferOffset; |
| 134 | __le32 DeviceVcHandle; |
| 135 | } rndis_set_msg_type; |
| 136 | |
| 137 | typedef struct rndis_set_cmplt_type { |
| 138 | __le32 MessageType; |
| 139 | __le32 MessageLength; |
| 140 | __le32 RequestID; |
| 141 | __le32 Status; |
| 142 | } rndis_set_cmplt_type; |
| 143 | |
| 144 | typedef struct rndis_reset_msg_type { |
| 145 | __le32 MessageType; |
| 146 | __le32 MessageLength; |
| 147 | __le32 Reserved; |
| 148 | } rndis_reset_msg_type; |
| 149 | |
| 150 | typedef struct rndis_reset_cmplt_type { |
| 151 | __le32 MessageType; |
| 152 | __le32 MessageLength; |
| 153 | __le32 Status; |
| 154 | __le32 AddressingReset; |
| 155 | } rndis_reset_cmplt_type; |
| 156 | |
| 157 | typedef struct rndis_indicate_status_msg_type { |
| 158 | __le32 MessageType; |
| 159 | __le32 MessageLength; |
| 160 | __le32 Status; |
| 161 | __le32 StatusBufferLength; |
| 162 | __le32 StatusBufferOffset; |
| 163 | } rndis_indicate_status_msg_type; |
| 164 | |
| 165 | typedef struct rndis_keepalive_msg_type { |
| 166 | __le32 MessageType; |
| 167 | __le32 MessageLength; |
| 168 | __le32 RequestID; |
| 169 | } rndis_keepalive_msg_type; |
| 170 | |
| 171 | typedef struct rndis_keepalive_cmplt_type { |
| 172 | __le32 MessageType; |
| 173 | __le32 MessageLength; |
| 174 | __le32 RequestID; |
| 175 | __le32 Status; |
| 176 | } rndis_keepalive_cmplt_type; |
| 177 | |
| 178 | struct rndis_packet_msg_type { |
| 179 | __le32 MessageType; |
| 180 | __le32 MessageLength; |
| 181 | __le32 DataOffset; |
| 182 | __le32 DataLength; |
| 183 | __le32 OOBDataOffset; |
| 184 | __le32 OOBDataLength; |
| 185 | __le32 NumOOBDataElements; |
| 186 | __le32 PerPacketInfoOffset; |
| 187 | __le32 PerPacketInfoLength; |
| 188 | __le32 VcHandle; |
| 189 | __le32 Reserved; |
| 190 | } __attribute__ ((packed)); |
| 191 | |
| 192 | struct rndis_config_parameter { |
| 193 | __le32 ParameterNameOffset; |
| 194 | __le32 ParameterNameLength; |
| 195 | __le32 ParameterType; |
| 196 | __le32 ParameterValueOffset; |
| 197 | __le32 ParameterValueLength; |
| 198 | }; |
| 199 | |
| 200 | /* implementation specific */ |
| 201 | enum rndis_state { |
| 202 | RNDIS_UNINITIALIZED, |
| 203 | RNDIS_INITIALIZED, |
| 204 | RNDIS_DATA_INITIALIZED, |
| 205 | }; |
| 206 | |
| 207 | typedef struct rndis_resp_t { |
| 208 | struct list_head list; |
| 209 | u8 *buf; |
| 210 | u32 length; |
| 211 | int send; |
| 212 | } rndis_resp_t; |
| 213 | |
| 214 | typedef struct rndis_params { |
| 215 | u8 confignr; |
| 216 | u8 used; |
| 217 | u16 saved_filter; |
| 218 | enum rndis_state state; |
| 219 | u32 medium; |
| 220 | u32 speed; |
| 221 | u32 media_state; |
| 222 | |
| 223 | const u8 *host_mac; |
| 224 | u16 *filter; |
Vitaly Kuzmichev | 7612a43 | 2011-02-11 18:18:34 +0300 | [diff] [blame] | 225 | struct net_device_stats *stats; |
| 226 | int mtu; |
| 227 | |
| 228 | u32 vendorID; |
| 229 | const char *vendorDescr; |
Mugunthan V N | d4a3755 | 2016-11-18 11:09:15 +0530 | [diff] [blame^] | 230 | #ifndef CONFIG_DM_ETH |
| 231 | struct eth_device *dev; |
| 232 | int (*ack)(struct eth_device *); |
| 233 | #else |
| 234 | struct udevice *dev; |
| 235 | int (*ack)(struct udevice *); |
| 236 | #endif |
Vitaly Kuzmichev | 7612a43 | 2011-02-11 18:18:34 +0300 | [diff] [blame] | 237 | struct list_head resp_queue; |
| 238 | } rndis_params; |
| 239 | |
| 240 | /* RNDIS Message parser and other useless functions */ |
| 241 | int rndis_msg_parser(u8 configNr, u8 *buf); |
| 242 | enum rndis_state rndis_get_state(int configNr); |
Vitaly Kuzmichev | 7612a43 | 2011-02-11 18:18:34 +0300 | [diff] [blame] | 243 | void rndis_deregister(int configNr); |
Mugunthan V N | d4a3755 | 2016-11-18 11:09:15 +0530 | [diff] [blame^] | 244 | #ifndef CONFIG_DM_ETH |
| 245 | int rndis_register(int (*rndis_control_ack)(struct eth_device *)); |
Vitaly Kuzmichev | 7612a43 | 2011-02-11 18:18:34 +0300 | [diff] [blame] | 246 | int rndis_set_param_dev(u8 configNr, struct eth_device *dev, int mtu, |
Mugunthan V N | d4a3755 | 2016-11-18 11:09:15 +0530 | [diff] [blame^] | 247 | struct net_device_stats *stats, u16 *cdc_filter); |
| 248 | #else |
| 249 | int rndis_register(int (*rndis_control_ack)(struct udevice *)); |
| 250 | int rndis_set_param_dev(u8 configNr, struct udevice *dev, int mtu, |
| 251 | struct net_device_stats *stats, u16 *cdc_filter); |
| 252 | #endif |
Vitaly Kuzmichev | 7612a43 | 2011-02-11 18:18:34 +0300 | [diff] [blame] | 253 | int rndis_set_param_vendor(u8 configNr, u32 vendorID, |
| 254 | const char *vendorDescr); |
| 255 | int rndis_set_param_medium(u8 configNr, u32 medium, u32 speed); |
| 256 | void rndis_add_hdr(void *bug, int length); |
| 257 | int rndis_rm_hdr(void *bug, int length); |
| 258 | u8 *rndis_get_next_response(int configNr, u32 *length); |
| 259 | void rndis_free_response(int configNr, u8 *buf); |
| 260 | |
| 261 | void rndis_uninit(int configNr); |
| 262 | int rndis_signal_connect(int configNr); |
| 263 | int rndis_signal_disconnect(int configNr); |
| 264 | extern void rndis_set_host_mac(int configNr, const u8 *addr); |
| 265 | |
| 266 | int rndis_init(void); |
| 267 | void rndis_exit(void); |
| 268 | |
| 269 | #endif /* _USBGADGET_RNDIS_H */ |