]> git.ipfire.org Git - thirdparty/hostap.git/blob - wpa_supplicant/bgscan.c
bgscan: Add signal strength change events
[thirdparty/hostap.git] / wpa_supplicant / bgscan.c
1 /*
2 * WPA Supplicant - background scan and roaming interface
3 * Copyright (c) 2009-2010, Jouni Malinen <j@w1.fi>
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 2 as
7 * published by the Free Software Foundation.
8 *
9 * Alternatively, this software may be distributed under the terms of BSD
10 * license.
11 *
12 * See README and COPYING for more details.
13 */
14
15 #include "includes.h"
16
17 #include "common.h"
18 #include "wpa_supplicant_i.h"
19 #include "config_ssid.h"
20 #include "bgscan.h"
21
22 #ifdef CONFIG_BGSCAN_SIMPLE
23 extern const struct bgscan_ops bgscan_simple_ops;
24 #endif /* CONFIG_BGSCAN_SIMPLE */
25
26 static const struct bgscan_ops * bgscan_modules[] = {
27 #ifdef CONFIG_BGSCAN_SIMPLE
28 &bgscan_simple_ops,
29 #endif /* CONFIG_BGSCAN_SIMPLE */
30 NULL
31 };
32
33
34 int bgscan_init(struct wpa_supplicant *wpa_s, struct wpa_ssid *ssid)
35 {
36 const char *name = ssid->bgscan;
37 const char *params;
38 size_t nlen;
39 int i;
40 const struct bgscan_ops *ops = NULL;
41
42 bgscan_deinit(wpa_s);
43 if (name == NULL)
44 return 0;
45
46 params = os_strchr(name, ':');
47 if (params == NULL) {
48 params = "";
49 nlen = os_strlen(name);
50 } else {
51 nlen = params - name;
52 params++;
53 }
54
55 for (i = 0; bgscan_modules[i]; i++) {
56 if (os_strncmp(name, bgscan_modules[i]->name, nlen) == 0) {
57 ops = bgscan_modules[i];
58 break;
59 }
60 }
61
62 if (ops == NULL) {
63 wpa_printf(MSG_ERROR, "bgscan: Could not find module "
64 "matching the parameter '%s'", name);
65 return -1;
66 }
67
68 wpa_s->bgscan_priv = ops->init(wpa_s, params, ssid);
69 if (wpa_s->bgscan_priv == NULL)
70 return -1;
71 wpa_s->bgscan = ops;
72 wpa_printf(MSG_DEBUG, "bgscan: Initialized module '%s' with "
73 "parameters '%s'", ops->name, params);
74
75 return 0;
76 }
77
78
79 void bgscan_deinit(struct wpa_supplicant *wpa_s)
80 {
81 if (wpa_s->bgscan && wpa_s->bgscan_priv) {
82 wpa_printf(MSG_DEBUG, "bgscan: Deinitializing module '%s'",
83 wpa_s->bgscan->name);
84 wpa_s->bgscan->deinit(wpa_s->bgscan_priv);
85 wpa_s->bgscan = NULL;
86 wpa_s->bgscan_priv = NULL;
87 }
88 }
89
90
91 int bgscan_notify_scan(struct wpa_supplicant *wpa_s)
92 {
93 if (wpa_s->bgscan && wpa_s->bgscan_priv)
94 return wpa_s->bgscan->notify_scan(wpa_s->bgscan_priv);
95 return 0;
96 }
97
98
99 void bgscan_notify_beacon_loss(struct wpa_supplicant *wpa_s)
100 {
101 if (wpa_s->bgscan && wpa_s->bgscan_priv)
102 wpa_s->bgscan->notify_beacon_loss(wpa_s->bgscan_priv);
103 }
104
105
106 void bgscan_notify_signal_change(struct wpa_supplicant *wpa_s, int above)
107 {
108 if (wpa_s->bgscan && wpa_s->bgscan_priv)
109 wpa_s->bgscan->notify_signal_change(wpa_s->bgscan_priv, above);
110 }