• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /****************************************************************************
2  * drivers/usbdev/rndis.c
3  *
4  *   Copyright (C) 2011-2017 Gregory Nutt. All rights reserved.
5  *   Copyright (c) Huawei Technologies Co., Ltd. 2017-2019. All rights reserved.
6  *   Authors: Sakari Kapanen <sakari.m.kapanen@gmail.com>,
7  *            Petteri Aimonen <jpa@git.mail.kapsi.fi>
8  *
9  * Redistribution and use in source and binary forms, with or without
10  * modification, are permitted provided that the following conditions
11  * are met:
12  *
13  * 1. Redistributions of source code must retain the above copyright
14  *    notice, this list of conditions and the following disclaimer.
15  * 2. Redistributions in binary form must reproduce the above copyright
16  *    notice, this list of conditions and the following disclaimer in
17  *    the documentation and/or other materials provided with the
18  *    distribution.
19  * 3. Neither the name NuttX nor the names of its contributors may be
20  *    used to endorse or promote products derived from this software
21  *    without specific prior written permission.
22  *
23  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
24  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
25  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
26  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
27  * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
28  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
29  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
30  * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
31  * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
33  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
34  * POSSIBILITY OF SUCH DAMAGE.
35  *
36  ****************************************************************************/
37 /****************************************************************************
38  * Notice of Export Control Law
39  * ===============================================
40  * Huawei LiteOS may be subject to applicable export control laws and regulations,
41  * which might include those applicable to Huawei LiteOS of U.S. and the country in
42  * which you are located.
43  * Import, export and usage of Huawei LiteOS in any manner by you shall be in
44  * compliance with such applicable export control laws and regulations.
45  ****************************************************************************/
46 
47 #ifndef __NUTTX_DRIVERS_USBDEV_RNDIS_STD_H
48 #define __NUTTX_DRIVERS_USBDEV_RNDIS_STD_H
49 
50 /****************************************************************************
51  * Pre-processor definitions
52  ****************************************************************************/
53 
54 /* Definitions for Microsoft RNDIS protocol.
55  * Documentation:
56  * https://docs.microsoft.com/en-us/windows-hardware/drivers/network/remote-ndis--rndis-2
57  * https://winprotocoldoc.blob.core.windows.net/productionwindowsarchives/WinArchive/[MS-RNDIS].pdf
58  */
59 
60 #define RNDIS_MAJOR_VERSION                  1
61 #define RNDIS_MINOR_VERSION                  0
62 
63 #define RNDIS_DEVICEFLAGS                    0x00000001
64 #define RNDIS_MEDIUM_802_3                   0x00000000
65 
66 /* Message types */
67 
68 #define RNDIS_MSG_COMPLETE                   0x80000000
69 #define RNDIS_PACKET_MSG                     0x00000001
70 #define RNDIS_INITIALIZE_MSG                 0x00000002
71 #define RNDIS_HALT_MSG                       0x00000003
72 #define RNDIS_QUERY_MSG                      0x00000004
73 #define RNDIS_SET_MSG                        0x00000005
74 #define RNDIS_RESET_MSG                      0x00000006
75 #define RNDIS_INDICATE_MSG                   0x00000007
76 #define RNDIS_KEEPALIVE_MSG                  0x00000008
77 
78 /* Status codes */
79 
80 #define RNDIS_STATUS_SUCCESS                 0x00000000
81 #define RNDIS_STATUS_FAILURE                 0xC0000001
82 #define RNDIS_STATUS_NOT_SUPPORTED           0xC00000BB
83 
84 /* ObjectIDs for query commands */
85 
86 #define RNDIS_OID_GEN_SUPPORTED_LIST         0x00010101
87 #define RNDIS_OID_GEN_HARDWARE_STATUS        0x00010102
88 #define RNDIS_OID_GEN_MEDIA_SUPPORTED        0x00010103
89 #define RNDIS_OID_GEN_MEDIA_IN_USE           0x00010104
90 #define RNDIS_OID_GEN_MAXIMUM_FRAME_SIZE     0x00010106
91 #define RNDIS_OID_GEN_LINK_SPEED             0x00010107
92 #define RNDIS_OID_GEN_TRANSMIT_BLOCK_SIZE    0x0001010A
93 #define RNDIS_OID_GEN_RECEIVE_BLOCK_SIZE     0x0001010B
94 #define RNDIS_OID_GEN_VENDOR_ID              0x0001010C
95 #define RNDIS_OID_GEN_VENDOR_DESCRIPTION     0x0001010D
96 #define RNDIS_OID_GEN_VENDOR_DRIVER_VERSION  0x00010116
97 #define RNDIS_OID_GEN_CURRENT_PACKET_FILTER  0x0001010E
98 #define RNDIS_OID_GEN_MAXIMUM_TOTAL_SIZE     0x00010111
99 #define RNDIS_OID_GEN_MEDIA_CONNECT_STATUS   0x00010114
100 #define RNDIS_OID_GEN_PHYSICAL_MEDIUM        0x00010202
101 #define RNDIS_OID_GEN_XMIT_OK                0x00020101
102 #define RNDIS_OID_GEN_RCV_OK                 0x00020102
103 #define RNDIS_OID_GEN_XMIT_ERROR             0x00020103
104 #define RNDIS_OID_GEN_RCV_ERROR              0x00020104
105 #define RNDIS_OID_GEN_RCV_NO_BUFFER          0x00020105
106 #define RNDIS_OID_802_3_PERMANENT_ADDRESS    0x01010101
107 #define RNDIS_OID_802_3_CURRENT_ADDRESS      0x01010102
108 #define RNDIS_OID_802_3_MULTICAST_LIST       0x01010103
109 #define RNDIS_OID_802_3_MAXIMUM_LIST_SIZE    0x01010104
110 #define RNDIS_OID_802_3_MAC_OPTIONS          0x01010105
111 #define RNDIS_OID_802_3_RCV_ERROR_ALIGNMENT  0x01020101
112 #define RNDIS_OID_802_3_XMIT_ONE_COLLISION   0x01020102
113 #define RNDIS_OID_802_3_XMIT_MORE_COLLISION  0x01020103
114 
115 #define RNDIS_SEND_ENCAPSULATED_COMMAND 0x00
116 #define RNDIS_GET_ENCAPSULATED_RESPONSE 0x01
117 
118 #define RNDIS_NOTIFICATION_RESPONSE_AVAILABLE 0x01
119 
120 /****************************************************************************
121  * Public types
122  ****************************************************************************/
123 
124 struct rndis_notification
125 {
126   uint32_t notification;  /* Notification */
127   uint32_t reserved;      /* Reserved */
128 };
129 
130 struct rndis_command_header
131 {
132   uint32_t msgtype;       /* MessageType */
133   uint32_t msglen;        /* MessageLength */
134   uint32_t reqid;         /* RequestID */
135 };
136 
137 struct rndis_response_header
138 {
139   uint32_t msgtype;       /* MessageType */
140   uint32_t msglen;        /* MessageLength */
141   uint32_t reqid;         /* RequestID */
142   uint32_t status;        /* Status */
143 };
144 
145 struct rndis_initialize_msg
146 {
147   struct rndis_command_header hdr;
148   uint32_t major;         /* MajorVersion */
149   uint32_t minor;         /* MinorVersion */
150   uint32_t xfrsize;       /* MaxTransferSize */
151 };
152 
153 struct rndis_initialize_cmplt
154 {
155   struct rndis_response_header hdr;
156   uint32_t major;         /* MajorVersion */
157   uint32_t minor;         /* MinorVersion */
158   uint32_t devflags;      /* DeviceFlags */
159   uint32_t medium;        /* Medium */
160   uint32_t pktperxfer;    /* MaxPacketsPerTransfer */
161   uint32_t xfrsize;       /* MaxTransferSize */
162   uint32_t pktalign;      /* PacketAlignmentFactor */
163   uint32_t reserved1;     /* Reserved1 */
164   uint32_t reserved2;     /* Reserved2 */
165 };
166 
167 struct rndis_query_msg
168 {
169   struct rndis_command_header hdr;
170   uint32_t objid;         /* ObjectID */
171   uint32_t buflen;        /* InformationBufferLength */
172   uint32_t bufoffset;     /* InformationBufferOffset */
173   uint32_t reserved;      /* Reserved */
174   uint32_t buffer[];      /* Buffer */
175 };
176 
177 struct rndis_query_cmplt
178 {
179   struct rndis_response_header hdr;
180   uint32_t buflen;        /* InformationBufferLength */
181   uint32_t bufoffset;     /* InformationBufferOffset */
182   uint32_t buffer[];      /* Buffer */
183 };
184 
185 struct rndis_set_msg
186 {
187   struct rndis_command_header hdr;
188   uint32_t objid;         /* ObjectID */
189   uint32_t buflen;        /* InformationBufferLength */
190   uint32_t bufoffset;     /* InformationBufferOffset */
191   uint32_t reserved;      /* Reserved */
192   uint32_t buffer[];      /* Buffer */
193 };
194 
195 struct rndis_reset_cmplt
196 {
197   struct rndis_response_header hdr;
198   uint32_t addreset;      /* AddressingReset */
199 };
200 
201 struct rndis_indicate_msg
202 {
203   uint32_t msgtype;       /* MessageType */
204   uint32_t msglen;        /* MessageLength */
205   uint32_t status;        /* Status */
206   uint32_t buflen;        /* StatusBufferLength */
207   uint32_t bufoffset;     /* StatusBufferOffset */
208   uint32_t buffer[];      /* Buffer */
209 };
210 
211 struct rndis_packet_msg
212 {
213   uint32_t msgtype;      /* MessageType */
214   uint32_t msglen;       /* MessageLength */
215   uint32_t dataoffset;   /* DataOffset */
216   uint32_t datalen;      /* DataLength */
217   uint32_t ooboffset;    /* OutOfBandDataOffset */
218   uint32_t ooblen;       /* OutOfBandDataLength */
219   uint32_t noobelem;     /* NumOutOfBandDataElements */
220   uint32_t infooffset;   /* PerPacketInfoOffset */
221   uint32_t infolen;      /* PerPacketInfoLength */
222   uint32_t handle;
223   uint32_t reserved;
224 };
225 
226 #endif
227