From 6f81854069a618c958a309daa6f7aa7fcc3dd803 Mon Sep 17 00:00:00 2001 From: Mathieu Kardous Date: Wed, 27 Nov 2024 20:48:50 -0500 Subject: [PATCH 1/9] Rename WifiEvent to WifiPlatformEvent --- .../silabs/wifi/SiWx/WifiInterface.cpp | 56 +++++++++---------- .../silabs/wifi/WifiInterfaceAbstraction.h | 26 ++++----- .../silabs/wifi/rs911x/WifiInterface.cpp | 44 +++++++-------- .../WiseconnectInterfaceAbstraction.cpp | 4 +- .../WiseconnectInterfaceAbstraction.h | 2 +- 5 files changed, 63 insertions(+), 69 deletions(-) diff --git a/src/platform/silabs/wifi/SiWx/WifiInterface.cpp b/src/platform/silabs/wifi/SiWx/WifiInterface.cpp index 291c9988d83215..0399502e06a37b 100644 --- a/src/platform/silabs/wifi/SiWx/WifiInterface.cpp +++ b/src/platform/silabs/wifi/SiWx/WifiInterface.cpp @@ -196,7 +196,7 @@ constexpr uint16_t kWifiScanTimeoutTicks = 10000; void DHCPTimerEventHandler(void * arg) { - WifiEvent event = WifiEvent::kStationDhcpPoll; + WifiPlatformEvent event = WifiPlatformEvent::kStationDhcpPoll; sl_matter_wifi_post_event(event); } @@ -410,7 +410,7 @@ sl_status_t JoinWifiNetwork(void) if (status == SL_STATUS_OK || status == SL_STATUS_IN_PROGRESS) { - WifiEvent event = WifiEvent::kStationConnect; + WifiPlatformEvent event = WifiPlatformEvent::kStationConnect; sl_matter_wifi_post_event(event); return status; } @@ -424,7 +424,7 @@ sl_status_t JoinWifiNetwork(void) ChipLogProgress(DeviceLayer, "Connection retry attempt %d", wfx_rsi.join_retries); wfx_retry_connection(++wfx_rsi.join_retries); - WifiEvent event = WifiEvent::kStationStartJoin; + WifiPlatformEvent event = WifiPlatformEvent::kStationStartJoin; sl_matter_wifi_post_event(event); return status; @@ -453,7 +453,7 @@ sl_status_t sl_matter_wifi_platform_init(void) VerifyOrReturnError(sScanCompleteSemaphore != nullptr, SL_STATUS_ALLOCATION_FAILED); // Create the message queue - sWifiEventQueue = osMessageQueueNew(kWfxQueueSize, sizeof(WifiEvent), nullptr); + sWifiEventQueue = osMessageQueueNew(kWfxQueueSize, sizeof(WifiPlatformEvent), nullptr); VerifyOrReturnError(sWifiEventQueue != nullptr, SL_STATUS_ALLOCATION_FAILED); // Create timer for DHCP polling @@ -612,7 +612,7 @@ void NotifyConnectivity(void) void HandleDHCPPolling(void) { - WifiEvent event; + WifiPlatformEvent event; // TODO: Notify the application that the interface is not set up or Chipdie here because we are in an unkonwn state struct netif * sta_netif = &wifi_client_context.netif; @@ -624,7 +624,7 @@ void HandleDHCPPolling(void) { wfx_dhcp_got_ipv4((uint32_t) sta_netif->ip_addr.u_addr.ip4.addr); hasNotifiedIPV4 = true; - event = WifiEvent::kStationDhcpDone; + event = WifiPlatformEvent::kStationDhcpDone; sl_matter_wifi_post_event(event); NotifyConnectivity(); } @@ -644,12 +644,12 @@ void HandleDHCPPolling(void) ChipLogProgress(DeviceLayer, "SLAAC OK: linklocal addr: %s", addrStr); wfx_ipv6_notify(GET_IPV6_SUCCESS); hasNotifiedIPV6 = true; - event = WifiEvent::kStationDhcpDone; + event = WifiPlatformEvent::kStationDhcpDone; sl_matter_wifi_post_event(event); NotifyConnectivity(); } } -void sl_matter_wifi_post_event(WifiEvent event) +void sl_matter_wifi_post_event(WifiPlatformEvent event) { sl_status_t status = osMessageQueuePut(sWifiEventQueue, &event, 0, 0); @@ -662,7 +662,7 @@ void sl_matter_wifi_post_event(WifiEvent event) } /// ResetDHCPNotificationFlags /// @brief Reset the flags that are used to notify the application about DHCP connectivity -/// and emits a WifiEvent::kStationDoDhcp event to trigger DHCP polling checks. Helper function for ProcessEvent. +/// and emits a WifiPlatformEvent::kStationDoDhcp event to trigger DHCP polling checks. Helper function for ProcessEvent. void ResetDHCPNotificationFlags(void) { @@ -672,23 +672,23 @@ void ResetDHCPNotificationFlags(void) hasNotifiedIPV6 = false; hasNotifiedWifiConnectivity = false; - WifiEvent event = WifiEvent::kStationDoDhcp; + WifiPlatformEvent event = WifiPlatformEvent::kStationDoDhcp; sl_matter_wifi_post_event(event); } -void ProcessEvent(WifiEvent event) +void ProcessEvent(WifiPlatformEvent event) { // Process event switch (event) { - case WifiEvent::kStationConnect: - ChipLogDetail(DeviceLayer, "WifiEvent::kStationConnect"); + case WifiPlatformEvent::kStationConnect: + ChipLogDetail(DeviceLayer, "WifiPlatformEvent::kStationConnect"); wfx_rsi.dev_state.Set(WifiState::kStationConnected); ResetDHCPNotificationFlags(); break; - case WifiEvent::kStationDisconnect: { - ChipLogDetail(DeviceLayer, "WifiEvent::kStationDisconnect"); + case WifiPlatformEvent::kStationDisconnect: { + ChipLogDetail(DeviceLayer, "WifiPlatformEvent::kStationDisconnect"); // TODO: This event is not being posted anywhere, seems to be a dead code or we are missing something wfx_rsi.dev_state.Clear(WifiState::kStationReady) @@ -706,17 +706,17 @@ void ProcessEvent(WifiEvent event) } break; - case WifiEvent::kAPStart: + case WifiPlatformEvent::kAPStart: // TODO: Currently unimplemented break; - case WifiEvent::kScan: - ChipLogDetail(DeviceLayer, "WifiEvent::kScan"); + case WifiPlatformEvent::kScan: + ChipLogDetail(DeviceLayer, "WifiPlatformEvent::kScan"); #ifdef SL_WFX_CONFIG_SCAN if (!(wfx_rsi.dev_state.Has(WifiState::kScanStarted))) { - ChipLogDetail(DeviceLayer, "WifiEvent::kScan"); + ChipLogDetail(DeviceLayer, "WifiPlatformEvent::kScan"); sl_wifi_scan_configuration_t wifi_scan_configuration; memset(&wifi_scan_configuration, 0, sizeof(wifi_scan_configuration)); @@ -761,25 +761,25 @@ void ProcessEvent(WifiEvent event) #endif /* SL_WFX_CONFIG_SCAN */ break; - case WifiEvent::kStationStartJoin: - ChipLogDetail(DeviceLayer, "WifiEvent::kStationStartJoin"); + case WifiPlatformEvent::kStationStartJoin: + ChipLogDetail(DeviceLayer, "WifiPlatformEvent::kStationStartJoin"); InitiateScan(); JoinWifiNetwork(); break; - case WifiEvent::kStationDoDhcp: - ChipLogDetail(DeviceLayer, "WifiEvent::kStationDoDhcp"); + case WifiPlatformEvent::kStationDoDhcp: + ChipLogDetail(DeviceLayer, "WifiPlatformEvent::kStationDoDhcp"); StartDHCPTimer(WFX_RSI_DHCP_POLL_INTERVAL); break; - case WifiEvent::kStationDhcpDone: - ChipLogDetail(DeviceLayer, "WifiEvent::kStationDhcpDone"); + case WifiPlatformEvent::kStationDhcpDone: + ChipLogDetail(DeviceLayer, "WifiPlatformEvent::kStationDhcpDone"); CancelDHCPTimer(); break; - case WifiEvent::kStationDhcpPoll: - ChipLogDetail(DeviceLayer, "WifiEvent::kStationDhcpPoll"); + case WifiPlatformEvent::kStationDhcpPoll: + ChipLogDetail(DeviceLayer, "WifiPlatformEvent::kStationDhcpPoll"); HandleDHCPPolling(); break; @@ -802,7 +802,7 @@ void ProcessEvent(WifiEvent event) void sl_matter_wifi_task(void * arg) { (void) arg; - WifiEvent event; + WifiPlatformEvent event; sl_status_t status = SL_STATUS_OK; status = sl_wifi_siwx917_init(); diff --git a/src/platform/silabs/wifi/WifiInterfaceAbstraction.h b/src/platform/silabs/wifi/WifiInterfaceAbstraction.h index 012683aef60333..b676e30c6bc692 100644 --- a/src/platform/silabs/wifi/WifiInterfaceAbstraction.h +++ b/src/platform/silabs/wifi/WifiInterfaceAbstraction.h @@ -81,25 +81,19 @@ enum class WifiState : uint16_t kScanStarted = (1 << 10), /* Scan Started */ }; -enum class WifiEvent : uint8_t +enum class WifiPlatformEvent : uint8_t { - kStationConnect = 0, - kStationDisconnect = 1, - kAPStart = 2, - kAPStop = 3, - kScan = 4, /* This is used as scan result and start */ - kStationStartJoin = 5, - kStationDoDhcp = 6, - kStationDhcpDone = 7, - kStationDhcpPoll = 8 + kStationConnect = 1, + kStationDisconnect = 2, + kAPStart = 3, + kAPStop = 4, + kScan = 5, /* This is used as scan result and start */ + kStationStartJoin = 6, + kStationDoDhcp = 7, + kStationDhcpDone = 8, + kStationDhcpPoll = 9, }; -typedef enum -{ - WIFI_EVENT, - IP_EVENT, -} wfx_event_base_t; - /* Note that these are same as RSI_security */ typedef enum { diff --git a/src/platform/silabs/wifi/rs911x/WifiInterface.cpp b/src/platform/silabs/wifi/rs911x/WifiInterface.cpp index 8b811534ca3e20..0ea835a1089c09 100644 --- a/src/platform/silabs/wifi/rs911x/WifiInterface.cpp +++ b/src/platform/silabs/wifi/rs911x/WifiInterface.cpp @@ -104,7 +104,7 @@ static void rsi_wireless_driver_task_wrapper(void * argument) static void DHCPTimerEventHandler(void * arg) { - WifiEvent event = WifiEvent::kStationDhcpPoll; + WifiPlatformEvent event = WifiPlatformEvent::kStationDhcpPoll; sl_matter_wifi_post_event(event); } @@ -262,7 +262,7 @@ static void wfx_rsi_join_cb(uint16_t status, const uint8_t * buf, const uint16_t */ ChipLogProgress(DeviceLayer, "wfx_rsi_join_cb: success"); memset(&temp_reset, 0, sizeof(wfx_wifi_scan_ext_t)); - WifiEvent event = WifiEvent::kStationConnect; + WifiPlatformEvent event = WifiPlatformEvent::kStationConnect; sl_matter_wifi_post_event(event); wfx_rsi.join_retries = 0; } @@ -284,7 +284,7 @@ static void wfx_rsi_join_fail_cb(uint16_t status, uint8_t * buf, uint32_t len) wfx_rsi.dev_state.Clear(WifiState::kStationConnecting).Clear(WifiState::kStationConnected); - WifiEvent event = WifiEvent::kStationStartJoin; + WifiPlatformEvent event = WifiPlatformEvent::kStationStartJoin; sl_matter_wifi_post_event(event); } /************************************************************************************* @@ -385,7 +385,7 @@ static int32_t sl_matter_wifi_init(void) 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(WifiEvent), NULL); + sWifiEventQueue = osMessageQueueNew(WFX_QUEUE_SIZE, sizeof(WifiPlatformEvent), NULL); if (sWifiEventQueue == NULL) { return SL_STATUS_ALLOCATION_FAILED; @@ -600,8 +600,8 @@ void HandleDHCPPolling(void) if ((ip6_addr_ispreferred(netif_ip6_addr_state(sta_netif, 0))) && !hasNotifiedIPV6) { wfx_ipv6_notify(GET_IPV6_SUCCESS); - hasNotifiedIPV6 = true; - WifiEvent event = WifiEvent::kStationDhcpDone; + hasNotifiedIPV6 = true; + WifiPlatformEvent event = WifiPlatformEvent::kStationDhcpDone; sl_matter_wifi_post_event(event); NotifyConnectivity(); } @@ -609,11 +609,11 @@ void HandleDHCPPolling(void) /** ResetDHCPNotificationFlags * @brief Reset the flags that are used to notify the application about DHCP connectivity - * and emits a WifiEvent::kStationDoDhcp event to trigger DHCP polling checks. Helper function for ProcessEvent. + * and emits a WifiPlatformEvent::kStationDoDhcp event to trigger DHCP polling checks. Helper function for ProcessEvent. */ void ResetDHCPNotificationFlags(void) { - WifiEvent outEvent; + WifiPlatformEvent outEvent; #if (CHIP_DEVICE_CONFIG_ENABLE_IPV4) hasNotifiedIPV4 = false; @@ -621,11 +621,11 @@ void ResetDHCPNotificationFlags(void) hasNotifiedIPV6 = false; hasNotifiedWifiConnectivity = false; - outEvent = WifiEvent::kStationDoDhcp; + outEvent = WifiPlatformEvent::kStationDoDhcp; sl_matter_wifi_post_event(outEvent); } -void sl_matter_wifi_post_event(WifiEvent event) +void sl_matter_wifi_post_event(WifiPlatformEvent event) { sl_status_t status = osMessageQueuePut(sWifiEventQueue, &event, 0, 0); @@ -645,13 +645,13 @@ void sl_matter_wifi_post_event(WifiEvent event) * * @param event The input Wi-Fi event to be processed. */ -void ProcessEvent(WifiEvent event) +void ProcessEvent(WifiPlatformEvent event) { // Process event switch (event) { - case WifiEvent::kStationConnect: { - ChipLogDetail(DeviceLayer, "WifiEvent::kStationConnect"); + case WifiPlatformEvent::kStationConnect: { + ChipLogDetail(DeviceLayer, "WifiPlatformEvent::kStationConnect"); wfx_rsi.dev_state.Set(WifiState::kStationConnected); ResetDHCPNotificationFlags(); wfx_lwip_set_sta_link_up(); @@ -662,8 +662,8 @@ void ProcessEvent(WifiEvent event) // is independant of IP connectivity. } break; - case WifiEvent::kStationDisconnect: { - ChipLogDetail(DeviceLayer, "WifiEvent::kStationDisconnect"); + case WifiPlatformEvent::kStationDisconnect: { + ChipLogDetail(DeviceLayer, "WifiPlatformEvent::kStationDisconnect"); // TODO: This event is not being posted anywhere, seems to be a dead code or we are missing something WifiStateFlags flagsToClear = WifiStateFlags(WifiState::kStationReady, WifiState::kStationConnecting, WifiState::kStationConnected, WifiState::kStationDhcpDone); @@ -678,10 +678,10 @@ void ProcessEvent(WifiEvent event) wfx_ipv6_notify(GET_IPV6_FAIL); } break; - case WifiEvent::kAPStart: + case WifiPlatformEvent::kAPStart: // TODO: Currently unimplemented break; - case WifiEvent::kScan: { + case WifiPlatformEvent::kScan: { #ifdef SL_WFX_CONFIG_SCAN rsi_rsp_scan_t scan_rsp = { 0 }; memset(&scan_rsp, 0, sizeof(scan_rsp)); @@ -746,22 +746,22 @@ void ProcessEvent(WifiEvent event) #endif /* SL_WFX_CONFIG_SCAN */ } break; - case WifiEvent::kStationStartJoin: { + case WifiPlatformEvent::kStationStartJoin: { // saving the AP related info wfx_rsi_save_ap_info(); // Joining to the network sl_wifi_platform_join_network(); } break; - case WifiEvent::kStationDoDhcp: { + case WifiPlatformEvent::kStationDoDhcp: { StartDHCPTimer(WFX_RSI_DHCP_POLL_INTERVAL); } break; - case WifiEvent::kStationDhcpDone: { + case WifiPlatformEvent::kStationDhcpDone: { CancelDHCPTimer(); } break; - case WifiEvent::kStationDhcpPoll: { + case WifiPlatformEvent::kStationDhcpPoll: { HandleDHCPPolling(); } break; @@ -790,7 +790,7 @@ void sl_matter_wifi_task(void * arg) ChipLogError(DeviceLayer, "sl_matter_wifi_task: sl_matter_wifi_init failed: %ld", rsi_status); return; } - WifiEvent event; + WifiPlatformEvent event; sl_matter_lwip_start(); sl_matter_wifi_task_started(); diff --git a/src/platform/silabs/wifi/wiseconnect-abstraction/WiseconnectInterfaceAbstraction.cpp b/src/platform/silabs/wifi/wiseconnect-abstraction/WiseconnectInterfaceAbstraction.cpp index 2266989b906f79..25a073895972fd 100644 --- a/src/platform/silabs/wifi/wiseconnect-abstraction/WiseconnectInterfaceAbstraction.cpp +++ b/src/platform/silabs/wifi/wiseconnect-abstraction/WiseconnectInterfaceAbstraction.cpp @@ -160,7 +160,7 @@ sl_status_t wfx_connect_to_ap(void) 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); - WifiEvent event = WifiEvent::kStationStartJoin; + WifiPlatformEvent event = WifiPlatformEvent::kStationStartJoin; sl_matter_wifi_post_event(event); return SL_STATUS_OK; } @@ -327,7 +327,7 @@ bool wfx_start_scan(char * ssid, void (*callback)(wfx_wifi_scan_result_t *)) VerifyOrReturnError(wfx_rsi.scan_ssid != nullptr, false); chip::Platform::CopyString(wfx_rsi.scan_ssid, wfx_rsi.scan_ssid_length, ssid); - WifiEvent event = WifiEvent::kScan; + WifiPlatformEvent event = WifiPlatformEvent::kScan; sl_matter_wifi_post_event(event); return true; diff --git a/src/platform/silabs/wifi/wiseconnect-abstraction/WiseconnectInterfaceAbstraction.h b/src/platform/silabs/wifi/wiseconnect-abstraction/WiseconnectInterfaceAbstraction.h index 9073a02ef64b5b..38e6ffa392b241 100644 --- a/src/platform/silabs/wifi/wiseconnect-abstraction/WiseconnectInterfaceAbstraction.h +++ b/src/platform/silabs/wifi/wiseconnect-abstraction/WiseconnectInterfaceAbstraction.h @@ -44,4 +44,4 @@ sl_status_t sl_matter_wifi_platform_init(void); * * @param[in] event Event to process. */ -void sl_matter_wifi_post_event(WifiEvent event); +void sl_matter_wifi_post_event(WifiPlatformEvent event); From 8cc501b925f22f705b0d6afac8f5fa9173beb13a Mon Sep 17 00:00:00 2001 From: Mathieu Kardous Date: Thu, 28 Nov 2024 18:06:46 -0500 Subject: [PATCH 2/9] Refactor Notify function and associated data structures --- src/platform/silabs/CHIPDevicePlatformEvent.h | 20 --- .../silabs/ConnectivityManagerImpl_WIFI.cpp | 73 ++++------ src/platform/silabs/PlatformManagerImpl.cpp | 84 ++++------- src/platform/silabs/PlatformManagerImpl.h | 2 +- .../silabs/wifi/SiWx/WifiInterface.cpp | 21 ++- .../silabs/wifi/WifiInterfaceAbstraction.cpp | 130 +++++++----------- .../silabs/wifi/WifiInterfaceAbstraction.h | 116 +++++++++------- .../silabs/wifi/rs911x/WifiInterface.cpp | 33 ++--- .../silabs/wifi/wf200/WifiInterface.cpp | 31 +++-- src/platform/silabs/wifi/wfx_msgs.h | 8 -- .../WiseconnectInterfaceAbstraction.cpp | 2 + .../WiseconnectInterfaceAbstraction.h | 18 ++- 12 files changed, 227 insertions(+), 311 deletions(-) diff --git a/src/platform/silabs/CHIPDevicePlatformEvent.h b/src/platform/silabs/CHIPDevicePlatformEvent.h index 090ada64037c6f..10c57a1a3b306d 100644 --- a/src/platform/silabs/CHIPDevicePlatformEvent.h +++ b/src/platform/silabs/CHIPDevicePlatformEvent.h @@ -63,32 +63,12 @@ struct ChipDevicePlatformEvent final #if CHIP_DEVICE_CONFIG_ENABLE_WIFI_STATION struct { - wfx_event_base_t eventBase; union { sl_wfx_generic_message_t genericMsgEvent; sl_wfx_startup_ind_t startupEvent; sl_wfx_connect_ind_t connectEvent; sl_wfx_disconnect_ind_t disconnectEvent; - - /* - * NOT CURRENTLY USED - *Some structs might be bigger in size than the one we use - * so we reduce the union size by commenting them out. - * Keep for possible future implementation. - */ - - // sl_wfx_generic_ind_t genericEvent; - // sl_wfx_exception_ind_t exceptionEvent; - // sl_wfx_error_ind_t errorEvent; - // sl_wfx_received_ind_t receivedEvent; - // sl_wfx_scan_result_ind_t scanResultEvent; - // sl_wfx_scan_complete_ind_t scanCompleteEvent; - // sl_wfx_start_ap_ind_t startApEvent; - // sl_wfx_stop_ap_ind_t stopApEvent; - // sl_wfx_ap_client_connected_ind_t apClientConnectedEvent; - // sl_wfx_ap_client_rejected_ind_t apClientRejectedEvent; - // sl_wfx_ap_client_disconnected_ind_t apClientDisconnectedEvent; } data; } WFXSystemEvent; #endif diff --git a/src/platform/silabs/ConnectivityManagerImpl_WIFI.cpp b/src/platform/silabs/ConnectivityManagerImpl_WIFI.cpp index 0d9d63317ef637..441579ead04837 100644 --- a/src/platform/silabs/ConnectivityManagerImpl_WIFI.cpp +++ b/src/platform/silabs/ConnectivityManagerImpl_WIFI.cpp @@ -81,60 +81,45 @@ void ConnectivityManagerImpl::_OnPlatformEvent(const ChipDeviceEvent * event) // Handle Wfx wifi events... if (event->Type == DeviceEventType::kWFXSystemEvent) { - if (event->Platform.WFXSystemEvent.eventBase == WIFI_EVENT) + + switch (event->Platform.WFXSystemEvent.data.genericMsgEvent.header.id) { - switch (event->Platform.WFXSystemEvent.data.genericMsgEvent.header.id) + case to_underlying(WifiEvent::kStartUp): + ChipLogProgress(DeviceLayer, "WIFI_EVENT_STA_START"); + DriveStationState(); + break; + case to_underlying(WifiEvent::kConnect): + ChipLogProgress(DeviceLayer, "WIFI_EVENT_STA_CONNECTED"); + if (mWiFiStationState == kWiFiStationState_Connecting) { - case SL_WFX_STARTUP_IND_ID: - ChipLogProgress(DeviceLayer, "WIFI_EVENT_STA_START"); - DriveStationState(); - break; - case SL_WFX_CONNECT_IND_ID: - ChipLogProgress(DeviceLayer, "WIFI_EVENT_STA_CONNECTED"); - if (mWiFiStationState == kWiFiStationState_Connecting) + if (event->Platform.WFXSystemEvent.data.connectEvent.body.status == 0) { - if (event->Platform.WFXSystemEvent.data.connectEvent.body.status == 0) - { - ChangeWiFiStationState(kWiFiStationState_Connecting_Succeeded); - } - else - { - ChangeWiFiStationState(kWiFiStationState_Connecting_Failed); - } + ChangeWiFiStationState(kWiFiStationState_Connecting_Succeeded); } - DriveStationState(); - break; - case SL_WFX_DISCONNECT_IND_ID: - ChipLogProgress(DeviceLayer, "WIFI_EVENT_STA_DISCONNECTED"); - if (mWiFiStationState == kWiFiStationState_Connecting) + else { ChangeWiFiStationState(kWiFiStationState_Connecting_Failed); } - DriveStationState(); - break; - default: - break; } - } - else if (event->Platform.WFXSystemEvent.eventBase == IP_EVENT) - { - switch (event->Platform.WFXSystemEvent.data.genericMsgEvent.header.id) + DriveStationState(); + break; + case to_underlying(WifiEvent::kDisconnect): + ChipLogProgress(DeviceLayer, "WIFI_EVENT_STA_DISCONNECTED"); + if (mWiFiStationState == kWiFiStationState_Connecting) { - case IP_EVENT_STA_GOT_IP: - ChipLogProgress(DeviceLayer, "IP_EVENT_STA_GOT_IP"); - UpdateInternetConnectivityState(); - break; - case IP_EVENT_STA_LOST_IP: - ChipLogProgress(DeviceLayer, "IP_EVENT_STA_LOST_IP"); - UpdateInternetConnectivityState(); - break; - case IP_EVENT_GOT_IP6: - ChipLogProgress(DeviceLayer, "IP_EVENT_GOT_IP6"); - UpdateInternetConnectivityState(); - break; - default: - break; + ChangeWiFiStationState(kWiFiStationState_Connecting_Failed); } + DriveStationState(); + break; + + case to_underlying(WifiEvent::kGotIPv4): + case to_underlying(WifiEvent::kLostIP): + case to_underlying(WifiEvent::kGotIPv6): + ChipLogProgress(DeviceLayer, "IP Change Event"); + UpdateInternetConnectivityState(); + break; + default: + break; } } } diff --git a/src/platform/silabs/PlatformManagerImpl.cpp b/src/platform/silabs/PlatformManagerImpl.cpp index b3d7f80052dd3a..b1fbe60634348d 100644 --- a/src/platform/silabs/PlatformManagerImpl.cpp +++ b/src/platform/silabs/PlatformManagerImpl.cpp @@ -141,71 +141,41 @@ void PlatformManagerImpl::_Shutdown() #if CHIP_DEVICE_CONFIG_ENABLE_WIFI_STATION // This function needs to be global so it can be used from the platform implementation without depending on the platfrom itself. // This is a workaround to avoid a circular dependency. -void HandleWFXSystemEvent(wfx_event_base_t eventBase, sl_wfx_generic_message_t * eventData) +void HandleWFXSystemEvent(sl_wfx_generic_message_t * eventData) { using namespace chip; using namespace chip::DeviceLayer; ChipDeviceEvent event; memset(&event, 0, sizeof(event)); - event.Type = DeviceEventType::kWFXSystemEvent; - event.Platform.WFXSystemEvent.eventBase = eventBase; + event.Type = DeviceEventType::kWFXSystemEvent; - if (eventBase == WIFI_EVENT) + switch (eventData->header.id) { - switch (eventData->header.id) - { - case SL_WFX_STARTUP_IND_ID: - memcpy(&event.Platform.WFXSystemEvent.data.startupEvent, eventData, - sizeof(event.Platform.WFXSystemEvent.data.startupEvent)); - break; - case SL_WFX_CONNECT_IND_ID: - memcpy(&event.Platform.WFXSystemEvent.data.connectEvent, eventData, - sizeof(event.Platform.WFXSystemEvent.data.connectEvent)); - break; - case SL_WFX_DISCONNECT_IND_ID: - memcpy(&event.Platform.WFXSystemEvent.data.disconnectEvent, eventData, - sizeof(event.Platform.WFXSystemEvent.data.disconnectEvent)); - break; - // case SL_WFX_RECEIVED_IND_ID: - // memcpy(&event.Platform.WFXSystemEvent.data.receivedEvent, eventData, - // sizeof(event.Platform.WFXSystemEvent.data.receivedEvent)); - // break; - // case SL_WFX_GENERIC_IND_ID: - // memcpy(&event.Platform.WFXSystemEvent.data.genericEvent, eventData, - // sizeof(event.Platform.WFXSystemEvent.data.genericEvent)); - // break; - // case SL_WFX_EXCEPTION_IND_ID: - // memcpy(&event.Platform.WFXSystemEvent.data.exceptionEvent, eventData, - // sizeof(event.Platform.WFXSystemEvent.data.exceptionEvent)); - // break; - // case SL_WFX_ERROR_IND_ID: - // memcpy(&event.Platform.WFXSystemEvent.data.errorEvent, eventData, - // sizeof(event.Platform.WFXSystemEvent.data.errorEvent)); - // break; - default: - break; - } - } - else if (eventBase == IP_EVENT) - { - switch (eventData->header.id) - { - case IP_EVENT_STA_GOT_IP: - memcpy(&event.Platform.WFXSystemEvent.data.genericMsgEvent, eventData, - sizeof(event.Platform.WFXSystemEvent.data.genericMsgEvent)); - break; - case IP_EVENT_GOT_IP6: - memcpy(&event.Platform.WFXSystemEvent.data.genericMsgEvent, eventData, - sizeof(event.Platform.WFXSystemEvent.data.genericMsgEvent)); - break; - case IP_EVENT_STA_LOST_IP: - memcpy(&event.Platform.WFXSystemEvent.data.genericMsgEvent, eventData, - sizeof(event.Platform.WFXSystemEvent.data.genericMsgEvent)); - break; - default: - break; - } + case to_underlying(WifiEvent::kStartUp): + memcpy(&event.Platform.WFXSystemEvent.data.startupEvent, eventData, + sizeof(event.Platform.WFXSystemEvent.data.startupEvent)); + break; + + case to_underlying(WifiEvent::kConnect): + memcpy(&event.Platform.WFXSystemEvent.data.connectEvent, eventData, + sizeof(event.Platform.WFXSystemEvent.data.connectEvent)); + break; + + case to_underlying(WifiEvent::kDisconnect): + memcpy(&event.Platform.WFXSystemEvent.data.disconnectEvent, eventData, + sizeof(event.Platform.WFXSystemEvent.data.disconnectEvent)); + break; + + case to_underlying(WifiEvent::kGotIPv4): + case to_underlying(WifiEvent::kLostIP): + case to_underlying(WifiEvent::kGotIPv6): + memcpy(&event.Platform.WFXSystemEvent.data.genericMsgEvent, eventData, + sizeof(event.Platform.WFXSystemEvent.data.genericMsgEvent)); + break; + + default: + break; } // TODO: We should add error processing here diff --git a/src/platform/silabs/PlatformManagerImpl.h b/src/platform/silabs/PlatformManagerImpl.h index dddc491384a86f..ee5897bbf1d868 100644 --- a/src/platform/silabs/PlatformManagerImpl.h +++ b/src/platform/silabs/PlatformManagerImpl.h @@ -31,7 +31,7 @@ #include #if CHIP_DEVICE_CONFIG_ENABLE_WIFI_STATION -void HandleWFXSystemEvent(wfx_event_base_t eventBase, sl_wfx_generic_message_t * eventData); +void HandleWFXSystemEvent(sl_wfx_generic_message_t * eventData); #endif namespace chip { diff --git a/src/platform/silabs/wifi/SiWx/WifiInterface.cpp b/src/platform/silabs/wifi/SiWx/WifiInterface.cpp index 0399502e06a37b..10093e25a92d1f 100644 --- a/src/platform/silabs/wifi/SiWx/WifiInterface.cpp +++ b/src/platform/silabs/wifi/SiWx/WifiInterface.cpp @@ -300,7 +300,7 @@ sl_status_t ScanCallback(sl_wifi_event_t event, sl_wifi_scan_result_t * scan_res { security = static_cast(scan_result->scan_info[0].security_mode); wfx_rsi.ap_chan = scan_result->scan_info[0].rf_channel; - memcpy(&wfx_rsi.ap_mac.octet, scan_result->scan_info[0].bssid, BSSID_LEN); + memcpy(&wfx_rsi.ap_mac.octet, scan_result->scan_info[0].bssid, kWifiMacAddressLength); } osSemaphoreRelease(sScanCompleteSemaphore); @@ -480,7 +480,7 @@ int32_t wfx_rsi_get_ap_info(wfx_wifi_scan_result_t * ap) 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); + memcpy(&ap->bssid[0], &wfx_rsi.ap_mac.octet[0], kWifiMacAddressLength); sl_wifi_get_signal_strength(SL_WIFI_CLIENT_INTERFACE, &rssi); ap->rssi = rssi; return status; @@ -570,7 +570,7 @@ sl_status_t show_scan_results(sl_wifi_scan_result_t * scan_result) } cur_scan_result.security = static_cast(scan_result->scan_info[idx].security_mode); cur_scan_result.rssi = (-1) * scan_result->scan_info[idx].rssi_val; - memcpy(cur_scan_result.bssid, scan_result->scan_info[idx].bssid, BSSID_LEN); + memcpy(cur_scan_result.bssid, scan_result->scan_info[idx].bssid, kWifiMacAddressLength); wfx_rsi.scan_cb(&cur_scan_result); // if user has not provided the ssid, then call the callback for each scan result @@ -606,7 +606,7 @@ sl_status_t bg_scan_callback_handler(sl_wifi_event_t event, sl_wifi_scan_result_ void NotifyConnectivity(void) { VerifyOrReturn(!hasNotifiedWifiConnectivity); - wfx_connected_notify(CONNECTION_STATUS_SUCCESS, &wfx_rsi.ap_mac); + NotifyConnection(&wfx_rsi.ap_mac); hasNotifiedWifiConnectivity = true; } @@ -630,7 +630,7 @@ void HandleDHCPPolling(void) } else if (dhcp_state == DHCP_OFF) { - wfx_ip_changed_notify(IP_STATUS_FAIL); + NotifyIPv4Change(false); hasNotifiedIPV4 = false; } #endif /* CHIP_DEVICE_CONFIG_ENABLE_IPV4 */ @@ -642,7 +642,7 @@ void HandleDHCPPolling(void) char addrStr[chip::Inet::IPAddress::kMaxStringLength] = { 0 }; VerifyOrReturn(ip6addr_ntoa_r(netif_ip6_addr(sta_netif, 0), addrStr, sizeof(addrStr)) != nullptr); ChipLogProgress(DeviceLayer, "SLAAC OK: linklocal addr: %s", addrStr); - wfx_ipv6_notify(GET_IPV6_SUCCESS); + NotifyIPv6Change(true); hasNotifiedIPV6 = true; event = WifiPlatformEvent::kStationDhcpDone; sl_matter_wifi_post_event(event); @@ -699,10 +699,9 @@ void ProcessEvent(WifiPlatformEvent event) /* TODO: Implement disconnect notify */ ResetDHCPNotificationFlags(); #if (CHIP_DEVICE_CONFIG_ENABLE_IPV4) - wfx_ip_changed_notify(0); // for IPV4 - wfx_ip_changed_notify(IP_STATUS_FAIL); + NotifyIPv4Change(false); #endif /* CHIP_DEVICE_CONFIG_ENABLE_IPV4 */ - wfx_ipv6_notify(GET_IPV6_FAIL); + NotifyIPv6Change(false); } break; @@ -840,7 +839,7 @@ void wfx_dhcp_got_ipv4(uint32_t ip) /* * Acquire the new IP address */ - wfx_rsi.ip4_addr[0] = (ip) &0xFF; + wfx_rsi.ip4_addr[0] = (ip) & 0xFF; wfx_rsi.ip4_addr[1] = (ip >> 8) & 0xFF; wfx_rsi.ip4_addr[2] = (ip >> 16) & 0xFF; wfx_rsi.ip4_addr[3] = (ip >> 24) & 0xFF; @@ -848,7 +847,7 @@ void wfx_dhcp_got_ipv4(uint32_t ip) wfx_rsi.ip4_addr[3]); /* Notify the Connectivity Manager - via the app */ wfx_rsi.dev_state.Set(WifiState::kStationDhcpDone).Set(WifiState::kStationReady); - wfx_ip_changed_notify(IP_STATUS_SUCCESS); + NotifyIPv4Change(true); } #endif /* CHIP_DEVICE_CONFIG_ENABLE_IPV4 */ diff --git a/src/platform/silabs/wifi/WifiInterfaceAbstraction.cpp b/src/platform/silabs/wifi/WifiInterfaceAbstraction.cpp index 698c839a10e43a..e0a7ae77cf8d5c 100644 --- a/src/platform/silabs/wifi/WifiInterfaceAbstraction.cpp +++ b/src/platform/silabs/wifi/WifiInterfaceAbstraction.cpp @@ -21,6 +21,7 @@ #include #include #include +#include #include #include #include @@ -35,7 +36,7 @@ using namespace chip::DeviceLayer; // TODO: This is a workaround because we depend on the platform lib which depends on the platform implementation. // As such we can't depend on the platform here as well -extern void HandleWFXSystemEvent(wfx_event_base_t eventBase, sl_wfx_generic_message_t * eventData); +extern void HandleWFXSystemEvent(sl_wfx_generic_message_t * eventData); namespace { @@ -61,109 +62,76 @@ void RetryConnectionTimerHandler(void * arg) } // namespace -/*********************************************************************************** - * @fn sl_matter_wifi_task_started(void) - * @brief - * Wifi device started notification - * @param[in]: None - * @return None - *************************************************************************************/ -void sl_matter_wifi_task_started(void) +/* Updated functions */ + +void NotifyIPv6Change(bool gotIPv6Addr) { - sl_wfx_startup_ind_t evt; - sl_wfx_mac_address_t mac; + sl_wfx_generic_message_t eventData = {}; + eventData.header.id = gotIPv6Addr ? to_underlying(WifiEvent::kGotIPv6) : to_underlying(WifiEvent::kLostIP); + eventData.header.length = sizeof(eventData.header); - // Creating a timer which will be used to retry connection with AP - sRetryTimer = osTimerNew(RetryConnectionTimerHandler, osTimerOnce, NULL, NULL); - VerifyOrReturn(sRetryTimer != NULL); + HandleWFXSystemEvent(&eventData); +} - memset(&evt, 0, sizeof(evt)); - evt.header.id = SL_WFX_STARTUP_IND_ID; - evt.header.length = sizeof evt; - evt.body.status = 0; - wfx_get_wifi_mac_addr(SL_WFX_STA_INTERFACE, &mac); - memcpy(&evt.body.mac_addr[0], &mac.octet[0], MAC_ADDRESS_FIRST_OCTET); +void NotifyIPv4Change(bool gotIPv4Addr) +{ + sl_wfx_generic_message_t eventData; - HandleWFXSystemEvent(WIFI_EVENT, (sl_wfx_generic_message_t *) &evt); + memset(&eventData, 0, sizeof(eventData)); + eventData.header.id = gotIPv4Addr ? to_underlying(WifiEvent::kGotIPv4) : to_underlying(WifiEvent::kLostIP); + eventData.header.length = sizeof(eventData.header); + HandleWFXSystemEvent(&eventData); } -/*********************************************************************************** - * @fn void wfx_connected_notify(int32_t status, sl_wfx_mac_address_t *ap) - * @brief - * For now we are not notifying anything other than AP Mac - - * Other stuff such as DTIM etc. may be required for later - * @param[in] status: - * @param[in] ap: access point - * @return None - *************************************************************************************/ -void wfx_connected_notify(int32_t status, sl_wfx_mac_address_t * ap) +void NotifyDisconnection(WifiDisconnectionReasons reason) { - sl_wfx_connect_ind_t evt; - - VerifyOrReturn(status == SUCCESS_STATUS); + sl_wfx_disconnect_ind_t evt = {}; + evt.header.id = to_underlying(WifiEvent::kDisconnect); + evt.header.length = sizeof evt; + evt.body.reason = to_underlying(reason); - memset(&evt, 0, sizeof(evt)); - evt.header.id = SL_WFX_CONNECT_IND_ID; - evt.header.length = sizeof evt; + HandleWFXSystemEvent((sl_wfx_generic_message_t *) &evt); +} +void NotifyConnection(sl_wfx_mac_address_t * ap) +{ + sl_wfx_connect_ind_t evt = {}; + evt.header.id = to_underlying(WifiEvent::kConnect); + evt.header.length = sizeof evt; #ifdef RS911X_WIFI evt.body.channel = wfx_rsi.ap_chan; #endif - memcpy(&evt.body.mac[0], &ap->octet[0], MAC_ADDRESS_FIRST_OCTET); + memcpy(&evt.body.mac[0], &ap->octet[0], kWifiMacAddressLength); - HandleWFXSystemEvent(WIFI_EVENT, (sl_wfx_generic_message_t *) &evt); + HandleWFXSystemEvent((sl_wfx_generic_message_t *) &evt); } -/************************************************************************************** - * @fn void wfx_disconnected_notify(int32_t status) - * @brief - * notification of disconnection - * @param[in] status: - * @return None - *************************************************************************************/ -void wfx_disconnected_notify(int32_t status) -{ - sl_wfx_disconnect_ind_t evt; - - memset(&evt, 0, sizeof(evt)); - evt.header.id = SL_WFX_DISCONNECT_IND_ID; - evt.header.length = sizeof evt; - evt.body.reason = status; - HandleWFXSystemEvent(WIFI_EVENT, (sl_wfx_generic_message_t *) &evt); -} +/* Function to update */ -/************************************************************************************** - * @fn void wfx_ipv6_notify(int got_ip) +/*********************************************************************************** + * @fn sl_matter_wifi_task_started(void) * @brief - * notification of ipv6 - * @param[in] got_ip: + * Wifi device started notification + * @param[in]: None * @return None *************************************************************************************/ -void wfx_ipv6_notify(int got_ip) +void sl_matter_wifi_task_started(void) { - sl_wfx_generic_message_t eventData; + sl_wfx_startup_ind_t evt; + sl_wfx_mac_address_t mac; - memset(&eventData, 0, sizeof(eventData)); - eventData.header.id = got_ip ? IP_EVENT_GOT_IP6 : IP_EVENT_STA_LOST_IP; - eventData.header.length = sizeof(eventData.header); - HandleWFXSystemEvent(IP_EVENT, &eventData); -} + // Creating a timer which will be used to retry connection with AP + sRetryTimer = osTimerNew(RetryConnectionTimerHandler, osTimerOnce, NULL, NULL); + VerifyOrReturn(sRetryTimer != NULL); -/************************************************************************************** - * @fn void wfx_ip_changed_notify(int got_ip) - * @brief - * notification of ip change - * @param[in] got_ip: - * @return None - *************************************************************************************/ -void wfx_ip_changed_notify(int got_ip) -{ - sl_wfx_generic_message_t eventData; + memset(&evt, 0, sizeof(evt)); + evt.header.id = to_underlying(WifiEvent::kStartUp); + evt.header.length = sizeof evt; + evt.body.status = 0; + wfx_get_wifi_mac_addr(SL_WFX_STA_INTERFACE, &mac); + memcpy(&evt.body.mac_addr[0], &mac.octet[0], kWifiMacAddressLength); - memset(&eventData, 0, sizeof(eventData)); - eventData.header.id = got_ip ? IP_EVENT_STA_GOT_IP : IP_EVENT_STA_LOST_IP; - eventData.header.length = sizeof(eventData.header); - HandleWFXSystemEvent(IP_EVENT, &eventData); + HandleWFXSystemEvent((sl_wfx_generic_message_t *) &evt); } /************************************************************************************** diff --git a/src/platform/silabs/wifi/WifiInterfaceAbstraction.h b/src/platform/silabs/wifi/WifiInterfaceAbstraction.h index b676e30c6bc692..7f17efb9aad7b1 100644 --- a/src/platform/silabs/wifi/WifiInterfaceAbstraction.h +++ b/src/platform/silabs/wifi/WifiInterfaceAbstraction.h @@ -36,35 +36,39 @@ #include "sl_si91x_types.h" #include "sl_wifi_constants.h" #include "sl_wifi_device.h" +#endif // (SLI_SI91X_MCU_INTERFACE | EXP_BOARD) -/* - * Interface to RSI Sapis - */ +/* Updated constants */ -#define WFX_RSI_DHCP_POLL_INTERVAL (250) /* Poll interval in ms for DHCP */ +constexpr uint8_t kWifiMacAddressLength = 6; -// MAX SSID LENGTH excluding NULL character -#define WFX_MAX_SSID_LENGTH (32) +/* Defines to update */ + +// TODO: Not sure why the pass key max length differs for the 917 SoC & NCP +#if (SLI_SI91X_MCU_INTERFACE | EXP_BOARD) // MAX PASSKEY LENGTH including NULL character #define WFX_MAX_PASSKEY_LENGTH (SL_WIFI_MAX_PSK_LENGTH) -#define SL_WIFI_ALLOCATE_COMMAND_BUFFER_WAIT_TIME_MS (1000) #else -// MAX SSID LENGTH excluding NULL character -#define WFX_MAX_SSID_LENGTH (32) // MAX PASSKEY LENGTH including NULL character #define WFX_MAX_PASSKEY_LENGTH (64) #endif // (SLI_SI91X_MCU_INTERFACE | EXP_BOARD) +// MAX SSID LENGTH excluding NULL character +#define WFX_MAX_SSID_LENGTH (32) #define MAX_JOIN_RETRIES_COUNT (5) -#define BSSID_LEN (6) -#define MAC_ADDRESS_FIRST_OCTET (6) -#define CONNECTION_STATUS_SUCCESS (1) -#define IP_STATUS_FAIL (0) -#define GET_IPV6_FAIL (0) -#define IP_STATUS_SUCCESS (1) -// TASK and Interrupt Macros -#define SUCCESS_STATUS (1) +/* Update Enums */ + +enum class WifiEvent : uint8_t +{ + kStartUp = 1, + kConnect = 2, + kDisconnect = 3, + kScanComplete = 4, + kGotIPv4 = 5, + kGotIPv6 = 6, + kLostIP = 7, +}; enum class WifiState : uint16_t { @@ -81,19 +85,17 @@ enum class WifiState : uint16_t kScanStarted = (1 << 10), /* Scan Started */ }; -enum class WifiPlatformEvent : uint8_t +enum class WifiDisconnectionReasons : uint16_t // using uint16 to match current structure during the transition { - kStationConnect = 1, - kStationDisconnect = 2, - kAPStart = 3, - kAPStop = 4, - kScan = 5, /* This is used as scan result and start */ - kStationStartJoin = 6, - kStationDoDhcp = 7, - kStationDhcpDone = 8, - kStationDhcpPoll = 9, + kUnknownError = 1, // Disconnation due to an internal error + kAccessPointLost = 2, // Device did not receive AP beacon too many times + kAccessPoint = 3, // AP disconnected the device + kApplication = 4, // Application requested disconnection + kWPACouterMeasures = 5, // WPA contermeasures triggered a disconnection }; +/* Enums to update */ + /* Note that these are same as RSI_security */ typedef enum { @@ -129,7 +131,7 @@ 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 bssid[kWifiMacAddressLength]; uint8_t chan; int16_t rssi; /* I suspect this is in dBm - so signed */ } wfx_wifi_scan_result_t; @@ -145,13 +147,6 @@ typedef struct wfx_wifi_scan_ext uint32_t overrun_count; } wfx_wifi_scan_ext_t; -typedef enum -{ - IP_EVENT_STA_GOT_IP, - IP_EVENT_GOT_IP6, - IP_EVENT_STA_LOST_IP, -} ip_event_id_t; - #ifdef RS911X_WIFI /* * This Sh%t is here to support WFXUtils - and the Matter stuff that uses it @@ -187,6 +182,42 @@ typedef struct wfx_rsi_s // TODO: We shouldn't need to have access to a global variable in the interface here extern WfxRsi_t wfx_rsi; +/* Updated functions */ + +/** + * @brief Function notifies the PlatformManager that an IPv6 event occured on the WiFi interface. + * + * @param gotIPv6Addr true, got an IPv6 address + * false, lost or wasn't able to get an IPv6 address + */ +void NotifyIPv6Change(bool gotIPv6Addr); + +#if CHIP_DEVICE_CONFIG_ENABLE_IPV4 +/** + * @brief Function notifies the PlatformManager that an IPv4 event occured on the WiFi interface. + * + * @param gotIPv4Addr true, got an IPv4 address + * false, lost or wasn't able to get an IPv4 address + */ +void NotifyIPv4Change(bool gotIPv4Addr); +#endif /* CHIP_DEVICE_CONFIG_ENABLE_IPV4 */ + +/** + * @brief Function notifies the PlatformManager that a disconnection event occurred + * + * @param reason reason for the disconnection + */ +void NotifyDisconnection(WifiDisconnectionReasons reason); + +/** + * @brief Function notifies the PlatformManager that a connection event occurred + * + * @param[in] ap pointer to the structure that contains the MAC address of the AP + */ +void NotifyConnection(sl_wfx_mac_address_t * ap); + +/* Function to update */ + sl_status_t wfx_wifi_start(void); void wfx_enable_sta_mode(void); void wfx_get_wifi_mac_addr(sl_wfx_interface_t interface, sl_wfx_mac_address_t * addr); @@ -215,8 +246,6 @@ void wfx_cancel_scan(void); * Call backs into the Matter Platform code */ void sl_matter_wifi_task_started(void); -void wfx_connected_notify(int32_t status, sl_wfx_mac_address_t * ap); -void wfx_disconnected_notify(int32_t status); /* Implemented for LWIP */ void wfx_lwip_set_sta_link_up(void); @@ -226,9 +255,7 @@ struct netif * wfx_get_netif(sl_wfx_interface_t interface); #if CHIP_DEVICE_CONFIG_ENABLE_IPV4 void wfx_dhcp_got_ipv4(uint32_t); -void wfx_ip_changed_notify(int got_ip); #endif /* CHIP_DEVICE_CONFIG_ENABLE_IPV4 */ -void wfx_ipv6_notify(int got_ip); void wfx_retry_connection(uint16_t retryAttempt); #ifdef RS911X_WIFI @@ -255,22 +282,11 @@ sl_status_t wfx_power_save(); void sl_matter_wifi_task(void * arg); -#if CHIP_DEVICE_CONFIG_ENABLE_IPV4 -void wfx_ip_changed_notify(int got_ip); -#endif /* CHIP_DEVICE_CONFIG_ENABLE_IPV4 */ - int32_t wfx_rsi_get_ap_info(wfx_wifi_scan_result_t * ap); int32_t wfx_rsi_get_ap_ext(wfx_wifi_scan_ext_t * extra_info); int32_t wfx_rsi_reset_count(); int32_t sl_wifi_platform_disconnect(); -/** - * @brief Posts an event to the Wi-Fi task - * - * @param[in] event Event to process. - */ -void sl_matter_wifi_post_event(WifiEvent event); - #ifdef __cplusplus extern "C" { #endif diff --git a/src/platform/silabs/wifi/rs911x/WifiInterface.cpp b/src/platform/silabs/wifi/rs911x/WifiInterface.cpp index 0ea835a1089c09..049c5b3b5bec85 100644 --- a/src/platform/silabs/wifi/rs911x/WifiInterface.cpp +++ b/src/platform/silabs/wifi/rs911x/WifiInterface.cpp @@ -154,7 +154,7 @@ int32_t wfx_rsi_get_ap_info(wfx_wifi_scan_result_t * ap) uint8_t rssi; ap->security = wfx_rsi.sec.security; ap->chan = wfx_rsi.ap_chan; - memcpy(&ap->bssid[0], &wfx_rsi.ap_mac.octet[0], BSSID_LEN); + memcpy(&ap->bssid[0], &wfx_rsi.ap_mac.octet[0], kWifiMacAddressLength); status = rsi_wlan_get(RSI_RSSI, &rssi, sizeof(rssi)); if (status == RSI_SUCCESS) { @@ -451,7 +451,7 @@ static void wfx_rsi_save_ap_info(void) // translation } wfx_rsi.sec.security = WFX_SEC_UNSPECIFIED; wfx_rsi.ap_chan = rsp.scan_info->rf_channel; - memcpy(&wfx_rsi.ap_mac.octet[0], &rsp.scan_info->bssid[0], BSSID_LEN); + memcpy(&wfx_rsi.ap_mac.octet[0], &rsp.scan_info->bssid[0], kWifiMacAddressLength); switch (rsp.scan_info->security_mode) { @@ -563,7 +563,7 @@ void NotifyConnectivity(void) { if (!hasNotifiedWifiConnectivity) { - wfx_connected_notify(CONNECTION_STATUS_SUCCESS, &wfx_rsi.ap_mac); + NotifyConnection(&wfx_rsi.ap_mac); hasNotifiedWifiConnectivity = true; } } @@ -590,7 +590,7 @@ void HandleDHCPPolling(void) } else if (dhcp_state == DHCP_OFF) { - wfx_ip_changed_notify(IP_STATUS_FAIL); + NotifyIPv4Change(false); hasNotifiedIPV4 = false; } #endif /* CHIP_DEVICE_CONFIG_ENABLE_IPV4 */ @@ -599,7 +599,7 @@ void HandleDHCPPolling(void) */ if ((ip6_addr_ispreferred(netif_ip6_addr_state(sta_netif, 0))) && !hasNotifiedIPV6) { - wfx_ipv6_notify(GET_IPV6_SUCCESS); + NotifyIPv6Change(true); hasNotifiedIPV6 = true; WifiPlatformEvent event = WifiPlatformEvent::kStationDhcpDone; sl_matter_wifi_post_event(event); @@ -655,11 +655,6 @@ void ProcessEvent(WifiPlatformEvent event) wfx_rsi.dev_state.Set(WifiState::kStationConnected); ResetDHCPNotificationFlags(); wfx_lwip_set_sta_link_up(); - /* We need to get AP Mac - TODO */ - // Uncomment once the hook into MATTER is moved to IP connectivty instead - // of AP connectivity. - // wfx_connected_notify(0, &wfx_rsi.ap_mac); // This - // is independant of IP connectivity. } break; case WifiPlatformEvent::kStationDisconnect: { @@ -670,12 +665,12 @@ void ProcessEvent(WifiPlatformEvent event) wfx_rsi.dev_state.Clear(flagsToClear); /* TODO: Implement disconnect notify */ ResetDHCPNotificationFlags(); - wfx_lwip_set_sta_link_down(); // Internally dhcpclient_poll(netif) -> - // wfx_ip_changed_notify(0) for IPV4 + wfx_lwip_set_sta_link_down(); + #if (CHIP_DEVICE_CONFIG_ENABLE_IPV4) - wfx_ip_changed_notify(IP_STATUS_FAIL); + NotifyIPv4Change(false); #endif /* CHIP_DEVICE_CONFIG_ENABLE_IPV4 */ - wfx_ipv6_notify(GET_IPV6_FAIL); + NotifyIPv6Change(false); } break; case WifiPlatformEvent::kAPStart: @@ -720,9 +715,9 @@ void ProcessEvent(WifiPlatformEvent event) 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); + configASSERT(sizeof(ap.bssid) == kWifiMacAddressLength); + configASSERT(sizeof(scan->bssid) == kWifiMacAddressLength); + memcpy(ap.bssid, scan->bssid, kWifiMacAddressLength); (*wfx_rsi.scan_cb)(&ap); // no ssid filter set, return all results @@ -823,7 +818,7 @@ void wfx_dhcp_got_ipv4(uint32_t ip) /* * Acquire the new IP address */ - wfx_rsi.ip4_addr[0] = (ip) &0xFF; + wfx_rsi.ip4_addr[0] = (ip) & 0xFF; wfx_rsi.ip4_addr[1] = (ip >> 8) & 0xFF; wfx_rsi.ip4_addr[2] = (ip >> 16) & 0xFF; wfx_rsi.ip4_addr[3] = (ip >> 24) & 0xFF; @@ -831,7 +826,7 @@ void wfx_dhcp_got_ipv4(uint32_t ip) wfx_rsi.ip4_addr[3]); /* Notify the Connectivity Manager - via the app */ wfx_rsi.dev_state.Set(WifiState::kStationDhcpDone, WifiState::kStationReady); - wfx_ip_changed_notify(IP_STATUS_SUCCESS); + NotifyIPv4Change(true); } #endif /* CHIP_DEVICE_CONFIG_ENABLE_IPV4 */ diff --git a/src/platform/silabs/wifi/wf200/WifiInterface.cpp b/src/platform/silabs/wifi/wf200/WifiInterface.cpp index 1ff37ab61727b6..1d55145041c5d9 100644 --- a/src/platform/silabs/wifi/wf200/WifiInterface.cpp +++ b/src/platform/silabs/wifi/wf200/WifiInterface.cpp @@ -45,7 +45,7 @@ using namespace ::chip::DeviceLayer; // TODO: This is a workaround because we depend on the platform lib which depends on the platform implementation. // As such we can't depend on the platform here as well -extern void HandleWFXSystemEvent(wfx_event_base_t eventBase, sl_wfx_generic_message_t * eventData); +extern void HandleWFXSystemEvent(sl_wfx_generic_message_t * eventData); /* wfxRsi Task will use as its stack */ StackType_t wfxEventTaskStack[1024] = { 0 }; @@ -326,7 +326,10 @@ extern "C" sl_status_t sl_wfx_host_process_event(sl_wfx_generic_message_t * even /******** INDICATION ********/ case SL_WFX_STARTUP_IND_ID: { ChipLogProgress(DeviceLayer, "startup completed."); - HandleWFXSystemEvent(WIFI_EVENT, event_payload); + + // TODO: This is a workaround until we unify the Matter Data structures + event_payload->header.id = to_underlying(WifiEvent::kStartUp); + HandleWFXSystemEvent(event_payload); break; } case SL_WFX_CONNECT_IND_ID: { @@ -480,7 +483,7 @@ static void sl_wfx_scan_result_callback(sl_wfx_scan_result_ind_body_t * scan_res } ap->scan.chan = scan_result->channel; ap->scan.rssi = scan_result->rcpi; - memcpy(&ap->scan.bssid[0], &scan_result->mac[0], BSSID_LEN); + memcpy(&ap->scan.bssid[0], &scan_result->mac[0], kWifiMacAddressLength); scan_count++; } } @@ -515,7 +518,7 @@ static void sl_wfx_connect_callback(sl_wfx_connect_ind_body_t connect_indication { case WFM_STATUS_SUCCESS: { ChipLogProgress(DeviceLayer, "STA-Connected"); - memcpy(&ap_mac.octet[0], mac, MAC_ADDRESS_FIRST_OCTET); + memcpy(&ap_mac.octet[0], mac, kWifiMacAddressLength); sl_wfx_context->state = static_cast(static_cast(sl_wfx_context->state) | static_cast(SL_WFX_STA_INTERFACE_CONNECTED)); xEventGroupSetBits(sl_wfx_event_group, SL_WFX_CONNECT); @@ -692,23 +695,23 @@ static void wfx_events_task(void * p_arg) if (!hasNotifiedWifiConnectivity) { ChipLogProgress(DeviceLayer, "will notify WiFi connectivity"); - wfx_connected_notify(CONNECTION_STATUS_SUCCESS, &ap_mac); + NotifyConnection(&ap_mac); hasNotifiedWifiConnectivity = true; } } else if (dhcp_state == DHCP_OFF) { - wfx_ip_changed_notify(IP_STATUS_FAIL); + NotifyIPv4Change(false); hasNotifiedIPV4 = false; } #endif // CHIP_DEVICE_CONFIG_ENABLE_IPV4 if ((ip6_addr_ispreferred(netif_ip6_addr_state(sta_netif, 0))) && !hasNotifiedIPV6) { - wfx_ipv6_notify(1); + NotifyIPv6Change(true); hasNotifiedIPV6 = true; if (!hasNotifiedWifiConnectivity) { - wfx_connected_notify(CONNECTION_STATUS_SUCCESS, &ap_mac); + NotifyConnection(&ap_mac); hasNotifiedWifiConnectivity = true; } } @@ -719,10 +722,10 @@ static void wfx_events_task(void * p_arg) if (flags & SL_WFX_CONNECT) { #if (CHIP_DEVICE_CONFIG_ENABLE_IPV4) - wfx_ip_changed_notify(IP_STATUS_FAIL); + NotifyIPv4Change(false); hasNotifiedIPV4 = false; #endif // CHIP_DEVICE_CONFIG_ENABLE_IPV4 - wfx_ipv6_notify(GET_IPV6_FAIL); + NotifyIPv6Change(false); hasNotifiedIPV6 = false; hasNotifiedWifiConnectivity = false; ChipLogProgress(DeviceLayer, "connected to AP"); @@ -744,10 +747,10 @@ static void wfx_events_task(void * p_arg) { #if (CHIP_DEVICE_CONFIG_ENABLE_IPV4) - wfx_ip_changed_notify(IP_STATUS_FAIL); + NotifyIPv4Change(false); hasNotifiedIPV4 = false; #endif // CHIP_DEVICE_CONFIG_ENABLE_IPV4 - wfx_ipv6_notify(GET_IPV6_FAIL); + NotifyIPv6Change(false); hasNotifiedIPV6 = false; hasNotifiedWifiConnectivity = false; wifi_extra &= ~WE_ST_STA_CONN; @@ -1209,7 +1212,7 @@ void wfx_dhcp_got_ipv4(uint32_t ip) */ uint8_t ip4_addr[4]; - ip4_addr[0] = (ip) &0xFF; + ip4_addr[0] = (ip) & 0xFF; ip4_addr[1] = (ip >> 8) & 0xFF; ip4_addr[2] = (ip >> 16) & 0xFF; ip4_addr[3] = (ip >> 24) & 0xFF; @@ -1217,7 +1220,7 @@ void wfx_dhcp_got_ipv4(uint32_t ip) ChipLogDetail(DeviceLayer, "DHCP IP=%d.%d.%d.%d", ip4_addr[0], ip4_addr[1], ip4_addr[2], ip4_addr[3]); sta_ip = ip; - wfx_ip_changed_notify(IP_STATUS_SUCCESS); + NotifyIPv4Change(true); } #endif /* CHIP_DEVICE_CONFIG_ENABLE_IPV4 */ diff --git a/src/platform/silabs/wifi/wfx_msgs.h b/src/platform/silabs/wifi/wfx_msgs.h index ec1744c998611b..8154c32d1edd27 100644 --- a/src/platform/silabs/wifi/wfx_msgs.h +++ b/src/platform/silabs/wifi/wfx_msgs.h @@ -27,14 +27,6 @@ #include "sl_wfx_constants.h" #else -// These names exists in the Si SDK as typedef enum. If they are present in the WF200 builds, we end up with conflicting -// definitions but no erros because one is a define the other is a typedef enum. This causes different files to use different -// values. -#define SL_WFX_STARTUP_IND_ID (1) -#define SL_WFX_CONNECT_IND_ID (2) -#define SL_WFX_DISCONNECT_IND_ID (3) -#define SL_WFX_SCAN_COMPLETE_ID (4) - typedef struct { uint8_t octet[6]; ///< Table to store a MAC address diff --git a/src/platform/silabs/wifi/wiseconnect-abstraction/WiseconnectInterfaceAbstraction.cpp b/src/platform/silabs/wifi/wiseconnect-abstraction/WiseconnectInterfaceAbstraction.cpp index 25a073895972fd..4acd2a96f0d957 100644 --- a/src/platform/silabs/wifi/wiseconnect-abstraction/WiseconnectInterfaceAbstraction.cpp +++ b/src/platform/silabs/wifi/wiseconnect-abstraction/WiseconnectInterfaceAbstraction.cpp @@ -18,6 +18,8 @@ #include #include +extern WfxRsi_t wfx_rsi; + namespace { // Thread for the WLAN RSI diff --git a/src/platform/silabs/wifi/wiseconnect-abstraction/WiseconnectInterfaceAbstraction.h b/src/platform/silabs/wifi/wiseconnect-abstraction/WiseconnectInterfaceAbstraction.h index 38e6ffa392b241..d593fd0d098e31 100644 --- a/src/platform/silabs/wifi/wiseconnect-abstraction/WiseconnectInterfaceAbstraction.h +++ b/src/platform/silabs/wifi/wiseconnect-abstraction/WiseconnectInterfaceAbstraction.h @@ -22,16 +22,22 @@ #include #define WFX_RSI_DHCP_POLL_INTERVAL (250) /* Poll interval in ms for DHCP */ -#define GET_IPV6_SUCCESS (1) -extern WfxRsi_t wfx_rsi; +enum class WifiPlatformEvent : uint8_t +{ + kStationConnect = 1, + kStationDisconnect = 2, + kAPStart = 3, + kAPStop = 4, + kScan = 5, /* This is used as scan result and start */ + kStationStartJoin = 6, + kStationDoDhcp = 7, + kStationDhcpDone = 8, + kStationDhcpPoll = 9, +}; void sl_matter_wifi_task(void * arg); -#if CHIP_DEVICE_CONFIG_ENABLE_IPV4 -void wfx_ip_changed_notify(int got_ip); -#endif /* CHIP_DEVICE_CONFIG_ENABLE_IPV4 */ - int32_t wfx_rsi_get_ap_info(wfx_wifi_scan_result_t * ap); int32_t wfx_rsi_get_ap_ext(wfx_wifi_scan_ext_t * extra_info); int32_t wfx_rsi_reset_count(); From 9611f3af2b6733dc6b386e09f472233556e4f2a9 Mon Sep 17 00:00:00 2001 From: Mathieu Kardous Date: Thu, 28 Nov 2024 20:37:13 -0500 Subject: [PATCH 3/9] Rename mac address function --- src/platform/silabs/ConfigurationManagerImpl.cpp | 2 +- src/platform/silabs/rs911x/BLEManagerImpl.cpp | 2 +- .../silabs/wifi/WifiInterfaceAbstraction.cpp | 2 +- src/platform/silabs/wifi/WifiInterfaceAbstraction.h | 12 +++++++++++- src/platform/silabs/wifi/lwip-support/ethernetif.cpp | 2 +- src/platform/silabs/wifi/wf200/WifiInterface.cpp | 2 +- .../WiseconnectInterfaceAbstraction.cpp | 4 ++-- 7 files changed, 18 insertions(+), 8 deletions(-) diff --git a/src/platform/silabs/ConfigurationManagerImpl.cpp b/src/platform/silabs/ConfigurationManagerImpl.cpp index 3a144eb1160370..a5d58d16bf236e 100644 --- a/src/platform/silabs/ConfigurationManagerImpl.cpp +++ b/src/platform/silabs/ConfigurationManagerImpl.cpp @@ -314,7 +314,7 @@ void ConfigurationManagerImpl::DoFactoryReset(intptr_t arg) CHIP_ERROR ConfigurationManagerImpl::GetPrimaryWiFiMACAddress(uint8_t * buf) { sl_wfx_mac_address_t macaddr; - wfx_get_wifi_mac_addr(SL_WFX_STA_INTERFACE, &macaddr); + GetMacAddress(SL_WFX_STA_INTERFACE, &macaddr); memcpy(buf, &macaddr.octet[0], sizeof(macaddr.octet)); return CHIP_NO_ERROR; diff --git a/src/platform/silabs/rs911x/BLEManagerImpl.cpp b/src/platform/silabs/rs911x/BLEManagerImpl.cpp index 75f118b38a99a4..a7907cb388a126 100644 --- a/src/platform/silabs/rs911x/BLEManagerImpl.cpp +++ b/src/platform/silabs/rs911x/BLEManagerImpl.cpp @@ -700,7 +700,7 @@ CHIP_ERROR BLEManagerImpl::StartAdvertising(void) mFlags.Clear(Flags::kRestartAdvertising); sl_wfx_mac_address_t macaddr; - wfx_get_wifi_mac_addr(SL_WFX_STA_INTERFACE, &macaddr); + GetMacAddress(SL_WFX_STA_INTERFACE, &macaddr); status = sInstance.SendBLEAdvertisementCommand(); diff --git a/src/platform/silabs/wifi/WifiInterfaceAbstraction.cpp b/src/platform/silabs/wifi/WifiInterfaceAbstraction.cpp index e0a7ae77cf8d5c..632b58f328469b 100644 --- a/src/platform/silabs/wifi/WifiInterfaceAbstraction.cpp +++ b/src/platform/silabs/wifi/WifiInterfaceAbstraction.cpp @@ -128,7 +128,7 @@ void sl_matter_wifi_task_started(void) evt.header.id = to_underlying(WifiEvent::kStartUp); evt.header.length = sizeof evt; evt.body.status = 0; - wfx_get_wifi_mac_addr(SL_WFX_STA_INTERFACE, &mac); + GetMacAddress(SL_WFX_STA_INTERFACE, &mac); memcpy(&evt.body.mac_addr[0], &mac.octet[0], kWifiMacAddressLength); HandleWFXSystemEvent((sl_wfx_generic_message_t *) &evt); diff --git a/src/platform/silabs/wifi/WifiInterfaceAbstraction.h b/src/platform/silabs/wifi/WifiInterfaceAbstraction.h index 7f17efb9aad7b1..89f391fabc99f0 100644 --- a/src/platform/silabs/wifi/WifiInterfaceAbstraction.h +++ b/src/platform/silabs/wifi/WifiInterfaceAbstraction.h @@ -216,11 +216,21 @@ void NotifyDisconnection(WifiDisconnectionReasons reason); */ void NotifyConnection(sl_wfx_mac_address_t * ap); +/** + * @brief Returns the provide interfaces MAC address + * Valid buffer large enough for the MAC address must be provided to the function + * + * @param[in] interface SL_WFX_STA_INTERFACE or SL_WFX_SOFTAP_INTERFACE. + * If soft AP is not enabled, the interface is ignored and the function always returns the Station MAC + * address + * @param[out] addr Interface MAC addres + */ +void GetMacAddress(sl_wfx_interface_t interface, sl_wfx_mac_address_t * addr); + /* Function to update */ sl_status_t wfx_wifi_start(void); void wfx_enable_sta_mode(void); -void wfx_get_wifi_mac_addr(sl_wfx_interface_t interface, sl_wfx_mac_address_t * addr); void wfx_set_wifi_provision(wfx_wifi_provision_t * wifiConfig); bool wfx_get_wifi_provision(wfx_wifi_provision_t * wifiConfig); bool wfx_is_sta_mode_enabled(void); diff --git a/src/platform/silabs/wifi/lwip-support/ethernetif.cpp b/src/platform/silabs/wifi/lwip-support/ethernetif.cpp index c37d6ab93337e8..7834957e2a97fe 100644 --- a/src/platform/silabs/wifi/lwip-support/ethernetif.cpp +++ b/src/platform/silabs/wifi/lwip-support/ethernetif.cpp @@ -90,7 +90,7 @@ static void low_level_init(struct netif * netif) /* Set netif MAC hardware address */ sl_wfx_mac_address_t mac_addr; - wfx_get_wifi_mac_addr(SL_WFX_STA_INTERFACE, &mac_addr); + GetMacAddress(SL_WFX_STA_INTERFACE, &mac_addr); netif->hwaddr[0] = mac_addr.octet[0]; netif->hwaddr[1] = mac_addr.octet[1]; diff --git a/src/platform/silabs/wifi/wf200/WifiInterface.cpp b/src/platform/silabs/wifi/wf200/WifiInterface.cpp index 1d55145041c5d9..f47eaec83fa3f8 100644 --- a/src/platform/silabs/wifi/wf200/WifiInterface.cpp +++ b/src/platform/silabs/wifi/wf200/WifiInterface.cpp @@ -1087,7 +1087,7 @@ sl_status_t wfx_connect_to_ap(void) * @param[in] interface: * @param[in] addr : address *****************************************************************************/ -void wfx_get_wifi_mac_addr(sl_wfx_interface_t interface, sl_wfx_mac_address_t * addr) +void GetMacAddress(sl_wfx_interface_t interface, sl_wfx_mac_address_t * addr) { sl_wfx_mac_address_t * mac; diff --git a/src/platform/silabs/wifi/wiseconnect-abstraction/WiseconnectInterfaceAbstraction.cpp b/src/platform/silabs/wifi/wiseconnect-abstraction/WiseconnectInterfaceAbstraction.cpp index 4acd2a96f0d957..19224e599f63ab 100644 --- a/src/platform/silabs/wifi/wiseconnect-abstraction/WiseconnectInterfaceAbstraction.cpp +++ b/src/platform/silabs/wifi/wiseconnect-abstraction/WiseconnectInterfaceAbstraction.cpp @@ -85,7 +85,7 @@ bool wfx_is_sta_mode_enabled(void) } /********************************************************************* - * @fn void wfx_get_wifi_mac_addr(sl_wfx_interface_t interface, sl_wfx_mac_address_t *addr) + * @fn void GetMacAddress(sl_wfx_interface_t interface, sl_wfx_mac_address_t *addr) * @brief * get the wifi mac address * @param[in] Interface: @@ -93,7 +93,7 @@ bool wfx_is_sta_mode_enabled(void) * @return * None ***********************************************************************/ -void wfx_get_wifi_mac_addr(sl_wfx_interface_t interface, sl_wfx_mac_address_t * addr) +void GetMacAddress(sl_wfx_interface_t interface, sl_wfx_mac_address_t * addr) { VerifyOrReturn(addr != nullptr); #ifdef SL_WFX_CONFIG_SOFTAP From 7f8bcd344e0d4c48bb5ddaaa56458f2307867a3b Mon Sep 17 00:00:00 2001 From: Mathieu Kardous Date: Fri, 29 Nov 2024 14:59:23 -0500 Subject: [PATCH 4/9] Refactor Mac Address handling --- examples/platform/silabs/efr32/BUILD.gn | 3 +- examples/platform/silabs/uart.cpp | 2 +- .../silabs/ConfigurationManagerImpl.cpp | 7 ++- src/platform/silabs/rs911x/BLEManagerImpl.cpp | 3 -- .../silabs/wifi/SiWx/WifiInterface.cpp | 8 ++-- .../silabs/wifi/WifiInterfaceAbstraction.cpp | 20 ++++++--- .../silabs/wifi/WifiInterfaceAbstraction.h | 23 ++++++---- .../silabs/wifi/lwip-support/ethernetif.cpp | 12 +---- .../silabs/wifi/rs911x/WifiInterface.cpp | 12 ++--- .../silabs/wifi/wf200/WifiInterface.cpp | 45 +++++++------------ src/platform/silabs/wifi/wfx_msgs.h | 4 -- .../WiseconnectInterfaceAbstraction.cpp | 32 ++++++------- 12 files changed, 76 insertions(+), 95 deletions(-) diff --git a/examples/platform/silabs/efr32/BUILD.gn b/examples/platform/silabs/efr32/BUILD.gn index 7b9dccf7ccaa06..46cfae71ecef99 100644 --- a/examples/platform/silabs/efr32/BUILD.gn +++ b/examples/platform/silabs/efr32/BUILD.gn @@ -174,7 +174,8 @@ source_set("efr32-common") { "${silabs_common_plat_dir}/syscalls_stubs.cpp", ] - if (chip_enable_pw_rpc || chip_build_libshell || enable_openthread_cli) { + if (chip_enable_pw_rpc || chip_build_libshell || enable_openthread_cli || + sl_uart_log_output) { sources += [ "${silabs_common_plat_dir}/uart.cpp" ] } diff --git a/examples/platform/silabs/uart.cpp b/examples/platform/silabs/uart.cpp index 809c4e53e05b7a..5bf9eeb51da156 100644 --- a/examples/platform/silabs/uart.cpp +++ b/examples/platform/silabs/uart.cpp @@ -53,7 +53,7 @@ extern "C" { #endif #include "sl_uartdrv_instances.h" #if SL_WIFI -#include +#include #endif // SL_WIFI #ifdef SL_CATALOG_UARTDRV_EUSART_PRESENT #include "sl_uartdrv_eusart_vcom_config.h" diff --git a/src/platform/silabs/ConfigurationManagerImpl.cpp b/src/platform/silabs/ConfigurationManagerImpl.cpp index a5d58d16bf236e..5e38cabd4b363a 100644 --- a/src/platform/silabs/ConfigurationManagerImpl.cpp +++ b/src/platform/silabs/ConfigurationManagerImpl.cpp @@ -313,11 +313,10 @@ void ConfigurationManagerImpl::DoFactoryReset(intptr_t arg) #ifdef SL_WIFI CHIP_ERROR ConfigurationManagerImpl::GetPrimaryWiFiMACAddress(uint8_t * buf) { - sl_wfx_mac_address_t macaddr; - GetMacAddress(SL_WFX_STA_INTERFACE, &macaddr); - memcpy(buf, &macaddr.octet[0], sizeof(macaddr.octet)); + VerifyOrReturnError(buf != nullptr, CHIP_ERROR_INVALID_ARGUMENT); - return CHIP_NO_ERROR; + MutableByteSpan byteSpan(buf, kPrimaryMACAddressLength); + return GetMacAddress(SL_WFX_STA_INTERFACE, byteSpan); } #endif diff --git a/src/platform/silabs/rs911x/BLEManagerImpl.cpp b/src/platform/silabs/rs911x/BLEManagerImpl.cpp index a7907cb388a126..90103f74e77758 100644 --- a/src/platform/silabs/rs911x/BLEManagerImpl.cpp +++ b/src/platform/silabs/rs911x/BLEManagerImpl.cpp @@ -699,9 +699,6 @@ CHIP_ERROR BLEManagerImpl::StartAdvertising(void) mFlags.Clear(Flags::kRestartAdvertising); - sl_wfx_mac_address_t macaddr; - GetMacAddress(SL_WFX_STA_INTERFACE, &macaddr); - status = sInstance.SendBLEAdvertisementCommand(); if (status == RSI_SUCCESS) diff --git a/src/platform/silabs/wifi/SiWx/WifiInterface.cpp b/src/platform/silabs/wifi/SiWx/WifiInterface.cpp index 10093e25a92d1f..754ec9bed2dd0d 100644 --- a/src/platform/silabs/wifi/SiWx/WifiInterface.cpp +++ b/src/platform/silabs/wifi/SiWx/WifiInterface.cpp @@ -257,7 +257,7 @@ sl_status_t sl_wifi_siwx917_init(void) ChipLogDetail(DeviceLayer, "Firmware version is: %x%x.%d.%d.%d.%d.%d.%d", version.chip_id, version.rom_id, version.major, version.minor, version.security_version, version.patch_num, version.customer_id, version.build_num); - status = sl_wifi_get_mac_address(SL_WIFI_CLIENT_INTERFACE, (sl_mac_address_t *) &wfx_rsi.sta_mac.octet[0]); + status = sl_wifi_get_mac_address(SL_WIFI_CLIENT_INTERFACE, reinterpret_cast(wfx_rsi.sta_mac.data())); VerifyOrReturnError(status == SL_STATUS_OK, status, ChipLogError(DeviceLayer, "sl_wifi_get_mac_address failed: 0x%lx", static_cast(status))); @@ -300,7 +300,7 @@ sl_status_t ScanCallback(sl_wifi_event_t event, sl_wifi_scan_result_t * scan_res { security = static_cast(scan_result->scan_info[0].security_mode); wfx_rsi.ap_chan = scan_result->scan_info[0].rf_channel; - memcpy(&wfx_rsi.ap_mac.octet, scan_result->scan_info[0].bssid, kWifiMacAddressLength); + memcpy(wfx_rsi.ap_mac.data(), scan_result->scan_info[0].bssid, kWifiMacAddressLength); } osSemaphoreRelease(sScanCompleteSemaphore); @@ -480,7 +480,7 @@ int32_t wfx_rsi_get_ap_info(wfx_wifi_scan_result_t * ap) 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], kWifiMacAddressLength); + memcpy(&ap->bssid[0], wfx_rsi.ap_mac.data(), kWifiMacAddressLength); sl_wifi_get_signal_strength(SL_WIFI_CLIENT_INTERFACE, &rssi); ap->rssi = rssi; return status; @@ -606,7 +606,7 @@ sl_status_t bg_scan_callback_handler(sl_wifi_event_t event, sl_wifi_scan_result_ void NotifyConnectivity(void) { VerifyOrReturn(!hasNotifiedWifiConnectivity); - NotifyConnection(&wfx_rsi.ap_mac); + NotifyConnection(wfx_rsi.ap_mac); hasNotifiedWifiConnectivity = true; } diff --git a/src/platform/silabs/wifi/WifiInterfaceAbstraction.cpp b/src/platform/silabs/wifi/WifiInterfaceAbstraction.cpp index 632b58f328469b..d6ea0beca7006a 100644 --- a/src/platform/silabs/wifi/WifiInterfaceAbstraction.cpp +++ b/src/platform/silabs/wifi/WifiInterfaceAbstraction.cpp @@ -93,7 +93,7 @@ void NotifyDisconnection(WifiDisconnectionReasons reason) HandleWFXSystemEvent((sl_wfx_generic_message_t *) &evt); } -void NotifyConnection(sl_wfx_mac_address_t * ap) +void NotifyConnection(const MacAddress & ap) { sl_wfx_connect_ind_t evt = {}; evt.header.id = to_underlying(WifiEvent::kConnect); @@ -101,7 +101,7 @@ void NotifyConnection(sl_wfx_mac_address_t * ap) #ifdef RS911X_WIFI evt.body.channel = wfx_rsi.ap_chan; #endif - memcpy(&evt.body.mac[0], &ap->octet[0], kWifiMacAddressLength); + std::copy(ap.begin(), ap.end(), evt.body.mac); HandleWFXSystemEvent((sl_wfx_generic_message_t *) &evt); } @@ -117,19 +117,25 @@ void NotifyConnection(sl_wfx_mac_address_t * ap) *************************************************************************************/ void sl_matter_wifi_task_started(void) { - sl_wfx_startup_ind_t evt; - sl_wfx_mac_address_t mac; + sl_wfx_startup_ind_t evt = {}; // Creating a timer which will be used to retry connection with AP sRetryTimer = osTimerNew(RetryConnectionTimerHandler, osTimerOnce, NULL, NULL); VerifyOrReturn(sRetryTimer != NULL); - memset(&evt, 0, sizeof(evt)); evt.header.id = to_underlying(WifiEvent::kStartUp); evt.header.length = sizeof evt; evt.body.status = 0; - GetMacAddress(SL_WFX_STA_INTERFACE, &mac); - memcpy(&evt.body.mac_addr[0], &mac.octet[0], kWifiMacAddressLength); + + // TODO : Remove workwound when sl_wfx_startup_ind_t is unified + // Issue is same structure name but different contents +#if WF200_WIFI + MutableByteSpan macSpan(evt.body.mac_addr[SL_WFX_STA_INTERFACE], kWifiMacAddressLength); +#else + MutableByteSpan macSpan(evt.body.mac_addr, kWifiMacAddressLength); +#endif // WF200_WIFI + + GetMacAddress(SL_WFX_STA_INTERFACE, macSpan); HandleWFXSystemEvent((sl_wfx_generic_message_t *) &evt); } diff --git a/src/platform/silabs/wifi/WifiInterfaceAbstraction.h b/src/platform/silabs/wifi/WifiInterfaceAbstraction.h index 89f391fabc99f0..a9b835369c92ce 100644 --- a/src/platform/silabs/wifi/WifiInterfaceAbstraction.h +++ b/src/platform/silabs/wifi/WifiInterfaceAbstraction.h @@ -19,6 +19,7 @@ #include #include #include +#include #include #include @@ -40,7 +41,7 @@ /* Updated constants */ -constexpr uint8_t kWifiMacAddressLength = 6; +constexpr size_t kWifiMacAddressLength = 6; /* Defines to update */ @@ -57,7 +58,9 @@ constexpr uint8_t kWifiMacAddressLength = 6; #define WFX_MAX_SSID_LENGTH (32) #define MAX_JOIN_RETRIES_COUNT (5) -/* Update Enums */ +/* Updated types */ + +using MacAddress = std::array; enum class WifiEvent : uint8_t { @@ -170,11 +173,11 @@ typedef struct wfx_rsi_s size_t scan_ssid_length; #endif #ifdef SL_WFX_CONFIG_SOFTAP - sl_wfx_mac_address_t softap_mac; + MacAddress softap_mac; #endif - sl_wfx_mac_address_t sta_mac; - sl_wfx_mac_address_t ap_mac; /* To which our STA is connected */ - sl_wfx_mac_address_t ap_bssid; /* To which our STA is connected */ + MacAddress sta_mac; + MacAddress ap_mac; /* To which our STA is connected */ + MacAddress ap_bssid; /* To which our STA is connected */ uint16_t join_retries; uint8_t ip4_addr[4]; /* Not sure if this is enough */ } WfxRsi_t; @@ -214,7 +217,7 @@ void NotifyDisconnection(WifiDisconnectionReasons reason); * * @param[in] ap pointer to the structure that contains the MAC address of the AP */ -void NotifyConnection(sl_wfx_mac_address_t * ap); +void NotifyConnection(const MacAddress & ap); /** * @brief Returns the provide interfaces MAC address @@ -224,8 +227,12 @@ void NotifyConnection(sl_wfx_mac_address_t * ap); * If soft AP is not enabled, the interface is ignored and the function always returns the Station MAC * address * @param[out] addr Interface MAC addres + * + * @return CHIP_ERROR CHIP_NO_ERROR on success + * CHIP_ERROR_BUFFER_TOO_SMALL if the provided ByteSpan size is too small + * */ -void GetMacAddress(sl_wfx_interface_t interface, sl_wfx_mac_address_t * addr); +CHIP_ERROR GetMacAddress(sl_wfx_interface_t interface, chip::MutableByteSpan & addr); /* Function to update */ diff --git a/src/platform/silabs/wifi/lwip-support/ethernetif.cpp b/src/platform/silabs/wifi/lwip-support/ethernetif.cpp index 7834957e2a97fe..9d9115ba4204e3 100644 --- a/src/platform/silabs/wifi/lwip-support/ethernetif.cpp +++ b/src/platform/silabs/wifi/lwip-support/ethernetif.cpp @@ -88,16 +88,8 @@ static void low_level_init(struct netif * netif) netif->hwaddr_len = ETH_HWADDR_LEN; /* Set netif MAC hardware address */ - sl_wfx_mac_address_t mac_addr; - - GetMacAddress(SL_WFX_STA_INTERFACE, &mac_addr); - - netif->hwaddr[0] = mac_addr.octet[0]; - netif->hwaddr[1] = mac_addr.octet[1]; - netif->hwaddr[2] = mac_addr.octet[2]; - netif->hwaddr[3] = mac_addr.octet[3]; - netif->hwaddr[4] = mac_addr.octet[4]; - netif->hwaddr[5] = mac_addr.octet[5]; + chip::MutableByteSpan byteSpan(netif->hwaddr, ETH_HWADDR_LEN); + GetMacAddress(SL_WFX_STA_INTERFACE, byteSpan); /* Set netif maximum transfer unit */ netif->mtu = 1500; diff --git a/src/platform/silabs/wifi/rs911x/WifiInterface.cpp b/src/platform/silabs/wifi/rs911x/WifiInterface.cpp index 049c5b3b5bec85..e640185600ce98 100644 --- a/src/platform/silabs/wifi/rs911x/WifiInterface.cpp +++ b/src/platform/silabs/wifi/rs911x/WifiInterface.cpp @@ -154,7 +154,7 @@ int32_t wfx_rsi_get_ap_info(wfx_wifi_scan_result_t * ap) uint8_t rssi; ap->security = wfx_rsi.sec.security; ap->chan = wfx_rsi.ap_chan; - memcpy(&ap->bssid[0], &wfx_rsi.ap_mac.octet[0], kWifiMacAddressLength); + memcpy(&ap->bssid[0], wfx_rsi.ap_mac.data(), kWifiMacAddressLength); status = rsi_wlan_get(RSI_RSSI, &rssi, sizeof(rssi)); if (status == RSI_SUCCESS) { @@ -375,14 +375,14 @@ static int32_t sl_matter_wifi_init(void) /* 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) + if ((status = rsi_wlan_get(RSI_MAC_ADDRESS, wfx_rsi.sta_mac.data(), RESP_BUFF_SIZE)) != RSI_SUCCESS) { ChipLogError(DeviceLayer, "rsi_wlan_get(RSI_MAC_ADDRESS) failed: %ld", status); return status; } - ChipLogDetail(DeviceLayer, "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, "MAC: %02x:%02x:%02x %02x:%02x:%02x", wfx_rsi.sta_mac.at(0), wfx_rsi.sta_mac.at(1), + wfx_rsi.sta_mac.at(2), wfx_rsi.sta_mac.at(3), wfx_rsi.sta_mac.at(4), wfx_rsi.sta_mac.at(5)); // Create the message queue sWifiEventQueue = osMessageQueueNew(WFX_QUEUE_SIZE, sizeof(WifiPlatformEvent), NULL); @@ -451,7 +451,7 @@ static void wfx_rsi_save_ap_info(void) // translation } wfx_rsi.sec.security = WFX_SEC_UNSPECIFIED; wfx_rsi.ap_chan = rsp.scan_info->rf_channel; - memcpy(&wfx_rsi.ap_mac.octet[0], &rsp.scan_info->bssid[0], kWifiMacAddressLength); + memcpy(wfx_rsi.ap_mac.data(), &rsp.scan_info->bssid[0], kWifiMacAddressLength); switch (rsp.scan_info->security_mode) { @@ -563,7 +563,7 @@ void NotifyConnectivity(void) { if (!hasNotifiedWifiConnectivity) { - NotifyConnection(&wfx_rsi.ap_mac); + NotifyConnection(wfx_rsi.ap_mac); hasNotifiedWifiConnectivity = true; } } diff --git a/src/platform/silabs/wifi/wf200/WifiInterface.cpp b/src/platform/silabs/wifi/wf200/WifiInterface.cpp index f47eaec83fa3f8..b4abf8a14f535e 100644 --- a/src/platform/silabs/wifi/wf200/WifiInterface.cpp +++ b/src/platform/silabs/wifi/wf200/WifiInterface.cpp @@ -58,7 +58,7 @@ StaticEventGroup_t wfxEventGroup; EventGroupHandle_t sl_wfx_event_group; TaskHandle_t wfx_events_task_handle; -static sl_wfx_mac_address_t ap_mac; +static MacAddress ap_mac; static uint32_t sta_ip; static wfx_wifi_scan_result_t ap_info; @@ -92,9 +92,6 @@ static wfx_wifi_scan_result_t ap_info; #define STA_IP_FAIL (0) #define WLAN_TASK_PRIORITY (1) -/***************************************************************************** - * macros - ******************************************************************************/ #define WE_ST_STARTED 1 #define WE_ST_STA_CONN 2 #define WE_ST_HW_STARTED 4 @@ -295,6 +292,19 @@ sl_status_t get_all_counters(void) } // namespace +CHIP_ERROR GetMacAddress(sl_wfx_interface_t interface, MutableByteSpan & address) +{ + VerifyOrReturnError(address.size() >= kWifiMacAddressLength, CHIP_ERROR_BUFFER_TOO_SMALL); + +#ifdef SL_WFX_CONFIG_SOFTAP + chip::ByteSpan byteSpan((interface == SL_WFX_SOFTAP_INTERFACE) ? wifiContext.mac_addr_1.octet : wifiContext.mac_addr_0.octet); +#else + chip::ByteSpan byteSpan(wifiContext.mac_addr_0.octet); +#endif + + return CopySpanToMutableSpan(byteSpan, address); +} + /*************************************************************************** * @brief * Creates WFX events processing task. @@ -518,7 +528,7 @@ static void sl_wfx_connect_callback(sl_wfx_connect_ind_body_t connect_indication { case WFM_STATUS_SUCCESS: { ChipLogProgress(DeviceLayer, "STA-Connected"); - memcpy(&ap_mac.octet[0], mac, kWifiMacAddressLength); + memcpy(ap_mac.data(), mac, kWifiMacAddressLength); sl_wfx_context->state = static_cast(static_cast(sl_wfx_context->state) | static_cast(SL_WFX_STA_INTERFACE_CONNECTED)); xEventGroupSetBits(sl_wfx_event_group, SL_WFX_CONNECT); @@ -695,7 +705,7 @@ static void wfx_events_task(void * p_arg) if (!hasNotifiedWifiConnectivity) { ChipLogProgress(DeviceLayer, "will notify WiFi connectivity"); - NotifyConnection(&ap_mac); + NotifyConnection(ap_mac); hasNotifiedWifiConnectivity = true; } } @@ -711,7 +721,7 @@ static void wfx_events_task(void * p_arg) hasNotifiedIPV6 = true; if (!hasNotifiedWifiConnectivity) { - NotifyConnection(&ap_mac); + NotifyConnection(ap_mac); hasNotifiedWifiConnectivity = true; } } @@ -1081,27 +1091,6 @@ sl_status_t wfx_connect_to_ap(void) return result; } -/**************************************************************************** - * @brief - * get the wifi mac addresss - * @param[in] interface: - * @param[in] addr : address - *****************************************************************************/ -void GetMacAddress(sl_wfx_interface_t interface, sl_wfx_mac_address_t * addr) -{ - sl_wfx_mac_address_t * mac; - -#ifdef SL_WFX_CONFIG_SOFTAP - mac = (interface == SL_WFX_SOFTAP_INTERFACE) ? &wifiContext.mac_addr_1 : &wifiContext.mac_addr_0; -#else - mac = &wifiContext.mac_addr_0; -#endif - *addr = *mac; - 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); -} - /**************************************************************************** * @brief * function called when driver have ipv4 address diff --git a/src/platform/silabs/wifi/wfx_msgs.h b/src/platform/silabs/wifi/wfx_msgs.h index 8154c32d1edd27..5cef9a38ac2c95 100644 --- a/src/platform/silabs/wifi/wfx_msgs.h +++ b/src/platform/silabs/wifi/wfx_msgs.h @@ -27,10 +27,6 @@ #include "sl_wfx_constants.h" #else -typedef struct -{ - uint8_t octet[6]; ///< Table to store a MAC address -} sl_wfx_mac_address_t; /** * @brief General Message header structure * diff --git a/src/platform/silabs/wifi/wiseconnect-abstraction/WiseconnectInterfaceAbstraction.cpp b/src/platform/silabs/wifi/wiseconnect-abstraction/WiseconnectInterfaceAbstraction.cpp index 19224e599f63ab..f0b863419855d0 100644 --- a/src/platform/silabs/wifi/wiseconnect-abstraction/WiseconnectInterfaceAbstraction.cpp +++ b/src/platform/silabs/wifi/wiseconnect-abstraction/WiseconnectInterfaceAbstraction.cpp @@ -37,6 +37,19 @@ constexpr osThreadAttr_t kWlanTaskAttr = { .name = "wlan_rsi", } // namespace +CHIP_ERROR GetMacAddress(sl_wfx_interface_t interface, chip::MutableByteSpan & address) +{ + VerifyOrReturnError(address.size() >= kWifiMacAddressLength, CHIP_ERROR_BUFFER_TOO_SMALL); + +#ifdef SL_WFX_CONFIG_SOFTAP + chip::ByteSpan byteSpan((interface == SL_WFX_SOFTAP_INTERFACE) ? wfx_rsi.softap_mac : wfx_rsi.sta_mac); +#else + chip::ByteSpan byteSpan(wfx_rsi.sta_mac); +#endif + + return CopySpanToMutableSpan(byteSpan, address); +} + /********************************************************************* * @fn sl_status_t wfx_wifi_start(void) * @brief @@ -84,25 +97,6 @@ bool wfx_is_sta_mode_enabled(void) return wfx_rsi.dev_state.Has(WifiState::kStationMode); } -/********************************************************************* - * @fn void GetMacAddress(sl_wfx_interface_t interface, sl_wfx_mac_address_t *addr) - * @brief - * get the wifi mac address - * @param[in] Interface: - * @param[in] addr : address - * @return - * None - ***********************************************************************/ -void GetMacAddress(sl_wfx_interface_t interface, sl_wfx_mac_address_t * addr) -{ - VerifyOrReturn(addr != nullptr); -#ifdef SL_WFX_CONFIG_SOFTAP - *addr = (interface == SL_WFX_SOFTAP_INTERFACE) ? wfx_rsi.softap_mac : wfx_rsi.sta_mac; -#else - *addr = wfx_rsi.sta_mac; -#endif -} - /********************************************************************* * @fn void wfx_set_wifi_provision(wfx_wifi_provision_t *cfg) * @brief From a36bc922cc2b75177f6b78c03e6560a1f98e24a9 Mon Sep 17 00:00:00 2001 From: Mathieu Kardous Date: Fri, 29 Nov 2024 23:36:14 -0500 Subject: [PATCH 5/9] Fix wf200 init --- src/platform/silabs/PlatformManagerImpl.cpp | 2 ++ src/platform/silabs/wifi/wf200/WifiInterface.cpp | 3 --- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/src/platform/silabs/PlatformManagerImpl.cpp b/src/platform/silabs/PlatformManagerImpl.cpp index b1fbe60634348d..b81b7c6cc13aa1 100644 --- a/src/platform/silabs/PlatformManagerImpl.cpp +++ b/src/platform/silabs/PlatformManagerImpl.cpp @@ -155,6 +155,8 @@ void HandleWFXSystemEvent(sl_wfx_generic_message_t * eventData) case to_underlying(WifiEvent::kStartUp): memcpy(&event.Platform.WFXSystemEvent.data.startupEvent, eventData, sizeof(event.Platform.WFXSystemEvent.data.startupEvent)); + // TODO: This is a workaround until we unify the Matter Data structures + event.Platform.WFXSystemEvent.data.startupEvent.header.id = to_underlying(WifiEvent::kStartUp); break; case to_underlying(WifiEvent::kConnect): diff --git a/src/platform/silabs/wifi/wf200/WifiInterface.cpp b/src/platform/silabs/wifi/wf200/WifiInterface.cpp index b4abf8a14f535e..b4c9d5a731926a 100644 --- a/src/platform/silabs/wifi/wf200/WifiInterface.cpp +++ b/src/platform/silabs/wifi/wf200/WifiInterface.cpp @@ -336,9 +336,6 @@ extern "C" sl_status_t sl_wfx_host_process_event(sl_wfx_generic_message_t * even /******** INDICATION ********/ case SL_WFX_STARTUP_IND_ID: { ChipLogProgress(DeviceLayer, "startup completed."); - - // TODO: This is a workaround until we unify the Matter Data structures - event_payload->header.id = to_underlying(WifiEvent::kStartUp); HandleWFXSystemEvent(event_payload); break; } From 19b91842eacbdde6b48e3a39d0202021c55a6322 Mon Sep 17 00:00:00 2001 From: "Restyled.io" Date: Mon, 2 Dec 2024 16:55:33 +0000 Subject: [PATCH 6/9] Restyled by clang-format --- src/platform/silabs/wifi/SiWx/WifiInterface.cpp | 2 +- src/platform/silabs/wifi/rs911x/WifiInterface.cpp | 2 +- src/platform/silabs/wifi/wf200/WifiInterface.cpp | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/platform/silabs/wifi/SiWx/WifiInterface.cpp b/src/platform/silabs/wifi/SiWx/WifiInterface.cpp index 754ec9bed2dd0d..7ff167fc718813 100644 --- a/src/platform/silabs/wifi/SiWx/WifiInterface.cpp +++ b/src/platform/silabs/wifi/SiWx/WifiInterface.cpp @@ -839,7 +839,7 @@ void wfx_dhcp_got_ipv4(uint32_t ip) /* * Acquire the new IP address */ - wfx_rsi.ip4_addr[0] = (ip) & 0xFF; + wfx_rsi.ip4_addr[0] = (ip) &0xFF; wfx_rsi.ip4_addr[1] = (ip >> 8) & 0xFF; wfx_rsi.ip4_addr[2] = (ip >> 16) & 0xFF; wfx_rsi.ip4_addr[3] = (ip >> 24) & 0xFF; diff --git a/src/platform/silabs/wifi/rs911x/WifiInterface.cpp b/src/platform/silabs/wifi/rs911x/WifiInterface.cpp index e640185600ce98..fa0fac5482a505 100644 --- a/src/platform/silabs/wifi/rs911x/WifiInterface.cpp +++ b/src/platform/silabs/wifi/rs911x/WifiInterface.cpp @@ -818,7 +818,7 @@ void wfx_dhcp_got_ipv4(uint32_t ip) /* * Acquire the new IP address */ - wfx_rsi.ip4_addr[0] = (ip) & 0xFF; + wfx_rsi.ip4_addr[0] = (ip) &0xFF; wfx_rsi.ip4_addr[1] = (ip >> 8) & 0xFF; wfx_rsi.ip4_addr[2] = (ip >> 16) & 0xFF; wfx_rsi.ip4_addr[3] = (ip >> 24) & 0xFF; diff --git a/src/platform/silabs/wifi/wf200/WifiInterface.cpp b/src/platform/silabs/wifi/wf200/WifiInterface.cpp index b4c9d5a731926a..d93bb170111081 100644 --- a/src/platform/silabs/wifi/wf200/WifiInterface.cpp +++ b/src/platform/silabs/wifi/wf200/WifiInterface.cpp @@ -1198,7 +1198,7 @@ void wfx_dhcp_got_ipv4(uint32_t ip) */ uint8_t ip4_addr[4]; - ip4_addr[0] = (ip) & 0xFF; + ip4_addr[0] = (ip) &0xFF; ip4_addr[1] = (ip >> 8) & 0xFF; ip4_addr[2] = (ip >> 16) & 0xFF; ip4_addr[3] = (ip >> 24) & 0xFF; From 940d576ba7d569b56379fe609accfefa639c0e4e Mon Sep 17 00:00:00 2001 From: Mathieu Kardous Date: Mon, 2 Dec 2024 12:07:10 -0500 Subject: [PATCH 7/9] add init value workaroudn --- src/platform/silabs/PlatformManagerImpl.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/platform/silabs/PlatformManagerImpl.cpp b/src/platform/silabs/PlatformManagerImpl.cpp index b81b7c6cc13aa1..7b33b934b3664d 100644 --- a/src/platform/silabs/PlatformManagerImpl.cpp +++ b/src/platform/silabs/PlatformManagerImpl.cpp @@ -152,6 +152,10 @@ void HandleWFXSystemEvent(sl_wfx_generic_message_t * eventData) switch (eventData->header.id) { +// TODO: Work around until we unify the data structures behind a Matter level common structure +#if WF200_WIFI + case SL_WFX_STARTUP_IND_ID: +#endif case to_underlying(WifiEvent::kStartUp): memcpy(&event.Platform.WFXSystemEvent.data.startupEvent, eventData, sizeof(event.Platform.WFXSystemEvent.data.startupEvent)); From e491ff213f9fa62094cb965f33e6857b2951eed0 Mon Sep 17 00:00:00 2001 From: Mathieu Kardous <84793247+mkardous-silabs@users.noreply.github.com> Date: Mon, 2 Dec 2024 19:51:22 -0500 Subject: [PATCH 8/9] Update src/platform/silabs/wifi/wiseconnect-abstraction/WiseconnectInterfaceAbstraction.h Co-authored-by: Junior Martinez <67972863+jmartinez-silabs@users.noreply.github.com> --- .../wiseconnect-abstraction/WiseconnectInterfaceAbstraction.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/platform/silabs/wifi/wiseconnect-abstraction/WiseconnectInterfaceAbstraction.h b/src/platform/silabs/wifi/wiseconnect-abstraction/WiseconnectInterfaceAbstraction.h index d593fd0d098e31..2df67dcd037bfd 100644 --- a/src/platform/silabs/wifi/wiseconnect-abstraction/WiseconnectInterfaceAbstraction.h +++ b/src/platform/silabs/wifi/wiseconnect-abstraction/WiseconnectInterfaceAbstraction.h @@ -29,7 +29,7 @@ enum class WifiPlatformEvent : uint8_t kStationDisconnect = 2, kAPStart = 3, kAPStop = 4, - kScan = 5, /* This is used as scan result and start */ + kScan = 5, /* This combines the scan start and scan result events */ kStationStartJoin = 6, kStationDoDhcp = 7, kStationDhcpDone = 8, From f3c8247b10e5f926c8ff2642afe9bb413f9aa2c4 Mon Sep 17 00:00:00 2001 From: Mathieu Kardous Date: Mon, 2 Dec 2024 19:54:36 -0500 Subject: [PATCH 9/9] start enums at 0 --- .../silabs/wifi/WifiInterfaceAbstraction.h | 14 +++++++------- .../WiseconnectInterfaceAbstraction.h | 18 +++++++++--------- 2 files changed, 16 insertions(+), 16 deletions(-) diff --git a/src/platform/silabs/wifi/WifiInterfaceAbstraction.h b/src/platform/silabs/wifi/WifiInterfaceAbstraction.h index a9b835369c92ce..f89f3fefed532d 100644 --- a/src/platform/silabs/wifi/WifiInterfaceAbstraction.h +++ b/src/platform/silabs/wifi/WifiInterfaceAbstraction.h @@ -64,13 +64,13 @@ using MacAddress = std::array; enum class WifiEvent : uint8_t { - kStartUp = 1, - kConnect = 2, - kDisconnect = 3, - kScanComplete = 4, - kGotIPv4 = 5, - kGotIPv6 = 6, - kLostIP = 7, + kStartUp = 0, + kConnect = 1, + kDisconnect = 2, + kScanComplete = 3, + kGotIPv4 = 4, + kGotIPv6 = 5, + kLostIP = 6, }; enum class WifiState : uint16_t diff --git a/src/platform/silabs/wifi/wiseconnect-abstraction/WiseconnectInterfaceAbstraction.h b/src/platform/silabs/wifi/wiseconnect-abstraction/WiseconnectInterfaceAbstraction.h index 2df67dcd037bfd..5ae23966f5ab61 100644 --- a/src/platform/silabs/wifi/wiseconnect-abstraction/WiseconnectInterfaceAbstraction.h +++ b/src/platform/silabs/wifi/wiseconnect-abstraction/WiseconnectInterfaceAbstraction.h @@ -25,15 +25,15 @@ enum class WifiPlatformEvent : uint8_t { - kStationConnect = 1, - kStationDisconnect = 2, - kAPStart = 3, - kAPStop = 4, - kScan = 5, /* This combines the scan start and scan result events */ - kStationStartJoin = 6, - kStationDoDhcp = 7, - kStationDhcpDone = 8, - kStationDhcpPoll = 9, + kStationConnect = 0, + kStationDisconnect = 1, + kAPStart = 2, + kAPStop = 3, + kScan = 4, /* This combines the scan start and scan result events */ + kStationStartJoin = 5, + kStationDoDhcp = 6, + kStationDhcpDone = 7, + kStationDhcpPoll = 8, }; void sl_matter_wifi_task(void * arg);