Patchwork [6/7] Adding autoscan module named exponential

login
register
mail settings
Submitter Tomasz Bursztyka
Date May 3, 2012, 1:16 p.m.
Message ID <1336051016-15005-7-git-send-email-tomasz.bursztyka@linux.intel.com>
Download mbox | patch
Permalink /patch/156697/
State Changes Requested
Headers show

Comments

Tomasz Bursztyka - May 3, 2012, 1:16 p.m.
This module will compute the interval on a base exponential.
Thus, params to this module are following this format: <base>:<limit>

Signed-hostap: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
---
 wpa_supplicant/Makefile               |    6 ++
 wpa_supplicant/autoscan.c             |    7 ++
 wpa_supplicant/autoscan_exponential.c |  105 +++++++++++++++++++++++++++++++++
 3 files changed, 118 insertions(+), 0 deletions(-)
 create mode 100644 wpa_supplicant/autoscan_exponential.c
Jouni Malinen - June 24, 2012, 10:07 a.m.
On Thu, May 03, 2012 at 04:16:55PM +0300, Tomasz Bursztyka wrote:
> This module will compute the interval on a base exponential.
> Thus, params to this module are following this format: <base>:<limit>

>  wpa_supplicant/Makefile               |    6 ++
>  wpa_supplicant/autoscan.c             |    7 ++
>  wpa_supplicant/autoscan_exponential.c |  105 +++++++++++++++++++++++++++++++++

It would be nice to get this (and same for 'periodic') documented in
wpa_supplicant/wpa_supplicant.conf with a reasonable example value
included there. The patch 1/7 could have added the documented from
config.h into wpa_supplicant.conf, too, and then these 6/7 and 7/7 could
extend that description.

> diff --git a/wpa_supplicant/Makefile b/wpa_supplicant/Makefile
> @@ -1311,6 +1311,12 @@ CFLAGS += -DCONFIG_BGSCAN
> +ifdef CONFIG_AUTOSCAN_EXPONENTIAL
> +CFLAGS += -DCONFIG_AUTOSCAN_EXPONENTIAL
> +OBJS += autoscan_exponential.o
> +NEED_AUTOSCAN=y
> +endif

Do you think we will get many more (or much larger) autoscan modules in
the future? If no, do we really need to make this configurable at build
time? I guess the autoscan.c itself could have enough size to justify
the extra complexity. Anyway, the added build configuration parameters
should be added to wpa_supplicant/defconfig.

Patch

diff --git a/wpa_supplicant/Makefile b/wpa_supplicant/Makefile
index d281ddb..859db6b 100644
--- a/wpa_supplicant/Makefile
+++ b/wpa_supplicant/Makefile
@@ -1311,6 +1311,12 @@  CFLAGS += -DCONFIG_BGSCAN
 OBJS += bgscan.o
 endif
 
+ifdef CONFIG_AUTOSCAN_EXPONENTIAL
+CFLAGS += -DCONFIG_AUTOSCAN_EXPONENTIAL
+OBJS += autoscan_exponential.o
+NEED_AUTOSCAN=y
+endif
+
 ifdef NEED_AUTOSCAN
 CFLAGS += -DCONFIG_AUTOSCAN
 OBJS += autoscan.o
diff --git a/wpa_supplicant/autoscan.c b/wpa_supplicant/autoscan.c
index a586f41..d2645bc 100644
--- a/wpa_supplicant/autoscan.c
+++ b/wpa_supplicant/autoscan.c
@@ -20,7 +20,14 @@ 
 #include "scan.h"
 #include "autoscan.h"
 
+#ifdef CONFIG_AUTOSCAN_EXPONENTIAL
+extern const struct autoscan_ops autoscan_exponential_ops;
+#endif /* CONFIG_AUTOSCAN_EXPONENTIAL */
+
 static const struct autoscan_ops * autoscan_modules[] = {
+#ifdef CONFIG_AUTOSCAN_EXPONENTIAL
+	&autoscan_exponential_ops,
+#endif /* CONFIG_AUTOSCAN_EXPONENTIAL */
 	NULL
 };
 
diff --git a/wpa_supplicant/autoscan_exponential.c b/wpa_supplicant/autoscan_exponential.c
new file mode 100644
index 0000000..f0c4a81
--- /dev/null
+++ b/wpa_supplicant/autoscan_exponential.c
@@ -0,0 +1,105 @@ 
+/*
+ * WPA Supplicant - auto scan exponential module
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * Alternatively, this software may be distributed under the terms of BSD
+ * license.
+ *
+ * See README and COPYING for more details.
+ */
+
+#include "includes.h"
+
+#include "common.h"
+#include "wpa_supplicant_i.h"
+#include "autoscan.h"
+
+struct autoscan_exponential_data {
+	struct wpa_supplicant *wpa_s;
+	int base;
+	int limit;
+	int interval;
+};
+
+
+static int autoscan_exponential_get_params(struct autoscan_exponential_data *data,
+					   const char *params)
+{
+	const char *pos;
+
+	if (params == NULL)
+		return -1;
+
+	data->base = atoi(params);
+
+	pos = os_strchr(params, ':');
+	if (pos == NULL)
+		return -1;
+
+	pos++;
+	data->limit = atoi(pos);
+
+	return 0;
+}
+
+
+static void * autoscan_exponential_init(struct wpa_supplicant *wpa_s,
+					const char *params)
+{
+	struct autoscan_exponential_data *data;
+
+	data = os_zalloc(sizeof(struct autoscan_exponential_data));
+	if (data == NULL)
+		return NULL;
+
+	if (autoscan_exponential_get_params(data, params) < 0) {
+		os_free(data);
+		return NULL;
+	}
+
+	wpa_printf(MSG_DEBUG, "autoscan exponential: base exponential is %d "
+		   "and limit is %d", data->base, data->limit);
+
+	data->wpa_s = wpa_s;
+
+	return data;
+}
+
+
+static void autoscan_exponential_deinit(void *priv)
+{
+	struct autoscan_exponential_data *data = priv;
+
+	os_free(data);
+}
+
+
+static int autoscan_exponential_notify_scan(void *priv,
+					    struct wpa_scan_results *scan_res)
+{
+	struct autoscan_exponential_data *data = priv;
+
+	wpa_printf(MSG_DEBUG, "autoscan exponential: scan result notification");
+
+	if (data->interval >= data->limit)
+		return data->limit;
+
+	if (data->interval <= 0)
+		data->interval = data->base;
+
+	data->interval = data->interval * data->base;
+
+	return data->interval;
+
+}
+
+
+const struct autoscan_ops autoscan_exponential_ops = {
+	.name = "exponential",
+	.init = autoscan_exponential_init,
+	.deinit = autoscan_exponential_deinit,
+	.notify_scan = autoscan_exponential_notify_scan,
+};