~ubuntu-branches/ubuntu/raring/virtualbox-ose/raring

« back to all changes in this revision

Viewing changes to src/VBox/RDP/client/vrdp/vrdpusb.h

  • Committer: Bazaar Package Importer
  • Author(s): Felix Geyer
  • Date: 2011-01-30 23:27:25 UTC
  • mfrom: (0.3.12 upstream)
  • Revision ID: james.westby@ubuntu.com-20110130232725-2ouajjd2ggdet0zd
Tags: 4.0.2-dfsg-1ubuntu1
* Merge from Debian unstable, remaining changes:
  - Add Apport hook.
    - debian/virtualbox-ose.files/source_virtualbox-ose.py
    - debian/virtualbox-ose.install
  - Drop *-source packages.
* Drop ubuntu-01-fix-build-gcc45.patch, fixed upstream.
* Drop ubuntu-02-as-needed.patch, added to the Debian package.

Show diffs side-by-side

added added

removed removed

Lines of Context:
17
17
#ifndef __VRDPUSB__H
18
18
#define __VRDPUSB__H
19
19
 
20
 
#include <endian.h>
21
 
#include <byteswap.h>
22
 
 
23
 
#ifndef cpu_to_le16
24
 
#if __BYTE_ORDER == __LITTLE_ENDIAN
25
 
#define cpu_to_le16(_le16) (_le16)
26
 
#elif __BYTE_ORDER == __BIG_ENDIAN
27
 
#define cpu_to_le16(_le16) bswap_16(_le16)
28
 
#else
29
 
#error Unsupported host byte order!
30
 
#endif
31
 
#endif /* cpu_to_le16 */
32
 
 
33
 
//#include <asm/byteorder.h>
34
 
//#define cpu_to_le16 __cpu_to_le16
35
 
 
36
 
#define uint8_t uint8
37
 
#define uint16_t uint16
38
 
#define uint32_t uint32
39
 
#define uint64_t long long
40
 
#define bool int
41
 
#define false 0
42
 
#define true 1
43
 
 
44
 
#define OPSTATIC
45
 
#ifdef RDPUSB_DEBUG
46
 
#define LogFlow(a) printf a
47
 
#define Log(a) printf a
48
 
#define Log2(a) printf a
49
 
#else
50
 
#define LogFlow(a) do {} while (0)
51
 
#define Log(a)     do {} while (0)
52
 
#define Log2(a)    do {} while (0)
53
 
#endif
54
 
 
55
 
#define LogRel(a) printf a
56
 
 
57
 
/* Runtime wrappers. */
58
 
#define RTMemAlloc xmalloc
59
 
#define RTMemRealloc xrealloc
60
 
#define RTMemFree xfree
61
 
 
62
 
#define _1K 1024
63
 
 
64
 
#define RT_LE2H_U16(_le16) (cpu_to_le16 (_le16))
65
 
 
66
 
#define VINF_SUCCESS 0
67
 
#define VERR_NO_MEMORY     (-8)
68
 
#define VERR_NOT_SUPPORTED (-37)
69
 
#define VERR_ACCESS_DENIED (-38)
70
 
#define VERR_VUSB_USBFS_PERMISSION (-2005)
71
 
 
72
 
#define RT_SUCCESS(_rc) ((_rc) >= 0)
73
 
 
74
 
#define RTFILE int
75
 
#define RTCRITSECT void *
76
 
 
77
 
#define Assert(_expr) do {                            \
78
 
    if (!(_expr))                                     \
79
 
    {                                                 \
80
 
        Log(("Assertion failed: {%s}!!!\n", #_expr)); \
81
 
    }                                                 \
82
 
} while (0)
83
 
 
84
 
#define AssertMsgFailed(_msg) do {                    \
85
 
        Log(("Assertion failed msg:!!!\n"));          \
86
 
        Log(_msg);                                    \
87
 
} while (0)
88
 
 
89
 
#define AssertReturn(_expr, _retval) do {             \
90
 
    if (!(_expr))                                     \
91
 
    {                                                 \
92
 
        Log(("Assertion failed: {%s}, returning 0x%08X!!!\n", #_expr, _retval)); \
93
 
        return (_retval);                             \
94
 
    }                                                 \
95
 
} while (0)
96
 
 
97
 
#define AssertRC(_rc) Assert(RT_SUCCESS(_rc))
98
 
 
99
 
#define RT_FAILURE(_rc) (!RT_SUCCESS(_rc))
100
 
 
101
 
#define NOREF(_a) ((void)_a)
102
 
 
103
 
static inline int RTCritSectInit (RTCRITSECT *pCritSect)
104
 
{
105
 
    return VINF_SUCCESS;
106
 
}
107
 
 
108
 
static inline int RTCritSectDelete (RTCRITSECT *pCritSect)
109
 
{
110
 
    return VINF_SUCCESS;
111
 
}
112
 
 
113
 
static inline int RTCritSectEnter (RTCRITSECT *pCritSect)
114
 
{
115
 
    return VINF_SUCCESS;
116
 
}
117
 
 
118
 
static inline int RTCritSectLeave (RTCRITSECT *pCritSect)
119
 
{
120
 
    return VINF_SUCCESS;
121
 
}
122
 
 
123
 
static inline void *RTMemDupEx (const void *pvSrc, size_t cbSrc, size_t cbExtra)
124
 
{
125
 
    void *p = RTMemAlloc (cbSrc + cbExtra);
126
 
 
127
 
    if (p)
128
 
    {
129
 
         memcpy (p, pvSrc, cbSrc);
130
 
         memset ((char *)p + cbSrc, 0, cbExtra);
131
 
    }
132
 
 
133
 
    return p;
134
 
}
135
 
 
136
 
static inline void *RTMemAllocZ (size_t cb)
137
 
{
138
 
    void *p = RTMemAlloc (cb);
139
 
 
140
 
    if (p)
141
 
    {
142
 
         memset (p, 0, cb);
143
 
    }
144
 
 
145
 
    return p;
146
 
}
147
 
 
148
 
static inline int RTStrToUInt32Ex (const char *pszValue, char **ppszNext, unsigned uBase, uint32_t *pu32)
149
 
{
150
 
    *pu32 = strtoul (pszValue, ppszNext, uBase);
151
 
    return VINF_SUCCESS;
152
 
}
153
 
 
154
 
#define PRTSTREAM FILE *
155
 
 
156
 
static inline int RTStrmOpen (const char *pszFileName, const char *pszMode, PRTSTREAM *ppStream)
157
 
{
158
 
    *ppStream = fopen (pszFileName, pszMode);
159
 
 
160
 
    if (*ppStream)
161
 
    {
162
 
        return VINF_SUCCESS;
163
 
    }
164
 
 
165
 
    return VERR_NOT_SUPPORTED;
166
 
}
167
 
 
168
 
static inline int RTStrmClose (PRTSTREAM pStream)
169
 
{
170
 
    fclose (pStream);
171
 
    return VINF_SUCCESS;
172
 
}
173
 
 
174
 
static inline int RTStrmGetLine (PRTSTREAM pStream, char *pszString, size_t cchString)
175
 
{
176
 
    if (fgets (pszString, cchString, pStream))
177
 
    {
178
 
        return VINF_SUCCESS;
179
 
    }
180
 
 
181
 
    return VERR_NOT_SUPPORTED;
182
 
}
183
 
 
184
 
static inline char *RTStrStripL (const char *psz)
185
 
{
186
 
    while (isspace (*psz))
187
 
        psz++;
188
 
    return (char *)psz;
189
 
}
190
 
 
191
 
#define NIL_RTFILE -1
192
 
 
193
 
#define RTFILE_O_READWRITE 0x00000003
194
 
#define RTFILE_O_OPEN      0x00000000
195
 
#define RTFILE_O_DENY_NONE 0x00000000
196
 
 
197
 
static inline int RTFileOpen (RTFILE *pFile, const char *pszFileName, unsigned fOpen)
198
 
{
199
 
    Assert (fOpen == RTFILE_O_READWRITE);
200
 
 
201
 
    *pFile = open (pszFileName, O_RDWR, 00600);
202
 
 
203
 
    if (*pFile != -1)
204
 
    {
205
 
        return VINF_SUCCESS;
206
 
    }
207
 
 
208
 
    return VERR_ACCESS_DENIED;
209
 
}
210
 
 
211
 
static inline int RTFileClose (RTFILE file)
212
 
{
213
 
    close (file);
214
 
    return VINF_SUCCESS;
215
 
}
216
 
 
217
 
static inline uint64_t RTTimeMilliTS (void)
218
 
{
219
 
     struct timeval tv;
220
 
     gettimeofday (&tv, NULL);
221
 
     return (uint64_t)tv.tv_sec * (uint64_t)(1000)
222
 
            + (uint64_t)(tv.tv_usec / 1000);
223
 
}
224
 
 
225
20
#define VRDP_USB_STATUS_SUCCESS         0
226
21
#define VRDP_USB_STATUS_ACCESS_DENIED   1
227
22
#define VRDP_USB_STATUS_DEVICE_REMOVED  2
232
27
#define VRDP_USB_CAPS_FLAG_ASYNC    (0)
233
28
#define VRDP_USB_CAPS_FLAG_POLL     (1)
234
29
 
235
 
#pragma pack(1)
236
 
 
237
 
#include "vusb.h"
238
 
 
239
 
typedef struct VUSBDEV
240
 
{
241
 
        char* pszName;
242
 
        int request_detach;
243
 
} VUSBDEV, *PVUSBDEV;
244
 
 
245
 
typedef struct usb_proxy {
246
 
    /* Note: the backend code assumes that the dev member is the first in the structure. */
247
 
    VUSBDEV Dev;
248
 
    /* 'union' because backend accesses the file handle as priv.File. */
249
 
    union {
250
 
        void *pv;
251
 
        int File;
252
 
    } Backend;
253
 
 
254
 
    struct usb_proxy *next;
255
 
    struct usb_proxy *prev;
256
 
 
257
 
    uint32_t devid;
258
 
 
259
 
    PVUSBURB urbs;
260
 
 
261
 
    int iActiveCfg;
262
 
    int cIgnoreSetConfigs;
263
 
} *PUSBPROXYDEV;
264
 
 
265
 
typedef struct vusb_setup {
266
 
        uint8_t  bmRequestType;
267
 
        uint8_t  bRequest;
268
 
        uint16_t wValue;
269
 
        uint16_t wIndex;
270
 
        uint16_t wLength;
271
 
} VUSBSETUP, *PVUSBSETUP;
272
 
#pragma pack()
273
 
 
274
 
 
275
 
static inline void vusbDevUnplugged(PVUSBDEV dev)
276
 
{
277
 
        dev->request_detach = 1;
278
 
}
279
 
 
280
 
int dev2fd (PUSBPROXYDEV pProxyDev);
281
 
 
282
 
 
283
 
typedef struct USBPROXYBACK
284
 
{
285
 
    /** Name of the backend. */
286
 
    const char *pszName;
287
 
 
288
 
    int  (* pfnOpen)(PUSBPROXYDEV pProxyDev, const char *pszAddress, void *pvBackend);
289
 
    void (* pfnClose)(PUSBPROXYDEV pProxyDev);
290
 
    int  (* pfnReset)(PUSBPROXYDEV pProxyDev);
291
 
    int  (* pfnSetConfig)(PUSBPROXYDEV pProxyDev, int iCfg);
292
 
    int  (* pfnClaimInterface)(PUSBPROXYDEV pProxyDev, int iIf);
293
 
    int  (* pfnReleaseInterface)(PUSBPROXYDEV pProxyDev, int iIf);
294
 
    int  (* pfnSetInterface)(PUSBPROXYDEV pProxyDev, int iIf, int setting);
295
 
    bool (* pfnClearHaltedEndpoint)(PUSBPROXYDEV  pDev, unsigned int iEp);
296
 
    int  (* pfnUrbQueue)(PVUSBURB urb);
297
 
    void (* pfnUrbCancel)(PVUSBURB pUrb);
298
 
    PVUSBURB (* pfnUrbReap)(PUSBPROXYDEV pProxyDev, unsigned cMillies);
299
 
    uint32_t uDummy;
300
 
} USBPROXYBACK;
301
 
 
302
 
typedef USBPROXYBACK *PUSBPROXYBACK;
303
 
 
304
 
extern const USBPROXYBACK g_USBProxyDeviceHost;
305
 
 
306
 
static inline int op_usbproxy_back_open(struct usb_proxy *p, const char *pszAddress)
307
 
{
308
 
     return g_USBProxyDeviceHost.pfnOpen (p, pszAddress, NULL);
309
 
}
310
 
 
311
 
static inline void op_usbproxy_back_close(PUSBPROXYDEV pDev)
312
 
{
313
 
     return g_USBProxyDeviceHost.pfnClose (pDev);
314
 
}
315
 
 
316
 
static inline int op_usbproxy_back_reset(PUSBPROXYDEV pDev)
317
 
{
318
 
    return g_USBProxyDeviceHost.pfnReset (pDev);
319
 
}
320
 
 
321
 
static inline int op_usbproxy_back_set_config(PUSBPROXYDEV pDev, int cfg)
322
 
{
323
 
    return g_USBProxyDeviceHost.pfnSetConfig (pDev, cfg);
324
 
}
325
 
 
326
 
static inline int op_usbproxy_back_claim_interface(PUSBPROXYDEV pDev, int ifnum)
327
 
{
328
 
    return g_USBProxyDeviceHost.pfnClaimInterface (pDev, ifnum);
329
 
}
330
 
 
331
 
static inline int op_usbproxy_back_release_interface(PUSBPROXYDEV pDev, int ifnum)
332
 
{
333
 
    return g_USBProxyDeviceHost.pfnReleaseInterface (pDev, ifnum);
334
 
}
335
 
 
336
 
static inline int op_usbproxy_back_interface_setting(PUSBPROXYDEV pDev, int ifnum, int setting)
337
 
{
338
 
    return g_USBProxyDeviceHost.pfnSetInterface (pDev, ifnum, setting);
339
 
}
340
 
 
341
 
static inline int op_usbproxy_back_queue_urb(PVUSBURB pUrb)
342
 
{
343
 
    return g_USBProxyDeviceHost.pfnUrbQueue(pUrb);
344
 
}
345
 
 
346
 
static inline PVUSBURB op_usbproxy_back_reap_urb(PUSBPROXYDEV pDev, unsigned cMillies)
347
 
{
348
 
    return g_USBProxyDeviceHost.pfnUrbReap (pDev, cMillies);
349
 
}
350
 
 
351
 
static inline bool op_usbproxy_back_clear_halted_ep(PUSBPROXYDEV pDev, unsigned EndPoint)
352
 
{
353
 
    return g_USBProxyDeviceHost.pfnClearHaltedEndpoint (pDev, EndPoint);
354
 
}
355
 
 
356
 
static inline void op_usbproxy_back_cancel_urb(PVUSBURB pUrb)
357
 
{
358
 
    return g_USBProxyDeviceHost.pfnUrbCancel (pUrb);
359
 
}
360
 
 
361
30
#endif /* __VRDPUSB__H  */