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