1 /*
2  * Copyright (c) 2021 Nordic Semiconductor ASA
3  *
4  * SPDX-License-Identifier: Apache-2.0
5  */
6 
7 #define USBIP_PORT		3240
8 #define USBIP_VERSION		0x0111U
9 
10 /* Retrieve the list of exported devices command code */
11 #define USBIP_OP_REQ_DEVLIST	0x8005U
12 /* Reply the list of exported devices command code */
13 #define USBIP_OP_REP_DEVLIST	0x0005U
14 /* Request to import a remote device command code */
15 #define USBIP_OP_REQ_IMPORT	0x8003U
16 /* Reply to import a remote device command code */
17 #define USBIP_OP_REP_IMPORT	0x0003U
18 
19 /* Submit an URB command code */
20 #define USBIP_CMD_SUBMIT	0x0001UL
21 /* Reply for submitting an URB command code */
22 #define USBIP_RET_SUBMIT	0x0003UL
23 /* Unlink an URB command code */
24 #define USBIP_CMD_UNLINK	0x0002UL
25 /* Reply for unlink an URB command code */
26 #define USBIP_RET_UNLINK	0x0004UL
27 
28 /* Command direction */
29 #define USBIP_DIR_OUT		0UL
30 #define USBIP_DIR_IN		1UL
31 
32 struct usbip_req_header {
33 	uint16_t version;
34 	uint16_t code;
35 	uint32_t status;
36 } __packed;
37 
38 struct usbip_devlist_header {
39 	uint16_t version;
40 	uint16_t code;
41 	uint32_t status;
42 	uint32_t ndev;
43 } __packed;
44 
45 struct usbip_devlist_data {
46 	char path[256];
47 	char busid[32];
48 
49 	uint32_t busnum;
50 	uint32_t devnum;
51 	uint32_t speed;
52 
53 	uint16_t idVendor;
54 	uint16_t idProduct;
55 	uint16_t bcdDevice;
56 
57 	uint8_t bDeviceClass;
58 	uint8_t bDeviceSubClass;
59 	uint8_t bDeviceProtocol;
60 	uint8_t bConfigurationValue;
61 	uint8_t bNumConfigurations;
62 	uint8_t bNumInterfaces;
63 } __packed;
64 
65 struct usbip_devlist_iface_data {
66 	uint8_t bInterfaceClass;
67 	uint8_t bInterfaceSubClass;
68 	uint8_t bInterfaceProtocol;
69 	uint8_t padding;
70 } __packed;
71 
72 struct usbip_cmd_header {
73 	uint32_t command;
74 	uint32_t seqnum;
75 	uint32_t devid;
76 	uint32_t direction;
77 	uint32_t ep;
78 } __packed;
79 
80 struct usbip_cmd_submit {
81 	uint32_t flags;
82 	uint32_t length;
83 	int32_t start_frame;
84 	int32_t numof_iso_pkts;
85 	int32_t interval;
86 	uint8_t setup[8];
87 } __packed;
88 
89 struct usbip_cmd_unlink {
90 	uint32_t seqnum;
91 	uint32_t padding[6];
92 } __packed;
93 
94 struct usbip_command {
95 	struct usbip_cmd_header hdr;
96 
97 	union {
98 		struct usbip_cmd_submit submit;
99 		struct usbip_cmd_unlink unlink;
100 	};
101 } __packed;
102 
103 struct usbip_ret_submit {
104 	int32_t status;
105 	uint32_t actual_length;
106 	int32_t start_frame;
107 	int32_t numof_iso_pkts;
108 	int32_t error_count;
109 	uint64_t setup;
110 } __packed;
111 
112 struct usbip_ret_unlink {
113 	int32_t status;
114 	uint32_t padding[6];
115 } __packed;
116 
117 struct usbip_return {
118 	struct usbip_cmd_header hdr;
119 
120 	union {
121 		struct usbip_ret_submit submit;
122 		struct usbip_ret_unlink unlink;
123 	};
124 } __packed;
125