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