4 * Copyright (c) 2006 Thomas Sailer
5 * Copyright (c) 2008 Andrzej Zaborowski
7 * Permission is hereby granted, free of charge, to any person obtaining a copy
8 * of this software and associated documentation files (the "Software"), to deal
9 * in the Software without restriction, including without limitation the rights
10 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11 * copies of the Software, and to permit persons to whom the Software is
12 * furnished to do so, subject to the following conditions:
14 * The above copyright notice and this permission notice shall be included in
15 * all copies or substantial portions of the Software.
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
20 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
26 #include "qemu-common.h"
28 #include "hw/usb/desc.h"
30 #include "qemu-queue.h"
34 /*#define TRAFFIC_DEBUG*/
35 /* Thanks to NetChip Technologies for donating this product ID.
36 * It's for devices with only CDC Ethernet configurations.
38 #define CDC_VENDOR_NUM 0x0525 /* NetChip */
39 #define CDC_PRODUCT_NUM 0xa4a1 /* Linux-USB Ethernet Gadget */
40 /* For hardware that can talk RNDIS and either of the above protocols,
41 * use this ID ... the windows INF files will know it.
43 #define RNDIS_VENDOR_NUM 0x0525 /* NetChip */
44 #define RNDIS_PRODUCT_NUM 0xa4a2 /* Ethernet/RNDIS Gadget */
47 STRING_MANUFACTURER
= 1,
59 #define DEV_CONFIG_VALUE 1 /* CDC or a subset */
60 #define DEV_RNDIS_CONFIG_VALUE 2 /* RNDIS; optional */
62 #define USB_CDC_SUBCLASS_ACM 0x02
63 #define USB_CDC_SUBCLASS_ETHERNET 0x06
65 #define USB_CDC_PROTO_NONE 0
66 #define USB_CDC_ACM_PROTO_VENDOR 0xff
68 #define USB_CDC_HEADER_TYPE 0x00 /* header_desc */
69 #define USB_CDC_CALL_MANAGEMENT_TYPE 0x01 /* call_mgmt_descriptor */
70 #define USB_CDC_ACM_TYPE 0x02 /* acm_descriptor */
71 #define USB_CDC_UNION_TYPE 0x06 /* union_desc */
72 #define USB_CDC_ETHERNET_TYPE 0x0f /* ether_desc */
74 #define USB_CDC_SEND_ENCAPSULATED_COMMAND 0x00
75 #define USB_CDC_GET_ENCAPSULATED_RESPONSE 0x01
76 #define USB_CDC_REQ_SET_LINE_CODING 0x20
77 #define USB_CDC_REQ_GET_LINE_CODING 0x21
78 #define USB_CDC_REQ_SET_CONTROL_LINE_STATE 0x22
79 #define USB_CDC_REQ_SEND_BREAK 0x23
80 #define USB_CDC_SET_ETHERNET_MULTICAST_FILTERS 0x40
81 #define USB_CDC_SET_ETHERNET_PM_PATTERN_FILTER 0x41
82 #define USB_CDC_GET_ETHERNET_PM_PATTERN_FILTER 0x42
83 #define USB_CDC_SET_ETHERNET_PACKET_FILTER 0x43
84 #define USB_CDC_GET_ETHERNET_STATISTIC 0x44
86 #define LOG2_STATUS_INTERVAL_MSEC 5 /* 1 << 5 == 32 msec */
87 #define STATUS_BYTECOUNT 16 /* 8 byte header + data */
89 #define ETH_FRAME_LEN 1514 /* Max. octets in frame sans FCS */
91 static const USBDescStrings usb_net_stringtable
= {
92 [STRING_MANUFACTURER
] = "QEMU",
93 [STRING_PRODUCT
] = "RNDIS/QEMU USB Network Device",
94 [STRING_ETHADDR
] = "400102030405",
95 [STRING_DATA
] = "QEMU USB Net Data Interface",
96 [STRING_CONTROL
] = "QEMU USB Net Control Interface",
97 [STRING_RNDIS_CONTROL
] = "QEMU USB Net RNDIS Control Interface",
98 [STRING_CDC
] = "QEMU USB Net CDC",
99 [STRING_SUBSET
] = "QEMU USB Net Subset",
100 [STRING_RNDIS
] = "QEMU USB Net RNDIS",
101 [STRING_SERIALNUMBER
] = "1",
104 static const USBDescIface desc_iface_rndis
[] = {
106 /* RNDIS Control Interface */
107 .bInterfaceNumber
= 0,
109 .bInterfaceClass
= USB_CLASS_COMM
,
110 .bInterfaceSubClass
= USB_CDC_SUBCLASS_ACM
,
111 .bInterfaceProtocol
= USB_CDC_ACM_PROTO_VENDOR
,
112 .iInterface
= STRING_RNDIS_CONTROL
,
114 .descs
= (USBDescOther
[]) {
116 /* Header Descriptor */
117 .data
= (uint8_t[]) {
118 0x05, /* u8 bLength */
119 USB_DT_CS_INTERFACE
, /* u8 bDescriptorType */
120 USB_CDC_HEADER_TYPE
, /* u8 bDescriptorSubType */
121 0x10, 0x01, /* le16 bcdCDC */
124 /* Call Management Descriptor */
125 .data
= (uint8_t[]) {
126 0x05, /* u8 bLength */
127 USB_DT_CS_INTERFACE
, /* u8 bDescriptorType */
128 USB_CDC_CALL_MANAGEMENT_TYPE
, /* u8 bDescriptorSubType */
129 0x00, /* u8 bmCapabilities */
130 0x01, /* u8 bDataInterface */
134 .data
= (uint8_t[]) {
135 0x04, /* u8 bLength */
136 USB_DT_CS_INTERFACE
, /* u8 bDescriptorType */
137 USB_CDC_ACM_TYPE
, /* u8 bDescriptorSubType */
138 0x00, /* u8 bmCapabilities */
141 /* Union Descriptor */
142 .data
= (uint8_t[]) {
143 0x05, /* u8 bLength */
144 USB_DT_CS_INTERFACE
, /* u8 bDescriptorType */
145 USB_CDC_UNION_TYPE
, /* u8 bDescriptorSubType */
146 0x00, /* u8 bMasterInterface0 */
147 0x01, /* u8 bSlaveInterface0 */
151 .eps
= (USBDescEndpoint
[]) {
153 .bEndpointAddress
= USB_DIR_IN
| 0x01,
154 .bmAttributes
= USB_ENDPOINT_XFER_INT
,
155 .wMaxPacketSize
= STATUS_BYTECOUNT
,
156 .bInterval
= 1 << LOG2_STATUS_INTERVAL_MSEC
,
160 /* RNDIS Data Interface */
161 .bInterfaceNumber
= 1,
163 .bInterfaceClass
= USB_CLASS_CDC_DATA
,
164 .iInterface
= STRING_DATA
,
165 .eps
= (USBDescEndpoint
[]) {
167 .bEndpointAddress
= USB_DIR_IN
| 0x02,
168 .bmAttributes
= USB_ENDPOINT_XFER_BULK
,
169 .wMaxPacketSize
= 0x40,
171 .bEndpointAddress
= USB_DIR_OUT
| 0x02,
172 .bmAttributes
= USB_ENDPOINT_XFER_BULK
,
173 .wMaxPacketSize
= 0x40,
179 static const USBDescIface desc_iface_cdc
[] = {
181 /* CDC Control Interface */
182 .bInterfaceNumber
= 0,
184 .bInterfaceClass
= USB_CLASS_COMM
,
185 .bInterfaceSubClass
= USB_CDC_SUBCLASS_ETHERNET
,
186 .bInterfaceProtocol
= USB_CDC_PROTO_NONE
,
187 .iInterface
= STRING_CONTROL
,
189 .descs
= (USBDescOther
[]) {
191 /* Header Descriptor */
192 .data
= (uint8_t[]) {
193 0x05, /* u8 bLength */
194 USB_DT_CS_INTERFACE
, /* u8 bDescriptorType */
195 USB_CDC_HEADER_TYPE
, /* u8 bDescriptorSubType */
196 0x10, 0x01, /* le16 bcdCDC */
199 /* Union Descriptor */
200 .data
= (uint8_t[]) {
201 0x05, /* u8 bLength */
202 USB_DT_CS_INTERFACE
, /* u8 bDescriptorType */
203 USB_CDC_UNION_TYPE
, /* u8 bDescriptorSubType */
204 0x00, /* u8 bMasterInterface0 */
205 0x01, /* u8 bSlaveInterface0 */
208 /* Ethernet Descriptor */
209 .data
= (uint8_t[]) {
210 0x0d, /* u8 bLength */
211 USB_DT_CS_INTERFACE
, /* u8 bDescriptorType */
212 USB_CDC_ETHERNET_TYPE
, /* u8 bDescriptorSubType */
213 STRING_ETHADDR
, /* u8 iMACAddress */
214 0x00, 0x00, 0x00, 0x00, /* le32 bmEthernetStatistics */
215 ETH_FRAME_LEN
& 0xff,
216 ETH_FRAME_LEN
>> 8, /* le16 wMaxSegmentSize */
217 0x00, 0x00, /* le16 wNumberMCFilters */
218 0x00, /* u8 bNumberPowerFilters */
222 .eps
= (USBDescEndpoint
[]) {
224 .bEndpointAddress
= USB_DIR_IN
| 0x01,
225 .bmAttributes
= USB_ENDPOINT_XFER_INT
,
226 .wMaxPacketSize
= STATUS_BYTECOUNT
,
227 .bInterval
= 1 << LOG2_STATUS_INTERVAL_MSEC
,
231 /* CDC Data Interface (off) */
232 .bInterfaceNumber
= 1,
233 .bAlternateSetting
= 0,
235 .bInterfaceClass
= USB_CLASS_CDC_DATA
,
237 /* CDC Data Interface */
238 .bInterfaceNumber
= 1,
239 .bAlternateSetting
= 1,
241 .bInterfaceClass
= USB_CLASS_CDC_DATA
,
242 .iInterface
= STRING_DATA
,
243 .eps
= (USBDescEndpoint
[]) {
245 .bEndpointAddress
= USB_DIR_IN
| 0x02,
246 .bmAttributes
= USB_ENDPOINT_XFER_BULK
,
247 .wMaxPacketSize
= 0x40,
249 .bEndpointAddress
= USB_DIR_OUT
| 0x02,
250 .bmAttributes
= USB_ENDPOINT_XFER_BULK
,
251 .wMaxPacketSize
= 0x40,
257 static const USBDescDevice desc_device_net
= {
259 .bDeviceClass
= USB_CLASS_COMM
,
260 .bMaxPacketSize0
= 0x40,
261 .bNumConfigurations
= 2,
262 .confs
= (USBDescConfig
[]) {
265 .bConfigurationValue
= DEV_RNDIS_CONFIG_VALUE
,
266 .iConfiguration
= STRING_RNDIS
,
267 .bmAttributes
= 0xc0,
269 .nif
= ARRAY_SIZE(desc_iface_rndis
),
270 .ifs
= desc_iface_rndis
,
273 .bConfigurationValue
= DEV_CONFIG_VALUE
,
274 .iConfiguration
= STRING_CDC
,
275 .bmAttributes
= 0xc0,
277 .nif
= ARRAY_SIZE(desc_iface_cdc
),
278 .ifs
= desc_iface_cdc
,
283 static const USBDesc desc_net
= {
285 .idVendor
= RNDIS_VENDOR_NUM
,
286 .idProduct
= RNDIS_PRODUCT_NUM
,
288 .iManufacturer
= STRING_MANUFACTURER
,
289 .iProduct
= STRING_PRODUCT
,
290 .iSerialNumber
= STRING_SERIALNUMBER
,
292 .full
= &desc_device_net
,
293 .str
= usb_net_stringtable
,
297 * RNDIS Definitions - in theory not specific to USB.
299 #define RNDIS_MAXIMUM_FRAME_SIZE 1518
300 #define RNDIS_MAX_TOTAL_SIZE 1558
302 /* Remote NDIS Versions */
303 #define RNDIS_MAJOR_VERSION 1
304 #define RNDIS_MINOR_VERSION 0
307 #define RNDIS_STATUS_SUCCESS 0x00000000U /* Success */
308 #define RNDIS_STATUS_FAILURE 0xc0000001U /* Unspecified error */
309 #define RNDIS_STATUS_INVALID_DATA 0xc0010015U /* Invalid data */
310 #define RNDIS_STATUS_NOT_SUPPORTED 0xc00000bbU /* Unsupported request */
311 #define RNDIS_STATUS_MEDIA_CONNECT 0x4001000bU /* Device connected */
312 #define RNDIS_STATUS_MEDIA_DISCONNECT 0x4001000cU /* Device disconnected */
314 /* Message Set for Connectionless (802.3) Devices */
316 RNDIS_PACKET_MSG
= 1,
317 RNDIS_INITIALIZE_MSG
= 2, /* Initialize device */
322 RNDIS_INDICATE_STATUS_MSG
= 7,
323 RNDIS_KEEPALIVE_MSG
= 8,
326 /* Message completion */
328 RNDIS_INITIALIZE_CMPLT
= 0x80000002U
,
329 RNDIS_QUERY_CMPLT
= 0x80000004U
,
330 RNDIS_SET_CMPLT
= 0x80000005U
,
331 RNDIS_RESET_CMPLT
= 0x80000006U
,
332 RNDIS_KEEPALIVE_CMPLT
= 0x80000008U
,
337 RNDIS_DF_CONNECTIONLESS
= 1,
338 RNDIS_DF_CONNECTIONORIENTED
= 2,
341 #define RNDIS_MEDIUM_802_3 0x00000000U
343 /* from drivers/net/sk98lin/h/skgepnmi.h */
344 #define OID_PNP_CAPABILITIES 0xfd010100
345 #define OID_PNP_SET_POWER 0xfd010101
346 #define OID_PNP_QUERY_POWER 0xfd010102
347 #define OID_PNP_ADD_WAKE_UP_PATTERN 0xfd010103
348 #define OID_PNP_REMOVE_WAKE_UP_PATTERN 0xfd010104
349 #define OID_PNP_ENABLE_WAKE_UP 0xfd010106
351 typedef uint32_t le32
;
353 typedef struct rndis_init_msg_type
{
359 le32 MaxTransferSize
;
360 } rndis_init_msg_type
;
362 typedef struct rndis_init_cmplt_type
{
371 le32 MaxPacketsPerTransfer
;
372 le32 MaxTransferSize
;
373 le32 PacketAlignmentFactor
;
376 } rndis_init_cmplt_type
;
378 typedef struct rndis_halt_msg_type
{
382 } rndis_halt_msg_type
;
384 typedef struct rndis_query_msg_type
{
389 le32 InformationBufferLength
;
390 le32 InformationBufferOffset
;
392 } rndis_query_msg_type
;
394 typedef struct rndis_query_cmplt_type
{
399 le32 InformationBufferLength
;
400 le32 InformationBufferOffset
;
401 } rndis_query_cmplt_type
;
403 typedef struct rndis_set_msg_type
{
408 le32 InformationBufferLength
;
409 le32 InformationBufferOffset
;
411 } rndis_set_msg_type
;
413 typedef struct rndis_set_cmplt_type
{
418 } rndis_set_cmplt_type
;
420 typedef struct rndis_reset_msg_type
{
424 } rndis_reset_msg_type
;
426 typedef struct rndis_reset_cmplt_type
{
430 le32 AddressingReset
;
431 } rndis_reset_cmplt_type
;
433 typedef struct rndis_indicate_status_msg_type
{
437 le32 StatusBufferLength
;
438 le32 StatusBufferOffset
;
439 } rndis_indicate_status_msg_type
;
441 typedef struct rndis_keepalive_msg_type
{
445 } rndis_keepalive_msg_type
;
447 typedef struct rndis_keepalive_cmplt_type
{
452 } rndis_keepalive_cmplt_type
;
454 struct rndis_packet_msg_type
{
461 le32 NumOOBDataElements
;
462 le32 PerPacketInfoOffset
;
463 le32 PerPacketInfoLength
;
468 struct rndis_config_parameter
{
469 le32 ParameterNameOffset
;
470 le32 ParameterNameLength
;
472 le32 ParameterValueOffset
;
473 le32 ParameterValueLength
;
476 /* implementation specific */
481 RNDIS_DATA_INITIALIZED
,
486 /* Required Object IDs (OIDs) */
487 OID_GEN_SUPPORTED_LIST
= 0x00010101,
488 OID_GEN_HARDWARE_STATUS
= 0x00010102,
489 OID_GEN_MEDIA_SUPPORTED
= 0x00010103,
490 OID_GEN_MEDIA_IN_USE
= 0x00010104,
491 OID_GEN_MAXIMUM_LOOKAHEAD
= 0x00010105,
492 OID_GEN_MAXIMUM_FRAME_SIZE
= 0x00010106,
493 OID_GEN_LINK_SPEED
= 0x00010107,
494 OID_GEN_TRANSMIT_BUFFER_SPACE
= 0x00010108,
495 OID_GEN_RECEIVE_BUFFER_SPACE
= 0x00010109,
496 OID_GEN_TRANSMIT_BLOCK_SIZE
= 0x0001010a,
497 OID_GEN_RECEIVE_BLOCK_SIZE
= 0x0001010b,
498 OID_GEN_VENDOR_ID
= 0x0001010c,
499 OID_GEN_VENDOR_DESCRIPTION
= 0x0001010d,
500 OID_GEN_CURRENT_PACKET_FILTER
= 0x0001010e,
501 OID_GEN_CURRENT_LOOKAHEAD
= 0x0001010f,
502 OID_GEN_DRIVER_VERSION
= 0x00010110,
503 OID_GEN_MAXIMUM_TOTAL_SIZE
= 0x00010111,
504 OID_GEN_PROTOCOL_OPTIONS
= 0x00010112,
505 OID_GEN_MAC_OPTIONS
= 0x00010113,
506 OID_GEN_MEDIA_CONNECT_STATUS
= 0x00010114,
507 OID_GEN_MAXIMUM_SEND_PACKETS
= 0x00010115,
508 OID_GEN_VENDOR_DRIVER_VERSION
= 0x00010116,
509 OID_GEN_SUPPORTED_GUIDS
= 0x00010117,
510 OID_GEN_NETWORK_LAYER_ADDRESSES
= 0x00010118,
511 OID_GEN_TRANSPORT_HEADER_OFFSET
= 0x00010119,
512 OID_GEN_MACHINE_NAME
= 0x0001021a,
513 OID_GEN_RNDIS_CONFIG_PARAMETER
= 0x0001021b,
514 OID_GEN_VLAN_ID
= 0x0001021c,
517 OID_GEN_MEDIA_CAPABILITIES
= 0x00010201,
518 OID_GEN_PHYSICAL_MEDIUM
= 0x00010202,
520 /* Required statistics OIDs */
521 OID_GEN_XMIT_OK
= 0x00020101,
522 OID_GEN_RCV_OK
= 0x00020102,
523 OID_GEN_XMIT_ERROR
= 0x00020103,
524 OID_GEN_RCV_ERROR
= 0x00020104,
525 OID_GEN_RCV_NO_BUFFER
= 0x00020105,
527 /* Optional statistics OIDs */
528 OID_GEN_DIRECTED_BYTES_XMIT
= 0x00020201,
529 OID_GEN_DIRECTED_FRAMES_XMIT
= 0x00020202,
530 OID_GEN_MULTICAST_BYTES_XMIT
= 0x00020203,
531 OID_GEN_MULTICAST_FRAMES_XMIT
= 0x00020204,
532 OID_GEN_BROADCAST_BYTES_XMIT
= 0x00020205,
533 OID_GEN_BROADCAST_FRAMES_XMIT
= 0x00020206,
534 OID_GEN_DIRECTED_BYTES_RCV
= 0x00020207,
535 OID_GEN_DIRECTED_FRAMES_RCV
= 0x00020208,
536 OID_GEN_MULTICAST_BYTES_RCV
= 0x00020209,
537 OID_GEN_MULTICAST_FRAMES_RCV
= 0x0002020a,
538 OID_GEN_BROADCAST_BYTES_RCV
= 0x0002020b,
539 OID_GEN_BROADCAST_FRAMES_RCV
= 0x0002020c,
540 OID_GEN_RCV_CRC_ERROR
= 0x0002020d,
541 OID_GEN_TRANSMIT_QUEUE_LENGTH
= 0x0002020e,
542 OID_GEN_GET_TIME_CAPS
= 0x0002020f,
543 OID_GEN_GET_NETCARD_TIME
= 0x00020210,
544 OID_GEN_NETCARD_LOAD
= 0x00020211,
545 OID_GEN_DEVICE_PROFILE
= 0x00020212,
546 OID_GEN_INIT_TIME_MS
= 0x00020213,
547 OID_GEN_RESET_COUNTS
= 0x00020214,
548 OID_GEN_MEDIA_SENSE_COUNTS
= 0x00020215,
549 OID_GEN_FRIENDLY_NAME
= 0x00020216,
550 OID_GEN_MINIPORT_INFO
= 0x00020217,
551 OID_GEN_RESET_VERIFY_PARAMETERS
= 0x00020218,
553 /* IEEE 802.3 (Ethernet) OIDs */
554 OID_802_3_PERMANENT_ADDRESS
= 0x01010101,
555 OID_802_3_CURRENT_ADDRESS
= 0x01010102,
556 OID_802_3_MULTICAST_LIST
= 0x01010103,
557 OID_802_3_MAXIMUM_LIST_SIZE
= 0x01010104,
558 OID_802_3_MAC_OPTIONS
= 0x01010105,
559 OID_802_3_RCV_ERROR_ALIGNMENT
= 0x01020101,
560 OID_802_3_XMIT_ONE_COLLISION
= 0x01020102,
561 OID_802_3_XMIT_MORE_COLLISIONS
= 0x01020103,
562 OID_802_3_XMIT_DEFERRED
= 0x01020201,
563 OID_802_3_XMIT_MAX_COLLISIONS
= 0x01020202,
564 OID_802_3_RCV_OVERRUN
= 0x01020203,
565 OID_802_3_XMIT_UNDERRUN
= 0x01020204,
566 OID_802_3_XMIT_HEARTBEAT_FAILURE
= 0x01020205,
567 OID_802_3_XMIT_TIMES_CRS_LOST
= 0x01020206,
568 OID_802_3_XMIT_LATE_COLLISIONS
= 0x01020207,
571 static const uint32_t oid_supported_list
[] =
573 /* the general stuff */
574 OID_GEN_SUPPORTED_LIST
,
575 OID_GEN_HARDWARE_STATUS
,
576 OID_GEN_MEDIA_SUPPORTED
,
577 OID_GEN_MEDIA_IN_USE
,
578 OID_GEN_MAXIMUM_FRAME_SIZE
,
580 OID_GEN_TRANSMIT_BLOCK_SIZE
,
581 OID_GEN_RECEIVE_BLOCK_SIZE
,
583 OID_GEN_VENDOR_DESCRIPTION
,
584 OID_GEN_VENDOR_DRIVER_VERSION
,
585 OID_GEN_CURRENT_PACKET_FILTER
,
586 OID_GEN_MAXIMUM_TOTAL_SIZE
,
587 OID_GEN_MEDIA_CONNECT_STATUS
,
588 OID_GEN_PHYSICAL_MEDIUM
,
590 /* the statistical stuff */
595 OID_GEN_RCV_NO_BUFFER
,
598 /* the general stuff */
599 OID_802_3_PERMANENT_ADDRESS
,
600 OID_802_3_CURRENT_ADDRESS
,
601 OID_802_3_MULTICAST_LIST
,
602 OID_802_3_MAC_OPTIONS
,
603 OID_802_3_MAXIMUM_LIST_SIZE
,
605 /* the statistical stuff */
606 OID_802_3_RCV_ERROR_ALIGNMENT
,
607 OID_802_3_XMIT_ONE_COLLISION
,
608 OID_802_3_XMIT_MORE_COLLISIONS
,
611 #define NDIS_MAC_OPTION_COPY_LOOKAHEAD_DATA (1 << 0)
612 #define NDIS_MAC_OPTION_RECEIVE_SERIALIZED (1 << 1)
613 #define NDIS_MAC_OPTION_TRANSFERS_NOT_PEND (1 << 2)
614 #define NDIS_MAC_OPTION_NO_LOOPBACK (1 << 3)
615 #define NDIS_MAC_OPTION_FULL_DUPLEX (1 << 4)
616 #define NDIS_MAC_OPTION_EOTX_INDICATION (1 << 5)
617 #define NDIS_MAC_OPTION_8021P_PRIORITY (1 << 6)
619 struct rndis_response
{
620 QTAILQ_ENTRY(rndis_response
) entries
;
625 typedef struct USBNetState
{
628 enum rndis_state rndis_state
;
631 uint32_t media_state
;
635 unsigned int out_ptr
;
636 uint8_t out_buf
[2048];
639 unsigned int in_ptr
, in_len
;
640 uint8_t in_buf
[2048];
642 char usbstring_mac
[13];
645 QTAILQ_HEAD(rndis_resp_head
, rndis_response
) rndis_resp
;
648 static int is_rndis(USBNetState
*s
)
650 return s
->dev
.config
->bConfigurationValue
== DEV_RNDIS_CONFIG_VALUE
;
653 static int ndis_query(USBNetState
*s
, uint32_t oid
,
654 uint8_t *inbuf
, unsigned int inlen
, uint8_t *outbuf
,
660 /* general oids (table 4-1) */
662 case OID_GEN_SUPPORTED_LIST
:
663 for (i
= 0; i
< ARRAY_SIZE(oid_supported_list
); i
++)
664 ((le32
*) outbuf
)[i
] = cpu_to_le32(oid_supported_list
[i
]);
665 return sizeof(oid_supported_list
);
668 case OID_GEN_HARDWARE_STATUS
:
669 *((le32
*) outbuf
) = cpu_to_le32(0);
673 case OID_GEN_MEDIA_SUPPORTED
:
674 *((le32
*) outbuf
) = cpu_to_le32(s
->medium
);
678 case OID_GEN_MEDIA_IN_USE
:
679 *((le32
*) outbuf
) = cpu_to_le32(s
->medium
);
683 case OID_GEN_MAXIMUM_FRAME_SIZE
:
684 *((le32
*) outbuf
) = cpu_to_le32(ETH_FRAME_LEN
);
688 case OID_GEN_LINK_SPEED
:
689 *((le32
*) outbuf
) = cpu_to_le32(s
->speed
);
693 case OID_GEN_TRANSMIT_BLOCK_SIZE
:
694 *((le32
*) outbuf
) = cpu_to_le32(ETH_FRAME_LEN
);
698 case OID_GEN_RECEIVE_BLOCK_SIZE
:
699 *((le32
*) outbuf
) = cpu_to_le32(ETH_FRAME_LEN
);
703 case OID_GEN_VENDOR_ID
:
704 *((le32
*) outbuf
) = cpu_to_le32(s
->vendorid
);
708 case OID_GEN_VENDOR_DESCRIPTION
:
709 pstrcpy((char *)outbuf
, outlen
, "QEMU USB RNDIS Net");
710 return strlen((char *)outbuf
) + 1;
712 case OID_GEN_VENDOR_DRIVER_VERSION
:
713 *((le32
*) outbuf
) = cpu_to_le32(1);
717 case OID_GEN_CURRENT_PACKET_FILTER
:
718 *((le32
*) outbuf
) = cpu_to_le32(s
->filter
);
722 case OID_GEN_MAXIMUM_TOTAL_SIZE
:
723 *((le32
*) outbuf
) = cpu_to_le32(RNDIS_MAX_TOTAL_SIZE
);
727 case OID_GEN_MEDIA_CONNECT_STATUS
:
728 *((le32
*) outbuf
) = cpu_to_le32(s
->media_state
);
731 case OID_GEN_PHYSICAL_MEDIUM
:
732 *((le32
*) outbuf
) = cpu_to_le32(0);
735 case OID_GEN_MAC_OPTIONS
:
736 *((le32
*) outbuf
) = cpu_to_le32(
737 NDIS_MAC_OPTION_RECEIVE_SERIALIZED
|
738 NDIS_MAC_OPTION_FULL_DUPLEX
);
741 /* statistics OIDs (table 4-2) */
743 case OID_GEN_XMIT_OK
:
744 *((le32
*) outbuf
) = cpu_to_le32(0);
749 *((le32
*) outbuf
) = cpu_to_le32(0);
753 case OID_GEN_XMIT_ERROR
:
754 *((le32
*) outbuf
) = cpu_to_le32(0);
758 case OID_GEN_RCV_ERROR
:
759 *((le32
*) outbuf
) = cpu_to_le32(0);
763 case OID_GEN_RCV_NO_BUFFER
:
764 *((le32
*) outbuf
) = cpu_to_le32(0);
767 /* ieee802.3 OIDs (table 4-3) */
769 case OID_802_3_PERMANENT_ADDRESS
:
770 memcpy(outbuf
, s
->conf
.macaddr
.a
, 6);
774 case OID_802_3_CURRENT_ADDRESS
:
775 memcpy(outbuf
, s
->conf
.macaddr
.a
, 6);
779 case OID_802_3_MULTICAST_LIST
:
780 *((le32
*) outbuf
) = cpu_to_le32(0xe0000000);
784 case OID_802_3_MAXIMUM_LIST_SIZE
:
785 *((le32
*) outbuf
) = cpu_to_le32(1);
788 case OID_802_3_MAC_OPTIONS
:
791 /* ieee802.3 statistics OIDs (table 4-4) */
793 case OID_802_3_RCV_ERROR_ALIGNMENT
:
794 *((le32
*) outbuf
) = cpu_to_le32(0);
798 case OID_802_3_XMIT_ONE_COLLISION
:
799 *((le32
*) outbuf
) = cpu_to_le32(0);
803 case OID_802_3_XMIT_MORE_COLLISIONS
:
804 *((le32
*) outbuf
) = cpu_to_le32(0);
808 fprintf(stderr
, "usbnet: unknown OID 0x%08x\n", oid
);
814 static int ndis_set(USBNetState
*s
, uint32_t oid
,
815 uint8_t *inbuf
, unsigned int inlen
)
818 case OID_GEN_CURRENT_PACKET_FILTER
:
819 s
->filter
= le32_to_cpup((le32
*) inbuf
);
821 s
->rndis_state
= RNDIS_DATA_INITIALIZED
;
823 s
->rndis_state
= RNDIS_INITIALIZED
;
827 case OID_802_3_MULTICAST_LIST
:
833 static int rndis_get_response(USBNetState
*s
, uint8_t *buf
)
836 struct rndis_response
*r
= s
->rndis_resp
.tqh_first
;
841 QTAILQ_REMOVE(&s
->rndis_resp
, r
, entries
);
843 memcpy(buf
, r
->buf
, r
->length
);
849 static void *rndis_queue_response(USBNetState
*s
, unsigned int length
)
851 struct rndis_response
*r
=
852 g_malloc0(sizeof(struct rndis_response
) + length
);
854 QTAILQ_INSERT_TAIL(&s
->rndis_resp
, r
, entries
);
860 static void rndis_clear_responsequeue(USBNetState
*s
)
862 struct rndis_response
*r
;
864 while ((r
= s
->rndis_resp
.tqh_first
)) {
865 QTAILQ_REMOVE(&s
->rndis_resp
, r
, entries
);
870 static int rndis_init_response(USBNetState
*s
, rndis_init_msg_type
*buf
)
872 rndis_init_cmplt_type
*resp
=
873 rndis_queue_response(s
, sizeof(rndis_init_cmplt_type
));
876 return USB_RET_STALL
;
878 resp
->MessageType
= cpu_to_le32(RNDIS_INITIALIZE_CMPLT
);
879 resp
->MessageLength
= cpu_to_le32(sizeof(rndis_init_cmplt_type
));
880 resp
->RequestID
= buf
->RequestID
; /* Still LE in msg buffer */
881 resp
->Status
= cpu_to_le32(RNDIS_STATUS_SUCCESS
);
882 resp
->MajorVersion
= cpu_to_le32(RNDIS_MAJOR_VERSION
);
883 resp
->MinorVersion
= cpu_to_le32(RNDIS_MINOR_VERSION
);
884 resp
->DeviceFlags
= cpu_to_le32(RNDIS_DF_CONNECTIONLESS
);
885 resp
->Medium
= cpu_to_le32(RNDIS_MEDIUM_802_3
);
886 resp
->MaxPacketsPerTransfer
= cpu_to_le32(1);
887 resp
->MaxTransferSize
= cpu_to_le32(ETH_FRAME_LEN
+
888 sizeof(struct rndis_packet_msg_type
) + 22);
889 resp
->PacketAlignmentFactor
= cpu_to_le32(0);
890 resp
->AFListOffset
= cpu_to_le32(0);
891 resp
->AFListSize
= cpu_to_le32(0);
895 static int rndis_query_response(USBNetState
*s
,
896 rndis_query_msg_type
*buf
, unsigned int length
)
898 rndis_query_cmplt_type
*resp
;
899 /* oid_supported_list is the largest data reply */
900 uint8_t infobuf
[sizeof(oid_supported_list
)];
901 uint32_t bufoffs
, buflen
;
903 unsigned int resplen
;
905 bufoffs
= le32_to_cpu(buf
->InformationBufferOffset
) + 8;
906 buflen
= le32_to_cpu(buf
->InformationBufferLength
);
907 if (bufoffs
+ buflen
> length
)
908 return USB_RET_STALL
;
910 infobuflen
= ndis_query(s
, le32_to_cpu(buf
->OID
),
911 bufoffs
+ (uint8_t *) buf
, buflen
, infobuf
,
913 resplen
= sizeof(rndis_query_cmplt_type
) +
914 ((infobuflen
< 0) ? 0 : infobuflen
);
915 resp
= rndis_queue_response(s
, resplen
);
917 return USB_RET_STALL
;
919 resp
->MessageType
= cpu_to_le32(RNDIS_QUERY_CMPLT
);
920 resp
->RequestID
= buf
->RequestID
; /* Still LE in msg buffer */
921 resp
->MessageLength
= cpu_to_le32(resplen
);
923 if (infobuflen
< 0) {
924 /* OID not supported */
925 resp
->Status
= cpu_to_le32(RNDIS_STATUS_NOT_SUPPORTED
);
926 resp
->InformationBufferLength
= cpu_to_le32(0);
927 resp
->InformationBufferOffset
= cpu_to_le32(0);
931 resp
->Status
= cpu_to_le32(RNDIS_STATUS_SUCCESS
);
932 resp
->InformationBufferOffset
=
933 cpu_to_le32(infobuflen
? sizeof(rndis_query_cmplt_type
) - 8 : 0);
934 resp
->InformationBufferLength
= cpu_to_le32(infobuflen
);
935 memcpy(resp
+ 1, infobuf
, infobuflen
);
940 static int rndis_set_response(USBNetState
*s
,
941 rndis_set_msg_type
*buf
, unsigned int length
)
943 rndis_set_cmplt_type
*resp
=
944 rndis_queue_response(s
, sizeof(rndis_set_cmplt_type
));
945 uint32_t bufoffs
, buflen
;
949 return USB_RET_STALL
;
951 bufoffs
= le32_to_cpu(buf
->InformationBufferOffset
) + 8;
952 buflen
= le32_to_cpu(buf
->InformationBufferLength
);
953 if (bufoffs
+ buflen
> length
)
954 return USB_RET_STALL
;
956 ret
= ndis_set(s
, le32_to_cpu(buf
->OID
),
957 bufoffs
+ (uint8_t *) buf
, buflen
);
958 resp
->MessageType
= cpu_to_le32(RNDIS_SET_CMPLT
);
959 resp
->RequestID
= buf
->RequestID
; /* Still LE in msg buffer */
960 resp
->MessageLength
= cpu_to_le32(sizeof(rndis_set_cmplt_type
));
962 /* OID not supported */
963 resp
->Status
= cpu_to_le32(RNDIS_STATUS_NOT_SUPPORTED
);
966 resp
->Status
= cpu_to_le32(RNDIS_STATUS_SUCCESS
);
971 static int rndis_reset_response(USBNetState
*s
, rndis_reset_msg_type
*buf
)
973 rndis_reset_cmplt_type
*resp
=
974 rndis_queue_response(s
, sizeof(rndis_reset_cmplt_type
));
977 return USB_RET_STALL
;
979 resp
->MessageType
= cpu_to_le32(RNDIS_RESET_CMPLT
);
980 resp
->MessageLength
= cpu_to_le32(sizeof(rndis_reset_cmplt_type
));
981 resp
->Status
= cpu_to_le32(RNDIS_STATUS_SUCCESS
);
982 resp
->AddressingReset
= cpu_to_le32(1); /* reset information */
987 static int rndis_keepalive_response(USBNetState
*s
,
988 rndis_keepalive_msg_type
*buf
)
990 rndis_keepalive_cmplt_type
*resp
=
991 rndis_queue_response(s
, sizeof(rndis_keepalive_cmplt_type
));
994 return USB_RET_STALL
;
996 resp
->MessageType
= cpu_to_le32(RNDIS_KEEPALIVE_CMPLT
);
997 resp
->MessageLength
= cpu_to_le32(sizeof(rndis_keepalive_cmplt_type
));
998 resp
->RequestID
= buf
->RequestID
; /* Still LE in msg buffer */
999 resp
->Status
= cpu_to_le32(RNDIS_STATUS_SUCCESS
);
1004 /* Prepare to receive the next packet */
1005 static void usb_net_reset_in_buf(USBNetState
*s
)
1007 s
->in_ptr
= s
->in_len
= 0;
1008 qemu_flush_queued_packets(&s
->nic
->nc
);
1011 static int rndis_parse(USBNetState
*s
, uint8_t *data
, int length
)
1014 le32
*tmp
= (le32
*) data
;
1016 msg_type
= le32_to_cpup(tmp
);
1019 case RNDIS_INITIALIZE_MSG
:
1020 s
->rndis_state
= RNDIS_INITIALIZED
;
1021 return rndis_init_response(s
, (rndis_init_msg_type
*) data
);
1023 case RNDIS_HALT_MSG
:
1024 s
->rndis_state
= RNDIS_UNINITIALIZED
;
1027 case RNDIS_QUERY_MSG
:
1028 return rndis_query_response(s
, (rndis_query_msg_type
*) data
, length
);
1031 return rndis_set_response(s
, (rndis_set_msg_type
*) data
, length
);
1033 case RNDIS_RESET_MSG
:
1034 rndis_clear_responsequeue(s
);
1036 usb_net_reset_in_buf(s
);
1037 return rndis_reset_response(s
, (rndis_reset_msg_type
*) data
);
1039 case RNDIS_KEEPALIVE_MSG
:
1040 /* For USB: host does this every 5 seconds */
1041 return rndis_keepalive_response(s
, (rndis_keepalive_msg_type
*) data
);
1044 return USB_RET_STALL
;
1047 static void usb_net_handle_reset(USBDevice
*dev
)
1051 static void usb_net_handle_control(USBDevice
*dev
, USBPacket
*p
,
1052 int request
, int value
, int index
, int length
, uint8_t *data
)
1054 USBNetState
*s
= (USBNetState
*) dev
;
1057 ret
= usb_desc_handle_control(dev
, p
, request
, value
, index
, length
, data
);
1063 case ClassInterfaceOutRequest
| USB_CDC_SEND_ENCAPSULATED_COMMAND
:
1064 if (!is_rndis(s
) || value
|| index
!= 0) {
1067 #ifdef TRAFFIC_DEBUG
1070 fprintf(stderr
, "SEND_ENCAPSULATED_COMMAND:");
1071 for (i
= 0; i
< length
; i
++) {
1073 fprintf(stderr
, "\n%04x:", i
);
1074 fprintf(stderr
, " %02x", data
[i
]);
1076 fprintf(stderr
, "\n\n");
1079 ret
= rndis_parse(s
, data
, length
);
1085 case ClassInterfaceRequest
| USB_CDC_GET_ENCAPSULATED_RESPONSE
:
1086 if (!is_rndis(s
) || value
|| index
!= 0) {
1089 p
->actual_length
= rndis_get_response(s
, data
);
1090 if (p
->actual_length
== 0) {
1092 p
->actual_length
= 1;
1094 #ifdef TRAFFIC_DEBUG
1097 fprintf(stderr
, "GET_ENCAPSULATED_RESPONSE:");
1098 for (i
= 0; i
< p
->actual_length
; i
++) {
1100 fprintf(stderr
, "\n%04x:", i
);
1101 fprintf(stderr
, " %02x", data
[i
]);
1103 fprintf(stderr
, "\n\n");
1110 fprintf(stderr
, "usbnet: failed control transaction: "
1111 "request 0x%x value 0x%x index 0x%x length 0x%x\n",
1112 request
, value
, index
, length
);
1113 p
->status
= USB_RET_STALL
;
1118 static void usb_net_handle_statusin(USBNetState
*s
, USBPacket
*p
)
1122 if (p
->iov
.size
< 8) {
1123 p
->status
= USB_RET_STALL
;
1127 buf
[0] = cpu_to_le32(1);
1128 buf
[1] = cpu_to_le32(0);
1129 usb_packet_copy(p
, buf
, 8);
1130 if (!s
->rndis_resp
.tqh_first
) {
1131 p
->status
= USB_RET_NAK
;
1134 #ifdef TRAFFIC_DEBUG
1135 fprintf(stderr
, "usbnet: interrupt poll len %zu return %d",
1136 p
->iov
.size
, p
->status
);
1137 iov_hexdump(p
->iov
.iov
, p
->iov
.niov
, stderr
, "usbnet", p
->status
);
1141 static void usb_net_handle_datain(USBNetState
*s
, USBPacket
*p
)
1145 if (s
->in_ptr
> s
->in_len
) {
1146 usb_net_reset_in_buf(s
);
1147 p
->status
= USB_RET_NAK
;
1151 p
->status
= USB_RET_NAK
;
1154 len
= s
->in_len
- s
->in_ptr
;
1155 if (len
> p
->iov
.size
) {
1158 usb_packet_copy(p
, &s
->in_buf
[s
->in_ptr
], len
);
1160 if (s
->in_ptr
>= s
->in_len
&&
1161 (is_rndis(s
) || (s
->in_len
& (64 - 1)) || !len
)) {
1162 /* no short packet necessary */
1163 usb_net_reset_in_buf(s
);
1166 #ifdef TRAFFIC_DEBUG
1167 fprintf(stderr
, "usbnet: data in len %zu return %d", p
->iov
.size
, len
);
1168 iov_hexdump(p
->iov
.iov
, p
->iov
.niov
, stderr
, "usbnet", len
);
1172 static void usb_net_handle_dataout(USBNetState
*s
, USBPacket
*p
)
1174 int sz
= sizeof(s
->out_buf
) - s
->out_ptr
;
1175 struct rndis_packet_msg_type
*msg
=
1176 (struct rndis_packet_msg_type
*) s
->out_buf
;
1179 #ifdef TRAFFIC_DEBUG
1180 fprintf(stderr
, "usbnet: data out len %zu\n", p
->iov
.size
);
1181 iov_hexdump(p
->iov
.iov
, p
->iov
.niov
, stderr
, "usbnet", p
->iov
.size
);
1184 if (sz
> p
->iov
.size
) {
1187 usb_packet_copy(p
, &s
->out_buf
[s
->out_ptr
], sz
);
1191 if (p
->iov
.size
< 64) {
1192 qemu_send_packet(&s
->nic
->nc
, s
->out_buf
, s
->out_ptr
);
1197 len
= le32_to_cpu(msg
->MessageLength
);
1198 if (s
->out_ptr
< 8 || s
->out_ptr
< len
) {
1201 if (le32_to_cpu(msg
->MessageType
) == RNDIS_PACKET_MSG
) {
1202 uint32_t offs
= 8 + le32_to_cpu(msg
->DataOffset
);
1203 uint32_t size
= le32_to_cpu(msg
->DataLength
);
1204 if (offs
+ size
<= len
)
1205 qemu_send_packet(&s
->nic
->nc
, s
->out_buf
+ offs
, size
);
1208 memmove(s
->out_buf
, &s
->out_buf
[len
], s
->out_ptr
);
1211 static void usb_net_handle_data(USBDevice
*dev
, USBPacket
*p
)
1213 USBNetState
*s
= (USBNetState
*) dev
;
1217 switch (p
->ep
->nr
) {
1219 usb_net_handle_statusin(s
, p
);
1223 usb_net_handle_datain(s
, p
);
1232 switch (p
->ep
->nr
) {
1234 usb_net_handle_dataout(s
, p
);
1244 p
->status
= USB_RET_STALL
;
1248 if (p
->status
== USB_RET_STALL
) {
1249 fprintf(stderr
, "usbnet: failed data transaction: "
1250 "pid 0x%x ep 0x%x len 0x%zx\n",
1251 p
->pid
, p
->ep
->nr
, p
->iov
.size
);
1255 static ssize_t
usbnet_receive(NetClientState
*nc
, const uint8_t *buf
, size_t size
)
1257 USBNetState
*s
= DO_UPCAST(NICState
, nc
, nc
)->opaque
;
1258 uint8_t *in_buf
= s
->in_buf
;
1259 size_t total_size
= size
;
1262 if (s
->rndis_state
!= RNDIS_DATA_INITIALIZED
) {
1265 total_size
+= sizeof(struct rndis_packet_msg_type
);
1267 if (total_size
> sizeof(s
->in_buf
)) {
1271 /* Only accept packet if input buffer is empty */
1272 if (s
->in_len
> 0) {
1277 struct rndis_packet_msg_type
*msg
;
1279 msg
= (struct rndis_packet_msg_type
*)in_buf
;
1280 memset(msg
, 0, sizeof(struct rndis_packet_msg_type
));
1281 msg
->MessageType
= cpu_to_le32(RNDIS_PACKET_MSG
);
1282 msg
->MessageLength
= cpu_to_le32(size
+ sizeof(*msg
));
1283 msg
->DataOffset
= cpu_to_le32(sizeof(*msg
) - 8);
1284 msg
->DataLength
= cpu_to_le32(size
);
1285 /* msg->OOBDataOffset;
1286 * msg->OOBDataLength;
1287 * msg->NumOOBDataElements;
1288 * msg->PerPacketInfoOffset;
1289 * msg->PerPacketInfoLength;
1293 in_buf
+= sizeof(*msg
);
1296 memcpy(in_buf
, buf
, size
);
1297 s
->in_len
= total_size
;
1302 static int usbnet_can_receive(NetClientState
*nc
)
1304 USBNetState
*s
= DO_UPCAST(NICState
, nc
, nc
)->opaque
;
1306 if (is_rndis(s
) && s
->rndis_state
!= RNDIS_DATA_INITIALIZED
) {
1313 static void usbnet_cleanup(NetClientState
*nc
)
1315 USBNetState
*s
= DO_UPCAST(NICState
, nc
, nc
)->opaque
;
1320 static void usb_net_handle_destroy(USBDevice
*dev
)
1322 USBNetState
*s
= (USBNetState
*) dev
;
1324 /* TODO: remove the nd_table[] entry */
1325 rndis_clear_responsequeue(s
);
1326 qemu_del_net_client(&s
->nic
->nc
);
1329 static NetClientInfo net_usbnet_info
= {
1330 .type
= NET_CLIENT_OPTIONS_KIND_NIC
,
1331 .size
= sizeof(NICState
),
1332 .can_receive
= usbnet_can_receive
,
1333 .receive
= usbnet_receive
,
1334 .cleanup
= usbnet_cleanup
,
1337 static int usb_net_initfn(USBDevice
*dev
)
1339 USBNetState
*s
= DO_UPCAST(USBNetState
, dev
, dev
);
1341 usb_desc_create_serial(dev
);
1344 s
->rndis_state
= RNDIS_UNINITIALIZED
;
1345 QTAILQ_INIT(&s
->rndis_resp
);
1347 s
->medium
= 0; /* NDIS_MEDIUM_802_3 */
1348 s
->speed
= 1000000; /* 100MBps, in 100Bps units */
1349 s
->media_state
= 0; /* NDIS_MEDIA_STATE_CONNECTED */;
1351 s
->vendorid
= 0x1234;
1353 qemu_macaddr_default_if_unset(&s
->conf
.macaddr
);
1354 s
->nic
= qemu_new_nic(&net_usbnet_info
, &s
->conf
,
1355 object_get_typename(OBJECT(s
)), s
->dev
.qdev
.id
, s
);
1356 qemu_format_nic_info_str(&s
->nic
->nc
, s
->conf
.macaddr
.a
);
1357 snprintf(s
->usbstring_mac
, sizeof(s
->usbstring_mac
),
1358 "%02x%02x%02x%02x%02x%02x",
1360 s
->conf
.macaddr
.a
[1],
1361 s
->conf
.macaddr
.a
[2],
1362 s
->conf
.macaddr
.a
[3],
1363 s
->conf
.macaddr
.a
[4],
1364 s
->conf
.macaddr
.a
[5]);
1365 usb_desc_set_string(dev
, STRING_ETHADDR
, s
->usbstring_mac
);
1367 add_boot_device_path(s
->conf
.bootindex
, &dev
->qdev
, "/ethernet@0");
1371 static USBDevice
*usb_net_init(USBBus
*bus
, const char *cmdline
)
1373 Error
*local_err
= NULL
;
1378 opts
= qemu_opts_parse(qemu_find_opts("net"), cmdline
, 0);
1382 qemu_opt_set(opts
, "type", "nic");
1383 qemu_opt_set(opts
, "model", "usb");
1385 idx
= net_client_init(opts
, 0, &local_err
);
1386 if (error_is_set(&local_err
)) {
1387 qerror_report_err(local_err
);
1388 error_free(local_err
);
1392 dev
= usb_create(bus
, "usb-net");
1396 qdev_set_nic_properties(&dev
->qdev
, &nd_table
[idx
]);
1397 qdev_init_nofail(&dev
->qdev
);
1401 static const VMStateDescription vmstate_usb_net
= {
1406 static Property net_properties
[] = {
1407 DEFINE_NIC_PROPERTIES(USBNetState
, conf
),
1408 DEFINE_PROP_END_OF_LIST(),
1411 static void usb_net_class_initfn(ObjectClass
*klass
, void *data
)
1413 DeviceClass
*dc
= DEVICE_CLASS(klass
);
1414 USBDeviceClass
*uc
= USB_DEVICE_CLASS(klass
);
1416 uc
->init
= usb_net_initfn
;
1417 uc
->product_desc
= "QEMU USB Network Interface";
1418 uc
->usb_desc
= &desc_net
;
1419 uc
->handle_reset
= usb_net_handle_reset
;
1420 uc
->handle_control
= usb_net_handle_control
;
1421 uc
->handle_data
= usb_net_handle_data
;
1422 uc
->handle_destroy
= usb_net_handle_destroy
;
1423 dc
->fw_name
= "network";
1424 dc
->vmsd
= &vmstate_usb_net
;
1425 dc
->props
= net_properties
;
1428 static TypeInfo net_info
= {
1430 .parent
= TYPE_USB_DEVICE
,
1431 .instance_size
= sizeof(USBNetState
),
1432 .class_init
= usb_net_class_initfn
,
1435 static void usb_net_register_types(void)
1437 type_register_static(&net_info
);
1438 usb_legacy_register("usb-net", "net", usb_net_init
);
1441 type_init(usb_net_register_types
)