1 | /* $Id: AudioTestServiceProtocol.h 89458 2021-06-02 09:04:06Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * AudioTestServiceProtocol - Audio test execution server, Protocol Header.
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2021 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 |
|
---|
18 | #ifndef VBOX_INCLUDED_SRC_Audio_AudioTestServiceProtocol_h
|
---|
19 | #define VBOX_INCLUDED_SRC_Audio_AudioTestServiceProtocol_h
|
---|
20 | #ifndef RT_WITHOUT_PRAGMA_ONCE
|
---|
21 | # pragma once
|
---|
22 | #endif
|
---|
23 |
|
---|
24 | #include <iprt/cdefs.h>
|
---|
25 | #include <iprt/list.h>
|
---|
26 |
|
---|
27 | #include <VBox/vmm/pdmaudioifs.h>
|
---|
28 |
|
---|
29 | #include "AudioTest.h"
|
---|
30 |
|
---|
31 | RT_C_DECLS_BEGIN
|
---|
32 |
|
---|
33 | /**
|
---|
34 | * Common Packet header (for requests and replies).
|
---|
35 | */
|
---|
36 | typedef struct ATSPKTHDR
|
---|
37 | {
|
---|
38 | /** The unpadded packet length. This include this header. */
|
---|
39 | uint32_t cb;
|
---|
40 | /** The CRC-32 for the packet starting from the opcode field. 0 if the packet
|
---|
41 | * hasn't been CRCed. */
|
---|
42 | uint32_t uCrc32;
|
---|
43 | /** Packet opcode, an unterminated ASCII string. */
|
---|
44 | uint8_t achOpcode[8];
|
---|
45 | } ATSPKTHDR;
|
---|
46 | AssertCompileSize(ATSPKTHDR, 16);
|
---|
47 | /** Pointer to a packet header. */
|
---|
48 | typedef ATSPKTHDR *PATSPKTHDR;
|
---|
49 | /** Pointer to a packet header. */
|
---|
50 | typedef ATSPKTHDR const *PCATSPKTHDR;
|
---|
51 | /** Pointer to a packet header pointer. */
|
---|
52 | typedef PATSPKTHDR *PPATSPKTHDR;
|
---|
53 |
|
---|
54 | /** Packet alignment. */
|
---|
55 | #define ATSPKT_ALIGNMENT 16
|
---|
56 | /** Max packet size. */
|
---|
57 | #define ATSPKT_MAX_SIZE _256K
|
---|
58 |
|
---|
59 | /**
|
---|
60 | * Status packet.
|
---|
61 | */
|
---|
62 | typedef struct ATSPKTSTS
|
---|
63 | {
|
---|
64 | /** Embedded common packet header. */
|
---|
65 | ATSPKTHDR Hdr;
|
---|
66 | /** The IPRT status code of the request. */
|
---|
67 | int32_t rcReq;
|
---|
68 | /** Size of the optional status message following this structure -
|
---|
69 | * only for errors. */
|
---|
70 | uint32_t cchStsMsg;
|
---|
71 | /** Padding - reserved. */
|
---|
72 | uint8_t au8Padding[8];
|
---|
73 | } ATSPKTSTS;
|
---|
74 | AssertCompileSizeAlignment(ATSPKTSTS, ATSPKT_ALIGNMENT);
|
---|
75 | /** Pointer to a status packet header. */
|
---|
76 | typedef ATSPKTSTS *PATSPKTSTS;
|
---|
77 |
|
---|
78 | #define ATSPKT_OPCODE_HOWDY "HOWDY "
|
---|
79 |
|
---|
80 | /** 32bit protocol version consisting of a 16bit major and 16bit minor part. */
|
---|
81 | #define ATS_PROTOCOL_VS (ATS_PROTOCOL_VS_MAJOR | ATS_PROTOCOL_VS_MINOR)
|
---|
82 | /** The major version part of the protocol version. */
|
---|
83 | #define ATS_PROTOCOL_VS_MAJOR (1 << 16)
|
---|
84 | /** The minor version part of the protocol version. */
|
---|
85 | #define ATS_PROTOCOL_VS_MINOR (0)
|
---|
86 |
|
---|
87 | /**
|
---|
88 | * The HOWDY request structure.
|
---|
89 | */
|
---|
90 | typedef struct ATSPKTREQHOWDY
|
---|
91 | {
|
---|
92 | /** Embedded packet header. */
|
---|
93 | ATSPKTHDR Hdr;
|
---|
94 | /** Version of the protocol the client wants to use. */
|
---|
95 | uint32_t uVersion;
|
---|
96 | /** Alignment. */
|
---|
97 | uint8_t au8Padding[12];
|
---|
98 | } ATSPKTREQHOWDY;
|
---|
99 | AssertCompileSizeAlignment(ATSPKTREQHOWDY, ATSPKT_ALIGNMENT);
|
---|
100 | /** Pointer to a HOWDY request structure. */
|
---|
101 | typedef ATSPKTREQHOWDY *PATSPKTREQHOWDY;
|
---|
102 |
|
---|
103 | /**
|
---|
104 | * The HOWDY reply structure.
|
---|
105 | */
|
---|
106 | typedef struct ATSPKTREPHOWDY
|
---|
107 | {
|
---|
108 | /** Status packet. */
|
---|
109 | ATSPKTSTS Sts;
|
---|
110 | /** Version to use for the established connection. */
|
---|
111 | uint32_t uVersion;
|
---|
112 | /** Padding - reserved. */
|
---|
113 | uint8_t au8Padding[12];
|
---|
114 | } ATSPKTREPHOWDY;
|
---|
115 | AssertCompileSizeAlignment(ATSPKTREPHOWDY, ATSPKT_ALIGNMENT);
|
---|
116 | /** Pointer to a HOWDY reply structure. */
|
---|
117 | typedef ATSPKTREPHOWDY *PATSPKTREPHOWDY;
|
---|
118 |
|
---|
119 | #define ATSPKT_OPCODE_BYE "BYE "
|
---|
120 |
|
---|
121 | /* No additional structures for BYE. */
|
---|
122 |
|
---|
123 | #define ATSPKT_OPCODE_TESTSET_BEGIN "TSET BEG"
|
---|
124 |
|
---|
125 | /**
|
---|
126 | * The TSET BEG request structure.
|
---|
127 | */
|
---|
128 | typedef struct ATSPKTREQTSETBEG
|
---|
129 | {
|
---|
130 | /** Embedded packet header. */
|
---|
131 | ATSPKTHDR Hdr;
|
---|
132 | /** Audio test set tag to use. */
|
---|
133 | char szTag[AUDIOTEST_TAG_MAX];
|
---|
134 | } ATSPKTREQTSETBEG;
|
---|
135 | AssertCompileSizeAlignment(ATSPKTREQTSETBEG, ATSPKT_ALIGNMENT);
|
---|
136 | /** Pointer to a TSET BEG reply structure. */
|
---|
137 | typedef ATSPKTREQTSETBEG *PATSPKTREQTSETBEG;
|
---|
138 |
|
---|
139 | #define ATSPKT_OPCODE_TESTSET_END "TSET END"
|
---|
140 |
|
---|
141 | /**
|
---|
142 | * The TSET END request structure.
|
---|
143 | */
|
---|
144 | typedef struct ATSPKTREQTSETEND
|
---|
145 | {
|
---|
146 | /** Embedded packet header. */
|
---|
147 | ATSPKTHDR Hdr;
|
---|
148 | /** Audio test set tag to use. */
|
---|
149 | char szTag[AUDIOTEST_TAG_MAX];
|
---|
150 | } ATSPKTREQTSETEND;
|
---|
151 | AssertCompileSizeAlignment(ATSPKTREQTSETEND, ATSPKT_ALIGNMENT);
|
---|
152 | /** Pointer to a TSET STA reply structure. */
|
---|
153 | typedef ATSPKTREQTSETEND *PATSPKTREQTSETEND;
|
---|
154 |
|
---|
155 | #define ATSPKT_OPCODE_TONE_PLAY "TN PLY "
|
---|
156 |
|
---|
157 | /**
|
---|
158 | * The TN PLY request structure.
|
---|
159 | */
|
---|
160 | typedef struct ATSPKTREQTONEPLAY
|
---|
161 | {
|
---|
162 | /** Embedded packet header. */
|
---|
163 | ATSPKTHDR Hdr;
|
---|
164 | /** Test tone parameters for playback. */
|
---|
165 | AUDIOTESTTONEPARMS ToneParms;
|
---|
166 | uint8_t aPadding[8];
|
---|
167 | } ATSPKTREQTONEPLAY;
|
---|
168 | AssertCompileSizeAlignment(ATSPKTREQTONEPLAY, ATSPKT_ALIGNMENT);
|
---|
169 | /** Pointer to a ATSPKTREQTONEPLAY structure. */
|
---|
170 | typedef ATSPKTREQTONEPLAY *PATSPKTREQTONEPLAY;
|
---|
171 |
|
---|
172 | #define ATSPKT_OPCODE_TONE_RECORD "TN REC "
|
---|
173 |
|
---|
174 | /**
|
---|
175 | * The TN REC request structure.
|
---|
176 | */
|
---|
177 | typedef struct ATSPKTREQTONEREC
|
---|
178 | {
|
---|
179 | /** Embedded packet header. */
|
---|
180 | ATSPKTHDR Hdr;
|
---|
181 | /** Test tone parameters for playback. */
|
---|
182 | AUDIOTESTTONEPARMS ToneParms;
|
---|
183 | uint8_t aPadding[8];
|
---|
184 | } ATSPKTREQTONEREC;
|
---|
185 | AssertCompileSizeAlignment(ATSPKTREQTONEREC, ATSPKT_ALIGNMENT);
|
---|
186 | /** Pointer to a ATSPKTREQTONEREC structure. */
|
---|
187 | typedef ATSPKTREQTONEREC *PATSPKTREQTONEREC;
|
---|
188 |
|
---|
189 | /* No additional structure for the reply (just standard STATUS packet). */
|
---|
190 |
|
---|
191 | /**
|
---|
192 | * Checks if the two opcodes match.
|
---|
193 | *
|
---|
194 | * @returns true on match, false on mismatch.
|
---|
195 | * @param pPktHdr The packet header.
|
---|
196 | * @param pszOpcode2 The opcode we're comparing with. Does not have
|
---|
197 | * to be the whole 8 chars long.
|
---|
198 | */
|
---|
199 | DECLINLINE(bool) atsIsSameOpcode(PCATSPKTHDR pPktHdr, const char *pszOpcode2)
|
---|
200 | {
|
---|
201 | if (pPktHdr->achOpcode[0] != pszOpcode2[0])
|
---|
202 | return false;
|
---|
203 | if (pPktHdr->achOpcode[1] != pszOpcode2[1])
|
---|
204 | return false;
|
---|
205 |
|
---|
206 | unsigned i = 2;
|
---|
207 | while ( i < RT_SIZEOFMEMB(ATSPKTHDR, achOpcode)
|
---|
208 | && pszOpcode2[i] != '\0')
|
---|
209 | {
|
---|
210 | if (pPktHdr->achOpcode[i] != pszOpcode2[i])
|
---|
211 | break;
|
---|
212 | i++;
|
---|
213 | }
|
---|
214 |
|
---|
215 | if ( i < RT_SIZEOFMEMB(ATSPKTHDR, achOpcode)
|
---|
216 | && pszOpcode2[i] == '\0')
|
---|
217 | {
|
---|
218 | while ( i < RT_SIZEOFMEMB(ATSPKTHDR, achOpcode)
|
---|
219 | && pPktHdr->achOpcode[i] == ' ')
|
---|
220 | i++;
|
---|
221 | }
|
---|
222 |
|
---|
223 | return i == RT_SIZEOFMEMB(ATSPKTHDR, achOpcode);
|
---|
224 | }
|
---|
225 |
|
---|
226 | /**
|
---|
227 | * Converts a ATS request packet from host to network byte ordering.
|
---|
228 | *
|
---|
229 | * @returns nothing.
|
---|
230 | * @param pPktHdr The packet to convert.
|
---|
231 | */
|
---|
232 | DECLHIDDEN(void) atsProtocolReqH2N(PATSPKTHDR pPktHdr);
|
---|
233 |
|
---|
234 | /**
|
---|
235 | * Converts a ATS request packet from network to host byte ordering.
|
---|
236 | *
|
---|
237 | * @returns nothing.
|
---|
238 | * @param pPktHdr The packet to convert.
|
---|
239 | */
|
---|
240 | DECLHIDDEN(void) atsProtocolReqN2H(PATSPKTHDR pPktHdr);
|
---|
241 |
|
---|
242 | /**
|
---|
243 | * Converts a ATS reply packet from host to network byte ordering.
|
---|
244 | *
|
---|
245 | * @returns nothing.
|
---|
246 | * @param pPktHdr The packet to convert.
|
---|
247 | */
|
---|
248 | DECLHIDDEN(void) atsProtocolRepH2N(PATSPKTHDR pPktHdr);
|
---|
249 |
|
---|
250 | /**
|
---|
251 | * Converts a ATS reply packet from network to host byte ordering.
|
---|
252 | *
|
---|
253 | * @returns nothing.
|
---|
254 | * @param pPktHdr The packet to convert.
|
---|
255 | */
|
---|
256 | DECLHIDDEN(void) atsProtocolRepN2H(PATSPKTHDR pPktHdr);
|
---|
257 |
|
---|
258 | RT_C_DECLS_END
|
---|
259 |
|
---|
260 | #endif /* !VBOX_INCLUDED_SRC_Audio_AudioTestServiceProtocol_h */
|
---|