$search
00001 /* 00002 * WPA Supplicant - background scan and roaming interface 00003 * Copyright (c) 2009-2010, Jouni Malinen <j@w1.fi> 00004 * 00005 * This program is free software; you can redistribute it and/or modify 00006 * it under the terms of the GNU General Public License version 2 as 00007 * published by the Free Software Foundation. 00008 * 00009 * Alternatively, this software may be distributed under the terms of BSD 00010 * license. 00011 * 00012 * See README and COPYING for more details. 00013 */ 00014 00015 #include "includes.h" 00016 00017 #include "common.h" 00018 #include "wpa_supplicant_i.h" 00019 #include "config_ssid.h" 00020 #include "bgscan.h" 00021 00022 #ifdef CONFIG_BGSCAN_SIMPLE 00023 extern const struct bgscan_ops bgscan_simple_ops; 00024 #endif /* CONFIG_BGSCAN_SIMPLE */ 00025 00026 static const struct bgscan_ops * bgscan_modules[] = { 00027 #ifdef CONFIG_BGSCAN_SIMPLE 00028 &bgscan_simple_ops, 00029 #endif /* CONFIG_BGSCAN_SIMPLE */ 00030 NULL 00031 }; 00032 00033 00034 int bgscan_init(struct wpa_supplicant *wpa_s, struct wpa_ssid *ssid) 00035 { 00036 const char *name = ssid->bgscan; 00037 const char *params; 00038 size_t nlen; 00039 int i; 00040 const struct bgscan_ops *ops = NULL; 00041 00042 bgscan_deinit(wpa_s); 00043 if (name == NULL) 00044 return 0; 00045 00046 params = os_strchr(name, ':'); 00047 if (params == NULL) { 00048 params = ""; 00049 nlen = os_strlen(name); 00050 } else { 00051 nlen = params - name; 00052 params++; 00053 } 00054 00055 for (i = 0; bgscan_modules[i]; i++) { 00056 if (os_strncmp(name, bgscan_modules[i]->name, nlen) == 0) { 00057 ops = bgscan_modules[i]; 00058 break; 00059 } 00060 } 00061 00062 if (ops == NULL) { 00063 wpa_printf(MSG_ERROR, "bgscan: Could not find module " 00064 "matching the parameter '%s'", name); 00065 return -1; 00066 } 00067 00068 wpa_s->bgscan_priv = ops->init(wpa_s, params, ssid); 00069 if (wpa_s->bgscan_priv == NULL) 00070 return -1; 00071 wpa_s->bgscan = ops; 00072 wpa_printf(MSG_DEBUG, "bgscan: Initialized module '%s' with " 00073 "parameters '%s'", ops->name, params); 00074 00075 return 0; 00076 } 00077 00078 00079 void bgscan_deinit(struct wpa_supplicant *wpa_s) 00080 { 00081 if (wpa_s->bgscan && wpa_s->bgscan_priv) { 00082 wpa_printf(MSG_DEBUG, "bgscan: Deinitializing module '%s'", 00083 wpa_s->bgscan->name); 00084 wpa_s->bgscan->deinit(wpa_s->bgscan_priv); 00085 wpa_s->bgscan = NULL; 00086 wpa_s->bgscan_priv = NULL; 00087 } 00088 } 00089 00090 00091 int bgscan_notify_scan(struct wpa_supplicant *wpa_s) 00092 { 00093 if (wpa_s->bgscan && wpa_s->bgscan_priv) 00094 return wpa_s->bgscan->notify_scan(wpa_s->bgscan_priv); 00095 return 0; 00096 } 00097 00098 00099 void bgscan_notify_beacon_loss(struct wpa_supplicant *wpa_s) 00100 { 00101 if (wpa_s->bgscan && wpa_s->bgscan_priv) 00102 wpa_s->bgscan->notify_beacon_loss(wpa_s->bgscan_priv); 00103 } 00104 00105 00106 void bgscan_notify_signal_change(struct wpa_supplicant *wpa_s, int above) 00107 { 00108 if (wpa_s->bgscan && wpa_s->bgscan_priv) 00109 wpa_s->bgscan->notify_signal_change(wpa_s->bgscan_priv, above); 00110 }