root / hw / usb-net.c @ 03f48b07
History | View | Annotate | Download (43 kB)
1 | 6c9f886c | balrog | /*
|
---|---|---|---|
2 | 6c9f886c | balrog | * QEMU USB Net devices
|
3 | 6c9f886c | balrog | *
|
4 | 6c9f886c | balrog | * Copyright (c) 2006 Thomas Sailer
|
5 | 6c9f886c | balrog | * Copyright (c) 2008 Andrzej Zaborowski
|
6 | 6c9f886c | balrog | *
|
7 | 6c9f886c | balrog | * Permission is hereby granted, free of charge, to any person obtaining a copy
|
8 | 6c9f886c | balrog | * of this software and associated documentation files (the "Software"), to deal
|
9 | 6c9f886c | balrog | * in the Software without restriction, including without limitation the rights
|
10 | 6c9f886c | balrog | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
11 | 6c9f886c | balrog | * copies of the Software, and to permit persons to whom the Software is
|
12 | 6c9f886c | balrog | * furnished to do so, subject to the following conditions:
|
13 | 6c9f886c | balrog | *
|
14 | 6c9f886c | balrog | * The above copyright notice and this permission notice shall be included in
|
15 | 6c9f886c | balrog | * all copies or substantial portions of the Software.
|
16 | 6c9f886c | balrog | *
|
17 | 6c9f886c | balrog | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
18 | 6c9f886c | balrog | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
19 | 6c9f886c | balrog | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
20 | 6c9f886c | balrog | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
21 | 6c9f886c | balrog | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
22 | 6c9f886c | balrog | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
23 | 6c9f886c | balrog | * THE SOFTWARE.
|
24 | 6c9f886c | balrog | */
|
25 | 6c9f886c | balrog | |
26 | 6c9f886c | balrog | #include "qemu-common.h" |
27 | 6c9f886c | balrog | #include "usb.h" |
28 | 30c7d32a | Gerd Hoffmann | #include "usb-desc.h" |
29 | 6c9f886c | balrog | #include "net.h" |
30 | 72cf2d4f | Blue Swirl | #include "qemu-queue.h" |
31 | 1ca4d09a | Gleb Natapov | #include "sysemu.h" |
32 | 4f4321c1 | Gerd Hoffmann | #include "iov.h" |
33 | 6c9f886c | balrog | |
34 | 6c9f886c | balrog | /*#define TRAFFIC_DEBUG*/
|
35 | 6c9f886c | balrog | /* Thanks to NetChip Technologies for donating this product ID.
|
36 | 6c9f886c | balrog | * It's for devices with only CDC Ethernet configurations.
|
37 | 6c9f886c | balrog | */
|
38 | 6c9f886c | balrog | #define CDC_VENDOR_NUM 0x0525 /* NetChip */ |
39 | 6c9f886c | balrog | #define CDC_PRODUCT_NUM 0xa4a1 /* Linux-USB Ethernet Gadget */ |
40 | 6c9f886c | balrog | /* For hardware that can talk RNDIS and either of the above protocols,
|
41 | 6c9f886c | balrog | * use this ID ... the windows INF files will know it.
|
42 | 6c9f886c | balrog | */
|
43 | 6c9f886c | balrog | #define RNDIS_VENDOR_NUM 0x0525 /* NetChip */ |
44 | 6c9f886c | balrog | #define RNDIS_PRODUCT_NUM 0xa4a2 /* Ethernet/RNDIS Gadget */ |
45 | 6c9f886c | balrog | |
46 | 6c9f886c | balrog | enum usbstring_idx {
|
47 | 6c9f886c | balrog | STRING_MANUFACTURER = 1,
|
48 | 6c9f886c | balrog | STRING_PRODUCT, |
49 | 6c9f886c | balrog | STRING_ETHADDR, |
50 | 6c9f886c | balrog | STRING_DATA, |
51 | 6c9f886c | balrog | STRING_CONTROL, |
52 | 6c9f886c | balrog | STRING_RNDIS_CONTROL, |
53 | 6c9f886c | balrog | STRING_CDC, |
54 | 6c9f886c | balrog | STRING_SUBSET, |
55 | 6c9f886c | balrog | STRING_RNDIS, |
56 | 6c9f886c | balrog | STRING_SERIALNUMBER, |
57 | 6c9f886c | balrog | }; |
58 | 6c9f886c | balrog | |
59 | 6c9f886c | balrog | #define DEV_CONFIG_VALUE 1 /* CDC or a subset */ |
60 | 6c9f886c | balrog | #define DEV_RNDIS_CONFIG_VALUE 2 /* RNDIS; optional */ |
61 | 6c9f886c | balrog | |
62 | 6c9f886c | balrog | #define USB_CDC_SUBCLASS_ACM 0x02 |
63 | 6c9f886c | balrog | #define USB_CDC_SUBCLASS_ETHERNET 0x06 |
64 | 6c9f886c | balrog | |
65 | 6c9f886c | balrog | #define USB_CDC_PROTO_NONE 0 |
66 | 6c9f886c | balrog | #define USB_CDC_ACM_PROTO_VENDOR 0xff |
67 | 6c9f886c | balrog | |
68 | 6c9f886c | balrog | #define USB_CDC_HEADER_TYPE 0x00 /* header_desc */ |
69 | 6c9f886c | balrog | #define USB_CDC_CALL_MANAGEMENT_TYPE 0x01 /* call_mgmt_descriptor */ |
70 | 6c9f886c | balrog | #define USB_CDC_ACM_TYPE 0x02 /* acm_descriptor */ |
71 | 6c9f886c | balrog | #define USB_CDC_UNION_TYPE 0x06 /* union_desc */ |
72 | 6c9f886c | balrog | #define USB_CDC_ETHERNET_TYPE 0x0f /* ether_desc */ |
73 | 6c9f886c | balrog | |
74 | 6c9f886c | balrog | #define USB_CDC_SEND_ENCAPSULATED_COMMAND 0x00 |
75 | 6c9f886c | balrog | #define USB_CDC_GET_ENCAPSULATED_RESPONSE 0x01 |
76 | 6c9f886c | balrog | #define USB_CDC_REQ_SET_LINE_CODING 0x20 |
77 | 6c9f886c | balrog | #define USB_CDC_REQ_GET_LINE_CODING 0x21 |
78 | 6c9f886c | balrog | #define USB_CDC_REQ_SET_CONTROL_LINE_STATE 0x22 |
79 | 6c9f886c | balrog | #define USB_CDC_REQ_SEND_BREAK 0x23 |
80 | 6c9f886c | balrog | #define USB_CDC_SET_ETHERNET_MULTICAST_FILTERS 0x40 |
81 | 6c9f886c | balrog | #define USB_CDC_SET_ETHERNET_PM_PATTERN_FILTER 0x41 |
82 | 6c9f886c | balrog | #define USB_CDC_GET_ETHERNET_PM_PATTERN_FILTER 0x42 |
83 | 6c9f886c | balrog | #define USB_CDC_SET_ETHERNET_PACKET_FILTER 0x43 |
84 | 6c9f886c | balrog | #define USB_CDC_GET_ETHERNET_STATISTIC 0x44 |
85 | 6c9f886c | balrog | |
86 | 6c9f886c | balrog | #define LOG2_STATUS_INTERVAL_MSEC 5 /* 1 << 5 == 32 msec */ |
87 | 6c9f886c | balrog | #define STATUS_BYTECOUNT 16 /* 8 byte header + data */ |
88 | 6c9f886c | balrog | |
89 | 6c9f886c | balrog | #define ETH_FRAME_LEN 1514 /* Max. octets in frame sans FCS */ |
90 | 6c9f886c | balrog | |
91 | 30c7d32a | Gerd Hoffmann | static const USBDescStrings usb_net_stringtable = { |
92 | 30c7d32a | Gerd Hoffmann | [STRING_MANUFACTURER] = "QEMU",
|
93 | 30c7d32a | Gerd Hoffmann | [STRING_PRODUCT] = "RNDIS/QEMU USB Network Device",
|
94 | 30c7d32a | Gerd Hoffmann | [STRING_ETHADDR] = "400102030405",
|
95 | 30c7d32a | Gerd Hoffmann | [STRING_DATA] = "QEMU USB Net Data Interface",
|
96 | 30c7d32a | Gerd Hoffmann | [STRING_CONTROL] = "QEMU USB Net Control Interface",
|
97 | 30c7d32a | Gerd Hoffmann | [STRING_RNDIS_CONTROL] = "QEMU USB Net RNDIS Control Interface",
|
98 | 30c7d32a | Gerd Hoffmann | [STRING_CDC] = "QEMU USB Net CDC",
|
99 | 30c7d32a | Gerd Hoffmann | [STRING_SUBSET] = "QEMU USB Net Subset",
|
100 | 30c7d32a | Gerd Hoffmann | [STRING_RNDIS] = "QEMU USB Net RNDIS",
|
101 | 30c7d32a | Gerd Hoffmann | [STRING_SERIALNUMBER] = "1",
|
102 | 6c9f886c | balrog | }; |
103 | 6c9f886c | balrog | |
104 | 30c7d32a | Gerd Hoffmann | static const USBDescIface desc_iface_rndis[] = { |
105 | 30c7d32a | Gerd Hoffmann | { |
106 | 30c7d32a | Gerd Hoffmann | /* RNDIS Control Interface */
|
107 | 30c7d32a | Gerd Hoffmann | .bInterfaceNumber = 0,
|
108 | 30c7d32a | Gerd Hoffmann | .bNumEndpoints = 1,
|
109 | 30c7d32a | Gerd Hoffmann | .bInterfaceClass = USB_CLASS_COMM, |
110 | 30c7d32a | Gerd Hoffmann | .bInterfaceSubClass = USB_CDC_SUBCLASS_ACM, |
111 | 30c7d32a | Gerd Hoffmann | .bInterfaceProtocol = USB_CDC_ACM_PROTO_VENDOR, |
112 | 30c7d32a | Gerd Hoffmann | .iInterface = STRING_RNDIS_CONTROL, |
113 | 30c7d32a | Gerd Hoffmann | .ndesc = 4,
|
114 | 30c7d32a | Gerd Hoffmann | .descs = (USBDescOther[]) { |
115 | 30c7d32a | Gerd Hoffmann | { |
116 | 30c7d32a | Gerd Hoffmann | /* Header Descriptor */
|
117 | 30c7d32a | Gerd Hoffmann | .data = (uint8_t[]) { |
118 | 30c7d32a | Gerd Hoffmann | 0x05, /* u8 bLength */ |
119 | 30c7d32a | Gerd Hoffmann | USB_DT_CS_INTERFACE, /* u8 bDescriptorType */
|
120 | 30c7d32a | Gerd Hoffmann | USB_CDC_HEADER_TYPE, /* u8 bDescriptorSubType */
|
121 | 30c7d32a | Gerd Hoffmann | 0x10, 0x01, /* le16 bcdCDC */ |
122 | 30c7d32a | Gerd Hoffmann | }, |
123 | 30c7d32a | Gerd Hoffmann | },{ |
124 | 30c7d32a | Gerd Hoffmann | /* Call Management Descriptor */
|
125 | 30c7d32a | Gerd Hoffmann | .data = (uint8_t[]) { |
126 | 30c7d32a | Gerd Hoffmann | 0x05, /* u8 bLength */ |
127 | 30c7d32a | Gerd Hoffmann | USB_DT_CS_INTERFACE, /* u8 bDescriptorType */
|
128 | 30c7d32a | Gerd Hoffmann | USB_CDC_CALL_MANAGEMENT_TYPE, /* u8 bDescriptorSubType */
|
129 | 30c7d32a | Gerd Hoffmann | 0x00, /* u8 bmCapabilities */ |
130 | 30c7d32a | Gerd Hoffmann | 0x01, /* u8 bDataInterface */ |
131 | 30c7d32a | Gerd Hoffmann | }, |
132 | 30c7d32a | Gerd Hoffmann | },{ |
133 | 30c7d32a | Gerd Hoffmann | /* ACM Descriptor */
|
134 | 30c7d32a | Gerd Hoffmann | .data = (uint8_t[]) { |
135 | 30c7d32a | Gerd Hoffmann | 0x04, /* u8 bLength */ |
136 | 30c7d32a | Gerd Hoffmann | USB_DT_CS_INTERFACE, /* u8 bDescriptorType */
|
137 | 30c7d32a | Gerd Hoffmann | USB_CDC_ACM_TYPE, /* u8 bDescriptorSubType */
|
138 | 30c7d32a | Gerd Hoffmann | 0x00, /* u8 bmCapabilities */ |
139 | 30c7d32a | Gerd Hoffmann | }, |
140 | 30c7d32a | Gerd Hoffmann | },{ |
141 | 30c7d32a | Gerd Hoffmann | /* Union Descriptor */
|
142 | 30c7d32a | Gerd Hoffmann | .data = (uint8_t[]) { |
143 | 30c7d32a | Gerd Hoffmann | 0x05, /* u8 bLength */ |
144 | 30c7d32a | Gerd Hoffmann | USB_DT_CS_INTERFACE, /* u8 bDescriptorType */
|
145 | 30c7d32a | Gerd Hoffmann | USB_CDC_UNION_TYPE, /* u8 bDescriptorSubType */
|
146 | 30c7d32a | Gerd Hoffmann | 0x00, /* u8 bMasterInterface0 */ |
147 | 30c7d32a | Gerd Hoffmann | 0x01, /* u8 bSlaveInterface0 */ |
148 | 30c7d32a | Gerd Hoffmann | }, |
149 | 30c7d32a | Gerd Hoffmann | }, |
150 | 30c7d32a | Gerd Hoffmann | }, |
151 | 30c7d32a | Gerd Hoffmann | .eps = (USBDescEndpoint[]) { |
152 | 30c7d32a | Gerd Hoffmann | { |
153 | 30c7d32a | Gerd Hoffmann | .bEndpointAddress = USB_DIR_IN | 0x01,
|
154 | 30c7d32a | Gerd Hoffmann | .bmAttributes = USB_ENDPOINT_XFER_INT, |
155 | 30c7d32a | Gerd Hoffmann | .wMaxPacketSize = STATUS_BYTECOUNT, |
156 | 30c7d32a | Gerd Hoffmann | .bInterval = 1 << LOG2_STATUS_INTERVAL_MSEC,
|
157 | 30c7d32a | Gerd Hoffmann | }, |
158 | 30c7d32a | Gerd Hoffmann | } |
159 | 30c7d32a | Gerd Hoffmann | },{ |
160 | 30c7d32a | Gerd Hoffmann | /* RNDIS Data Interface */
|
161 | 30c7d32a | Gerd Hoffmann | .bInterfaceNumber = 1,
|
162 | 30c7d32a | Gerd Hoffmann | .bNumEndpoints = 2,
|
163 | 30c7d32a | Gerd Hoffmann | .bInterfaceClass = USB_CLASS_CDC_DATA, |
164 | 30c7d32a | Gerd Hoffmann | .iInterface = STRING_DATA, |
165 | 30c7d32a | Gerd Hoffmann | .eps = (USBDescEndpoint[]) { |
166 | 30c7d32a | Gerd Hoffmann | { |
167 | 30c7d32a | Gerd Hoffmann | .bEndpointAddress = USB_DIR_IN | 0x02,
|
168 | 30c7d32a | Gerd Hoffmann | .bmAttributes = USB_ENDPOINT_XFER_BULK, |
169 | 30c7d32a | Gerd Hoffmann | .wMaxPacketSize = 0x40,
|
170 | 30c7d32a | Gerd Hoffmann | },{ |
171 | 30c7d32a | Gerd Hoffmann | .bEndpointAddress = USB_DIR_OUT | 0x02,
|
172 | 30c7d32a | Gerd Hoffmann | .bmAttributes = USB_ENDPOINT_XFER_BULK, |
173 | 30c7d32a | Gerd Hoffmann | .wMaxPacketSize = 0x40,
|
174 | 30c7d32a | Gerd Hoffmann | } |
175 | 30c7d32a | Gerd Hoffmann | } |
176 | 30c7d32a | Gerd Hoffmann | } |
177 | 6c9f886c | balrog | }; |
178 | 6c9f886c | balrog | |
179 | 30c7d32a | Gerd Hoffmann | static const USBDescIface desc_iface_cdc[] = { |
180 | 30c7d32a | Gerd Hoffmann | { |
181 | 30c7d32a | Gerd Hoffmann | /* CDC Control Interface */
|
182 | 30c7d32a | Gerd Hoffmann | .bInterfaceNumber = 0,
|
183 | 30c7d32a | Gerd Hoffmann | .bNumEndpoints = 1,
|
184 | 30c7d32a | Gerd Hoffmann | .bInterfaceClass = USB_CLASS_COMM, |
185 | 30c7d32a | Gerd Hoffmann | .bInterfaceSubClass = USB_CDC_SUBCLASS_ETHERNET, |
186 | 30c7d32a | Gerd Hoffmann | .bInterfaceProtocol = USB_CDC_PROTO_NONE, |
187 | 30c7d32a | Gerd Hoffmann | .iInterface = STRING_CONTROL, |
188 | 30c7d32a | Gerd Hoffmann | .ndesc = 3,
|
189 | 30c7d32a | Gerd Hoffmann | .descs = (USBDescOther[]) { |
190 | 30c7d32a | Gerd Hoffmann | { |
191 | 30c7d32a | Gerd Hoffmann | /* Header Descriptor */
|
192 | 30c7d32a | Gerd Hoffmann | .data = (uint8_t[]) { |
193 | 30c7d32a | Gerd Hoffmann | 0x05, /* u8 bLength */ |
194 | 30c7d32a | Gerd Hoffmann | USB_DT_CS_INTERFACE, /* u8 bDescriptorType */
|
195 | 30c7d32a | Gerd Hoffmann | USB_CDC_HEADER_TYPE, /* u8 bDescriptorSubType */
|
196 | 30c7d32a | Gerd Hoffmann | 0x10, 0x01, /* le16 bcdCDC */ |
197 | 30c7d32a | Gerd Hoffmann | }, |
198 | 30c7d32a | Gerd Hoffmann | },{ |
199 | 30c7d32a | Gerd Hoffmann | /* Union Descriptor */
|
200 | 30c7d32a | Gerd Hoffmann | .data = (uint8_t[]) { |
201 | 30c7d32a | Gerd Hoffmann | 0x05, /* u8 bLength */ |
202 | 30c7d32a | Gerd Hoffmann | USB_DT_CS_INTERFACE, /* u8 bDescriptorType */
|
203 | 30c7d32a | Gerd Hoffmann | USB_CDC_UNION_TYPE, /* u8 bDescriptorSubType */
|
204 | 30c7d32a | Gerd Hoffmann | 0x00, /* u8 bMasterInterface0 */ |
205 | 30c7d32a | Gerd Hoffmann | 0x01, /* u8 bSlaveInterface0 */ |
206 | 30c7d32a | Gerd Hoffmann | }, |
207 | 30c7d32a | Gerd Hoffmann | },{ |
208 | 30c7d32a | Gerd Hoffmann | /* Ethernet Descriptor */
|
209 | 30c7d32a | Gerd Hoffmann | .data = (uint8_t[]) { |
210 | 30c7d32a | Gerd Hoffmann | 0x0d, /* u8 bLength */ |
211 | 30c7d32a | Gerd Hoffmann | USB_DT_CS_INTERFACE, /* u8 bDescriptorType */
|
212 | 30c7d32a | Gerd Hoffmann | USB_CDC_ETHERNET_TYPE, /* u8 bDescriptorSubType */
|
213 | 30c7d32a | Gerd Hoffmann | STRING_ETHADDR, /* u8 iMACAddress */
|
214 | 30c7d32a | Gerd Hoffmann | 0x00, 0x00, 0x00, 0x00, /* le32 bmEthernetStatistics */ |
215 | 30c7d32a | Gerd Hoffmann | ETH_FRAME_LEN & 0xff,
|
216 | 30c7d32a | Gerd Hoffmann | ETH_FRAME_LEN >> 8, /* le16 wMaxSegmentSize */ |
217 | 30c7d32a | Gerd Hoffmann | 0x00, 0x00, /* le16 wNumberMCFilters */ |
218 | 30c7d32a | Gerd Hoffmann | 0x00, /* u8 bNumberPowerFilters */ |
219 | 30c7d32a | Gerd Hoffmann | }, |
220 | 30c7d32a | Gerd Hoffmann | }, |
221 | 30c7d32a | Gerd Hoffmann | }, |
222 | 30c7d32a | Gerd Hoffmann | .eps = (USBDescEndpoint[]) { |
223 | 30c7d32a | Gerd Hoffmann | { |
224 | 30c7d32a | Gerd Hoffmann | .bEndpointAddress = USB_DIR_IN | 0x01,
|
225 | 30c7d32a | Gerd Hoffmann | .bmAttributes = USB_ENDPOINT_XFER_INT, |
226 | 30c7d32a | Gerd Hoffmann | .wMaxPacketSize = STATUS_BYTECOUNT, |
227 | 30c7d32a | Gerd Hoffmann | .bInterval = 1 << LOG2_STATUS_INTERVAL_MSEC,
|
228 | 30c7d32a | Gerd Hoffmann | }, |
229 | 30c7d32a | Gerd Hoffmann | } |
230 | 30c7d32a | Gerd Hoffmann | },{ |
231 | 30c7d32a | Gerd Hoffmann | /* CDC Data Interface (off) */
|
232 | 30c7d32a | Gerd Hoffmann | .bInterfaceNumber = 1,
|
233 | 30c7d32a | Gerd Hoffmann | .bAlternateSetting = 0,
|
234 | 30c7d32a | Gerd Hoffmann | .bNumEndpoints = 0,
|
235 | 30c7d32a | Gerd Hoffmann | .bInterfaceClass = USB_CLASS_CDC_DATA, |
236 | 30c7d32a | Gerd Hoffmann | },{ |
237 | 30c7d32a | Gerd Hoffmann | /* CDC Data Interface */
|
238 | 30c7d32a | Gerd Hoffmann | .bInterfaceNumber = 1,
|
239 | 30c7d32a | Gerd Hoffmann | .bAlternateSetting = 1,
|
240 | 30c7d32a | Gerd Hoffmann | .bNumEndpoints = 2,
|
241 | 30c7d32a | Gerd Hoffmann | .bInterfaceClass = USB_CLASS_CDC_DATA, |
242 | 30c7d32a | Gerd Hoffmann | .iInterface = STRING_DATA, |
243 | 30c7d32a | Gerd Hoffmann | .eps = (USBDescEndpoint[]) { |
244 | 30c7d32a | Gerd Hoffmann | { |
245 | 30c7d32a | Gerd Hoffmann | .bEndpointAddress = USB_DIR_IN | 0x02,
|
246 | 30c7d32a | Gerd Hoffmann | .bmAttributes = USB_ENDPOINT_XFER_BULK, |
247 | 30c7d32a | Gerd Hoffmann | .wMaxPacketSize = 0x40,
|
248 | 30c7d32a | Gerd Hoffmann | },{ |
249 | 30c7d32a | Gerd Hoffmann | .bEndpointAddress = USB_DIR_OUT | 0x02,
|
250 | 30c7d32a | Gerd Hoffmann | .bmAttributes = USB_ENDPOINT_XFER_BULK, |
251 | 30c7d32a | Gerd Hoffmann | .wMaxPacketSize = 0x40,
|
252 | 30c7d32a | Gerd Hoffmann | } |
253 | 30c7d32a | Gerd Hoffmann | } |
254 | 30c7d32a | Gerd Hoffmann | } |
255 | 30c7d32a | Gerd Hoffmann | }; |
256 | 30c7d32a | Gerd Hoffmann | |
257 | 30c7d32a | Gerd Hoffmann | static const USBDescDevice desc_device_net = { |
258 | 30c7d32a | Gerd Hoffmann | .bcdUSB = 0x0200,
|
259 | 30c7d32a | Gerd Hoffmann | .bDeviceClass = USB_CLASS_COMM, |
260 | 30c7d32a | Gerd Hoffmann | .bMaxPacketSize0 = 0x40,
|
261 | 30c7d32a | Gerd Hoffmann | .bNumConfigurations = 2,
|
262 | 30c7d32a | Gerd Hoffmann | .confs = (USBDescConfig[]) { |
263 | 30c7d32a | Gerd Hoffmann | { |
264 | 30c7d32a | Gerd Hoffmann | .bNumInterfaces = 2,
|
265 | 30c7d32a | Gerd Hoffmann | .bConfigurationValue = DEV_RNDIS_CONFIG_VALUE, |
266 | 30c7d32a | Gerd Hoffmann | .iConfiguration = STRING_RNDIS, |
267 | 30c7d32a | Gerd Hoffmann | .bmAttributes = 0xc0,
|
268 | 30c7d32a | Gerd Hoffmann | .bMaxPower = 0x32,
|
269 | 30c7d32a | Gerd Hoffmann | .nif = ARRAY_SIZE(desc_iface_rndis), |
270 | 30c7d32a | Gerd Hoffmann | .ifs = desc_iface_rndis, |
271 | 30c7d32a | Gerd Hoffmann | },{ |
272 | 30c7d32a | Gerd Hoffmann | .bNumInterfaces = 2,
|
273 | 30c7d32a | Gerd Hoffmann | .bConfigurationValue = DEV_CONFIG_VALUE, |
274 | 30c7d32a | Gerd Hoffmann | .iConfiguration = STRING_CDC, |
275 | 30c7d32a | Gerd Hoffmann | .bmAttributes = 0xc0,
|
276 | 30c7d32a | Gerd Hoffmann | .bMaxPower = 0x32,
|
277 | 30c7d32a | Gerd Hoffmann | .nif = ARRAY_SIZE(desc_iface_cdc), |
278 | 30c7d32a | Gerd Hoffmann | .ifs = desc_iface_cdc, |
279 | 30c7d32a | Gerd Hoffmann | } |
280 | 30c7d32a | Gerd Hoffmann | }, |
281 | 30c7d32a | Gerd Hoffmann | }; |
282 | 30c7d32a | Gerd Hoffmann | |
283 | 30c7d32a | Gerd Hoffmann | static const USBDesc desc_net = { |
284 | 30c7d32a | Gerd Hoffmann | .id = { |
285 | 30c7d32a | Gerd Hoffmann | .idVendor = RNDIS_VENDOR_NUM, |
286 | 30c7d32a | Gerd Hoffmann | .idProduct = RNDIS_PRODUCT_NUM, |
287 | 30c7d32a | Gerd Hoffmann | .bcdDevice = 0,
|
288 | 30c7d32a | Gerd Hoffmann | .iManufacturer = STRING_MANUFACTURER, |
289 | 30c7d32a | Gerd Hoffmann | .iProduct = STRING_PRODUCT, |
290 | 30c7d32a | Gerd Hoffmann | .iSerialNumber = STRING_SERIALNUMBER, |
291 | 30c7d32a | Gerd Hoffmann | }, |
292 | 30c7d32a | Gerd Hoffmann | .full = &desc_device_net, |
293 | 30c7d32a | Gerd Hoffmann | .str = usb_net_stringtable, |
294 | 6c9f886c | balrog | }; |
295 | 6c9f886c | balrog | |
296 | 6c9f886c | balrog | /*
|
297 | 6c9f886c | balrog | * RNDIS Definitions - in theory not specific to USB.
|
298 | 6c9f886c | balrog | */
|
299 | 6c9f886c | balrog | #define RNDIS_MAXIMUM_FRAME_SIZE 1518 |
300 | 6c9f886c | balrog | #define RNDIS_MAX_TOTAL_SIZE 1558 |
301 | 6c9f886c | balrog | |
302 | 6c9f886c | balrog | /* Remote NDIS Versions */
|
303 | 6c9f886c | balrog | #define RNDIS_MAJOR_VERSION 1 |
304 | 6c9f886c | balrog | #define RNDIS_MINOR_VERSION 0 |
305 | 6c9f886c | balrog | |
306 | 6c9f886c | balrog | /* Status Values */
|
307 | 6c9f886c | balrog | #define RNDIS_STATUS_SUCCESS 0x00000000U /* Success */ |
308 | 6c9f886c | balrog | #define RNDIS_STATUS_FAILURE 0xc0000001U /* Unspecified error */ |
309 | 6c9f886c | balrog | #define RNDIS_STATUS_INVALID_DATA 0xc0010015U /* Invalid data */ |
310 | 6c9f886c | balrog | #define RNDIS_STATUS_NOT_SUPPORTED 0xc00000bbU /* Unsupported request */ |
311 | 6c9f886c | balrog | #define RNDIS_STATUS_MEDIA_CONNECT 0x4001000bU /* Device connected */ |
312 | 6c9f886c | balrog | #define RNDIS_STATUS_MEDIA_DISCONNECT 0x4001000cU /* Device disconnected */ |
313 | 6c9f886c | balrog | |
314 | 6c9f886c | balrog | /* Message Set for Connectionless (802.3) Devices */
|
315 | 6c9f886c | balrog | enum {
|
316 | 6c9f886c | balrog | RNDIS_PACKET_MSG = 1,
|
317 | 6c9f886c | balrog | RNDIS_INITIALIZE_MSG = 2, /* Initialize device */ |
318 | 6c9f886c | balrog | RNDIS_HALT_MSG = 3,
|
319 | 6c9f886c | balrog | RNDIS_QUERY_MSG = 4,
|
320 | 6c9f886c | balrog | RNDIS_SET_MSG = 5,
|
321 | 6c9f886c | balrog | RNDIS_RESET_MSG = 6,
|
322 | 6c9f886c | balrog | RNDIS_INDICATE_STATUS_MSG = 7,
|
323 | 6c9f886c | balrog | RNDIS_KEEPALIVE_MSG = 8,
|
324 | 6c9f886c | balrog | }; |
325 | 6c9f886c | balrog | |
326 | 6c9f886c | balrog | /* Message completion */
|
327 | 6c9f886c | balrog | enum {
|
328 | 6c9f886c | balrog | RNDIS_INITIALIZE_CMPLT = 0x80000002U,
|
329 | 6c9f886c | balrog | RNDIS_QUERY_CMPLT = 0x80000004U,
|
330 | 6c9f886c | balrog | RNDIS_SET_CMPLT = 0x80000005U,
|
331 | 6c9f886c | balrog | RNDIS_RESET_CMPLT = 0x80000006U,
|
332 | 6c9f886c | balrog | RNDIS_KEEPALIVE_CMPLT = 0x80000008U,
|
333 | 6c9f886c | balrog | }; |
334 | 6c9f886c | balrog | |
335 | 6c9f886c | balrog | /* Device Flags */
|
336 | 6c9f886c | balrog | enum {
|
337 | 6c9f886c | balrog | RNDIS_DF_CONNECTIONLESS = 1,
|
338 | 6c9f886c | balrog | RNDIS_DF_CONNECTIONORIENTED = 2,
|
339 | 6c9f886c | balrog | }; |
340 | 6c9f886c | balrog | |
341 | 6c9f886c | balrog | #define RNDIS_MEDIUM_802_3 0x00000000U |
342 | 6c9f886c | balrog | |
343 | 6c9f886c | balrog | /* from drivers/net/sk98lin/h/skgepnmi.h */
|
344 | 6c9f886c | balrog | #define OID_PNP_CAPABILITIES 0xfd010100 |
345 | 6c9f886c | balrog | #define OID_PNP_SET_POWER 0xfd010101 |
346 | 6c9f886c | balrog | #define OID_PNP_QUERY_POWER 0xfd010102 |
347 | 6c9f886c | balrog | #define OID_PNP_ADD_WAKE_UP_PATTERN 0xfd010103 |
348 | 6c9f886c | balrog | #define OID_PNP_REMOVE_WAKE_UP_PATTERN 0xfd010104 |
349 | 6c9f886c | balrog | #define OID_PNP_ENABLE_WAKE_UP 0xfd010106 |
350 | 6c9f886c | balrog | |
351 | 6c9f886c | balrog | typedef uint32_t le32;
|
352 | 6c9f886c | balrog | |
353 | 6c9f886c | balrog | typedef struct rndis_init_msg_type { |
354 | 6c9f886c | balrog | le32 MessageType; |
355 | 6c9f886c | balrog | le32 MessageLength; |
356 | 6c9f886c | balrog | le32 RequestID; |
357 | 6c9f886c | balrog | le32 MajorVersion; |
358 | 6c9f886c | balrog | le32 MinorVersion; |
359 | 6c9f886c | balrog | le32 MaxTransferSize; |
360 | 6c9f886c | balrog | } rndis_init_msg_type; |
361 | 6c9f886c | balrog | |
362 | 6c9f886c | balrog | typedef struct rndis_init_cmplt_type { |
363 | 6c9f886c | balrog | le32 MessageType; |
364 | 6c9f886c | balrog | le32 MessageLength; |
365 | 6c9f886c | balrog | le32 RequestID; |
366 | 6c9f886c | balrog | le32 Status; |
367 | 6c9f886c | balrog | le32 MajorVersion; |
368 | 6c9f886c | balrog | le32 MinorVersion; |
369 | 6c9f886c | balrog | le32 DeviceFlags; |
370 | 6c9f886c | balrog | le32 Medium; |
371 | 6c9f886c | balrog | le32 MaxPacketsPerTransfer; |
372 | 6c9f886c | balrog | le32 MaxTransferSize; |
373 | 6c9f886c | balrog | le32 PacketAlignmentFactor; |
374 | 6c9f886c | balrog | le32 AFListOffset; |
375 | 6c9f886c | balrog | le32 AFListSize; |
376 | 6c9f886c | balrog | } rndis_init_cmplt_type; |
377 | 6c9f886c | balrog | |
378 | 6c9f886c | balrog | typedef struct rndis_halt_msg_type { |
379 | 6c9f886c | balrog | le32 MessageType; |
380 | 6c9f886c | balrog | le32 MessageLength; |
381 | 6c9f886c | balrog | le32 RequestID; |
382 | 6c9f886c | balrog | } rndis_halt_msg_type; |
383 | 6c9f886c | balrog | |
384 | 6c9f886c | balrog | typedef struct rndis_query_msg_type { |
385 | 6c9f886c | balrog | le32 MessageType; |
386 | 6c9f886c | balrog | le32 MessageLength; |
387 | 6c9f886c | balrog | le32 RequestID; |
388 | 6c9f886c | balrog | le32 OID; |
389 | 6c9f886c | balrog | le32 InformationBufferLength; |
390 | 6c9f886c | balrog | le32 InformationBufferOffset; |
391 | 6c9f886c | balrog | le32 DeviceVcHandle; |
392 | 6c9f886c | balrog | } rndis_query_msg_type; |
393 | 6c9f886c | balrog | |
394 | 6c9f886c | balrog | typedef struct rndis_query_cmplt_type { |
395 | 6c9f886c | balrog | le32 MessageType; |
396 | 6c9f886c | balrog | le32 MessageLength; |
397 | 6c9f886c | balrog | le32 RequestID; |
398 | 6c9f886c | balrog | le32 Status; |
399 | 6c9f886c | balrog | le32 InformationBufferLength; |
400 | 6c9f886c | balrog | le32 InformationBufferOffset; |
401 | 6c9f886c | balrog | } rndis_query_cmplt_type; |
402 | 6c9f886c | balrog | |
403 | 6c9f886c | balrog | typedef struct rndis_set_msg_type { |
404 | 6c9f886c | balrog | le32 MessageType; |
405 | 6c9f886c | balrog | le32 MessageLength; |
406 | 6c9f886c | balrog | le32 RequestID; |
407 | 6c9f886c | balrog | le32 OID; |
408 | 6c9f886c | balrog | le32 InformationBufferLength; |
409 | 6c9f886c | balrog | le32 InformationBufferOffset; |
410 | 6c9f886c | balrog | le32 DeviceVcHandle; |
411 | 6c9f886c | balrog | } rndis_set_msg_type; |
412 | 6c9f886c | balrog | |
413 | 6c9f886c | balrog | typedef struct rndis_set_cmplt_type { |
414 | 6c9f886c | balrog | le32 MessageType; |
415 | 6c9f886c | balrog | le32 MessageLength; |
416 | 6c9f886c | balrog | le32 RequestID; |
417 | 6c9f886c | balrog | le32 Status; |
418 | 6c9f886c | balrog | } rndis_set_cmplt_type; |
419 | 6c9f886c | balrog | |
420 | 6c9f886c | balrog | typedef struct rndis_reset_msg_type { |
421 | 6c9f886c | balrog | le32 MessageType; |
422 | 6c9f886c | balrog | le32 MessageLength; |
423 | 6c9f886c | balrog | le32 Reserved; |
424 | 6c9f886c | balrog | } rndis_reset_msg_type; |
425 | 6c9f886c | balrog | |
426 | 6c9f886c | balrog | typedef struct rndis_reset_cmplt_type { |
427 | 6c9f886c | balrog | le32 MessageType; |
428 | 6c9f886c | balrog | le32 MessageLength; |
429 | 6c9f886c | balrog | le32 Status; |
430 | 6c9f886c | balrog | le32 AddressingReset; |
431 | 6c9f886c | balrog | } rndis_reset_cmplt_type; |
432 | 6c9f886c | balrog | |
433 | 6c9f886c | balrog | typedef struct rndis_indicate_status_msg_type { |
434 | 6c9f886c | balrog | le32 MessageType; |
435 | 6c9f886c | balrog | le32 MessageLength; |
436 | 6c9f886c | balrog | le32 Status; |
437 | 6c9f886c | balrog | le32 StatusBufferLength; |
438 | 6c9f886c | balrog | le32 StatusBufferOffset; |
439 | 6c9f886c | balrog | } rndis_indicate_status_msg_type; |
440 | 6c9f886c | balrog | |
441 | 6c9f886c | balrog | typedef struct rndis_keepalive_msg_type { |
442 | 6c9f886c | balrog | le32 MessageType; |
443 | 6c9f886c | balrog | le32 MessageLength; |
444 | 6c9f886c | balrog | le32 RequestID; |
445 | 6c9f886c | balrog | } rndis_keepalive_msg_type; |
446 | 6c9f886c | balrog | |
447 | 6c9f886c | balrog | typedef struct rndis_keepalive_cmplt_type { |
448 | 6c9f886c | balrog | le32 MessageType; |
449 | 6c9f886c | balrog | le32 MessageLength; |
450 | 6c9f886c | balrog | le32 RequestID; |
451 | 6c9f886c | balrog | le32 Status; |
452 | 6c9f886c | balrog | } rndis_keepalive_cmplt_type; |
453 | 6c9f886c | balrog | |
454 | 6c9f886c | balrog | struct rndis_packet_msg_type {
|
455 | 6c9f886c | balrog | le32 MessageType; |
456 | 6c9f886c | balrog | le32 MessageLength; |
457 | 6c9f886c | balrog | le32 DataOffset; |
458 | 6c9f886c | balrog | le32 DataLength; |
459 | 6c9f886c | balrog | le32 OOBDataOffset; |
460 | 6c9f886c | balrog | le32 OOBDataLength; |
461 | 6c9f886c | balrog | le32 NumOOBDataElements; |
462 | 6c9f886c | balrog | le32 PerPacketInfoOffset; |
463 | 6c9f886c | balrog | le32 PerPacketInfoLength; |
464 | 6c9f886c | balrog | le32 VcHandle; |
465 | 6c9f886c | balrog | le32 Reserved; |
466 | 6c9f886c | balrog | }; |
467 | 6c9f886c | balrog | |
468 | 6c9f886c | balrog | struct rndis_config_parameter {
|
469 | 6c9f886c | balrog | le32 ParameterNameOffset; |
470 | 6c9f886c | balrog | le32 ParameterNameLength; |
471 | 6c9f886c | balrog | le32 ParameterType; |
472 | 6c9f886c | balrog | le32 ParameterValueOffset; |
473 | 6c9f886c | balrog | le32 ParameterValueLength; |
474 | 6c9f886c | balrog | }; |
475 | 6c9f886c | balrog | |
476 | 6c9f886c | balrog | /* implementation specific */
|
477 | 6c9f886c | balrog | enum rndis_state
|
478 | 6c9f886c | balrog | { |
479 | 6c9f886c | balrog | RNDIS_UNINITIALIZED, |
480 | 6c9f886c | balrog | RNDIS_INITIALIZED, |
481 | 6c9f886c | balrog | RNDIS_DATA_INITIALIZED, |
482 | 6c9f886c | balrog | }; |
483 | 6c9f886c | balrog | |
484 | 6c9f886c | balrog | /* from ndis.h */
|
485 | 6c9f886c | balrog | enum ndis_oid {
|
486 | 6c9f886c | balrog | /* Required Object IDs (OIDs) */
|
487 | 6c9f886c | balrog | OID_GEN_SUPPORTED_LIST = 0x00010101,
|
488 | 6c9f886c | balrog | OID_GEN_HARDWARE_STATUS = 0x00010102,
|
489 | 6c9f886c | balrog | OID_GEN_MEDIA_SUPPORTED = 0x00010103,
|
490 | 6c9f886c | balrog | OID_GEN_MEDIA_IN_USE = 0x00010104,
|
491 | 6c9f886c | balrog | OID_GEN_MAXIMUM_LOOKAHEAD = 0x00010105,
|
492 | 6c9f886c | balrog | OID_GEN_MAXIMUM_FRAME_SIZE = 0x00010106,
|
493 | 6c9f886c | balrog | OID_GEN_LINK_SPEED = 0x00010107,
|
494 | 6c9f886c | balrog | OID_GEN_TRANSMIT_BUFFER_SPACE = 0x00010108,
|
495 | 6c9f886c | balrog | OID_GEN_RECEIVE_BUFFER_SPACE = 0x00010109,
|
496 | 6c9f886c | balrog | OID_GEN_TRANSMIT_BLOCK_SIZE = 0x0001010a,
|
497 | 6c9f886c | balrog | OID_GEN_RECEIVE_BLOCK_SIZE = 0x0001010b,
|
498 | 6c9f886c | balrog | OID_GEN_VENDOR_ID = 0x0001010c,
|
499 | 6c9f886c | balrog | OID_GEN_VENDOR_DESCRIPTION = 0x0001010d,
|
500 | 6c9f886c | balrog | OID_GEN_CURRENT_PACKET_FILTER = 0x0001010e,
|
501 | 6c9f886c | balrog | OID_GEN_CURRENT_LOOKAHEAD = 0x0001010f,
|
502 | 6c9f886c | balrog | OID_GEN_DRIVER_VERSION = 0x00010110,
|
503 | 6c9f886c | balrog | OID_GEN_MAXIMUM_TOTAL_SIZE = 0x00010111,
|
504 | 6c9f886c | balrog | OID_GEN_PROTOCOL_OPTIONS = 0x00010112,
|
505 | 6c9f886c | balrog | OID_GEN_MAC_OPTIONS = 0x00010113,
|
506 | 6c9f886c | balrog | OID_GEN_MEDIA_CONNECT_STATUS = 0x00010114,
|
507 | 6c9f886c | balrog | OID_GEN_MAXIMUM_SEND_PACKETS = 0x00010115,
|
508 | 6c9f886c | balrog | OID_GEN_VENDOR_DRIVER_VERSION = 0x00010116,
|
509 | 6c9f886c | balrog | OID_GEN_SUPPORTED_GUIDS = 0x00010117,
|
510 | 6c9f886c | balrog | OID_GEN_NETWORK_LAYER_ADDRESSES = 0x00010118,
|
511 | 6c9f886c | balrog | OID_GEN_TRANSPORT_HEADER_OFFSET = 0x00010119,
|
512 | 6c9f886c | balrog | OID_GEN_MACHINE_NAME = 0x0001021a,
|
513 | 6c9f886c | balrog | OID_GEN_RNDIS_CONFIG_PARAMETER = 0x0001021b,
|
514 | 6c9f886c | balrog | OID_GEN_VLAN_ID = 0x0001021c,
|
515 | 6c9f886c | balrog | |
516 | 6c9f886c | balrog | /* Optional OIDs */
|
517 | 6c9f886c | balrog | OID_GEN_MEDIA_CAPABILITIES = 0x00010201,
|
518 | 6c9f886c | balrog | OID_GEN_PHYSICAL_MEDIUM = 0x00010202,
|
519 | 6c9f886c | balrog | |
520 | 6c9f886c | balrog | /* Required statistics OIDs */
|
521 | 6c9f886c | balrog | OID_GEN_XMIT_OK = 0x00020101,
|
522 | 6c9f886c | balrog | OID_GEN_RCV_OK = 0x00020102,
|
523 | 6c9f886c | balrog | OID_GEN_XMIT_ERROR = 0x00020103,
|
524 | 6c9f886c | balrog | OID_GEN_RCV_ERROR = 0x00020104,
|
525 | 6c9f886c | balrog | OID_GEN_RCV_NO_BUFFER = 0x00020105,
|
526 | 6c9f886c | balrog | |
527 | 6c9f886c | balrog | /* Optional statistics OIDs */
|
528 | 6c9f886c | balrog | OID_GEN_DIRECTED_BYTES_XMIT = 0x00020201,
|
529 | 6c9f886c | balrog | OID_GEN_DIRECTED_FRAMES_XMIT = 0x00020202,
|
530 | 6c9f886c | balrog | OID_GEN_MULTICAST_BYTES_XMIT = 0x00020203,
|
531 | 6c9f886c | balrog | OID_GEN_MULTICAST_FRAMES_XMIT = 0x00020204,
|
532 | 6c9f886c | balrog | OID_GEN_BROADCAST_BYTES_XMIT = 0x00020205,
|
533 | 6c9f886c | balrog | OID_GEN_BROADCAST_FRAMES_XMIT = 0x00020206,
|
534 | 6c9f886c | balrog | OID_GEN_DIRECTED_BYTES_RCV = 0x00020207,
|
535 | 6c9f886c | balrog | OID_GEN_DIRECTED_FRAMES_RCV = 0x00020208,
|
536 | 6c9f886c | balrog | OID_GEN_MULTICAST_BYTES_RCV = 0x00020209,
|
537 | 6c9f886c | balrog | OID_GEN_MULTICAST_FRAMES_RCV = 0x0002020a,
|
538 | 6c9f886c | balrog | OID_GEN_BROADCAST_BYTES_RCV = 0x0002020b,
|
539 | 6c9f886c | balrog | OID_GEN_BROADCAST_FRAMES_RCV = 0x0002020c,
|
540 | 6c9f886c | balrog | OID_GEN_RCV_CRC_ERROR = 0x0002020d,
|
541 | 6c9f886c | balrog | OID_GEN_TRANSMIT_QUEUE_LENGTH = 0x0002020e,
|
542 | 6c9f886c | balrog | OID_GEN_GET_TIME_CAPS = 0x0002020f,
|
543 | 6c9f886c | balrog | OID_GEN_GET_NETCARD_TIME = 0x00020210,
|
544 | 6c9f886c | balrog | OID_GEN_NETCARD_LOAD = 0x00020211,
|
545 | 6c9f886c | balrog | OID_GEN_DEVICE_PROFILE = 0x00020212,
|
546 | 6c9f886c | balrog | OID_GEN_INIT_TIME_MS = 0x00020213,
|
547 | 6c9f886c | balrog | OID_GEN_RESET_COUNTS = 0x00020214,
|
548 | 6c9f886c | balrog | OID_GEN_MEDIA_SENSE_COUNTS = 0x00020215,
|
549 | 6c9f886c | balrog | OID_GEN_FRIENDLY_NAME = 0x00020216,
|
550 | 6c9f886c | balrog | OID_GEN_MINIPORT_INFO = 0x00020217,
|
551 | 6c9f886c | balrog | OID_GEN_RESET_VERIFY_PARAMETERS = 0x00020218,
|
552 | 6c9f886c | balrog | |
553 | 6c9f886c | balrog | /* IEEE 802.3 (Ethernet) OIDs */
|
554 | 6c9f886c | balrog | OID_802_3_PERMANENT_ADDRESS = 0x01010101,
|
555 | 6c9f886c | balrog | OID_802_3_CURRENT_ADDRESS = 0x01010102,
|
556 | 6c9f886c | balrog | OID_802_3_MULTICAST_LIST = 0x01010103,
|
557 | 6c9f886c | balrog | OID_802_3_MAXIMUM_LIST_SIZE = 0x01010104,
|
558 | 6c9f886c | balrog | OID_802_3_MAC_OPTIONS = 0x01010105,
|
559 | 6c9f886c | balrog | OID_802_3_RCV_ERROR_ALIGNMENT = 0x01020101,
|
560 | 6c9f886c | balrog | OID_802_3_XMIT_ONE_COLLISION = 0x01020102,
|
561 | 6c9f886c | balrog | OID_802_3_XMIT_MORE_COLLISIONS = 0x01020103,
|
562 | 6c9f886c | balrog | OID_802_3_XMIT_DEFERRED = 0x01020201,
|
563 | 6c9f886c | balrog | OID_802_3_XMIT_MAX_COLLISIONS = 0x01020202,
|
564 | 6c9f886c | balrog | OID_802_3_RCV_OVERRUN = 0x01020203,
|
565 | 6c9f886c | balrog | OID_802_3_XMIT_UNDERRUN = 0x01020204,
|
566 | 6c9f886c | balrog | OID_802_3_XMIT_HEARTBEAT_FAILURE = 0x01020205,
|
567 | 6c9f886c | balrog | OID_802_3_XMIT_TIMES_CRS_LOST = 0x01020206,
|
568 | 6c9f886c | balrog | OID_802_3_XMIT_LATE_COLLISIONS = 0x01020207,
|
569 | 6c9f886c | balrog | }; |
570 | 6c9f886c | balrog | |
571 | 6c9f886c | balrog | static const uint32_t oid_supported_list[] = |
572 | 6c9f886c | balrog | { |
573 | 6c9f886c | balrog | /* the general stuff */
|
574 | 6c9f886c | balrog | OID_GEN_SUPPORTED_LIST, |
575 | 6c9f886c | balrog | OID_GEN_HARDWARE_STATUS, |
576 | 6c9f886c | balrog | OID_GEN_MEDIA_SUPPORTED, |
577 | 6c9f886c | balrog | OID_GEN_MEDIA_IN_USE, |
578 | 6c9f886c | balrog | OID_GEN_MAXIMUM_FRAME_SIZE, |
579 | 6c9f886c | balrog | OID_GEN_LINK_SPEED, |
580 | 6c9f886c | balrog | OID_GEN_TRANSMIT_BLOCK_SIZE, |
581 | 6c9f886c | balrog | OID_GEN_RECEIVE_BLOCK_SIZE, |
582 | 6c9f886c | balrog | OID_GEN_VENDOR_ID, |
583 | 6c9f886c | balrog | OID_GEN_VENDOR_DESCRIPTION, |
584 | 6c9f886c | balrog | OID_GEN_VENDOR_DRIVER_VERSION, |
585 | 6c9f886c | balrog | OID_GEN_CURRENT_PACKET_FILTER, |
586 | 6c9f886c | balrog | OID_GEN_MAXIMUM_TOTAL_SIZE, |
587 | 6c9f886c | balrog | OID_GEN_MEDIA_CONNECT_STATUS, |
588 | 6c9f886c | balrog | OID_GEN_PHYSICAL_MEDIUM, |
589 | 6c9f886c | balrog | |
590 | 6c9f886c | balrog | /* the statistical stuff */
|
591 | 6c9f886c | balrog | OID_GEN_XMIT_OK, |
592 | 6c9f886c | balrog | OID_GEN_RCV_OK, |
593 | 6c9f886c | balrog | OID_GEN_XMIT_ERROR, |
594 | 6c9f886c | balrog | OID_GEN_RCV_ERROR, |
595 | 6c9f886c | balrog | OID_GEN_RCV_NO_BUFFER, |
596 | 6c9f886c | balrog | |
597 | 6c9f886c | balrog | /* IEEE 802.3 */
|
598 | 6c9f886c | balrog | /* the general stuff */
|
599 | 6c9f886c | balrog | OID_802_3_PERMANENT_ADDRESS, |
600 | 6c9f886c | balrog | OID_802_3_CURRENT_ADDRESS, |
601 | 6c9f886c | balrog | OID_802_3_MULTICAST_LIST, |
602 | 6c9f886c | balrog | OID_802_3_MAC_OPTIONS, |
603 | 6c9f886c | balrog | OID_802_3_MAXIMUM_LIST_SIZE, |
604 | 6c9f886c | balrog | |
605 | 6c9f886c | balrog | /* the statistical stuff */
|
606 | 6c9f886c | balrog | OID_802_3_RCV_ERROR_ALIGNMENT, |
607 | 6c9f886c | balrog | OID_802_3_XMIT_ONE_COLLISION, |
608 | 6c9f886c | balrog | OID_802_3_XMIT_MORE_COLLISIONS, |
609 | 6c9f886c | balrog | }; |
610 | 6c9f886c | balrog | |
611 | 6c9f886c | balrog | #define NDIS_MAC_OPTION_COPY_LOOKAHEAD_DATA (1 << 0) |
612 | 6c9f886c | balrog | #define NDIS_MAC_OPTION_RECEIVE_SERIALIZED (1 << 1) |
613 | 6c9f886c | balrog | #define NDIS_MAC_OPTION_TRANSFERS_NOT_PEND (1 << 2) |
614 | 6c9f886c | balrog | #define NDIS_MAC_OPTION_NO_LOOPBACK (1 << 3) |
615 | 6c9f886c | balrog | #define NDIS_MAC_OPTION_FULL_DUPLEX (1 << 4) |
616 | 6c9f886c | balrog | #define NDIS_MAC_OPTION_EOTX_INDICATION (1 << 5) |
617 | 6c9f886c | balrog | #define NDIS_MAC_OPTION_8021P_PRIORITY (1 << 6) |
618 | 6c9f886c | balrog | |
619 | 6c9f886c | balrog | struct rndis_response {
|
620 | 72cf2d4f | Blue Swirl | QTAILQ_ENTRY(rndis_response) entries; |
621 | 6c9f886c | balrog | uint32_t length; |
622 | 6c9f886c | balrog | uint8_t buf[0];
|
623 | 6c9f886c | balrog | }; |
624 | 6c9f886c | balrog | |
625 | 6c9f886c | balrog | typedef struct USBNetState { |
626 | 6c9f886c | balrog | USBDevice dev; |
627 | 6c9f886c | balrog | |
628 | 6c9f886c | balrog | enum rndis_state rndis_state;
|
629 | 6c9f886c | balrog | uint32_t medium; |
630 | 6c9f886c | balrog | uint32_t speed; |
631 | 6c9f886c | balrog | uint32_t media_state; |
632 | 6c9f886c | balrog | uint16_t filter; |
633 | 6c9f886c | balrog | uint32_t vendorid; |
634 | 6c9f886c | balrog | |
635 | 6c9f886c | balrog | unsigned int out_ptr; |
636 | 6c9f886c | balrog | uint8_t out_buf[2048];
|
637 | 6c9f886c | balrog | |
638 | 6c9f886c | balrog | USBPacket *inpkt; |
639 | 6c9f886c | balrog | unsigned int in_ptr, in_len; |
640 | 6c9f886c | balrog | uint8_t in_buf[2048];
|
641 | 6c9f886c | balrog | |
642 | 6c9f886c | balrog | char usbstring_mac[13]; |
643 | e0394b8b | Mark McLoughlin | NICState *nic; |
644 | e0394b8b | Mark McLoughlin | NICConf conf; |
645 | 72cf2d4f | Blue Swirl | QTAILQ_HEAD(rndis_resp_head, rndis_response) rndis_resp; |
646 | 6c9f886c | balrog | } USBNetState; |
647 | 6c9f886c | balrog | |
648 | a980a065 | Gerd Hoffmann | static int is_rndis(USBNetState *s) |
649 | a980a065 | Gerd Hoffmann | { |
650 | a980a065 | Gerd Hoffmann | return s->dev.config->bConfigurationValue == DEV_RNDIS_CONFIG_VALUE;
|
651 | a980a065 | Gerd Hoffmann | } |
652 | a980a065 | Gerd Hoffmann | |
653 | 6c9f886c | balrog | static int ndis_query(USBNetState *s, uint32_t oid, |
654 | 363a37d5 | blueswir1 | uint8_t *inbuf, unsigned int inlen, uint8_t *outbuf, |
655 | 363a37d5 | blueswir1 | size_t outlen) |
656 | 6c9f886c | balrog | { |
657 | b1503cda | malc | unsigned int i; |
658 | 6c9f886c | balrog | |
659 | 6c9f886c | balrog | switch (oid) {
|
660 | 6c9f886c | balrog | /* general oids (table 4-1) */
|
661 | 6c9f886c | balrog | /* mandatory */
|
662 | 6c9f886c | balrog | case OID_GEN_SUPPORTED_LIST:
|
663 | b1503cda | malc | for (i = 0; i < ARRAY_SIZE(oid_supported_list); i++) |
664 | 6c9f886c | balrog | ((le32 *) outbuf)[i] = cpu_to_le32(oid_supported_list[i]); |
665 | 6c9f886c | balrog | return sizeof(oid_supported_list); |
666 | 6c9f886c | balrog | |
667 | 6c9f886c | balrog | /* mandatory */
|
668 | 6c9f886c | balrog | case OID_GEN_HARDWARE_STATUS:
|
669 | 6c9f886c | balrog | *((le32 *) outbuf) = cpu_to_le32(0);
|
670 | 6c9f886c | balrog | return sizeof(le32); |
671 | 6c9f886c | balrog | |
672 | 6c9f886c | balrog | /* mandatory */
|
673 | 6c9f886c | balrog | case OID_GEN_MEDIA_SUPPORTED:
|
674 | 6c9f886c | balrog | *((le32 *) outbuf) = cpu_to_le32(s->medium); |
675 | 6c9f886c | balrog | return sizeof(le32); |
676 | 6c9f886c | balrog | |
677 | 6c9f886c | balrog | /* mandatory */
|
678 | 6c9f886c | balrog | case OID_GEN_MEDIA_IN_USE:
|
679 | 6c9f886c | balrog | *((le32 *) outbuf) = cpu_to_le32(s->medium); |
680 | 6c9f886c | balrog | return sizeof(le32); |
681 | 6c9f886c | balrog | |
682 | 6c9f886c | balrog | /* mandatory */
|
683 | 6c9f886c | balrog | case OID_GEN_MAXIMUM_FRAME_SIZE:
|
684 | 6c9f886c | balrog | *((le32 *) outbuf) = cpu_to_le32(ETH_FRAME_LEN); |
685 | 6c9f886c | balrog | return sizeof(le32); |
686 | 6c9f886c | balrog | |
687 | 6c9f886c | balrog | /* mandatory */
|
688 | 6c9f886c | balrog | case OID_GEN_LINK_SPEED:
|
689 | 6c9f886c | balrog | *((le32 *) outbuf) = cpu_to_le32(s->speed); |
690 | 6c9f886c | balrog | return sizeof(le32); |
691 | 6c9f886c | balrog | |
692 | 6c9f886c | balrog | /* mandatory */
|
693 | 6c9f886c | balrog | case OID_GEN_TRANSMIT_BLOCK_SIZE:
|
694 | 6c9f886c | balrog | *((le32 *) outbuf) = cpu_to_le32(ETH_FRAME_LEN); |
695 | 6c9f886c | balrog | return sizeof(le32); |
696 | 6c9f886c | balrog | |
697 | 6c9f886c | balrog | /* mandatory */
|
698 | 6c9f886c | balrog | case OID_GEN_RECEIVE_BLOCK_SIZE:
|
699 | 6c9f886c | balrog | *((le32 *) outbuf) = cpu_to_le32(ETH_FRAME_LEN); |
700 | 6c9f886c | balrog | return sizeof(le32); |
701 | 6c9f886c | balrog | |
702 | 6c9f886c | balrog | /* mandatory */
|
703 | 6c9f886c | balrog | case OID_GEN_VENDOR_ID:
|
704 | 6c9f886c | balrog | *((le32 *) outbuf) = cpu_to_le32(s->vendorid); |
705 | 6c9f886c | balrog | return sizeof(le32); |
706 | 6c9f886c | balrog | |
707 | 6c9f886c | balrog | /* mandatory */
|
708 | 6c9f886c | balrog | case OID_GEN_VENDOR_DESCRIPTION:
|
709 | b55266b5 | blueswir1 | pstrcpy((char *)outbuf, outlen, "QEMU USB RNDIS Net"); |
710 | b55266b5 | blueswir1 | return strlen((char *)outbuf) + 1; |
711 | 6c9f886c | balrog | |
712 | 6c9f886c | balrog | case OID_GEN_VENDOR_DRIVER_VERSION:
|
713 | 6c9f886c | balrog | *((le32 *) outbuf) = cpu_to_le32(1);
|
714 | 6c9f886c | balrog | return sizeof(le32); |
715 | 6c9f886c | balrog | |
716 | 6c9f886c | balrog | /* mandatory */
|
717 | 6c9f886c | balrog | case OID_GEN_CURRENT_PACKET_FILTER:
|
718 | 6c9f886c | balrog | *((le32 *) outbuf) = cpu_to_le32(s->filter); |
719 | 6c9f886c | balrog | return sizeof(le32); |
720 | 6c9f886c | balrog | |
721 | 6c9f886c | balrog | /* mandatory */
|
722 | 6c9f886c | balrog | case OID_GEN_MAXIMUM_TOTAL_SIZE:
|
723 | 6c9f886c | balrog | *((le32 *) outbuf) = cpu_to_le32(RNDIS_MAX_TOTAL_SIZE); |
724 | 6c9f886c | balrog | return sizeof(le32); |
725 | 6c9f886c | balrog | |
726 | 6c9f886c | balrog | /* mandatory */
|
727 | 6c9f886c | balrog | case OID_GEN_MEDIA_CONNECT_STATUS:
|
728 | 6c9f886c | balrog | *((le32 *) outbuf) = cpu_to_le32(s->media_state); |
729 | 6c9f886c | balrog | return sizeof(le32); |
730 | 6c9f886c | balrog | |
731 | 6c9f886c | balrog | case OID_GEN_PHYSICAL_MEDIUM:
|
732 | 6c9f886c | balrog | *((le32 *) outbuf) = cpu_to_le32(0);
|
733 | 6c9f886c | balrog | return sizeof(le32); |
734 | 6c9f886c | balrog | |
735 | 6c9f886c | balrog | case OID_GEN_MAC_OPTIONS:
|
736 | 6c9f886c | balrog | *((le32 *) outbuf) = cpu_to_le32( |
737 | 6c9f886c | balrog | NDIS_MAC_OPTION_RECEIVE_SERIALIZED | |
738 | 6c9f886c | balrog | NDIS_MAC_OPTION_FULL_DUPLEX); |
739 | 6c9f886c | balrog | return sizeof(le32); |
740 | 6c9f886c | balrog | |
741 | 6c9f886c | balrog | /* statistics OIDs (table 4-2) */
|
742 | 6c9f886c | balrog | /* mandatory */
|
743 | 6c9f886c | balrog | case OID_GEN_XMIT_OK:
|
744 | 6c9f886c | balrog | *((le32 *) outbuf) = cpu_to_le32(0);
|
745 | 6c9f886c | balrog | return sizeof(le32); |
746 | 6c9f886c | balrog | |
747 | 6c9f886c | balrog | /* mandatory */
|
748 | 6c9f886c | balrog | case OID_GEN_RCV_OK:
|
749 | 6c9f886c | balrog | *((le32 *) outbuf) = cpu_to_le32(0);
|
750 | 6c9f886c | balrog | return sizeof(le32); |
751 | 6c9f886c | balrog | |
752 | 6c9f886c | balrog | /* mandatory */
|
753 | 6c9f886c | balrog | case OID_GEN_XMIT_ERROR:
|
754 | 6c9f886c | balrog | *((le32 *) outbuf) = cpu_to_le32(0);
|
755 | 6c9f886c | balrog | return sizeof(le32); |
756 | 6c9f886c | balrog | |
757 | 6c9f886c | balrog | /* mandatory */
|
758 | 6c9f886c | balrog | case OID_GEN_RCV_ERROR:
|
759 | 6c9f886c | balrog | *((le32 *) outbuf) = cpu_to_le32(0);
|
760 | 6c9f886c | balrog | return sizeof(le32); |
761 | 6c9f886c | balrog | |
762 | 6c9f886c | balrog | /* mandatory */
|
763 | 6c9f886c | balrog | case OID_GEN_RCV_NO_BUFFER:
|
764 | 6c9f886c | balrog | *((le32 *) outbuf) = cpu_to_le32(0);
|
765 | 6c9f886c | balrog | return sizeof(le32); |
766 | 6c9f886c | balrog | |
767 | 6c9f886c | balrog | /* ieee802.3 OIDs (table 4-3) */
|
768 | 6c9f886c | balrog | /* mandatory */
|
769 | 6c9f886c | balrog | case OID_802_3_PERMANENT_ADDRESS:
|
770 | e0394b8b | Mark McLoughlin | memcpy(outbuf, s->conf.macaddr.a, 6);
|
771 | 6c9f886c | balrog | return 6; |
772 | 6c9f886c | balrog | |
773 | 6c9f886c | balrog | /* mandatory */
|
774 | 6c9f886c | balrog | case OID_802_3_CURRENT_ADDRESS:
|
775 | e0394b8b | Mark McLoughlin | memcpy(outbuf, s->conf.macaddr.a, 6);
|
776 | 6c9f886c | balrog | return 6; |
777 | 6c9f886c | balrog | |
778 | 6c9f886c | balrog | /* mandatory */
|
779 | 6c9f886c | balrog | case OID_802_3_MULTICAST_LIST:
|
780 | 6c9f886c | balrog | *((le32 *) outbuf) = cpu_to_le32(0xe0000000);
|
781 | 6c9f886c | balrog | return sizeof(le32); |
782 | 6c9f886c | balrog | |
783 | 6c9f886c | balrog | /* mandatory */
|
784 | 6c9f886c | balrog | case OID_802_3_MAXIMUM_LIST_SIZE:
|
785 | 6c9f886c | balrog | *((le32 *) outbuf) = cpu_to_le32(1);
|
786 | 6c9f886c | balrog | return sizeof(le32); |
787 | 6c9f886c | balrog | |
788 | 6c9f886c | balrog | case OID_802_3_MAC_OPTIONS:
|
789 | 6c9f886c | balrog | return 0; |
790 | 6c9f886c | balrog | |
791 | 6c9f886c | balrog | /* ieee802.3 statistics OIDs (table 4-4) */
|
792 | 6c9f886c | balrog | /* mandatory */
|
793 | 6c9f886c | balrog | case OID_802_3_RCV_ERROR_ALIGNMENT:
|
794 | 6c9f886c | balrog | *((le32 *) outbuf) = cpu_to_le32(0);
|
795 | 6c9f886c | balrog | return sizeof(le32); |
796 | 6c9f886c | balrog | |
797 | 6c9f886c | balrog | /* mandatory */
|
798 | 6c9f886c | balrog | case OID_802_3_XMIT_ONE_COLLISION:
|
799 | 6c9f886c | balrog | *((le32 *) outbuf) = cpu_to_le32(0);
|
800 | 6c9f886c | balrog | return sizeof(le32); |
801 | 6c9f886c | balrog | |
802 | 6c9f886c | balrog | /* mandatory */
|
803 | 6c9f886c | balrog | case OID_802_3_XMIT_MORE_COLLISIONS:
|
804 | 6c9f886c | balrog | *((le32 *) outbuf) = cpu_to_le32(0);
|
805 | 6c9f886c | balrog | return sizeof(le32); |
806 | 6c9f886c | balrog | |
807 | 6c9f886c | balrog | default:
|
808 | 6c9f886c | balrog | fprintf(stderr, "usbnet: unknown OID 0x%08x\n", oid);
|
809 | 6c9f886c | balrog | return 0; |
810 | 6c9f886c | balrog | } |
811 | 6c9f886c | balrog | return -1; |
812 | 6c9f886c | balrog | } |
813 | 6c9f886c | balrog | |
814 | 6c9f886c | balrog | static int ndis_set(USBNetState *s, uint32_t oid, |
815 | 6c9f886c | balrog | uint8_t *inbuf, unsigned int inlen) |
816 | 6c9f886c | balrog | { |
817 | 6c9f886c | balrog | switch (oid) {
|
818 | 6c9f886c | balrog | case OID_GEN_CURRENT_PACKET_FILTER:
|
819 | 6c9f886c | balrog | s->filter = le32_to_cpup((le32 *) inbuf); |
820 | 6c9f886c | balrog | if (s->filter) {
|
821 | 6c9f886c | balrog | s->rndis_state = RNDIS_DATA_INITIALIZED; |
822 | 6c9f886c | balrog | } else {
|
823 | 6c9f886c | balrog | s->rndis_state = RNDIS_INITIALIZED; |
824 | 6c9f886c | balrog | } |
825 | 6c9f886c | balrog | return 0; |
826 | 6c9f886c | balrog | |
827 | 6c9f886c | balrog | case OID_802_3_MULTICAST_LIST:
|
828 | 6c9f886c | balrog | return 0; |
829 | 6c9f886c | balrog | } |
830 | 6c9f886c | balrog | return -1; |
831 | 6c9f886c | balrog | } |
832 | 6c9f886c | balrog | |
833 | 6c9f886c | balrog | static int rndis_get_response(USBNetState *s, uint8_t *buf) |
834 | 6c9f886c | balrog | { |
835 | 6c9f886c | balrog | int ret = 0; |
836 | 6c9f886c | balrog | struct rndis_response *r = s->rndis_resp.tqh_first;
|
837 | 6c9f886c | balrog | |
838 | 6c9f886c | balrog | if (!r)
|
839 | 6c9f886c | balrog | return ret;
|
840 | 6c9f886c | balrog | |
841 | 72cf2d4f | Blue Swirl | QTAILQ_REMOVE(&s->rndis_resp, r, entries); |
842 | 6c9f886c | balrog | ret = r->length; |
843 | 6c9f886c | balrog | memcpy(buf, r->buf, r->length); |
844 | 7267c094 | Anthony Liguori | g_free(r); |
845 | 6c9f886c | balrog | |
846 | 6c9f886c | balrog | return ret;
|
847 | 6c9f886c | balrog | } |
848 | 6c9f886c | balrog | |
849 | 6c9f886c | balrog | static void *rndis_queue_response(USBNetState *s, unsigned int length) |
850 | 6c9f886c | balrog | { |
851 | 6c9f886c | balrog | struct rndis_response *r =
|
852 | 7267c094 | Anthony Liguori | g_malloc0(sizeof(struct rndis_response) + length); |
853 | 6c9f886c | balrog | |
854 | 72cf2d4f | Blue Swirl | QTAILQ_INSERT_TAIL(&s->rndis_resp, r, entries); |
855 | 6c9f886c | balrog | r->length = length; |
856 | 6c9f886c | balrog | |
857 | 6c9f886c | balrog | return &r->buf[0]; |
858 | 6c9f886c | balrog | } |
859 | 6c9f886c | balrog | |
860 | 6c9f886c | balrog | static void rndis_clear_responsequeue(USBNetState *s) |
861 | 6c9f886c | balrog | { |
862 | 6c9f886c | balrog | struct rndis_response *r;
|
863 | 6c9f886c | balrog | |
864 | 6c9f886c | balrog | while ((r = s->rndis_resp.tqh_first)) {
|
865 | 72cf2d4f | Blue Swirl | QTAILQ_REMOVE(&s->rndis_resp, r, entries); |
866 | 7267c094 | Anthony Liguori | g_free(r); |
867 | 6c9f886c | balrog | } |
868 | 6c9f886c | balrog | } |
869 | 6c9f886c | balrog | |
870 | 6c9f886c | balrog | static int rndis_init_response(USBNetState *s, rndis_init_msg_type *buf) |
871 | 6c9f886c | balrog | { |
872 | 6c9f886c | balrog | rndis_init_cmplt_type *resp = |
873 | 6c9f886c | balrog | rndis_queue_response(s, sizeof(rndis_init_cmplt_type));
|
874 | 6c9f886c | balrog | |
875 | 6c9f886c | balrog | if (!resp)
|
876 | 6c9f886c | balrog | return USB_RET_STALL;
|
877 | 6c9f886c | balrog | |
878 | 6c9f886c | balrog | resp->MessageType = cpu_to_le32(RNDIS_INITIALIZE_CMPLT); |
879 | 6c9f886c | balrog | resp->MessageLength = cpu_to_le32(sizeof(rndis_init_cmplt_type));
|
880 | 6c9f886c | balrog | resp->RequestID = buf->RequestID; /* Still LE in msg buffer */
|
881 | 6c9f886c | balrog | resp->Status = cpu_to_le32(RNDIS_STATUS_SUCCESS); |
882 | 6c9f886c | balrog | resp->MajorVersion = cpu_to_le32(RNDIS_MAJOR_VERSION); |
883 | 6c9f886c | balrog | resp->MinorVersion = cpu_to_le32(RNDIS_MINOR_VERSION); |
884 | 6c9f886c | balrog | resp->DeviceFlags = cpu_to_le32(RNDIS_DF_CONNECTIONLESS); |
885 | 6c9f886c | balrog | resp->Medium = cpu_to_le32(RNDIS_MEDIUM_802_3); |
886 | 6c9f886c | balrog | resp->MaxPacketsPerTransfer = cpu_to_le32(1);
|
887 | 6c9f886c | balrog | resp->MaxTransferSize = cpu_to_le32(ETH_FRAME_LEN + |
888 | 6c9f886c | balrog | sizeof(struct rndis_packet_msg_type) + 22); |
889 | 6c9f886c | balrog | resp->PacketAlignmentFactor = cpu_to_le32(0);
|
890 | 6c9f886c | balrog | resp->AFListOffset = cpu_to_le32(0);
|
891 | 6c9f886c | balrog | resp->AFListSize = cpu_to_le32(0);
|
892 | 6c9f886c | balrog | return 0; |
893 | 6c9f886c | balrog | } |
894 | 6c9f886c | balrog | |
895 | 6c9f886c | balrog | static int rndis_query_response(USBNetState *s, |
896 | 6c9f886c | balrog | rndis_query_msg_type *buf, unsigned int length) |
897 | 6c9f886c | balrog | { |
898 | 6c9f886c | balrog | rndis_query_cmplt_type *resp; |
899 | 6c9f886c | balrog | /* oid_supported_list is the largest data reply */
|
900 | 6c9f886c | balrog | uint8_t infobuf[sizeof(oid_supported_list)];
|
901 | 6c9f886c | balrog | uint32_t bufoffs, buflen; |
902 | 6c9f886c | balrog | int infobuflen;
|
903 | 6c9f886c | balrog | unsigned int resplen; |
904 | 6c9f886c | balrog | |
905 | 6c9f886c | balrog | bufoffs = le32_to_cpu(buf->InformationBufferOffset) + 8;
|
906 | 6c9f886c | balrog | buflen = le32_to_cpu(buf->InformationBufferLength); |
907 | 6c9f886c | balrog | if (bufoffs + buflen > length)
|
908 | 6c9f886c | balrog | return USB_RET_STALL;
|
909 | 6c9f886c | balrog | |
910 | 6c9f886c | balrog | infobuflen = ndis_query(s, le32_to_cpu(buf->OID), |
911 | 363a37d5 | blueswir1 | bufoffs + (uint8_t *) buf, buflen, infobuf, |
912 | 363a37d5 | blueswir1 | sizeof(infobuf));
|
913 | 6c9f886c | balrog | resplen = sizeof(rndis_query_cmplt_type) +
|
914 | 6c9f886c | balrog | ((infobuflen < 0) ? 0 : infobuflen); |
915 | 6c9f886c | balrog | resp = rndis_queue_response(s, resplen); |
916 | 6c9f886c | balrog | if (!resp)
|
917 | 6c9f886c | balrog | return USB_RET_STALL;
|
918 | 6c9f886c | balrog | |
919 | 6c9f886c | balrog | resp->MessageType = cpu_to_le32(RNDIS_QUERY_CMPLT); |
920 | 6c9f886c | balrog | resp->RequestID = buf->RequestID; /* Still LE in msg buffer */
|
921 | 6c9f886c | balrog | resp->MessageLength = cpu_to_le32(resplen); |
922 | 6c9f886c | balrog | |
923 | 6c9f886c | balrog | if (infobuflen < 0) { |
924 | 6c9f886c | balrog | /* OID not supported */
|
925 | 6c9f886c | balrog | resp->Status = cpu_to_le32(RNDIS_STATUS_NOT_SUPPORTED); |
926 | 6c9f886c | balrog | resp->InformationBufferLength = cpu_to_le32(0);
|
927 | 6c9f886c | balrog | resp->InformationBufferOffset = cpu_to_le32(0);
|
928 | 6c9f886c | balrog | return 0; |
929 | 6c9f886c | balrog | } |
930 | 6c9f886c | balrog | |
931 | 6c9f886c | balrog | resp->Status = cpu_to_le32(RNDIS_STATUS_SUCCESS); |
932 | 6c9f886c | balrog | resp->InformationBufferOffset = |
933 | 6c9f886c | balrog | cpu_to_le32(infobuflen ? sizeof(rndis_query_cmplt_type) - 8 : 0); |
934 | 6c9f886c | balrog | resp->InformationBufferLength = cpu_to_le32(infobuflen); |
935 | 6c9f886c | balrog | memcpy(resp + 1, infobuf, infobuflen);
|
936 | 6c9f886c | balrog | |
937 | 6c9f886c | balrog | return 0; |
938 | 6c9f886c | balrog | } |
939 | 6c9f886c | balrog | |
940 | 6c9f886c | balrog | static int rndis_set_response(USBNetState *s, |
941 | 6c9f886c | balrog | rndis_set_msg_type *buf, unsigned int length) |
942 | 6c9f886c | balrog | { |
943 | 6c9f886c | balrog | rndis_set_cmplt_type *resp = |
944 | 6c9f886c | balrog | rndis_queue_response(s, sizeof(rndis_set_cmplt_type));
|
945 | 6c9f886c | balrog | uint32_t bufoffs, buflen; |
946 | 6c9f886c | balrog | int ret;
|
947 | 6c9f886c | balrog | |
948 | 6c9f886c | balrog | if (!resp)
|
949 | 6c9f886c | balrog | return USB_RET_STALL;
|
950 | 6c9f886c | balrog | |
951 | 6c9f886c | balrog | bufoffs = le32_to_cpu(buf->InformationBufferOffset) + 8;
|
952 | 6c9f886c | balrog | buflen = le32_to_cpu(buf->InformationBufferLength); |
953 | 6c9f886c | balrog | if (bufoffs + buflen > length)
|
954 | 6c9f886c | balrog | return USB_RET_STALL;
|
955 | 6c9f886c | balrog | |
956 | 6c9f886c | balrog | ret = ndis_set(s, le32_to_cpu(buf->OID), |
957 | 6c9f886c | balrog | bufoffs + (uint8_t *) buf, buflen); |
958 | 6c9f886c | balrog | resp->MessageType = cpu_to_le32(RNDIS_SET_CMPLT); |
959 | 6c9f886c | balrog | resp->RequestID = buf->RequestID; /* Still LE in msg buffer */
|
960 | 6c9f886c | balrog | resp->MessageLength = cpu_to_le32(sizeof(rndis_set_cmplt_type));
|
961 | 6c9f886c | balrog | if (ret < 0) { |
962 | 6c9f886c | balrog | /* OID not supported */
|
963 | 6c9f886c | balrog | resp->Status = cpu_to_le32(RNDIS_STATUS_NOT_SUPPORTED); |
964 | 6c9f886c | balrog | return 0; |
965 | 6c9f886c | balrog | } |
966 | 6c9f886c | balrog | resp->Status = cpu_to_le32(RNDIS_STATUS_SUCCESS); |
967 | 6c9f886c | balrog | |
968 | 6c9f886c | balrog | return 0; |
969 | 6c9f886c | balrog | } |
970 | 6c9f886c | balrog | |
971 | 6c9f886c | balrog | static int rndis_reset_response(USBNetState *s, rndis_reset_msg_type *buf) |
972 | 6c9f886c | balrog | { |
973 | 6c9f886c | balrog | rndis_reset_cmplt_type *resp = |
974 | 6c9f886c | balrog | rndis_queue_response(s, sizeof(rndis_reset_cmplt_type));
|
975 | 6c9f886c | balrog | |
976 | 6c9f886c | balrog | if (!resp)
|
977 | 6c9f886c | balrog | return USB_RET_STALL;
|
978 | 6c9f886c | balrog | |
979 | 6c9f886c | balrog | resp->MessageType = cpu_to_le32(RNDIS_RESET_CMPLT); |
980 | 6c9f886c | balrog | resp->MessageLength = cpu_to_le32(sizeof(rndis_reset_cmplt_type));
|
981 | 6c9f886c | balrog | resp->Status = cpu_to_le32(RNDIS_STATUS_SUCCESS); |
982 | 6c9f886c | balrog | resp->AddressingReset = cpu_to_le32(1); /* reset information */ |
983 | 6c9f886c | balrog | |
984 | 6c9f886c | balrog | return 0; |
985 | 6c9f886c | balrog | } |
986 | 6c9f886c | balrog | |
987 | 6c9f886c | balrog | static int rndis_keepalive_response(USBNetState *s, |
988 | 6c9f886c | balrog | rndis_keepalive_msg_type *buf) |
989 | 6c9f886c | balrog | { |
990 | 6c9f886c | balrog | rndis_keepalive_cmplt_type *resp = |
991 | 6c9f886c | balrog | rndis_queue_response(s, sizeof(rndis_keepalive_cmplt_type));
|
992 | 6c9f886c | balrog | |
993 | 6c9f886c | balrog | if (!resp)
|
994 | 6c9f886c | balrog | return USB_RET_STALL;
|
995 | 6c9f886c | balrog | |
996 | 6c9f886c | balrog | resp->MessageType = cpu_to_le32(RNDIS_KEEPALIVE_CMPLT); |
997 | 6c9f886c | balrog | resp->MessageLength = cpu_to_le32(sizeof(rndis_keepalive_cmplt_type));
|
998 | 6c9f886c | balrog | resp->RequestID = buf->RequestID; /* Still LE in msg buffer */
|
999 | 6c9f886c | balrog | resp->Status = cpu_to_le32(RNDIS_STATUS_SUCCESS); |
1000 | 6c9f886c | balrog | |
1001 | 6c9f886c | balrog | return 0; |
1002 | 6c9f886c | balrog | } |
1003 | 6c9f886c | balrog | |
1004 | 6c9f886c | balrog | static int rndis_parse(USBNetState *s, uint8_t *data, int length) |
1005 | 6c9f886c | balrog | { |
1006 | d4c4e6fd | Blue Swirl | uint32_t msg_type; |
1007 | 6c9f886c | balrog | le32 *tmp = (le32 *) data; |
1008 | 6c9f886c | balrog | |
1009 | d4c4e6fd | Blue Swirl | msg_type = le32_to_cpup(tmp); |
1010 | 6c9f886c | balrog | |
1011 | 6c9f886c | balrog | switch (msg_type) {
|
1012 | 6c9f886c | balrog | case RNDIS_INITIALIZE_MSG:
|
1013 | 6c9f886c | balrog | s->rndis_state = RNDIS_INITIALIZED; |
1014 | 6c9f886c | balrog | return rndis_init_response(s, (rndis_init_msg_type *) data);
|
1015 | 6c9f886c | balrog | |
1016 | 6c9f886c | balrog | case RNDIS_HALT_MSG:
|
1017 | 6c9f886c | balrog | s->rndis_state = RNDIS_UNINITIALIZED; |
1018 | 6c9f886c | balrog | return 0; |
1019 | 6c9f886c | balrog | |
1020 | 6c9f886c | balrog | case RNDIS_QUERY_MSG:
|
1021 | 6c9f886c | balrog | return rndis_query_response(s, (rndis_query_msg_type *) data, length);
|
1022 | 6c9f886c | balrog | |
1023 | 6c9f886c | balrog | case RNDIS_SET_MSG:
|
1024 | 6c9f886c | balrog | return rndis_set_response(s, (rndis_set_msg_type *) data, length);
|
1025 | 6c9f886c | balrog | |
1026 | 6c9f886c | balrog | case RNDIS_RESET_MSG:
|
1027 | 6c9f886c | balrog | rndis_clear_responsequeue(s); |
1028 | 6c9f886c | balrog | s->out_ptr = s->in_ptr = s->in_len = 0;
|
1029 | 6c9f886c | balrog | return rndis_reset_response(s, (rndis_reset_msg_type *) data);
|
1030 | 6c9f886c | balrog | |
1031 | 6c9f886c | balrog | case RNDIS_KEEPALIVE_MSG:
|
1032 | 6c9f886c | balrog | /* For USB: host does this every 5 seconds */
|
1033 | 6c9f886c | balrog | return rndis_keepalive_response(s, (rndis_keepalive_msg_type *) data);
|
1034 | 6c9f886c | balrog | } |
1035 | 6c9f886c | balrog | |
1036 | 6c9f886c | balrog | return USB_RET_STALL;
|
1037 | 6c9f886c | balrog | } |
1038 | 6c9f886c | balrog | |
1039 | 6c9f886c | balrog | static void usb_net_handle_reset(USBDevice *dev) |
1040 | 6c9f886c | balrog | { |
1041 | 6c9f886c | balrog | } |
1042 | 6c9f886c | balrog | |
1043 | 007fd62f | Hans de Goede | static int usb_net_handle_control(USBDevice *dev, USBPacket *p, |
1044 | 007fd62f | Hans de Goede | int request, int value, int index, int length, uint8_t *data) |
1045 | 6c9f886c | balrog | { |
1046 | 6c9f886c | balrog | USBNetState *s = (USBNetState *) dev; |
1047 | 30c7d32a | Gerd Hoffmann | int ret;
|
1048 | 6c9f886c | balrog | |
1049 | 007fd62f | Hans de Goede | ret = usb_desc_handle_control(dev, p, request, value, index, length, data); |
1050 | 30c7d32a | Gerd Hoffmann | if (ret >= 0) { |
1051 | 30c7d32a | Gerd Hoffmann | return ret;
|
1052 | 30c7d32a | Gerd Hoffmann | } |
1053 | 30c7d32a | Gerd Hoffmann | |
1054 | 30c7d32a | Gerd Hoffmann | ret = 0;
|
1055 | 6c9f886c | balrog | switch(request) {
|
1056 | 6c9f886c | balrog | case ClassInterfaceOutRequest | USB_CDC_SEND_ENCAPSULATED_COMMAND:
|
1057 | a980a065 | Gerd Hoffmann | if (!is_rndis(s) || value || index != 0) { |
1058 | 6c9f886c | balrog | goto fail;
|
1059 | a980a065 | Gerd Hoffmann | } |
1060 | eb38c52c | blueswir1 | #ifdef TRAFFIC_DEBUG
|
1061 | 6c9f886c | balrog | { |
1062 | 6c9f886c | balrog | unsigned int i; |
1063 | 6c9f886c | balrog | fprintf(stderr, "SEND_ENCAPSULATED_COMMAND:");
|
1064 | 6c9f886c | balrog | for (i = 0; i < length; i++) { |
1065 | 6c9f886c | balrog | if (!(i & 15)) |
1066 | 6c9f886c | balrog | fprintf(stderr, "\n%04x:", i);
|
1067 | 6c9f886c | balrog | fprintf(stderr, " %02x", data[i]);
|
1068 | 6c9f886c | balrog | } |
1069 | 6c9f886c | balrog | fprintf(stderr, "\n\n");
|
1070 | 6c9f886c | balrog | } |
1071 | 6c9f886c | balrog | #endif
|
1072 | 6c9f886c | balrog | ret = rndis_parse(s, data, length); |
1073 | 6c9f886c | balrog | break;
|
1074 | 6c9f886c | balrog | |
1075 | 6c9f886c | balrog | case ClassInterfaceRequest | USB_CDC_GET_ENCAPSULATED_RESPONSE:
|
1076 | a980a065 | Gerd Hoffmann | if (!is_rndis(s) || value || index != 0) { |
1077 | 6c9f886c | balrog | goto fail;
|
1078 | a980a065 | Gerd Hoffmann | } |
1079 | 6c9f886c | balrog | ret = rndis_get_response(s, data); |
1080 | 6c9f886c | balrog | if (!ret) {
|
1081 | 6c9f886c | balrog | data[0] = 0; |
1082 | 6c9f886c | balrog | ret = 1;
|
1083 | 6c9f886c | balrog | } |
1084 | eb38c52c | blueswir1 | #ifdef TRAFFIC_DEBUG
|
1085 | 6c9f886c | balrog | { |
1086 | 6c9f886c | balrog | unsigned int i; |
1087 | 6c9f886c | balrog | fprintf(stderr, "GET_ENCAPSULATED_RESPONSE:");
|
1088 | 6c9f886c | balrog | for (i = 0; i < ret; i++) { |
1089 | 6c9f886c | balrog | if (!(i & 15)) |
1090 | 6c9f886c | balrog | fprintf(stderr, "\n%04x:", i);
|
1091 | 6c9f886c | balrog | fprintf(stderr, " %02x", data[i]);
|
1092 | 6c9f886c | balrog | } |
1093 | 6c9f886c | balrog | fprintf(stderr, "\n\n");
|
1094 | 6c9f886c | balrog | } |
1095 | 6c9f886c | balrog | #endif
|
1096 | 6c9f886c | balrog | break;
|
1097 | 6c9f886c | balrog | |
1098 | 6c9f886c | balrog | default:
|
1099 | 6c9f886c | balrog | fail:
|
1100 | 6c9f886c | balrog | fprintf(stderr, "usbnet: failed control transaction: "
|
1101 | 6c9f886c | balrog | "request 0x%x value 0x%x index 0x%x length 0x%x\n",
|
1102 | 6c9f886c | balrog | request, value, index, length); |
1103 | 6c9f886c | balrog | ret = USB_RET_STALL; |
1104 | 6c9f886c | balrog | break;
|
1105 | 6c9f886c | balrog | } |
1106 | 6c9f886c | balrog | return ret;
|
1107 | 6c9f886c | balrog | } |
1108 | 6c9f886c | balrog | |
1109 | 6c9f886c | balrog | static int usb_net_handle_statusin(USBNetState *s, USBPacket *p) |
1110 | 6c9f886c | balrog | { |
1111 | 4f4321c1 | Gerd Hoffmann | le32 buf[2];
|
1112 | 6c9f886c | balrog | int ret = 8; |
1113 | 6c9f886c | balrog | |
1114 | 4f4321c1 | Gerd Hoffmann | if (p->iov.size < 8) { |
1115 | 6c9f886c | balrog | return USB_RET_STALL;
|
1116 | 4f4321c1 | Gerd Hoffmann | } |
1117 | 6c9f886c | balrog | |
1118 | 4f4321c1 | Gerd Hoffmann | buf[0] = cpu_to_le32(1); |
1119 | 4f4321c1 | Gerd Hoffmann | buf[1] = cpu_to_le32(0); |
1120 | 4f4321c1 | Gerd Hoffmann | usb_packet_copy(p, buf, 8);
|
1121 | 6c9f886c | balrog | if (!s->rndis_resp.tqh_first)
|
1122 | 6c9f886c | balrog | ret = USB_RET_NAK; |
1123 | 6c9f886c | balrog | |
1124 | eb38c52c | blueswir1 | #ifdef TRAFFIC_DEBUG
|
1125 | 4f4321c1 | Gerd Hoffmann | fprintf(stderr, "usbnet: interrupt poll len %zu return %d",
|
1126 | 4f4321c1 | Gerd Hoffmann | p->iov.size, ret); |
1127 | 4f4321c1 | Gerd Hoffmann | iov_hexdump(p->iov.iov, p->iov.niov, stderr, "usbnet", ret);
|
1128 | 6c9f886c | balrog | #endif
|
1129 | 6c9f886c | balrog | |
1130 | 6c9f886c | balrog | return ret;
|
1131 | 6c9f886c | balrog | } |
1132 | 6c9f886c | balrog | |
1133 | 6c9f886c | balrog | static int usb_net_handle_datain(USBNetState *s, USBPacket *p) |
1134 | 6c9f886c | balrog | { |
1135 | 6c9f886c | balrog | int ret = USB_RET_NAK;
|
1136 | 6c9f886c | balrog | |
1137 | 6c9f886c | balrog | if (s->in_ptr > s->in_len) {
|
1138 | 6c9f886c | balrog | s->in_ptr = s->in_len = 0;
|
1139 | 6c9f886c | balrog | ret = USB_RET_NAK; |
1140 | 6c9f886c | balrog | return ret;
|
1141 | 6c9f886c | balrog | } |
1142 | 6c9f886c | balrog | if (!s->in_len) {
|
1143 | 6c9f886c | balrog | ret = USB_RET_NAK; |
1144 | 6c9f886c | balrog | return ret;
|
1145 | 6c9f886c | balrog | } |
1146 | 6c9f886c | balrog | ret = s->in_len - s->in_ptr; |
1147 | 4f4321c1 | Gerd Hoffmann | if (ret > p->iov.size) {
|
1148 | 4f4321c1 | Gerd Hoffmann | ret = p->iov.size; |
1149 | 4f4321c1 | Gerd Hoffmann | } |
1150 | 4f4321c1 | Gerd Hoffmann | usb_packet_copy(p, &s->in_buf[s->in_ptr], ret); |
1151 | 6c9f886c | balrog | s->in_ptr += ret; |
1152 | 6c9f886c | balrog | if (s->in_ptr >= s->in_len &&
|
1153 | a980a065 | Gerd Hoffmann | (is_rndis(s) || (s->in_len & (64 - 1)) || !ret)) { |
1154 | 6c9f886c | balrog | /* no short packet necessary */
|
1155 | 6c9f886c | balrog | s->in_ptr = s->in_len = 0;
|
1156 | 6c9f886c | balrog | } |
1157 | 6c9f886c | balrog | |
1158 | eb38c52c | blueswir1 | #ifdef TRAFFIC_DEBUG
|
1159 | 4f4321c1 | Gerd Hoffmann | fprintf(stderr, "usbnet: data in len %zu return %d", p->iov.size, ret);
|
1160 | 4f4321c1 | Gerd Hoffmann | iov_hexdump(p->iov.iov, p->iov.niov, stderr, "usbnet", ret);
|
1161 | 6c9f886c | balrog | #endif
|
1162 | 6c9f886c | balrog | |
1163 | 6c9f886c | balrog | return ret;
|
1164 | 6c9f886c | balrog | } |
1165 | 6c9f886c | balrog | |
1166 | 6c9f886c | balrog | static int usb_net_handle_dataout(USBNetState *s, USBPacket *p) |
1167 | 6c9f886c | balrog | { |
1168 | 4f4321c1 | Gerd Hoffmann | int ret = p->iov.size;
|
1169 | 6c9f886c | balrog | int sz = sizeof(s->out_buf) - s->out_ptr; |
1170 | 6c9f886c | balrog | struct rndis_packet_msg_type *msg =
|
1171 | 6c9f886c | balrog | (struct rndis_packet_msg_type *) s->out_buf;
|
1172 | 6c9f886c | balrog | uint32_t len; |
1173 | 6c9f886c | balrog | |
1174 | eb38c52c | blueswir1 | #ifdef TRAFFIC_DEBUG
|
1175 | 4f4321c1 | Gerd Hoffmann | fprintf(stderr, "usbnet: data out len %zu\n", p->iov.size);
|
1176 | 4f4321c1 | Gerd Hoffmann | iov_hexdump(p->iov.iov, p->iov.niov, stderr, "usbnet", p->iov.size);
|
1177 | 6c9f886c | balrog | #endif
|
1178 | 6c9f886c | balrog | |
1179 | 6c9f886c | balrog | if (sz > ret)
|
1180 | 6c9f886c | balrog | sz = ret; |
1181 | 4f4321c1 | Gerd Hoffmann | usb_packet_copy(p, &s->out_buf[s->out_ptr], sz); |
1182 | 6c9f886c | balrog | s->out_ptr += sz; |
1183 | 6c9f886c | balrog | |
1184 | a980a065 | Gerd Hoffmann | if (!is_rndis(s)) {
|
1185 | 6c9f886c | balrog | if (ret < 64) { |
1186 | e0394b8b | Mark McLoughlin | qemu_send_packet(&s->nic->nc, s->out_buf, s->out_ptr); |
1187 | 6c9f886c | balrog | s->out_ptr = 0;
|
1188 | 6c9f886c | balrog | } |
1189 | 6c9f886c | balrog | return ret;
|
1190 | 6c9f886c | balrog | } |
1191 | 6c9f886c | balrog | len = le32_to_cpu(msg->MessageLength); |
1192 | 6c9f886c | balrog | if (s->out_ptr < 8 || s->out_ptr < len) |
1193 | 6c9f886c | balrog | return ret;
|
1194 | 6c9f886c | balrog | if (le32_to_cpu(msg->MessageType) == RNDIS_PACKET_MSG) {
|
1195 | 6c9f886c | balrog | uint32_t offs = 8 + le32_to_cpu(msg->DataOffset);
|
1196 | 6c9f886c | balrog | uint32_t size = le32_to_cpu(msg->DataLength); |
1197 | 6c9f886c | balrog | if (offs + size <= len)
|
1198 | e0394b8b | Mark McLoughlin | qemu_send_packet(&s->nic->nc, s->out_buf + offs, size); |
1199 | 6c9f886c | balrog | } |
1200 | 6c9f886c | balrog | s->out_ptr -= len; |
1201 | 6c9f886c | balrog | memmove(s->out_buf, &s->out_buf[len], s->out_ptr); |
1202 | 6c9f886c | balrog | |
1203 | 6c9f886c | balrog | return ret;
|
1204 | 6c9f886c | balrog | } |
1205 | 6c9f886c | balrog | |
1206 | 6c9f886c | balrog | static int usb_net_handle_data(USBDevice *dev, USBPacket *p) |
1207 | 6c9f886c | balrog | { |
1208 | 6c9f886c | balrog | USBNetState *s = (USBNetState *) dev; |
1209 | 6c9f886c | balrog | int ret = 0; |
1210 | 6c9f886c | balrog | |
1211 | 6c9f886c | balrog | switch(p->pid) {
|
1212 | 6c9f886c | balrog | case USB_TOKEN_IN:
|
1213 | 079d0b7f | Gerd Hoffmann | switch (p->ep->nr) {
|
1214 | 6c9f886c | balrog | case 1: |
1215 | 6c9f886c | balrog | ret = usb_net_handle_statusin(s, p); |
1216 | 6c9f886c | balrog | break;
|
1217 | 6c9f886c | balrog | |
1218 | 6c9f886c | balrog | case 2: |
1219 | 6c9f886c | balrog | ret = usb_net_handle_datain(s, p); |
1220 | 6c9f886c | balrog | break;
|
1221 | 6c9f886c | balrog | |
1222 | 6c9f886c | balrog | default:
|
1223 | 6c9f886c | balrog | goto fail;
|
1224 | 6c9f886c | balrog | } |
1225 | 6c9f886c | balrog | break;
|
1226 | 6c9f886c | balrog | |
1227 | 6c9f886c | balrog | case USB_TOKEN_OUT:
|
1228 | 079d0b7f | Gerd Hoffmann | switch (p->ep->nr) {
|
1229 | 6c9f886c | balrog | case 2: |
1230 | 6c9f886c | balrog | ret = usb_net_handle_dataout(s, p); |
1231 | 6c9f886c | balrog | break;
|
1232 | 6c9f886c | balrog | |
1233 | 6c9f886c | balrog | default:
|
1234 | 6c9f886c | balrog | goto fail;
|
1235 | 6c9f886c | balrog | } |
1236 | 6c9f886c | balrog | break;
|
1237 | 6c9f886c | balrog | |
1238 | 6c9f886c | balrog | default:
|
1239 | 6c9f886c | balrog | fail:
|
1240 | 6c9f886c | balrog | ret = USB_RET_STALL; |
1241 | 6c9f886c | balrog | break;
|
1242 | 6c9f886c | balrog | } |
1243 | 6c9f886c | balrog | if (ret == USB_RET_STALL)
|
1244 | 6c9f886c | balrog | fprintf(stderr, "usbnet: failed data transaction: "
|
1245 | 4f4321c1 | Gerd Hoffmann | "pid 0x%x ep 0x%x len 0x%zx\n",
|
1246 | 079d0b7f | Gerd Hoffmann | p->pid, p->ep->nr, p->iov.size); |
1247 | 6c9f886c | balrog | return ret;
|
1248 | 6c9f886c | balrog | } |
1249 | 6c9f886c | balrog | |
1250 | e0394b8b | Mark McLoughlin | static ssize_t usbnet_receive(VLANClientState *nc, const uint8_t *buf, size_t size) |
1251 | 6c9f886c | balrog | { |
1252 | e0394b8b | Mark McLoughlin | USBNetState *s = DO_UPCAST(NICState, nc, nc)->opaque; |
1253 | 6c9f886c | balrog | struct rndis_packet_msg_type *msg;
|
1254 | 6c9f886c | balrog | |
1255 | a980a065 | Gerd Hoffmann | if (is_rndis(s)) {
|
1256 | 6c9f886c | balrog | msg = (struct rndis_packet_msg_type *) s->in_buf;
|
1257 | 98d23704 | Peter Maydell | if (s->rndis_state != RNDIS_DATA_INITIALIZED) {
|
1258 | 4f1c942b | Mark McLoughlin | return -1; |
1259 | 98d23704 | Peter Maydell | } |
1260 | 6c9f886c | balrog | if (size + sizeof(struct rndis_packet_msg_type) > sizeof(s->in_buf)) |
1261 | 4f1c942b | Mark McLoughlin | return -1; |
1262 | 6c9f886c | balrog | |
1263 | 6c9f886c | balrog | memset(msg, 0, sizeof(struct rndis_packet_msg_type)); |
1264 | 6c9f886c | balrog | msg->MessageType = cpu_to_le32(RNDIS_PACKET_MSG); |
1265 | 6c9f886c | balrog | msg->MessageLength = cpu_to_le32(size + sizeof(struct rndis_packet_msg_type)); |
1266 | 6c9f886c | balrog | msg->DataOffset = cpu_to_le32(sizeof(struct rndis_packet_msg_type) - 8); |
1267 | 6c9f886c | balrog | msg->DataLength = cpu_to_le32(size); |
1268 | 6c9f886c | balrog | /* msg->OOBDataOffset;
|
1269 | 6c9f886c | balrog | * msg->OOBDataLength;
|
1270 | 6c9f886c | balrog | * msg->NumOOBDataElements;
|
1271 | 6c9f886c | balrog | * msg->PerPacketInfoOffset;
|
1272 | 6c9f886c | balrog | * msg->PerPacketInfoLength;
|
1273 | 6c9f886c | balrog | * msg->VcHandle;
|
1274 | 6c9f886c | balrog | * msg->Reserved;
|
1275 | 6c9f886c | balrog | */
|
1276 | 6c9f886c | balrog | memcpy(msg + 1, buf, size);
|
1277 | 6c9f886c | balrog | s->in_len = size + sizeof(struct rndis_packet_msg_type); |
1278 | 6c9f886c | balrog | } else {
|
1279 | 6c9f886c | balrog | if (size > sizeof(s->in_buf)) |
1280 | 4f1c942b | Mark McLoughlin | return -1; |
1281 | 6c9f886c | balrog | memcpy(s->in_buf, buf, size); |
1282 | 6c9f886c | balrog | s->in_len = size; |
1283 | 6c9f886c | balrog | } |
1284 | 6c9f886c | balrog | s->in_ptr = 0;
|
1285 | 4f1c942b | Mark McLoughlin | return size;
|
1286 | 6c9f886c | balrog | } |
1287 | 6c9f886c | balrog | |
1288 | e0394b8b | Mark McLoughlin | static int usbnet_can_receive(VLANClientState *nc) |
1289 | 6c9f886c | balrog | { |
1290 | e0394b8b | Mark McLoughlin | USBNetState *s = DO_UPCAST(NICState, nc, nc)->opaque; |
1291 | 6c9f886c | balrog | |
1292 | 98d23704 | Peter Maydell | if (is_rndis(s) && s->rndis_state != RNDIS_DATA_INITIALIZED) {
|
1293 | 6c9f886c | balrog | return 1; |
1294 | a980a065 | Gerd Hoffmann | } |
1295 | 6c9f886c | balrog | |
1296 | 6c9f886c | balrog | return !s->in_len;
|
1297 | 6c9f886c | balrog | } |
1298 | 6c9f886c | balrog | |
1299 | e0394b8b | Mark McLoughlin | static void usbnet_cleanup(VLANClientState *nc) |
1300 | b946a153 | aliguori | { |
1301 | e0394b8b | Mark McLoughlin | USBNetState *s = DO_UPCAST(NICState, nc, nc)->opaque; |
1302 | b946a153 | aliguori | |
1303 | 42be86ce | Gerd Hoffmann | s->nic = NULL;
|
1304 | b946a153 | aliguori | } |
1305 | b946a153 | aliguori | |
1306 | 6c9f886c | balrog | static void usb_net_handle_destroy(USBDevice *dev) |
1307 | 6c9f886c | balrog | { |
1308 | 6c9f886c | balrog | USBNetState *s = (USBNetState *) dev; |
1309 | 6c9f886c | balrog | |
1310 | dcf414d6 | balrog | /* TODO: remove the nd_table[] entry */
|
1311 | 42be86ce | Gerd Hoffmann | rndis_clear_responsequeue(s); |
1312 | e0394b8b | Mark McLoughlin | qemu_del_vlan_client(&s->nic->nc); |
1313 | 6c9f886c | balrog | } |
1314 | 6c9f886c | balrog | |
1315 | 42be86ce | Gerd Hoffmann | static NetClientInfo net_usbnet_info = {
|
1316 | 42be86ce | Gerd Hoffmann | .type = NET_CLIENT_TYPE_NIC, |
1317 | 42be86ce | Gerd Hoffmann | .size = sizeof(NICState),
|
1318 | 42be86ce | Gerd Hoffmann | .can_receive = usbnet_can_receive, |
1319 | 42be86ce | Gerd Hoffmann | .receive = usbnet_receive, |
1320 | 42be86ce | Gerd Hoffmann | .cleanup = usbnet_cleanup, |
1321 | 42be86ce | Gerd Hoffmann | }; |
1322 | 42be86ce | Gerd Hoffmann | |
1323 | 806b6024 | Gerd Hoffmann | static int usb_net_initfn(USBDevice *dev) |
1324 | 6c9f886c | balrog | { |
1325 | 806b6024 | Gerd Hoffmann | USBNetState *s = DO_UPCAST(USBNetState, dev, dev); |
1326 | 6c9f886c | balrog | |
1327 | a980a065 | Gerd Hoffmann | usb_desc_init(dev); |
1328 | 6c9f886c | balrog | |
1329 | 6c9f886c | balrog | s->rndis_state = RNDIS_UNINITIALIZED; |
1330 | 72cf2d4f | Blue Swirl | QTAILQ_INIT(&s->rndis_resp); |
1331 | 806b6024 | Gerd Hoffmann | |
1332 | 6c9f886c | balrog | s->medium = 0; /* NDIS_MEDIUM_802_3 */ |
1333 | 6c9f886c | balrog | s->speed = 1000000; /* 100MBps, in 100Bps units */ |
1334 | 6c9f886c | balrog | s->media_state = 0; /* NDIS_MEDIA_STATE_CONNECTED */; |
1335 | 6c9f886c | balrog | s->filter = 0;
|
1336 | 6c9f886c | balrog | s->vendorid = 0x1234;
|
1337 | 42be86ce | Gerd Hoffmann | |
1338 | 42be86ce | Gerd Hoffmann | qemu_macaddr_default_if_unset(&s->conf.macaddr); |
1339 | 42be86ce | Gerd Hoffmann | s->nic = qemu_new_nic(&net_usbnet_info, &s->conf, |
1340 | f79f2bfc | Anthony Liguori | object_get_typename(OBJECT(s)), s->dev.qdev.id, s); |
1341 | 42be86ce | Gerd Hoffmann | qemu_format_nic_info_str(&s->nic->nc, s->conf.macaddr.a); |
1342 | 42be86ce | Gerd Hoffmann | snprintf(s->usbstring_mac, sizeof(s->usbstring_mac),
|
1343 | 42be86ce | Gerd Hoffmann | "%02x%02x%02x%02x%02x%02x",
|
1344 | 42be86ce | Gerd Hoffmann | 0x40,
|
1345 | 42be86ce | Gerd Hoffmann | s->conf.macaddr.a[1],
|
1346 | 42be86ce | Gerd Hoffmann | s->conf.macaddr.a[2],
|
1347 | 42be86ce | Gerd Hoffmann | s->conf.macaddr.a[3],
|
1348 | 42be86ce | Gerd Hoffmann | s->conf.macaddr.a[4],
|
1349 | 42be86ce | Gerd Hoffmann | s->conf.macaddr.a[5]);
|
1350 | 30c7d32a | Gerd Hoffmann | usb_desc_set_string(dev, STRING_ETHADDR, s->usbstring_mac); |
1351 | 42be86ce | Gerd Hoffmann | |
1352 | 1ca4d09a | Gleb Natapov | add_boot_device_path(s->conf.bootindex, &dev->qdev, "/ethernet@0");
|
1353 | 806b6024 | Gerd Hoffmann | return 0; |
1354 | 806b6024 | Gerd Hoffmann | } |
1355 | 806b6024 | Gerd Hoffmann | |
1356 | 3741715c | Jan Kiszka | static USBDevice *usb_net_init(USBBus *bus, const char *cmdline) |
1357 | 806b6024 | Gerd Hoffmann | { |
1358 | 806b6024 | Gerd Hoffmann | USBDevice *dev; |
1359 | 42be86ce | Gerd Hoffmann | QemuOpts *opts; |
1360 | 42be86ce | Gerd Hoffmann | int idx;
|
1361 | 6c9f886c | balrog | |
1362 | 3329f07b | Gerd Hoffmann | opts = qemu_opts_parse(qemu_find_opts("net"), cmdline, 0); |
1363 | 42be86ce | Gerd Hoffmann | if (!opts) {
|
1364 | 42be86ce | Gerd Hoffmann | return NULL; |
1365 | 42be86ce | Gerd Hoffmann | } |
1366 | 42be86ce | Gerd Hoffmann | qemu_opt_set(opts, "type", "nic"); |
1367 | 42be86ce | Gerd Hoffmann | qemu_opt_set(opts, "model", "usb"); |
1368 | 6c9f886c | balrog | |
1369 | 42be86ce | Gerd Hoffmann | idx = net_client_init(NULL, opts, 0); |
1370 | 42be86ce | Gerd Hoffmann | if (idx == -1) { |
1371 | 42be86ce | Gerd Hoffmann | return NULL; |
1372 | 42be86ce | Gerd Hoffmann | } |
1373 | 7cb7434b | aliguori | |
1374 | 3741715c | Jan Kiszka | dev = usb_create(bus, "usb-net");
|
1375 | d44168ff | Paul Brook | if (!dev) {
|
1376 | d44168ff | Paul Brook | return NULL; |
1377 | d44168ff | Paul Brook | } |
1378 | 42be86ce | Gerd Hoffmann | qdev_set_nic_properties(&dev->qdev, &nd_table[idx]); |
1379 | beb6f0de | Kevin Wolf | qdev_init_nofail(&dev->qdev); |
1380 | 42be86ce | Gerd Hoffmann | return dev;
|
1381 | 6c9f886c | balrog | } |
1382 | 806b6024 | Gerd Hoffmann | |
1383 | 4ab0ba9e | Gerd Hoffmann | static const VMStateDescription vmstate_usb_net = { |
1384 | 4ab0ba9e | Gerd Hoffmann | .name = "usb-net",
|
1385 | 4ab0ba9e | Gerd Hoffmann | .unmigratable = 1,
|
1386 | 4ab0ba9e | Gerd Hoffmann | }; |
1387 | 4ab0ba9e | Gerd Hoffmann | |
1388 | 39bffca2 | Anthony Liguori | static Property net_properties[] = {
|
1389 | 39bffca2 | Anthony Liguori | DEFINE_NIC_PROPERTIES(USBNetState, conf), |
1390 | 39bffca2 | Anthony Liguori | DEFINE_PROP_END_OF_LIST(), |
1391 | 39bffca2 | Anthony Liguori | }; |
1392 | 39bffca2 | Anthony Liguori | |
1393 | 62aed765 | Anthony Liguori | static void usb_net_class_initfn(ObjectClass *klass, void *data) |
1394 | 62aed765 | Anthony Liguori | { |
1395 | 39bffca2 | Anthony Liguori | DeviceClass *dc = DEVICE_CLASS(klass); |
1396 | 62aed765 | Anthony Liguori | USBDeviceClass *uc = USB_DEVICE_CLASS(klass); |
1397 | 62aed765 | Anthony Liguori | |
1398 | 62aed765 | Anthony Liguori | uc->init = usb_net_initfn; |
1399 | 62aed765 | Anthony Liguori | uc->product_desc = "QEMU USB Network Interface";
|
1400 | 62aed765 | Anthony Liguori | uc->usb_desc = &desc_net; |
1401 | 62aed765 | Anthony Liguori | uc->handle_reset = usb_net_handle_reset; |
1402 | 62aed765 | Anthony Liguori | uc->handle_control = usb_net_handle_control; |
1403 | 62aed765 | Anthony Liguori | uc->handle_data = usb_net_handle_data; |
1404 | 62aed765 | Anthony Liguori | uc->handle_destroy = usb_net_handle_destroy; |
1405 | 39bffca2 | Anthony Liguori | dc->fw_name = "network";
|
1406 | 39bffca2 | Anthony Liguori | dc->vmsd = &vmstate_usb_net; |
1407 | 39bffca2 | Anthony Liguori | dc->props = net_properties; |
1408 | 62aed765 | Anthony Liguori | } |
1409 | 62aed765 | Anthony Liguori | |
1410 | 39bffca2 | Anthony Liguori | static TypeInfo net_info = {
|
1411 | 39bffca2 | Anthony Liguori | .name = "usb-net",
|
1412 | 39bffca2 | Anthony Liguori | .parent = TYPE_USB_DEVICE, |
1413 | 39bffca2 | Anthony Liguori | .instance_size = sizeof(USBNetState),
|
1414 | 39bffca2 | Anthony Liguori | .class_init = usb_net_class_initfn, |
1415 | 806b6024 | Gerd Hoffmann | }; |
1416 | 806b6024 | Gerd Hoffmann | |
1417 | 83f7d43a | Andreas Färber | static void usb_net_register_types(void) |
1418 | 806b6024 | Gerd Hoffmann | { |
1419 | 39bffca2 | Anthony Liguori | type_register_static(&net_info); |
1420 | ba02430f | Anthony Liguori | usb_legacy_register("usb-net", "net", usb_net_init); |
1421 | 806b6024 | Gerd Hoffmann | } |
1422 | 83f7d43a | Andreas Färber | |
1423 | 83f7d43a | Andreas Färber | type_init(usb_net_register_types) |