hostapd/wpa_supplicant/bgscan_simple.c
Jouni Malinen 60b94c9819 Add preliminary background scan and roaming module design
This allows background scanning and roaming decisions to be contained in
a single place based on a defined set of notification events which will
hopefully make it easier to experiment with roaming improvements. In
addition, this allows multiple intra-ESS roaming policies to be used
(each network configuration block can configure its own bgscan module).

The beacon loss and signal strength notifications are implemented for
the bgscan API, but the actual events are not yet available from the
driver.

The included sample bgscan module ("simple") is an example of what can
be done with the new bgscan mechanism. It requests periodic background
scans when the device remains associated with an ESS and has couple of
notes on what a more advanced bgscan module could do to optimize
background scanning and roaming. The periodic scans will cause the scan
result handler to pick a better AP if one becomes available. This bgscan
module can be taken into use by adding bgscan="simple" (or
bgscan="simple:<bgscan interval in seconds>") into the network
configuration block.
2009-09-15 00:08:24 +03:00

130 lines
3.4 KiB
C

/*
* WPA Supplicant - background scan and roaming module: simple
* Copyright (c) 2009, Jouni Malinen <j@w1.fi>
*
* 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 "eloop.h"
#include "drivers/driver.h"
#include "config_ssid.h"
#include "wpa_supplicant_i.h"
#include "bgscan.h"
struct bgscan_simple_data {
struct wpa_supplicant *wpa_s;
const struct wpa_ssid *ssid;
int scan_interval;
};
static void bgscan_simple_timeout(void *eloop_ctx, void *timeout_ctx)
{
struct bgscan_simple_data *data = eloop_ctx;
struct wpa_supplicant *wpa_s = data->wpa_s;
struct wpa_driver_scan_params params;
os_memset(&params, 0, sizeof(params));
params.num_ssids = 1;
params.ssids[0].ssid = data->ssid->ssid;
params.ssids[0].ssid_len = data->ssid->ssid_len;
params.freqs = data->ssid->scan_freq;
/*
* A more advanced bgscan module would learn about most like channels
* over time and request scans only for some channels (probing others
* every now and then) to reduce effect on the data connection.
*/
wpa_printf(MSG_DEBUG, "bgscan simple: Request a background scan");
if (wpa_supplicant_trigger_scan(wpa_s, &params)) {
wpa_printf(MSG_DEBUG, "bgscan simple: Failed to trigger scan");
eloop_register_timeout(data->scan_interval, 0,
bgscan_simple_timeout, data, NULL);
}
}
static void * bgscan_simple_init(struct wpa_supplicant *wpa_s,
const char *params,
const struct wpa_ssid *ssid)
{
struct bgscan_simple_data *data;
data = os_zalloc(sizeof(*data));
if (data == NULL)
return NULL;
data->wpa_s = wpa_s;
data->ssid = ssid;
if (params)
data->scan_interval = atoi(params);
if (data->scan_interval <= 0)
data->scan_interval = 30;
eloop_register_timeout(data->scan_interval, 0, bgscan_simple_timeout,
data, NULL);
return data;
}
static void bgscan_simple_deinit(void *priv)
{
struct bgscan_simple_data *data = priv;
eloop_cancel_timeout(bgscan_simple_timeout, data, NULL);
os_free(data);
}
static int bgscan_simple_notify_scan(void *priv)
{
struct bgscan_simple_data *data = priv;
wpa_printf(MSG_DEBUG, "bgscan simple: scan result notification");
eloop_cancel_timeout(bgscan_simple_timeout, data, NULL);
eloop_register_timeout(data->scan_interval, 0, bgscan_simple_timeout,
data, NULL);
/*
* A more advanced bgscan could process scan results internally, select
* the BSS and request roam if needed. This sample uses the existing
* BSS/ESS selection routine. Change this to return 1 if selection is
* done inside the bgscan module.
*/
return 0;
}
static void bgscan_simple_notify_beacon_loss(void *priv)
{
wpa_printf(MSG_DEBUG, "bgscan simple: beacon loss");
/* TODO: speed up background scanning */
}
static void bgscan_simple_notify_signal_change(void *priv)
{
wpa_printf(MSG_DEBUG, "bgscan simple: signal level changed");
/* TODO: if signal strength dropped enough, speed up background
* scanning */
}
const struct bgscan_ops bgscan_simple_ops = {
.name = "simple",
.init = bgscan_simple_init,
.deinit = bgscan_simple_deinit,
.notify_scan = bgscan_simple_notify_scan,
.notify_beacon_loss = bgscan_simple_notify_beacon_loss,
.notify_signal_change = bgscan_simple_notify_signal_change,
};