17
17
#ifndef __VRDPUSB__H
18
18
#define __VRDPUSB__H
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)
29
#error Unsupported host byte order!
31
#endif /* cpu_to_le16 */
33
//#include <asm/byteorder.h>
34
//#define cpu_to_le16 __cpu_to_le16
37
#define uint16_t uint16
38
#define uint32_t uint32
39
#define uint64_t long long
46
#define LogFlow(a) printf a
47
#define Log(a) printf a
48
#define Log2(a) printf a
50
#define LogFlow(a) do {} while (0)
51
#define Log(a) do {} while (0)
52
#define Log2(a) do {} while (0)
55
#define LogRel(a) printf a
57
/* Runtime wrappers. */
58
#define RTMemAlloc xmalloc
59
#define RTMemRealloc xrealloc
60
#define RTMemFree xfree
64
#define RT_LE2H_U16(_le16) (cpu_to_le16 (_le16))
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)
72
#define RT_SUCCESS(_rc) ((_rc) >= 0)
75
#define RTCRITSECT void *
77
#define Assert(_expr) do { \
80
Log(("Assertion failed: {%s}!!!\n", #_expr)); \
84
#define AssertMsgFailed(_msg) do { \
85
Log(("Assertion failed msg:!!!\n")); \
89
#define AssertReturn(_expr, _retval) do { \
92
Log(("Assertion failed: {%s}, returning 0x%08X!!!\n", #_expr, _retval)); \
97
#define AssertRC(_rc) Assert(RT_SUCCESS(_rc))
99
#define RT_FAILURE(_rc) (!RT_SUCCESS(_rc))
101
#define NOREF(_a) ((void)_a)
103
static inline int RTCritSectInit (RTCRITSECT *pCritSect)
108
static inline int RTCritSectDelete (RTCRITSECT *pCritSect)
113
static inline int RTCritSectEnter (RTCRITSECT *pCritSect)
118
static inline int RTCritSectLeave (RTCRITSECT *pCritSect)
123
static inline void *RTMemDupEx (const void *pvSrc, size_t cbSrc, size_t cbExtra)
125
void *p = RTMemAlloc (cbSrc + cbExtra);
129
memcpy (p, pvSrc, cbSrc);
130
memset ((char *)p + cbSrc, 0, cbExtra);
136
static inline void *RTMemAllocZ (size_t cb)
138
void *p = RTMemAlloc (cb);
148
static inline int RTStrToUInt32Ex (const char *pszValue, char **ppszNext, unsigned uBase, uint32_t *pu32)
150
*pu32 = strtoul (pszValue, ppszNext, uBase);
154
#define PRTSTREAM FILE *
156
static inline int RTStrmOpen (const char *pszFileName, const char *pszMode, PRTSTREAM *ppStream)
158
*ppStream = fopen (pszFileName, pszMode);
165
return VERR_NOT_SUPPORTED;
168
static inline int RTStrmClose (PRTSTREAM pStream)
174
static inline int RTStrmGetLine (PRTSTREAM pStream, char *pszString, size_t cchString)
176
if (fgets (pszString, cchString, pStream))
181
return VERR_NOT_SUPPORTED;
184
static inline char *RTStrStripL (const char *psz)
186
while (isspace (*psz))
191
#define NIL_RTFILE -1
193
#define RTFILE_O_READWRITE 0x00000003
194
#define RTFILE_O_OPEN 0x00000000
195
#define RTFILE_O_DENY_NONE 0x00000000
197
static inline int RTFileOpen (RTFILE *pFile, const char *pszFileName, unsigned fOpen)
199
Assert (fOpen == RTFILE_O_READWRITE);
201
*pFile = open (pszFileName, O_RDWR, 00600);
208
return VERR_ACCESS_DENIED;
211
static inline int RTFileClose (RTFILE file)
217
static inline uint64_t RTTimeMilliTS (void)
220
gettimeofday (&tv, NULL);
221
return (uint64_t)tv.tv_sec * (uint64_t)(1000)
222
+ (uint64_t)(tv.tv_usec / 1000);
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)
239
typedef struct VUSBDEV
243
} VUSBDEV, *PVUSBDEV;
245
typedef struct usb_proxy {
246
/* Note: the backend code assumes that the dev member is the first in the structure. */
248
/* 'union' because backend accesses the file handle as priv.File. */
254
struct usb_proxy *next;
255
struct usb_proxy *prev;
262
int cIgnoreSetConfigs;
265
typedef struct vusb_setup {
266
uint8_t bmRequestType;
271
} VUSBSETUP, *PVUSBSETUP;
275
static inline void vusbDevUnplugged(PVUSBDEV dev)
277
dev->request_detach = 1;
280
int dev2fd (PUSBPROXYDEV pProxyDev);
283
typedef struct USBPROXYBACK
285
/** Name of the backend. */
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);
302
typedef USBPROXYBACK *PUSBPROXYBACK;
304
extern const USBPROXYBACK g_USBProxyDeviceHost;
306
static inline int op_usbproxy_back_open(struct usb_proxy *p, const char *pszAddress)
308
return g_USBProxyDeviceHost.pfnOpen (p, pszAddress, NULL);
311
static inline void op_usbproxy_back_close(PUSBPROXYDEV pDev)
313
return g_USBProxyDeviceHost.pfnClose (pDev);
316
static inline int op_usbproxy_back_reset(PUSBPROXYDEV pDev)
318
return g_USBProxyDeviceHost.pfnReset (pDev);
321
static inline int op_usbproxy_back_set_config(PUSBPROXYDEV pDev, int cfg)
323
return g_USBProxyDeviceHost.pfnSetConfig (pDev, cfg);
326
static inline int op_usbproxy_back_claim_interface(PUSBPROXYDEV pDev, int ifnum)
328
return g_USBProxyDeviceHost.pfnClaimInterface (pDev, ifnum);
331
static inline int op_usbproxy_back_release_interface(PUSBPROXYDEV pDev, int ifnum)
333
return g_USBProxyDeviceHost.pfnReleaseInterface (pDev, ifnum);
336
static inline int op_usbproxy_back_interface_setting(PUSBPROXYDEV pDev, int ifnum, int setting)
338
return g_USBProxyDeviceHost.pfnSetInterface (pDev, ifnum, setting);
341
static inline int op_usbproxy_back_queue_urb(PVUSBURB pUrb)
343
return g_USBProxyDeviceHost.pfnUrbQueue(pUrb);
346
static inline PVUSBURB op_usbproxy_back_reap_urb(PUSBPROXYDEV pDev, unsigned cMillies)
348
return g_USBProxyDeviceHost.pfnUrbReap (pDev, cMillies);
351
static inline bool op_usbproxy_back_clear_halted_ep(PUSBPROXYDEV pDev, unsigned EndPoint)
353
return g_USBProxyDeviceHost.pfnClearHaltedEndpoint (pDev, EndPoint);
356
static inline void op_usbproxy_back_cancel_urb(PVUSBURB pUrb)
358
return g_USBProxyDeviceHost.pfnUrbCancel (pUrb);
361
30
#endif /* __VRDPUSB__H */