-
Notifications
You must be signed in to change notification settings - Fork 232
/
Copy pathHAPAccessoryServer+Reset.c
94 lines (79 loc) · 3.01 KB
/
HAPAccessoryServer+Reset.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
// 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"
HAP_RESULT_USE_CHECK
HAPError HAPRestoreFactorySettings(HAPPlatformKeyValueStoreRef keyValueStore) {
HAPPrecondition(keyValueStore);
HAPError err;
// Erase persistent store.
static const HAPPlatformKeyValueStoreDomain domainsToPurge[] = {
kHAPKeyValueStoreDomain_Configuration,
kHAPKeyValueStoreDomain_CharacteristicConfiguration,
kHAPKeyValueStoreDomain_Pairings
};
for (size_t i = 0; i < HAPArrayCount(domainsToPurge); i++) {
err = HAPPlatformKeyValueStorePurgeDomain(keyValueStore, domainsToPurge[i]);
if (err) {
HAPAssert(err == kHAPError_Unknown);
return err;
}
}
return kHAPError_None;
}
HAP_RESULT_USE_CHECK
HAPError HAPRemoveAllPairings(HAPPlatformKeyValueStoreRef keyValueStore) {
HAPPrecondition(keyValueStore);
HAPError err;
// Erase persistent store.
static const HAPPlatformKeyValueStoreDomain domainsToPurge[] = { kHAPKeyValueStoreDomain_Pairings };
for (size_t i = 0; i < HAPArrayCount(domainsToPurge); i++) {
err = HAPPlatformKeyValueStorePurgeDomain(keyValueStore, domainsToPurge[i]);
if (err) {
HAPAssert(err == kHAPError_Unknown);
return err;
}
}
return kHAPError_None;
}
HAP_RESULT_USE_CHECK
HAPError HAPHandleFirmwareUpdate(HAPAccessoryServerRef* server_) {
HAPPrecondition(server_);
HAPAccessoryServer* server = (HAPAccessoryServer*) server_;
HAPPlatformKeyValueStoreRef keyValueStore = server->platform.keyValueStore;
HAPError err;
// Increment CN.
// See HomeKit Accessory Protocol Specification R14
// Table 6-7 _hap._tcp Bonjour TXT Record Keys
// See HomeKit Accessory Protocol Specification R14
// Section 7.4.2.1.2 Manufacturer Data
err = HAPAccessoryServerIncrementCN(keyValueStore);
if (err) {
HAPAssert(err == kHAPError_Unknown);
return err;
}
// BLE: Reset GSN.
// See HomeKit Accessory Protocol Specification R14
// Section 7.4.1.8 Global State Number (GSN)
if (server->transports.ble) {
err = HAPPlatformKeyValueStoreRemove(
keyValueStore, kHAPKeyValueStoreDomain_Configuration, kHAPKeyValueStoreKey_Configuration_BLEGSN);
if (err) {
HAPAssert(err == kHAPError_Unknown);
return err;
}
}
// BLE: Reset Broadcast Encryption Key.
// See HomeKit Accessory Protocol Specification R14
// Section 7.4.7.4 Broadcast Encryption Key expiration and refresh
if (server->transports.ble) {
err = HAPNonnull(server->transports.ble)->broadcast.expireKey(keyValueStore);
if (err) {
HAPAssert(err == kHAPError_Unknown);
return err;
}
}
return kHAPError_None;
}