VirtualBox

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

Last change on this file since 90488 was 82968, checked in by vboxsync, 5 years ago

Copyright year updates by scm.

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