blob: 56618308009b78650e39d816cfbf506e9967b88d [file] [log] [blame]
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001/*
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
23extern const struct bgscan_ops bgscan_simple_ops;
24#endif /* CONFIG_BGSCAN_SIMPLE */
25#ifdef CONFIG_BGSCAN_LEARN
26extern const struct bgscan_ops bgscan_learn_ops;
27#endif /* CONFIG_BGSCAN_LEARN */
28
29static const struct bgscan_ops * bgscan_modules[] = {
30#ifdef CONFIG_BGSCAN_SIMPLE
31 &bgscan_simple_ops,
32#endif /* CONFIG_BGSCAN_SIMPLE */
33#ifdef CONFIG_BGSCAN_LEARN
34 &bgscan_learn_ops,
35#endif /* CONFIG_BGSCAN_LEARN */
36 NULL
37};
38
39
40int bgscan_init(struct wpa_supplicant *wpa_s, struct wpa_ssid *ssid)
41{
42 const char *name = ssid->bgscan;
43 const char *params;
44 size_t nlen;
45 int i;
46 const struct bgscan_ops *ops = NULL;
47
48 bgscan_deinit(wpa_s);
49 if (name == NULL)
50 return 0;
51
52 params = os_strchr(name, ':');
53 if (params == NULL) {
54 params = "";
55 nlen = os_strlen(name);
56 } else {
57 nlen = params - name;
58 params++;
59 }
60
61 for (i = 0; bgscan_modules[i]; i++) {
62 if (os_strncmp(name, bgscan_modules[i]->name, nlen) == 0) {
63 ops = bgscan_modules[i];
64 break;
65 }
66 }
67
68 if (ops == NULL) {
69 wpa_printf(MSG_ERROR, "bgscan: Could not find module "
70 "matching the parameter '%s'", name);
71 return -1;
72 }
73
74 wpa_s->bgscan_priv = ops->init(wpa_s, params, ssid);
75 if (wpa_s->bgscan_priv == NULL)
76 return -1;
77 wpa_s->bgscan = ops;
78 wpa_printf(MSG_DEBUG, "bgscan: Initialized module '%s' with "
79 "parameters '%s'", ops->name, params);
80
81 return 0;
82}
83
84
85void bgscan_deinit(struct wpa_supplicant *wpa_s)
86{
87 if (wpa_s->bgscan && wpa_s->bgscan_priv) {
88 wpa_printf(MSG_DEBUG, "bgscan: Deinitializing module '%s'",
89 wpa_s->bgscan->name);
90 wpa_s->bgscan->deinit(wpa_s->bgscan_priv);
91 wpa_s->bgscan = NULL;
92 wpa_s->bgscan_priv = NULL;
93 }
94}
95
96
97int bgscan_notify_scan(struct wpa_supplicant *wpa_s,
98 struct wpa_scan_results *scan_res)
99{
100 if (wpa_s->bgscan && wpa_s->bgscan_priv)
101 return wpa_s->bgscan->notify_scan(wpa_s->bgscan_priv,
102 scan_res);
103 return 0;
104}
105
106
107void bgscan_notify_beacon_loss(struct wpa_supplicant *wpa_s)
108{
109 if (wpa_s->bgscan && wpa_s->bgscan_priv)
110 wpa_s->bgscan->notify_beacon_loss(wpa_s->bgscan_priv);
111}
112
113
114void bgscan_notify_signal_change(struct wpa_supplicant *wpa_s, int above,
115 int current_signal, int current_noise,
116 int current_txrate)
117{
118 if (wpa_s->bgscan && wpa_s->bgscan_priv)
119 wpa_s->bgscan->notify_signal_change(wpa_s->bgscan_priv, above,
120 current_signal,
121 current_noise,
122 current_txrate);
123}