summaryrefslogtreecommitdiff
path: root/plugins
diff options
context:
space:
mode:
authorJukka Rissanen <jukka.rissanen@linux.intel.com>2012-08-21 10:38:04 (GMT)
committerPatrik Flykt <patrik.flykt@linux.intel.com>2012-08-23 11:19:14 (GMT)
commit3a8be9689f01e359a3325b1a9afbfb653883aed1 (patch)
tree20f6837405f9b5bd65ef0b1331b34f7e181619e1 /plugins
parent7e151a7520740b586fe4f2adad1aa21864ef5321 (diff)
downloadconnman-3a8be9689f01e359a3325b1a9afbfb653883aed1.zip
connman-3a8be9689f01e359a3325b1a9afbfb653883aed1.tar.gz
connman-3a8be9689f01e359a3325b1a9afbfb653883aed1.tar.bz2
device: Refactor device scan function
In wifi plugin this means that we combine three wifi scan functions (normal, fast, hidden) into one scan function.
Diffstat (limited to 'plugins')
-rw-r--r--plugins/iwmx.c5
-rw-r--r--plugins/wifi.c144
2 files changed, 65 insertions, 84 deletions
diff --git a/plugins/iwmx.c b/plugins/iwmx.c
index 7c1e792..c936706 100644
--- a/plugins/iwmx.c
+++ b/plugins/iwmx.c
@@ -534,7 +534,10 @@ static void iwmx_cm_remove(struct connman_device *dev)
* First we obtain the current list of networks and pass it to the
* callback processor. Then we start an scan cycle.
*/
-static int iwmx_cm_scan(struct connman_device *dev)
+static int iwmx_cm_scan(struct connman_device *dev,
+ const char *ssid, unsigned int ssid_len,
+ const char *identity, const char* passphrase,
+ void *user_data)
{
struct wmxsdk *wmxsdk = connman_device_get_data(dev);
return iwmx_sdk_scan(wmxsdk);
diff --git a/plugins/wifi.c b/plugins/wifi.c
index 409c060..eec1cfb 100644
--- a/plugins/wifi.c
+++ b/plugins/wifi.c
@@ -902,24 +902,34 @@ static int get_latest_connections(int max_ssids,
return num_ssids;
}
-static int wifi_scan(struct connman_device *device)
+static int wifi_scan_simple(struct connman_device *device)
{
reset_autoscan(device);
return throw_wifi_scan(device, scan_callback_hidden);
}
-static int wifi_scan_fast(struct connman_device *device)
+/*
+ * Note that the hidden scan is only used when connecting to this specific
+ * hidden AP first time. It is not used when system autoconnects to hidden AP.
+ */
+static int wifi_scan(struct connman_device *device,
+ const char *ssid, unsigned int ssid_len,
+ const char *identity, const char* passphrase,
+ gpointer user_data)
{
struct wifi_data *wifi = connman_device_get_data(device);
GSupplicantScanParams *scan_params = NULL;
+ struct scan_ssid *scan_ssid;
+ struct hidden_params *hidden;
int ret;
int driver_max_ssids = 0;
+ connman_bool_t do_hidden;
if (wifi == NULL)
return -ENODEV;
- DBG("device %p %p", device, wifi->interface);
+ DBG("device %p wifi %p hidden ssid %s", device, wifi->interface, ssid);
if (wifi->tethering == TRUE)
return 0;
@@ -927,107 +937,77 @@ static int wifi_scan_fast(struct connman_device *device)
if (connman_device_get_scanning(device) == TRUE)
return -EALREADY;
- driver_max_ssids = g_supplicant_interface_get_max_scan_ssids(
- wifi->interface);
- DBG("max ssids %d", driver_max_ssids);
- if (driver_max_ssids == 0)
- return wifi_scan(device);
-
- scan_params = g_try_malloc0(sizeof(GSupplicantScanParams));
- if (scan_params == NULL)
- return -ENOMEM;
+ if (ssid == NULL || ssid_len == 0 || ssid_len > 32) {
+ do_hidden = FALSE;
+ } else {
+ if (wifi->hidden != NULL)
+ return -EBUSY;
- ret = get_latest_connections(driver_max_ssids, scan_params);
- if (ret <= 0) {
- g_supplicant_free_scan_params(scan_params);
- return wifi_scan(device);
+ do_hidden = TRUE;
}
- connman_device_ref(device);
- reset_autoscan(device);
-
- ret = g_supplicant_interface_scan(wifi->interface, scan_params,
- scan_callback, device);
- if (ret == 0)
- connman_device_set_scanning(device, TRUE);
- else {
- g_supplicant_free_scan_params(scan_params);
- connman_device_unref(device);
+ if (do_hidden == FALSE) {
+ driver_max_ssids = g_supplicant_interface_get_max_scan_ssids(
+ wifi->interface);
+ DBG("max ssids %d", driver_max_ssids);
+ if (driver_max_ssids == 0)
+ return wifi_scan_simple(device);
}
- return ret;
-}
-
-/*
- * This func is only used when connecting to this specific AP first time.
- * It is not used when system autoconnects to hidden AP.
- */
-static int wifi_scan_hidden(struct connman_device *device,
- const char *ssid, unsigned int ssid_len,
- const char *identity, const char* passphrase,
- gpointer user_data)
-{
- struct wifi_data *wifi = connman_device_get_data(device);
- GSupplicantScanParams *scan_params = NULL;
- struct scan_ssid *scan_ssid;
- struct hidden_params *hidden;
- int ret;
-
- if (wifi == NULL)
- return -ENODEV;
-
- DBG("hidden SSID %s", ssid);
-
- if (wifi->tethering == TRUE || wifi->hidden != NULL)
- return -EBUSY;
-
- if (ssid == NULL || ssid_len == 0 || ssid_len > 32)
- return -EINVAL;
-
- if (connman_device_get_scanning(device) == TRUE)
- return -EALREADY;
-
scan_params = g_try_malloc0(sizeof(GSupplicantScanParams));
if (scan_params == NULL)
return -ENOMEM;
- scan_ssid = g_try_new(struct scan_ssid, 1);
- if (scan_ssid == NULL) {
- g_free(scan_params);
- return -ENOMEM;
- }
+ if (do_hidden == TRUE) {
+ scan_ssid = g_try_new(struct scan_ssid, 1);
+ if (scan_ssid == NULL) {
+ g_free(scan_params);
+ return -ENOMEM;
+ }
+
+ memcpy(scan_ssid->ssid, ssid, ssid_len);
+ scan_ssid->ssid_len = ssid_len;
+ scan_params->ssids = g_slist_prepend(scan_params->ssids,
+ scan_ssid);
+ scan_params->num_ssids = 1;
- memcpy(scan_ssid->ssid, ssid, ssid_len);
- scan_ssid->ssid_len = ssid_len;
- scan_params->ssids = g_slist_prepend(scan_params->ssids, scan_ssid);
+ hidden = g_try_new0(struct hidden_params, 1);
+ if (hidden == NULL) {
+ g_free(scan_params);
+ return -ENOMEM;
+ }
- scan_params->num_ssids = 1;
+ memcpy(hidden->ssid, ssid, ssid_len);
+ hidden->ssid_len = ssid_len;
+ hidden->identity = g_strdup(identity);
+ hidden->passphrase = g_strdup(passphrase);
+ hidden->user_data = user_data;
+ wifi->hidden = hidden;
- hidden = g_try_new0(struct hidden_params, 1);
- if (hidden == NULL) {
- g_free(scan_params);
- return -ENOMEM;
+ } else {
+ ret = get_latest_connections(driver_max_ssids, scan_params);
+ if (ret <= 0) {
+ g_supplicant_free_scan_params(scan_params);
+ return wifi_scan_simple(device);
+ }
}
- memcpy(hidden->ssid, ssid, ssid_len);
- hidden->ssid_len = ssid_len;
- hidden->identity = g_strdup(identity);
- hidden->passphrase = g_strdup(passphrase);
- hidden->user_data = user_data;
- wifi->hidden = hidden;
connman_device_ref(device);
reset_autoscan(device);
ret = g_supplicant_interface_scan(wifi->interface, scan_params,
- scan_callback, device);
+ scan_callback, device);
if (ret == 0)
connman_device_set_scanning(device, TRUE);
else {
- connman_device_unref(device);
g_supplicant_free_scan_params(scan_params);
- hidden_free(wifi->hidden);
- wifi->hidden = NULL;
+ connman_device_unref(device);
+
+ if (do_hidden == TRUE) {
+ hidden_free(wifi->hidden);
+ wifi->hidden = NULL;
+ }
}
return ret;
@@ -1072,8 +1052,6 @@ static struct connman_device_driver wifi_ng_driver = {
.enable = wifi_enable,
.disable = wifi_disable,
.scan = wifi_scan,
- .scan_fast = wifi_scan_fast,
- .scan_hidden = wifi_scan_hidden,
.set_regdom = wifi_set_regdom,
};