forked from nrfconnect/sdk-nrf
-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
samples: wifi: sta: Use wifi_cred library #11
Closed
+15
−85
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,6 +24,9 @@ LOG_MODULE_REGISTER(sta, CONFIG_LOG_DEFAULT_LEVEL); | |
#include <zephyr/net/net_event.h> | ||
#include <zephyr/drivers/gpio.h> | ||
|
||
#include <net/wifi_credentials.h> | ||
#include <net/wifi_mgmt_ext.h> | ||
|
||
#include <qspi_if.h> | ||
|
||
#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); | ||
} | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. unnecessary whitespace |
||
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"); | ||
|
||
D-Triveni marked this conversation as resolved.
Show resolved
Hide resolved
|
||
return -ENOEXEC; | ||
} | ||
|
||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this needed? As we are only calling the Wi-Fi mgmt ext API?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not needed.