Skip to content

Commit 1740546

Browse files
[Silabs] Move LwIP specific functions out of the WifiInterface (#37581)
* Clean up WifiIntercace by moving LWIP APIs * Finish cleanup * Fix build * Apply suggestions from code review
1 parent 0d6b2fb commit 1740546

14 files changed

+308
-339
lines changed

src/platform/silabs/wifi/BUILD.gn

+1
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,7 @@ source_set("wifi-platform") {
149149
"${silabs_platform_dir}/wifi/lwip-support/ethernetif.cpp",
150150
"${silabs_platform_dir}/wifi/lwip-support/ethernetif.h",
151151
"${silabs_platform_dir}/wifi/lwip-support/lwip_netif.cpp",
152+
"${silabs_platform_dir}/wifi/lwip-support/lwip_netif.h",
152153
]
153154
}
154155

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

+1-28
Original file line numberDiff line numberDiff line change
@@ -616,8 +616,7 @@ void HandleDHCPPolling(void)
616616
uint8_t dhcp_state = dhcpclient_poll(sta_netif);
617617
if (dhcp_state == DHCP_ADDRESS_ASSIGNED && !HasNotifiedIPv4Change())
618618
{
619-
wfx_dhcp_got_ipv4((uint32_t) sta_netif->ip_addr.u_addr.ip4.addr);
620-
NotifyIPv4Change(true);
619+
GotIPv4Address((uint32_t) sta_netif->ip_addr.u_addr.ip4.addr);
621620
event = WifiPlatformEvent::kStationDhcpDone;
622621
PostWifiPlatformEvent(event);
623622
NotifyConnectivity();
@@ -845,29 +844,3 @@ CHIP_ERROR ConfigureBroadcastFilter(bool enableBroadcastFilter)
845844
return CHIP_NO_ERROR;
846845
}
847846
#endif // CHIP_CONFIG_ENABLE_ICD_SERVER
848-
849-
#if CHIP_DEVICE_CONFIG_ENABLE_IPV4
850-
/********************************************************************************************
851-
* @fn void wfx_dhcp_got_ipv4(uint32_t ip)
852-
* @brief
853-
* Acquire the new ip address
854-
* @param[in] ip: internet protocol
855-
* @return
856-
* None
857-
**********************************************************************************************/
858-
void wfx_dhcp_got_ipv4(uint32_t ip)
859-
{
860-
/*
861-
* Acquire the new IP address
862-
*/
863-
wfx_rsi.ip4_addr[0] = (ip) &0xFF;
864-
wfx_rsi.ip4_addr[1] = (ip >> 8) & 0xFF;
865-
wfx_rsi.ip4_addr[2] = (ip >> 16) & 0xFF;
866-
wfx_rsi.ip4_addr[3] = (ip >> 24) & 0xFF;
867-
ChipLogDetail(DeviceLayer, "DHCP OK: IP=%d.%d.%d.%d", wfx_rsi.ip4_addr[0], wfx_rsi.ip4_addr[1], wfx_rsi.ip4_addr[2],
868-
wfx_rsi.ip4_addr[3]);
869-
/* Notify the Connectivity Manager - via the app */
870-
wfx_rsi.dev_state.Set(WifiState::kStationDhcpDone).Set(WifiState::kStationReady);
871-
NotifyIPv4Change(true);
872-
}
873-
#endif /* CHIP_DEVICE_CONFIG_ENABLE_IPV4 */

src/platform/silabs/wifi/WifiInterface.cpp

+3
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@ using namespace chip::DeviceLayer;
3131

3232
#define CONVERT_SEC_TO_MS(TimeInS) (TimeInS * 1000)
3333

34+
// TODO: We shouldn't need to have access to a global variable in the interface here
35+
extern WfxRsi_t wfx_rsi;
36+
3437
// TODO: This is a workaround because we depend on the platform lib which depends on the platform implementation.
3538
// As such we can't depend on the platform here as well
3639
extern void HandleWFXSystemEvent(sl_wfx_generic_message_t * eventData);

src/platform/silabs/wifi/WifiInterface.h

-39
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,6 @@
2626
#include "sl_status.h"
2727
#include <stdbool.h>
2828

29-
/* LwIP includes. */
30-
#include "lwip/ip_addr.h"
31-
#include "lwip/netif.h"
32-
#include "lwip/netifapi.h"
33-
#include "lwip/tcpip.h"
34-
3529
#if (SLI_SI91X_MCU_INTERFACE | EXP_BOARD)
3630
#include "rsi_common_apis.h"
3731
#include "sl_si91x_types.h"
@@ -172,9 +166,6 @@ typedef struct wfx_rsi_s
172166
uint8_t ip4_addr[4]; /* Not sure if this is enough */
173167
} WfxRsi_t;
174168

175-
// TODO: We shouldn't need to have access to a global variable in the interface here
176-
extern WfxRsi_t wfx_rsi;
177-
178169
/* Updated functions */
179170

180171
/**
@@ -399,34 +390,4 @@ void wfx_cancel_scan(void);
399390
*/
400391
void sl_matter_wifi_task_started(void);
401392

402-
/* Implemented for LWIP */
403-
void wfx_lwip_set_sta_link_up(void);
404-
void wfx_lwip_set_sta_link_down(void);
405-
void sl_matter_lwip_start(void);
406-
struct netif * wfx_get_netif(sl_wfx_interface_t interface);
407-
408-
#if CHIP_DEVICE_CONFIG_ENABLE_IPV4
409-
void wfx_dhcp_got_ipv4(uint32_t);
410-
#endif /* CHIP_DEVICE_CONFIG_ENABLE_IPV4 */
411393
void wfx_retry_connection(uint16_t retryAttempt);
412-
413-
#ifdef RS911X_WIFI
414-
#if !(EXP_BOARD) // for RS9116
415-
void * wfx_rsi_alloc_pkt(void);
416-
/* RSI for LWIP */
417-
void wfx_rsi_pkt_add_data(void * p, uint8_t * buf, uint16_t len, uint16_t off);
418-
int32_t wfx_rsi_send_data(void * p, uint16_t len);
419-
#endif //!(EXP_BOARD)
420-
#endif // RS911X_WIFI
421-
422-
#ifdef __cplusplus
423-
extern "C" {
424-
#endif
425-
426-
#ifdef WF200_WIFI
427-
void sl_wfx_host_gpio_init(void);
428-
#endif /* WF200_WIFI */
429-
430-
#ifdef __cplusplus
431-
}
432-
#endif

src/platform/silabs/wifi/lwip-support/ethernetif.cpp

+100-29
Original file line numberDiff line numberDiff line change
@@ -21,40 +21,26 @@
2121
#include <stdlib.h>
2222
#include <string.h>
2323

24-
#ifndef WF200_WIFI
25-
#include "FreeRTOS.h"
26-
#include "event_groups.h"
27-
#include "task.h"
28-
#if (SLI_SI91X_MCU_INTERFACE | EXP_BOARD)
29-
#ifdef __cplusplus
24+
// LwIP includes - Includes must be before the rsi headers due to redefination errors
25+
#include "lwip/ethip6.h"
26+
#include "lwip/timeouts.h"
27+
#include "netif/etharp.h"
28+
29+
#ifdef RS911X_WIFI
3030
extern "C" {
31-
#endif
32-
#include "cmsis_os2.h"
33-
#include "sl_net.h"
34-
#include "sl_si91x_driver.h"
35-
#include "sl_si91x_host_interface.h"
36-
#include "sl_si91x_types.h"
37-
#include "sl_wifi.h"
38-
#include "sl_wifi_callback_framework.h"
39-
#include "sl_wifi_constants.h"
40-
#include "sl_wifi_types.h"
41-
#ifdef __cplusplus
31+
#include "rsi_driver.h"
32+
#include "rsi_pkt_mgmt.h"
4233
}
43-
#endif
44-
#endif // (SLI_SI91X_MCU_INTERFACE | EXP_BOARD)
45-
#endif // WF200_WIFI
34+
#endif // RS911X_WIFI
4635

47-
#include <platform/silabs/wifi/WifiInterface.h>
4836
#ifdef WF200_WIFI
4937
#include "sl_wfx.h"
5038
#endif
51-
/* LwIP includes. */
52-
#include "ethernetif.h"
53-
#include "lwip/ethip6.h"
54-
#include "lwip/timeouts.h"
55-
#include "netif/etharp.h"
5639

5740
#include <lib/support/logging/CHIPLogging.h>
41+
#include <platform/silabs/wifi/WifiInterface.h>
42+
#include <platform/silabs/wifi/lwip-support/ethernetif.h>
43+
#include <platform/silabs/wifi/lwip-support/lwip_netif.h>
5844

5945
StaticSemaphore_t xEthernetIfSemaBuffer;
6046

@@ -286,7 +272,7 @@ void sl_wfx_host_received_frame_callback(sl_wfx_received_ind_t * rx_buffer)
286272
{
287273

288274
/* Send received frame to station interface */
289-
if ((netif = wfx_get_netif(SL_WFX_STA_INTERFACE)) != NULL)
275+
if ((netif = chip::DeviceLayer::Silabs::Lwip::GetNetworkInterface(SL_WFX_STA_INTERFACE)) != NULL)
290276
{
291277
uint8_t * buffer;
292278
uint16_t len;
@@ -316,7 +302,92 @@ void sl_wfx_host_received_frame_callback(sl_wfx_received_ind_t * rx_buffer)
316302
}
317303

318304
#else /* For RS911x - using LWIP */
305+
319306
static SemaphoreHandle_t ethout_sem;
307+
308+
/**
309+
* @brief Allocates packets for the data about to be sent
310+
*
311+
* TODO: Validate if this warning still applied and fix the associated code
312+
* WARNING - Taken from RSI and broken up
313+
* This is my own RSI stuff for not copying code and allocating an extra
314+
* level of indirection - when using LWIP buffers
315+
* see also: int32_t rsi_wlan_send_data_xx(uint8_t *buffer, uint32_t length)
316+
*
317+
* @return void* pointer to the allocated packet buffer
318+
*/
319+
static void * wfx_rsi_alloc_pkt(void)
320+
{
321+
rsi_pkt_t * pkt;
322+
323+
// Allocate packet to send data
324+
if ((pkt = rsi_pkt_alloc(&rsi_driver_cb->wlan_cb->wlan_tx_pool)) == NULL)
325+
{
326+
return (void *) 0;
327+
}
328+
329+
return (void *) pkt;
330+
}
331+
332+
/**
333+
* @brief Adds the buffer data to the allocated packet.
334+
* the packet must be allocated before adding data to it.
335+
*
336+
* @param[in,out] p pointer to the allocated packet
337+
* @param[in] buf pointer to the data buffer to copy to the packet
338+
* @param[in] len length of the data buffer
339+
* @param[in] off the offset at which to put the data in the packet
340+
*/
341+
void wfx_rsi_pkt_add_data(void * p, uint8_t * buf, uint16_t len, uint16_t off)
342+
{
343+
rsi_pkt_t * pkt;
344+
345+
pkt = (rsi_pkt_t *) p;
346+
memcpy(((char *) pkt->data) + off, buf, len);
347+
}
348+
349+
/**
350+
* @brief Triggers the packet to sent on the wire
351+
*
352+
* @param p pointer to the packet to send
353+
* @param len length of the packet to send
354+
*
355+
* @return int32_t RSI_ERROR_NONE, if the packet was succesfully sent out
356+
* RSI_ERROR_RESPONSE_TIMEOUT, if we are unable to acquire the semaphore of the status
357+
* other error (< 0) if we were unable to send out the the packet
358+
*/
359+
int32_t wfx_rsi_send_data(void * p, uint16_t len)
360+
{
361+
int32_t status;
362+
uint8_t * host_desc;
363+
rsi_pkt_t * pkt;
364+
365+
pkt = (rsi_pkt_t *) p;
366+
host_desc = pkt->desc;
367+
memset(host_desc, 0, RSI_HOST_DESC_LENGTH);
368+
rsi_uint16_to_2bytes(host_desc, (len & 0xFFF));
369+
370+
// Fill packet type
371+
host_desc[1] |= (RSI_WLAN_DATA_Q << 4);
372+
host_desc[2] |= 0x01;
373+
374+
rsi_enqueue_pkt(&rsi_driver_cb->wlan_tx_q, pkt);
375+
376+
#ifndef RSI_SEND_SEM_BITMAP
377+
rsi_driver_cb_non_rom->send_wait_bitmap |= BIT(0);
378+
#endif
379+
// Set TX packet pending event
380+
rsi_set_event(RSI_TX_EVENT);
381+
382+
if (rsi_wait_on_wlan_semaphore(&rsi_driver_cb_non_rom->send_data_sem, RSI_SEND_DATA_RESPONSE_WAIT_TIME) != RSI_ERROR_NONE)
383+
{
384+
return RSI_ERROR_RESPONSE_TIMEOUT;
385+
}
386+
status = rsi_wlan_get_status();
387+
388+
return status;
389+
}
390+
320391
/*****************************************************************************
321392
* @fn static err_t low_level_output(struct netif *netif, struct pbuf *p)
322393
* @brief
@@ -441,7 +512,7 @@ sl_status_t sl_si91x_host_process_data_frame(sl_wifi_interface_t interface, sl_w
441512
/* get the network interface for STATION interface,
442513
* and forward the received frame buffer to LWIP
443514
*/
444-
if ((ifp = wfx_get_netif(SL_WFX_STA_INTERFACE)) != (struct netif *) 0)
515+
if ((ifp = GetNetworkInterface(SL_WFX_STA_INTERFACE)) != (struct netif *) 0)
445516
{
446517
low_level_input(ifp, rsi_pkt->data, rsi_pkt->length);
447518
}
@@ -465,7 +536,7 @@ void wfx_host_received_sta_frame_cb(uint8_t * buf, int len)
465536
/* get the network interface for STATION interface,
466537
* and forward the received frame buffer to LWIP
467538
*/
468-
if ((ifp = wfx_get_netif(SL_WFX_STA_INTERFACE)) != (struct netif *) 0)
539+
if ((ifp = chip::DeviceLayer::Silabs::Lwip::GetNetworkInterface(SL_WFX_STA_INTERFACE)) != (struct netif *) 0)
469540
{
470541
low_level_input(ifp, buf, len);
471542
}

0 commit comments

Comments
 (0)