usbip_network.h 5.1 KB
Newer Older
1 2 3 4
/*
 * Copyright (C) 2005-2007 Takahiro Hirofuchi
 */

5 6
#ifndef __USBIP_NETWORK_H
#define __USBIP_NETWORK_H
7

8 9 10
#ifdef HAVE_CONFIG_H
#include "../config.h"
#endif
11

12
#include <sys/types.h>
13

14
#include <stdint.h>
15

16 17 18
extern int usbip_port;
extern char *usbip_port_string;
void usbip_setup_port_number(char *arg);
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36

/* ---------------------------------------------------------------------- */
/* Common header for all the kinds of PDUs. */
struct op_common {
	uint16_t version;

#define OP_REQUEST	(0x80 << 8)
#define OP_REPLY	(0x00 << 8)
	uint16_t code;

	/* add more error code */
#define ST_OK	0x00
#define ST_NA	0x01
	uint32_t status; /* op_code status (for reply) */

} __attribute__((packed));

#define PACK_OP_COMMON(pack, op_common)  do {\
37
	usbip_net_pack_uint16_t(pack, &(op_common)->version);\
38 39
	usbip_net_pack_uint16_t(pack, &(op_common)->code);\
	usbip_net_pack_uint32_t(pack, &(op_common)->status);\
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58
} while (0)

/* ---------------------------------------------------------------------- */
/* Dummy Code */
#define OP_UNSPEC	0x00
#define OP_REQ_UNSPEC	OP_UNSPEC
#define OP_REP_UNSPEC	OP_UNSPEC

/* ---------------------------------------------------------------------- */
/* Retrieve USB device information. (still not used) */
#define OP_DEVINFO	0x02
#define OP_REQ_DEVINFO	(OP_REQUEST | OP_DEVINFO)
#define OP_REP_DEVINFO	(OP_REPLY   | OP_DEVINFO)

struct op_devinfo_request {
	char busid[SYSFS_BUS_ID_SIZE];
} __attribute__((packed));

struct op_devinfo_reply {
59 60
	struct usbip_usb_device udev;
	struct usbip_usb_interface uinf[];
61 62 63 64 65 66 67 68 69 70 71 72 73
} __attribute__((packed));

/* ---------------------------------------------------------------------- */
/* Import a remote USB device. */
#define OP_IMPORT	0x03
#define OP_REQ_IMPORT	(OP_REQUEST | OP_IMPORT)
#define OP_REP_IMPORT   (OP_REPLY   | OP_IMPORT)

struct op_import_request {
	char busid[SYSFS_BUS_ID_SIZE];
} __attribute__((packed));

struct op_import_reply {
74 75
	struct usbip_usb_device udev;
//	struct usbip_usb_interface uinf[];
76 77 78 79 80 81
} __attribute__((packed));

#define PACK_OP_IMPORT_REQUEST(pack, request)  do {\
} while (0)

#define PACK_OP_IMPORT_REPLY(pack, reply)  do {\
82
	usbip_net_pack_usb_device(pack, &(reply)->udev);\
83 84 85 86 87 88 89 90 91
} while (0)

/* ---------------------------------------------------------------------- */
/* Export a USB device to a remote host. */
#define OP_EXPORT	0x06
#define OP_REQ_EXPORT	(OP_REQUEST | OP_EXPORT)
#define OP_REP_EXPORT	(OP_REPLY   | OP_EXPORT)

struct op_export_request {
92
	struct usbip_usb_device udev;
93 94 95
} __attribute__((packed));

struct op_export_reply {
96
	int returncode;
97 98 99 100
} __attribute__((packed));


#define PACK_OP_EXPORT_REQUEST(pack, request)  do {\
101
	usbip_net_pack_usb_device(pack, &(request)->udev);\
102 103 104 105 106 107 108 109 110 111 112 113
} while (0)

#define PACK_OP_EXPORT_REPLY(pack, reply)  do {\
} while (0)

/* ---------------------------------------------------------------------- */
/* un-Export a USB device from a remote host. */
#define OP_UNEXPORT	0x07
#define OP_REQ_UNEXPORT	(OP_REQUEST | OP_UNEXPORT)
#define OP_REP_UNEXPORT	(OP_REPLY   | OP_UNEXPORT)

struct op_unexport_request {
114
	struct usbip_usb_device udev;
115 116 117
} __attribute__((packed));

struct op_unexport_reply {
118
	int returncode;
119 120 121
} __attribute__((packed));

#define PACK_OP_UNEXPORT_REQUEST(pack, request)  do {\
122
	usbip_net_pack_usb_device(pack, &(request)->udev);\
123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158
} while (0)

#define PACK_OP_UNEXPORT_REPLY(pack, reply)  do {\
} while (0)

/* ---------------------------------------------------------------------- */
/* Negotiate IPSec encryption key. (still not used) */
#define OP_CRYPKEY	0x04
#define OP_REQ_CRYPKEY	(OP_REQUEST | OP_CRYPKEY)
#define OP_REP_CRYPKEY	(OP_REPLY   | OP_CRYPKEY)

struct op_crypkey_request {
	/* 128bit key */
	uint32_t key[4];
} __attribute__((packed));

struct op_crypkey_reply {
	uint32_t __reserved;
} __attribute__((packed));


/* ---------------------------------------------------------------------- */
/* Retrieve the list of exported USB devices. */
#define OP_DEVLIST	0x05
#define OP_REQ_DEVLIST	(OP_REQUEST | OP_DEVLIST)
#define OP_REP_DEVLIST	(OP_REPLY   | OP_DEVLIST)

struct op_devlist_request {
} __attribute__((packed));

struct op_devlist_reply {
	uint32_t ndev;
	/* followed by reply_extra[] */
} __attribute__((packed));

struct op_devlist_reply_extra {
159 160
	struct usbip_usb_device    udev;
	struct usbip_usb_interface uinf[];
161 162 163 164 165 166
} __attribute__((packed));

#define PACK_OP_DEVLIST_REQUEST(pack, request)  do {\
} while (0)

#define PACK_OP_DEVLIST_REPLY(pack, reply)  do {\
167
	usbip_net_pack_uint32_t(pack, &(reply)->ndev);\
168 169
} while (0)

170 171 172 173 174 175 176 177 178 179 180 181
void usbip_net_pack_uint32_t(int pack, uint32_t *num);
void usbip_net_pack_uint16_t(int pack, uint16_t *num);
void usbip_net_pack_usb_device(int pack, struct usbip_usb_device *udev);
void usbip_net_pack_usb_interface(int pack, struct usbip_usb_interface *uinf);

ssize_t usbip_net_recv(int sockfd, void *buff, size_t bufflen);
ssize_t usbip_net_send(int sockfd, void *buff, size_t bufflen);
int usbip_net_send_op_common(int sockfd, uint32_t code, uint32_t status);
int usbip_net_recv_op_common(int sockfd, uint16_t *code);
int usbip_net_set_reuseaddr(int sockfd);
int usbip_net_set_nodelay(int sockfd);
int usbip_net_set_keepalive(int sockfd);
182
int usbip_net_set_v6only(int sockfd);
183
int usbip_net_tcp_connect(char *hostname, char *port);
184

185
#endif /* __USBIP_NETWORK_H */