The response has been limited to 50k tokens of the smallest files in the repo. You can remove this limitation by removing the max tokens filter.
├── .clang-format
├── .dockerignore
├── .github
    └── workflows
    │   ├── linter.yml
    │   ├── linux-ci.yml
    │   └── no-docker-linux-ci.yml
├── .gitignore
├── Applications
    ├── Lightbulb
    │   ├── App.c
    │   ├── App.h
    │   ├── DB.c
    │   ├── DB.h
    │   └── Main.c
    ├── Lock
    │   ├── App.c
    │   ├── App.h
    │   ├── DB.c
    │   ├── DB.h
    │   └── Main.c
    └── Main.c
├── Build
    ├── Docker
    │   ├── Dockerfile
    │   └── Dockerfile.Raspi
    ├── Makefile
    ├── Makefile.Darwin
    ├── Makefile.Linux
    └── Makefile.Raspi
├── CODE_OF_CONDUCT.md
├── CONTRIBUTING.md
├── CONTRIBUTORS.md
├── Documentation
    ├── coding_convention.md
    ├── conf.py
    ├── crypto.md
    ├── darwin_visual_debug.md
    ├── getting_started.md
    └── index.rst
├── External
    ├── Base64
    │   ├── util_base64.c
    │   └── util_base64.h
    ├── HTTP
    │   ├── util_http_reader.c
    │   └── util_http_reader.h
    └── JSON
    │   ├── util_json_reader.c
    │   └── util_json_reader.h
├── HAP
    ├── HAP+Internal.h
    ├── HAP+KeyValueStoreDomains.h
    ├── HAP.h
    ├── HAPAccessory+Info.c
    ├── HAPAccessory+Info.h
    ├── HAPAccessoryServer+Internal.h
    ├── HAPAccessoryServer+Reset.c
    ├── HAPAccessoryServer.c
    ├── HAPAccessorySetup.c
    ├── HAPAccessorySetup.h
    ├── HAPAccessorySetupInfo.c
    ├── HAPAccessorySetupInfo.h
    ├── HAPAccessoryValidation.c
    ├── HAPAccessoryValidation.h
    ├── HAPBLEAccessoryServer+Advertising.c
    ├── HAPBLEAccessoryServer+Advertising.h
    ├── HAPBLEAccessoryServer+Broadcast.c
    ├── HAPBLEAccessoryServer+Broadcast.h
    ├── HAPBLEAccessoryServer.c
    ├── HAPBLEAccessoryServer.h
    ├── HAPBLECharacteristic+Broadcast.c
    ├── HAPBLECharacteristic+Broadcast.h
    ├── HAPBLECharacteristic+Configuration.c
    ├── HAPBLECharacteristic+Configuration.h
    ├── HAPBLECharacteristic+Signature.c
    ├── HAPBLECharacteristic+Signature.h
    ├── HAPBLECharacteristic+Value.h
    ├── HAPBLECharacteristic.c
    ├── HAPBLECharacteristic.h
    ├── HAPBLECharacteristicParseAndWriteValue.c
    ├── HAPBLECharacteristicReadAndSerializeValue.c
    ├── HAPBLEPDU+TLV.c
    ├── HAPBLEPDU+TLV.h
    ├── HAPBLEPDU.c
    ├── HAPBLEPDU.h
    ├── HAPBLEPeripheralManager.c
    ├── HAPBLEPeripheralManager.h
    ├── HAPBLEProcedure.c
    ├── HAPBLEProcedure.h
    ├── HAPBLEProtocol+Configuration.c
    ├── HAPBLEProtocol+Configuration.h
    ├── HAPBLEService+Signature.c
    ├── HAPBLEService+Signature.h
    ├── HAPBLESession.c
    ├── HAPBLESession.h
    ├── HAPBLETransaction.c
    ├── HAPBLETransaction.h
    ├── HAPBitSet.c
    ├── HAPBitSet.h
    ├── HAPCharacteristic.c
    ├── HAPCharacteristic.h
    ├── HAPCharacteristicTypes+TLV.h
    ├── HAPCharacteristicTypes.c
    ├── HAPCharacteristicTypes.h
    ├── HAPDeviceID.c
    ├── HAPDeviceID.h
    ├── HAPIP+ByteBuffer.c
    ├── HAPIP+ByteBuffer.h
    ├── HAPIPAccessory.c
    ├── HAPIPAccessory.h
    ├── HAPIPAccessoryProtocol.c
    ├── HAPIPAccessoryProtocol.h
    ├── HAPIPAccessoryServer.c
    ├── HAPIPAccessoryServer.h
    ├── HAPIPCharacteristic.c
    ├── HAPIPCharacteristic.h
    ├── HAPIPSecurityProtocol.c
    ├── HAPIPSecurityProtocol.h
    ├── HAPIPServiceDiscovery.c
    ├── HAPIPServiceDiscovery.h
    ├── HAPIPSession.h
    ├── HAPJSONUtils.c
    ├── HAPJSONUtils.h
    ├── HAPLegacyImport.c
    ├── HAPLegacyImport.h
    ├── HAPLog+Attributes.h
    ├── HAPMACAddress.c
    ├── HAPMACAddress.h
    ├── HAPMFiAuth.h
    ├── HAPMFiHWAuth+Types.h
    ├── HAPMFiHWAuth.c
    ├── HAPMFiHWAuth.h
    ├── HAPMFiTokenAuth.c
    ├── HAPMFiTokenAuth.h
    ├── HAPPDU.c
    ├── HAPPDU.h
    ├── HAPPairing.c
    ├── HAPPairing.h
    ├── HAPPairingBLESessionCache.c
    ├── HAPPairingBLESessionCache.h
    ├── HAPPairingPairSetup.c
    ├── HAPPairingPairSetup.h
    ├── HAPPairingPairVerify.c
    ├── HAPPairingPairVerify.h
    ├── HAPPairingPairings.c
    ├── HAPPairingPairings.h
    ├── HAPRequestHandlers+AccessoryInformation.c
    ├── HAPRequestHandlers+AccessoryInformation.h
    ├── HAPRequestHandlers+HAPProtocolInformation.c
    ├── HAPRequestHandlers+HAPProtocolInformation.h
    ├── HAPRequestHandlers+Pairing.c
    ├── HAPRequestHandlers+Pairing.h
    ├── HAPRequestHandlers.c
    ├── HAPRequestHandlers.h
    ├── HAPServiceTypes.c
    ├── HAPServiceTypes.h
    ├── HAPSession.c
    ├── HAPSession.h
    ├── HAPStringBuilder.c
    ├── HAPStringBuilder.h
    ├── HAPTLV+Internal.h
    ├── HAPTLV.c
    ├── HAPTLVMemory.c
    ├── HAPTLVReader.c
    ├── HAPTLVWriter.c
    ├── HAPUUID.c
    ├── HAPUUID.h
    └── HAPVersion.c
├── LICENSE.md
├── Makefile
├── PAL
    ├── Crypto
    │   ├── MbedTLS
    │   │   ├── Ed25519
    │   │   │   ├── BaseTypes.h
    │   │   │   ├── LICENSE
    │   │   │   ├── apple.h
    │   │   │   ├── base_folding8.h
    │   │   │   ├── curve25519_mehdi.c
    │   │   │   ├── curve25519_mehdi.h
    │   │   │   ├── curve25519_order.c
    │   │   │   ├── curve25519_utils.c
    │   │   │   ├── ed25519_sign.c
    │   │   │   ├── ed25519_signature.h
    │   │   │   └── ed25519_verify.c
    │   │   └── HAPMbedTLS.c
    │   └── OpenSSL
    │   │   └── HAPOpenSSL.c
    ├── Darwin
    │   ├── HAPPlatform+Init.h
    │   ├── HAPPlatform.m
    │   ├── HAPPlatformAbort.m
    │   ├── HAPPlatformAccessorySetup+Init.h
    │   ├── HAPPlatformAccessorySetup.m
    │   ├── HAPPlatformAccessorySetupDisplay.m
    │   ├── HAPPlatformAccessorySetupNFC.m
    │   ├── HAPPlatformBLEPeripheralManager+Init.h
    │   ├── HAPPlatformBLEPeripheralManager.m
    │   ├── HAPPlatformClock.m
    │   ├── HAPPlatformKeyValueStore+Init.h
    │   ├── HAPPlatformKeyValueStore+SDKDomains.h
    │   ├── HAPPlatformKeyValueStore.m
    │   ├── HAPPlatformLog+Init.h
    │   ├── HAPPlatformLog.m
    │   ├── HAPPlatformMFiHWAuth+Init.h
    │   ├── HAPPlatformMFiHWAuth.m
    │   ├── HAPPlatformMFiTokenAuth+Init.h
    │   ├── HAPPlatformMFiTokenAuth.m
    │   ├── HAPPlatformRandomNumber.m
    │   ├── HAPPlatformRunLoop+Init.h
    │   ├── HAPPlatformRunLoop.m
    │   ├── HAPPlatformServiceDiscovery+Init.h
    │   ├── HAPPlatformServiceDiscovery.m
    │   ├── HAPPlatformTCPStreamManager+Init.h
    │   ├── HAPPlatformTCPStreamManager.m
    │   └── HAPPlatformTimer.m
    ├── HAPAssert.c
    ├── HAPAssert.h
    ├── HAPBase+CompilerAbstraction.h
    ├── HAPBase+Crypto.c
    ├── HAPBase+Double.c
    ├── HAPBase+Float.c
    ├── HAPBase+Int.c
    ├── HAPBase+MACAddress.c
    ├── HAPBase+RawBuffer.c
    ├── HAPBase+Sha1Checksum.c
    ├── HAPBase+String.c
    ├── HAPBase+UTF8.c
    ├── HAPBase.h
    ├── HAPCrypto.h
    ├── HAPLog.c
    ├── HAPLog.h
    ├── HAPPlatform.h
    ├── HAPPlatformAbort.h
    ├── HAPPlatformAccessorySetup.h
    ├── HAPPlatformAccessorySetupDisplay.h
    ├── HAPPlatformAccessorySetupNFC.h
    ├── HAPPlatformBLEPeripheralManager.h
    ├── HAPPlatformClock.h
    ├── HAPPlatformKeyValueStore.h
    ├── HAPPlatformLog.h
    ├── HAPPlatformMFiHWAuth.h
    ├── HAPPlatformMFiTokenAuth.h
    ├── HAPPlatformRandomNumber.h
    ├── HAPPlatformRunLoop.h
    ├── HAPPlatformServiceDiscovery.h
    ├── HAPPlatformSystemInit.c
    ├── HAPPlatformTCPStreamManager.h
    ├── HAPPlatformTimer.h
    ├── Linux
    ├── Mock
    │   ├── HAPPlatform+Init.h
    │   ├── HAPPlatform.c
    │   ├── HAPPlatformAbort.c
    │   ├── HAPPlatformAccessorySetup+Init.h
    │   ├── HAPPlatformAccessorySetup.c
    │   ├── HAPPlatformAccessorySetupDisplay.c
    │   ├── HAPPlatformAccessorySetupNFC.c
    │   ├── HAPPlatformBLEPeripheralManager+Init.h
    │   ├── HAPPlatformBLEPeripheralManager+Test.h
    │   ├── HAPPlatformBLEPeripheralManager.c
    │   ├── HAPPlatformClock+Test.h
    │   ├── HAPPlatformClock.c
    │   ├── HAPPlatformKeyValueStore+Init.h
    │   ├── HAPPlatformKeyValueStore.c
    │   ├── HAPPlatformLog.c
    │   ├── HAPPlatformMFiHWAuth+Init.h
    │   ├── HAPPlatformMFiHWAuth.c
    │   ├── HAPPlatformMFiTokenAuth+Init.h
    │   ├── HAPPlatformMFiTokenAuth.c
    │   ├── HAPPlatformRandomNumber.c
    │   ├── HAPPlatformRunLoop.c
    │   ├── HAPPlatformServiceDiscovery+Init.h
    │   ├── HAPPlatformServiceDiscovery+Test.h
    │   ├── HAPPlatformServiceDiscovery.c
    │   ├── HAPPlatformStartup.S
    │   ├── HAPPlatformSystemCommand.c
    │   ├── HAPPlatformSystemCommand.h
    │   ├── HAPPlatformTCPStreamManager+Init.h
    │   ├── HAPPlatformTCPStreamManager+Test.h
    │   ├── HAPPlatformTCPStreamManager.c
    │   ├── HAPPlatformTimer+Init.h
    │   └── HAPPlatformTimer.c
    ├── POSIX
    │   ├── HAPPlatform+Init.h
    │   ├── HAPPlatform.c
    │   ├── HAPPlatformAbort.c
    │   ├── HAPPlatformAccessorySetup+Init.h
    │   ├── HAPPlatformAccessorySetup.c
    │   ├── HAPPlatformAccessorySetupDisplay+Init.h
    │   ├── HAPPlatformAccessorySetupDisplay.c
    │   ├── HAPPlatformAccessorySetupNFC+Init.h
    │   ├── HAPPlatformAccessorySetupNFC.c
    │   ├── HAPPlatformBLEPeripheralManager+Init.h
    │   ├── HAPPlatformBLEPeripheralManager.c
    │   ├── HAPPlatformClock.c
    │   ├── HAPPlatformFileHandle.h
    │   ├── HAPPlatformFileManager.c
    │   ├── HAPPlatformFileManager.h
    │   ├── HAPPlatformKeyValueStore+Init.h
    │   ├── HAPPlatformKeyValueStore+SDKDomains.h
    │   ├── HAPPlatformKeyValueStore.c
    │   ├── HAPPlatformLog+Init.h
    │   ├── HAPPlatformLog.c
    │   ├── HAPPlatformMFiHWAuth+Init.h
    │   ├── HAPPlatformMFiHWAuth.c
    │   ├── HAPPlatformMFiTokenAuth+Init.h
    │   ├── HAPPlatformMFiTokenAuth.c
    │   ├── HAPPlatformRandomNumber.c
    │   ├── HAPPlatformRunLoop+Init.h
    │   ├── HAPPlatformRunLoop.c
    │   ├── HAPPlatformServiceDiscovery+Init.h
    │   ├── HAPPlatformServiceDiscovery.c
    │   ├── HAPPlatformSystemCommand.c
    │   ├── HAPPlatformSystemCommand.h
    │   ├── HAPPlatformTCPStreamManager+Init.h
    │   └── HAPPlatformTCPStreamManager.c
    └── Raspi
├── README.md
├── Tests
    ├── HAPAccessorySetupGetSetupHashTest.c
    ├── HAPAccessorySetupGetSetupPayloadTest.c
    ├── HAPAccessorySetupTest.c
    ├── HAPBLEEventTest.c
    ├── HAPBLETransactionParseRequestTest.c
    ├── HAPBase+FloatTests.c
    ├── HAPBase+IntTests.c
    ├── HAPBase+StringTests.c
    ├── HAPCryptoTest.c
    ├── HAPExhaustiveUTF8Test.c
    ├── HAPIPAccessoryProtocolReadCharacteristicWriteRequestsTest.c
    ├── HAPIPAccessoryProtocolReadPrepareWriteRequestTest.c
    ├── HAPIPAccessoryProtocolReadStringCharacteristicWriteRequestsTest.c
    ├── HAPIPAccessoryProtocolSerializeCharacteristicReadResponseTest.c
    ├── HAPIPAccessoryProtocolSerializeStringCharacteristicReadResponseTest.c
    ├── HAPImportTest.c
    ├── HAPJSONUtilsTest.c
    ├── HAPPlatformSystemCommandTest.c
    ├── HAPTLVTest.c
    ├── HAPUTF8Test.c
    ├── HAPUUIDTest.c
    ├── Harness
    │   ├── HAPTestController.c
    │   ├── HAPTestController.h
    │   ├── TemplateDB.c
    │   └── TemplateDB.h
    └── util_base64_test.c
└── Tools
    ├── AccessorySetupGenerator
        └── Main.c
    ├── download.sh
    ├── generate_api_doc.sh
    ├── install.sh
    ├── linters
        ├── clint.sh
        ├── git-hooks-pre-commit
        ├── lint.sh
        └── shlint.sh
    ├── provision_raspi.sh
    ├── raspi_docker_import.sh
    └── raspi_sdcard_setup.sh


/.clang-format:
--------------------------------------------------------------------------------
 1 | BasedOnStyle: WebKit
 2 | 
 3 | # Indentation
 4 | ContinuationIndentWidth: 8
 5 | IndentCaseLabels: true
 6 | IndentPPDirectives: None
 7 | IndentWidth: 4
 8 | TabWidth: 4
 9 | UseTab: Never
10 | TypenameMacros:
11 |   - HAP_ENUM_BEGIN
12 |   - HAP_ENUM_END
13 | 
14 | AlignAfterOpenBracket: AlwaysBreak
15 | AlignConsecutiveMacros: true
16 | AlignEscapedNewlines: DontAlign
17 | AlignOperands: true
18 | AlignTrailingComments: true
19 | AllowAllParametersOfDeclarationOnNextLine: false
20 | AllowShortIfStatementsOnASingleLine: false
21 | AllowShortFunctionsOnASingleLine: false
22 | AllowShortLoopsOnASingleLine: false
23 | AlwaysBreakAfterReturnType: None
24 | AlwaysBreakBeforeMultilineStrings: true
25 | BreakBeforeBraces: Attach
26 | BreakBeforeBinaryOperators: None
27 | BreakBeforeTernaryOperators: false
28 | BinPackParameters: false
29 | BinPackArguments: false
30 | ColumnLimit: 120
31 | IndentWrappedFunctionNames: true
32 | MaxEmptyLinesToKeep: 1
33 | ObjCBlockIndentWidth: 4
34 | ObjCSpaceAfterProperty: true
35 | ObjCSpaceBeforeProtocolList: false
36 | PointerAlignment: Left
37 | SortIncludes: false
38 | SpaceAfterCStyleCast: true
39 | SpacesBeforeTrailingComments: 1
40 | SpacesInContainerLiterals: false
41 | 


--------------------------------------------------------------------------------
/.dockerignore:
--------------------------------------------------------------------------------
 1 | # Git related
 2 | .git
 3 | 
 4 | # Build generated
 5 | Output/
 6 | Services/
 7 | 
 8 | # Temp directories
 9 | tmp/
10 | **/.cache/
11 | 


--------------------------------------------------------------------------------
/.github/workflows/linter.yml:
--------------------------------------------------------------------------------
 1 | name: Lint code
 2 | 
 3 | on: pull_request
 4 | 
 5 | jobs:
 6 |   linter:
 7 |     runs-on: ubuntu-18.04
 8 |     steps:
 9 |       - name: Checkout code
10 |         uses: actions/checkout@v1
11 | 
12 |       - name: Lint shell scripts
13 |         run: ./Tools/linters/shlint.sh
14 |         
15 |       - name: Lint source code
16 |         run: ./Tools/linters/clint.sh
17 | 


--------------------------------------------------------------------------------
/.github/workflows/linux-ci.yml:
--------------------------------------------------------------------------------
 1 | name: Linux CI
 2 | 
 3 | on: pull_request
 4 | 
 5 | jobs:
 6 |   linux-unit-test:
 7 |     runs-on: ubuntu-18.04
 8 | 
 9 |     steps:
10 |       - name: Checkout code
11 |         uses: actions/checkout@v1
12 | 
13 |       - name: Linux debug build
14 |         run: make TARGET=Linux all
15 |         
16 |       - name: Linux release build
17 |         run: make TARGET=Linux BUILD_TYPE=Release all
18 | 


--------------------------------------------------------------------------------
/.github/workflows/no-docker-linux-ci.yml:
--------------------------------------------------------------------------------
 1 | name: Linux CI (No Docker)
 2 | 
 3 | on: pull_request
 4 | 
 5 | jobs:
 6 |   docker-unit-test:
 7 |     runs-on: ubuntu-18.04
 8 | 
 9 |     steps:
10 |       - name: Checkout code
11 |         uses: actions/checkout@v1
12 | 
13 |       - name: Installing dependencies
14 |         # These were taken from Build/Docker/Dockerfile
15 |         run: |
16 |           sudo apt-get update
17 |           sudo apt-get install -y \
18 |             clang \
19 |             libavahi-compat-libdnssd-dev \
20 |             libssl-dev \
21 |             make
22 |           sudo apt-get clean
23 |           sudo rm -rf /var/lib/apt/lists/*
24 | 
25 |       - name: Linux debug build
26 |         run: make TARGET=Linux DOCKER=0 all
27 |         
28 |       - name: Linux release build
29 |         run: make TARGET=Linux DOCKER=0 BUILD_TYPE=Release all
30 | 


--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
 1 | ## Build generated
 2 | Output/
 3 | 
 4 | # Exclude .DS_Store
 5 | .DS_Store
 6 | 
 7 | # VIM temporary files
 8 | *.swp
 9 | *.swo
10 | *.tags*
11 | 
12 | # Pycharm temporary files
13 | .idea/
14 | 
15 | .HomeKitStore
16 | 
17 | # Open source export
18 | export/
19 | 
20 | # Documentation related
21 | Documentation/_api_docs/
22 | Documentation/api_docs/
23 | 


--------------------------------------------------------------------------------
/Applications/Lightbulb/App.h:
--------------------------------------------------------------------------------
  1 | // Copyright (c) 2015-2019 The HomeKit ADK Contributors
  2 | //
  3 | // Licensed under the Apache License, Version 2.0 (the “License”);
  4 | // you may not use this file except in compliance with the License.
  5 | // See [CONTRIBUTORS.md] for the list of HomeKit ADK project authors.
  6 | 
  7 | // The most basic HomeKit example: an accessory that represents a light bulb that
  8 | // only supports switching the light on and off. Actions are exposed as individual
  9 | // functions below.
 10 | //
 11 | // This header file is platform-independent.
 12 | 
 13 | #ifndef APP_H
 14 | #define APP_H
 15 | 
 16 | #ifdef __cplusplus
 17 | extern "C" {
 18 | #endif
 19 | 
 20 | #include "HAP.h"
 21 | 
 22 | #if __has_feature(nullability)
 23 | #pragma clang assume_nonnull begin
 24 | #endif
 25 | 
 26 | /**
 27 |  * Identify routine. Used to locate the accessory.
 28 |  */
 29 | HAP_RESULT_USE_CHECK
 30 | HAPError IdentifyAccessory(
 31 |         HAPAccessoryServerRef* server,
 32 |         const HAPAccessoryIdentifyRequest* request,
 33 |         void* _Nullable context);
 34 | 
 35 | /**
 36 |  * Handle read request to the 'On' characteristic of the Light Bulb service.
 37 |  */
 38 | HAP_RESULT_USE_CHECK
 39 | HAPError HandleLightBulbOnRead(
 40 |         HAPAccessoryServerRef* server,
 41 |         const HAPBoolCharacteristicReadRequest* request,
 42 |         bool* value,
 43 |         void* _Nullable context);
 44 | 
 45 | /**
 46 |  * Handle write request to the 'On' characteristic of the Light Bulb service.
 47 |  */
 48 | HAP_RESULT_USE_CHECK
 49 | HAPError HandleLightBulbOnWrite(
 50 |         HAPAccessoryServerRef* server,
 51 |         const HAPBoolCharacteristicWriteRequest* request,
 52 |         bool value,
 53 |         void* _Nullable context);
 54 | 
 55 | /**
 56 |  * Initialize the application.
 57 |  */
 58 | void AppCreate(HAPAccessoryServerRef* server, HAPPlatformKeyValueStoreRef keyValueStore);
 59 | 
 60 | /**
 61 |  * Deinitialize the application.
 62 |  */
 63 | void AppRelease(void);
 64 | 
 65 | /**
 66 |  * Start the accessory server for the app.
 67 |  */
 68 | void AppAccessoryServerStart(void);
 69 | 
 70 | /**
 71 |  * Handle the updated state of the Accessory Server.
 72 |  */
 73 | void AccessoryServerHandleUpdatedState(HAPAccessoryServerRef* server, void* _Nullable context);
 74 | 
 75 | void AccessoryServerHandleSessionAccept(HAPAccessoryServerRef* server, HAPSessionRef* session, void* _Nullable context);
 76 | 
 77 | void AccessoryServerHandleSessionInvalidate(
 78 |         HAPAccessoryServerRef* server,
 79 |         HAPSessionRef* session,
 80 |         void* _Nullable context);
 81 | 
 82 | /**
 83 |  * Restore platform specific factory settings.
 84 |  */
 85 | void RestorePlatformFactorySettings(void);
 86 | 
 87 | /**
 88 |  * Returns pointer to accessory information
 89 |  */
 90 | const HAPAccessory* AppGetAccessoryInfo();
 91 | 
 92 | #if __has_feature(nullability)
 93 | #pragma clang assume_nonnull end
 94 | #endif
 95 | 
 96 | #ifdef __cplusplus
 97 | }
 98 | #endif
 99 | 
100 | #endif
101 | 


--------------------------------------------------------------------------------
/Applications/Lightbulb/DB.h:
--------------------------------------------------------------------------------
 1 | // Copyright (c) 2015-2019 The HomeKit ADK Contributors
 2 | //
 3 | // Licensed under the Apache License, Version 2.0 (the “License”);
 4 | // you may not use this file except in compliance with the License.
 5 | // See [CONTRIBUTORS.md] for the list of HomeKit ADK project authors.
 6 | 
 7 | // Basic light bulb database example. This header file, and the corresponding DB.c implementation in the ADK, is
 8 | // platform-independent.
 9 | 
10 | #ifndef DB_H
11 | #define DB_H
12 | 
13 | #ifdef __cplusplus
14 | extern "C" {
15 | #endif
16 | 
17 | #include "HAP.h"
18 | 
19 | #if __has_feature(nullability)
20 | #pragma clang assume_nonnull begin
21 | #endif
22 | 
23 | /**
24 |  * Total number of services and characteristics contained in the accessory.
25 |  */
26 | #define kAttributeCount ((size_t) 21)
27 | 
28 | /**
29 |  * HomeKit Accessory Information service.
30 |  */
31 | extern const HAPService accessoryInformationService;
32 | 
33 | /**
34 |  * Characteristics to expose accessory information and configuration (associated with Accessory Information service).
35 |  */
36 | extern const HAPBoolCharacteristic accessoryInformationIdentifyCharacteristic;
37 | extern const HAPStringCharacteristic accessoryInformationManufacturerCharacteristic;
38 | extern const HAPStringCharacteristic accessoryInformationModelCharacteristic;
39 | extern const HAPStringCharacteristic accessoryInformationNameCharacteristic;
40 | extern const HAPStringCharacteristic accessoryInformationSerialNumberCharacteristic;
41 | extern const HAPStringCharacteristic accessoryInformationFirmwareRevisionCharacteristic;
42 | extern const HAPStringCharacteristic accessoryInformationHardwareRevisionCharacteristic;
43 | extern const HAPStringCharacteristic accessoryInformationADKVersionCharacteristic;
44 | 
45 | /**
46 |  * HAP Protocol Information service.
47 |  */
48 | extern const HAPService hapProtocolInformationService;
49 | 
50 | /**
51 |  * Pairing service.
52 |  */
53 | extern const HAPService pairingService;
54 | 
55 | /**
56 |  * Light Bulb service.
57 |  */
58 | extern const HAPService lightBulbService;
59 | 
60 | /**
61 |  * The 'On' characteristic of the Light Bulb service.
62 |  */
63 | extern const HAPBoolCharacteristic lightBulbOnCharacteristic;
64 | 
65 | #if __has_feature(nullability)
66 | #pragma clang assume_nonnull end
67 | #endif
68 | 
69 | #ifdef __cplusplus
70 | }
71 | #endif
72 | 
73 | #endif
74 | 


--------------------------------------------------------------------------------
/Applications/Lightbulb/Main.c:
--------------------------------------------------------------------------------
1 | ../Main.c


--------------------------------------------------------------------------------
/Applications/Lock/Main.c:
--------------------------------------------------------------------------------
1 | ../Main.c


--------------------------------------------------------------------------------
/Build/Docker/Dockerfile:
--------------------------------------------------------------------------------
 1 | # Build stage
 2 | FROM ubuntu:18.04
 3 | 
 4 | RUN echo ========== Install dependencies ========== \
 5 |   && apt-get update && apt-get install -y \
 6 |     clang \
 7 |     gdb \
 8 |     git \
 9 |     libavahi-compat-libdnssd-dev \
10 |     libssl-dev \
11 |     make \
12 |     openssh-server \
13 |     perl \
14 |     unzip \
15 |     wget \
16 |   && apt-get clean \
17 |   && rm -rf /var/lib/apt/lists/*
18 | 
19 | WORKDIR /build
20 | 


--------------------------------------------------------------------------------
/Build/Docker/Dockerfile.Raspi:
--------------------------------------------------------------------------------
1 | # Build stage
2 | FROM dev-test/raspiadk-base as build
3 | 
4 | WORKDIR /build
5 | 
6 | # Only package the build image. The built image won't have any test artifacts in it
7 | FROM build
8 | 


--------------------------------------------------------------------------------
/Build/Makefile.Darwin:
--------------------------------------------------------------------------------
 1 | TARGET_FLAVOR ?= macosx
 2 | 
 3 | XCODE_SDK_macosx := macosx
 4 | XCODE_TOOLCHAIN_macosx := XcodeDefault
 5 | CFLAGS_macosx := -mmacosx-version-min=10.14
 6 | 
 7 | XCODE_SDK_ios := iphoneos13.0.internal
 8 | XCODE_TOOLCHAIN_ios := iOS13.0
 9 | CFLAGS_ios := -arch arm64 -mios-version-min=13.0
10 | 
11 | XCODE_SDK := $(XCODE_SDK_$(TARGET_FLAVOR))
12 | 
13 | XCODE_RUN := xcrun --sdk $(XCODE_SDK) --toolchain $(XCODE_TOOLCHAIN_$(TARGET_FLAVOR))
14 | XCODE_SDK_PATH := $(shell $(XCODE_RUN) --show-sdk-path)
15 | 
16 | CC := $(shell $(XCODE_RUN) -find clang)
17 | AR := ar
18 | COMPILER := $(shell $(CC) -dumpmachine)
19 | DEBUGGER := lldb
20 | 
21 | SRC_DIRS_Darwin := PAL/Darwin Common
22 | CRYPTO_Darwin := PAL/Crypto/OpenSSL PAL/Crypto/MbedTLS
23 | 
24 | CFLAGS_m := -fobjc-arc -Wno-ignored-attributes -Wno-unguarded-availability-new -Wno-availability -Wunused-function -Wno-error=missing-method-return-type -Wno-error=unused-parameter
25 | CFLAGS_Darwin := $(CFLAGS_$(TARGET_FLAVOR)) $(CFLAGS_BLE) $(CFLAGS_IP)
26 | CFLAGS_Darwin += -DDARWIN=1 -Werror=unused-function
27 | CFLAGS_Darwin += -Wno-expansion-to-defined -Wno-nullability-completeness -Wno-deprecated-declarations
28 | CFLAGS_Darwin += -isysroot $(XCODE_SDK_PATH)
29 | LDFLAGS_Darwin := $(addprefix -framework ,Foundation CoreBluetooth Network CoreGraphics ImageIO CoreServices)
30 | ifeq ($(BUILD_TYPE),Release)
31 |     LDFLAGS_Darwin += -dead_strip
32 | endif
33 | 
34 | EXCLUDE_Darwin := \
35 |     Tests/HAPPlatformSystemCommandTest.c \
36 |     PAL/Mock/HAPPlatformSystemCommand.c
37 | 
38 | SKIPPED_TESTS_Darwin := HAPExhaustiveUTF8Test
39 | 
40 | PROTOCOLS_Darwin := IP BLE
41 | 


--------------------------------------------------------------------------------
/Build/Makefile.Linux:
--------------------------------------------------------------------------------
 1 | 
 2 | CC := clang
 3 | AR := ar
 4 | COMPILER := $(shell $(CC) -dumpmachine)
 5 | DEBUGGER := gdb
 6 | 
 7 | SRC_DIRS_Linux := PAL/Linux
 8 | CRYPTO_Linux := PAL/Crypto/OpenSSL
 9 | 
10 | CFLAGS_Linux := $(CFLAGS_IP) -ffunction-sections -fdata-sections
11 | LDFLAGS_Linux := -ldns_sd -pthread -lm
12 | ifeq ($(BUILD_TYPE),Release)
13 |     LDFLAGS_Linux += -Wl,--gc-sections -Wl,--as-needed -Wl,--strip-all
14 | endif
15 | 
16 | LINK_BEGIN_Linux := -Wl,--start-group
17 | LINK_END_Linux := -Wl,--end-group
18 | 
19 | EXCLUDE_Linux := Applications/LightbulbLED
20 | 
21 | SKIPPED_TESTS_Linux := HAPExhaustiveUTF8Test
22 | 
23 | PROTOCOLS_Linux := IP
24 | 


--------------------------------------------------------------------------------
/Build/Makefile.Raspi:
--------------------------------------------------------------------------------
 1 | 
 2 | CC := clang
 3 | AR := ar
 4 | COMPILER := $(shell $(CC) -dumpmachine)
 5 | DEBUGGER := gdb
 6 | 
 7 | SRC_DIRS_Raspi := PAL/Raspi
 8 | CRYPTO_Raspi := PAL/Crypto/OpenSSL
 9 | 
10 | CFLAGS_Raspi := $(CFLAGS_IP) -ffunction-sections -fdata-sections
11 | CFLAGS_Raspi += -DLED_PORT=\"/sys/class/leds/led0/brightness\"
12 | CFLAGS_Raspi += -DLED_TRIGGER=\"/sys/class/leds/led0/trigger\"
13 | 
14 | CFLAGS_Raspi += -DRPI
15 | CFLAGS_Raspi += -I/opt/vc/include
16 | 
17 | LDFLAGS_Raspi := -L/opt/vc/lib
18 | LDFLAGS_Raspi += -ldns_sd -lsqlite3 -pthread -lasound -lopus -lfaac -lm -lnfc
19 | LDFLAGS_Raspi += -lbcm_host -lmmal -lmmal_core -lmmal_components -lmmal_util -lvcos
20 | ifeq ($(BUILD_TYPE),Release)
21 |     LDFLAGS_Raspi += -Wl,--gc-sections -Wl,--as-needed -Wl,--strip-all
22 | endif
23 | 
24 | LINK_BEGIN_Raspi := -Wl,--start-group
25 | LINK_END_Raspi := -Wl,--end-group
26 | 
27 | SKIPPED_TESTS_Raspi := HAPExhaustiveUTF8Test
28 | 
29 | PROTOCOLS_Raspi := IP
30 | 


--------------------------------------------------------------------------------
/CONTRIBUTING.md:
--------------------------------------------------------------------------------
1 | By submitting a pull request, you represent that you have the right to license your contribution to Apple and the
2 | community, and agree by submitting the patch that your contributions are licensed under the
3 | [Apache 2.0 license](./LICENSE.md).
4 | 
5 | Before submitting the pull request, please make sure you have tested your changes and that they follow the project
6 | [guidelines for contributing code](./Documentation/coding_convention.md).
7 | 


--------------------------------------------------------------------------------
/CONTRIBUTORS.md:
--------------------------------------------------------------------------------
1 | The following organizations and individuals have contributed to the HomeKit ADK:
2 | * Oberon microsystems AG
3 | * Apple Inc.
4 | 


--------------------------------------------------------------------------------
/Documentation/darwin_visual_debug.md:
--------------------------------------------------------------------------------
 1 | # Debugging on Darwin using visual debugger
 2 | 
 3 | ## Using Visual Studio Code
 4 | 
 5 | ### Installation
 6 | * Download VSCode: https://code.visualstudio.com/
 7 | 
 8 | * To install c/c++ language support: within VSCode press ⌘+p and enter
 9 | ```
10 | ext install ms-vscode.cpptools
11 | ```
12 | 
13 | * To install debugger: within VSCode, press ⌘+p and enter
14 | ```
15 | ext install vadimcn.vscode-lldb
16 | ```
17 | * Note: an alternative debugger is necessary because llvm no longer includes lldb-mi which the default debugger uses.
18 | 
19 | 
20 | ### Running an application
21 | * Create a workspace which points to the root of your ADK folder.
22 | * Click "Debug" > "Open Configuration", which will open the launch.json file.
23 | * Set "type" to "lldb"
24 | * Set "program" to the application you want to run.
25 | 
26 | Example launch.json file for Lightbulb app:
27 | ```
28 | {
29 |     "version": "0.2.0",
30 |     "configurations": [
31 |         {
32 |             "type": "lldb",
33 |             "request": "launch",
34 |             "name": "Debug",
35 |             "program": "${workspaceFolder}/Output/Darwin-x86_64-apple-darwin19.0.0/Debug/IP/Applications/Lightbulb.OpenSSL",
36 |             "args": [],
37 |             "cwd": "${workspaceFolder}"
38 |         }
39 |     ]
40 | }
41 | ```
42 | 


--------------------------------------------------------------------------------
/Documentation/index.rst:
--------------------------------------------------------------------------------
 1 | HomeKit ADK
 2 | ========================================================================================
 3 | The HomeKit ADK is used by silicon vendors and accessory manufacturers to build HomeKit compatible devices.
 4 | 
 5 | The HomeKit ADK implements key components of the HomeKit Accessory Protocol (HAP), which embodies the core principles
 6 | Apple brings to smart home technology: security, privacy, and reliability.
 7 | 
 8 | .. toctree::
 9 |    :maxdepth: 2
10 | 
11 |    getting_started.md
12 |    crypto.md
13 |    coding_convention.md
14 |    _api_docs/pal_api_root
15 | 


--------------------------------------------------------------------------------
/External/Base64/util_base64.h:
--------------------------------------------------------------------------------
 1 | // Copyright (c) 2015-2019 The HomeKit ADK Contributors
 2 | //
 3 | // Licensed under the Apache License, Version 2.0 (the “License”);
 4 | // you may not use this file except in compliance with the License.
 5 | // See [CONTRIBUTORS.md] for the list of HomeKit ADK project authors.
 6 | 
 7 | #ifndef UTIL_BASE64_H
 8 | #define UTIL_BASE64_H
 9 | 
10 | #include "HAPPlatform.h"
11 | 
12 | /**
13 |  * Returns the number of bytes necessary to store the base64 encoded data for a given data length.
14 |  * NULL terminator excluded.
15 |  *
16 |  * @param      data_len             Length of data before encoding.
17 |  *
18 |  * @return Number of bytes necessary to store the base64 encoded data for the given data length.
19 |  */
20 | #define util_base64_encoded_len(data_len) (((data_len) + 2) / 3 * 4)
21 | 
22 | /**
23 |  * Base64 encodes data @p p_data with length @p data_len into @p p_encoded with capacity @p encoded_capacity.
24 |  * Length of encoded data is put into @p p_encoded_len.
25 |  *
26 |  * @param      p_data               Data to encode.
27 |  * @param      data_len             Length of @p p_data.
28 |  * @param[out] p_encoded            Base64 encoded data.
29 |  * @param      encoded_capacity     Capacity of @p p_encoded. Must be at least 4/3 * @p data_len.
30 |  * @param[out] p_encoded_len        Effective length of @p p_encoded.
31 |  */
32 | void util_base64_encode(
33 |         const void* p_data,
34 |         size_t data_len,
35 |         char* p_encoded,
36 |         size_t encoded_capacity,
37 |         size_t* p_encoded_len);
38 | 
39 | /**
40 |  * Base64 decodes data @p p_encoded with length @p encoded_len into @p p_data with capacity @p data_capacity.
41 |  * Length of decoded data is put into @p p_data_len.
42 |  *
43 |  * @param      p_encoded            Data to decode.
44 |  * @param      encoded_len          Length of @p p_encoded.
45 |  * @param[out] p_data               Base64 decoded data.
46 |  * @param      data_capacity        Capacity of @p p_decoded. Maximum 3/4 * @p data_len is required for decoding.
47 |  * @param[out] p_data_len           Effective length of @p data_capacity.
48 |  *
49 |  * @return kHAPError_None           If successful.
50 |  * @return kHAPError_InvalidData    If @p p_encoded contains malformed data.
51 |  * @return kHAPError_OutOfResources If @p data_capacity is not large enough.
52 |  */
53 | HAP_RESULT_USE_CHECK
54 | HAPError util_base64_decode(
55 |         const char* p_encoded,
56 |         size_t encoded_len,
57 |         void* p_data,
58 |         size_t data_capacity,
59 |         size_t* p_data_len);
60 | 
61 | #endif
62 | 


--------------------------------------------------------------------------------
/External/HTTP/util_http_reader.h:
--------------------------------------------------------------------------------
 1 | // Copyright (c) 2015-2019 The HomeKit ADK Contributors
 2 | //
 3 | // Licensed under the Apache License, Version 2.0 (the “License”);
 4 | // you may not use this file except in compliance with the License.
 5 | // See [CONTRIBUTORS.md] for the list of HomeKit ADK project authors.
 6 | 
 7 | #ifndef UTIL_HTTP_READER_H
 8 | #define UTIL_HTTP_READER_H
 9 | 
10 | #include "HAPPlatform.h"
11 | 
12 | #define util_HTTP_READER_TYPE_REQUEST  0
13 | #define util_HTTP_READER_TYPE_RESPONSE 1
14 | 
15 | #define util_HTTP_READER_STATE_EXPECTING_METHOD 0
16 | #define util_HTTP_READER_STATE_READING_METHOD   1
17 | #define util_HTTP_READER_STATE_COMPLETED_METHOD 2
18 | 
19 | #define util_HTTP_READER_STATE_EXPECTING_URI 3
20 | #define util_HTTP_READER_STATE_READING_URI   4
21 | #define util_HTTP_READER_STATE_COMPLETED_URI 5
22 | 
23 | #define util_HTTP_READER_STATE_EXPECTING_VERSION 6
24 | #define util_HTTP_READER_STATE_READING_VERSION   7
25 | #define util_HTTP_READER_STATE_COMPLETED_VERSION 8
26 | 
27 | #define util_HTTP_READER_STATE_EXPECTING_STATUS 9
28 | #define util_HTTP_READER_STATE_READING_STATUS   10
29 | #define util_HTTP_READER_STATE_COMPLETED_STATUS 11
30 | 
31 | #define util_HTTP_READER_STATE_EXPECTING_REASON 12
32 | #define util_HTTP_READER_STATE_READING_REASON   13
33 | #define util_HTTP_READER_STATE_COMPLETED_REASON 14
34 | 
35 | #define util_HTTP_READER_STATE_EXPECTING_HEADER_NAME 15
36 | #define util_HTTP_READER_STATE_READING_HEADER_NAME   16
37 | #define util_HTTP_READER_STATE_COMPLETED_HEADER_NAME 17
38 | 
39 | #define util_HTTP_READER_STATE_EXPECTING_HEADER_VALUE 18
40 | #define util_HTTP_READER_STATE_READING_HEADER_VALUE   19
41 | #define util_HTTP_READER_STATE_COMPLETED_HEADER_VALUE 20
42 | 
43 | #define util_HTTP_READER_STATE_ENDING_HEADER_LINE  21
44 | #define util_HTTP_READER_STATE_ENDING_HEADER_LINES 22
45 | 
46 | #define util_HTTP_READER_STATE_DONE  23
47 | #define util_HTTP_READER_STATE_ERROR 24
48 | 
49 | struct util_http_reader {
50 |     int type;
51 |     int state;
52 |     int substate;
53 |     int in_quoted_pair;
54 |     int in_quoted_string;
55 |     char* result_token;
56 |     size_t result_length;
57 | };
58 | 
59 | void util_http_reader_init(struct util_http_reader* r, int type);
60 | HAP_RESULT_USE_CHECK
61 | size_t util_http_reader_read(struct util_http_reader* r, char* buffer, size_t length);
62 | 
63 | #endif
64 | 


--------------------------------------------------------------------------------
/External/JSON/util_json_reader.h:
--------------------------------------------------------------------------------
 1 | // Copyright (c) 2015-2019 The HomeKit ADK Contributors
 2 | //
 3 | // Licensed under the Apache License, Version 2.0 (the “License”);
 4 | // you may not use this file except in compliance with the License.
 5 | // See [CONTRIBUTORS.md] for the list of HomeKit ADK project authors.
 6 | 
 7 | #ifndef UTIL_JSON_READER_H
 8 | #define UTIL_JSON_READER_H
 9 | 
10 | #include "HAPPlatform.h"
11 | 
12 | #define util_JSON_READER_STATE_READING_WHITESPACE 0
13 | 
14 | #define util_JSON_READER_STATE_BEGINNING_OBJECT 1
15 | #define util_JSON_READER_STATE_COMPLETED_OBJECT 2
16 | 
17 | #define util_JSON_READER_STATE_BEGINNING_ARRAY 3
18 | #define util_JSON_READER_STATE_COMPLETED_ARRAY 4
19 | 
20 | #define util_JSON_READER_STATE_BEGINNING_NUMBER 5
21 | #define util_JSON_READER_STATE_READING_NUMBER   6
22 | #define util_JSON_READER_STATE_COMPLETED_NUMBER 7
23 | 
24 | #define util_JSON_READER_STATE_BEGINNING_STRING 8
25 | #define util_JSON_READER_STATE_READING_STRING   9
26 | #define util_JSON_READER_STATE_COMPLETED_STRING 10
27 | 
28 | #define util_JSON_READER_STATE_BEGINNING_FALSE 11
29 | #define util_JSON_READER_STATE_READING_FALSE   12
30 | #define util_JSON_READER_STATE_COMPLETED_FALSE 13
31 | 
32 | #define util_JSON_READER_STATE_BEGINNING_TRUE 14
33 | #define util_JSON_READER_STATE_READING_TRUE   15
34 | #define util_JSON_READER_STATE_COMPLETED_TRUE 16
35 | 
36 | #define util_JSON_READER_STATE_BEGINNING_NULL 17
37 | #define util_JSON_READER_STATE_READING_NULL   18
38 | #define util_JSON_READER_STATE_COMPLETED_NULL 19
39 | 
40 | #define util_JSON_READER_STATE_AFTER_NAME_SEPARATOR  20
41 | #define util_JSON_READER_STATE_AFTER_VALUE_SEPARATOR 21
42 | 
43 | #define util_JSON_READER_STATE_ERROR 22
44 | 
45 | struct util_json_reader {
46 |     int state;
47 |     int substate;
48 | };
49 | 
50 | void util_json_reader_init(struct util_json_reader* r);
51 | HAP_RESULT_USE_CHECK
52 | size_t util_json_reader_read(struct util_json_reader* r, const char* buffer, size_t length);
53 | 
54 | #endif
55 | 


--------------------------------------------------------------------------------
/HAP/HAP+Internal.h:
--------------------------------------------------------------------------------
  1 | // Copyright (c) 2015-2019 The HomeKit ADK Contributors
  2 | //
  3 | // Licensed under the Apache License, Version 2.0 (the “License”);
  4 | // you may not use this file except in compliance with the License.
  5 | // See [CONTRIBUTORS.md] for the list of HomeKit ADK project authors.
  6 | 
  7 | #ifndef HAP_INTERNAL_H
  8 | #define HAP_INTERNAL_H
  9 | 
 10 | #ifdef __cplusplus
 11 | extern "C" {
 12 | #endif
 13 | 
 14 | // Core features.
 15 | #ifndef HAP_IP
 16 | #define HAP_IP 1
 17 | #endif
 18 | #ifndef HAP_BLE
 19 | #define HAP_BLE 1
 20 | #endif
 21 | 
 22 | #include "HAP.h"
 23 | 
 24 | #include "HAPCrypto.h"
 25 | 
 26 | #include "util_http_reader.h"
 27 | 
 28 | #include "HAPStringBuilder.h"
 29 | 
 30 | #include "HAPDeviceID.h"
 31 | #include "HAPPDU.h"
 32 | 
 33 | #include "HAPMFiAuth.h"
 34 | #include "HAPMFiHWAuth+Types.h"
 35 | #include "HAPMFiHWAuth.h"
 36 | 
 37 | #include "HAPPairing.h"
 38 | #include "HAPPairingBLESessionCache.h"
 39 | #include "HAPPairingPairSetup.h"
 40 | #include "HAPPairingPairVerify.h"
 41 | #include "HAPPairingPairings.h"
 42 | 
 43 | #include "HAPSession.h"
 44 | 
 45 | #include "HAPBLEPDU+TLV.h"
 46 | #include "HAPBLEPDU.h"
 47 | #include "HAPBLETransaction.h"
 48 | 
 49 | #include "HAPBLEAccessoryServer+Advertising.h"
 50 | #include "HAPBLEAccessoryServer+Broadcast.h"
 51 | #include "HAPBLEAccessoryServer.h"
 52 | #include "HAPBLECharacteristic+Broadcast.h"
 53 | #include "HAPBLECharacteristic+Configuration.h"
 54 | #include "HAPBLECharacteristic+Signature.h"
 55 | #include "HAPBLECharacteristic+Value.h"
 56 | #include "HAPBLECharacteristic.h"
 57 | 
 58 | #include "HAPBLEPeripheralManager.h"
 59 | #include "HAPBLEProcedure.h"
 60 | #include "HAPBLEProtocol+Configuration.h"
 61 | #include "HAPBLEService+Signature.h"
 62 | #include "HAPBLESession.h"
 63 | 
 64 | #include "HAPIP+ByteBuffer.h"
 65 | #include "HAPIPAccessory.h"
 66 | #include "HAPIPAccessoryProtocol.h"
 67 | #include "HAPIPCharacteristic.h"
 68 | #include "HAPIPSecurityProtocol.h"
 69 | #include "HAPIPSession.h"
 70 | 
 71 | #include "HAPIPAccessoryServer.h"
 72 | #include "HAPIPServiceDiscovery.h"
 73 | 
 74 | #include "HAP+KeyValueStoreDomains.h"
 75 | #include "HAPAccessory+Info.h"
 76 | #include "HAPAccessoryServer+Internal.h"
 77 | #include "HAPAccessorySetup.h"
 78 | #include "HAPAccessorySetupInfo.h"
 79 | #include "HAPAccessoryValidation.h"
 80 | #include "HAPCharacteristic.h"
 81 | 
 82 | #include "HAPJSONUtils.h"
 83 | #include "HAPLog+Attributes.h"
 84 | #include "HAPMACAddress.h"
 85 | #include "HAPMFiTokenAuth.h"
 86 | #include "HAPTLV+Internal.h"
 87 | #include "HAPUUID.h"
 88 | 
 89 | #include "HAPCharacteristicTypes+TLV.h"
 90 | 
 91 | #if __has_feature(nullability)
 92 | #pragma clang assume_nonnull begin
 93 | #endif
 94 | 
 95 | #define kHAP_LogSubsystem "com.apple.mfi.HomeKit.Core"
 96 | 
 97 | #if __has_feature(nullability)
 98 | #pragma clang assume_nonnull end
 99 | #endif
100 | 
101 | #ifdef __cplusplus
102 | }
103 | #endif
104 | 
105 | #endif
106 | 


--------------------------------------------------------------------------------
/HAP/HAPAccessory+Info.h:
--------------------------------------------------------------------------------
 1 | // Copyright (c) 2015-2019 The HomeKit ADK Contributors
 2 | //
 3 | // Licensed under the Apache License, Version 2.0 (the “License”);
 4 | // you may not use this file except in compliance with the License.
 5 | // See [CONTRIBUTORS.md] for the list of HomeKit ADK project authors.
 6 | 
 7 | #ifndef HAP_ACCESSORY_INFO_H
 8 | #define HAP_ACCESSORY_INFO_H
 9 | 
10 | #ifdef __cplusplus
11 | extern "C" {
12 | #endif
13 | 
14 | #include "HAP.h"
15 | 
16 | #if __has_feature(nullability)
17 | #pragma clang assume_nonnull begin
18 | #endif
19 | 
20 | /**
21 |  * Serializes the body of a HAP-Info-Read-Response.
22 |  *
23 |  * @param      server               Accessory server.
24 |  * @param      session              Session on which the request came in.
25 |  * @param      accessory            The accessory on which the request came in.
26 |  * @param      responseWriter       Writer to serialize Characteristic Signature into.
27 |  *
28 |  * @return kHAPError_None           If successful.
29 |  * @return kHAPError_Unknown        If an I/O error occurred.
30 |  * @return kHAPError_OutOfResources If writer does not have enough capacity.
31 |  */
32 | HAP_RESULT_USE_CHECK
33 | HAPError HAPAccessoryGetInfoResponse(
34 |         HAPAccessoryServerRef* server,
35 |         HAPSessionRef* session,
36 |         const HAPAccessory* accessory,
37 |         HAPTLVWriterRef* responseWriter);
38 | 
39 | #if __has_feature(nullability)
40 | #pragma clang assume_nonnull end
41 | #endif
42 | 
43 | #ifdef __cplusplus
44 | }
45 | #endif
46 | 
47 | #endif
48 | 


--------------------------------------------------------------------------------
/HAP/HAPAccessoryValidation.h:
--------------------------------------------------------------------------------
 1 | // Copyright (c) 2015-2019 The HomeKit ADK Contributors
 2 | //
 3 | // Licensed under the Apache License, Version 2.0 (the “License”);
 4 | // you may not use this file except in compliance with the License.
 5 | // See [CONTRIBUTORS.md] for the list of HomeKit ADK project authors.
 6 | 
 7 | #ifndef HAP_ACCESSORY_VALIDATION_H
 8 | #define HAP_ACCESSORY_VALIDATION_H
 9 | 
10 | #ifdef __cplusplus
11 | extern "C" {
12 | #endif
13 | 
14 | #include "HAP+Internal.h"
15 | 
16 | #if __has_feature(nullability)
17 | #pragma clang assume_nonnull begin
18 | #endif
19 | 
20 | /**
21 |  * Validates a regular (Bluetooth LE / IP) accessory definition.
22 |  *
23 |  * @param      server               Accessory server.
24 |  * @param      accessory            Accessory to validate.
25 |  *
26 |  * @return true                     If the accessory definition is valid.
27 |  * @return false                    Otherwise.
28 |  */
29 | bool HAPRegularAccessoryIsValid(HAPAccessoryServerRef* server, const HAPAccessory* accessory);
30 | 
31 | /**
32 |  * Validates a bridged accessory definition.
33 |  *
34 |  * @param      bridgedAccessory     Accessory to validate.
35 |  *
36 |  * @return true                     If the accessory definition is valid.
37 |  * @return false                    Otherwise.
38 |  */
39 | bool HAPBridgedAccessoryIsValid(const HAPAccessory* bridgedAccessory);
40 | 
41 | #if __has_feature(nullability)
42 | #pragma clang assume_nonnull end
43 | #endif
44 | 
45 | #ifdef __cplusplus
46 | }
47 | #endif
48 | 
49 | #endif
50 | 


--------------------------------------------------------------------------------
/HAP/HAPBLECharacteristic+Signature.c:
--------------------------------------------------------------------------------
 1 | // Copyright (c) 2015-2019 The HomeKit ADK Contributors
 2 | //
 3 | // Licensed under the Apache License, Version 2.0 (the “License”);
 4 | // you may not use this file except in compliance with the License.
 5 | // See [CONTRIBUTORS.md] for the list of HomeKit ADK project authors.
 6 | 
 7 | #include "HAP+Internal.h"
 8 | 
 9 | HAP_RESULT_USE_CHECK
10 | HAPError HAPBLECharacteristicGetSignatureReadResponse(
11 |         const HAPCharacteristic* characteristic,
12 |         const HAPService* service,
13 |         HAPTLVWriterRef* responseWriter) {
14 |     HAPPrecondition(characteristic);
15 |     HAPPrecondition(service);
16 |     HAPPrecondition(responseWriter);
17 | 
18 |     HAPError err;
19 | 
20 |     err = HAPBLEPDUTLVSerializeCharacteristicType(characteristic, responseWriter);
21 |     if (err) {
22 |         HAPAssert(err == kHAPError_OutOfResources);
23 |         return err;
24 |     }
25 |     err = HAPBLEPDUTLVSerializeServiceInstanceID(service, responseWriter);
26 |     if (err) {
27 |         HAPAssert(err == kHAPError_OutOfResources);
28 |         return err;
29 |     }
30 |     err = HAPBLEPDUTLVSerializeServiceType(service, responseWriter);
31 |     if (err) {
32 |         HAPAssert(err == kHAPError_OutOfResources);
33 |         return err;
34 |     }
35 |     err = HAPBLEPDUTLVSerializeHAPCharacteristicPropertiesDescriptor(characteristic, responseWriter);
36 |     if (err) {
37 |         HAPAssert(err == kHAPError_OutOfResources);
38 |         return err;
39 |     }
40 |     err = HAPBLEPDUTLVSerializeGATTUserDescriptionDescriptor(characteristic, responseWriter);
41 |     if (err) {
42 |         HAPAssert(err == kHAPError_OutOfResources);
43 |         return err;
44 |     }
45 |     err = HAPBLEPDUTLVSerializeGATTPresentationFormatDescriptor(characteristic, responseWriter);
46 |     if (err) {
47 |         HAPAssert(err == kHAPError_OutOfResources);
48 |         return err;
49 |     }
50 |     err = HAPBLEPDUTLVSerializeGATTValidRange(characteristic, responseWriter);
51 |     if (err) {
52 |         HAPAssert(err == kHAPError_OutOfResources);
53 |         return err;
54 |     }
55 |     err = HAPBLEPDUTLVSerializeHAPStepValueDescriptor(characteristic, responseWriter);
56 |     if (err) {
57 |         HAPAssert(err == kHAPError_OutOfResources);
58 |         return err;
59 |     }
60 |     err = HAPBLEPDUTLVSerializeHAPValidValuesDescriptor(characteristic, responseWriter);
61 |     if (err) {
62 |         HAPAssert(err == kHAPError_OutOfResources);
63 |         return err;
64 |     }
65 |     err = HAPBLEPDUTLVSerializeHAPValidValuesRangeDescriptor(characteristic, responseWriter);
66 |     if (err) {
67 |         HAPAssert(err == kHAPError_OutOfResources);
68 |         return err;
69 |     }
70 | 
71 |     return kHAPError_None;
72 | }
73 | 


--------------------------------------------------------------------------------
/HAP/HAPBLECharacteristic+Signature.h:
--------------------------------------------------------------------------------
 1 | // Copyright (c) 2015-2019 The HomeKit ADK Contributors
 2 | //
 3 | // Licensed under the Apache License, Version 2.0 (the “License”);
 4 | // you may not use this file except in compliance with the License.
 5 | // See [CONTRIBUTORS.md] for the list of HomeKit ADK project authors.
 6 | 
 7 | #ifndef HAP_BLE_CHARACTERISTIC_SIGNATURE_H
 8 | #define HAP_BLE_CHARACTERISTIC_SIGNATURE_H
 9 | 
10 | #ifdef __cplusplus
11 | extern "C" {
12 | #endif
13 | 
14 | #include "HAP+Internal.h"
15 | 
16 | #if __has_feature(nullability)
17 | #pragma clang assume_nonnull begin
18 | #endif
19 | 
20 | /**
21 |  * Serializes the body of a HAP-Characteristic-Signature-Read-Response.
22 |  *
23 |  * @param      characteristic       Characteristic that received the request.
24 |  * @param      service              The service that contains the characteristic.
25 |  * @param      responseWriter       Writer to serialize Characteristic Signature into.
26 |  *
27 |  * @return kHAPError_None           If successful.
28 |  * @return kHAPError_OutOfResources If writer does not have enough capacity.
29 |  *
30 |  * @see HomeKit Accessory Protocol Specification R14
31 |  *      Section 7.3.4.2 HAP-Characteristic-Signature-Read-Response
32 |  */
33 | HAP_RESULT_USE_CHECK
34 | HAPError HAPBLECharacteristicGetSignatureReadResponse(
35 |         const HAPCharacteristic* characteristic,
36 |         const HAPService* service,
37 |         HAPTLVWriterRef* responseWriter);
38 | 
39 | #if __has_feature(nullability)
40 | #pragma clang assume_nonnull end
41 | #endif
42 | 
43 | #ifdef __cplusplus
44 | }
45 | #endif
46 | 
47 | #endif
48 | 


--------------------------------------------------------------------------------
/HAP/HAPBLECharacteristic.c:
--------------------------------------------------------------------------------
 1 | // Copyright (c) 2015-2019 The HomeKit ADK Contributors
 2 | //
 3 | // Licensed under the Apache License, Version 2.0 (the “License”);
 4 | // you may not use this file except in compliance with the License.
 5 | // See [CONTRIBUTORS.md] for the list of HomeKit ADK project authors.
 6 | 
 7 | #include "HAP+Internal.h"
 8 | 
 9 | HAP_RESULT_USE_CHECK
10 | bool HAPBLECharacteristicSupportsServiceProcedures(const HAPCharacteristic* characteristic_) {
11 |     HAPPrecondition(characteristic_);
12 |     const HAPBaseCharacteristic* characteristic = characteristic_;
13 | 
14 |     return HAPUUIDAreEqual(characteristic->characteristicType, &kHAPCharacteristicType_ServiceSignature);
15 | }
16 | 
17 | bool HAPBLECharacteristicDropsSecuritySession(const HAPCharacteristic* characteristic_) {
18 |     HAPPrecondition(characteristic_);
19 |     const HAPBaseCharacteristic* characteristic = characteristic_;
20 | 
21 |     return HAPUUIDAreEqual(characteristic->characteristicType, &kHAPCharacteristicType_PairSetup) ||
22 |            HAPUUIDAreEqual(characteristic->characteristicType, &kHAPCharacteristicType_PairVerify) ||
23 |            HAPUUIDAreEqual(characteristic->characteristicType, &kHAPCharacteristicType_PairingFeatures);
24 | }
25 | 


--------------------------------------------------------------------------------
/HAP/HAPBLECharacteristic.h:
--------------------------------------------------------------------------------
 1 | // Copyright (c) 2015-2019 The HomeKit ADK Contributors
 2 | //
 3 | // Licensed under the Apache License, Version 2.0 (the “License”);
 4 | // you may not use this file except in compliance with the License.
 5 | // See [CONTRIBUTORS.md] for the list of HomeKit ADK project authors.
 6 | 
 7 | #ifndef HAP_BLE_CHARACTERISTIC_H
 8 | #define HAP_BLE_CHARACTERISTIC_H
 9 | 
10 | #ifdef __cplusplus
11 | extern "C" {
12 | #endif
13 | 
14 | #include "HAP+Internal.h"
15 | 
16 | #if __has_feature(nullability)
17 | #pragma clang assume_nonnull begin
18 | #endif
19 | 
20 | /**
21 |  * Returns whether a characteristic supports HAP-BLE service procedures.
22 |  *
23 |  * @param      characteristic       Characteristic.
24 |  *
25 |  * @return true                     If the characteristic supports HAP-BLE service procedures.
26 |  * @return false                    Otherwise.
27 |  *
28 |  * @see HomeKit Accessory Protocol Specification R14
29 |  *      Section 7.3.4.12 HAP-Service-Signature-Read-Request
30 |  * @see HomeKit Accessory Protocol Specification R14
31 |  *      Section 7.3.4.13 HAP-Service-Signature-Read-Response
32 |  */
33 | HAP_RESULT_USE_CHECK
34 | bool HAPBLECharacteristicSupportsServiceProcedures(const HAPCharacteristic* characteristic);
35 | 
36 | /**
37 |  * Returns whether accessing a characteristic over BLE should drop the security session.
38 |  *
39 |  * @param      characteristic       Characteristic.
40 |  *
41 |  * @return true                     If the security session should be dropped if the characteristic is accessed.
42 |  * @return false                    Otherwise.
43 |  */
44 | bool HAPBLECharacteristicDropsSecuritySession(const HAPCharacteristic* characteristic);
45 | 
46 | #if __has_feature(nullability)
47 | #pragma clang assume_nonnull end
48 | #endif
49 | 
50 | #ifdef __cplusplus
51 | }
52 | #endif
53 | 
54 | #endif
55 | 


--------------------------------------------------------------------------------
/HAP/HAPBLEPeripheralManager.h:
--------------------------------------------------------------------------------
 1 | // Copyright (c) 2015-2019 The HomeKit ADK Contributors
 2 | //
 3 | // Licensed under the Apache License, Version 2.0 (the “License”);
 4 | // you may not use this file except in compliance with the License.
 5 | // See [CONTRIBUTORS.md] for the list of HomeKit ADK project authors.
 6 | 
 7 | #ifndef HAP_BLE_PERIPHERAL_MANAGER_H
 8 | #define HAP_BLE_PERIPHERAL_MANAGER_H
 9 | 
10 | #ifdef __cplusplus
11 | extern "C" {
12 | #endif
13 | 
14 | #include "HAP+Internal.h"
15 | 
16 | #if __has_feature(nullability)
17 | #pragma clang assume_nonnull begin
18 | #endif
19 | 
20 | /**
21 |  * Releases all resources that have been allocated by the peripheral manager.
22 |  *
23 |  * @param      server               Accessory server.
24 |  */
25 | void HAPBLEPeripheralManagerRelease(HAPAccessoryServerRef* server);
26 | 
27 | /**
28 |  * Registers the accessory server's GATT DB.
29 |  *
30 |  * @param      server               Accessory server.
31 |  */
32 | void HAPBLEPeripheralManagerRegister(HAPAccessoryServerRef* server);
33 | 
34 | /**
35 |  * Raises an event notification for a given characteristic in a given service provided by a given accessory object.
36 |  *
37 |  * @param      server               Accessory server.
38 |  * @param      characteristic       The characteristic whose value has changed.
39 |  * @param      service              The service that contains the characteristic.
40 |  * @param      accessory            The accessory that provides the service.
41 |  */
42 | void HAPBLEPeripheralManagerRaiseEvent(
43 |         HAPAccessoryServerRef* server,
44 |         const HAPCharacteristic* characteristic,
45 |         const HAPService* service,
46 |         const HAPAccessory* accessory);
47 | 
48 | /**
49 |  * Informs the peripheral manager that a HomeKit Session was accepted.
50 |  *
51 |  * - This is called after the application has been informed that the session was accepted.
52 |  *
53 |  * @param      server               Accessory server.
54 |  * @param      session              The newly accepted session.
55 |  */
56 | void HAPBLEPeripheralManagerHandleSessionAccept(HAPAccessoryServerRef* server, HAPSessionRef* session);
57 | 
58 | /**
59 |  * Informs the peripheral manager that a HomeKit Session was invalidated.
60 |  *
61 |  * - This is called before the application is informed that the session was invalidated.
62 |  *
63 |  * @param      server               Accessory server.
64 |  * @param      session              The session being invalidated.
65 |  */
66 | void HAPBLEPeripheralManagerHandleSessionInvalidate(HAPAccessoryServerRef* server, HAPSessionRef* session);
67 | 
68 | #if __has_feature(nullability)
69 | #pragma clang assume_nonnull end
70 | #endif
71 | 
72 | #ifdef __cplusplus
73 | }
74 | #endif
75 | 
76 | #endif
77 | 


--------------------------------------------------------------------------------
/HAP/HAPBLEService+Signature.c:
--------------------------------------------------------------------------------
 1 | // Copyright (c) 2015-2019 The HomeKit ADK Contributors
 2 | //
 3 | // Licensed under the Apache License, Version 2.0 (the “License”);
 4 | // you may not use this file except in compliance with the License.
 5 | // See [CONTRIBUTORS.md] for the list of HomeKit ADK project authors.
 6 | 
 7 | #include "HAP+Internal.h"
 8 | 
 9 | HAP_RESULT_USE_CHECK
10 | HAPError HAPBLEServiceGetSignatureReadResponse(const HAPService* _Nullable service, HAPTLVWriterRef* responseWriter) {
11 |     HAPPrecondition(responseWriter);
12 | 
13 |     HAPError err;
14 | 
15 |     err = HAPBLEPDUTLVSerializeHAPServiceProperties(service, responseWriter);
16 |     if (err) {
17 |         HAPAssert(err == kHAPError_OutOfResources);
18 |         return err;
19 |     }
20 |     err = HAPBLEPDUTLVSerializeHAPLinkedServices(service, responseWriter);
21 |     if (err) {
22 |         HAPAssert(err == kHAPError_OutOfResources);
23 |         return err;
24 |     }
25 | 
26 |     return kHAPError_None;
27 | }
28 | 


--------------------------------------------------------------------------------
/HAP/HAPBLEService+Signature.h:
--------------------------------------------------------------------------------
 1 | // Copyright (c) 2015-2019 The HomeKit ADK Contributors
 2 | //
 3 | // Licensed under the Apache License, Version 2.0 (the “License”);
 4 | // you may not use this file except in compliance with the License.
 5 | // See [CONTRIBUTORS.md] for the list of HomeKit ADK project authors.
 6 | 
 7 | #ifndef HAP_BLE_SERVICE_SIGNATURE_H
 8 | #define HAP_BLE_SERVICE_SIGNATURE_H
 9 | 
10 | #ifdef __cplusplus
11 | extern "C" {
12 | #endif
13 | 
14 | #include "HAP+Internal.h"
15 | 
16 | #if __has_feature(nullability)
17 | #pragma clang assume_nonnull begin
18 | #endif
19 | 
20 | /**
21 |  * Serializes the body of a HAP-Service-Signature-Read-Response.
22 |  *
23 |  * @param      service              Service. NULL if the request had an invalid IID.
24 |  * @param      responseWriter       Writer to serialize Service Signature into.
25 |  *
26 |  * @return kHAPError_None           If successful.
27 |  * @return kHAPError_OutOfResources If writer does not have enough capacity.
28 |  *
29 |  * @see HomeKit Accessory Protocol Specification R14
30 |  *      Section 7.3.4.13 HAP-Service-Signature-Read-Response
31 |  */
32 | HAP_RESULT_USE_CHECK
33 | HAPError HAPBLEServiceGetSignatureReadResponse(const HAPService* _Nullable service, HAPTLVWriterRef* responseWriter);
34 | 
35 | #if __has_feature(nullability)
36 | #pragma clang assume_nonnull end
37 | #endif
38 | 
39 | #ifdef __cplusplus
40 | }
41 | #endif
42 | 
43 | #endif
44 | 


--------------------------------------------------------------------------------
/HAP/HAPBitSet.c:
--------------------------------------------------------------------------------
 1 | // Copyright (c) 2015-2019 The HomeKit ADK Contributors
 2 | //
 3 | // Licensed under the Apache License, Version 2.0 (the “License”);
 4 | // you may not use this file except in compliance with the License.
 5 | // See [CONTRIBUTORS.md] for the list of HomeKit ADK project authors.
 6 | 
 7 | #undef HAP_DISALLOW_USE_IGNORED
 8 | #define HAP_DISALLOW_USE_IGNORED 1
 9 | 
10 | #include "HAP+Internal.h"
11 | 
12 | HAP_RESULT_USE_CHECK
13 | bool HAPBitSetContainsInternal(const uint8_t* bitSet, size_t numBytes, uint8_t bitIndex) {
14 |     HAPPrecondition(bitSet);
15 | 
16 |     size_t byteIndex = bitIndex / CHAR_BIT;
17 |     HAPPrecondition(byteIndex < numBytes);
18 |     uint8_t bitMask = (uint8_t)(1u << (uint8_t)(bitIndex % CHAR_BIT));
19 | 
20 |     return bitSet[byteIndex] & bitMask;
21 | }
22 | 
23 | void HAPBitSetInsertInternal(uint8_t* bitSet, size_t numBytes, uint8_t bitIndex) {
24 |     HAPPrecondition(bitSet);
25 | 
26 |     size_t byteIndex = bitIndex / CHAR_BIT;
27 |     HAPPrecondition(byteIndex < numBytes);
28 |     uint8_t bitMask = (uint8_t)(1u << (uint8_t)(bitIndex % CHAR_BIT));
29 | 
30 |     bitSet[byteIndex] |= bitMask;
31 | }
32 | 
33 | void HAPBitSetRemoveInternal(uint8_t* bitSet, size_t numBytes, uint8_t bitIndex) {
34 |     HAPPrecondition(bitSet);
35 | 
36 |     size_t byteIndex = bitIndex / CHAR_BIT;
37 |     HAPPrecondition(byteIndex < numBytes);
38 |     uint8_t bitMask = (uint8_t)(1u << (uint8_t)(bitIndex % CHAR_BIT));
39 | 
40 |     bitSet[byteIndex] &= (uint8_t) ~bitMask;
41 | }
42 | 


--------------------------------------------------------------------------------
/HAP/HAPBitSet.h:
--------------------------------------------------------------------------------
 1 | // Copyright (c) 2015-2019 The HomeKit ADK Contributors
 2 | //
 3 | // Licensed under the Apache License, Version 2.0 (the “License”);
 4 | // you may not use this file except in compliance with the License.
 5 | // See [CONTRIBUTORS.md] for the list of HomeKit ADK project authors.
 6 | 
 7 | #ifndef HAP_UTILS_H
 8 | #define HAP_UTILS_H
 9 | 
10 | #ifdef __cplusplus
11 | extern "C" {
12 | #endif
13 | 
14 | #include "HAP+Internal.h"
15 | 
16 | #if __has_feature(nullability)
17 | #pragma clang assume_nonnull begin
18 | #endif
19 | 
20 | /**
21 |  * Indicates whether the specified bit is set in a bit set.
22 |  *
23 |  * @param      bitSet               Byte array representing the bit set.
24 |  * @param      bitIndex             Bit index.
25 |  *
26 |  * @return true                     If the specified bit is set.
27 |  * @return false                    Otherwise.
28 |  */
29 | #define HAPBitSetContains(bitSet, bitIndex) HAPBitSetContainsInternal((bitSet), sizeof(bitSet), (bitIndex))
30 | 
31 | /**
32 |  * Inserts the specified bit into a bit set.
33 |  *
34 |  * @param      bitSet               Byte array representing the bit set.
35 |  * @param      bitIndex             Bit index.
36 |  */
37 | #define HAPBitSetInsert(bitSet, bitIndex) HAPBitSetInsertInternal((bitSet), sizeof(bitSet), (bitIndex))
38 | 
39 | /**
40 |  * Removes the specified bit from a bit set.
41 |  *
42 |  * @param      bitSet               Byte array representing the bit set.
43 |  * @param      bitIndex             Bit index.
44 |  */
45 | #define HAPBitSetRemove(bitSet, bitIndex) HAPBitSetRemoveInternal((bitSet), sizeof(bitSet), (bitIndex))
46 | 
47 | //----------------------------------------------------------------------------------------------------------------------
48 | // Internal functions. Do not use directly.
49 | 
50 | /**@cond */
51 | HAP_RESULT_USE_CHECK
52 | bool HAPBitSetContainsInternal(const uint8_t* bitSet, size_t numBytes, uint8_t bitIndex);
53 | HAP_DISALLOW_USE(HAPBitSetContainsInternal)
54 | 
55 | void HAPBitSetInsertInternal(uint8_t* bitSet, size_t numBytes, uint8_t bitIndex);
56 | HAP_DISALLOW_USE(HAPBitSetInsertInternal)
57 | 
58 | void HAPBitSetRemoveInternal(uint8_t* bitSet, size_t numBytes, uint8_t bitIndex);
59 | HAP_DISALLOW_USE(HAPBitSetRemoveInternal)
60 | /**@endcond */
61 | 
62 | #if __has_feature(nullability)
63 | #pragma clang assume_nonnull end
64 | #endif
65 | 
66 | #ifdef __cplusplus
67 | }
68 | #endif
69 | 
70 | #endif
71 | 


--------------------------------------------------------------------------------
/HAP/HAPCharacteristicTypes+TLV.h:
--------------------------------------------------------------------------------
 1 | // Copyright (c) 2015-2019 The HomeKit ADK Contributors
 2 | //
 3 | // Licensed under the Apache License, Version 2.0 (the “License”);
 4 | // you may not use this file except in compliance with the License.
 5 | // See [CONTRIBUTORS.md] for the list of HomeKit ADK project authors.
 6 | 
 7 | #ifndef HAP_CHARACTERISTIC_TYPES_TLV_H
 8 | #define HAP_CHARACTERISTIC_TYPES_TLV_H
 9 | 
10 | #ifdef __cplusplus
11 | extern "C" {
12 | #endif
13 | 
14 | #include "HAP+Internal.h"
15 | 
16 | #if __has_feature(nullability)
17 | #pragma clang assume_nonnull begin
18 | #endif
19 | 
20 | #if __has_feature(nullability)
21 | #pragma clang assume_nonnull end
22 | #endif
23 | 
24 | #ifdef __cplusplus
25 | }
26 | #endif
27 | 
28 | #endif
29 | 


--------------------------------------------------------------------------------
/HAP/HAPDeviceID.c:
--------------------------------------------------------------------------------
 1 | // Copyright (c) 2015-2019 The HomeKit ADK Contributors
 2 | //
 3 | // Licensed under the Apache License, Version 2.0 (the “License”);
 4 | // you may not use this file except in compliance with the License.
 5 | // See [CONTRIBUTORS.md] for the list of HomeKit ADK project authors.
 6 | 
 7 | #include "HAP+Internal.h"
 8 | 
 9 | static const HAPLogObject logObject = { .subsystem = kHAP_LogSubsystem, .category = "DeviceID" };
10 | 
11 | HAP_RESULT_USE_CHECK
12 | HAPError HAPDeviceIDGet(HAPPlatformKeyValueStoreRef keyValueStore, HAPDeviceID* deviceID) {
13 |     HAPPrecondition(keyValueStore);
14 |     HAPPrecondition(deviceID);
15 | 
16 |     HAPError err;
17 | 
18 |     // Try to load Device ID.
19 |     bool found;
20 |     size_t numBytes;
21 |     err = HAPPlatformKeyValueStoreGet(
22 |             keyValueStore,
23 |             kHAPKeyValueStoreDomain_Configuration,
24 |             kHAPKeyValueStoreKey_Configuration_DeviceID,
25 |             deviceID->bytes,
26 |             sizeof deviceID->bytes,
27 |             &numBytes,
28 |             &found);
29 |     if (err) {
30 |         HAPAssert(err == kHAPError_Unknown);
31 |         return err;
32 |     }
33 |     if (!found) {
34 |         // Generate new Device ID.
35 |         HAPPlatformRandomNumberFill(deviceID->bytes, sizeof deviceID->bytes);
36 |         HAPLogBufferInfo(&logObject, deviceID->bytes, sizeof deviceID->bytes, "Generated new Device ID.");
37 | 
38 |         // Store new Device ID.
39 |         err = HAPPlatformKeyValueStoreSet(
40 |                 keyValueStore,
41 |                 kHAPKeyValueStoreDomain_Configuration,
42 |                 kHAPKeyValueStoreKey_Configuration_DeviceID,
43 |                 deviceID->bytes,
44 |                 sizeof deviceID->bytes);
45 |         if (err) {
46 |             HAPAssert(err == kHAPError_Unknown);
47 |             return err;
48 |         }
49 |     } else if (numBytes != sizeof deviceID->bytes) {
50 |         HAPLog(&logObject, "Invalid Device ID.");
51 |         return kHAPError_Unknown;
52 |     }
53 | 
54 |     return kHAPError_None;
55 | }
56 | 
57 | HAP_RESULT_USE_CHECK
58 | HAPError HAPDeviceIDGetAsString(HAPPlatformKeyValueStoreRef keyValueStore, HAPDeviceIDString* deviceIDString) {
59 |     HAPPrecondition(keyValueStore);
60 |     HAPPrecondition(deviceIDString);
61 | 
62 |     HAPError err;
63 | 
64 |     HAPDeviceID deviceID;
65 |     err = HAPDeviceIDGet(keyValueStore, &deviceID);
66 |     if (err) {
67 |         HAPAssert(err == kHAPError_Unknown);
68 |         return err;
69 |     }
70 | 
71 |     HAPAssert(sizeof deviceID.bytes == 6);
72 |     err = HAPStringWithFormat(
73 |             deviceIDString->stringValue,
74 |             sizeof deviceIDString->stringValue,
75 |             "%02X:%02X:%02X:%02X:%02X:%02X",
76 |             deviceID.bytes[0],
77 |             deviceID.bytes[1],
78 |             deviceID.bytes[2],
79 |             deviceID.bytes[3],
80 |             deviceID.bytes[4],
81 |             deviceID.bytes[5]);
82 |     HAPAssert(!err);
83 | 
84 |     return kHAPError_None;
85 | }
86 | 


--------------------------------------------------------------------------------
/HAP/HAPDeviceID.h:
--------------------------------------------------------------------------------
 1 | // Copyright (c) 2015-2019 The HomeKit ADK Contributors
 2 | //
 3 | // Licensed under the Apache License, Version 2.0 (the “License”);
 4 | // you may not use this file except in compliance with the License.
 5 | // See [CONTRIBUTORS.md] for the list of HomeKit ADK project authors.
 6 | 
 7 | #ifndef HAP_DEVICE_ID_H
 8 | #define HAP_DEVICE_ID_H
 9 | 
10 | #ifdef __cplusplus
11 | extern "C" {
12 | #endif
13 | 
14 | #include "HAP+Internal.h"
15 | 
16 | #if __has_feature(nullability)
17 | #pragma clang assume_nonnull begin
18 | #endif
19 | 
20 | /**
21 |  * Length of a Device ID.
22 |  */
23 | #define kHAPDeviceID_NumBytes ((size_t) 6)
24 | 
25 | /**
26 |  * Device ID.
27 |  *
28 |  * @see HomeKit Accessory Protocol Specification R14
29 |  *      Section 5.4 Device ID
30 |  * @see Accessory Interface Specification - Wi-Fi Accessory Configuration Addendum R1
31 |  *      Table 2-7 Apple Device IE elements
32 |  */
33 | typedef struct {
34 |     /** Value. */
35 |     uint8_t bytes[kHAPDeviceID_NumBytes];
36 | } HAPDeviceID;
37 | HAP_NONNULL_SUPPORT(HAPDeviceID)
38 | 
39 | /**
40 |  * Gets the Device ID.
41 |  *
42 |  * @param      keyValueStore        Key-value store.
43 |  * @param[out] deviceID             Device ID.
44 |  *
45 |  * @return kHAPError_None           If successful.
46 |  * @return kHAPError_Unknown        If persistent store access failed.
47 |  */
48 | HAP_RESULT_USE_CHECK
49 | HAPError HAPDeviceIDGet(HAPPlatformKeyValueStoreRef keyValueStore, HAPDeviceID* deviceID);
50 | 
51 | /**
52 |  * NULL-terminated Device ID string (format: XX:XX:XX:XX:XX:XX, uppercase).
53 |  */
54 | typedef struct {
55 |     char stringValue[17 + 1]; /**< NULL-terminated. */
56 | } HAPDeviceIDString;
57 | 
58 | /**
59 |  * Gets the Device ID as a string.
60 |  *
61 |  * @param      keyValueStore        Key-value store.
62 |  * @param[out] deviceIDString       Device ID string.
63 |  *
64 |  * @return kHAPError_None           If successful.
65 |  * @return kHAPError_Unknown        If persistent store access failed.
66 |  */
67 | HAP_RESULT_USE_CHECK
68 | HAPError HAPDeviceIDGetAsString(HAPPlatformKeyValueStoreRef keyValueStore, HAPDeviceIDString* deviceIDString);
69 | 
70 | #if __has_feature(nullability)
71 | #pragma clang assume_nonnull end
72 | #endif
73 | 
74 | #ifdef __cplusplus
75 | }
76 | #endif
77 | 
78 | #endif
79 | 


--------------------------------------------------------------------------------
/HAP/HAPIP+ByteBuffer.c:
--------------------------------------------------------------------------------
 1 | // Copyright (c) 2015-2019 The HomeKit ADK Contributors
 2 | //
 3 | // Licensed under the Apache License, Version 2.0 (the “License”);
 4 | // you may not use this file except in compliance with the License.
 5 | // See [CONTRIBUTORS.md] for the list of HomeKit ADK project authors.
 6 | 
 7 | #include "HAP+Internal.h"
 8 | 
 9 | void HAPIPByteBufferClear(HAPIPByteBuffer* byteBuffer) {
10 |     HAPPrecondition(byteBuffer);
11 | 
12 |     byteBuffer->position = 0;
13 |     byteBuffer->limit = byteBuffer->capacity;
14 | }
15 | 
16 | void HAPIPByteBufferFlip(HAPIPByteBuffer* byteBuffer) {
17 |     HAPPrecondition(byteBuffer);
18 | 
19 |     byteBuffer->limit = byteBuffer->position;
20 |     byteBuffer->position = 0;
21 | }
22 | 
23 | void HAPIPByteBufferShiftLeft(HAPIPByteBuffer* byteBuffer, size_t numBytes) {
24 |     HAPPrecondition(byteBuffer);
25 |     HAPPrecondition(byteBuffer->data);
26 |     HAPPrecondition(numBytes <= byteBuffer->position);
27 |     HAPPrecondition(byteBuffer->position <= byteBuffer->limit);
28 |     HAPPrecondition(byteBuffer->limit <= byteBuffer->capacity);
29 | 
30 |     HAPRawBufferCopyBytes(byteBuffer->data, &byteBuffer->data[numBytes], byteBuffer->position - numBytes);
31 |     byteBuffer->position -= numBytes;
32 |     byteBuffer->limit -= numBytes;
33 | }
34 | 
35 | HAP_PRINTFLIKE(2, 3)
36 | HAP_RESULT_USE_CHECK
37 | HAPError HAPIPByteBufferAppendStringWithFormat(HAPIPByteBuffer* byteBuffer, const char* format, ...) {
38 |     HAPPrecondition(byteBuffer);
39 |     HAPPrecondition(byteBuffer->data);
40 |     HAPPrecondition(byteBuffer->position <= byteBuffer->limit);
41 |     HAPPrecondition(byteBuffer->limit <= byteBuffer->capacity);
42 | 
43 |     HAPError err;
44 | 
45 |     va_list args;
46 |     va_start(args, format);
47 |     err = HAPStringWithFormatAndArguments(
48 |             &byteBuffer->data[byteBuffer->position], byteBuffer->limit - byteBuffer->position, format, args);
49 |     va_end(args);
50 |     if (err) {
51 |         HAPAssert(kHAPError_OutOfResources);
52 |         return err;
53 |     }
54 |     byteBuffer->position += HAPStringGetNumBytes(&byteBuffer->data[byteBuffer->position]);
55 |     return kHAPError_None;
56 | }
57 | 


--------------------------------------------------------------------------------
/HAP/HAPIP+ByteBuffer.h:
--------------------------------------------------------------------------------
 1 | // Copyright (c) 2015-2019 The HomeKit ADK Contributors
 2 | //
 3 | // Licensed under the Apache License, Version 2.0 (the “License”);
 4 | // you may not use this file except in compliance with the License.
 5 | // See [CONTRIBUTORS.md] for the list of HomeKit ADK project authors.
 6 | 
 7 | #ifndef HAP_IP_BYTE_BUFFER_H
 8 | #define HAP_IP_BYTE_BUFFER_H
 9 | 
10 | #ifdef __cplusplus
11 | extern "C" {
12 | #endif
13 | 
14 | #include "HAP+Internal.h"
15 | 
16 | #if __has_feature(nullability)
17 | #pragma clang assume_nonnull begin
18 | #endif
19 | 
20 | /**
21 |  * Byte buffer data structure used by IP specific functions.
22 |  *
23 |  * Example usage:
24 |  * 1. The buffer is cleared using HAPIPByteBufferClear.
25 |  * 2. The buffer is filled by appending to the data member and increasing position up to limit.
26 |  * 3. The appended data is finalized using HAPIPByteBufferFlip.
27 |  * 4. The data is read back by accessing the data member and increasing position up to limit.
28 |  * 5. Read data may be discarded using HAPIPByteBufferShiftLeft.
29 |  */
30 | typedef struct {
31 |     size_t capacity;
32 |     size_t position;
33 |     size_t limit;
34 |     char* data;
35 | } HAPIPByteBuffer;
36 | 
37 | /**
38 |  * Clears a byte buffer.
39 |  *
40 |  * @param      byteBuffer           Byte buffer.
41 |  */
42 | void HAPIPByteBufferClear(HAPIPByteBuffer* byteBuffer);
43 | 
44 | /**
45 |  * Flips a byte buffer, making available appended data for reading.
46 |  *
47 |  * @param      byteBuffer           Byte buffer.
48 |  */
49 | void HAPIPByteBufferFlip(HAPIPByteBuffer* byteBuffer);
50 | 
51 | /**
52 |  * Discards bytes form a byte buffer.
53 |  *
54 |  * @param      byteBuffer           Byte buffer.
55 |  * @param      numBytes             Number of bytes to discard.
56 |  */
57 | void HAPIPByteBufferShiftLeft(HAPIPByteBuffer* byteBuffer, size_t numBytes);
58 | 
59 | /**
60 |  * Appends a formatted string to a byte buffer.
61 |  *
62 |  * @param      byteBuffer           Byte buffer.
63 |  * @param      format               A format string.
64 |  * @param      ...                  Arguments for the format string.
65 |  *
66 |  * @return kHAPError_None           If successful.
67 |  * @return kHAPError_OutOfResources If the supplied buffer is not large enough.
68 |  */
69 | HAP_PRINTFLIKE(2, 3)
70 | HAP_RESULT_USE_CHECK
71 | HAPError HAPIPByteBufferAppendStringWithFormat(HAPIPByteBuffer* byteBuffer, const char* format, ...);
72 | 
73 | #if __has_feature(nullability)
74 | #pragma clang assume_nonnull end
75 | #endif
76 | 
77 | #ifdef __cplusplus
78 | }
79 | #endif
80 | 
81 | #endif
82 | 


--------------------------------------------------------------------------------
/HAP/HAPIPCharacteristic.h:
--------------------------------------------------------------------------------
 1 | // Copyright (c) 2015-2019 The HomeKit ADK Contributors
 2 | //
 3 | // Licensed under the Apache License, Version 2.0 (the “License”);
 4 | // you may not use this file except in compliance with the License.
 5 | // See [CONTRIBUTORS.md] for the list of HomeKit ADK project authors.
 6 | 
 7 | #ifndef HAP_IP_CHARACTERISTIC_H
 8 | #define HAP_IP_CHARACTERISTIC_H
 9 | 
10 | #ifdef __cplusplus
11 | extern "C" {
12 | #endif
13 | 
14 | #include "HAP+Internal.h"
15 | 
16 | #if __has_feature(nullability)
17 | #pragma clang assume_nonnull begin
18 | #endif
19 | 
20 | /**
21 |  * Returns whether a characteristic supports HAP over IP (Ethernet / Wi-Fi).
22 |  *
23 |  * - Certain characteristics are only applicable to HAP over Bluetooth LE.
24 |  *
25 |  * @param      characteristic       Characteristic.
26 |  *
27 |  * @return true                     If the characteristic supports HAP over IP (Ethernet / Wi-Fi).
28 |  * @return false                    Otherwise.
29 |  */
30 | HAP_RESULT_USE_CHECK
31 | bool HAPIPCharacteristicIsSupported(const HAPCharacteristic* characteristic);
32 | 
33 | /**
34 |  * Returns the number of enabled properties of a characteristic.
35 |  *
36 |  * @param      characteristic       Characteristic.
37 |  *
38 |  * @return Number of enabled properties.
39 |  */
40 | HAP_RESULT_USE_CHECK
41 | size_t HAPCharacteristicGetNumEnabledProperties(const HAPCharacteristic* characteristic);
42 | 
43 | /**
44 |  * Returns the unit of the characteristic value.
45 |  *
46 |  * @param      characteristic       Characteristic.
47 |  *
48 |  * @return Unit of the characteristic value.
49 |  */
50 | HAP_RESULT_USE_CHECK
51 | HAPCharacteristicUnits HAPCharacteristicGetUnit(const HAPCharacteristic* characteristic);
52 | 
53 | #if __has_feature(nullability)
54 | #pragma clang assume_nonnull end
55 | #endif
56 | 
57 | #ifdef __cplusplus
58 | }
59 | #endif
60 | 
61 | #endif
62 | 


--------------------------------------------------------------------------------
/HAP/HAPIPSecurityProtocol.h:
--------------------------------------------------------------------------------
 1 | // Copyright (c) 2015-2019 The HomeKit ADK Contributors
 2 | //
 3 | // Licensed under the Apache License, Version 2.0 (the “License”);
 4 | // you may not use this file except in compliance with the License.
 5 | // See [CONTRIBUTORS.md] for the list of HomeKit ADK project authors.
 6 | 
 7 | #ifndef HAP_IP_SECURITY_PROTOCOL_H
 8 | #define HAP_IP_SECURITY_PROTOCOL_H
 9 | 
10 | #ifdef __cplusplus
11 | extern "C" {
12 | #endif
13 | 
14 | #include "HAP+Internal.h"
15 | 
16 | #if __has_feature(nullability)
17 | #pragma clang assume_nonnull begin
18 | #endif
19 | 
20 | /**
21 |  * Maximum frame length in the IP security protocol.
22 |  */
23 | #define kHAPIPSecurityProtocol_MaxFrameBytes ((size_t) 1024)
24 | 
25 | /**
26 |  * Computes the number of encrypted bytes given the number of plaintext bytes.
27 |  *
28 |  * @param      numPlaintextBytes    Number of plaintext bytes.
29 |  *
30 |  * @return Number of encrypted bytes given the number of plaintext bytes.
31 |  */
32 | HAP_RESULT_USE_CHECK
33 | size_t HAPIPSecurityProtocolGetNumEncryptedBytes(size_t numPlaintextBytes);
34 | 
35 | /**
36 |  * Encrypts data to be sent over a HomeKit session.
37 |  *
38 |  * @param      server               Accessory server.
39 |  * @param      session              The session over which the data will be sent.
40 |  * @param      buffer               Plaintext data to be encrypted.
41 |  */
42 | void HAPIPSecurityProtocolEncryptData(HAPAccessoryServerRef* server, HAPSessionRef* session, HAPIPByteBuffer* buffer);
43 | 
44 | /**
45 |  * Decrypts data received over a HomeKit session.
46 |  *
47 |  * @param      server               Accessory server.
48 |  * @param      session              The session over which the data has been received.
49 |  * @param      buffer               Encrypted data to be decrypted.
50 |  *
51 |  * @return kHAPError_None           If successful.
52 |  * @return kHAPError_InvalidData    If the controller sent a malformed data, or decryption failed.
53 |  */
54 | HAP_RESULT_USE_CHECK
55 | HAPError HAPIPSecurityProtocolDecryptData(
56 |         HAPAccessoryServerRef* server,
57 |         HAPSessionRef* session,
58 |         HAPIPByteBuffer* buffer);
59 | 
60 | #if __has_feature(nullability)
61 | #pragma clang assume_nonnull end
62 | #endif
63 | 
64 | #ifdef __cplusplus
65 | }
66 | #endif
67 | 
68 | #endif
69 | 


--------------------------------------------------------------------------------
/HAP/HAPIPServiceDiscovery.h:
--------------------------------------------------------------------------------
 1 | // Copyright (c) 2015-2019 The HomeKit ADK Contributors
 2 | //
 3 | // Licensed under the Apache License, Version 2.0 (the “License”);
 4 | // you may not use this file except in compliance with the License.
 5 | // See [CONTRIBUTORS.md] for the list of HomeKit ADK project authors.
 6 | 
 7 | #ifndef HAP_IP_SERVICE_DISCOVERY_H
 8 | #define HAP_IP_SERVICE_DISCOVERY_H
 9 | 
10 | #ifdef __cplusplus
11 | extern "C" {
12 | #endif
13 | 
14 | #include "HAP+Internal.h"
15 | 
16 | #if __has_feature(nullability)
17 | #pragma clang assume_nonnull begin
18 | #endif
19 | 
20 | /**
21 |  * The currently active service.
22 |  */
23 | HAP_ENUM_BEGIN(uint8_t, HAPIPServiceDiscoveryType) { /**
24 |                                                       * No Bonjour service discovery active.
25 |                                                       */
26 |                                                      kHAPIPServiceDiscoveryType_None,
27 | 
28 |                                                      /**
29 |                                                       * _hap service is currently being advertised.
30 |                                                       */
31 |                                                      kHAPIPServiceDiscoveryType_HAP,
32 | 
33 |                                                      /**
34 |                                                       * _mfi-config service is currently being advertised.
35 |                                                       */
36 |                                                      kHAPIPServiceDiscoveryType_MFiConfig
37 | } HAP_ENUM_END(uint8_t, HAPIPServiceDiscoveryType);
38 | 
39 | /**
40 |  * Registers or updates the Bonjour records for the _hap service.
41 |  *
42 |  * - Only one service may be active at a time. To switch services, first stop Bonjour service discovery.
43 |  *
44 |  * @param      server               Accessory server.
45 |  */
46 | void HAPIPServiceDiscoverySetHAPService(HAPAccessoryServerRef* server);
47 | 
48 | /**
49 |  * Registers or updates the Bonjour records for the _mfi-config service.
50 |  *
51 |  * - Only one service may be active at a time. To switch services, first stop Bonjour service discovery.
52 |  *
53 |  * @param      server               Accessory server.
54 |  */
55 | void HAPIPServiceDiscoverySetMFiConfigService(HAPAccessoryServerRef* server);
56 | 
57 | /**
58 |  * Stops Bonjour service discovery.
59 |  *
60 |  * @param      server               Accessory server.
61 |  */
62 | void HAPIPServiceDiscoveryStop(HAPAccessoryServerRef* server);
63 | 
64 | #if __has_feature(nullability)
65 | #pragma clang assume_nonnull end
66 | #endif
67 | 
68 | #ifdef __cplusplus
69 | }
70 | #endif
71 | 
72 | #endif
73 | 


--------------------------------------------------------------------------------
/HAP/HAPMACAddress.h:
--------------------------------------------------------------------------------
 1 | // Copyright (c) 2015-2019 The HomeKit ADK Contributors
 2 | //
 3 | // Licensed under the Apache License, Version 2.0 (the “License”);
 4 | // you may not use this file except in compliance with the License.
 5 | // See [CONTRIBUTORS.md] for the list of HomeKit ADK project authors.
 6 | 
 7 | #ifndef HAP_MAC_ADDRESS_H
 8 | #define HAP_MAC_ADDRESS_H
 9 | 
10 | #ifdef __cplusplus
11 | extern "C" {
12 | #endif
13 | 
14 | #include "HAP+Internal.h"
15 | 
16 | #if __has_feature(nullability)
17 | #pragma clang assume_nonnull begin
18 | #endif
19 | 
20 | /**
21 |  * Gets the random (static) MAC address for a Bluetooth interface.
22 |  *
23 |  * @param      server               Accessory server.
24 |  * @param      bleInterface         Bluetooth interface.
25 |  * @param[out] macAddress           MAC address, if successful.
26 |  *
27 |  * @return kHAPError_None           If successful.
28 |  * @return kHAPError_Unknown        If persistent store access failed.
29 |  *
30 |  * @see Bluetooth Core Specification Version 5
31 |  *      Vol 6 Part B Section 1.3.2.1 Static Device Address
32 |  */
33 | HAP_RESULT_USE_CHECK
34 | HAPError HAPMACAddressGetRandomStaticBLEDeviceAddress(
35 |         HAPAccessoryServerRef* server,
36 |         const char* _Nullable bleInterface,
37 |         HAPMACAddress* macAddress);
38 | 
39 | #if __has_feature(nullability)
40 | #pragma clang assume_nonnull end
41 | #endif
42 | 
43 | #ifdef __cplusplus
44 | }
45 | #endif
46 | 
47 | #endif
48 | 


--------------------------------------------------------------------------------
/HAP/HAPMFiAuth.h:
--------------------------------------------------------------------------------
 1 | // Copyright (c) 2015-2019 The HomeKit ADK Contributors
 2 | //
 3 | // Licensed under the Apache License, Version 2.0 (the “License”);
 4 | // you may not use this file except in compliance with the License.
 5 | // See [CONTRIBUTORS.md] for the list of HomeKit ADK project authors.
 6 | 
 7 | #ifndef HAP_MFI_AUTH_H
 8 | #define HAP_MFI_AUTH_H
 9 | 
10 | #ifdef __cplusplus
11 | extern "C" {
12 | #endif
13 | 
14 | #include "HAP+Internal.h"
15 | 
16 | #if __has_feature(nullability)
17 | #pragma clang assume_nonnull begin
18 | #endif
19 | 
20 | /**
21 |  * MFiAuth implementation.
22 |  */
23 | typedef struct {
24 |     /**
25 |      * Retrieves a copy of the MFi certificate.
26 |      *
27 |      * @param      server               Accessory server.
28 |      * @param[out] certificateBytes     MFi certificate buffer.
29 |      * @param      maxCertificateBytes  Capacity of MFi certificate buffer.
30 |      * @param[out] numCertificateBytes  Effective length of MFi certificate buffer.
31 |      *
32 |      * @return kHAPError_None           If successful.
33 |      * @return kHAPError_Unknown        If communication with the MFi component failed.
34 |      * @return kHAPError_OutOfResources If out of resources to process request.
35 |      */
36 |     HAP_RESULT_USE_CHECK
37 |     HAPError (*copyCertificate)(
38 |             HAPAccessoryServerRef* server,
39 |             void* certificateBytes,
40 |             size_t maxCertificateBytes,
41 |             size_t* numCertificateBytes);
42 | 
43 |     /**
44 |      * Signs the digest of a challenge with the MFi Private Key.
45 |      *
46 |      * @param      server               Accessory server.
47 |      * @param      challengeBytes       Challenge buffer.
48 |      * @param      numChallengeBytes    Length of challenge buffer.
49 |      * @param[out] signatureBytes       Signature buffer.
50 |      * @param      maxSignatureBytes    Capacity of signature buffer.
51 |      * @param[out] numSignatureBytes    Effective length of signature buffer.
52 |      *
53 |      * @return kHAPError_None           If successful.
54 |      * @return kHAPError_Unknown        If communication with the MFi component failed.
55 |      * @return kHAPError_OutOfResources If out of resources to process request.
56 |      */
57 |     HAP_RESULT_USE_CHECK
58 |     HAPError (*createSignature)(
59 |             HAPAccessoryServerRef* server,
60 |             const void* challengeBytes,
61 |             size_t numChallengeBytes,
62 |             void* signatureBytes,
63 |             size_t maxSignatureBytes,
64 |             size_t* numSignatureBytes);
65 | } HAPMFiAuth;
66 | 
67 | #if __has_feature(nullability)
68 | #pragma clang assume_nonnull end
69 | #endif
70 | 
71 | #ifdef __cplusplus
72 | }
73 | #endif
74 | 
75 | #endif
76 | 


--------------------------------------------------------------------------------
/HAP/HAPMFiTokenAuth.h:
--------------------------------------------------------------------------------
 1 | // Copyright (c) 2015-2019 The HomeKit ADK Contributors
 2 | //
 3 | // Licensed under the Apache License, Version 2.0 (the “License”);
 4 | // you may not use this file except in compliance with the License.
 5 | // See [CONTRIBUTORS.md] for the list of HomeKit ADK project authors.
 6 | 
 7 | #ifndef HAP_MFI_TOKEN_AUTH_H
 8 | #define HAP_MFI_TOKEN_AUTH_H
 9 | 
10 | #ifdef __cplusplus
11 | extern "C" {
12 | #endif
13 | 
14 | #include "HAP.h"
15 | 
16 | #if __has_feature(nullability)
17 | #pragma clang assume_nonnull begin
18 | #endif
19 | 
20 | /**
21 |  * Serializes the body of a HAP-Token-Read-Response.
22 |  *
23 |  * @param      server               Accessory server.
24 |  * @param      session              Session on which the request came in.
25 |  * @param      accessory            The accessory on which the request came in.
26 |  * @param      responseWriter       Writer to serialize Characteristic Signature into.
27 |  *
28 |  * @return kHAPError_None           If successful.
29 |  * @return kHAPError_Unknown        If an I/O error occurred.
30 |  * @return kHAPError_InvalidState   If no Software Token is provisioned.
31 |  * @return kHAPError_OutOfResources If writer does not have enough capacity.
32 |  */
33 | HAP_RESULT_USE_CHECK
34 | HAPError HAPMFiTokenAuthGetTokenResponse(
35 |         HAPAccessoryServerRef* server,
36 |         HAPSessionRef* session,
37 |         const HAPAccessory* accessory,
38 |         HAPTLVWriterRef* responseWriter);
39 | 
40 | /**
41 |  * Processes a HAP-Token-Update-Request.
42 |  *
43 |  * @param      server               Accessory server.
44 |  * @param      session              Session on which the request came in.
45 |  * @param      accessory            The accessory on which the request came in.
46 |  * @param      requestReader        Reader to parse request from. Reader content will become invalid.
47 |  *
48 |  * @return kHAPError_None           If successful.
49 |  * @return kHAPError_Unknown        If an I/O error occurred.
50 |  * @return kHAPError_InvalidState   If no Software Token is provisioned.
51 |  * @return kHAPError_InvalidData    If the controller sent a malformed request.
52 |  */
53 | HAP_RESULT_USE_CHECK
54 | HAPError HAPMFiTokenAuthHandleTokenUpdateRequest(
55 |         HAPAccessoryServerRef* server,
56 |         HAPSessionRef* session,
57 |         const HAPAccessory* accessory,
58 |         HAPTLVReaderRef* requestReader);
59 | 
60 | #if __has_feature(nullability)
61 | #pragma clang assume_nonnull end
62 | #endif
63 | 
64 | #ifdef __cplusplus
65 | }
66 | #endif
67 | 
68 | #endif
69 | 


--------------------------------------------------------------------------------
/HAP/HAPPDU.c:
--------------------------------------------------------------------------------
 1 | // Copyright (c) 2015-2019 The HomeKit ADK Contributors
 2 | //
 3 | // Licensed under the Apache License, Version 2.0 (the “License”);
 4 | // you may not use this file except in compliance with the License.
 5 | // See [CONTRIBUTORS.md] for the list of HomeKit ADK project authors.
 6 | 
 7 | #include "HAP+Internal.h"
 8 | 
 9 | HAP_RESULT_USE_CHECK
10 | bool HAPPDUIsValidOpcode(uint8_t value) {
11 |     HAPAssert(sizeof(HAPPDUOpcode) == sizeof value);
12 |     switch ((HAPPDUOpcode) value) {
13 |         case kHAPPDUOpcode_CharacteristicSignatureRead:
14 |         case kHAPPDUOpcode_CharacteristicWrite:
15 |         case kHAPPDUOpcode_CharacteristicRead:
16 |         case kHAPPDUOpcode_CharacteristicTimedWrite:
17 |         case kHAPPDUOpcode_CharacteristicExecuteWrite:
18 |         case kHAPPDUOpcode_ServiceSignatureRead:
19 |         case kHAPPDUOpcode_CharacteristicConfiguration:
20 |         case kHAPPDUOpcode_ProtocolConfiguration:
21 |         case kHAPPDUOpcode_Token:
22 |         case kHAPPDUOpcode_TokenUpdate:
23 |         case kHAPPDUOpcode_Info: {
24 |             return true;
25 |         }
26 |     }
27 |     return false;
28 | }
29 | 


--------------------------------------------------------------------------------
/HAP/HAPPairingBLESessionCache.h:
--------------------------------------------------------------------------------
 1 | // Copyright (c) 2015-2019 The HomeKit ADK Contributors
 2 | //
 3 | // Licensed under the Apache License, Version 2.0 (the “License”);
 4 | // you may not use this file except in compliance with the License.
 5 | // See [CONTRIBUTORS.md] for the list of HomeKit ADK project authors.
 6 | 
 7 | #ifndef HAP_PAIRING_BLE_SESSION_CACHE_H
 8 | #define HAP_PAIRING_BLE_SESSION_CACHE_H
 9 | 
10 | #ifdef __cplusplus
11 | extern "C" {
12 | #endif
13 | 
14 | #include "HAP+Internal.h"
15 | 
16 | #if __has_feature(nullability)
17 | #pragma clang assume_nonnull begin
18 | #endif
19 | 
20 | /**
21 |  * BLE: Pair Resume cache session ID.
22 |  */
23 | typedef struct {
24 |     uint8_t value[8]; /**< Session ID. */
25 | } HAPPairingBLESessionID;
26 | HAP_STATIC_ASSERT(sizeof(HAPPairingBLESessionID) == 8, HAPPairingBLESessionID);
27 | 
28 | /**
29 |  * Retrieves the shared secret and pairing ID for a session ID, if available.
30 |  *
31 |  * - The stored information is invalidated after fetching.
32 |  *
33 |  * @param      server               Accessory server.
34 |  * @param      sessionID            Session ID to retrieve data for.
35 |  * @param[out] sharedSecret         Shared secret.
36 |  * @param[out] pairingID            Pairing ID. -1, if session not found.
37 |  *
38 |  * @see HomeKit Accessory Protocol Specification R14
39 |  *      Section 7.3.7 Pair-Resume Procedure
40 |  */
41 | void HAPPairingBLESessionCacheFetch(
42 |         HAPAccessoryServerRef* server,
43 |         const HAPPairingBLESessionID* sessionID,
44 |         uint8_t sharedSecret[_Nonnull X25519_SCALAR_BYTES],
45 |         int* pairingID);
46 | 
47 | /**
48 |  * Stores the shared secret and pairing ID for a session ID.
49 |  *
50 |  * @param      server               Accessory server.
51 |  * @param      sessionID            Session ID.
52 |  * @param      sharedSecret         Shared secret.
53 |  * @param      pairingID            Pairing ID.
54 |  *
55 |  * @see HomeKit Accessory Protocol Specification R14
56 |  *      Section 7.3.7 Pair-Resume Procedure
57 |  */
58 | void HAPPairingBLESessionCacheSave(
59 |         HAPAccessoryServerRef* server,
60 |         const HAPPairingBLESessionID* sessionID,
61 |         uint8_t sharedSecret[_Nonnull X25519_SCALAR_BYTES],
62 |         int pairingID);
63 | 
64 | /**
65 |  * Invalidates Pair Resume cache entries related to a pairing.
66 |  *
67 |  * @param      server               Accessory server.
68 |  * @param      pairingID            Pairing ID.
69 |  */
70 | void HAPPairingBLESessionCacheInvalidateEntriesForPairing(HAPAccessoryServerRef* server, int pairingID);
71 | 
72 | #if __has_feature(nullability)
73 | #pragma clang assume_nonnull end
74 | #endif
75 | 
76 | #ifdef __cplusplus
77 | }
78 | #endif
79 | 
80 | #endif
81 | 


--------------------------------------------------------------------------------
/HAP/HAPPairingPairSetup.h:
--------------------------------------------------------------------------------
 1 | // Copyright (c) 2015-2019 The HomeKit ADK Contributors
 2 | //
 3 | // Licensed under the Apache License, Version 2.0 (the “License”);
 4 | // you may not use this file except in compliance with the License.
 5 | // See [CONTRIBUTORS.md] for the list of HomeKit ADK project authors.
 6 | 
 7 | #ifndef HAP_PAIRING_PAIR_SETUP_H
 8 | #define HAP_PAIRING_PAIR_SETUP_H
 9 | 
10 | #ifdef __cplusplus
11 | extern "C" {
12 | #endif
13 | 
14 | #include "HAP+Internal.h"
15 | 
16 | #if __has_feature(nullability)
17 | #pragma clang assume_nonnull begin
18 | #endif
19 | 
20 | /**
21 |  * Timeout value to avoid perpetual starvation in cases where a HAP session fails to make progress
22 |  * during a Pair Setup procedure.
23 |  */
24 | #define kHAPPairing_PairSetupProcedureTimeout ((HAPTime)(30 * HAPSecond))
25 | 
26 | /**
27 |  * Resets Pair Setup procedure state for a given session, e.g. after a session is terminated.
28 |  *
29 |  * @param      server               Accessory server.
30 |  * @param      session              Session to reset.
31 |  */
32 | void HAPPairingPairSetupResetForSession(HAPAccessoryServerRef* server, HAPSessionRef* session);
33 | 
34 | /**
35 |  * Processes a write request on the Pair Setup endpoint.
36 |  *
37 |  * @param      server               Accessory server.
38 |  * @param      session              The session over which the request has been received.
39 |  * @param      requestReader        TLV reader for parsing the value.
40 |  *
41 |  * @return kHAPError_None           If successful.
42 |  * @return kHAPError_InvalidState   If the request cannot be processed in the current state.
43 |  * @return kHAPError_InvalidData    If the controller sent a malformed request.
44 |  * @return kHAPError_OutOfResources If request reader does not have enough free memory.
45 |  */
46 | HAP_RESULT_USE_CHECK
47 | HAPError HAPPairingPairSetupHandleWrite(
48 |         HAPAccessoryServerRef* server,
49 |         HAPSessionRef* session,
50 |         HAPTLVReaderRef* requestReader);
51 | 
52 | /**
53 |  * Processes a read request on the Pair Setup endpoint.
54 |  *
55 |  * @param      server               Accessory server.
56 |  * @param      session              The session over which the response will be sent.
57 |  * @param      responseWriter       TLV writer for serializing the response.
58 |  *
59 |  * @return kHAPError_None           If successful.
60 |  * @return kHAPError_Unknown        If communication with Apple Authentication Coprocessor failed.
61 |  * @return kHAPError_InvalidState   If the request cannot be processed in the current state.
62 |  * @return kHAPError_OutOfResources If response writer does not have enough capacity.
63 |  */
64 | HAP_RESULT_USE_CHECK
65 | HAPError HAPPairingPairSetupHandleRead(
66 |         HAPAccessoryServerRef* server,
67 |         HAPSessionRef* session,
68 |         HAPTLVWriterRef* responseWriter);
69 | 
70 | #if __has_feature(nullability)
71 | #pragma clang assume_nonnull end
72 | #endif
73 | 
74 | #ifdef __cplusplus
75 | }
76 | #endif
77 | 
78 | #endif
79 | 


--------------------------------------------------------------------------------
/HAP/HAPPairingPairVerify.h:
--------------------------------------------------------------------------------
 1 | // Copyright (c) 2015-2019 The HomeKit ADK Contributors
 2 | //
 3 | // Licensed under the Apache License, Version 2.0 (the “License”);
 4 | // you may not use this file except in compliance with the License.
 5 | // See [CONTRIBUTORS.md] for the list of HomeKit ADK project authors.
 6 | 
 7 | #ifndef HAP_PAIRING_PAIR_VERIFY_H
 8 | #define HAP_PAIRING_PAIR_VERIFY_H
 9 | 
10 | #ifdef __cplusplus
11 | extern "C" {
12 | #endif
13 | 
14 | #include "HAP+Internal.h"
15 | 
16 | #if __has_feature(nullability)
17 | #pragma clang assume_nonnull begin
18 | #endif
19 | 
20 | /**
21 |  * Initializes Pair Verify procedure state for a given session.
22 |  *
23 |  * @param      session              Session.
24 |  */
25 | void HAPPairingPairVerifyReset(HAPSessionRef* session);
26 | 
27 | /**
28 |  * Processes a write request on the Pair Verify endpoint.
29 |  *
30 |  * @param      server               Accessory server.
31 |  * @param      session              The session over which the request has been received.
32 |  * @param      requestReader        TLV reader for parsing the value.
33 |  *
34 |  * @return kHAPError_None           If successful.
35 |  * @return kHAPError_InvalidState   If the request cannot be processed in the current state.
36 |  * @return kHAPError_InvalidData    If the controller sent a malformed request.
37 |  * @return kHAPError_OutOfResources If request reader does not have enough free memory.
38 |  */
39 | HAP_RESULT_USE_CHECK
40 | HAPError HAPPairingPairVerifyHandleWrite(
41 |         HAPAccessoryServerRef* server,
42 |         HAPSessionRef* session,
43 |         HAPTLVReaderRef* requestReader);
44 | 
45 | /**
46 |  * Processes a read request on the Pair Verify endpoint.
47 |  *
48 |  * @param      server               Accessory server.
49 |  * @param      session              The session over which the response will be sent.
50 |  * @param      responseWriter       TLV writer for serializing the response.
51 |  *
52 |  * @return kHAPError_None           If successful.
53 |  * @return kHAPError_InvalidState   If the request cannot be processed in the current state.
54 |  * @return kHAPError_OutOfResources If response writer does not have enough capacity.
55 |  */
56 | HAP_RESULT_USE_CHECK
57 | HAPError HAPPairingPairVerifyHandleRead(
58 |         HAPAccessoryServerRef* server,
59 |         HAPSessionRef* session,
60 |         HAPTLVWriterRef* responseWriter);
61 | 
62 | #if __has_feature(nullability)
63 | #pragma clang assume_nonnull end
64 | #endif
65 | 
66 | #ifdef __cplusplus
67 | }
68 | #endif
69 | 
70 | #endif
71 | 


--------------------------------------------------------------------------------
/HAP/HAPPairingPairings.h:
--------------------------------------------------------------------------------
 1 | // Copyright (c) 2015-2019 The HomeKit ADK Contributors
 2 | //
 3 | // Licensed under the Apache License, Version 2.0 (the “License”);
 4 | // you may not use this file except in compliance with the License.
 5 | // See [CONTRIBUTORS.md] for the list of HomeKit ADK project authors.
 6 | 
 7 | #ifndef HAP_PAIRING_PAIRINGS_H
 8 | #define HAP_PAIRING_PAIRINGS_H
 9 | 
10 | #ifdef __cplusplus
11 | extern "C" {
12 | #endif
13 | 
14 | #include "HAP+Internal.h"
15 | 
16 | #if __has_feature(nullability)
17 | #pragma clang assume_nonnull begin
18 | #endif
19 | 
20 | /**
21 |  * Initializes Pairings state for a given session.
22 |  *
23 |  * @param      session              Session.
24 |  */
25 | void HAPPairingPairingsReset(HAPSessionRef* session);
26 | 
27 | /**
28 |  * Processes a write request on the Pairings endpoint.
29 |  *
30 |  * @param      server               Accessory server.
31 |  * @param      session              The session over which the request has been received.
32 |  * @param      requestReader        TLV reader for parsing the value.
33 |  *
34 |  * @return kHAPError_None           If successful.
35 |  * @return kHAPError_InvalidState   If the request cannot be processed in the current state.
36 |  * @return kHAPError_InvalidData    If the controller sent a malformed request.
37 |  */
38 | HAP_RESULT_USE_CHECK
39 | HAPError HAPPairingPairingsHandleWrite(
40 |         HAPAccessoryServerRef* server,
41 |         HAPSessionRef* session,
42 |         HAPTLVReaderRef* requestReader);
43 | 
44 | /**
45 |  * Processes a read request on the Pairings endpoint.
46 |  *
47 |  * @param      server               Accessory server.
48 |  * @param      session              The session over which the response will be sent.
49 |  * @param      responseWriter       TLV writer for serializing the response.
50 |  *
51 |  * @return kHAPError_None           If successful.
52 |  * @return kHAPError_InvalidState   If the request cannot be processed in the current state.
53 |  * @return kHAPError_OutOfResources If response writer does not have enough capacity.
54 |  */
55 | HAP_RESULT_USE_CHECK
56 | HAPError HAPPairingPairingsHandleRead(
57 |         HAPAccessoryServerRef* server,
58 |         HAPSessionRef* session,
59 |         HAPTLVWriterRef* responseWriter);
60 | 
61 | #if __has_feature(nullability)
62 | #pragma clang assume_nonnull end
63 | #endif
64 | 
65 | #ifdef __cplusplus
66 | }
67 | #endif
68 | 
69 | #endif
70 | 


--------------------------------------------------------------------------------
/HAP/HAPRequestHandlers+HAPProtocolInformation.c:
--------------------------------------------------------------------------------
 1 | // Copyright (c) 2015-2019 The HomeKit ADK Contributors
 2 | //
 3 | // Licensed under the Apache License, Version 2.0 (the “License”);
 4 | // you may not use this file except in compliance with the License.
 5 | // See [CONTRIBUTORS.md] for the list of HomeKit ADK project authors.
 6 | 
 7 | #include "HAP+Internal.h"
 8 | 
 9 | static const HAPLogObject logObject = { .subsystem = kHAP_LogSubsystem, .category = "RequestHandlers" };
10 | 
11 | HAP_RESULT_USE_CHECK
12 | HAPError HAPHandleHAPProtocolInformationVersionRead(
13 |         HAPAccessoryServerRef* server HAP_UNUSED,
14 |         const HAPStringCharacteristicReadRequest* request,
15 |         char* value,
16 |         size_t maxValueBytes,
17 |         void* _Nullable context HAP_UNUSED) {
18 |     switch (request->transportType) {
19 |         case kHAPTransportType_IP: {
20 |             static const char version[] = kHAPProtocolVersion_IP;
21 |             size_t numBytes = sizeof version;
22 |             if (numBytes >= maxValueBytes) {
23 |                 HAPLog(&logObject, "Not enough space available to send IP protocol version.");
24 |                 return kHAPError_OutOfResources;
25 |             }
26 |             HAPRawBufferCopyBytes(value, version, numBytes);
27 |         }
28 |             return kHAPError_None;
29 |         case kHAPTransportType_BLE: {
30 |             static const char version[] = kHAPProtocolVersion_BLE;
31 |             size_t numBytes = sizeof version;
32 |             if (numBytes >= maxValueBytes) {
33 |                 HAPLog(&logObject, "Not enough space available to send BLE protocol version.");
34 |                 return kHAPError_OutOfResources;
35 |             }
36 |             HAPRawBufferCopyBytes(value, version, numBytes);
37 |         }
38 |             return kHAPError_None;
39 |     }
40 |     HAPFatalError();
41 | }
42 | 


--------------------------------------------------------------------------------
/HAP/HAPRequestHandlers+HAPProtocolInformation.h:
--------------------------------------------------------------------------------
 1 | // Copyright (c) 2015-2019 The HomeKit ADK Contributors
 2 | //
 3 | // Licensed under the Apache License, Version 2.0 (the “License”);
 4 | // you may not use this file except in compliance with the License.
 5 | // See [CONTRIBUTORS.md] for the list of HomeKit ADK project authors.
 6 | 
 7 | #ifndef HAP_REQUEST_HANDLERS_HAP_PROTOCOL_INFORMATION_H
 8 | #define HAP_REQUEST_HANDLERS_HAP_PROTOCOL_INFORMATION_H
 9 | 
10 | #ifdef __cplusplus
11 | extern "C" {
12 | #endif
13 | 
14 | #include "HAP.h"
15 | 
16 | #if __has_feature(nullability)
17 | #pragma clang assume_nonnull begin
18 | #endif
19 | 
20 | /**
21 |  * Handle read request to the 'Version' characteristic of the HAP Protocol Information service.
22 |  */
23 | HAP_RESULT_USE_CHECK
24 | HAPError HAPHandleHAPProtocolInformationVersionRead(
25 |         HAPAccessoryServerRef* server,
26 |         const HAPStringCharacteristicReadRequest* request,
27 |         char* value,
28 |         size_t maxValueBytes,
29 |         void* _Nullable context);
30 | 
31 | #if __has_feature(nullability)
32 | #pragma clang assume_nonnull end
33 | #endif
34 | 
35 | #ifdef __cplusplus
36 | }
37 | #endif
38 | 
39 | #endif
40 | 


--------------------------------------------------------------------------------
/HAP/HAPRequestHandlers.c:
--------------------------------------------------------------------------------
 1 | // Copyright (c) 2015-2019 The HomeKit ADK Contributors
 2 | //
 3 | // Licensed under the Apache License, Version 2.0 (the “License”);
 4 | // you may not use this file except in compliance with the License.
 5 | // See [CONTRIBUTORS.md] for the list of HomeKit ADK project authors.
 6 | 
 7 | #include "HAP+Internal.h"
 8 | 
 9 | static const HAPLogObject logObject = { .subsystem = kHAP_LogSubsystem, .category = "RequestHandlers" };
10 | 
11 | HAP_RESULT_USE_CHECK
12 | HAPError HAPHandleServiceSignatureRead(
13 |         HAPAccessoryServerRef* server HAP_UNUSED,
14 |         const HAPDataCharacteristicReadRequest* request HAP_UNUSED,
15 |         void* valueBytes HAP_UNUSED,
16 |         size_t maxValueBytes HAP_UNUSED,
17 |         size_t* numValueBytes,
18 |         void* _Nullable context HAP_UNUSED) {
19 |     // This seems to be required, as HAT crashes when characteristics properties are 0.
20 |     // Also, iOS 11 does not detect Service Signature for R10+ Protocol Configuration PDU if it is not readable.
21 |     HAPLog(&logObject,
22 |            "Sending dummy response to work around controller bugs with characteristic having 0 properties.");
23 |     *numValueBytes = 0;
24 |     return kHAPError_None;
25 | }
26 | 
27 | HAP_RESULT_USE_CHECK
28 | HAPError HAPHandleNameRead(
29 |         HAPAccessoryServerRef* server HAP_UNUSED,
30 |         const HAPStringCharacteristicReadRequest* request,
31 |         char* value,
32 |         size_t maxValueBytes,
33 |         void* _Nullable context HAP_UNUSED) {
34 |     HAPPrecondition(request->service->name);
35 |     const char* name = request->service->name;
36 | 
37 |     size_t numBytes = HAPStringGetNumBytes(name);
38 |     if (numBytes >= maxValueBytes) {
39 |         HAPLog(&logObject, "Not enough space available to send service name.");
40 |         return kHAPError_OutOfResources;
41 |     }
42 |     HAPRawBufferCopyBytes(value, name, numBytes);
43 |     value[numBytes] = '\0';
44 |     return kHAPError_None;
45 | }
46 | 


--------------------------------------------------------------------------------
/HAP/HAPTLVMemory.c:
--------------------------------------------------------------------------------
 1 | // Copyright (c) 2015-2019 The HomeKit ADK Contributors
 2 | //
 3 | // Licensed under the Apache License, Version 2.0 (the “License”);
 4 | // you may not use this file except in compliance with the License.
 5 | // See [CONTRIBUTORS.md] for the list of HomeKit ADK project authors.
 6 | 
 7 | #include "HAP+Internal.h"
 8 | 
 9 | void* _Nullable HAPTLVScratchBufferAlloc(
10 |         void* _Nonnull* _Nonnull scratchBytes,
11 |         size_t* maxScratchBytes,
12 |         size_t numBytes) {
13 |     if (!scratchBytes || !*scratchBytes || !maxScratchBytes || !*maxScratchBytes) {
14 |         return NULL;
15 |     }
16 | 
17 |     uint8_t* bytes = *scratchBytes;
18 |     HAP_DIAGNOSTIC_PUSH
19 |     HAP_DIAGNOSTIC_IGNORED_MSVC(4146)
20 |     uintptr_t o = (uintptr_t)(-(uintptr_t) bytes & 0x03);
21 |     if (*maxScratchBytes < numBytes + o) {
22 |         return NULL;
23 |     }
24 |     HAP_DIAGNOSTIC_POP
25 | 
26 |     *scratchBytes = &bytes[o + numBytes];
27 |     *maxScratchBytes -= o + numBytes;
28 |     return &bytes[o];
29 | }
30 | 
31 | void* _Nullable HAPTLVScratchBufferAllocUnaligned(
32 |         void* _Nonnull* _Nonnull scratchBytes,
33 |         size_t* numScratchBytes,
34 |         size_t numBytes) {
35 |     if (!scratchBytes || !*scratchBytes || !numScratchBytes || !*numScratchBytes) {
36 |         return NULL;
37 |     }
38 | 
39 |     uint8_t* bytes = *scratchBytes;
40 | 
41 |     if (*numScratchBytes < numBytes) {
42 |         return NULL;
43 |     }
44 |     *scratchBytes = &bytes[numBytes];
45 |     *numScratchBytes -= numBytes;
46 |     return bytes;
47 | }
48 | 


--------------------------------------------------------------------------------
/HAP/HAPVersion.c:
--------------------------------------------------------------------------------
 1 | // Copyright (c) 2015-2019 The HomeKit ADK Contributors
 2 | //
 3 | // Licensed under the Apache License, Version 2.0 (the “License”);
 4 | // you may not use this file except in compliance with the License.
 5 | // See [CONTRIBUTORS.md] for the list of HomeKit ADK project authors.
 6 | 
 7 | #include "HAP+Internal.h"
 8 | 
 9 | #if defined(HAP_IDENTIFICATION) || defined(HAP_VERSION) || defined(HAP_BUILD)
10 | #ifdef _MSC_VER
11 | #ifdef armv7
12 | // Windows CE 7.0 workaround to serialize the string "/ARM/MSVC/armv7-wince7/".
13 | #undef armv7
14 | #endif
15 | #define COMMAND_LINE_STRINGIFY_INNER(X) #X
16 | #define COMMAND_LINE_STRINGIFY(X)       COMMAND_LINE_STRINGIFY_INNER(X)
17 | #else
18 | #define COMMAND_LINE_STRINGIFY(X) X
19 | #endif
20 | #endif
21 | 
22 | HAP_RESULT_USE_CHECK
23 | uint32_t HAPGetCompatibilityVersion(void) {
24 |     return HAP_COMPATIBILITY_VERSION;
25 | }
26 | 
27 | const char* HAPGetIdentification(void) {
28 | #ifdef HAP_IDENTIFICATION
29 |     const char* identification = COMMAND_LINE_STRINGIFY(HAP_IDENTIFICATION);
30 | #else
31 |     const char* identification = "Unknown";
32 | #endif
33 | 
34 |     return identification;
35 | }
36 | 
37 | HAP_RESULT_USE_CHECK
38 | const char* HAPGetVersion(void) {
39 | #ifdef HAP_VERSION
40 |     const char* version = COMMAND_LINE_STRINGIFY(HAP_VERSION);
41 | #else
42 |     const char* version = "Internal";
43 | #endif
44 | 
45 |     return version;
46 | }
47 | 
48 | HAP_RESULT_USE_CHECK
49 | const char* HAPGetBuild(void) {
50 | #ifdef HAP_BUILD
51 |     const char* build = COMMAND_LINE_STRINGIFY(HAP_BUILD);
52 | #else
53 |     HAP_DIAGNOSTIC_PUSH
54 |     HAP_DIAGNOSTIC_IGNORED_CLANG("-Wdate-time")
55 |     const char* build = __DATE__ " " __TIME__;
56 |     HAP_DIAGNOSTIC_POP
57 | #endif
58 | 
59 |     return build;
60 | }
61 | 


--------------------------------------------------------------------------------
/Makefile:
--------------------------------------------------------------------------------
 1 | # Use "make TARGET=Linux all" to build for Linux
 2 | 
 3 | export
 4 | 
 5 | STEPS := all tests apps clean check info tools docs %.debug
 6 | .PHONY: $(STEPS) %.debug shell docker lint lint-changed
 7 | 
 8 | CWD := $(shell pwd)
 9 | HOST := $(shell uname)
10 | 
11 | NPROC :=
12 | ifeq ($(HOST),Darwin)
13 |   NPROC = sysctl -n hw.physicalcpu
14 | else
15 |   NPROC = nproc
16 | endif
17 | 
18 | TARGET ?= $(HOST)
19 | BUILD_TYPE ?= Debug
20 | MAKE := make -f Build/Makefile -j $(shell $(NPROC))
21 | DOCKER_EXE := DOCKER_BUILDKIT=0 docker
22 | DOCKER ?= 1
23 | 
24 | DOCKERFILE := Build/Docker/Dockerfile
25 | ifeq ($(TARGET),Raspi)
26 | 	DOCKERFILE := Build/Docker/Dockerfile.Raspi
27 | endif
28 | 
29 | ENABLE_TTY =
30 | MAKE_DOCKER = $(DOCKER_EXE) build - < $(DOCKERFILE) | tee /dev/stderr | grep "Successfully built" | cut -d ' ' -f 3
31 | RUN = $(DOCKER_EXE) run \
32 |   -e APPS \
33 |   -e BUILD_TYPE \
34 |   -e HOST \
35 |   -e LOG_LEVEL \
36 |   -e PROTOCOLS \
37 |   -e TARGET \
38 |   -e USE_HW_AUTH \
39 |   -e USE_NFC \
40 |   --cap-add=SYS_PTRACE \
41 |   --security-opt seccomp=unconfined \
42 |   --mount type=bind,source="$(CWD)",target=/build \
43 |   --rm \
44 |   -i $(ENABLE_TTY) `$(MAKE_DOCKER)`
45 | 
46 | ifeq ($(HOST)$(TARGET),LinuxDarwin)
47 | $(error Can't build $(TARGET) on $(HOST).)
48 | endif
49 | ifneq ($(TARGET),Darwin)
50 | 	ifneq (,$(wildcard /.dockerenv))
51 | 		# If we are already running inside docker
52 | 		MAKE := $(MAKE)
53 | 	else ifeq ($(DOCKER),0)
54 | 		MAKE := $(MAKE)
55 | 	else
56 | 		# Else run make inside docker
57 | 		MAKE := $(RUN) $(MAKE)
58 | 	endif
59 | endif
60 | 
61 | define make_target
62 |   $(1):
63 | 	@$(2) $@
64 | 
65 | endef
66 | 
67 | $(eval $(foreach step,$(STEPS),$(call make_target,$(step),$(MAKE) PAL=$(TARGET))))
68 | 
69 | shell: ENABLE_TTY=-t
70 | shell:
71 | 	@$(RUN) bash
72 | 
73 | docker:
74 | 	@$(MAKE_DOCKER)
75 | 
76 | # Lint (and correct) all files.
77 | lint:
78 | 	@Tools/linters/lint.sh -c
79 | 
80 | # Lint (and correct) all currently-changed files (according to git).
81 | lint-changed:
82 | 	@git diff-index --name-only HEAD \
83 | 	  | xargs printf -- '-f\0%s\0' \
84 |  	  | xargs -0 -- Tools/linters/lint.sh -Q -c
85 | 


--------------------------------------------------------------------------------
/PAL/Crypto/MbedTLS/Ed25519/LICENSE:
--------------------------------------------------------------------------------
 1 | 
 2 | The MIT License (MIT)
 3 | 
 4 | Copyright (c) 2015 mehdi sotoodeh
 5 | 
 6 | Permission is hereby granted, free of charge, to any person obtaining a copy
 7 | of this software and associated documentation files (the "Software"), to deal
 8 | in the Software without restriction, including without limitation the rights
 9 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 | copies of the Software, and to permit persons to whom the Software is
11 | furnished to do so, subject to the following conditions:
12 | 
13 | The above copyright notice and this permission notice shall be included in all
14 | copies or substantial portions of the Software.
15 | 
16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 | SOFTWARE.
23 | 


--------------------------------------------------------------------------------
/PAL/Crypto/MbedTLS/Ed25519/apple.h:
--------------------------------------------------------------------------------
 1 | // Copyright (c) 2019 The HomeKit ADK Contributors
 2 | //
 3 | // Licensed under the Apache License, Version 2.0 (the “License”);
 4 | // you may not use this file except in compliance with the License.
 5 | // See [CONTRIBUTORS.md] for the list of HomeKit ADK project authors.
 6 | 
 7 | #include "HAPCrypto.h"
 8 | 
 9 | #define SHA512_DIGEST_LENGTH SHA512_BYTES
10 | 
11 | #define mem_alloc(size)      malloc(size)
12 | #define mem_free(ptr)        free(ptr)
13 | #define mem_clear(ptr, size) memset(ptr, 0, size)
14 | 


--------------------------------------------------------------------------------
/PAL/Darwin/HAPPlatform+Init.h:
--------------------------------------------------------------------------------
 1 | // Copyright (c) 2015-2019 The HomeKit ADK Contributors
 2 | //
 3 | // Licensed under the Apache License, Version 2.0 (the “License”);
 4 | // you may not use this file except in compliance with the License.
 5 | // See [CONTRIBUTORS.md] for the list of HomeKit ADK project authors.
 6 | 
 7 | #ifndef HAP_PLATFORM_INIT_H
 8 | #define HAP_PLATFORM_INIT_H
 9 | 
10 | #ifdef __cplusplus
11 | extern "C" {
12 | #endif
13 | 
14 | /**
15 |  * Optional features set in Makefile.
16 |  */
17 | /**@{*/
18 | #ifndef HAVE_DISPLAY
19 | #define HAVE_DISPLAY 0
20 | #endif
21 | 
22 | #ifndef HAVE_MFI_HW_AUTH
23 | #define HAVE_MFI_HW_AUTH 0
24 | #endif
25 | /**@}*/
26 | 
27 | #include <stdlib.h>
28 | 
29 | #include "HAPPlatform.h"
30 | 
31 | #if __has_feature(nullability)
32 | #pragma clang assume_nonnull begin
33 | #endif
34 | 
35 | #if __has_feature(nullability)
36 | #pragma clang assume_nonnull end
37 | #endif
38 | 
39 | #ifdef __cplusplus
40 | }
41 | #endif
42 | 
43 | #endif
44 | 


--------------------------------------------------------------------------------
/PAL/Darwin/HAPPlatform.m:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2015-2019 The HomeKit ADK Contributors
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the “License”);
4 | // you may not use this file except in compliance with the License.
5 | // See [CONTRIBUTORS.md] for the list of HomeKit ADK project authors.
6 | 
7 | #include "POSIX/HAPPlatform.c"
8 | 


--------------------------------------------------------------------------------
/PAL/Darwin/HAPPlatformAbort.m:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2015-2019 The HomeKit ADK Contributors
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the “License”);
4 | // you may not use this file except in compliance with the License.
5 | // See [CONTRIBUTORS.md] for the list of HomeKit ADK project authors.
6 | 
7 | #include "POSIX/HAPPlatformAbort.c"
8 | 


--------------------------------------------------------------------------------
/PAL/Darwin/HAPPlatformAccessorySetup+Init.h:
--------------------------------------------------------------------------------
 1 | // Copyright (c) 2015-2019 The HomeKit ADK Contributors
 2 | //
 3 | // Licensed under the Apache License, Version 2.0 (the “License”);
 4 | // you may not use this file except in compliance with the License.
 5 | // See [CONTRIBUTORS.md] for the list of HomeKit ADK project authors.
 6 | 
 7 | #ifndef HAP_PLATFORM_ACCESSORY_SETUP_INIT_H
 8 | #define HAP_PLATFORM_ACCESSORY_SETUP_INIT_H
 9 | 
10 | #ifdef __cplusplus
11 | extern "C" {
12 | #endif
13 | 
14 | #ifndef HAVE_NFC
15 | #define HAVE_NFC 0
16 | #endif
17 | 
18 | #if HAVE_NFC
19 | #include <pthread.h>
20 | #include <nfc/nfc.h>
21 | #endif
22 | 
23 | #include "HAPPlatform.h"
24 | 
25 | #if __has_feature(nullability)
26 | #pragma clang assume_nonnull begin
27 | #endif
28 | 
29 | /**
30 |  * Accessory setup manager initialization options.
31 |  */
32 | typedef struct {
33 |     HAPPlatformKeyValueStore* keyValueStore;
34 | } HAPPlatformAccessorySetupOptions;
35 | 
36 | /**
37 |  * Accessory setup manager.
38 |  */
39 | struct HAPPlatformAccessorySetup {
40 |     // Opaque type. Do not access the instance fields directly.
41 |     /**@cond */
42 |     char _;
43 |     /**@endcond */
44 | };
45 | 
46 | /**
47 |  * Initializes the accessory setup manager.
48 |  *
49 |  * @param[out] accessorySetup       Pointer to an allocated but uninitialized HAPPlatformAccessorySetup structure.
50 |  * @param      options              Initialization options.
51 |  */
52 | void HAPPlatformAccessorySetupCreate(
53 |         HAPPlatformAccessorySetupRef accessorySetup,
54 |         const HAPPlatformAccessorySetupOptions* options);
55 | 
56 | /**
57 |  * Releases resources associated with an initialized accessory setup manager.
58 |  *
59 |  * @param      accessorySetup       Accessory setup manager.
60 |  */
61 | void HAPPlatformAccessorySetupRelease(HAPPlatformAccessorySetupRef accessorySetup);
62 | 
63 | #if __has_feature(nullability)
64 | #pragma clang assume_nonnull end
65 | #endif
66 | 
67 | #ifdef __cplusplus
68 | }
69 | #endif
70 | 
71 | #endif
72 | 


--------------------------------------------------------------------------------
/PAL/Darwin/HAPPlatformAccessorySetup.m:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2015-2019 The HomeKit ADK Contributors
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the “License”);
4 | // you may not use this file except in compliance with the License.
5 | // See [CONTRIBUTORS.md] for the list of HomeKit ADK project authors.
6 | 
7 | #include "Mock/HAPPlatformAccessorySetup.c"
8 | 


--------------------------------------------------------------------------------
/PAL/Darwin/HAPPlatformAccessorySetupDisplay.m:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2015-2019 The HomeKit ADK Contributors
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the “License”);
4 | // you may not use this file except in compliance with the License.
5 | // See [CONTRIBUTORS.md] for the list of HomeKit ADK project authors.
6 | 
7 | #include "Mock/HAPPlatformAccessorySetupDisplay.c"
8 | 


--------------------------------------------------------------------------------
/PAL/Darwin/HAPPlatformAccessorySetupNFC.m:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2015-2019 The HomeKit ADK Contributors
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the “License”);
4 | // you may not use this file except in compliance with the License.
5 | // See [CONTRIBUTORS.md] for the list of HomeKit ADK project authors.
6 | 
7 | #include "Mock/HAPPlatformAccessorySetupNFC.c"
8 | 


--------------------------------------------------------------------------------
/PAL/Darwin/HAPPlatformBLEPeripheralManager+Init.h:
--------------------------------------------------------------------------------
 1 | // Copyright (c) 2015-2019 The HomeKit ADK Contributors
 2 | //
 3 | // Licensed under the Apache License, Version 2.0 (the “License”);
 4 | // you may not use this file except in compliance with the License.
 5 | // See [CONTRIBUTORS.md] for the list of HomeKit ADK project authors.
 6 | 
 7 | #ifndef HAP_PLATFORM_BLE_PERIPHERAL_MANAGER_INIT_H
 8 | #define HAP_PLATFORM_BLE_PERIPHERAL_MANAGER_INIT_H
 9 | 
10 | #ifdef __cplusplus
11 | extern "C" {
12 | #endif
13 | 
14 | #include "HAPPlatform.h"
15 | 
16 | #if __has_feature(nullability)
17 | #pragma clang assume_nonnull begin
18 | #endif
19 | 
20 | /**
21 |  * BLE peripheral manager initialization options.
22 |  */
23 | typedef struct {
24 |     /**
25 |      * Key-value store.
26 |      * If critical data is pending, BLE reads will be delayed until the data is persisted.
27 |      */
28 |     HAPPlatformKeyValueStoreRef keyValueStore;
29 | } HAPPlatformBLEPeripheralManagerOptions;
30 | 
31 | /**
32 |  * BLE peripheral manager.
33 |  */
34 | struct HAPPlatformBLEPeripheralManager {
35 |     // Opaque type. Do not access the instance fields directly.
36 |     /**@cond */
37 |     char _;
38 |     /**@endcond */
39 | };
40 | 
41 | /**
42 |  * Initializes the BLE peripheral manager.
43 |  *
44 |  * @param[out] blePeripheralManager Pointer to an allocated but uninitialized HAPPlatformBLEPeripheralManager structure.
45 |  * @param      options              Initialization options.
46 |  */
47 | void HAPPlatformBLEPeripheralManagerCreate(
48 |         HAPPlatformBLEPeripheralManagerRef blePeripheralManager,
49 |         const HAPPlatformBLEPeripheralManagerOptions* options);
50 | 
51 | #if __has_feature(nullability)
52 | #pragma clang assume_nonnull end
53 | #endif
54 | 
55 | #ifdef __cplusplus
56 | }
57 | #endif
58 | 
59 | #endif
60 | 


--------------------------------------------------------------------------------
/PAL/Darwin/HAPPlatformClock.m:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2015-2019 The HomeKit ADK Contributors
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the “License”);
4 | // you may not use this file except in compliance with the License.
5 | // See [CONTRIBUTORS.md] for the list of HomeKit ADK project authors.
6 | 
7 | #include "POSIX/HAPPlatformClock.c"
8 | 


--------------------------------------------------------------------------------
/PAL/Darwin/HAPPlatformKeyValueStore+Init.h:
--------------------------------------------------------------------------------
 1 | // Copyright (c) 2015-2019 The HomeKit ADK Contributors
 2 | //
 3 | // Licensed under the Apache License, Version 2.0 (the “License”);
 4 | // you may not use this file except in compliance with the License.
 5 | // See [CONTRIBUTORS.md] for the list of HomeKit ADK project authors.
 6 | 
 7 | #ifndef HAP_PLATFORM_KEY_VALUE_STORE_INIT_H
 8 | #define HAP_PLATFORM_KEY_VALUE_STORE_INIT_H
 9 | 
10 | #ifdef __cplusplus
11 | extern "C" {
12 | #endif
13 | 
14 | #include "HAPPlatform.h"
15 | 
16 | #if __has_feature(nullability)
17 | #pragma clang assume_nonnull begin
18 | #endif
19 | 
20 | /**@file
21 |  * File system based key-value store.
22 |  *
23 |  * **Example**
24 | 
25 |    @code{.c}
26 | 
27 |    // Allocate key-value store.
28 |    static HAPPlatformKeyValueStore keyValueStore;
29 | 
30 |    // Initialize key-value store.
31 |    HAPPlatformKeyValueStoreCreate(&platform.keyValueStore,
32 |        &(const HAPPlatformKeyValueStoreOptions) {
33 |            .rootDirectory = ".HomeKitStore" // May be changed to store into a different directory.
34 |        });
35 | 
36 |    @endcode
37 |  */
38 | 
39 | /**
40 |  * Key-value store initialization options.
41 |  */
42 | typedef struct {
43 |     /**
44 |      * Root directory into which the values will be stored as files.
45 |      *
46 |      * - This directory is relative to the directory from which the application is executing,
47 |      *   i.e. not relative to the application binary.
48 |      */
49 |     const char* rootDirectory;
50 | } HAPPlatformKeyValueStoreOptions;
51 | 
52 | /**
53 |  * Key-value store.
54 |  */
55 | struct HAPPlatformKeyValueStore {
56 |     // Opaque type. Do not access the instance fields directly.
57 |     /**@cond */
58 |     const char* rootDirectory;
59 |     /**@endcond */
60 | };
61 | 
62 | /**
63 |  * Initializes the key-value store.
64 |  *
65 |  * @param[out] keyValueStore        Pointer to an allocated but uninitialized HAPPlatformKeyValueStore structure.
66 |  * @param      options              Initialization options.
67 |  */
68 | void HAPPlatformKeyValueStoreCreate(
69 |         HAPPlatformKeyValueStoreRef keyValueStore,
70 |         const HAPPlatformKeyValueStoreOptions* options);
71 | 
72 | #if __has_feature(nullability)
73 | #pragma clang assume_nonnull end
74 | #endif
75 | 
76 | #ifdef __cplusplus
77 | }
78 | #endif
79 | 
80 | #endif
81 | 


--------------------------------------------------------------------------------
/PAL/Darwin/HAPPlatformKeyValueStore+SDKDomains.h:
--------------------------------------------------------------------------------
 1 | // Copyright (c) 2015-2019 The HomeKit ADK Contributors
 2 | //
 3 | // Licensed under the Apache License, Version 2.0 (the “License”);
 4 | // you may not use this file except in compliance with the License.
 5 | // See [CONTRIBUTORS.md] for the list of HomeKit ADK project authors.
 6 | 
 7 | #ifndef HAP_PLATFORM_KEY_VALUE_STORE_SDK_DOMAINS_H
 8 | #define HAP_PLATFORM_KEY_VALUE_STORE_SDK_DOMAINS_H
 9 | 
10 | #ifdef __cplusplus
11 | extern "C" {
12 | #endif
13 | 
14 | #include "HAPPlatform.h"
15 | 
16 | /**
17 |  * Statically provisioned data.
18 |  *
19 |  * Purged: Never.
20 |  */
21 | #define kSDKKeyValueStoreDomain_Provisioning ((HAPPlatformKeyValueStoreDomain) 0x40)
22 | 
23 | ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
24 | 
25 | /**
26 |  * Static Setup Code salt & verifier.
27 |  *
28 |  * Format: HAPSetupInfo.
29 |  */
30 | #define kSDKKeyValueStoreKey_Provisioning_SetupInfo ((HAPPlatformKeyValueStoreKey) 0x10)
31 | 
32 | /**
33 |  * Setup ID.
34 |  *
35 |  * Format: HAPSetupID.
36 |  */
37 | #define kSDKKeyValueStoreKey_Provisioning_SetupID ((HAPPlatformKeyValueStoreKey) 0x11)
38 | 
39 | /**
40 |  * Setup Code for NFC.
41 |  *
42 |  * Format: HAPSetupCode.
43 |  */
44 | #define kSDKKeyValueStoreKey_Provisioning_SetupCode ((HAPPlatformKeyValueStoreKey) 0x12)
45 | 
46 | /**
47 |  * Software Token UUID.
48 |  *
49 |  * Format: HAPPlatformMFiTokenAuthUUID.
50 |  */
51 | #define kSDKKeyValueStoreKey_Provisioning_MFiTokenUUID ((HAPPlatformKeyValueStoreKey) 0x20)
52 | 
53 | /**
54 |  * Software Token.
55 |  *
56 |  * Format: Opaque blob, up to kHAPPlatformMFiTokenAuth_MaxMFiTokenBytes bytes.
57 |  */
58 | #define kSDKKeyValueStoreKey_Provisioning_MFiToken ((HAPPlatformKeyValueStoreKey) 0x21)
59 | 
60 | #ifdef __cplusplus
61 | }
62 | #endif
63 | 
64 | #endif
65 | 


--------------------------------------------------------------------------------
/PAL/Darwin/HAPPlatformLog+Init.h:
--------------------------------------------------------------------------------
 1 | // Copyright (c) 2015-2019 The HomeKit ADK Contributors
 2 | //
 3 | // Licensed under the Apache License, Version 2.0 (the “License”);
 4 | // you may not use this file except in compliance with the License.
 5 | // See [CONTRIBUTORS.md] for the list of HomeKit ADK project authors.
 6 | 
 7 | #ifndef HAP_PLATFORM_LOG_INIT_H
 8 | #define HAP_PLATFORM_LOG_INIT_H
 9 | 
10 | #ifdef __cplusplus
11 | extern "C" {
12 | #endif
13 | 
14 | #include "HAPPlatform.h"
15 | 
16 | #if __has_feature(nullability)
17 | #pragma clang assume_nonnull begin
18 | #endif
19 | 
20 | /**
21 |  * Logs a POSIX error, for example fetched from errno.
22 |  *
23 |  * - The error number will be mapped to a locale-dependent error message string.
24 |  *
25 |  * @param      type                 A log type constant, indicating the level of logging to perform.
26 |  * @param      message              The log message.
27 |  * @param      errorNumber          POSIX error number.
28 |  * @param      function             Function name in which the error occurred.
29 |  * @param      file                 File name in which the error occurred.
30 |  * @param      line                 Line number on which the error occurred.
31 |  */
32 | void HAPPlatformLogPOSIXError(
33 |         HAPLogType type,
34 |         const char* message,
35 |         int errorNumber,
36 |         const char* function,
37 |         const char* file,
38 |         int line);
39 | 
40 | #if __has_feature(nullability)
41 | #pragma clang assume_nonnull end
42 | #endif
43 | 
44 | #ifdef __cplusplus
45 | }
46 | #endif
47 | 
48 | #endif
49 | 


--------------------------------------------------------------------------------
/PAL/Darwin/HAPPlatformLog.m:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2015-2019 The HomeKit ADK Contributors
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the “License”);
4 | // you may not use this file except in compliance with the License.
5 | // See [CONTRIBUTORS.md] for the list of HomeKit ADK project authors.
6 | 
7 | #include "POSIX/HAPPlatformLog.c"
8 | 


--------------------------------------------------------------------------------
/PAL/Darwin/HAPPlatformMFiHWAuth+Init.h:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2015-2019 The HomeKit ADK Contributors
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the “License”);
4 | // you may not use this file except in compliance with the License.
5 | // See [CONTRIBUTORS.md] for the list of HomeKit ADK project authors.
6 | 
7 | #include "Mock/HAPPlatformMFiHWAuth+Init.h"
8 | 


--------------------------------------------------------------------------------
/PAL/Darwin/HAPPlatformMFiHWAuth.m:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2015-2019 The HomeKit ADK Contributors
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the “License”);
4 | // you may not use this file except in compliance with the License.
5 | // See [CONTRIBUTORS.md] for the list of HomeKit ADK project authors.
6 | 
7 | #include "Mock/HAPPlatformMFiHWAuth.c"
8 | 


--------------------------------------------------------------------------------
/PAL/Darwin/HAPPlatformMFiTokenAuth+Init.h:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2015-2019 The HomeKit ADK Contributors
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the “License”);
4 | // you may not use this file except in compliance with the License.
5 | // See [CONTRIBUTORS.md] for the list of HomeKit ADK project authors.
6 | 
7 | #include "POSIX/HAPPlatformMFiTokenAuth+Init.h"
8 | 


--------------------------------------------------------------------------------
/PAL/Darwin/HAPPlatformMFiTokenAuth.m:
--------------------------------------------------------------------------------
 1 | // Copyright (c) 2015-2019 The HomeKit ADK Contributors
 2 | //
 3 | // Licensed under the Apache License, Version 2.0 (the “License”);
 4 | // you may not use this file except in compliance with the License.
 5 | // See [CONTRIBUTORS.md] for the list of HomeKit ADK project authors.
 6 | 
 7 | #include "HAPPlatformMFiTokenAuth+Init.h"
 8 | 
 9 | #include "Mock/HAPPlatformMFiTokenAuth.c"
10 | 


--------------------------------------------------------------------------------
/PAL/Darwin/HAPPlatformRandomNumber.m:
--------------------------------------------------------------------------------
 1 | // Copyright (c) 2015-2019 The HomeKit ADK Contributors
 2 | //
 3 | // Licensed under the Apache License, Version 2.0 (the “License”);
 4 | // you may not use this file except in compliance with the License.
 5 | // See [CONTRIBUTORS.md] for the list of HomeKit ADK project authors.
 6 | 
 7 | #include "HAPPlatform.h"
 8 | #include <stdlib.h>
 9 | 
10 | void HAPPlatformRandomNumberFill(void* bytes, size_t numBytes) {
11 |     arc4random_buf(bytes, numBytes);
12 | }
13 | 


--------------------------------------------------------------------------------
/PAL/Darwin/HAPPlatformRunLoop+Init.h:
--------------------------------------------------------------------------------
 1 | // Copyright (c) 2015-2019 The HomeKit ADK Contributors
 2 | //
 3 | // Licensed under the Apache License, Version 2.0 (the “License”);
 4 | // you may not use this file except in compliance with the License.
 5 | // See [CONTRIBUTORS.md] for the list of HomeKit ADK project authors.
 6 | 
 7 | #ifndef HAP_PLATFORM_RUN_LOOP_INIT_H
 8 | #define HAP_PLATFORM_RUN_LOOP_INIT_H
 9 | 
10 | #ifdef __cplusplus
11 | extern "C" {
12 | #endif
13 | 
14 | #include "HAPPlatform.h"
15 | 
16 | #if __has_feature(nullability)
17 | #pragma clang assume_nonnull begin
18 | #endif
19 | 
20 | /**
21 |  * Run loop initialization options.
22 |  */
23 | typedef struct {
24 |     /**
25 |      * Key-value store.
26 |      */
27 |     HAPPlatformKeyValueStoreRef keyValueStore;
28 | } HAPPlatformRunLoopOptions;
29 | 
30 | /**
31 |  * Initializes the run loop.
32 |  *
33 |  * @param      options              Initialization options.
34 |  */
35 | void HAPPlatformRunLoopCreate(const HAPPlatformRunLoopOptions* options);
36 | 
37 | /**
38 |  * Release run loop.
39 |  */
40 | void HAPPlatformRunLoopRelease(void);
41 | 
42 | #if __has_feature(nullability)
43 | #pragma clang assume_nonnull end
44 | #endif
45 | 
46 | #ifdef __cplusplus
47 | }
48 | #endif
49 | 
50 | #endif
51 | 


--------------------------------------------------------------------------------
/PAL/Darwin/HAPPlatformRunLoop.m:
--------------------------------------------------------------------------------
 1 | // Copyright (c) 2015-2019 The HomeKit ADK Contributors
 2 | //
 3 | // Licensed under the Apache License, Version 2.0 (the “License”);
 4 | // you may not use this file except in compliance with the License.
 5 | // See [CONTRIBUTORS.md] for the list of HomeKit ADK project authors.
 6 | 
 7 | #include "HAPPlatformRunLoop+Init.h"
 8 | 
 9 | #import <Foundation/Foundation.h>
10 | 
11 | void HAPPlatformRunLoopCreate(const HAPPlatformRunLoopOptions* options) {
12 |     HAPPrecondition(options);
13 |     HAPPrecondition(options->keyValueStore);
14 | }
15 | 
16 | void HAPPlatformRunLoopRelease(void) {
17 | }
18 | 
19 | void HAPPlatformRunLoopRun(void) {
20 |     CFRunLoopRun();
21 | }
22 | 
23 | HAP_RESULT_USE_CHECK
24 | HAPError HAPPlatformRunLoopScheduleCallback(
25 |         HAPPlatformRunLoopCallback callback,
26 |         void* _Nullable context,
27 |         size_t contextSize) {
28 |     dispatch_async(dispatch_get_main_queue(), ^{
29 |         callback(context, contextSize);
30 |     });
31 |     return kHAPError_None;
32 | }
33 | 
34 | void HAPPlatformRunLoopStop(void) {
35 |     CFRunLoopStop(CFRunLoopGetCurrent());
36 | }
37 | 


--------------------------------------------------------------------------------
/PAL/Darwin/HAPPlatformServiceDiscovery+Init.h:
--------------------------------------------------------------------------------
 1 | // Copyright (c) 2015-2019 The HomeKit ADK Contributors
 2 | //
 3 | // Licensed under the Apache License, Version 2.0 (the “License”);
 4 | // you may not use this file except in compliance with the License.
 5 | // See [CONTRIBUTORS.md] for the list of HomeKit ADK project authors.
 6 | 
 7 | #ifndef HAP_PLATFORM_SERVICE_DISCOVERY_INIT_H
 8 | #define HAP_PLATFORM_SERVICE_DISCOVERY_INIT_H
 9 | 
10 | #ifdef __cplusplus
11 | extern "C" {
12 | #endif
13 | 
14 | #include <dns_sd.h>
15 | #include <net/if.h>
16 | 
17 | #include "HAPPlatform.h"
18 | 
19 | #if __has_feature(nullability)
20 | #pragma clang assume_nonnull begin
21 | #endif
22 | 
23 | /**@file
24 |  * Bonjour service discovery for Darwin based on NSNetService.
25 |  *
26 |  * **Example**
27 | 
28 |    @code{.c}
29 | 
30 |    // Allocate service discovery object.
31 |    static HAPPlatformServiceDiscovery serviceDiscovery;
32 | 
33 |    // Initialize service discovery object. Depends on a TCP stream manager instance.
34 |    HAPPlatformServiceDiscoveryCreate(&platform.serviceDiscovery,
35 |        &(const HAPPlatformServiceDiscoveryOptions) {
36 |            // Register services on all available network interfaces.
37 |            .interfaceName = NULL
38 |        });
39 | 
40 |    @endcode
41 |  */
42 | 
43 | /**
44 |  * Service discovery initialization options.
45 |  */
46 | typedef struct {
47 |     /**
48 |      * Local network interface name on which to register services.
49 |      * A value of NULL will use all available network interfaces.
50 |      */
51 |     const char* _Nullable interfaceName;
52 | } HAPPlatformServiceDiscoveryOptions;
53 | 
54 | /**
55 |  * Service discovery memory configuration value.
56 |  */
57 | #define kHAPPlatformServiceDiscovery_MaxTXTRecordBufferBytes (512)
58 | 
59 | /**
60 |  * Service discovery.
61 |  */
62 | struct HAPPlatformServiceDiscovery {
63 |     // Opaque type. Do not access the instance fields directly.
64 |     /**@cond */
65 |     char _;
66 |     /**@endcond */
67 | };
68 | 
69 | /**
70 |  * Initializes service discovery.
71 |  *
72 |  * @param      serviceDiscovery     Pointer to an allocated but uninitialized HAPPlatformServiceDiscovery structure.
73 |  * @param      options              Initialization options.
74 |  */
75 | void HAPPlatformServiceDiscoveryCreate(
76 |         HAPPlatformServiceDiscoveryRef serviceDiscovery,
77 |         const HAPPlatformServiceDiscoveryOptions* options);
78 | 
79 | #if __has_feature(nullability)
80 | #pragma clang assume_nonnull end
81 | #endif
82 | 
83 | #ifdef __cplusplus
84 | }
85 | #endif
86 | 
87 | #endif
88 | 


--------------------------------------------------------------------------------
/PAL/Darwin/HAPPlatformServiceDiscovery.m:
--------------------------------------------------------------------------------
 1 | // Copyright (c) 2015-2019 The HomeKit ADK Contributors
 2 | //
 3 | // Licensed under the Apache License, Version 2.0 (the “License”);
 4 | // you may not use this file except in compliance with the License.
 5 | // See [CONTRIBUTORS.md] for the list of HomeKit ADK project authors.
 6 | 
 7 | #include "HAPPlatformServiceDiscovery+Init.h"
 8 | 
 9 | #import <Foundation/Foundation.h>
10 | 
11 | static const HAPLogObject sd_log = { .subsystem = kHAPPlatform_LogSubsystem, .category = "ServiceDiscovery" };
12 | 
13 | static NSNetService* service = nil;
14 | 
15 | void HAPPlatformServiceDiscoveryCreate(
16 |         HAPPlatformServiceDiscoveryRef serviceDiscovery,
17 |         const HAPPlatformServiceDiscoveryOptions* options) {
18 |     HAPPrecondition(serviceDiscovery);
19 |     (void) options;
20 | }
21 | 
22 | void HAPPlatformServiceDiscoveryRegister(
23 |         HAPPlatformServiceDiscoveryRef serviceDiscovery,
24 |         const char* name,
25 |         const char* protocol,
26 |         uint16_t port,
27 |         HAPPlatformServiceDiscoveryTXTRecord* txtRecords,
28 |         size_t numTXTRecords) {
29 |     HAPPrecondition(serviceDiscovery);
30 |     HAPPrecondition(!service);
31 |     HAPPrecondition(name);
32 |     HAPPrecondition(protocol);
33 |     HAPPrecondition(!numTXTRecords || txtRecords);
34 |     service = [[NSNetService alloc] initWithDomain:@"" type:@(protocol) name:@(name) port:port];
35 |     HAPPlatformServiceDiscoveryUpdateTXTRecords(serviceDiscovery, txtRecords, numTXTRecords);
36 |     [service publish];
37 | 
38 |     HAPLog(&sd_log, "Publishing %s:%s on port %u", name, protocol, port);
39 | }
40 | 
41 | void HAPPlatformServiceDiscoveryUpdateTXTRecords(
42 |         HAPPlatformServiceDiscoveryRef serviceDiscovery,
43 |         HAPPlatformServiceDiscoveryTXTRecord* txtRecords,
44 |         size_t numTXTRecords) {
45 |     HAPPrecondition(serviceDiscovery);
46 |     HAPPrecondition(service);
47 |     HAPPrecondition(!numTXTRecords || txtRecords);
48 |     NSMutableDictionary* txt = [NSMutableDictionary dictionaryWithCapacity:numTXTRecords];
49 |     for (HAPPlatformServiceDiscoveryTXTRecord* p = txtRecords; p < txtRecords + numTXTRecords; ++p) {
50 |         [txt setObject:[NSData dataWithBytes:p->value.bytes length:p->value.numBytes] forKey:@(p->key)];
51 |         HAPLogBuffer(&sd_log, p->value.bytes, p->value.numBytes, "TXT record");
52 |     }
53 |     [service setTXTRecordData:[NSNetService dataFromTXTRecordDictionary:txt]];
54 | }
55 | 
56 | void HAPPlatformServiceDiscoveryStop(HAPPlatformServiceDiscoveryRef serviceDiscovery) {
57 |     HAPPrecondition(serviceDiscovery);
58 |     HAPPrecondition(service);
59 |     [service stop];
60 |     service = nil;
61 | }
62 | 


--------------------------------------------------------------------------------
/PAL/Darwin/HAPPlatformTCPStreamManager+Init.h:
--------------------------------------------------------------------------------
 1 | // Copyright (c) 2015-2019 The HomeKit ADK Contributors
 2 | //
 3 | // Licensed under the Apache License, Version 2.0 (the “License”);
 4 | // you may not use this file except in compliance with the License.
 5 | // See [CONTRIBUTORS.md] for the list of HomeKit ADK project authors.
 6 | 
 7 | #ifndef HAP_PLATFORM_TCP_STREAM_MANAGER_INIT_H
 8 | #define HAP_PLATFORM_TCP_STREAM_MANAGER_INIT_H
 9 | 
10 | #ifdef __cplusplus
11 | extern "C" {
12 | #endif
13 | 
14 | #include "HAPPlatform.h"
15 | 
16 | #if __has_feature(nullability)
17 | #pragma clang assume_nonnull begin
18 | #endif
19 | 
20 | typedef struct {
21 |     // Opaque type. Do not access the instance fields directly.
22 |     /**@cond */
23 |     char _;
24 |     /**@endcond */
25 | } HAPPlatformTCPStream;
26 | 
27 | /**
28 |  * TCP stream manager.
29 |  */
30 | struct HAPPlatformTCPStreamManager {
31 |     // Opaque type. Do not access the instance fields directly.
32 |     /**@cond */
33 |     char _;
34 |     /**@endcond */
35 | };
36 | 
37 | /**
38 |  * Default buffer size.
39 |  */
40 | #define kHAPPlatformTCPStreamManager_NumBufferBytes ((size_t) 4 * 1024)
41 | 
42 | /**
43 |  * Key-value store initialization options.
44 |  */
45 | typedef struct {
46 |     /**
47 |      * Local network interface name on which to bind the TCP stream manager.
48 |      * A value of NULL will use all available network interfaces.
49 |      */
50 |     const char* _Nullable interfaceName;
51 | 
52 |     /**
53 |      * Local port number on which to bind the TCP stream manager.
54 |      * A value of 0 will use an unused port number from the ephemeral port range.
55 |      */
56 |     uint16_t port;
57 | 
58 |     /**
59 |      * Maximum number of concurrent TCP streams.
60 |      */
61 |     size_t maxConcurrentTCPStreams;
62 | } HAPPlatformTCPStreamManagerOptions;
63 | 
64 | /**
65 |  * Initializes a TCP stream manager.
66 |  *
67 |  * @param[out] tcpStreamManager     Pointer to an allocated but uninitialized HAPPlatformTCPStreamManager structure.
68 |  * @param      options              Initialization options.
69 |  */
70 | void HAPPlatformTCPStreamManagerCreate(
71 |         HAPPlatformTCPStreamManagerRef tcpStreamManager,
72 |         const HAPPlatformTCPStreamManagerOptions* options);
73 | 
74 | /**
75 |  * Releases resources associated with an initialized TCP stream manager instance.
76 |  *
77 |  * - IMPORTANT: Do not use this method on TCP stream manager structures that are not initialized!
78 |  *
79 |  * @param      tcpStreamManager     TCP stream manager.
80 |  */
81 | void HAPPlatformTCPStreamManagerRelease(HAPPlatformTCPStreamManagerRef tcpStreamManager);
82 | 
83 | #if __has_feature(nullability)
84 | #pragma clang assume_nonnull end
85 | #endif
86 | 
87 | #ifdef __cplusplus
88 | }
89 | #endif
90 | 
91 | #endif
92 | 


--------------------------------------------------------------------------------
/PAL/Darwin/HAPPlatformTimer.m:
--------------------------------------------------------------------------------
 1 | // Copyright (c) 2015-2019 The HomeKit ADK Contributors
 2 | //
 3 | // Licensed under the Apache License, Version 2.0 (the “License”);
 4 | // you may not use this file except in compliance with the License.
 5 | // See [CONTRIBUTORS.md] for the list of HomeKit ADK project authors.
 6 | 
 7 | #include "HAPPlatformTimer.h"
 8 | 
 9 | #import <Foundation/Foundation.h>
10 | 
11 | static NSTimer* scheduleTimer(HAPTime deadline, HAPPlatformTimerCallback callback, void* _Nullable context) {
12 |     NSTimeInterval interval = 0;
13 |     HAPTime currentTime = HAPPlatformClockGetCurrent();
14 | 
15 |     if (deadline > currentTime) {
16 |         interval = ((NSTimeInterval)(deadline - currentTime)) / 1000.0;
17 |     }
18 | 
19 |     NSTimer* t = [NSTimer
20 |             scheduledTimerWithTimeInterval:interval
21 |                                    repeats:NO
22 |                                      block:^(NSTimer* timer) {
23 |                                          dispatch_async(dispatch_get_main_queue(), ^{
24 |                                              NSLog(@"Timer fired %@ timer %@", [NSThread currentThread], timer);
25 |                                              callback((HAPPlatformTimerRef)(__bridge void*) timer, context);
26 |                                              NSLog(@"callback completed");
27 |                                          });
28 |                                      }];
29 | 
30 |     return t;
31 | }
32 | 
33 | HAP_RESULT_USE_CHECK
34 | HAPError HAPPlatformTimerRegister(
35 |         HAPPlatformTimerRef* timer,
36 |         HAPTime deadline,
37 |         HAPPlatformTimerCallback callback,
38 |         void* _Nullable context) {
39 |     __block NSTimer* t;
40 | 
41 |     if (![NSThread isMainThread]) {
42 |         // needs to be sync since timer has to be updated, but can only
43 |         // do this if not already on the main thread
44 |         dispatch_sync(dispatch_get_main_queue(), ^{
45 |             t = scheduleTimer(deadline, callback, context);
46 | 
47 |             printf("timer dispatch register %p\n", t);
48 |         });
49 |     } else {
50 |         t = scheduleTimer(deadline, callback, context);
51 |         printf("timer register %p\n", t);
52 |     }
53 | 
54 |     *timer = (HAPPlatformTimerRef)(__bridge_retained void*) t;
55 | 
56 |     return kHAPError_None;
57 | }
58 | 
59 | void HAPPlatformTimerDeregister(HAPPlatformTimerRef timer_) {
60 |     NSTimer* timer = (__bridge_transfer NSTimer*) (void*) timer_;
61 |     [timer invalidate];
62 |     timer = nil;
63 | }
64 | 


--------------------------------------------------------------------------------
/PAL/HAPAssert.c:
--------------------------------------------------------------------------------
 1 | // Copyright (c) 2015-2019 The HomeKit ADK Contributors
 2 | //
 3 | // Licensed under the Apache License, Version 2.0 (the “License”);
 4 | // you may not use this file except in compliance with the License.
 5 | // See [CONTRIBUTORS.md] for the list of HomeKit ADK project authors.
 6 | 
 7 | #undef HAP_DISALLOW_USE_IGNORED
 8 | #define HAP_DISALLOW_USE_IGNORED 1
 9 | 
10 | #include "HAPPlatform.h"
11 | 
12 | HAP_NORETURN
13 | void HAPAssertAbortInternal(void) {
14 |     HAPPlatformAbort();
15 | }
16 | 
17 | HAP_NORETURN
18 | void HAPAssertInternal(const char* callerFunction, const char* callerFile, int callerLine) {
19 |     HAPLogFault(&kHAPLog_Default, "assertion failed - %s @ %s:%d", callerFunction, callerFile, callerLine);
20 |     HAPPlatformAbort();
21 | }
22 | 
23 | HAP_NORETURN
24 | void HAPAssertionFailureInternal(const char* callerFunction, const char* callerFile, int callerLine) {
25 |     HAPLogFault(&kHAPLog_Default, "assertion failed - %s @ %s:%d", callerFunction, callerFile, callerLine);
26 |     HAPPlatformAbort();
27 | }
28 | 
29 | HAP_NORETURN
30 | void HAPPreconditionInternal(const char* condition, const char* callerFunction) {
31 |     HAPLogFault(&kHAPLog_Default, "precondition failed: %s - %s", condition, callerFunction);
32 |     HAPPlatformAbort();
33 | }
34 | 
35 | HAP_NORETURN
36 | void HAPPreconditionFailureInternal(const char* callerFunction) {
37 |     HAPLogFault(&kHAPLog_Default, "precondition failed - %s", callerFunction);
38 |     HAPPlatformAbort();
39 | }
40 | 
41 | HAP_NORETURN
42 | void HAPFatalErrorInternal(const char* callerFunction, const char* callerFile, int callerLine) {
43 |     HAPLogFault(&kHAPLog_Default, "fatal error - %s @ %s:%d", callerFunction, callerFile, callerLine);
44 |     HAPPlatformAbort();
45 | }
46 | 


--------------------------------------------------------------------------------
/PAL/HAPBase+Double.c:
--------------------------------------------------------------------------------
 1 | // Copyright (c) 2015-2019 The HomeKit ADK Contributors
 2 | //
 3 | // Licensed under the Apache License, Version 2.0 (the “License”);
 4 | // you may not use this file except in compliance with the License.
 5 | // See [CONTRIBUTORS.md] for the list of HomeKit ADK project authors.
 6 | 
 7 | #include "HAPPlatform.h"
 8 | 
 9 | HAP_RESULT_USE_CHECK
10 | double HAPDoubleFromBitPattern(uint64_t bitPattern) {
11 |     double value;
12 |     HAPAssert(sizeof value == sizeof bitPattern);
13 |     HAPRawBufferCopyBytes(&value, &bitPattern, sizeof value);
14 |     return value;
15 | }
16 | 
17 | HAP_RESULT_USE_CHECK
18 | uint64_t HAPDoubleGetBitPattern(double value) {
19 |     uint64_t bitPattern;
20 |     HAPAssert(sizeof bitPattern == sizeof value);
21 |     HAPRawBufferCopyBytes(&bitPattern, &value, sizeof bitPattern);
22 |     return bitPattern;
23 | }
24 | 


--------------------------------------------------------------------------------
/PAL/HAPBase+RawBuffer.c:
--------------------------------------------------------------------------------
 1 | // Copyright (c) 2015-2019 The HomeKit ADK Contributors
 2 | //
 3 | // Licensed under the Apache License, Version 2.0 (the “License”);
 4 | // you may not use this file except in compliance with the License.
 5 | // See [CONTRIBUTORS.md] for the list of HomeKit ADK project authors.
 6 | 
 7 | #include "HAPPlatform.h"
 8 | #include "HAPCrypto.h"
 9 | 
10 | void HAPRawBufferZero(void* bytes, size_t numBytes) {
11 |     HAPPrecondition(bytes);
12 | 
13 |     uint8_t* b = bytes;
14 | 
15 |     for (size_t i = 0; i < numBytes; i++) {
16 |         b[i] = 0;
17 |     }
18 | }
19 | 
20 | void HAPRawBufferCopyBytes(void* destinationBytes, const void* sourceBytes, size_t numBytes) {
21 |     HAPPrecondition(destinationBytes);
22 |     HAPPrecondition(sourceBytes);
23 | 
24 |     uint8_t* destination = destinationBytes;
25 |     const uint8_t* source = sourceBytes;
26 | 
27 |     if (destinationBytes < sourceBytes) {
28 |         for (size_t i = 0; i < numBytes; i++) {
29 |             destination[i] = source[i];
30 |         }
31 |     } else if (destinationBytes > sourceBytes) {
32 |         for (size_t i = numBytes; i > 0; i--) {
33 |             destination[i - 1] = source[i - 1];
34 |         }
35 |     }
36 | }
37 | 
38 | HAP_RESULT_USE_CHECK
39 | bool HAPRawBufferAreEqual(const void* bytes, const void* otherBytes, size_t numBytes) {
40 |     HAPPrecondition(bytes);
41 |     HAPPrecondition(otherBytes);
42 | 
43 |     if (!numBytes) {
44 |         return true;
45 |     }
46 |     return HAP_constant_time_equal(bytes, otherBytes, numBytes) == 1;
47 | }
48 | 
49 | HAP_RESULT_USE_CHECK
50 | bool HAPRawBufferIsZero(const void* bytes, size_t numBytes) {
51 |     HAPPrecondition(bytes);
52 | 
53 |     if (!numBytes) {
54 |         return true;
55 |     }
56 |     return HAP_constant_time_is_zero(bytes, numBytes) == 1;
57 | }
58 | 


--------------------------------------------------------------------------------
/PAL/HAPBase+Sha1Checksum.c:
--------------------------------------------------------------------------------
 1 | // Copyright (c) 2015-2019 The HomeKit ADK Contributors
 2 | //
 3 | // Licensed under the Apache License, Version 2.0 (the “License”);
 4 | // you may not use this file except in compliance with the License.
 5 | // See [CONTRIBUTORS.md] for the list of HomeKit ADK project authors.
 6 | 
 7 | #include "HAPPlatform.h"
 8 | #include "HAPCrypto.h"
 9 | 
10 | void HAPSHA1Checksum(uint8_t checksum[kHAPSHA1Checksum_NumBytes], const void* bytes, size_t numBytes) {
11 |     HAPAssert(checksum);
12 |     HAPAssert(bytes);
13 | 
14 |     HAP_sha1(checksum, bytes, numBytes);
15 | }
16 | 


--------------------------------------------------------------------------------
/PAL/HAPBase+UTF8.c:
--------------------------------------------------------------------------------
 1 | // Copyright (c) 2015-2019 The HomeKit ADK Contributors
 2 | //
 3 | // Licensed under the Apache License, Version 2.0 (the “License”);
 4 | // you may not use this file except in compliance with the License.
 5 | // See [CONTRIBUTORS.md] for the list of HomeKit ADK project authors.
 6 | 
 7 | #include "HAPPlatform.h"
 8 | 
 9 | HAP_RESULT_USE_CHECK
10 | bool HAPUTF8IsValidData(const void* bytes, size_t numBytes) {
11 |     HAPPrecondition(bytes);
12 | 
13 |     // See http://www.unicode.org/versions/Unicode6.0.0/ch03.pdf - Table 3-7, page 94.
14 | 
15 |     int error = 0;  // Error state in bit 0.
16 |     int state = 0;  // Number of leading 1 bits == number of outstanding continuation bytes.
17 |     int prefix = 0; // Prefix byte if value is second byte.
18 | 
19 |     // state     value    -> more  first  second -> error  state'    prefix
20 |     // 0xxxxxxx  0xxxxxxx     0      0      x        0    00000000  00000000
21 |     // 0xxxxxxx  10xxxxxx     0      1      0        1
22 |     // 0xxxxxxx  1110xxxx     0      1      1        0    110xxxxx  1110xxxx
23 |     // 110xxxx0  0xxxxxxx     1      0      x        1
24 |     // 110xxxx0  10xxxxxx     1      1      0        0    10xxxxxx  00000000
25 |     // 110xxxx0  110xxxxx     1      1      1        1
26 | 
27 |     for (size_t i = 0; i < numBytes; i++) {
28 |         int value = ((const uint8_t*) bytes)[i];
29 |         int more = state >> 7;         // More continuation bytes expected.
30 |         int first = value >> 7;        // First bit.
31 |         int second = (value >> 6) & 1; // Second bit.
32 | 
33 |         // Illegal value.
34 |         error |= ((uint8_t)(value - 0xC0) - 2) >> 8; // value == 1100000x
35 |         error |= (0xF4 - value) >> 8;                // value >= 11110101
36 | 
37 |         // Illegal second byte.
38 |         int bits = value >> 5;
39 |         error |= (((uint8_t)(prefix - 0xE0) - 1) >> 8) & ~bits; // 11100000  xx0xxxxx
40 |         error |= (((uint8_t)(prefix - 0xED) - 1) >> 8) & bits;  // 11101101  xx1xxxxx
41 |         bits |= value >> 4;
42 |         error |= (((uint8_t)(prefix - 0xF0) - 1) >> 8) & ~bits; // 11110000  xx00xxxx
43 |         error |= (((uint8_t)(prefix - 0xF4) - 1) >> 8) & bits;  // 11110100  xx11xxxx
44 | 
45 |         // Illegal continuation.
46 |         error |= (first & ~second) ^ more;
47 | 
48 |         // New state.
49 |         prefix = -(first & second) & value;
50 |         state = (uint8_t)((prefix | (-more & state)) << 1);
51 |     }
52 | 
53 |     // Missing continuations.
54 |     error |= state >> 7;
55 | 
56 |     return (bool) (1 & ~error);
57 | }
58 | 


--------------------------------------------------------------------------------
/PAL/HAPPlatform.h:
--------------------------------------------------------------------------------
 1 | // Copyright (c) 2015-2019 The HomeKit ADK Contributors
 2 | //
 3 | // Licensed under the Apache License, Version 2.0 (the “License”);
 4 | // you may not use this file except in compliance with the License.
 5 | // See [CONTRIBUTORS.md] for the list of HomeKit ADK project authors.
 6 | 
 7 | #ifndef HAP_PLATFORM_H
 8 | #define HAP_PLATFORM_H
 9 | 
10 | #ifdef __cplusplus
11 | extern "C" {
12 | #endif
13 | 
14 | #include "HAPBase.h"
15 | 
16 | #include "HAPPlatformAbort.h"
17 | #include "HAPPlatformAccessorySetup.h"
18 | #include "HAPPlatformAccessorySetupDisplay.h"
19 | #include "HAPPlatformAccessorySetupNFC.h"
20 | #include "HAPPlatformBLEPeripheralManager.h"
21 | #include "HAPPlatformClock.h"
22 | #include "HAPPlatformKeyValueStore.h"
23 | #include "HAPPlatformLog.h"
24 | #include "HAPPlatformMFiHWAuth.h"
25 | #include "HAPPlatformMFiTokenAuth.h"
26 | #include "HAPPlatformRandomNumber.h"
27 | #include "HAPPlatformRunLoop.h"
28 | #include "HAPPlatformServiceDiscovery.h"
29 | #include "HAPPlatformTCPStreamManager.h"
30 | #include "HAPPlatformTimer.h"
31 | 
32 | #if __has_feature(nullability)
33 | #pragma clang assume_nonnull begin
34 | #endif
35 | 
36 | /**
37 |  * Log subsystem used by the HAP platform implementation.
38 |  */
39 | #define kHAPPlatform_LogSubsystem "com.apple.mfi.HomeKit.Platform"
40 | 
41 | /**
42 |  * Compatibility version of the HAP platform interface.
43 |  *
44 |  * - If this version differs from the one returned by HAPPlatformGetCompatibilityVersion,
45 |  *   the HAP platform implementation is incompatible and must not be used.
46 |  */
47 | #define HAP_PLATFORM_COMPATIBILITY_VERSION (7)
48 | 
49 | /**
50 |  * Gets the compatibility version of the HAP platform implementation.
51 |  *
52 |  * - If the compatibility version differs from HAP_PLATFORM_COMPATIBILITY_VERSION,
53 |  *   the HAP platform implementation is incompatible and may not be used.
54 |  *
55 |  * @return Compatibility version of the HAP library.
56 |  */
57 | HAP_RESULT_USE_CHECK
58 | uint32_t HAPPlatformGetCompatibilityVersion(void);
59 | 
60 | /**
61 |  * Gets the identification of the HAP platform implementation.
62 |  *
63 |  * @return HAP platform implementation identification string.
64 |  */
65 | HAP_RESULT_USE_CHECK
66 | const char* HAPPlatformGetIdentification(void);
67 | 
68 | /**
69 |  * Gets the version string of the HAP platform implementation.
70 |  *
71 |  * @return Version string of the HAP platform implementation.
72 |  */
73 | HAP_RESULT_USE_CHECK
74 | const char* HAPPlatformGetVersion(void);
75 | 
76 | /**
77 |  * Gets the build version string of the HAP platform implementation.
78 |  *
79 |  * @return Build version string of the HAP platform implementation.
80 |  */
81 | HAP_RESULT_USE_CHECK
82 | const char* HAPPlatformGetBuild(void);
83 | 
84 | #if __has_feature(nullability)
85 | #pragma clang assume_nonnull end
86 | #endif
87 | 
88 | #ifdef __cplusplus
89 | }
90 | #endif
91 | 
92 | #endif
93 | 


--------------------------------------------------------------------------------
/PAL/HAPPlatformAbort.h:
--------------------------------------------------------------------------------
 1 | // Copyright (c) 2015-2019 The HomeKit ADK Contributors
 2 | //
 3 | // Licensed under the Apache License, Version 2.0 (the “License”);
 4 | // you may not use this file except in compliance with the License.
 5 | // See [CONTRIBUTORS.md] for the list of HomeKit ADK project authors.
 6 | 
 7 | #ifndef HAP_PLATFORM_ABORT_H
 8 | #define HAP_PLATFORM_ABORT_H
 9 | 
10 | #ifdef __cplusplus
11 | extern "C" {
12 | #endif
13 | 
14 | #include "HAPBase.h"
15 | 
16 | #if __has_feature(nullability)
17 | #pragma clang assume_nonnull begin
18 | #endif
19 | 
20 | /**
21 |  * Called when a fatal error occurred. Must not return.
22 |  */
23 | HAP_NORETURN
24 | void HAPPlatformAbort(void);
25 | 
26 | #if __has_feature(nullability)
27 | #pragma clang assume_nonnull end
28 | #endif
29 | 
30 | #ifdef __cplusplus
31 | }
32 | #endif
33 | 
34 | #endif
35 | 


--------------------------------------------------------------------------------
/PAL/HAPPlatformAccessorySetupNFC.h:
--------------------------------------------------------------------------------
 1 | // Copyright (c) 2015-2019 The HomeKit ADK Contributors
 2 | //
 3 | // Licensed under the Apache License, Version 2.0 (the “License”);
 4 | // you may not use this file except in compliance with the License.
 5 | // See [CONTRIBUTORS.md] for the list of HomeKit ADK project authors.
 6 | 
 7 | #ifndef HAP_PLATFORM_ACCESSORY_SETUP_NFC_H
 8 | #define HAP_PLATFORM_ACCESSORY_SETUP_NFC_H
 9 | 
10 | #ifdef __cplusplus
11 | extern "C" {
12 | #endif
13 | 
14 | #include "HAPPlatform.h"
15 | 
16 | #if __has_feature(nullability)
17 | #pragma clang assume_nonnull begin
18 | #endif
19 | 
20 | /**
21 |  * @file
22 |  *
23 |  * During HomeKit pairing, a setup code is used by the controller to set up an encrypted link with the accessory.
24 |  * If the accessory has a programmable NFC tag, accessory setup information may be exchanged over NFC.
25 |  * This platform module must be implemented if the accessory has a programmable NFC tag.
26 |  *
27 |  * - Programmable NFC requires the accessory to be provisioned with a setup ID.
28 |  *   If no display is available the raw setup code must also be provisioned.
29 |  *
30 |  * - In contrast to displays that are activated automatically when a pairing request is registered,
31 |  *   programmable NFC is only available after explicitly entering pairing mode.
32 |  */
33 | 
34 | /**
35 |  * Accessory setup programmable NFC tag.
36 |  */
37 | typedef struct HAPPlatformAccessorySetupNFC HAPPlatformAccessorySetupNFC;
38 | typedef struct HAPPlatformAccessorySetupNFC* HAPPlatformAccessorySetupNFCRef;
39 | HAP_NONNULL_SUPPORT(HAPPlatformAccessorySetupNFC)
40 | 
41 | /**
42 |  * Updates the setup code that is shown on a connected display.
43 |  *
44 |  * @param      setupNFC             Accessory setup programmable NFC tag.
45 |  * @param      setupPayload         Setup payload to make available using the programmable NFC tag.
46 |  * @param      isPairable           Whether the setup payload may be used for pairing or indicates an error condition.
47 |  */
48 | void HAPPlatformAccessorySetupNFCUpdateSetupPayload(
49 |         HAPPlatformAccessorySetupNFCRef setupNFC,
50 |         const HAPSetupPayload* setupPayload,
51 |         bool isPairable);
52 | 
53 | #if __has_feature(nullability)
54 | #pragma clang assume_nonnull end
55 | #endif
56 | 
57 | #ifdef __cplusplus
58 | }
59 | #endif
60 | 
61 | #endif
62 | 


--------------------------------------------------------------------------------
/PAL/HAPPlatformClock.h:
--------------------------------------------------------------------------------
 1 | // Copyright (c) 2015-2019 The HomeKit ADK Contributors
 2 | //
 3 | // Licensed under the Apache License, Version 2.0 (the “License”);
 4 | // you may not use this file except in compliance with the License.
 5 | // See [CONTRIBUTORS.md] for the list of HomeKit ADK project authors.
 6 | 
 7 | #ifndef HAP_PLATFORM_CLOCK_H
 8 | #define HAP_PLATFORM_CLOCK_H
 9 | 
10 | #ifdef __cplusplus
11 | extern "C" {
12 | #endif
13 | 
14 | #include "HAPPlatform.h"
15 | 
16 | #if __has_feature(nullability)
17 | #pragma clang assume_nonnull begin
18 | #endif
19 | 
20 | /**
21 |  * Gets the current system time expressed as milliseconds relative to an implementation-defined time in the past.
22 |  *
23 |  * - The clock must not jump backwards.
24 |  * - The clock must have a minimum resolution of 100ms.
25 |  * - The clock does not have to be persisted across system restarts.
26 |  * - The clock may be suspended to conserve power when no timers are scheduled and no connection is active.
27 |  *
28 |  * @return Clock in milliseconds. Cannot exceed 2^63 - 1 to allow implementations to add offsets without overflow.
29 |  */
30 | HAPTime HAPPlatformClockGetCurrent(void);
31 | 
32 | #if __has_feature(nullability)
33 | #pragma clang assume_nonnull end
34 | #endif
35 | 
36 | #ifdef __cplusplus
37 | }
38 | #endif
39 | 
40 | #endif
41 | 


--------------------------------------------------------------------------------
/PAL/HAPPlatformRandomNumber.h:
--------------------------------------------------------------------------------
 1 | // Copyright (c) 2015-2019 The HomeKit ADK Contributors
 2 | //
 3 | // Licensed under the Apache License, Version 2.0 (the “License”);
 4 | // you may not use this file except in compliance with the License.
 5 | // See [CONTRIBUTORS.md] for the list of HomeKit ADK project authors.
 6 | 
 7 | #ifndef HAP_PLATFORM_RANDOM_NUMBER_H
 8 | #define HAP_PLATFORM_RANDOM_NUMBER_H
 9 | 
10 | #ifdef __cplusplus
11 | extern "C" {
12 | #endif
13 | 
14 | #include "HAPPlatform.h"
15 | 
16 | #if __has_feature(nullability)
17 | #pragma clang assume_nonnull begin
18 | #endif
19 | 
20 | /**
21 |  * Fills a buffer with cryptographically securely generated random numbers.
22 |  *
23 |  * @param[out] bytes                Buffer to fill with random numbers.
24 |  * @param      numBytes             Length of buffer.
25 |  */
26 | void HAPPlatformRandomNumberFill(void* bytes, size_t numBytes)
27 |         HAP_DIAGNOSE_ERROR(!bytes && numBytes, "empty buffer cannot have a length");
28 | 
29 | #if __has_feature(nullability)
30 | #pragma clang assume_nonnull end
31 | #endif
32 | 
33 | #ifdef __cplusplus
34 | }
35 | #endif
36 | 
37 | #endif
38 | 


--------------------------------------------------------------------------------
/PAL/HAPPlatformRunLoop.h:
--------------------------------------------------------------------------------
 1 | // Copyright (c) 2015-2019 The HomeKit ADK Contributors
 2 | //
 3 | // Licensed under the Apache License, Version 2.0 (the “License”);
 4 | // you may not use this file except in compliance with the License.
 5 | // See [CONTRIBUTORS.md] for the list of HomeKit ADK project authors.
 6 | 
 7 | #ifndef HAP_PLATFORM_RUN_LOOP_H
 8 | #define HAP_PLATFORM_RUN_LOOP_H
 9 | 
10 | #ifdef __cplusplus
11 | extern "C" {
12 | #endif
13 | 
14 | #include "HAPPlatform.h"
15 | 
16 | #if __has_feature(nullability)
17 | #pragma clang assume_nonnull begin
18 | #endif
19 | 
20 | /**
21 |  * Runs the loop which processes data from all attached input sources.
22 |  *
23 |  * - This function may only be called while the run loop is stopped.
24 |  */
25 | void HAPPlatformRunLoopRun(void);
26 | 
27 | /**
28 |  * Schedules a request to exit the run loop.
29 |  *
30 |  * - This function must be called from the same execution context (e.g., thread) as the run loop,
31 |  *   i.e. it should be scheduled on the run loop.
32 |  *
33 |  * - When this function returns, the run loop is not yet fully stopped.
34 |  *   Wait for HAPPlatformRunLoopRun to return.
35 |  *
36 |  * - The execution of pending scheduled events may be delayed until the run loop is started again.
37 |  */
38 | void HAPPlatformRunLoopStop(void);
39 | 
40 | /**
41 |  * Callback that is invoked from the run loop.
42 |  *
43 |  * @param      context              Client context.
44 |  * @param      contextSize          Size of the context.
45 |  */
46 | typedef void (*HAPPlatformRunLoopCallback)(void* _Nullable context, size_t contextSize);
47 | 
48 | /**
49 |  * Schedule a callback that will be called from the run loop.
50 |  *
51 |  * - It is safe to call this function from execution contexts (e.g., threads) other than the run loop,
52 |  *   e.g., from another thread or from a signal handler.
53 |  *
54 |  * @param      callback             Function to call on the run loop.
55 |  * @param      context              Context that is passed to the callback.
56 |  * @param      contextSize          Size of context data that is passed to the callback.
57 |  *
58 |  * @return kHAPError_None           If successful.
59 |  * @return kHAPError_OutOfResources If there are not enough resources to schedule the callback.
60 |  */
61 | HAP_RESULT_USE_CHECK
62 | HAPError HAPPlatformRunLoopScheduleCallback(
63 |         HAPPlatformRunLoopCallback callback,
64 |         void* _Nullable context,
65 |         size_t contextSize);
66 | 
67 | #if __has_feature(nullability)
68 | #pragma clang assume_nonnull end
69 | #endif
70 | 
71 | #ifdef __cplusplus
72 | }
73 | #endif
74 | 
75 | #endif
76 | 


--------------------------------------------------------------------------------
/PAL/HAPPlatformServiceDiscovery.h:
--------------------------------------------------------------------------------
 1 | // Copyright (c) 2015-2019 The HomeKit ADK Contributors
 2 | //
 3 | // Licensed under the Apache License, Version 2.0 (the “License”);
 4 | // you may not use this file except in compliance with the License.
 5 | // See [CONTRIBUTORS.md] for the list of HomeKit ADK project authors.
 6 | 
 7 | #ifndef HAP_PLATFORM_SERVICE_DISCOVERY_H
 8 | #define HAP_PLATFORM_SERVICE_DISCOVERY_H
 9 | 
10 | #ifdef __cplusplus
11 | extern "C" {
12 | #endif
13 | 
14 | #include "HAPPlatform.h"
15 | 
16 | #if __has_feature(nullability)
17 | #pragma clang assume_nonnull begin
18 | #endif
19 | 
20 | /**
21 |  * Service discovery.
22 |  */
23 | typedef struct HAPPlatformServiceDiscovery HAPPlatformServiceDiscovery;
24 | typedef struct HAPPlatformServiceDiscovery* HAPPlatformServiceDiscoveryRef;
25 | HAP_NONNULL_SUPPORT(HAPPlatformServiceDiscovery)
26 | 
27 | /**
28 |  * TXT record.
29 |  */
30 | typedef struct {
31 |     /** Key of the TXT record. */
32 |     const char* key;
33 | 
34 |     /** Value of the TXT record. */
35 |     struct {
36 |         /** Buffer containing TXT value. */
37 |         const void* _Nullable bytes;
38 | 
39 |         /** Length of TXT value. */
40 |         size_t numBytes;
41 |     } value;
42 | } HAPPlatformServiceDiscoveryTXTRecord;
43 | 
44 | /**
45 |  * Starts Bonjour service discovery.
46 |  *
47 |  * @param      serviceDiscovery     Service discovery.
48 |  * @param      name                 Service name.
49 |  * @param      protocol             Protocol name.
50 |  * @param      port                 Port number.
51 |  * @param      txtRecords           Array of TXT records.
52 |  * @param      numTXTRecords        Number of TXT records.
53 |  */
54 | void HAPPlatformServiceDiscoveryRegister(
55 |         HAPPlatformServiceDiscoveryRef serviceDiscovery,
56 |         const char* name,
57 |         const char* protocol,
58 |         HAPNetworkPort port,
59 |         HAPPlatformServiceDiscoveryTXTRecord* txtRecords,
60 |         size_t numTXTRecords);
61 | 
62 | /**
63 |  * Updates the TXT records of a running Bonjour service discovery.
64 |  *
65 |  * @param      serviceDiscovery     Service discovery.
66 |  * @param      txtRecords           Array of TXT records.
67 |  * @param      numTXTRecords        Number of TXT records.
68 |  */
69 | void HAPPlatformServiceDiscoveryUpdateTXTRecords(
70 |         HAPPlatformServiceDiscoveryRef serviceDiscovery,
71 |         HAPPlatformServiceDiscoveryTXTRecord* txtRecords,
72 |         size_t numTXTRecords);
73 | 
74 | /**
75 |  * Stops Bonjour service discovery.
76 |  *
77 |  * @param      serviceDiscovery     Service discovery.
78 |  */
79 | void HAPPlatformServiceDiscoveryStop(HAPPlatformServiceDiscoveryRef serviceDiscovery);
80 | 
81 | #if __has_feature(nullability)
82 | #pragma clang assume_nonnull end
83 | #endif
84 | 
85 | #ifdef __cplusplus
86 | }
87 | #endif
88 | 
89 | #endif
90 | 


--------------------------------------------------------------------------------
/PAL/HAPPlatformSystemInit.c:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2015-2019 The HomeKit ADK Contributors
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the “License”);
4 | // you may not use this file except in compliance with the License.
5 | // See [CONTRIBUTORS.md] for the list of HomeKit ADK project authors.
6 | 
7 | // This is only used by bare metal targets and is empty otherwise
8 | 


--------------------------------------------------------------------------------
/PAL/HAPPlatformTimer.h:
--------------------------------------------------------------------------------
 1 | // Copyright (c) 2015-2019 The HomeKit ADK Contributors
 2 | //
 3 | // Licensed under the Apache License, Version 2.0 (the “License”);
 4 | // you may not use this file except in compliance with the License.
 5 | // See [CONTRIBUTORS.md] for the list of HomeKit ADK project authors.
 6 | 
 7 | #ifndef HAP_PLATFORM_TIMER_H
 8 | #define HAP_PLATFORM_TIMER_H
 9 | 
10 | #ifdef __cplusplus
11 | extern "C" {
12 | #endif
13 | 
14 | #include "HAPPlatform.h"
15 | 
16 | #if __has_feature(nullability)
17 | #pragma clang assume_nonnull begin
18 | #endif
19 | 
20 | typedef uintptr_t HAPPlatformTimerRef;
21 | 
22 | /**
23 |  * Callback that is invoked when a timer expires.
24 |  *
25 |  * @param      timer                Timer ID.
26 |  * @param      context              Client context.
27 |  */
28 | typedef void (*HAPPlatformTimerCallback)(HAPPlatformTimerRef timer, void* _Nullable context);
29 | 
30 | /**
31 |  * Registers a timer to fire a callback after a certain time.
32 |  *
33 |  * - The callback is never invoked synchronously, even if the timer already expired on creation.
34 |  *
35 |  * - The deadline is given as an absolute time in milliseconds, relative to an implementation-defined time in the past
36 |  *   (the same one as in HAPPlatformClockGetCurrent).
37 |  *
38 |  * - Timers fire in ascending order of their deadlines. Timers registered with the same deadline fire in order of
39 |  *   registration.
40 |  *
41 |  * @param[out] timer                Non-zero Timer ID, if successful.
42 |  * @param      deadline             Deadline after which the timer expires.
43 |  * @param      callback             Function to call when the timer expires.
44 |  * @param      context              Context that is passed to the callback.
45 |  *
46 |  * @return kHAPError_None           If successful.
47 |  * @return kHAPError_OutOfResources If not more timers can be allocated.
48 |  */
49 | HAP_RESULT_USE_CHECK
50 | HAPError HAPPlatformTimerRegister(
51 |         HAPPlatformTimerRef* timer,
52 |         HAPTime deadline,
53 |         HAPPlatformTimerCallback callback,
54 |         void* _Nullable context);
55 | 
56 | /**
57 |  * Deregisters a timer that has not yet fired.
58 |  *
59 |  * @param      timer                Timer ID.
60 |  */
61 | void HAPPlatformTimerDeregister(HAPPlatformTimerRef timer);
62 | 
63 | #if __has_feature(nullability)
64 | #pragma clang assume_nonnull end
65 | #endif
66 | 
67 | #ifdef __cplusplus
68 | }
69 | #endif
70 | 
71 | #endif
72 | 


--------------------------------------------------------------------------------
/PAL/Linux:
--------------------------------------------------------------------------------
1 | POSIX


--------------------------------------------------------------------------------
/PAL/Mock/HAPPlatform+Init.h:
--------------------------------------------------------------------------------
 1 | // Copyright (c) 2015-2019 The HomeKit ADK Contributors
 2 | //
 3 | // Licensed under the Apache License, Version 2.0 (the “License”);
 4 | // you may not use this file except in compliance with the License.
 5 | // See [CONTRIBUTORS.md] for the list of HomeKit ADK project authors.
 6 | 
 7 | #ifndef HAP_PLATFORM_INIT_H
 8 | #define HAP_PLATFORM_INIT_H
 9 | 
10 | #ifdef __cplusplus
11 | extern "C" {
12 | #endif
13 | 
14 | #include "HAP.h"
15 | #include "HAPPlatformClock+Test.h"
16 | #include "HAPPlatformTCPStreamManager+Test.h"
17 | 
18 | #if __has_feature(nullability)
19 | #pragma clang assume_nonnull begin
20 | #endif
21 | 
22 | /**
23 |  * Global platform object.
24 |  */
25 | extern HAPPlatform platform;
26 | 
27 | /**
28 |  * Initializes the platform.
29 |  */
30 | void HAPPlatformCreate(void);
31 | 
32 | #if __has_feature(nullability)
33 | #pragma clang assume_nonnull end
34 | #endif
35 | 
36 | #ifdef __cplusplus
37 | }
38 | #endif
39 | 
40 | #endif
41 | 


--------------------------------------------------------------------------------
/PAL/Mock/HAPPlatformAbort.c:
--------------------------------------------------------------------------------
 1 | // Copyright (c) 2015-2019 The HomeKit ADK Contributors
 2 | //
 3 | // Licensed under the Apache License, Version 2.0 (the “License”);
 4 | // you may not use this file except in compliance with the License.
 5 | // See [CONTRIBUTORS.md] for the list of HomeKit ADK project authors.
 6 | 
 7 | #include <stdlib.h>
 8 | 
 9 | #include "HAPPlatform.h"
10 | 
11 | HAP_NORETURN
12 | void HAPPlatformAbort(void) {
13 |     exit(EXIT_FAILURE);
14 | }
15 | 


--------------------------------------------------------------------------------
/PAL/Mock/HAPPlatformAccessorySetup+Init.h:
--------------------------------------------------------------------------------
 1 | // Copyright (c) 2015-2019 The HomeKit ADK Contributors
 2 | //
 3 | // Licensed under the Apache License, Version 2.0 (the “License”);
 4 | // you may not use this file except in compliance with the License.
 5 | // See [CONTRIBUTORS.md] for the list of HomeKit ADK project authors.
 6 | 
 7 | #ifndef HAP_PLATFORM_ACCESSORY_SETUP_INIT_H
 8 | #define HAP_PLATFORM_ACCESSORY_SETUP_INIT_H
 9 | 
10 | #ifdef __cplusplus
11 | extern "C" {
12 | #endif
13 | 
14 | #include "HAPPlatform.h"
15 | 
16 | #if __has_feature(nullability)
17 | #pragma clang assume_nonnull begin
18 | #endif
19 | 
20 | /**
21 |  * Accessory setup manager initialization options.
22 |  */
23 | typedef struct {
24 |     /**
25 |      * Key-value store.
26 |      */
27 |     HAPPlatformKeyValueStoreRef keyValueStore;
28 | } HAPPlatformAccessorySetupOptions;
29 | 
30 | /**
31 |  * Accessory setup manager.
32 |  */
33 | struct HAPPlatformAccessorySetup {
34 |     // Opaque type. Do not access the instance fields directly.
35 |     /**@cond */
36 |     char _;
37 |     /**@endcond */
38 | };
39 | 
40 | #if __has_feature(nullability)
41 | #pragma clang assume_nonnull end
42 | #endif
43 | 
44 | #ifdef __cplusplus
45 | }
46 | #endif
47 | 
48 | #endif
49 | 


--------------------------------------------------------------------------------
/PAL/Mock/HAPPlatformAccessorySetupDisplay.c:
--------------------------------------------------------------------------------
 1 | // Copyright (c) 2015-2019 The HomeKit ADK Contributors
 2 | //
 3 | // Licensed under the Apache License, Version 2.0 (the “License”);
 4 | // you may not use this file except in compliance with the License.
 5 | // See [CONTRIBUTORS.md] for the list of HomeKit ADK project authors.
 6 | 
 7 | #include "HAPPlatform.h"
 8 | 
 9 | static const HAPLogObject logObject = { .subsystem = kHAPPlatform_LogSubsystem, .category = "AccessorySetupDisplay" };
10 | 
11 | void HAPPlatformAccessorySetupDisplayUpdateSetupPayload(
12 |         HAPPlatformAccessorySetupDisplayRef _Nonnull setupDisplay,
13 |         const HAPSetupPayload* _Nullable setupPayload,
14 |         const HAPSetupCode* _Nullable setupCode) {
15 |     HAPPrecondition(setupDisplay);
16 | 
17 |     (void) setupPayload;
18 |     (void) setupCode;
19 |     HAPLogError(&logObject, "[NYI] %s.", __func__);
20 |     HAPFatalError();
21 | }
22 | 
23 | void HAPPlatformAccessorySetupDisplayHandleStartPairing(HAPPlatformAccessorySetupDisplayRef _Nonnull setupDisplay) {
24 |     HAPPrecondition(setupDisplay);
25 | 
26 |     HAPLogError(&logObject, "[NYI] %s.", __func__);
27 |     HAPFatalError();
28 | }
29 | 
30 | void HAPPlatformAccessorySetupDisplayHandleStopPairing(HAPPlatformAccessorySetupDisplayRef _Nonnull setupDisplay) {
31 |     HAPPrecondition(setupDisplay);
32 | 
33 |     HAPLogError(&logObject, "[NYI] %s.", __func__);
34 |     HAPFatalError();
35 | }
36 | 


--------------------------------------------------------------------------------
/PAL/Mock/HAPPlatformAccessorySetupNFC.c:
--------------------------------------------------------------------------------
 1 | // Copyright (c) 2015-2019 The HomeKit ADK Contributors
 2 | //
 3 | // Licensed under the Apache License, Version 2.0 (the “License”);
 4 | // you may not use this file except in compliance with the License.
 5 | // See [CONTRIBUTORS.md] for the list of HomeKit ADK project authors.
 6 | 
 7 | #include "HAPPlatform.h"
 8 | 
 9 | static const HAPLogObject logObject = { .subsystem = kHAPPlatform_LogSubsystem, .category = "AccessorySetupNFC" };
10 | 
11 | void HAPPlatformAccessorySetupNFCUpdateSetupPayload(
12 |         HAPPlatformAccessorySetupNFCRef setupNFC,
13 |         const HAPSetupPayload* setupPayload,
14 |         bool isPairable) {
15 |     HAPPrecondition(setupNFC);
16 |     HAPPrecondition(setupPayload);
17 | 
18 |     (void) isPairable;
19 |     HAPLogError(&logObject, "[NYI] %s.", __func__);
20 |     HAPFatalError();
21 | }
22 | 


--------------------------------------------------------------------------------
/PAL/Mock/HAPPlatformBLEPeripheralManager+Test.h:
--------------------------------------------------------------------------------
 1 | // Copyright (c) 2015-2019 The HomeKit ADK Contributors
 2 | //
 3 | // Licensed under the Apache License, Version 2.0 (the “License”);
 4 | // you may not use this file except in compliance with the License.
 5 | // See [CONTRIBUTORS.md] for the list of HomeKit ADK project authors.
 6 | 
 7 | #ifndef HAP_PLATFORM_BLE_PERIPHERAL_MANAGER_TEST_H
 8 | #define HAP_PLATFORM_BLE_PERIPHERAL_MANAGER_TEST_H
 9 | 
10 | #ifdef __cplusplus
11 | extern "C" {
12 | #endif
13 | 
14 | #include "HAP.h"
15 | 
16 | #if __has_feature(nullability)
17 | #pragma clang assume_nonnull begin
18 | #endif
19 | 
20 | /**
21 |  * Returns whether a BLE peripheral manager is currently advertising.
22 |  *
23 |  * @param      blePeripheralManager BLE peripheral manager.
24 |  *
25 |  * @return true                     If the BLE peripheral manager is currently advertising.
26 |  * @return false                    Otherwise.
27 |  */
28 | HAP_RESULT_USE_CHECK
29 | bool HAPPlatformBLEPeripheralManagerIsAdvertising(HAPPlatformBLEPeripheralManagerRef blePeripheralManager);
30 | 
31 | /**
32 |  * Returns the Bluetooth device address (BD_ADDR) that is currently being advertised.
33 |  *
34 |  * - This can only be called if the BLE peripheral manager is currently advertising.
35 |  *
36 |  * @param      blePeripheralManager BLE peripheral manager.
37 |  * @param[out] deviceAddress        Bluetooth device address.
38 |  */
39 | void HAPPlatformBLEPeripheralManagerGetDeviceAddress(
40 |         HAPPlatformBLEPeripheralManagerRef blePeripheralManager,
41 |         HAPPlatformBLEPeripheralManagerDeviceAddress* deviceAddress);
42 | 
43 | /**
44 |  * Fetches the currently advertised advertising data.
45 |  *
46 |  * - This can only be called if the BLE peripheral manager is currently advertising.
47 |  *
48 |  * @param      blePeripheralManager BLE peripheral manager.
49 |  * @param[out] advertisingBytes     Advertising data buffer.
50 |  * @param      maxAdvertisingBytes  Capacity of advertising data buffer.
51 |  * @param[out] numAdvertisingBytes  Length of advertising data buffer.
52 |  * @param[out] scanResponseBytes    Scan response data buffer.
53 |  * @param      maxScanResponseBytes Capacity of scan response data buffer.
54 |  * @param[out] numScanResponseBytes Length of scan response data buffer.
55 |  *
56 |  * @return kHAPError_None           If successful.
57 |  * @return kHAPError_OutOfResources If the supplied buffers are not large enough.
58 |  */
59 | HAP_RESULT_USE_CHECK
60 | HAPError HAPPlatformBLEPeripheralManagerGetAdvertisingData(
61 |         HAPPlatformBLEPeripheralManagerRef blePeripheralManager,
62 |         void* advertisingBytes,
63 |         size_t maxAdvertisingBytes,
64 |         size_t* numAdvertisingBytes,
65 |         void* scanResponseBytes,
66 |         size_t maxScanResponseBytes,
67 |         size_t* numScanResponseBytes);
68 | 
69 | #if __has_feature(nullability)
70 | #pragma clang assume_nonnull end
71 | #endif
72 | 
73 | #ifdef __cplusplus
74 | }
75 | #endif
76 | 
77 | #endif
78 | 


--------------------------------------------------------------------------------
/PAL/Mock/HAPPlatformClock+Test.h:
--------------------------------------------------------------------------------
 1 | // Copyright (c) 2015-2019 The HomeKit ADK Contributors
 2 | //
 3 | // Licensed under the Apache License, Version 2.0 (the “License”);
 4 | // you may not use this file except in compliance with the License.
 5 | // See [CONTRIBUTORS.md] for the list of HomeKit ADK project authors.
 6 | 
 7 | #ifndef HAP_PLATFORM_CLOCK_TEST_H
 8 | #define HAP_PLATFORM_CLOCK_TEST_H
 9 | 
10 | #ifdef __cplusplus
11 | extern "C" {
12 | #endif
13 | 
14 | #include "HAPPlatform.h"
15 | 
16 | #if __has_feature(nullability)
17 | #pragma clang assume_nonnull begin
18 | #endif
19 | 
20 | /**
21 |  * Advances the clock by a given delta.
22 |  *
23 |  * @param      delta                Delta to advance the clock by.
24 |  */
25 | void HAPPlatformClockAdvance(HAPTime delta);
26 | 
27 | #if __has_feature(nullability)
28 | #pragma clang assume_nonnull end
29 | #endif
30 | 
31 | #ifdef __cplusplus
32 | }
33 | #endif
34 | 
35 | #endif
36 | 


--------------------------------------------------------------------------------
/PAL/Mock/HAPPlatformClock.c:
--------------------------------------------------------------------------------
 1 | // Copyright (c) 2015-2019 The HomeKit ADK Contributors
 2 | //
 3 | // Licensed under the Apache License, Version 2.0 (the “License”);
 4 | // you may not use this file except in compliance with the License.
 5 | // See [CONTRIBUTORS.md] for the list of HomeKit ADK project authors.
 6 | 
 7 | #include "HAPPlatform.h"
 8 | #include "HAPPlatformClock+Test.h"
 9 | #include "HAPPlatformTimer+Init.h"
10 | 
11 | static const HAPLogObject logObject = { .subsystem = kHAPPlatform_LogSubsystem, .category = "Clock" };
12 | 
13 | static HAPTime now;
14 | 
15 | HAPTime HAPPlatformClockGetCurrent(void) {
16 |     // Check for overflow.
17 |     if (now & (1ull << 63)) {
18 |         HAPLog(&logObject, "Time overflowed (capped at 2^63 - 1).");
19 |         HAPFatalError();
20 |     }
21 |     return now;
22 | }
23 | 
24 | void HAPPlatformClockAdvance(HAPTime delta) {
25 |     now += delta;
26 |     HAPLogInfo(
27 |             &logObject,
28 |             "Clock advanced to %8llu.%03llu",
29 |             (unsigned long long) (now / HAPSecond),
30 |             (unsigned long long) (now % HAPSecond));
31 | 
32 |     HAPPlatformTimerProcessExpiredTimers();
33 | }
34 | 


--------------------------------------------------------------------------------
/PAL/Mock/HAPPlatformMFiHWAuth+Init.h:
--------------------------------------------------------------------------------
 1 | // Copyright (c) 2015-2019 The HomeKit ADK Contributors
 2 | //
 3 | // Licensed under the Apache License, Version 2.0 (the “License”);
 4 | // you may not use this file except in compliance with the License.
 5 | // See [CONTRIBUTORS.md] for the list of HomeKit ADK project authors.
 6 | 
 7 | #ifndef HAP_PLATFORM_MFI_HW_AUTH_INIT_H
 8 | #define HAP_PLATFORM_MFI_HW_AUTH_INIT_H
 9 | 
10 | #ifdef __cplusplus
11 | extern "C" {
12 | #endif
13 | 
14 | #include "HAPPlatform.h"
15 | 
16 | #if __has_feature(nullability)
17 | #pragma clang assume_nonnull begin
18 | #endif
19 | 
20 | /**
21 |  * Apple Authentication Coprocessor provider.
22 |  */
23 | struct HAPPlatformMFiHWAuth {
24 |     // Opaque type. Do not access the instance fields directly.
25 |     /**@cond */
26 |     bool poweredOn;
27 |     /**@endcond */
28 | };
29 | 
30 | /**
31 |  * Initializes an Apple Authentication Coprocessor provider.
32 |  *
33 |  * @param[out] mfiHWAuth            Pointer to an allocated but uninitialized HAPPlatformMFiHWAuth structure.
34 |  */
35 | void HAPPlatformMFiHWAuthCreate(HAPPlatformMFiHWAuthRef mfiHWAuth);
36 | 
37 | /**
38 |  * Deinitializes an Apple Authentication Coprocessor.
39 |  *
40 |  * @param      mfiHWAuth            Initialized Apple Authentication Coprocessor provider.
41 |  */
42 | void HAPPlatformMFiHWAuthRelease(HAPPlatformMFiHWAuthRef mfiHWAuth);
43 | 
44 | #if __has_feature(nullability)
45 | #pragma clang assume_nonnull end
46 | #endif
47 | 
48 | #ifdef __cplusplus
49 | }
50 | #endif
51 | 
52 | #endif
53 | 


--------------------------------------------------------------------------------
/PAL/Mock/HAPPlatformMFiTokenAuth+Init.h:
--------------------------------------------------------------------------------
 1 | // Copyright (c) 2015-2019 The HomeKit ADK Contributors
 2 | //
 3 | // Licensed under the Apache License, Version 2.0 (the “License”);
 4 | // you may not use this file except in compliance with the License.
 5 | // See [CONTRIBUTORS.md] for the list of HomeKit ADK project authors.
 6 | 
 7 | #ifndef HAP_PLATFORM_MFI_TOKEN_AUTH_INIT_H
 8 | #define HAP_PLATFORM_MFI_TOKEN_AUTH_INIT_H
 9 | 
10 | #ifdef __cplusplus
11 | extern "C" {
12 | #endif
13 | 
14 | #include "HAPPlatform.h"
15 | #include "HAPPlatformMFiTokenAuth+Init.h"
16 | 
17 | #if __has_feature(nullability)
18 | #pragma clang assume_nonnull begin
19 | #endif
20 | 
21 | /**
22 |  * Software token provider initialization options.
23 |  */
24 | typedef struct {
25 |     /**
26 |      * Key-value store.
27 |      */
28 |     HAPPlatformKeyValueStoreRef keyValueStore;
29 | } HAPPlatformMFiTokenAuthOptions;
30 | 
31 | /**
32 |  * Software Token provider.
33 |  */
34 | struct HAPPlatformMFiTokenAuth {
35 |     // Opaque type. Do not access the instance fields directly.
36 |     /**@cond */
37 |     char _;
38 |     /**@endcond */
39 | };
40 | 
41 | #if __has_feature(nullability)
42 | #pragma clang assume_nonnull end
43 | #endif
44 | 
45 | #ifdef __cplusplus
46 | }
47 | #endif
48 | 
49 | #endif
50 | 


--------------------------------------------------------------------------------
/PAL/Mock/HAPPlatformMFiTokenAuth.c:
--------------------------------------------------------------------------------
 1 | // Copyright (c) 2015-2019 The HomeKit ADK Contributors
 2 | //
 3 | // Licensed under the Apache License, Version 2.0 (the “License”);
 4 | // you may not use this file except in compliance with the License.
 5 | // See [CONTRIBUTORS.md] for the list of HomeKit ADK project authors.
 6 | 
 7 | #include "HAPPlatformMFiTokenAuth+Init.h"
 8 | 
 9 | static const HAPLogObject logObject = { .subsystem = kHAPPlatform_LogSubsystem, .category = "MFiTokenAuth" };
10 | 
11 | void HAPPlatformMFiTokenAuthCreate(
12 |         HAPPlatformMFiTokenAuthRef _Nonnull mfiTokenAuth,
13 |         const HAPPlatformMFiTokenAuthOptions* _Nonnull options) {
14 |     HAPPrecondition(mfiTokenAuth);
15 |     HAPPrecondition(options);
16 |     HAPPrecondition(options->keyValueStore);
17 | }
18 | 
19 | HAP_RESULT_USE_CHECK
20 | HAPError HAPPlatformMFiTokenAuthLoad(
21 |         HAPPlatformMFiTokenAuthRef _Nonnull mfiTokenAuth,
22 |         bool* _Nonnull valid,
23 |         HAPPlatformMFiTokenAuthUUID* _Nullable mfiTokenUUID,
24 |         void* _Nullable mfiTokenBytes,
25 |         size_t maxMFiTokenBytes,
26 |         size_t* _Nullable numMFiTokenBytes) {
27 |     HAPPrecondition(mfiTokenAuth);
28 |     HAPPrecondition(valid);
29 |     HAPPrecondition((mfiTokenUUID == NULL) == (mfiTokenBytes == NULL));
30 |     HAPPrecondition(!maxMFiTokenBytes || mfiTokenBytes);
31 |     HAPPrecondition((mfiTokenBytes == NULL) == (numMFiTokenBytes == NULL));
32 | 
33 |     HAPLogError(&logObject, "[NYI] %s.", __func__);
34 |     HAPFatalError();
35 | }
36 | 
37 | HAP_RESULT_USE_CHECK
38 | HAPError HAPPlatformMFiTokenAuthUpdate(
39 |         HAPPlatformMFiTokenAuthRef _Nonnull mfiTokenAuth,
40 |         const void* _Nonnull mfiTokenBytes,
41 |         size_t numMFiTokenBytes) {
42 |     HAPPrecondition(mfiTokenAuth);
43 |     HAPPrecondition(mfiTokenBytes);
44 |     HAPPrecondition(numMFiTokenBytes <= kHAPPlatformMFiTokenAuth_MaxMFiTokenBytes);
45 | 
46 |     HAPLogError(&logObject, "[NYI] %s.", __func__);
47 |     HAPFatalError();
48 | }
49 | 
50 | bool HAPPlatformMFiTokenAuthIsProvisioned(HAPPlatformMFiTokenAuthRef _Nonnull mfiTokenAuth) {
51 |     HAPPrecondition(mfiTokenAuth);
52 | 
53 |     return false;
54 | }
55 | 


--------------------------------------------------------------------------------
/PAL/Mock/HAPPlatformRandomNumber.c:
--------------------------------------------------------------------------------
 1 | // Copyright (c) 2015-2019 The HomeKit ADK Contributors
 2 | //
 3 | // Licensed under the Apache License, Version 2.0 (the “License”);
 4 | // you may not use this file except in compliance with the License.
 5 | // See [CONTRIBUTORS.md] for the list of HomeKit ADK project authors.
 6 | 
 7 | #include "HAPPlatform.h"
 8 | 
 9 | void HAPPlatformRandomNumberFill(void* bytes, size_t numBytes) {
10 |     HAPPrecondition(bytes);
11 | 
12 |     for (size_t o = 0; o < numBytes; o++) {
13 |         static uint64_t seed[2] = { 1, 1 };
14 |         uint64_t x = seed[0];
15 |         uint64_t y = seed[1];
16 |         seed[0] = y;
17 |         x ^= x << 23;       // a
18 |         x ^= x >> 17;       // b
19 |         x ^= y ^ (y >> 26); // c
20 |         seed[1] = x;
21 |         ((uint8_t*) bytes)[o] = (uint8_t)(x + y);
22 |     }
23 | }
24 | 


--------------------------------------------------------------------------------
/PAL/Mock/HAPPlatformRunLoop.c:
--------------------------------------------------------------------------------
 1 | // Copyright (c) 2015-2019 The HomeKit ADK Contributors
 2 | //
 3 | // Licensed under the Apache License, Version 2.0 (the “License”);
 4 | // you may not use this file except in compliance with the License.
 5 | // See [CONTRIBUTORS.md] for the list of HomeKit ADK project authors.
 6 | 
 7 | #include "HAPPlatform.h"
 8 | 
 9 | static const HAPLogObject logObject = { .subsystem = kHAPPlatform_LogSubsystem, .category = "RunLoop" };
10 | 
11 | // This platform module must be implemented in any case.
12 | 
13 | void HAPPlatformRunLoopRun(void) {
14 |     HAPLogError(&logObject, "[NYI] %s.", __func__);
15 |     HAPFatalError();
16 | }
17 | 
18 | void HAPPlatformRunLoopStop(void) {
19 |     HAPLogError(&logObject, "[NYI] %s.", __func__);
20 |     HAPFatalError();
21 | }
22 | 
23 | HAP_RESULT_USE_CHECK
24 | HAPError HAPPlatformRunLoopScheduleCallback(
25 |         HAPPlatformRunLoopCallback callback,
26 |         void* _Nullable context,
27 |         size_t contextSize) {
28 |     HAPPrecondition(callback);
29 |     HAPPrecondition(!contextSize || context);
30 | 
31 |     HAPLogError(&logObject, "[NYI] %s.", __func__);
32 |     HAPFatalError();
33 | }
34 | 


--------------------------------------------------------------------------------
/PAL/Mock/HAPPlatformServiceDiscovery+Init.h:
--------------------------------------------------------------------------------
 1 | // Copyright (c) 2015-2019 The HomeKit ADK Contributors
 2 | //
 3 | // Licensed under the Apache License, Version 2.0 (the “License”);
 4 | // you may not use this file except in compliance with the License.
 5 | // See [CONTRIBUTORS.md] for the list of HomeKit ADK project authors.
 6 | 
 7 | #ifndef HAP_PLATFORM_SERVICE_DISCOVERY_INIT_H
 8 | #define HAP_PLATFORM_SERVICE_DISCOVERY_INIT_H
 9 | 
10 | #ifdef __cplusplus
11 | extern "C" {
12 | #endif
13 | 
14 | #include "HAPPlatform.h"
15 | 
16 | #if __has_feature(nullability)
17 | #pragma clang assume_nonnull begin
18 | #endif
19 | 
20 | /**
21 |  * Service discovery.
22 |  */
23 | struct HAPPlatformServiceDiscovery {
24 |     // Opaque type. Do not access the instance fields directly.
25 |     /**@cond */
26 |     char name[65];
27 |     char protocol[31];
28 |     struct {
29 |         char key[9];
30 |         struct {
31 |             uint8_t bytes[22];
32 |             uint8_t numBytes;
33 |         } value;
34 |     } txtRecords[16];
35 |     HAPNetworkPort port;
36 |     /**@endcond */
37 | };
38 | 
39 | /**
40 |  * Initializes a service discovery.
41 |  *
42 |  * @param[out] serviceDiscovery     Pointer to an allocated but uninitialized HAPPlatformServiceDiscovery structure.
43 |  */
44 | void HAPPlatformServiceDiscoveryCreate(HAPPlatformServiceDiscoveryRef serviceDiscovery);
45 | 
46 | #if __has_feature(nullability)
47 | #pragma clang assume_nonnull end
48 | #endif
49 | 
50 | #ifdef __cplusplus
51 | }
52 | #endif
53 | 
54 | #endif
55 | 


--------------------------------------------------------------------------------
/PAL/Mock/HAPPlatformStartup.S:
--------------------------------------------------------------------------------
1 | // This is only used by bare metal targets and is empty otherwise
2 | 
3 | 


--------------------------------------------------------------------------------
/PAL/Mock/HAPPlatformSystemCommand.h:
--------------------------------------------------------------------------------
 1 | // Copyright (c) 2015-2019 The HomeKit ADK Contributors
 2 | //
 3 | // Licensed under the Apache License, Version 2.0 (the “License”);
 4 | // you may not use this file except in compliance with the License.
 5 | // See [CONTRIBUTORS.md] for the list of HomeKit ADK project authors.
 6 | 
 7 | #ifndef HAP_PLATFORM_SYSTEM_COMMAND_H
 8 | #define HAP_PLATFORM_SYSTEM_COMMAND_H
 9 | 
10 | #ifdef __cplusplus
11 | extern "C" {
12 | #endif
13 | 
14 | #include "HAPPlatform.h"
15 | 
16 | #if __has_feature(nullability)
17 | #pragma clang assume_nonnull begin
18 | #endif
19 | 
20 | /**
21 |  * Synchronously runs a system command and stores the result of STDOUT in the provided buffer.
22 |  *
23 |  * Passes an empty environment to HAPPlatformSystemCommandRunWithEnvironment.
24 |  *
25 |  * @param      command              Command to be run.
26 |  * @param[out] bytes                Buffer that will be filled with data.
27 |  * @param      maxBytes             Maximum number of bytes that may be filled into the buffer.
28 |  * @param[in,out] numBytes          Effective number of bytes written to the buffer.
29 |  *
30 |  * @return kHAPError_None           If successful.
31 |  * @return kHAPError_Unknown        If the process does not exit successfully.
32 |  * @return kHAPError_OutOfResources If the buffer was not big enough to store the result.
33 |  */
34 | HAP_RESULT_USE_CHECK
35 | HAPError HAPPlatformSystemCommandRun(
36 |         char* _Nullable const command[_Nonnull],
37 |         char* bytes,
38 |         size_t maxBytes,
39 |         size_t* numBytes);
40 | 
41 | /**
42 |  * Synchronously runs a system command with an environment and stores the result of STDOUT in the provided buffer.
43 |  *
44 |  * @param      command              Command to be run.
45 |  * @param      environment          Environment to be passed to the command.
46 |  * @param[out] bytes                Buffer that will be filled with data.
47 |  * @param      maxBytes             Maximum number of bytes that may be filled into the buffer.
48 |  * @param[in,out] numBytes          Effective number of bytes written to the buffer.
49 |  *
50 |  * @return kHAPError_None           If successful.
51 |  * @return kHAPError_Unknown        If the process does not exit successfully.
52 |  * @return kHAPError_OutOfResources If the buffer was not big enough to store the result.
53 |  */
54 | HAP_RESULT_USE_CHECK
55 | HAPError HAPPlatformSystemCommandRunWithEnvironment(
56 |         char* _Nullable const command[_Nonnull],
57 |         char* _Nullable const environment[_Nullable],
58 |         char* bytes,
59 |         size_t maxBytes,
60 |         size_t* numBytes);
61 | 
62 | #if __has_feature(nullability)
63 | #pragma clang assume_nonnull end
64 | #endif
65 | 
66 | #ifdef __cplusplus
67 | }
68 | #endif
69 | 
70 | #endif
71 | 


--------------------------------------------------------------------------------
/PAL/Mock/HAPPlatformTimer+Init.h:
--------------------------------------------------------------------------------
 1 | // Copyright (c) 2015-2019 The HomeKit ADK Contributors
 2 | //
 3 | // Licensed under the Apache License, Version 2.0 (the “License”);
 4 | // you may not use this file except in compliance with the License.
 5 | // See [CONTRIBUTORS.md] for the list of HomeKit ADK project authors.
 6 | 
 7 | #ifndef HAP_PLATFORM_TIMER_INIT_H
 8 | #define HAP_PLATFORM_TIMER_INIT_H
 9 | 
10 | #ifdef __cplusplus
11 | extern "C" {
12 | #endif
13 | 
14 | #include "HAPPlatform.h"
15 | 
16 | #if __has_feature(nullability)
17 | #pragma clang assume_nonnull begin
18 | #endif
19 | 
20 | /**
21 |  * Processes expired timers.
22 |  */
23 | void HAPPlatformTimerProcessExpiredTimers(void);
24 | 
25 | #if __has_feature(nullability)
26 | #pragma clang assume_nonnull end
27 | #endif
28 | 
29 | #ifdef __cplusplus
30 | }
31 | #endif
32 | 
33 | #endif
34 | 


--------------------------------------------------------------------------------
/PAL/POSIX/HAPPlatform+Init.h:
--------------------------------------------------------------------------------
 1 | // Copyright (c) 2015-2019 The HomeKit ADK Contributors
 2 | //
 3 | // Licensed under the Apache License, Version 2.0 (the “License”);
 4 | // you may not use this file except in compliance with the License.
 5 | // See [CONTRIBUTORS.md] for the list of HomeKit ADK project authors.
 6 | 
 7 | #ifndef HAP_PLATFORM_INIT_H
 8 | #define HAP_PLATFORM_INIT_H
 9 | 
10 | #ifdef __cplusplus
11 | extern "C" {
12 | #endif
13 | 
14 | /**
15 |  * Optional features set in Makefile.
16 |  */
17 | /**@{*/
18 | #ifndef HAVE_DISPLAY
19 | #define HAVE_DISPLAY 0
20 | #endif
21 | 
22 | #ifndef HAVE_NFC
23 | #define HAVE_NFC 0
24 | #endif
25 | 
26 | #ifndef HAVE_MFI_HW_AUTH
27 | #define HAVE_MFI_HW_AUTH 0
28 | #endif
29 | /**@}*/
30 | 
31 | #include <stdlib.h>
32 | 
33 | #include "HAPPlatform.h"
34 | 
35 | #if __has_feature(nullability)
36 | #pragma clang assume_nonnull begin
37 | #endif
38 | 
39 | /**
40 |  * Deallocate memory pointed to by ptr.
41 |  *
42 |  * @param      ptr                  Pointer to memory to be deallocated.
43 |  */
44 | #define HAPPlatformFreeSafe(ptr) \
45 |     do { \
46 |         HAPAssert(ptr); \
47 |         free(ptr); \
48 |         ptr = NULL; \
49 |     } while (0)
50 | 
51 | #if __has_feature(nullability)
52 | #pragma clang assume_nonnull end
53 | #endif
54 | 
55 | #ifdef __cplusplus
56 | }
57 | #endif
58 | 
59 | #endif
60 | 


--------------------------------------------------------------------------------
/PAL/POSIX/HAPPlatform.c:
--------------------------------------------------------------------------------
 1 | // Copyright (c) 2015-2019 The HomeKit ADK Contributors
 2 | //
 3 | // Licensed under the Apache License, Version 2.0 (the “License”);
 4 | // you may not use this file except in compliance with the License.
 5 | // See [CONTRIBUTORS.md] for the list of HomeKit ADK project authors.
 6 | 
 7 | #include "HAPPlatform.h"
 8 | 
 9 | #include <stdlib.h>
10 | #include <sys/utsname.h>
11 | 
12 | static struct utsname* sysinfo = NULL;
13 | 
14 | static struct utsname* SystemInfo() {
15 |     if (!sysinfo) {
16 |         sysinfo = (struct utsname*) malloc(sizeof(struct utsname));
17 |         int ret = uname(sysinfo);
18 |         HAPAssert(!ret);
19 |     }
20 |     return sysinfo;
21 | }
22 | 
23 | HAP_RESULT_USE_CHECK
24 | uint32_t HAPPlatformGetCompatibilityVersion(void) {
25 |     return HAP_PLATFORM_COMPATIBILITY_VERSION;
26 | }
27 | 
28 | HAP_RESULT_USE_CHECK
29 | const char* HAPPlatformGetIdentification(void) {
30 |     return SystemInfo()->sysname;
31 | }
32 | 
33 | HAP_RESULT_USE_CHECK
34 | const char* HAPPlatformGetVersion(void) {
35 |     return SystemInfo()->release;
36 | }
37 | 
38 | HAP_RESULT_USE_CHECK
39 | const char* HAPPlatformGetBuild(void) {
40 |     HAP_DIAGNOSTIC_PUSH
41 |     HAP_DIAGNOSTIC_IGNORED_CLANG("-Wdate-time")
42 |     const char* build = __DATE__ " " __TIME__;
43 |     HAP_DIAGNOSTIC_POP
44 |     return build;
45 | }
46 | 


--------------------------------------------------------------------------------
/PAL/POSIX/HAPPlatformAbort.c:
--------------------------------------------------------------------------------
 1 | // Copyright (c) 2015-2019 The HomeKit ADK Contributors
 2 | //
 3 | // Licensed under the Apache License, Version 2.0 (the “License”);
 4 | // you may not use this file except in compliance with the License.
 5 | // See [CONTRIBUTORS.md] for the list of HomeKit ADK project authors.
 6 | 
 7 | #include <stdlib.h>
 8 | 
 9 | #include "HAPPlatform.h"
10 | 
11 | HAP_NORETURN
12 | void HAPPlatformAbort(void) {
13 |     exit(EXIT_FAILURE);
14 | }
15 | 


--------------------------------------------------------------------------------
/PAL/POSIX/HAPPlatformAccessorySetup+Init.h:
--------------------------------------------------------------------------------
 1 | // Copyright (c) 2015-2019 The HomeKit ADK Contributors
 2 | //
 3 | // Licensed under the Apache License, Version 2.0 (the “License”);
 4 | // you may not use this file except in compliance with the License.
 5 | // See [CONTRIBUTORS.md] for the list of HomeKit ADK project authors.
 6 | 
 7 | #ifndef HAP_PLATFORM_ACCESSORY_SETUP_INIT_H
 8 | #define HAP_PLATFORM_ACCESSORY_SETUP_INIT_H
 9 | 
10 | #ifdef __cplusplus
11 | extern "C" {
12 | #endif
13 | 
14 | #include "HAPPlatform.h"
15 | 
16 | #if __has_feature(nullability)
17 | #pragma clang assume_nonnull begin
18 | #endif
19 | 
20 | /**@file
21 |  * Accessory setup manager.
22 |  *
23 |  * - The linked key-value store needs to be provisioned with accessory setup information
24 |  *   before this implementation may be used. Please refer to the Provision tool.
25 |  *
26 |  * **Example**
27 | 
28 |    @code{.c}
29 | 
30 |    // Get dependencies.
31 |    HAPPlatformKeyValueStoreRef keyValueStore;
32 | 
33 |    // Allocate accessory setup manager.
34 |    static HAPPlatformAccessorySetup accessorySetup;
35 | 
36 |    // Determine accessory capabilities.
37 |    bool HAVE_DISPLAY;
38 |    bool HAVE_NFC;
39 |    const char *LIBNFC_CONNECTION_STRING; // Only applicable if programmable NFC is used.
40 | 
41 |    // Initialize accessory setup manager.
42 |    HAPPlatformAccessorySetupCreate(&accessorySetup,
43 |        &(const HAPPlatformAccessorySetupOptions) {
44 |            .keyValueStore = keyValueStore,
45 |            .useDisplay = HAVE_DISPLAY,
46 |            .useProgrammableNFC = HAVE_NFC,
47 |            .libnfcConnectionString = HAVE_NFC ? LIBNFC_CONNECTION_STRING : NULL
48 |        });
49 | 
50 |    @endcode
51 |  */
52 | 
53 | /**
54 |  * Accessory setup manager initialization options.
55 |  */
56 | typedef struct {
57 |     /**
58 |      * Key-value store.
59 |      */
60 |     HAPPlatformKeyValueStoreRef keyValueStore;
61 | } HAPPlatformAccessorySetupOptions;
62 | 
63 | /**
64 |  * Accessory setup manager.
65 |  */
66 | struct HAPPlatformAccessorySetup {
67 |     // Opaque type. Do not access the instance fields directly.
68 |     /**@cond */
69 |     HAPPlatformKeyValueStoreRef keyValueStore;
70 |     /**@endcond */
71 | };
72 | 
73 | /**
74 |  * Initializes the accessory setup manager.
75 |  *
76 |  * @param[out] accessorySetup       Pointer to an allocated but uninitialized HAPPlatformAccessorySetup structure.
77 |  * @param      options              Initialization options.
78 |  */
79 | void HAPPlatformAccessorySetupCreate(
80 |         HAPPlatformAccessorySetupRef accessorySetup,
81 |         const HAPPlatformAccessorySetupOptions* options);
82 | 
83 | #if __has_feature(nullability)
84 | #pragma clang assume_nonnull end
85 | #endif
86 | 
87 | #ifdef __cplusplus
88 | }
89 | #endif
90 | 
91 | #endif
92 | 


--------------------------------------------------------------------------------
/PAL/POSIX/HAPPlatformAccessorySetupDisplay+Init.h:
--------------------------------------------------------------------------------
 1 | // Copyright (c) 2015-2019 The HomeKit ADK Contributors
 2 | //
 3 | // Licensed under the Apache License, Version 2.0 (the “License”);
 4 | // you may not use this file except in compliance with the License.
 5 | // See [CONTRIBUTORS.md] for the list of HomeKit ADK project authors.
 6 | 
 7 | #ifndef HAP_PLATFORM_ACCESSORY_SETUP_DISPLAY_INIT_H
 8 | #define HAP_PLATFORM_ACCESSORY_SETUP_DISPLAY_INIT_H
 9 | 
10 | #ifdef __cplusplus
11 | extern "C" {
12 | #endif
13 | 
14 | #include "HAPPlatform.h"
15 | 
16 | #if __has_feature(nullability)
17 | #pragma clang assume_nonnull begin
18 | #endif
19 | 
20 | #ifndef HAVE_DISPLAY
21 | #define HAVE_DISPLAY 0
22 | #endif
23 | 
24 | /**@file
25 |  * Accessory setup display.
26 |  *
27 |  * - The HAPLog APIs are used to display the setup payload and setup code.
28 |  *   For a real display the implementation needs to be adjusted.
29 |  *
30 |  * **Example**
31 | 
32 |    @code{.c}
33 | 
34 |    // Allocate Accessory setup display.
35 |    static HAPPlatformAccessorySetupDisplay setupDisplay;
36 | 
37 |    // Initialize Accessory setup display.
38 |    HAPPlatformAccessorySetupDisplayCreate(&setupDisplay);
39 | 
40 |    @endcode
41 | */
42 | 
43 | /**
44 |  * Accessory setup display.
45 |  */
46 | struct HAPPlatformAccessorySetupDisplay {
47 |     // Opaque type. Do not access the instance fields directly.
48 |     /**@cond */
49 |     HAPSetupPayload setupPayload;
50 |     HAPSetupCode setupCode;
51 |     bool setupPayloadIsSet : 1;
52 |     bool setupCodeIsSet : 1;
53 |     /**@endcond */
54 | };
55 | 
56 | /**
57 |  * Initializes Accessory setup display.
58 |  *
59 |  * @param[out] setupDisplay         Accessory setup display.
60 |  */
61 | void HAPPlatformAccessorySetupDisplayCreate(HAPPlatformAccessorySetupDisplayRef setupDisplay);
62 | 
63 | #if __has_feature(nullability)
64 | #pragma clang assume_nonnull end
65 | #endif
66 | 
67 | #ifdef __cplusplus
68 | }
69 | #endif
70 | 
71 | #endif
72 | 


--------------------------------------------------------------------------------
/PAL/POSIX/HAPPlatformBLEPeripheralManager+Init.h:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2015-2019 The HomeKit ADK Contributors
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the “License”);
4 | // you may not use this file except in compliance with the License.
5 | // See [CONTRIBUTORS.md] for the list of HomeKit ADK project authors.
6 | 
7 | #include "../Mock/HAPPlatformBLEPeripheralManager+Init.h"
8 | 


--------------------------------------------------------------------------------
/PAL/POSIX/HAPPlatformBLEPeripheralManager.c:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2015-2019 The HomeKit ADK Contributors
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the “License”);
4 | // you may not use this file except in compliance with the License.
5 | // See [CONTRIBUTORS.md] for the list of HomeKit ADK project authors.
6 | 
7 | #include "../Mock/HAPPlatformBLEPeripheralManager.c"
8 | 


--------------------------------------------------------------------------------
/PAL/POSIX/HAPPlatformClock.c:
--------------------------------------------------------------------------------
 1 | // Copyright (c) 2015-2019 The HomeKit ADK Contributors
 2 | //
 3 | // Licensed under the Apache License, Version 2.0 (the “License”);
 4 | // you may not use this file except in compliance with the License.
 5 | // See [CONTRIBUTORS.md] for the list of HomeKit ADK project authors.
 6 | 
 7 | #include <errno.h>
 8 | #include <sys/time.h>
 9 | #include <time.h>
10 | 
11 | #include "HAPPlatform.h"
12 | 
13 | static const HAPLogObject logObject = { .subsystem = kHAPPlatform_LogSubsystem, .category = "Clock" };
14 | 
15 | HAPTime HAPPlatformClockGetCurrent(void) {
16 |     int e;
17 | 
18 |     static bool isInitialized;
19 |     static HAPTime previousNow;
20 | 
21 |     // Get current time.
22 |     HAPTime now;
23 | #if defined(CLOCK_MONOTONIC_RAW)
24 |     // This clock should be unaffected by frequency or time adjustments.
25 | 
26 |     if (!isInitialized) {
27 |         HAPLog(&logObject, "Using 'clock_gettime' with 'CLOCK_MONOTONIC_RAW'.");
28 |         isInitialized = true;
29 |     }
30 | 
31 |     struct timespec t;
32 |     e = clock_gettime(CLOCK_MONOTONIC_RAW, &t);
33 |     if (e) {
34 |         int _errno = errno;
35 |         HAPAssert(e == -1);
36 |         HAPLogError(&logObject, "clock_gettime failed: %d.", _errno);
37 |         HAPFatalError();
38 |     }
39 |     now = (HAPTime) t.tv_sec * 1000 + (HAPTime) t.tv_nsec / 1000000;
40 | 
41 |     if (now < previousNow) {
42 |         HAPLog(&logObject, "Time jumped backwards by %lu ms.", (unsigned long) (previousNow - now));
43 |         HAPFatalError();
44 |     }
45 | #else
46 |     // Portable fallback clock.
47 |     // Note: `gettimeofday` is susceptible to significant jumps as it can be changed remotely (e.g. through NTP).
48 |     // We try to mitigate against the case of turning back the clock by keeping track of the time difference.
49 |     // When the time jumps forward timers may complete early and operations may fail.
50 |     // This may happen for example when the system time is re-synchronized after joining a different network.
51 | 
52 |     if (!isInitialized) {
53 |         HAPLog(&logObject, "Using 'gettimeofday'.");
54 |         isInitialized = true;
55 |     }
56 | 
57 |     struct timeval t;
58 |     e = gettimeofday(&t, NULL);
59 |     if (e) {
60 |         int _errno = errno;
61 |         HAPAssert(e == -1);
62 |         HAPLogError(&logObject, "gettimeofday failed: %d.", _errno);
63 |         HAPFatalError();
64 |     }
65 |     now = (HAPTime) t.tv_sec * 1000 + (HAPTime) t.tv_usec / 1000;
66 | 
67 |     static HAPTime offset;
68 |     if (now < previousNow) {
69 |         HAPLog(&logObject, "Time jumped backwards by %lu ms. Adjusting offset.", (unsigned long) (previousNow - now));
70 |         offset += previousNow - now;
71 |     }
72 |     now += offset;
73 | #endif
74 | 
75 |     // Check for overflow.
76 |     if (now & (1ull << 63)) {
77 |         HAPLog(&logObject, "Time overflowed (capped at 2^63 - 1).");
78 |         HAPFatalError();
79 |     }
80 | 
81 |     previousNow = now;
82 |     return now;
83 | }
84 | 


--------------------------------------------------------------------------------
/PAL/POSIX/HAPPlatformKeyValueStore+Init.h:
--------------------------------------------------------------------------------
 1 | // Copyright (c) 2015-2019 The HomeKit ADK Contributors
 2 | //
 3 | // Licensed under the Apache License, Version 2.0 (the “License”);
 4 | // you may not use this file except in compliance with the License.
 5 | // See [CONTRIBUTORS.md] for the list of HomeKit ADK project authors.
 6 | 
 7 | #ifndef HAP_PLATFORM_KEY_VALUE_STORE_INIT_H
 8 | #define HAP_PLATFORM_KEY_VALUE_STORE_INIT_H
 9 | 
10 | #ifdef __cplusplus
11 | extern "C" {
12 | #endif
13 | 
14 | #include "HAPPlatform.h"
15 | 
16 | #if __has_feature(nullability)
17 | #pragma clang assume_nonnull begin
18 | #endif
19 | 
20 | /**@file
21 |  * File system based key-value store.
22 |  *
23 |  * The implementation uses the filesystem to store data persistently.
24 |  * Each `HAPPlatformKeyValueStoreKey` is mapped to a file within a configurable directory.
25 |  *
26 |  * Data writes and deletions are persisted in a blocking manner using `fsync`.
27 |  * This guarantees atomicity in case of power failure.
28 |  *
29 |  * **Example**
30 | 
31 |    @code{.c}
32 | 
33 |    // Allocate key-value store.
34 |    static HAPPlatformKeyValueStore keyValueStore;
35 | 
36 |    // Initialize key-value store.
37 |    HAPPlatformKeyValueStoreCreate(&platform.keyValueStore,
38 |        &(const HAPPlatformKeyValueStoreOptions) {
39 |            .rootDirectory = ".HomeKitStore" // May be changed to store into a different directory.
40 |        });
41 | 
42 |    @endcode
43 |  */
44 | 
45 | /**
46 |  * Key-value store initialization options.
47 |  */
48 | typedef struct {
49 |     /**
50 |      * Root directory into which the values will be stored as files.
51 |      *
52 |      * - This directory is relative to the directory from which the application is executing,
53 |      *   i.e. not relative to the application binary.
54 |      */
55 |     const char* rootDirectory;
56 | } HAPPlatformKeyValueStoreOptions;
57 | 
58 | /**
59 |  * Key-value store.
60 |  */
61 | struct HAPPlatformKeyValueStore {
62 |     // Opaque type. Do not access the instance fields directly.
63 |     /**@cond */
64 |     const char* rootDirectory;
65 |     /**@endcond */
66 | };
67 | 
68 | /**
69 |  * Initializes the key-value store.
70 |  *
71 |  * @param[out] keyValueStore        Pointer to an allocated but uninitialized HAPPlatformKeyValueStore structure.
72 |  * @param      options              Initialization options.
73 |  */
74 | void HAPPlatformKeyValueStoreCreate(
75 |         HAPPlatformKeyValueStoreRef keyValueStore,
76 |         const HAPPlatformKeyValueStoreOptions* options);
77 | 
78 | #if __has_feature(nullability)
79 | #pragma clang assume_nonnull end
80 | #endif
81 | 
82 | #ifdef __cplusplus
83 | }
84 | #endif
85 | 
86 | #endif
87 | 


--------------------------------------------------------------------------------
/PAL/POSIX/HAPPlatformKeyValueStore+SDKDomains.h:
--------------------------------------------------------------------------------
 1 | // Copyright (c) 2015-2019 The HomeKit ADK Contributors
 2 | //
 3 | // Licensed under the Apache License, Version 2.0 (the “License”);
 4 | // you may not use this file except in compliance with the License.
 5 | // See [CONTRIBUTORS.md] for the list of HomeKit ADK project authors.
 6 | 
 7 | #ifndef HAP_PLATFORM_KEY_VALUE_STORE_SDK_DOMAINS_H
 8 | #define HAP_PLATFORM_KEY_VALUE_STORE_SDK_DOMAINS_H
 9 | 
10 | #ifdef __cplusplus
11 | extern "C" {
12 | #endif
13 | 
14 | #include "HAPPlatform.h"
15 | 
16 | /**
17 |  * Statically provisioned data.
18 |  *
19 |  * Purged: Never.
20 |  */
21 | #define kSDKKeyValueStoreDomain_Provisioning ((HAPPlatformKeyValueStoreDomain) 0x40)
22 | 
23 | ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
24 | 
25 | /**
26 |  * Static setup code SRP salt & verifier.
27 |  *
28 |  * Format: HAPSetupInfo.
29 |  */
30 | #define kSDKKeyValueStoreKey_Provisioning_SetupInfo ((HAPPlatformKeyValueStoreKey) 0x10)
31 | 
32 | /**
33 |  * Setup ID.
34 |  *
35 |  * Format: HAPSetupID.
36 |  */
37 | #define kSDKKeyValueStoreKey_Provisioning_SetupID ((HAPPlatformKeyValueStoreKey) 0x11)
38 | 
39 | /**
40 |  * Setup code for NFC.
41 |  *
42 |  * Format: HAPSetupCode.
43 |  */
44 | #define kSDKKeyValueStoreKey_Provisioning_SetupCode ((HAPPlatformKeyValueStoreKey) 0x12)
45 | 
46 | /**
47 |  * Software Token UUID.
48 |  *
49 |  * Format: HAPPlatformMFiTokenAuthUUID.
50 |  */
51 | #define kSDKKeyValueStoreKey_Provisioning_MFiTokenUUID ((HAPPlatformKeyValueStoreKey) 0x20)
52 | 
53 | /**
54 |  * Software Token.
55 |  *
56 |  * Format: Opaque blob, up to kHAPPlatformMFiTokenAuth_MaxMFiTokenBytes bytes.
57 |  */
58 | #define kSDKKeyValueStoreKey_Provisioning_MFiToken ((HAPPlatformKeyValueStoreKey) 0x21)
59 | 
60 | #ifdef __cplusplus
61 | }
62 | #endif
63 | 
64 | #endif
65 | 


--------------------------------------------------------------------------------
/PAL/POSIX/HAPPlatformLog+Init.h:
--------------------------------------------------------------------------------
 1 | // Copyright (c) 2015-2019 The HomeKit ADK Contributors
 2 | //
 3 | // Licensed under the Apache License, Version 2.0 (the “License”);
 4 | // you may not use this file except in compliance with the License.
 5 | // See [CONTRIBUTORS.md] for the list of HomeKit ADK project authors.
 6 | 
 7 | #ifndef HAP_PLATFORM_LOG_INIT_H
 8 | #define HAP_PLATFORM_LOG_INIT_H
 9 | 
10 | #ifdef __cplusplus
11 | extern "C" {
12 | #endif
13 | 
14 | #include "HAPPlatform.h"
15 | 
16 | #if __has_feature(nullability)
17 | #pragma clang assume_nonnull begin
18 | #endif
19 | 
20 | /**
21 |  * Logs a POSIX error, for example fetched from errno.
22 |  *
23 |  * - The error number will be mapped to a locale-dependent error message string.
24 |  *
25 |  * @param      type                 A log type constant, indicating the level of logging to perform.
26 |  * @param      message              The log message.
27 |  * @param      errorNumber          POSIX error number.
28 |  * @param      function             Function name in which the error occurred.
29 |  * @param      file                 File name in which the error occurred.
30 |  * @param      line                 Line number on which the error occurred.
31 |  */
32 | void HAPPlatformLogPOSIXError(
33 |         HAPLogType type,
34 |         const char* message,
35 |         int errorNumber,
36 |         const char* function,
37 |         const char* file,
38 |         int line);
39 | 
40 | #if __has_feature(nullability)
41 | #pragma clang assume_nonnull end
42 | #endif
43 | 
44 | #ifdef __cplusplus
45 | }
46 | #endif
47 | 
48 | #endif
49 | 


--------------------------------------------------------------------------------
/PAL/POSIX/HAPPlatformMFiHWAuth+Init.h:
--------------------------------------------------------------------------------
 1 | // Copyright (c) 2015-2019 The HomeKit ADK Contributors
 2 | //
 3 | // Licensed under the Apache License, Version 2.0 (the “License”);
 4 | // you may not use this file except in compliance with the License.
 5 | // See [CONTRIBUTORS.md] for the list of HomeKit ADK project authors.
 6 | 
 7 | #ifndef HAP_PLATFORM_MFI_HW_AUTH_INIT_H
 8 | #define HAP_PLATFORM_MFI_HW_AUTH_INIT_H
 9 | 
10 | #ifdef __cplusplus
11 | extern "C" {
12 | #endif
13 | 
14 | #include "HAPPlatform.h"
15 | 
16 | #if __has_feature(nullability)
17 | #pragma clang assume_nonnull begin
18 | #endif
19 | 
20 | /**@file
21 |  * Apple Authentication Coprocessor provider based on the i2c-dev module.
22 |  *
23 |  * The implementation accesses the Apple Authentication Coprocessor directly over I2C.
24 |  * It is assumed that the Apple Authentication Coprocessor uses I2C address 0x10
25 |  * and that the i2c-dev module makes it accessible through the path "/dev/i2c-1".
26 |  * If a different path or I2C address is used, the implementation needs to be adjusted.
27 |  *
28 |  * **Example**
29 | 
30 |    @code{.c}
31 | 
32 |    // Allocate Apple Authentication Coprocessor provider.
33 |    static HAPPlatformMFiHWAuth mfiHWAuth;
34 | 
35 |    // Initialize Apple Authentication Coprocessor provider.
36 |    HAPPlatformMFiHWAuthCreate(&mfiHWAuth);
37 | 
38 |    // Before process exits, ensure that resources are properly released.
39 |    HAPPlatformMFiHWAuthRelease(&mfiHWAuth);
40 | 
41 |    @endcode
42 |  */
43 | 
44 | /**
45 |  * Apple Authentication Coprocessor provider.
46 |  */
47 | struct HAPPlatformMFiHWAuth {
48 |     // Opaque type. Do not access the instance fields directly.
49 |     /**@cond */
50 |     int i2cFile;
51 |     bool enabled;
52 |     /**@endcond */
53 | };
54 | 
55 | /**
56 |  * Initializes an Apple Authentication Coprocessor provider.
57 |  *
58 |  * @param[out] mfiHWAuth            Pointer to an allocated but uninitialized HAPPlatformMFiHWAuth structure.
59 |  */
60 | void HAPPlatformMFiHWAuthCreate(HAPPlatformMFiHWAuthRef mfiHWAuth);
61 | 
62 | /**
63 |  * Deinitializes an Apple Authentication Coprocessor.
64 |  *
65 |  * @param      mfiHWAuth            Initialized Apple Authentication Coprocessor provider.
66 |  */
67 | void HAPPlatformMFiHWAuthRelease(HAPPlatformMFiHWAuthRef mfiHWAuth);
68 | 
69 | #if __has_feature(nullability)
70 | #pragma clang assume_nonnull end
71 | #endif
72 | 
73 | #ifdef __cplusplus
74 | }
75 | #endif
76 | 
77 | #endif
78 | 


--------------------------------------------------------------------------------
/PAL/POSIX/HAPPlatformMFiTokenAuth+Init.h:
--------------------------------------------------------------------------------
 1 | // Copyright (c) 2015-2019 The HomeKit ADK Contributors
 2 | //
 3 | // Licensed under the Apache License, Version 2.0 (the “License”);
 4 | // you may not use this file except in compliance with the License.
 5 | // See [CONTRIBUTORS.md] for the list of HomeKit ADK project authors.
 6 | 
 7 | #ifndef HAP_PLATFORM_MFI_TOKEN_AUTH_INIT_H
 8 | #define HAP_PLATFORM_MFI_TOKEN_AUTH_INIT_H
 9 | 
10 | #ifdef __cplusplus
11 | extern "C" {
12 | #endif
13 | 
14 | #include "HAPPlatform.h"
15 | 
16 | #if __has_feature(nullability)
17 | #pragma clang assume_nonnull begin
18 | #endif
19 | 
20 | /**@file
21 |  * Software Token provider.
22 |  *
23 |  * The linked key-value store needs to be provisioned with software token information
24 |  * before this implementation may be used. Please refer to the Provision tool.
25 |  *
26 |  * **Example**
27 | 
28 |    @code{.c}
29 | 
30 |    // Get dependencies.
31 |    HAPPlatformKeyValueStoreRef keyValueStore;
32 | 
33 |    // Allocate Software Token provider.
34 |    static HAPPlatformMFiTokenAuth mfiTokenAuth;
35 | 
36 |    // Initialize Software Token provider.
37 |    HAPPlatformMFiTokenAuthCreate(&mfiTokenAuth,
38 |        &(const HAPPlatformMFiTokenAuthOptions) {
39 |            .keyValueStore = keyValueStore
40 |        });
41 | 
42 |    @endcode
43 |  */
44 | 
45 | /**
46 |  * Software token provider initialization options.
47 |  */
48 | typedef struct {
49 |     /**
50 |      * Key-value store.
51 |      */
52 |     HAPPlatformKeyValueStoreRef keyValueStore;
53 | } HAPPlatformMFiTokenAuthOptions;
54 | 
55 | /**
56 |  * Software Token provider.
57 |  */
58 | struct HAPPlatformMFiTokenAuth {
59 |     // Opaque type. Do not access the instance fields directly.
60 |     /**@cond */
61 |     HAPPlatformKeyValueStoreRef keyValueStore;
62 |     /**@endcond */
63 | };
64 | 
65 | /**
66 |  * Initializes Software Token provider.
67 |  *
68 |  * @param[out] mfiTokenAuth         Software Token provider.
69 |  * @param      options              Initialization options.
70 |  */
71 | void HAPPlatformMFiTokenAuthCreate(
72 |         HAPPlatformMFiTokenAuthRef mfiTokenAuth,
73 |         const HAPPlatformMFiTokenAuthOptions* options);
74 | 
75 | /**
76 |  * Returns whether a Software Token is provisioned.
77 |  *
78 |  * @param      mfiTokenAuth         Software Token provider.
79 |  *
80 |  * @return true                     If a Software Token is provisioned.
81 |  * @return false                    Otherwise.
82 |  */
83 | bool HAPPlatformMFiTokenAuthIsProvisioned(HAPPlatformMFiTokenAuthRef mfiTokenAuth);
84 | 
85 | #if __has_feature(nullability)
86 | #pragma clang assume_nonnull end
87 | #endif
88 | 
89 | #ifdef __cplusplus
90 | }
91 | #endif
92 | 
93 | #endif
94 | 


--------------------------------------------------------------------------------
/PAL/POSIX/HAPPlatformRandomNumber.c:
--------------------------------------------------------------------------------
 1 | // Copyright (c) 2015-2019 The HomeKit ADK Contributors
 2 | //
 3 | // Licensed under the Apache License, Version 2.0 (the “License”);
 4 | // you may not use this file except in compliance with the License.
 5 | // See [CONTRIBUTORS.md] for the list of HomeKit ADK project authors.
 6 | 
 7 | #include <errno.h>
 8 | #include <linux/random.h>
 9 | #include <syscall.h>
10 | #include <unistd.h>
11 | 
12 | #include "HAPPlatform.h"
13 | 
14 | /**
15 |  * Linux Random Number generator.
16 |  *
17 |  * This Random Number generator makes use of the Linux getrandom(2) interface.
18 |  * Please note that this interface is only supported from Linux 3.17 onwards.
19 |  *
20 |  * For more information see:
21 |  *  - LWN - The long road to getrandom() in glibc: https://lwn.net/Articles/711013/
22 |  *  - Getrandom Manpage: http://man7.org/linux/man-pages/man2/getrandom.2.html
23 |  */
24 | 
25 | static const HAPLogObject logObject = { .subsystem = kHAPPlatform_LogSubsystem, .category = "RandomNumber" };
26 | 
27 | void HAPPlatformRandomNumberFill(void* bytes, size_t numBytes) {
28 |     HAPPrecondition(bytes);
29 | 
30 |     // Read random data.
31 |     for (int i = 0; i < 5; i++) {
32 |         size_t o = 0;
33 |         while (o < numBytes) {
34 |             size_t c = numBytes - o;
35 | 
36 |             // Using getrandom() to read small buffers (<= 256 bytes) from the urandom source is the preferred mode of
37 |             // usage.
38 |             // Source: man page of getrandom(2).
39 |             if (c > 256) {
40 |                 c = 256;
41 |             }
42 | 
43 |             ssize_t n;
44 |             do {
45 |                 // Flags to call getrandom.
46 |                 const int getrandomFlags = GRND_NONBLOCK; // Use the urandom source and do not block.
47 | 
48 |                 // With glibc >= 2.25 it is possible to call getrandom() directly.
49 |                 // Source: man page of getrandom(2).
50 |                 n = syscall(SYS_getrandom, &((uint8_t*) bytes)[o], c, getrandomFlags);
51 |             } while ((n == -1) && (errno == EINTR));
52 | 
53 |             if (n < 0) {
54 |                 int _errno = errno;
55 |                 HAPAssert(n == -1);
56 |                 HAPLogError(&logObject, "Read from getrandom failed: %d.", _errno);
57 |                 HAPFatalError();
58 |             }
59 | 
60 |             HAPAssert((size_t) n <= c);
61 |             o += (size_t) n;
62 |         }
63 | 
64 |         // Verify random data.
65 |         if (numBytes < 128 / 8 || !HAPRawBufferIsZero(bytes, numBytes)) {
66 |             return;
67 |         }
68 |     }
69 |     HAPLogError(&logObject, "getrandom produced only zeros.");
70 |     HAPFatalError();
71 | }
72 | 


--------------------------------------------------------------------------------
/PAL/POSIX/HAPPlatformRunLoop+Init.h:
--------------------------------------------------------------------------------
 1 | // Copyright (c) 2015-2019 The HomeKit ADK Contributors
 2 | //
 3 | // Licensed under the Apache License, Version 2.0 (the “License”);
 4 | // you may not use this file except in compliance with the License.
 5 | // See [CONTRIBUTORS.md] for the list of HomeKit ADK project authors.
 6 | 
 7 | #ifndef HAP_PLATFORM_RUN_LOOP_INIT_H
 8 | #define HAP_PLATFORM_RUN_LOOP_INIT_H
 9 | 
10 | #ifdef __cplusplus
11 | extern "C" {
12 | #endif
13 | 
14 | #include "HAPPlatform.h"
15 | 
16 | #if __has_feature(nullability)
17 | #pragma clang assume_nonnull begin
18 | #endif
19 | 
20 | /**@file
21 |  * Global run loop for POSIX.
22 |  *
23 |  * This implementation implements the following platform modules:
24 |  * - HAPPlatformRunLoop
25 |  * - HAPPlatformTimer
26 |  * - HAPPlatformFileHandle (POSIX-specific)
27 |  */
28 | 
29 | /**
30 |  * Run loop initialization options.
31 |  */
32 | typedef struct {
33 |     /**
34 |      * Key-value store.
35 |      */
36 |     HAPPlatformKeyValueStoreRef keyValueStore;
37 | } HAPPlatformRunLoopOptions;
38 | 
39 | /**
40 |  * Create run loop.
41 |  */
42 | void HAPPlatformRunLoopCreate(const HAPPlatformRunLoopOptions* options);
43 | 
44 | /**
45 |  * Release run loop.
46 |  */
47 | void HAPPlatformRunLoopRelease(void);
48 | 
49 | #if __has_feature(nullability)
50 | #pragma clang assume_nonnull end
51 | #endif
52 | 
53 | #ifdef __cplusplus
54 | }
55 | #endif
56 | 
57 | #endif
58 | 


--------------------------------------------------------------------------------
/PAL/POSIX/HAPPlatformServiceDiscovery+Init.h:
--------------------------------------------------------------------------------
 1 | // Copyright (c) 2015-2019 The HomeKit ADK Contributors
 2 | //
 3 | // Licensed under the Apache License, Version 2.0 (the “License”);
 4 | // you may not use this file except in compliance with the License.
 5 | // See [CONTRIBUTORS.md] for the list of HomeKit ADK project authors.
 6 | 
 7 | #ifndef HAP_PLATFORM_SERVICE_DISCOVERY_INIT_H
 8 | #define HAP_PLATFORM_SERVICE_DISCOVERY_INIT_H
 9 | 
10 | #ifdef __cplusplus
11 | extern "C" {
12 | #endif
13 | 
14 | #include <dns_sd.h>
15 | #include <net/if.h>
16 | 
17 | #include "HAPPlatform.h"
18 | #include "HAPPlatformFileHandle.h"
19 | 
20 | #if __has_feature(nullability)
21 | #pragma clang assume_nonnull begin
22 | #endif
23 | 
24 | /**@file
25 |  * Bonjour service discovery for POSIX based on Apple's mDNSResponder.
26 |  *
27 |  * **Example**
28 | 
29 |    @code{.c}
30 | 
31 |    // Allocate service discovery object.
32 |    static HAPPlatformServiceDiscovery serviceDiscovery;
33 | 
34 |    // Initialize service discovery object. Depends on a TCP stream manager instance.
35 |    HAPPlatformServiceDiscoveryCreate(&platform.serviceDiscovery,
36 |        &(const HAPPlatformServiceDiscoveryOptions) {
37 |            // Register services on all available network interfaces.
38 |            .interfaceName = NULL
39 |        });
40 | 
41 |    @endcode
42 |  */
43 | 
44 | /**
45 |  * Service discovery initialization options.
46 |  */
47 | typedef struct {
48 |     /**
49 |      * Local network interface name on which to register services.
50 |      * A value of NULL will use all available network interfaces.
51 |      */
52 |     const char* _Nullable interfaceName;
53 | } HAPPlatformServiceDiscoveryOptions;
54 | 
55 | /**
56 |  * Service discovery memory configuration value.
57 |  */
58 | #define kHAPPlatformServiceDiscovery_MaxTXTRecordBufferBytes (512)
59 | 
60 | /**
61 |  * Service discovery.
62 |  */
63 | struct HAPPlatformServiceDiscovery {
64 |     // Opaque type. Do not access the instance fields directly.
65 |     /**@cond */
66 |     char interfaceName[IFNAMSIZ];
67 | 
68 |     DNSServiceRef dnsService;
69 |     TXTRecordRef txtRecord;
70 |     char txtRecordBuffer[kHAPPlatformServiceDiscovery_MaxTXTRecordBufferBytes];
71 |     HAPPlatformFileHandleRef fileHandle;
72 |     /**@endcond */
73 | };
74 | 
75 | /**
76 |  * Initializes service discovery.
77 |  *
78 |  * @param      serviceDiscovery     Pointer to an allocated but uninitialized HAPPlatformServiceDiscovery structure.
79 |  * @param      options              Initialization options.
80 |  */
81 | void HAPPlatformServiceDiscoveryCreate(
82 |         HAPPlatformServiceDiscoveryRef serviceDiscovery,
83 |         const HAPPlatformServiceDiscoveryOptions* options);
84 | 
85 | #if __has_feature(nullability)
86 | #pragma clang assume_nonnull end
87 | #endif
88 | 
89 | #ifdef __cplusplus
90 | }
91 | #endif
92 | 
93 | #endif
94 | 


--------------------------------------------------------------------------------
/PAL/POSIX/HAPPlatformSystemCommand.h:
--------------------------------------------------------------------------------
 1 | // Copyright (c) 2015-2019 The HomeKit ADK Contributors
 2 | //
 3 | // Licensed under the Apache License, Version 2.0 (the “License”);
 4 | // you may not use this file except in compliance with the License.
 5 | // See [CONTRIBUTORS.md] for the list of HomeKit ADK project authors.
 6 | 
 7 | #ifndef HAP_PLATFORM_SYSTEM_COMMAND_H
 8 | #define HAP_PLATFORM_SYSTEM_COMMAND_H
 9 | 
10 | #ifdef __cplusplus
11 | extern "C" {
12 | #endif
13 | 
14 | #include "HAPPlatform.h"
15 | 
16 | #if __has_feature(nullability)
17 | #pragma clang assume_nonnull begin
18 | #endif
19 | 
20 | /**
21 |  * Synchronously runs a system command and stores the result of STDOUT in the provided buffer.
22 |  *
23 |  * Passes an empty environment to HAPPlatformSystemCommandRunWithEnvironment.
24 |  *
25 |  * @param      command              Command to be run.
26 |  * @param[out] bytes                Buffer that will be filled with data.
27 |  * @param      maxBytes             Maximum number of bytes that may be filled into the buffer.
28 |  * @param[in,out] numBytes          Effective number of bytes written to the buffer.
29 |  *
30 |  * @return kHAPError_None           If successful.
31 |  * @return kHAPError_Unknown        If the process does not exit successfully.
32 |  * @return kHAPError_OutOfResources If the buffer was not big enough to store the result.
33 |  */
34 | HAP_RESULT_USE_CHECK
35 | HAPError HAPPlatformSystemCommandRun(
36 |         char* _Nullable const command[_Nonnull],
37 |         char* bytes,
38 |         size_t maxBytes,
39 |         size_t* numBytes);
40 | 
41 | /**
42 |  * Synchronously runs a system command with an environment and stores the result of STDOUT in the provided buffer.
43 |  *
44 |  * @param      command              Command to be run.
45 |  * @param      environment          Environment to be passed to the command.
46 |  * @param[out] bytes                Buffer that will be filled with data.
47 |  * @param      maxBytes             Maximum number of bytes that may be filled into the buffer.
48 |  * @param[in,out] numBytes          Effective number of bytes written to the buffer.
49 |  *
50 |  * @return kHAPError_None           If successful.
51 |  * @return kHAPError_Unknown        If the process does not exit successfully.
52 |  * @return kHAPError_OutOfResources If the buffer was not big enough to store the result.
53 |  */
54 | HAP_RESULT_USE_CHECK
55 | HAPError HAPPlatformSystemCommandRunWithEnvironment(
56 |         char* _Nullable const command[_Nonnull],
57 |         char* _Nullable const environment[_Nullable],
58 |         char* bytes,
59 |         size_t maxBytes,
60 |         size_t* numBytes);
61 | 
62 | #if __has_feature(nullability)
63 | #pragma clang assume_nonnull end
64 | #endif
65 | 
66 | #ifdef __cplusplus
67 | }
68 | #endif
69 | 
70 | #endif
71 | 


--------------------------------------------------------------------------------
/PAL/Raspi:
--------------------------------------------------------------------------------
1 | POSIX


--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
 1 | # HomeKit Accessory Development Kit (ADK)
 2 | 
 3 | The HomeKit ADK is used by silicon vendors and accessory manufacturers to build HomeKit compatible devices.
 4 | 
 5 | The HomeKit ADK implements key components of the HomeKit Accessory Protocol (HAP), which embodies the core principles Apple brings to smart home technology: security, privacy, and reliability.
 6 | 
 7 | The HomeKit Open Source ADK is an open-source version of the HomeKit Accessory Development Kit. It can be used by any developer to prototype non-commercial smart home accessories. For commercial accessories, accessory developers must continue to use the commercial version of the HomeKit ADK available through the MFi Program.
 8 | 
 9 | Go to the [Apple Developer Site](https://developer.apple.com/homekit/) if you like to learn more about developing HomeKit-enabled accessories and apps.
10 | 
11 | 
12 | ### Getting Started
13 | Please go through [Getting Started Guide](./Documentation/getting_started.md#prerequisites) before using HomeKit ADK.
14 | 
15 | ### Documentation
16 | ADK documentation is available as markdown files in [Documentation](./Documentation/) directory. However, a more user friendly
17 | `HTML` documentation can be generated from the markdown files by running the following command:
18 | 
19 | ```sh
20 | make docs
21 | ```
22 | 
23 | The command above will prompt to open the generated HTML webpage. After the command has finished, the webpage `./Documentation/api_docs/html/index.html` can also be opened in a browser.
24 | 


--------------------------------------------------------------------------------
/Tests/HAPAccessorySetupGetSetupHashTest.c:
--------------------------------------------------------------------------------
 1 | // Copyright (c) 2015-2019 The HomeKit ADK Contributors
 2 | //
 3 | // Licensed under the Apache License, Version 2.0 (the “License”);
 4 | // you may not use this file except in compliance with the License.
 5 | // See [CONTRIBUTORS.md] for the list of HomeKit ADK project authors.
 6 | 
 7 | #include "HAP+Internal.h"
 8 | 
 9 | const char* TestArgs[][4] = {
10 |     { "", "7OSX", "E1:91:1A:70:85:AA", "C9FE1BCF" },
11 |     { "", "7OSX", "C8:D8:58:C6:63:F5", "EF5D8E9B" },
12 | };
13 | 
14 | int Test(int argc, const char* argv[]) {
15 |     HAPError err;
16 | 
17 |     // Input arguments:
18 |     // argv[1] - Setup ID. Format XXXX.
19 |     // argv[2] - Device ID. Format XX:XX:XX:XX:XX:XX, uppercase.
20 |     // argv[3] - Expected setup hash (hex, uppercase).
21 |     HAPPrecondition(argc == 4);
22 | 
23 |     // Process arguments.
24 |     HAPPrecondition(HAPAccessorySetupIsValidSetupID(argv[1]));
25 |     const HAPSetupID* setupID = (const HAPSetupID*) argv[1];
26 |     HAPPrecondition(HAPStringGetNumBytes(argv[2]) == sizeof(HAPDeviceIDString) - 1);
27 |     const HAPDeviceIDString* deviceIDString = (const HAPDeviceIDString*) argv[2];
28 | 
29 |     // Derive setup hash.
30 |     HAPAccessorySetupSetupHash setupHash;
31 |     HAPAccessorySetupGetSetupHash(&setupHash, setupID, deviceIDString);
32 | 
33 |     // Compare with expectation.
34 |     HAPPrecondition(HAPStringGetNumBytes(argv[3]) == 2 * sizeof setupHash.bytes);
35 |     for (size_t i = 0; i < sizeof setupHash.bytes; i++) {
36 |         char setupHashHexString[3];
37 |         err = HAPStringWithFormat(setupHashHexString, sizeof setupHashHexString, "%02X", setupHash.bytes[i]);
38 |         HAPAssert(!err);
39 |         HAPAssert(HAPStringGetNumBytes(setupHashHexString) == sizeof setupHashHexString - 1);
40 |         HAPAssert(HAPRawBufferAreEqual(setupHashHexString, &argv[3][2 * i], 2));
41 |     }
42 | 
43 |     return 0;
44 | }
45 | 
46 | int main(int argc HAP_UNUSED, char* argv[] HAP_UNUSED) {
47 |     for (size_t i = 0; i < HAPArrayCount(TestArgs); ++i) {
48 |         HAPAssert(Test(4, TestArgs[i]) == 0);
49 |     }
50 |     return 0;
51 | }
52 | 


--------------------------------------------------------------------------------
/Tests/HAPAccessorySetupTest.c:
--------------------------------------------------------------------------------
 1 | // Copyright (c) 2015-2019 The HomeKit ADK Contributors
 2 | //
 3 | // Licensed under the Apache License, Version 2.0 (the “License”);
 4 | // you may not use this file except in compliance with the License.
 5 | // See [CONTRIBUTORS.md] for the list of HomeKit ADK project authors.
 6 | 
 7 | #include "HAP+Internal.h"
 8 | 
 9 | int main() {
10 |     // See HomeKit Accessory Protocol Specification R14
11 |     // Section 4.2.1.2 Invalid Setup Codes
12 |     HAPAssert(!HAPAccessorySetupIsValidSetupCode("000-00-000"));
13 |     HAPAssert(!HAPAccessorySetupIsValidSetupCode("111-11-111"));
14 |     HAPAssert(!HAPAccessorySetupIsValidSetupCode("222-22-222"));
15 |     HAPAssert(!HAPAccessorySetupIsValidSetupCode("333-33-333"));
16 |     HAPAssert(!HAPAccessorySetupIsValidSetupCode("444-44-444"));
17 |     HAPAssert(!HAPAccessorySetupIsValidSetupCode("555-55-555"));
18 |     HAPAssert(!HAPAccessorySetupIsValidSetupCode("666-66-666"));
19 |     HAPAssert(!HAPAccessorySetupIsValidSetupCode("777-77-777"));
20 |     HAPAssert(!HAPAccessorySetupIsValidSetupCode("888-88-888"));
21 |     HAPAssert(!HAPAccessorySetupIsValidSetupCode("999-99-999"));
22 |     HAPAssert(!HAPAccessorySetupIsValidSetupCode("123-45-678"));
23 |     HAPAssert(!HAPAccessorySetupIsValidSetupCode("876-54-321"));
24 | }
25 | 


--------------------------------------------------------------------------------
/Tests/HAPIPAccessoryProtocolReadPrepareWriteRequestTest.c:
--------------------------------------------------------------------------------
 1 | // Copyright (c) 2015-2019 The HomeKit ADK Contributors
 2 | //
 3 | // Licensed under the Apache License, Version 2.0 (the “License”);
 4 | // you may not use this file except in compliance with the License.
 5 | // See [CONTRIBUTORS.md] for the list of HomeKit ADK project authors.
 6 | 
 7 | #include "HAP+Internal.h"
 8 | 
 9 | int main() {
10 |     HAPError err;
11 | 
12 |     {
13 |         // See HomeKit Accessory Protocol Specification R14
14 |         // Section 6.7.2.4 Timed Write Procedures
15 |         const char request[] =
16 |                 "{\n"
17 |                 "    \"ttl\" : 2500,\n"
18 |                 "    \"pid\": 11122333\n"
19 |                 "    \n"
20 |                 "}\n";
21 |         uint64_t ttl;
22 |         uint64_t pid;
23 |         err = HAPIPAccessoryProtocolGetCharacteristicWritePreparation(request, sizeof request - 1, &ttl, &pid);
24 |         HAPAssert(!err);
25 |         HAPAssert(ttl == 2500);
26 |         HAPAssert(pid == 11122333);
27 |     }
28 |     {
29 |         // Detect duplicate TTL.
30 |         const char request[] =
31 |                 "{\n"
32 |                 "    \"ttl\" : 2500,\n"
33 |                 "    \"pid\": 11122333,\n"
34 |                 "    \n"
35 |                 "    \"ttl\" : 2500\n"
36 |                 "}\n";
37 |         uint64_t ttl;
38 |         uint64_t pid;
39 |         err = HAPIPAccessoryProtocolGetCharacteristicWritePreparation(request, sizeof request - 1, &ttl, &pid);
40 |         HAPAssert(err == kHAPError_InvalidData);
41 |     }
42 |     {
43 |         // Detect duplicate PID.
44 |         const char request[] =
45 |                 "{\n"
46 |                 "    \"ttl\" : 2500,\n"
47 |                 "    \"pid\": 11122333,\n"
48 |                 "    \n"
49 |                 "    \"pid\": 11122333\n"
50 |                 "}\n";
51 |         uint64_t ttl;
52 |         uint64_t pid;
53 |         err = HAPIPAccessoryProtocolGetCharacteristicWritePreparation(request, sizeof request - 1, &ttl, &pid);
54 |         HAPAssert(err == kHAPError_InvalidData);
55 |     }
56 | 
57 |     return 0;
58 | }
59 | 


--------------------------------------------------------------------------------
/Tests/HAPImportTest.c:
--------------------------------------------------------------------------------
 1 | // Copyright (c) 2015-2019 The HomeKit ADK Contributors
 2 | //
 3 | // Licensed under the Apache License, Version 2.0 (the “License”);
 4 | // you may not use this file except in compliance with the License.
 5 | // See [CONTRIBUTORS.md] for the list of HomeKit ADK project authors.
 6 | 
 7 | #include "HAP+Internal.h"
 8 | #include "HAPPlatform+Init.h"
 9 | 
10 | typedef struct {
11 |     HAPControllerPairingIdentifier pairingIdentifier;
12 |     HAPControllerPublicKey publicKey;
13 |     bool isAdmin;
14 | 
15 |     bool foundInExport;
16 | } ControllerPairing;
17 | 
18 | int main() {
19 |     HAPError err;
20 |     HAPPlatformCreate();
21 | 
22 |     // Import Device ID.
23 |     HAPAccessoryServerDeviceID expectedDeviceID;
24 |     HAPPlatformRandomNumberFill(expectedDeviceID.bytes, sizeof expectedDeviceID.bytes);
25 |     err = HAPLegacyImportDeviceID(platform.keyValueStore, &expectedDeviceID);
26 |     HAPAssert(!err);
27 | 
28 |     // Import long-term secret key.
29 |     HAPAccessoryServerLongTermSecretKey expectedLongTermSecretKey;
30 |     HAPPlatformRandomNumberFill(expectedLongTermSecretKey.bytes, sizeof expectedLongTermSecretKey.bytes);
31 |     err = HAPLegacyImportLongTermSecretKey(platform.keyValueStore, &expectedLongTermSecretKey);
32 |     HAPAssert(!err);
33 | 
34 |     // Import pairings.
35 |     ControllerPairing pairings[kHAPPairingStorage_MinElements];
36 |     HAPRawBufferZero(pairings, sizeof pairings);
37 |     for (HAPPlatformKeyValueStoreKey i = 0; i < HAPArrayCount(pairings); i++) {
38 |         pairings[i].pairingIdentifier.numBytes = i % sizeof pairings[i].pairingIdentifier.bytes;
39 |         HAPPlatformRandomNumberFill(pairings[i].pairingIdentifier.bytes, pairings[i].pairingIdentifier.numBytes);
40 |         HAPPlatformRandomNumberFill(pairings[i].publicKey.bytes, sizeof pairings[i].publicKey.bytes);
41 |         pairings[i].isAdmin = i % 2 != 0;
42 |         err = HAPLegacyImportControllerPairing(
43 |                 platform.keyValueStore, i, &pairings[i].pairingIdentifier, &pairings[i].publicKey, pairings[i].isAdmin);
44 |         HAPAssert(!err);
45 |     }
46 | 
47 |     // Remove pairings.
48 |     err = HAPRemoveAllPairings(platform.keyValueStore);
49 |     HAPAssert(!err);
50 | 
51 |     // Restore factory settings.
52 |     err = HAPRestoreFactorySettings(platform.keyValueStore);
53 |     HAPAssert(!err);
54 | 
55 |     return 0;
56 | }
57 | 


--------------------------------------------------------------------------------
/Tests/HAPPlatformSystemCommandTest.c:
--------------------------------------------------------------------------------
 1 | // Copyright (c) 2015-2019 The HomeKit ADK Contributors
 2 | //
 3 | // Licensed under the Apache License, Version 2.0 (the “License”);
 4 | // you may not use this file except in compliance with the License.
 5 | // See [CONTRIBUTORS.md] for the list of HomeKit ADK project authors.
 6 | 
 7 | // A simple test to verify the behavior of HAPPlatformSystemCommand.
 8 | //
 9 | // This test requires the POSIX commands echo, true, false.
10 | 
11 | #ifndef ECHO_COMMAND
12 | #define ECHO_COMMAND "/bin/echo"
13 | #endif
14 | 
15 | #ifndef TRUE_COMMAND
16 | #define TRUE_COMMAND "/usr/bin/env", "true"
17 | #endif
18 | #ifndef FALSE_COMMAND
19 | #define FALSE_COMMAND "/usr/bin/env", "false"
20 | #endif
21 | 
22 | #include <string.h>
23 | 
24 | #include "HAPPlatformSystemCommand.h"
25 | 
26 | static const HAPLogObject logObject = { .subsystem = kHAPPlatform_LogSubsystem ".Test", .category = "SystemCommand" };
27 | 
28 | static void RunAndCheck(char* const cmd[], const char* _Nullable expectedResult, HAPError expectedError) {
29 |     HAPPrecondition(cmd);
30 | 
31 |     HAPLogInfo(&logObject, "Testing: %s %s", cmd[0], cmd[1] ? cmd[1] : "");
32 |     HAPError err;
33 |     char result[6];
34 | 
35 |     HAPRawBufferZero(result, sizeof(result));
36 |     size_t written;
37 |     err = HAPPlatformSystemCommandRun(cmd, result, sizeof(result), &written);
38 |     HAPAssert(err == expectedError);
39 |     if (expectedResult) {
40 |         HAPAssert(strcmp(expectedResult, result));
41 |     }
42 | }
43 | 
44 | int main() {
45 |     {
46 |         char* const cmd[] = { ECHO_COMMAND, "true", NULL };
47 |         RunAndCheck(cmd, "true", kHAPError_None);
48 |     }
49 |     {
50 |         char* const cmd[] = { ECHO_COMMAND, "false", NULL };
51 |         RunAndCheck(cmd, "false", kHAPError_None);
52 |     }
53 |     {
54 |         char* const cmd[] = { TRUE_COMMAND, NULL };
55 |         RunAndCheck(cmd, NULL, kHAPError_None);
56 |     }
57 |     {
58 |         char* const cmd[] = { FALSE_COMMAND, NULL };
59 |         RunAndCheck(cmd, NULL, kHAPError_Unknown);
60 |     }
61 |     {
62 |         char* const cmd[] = { ECHO_COMMAND, "Extra Long string which does not fit into buffer.", NULL };
63 |         RunAndCheck(cmd, NULL, kHAPError_OutOfResources);
64 |     }
65 | }
66 | 


--------------------------------------------------------------------------------
/Tests/Harness/TemplateDB.h:
--------------------------------------------------------------------------------
 1 | // Copyright (c) 2015-2019 The HomeKit ADK Contributors
 2 | //
 3 | // Licensed under the Apache License, Version 2.0 (the “License”);
 4 | // you may not use this file except in compliance with the License.
 5 | // See [CONTRIBUTORS.md] for the list of HomeKit ADK project authors.
 6 | 
 7 | #ifndef TEMPLATE_DB_H
 8 | #define TEMPLATE_DB_H
 9 | 
10 | #ifdef __cplusplus
11 | extern "C" {
12 | #endif
13 | 
14 | #include "HAP+Internal.h"
15 | 
16 | #if __has_feature(nullability)
17 | #pragma clang assume_nonnull begin
18 | #endif
19 | 
20 | #define kAttributeCount ((size_t)(17))
21 | 
22 | /**
23 |  * HomeKit Accessory Information service
24 |  */
25 | extern const HAPService accessoryInformationService;
26 | 
27 | /**
28 |  * Characteristics to expose accessory information and configuration (associated with accessory information service)
29 |  */
30 | extern const HAPBoolCharacteristic accessoryInformationIdentifyCharacteristic;
31 | extern const HAPStringCharacteristic accessoryInformationManufacturerCharacteristic;
32 | extern const HAPStringCharacteristic accessoryInformationModelCharacteristic;
33 | extern const HAPStringCharacteristic accessoryInformationNameCharacteristic;
34 | extern const HAPStringCharacteristic accessoryInformationSerialNumberCharacteristic;
35 | extern const HAPStringCharacteristic accessoryInformationFirmwareRevisionCharacteristic;
36 | extern const HAPStringCharacteristic accessoryInformationHardwareRevisionCharacteristic;
37 | extern const HAPStringCharacteristic accessoryInformationADKVersionCharacteristic;
38 | 
39 | /**
40 |  * HAP Protocol Information Service
41 |  */
42 | extern const HAPService hapProtocolInformationService;
43 | 
44 | /**
45 |  * Pairing Service
46 |  */
47 | extern const HAPService pairingService;
48 | 
49 | #if __has_feature(nullability)
50 | #pragma clang assume_nonnull end
51 | #endif
52 | 
53 | #ifdef __cplusplus
54 | }
55 | #endif
56 | 
57 | #endif
58 | 


--------------------------------------------------------------------------------
/Tools/linters/git-hooks-pre-commit:
--------------------------------------------------------------------------------
 1 | #!/bin/sh
 2 | 
 3 | # Redirect output to stderr.
 4 | exec 1>&2
 5 | 
 6 | REPO_ROOT=`git rev-parse --show-toplevel`
 7 | 
 8 | echo "==> Running lint on changed files..."
 9 | exec git diff-index --cached --name-only HEAD \
10 |   | xargs printf -- '-f\0%s\0' \
11 |   | xargs -0 -- ${REPO_ROOT}/Tools/linters/lint.sh -F
12 | echo
13 | 


--------------------------------------------------------------------------------
/Tools/raspi_docker_import.sh:
--------------------------------------------------------------------------------
  1 | #!/bin/bash -e
  2 | 
  3 | set -eu -o pipefail
  4 | 
  5 | usage()
  6 | {
  7 |   echo "This script is used to import a RaspberryPi rootfs from an active device"
  8 |   echo "into docker."
  9 |   echo ""
 10 |   echo "Usage: $0 -n HOSTNAME [-i SSH_IDENTITY | -p SSH_PASSWORD]"
 11 |   echo ""
 12 |   echo "OPTIONS:"
 13 |   echo "-n  - [required] raspberry pi host name"
 14 |   echo "-p  - [optional] raspberry pi password"
 15 |   echo "-i  - [optional] ssh identity file"
 16 |   echo ""
 17 |   exit 1
 18 | }
 19 | 
 20 | 
 21 | HOSTNAME=
 22 | PASSWORD=
 23 | IDENTITY_FILE=
 24 | while getopts "hn:i:p:" opt; do
 25 |   case ${opt} in
 26 |     n ) HOSTNAME=$OPTARG
 27 |       ;;
 28 |     p ) PASSWORD=$OPTARG
 29 |       ;;
 30 |     i ) IDENTITY_FILE=$OPTARG
 31 |       ;;
 32 |     h ) usage
 33 |       ;;
 34 |     \? ) usage
 35 |       ;;
 36 |   esac
 37 | done
 38 | 
 39 | if [[ -z "$HOSTNAME" ]]; then
 40 |   usage
 41 | fi
 42 | 
 43 | if [[ -z "$PASSWORD" && -z "$IDENTITY_FILE" ]]; then
 44 |   usage
 45 | fi
 46 | 
 47 | if [[ -n "$PASSWORD" ]]; then
 48 |   SSH_OPTS=(-o 'StrictHostKeyChecking=no' -o 'UserKnownHostsFile=/dev/null' -o 'ConnectTimeout=30' -o 'ServerAliveInterval=10000')
 49 | else
 50 |   SSH_OPTS=(-i "$IDENTITY_FILE" -o 'StrictHostKeyChecking=no' -o 'UserKnownHostsFile=/dev/null' -o 'ConnectTimeout=30' -o 'ServerAliveInterval=10000')
 51 | fi
 52 | 
 53 | 
 54 | # create rootfs tarball
 55 | expect <<EOF
 56 |   set timeout -1
 57 |   spawn ssh ${SSH_OPTS[@]} pi@${HOSTNAME}.local
 58 |   expect {
 59 |     "password: " {
 60 |       send "${PASSWORD}\n"
 61 |       exp_continue
 62 |     }
 63 |     "pi@${HOSTNAME}:"
 64 |   }
 65 |   send "sudo su\n"
 66 |   expect "root@${HOSTNAME}:"
 67 |   send "mkdir /temp\n"
 68 |   expect "root@${HOSTNAME}:"
 69 |   send "tar --numeric-owner --exclude=/proc --exclude=/sys --exclude=/temp -cf /temp/raspi-base.tar / \n"
 70 |   expect "root@${HOSTNAME}:"
 71 |   send "exit\n"
 72 |   expect "pi@${HOSTNAME}:"
 73 |   send "exit\n"
 74 |   expect eof
 75 | EOF
 76 | 
 77 | mkdir -p .tmp
 78 | 
 79 | # copy tar file to local disk
 80 | expect <<EOF
 81 |   set timeout -1
 82 |   spawn scp ${SSH_OPTS[@]} pi@${HOSTNAME}.local:/temp/raspi-base.tar .tmp/
 83 |   expect {
 84 |     "password: " {
 85 |       send "${PASSWORD}\n"
 86 |       exp_continue
 87 |     }
 88 |     eof
 89 |   }
 90 |   lassign [wait] pid spawnID osError value
 91 |   exit \$value
 92 | EOF
 93 | 
 94 | set -x
 95 | # import tar file to docker
 96 | docker import .tmp/raspi-base.tar dev-test/raspiadk-base
 97 | rm -rf .tmp
 98 | set +x
 99 | 
100 | expect <<EOF
101 |   set timeout -1
102 |   spawn ssh ${SSH_OPTS[@]}  pi@${HOSTNAME}.local
103 |   expect {
104 |     "password: " {
105 |       send "${PASSWORD}\n"
106 |       exp_continue
107 |     }
108 |     "pi@${HOSTNAME}:"
109 |   }
110 |   send "sudo rm -rf /temp \n"
111 |   expect "pi@${HOSTNAME}:"
112 |   send "exit\n"
113 |   expect eof
114 | EOF
115 | 
116 | 


--------------------------------------------------------------------------------