Skip to content

Commit 111beae

Browse files
committed
addressing review comments
1 parent a06555e commit 111beae

File tree

9 files changed

+128
-45
lines changed

9 files changed

+128
-45
lines changed

.github/workflows/silabs-common-build.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ jobs:
1515
runs-on: ubuntu-latest
1616

1717
container:
18-
image: ghcr.io/project-chip/chip-build-efr32:115
18+
image: ghcr.io/project-chip/chip-build-efr32:95
1919

2020
strategy:
2121
matrix:

examples/lighting-app/silabs/include/AppEvent.h

+6
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,12 @@ struct AppEvent
4141
{
4242
uint8_t Action;
4343
} ButtonEvent;
44+
#ifdef DISPLAY_ENABLED
45+
struct
46+
{
47+
void * screen;
48+
} LCDEvent;
49+
#endif
4450
struct
4551
{
4652
void * Context;

examples/platform/silabs/BaseApplication.cpp

+11-7
Original file line numberDiff line numberDiff line change
@@ -252,8 +252,9 @@ void BaseApplicationDelegate::OnCommissioningWindowClosed()
252252
slLCD.GetScreen(screen);
253253
VerifyOrReturn(screen == SilabsLCD::Screen_e::QRCodeScreen);
254254
AppEvent event;
255-
event.Type = AppEvent::kEventType_LCD;
256-
event.Handler = AppTask::GetAppTask().UpdateDisplayHandler;
255+
event.Type = AppEvent::kEventType_LCD;
256+
event.LCDEvent.screen = reinterpret_cast<void *>(static_cast<uintptr_t>(SilabsLCD::Screen_e::DemoScreen));
257+
event.Handler = AppTask::GetAppTask().UpdateDisplayHandler;
257258
BaseApplication::PostEvent(&event);
258259
#endif // QR_CODE_ENABLED
259260
#endif // DISPLAY_ENABLED
@@ -625,8 +626,9 @@ void BaseApplication::ButtonHandler(AppEvent * aEvent)
625626
}
626627

627628
AppEvent event;
628-
event.Type = AppEvent::kEventType_LCD;
629-
event.Handler = AppTask::GetAppTask().UpdateDisplayHandler;
629+
event.Type = AppEvent::kEventType_LCD;
630+
event.LCDEvent.screen = reinterpret_cast<void *>(static_cast<uintptr_t>(SilabsLCD::Screen_e::CycleScreen));
631+
event.Handler = AppTask::GetAppTask().UpdateDisplayHandler;
630632
PostEvent(&event);
631633
}
632634
}
@@ -635,7 +637,8 @@ void BaseApplication::ButtonHandler(AppEvent * aEvent)
635637
void BaseApplication::UpdateDisplayHandler(AppEvent * aEvent)
636638
{
637639
VerifyOrReturn(aEvent->Type == AppEvent::kEventType_LCD);
638-
AppTask::GetAppTask().UpdateDisplay();
640+
SilabsLCD::Screen_e screen = static_cast<SilabsLCD::Screen_e>(reinterpret_cast<uintptr_t>(aEvent->LCDEvent.screen));
641+
(screen == SilabsLCD::Screen_e::CycleScreen) ? AppTask::GetAppTask().UpdateDisplay() : AppTask::GetLCD().SetScreen(screen);
639642
}
640643

641644
void BaseApplication::UpdateDisplay()
@@ -942,8 +945,9 @@ void BaseApplication::OnPlatformEvent(const ChipDeviceEvent * event, intptr_t)
942945
if (screen == SilabsLCD::Screen_e::StatusScreen)
943946
{
944947
AppEvent event;
945-
event.Type = AppEvent::kEventType_LCD;
946-
event.Handler = AppTask::GetAppTask().UpdateDisplayHandler;
948+
event.Type = AppEvent::kEventType_LCD;
949+
event.LCDEvent.screen = reinterpret_cast<void *>(static_cast<uintptr_t>(SilabsLCD::Screen_e::StatusScreen));
950+
event.Handler = AppTask::GetAppTask().UpdateDisplayHandler;
947951
PostEvent(&event);
948952
}
949953
#endif // DISPLAY_ENABLED

examples/platform/silabs/display/lcd.h

+1
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ class SilabsLCD
4040
QRCodeScreen,
4141
#endif
4242
InvalidScreen,
43+
CycleScreen,
4344
} Screen_e;
4445

4546
typedef enum icdMode

src/platform/silabs/wifi/BUILD.gn

+3-1
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,9 @@ source_set("wifi-platform") {
139139
"${silabs_platform_dir}/wifi/SiWx/WifiInterface.cpp",
140140
"${silabs_platform_dir}/wifi/wiseconnect-abstraction/WiseconnectInterfaceAbstraction.cpp",
141141
"${silabs_platform_dir}/wifi/wiseconnect-abstraction/WiseconnectInterfaceAbstraction.h",
142-
"${wifi_sdk_root}/components/service/network_manager/src/sl_net_for_lwip.c",
142+
143+
# Wi-Fi Config - Using the file sdk support until the wiseconnect file is fixed
144+
"${matter_support_root}/sdk-copies/components/service/network_manager/src/sl_net_for_lwip.c",
143145
]
144146

145147
public_deps += [ "${lwip_root}:lwip" ]

src/platform/silabs/wifi/SiWx/WifiInterface.cpp

+91-23
Original file line numberDiff line numberDiff line change
@@ -100,11 +100,16 @@ bool ps_requirement_added = false;
100100
#endif // CHIP_CONFIG_ENABLE_ICD_SERVER
101101

102102
bool hasNotifiedWifiConnectivity = false;
103+
bool hasNotifiedIPV6 = false;
104+
#if (CHIP_DEVICE_CONFIG_ENABLE_IPV4)
105+
bool hasNotifiedIPV4 = false;
106+
#endif /* CHIP_DEVICE_CONFIG_ENABLE_IPV4 */
103107

104108
wfx_wifi_scan_ext_t temp_reset;
105109

106110
osSemaphoreId_t sScanCompleteSemaphore;
107111
osSemaphoreId_t sScanInProgressSemaphore;
112+
osTimerId_t sDHCPTimer;
108113
osMessageQueueId_t sWifiEventQueue = nullptr;
109114

110115
sl_net_wifi_lwip_context_t wifi_client_context;
@@ -203,6 +208,27 @@ constexpr uint8_t kWfxQueueSize = 10;
203208
// TODO: Figure out why we actually need this, we are already handling failure and retries somewhere else.
204209
constexpr uint16_t kWifiScanTimeoutTicks = 10000;
205210

211+
void DHCPTimerEventHandler(void * arg)
212+
{
213+
WifiEvent event = WifiEvent::kStationDhcpPoll;
214+
sl_matter_wifi_post_event(event);
215+
}
216+
217+
void CancelDHCPTimer(void)
218+
{
219+
VerifyOrReturn(osTimerIsRunning(sDHCPTimer), ChipLogDetail(DeviceLayer, "CancelDHCPTimer: timer not running"));
220+
VerifyOrReturn(osTimerStop(sDHCPTimer) == osOK, ChipLogError(DeviceLayer, "CancelDHCPTimer: failed to stop timer"));
221+
}
222+
223+
void StartDHCPTimer(uint32_t timeout)
224+
{
225+
// Cancel timer if already started
226+
CancelDHCPTimer();
227+
228+
VerifyOrReturn(osTimerStart(sDHCPTimer, pdMS_TO_TICKS(timeout)) == osOK,
229+
ChipLogError(DeviceLayer, "StartDHCPTimer: failed to start timer"));
230+
}
231+
206232
sl_status_t sl_wifi_siwx917_init(void)
207233
{
208234
sl_status_t status = SL_STATUS_OK;
@@ -331,10 +357,7 @@ sl_status_t SetWifiConfigurations()
331357
VerifyOrReturnError(status == SL_STATUS_OK, status,
332358
ChipLogError(DeviceLayer, "sl_wifi_set_listen_interval failed: 0x%lx", status));
333359

334-
// This is be triggered on the disconnect use case, providing the amount of TA tries
335-
// Setting the TA retry to 1 and giving the control to the M4 for improved power efficiency
336-
// When max_retry_attempts is set to 0, TA will retry indefinitely.
337-
sl_wifi_advanced_client_configuration_t client_config = { .max_retry_attempts = 1 };
360+
sl_wifi_advanced_client_configuration_t client_config = { .max_retry_attempts = 5 };
338361
status = sl_wifi_set_advanced_client_configuration(SL_WIFI_CLIENT_INTERFACE, &client_config);
339362
VerifyOrReturnError(status == SL_STATUS_OK, status,
340363
ChipLogError(DeviceLayer, "sl_wifi_set_advanced_client_configuration failed: 0x%lx", status));
@@ -491,6 +514,11 @@ sl_status_t sl_matter_wifi_platform_init(void)
491514
sWifiEventQueue = osMessageQueueNew(kWfxQueueSize, sizeof(WifiEvent), nullptr);
492515
VerifyOrReturnError(sWifiEventQueue != nullptr, SL_STATUS_ALLOCATION_FAILED);
493516

517+
// Create timer for DHCP polling
518+
// TODO: Use LWIP timer instead of creating a new one here
519+
sDHCPTimer = osTimerNew(DHCPTimerEventHandler, osTimerPeriodic, nullptr, nullptr);
520+
VerifyOrReturnError(sDHCPTimer != nullptr, SL_STATUS_ALLOCATION_FAILED);
521+
494522
return status;
495523
}
496524

@@ -634,29 +662,53 @@ sl_status_t bg_scan_callback_handler(sl_wifi_event_t event, sl_wifi_scan_result_
634662

635663
/// NotifyConnectivity
636664
/// @brief Notify the application about the connectivity status if it has not been notified yet.
665+
/// Helper function for HandleDHCPPolling.
637666
void NotifyConnectivity(void)
638667
{
639668
VerifyOrReturn(!hasNotifiedWifiConnectivity);
640669
wfx_connected_notify(CONNECTION_STATUS_SUCCESS, &wfx_rsi.ap_mac);
641670
hasNotifiedWifiConnectivity = true;
642671
}
643672

644-
/// NotifySuccessfulConnection
645-
/// @brief Processing function responsible for notifying the upper layers of a succesful connection attempt.
646-
void NotifySuccessfulConnection(void)
673+
void HandleDHCPPolling(void)
647674
{
675+
WifiEvent event;
676+
677+
// TODO: Notify the application that the interface is not set up or Chipdie here because we are in an unkonwn state
648678
struct netif * sta_netif = &wifi_client_context.netif;
649679
VerifyOrReturn(sta_netif != nullptr, ChipLogError(DeviceLayer, "HandleDHCPPolling: failed to get STA netif"));
680+
650681
#if (CHIP_DEVICE_CONFIG_ENABLE_IPV4)
651-
wfx_dhcp_got_ipv4((uint32_t) sta_netif->ip_addr.u_addr.ip4.addr);
682+
uint8_t dhcp_state = dhcpclient_poll(sta_netif);
683+
if (dhcp_state == DHCP_ADDRESS_ASSIGNED && !hasNotifiedIPV4)
684+
{
685+
wfx_dhcp_got_ipv4((uint32_t) sta_netif->ip_addr.u_addr.ip4.addr);
686+
hasNotifiedIPV4 = true;
687+
event = WifiEvent::kStationDhcpDone;
688+
sl_matter_wifi_post_event(event);
689+
NotifyConnectivity();
690+
}
691+
else if (dhcp_state == DHCP_OFF)
692+
{
693+
wfx_ip_changed_notify(IP_STATUS_FAIL);
694+
hasNotifiedIPV4 = false;
695+
}
652696
#endif /* CHIP_DEVICE_CONFIG_ENABLE_IPV4 */
653-
char addrStr[chip::Inet::IPAddress::kMaxStringLength] = { 0 };
654-
VerifyOrReturn(ip6addr_ntoa_r(netif_ip6_addr(sta_netif, 0), addrStr, sizeof(addrStr)) != nullptr);
655-
ChipLogProgress(DeviceLayer, "SLAAC OK: linklocal addr: %s", addrStr);
656-
wfx_ipv6_notify(GET_IPV6_SUCCESS);
657-
NotifyConnectivity();
697+
/* Checks if the assigned IPv6 address is preferred by evaluating
698+
* the first block of IPv6 address ( block 0)
699+
*/
700+
if ((ip6_addr_ispreferred(netif_ip6_addr_state(sta_netif, 0))) && !hasNotifiedIPV6)
701+
{
702+
char addrStr[chip::Inet::IPAddress::kMaxStringLength] = { 0 };
703+
VerifyOrReturn(ip6addr_ntoa_r(netif_ip6_addr(sta_netif, 0), addrStr, sizeof(addrStr)) != nullptr);
704+
ChipLogProgress(DeviceLayer, "SLAAC OK: linklocal addr: %s", addrStr);
705+
wfx_ipv6_notify(GET_IPV6_SUCCESS);
706+
hasNotifiedIPV6 = true;
707+
event = WifiEvent::kStationDhcpDone;
708+
sl_matter_wifi_post_event(event);
709+
NotifyConnectivity();
710+
}
658711
}
659-
660712
void sl_matter_wifi_post_event(WifiEvent event)
661713
{
662714
sl_status_t status = osMessageQueuePut(sWifiEventQueue, &event, 0, 0);
@@ -668,14 +720,19 @@ void sl_matter_wifi_post_event(WifiEvent event)
668720
// Chipdie, etc.
669721
}
670722
}
671-
/// ResetConnectivityNotificationFlags
723+
/// ResetDHCPNotificationFlags
672724
/// @brief Reset the flags that are used to notify the application about DHCP connectivity
673-
/// and emits a WifiEvent::kConnectionComplete event to trigger DHCP polling checks. Helper function for ProcessEvent.
674-
void ResetConnectivityNotificationFlags(void)
725+
/// and emits a WifiEvent::kStationDoDhcp event to trigger DHCP polling checks. Helper function for ProcessEvent.
726+
void ResetDHCPNotificationFlags(void)
675727
{
728+
729+
#if (CHIP_DEVICE_CONFIG_ENABLE_IPV4)
730+
hasNotifiedIPV4 = false;
731+
#endif // CHIP_DEVICE_CONFIG_ENABLE_IPV4
732+
hasNotifiedIPV6 = false;
676733
hasNotifiedWifiConnectivity = false;
677734

678-
WifiEvent event = WifiEvent::kConnectionComplete;
735+
WifiEvent event = WifiEvent::kStationDoDhcp;
679736
sl_matter_wifi_post_event(event);
680737
}
681738

@@ -687,7 +744,7 @@ void ProcessEvent(WifiEvent event)
687744
case WifiEvent::kStationConnect:
688745
ChipLogDetail(DeviceLayer, "WifiEvent::kStationConnect");
689746
wfx_rsi.dev_state.Set(WifiState::kStationConnected);
690-
ResetConnectivityNotificationFlags();
747+
ResetDHCPNotificationFlags();
691748
break;
692749

693750
case WifiEvent::kStationDisconnect: {
@@ -700,7 +757,7 @@ void ProcessEvent(WifiEvent event)
700757
.Clear(WifiState::kStationDhcpDone);
701758

702759
/* TODO: Implement disconnect notify */
703-
ResetConnectivityNotificationFlags();
760+
ResetDHCPNotificationFlags();
704761
#if (CHIP_DEVICE_CONFIG_ENABLE_IPV4)
705762
wfx_ip_changed_notify(0); // for IPV4
706763
wfx_ip_changed_notify(IP_STATUS_FAIL);
@@ -777,9 +834,20 @@ void ProcessEvent(WifiEvent event)
777834
JoinWifiNetwork();
778835
break;
779836

780-
case WifiEvent::kConnectionComplete:
781-
ChipLogDetail(DeviceLayer, "WifiPlatformEvent::kConnectionComplete");
782-
NotifySuccessfulConnection();
837+
case WifiEvent::kStationDoDhcp:
838+
ChipLogDetail(DeviceLayer, "WifiEvent::kStationDoDhcp");
839+
StartDHCPTimer(WFX_RSI_DHCP_POLL_INTERVAL);
840+
break;
841+
842+
case WifiEvent::kStationDhcpDone:
843+
ChipLogDetail(DeviceLayer, "WifiEvent::kStationDhcpDone");
844+
CancelDHCPTimer();
845+
break;
846+
847+
case WifiEvent::kStationDhcpPoll:
848+
ChipLogDetail(DeviceLayer, "WifiEvent::kStationDhcpPoll");
849+
HandleDHCPPolling();
850+
break;
783851

784852
default:
785853
break;

src/platform/silabs/wifi/WifiInterfaceAbstraction.h

+9-9
Original file line numberDiff line numberDiff line change
@@ -87,15 +87,15 @@ enum class WifiState : uint16_t
8787

8888
enum class WifiEvent : uint8_t
8989
{
90-
kStationConnect = 0,
91-
kStationDisconnect = 1,
92-
kAPStart = 2,
93-
kAPStop = 3,
94-
kScan = 4, /* This is used as scan result and start */
95-
kStationStartJoin = 5,
96-
kConnectionComplete = 6,
97-
kStationDhcpDone = 7,
98-
kStationDhcpPoll = 8
90+
kStationConnect = 0,
91+
kStationDisconnect = 1,
92+
kAPStart = 2,
93+
kAPStop = 3,
94+
kScan = 4, /* This is used as scan result and start */
95+
kStationStartJoin = 5,
96+
kStationDoDhcp = 6,
97+
kStationDhcpDone = 7,
98+
kStationDhcpPoll = 8
9999
};
100100

101101
typedef enum

src/platform/silabs/wifi/rs911x/WifiInterface.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -606,7 +606,7 @@ void HandleDHCPPolling(void)
606606

607607
/** ResetDHCPNotificationFlags
608608
* @brief Reset the flags that are used to notify the application about DHCP connectivity
609-
* and emits a WifiEvent::kConnectionComplete event to trigger DHCP polling checks. Helper function for ProcessEvent.
609+
* and emits a WifiEvent::kStationDoDhcp event to trigger DHCP polling checks. Helper function for ProcessEvent.
610610
*/
611611
void ResetDHCPNotificationFlags(void)
612612
{
@@ -618,7 +618,7 @@ void ResetDHCPNotificationFlags(void)
618618
hasNotifiedIPV6 = false;
619619
hasNotifiedWifiConnectivity = false;
620620

621-
outEvent = WifiEvent::kConnectionComplete;
621+
outEvent = WifiEvent::kStationDoDhcp;
622622
sl_matter_wifi_post_event(outEvent);
623623
}
624624

@@ -752,7 +752,7 @@ void ProcessEvent(WifiEvent event)
752752
sl_wifi_platform_join_network();
753753
}
754754
break;
755-
case WifiEvent::kConnectionComplete: {
755+
case WifiEvent::kStationDoDhcp: {
756756
StartDHCPTimer(WFX_RSI_DHCP_POLL_INTERVAL);
757757
}
758758
break;

src/platform/silabs/wifi/rs911x/rs9117.gni

+3-1
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,9 @@ rs9117_src_sapi = [
4444
"${wifi_sdk_root}/components/device/silabs/si91x/wireless/ncp_interface/spi/sl_si91x_spi.c",
4545
"${wifi_sdk_root}/components/device/silabs/si91x/wireless/ncp_interface/sl_si91x_ncp_driver.c",
4646

47+
# Wi-Fi Config - Using the file sdk support until the wiseconnect file is fixed
48+
"${matter_support_root}/sdk-copies/components/service/network_manager/src/sl_net_for_lwip.c",
49+
4750
# wifi component
4851
"${wifi_sdk_root}/components/protocol/wifi/src/sl_wifi_basic_credentials.c",
4952
"${wifi_sdk_root}/components/protocol/wifi/src/sl_wifi_callback_framework.c",
@@ -52,7 +55,6 @@ rs9117_src_sapi = [
5255
# basic_network_manager component
5356
"${wifi_sdk_root}/components/service/network_manager/src/sl_net_credentials.c",
5457
"${wifi_sdk_root}/components/service/network_manager/src/sl_net_basic_profiles.c",
55-
"${wifi_sdk_root}/components/service/network_manager/src/sl_net_for_lwip.c",
5658

5759
# si91x_basic_buffers component
5860
"${wifi_sdk_root}/components/device/silabs/si91x/wireless/memory/malloc_buffers.c",

0 commit comments

Comments
 (0)