Skip to content

Commit

Permalink
[Silabs] [EFR32] Adds translation between spec WiFi Security Types (#…
Browse files Browse the repository at this point in the history
…25458)

* Adds fix for #25118

* Adds fix for unused-variable-warning

* Adds fix for rsi_wlan_connect_async invoke

* Adding break statements for default case.

* Update examples/platform/silabs/efr32/rs911x/rsi_if.c

Co-authored-by: Jonathan Mégevand <[email protected]>

---------

Co-authored-by: Jonathan Mégevand <[email protected]>
  • Loading branch information
2 people authored and pull[bot] committed Aug 11, 2023
1 parent 418b98a commit 2493944
Show file tree
Hide file tree
Showing 6 changed files with 137 additions and 90 deletions.
57 changes: 44 additions & 13 deletions examples/platform/silabs/SiWx917/SiWx917/rsi_if.c
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,6 @@ extern rsi_semaphore_handle_t sl_rs_ble_init_sem;
*/
static uint8_t wfx_rsi_drv_buf[WFX_RSI_BUF_SZ];
wfx_wifi_scan_ext_t * temp_reset;
uint8_t security;

/******************************************************************
* @fn int32_t wfx_rsi_get_ap_info(wfx_wifi_scan_result_t *ap)
Expand All @@ -89,7 +88,7 @@ int32_t wfx_rsi_get_ap_info(wfx_wifi_scan_result_t * ap)
{
int32_t status;
uint8_t rssi;
ap->security = security;
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);
status = rsi_wlan_get(RSI_RSSI, &rssi, sizeof(rssi));
Expand Down Expand Up @@ -381,21 +380,33 @@ static void wfx_rsi_save_ap_info()
}
else
{
wfx_rsi.sec.security = rsp.scan_info->security_mode;
wfx_rsi.sec.security = WFX_SEC_UNSPECIFIED;
wfx_rsi.ap_chan = rsp.scan_info->rf_channel;
memcpy(&wfx_rsi.ap_mac.octet[0], &rsp.scan_info->bssid[0], BSSID_MAX_STR_LEN);
}
if ((wfx_rsi.sec.security == RSI_WPA) || (wfx_rsi.sec.security == RSI_WPA2))
switch (rsp.scan_info->security_mode)
{
// saving the security before changing into mixed mode
security = wfx_rsi.sec.security;
wfx_rsi.sec.security = RSI_WPA_WPA2_MIXED;
}
if (wfx_rsi.sec.security == SME_WPA3)
{
// returning 3 for WPA3 when DGWIFI read security-type is called
security = WPA3_SECURITY;
wfx_rsi.sec.security = RSI_WPA3;
case SME_OPEN:
wfx_rsi.sec.security = WFX_SEC_NONE;
break;
case SME_WPA:
case SME_WPA_ENTERPRISE:
wfx_rsi.sec.security = WFX_SEC_WPA;
break;
case SME_WPA2:
case SME_WPA2_ENTERPRISE:
wfx_rsi.sec.security = WFX_SEC_WPA2;
break;
case SME_WEP:
wfx_rsi.sec.security = WFX_SEC_WEP;
break;
case SME_WPA3:
case SME_WPA3_TRANSITION:
wfx_rsi.sec.security = WFX_SEC_WPA3;
break;
default:
wfx_rsi.sec.security = WFX_SEC_UNSPECIFIED;
break;
}
WFX_RSI_LOG("%s: WLAN: connecting to %s==%s, sec=%d, status=%02x", __func__, &wfx_rsi.sec.ssid[0], &wfx_rsi.sec.passkey[0],
wfx_rsi.sec.security, status);
Expand All @@ -418,6 +429,26 @@ static void wfx_rsi_do_join(void)
}
else
{
switch (wfx_rsi.sec.security)
{
case WFX_SEC_WEP:
connect_security_mode = RSI_WEP;
break;
case WFX_SEC_WPA:
case WFX_SEC_WPA2:
connect_security_mode = RSI_WPA_WPA2_MIXED;
break;
case WFX_SEC_WPA3:
connect_security_mode = RSI_WPA3;
break;
case WFX_SEC_NONE:
connect_security_mode = RSI_OPEN;
break;
default:
WFX_RSI_LOG("%s: error: unknown security type.");
return;
}

WFX_RSI_LOG("%s: WLAN: connecting to %s==%s, sec=%d", __func__, &wfx_rsi.sec.ssid[0], &wfx_rsi.sec.passkey[0],
wfx_rsi.sec.security);
/*
Expand Down
67 changes: 51 additions & 16 deletions examples/platform/silabs/efr32/rs911x/rsi_if.c
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,6 @@ extern rsi_semaphore_handle_t sl_rs_ble_init_sem;
*/
static uint8_t wfx_rsi_drv_buf[WFX_RSI_BUF_SZ];
wfx_wifi_scan_ext_t * temp_reset;
uint8_t security;

/******************************************************************
* @fn int32_t wfx_rsi_get_ap_info(wfx_wifi_scan_result_t *ap)
Expand All @@ -96,7 +95,7 @@ int32_t wfx_rsi_get_ap_info(wfx_wifi_scan_result_t * ap)
{
int32_t status;
uint8_t rssi;
ap->security = security;
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);
status = rsi_wlan_get(RSI_RSSI, &rssi, sizeof(rssi));
Expand Down Expand Up @@ -435,7 +434,7 @@ void wfx_show_err(char * msg)
* @return
* None
*******************************************************************************************/
static void wfx_rsi_save_ap_info()
static void wfx_rsi_save_ap_info() // translation
{
int32_t status;
rsi_rsp_scan_t rsp;
Expand All @@ -450,22 +449,36 @@ static void wfx_rsi_save_ap_info()
}
else
{
wfx_rsi.sec.security = rsp.scan_info->security_mode;
wfx_rsi.sec.security = WFX_SEC_UNSPECIFIED;
wfx_rsi.ap_chan = rsp.scan_info->rf_channel;
memcpy(&wfx_rsi.ap_mac.octet[0], &rsp.scan_info->bssid[0], BSSID_MAX_STR_LEN);
}
if ((wfx_rsi.sec.security == RSI_WPA) || (wfx_rsi.sec.security == RSI_WPA2))
{
// saving the security before changing into mixed mode
security = wfx_rsi.sec.security;
wfx_rsi.sec.security = RSI_WPA_WPA2_MIXED;
}
if (wfx_rsi.sec.security == SME_WPA3)

switch (rsp.scan_info->security_mode)
{
// returning 3 for WPA3 when DGWIFI read security-type is called
security = WPA3_SECURITY;
wfx_rsi.sec.security = RSI_WPA3;
case SME_OPEN:
wfx_rsi.sec.security = WFX_SEC_NONE;
break;
case SME_WPA:
case SME_WPA_ENTERPRISE:
wfx_rsi.sec.security = WFX_SEC_WPA;
break;
case SME_WPA2:
case SME_WPA2_ENTERPRISE:
wfx_rsi.sec.security = WFX_SEC_WPA2;
break;
case SME_WEP:
wfx_rsi.sec.security = WFX_SEC_WEP;
break;
case SME_WPA3:
case SME_WPA3_TRANSITION:
wfx_rsi.sec.security = WFX_SEC_WPA3;
break;
default:
wfx_rsi.sec.security = WFX_SEC_UNSPECIFIED;
break;
}

WFX_RSI_LOG("%s: WLAN: connecting to %s==%s, sec=%d, status=%02x", __func__, &wfx_rsi.sec.ssid[0], &wfx_rsi.sec.passkey[0],
wfx_rsi.sec.security, status);
}
Expand All @@ -480,13 +493,35 @@ static void wfx_rsi_save_ap_info()
static void wfx_rsi_do_join(void)
{
int32_t status;
rsi_security_mode_t connect_security_mode;

if (wfx_rsi.dev_state & (WFX_RSI_ST_STA_CONNECTING | WFX_RSI_ST_STA_CONNECTED))
{
WFX_RSI_LOG("%s: not joining - already in progress", __func__);
}
else
{

switch (wfx_rsi.sec.security)
{
case WFX_SEC_WEP:
connect_security_mode = RSI_WEP;
break;
case WFX_SEC_WPA:
case WFX_SEC_WPA2:
connect_security_mode = RSI_WPA_WPA2_MIXED;
break;
case WFX_SEC_WPA3:
connect_security_mode = RSI_WPA3;
break;
case WFX_SEC_NONE:
connect_security_mode = RSI_OPEN;
break;
default:
WFX_RSI_LOG("%s: error: unknown security type.");
return;
}

WFX_RSI_LOG("%s: WLAN: connecting to %s==%s, sec=%d", __func__, &wfx_rsi.sec.ssid[0], &wfx_rsi.sec.passkey[0],
wfx_rsi.sec.security);

Expand All @@ -511,8 +546,8 @@ static void wfx_rsi_do_join(void)
/* Call rsi connect call with given ssid and password
* And check there is a success
*/
if ((status = rsi_wlan_connect_async((int8_t *) &wfx_rsi.sec.ssid[0], (rsi_security_mode_t) wfx_rsi.sec.security,
&wfx_rsi.sec.passkey[0], wfx_rsi_join_cb)) != RSI_SUCCESS)
if ((status = rsi_wlan_connect_async((int8_t *) &wfx_rsi.sec.ssid[0], connect_security_mode, &wfx_rsi.sec.passkey[0],
wfx_rsi_join_cb)) != RSI_SUCCESS)
{

wfx_rsi.dev_state &= ~WFX_RSI_ST_STA_CONNECTING;
Expand Down
49 changes: 25 additions & 24 deletions examples/platform/silabs/efr32/wf200/host_if.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,7 @@ static void sl_wfx_scan_result_callback(sl_wfx_scan_result_ind_body_t * scan_res
ap->scan.ssid[scan_result->ssid_def.ssid_length] = 0; /* make sure about null terminate */
/* We do it in this order WPA3 first */
/* No EAP supported - Is this required */
ap->scan.security = WFX_SEC_UNSPECIFIED;
if (scan_result->security_mode.wpa3)
{
ap->scan.security = WFX_SEC_WPA3;
Expand Down Expand Up @@ -967,27 +968,8 @@ void wfx_set_wifi_provision(wfx_wifi_provision_t * wifiConfig)
{
memcpy(wifi_provision.ssid, wifiConfig->ssid, sizeof(wifiConfig->ssid));
memcpy(wifi_provision.passkey, wifiConfig->passkey, sizeof(wifiConfig->passkey));
wifi_provision.security = wifiConfig->security;
SILABS_LOG("WIFI: Provision SSID=%s", &wifi_provision.ssid[0]);

/* Not very good - To be improved */
switch (wifiConfig->security)
{
case WFX_SEC_WPA:
wifi_provision.security = static_cast<uint8_t>(sl_wfx_security_mode_e::WFM_SECURITY_MODE_WPA2_WPA1_PSK);
break;
case WFX_SEC_WPA3:
wifi_provision.security = WFM_SECURITY_MODE_WPA3_SAE;
break;
case WFX_SEC_WPA2:
wifi_provision.security = static_cast<uint8_t>(sl_wfx_security_mode_e::WFM_SECURITY_MODE_WPA2_WPA1_PSK);
break;
case WFX_SEC_WPA_WPA2_MIXED:
wifi_provision.security = static_cast<uint8_t>(sl_wfx_security_mode_e::WFM_SECURITY_MODE_WPA2_WPA1_PSK);
break;
default:
wifi_provision.security = WFM_SECURITY_MODE_WPA2_PSK;
break;
}
}

/****************************************************************************
Expand Down Expand Up @@ -1039,6 +1021,7 @@ bool wfx_is_sta_provisioned(void)
sl_status_t wfx_connect_to_ap(void)
{
sl_status_t result;
sl_wfx_security_mode_t connect_security_mode;

if (wifi_provision.ssid[0] == 0)
{
Expand All @@ -1050,10 +1033,28 @@ sl_status_t wfx_connect_to_ap(void)
"Time: %d, Number of prob: %d",
ACTIVE_CHANNEL_TIME, PASSIVE_CHANNEL_TIME, NUM_PROBE_REQUEST);
(void) sl_wfx_set_scan_parameters(ACTIVE_CHANNEL_TIME, PASSIVE_CHANNEL_TIME, NUM_PROBE_REQUEST);
result =
sl_wfx_send_join_command((uint8_t *) wifi_provision.ssid, strlen(wifi_provision.ssid), NULL, CHANNEL_0,
static_cast<sl_wfx_security_mode_t>(wifi_provision.security), PREVENT_ROAMING, DISABLE_PMF_MODE,
(uint8_t *) wifi_provision.passkey, strlen(wifi_provision.passkey), NULL, IE_DATA_LENGTH);
switch (wifi_provision.security)
{
case WFX_SEC_WEP:
connect_security_mode = sl_wfx_security_mode_e::WFM_SECURITY_MODE_WEP;
break;
case WFX_SEC_WPA:
case WFX_SEC_WPA2:
connect_security_mode = sl_wfx_security_mode_e::WFM_SECURITY_MODE_WPA2_WPA1_PSK;
break;
case WFX_SEC_WPA3:
connect_security_mode = sl_wfx_security_mode_e::WFM_SECURITY_MODE_WPA3_SAE;
break;
case WFX_SEC_NONE:
connect_security_mode = sl_wfx_security_mode_e::WFM_SECURITY_MODE_OPEN;
break;
default:
SILABS_LOG("%s: error: unknown security type.");
return SL_STATUS_INVALID_STATE;
}
result = sl_wfx_send_join_command((uint8_t *) wifi_provision.ssid, strlen(wifi_provision.ssid), NULL, CHANNEL_0,
connect_security_mode, PREVENT_ROAMING, DISABLE_PMF_MODE, (uint8_t *) wifi_provision.passkey,
strlen(wifi_provision.passkey), NULL, IE_DATA_LENGTH);

return result;
}
Expand Down
2 changes: 1 addition & 1 deletion src/platform/silabs/NetworkCommissioningWiFiDriver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ CHIP_ERROR SlWiFiDriver::ConnectWiFiNetwork(const char * ssid, uint8_t ssidLen,
wfx_wifi_provision_t wifiConfig = {};
memcpy(wifiConfig.ssid, ssid, ssidLen);
memcpy(wifiConfig.passkey, key, keyLen);
wifiConfig.security = WFX_SEC_WPA_WPA2_MIXED;
wifiConfig.security = WFX_SEC_WPA2;

ChipLogProgress(NetworkProvisioning, "Setting up connection for WiFi SSID: %.*s", static_cast<int>(ssidLen), ssid);
// Configure the WFX WiFi interface.
Expand Down
26 changes: 8 additions & 18 deletions src/platform/silabs/SiWx917/wifi/wfx_host_events.h
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,6 @@
#define BG_SCAN_RES_SIZE 500

#define SPI_CONFIG_SUCCESS 0
#define WPA3_SECURITY 3

typedef enum
{
Expand All @@ -149,28 +148,19 @@ typedef enum
/* Note that these are same as RSI_security */
typedef enum
{
WFX_SEC_NONE = 0,
WFX_SEC_WPA = 1,
WFX_SEC_WPA2 = 2,
WFX_SEC_WEP = 3,
WFX_SEC_WPA_EAP = 4,
WFX_SEC_WPA2_EAP = 5,
WFX_SEC_WPA_WPA2_MIXED = 6,
WFX_SEC_WPA_PMK = 7,
WFX_SEC_WPA2_PMK = 8,
WFX_SEC_WPS_PIN = 9,
WFX_SEC_GEN_WPS_PIN = 10,
WFX_SEC_PUSH_BTN = 11,
WFX_SEC_WPA3 = 11,
WFX_SEC_UNSPECIFIED = 0,
WFX_SEC_NONE = 1,
WFX_SEC_WEP = 2,
WFX_SEC_WPA = 3,
WFX_SEC_WPA2 = 4,
WFX_SEC_WPA3 = 5
} wfx_sec_t;

#define WPA3_SECURITY 3

typedef struct
{
char ssid[32 + 1];
char passkey[64 + 1];
uint8_t security;
wfx_sec_t security;
} wfx_wifi_provision_t;

typedef enum
Expand All @@ -185,7 +175,7 @@ typedef enum
typedef struct wfx_wifi_scan_result
{
char ssid[32 + 1];
uint8_t security;
wfx_sec_t security;
uint8_t bssid[6];
uint8_t chan;
int16_t rssi; /* I suspect this is in dBm - so signed */
Expand Down
Loading

0 comments on commit 2493944

Please sign in to comment.