diff --git a/samples/wifi/sta/Kconfig b/samples/wifi/sta/Kconfig index 8b7c04bba40a..dcef2b3d5e11 100644 --- a/samples/wifi/sta/Kconfig +++ b/samples/wifi/sta/Kconfig @@ -12,41 +12,6 @@ config CONNECTION_IDLE_TIMEOUT int "Time to be waited for a station to connect" default 30 -config STA_SAMPLE_SSID - string "SSID" - help - Specify the SSID to connect - -choice STA_KEY_MGMT_SELECT - prompt "Security Option" - default STA_KEY_MGMT_WPA3 - -config STA_KEY_MGMT_NONE - bool "Open Security" - help - Enable for Open Security - -config STA_KEY_MGMT_WPA2 - bool "WPA2 Security" - help - Enable for WPA2 Security - -config STA_KEY_MGMT_WPA2_256 - bool "WPA2 SHA 256 Security" - help - Enable for WPA2-PSK-256 Security - -config STA_KEY_MGMT_WPA3 - bool "WPA3 Security" - help - Enable for WPA3 Security -endchoice - -config STA_SAMPLE_PASSWORD - string "Passphrase (WPA2) or password (WPA3)" - help - Specify the Password to connect - config NRF700X_QSPI_ENCRYPTION_KEY string "16 bytes QSPI encryption key, only for testing purposes" depends on BOARD_NRF7002DK_NRF5340_CPUAPP diff --git a/samples/wifi/sta/prj.conf b/samples/wifi/sta/prj.conf index 465135fa3288..a53a349533d6 100644 --- a/samples/wifi/sta/prj.conf +++ b/samples/wifi/sta/prj.conf @@ -9,13 +9,11 @@ CONFIG_WIFI_NRF700X=y # WPA supplicant CONFIG_WPA_SUPP=y -# Below configs need to be modified based on security -# CONFIG_STA_KEY_MGMT_NONE=y -# CONFIG_STA_KEY_MGMT_WPA2=y -# CONFIG_STA_KEY_MGMT_WPA2_256=y -# CONFIG_STA_KEY_MGMT_WPA3=y -CONFIG_STA_SAMPLE_SSID="Myssid" -CONFIG_STA_SAMPLE_PASSWORD="Mypassword" +CONFIG_WIFI_MGMT_EXT=y +CONFIG_WIFI_CREDENTIALS=y +CONFIG_WIFI_CREDENTIALS_STATIC=y +CONFIG_WIFI_CREDENTIALS_STATIC_SSID="Myssid" +CONFIG_WIFI_CREDENTIALS_STATIC_PASSWORD="Mypassword" # System settings CONFIG_NEWLIB_LIBC=y diff --git a/samples/wifi/sta/src/main.c b/samples/wifi/sta/src/main.c index 83ccd49843fb..0d6eaf4b60e8 100644 --- a/samples/wifi/sta/src/main.c +++ b/samples/wifi/sta/src/main.c @@ -24,6 +24,9 @@ LOG_MODULE_REGISTER(sta, CONFIG_LOG_DEFAULT_LEVEL); #include #include +#include +#include + #include #include "net_private.h" @@ -125,6 +128,7 @@ static int cmd_wifi_status(void) LOG_INF("MFP: %s", wifi_mfp_txt(status.mfp)); LOG_INF("RSSI: %d", status.rssi); } + return 0; } @@ -195,6 +199,7 @@ static void print_dhcp_ip(struct net_mgmt_event_callback *cb) LOG_INF("DHCP IP address: %s", dhcp_info); } + static void net_mgmt_event_handler(struct net_mgmt_event_callback *cb, uint32_t mgmt_event, struct net_if *iface) { @@ -207,56 +212,18 @@ static void net_mgmt_event_handler(struct net_mgmt_event_callback *cb, } } -static int __wifi_args_to_params(struct wifi_connect_req_params *params) -{ - - params->timeout = CONFIG_STA_CONN_TIMEOUT_SEC * MSEC_PER_SEC; - - if (params->timeout == 0) { - params->timeout = SYS_FOREVER_MS; - } - - /* Defaults */ - params->band = WIFI_FREQ_BAND_UNKNOWN; - params->channel = WIFI_CHANNEL_ANY; - params->security = WIFI_SECURITY_TYPE_NONE; - params->mfp = WIFI_MFP_OPTIONAL; - - /* SSID */ - params->ssid = CONFIG_STA_SAMPLE_SSID; - params->ssid_length = strlen(params->ssid); - -#if defined(CONFIG_STA_KEY_MGMT_WPA2) - params->security = 1; -#elif defined(CONFIG_STA_KEY_MGMT_WPA2_256) - params->security = 2; -#elif defined(CONFIG_STA_KEY_MGMT_WPA3) - params->security = 3; -#else - params->security = 0; -#endif - -#if !defined(CONFIG_STA_KEY_MGMT_NONE) - params->psk = CONFIG_STA_SAMPLE_PASSWORD; - params->psk_length = strlen(params->psk); -#endif - - return 0; -} - static int wifi_connect(void) { - struct net_if *iface = net_if_get_default(); - static struct wifi_connect_req_params cnx_params; + struct net_if *iface = net_if_get_first_wifi(); + int ret; context.connected = false; context.connect_result = false; - __wifi_args_to_params(&cnx_params); - if (net_mgmt(NET_REQUEST_WIFI_CONNECT, iface, - &cnx_params, sizeof(struct wifi_connect_req_params))) { + /* Apply stored wifi credential */ + ret = net_mgmt(NET_REQUEST_WIFI_CONNECT_STORED, iface, NULL, 0); + if (ret) { LOG_ERR("Connection request failed"); - return -ENOEXEC; }