VirtualBox

source: vbox/trunk/src/VBox/ValidationKit/utils/usb/UsbTestServiceProtocol.h@ 60488

Last change on this file since 60488 was 60488, checked in by vboxsync, 9 years ago

ValidationKit/usb: Fixes

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 11.3 KB
Line 
1/* $Id: UsbTestServiceProtocol.h 60488 2016-04-14 10:33:11Z vboxsync $ */
2/** @file
3 * UsbTestServ - Remote USB test configuration and execution server, Protocol Header.
4 */
5
6/*
7 * Copyright (C) 2016 Oracle Corporation
8 *
9 * This file is part of VirtualBox Open Source Edition (OSE), as
10 * available from http://www.215389.xyz. This file is free software;
11 * you can redistribute it and/or modify it under the terms of the GNU
12 * General Public License (GPL) as published by the Free Software
13 * Foundation, in version 2 as it comes in the "COPYING" file of the
14 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
15 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
16 *
17 * The contents of this file may alternatively be used under the terms
18 * of the Common Development and Distribution License Version 1.0
19 * (CDDL) only, as it comes in the "COPYING.CDDL" file of the
20 * VirtualBox OSE distribution, in which case the provisions of the
21 * CDDL are applicable instead of those of the GPL.
22 *
23 * You may elect to license modified versions of this file under the
24 * terms and conditions of either the GPL or the CDDL or both.
25 */
26
27#ifndef ___UsbTestServiceProtocol_h___
28#define ___UsbTestServiceProtocol_h___
29
30#include <iprt/cdefs.h>
31
32RT_C_DECLS_BEGIN
33
34/**
35 * Common Packet header (for requests and replies).
36 */
37typedef struct UTSPKTHDR
38{
39 /** The unpadded packet length. This include this header. */
40 uint32_t cb;
41 /** The CRC-32 for the packet starting from the opcode field. 0 if the packet
42 * hasn't been CRCed. */
43 uint32_t uCrc32;
44 /** Packet opcode, an unterminated ASCII string. */
45 uint8_t achOpcode[8];
46} UTSPKTHDR;
47AssertCompileSize(UTSPKTHDR, 16);
48/** Pointer to a packet header. */
49typedef UTSPKTHDR *PUTSPKTHDR;
50/** Pointer to a packet header. */
51typedef UTSPKTHDR const *PCUTSPKTHDR;
52/** Pointer to a packet header pointer. */
53typedef PUTSPKTHDR *PPUTSPKTHDR;
54
55/** Packet alignment. */
56#define UTSPKT_ALIGNMENT 16
57/** Max packet size. */
58#define UTSPKT_MAX_SIZE _256K
59
60/**
61 * Status packet.
62 */
63typedef struct UTSPKTSTS
64{
65 /** Embedded common packet header. */
66 UTSPKTHDR Hdr;
67 /** The IPRT status code of the request. */
68 int32_t rcReq;
69 /** Size of the optional status message following this structure -
70 * only for errors. */
71 uint32_t cchStsMsg;
72 /** Padding - reserved. */
73 uint8_t au8Padding[8];
74} UTSPKTSTS;
75AssertCompileSizeAlignment(UTSPKTSTS, UTSPKT_ALIGNMENT);
76/** Pointer to a status packet header. */
77typedef UTSPKTSTS *PUTSPKTSTS;
78
79#define UTSPKT_OPCODE_HOWDY "HOWDY "
80
81/** 32bit protocol version consisting of a 16bit major and 16bit minor part. */
82#define UTS_PROTOCOL_VS (UTS_PROTOCOL_VS_MAJOR | UTS_PROTOCOL_VS_MINOR)
83/** The major version part of the protocol version. */
84#define UTS_PROTOCOL_VS_MAJOR (1 << 16)
85/** The minor version part of the protocol version. */
86#define UTS_PROTOCOL_VS_MINOR (0)
87
88/**
89 * The HOWDY request structure.
90 */
91typedef struct UTSPKTREQHOWDY
92{
93 /** Embedded packet header. */
94 UTSPKTHDR Hdr;
95 /** Version of the protocol the client wants to use. */
96 uint32_t uVersion;
97 /** Mask of USB device connections the client wants to use. */
98 uint32_t fUsbConn;
99 /** The number of characters for the hostname. */
100 uint32_t cchHostname;
101 /** The client host name as terminated ASCII string. */
102 char achHostname[68];
103} UTSPKTREQHOWDY;
104AssertCompileSizeAlignment(UTSPKTREQHOWDY, UTSPKT_ALIGNMENT);
105/** Pointer to a HOWDY request structure. */
106typedef UTSPKTREQHOWDY *PUTSPKTREQHOWDY;
107
108/**
109 * The HOWDY reply structure.
110 */
111typedef struct UTSPKTREPHOWDY
112{
113 /** Status packet. */
114 UTSPKTSTS Sts;
115 /** Version to use for the established connection. */
116 uint32_t uVersion;
117 /** Mask of supported USB device connections for this connection. */
118 uint32_t fUsbConn;
119 /** Port number the USB/IP server is listening on if
120 * the client requested USB/IP support and the server can
121 * deliver it. */
122 uint32_t uUsbIpPort;
123 /** Maximum number of devices supported over USB/IP
124 * at the same time. */
125 uint32_t cUsbIpDevices;
126 /** Maximum number of physical devices supported for this client
127 * if a physical connection is present. */
128 uint32_t cPhysicalDevices;
129 /** Padding - reserved. */
130 uint8_t au8Padding[12];
131} UTSPKTREPHOWDY;
132AssertCompileSizeAlignment(UTSPKTREPHOWDY, UTSPKT_ALIGNMENT);
133/** Pointer to a HOWDY reply structure. */
134typedef UTSPKTREPHOWDY *PUTSPKTREPHOWDY;
135
136/** Connections over USB/IP are supported. */
137#define UTSPKT_HOWDY_CONN_F_USBIP RT_BIT_32(0)
138/** The server has a physical connection available to the client
139 * which can be used for testing. */
140#define UTSPKT_HOWDY_CONN_F_PHYSICAL RT_BIT_32(1)
141
142
143#define UTSPKT_OPCODE_BYE "BYE "
144
145/* No additional structures for BYE. */
146
147#define UTSPKT_OPCODE_GADGET_CREATE "GDGTCRT "
148
149/**
150 * The GADGET CREATE request structure.
151 */
152typedef struct UTSPKTREQGDGTCTOR
153{
154 /** Embedded packet header. */
155 UTSPKTHDR Hdr;
156 /** Gadget type. */
157 uint32_t u32GdgtType;
158 /** Access methods. */
159 uint32_t u32GdgtAccess;
160 /** Number of config items - following this structure. */
161 uint32_t u32CfgItems;
162 /** Reserved. */
163 uint32_t u32Rsvd0;
164} UTSPKTREQGDGTCTOR;
165AssertCompileSizeAlignment(UTSPKTREQGDGTCTOR, UTSPKT_ALIGNMENT);
166/** Pointer to a GADGET CREATE structure. */
167typedef UTSPKTREQGDGTCTOR *PUTSPKTREQGDGTCTOR;
168
169/** Gadget type - Test device. */
170#define UTSPKT_GDGT_CREATE_TYPE_TEST UINT32_C(0x1)
171
172/** Gadget acess method - USB/IP. */
173#define UTSPKT_GDGT_CREATE_ACCESS_USBIP UINT32_C(0x1)
174
175/**
176 * Configuration item.
177 */
178typedef struct UTSPKTREQGDGTCTORCFGITEM
179{
180 /** Size of the key incuding termination in bytes. */
181 uint32_t u32KeySize;
182 /** Item type. */
183 uint32_t u32Type;
184 /** Size of the value string including termination in bytes. */
185 uint32_t u32ValSize;
186 /** Reserved. */
187 uint32_t u32Rsvd0;
188} UTSPKTREQGDGTCTORCFGITEM;
189AssertCompileSizeAlignment(UTSPKTREQGDGTCTORCFGITEM, UTSPKT_ALIGNMENT);
190/** Pointer to a configuration item. */
191typedef UTSPKTREQGDGTCTORCFGITEM *PUTSPKTREQGDGTCTORCFGITEM;
192
193/** Boolean configuration item type. */
194#define UTSPKT_GDGT_CFG_ITEM_TYPE_BOOLEAN UINT32_C(1)
195/** String configuration item type. */
196#define UTSPKT_GDGT_CFG_ITEM_TYPE_STRING UINT32_C(2)
197/** Unsigned 8-bit integer configuration item type. */
198#define UTSPKT_GDGT_CFG_ITEM_TYPE_UINT8 UINT32_C(3)
199/** Unsigned 16-bit integer configuration item type. */
200#define UTSPKT_GDGT_CFG_ITEM_TYPE_UINT16 UINT32_C(4)
201/** Unsigned 32-bit integer configuration item type. */
202#define UTSPKT_GDGT_CFG_ITEM_TYPE_UINT32 UINT32_C(5)
203/** Unsigned 64-bit integer configuration item type. */
204#define UTSPKT_GDGT_CFG_ITEM_TYPE_UINT64 UINT32_C(6)
205/** Signed 8-bit integer configuration item type. */
206#define UTSPKT_GDGT_CFG_ITEM_TYPE_INT8 UINT32_C(7)
207/** Signed 16-bit integer configuration item type. */
208#define UTSPKT_GDGT_CFG_ITEM_TYPE_INT16 UINT32_C(8)
209/** Signed 32-bit integer configuration item type. */
210#define UTSPKT_GDGT_CFG_ITEM_TYPE_INT32 UINT32_C(9)
211/** Signed 64-bit integer configuration item type. */
212#define UTSPKT_GDGT_CFG_ITEM_TYPE_INT64 UINT32_C(10)
213
214/**
215 * The GADGET CREATE reply structure.
216 */
217typedef struct UTSPKTREPGDGTCTOR
218{
219 /** Status packet. */
220 UTSPKTSTS Sts;
221 /** The gadget ID on success. */
222 uint32_t idGadget;
223 /** Padding - reserved. */
224 uint8_t au8Padding[12];
225} UTSPKTREPGDGTCTOR;
226AssertCompileSizeAlignment(UTSPKTREPGDGTCTOR, UTSPKT_ALIGNMENT);
227/** Pointer to a GADGET CREATE structure. */
228typedef UTSPKTREPGDGTCTOR *PUTSPKTREPGDGTCTOR;
229
230
231#define UTSPKT_OPCODE_GADGET_DESTROY "GDGTDTOR"
232
233/**
234 * The GADGET DESTROY request structure.
235 */
236typedef struct UTSPKTREQGDGTDTOR
237{
238 /** Embedded packet header. */
239 UTSPKTHDR Hdr;
240 /** Gadget ID as returned from the GADGET CREATE request on success. */
241 uint32_t idGadget;
242 /** Padding - reserved. */
243 uint8_t au8Padding[12];
244} UTSPKTREQGDGTDTOR;
245AssertCompileSizeAlignment(UTSPKTREQGDGTDTOR, UTSPKT_ALIGNMENT);
246/** Pointer to a GADGET DESTROY structure. */
247typedef UTSPKTREQGDGTDTOR *PUTSPKTREQGDGTDTOR;
248
249/* No additional structure for the reply (just standard STATUS packet). */
250
251#define UTSPKT_OPCODE_GADGET_CONNECT "GDGTCNCT"
252
253/**
254 * The GADGET CONNECT request structure.
255 */
256typedef struct UTSPKTREQGDGTCNCT
257{
258 /** Embedded packet header. */
259 UTSPKTHDR Hdr;
260 /** Gadget ID as returned from the GADGET CREATE request on success. */
261 uint32_t idGadget;
262 /** Padding - reserved. */
263 uint8_t au8Padding[12];
264} UTSPKTREQGDGTCNCT;
265AssertCompileSizeAlignment(UTSPKTREQGDGTCNCT, UTSPKT_ALIGNMENT);
266/** Pointer to a GADGET CONNECT request structure. */
267typedef UTSPKTREQGDGTCNCT *PUTSPKTREQGDGTCNCT;
268
269/* No additional structure for the reply (just standard STATUS packet). */
270
271#define UTSPKT_OPCODE_GADGET_DISCONNECT "GDGTDCNT"
272
273/**
274 * The GADGET DISCONNECT request structure.
275 */
276typedef struct UTSPKTREQGDGTDCNT
277{
278 /** Embedded packet header. */
279 UTSPKTHDR Hdr;
280 /** Gadget ID as returned from the GADGET CREATE request on success. */
281 uint32_t idGadget;
282 /** Padding - reserved. */
283 uint8_t au8Padding[12];
284} UTSPKTREQGDGTDCNT;
285AssertCompileSizeAlignment(UTSPKTREQGDGTDCNT, UTSPKT_ALIGNMENT);
286/** Pointer to a GADGET CONNECT request structure. */
287typedef UTSPKTREQGDGTDCNT *PUTSPKTREQGDGTDCNT;
288
289/* No additional structure for the reply (just standard STATUS packet). */
290
291/**
292 * Checks if the two opcodes match.
293 *
294 * @returns true on match, false on mismatch.
295 * @param pPktHdr The packet header.
296 * @param pszOpcode2 The opcode we're comparing with. Does not have
297 * to be the whole 8 chars long.
298 */
299DECLINLINE(bool) utsIsSameOpcode(PCUTSPKTHDR pPktHdr, const char *pszOpcode2)
300{
301 if (pPktHdr->achOpcode[0] != pszOpcode2[0])
302 return false;
303 if (pPktHdr->achOpcode[1] != pszOpcode2[1])
304 return false;
305
306 unsigned i = 2;
307 while ( i < RT_SIZEOFMEMB(UTSPKTHDR, achOpcode)
308 && pszOpcode2[i] != '\0')
309 {
310 if (pPktHdr->achOpcode[i] != pszOpcode2[i])
311 break;
312 i++;
313 }
314
315 if ( i < RT_SIZEOFMEMB(UTSPKTHDR, achOpcode)
316 && pszOpcode2[i] == '\0')
317 {
318 while ( i < RT_SIZEOFMEMB(UTSPKTHDR, achOpcode)
319 && pPktHdr->achOpcode[i] == ' ')
320 i++;
321 }
322
323 return i == RT_SIZEOFMEMB(UTSPKTHDR, achOpcode);
324}
325
326/**
327 * Converts a UTS request packet from host to network byte ordering.
328 *
329 * @returns nothing.
330 * @param pPktHdr The packet to convert.
331 */
332DECLHIDDEN(void) utsProtocolReqH2N(PUTSPKTHDR pPktHdr);
333
334/**
335 * Converts a UTS request packet from network to host byte ordering.
336 *
337 * @returns nothing.
338 * @param pPktHdr The packet to convert.
339 */
340DECLHIDDEN(void) utsProtocolReqN2H(PUTSPKTHDR pPktHdr);
341
342/**
343 * Converts a UTS reply packet from host to network byte ordering.
344 *
345 * @returns nothing.
346 * @param pPktHdr The packet to convert.
347 */
348DECLHIDDEN(void) utsProtocolRepH2N(PUTSPKTHDR pPktHdr);
349
350/**
351 * Converts a UTS reply packet from network to host byte ordering.
352 *
353 * @returns nothing.
354 * @param pPktHdr The packet to convert.
355 */
356DECLHIDDEN(void) utsProtocolRepN2H(PUTSPKTHDR pPktHdr);
357
358RT_C_DECLS_END
359
360#endif
Note: See TracBrowser for help on using the repository browser.

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