Skip to content

Commit 085b216

Browse files
npal-cykartben
authored andcommitted
drivers: wifi: AIROC: update connect\scan api
- Updated airoc_mgmt_connect to be able use security provided by user (params->security). If it is not passed, we will perform scan ssid to detect secure type. - Fix convert_whd_security_to_zephyr() with correct corresponding whd_security_t to zephyr security type. Signed-off-by: Nazar Palamar <[email protected]>
1 parent c9ffcac commit 085b216

File tree

1 file changed

+66
-24
lines changed

1 file changed

+66
-24
lines changed

drivers/wifi/infineon/airoc_wifi.c

Lines changed: 66 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -154,9 +154,12 @@ static int convert_whd_security_to_zephyr(whd_security_t security)
154154
break;
155155

156156
case WHD_SECURITY_WEP_PSK:
157+
case WHD_SECURITY_WEP_SHARED:
157158
zephyr_security = WIFI_SECURITY_TYPE_WEP;
158159
break;
159160

161+
case WHD_SECURITY_WPA2_WPA_MIXED_PSK:
162+
case WHD_SECURITY_WPA2_WPA_AES_PSK:
160163
case WHD_SECURITY_WPA3_WPA2_PSK:
161164
zephyr_security = WIFI_SECURITY_TYPE_WPA_AUTO_PERSONAL;
162165
break;
@@ -173,6 +176,8 @@ static int convert_whd_security_to_zephyr(whd_security_t security)
173176
zephyr_security = WIFI_SECURITY_TYPE_SAE;
174177
break;
175178

179+
case WHD_SECURITY_WPA_TKIP_PSK:
180+
case WHD_SECURITY_WPA_MIXED_PSK:
176181
case WHD_SECURITY_WPA_AES_PSK:
177182
zephyr_security = WIFI_SECURITY_TYPE_WPA_PSK;
178183
break;
@@ -186,6 +191,45 @@ static int convert_whd_security_to_zephyr(whd_security_t security)
186191
return zephyr_security;
187192
}
188193

194+
static whd_security_t convert_zephyr_security_to_whd(int security)
195+
{
196+
whd_security_t whd_security = WIFI_SECURITY_TYPE_UNKNOWN;
197+
198+
switch (security) {
199+
case WIFI_SECURITY_TYPE_NONE:
200+
whd_security = WHD_SECURITY_OPEN;
201+
break;
202+
203+
case WIFI_SECURITY_TYPE_WEP:
204+
whd_security = WHD_SECURITY_WEP_PSK;
205+
break;
206+
207+
case WIFI_SECURITY_TYPE_WPA_AUTO_PERSONAL:
208+
whd_security = WHD_SECURITY_WPA3_WPA2_PSK;
209+
break;
210+
211+
case WIFI_SECURITY_TYPE_PSK:
212+
whd_security = WHD_SECURITY_WPA2_AES_PSK;
213+
break;
214+
215+
case WIFI_SECURITY_TYPE_PSK_SHA256:
216+
whd_security = WIFI_SECURITY_TYPE_PSK_SHA256;
217+
break;
218+
219+
case WIFI_SECURITY_TYPE_SAE:
220+
whd_security = WHD_SECURITY_WPA3_SAE;
221+
break;
222+
223+
case WIFI_SECURITY_TYPE_WPA_PSK:
224+
whd_security = WHD_SECURITY_WPA_AES_PSK;
225+
break;
226+
227+
default:
228+
break;
229+
}
230+
return whd_security;
231+
}
232+
189233
static void parse_scan_result(whd_scan_result_t *p_whd_result, struct wifi_scan_result *p_zy_result)
190234
{
191235
if (p_whd_result->SSID.length != 0) {
@@ -506,8 +550,9 @@ static int airoc_mgmt_scan(const struct device *dev, struct wifi_scan_params *pa
506550
static int airoc_mgmt_connect(const struct device *dev, struct wifi_connect_req_params *params)
507551
{
508552
struct airoc_wifi_data *data = (struct airoc_wifi_data *)dev->data;
509-
whd_ssid_t ssid = {0};
510553
int ret = 0;
554+
whd_scan_result_t scan_result;
555+
whd_scan_result_t usr_result = {0};
511556

512557
if (k_sem_take(&data->sema_common, K_MSEC(AIROC_WIFI_WAIT_SEMA_MS)) != 0) {
513558
return -EAGAIN;
@@ -525,27 +570,29 @@ static int airoc_mgmt_connect(const struct device *dev, struct wifi_connect_req_
525570
goto error;
526571
}
527572

528-
ssid.length = params->ssid_length;
529-
memcpy(ssid.value, params->ssid, params->ssid_length);
573+
usr_result.SSID.length = params->ssid_length;
574+
memcpy(usr_result.SSID.value, params->ssid, params->ssid_length);
530575

531-
whd_scan_result_t scan_result;
532-
whd_scan_result_t usr_result = {0};
533-
534-
usr_result.SSID.length = ssid.length;
535-
memcpy(usr_result.SSID.value, ssid.value, ssid.length);
576+
if ((params->security == WIFI_SECURITY_TYPE_NONE) && (params->psk_length > 0)) {
577+
/* Try to scan ssid to define security */
536578

537-
if (whd_wifi_scan(airoc_sta_if, WHD_SCAN_TYPE_ACTIVE, WHD_BSS_TYPE_ANY, NULL, NULL, NULL,
538-
NULL, airoc_wifi_scan_cb_search, &scan_result,
539-
&(usr_result)) != WHD_SUCCESS) {
540-
LOG_ERR("Failed start scan");
541-
ret = -EAGAIN;
542-
goto error;
543-
}
579+
if (whd_wifi_scan(airoc_sta_if, WHD_SCAN_TYPE_ACTIVE, WHD_BSS_TYPE_ANY, NULL, NULL,
580+
NULL, NULL, airoc_wifi_scan_cb_search, &scan_result,
581+
&(usr_result)) != WHD_SUCCESS) {
582+
LOG_ERR("Failed start scan");
583+
ret = -EAGAIN;
584+
goto error;
585+
}
544586

545-
if (k_sem_take(&airoc_wifi_data.sema_scan, K_MSEC(AIROC_WIFI_SCAN_TIMEOUT_MS)) != 0) {
546-
whd_wifi_stop_scan(airoc_sta_if);
547-
ret = -EAGAIN;
548-
goto error;
587+
if (k_sem_take(&airoc_wifi_data.sema_scan, K_MSEC(AIROC_WIFI_SCAN_TIMEOUT_MS)) !=
588+
0) {
589+
whd_wifi_stop_scan(airoc_sta_if);
590+
ret = -EAGAIN;
591+
goto error;
592+
}
593+
} else {
594+
/* Get security from user, convert it to */
595+
usr_result.security = convert_zephyr_security_to_whd(params->security);
549596
}
550597

551598
if (usr_result.security == WHD_SECURITY_UNKNOWN) {
@@ -554,11 +601,6 @@ static int airoc_mgmt_connect(const struct device *dev, struct wifi_connect_req_
554601
goto error;
555602
}
556603

557-
if (usr_result.security == WHD_SECURITY_WPA3_WPA2_PSK)
558-
{
559-
usr_result.security = WHD_SECURITY_WPA2_AES_PSK;
560-
}
561-
562604
/* Connect to the network */
563605
if (whd_wifi_join(airoc_sta_if, &usr_result.SSID, usr_result.security, params->psk,
564606
params->psk_length) != WHD_SUCCESS) {

0 commit comments

Comments
 (0)