-
Notifications
You must be signed in to change notification settings - Fork 232
/
Copy pathHAPBLEPDU.c
690 lines (634 loc) · 22 KB
/
HAPBLEPDU.c
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
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
// Copyright (c) 2015-2019 The HomeKit ADK Contributors
//
// Licensed under the Apache License, Version 2.0 (the “License”);
// you may not use this file except in compliance with the License.
// See [CONTRIBUTORS.md] for the list of HomeKit ADK project authors.
#include "HAP+Internal.h"
static const HAPLogObject logObject = { .subsystem = kHAP_LogSubsystem, .category = "BLEPDU" };
/**
* Checks whether a value represents a valid PDU type.
*
* @param value Value to check.
*
* @return true If the value is valid.
* @return false Otherwise.
*/
HAP_RESULT_USE_CHECK
static bool HAPBLEPDUIsValidType(uint8_t value) {
switch (value) {
case kHAPBLEPDUType_Request:
case kHAPBLEPDUType_Response: {
return true;
}
default: {
return false;
}
}
}
/**
* Returns description of a PDU type.
*
* @param type Value of which to get description.
*
* @return Description of the type.
*/
HAP_RESULT_USE_CHECK
static const char* HAPBLEPDUTypeDescription(HAPBLEPDUType type) {
HAPPrecondition(HAPBLEPDUIsValidType(type));
switch (type) {
case kHAPBLEPDUType_Request: {
return "Request";
}
case kHAPBLEPDUType_Response: {
return "Response";
}
}
HAPFatalError();
}
/**
* Returns description of a HAP Opcode.
*
* @param opcode Value of which to get description.
*
* @return Description of the opcode.
*/
HAP_RESULT_USE_CHECK
static const char* HAPBLEPDUOpcodeDescription(HAPPDUOpcode opcode) {
HAPPrecondition(HAPPDUIsValidOpcode(opcode));
switch (opcode) {
case kHAPPDUOpcode_CharacteristicSignatureRead: {
return "HAP-Characteristic-Signature-Read";
}
case kHAPPDUOpcode_CharacteristicWrite: {
return "HAP-Characteristic-Write";
}
case kHAPPDUOpcode_CharacteristicRead: {
return "HAP-Characteristic-Read";
}
case kHAPPDUOpcode_CharacteristicTimedWrite: {
return "HAP-Characteristic-Timed-Write";
}
case kHAPPDUOpcode_CharacteristicExecuteWrite: {
return "HAP-Characteristic-Execute-Write";
}
case kHAPPDUOpcode_ServiceSignatureRead: {
return "HAP-Service-Signature-Read";
}
case kHAPPDUOpcode_CharacteristicConfiguration: {
return "HAP-Characteristic-Configuration";
}
case kHAPPDUOpcode_ProtocolConfiguration: {
return "HAP-Protocol-Configuration";
}
case kHAPPDUOpcode_Token: {
return "HAP-Token";
}
case kHAPPDUOpcode_TokenUpdate: {
return "HAP-Token-Update";
}
case kHAPPDUOpcode_Info: {
return "HAP-Info";
}
}
HAPFatalError();
}
HAP_RESULT_USE_CHECK
bool HAPBLEPDUOpcodeIsServiceOperation(HAPPDUOpcode opcode) {
HAPPrecondition(HAPPDUIsValidOpcode(opcode));
switch (opcode) {
case kHAPPDUOpcode_ServiceSignatureRead:
case kHAPPDUOpcode_ProtocolConfiguration: {
return true;
}
case kHAPPDUOpcode_CharacteristicSignatureRead:
case kHAPPDUOpcode_CharacteristicWrite:
case kHAPPDUOpcode_CharacteristicRead:
case kHAPPDUOpcode_CharacteristicTimedWrite:
case kHAPPDUOpcode_CharacteristicExecuteWrite:
case kHAPPDUOpcode_CharacteristicConfiguration:
case kHAPPDUOpcode_Token:
case kHAPPDUOpcode_TokenUpdate:
case kHAPPDUOpcode_Info: {
return false;
}
}
HAPFatalError();
}
/**
* Checks whether a value represents a valid HAP Status Code.
*
* @param value Value to check.
*
* @return true If the value is valid.
* @return false Otherwise.
*/
HAP_RESULT_USE_CHECK
static bool HAPBLEPDUIsValidStatus(uint8_t value) {
switch (value) {
case kHAPBLEPDUStatus_Success:
case kHAPBLEPDUStatus_UnsupportedPDU:
case kHAPBLEPDUStatus_MaxProcedures:
case kHAPBLEPDUStatus_InsufficientAuthorization:
case kHAPBLEPDUStatus_InvalidInstanceID:
case kHAPBLEPDUStatus_InsufficientAuthentication:
case kHAPBLEPDUStatus_InvalidRequest: {
return true;
}
default: {
return false;
}
}
}
/**
* Returns description of a HAP Status Code.
*
* @param status Value of which to get description.
*
* @return Description of the status.
*/
HAP_RESULT_USE_CHECK
static const char* HAPBLEPDUStatusDescription(HAPBLEPDUStatus status) {
HAPPrecondition(HAPBLEPDUIsValidStatus(status));
switch (status) {
case kHAPBLEPDUStatus_Success: {
return "Success";
}
case kHAPBLEPDUStatus_UnsupportedPDU: {
return "Unsupported-PDU";
}
case kHAPBLEPDUStatus_MaxProcedures: {
return "Max-Procedures";
}
case kHAPBLEPDUStatus_InsufficientAuthorization: {
return "Insufficient Authorization";
}
case kHAPBLEPDUStatus_InvalidInstanceID: {
return "Invalid Instance ID";
}
case kHAPBLEPDUStatus_InsufficientAuthentication: {
return "Insufficient Authentication";
}
case kHAPBLEPDUStatus_InvalidRequest: {
return "Invalid Request";
}
}
HAPFatalError();
}
/**
* Logs a HAP-BLE PDU.
*
* @param pdu PDU to log.
*/
static void LogPDU(const HAPBLEPDU* pdu) {
HAPPrecondition(pdu);
HAPBLEPDUType type = pdu->controlField.type;
HAPPrecondition(HAPBLEPDUIsValidType(type));
switch (pdu->controlField.fragmentationStatus) {
case kHAPBLEPDUFragmentationStatus_FirstFragment: {
switch (type) {
case kHAPBLEPDUType_Request: {
HAPPDUOpcode opcode = pdu->fixedParams.request.opcode;
HAPLogBufferDebug(
&logObject,
pdu->body.bytes,
pdu->body.numBytes,
"%s-%s (0x%02x):\n"
" TID: 0x%02x\n"
" IID: %u",
HAPPDUIsValidOpcode(opcode) ? HAPBLEPDUOpcodeDescription(opcode) : "Unknown",
HAPBLEPDUTypeDescription(type),
opcode,
pdu->fixedParams.request.tid,
pdu->fixedParams.request.iid);
} break;
case kHAPBLEPDUType_Response: {
HAPBLEPDUStatus status = pdu->fixedParams.response.status;
HAPLogBufferDebug(
&logObject,
pdu->body.bytes,
pdu->body.numBytes,
"%s:\n"
" TID: 0x%02x\n"
" Status: %s (0x%02x)",
HAPBLEPDUTypeDescription(type),
pdu->fixedParams.response.tid,
HAPBLEPDUIsValidStatus(status) ? HAPBLEPDUStatusDescription(status) : "Unknown",
pdu->fixedParams.response.status);
} break;
}
} break;
case kHAPBLEPDUFragmentationStatus_Continuation: {
HAPLogBufferDebug(
&logObject,
pdu->body.bytes,
pdu->body.numBytes,
"%s (Continuation):\n"
" TID: 0x%02x",
HAPBLEPDUTypeDescription(type),
pdu->fixedParams.response.tid);
} break;
}
}
/**
* Attempts to deserialize the Control Field into a PDU structure.
*
* @param[out] pdu PDU.
* @param controlField Serialized Control Field.
*
* @return kHAPError_None If successful.
* @return kHAPError_InvalidData If the controller sent a malformed request.
*/
HAP_RESULT_USE_CHECK
static HAPError DeserializeControlField(HAPBLEPDU* pdu, const uint8_t* controlField) {
HAPPrecondition(pdu);
HAPPrecondition(controlField);
// Check that reserved bits are 0.
if (controlField[0] & (1 << 6 | 1 << 5 | 1 << 4)) {
HAPLog(&logObject, "Invalid reserved bits in Control Field 0x%02x.", controlField[0]);
return kHAPError_InvalidData;
}
// Fragmentation status.
switch (controlField[0] & 1 << 7) {
case 0 << 7: {
pdu->controlField.fragmentationStatus = kHAPBLEPDUFragmentationStatus_FirstFragment;
} break;
case 1 << 7: {
pdu->controlField.fragmentationStatus = kHAPBLEPDUFragmentationStatus_Continuation;
} break;
default: {
HAPLog(&logObject, "Invalid fragmentation status in Control Field 0x%02x.", controlField[0]);
return kHAPError_InvalidData;
}
}
// PDU Type.
switch (controlField[0] & (1 << 3 | 1 << 2 | 1 << 1)) {
case 0 << 3 | 0 << 2 | 0 << 1: {
pdu->controlField.type = kHAPBLEPDUType_Request;
} break;
case 0 << 3 | 0 << 2 | 1 << 1: {
pdu->controlField.type = kHAPBLEPDUType_Response;
} break;
default: {
HAPLog(&logObject, "Invalid PDU Type in Control Field 0x%02x.", controlField[0]);
return kHAPError_InvalidData;
}
}
// Length.
switch (controlField[0] & 1 << 0) {
case 0 << 0: {
pdu->controlField.length = kHAPBLEPDUControlFieldLength_1Byte;
} break;
default: {
HAPLog(&logObject, "Invalid length in Control Field 0x%02x.", controlField[0]);
return kHAPError_InvalidData;
}
}
return kHAPError_None;
}
HAP_RESULT_USE_CHECK
HAPError HAPBLEPDUDeserialize(HAPBLEPDU* pdu, const void* bytes, size_t numBytes) {
HAPPrecondition(pdu);
HAPPrecondition(bytes);
HAPError err;
const uint8_t* b = bytes;
size_t remainingBytes = numBytes;
// PDU Header - Control Field.
if (remainingBytes < 1) {
HAPLog(&logObject, "PDU not long enough to contain Control Field.");
return kHAPError_InvalidData;
}
err = DeserializeControlField(pdu, b);
if (err) {
HAPAssert(err == kHAPError_InvalidData);
return err;
}
if (pdu->controlField.fragmentationStatus != kHAPBLEPDUFragmentationStatus_FirstFragment) {
HAPLog(&logObject, "Unexpected PDU fragmentation status (expected: First fragment (or no fragmentation)).");
return kHAPError_InvalidData;
}
b += 1;
remainingBytes -= 1;
// PDU Fixed Params.
switch (pdu->controlField.type) {
case kHAPBLEPDUType_Request: {
if (remainingBytes < 4) {
HAPLog(&logObject, "Request PDU not long enough to contain Fixed Params.");
return kHAPError_InvalidData;
}
pdu->fixedParams.request.opcode = (HAPPDUOpcode) b[0];
pdu->fixedParams.request.tid = b[1];
pdu->fixedParams.request.iid = HAPReadLittleUInt16(&b[2]);
b += 4;
remainingBytes -= 4;
}
goto deserialize_body;
case kHAPBLEPDUType_Response: {
if (remainingBytes < 2) {
HAPLog(&logObject, "Response PDU not long enough to contain Fixed Params.");
return kHAPError_InvalidData;
}
pdu->fixedParams.response.tid = b[0];
pdu->fixedParams.response.status = (HAPBLEPDUStatus) b[1];
b += 2;
remainingBytes -= 2;
}
goto deserialize_body;
}
HAPFatalError();
deserialize_body:
// PDU Body (Optional).
if (!remainingBytes) {
pdu->body.totalBodyBytes = 0;
pdu->body.bytes = NULL;
pdu->body.numBytes = 0;
} else {
if (remainingBytes < 2) {
HAPLog(&logObject, "PDU not long enough to contain body length.");
return kHAPError_InvalidData;
}
pdu->body.totalBodyBytes = HAPReadLittleUInt16(b);
b += 2;
remainingBytes -= 2;
if (remainingBytes < pdu->body.totalBodyBytes) {
// First fragment.
pdu->body.numBytes = (uint16_t) remainingBytes;
} else {
// Complete body available.
pdu->body.numBytes = pdu->body.totalBodyBytes;
}
pdu->body.bytes = b;
b += pdu->body.numBytes;
remainingBytes -= pdu->body.numBytes;
}
// All data read.
if (remainingBytes) {
HAPLog(&logObject, "Excess data after PDU.");
return kHAPError_InvalidData;
}
(void) b;
LogPDU(pdu);
return kHAPError_None;
}
HAP_RESULT_USE_CHECK
HAPError HAPBLEPDUDeserializeContinuation(
HAPBLEPDU* pdu,
const void* bytes,
size_t numBytes,
HAPBLEPDUType typeOfFirstFragment,
size_t remainingBodyBytes,
size_t totalBodyBytesSoFar) {
HAPPrecondition(pdu);
HAPPrecondition(bytes);
HAPPrecondition(remainingBodyBytes >= totalBodyBytesSoFar);
HAPPrecondition(remainingBodyBytes <= UINT16_MAX);
HAPError err;
const uint8_t* b = bytes;
size_t remainingBytes = numBytes;
// PDU Header - Control Field.
if (remainingBytes < 1) {
HAPLog(&logObject, "PDU not long enough to contain Control Field.");
return kHAPError_InvalidData;
}
err = DeserializeControlField(pdu, b);
if (err) {
HAPAssert(err == kHAPError_InvalidData);
return err;
}
if (pdu->controlField.fragmentationStatus != kHAPBLEPDUFragmentationStatus_Continuation) {
HAPLog(&logObject, "Unexpected PDU fragmentation status (expected: Continuation of fragmented PDU).");
return kHAPError_InvalidData;
}
if (pdu->controlField.type != typeOfFirstFragment) {
HAPLog(&logObject,
"Unexpected PDU type (Continuation type: 0x%02x, First Fragment type: 0x%02x).",
pdu->controlField.type,
typeOfFirstFragment);
return kHAPError_InvalidData;
}
b += 1;
remainingBytes -= 1;
// PDU Fixed Params.
if (remainingBytes < 1) {
HAPLog(&logObject, "Continuation PDU not long enough to contain Fixed Params.");
return kHAPError_InvalidData;
}
pdu->fixedParams.continuation.tid = b[0];
b += 1;
remainingBytes -= 1;
// PDU Body (Optional).
pdu->body.totalBodyBytes = (uint16_t) remainingBodyBytes;
if (!remainingBytes) {
pdu->body.bytes = NULL;
pdu->body.numBytes = 0;
} else if (remainingBytes <= remainingBodyBytes - totalBodyBytesSoFar) {
pdu->body.numBytes = (uint16_t) remainingBytes;
pdu->body.bytes = b;
b += pdu->body.numBytes;
remainingBytes -= pdu->body.numBytes;
}
// All data read.
if (remainingBytes) {
HAPLog(&logObject, "Excess data after PDU.");
return kHAPError_InvalidData;
}
(void) b;
LogPDU(pdu);
return kHAPError_None;
}
/**
* Checks whether a value represents a valid fragmentation status.
*
* @param value Value to check.
*
* @return true If the value is valid.
* @return false Otherwise.
*/
HAP_RESULT_USE_CHECK
static bool HAPBLEPDUIsValidFragmentStatus(uint8_t value) {
switch (value) {
case kHAPBLEPDUFragmentationStatus_FirstFragment:
case kHAPBLEPDUFragmentationStatus_Continuation: {
return true;
}
default: {
return false;
}
}
}
/**
* Checks whether a value represents a valid Control Field length.
*
* @param value Value to check.
*
* @return true If the value is valid.
* @return false Otherwise.
*/
HAP_RESULT_USE_CHECK
static bool HAPBLEPDUIsValidControlFieldLength(uint8_t value) {
switch (value) {
case kHAPBLEPDUControlFieldLength_1Byte: {
return true;
}
default: {
return false;
}
}
}
/**
* Checks whether the Control Field of a PDU structure is valid.
*
* @param pdu PDU with Control Field to check.
*
* @return true If the Control Field is valid.
* @return false Otherwise.
*/
HAP_RESULT_USE_CHECK
static bool HAPBLEPDUHasValidControlField(const HAPBLEPDU* pdu) {
HAPPrecondition(pdu);
return HAPBLEPDUIsValidFragmentStatus(pdu->controlField.fragmentationStatus) &&
HAPBLEPDUIsValidType(pdu->controlField.type) && HAPBLEPDUIsValidControlFieldLength(pdu->controlField.length);
}
/**
* Serializes the Control Field of a PDU structure.
*
* @param pdu PDU with Control Field to serialize.
* @param[out] controlFieldByte Serialized Control Field.
*/
static void SerializeControlField(const HAPBLEPDU* pdu, uint8_t* controlFieldByte) {
HAPPrecondition(pdu);
HAPPrecondition(HAPBLEPDUHasValidControlField(pdu));
HAPPrecondition(controlFieldByte);
// Clear all bits.
controlFieldByte[0] = 0;
// Fragmentation status.
switch (pdu->controlField.fragmentationStatus) {
case kHAPBLEPDUFragmentationStatus_FirstFragment: {
controlFieldByte[0] |= 0 << 7;
}
goto serialize_pdu_type;
case kHAPBLEPDUFragmentationStatus_Continuation: {
controlFieldByte[0] |= 1 << 7;
}
goto serialize_pdu_type;
}
HAPFatalError();
serialize_pdu_type:
// PDU Type.
switch (pdu->controlField.type) {
case kHAPBLEPDUType_Request: {
controlFieldByte[0] |= 0 << 3 | 0 << 2 | 0 << 1;
}
goto serialize_length;
case kHAPBLEPDUType_Response: {
controlFieldByte[0] |= 0 << 3 | 0 << 2 | 1 << 1;
}
goto serialize_length;
}
HAPFatalError();
serialize_length:
// Length.
switch (pdu->controlField.length) {
case kHAPBLEPDUControlFieldLength_1Byte: {
controlFieldByte[0] |= 0 << 0;
return;
}
}
HAPFatalError();
}
HAP_RESULT_USE_CHECK
HAPError HAPBLEPDUSerialize(const HAPBLEPDU* pdu, void* bytes, size_t maxBytes, size_t* numBytes) {
HAPPrecondition(pdu);
HAPPrecondition(HAPBLEPDUHasValidControlField(pdu));
HAPPrecondition(pdu->body.numBytes <= pdu->body.totalBodyBytes);
HAPPrecondition(bytes);
HAPPrecondition(numBytes);
LogPDU(pdu);
uint8_t* b = bytes;
size_t remainingBytes = maxBytes;
// PDU Header - Control Field.
if (remainingBytes < 1) {
HAPLog(&logObject, "Not enough capacity to serialize Control Field.");
return kHAPError_OutOfResources;
}
SerializeControlField(pdu, b);
b += 1;
remainingBytes -= 1;
// PDU Header - PDU Fixed Params.
switch (pdu->controlField.fragmentationStatus) {
case kHAPBLEPDUFragmentationStatus_FirstFragment: {
switch (pdu->controlField.type) {
case kHAPBLEPDUType_Request: {
if (remainingBytes < 4) {
HAPLog(&logObject, "Not enough capacity to serialize Request PDU Fixed Params.");
return kHAPError_OutOfResources;
}
b[0] = pdu->fixedParams.request.opcode;
b[1] = pdu->fixedParams.request.tid;
HAPWriteLittleUInt16(&b[2], pdu->fixedParams.request.iid);
b += 4;
remainingBytes -= 4;
goto serialize_body;
}
case kHAPBLEPDUType_Response: {
if (remainingBytes < 2) {
HAPLog(&logObject, "Not enough capacity to serialize Response PDU Fixed Params.");
return kHAPError_OutOfResources;
}
b[0] = pdu->fixedParams.response.tid;
b[1] = pdu->fixedParams.response.status;
b += 2;
remainingBytes -= 2;
goto serialize_body;
}
}
HAPFatalError();
serialize_body:
// PDU Body (Optional).
if (pdu->body.bytes) {
if (remainingBytes < 2) {
HAPLog(&logObject, "Not enough capacity to serialize PDU Body length.");
return kHAPError_OutOfResources;
}
HAPWriteLittleUInt16(&b[0], pdu->body.totalBodyBytes);
b += 2;
remainingBytes -= 2;
if (remainingBytes < pdu->body.numBytes) {
HAPLog(&logObject, "Not enough capacity to serialize PDU Body.");
return kHAPError_OutOfResources;
}
HAPRawBufferCopyBytes(b, HAPNonnullVoid(pdu->body.bytes), pdu->body.numBytes);
b += pdu->body.numBytes;
remainingBytes -= pdu->body.numBytes;
}
goto done;
}
case kHAPBLEPDUFragmentationStatus_Continuation: {
if (remainingBytes < 1) {
HAPLog(&logObject, "Not enough capacity to serialize Continuation PDU Fixed Params.");
return kHAPError_OutOfResources;
}
b[0] = pdu->fixedParams.continuation.tid;
b += 1;
remainingBytes -= 1;
if (remainingBytes < pdu->body.numBytes) {
HAPLog(&logObject, "Not enough capacity to serialize PDU Body.");
return kHAPError_OutOfResources;
}
if (!pdu->body.numBytes) {
HAPLog(&logObject, "Received empty continuation fragment.");
} else {
HAPAssert(pdu->body.bytes);
HAPRawBufferCopyBytes(b, HAPNonnullVoid(pdu->body.bytes), pdu->body.numBytes);
b += pdu->body.numBytes;
remainingBytes -= pdu->body.numBytes;
}
goto done;
}
}
HAPAssertionFailure();
done:
// All data written.
*numBytes = maxBytes - remainingBytes;
(void) b;
return kHAPError_None;
}