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