aboutsummaryrefslogtreecommitdiffstats
path: root/wpa_supplicant/bgscan_learn.c
diff options
context:
space:
mode:
authorJouni Malinen <j@w1.fi>2010-07-10 23:05:31 (GMT)
committerJouni Malinen <j@w1.fi>2010-07-10 23:05:31 (GMT)
commit2e8d6ae32e15a78ac8952158671d18959b69630b (patch)
tree2b661280cf8a8a02dfbc8d86e797669bde55f1f9 /wpa_supplicant/bgscan_learn.c
parentc4d71c25057465e18941b57765b45f5626b9e314 (diff)
downloadhostap-2e8d6ae32e15a78ac8952158671d18959b69630b.zip
hostap-2e8d6ae32e15a78ac8952158671d18959b69630b.tar.gz
hostap-2e8d6ae32e15a78ac8952158671d18959b69630b.tar.bz2
bgscan learn: Add data file for storing learned network information
Diffstat (limited to 'wpa_supplicant/bgscan_learn.c')
-rw-r--r--wpa_supplicant/bgscan_learn.c62
1 files changed, 62 insertions, 0 deletions
diff --git a/wpa_supplicant/bgscan_learn.c b/wpa_supplicant/bgscan_learn.c
index 1244856..91ac80d 100644
--- a/wpa_supplicant/bgscan_learn.c
+++ b/wpa_supplicant/bgscan_learn.c
@@ -31,9 +31,57 @@ struct bgscan_learn_data {
int short_interval; /* use if signal < threshold */
int long_interval; /* use if signal > threshold */
struct os_time last_bgscan;
+ char *fname;
};
+static int bgscan_learn_load(struct bgscan_learn_data *data)
+{
+ FILE *f;
+ char buf[128];
+
+ if (data->fname == NULL)
+ return 0;
+
+ f = fopen(data->fname, "r");
+ if (f == NULL)
+ return 0;
+
+ wpa_printf(MSG_DEBUG, "bgscan learn: Loading data from %s",
+ data->fname);
+
+ if (fgets(buf, sizeof(buf), f) == NULL ||
+ os_strncmp(buf, "wpa_supplicant-bgscan-learn\n", 28) != 0) {
+ wpa_printf(MSG_INFO, "bgscan learn: Invalid data file %s",
+ data->fname);
+ fclose(f);
+ return -1;
+ }
+
+ fclose(f);
+ return 0;
+}
+
+
+static void bgscan_learn_save(struct bgscan_learn_data *data)
+{
+ FILE *f;
+
+ if (data->fname == NULL)
+ return;
+
+ wpa_printf(MSG_DEBUG, "bgscan learn: Saving data to %s",
+ data->fname);
+
+ f = fopen(data->fname, "w");
+ if (f == NULL)
+ return;
+ fprintf(f, "wpa_supplicant-bgscan-learn\n");
+
+ fclose(f);
+}
+
+
static void bgscan_learn_timeout(void *eloop_ctx, void *timeout_ctx)
{
struct bgscan_learn_data *data = eloop_ctx;
@@ -85,6 +133,11 @@ static int bgscan_learn_get_params(struct bgscan_learn_data *data,
}
pos++;
data->long_interval = atoi(pos);
+ pos = os_strchr(pos, ':');
+ if (pos) {
+ pos++;
+ data->fname = os_strdup(pos);
+ }
return 0;
}
@@ -102,6 +155,7 @@ static void * bgscan_learn_init(struct wpa_supplicant *wpa_s,
data->wpa_s = wpa_s;
data->ssid = ssid;
if (bgscan_learn_get_params(data, params) < 0) {
+ os_free(data->fname);
os_free(data);
return NULL;
}
@@ -110,6 +164,12 @@ static void * bgscan_learn_init(struct wpa_supplicant *wpa_s,
if (data->long_interval <= 0)
data->long_interval = 30;
+ if (bgscan_learn_load(data) < 0) {
+ os_free(data->fname);
+ os_free(data);
+ return NULL;
+ }
+
wpa_printf(MSG_DEBUG, "bgscan learn: Signal strength threshold %d "
"Short bgscan interval %d Long bgscan interval %d",
data->signal_threshold, data->short_interval,
@@ -131,9 +191,11 @@ static void * bgscan_learn_init(struct wpa_supplicant *wpa_s,
static void bgscan_learn_deinit(void *priv)
{
struct bgscan_learn_data *data = priv;
+ bgscan_learn_save(data);
eloop_cancel_timeout(bgscan_learn_timeout, data, NULL);
if (data->signal_threshold)
wpa_drv_signal_monitor(data->wpa_s, 0, 0);
+ os_free(data->fname);
os_free(data);
}