Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SIlabs] Refactor GetMacAddress function and initial clean up of the Notify functions #36693

Merged
merged 9 commits into from
Dec 4, 2024
3 changes: 2 additions & 1 deletion examples/platform/silabs/efr32/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -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" ]
}

Expand Down
2 changes: 1 addition & 1 deletion examples/platform/silabs/uart.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ extern "C" {
#endif
#include "sl_uartdrv_instances.h"
#if SL_WIFI
#include <platform/silabs/wifi/wf200/platform/spi_multiplex.h>
#include <platform/silabs/wifi/ncp/spi_multiplex.h>
#endif // SL_WIFI
#ifdef SL_CATALOG_UARTDRV_EUSART_PRESENT
#include "sl_uartdrv_eusart_vcom_config.h"
Expand Down
20 changes: 0 additions & 20 deletions src/platform/silabs/CHIPDevicePlatformEvent.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 3 additions & 4 deletions src/platform/silabs/ConfigurationManagerImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
73 changes: 29 additions & 44 deletions src/platform/silabs/ConnectivityManagerImpl_WIFI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
}
Expand Down
90 changes: 33 additions & 57 deletions src/platform/silabs/PlatformManagerImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/platform/silabs/PlatformManagerImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
#include <cmsis_os2.h>

#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 {
Expand Down
3 changes: 0 additions & 3 deletions src/platform/silabs/rs911x/BLEManagerImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Loading
Loading