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/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/ConfigurationManagerImpl.cpp b/src/platform/silabs/ConfigurationManagerImpl.cpp index 3a144eb1160370..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; - wfx_get_wifi_mac_addr(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/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..7b33b934b3664d 100644 --- a/src/platform/silabs/PlatformManagerImpl.cpp +++ b/src/platform/silabs/PlatformManagerImpl.cpp @@ -141,71 +141,47 @@ 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; - } +// 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)); + // 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): + 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/rs911x/BLEManagerImpl.cpp b/src/platform/silabs/rs911x/BLEManagerImpl.cpp index 75f118b38a99a4..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; - wfx_get_wifi_mac_addr(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 291c9988d83215..7ff167fc718813 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); } @@ -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, BSSID_LEN); + memcpy(wfx_rsi.ap_mac.data(), scan_result->scan_info[0].bssid, kWifiMacAddressLength); } osSemaphoreRelease(sScanCompleteSemaphore); @@ -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 @@ -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.data(), 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,13 +606,13 @@ 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; } 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,13 +624,13 @@ 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(); } else if (dhcp_state == DHCP_OFF) { - wfx_ip_changed_notify(IP_STATUS_FAIL); + NotifyIPv4Change(false); hasNotifiedIPV4 = false; } #endif /* CHIP_DEVICE_CONFIG_ENABLE_IPV4 */ @@ -642,14 +642,14 @@ 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 = 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) @@ -699,24 +699,23 @@ void ProcessEvent(WifiEvent 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; - 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 +760,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 +801,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(); @@ -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..d6ea0beca7006a 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,82 @@ 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(const MacAddress & 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); + std::copy(ap.begin(), ap.end(), evt.body.mac); - HandleWFXSystemEvent(WIFI_EVENT, (sl_wfx_generic_message_t *) &evt); + HandleWFXSystemEvent((sl_wfx_generic_message_t *) &evt); } -/************************************************************************************** - * @fn void wfx_disconnected_notify(int32_t status) +/* Function to update */ + +/*********************************************************************************** + * @fn sl_matter_wifi_task_started(void) * @brief - * notification of disconnection - * @param[in] status: + * Wifi device started notification + * @param[in]: None * @return None *************************************************************************************/ -void wfx_disconnected_notify(int32_t status) +void sl_matter_wifi_task_started(void) { - sl_wfx_disconnect_ind_t evt; + sl_wfx_startup_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); -} + // Creating a timer which will be used to retry connection with AP + sRetryTimer = osTimerNew(RetryConnectionTimerHandler, osTimerOnce, NULL, NULL); + VerifyOrReturn(sRetryTimer != NULL); -/************************************************************************************** - * @fn void wfx_ipv6_notify(int got_ip) - * @brief - * notification of ipv6 - * @param[in] got_ip: - * @return None - *************************************************************************************/ -void wfx_ipv6_notify(int got_ip) -{ - sl_wfx_generic_message_t eventData; + evt.header.id = to_underlying(WifiEvent::kStartUp); + evt.header.length = sizeof evt; + evt.body.status = 0; - 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); -} + // 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 -/************************************************************************************** - * @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; + GetMacAddress(SL_WFX_STA_INTERFACE, macSpan); - 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 012683aef60333..f89f3fefed532d 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 @@ -36,35 +37,41 @@ #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 size_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) +/* Updated types */ + +using MacAddress = std::array; + +enum class WifiEvent : uint8_t +{ + kStartUp = 0, + kConnect = 1, + kDisconnect = 2, + kScanComplete = 3, + kGotIPv4 = 4, + kGotIPv6 = 5, + kLostIP = 6, +}; enum class WifiState : uint16_t { @@ -81,24 +88,16 @@ enum class WifiState : uint16_t kScanStarted = (1 << 10), /* Scan Started */ }; -enum class WifiEvent : uint8_t +enum class WifiDisconnectionReasons : uint16_t // using uint16 to match current structure during the transition { - 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 + 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 }; -typedef enum -{ - WIFI_EVENT, - IP_EVENT, -} wfx_event_base_t; +/* Enums to update */ /* Note that these are same as RSI_security */ typedef enum @@ -135,7 +134,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; @@ -151,13 +150,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 @@ -181,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; @@ -193,9 +185,59 @@ 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(const MacAddress & 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 + * + * @return CHIP_ERROR CHIP_NO_ERROR on success + * CHIP_ERROR_BUFFER_TOO_SMALL if the provided ByteSpan size is too small + * + */ +CHIP_ERROR GetMacAddress(sl_wfx_interface_t interface, chip::MutableByteSpan & 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); @@ -221,8 +263,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); @@ -232,9 +272,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 @@ -261,22 +299,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/lwip-support/ethernetif.cpp b/src/platform/silabs/wifi/lwip-support/ethernetif.cpp index c37d6ab93337e8..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; - - wfx_get_wifi_mac_addr(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 8b811534ca3e20..fa0fac5482a505 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); } @@ -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.data(), kWifiMacAddressLength); status = rsi_wlan_get(RSI_RSSI, &rssi, sizeof(rssi)); if (status == RSI_SUCCESS) { @@ -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); } /************************************************************************************* @@ -375,17 +375,17 @@ 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(WifiEvent), NULL); + sWifiEventQueue = osMessageQueueNew(WFX_QUEUE_SIZE, sizeof(WifiPlatformEvent), NULL); if (sWifiEventQueue == NULL) { return SL_STATUS_ALLOCATION_FAILED; @@ -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.data(), &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,9 +599,9 @@ 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; + NotifyIPv6Change(true); + 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,43 +645,38 @@ 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(); - /* 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 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); 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 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)); @@ -720,9 +715,9 @@ void ProcessEvent(WifiEvent 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 @@ -746,22 +741,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 +785,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(); @@ -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..d93bb170111081 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 }; @@ -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. @@ -326,7 +336,7 @@ 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); + HandleWFXSystemEvent(event_payload); break; } case SL_WFX_CONNECT_IND_ID: { @@ -480,7 +490,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 +525,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.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); @@ -692,23 +702,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 +729,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 +754,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; @@ -1078,27 +1088,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 wfx_get_wifi_mac_addr(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 @@ -1217,7 +1206,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..5cef9a38ac2c95 100644 --- a/src/platform/silabs/wifi/wfx_msgs.h +++ b/src/platform/silabs/wifi/wfx_msgs.h @@ -27,18 +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 -} 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 2266989b906f79..f0b863419855d0 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 @@ -35,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 @@ -82,25 +97,6 @@ bool wfx_is_sta_mode_enabled(void) return wfx_rsi.dev_state.Has(WifiState::kStationMode); } -/********************************************************************* - * @fn void wfx_get_wifi_mac_addr(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 wfx_get_wifi_mac_addr(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 @@ -160,7 +156,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 +323,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..5ae23966f5ab61 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 = 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); -#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(); @@ -44,4 +50,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);