VirtualBox

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

Last change on this file since 105374 was 99775, checked in by vboxsync, 19 months ago

*: Mark functions as static if not used outside of a given compilation unit. Enables the compiler to optimize inlining, reduces the symbol tables, exposes unused functions and in some rare cases exposes mismtaches between function declarations and definitions, but most importantly reduces the number of parfait reports for the extern-function-no-forward-declaration category. This should not result in any functional changes, bugref:3409

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