WiFi autoscan improvement
by Raul.Camacho@continental-corporation.com
Hi All,
My name is Raul Camacho and I am software developer on Continental
Automotive company. I am involved on projects which use connman to handle
WiFi technology (STA) and
currently we have a customer requirement which specifies that our product
needs to perform a periodic autoscan when WiFi is enabled (STA). connman
by itself has
predefined autoscan scheme "exponential:3:300", however in order to meet
our customer requeriment, I proposed the following implemetation on
connman (wifi plugin):
diff --git a/plugins/wifi.c b/plugins/wifi.c
index 9d56671..4bc7bec 100644
--- a/plugins/wifi.c
+++ b/plugins/wifi.c
@@ -64,7 +64,7 @@
#define FAVORITE_MAXIMUM_RETRIES 2
#define BGSCAN_DEFAULT "simple:30:-45:300"
-#define AUTOSCAN_DEFAULT "exponential:3:300"
+#define AUTOSCAN_DEFAULT "periodic:15"
#define P2P_FIND_TIMEOUT 30
#define P2P_CONNECTION_TIMEOUT 100
@@ -83,6 +83,11 @@ enum wifi_ap_capability{
WIFI_AP_NOT_SUPPORTED = 2,
};
+enum wifi_autoscan_module{
+ WIFI_AUTOSCAN_EXPONENTIAL = 0,
+ WIFI_AUTOSCAN_PERIODIC = 1,
+};
+
struct hidden_params {
char ssid[32];
unsigned int ssid_len;
@@ -99,6 +104,7 @@ struct hidden_params {
* Should be removed when wpa_s autoscan support will be by default.
*/
struct autoscan_params {
+ enum wifi_autoscan_module module;
int base;
int limit;
int interval;
@@ -825,13 +831,14 @@ static void reset_autoscan(struct connman_device
*device)
autoscan = wifi->autoscan;
- if (autoscan->timeout == 0 && autoscan->interval == 0)
+ if (autoscan->timeout == 0)
return;
g_source_remove(autoscan->timeout);
-
autoscan->timeout = 0;
- autoscan->interval = 0;
+
+ if (autoscan->module == WIFI_AUTOSCAN_EXPONENTIAL)
+ autoscan->interval = 0;
connman_device_unref(device);
}
@@ -1346,25 +1353,30 @@ static gboolean autoscan_timeout(gpointer data)
autoscan = wifi->autoscan;
- if (autoscan->interval <= 0) {
- interval = autoscan->base;
- goto set_interval;
- } else
- interval = autoscan->interval * autoscan->base;
+ if (autoscan->module == WIFI_AUTOSCAN_EXPONENTIAL){
+ if (autoscan->interval <= 0) {
+ interval = autoscan->base;
+ goto set_interval;
+ } else
+ interval = autoscan->interval * autoscan->base;
- if (interval > autoscan->limit)
- interval = autoscan->limit;
+ if (interval > autoscan->limit)
+ interval = autoscan->limit;
- throw_wifi_scan(wifi->device, scan_callback_hidden);
+ throw_wifi_scan(wifi->device, scan_callback_hidden);
set_interval:
- DBG("interval %d", interval);
-
- autoscan->interval = interval;
-
- autoscan->timeout = g_timeout_add_seconds(interval,
- autoscan_timeout, device);
-
+ DBG("exponential interval %d", interval);
+ autoscan->interval = interval;
+ autoscan->timeout = g_timeout_add_seconds(interval,
+ autoscan_timeout,
device);
+ }
+ else if (autoscan->module == WIFI_AUTOSCAN_PERIODIC) {
+ throw_wifi_scan(wifi->device, scan_callback_hidden);
+ DBG("periodic interval %d", autoscan->interval);
+ autoscan->timeout =
g_timeout_add_seconds(autoscan->interval,
+ autoscan_timeout,
device);
+ }
return FALSE;
}
@@ -1388,7 +1400,7 @@ static void start_autoscan(struct connman_device
*device)
if (!autoscan)
return;
- if (autoscan->timeout > 0 || autoscan->interval > 0)
+ if (autoscan->timeout > 0)
return;
connman_device_ref(device);
@@ -1400,8 +1412,11 @@ static struct autoscan_params
*parse_autoscan_params(const char *params)
{
struct autoscan_params *autoscan;
char **list_params;
+ enum wifi_autoscan_module module;
int limit;
int base;
+ int interval;
+ int num_params;
DBG("Emulating autoscan");
@@ -1409,13 +1424,28 @@ static struct autoscan_params
*parse_autoscan_params(const char *params)
if (list_params == 0)
return NULL;
- if (g_strv_length(list_params) < 3) {
+ num_params = g_strv_length(list_params);
+ if (num_params < 2 || num_params > 3) {
g_strfreev(list_params);
return NULL;
}
- base = atoi(list_params[1]);
- limit = atoi(list_params[2]);
+ if (0 == g_strcmp0("exponential", list_params[0])){
+ module = WIFI_AUTOSCAN_EXPONENTIAL;
+ base = atoi(list_params[1]);
+ limit = atoi(list_params[2]);
+ interval = 0;
+ }
+ else if (0 == g_strcmp0("periodic", list_params[0])) {
+ module = WIFI_AUTOSCAN_PERIODIC;
+ base = 0;
+ limit = 0;
+ interval = atoi(list_params[1]);
+ }
+ else {
+ g_strfreev(list_params);
+ return NULL;
+ }
g_strfreev(list_params);
@@ -1425,10 +1455,13 @@ static struct autoscan_params
*parse_autoscan_params(const char *params)
return NULL;
}
- DBG("base %d - limit %d", base, limit);
+ autoscan->module = module;
autoscan->base = base;
autoscan->limit = limit;
+ autoscan->interval = interval;
+ DBG("module %s - base %d - limit %d - interval %d",
(autoscan->module == WIFI_AUTOSCAN_EXPONENTIAL) ? "exponential" :
"periodic",
+ autoscan->base, autoscan->limit,
autoscan->interval);
return autoscan;
}
With this patch, connman will be able to perform either a "periodic" or
"exponential" autoscan scheme by setting the AUTOSCAN_DEFAULT var as
"exponential:xxx:xxx" or "periodic:xxx",
exactly same way in which wpa_supplicant (autoscan) can be set on config
file. The connman version I use is 1.33.
The reason why I am sending this to you, is because I would like to know
if this feature can be implemented on connman oficial release. We really
want to contribute to the connman community.
Due to this is my fist time that I participate on this community, I hope I
did it in a correct way.
Best Regards.
Raúl Camacho
Software Developer