Skip to content

Commit 7f956a9

Browse files
Gil Pitneyjukkar
authored andcommitted
drivers: wifi: simplelink: add timeout for fast connect feature
The SimpleLink wifi driver enables the Fast Connect method of WiFi provisioning, which allows the network coprocessor to reconnect to a previously connected Access Point (AP) on startup. Previously, if Fast Connect failed to connect, any network socket applications would inevitably fail, as there would have been no wifi connection. This patch adds a configurable timeout for the Fast Connect feature, after which timeout, an error is logged informing the user to manually reconnect to an AP. Reconnection is typically accomplished by separately running the wifi sample shell program. Fixes: zephyrproject-rtos#11889 Signed-off-by: Gil Pitney <[email protected]>
1 parent 32cbc42 commit 7f956a9

File tree

2 files changed

+27
-3
lines changed

2 files changed

+27
-3
lines changed

drivers/wifi/simplelink/Kconfig.simplelink

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,4 +42,13 @@ config WIFI_SIMPLELINK_MAX_SCAN_RETRIES
4242
The number of times, separated by a one second interval, to retry
4343
a request for the network list.
4444

45+
config WIFI_SIMPLELINK_FAST_CONNECT_TIMEOUT
46+
int "Time (in seconds) to wait for fast connect on startup"
47+
default 7
48+
help
49+
SimpleLink uses the "FastConnect" feature to reconnect to the
50+
previously connected AP on startup. Should the WiFi connection
51+
timeout, the SimpleLink driver will fail to initialize,
52+
and LOG an error.
53+
4554
endif # WIFI_SIMPLELINK

drivers/wifi/simplelink/simplelink.c

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ LOG_MODULE_REGISTER(LOG_MODULE_NAME);
2222
#include "simplelink_sockets.h"
2323

2424
#define SCAN_RETRY_DELAY 2000 /* ms */
25+
#define FC_TIMEOUT K_SECONDS(CONFIG_WIFI_SIMPLELINK_FAST_CONNECT_TIMEOUT)
2526

2627
struct simplelink_data {
2728
struct net_if *iface;
@@ -32,9 +33,11 @@ struct simplelink_data {
3233
scan_result_cb_t cb;
3334
int num_results_or_err;
3435
int scan_retries;
36+
bool initialized;
3537
};
3638

3739
static struct simplelink_data simplelink_data;
40+
static K_SEM_DEFINE(ip_acquired, 0, 1);
3841

3942
/* Handle connection events from the SimpleLink Event Handlers: */
4043
static void simplelink_wifi_cb(u32_t event, struct sl_connect_state *conn)
@@ -68,6 +71,11 @@ static void simplelink_wifi_cb(u32_t event, struct sl_connect_state *conn)
6871
net_if_ipv4_set_gw(simplelink_data.iface, &gwaddr);
6972
net_if_ipv4_addr_add(simplelink_data.iface, &addr,
7073
NET_ADDR_DHCP, 0);
74+
75+
if (!simplelink_data.initialized) {
76+
simplelink_data.initialized = true;
77+
k_sem_give(&ip_acquired);
78+
}
7179
break;
7280

7381
default:
@@ -203,13 +211,23 @@ static void simplelink_iface_init(struct net_if *iface)
203211

204212
simplelink_data.iface = iface;
205213

214+
/* Direct socket offload used instead of net offload: */
215+
iface->if_dev->offload = &simplelink_offload;
216+
206217
/* Initialize and configure NWP to defaults: */
207218
ret = _simplelink_init(simplelink_wifi_cb);
208219
if (ret) {
209220
LOG_ERR("_simplelink_init failed!");
210221
return;
211222
}
212223

224+
ret = k_sem_take(&ip_acquired, FC_TIMEOUT);
225+
if (ret < 0) {
226+
simplelink_data.initialized = false;
227+
LOG_ERR("FastConnect timed out connecting to previous AP.");
228+
LOG_ERR("Please re-establish WiFi connection.");
229+
}
230+
213231
/* Grab our MAC address: */
214232
_simplelink_get_mac(simplelink_data.mac);
215233

@@ -223,9 +241,6 @@ static void simplelink_iface_init(struct net_if *iface)
223241
sizeof(simplelink_data.mac),
224242
NET_LINK_ETHERNET);
225243

226-
/* Direct socket offload used instead of net offload: */
227-
iface->if_dev->offload = &simplelink_offload;
228-
229244
#ifdef CONFIG_NET_SOCKETS_OFFLOAD
230245
/* Direct socket offload: */
231246
socket_offload_register(&simplelink_ops);

0 commit comments

Comments
 (0)