VirtualBox

source: vbox/trunk/src/VBox/RDP/client/vrdp/vrdpusb.h@ 28800

Last change on this file since 28800 was 28800, checked in by vboxsync, 15 years ago

Automated rebranding to Oracle copyright/license strings via filemuncher

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 8.5 KB
Line 
1/** @file
2 *
3 */
4
5/*
6 * Copyright (C) 2006-2007 Oracle Corporation
7 *
8 * This file is part of VirtualBox Open Source Edition (OSE), as
9 * available from http://www.virtualbox.org. This file is free software;
10 * you can redistribute it and/or modify it under the terms of the GNU
11 * General Public License (GPL) as published by the Free Software
12 * Foundation, in version 2 as it comes in the "COPYING" file of the
13 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
14 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
15 */
16
17#ifndef __VRDPUSB__H
18#define __VRDPUSB__H
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
103static inline int RTCritSectInit (RTCRITSECT *pCritSect)
104{
105 return VINF_SUCCESS;
106}
107
108static inline int RTCritSectDelete (RTCRITSECT *pCritSect)
109{
110 return VINF_SUCCESS;
111}
112
113static inline int RTCritSectEnter (RTCRITSECT *pCritSect)
114{
115 return VINF_SUCCESS;
116}
117
118static inline int RTCritSectLeave (RTCRITSECT *pCritSect)
119{
120 return VINF_SUCCESS;
121}
122
123static 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
136static 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
148static 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
156static 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
168static inline int RTStrmClose (PRTSTREAM pStream)
169{
170 fclose (pStream);
171 return VINF_SUCCESS;
172}
173
174static 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
184static 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
197static 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
211static inline int RTFileClose (RTFILE file)
212{
213 close (file);
214 return VINF_SUCCESS;
215}
216
217static 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#define VRDP_USB_STATUS_SUCCESS 0
226#define VRDP_USB_STATUS_ACCESS_DENIED 1
227#define VRDP_USB_STATUS_DEVICE_REMOVED 2
228
229#define VRDP_USB_REAP_FLAG_CONTINUED (0)
230#define VRDP_USB_REAP_FLAG_LAST (1)
231
232#define VRDP_USB_CAPS_FLAG_ASYNC (0)
233#define VRDP_USB_CAPS_FLAG_POLL (1)
234
235#pragma pack(1)
236
237#include "vusb.h"
238
239typedef struct VUSBDEV
240{
241 char* pszName;
242 int request_detach;
243} VUSBDEV, *PVUSBDEV;
244
245typedef 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
265typedef 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
275static inline void vusbDevUnplugged(PVUSBDEV dev)
276{
277 dev->request_detach = 1;
278}
279
280int dev2fd (PUSBPROXYDEV pProxyDev);
281
282
283typedef 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
302typedef USBPROXYBACK *PUSBPROXYBACK;
303
304extern const USBPROXYBACK g_USBProxyDeviceHost;
305
306static inline int op_usbproxy_back_open(struct usb_proxy *p, const char *pszAddress)
307{
308 return g_USBProxyDeviceHost.pfnOpen (p, pszAddress, NULL);
309}
310
311static inline void op_usbproxy_back_close(PUSBPROXYDEV pDev)
312{
313 return g_USBProxyDeviceHost.pfnClose (pDev);
314}
315
316static inline int op_usbproxy_back_reset(PUSBPROXYDEV pDev)
317{
318 return g_USBProxyDeviceHost.pfnReset (pDev);
319}
320
321static inline int op_usbproxy_back_set_config(PUSBPROXYDEV pDev, int cfg)
322{
323 return g_USBProxyDeviceHost.pfnSetConfig (pDev, cfg);
324}
325
326static inline int op_usbproxy_back_claim_interface(PUSBPROXYDEV pDev, int ifnum)
327{
328 return g_USBProxyDeviceHost.pfnClaimInterface (pDev, ifnum);
329}
330
331static inline int op_usbproxy_back_release_interface(PUSBPROXYDEV pDev, int ifnum)
332{
333 return g_USBProxyDeviceHost.pfnReleaseInterface (pDev, ifnum);
334}
335
336static inline int op_usbproxy_back_interface_setting(PUSBPROXYDEV pDev, int ifnum, int setting)
337{
338 return g_USBProxyDeviceHost.pfnSetInterface (pDev, ifnum, setting);
339}
340
341static inline int op_usbproxy_back_queue_urb(PVUSBURB pUrb)
342{
343 return g_USBProxyDeviceHost.pfnUrbQueue(pUrb);
344}
345
346static inline PVUSBURB op_usbproxy_back_reap_urb(PUSBPROXYDEV pDev, unsigned cMillies)
347{
348 return g_USBProxyDeviceHost.pfnUrbReap (pDev, cMillies);
349}
350
351static inline bool op_usbproxy_back_clear_halted_ep(PUSBPROXYDEV pDev, unsigned EndPoint)
352{
353 return g_USBProxyDeviceHost.pfnClearHaltedEndpoint (pDev, EndPoint);
354}
355
356static inline void op_usbproxy_back_cancel_urb(PVUSBURB pUrb)
357{
358 return g_USBProxyDeviceHost.pfnUrbCancel (pUrb);
359}
360
361#endif /* __VRDPUSB__H */
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette