X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=plugins%2Fwifi.c;h=3e4899950af603cd32e288294ff11184679b288a;hb=c223c7fbca163f55eabe75af145c513137593eb5;hp=3cd2be29bd42692b0036a57a1c8e60db5e67c0d4;hpb=4bf651579338f163d18b63a25c3d10846c8e2b3d;p=framework%2Fconnectivity%2Fconnman.git diff --git a/plugins/wifi.c b/plugins/wifi.c index 3cd2be2..3e48999 100644 --- a/plugins/wifi.c +++ b/plugins/wifi.c @@ -68,6 +68,7 @@ struct hidden_params { unsigned int ssid_len; char *identity; char *passphrase; + gpointer user_data; }; /** @@ -107,6 +108,8 @@ struct wifi_data { static GList *iface_list = NULL; +static void start_autoscan(struct connman_device *device); + static void handle_tethering(struct wifi_data *wifi) { if (wifi->tethering == FALSE) @@ -202,7 +205,7 @@ static void remove_networks(struct connman_device *device, wifi->networks = NULL; } -static void stop_autoscan(struct connman_device *device) +static void reset_autoscan(struct connman_device *device) { struct wifi_data *wifi = connman_device_get_data(device); struct autoscan_params *autoscan; @@ -222,11 +225,16 @@ static void stop_autoscan(struct connman_device *device) autoscan->timeout = 0; autoscan->interval = 0; - connman_device_set_scanning(device, FALSE); - connman_device_unref(device); } +static void stop_autoscan(struct connman_device *device) +{ + reset_autoscan(device); + + connman_device_set_scanning(device, FALSE); +} + static void wifi_remove(struct connman_device *device) { struct wifi_data *wifi = connman_device_get_data(device); @@ -236,12 +244,6 @@ static void wifi_remove(struct connman_device *device) if (wifi == NULL) return; - stop_autoscan(device); - - /* In case of a user scan, device is still referenced */ - if (connman_device_get_scanning(device) == TRUE) - connman_device_unref(wifi->device); - iface_list = g_list_remove(iface_list, wifi); remove_networks(device, wifi); @@ -420,18 +422,39 @@ static int throw_wifi_scan(struct connman_device *device, return ret; } -static void hidden_scan_callback(int result, - GSupplicantInterface *interface, void *user_data) +static void hidden_free(struct hidden_params *hidden) +{ + if (hidden == NULL) + return; + + g_free(hidden->identity); + g_free(hidden->passphrase); + g_free(hidden); +} + +static void scan_callback(int result, GSupplicantInterface *interface, + void *user_data) { struct connman_device *device = user_data; + struct wifi_data *wifi = connman_device_get_data(device); DBG("result %d", result); + if (wifi != NULL && wifi->hidden != NULL) { + connman_network_clear_hidden(wifi->hidden->user_data); + hidden_free(wifi->hidden); + wifi->hidden = NULL; + } + + if (result < 0) + connman_device_reset_scanning(device); + connman_device_set_scanning(device, FALSE); + start_autoscan(device); connman_device_unref(device); } -static void autoscan_scan_callback(int result, +static void scan_callback_hidden(int result, GSupplicantInterface *interface, void *user_data) { struct connman_device *device = user_data; @@ -459,7 +482,7 @@ static void autoscan_scan_callback(int result, scan_params) > 0) { ret = g_supplicant_interface_scan(wifi->interface, scan_params, - hidden_scan_callback, + scan_callback, device); if (ret == 0) return; @@ -469,8 +492,7 @@ static void autoscan_scan_callback(int result, } out: - connman_device_set_scanning(device, FALSE); - connman_device_unref(device); + scan_callback(result, interface, user_data); } static gboolean autoscan_timeout(gpointer data) @@ -491,7 +513,7 @@ static gboolean autoscan_timeout(gpointer data) if (autoscan->interval >= autoscan->limit) interval = autoscan->limit; - throw_wifi_scan(wifi->device, autoscan_scan_callback); + throw_wifi_scan(wifi->device, scan_callback_hidden); set_interval: DBG("interval %d", interval); @@ -636,6 +658,14 @@ static int wifi_disable(struct connman_device *device) if (wifi->pending_network != NULL) wifi->pending_network = NULL; + stop_autoscan(device); + + /* In case of a user scan, device is still referenced */ + if (connman_device_get_scanning(device) == TRUE) { + connman_device_set_scanning(device, FALSE); + connman_device_unref(wifi->device); + } + remove_networks(device, wifi); ret = g_supplicant_interface_remove(wifi->interface, NULL, NULL); @@ -645,38 +675,6 @@ static int wifi_disable(struct connman_device *device) return -EINPROGRESS; } -static void hidden_free(struct hidden_params *hidden) -{ - if (hidden == NULL) - return; - - g_free(hidden->identity); - g_free(hidden->passphrase); - g_free(hidden); -} - -static void scan_callback(int result, GSupplicantInterface *interface, - void *user_data) -{ - struct connman_device *device = user_data; - struct wifi_data *wifi = connman_device_get_data(device); - - DBG("result %d", result); - - if (wifi != NULL && wifi->hidden != NULL) { - hidden_free(wifi->hidden); - wifi->hidden = NULL; - } - - if (result < 0) - connman_device_reset_scanning(device); - - connman_device_set_scanning(device, FALSE); - connman_device_unref(device); - - start_autoscan(device); -} - struct last_connected { GTimeVal modified; gchar *ssid; @@ -808,9 +806,9 @@ static int get_latest_connections(int max_ssids, static int wifi_scan(struct connman_device *device) { - stop_autoscan(device); + reset_autoscan(device); - return throw_wifi_scan(device, scan_callback); + return throw_wifi_scan(device, scan_callback_hidden); } static int wifi_scan_fast(struct connman_device *device) @@ -825,8 +823,6 @@ static int wifi_scan_fast(struct connman_device *device) if (wifi->tethering == TRUE) return 0; - stop_autoscan(device); - if (connman_device_get_scanning(device) == TRUE) return -EALREADY; @@ -847,6 +843,8 @@ static int wifi_scan_fast(struct connman_device *device) } connman_device_ref(device); + reset_autoscan(device); + ret = g_supplicant_interface_scan(wifi->interface, scan_params, scan_callback, device); if (ret == 0) @@ -865,7 +863,8 @@ static int wifi_scan_fast(struct connman_device *device) */ static int wifi_scan_hidden(struct connman_device *device, const char *ssid, unsigned int ssid_len, - const char *identity, const char* passphrase) + const char *identity, const char* passphrase, + gpointer user_data) { struct wifi_data *wifi = connman_device_get_data(device); GSupplicantScanParams *scan_params = NULL; @@ -881,8 +880,6 @@ static int wifi_scan_hidden(struct connman_device *device, if (ssid == NULL || ssid_len == 0 || ssid_len > 32) return -EINVAL; - stop_autoscan(device); - if (connman_device_get_scanning(device) == TRUE) return -EALREADY; @@ -911,9 +908,13 @@ static int wifi_scan_hidden(struct connman_device *device, 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); if (ret == 0) @@ -1459,7 +1460,7 @@ static void interface_removed(GSupplicantInterface *interface) return; if (wifi == NULL || wifi->device == NULL) { - connman_error("Wrong wifi pointer"); + DBG("wifi interface already removed"); return; } @@ -1572,7 +1573,9 @@ static void network_added(GSupplicantNetwork *supplicant_network) ssid_len) == 0) { connman_network_connect_hidden(network, wifi->hidden->identity, - wifi->hidden->passphrase); + wifi->hidden->passphrase, + wifi->hidden->user_data); + wifi->hidden->user_data = NULL; hidden_free(wifi->hidden); wifi->hidden = NULL; }