Skip to content

Commit 1633300

Browse files
rosahay-silabsjmeg-sfy
authored andcommitted
[Silabs] [EFR32] Adds translation between spec WiFi Security Types (#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]>
1 parent 7d30870 commit 1633300

File tree

6 files changed

+137
-90
lines changed

6 files changed

+137
-90
lines changed

examples/platform/silabs/SiWx917/SiWx917/rsi_if.c

+44-13
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,6 @@ extern rsi_semaphore_handle_t sl_rs_ble_init_sem;
7575
*/
7676
static uint8_t wfx_rsi_drv_buf[WFX_RSI_BUF_SZ];
7777
wfx_wifi_scan_ext_t * temp_reset;
78-
uint8_t security;
7978

8079
/******************************************************************
8180
* @fn int32_t wfx_rsi_get_ap_info(wfx_wifi_scan_result_t *ap)
@@ -89,7 +88,7 @@ int32_t wfx_rsi_get_ap_info(wfx_wifi_scan_result_t * ap)
8988
{
9089
int32_t status;
9190
uint8_t rssi;
92-
ap->security = security;
91+
ap->security = wfx_rsi.sec.security;
9392
ap->chan = wfx_rsi.ap_chan;
9493
memcpy(&ap->bssid[0], &wfx_rsi.ap_mac.octet[0], BSSID_MAX_STR_LEN);
9594
status = rsi_wlan_get(RSI_RSSI, &rssi, sizeof(rssi));
@@ -381,21 +380,33 @@ static void wfx_rsi_save_ap_info()
381380
}
382381
else
383382
{
384-
wfx_rsi.sec.security = rsp.scan_info->security_mode;
383+
wfx_rsi.sec.security = WFX_SEC_UNSPECIFIED;
385384
wfx_rsi.ap_chan = rsp.scan_info->rf_channel;
386385
memcpy(&wfx_rsi.ap_mac.octet[0], &rsp.scan_info->bssid[0], BSSID_MAX_STR_LEN);
387386
}
388-
if ((wfx_rsi.sec.security == RSI_WPA) || (wfx_rsi.sec.security == RSI_WPA2))
387+
switch (rsp.scan_info->security_mode)
389388
{
390-
// saving the security before changing into mixed mode
391-
security = wfx_rsi.sec.security;
392-
wfx_rsi.sec.security = RSI_WPA_WPA2_MIXED;
393-
}
394-
if (wfx_rsi.sec.security == SME_WPA3)
395-
{
396-
// returning 3 for WPA3 when DGWIFI read security-type is called
397-
security = WPA3_SECURITY;
398-
wfx_rsi.sec.security = RSI_WPA3;
389+
case SME_OPEN:
390+
wfx_rsi.sec.security = WFX_SEC_NONE;
391+
break;
392+
case SME_WPA:
393+
case SME_WPA_ENTERPRISE:
394+
wfx_rsi.sec.security = WFX_SEC_WPA;
395+
break;
396+
case SME_WPA2:
397+
case SME_WPA2_ENTERPRISE:
398+
wfx_rsi.sec.security = WFX_SEC_WPA2;
399+
break;
400+
case SME_WEP:
401+
wfx_rsi.sec.security = WFX_SEC_WEP;
402+
break;
403+
case SME_WPA3:
404+
case SME_WPA3_TRANSITION:
405+
wfx_rsi.sec.security = WFX_SEC_WPA3;
406+
break;
407+
default:
408+
wfx_rsi.sec.security = WFX_SEC_UNSPECIFIED;
409+
break;
399410
}
400411
WFX_RSI_LOG("%s: WLAN: connecting to %s==%s, sec=%d, status=%02x", __func__, &wfx_rsi.sec.ssid[0], &wfx_rsi.sec.passkey[0],
401412
wfx_rsi.sec.security, status);
@@ -418,6 +429,26 @@ static void wfx_rsi_do_join(void)
418429
}
419430
else
420431
{
432+
switch (wfx_rsi.sec.security)
433+
{
434+
case WFX_SEC_WEP:
435+
connect_security_mode = RSI_WEP;
436+
break;
437+
case WFX_SEC_WPA:
438+
case WFX_SEC_WPA2:
439+
connect_security_mode = RSI_WPA_WPA2_MIXED;
440+
break;
441+
case WFX_SEC_WPA3:
442+
connect_security_mode = RSI_WPA3;
443+
break;
444+
case WFX_SEC_NONE:
445+
connect_security_mode = RSI_OPEN;
446+
break;
447+
default:
448+
WFX_RSI_LOG("%s: error: unknown security type.");
449+
return;
450+
}
451+
421452
WFX_RSI_LOG("%s: WLAN: connecting to %s==%s, sec=%d", __func__, &wfx_rsi.sec.ssid[0], &wfx_rsi.sec.passkey[0],
422453
wfx_rsi.sec.security);
423454
/*

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

+51-16
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,6 @@ extern rsi_semaphore_handle_t sl_rs_ble_init_sem;
8282
*/
8383
static uint8_t wfx_rsi_drv_buf[WFX_RSI_BUF_SZ];
8484
wfx_wifi_scan_ext_t * temp_reset;
85-
uint8_t security;
8685

8786
/******************************************************************
8887
* @fn int32_t wfx_rsi_get_ap_info(wfx_wifi_scan_result_t *ap)
@@ -96,7 +95,7 @@ int32_t wfx_rsi_get_ap_info(wfx_wifi_scan_result_t * ap)
9695
{
9796
int32_t status;
9897
uint8_t rssi;
99-
ap->security = security;
98+
ap->security = wfx_rsi.sec.security;
10099
ap->chan = wfx_rsi.ap_chan;
101100
memcpy(&ap->bssid[0], &wfx_rsi.ap_mac.octet[0], BSSID_MAX_STR_LEN);
102101
status = rsi_wlan_get(RSI_RSSI, &rssi, sizeof(rssi));
@@ -435,7 +434,7 @@ void wfx_show_err(char * msg)
435434
* @return
436435
* None
437436
*******************************************************************************************/
438-
static void wfx_rsi_save_ap_info()
437+
static void wfx_rsi_save_ap_info() // translation
439438
{
440439
int32_t status;
441440
rsi_rsp_scan_t rsp;
@@ -450,22 +449,36 @@ static void wfx_rsi_save_ap_info()
450449
}
451450
else
452451
{
453-
wfx_rsi.sec.security = rsp.scan_info->security_mode;
452+
wfx_rsi.sec.security = WFX_SEC_UNSPECIFIED;
454453
wfx_rsi.ap_chan = rsp.scan_info->rf_channel;
455454
memcpy(&wfx_rsi.ap_mac.octet[0], &rsp.scan_info->bssid[0], BSSID_MAX_STR_LEN);
456455
}
457-
if ((wfx_rsi.sec.security == RSI_WPA) || (wfx_rsi.sec.security == RSI_WPA2))
458-
{
459-
// saving the security before changing into mixed mode
460-
security = wfx_rsi.sec.security;
461-
wfx_rsi.sec.security = RSI_WPA_WPA2_MIXED;
462-
}
463-
if (wfx_rsi.sec.security == SME_WPA3)
456+
457+
switch (rsp.scan_info->security_mode)
464458
{
465-
// returning 3 for WPA3 when DGWIFI read security-type is called
466-
security = WPA3_SECURITY;
467-
wfx_rsi.sec.security = RSI_WPA3;
459+
case SME_OPEN:
460+
wfx_rsi.sec.security = WFX_SEC_NONE;
461+
break;
462+
case SME_WPA:
463+
case SME_WPA_ENTERPRISE:
464+
wfx_rsi.sec.security = WFX_SEC_WPA;
465+
break;
466+
case SME_WPA2:
467+
case SME_WPA2_ENTERPRISE:
468+
wfx_rsi.sec.security = WFX_SEC_WPA2;
469+
break;
470+
case SME_WEP:
471+
wfx_rsi.sec.security = WFX_SEC_WEP;
472+
break;
473+
case SME_WPA3:
474+
case SME_WPA3_TRANSITION:
475+
wfx_rsi.sec.security = WFX_SEC_WPA3;
476+
break;
477+
default:
478+
wfx_rsi.sec.security = WFX_SEC_UNSPECIFIED;
479+
break;
468480
}
481+
469482
WFX_RSI_LOG("%s: WLAN: connecting to %s==%s, sec=%d, status=%02x", __func__, &wfx_rsi.sec.ssid[0], &wfx_rsi.sec.passkey[0],
470483
wfx_rsi.sec.security, status);
471484
}
@@ -480,13 +493,35 @@ static void wfx_rsi_save_ap_info()
480493
static void wfx_rsi_do_join(void)
481494
{
482495
int32_t status;
496+
rsi_security_mode_t connect_security_mode;
483497

484498
if (wfx_rsi.dev_state & (WFX_RSI_ST_STA_CONNECTING | WFX_RSI_ST_STA_CONNECTED))
485499
{
486500
WFX_RSI_LOG("%s: not joining - already in progress", __func__);
487501
}
488502
else
489503
{
504+
505+
switch (wfx_rsi.sec.security)
506+
{
507+
case WFX_SEC_WEP:
508+
connect_security_mode = RSI_WEP;
509+
break;
510+
case WFX_SEC_WPA:
511+
case WFX_SEC_WPA2:
512+
connect_security_mode = RSI_WPA_WPA2_MIXED;
513+
break;
514+
case WFX_SEC_WPA3:
515+
connect_security_mode = RSI_WPA3;
516+
break;
517+
case WFX_SEC_NONE:
518+
connect_security_mode = RSI_OPEN;
519+
break;
520+
default:
521+
WFX_RSI_LOG("%s: error: unknown security type.");
522+
return;
523+
}
524+
490525
WFX_RSI_LOG("%s: WLAN: connecting to %s==%s, sec=%d", __func__, &wfx_rsi.sec.ssid[0], &wfx_rsi.sec.passkey[0],
491526
wfx_rsi.sec.security);
492527

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

518553
wfx_rsi.dev_state &= ~WFX_RSI_ST_STA_CONNECTING;

examples/platform/silabs/efr32/wf200/host_if.cpp

+25-24
Original file line numberDiff line numberDiff line change
@@ -312,6 +312,7 @@ static void sl_wfx_scan_result_callback(sl_wfx_scan_result_ind_body_t * scan_res
312312
ap->scan.ssid[scan_result->ssid_def.ssid_length] = 0; /* make sure about null terminate */
313313
/* We do it in this order WPA3 first */
314314
/* No EAP supported - Is this required */
315+
ap->scan.security = WFX_SEC_UNSPECIFIED;
315316
if (scan_result->security_mode.wpa3)
316317
{
317318
ap->scan.security = WFX_SEC_WPA3;
@@ -967,27 +968,8 @@ void wfx_set_wifi_provision(wfx_wifi_provision_t * wifiConfig)
967968
{
968969
memcpy(wifi_provision.ssid, wifiConfig->ssid, sizeof(wifiConfig->ssid));
969970
memcpy(wifi_provision.passkey, wifiConfig->passkey, sizeof(wifiConfig->passkey));
971+
wifi_provision.security = wifiConfig->security;
970972
SILABS_LOG("WIFI: Provision SSID=%s", &wifi_provision.ssid[0]);
971-
972-
/* Not very good - To be improved */
973-
switch (wifiConfig->security)
974-
{
975-
case WFX_SEC_WPA:
976-
wifi_provision.security = static_cast<uint8_t>(sl_wfx_security_mode_e::WFM_SECURITY_MODE_WPA2_WPA1_PSK);
977-
break;
978-
case WFX_SEC_WPA3:
979-
wifi_provision.security = WFM_SECURITY_MODE_WPA3_SAE;
980-
break;
981-
case WFX_SEC_WPA2:
982-
wifi_provision.security = static_cast<uint8_t>(sl_wfx_security_mode_e::WFM_SECURITY_MODE_WPA2_WPA1_PSK);
983-
break;
984-
case WFX_SEC_WPA_WPA2_MIXED:
985-
wifi_provision.security = static_cast<uint8_t>(sl_wfx_security_mode_e::WFM_SECURITY_MODE_WPA2_WPA1_PSK);
986-
break;
987-
default:
988-
wifi_provision.security = WFM_SECURITY_MODE_WPA2_PSK;
989-
break;
990-
}
991973
}
992974

993975
/****************************************************************************
@@ -1039,6 +1021,7 @@ bool wfx_is_sta_provisioned(void)
10391021
sl_status_t wfx_connect_to_ap(void)
10401022
{
10411023
sl_status_t result;
1024+
sl_wfx_security_mode_t connect_security_mode;
10421025

10431026
if (wifi_provision.ssid[0] == 0)
10441027
{
@@ -1050,10 +1033,28 @@ sl_status_t wfx_connect_to_ap(void)
10501033
"Time: %d, Number of prob: %d",
10511034
ACTIVE_CHANNEL_TIME, PASSIVE_CHANNEL_TIME, NUM_PROBE_REQUEST);
10521035
(void) sl_wfx_set_scan_parameters(ACTIVE_CHANNEL_TIME, PASSIVE_CHANNEL_TIME, NUM_PROBE_REQUEST);
1053-
result =
1054-
sl_wfx_send_join_command((uint8_t *) wifi_provision.ssid, strlen(wifi_provision.ssid), NULL, CHANNEL_0,
1055-
static_cast<sl_wfx_security_mode_t>(wifi_provision.security), PREVENT_ROAMING, DISABLE_PMF_MODE,
1056-
(uint8_t *) wifi_provision.passkey, strlen(wifi_provision.passkey), NULL, IE_DATA_LENGTH);
1036+
switch (wifi_provision.security)
1037+
{
1038+
case WFX_SEC_WEP:
1039+
connect_security_mode = sl_wfx_security_mode_e::WFM_SECURITY_MODE_WEP;
1040+
break;
1041+
case WFX_SEC_WPA:
1042+
case WFX_SEC_WPA2:
1043+
connect_security_mode = sl_wfx_security_mode_e::WFM_SECURITY_MODE_WPA2_WPA1_PSK;
1044+
break;
1045+
case WFX_SEC_WPA3:
1046+
connect_security_mode = sl_wfx_security_mode_e::WFM_SECURITY_MODE_WPA3_SAE;
1047+
break;
1048+
case WFX_SEC_NONE:
1049+
connect_security_mode = sl_wfx_security_mode_e::WFM_SECURITY_MODE_OPEN;
1050+
break;
1051+
default:
1052+
SILABS_LOG("%s: error: unknown security type.");
1053+
return SL_STATUS_INVALID_STATE;
1054+
}
1055+
result = sl_wfx_send_join_command((uint8_t *) wifi_provision.ssid, strlen(wifi_provision.ssid), NULL, CHANNEL_0,
1056+
connect_security_mode, PREVENT_ROAMING, DISABLE_PMF_MODE, (uint8_t *) wifi_provision.passkey,
1057+
strlen(wifi_provision.passkey), NULL, IE_DATA_LENGTH);
10571058

10581059
return result;
10591060
}

src/platform/silabs/NetworkCommissioningWiFiDriver.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ CHIP_ERROR SlWiFiDriver::ConnectWiFiNetwork(const char * ssid, uint8_t ssidLen,
149149
wfx_wifi_provision_t wifiConfig = {};
150150
memcpy(wifiConfig.ssid, ssid, ssidLen);
151151
memcpy(wifiConfig.passkey, key, keyLen);
152-
wifiConfig.security = WFX_SEC_WPA_WPA2_MIXED;
152+
wifiConfig.security = WFX_SEC_WPA2;
153153

154154
ChipLogProgress(NetworkProvisioning, "Setting up connection for WiFi SSID: %.*s", static_cast<int>(ssidLen), ssid);
155155
// Configure the WFX WiFi interface.

src/platform/silabs/SiWx917/wifi/wfx_host_events.h

+8-18
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,6 @@
131131
#define BG_SCAN_RES_SIZE 500
132132

133133
#define SPI_CONFIG_SUCCESS 0
134-
#define WPA3_SECURITY 3
135134

136135
typedef enum
137136
{
@@ -149,28 +148,19 @@ typedef enum
149148
/* Note that these are same as RSI_security */
150149
typedef enum
151150
{
152-
WFX_SEC_NONE = 0,
153-
WFX_SEC_WPA = 1,
154-
WFX_SEC_WPA2 = 2,
155-
WFX_SEC_WEP = 3,
156-
WFX_SEC_WPA_EAP = 4,
157-
WFX_SEC_WPA2_EAP = 5,
158-
WFX_SEC_WPA_WPA2_MIXED = 6,
159-
WFX_SEC_WPA_PMK = 7,
160-
WFX_SEC_WPA2_PMK = 8,
161-
WFX_SEC_WPS_PIN = 9,
162-
WFX_SEC_GEN_WPS_PIN = 10,
163-
WFX_SEC_PUSH_BTN = 11,
164-
WFX_SEC_WPA3 = 11,
151+
WFX_SEC_UNSPECIFIED = 0,
152+
WFX_SEC_NONE = 1,
153+
WFX_SEC_WEP = 2,
154+
WFX_SEC_WPA = 3,
155+
WFX_SEC_WPA2 = 4,
156+
WFX_SEC_WPA3 = 5
165157
} wfx_sec_t;
166158

167-
#define WPA3_SECURITY 3
168-
169159
typedef struct
170160
{
171161
char ssid[32 + 1];
172162
char passkey[64 + 1];
173-
uint8_t security;
163+
wfx_sec_t security;
174164
} wfx_wifi_provision_t;
175165

176166
typedef enum
@@ -185,7 +175,7 @@ typedef enum
185175
typedef struct wfx_wifi_scan_result
186176
{
187177
char ssid[32 + 1];
188-
uint8_t security;
178+
wfx_sec_t security;
189179
uint8_t bssid[6];
190180
uint8_t chan;
191181
int16_t rssi; /* I suspect this is in dBm - so signed */

0 commit comments

Comments
 (0)