2 * WPA Supplicant - background scan and roaming module: simple
3 * Copyright (c) 2009, Jouni Malinen <j@w1.fi>
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.
9 * Alternatively, this software may be distributed under the terms of BSD
12 * See README and COPYING for more details.
19 #include "drivers/driver.h"
20 #include "config_ssid.h"
21 #include "wpa_supplicant_i.h"
24 struct bgscan_simple_data
{
25 struct wpa_supplicant
*wpa_s
;
26 const struct wpa_ssid
*ssid
;
31 static void bgscan_simple_timeout(void *eloop_ctx
, void *timeout_ctx
)
33 struct bgscan_simple_data
*data
= eloop_ctx
;
34 struct wpa_supplicant
*wpa_s
= data
->wpa_s
;
35 struct wpa_driver_scan_params params
;
37 os_memset(¶ms
, 0, sizeof(params
));
39 params
.ssids
[0].ssid
= data
->ssid
->ssid
;
40 params
.ssids
[0].ssid_len
= data
->ssid
->ssid_len
;
41 params
.freqs
= data
->ssid
->scan_freq
;
44 * A more advanced bgscan module would learn about most like channels
45 * over time and request scans only for some channels (probing others
46 * every now and then) to reduce effect on the data connection.
49 wpa_printf(MSG_DEBUG
, "bgscan simple: Request a background scan");
50 if (wpa_supplicant_trigger_scan(wpa_s
, ¶ms
)) {
51 wpa_printf(MSG_DEBUG
, "bgscan simple: Failed to trigger scan");
52 eloop_register_timeout(data
->scan_interval
, 0,
53 bgscan_simple_timeout
, data
, NULL
);
58 static void * bgscan_simple_init(struct wpa_supplicant
*wpa_s
,
60 const struct wpa_ssid
*ssid
)
62 struct bgscan_simple_data
*data
;
64 data
= os_zalloc(sizeof(*data
));
70 data
->scan_interval
= atoi(params
);
71 if (data
->scan_interval
<= 0)
72 data
->scan_interval
= 30;
73 eloop_register_timeout(data
->scan_interval
, 0, bgscan_simple_timeout
,
79 static void bgscan_simple_deinit(void *priv
)
81 struct bgscan_simple_data
*data
= priv
;
82 eloop_cancel_timeout(bgscan_simple_timeout
, data
, NULL
);
87 static int bgscan_simple_notify_scan(void *priv
)
89 struct bgscan_simple_data
*data
= priv
;
91 wpa_printf(MSG_DEBUG
, "bgscan simple: scan result notification");
93 eloop_cancel_timeout(bgscan_simple_timeout
, data
, NULL
);
94 eloop_register_timeout(data
->scan_interval
, 0, bgscan_simple_timeout
,
98 * A more advanced bgscan could process scan results internally, select
99 * the BSS and request roam if needed. This sample uses the existing
100 * BSS/ESS selection routine. Change this to return 1 if selection is
101 * done inside the bgscan module.
108 static void bgscan_simple_notify_beacon_loss(void *priv
)
110 wpa_printf(MSG_DEBUG
, "bgscan simple: beacon loss");
111 /* TODO: speed up background scanning */
115 static void bgscan_simple_notify_signal_change(void *priv
)
117 wpa_printf(MSG_DEBUG
, "bgscan simple: signal level changed");
118 /* TODO: if signal strength dropped enough, speed up background
123 const struct bgscan_ops bgscan_simple_ops
= {
125 .init
= bgscan_simple_init
,
126 .deinit
= bgscan_simple_deinit
,
127 .notify_scan
= bgscan_simple_notify_scan
,
128 .notify_beacon_loss
= bgscan_simple_notify_beacon_loss
,
129 .notify_signal_change
= bgscan_simple_notify_signal_change
,