Skip to content

Commit

Permalink
[SILABS] [RS917] Added support for Wi-Fi SDK 3.1.0 for 917 NCP (#28943)
Browse files Browse the repository at this point in the history
* Added changes for 917 NCP brignup

* Added changes for 917 ncp

* Resolved build errors for 917 NCP

* Resolved build errors for 917 NCP

* added changes in efr32_sdk.gni for wifi sdk

* Build errors resolved

* Fixed NCP build errors

* Added fix for sl wifi init

* Added BLE defines in efr32_sdk.gni

* Added changes for the 917 NCP

* Added changes 917 NCP

* Added chnages for NCP rx buffer

* changes for 917 NCP mode

* Updated wifi sdk commit

* removed the commented code

* Removed the commented code and required changes for SDk 3.0

* Added changes for RS9116 build

* Added fix for RS9116 build issue

* Removed the unused code

* Fixed warning changes for the 917 ncp

* Added licence for the file

* Added changes for the SOC and NCP

* Removed the sl_wifi_if duplicate file

* Added changes related to efr32_sdk

* Added changes for define

* Added changes for rs9116 and SOC error

* Added wifi component for 917 NCP

* Fixeed the hardfault for 917 NCP

* Removed EFR32 MG12 for the SI917

* Restyled by whitespace

* Added changes for the comments

* Added chnages for sdk 3.1.0

* Adds wifi-sdk 3.1.0 and required changes for it

* Added SOC and Common flash fixes

* Added changes for retyle commit

* Added restyle changes

* Added changes for the third party silabs sdk

* Restyled by gn

* Added changes for the rs9117 NCP file

* Added changes according to CSA comment

* Restyled by gn

* Added func return type

* Added micro changes for the command buffer time

---------

Co-authored-by: bhmanda-silabs <bhavani.manda@silabs.com>
Co-authored-by: Restyled.io <commits@restyled.io>
Co-authored-by: srningap <Srishylam.Ningapuram@silabs.com>
  • Loading branch information
4 people authored and pull[bot] committed Oct 26, 2023
1 parent b61fb5f commit 2559890
Show file tree
Hide file tree
Showing 18 changed files with 524 additions and 154 deletions.
156 changes: 84 additions & 72 deletions examples/platform/silabs/SiWx917/SiWx917/sl_wifi_if.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
#include "task.h"
#include "wfx_host_events.h"

#include "rsi_ble_config.h"
#include "ble_config.h"

#include "dhcp_client.h"
#include "lwip/nd6.h"
Expand Down Expand Up @@ -66,7 +66,7 @@ bool is_wifi_disconnection_event = false;
/* Declare a variable to hold connection time intervals */
uint32_t retryInterval = WLAN_MIN_RETRY_TIMER_MS;
volatile bool scan_results_complete = false;
#define WIFI_SCAN_TIMEOUT 10000 // WiFi Scan interval
#define WIFI_SCAN_TIMEOUT_TICK 10000

extern osSemaphoreId_t sl_rs_ble_init_sem;

Expand All @@ -89,13 +89,12 @@ volatile sl_status_t callback_status = SL_STATUS_OK;
int32_t wfx_rsi_get_ap_info(wfx_wifi_scan_result_t * ap)
{
sl_status_t status = SL_STATUS_OK;
uint8_t rssi = 0;
int32_t rssi = 0;
ap->security = wfx_rsi.sec.security;
ap->chan = wfx_rsi.ap_chan;
memcpy(&ap->bssid[0], &wfx_rsi.ap_mac.octet[0], BSSID_MAX_STR_LEN);
sl_wifi_get_signal_strength(SL_WIFI_CLIENT_INTERFACE, &rssi);
ap->rssi = rssi;

return status;
}

Expand Down Expand Up @@ -182,12 +181,9 @@ sl_status_t join_callback_handler(sl_wifi_event_t event, char * result, uint32_t
/*
* Join was complete - Do the DHCP
*/
SILABS_LOG("Join Completed %c: Join Event received with %u bytes payload\n", *result, result_length);
SILABS_LOG("join_callback_handler: join completed.");
SILABS_LOG("%c: Join Event received with %u bytes payload\n", *result, result_length);
xEventGroupSetBits(wfx_rsi.events, WFX_EVT_STA_CONN);
wfx_rsi.join_retries = 0;
retryInterval = WLAN_MIN_RETRY_TIMER_MS;
if (is_wifi_disconnection_event)
is_wifi_disconnection_event = false;
callback_status = SL_STATUS_OK;
return SL_STATUS_OK;
}
Expand Down Expand Up @@ -234,12 +230,12 @@ int32_t wfx_rsi_power_save()
*****************************************************************************************/
int32_t wfx_wifi_rsi_init(void)
{
SILABS_LOG("wfx_wifi_rsi_init started");
sl_status_t status;
status = sl_wifi_init(&config, default_wifi_event_handler);
if (status != SL_STATUS_OK)
{
SILABS_LOG("wfx_wifi_rsi_init failed %x", status);
return status;
}
return status;
}
Expand All @@ -252,9 +248,19 @@ int32_t wfx_wifi_rsi_init(void)
* @return
* None
*****************************************************************************************/
static int32_t wfx_rsi_init(void)
static sl_status_t wfx_rsi_init(void)
{
sl_status_t status;

#ifndef RSI_M4_INTERFACE
status = wfx_wifi_rsi_init();
if (status != SL_STATUS_OK)
{
SILABS_LOG("wfx_rsi_init failed %x", status);
return status;
}
#endif

status = sl_wifi_get_mac_address(SL_WIFI_CLIENT_INTERFACE, (sl_mac_address_t *) &wfx_rsi.sta_mac.octet[0]);
if (status != SL_STATUS_OK)
{
Expand All @@ -269,13 +275,18 @@ static int32_t wfx_rsi_init(void)
}

/*************************************************************************************
* @fn sl_status_t scan_callback_handler
* @fn void wfx_show_err(char *msg)
* @brief
* scan callback handler
* driver shows error message
* @param[in] msg
* @return
* sl_status_t
* None
*****************************************************************************************/
void wfx_show_err(char * msg)
{
SILABS_LOG("wfx_show_err: message: %d", msg);
}

sl_status_t scan_callback_handler(sl_wifi_event_t event, sl_wifi_scan_result_t * scan_result, uint32_t result_length, void * arg)
{
if (CHECK_IF_EVENT_FAILED(event))
Expand All @@ -291,7 +302,7 @@ sl_status_t scan_callback_handler(sl_wifi_event_t event, sl_wifi_scan_result_t *
}
wfx_rsi.sec.security = WFX_SEC_UNSPECIFIED;
wfx_rsi.ap_chan = scan_result->scan_info[0].rf_channel;
memcpy(&wfx_rsi.ap_mac.octet[0], scan_result->scan_info[0].bssid[0], BSSID_MAX_STR_LEN);
memcpy(&wfx_rsi.ap_mac.octet, scan_result->scan_info[0].bssid, BSSID_MAX_STR_LEN);
switch (scan_result->scan_info[0].security_mode)
{
case SL_WIFI_OPEN:
Expand Down Expand Up @@ -323,26 +334,16 @@ sl_status_t scan_callback_handler(sl_wifi_event_t event, sl_wifi_scan_result_t *
scan_results_complete = true;
return SL_STATUS_OK;
}

/*************************************************************************************
* @fn sl_status_t show_scan_results
* @brief
* driver shows scan results
* @param[in] msg
* @return
* sl_status_t
*****************************************************************************************/
sl_status_t show_scan_results(sl_wifi_scan_result_t * scan_result)
{
ARGS_CHECK_NULL_POINTER(scan_result);
int x;
wfx_wifi_scan_result_t ap;
if (wfx_rsi.dev_state & WFX_RSI_ST_STA_CONNECTED)
{
for (x = 0; x < scan_result->scan_count; x++)
for (x = 0; x < (int) scan_result->scan_count; x++)
{
strcpy(&ap.ssid[0], (char *) &scan_result->scan_info[x].ssid);
uint8_t * bssid = (uint8_t *) &scan_result->scan_info[x].bssid;
if (wfx_rsi.scan_ssid)
{
SILABS_LOG("SCAN SSID: %s , ap scan: %s", wfx_rsi.scan_ssid, ap.ssid);
Expand Down Expand Up @@ -373,15 +374,6 @@ sl_status_t show_scan_results(sl_wifi_scan_result_t * scan_result)
}
return SL_STATUS_OK;
}

/*************************************************************************************
* @fn bg_scan_callback_handler
* @brief
* scan for wifi events in background
* @param[in]
* @return
* SL_STATUS_OK
*****************************************************************************************/
sl_status_t bg_scan_callback_handler(sl_wifi_event_t event, sl_wifi_scan_result_t * result, uint32_t result_length, void * arg)
{
callback_status = show_scan_results(result);
Expand Down Expand Up @@ -409,13 +401,12 @@ static void wfx_rsi_save_ap_info() // translation
if (SL_STATUS_IN_PROGRESS == status)
{
const uint32_t start = osKernelGetTickCount();
while (!scan_results_complete && (osKernelGetTickCount() - start) <= WIFI_SCAN_TIMEOUT)
while (!scan_results_complete && (osKernelGetTickCount() - start) <= WIFI_SCAN_TIMEOUT_TICK)
{
osThreadYield();
}
status = scan_results_complete ? callback_status : SL_STATUS_TIMEOUT;
}
return status;
}

/********************************************************************************************
Expand All @@ -425,9 +416,9 @@ static void wfx_rsi_save_ap_info() // translation
* @return
* None
**********************************************************************************************/
static void wfx_rsi_do_join(void)
static sl_status_t wfx_rsi_do_join(void)
{
int32_t status;
sl_status_t status = SL_STATUS_OK;
sl_wifi_security_t connect_security_mode;
switch (wfx_rsi.sec.security)
{
Expand All @@ -445,8 +436,8 @@ static void wfx_rsi_do_join(void)
connect_security_mode = SL_WIFI_OPEN;
break;
default:
SILABS_LOG("%s: error: unknown security type.");
return;
SILABS_LOG("error: unknown security type.");
return status;
}

if (wfx_rsi.dev_state & (WFX_RSI_ST_STA_CONNECTING | WFX_RSI_ST_STA_CONNECTED))
Expand All @@ -466,12 +457,7 @@ static void wfx_rsi_do_join(void)
*/
wfx_rsi.dev_state |= WFX_RSI_ST_STA_CONNECTING;

status = sl_wifi_set_join_callback(join_callback_handler, NULL);
if (SL_STATUS_OK != status)
{
SILABS_LOG(" Set Join Callback fail ");
return status;
}
sl_wifi_set_join_callback(join_callback_handler, NULL);

/* Try to connect Wifi with given Credentials
* untill there is a success or maximum number of tries allowed
Expand All @@ -487,6 +473,7 @@ static void wfx_rsi_do_join(void)
status = sl_net_set_credential(id, SL_NET_WIFI_PSK, &wfx_rsi.sec.passkey[0], strlen(wfx_rsi.sec.passkey));
if (SL_STATUS_OK != status)
{
SILABS_LOG("wfx_rsi_do_join: RSI callback register join failed with status: %02x", status);
return status;
}

Expand All @@ -509,21 +496,18 @@ static void wfx_rsi_do_join(void)
}
else
{
if (is_wifi_disconnection_event || wfx_rsi.join_retries <= WFX_RSI_CONFIG_MAX_JOIN)
while (is_wifi_disconnection_event || wfx_rsi.join_retries <= WFX_RSI_CONFIG_MAX_JOIN)
{
SILABS_LOG("%s: failed. retry: %d", __func__, wfx_rsi.join_retries);
wfx_retry_interval_handler(is_wifi_disconnection_event, wfx_rsi.join_retries++);
if (is_wifi_disconnection_event || wfx_rsi.join_retries <= WFX_RSI_CONFIG_MAX_JOIN)
xEventGroupSetBits(wfx_rsi.events, WFX_EVT_STA_START_JOIN);
SILABS_LOG("%s: starting JOIN to %s after %d tries\n", __func__, (char *) &wfx_rsi.sec.ssid[0],
wfx_rsi.join_retries);
wfx_rsi.join_retries += 1;
wfx_rsi.dev_state &= ~(WFX_RSI_ST_STA_CONNECTING | WFX_RSI_ST_STA_CONNECTED);
if (wfx_rsi.join_retries <= MAX_JOIN_RETRIES_COUNT)
{
xEventGroupSetBits(wfx_rsi.events, WFX_EVT_STA_START_JOIN);
}
wfx_retry_interval_handler(is_wifi_disconnection_event, wfx_rsi.join_retries);
}
}
}
return status;
}

/*********************************************************************************
Expand All @@ -543,18 +527,18 @@ void wfx_rsi_task(void * arg)
TickType_t last_dhcp_poll, now;
struct netif * sta_netif;
(void) arg;
uint32_t rsi_status = wfx_rsi_init();
if (rsi_status != RSI_SUCCESS)
sl_status_t status = wfx_rsi_init();
if (status != RSI_SUCCESS)
{
SILABS_LOG("%s: error: wfx_rsi_init with status: %02x", __func__, rsi_status);
SILABS_LOG("wfx_rsi_task: error: wfx_rsi_init with status: %02x", status);
return;
}
wfx_lwip_start();
last_dhcp_poll = xTaskGetTickCount();
sta_netif = wfx_get_netif(SL_WFX_STA_INTERFACE);
wfx_started_notify();

SILABS_LOG("%s: starting event wait", __func__);
SILABS_LOG("wfx_rsi_task: starting event wait");
for (;;)
{
/*
Expand Down Expand Up @@ -604,6 +588,14 @@ void wfx_rsi_task(void * arg)
hasNotifiedIPV4 = false;
}
#endif /* CHIP_DEVICE_CONFIG_ENABLE_IPV4 */
/*
* Checks if the IPv6 event has been notified, if not invoke the nd6_tmr,
* which starts the duplicate address detectation.
*/
if (!hasNotifiedIPV6)
{
nd6_tmr();
}
/* Checks if the assigned IPv6 address is preferred by evaluating
* the first block of IPv6 address ( block 0)
*/
Expand All @@ -625,7 +617,7 @@ void wfx_rsi_task(void * arg)
// saving the AP related info
wfx_rsi_save_ap_info();
// Joining to the network
wfx_rsi_do_join();
status = wfx_rsi_do_join();
}
if (flags & WFX_EVT_STA_CONN)
{
Expand Down Expand Up @@ -664,9 +656,8 @@ void wfx_rsi_task(void * arg)
if (!(wfx_rsi.dev_state & WFX_RSI_ST_SCANSTARTED))
{
SILABS_LOG("%s: start SSID scan", __func__);
int x;
sl_wifi_scan_configuration_t wifi_scan_configuration = { 0 };
wfx_wifi_scan_result_t ap;

// TODO: Add scan logic
sl_wifi_advanced_scan_configuration_t advanced_scan_configuration = { 0 };
int32_t status;
Expand All @@ -676,23 +667,16 @@ void wfx_rsi_task(void * arg)
advanced_scan_configuration.trigger_level_change = ADV_RSSI_TOLERANCE_THRESHOLD;
advanced_scan_configuration.enable_multi_probe = ADV_MULTIPROBE;
status = sl_wifi_set_advanced_scan_configuration(&advanced_scan_configuration);
VERIFY_STATUS_AND_RETURN(status);
/* Terminate with end of scan which is no ap sent back */
wifi_scan_configuration.type = SL_WIFI_SCAN_TYPE_ADV_SCAN;
wifi_scan_configuration.periodic_scan_interval = ADV_SCAN_PERIODICITY;

status = sl_wifi_set_scan_callback(bg_scan_callback_handler, NULL);
if (SL_STATUS_OK != status)
{
return status;
}

sl_wifi_set_scan_callback(bg_scan_callback_handler, NULL);
status = sl_wifi_start_scan(SL_WIFI_CLIENT_2_4GHZ_INTERFACE, NULL, &wifi_scan_configuration);
if (SL_STATUS_IN_PROGRESS == status)
{
printf("Scanning...\r\n");
const uint32_t start = osKernelGetTickCount();
while (!scan_results_complete && (osKernelGetTickCount() - start) <= WIFI_SCAN_TIMEOUT)
while (!scan_results_complete && (osKernelGetTickCount() - start) <= WIFI_SCAN_TIMEOUT_TICK)
{
osThreadYield();
}
Expand Down Expand Up @@ -740,6 +724,7 @@ void wfx_dhcp_got_ipv4(uint32_t ip)
}
#endif /* CHIP_DEVICE_CONFIG_ENABLE_IPV4 */

#if !EXP_BOARD
/*
* WARNING - Taken from RSI and broken up
* This is my own RSI stuff for not copying code and allocating an extra
Expand All @@ -763,13 +748,14 @@ void * wfx_rsi_alloc_pkt(uint16_t data_length)
/* Confirm if packet is allocated */

status = sl_si91x_allocate_command_buffer(&buffer, (void **) &packet, sizeof(sl_si91x_packet_t) + data_length,
SL_WIFI_ALLOCATE_COMMAND_BUFFER_WAIT_TIME);
SL_WIFI_ALLOCATE_COMMAND_BUFFER_WAIT_TIME_MS);
if (packet == NULL)
{
return SL_STATUS_ALLOCATION_FAILED;
}
return (void *) packet;
}
#endif

/********************************************************************************************
* @fn void wfx_rsi_pkt_add_data(void *p, uint8_t *buf, uint16_t len, uint16_t off)
Expand All @@ -788,3 +774,29 @@ void wfx_rsi_pkt_add_data(void * p, uint8_t * buf, uint16_t len, uint16_t off)
pkt = (sl_si91x_packet_t *) p;
memcpy(((char *) pkt->data) + off, buf, len);
}

#if !EXP_BOARD
/********************************************************************************************
* @fn int32_t wfx_rsi_send_data(void *p, uint16_t len)
* @brief
* Driver send a data
* @param[in] p:
* @param[in] len:
* @return
* None
**********************************************************************************************/
int32_t wfx_rsi_send_data(void * p, uint16_t len)
{
int32_t status;
sl_wifi_buffer_t * buffer;
buffer = (sl_wifi_buffer_t *) p;

if (sl_si91x_driver_send_data_packet(SI91X_WLAN_CMD_QUEUE, buffer, RSI_SEND_RAW_DATA_RESPONSE_WAIT_TIME))
{
SILABS_LOG("*ERR*EN-RSI:Send fail");
return ERR_IF;
}
return status;
}

#endif
5 changes: 4 additions & 1 deletion examples/platform/silabs/efr32/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,13 @@ if (chip_enable_wifi) {
assert(use_rs9116 || use_wf200 || use_SiWx917)
import("${chip_root}/src/platform/silabs/wifi_args.gni")

if (use_rs9116 || use_SiWx917) {
if (use_rs9116) {
wiseconnect_sdk_root =
"${chip_root}/third_party/silabs/wiseconnect-wifi-bt-sdk"
import("rs911x/rs911x.gni")
} else if (use_SiWx917) {
wifi_sdk_root = "${chip_root}/third_party/silabs/wifi_sdk"
import("rs911x/rs9117.gni")
}
if (use_wf200) {
import("wf200/wf200.gni")
Expand Down
Loading

0 comments on commit 2559890

Please sign in to comment.