-
Notifications
You must be signed in to change notification settings - Fork 232
/
Copy pathHAPUUID.h
121 lines (109 loc) · 4.21 KB
/
HAPUUID.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
// 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_UUID_H
#define HAP_UUID_H
#ifdef __cplusplus
extern "C" {
#endif
#include "HAP+Internal.h"
#if __has_feature(nullability)
#pragma clang assume_nonnull begin
#endif
/**
* Creates a HAPUUID structure from a short UUID that is based on the Apple-defined HAP Base UUID.
*
* - Full UUIDs have the form XXXXXXXX-0000-1000-8000-0026BB765291.
* The short form consists of just the front part, e.g. 0x43 for the HomeKit Light Bulb service.
* UUID strings use hexadecimal digits - remember to use the 0x prefix.
*
* - This function may only be used for Apple-defined types.
* For vendor-specific UUIDs, a different base UUID must be used.
*
* @param uuid Short UUID, e.g. 0x43 for the HomeKit Light Bulb service.
*
* @return Initialized HAPUUID structure.
*
* @see HomeKit Accessory Protocol Specification R14
* Section 6.6.1 Service and Characteristic Types
*/
#define HAPUUIDCreateAppleDefined(uuid) \
{ \
{ 0x91, 0x52, 0x76, 0xBB, 0x26, 0x00, 0x00, 0x80, 0x00, 0x10, 0x00, 0x00, HAPExpandLittleUInt32(uuid) } \
}
/**
* Returns whether a HAP UUID is Apple defined.
*
* @param uuid UUID.
*
* @return true If the UUID is Apple defined.
* @return false Otherwise.
*
* @see HomeKit Accessory Protocol Specification R14
* Section 6.6.1 Service and Characteristic Types
*/
HAP_RESULT_USE_CHECK
bool HAPUUIDIsAppleDefined(const HAPUUID* uuid);
/**
* Determines the space needed by the string representation of a HAP UUID.
*
* @param uuid UUID.
*
* @return Number of bytes that the UUID's string representation needs (excluding NULL-terminator).
*/
HAP_RESULT_USE_CHECK
size_t HAPUUIDGetNumDescriptionBytes(const HAPUUID* uuid);
/**
* Gets the string representation of a HAP UUID.
*
* @param uuid UUID.
* @param[out] bytes Buffer to fill with the UUID's string representation. Will be NULL-terminated.
* @param maxBytes Capacity of buffer.
*
* @return kHAPError_None If successful.
* @return kHAPError_OutOfResources If the supplied buffer is not large enough.
*/
HAP_RESULT_USE_CHECK
HAPError HAPUUIDGetDescription(const HAPUUID* uuid, char* bytes, size_t maxBytes);
/**
* Gets the short form of a HAP UUID.
*
* - When Apple-defined UUIDs based on the HAP Base UUID 00000000-0000-1000-8000-0026BB765291 are encoded
* in short form, the -0000-1000-8000-0026BB765291 suffix is omitted and leading zero bytes are removed.
* The remaining bytes are sent in the same order as when sending a full UUID.
* To convert back to a full UUID, the process is reversed.
*
* - Custom types do not use the HAP Base UUID and are encoded in the same format as the full UUID.
*
* - Examples:
* 00000000-0000-1000-8000-0026BB765291 -> []
* 0000003E-0000-1000-8000-0026BB765291 -> [0x3E]
* 00000001-0000-1000-8000-0026BB765291 -> [0x01]
* 00000F25-0000-1000-8000-0026BB765291 -> [0x25, 0x0F]
* 0000BBAB-0000-1000-8000-0026BB765291 -> [0xAB, 0xBB]
* 00112233-0000-1000-8000-0026BB765291 -> [0x33, 0x22, 0x11]
* 010004FF-0000-1000-8000-0026BB765291 -> [0xFF, 0x04, 0x00, 0x01]
* FF000000-0000-1000-8000-0026BB765291 -> [0x00, 0x00, 0x00, 0xFF]
*
* @param uuid UUID.
* @param[out] bytes Buffer to fill with the UUID's compact representation.
* @param maxBytes Capacity of buffer.
* @param[out] numBytes Effective length of buffer.
*
* @return kHAPError_None If successful.
* @return kHAPError_OutOfResources If the supplied buffer is not large enough.
*
* @see HomeKit Accessory Protocol Specification R14
* Section 6.6.1 Service and Characteristic Types
*/
HAP_RESULT_USE_CHECK
HAPError HAPUUIDGetShortFormBytes(const HAPUUID* uuid, void* bytes, size_t maxBytes, size_t* numBytes);
#if __has_feature(nullability)
#pragma clang assume_nonnull end
#endif
#ifdef __cplusplus
}
#endif
#endif