Merge "[connman]: Fixed Scan Issue" into tizen
[platform/upstream/connman.git] / plugins / wifi.c
index e8c7ae5..05eb47e 100755 (executable)
@@ -130,21 +130,22 @@ struct wifi_data {
        int servicing;
 #if defined TIZEN_EXT
        int assoc_retry_count;
-       struct connman_network *interface_disconnected_network;
        struct connman_network *scan_pending_network;
+       bool allow_full_scan;
 #endif
 };
 
 #if defined TIZEN_EXT
 #include "connman.h"
 
-#define TIZEN_ASSOC_RETRY_COUNT                3
+#define TIZEN_ASSOC_RETRY_COUNT                4
 
 static gboolean wifi_first_scan = false;
 static gboolean found_with_first_scan = false;
 static gboolean is_wifi_notifier_registered = false;
 #endif
 
+
 static GList *iface_list = NULL;
 
 static GList *pending_wifi_device = NULL;
@@ -1320,9 +1321,15 @@ static void scan_callback(int result, GSupplicantInterface *interface,
                connman_device_unref(device);
 
 #if defined TIZEN_EXT
-       if (wifi && wifi->scan_pending_network) {
+       if (wifi && wifi->allow_full_scan) {
+               DBG("Trigger Full Channel Scan");
+               throw_wifi_scan(device, scan_callback);
+               wifi->allow_full_scan = FALSE;
+       }
+       if (wifi && wifi->scan_pending_network && result != -EIO) {
                network_connect(wifi->scan_pending_network);
                wifi->scan_pending_network = NULL;
+               connman_network_set_connecting(wifi->network);
        }
 
        if (is_wifi_notifier_registered != true &&
@@ -1589,7 +1596,6 @@ static int wifi_disable(struct connman_device *device)
 
 #if defined TIZEN_EXT
        wifi->scan_pending_network = NULL;
-       wifi->interface_disconnected_network = NULL;
 
        if (is_wifi_notifier_registered == true) {
                connman_notifier_unregister(&notifier);
@@ -1929,21 +1935,18 @@ static int wifi_scan(enum connman_service_type type,
 
        connman_device_ref(device);
 
+#if defined TIZEN_EXT
+       /*To allow the Full Scan after ssid based scan, set the flag here
+     It is required because Tizen does not use the ConnMan specific
+     backgroung Scan feature.Tizen has added the BG Scan feature in net-config
+     To sync with up ConnMan, we need to issue the Full Scan after SSID specific scan.*/
+        wifi->allow_full_scan = TRUE;
+#endif
        reset_autoscan(device);
 
-#if defined TIZEN_EXT
-       if (wifi->hidden) {
-               ret = g_supplicant_interface_scan(wifi->interface, scan_params,
-                                               scan_callback, device);
-       }
-       else {
-               ret = g_supplicant_interface_scan(wifi->interface, NULL,
-                                                       scan_callback_hidden, device);
-       }
-#else
        ret = g_supplicant_interface_scan(wifi->interface, scan_params,
                                                scan_callback, device);
-#endif
+
        if (ret == 0) {
                connman_device_set_scanning(device,
                                CONNMAN_SERVICE_TYPE_WIFI, true);
@@ -2048,9 +2051,6 @@ static void network_remove(struct connman_network *network)
 
        if (wifi->scan_pending_network == network)
                wifi->scan_pending_network = NULL;
-
-       if (wifi->interface_disconnected_network == network)
-               wifi->interface_disconnected_network = NULL;
 #endif
 }
 
@@ -2077,7 +2077,6 @@ static void connect_callback(int result, GSupplicantInterface *interface,
        return;
 
 found:
-       wifi->interface_disconnected_network = NULL;
 #endif
        if (result == -ENOKEY) {
                connman_network_set_error(network,
@@ -2104,6 +2103,12 @@ static GSupplicantSecurity network_security(const char *security)
                return G_SUPPLICANT_SECURITY_PSK;
        else if (g_str_equal(security, "ieee8021x"))
                return G_SUPPLICANT_SECURITY_IEEE8021X;
+#if defined TIZEN_EXT
+       else if (g_str_equal(security, "ft_psk") == TRUE)
+               return G_SUPPLICANT_SECURITY_FT_PSK;
+       else if (g_str_equal(security, "ft_ieee8021x") == TRUE)
+               return G_SUPPLICANT_SECURITY_FT_IEEE8021X;
+#endif
 
        return G_SUPPLICANT_SECURITY_UNKNOWN;
 }
@@ -2187,20 +2192,6 @@ static int network_connect(struct connman_network *network)
 
        ssid_init(ssid, network);
 
-#if defined TIZEN_EXT
-       if (wifi->interface_disconnected_network == network) {
-               g_free(ssid);
-               throw_wifi_scan(device, scan_callback);
-
-               if (wifi->disconnecting != TRUE) {
-                       wifi->scan_pending_network = network;
-                       wifi->interface_disconnected_network = NULL;
-               }
-
-               return -EINPROGRESS;
-       }
-#endif
-
        if (wifi->disconnecting) {
                wifi->pending_network = network;
                g_free(ssid);
@@ -2208,7 +2199,6 @@ static int network_connect(struct connman_network *network)
                wifi->network = connman_network_ref(network);
                wifi->retries = 0;
 #if defined TIZEN_EXT
-               wifi->interface_disconnected_network = NULL;
                wifi->scan_pending_network = NULL;
 #endif
 
@@ -2316,8 +2306,6 @@ static int network_disconnect(struct connman_network *network)
        if (wifi->scan_pending_network == network)
                wifi->scan_pending_network = NULL;
 
-       if (wifi->interface_disconnected_network == network)
-               wifi->interface_disconnected_network = NULL;
 #endif
        connman_network_set_associating(network, false);
 
@@ -2525,11 +2513,6 @@ static bool handle_4way_handshake_failure(GSupplicantInterface *interface,
        wifi->retries = 0;
        connman_network_set_error(network, CONNMAN_NETWORK_ERROR_INVALID_KEY);
 
-#if defined TIZEN_EXT
-       /* not retry autoconnect in case of invalid-key error */
-       __connman_service_set_autoconnect(service, false);
-#endif
-
        return false;
 }
 
@@ -2565,7 +2548,7 @@ static bool handle_wifi_assoc_retry(struct connman_network *network,
                 * however QA team recommends that the invalid-key error
                 * might be better to display for user experience.
                 */
-               connman_network_set_error(network, CONNMAN_NETWORK_ERROR_INVALID_KEY);
+               connman_network_set_error(network, CONNMAN_NETWORK_ERROR_ASSOCIATE_FAIL);
 
                return false;
        }
@@ -2626,6 +2609,8 @@ static void interface_state(GSupplicantInterface *interface)
                reset_autoscan(device);
 
                wifi->assoc_retry_count = 0;
+
+               wifi->scan_pending_network = NULL;
 #else
                /* though it should be already stopped: */
                stop_autoscan(device);
@@ -2667,6 +2652,15 @@ static void interface_state(GSupplicantInterface *interface)
                        DBG("Could not disables selected network");
 
 #if defined TIZEN_EXT
+               int err;
+               int reason_code = 0;
+
+               err = g_supplicant_interface_remove_network(wifi->interface);
+               if (err < 0)
+                       DBG("Failed to remove network(%d)", err);
+
+               reason_code = g_supplicant_interface_get_disconnect_reason(wifi->interface);
+
                /* Some of Wi-Fi networks are not comply Wi-Fi specification.
                 * Retry association until its retry count is expired */
                if (handle_wifi_assoc_retry(network, wifi) == true) {
@@ -2675,23 +2669,19 @@ static void interface_state(GSupplicantInterface *interface)
                        break;
                }
 
+               if(reason_code > 0){
+                       DBG("Set disconnect reason code(%d)", reason_code);
+                       connman_network_set_disconnect_reason(network, reason_code);
+               }
+
                /* To avoid unnecessary repeated association in wpa_supplicant,
                 * "RemoveNetwork" should be made when Wi-Fi is disconnected */
                if (wps != true && wifi->network && wifi->disconnecting == false) {
-#if 0 /* temporary disabled */
-                       int err;
-
                        wifi->disconnecting = true;
                        err = g_supplicant_interface_disconnect(wifi->interface,
                                                        disconnect_callback, wifi->network);
                        if (err < 0)
                                wifi->disconnecting = false;
-#endif
-
-                       if (wifi->connected)
-                               wifi->interface_disconnected_network = wifi->network;
-                       else
-                               wifi->interface_disconnected_network = NULL;
 
                connman_network_set_connected(network, false);
                connman_network_set_associating(network, false);
@@ -2849,6 +2839,8 @@ static void scan_finished(GSupplicantInterface *interface)
 {
 #if defined TIZEN_EXT
        struct wifi_data *wifi;
+       bool is_associating = false;
+       static bool is_scanning = true;
 #endif
 
        DBG("");
@@ -2859,6 +2851,23 @@ static void scan_finished(GSupplicantInterface *interface)
                network_connect(wifi->scan_pending_network);
                wifi->scan_pending_network = NULL;
        }
+
+       //service state - associating
+       if(!wifi || !wifi->network)
+               return;
+
+       is_associating = connman_network_get_associating(wifi->network);
+       if(is_associating && is_scanning){
+               is_scanning = false;
+               DBG("send scan for connecting");
+               throw_wifi_scan(wifi->device, scan_callback);
+
+               return;
+       }
+       is_scanning = true;
+
+       //go scan
+
 #endif
 }
 
@@ -2960,6 +2969,10 @@ static void network_added(GSupplicantNetwork *supplicant_network)
                        g_supplicant_network_get_maxrate(supplicant_network));
        connman_network_set_enc_mode(network,
                        g_supplicant_network_get_enc_mode(supplicant_network));
+       connman_network_set_rsn_mode(network,
+                       g_supplicant_network_get_rsn_mode(supplicant_network));
+       connman_network_set_keymgmt(network,
+                       g_supplicant_network_get_keymgmt(supplicant_network));
 #endif
        connman_network_set_available(network, true);
        connman_network_set_string(network, "WiFi.Mode", mode);
@@ -3016,9 +3029,6 @@ static void network_removed(GSupplicantNetwork *network)
        if (connman_network == wifi->scan_pending_network)
                wifi->scan_pending_network = NULL;
 
-       if (connman_network == wifi->interface_disconnected_network)
-               wifi->interface_disconnected_network = NULL;
-
        if (connman_network == wifi->pending_network)
                wifi->pending_network = NULL;