diff --git a/.github/workflows/minimal-build.yaml b/.github/workflows/minimal-build.yaml index 9ba9565b44c25b..ade1bd56ea36ff 100644 --- a/.github/workflows/minimal-build.yaml +++ b/.github/workflows/minimal-build.yaml @@ -17,7 +17,7 @@ name: Minimal Build (Linux / configure) on: push: branches-ignore: - - 'dependabot/**' + - "dependabot/**" pull_request: merge_group: @@ -42,11 +42,11 @@ jobs: - name: Checkout submodules # but don't bootstrap! uses: ./.github/actions/checkout-submodules with: - platform: linux + platform: linux - name: Configure and build All Clusters App run: | - CC=gcc CXX=g++ scripts/configure --project=examples/all-clusters-app/linux && ./ninja-build + CC=gcc CXX=g++ scripts/configure --project=examples/all-clusters-app/linux --enable-recommended=no && ./ninja-build minimal-network-manager: name: Linux / configure build of network-manager-app @@ -64,8 +64,8 @@ jobs: - name: Checkout submodules # but don't bootstrap! uses: ./.github/actions/checkout-submodules with: - platform: linux + platform: linux - name: Configure and build Network Manager App run: | - CC=gcc CXX=g++ scripts/configure --project=examples/network-manager-app/linux && ./ninja-build + CC=gcc CXX=g++ scripts/configure --project=examples/network-manager-app/linux --enable-recommended=no && ./ninja-build diff --git a/config/recommended.gni b/config/recommended.gni new file mode 100644 index 00000000000000..a30045ced7814e --- /dev/null +++ b/config/recommended.gni @@ -0,0 +1,31 @@ +# Copyright (c) 2024 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. + +declare_args() { + # Note for SDK developers: As additional features with their own settings + # are added to the SDK, consider using the `matter_enable_recommended` + # meta-setting instead of a default value of 'true', especially where a + # different default is used based on platform (current_os): Often various + # debugging features have previously been defaulted to on for Linux and/or + # Mac but off for embedded platforms (on the assumption that Linux / Mac + # don't have resource constraints?); build settings of that nature should + # instead reference this meta-setting. E.g. + # enable_flux_capacitor = matter_enable_recommended && current_os == "linux" + + # Enable recommended settings by default. This is a meta-setting + # that is enabled by default, and acts as a default for various + # other settings. Setting it to false produces a more conservative / + # minimal set of defaults. + matter_enable_recommended = true +} diff --git a/examples/chip-tool/templates/logging/DataModelLogger-src.zapt b/examples/chip-tool/templates/logging/DataModelLogger-src.zapt index 3f76143ffab36c..cbce6c27abf767 100644 --- a/examples/chip-tool/templates/logging/DataModelLogger-src.zapt +++ b/examples/chip-tool/templates/logging/DataModelLogger-src.zapt @@ -1,6 +1,7 @@ {{> header}} #include +#include using namespace chip::app::Clusters; diff --git a/examples/chip-tool/templates/logging/EntryToText-src.zapt b/examples/chip-tool/templates/logging/EntryToText-src.zapt index 646ee2ad872eaf..f7cf8ab51c533b 100644 --- a/examples/chip-tool/templates/logging/EntryToText-src.zapt +++ b/examples/chip-tool/templates/logging/EntryToText-src.zapt @@ -81,4 +81,14 @@ char const * GeneratedCommandIdToText(chip::ClusterId cluster, chip::CommandId i {{/zcl_clusters}} default: return "Unknown"; } +} + +char const * DeviceTypeIdToText(chip::DeviceTypeId id) { + switch(id) + { +{{#zcl_device_types}} + case {{asHex code 8}}: return "{{caption}}"; +{{/zcl_device_types}} + default: return "Unknown"; + } } \ No newline at end of file diff --git a/examples/chip-tool/templates/logging/EntryToText.zapt b/examples/chip-tool/templates/logging/EntryToText.zapt index d1a78f84dc218c..fa77ffc916dced 100644 --- a/examples/chip-tool/templates/logging/EntryToText.zapt +++ b/examples/chip-tool/templates/logging/EntryToText.zapt @@ -10,4 +10,6 @@ char const * AttributeIdToText(chip::ClusterId cluster, chip::AttributeId id); char const * AcceptedCommandIdToText(chip::ClusterId cluster, chip::CommandId id); -char const * GeneratedCommandIdToText(chip::ClusterId cluster, chip::CommandId id); \ No newline at end of file +char const * GeneratedCommandIdToText(chip::ClusterId cluster, chip::CommandId id); + +char const * DeviceTypeIdToText(chip::DeviceTypeId id); \ No newline at end of file diff --git a/examples/chip-tool/templates/partials/StructLoggerImpl.zapt b/examples/chip-tool/templates/partials/StructLoggerImpl.zapt index 3dbd99e7400ef4..e4da56005b8064 100644 --- a/examples/chip-tool/templates/partials/StructLoggerImpl.zapt +++ b/examples/chip-tool/templates/partials/StructLoggerImpl.zapt @@ -3,12 +3,34 @@ CHIP_ERROR DataModelLogger::LogValue(const char * label, size_t indent, const ch DataModelLogger::LogString(label, indent, "{"); {{#zcl_struct_items}} { +{{#if (isEqual type "devtype_id") }} +{{#if isNullable }} + if (value.{{asLowerCamelCase label}}.IsNull()) + { + CHIP_ERROR err = LogValue("{{asUpperCamelCase label}}", indent + 1, value.{{asLowerCamelCase label}}); + if (err != CHIP_NO_ERROR) + { + DataModelLogger::LogString(indent + 1, "Struct truncated due to invalid value for '{{asUpperCamelCase label}}'"); + return err; + } + } + else + { + std::string item = std::to_string(value.{{asLowerCamelCase label}}.Value()) + " (" + DeviceTypeIdToText(value.{{asLowerCamelCase label}}.Value()) + ")"; + DataModelLogger::LogString("{{asUpperCamelCase label}}", indent + 1, item); + } +{{else}} + std::string item = std::to_string(value.{{asLowerCamelCase label}}) + " (" + DeviceTypeIdToText(value.{{asLowerCamelCase label}}) + ")"; + DataModelLogger::LogString("{{asUpperCamelCase label}}", indent + 1, item); +{{/if}} +{{else}} CHIP_ERROR err = LogValue("{{asUpperCamelCase label}}", indent + 1, value.{{asLowerCamelCase label}}); if (err != CHIP_NO_ERROR) { DataModelLogger::LogString(indent + 1, "Struct truncated due to invalid value for '{{asUpperCamelCase label}}'"); return err; } +{{/if}} } {{/zcl_struct_items}} DataModelLogger::LogString(indent, "}"); diff --git a/examples/platform/silabs/BaseApplication.cpp b/examples/platform/silabs/BaseApplication.cpp index cbef67996c4528..c61b91f7400879 100644 --- a/examples/platform/silabs/BaseApplication.cpp +++ b/examples/platform/silabs/BaseApplication.cpp @@ -621,7 +621,7 @@ void BaseApplication::CancelFactoryResetSequence() if (sIsFactoryResetTriggered) { sIsFactoryResetTriggered = false; - ChipLogProgress(AppServer, "Factory Reset has been Canceled"); + ChipLogProgress(AppServer, "Factory Reset has been cancelled"); } } @@ -854,7 +854,7 @@ void BaseApplication::OnPlatformEvent(const ChipDeviceEvent * event, intptr_t) VerifyOrReturn(event->InternetConnectivityChange.IPv4 == kConnectivity_Established); if (DIC_OK != dic_init(dic::control::subscribeCB)) { - SILABS_LOG("Failed to initialize DIC module\n"); + ChipLogError(AppServer, "dic_init failed"); } #endif // DIC_ENABLE #ifdef DISPLAY_ENABLED diff --git a/examples/platform/silabs/SiWx917/SiWx917/sl_wifi_if.cpp b/examples/platform/silabs/SiWx917/SiWx917/sl_wifi_if.cpp index ad3e15f6715c43..d283f05162bd54 100644 --- a/examples/platform/silabs/SiWx917/SiWx917/sl_wifi_if.cpp +++ b/examples/platform/silabs/SiWx917/SiWx917/sl_wifi_if.cpp @@ -36,8 +36,12 @@ #include "task.h" #include "wfx_host_events.h" #include "wfx_rsi.h" + #include #include +#include +#include +#include #include extern "C" { @@ -120,7 +124,7 @@ static void DHCPTimerEventHandler(void * arg) WfxPostEvent(&event); } -static void CancelDHCPTimer() +static void CancelDHCPTimer(void) { osStatus_t status; @@ -164,8 +168,10 @@ int32_t wfx_rsi_get_ap_info(wfx_wifi_scan_result_t * ap) { sl_status_t status = SL_STATUS_OK; int32_t rssi = 0; + ap->ssid_length = wfx_rsi.sec.ssid_length; ap->security = wfx_rsi.sec.security; ap->chan = wfx_rsi.ap_chan; + chip::Platform::CopyString(ap->ssid, ap->ssid_length, wfx_rsi.sec.ssid); memcpy(&ap->bssid[0], &wfx_rsi.ap_mac.octet[0], BSSID_LEN); sl_wifi_get_signal_strength(SL_WIFI_CLIENT_INTERFACE, &rssi); ap->rssi = rssi; @@ -197,14 +203,14 @@ int32_t wfx_rsi_get_ap_ext(wfx_wifi_scan_ext_t * extra_info) } /****************************************************************** - * @fn int32_t wfx_rsi_reset_count() + * @fn int32_t wfx_rsi_reset_count(void) * @brief * Getting the driver reset count * @param[in] None * @return * status *********************************************************************/ -int32_t wfx_rsi_reset_count() +int32_t wfx_rsi_reset_count(void) { sl_wifi_statistics_t test = { 0 }; sl_status_t status = SL_STATUS_OK; @@ -221,14 +227,14 @@ int32_t wfx_rsi_reset_count() } /****************************************************************** - * @fn wfx_rsi_disconnect() + * @fn wfx_rsi_disconnect(void) * @brief * Getting the driver disconnect status * @param[in] None * @return * status *********************************************************************/ -int32_t wfx_rsi_disconnect() +int32_t wfx_rsi_disconnect(void) { return sl_wifi_disconnect(SL_WIFI_CLIENT_INTERFACE); } @@ -251,18 +257,17 @@ sl_status_t join_callback_handler(sl_wifi_event_t event, char * result, uint32_t */ ChipLogDetail(DeviceLayer, "join_callback_handler: success"); memset(&temp_reset, 0, sizeof(temp_reset)); - - WfxEvent.eventType = WFX_EVT_STA_CONN; - WfxPostEvent(&WfxEvent); wfx_rsi.join_retries = 0; callback_status = SL_STATUS_OK; + WfxEvent.eventType = WFX_EVT_STA_CONN; + WfxPostEvent(&WfxEvent); return SL_STATUS_OK; } #if CHIP_CONFIG_ENABLE_ICD_SERVER #if SLI_SI91X_MCU_INTERFACE // Required to invoke button press event during sleep as falling edge is not detected -void sl_si91x_invoke_btn_press_event() +void sl_si91x_invoke_btn_press_event(void) { // TODO: should be removed once we are getting the press interrupt for button 0 with sleep if (!RSI_NPSSGPIO_GetPin(SL_BUTTON_BTN0_PIN) && !btn0_pressed) @@ -298,12 +303,12 @@ void sl_si91x_invoke_btn_press_event() #endif // SLI_SI91X_MCU_INTERFACE /****************************************************************** - * @fn wfx_rsi_power_save() + * @fn wfx_rsi_power_save(rsi_power_save_profile_mode_t sl_si91x_ble_state, sl_si91x_performance_profile_t sl_si91x_wifi_state) * @brief * Setting the RS911x in DTIM sleep based mode * * @param[in] sl_si91x_ble_state : State to set for the BLE - sl_si91x_wifi_state : State to set for the WiFi + * @param[in] sl_si91x_wifi_state : State to set for the WiFi * @return * None *********************************************************************/ @@ -339,7 +344,7 @@ int32_t wfx_rsi_power_save(rsi_power_save_profile_mode_t sl_si91x_ble_state, sl_ *****************************************************************************************/ int32_t wfx_wifi_rsi_init(void) { - ChipLogDetail(DeviceLayer, "wfx_wifi_rsi_init started"); + ChipLogDetail(DeviceLayer, "wfx_wifi_rsi_init: started"); sl_status_t status; status = sl_wifi_init(&config, NULL, sl_wifi_default_event_handler); VerifyOrReturnError(status == SL_STATUS_OK, status); @@ -534,7 +539,10 @@ sl_status_t show_scan_results(sl_wifi_scan_result_t * scan_result) for (int idx = 0; idx < (int) scan_result->scan_count; idx++) { memset(&cur_scan_result, 0, sizeof(cur_scan_result)); - strncpy(cur_scan_result.ssid, (char *) &scan_result->scan_info[idx].ssid, WFX_MAX_SSID_LENGTH); + + cur_scan_result.ssid_length = strnlen((char *) scan_result->scan_info[idx].ssid, + chip::min(sizeof(scan_result->scan_info[idx].ssid), WFX_MAX_SSID_LENGTH)); + chip::Platform::CopyString(cur_scan_result.ssid, cur_scan_result.ssid_length, (char *) scan_result->scan_info[idx].ssid); // if user has provided ssid, then check if the current scan result ssid matches the user provided ssid if (wfx_rsi.scan_ssid != NULL && @@ -559,10 +567,10 @@ sl_status_t show_scan_results(sl_wifi_scan_result_t * scan_result) // cleanup and return wfx_rsi.dev_state &= ~WFX_RSI_ST_SCANSTARTED; wfx_rsi.scan_cb((wfx_wifi_scan_result_t *) 0); - wfx_rsi.scan_cb = NULL; + wfx_rsi.scan_cb = nullptr; if (wfx_rsi.scan_ssid) { - vPortFree(wfx_rsi.scan_ssid); + chip::Platform::MemoryFree(wfx_rsi.scan_ssid); wfx_rsi.scan_ssid = NULL; } return SL_STATUS_OK; @@ -576,14 +584,14 @@ sl_status_t bg_scan_callback_handler(sl_wifi_event_t event, sl_wifi_scan_result_ return SL_STATUS_OK; } /*************************************************************************************** - * @fn static void wfx_rsi_save_ap_info() + * @fn static void wfx_rsi_save_ap_info(void) * @brief * Saving the details of the AP * @param[in] None * @return * None *******************************************************************************************/ -static void wfx_rsi_save_ap_info() // translation +static void wfx_rsi_save_ap_info(void) // translation { sl_status_t status = SL_STATUS_OK; #ifndef EXP_BOARD @@ -592,8 +600,8 @@ static void wfx_rsi_save_ap_info() // translation #endif sl_wifi_ssid_t ssid_arg; memset(&ssid_arg, 0, sizeof(ssid_arg)); - ssid_arg.length = strnlen(wfx_rsi.sec.ssid, WFX_MAX_SSID_LENGTH); - strncpy((char *) &ssid_arg.value[0], wfx_rsi.sec.ssid, WFX_MAX_SSID_LENGTH); + ssid_arg.length = wfx_rsi.sec.ssid_length; + chip::Platform::CopyString((char *) &ssid_arg.value[0], ssid_arg.length, wfx_rsi.sec.ssid); sl_wifi_set_scan_callback(scan_callback_handler, NULL); scan_results_complete = false; #ifndef EXP_BOARD @@ -619,7 +627,7 @@ static sl_status_t wfx_rsi_do_join(void) sl_status_t status = SL_STATUS_OK; sl_wifi_client_configuration_t ap; memset(&ap, 0, sizeof(ap)); - WfxEvent_t event; + switch (wfx_rsi.sec.security) { case WFX_SEC_WEP: @@ -662,19 +670,17 @@ static sl_status_t wfx_rsi_do_join(void) status = sl_wifi_set_advanced_client_configuration(SL_WIFI_CLIENT_INTERFACE, &client_config); VerifyOrReturnError(status == SL_STATUS_OK, status); #endif // CHIP_CONFIG_ENABLE_ICD_SERVER - size_t psk_length = strlen(wfx_rsi.sec.passkey); - VerifyOrReturnError(psk_length <= SL_WIFI_MAX_PSK_LENGTH, SL_STATUS_SI91X_INVALID_PSK_LENGTH); sl_net_credential_id_t id = SL_NET_DEFAULT_WIFI_CLIENT_CREDENTIAL_ID; - status = sl_net_set_credential(id, SL_NET_WIFI_PSK, &wfx_rsi.sec.passkey[0], psk_length); + status = sl_net_set_credential(id, SL_NET_WIFI_PSK, &wfx_rsi.sec.passkey[0], wfx_rsi.sec.passkey_length); VerifyOrReturnError(status == SL_STATUS_OK, status); uint32_t timeout_ms = 0; - ap.ssid.length = strnlen(wfx_rsi.sec.ssid, WFX_MAX_SSID_LENGTH); + ap.ssid.length = wfx_rsi.sec.ssid_length; ap.encryption = SL_WIFI_NO_ENCRYPTION; ap.credential_id = id; - memset(&ap.ssid.value, 0, (sizeof(ap.ssid.value) / sizeof(ap.ssid.value[0]))); - strncpy((char *) &ap.ssid.value[0], wfx_rsi.sec.ssid, WFX_MAX_SSID_LENGTH); + memcpy((char *) &ap.ssid.value[0], wfx_rsi.sec.ssid, wfx_rsi.sec.ssid_length); ChipLogDetail(DeviceLayer, "wfx_rsi_do_join: SSID: %s, SECURITY: %d(%d)", ap.ssid.value, ap.security, wfx_rsi.sec.security); + status = sl_wifi_connect(SL_WIFI_CLIENT_INTERFACE, &ap, timeout_ms); // sl_wifi_connect returns SL_STATUS_IN_PROGRESS if join is in progress // after the initial scan is done, the scan does not check for SSID @@ -687,24 +693,25 @@ static sl_status_t wfx_rsi_do_join(void) wfx_rsi.dev_state &= ~(WFX_RSI_ST_STA_CONNECTING | WFX_RSI_ST_STA_CONNECTED); ChipLogProgress(DeviceLayer, "wfx_rsi_do_join: retry attempt %d", wfx_rsi.join_retries); wfx_retry_connection(++wfx_rsi.join_retries); + + WfxEvent_t event; event.eventType = WFX_EVT_STA_START_JOIN; WfxPostEvent(&event); + return status; } /// NotifyConnectivity /// @brief Notify the application about the connectivity status if it has not been notified yet. /// Helper function for HandleDHCPPolling. -void NotifyConnectivity() +void NotifyConnectivity(void) { - if (!hasNotifiedWifiConnectivity) - { - wfx_connected_notify(CONNECTION_STATUS_SUCCESS, &wfx_rsi.ap_mac); - hasNotifiedWifiConnectivity = true; - } + VerifyOrReturn(!hasNotifiedWifiConnectivity); + wfx_connected_notify(CONNECTION_STATUS_SUCCESS, &wfx_rsi.ap_mac); + hasNotifiedWifiConnectivity = true; } -void HandleDHCPPolling() +void HandleDHCPPolling(void) { struct netif * sta_netif; WfxEvent_t event; @@ -722,6 +729,8 @@ void HandleDHCPPolling() { wfx_dhcp_got_ipv4((uint32_t) sta_netif->ip_addr.u_addr.ip4.addr); hasNotifiedIPV4 = true; + event.eventType = WFX_EVT_STA_DHCP_DONE; + WfxPostEvent(&event); NotifyConnectivity(); } else if (dhcp_state == DHCP_OFF) @@ -760,7 +769,7 @@ void WfxPostEvent(WfxEvent_t * event) /// ResetDHCPNotificationFlags /// @brief Reset the flags that are used to notify the application about DHCP connectivity /// and emits a WFX_EVT_STA_DO_DHCP event to trigger DHCP polling checks. Helper function for ProcessEvent. -void ResetDHCPNotificationFlags() +void ResetDHCPNotificationFlags(void) { WfxEvent_t outEvent; @@ -877,7 +886,7 @@ void ProcessEvent(WfxEvent_t inEvent) /********************************************************************************* * @fn void wfx_rsi_task(void *arg) * @brief - * The main WLAN task - started by wfx_wifi_start () that interfaces with RSI. + * The main WLAN task - started by wfx_wifi_start() that interfaces with RSI. * The rest of RSI stuff come in call-backs. * The initialization has been already done. * @param[in] arg: diff --git a/examples/platform/silabs/efr32/rs911x/rsi_if.cpp b/examples/platform/silabs/efr32/rs911x/rsi_if.cpp index d5560d69e97219..02500c80f78e35 100644 --- a/examples/platform/silabs/efr32/rs911x/rsi_if.cpp +++ b/examples/platform/silabs/efr32/rs911x/rsi_if.cpp @@ -54,10 +54,10 @@ extern "C" { #include "silabs_utils.h" #include "wfx_rsi.h" -// TODO convert this file to cpp and use CodeUtils.h -#ifndef MIN -#define MIN(a, b) ((a) < (b) ? (a) : (b)) -#endif +#include +#include +#include +#include #define WFX_QUEUE_SIZE 10 @@ -112,21 +112,21 @@ static void DHCPTimerEventHandler(void * arg) WfxPostEvent(&event); } -static void CancelDHCPTimer() +static void CancelDHCPTimer(void) { osStatus_t status; // Check if timer started if (!osTimerIsRunning(sDHCPTimer)) { - SILABS_LOG("CancelDHCPTimer: timer not running"); + ChipLogError(DeviceLayer, "CancelDHCPTimer: timer not running"); return; } status = osTimerStop(sDHCPTimer); if (status != osOK) { - SILABS_LOG("CancelDHCPTimer: failed to stop timer with status: %d", status); + ChipLogError(DeviceLayer, "CancelDHCPTimer: failed to stop timer with status: %d", status); } } @@ -140,7 +140,7 @@ static void StartDHCPTimer(uint32_t timeout) status = osTimerStart(sDHCPTimer, pdMS_TO_TICKS(timeout)); if (status != osOK) { - SILABS_LOG("StartDHCPTimer: failed to start timer with status: %d", status); + ChipLogError(DeviceLayer, "StartDHCPTimer: failed to start timer with status: %d", status); } } @@ -154,7 +154,7 @@ static void StartDHCPTimer(uint32_t timeout) *********************************************************************/ int32_t wfx_rsi_get_ap_info(wfx_wifi_scan_result_t * ap) { - int32_t status; + int32_t status = RSI_SUCCESS; uint8_t rssi; ap->security = wfx_rsi.sec.security; ap->chan = wfx_rsi.ap_chan; @@ -182,70 +182,65 @@ int32_t wfx_rsi_get_ap_ext(wfx_wifi_scan_ext_t * extra_info) status = rsi_wlan_get(RSI_WLAN_EXT_STATS, buff, sizeof(buff)); if (status != RSI_SUCCESS) { - SILABS_LOG("Failed, Error Code : 0x%lX", status); - } - else - { - rsi_wlan_ext_stats_t * test = (rsi_wlan_ext_stats_t *) buff; - extra_info->beacon_lost_count = test->beacon_lost_count - temp_reset.beacon_lost_count; - extra_info->beacon_rx_count = test->beacon_rx_count - temp_reset.beacon_rx_count; - extra_info->mcast_rx_count = test->mcast_rx_count - temp_reset.mcast_rx_count; - extra_info->mcast_tx_count = test->mcast_tx_count - temp_reset.mcast_tx_count; - extra_info->ucast_rx_count = test->ucast_rx_count - temp_reset.ucast_rx_count; - extra_info->ucast_tx_count = test->ucast_tx_count - temp_reset.ucast_tx_count; - extra_info->overrun_count = test->overrun_count - temp_reset.overrun_count; + ChipLogError(DeviceLayer, "Failed, Error Code : 0x%lX", status); + return status; } + rsi_wlan_ext_stats_t * test = (rsi_wlan_ext_stats_t *) buff; + extra_info->beacon_lost_count = test->beacon_lost_count - temp_reset.beacon_lost_count; + extra_info->beacon_rx_count = test->beacon_rx_count - temp_reset.beacon_rx_count; + extra_info->mcast_rx_count = test->mcast_rx_count - temp_reset.mcast_rx_count; + extra_info->mcast_tx_count = test->mcast_tx_count - temp_reset.mcast_tx_count; + extra_info->ucast_rx_count = test->ucast_rx_count - temp_reset.ucast_rx_count; + extra_info->ucast_tx_count = test->ucast_tx_count - temp_reset.ucast_tx_count; + extra_info->overrun_count = test->overrun_count - temp_reset.overrun_count; return status; } /****************************************************************** - * @fn int32_t wfx_rsi_reset_count() + * @fn int32_t wfx_rsi_reset_count(void) * @brief * Getting the driver reset count * @param[in] None * @return * status *********************************************************************/ -int32_t wfx_rsi_reset_count() +int32_t wfx_rsi_reset_count(void) { int32_t status; uint8_t buff[RSI_RESPONSE_MAX_SIZE] = { 0 }; status = rsi_wlan_get(RSI_WLAN_EXT_STATS, buff, sizeof(buff)); if (status != RSI_SUCCESS) { - SILABS_LOG("Failed, Error Code : 0x%lX", status); - } - else - { - rsi_wlan_ext_stats_t * test = (rsi_wlan_ext_stats_t *) buff; - temp_reset.beacon_lost_count = test->beacon_lost_count; - temp_reset.beacon_rx_count = test->beacon_rx_count; - temp_reset.mcast_rx_count = test->mcast_rx_count; - temp_reset.mcast_tx_count = test->mcast_tx_count; - temp_reset.ucast_rx_count = test->ucast_rx_count; - temp_reset.ucast_tx_count = test->ucast_tx_count; - temp_reset.overrun_count = test->overrun_count; + ChipLogError(DeviceLayer, "Failed, Error Code : 0x%lX", status); + return status; } + rsi_wlan_ext_stats_t * test = (rsi_wlan_ext_stats_t *) buff; + temp_reset.beacon_lost_count = test->beacon_lost_count; + temp_reset.beacon_rx_count = test->beacon_rx_count; + temp_reset.mcast_rx_count = test->mcast_rx_count; + temp_reset.mcast_tx_count = test->mcast_tx_count; + temp_reset.ucast_rx_count = test->ucast_rx_count; + temp_reset.ucast_tx_count = test->ucast_tx_count; + temp_reset.overrun_count = test->overrun_count; return status; } /****************************************************************** - * @fn wfx_rsi_disconnect() + * @fn wfx_rsi_disconnect(void) * @brief * Getting the driver disconnect status * @param[in] None * @return * status *********************************************************************/ -int32_t wfx_rsi_disconnect() +int32_t wfx_rsi_disconnect(void) { - int32_t status = rsi_wlan_disconnect(); - return status; + return rsi_wlan_disconnect(); } #if SL_ICD_ENABLED /****************************************************************** - * @fn wfx_rsi_power_save() + * @fn wfx_rsi_power_save(void) * @brief * Setting the RS911x in DTIM sleep based mode * @@ -253,14 +248,14 @@ int32_t wfx_rsi_disconnect() * @return * None *********************************************************************/ -int32_t wfx_rsi_power_save() +int32_t wfx_rsi_power_save(void) { int32_t status; #ifdef RSI_BLE_ENABLE status = rsi_bt_power_save_profile(RSI_SLEEP_MODE_2, RSI_MAX_PSP); if (status != RSI_SUCCESS) { - SILABS_LOG("BT Powersave Config Failed, Error Code : 0x%lX", status); + ChipLogError(DeviceLayer, "BT Powersave Config Failed, Error Code : 0x%lX", status); return status; } #endif /* RSI_BLE_ENABLE */ @@ -268,10 +263,10 @@ int32_t wfx_rsi_power_save() status = rsi_wlan_power_save_profile(RSI_SLEEP_MODE_2, RSI_MAX_PSP); if (status != RSI_SUCCESS) { - SILABS_LOG("Powersave Config Failed, Error Code : 0x%lX", status); + ChipLogError(DeviceLayer, "Powersave Config Failed, Error Code : 0x%lX", status); return status; } - SILABS_LOG("Powersave Config Success"); + ChipLogDetail(DeviceLayer, "Powersave Config Success"); return status; } #endif /* SL_ICD_ENABLED */ @@ -295,20 +290,19 @@ static void wfx_rsi_join_cb(uint16_t status, const uint8_t * buf, const uint16_t /* * We should enable retry.. (Need config variable for this) */ - SILABS_LOG("wfx_rsi_join_cb: failed. retry: %d", wfx_rsi.join_retries); + ChipLogProgress(DeviceLayer, "wfx_rsi_join_cb: failed. retry: %d", wfx_rsi.join_retries); wfx_retry_connection(++wfx_rsi.join_retries); + return; } - else - { - /* - * Join was complete - Do the DHCP - */ - memset(&temp_reset, 0, sizeof(wfx_wifi_scan_ext_t)); - SILABS_LOG("wfx_rsi_join_cb: join completed."); - WfxEvent.eventType = WFX_EVT_STA_CONN; - WfxPostEvent(&WfxEvent); - wfx_rsi.join_retries = 0; - } + + /* + * Join was complete - Do the DHCP + */ + ChipLogProgress(DeviceLayer, "wfx_rsi_join_cb: success"); + memset(&temp_reset, 0, sizeof(wfx_wifi_scan_ext_t)); + WfxEvent.eventType = WFX_EVT_STA_CONN; + WfxPostEvent(&WfxEvent); + wfx_rsi.join_retries = 0; } /****************************************************************** @@ -323,7 +317,7 @@ static void wfx_rsi_join_cb(uint16_t status, const uint8_t * buf, const uint16_t *********************************************************************/ static void wfx_rsi_join_fail_cb(uint16_t status, uint8_t * buf, uint32_t len) { - SILABS_LOG("wfx_rsi_join_fail_cb: error: failed status: %02x", status); + ChipLogError(DeviceLayer, "wfx_rsi_join_fail_cb: status: %d", status); WfxEvent_t WfxEvent; wfx_rsi.join_retries += 1; wfx_rsi.dev_state &= ~(WFX_RSI_ST_STA_CONNECTING | WFX_RSI_ST_STA_CONNECTED); @@ -363,30 +357,27 @@ static int32_t wfx_rsi_init(void) uint8_t buf[RSI_RESPONSE_HOLD_BUFF_SIZE]; extern void rsi_hal_board_init(void); - SILABS_LOG("wfx_rsi_init: starting(HEAP_SZ = %d)", SL_HEAP_SIZE); + ChipLogProgress(DeviceLayer, "wfx_rsi_init: starting(HEAP_SZ = %d)", SL_HEAP_SIZE); //! Driver initialization status = rsi_driver_init(wfx_rsi_drv_buf, WFX_RSI_BUF_SZ); if ((status < RSI_DRIVER_STATUS) || (status > WFX_RSI_BUF_SZ)) { - SILABS_LOG("wfx_rsi_init: error: RSI Driver initialization failed with status: %02x", status); + ChipLogError(DeviceLayer, "wfx_rsi_init: rsi_driver_init failed: %ld", status); return status; } - - SILABS_LOG("wfx_rsi_init: rsi_device_init", __func__); /* ! Redpine module intialisation */ if ((status = rsi_device_init(LOAD_NWP_FW)) != RSI_SUCCESS) { - SILABS_LOG("wfx_rsi_init: error: rsi_device_init failed with status: %02x", status); + ChipLogError(DeviceLayer, "wfx_rsi_init: rsi_device_init failed: %ld", status); return status; } - SILABS_LOG("wfx_rsi_init: start wireless drv task", __func__); /* * Create the driver wrapper thread */ sDrvThread = osThreadNew(rsi_wireless_driver_task_wrapper, NULL, &kDrvTaskAttr); if (NULL == sDrvThread) { - SILABS_LOG("wfx_rsi_init: error: rsi_wireless_driver_task failed", __func__); + ChipLogError(DeviceLayer, "wfx_rsi_init: failed to create task"); return RSI_ERROR_INVALID_PARAM; } @@ -397,41 +388,40 @@ static int32_t wfx_rsi_init(void) if ((status = rsi_wireless_init(OPER_MODE_0, COEX_MODE_0)) != RSI_SUCCESS) { #endif - SILABS_LOG("wfx_rsi_init: error: Initialize WiSeConnect failed with status: %02x", status); + ChipLogError(DeviceLayer, "wfx_rsi_init: rsi_wireless_init failed: %ld", status); return status; } - SILABS_LOG("wfx_rsi_init: get FW version..", __func__); /* * Get the MAC and other info to let the user know about it. */ if (rsi_wlan_get(RSI_FW_VERSION, buf, sizeof(buf)) != RSI_SUCCESS) { - SILABS_LOG("wfx_rsi_init: error: rsi_wlan_get(RSI_FW_VERSION) failed with status: %02x", status); + ChipLogError(DeviceLayer, "wfx_rsi_init: rsi_wlan_get(RSI_FW_VERSION) failed: %ld", status); return status; } buf[sizeof(buf) - 1] = 0; - SILABS_LOG("wfx_rsi_init: RSI firmware version: %s", buf); + ChipLogProgress(DeviceLayer, "RSI firmware version: %s", buf); //! Send feature frame if ((status = rsi_send_feature_frame()) != RSI_SUCCESS) { - SILABS_LOG("wfx_rsi_init: error: rsi_send_feature_frame failed with status: %02x", status); + ChipLogError(DeviceLayer, "error: rsi_send_feature_frame failed: %ld", status); return status; } - SILABS_LOG("wfx_rsi_init: sent rsi_send_feature_frame", __func__); /* initializes wlan radio parameters and WLAN supplicant parameters. */ (void) rsi_wlan_radio_init(); /* Required so we can get MAC address */ if ((status = rsi_wlan_get(RSI_MAC_ADDRESS, &wfx_rsi.sta_mac.octet[0], RESP_BUFF_SIZE)) != RSI_SUCCESS) { - SILABS_LOG("wfx_rsi_init: error: rsi_wlan_get failed with status: %02x", status); + ChipLogError(DeviceLayer, "wfx_rsi_init: rsi_wlan_get(RSI_MAC_ADDRESS) failed: %ld", status); return status; } - SILABS_LOG("wfx_rsi_init: WLAN: MAC %02x:%02x:%02x %02x:%02x:%02x", wfx_rsi.sta_mac.octet[0], wfx_rsi.sta_mac.octet[1], - wfx_rsi.sta_mac.octet[2], wfx_rsi.sta_mac.octet[3], wfx_rsi.sta_mac.octet[4], wfx_rsi.sta_mac.octet[5]); + ChipLogDetail(DeviceLayer, "wfx_rsi_init: MAC: %02x:%02x:%02x %02x:%02x:%02x", wfx_rsi.sta_mac.octet[0], + wfx_rsi.sta_mac.octet[1], wfx_rsi.sta_mac.octet[2], wfx_rsi.sta_mac.octet[3], wfx_rsi.sta_mac.octet[4], + wfx_rsi.sta_mac.octet[5]); // Create the message queue sWifiEventQueue = osMessageQueueNew(WFX_QUEUE_SIZE, sizeof(WfxEvent_t), NULL); @@ -453,12 +443,12 @@ static int32_t wfx_rsi_init(void) */ if ((status = rsi_wlan_register_callbacks(RSI_JOIN_FAIL_CB, wfx_rsi_join_fail_cb)) != RSI_SUCCESS) { - SILABS_LOG("wfx_rsi_init: RSI callback register join failed with status: %02x", status); + ChipLogError(DeviceLayer, "wfx_rsi_init: rsi_wlan_register_callbacks failed: %ld", status); return status; } if ((status = rsi_wlan_register_callbacks(RSI_WLAN_DATA_RECEIVE_NOTIFY_CB, wfx_rsi_wlan_pkt_cb)) != RSI_SUCCESS) { - SILABS_LOG("wfx_rsi_init: RSI callback register data-notify failed with status: %02x", status); + ChipLogError(DeviceLayer, "wfx_rsi_init: rsi_wlan_register_callbacks failed: %ld", status); return status; } @@ -467,26 +457,26 @@ static int32_t wfx_rsi_init(void) #endif wfx_rsi.dev_state |= WFX_RSI_ST_DEV_READY; - SILABS_LOG("wfx_rsi_init: RSI: OK", __func__); + ChipLogProgress(DeviceLayer, "wfx_rsi_init: success"); return RSI_SUCCESS; } /*************************************************************************************** - * @fn static void wfx_rsi_save_ap_info() + * @fn static void wfx_rsi_save_ap_info(void) * @brief * Saving the details of the AP * @param[in] None * @return * None *******************************************************************************************/ -static void wfx_rsi_save_ap_info() // translation +static void wfx_rsi_save_ap_info(void) // translation { int32_t status; rsi_rsp_scan_t rsp; status = rsi_wlan_scan_with_bitmap_options((int8_t *) &wfx_rsi.sec.ssid[0], AP_CHANNEL_NO_0, &rsp, sizeof(rsp), SCAN_BITMAP_OPTN_1); - if (status) + if (status != RSI_SUCCESS) { /* * Scan is done - failed @@ -496,7 +486,7 @@ static void wfx_rsi_save_ap_info() // translation #else /* !WIFI_ENABLE_SECURITY_WPA3_TRANSITION */ wfx_rsi.sec.security = WFX_SEC_WPA2; #endif /* WIFI_ENABLE_SECURITY_WPA3_TRANSITION */ - SILABS_LOG("wfx_rsi_save_ap_info: warn: failed with status: %02x", status); + ChipLogProgress(DeviceLayer, "warn: scan failed: %ld", status); return; } wfx_rsi.sec.security = WFX_SEC_UNSPECIFIED; @@ -532,8 +522,8 @@ static void wfx_rsi_save_ap_info() // translation break; } - SILABS_LOG("wfx_rsi_save_ap_info: WLAN: connecting to %s, sec=%d, status=%02x", &wfx_rsi.sec.ssid[0], wfx_rsi.sec.security, - status); + ChipLogProgress(DeviceLayer, "wfx_rsi_save_ap_info: connecting to %s, sec=%d, status=%ld", &wfx_rsi.sec.ssid[0], + wfx_rsi.sec.security, status); } /******************************************************************************************** @@ -550,58 +540,56 @@ static void wfx_rsi_do_join(void) if (wfx_rsi.dev_state & (WFX_RSI_ST_STA_CONNECTING | WFX_RSI_ST_STA_CONNECTED)) { - SILABS_LOG("wfx_rsi_do_join: not joining - already in progress"); + ChipLogProgress(DeviceLayer, "wfx_rsi_do_join: already in progress"); + return; } - else - { - switch (wfx_rsi.sec.security) - { - case WFX_SEC_WEP: - connect_security_mode = RSI_WEP; - break; - case WFX_SEC_WPA: - case WFX_SEC_WPA2: - connect_security_mode = RSI_WPA_WPA2_MIXED; - break; + switch (wfx_rsi.sec.security) + { + case WFX_SEC_WEP: + connect_security_mode = RSI_WEP; + break; + case WFX_SEC_WPA: + case WFX_SEC_WPA2: + connect_security_mode = RSI_WPA_WPA2_MIXED; + break; #if WIFI_ENABLE_SECURITY_WPA3_TRANSITION - case WFX_SEC_WPA3: - connect_security_mode = RSI_WPA3_PERSONAL_TRANSITION; - break; + case WFX_SEC_WPA3: + connect_security_mode = RSI_WPA3_PERSONAL_TRANSITION; + break; #endif // WIFI_ENABLE_SECURITY_WPA3_TRANSITION - case WFX_SEC_NONE: - connect_security_mode = RSI_OPEN; - break; - default: - SILABS_LOG("wfx_rsi_do_join: error: unknown security type."); - return; - } + case WFX_SEC_NONE: + connect_security_mode = RSI_OPEN; + break; + default: + ChipLogError(DeviceLayer, "wfx_rsi_do_join: error: unknown security type."); + return; + } - SILABS_LOG("wfx_rsi_do_join: WLAN: connecting to %s, sec=%d", &wfx_rsi.sec.ssid[0], wfx_rsi.sec.security); + ChipLogProgress(DeviceLayer, "wfx_rsi_do_join: connecting to %s, sec=%d", &wfx_rsi.sec.ssid[0], wfx_rsi.sec.security); - /* - * Join the network - */ - /* TODO - make the WFX_SECURITY_xxx - same as RSI_xxx - * Right now it's done by hand - we need something better - */ - wfx_rsi.dev_state |= WFX_RSI_ST_STA_CONNECTING; + /* + * Join the network + */ + /* TODO - make the WFX_SECURITY_xxx - same as RSI_xxx + * Right now it's done by hand - we need something better + */ + wfx_rsi.dev_state |= WFX_RSI_ST_STA_CONNECTING; - if ((status = rsi_wlan_register_callbacks(RSI_JOIN_FAIL_CB, wfx_rsi_join_fail_cb)) != RSI_SUCCESS) - { - SILABS_LOG("wfx_rsi_do_join: RSI callback register join failed with status: %02x", status); - } + if ((status = rsi_wlan_register_callbacks(RSI_JOIN_FAIL_CB, wfx_rsi_join_fail_cb)) != RSI_SUCCESS) + { + ChipLogError(DeviceLayer, "wfx_rsi_do_join: rsi_wlan_register_callbacks failed: %ld", status); + } - /* Try to connect Wifi with given Credentials - * untill there is a success or maximum number of tries allowed - */ - if ((status = rsi_wlan_connect_async((int8_t *) &wfx_rsi.sec.ssid[0], connect_security_mode, &wfx_rsi.sec.passkey[0], - wfx_rsi_join_cb)) != RSI_SUCCESS) - { - wfx_rsi.dev_state &= ~WFX_RSI_ST_STA_CONNECTING; - SILABS_LOG("wfx_rsi_do_join: rsi_wlan_connect_async failed with status: %02x on try %d", status, wfx_rsi.join_retries); - wfx_retry_connection(++wfx_rsi.join_retries); - } + /* Try to connect Wifi with given Credentials + * until there is a success or maximum number of tries allowed + */ + if ((status = rsi_wlan_connect_async((int8_t *) &wfx_rsi.sec.ssid[0], connect_security_mode, &wfx_rsi.sec.passkey[0], + wfx_rsi_join_cb)) != RSI_SUCCESS) + { + wfx_rsi.dev_state &= ~WFX_RSI_ST_STA_CONNECTING; + ChipLogProgress(DeviceLayer, "wfx_rsi_do_join: rsi_wlan_connect_async failed: %ld on try %d", status, wfx_rsi.join_retries); + wfx_retry_connection(++wfx_rsi.join_retries); } } @@ -609,7 +597,7 @@ static void wfx_rsi_do_join(void) * @brief Notify the application about the connectivity status if it has not been notified yet. * Helper function for HandleDHCPPolling. */ -void NotifyConnectivity() +void NotifyConnectivity(void) { if (!hasNotifiedWifiConnectivity) { @@ -618,7 +606,7 @@ void NotifyConnectivity() } } -void HandleDHCPPolling() +void HandleDHCPPolling(void) { struct netif * sta_netif; WfxEvent_t event; @@ -628,7 +616,7 @@ void HandleDHCPPolling() { // TODO: Notify the application that the interface is not set up or Chipdie here because we // are in an unkonwn state - SILABS_LOG("HandleDHCPPolling: failed to get STA netif"); + ChipLogError(DeviceLayer, "HandleDHCPPolling: failed to get STA netif"); return; } #if (CHIP_DEVICE_CONFIG_ENABLE_IPV4) @@ -662,7 +650,7 @@ void HandleDHCPPolling() * @brief Reset the flags that are used to notify the application about DHCP connectivity * and emits a WFX_EVT_STA_DO_DHCP event to trigger DHCP polling checks. Helper function for ProcessEvent. */ -void ResetDHCPNotificationFlags() +void ResetDHCPNotificationFlags(void) { WfxEvent_t outEvent; @@ -685,19 +673,27 @@ void WfxPostEvent(WfxEvent_t * event) if (status != osOK) { - SILABS_LOG("WfxPostEvent: failed to post event with status: %d", status); + ChipLogError(DeviceLayer, "WfxPostEvent: failed to post event with status: %ld", status); // TODO: Handle error, requeue event depending on queue size or notify relevant task, // Chipdie, etc. } } +/** + * @brief Process the Wi-Fi event. + * + * This function is responsible for processing different types of Wi-Fi events and taking appropriate actions based on the event + * type. + * + * @param inEvent The input Wi-Fi event to be processed. + */ void ProcessEvent(WfxEvent_t inEvent) { // Process event switch (inEvent.eventType) { case WFX_EVT_STA_CONN: { - SILABS_LOG("Starting LwIP STA"); + ChipLogDetail(DeviceLayer, "_onWFXEvent: WFX_EVT_STA_CONN"); wfx_rsi.dev_state |= WFX_RSI_ST_STA_CONNECTED; ResetDHCPNotificationFlags(); wfx_lwip_set_sta_link_up(); @@ -709,10 +705,10 @@ void ProcessEvent(WfxEvent_t inEvent) } break; case WFX_EVT_STA_DISCONN: { + ChipLogDetail(DeviceLayer, "_onWFXEvent: WFX_EVT_STA_DISCONN"); // TODO: This event is not being posted anywhere, seems to be a dead code or we are missing something wfx_rsi.dev_state &= ~(WFX_RSI_ST_STA_READY | WFX_RSI_ST_STA_CONNECTING | WFX_RSI_ST_STA_CONNECTED | WFX_RSI_ST_STA_DHCP_DONE); - SILABS_LOG("Disconnect notify"); /* TODO: Implement disconnect notify */ ResetDHCPNotificationFlags(); wfx_lwip_set_sta_link_down(); // Internally dhcpclient_poll(netif) -> @@ -732,48 +728,64 @@ void ProcessEvent(WfxEvent_t inEvent) case WFX_EVT_SCAN: { #ifdef SL_WFX_CONFIG_SCAN rsi_rsp_scan_t scan_rsp = { 0 }; - int32_t status = rsi_wlan_bgscan_profile(1, &scan_rsp, sizeof(scan_rsp)); + memset(&scan_rsp, 0, sizeof(scan_rsp)); + int32_t status = rsi_wlan_bgscan_profile(1, &scan_rsp, sizeof(scan_rsp)); - if (status) + if (status != RSI_SUCCESS) { - SILABS_LOG("SSID scan failed: %02x ", status); + ChipLogError(DeviceLayer, "rsi_wlan_bgscan failed: %ld ", status); + return; } - else + + if (wfx_rsi.scan_cb == NULL) + { + ChipLogError(DeviceLayer, "wfx_rsi.scan_cb is NULL"); + return; + } + + rsi_scan_info_t * scan; + wfx_wifi_scan_result_t ap; + + for (int x = 0; x < scan_rsp.scan_count[0]; x++) { - rsi_scan_info_t * scan; - wfx_wifi_scan_result_t ap; - for (int x = 0; x < scan_rsp.scan_count[0]; x++) + scan = &scan_rsp.scan_info[x]; + // clear structure and calculate size of SSID + memset(&ap, 0, sizeof(ap)); + ap.ssid_length = + strnlen(reinterpret_cast(scan->ssid), chip::min(sizeof(scan->ssid), WFX_MAX_SSID_LENGTH)); + chip::Platform::CopyString(ap.ssid, ap.ssid_length, reinterpret_cast(scan->ssid)); + + // check if the scanned ssid is the one we are looking for + if (wfx_rsi.scan_ssid_length != 0 && strncmp(wfx_rsi.scan_ssid, ap.ssid, WFX_MAX_SSID_LENGTH) != CMP_SUCCESS) { - scan = &scan_rsp.scan_info[x]; - // is it a scan all or target scan - if (wfx_rsi.scan_ssid != NULL && - (strncmp(wfx_rsi.scan_ssid, (char *) scan->ssid, MIN(strlen(wfx_rsi.scan_ssid), sizeof(scan->ssid))) == - CMP_SUCCESS)) - { - strncpy(ap.ssid, (char *) scan->ssid, MIN(sizeof(ap.ssid), sizeof(scan->ssid))); - ap.security = static_cast(scan->security_mode); - ap.rssi = (-1) * scan->rssi_val; - configASSERT(sizeof(ap.bssid) >= BSSID_LEN); - configASSERT(sizeof(scan->bssid) >= BSSID_LEN); - memcpy(ap.bssid, scan->bssid, BSSID_LEN); - (*wfx_rsi.scan_cb)(&ap); - - if (wfx_rsi.scan_ssid) - { - break; // we found the targeted ssid. - } - } + continue; // we found the targeted ssid. } + // TODO: convert security mode from RSI to WFX + ap.security = static_cast(scan->security_mode); + ap.rssi = (-1) * scan->rssi_val; + + configASSERT(sizeof(ap.bssid) == BSSID_LEN); + configASSERT(sizeof(scan->bssid) == BSSID_LEN); + memcpy(ap.bssid, scan->bssid, BSSID_LEN); + (*wfx_rsi.scan_cb)(&ap); + + // no ssid filter set, return all results + if (wfx_rsi.scan_ssid_length == 0) + { + continue; + } + + break; } /* Terminate with end of scan which is no ap sent back */ - (*wfx_rsi.scan_cb)((wfx_wifi_scan_result_t *) 0); - wfx_rsi.scan_cb = (void (*)(wfx_wifi_scan_result_t *)) 0; + (*wfx_rsi.scan_cb)((wfx_wifi_scan_result_t *) NULL); + wfx_rsi.scan_cb = nullptr; if (wfx_rsi.scan_ssid) { - vPortFree(wfx_rsi.scan_ssid); - wfx_rsi.scan_ssid = (char *) 0; + chip::Platform::MemoryFree(wfx_rsi.scan_ssid); + wfx_rsi.scan_ssid = NULL; } #endif /* SL_WFX_CONFIG_SCAN */ } @@ -819,14 +831,14 @@ void wfx_rsi_task(void * arg) uint32_t rsi_status = wfx_rsi_init(); if (rsi_status != RSI_SUCCESS) { - SILABS_LOG("wfx_rsi_task: error: wfx_rsi_init with status: %02x", rsi_status); + ChipLogError(DeviceLayer, "wfx_rsi_task: wfx_rsi_init failed: %ld", rsi_status); return; } WfxEvent_t wfxEvent; wfx_lwip_start(); wfx_started_notify(); - SILABS_LOG("Starting event loop"); + ChipLogProgress(DeviceLayer, "wfx_rsi_task: starting event loop"); for (;;) { osStatus_t status = osMessageQueueGet(sWifiEventQueue, &wfxEvent, NULL, osWaitForever); @@ -836,7 +848,7 @@ void wfx_rsi_task(void * arg) } else { - SILABS_LOG("Failed to get event with status: %x", status); + ChipLogProgress(DeviceLayer, "wfx_rsi_task: get event failed: %x", status); } } } @@ -859,8 +871,8 @@ void wfx_dhcp_got_ipv4(uint32_t ip) wfx_rsi.ip4_addr[1] = (ip >> 8) & HEX_VALUE_FF; wfx_rsi.ip4_addr[2] = (ip >> 16) & HEX_VALUE_FF; wfx_rsi.ip4_addr[3] = (ip >> 24) & HEX_VALUE_FF; - SILABS_LOG("wfx_dhcp_got_ipv4: DHCP OK: IP=%d.%d.%d.%d", wfx_rsi.ip4_addr[0], wfx_rsi.ip4_addr[1], wfx_rsi.ip4_addr[2], - wfx_rsi.ip4_addr[3]); + ChipLogProgress(DeviceLayer, "DHCP OK: IP=%d.%d.%d.%d", wfx_rsi.ip4_addr[0], wfx_rsi.ip4_addr[1], wfx_rsi.ip4_addr[2], + wfx_rsi.ip4_addr[3]); /* Notify the Connectivity Manager - via the app */ wfx_rsi.dev_state |= WFX_RSI_ST_STA_DHCP_DONE; wfx_ip_changed_notify(IP_STATUS_SUCCESS); @@ -875,14 +887,14 @@ void wfx_dhcp_got_ipv4(uint32_t ip) * see also: int32_t rsi_wlan_send_data_xx(uint8_t *buffer, uint32_t length) */ /******************************************************************************************** - * @fn void *wfx_rsi_alloc_pkt() + * @fn void *wfx_rsi_alloc_pkt(void) * @brief * Allocate packet to send data * @param[in] None * @return * None **********************************************************************************************/ -void * wfx_rsi_alloc_pkt() +void * wfx_rsi_alloc_pkt(void) { rsi_pkt_t * pkt; diff --git a/examples/platform/silabs/efr32/wf200/host_if.cpp b/examples/platform/silabs/efr32/wf200/host_if.cpp index 8247e385f61bcf..044ecc6e978cbd 100644 --- a/examples/platform/silabs/efr32/wf200/host_if.cpp +++ b/examples/platform/silabs/efr32/wf200/host_if.cpp @@ -42,6 +42,9 @@ #include "dhcp_client.h" #include "ethernetif.h" +#include +#include +#include #include using namespace ::chip; @@ -91,7 +94,7 @@ struct netif * sta_netif; wfx_wifi_provision_t wifi_provision; sl_wfx_get_counters_cnf_t * counters; sl_wfx_get_counters_cnf_t * Tempcounters; -#define PUT_COUNTER(name) SILABS_LOG("%-24s %lu\r\n", #name, (unsigned long) counters->body.count_##name); +#define PUT_COUNTER(name) ChipLogDetail(DeviceLayer, "%-24s %lu", #name, (unsigned long) counters->body.count_##name); bool hasNotifiedIPV6 = false; bool hasNotifiedIPV4 = false; @@ -108,6 +111,7 @@ static struct scan_result_holder static uint8_t scan_count = 0; static void (*scan_cb)(wfx_wifi_scan_result_t *); /* user-callback - when scan is done */ static char * scan_ssid; /* Which one are we scanning for */ +size_t scan_ssid_length = 0; static void sl_wfx_scan_result_callback(sl_wfx_scan_result_ind_body_t * scan_result); static void sl_wfx_scan_complete_callback(uint32_t status); #endif /* SL_WFX_CONFIG_SCAN */ @@ -133,7 +137,7 @@ extern uint32_t gOverrunCount; * @brief * Creates WFX events processing task. ******************************************************************************/ -static void wfx_events_task_start() +static void wfx_events_task_start(void) { /* create an event group to track Wi-Fi events */ sl_wfx_event_group = xEventGroupCreateStatic(&wfxEventGroup); @@ -142,7 +146,7 @@ static void wfx_events_task_start() wfxEventTaskStack, &wfxEventTaskBuffer); if (NULL == wfx_events_task_handle) { - SILABS_LOG("Failed to create WFX wfx_events"); + ChipLogError(DeviceLayer, "Failed to create WFX wfx_events"); } } @@ -159,7 +163,7 @@ sl_status_t sl_wfx_host_process_event(sl_wfx_generic_message_t * event_payload) { /******** INDICATION ********/ case SL_WFX_STARTUP_IND_ID: { - SILABS_LOG("WFX Startup Completed\r\n"); + ChipLogProgress(DeviceLayer, "startup completed."); PlatformMgrImpl().HandleWFXSystemEvent(WIFI_EVENT, event_payload); break; } @@ -237,34 +241,21 @@ sl_status_t sl_wfx_host_process_event(sl_wfx_generic_message_t * event_payload) } case SL_WFX_EXCEPTION_IND_ID: { sl_wfx_exception_ind_t * firmware_exception = (sl_wfx_exception_ind_t *) event_payload; - uint8_t * exception_tmp = (uint8_t *) firmware_exception; - SILABS_LOG("firmware exception\r\n"); - for (uint16_t i = 0; i < firmware_exception->header.length; i += 16) - { - SILABS_LOG("hif: %.8x:", i); - for (uint8_t j = 0; (j < 16) && ((i + j) < firmware_exception->header.length); j++) - { - SILABS_LOG(" %.2x", *exception_tmp); - exception_tmp++; - } - SILABS_LOG("\r\n"); - } + ChipLogError(DeviceLayer, "event: SL_WFX_EXCEPTION_IND_ID"); + ChipLogError(DeviceLayer, "firmware_exception->header.length: %d", firmware_exception->header.length); + // create a bytespan header.length with exception payload + ByteSpan exception_byte_span = ByteSpan((uint8_t *) firmware_exception, firmware_exception->header.length); + ChipLogByteSpan(DeviceLayer, exception_byte_span); break; } case SL_WFX_ERROR_IND_ID: { sl_wfx_error_ind_t * firmware_error = (sl_wfx_error_ind_t *) event_payload; - uint8_t * error_tmp = (uint8_t *) firmware_error; - SILABS_LOG("firmware error %lu\r\n", firmware_error->body.type); - for (uint16_t i = 0; i < firmware_error->header.length; i += 16) - { - SILABS_LOG("hif: %.8x:", i); - for (uint8_t j = 0; (j < 16) && ((i + j) < firmware_error->header.length); j++) - { - SILABS_LOG(" %.2x", *error_tmp); - error_tmp++; - } - SILABS_LOG("\r\n"); - } + ChipLogError(DeviceLayer, "event: SL_WFX_ERROR_IND_ID"); + ChipLogError(DeviceLayer, "firmware_error->type: %lu", firmware_error->body.type); + ChipLogError(DeviceLayer, "firmware_error->header.length: %d", firmware_error->header.length); + // create a bytespan header.length with error payload + ByteSpan error_byte_span = ByteSpan((uint8_t *) firmware_error, firmware_error->header.length); + ChipLogByteSpan(DeviceLayer, error_byte_span); break; } } @@ -282,28 +273,26 @@ static void sl_wfx_scan_result_callback(sl_wfx_scan_result_ind_body_t * scan_res { struct scan_result_holder * ap; - SILABS_LOG("# %2d %2d %03d %02X:%02X:%02X:%02X:%02X:%02X %s", scan_count, scan_result->channel, - ((int16_t) (scan_result->rcpi - 220) / 2), scan_result->mac[0], scan_result->mac[1], scan_result->mac[2], - scan_result->mac[3], scan_result->mac[4], scan_result->mac[5], scan_result->ssid_def.ssid); - /*Report one AP information*/ - SILABS_LOG("\r\n"); + ChipLogDetail(DeviceLayer, "# %2d %2d %03d %02X:%02X:%02X:%02X:%02X:%02X %s", scan_count, scan_result->channel, + ((int16_t) (scan_result->rcpi - 220) / 2), scan_result->mac[0], scan_result->mac[1], scan_result->mac[2], + scan_result->mac[3], scan_result->mac[4], scan_result->mac[5], scan_result->ssid_def.ssid); + /* Report one AP information */ /* don't save if filter only wants specific ssid */ - if (scan_ssid != (char *) 0) + if (scan_ssid != nullptr) { if (strcmp(scan_ssid, (char *) &scan_result->ssid_def.ssid[0]) != CMP_SUCCESS) return; } - if ((ap = (struct scan_result_holder *) pvPortMalloc(sizeof(*ap))) == (struct scan_result_holder *) 0) + if ((ap = (struct scan_result_holder *) (chip::Platform::MemoryAlloc(sizeof(*ap)))) == (struct scan_result_holder *) 0) { - SILABS_LOG("*ERR*Scan: No Mem"); + ChipLogError(DeviceLayer, "Scan: No Mem"); } else { ap->next = scan_save; scan_save = ap; /* Not checking if scan_result->ssid_length is < 33 */ - memcpy(ap->scan.ssid, scan_result->ssid_def.ssid, scan_result->ssid_def.ssid_length); - ap->scan.ssid[scan_result->ssid_def.ssid_length] = 0; /* make sure about null terminate */ + chip::Platform::CopyString(ap->scan.ssid, sizeof(ap->scan.ssid), (char *) &scan_result->ssid_def.ssid[0]); /* We do it in this order WPA3 first */ /* No EAP supported - Is this required */ ap->scan.security = WFX_SEC_UNSPECIFIED; @@ -363,7 +352,7 @@ static void sl_wfx_connect_callback(sl_wfx_connect_ind_body_t connect_indication switch (status) { case WFM_STATUS_SUCCESS: { - SILABS_LOG("STA-Connected\r\n"); + ChipLogProgress(DeviceLayer, "STA-Connected"); memcpy(&ap_mac.octet[0], mac, MAC_ADDRESS_FIRST_OCTET); sl_wfx_context->state = static_cast(static_cast(sl_wfx_context->state) | static_cast(SL_WFX_STA_INTERFACE_CONNECTED)); @@ -371,27 +360,27 @@ static void sl_wfx_connect_callback(sl_wfx_connect_ind_body_t connect_indication break; } case WFM_STATUS_NO_MATCHING_AP: { - SILABS_LOG("WFX Connection failed, access point not found\r\n"); + ChipLogError(DeviceLayer, "Connection failed, access point not found"); break; } case WFM_STATUS_CONNECTION_ABORTED: { - SILABS_LOG("WFX Connection aborted\r\n"); + ChipLogError(DeviceLayer, "Connection aborted"); break; } case WFM_STATUS_CONNECTION_TIMEOUT: { - SILABS_LOG("WFX Connection timeout\r\n"); + ChipLogError(DeviceLayer, "Connection timeout"); break; } case WFM_STATUS_CONNECTION_REJECTED_BY_AP: { - SILABS_LOG("WFX Connection rejected by the access point\r\n"); + ChipLogError(DeviceLayer, "Connection rejected by the access point"); break; } case WFM_STATUS_CONNECTION_AUTH_FAILURE: { - SILABS_LOG("WFX Connection authentication failure\r\n"); + ChipLogError(DeviceLayer, "Connection authentication failure"); break; } default: { - SILABS_LOG("WF Connection attempt error\r\n"); + ChipLogError(DeviceLayer, "Connection attempt error"); } } @@ -399,7 +388,7 @@ static void sl_wfx_connect_callback(sl_wfx_connect_ind_body_t connect_indication { retryJoin += 1; retryInProgress = false; - SILABS_LOG("WFX Retry to connect to network count: %d", retryJoin); + ChipLogProgress(DeviceLayer, "Retry to connect to network count: %d", retryJoin); sl_wfx_context->state = static_cast(static_cast(sl_wfx_context->state) & ~static_cast(SL_WFX_STARTED)); wfx_retry_connection(retryJoin); @@ -415,7 +404,7 @@ static void sl_wfx_connect_callback(sl_wfx_connect_ind_body_t connect_indication static void sl_wfx_disconnect_callback(uint8_t * mac, uint16_t reason) { (void) (mac); - SILABS_LOG("WFX Disconnected %d\r\n", reason); + ChipLogProgress(DeviceLayer, "Disconnected %d", reason); sl_wfx_context->state = static_cast(static_cast(sl_wfx_context->state) & ~static_cast(SL_WFX_STA_INTERFACE_CONNECTED)); retryInProgress = false; @@ -430,18 +419,10 @@ static void sl_wfx_disconnect_callback(uint8_t * mac, uint16_t reason) *****************************************************************************/ static void sl_wfx_start_ap_callback(uint32_t status) { - if (status == AP_START_SUCCESS) - { - SILABS_LOG("AP started\r\n"); - sl_wfx_context->state = - static_cast(static_cast(sl_wfx_context->state) | static_cast(SL_WFX_AP_INTERFACE_UP)); - xEventGroupSetBits(sl_wfx_event_group, SL_WFX_START_AP); - } - else - { - SILABS_LOG("AP start failed\r\n"); - strcpy(event_log, "AP start failed"); - } + VerifyOrReturnLogError(status == AP_START_SUCCESS, CHIP_ERROR_INTERNAL); + sl_wfx_context->state = + static_cast(static_cast(sl_wfx_context->state) | static_cast(SL_WFX_AP_INTERFACE_UP)); + xEventGroupSetBits(sl_wfx_event_group, SL_WFX_START_AP); } /**************************************************************************** @@ -452,7 +433,7 @@ static void sl_wfx_stop_ap_callback(void) { // TODO // dhcpserver_clear_stored_mac(); - SILABS_LOG("SoftAP stopped\r\n"); + ChipLogProgress(DeviceLayer, "SoftAP stopped"); sl_wfx_context->state = static_cast(static_cast(sl_wfx_context->state) & ~static_cast(SL_WFX_AP_INTERFACE_UP)); xEventGroupSetBits(sl_wfx_event_group, SL_WFX_STOP_AP); @@ -465,9 +446,8 @@ static void sl_wfx_stop_ap_callback(void) *****************************************************************************/ static void sl_wfx_client_connected_callback(uint8_t * mac) { - SILABS_LOG("Client connected, MAC: %02X:%02X:%02X:%02X:%02X:%02X\r\n", mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]); - // TODO - SILABS_LOG("Open a web browser and go to http://%d.%d.%d.%d\r\n", ap_ip_addr0, ap_ip_addr1, ap_ip_addr2, ap_ip_addr3); + ChipLogProgress(DeviceLayer, "Client connected, MAC: %02X:%02X:%02X:%02X:%02X:%02X", mac[0], mac[1], mac[2], mac[3], mac[4], + mac[5]); } /**************************************************************************** @@ -478,8 +458,8 @@ static void sl_wfx_client_connected_callback(uint8_t * mac) *****************************************************************************/ static void sl_wfx_ap_client_rejected_callback(uint32_t status, uint8_t * mac) { - SILABS_LOG("Client rejected, reason: %d, MAC: %02X:%02X:%02X:%02X:%02X:%02X\r\n", (int) status, mac[0], mac[1], mac[2], mac[3], - mac[4], mac[5]); + ChipLogError(DeviceLayer, "Client rejected, reason: %d, MAC: %02X:%02X:%02X:%02X:%02X:%02X", (int) status, mac[0], mac[1], + mac[2], mac[3], mac[4], mac[5]); } /**************************************************************************** @@ -490,9 +470,8 @@ static void sl_wfx_ap_client_rejected_callback(uint32_t status, uint8_t * mac) *****************************************************************************/ static void sl_wfx_ap_client_disconnected_callback(uint32_t status, uint8_t * mac) { - // TODO - SILABS_LOG("Client disconnected, reason: %d, MAC: %02X:%02X:%02X:%02X:%02X:%02X\r\n", (int) status, mac[0], mac[1], mac[2], - mac[3], mac[4], mac[5]); + ChipLogError(DeviceLayer, "Client disconnected, reason: %d, MAC: %02X:%02X:%02X:%02X:%02X:%02X", (int) status, mac[0], mac[1], + mac[2], mac[3], mac[4], mac[5]); } #endif /* SL_WFX_CONFIG_SOFTAP */ @@ -504,7 +483,6 @@ static void sl_wfx_ap_client_disconnected_callback(uint32_t status, uint8_t * ma static void sl_wfx_generic_status_callback(sl_wfx_generic_ind_t * frame) { (void) (frame); - SILABS_LOG("WFX Generic status received\r\n"); } /*************************************************************************** @@ -534,7 +512,7 @@ static void wfx_events_task(void * p_arg) pdTRUE, pdFALSE, pdMS_TO_TICKS(250)); /* 250 msec delay converted to ticks */ if (flags & SL_WFX_RETRY_CONNECT) { - SILABS_LOG("WFX sending the connect command"); + ChipLogProgress(DeviceLayer, "sending the connect command"); wfx_connect_to_ap(); } @@ -551,7 +529,7 @@ static void wfx_events_task(void * p_arg) hasNotifiedIPV4 = true; if (!hasNotifiedWifiConnectivity) { - SILABS_LOG("WIFI: Has Notified Wifi Connectivity"); + ChipLogProgress(DeviceLayer, "will notify WiFi connectivity"); wfx_connected_notify(CONNECTION_STATUS_SUCCESS, &ap_mac); hasNotifiedWifiConnectivity = true; } @@ -585,7 +563,7 @@ static void wfx_events_task(void * p_arg) wfx_ipv6_notify(GET_IPV6_FAIL); hasNotifiedIPV6 = false; hasNotifiedWifiConnectivity = false; - SILABS_LOG("WIFI: Connected to AP"); + ChipLogProgress(DeviceLayer, "connected to AP"); wifi_extra |= WE_ST_STA_CONN; retryJoin = 0; wfx_lwip_set_sta_link_up(); @@ -593,7 +571,7 @@ static void wfx_events_task(void * p_arg) if (!(wfx_get_wifi_state() & SL_WFX_AP_INTERFACE_UP)) { // Enable the power save - SILABS_LOG("WF200 going to DTIM based sleep"); + ChipLogProgress(DeviceLayer, "WF200 going to DTIM based sleep"); sl_wfx_set_power_mode(WFM_PM_MODE_DTIM, WFM_PM_POLL_FAST_PS, BEACON_1, 0 /*timeout*/); sl_wfx_enable_device_power_save(); } @@ -637,9 +615,10 @@ static void wfx_events_task(void * p_arg) sp = (sl_wfx_ssid_def_t *) 0; } - SILABS_LOG("WIFI Scan Paramter set to Active channel time %d, Passive " - "Channel Time: %d, Number of prob: %d", - ACTIVE_CHANNEL_TIME, PASSIVE_CHANNEL_TIME, NUM_PROBE_REQUEST); + ChipLogDetail(DeviceLayer, + "WIFI Scan Paramter set to Active channel time %d, Passive " + "Channel Time: %d, Number of prob: %d", + ACTIVE_CHANNEL_TIME, PASSIVE_CHANNEL_TIME, NUM_PROBE_REQUEST); (void) sl_wfx_set_scan_parameters(ACTIVE_CHANNEL_TIME, PASSIVE_CHANNEL_TIME, NUM_PROBE_REQUEST); (void) sl_wfx_send_scan_command(WFM_SCAN_MODE_ACTIVE, CHANNEL_LIST, /* Channel list */ CHANNEL_COUNT, /* Scan all chans */ @@ -650,20 +629,20 @@ static void wfx_events_task(void * p_arg) { struct scan_result_holder *hp, *next; - SILABS_LOG("WIFI: Return %d scan results", scan_count); + ChipLogDetail(DeviceLayer, "WIFI: Return %d scan results", scan_count); for (hp = scan_save; hp; hp = next) { next = hp->next; (*scan_cb)(&hp->scan); - vPortFree(hp); + chip::Platform::MemoryFree(hp); } (*scan_cb)((wfx_wifi_scan_result *) 0); scan_save = (struct scan_result_holder *) 0; scan_count = 0; if (scan_ssid) { - vPortFree(scan_ssid); - scan_ssid = (char *) 0; + chip::Platform::MemoryFree(scan_ssid); + scan_ssid = NULL; } /* Terminate scan */ scan_cb = 0; @@ -681,15 +660,15 @@ static sl_status_t wfx_init(void) /* Initialize the WF200 used by the two interfaces */ wfx_events_task_start(); sl_status_t status = sl_wfx_init(&wifiContext); - SILABS_LOG("FMAC Driver version %s", FMAC_DRIVER_VERSION_STRING); + ChipLogProgress(DeviceLayer, "FMAC Driver version: %s", FMAC_DRIVER_VERSION_STRING); switch (status) { case SL_STATUS_OK: - SILABS_LOG("WF200 FW ver:%d.%d.%d [MAC %02x:%02x:%02x-%02x:%02x:%02x]", wifiContext.firmware_major, - wifiContext.firmware_minor, wifiContext.firmware_build, wifiContext.mac_addr_0.octet[0], - wifiContext.mac_addr_0.octet[1], wifiContext.mac_addr_0.octet[2], wifiContext.mac_addr_0.octet[3], - wifiContext.mac_addr_0.octet[4], wifiContext.mac_addr_0.octet[5]); - SILABS_LOG("WF200 Init OK"); + ChipLogProgress(DeviceLayer, "WF200 FW ver:%d.%d.%d [MAC %02x:%02x:%02x-%02x:%02x:%02x]", wifiContext.firmware_major, + wifiContext.firmware_minor, wifiContext.firmware_build, wifiContext.mac_addr_0.octet[0], + wifiContext.mac_addr_0.octet[1], wifiContext.mac_addr_0.octet[2], wifiContext.mac_addr_0.octet[3], + wifiContext.mac_addr_0.octet[4], wifiContext.mac_addr_0.octet[5]); + ChipLogProgress(DeviceLayer, "WF200 Init OK"); if (wifiContext.state == SL_WFX_STA_INTERFACE_CONNECTED) { @@ -698,19 +677,19 @@ static sl_status_t wfx_init(void) break; case SL_STATUS_WIFI_INVALID_KEY: - SILABS_LOG("*ERR*WF200: F/W keyset invalid"); + ChipLogError(DeviceLayer, "WF200: F/W keyset invalid"); break; case SL_STATUS_WIFI_FIRMWARE_DOWNLOAD_TIMEOUT: - SILABS_LOG("*ERR*WF200: F/W download timo"); + ChipLogError(DeviceLayer, "WF200: F/W download timo"); break; case SL_STATUS_TIMEOUT: - SILABS_LOG("*ERR*WF200: Poll for value timo"); + ChipLogError(DeviceLayer, "WF200: Poll for value timo"); break; case SL_STATUS_FAIL: - SILABS_LOG("*ERR*WF200: Error"); + ChipLogError(DeviceLayer, "WF200: Error"); break; default: - SILABS_LOG("*ERR*WF200: Unknown"); + ChipLogError(DeviceLayer, "WF200: Unknown"); } return status; @@ -728,22 +707,22 @@ static void wfx_wifi_hw_start(void) if (wifi_extra & WE_ST_HW_STARTED) return; - SILABS_LOG("STARTING WF200\n"); + ChipLogDetail(DeviceLayer, "STARTING WF200"); wifi_extra |= WE_ST_HW_STARTED; sl_wfx_host_gpio_init(); if ((status = wfx_init()) == SL_STATUS_OK) { /* Initialize the LwIP stack */ - SILABS_LOG("WF200:Start LWIP"); + ChipLogDetail(DeviceLayer, "WF200:Start LWIP"); wfx_lwip_start(); wfx_started_notify(); wifiContext.state = SL_WFX_STARTED; /* Really this is a bit mask */ - SILABS_LOG("WF200:ready.."); + ChipLogDetail(DeviceLayer, "WF200:ready.."); } else { - SILABS_LOG("*ERR*WF200:init failed"); + ChipLogError(DeviceLayer, "WF200:init failed"); } } @@ -756,23 +735,22 @@ static void wfx_wifi_hw_start(void) int32_t wfx_get_ap_info(wfx_wifi_scan_result_t * ap) { int32_t signal_strength; - SILABS_LOG("WIFI:SSID:: %s", &ap_info.ssid[0]); - memcpy(ap->ssid, ap_info.ssid, sizeof(ap_info.ssid)); - SILABS_LOG("WIFI:Mac addr:: %02x:%02x:%02x:%02x:%02x:%02x", ap_info.bssid[0], ap_info.bssid[1], ap_info.bssid[2], - ap_info.bssid[3], ap_info.bssid[4], ap_info.bssid[5]); + + ap->ssid_length = strnlen(ap_info.ssid, chip::min(sizeof(ap_info.ssid), WFX_MAX_SSID_LENGTH)); + chip::Platform::CopyString(ap->ssid, ap->ssid_length, ap_info.ssid); memcpy(ap->bssid, ap_info.bssid, sizeof(ap_info.bssid)); ap->security = ap_info.security; - SILABS_LOG("WIFI:security:: %d", ap->security); - ap->chan = ap_info.chan; - SILABS_LOG("WIFI:Channel:: to %d", ap->chan); + ap->chan = ap_info.chan; + ChipLogDetail(DeviceLayer, "WIFI:SSID :: %s", &ap_info.ssid[0]); + ChipLogDetail(DeviceLayer, "WIFI:BSSID :: %02x:%02x:%02x:%02x:%02x:%02x", ap_info.bssid[0], ap_info.bssid[1], + ap_info.bssid[2], ap_info.bssid[3], ap_info.bssid[4], ap_info.bssid[5]); + ChipLogDetail(DeviceLayer, "WIFI:security :: %d", ap->security); + ChipLogDetail(DeviceLayer, "WIFI:channel :: %d", ap->chan); sl_status_t status = sl_wfx_get_signal_strength((uint32_t *) &signal_strength); - - if (status == SL_STATUS_OK) - { - SILABS_LOG("status SL_STATUS_OK & signal_strength:: %d", signal_strength); - ap->rssi = (signal_strength - 220) / 2; - } + VerifyOrReturnError(status == SL_STATUS_OK, status); + ChipLogDetail(DeviceLayer, "signal_strength: %ld", signal_strength); + ap->rssi = (signal_strength - 220) / 2; return status; } @@ -788,7 +766,7 @@ int32_t wfx_get_ap_ext(wfx_wifi_scan_ext_t * extra_info) status = get_all_counters(); if (status != SL_STATUS_OK) { - SILABS_LOG("Failed to get the couters"); + ChipLogError(DeviceLayer, "Failed to get the couters"); } else { @@ -808,15 +786,13 @@ sl_status_t get_all_counters(void) sl_status_t result; uint8_t command_id = 0x05; uint16_t mib_id = 0x2035; - sl_wfx_mib_req_t * request = NULL; + sl_wfx_mib_req_t * request = nullptr; uint32_t request_length = SL_WFX_ROUND_UP_EVEN(sizeof(sl_wfx_header_mib_t) + sizeof(sl_wfx_mib_req_body_t)); result = sl_wfx_allocate_command_buffer((sl_wfx_generic_message_t **) &request, command_id, SL_WFX_CONTROL_BUFFER, request_length); - if (request == NULL) - { - } + VerifyOrReturnError(request != nullptr, SL_STATUS_NULL_POINTER); request->body.mib_id = mib_id; request->header.interface = 0x2; @@ -828,8 +804,8 @@ sl_status_t get_all_counters(void) result = sl_wfx_host_wait_for_confirmation(command_id, SL_WFX_DEFAULT_REQUEST_TIMEOUT_MS, (void **) &counters); SL_WFX_ERROR_CHECK(result); - SILABS_LOG("%-24s %12s \r\n", "", "Debug Counters Content"); - SILABS_LOG("%-24s %lu\r\n", "rcpi", (unsigned long) counters->body.rcpi); + ChipLogDetail(DeviceLayer, "%-24s %12s ", "", "Debug Counters Content"); + ChipLogDetail(DeviceLayer, "%-24s %lu", "rcpi", (unsigned long) counters->body.rcpi); PUT_COUNTER(plcp_errors); PUT_COUNTER(fcs_errors); PUT_COUNTER(tx_packets); @@ -865,7 +841,7 @@ sl_status_t get_all_counters(void) sl_wfx_context->used_buffers--; } } - if (request != NULL) + if (request != nullptr) { sl_wfx_free_command_buffer((sl_wfx_generic_message_t *) request, command_id, SL_WFX_CONTROL_BUFFER); } @@ -878,7 +854,7 @@ sl_status_t get_all_counters(void) * reset the count * @return returns -1 **************************************************************************/ -int32_t wfx_reset_counts() +int32_t wfx_reset_counts(void) { /* TODO */ return -1; @@ -893,7 +869,7 @@ sl_status_t wfx_wifi_start(void) { if (wifi_extra & WE_ST_STARTED) { - SILABS_LOG("WIFI: Already started"); + ChipLogDetail(DeviceLayer, "WIFI: Already started"); return SL_STATUS_OK; } wifi_extra |= WE_ST_STARTED; @@ -921,7 +897,7 @@ sl_wfx_state_t wfx_get_wifi_state(void) *****************************************************************************/ struct netif * wfx_GetNetif(sl_wfx_interface_t interface) { - struct netif * SelectedNetif = NULL; + struct netif * SelectedNetif = nullptr; if (interface == SL_WFX_STA_INTERFACE) { SelectedNetif = sta_netif; @@ -955,10 +931,10 @@ sl_wfx_mac_address_t wfx_get_wifi_mac_addr(sl_wfx_interface_t interface) *****************************************************************************/ void wfx_set_wifi_provision(wfx_wifi_provision_t * wifiConfig) { - memcpy(wifi_provision.ssid, wifiConfig->ssid, sizeof(wifiConfig->ssid)); - memcpy(wifi_provision.passkey, wifiConfig->passkey, sizeof(wifiConfig->passkey)); + Platform::CopyString(wifi_provision.ssid, sizeof(wifi_provision.ssid), wifiConfig->ssid); + Platform::CopyString(wifi_provision.passkey, sizeof(wifi_provision.passkey), wifiConfig->passkey); wifi_provision.security = wifiConfig->security; - SILABS_LOG("WIFI: Provision SSID=%s", &wifi_provision.ssid[0]); + ChipLogProgress(DeviceLayer, "WIFI: Provision SSID=%s", &wifi_provision.ssid[0]); } /**************************************************************************** @@ -970,12 +946,8 @@ void wfx_set_wifi_provision(wfx_wifi_provision_t * wifiConfig) *****************************************************************************/ bool wfx_get_wifi_provision(wfx_wifi_provision_t * wifiConfig) { - if (wifiConfig == NULL) - { - return false; - } + VerifyOrReturnError(wifiConfig != nullptr, false); memcpy(wifiConfig, &wifi_provision, sizeof(wfx_wifi_provision_t)); - return true; } @@ -1012,15 +984,13 @@ sl_status_t wfx_connect_to_ap(void) sl_status_t result; sl_wfx_security_mode_t connect_security_mode; - if (wifi_provision.ssid[0] == 0) - { - return SL_STATUS_NOT_AVAILABLE; - } - SILABS_LOG("WIFI:JOIN to %s", &wifi_provision.ssid[0]); + VerifyOrReturnError(wifi_provision.ssid[0], SL_STATUS_NOT_AVAILABLE); + ChipLogDetail(DeviceLayer, "WIFI:JOIN to %s", &wifi_provision.ssid[0]); - SILABS_LOG("WIFI Scan Paramter set to Active channel time %d, Passive Channel " - "Time: %d, Number of prob: %d", - ACTIVE_CHANNEL_TIME, PASSIVE_CHANNEL_TIME, NUM_PROBE_REQUEST); + ChipLogDetail(DeviceLayer, + "WIFI Scan Paramter set to Active channel time %d, Passive Channel " + "Time: %d, Number of prob: %d", + ACTIVE_CHANNEL_TIME, PASSIVE_CHANNEL_TIME, NUM_PROBE_REQUEST); (void) sl_wfx_set_scan_parameters(ACTIVE_CHANNEL_TIME, PASSIVE_CHANNEL_TIME, NUM_PROBE_REQUEST); switch (wifi_provision.security) { @@ -1038,7 +1008,7 @@ sl_status_t wfx_connect_to_ap(void) connect_security_mode = sl_wfx_security_mode_e::WFM_SECURITY_MODE_OPEN; break; default: - SILABS_LOG("%s: error: unknown security type."); + ChipLogError(DeviceLayer, "error: unknown security type."); return SL_STATUS_INVALID_STATE; } result = sl_wfx_send_join_command((uint8_t *) wifi_provision.ssid, strlen(wifi_provision.ssid), NULL, CHANNEL_0, @@ -1064,8 +1034,8 @@ void wfx_get_wifi_mac_addr(sl_wfx_interface_t interface, sl_wfx_mac_address_t * mac = &wifiContext.mac_addr_0; #endif *addr = *mac; - SILABS_LOG("WLAN:Get WiFi Mac addr %02x:%02x:%02x:%02x:%02x:%02x", mac->octet[0], mac->octet[1], mac->octet[2], mac->octet[3], - mac->octet[4], mac->octet[5]); + ChipLogDetail(DeviceLayer, "WLAN:Get WiFi Mac addr %02x:%02x:%02x:%02x:%02x:%02x", mac->octet[0], mac->octet[1], mac->octet[2], + mac->octet[3], mac->octet[4], mac->octet[5]); memcpy(&ap_info.bssid[0], &mac->octet[0], 6); } @@ -1078,14 +1048,8 @@ void wfx_get_wifi_mac_addr(sl_wfx_interface_t interface, sl_wfx_mac_address_t * *****************************************************************************/ bool wfx_have_ipv4_addr(sl_wfx_interface_t which_if) { - if (which_if == SL_WFX_STA_INTERFACE) - { - return (sta_ip == STA_IP_FAIL) ? false : true; - } - else - { - return false; /* TODO */ - } + VerifyOrReturnError(which_if == SL_WFX_STA_INTERFACE, false); + return (sta_ip == STA_IP_FAIL) ? false : true; } /**************************************************************************** @@ -1097,18 +1061,8 @@ bool wfx_have_ipv4_addr(sl_wfx_interface_t which_if) *****************************************************************************/ bool wfx_have_ipv6_addr(sl_wfx_interface_t which_if) { - SILABS_LOG("%s: started.", __func__); - bool status = false; - if (which_if == SL_WFX_STA_INTERFACE) - { - status = wfx_is_sta_connected(); - } - else - { - status = false; /* TODO */ - } - SILABS_LOG("%s: status: %d", __func__, status); - return status; + VerifyOrReturnError(which_if == SL_WFX_STA_INTERFACE, false); + return wfx_is_sta_connected(); } /**************************************************************************** @@ -1119,7 +1073,7 @@ bool wfx_have_ipv6_addr(sl_wfx_interface_t which_if) *****************************************************************************/ sl_status_t wfx_sta_discon(void) { - SILABS_LOG("STA-Disconnecting"); + ChipLogProgress(DeviceLayer, "STA-Disconnecting"); int32_t status = sl_wfx_send_disconnect_command(); wifi_extra &= ~WE_ST_STA_CONN; xEventGroupSetBits(sl_wfx_event_group, SL_WFX_RETRY_CONNECT); @@ -1145,11 +1099,7 @@ bool wfx_is_sta_mode_enabled(void) bool wfx_is_sta_connected(void) { bool val; - val = (wifi_extra & WE_ST_STA_CONN) ? true : false; - - SILABS_LOG("WLAN: STA %s connected", (val ? "IS" : "NOT")); - return val; } @@ -1159,10 +1109,7 @@ bool wfx_is_sta_connected(void) * @return returns true if sucessful, * false otherwise *****************************************************************************/ -void wfx_setup_ip6_link_local(sl_wfx_interface_t whichif) -{ - SILABS_LOG("Setup-IP6: TODO"); /* It is automatically done when lwip link up */ -} +void wfx_setup_ip6_link_local(sl_wfx_interface_t whichif) {} /**************************************************************************** * @brief @@ -1170,7 +1117,7 @@ void wfx_setup_ip6_link_local(sl_wfx_interface_t whichif) * @return returns WIFI_MODE_NULL if sucessful, * WIFI_MODE_STA otherwise *****************************************************************************/ -wifi_mode_t wfx_get_wifi_mode() +wifi_mode_t wfx_get_wifi_mode(void) { if (wifiContext.state & SL_WFX_STARTED) return WIFI_MODE_STA; @@ -1234,22 +1181,16 @@ void wfx_enable_sta_mode(void) #ifdef SL_WFX_CONFIG_SCAN bool wfx_start_scan(char * ssid, void (*callback)(wfx_wifi_scan_result_t *)) { - int sz; - - if (scan_cb) - return false; /* Already in progress */ + VerifyOrReturnError(scan_cb != nullptr, false); if (ssid) { - sz = strlen(ssid); - if ((scan_ssid = (char *) pvPortMalloc(sz + 1)) == (char *) 0) - { - return false; - } - strcpy(scan_ssid, ssid); + scan_ssid_length = strnlen(ssid, WFX_MAX_SSID_LENGTH); + scan_ssid = reinterpret_cast(chip::Platform::MemoryAlloc(scan_ssid_length)); + VerifyOrReturnError(scan_ssid != nullptr, false); + Platform::CopyString(scan_ssid, scan_ssid_length, ssid); } scan_cb = callback; xEventGroupSetBits(sl_wfx_event_group, SL_WFX_SCAN_START); - return true; } @@ -1261,23 +1202,20 @@ void wfx_cancel_scan(void) { struct scan_result_holder *hp, *next; /* Not possible */ - if (!scan_cb) - { - return; - } + VerifyOrReturn(scan_cb != nullptr); sl_wfx_send_stop_scan_command(); for (hp = scan_save; hp; hp = next) { next = hp->next; - vPortFree(hp); + chip::Platform::MemoryFree(hp); } scan_save = (struct scan_result_holder *) 0; scan_count = 0; if (scan_ssid) { - vPortFree(scan_ssid); - scan_ssid = (char *) 0; + chip::Platform::MemoryFree(scan_ssid); + scan_ssid = nullptr; } - scan_cb = 0; + scan_cb = nullptr; } #endif /* SL_WFX_CONFIG_SCAN */ diff --git a/examples/platform/silabs/wfx_rsi.h b/examples/platform/silabs/wfx_rsi.h index 5e7358e0d02cb1..0e62cb78029a79 100644 --- a/examples/platform/silabs/wfx_rsi.h +++ b/examples/platform/silabs/wfx_rsi.h @@ -77,6 +77,7 @@ typedef struct wfx_rsi_s #ifdef SL_WFX_CONFIG_SCAN void (*scan_cb)(wfx_wifi_scan_result_t *); char * scan_ssid; /* Which one are we scanning for */ + size_t scan_ssid_length; #endif #ifdef SL_WFX_CONFIG_SOFTAP sl_wfx_mac_address_t softap_mac; diff --git a/examples/platform/silabs/wifi/wfx_notify.cpp b/examples/platform/silabs/wifi/wfx_notify.cpp index e1d3c81abf8504..de1becacb33b30 100644 --- a/examples/platform/silabs/wifi/wfx_notify.cpp +++ b/examples/platform/silabs/wifi/wfx_notify.cpp @@ -60,13 +60,13 @@ static void RetryConnectionTimerHandler(void * arg) } } /*********************************************************************************** - * @fn wfx_started_notify() + * @fn wfx_started_notify(void) * @brief * Wifi device started notification * @param[in]: None * @return None *************************************************************************************/ -void wfx_started_notify() +void wfx_started_notify(void) { sl_wfx_startup_ind_t evt; sl_wfx_mac_address_t mac; diff --git a/examples/platform/silabs/wifi/wfx_rsi_host.cpp b/examples/platform/silabs/wifi/wfx_rsi_host.cpp index 921ec82587fe77..130d9c90d19817 100644 --- a/examples/platform/silabs/wifi/wfx_rsi_host.cpp +++ b/examples/platform/silabs/wifi/wfx_rsi_host.cpp @@ -15,16 +15,20 @@ * limitations under the License. */ -#include "stdbool.h" +#include #include #include #include #include "FreeRTOS.h" #include "event_groups.h" -#include "silabs_utils.h" -#include "sl_status.h" #include "task.h" + +#include +#include +#include +#include + #include "wfx_host_events.h" #include "wfx_rsi.h" @@ -54,22 +58,15 @@ constexpr osThreadAttr_t kWlanTaskAttr = { .name = "wlan_rsi", ***********************************************************************/ sl_status_t wfx_wifi_start(void) { - if (wfx_rsi.dev_state & WFX_RSI_ST_STARTED) - { - return SL_STATUS_OK; - } - + VerifyOrReturnError(!(wfx_rsi.dev_state & WFX_RSI_ST_STARTED), SL_STATUS_OK); wfx_rsi.dev_state |= WFX_RSI_ST_STARTED; - SILABS_LOG("%s: starting..", __func__); - /* - * Create the Wifi driver task - */ // Creating a Wi-Fi driver thread sWlanThread = osThreadNew(wfx_rsi_task, NULL, &kWlanTaskAttr); VerifyOrReturnError(sWlanThread != NULL, SL_STATUS_FAIL); + ChipLogProgress(DeviceLayer, "wfx_rsi_task created successfully"); return SL_STATUS_OK; } @@ -110,14 +107,12 @@ bool wfx_is_sta_mode_enabled(void) ***********************************************************************/ void wfx_get_wifi_mac_addr(sl_wfx_interface_t interface, sl_wfx_mac_address_t * addr) { - if (addr) - { + VerifyOrReturn(addr != nullptr); #ifdef SL_WFX_CONFIG_SOFTAP - *addr = (interface == SL_WFX_SOFTAP_INTERFACE) ? wfx_rsi.softap_mac : wfx_rsi.sta_mac; + *addr = (interface == SL_WFX_SOFTAP_INTERFACE) ? wfx_rsi.softap_mac : wfx_rsi.sta_mac; #else - *addr = wfx_rsi.sta_mac; + *addr = wfx_rsi.sta_mac; #endif - } } /********************************************************************* @@ -130,11 +125,9 @@ void wfx_get_wifi_mac_addr(sl_wfx_interface_t interface, sl_wfx_mac_address_t * ***********************************************************************/ void wfx_set_wifi_provision(wfx_wifi_provision_t * cfg) { - if (cfg) - { - wfx_rsi.sec = *cfg; - wfx_rsi.dev_state |= WFX_RSI_ST_STA_PROVISIONED; - } + VerifyOrReturn(cfg != nullptr); + wfx_rsi.sec = *cfg; + wfx_rsi.dev_state |= WFX_RSI_ST_STA_PROVISIONED; } /********************************************************************* @@ -147,15 +140,10 @@ void wfx_set_wifi_provision(wfx_wifi_provision_t * cfg) ***********************************************************************/ bool wfx_get_wifi_provision(wfx_wifi_provision_t * wifiConfig) { - if (wifiConfig != NULL) - { - if (wfx_rsi.dev_state & WFX_RSI_ST_STA_PROVISIONED) - { - *wifiConfig = wfx_rsi.sec; - return true; - } - } - return false; + VerifyOrReturnError(wifiConfig != nullptr, false); + VerifyOrReturnError(wfx_rsi.dev_state & WFX_RSI_ST_STA_PROVISIONED, false); + *wifiConfig = wfx_rsi.sec; + return true; } /********************************************************************* @@ -169,7 +157,7 @@ void wfx_clear_wifi_provision(void) { memset(&wfx_rsi.sec, 0, sizeof(wfx_rsi.sec)); wfx_rsi.dev_state &= ~WFX_RSI_ST_STA_PROVISIONED; - SILABS_LOG("%s: completed.", __func__); + ChipLogProgress(DeviceLayer, "Clear WiFi Provision"); } /************************************************************************* @@ -177,30 +165,25 @@ void wfx_clear_wifi_provision(void) * @brief * Start a JOIN command to the AP - Done by the wfx_rsi task * @param[in] None - * @return returns SL_STATUS_OK if successful, - * SL_STATUS_INVALID_CONFIGURATION otherwise + * @return returns SL_STATUS_OK if successful ****************************************************************************/ sl_status_t wfx_connect_to_ap(void) { + VerifyOrReturnError(wfx_rsi.dev_state & WFX_RSI_ST_STA_PROVISIONED, SL_STATUS_INVALID_CONFIGURATION); + VerifyOrReturnError(wfx_rsi.sec.ssid_length, SL_STATUS_INVALID_CREDENTIALS); + VerifyOrReturnError(wfx_rsi.sec.ssid_length <= WFX_MAX_SSID_LENGTH, SL_STATUS_HAS_OVERFLOWED); + ChipLogProgress(DeviceLayer, "connect to access point: %s", wfx_rsi.sec.ssid); WfxEvent_t event; - if (wfx_rsi.dev_state & WFX_RSI_ST_STA_PROVISIONED) - { - SILABS_LOG("Connecting to access point -> SSID: %s", &wfx_rsi.sec.ssid[0]); - event.eventType = WFX_EVT_STA_START_JOIN; - WfxPostEvent(&event); - } - else - { - SILABS_LOG("Error: access point not provisioned."); - return SL_STATUS_INVALID_CONFIGURATION; - } + event.eventType = WFX_EVT_STA_START_JOIN; + WfxPostEvent(&event); return SL_STATUS_OK; } #if SL_ICD_ENABLED #if SLI_SI917 /********************************************************************* - * @fn sl_status_t wfx_power_save() + * @fn sl_status_t wfx_power_save(rsi_power_save_profile_mode_t sl_si91x_ble_state, sl_si91x_performance_profile_t + sl_si91x_wifi_state) * @brief * Implements the power save in sleepy application * @param[in] sl_si91x_ble_state : State to set for the BLE @@ -214,14 +197,14 @@ sl_status_t wfx_power_save(rsi_power_save_profile_mode_t sl_si91x_ble_state, sl_ } #else // For RS9116 /********************************************************************* - * @fn sl_status_t wfx_power_save() + * @fn sl_status_t wfx_power_save(void) * @brief * Implements the power save in sleepy application * @param[in] None * @return SL_STATUS_OK if successful, * SL_STATUS_FAIL otherwise ***********************************************************************/ -sl_status_t wfx_power_save() +sl_status_t wfx_power_save(void) { return (wfx_rsi_power_save() ? SL_STATUS_FAIL : SL_STATUS_OK); } @@ -241,7 +224,6 @@ void wfx_setup_ip6_link_local(sl_wfx_interface_t whichif) * TODO: Implement IPV6 setup, currently in wfx_rsi_task() * This is hooked with MATTER code. */ - SILABS_LOG("%s: warning: not implemented.", __func__); } /********************************************************************* @@ -255,19 +237,18 @@ void wfx_setup_ip6_link_local(sl_wfx_interface_t whichif) bool wfx_is_sta_connected(void) { bool status = (wfx_rsi.dev_state & WFX_RSI_ST_STA_CONNECTED) > 0; - SILABS_LOG("%s: %s", __func__, (status ? "Connected" : "Disconnected")); return status; } /********************************************************************* - * @fn wifi_mode_t wfx_get_wifi_mode() + * @fn wifi_mode_t wfx_get_wifi_mode(void) * @brief * get the wifi mode * @param[in] None * @return return WIFI_MODE_NULL if successful, * WIFI_MODE_STA otherwise ***********************************************************************/ -wifi_mode_t wfx_get_wifi_mode() +wifi_mode_t wfx_get_wifi_mode(void) { if (wfx_rsi.dev_state & WFX_RSI_ST_DEV_READY) return WIFI_MODE_STA; @@ -284,11 +265,9 @@ wifi_mode_t wfx_get_wifi_mode() ***********************************************************************/ sl_status_t wfx_sta_discon(void) { - SILABS_LOG("%s: started.", __func__); - int32_t status; + sl_status_t status; status = wfx_rsi_disconnect(); wfx_rsi.dev_state &= ~WFX_RSI_ST_STA_CONNECTED; - SILABS_LOG("%s: completed.", __func__); return status; } #if CHIP_DEVICE_CONFIG_ENABLE_IPV4 @@ -302,17 +281,8 @@ sl_status_t wfx_sta_discon(void) ***********************************************************************/ bool wfx_have_ipv4_addr(sl_wfx_interface_t which_if) { - bool status = false; - if (which_if == SL_WFX_STA_INTERFACE) - { - status = (wfx_rsi.dev_state & WFX_RSI_ST_STA_DHCP_DONE) > 0; - } - else - { - status = false; /* TODO */ - } - SILABS_LOG("%s: status: %d", __func__, status); - return status; + VerifyOrReturnError(which_if == SL_WFX_STA_INTERFACE, false); + return ((wfx_rsi.dev_state & WFX_RSI_ST_STA_DHCP_DONE) > 0); } #endif /* CHIP_DEVICE_CONFIG_ENABLE_IPV4 */ @@ -326,17 +296,9 @@ bool wfx_have_ipv4_addr(sl_wfx_interface_t which_if) ***********************************************************************/ bool wfx_have_ipv6_addr(sl_wfx_interface_t which_if) { - bool status = false; - if (which_if == SL_WFX_STA_INTERFACE) - { - status = (wfx_rsi.dev_state & WFX_RSI_ST_STA_CONNECTED) > 0; - } - else - { - status = false; /* TODO */ - } - SILABS_LOG("%s: %d", __func__, status); - return status; + VerifyOrReturnError(which_if == SL_WFX_STA_INTERFACE, false); + // TODO: WFX_RSI_ST_STA_CONNECTED does not guarantee SLAAC IPv6 LLA, maybe use a different FLAG + return ((wfx_rsi.dev_state & WFX_RSI_ST_STA_CONNECTED) > 0); } /********************************************************************* @@ -379,14 +341,14 @@ int32_t wfx_get_ap_ext(wfx_wifi_scan_ext_t * extra_info) } /*************************************************************************** - * @fn int32_t wfx_reset_counts(){ + * @fn int32_t wfx_reset_counts(void) * @brief * get the driver reset count * @param[in] None * @return * reset count *****************************************************************************/ -int32_t wfx_reset_counts() +int32_t wfx_reset_counts(void) { return wfx_rsi_reset_count(); } @@ -402,21 +364,17 @@ int32_t wfx_reset_counts() *******************************************************************************/ bool wfx_start_scan(char * ssid, void (*callback)(wfx_wifi_scan_result_t *)) { - int sz; - WfxEvent_t event; - if (wfx_rsi.scan_cb) - return false; /* Already in progress */ - if (ssid) - { - sz = strlen(ssid); - if ((wfx_rsi.scan_ssid = (char *) pvPortMalloc(sz + 1)) == (char *) 0) - { - return false; - } - strcpy(wfx_rsi.scan_ssid, ssid); - } + // check if already in progress + VerifyOrReturnError(wfx_rsi.scan_cb != nullptr, false); wfx_rsi.scan_cb = callback; + VerifyOrReturnError(ssid != nullptr, false); + wfx_rsi.scan_ssid_length = strnlen(ssid, chip::min(sizeof(ssid), WFX_MAX_SSID_LENGTH)); + wfx_rsi.scan_ssid = reinterpret_cast(chip::Platform::MemoryAlloc(wfx_rsi.scan_ssid_length)); + VerifyOrReturnError(wfx_rsi.scan_ssid != nullptr, false); + chip::Platform::CopyString(wfx_rsi.scan_ssid, wfx_rsi.scan_ssid_length, ssid); + + WfxEvent_t event; event.eventType = WFX_EVT_SCAN; WfxPostEvent(&event); @@ -434,6 +392,6 @@ bool wfx_start_scan(char * ssid, void (*callback)(wfx_wifi_scan_result_t *)) void wfx_cancel_scan(void) { /* Not possible */ - SILABS_LOG("%s: cannot cancel scan", __func__); + ChipLogError(DeviceLayer, "cannot cancel scan"); } #endif /* SL_WFX_CONFIG_SCAN */ diff --git a/examples/shell/shell_common/BUILD.gn b/examples/shell/shell_common/BUILD.gn index e4aa2973f8cc04..645c8ddb510220 100644 --- a/examples/shell/shell_common/BUILD.gn +++ b/examples/shell/shell_common/BUILD.gn @@ -13,13 +13,12 @@ # limitations under the License. import("//build_overrides/chip.gni") -import("//build_overrides/openthread.gni") - +import("${chip_root}/config/recommended.gni") import("${chip_root}/src/platform/device.gni") declare_args() { - # Enable server command only on linux for now. - chip_shell_cmd_server = current_os == "linux" || current_os == "mac" + chip_shell_cmd_server = matter_enable_recommended && + (current_os == "linux" || current_os == "mac") } config("shell_common_config") { diff --git a/scripts/tools/generate_esp32_chip_factory_bin.py b/scripts/tools/generate_esp32_chip_factory_bin.py index 892f0609927cd2..ef23dc61b337ef 100755 --- a/scripts/tools/generate_esp32_chip_factory_bin.py +++ b/scripts/tools/generate_esp32_chip_factory_bin.py @@ -209,6 +209,11 @@ class Product_Color_Enum(Enum): 'encoding': 'string', 'value': None, }, + 'device-type': { + 'type': 'data', + 'encoding': 'u32', + 'value': None, + }, } @@ -372,6 +377,8 @@ def populate_factory_data(args, spake2p_params): FACTORY_DATA['product-url']['value'] = args.product_url if args.product_label: FACTORY_DATA['product-label']['value'] = args.product_label + if args.device_type is not None: + FACTORY_DATA['device-type']['value'] = args.device_type # SupportedModes are stored as multiple entries # - sm-sz/ : number of supported modes for the endpoint @@ -554,6 +561,8 @@ def any_base_int(s): return int(s, 0) parser.add_argument("--product-label", type=str, help='human readable product label') parser.add_argument("--product-url", type=str, help='link to product specific web page') + parser.add_argument("--device-type", type=any_base_int, help='commissionable device type') + parser.add_argument('-s', '--size', type=any_base_int, default=0x6000, help='The size of the partition.bin, default: 0x6000') parser.add_argument('--target', default='esp32', diff --git a/scripts/tools/telink/requirements.txt b/scripts/tools/telink/requirements.txt index bb4359b5319da3..58b519dc924bfa 100644 --- a/scripts/tools/telink/requirements.txt +++ b/scripts/tools/telink/requirements.txt @@ -1,4 +1,4 @@ -cryptography==41.0.4 +cryptography==43.0.1 cffi==1.15.0 future==0.18.3 pycparser==2.21 diff --git a/src/app/common_flags.gni b/src/app/common_flags.gni index 953afc23a20650..d3e7ce34bf0338 100644 --- a/src/app/common_flags.gni +++ b/src/app/common_flags.gni @@ -12,6 +12,9 @@ # See the License for the specific language governing permissions and # limitations under the License. +import("//build_overrides/chip.gni") +import("${chip_root}/config/recommended.gni") + declare_args() { # Temporary flag for interaction model and echo protocols, set it to true to enable chip_app_use_echo = false @@ -26,7 +29,7 @@ declare_args() { # - disabled: does not use data model interface at all # - check: runs BOTH datamodel and non-data-model (if possible) functionality and compares results # - enabled: runs only the data model interface (does not use the legacy code) - if (current_os == "linux") { + if (matter_enable_recommended && current_os == "linux") { chip_use_data_model_interface = "check" } else { chip_use_data_model_interface = "disabled" diff --git a/src/app/util/attribute-storage.h b/src/app/util/attribute-storage.h index b45bfe43cff43e..23a9b9b5fd20c3 100644 --- a/src/app/util/attribute-storage.h +++ b/src/app/util/attribute-storage.h @@ -60,6 +60,12 @@ static constexpr uint16_t kEmberInvalidEndpointIndex = 0xFFFF; } /* cluster revision */ \ } +// The attrMask must contain the relevant ATTRIBUTE_MASK_* bits from +// attribute-metadata.h. Specifically: +// +// * Writable attributes must have ATTRIBUTE_MASK_WRITABLE +// * Nullable attributes (have X in the quality column in the spec) must have ATTRIBUTE_MASK_NULLABLE +// * Attributes that have T in the Access column in the spec must have ATTRIBUTE_MASK_MUST_USE_TIMED_WRITE #define DECLARE_DYNAMIC_ATTRIBUTE(attId, attType, attSizeBytes, attrMask) \ { \ ZAP_EMPTY_DEFAULT(), attId, attSizeBytes, ZAP_TYPE(attType), attrMask | ZAP_ATTRIBUTE_MASK(EXTERNAL_STORAGE) \ diff --git a/src/darwin/Framework/CHIPTests/MTRCommissionableBrowserTests.m b/src/darwin/Framework/CHIPTests/MTRCommissionableBrowserTests.m index 15ef7a839de97a..0acfbd9a580371 100644 --- a/src/darwin/Framework/CHIPTests/MTRCommissionableBrowserTests.m +++ b/src/darwin/Framework/CHIPTests/MTRCommissionableBrowserTests.m @@ -55,6 +55,7 @@ @interface DeviceScannerDelegate : NSObject @property (nonatomic, nullable) XCTestExpectation * expectation; @property (nonatomic) NSMutableArray *> * results; @property (nonatomic) NSMutableArray *> * removedResults; +@property (nonatomic) BOOL expectedResultsCountReached; - (instancetype)initWithExpectation:(XCTestExpectation *)expectation; - (void)controller:(MTRDeviceController *)controller didFindCommissionableDevice:(MTRCommissionableBrowserResult *)device; @@ -71,6 +72,7 @@ - (instancetype)initWithExpectation:(XCTestExpectation *)expectation _expectation = expectation; _results = [[NSMutableArray alloc] init]; _removedResults = [[NSMutableArray alloc] init]; + _expectedResultsCountReached = NO; return self; } @@ -83,6 +85,7 @@ - (instancetype)init _expectation = nil; _results = [[NSMutableArray alloc] init]; _removedResults = [[NSMutableArray alloc] init]; + _expectedResultsCountReached = NO; return self; } @@ -111,7 +114,14 @@ - (void)controller:(MTRDeviceController *)controller didFindCommissionableDevice // Ensure that we just saw the same results as our final set popping in and out if things // ever got removed here. XCTAssertEqualObjects(finalResultsSet, allResultsSet); - [self.expectation fulfill]; + + // If we have a remove and re-add after the result count reached the + // expected one, we can end up in this branch again. Doing the above + // checks is fine, but we shouldn't double-fulfill the expectation. + if (self.expectedResultsCountReached == NO) { + self.expectedResultsCountReached = YES; + [self.expectation fulfill]; + } } XCTAssertLessThanOrEqual(_results.count, kExpectedDiscoveredDevicesCount); diff --git a/src/lib/core/core.gni b/src/lib/core/core.gni index f2189198e36131..eea73a5c56f7b3 100644 --- a/src/lib/core/core.gni +++ b/src/lib/core/core.gni @@ -12,6 +12,9 @@ # See the License for the specific language governing permissions and # limitations under the License. +import("//build_overrides/chip.gni") +import("${chip_root}/config/recommended.gni") + declare_args() { # Enable logging. Shorthand for chip_error_logging, etc. chip_logging = true @@ -28,13 +31,16 @@ declare_args() { chip_progress_logging = chip_logging # Enable detail logging. - chip_detail_logging = chip_logging + chip_detail_logging = matter_enable_recommended && chip_logging # Enable automation logging. - chip_automation_logging = chip_logging + chip_automation_logging = matter_enable_recommended && chip_logging +} +declare_args() { # Configure the maximum size for logged messages - if (current_os == "linux" || current_os == "mac" || current_os == "ios") { + if ((matter_enable_recommended || chip_detail_logging) && + (current_os == "linux" || current_os == "mac" || current_os == "ios")) { # Allow base64 encoding of 1 MTU (4 * (1280 / 3) + padding chip_log_message_max_size = 1708 } else { @@ -88,7 +94,8 @@ declare_args() { chip_config_memory_debug_dmalloc = false # When enabled trace messages using tansport trace hook. - chip_enable_transport_trace = current_os == "linux" || current_os == "mac" + chip_enable_transport_trace = matter_enable_recommended && + (current_os == "linux" || current_os == "mac") # When this is enabled trace messages will be sent to pw_trace. chip_enable_transport_pw_trace = false diff --git a/src/platform/ESP32/ConfigurationManagerImpl.cpp b/src/platform/ESP32/ConfigurationManagerImpl.cpp index 31c7cb714f96c0..78446432c58b0a 100644 --- a/src/platform/ESP32/ConfigurationManagerImpl.cpp +++ b/src/platform/ESP32/ConfigurationManagerImpl.cpp @@ -269,6 +269,23 @@ CHIP_ERROR ConfigurationManagerImpl::GetLocationCapability(uint8_t & location) #endif // CONFIG_ENABLE_ESP32_LOCATIONCAPABILITY } +CHIP_ERROR ConfigurationManagerImpl::GetDeviceTypeId(uint32_t & deviceType) +{ + uint32_t value = 0; + CHIP_ERROR err = ReadConfigValue(ESP32Config::kConfigKey_PrimaryDeviceType, value); + + if (err == CHIP_DEVICE_ERROR_CONFIG_NOT_FOUND) + { + deviceType = CHIP_DEVICE_CONFIG_DEVICE_TYPE; + } + else + { + deviceType = value; + } + + return CHIP_NO_ERROR; +} + CHIP_ERROR ConfigurationManagerImpl::StoreCountryCode(const char * code, size_t codeLen) { // As per spec, codeLen has to be 2 diff --git a/src/platform/ESP32/ConfigurationManagerImpl.h b/src/platform/ESP32/ConfigurationManagerImpl.h index 63b3e094763a75..648c150fc01a44 100644 --- a/src/platform/ESP32/ConfigurationManagerImpl.h +++ b/src/platform/ESP32/ConfigurationManagerImpl.h @@ -58,6 +58,7 @@ class ConfigurationManagerImpl : public Internal::GenericConfigurationManagerImp CHIP_ERROR GetSoftwareVersionString(char * buf, size_t bufSize); CHIP_ERROR GetSoftwareVersion(uint32_t & softwareVer) override; CHIP_ERROR GetLocationCapability(uint8_t & location) override; + CHIP_ERROR GetDeviceTypeId(uint32_t & deviceType) override; static ConfigurationManagerImpl & GetDefaultInstance(); // Set the country code to esp_phy layer and also store it to NVS diff --git a/src/platform/ESP32/ESP32Config.cpp b/src/platform/ESP32/ESP32Config.cpp index c94de5c04b85b2..df48f5f2955793 100644 --- a/src/platform/ESP32/ESP32Config.cpp +++ b/src/platform/ESP32/ESP32Config.cpp @@ -81,6 +81,7 @@ const ESP32Config::Key ESP32Config::kConfigKey_ProductFinish = { kConfig const ESP32Config::Key ESP32Config::kConfigKey_ProductColor = { kConfigNamespace_ChipFactory, "product-color" }; const ESP32Config::Key ESP32Config::kConfigKey_PartNumber = { kConfigNamespace_ChipFactory, "part-number" }; const ESP32Config::Key ESP32Config::kConfigKey_LocationCapability = { kConfigNamespace_ChipFactory, "loc-capability" }; +const ESP32Config::Key ESP32Config::kConfigKey_PrimaryDeviceType = { kConfigNamespace_ChipFactory, "device-type" }; // Keys stored in the chip-config namespace const ESP32Config::Key ESP32Config::kConfigKey_ServiceConfig = { kConfigNamespace_ChipConfig, "service-config" }; diff --git a/src/platform/ESP32/ESP32Config.h b/src/platform/ESP32/ESP32Config.h index 218f2354b2b358..f2f03cf7f9074b 100644 --- a/src/platform/ESP32/ESP32Config.h +++ b/src/platform/ESP32/ESP32Config.h @@ -83,6 +83,7 @@ class ESP32Config static const Key kConfigKey_ProductFinish; static const Key kConfigKey_ProductColor; static const Key kConfigKey_LocationCapability; + static const Key kConfigKey_PrimaryDeviceType; // CHIP Config keys static const Key kConfigKey_ServiceConfig; diff --git a/src/platform/silabs/ConnectivityManagerImpl_WIFI.cpp b/src/platform/silabs/ConnectivityManagerImpl_WIFI.cpp index b5a9c1eb56a3f8..6e5470f7d05f26 100644 --- a/src/platform/silabs/ConnectivityManagerImpl_WIFI.cpp +++ b/src/platform/silabs/ConnectivityManagerImpl_WIFI.cpp @@ -327,7 +327,7 @@ void ConnectivityManagerImpl::DriveStationState() ChipLogProgress(DeviceLayer, "Attempting to connect WiFi"); if ((serr = wfx_connect_to_ap()) != SL_STATUS_OK) { - ChipLogError(DeviceLayer, "wfx_connect_to_ap() failed."); + ChipLogError(DeviceLayer, "wfx_connect_to_ap() failed: %" PRId32, serr); } SuccessOrExit(serr); diff --git a/src/platform/silabs/KeyValueStoreManagerImpl.cpp b/src/platform/silabs/KeyValueStoreManagerImpl.cpp index 012c951aaaa729..34d88388badf22 100644 --- a/src/platform/silabs/KeyValueStoreManagerImpl.cpp +++ b/src/platform/silabs/KeyValueStoreManagerImpl.cpp @@ -88,9 +88,9 @@ uint16_t KeyValueStoreManagerImpl::hashKvsKeyString(const char * key) const CHIP_ERROR KeyValueStoreManagerImpl::MapKvsKeyToNvm3(const char * key, uint16_t hash, uint32_t & nvm3Key, bool isSlotNeeded) const { CHIP_ERROR err; - char * strPrefix = nullptr; - uint8_t firstEmptyKeySlot = kMaxEntries; - for (uint8_t keyIndex = 0; keyIndex < kMaxEntries; keyIndex++) + char * strPrefix = nullptr; + uint16_t firstEmptyKeySlot = kMaxEntries; + for (uint16_t keyIndex = 0; keyIndex < kMaxEntries; keyIndex++) { if (mKvsKeyMap[keyIndex] == hash) { @@ -165,7 +165,7 @@ void KeyValueStoreManagerImpl::ScheduleKeyMapSave(void) Commit the key map in nvm once it as stabilized. */ SystemLayer().StartTimer( - std::chrono::duration_cast(System::Clock::Seconds32(SILABS_KVS_SAVE_DELAY_SECONDS)), + std::chrono::duration_cast(System::Clock::Seconds32(SL_KVS_SAVE_DELAY_SECONDS)), KeyValueStoreManagerImpl::OnScheduledKeyMapSave, NULL); } @@ -247,7 +247,7 @@ CHIP_ERROR KeyValueStoreManagerImpl::_Delete(const char * key) void KeyValueStoreManagerImpl::ErasePartition(void) { // Iterate over all the Matter Kvs nvm3 records and delete each one... - for (uint32_t nvm3Key = SilabsConfig::kMinConfigKey_MatterKvs; nvm3Key <= SilabsConfig::kMaxConfigKey_MatterKvs; nvm3Key++) + for (uint32_t nvm3Key = SilabsConfig::kMinConfigKey_MatterKvs; nvm3Key <= SilabsConfig::kConfigKey_KvsLastKeySlot; nvm3Key++) { SilabsConfig::ClearConfigValue(nvm3Key); } diff --git a/src/platform/silabs/NetworkCommissioningWiFiDriver.cpp b/src/platform/silabs/NetworkCommissioningWiFiDriver.cpp index 614a121280eaef..7f6240c32c5858 100644 --- a/src/platform/silabs/NetworkCommissioningWiFiDriver.cpp +++ b/src/platform/silabs/NetworkCommissioningWiFiDriver.cpp @@ -147,10 +147,19 @@ CHIP_ERROR SlWiFiDriver::ConnectWiFiNetwork(const char * ssid, uint8_t ssidLen, } } ReturnErrorOnFailure(ConnectivityMgr().SetWiFiStationMode(ConnectivityManager::kWiFiStationMode_Disabled)); + // Set the wifi configuration - wfx_wifi_provision_t wifiConfig = {}; + wfx_wifi_provision_t wifiConfig; + memset(&wifiConfig, 0, sizeof(wifiConfig)); + + VerifyOrReturnError(ssidLen <= WFX_MAX_SSID_LENGTH, CHIP_ERROR_BUFFER_TOO_SMALL); memcpy(wifiConfig.ssid, ssid, ssidLen); + wifiConfig.ssid_length = ssidLen; + + VerifyOrReturnError(keyLen < WFX_MAX_PASSKEY_LENGTH, CHIP_ERROR_BUFFER_TOO_SMALL); memcpy(wifiConfig.passkey, key, keyLen); + wifiConfig.passkey_length = keyLen; + wifiConfig.security = WFX_SEC_WPA2; ChipLogProgress(NetworkProvisioning, "Setting up connection for WiFi SSID: %.*s", static_cast(ssidLen), ssid); diff --git a/src/platform/silabs/SiWx917/wifi/ethernetif.cpp b/src/platform/silabs/SiWx917/wifi/ethernetif.cpp index 72725102d6da48..2860b895ce7fae 100644 --- a/src/platform/silabs/SiWx917/wifi/ethernetif.cpp +++ b/src/platform/silabs/SiWx917/wifi/ethernetif.cpp @@ -44,7 +44,7 @@ extern "C" { #include "lwip/ethip6.h" #include "lwip/timeouts.h" #include "netif/etharp.h" -#include "silabs_utils.h" +#include StaticSemaphore_t xEthernetIfSemaBuffer; @@ -131,13 +131,13 @@ static void low_level_input(struct netif * netif, uint8_t * b, uint16_t len) (memcmp(netif->hwaddr, dst_mac, netif->hwaddr_len) != 0)) { #ifdef WIFI_DEBUG_ENABLED - SILABS_LOG("%s: DROP, [%02x:%02x:%02x:%02x:%02x:%02x]<-[%02x:%02x:%02x:%02x:%02x:%02x] type=%02x%02x", __func__, + ChipLogDetail(DeviceLayer, "DROP: [%02x:%02x:%02x:%02x:%02x:%02x]->[%02x:%02x:%02x:%02x:%02x:%02x] type=%02x%02x", - dst_mac[0], dst_mac[1], dst_mac[2], dst_mac[3], dst_mac[4], dst_mac[5], + src_mac[0], src_mac[1], src_mac[2], src_mac[3], src_mac[4], src_mac[5], - src_mac[0], src_mac[1], src_mac[2], src_mac[3], src_mac[4], src_mac[5], + dst_mac[0], dst_mac[1], dst_mac[2], dst_mac[3], dst_mac[4], dst_mac[5], - b[12], b[13]); + b[12], b[13]); #endif return; } @@ -153,14 +153,14 @@ static void low_level_input(struct netif * netif, uint8_t * b, uint16_t len) bufferoffset += q->len; } #ifdef WIFI_DEBUG_ENABLED - SILABS_LOG("%s: ACCEPT %d, [%02x:%02x:%02x:%02x:%02x:%02x]<-[%02x:%02x:%02x:%02x:%02x:%02x] type=%02x%02x", __func__, - bufferoffset, + ChipLogDetail(DeviceLayer, "ACCEPT(%d): [%02x:%02x:%02x:%02x:%02x:%02x]->[%02x:%02x:%02x:%02x:%02x:%02x] type=%02x%02x", + bufferoffset, - dst_mac[0], dst_mac[1], dst_mac[2], dst_mac[3], dst_mac[4], dst_mac[5], + src_mac[0], src_mac[1], src_mac[2], src_mac[3], src_mac[4], src_mac[5], - src_mac[0], src_mac[1], src_mac[2], src_mac[3], src_mac[4], src_mac[5], + dst_mac[0], dst_mac[1], dst_mac[2], dst_mac[3], dst_mac[4], dst_mac[5], - b[12], b[13]); + b[12], b[13]); #endif if (netif->input(p, netif) != ERR_OK) diff --git a/src/platform/silabs/SiWx917/wifi/wfx_host_events.h b/src/platform/silabs/SiWx917/wifi/wfx_host_events.h index 319a1c508e658d..42a5dfffc1c381 100644 --- a/src/platform/silabs/SiWx917/wifi/wfx_host_events.h +++ b/src/platform/silabs/SiWx917/wifi/wfx_host_events.h @@ -159,7 +159,9 @@ typedef enum typedef struct { char ssid[WFX_MAX_SSID_LENGTH + 1]; + size_t ssid_length; char passkey[WFX_MAX_PASSKEY_LENGTH + 1]; + size_t passkey_length; wfx_sec_t security; } wfx_wifi_provision_t; @@ -175,6 +177,7 @@ typedef enum typedef struct wfx_wifi_scan_result { char ssid[WFX_MAX_SSID_LENGTH + 1]; + size_t ssid_length; wfx_sec_t security; uint8_t bssid[BSSID_LEN]; uint8_t chan; diff --git a/src/platform/silabs/SilabsConfig.h b/src/platform/silabs/SilabsConfig.h index ccb14beeb8f177..cef9ca323f74d2 100644 --- a/src/platform/silabs/SilabsConfig.h +++ b/src/platform/silabs/SilabsConfig.h @@ -35,9 +35,11 @@ #endif // Delay before Key/Value is actually saved in NVM -#define SILABS_KVS_SAVE_DELAY_SECONDS 5 +#ifndef SL_KVS_SAVE_DELAY_SECONDS +#define SL_KVS_SAVE_DELAY_SECONDS 2 +#endif -static_assert((KVS_MAX_ENTRIES <= 255), "Implementation supports up to 255 Kvs entries"); +static_assert((KVS_MAX_ENTRIES <= 511), "Implementation supports up to 511 Kvs entries"); static_assert((KVS_MAX_ENTRIES >= 30), "Mininimal Kvs entries requirement is not met"); namespace chip { @@ -89,7 +91,8 @@ class SilabsConfig // Persistent counter values set at runtime. Retained during factory reset. static constexpr uint8_t kMatterCounter_KeyBase = 0x74; // Persistent config values set at runtime. Cleared during factory reset. - static constexpr uint8_t kMatterKvs_KeyBase = 0x75; + static constexpr uint8_t kMatterKvs_KeyBase = 0x75; + static constexpr uint8_t kMatterKvs_ExtendedRange = 0x76; // Key definitions for well-known configuration values. // Factory config keys @@ -167,7 +170,8 @@ class SilabsConfig // Matter KVS storage Keys static constexpr Key kConfigKey_KvsStringKeyMap = SilabsConfigKey(kMatterKvs_KeyBase, 0x00); static constexpr Key kConfigKey_KvsFirstKeySlot = SilabsConfigKey(kMatterKvs_KeyBase, 0x01); - static constexpr Key kConfigKey_KvsLastKeySlot = SilabsConfigKey(kMatterKvs_KeyBase, KVS_MAX_ENTRIES); + static constexpr Key kConfigKey_KvsLastKeySlot = + SilabsConfigKey(kMatterKvs_KeyBase + (KVS_MAX_ENTRIES >> 8), KVS_MAX_ENTRIES & UINT8_MAX); // Set key id limits for each group. static constexpr Key kMinConfigKey_MatterFactory = SilabsConfigKey(kMatterFactory_KeyBase, 0x00); @@ -180,7 +184,9 @@ class SilabsConfig static constexpr Key kMaxConfigKey_MatterCounter = SilabsConfigKey(kMatterCounter_KeyBase, 0x1F); static constexpr Key kMinConfigKey_MatterKvs = kConfigKey_KvsStringKeyMap; - static constexpr Key kMaxConfigKey_MatterKvs = kConfigKey_KvsLastKeySlot; + static constexpr Key kMaxConfigKey_MatterKvs = SilabsConfigKey(kMatterKvs_ExtendedRange, 0xFF); + static_assert(kConfigKey_KvsLastKeySlot <= kMaxConfigKey_MatterKvs, + "Configured KVS_MAX_ENTRIES overflows the reserved KVS Key range"); static CHIP_ERROR Init(void); static void DeInit(void); diff --git a/src/platform/silabs/efr32/wifi/ethernetif.cpp b/src/platform/silabs/efr32/wifi/ethernetif.cpp index 0388337939a3e2..d0f0ec6daf47f7 100644 --- a/src/platform/silabs/efr32/wifi/ethernetif.cpp +++ b/src/platform/silabs/efr32/wifi/ethernetif.cpp @@ -148,8 +148,8 @@ static void low_level_input(struct netif * netif, uint8_t * b, uint16_t len) (memcmp(netif->hwaddr, dst_mac, netif->hwaddr_len) != 0)) { #ifdef WIFI_DEBUG_ENABLED - ChipLogProgress(DeviceLayer, "%s: DROP, [%02x:%02x:%02x:%02x:%02x:%02x]<-[%02x:%02x:%02x:%02x:%02x:%02x] type=%02x%02x", - __func__, + ChipLogProgress(DeviceLayer, + "lwip_input: DROP, [%02x:%02x:%02x:%02x:%02x:%02x]<-[%02x:%02x:%02x:%02x:%02x:%02x] type=%02x%02x", dst_mac[0], dst_mac[1], dst_mac[2], dst_mac[3], dst_mac[4], dst_mac[5], @@ -172,7 +172,7 @@ static void low_level_input(struct netif * netif, uint8_t * b, uint16_t len) } #ifdef WIFI_DEBUG_ENABLED ChipLogProgress(DeviceLayer, - "%s: ACCEPT %ld, [%02x:%02x:%02x:%02x:%02x:%02x]<-[%02x:%02x:%02x:%02x:%02x:%02x] type=%02x%02x", __func__, + "lwip_input: ACCEPT %ld, [%02x:%02x:%02x:%02x:%02x:%02x]<-[%02x:%02x:%02x:%02x:%02x:%02x] type=%02x%02x", bufferoffset, dst_mac[0], dst_mac[1], dst_mac[2], dst_mac[3], dst_mac[4], dst_mac[5], diff --git a/src/platform/silabs/efr32/wifi/wfx_host_events.h b/src/platform/silabs/efr32/wifi/wfx_host_events.h index 51f96d7b9dbc73..4686931eafac4e 100644 --- a/src/platform/silabs/efr32/wifi/wfx_host_events.h +++ b/src/platform/silabs/efr32/wifi/wfx_host_events.h @@ -254,7 +254,9 @@ typedef enum typedef struct { char ssid[WFX_MAX_SSID_LENGTH + 1]; + size_t ssid_length; char passkey[WFX_MAX_PASSKEY_LENGTH + 1]; + size_t passkey_length; wfx_sec_t security; } wfx_wifi_provision_t; @@ -270,6 +272,7 @@ typedef enum typedef struct wfx_wifi_scan_result { char ssid[WFX_MAX_SSID_LENGTH + 1]; + size_t ssid_length; wfx_sec_t security; uint8_t bssid[BSSID_LEN]; uint8_t chan; diff --git a/src/python_testing/TC_BRBINFO_4_1.py b/src/python_testing/TC_BRBINFO_4_1.py index df922748999dd0..8b064a775f358b 100644 --- a/src/python_testing/TC_BRBINFO_4_1.py +++ b/src/python_testing/TC_BRBINFO_4_1.py @@ -123,6 +123,7 @@ async def setup_class(self): self.set_of_dut_endpoints_before_adding_device = set(root_part_list) super().setup_class() + self._active_change_event_subscription = None self.app_process = None self.app_process_paused = False app = self.user_params.get("th_icd_server_app_path", None) @@ -156,6 +157,10 @@ async def setup_class(self): params.commissioningParameters.setupManualCode, params.commissioningParameters.setupQRCode) def teardown_class(self): + if self._active_change_event_subscription is not None: + self._active_change_event_subscription.Shutdown() + self._active_change_event_subscription = None + # In case the th_icd_server_app_path does not exist, then we failed the test # and there is nothing to remove if self.app_process is not None: @@ -239,8 +244,8 @@ async def test_TC_BRBINFO_4_1(self): self.q = queue.Queue() urgent = 1 cb = SimpleEventCallback("ActiveChanged", event.cluster_id, event.event_id, self.q) - subscription = await self.default_controller.ReadEvent(nodeid=self.dut_node_id, events=[(dynamic_endpoint_id, event, urgent)], reportInterval=[1, 3]) - subscription.SetEventUpdateCallback(callback=cb) + self._active_change_event_subscription = await self.default_controller.ReadEvent(nodeid=self.dut_node_id, events=[(dynamic_endpoint_id, event, urgent)], reportInterval=[1, 3]) + self._active_change_event_subscription.SetEventUpdateCallback(callback=cb) self.step("3") stay_active_duration_ms = 1000 diff --git a/src/python_testing/TC_CCTRL_2_2.py b/src/python_testing/TC_CCTRL_2_2.py index 8e7a8f1fde6ac3..87849e40443d01 100644 --- a/src/python_testing/TC_CCTRL_2_2.py +++ b/src/python_testing/TC_CCTRL_2_2.py @@ -141,7 +141,7 @@ async def test_TC_CCTRL_2_2(self): events = await self.default_controller.ReadEvent(nodeid=self.dut_node_id, events=event_path) self.step(5) - cmd = Clusters.CommissionerControl.Commands.CommissionNode(requestId=1, responseTimeoutSeconds=30) + cmd = Clusters.CommissionerControl.Commands.CommissionNode(requestID=1, responseTimeoutSeconds=30) try: await self.send_single_cmd(cmd) asserts.fail("Unexpected success on CommissionNode") @@ -162,7 +162,7 @@ async def test_TC_CCTRL_2_2(self): self.step(8) good_request_id = 0x1234567887654321 cmd = Clusters.CommissionerControl.Commands.RequestCommissioningApproval( - requestId=good_request_id, vendorId=th_server_vid, productId=th_server_pid) + requestID=good_request_id, vendorID=th_server_vid, productID=th_server_pid) try: await self.send_single_cmd(cmd=cmd, node_id=pase_nodeid) asserts.fail("Unexpected success on RequestCommissioningApproval over PASE") @@ -187,7 +187,7 @@ async def test_TC_CCTRL_2_2(self): not_th_server_vid = 0x6006 asserts.assert_not_equal(not_th_server_vid, th_server_vid, "Test implementation assumption incorrect") cmd = Clusters.CommissionerControl.Commands.RequestCommissioningApproval( - requestId=good_request_id, vendorId=not_th_server_vid, productId=th_server_pid) + requestID=good_request_id, vendorID=not_th_server_vid, productID=th_server_pid) # If no exception is raised, this is success await self.send_single_cmd(cmd) @@ -203,13 +203,13 @@ async def test_TC_CCTRL_2_2(self): new_event = await self.default_controller.ReadEvent(nodeid=self.dut_node_id, events=event_path, eventNumberFilter=max(event_nums)+1) asserts.assert_equal(len(new_event), 1, "Unexpected event list len") asserts.assert_equal(new_event[0].Data.statusCode, 0, "Unexpected status code") - asserts.assert_equal(new_event[0].Data.clientNodeId, + asserts.assert_equal(new_event[0].Data.clientNodeID, self.matter_test_config.controller_node_id, "Unexpected client node id") - asserts.assert_equal(new_event[0].Data.requestId, good_request_id, "Unexpected request ID") + asserts.assert_equal(new_event[0].Data.requestID, good_request_id, "Unexpected request ID") self.step(14) bad_request_id = 0x1234567887654322 - cmd = Clusters.CommissionerControl.Commands.CommissionNode(requestId=bad_request_id, responseTimeoutSeconds=30) + cmd = Clusters.CommissionerControl.Commands.CommissionNode(requestID=bad_request_id, responseTimeoutSeconds=30) try: await self.send_single_cmd(cmd=cmd) asserts.fail("Unexpected success on CommissionNode") @@ -217,7 +217,7 @@ async def test_TC_CCTRL_2_2(self): asserts.assert_equal(e.status, Status.Failure, "Incorrect error returned") self.step(15) - cmd = Clusters.CommissionerControl.Commands.CommissionNode(requestId=good_request_id, responseTimeoutSeconds=29) + cmd = Clusters.CommissionerControl.Commands.CommissionNode(requestID=good_request_id, responseTimeoutSeconds=29) try: await self.send_single_cmd(cmd=cmd) asserts.fail("Unexpected success on CommissionNode") @@ -225,7 +225,7 @@ async def test_TC_CCTRL_2_2(self): asserts.assert_equal(e.status, Status.ConstraintError, "Incorrect error returned") self.step(16) - cmd = Clusters.CommissionerControl.Commands.CommissionNode(requestId=good_request_id, responseTimeoutSeconds=121) + cmd = Clusters.CommissionerControl.Commands.CommissionNode(requestID=good_request_id, responseTimeoutSeconds=121) try: await self.send_single_cmd(cmd=cmd) asserts.fail("Unexpected success on CommissionNode") @@ -233,7 +233,7 @@ async def test_TC_CCTRL_2_2(self): asserts.assert_equal(e.status, Status.ConstraintError, "Incorrect error returned") self.step(17) - cmd = Clusters.CommissionerControl.Commands.CommissionNode(requestId=good_request_id, responseTimeoutSeconds=30) + cmd = Clusters.CommissionerControl.Commands.CommissionNode(requestID=good_request_id, responseTimeoutSeconds=30) resp: Clusters.CommissionerControl.Commands.ReverseOpenCommissioningWindow = await self.send_single_cmd(cmd) asserts.assert_equal(type(resp), Clusters.CommissionerControl.Commands.ReverseOpenCommissioningWindow, "Incorrect response type") @@ -263,7 +263,7 @@ async def test_TC_CCTRL_2_2(self): self.step(22) good_request_id = 0x1234567812345678 cmd = Clusters.CommissionerControl.Commands.RequestCommissioningApproval( - requestId=good_request_id, vendorId=th_server_vid, productId=th_server_pid, label="Test Ecosystem") + requestID=good_request_id, vendorID=th_server_vid, productID=th_server_pid, label="Test Ecosystem") await self.send_single_cmd(cmd) self.step(23) @@ -276,12 +276,12 @@ async def test_TC_CCTRL_2_2(self): new_event = await self.default_controller.ReadEvent(nodeid=self.dut_node_id, events=event_path, eventNumberFilter=max(event_nums)+1) asserts.assert_equal(len(new_event), 1, "Unexpected event list len") asserts.assert_equal(new_event[0].Data.statusCode, 0, "Unexpected status code") - asserts.assert_equal(new_event[0].Data.clientNodeId, + asserts.assert_equal(new_event[0].Data.clientNodeID, self.matter_test_config.controller_node_id, "Unexpected client node id") - asserts.assert_equal(new_event[0].Data.requestId, good_request_id, "Unexpected request ID") + asserts.assert_equal(new_event[0].Data.requestID, good_request_id, "Unexpected request ID") self.step(25) - cmd = Clusters.CommissionerControl.Commands.CommissionNode(requestId=good_request_id, responseTimeoutSeconds=30) + cmd = Clusters.CommissionerControl.Commands.CommissionNode(requestID=good_request_id, responseTimeoutSeconds=30) resp = await self.send_single_cmd(cmd) asserts.assert_equal(type(resp), Clusters.CommissionerControl.Commands.ReverseOpenCommissioningWindow, "Incorrect response type") diff --git a/src/python_testing/TC_CCTRL_2_3.py b/src/python_testing/TC_CCTRL_2_3.py index 224f283f46d27b..2c1c20e17f309f 100644 --- a/src/python_testing/TC_CCTRL_2_3.py +++ b/src/python_testing/TC_CCTRL_2_3.py @@ -34,7 +34,7 @@ from chip import ChipDeviceCtrl from chip.interaction_model import InteractionModelError, Status from matter_testing_support import (MatterBaseTest, TestStep, async_test_body, default_matter_test_main, has_cluster, - per_endpoint_test) + run_if_endpoint_matches) from mobly import asserts @@ -109,7 +109,7 @@ def steps_TC_CCTRL_2_3(self) -> list[TestStep]: def default_timeout(self) -> int: return 3*60 - @per_endpoint_test(has_cluster(Clusters.CommissionerControl)) + @run_if_endpoint_matches(has_cluster(Clusters.CommissionerControl)) async def test_TC_CCTRL_2_3(self): self.is_ci = self.check_pics('PICS_SDK_CI_ONLY') @@ -125,7 +125,7 @@ async def test_TC_CCTRL_2_3(self): self.step(4) good_request_id = 0x1234567812345678 cmd = Clusters.CommissionerControl.Commands.RequestCommissioningApproval( - requestId=good_request_id, vendorId=th_server_vid, productId=th_server_pid, label="Test Ecosystem") + requestID=good_request_id, vendorID=th_server_vid, productID=th_server_pid, label="Test Ecosystem") await self.send_single_cmd(cmd=cmd) self.step(5) @@ -137,13 +137,13 @@ async def test_TC_CCTRL_2_3(self): events = await self.default_controller.ReadEvent(nodeid=self.dut_node_id, events=event_path) asserts.assert_equal(len(events), 1, "Unexpected event list len") asserts.assert_equal(events[0].Data.statusCode, 0, "Unexpected status code") - asserts.assert_equal(events[0].Data.clientNodeId, + asserts.assert_equal(events[0].Data.clientNodeID, self.matter_test_config.controller_node_id, "Unexpected client node id") - asserts.assert_equal(events[0].Data.requestId, good_request_id, "Unexpected request ID") + asserts.assert_equal(events[0].Data.requestID, good_request_id, "Unexpected request ID") self.step(7) cmd = Clusters.CommissionerControl.Commands.RequestCommissioningApproval( - requestId=good_request_id, vendorId=th_server_vid, productId=th_server_pid) + requestID=good_request_id, vendorID=th_server_vid, productID=th_server_pid) try: await self.send_single_cmd(cmd=cmd) asserts.fail("Unexpected success on CommissionNode") @@ -151,13 +151,13 @@ async def test_TC_CCTRL_2_3(self): asserts.assert_equal(e.status, Status.Failure, "Incorrect error returned") self.step(8) - cmd = Clusters.CommissionerControl.Commands.CommissionNode(requestId=good_request_id, responseTimeoutSeconds=30) + cmd = Clusters.CommissionerControl.Commands.CommissionNode(requestID=good_request_id, responseTimeoutSeconds=30) resp = await self.send_single_cmd(cmd) asserts.assert_equal(type(resp), Clusters.CommissionerControl.Commands.ReverseOpenCommissioningWindow, "Incorrect response type") self.step(9) - cmd = Clusters.CommissionerControl.Commands.CommissionNode(requestId=good_request_id, responseTimeoutSeconds=30) + cmd = Clusters.CommissionerControl.Commands.CommissionNode(requestID=good_request_id, responseTimeoutSeconds=30) try: await self.send_single_cmd(cmd=cmd) asserts.fail("Unexpected success on CommissionNode") diff --git a/src/python_testing/TC_MCORE_FS_1_1.py b/src/python_testing/TC_MCORE_FS_1_1.py index e56a1fb8246b56..4ea9d362655884 100755 --- a/src/python_testing/TC_MCORE_FS_1_1.py +++ b/src/python_testing/TC_MCORE_FS_1_1.py @@ -111,7 +111,7 @@ async def test_TC_MCORE_FS_1_1(self): self.step("3a") good_request_id = 0x1234567812345678 cmd = Clusters.CommissionerControl.Commands.RequestCommissioningApproval( - requestId=good_request_id, vendorId=th_fsa_server_vid, productId=th_fsa_server_pid, label="Test Ecosystem") + requestID=good_request_id, vendorID=th_fsa_server_vid, productID=th_fsa_server_pid, label="Test Ecosystem") await self.send_single_cmd(cmd, endpoint=dut_commissioning_control_endpoint) if not self.is_ci: @@ -125,12 +125,12 @@ async def test_TC_MCORE_FS_1_1(self): asserts.assert_equal(len(new_event), 1, "Unexpected event list len") asserts.assert_equal(new_event[0].Data.statusCode, 0, "Unexpected status code") - asserts.assert_equal(new_event[0].Data.clientNodeId, + asserts.assert_equal(new_event[0].Data.clientNodeID, self.matter_test_config.controller_node_id, "Unexpected client node id") - asserts.assert_equal(new_event[0].Data.requestId, good_request_id, "Unexpected request ID") + asserts.assert_equal(new_event[0].Data.requestID, good_request_id, "Unexpected request ID") self.step("3b") - cmd = Clusters.CommissionerControl.Commands.CommissionNode(requestId=good_request_id, responseTimeoutSeconds=30) + cmd = Clusters.CommissionerControl.Commands.CommissionNode(requestID=good_request_id, responseTimeoutSeconds=30) resp = await self.send_single_cmd(cmd, endpoint=dut_commissioning_control_endpoint) asserts.assert_equal(type(resp), Clusters.CommissionerControl.Commands.ReverseOpenCommissioningWindow, "Incorrect response type") diff --git a/src/python_testing/TC_MCORE_FS_1_2.py b/src/python_testing/TC_MCORE_FS_1_2.py index 816abe5d876b00..b18dcc5b42ef64 100644 --- a/src/python_testing/TC_MCORE_FS_1_2.py +++ b/src/python_testing/TC_MCORE_FS_1_2.py @@ -63,10 +63,15 @@ class TC_MCORE_FS_1_2(MatterBaseTest): @async_test_body async def setup_class(self): super().setup_class() + self._partslist_subscription = None self._app_th_server_process = None self._th_server_kvs = None def teardown_class(self): + if self._partslist_subscription is not None: + self._partslist_subscription.Shutdown() + self._partslist_subscription = None + if self._app_th_server_process is not None: logging.warning("Stopping app with SIGTERM") self._app_th_server_process.send_signal(signal.SIGTERM.value) @@ -142,7 +147,7 @@ async def test_TC_MCORE_FS_1_2(self): subscription_contents = [ (root_endpoint, Clusters.Descriptor.Attributes.PartsList) ] - sub = await self.default_controller.ReadAttribute( + self._partslist_subscription = await self.default_controller.ReadAttribute( nodeid=self.dut_node_id, attributes=subscription_contents, reportInterval=(min_report_interval_sec, max_report_interval_sec), @@ -152,8 +157,8 @@ async def test_TC_MCORE_FS_1_2(self): parts_list_queue = queue.Queue() attribute_handler = AttributeChangeAccumulator( name=self.default_controller.name, expected_attribute=Clusters.Descriptor.Attributes.PartsList, output=parts_list_queue) - sub.SetAttributeUpdateCallback(attribute_handler) - cached_attributes = sub.GetAttributes() + self._partslist_subscription.SetAttributeUpdateCallback(attribute_handler) + cached_attributes = self._partslist_subscription.GetAttributes() step_1_dut_parts_list = cached_attributes[root_endpoint][Clusters.Descriptor][Clusters.Descriptor.Attributes.PartsList] asserts.assert_true(type_matches(step_1_dut_parts_list, list), "PartsList is expected to be a list") diff --git a/src/python_testing/TC_MCORE_FS_1_3.py b/src/python_testing/TC_MCORE_FS_1_3.py index 1a18896c055952..2a21c977c9fc8b 100644 --- a/src/python_testing/TC_MCORE_FS_1_3.py +++ b/src/python_testing/TC_MCORE_FS_1_3.py @@ -170,9 +170,9 @@ async def commission_via_commissioner_control(self, controller_node_id: int, dev await self.send_single_cmd( node_id=controller_node_id, cmd=Clusters.CommissionerControl.Commands.RequestCommissioningApproval( - requestId=request_id, - vendorId=vendor_id, - productId=product_id, + requestID=request_id, + vendorID=vendor_id, + productID=product_id, ), ) @@ -182,7 +182,7 @@ async def commission_via_commissioner_control(self, controller_node_id: int, dev resp = await self.send_single_cmd( node_id=controller_node_id, cmd=Clusters.CommissionerControl.Commands.CommissionNode( - requestId=request_id, + requestID=request_id, responseTimeoutSeconds=30, ), ) diff --git a/src/python_testing/TC_MCORE_FS_1_5.py b/src/python_testing/TC_MCORE_FS_1_5.py index df80072d5126e3..22654c994bf41f 100755 --- a/src/python_testing/TC_MCORE_FS_1_5.py +++ b/src/python_testing/TC_MCORE_FS_1_5.py @@ -61,10 +61,20 @@ class TC_MCORE_FS_1_5(MatterBaseTest): @async_test_body async def setup_class(self): super().setup_class() + self._partslist_subscription = None + self._cadmin_subscription = None self._app_th_server_process = None self._th_server_kvs = None def teardown_class(self): + if self._partslist_subscription is not None: + self._partslist_subscription.Shutdown() + self._partslist_subscription = None + + if self._cadmin_subscription is not None: + self._cadmin_subscription.Shutdown() + self._cadmin_subscription = None + if self._app_th_server_process is not None: logging.warning("Stopping app with SIGTERM") self._app_th_server_process.send_signal(signal.SIGTERM.value) @@ -142,7 +152,7 @@ async def test_TC_MCORE_FS_1_5(self): parts_list_subscription_contents = [ (root_endpoint, Clusters.Descriptor.Attributes.PartsList) ] - parts_list_sub = await self.default_controller.ReadAttribute( + self._partslist_subscription = await self.default_controller.ReadAttribute( nodeid=self.dut_node_id, attributes=parts_list_subscription_contents, reportInterval=(min_report_interval_sec, max_report_interval_sec), @@ -152,8 +162,8 @@ async def test_TC_MCORE_FS_1_5(self): parts_list_queue = queue.Queue() parts_list_attribute_handler = AttributeChangeAccumulator( name=self.default_controller.name, expected_attribute=Clusters.Descriptor.Attributes.PartsList, output=parts_list_queue) - parts_list_sub.SetAttributeUpdateCallback(parts_list_attribute_handler) - parts_list_cached_attributes = parts_list_sub.GetAttributes() + self._partslist_subscription.SetAttributeUpdateCallback(parts_list_attribute_handler) + parts_list_cached_attributes = self._partslist_subscription.GetAttributes() step_1_dut_parts_list = parts_list_cached_attributes[root_endpoint][Clusters.Descriptor][Clusters.Descriptor.Attributes.PartsList] asserts.assert_true(type_matches(step_1_dut_parts_list, list), "PartsList is expected to be a list") @@ -219,7 +229,7 @@ async def test_TC_MCORE_FS_1_5(self): cadmin_subscription_contents = [ (newly_added_endpoint, Clusters.AdministratorCommissioning) ] - cadmin_sub = await self.default_controller.ReadAttribute( + self._cadmin_subscription = await self.default_controller.ReadAttribute( nodeid=self.dut_node_id, attributes=cadmin_subscription_contents, reportInterval=(min_report_interval_sec, max_report_interval_sec), @@ -230,7 +240,7 @@ async def test_TC_MCORE_FS_1_5(self): # This AttributeChangeAccumulator is really just to let us know when new subscription came in cadmin_attribute_handler = AttributeChangeAccumulator( name=self.default_controller.name, expected_attribute=Clusters.AdministratorCommissioning.Attributes.WindowStatus, output=cadmin_queue) - cadmin_sub.SetAttributeUpdateCallback(cadmin_attribute_handler) + self._cadmin_subscription.SetAttributeUpdateCallback(cadmin_attribute_handler) time.sleep(1) self.step(7) diff --git a/src/python_testing/TC_SEAR_1_2.py b/src/python_testing/TC_SEAR_1_2.py index 2c253efa860038..1bed2c8d12cac8 100644 --- a/src/python_testing/TC_SEAR_1_2.py +++ b/src/python_testing/TC_SEAR_1_2.py @@ -180,12 +180,12 @@ async def read_and_validate_progress(self, step): progareaid_list.append(p.areaID) asserts.assert_true(p.areaID in self.areaid_list, f"Progress entry has invalid AreaID value ({p.areaID})") - asserts.assert_true(p.status in (Clusters.ServiceArea.OperationalStatusEnum.kPending, - Clusters.ServiceArea.OperationalStatusEnum.kOperating, - Clusters.ServiceArea.OperationalStatusEnum.kSkipped, - Clusters.ServiceArea.OperationalStatusEnum.kCompleted), + asserts.assert_true(p.status in (Clusters.ServiceArea.Enums.OperationalStatusEnum.kPending, + Clusters.ServiceArea.Enums.OperationalStatusEnum.kOperating, + Clusters.ServiceArea.Enums.OperationalStatusEnum.kSkipped, + Clusters.ServiceArea.Enums.OperationalStatusEnum.kCompleted), f"Progress entry has invalid Status value ({p.status})") - if p.status not in (Clusters.ServiceArea.OperationalStatusEnum.kSkipped, Clusters.ServiceArea.OperationalStatusEnum.kCompleted): + if p.status not in (Clusters.ServiceArea.Enums.OperationalStatusEnum.kSkipped, Clusters.ServiceArea.Enums.OperationalStatusEnum.kCompleted): asserts.assert_true(p.totalOperationalTime is NullValue, f"Progress entry should have a null TotalOperationalTime value (Status is {p.status})") # TODO how to check that InitialTimeEstimate is either null or uint32? diff --git a/src/python_testing/test_testing/test_TC_CCNTL_2_2.py b/src/python_testing/test_testing/test_TC_CCNTL_2_2.py index d528b5652e1b45..bd28023b8e32e8 100644 --- a/src/python_testing/test_testing/test_TC_CCNTL_2_2.py +++ b/src/python_testing/test_testing/test_TC_CCNTL_2_2.py @@ -94,14 +94,14 @@ def dynamic_event_return(*args, **argv): header = Attribute.EventHeader(EndpointId=0, ClusterId=Clusters.CommissionerControl.id, EventId=Clusters.CommissionerControl.Events.CommissioningRequestResult.event_id, EventNumber=1) data = Clusters.CommissionerControl.Events.CommissioningRequestResult( - requestId=0x1234567887654321, clientNodeId=112233, statusCode=0) + requestID=0x1234567887654321, clientNodeID=112233, statusCode=0) result = Attribute.EventReadResult(Header=header, Status=Status.Success, Data=data) return [result] elif event_call_count == 4: # returned event with new request header = Attribute.EventHeader(EndpointId=0, ClusterId=Clusters.CommissionerControl.id, EventId=Clusters.CommissionerControl.Events.CommissioningRequestResult.event_id, EventNumber=1) data = Clusters.CommissionerControl.Events.CommissioningRequestResult( - requestId=0x1234567812345678, clientNodeId=112233, statusCode=0) + requestID=0x1234567812345678, clientNodeID=112233, statusCode=0) result = Attribute.EventReadResult(Header=header, Status=Status.Success, Data=data) return [result] else: diff --git a/src/python_testing/test_testing/test_TC_MCORE_FS_1_1.py b/src/python_testing/test_testing/test_TC_MCORE_FS_1_1.py index 5b2e29b71915b1..d79b4125309e11 100644 --- a/src/python_testing/test_testing/test_TC_MCORE_FS_1_1.py +++ b/src/python_testing/test_testing/test_TC_MCORE_FS_1_1.py @@ -72,7 +72,7 @@ def dynamic_event_return(*args, **argv): header = Attribute.EventHeader(EndpointId=0, ClusterId=Clusters.CommissionerControl.id, EventId=Clusters.CommissionerControl.Events.CommissioningRequestResult.event_id, EventNumber=1) data = Clusters.CommissionerControl.Events.CommissioningRequestResult( - requestId=0x1234567812345678, clientNodeId=112233, statusCode=0) + requestID=0x1234567812345678, clientNodeID=112233, statusCode=0) result = Attribute.EventReadResult(Header=header, Status=Status.Success, Data=data) return [result] else: diff --git a/src/tracing/tracing_args.gni b/src/tracing/tracing_args.gni index d6ddb1fd2e99b8..085844e4a53605 100644 --- a/src/tracing/tracing_args.gni +++ b/src/tracing/tracing_args.gni @@ -11,9 +11,8 @@ # 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. -import("//build_overrides/build.gni") import("//build_overrides/chip.gni") -import("${build_root}/config/compiler/compiler.gni") +import("${chip_root}/config/recommended.gni") import("${chip_root}/src/platform/device.gni") declare_args() { @@ -24,7 +23,8 @@ declare_args() { # Additionally, if tracing is enabled, the main() function has to add # backends explicitly matter_enable_tracing_support = - current_os == "android" || chip_device_platform == "darwin" + matter_enable_recommended && + (current_os == "android" || chip_device_platform == "darwin") # Defines the trace backend. Current matter tracing splits the logic # into two parts: diff --git a/third_party/silabs/SiWx917_sdk.gni b/third_party/silabs/SiWx917_sdk.gni index 30e1595493c60c..e91afe7483b3fa 100644 --- a/third_party/silabs/SiWx917_sdk.gni +++ b/third_party/silabs/SiWx917_sdk.gni @@ -187,7 +187,7 @@ template("siwx917_sdk") { # 1->SOC and 0->NCP "RSI_WLAN_API_ENABLE", "NVM3_DEFAULT_NVM_SIZE=40960", - "NVM3_DEFAULT_MAX_OBJECT_SIZE=4092", + "NVM3_DEFAULT_MAX_OBJECT_SIZE=${sl_nvm3_max_object_size}", "KVS_MAX_ENTRIES=${kvs_max_entries}", "${silabs_mcu}=1", "${silabs_board}=1", diff --git a/third_party/silabs/efr32_sdk.gni b/third_party/silabs/efr32_sdk.gni index 1cd69d31e7084b..3f30a0ca52f867 100644 --- a/third_party/silabs/efr32_sdk.gni +++ b/third_party/silabs/efr32_sdk.gni @@ -38,6 +38,7 @@ declare_args() { # enable by default for thread/non-wifi-ncp builds enable_openthread_cli = !(use_rs9116 || use_wf200 || use_SiWx917) kvs_max_entries = 255 + sl_nvm3_max_object_size = 4092 # Use Silabs factory data provider example. # Users can implement their own. @@ -421,7 +422,7 @@ template("efr32_sdk") { "HARD_FAULT_LOG_ENABLE", "CORTEXM3_EFM32_MICRO", "NVM3_DEFAULT_NVM_SIZE=40960", - "NVM3_DEFAULT_MAX_OBJECT_SIZE=4092", + "NVM3_DEFAULT_MAX_OBJECT_SIZE=${sl_nvm3_max_object_size}", "KVS_MAX_ENTRIES=${kvs_max_entries}", "CORTEXM3=1", "MICRO=EMBER_MICRO_CORTEXM3_EFR32", diff --git a/zzz_generated/chip-tool/zap-generated/cluster/logging/DataModelLogger.cpp b/zzz_generated/chip-tool/zap-generated/cluster/logging/DataModelLogger.cpp index 2d788bd2613215..8def02781d4b9a 100644 --- a/zzz_generated/chip-tool/zap-generated/cluster/logging/DataModelLogger.cpp +++ b/zzz_generated/chip-tool/zap-generated/cluster/logging/DataModelLogger.cpp @@ -18,6 +18,7 @@ // THIS FILE IS GENERATED BY ZAP #include +#include using namespace chip::app::Clusters; @@ -273,12 +274,8 @@ CHIP_ERROR DataModelLogger::LogValue(const char * label, size_t indent, { DataModelLogger::LogString(label, indent, "{"); { - CHIP_ERROR err = LogValue("DeviceType", indent + 1, value.deviceType); - if (err != CHIP_NO_ERROR) - { - DataModelLogger::LogString(indent + 1, "Struct truncated due to invalid value for 'DeviceType'"); - return err; - } + std::string item = std::to_string(value.deviceType) + " (" + DeviceTypeIdToText(value.deviceType) + ")"; + DataModelLogger::LogString("DeviceType", indent + 1, item); } { CHIP_ERROR err = LogValue("Revision", indent + 1, value.revision); @@ -641,11 +638,19 @@ DataModelLogger::LogValue(const char * label, size_t indent, } } { - CHIP_ERROR err = LogValue("DeviceType", indent + 1, value.deviceType); - if (err != CHIP_NO_ERROR) + if (value.deviceType.IsNull()) { - DataModelLogger::LogString(indent + 1, "Struct truncated due to invalid value for 'DeviceType'"); - return err; + CHIP_ERROR err = LogValue("DeviceType", indent + 1, value.deviceType); + if (err != CHIP_NO_ERROR) + { + DataModelLogger::LogString(indent + 1, "Struct truncated due to invalid value for 'DeviceType'"); + return err; + } + } + else + { + std::string item = std::to_string(value.deviceType.Value()) + " (" + DeviceTypeIdToText(value.deviceType.Value()) + ")"; + DataModelLogger::LogString("DeviceType", indent + 1, item); } } DataModelLogger::LogString(indent, "}"); diff --git a/zzz_generated/chip-tool/zap-generated/cluster/logging/EntryToText.cpp b/zzz_generated/chip-tool/zap-generated/cluster/logging/EntryToText.cpp index 07bac4319c7c61..8f320e64e682b8 100644 --- a/zzz_generated/chip-tool/zap-generated/cluster/logging/EntryToText.cpp +++ b/zzz_generated/chip-tool/zap-generated/cluster/logging/EntryToText.cpp @@ -6700,3 +6700,146 @@ char const * GeneratedCommandIdToText(chip::ClusterId cluster, chip::CommandId i return "Unknown"; } } + +char const * DeviceTypeIdToText(chip::DeviceTypeId id) +{ + switch (id) + { + case 0x0000000A: + return "Matter Door Lock"; + case 0x0000000B: + return "Matter Door Lock Controller"; + case 0x0000000E: + return "Matter Aggregator"; + case 0x0000000F: + return "Matter Generic Switch"; + case 0x00000011: + return "Matter Power Source"; + case 0x00000012: + return "Matter OTA Requestor"; + case 0x00000013: + return "Matter Bridged Device"; + case 0x00000014: + return "Matter OTA Provider"; + case 0x00000015: + return "Matter Contact Sensor"; + case 0x00000016: + return "Matter Root Node"; + case 0x00000019: + return "Matter Secondary Network Interface Device Type"; + case 0x00000022: + return "Matter Speaker"; + case 0x00000023: + return "Matter Casting Video Player"; + case 0x00000024: + return "Matter Content App"; + case 0x00000027: + return "Matter Mode Select"; + case 0x00000028: + return "Matter Basic Video Player"; + case 0x00000029: + return "Matter Casting Video Client"; + case 0x0000002A: + return "Matter Video Remote Control"; + case 0x0000002B: + return "Matter Fan"; + case 0x0000002C: + return "Matter Air Quality Sensor"; + case 0x0000002D: + return "Matter Air Purifier"; + case 0x00000041: + return "Matter Water Freeze Detector"; + case 0x00000042: + return "Matter Water Valve"; + case 0x00000043: + return "Matter Water Leak Detector"; + case 0x00000044: + return "Matter Rain Sensor"; + case 0x00000070: + return "Matter Refrigerator"; + case 0x00000071: + return "Matter Temperature Controlled Cabinet"; + case 0x00000072: + return "Matter Room Air Conditioner"; + case 0x00000073: + return "Matter Laundry Washer"; + case 0x00000074: + return "Matter Robotic Vacuum Cleaner"; + case 0x00000075: + return "Matter Dishwasher"; + case 0x00000076: + return "Matter Smoke CO Alarm"; + case 0x00000077: + return "Matter Cook Surface"; + case 0x00000078: + return "Matter Cooktop"; + case 0x00000079: + return "Matter Microwave Oven"; + case 0x0000007A: + return "Matter Extractor Hood"; + case 0x0000007B: + return "Matter Oven"; + case 0x0000007C: + return "Matter Laundry Dryer"; + case 0x00000090: + return "Matter Network Infrastructure Manager"; + case 0x00000091: + return "Matter Thread Border Router"; + case 0x00000100: + return "Matter On/Off Light"; + case 0x00000101: + return "Matter Dimmable Light"; + case 0x00000103: + return "Matter On/Off Light Switch"; + case 0x00000104: + return "Matter Dimmer Switch"; + case 0x00000105: + return "Matter Color Dimmer Switch"; + case 0x00000106: + return "Matter Light Sensor"; + case 0x00000107: + return "Matter Occupancy Sensor"; + case 0x0000010A: + return "Matter On/Off Plug-in Unit"; + case 0x0000010B: + return "Matter Dimmable Plug-in Unit"; + case 0x0000010C: + return "Matter Color Temperature Light"; + case 0x0000010D: + return "Matter Extended Color Light"; + case 0x00000202: + return "Matter Window Covering"; + case 0x00000203: + return "Matter Window Covering Controller"; + case 0x00000300: + return "Matter Heating/Cooling Unit"; + case 0x00000301: + return "Matter Thermostat"; + case 0x00000302: + return "Matter Temperature Sensor"; + case 0x00000303: + return "Matter Pump"; + case 0x00000304: + return "Matter Pump Controller"; + case 0x00000305: + return "Matter Pressure Sensor"; + case 0x00000306: + return "Matter Flow Sensor"; + case 0x00000307: + return "Matter Humidity Sensor"; + case 0x0000050C: + return "Matter EVSE"; + case 0x00000510: + return "Matter Electrical Sensor"; + case 0x00000840: + return "Matter Control Bridge"; + case 0x00000850: + return "Matter On/Off Sensor"; + case 0xFFF10001: + return "Matter Orphan Clusters"; + case 0xFFF10003: + return "Matter All-clusters-app Server Example"; + default: + return "Unknown"; + } +} diff --git a/zzz_generated/chip-tool/zap-generated/cluster/logging/EntryToText.h b/zzz_generated/chip-tool/zap-generated/cluster/logging/EntryToText.h index 27fa6512fbdd01..f65ab6e45f549a 100644 --- a/zzz_generated/chip-tool/zap-generated/cluster/logging/EntryToText.h +++ b/zzz_generated/chip-tool/zap-generated/cluster/logging/EntryToText.h @@ -28,3 +28,5 @@ char const * AttributeIdToText(chip::ClusterId cluster, chip::AttributeId id); char const * AcceptedCommandIdToText(chip::ClusterId cluster, chip::CommandId id); char const * GeneratedCommandIdToText(chip::ClusterId cluster, chip::CommandId id); + +char const * DeviceTypeIdToText(chip::DeviceTypeId id);