summaryrefslogtreecommitdiffstats
path: root/qemu/roms/ipxe/src/include/ipxe/pccrr.h
blob: 1ea86c40d1601143c5a8549f6c886339cf28478a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
#ifndef _IPXE_PCCRR_H
#define _IPXE_PCCRR_H

/** @file
 *
 * Peer Content Caching and Retrieval: Retrieval Protocol [MS-PCCRR]
 *
 * All fields are in network byte order.
 *
 */

FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );

#include <stdint.h>
#include <ipxe/uaccess.h>

/** Magic retrieval URI path */
#define PEERDIST_MAGIC_PATH "/116B50EB-ECE2-41ac-8429-9F9E963361B7/"

/** Retrieval protocol version */
union peerdist_msg_version {
	/** Raw version number */
	uint32_t raw;
	/** Major:minor version number */
	struct {
		/** Minor version number */
		uint16_t minor;
		/** Major version number */
		uint16_t major;
	} __attribute__ (( packed ));
} __attribute__ (( packed ));

/** Retrieval protocol version 1.0 */
#define PEERDIST_MSG_VERSION_1_0 0x00000001UL

/** Retrieval protocol version 2.0 */
#define PEERDIST_MSG_VERSION_2_0 0x00000002UL

/** Retrieval protocol supported versions */
struct peerdist_msg_versions {
	/** Minimum supported protocol version */
	union peerdist_msg_version min;
	/** Maximum supported protocol version */
	union peerdist_msg_version max;
} __attribute__ (( packed ));

/** Retrieval protocol block range */
struct peerdist_msg_range {
	/** First block in range */
	uint32_t first;
	/** Number of blocks in range */
	uint32_t count;
} __attribute__ (( packed ));

/** Retrieval protocol segment ID header */
struct peerdist_msg_segment {
	/** Digest size (i.e. length of segment ID) */
	uint32_t digestsize;
	/* Followed by a single variable-length ID and padding:
	 *
	 * uint8_t id[digestsize];
	 * uint8_t pad[ (-digestsize) & 0x3 ];
	 */
} __attribute__ (( packed ));

/** Retrieval protocol segment ID
 *
 * @v digestsize	Digest size
 */
#define peerdist_msg_segment_t( digestsize )				\
	struct {							\
		struct peerdist_msg_segment segment;			\
		uint8_t id[digestsize];					\
		uint8_t pad[ ( -(digestsize) ) & 0x3 ];			\
	} __attribute__ (( packed ))

/** Retrieval protocol block range list header */
struct peerdist_msg_ranges {
	/** Number of ranges */
	uint32_t count;
	/* Followed by an array of block ranges:
	 *
	 * struct peerdist_msg_range range[count];
	 */
} __attribute__ (( packed ));

/** Retrieval protocol block range list
 *
 * @v count		Number of ranges
 */
#define peerdist_msg_ranges_t( count )					\
	struct {							\
		struct peerdist_msg_ranges ranges;			\
		struct peerdist_msg_range range[count];			\
	} __attribute__ (( packed ))

/** Retrieval protocol data block header */
struct peerdist_msg_block {
	/** Length of data block */
	uint32_t len;
	/* Followed by the (encrypted) data block:
	 *
	 * uint8_t data[len];
	 */
} __attribute__ (( packed ));

/** Retrieval protocol data block */
#define peerdist_msg_block_t( len )					\
	struct {							\
		struct peerdist_msg_block block;			\
		uint8_t data[len];					\
	} __attribute__ (( packed ))

/** Retrieval protocol initialisation vector header */
struct peerdist_msg_iv {
	/** Cipher block size */
	uint32_t blksize;
	/* Followed by the initialisation vector:
	 *
	 * uint8_t data[blksize];
	 */
} __attribute__ (( packed ));

/** Retrieval protocol initialisation vector */
#define peerdist_msg_iv_t( blksize )					\
	struct {							\
		struct peerdist_msg_iv iv;				\
		uint8_t data[blksize];					\
	} __attribute__ (( packed ))

/** Retrieval protocol useless VRF data header */
struct peerdist_msg_useless_vrf {
	/** Length of useless VRF data */
	uint32_t len;
	/* Followed by a variable-length useless VRF data block and
	 * padding:
	 *
	 * uint8_t data[len];
	 * uint8_t pad[ (-len) & 0x3 ];
	 */
} __attribute__ (( packed ));

/** Retrieval protocol useless VRF data */
#define peerdist_msg_useless_vrf_t( vrf_len )				\
	struct {							\
		struct peerdist_msg_useless_vrf vrf;			\
		uint8_t data[vrf_len];					\
		uint8_t pad[ ( -(vrf_len) ) & 0x3 ];			\
	} __attribute__ (( packed ))

/** Retrieval protocol message header */
struct peerdist_msg_header {
	/** Protocol version
	 *
	 * This is the protocol version in which the message type was
	 * first defined.
	 */
	union peerdist_msg_version version;
	/** Message type */
	uint32_t type;
	/** Message size (including this header) */
	uint32_t len;
	/** Cryptographic algorithm ID */
	uint32_t algorithm;
} __attribute__ (( packed ));

/** Retrieval protocol cryptographic algorithm IDs */
enum peerdist_msg_algorithm {
	/** No encryption */
	PEERDIST_MSG_PLAINTEXT = 0x00000000UL,
	/** AES-128 in CBC mode */
	PEERDIST_MSG_AES_128_CBC = 0x00000001UL,
	/** AES-192 in CBC mode */
	PEERDIST_MSG_AES_192_CBC = 0x00000002UL,
	/** AES-256 in CBC mode */
	PEERDIST_MSG_AES_256_CBC = 0x00000003UL,
};

/** Retrieval protocol transport response header */
struct peerdist_msg_transport_header {
	/** Length (excluding this header)
	 *
	 * This seems to be identical in both purpose and value to the
	 * length found within the message header, and therefore
	 * serves no useful purpose.
	 */
	uint32_t len;
} __attribute__ (( packed ));

/** Retrieval protocol negotiation request */
struct peerdist_msg_nego_req {
	/** Message header */
	struct peerdist_msg_header hdr;
	/** Supported versions */
	struct peerdist_msg_versions versions;
} __attribute__ (( packed ));

/** Retrieval protocol negotiation request version */
#define PEERDIST_MSG_NEGO_REQ_VERSION PEERDIST_MSG_VERSION_1_0

/** Retrieval protocol negotiation request type */
#define PEERDIST_MSG_NEGO_REQ_TYPE 0x00000000UL

/** Retrieval protocol negotiation response */
struct peerdist_msg_nego_resp {
	/** Message header */
	struct peerdist_msg_header hdr;
	/** Supported versions */
	struct peerdist_msg_versions versions;
} __attribute__ (( packed ));

/** Retrieval protocol negotiation response version */
#define PEERDIST_MSG_NEGO_RESP_VERSION PEERDIST_MSG_VERSION_1_0

/** Retrieval protocol negotiation response type */
#define PEERDIST_MSG_NEGO_RESP_TYPE 0x00000001UL

/** Retrieval protocol block list request header */
struct peerdist_msg_getblklist {
	/** Message header */
	struct peerdist_msg_header hdr;
	/* Followed by a segment ID and a block range list:
	 *
	 * peerdist_msg_segment_t(digestsize) segment;
	 * peerdist_msg_ranges_t(count) ranges;
	 */
} __attribute__ (( packed ));

/** Retrieval protocol block list request
 *
 * @v digestsize	Digest size
 * @v count		Block range count
 */
#define peerdist_msg_getblklist_t( digestsize, count )			\
	struct {							\
		struct peerdist_msg_getblklist getblklist;		\
		peerdist_msg_segment_t ( digestsize ) segment;		\
		peerdist_msg_ranges_t ( count ) ranges;			\
	} __attribute__ (( packed ))

/** Retrieval protocol block list request version */
#define PEERDIST_MSG_GETBLKLIST_VERSION PEERDIST_MSG_VERSION_1_0

/** Retrieval protocol block list request type */
#define PEERDIST_MSG_GETBLKLIST_TYPE 0x00000002UL

/** Retrieval protocol block fetch request header */
struct peerdist_msg_getblks {
	/** Message header */
	struct peerdist_msg_header hdr;
	/* Followed by a segment ID, a block range list, and a useless
	 * VRF block:
	 *
	 * peerdist_msg_segment_t(digestsize) segment;
	 * peerdist_msg_ranges_t(count) ranges;
	 * peerdist_msg_vrf_t(vrf_len) vrf;
	 */
} __attribute__ (( packed ));

/** Retrieval protocol block fetch request
 *
 * @v digestsize	Digest size
 * @v count		Block range count
 * @v vrf_len		Length of uselessness
 */
#define peerdist_msg_getblks_t( digestsize, count, vrf_len )		\
	struct {							\
		struct peerdist_msg_getblks getblks;			\
		peerdist_msg_segment_t ( digestsize ) segment;		\
		peerdist_msg_ranges_t ( count ) ranges;			\
		peerdist_msg_useless_vrf_t ( vrf_len );			\
	} __attribute__ (( packed ))

/** Retrieval protocol block fetch request version */
#define PEERDIST_MSG_GETBLKS_VERSION PEERDIST_MSG_VERSION_1_0

/** Retrieval protocol block fetch request type */
#define PEERDIST_MSG_GETBLKS_TYPE 0x00000003UL

/** Retrieval protocol block list response header */
struct peerdist_msg_blklist {
	/** Message header */
	struct peerdist_msg_header hdr;
	/* Followed by a segment ID, a block range list, and a next
	 * block index:
	 *
	 * peerdist_msg_segment_t(digestsize) segment;
	 * peerdist_msg_ranges_t(count) ranges;
	 * uint32_t next;
	 */
} __attribute__ (( packed ));

/** Retrieval protocol block list response
 *
 * @v digestsize	Digest size
 * @v count		Block range count
 */
#define peerdist_msg_blklist_t( digestsize, count )			\
	struct {							\
		struct peerdist_msg_blklist blklist;			\
		peerdist_msg_segment_t ( digestsize ) segment;		\
		peerdist_msg_ranges_t ( count ) ranges;			\
		uint32_t next;						\
	} __attribute__ (( packed ))

/** Retrieval protocol block list response version */
#define PEERDIST_MSG_BLKLIST_VERSION PEERDIST_MSG_VERSION_1_0

/** Retrieval protocol block list response type */
#define PEERDIST_MSG_BLKLIST_TYPE 0x00000004UL

/** Retrieval protocol block fetch response header */
struct peerdist_msg_blk {
	/** Message header */
	struct peerdist_msg_header hdr;
	/* Followed by a segment ID, a block index, a next block
	 * index, a data block, a useless VRF block, and an
	 * initialisation vector:
	 *
	 * peerdist_msg_segment_t(digestsize) segment;
	 * uint32_t index;
	 * uint32_t next;
	 * peerdist_msg_block_t(len) data;
	 * peerdist_msg_useless_vrf_t(vrf_len) vrf;
	 * peerdist_msg_iv_t(blksize) iv;
	 */
} __attribute__ (( packed ));

/** Retrieval protocol block fetch response
 *
 * @v digestsize	Digest size
 * @v len		Data block length
 * @v vrf_len		Length of uselessness
 * @v blksize		Cipher block size
 */
#define peerdist_msg_blk_t( digestsize, len, vrf_len, blksize )		\
	struct {							\
		struct peerdist_msg_blk blk;				\
		peerdist_msg_segment_t ( digestsize ) segment;		\
		uint32_t index;						\
		uint32_t next;						\
		peerdist_msg_block_t ( len ) block;			\
		peerdist_msg_useless_vrf_t ( vrf_len ) vrf;		\
		peerdist_msg_iv_t ( blksize ) iv;			\
	} __attribute__ (( packed ))

/** Retrieval protocol block fetch response version */
#define PEERDIST_MSG_BLK_VERSION PEERDIST_MSG_VERSION_1_0

/** Retrieval protocol block fetch response type */
#define PEERDIST_MSG_BLK_TYPE 0x00000005UL

/**
 * Parse retrieval protocol block fetch response
 *
 * @v raw		Raw data
 * @v raw_len		Length of raw data
 * @v digestsize	Digest size
 * @v blksize		Cipher block size
 * @v blk		Structure to fill in
 * @ret rc		Return status code
 */
#define peerdist_msg_blk( raw, raw_len, digestsize, blksize, blk ) ( {	\
	assert ( sizeof ( (blk)->segment.id ) == (digestsize) );	\
	assert ( sizeof ( (blk)->block.data ) == 0 );			\
	assert ( sizeof ( (blk)->vrf.data ) == 0 );			\
	assert ( sizeof ( (blk)->iv.data ) == blksize );		\
	peerdist_msg_blk_untyped ( (raw), (raw_len), (digestsize),	\
				   (blksize), blk );			\
	} )

extern int peerdist_msg_blk_untyped ( userptr_t raw, size_t raw_len,
				      size_t digestsize, size_t blksize,
				      void *out );

#endif /* _IPXE_PCCRR_H */