1
2
3
4
5
6#ifndef __USBIP_NETWORK_H
7#define __USBIP_NETWORK_H
8
9#ifdef HAVE_CONFIG_H
10#include "../config.h"
11#endif
12
13#include <sys/types.h>
14
15#include <stdint.h>
16
17extern int usbip_port;
18extern char *usbip_port_string;
19void usbip_setup_port_number(char *arg);
20
21
22
23struct op_common {
24 uint16_t version;
25
26#define OP_REQUEST (0x80 << 8)
27#define OP_REPLY (0x00 << 8)
28 uint16_t code;
29
30
31 uint32_t status;
32
33} __attribute__((packed));
34
35#define PACK_OP_COMMON(pack, op_common) do {\
36 usbip_net_pack_uint16_t(pack, &(op_common)->version);\
37 usbip_net_pack_uint16_t(pack, &(op_common)->code);\
38 usbip_net_pack_uint32_t(pack, &(op_common)->status);\
39} while (0)
40
41
42
43#define OP_UNSPEC 0x00
44#define OP_REQ_UNSPEC OP_UNSPEC
45#define OP_REP_UNSPEC OP_UNSPEC
46
47
48
49#define OP_DEVINFO 0x02
50#define OP_REQ_DEVINFO (OP_REQUEST | OP_DEVINFO)
51#define OP_REP_DEVINFO (OP_REPLY | OP_DEVINFO)
52
53struct op_devinfo_request {
54 char busid[SYSFS_BUS_ID_SIZE];
55} __attribute__((packed));
56
57struct op_devinfo_reply {
58 struct usbip_usb_device udev;
59 struct usbip_usb_interface uinf[];
60} __attribute__((packed));
61
62
63
64#define OP_IMPORT 0x03
65#define OP_REQ_IMPORT (OP_REQUEST | OP_IMPORT)
66#define OP_REP_IMPORT (OP_REPLY | OP_IMPORT)
67
68struct op_import_request {
69 char busid[SYSFS_BUS_ID_SIZE];
70} __attribute__((packed));
71
72struct op_import_reply {
73 struct usbip_usb_device udev;
74
75} __attribute__((packed));
76
77#define PACK_OP_IMPORT_REQUEST(pack, request) do {\
78} while (0)
79
80#define PACK_OP_IMPORT_REPLY(pack, reply) do {\
81 usbip_net_pack_usb_device(pack, &(reply)->udev);\
82} while (0)
83
84
85
86#define OP_EXPORT 0x06
87#define OP_REQ_EXPORT (OP_REQUEST | OP_EXPORT)
88#define OP_REP_EXPORT (OP_REPLY | OP_EXPORT)
89
90struct op_export_request {
91 struct usbip_usb_device udev;
92} __attribute__((packed));
93
94struct op_export_reply {
95 int returncode;
96} __attribute__((packed));
97
98
99#define PACK_OP_EXPORT_REQUEST(pack, request) do {\
100 usbip_net_pack_usb_device(pack, &(request)->udev);\
101} while (0)
102
103#define PACK_OP_EXPORT_REPLY(pack, reply) do {\
104} while (0)
105
106
107
108#define OP_UNEXPORT 0x07
109#define OP_REQ_UNEXPORT (OP_REQUEST | OP_UNEXPORT)
110#define OP_REP_UNEXPORT (OP_REPLY | OP_UNEXPORT)
111
112struct op_unexport_request {
113 struct usbip_usb_device udev;
114} __attribute__((packed));
115
116struct op_unexport_reply {
117 int returncode;
118} __attribute__((packed));
119
120#define PACK_OP_UNEXPORT_REQUEST(pack, request) do {\
121 usbip_net_pack_usb_device(pack, &(request)->udev);\
122} while (0)
123
124#define PACK_OP_UNEXPORT_REPLY(pack, reply) do {\
125} while (0)
126
127
128
129#define OP_CRYPKEY 0x04
130#define OP_REQ_CRYPKEY (OP_REQUEST | OP_CRYPKEY)
131#define OP_REP_CRYPKEY (OP_REPLY | OP_CRYPKEY)
132
133struct op_crypkey_request {
134
135 uint32_t key[4];
136} __attribute__((packed));
137
138struct op_crypkey_reply {
139 uint32_t __reserved;
140} __attribute__((packed));
141
142
143
144
145#define OP_DEVLIST 0x05
146#define OP_REQ_DEVLIST (OP_REQUEST | OP_DEVLIST)
147#define OP_REP_DEVLIST (OP_REPLY | OP_DEVLIST)
148
149struct op_devlist_request {
150} __attribute__((packed));
151
152struct op_devlist_reply {
153 uint32_t ndev;
154
155} __attribute__((packed));
156
157struct op_devlist_reply_extra {
158 struct usbip_usb_device udev;
159 struct usbip_usb_interface uinf[];
160} __attribute__((packed));
161
162#define PACK_OP_DEVLIST_REQUEST(pack, request) do {\
163} while (0)
164
165#define PACK_OP_DEVLIST_REPLY(pack, reply) do {\
166 usbip_net_pack_uint32_t(pack, &(reply)->ndev);\
167} while (0)
168
169void usbip_net_pack_uint32_t(int pack, uint32_t *num);
170void usbip_net_pack_uint16_t(int pack, uint16_t *num);
171void usbip_net_pack_usb_device(int pack, struct usbip_usb_device *udev);
172void usbip_net_pack_usb_interface(int pack, struct usbip_usb_interface *uinf);
173
174ssize_t usbip_net_recv(int sockfd, void *buff, size_t bufflen);
175ssize_t usbip_net_send(int sockfd, void *buff, size_t bufflen);
176int usbip_net_send_op_common(int sockfd, uint32_t code, uint32_t status);
177int usbip_net_recv_op_common(int sockfd, uint16_t *code, int *status);
178int usbip_net_set_reuseaddr(int sockfd);
179int usbip_net_set_nodelay(int sockfd);
180int usbip_net_set_keepalive(int sockfd);
181int usbip_net_set_v6only(int sockfd);
182int usbip_net_tcp_connect(char *hostname, char *port);
183
184#endif
185