From 86fa8c25cd4c74181e0c4bb92e56cf04604bd3f4 Mon Sep 17 00:00:00 2001 From: Kamil Kasperczyk Date: Thu, 1 Jun 2023 13:28:39 +0200 Subject: [PATCH 01/12] [nrfconnect] Updated nRF Connect SDK to 2.4.0 Bumped recommended nRF Connect SDK version to 2.4.0 and included several bug fixes and improvements: 1. Extend the connection request log with RSSI. This comes in handy especially during tests related to TX/RX power. Signed-off-by: Marcin Kajor 2. Support disabling Wi-Fi LPM during the OTA DFU. Added subclass of OTAImageProcessorImpl whcih implements Wi-Fi specific optimization for LPM which should be disabled during OTA due to the high throughput requirements. This allows applications to use the OTAImageProcessorImplWiFi to do the job. Signed-off-by: Marcin Kajor 3. Provide configs for Matter NUS feature Matter NUS feature allows to add of BLE Nordic UART Service and register commands which allow controlling the Matter device via BLE. This can be useful when the device loses connection with a Matter Controller but it should be controlled in another way for e.g. a Door Lock. 4. FactoryDataProvider: align the fprotect memory block Due to the smallest atomic SPU block (16k for nRF53) which can be protected we need to calculate proper offsets to include factory data partition. Signed-off-by: Marcin Kajor 5. nrfconnect: migrate to new MCUmgr Kconfig options Migrate to new MCUmgr Kconfig options using: $ZEPHYR_BASE/scripts/utils/migrate_mcumgr_kconfigs.py Signed-off-by: Johann Fischer 6. Added IMAGE_ACCESS_HOOKS config to nRF53 config set CONFIG_IMAGE_ACCESS_HOOKS is required for nRF53 to confirm image during DFU over BLE after the changes provided by the recent Zephyr's upmerge. Signed-off-by: Arkadiusz Balys 7. Changed WPA SUPP logs level to error * Changed default log level to error * Changed WPA supplicant log levet to error. This is a workaround and it will be removed once default log levels fix to Zephyr will be merged. Signed-off-by: Kamil Kasperczyk 8. Fixed dependencies for CHIP_DFU_OVER_BT_SMP kconfig Some Kconfigs selected by the CHIP_DFU_OVER_BT_SMP have unmet dependencies. Signed-off-by: Kamil Kasperczyk 9. Set BLE connection to 1 for NUS We decided to work with single BLE connection when NUS is active. 10. Repair a path within error messages in FD ptyhon script Two paths were set wrongly in the factory data python script. 11. Fixed system workqueue stack overflow for Wi-Fi After failing to connect to the Wi-Fi network (e.g. due to bad password) the application falls into stack overflow. Increased the stack size to handle the connection failure properly. Signed-off-by: Kamil Kasperczyk 12. Disable bonding for NUS Matter NUS should require providing a PIN code before each pairing, so we do not want to store anything in persistent storage and we should disable the Bluetooth LE bonding feature. 13. Disable unnecessary assert information Limit assert information for Matter applications to file name and file number. Signed-off-by: Lukasz Duda 14. Introduce workaround to Wi-Fi connection recovery It was observed that sometimes WPA supplicant may stuck in the reconnection process. This change introduces a workaround and fixes for existing recovery mechanism: * Changed is-Recovery-Aborted approach to is-Recovery-started. * Distinguished disconnects requested by the application from the disconnects coming from the supplicant. * Added scheduling recovery procedure if supplicant was not able to re-connect to the network for given amount of time (60 s). Signed-off-by: Kamil Kasperczyk 15. Adapt WiFiManager to the new wifi_ps_config API The wifi_ps_config has been extended in Zephyr so this patch is need to avoid build errors. Signed-off-by: Marcin Kajor 16. Integrated new Wi-Fi disconnect completed event Integrated handling new Wi-Fi disconnect completed event, what should fix occassional failures observed during connection recovery. Signed-off-by: Kamil Kasperczyk 17. Fixed nRF7002 EK shield kconfig name Due to introduction of new nRF7002 shields, the nRF7002 EK shield kconfig name was changed and we have to align our configuration. Signed-off-by: Kamil Kasperczyk 18. [nrfconnect] Use default number of RTC channels The default number of RTC channels on nRF5340 was increased from 2 to 3 some time ago, but Matter applications are still built with 2 user channels. This causes that CSL transmitter does not work properly on Matter Thread Router devices. 19 Add a workaround to WiFi recovery During the recovery procedure, if the net_mgmt function returns the value "-16" the device cannot recover the WiFi network until the reboot is called. This workaround allows the device to try to rescan the WiFi network even if the net_mgmt function returned an error. This workaround works only, when the WiFi recovery mechanism is active. 20. moved bt_fixed_passkey config to the features set BT_FIXED_PASSKEY cannot be added to prj_release.conf file because it causes a CMAKE warning. The config has been moved to the Kconfig.feature file. Fix the build warning in door-lock-server This fixes the uninitialized variable warning appearing when compiling the door lock app. Signed-off-by: Marcin Kajor 21. Fixed nrf7002 kconfig name again nRF7002 EK kconfig name changed once again, so we need to align our kconfigs to that. Signed-off-by: Kamil Kasperczyk --- .github/workflows/examples-nrfconnect.yaml | 2 +- .../.nrfconnect-recommended-revision | 2 +- config/nrfconnect/chip-module/Kconfig | 16 ++- .../nrfconnect/chip-module/Kconfig.defaults | 17 ++- .../nrfconnect/chip-module/Kconfig.features | 83 +++++++++-- .../Kconfig.multiprotocol_rpmsg.defaults | 3 - config/zephyr/chip-module/Kconfig.features | 14 +- .../nrfconnect/CMakeLists.txt | 2 +- .../nrfconnect/main/AppTask.cpp | 2 +- .../nrfconnect/main/include/AppTask.h | 2 +- .../nrfconnect/CMakeLists.txt | 2 +- .../nrfconnect/main/AppTask.cpp | 2 +- .../nrfconnect/main/include/AppTask.h | 2 +- .../nrfconnect/CMakeLists.txt | 4 +- .../nrfconnect/main/AppTask.cpp | 4 +- .../nrfconnect/main/include/AppTask.h | 2 +- .../lighting-app/nrfconnect/CMakeLists.txt | 4 +- .../lighting-app/nrfconnect/main/AppTask.cpp | 4 +- .../nrfconnect/main/include/AppTask.h | 2 +- examples/lock-app/nrfconnect/CMakeLists.txt | 4 +- examples/lock-app/nrfconnect/main/AppTask.cpp | 4 +- .../nrfconnect/main/include/AppTask.h | 2 +- .../platform/nrfconnect/util/DFUOverSMP.cpp | 2 +- examples/pump-app/nrfconnect/CMakeLists.txt | 4 +- examples/pump-app/nrfconnect/main/AppTask.cpp | 4 +- .../nrfconnect/main/include/AppTask.h | 2 +- .../nrfconnect/CMakeLists.txt | 4 +- .../nrfconnect/main/AppTask.cpp | 4 +- .../nrfconnect/main/include/AppTask.h | 2 +- examples/window-app/nrfconnect/CMakeLists.txt | 4 +- .../window-app/nrfconnect/main/AppTask.cpp | 4 +- .../nrfconnect/main/include/AppTask.h | 2 +- .../generate_nrfconnect_chip_factory_data.py | 4 +- .../door-lock-server/door-lock-server.cpp | 4 +- src/platform/Zephyr/BLEAdvertisingArbiter.cpp | 2 + src/platform/nrfconnect/BUILD.gn | 1 + src/platform/nrfconnect/FactoryDataProvider.h | 34 ++++- .../nrfconnect/OTAImageProcessorImplWiFi.h | 63 +++++++++ src/platform/nrfconnect/wifi/WiFiManager.cpp | 130 +++++++++++++++--- src/platform/nrfconnect/wifi/WiFiManager.h | 15 +- 40 files changed, 372 insertions(+), 92 deletions(-) create mode 100644 src/platform/nrfconnect/OTAImageProcessorImplWiFi.h diff --git a/.github/workflows/examples-nrfconnect.yaml b/.github/workflows/examples-nrfconnect.yaml index 7f66809a2d9138..caba78329e53c6 100644 --- a/.github/workflows/examples-nrfconnect.yaml +++ b/.github/workflows/examples-nrfconnect.yaml @@ -40,7 +40,7 @@ jobs: if: github.actor != 'restyled-io[bot]' container: - image: connectedhomeip/chip-build-nrf-platform:0.7.3 + image: connectedhomeip/chip-build-nrf-platform:0.7.16 volumes: - "/tmp/bloat_reports:/tmp/bloat_reports" diff --git a/config/nrfconnect/.nrfconnect-recommended-revision b/config/nrfconnect/.nrfconnect-recommended-revision index b1d18bc43f08ca..8721bbc46ad2f7 100644 --- a/config/nrfconnect/.nrfconnect-recommended-revision +++ b/config/nrfconnect/.nrfconnect-recommended-revision @@ -1 +1 @@ -v2.3.0 +v2.4.0 diff --git a/config/nrfconnect/chip-module/Kconfig b/config/nrfconnect/chip-module/Kconfig index 34143ed3aa89dd..b4e7bc1863a17f 100644 --- a/config/nrfconnect/chip-module/Kconfig +++ b/config/nrfconnect/chip-module/Kconfig @@ -94,7 +94,7 @@ config CHIP_MALLOC_SYS_HEAP config CHIP_FACTORY_DATA bool "Factory data provider" select ZCBOR - select FPROTECT + imply FPROTECT help Enables the default nRF Connect factory data provider implementation that supports reading the factory data encoded in the CBOR format from the @@ -134,6 +134,20 @@ config CHIP_FACTORY_DATA_ROTATING_DEVICE_UID_MAX_LEN help Maximum acceptable length of rotating device ID unique ID in bytes. +config CHIP_FACTORY_DATA_WRITE_PROTECT + bool "Enable Factory Data write protection" + select FPROTECT + depends on CHIP_FACTORY_DATA + default y if CHIP_FACTORY_DATA + help + Enables the write protection of the Factory Data partition in the flash memory. + This is a recommended feature, but it requires the Settings partition size to be + a multiple of FPROTECT_BLOCK_SIZE and the Factory Data partition to be placed + right after the application partition in the address space (the Factory Data + partition offset must be equal to the last address of the application partition). + The second requirement is valid only when the FPROTECT_BLOCK_SIZE is bigger than + the flash memory page size. + if CHIP_FACTORY_DATA_BUILD # Factory data definitions diff --git a/config/nrfconnect/chip-module/Kconfig.defaults b/config/nrfconnect/chip-module/Kconfig.defaults index bf7b494e7050d5..2561aa05e855d7 100644 --- a/config/nrfconnect/chip-module/Kconfig.defaults +++ b/config/nrfconnect/chip-module/Kconfig.defaults @@ -37,7 +37,7 @@ config CHIP_APP_LOG_LEVEL default 4 # debug config LOG_DEFAULT_LEVEL - default 2 # warning + default 1 # error config CHIP_LOG_SIZE_OPTIMIZATION default y @@ -50,6 +50,12 @@ config PRINTK_SYNC config ASSERT default y +config ASSERT_NO_COND_INFO + default y + +config ASSERT_NO_MSG_INFO + default y + config HW_STACK_PROTECTION default y @@ -216,6 +222,10 @@ endif if CHIP_WIFI +choice WPA_SUPP_LOG_LEVEL_CHOICE + default WPA_SUPP_LOG_LEVEL_ERR +endchoice + config NRF_WIFI_LOW_POWER default n @@ -223,7 +233,7 @@ config MBEDTLS_PSA_CRYPTO_EXTERNAL_RNG default n config SYSTEM_WORKQUEUE_STACK_SIZE - default 2048 + default 2560 # align these numbers to match the OpenThread config config NET_IF_UNICAST_IPV6_ADDR_COUNT @@ -436,6 +446,9 @@ endif # SOC_SERIES_NRF52X if SOC_SERIES_NRF53X +config BOOT_IMAGE_ACCESS_HOOKS + default y + config UPDATEABLE_IMAGE_NUMBER default 2 diff --git a/config/nrfconnect/chip-module/Kconfig.features b/config/nrfconnect/chip-module/Kconfig.features index 0501e351681e9a..84390e38d2029b 100644 --- a/config/nrfconnect/chip-module/Kconfig.features +++ b/config/nrfconnect/chip-module/Kconfig.features @@ -21,7 +21,7 @@ if CHIP config CHIP_WIFI bool "Enable nrfconnect Wi-Fi support" - default y if SHIELD_NRF7002_EK || BOARD_NRF7002DK_NRF5340_CPUAPP + default y if SHIELD_NRF7002EK || BOARD_NRF7002DK_NRF5340_CPUAPP select WIFI_NRF700X select WIFI select WPA_SUPP @@ -73,18 +73,77 @@ config SPI_NOR_FLASH_LAYOUT_PAGE_SIZE endif # CHIP_SPI_NOR +config CHIP_NUS + bool "Enable Nordic UART service for Matter purposes" + select BT_NUS + select BT_SMP + select BT_NUS_AUTHEN + help + Enables Nordic UART service (NUS) for Matter samples. + Using NUS service you can control a Matter sample using pre-defined BLE commands + and do defined operations. The CHIP NUS service can be useful to keep communication + with a smart home device when a connection within Matter network is lost. + +if CHIP_NUS + +# Requires providing a PIN for each pair request +config BT_BONDABLE + default n + +config BT_RX_STACK_SIZE + default 1536 + +config SYSTEM_WORKQUEUE_STACK_SIZE + default 2048 + +config BT_DEVICE_APPEARANCE + default 833 + +if !LOG + +config BT_FIXED_PASSKEY + default y + +endif + +config CHIP_NUS_MAX_COMMAND_LEN + int "Maximum length of single command in Bytes" + default 10 + help + Maximum length of single command. This command will be send via Bluetooth LE to + a paired smart home device. + +config CHIP_NUS_FIXED_PASSKEY + int "Define the default passkey for NUS" + depends on BT_FIXED_PASSKEY + default 123456 + help + Define the default password for pairing with the Bluetooth LE device. + +config CHIP_NUS_MAX_COMMANDS + int "Define maximum NUS commands amount" + default 2 + help + Define the maximum number of NUS commands to declare by user. + +endif + + config CHIP_DFU_OVER_BT_SMP bool "Enable DFU over Bluetooth LE SMP feature set" imply CHIP_QSPI_NOR if BOARD_NRF5340DK_NRF5340_CPUAPP || BOARD_NRF52840DK_NRF52840 imply CHIP_SPI_NOR if BOARD_NRF7002DK_NRF5340_CPUAPP imply BOOTLOADER_MCUBOOT select MCUMGR - select MCUMGR_SMP_BT - select MCUMGR_CMD_IMG_MGMT - select MCUMGR_CMD_OS_MGMT + select MCUMGR_TRANSPORT_BT + select IMG_MANAGER + select STREAM_FLASH + select ZCBOR + select MCUMGR_GRP_IMG + select MCUMGR_GRP_OS # Enable custom SMP request to erase settings partition. - select MCUMGR_GRP_ZEPHYR_BASIC - select MCUMGR_GRP_BASIC_CMD_STORAGE_ERASE + select MCUMGR_GRP_ZBASIC + select MCUMGR_GRP_ZBASIC_STORAGE_ERASE help Enables Device Firmware Upgrade over Bluetooth LE with SMP and configures the set of options related to that feature. @@ -92,10 +151,10 @@ config CHIP_DFU_OVER_BT_SMP if CHIP_DFU_OVER_BT_SMP # MCU Manager and SMP configuration -config MCUMGR_SMP_BT_AUTHEN +config MCUMGR_TRANSPORT_BT_AUTHEN default n -config MCUMGR_BUF_COUNT +config MCUMGR_TRANSPORT_NETBUF_COUNT default 6 config MCUMGR_MGMT_NOTIFICATION_HOOKS @@ -117,8 +176,8 @@ config BT_L2CAP_TX_MTU config BT_BUF_ACL_RX_SIZE default 502 -# Increase MCUMGR_BUF_SIZE, as it must be big enough to fit MAX MTU + overhead and for single-image DFU default is 384 B -config MCUMGR_BUF_SIZE +# Increase MCUMGR_TRANSPORT_NETBUF_SIZE, as it must be big enough to fit MAX MTU + overhead and for single-image DFU default is 384 B +config MCUMGR_TRANSPORT_NETBUF_SIZE default 1024 # Increase system workqueue size, as SMP is processed within it @@ -128,10 +187,10 @@ config SYSTEM_WORKQUEUE_STACK_SIZE if SOC_SERIES_NRF53X # Enable custom SMP request to erase settings partition. -config MCUMGR_GRP_ZEPHYR_BASIC +config MCUMGR_GRP_ZBASIC default y -config MCUMGR_GRP_BASIC_CMD_STORAGE_ERASE +config MCUMGR_GRP_ZBASIC_STORAGE_ERASE default y endif # SOC_SERIES_NRF53X diff --git a/config/nrfconnect/chip-module/Kconfig.multiprotocol_rpmsg.defaults b/config/nrfconnect/chip-module/Kconfig.multiprotocol_rpmsg.defaults index 9fee38cb5f38fc..eb0b01e2664ce7 100644 --- a/config/nrfconnect/chip-module/Kconfig.multiprotocol_rpmsg.defaults +++ b/config/nrfconnect/chip-module/Kconfig.multiprotocol_rpmsg.defaults @@ -75,8 +75,5 @@ config EXCEPTION_STACK_TRACE config NRF_802154_SER_RADIO default y -config NRF_RTC_TIMER_USER_CHAN_COUNT - default 2 - config NRF_802154_ENCRYPTION default y diff --git a/config/zephyr/chip-module/Kconfig.features b/config/zephyr/chip-module/Kconfig.features index bc800095dc7ce0..1fa6e051a1d2b2 100644 --- a/config/zephyr/chip-module/Kconfig.features +++ b/config/zephyr/chip-module/Kconfig.features @@ -24,23 +24,23 @@ config MCUMGR bool default y -config MCUMGR_CMD_IMG_MGMT +config MCUMGR_GRP_IMG bool default y -config MCUMGR_CMD_OS_MGMT +config MCUMGR_GRP_OS bool default y -config MCUMGR_SMP_BT +config MCUMGR_TRANSPORT_BT bool default y -config MCUMGR_SMP_BT_AUTHEN +config MCUMGR_TRANSPORT_BT_AUTHEN bool default n -config MCUMGR_BUF_COUNT +config MCUMGR_TRANSPORT_NETBUF_COUNT int default 6 @@ -53,8 +53,8 @@ config BT_BUF_ACL_RX_SIZE int default 502 -# Increase MCUMGR_BUF_SIZE, as it must be big enough to fit MAX MTU + overhead and for single-image DFU default is 384 B -config MCUMGR_BUF_SIZE +# Increase MCUMGR_TRANSPORT_NETBUF_SIZE, as it must be big enough to fit MAX MTU + overhead and for single-image DFU default is 384 B +config MCUMGR_TRANSPORT_NETBUF_SIZE int default 1024 diff --git a/examples/all-clusters-app/nrfconnect/CMakeLists.txt b/examples/all-clusters-app/nrfconnect/CMakeLists.txt index fc50ade57e9c96..6b28a6e1a61c3c 100644 --- a/examples/all-clusters-app/nrfconnect/CMakeLists.txt +++ b/examples/all-clusters-app/nrfconnect/CMakeLists.txt @@ -67,7 +67,7 @@ chip_configure_data_model(app ZAP_FILE ${ALL_CLUSTERS_COMMON_DIR}/all-clusters-app.zap ) -if(CONFIG_CHIP_OTA_REQUESTOR OR CONFIG_MCUMGR_SMP_BT) +if(CONFIG_CHIP_OTA_REQUESTOR OR CONFIG_MCUMGR_TRANSPORT_BT) target_sources(app PRIVATE ${NRFCONNECT_COMMON}/util/OTAUtil.cpp) endif() diff --git a/examples/all-clusters-app/nrfconnect/main/AppTask.cpp b/examples/all-clusters-app/nrfconnect/main/AppTask.cpp index a5fbf9b1e95d09..cb3087217ab11c 100644 --- a/examples/all-clusters-app/nrfconnect/main/AppTask.cpp +++ b/examples/all-clusters-app/nrfconnect/main/AppTask.cpp @@ -358,7 +358,7 @@ void AppTask::FunctionHandler(const AppEvent & event) Instance().CancelTimer(); Instance().mFunction = FunctionEvent::NoneSelected; -#ifdef CONFIG_MCUMGR_SMP_BT +#ifdef CONFIG_MCUMGR_TRANSPORT_BT GetDFUOverSMP().StartServer(); #else LOG_INF("Software update is disabled"); diff --git a/examples/all-clusters-app/nrfconnect/main/include/AppTask.h b/examples/all-clusters-app/nrfconnect/main/include/AppTask.h index 4b57d1dc3f249c..4db18dba683c0e 100644 --- a/examples/all-clusters-app/nrfconnect/main/include/AppTask.h +++ b/examples/all-clusters-app/nrfconnect/main/include/AppTask.h @@ -28,7 +28,7 @@ #include #endif -#ifdef CONFIG_MCUMGR_SMP_BT +#ifdef CONFIG_MCUMGR_TRANSPORT_BT #include "DFUOverSMP.h" #endif diff --git a/examples/all-clusters-minimal-app/nrfconnect/CMakeLists.txt b/examples/all-clusters-minimal-app/nrfconnect/CMakeLists.txt index 6fdc49b494018e..00ecc2ca2fbfc5 100644 --- a/examples/all-clusters-minimal-app/nrfconnect/CMakeLists.txt +++ b/examples/all-clusters-minimal-app/nrfconnect/CMakeLists.txt @@ -65,7 +65,7 @@ chip_configure_data_model(app ZAP_FILE ${CMAKE_CURRENT_SOURCE_DIR}/../all-clusters-common/all-clusters-minimal-app.zap ) -if(CONFIG_CHIP_OTA_REQUESTOR OR CONFIG_MCUMGR_SMP_BT) +if(CONFIG_CHIP_OTA_REQUESTOR OR CONFIG_MCUMGR_TRANSPORT_BT) target_sources(app PRIVATE ${NRFCONNECT_COMMON}/util/OTAUtil.cpp) endif() diff --git a/examples/all-clusters-minimal-app/nrfconnect/main/AppTask.cpp b/examples/all-clusters-minimal-app/nrfconnect/main/AppTask.cpp index 19ce36436419b3..3307789c9e5989 100644 --- a/examples/all-clusters-minimal-app/nrfconnect/main/AppTask.cpp +++ b/examples/all-clusters-minimal-app/nrfconnect/main/AppTask.cpp @@ -279,7 +279,7 @@ void AppTask::FunctionHandler(const AppEvent & event) { Instance().CancelTimer(); -#ifdef CONFIG_MCUMGR_SMP_BT +#ifdef CONFIG_MCUMGR_TRANSPORT_BT GetDFUOverSMP().StartServer(); #else LOG_INF("Software update is disabled"); diff --git a/examples/all-clusters-minimal-app/nrfconnect/main/include/AppTask.h b/examples/all-clusters-minimal-app/nrfconnect/main/include/AppTask.h index 9921de58383521..0d5a9f1f1dc84f 100644 --- a/examples/all-clusters-minimal-app/nrfconnect/main/include/AppTask.h +++ b/examples/all-clusters-minimal-app/nrfconnect/main/include/AppTask.h @@ -28,7 +28,7 @@ #include #endif -#ifdef CONFIG_MCUMGR_SMP_BT +#ifdef CONFIG_MCUMGR_TRANSPORT_BT #include "DFUOverSMP.h" #endif diff --git a/examples/light-switch-app/nrfconnect/CMakeLists.txt b/examples/light-switch-app/nrfconnect/CMakeLists.txt index 7512e45ce45211..2e719072f23fb4 100644 --- a/examples/light-switch-app/nrfconnect/CMakeLists.txt +++ b/examples/light-switch-app/nrfconnect/CMakeLists.txt @@ -62,11 +62,11 @@ target_sources(app PRIVATE ${NRFCONNECT_COMMON}/util/LEDWidget.cpp) -if(CONFIG_CHIP_OTA_REQUESTOR OR CONFIG_MCUMGR_SMP_BT) +if(CONFIG_CHIP_OTA_REQUESTOR OR CONFIG_MCUMGR_TRANSPORT_BT) target_sources(app PRIVATE ${NRFCONNECT_COMMON}/util/OTAUtil.cpp) endif() -if(CONFIG_MCUMGR_SMP_BT) +if(CONFIG_MCUMGR_TRANSPORT_BT) target_sources(app PRIVATE ${NRFCONNECT_COMMON}/util/DFUOverSMP.cpp) endif() diff --git a/examples/light-switch-app/nrfconnect/main/AppTask.cpp b/examples/light-switch-app/nrfconnect/main/AppTask.cpp index 9bc8422328d88a..405664af872c24 100644 --- a/examples/light-switch-app/nrfconnect/main/AppTask.cpp +++ b/examples/light-switch-app/nrfconnect/main/AppTask.cpp @@ -188,7 +188,7 @@ CHIP_ERROR AppTask::Init() k_timer_user_data_set(&sFunctionTimer, this); // Initialize DFU -#ifdef CONFIG_MCUMGR_SMP_BT +#ifdef CONFIG_MCUMGR_TRANSPORT_BT GetDFUOverSMP().Init(); GetDFUOverSMP().ConfirmNewImage(); #endif @@ -300,7 +300,7 @@ void AppTask::ButtonReleaseHandler(const AppEvent & event) Instance().CancelTimer(Timer::Function); Instance().mFunction = FunctionEvent::NoneSelected; -#ifdef CONFIG_MCUMGR_SMP_BT +#ifdef CONFIG_MCUMGR_TRANSPORT_BT GetDFUOverSMP().StartServer(); UpdateStatusLED(); #else diff --git a/examples/light-switch-app/nrfconnect/main/include/AppTask.h b/examples/light-switch-app/nrfconnect/main/include/AppTask.h index a40c5e82bfd51f..240ac589040164 100644 --- a/examples/light-switch-app/nrfconnect/main/include/AppTask.h +++ b/examples/light-switch-app/nrfconnect/main/include/AppTask.h @@ -29,7 +29,7 @@ #include #endif -#ifdef CONFIG_MCUMGR_SMP_BT +#ifdef CONFIG_MCUMGR_TRANSPORT_BT #include "DFUOverSMP.h" #endif diff --git a/examples/lighting-app/nrfconnect/CMakeLists.txt b/examples/lighting-app/nrfconnect/CMakeLists.txt index 94996c75ab7255..bf378bc4468339 100644 --- a/examples/lighting-app/nrfconnect/CMakeLists.txt +++ b/examples/lighting-app/nrfconnect/CMakeLists.txt @@ -67,11 +67,11 @@ chip_configure_data_model(app ZAP_FILE ${CMAKE_CURRENT_SOURCE_DIR}/../lighting-common/lighting-app.zap ) -if(CONFIG_CHIP_OTA_REQUESTOR OR CONFIG_MCUMGR_SMP_BT) +if(CONFIG_CHIP_OTA_REQUESTOR OR CONFIG_MCUMGR_TRANSPORT_BT) target_sources(app PRIVATE ${NRFCONNECT_COMMON}/util/OTAUtil.cpp) endif() -if(CONFIG_MCUMGR_SMP_BT) +if(CONFIG_MCUMGR_TRANSPORT_BT) target_sources(app PRIVATE ${NRFCONNECT_COMMON}/util/DFUOverSMP.cpp) endif() diff --git a/examples/lighting-app/nrfconnect/main/AppTask.cpp b/examples/lighting-app/nrfconnect/main/AppTask.cpp index 5ff0c6a59ea3ca..e16230e000ca0f 100644 --- a/examples/lighting-app/nrfconnect/main/AppTask.cpp +++ b/examples/lighting-app/nrfconnect/main/AppTask.cpp @@ -197,7 +197,7 @@ CHIP_ERROR AppTask::Init() k_timer_init(&sFunctionTimer, &AppTask::FunctionTimerTimeoutCallback, nullptr); k_timer_user_data_set(&sFunctionTimer, this); -#ifdef CONFIG_MCUMGR_SMP_BT +#ifdef CONFIG_MCUMGR_TRANSPORT_BT // Initialize DFU over SMP GetDFUOverSMP().Init(); GetDFUOverSMP().ConfirmNewImage(); @@ -474,7 +474,7 @@ void AppTask::FunctionHandler(const AppEvent & event) Instance().CancelTimer(); Instance().mFunction = FunctionEvent::NoneSelected; -#ifdef CONFIG_MCUMGR_SMP_BT +#ifdef CONFIG_MCUMGR_TRANSPORT_BT GetDFUOverSMP().StartServer(); #else LOG_INF("Software update is disabled"); diff --git a/examples/lighting-app/nrfconnect/main/include/AppTask.h b/examples/lighting-app/nrfconnect/main/include/AppTask.h index 51df03f650c530..37be9a0334847c 100644 --- a/examples/lighting-app/nrfconnect/main/include/AppTask.h +++ b/examples/lighting-app/nrfconnect/main/include/AppTask.h @@ -34,7 +34,7 @@ #include "Rpc.h" #endif -#ifdef CONFIG_MCUMGR_SMP_BT +#ifdef CONFIG_MCUMGR_TRANSPORT_BT #include "DFUOverSMP.h" #endif diff --git a/examples/lock-app/nrfconnect/CMakeLists.txt b/examples/lock-app/nrfconnect/CMakeLists.txt index 4be8f9927b5c22..e1b3e8f2f0e489 100644 --- a/examples/lock-app/nrfconnect/CMakeLists.txt +++ b/examples/lock-app/nrfconnect/CMakeLists.txt @@ -64,11 +64,11 @@ chip_configure_data_model(app ZAP_FILE ${CMAKE_CURRENT_SOURCE_DIR}/../lock-common/lock-app.zap ) -if(CONFIG_CHIP_OTA_REQUESTOR OR CONFIG_MCUMGR_SMP_BT) +if(CONFIG_CHIP_OTA_REQUESTOR OR CONFIG_MCUMGR_TRANSPORT_BT) target_sources(app PRIVATE ${NRFCONNECT_COMMON}/util/OTAUtil.cpp) endif() -if(CONFIG_MCUMGR_SMP_BT) +if(CONFIG_MCUMGR_TRANSPORT_BT) target_sources(app PRIVATE ${NRFCONNECT_COMMON}/util/DFUOverSMP.cpp) endif() diff --git a/examples/lock-app/nrfconnect/main/AppTask.cpp b/examples/lock-app/nrfconnect/main/AppTask.cpp index 8acf7d6b56d325..aa65236ba747d2 100644 --- a/examples/lock-app/nrfconnect/main/AppTask.cpp +++ b/examples/lock-app/nrfconnect/main/AppTask.cpp @@ -179,7 +179,7 @@ CHIP_ERROR AppTask::Init() k_timer_init(&sFunctionTimer, &AppTask::FunctionTimerTimeoutCallback, nullptr); k_timer_user_data_set(&sFunctionTimer, this); -#ifdef CONFIG_MCUMGR_SMP_BT +#ifdef CONFIG_MCUMGR_TRANSPORT_BT // Initialize DFU over SMP GetDFUOverSMP().Init(); GetDFUOverSMP().ConfirmNewImage(); @@ -433,7 +433,7 @@ void AppTask::FunctionHandler(const AppEvent & event) Instance().CancelTimer(); Instance().mFunction = FunctionEvent::NoneSelected; -#ifdef CONFIG_MCUMGR_SMP_BT +#ifdef CONFIG_MCUMGR_TRANSPORT_BT GetDFUOverSMP().StartServer(); #else LOG_INF("Software update is disabled"); diff --git a/examples/lock-app/nrfconnect/main/include/AppTask.h b/examples/lock-app/nrfconnect/main/include/AppTask.h index 76738ac9afd331..01d1536bc2545e 100644 --- a/examples/lock-app/nrfconnect/main/include/AppTask.h +++ b/examples/lock-app/nrfconnect/main/include/AppTask.h @@ -31,7 +31,7 @@ #include #endif -#ifdef CONFIG_MCUMGR_SMP_BT +#ifdef CONFIG_MCUMGR_TRANSPORT_BT #include "DFUOverSMP.h" #endif diff --git a/examples/platform/nrfconnect/util/DFUOverSMP.cpp b/examples/platform/nrfconnect/util/DFUOverSMP.cpp index 1720a58edb5c73..95e3ab521bcdc2 100644 --- a/examples/platform/nrfconnect/util/DFUOverSMP.cpp +++ b/examples/platform/nrfconnect/util/DFUOverSMP.cpp @@ -17,7 +17,7 @@ #include "DFUOverSMP.h" -#if !defined(CONFIG_MCUMGR_SMP_BT) || !defined(CONFIG_MCUMGR_CMD_IMG_MGMT) || !defined(CONFIG_MCUMGR_CMD_OS_MGMT) +#if !defined(CONFIG_MCUMGR_SMP_BT) || !defined(CONFIG_MCUMGR_GRP_IMG) || !defined(CONFIG_MCUMGR_CMD_OS_MGMT) #error "DFUOverSMP requires MCUMGR module configs enabled" #endif diff --git a/examples/pump-app/nrfconnect/CMakeLists.txt b/examples/pump-app/nrfconnect/CMakeLists.txt index 59ac3654a27d29..94ae9180fb6392 100644 --- a/examples/pump-app/nrfconnect/CMakeLists.txt +++ b/examples/pump-app/nrfconnect/CMakeLists.txt @@ -63,10 +63,10 @@ chip_configure_data_model(app ZAP_FILE ${CMAKE_CURRENT_SOURCE_DIR}/../pump-common/pump-app.zap ) -if(CONFIG_CHIP_OTA_REQUESTOR OR CONFIG_MCUMGR_SMP_BT) +if(CONFIG_CHIP_OTA_REQUESTOR OR CONFIG_MCUMGR_TRANSPORT_BT) target_sources(app PRIVATE ${NRFCONNECT_COMMON}/util/OTAUtil.cpp) endif() -if(CONFIG_MCUMGR_SMP_BT) +if(CONFIG_MCUMGR_TRANSPORT_BT) target_sources(app PRIVATE ${NRFCONNECT_COMMON}/util/DFUOverSMP.cpp) endif() diff --git a/examples/pump-app/nrfconnect/main/AppTask.cpp b/examples/pump-app/nrfconnect/main/AppTask.cpp index 1a45d22444af03..9c75c54e1fcc87 100644 --- a/examples/pump-app/nrfconnect/main/AppTask.cpp +++ b/examples/pump-app/nrfconnect/main/AppTask.cpp @@ -154,7 +154,7 @@ CHIP_ERROR AppTask::Init() k_timer_init(&sFunctionTimer, &AppTask::FunctionTimerTimeoutCallback, nullptr); k_timer_user_data_set(&sFunctionTimer, this); -#ifdef CONFIG_MCUMGR_SMP_BT +#ifdef CONFIG_MCUMGR_TRANSPORT_BT // Initialize DFU over SMP GetDFUOverSMP().Init(); GetDFUOverSMP().ConfirmNewImage(); @@ -342,7 +342,7 @@ void AppTask::FunctionHandler(const AppEvent & event) { Instance().CancelTimer(); -#ifdef CONFIG_MCUMGR_SMP_BT +#ifdef CONFIG_MCUMGR_TRANSPORT_BT GetDFUOverSMP().StartServer(); #else LOG_INF("Software update is disabled"); diff --git a/examples/pump-app/nrfconnect/main/include/AppTask.h b/examples/pump-app/nrfconnect/main/include/AppTask.h index bcf2d1eaf20dad..fb2fe2c855cb1a 100644 --- a/examples/pump-app/nrfconnect/main/include/AppTask.h +++ b/examples/pump-app/nrfconnect/main/include/AppTask.h @@ -31,7 +31,7 @@ #include #endif -#ifdef CONFIG_MCUMGR_SMP_BT +#ifdef CONFIG_MCUMGR_TRANSPORT_BT #include "DFUOverSMP.h" #endif diff --git a/examples/pump-controller-app/nrfconnect/CMakeLists.txt b/examples/pump-controller-app/nrfconnect/CMakeLists.txt index 3534eb8444a4fb..8a5b8f4193b245 100644 --- a/examples/pump-controller-app/nrfconnect/CMakeLists.txt +++ b/examples/pump-controller-app/nrfconnect/CMakeLists.txt @@ -63,10 +63,10 @@ chip_configure_data_model(app ZAP_FILE ${CMAKE_CURRENT_SOURCE_DIR}/../pump-controller-common/pump-controller-app.zap ) -if(CONFIG_CHIP_OTA_REQUESTOR OR CONFIG_MCUMGR_SMP_BT) +if(CONFIG_CHIP_OTA_REQUESTOR OR CONFIG_MCUMGR_TRANSPORT_BT) target_sources(app PRIVATE ${NRFCONNECT_COMMON}/util/OTAUtil.cpp) endif() -if(CONFIG_MCUMGR_SMP_BT) +if(CONFIG_MCUMGR_TRANSPORT_BT) target_sources(app PRIVATE ${NRFCONNECT_COMMON}/util/DFUOverSMP.cpp) endif() diff --git a/examples/pump-controller-app/nrfconnect/main/AppTask.cpp b/examples/pump-controller-app/nrfconnect/main/AppTask.cpp index 6a8954c121f0e1..9580af61ae451d 100644 --- a/examples/pump-controller-app/nrfconnect/main/AppTask.cpp +++ b/examples/pump-controller-app/nrfconnect/main/AppTask.cpp @@ -152,7 +152,7 @@ CHIP_ERROR AppTask::Init() k_timer_init(&sFunctionTimer, &AppTask::FunctionTimerTimeoutCallback, nullptr); k_timer_user_data_set(&sFunctionTimer, this); -#ifdef CONFIG_MCUMGR_SMP_BT +#ifdef CONFIG_MCUMGR_TRANSPORT_BT // Initialize DFU over SMP GetDFUOverSMP().Init(); GetDFUOverSMP().ConfirmNewImage(); @@ -339,7 +339,7 @@ void AppTask::FunctionHandler(const AppEvent & event) { Instance().CancelTimer(); -#ifdef CONFIG_MCUMGR_SMP_BT +#ifdef CONFIG_MCUMGR_TRANSPORT_BT GetDFUOverSMP().StartServer(); #else LOG_INF("Software update is disabled"); diff --git a/examples/pump-controller-app/nrfconnect/main/include/AppTask.h b/examples/pump-controller-app/nrfconnect/main/include/AppTask.h index 02e7f0a5320d12..8ca4a69e91c0f0 100644 --- a/examples/pump-controller-app/nrfconnect/main/include/AppTask.h +++ b/examples/pump-controller-app/nrfconnect/main/include/AppTask.h @@ -31,7 +31,7 @@ #include #endif -#ifdef CONFIG_MCUMGR_SMP_BT +#ifdef CONFIG_MCUMGR_TRANSPORT_BT #include "DFUOverSMP.h" #endif diff --git a/examples/window-app/nrfconnect/CMakeLists.txt b/examples/window-app/nrfconnect/CMakeLists.txt index 21bb4caeb6194b..441adc79b3ef95 100644 --- a/examples/window-app/nrfconnect/CMakeLists.txt +++ b/examples/window-app/nrfconnect/CMakeLists.txt @@ -66,11 +66,11 @@ chip_configure_data_model(app ZAP_FILE ${WIN_APP_COMMON_DIR}/window-app.zap ) -if(CONFIG_CHIP_OTA_REQUESTOR OR CONFIG_MCUMGR_SMP_BT) +if(CONFIG_CHIP_OTA_REQUESTOR OR CONFIG_MCUMGR_TRANSPORT_BT) target_sources(app PRIVATE ${NRFCONNECT_COMMON}/util/OTAUtil.cpp) endif() -if(CONFIG_MCUMGR_SMP_BT) +if(CONFIG_MCUMGR_TRANSPORT_BT) target_sources(app PRIVATE ${NRFCONNECT_COMMON}/util/DFUOverSMP.cpp) endif() diff --git a/examples/window-app/nrfconnect/main/AppTask.cpp b/examples/window-app/nrfconnect/main/AppTask.cpp index fca63e3176a409..38e20fd503d4ea 100644 --- a/examples/window-app/nrfconnect/main/AppTask.cpp +++ b/examples/window-app/nrfconnect/main/AppTask.cpp @@ -159,7 +159,7 @@ CHIP_ERROR AppTask::Init() k_timer_init(&sFunctionTimer, &AppTask::FunctionTimerTimeoutCallback, nullptr); k_timer_user_data_set(&sFunctionTimer, this); -#ifdef CONFIG_MCUMGR_SMP_BT +#ifdef CONFIG_MCUMGR_TRANSPORT_BT // Initialize DFU over SMP GetDFUOverSMP().Init(); GetDFUOverSMP().ConfirmNewImage(); @@ -367,7 +367,7 @@ void AppTask::FunctionHandler(const AppEvent & event) { Instance().CancelTimer(); -#ifdef CONFIG_MCUMGR_SMP_BT +#ifdef CONFIG_MCUMGR_TRANSPORT_BT GetDFUOverSMP().StartServer(); #else LOG_INF("Software update is disabled"); diff --git a/examples/window-app/nrfconnect/main/include/AppTask.h b/examples/window-app/nrfconnect/main/include/AppTask.h index 28a7331d9737ba..64410f910547a2 100644 --- a/examples/window-app/nrfconnect/main/include/AppTask.h +++ b/examples/window-app/nrfconnect/main/include/AppTask.h @@ -28,7 +28,7 @@ #include #endif -#ifdef CONFIG_MCUMGR_SMP_BT +#ifdef CONFIG_MCUMGR_TRANSPORT_BT #include "DFUOverSMP.h" #endif diff --git a/scripts/tools/nrfconnect/generate_nrfconnect_chip_factory_data.py b/scripts/tools/nrfconnect/generate_nrfconnect_chip_factory_data.py index c013bbbd1ffa5c..6c2af9dc890617 100644 --- a/scripts/tools/nrfconnect/generate_nrfconnect_chip_factory_data.py +++ b/scripts/tools/nrfconnect/generate_nrfconnect_chip_factory_data.py @@ -545,13 +545,13 @@ def base64_str(s): return base64.b64decode(s) log.error(("Requested verification of the JSON file using jsonschema, but the module is not installed. \n" "Install only the module by invoking: pip3 install jsonschema \n" "Alternatively, install it with all dependencies for Matter by invoking: pip3 install " - "-r ./scripts/requirements.nrfconnect.txt from the Matter root directory.")) + "-r ./scripts/setup/requirements.nrfconnect.txt from the Matter root directory.")) return if args.generate_onboarding and no_onboarding_modules: log.error(("Requested generation of onboarding codes, but the some modules are not installed. \n" "Install all dependencies for Matter by invoking: pip3 install " - "-r ./scripts/requirements.nrfconnect.txt from the Matter root directory.")) + "-r ./scripts/setup/requirements.nrfconnect.txt from the Matter root directory.")) return generator = FactoryDataGenerator(args) diff --git a/src/app/clusters/door-lock-server/door-lock-server.cpp b/src/app/clusters/door-lock-server/door-lock-server.cpp index dbfd723ad8cfff..7c79db19f7aadf 100644 --- a/src/app/clusters/door-lock-server/door-lock-server.cpp +++ b/src/app/clusters/door-lock-server/door-lock-server.cpp @@ -3344,8 +3344,8 @@ bool DoorLockServer::HandleRemoteLockOperation(chip::app::CommandHandler * comma EndpointId endpoint = commandPath.mEndpointId; OperationErrorEnum reason = OperationErrorEnum::kUnspecified; - Nullable pinUserIdx; // Will get set to non-null if we find a user for the PIN. - Optional pinCredIdx; // Will get set to a value if the PIN is one we know about. + Nullable pinUserIdx; // Will get set to non-null if we find a user for the PIN. + Optional pinCredIdx{ Optional::Missing() }; // Will get set to a value if the PIN is one we know about. bool success = false; bool sendEvent = true; diff --git a/src/platform/Zephyr/BLEAdvertisingArbiter.cpp b/src/platform/Zephyr/BLEAdvertisingArbiter.cpp index 24f7b27317b637..3d0c744dda216b 100644 --- a/src/platform/Zephyr/BLEAdvertisingArbiter.cpp +++ b/src/platform/Zephyr/BLEAdvertisingArbiter.cpp @@ -38,6 +38,8 @@ const BLEAdvertisingArbiter::Request & ToRequest(const sys_snode_t * node) // Notify application about stopped advertising if the callback has been provided void NotifyAdvertisingStopped(const sys_snode_t * node) { + VerifyOrReturn(node); + const Request & request = ToRequest(node); if (request.onStopped != nullptr) diff --git a/src/platform/nrfconnect/BUILD.gn b/src/platform/nrfconnect/BUILD.gn index 7b1a8872aa2d39..ac22b0aed99f20 100644 --- a/src/platform/nrfconnect/BUILD.gn +++ b/src/platform/nrfconnect/BUILD.gn @@ -103,6 +103,7 @@ static_library("nrfconnect") { "wifi/NrfWiFiDriver.h", "wifi/WiFiManager.cpp", "wifi/WiFiManager.h", + "OTAImageProcessorImplWiFi.h", ] } diff --git a/src/platform/nrfconnect/FactoryDataProvider.h b/src/platform/nrfconnect/FactoryDataProvider.h index 368ec957eff5bd..15dae3ab7e3a0e 100644 --- a/src/platform/nrfconnect/FactoryDataProvider.h +++ b/src/platform/nrfconnect/FactoryDataProvider.h @@ -40,11 +40,43 @@ struct InternalFlashFactoryData return CHIP_NO_ERROR; } +#ifdef CONFIG_CHIP_FACTORY_DATA_WRITE_PROTECT +#define TO_STR_IMPL(x) #x +#define TO_STR(x) TO_STR_IMPL(x) + // These two helpers allows to get the factory data memory block which shall be protected with fprotect, so that: + // 1) it is aligned to the multiple of CONFIG_FPROTECT_BLOCK_SIZE (which differs between nRF families) + // 2) it does not exceed the settings partition start address + // Note that this block can overlap with app partition but this is not a problem since we do not aim to modify + // the application code at runtime anyway. + constexpr size_t FactoryDataBlockBegin() + { + // calculate the nearest multiple of CONFIG_FPROTECT_BLOCK_SIZE smaller than PM_FACTORY_DATA_ADDRESS + return PM_FACTORY_DATA_ADDRESS & (-CONFIG_FPROTECT_BLOCK_SIZE); + } + + constexpr size_t FactoryDataBlockSize() + { + // calculate the factory data end address rounded up to the nearest multiple of CONFIG_FPROTECT_BLOCK_SIZE + // and make sure we do not overlap with settings partition + constexpr size_t kFactoryDataBlockEnd = + (PM_FACTORY_DATA_ADDRESS + PM_FACTORY_DATA_SIZE + CONFIG_FPROTECT_BLOCK_SIZE - 1) & (-CONFIG_FPROTECT_BLOCK_SIZE); + static_assert(kFactoryDataBlockEnd <= PM_SETTINGS_STORAGE_ADDRESS, + "FPROTECT memory block, which contains factory data" + "partition overlaps with the settings partition." + "Probably your settings partition size is not a multiple" + "of the atomic FPROTECT block size of " TO_STR(CONFIG_FPROTECT_BLOCK_SIZE) "kB"); + return kFactoryDataBlockEnd - FactoryDataBlockBegin(); + } +#undef TO_STR +#undef TO_STR_IMPL CHIP_ERROR ProtectFactoryDataPartitionAgainstWrite() { - int ret = fprotect_area(PM_FACTORY_DATA_ADDRESS, PM_FACTORY_DATA_SIZE); + int ret = fprotect_area(FactoryDataBlockBegin(), FactoryDataBlockSize()); return System::MapErrorZephyr(ret); } +#else + CHIP_ERROR ProtectFactoryDataPartitionAgainstWrite() { return CHIP_ERROR_NOT_IMPLEMENTED; } +#endif }; struct ExternalFlashFactoryData diff --git a/src/platform/nrfconnect/OTAImageProcessorImplWiFi.h b/src/platform/nrfconnect/OTAImageProcessorImplWiFi.h new file mode 100644 index 00000000000000..f7465312c9f003 --- /dev/null +++ b/src/platform/nrfconnect/OTAImageProcessorImplWiFi.h @@ -0,0 +1,63 @@ +/* + * Copyright (c) 2023 Project CHIP Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#pragma once + +#include "OTAImageProcessorImpl.h" +#include "wifi/WiFiManager.h" + +namespace chip { + +namespace DeviceLayer { + +class OTAImageProcessorImplWiFi : public OTAImageProcessorImpl +{ +public: + explicit OTAImageProcessorImplWiFi(ExternalFlashManager * flashHandler = nullptr) : OTAImageProcessorImpl(flashHandler) {} + + CHIP_ERROR PrepareDownload() override + { + CHIP_ERROR err = WiFiManager::Instance().SetLowPowerMode(false); + if (err == CHIP_NO_ERROR) + { + return OTAImageProcessorImpl::PrepareDownload(); + } + return err; + }; + + CHIP_ERROR Abort() override + { + CHIP_ERROR err = OTAImageProcessorImpl::Abort(); + if (err == CHIP_NO_ERROR) + { + return WiFiManager::Instance().SetLowPowerMode(true); + } + return err; + }; + + CHIP_ERROR Apply() override + { + CHIP_ERROR err = OTAImageProcessorImpl::Apply(); + if (err == CHIP_NO_ERROR) + { + return WiFiManager::Instance().SetLowPowerMode(true); + } + return err; + }; +}; + +} // namespace DeviceLayer +} // namespace chip diff --git a/src/platform/nrfconnect/wifi/WiFiManager.cpp b/src/platform/nrfconnect/wifi/WiFiManager.cpp index d8e60bada951ec..c1eabd557e4805 100644 --- a/src/platform/nrfconnect/wifi/WiFiManager.cpp +++ b/src/platform/nrfconnect/wifi/WiFiManager.cpp @@ -138,11 +138,12 @@ const Map { WIFI_STATE_GROUP_HANDSHAKE, WiFiManager::StationStatus::PROVISIONING }, { WIFI_STATE_COMPLETED, WiFiManager::StationStatus::FULLY_PROVISIONED } }); -const Map +const Map WiFiManager::sEventHandlerMap({ { NET_EVENT_WIFI_SCAN_RESULT, WiFiManager::ScanResultHandler }, { NET_EVENT_WIFI_SCAN_DONE, WiFiManager::ScanDoneHandler }, { NET_EVENT_WIFI_CONNECT_RESULT, WiFiManager::ConnectHandler }, - { NET_EVENT_WIFI_DISCONNECT_RESULT, WiFiManager::DisconnectHandler } }); + { NET_EVENT_WIFI_DISCONNECT_RESULT, WiFiManager::NetworkDrivenDisconnectHandler }, + { NET_EVENT_WIFI_DISCONNECT_COMPLETE, WiFiManager::ApplicationDrivenDisconnectHandler } }); void WiFiManager::WifiMgmtEventHandler(net_mgmt_event_callback * cb, uint32_t mgmtEvent, net_if * iface) { @@ -205,10 +206,31 @@ CHIP_ERROR WiFiManager::Scan(const ByteSpan & ssid, ScanResultCallback resultCal mCachedWiFiState = mWiFiState; mWiFiState = WIFI_STATE_SCANNING; mSsidFound = false; + mRecoveryArmed = true; + // TODO Workaround for recovery mechanism to wait before the next scan request until the WiFi supplicant is not busy. + static bool workaroundDone; - if (net_mgmt(NET_REQUEST_WIFI_SCAN, iface, NULL, 0)) + int ret = net_mgmt(NET_REQUEST_WIFI_SCAN, iface, NULL, 0); + + if (ret) { - ChipLogError(DeviceLayer, "Scan request failed"); + ChipLogError(DeviceLayer, "Scan request failed %d", ret); + if(ret == -EBUSY && !workaroundDone){ + // TODO Wi-Fi driver returned an error during recovery. + // As a workaround schedule the recovery timer one more time in WifiSupplicantWorkaroundTime time. + // This allows the device to run the Scan method without + // rebooting when the "Device or resource busy" error occurs. + DeviceLayer::SystemLayer().StartTimer(System::Clock::Milliseconds32(kWifiSupplicantWorkaroundTime), Recover, nullptr); + workaroundDone = true; + return CHIP_NO_ERROR; + } + else + { + // TODO The workaround has not worked, so reboot the device + ChipLogError(DeviceLayer, "WiFi driver does not respond, resetting the device..."); + workaroundDone = false; + PlatformMgr().Shutdown(); + } return CHIP_ERROR_INTERNAL; } @@ -250,10 +272,12 @@ CHIP_ERROR WiFiManager::Disconnect() net_if * iface = InetUtils::GetInterface(); VerifyOrReturnError(nullptr != iface, CHIP_ERROR_INTERNAL); - int status = net_mgmt(NET_REQUEST_WIFI_DISCONNECT, iface, NULL, 0); + mApplicationDisconnectRequested = true; + int status = net_mgmt(NET_REQUEST_WIFI_DISCONNECT, iface, NULL, 0); if (status) { + mApplicationDisconnectRequested = false; if (status == -EALREADY) { ChipLogDetail(DeviceLayer, "Already disconnected"); @@ -387,15 +411,21 @@ void WiFiManager::ScanDoneHandler(Platform::UniquePtr data) // Internal scan is supposed to be followed by a connection request if the SSID has been found if (Instance().mInternalScan) { - if (!Instance().mSsidFound && !Instance().mRecoveryTimerAborted) + if (Instance().mRecoveryArmed) { - ChipLogProgress(DeviceLayer, "No requested SSID found"); - auto currentTimeout = Instance().CalculateNextRecoveryTime(); - ChipLogProgress(DeviceLayer, "Starting connection recover: re-scanning... (next attempt in %d ms)", - currentTimeout.count()); - Instance().mRecoveryTimerAborted = false; - DeviceLayer::SystemLayer().StartTimer(currentTimeout, Recover, nullptr); - return; + if (!Instance().mSsidFound) + { + ChipLogProgress(DeviceLayer, "No requested SSID found"); + auto currentTimeout = Instance().CalculateNextRecoveryTime(); + ChipLogProgress(DeviceLayer, "Starting connection recover: re-scanning... (next attempt in %d ms)", + currentTimeout.count()); + DeviceLayer::SystemLayer().StartTimer(currentTimeout, Recover, nullptr); + return; + } + else + { + Instance().AbortConnectionRecovery(); + } } Instance().mWiFiState = WIFI_STATE_ASSOCIATING; @@ -412,8 +442,8 @@ void WiFiManager::ScanDoneHandler(Platform::UniquePtr data) Instance().mWiFiState = WIFI_STATE_DISCONNECTED; return; } - ChipLogProgress(DeviceLayer, "Connection to %*s requested", Instance().mWiFiParams.mParams.ssid_length, - Instance().mWiFiParams.mParams.ssid); + ChipLogProgress(DeviceLayer, "Connection to %*s requested [RSSI=%d]", Instance().mWiFiParams.mParams.ssid_length, + Instance().mWiFiParams.mParams.ssid, Instance().mWiFiParams.mRssi); Instance().mInternalScan = false; } }); @@ -499,17 +529,43 @@ void WiFiManager::ConnectHandler(Platform::UniquePtr data) } } -void WiFiManager::DisconnectHandler(Platform::UniquePtr) +void WiFiManager::NetworkDrivenDisconnectHandler(Platform::UniquePtr) { + // Workaround: schedule the application level connection recovery in kSupplicantReconnectionTimeoutMs to give WPA supplicant + // some time to restore it. + if (!Instance().mRecoveryArmed) + { + Instance().mRecoveryArmed = true; + DeviceLayer::SystemLayer().StartTimer( + System::Clock::Milliseconds32(kSupplicantReconnectionTimeoutMs), + [](System::Layer * layer, void * param) { Instance().Disconnect(); }, nullptr); + } + SystemLayer().ScheduleLambda([] { ChipLogProgress(DeviceLayer, "WiFi station disconnected"); Instance().mWiFiState = WIFI_STATE_DISCONNECTED; Instance().PostConnectivityStatusChange(kConnectivity_Lost); - // Ensure fresh recovery for future connection requests. - Instance().ResetRecoveryTime(); }); } +void WiFiManager::ApplicationDrivenDisconnectHandler(Platform::UniquePtr) +{ + if (!Instance().mRecoveryArmed) + { + return; + } + + if (!Instance().mApplicationDisconnectRequested) + { + Instance().AbortConnectionRecovery(); + } + else + { + Instance().mApplicationDisconnectRequested = false; + SystemLayer().ScheduleLambda([] { Recover(nullptr, nullptr); }); + } +} + WiFiManager::StationStatus WiFiManager::GetStationStatus() const { return WiFiManager::sStatusMap[mWiFiState]; @@ -542,6 +598,13 @@ System::Clock::Milliseconds32 WiFiManager::CalculateNextRecoveryTime() void WiFiManager::Recover(System::Layer *, void *) { + // Prevent scheduling recovery if we are already connected to the network. + if (Instance().mWiFiState == WIFI_STATE_COMPLETED) + { + Instance().AbortConnectionRecovery(); + return; + } + // If kConnectionRecoveryMaxOverallInterval has a non-zero value prevent endless re-scan. if (0 != kConnectionRecoveryMaxRetries && (++Instance().mConnectionRecoveryCounter >= kConnectionRecoveryMaxRetries)) { @@ -562,7 +625,36 @@ void WiFiManager::AbortConnectionRecovery() { DeviceLayer::SystemLayer().CancelTimer(Recover, nullptr); Instance().ResetRecoveryTime(); - Instance().mRecoveryTimerAborted = true; + Instance().mRecoveryArmed = false; +} + +CHIP_ERROR WiFiManager::SetLowPowerMode(bool onoff) +{ + net_if * iface = InetUtils::GetInterface(); + VerifyOrReturnError(nullptr != iface, CHIP_ERROR_INTERNAL); + + wifi_ps_config currentConfig{}; + if (net_mgmt(NET_REQUEST_WIFI_PS_CONFIG, iface, ¤tConfig, sizeof(currentConfig))) + { + ChipLogError(DeviceLayer, "Get current low power mode config request failed"); + return CHIP_ERROR_INTERNAL; + } + + if ((currentConfig.ps_params.enabled == WIFI_PS_ENABLED && onoff == false) || + (currentConfig.ps_params.enabled == WIFI_PS_DISABLED && onoff == true)) + { + wifi_ps_params params{ .enabled = onoff ? WIFI_PS_ENABLED : WIFI_PS_DISABLED }; + if (net_mgmt(NET_REQUEST_WIFI_PS, iface, ¶ms, sizeof(params))) + { + ChipLogError(DeviceLayer, "Set low power mode request failed"); + return CHIP_ERROR_INTERNAL; + } + ChipLogProgress(DeviceLayer, "Successfully set low power mode [%d]", onoff); + return CHIP_NO_ERROR; + } + + ChipLogDetail(DeviceLayer, "Low power mode is already in requested state [%d]", onoff); + return CHIP_NO_ERROR; } } // namespace DeviceLayer diff --git a/src/platform/nrfconnect/wifi/WiFiManager.h b/src/platform/nrfconnect/wifi/WiFiManager.h index 880ab4c4ba2a50..5c477d7fa6c73e 100644 --- a/src/platform/nrfconnect/wifi/WiFiManager.h +++ b/src/platform/nrfconnect/wifi/WiFiManager.h @@ -173,6 +173,7 @@ class WiFiManager static constexpr uint32_t kConnectionRecoveryMaxIntervalMs = CONFIG_CHIP_WIFI_CONNECTION_RECOVERY_MAXIMUM_INTERVAL; static constexpr uint32_t kConnectionRecoveryJitterMs = CONFIG_CHIP_WIFI_CONNECTION_RECOVERY_JITTER; static constexpr uint32_t kConnectionRecoveryMaxRetries = CONFIG_CHIP_WIFI_CONNECTION_RECOVERY_MAX_RETRIES_NUMBER; + static constexpr uint32_t kSupplicantReconnectionTimeoutMs = 60000; static_assert(kConnectionRecoveryMinIntervalMs < kConnectionRecoveryMaxIntervalMs); static_assert(kConnectionRecoveryJitterMs <= kConnectionRecoveryMaxIntervalMs); @@ -192,6 +193,7 @@ class WiFiManager CHIP_ERROR GetWiFiInfo(WiFiInfo & info) const; CHIP_ERROR GetNetworkStatistics(NetworkStatistics & stats) const; void AbortConnectionRecovery(); + CHIP_ERROR SetLowPowerMode(bool onoff); private: using NetEventHandler = void (*)(Platform::UniquePtr); @@ -203,14 +205,16 @@ class WiFiManager }; constexpr static uint32_t kWifiManagementEvents = NET_EVENT_WIFI_SCAN_RESULT | NET_EVENT_WIFI_SCAN_DONE | - NET_EVENT_WIFI_CONNECT_RESULT | NET_EVENT_WIFI_DISCONNECT_RESULT | NET_EVENT_WIFI_IFACE_STATUS; + NET_EVENT_WIFI_CONNECT_RESULT | NET_EVENT_WIFI_DISCONNECT_RESULT | NET_EVENT_WIFI_DISCONNECT_COMPLETE | + NET_EVENT_WIFI_IFACE_STATUS; // Event handling static void WifiMgmtEventHandler(net_mgmt_event_callback * cb, uint32_t mgmtEvent, net_if * iface); static void ScanResultHandler(Platform::UniquePtr data); static void ScanDoneHandler(Platform::UniquePtr data); static void ConnectHandler(Platform::UniquePtr data); - static void DisconnectHandler(Platform::UniquePtr data); + static void NetworkDrivenDisconnectHandler(Platform::UniquePtr data); + static void ApplicationDrivenDisconnectHandler(Platform::UniquePtr data); static void PostConnectivityStatusChange(ConnectivityChange changeType); static void SendRouterSolicitation(System::Layer * layer, void * param); @@ -240,10 +244,13 @@ class WiFiManager bool mSsidFound{ false }; uint32_t mConnectionRecoveryCounter{ 0 }; uint32_t mConnectionRecoveryTimeMs{ kConnectionRecoveryMinIntervalMs }; - bool mRecoveryTimerAborted{ false }; + bool mRecoveryArmed{ false }; + bool mApplicationDisconnectRequested{ false }; + // TODO Workaround for recovery mechanism to wait before the next scan request until the WiFi supplicant is not busy. + static constexpr uint32_t kWifiSupplicantWorkaroundTime = 8000; static const Map sStatusMap; - static const Map sEventHandlerMap; + static const Map sEventHandlerMap; }; } // namespace DeviceLayer From 2a9d209a8f9ba571405ed021890df4fb8fd62b7b Mon Sep 17 00:00:00 2001 From: Kamil Kasperczyk Date: Thu, 1 Jun 2023 14:34:16 +0200 Subject: [PATCH 02/12] [zephyr] Remove device argument from SYS_INIT() callbacks. The SYS_INIT() callback API changed in Zephyr and Matter code alignments were needed. --- src/lib/shell/MainLoopZephyr.cpp | 7 ++----- src/platform/Zephyr/SysHeapMalloc.cpp | 2 +- 2 files changed, 3 insertions(+), 6 deletions(-) diff --git a/src/lib/shell/MainLoopZephyr.cpp b/src/lib/shell/MainLoopZephyr.cpp index 53080066704e3e..d106bfa89fa13b 100644 --- a/src/lib/shell/MainLoopZephyr.cpp +++ b/src/lib/shell/MainLoopZephyr.cpp @@ -28,11 +28,8 @@ static int cmd_matter(const struct shell * shell, size_t argc, char ** argv) chip::Shell::streamer_set_shell(shell); return (Engine::Root().ExecCommand(argc - 1, argv + 1) == CHIP_NO_ERROR) ? 0 : -ENOEXEC; } -#ifdef CONFIG_BOARD_TLSR9518ADK80D -static int RegisterCommands(void) -#else -static int RegisterCommands(const struct device * dev) -#endif /* CONFIG_BOARD_TLSR9518ADK80D */ + +static int RegisterCommands() { Engine::Root().RegisterDefaultCommands(); return 0; diff --git a/src/platform/Zephyr/SysHeapMalloc.cpp b/src/platform/Zephyr/SysHeapMalloc.cpp index 1a80fadd1835a7..d4f65b05459615 100644 --- a/src/platform/Zephyr/SysHeapMalloc.cpp +++ b/src/platform/Zephyr/SysHeapMalloc.cpp @@ -67,7 +67,7 @@ LockGuard::~LockGuard() } } -int initHeap(const device *) +int initHeap() { sys_heap_init(&sHeap, sHeapMemory, sizeof(sHeapMemory)); return 0; From dd5d2225a5ef1ef657a9e434c839f06239a181dc Mon Sep 17 00:00:00 2001 From: Damian Krolik Date: Thu, 30 Mar 2023 13:15:52 +0200 Subject: [PATCH 03/12] [nrfconnect] Stop using Zephyr POSIX layer After recent changes in Zephyr, the Zephyr POSIX layer no longer includes missing POSIX definitions from the standard library. Given that and that the Zephyr POSIX layer is very incomplete, it is no longer possible to build Matter samples using that layer. Disable Zephyr socket layer, and use NET_SOCKETS_POSIX_NAMES which only wraps the socket functions with POSIX names. Make sure that proper headers are included when using this configuration. --- config/nrfconnect/chip-module/CMakeLists.txt | 14 ++---- .../nrfconnect/chip-module/Kconfig.defaults | 9 ++-- config/zephyr/Kconfig | 2 +- examples/pigweed-app/nrfconnect/prj.conf | 3 -- .../GenericPlatformManagerImpl_Zephyr.h | 7 +++ src/inet/IPAddress-StringFuncts.cpp | 2 +- src/inet/IPAddress.h | 12 +++-- src/inet/UDPEndPointImplSockets.cpp | 12 +++-- src/inet/ZephyrSocket.h | 8 +++- src/inet/arpa-inet-compatibility.h | 2 +- .../UserDirectedCommissioningClient.cpp | 3 ++ src/system/SystemClock.h | 8 +++- src/system/SystemConfig.h | 48 +++++++++++++++++++ src/system/SystemLayerImplSelect.h | 6 +++ src/system/WakeEvent.cpp | 48 ++++++++++++++++--- 15 files changed, 145 insertions(+), 39 deletions(-) diff --git a/config/nrfconnect/chip-module/CMakeLists.txt b/config/nrfconnect/chip-module/CMakeLists.txt index 2511fa3094cff6..a8b34d16dc77ba 100644 --- a/config/nrfconnect/chip-module/CMakeLists.txt +++ b/config/nrfconnect/chip-module/CMakeLists.txt @@ -50,21 +50,12 @@ include(${COMMON_CMAKE_SOURCE_DIR}/chip_gn_args.cmake) include(${COMMON_CMAKE_SOURCE_DIR}/chip_gn.cmake) # Prepare compiler flags -matter_add_flags(-D_DEFAULT_SOURCE) - -if (CHIP_CFLAGS) - matter_add_flags("${CHIP_CFLAGS}") -endif() +matter_add_flags(-D_POSIX_C_SOURCE=200809) if (CONFIG_ARM) matter_add_cflags(--specs=nosys.specs) endif() -if (CONFIG_POSIX_API) - matter_add_flags(-D_SYS__PTHREADTYPES_H_) - matter_add_flags(-isystem${ZEPHYR_BASE}/include/zephyr/posix) -endif() - if (CONFIG_NORDIC_SECURITY_BACKEND) zephyr_include_directories($) zephyr_include_directories($) @@ -197,8 +188,9 @@ matter_build(chip DEVICE_INFO_EXAMPLE_PROVIDER ${CONFIG_CHIP_EXAMPLE_DEVICE_INFO_PROVIDER} GN_DEPENDENCIES kernel ) + set_property(GLOBAL APPEND PROPERTY ZEPHYR_INTERFACE_LIBS chip) -target_compile_definitions(chip INTERFACE _DEFAULT_SOURCE) +target_compile_definitions(chip INTERFACE _POSIX_C_SOURCE=200809) if (CONFIG_CHIP_MALLOC_SYS_HEAP_OVERRIDE) target_link_options(chip INTERFACE diff --git a/config/nrfconnect/chip-module/Kconfig.defaults b/config/nrfconnect/chip-module/Kconfig.defaults index 2561aa05e855d7..d275d938021c63 100644 --- a/config/nrfconnect/chip-module/Kconfig.defaults +++ b/config/nrfconnect/chip-module/Kconfig.defaults @@ -69,9 +69,9 @@ config PTHREAD_IPC bool default n -# Generic networking options -config NET_SOCKETS_POSIX_NAMES - default n +config POSIX_MAX_FDS + int + default 16 # Application stack size config MAIN_STACK_SIZE @@ -242,9 +242,6 @@ config NET_IF_UNICAST_IPV6_ADDR_COUNT config NET_IF_MCAST_IPV6_ADDR_COUNT default 8 -config NET_SOCKETS_POSIX_NAMES - default n - config NET_SOCKETS_POLL_MAX default 4 diff --git a/config/zephyr/Kconfig b/config/zephyr/Kconfig index f0e8d9eddfcb66..91dd782c1cecf6 100644 --- a/config/zephyr/Kconfig +++ b/config/zephyr/Kconfig @@ -22,7 +22,6 @@ menuconfig CHIP imply REQUIRES_FULL_LIBC imply NEWLIB_LIBC_NANO imply CBPRINTF_LIBC_SUBSTS - imply POSIX_API if !ARCH_POSIX imply EVENTFD if !ARCH_POSIX imply REBOOT imply ENTROPY_GENERATOR @@ -30,6 +29,7 @@ menuconfig CHIP imply NET_IPV6 imply NET_CONFIG_NEED_IPV6 imply NET_SOCKETS + imply NET_SOCKETS_POSIX_NAMES if !ARCH_POSIX imply NETWORKING imply HWINFO imply FLASH diff --git a/examples/pigweed-app/nrfconnect/prj.conf b/examples/pigweed-app/nrfconnect/prj.conf index bb86ae1babb8f8..fad377211225f9 100644 --- a/examples/pigweed-app/nrfconnect/prj.conf +++ b/examples/pigweed-app/nrfconnect/prj.conf @@ -20,9 +20,6 @@ CONFIG_CHIP=y # samples. This file should contain only options specific for this sample # or overrides of default values. -# Export POSIX names for functions implementing a subset of POSIX standard in Zephyr -CONFIG_POSIX_API=y - # Add support for LEDs and buttons on Nordic development kits CONFIG_DK_LIBRARY=y diff --git a/src/include/platform/internal/GenericPlatformManagerImpl_Zephyr.h b/src/include/platform/internal/GenericPlatformManagerImpl_Zephyr.h index 88d98ec9613d92..70b382f961427e 100644 --- a/src/include/platform/internal/GenericPlatformManagerImpl_Zephyr.h +++ b/src/include/platform/internal/GenericPlatformManagerImpl_Zephyr.h @@ -26,7 +26,14 @@ #include #include +#if CHIP_SYSTEM_CONFIG_USE_POSIX_SOCKETS #include +#endif + +#if CHIP_SYSTEM_CONFIG_USE_ZEPHYR_SOCKETS +#include +#endif + #include namespace chip { diff --git a/src/inet/IPAddress-StringFuncts.cpp b/src/inet/IPAddress-StringFuncts.cpp index 1f15e05844b0fe..12beec23ec2295 100644 --- a/src/inet/IPAddress-StringFuncts.cpp +++ b/src/inet/IPAddress-StringFuncts.cpp @@ -34,7 +34,7 @@ #include #include -#if CHIP_SYSTEM_CONFIG_USE_SOCKETS || CHIP_SYSTEM_CONFIG_USE_NETWORK_FRAMEWORK +#if CHIP_SYSTEM_CONFIG_USE_POSIX_SOCKETS || CHIP_SYSTEM_CONFIG_USE_NETWORK_FRAMEWORK #include #endif diff --git a/src/inet/IPAddress.h b/src/inet/IPAddress.h index 661d0f84d65a91..c97f25de752d44 100644 --- a/src/inet/IPAddress.h +++ b/src/inet/IPAddress.h @@ -56,14 +56,18 @@ #include #endif // CHIP_SYSTEM_CONFIG_USE_OPEN_THREAD_ENDPOINT -#if CHIP_SYSTEM_CONFIG_USE_SOCKETS || CHIP_SYSTEM_CONFIG_USE_NETWORK_FRAMEWORK +#if CHIP_SYSTEM_CONFIG_USE_POSIX_SOCKETS || CHIP_SYSTEM_CONFIG_USE_NETWORK_FRAMEWORK #include #include -#endif // CHIP_SYSTEM_CONFIG_USE_SOCKETS || CHIP_SYSTEM_CONFIG_USE_NETWORK_FRAMEWORK +#endif // CHIP_SYSTEM_CONFIG_USE_POSIX_SOCKETS || CHIP_SYSTEM_CONFIG_USE_NETWORK_FRAMEWORK -#if CHIP_SYSTEM_CONFIG_USE_SOCKETS +#if CHIP_SYSTEM_CONFIG_USE_POSIX_SOCKETS #include -#endif // CHIP_SYSTEM_CONFIG_USE_SOCKETS +#endif // CHIP_SYSTEM_CONFIG_USE_POSIX_SOCKETS + +#if CHIP_SYSTEM_CONFIG_USE_ZEPHYR_SOCKETS +#include +#endif // CHIP_SYSTEM_CONFIG_USE_ZEPHYR_SOCKETS #if CHIP_SYSTEM_CONFIG_USE_OPEN_THREAD_ENDPOINT && INET_CONFIG_ENABLE_IPV4 #error Forbidden : native Open Thread implementation with IPV4 enabled diff --git a/src/inet/UDPEndPointImplSockets.cpp b/src/inet/UDPEndPointImplSockets.cpp index 6c85906bb7a9ed..fde54d16cee1b1 100644 --- a/src/inet/UDPEndPointImplSockets.cpp +++ b/src/inet/UDPEndPointImplSockets.cpp @@ -30,14 +30,20 @@ #include #include +#if CHIP_SYSTEM_CONFIG_USE_POSIX_SOCKETS #if HAVE_SYS_SOCKET_H #include -#endif // HAVE_SYS_SOCKET_H - -#include +#endif #include #include #include +#endif // CHIP_SYSTEM_CONFIG_USE_POSIX_SOCKETS + +#if CHIP_SYSTEM_CONFIG_USE_ZEPHYR_SOCKETS +#include +#endif // CHIP_SYSTEM_CONFIG_USE_ZEPHYR_SOCKETS + +#include #include #include diff --git a/src/inet/ZephyrSocket.h b/src/inet/ZephyrSocket.h index 56cc9dcde15a98..93e4c055d8059e 100644 --- a/src/inet/ZephyrSocket.h +++ b/src/inet/ZephyrSocket.h @@ -23,7 +23,13 @@ #pragma once -#include +#if CHIP_SYSTEM_CONFIG_USE_POSIX_SOCKETS +#include +#endif + +#if CHIP_SYSTEM_CONFIG_USE_ZEPHYR_SOCKETS +#include +#endif static inline ssize_t recvmsg(int sock, struct msghdr * msg, int flags) { diff --git a/src/inet/arpa-inet-compatibility.h b/src/inet/arpa-inet-compatibility.h index 56d9121e40d5ae..ce4f2f923c7e73 100644 --- a/src/inet/arpa-inet-compatibility.h +++ b/src/inet/arpa-inet-compatibility.h @@ -20,7 +20,7 @@ #include -#if CHIP_SYSTEM_CONFIG_USE_SOCKETS +#if CHIP_SYSTEM_CONFIG_USE_POSIX_SOCKETS #include #else // !CHIP_SYSTEM_CONFIG_USE_SOCKETS diff --git a/src/protocols/user_directed_commissioning/UserDirectedCommissioningClient.cpp b/src/protocols/user_directed_commissioning/UserDirectedCommissioningClient.cpp index 5701c827b43bc7..4b264db12c2da8 100644 --- a/src/protocols/user_directed_commissioning/UserDirectedCommissioningClient.cpp +++ b/src/protocols/user_directed_commissioning/UserDirectedCommissioningClient.cpp @@ -23,6 +23,7 @@ * */ +#if CHIP_DEVICE_CONFIG_ENABLE_COMMISSIONER_DISCOVERY_CLIENT #include "UserDirectedCommissioning.h" #include @@ -78,3 +79,5 @@ CHIP_ERROR UserDirectedCommissioningClient::EncodeUDCMessage(const System::Packe } // namespace UserDirectedCommissioning } // namespace Protocols } // namespace chip + +#endif // CHIP_DEVICE_CONFIG_ENABLE_COMMISSIONER_DISCOVERY_CLIENT diff --git a/src/system/SystemClock.h b/src/system/SystemClock.h index dfc54e8a12f0e9..d669200ae37000 100644 --- a/src/system/SystemClock.h +++ b/src/system/SystemClock.h @@ -32,9 +32,13 @@ #include #include -#if CHIP_SYSTEM_CONFIG_USE_POSIX_TIME_FUNCTS || CHIP_SYSTEM_CONFIG_USE_SOCKETS +#if CHIP_SYSTEM_CONFIG_USE_POSIX_TIME_FUNCTS || CHIP_SYSTEM_CONFIG_USE_POSIX_SOCKETS #include -#endif // CHIP_SYSTEM_CONFIG_USE_POSIX_TIME_FUNCTS || CHIP_SYSTEM_CONFIG_USE_SOCKETS +#endif // CHIP_SYSTEM_CONFIG_USE_POSIX_TIME_FUNCTS || CHIP_SYSTEM_CONFIG_USE_POSIX_SOCKETS + +#if CHIP_SYSTEM_CONFIG_USE_ZEPHYR_SOCKETS +#include +#endif #include #include diff --git a/src/system/SystemConfig.h b/src/system/SystemConfig.h index 17fbe26101fe32..7315374e21f8aa 100644 --- a/src/system/SystemConfig.h +++ b/src/system/SystemConfig.h @@ -715,3 +715,51 @@ struct LwIPEvent; #define CHIP_SYSTEM_CONFIG_USE_BSD_IFADDRS 0 #endif #endif // CHIP_SYSTEM_CONFIG_USE_BSD_IFADDRS + +/** + * @def CHIP_SYSTEM_CONFIG_USE_ZEPHYR_SOCKETS + * + * @brief + * Use Zephyr socket API. + * + * Defaults to enabled on Zephyr platforms that do not enable Zephyr POSIX layer. + */ +#ifndef CHIP_SYSTEM_CONFIG_USE_ZEPHYR_SOCKETS +#if CHIP_SYSTEM_CONFIG_USE_SOCKETS && __ZEPHYR__ && !CONFIG_POSIX_API +#define CHIP_SYSTEM_CONFIG_USE_ZEPHYR_SOCKETS 1 +#else +#define CHIP_SYSTEM_CONFIG_USE_ZEPHYR_SOCKETS 0 +#endif +#endif // CHIP_SYSTEM_CONFIG_USE_ZEPHYR_SOCKETS + +/** + * @def CHIP_SYSTEM_CONFIG_USE_POSIX_SOCKETS + * + * @brief + * Use POSIX socket API. + * + * Defaults to enabled on platforms that use sockets other than Zephyr sockets. + */ +#ifndef CHIP_SYSTEM_CONFIG_USE_POSIX_SOCKETS +#if CHIP_SYSTEM_CONFIG_USE_SOCKETS && !CHIP_SYSTEM_CONFIG_USE_ZEPHYR_SOCKETS +#define CHIP_SYSTEM_CONFIG_USE_POSIX_SOCKETS 1 +#else +#define CHIP_SYSTEM_CONFIG_USE_POSIX_SOCKETS 0 +#endif +#endif // CHIP_SYSTEM_CONFIG_USE_POSIX_SOCKETS + +/** + * @def CHIP_SYSTEM_CONFIG_USE_ZEPHYR_EVENTFD + * + * @brief + * Use Zephyr eventfd API. + * + * Defaults to enabled on Zephyr platforms that enable CONFIG_EVENTFD. + */ +#ifndef CHIP_SYSTEM_CONFIG_USE_ZEPHYR_EVENTFD +#if __ZEPHYR__ && CONFIG_EVENTFD +#define CHIP_SYSTEM_CONFIG_USE_ZEPHYR_EVENTFD 1 +#else +#define CHIP_SYSTEM_CONFIG_USE_ZEPHYR_EVENTFD 0 +#endif +#endif // CHIP_SYSTEM_CONFIG_USE_ZEPHYR_EVENTFD diff --git a/src/system/SystemLayerImplSelect.h b/src/system/SystemLayerImplSelect.h index 0eb930eeb86c8d..552e8d9e40163d 100644 --- a/src/system/SystemLayerImplSelect.h +++ b/src/system/SystemLayerImplSelect.h @@ -22,7 +22,13 @@ #pragma once +#if CHIP_SYSTEM_CONFIG_USE_POSIX_SOCKETS #include +#endif + +#if CHIP_SYSTEM_CONFIG_USE_ZEPHYR_SOCKETS +#include +#endif #if CHIP_SYSTEM_CONFIG_POSIX_LOCKING #include diff --git a/src/system/WakeEvent.cpp b/src/system/WakeEvent.cpp index ab115025006d03..6a535c90198759 100644 --- a/src/system/WakeEvent.cpp +++ b/src/system/WakeEvent.cpp @@ -38,8 +38,12 @@ #include #if !CHIP_SYSTEM_CONFIG_USE_POSIX_PIPE +#if CHIP_SYSTEM_CONFIG_USE_ZEPHYR_EVENTFD +#include +#else #include #endif +#endif // !CHIP_SYSTEM_CONFIG_USE_POSIX_PIPE namespace chip { namespace System { @@ -122,6 +126,42 @@ CHIP_ERROR WakeEvent::Notify() const #else // CHIP_SYSTEM_CONFIG_USE_POSIX_PIPE +namespace { + +#if CHIP_SYSTEM_CONFIG_USE_ZEPHYR_EVENTFD + +int ReadEvent(int eventFd) +{ + eventfd_t value; + + return eventfd_read(eventFd, &value); +} + +int WriteEvent(int eventFd) +{ + return eventfd_write(eventFd, 1); +} + +#else + +int ReadEvent(int eventFd) +{ + uint64_t value; + + return ::read(eventFd, &value, sizeof(value)); +} + +int WriteEvent(int eventFd) +{ + uint64_t value = 1; + + return ::write(mReadFD, &value, sizeof(value)); +} + +#endif + +} // namespace + CHIP_ERROR WakeEvent::Open(LayerSockets & systemLayer) { mReadFD = ::eventfd(0, 0); @@ -146,9 +186,7 @@ void WakeEvent::Close(LayerSockets & systemLayer) void WakeEvent::Confirm() const { - uint64_t value; - - if (::read(mReadFD, &value, sizeof(value)) < 0 && errno != EAGAIN && errno != EWOULDBLOCK) + if (ReadEvent(mReadFD) < 0 && errno != EAGAIN && errno != EWOULDBLOCK) { ChipLogError(chipSystemLayer, "System wake event confirm failed: %" CHIP_ERROR_FORMAT, CHIP_ERROR_POSIX(errno).Format()); } @@ -156,9 +194,7 @@ void WakeEvent::Confirm() const CHIP_ERROR WakeEvent::Notify() const { - uint64_t value = 1; - - if (::write(mReadFD, &value, sizeof(value)) < 0 && errno != EAGAIN && errno != EWOULDBLOCK) + if (WriteEvent(mReadFD) < 0 && errno != EAGAIN && errno != EWOULDBLOCK) { return CHIP_ERROR_POSIX(errno); } From 872b41230018e295fbefaf8252d7ba3caa2d2126 Mon Sep 17 00:00:00 2001 From: Kamil Kasperczyk Date: Thu, 1 Jun 2023 15:25:45 +0200 Subject: [PATCH 04/12] [nrfconnect] Removed obsolete MCUMGR SMP BT config Replaced CONFIG_MCUMGR_SMP_BT that is no longer supported with the CONFIG_MCUMGR_TRANSPORT_BT --- examples/platform/nrfconnect/util/DFUOverSMP.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/platform/nrfconnect/util/DFUOverSMP.cpp b/examples/platform/nrfconnect/util/DFUOverSMP.cpp index 95e3ab521bcdc2..ac59171598127f 100644 --- a/examples/platform/nrfconnect/util/DFUOverSMP.cpp +++ b/examples/platform/nrfconnect/util/DFUOverSMP.cpp @@ -17,7 +17,7 @@ #include "DFUOverSMP.h" -#if !defined(CONFIG_MCUMGR_SMP_BT) || !defined(CONFIG_MCUMGR_GRP_IMG) || !defined(CONFIG_MCUMGR_CMD_OS_MGMT) +#if !defined(CONFIG_MCUMGR_TRANSPORT_BT) || !defined(CONFIG_MCUMGR_GRP_IMG) || !defined(CONFIG_MCUMGR_GRP_OS) #error "DFUOverSMP requires MCUMGR module configs enabled" #endif From 2ba771d0282e25ec48f4c50803057db5f37b267e Mon Sep 17 00:00:00 2001 From: Kamil Kasperczyk Date: Fri, 2 Jun 2023 12:01:22 +0200 Subject: [PATCH 05/12] Addressed review comments * Added CHIP_NRF_PLATFORM symbol to conditionally modify generic Zephyr configuration * Updated docker versions for cloud builds * Updated sdk-zephyr toolchain version to 0.16.0 in build scripts for nrf platform. --- config/nrfconnect/chip-module/CMakeLists.txt | 4 ++++ config/nrfconnect/chip-module/Kconfig | 8 ++++++++ config/zephyr/Kconfig | 3 ++- integrations/cloudbuild/build-all.yaml | 6 +++--- integrations/cloudbuild/chef.yaml | 6 +++--- integrations/cloudbuild/smoke-test.yaml | 12 ++++++------ scripts/build/builders/nrf.py | 2 +- scripts/examples/nrfconnect_example.sh | 2 +- src/inet/UDPEndPointImplSockets.cpp | 2 +- 9 files changed, 29 insertions(+), 16 deletions(-) diff --git a/config/nrfconnect/chip-module/CMakeLists.txt b/config/nrfconnect/chip-module/CMakeLists.txt index a8b34d16dc77ba..269a4c179e7007 100644 --- a/config/nrfconnect/chip-module/CMakeLists.txt +++ b/config/nrfconnect/chip-module/CMakeLists.txt @@ -50,6 +50,10 @@ include(${COMMON_CMAKE_SOURCE_DIR}/chip_gn_args.cmake) include(${COMMON_CMAKE_SOURCE_DIR}/chip_gn.cmake) # Prepare compiler flags +if (CHIP_CFLAGS) + matter_add_flags("${CHIP_CFLAGS}") +endif() + matter_add_flags(-D_POSIX_C_SOURCE=200809) if (CONFIG_ARM) diff --git a/config/nrfconnect/chip-module/Kconfig b/config/nrfconnect/chip-module/Kconfig index b4e7bc1863a17f..059d5112652b3f 100644 --- a/config/nrfconnect/chip-module/Kconfig +++ b/config/nrfconnect/chip-module/Kconfig @@ -18,6 +18,14 @@ rsource "../../zephyr/Kconfig" if CHIP +config CHIP_NRF_PLATFORM + bool + default y + help + States that the configuration uses Matter nRF platform, + what can be used to conditionally deviate from Zephyr generic configuration + for nRF platform related purposes. + # See config/zephyr/Kconfig for full definition config CHIP_DEVICE_VENDOR_NAME default "Nordic Semiconductor ASA" diff --git a/config/zephyr/Kconfig b/config/zephyr/Kconfig index 91dd782c1cecf6..3ea261d2371eca 100644 --- a/config/zephyr/Kconfig +++ b/config/zephyr/Kconfig @@ -22,6 +22,7 @@ menuconfig CHIP imply REQUIRES_FULL_LIBC imply NEWLIB_LIBC_NANO imply CBPRINTF_LIBC_SUBSTS + imply POSIX_API if !ARCH_POSIX && !CHIP_NRF_PLATFORM imply EVENTFD if !ARCH_POSIX imply REBOOT imply ENTROPY_GENERATOR @@ -29,7 +30,7 @@ menuconfig CHIP imply NET_IPV6 imply NET_CONFIG_NEED_IPV6 imply NET_SOCKETS - imply NET_SOCKETS_POSIX_NAMES if !ARCH_POSIX + imply NET_SOCKETS_POSIX_NAMES if !ARCH_POSIX && CHIP_NRF_PLATFORM imply NETWORKING imply HWINFO imply FLASH diff --git a/integrations/cloudbuild/build-all.yaml b/integrations/cloudbuild/build-all.yaml index fdc77e8a58aae1..433ff656d0b188 100644 --- a/integrations/cloudbuild/build-all.yaml +++ b/integrations/cloudbuild/build-all.yaml @@ -6,7 +6,7 @@ steps: - "--init" - "--recursive" id: Submodules - - name: "connectedhomeip/chip-build-vscode:0.7.3" + - name: "connectedhomeip/chip-build-vscode:0.7.16" env: - PW_ENVIRONMENT_ROOT=/pwenv args: @@ -21,7 +21,7 @@ steps: path: /pwenv timeout: 900s - - name: "connectedhomeip/chip-build-vscode:0.7.3" + - name: "connectedhomeip/chip-build-vscode:0.7.16" env: - PW_ENVIRONMENT_ROOT=/pwenv args: @@ -84,7 +84,7 @@ steps: --target k32w-shell build --create-archives /workspace/artifacts/ - - name: "connectedhomeip/chip-build-vscode:0.7.3" + - name: "connectedhomeip/chip-build-vscode:0.7.16" env: - PW_ENVIRONMENT_ROOT=/pwenv args: diff --git a/integrations/cloudbuild/chef.yaml b/integrations/cloudbuild/chef.yaml index 4db1c7afb05b2e..bde0b7aea6d481 100644 --- a/integrations/cloudbuild/chef.yaml +++ b/integrations/cloudbuild/chef.yaml @@ -1,5 +1,5 @@ steps: - - name: "connectedhomeip/chip-build-vscode:0.7.3" + - name: "connectedhomeip/chip-build-vscode:0.7.16" env: - PW_ENVIRONMENT_ROOT=/pwenv args: @@ -12,7 +12,7 @@ steps: path: /pwenv timeout: 2700s - - name: "connectedhomeip/chip-build-vscode:0.7.3" + - name: "connectedhomeip/chip-build-vscode:0.7.16" env: - PW_ENVIRONMENT_ROOT=/pwenv args: @@ -26,7 +26,7 @@ steps: - name: pwenv path: /pwenv - - name: "connectedhomeip/chip-build-vscode:0.7.3" + - name: "connectedhomeip/chip-build-vscode:0.7.16" env: - PW_ENVIRONMENT_ROOT=/pwenv args: diff --git a/integrations/cloudbuild/smoke-test.yaml b/integrations/cloudbuild/smoke-test.yaml index 5c1d09c5f555ad..40c4b68479c01b 100644 --- a/integrations/cloudbuild/smoke-test.yaml +++ b/integrations/cloudbuild/smoke-test.yaml @@ -1,5 +1,5 @@ steps: - - name: "connectedhomeip/chip-build-vscode:0.7.3" + - name: "connectedhomeip/chip-build-vscode:0.7.16" entrypoint: "bash" args: - "-c" @@ -22,7 +22,7 @@ steps: path: /pwenv timeout: 900s - - name: "connectedhomeip/chip-build-vscode:0.7.3" + - name: "connectedhomeip/chip-build-vscode:0.7.16" id: ESP32 env: - PW_ENVIRONMENT_ROOT=/pwenv @@ -42,7 +42,7 @@ steps: volumes: - name: pwenv path: /pwenv - - name: "connectedhomeip/chip-build-vscode:0.7.3" + - name: "connectedhomeip/chip-build-vscode:0.7.16" id: NRFConnect env: - PW_ENVIRONMENT_ROOT=/pwenv @@ -63,7 +63,7 @@ steps: - name: pwenv path: /pwenv - - name: "connectedhomeip/chip-build-vscode:0.7.3" + - name: "connectedhomeip/chip-build-vscode:0.7.16" id: EFR32 env: - PW_ENVIRONMENT_ROOT=/pwenv @@ -85,7 +85,7 @@ steps: - name: pwenv path: /pwenv - - name: "connectedhomeip/chip-build-vscode:0.7.3" + - name: "connectedhomeip/chip-build-vscode:0.7.16" id: Linux env: - PW_ENVIRONMENT_ROOT=/pwenv @@ -145,7 +145,7 @@ steps: - name: pwenv path: /pwenv - - name: "connectedhomeip/chip-build-vscode:0.7.3" + - name: "connectedhomeip/chip-build-vscode:0.7.16" id: Android env: - PW_ENVIRONMENT_ROOT=/pwenv diff --git a/scripts/build/builders/nrf.py b/scripts/build/builders/nrf.py index 6357a1e755fb3b..d699d60ebd0148 100644 --- a/scripts/build/builders/nrf.py +++ b/scripts/build/builders/nrf.py @@ -161,7 +161,7 @@ def generate(self): zephyr_base = os.environ['ZEPHYR_BASE'] nrfconnect_sdk = os.path.dirname(zephyr_base) zephyr_sdk_dir = os.environ.get('ZEPHYR_SDK_INSTALL_DIR') or os.path.join( - os.environ['NRF5_TOOLS_ROOT'], 'zephyr-sdk-0.15.2') + os.environ['NRF5_TOOLS_ROOT'], 'zephyr-sdk-0.16.0') # NRF builds will both try to change .west/config in nrfconnect and # overall perform a git fetch on that location diff --git a/scripts/examples/nrfconnect_example.sh b/scripts/examples/nrfconnect_example.sh index 072ecada10a2db..db1c850ff5e9a9 100755 --- a/scripts/examples/nrfconnect_example.sh +++ b/scripts/examples/nrfconnect_example.sh @@ -44,7 +44,7 @@ source "../scripts/activate.sh" export ZEPHYR_TOOLCHAIN_VARIANT=zephyr if [[ -z "$ZEPHYR_SDK_INSTALL_DIR" && -n "$NRF5_TOOLS_ROOT" ]]; then - export ZEPHYR_SDK_INSTALL_DIR="$NRF5_TOOLS_ROOT"/zephyr-sdk-0.15.2 + export ZEPHYR_SDK_INSTALL_DIR="$NRF5_TOOLS_ROOT"/zephyr-sdk-0.16.0 fi # Set ccache base directory to improve the cache hit ratio diff --git a/src/inet/UDPEndPointImplSockets.cpp b/src/inet/UDPEndPointImplSockets.cpp index fde54d16cee1b1..5c9748d0cf32fb 100644 --- a/src/inet/UDPEndPointImplSockets.cpp +++ b/src/inet/UDPEndPointImplSockets.cpp @@ -33,7 +33,7 @@ #if CHIP_SYSTEM_CONFIG_USE_POSIX_SOCKETS #if HAVE_SYS_SOCKET_H #include -#endif +#endif // HAVE_SYS_SOCKET_H #include #include #include From 3086350c5b56f30120e2a69a878e2f26f4e5d724 Mon Sep 17 00:00:00 2001 From: "Restyled.io" Date: Thu, 1 Jun 2023 20:24:30 +0000 Subject: [PATCH 06/12] Restyled by whitespace --- src/platform/Zephyr/BLEAdvertisingArbiter.cpp | 2 +- src/platform/nrfconnect/wifi/WiFiManager.cpp | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/platform/Zephyr/BLEAdvertisingArbiter.cpp b/src/platform/Zephyr/BLEAdvertisingArbiter.cpp index 3d0c744dda216b..29f55168f1c627 100644 --- a/src/platform/Zephyr/BLEAdvertisingArbiter.cpp +++ b/src/platform/Zephyr/BLEAdvertisingArbiter.cpp @@ -39,7 +39,7 @@ const BLEAdvertisingArbiter::Request & ToRequest(const sys_snode_t * node) void NotifyAdvertisingStopped(const sys_snode_t * node) { VerifyOrReturn(node); - + const Request & request = ToRequest(node); if (request.onStopped != nullptr) diff --git a/src/platform/nrfconnect/wifi/WiFiManager.cpp b/src/platform/nrfconnect/wifi/WiFiManager.cpp index c1eabd557e4805..e327d010471929 100644 --- a/src/platform/nrfconnect/wifi/WiFiManager.cpp +++ b/src/platform/nrfconnect/wifi/WiFiManager.cpp @@ -224,12 +224,12 @@ CHIP_ERROR WiFiManager::Scan(const ByteSpan & ssid, ScanResultCallback resultCal workaroundDone = true; return CHIP_NO_ERROR; } - else + else { // TODO The workaround has not worked, so reboot the device ChipLogError(DeviceLayer, "WiFi driver does not respond, resetting the device..."); workaroundDone = false; - PlatformMgr().Shutdown(); + PlatformMgr().Shutdown(); } return CHIP_ERROR_INTERNAL; } From 4d32d04f619f8047539c5550af7fcf9f73193823 Mon Sep 17 00:00:00 2001 From: "Restyled.io" Date: Thu, 1 Jun 2023 20:24:31 +0000 Subject: [PATCH 07/12] Restyled by clang-format --- src/platform/nrfconnect/wifi/WiFiManager.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/platform/nrfconnect/wifi/WiFiManager.cpp b/src/platform/nrfconnect/wifi/WiFiManager.cpp index e327d010471929..68192516b73437 100644 --- a/src/platform/nrfconnect/wifi/WiFiManager.cpp +++ b/src/platform/nrfconnect/wifi/WiFiManager.cpp @@ -215,7 +215,8 @@ CHIP_ERROR WiFiManager::Scan(const ByteSpan & ssid, ScanResultCallback resultCal if (ret) { ChipLogError(DeviceLayer, "Scan request failed %d", ret); - if(ret == -EBUSY && !workaroundDone){ + if (ret == -EBUSY && !workaroundDone) + { // TODO Wi-Fi driver returned an error during recovery. // As a workaround schedule the recovery timer one more time in WifiSupplicantWorkaroundTime time. // This allows the device to run the Scan method without From ce98ffb1eb3c69b095f3a694b709896ed77d3245 Mon Sep 17 00:00:00 2001 From: "Restyled.io" Date: Thu, 1 Jun 2023 20:24:32 +0000 Subject: [PATCH 08/12] Restyled by gn --- src/platform/nrfconnect/BUILD.gn | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/platform/nrfconnect/BUILD.gn b/src/platform/nrfconnect/BUILD.gn index ac22b0aed99f20..65167ac4c8b5f5 100644 --- a/src/platform/nrfconnect/BUILD.gn +++ b/src/platform/nrfconnect/BUILD.gn @@ -97,13 +97,13 @@ static_library("nrfconnect") { sources += [ "../Zephyr/InetUtils.cpp", "../Zephyr/InetUtils.h", + "OTAImageProcessorImplWiFi.h", "wifi/ConnectivityManagerImplWiFi.cpp", "wifi/ConnectivityManagerImplWiFi.h", "wifi/NrfWiFiDriver.cpp", "wifi/NrfWiFiDriver.h", "wifi/WiFiManager.cpp", "wifi/WiFiManager.h", - "OTAImageProcessorImplWiFi.h", ] } From 28400155c846a6e9aa74a6859bbb88d240768742 Mon Sep 17 00:00:00 2001 From: Kamil Kasperczyk Date: Fri, 2 Jun 2023 12:23:24 +0200 Subject: [PATCH 09/12] Fixed chef CI workflow --- .github/workflows/chef.yaml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/chef.yaml b/.github/workflows/chef.yaml index 42dba7ca4485aa..671eb2a7c5a47f 100644 --- a/.github/workflows/chef.yaml +++ b/.github/workflows/chef.yaml @@ -35,7 +35,7 @@ jobs: if: github.actor != 'restyled-io[bot]' container: - image: connectedhomeip/chip-build:0.7.3 + image: connectedhomeip/chip-build:0.7.16 options: --user root steps: @@ -71,7 +71,7 @@ jobs: if: github.actor != 'restyled-io[bot]' container: - image: connectedhomeip/chip-build-esp32:0.7.3 + image: connectedhomeip/chip-build-esp32:0.7.16 options: --user root steps: @@ -107,7 +107,7 @@ jobs: if: github.actor != 'restyled-io[bot]' container: - image: connectedhomeip/chip-build-nrf-platform:0.7.3 + image: connectedhomeip/chip-build-nrf-platform:0.7.16 options: --user root steps: From 26d942f84b30ae85cd6fad946c51ff5967b6b609 Mon Sep 17 00:00:00 2001 From: Kamil Kasperczyk Date: Fri, 2 Jun 2023 13:46:52 +0200 Subject: [PATCH 10/12] Fixed compilation errors * Fixed typo in wake event * Removed ifdef leading to compilation errors for Darwin and Linux and added ifdef for usleep usage that is a root cause of problems on Zephyr. --- .../UserDirectedCommissioningClient.cpp | 12 +++++++++--- src/system/WakeEvent.cpp | 2 +- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/src/protocols/user_directed_commissioning/UserDirectedCommissioningClient.cpp b/src/protocols/user_directed_commissioning/UserDirectedCommissioningClient.cpp index 4b264db12c2da8..831a7bc1f668df 100644 --- a/src/protocols/user_directed_commissioning/UserDirectedCommissioningClient.cpp +++ b/src/protocols/user_directed_commissioning/UserDirectedCommissioningClient.cpp @@ -23,9 +23,12 @@ * */ -#if CHIP_DEVICE_CONFIG_ENABLE_COMMISSIONER_DISCOVERY_CLIENT #include "UserDirectedCommissioning.h" +#ifdef __ZEPHYR__ +#include +#endif // __ZEPHYR__ + #include namespace chip { @@ -51,7 +54,12 @@ CHIP_ERROR UserDirectedCommissioningClient::SendUDCMessage(TransportMgrBase * tr ChipLogError(AppServer, "UDC SendMessage failed: %" CHIP_ERROR_FORMAT, err.Format()); return err; } + // Zephyr doesn't provide usleep implementation. +#ifdef __ZEPHYR__ + k_usleep(100 * 1000); // 100ms +#else usleep(100 * 1000); // 100ms +#endif // __ZEPHYR__ } ChipLogProgress(Inet, "UDC msg sent"); @@ -79,5 +87,3 @@ CHIP_ERROR UserDirectedCommissioningClient::EncodeUDCMessage(const System::Packe } // namespace UserDirectedCommissioning } // namespace Protocols } // namespace chip - -#endif // CHIP_DEVICE_CONFIG_ENABLE_COMMISSIONER_DISCOVERY_CLIENT diff --git a/src/system/WakeEvent.cpp b/src/system/WakeEvent.cpp index 6a535c90198759..1a3a806badcde3 100644 --- a/src/system/WakeEvent.cpp +++ b/src/system/WakeEvent.cpp @@ -155,7 +155,7 @@ int WriteEvent(int eventFd) { uint64_t value = 1; - return ::write(mReadFD, &value, sizeof(value)); + return ::write(eventFd, &value, sizeof(value)); } #endif From e2eb7628ce2e0ce1d45540828592280f24acea33 Mon Sep 17 00:00:00 2001 From: Damian Krolik Date: Fri, 2 Jun 2023 19:20:44 +0200 Subject: [PATCH 11/12] Fix more compilation errors --- src/app/clusters/door-lock-server/door-lock-server.cpp | 4 ++-- src/system/SystemConfig.h | 2 +- src/system/WakeEvent.cpp | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/app/clusters/door-lock-server/door-lock-server.cpp b/src/app/clusters/door-lock-server/door-lock-server.cpp index 7c79db19f7aadf..dbfd723ad8cfff 100644 --- a/src/app/clusters/door-lock-server/door-lock-server.cpp +++ b/src/app/clusters/door-lock-server/door-lock-server.cpp @@ -3344,8 +3344,8 @@ bool DoorLockServer::HandleRemoteLockOperation(chip::app::CommandHandler * comma EndpointId endpoint = commandPath.mEndpointId; OperationErrorEnum reason = OperationErrorEnum::kUnspecified; - Nullable pinUserIdx; // Will get set to non-null if we find a user for the PIN. - Optional pinCredIdx{ Optional::Missing() }; // Will get set to a value if the PIN is one we know about. + Nullable pinUserIdx; // Will get set to non-null if we find a user for the PIN. + Optional pinCredIdx; // Will get set to a value if the PIN is one we know about. bool success = false; bool sendEvent = true; diff --git a/src/system/SystemConfig.h b/src/system/SystemConfig.h index 7315374e21f8aa..d0188ca70f46e2 100644 --- a/src/system/SystemConfig.h +++ b/src/system/SystemConfig.h @@ -725,7 +725,7 @@ struct LwIPEvent; * Defaults to enabled on Zephyr platforms that do not enable Zephyr POSIX layer. */ #ifndef CHIP_SYSTEM_CONFIG_USE_ZEPHYR_SOCKETS -#if CHIP_SYSTEM_CONFIG_USE_SOCKETS && __ZEPHYR__ && !CONFIG_POSIX_API +#if CHIP_SYSTEM_CONFIG_USE_SOCKETS && __ZEPHYR__ && CONFIG_NET_SOCKETS_POSIX_NAMES #define CHIP_SYSTEM_CONFIG_USE_ZEPHYR_SOCKETS 1 #else #define CHIP_SYSTEM_CONFIG_USE_ZEPHYR_SOCKETS 0 diff --git a/src/system/WakeEvent.cpp b/src/system/WakeEvent.cpp index 1a3a806badcde3..4b5d7c2a9ad00f 100644 --- a/src/system/WakeEvent.cpp +++ b/src/system/WakeEvent.cpp @@ -144,14 +144,14 @@ int WriteEvent(int eventFd) #else -int ReadEvent(int eventFd) +ssize_t ReadEvent(int eventFd) { uint64_t value; return ::read(eventFd, &value, sizeof(value)); } -int WriteEvent(int eventFd) +ssize_t WriteEvent(int eventFd) { uint64_t value = 1; From 27422c6be326324112b1faa9274e0c9b8a6e80a4 Mon Sep 17 00:00:00 2001 From: Damian Krolik Date: Fri, 2 Jun 2023 19:22:06 +0200 Subject: [PATCH 12/12] [chef] fixes to Zephyr environment variables 1. Use Zephyr SDK toolchain. 2. Use proper shell configuration. --- config/nrfconnect/chip-module/CMakeLists.txt | 3 ++ examples/chef/chef.py | 33 ++++++++++++++------ examples/chef/nrfconnect/CMakeLists.txt | 5 ++- examples/chef/nrfconnect/main.cpp | 4 +-- 4 files changed, 31 insertions(+), 14 deletions(-) diff --git a/config/nrfconnect/chip-module/CMakeLists.txt b/config/nrfconnect/chip-module/CMakeLists.txt index 269a4c179e7007..43149d2306e3c1 100644 --- a/config/nrfconnect/chip-module/CMakeLists.txt +++ b/config/nrfconnect/chip-module/CMakeLists.txt @@ -194,7 +194,10 @@ matter_build(chip ) set_property(GLOBAL APPEND PROPERTY ZEPHYR_INTERFACE_LIBS chip) +# Enable visibility of POSIX.1-2008 functions, such as strnlen target_compile_definitions(chip INTERFACE _POSIX_C_SOURCE=200809) +# Make sure that kernel symbols that are only referenced by the Matter libraries are resolved. +target_link_libraries(chip INTERFACE $) if (CONFIG_CHIP_MALLOC_SYS_HEAP_OVERRIDE) target_link_options(chip INTERFACE diff --git a/examples/chef/chef.py b/examples/chef/chef.py index b663a49f495676..7e8de18787458e 100755 --- a/examples/chef/chef.py +++ b/examples/chef/chef.py @@ -75,6 +75,8 @@ def load_config() -> None: "for the vendor's SDK") configStream = open(configFile, 'w') config["nrfconnect"]["ZEPHYR_BASE"] = os.environ.get('ZEPHYR_BASE') + config["nrfconnect"]["ZEPHYR_SDK_INSTALL_DIR"] = os.environ.get( + 'ZEPHYR_SDK_INSTALL_DIR') config["nrfconnect"]["TTY"] = None config["esp32"]["IDF_PATH"] = os.environ.get('IDF_PATH') config["esp32"]["TTY"] = None @@ -374,9 +376,6 @@ def main() -> int: flush_print( f"{device_name} in CICD config but not {_DEVICE_FOLDER}!") exit(1) - if options.build_target == "nrfconnect": - shell.run_cmd( - "export GNUARMEMB_TOOLCHAIN_PATH=\"$PW_ARM_CIPD_INSTALL_DIR\"") shell.run_cmd(f"cd {_CHEF_SCRIPT_PATH}") command = f"./chef.py -cbr -d {device_name} -t {options.build_target}" flush_print(f"Building {command}", with_border=True) @@ -412,8 +411,6 @@ def main() -> int: command += " ".join(args) flush_print(f"Building {command}", with_border=True) shell.run_cmd(f"cd {_CHEF_SCRIPT_PATH}") - shell.run_cmd( - "export GNUARMEMB_TOOLCHAIN_PATH=\"$PW_ARM_CIPD_INSTALL_DIR\"") try: shell.run_cmd(command) except RuntimeError as build_fail_error: @@ -469,11 +466,29 @@ def main() -> int: elif options.build_target == "nrfconnect": if config['nrfconnect']['ZEPHYR_BASE'] is None: flush_print( - 'Path for nrfconnect SDK was not found. Make sure nrfconnect.ZEPHYR_BASE is set on your config.yaml file') + 'The path for nrfconnect SDK was not found. Make sure nrfconnect.ZEPHYR_BASE is set on your config.yaml file. This is typically /ncs/vX.X.X/zephyr') exit(1) - shell.run_cmd( - f'source {config["nrfconnect"]["ZEPHYR_BASE"]}/zephyr-env.sh') - shell.run_cmd("export ZEPHYR_TOOLCHAIN_VARIANT=gnuarmemb") + if config['nrfconnect']['ZEPHYR_SDK_INSTALL_DIR'] is None: + flush_print( + 'The path for nrfconnect toolchain was not found. Make sure nrfconnect.ZEPHYR_SDK_INSTALL_DIR is set on your config.yaml file. This is typically /ncs/toolchains/vX.X.X/opt/zephyr-sdk') + exit(1) + zephyr_sdk_dir = config['nrfconnect']['ZEPHYR_SDK_INSTALL_DIR'] + shell.run_cmd("export ZEPHYR_TOOLCHAIN_VARIANT=zephyr") + shell.run_cmd(f"export ZEPHYR_SDK_INSTALL_DIR={zephyr_sdk_dir}") + shell.run_cmd(f"export ZEPHYR_BASE={config['nrfconnect']['ZEPHYR_BASE']}") + shell.run_cmd(f'source {config["nrfconnect"]["ZEPHYR_BASE"]}/zephyr-env.sh') + # QUIRK: + # When the Zephyr SDK is installed as a part of the NCS toolchain, the build system will use + # build tools from the NCS toolchain, but it will not update the PATH and LD_LIBRARY_PATH + # and hence the build will fail. This ideally, should be handled automatically by the NCS + # build system but until it is fixed, set the variables manually. + ncs_toolchain_dir = os.path.abspath(f"{zephyr_sdk_dir}/../..") + if os.path.exists(os.path.join(ncs_toolchain_dir, 'manifest.json')): + shell.run_cmd(f"export PATH=$PATH:{ncs_toolchain_dir}/usr/bin") + shell.run_cmd(f"export PATH=$PATH:{ncs_toolchain_dir}/usr/local/bin") + shell.run_cmd(f"export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:{ncs_toolchain_dir}/usr/lib") + shell.run_cmd( + f"export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:{ncs_toolchain_dir}/usr/local/lib") elif options.build_target == "linux": pass elif options.build_target == "silabs-thread": diff --git a/examples/chef/nrfconnect/CMakeLists.txt b/examples/chef/nrfconnect/CMakeLists.txt index 4249001f35a0ec..c813a314a74264 100644 --- a/examples/chef/nrfconnect/CMakeLists.txt +++ b/examples/chef/nrfconnect/CMakeLists.txt @@ -32,7 +32,6 @@ set(CHIP_CFLAGS "${CHIP_CFLAGS} -DCHIP_DEVICE_CONFIG_DEVICE_PRODUCT_ID=${CONFIG_ if(NOT ${CONFIG_DEVICE_PRODUCT_NAME} STREQUAL "") set(CHIP_CFLAGS "${CHIP_CFLAGS} -DCHIP_DEVICE_CONFIG_DEVICE_PRODUCT_NAME=\"${CONFIG_DEVICE_PRODUCT_NAME}\"") endif() -set(CHIP_CFLAGS "${CHIP_CFLAGS} -DCHIP_PLATFORM_NRFCONNECT=1") if(NOT ${CHIP_DEVICE_CONFIG_DEVICE_SOFTWARE_VERSION_STRING} STREQUAL "") set(CHIP_CFLAGS "${CHIP_CFLAGS} -DCHIP_DEVICE_CONFIG_DEVICE_SOFTWARE_VERSION_STRING=\"${CHIP_DEVICE_CONFIG_DEVICE_SOFTWARE_VERSION_STRING}\"") endif() @@ -76,7 +75,7 @@ target_include_directories(app PRIVATE ${NRFCONNECT_COMMON}/app/include ) -if (CONFIG_ENABLE_CHIP_SHELL) +if (CONFIG_CHIP_LIB_SHELL) target_sources(app PRIVATE ${CHEF}/shell_common/globals.cpp ${CHEF}/shell_common/cmd_misc.cpp @@ -86,7 +85,7 @@ if (CONFIG_ENABLE_CHIP_SHELL) target_include_directories(app PRIVATE ${CHEF}/shell_common/include ) -endif (CONFIG_ENABLE_CHIP_SHELL) +endif() target_sources(app PRIVATE ${CHEF}/nrfconnect/main.cpp diff --git a/examples/chef/nrfconnect/main.cpp b/examples/chef/nrfconnect/main.cpp index 17e207ead026cc..c4157798567e5b 100644 --- a/examples/chef/nrfconnect/main.cpp +++ b/examples/chef/nrfconnect/main.cpp @@ -138,7 +138,7 @@ int main() ChipLogError(AppServer, "OpenBasicCommissioningWindow() failed"); } -#if CONFIG_ENABLE_CHIP_SHELL || CONFIG_CHIP_LIB_SHELL +#if CONFIG_CHIP_LIB_SHELL int rc = Engine::Root().Init(); if (rc != 0) { @@ -154,7 +154,7 @@ int main() cmd_app_server_init(); #endif -#if CONFIG_ENABLE_CHIP_SHELL || CONFIG_CHIP_LIB_SHELL +#if CONFIG_CHIP_LIB_SHELL Engine::Root().RunMainLoop(); #endif