-
Notifications
You must be signed in to change notification settings - Fork 232
/
Copy pathHAP.h
4497 lines (3979 loc) · 154 KB
/
HAP.h
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
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// 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.
#ifndef HAP_H
#define HAP_H
#ifdef __cplusplus
extern "C" {
#endif
#include "HAPPlatform.h"
#if __has_feature(nullability)
#pragma clang assume_nonnull begin
#endif
/**
* Compatibility version of the HAP interface.
*
* - If this version differs from the one returned by HAPGetCompatibilityVersion,
* the library is incompatible and must not be used.
*/
#define HAP_COMPATIBILITY_VERSION (7)
/**
* Gets the compatibility version of the HAP library.
*
* - If the compatibility version differs from HAP_COMPATIBILITY_VERSION,
* the library is incompatible and may not be used.
*
* @return Compatibility version of the HAP library.
*/
HAP_RESULT_USE_CHECK
uint32_t HAPGetCompatibilityVersion(void);
/**
* Gets the identification of the HAP library.
*
* @return HAP library identification string.
*/
HAP_RESULT_USE_CHECK
const char* HAPGetIdentification(void);
/**
* Gets the version string of the HAP library.
*
* @return Version string of the HAP library.
*/
HAP_RESULT_USE_CHECK
const char* HAPGetVersion(void);
/**
* Gets the build version string of the HAP library.
*
* @return Build version string of the HAP library.
*/
HAP_RESULT_USE_CHECK
const char* HAPGetBuild(void);
/**
* 128-bit UUID.
*
* - The encoding of UUIDs uses reversed byte order compared to RFC 4122, i.e. network byte order backwards.
*
* Sample:
* UUID: 00112233-4455-6677-8899-AABBCCDDEEFF
* bytes: 0xFF, 0xEE, 0xDD, 0xCC, 0xBB, 0xAA, 0x99, 0x88, 0x77, 0x66, 0x55, 0x44, 0x33, 0x22, 0x11, 0x00
*/
typedef struct {
uint8_t bytes[16]; /**< UUID bytes in reversed network byte order. */
} HAPUUID;
HAP_STATIC_ASSERT(sizeof(HAPUUID) == 16, HAPUUID);
HAP_NONNULL_SUPPORT(HAPUUID)
/**
* Returns whether or not two UUIDs are equal.
*
* @param uuid UUID to compare.
* @param otherUUID UUID to compare with.
*
* @return true If both UUIDs are equal.
* @return false Otherwise.
*/
HAP_RESULT_USE_CHECK
bool HAPUUIDAreEqual(const HAPUUID* uuid, const HAPUUID* otherUUID);
/**
* TLV type.
*
* - The type semantics depend on the context.
*/
typedef uint8_t HAPTLVType;
/**
* TLV.
*/
typedef struct {
/** Type. */
HAPTLVType type;
/** Value. */
struct {
const void* _Nullable bytes; /**< Buffer containing value. */
size_t numBytes; /**< Length of buffer. */
} value;
} HAPTLV;
/**
* TLV Reader.
*/
typedef HAP_OPAQUE(32) HAPTLVReaderRef;
/**
* Creates a new TLV reader.
*
* @param reader An uninitialized TLV reader.
* @param bytes Buffer containing raw TLV data. Will be modified by the reader. Must remain valid.
* @param numBytes Length of buffer.
*/
void HAPTLVReaderCreate(HAPTLVReaderRef* reader, void* _Nullable bytes, size_t numBytes);
/**
* Fetches the next TLV item from a TLV reader's buffer. TLV item content is NULL-terminated for convenience.
*
* @param reader Reader to fetch TLV item from.
* @param[out] found True if a TLV item has been fetched. False otherwise.
* @param[out] tlv Next TLV item. Valid when @p found is true. Fragments are merged automatically.
*
* @return kHAPError_None If successful.
* @return kHAPError_InvalidData If parsing failed (Incomplete item, or violation of TLV rules).
*/
HAP_RESULT_USE_CHECK
HAPError HAPTLVReaderGetNext(HAPTLVReaderRef* reader, bool* found, HAPTLV* tlv);
/**
* Fetches TLV items by type into @p tlvs.
*
* On input, @p tlvs is a NULL-terminated array to TLV items.
* For each TLV item, the type shall be specified. Types must be unique.
*
* On output, @p tlvs are updated to contain the actual TLV items.
* If multiple TLV items with one of the requested types are found, an error is returned.
* TLV item contents are NULL-terminated for convenience.
*
* - This API must be used on a freshly initialized TLV reader. All TLV items will be read.
*
* @param reader Reader to fetch TLV items from.
* @param[in,out] tlvs NULL-terminated array to TLV structures.
* On input, type filters are specified. On output, actual TLV items are filled in.
* For TLV items not found, values are set to NULL.
* Each type may only be requested once.
*
* @return kHAPError_None If successful.
* @return kHAPError_InvalidData If parsing failed (Incomplete item, or violation of TLV rules), or if multiple TLV
* items with a requested type are found.
*/
HAP_RESULT_USE_CHECK
HAPError HAPTLVReaderGetAll(HAPTLVReaderRef* reader, HAPTLV* _Nullable const* _Nonnull tlvs);
/**
* TLV Writer.
*/
typedef HAP_OPAQUE(32) HAPTLVWriterRef;
HAP_NONNULL_SUPPORT(HAPTLVWriterRef)
/**
* Creates a new TLV writer.
*
* @param writer An uninitialized TLV writer.
* @param bytes Buffer to serialize TLV data into. Must remain valid.
* @param maxBytes Capacity of the buffer.
*/
void HAPTLVWriterCreate(HAPTLVWriterRef* writer, void* bytes, size_t maxBytes);
/**
* Serializes a TLV item and appends it to the writer's buffer.
*
* - Multiple items of same type must be separated by an item with different type.
*
* @param writer Writer to append serialized TLV to.
* @param tlv TLV to write.
*
* @return kHAPError_None If successful.
* @return kHAPError_OutOfResources If the writer's buffer is not large enough to hold the serialized TLV item.
*/
HAP_RESULT_USE_CHECK
HAPError HAPTLVWriterAppend(HAPTLVWriterRef* writer, const HAPTLV* tlv);
/**
* Retrieves the buffer containing the serialized TLV data.
*
* @param writer Writer to retrieve buffer from.
* @param[out] bytes Buffer containing serialized TLV data written so far.
* @param[out] numBytes Length of buffer.
*/
void HAPTLVWriterGetBuffer(const HAPTLVWriterRef* writer, void* _Nonnull* _Nonnull bytes, size_t* numBytes);
/**
* Retrieves a temporary buffer of unused memory, e.g. to prepare the next TLV payload to be written.
*
* - /!\ The buffer becomes invalid after writing to the TLV writer again.
*
* @param writer Writer to retrieve buffer from.
* @param[out] scratchBytes Temporary buffer of free memory.
* @param[out] numScratchBytes Capacity of scratch buffer.
*/
void HAPTLVWriterGetScratchBytes(
const HAPTLVWriterRef* writer,
void* _Nonnull* _Nonnull scratchBytes,
size_t* numScratchBytes);
/**
* HomeKit Accessory server.
*/
typedef HAP_OPAQUE(2418) HAPAccessoryServerRef;
HAP_NONNULL_SUPPORT(HAPAccessoryServerRef)
/**
* HomeKit Session.
*/
typedef HAP_OPAQUE(488) HAPSessionRef;
HAP_NONNULL_SUPPORT(HAPSessionRef)
/**
* Formats that HomeKit characteristics can have.
*
* - IMPORTANT: The format must always match the type of the characteristic structure!
* For example, kHAPCharacteristicFormat_UInt8 may only be used on HAPUInt8Characteristic.
*
* - For Apple-defined characteristics, the format must be used exactly as defined in the specification.
* For example, in the specification the Brightness characteristic is defined to have type "int".
* Therefore, a HAPIntCharacteristic must be used for it (with format kHAPCharacteristicFormat_Int).
*
* - For vendor-specific characteristics, any format may be chosen.
*/
HAP_ENUM_BEGIN(uint8_t, HAPCharacteristicFormat) { /**
* Opaque data blob. Raw bytes.
*
* - Default format in case no other format has been specified.
*/
kHAPCharacteristicFormat_Data,
/**
* Boolean. True or false.
*/
kHAPCharacteristicFormat_Bool,
/**
* Unsigned 8-bit integer.
*/
kHAPCharacteristicFormat_UInt8,
/**
* Unsigned 16-bit integer.
*/
kHAPCharacteristicFormat_UInt16,
/**
* Unsigned 32-bit integer.
*/
kHAPCharacteristicFormat_UInt32,
/**
* Unsigned 64-bit integer.
*/
kHAPCharacteristicFormat_UInt64,
/**
* Signed 32-bit integer.
*/
kHAPCharacteristicFormat_Int,
/**
* 32-bit floating point.
*/
kHAPCharacteristicFormat_Float,
/**
* UTF-8 string.
*/
kHAPCharacteristicFormat_String,
/**
* One or more TLV8s.
*/
kHAPCharacteristicFormat_TLV8
} HAP_ENUM_END(uint8_t, HAPCharacteristicFormat);
/**
* Properties that HomeKit characteristics can have.
*
* For Apple-defined characteristics, the default values for the following properties are defined by the specification:
* - readable (Paired Read)
* - writable (Paired Write)
* - supportsEventNotification (Notify)
*
* The remaining properties have to be evaluated on a case by case basis.
*/
typedef struct {
/**
* The characteristic is readable.
*
* - A read handler must be plugged into the characteristic structure's corresponding callback field.
* Only controllers with a secured connection can perform reads.
*/
bool readable : 1;
/**
* The characteristic is writable.
*
* - A write handler must be plugged into the characteristic structure's corresponding callback field.
* Only controllers with a secured connection can perform writes.
*/
bool writable : 1;
/**
* The characteristic supports notifications using the event connection established by the controller.
* The event connection provides unidirectional communication from the accessory to the controller.
*
* - A read handler must be plugged into the characteristic structure's corresponding callback field.
* Only controllers with a secured connection can subscribe to events.
*
* - When the characteristic state changes, the HAPAccessoryServerRaiseEvent or
* HAPAccessoryServerRaiseEventOnSession function must be called.
*/
bool supportsEventNotification : 1;
/**
* The characteristic should be hidden from the user.
*
* - This is useful for characteristics to configure the accessory or to update firmware on the accessory.
* Generic HomeKit applications on the controller won't show these characteristics.
*
* - When all characteristics in a service are marked hidden then the service must also be marked as hidden.
*/
bool hidden : 1;
/**
* The characteristic will only be accessible by admin controllers.
*
* - Reads and writes to the characteristic will only execute if the controller has admin permissions.
*
* - Event notification values for the characteristic will only be delivered to controllers with admin permissions.
*/
HAP_DEPRECATED_MSG("Use properties readRequiresAdminPermissions and writeRequiresAdminPermissions instead.")
bool requiresAdminPermissions : 1;
/**
* The characteristic will only be accessible for read operations by admin controllers.
*
* - Reads to the characteristic will only execute if the controller has admin permissions.
*
* - Event notification values for the characteristic will only be delivered to controllers with admin permissions.
*
* - The subscription state of event notifications for the characteristic will only be modified by controllers with
* admin permissions.
*/
bool readRequiresAdminPermissions : 1;
/**
* The characteristic will only be accessible for write operations by admin controllers.
*
* - Writes to the characteristic will only execute if the controller has admin permissions.
*/
bool writeRequiresAdminPermissions : 1;
/**
* The characteristic requires time sensitive actions.
*
* - Writes to the characteristic will only execute if the accessory can be reached within a short time frame.
* This is useful for example for security class characteristics like Lock Target State or Target Door State.
*
* - A write handler must be plugged into the characteristic structure's corresponding callback field.
* The characteristic must also be marked as writable.
*/
bool requiresTimedWrite : 1;
/**
* The characteristic requires additional authorization data.
*
* - Additional authorization data is controller-provided data that the accessory may use to validate that the
* controller is authorized to perform a requested operation. The contents of the authorization data are
* manufacturer specific. The additional authorization data is provided by the accessory app (an iOS app
* provided by the accessory manufacturer to control or configure the accessory) to iOS and stored by iOS
* on the controller. The additional authorization data must not be unique per write request as the controller
* will not construct or receive unique authorization data for each request. Additional authorization data
* may change periodically, e.g. once per month, or when user permissions change.
*
* - A write handler must be plugged into the characteristic structure's corresponding callback field.
* The characteristic must also be marked as writable.
*
* - It is left up to the write handler to validate additional authorization data.
* If authorization is insufficient, kHAPError_NotAuthorized must be returned from the handler.
*
* @see iOS documentation for [HMCharacteristic updateAuthorizationData(_:completionHandler:)]
*
* @see HomeKit Accessory Protocol Specification R14
* Section 2.3.3.2 Additional Authorization Data
*/
bool supportsAuthorizationData : 1;
/**
* These properties only affect connections over IP (Ethernet / Wi-Fi).
*
* - If the accessory only supports Bluetooth, these properties can be ignored.
*/
struct {
/**
* This flag prevents the characteristic from being read during discovery.
*
* - Normally, all characteristic values are being read during discovery over an IP transport.
* If a characteristic maintains state across multiple reads / writes, depending on the timing
* such discovery operations may interfere with correct operation.
*
* - Setting this flag prevents the characteristic from being read during discovery.
* Instead, a NULL value will be sent to the controller during discovery. Only explicit reads are processed.
*
* - This property may be useful for characteristics that handle firmware updates of the accessory.
*/
bool controlPoint : 1;
/**
* Write operations on the characteristic require a read response value.
*
* - This property is typically applicable to write control point operations.
*
* - Write and read handlers must be plugged into the characteristic structure's corresponding callback fields.
* The characteristic must also be marked as writable.
*
* - After a successful write, a read operation is always requested immediately (i.e. without any other requests
* in-between).
*/
bool supportsWriteResponse : 1;
} ip;
/**
* These properties only affect connections over Bluetooth LE.
*
* - If the accessory only supports IP (Ethernet, Wi-Fi), these properties can be ignored.
*/
struct {
/**
* The characteristic supports broadcast notifications. Such broadcasts happen when the characteristic state
* changes while no controller is connected. This allows paired controllers to quickly react to the notification
* without having to re-establish a secured connection.
*
* - When this property is not set, controllers may only receive state updates while connected.
*
* - A read handler must be plugged into the characteristic structure's corresponding callback field.
* Only paired controllers can decode and process the broadcasts.
*
* - When the characteristic state changes, the HAPAccessoryServerRaiseEvent or
* HAPAccessoryServerRaiseEventOnSession function must be called.
*/
bool supportsBroadcastNotification : 1;
/**
* The characteristic supports disconnected notifications. When the characteristic state changes while no
* controller is connected, paired controllers will re-establish a secured connection to the accessory and
* fetch the updated characteristic state.
*
* - When this property is set, the following properties must also be set:
* - readable
* - supportsEventNotification
* - ble.supportsBroadcastNotification
*
* - This property must be set on at least one characteristic of an accessory to work around an issue
* in certain versions of the Home app that would otherwise claim that Additional Setup is required.
*
* - Disconnected events should only be used to reflect important state changes in the accessory.
* For example, contact sensor state changes or current door state changes should use this property.
* On the other hand, a temperature sensor must not use this property for changes in temperature readings.
*
* - A read handler must be plugged into the characteristic structure's corresponding callback field.
*
* - When the characteristic state changes, the HAPAccessoryServerRaiseEvent or
* HAPAccessoryServerRaiseEventOnSession function must be called.
*/
bool supportsDisconnectedNotification : 1;
/**
* The characteristic is always readable, even before a secured session is established.
*
* - This is mainly an internal property that is used on characteristics that handle the pairing process.
*
* - A read handler must be plugged into the characteristic structure's corresponding callback field.
*/
bool readableWithoutSecurity : 1;
/**
* The characteristic is always writable, even before a secured session is established.
*
* - This is mainly an internal property that is used on characteristics that handle the pairing process.
*
* - A write handler must be plugged into the characteristic structure's corresponding callback field.
*/
bool writableWithoutSecurity : 1;
} ble;
} HAPCharacteristicProperties;
HAP_STATIC_ASSERT(sizeof(HAPCharacteristicProperties) == 4, HAPCharacteristicProperties);
/**
* Units that numeric HomeKit characteristics can have.
*
* For Apple-defined characteristics, the corresponding units are defined by the specification.
*/
HAP_ENUM_BEGIN(uint8_t, HAPCharacteristicUnits) { /**
* Unitless. Used for example on enumerations.
*/
kHAPCharacteristicUnits_None,
/**
* The unit of the characteristic is degrees celsius.
*/
kHAPCharacteristicUnits_Celsius,
/**
* The unit of the characteristic is the degrees of an arc.
*/
kHAPCharacteristicUnits_ArcDegrees,
/**
* The unit of the characteristic is a percentage %.
*/
kHAPCharacteristicUnits_Percentage,
/**
* The unit of the characteristic is lux (that is, illuminance).
*/
kHAPCharacteristicUnits_Lux,
/**
* The unit of the characteristic is seconds.
*/
kHAPCharacteristicUnits_Seconds
} HAP_ENUM_END(uint8_t, HAPCharacteristicUnits);
/**
* Transport type over which a request has been received or over which a response will be sent.
*/
HAP_ENUM_BEGIN(uint8_t, HAPTransportType) { /**
* HAP over IP (Ethernet / Wi-Fi).
*/
kHAPTransportType_IP = 1,
/**
* HAP over Bluetooth LE.
*/
kHAPTransportType_BLE
} HAP_ENUM_END(uint8_t, HAPTransportType);
typedef void HAPCharacteristic;
typedef struct HAPService HAPService;
typedef struct HAPAccessory HAPAccessory;
// <editor-fold desc="HAPDataCharacteristic">
typedef struct HAPDataCharacteristic HAPDataCharacteristic;
/**
* Data characteristic read request.
*/
typedef struct {
/**
* Transport type over which the response will be sent.
*/
HAPTransportType transportType;
/**
* The session over which the response will be sent.
*
* - A controller may be logged in on multiple sessions concurrently.
* - May be NULL if a request is generated internally (e.g. for BLE broadcasts while disconnected).
*
* - For remote requests (e.g. via Apple TV), the associated controller may not be
* the one who originated the request, but instead the admin controller who set up the Apple TV.
*/
HAPSessionRef* _Nullable session;
/**
* The characteristic whose value is to be read.
*/
const HAPDataCharacteristic* characteristic;
/**
* The service that contains the characteristic.
*/
const HAPService* service;
/**
* The accessory that provides the service.
*/
const HAPAccessory* accessory;
} HAPDataCharacteristicReadRequest;
/**
* Data characteristic write request.
*/
typedef struct {
/**
* Transport type over which the request has been received.
*/
HAPTransportType transportType;
/**
* The session over which the request has been received.
*
* - A controller may be logged in on multiple sessions concurrently.
*
* - For remote requests (e.g. via Apple TV), the associated controller may not be
* the one who originated the request, but instead the admin controller who set up the Apple TV.
*/
HAPSessionRef* session;
/**
* The characteristic whose value is to be written.
*/
const HAPDataCharacteristic* characteristic;
/**
* The service that contains the characteristic.
*/
const HAPService* service;
/**
* The accessory that provides the service.
*/
const HAPAccessory* accessory;
/**
* Whether the request appears to have originated from a remote controller, e.g. via Apple TV.
*/
bool remote;
/**
* Additional authorization data.
*/
struct {
const void* _Nullable bytes; /**< Raw AAD data, if applicable. */
size_t numBytes; /**< Length of additional authorization data. */
} authorizationData;
} HAPDataCharacteristicWriteRequest;
/**
* Data characteristic subscription request.
*/
typedef struct {
/**
* Transport type over which the request has been received.
*/
HAPTransportType transportType;
/**
* The session over which the request has been received.
*
* - A controller may be logged in on multiple sessions concurrently.
*/
HAPSessionRef* session;
/**
* The characteristic whose value is to be subscribed or unsubscribed.
*/
const HAPDataCharacteristic* characteristic;
/**
* The service that contains the characteristic.
*/
const HAPService* service;
/**
* The accessory that provides the service.
*/
const HAPAccessory* accessory;
} HAPDataCharacteristicSubscriptionRequest;
/**
* HomeKit Data characteristic.
*/
struct HAPDataCharacteristic {
/**
* Format. Must be kHAPCharacteristicFormat_Data.
*/
HAPCharacteristicFormat format;
/**
* Instance ID.
*
* - Must be unique across all service or characteristic instance IDs of the accessory.
* - Must not change while the accessory is paired, including over firmware updates.
* - Must not be 0.
* - For accessories that support Bluetooth LE, must not exceed UINT16_MAX.
*/
uint64_t iid;
/**
* The type of the characteristic.
*/
const HAPUUID* characteristicType;
/**
* Description for debugging (based on "Type" field of HAP specification).
*/
const char* debugDescription;
/**
* Description of the characteristic provided by the manufacturer of the accessory.
*/
const char* _Nullable manufacturerDescription;
/**
* Characteristic properties.
*/
HAPCharacteristicProperties properties;
/**
* Value constraints.
*/
struct {
uint32_t maxLength; /**< Maximum length. */
} constraints;
/**
* Callbacks.
*/
struct {
/**
* The callback used to handle read requests.
* On success, the value stored in the value buffer is sent back to the controller.
*
* - Required if the characteristic is marked readable in the characteristic properties.
* - The callback must not block. Consider prefetching values if it would take too long.
* - The returned value must satisfy the constraints of the characteristic.
*
* @param server Accessory server.
* @param request Request.
* @param[out] valueBytes Value buffer.
* @param maxValueBytes Capacity of value buffer.
* @param[out] numValueBytes Length of value buffer.
* @param context The context parameter given to the HAPAccessoryServerCreate function.
*
* @return kHAPError_None If successful.
* @return kHAPError_Unknown If unable to perform operation with requested service or characteristic.
* @return kHAPError_InvalidState If the request cannot be processed in the current state.
* @return kHAPError_OutOfResources If out of resources to process request.
* @return kHAPError_Busy If the request failed temporarily.
*/
HAP_RESULT_USE_CHECK
HAPError (*_Nullable handleRead)(
HAPAccessoryServerRef* server,
const HAPDataCharacteristicReadRequest* request,
void* valueBytes,
size_t maxValueBytes,
size_t* numValueBytes,
void* _Nullable context);
/**
* The callback used to handle write requests.
*
* - Required if the characteristic is marked writeable in the characteristic properties.
* - The callback must not block. Consider queueing values if it would take too long.
* - The value is already checked against the constraints of the characteristic.
*
* @param server Accessory server.
* @param request Request.
* @param valueBytes Value buffer.
* @param numValueBytes Length of value buffer.
* @param context The context parameter given to the HAPAccessoryServerCreate function.
*
* @return kHAPError_None If successful.
* @return kHAPError_Unknown If unable to perform operation with requested service or characteristic.
* @return kHAPError_InvalidState If the request cannot be processed in the current state.
* @return kHAPError_InvalidData If the controller sent a malformed request.
* @return kHAPError_OutOfResources If out of resources to process request.
* @return kHAPError_NotAuthorized If additional authorization data is insufficient.
* @return kHAPError_Busy If the request failed temporarily.
*/
HAP_RESULT_USE_CHECK
HAPError (*_Nullable handleWrite)(
HAPAccessoryServerRef* server,
const HAPDataCharacteristicWriteRequest* request,
const void* valueBytes,
size_t numValueBytes,
void* _Nullable context);
/**
* The callback used to handle subscribe requests.
*
* - The callback must not block. Consider queueing values if it would take too long.
*
* @param server Accessory server.
* @param request Request.
* @param context The context parameter given to the HAPAccessoryServerCreate function.
*/
void (*_Nullable handleSubscribe)(
HAPAccessoryServerRef* server,
const HAPDataCharacteristicSubscriptionRequest* request,
void* _Nullable context);
/**
* The callback used to handle unsubscribe requests.
*
* - The callback must not block. Consider queueing values if it would take too long.
*
* @param server Accessory server.
* @param request Request.
* @param context The context parameter given to the HAPAccessoryServerCreate function.
*/
void (*_Nullable handleUnsubscribe)(
HAPAccessoryServerRef* server,
const HAPDataCharacteristicSubscriptionRequest* request,
void* _Nullable context);
} callbacks;
};
// </editor-fold>
// <editor-fold desc="HAPBoolCharacteristic">
typedef struct HAPBoolCharacteristic HAPBoolCharacteristic;
/**
* Bool characteristic read request.
*/
typedef struct {
/**
* Transport type over which the response will be sent.
*/
HAPTransportType transportType;
/**
* The session over which the response will be sent.
*
* - A controller may be logged in on multiple sessions concurrently.
* - May be NULL if a request is generated internally (e.g. for BLE broadcasts while disconnected).
*
* - For remote requests (e.g. via Apple TV), the associated controller may not be
* the one who originated the request, but instead the admin controller who set up the Apple TV.
*/
HAPSessionRef* _Nullable session;
/**
* The characteristic whose value is to be read.
*/
const HAPBoolCharacteristic* characteristic;
/**
* The service that contains the characteristic.
*/
const HAPService* service;
/**
* The accessory that provides the service.
*/
const HAPAccessory* accessory;
} HAPBoolCharacteristicReadRequest;
/**
* Bool characteristic write request.
*/
typedef struct {
/**
* Transport type over which the request has been received.
*/
HAPTransportType transportType;
/**
* The session over which the request has been received.
*
* - A controller may be logged in on multiple sessions concurrently.
*
* - For remote requests (e.g. via Apple TV), the associated controller may not be
* the one who originated the request, but instead the admin controller who set up the Apple TV.
*/
HAPSessionRef* session;
/**
* The characteristic whose value is to be written.
*/
const HAPBoolCharacteristic* characteristic;
/**
* The service that contains the characteristic.
*/
const HAPService* service;
/**
* The accessory that provides the service.
*/
const HAPAccessory* accessory;
/**
* Whether the request appears to have originated from a remote controller, e.g. via Apple TV.
*/
bool remote;
/**
* Additional authorization data.
*/
struct {
const void* _Nullable bytes; /**< Raw AAD data, if applicable. */
size_t numBytes; /**< Length of additional authorization data. */
} authorizationData;
} HAPBoolCharacteristicWriteRequest;
/**
* Bool characteristic subscription request.
*/
typedef struct {
/**
* Transport type over which the request has been received.
*/
HAPTransportType transportType;
/**
* The session over which the request has been received.
*
* - A controller may be logged in on multiple sessions concurrently.
*/
HAPSessionRef* session;
/**
* The characteristic whose value is to be subscribed or unsubscribed.
*/
const HAPBoolCharacteristic* characteristic;
/**
* The service that contains the characteristic.
*/
const HAPService* service;
/**
* The accessory that provides the service.
*/
const HAPAccessory* accessory;
} HAPBoolCharacteristicSubscriptionRequest;
/**
* HomeKit Bool characteristic.
*/
struct HAPBoolCharacteristic {
/**
* Format. Must be kHAPCharacteristicFormat_Bool.
*/
HAPCharacteristicFormat format;
/**
* Instance ID.
*
* - Must be unique across all service or characteristic instance IDs of the accessory.
* - Must not change while the accessory is paired, including over firmware updates.
* - Must not be 0.
* - For accessories that support Bluetooth LE, must not exceed UINT16_MAX.
*/
uint64_t iid;
/**
* The type of the characteristic.
*/
const HAPUUID* characteristicType;
/**
* Description for debugging (based on "Type" field of HAP specification).
*/
const char* debugDescription;
/**
* Description of the characteristic provided by the manufacturer of the accessory.
*/
const char* _Nullable manufacturerDescription;
/**
* Characteristic properties.
*/
HAPCharacteristicProperties properties;
/**
* Callbacks.
*/
struct {
/**
* The callback used to handle read requests.
* On success, the value stored in @p value is sent back to the controller.
*
* - Required if the characteristic is marked readable in the characteristic properties.
* - The callback must not block. Consider prefetching values if it would take too long.
* - The returned value must satisfy the constraints of the characteristic.
*
* @param server Accessory server.
* @param request Request.
* @param[out] value Value.
* @param context The context parameter given to the HAPAccessoryServerCreate function.
*
* @return kHAPError_None If successful.
* @return kHAPError_Unknown If unable to perform operation with requested service or characteristic.
* @return kHAPError_InvalidState If the request cannot be processed in the current state.
* @return kHAPError_OutOfResources If out of resources to process request.
* @return kHAPError_Busy If the request failed temporarily.
*/