Skip to content

Commit 7cbcd1d

Browse files
krish2718nashif
authored andcommitted
modules: hostap: Add checks for WPA3
If the WPA3 is disabled in the build handle gracefully rather than cryptic supplicant internal messages. Signed-off-by: Chaitanya Tata <[email protected]>
1 parent 237e4e4 commit 7cbcd1d

File tree

1 file changed

+58
-39
lines changed

1 file changed

+58
-39
lines changed

modules/hostap/src/supp_api.c

Lines changed: 58 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#include <zephyr/logging/log.h>
1010
#include <zephyr/kernel.h>
1111
#include <zephyr/net/wifi_mgmt.h>
12+
#include <zephyr/sys/util.h>
1213

1314
#include "includes.h"
1415
#include "common.h"
@@ -399,13 +400,16 @@ enum wifi_security_type wpas_key_mgmt_to_zephyr(bool is_hapd, void *config, int
399400
case WPA_KEY_MGMT_PSK_SHA256:
400401
return WIFI_SECURITY_TYPE_PSK_SHA256;
401402
case WPA_KEY_MGMT_SAE:
402-
if (pwe == 1) {
403-
return WIFI_SECURITY_TYPE_SAE_H2E;
404-
} else if (pwe == 2) {
405-
return WIFI_SECURITY_TYPE_SAE_AUTO;
406-
} else {
407-
return WIFI_SECURITY_TYPE_SAE_HNP;
403+
if (IS_ENABLED(CONFIG_WIFI_NM_WPA_SUPPLICANT_WPA3)) {
404+
if (pwe == 1) {
405+
return WIFI_SECURITY_TYPE_SAE_H2E;
406+
} else if (pwe == 2) {
407+
return WIFI_SECURITY_TYPE_SAE_AUTO;
408+
} else {
409+
return WIFI_SECURITY_TYPE_SAE_HNP;
410+
}
408411
}
412+
return WIFI_SECURITY_TYPE_UNKNOWN;
409413
case WPA_KEY_MGMT_PSK_SHA256 | WPA_KEY_MGMT_PSK:
410414
case WPA_KEY_MGMT_SAE | WPA_KEY_MGMT_PSK:
411415
case WPA_KEY_MGMT_SAE | WPA_KEY_MGMT_PSK_SHA256:
@@ -414,15 +418,21 @@ enum wifi_security_type wpas_key_mgmt_to_zephyr(bool is_hapd, void *config, int
414418
case WPA_KEY_MGMT_FT_PSK:
415419
return WIFI_SECURITY_TYPE_FT_PSK;
416420
case WPA_KEY_MGMT_FT_SAE:
417-
return WIFI_SECURITY_TYPE_FT_SAE;
421+
if (IS_ENABLED(CONFIG_WIFI_NM_WPA_SUPPLICANT_WPA3)) {
422+
return WIFI_SECURITY_TYPE_FT_SAE;
423+
}
424+
return WIFI_SECURITY_TYPE_UNKNOWN;
418425
case WPA_KEY_MGMT_FT_IEEE8021X:
419426
return WIFI_SECURITY_TYPE_FT_EAP;
420427
case WPA_KEY_MGMT_DPP:
421428
return WIFI_SECURITY_TYPE_DPP;
422429
case WPA_KEY_MGMT_FT_IEEE8021X_SHA384:
423430
return WIFI_SECURITY_TYPE_FT_EAP_SHA384;
424431
case WPA_KEY_MGMT_SAE_EXT_KEY:
425-
return WIFI_SECURITY_TYPE_SAE_EXT_KEY;
432+
if (IS_ENABLED(CONFIG_WIFI_NM_WPA_SUPPLICANT_WPA3)) {
433+
return WIFI_SECURITY_TYPE_SAE_EXT_KEY;
434+
}
435+
return WIFI_SECURITY_TYPE_UNKNOWN;
426436
case WPA_KEY_MGMT_DPP | WPA_KEY_MGMT_PSK:
427437
return WIFI_SECURITY_TYPE_DPP;
428438
default:
@@ -711,10 +721,11 @@ static int wpas_add_and_config_network(struct wpa_supplicant *wpa_s,
711721
}
712722
}
713723

714-
if (params->security == WIFI_SECURITY_TYPE_SAE_HNP ||
715-
params->security == WIFI_SECURITY_TYPE_SAE_H2E ||
716-
params->security == WIFI_SECURITY_TYPE_SAE_AUTO ||
717-
params->security == WIFI_SECURITY_TYPE_SAE_EXT_KEY) {
724+
if (IS_ENABLED(CONFIG_WIFI_NM_WPA_SUPPLICANT_WPA3) &&
725+
(params->security == WIFI_SECURITY_TYPE_SAE_HNP ||
726+
params->security == WIFI_SECURITY_TYPE_SAE_H2E ||
727+
params->security == WIFI_SECURITY_TYPE_SAE_AUTO ||
728+
params->security == WIFI_SECURITY_TYPE_SAE_EXT_KEY)) {
718729
if (params->sae_password) {
719730
if ((params->sae_password_length < WIFI_PSK_MIN_LEN) ||
720731
(params->sae_password_length > WIFI_SAE_PSWD_MAX_LEN)) {
@@ -811,42 +822,50 @@ static int wpas_add_and_config_network(struct wpa_supplicant *wpa_s,
811822
goto out;
812823
}
813824
} else if (params->security == WIFI_SECURITY_TYPE_WPA_AUTO_PERSONAL) {
814-
if (params->sae_password) {
815-
if ((params->sae_password_length < WIFI_PSK_MIN_LEN) ||
816-
(params->sae_password_length > WIFI_SAE_PSWD_MAX_LEN)) {
817-
wpa_printf(MSG_ERROR,
818-
"Passphrase should be in range (%d-%d) characters",
819-
WIFI_PSK_MIN_LEN, WIFI_SAE_PSWD_MAX_LEN);
825+
if (!wpa_cli_cmd_v("set_network %d psk \"%s\"", resp.network_id,
826+
psk_null_terminated)) {
827+
goto out;
828+
}
829+
830+
if (IS_ENABLED(CONFIG_WIFI_NM_WPA_SUPPLICANT_WPA3)) {
831+
if (params->sae_password) {
832+
if ((params->sae_password_length < WIFI_PSK_MIN_LEN) ||
833+
(params->sae_password_length > WIFI_SAE_PSWD_MAX_LEN)) {
834+
wpa_printf(MSG_ERROR,
835+
"Passphrase should be in range (%d-%d) characters",
836+
WIFI_PSK_MIN_LEN, WIFI_SAE_PSWD_MAX_LEN);
837+
goto out;
838+
}
839+
strncpy(sae_null_terminated, params->sae_password,
840+
WIFI_SAE_PSWD_MAX_LEN);
841+
sae_null_terminated[params->sae_password_length] = '\0';
842+
if (!wpa_cli_cmd_v("set_network %d sae_password \"%s\"",
843+
resp.network_id, sae_null_terminated)) {
844+
goto out;
845+
}
846+
} else {
847+
if (!wpa_cli_cmd_v("set_network %d sae_password \"%s\"",
848+
resp.network_id, psk_null_terminated)) {
849+
goto out;
850+
}
851+
}
852+
853+
if (!wpa_cli_cmd_v("set sae_pwe 2")) {
820854
goto out;
821855
}
822-
strncpy(sae_null_terminated, params->sae_password,
823-
WIFI_SAE_PSWD_MAX_LEN);
824-
sae_null_terminated[params->sae_password_length] = '\0';
825-
if (!wpa_cli_cmd_v("set_network %d sae_password \"%s\"",
826-
resp.network_id, sae_null_terminated)) {
856+
857+
if (!wpa_cli_cmd_v(
858+
"set_network %d key_mgmt WPA-PSK WPA-PSK-SHA256 SAE",
859+
resp.network_id)) {
827860
goto out;
828861
}
829862
} else {
830-
if (!wpa_cli_cmd_v("set_network %d sae_password \"%s\"",
831-
resp.network_id, psk_null_terminated)) {
863+
if (!wpa_cli_cmd_v("set_network %d key_mgmt WPA-PSK WPA-PSK-SHA256",
864+
resp.network_id)) {
832865
goto out;
833866
}
834867
}
835868

836-
if (!wpa_cli_cmd_v("set_network %d psk \"%s\"", resp.network_id,
837-
psk_null_terminated)) {
838-
goto out;
839-
}
840-
841-
if (!wpa_cli_cmd_v("set sae_pwe 2")) {
842-
goto out;
843-
}
844-
845-
if (!wpa_cli_cmd_v("set_network %d key_mgmt WPA-PSK WPA-PSK-SHA256 SAE",
846-
resp.network_id)) {
847-
goto out;
848-
}
849-
850869
if (!wpa_cli_cmd_v("set_network %d proto WPA RSN", resp.network_id)) {
851870
goto out;
852871
}

0 commit comments

Comments
 (0)