Skip to content

Commit 4c36fe9

Browse files
[CSA-CP] Using the sl_net_for_lwip.c file for connection (#360)
1 parent c77667f commit 4c36fe9

File tree

6 files changed

+38
-110
lines changed

6 files changed

+38
-110
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:95
18+
image: ghcr.io/project-chip/chip-build-efr32:115
1919

2020
strategy:
2121
matrix:

src/platform/silabs/wifi/BUILD.gn

+1-3
Original file line numberDiff line numberDiff line change
@@ -139,9 +139,7 @@ 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-
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",
142+
"${wifi_sdk_root}/components/service/network_manager/src/sl_net_for_lwip.c",
145143
]
146144

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

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

+23-91
Original file line numberDiff line numberDiff line change
@@ -100,16 +100,11 @@ 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 */
107103

108104
wfx_wifi_scan_ext_t temp_reset;
109105

110106
osSemaphoreId_t sScanCompleteSemaphore;
111107
osSemaphoreId_t sScanInProgressSemaphore;
112-
osTimerId_t sDHCPTimer;
113108
osMessageQueueId_t sWifiEventQueue = nullptr;
114109

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

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-
232206
sl_status_t sl_wifi_siwx917_init(void)
233207
{
234208
sl_status_t status = SL_STATUS_OK;
@@ -357,7 +331,10 @@ sl_status_t SetWifiConfigurations()
357331
VerifyOrReturnError(status == SL_STATUS_OK, status,
358332
ChipLogError(DeviceLayer, "sl_wifi_set_listen_interval failed: 0x%lx", status));
359333

360-
sl_wifi_advanced_client_configuration_t client_config = { .max_retry_attempts = 5 };
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 };
361338
status = sl_wifi_set_advanced_client_configuration(SL_WIFI_CLIENT_INTERFACE, &client_config);
362339
VerifyOrReturnError(status == SL_STATUS_OK, status,
363340
ChipLogError(DeviceLayer, "sl_wifi_set_advanced_client_configuration failed: 0x%lx", status));
@@ -514,11 +491,6 @@ sl_status_t sl_matter_wifi_platform_init(void)
514491
sWifiEventQueue = osMessageQueueNew(kWfxQueueSize, sizeof(WifiEvent), nullptr);
515492
VerifyOrReturnError(sWifiEventQueue != nullptr, SL_STATUS_ALLOCATION_FAILED);
516493

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-
522494
return status;
523495
}
524496

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

663635
/// NotifyConnectivity
664636
/// @brief Notify the application about the connectivity status if it has not been notified yet.
665-
/// Helper function for HandleDHCPPolling.
666637
void NotifyConnectivity(void)
667638
{
668639
VerifyOrReturn(!hasNotifiedWifiConnectivity);
669640
wfx_connected_notify(CONNECTION_STATUS_SUCCESS, &wfx_rsi.ap_mac);
670641
hasNotifiedWifiConnectivity = true;
671642
}
672643

673-
void HandleDHCPPolling(void)
644+
/// NotifySuccessfulConnection
645+
/// @brief Processing function responsible for notifying the upper layers of a succesful connection attempt.
646+
void NotifySuccessfulConnection(void)
674647
{
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
678648
struct netif * sta_netif = &wifi_client_context.netif;
679649
VerifyOrReturn(sta_netif != nullptr, ChipLogError(DeviceLayer, "HandleDHCPPolling: failed to get STA netif"));
680-
681650
#if (CHIP_DEVICE_CONFIG_ENABLE_IPV4)
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-
}
651+
wfx_dhcp_got_ipv4((uint32_t) sta_netif->ip_addr.u_addr.ip4.addr);
696652
#endif /* CHIP_DEVICE_CONFIG_ENABLE_IPV4 */
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-
}
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();
711658
}
659+
712660
void sl_matter_wifi_post_event(WifiEvent event)
713661
{
714662
sl_status_t status = osMessageQueuePut(sWifiEventQueue, &event, 0, 0);
@@ -720,19 +668,14 @@ void sl_matter_wifi_post_event(WifiEvent event)
720668
// Chipdie, etc.
721669
}
722670
}
723-
/// ResetDHCPNotificationFlags
671+
/// ResetConnectivityNotificationFlags
724672
/// @brief Reset the flags that are used to notify the application about DHCP connectivity
725-
/// and emits a WifiEvent::kStationDoDhcp event to trigger DHCP polling checks. Helper function for ProcessEvent.
726-
void ResetDHCPNotificationFlags(void)
673+
/// and emits a WifiEvent::kConnectionComplete event to trigger DHCP polling checks. Helper function for ProcessEvent.
674+
void ResetConnectivityNotificationFlags(void)
727675
{
728-
729-
#if (CHIP_DEVICE_CONFIG_ENABLE_IPV4)
730-
hasNotifiedIPV4 = false;
731-
#endif // CHIP_DEVICE_CONFIG_ENABLE_IPV4
732-
hasNotifiedIPV6 = false;
733676
hasNotifiedWifiConnectivity = false;
734677

735-
WifiEvent event = WifiEvent::kStationDoDhcp;
678+
WifiEvent event = WifiEvent::kConnectionComplete;
736679
sl_matter_wifi_post_event(event);
737680
}
738681

@@ -744,7 +687,7 @@ void ProcessEvent(WifiEvent event)
744687
case WifiEvent::kStationConnect:
745688
ChipLogDetail(DeviceLayer, "WifiEvent::kStationConnect");
746689
wfx_rsi.dev_state.Set(WifiState::kStationConnected);
747-
ResetDHCPNotificationFlags();
690+
ResetConnectivityNotificationFlags();
748691
break;
749692

750693
case WifiEvent::kStationDisconnect: {
@@ -757,7 +700,7 @@ void ProcessEvent(WifiEvent event)
757700
.Clear(WifiState::kStationDhcpDone);
758701

759702
/* TODO: Implement disconnect notify */
760-
ResetDHCPNotificationFlags();
703+
ResetConnectivityNotificationFlags();
761704
#if (CHIP_DEVICE_CONFIG_ENABLE_IPV4)
762705
wfx_ip_changed_notify(0); // for IPV4
763706
wfx_ip_changed_notify(IP_STATUS_FAIL);
@@ -834,20 +777,9 @@ void ProcessEvent(WifiEvent event)
834777
JoinWifiNetwork();
835778
break;
836779

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;
780+
case WifiEvent::kConnectionComplete:
781+
ChipLogDetail(DeviceLayer, "WifiPlatformEvent::kConnectionComplete");
782+
NotifySuccessfulConnection();
851783

852784
default:
853785
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-
kStationDoDhcp = 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+
kConnectionComplete = 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::kStationDoDhcp event to trigger DHCP polling checks. Helper function for ProcessEvent.
609+
* and emits a WifiEvent::kConnectionComplete 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::kStationDoDhcp;
621+
outEvent = WifiEvent::kConnectionComplete;
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::kStationDoDhcp: {
755+
case WifiEvent::kConnectionComplete: {
756756
StartDHCPTimer(WFX_RSI_DHCP_POLL_INTERVAL);
757757
}
758758
break;

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

+1-3
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,6 @@ 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-
5047
# wifi component
5148
"${wifi_sdk_root}/components/protocol/wifi/src/sl_wifi_basic_credentials.c",
5249
"${wifi_sdk_root}/components/protocol/wifi/src/sl_wifi_callback_framework.c",
@@ -55,6 +52,7 @@ rs9117_src_sapi = [
5552
# basic_network_manager component
5653
"${wifi_sdk_root}/components/service/network_manager/src/sl_net_credentials.c",
5754
"${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",
5856

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

0 commit comments

Comments
 (0)