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