├── .gitignore ├── .gitlab-ci.yml ├── .gitmodules ├── MFI_README.md ├── README.md ├── components ├── button │ ├── CMakeLists.txt │ ├── Kconfig │ ├── button │ │ ├── button.c │ │ ├── button_obj.cpp │ │ ├── component.mk │ │ └── include │ │ │ └── iot_button.h │ └── component.mk └── homekit │ ├── esp_hap_apple_profiles │ ├── CMakeLists.txt │ ├── component.mk │ ├── include │ │ ├── hap_apple_chars.h │ │ └── hap_apple_servs.h │ └── src │ │ ├── hap_apple_chars.c │ │ └── hap_apple_servs.c │ ├── esp_hap_core │ ├── CMakeLists.txt │ ├── Kconfig │ ├── component.mk │ ├── idf_component.yml │ ├── include │ │ ├── hap.h │ │ ├── hap_bct.h │ │ └── hap_wac.h │ └── src │ │ ├── byte_convert.c │ │ ├── esp_hap_acc.c │ │ ├── esp_hap_bct.c │ │ ├── esp_hap_char.c │ │ ├── esp_hap_controllers.c │ │ ├── esp_hap_database.c │ │ ├── esp_hap_ip_services.c │ │ ├── esp_hap_keystore.c │ │ ├── esp_hap_main.c │ │ ├── esp_hap_mdns.c │ │ ├── esp_hap_network_io.c │ │ ├── esp_hap_pair_common.c │ │ ├── esp_hap_pair_setup.c │ │ ├── esp_hap_pair_verify.c │ │ ├── esp_hap_pairings.c │ │ ├── esp_hap_serv.c │ │ ├── esp_hap_setup_payload.c │ │ ├── esp_hap_wifi.c │ │ ├── esp_mfi_debug.c │ │ ├── esp_mfi_dummy.c │ │ ├── hexbin.c │ │ ├── hexdump.c │ │ └── priv_includes │ │ ├── base36.h │ │ ├── byte_convert.h │ │ ├── esp_hap_acc.h │ │ ├── esp_hap_bct_priv.h │ │ ├── esp_hap_char.h │ │ ├── esp_hap_controllers.h │ │ ├── esp_hap_database.h │ │ ├── esp_hap_ip_services.h │ │ ├── esp_hap_keystore.h │ │ ├── esp_hap_main.h │ │ ├── esp_hap_mdns.h │ │ ├── esp_hap_network_io.h │ │ ├── esp_hap_pair_common.h │ │ ├── esp_hap_pair_setup.h │ │ ├── esp_hap_pair_verify.h │ │ ├── esp_hap_pairings.h │ │ ├── esp_hap_secure_message.h │ │ ├── esp_hap_serv.h │ │ ├── esp_hap_wac.h │ │ ├── esp_hap_wifi.h │ │ ├── esp_mfi_debug.h │ │ ├── hexbin.h │ │ └── hexdump.h │ ├── esp_hap_extras │ ├── CMakeLists.txt │ ├── component.mk │ ├── include │ │ ├── hap_bct_http_handlers.h │ │ └── hap_fw_upgrade.h │ └── src │ │ ├── hap_bct_http_handlers.c │ │ └── hap_fw_upgrade.c │ ├── esp_hap_platform │ ├── CMakeLists.txt │ ├── Kconfig │ ├── component.mk │ ├── include │ │ ├── esp_mfi_aes.h │ │ ├── esp_mfi_base64.h │ │ ├── esp_mfi_i2c.h │ │ ├── esp_mfi_rand.h │ │ ├── esp_mfi_sha.h │ │ ├── hap_platform_httpd.h │ │ ├── hap_platform_keystore.h │ │ ├── hap_platform_memory.h │ │ └── hap_platform_os.h │ └── src │ │ ├── esp_mfi_aes.c │ │ ├── esp_mfi_base64.c │ │ ├── esp_mfi_i2c.c │ │ ├── esp_mfi_rand.c │ │ ├── esp_mfi_sha.c │ │ ├── hap_platform_httpd.c │ │ ├── hap_platform_keystore.c │ │ ├── hap_platform_memory.c │ │ └── hap_platform_os.c │ ├── hkdf-sha │ ├── CMakeLists.txt │ ├── component.mk │ ├── include │ │ └── hkdf-sha.h │ └── upstream │ │ ├── .gitignore │ │ ├── Makefile │ │ ├── README.md │ │ ├── hkdf.c │ │ ├── hmac.c │ │ ├── rfc6234.txt │ │ ├── sha-private.h │ │ ├── sha.h │ │ ├── sha1.c │ │ ├── sha224-256.c │ │ ├── sha384-512.c │ │ ├── shatest.c │ │ └── usha.c │ └── mu_srp │ ├── CMakeLists.txt │ ├── LICENSE │ ├── component.mk │ ├── mu_bignum.h │ ├── mu_srp.c │ └── mu_srp.h ├── examples ├── bridge │ ├── CMakeLists.txt │ ├── Makefile │ ├── main │ │ ├── CMakeLists.txt │ │ ├── Kconfig.projbuild │ │ ├── app_main.c │ │ └── component.mk │ ├── partitions_hap.csv │ ├── sdkconfig.defaults │ └── sdkconfig.defaults.esp32c6 ├── common │ ├── app_hap_setup_payload │ │ ├── CMakeLists.txt │ │ ├── app_hap_setup_payload.c │ │ ├── app_hap_setup_payload.h │ │ └── component.mk │ ├── app_wifi │ │ ├── CMakeLists.txt │ │ ├── Kconfig.projbuild │ │ ├── app_wifi.c │ │ ├── app_wifi.h │ │ └── component.mk │ └── qrcode │ │ ├── CMakeLists.txt │ │ ├── component.mk │ │ ├── include │ │ └── qrcode.h │ │ └── src │ │ ├── qrcode.c │ │ ├── qrcodegen.c │ │ └── qrcodegen.h ├── data_tlv8 │ ├── CMakeLists.txt │ ├── Makefile │ ├── main │ │ ├── CMakeLists.txt │ │ ├── Kconfig.projbuild │ │ ├── app_main.c │ │ └── component.mk │ ├── partitions_hap.csv │ ├── sdkconfig.defaults │ └── sdkconfig.defaults.esp32c6 ├── emulator │ ├── CMakeLists.txt │ ├── Makefile │ ├── README.md │ ├── emulator_factory.bin │ ├── main │ │ ├── CMakeLists.txt │ │ ├── Kconfig.projbuild │ │ ├── app_main.c │ │ ├── cmd_register.c │ │ ├── component.mk │ │ ├── console_init.c │ │ ├── console_settings.c │ │ ├── console_settings.h │ │ ├── emulator.c │ │ └── emulator.h │ ├── partitions_hap.csv │ ├── sdkconfig.defaults │ └── sdkconfig.defaults.esp32c6 ├── fan │ ├── CMakeLists.txt │ ├── Makefile │ ├── fan_factory.bin │ ├── main │ │ ├── CMakeLists.txt │ │ ├── Kconfig.projbuild │ │ ├── app_main.c │ │ └── component.mk │ ├── partitions_hap.csv │ ├── sdkconfig.defaults │ └── sdkconfig.defaults.esp32c6 ├── lightbulb │ ├── CMakeLists.txt │ ├── Makefile │ ├── main │ │ ├── CMakeLists.txt │ │ ├── Kconfig.projbuild │ │ ├── app_main.c │ │ ├── component.mk │ │ ├── lightbulb.c │ │ └── lightbulb.h │ ├── partitions_hap.csv │ ├── sdkconfig.defaults │ └── sdkconfig.defaults.esp32c6 └── smart_outlet │ ├── CMakeLists.txt │ ├── Makefile │ ├── main │ ├── CMakeLists.txt │ ├── Kconfig.projbuild │ ├── app_main.c │ └── component.mk │ ├── partitions_hap.csv │ ├── sdkconfig.defaults │ └── sdkconfig.defaults.esp32c6 └── tools ├── factory_nvs_gen ├── README.md └── factory_nvs_gen.py ├── idf_tools ├── mass_mfg │ └── mfg_gen.py └── nvs_partition_generator │ ├── README.rst │ └── nvs_partition_gen.py ├── mfg_homekit ├── README.md ├── hk_mfg_gen.py └── setup_info_gen.py ├── setup_payload_gen ├── README.md └── setup_payload_gen.py └── srp └── srp_tool.py /.gitignore: -------------------------------------------------------------------------------- 1 | .config 2 | *.o 3 | *.pyc 4 | 5 | 6 | # Example project files 7 | examples/**/sdkconfig 8 | examples/**/sdkconfig.old 9 | examples/**/build 10 | 11 | # emacs 12 | .dir-locals.el 13 | 14 | # eclipse setting 15 | .settings 16 | 17 | # vscode 18 | .vscode 19 | 20 | # Doc build artifacts 21 | docs/*/_build/ 22 | docs/*/doxygen-warning-log.txt 23 | docs/*/sphinx-warning-log.txt 24 | docs/*/sphinx-warning-log-sanitized.txt 25 | docs/*/xml/ 26 | docs/*/xml_in/ 27 | docs/*/man/ 28 | docs/doxygen_sqlite3.db 29 | 30 | # MacOS directory files 31 | .DS_Store 32 | 33 | # Tools 34 | tools/factory_nvs_gen/*.bin 35 | tools/factory_nvs_gen/*.csv 36 | 37 | # Patch files 38 | *.patch 39 | 40 | #CTags 41 | tags 42 | 43 | # Managed components 44 | examples/**/managed_components/* 45 | 46 | # Dependency lock files 47 | dependencies.lock -------------------------------------------------------------------------------- /.gitlab-ci.yml: -------------------------------------------------------------------------------- 1 | stages: 2 | - build 3 | 4 | variables: 5 | GIT_SUBMODULE_STRATEGY: recursive 6 | 7 | .build_template: 8 | stage: build 9 | image: espressif/idf:latest 10 | tags: 11 | - build 12 | 13 | variables: 14 | EXAMPLES: "bridge data_tlv8 emulator fan lightbulb smart_outlet" 15 | EXAMPLE_TARGETS: "esp32 esp32c3 esp32s3" 16 | 17 | artifacts: 18 | paths: 19 | - examples/fan/build/*.bin 20 | - examples/fan/build/*.elf 21 | - examples/fan/build/*.map 22 | - examples/fan/build/bootloader/*.bin 23 | artifacts: 24 | paths: 25 | - $CI_PROJECT_DIR/esp-homekit-sdk-bins-${CI_JOB_ID}.zip 26 | expire_in: 3 mos 27 | 28 | before_script: 29 | - mkdir -p ~/.ssh 30 | - chmod 700 ~/.ssh 31 | - echo -n $GITLAB_KEY >> ~/.ssh/id_rsa_base64 32 | - base64 --decode --ignore-garbage ~/.ssh/id_rsa_base64 > ~/.ssh/id_rsa 33 | - chmod 600 ~/.ssh/id_rsa 34 | - echo -e "Host gitlab.espressif.cn\n\tStrictHostKeyChecking no\n" >> ~/.ssh/config 35 | 36 | script: 37 | - for EXAMPLE in $EXAMPLES; do 38 | - cd $CI_PROJECT_DIR/examples/$EXAMPLE 39 | - echo Building $EXAMPLE 40 | - for TARGET in $EXAMPLE_TARGETS; do 41 | - echo Building for $TARGET 42 | - idf.py set-target $TARGET 43 | - idf.py build 44 | - mkdir -p $CI_PROJECT_DIR/esp-homekit-sdk-bins-${CI_JOB_ID}/$EXAMPLE/$TARGET/ 45 | - cp $CI_PROJECT_DIR/examples/$EXAMPLE/build/*.bin $CI_PROJECT_DIR/esp-homekit-sdk-bins-${CI_JOB_ID}/$EXAMPLE/$TARGET/ 46 | - done 47 | - echo Build Complete for $EXAMPLE 48 | - done 49 | # Generating zip file for binaries generated 50 | - cd $CI_PROJECT_DIR 51 | - echo Generating zip file for binaries generated 52 | - tar -zcvf esp-homekit-sdk-bins-${CI_JOB_ID}.zip esp-homekit-sdk-bins-${CI_JOB_ID}/ 53 | 54 | build_idf_v4.4: 55 | extends: .build_template 56 | image: espressif/idf:release-v4.4 57 | variables: 58 | EXAMPLE_TARGETS: "esp32 esp32s2 esp32c3 esp32s3" 59 | 60 | build_idf_v5.0: 61 | extends: .build_template 62 | image: espressif/idf:release-v5.0 63 | variables: 64 | EXAMPLE_TARGETS: "esp32 esp32s2 esp32c3 esp32s3" 65 | 66 | build_idf_v5.1: 67 | extends: .build_template 68 | image: espressif/idf:release-v5.1 69 | variables: 70 | EXAMPLE_TARGETS: "esp32 esp32s2 esp32c3 esp32s3 esp32c2 esp32c6" 71 | 72 | build_idf_v5.2: 73 | extends: .build_template 74 | image: espressif/idf:release-v5.2 75 | 76 | build_idf_v5.3: 77 | extends: .build_template 78 | image: espressif/idf:release-v5.3 79 | -------------------------------------------------------------------------------- /.gitmodules: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/espressif/esp-homekit-sdk/bfbcd6e749635d97645380b9d7b32274553fe017/.gitmodules -------------------------------------------------------------------------------- /MFI_README.md: -------------------------------------------------------------------------------- 1 | # ESP HomeKit SDK (MFi) 2 | 3 | The Open source variant of esp-homekit-sdk cannot be used for commercial products. If you want to build commercial products and have an MFi License already, please get in touch with us by visiting [here](https://www.espressif.com/en/products/sdks/esp-homekit-sdk). 4 | -------------------------------------------------------------------------------- /components/button/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | idf_component_register(SRCS "button/button.c" "button/button_obj.cpp" 2 | INCLUDE_DIRS "button/include" 3 | REQUIRES "driver") 4 | -------------------------------------------------------------------------------- /components/button/Kconfig: -------------------------------------------------------------------------------- 1 | menu "Button" 2 | config IO_GLITCH_FILTER_TIME_MS 3 | int "IO glitch filter timer ms (10~100)" 4 | range 10 100 5 | default 50 6 | endmenu -------------------------------------------------------------------------------- /components/button/button/button_obj.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * ESPRESSIF MIT License 3 | * 4 | * Copyright (c) 2017 5 | * 6 | * Permission is hereby granted for use on ESPRESSIF SYSTEMS products only, in which case, 7 | * it is free of charge, to any person obtaining a copy of this software and associated 8 | * documentation files (the "Software"), to deal in the Software without restriction, including 9 | * without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, 10 | * and/or sell copies of the Software, and to permit persons to whom the Software is furnished 11 | * to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all copies or 14 | * 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, FITNESS 18 | * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 19 | * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 20 | * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 21 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 22 | * 23 | */ 24 | 25 | #include 26 | #include 27 | #include 28 | #include 29 | 30 | CButton::CButton(gpio_num_t gpio_num, button_active_t active_level) 31 | { 32 | m_btn_handle = iot_button_create(gpio_num, active_level); 33 | } 34 | 35 | CButton::~CButton() 36 | { 37 | iot_button_delete(m_btn_handle); 38 | m_btn_handle = NULL; 39 | } 40 | 41 | esp_err_t CButton::set_evt_cb(button_cb_type_t type, button_cb cb, void* arg) 42 | { 43 | return iot_button_set_evt_cb(m_btn_handle, type, cb, arg); 44 | } 45 | 46 | esp_err_t CButton::set_serial_cb(button_cb cb, void* arg, TickType_t interval_tick, uint32_t start_after_sec) 47 | { 48 | return iot_button_set_serial_cb(m_btn_handle, start_after_sec, interval_tick, cb, arg); 49 | } 50 | 51 | esp_err_t CButton::add_on_press_cb(uint32_t press_sec, button_cb cb, void* arg) 52 | { 53 | return iot_button_add_on_press_cb(m_btn_handle, press_sec, cb, arg); 54 | } 55 | 56 | esp_err_t CButton::add_on_release_cb(uint32_t press_sec, button_cb cb, void* arg) 57 | { 58 | return iot_button_add_on_release_cb(m_btn_handle, press_sec, cb, arg); 59 | } 60 | 61 | esp_err_t CButton::rm_cb(button_cb_type_t type) 62 | { 63 | return iot_button_rm_cb(m_btn_handle, type); 64 | } 65 | -------------------------------------------------------------------------------- /components/button/button/component.mk: -------------------------------------------------------------------------------- 1 | # 2 | # "main" pseudo-component makefile. 3 | # 4 | # (Uses default behaviour of compiling all source files in directory, adding 'include' to include path.) 5 | -------------------------------------------------------------------------------- /components/button/component.mk: -------------------------------------------------------------------------------- 1 | COMPONENT_ADD_INCLUDEDIRS := ./button/include 2 | COMPONENT_SRCDIRS := ./button 3 | -------------------------------------------------------------------------------- /components/homekit/esp_hap_apple_profiles/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | set(COMPONENT_ADD_INCLUDEDIRS include) 2 | 3 | # Edit following two lines to set component requirements (see docs) 4 | set(COMPONENT_REQUIRES esp_hap_core) 5 | set(COMPONENT_PRIV_REQUIRES ) 6 | 7 | set(COMPONENT_SRCS src/hap_apple_chars.c src/hap_apple_servs.c) 8 | 9 | register_component() 10 | component_compile_options(-Wno-unused-function) 11 | -------------------------------------------------------------------------------- /components/homekit/esp_hap_apple_profiles/component.mk: -------------------------------------------------------------------------------- 1 | # 2 | # Component Makefile 3 | # 4 | CFLAGS += -Wno-unused-function 5 | COMPONENT_SRCDIRS := src 6 | COMPONENT_ADD_INCLUDEDIRS := include 7 | -------------------------------------------------------------------------------- /components/homekit/esp_hap_core/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | set(HAP_SDK_VER "4.0") 2 | execute_process ( 3 | COMMAND bash -c "git log --pretty=format:\"%h\" -1" 4 | OUTPUT_VARIABLE GIT_COMMIT 5 | WORKING_DIRECTORY ${COMPONENT_DIR} 6 | ) 7 | #execute_process(COMMAND "git log --pretty=format:\"%h\"" -1 OUTPUT_VARIABLE GIT_COMMIT) 8 | set(MFI_VER ${HAP_SDK_VER}-${GIT_COMMIT}) 9 | message(STATUS ${MFI_VER}) 10 | 11 | 12 | # CORE 13 | set(srcs src/byte_convert.c 14 | src/esp_hap_acc.c 15 | src/esp_hap_bct.c 16 | src/esp_hap_char.c 17 | src/esp_hap_controllers.c 18 | src/esp_hap_database.c 19 | src/esp_hap_ip_services.c 20 | src/esp_hap_keystore.c 21 | src/esp_hap_main.c 22 | src/esp_hap_mdns.c 23 | src/esp_hap_network_io.c 24 | src/esp_hap_pair_common.c 25 | src/esp_hap_pair_setup.c 26 | src/esp_hap_pair_verify.c 27 | src/esp_hap_pairings.c 28 | src/esp_hap_serv.c 29 | src/esp_hap_wifi.c 30 | src/esp_hap_setup_payload.c 31 | src/hexbin.c 32 | src/hexdump.c 33 | src/esp_mfi_debug.c) 34 | 35 | set(priv_includes src/priv_includes) 36 | 37 | if(CONFIG_HAP_MFI_ENABLE) 38 | list(APPEND srcs src/mfi/esp_mfi_auth.c src/mfi/esp_mfi_coprocessor.c src/mfi/esp_mfi_element.c src/mfi/esp_mfi_sap.c src/mfi/esp_mfi_pair_setup.c src/mfi/esp_hap_secure_message.c src/mfi/esp_mfi_wac.c src/mfi/esp_hap_wifi_transport.c) 39 | list(APPEND priv_includes src/mfi) 40 | else() 41 | list(APPEND srcs src/esp_mfi_dummy.c) 42 | 43 | endif() 44 | 45 | set(priv_req libsodium esp_http_server hkdf-sha mu_srp json_generator json_parser esp_hap_platform esp_hap_apple_profiles mdns) 46 | # esp_timer component was introduced in v4.2 47 | if("${IDF_VERSION_MAJOR}.${IDF_VERSION_MINOR}" VERSION_GREATER "4.1") 48 | list(APPEND priv_req esp_timer) 49 | endif() 50 | 51 | if("${IDF_VERSION_MAJOR}.${IDF_VERSION_MINOR}" VERSION_GREATER_EQUAL "5.0") 52 | list(APPEND priv_req esp_wifi) 53 | list(APPEND req esp_event) 54 | endif() 55 | 56 | idf_component_register(SRCS ${srcs} 57 | INCLUDE_DIRS "include" 58 | PRIV_INCLUDE_DIRS ${priv_includes} 59 | REQUIRES ${req} 60 | PRIV_REQUIRES ${priv_req}) 61 | component_compile_options(-Wno-unused-function) 62 | target_compile_definitions(${COMPONENT_TARGET} PRIVATE "-D MFI_VER=\"${MFI_VER}\"") 63 | # Added just to automatically trigger re-runs of CMake 64 | git_describe(ESP_HOMEKIT_VERSION ${COMPONENT_DIR}) 65 | message(STATUS "ESP HomeKit SDK Project commit: " ${ESP_HOMEKIT_VERSION}) 66 | -------------------------------------------------------------------------------- /components/homekit/esp_hap_core/Kconfig: -------------------------------------------------------------------------------- 1 | menu "HomeKit" 2 | 3 | config HAP_MFI_ENABLE 4 | bool "Enable MFi" 5 | default n 6 | help 7 | If you have the MFi variant of the SDK, set this to true to use features like 8 | HW authentication, software token authentication and WAC. 9 | 10 | config HAP_SESSION_KEEP_ALIVE_ENABLE 11 | bool "Enable Keep Alive on sessions" 12 | default n 13 | depends on !HAP_MFI_ENABLE 14 | help 15 | Enable Keep Alive on Controller Sessions so that stale connections do not stay 16 | open indefinitely. Note that the HomeKit Specs do not allow this and so, this 17 | should be enabled at your own risk. Even without this option, the HomeKit core 18 | will close stale session using the HTTP Server's Least Recently Used (LRU) purge 19 | logic. 20 | 21 | endmenu 22 | -------------------------------------------------------------------------------- /components/homekit/esp_hap_core/component.mk: -------------------------------------------------------------------------------- 1 | # 2 | # Component Makefile 3 | # 4 | HAP_SDK_VER := "4.0" 5 | COMPONENT_SRCDIRS := src 6 | COMPONENT_PRIV_INCLUDEDIRS := src/priv_includes 7 | MFI_VER := $(HAP_SDK_VER)-$(shell git log --pretty=format:"%h" -1) 8 | 9 | ifdef CONFIG_HAP_MFI_ENABLE 10 | COMPONENT_SRCDIRS += src/mfi 11 | COMPONENT_OBJEXCLUDE += src/esp_mfi_dummy.o 12 | COMPONENT_PRIV_INCLUDEDIRS += src/mfi 13 | endif 14 | 15 | CPPFLAGS += -D MFI_VER=\"$(MFI_VER)\" 16 | 17 | CFLAGS += -Wno-unused-function 18 | COMPONENT_ADD_INCLUDEDIRS := include 19 | -------------------------------------------------------------------------------- /components/homekit/esp_hap_core/idf_component.yml: -------------------------------------------------------------------------------- 1 | ## IDF Component Manager Manifest File 2 | dependencies: 3 | espressif/json_generator: 4 | version: "~1.1.1" 5 | espressif/json_parser: 6 | version: "~1.0.3" 7 | espressif/libsodium: 8 | version: "~1.0.20" 9 | rules: 10 | - if: "idf_version >=5.0" 11 | espressif/mdns: 12 | rules: 13 | - if: "idf_version >=5.0" 14 | -------------------------------------------------------------------------------- /components/homekit/esp_hap_core/include/hap_bct.h: -------------------------------------------------------------------------------- 1 | /* 2 | * ESPRESSIF MIT License 3 | * 4 | * Copyright (c) 2020 5 | * 6 | * Permission is hereby granted for use on ESPRESSIF SYSTEMS products only, in which case, 7 | * it is free of charge, to any person obtaining a copy of this software and associated 8 | * documentation files (the "Software"), to deal in the Software without restriction, including 9 | * without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, 10 | * and/or sell copies of the Software, and to permit persons to whom the Software is furnished 11 | * to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all copies or 14 | * 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, FITNESS 18 | * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 19 | * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 20 | * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 21 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 22 | * 23 | */ 24 | #ifndef _HAP_BCT_H_ 25 | #define _HAP_BCT_H_ 26 | 27 | #ifdef __cplusplus 28 | extern "C" { 29 | #endif 30 | 31 | /** 32 | * @brief Change the name of the Bonjour Service for BCT 33 | * 34 | * This is required as per the "Manual Name Change" step of "Tester Interaction" 35 | * section of Bonjour Conformance Test. 36 | * 37 | * @param[in] name The desired new name for the service. For BCT 1.4 or earlier: "New - Bonjour Service Name". 38 | * For BCT 1.5 or later: "New-BCT" 39 | */ 40 | void hap_bct_change_name(const char *name); 41 | 42 | /** 43 | * @brief Trigger a Hot plug of the network interface for BCT 44 | * 45 | * This is required as per the "Cable Change Handling" and "Hot Plugging" steps 46 | * of "Tester Interaction" section of Bonjout Conformance Test 47 | */ 48 | void hap_bct_hot_plug(); 49 | 50 | #ifdef __cplusplus 51 | } 52 | #endif 53 | 54 | #endif /* _HAP_BCT_H_ */ 55 | -------------------------------------------------------------------------------- /components/homekit/esp_hap_core/src/byte_convert.c: -------------------------------------------------------------------------------- 1 | // Copyright 2020 Espressif Systems (Shanghai) PTE LTD 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 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | #include 15 | #include 16 | 17 | /* Functions to convert Little Endian byte stream to 18 | * uint16, uint32 and uint64 19 | */ 20 | uint16_t get_u16_le(const void *val_ptr) 21 | { 22 | const uint8_t *p = (const uint8_t *)val_ptr; 23 | uint16_t val; 24 | 25 | val = (uint16_t)p[0]; 26 | val |= (uint16_t)p[1] << 8; 27 | 28 | return val; 29 | } 30 | 31 | uint32_t get_u32_le(const void *val_ptr) 32 | { 33 | const uint8_t *p = (const uint8_t *)val_ptr; 34 | uint32_t val; 35 | 36 | val = (uint32_t)p[0]; 37 | val |= (uint32_t)p[1] << 8; 38 | val |= (uint32_t)p[2] << 16; 39 | val |= (uint32_t)p[3] << 24; 40 | 41 | return val; 42 | } 43 | 44 | uint64_t get_u64_le(const void *val_ptr) 45 | { 46 | const uint8_t *p = (const uint8_t *)val_ptr; 47 | uint64_t val; 48 | 49 | val = (uint64_t)p[0]; 50 | val |= (uint64_t)p[1] << 8; 51 | val |= (uint64_t)p[2] << 16; 52 | val |= (uint64_t)p[3] << 24; 53 | val |= (uint64_t)p[4] << 32; 54 | val |= (uint64_t)p[5] << 40; 55 | val |= (uint64_t)p[6] << 48; 56 | val |= (uint64_t)p[7] << 56; 57 | 58 | return val; 59 | } 60 | 61 | /* Functions to convert Big Endian byte stream to 62 | * uint16, uint32 and uint64 63 | */ 64 | uint16_t get_u16_be(const void *val_ptr) 65 | { 66 | const uint8_t *p = (const uint8_t *)val_ptr; 67 | uint16_t val; 68 | 69 | val = (uint16_t)p[0] << 8; 70 | val |= (uint16_t)p[1]; 71 | 72 | return val; 73 | } 74 | 75 | uint32_t get_u32_be(const void *val_ptr) 76 | { 77 | const uint8_t *p = (const uint8_t *)val_ptr; 78 | uint32_t val; 79 | 80 | val = (uint32_t)p[0] << 24; 81 | val |= (uint32_t)p[1] << 16; 82 | val |= (uint32_t)p[2] << 8; 83 | val |= (uint32_t)p[3]; 84 | 85 | return val; 86 | } 87 | 88 | uint64_t get_u64_be(const void *val_ptr) 89 | { 90 | const uint8_t *p = (const uint8_t *)val_ptr; 91 | uint64_t val; 92 | 93 | val = (uint64_t)p[0] << 56; 94 | val |= (uint64_t)p[1] << 48; 95 | val |= (uint64_t)p[2] << 40; 96 | val |= (uint64_t)p[3] << 32; 97 | val |= (uint64_t)p[4] << 24; 98 | val |= (uint64_t)p[5] << 16; 99 | val |= (uint64_t)p[6] << 8; 100 | val |= (uint64_t)p[7]; 101 | 102 | return val; 103 | } 104 | 105 | /* Functions to convert uint16, uint32 and uint64 106 | * to Little Endian 107 | */ 108 | void put_u16_le(void *val_ptr, const uint16_t val) 109 | { 110 | uint8_t *p = (uint8_t *)val_ptr; 111 | 112 | p[0] = (uint8_t)val & 0xff; 113 | p[1] = (uint8_t)(val >> 8) & 0xff; 114 | } 115 | 116 | void put_u32_le(void *val_ptr, const uint32_t val) 117 | { 118 | uint8_t *p = (uint8_t *)val_ptr; 119 | 120 | p[0] = (uint8_t)val & 0xff; 121 | p[1] = (uint8_t)(val >> 8) & 0xff; 122 | p[2] = (uint8_t)(val >> 16) & 0xff; 123 | p[3] = (uint8_t)(val >> 24) & 0xff; 124 | } 125 | 126 | void put_u64_le(void *val_ptr, const uint64_t val) 127 | { 128 | uint8_t *p = (uint8_t *)val_ptr; 129 | 130 | p[0] = (uint8_t)val & 0xff; 131 | p[1] = (uint8_t)(val >> 8) & 0xff; 132 | p[2] = (uint8_t)(val >> 16) & 0xff; 133 | p[3] = (uint8_t)(val >> 24) & 0xff; 134 | p[4] = (uint8_t)(val >> 32) & 0xff; 135 | p[5] = (uint8_t)(val >> 40) & 0xff; 136 | p[6] = (uint8_t)(val >> 48) & 0xff; 137 | p[7] = (uint8_t)(val >> 56) & 0xff; 138 | } 139 | 140 | /* Functions to convert uint16, uint32 and uint64 141 | * to Big Endian 142 | */ 143 | void put_u16_be(void *val_ptr, const uint16_t val) 144 | { 145 | uint8_t *p = (uint8_t *)val_ptr; 146 | 147 | p[0] = (uint8_t)(val >> 8) & 0xff; 148 | p[1] = (uint8_t)val & 0xff; 149 | } 150 | 151 | void put_u32_be(void *val_ptr, const uint32_t val) 152 | { 153 | uint8_t *p = (uint8_t *)val_ptr; 154 | 155 | p[0] = (uint8_t)((val >> 24) & 0xff); 156 | p[1] = (uint8_t)((val >> 16) & 0xff); 157 | p[2] = (uint8_t)((val >> 8) & 0xff); 158 | p[3] = (uint8_t)(val & 0xff); 159 | } 160 | 161 | void put_u64_be(void *val_ptr, const uint64_t val) 162 | { 163 | uint8_t *p = (uint8_t *)val_ptr; 164 | 165 | p[0] = (uint8_t)(val >> 56) & 0xff; 166 | p[1] = (uint8_t)(val >> 48) & 0xff; 167 | p[2] = (uint8_t)(val >> 40) & 0xff; 168 | p[3] = (uint8_t)(val >> 32) & 0xff; 169 | p[4] = (uint8_t)(val >> 24) & 0xff; 170 | p[5] = (uint8_t)(val >> 16) & 0xff; 171 | p[6] = (uint8_t)(val >> 8) & 0xff; 172 | p[7] = (uint8_t)val & 0xff; 173 | } 174 | -------------------------------------------------------------------------------- /components/homekit/esp_hap_core/src/esp_hap_bct.c: -------------------------------------------------------------------------------- 1 | /* 2 | * ESPRESSIF MIT License 3 | * 4 | * Copyright (c) 2020 5 | * 6 | * Permission is hereby granted for use on ESPRESSIF SYSTEMS products only, in which case, 7 | * it is free of charge, to any person obtaining a copy of this software and associated 8 | * documentation files (the "Software"), to deal in the Software without restriction, including 9 | * without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, 10 | * and/or sell copies of the Software, and to permit persons to whom the Software is furnished 11 | * to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all copies or 14 | * 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, FITNESS 18 | * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 19 | * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 20 | * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 21 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 22 | * 23 | */ 24 | 25 | #include 26 | #include 27 | #include 28 | #include 29 | #include 30 | #include 31 | #include 32 | #include 33 | 34 | static char *new_name; 35 | 36 | void hap_bct_change_name(const char *name) 37 | { 38 | if (new_name) { 39 | hap_platform_memory_free(new_name); 40 | } 41 | new_name = strdup(name); 42 | hap_send_event(HAP_INTERNAL_EVENT_BCT_CHANGE_NAME); 43 | } 44 | 45 | void hap_bct_hot_plug() 46 | { 47 | hap_send_event(HAP_INTERNAL_EVENT_BCT_HOT_PLUG); 48 | } 49 | 50 | void hap_handle_bct_change_name() 51 | { 52 | if (!new_name) { 53 | ESP_MFI_DEBUG(ESP_MFI_DEBUG_ERR, "No BCT name specified"); 54 | return; 55 | } else { 56 | ESP_MFI_DEBUG(ESP_MFI_DEBUG_INFO, "Changing BCT Name to %s", new_name); 57 | } 58 | if (hap_mdns_serv_name_change(&hap_priv.hap_mdns_handle, new_name) != HAP_SUCCESS) { 59 | ESP_MFI_DEBUG(ESP_MFI_DEBUG_ERR, "Failed to change BCT name"); 60 | } 61 | hap_platform_memory_free(new_name); 62 | new_name = NULL; 63 | } 64 | 65 | void hap_handle_hot_plug() 66 | { 67 | esp_wifi_stop(); 68 | vTaskDelay((10 * 1000) / portTICK_PERIOD_MS); /* Wait for 10 seconds */ 69 | esp_wifi_start(); 70 | esp_wifi_connect(); 71 | } 72 | -------------------------------------------------------------------------------- /components/homekit/esp_hap_core/src/esp_hap_mdns.c: -------------------------------------------------------------------------------- 1 | /* 2 | * ESPRESSIF MIT License 3 | * 4 | * Copyright (c) 2020 5 | * 6 | * Permission is hereby granted for use on ESPRESSIF SYSTEMS products only, in which case, 7 | * it is free of charge, to any person obtaining a copy of this software and associated 8 | * documentation files (the "Software"), to deal in the Software without restriction, including 9 | * without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, 10 | * and/or sell copies of the Software, and to permit persons to whom the Software is furnished 11 | * to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all copies or 14 | * 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, FITNESS 18 | * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 19 | * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 20 | * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 21 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 22 | * 23 | */ 24 | #include 25 | #include 26 | #include 27 | 28 | static bool mdns_init_done; 29 | 30 | int hap_mdns_serv_start(hap_mdns_handle_t *handle, const char *name, const char *type, 31 | const char *protocol, int port, mdns_txt_item_t *txt_records, size_t num_txt) 32 | { 33 | strcpy(handle->type, type); 34 | strcpy(handle->proto, protocol); 35 | if (mdns_service_add(name, type, protocol, port, txt_records, num_txt) != 0) { 36 | return HAP_FAIL; 37 | } 38 | return HAP_SUCCESS; 39 | } 40 | 41 | int hap_mdns_serv_update_txt(hap_mdns_handle_t *handle, mdns_txt_item_t *txt_records, size_t num_txt) 42 | { 43 | if (mdns_service_txt_set(handle->type, handle->proto, txt_records, num_txt) != 0) { 44 | return HAP_FAIL; 45 | } 46 | return HAP_SUCCESS; 47 | } 48 | 49 | int hap_mdns_serv_name_change(hap_mdns_handle_t *handle, const char * instance_name) 50 | { 51 | if (mdns_service_instance_name_set(handle->type, handle->proto, instance_name) == ESP_OK) { 52 | return HAP_SUCCESS; 53 | } 54 | return HAP_FAIL; 55 | } 56 | 57 | int hap_mdns_serv_stop(hap_mdns_handle_t *handle) 58 | { 59 | if (mdns_service_remove(handle->type, handle->proto) == ESP_OK) { 60 | return HAP_SUCCESS; 61 | } 62 | return HAP_FAIL; 63 | } 64 | 65 | int hap_mdns_init() 66 | { 67 | int ret = HAP_SUCCESS; 68 | if (!mdns_init_done) { 69 | ret = mdns_init(); 70 | if (ret == ESP_OK) { 71 | mdns_hostname_set("MyHost"); 72 | mdns_init_done = true; 73 | ESP_MFI_DEBUG(ESP_MFI_DEBUG_INFO, "mDNS initialised"); 74 | return HAP_SUCCESS; 75 | } 76 | } 77 | return HAP_FAIL; 78 | } 79 | 80 | int hap_mdns_deinit() 81 | { 82 | mdns_free(); 83 | mdns_init_done = false; 84 | return HAP_SUCCESS; 85 | } 86 | -------------------------------------------------------------------------------- /components/homekit/esp_hap_core/src/esp_hap_pair_common.c: -------------------------------------------------------------------------------- 1 | /* 2 | * ESPRESSIF MIT License 3 | * 4 | * Copyright (c) 2020 5 | * 6 | * Permission is hereby granted for use on ESPRESSIF SYSTEMS products only, in which case, 7 | * it is free of charge, to any person obtaining a copy of this software and associated 8 | * documentation files (the "Software"), to deal in the Software without restriction, including 9 | * without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, 10 | * and/or sell copies of the Software, and to permit persons to whom the Software is furnished 11 | * to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all copies or 14 | * 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, FITNESS 18 | * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 19 | * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 20 | * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 21 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 22 | * 23 | */ 24 | #include 25 | #include 26 | #include 27 | #include 28 | 29 | void hap_tlv_data_init(hap_tlv_data_t *tlv_data, uint8_t *buf, int buf_size) 30 | { 31 | tlv_data->bufptr = buf; 32 | tlv_data->bufsize = buf_size; 33 | tlv_data->curlen = 0; 34 | } 35 | 36 | int get_tlv_length(uint8_t *buf, int buflen, uint8_t type) 37 | { 38 | if (!buf ) 39 | return -1; 40 | int curlen = 0; 41 | int val_len = 0; 42 | bool found = false; 43 | while (buflen > 0) { 44 | if (buf[curlen] == type) { 45 | uint8_t len = buf[curlen + 1]; 46 | if ((buflen - len) < 2) 47 | return -1; 48 | val_len += len; 49 | if (len < 255) 50 | return val_len; 51 | else 52 | found = true; 53 | 54 | } else if (found) 55 | return val_len; 56 | 57 | /* buf[curlen +1] will give the Length */ 58 | buflen -= (2 + buf[curlen + 1]); 59 | curlen += (2 + buf[curlen + 1]); 60 | } 61 | return -1; 62 | } 63 | int get_value_from_tlv(uint8_t *buf, int buflen, uint8_t type, void *val, int val_size) 64 | { 65 | if (!buf || !val) 66 | return -1; 67 | int curlen = 0; 68 | int val_len = 0; 69 | bool found = false; 70 | while (buflen > 0) { 71 | if (buf[curlen] == type) { 72 | uint8_t len = buf[curlen + 1]; 73 | if ((val_size < len) || ((buflen - len) < 2)) 74 | return -1; 75 | memcpy(val + val_len, &buf[curlen + 2], len); 76 | val_len += len; 77 | val_size -= len; 78 | if (len < 255) 79 | return val_len; 80 | else 81 | found = true; 82 | 83 | } else if (found) 84 | return val_len; 85 | 86 | /* buf[curlen +1] will give the Length */ 87 | buflen -= (2 + buf[curlen + 1]); 88 | curlen += (2 + buf[curlen + 1]); 89 | } 90 | return -1; 91 | } 92 | 93 | int add_tlv(hap_tlv_data_t *tlv_data, uint8_t type, int len, void *val) 94 | { 95 | if(!tlv_data->bufptr || ((len + 2) > (tlv_data->bufsize - tlv_data->curlen))) 96 | return -1; 97 | uint8_t *buf_ptr = (uint8_t *)val; 98 | int orig_len = tlv_data->curlen; 99 | do { 100 | tlv_data->bufptr[tlv_data->curlen++] = type; 101 | int tmp_len; 102 | if (len > 255) 103 | tmp_len = 255; 104 | else 105 | tmp_len = len; 106 | tlv_data->bufptr[tlv_data->curlen++] = tmp_len; 107 | memcpy(&tlv_data->bufptr[tlv_data->curlen], buf_ptr, tmp_len); 108 | tlv_data->curlen += tmp_len; 109 | buf_ptr += tmp_len; 110 | len -= tmp_len; 111 | } while (len); 112 | return tlv_data->curlen - orig_len; 113 | } 114 | void hap_prepare_error_tlv(uint8_t state, uint8_t error, void *buf, int bufsize, int *outlen) 115 | { 116 | hap_tlv_data_t tlv_data; 117 | tlv_data.bufptr = buf; 118 | tlv_data.bufsize = bufsize; 119 | tlv_data.curlen = 0; 120 | /* Not doing any error handling because the size required for "state" and "error" will 121 | * be too small to cause any error, and we anyways dont have any specific action to 122 | * do in case if error in add_tlv() 123 | */ 124 | add_tlv(&tlv_data, kTLVType_State, sizeof(state), &state); 125 | add_tlv(&tlv_data, kTLVType_Error, sizeof(error), &error); 126 | *outlen = tlv_data.curlen; 127 | } 128 | -------------------------------------------------------------------------------- /components/homekit/esp_hap_core/src/esp_hap_setup_payload.c: -------------------------------------------------------------------------------- 1 | /* 2 | * ESPRESSIF MIT License 3 | * 4 | * Copyright (c) 2020 5 | * 6 | * Permission is hereby granted for use on ESPRESSIF SYSTEMS products only, in which case, 7 | * it is free of charge, to any person obtaining a copy of this software and associated 8 | * documentation files (the "Software"), to deal in the Software without restriction, including 9 | * without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, 10 | * and/or sell copies of the Software, and to permit persons to whom the Software is furnished 11 | * to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all copies or 14 | * 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, FITNESS 18 | * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 19 | * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 20 | * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 21 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 22 | * 23 | */ 24 | #include 25 | #include 26 | #include 27 | #include 28 | #include 29 | 30 | #include 31 | 32 | static const char *TAG = "esp_hap_setup_payload"; 33 | 34 | #define SETUP_CODE_MASK 0x0000000007ffffff 35 | #define HAP_OVER_IP_MASK 0x0000000010000000 36 | #define WAC_MASK 0x0000000040000000 37 | #define SETUP_PAYLOAD_PREFIX "X-HM://00" 38 | 39 | static void remove_chars(char *str, char c) 40 | { 41 | int i = 0, j = 0; 42 | while(str[i]) { 43 | if (str[i] != c) { 44 | str[j] = str[i]; 45 | j++; 46 | } 47 | i++; 48 | } 49 | str[j] = 0; 50 | } 51 | 52 | char *esp_hap_get_setup_payload(char *setup_code, char *setup_id, bool wac_support, hap_cid_t cid) 53 | { 54 | if (!setup_code || !setup_id) { 55 | ESP_LOGE(TAG, "Setup code or Setup ID cannot be NULL"); 56 | return NULL; 57 | } 58 | uint64_t payload = 0; 59 | if (strlen(setup_code) != 10 || strlen(setup_id) != 4) { 60 | ESP_LOGE(TAG, "Setup code or Setup ID not correct. Eg. 111-22-333, ES32"); 61 | return NULL; 62 | } 63 | char setup_code_copy[11]; 64 | strcpy(setup_code_copy, setup_code); 65 | remove_chars(setup_code_copy, '-'); 66 | int64_t code = atoi(setup_code_copy); 67 | int64_t category = cid; 68 | category <<= 31; 69 | 70 | payload |= code; 71 | payload |= category; 72 | payload |= HAP_OVER_IP_MASK; 73 | if (wac_support) { 74 | payload |= WAC_MASK; 75 | } 76 | char *base36_str = base36_to_str(payload); 77 | char setup_payload[24]; 78 | snprintf(setup_payload, sizeof(setup_payload), "%s%s%s", SETUP_PAYLOAD_PREFIX, base36_str, setup_id); 79 | free(base36_str); 80 | return strdup(setup_payload); 81 | } 82 | -------------------------------------------------------------------------------- /components/homekit/esp_hap_core/src/esp_hap_wifi.c: -------------------------------------------------------------------------------- 1 | /* 2 | * ESPRESSIF MIT License 3 | * 4 | * Copyright (c) 2020 5 | * 6 | * Permission is hereby granted for use on ESPRESSIF SYSTEMS products only, in which case, 7 | * it is free of charge, to any person obtaining a copy of this software and associated 8 | * documentation files (the "Software"), to deal in the Software without restriction, including 9 | * without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, 10 | * and/or sell copies of the Software, and to permit persons to whom the Software is furnished 11 | * to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all copies or 14 | * 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, FITNESS 18 | * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 19 | * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 20 | * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 21 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 22 | * 23 | */ 24 | #include 25 | #include 26 | #include 27 | #include 28 | #include 29 | 30 | esp_err_t hap_wifi_is_provisioned(bool *provisioned) 31 | { 32 | if (!provisioned) { 33 | return ESP_ERR_INVALID_ARG; 34 | } 35 | 36 | *provisioned = false; 37 | 38 | /* Get Wi-Fi Station configuration */ 39 | wifi_config_t wifi_cfg; 40 | if (esp_wifi_get_config(ESP_IF_WIFI_STA, &wifi_cfg) != ESP_OK) { 41 | return ESP_FAIL; 42 | } 43 | 44 | if (strlen((const char *) wifi_cfg.sta.ssid)) { 45 | *provisioned = true; 46 | } 47 | return ESP_OK; 48 | } 49 | bool hap_is_network_configured(void) 50 | { 51 | /* If only the Ethernet is enabled, return true */ 52 | if (hap_priv.transport == HAP_TRANSPORT_ETHERNET) { 53 | return true; 54 | } 55 | 56 | bool provisioned = false; 57 | hap_wifi_is_provisioned(&provisioned); 58 | return provisioned; 59 | } 60 | 61 | void hap_erase_network_info(void) 62 | { 63 | esp_wifi_restore(); 64 | } 65 | 66 | esp_err_t hap_wifi_softap_start(char *ssid) 67 | { 68 | if (!ssid) { 69 | ESP_MFI_DEBUG(ESP_MFI_DEBUG_ERR, "SSID cannot be NULL"); 70 | } 71 | ESP_MFI_DEBUG(ESP_MFI_DEBUG_INFO, "Starting SoftAP with SSID: %s", ssid); 72 | wifi_config_t wifi_config = { 73 | .ap = { 74 | .ssid = "", 75 | .ssid_len = 0, 76 | .max_connection = 4, 77 | .password = "", 78 | .authmode = WIFI_AUTH_OPEN 79 | }, 80 | }; 81 | size_t ssid_len = strnlen(ssid, sizeof(wifi_config.ap.ssid)); 82 | memcpy(wifi_config.ap.ssid, ssid, ssid_len); 83 | wifi_mode_t mode; 84 | esp_wifi_get_mode(&mode); 85 | if (mode == WIFI_MODE_STA) { 86 | esp_wifi_set_mode(WIFI_MODE_APSTA); 87 | } else { 88 | esp_wifi_set_mode(WIFI_MODE_AP); 89 | } 90 | esp_wifi_set_config(ESP_IF_WIFI_AP, &wifi_config); 91 | esp_wifi_start(); 92 | return ESP_OK; 93 | } 94 | 95 | esp_err_t hap_wifi_softap_stop(void) 96 | { 97 | ESP_MFI_DEBUG(ESP_MFI_DEBUG_INFO, "Stopping SoftAP."); 98 | wifi_mode_t mode; 99 | esp_wifi_get_mode(&mode); 100 | if (mode == WIFI_MODE_AP) { 101 | esp_wifi_stop(); 102 | } 103 | esp_wifi_set_mode(WIFI_MODE_STA); 104 | return ESP_OK; 105 | } 106 | 107 | esp_err_t hap_wifi_sta_connect(wifi_config_t *config) 108 | { 109 | ESP_MFI_DEBUG(ESP_MFI_DEBUG_INFO, "Connecting to Wi-Fi."); 110 | wifi_mode_t mode; 111 | esp_wifi_get_mode(&mode); 112 | if (mode == WIFI_MODE_AP || mode == WIFI_MODE_APSTA) { 113 | esp_wifi_set_mode(WIFI_MODE_APSTA); 114 | } else { 115 | esp_wifi_set_mode(WIFI_MODE_STA); 116 | } 117 | esp_wifi_set_config(ESP_IF_WIFI_STA, config); 118 | esp_wifi_start(); 119 | esp_wifi_connect(); 120 | return ESP_OK; 121 | } 122 | 123 | esp_err_t hap_wifi_sta_switch(wifi_config_t *config) 124 | { 125 | ESP_MFI_DEBUG(ESP_MFI_DEBUG_INFO, "Switching Wi-Fi network."); 126 | wifi_mode_t mode; 127 | esp_wifi_get_mode(&mode); 128 | if (mode == WIFI_MODE_AP || mode == WIFI_MODE_APSTA) { 129 | esp_wifi_set_mode(WIFI_MODE_APSTA); 130 | } else { 131 | esp_wifi_set_mode(WIFI_MODE_STA); 132 | } 133 | esp_wifi_set_config(ESP_IF_WIFI_STA, config); 134 | esp_wifi_disconnect(); 135 | esp_wifi_connect(); 136 | return ESP_OK; 137 | } 138 | -------------------------------------------------------------------------------- /components/homekit/esp_hap_core/src/esp_mfi_debug.c: -------------------------------------------------------------------------------- 1 | /* 2 | * ESPRESSIF MIT License 3 | * 4 | * Copyright (c) 2020 5 | * 6 | * Permission is hereby granted for use on ESPRESSIF SYSTEMS products only, in which case, 7 | * it is free of charge, to any person obtaining a copy of this software and associated 8 | * documentation files (the "Software"), to deal in the Software without restriction, including 9 | * without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, 10 | * and/or sell copies of the Software, and to permit persons to whom the Software is furnished 11 | * to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all copies or 14 | * 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, FITNESS 18 | * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 19 | * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 20 | * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 21 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 22 | * 23 | */ 24 | 25 | #include 26 | #include 27 | #include 28 | 29 | #define RED_CHAR 31 30 | #define GREEN_CHAR 32 31 | #define YELLOW_CHAR 33 32 | #define BLUE_CHAR 34 33 | #define CYAN_CHAR 36 34 | #define WHITE_CHAR 37 35 | 36 | #ifdef CONFIG_MFI_DEBUG_LEVEL_INIT 37 | #define MFI_DEBUG_LEVEL_INIT CONFIG_MFI_DEBUG_LEVEL_INIT 38 | #else /* CONFIG_MFI_DEBUG_LEVEL_INIT */ 39 | #define MFI_DEBUG_LEVEL_INIT 0 40 | #endif /* CONFIG_MFI_DEBUG_LEVEL_INIT */ 41 | 42 | static uint32_t mfi_debug_level = MFI_DEBUG_LEVEL_INIT; 43 | 44 | /** 45 | * @bref set the MFI debugging level 46 | */ 47 | int esp_mfi_set_debug_level(uint32_t level) 48 | { 49 | mfi_debug_level = level; 50 | return 0; 51 | } 52 | 53 | /** 54 | * @bref get the MFI debugging level and output data color 55 | */ 56 | uint32_t esp_mfi_get_debug_level(uint32_t level, uint32_t *color) 57 | { 58 | const uint32_t prospect_table[] = { 59 | 0, /* no */ 60 | WHITE_CHAR, /* information: 1, color(37: white) */ 61 | GREEN_CHAR, /* warn : 3, color(32: green) */ 62 | RED_CHAR, /* error : 3, color(31: red) */ 63 | YELLOW_CHAR, /* assert : 4, color(33: yellow) */ 64 | CYAN_CHAR /* block : 5, color(36: cyan) */ 65 | /* others : n, color(34: blue) */ 66 | }; 67 | const uint32_t prospect_table_size = sizeof(prospect_table) / sizeof(prospect_table[0]); 68 | 69 | if (level < prospect_table_size) 70 | *color = prospect_table[level]; 71 | else 72 | *color = BLUE_CHAR; 73 | 74 | return mfi_debug_level; 75 | } 76 | 77 | void hap_set_debug_level(hap_debug_level_t level) 78 | { 79 | esp_mfi_set_debug_level(level); 80 | } 81 | -------------------------------------------------------------------------------- /components/homekit/esp_hap_core/src/esp_mfi_dummy.c: -------------------------------------------------------------------------------- 1 | /* 2 | * ESPRESSIF MIT License 3 | * 4 | * Copyright (c) 2020 5 | * 6 | * Permission is hereby granted for use on ESPRESSIF SYSTEMS products only, in which case, 7 | * it is free of charge, to any person obtaining a copy of this software and associated 8 | * documentation files (the "Software"), to deal in the Software without restriction, including 9 | * without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, 10 | * and/or sell copies of the Software, and to permit persons to whom the Software is furnished 11 | * to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all copies or 14 | * 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, FITNESS 18 | * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 19 | * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 20 | * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 21 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 22 | * 23 | */ 24 | #include 25 | #include 26 | #include 27 | #include 28 | #include 29 | #include 30 | #include 31 | 32 | ESP_EVENT_DEFINE_BASE(HAP_WAC_EVENT); 33 | 34 | int hap_pair_setup_manage_mfi_auth(pair_setup_ctx_t *ps_ctx, hap_tlv_data_t *tlv_data, hap_tlv_error_t *tlv_error) 35 | { 36 | 37 | if (ps_ctx->method == HAP_METHOD_PAIR_SETUP) { 38 | ESP_MFI_DEBUG(ESP_MFI_DEBUG_ERR, "Secure pair setup not supported. Please use MFi variant of the SDK."); 39 | *tlv_error = kTLVError_Unknown; 40 | return HAP_FAIL; 41 | } 42 | ESP_MFI_DEBUG(ESP_MFI_DEBUG_WARN, "Using pair-setup without MFi."); 43 | return ESP_OK; 44 | } 45 | 46 | int hap_enable_mfi_auth(hap_mfi_auth_type_t auth_type) 47 | { 48 | ESP_MFI_DEBUG(ESP_MFI_DEBUG_WARN, "MFi auth not supported. Falling back to HAP_MFI_AUTH_NONE"); 49 | hap_priv.auth_type = HAP_MFI_AUTH_NONE; 50 | return 0; 51 | } 52 | 53 | int hap_wac_start(void) 54 | { 55 | ESP_MFI_DEBUG(ESP_MFI_DEBUG_ERR, "WAC not supported. Please use MFi variant of the SDK."); 56 | return ESP_FAIL; 57 | } 58 | 59 | int hap_wac_stop(void) 60 | { 61 | ESP_MFI_DEBUG(ESP_MFI_DEBUG_ERR, "WAC not supported. Please use MFi variant of the SDK."); 62 | return ESP_FAIL; 63 | } 64 | int hap_enable_hw_auth(void) 65 | { 66 | ESP_MFI_DEBUG(ESP_MFI_DEBUG_ERR, "MFi HW Auth not supported. Please use MFi variant of the SDK."); 67 | return ESP_FAIL; 68 | 69 | } 70 | int hap_enable_sw_auth(void) 71 | { 72 | ESP_MFI_DEBUG(ESP_MFI_DEBUG_ERR, "MFi SW Auth not supported. Please use MFi variant of the SDK."); 73 | return ESP_FAIL; 74 | } 75 | int hap_register_secure_message_handler(httpd_handle_t handle) 76 | { 77 | ESP_MFI_DEBUG(ESP_MFI_DEBUG_ERR, "MFi SW Auth not supported. Please use MFi variant of the SDK."); 78 | return ESP_FAIL; 79 | } 80 | int hap_unregister_secure_message_handler(httpd_handle_t handle) 81 | { 82 | ESP_MFI_DEBUG(ESP_MFI_DEBUG_ERR, "MFi SW Auth not supported. Please use MFi variant of the SDK."); 83 | return ESP_FAIL; 84 | } 85 | 86 | esp_err_t hap_wifi_config_revert_network(void) 87 | { 88 | ESP_MFI_DEBUG(ESP_MFI_DEBUG_ERR, "Wi-Fi reconfiguration service not supported. Please use MFi variant of the SDK."); 89 | return ESP_FAIL; 90 | } 91 | esp_err_t hap_wifi_config_sta_connect(void) 92 | { 93 | ESP_MFI_DEBUG(ESP_MFI_DEBUG_ERR, "Wi-Fi reconfiguration service not supported. Please use MFi variant of the SDK."); 94 | return ESP_FAIL; 95 | } 96 | 97 | esp_err_t hap_acc_add_wifi_transport_service(hap_acc_t *ha, uint32_t capabilities) 98 | { 99 | ESP_MFI_DEBUG(ESP_MFI_DEBUG_WARN, "Wi-Fi reconfiguration service not supported. Please use MFi variant of the SDK."); 100 | return ESP_FAIL; 101 | } 102 | -------------------------------------------------------------------------------- /components/homekit/esp_hap_core/src/hexbin.c: -------------------------------------------------------------------------------- 1 | // Copyright 2020 Espressif Systems (Shanghai) PTE LTD 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 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | #include 15 | static int hex2bin_byte(uint8_t *byte) 16 | { 17 | if (*byte >= '0' && *byte <= '9') 18 | *byte -= '0'; 19 | else if (*byte >= 'a' && *byte <= 'f') 20 | *byte -= ('a' - 0x0a); 21 | else if (*byte >= 'A' && *byte <= 'F') 22 | *byte -= ('A' - 0x0a); 23 | else 24 | return -1; 25 | return 0; 26 | } 27 | 28 | int hex2bin(const char *ihex, size_t ilen, uint8_t *obin, size_t *olen) 29 | { 30 | if (ilen > (2 * (*olen))) { 31 | return -1; 32 | } else if (ilen % 2) { 33 | return -1; 34 | } 35 | int i, j; 36 | uint8_t byte; 37 | for (i = 0, j = 0; i < ilen / 2; i++) { 38 | byte = ihex[j++]; 39 | if (hex2bin_byte(&byte) < 0) { 40 | return -1; 41 | } 42 | obin[i] = (byte << 4); 43 | byte = ihex[j++]; 44 | if (hex2bin_byte(&byte) < 0) { 45 | return -1; 46 | } 47 | obin[i] |= byte; 48 | } 49 | *olen = i; 50 | return 0; 51 | } 52 | -------------------------------------------------------------------------------- /components/homekit/esp_hap_core/src/hexdump.c: -------------------------------------------------------------------------------- 1 | // Copyright 2020 Espressif Systems (Shanghai) PTE LTD 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 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | #include 15 | 16 | //#define HEX_DBG_ENABLE 17 | 18 | #ifdef HEX_DBG_ENABLE 19 | void hex_dbg_with_name(char *name, unsigned char *buf, int buf_len) 20 | { 21 | int i; 22 | printf("%s: ", name); 23 | for (i = 0; i < buf_len; i++) { 24 | if (i % 16 == 0) 25 | printf("\r\n"); 26 | printf("%02x ", buf[i]); 27 | } 28 | printf("\r\n"); 29 | } 30 | #else 31 | void hex_dbg_with_name(char *name, unsigned char *buf, int buf_len) 32 | { 33 | } 34 | #endif /* HEX_DBG_ENABLED */ 35 | -------------------------------------------------------------------------------- /components/homekit/esp_hap_core/src/priv_includes/base36.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Base36 PostgreSQL input/output function for bigint 3 | * 4 | * Author: Dimitri Fontaine 5 | * 6 | * Taken from https://github.com/dimitri/base36/blob/master/base36.c 7 | */ 8 | 9 | #include 10 | #include 11 | 12 | #define BASE36_LENGTH 13 13 | 14 | typedef long long int base36; 15 | 16 | static int base36_digits[36] = 17 | {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 18 | 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 19 | 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 20 | 'U', 'V', 'W', 'X', 'Y', 'Z' 21 | }; 22 | 23 | static base36 base36_powers[BASE36_LENGTH] = 24 | { 25 | 1ULL, 26 | 36ULL, 27 | 1296ULL, 28 | 46656ULL, 29 | 1679616ULL, 30 | 60466176ULL, 31 | 2176782336ULL, 32 | 78364164096ULL, 33 | 2821109907456ULL, 34 | 101559956668416ULL, 35 | 3656158440062976ULL, 36 | 131621703842267136ULL, 37 | 4738381338321616896ULL 38 | }; 39 | 40 | static inline 41 | char *base36_to_str(base36 c) 42 | { 43 | int i, d, p = 0; 44 | base36 m = c; 45 | bool discard = true; 46 | char *str = calloc((BASE36_LENGTH + 1), sizeof(char)); 47 | 48 | for(i=BASE36_LENGTH-1; i>=0; i--) 49 | { 50 | d = m / base36_powers[i]; 51 | m = m - base36_powers[i] * d; 52 | 53 | discard = discard && (d == 0 && i >0); 54 | 55 | if( !discard ) 56 | str[p++] = base36_digits[d]; 57 | } 58 | 59 | return str; 60 | } 61 | -------------------------------------------------------------------------------- /components/homekit/esp_hap_core/src/priv_includes/byte_convert.h: -------------------------------------------------------------------------------- 1 | // Copyright 2020 Espressif Systems (Shanghai) PTE LTD 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 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | /** 15 | * \file byte_convert.h 16 | * \brief Conversion between integers and byte streams 17 | * 18 | * This module offers APIs to convert 16bit, 32bit and 64 bit unsigned integers 19 | * into Little/Big Endian byte streams 20 | */ 21 | #ifndef _BYTE_CONVERT_H 22 | #define _BYTE_CONVERT_H 23 | 24 | #include 25 | 26 | /** Little Endian to uint16 Conversion 27 | * Get a uint16 integer from a little Endian byte stream 28 | * 29 | * \param[in] val_ptr Pointer to the 2 byte stream 30 | * 31 | * \return The converted uint16 integer 32 | */ 33 | uint16_t get_u16_le(const void *val_ptr); 34 | 35 | /** Little Endian to uint32 Conversion 36 | * Get a uint32 integer from a little Endian byte stream 37 | * 38 | * \param[in] val_ptr Pointer to the 4 byte stream 39 | * 40 | * \return The converted uint32 integer 41 | */ 42 | uint32_t get_u32_le(const void *val_ptr); 43 | 44 | /** Little Endian to uint64 Conversion 45 | * Get a uint64 integer from a little Endian byte stream 46 | * 47 | * \param[in] val_ptr Pointer to the 8 byte stream 48 | * 49 | * \return The converted uint32 integer 50 | */ 51 | uint64_t get_u64_le(const void *val_ptr); 52 | 53 | /** Big Endian to uint16 Conversion 54 | * Get a uint16 integer from a Big Endian byte stream 55 | * 56 | * \param[in] val_ptr Pointer to the 2 byte stream 57 | * 58 | * \return The converted uint16 integer 59 | */ 60 | uint16_t get_u16_be(const void *val_ptr); 61 | 62 | /** Big Endian to uint32 Conversion 63 | * Get a uint32 integer from a Big Endian byte stream 64 | * 65 | * \param[in] val_ptr Pointer to the 4 byte stream 66 | * 67 | * \return The converted uint32 integer 68 | */ 69 | uint32_t get_u32_be(const void *val_ptr); 70 | 71 | /** Big Endian to uint64 Conversion 72 | * Get a uint64 integer from a Big Endian byte stream 73 | * 74 | * \param[in] val_ptr Pointer to the 8 byte stream 75 | * 76 | * \return The converted uint16 integer 77 | */ 78 | uint64_t get_u64_be(const void *val_ptr); 79 | 80 | /** Uint16 to Little Endian Conversion 81 | * 82 | * Put a uint16 integer into a Little Endian byte stream 83 | * 84 | * \param[out] Pointer to a 2 byte stream that will be filled with the value 85 | * 86 | * \param[in] The uint16 integer 87 | */ 88 | void put_u16_le(void *val_ptr, const uint16_t val); 89 | 90 | /** Uint32 to Little Endian Conversion 91 | * 92 | * Put a uint32 integer into a Little Endian byte stream 93 | * 94 | * \param[out] Pointer to a 4 byte stream that will be filled with the value 95 | * 96 | * \param[in] The uint32 integer 97 | */ 98 | void put_u32_le(void *val_ptr, const uint32_t val); 99 | 100 | /** Uint64 to Little Endian Conversion 101 | * 102 | * Put a uint64 integer into a Little Endian byte stream 103 | * 104 | * \param[out] Pointer to a 8 byte stream that will be filled with the value 105 | * 106 | * \param[in] The uint64 integer 107 | */ 108 | void put_u64_le(void *val_ptr, const uint64_t val); 109 | 110 | /** Uint16 to Big Endian Conversion 111 | * 112 | * Put a uint16 integer into a Big Endian byte stream 113 | * 114 | * \param[out] Pointer to a 2 byte stream that will be filled with the value 115 | * 116 | * \param[in] The uint16 integer 117 | */ 118 | void put_u16_be(void *val_ptr, const uint16_t val); 119 | 120 | /** Uint32 to Big Endian Conversion 121 | * 122 | * Put a uint32 integer into a Big Endian byte stream 123 | * 124 | * \param[out] Pointer to a 4 byte stream that will be filled with the value 125 | * 126 | * \param[in] The uint32 integer 127 | */ 128 | void put_u32_be(void *val_ptr, const uint32_t val); 129 | 130 | /** Uint64 to Big Endian Conversion 131 | * 132 | * Put a uint64 integer into a Big Endian byte stream 133 | * 134 | * \param[out] Pointer to a 8 byte stream that will be filled with the value 135 | * 136 | * \param[in] The uint64 integer 137 | */ 138 | void put_u64_be(void *val_ptr, const uint64_t val); 139 | #endif /* _BYTE_CONVERT_H */ 140 | -------------------------------------------------------------------------------- /components/homekit/esp_hap_core/src/priv_includes/esp_hap_acc.h: -------------------------------------------------------------------------------- 1 | /* 2 | * ESPRESSIF MIT License 3 | * 4 | * Copyright (c) 2020 5 | * 6 | * Permission is hereby granted for use on ESPRESSIF SYSTEMS products only, in which case, 7 | * it is free of charge, to any person obtaining a copy of this software and associated 8 | * documentation files (the "Software"), to deal in the Software without restriction, including 9 | * without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, 10 | * and/or sell copies of the Software, and to permit persons to whom the Software is furnished 11 | * to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all copies or 14 | * 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, FITNESS 18 | * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 19 | * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 20 | * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 21 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 22 | * 23 | */ 24 | 25 | #ifndef _HAP_ACC_H_ 26 | #define _HAP_ACC_H_ 27 | 28 | #include 29 | #include 30 | 31 | #ifdef __cplusplus 32 | extern "C"{ 33 | #endif 34 | 35 | typedef struct esp_mfi_accessory { 36 | struct esp_mfi_accessory *next; 37 | uint32_t aid; /* accessory AID */ 38 | hap_serv_t *servs; /* service list */ 39 | bool power_off; 40 | uint32_t next_iid; 41 | hap_identify_routine_t identify_routine; 42 | } __hap_acc_t; 43 | hap_char_t *hap_acc_get_char_by_iid(hap_acc_t *ha, int32_t iid); 44 | hap_acc_t *hap_acc_get_by_aid(int32_t aid); 45 | int hap_acc_get_info(hap_acc_cfg_t *acc_cfg); 46 | const hap_val_t *hap_get_product_data(); 47 | #ifdef __cplusplus 48 | } 49 | #endif 50 | 51 | #endif /* _HAP_ACC_H_ */ 52 | -------------------------------------------------------------------------------- /components/homekit/esp_hap_core/src/priv_includes/esp_hap_bct_priv.h: -------------------------------------------------------------------------------- 1 | /* 2 | * ESPRESSIF MIT License 3 | * 4 | * Copyright (c) 2020 5 | * 6 | * Permission is hereby granted for use on ESPRESSIF SYSTEMS products only, in which case, 7 | * it is free of charge, to any person obtaining a copy of this software and associated 8 | * documentation files (the "Software"), to deal in the Software without restriction, including 9 | * without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, 10 | * and/or sell copies of the Software, and to permit persons to whom the Software is furnished 11 | * to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all copies or 14 | * 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, FITNESS 18 | * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 19 | * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 20 | * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 21 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 22 | * 23 | */ 24 | #ifndef _HAP_BCT_PRIV_H_ 25 | #define _HAP_BCT_PRIV_H_ 26 | void hap_handle_bct_change_name(); 27 | void hap_handle_hot_plug(); 28 | #endif /* _HAP_BCT_PRIV_H_ */ 29 | -------------------------------------------------------------------------------- /components/homekit/esp_hap_core/src/priv_includes/esp_hap_char.h: -------------------------------------------------------------------------------- 1 | /* 2 | * ESPRESSIF MIT License 3 | * 4 | * Copyright (c) 2020 5 | * 6 | * Permission is hereby granted for use on ESPRESSIF SYSTEMS products only, in which case, 7 | * it is free of charge, to any person obtaining a copy of this software and associated 8 | * documentation files (the "Software"), to deal in the Software without restriction, including 9 | * without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, 10 | * and/or sell copies of the Software, and to permit persons to whom the Software is furnished 11 | * to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all copies or 14 | * 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, FITNESS 18 | * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 19 | * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 20 | * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 21 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 22 | * 23 | */ 24 | 25 | #ifndef _HAP_CHAR_H_ 26 | #define _HAP_CHAR_H_ 27 | 28 | #include 29 | #include 30 | #include 31 | 32 | #include 33 | #include 34 | 35 | #ifdef __cplusplus 36 | extern "C" { 37 | #endif 38 | #define HAP_CHAR_MIN_FLAG (1 << 0) 39 | #define HAP_CHAR_MAX_FLAG (1 << 1) 40 | #define HAP_CHAR_STEP_FLAG (1 << 2) 41 | #define HAP_CHAR_MAXLEN_FLAG (1 << 3) 42 | #define HAP_CHAR_MAXDATALEN_FLAG (1 << 4) 43 | 44 | /** 45 | * @brief characteristics object information 46 | */ 47 | typedef struct { 48 | uint32_t iid; /* Characteristic instance ID */ 49 | const char *type_uuid; /* Apple's characteristic UUID */ 50 | uint16_t permission; /* Characteristic permission */ 51 | hap_char_format_t format; /* data type of the value */ 52 | hap_val_t val; 53 | bool ev; /* check if characteristics supports event */ 54 | char *description; /* characteristics's description */ 55 | char *unit; 56 | 57 | /* Characteristics's father subsystem */ 58 | hap_serv_t *parent; 59 | 60 | uint8_t constraint_flags; 61 | 62 | hap_val_t max; /* maximum value, maxlen, max data len*/ 63 | hap_val_t min; /* minimum value */ 64 | hap_val_t step; /* step value */ 65 | 66 | hap_char_t *next_char; 67 | /* Bitmap to indicate which controllers have enabled notifications 68 | */ 69 | uint16_t ev_ctrls; 70 | 71 | /* Bitmap indicating the last controller that modified the value. 72 | * No notification should be sent to the owner 73 | */ 74 | uint16_t owner_ctrl; 75 | 76 | /* Pointer to a valid values range. It will be a 2 byte array, if set from application */ 77 | uint8_t *valid_vals_range; 78 | /* Since a list of valid values can have any length, using a pointer here, 79 | * which will be allocated if valid values are set for a characteristic 80 | */ 81 | uint8_t *valid_vals; 82 | size_t valid_vals_cnt; 83 | bool update_called; 84 | } __hap_char_t; 85 | 86 | void hap_char_manage_notification(hap_char_t *hc, int index, bool ev); 87 | bool hap_char_is_ctrl_subscribed(hap_char_t *hc, int index); 88 | void hap_char_set_owner_ctrl(hap_char_t *hc, int index); 89 | bool hap_char_is_ctrl_owner(hap_char_t *hc, int index); 90 | void hap_disable_all_char_notif(int index); 91 | int hap_char_check_val_constraints(__hap_char_t *_hc, hap_val_t *val); 92 | int hap_event_queue_init(); 93 | int hap_event_queue_deinit(); 94 | hap_char_t * hap_get_pending_notif_char(); 95 | #ifdef __cplusplus 96 | } 97 | #endif 98 | 99 | #endif /* _HAP_CHAR_H_ */ 100 | -------------------------------------------------------------------------------- /components/homekit/esp_hap_core/src/priv_includes/esp_hap_controllers.h: -------------------------------------------------------------------------------- 1 | /* 2 | * ESPRESSIF MIT License 3 | * 4 | * Copyright (c) 2020 5 | * 6 | * Permission is hereby granted for use on ESPRESSIF SYSTEMS products only, in which case, 7 | * it is free of charge, to any person obtaining a copy of this software and associated 8 | * documentation files (the "Software"), to deal in the Software without restriction, including 9 | * without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, 10 | * and/or sell copies of the Software, and to permit persons to whom the Software is furnished 11 | * to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all copies or 14 | * 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, FITNESS 18 | * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 19 | * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 20 | * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 21 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 22 | * 23 | */ 24 | #ifndef _HAP_CONTROLLERS_H_ 25 | #define _HAP_CONTROLLERS_H_ 26 | 27 | #include 28 | #include 29 | 30 | #define HAP_MAX_CONTROLLERS 16 31 | #define HAP_CTRL_ID_LEN 64 32 | #define ED_KEY_LEN 32 33 | 34 | 35 | typedef struct { 36 | char id[HAP_CTRL_ID_LEN]; 37 | uint8_t ltpk[ED_KEY_LEN]; 38 | uint8_t perms; 39 | } __attribute__((packed)) hap_ctrl_info_t; 40 | 41 | typedef struct { 42 | hap_ctrl_info_t info; 43 | /* If "valid" is false, it means that the entry is invalid, 44 | * irrespective of the values of other members, and can be 45 | * used to store new controller info 46 | */ 47 | bool valid; 48 | /* Index is used just for better managing the keystore data */ 49 | uint8_t index; 50 | } hap_ctrl_data_t; 51 | 52 | int hap_controllers_init(); 53 | bool is_accessory_paired(); 54 | bool is_admin_paired(); 55 | hap_ctrl_data_t *hap_controller_get_empty_loc(); 56 | int hap_controller_save(hap_ctrl_data_t *ctrl_data); 57 | void hap_controller_remove(hap_ctrl_data_t *ctrl_data); 58 | hap_ctrl_data_t *hap_get_controller(char *ctrl_id); 59 | void hap_erase_controller_info(); 60 | 61 | #endif /* _HAP_CONTROLLERS_H_ */ 62 | -------------------------------------------------------------------------------- /components/homekit/esp_hap_core/src/priv_includes/esp_hap_database.h: -------------------------------------------------------------------------------- 1 | /* 2 | * ESPRESSIF MIT License 3 | * 4 | * Copyright (c) 2020 5 | * 6 | * Permission is hereby granted for use on ESPRESSIF SYSTEMS products only, in which case, 7 | * it is free of charge, to any person obtaining a copy of this software and associated 8 | * documentation files (the "Software"), to deal in the Software without restriction, including 9 | * without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, 10 | * and/or sell copies of the Software, and to permit persons to whom the Software is furnished 11 | * to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all copies or 14 | * 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, FITNESS 18 | * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 19 | * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 20 | * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 21 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 22 | * 23 | */ 24 | #ifndef _HAP_DATABASE_H_ 25 | #define _HAP_DATABASE_H_ 26 | 27 | #include 28 | #include 29 | #include 30 | #include 31 | #include 32 | #include 33 | #include 34 | #include 35 | 36 | #define HAP_KEYSTORE_NAMESPACE_HAPMAIN "hap_main" 37 | #define HAP_FACTORY_NAMESPACE_HAP_SETUP "hap_setup" 38 | 39 | #define HAP_MAX_SESSIONS 8 40 | #define SETUP_ID_LEN 4 41 | #define SETUP_HASH_LEN 4 42 | 43 | #define HAP_ACC_ID_LEN 18 /* AA:BB:CC:XX:YY:ZZ\0 */ 44 | #define ED_KEY_LEN 32 45 | #define HAP_SW_TOKEN_MAX_LEN 1200 46 | 47 | 48 | typedef struct { 49 | hap_acc_cfg_t primary_acc; 50 | uint32_t config_num; 51 | uint32_t cur_aid; 52 | uint8_t raw_acc_id[6]; 53 | char acc_id[HAP_ACC_ID_LEN]; 54 | char setup_id[SETUP_ID_LEN + 1]; 55 | uint8_t setup_hash[SETUP_HASH_LEN]; 56 | char setup_hash_str[SETUP_HASH_LEN * 2 + 1]; 57 | uint8_t ltska[ED_KEY_LEN]; 58 | uint8_t ltpka[ED_KEY_LEN]; 59 | hap_cid_t cid; 60 | hap_ctrl_data_t controllers[HAP_MAX_CONTROLLERS]; 61 | hap_secure_session_t *sessions[HAP_MAX_SESSIONS]; 62 | uint8_t pair_attempts; 63 | hap_mdns_handle_t wac_mdns_handle; 64 | hap_mdns_handle_t hap_mdns_handle; 65 | hap_setup_info_t *setup_info; 66 | char *setup_code; 67 | char *ssid; 68 | char *password; 69 | hap_software_token_info_t *token_info; 70 | uint8_t features; 71 | hap_event_handler_t hap_event_handler; 72 | char *softap_ssid; 73 | void (*ext_nw_prov_start)(void *data, const char *name); 74 | void (*ext_nw_prov_stop)(void *data); 75 | void *ext_nw_prov_data; 76 | hap_cfg_t cfg; 77 | hap_transport_t transport; 78 | uint32_t pairing_flags; 79 | httpd_handle_t server; 80 | uint8_t *product_data; 81 | uint16_t state_num; 82 | bool disconnected_event_sent; 83 | hap_mfi_auth_type_t auth_type; 84 | TimerHandle_t pairing_mode_timer; 85 | } hap_priv_t; 86 | 87 | extern hap_priv_t hap_priv; 88 | int hap_database_init(void); 89 | char *hap_get_acc_id(); 90 | int hap_get_next_aid(); 91 | int hap_acc_setup_init(); 92 | void hap_erase_accessory_info(); 93 | void hap_increment_and_save_config_num(); 94 | void hap_increment_and_save_state_num(); 95 | #endif /* _HAP_DATABASE_H_ */ 96 | -------------------------------------------------------------------------------- /components/homekit/esp_hap_core/src/priv_includes/esp_hap_ip_services.h: -------------------------------------------------------------------------------- 1 | /* 2 | * ESPRESSIF MIT License 3 | * 4 | * Copyright (c) 2020 5 | * 6 | * Permission is hereby granted for use on ESPRESSIF SYSTEMS products only, in which case, 7 | * it is free of charge, to any person obtaining a copy of this software and associated 8 | * documentation files (the "Software"), to deal in the Software without restriction, including 9 | * without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, 10 | * and/or sell copies of the Software, and to permit persons to whom the Software is furnished 11 | * to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all copies or 14 | * 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, FITNESS 18 | * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 19 | * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 20 | * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 21 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 22 | * 23 | */ 24 | #ifndef _HAP_IP_SERVICES_H_ 25 | #define _HAP_IP_SERVICES_H_ 26 | #include 27 | #include 28 | int hap_http_session_not_authorized(httpd_req_t *req); 29 | int hap_httpd_get_data(httpd_req_t *req, char *buffer, int len); 30 | int hap_httpd_start(); 31 | int hap_httpd_stop(); 32 | int hap_ip_services_start(); 33 | int hap_ip_services_stop(); 34 | int hap_mdns_announce(bool first); 35 | int hap_mdns_deannounce(); 36 | void hap_http_send_notif(); 37 | #endif /* _HAP_IP_SERVICES_H_ */ 38 | -------------------------------------------------------------------------------- /components/homekit/esp_hap_core/src/priv_includes/esp_hap_keystore.h: -------------------------------------------------------------------------------- 1 | /* 2 | * ESPRESSIF MIT License 3 | * 4 | * Copyright (c) 2020 5 | * 6 | * Permission is hereby granted for use on ESPRESSIF SYSTEMS products only, in which case, 7 | * it is free of charge, to any person obtaining a copy of this software and associated 8 | * documentation files (the "Software"), to deal in the Software without restriction, including 9 | * without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, 10 | * and/or sell copies of the Software, and to permit persons to whom the Software is furnished 11 | * to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all copies or 14 | * 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, FITNESS 18 | * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 19 | * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 20 | * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 21 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 22 | * 23 | */ 24 | #ifndef _HAP_KEYSTORE_H_ 25 | #define _HAP_KEYSTORE_H_ 26 | #include 27 | int hap_keystore_init(); 28 | int hap_keystore_get(const char *name_space, const char *key, uint8_t *val, size_t *val_size); 29 | int hap_keystore_set(const char *name_space, const char *key, const uint8_t *val, const size_t val_len); 30 | int hap_keystore_delete(const char *name_space, const char *key); 31 | int hap_keystore_delete_namespace(const char *name_space); 32 | int hap_factory_keystore_set(const char *name_space, const char *key, const uint8_t *val, const size_t val_len); 33 | void hap_keystore_erase_all_data(); 34 | #endif /* _HAP_KEYSTORE_H_ */ 35 | -------------------------------------------------------------------------------- /components/homekit/esp_hap_core/src/priv_includes/esp_hap_main.h: -------------------------------------------------------------------------------- 1 | /* 2 | * ESPRESSIF MIT License 3 | * 4 | * Copyright (c) 2020 5 | * 6 | * Permission is hereby granted for use on ESPRESSIF SYSTEMS products only, in which case, 7 | * it is free of charge, to any person obtaining a copy of this software and associated 8 | * documentation files (the "Software"), to deal in the Software without restriction, including 9 | * without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, 10 | * and/or sell copies of the Software, and to permit persons to whom the Software is furnished 11 | * to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all copies or 14 | * 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, FITNESS 18 | * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 19 | * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 20 | * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 21 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 22 | * 23 | */ 24 | 25 | #ifndef _HAP_MAIN_LOOP_H_ 26 | #define _HAP_MAIN_LOOP_H_ 27 | #include 28 | #include 29 | 30 | #define HAP_FF_HARDWARE_AUTH 0x01 31 | #define HAP_FF_SW_TOKEN_AUTH 0x02 32 | 33 | 34 | #define HAP_SF_ACC_UNPAIRED 0x01 35 | #define HAP_SF_ACC_UNCONFIGURED 0x02 36 | #define HAP_SF_PROBLEM_DETECTED 0x04 37 | 38 | typedef enum { 39 | HAP_INTERNAL_EVENT_LOOP_STOP = 1, 40 | HAP_INTERNAL_EVENT_ACC_PAIRED, 41 | HAP_INTERNAL_EVENT_ACC_UNPAIRED, 42 | HAP_INTERNAL_EVENT_CONFIG_NUM_UPDATED, 43 | HAP_INTERNAL_EVENT_BCT_CHANGE_NAME, 44 | HAP_INTERNAL_EVENT_BCT_HOT_PLUG, 45 | HAP_INTERNAL_EVENT_RESET_PAIRINGS, 46 | HAP_INTERNAL_EVENT_RESET_TO_FACTORY, 47 | HAP_INTERNAL_EVENT_REBOOT, 48 | HAP_INTERNAL_EVENT_RESET_NETWORK, 49 | HAP_INTERNAL_EVENT_TRIGGER_NOTIF, 50 | HAP_INTERNAL_EVENT_RESET_HOMEKIT_DATA, 51 | HAP_INTERNAL_EVENT_NETWORK_SWITCH, 52 | HAP_INTERNAL_EVENT_NETWORK_REVERT, 53 | } hap_internal_event_t; 54 | 55 | typedef struct { 56 | hap_internal_event_t event; 57 | } hap_event_ctx_t; 58 | 59 | typedef enum { 60 | HAP_STATE_NONE = 0, 61 | HAP_STATE_NW_UNCONFIGURED, 62 | HAP_STATE_NW_CONFIGURED, 63 | } hap_state_t; 64 | 65 | int hap_loop_start(); 66 | int hap_loop_stop(); 67 | int hap_send_event(hap_internal_event_t event); 68 | int hap_update_config_number(); 69 | bool is_hap_loop_started(); 70 | void hap_report_event(hap_event_t event, void *data, size_t data_size); 71 | int hap_enable_hw_auth(void); 72 | int hap_enable_sw_auth(void); 73 | int hap_trigger_network_switch(void); 74 | int hap_trigger_network_revert(void); 75 | 76 | #endif /* _HAP_MAIN_LOOP_H_ */ 77 | -------------------------------------------------------------------------------- /components/homekit/esp_hap_core/src/priv_includes/esp_hap_mdns.h: -------------------------------------------------------------------------------- 1 | /* 2 | * ESPRESSIF MIT License 3 | * 4 | * Copyright (c) 2020 5 | * 6 | * Permission is hereby granted for use on ESPRESSIF SYSTEMS products only, in which case, 7 | * it is free of charge, to any person obtaining a copy of this software and associated 8 | * documentation files (the "Software"), to deal in the Software without restriction, including 9 | * without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, 10 | * and/or sell copies of the Software, and to permit persons to whom the Software is furnished 11 | * to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all copies or 14 | * 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, FITNESS 18 | * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 19 | * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 20 | * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 21 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 22 | * 23 | */ 24 | #ifndef _HAP_MDNS_H_ 25 | #define _HAP_MDNS_H_ 26 | 27 | #include 28 | #include 29 | 30 | typedef struct { 31 | char type[32]; 32 | char proto[32]; 33 | } hap_mdns_handle_t; 34 | 35 | int hap_mdns_serv_start(hap_mdns_handle_t *handle, const char *name, const char *type, 36 | const char *protocol, int port, mdns_txt_item_t *txt_records, size_t num_txt); 37 | int hap_mdns_serv_update_txt(hap_mdns_handle_t *handle, mdns_txt_item_t *txt_records, size_t num_txt); 38 | int hap_mdns_serv_name_change(hap_mdns_handle_t *handle, const char * instance_name); 39 | int hap_mdns_serv_stop(hap_mdns_handle_t *handle); 40 | int hap_mdns_init(); 41 | int hap_mdns_deinit(); 42 | 43 | #endif /* _HAP_MDNS_H_ */ 44 | -------------------------------------------------------------------------------- /components/homekit/esp_hap_core/src/priv_includes/esp_hap_network_io.h: -------------------------------------------------------------------------------- 1 | /* 2 | * ESPRESSIF MIT License 3 | * 4 | * Copyright (c) 2020 5 | * 6 | * Permission is hereby granted for use on ESPRESSIF SYSTEMS products only, in which case, 7 | * it is free of charge, to any person obtaining a copy of this software and associated 8 | * documentation files (the "Software"), to deal in the Software without restriction, including 9 | * without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, 10 | * and/or sell copies of the Software, and to permit persons to whom the Software is furnished 11 | * to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all copies or 14 | * 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, FITNESS 18 | * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 19 | * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 20 | * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 21 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 22 | * 23 | */ 24 | #ifndef _HAP_NETWORK_IO_H_ 25 | #define _HAP_NETWORK_IO_H_ 26 | #include 27 | #include 28 | int hap_httpd_send(httpd_handle_t hd, int sockfd, const char *buf, unsigned buf_len, int flags); 29 | int hap_httpd_recv(httpd_handle_t hd, int sockfd, char *buf, unsigned buf_len, int flags); 30 | 31 | #endif /* _HAP_NETWORK_IO_H_ */ 32 | -------------------------------------------------------------------------------- /components/homekit/esp_hap_core/src/priv_includes/esp_hap_pair_common.h: -------------------------------------------------------------------------------- 1 | /* 2 | * ESPRESSIF MIT License 3 | * 4 | * Copyright (c) 2020 5 | * 6 | * Permission is hereby granted for use on ESPRESSIF SYSTEMS products only, in which case, 7 | * it is free of charge, to any person obtaining a copy of this software and associated 8 | * documentation files (the "Software"), to deal in the Software without restriction, including 9 | * without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, 10 | * and/or sell copies of the Software, and to permit persons to whom the Software is furnished 11 | * to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all copies or 14 | * 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, FITNESS 18 | * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 19 | * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 20 | * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 21 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 22 | * 23 | */ 24 | #ifndef _HAP_PAIR_COMMON_H_ 25 | #define _HAP_PAIR_COMMON_H_ 26 | 27 | #include 28 | #include 29 | #define ENCRYPT_KEY_LEN 32 30 | #define POLY_AUTHTAG_LEN 16 31 | #define CURVE_KEY_LEN 32 32 | #define ED_SIGN_LEN 64 33 | #define NONCE_LEN 8 34 | 35 | #define STATE_M0 0 36 | #define STATE_M1 1 37 | #define STATE_M2 2 38 | #define STATE_M3 3 39 | #define STATE_M4 4 40 | #define STATE_M5 5 41 | #define STATE_M6 6 42 | #define STATE_VERIFIED 0x55 43 | #define STATE_INVALID 0xaa 44 | 45 | #define PROCESS_PAIR_SETUP 0x33 46 | #define PROCESS_PAIR_VERIFY 0xcc 47 | 48 | typedef enum { 49 | HAP_METHOD_RESERVED = 0, 50 | HAP_METHOD_PAIR_SETUP = 1, 51 | HAP_METHOD_PAIR_VERIFY = 2, 52 | HAP_METHOD_ADD_PAIRING = 3, 53 | HAP_METHOD_REMOVE_PAIRING = 4, 54 | HAP_METHOD_LIST_PAIRINGS = 5, 55 | } hap_pairing_methods_t; 56 | 57 | 58 | typedef enum { 59 | kTLVError_Unknown = 0x01, 60 | kTLVError_Authentication = 0x02, 61 | kTLVError_Backoff = 0x03, 62 | kTLVError_MaxPeers = 0x04, 63 | kTLVError_MaxTries = 0x05, 64 | kTLVError_Unavailable = 0x06, 65 | kTLVError_Busy = 0x07, 66 | } hap_tlv_error_t; 67 | 68 | typedef enum { 69 | kTLVType_Method = 0x00, 70 | kTLVType_Identifier = 0x01, 71 | kTLVType_Salt = 0x02, 72 | kTLVType_PublicKey = 0x03, 73 | kTLVType_Proof = 0x04, 74 | kTLVType_EncryptedData = 0x05, 75 | kTLVType_State = 0x06, 76 | kTLVType_Error = 0x07, 77 | kTLVType_RetryDelay = 0x08, 78 | kTLVType_Certificate = 0x09, 79 | kTLVType_Signature = 0x0a, 80 | kTLVType_Permissions = 0x0b, 81 | kTLVType_FragmentedData = 0x0c, 82 | kTLVType_FragmentLast = 0x0d, 83 | kTLVType_Flags = 0x13, 84 | kTLVType_OwnershipProofToken = 0x1A, 85 | kTLVType_ProductData = 0x1C, 86 | kTLVType_Separator = 0xff, 87 | } hap_tlv_type_t; 88 | 89 | typedef struct { 90 | uint8_t *bufptr; 91 | int bufsize; 92 | int curlen; 93 | } hap_tlv_data_t; 94 | 95 | typedef struct { 96 | uint8_t state; 97 | uint8_t encrypt_key[ENCRYPT_KEY_LEN]; 98 | uint8_t decrypt_key[ENCRYPT_KEY_LEN]; 99 | uint8_t encrypt_nonce[NONCE_LEN]; 100 | uint8_t decrypt_nonce[NONCE_LEN]; 101 | hap_ctrl_data_t *ctrl; 102 | uint64_t pid; 103 | int64_t ttl; 104 | int64_t prepare_time; 105 | /* TODO: As of now, this identifier will be the socket 106 | * number, since only http is supported. 107 | * Need to make this generic later. 108 | */ 109 | int conn_identifier; 110 | } hap_secure_session_t; 111 | 112 | void hap_tlv_data_init(hap_tlv_data_t *tlv_data, uint8_t *buf, int buf_size); 113 | int get_value_from_tlv(uint8_t *buf, int buf_len, uint8_t type, void *val, int val_size); 114 | int get_tlv_length(uint8_t *buf, int buflen, uint8_t type); 115 | int add_tlv(hap_tlv_data_t *tlv_data, uint8_t type, int len, void *val); 116 | void hap_prepare_error_tlv(uint8_t state, uint8_t error, void *buf, int buf_size, int *out_len); 117 | #endif /* _HAP_PAIR_COMMON_H_ */ 118 | -------------------------------------------------------------------------------- /components/homekit/esp_hap_core/src/priv_includes/esp_hap_pair_setup.h: -------------------------------------------------------------------------------- 1 | /* 2 | * ESPRESSIF MIT License 3 | * 4 | * Copyright (c) 2020 5 | * 6 | * Permission is hereby granted for use on ESPRESSIF SYSTEMS products only, in which case, 7 | * it is free of charge, to any person obtaining a copy of this software and associated 8 | * documentation files (the "Software"), to deal in the Software without restriction, including 9 | * without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, 10 | * and/or sell copies of the Software, and to permit persons to whom the Software is furnished 11 | * to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all copies or 14 | * 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, FITNESS 18 | * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 19 | * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 20 | * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 21 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 22 | * 23 | */ 24 | #ifndef _HAP_PAIR_SETUP_H_ 25 | #define _HAP_PAIR_SETUP_H_ 26 | #include 27 | #include 28 | #include 29 | #include 30 | #include 31 | 32 | #define PS_NONCE1 "PS-Msg04" 33 | #define PS_NONCE2 "PS-Msg05" 34 | #define PS_NONCE3 "PS-Msg06" 35 | 36 | #define PAIR_FLAG_TRANSIENT 0x00000010 37 | #define PAIR_FLAG_SPLIT 0x01000000 38 | 39 | 40 | typedef struct { 41 | uint8_t state; 42 | uint8_t process; 43 | uint8_t method; 44 | uint32_t pairing_flags; 45 | int8_t pairing_flags_len; 46 | int len_s; 47 | char *bytes_s; 48 | int secret_len; 49 | char *shared_secret; 50 | mu_srp_handle_t srp_hd; 51 | hap_ctrl_data_t *ctrl; 52 | uint8_t session_key[32]; 53 | TimerHandle_t timer; 54 | hap_secure_session_t *session; 55 | int sock_fd; 56 | } pair_setup_ctx_t; 57 | int hap_pair_setup_context_init(int sock_fd, void **ctx, uint8_t *buf, int bufsize, int *outlen); 58 | int hap_pair_setup_process(void **ctx, uint8_t *buf, int inlen, int bufsize, int *outlen); 59 | void hap_pair_setup_ctx_clean(void *sess_ctx); 60 | int hap_pair_setup_manage_mfi_auth(pair_setup_ctx_t *ps_ctx, hap_tlv_data_t *tlv_data, hap_tlv_error_t *tlv_error); 61 | void hap_start_pairing_mode_timer(void); 62 | #endif /* _HAP_PAIR_SETUP_H_ */ 63 | -------------------------------------------------------------------------------- /components/homekit/esp_hap_core/src/priv_includes/esp_hap_pair_verify.h: -------------------------------------------------------------------------------- 1 | /* 2 | * ESPRESSIF MIT License 3 | * 4 | * Copyright (c) 2020 5 | * 6 | * Permission is hereby granted for use on ESPRESSIF SYSTEMS products only, in which case, 7 | * it is free of charge, to any person obtaining a copy of this software and associated 8 | * documentation files (the "Software"), to deal in the Software without restriction, including 9 | * without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, 10 | * and/or sell copies of the Software, and to permit persons to whom the Software is furnished 11 | * to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all copies or 14 | * 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, FITNESS 18 | * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 19 | * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 20 | * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 21 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 22 | * 23 | */ 24 | #ifndef _HAP_PAIR_VERIFY_H_ 25 | #define _HAP_PAIR_VERIFY_H_ 26 | #include 27 | #include 28 | int hap_pair_verify_context_init(void **ctx, uint8_t *buf, int bufsize, int *outlen); 29 | void hap_pair_verify_context_deinit(void *pv_ctx); 30 | int hap_pair_verify_process(void **ctx, uint8_t *buf, int inlen, int bufsize, int *outlen); 31 | uint8_t hap_pair_verify_get_state(void *ctx); 32 | void hap_free_session(void *session); 33 | int hap_get_ctrl_session_index(hap_secure_session_t *session); 34 | int hap_close_session(hap_secure_session_t *session); 35 | void hap_close_sessions_of_ctrl(hap_ctrl_data_t *ctrl); 36 | void hap_close_all_sessions(); 37 | #endif /* _HAP_PAIR_VERIFY_H_ */ 38 | -------------------------------------------------------------------------------- /components/homekit/esp_hap_core/src/priv_includes/esp_hap_pairings.h: -------------------------------------------------------------------------------- 1 | /* 2 | * ESPRESSIF MIT License 3 | * 4 | * Copyright (c) 2020 5 | * 6 | * Permission is hereby granted for use on ESPRESSIF SYSTEMS products only, in which case, 7 | * it is free of charge, to any person obtaining a copy of this software and associated 8 | * documentation files (the "Software"), to deal in the Software without restriction, including 9 | * without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, 10 | * and/or sell copies of the Software, and to permit persons to whom the Software is furnished 11 | * to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all copies or 14 | * 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, FITNESS 18 | * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 19 | * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 20 | * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 21 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 22 | * 23 | */ 24 | #ifndef _HAP_PAIRINGS_H_ 25 | #define _HAP_PAIRINGS_H_ 26 | #include 27 | int hap_pairings_process(void *ctx, uint8_t *buf, int inlen, int bufsize, int *outlen); 28 | bool hap_is_req_secure(hap_secure_session_t *session); 29 | #endif /* _HAP_PAIRINGS_H_ */ 30 | -------------------------------------------------------------------------------- /components/homekit/esp_hap_core/src/priv_includes/esp_hap_secure_message.h: -------------------------------------------------------------------------------- 1 | /* 2 | * ESPRESSIF MIT License 3 | * 4 | * Copyright (c) 2020 5 | * 6 | * Permission is hereby granted for use on ESPRESSIF SYSTEMS products only, in which case, 7 | * it is free of charge, to any person obtaining a copy of this software and associated 8 | * documentation files (the "Software"), to deal in the Software without restriction, including 9 | * without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, 10 | * and/or sell copies of the Software, and to permit persons to whom the Software is furnished 11 | * to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all copies or 14 | * 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, FITNESS 18 | * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 19 | * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 20 | * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 21 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 22 | * 23 | */ 24 | #ifndef _HAP_SECURE_MESSAGE_H_ 25 | #define _HAP_SECURE_MESSAGE_H_ 26 | #include 27 | #include 28 | /** Information for Software Token based authentication. 29 | * To be used only if MFi chip is not present on the accessory 30 | */ 31 | typedef struct { 32 | /** UUID for the accessory */ 33 | uint8_t uuid[16]; 34 | /** Token associated with the UUID */ 35 | uint8_t *token; 36 | /* Length of the above token */ 37 | size_t token_len; 38 | } hap_software_token_info_t; 39 | 40 | int hap_register_secure_message_handler(httpd_handle_t handle); 41 | int hap_unregister_secure_message_handler(httpd_handle_t handle); 42 | #endif /* _HAP_SECURE_MESSAGE_H_ */ 43 | -------------------------------------------------------------------------------- /components/homekit/esp_hap_core/src/priv_includes/esp_hap_serv.h: -------------------------------------------------------------------------------- 1 | /* 2 | * ESPRESSIF MIT License 3 | * 4 | * Copyright (c) 2020 5 | * 6 | * Permission is hereby granted for use on ESPRESSIF SYSTEMS products only, in which case, 7 | * it is free of charge, to any person obtaining a copy of this software and associated 8 | * documentation files (the "Software"), to deal in the Software without restriction, including 9 | * without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, 10 | * and/or sell copies of the Software, and to permit persons to whom the Software is furnished 11 | * to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all copies or 14 | * 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, FITNESS 18 | * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 19 | * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 20 | * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 21 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 22 | * 23 | */ 24 | 25 | #ifndef _HAP_SERV_H_ 26 | #define _HAP_SERV_H_ 27 | 28 | #include 29 | #include 30 | #include 31 | 32 | #ifdef __cplusplus 33 | extern "C" { 34 | #endif 35 | 36 | typedef struct hap_linked_serv { 37 | hap_serv_t *hs; 38 | struct hap_linked_serv *next; 39 | } hap_linked_serv_t; 40 | 41 | typedef struct hap_linked_serv hap_linked_serv_t; 42 | 43 | /** 44 | * HAP service information 45 | */ 46 | typedef struct { 47 | char *type_uuid; /* String that defines the type of the service. */ 48 | 49 | uint32_t iid; /* service instance ID */ 50 | 51 | bool hidden; /* If set it to be True, the service is not visible to user. */ 52 | bool primary; /* If set it to be True, this is the primary service of the accessory. */ 53 | 54 | /** 55 | * List of Characteristic objects. Must not be empty. The maximum number of characteristics 56 | * allowed is 100, and each characteristic in the array must have a unique type. 57 | */ 58 | hap_char_t *chars; 59 | hap_acc_t *parent; 60 | hap_serv_t *next_serv; 61 | 62 | hap_serv_write_t write_cb; 63 | hap_serv_read_t read_cb; 64 | hap_serv_bulk_read_t bulk_read; 65 | hap_linked_serv_t *linked_servs; 66 | void *priv; 67 | } __hap_serv_t; 68 | 69 | bool hap_serv_get_hidden(hap_serv_t *hs); 70 | bool hap_serv_get_primary(hap_serv_t *hs); 71 | hap_char_t *hap_serv_get_char_by_iid(hap_serv_t *hs, int32_t iid); 72 | char *hap_serv_get_uuid(hap_serv_t *hs); 73 | hap_serv_t *hap_serv_create(char *type_uuid); 74 | void hap_serv_delete(hap_serv_t *hs); 75 | int hap_serv_add_char(hap_serv_t *hs, hap_char_t *hc); 76 | #ifdef __cplusplus 77 | } 78 | #endif 79 | 80 | #endif /* _HAP_SERV_H_ */ 81 | -------------------------------------------------------------------------------- /components/homekit/esp_hap_core/src/priv_includes/esp_hap_wac.h: -------------------------------------------------------------------------------- 1 | /* 2 | * ESPRESSIF MIT License 3 | * 4 | * Copyright (c) 2020 5 | * 6 | * Permission is hereby granted for use on ESPRESSIF SYSTEMS products only, in which case, 7 | * it is free of charge, to any person obtaining a copy of this software and associated 8 | * documentation files (the "Software"), to deal in the Software without restriction, including 9 | * without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, 10 | * and/or sell copies of the Software, and to permit persons to whom the Software is furnished 11 | * to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all copies or 14 | * 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, FITNESS 18 | * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 19 | * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 20 | * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 21 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 22 | * 23 | */ 24 | 25 | #ifndef _HAP_WAC_H_ 26 | #define _HAP_WAC_H_ 27 | int hap_wac_start(void); 28 | int hap_wac2_network_switch(void); 29 | int hap_wac2_finish(void); 30 | int hap_wac2_stop(void); 31 | bool hap_is_mfi_auth_enabled(); 32 | #endif /* _HAP_WAC_H_ */ 33 | -------------------------------------------------------------------------------- /components/homekit/esp_hap_core/src/priv_includes/esp_hap_wifi.h: -------------------------------------------------------------------------------- 1 | /* 2 | * ESPRESSIF MIT License 3 | * 4 | * Copyright (c) 2020 5 | * 6 | * Permission is hereby granted for use on ESPRESSIF SYSTEMS products only, in which case, 7 | * it is free of charge, to any person obtaining a copy of this software and associated 8 | * documentation files (the "Software"), to deal in the Software without restriction, including 9 | * without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, 10 | * and/or sell copies of the Software, and to permit persons to whom the Software is furnished 11 | * to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all copies or 14 | * 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, FITNESS 18 | * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 19 | * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 20 | * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 21 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 22 | * 23 | */ 24 | #ifndef _HAP_WIFI_H_ 25 | #define _HAP_WIFI_H_ 26 | #include 27 | #include 28 | bool hap_is_network_configured(); 29 | void hap_wifi_restart(); 30 | void hap_erase_network_info(); 31 | esp_err_t hap_wifi_sta_switch(wifi_config_t *config); 32 | esp_err_t hap_wifi_config_sta_connect(void); 33 | esp_err_t hap_wifi_config_revert_network(void); 34 | #endif /* _HAP_WIFI_H_ */ 35 | -------------------------------------------------------------------------------- /components/homekit/esp_hap_core/src/priv_includes/hexbin.h: -------------------------------------------------------------------------------- 1 | // Copyright 2020 Espressif Systems (Shanghai) PTE LTD 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 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | #ifndef _HEXBIN_H_ 15 | #define _HEXBIN_H_ 16 | #include 17 | #include 18 | int hex2bin(const char *ihex, size_t ilen, uint8_t *obin, size_t *olen); 19 | #endif /* _HEXBIN_H_ */ 20 | -------------------------------------------------------------------------------- /components/homekit/esp_hap_core/src/priv_includes/hexdump.h: -------------------------------------------------------------------------------- 1 | // Copyright 2020 Espressif Systems (Shanghai) PTE LTD 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 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | #ifndef _HEXDUMP_H_ 15 | #define _HEXDUMP_H_ 16 | void hex_dbg_with_name(char *name, unsigned char *buf, int buf_len); 17 | 18 | #endif /* _HEXDUMP_H_ */ 19 | -------------------------------------------------------------------------------- /components/homekit/esp_hap_extras/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | set(COMPONENT_ADD_INCLUDEDIRS include) 2 | 3 | # Edit following two lines to set component requirements (see docs) 4 | set(COMPONENT_REQUIRES esp_hap_core) 5 | set(COMPONENT_PRIV_REQUIRES esp_http_server esp_https_ota esp_hap_platform app_update) 6 | 7 | set(COMPONENT_SRCS src/hap_bct_http_handlers.c src/hap_fw_upgrade.c) 8 | 9 | register_component() 10 | component_compile_options(-Wno-unused-function) 11 | -------------------------------------------------------------------------------- /components/homekit/esp_hap_extras/component.mk: -------------------------------------------------------------------------------- 1 | # 2 | # Component Makefile 3 | # 4 | CFLAGS += -Wno-unused-function 5 | COMPONENT_SRCDIRS := src 6 | COMPONENT_ADD_INCLUDEDIRS := include 7 | -------------------------------------------------------------------------------- /components/homekit/esp_hap_extras/include/hap_bct_http_handlers.h: -------------------------------------------------------------------------------- 1 | /* 2 | * ESPRESSIF MIT License 3 | * 4 | * Copyright (c) 2020 5 | * 6 | * Permission is hereby granted for use on ESPRESSIF SYSTEMS products only, in which case, 7 | * it is free of charge, to any person obtaining a copy of this software and associated 8 | * documentation files (the "Software"), to deal in the Software without restriction, including 9 | * without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, 10 | * and/or sell copies of the Software, and to permit persons to whom the Software is furnished 11 | * to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all copies or 14 | * 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, FITNESS 18 | * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 19 | * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 20 | * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 21 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 22 | * 23 | */ 24 | 25 | /* BCT HTTP Handlers 26 | */ 27 | #ifndef _HAP_BCT_HTTP_HANDLERS_H_ 28 | #define _HAP_BCT_HTTP_HANDLERS_H_ 29 | 30 | #ifdef __cplusplus 31 | extern "C" { 32 | #endif 33 | 34 | /** 35 | * @brief Register web handlers for tester interaction steps of Bonjour Conformance Tests (BCT) 36 | * 37 | * Two web handlers will be registered, which can be used during BCT to trigger 38 | * varions "Tester Interaction" steps. 39 | * 40 | * /bct/hotplug: A GET or POST on this can be used for "Cable Change Handling" or "Hot Plugging" 41 | * steps. 42 | * /bct/name-change: A GET or POST on this can be used for "Manual Name Change". 43 | * 44 | * Eg. curl 169.254.1.9/bct/hotplug 45 | * curl -d {} 169.254.1.9/bct/name-change 46 | * 47 | * This should be used only for Certification accessories. Irrespective of when this API is called, 48 | * the handlers will get enabled only after hap_start(). 49 | */ 50 | void hap_bct_register_http_handlers(); 51 | 52 | /** 53 | * @brief De-register the handlers registered using hap_bct_register_http_handlers() 54 | */ 55 | void hap_bct_unregister_http_handlers(); 56 | 57 | #ifdef __cplusplus 58 | } 59 | #endif 60 | 61 | #endif /* _HAP_BCT_HTTP_HANDLERS_H_ */ 62 | -------------------------------------------------------------------------------- /components/homekit/esp_hap_extras/include/hap_fw_upgrade.h: -------------------------------------------------------------------------------- 1 | /* 2 | * ESPRESSIF MIT License 3 | * 4 | * Copyright (c) 2020 5 | * 6 | * Permission is hereby granted for use on ESPRESSIF SYSTEMS products only, in which case, 7 | * it is free of charge, to any person obtaining a copy of this software and associated 8 | * documentation files (the "Software"), to deal in the Software without restriction, including 9 | * without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, 10 | * and/or sell copies of the Software, and to permit persons to whom the Software is furnished 11 | * to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all copies or 14 | * 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, FITNESS 18 | * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 19 | * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 20 | * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 21 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 22 | * 23 | */ 24 | 25 | /* Firmware Upgrade HomeKit Custom Service 26 | */ 27 | #ifndef _HAP_FW_UPGRADE_H_ 28 | #define _HAP_FW_UPGRADE_H_ 29 | #include 30 | #include 31 | #include 32 | 33 | #ifdef __cplusplus 34 | extern "C" { 35 | #endif 36 | 37 | /** Custom UUID for Firmware Upgrade Service */ 38 | #define HAP_SERV_CUSTOM_UUID_FW_UPG "d57034d8-3736-11e8-b467-0ed5f89f718b" 39 | 40 | /** Custom UUID for the Write-Only Firmware Upgrade URL */ 41 | #define HAP_CHAR_CUSTOM_UUID_FW_UPG_URL "d57039e2-3736-11e8-b467-0ed5f89f718b" 42 | 43 | /** Custom UUID for the Read-Only Firmware Upgrade Status */ 44 | #define HAP_CHAR_CUSTOM_UUID_FW_UPG_STATUS "d5703b5e-3736-11e8-b467-0ed5f89f718b" 45 | 46 | typedef struct { 47 | char * server_cert_pem; /*!< Server verification, PEM format as string */ 48 | } hap_fw_upgrade_config_t; 49 | 50 | /** Firmware Upgrade Status 51 | * 52 | * These are the valid values for HAP_CHAR_CUSTOM_UUID_FW_UPG_STATUS 53 | */ 54 | typedef enum { 55 | /** FW Upgrade Failed */ 56 | FW_UPG_STATUS_FAIL = -1, 57 | /** FW Upgrade Idle */ 58 | FW_UPG_STATUS_IDLE = 0, 59 | /** FW Upgrade in Progress */ 60 | FW_UPG_STATUS_UPGRADING = 1, 61 | /** FW Upgrade Successful */ 62 | FW_UPG_STATUS_SUCCESS = 2, 63 | } hap_fw_upgrade_status_t; 64 | 65 | /** Create Firmware Upgrade Service 66 | * 67 | * This creates the custom Firmware Upgrade HomeKit Service with appropriate characteristics. 68 | * Add this service to the accessory, to enable the HTTP Client based Firmware Upgrade. 69 | * Host the FW image binary on a webserver and provide the URL as write value for 70 | * \ref HAP_CHAR_CUSTOM_UUID_FW_UPG_URL. The status will be reported on 71 | * \ref HAP_CHAR_CUSTOM_UUID_FW_UPG_STATUS 72 | * 73 | * Please refer the top level README.md for more details. 74 | * ESP32 OTA details: https://docs.espressif.com/projects/esp-idf/en/latest/api-reference/system/ota.html 75 | * ESP32 API Reference: https://docs.espressif.com/projects/esp-idf/en/latest/api-reference/system/esp_https_ota.html 76 | * @param[in] ota_config Pointer to a \ref hap_fw_upgrade_config_t structure, for using Secure HTTP (HTTPS). 77 | * 78 | * @return Service Object pointer on success 79 | * @return NULL on failure 80 | */ 81 | hap_serv_t * hap_serv_fw_upgrade_create(hap_fw_upgrade_config_t *ota_config); 82 | 83 | #ifdef __cplusplus 84 | } 85 | #endif 86 | 87 | #endif /* _HAP_FW_UPGRADE_H_ */ 88 | -------------------------------------------------------------------------------- /components/homekit/esp_hap_extras/src/hap_bct_http_handlers.c: -------------------------------------------------------------------------------- 1 | /* 2 | * ESPRESSIF MIT License 3 | * 4 | * Copyright (c) 2020 5 | * 6 | * Permission is hereby granted for use on ESPRESSIF SYSTEMS products only, in which case, 7 | * it is free of charge, to any person obtaining a copy of this software and associated 8 | * documentation files (the "Software"), to deal in the Software without restriction, including 9 | * without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, 10 | * and/or sell copies of the Software, and to permit persons to whom the Software is furnished 11 | * to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all copies or 14 | * 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, FITNESS 18 | * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 19 | * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 20 | * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 21 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 22 | * 23 | */ 24 | 25 | /* BCT HTTP Handlers 26 | */ 27 | #include 28 | #include 29 | #include 30 | #include 31 | #include 32 | 33 | #define SUCCESS_RESP "{\"status\":0}" 34 | 35 | #ifdef CONFIG_LEGACY_BCT /* BCT 1.4 and earlier */ 36 | #define NEW_BCT_NAME "New - Bonjour Service Name" 37 | #else 38 | #define NEW_BCT_NAME "New-BCT" 39 | #endif /* CONFIG_LEGACY_BCT */ 40 | 41 | static int hap_bct_name_change_handler(httpd_req_t *req) 42 | { 43 | hap_bct_change_name(NEW_BCT_NAME); 44 | return httpd_resp_send(req, SUCCESS_RESP, strlen(SUCCESS_RESP)); 45 | } 46 | static struct httpd_uri bct_name_change_get = { 47 | .uri = "/bct/name-change", 48 | .method = HTTP_GET, 49 | .handler = hap_bct_name_change_handler, 50 | }; 51 | static struct httpd_uri bct_name_change_post = { 52 | .uri = "/bct/name-change", 53 | .method = HTTP_POST, 54 | .handler = hap_bct_name_change_handler, 55 | }; 56 | 57 | static int hap_bct_hot_plug_handler(httpd_req_t *req) 58 | { 59 | hap_bct_hot_plug(); 60 | return httpd_resp_send(req, SUCCESS_RESP, strlen(SUCCESS_RESP)); 61 | } 62 | static struct httpd_uri bct_hotplug_get = { 63 | .uri = "/bct/hotplug", 64 | .method = HTTP_GET, 65 | .handler = hap_bct_hot_plug_handler, 66 | }; 67 | 68 | static struct httpd_uri bct_hotplug_post = { 69 | .uri = "/bct/hotplug", 70 | .method = HTTP_POST, 71 | .handler = hap_bct_hot_plug_handler, 72 | }; 73 | 74 | void hap_bct_register_http_handlers() 75 | { 76 | httpd_handle_t *httpd_handle = hap_platform_httpd_get_handle(); 77 | httpd_register_uri_handler(*httpd_handle, &bct_name_change_get); 78 | httpd_register_uri_handler(*httpd_handle, &bct_name_change_post); 79 | httpd_register_uri_handler(*httpd_handle, &bct_hotplug_get); 80 | httpd_register_uri_handler(*httpd_handle, &bct_hotplug_post); 81 | } 82 | 83 | void hap_bct_unregister_http_handlers() 84 | { 85 | httpd_handle_t *httpd_handle = hap_platform_httpd_get_handle(); 86 | httpd_unregister_uri_handler(*httpd_handle, "/bct/name-change", HTTP_GET); 87 | httpd_unregister_uri_handler(*httpd_handle, "/bct/name-change", HTTP_POST); 88 | httpd_unregister_uri_handler(*httpd_handle, "/bct/hotplug", HTTP_GET); 89 | httpd_unregister_uri_handler(*httpd_handle, "/bct/hotplug", HTTP_POST); 90 | } 91 | -------------------------------------------------------------------------------- /components/homekit/esp_hap_platform/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | set(srcs src/esp_mfi_aes.c src/esp_mfi_base64.c src/esp_mfi_rand.c src/esp_mfi_sha.c src/hap_platform_httpd.c src/hap_platform_keystore.c src/hap_platform_memory.c src/hap_platform_os.c) 2 | 3 | if(NOT CONFIG_IDF_TARGET_ESP8266) 4 | list(APPEND srcs src/esp_mfi_i2c.c) 5 | endif() 6 | 7 | if("${IDF_VERSION_MAJOR}.${IDF_VERSION_MINOR}" VERSION_GREATER_EQUAL "5.0") 8 | list(APPEND priv_req driver) 9 | endif() 10 | 11 | idf_component_register(SRCS ${srcs} 12 | INCLUDE_DIRS "include" 13 | REQUIRES esp_http_server 14 | PRIV_REQUIRES ${priv_req} mbedtls nvs_flash mdns esp_hap_core) 15 | component_compile_options(-Wno-unused-function) 16 | -------------------------------------------------------------------------------- /components/homekit/esp_hap_platform/Kconfig: -------------------------------------------------------------------------------- 1 | menu "MFi I2C Setup" 2 | 3 | choice 4 | prompt "Choose Data Rate" 5 | default DR_400 if IDF_TARGET_ESP32 6 | default DR_100 if IDF_TARGET_ESP32S2 7 | config DR_400 8 | bool "400 kbit/s" 9 | config DR_100 10 | bool "100 kbit/s" 11 | endchoice 12 | 13 | config IC2_SPEED 14 | int 15 | default 400000 if DR_400 16 | default 100000 if DR_100 17 | help 18 | Set the i2c datarate 19 | 20 | config SDA_GPIO 21 | int "SDA GPIO" 22 | default 26 if IDF_TARGET_ESP32 23 | default 4 if IDF_TARGET_ESP32S2 24 | default 5 if IDF_TARGET_ESP32C3 25 | default 2 if IDF_TARGET_ESP8266 26 | default 4 27 | help 28 | GPIO for SDA - please check schematic carefully 29 | 30 | config SCL_GPIO 31 | int "SCL GPIO" 32 | default 27 if IDF_TARGET_ESP32 33 | default 5 if IDF_TARGET_ESP32S2 34 | default 6 if IDF_TARGET_ESP32C3 35 | default 14 if IDF_TARGET_ESP8266 36 | default 5 37 | help 38 | GPIO for SCL - please check schematic carefully 39 | 40 | config I2C_MAX_READ_COUNT 41 | int "Max read count" 42 | range 50 300 43 | default 150 44 | help 45 | Set the max read count 46 | 47 | config I2C_RETRY_COUNT 48 | int "Retry Count" 49 | default 200 50 | help 51 | Set the number of retries for an I2C interface 52 | 53 | endmenu 54 | 55 | menu "HAP HTTP Server" 56 | 57 | config HAP_HTTP_STACK_SIZE 58 | int "Server Stack Size" 59 | default 12288 60 | range 8192 32768 61 | help 62 | Set the stack size for the HomeKit HTTP Server thread. 63 | 64 | config HAP_HTTP_SERVER_PORT 65 | int "Server Port" 66 | default 80 67 | help 68 | Set the HomeKit HTTP Server Port number. 69 | 70 | config HAP_HTTP_CONTROL_PORT 71 | int "Server Control Port" 72 | default 32859 73 | help 74 | Set the HomeKit HTTP Server UDP Control Port which is used for internl communication. 75 | 76 | config HAP_HTTP_MAX_OPEN_SOCKETS 77 | int "Max Open Sockets" 78 | default 8 79 | range 2 24 80 | help 81 | Set the Maximum simultaneous Open Sockets that the HTTP Server should allow. 82 | A minimum of 8 is required for HomeKit Certification. 83 | 84 | config HAP_HTTP_MAX_URI_HANDLERS 85 | int "Max URI Handlers" 86 | default 16 87 | range 12 32 88 | help 89 | Set the Maximum number of URI handlers that the HTTP Server should allow. 90 | 91 | endmenu 92 | 93 | menu "HAP Platform Keystore" 94 | 95 | config HAP_PLATFORM_DEF_NVS_RUNTIME_PARTITION 96 | string "Runtime NVS partition name" 97 | default "nvs" 98 | help 99 | Set the runtime NVS partition name for HomeKit use. 100 | 101 | config HAP_PLATFORM_DEF_NVS_FACTORY_PARTITION 102 | string "Factory NVS partition name" 103 | default "factory_nvs" 104 | help 105 | Set the factory NVS partition name for HomeKit use. 106 | 107 | endmenu 108 | -------------------------------------------------------------------------------- /components/homekit/esp_hap_platform/component.mk: -------------------------------------------------------------------------------- 1 | # 2 | # Component Makefile 3 | # 4 | CFLAGS += -Wno-unused-function 5 | COMPONENT_SRCDIRS := src 6 | ifdef CONFIG_IDF_TARGET_ESP8266 7 | COMPONENT_OBJEXCLUDE += src/esp_mfi_i2c.o 8 | endif 9 | COMPONENT_ADD_INCLUDEDIRS := include 10 | -------------------------------------------------------------------------------- /components/homekit/esp_hap_platform/include/esp_mfi_aes.h: -------------------------------------------------------------------------------- 1 | /* 2 | * ESPRESSIF MIT License 3 | * 4 | * Copyright (c) 2020 5 | * 6 | * Permission is hereby granted for use on ESPRESSIF SYSTEMS products only, in which case, 7 | * it is free of charge, to any person obtaining a copy of this software and associated 8 | * documentation files (the "Software"), to deal in the Software without restriction, including 9 | * without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, 10 | * and/or sell copies of the Software, and to permit persons to whom the Software is furnished 11 | * to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all copies or 14 | * 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, FITNESS 18 | * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 19 | * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 20 | * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 21 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 22 | * 23 | */ 24 | #ifndef ESP_MFI_AES_H_ 25 | #define ESP_MFI_AES_H_ 26 | 27 | #include 28 | 29 | #ifdef __cplusplus 30 | extern "C" { 31 | #endif 32 | 33 | #define MFI_AES_CTR_SIZE 16 34 | 35 | typedef void* esp_mfi_aes_ctr_t; 36 | 37 | /** 38 | * @brief Create AES context 39 | * 40 | * @return pointer of the AES context 41 | */ 42 | esp_mfi_aes_ctr_t esp_mfi_aes_ctr_new(void); 43 | 44 | /** 45 | * @brief Initialize AES context, including the key and nonce 46 | * 47 | * @param incontext pointer of the AES context 48 | * @param inkey AES key 49 | * @param innonce AES nonce 50 | * 51 | * @return 52 | * - 0 : succeed 53 | * - others : fail 54 | */ 55 | int esp_mfi_aes_ctr_init(esp_mfi_aes_ctr_t incontext, const uint8_t inkey[MFI_AES_CTR_SIZE], const uint8_t innonce[MFI_AES_CTR_SIZE]); 56 | 57 | /** 58 | * @brief Update AES context 59 | * 60 | * @param incontext AES context point 61 | * @param insrc pointer of the source data to be updated 62 | * @param insrclen source data length 63 | * @param indst pointer of the updated data 64 | * 65 | * @return 66 | * - 0 : succeed 67 | * - others : fail 68 | */ 69 | int esp_mfi_aes_ctr_update(esp_mfi_aes_ctr_t incontext, const void *insrc, uint16_t insrclen, void *indst); 70 | 71 | /** 72 | * @brief Destroy AES context pointer 73 | * 74 | * @param incontext pointer of the AES context 75 | */ 76 | void esp_mfi_aes_ctr_final(esp_mfi_aes_ctr_t incontext); 77 | 78 | #ifdef __cplusplus 79 | } 80 | #endif 81 | 82 | #endif /* ESP_MFI_AES_H_ */ 83 | -------------------------------------------------------------------------------- /components/homekit/esp_hap_platform/include/esp_mfi_base64.h: -------------------------------------------------------------------------------- 1 | /* 2 | * ESPRESSIF MIT License 3 | * 4 | * Copyright (c) 2020 5 | * 6 | * Permission is hereby granted for use on ESPRESSIF SYSTEMS products only, in which case, 7 | * it is free of charge, to any person obtaining a copy of this software and associated 8 | * documentation files (the "Software"), to deal in the Software without restriction, including 9 | * without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, 10 | * and/or sell copies of the Software, and to permit persons to whom the Software is furnished 11 | * to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all copies or 14 | * 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, FITNESS 18 | * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 19 | * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 20 | * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 21 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 22 | * 23 | */ 24 | #ifndef ESP_MFI_BASE64_H_ 25 | #define ESP_MFI_BASE64_H_ 26 | 27 | #include 28 | 29 | #ifdef __cplusplus 30 | extern "C" { 31 | #endif 32 | 33 | /** 34 | * @brief transform bin data to base64 data 35 | * 36 | * @param src input data point 37 | * @param len input data length 38 | * @param dest output data point 39 | * @param dest_len output data buffer length 40 | * @param out_len output data length 41 | * 42 | * @return 43 | * - 0 : succeed 44 | * - others : fail 45 | */ 46 | int esp_mfi_base64_encode(const char *src, int len, char *dest, int dest_len, int *out_len); 47 | 48 | /** 49 | * @brief transform base64 data to bin data 50 | * 51 | * @param src input data point 52 | * @param len input data length 53 | * @param dest output data point 54 | * @param dest_len output data buffer length 55 | * @param out_len output data length 56 | * 57 | * @return 58 | * - 0 : succeed 59 | * - others : fail 60 | */ 61 | int esp_mfi_base64_decode(const char *src, int len, char *dest, int dest_len, int *out_len); 62 | 63 | #ifdef __cplusplus 64 | } 65 | #endif 66 | 67 | #endif /* ESP_MFI_BASE64_H_ */ 68 | -------------------------------------------------------------------------------- /components/homekit/esp_hap_platform/include/esp_mfi_i2c.h: -------------------------------------------------------------------------------- 1 | /* 2 | * ESPRESSIF MIT License 3 | * 4 | * Copyright (c) 2020 5 | * 6 | * Permission is hereby granted for use on ESPRESSIF SYSTEMS products only, in which case, 7 | * it is free of charge, to any person obtaining a copy of this software and associated 8 | * documentation files (the "Software"), to deal in the Software without restriction, including 9 | * without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, 10 | * and/or sell copies of the Software, and to permit persons to whom the Software is furnished 11 | * to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all copies or 14 | * 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, FITNESS 18 | * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 19 | * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 20 | * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 21 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 22 | * 23 | */ 24 | 25 | #ifndef ESP_MFI_I2C_H_ 26 | #define ESP_MFI_I2C_H_ 27 | 28 | #include 29 | 30 | #ifdef __cplusplus 31 | extern "C" { 32 | #endif 33 | 34 | /** 35 | * @brief Initialize I2C 36 | * 37 | * @return 38 | * - 0 : succeed 39 | * - others : fail 40 | */ 41 | int esp_mfi_i2c_init(void); 42 | 43 | /** 44 | * @brief I2C operation end 45 | * 46 | * @return 47 | * - 0 : succeed 48 | * - others : fail 49 | */ 50 | int esp_mfi_i2c_end(void); 51 | 52 | /** 53 | * @brief Write data to I2C slave 54 | * 55 | * @param slvaddr address of slave 56 | * @param regaddr address of register 57 | * @param buff pointer of data to write 58 | * @param len the data length 59 | * 60 | * @return 61 | * - 0 : succeed 62 | * - others : fail 63 | */ 64 | int esp_mfi_i2c_write(uint8_t slvaddr, uint8_t regaddr, uint8_t *buff, uint32_t len); 65 | 66 | /** 67 | * @brief Read data from I2C slave 68 | * 69 | * @param slvaddr address of slave 70 | * @param regaddr address of register 71 | * @param buff pointer of data read 72 | * @param len the data length 73 | * 74 | * @return 75 | * - 0 : succeed 76 | * - others : fail 77 | */ 78 | int esp_mfi_i2c_read(uint8_t slvaddr, uint8_t regaddr, uint8_t *buff, uint32_t len); 79 | 80 | /** 81 | * @brief Configure the I2C GPIOs 82 | * 83 | * The default MFi I2C SDA and SCL pins are set by CONFIG_SDA_GPIO and CONFIG_SCL_GPIO. 84 | * However, some applications may need changing these at run time, based on some config 85 | * data. This API have been provided for such use cases. 86 | * This should be called before hap_start() and should not be called thereafter. 87 | * 88 | * @param sda_gpio The SDA GPIO 89 | * @param scl_gpio The SCL GPIO 90 | */ 91 | void esp_mfi_i2c_configure(uint8_t sda_gpio, uint8_t scl_gpio); 92 | #ifdef __cplusplus 93 | } 94 | #endif 95 | 96 | #endif /* ESP_MFI_I2C_H_ */ 97 | -------------------------------------------------------------------------------- /components/homekit/esp_hap_platform/include/esp_mfi_rand.h: -------------------------------------------------------------------------------- 1 | /* 2 | * ESPRESSIF MIT License 3 | * 4 | * Copyright (c) 2020 5 | * 6 | * Permission is hereby granted for use on ESPRESSIF SYSTEMS products only, in which case, 7 | * it is free of charge, to any person obtaining a copy of this software and associated 8 | * documentation files (the "Software"), to deal in the Software without restriction, including 9 | * without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, 10 | * and/or sell copies of the Software, and to permit persons to whom the Software is furnished 11 | * to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all copies or 14 | * 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, FITNESS 18 | * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 19 | * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 20 | * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 21 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 22 | * 23 | */ 24 | 25 | #ifndef ESP_MFI_RAND_H_ 26 | #define ESP_MFI_RAND_H_ 27 | 28 | #include 29 | 30 | #ifdef __cplusplus 31 | extern "C" { 32 | #endif 33 | 34 | /** 35 | * @brief Get a random number of bytes specified. 36 | * 37 | * @param buf pointer of the random number it gets 38 | * @param len specified bytes of the random number 39 | * 40 | * @return 41 | * - > 0 : the actual length(bytes) of the random number 42 | * - others : failure 43 | */ 44 | int esp_mfi_get_random(uint8_t *buf, uint16_t len); 45 | 46 | #ifdef __cplusplus 47 | } 48 | #endif 49 | 50 | #endif /* ESP_MFI_RAND_H_ */ 51 | -------------------------------------------------------------------------------- /components/homekit/esp_hap_platform/include/hap_platform_keystore.h: -------------------------------------------------------------------------------- 1 | /* 2 | * ESPRESSIF MIT License 3 | * 4 | * Copyright (c) 2020 5 | * 6 | * Permission is hereby granted for use on ESPRESSIF SYSTEMS products only, in which case, 7 | * it is free of charge, to any person obtaining a copy of this software and associated 8 | * documentation files (the "Software"), to deal in the Software without restriction, including 9 | * without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, 10 | * and/or sell copies of the Software, and to permit persons to whom the Software is furnished 11 | * to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all copies or 14 | * 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, FITNESS 18 | * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 19 | * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 20 | * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 21 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 22 | * 23 | */ 24 | 25 | #ifndef _HAP_PLATFORM_KEYSTORE_H_ 26 | #define _HAP_PLATFORM_KEYSTORE_H_ 27 | 28 | #include 29 | 30 | #ifdef __cplusplus 31 | extern "C" { 32 | #endif 33 | 34 | /** Get NVS Partition Name 35 | * 36 | * @return pointer to an allocated string indicating NVS partition Name 37 | */ 38 | char * hap_platform_keystore_get_nvs_partition_name(); 39 | 40 | 41 | /** Get Factory NVS Partition Name 42 | * 43 | * @return pointer to an allocated string indicating Factory NVS partition Name 44 | */ 45 | char * hap_platform_keystore_get_factory_nvs_partition_name(); 46 | 47 | /** Initialise Key Store Partition 48 | * 49 | * @param[in] part_name Name of Partition 50 | * @param[in] read_only True for Read-Only, False for Read-Write 51 | * 52 | * @return 0 on success 53 | * @return -1 on error 54 | */ 55 | int hap_platform_keystore_init_partition(const char *part_name, bool read_only); 56 | 57 | /** Get Value from Key Store 58 | * 59 | * @param[in] part_name Name of Partition 60 | * @param[in] name_space Name space for the key 61 | * @param[in] key Name of the key 62 | * @param[out] val Allocated buffer into which the value will be read 63 | * @param[in,out] val_size Size of the allocated value buffer. Will hold the size of value read on success 64 | * 65 | * @return 0 on success 66 | * @return -1 on error 67 | */ 68 | int hap_platform_keystore_get(const char *part_name, const char *name_space, const char *key, uint8_t *val, size_t *val_size); 69 | 70 | /** Set Value in Key Store 71 | * 72 | * @param[in] part_name Name of Partition 73 | * @param[in] name_space Name space for the key 74 | * @param[in] key Name of the key 75 | * @param[in] val Pointer to the value buffer 76 | * @param[in] val_len Length of the value buffer 77 | * 78 | * @return 0 on success 79 | * @return -1 on error 80 | */ 81 | int hap_platform_keystore_set(const char *part_name, const char *name_space, const char *key, const uint8_t *val, const size_t val_len); 82 | 83 | /** Delete Entry from Key Store 84 | * 85 | * @param[in] part_name Name of Partition 86 | * @param[in] name_space Name space for the key 87 | * @param[in] key Name of the key 88 | * 89 | * @return 0 on success 90 | * @return -1 on error 91 | */ 92 | int hap_platform_keystore_delete(const char *part_name, const char *name_space, const char *key); 93 | 94 | /** Delete Name space from Key Store 95 | * 96 | * @param[in] part_name Name of Partition 97 | * @param[in] name_space Name space for the key 98 | * 99 | * @return 0 on success 100 | * @return -1 on error 101 | */ 102 | int hap_platform_keystore_delete_namespace(const char *part_name, const char *name_space); 103 | 104 | /** Erase a Key Store partition 105 | * 106 | * @param[in] part_name Name of Partition 107 | * 108 | * @return 0 on success 109 | * @return -1 on error 110 | */ 111 | int hap_platfrom_keystore_erase_partition(const char *part_name); 112 | #ifdef __cplusplus 113 | } 114 | #endif 115 | #endif /* _HAP_PLATFORM_KEYSTORE_H_ */ 116 | -------------------------------------------------------------------------------- /components/homekit/esp_hap_platform/include/hap_platform_memory.h: -------------------------------------------------------------------------------- 1 | /* 2 | * ESPRESSIF MIT License 3 | * 4 | * Copyright (c) 2019 5 | * 6 | * Permission is hereby granted for use on ESPRESSIF SYSTEMS products only, in which case, 7 | * it is free of charge, to any person obtaining a copy of this software and associated 8 | * documentation files (the "Software"), to deal in the Software without restriction, including 9 | * without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, 10 | * and/or sell copies of the Software, and to permit persons to whom the Software is furnished 11 | * to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all copies or 14 | * 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, FITNESS 18 | * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 19 | * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 20 | * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 21 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 22 | * 23 | */ 24 | #ifndef _HAP_PLATFORM_MEMORY_H_ 25 | #define _HAP_PLATFORM_MEMORY_H_ 26 | #include 27 | #ifdef __cplusplus 28 | extern "C" { 29 | #endif 30 | 31 | 32 | /** Allocate memory 33 | * 34 | * This API allocates "size" bytes of memory and returns a pointer to the allocated memory. 35 | * 36 | * @param[in] size Number of bytes to be allocated 37 | * 38 | * @return pointer to the allocated memory 39 | * @return NULL on failure 40 | */ 41 | void * hap_platform_memory_malloc(size_t size); 42 | 43 | /** Allocate contiguous memory for items 44 | * 45 | * This API contiguously allocates enough space for "count" objects that are "size" bytes of memory each 46 | * and returns a pointer to the allocated memory. The allocated memory is filled with bytes of value zero. 47 | * 48 | * @param[in] count Number of items 49 | * @param[in] size Size of each item 50 | * 51 | * @return pointer to the allocated memory 52 | * @return NULL on failure 53 | */ 54 | void * hap_platform_memory_calloc(size_t count, size_t size); 55 | 56 | /** Free allocate memory 57 | * 58 | * This API frees the memory allocated by hap_platform_memory_malloc() or hap_platform_memory_calloc() 59 | * 60 | * @param[in] ptr Pointer to the allocated memory 61 | */ 62 | void hap_platform_memory_free(void *ptr); 63 | 64 | #ifdef __cplusplus 65 | } 66 | #endif 67 | #endif /* _HAP_PLATFORM_MEMORY_H_ */ 68 | -------------------------------------------------------------------------------- /components/homekit/esp_hap_platform/include/hap_platform_os.h: -------------------------------------------------------------------------------- 1 | /* 2 | * ESPRESSIF MIT License 3 | * 4 | * Copyright (c) 2019 5 | * 6 | * Permission is hereby granted for use on ESPRESSIF SYSTEMS products only, in which case, 7 | * it is free of charge, to any person obtaining a copy of this software and associated 8 | * documentation files (the "Software"), to deal in the Software without restriction, including 9 | * without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, 10 | * and/or sell copies of the Software, and to permit persons to whom the Software is furnished 11 | * to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all copies or 14 | * 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, FITNESS 18 | * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 19 | * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 20 | * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 21 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 22 | * 23 | */ 24 | #ifndef _HAP_PLATFORM_OS_H_ 25 | #define _HAP_PLATFORM_OS_H_ 26 | #include 27 | #ifdef __cplusplus 28 | extern "C" { 29 | #endif 30 | 31 | 32 | /** Return the OS tick period in milliseconds 33 | * 34 | * @return the milliseconds per tick as configured for the OS 35 | */ 36 | uint16_t hap_platform_os_get_msec_per_tick(); 37 | 38 | #ifdef __cplusplus 39 | } 40 | #endif 41 | #endif /* _HAP_PLATFORM_OS_H_ */ 42 | -------------------------------------------------------------------------------- /components/homekit/esp_hap_platform/src/esp_mfi_base64.c: -------------------------------------------------------------------------------- 1 | /* 2 | * ESPRESSIF MIT License 3 | * 4 | * Copyright (c) 2020 5 | * 6 | * Permission is hereby granted for use on ESPRESSIF SYSTEMS products only, in which case, 7 | * it is free of charge, to any person obtaining a copy of this software and associated 8 | * documentation files (the "Software"), to deal in the Software without restriction, including 9 | * without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, 10 | * and/or sell copies of the Software, and to permit persons to whom the Software is furnished 11 | * to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all copies or 14 | * 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, FITNESS 18 | * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 19 | * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 20 | * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 21 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 22 | * 23 | */ 24 | 25 | #include 26 | 27 | #include "mbedtls/base64.h" 28 | 29 | /** 30 | * @brief transform bin data to base64 data 31 | */ 32 | int esp_mfi_base64_encode(const char *src, int len, char *dest, int dest_len, int *out_len) 33 | { 34 | int ret = mbedtls_base64_encode((unsigned char *)dest, dest_len, (size_t *)out_len, (unsigned char *)src, len); 35 | if (ret != 0){ 36 | return -EINVAL; 37 | } else{ 38 | return 0; 39 | } 40 | } 41 | 42 | /** 43 | * @brief transform base64 data to bin data 44 | */ 45 | int esp_mfi_base64_decode(const char *src, int len, char *dest, int dest_len, int *out_len) 46 | { 47 | int ret = 0; 48 | ret = mbedtls_base64_decode((unsigned char *)dest, dest_len, (size_t *)out_len, (unsigned char *)src, len); 49 | if (ret != 0) { 50 | return -EINVAL; 51 | } else { 52 | return 0; 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /components/homekit/esp_hap_platform/src/esp_mfi_rand.c: -------------------------------------------------------------------------------- 1 | /* 2 | * ESPRESSIF MIT License 3 | * 4 | * Copyright (c) 2020 5 | * 6 | * Permission is hereby granted for use on ESPRESSIF SYSTEMS products only, in which case, 7 | * it is free of charge, to any person obtaining a copy of this software and associated 8 | * documentation files (the "Software"), to deal in the Software without restriction, including 9 | * without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, 10 | * and/or sell copies of the Software, and to permit persons to whom the Software is furnished 11 | * to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all copies or 14 | * 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, FITNESS 18 | * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 19 | * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 20 | * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 21 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 22 | * 23 | */ 24 | 25 | #include 26 | #include 27 | #include 28 | #if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5, 0, 0) 29 | #include 30 | #endif 31 | /** 32 | * @bref Obtain a series of random bytes 33 | * 34 | * @param buf the random bytes were copied point 35 | * len the number of bytes requested 36 | * 37 | * @return the result 38 | * > 0 : the number of bytes that were copied to the buffer 39 | * others : failed 40 | */ 41 | int esp_mfi_get_random(uint8_t *buf, uint16_t len) 42 | { 43 | int i, j; 44 | unsigned long tmp; 45 | 46 | for (i = 0; i < ((len + 3) & ~3) / 4; i++) { 47 | tmp = esp_random(); 48 | 49 | for (j = 0; j < 4; j++) { 50 | if ((i * 4 + j) < len) { 51 | buf[i * 4 + j] = (uint8_t) (tmp >> (j * 8)); 52 | } else { 53 | break; 54 | } 55 | } 56 | } 57 | 58 | return len; 59 | } 60 | -------------------------------------------------------------------------------- /components/homekit/esp_hap_platform/src/hap_platform_httpd.c: -------------------------------------------------------------------------------- 1 | /* 2 | * ESPRESSIF MIT License 3 | * 4 | * Copyright (c) 2019 5 | * 6 | * Permission is hereby granted for use on ESPRESSIF SYSTEMS products only, in which case, 7 | * it is free of charge, to any person obtaining a copy of this software and associated 8 | * documentation files (the "Software"), to deal in the Software without restriction, including 9 | * without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, 10 | * and/or sell copies of the Software, and to permit persons to whom the Software is furnished 11 | * to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all copies or 14 | * 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, FITNESS 18 | * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 19 | * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 20 | * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 21 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 22 | * 23 | */ 24 | #include 25 | 26 | httpd_handle_t *int_handle; 27 | int hap_platform_httpd_start(httpd_handle_t *handle) 28 | { 29 | httpd_config_t config = HTTPD_DEFAULT_CONFIG(); 30 | config.task_priority = tskIDLE_PRIORITY+5; 31 | config.stack_size = CONFIG_HAP_HTTP_STACK_SIZE; 32 | config.server_port = CONFIG_HAP_HTTP_SERVER_PORT; 33 | config.ctrl_port = CONFIG_HAP_HTTP_CONTROL_PORT; 34 | config.max_open_sockets = CONFIG_HAP_HTTP_MAX_OPEN_SOCKETS; 35 | config.max_uri_handlers = CONFIG_HAP_HTTP_MAX_URI_HANDLERS; 36 | config.max_resp_headers = 8; 37 | config.backlog_conn = 5; 38 | config.lru_purge_enable = true; 39 | config.recv_wait_timeout = 5; 40 | config.send_wait_timeout = 5; 41 | 42 | esp_err_t err = httpd_start(handle, &config); 43 | if (err == ESP_OK) { 44 | int_handle = handle; 45 | } 46 | return err; 47 | } 48 | 49 | int hap_platform_httpd_stop(httpd_handle_t *handle) 50 | { 51 | esp_err_t err = httpd_stop(*handle); 52 | if (err == ESP_OK) { 53 | int_handle = NULL; 54 | } 55 | return err; 56 | } 57 | 58 | int hap_platform_httpd_get_port() 59 | { 60 | return CONFIG_HAP_HTTP_SERVER_PORT; 61 | } 62 | 63 | void * hap_platform_httpd_get_sess_ctx(httpd_req_t *req) 64 | { 65 | if (req) { 66 | return req->sess_ctx; 67 | } 68 | return NULL; 69 | } 70 | 71 | esp_err_t hap_platform_httpd_set_sess_ctx(httpd_req_t *req, void *ctx, httpd_free_ctx_fn_t free_ctx, bool ignore_ctx_changes) 72 | { 73 | if (req) { 74 | req->sess_ctx = ctx; 75 | req->free_ctx = free_ctx; 76 | #ifndef CONFIG_IDF_TARGET_ESP8266 77 | req->ignore_sess_ctx_changes = ignore_ctx_changes; 78 | #endif 79 | return ESP_OK; 80 | } 81 | return ESP_FAIL; 82 | } 83 | 84 | static char * hap_platform_httpd_rqtype_to_string(int method) 85 | { 86 | switch (method) { 87 | case HTTP_GET: 88 | return "GET"; 89 | case HTTP_POST: 90 | return "POST"; 91 | case HTTP_PUT: 92 | return "PUT"; 93 | default: 94 | return "INVALID"; 95 | } 96 | } 97 | 98 | const char *hap_platform_httpd_get_req_method(httpd_req_t *req) 99 | { 100 | if (req) { 101 | return hap_platform_httpd_rqtype_to_string(req->method); 102 | } 103 | return NULL; 104 | } 105 | 106 | const char *hap_platform_httpd_get_req_uri(httpd_req_t *req) 107 | { 108 | if (req) { 109 | return req->uri; 110 | } 111 | return NULL; 112 | } 113 | 114 | int hap_platform_httpd_get_content_len(httpd_req_t *req) 115 | { 116 | if (req) { 117 | return req->content_len; 118 | } 119 | return -1; 120 | } 121 | 122 | httpd_handle_t *hap_platform_httpd_get_handle() 123 | { 124 | return int_handle; 125 | } 126 | -------------------------------------------------------------------------------- /components/homekit/esp_hap_platform/src/hap_platform_memory.c: -------------------------------------------------------------------------------- 1 | /* 2 | * ESPRESSIF MIT License 3 | * 4 | * Copyright (c) 2019 5 | * 6 | * Permission is hereby granted for use on ESPRESSIF SYSTEMS products only, in which case, 7 | * it is free of charge, to any person obtaining a copy of this software and associated 8 | * documentation files (the "Software"), to deal in the Software without restriction, including 9 | * without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, 10 | * and/or sell copies of the Software, and to permit persons to whom the Software is furnished 11 | * to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all copies or 14 | * 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, FITNESS 18 | * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 19 | * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 20 | * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 21 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 22 | * 23 | */ 24 | #include 25 | 26 | void * hap_platform_memory_malloc(size_t size) 27 | { 28 | return malloc(size); 29 | } 30 | 31 | void * hap_platform_memory_calloc(size_t count, size_t size) 32 | { 33 | return calloc(count, size); 34 | } 35 | 36 | void hap_platform_memory_free(void *ptr) 37 | { 38 | free(ptr); 39 | } 40 | -------------------------------------------------------------------------------- /components/homekit/esp_hap_platform/src/hap_platform_os.c: -------------------------------------------------------------------------------- 1 | /* 2 | * ESPRESSIF MIT License 3 | * 4 | * Copyright (c) 2019 5 | * 6 | * Permission is hereby granted for use on ESPRESSIF SYSTEMS products only, in which case, 7 | * it is free of charge, to any person obtaining a copy of this software and associated 8 | * documentation files (the "Software"), to deal in the Software without restriction, including 9 | * without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, 10 | * and/or sell copies of the Software, and to permit persons to whom the Software is furnished 11 | * to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all copies or 14 | * 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, FITNESS 18 | * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 19 | * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 20 | * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 21 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 22 | * 23 | */ 24 | #include 25 | #include 26 | #include 27 | #include 28 | 29 | uint16_t hap_platform_os_get_msec_per_tick() 30 | { 31 | return portTICK_PERIOD_MS; 32 | } 33 | -------------------------------------------------------------------------------- /components/homekit/hkdf-sha/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | set(COMPONENT_ADD_INCLUDEDIRS ./include) 2 | 3 | # Edit following two lines to set component requirements (see docs) 4 | set(COMPONENT_REQUIRES ) 5 | set(COMPONENT_PRIV_REQUIRES ) 6 | 7 | set(COMPONENT_SRCS ./upstream/hkdf.c ./upstream/hmac.c ./upstream/sha1.c ./upstream/sha224-256.c ./upstream/sha384-512.c ./upstream/shatest.c ./upstream/usha.c) 8 | 9 | register_component() 10 | -------------------------------------------------------------------------------- /components/homekit/hkdf-sha/component.mk: -------------------------------------------------------------------------------- 1 | # Empty 2 | COMPONENT_SRCDIRS := ./upstream 3 | COMPONENT_ADD_INCLUDEDIRS := ./include 4 | -------------------------------------------------------------------------------- /components/homekit/hkdf-sha/upstream/.gitignore: -------------------------------------------------------------------------------- 1 | # Object files 2 | *.o 3 | 4 | # Libraries 5 | *.lib 6 | *.a 7 | 8 | # Shared objects (inc. Windows DLLs) 9 | *.dll 10 | *.so 11 | *.so.* 12 | *.dylib 13 | 14 | # Executables 15 | *.exe 16 | *.out 17 | *.app 18 | 19 | shatest 20 | 21 | # Dependencies 22 | *.d 23 | -------------------------------------------------------------------------------- /components/homekit/hkdf-sha/upstream/Makefile: -------------------------------------------------------------------------------- 1 | # Makefile for rfc6234 code examples 2 | 3 | BINS += shatest 4 | DEPS = Makefile 5 | 6 | # Prettifiers 7 | LINK = @echo "* Linking $@"; $(CC) $(CFLAGS) $(LDFLAGS) 8 | 9 | all: ${BINS} 10 | @echo "* All Done" 11 | 12 | OBJS := $(shell ls *.c | sed 's/\.c/.o/' | sed 's/ /\n/g' | sort | uniq | tr '\n' ' ') 13 | 14 | -include $(OBJS:.o=.d) 15 | 16 | depend: clean 17 | @echo "* Making dependencies for $(OBJS)" 18 | @$(MAKE) -s $(OBJS) 19 | @echo "* Making dependencies - done" 20 | 21 | clean: 22 | @echo "* Cleansing" 23 | @rm -rf $(BINS) *.o *.so *.lo *.la *.slo *.loT *.d 24 | 25 | shatest: $(DEPS) $(OBJS) 26 | $(LINK) -o $@ $(OBJS) 27 | 28 | %.o: %.c $(DEPS) 29 | @echo "* Compiling $@"; 30 | @$(CC) -c $(CFLAGS) $*.c -o $*.o 31 | @$(CC) -MM $(CFLAGS) $*.c > $*.d 32 | @cp -f $*.d $*.d.tmp 33 | @sed -e 's/.*://' -e 's/\\$$//' < $*.d.tmp | fmt -1 | \ 34 | sed -e 's/^ *//' -e 's/$$/:/' >> $*.d 35 | @rm -f $*.d.tmp 36 | 37 | -------------------------------------------------------------------------------- /components/homekit/hkdf-sha/upstream/README.md: -------------------------------------------------------------------------------- 1 | rfc6234 RFC6234 US Secure Hash Algorithms - Example Code Extract 2 | ================================================================ 3 | 4 | These are the code examples given in the IETF RFC6234: 5 | http://tools.ietf.org/html/rfc6234 6 | 7 | -------------------------------------------------------------------------------- /components/homekit/hkdf-sha/upstream/sha-private.h: -------------------------------------------------------------------------------- 1 | /************************ sha-private.h ************************/ 2 | /***************** See RFC 6234 for details. *******************/ 3 | #ifndef _SHA_PRIVATE__H 4 | #define _SHA_PRIVATE__H 5 | /* 6 | * These definitions are defined in FIPS 180-3, section 4.1. 7 | * Ch() and Maj() are defined identically in sections 4.1.1, 8 | * 4.1.2, and 4.1.3. 9 | * 10 | * The definitions used in FIPS 180-3 are as follows: 11 | */ 12 | 13 | #ifndef USE_MODIFIED_MACROS 14 | #define SHA_Ch(x,y,z) (((x) & (y)) ^ ((~(x)) & (z))) 15 | #define SHA_Maj(x,y,z) (((x) & (y)) ^ ((x) & (z)) ^ ((y) & (z))) 16 | #else /* USE_MODIFIED_MACROS */ 17 | /* 18 | * The following definitions are equivalent and potentially faster. 19 | */ 20 | 21 | #define SHA_Ch(x, y, z) (((x) & ((y) ^ (z))) ^ (z)) 22 | #define SHA_Maj(x, y, z) (((x) & ((y) | (z))) | ((y) & (z))) 23 | 24 | #endif /* USE_MODIFIED_MACROS */ 25 | 26 | #define SHA_Parity(x, y, z) ((x) ^ (y) ^ (z)) 27 | 28 | #endif /* _SHA_PRIVATE__H */ 29 | 30 | -------------------------------------------------------------------------------- /components/homekit/mu_srp/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | set(COMPONENT_ADD_INCLUDEDIRS .) 2 | 3 | # Edit following two lines to set component requirements (see docs) 4 | set(COMPONENT_REQUIRES ) 5 | set(COMPONENT_PRIV_REQUIRES hkdf-sha mbedtls) 6 | 7 | set(COMPONENT_SRCS ./mu_srp.c) 8 | 9 | register_component() 10 | -------------------------------------------------------------------------------- /components/homekit/mu_srp/component.mk: -------------------------------------------------------------------------------- 1 | # Empty 2 | COMPONENT_SRCDIRS := . 3 | COMPONENT_ADD_INCLUDEDIRS := . 4 | -------------------------------------------------------------------------------- /components/homekit/mu_srp/mu_srp.h: -------------------------------------------------------------------------------- 1 | #ifndef _MU_SRP_H_ 2 | #define _MU_SRP_H_ 3 | 4 | #include 5 | #include "mu_bignum.h" 6 | 7 | typedef enum { 8 | MU_NG_3072 = 0, 9 | } mu_ng_type_t; 10 | 11 | typedef struct mu_srp_handle { 12 | int allocated; 13 | mu_ng_type_t type; 14 | mu_bn_ctx_t *ctx; 15 | 16 | /* N 17 | * the bytes_n simply points to the static array 18 | */ 19 | mu_bn_t *n; 20 | const char *bytes_n; 21 | int len_n; 22 | 23 | /* g 24 | * the bytes_g simply points to the static array 25 | */ 26 | mu_bn_t *g; 27 | char *bytes_g; 28 | int len_g; 29 | 30 | /* Salt */ 31 | mu_bn_t *s; 32 | char *bytes_s; 33 | int len_s; 34 | /* Verifier */ 35 | mu_bn_t *v; 36 | /* B */ 37 | mu_bn_t *B; 38 | char *bytes_B; 39 | int len_B; 40 | /* b */ 41 | mu_bn_t *b; 42 | /* A */ 43 | mu_bn_t *A; 44 | char *bytes_A; 45 | int len_A; 46 | /* K - session key*/ 47 | char *session_key; 48 | } mu_srp_handle_t; 49 | 50 | int mu_srp_init(mu_srp_handle_t *hd, mu_ng_type_t ng); 51 | 52 | void mu_srp_free(mu_srp_handle_t *hd); 53 | /* Returns B (pub key) and salt 54 | * 55 | * *bytes_B MUST NOT BE FREED BY THE CALLER 56 | * *bytes_salt MUST NOT BE FREE BY THE CALLER 57 | * 58 | */ 59 | int mu_srp_srv_pubkey(mu_srp_handle_t *hd, const char *username, const char *pass, int pass_len, int salt_len, 60 | char **bytes_B, int *len_B, char **bytes_salt); 61 | 62 | /* Set the Salt and Verifier pre-generated for a given password. 63 | * This should be used only if the actual password is not available. 64 | * The public key can then be generated using mu_srp_srv_pubkey_from_salt_verifier() 65 | * and not mu_srp_srv_pubkey() 66 | */ 67 | int mu_srp_set_salt_verifier(mu_srp_handle_t *hd, const char *salt, int salt_len, 68 | const char *verifier, int verifier_len); 69 | 70 | /* Returns B (pub key) when the salt and verifier are set using mu_srp_set_salt_verifier() 71 | * 72 | * *bytes_B MUST NOT BE FREED BY THE CALLER 73 | */ 74 | int mu_srp_srv_pubkey_from_salt_verifier(mu_srp_handle_t *hd, char **bytes_B, int *len_B); 75 | 76 | /* Returns bytes_key 77 | * *bytes_key MUST NOT BE FREED BY THE CALLER 78 | */ 79 | int mu_srp_get_session_key(mu_srp_handle_t *hd, char *bytes_A, int len_A, char **bytes_key, int *len_key); 80 | 81 | /* Exchange proofs 82 | * Returns 1 if user's proof is ok. Also 1 when is returned, bytes_host_proof contains our proof. 83 | * 84 | * bytes_user_proof is parameter in 85 | * bytes_host_proof is parameter out (should be SHA512_DIGEST_LENGTH) bytes in size 86 | */ 87 | int mu_srp_exchange_proofs(mu_srp_handle_t *hd, char *username, char *bytes_user_proof, char *bytes_host_proof); 88 | 89 | 90 | 91 | #endif /* ! _MU_SRP_H_ */ 92 | -------------------------------------------------------------------------------- /examples/bridge/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # The following lines of boilerplate have to be in your project's CMakeLists 2 | # in this exact order for cmake to work correctly 3 | cmake_minimum_required(VERSION 3.5) 4 | 5 | if(DEFINED ENV{HOMEKIT_PATH}) 6 | set(HOMEKIT_PATH $ENV{HOMEKIT_PATH}) 7 | else() 8 | set(HOMEKIT_PATH ${CMAKE_CURRENT_LIST_DIR}/../..) 9 | endif(DEFINED ENV{HOMEKIT_PATH}) 10 | 11 | set(EXTRA_COMPONENT_DIRS ${HOMEKIT_PATH}/components ${HOMEKIT_PATH}/components/homekit ${CMAKE_CURRENT_LIST_DIR}/../common) 12 | 13 | include($ENV{IDF_PATH}/tools/cmake/project.cmake) 14 | project(bridge) 15 | -------------------------------------------------------------------------------- /examples/bridge/Makefile: -------------------------------------------------------------------------------- 1 | # 2 | # This is a project Makefile. It is assumed the directory this Makefile resides in is a 3 | # project subdirectory. 4 | # 5 | 6 | HOMEKIT_PATH ?= $(abspath $(shell pwd)/../..) 7 | COMMON_COMPONENT_PATH ?= $(abspath $(shell pwd)/../common) 8 | 9 | PROJECT_NAME := bridge 10 | EXTRA_COMPONENT_DIRS += $(HOMEKIT_PATH)/components/ 11 | EXTRA_COMPONENT_DIRS += $(HOMEKIT_PATH)/components/homekit 12 | EXTRA_COMPONENT_DIRS += $(COMMON_COMPONENT_PATH) 13 | 14 | include $(IDF_PATH)/make/project.mk 15 | 16 | -------------------------------------------------------------------------------- /examples/bridge/main/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | idf_component_register(SRCS ./app_main.c) 2 | -------------------------------------------------------------------------------- /examples/bridge/main/Kconfig.projbuild: -------------------------------------------------------------------------------- 1 | menu "Example Configuration" 2 | 3 | config EXAMPLE_USE_HARDCODED_SETUP_CODE 4 | bool "Use hard-coded setup code" 5 | default y 6 | help 7 | HomeKit does not recommend having the setup code programmed in the accessory as is. 8 | Instead, it expects setup info (salt-verifier pair) generated for the given setup code. 9 | Use this option only for testing purposes. For production, the setup info should be 10 | used. 11 | 12 | config EXAMPLE_SETUP_CODE 13 | string "HomeKit Setup Code" 14 | default "111-22-333" 15 | depends on EXAMPLE_USE_HARDCODED_SETUP_CODE 16 | help 17 | Setup code to be used for HomeKot pairing, if hard-coded setup code is enabled. 18 | 19 | config EXAMPLE_SETUP_ID 20 | string "HomeKit Setup Id" 21 | default "ES32" 22 | depends on EXAMPLE_USE_HARDCODED_SETUP_CODE 23 | help 24 | Setup id to be used for HomeKot pairing, if hard-coded setup code is enabled. 25 | 26 | endmenu 27 | -------------------------------------------------------------------------------- /examples/bridge/main/component.mk: -------------------------------------------------------------------------------- 1 | # 2 | # "main" pseudo-component makefile. 3 | # 4 | # (Uses default behaviour of compiling all source files in directory, adding 'include' to include path.) 5 | -------------------------------------------------------------------------------- /examples/bridge/partitions_hap.csv: -------------------------------------------------------------------------------- 1 | # Name, Type, SubType, Offset, Size, Flags 2 | # Note: Firmware partition offset needs to be 64K aligned, initial 36K (9 sectors) are reserved for bootloader and partition table 3 | sec_cert, 0x3F, ,0xd000, 0x3000, , # Never mark this as an encrypted partition 4 | nvs, data, nvs, 0x10000, 0x6000, 5 | otadata, data, ota, , 0x2000 6 | phy_init, data, phy, , 0x1000, 7 | ota_0, app, ota_0, 0x20000, 1600K, 8 | ota_1, app, ota_1, , 1600K, 9 | factory_nvs, data, nvs, 0x340000, 0x6000 10 | nvs_keys, data, nvs_keys,0x346000, 0x1000 11 | -------------------------------------------------------------------------------- /examples/bridge/sdkconfig.defaults: -------------------------------------------------------------------------------- 1 | CONFIG_PARTITION_TABLE_CUSTOM=y 2 | CONFIG_PARTITION_TABLE_CUSTOM_FILENAME="partitions_hap.csv" 3 | CONFIG_PARTITION_TABLE_CUSTOM_APP_BIN_OFFSET=0x10000 4 | CONFIG_FREERTOS_UNICORE=y 5 | CONFIG_FREERTOS_ASSERT_ON_UNTESTED_FUNCTION=n 6 | CONFIG_FREERTOS_ASSERT_FAIL_ABORT=n 7 | CONFIG_FREERTOS_ASSERT_DISABLE=y 8 | CONFIG_LWIP_MAX_SOCKETS=16 9 | CONFIG_LWIP_SO_REUSE=y 10 | CONFIG_LWIP_MAX_ACTIVE_TCP=12 11 | CONFIG_LWIP_MAX_LISTENING_TCP=12 12 | CONFIG_LWIP_UDP_RECVMBOX_SIZE=10 13 | CONFIG_MBEDTLS_HARDWARE_MPI=y 14 | CONFIG_MBEDTLS_HARDWARE_SHA=n 15 | CONFIG_ESP_TASK_WDT=n 16 | CONFIG_LWIP_AUTOIP=y 17 | CONFIG_ESPTOOLPY_FLASHSIZE_4MB=y 18 | CONFIG_LWIP_AUTOIP_RATE_LIMIT_INTERVAL=60 19 | CONFIG_MP_BLOB_SUPPORT=y 20 | CONFIG_ENABLE_UNIFIED_PROVISIONING=y 21 | CONFIG_BT_ENABLED=y 22 | CONFIG_BTDM_CTRL_MODE_BLE_ONLY=y 23 | CONFIG_BT_NIMBLE_ENABLED=y -------------------------------------------------------------------------------- /examples/bridge/sdkconfig.defaults.esp32c6: -------------------------------------------------------------------------------- 1 | # perform the size optimized builds for C6 to avoid app size overflow 2 | CONFIG_COMPILER_OPTIMIZATION_SIZE=y 3 | CONFIG_ESP_ROM_HAS_NEWLIB_NANO_FORMAT=y 4 | -------------------------------------------------------------------------------- /examples/common/app_hap_setup_payload/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | idf_component_register(SRCS "app_hap_setup_payload.c" 2 | INCLUDE_DIRS "." 3 | REQUIRES qrcode esp_hap_core) 4 | -------------------------------------------------------------------------------- /examples/common/app_hap_setup_payload/app_hap_setup_payload.c: -------------------------------------------------------------------------------- 1 | /* 2 | This example code is in the Public Domain (or CC0 licensed, at your option.) 3 | 4 | Unless required by applicable law or agreed to in writing, this 5 | software is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 6 | CONDITIONS OF ANY KIND, either express or implied. 7 | */ 8 | #include 9 | #include 10 | #include 11 | #include 12 | 13 | static const char *TAG = "app_hap_setup_payload"; 14 | 15 | #define QRCODE_BASE_URL "https://espressif.github.io/esp-homekit-sdk/qrcode.html" 16 | 17 | esp_err_t app_hap_setup_payload(char *setup_code, char *setup_id, bool wac_support, hap_cid_t cid) 18 | { 19 | char *setup_payload = esp_hap_get_setup_payload(setup_code, setup_id, wac_support, cid); 20 | if (setup_payload) { 21 | ESP_LOGI(TAG, "-----QR Code for HomeKit-----"); 22 | ESP_LOGI(TAG, "Scan this QR code from the Home app on iOS"); 23 | qrcode_display(setup_payload); 24 | ESP_LOGI(TAG, "If QR code is not visible, copy paste the below URL in a browser.\n%s?data=%s", QRCODE_BASE_URL, setup_payload); 25 | free(setup_payload); 26 | return ESP_OK; 27 | } 28 | return ESP_FAIL; 29 | } 30 | -------------------------------------------------------------------------------- /examples/common/app_hap_setup_payload/app_hap_setup_payload.h: -------------------------------------------------------------------------------- 1 | /* 2 | This example code is in the Public Domain (or CC0 licensed, at your option.) 3 | 4 | Unless required by applicable law or agreed to in writing, this 5 | software is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 6 | CONDITIONS OF ANY KIND, either express or implied. 7 | */ 8 | #pragma once 9 | #include 10 | #include 11 | 12 | /** Show the HAP Setup payload 13 | * 14 | * This shows the setup paylod in a QR code 15 | * 16 | * @param[in] setup_code NULL terminated setup code. Eg. "111-22-333" 17 | * @param[in] setup_id NULL terminated setup id. Eg. "ES32" 18 | * @param[in] wac_support Boolean indicating if WAC provisioning is supported. 19 | * @param[in] cid Accessory category identifier. 20 | * 21 | * @return ESP_OK on success. 22 | * @return ESP_FAIL on failure. 23 | */ 24 | esp_err_t app_hap_setup_payload(char *setup_code, char *setup_id, bool wac_support, hap_cid_t cid); 25 | -------------------------------------------------------------------------------- /examples/common/app_hap_setup_payload/component.mk: -------------------------------------------------------------------------------- 1 | COMPONENT_ADD_INCLUDEDIRS := . 2 | COMPONENT_SRCDIRS := . 3 | -------------------------------------------------------------------------------- /examples/common/app_wifi/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | idf_component_register(SRCS "app_wifi.c" 2 | INCLUDE_DIRS "." 3 | REQUIRES wifi_provisioning qrcode esp_hap_core esp_hap_platform nvs_flash) 4 | -------------------------------------------------------------------------------- /examples/common/app_wifi/Kconfig.projbuild: -------------------------------------------------------------------------------- 1 | menu "App Wi-Fi" 2 | 3 | choice APP_WIFI_CRED_SOURCE 4 | bool "Source of Wi-Fi Credentials" 5 | default APP_WIFI_USE_PROVISIONING 6 | help 7 | Wi-Fi credentials can either be hard-coded or provided using Provisioning. 8 | 9 | config APP_WIFI_USE_PROVISIONING 10 | bool "Use Provisioning" 11 | config APP_WIFI_USE_HARDCODED 12 | bool "Use Hardcoded" 13 | endchoice 14 | 15 | config APP_WIFI_CRED_SOURCE 16 | int 17 | default 1 if APP_WIFI_USE_PROVISIONING 18 | default 2 if APP_WIFI_USE_HARDCODED 19 | 20 | 21 | config APP_WIFI_SSID 22 | string "WiFi SSID" 23 | default "myssid" 24 | depends on APP_WIFI_USE_HARDCODED 25 | help 26 | SSID (network name) for the example to connect to. 27 | 28 | config APP_WIFI_PASSWORD 29 | string "WiFi Password" 30 | default "mypassword" 31 | depends on APP_WIFI_USE_HARDCODED 32 | help 33 | WiFi password (WPA or WPA2) for the example to use. 34 | 35 | choice APP_WIFI_PROVISIONING_TYPE 36 | bool "Provisioning Type" 37 | default APP_WIFI_USE_UNIFIED_PROVISIONING 38 | depends on APP_WIFI_USE_PROVISIONING 39 | help 40 | The type of Provisioning to Use. 41 | 42 | config APP_WIFI_USE_UNIFIED_PROVISIONING 43 | bool "Unified Provisioning" 44 | config APP_WIFI_USE_WAC_PROVISIONING 45 | bool "Apple WAC Provisioning" 46 | depends on HAP_MFI_ENABLE 47 | config APP_WIFI_USE_BOTH_PROVISIONING 48 | bool "Use Both" 49 | depends on HAP_MFI_ENABLE 50 | endchoice 51 | 52 | config APP_WIFI_PROVISIONING_TYPE 53 | int 54 | default 1 if APP_WIFI_USE_UNIFIED_PROVISIONING 55 | default 2 if APP_WIFI_USE_WAC_PROVISIONING 56 | default 3 if APP_WIFI_USE_BOTH_PROVISIONING 57 | 58 | config APP_WIFI_PROV_SHOW_QR 59 | bool "Show provisioning QR code" 60 | depends on APP_WIFI_USE_UNIFIED_PROVISIONING || APP_WIFI_USE_BOTH_PROVISIONING 61 | default y 62 | help 63 | Show the QR code for provisioning. 64 | 65 | choice APP_WIFI_PROV_TRANSPORT 66 | bool "Provisioning Transport method" 67 | default APP_WIFI_PROV_TRANSPORT_BLE 68 | depends on APP_WIFI_USE_UNIFIED_PROVISIONING || APP_WIFI_USE_BOTH_PROVISIONING 69 | help 70 | Wi-Fi provisioning component offers both, SoftAP and BLE transports. Choose any one. 71 | 72 | config APP_WIFI_PROV_TRANSPORT_SOFTAP 73 | bool "Soft AP" 74 | config APP_WIFI_PROV_TRANSPORT_BLE 75 | bool "BLE" 76 | select BT_ENABLED 77 | depends on !IDF_TARGET_ESP32S2 78 | endchoice 79 | 80 | config APP_WIFI_PROV_TRANSPORT 81 | int 82 | default 1 if APP_WIFI_PROV_TRANSPORT_SOFTAP 83 | default 2 if APP_WIFI_PROV_TRANSPORT_BLE 84 | 85 | config APP_WIFI_PROV_USING_BLUEDROID 86 | bool 87 | depends on (BT_BLUEDROID_ENABLED && (IDF_TARGET_ESP32C3 || IDF_TARGET_ESP32S3)) 88 | select BT_BLE_42_FEATURES_SUPPORTED 89 | default y 90 | help 91 | This enables BLE 4.2 features for Bluedroid. 92 | 93 | endmenu 94 | -------------------------------------------------------------------------------- /examples/common/app_wifi/app_wifi.h: -------------------------------------------------------------------------------- 1 | /* 2 | This example code is in the Public Domain (or CC0 licensed, at your option.) 3 | 4 | Unless required by applicable law or agreed to in writing, this 5 | software is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 6 | CONDITIONS OF ANY KIND, either express or implied. 7 | */ 8 | #pragma once 9 | #include 10 | 11 | void app_wifi_init(void); 12 | esp_err_t app_wifi_start(TickType_t ticks_to_wait); 13 | -------------------------------------------------------------------------------- /examples/common/app_wifi/component.mk: -------------------------------------------------------------------------------- 1 | COMPONENT_ADD_INCLUDEDIRS := . 2 | COMPONENT_SRCDIRS := . 3 | -------------------------------------------------------------------------------- /examples/common/qrcode/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | idf_component_register(SRCS ./src/qrcodegen.c ./src/qrcode.c 2 | INCLUDE_DIRS include 3 | REQUIRES 4 | PRIV_REQUIRES ) 5 | 6 | -------------------------------------------------------------------------------- /examples/common/qrcode/component.mk: -------------------------------------------------------------------------------- 1 | COMPONENT_ADD_INCLUDEDIRS := include 2 | COMPONENT_PRIV_INCLUDEDIRS := src 3 | COMPONENT_SRCDIRS := src 4 | -------------------------------------------------------------------------------- /examples/common/qrcode/include/qrcode.h: -------------------------------------------------------------------------------- 1 | // Copyright 2019 Espressif Systems (Shanghai) PTE LTD 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 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | #pragma once 15 | 16 | #include 17 | 18 | #ifdef __cplusplus 19 | extern "C" { 20 | #endif 21 | 22 | /** 23 | * @brief Generate and display QR Code on the console 24 | * Encodes the given string into a QR Code & displays it on the console 25 | * 26 | * @attention 1. Can successfully encode a UTF-8 string of up to 2953 bytes or an alphanumeric 27 | * string of up to 4296 characters or any digit string of up to 7089 characters 28 | * 29 | * @param text string to encode into a QR Code. 30 | * 31 | * @return 32 | * - ESP_OK: succeed 33 | * - ESP_FAIL: Failed to encode string into a QR Code 34 | * - ESP_ERR_NO_MEM: Failed to allocate buffer for given MAX_QRCODE_VERSION 35 | */ 36 | esp_err_t qrcode_display(const char *text); 37 | 38 | #ifdef __cplusplus 39 | } 40 | #endif 41 | -------------------------------------------------------------------------------- /examples/common/qrcode/src/qrcode.c: -------------------------------------------------------------------------------- 1 | // Copyright 2019 Espressif Systems (Shanghai) PTE LTD 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 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #include 16 | #include 17 | #include 18 | 19 | #include "qrcodegen.h" 20 | 21 | #define MAX_QRCODE_VERSION 5 22 | 23 | static const char *lt[] = { 24 | /* 0 */ " ", 25 | /* 1 */ "\u2580 ", 26 | /* 2 */ " \u2580", 27 | /* 3 */ "\u2580\u2580", 28 | /* 4 */ "\u2584 ", 29 | /* 5 */ "\u2588 ", 30 | /* 6 */ "\u2584\u2580", 31 | /* 7 */ "\u2588\u2580", 32 | /* 8 */ " \u2584", 33 | /* 9 */ "\u2580\u2584", 34 | /* 10 */ " \u2588", 35 | /* 11 */ "\u2580\u2588", 36 | /* 12 */ "\u2584\u2584", 37 | /* 13 */ "\u2588\u2584", 38 | /* 14 */ "\u2584\u2588", 39 | /* 15 */ "\u2588\u2588", 40 | }; 41 | 42 | void print_qr_char(unsigned char n) 43 | { 44 | printf("%s", lt[n]); 45 | } 46 | 47 | extern void print_qr_char(unsigned char); 48 | static void printQr(const uint8_t qrcode[]) { 49 | int size = qrcodegen_getSize(qrcode); 50 | int border = 2; 51 | unsigned char num = 0; 52 | 53 | for (int y = -border; y < size + border; y+=2) { 54 | for (int x = -border; x < size + border; x+=2) { 55 | num = 0; 56 | if (qrcodegen_getModule(qrcode, x, y)) { 57 | num |= 1 << 0; 58 | } 59 | if ((x < size + border) && qrcodegen_getModule(qrcode, x+1, y)) { 60 | num |= 1 << 1; 61 | } 62 | if ((y < size + border) && qrcodegen_getModule(qrcode, x, y+1)) { 63 | num |= 1 << 2; 64 | } 65 | if ((x < size + border) && (y < size + border) && qrcodegen_getModule(qrcode, x+1, y+1)) { 66 | num |= 1 << 3; 67 | } 68 | print_qr_char(num); 69 | } 70 | printf("\n"); 71 | } 72 | printf("\n"); 73 | } 74 | 75 | esp_err_t qrcode_display(const char *text) 76 | { 77 | enum qrcodegen_Ecc errCorLvl = qrcodegen_Ecc_LOW; 78 | uint8_t *qrcode, *tempBuffer; 79 | esp_err_t err = ESP_FAIL; 80 | 81 | qrcode = calloc(1, qrcodegen_BUFFER_LEN_FOR_VERSION(MAX_QRCODE_VERSION)); 82 | if (!qrcode) 83 | return ESP_ERR_NO_MEM; 84 | 85 | tempBuffer = calloc(1, qrcodegen_BUFFER_LEN_FOR_VERSION(MAX_QRCODE_VERSION)); 86 | if (!tempBuffer) { 87 | free(qrcode); 88 | return ESP_ERR_NO_MEM; 89 | } 90 | 91 | // Make and print the QR Code symbol 92 | bool ok = qrcodegen_encodeText(text, tempBuffer, qrcode, errCorLvl, 93 | qrcodegen_VERSION_MIN, MAX_QRCODE_VERSION, qrcodegen_Mask_AUTO, true); 94 | if (ok) { 95 | printQr(qrcode); 96 | err = ESP_OK; 97 | } 98 | 99 | free(qrcode); 100 | free(tempBuffer); 101 | return err; 102 | } 103 | -------------------------------------------------------------------------------- /examples/data_tlv8/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | 2 | # (Automatically converted from project Makefile by convert_to_cmake.py.) 3 | 4 | # The following lines of boilerplate have to be in your project's CMakeLists 5 | # in this exact order for cmake to work correctly 6 | cmake_minimum_required(VERSION 3.5) 7 | 8 | if(DEFINED ENV{HOMEKIT_PATH}) 9 | set(HOMEKIT_PATH $ENV{HOMEKIT_PATH}) 10 | else() 11 | set(HOMEKIT_PATH ${CMAKE_CURRENT_LIST_DIR}/../..) 12 | endif(DEFINED ENV{HOMEKIT_PATH}) 13 | 14 | set(EXTRA_COMPONENT_DIRS ${HOMEKIT_PATH}/components ${HOMEKIT_PATH}/components/homekit ${CMAKE_CURRENT_LIST_DIR}/../common) 15 | 16 | include($ENV{IDF_PATH}/tools/cmake/project.cmake) 17 | project(data_tlv8) 18 | -------------------------------------------------------------------------------- /examples/data_tlv8/Makefile: -------------------------------------------------------------------------------- 1 | # 2 | # This is a project Makefile. It is assumed the directory this Makefile resides in is a 3 | # project subdirectory. 4 | # 5 | 6 | HOMEKIT_PATH ?= $(abspath $(shell pwd)/../..) 7 | COMMON_COMPONENT_PATH ?= $(abspath $(shell pwd)/../common) 8 | 9 | PROJECT_NAME := data_tlv8 10 | EXTRA_COMPONENT_DIRS += $(HOMEKIT_PATH)/components/ 11 | EXTRA_COMPONENT_DIRS += $(HOMEKIT_PATH)/components/homekit 12 | EXTRA_COMPONENT_DIRS += $(COMMON_COMPONENT_PATH) 13 | 14 | include $(IDF_PATH)/make/project.mk 15 | 16 | -------------------------------------------------------------------------------- /examples/data_tlv8/main/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | idf_component_register(SRCS ./app_main.c) 2 | -------------------------------------------------------------------------------- /examples/data_tlv8/main/Kconfig.projbuild: -------------------------------------------------------------------------------- 1 | menu "Example Configuration" 2 | 3 | config EXAMPLE_USE_HARDCODED_SETUP_CODE 4 | bool "Use hard-coded setup code" 5 | default y 6 | help 7 | HomeKit does not recommend having the setup code programmed in the accessory as is. 8 | Instead, it expects setup info (salt-verifier pair) generated for the given setup code. 9 | Use this option only for testing purposes. For production, the setup info should be 10 | used. 11 | 12 | config EXAMPLE_SETUP_CODE 13 | string "HomeKit Setup Code" 14 | default "111-22-333" 15 | depends on EXAMPLE_USE_HARDCODED_SETUP_CODE 16 | help 17 | Setup code to be used for HomeKot pairing, if hard-coded setup code is enabled. 18 | 19 | config EXAMPLE_SETUP_ID 20 | string "HomeKit Setup Id" 21 | default "ES32" 22 | depends on EXAMPLE_USE_HARDCODED_SETUP_CODE 23 | help 24 | Setup id to be used for HomeKot pairing, if hard-coded setup code is enabled. 25 | 26 | endmenu 27 | -------------------------------------------------------------------------------- /examples/data_tlv8/main/component.mk: -------------------------------------------------------------------------------- 1 | # 2 | # "main" pseudo-component makefile. 3 | # 4 | # (Uses default behaviour of compiling all source files in directory, adding 'include' to include path.) 5 | -------------------------------------------------------------------------------- /examples/data_tlv8/partitions_hap.csv: -------------------------------------------------------------------------------- 1 | # Name, Type, SubType, Offset, Size, Flags 2 | # Note: Firmware partition offset needs to be 64K aligned, initial 36K (9 sectors) are reserved for bootloader and partition table 3 | sec_cert, 0x3F, ,0xd000, 0x3000, , # Never mark this as an encrypted partition 4 | nvs, data, nvs, 0x10000, 0x6000, 5 | otadata, data, ota, , 0x2000 6 | phy_init, data, phy, , 0x1000, 7 | ota_0, app, ota_0, 0x20000, 1600K, 8 | ota_1, app, ota_1, , 1600K, 9 | factory_nvs, data, nvs, 0x340000, 0x6000 10 | nvs_keys, data, nvs_keys,0x346000, 0x1000 11 | -------------------------------------------------------------------------------- /examples/data_tlv8/sdkconfig.defaults: -------------------------------------------------------------------------------- 1 | CONFIG_PARTITION_TABLE_CUSTOM=y 2 | CONFIG_PARTITION_TABLE_CUSTOM_FILENAME="partitions_hap.csv" 3 | CONFIG_PARTITION_TABLE_CUSTOM_APP_BIN_OFFSET=0x10000 4 | CONFIG_FREERTOS_UNICORE=y 5 | CONFIG_FREERTOS_ASSERT_ON_UNTESTED_FUNCTION=n 6 | CONFIG_FREERTOS_ASSERT_FAIL_ABORT=n 7 | CONFIG_FREERTOS_ASSERT_DISABLE=y 8 | CONFIG_LWIP_MAX_SOCKETS=16 9 | CONFIG_LWIP_SO_REUSE=y 10 | CONFIG_LWIP_MAX_ACTIVE_TCP=12 11 | CONFIG_LWIP_MAX_LISTENING_TCP=12 12 | CONFIG_LWIP_UDP_RECVMBOX_SIZE=10 13 | CONFIG_MBEDTLS_HARDWARE_MPI=y 14 | CONFIG_MBEDTLS_HARDWARE_SHA=n 15 | CONFIG_ESP_TASK_WDT=n 16 | CONFIG_LWIP_AUTOIP=y 17 | CONFIG_ESPTOOLPY_FLASHSIZE_4MB=y 18 | CONFIG_LWIP_AUTOIP_RATE_LIMIT_INTERVAL=60 19 | CONFIG_MP_BLOB_SUPPORT=y 20 | CONFIG_ENABLE_UNIFIED_PROVISIONING=y 21 | CONFIG_BT_ENABLED=y 22 | CONFIG_BTDM_CTRL_MODE_BLE_ONLY=y 23 | CONFIG_BT_NIMBLE_ENABLED=y -------------------------------------------------------------------------------- /examples/data_tlv8/sdkconfig.defaults.esp32c6: -------------------------------------------------------------------------------- 1 | # perform the size optimized builds for C6 to avoid app size overflow 2 | CONFIG_COMPILER_OPTIMIZATION_SIZE=y 3 | CONFIG_ESP_ROM_HAS_NEWLIB_NANO_FORMAT=y 4 | -------------------------------------------------------------------------------- /examples/emulator/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | 2 | # (Automatically converted from project Makefile by convert_to_cmake.py.) 3 | 4 | # The following lines of boilerplate have to be in your project's CMakeLists 5 | # in this exact order for cmake to work correctly 6 | cmake_minimum_required(VERSION 3.5) 7 | 8 | if(DEFINED ENV{HOMEKIT_PATH}) 9 | set(HOMEKIT_PATH $ENV{HOMEKIT_PATH}) 10 | else() 11 | set(HOMEKIT_PATH ${CMAKE_CURRENT_LIST_DIR}/../..) 12 | endif(DEFINED ENV{HOMEKIT_PATH}) 13 | 14 | set(EXTRA_COMPONENT_DIRS ${HOMEKIT_PATH}/components ${HOMEKIT_PATH}/components/homekit ${CMAKE_CURRENT_LIST_DIR}/../common) 15 | 16 | include($ENV{IDF_PATH}/tools/cmake/project.cmake) 17 | project(emulator) 18 | -------------------------------------------------------------------------------- /examples/emulator/Makefile: -------------------------------------------------------------------------------- 1 | # 2 | # This is a project Makefile. It is assumed the directory this Makefile resides in is a 3 | # project subdirectory. 4 | # 5 | 6 | HOMEKIT_PATH ?= $(abspath $(shell pwd)/../..) 7 | COMMON_COMPONENT_PATH ?= $(abspath $(shell pwd)/../common) 8 | 9 | PROJECT_NAME := emulator 10 | EXTRA_COMPONENT_DIRS += $(HOMEKIT_PATH)/components/ 11 | EXTRA_COMPONENT_DIRS += $(HOMEKIT_PATH)/components/homekit 12 | EXTRA_COMPONENT_DIRS += $(COMMON_COMPONENT_PATH) 13 | 14 | include $(IDF_PATH)/make/project.mk 15 | 16 | -------------------------------------------------------------------------------- /examples/emulator/README.md: -------------------------------------------------------------------------------- 1 | # HomeKit Emulator 2 | 3 | This is a test example which can be used to emulate many standard HomeKit accessories. Set it up as you would do for any of the other examples, Once it boots up, use the console to try out various options 4 | 5 | ## Console 6 | 7 | The prompt `esp32>` would appear on the serial console. Enter `help` to see all the available commands & their usage in the emulator. 8 | 9 | ### Available Commands 10 | 11 | - `profile-list` : Lists all the supported profiles by this homekit sdk. 12 | - `profile ` : Entering a valid profile Id from the profile list will lead to the board emulating the accessory selected after rebooting. 13 | - `read-char (optional) (optional)`: Without any arguments it prints the _characteristics and services of all the accessories_. With an aid it prints all the _characteristics and services pertaining to the given accessory._ With an aid and an iid, it will print the _given characteristic or all characteristics from the given service_. 14 | - `write-char ` : Writes the value to the particular characteristic 15 | - `reset` : Factory resets the device erasing the pairing and provisioning information. 16 | - `reset-pairings` : Erases the pairing information from the device. 17 | - `reset-network`: Erases the network credentials from the device. 18 | - `reboot` : Reboots the accessory. 19 | - `auth ` : Sets the authentication mechanism (None, Hardware or Software auth). 20 | -------------------------------------------------------------------------------- /examples/emulator/emulator_factory.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/espressif/esp-homekit-sdk/bfbcd6e749635d97645380b9d7b32274553fe017/examples/emulator/emulator_factory.bin -------------------------------------------------------------------------------- /examples/emulator/main/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | idf_component_register(SRCS ./app_main.c ./emulator.c ./cmd_register.c ./console_init.c ./console_settings.c 2 | INCLUDE_DIRS ".") 3 | -------------------------------------------------------------------------------- /examples/emulator/main/Kconfig.projbuild: -------------------------------------------------------------------------------- 1 | menu "Example Configuration" 2 | 3 | config EXAMPLE_USE_HARDCODED_SETUP_CODE 4 | bool "Use hard-coded setup code" 5 | default y 6 | help 7 | HomeKit does not recommend having the setup code programmed in the accessory as is. 8 | Instead, it expects setup info (salt-verifier pair) generated for the given setup code. 9 | Use this option only for testing purposes. For production, the setup info should be 10 | used. 11 | 12 | config EXAMPLE_SETUP_CODE 13 | string "HomeKit Setup Code" 14 | default "111-22-333" 15 | depends on EXAMPLE_USE_HARDCODED_SETUP_CODE 16 | help 17 | Setup code to be used for HomeKot pairing, if hard-coded setup code is enabled. 18 | 19 | config EXAMPLE_SETUP_ID 20 | string "HomeKit Setup Id" 21 | default "ES32" 22 | depends on EXAMPLE_USE_HARDCODED_SETUP_CODE 23 | help 24 | Setup id to be used for HomeKot pairing, if hard-coded setup code is enabled. 25 | 26 | endmenu 27 | -------------------------------------------------------------------------------- /examples/emulator/main/component.mk: -------------------------------------------------------------------------------- 1 | # 2 | # "main" pseudo-component makefile. 3 | # 4 | # (Uses default behaviour of compiling all source files in directory, adding 'include' to include path.) 5 | -------------------------------------------------------------------------------- /examples/emulator/main/console_init.c: -------------------------------------------------------------------------------- 1 | /* Console example 2 | 3 | This example code is in the Public Domain (or CC0 licensed, at your option.) 4 | 5 | Unless required by applicable law or agreed to in writing, this 6 | software is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 7 | CONDITIONS OF ANY KIND, either express or implied. 8 | */ 9 | 10 | #include 11 | #include 12 | #include "esp_system.h" 13 | #include "esp_log.h" 14 | #include "esp_console.h" 15 | #include "driver/uart.h" 16 | #include "linenoise/linenoise.h" 17 | #include "argtable3/argtable3.h" 18 | #include "emulator.h" 19 | #include "console_settings.h" 20 | 21 | void console_init() 22 | { 23 | /* Initialize console peripheral */ 24 | initialize_console_peripheral(); 25 | 26 | /* Initialize the console library */ 27 | initialize_console_library(NULL); /* NULL since we're not using history */ 28 | 29 | /* Register commands */ 30 | esp_console_register_help_command(); 31 | register_system(); 32 | 33 | /* Set up the prompt */ 34 | const char* prompt = setup_prompt("esp32>"); 35 | 36 | linenoiseSetDumbMode(1); 37 | 38 | if (linenoiseIsDumbMode()) { 39 | printf("\n" 40 | "Your terminal application does not support escape sequences.\n" 41 | "Line editing and history features are disabled.\n" 42 | "On Windows, try using Putty instead.\n"); 43 | } 44 | 45 | /* Main loop */ 46 | while(true) { 47 | /* Get a line using linenoise. 48 | * The line is returned when ENTER is pressed. 49 | */ 50 | char* line = linenoise(prompt); 51 | if (line == NULL) { /* Ignore empty lines */ 52 | continue; 53 | } 54 | 55 | /* Try to run the command */ 56 | int ret; 57 | esp_err_t err = esp_console_run(line, &ret); 58 | if (err == ESP_ERR_NOT_FOUND) { 59 | printf("Unrecognized command\n"); 60 | } else if (err == ESP_ERR_INVALID_ARG) { 61 | /* command was empty */ 62 | } else if (err == ESP_OK && ret != ESP_OK) { 63 | printf("Command returned non-zero error code: 0x%x\n", ret); 64 | } else if (err != ESP_OK) { 65 | printf("Internal error: 0x%x\n", err); 66 | } 67 | /* linenoise allocates line buffer on the heap, so need to free it */ 68 | linenoiseFree(line); 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /examples/emulator/main/console_settings.c: -------------------------------------------------------------------------------- 1 | /* 2 | * SPDX-FileCopyrightText: 2024 Espressif Systems (Shanghai) CO LTD 3 | * 4 | * SPDX-License-Identifier: Apache-2.0 5 | */ 6 | 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include "esp_system.h" 12 | #include "esp_log.h" 13 | #include "esp_console.h" 14 | #if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5, 3, 0) 15 | #include "driver/uart_vfs.h" 16 | #else 17 | #include "esp_vfs_dev.h" 18 | #endif 19 | #include "driver/uart.h" 20 | #include "linenoise/linenoise.h" 21 | #include "argtable3/argtable3.h" 22 | 23 | #define CONSOLE_MAX_CMDLINE_ARGS 8 24 | #define CONSOLE_MAX_CMDLINE_LENGTH 256 25 | #define CONSOLE_PROMPT_MAX_LEN (32) 26 | 27 | static char prompt[CONSOLE_PROMPT_MAX_LEN]; /* Prompt to be printed before each line */ 28 | 29 | void initialize_console_peripheral(void) 30 | { 31 | /* Drain stdout before reconfiguring it */ 32 | fflush(stdout); 33 | fsync(fileno(stdout)); 34 | 35 | #if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5, 3, 0) 36 | /* Minicom, screen, idf_monitor send CR when ENTER key is pressed */ 37 | uart_vfs_dev_port_set_rx_line_endings(CONFIG_ESP_CONSOLE_UART_NUM, ESP_LINE_ENDINGS_CR); 38 | /* Move the caret to the beginning of the next line on '\n' */ 39 | uart_vfs_dev_port_set_tx_line_endings(CONFIG_ESP_CONSOLE_UART_NUM, ESP_LINE_ENDINGS_CRLF); 40 | #else 41 | /* Minicom, screen, idf_monitor send CR when ENTER key is pressed */ 42 | esp_vfs_dev_uart_set_rx_line_endings(ESP_LINE_ENDINGS_CR); 43 | /* Move the caret to the beginning of the next line on '\n' */ 44 | esp_vfs_dev_uart_set_tx_line_endings(ESP_LINE_ENDINGS_CRLF); 45 | #endif 46 | 47 | /* Configure UART */ 48 | const uart_config_t uart_config = { 49 | .baud_rate = CONFIG_ESP_CONSOLE_UART_BAUDRATE, 50 | .data_bits = UART_DATA_8_BITS, 51 | .parity = UART_PARITY_DISABLE, 52 | .stop_bits = UART_STOP_BITS_1, 53 | #if SOC_UART_SUPPORT_REF_TICK 54 | .source_clk = UART_SCLK_REF_TICK, 55 | #elif SOC_UART_SUPPORT_XTAL_CLK 56 | .source_clk = UART_SCLK_XTAL, 57 | #endif 58 | }; 59 | 60 | /* Install UART driver for interrupt-driven reads and writes */ 61 | ESP_ERROR_CHECK(uart_driver_install(CONFIG_ESP_CONSOLE_UART_NUM, 256, 0, 0, NULL, 0)); 62 | ESP_ERROR_CHECK(uart_param_config(CONFIG_ESP_CONSOLE_UART_NUM, &uart_config)); 63 | 64 | #if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5, 3, 0) 65 | /* Tell VFS to use UART driver */ 66 | uart_vfs_dev_use_driver(CONFIG_ESP_CONSOLE_UART_NUM); 67 | #endif 68 | /* Disable buffering on stdin */ 69 | setvbuf(stdin, NULL, _IONBF, 0); 70 | } 71 | 72 | void initialize_console_library(const char *history_path) 73 | { 74 | /* Initialize the console */ 75 | esp_console_config_t console_config = { 76 | .max_cmdline_args = CONSOLE_MAX_CMDLINE_ARGS, 77 | .max_cmdline_length = CONSOLE_MAX_CMDLINE_LENGTH, 78 | #if CONFIG_LOG_COLORS 79 | .hint_color = atoi(LOG_COLOR_CYAN) 80 | #endif 81 | }; 82 | ESP_ERROR_CHECK(esp_console_init(&console_config)); 83 | 84 | /* Set command maximum length */ 85 | linenoiseSetMaxLineLen(console_config.max_cmdline_length); 86 | /* Don't return empty lines */ 87 | linenoiseAllowEmpty(false); 88 | 89 | #if CONFIG_CONSOLE_STORE_HISTORY 90 | /* Load command history from filesystem */ 91 | linenoiseHistoryLoad(history_path); 92 | #endif 93 | } 94 | 95 | char *setup_prompt(const char *prompt_str) 96 | { 97 | /* set command line prompt */ 98 | const char *prompt_temp = "esp32>"; 99 | if (prompt_str) { 100 | prompt_temp = prompt_str; 101 | } 102 | 103 | snprintf(prompt, CONSOLE_PROMPT_MAX_LEN - 1, LOG_COLOR_I "%s " LOG_RESET_COLOR, prompt_temp); 104 | 105 | if (linenoiseIsDumbMode()) { 106 | #if CONFIG_LOG_COLORS 107 | /* Since the terminal doesn't support escape sequences, 108 | * don't use color codes in the prompt. 109 | */ 110 | snprintf(prompt, CONSOLE_PROMPT_MAX_LEN - 1, "%s ", prompt_temp); 111 | #endif 112 | } 113 | return prompt; 114 | } 115 | -------------------------------------------------------------------------------- /examples/emulator/main/console_settings.h: -------------------------------------------------------------------------------- 1 | /* 2 | * SPDX-FileCopyrightText: 2024 Espressif Systems (Shanghai) CO LTD 3 | * 4 | * SPDX-License-Identifier: Apache-2.0 5 | */ 6 | 7 | #pragma once 8 | 9 | /** 10 | * @brief Initialize console peripheral type 11 | * 12 | * Console peripheral is based on sdkconfig settings 13 | * 14 | * UART CONFIG_ESP_CONSOLE_UART_DEFAULT 15 | * USB_OTG CONFIG_ESP_CONSOLE_USB_CDC 16 | * USB_SERIAL_JTAG CONFIG_ESP_CONSOLE_USB_SERIAL_JTAG 17 | */ 18 | void initialize_console_peripheral(void); 19 | 20 | /** 21 | * @brief Initialize linenoise and esp console 22 | * 23 | * This function initialize linenoise library and esp_console component, 24 | * also checks if the terminal supports escape sequences 25 | * 26 | * @param history_path Path to store command history 27 | */ 28 | void initialize_console_library(const char *history_path); 29 | 30 | /** 31 | * @brief Initialize console prompt 32 | * 33 | * This function adds color code to the prompt (if the console supports escape sequences) 34 | * 35 | * @param prompt_str Prompt in form of string eg esp32> 36 | * 37 | * @return 38 | * - pointer to initialized prompt 39 | */ 40 | char *setup_prompt(const char *prompt_str); -------------------------------------------------------------------------------- /examples/emulator/main/emulator.h: -------------------------------------------------------------------------------- 1 | #ifndef _EMULATOR_H_ 2 | #define _EMULATOR_H_ 3 | #include 4 | 5 | typedef struct { 6 | hap_cid_t cid; 7 | char *name; 8 | hap_serv_t * (*serv_create) (void); 9 | } hap_emulator_profile_t; 10 | int emulator_write(hap_write_data_t write_data[], int count, 11 | void *serv_priv, void *write_priv); 12 | hap_emulator_profile_t * emulator_get_profile(); 13 | int emulator_get_state(); 14 | void emulator_get_characteristics(); 15 | void emulator_read_chars(int num, ...); 16 | void emulator_write_char(int aid, int iid, char *sval); 17 | void emulator_show_profiles(); 18 | void emulator_reset_to_factory(); 19 | void emulator_reset_pairings(); 20 | void emulator_switch_profile(int profile); 21 | void emulator_set_wac(); 22 | void emulator_set_auth(); 23 | void emulator_reset_wifi_credentials(); 24 | void emulator_reboot_accessory(); 25 | void console_init(); 26 | void register_system(); 27 | 28 | #endif /* _EMULATOR_H_ */ 29 | -------------------------------------------------------------------------------- /examples/emulator/partitions_hap.csv: -------------------------------------------------------------------------------- 1 | # Name, Type, SubType, Offset, Size, Flags 2 | # Note: Firmware partition offset needs to be 64K aligned, initial 36K (9 sectors) are reserved for bootloader and partition table 3 | sec_cert, 0x3F, ,0xd000, 0x3000, , # Never mark this as an encrypted partition 4 | nvs, data, nvs, 0x10000, 0x6000, 5 | otadata, data, ota, , 0x2000 6 | phy_init, data, phy, , 0x1000, 7 | ota_0, app, ota_0, 0x20000, 1600K, 8 | ota_1, app, ota_1, , 1600K, 9 | factory_nvs, data, nvs, 0x340000, 0x6000 10 | nvs_keys, data, nvs_keys,0x346000, 0x1000 11 | -------------------------------------------------------------------------------- /examples/emulator/sdkconfig.defaults: -------------------------------------------------------------------------------- 1 | CONFIG_PARTITION_TABLE_CUSTOM=y 2 | CONFIG_PARTITION_TABLE_CUSTOM_FILENAME="partitions_hap.csv" 3 | CONFIG_PARTITION_TABLE_CUSTOM_APP_BIN_OFFSET=0x10000 4 | CONFIG_FREERTOS_UNICORE=y 5 | CONFIG_FREERTOS_ASSERT_ON_UNTESTED_FUNCTION=n 6 | CONFIG_FREERTOS_ASSERT_FAIL_ABORT=n 7 | CONFIG_FREERTOS_ASSERT_DISABLE=y 8 | CONFIG_LWIP_MAX_SOCKETS=16 9 | CONFIG_LWIP_SO_REUSE=y 10 | CONFIG_LWIP_MAX_ACTIVE_TCP=12 11 | CONFIG_LWIP_MAX_LISTENING_TCP=12 12 | CONFIG_LWIP_UDP_RECVMBOX_SIZE=10 13 | CONFIG_MBEDTLS_HARDWARE_MPI=y 14 | CONFIG_MBEDTLS_HARDWARE_SHA=n 15 | CONFIG_ESP_TASK_WDT=n 16 | CONFIG_LWIP_AUTOIP=y 17 | CONFIG_ESPTOOLPY_FLASHSIZE_4MB=y 18 | CONFIG_LWIP_AUTOIP_RATE_LIMIT_INTERVAL=60 19 | CONFIG_MP_BLOB_SUPPORT=y 20 | CONFIG_LOG_DEFAULT_LEVEL_ERROR=y 21 | CONFIG_BOOTLOADER_LOG_LEVEL_ERROR=y 22 | CONFIG_ENABLE_UNIFIED_PROVISIONING=y 23 | CONFIG_BT_ENABLED=y 24 | CONFIG_BTDM_CTRL_MODE_BLE_ONLY=y 25 | CONFIG_BT_NIMBLE_ENABLED=y -------------------------------------------------------------------------------- /examples/emulator/sdkconfig.defaults.esp32c6: -------------------------------------------------------------------------------- 1 | # perform the size optimized builds for C6 to avoid app size overflow 2 | CONFIG_COMPILER_OPTIMIZATION_SIZE=y 3 | CONFIG_ESP_ROM_HAS_NEWLIB_NANO_FORMAT=y 4 | -------------------------------------------------------------------------------- /examples/fan/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | 2 | # (Automatically converted from project Makefile by convert_to_cmake.py.) 3 | 4 | # The following lines of boilerplate have to be in your project's CMakeLists 5 | # in this exact order for cmake to work correctly 6 | cmake_minimum_required(VERSION 3.5) 7 | 8 | if(DEFINED ENV{HOMEKIT_PATH}) 9 | set(HOMEKIT_PATH $ENV{HOMEKIT_PATH}) 10 | else() 11 | set(HOMEKIT_PATH ${CMAKE_CURRENT_LIST_DIR}/../..) 12 | endif(DEFINED ENV{HOMEKIT_PATH}) 13 | 14 | set(EXTRA_COMPONENT_DIRS ${HOMEKIT_PATH}/components ${HOMEKIT_PATH}/components/homekit ${CMAKE_CURRENT_LIST_DIR}/../common) 15 | 16 | include($ENV{IDF_PATH}/tools/cmake/project.cmake) 17 | project(fan) 18 | -------------------------------------------------------------------------------- /examples/fan/Makefile: -------------------------------------------------------------------------------- 1 | # 2 | # This is a project Makefile. It is assumed the directory this Makefile resides in is a 3 | # project subdirectory. 4 | # 5 | 6 | HOMEKIT_PATH ?= $(abspath $(shell pwd)/../..) 7 | COMMON_COMPONENT_PATH ?= $(abspath $(shell pwd)/../common) 8 | 9 | PROJECT_NAME := fan 10 | EXTRA_COMPONENT_DIRS += $(HOMEKIT_PATH)/components/ 11 | EXTRA_COMPONENT_DIRS += $(HOMEKIT_PATH)/components/homekit 12 | EXTRA_COMPONENT_DIRS += $(COMMON_COMPONENT_PATH) 13 | 14 | include $(IDF_PATH)/make/project.mk 15 | 16 | -------------------------------------------------------------------------------- /examples/fan/fan_factory.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/espressif/esp-homekit-sdk/bfbcd6e749635d97645380b9d7b32274553fe017/examples/fan/fan_factory.bin -------------------------------------------------------------------------------- /examples/fan/main/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | idf_component_register(SRCS ./app_main.c) 2 | -------------------------------------------------------------------------------- /examples/fan/main/Kconfig.projbuild: -------------------------------------------------------------------------------- 1 | menu "Example Configuration" 2 | 3 | config EXAMPLE_USE_HARDCODED_SETUP_CODE 4 | bool "Use hard-coded setup code" 5 | default y 6 | help 7 | HomeKit does not recommend having the setup code programmed in the accessory as is. 8 | Instead, it expects setup info (salt-verifier pair) generated for the given setup code. 9 | Use this option only for testing purposes. For production, the setup info should be 10 | used. 11 | 12 | config EXAMPLE_SETUP_CODE 13 | string "HomeKit Setup Code" 14 | default "111-22-333" 15 | depends on EXAMPLE_USE_HARDCODED_SETUP_CODE 16 | help 17 | Setup code to be used for HomeKot pairing, if hard-coded setup code is enabled. 18 | 19 | config EXAMPLE_SETUP_ID 20 | string "HomeKit Setup Id" 21 | default "ES32" 22 | depends on EXAMPLE_USE_HARDCODED_SETUP_CODE 23 | help 24 | Setup id to be used for HomeKot pairing, if hard-coded setup code is enabled. 25 | 26 | endmenu 27 | -------------------------------------------------------------------------------- /examples/fan/main/component.mk: -------------------------------------------------------------------------------- 1 | # 2 | # "main" pseudo-component makefile. 3 | # 4 | # (Uses default behaviour of compiling all source files in directory, adding 'include' to include path.) 5 | -------------------------------------------------------------------------------- /examples/fan/partitions_hap.csv: -------------------------------------------------------------------------------- 1 | # Name, Type, SubType, Offset, Size, Flags 2 | # Note: Firmware partition offset needs to be 64K aligned, initial 36K (9 sectors) are reserved for bootloader and partition table 3 | sec_cert, 0x3F, ,0xd000, 0x3000, , # Never mark this as an encrypted partition 4 | nvs, data, nvs, 0x10000, 0x6000, 5 | otadata, data, ota, , 0x2000 6 | phy_init, data, phy, , 0x1000, 7 | ota_0, app, ota_0, 0x20000, 1600K, 8 | ota_1, app, ota_1, , 1600K, 9 | factory_nvs, data, nvs, 0x340000, 0x6000 10 | nvs_keys, data, nvs_keys,0x346000, 0x1000 11 | -------------------------------------------------------------------------------- /examples/fan/sdkconfig.defaults: -------------------------------------------------------------------------------- 1 | CONFIG_PARTITION_TABLE_CUSTOM=y 2 | CONFIG_PARTITION_TABLE_CUSTOM_FILENAME="partitions_hap.csv" 3 | CONFIG_PARTITION_TABLE_CUSTOM_APP_BIN_OFFSET=0x10000 4 | CONFIG_FREERTOS_UNICORE=y 5 | CONFIG_FREERTOS_ASSERT_ON_UNTESTED_FUNCTION=n 6 | CONFIG_FREERTOS_ASSERT_FAIL_ABORT=n 7 | CONFIG_FREERTOS_ASSERT_DISABLE=y 8 | CONFIG_LWIP_MAX_SOCKETS=16 9 | CONFIG_LWIP_SO_REUSE=y 10 | CONFIG_LWIP_MAX_ACTIVE_TCP=12 11 | CONFIG_LWIP_MAX_LISTENING_TCP=12 12 | CONFIG_LWIP_UDP_RECVMBOX_SIZE=10 13 | CONFIG_MBEDTLS_HARDWARE_MPI=y 14 | CONFIG_MBEDTLS_HARDWARE_SHA=n 15 | CONFIG_ESP_TASK_WDT=n 16 | CONFIG_LWIP_AUTOIP=y 17 | CONFIG_ESPTOOLPY_FLASHSIZE_4MB=y 18 | CONFIG_LWIP_AUTOIP_RATE_LIMIT_INTERVAL=60 19 | CONFIG_MP_BLOB_SUPPORT=y 20 | CONFIG_ENABLE_UNIFIED_PROVISIONING=y 21 | CONFIG_BT_ENABLED=y 22 | CONFIG_BTDM_CTRL_MODE_BLE_ONLY=y 23 | CONFIG_BT_NIMBLE_ENABLED=y -------------------------------------------------------------------------------- /examples/fan/sdkconfig.defaults.esp32c6: -------------------------------------------------------------------------------- 1 | # perform the size optimized builds for C6 to avoid app size overflow 2 | CONFIG_COMPILER_OPTIMIZATION_SIZE=y 3 | CONFIG_ESP_ROM_HAS_NEWLIB_NANO_FORMAT=y 4 | -------------------------------------------------------------------------------- /examples/lightbulb/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | 2 | # (Automatically converted from project Makefile by convert_to_cmake.py.) 3 | 4 | # The following lines of boilerplate have to be in your project's CMakeLists 5 | # in this exact order for cmake to work correctly 6 | cmake_minimum_required(VERSION 3.5) 7 | 8 | if(DEFINED ENV{HOMEKIT_PATH}) 9 | set(HOMEKIT_PATH $ENV{HOMEKIT_PATH}) 10 | else() 11 | set(HOMEKIT_PATH ${CMAKE_CURRENT_LIST_DIR}/../..) 12 | endif(DEFINED ENV{HOMEKIT_PATH}) 13 | 14 | set(EXTRA_COMPONENT_DIRS ${HOMEKIT_PATH}/components ${HOMEKIT_PATH}/components/homekit ${CMAKE_CURRENT_LIST_DIR}/../common) 15 | 16 | include($ENV{IDF_PATH}/tools/cmake/project.cmake) 17 | project(lightbulb) 18 | -------------------------------------------------------------------------------- /examples/lightbulb/Makefile: -------------------------------------------------------------------------------- 1 | # 2 | # This is a project Makefile. It is assumed the directory this Makefile resides in is a 3 | # project subdirectory. 4 | # 5 | 6 | HOMEKIT_PATH ?= $(abspath $(shell pwd)/../..) 7 | COMMON_COMPONENT_PATH ?= $(abspath $(shell pwd)/../common) 8 | 9 | PROJECT_NAME := lightbulb 10 | EXTRA_COMPONENT_DIRS += $(HOMEKIT_PATH)/components/ 11 | EXTRA_COMPONENT_DIRS += $(HOMEKIT_PATH)/components/homekit 12 | EXTRA_COMPONENT_DIRS += $(COMMON_COMPONENT_PATH) 13 | 14 | include $(IDF_PATH)/make/project.mk 15 | 16 | -------------------------------------------------------------------------------- /examples/lightbulb/main/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | idf_component_register(SRCS ./app_main.c ./lightbulb.c 2 | INCLUDE_DIRS ".") 3 | -------------------------------------------------------------------------------- /examples/lightbulb/main/Kconfig.projbuild: -------------------------------------------------------------------------------- 1 | menu "Example Configuration" 2 | 3 | config EXAMPLE_USE_HARDCODED_SETUP_CODE 4 | bool "Use hard-coded setup code" 5 | default y 6 | help 7 | HomeKit does not recommend having the setup code programmed in the accessory as is. 8 | Instead, it expects setup info (salt-verifier pair) generated for the given setup code. 9 | Use this option only for testing purposes. For production, the setup info should be 10 | used. 11 | 12 | config EXAMPLE_SETUP_CODE 13 | string "HomeKit Setup Code" 14 | default "111-22-333" 15 | depends on EXAMPLE_USE_HARDCODED_SETUP_CODE 16 | help 17 | Setup code to be used for HomeKot pairing, if hard-coded setup code is enabled. 18 | 19 | config EXAMPLE_SETUP_ID 20 | string "HomeKit Setup Id" 21 | default "ES32" 22 | depends on EXAMPLE_USE_HARDCODED_SETUP_CODE 23 | help 24 | Setup id to be used for HomeKot pairing, if hard-coded setup code is enabled. 25 | 26 | endmenu 27 | -------------------------------------------------------------------------------- /examples/lightbulb/main/component.mk: -------------------------------------------------------------------------------- 1 | # 2 | # "main" pseudo-component makefile. 3 | # 4 | # (Uses default behaviour of compiling all source files in directory, adding 'include' to include path.) 5 | -------------------------------------------------------------------------------- /examples/lightbulb/main/lightbulb.c: -------------------------------------------------------------------------------- 1 | /* 2 | * ESPRESSIF MIT License 3 | * 4 | * Copyright (c) 2018 5 | * 6 | * Permission is hereby granted for use on ESPRESSIF SYSTEMS products only, in which case, 7 | * it is free of charge, to any person obtaining a copy of this software and associated 8 | * documentation files (the "Software"), to deal in the Software without restriction, including 9 | * without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, 10 | * and/or sell copies of the Software, and to permit persons to whom the Software is furnished 11 | * to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all copies or 14 | * 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, FITNESS 18 | * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 19 | * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 20 | * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 21 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 22 | * 23 | */ 24 | 25 | /* HomeKit Lightbulb Example Dummy Implementation 26 | * Refer ESP IDF docs for LED driver implementation: 27 | * https://docs.espressif.com/projects/esp-idf/en/latest/esp32/api-reference/peripherals/ledc.html 28 | * https://docs.espressif.com/projects/esp-idf/en/latest/esp32/api-reference/peripherals/rmt.html 29 | */ 30 | 31 | #include 32 | #include 33 | #include "esp_log.h" 34 | 35 | static const char *TAG = "lightbulb"; 36 | 37 | /** 38 | * @brief initialize the lightbulb lowlevel module 39 | */ 40 | void lightbulb_init(void) 41 | { 42 | ESP_LOGI(TAG, "Dummy Light Driver Init."); 43 | } 44 | 45 | /** 46 | * @brief turn on/off the lowlevel lightbulb 47 | */ 48 | int lightbulb_set_on(bool value) 49 | { 50 | ESP_LOGI(TAG, "lightbulb_set_on : %s", value == true ? "true" : "false"); 51 | return 0; 52 | } 53 | 54 | /** 55 | * @brief set the saturation of the lowlevel lightbulb 56 | */ 57 | int lightbulb_set_saturation(float value) 58 | { 59 | ESP_LOGI(TAG, "lightbulb_set_saturation : %f", value); 60 | return 0; 61 | } 62 | 63 | /** 64 | * @brief set the hue of the lowlevel lightbulb 65 | */ 66 | int lightbulb_set_hue(float value) 67 | { 68 | ESP_LOGI(TAG, "lightbulb_set_hue : %f", value); 69 | return 0; 70 | } 71 | 72 | /** 73 | * @brief set the brightness of the lowlevel lightbulb 74 | */ 75 | int lightbulb_set_brightness(int value) 76 | { 77 | ESP_LOGI(TAG, "lightbulb_set_brightness : %d", value); 78 | return 0; 79 | } 80 | -------------------------------------------------------------------------------- /examples/lightbulb/main/lightbulb.h: -------------------------------------------------------------------------------- 1 | /* 2 | * ESPRESSIF MIT License 3 | * 4 | * Copyright (c) 2018 5 | * 6 | * Permission is hereby granted for use on ESPRESSIF SYSTEMS products only, in which case, 7 | * it is free of charge, to any person obtaining a copy of this software and associated 8 | * documentation files (the "Software"), to deal in the Software without restriction, including 9 | * without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, 10 | * and/or sell copies of the Software, and to permit persons to whom the Software is furnished 11 | * to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all copies or 14 | * 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, FITNESS 18 | * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 19 | * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 20 | * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 21 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 22 | * 23 | */ 24 | 25 | /* HomeKit Lightbulb Example 26 | */ 27 | 28 | #ifndef _LIGHTBULB_H_ 29 | #define _LIGHTBULB_H_ 30 | 31 | /** 32 | * @brief initialize the lightbulb lowlevel module 33 | * 34 | * @param none 35 | * 36 | * @return none 37 | */ 38 | void lightbulb_init(void); 39 | 40 | /** 41 | * @brief deinitialize the lightbulb's lowlevel module 42 | * 43 | * @param none 44 | * 45 | * @return none 46 | */ 47 | void lightbulb_deinit(void); 48 | 49 | /** 50 | * @brief turn on/off the lowlevel lightbulb 51 | * 52 | * @param value The "On" value 53 | * 54 | * @return none 55 | */ 56 | int lightbulb_set_on(bool value); 57 | 58 | /** 59 | * @brief set the saturation of the lowlevel lightbulb 60 | * 61 | * @param value The Saturation value 62 | * 63 | * @return 64 | * - 0 : OK 65 | * - others : fail 66 | */ 67 | int lightbulb_set_saturation(float value); 68 | 69 | /** 70 | * @brief set the hue of the lowlevel lightbulb 71 | * 72 | * @param value The Hue value 73 | * 74 | * @return 75 | * - 0 : OK 76 | * - others : fail 77 | */ 78 | int lightbulb_set_hue(float value); 79 | 80 | /** 81 | * @brief set the brightness of the lowlevel lightbulb 82 | * 83 | * @param value The Brightness value 84 | * 85 | * @return 86 | * - 0 : OK 87 | * - others : fail 88 | */ 89 | int lightbulb_set_brightness(int value); 90 | 91 | #endif /* _LIGHTBULB_H_ */ 92 | -------------------------------------------------------------------------------- /examples/lightbulb/partitions_hap.csv: -------------------------------------------------------------------------------- 1 | # Name, Type, SubType, Offset, Size, Flags 2 | # Note: Firmware partition offset needs to be 64K aligned, initial 36K (9 sectors) are reserved for bootloader and partition table 3 | sec_cert, 0x3F, ,0xd000, 0x3000, , # Never mark this as an encrypted partition 4 | nvs, data, nvs, 0x10000, 0x6000, 5 | otadata, data, ota, , 0x2000 6 | phy_init, data, phy, , 0x1000, 7 | ota_0, app, ota_0, 0x20000, 1600K, 8 | ota_1, app, ota_1, , 1600K, 9 | factory_nvs, data, nvs, 0x340000, 0x6000 10 | nvs_keys, data, nvs_keys,0x346000, 0x1000 11 | -------------------------------------------------------------------------------- /examples/lightbulb/sdkconfig.defaults: -------------------------------------------------------------------------------- 1 | CONFIG_PARTITION_TABLE_CUSTOM=y 2 | CONFIG_PARTITION_TABLE_CUSTOM_FILENAME="partitions_hap.csv" 3 | CONFIG_PARTITION_TABLE_CUSTOM_APP_BIN_OFFSET=0x10000 4 | CONFIG_FREERTOS_UNICORE=y 5 | CONFIG_FREERTOS_ASSERT_ON_UNTESTED_FUNCTION=n 6 | CONFIG_FREERTOS_ASSERT_FAIL_ABORT=n 7 | CONFIG_FREERTOS_ASSERT_DISABLE=y 8 | CONFIG_LWIP_MAX_SOCKETS=16 9 | CONFIG_LWIP_SO_REUSE=y 10 | CONFIG_LWIP_MAX_ACTIVE_TCP=12 11 | CONFIG_LWIP_MAX_LISTENING_TCP=12 12 | CONFIG_LWIP_UDP_RECVMBOX_SIZE=10 13 | CONFIG_MBEDTLS_HARDWARE_MPI=y 14 | CONFIG_MBEDTLS_HARDWARE_SHA=n 15 | CONFIG_ESP_TASK_WDT=n 16 | CONFIG_LWIP_AUTOIP=y 17 | CONFIG_ESPTOOLPY_FLASHSIZE_4MB=y 18 | CONFIG_LWIP_AUTOIP_RATE_LIMIT_INTERVAL=60 19 | CONFIG_MP_BLOB_SUPPORT=y 20 | CONFIG_ENABLE_UNIFIED_PROVISIONING=y 21 | CONFIG_BT_ENABLED=y 22 | CONFIG_BTDM_CTRL_MODE_BLE_ONLY=y 23 | CONFIG_BT_NIMBLE_ENABLED=y -------------------------------------------------------------------------------- /examples/lightbulb/sdkconfig.defaults.esp32c6: -------------------------------------------------------------------------------- 1 | # perform the size optimized builds for C6 to avoid app size overflow 2 | CONFIG_COMPILER_OPTIMIZATION_SIZE=y 3 | CONFIG_ESP_ROM_HAS_NEWLIB_NANO_FORMAT=y 4 | -------------------------------------------------------------------------------- /examples/smart_outlet/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | 2 | # (Automatically converted from project Makefile by convert_to_cmake.py.) 3 | 4 | # The following lines of boilerplate have to be in your project's CMakeLists 5 | # in this exact order for cmake to work correctly 6 | cmake_minimum_required(VERSION 3.5) 7 | 8 | if(DEFINED ENV{HOMEKIT_PATH}) 9 | set(HOMEKIT_PATH $ENV{HOMEKIT_PATH}) 10 | else() 11 | set(HOMEKIT_PATH ${CMAKE_CURRENT_LIST_DIR}/../..) 12 | endif(DEFINED ENV{HOMEKIT_PATH}) 13 | 14 | set(EXTRA_COMPONENT_DIRS ${HOMEKIT_PATH}/components ${HOMEKIT_PATH}/components/homekit ${CMAKE_CURRENT_LIST_DIR}/../common) 15 | 16 | include($ENV{IDF_PATH}/tools/cmake/project.cmake) 17 | project(smart_outlet) 18 | -------------------------------------------------------------------------------- /examples/smart_outlet/Makefile: -------------------------------------------------------------------------------- 1 | # 2 | # This is a project Makefile. It is assumed the directory this Makefile resides in is a 3 | # project subdirectory. 4 | # 5 | 6 | HOMEKIT_PATH ?= $(abspath $(shell pwd)/../..) 7 | COMMON_COMPONENT_PATH ?= $(abspath $(shell pwd)/../common) 8 | 9 | PROJECT_NAME := smart_outlet 10 | EXTRA_COMPONENT_DIRS += $(HOMEKIT_PATH)/components/ 11 | EXTRA_COMPONENT_DIRS += $(HOMEKIT_PATH)/components/homekit 12 | EXTRA_COMPONENT_DIRS += $(COMMON_COMPONENT_PATH) 13 | 14 | include $(IDF_PATH)/make/project.mk 15 | 16 | -------------------------------------------------------------------------------- /examples/smart_outlet/main/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | idf_component_register(SRCS ./app_main.c) 2 | -------------------------------------------------------------------------------- /examples/smart_outlet/main/Kconfig.projbuild: -------------------------------------------------------------------------------- 1 | menu "Example Configuration" 2 | 3 | config EXAMPLE_USE_HARDCODED_SETUP_CODE 4 | bool "Use hard-coded setup code" 5 | default y 6 | help 7 | HomeKit does not recommend having the setup code programmed in the accessory as is. 8 | Instead, it expects setup info (salt-verifier pair) generated for the given setup code. 9 | Use this option only for testing purposes. For production, the setup info should be 10 | used. 11 | 12 | config EXAMPLE_SETUP_CODE 13 | string "HomeKit Setup Code" 14 | default "111-22-333" 15 | depends on EXAMPLE_USE_HARDCODED_SETUP_CODE 16 | help 17 | Setup code to be used for HomeKot pairing, if hard-coded setup code is enabled. 18 | 19 | config EXAMPLE_SETUP_ID 20 | string "HomeKit Setup Id" 21 | default "ES32" 22 | depends on EXAMPLE_USE_HARDCODED_SETUP_CODE 23 | help 24 | Setup id to be used for HomeKot pairing, if hard-coded setup code is enabled. 25 | 26 | endmenu 27 | -------------------------------------------------------------------------------- /examples/smart_outlet/main/component.mk: -------------------------------------------------------------------------------- 1 | # 2 | # "main" pseudo-component makefile. 3 | # 4 | # (Uses default behaviour of compiling all source files in directory, adding 'include' to include path.) 5 | -------------------------------------------------------------------------------- /examples/smart_outlet/partitions_hap.csv: -------------------------------------------------------------------------------- 1 | # Name, Type, SubType, Offset, Size, Flags 2 | # Note: Firmware partition offset needs to be 64K aligned, initial 36K (9 sectors) are reserved for bootloader and partition table 3 | sec_cert, 0x3F, ,0xd000, 0x3000, , # Never mark this as an encrypted partition 4 | nvs, data, nvs, 0x10000, 0x6000, 5 | otadata, data, ota, , 0x2000 6 | phy_init, data, phy, , 0x1000, 7 | ota_0, app, ota_0, 0x20000, 1600K, 8 | ota_1, app, ota_1, , 1600K, 9 | factory_nvs, data, nvs, 0x340000, 0x6000 10 | nvs_keys, data, nvs_keys,0x346000, 0x1000 11 | -------------------------------------------------------------------------------- /examples/smart_outlet/sdkconfig.defaults: -------------------------------------------------------------------------------- 1 | CONFIG_PARTITION_TABLE_CUSTOM=y 2 | CONFIG_PARTITION_TABLE_CUSTOM_FILENAME="partitions_hap.csv" 3 | CONFIG_PARTITION_TABLE_CUSTOM_APP_BIN_OFFSET=0x10000 4 | CONFIG_FREERTOS_UNICORE=y 5 | CONFIG_FREERTOS_ASSERT_ON_UNTESTED_FUNCTION=n 6 | CONFIG_FREERTOS_ASSERT_FAIL_ABORT=n 7 | CONFIG_FREERTOS_ASSERT_DISABLE=y 8 | CONFIG_LWIP_MAX_SOCKETS=16 9 | CONFIG_LWIP_SO_REUSE=y 10 | CONFIG_LWIP_MAX_ACTIVE_TCP=12 11 | CONFIG_LWIP_MAX_LISTENING_TCP=12 12 | CONFIG_LWIP_UDP_RECVMBOX_SIZE=10 13 | CONFIG_MBEDTLS_HARDWARE_MPI=y 14 | CONFIG_MBEDTLS_HARDWARE_SHA=n 15 | CONFIG_ESP_TASK_WDT=n 16 | CONFIG_LWIP_AUTOIP=y 17 | CONFIG_ESPTOOLPY_FLASHSIZE_4MB=y 18 | CONFIG_LWIP_AUTOIP_RATE_LIMIT_INTERVAL=60 19 | CONFIG_MP_BLOB_SUPPORT=y 20 | CONFIG_ENABLE_UNIFIED_PROVISIONING=y 21 | CONFIG_BT_ENABLED=y 22 | CONFIG_BTDM_CTRL_MODE_BLE_ONLY=y 23 | CONFIG_BT_NIMBLE_ENABLED=y -------------------------------------------------------------------------------- /examples/smart_outlet/sdkconfig.defaults.esp32c6: -------------------------------------------------------------------------------- 1 | # perform the size optimized builds for C6 to avoid app size overflow 2 | CONFIG_COMPILER_OPTIMIZATION_SIZE=y 3 | CONFIG_ESP_ROM_HAS_NEWLIB_NANO_FORMAT=y 4 | -------------------------------------------------------------------------------- /tools/factory_nvs_gen/README.md: -------------------------------------------------------------------------------- 1 | # Factory NVS Generator 2 | 3 | ## Introduction 4 | 5 | factory\_nvs\_gen is a Python script that can be used to generate the Factory NVS Partition image with 6 | accessory setup information like setup\_id, setup\_salt and setup\_verifier. Using such images, the same 7 | firmware can be used for multiple accessories, as the setup information is no more a part of the 8 | firmware, but read from a different partition. 9 | 10 | Using this needs the factory\_nvs partition in partition table. Please check the partitions\_hap.csv 11 | file in the example accessories for reference. Using the same file for your accessory is recommended. 12 | 13 | ## Usage 14 | 15 | This utility requires the python library "srp". If not available already, please install using 16 | 17 | ``` 18 | pip install srp 19 | ``` 20 | 21 | The Utility can then be used as below: 22 | 23 | ``` 24 | usage: ./factory_nvs_gen.py [-h] [--infile INFILE] [--size SIZE] 25 | [--version {v1,v2}] [--keygen {true,false}] 26 | [--encrypt {true,false}] [--keyfile KEYFILE] 27 | setup_code setup_id outfile 28 | 29 | Factory NVS Generator 30 | 31 | optional arguments: 32 | -h, --help show this help message and exit 33 | 34 | To generate Factory NVS partition: 35 | setup_code the input setup code without hyphens Eg.: 11122333 36 | setup_id the input setup identifer Eg.: ES32 37 | --infile INFILE the input csv file with extension(full path) to add 38 | HomeKit data generated to this file Eg.: fan_data.csv 39 | outfile the output csv and bin filename without extension Eg.: 40 | fan_factory 41 | --size SIZE Size of NVS Partition in bytes (must be multiple of 42 | 4096) 43 | --version {v1,v2} Set version. Default: v2 44 | --keygen {true,false} 45 | Generate keys for encryption. Creates an 46 | `encryption_keys.bin` file. Default: false 47 | --encrypt {true,false} 48 | Set encryption mode. Default: false 49 | --keyfile KEYFILE File having key for encryption (Applicable only if 50 | encryption mode is true) 51 | ``` 52 | 53 | where 54 | 55 | - *setup\_code* is the pairing code, without the hyphen (-). (Eg. 11122333) 56 | - *Setup\_id* is a 4 character alphanumeric string configured for an accessory (Eg. 7OSX) 57 | - *target\_filename\_without\_extension* is a name like fan\_factory, to which .csv and .bin extensions are added for creating the files 58 | 59 | ## Example 60 | 61 | ``` 62 | ~# ./factory_nvs_gen.py 11122333 ES32 fan_factory 63 | CSV Generated: fan_factory.csv 64 | NVS Flash Binary Generated: fan_factory.bin 65 | ``` 66 | 67 | ``` 68 | ./factory_nvs_gen.py 11122333 ES32 fan_factory --version v2 --encrypt true --keygen true 69 | CSV Generated: fan_factory.csv 70 | Version: v2 - Multipage Blob Support Enabled 71 | NVS binary created: /path/esp_homekit_sdk_src/tools/factory_nvs_gen/fan_factory.bin 72 | Encryption keys binary created: /path/esp_homekit_sdk_src/tools/factory_nvs_gen/keys/encryption_keys_04-11_18-32.bin 73 | NVS Flash Binary Generated: fan_factory.bin 74 | ``` 75 | 76 | ## Using the Binary 77 | 78 | As mentioned, earlier, using this requires the factory\_nvs partition in your partition table. 79 | A `make` target has been added for flashing this, however it requires that 80 | 81 | - The .bin image is present in your accessory folder (where you will execute make) with the name 82 | $(PROJECT_NAME)\_factory.bin (Eg. fan\_factory.bin) 83 | - The appropriate value is set for CONFIG\_APP\_FACTORY\_NVS\_OFFSET, which is basically the offset for 84 | the factory_nvs partition in the partition table 85 | 86 | If the above requirements are met, first flash all the components, including the partition table and then flash the NVS partition as given below: 87 | 88 | ``` 89 | make flash 90 | make factory-nvs-flash 91 | ``` 92 | 93 | ## Adding custom data 94 | 95 | For certain applications, some custom NVS data may be required in addition to the HomeKit data. 96 | Such data can be included by writing it into a CSV file, the format for which should be as per 97 | the requirements of nvs\_partition\_generator. Please refer the documentation under tools/nvs\_partition\_generator 98 | for details about formatting. The file with the custom data (say app.csv) should then be passed to 99 | the factory\_nvs\_gen as below: 100 | 101 | ``` 102 | ~# ./factory_nvs_gen.py 11122333 ES32 fan_factory --infile app_data.csv 103 | CSV Generated: fan_factory.csv 104 | NVS Flash Binary Generated: fan_factory.bin 105 | ``` 106 | 107 | *Note that the custom data cannot use hap\_setup as the namespace, unless it is the UUID/Token for Software Authentication* 108 | -------------------------------------------------------------------------------- /tools/setup_payload_gen/README.md: -------------------------------------------------------------------------------- 1 | # Setup Payload Generator 2 | 3 | ## Introduction 4 | setup\_payload\_gen is a Python script that can be used to generate the Setup Payload required 5 | for generating the QR code for HomeKit Accessory Setup 6 | 7 | ## Usage 8 | 9 | ``` 10 | ~# usage: setup_payload_gen.py [] 11 | ``` 12 | 13 | where 14 | 15 | - *AccessoryCategory* is a number from the "Accessory Categories" table of HAP Spec. (Eg. 3 for fan) 16 | - *setupCode* is the pairing code, without the hyphen (-). (Eg. 11122333) 17 | - *SetupID* is a 4 character alphanumeric string configured for an accessory (Eg. 7OSX) 18 | - *ProductData* is the unique 16 characters long Product Data assigned by Apple for your product which can be copied from the MFi Portal (Eg. 1122334455667788) 19 | 20 | ## Example 21 | 22 | ``` 23 | ~# ./setup_payload_gen.py 7 51808582 7OSX 24 | Setup Payload Header Encoding: 007JNU5AE 25 | Setup Payload Data Encoding: 7OSX 26 | Setup Payload: X-HM://007JNU5AE7OSX 27 | ``` 28 | ``` 29 | ~# ./setup_payload_gen.py 7 51808582 7OSX 1122334455667788 30 | Setup Payload Header Encoding: 0E8NKO6YU 31 | Setup Payload Data Encoding: 7OSX0CZ067T6WCYA44AY9S 32 | Setup Payload: X-HM://0E8NKO6YU7OSX0CZ067T6WCYA44AY9S 33 | ``` 34 | 35 | 36 | ## Generating QR 37 | Any standard QR code generator can be used for generating the QR code for 38 | HomeKit Acessory Setup using the Payload generated above. 39 | 40 | Eg. [http://www.qr-code-generator.com/](http://www.qr-code-generator.com/) 41 | --------------------------------------------------------------------------------