~ubuntu-branches/ubuntu/precise/linux-ti-omap4/precise

« back to all changes in this revision

Viewing changes to drivers/staging/usbip/userspace/src/usbip_network.h

  • Committer: Bazaar Package Importer
  • Author(s): Paolo Pisati
  • Date: 2011-06-29 15:23:51 UTC
  • mfrom: (26.1.1 natty-proposed)
  • Revision ID: james.westby@ubuntu.com-20110629152351-xs96tm303d95rpbk
Tags: 3.0.0-1200.2
* Rebased against 3.0.0-6.7
* BSP from TI based on 3.0.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Copyright (C) 2005-2007 Takahiro Hirofuchi
 
3
 */
 
4
 
 
5
#ifndef _USBIP_NETWORK_H
 
6
#define _USBIP_NETWORK_H
 
7
 
 
8
#include "usbip.h"
 
9
#include <sys/types.h>
 
10
#include <sys/socket.h>
 
11
#include <netinet/tcp.h>
 
12
 
 
13
 
 
14
/* -------------------------------------------------- */
 
15
/* Define Protocol Format                             */
 
16
/* -------------------------------------------------- */
 
17
 
 
18
 
 
19
/* ---------------------------------------------------------------------- */
 
20
/* Common header for all the kinds of PDUs. */
 
21
struct op_common {
 
22
        uint16_t version;
 
23
 
 
24
#define OP_REQUEST      (0x80 << 8)
 
25
#define OP_REPLY        (0x00 << 8)
 
26
        uint16_t code;
 
27
 
 
28
        /* add more error code */
 
29
#define ST_OK   0x00
 
30
#define ST_NA   0x01
 
31
        uint32_t status; /* op_code status (for reply) */
 
32
 
 
33
} __attribute__((packed));
 
34
 
 
35
#define PACK_OP_COMMON(pack, op_common)  do {\
 
36
        pack_uint16_t(pack, &(op_common)->version);\
 
37
        pack_uint16_t(pack, &(op_common)->code   );\
 
38
        pack_uint32_t(pack, &(op_common)->status );\
 
39
} while (0)
 
40
 
 
41
 
 
42
/* ---------------------------------------------------------------------- */
 
43
/* Dummy Code */
 
44
#define OP_UNSPEC       0x00
 
45
#define OP_REQ_UNSPEC   OP_UNSPEC
 
46
#define OP_REP_UNSPEC   OP_UNSPEC
 
47
 
 
48
/* ---------------------------------------------------------------------- */
 
49
/* Retrieve USB device information. (still not used) */
 
50
#define OP_DEVINFO      0x02
 
51
#define OP_REQ_DEVINFO  (OP_REQUEST | OP_DEVINFO)
 
52
#define OP_REP_DEVINFO  (OP_REPLY   | OP_DEVINFO)
 
53
 
 
54
struct op_devinfo_request {
 
55
        char busid[SYSFS_BUS_ID_SIZE];
 
56
} __attribute__((packed));
 
57
 
 
58
struct op_devinfo_reply {
 
59
        struct usb_device udev;
 
60
        struct usb_interface uinf[];
 
61
} __attribute__((packed));
 
62
 
 
63
 
 
64
/* ---------------------------------------------------------------------- */
 
65
/* Import a remote USB device. */
 
66
#define OP_IMPORT       0x03
 
67
#define OP_REQ_IMPORT   (OP_REQUEST | OP_IMPORT)
 
68
#define OP_REP_IMPORT   (OP_REPLY   | OP_IMPORT)
 
69
 
 
70
struct op_import_request {
 
71
        char busid[SYSFS_BUS_ID_SIZE];
 
72
} __attribute__((packed));
 
73
 
 
74
struct op_import_reply {
 
75
        struct usb_device udev;
 
76
//      struct usb_interface uinf[];
 
77
} __attribute__((packed));
 
78
 
 
79
#define PACK_OP_IMPORT_REQUEST(pack, request)  do {\
 
80
} while (0)
 
81
 
 
82
#define PACK_OP_IMPORT_REPLY(pack, reply)  do {\
 
83
        pack_usb_device(pack, &(reply)->udev);\
 
84
} while (0)
 
85
 
 
86
 
 
87
 
 
88
/* ---------------------------------------------------------------------- */
 
89
/* Export a USB device to a remote host. */
 
90
#define OP_EXPORT       0x06
 
91
#define OP_REQ_EXPORT   (OP_REQUEST | OP_EXPORT)
 
92
#define OP_REP_EXPORT   (OP_REPLY   | OP_EXPORT)
 
93
 
 
94
struct op_export_request {
 
95
        struct usb_device udev;
 
96
} __attribute__((packed));
 
97
 
 
98
struct op_export_reply {
 
99
        int returncode;
 
100
} __attribute__((packed));
 
101
 
 
102
 
 
103
#define PACK_OP_EXPORT_REQUEST(pack, request)  do {\
 
104
        pack_usb_device(pack, &(request)->udev);\
 
105
} while (0)
 
106
 
 
107
#define PACK_OP_EXPORT_REPLY(pack, reply)  do {\
 
108
} while (0)
 
109
 
 
110
/* ---------------------------------------------------------------------- */
 
111
/* un-Export a USB device from a remote host. */
 
112
#define OP_UNEXPORT     0x07
 
113
#define OP_REQ_UNEXPORT (OP_REQUEST | OP_UNEXPORT)
 
114
#define OP_REP_UNEXPORT (OP_REPLY   | OP_UNEXPORT)
 
115
 
 
116
struct op_unexport_request {
 
117
        struct usb_device udev;
 
118
} __attribute__((packed));
 
119
 
 
120
struct op_unexport_reply {
 
121
        int returncode;
 
122
} __attribute__((packed));
 
123
 
 
124
#define PACK_OP_UNEXPORT_REQUEST(pack, request)  do {\
 
125
        pack_usb_device(pack, &(request)->udev);\
 
126
} while (0)
 
127
 
 
128
#define PACK_OP_UNEXPORT_REPLY(pack, reply)  do {\
 
129
} while (0)
 
130
 
 
131
 
 
132
 
 
133
/* ---------------------------------------------------------------------- */
 
134
/* Negotiate IPSec encryption key. (still not used) */
 
135
#define OP_CRYPKEY      0x04
 
136
#define OP_REQ_CRYPKEY  (OP_REQUEST | OP_CRYPKEY)
 
137
#define OP_REP_CRYPKEY  (OP_REPLY   | OP_CRYPKEY)
 
138
 
 
139
struct op_crypkey_request {
 
140
        /* 128bit key */
 
141
        uint32_t key[4];
 
142
} __attribute__((packed));
 
143
 
 
144
struct op_crypkey_reply {
 
145
        uint32_t __reserved;
 
146
} __attribute__((packed));
 
147
 
 
148
 
 
149
/* ---------------------------------------------------------------------- */
 
150
/* Retrieve the list of exported USB devices. */
 
151
#define OP_DEVLIST      0x05
 
152
#define OP_REQ_DEVLIST  (OP_REQUEST | OP_DEVLIST)
 
153
#define OP_REP_DEVLIST  (OP_REPLY   | OP_DEVLIST)
 
154
 
 
155
struct op_devlist_request {
 
156
} __attribute__((packed));
 
157
 
 
158
struct op_devlist_reply {
 
159
        uint32_t ndev;
 
160
        /* followed by reply_extra[] */
 
161
} __attribute__((packed));
 
162
 
 
163
struct op_devlist_reply_extra {
 
164
        struct usb_device    udev;
 
165
        struct usb_interface uinf[];
 
166
} __attribute__((packed));
 
167
 
 
168
#define PACK_OP_DEVLIST_REQUEST(pack, request)  do {\
 
169
} while (0)
 
170
 
 
171
#define PACK_OP_DEVLIST_REPLY(pack, reply)  do {\
 
172
        pack_uint32_t(pack, &(reply)->ndev);\
 
173
} while (0)
 
174
 
 
175
 
 
176
/* -------------------------------------------------- */
 
177
/* Declare Prototype Function                         */
 
178
/* -------------------------------------------------- */
 
179
 
 
180
void pack_uint32_t(int pack, uint32_t *num);
 
181
void pack_uint16_t(int pack, uint16_t *num);
 
182
void pack_usb_device(int pack, struct usb_device *udev);
 
183
void pack_usb_interface(int pack, struct usb_interface *uinf);
 
184
 
 
185
ssize_t usbip_recv(int sockfd, void *buff, size_t bufflen);
 
186
ssize_t usbip_send(int sockfd, void *buff, size_t bufflen);
 
187
int usbip_send_op_common(int sockfd, uint32_t code, uint32_t status);
 
188
int usbip_recv_op_common(int sockfd, uint16_t *code);
 
189
int usbip_set_reuseaddr(int sockfd);
 
190
int usbip_set_nodelay(int sockfd);
 
191
int usbip_set_keepalive(int sockfd);
 
192
 
 
193
int tcp_connect(char *hostname, char *service);
 
194
 
 
195
#define USBIP_PORT 3240
 
196
#define USBIP_PORT_STRING "3240"
 
197
 
 
198
#endif