Maintain connection status when wifi roaming
[platform/upstream/connman.git] / gsupplicant / supplicant.c
index 00d183d..e457fef 100755 (executable)
@@ -317,6 +317,7 @@ struct g_supplicant_bss {
        unsigned int transition_mode_ssid_len;
        unsigned char transition_mode_bssid[6];
        unsigned char transition_mode_ssid[32];
+       dbus_bool_t pmf_required;
 #endif
 };
 
@@ -666,6 +667,9 @@ static int store_network_information(GSupplicantInterface * interface,
 
        if ((ssid->security == G_SUPPLICANT_SECURITY_WEP ||
                ssid->security == G_SUPPLICANT_SECURITY_PSK ||
+#if defined TIZEN_EXT
+               ssid->security == G_SUPPLICANT_SECURITY_SAE ||
+#endif
                ssid->security == G_SUPPLICANT_SECURITY_NONE) &&
                ssid->passphrase) {
                interface->network_info.passphrase = g_strdup(ssid->passphrase);
@@ -1597,6 +1601,32 @@ dbus_int16_t g_supplicant_network_get_signal(GSupplicantNetwork *network)
        return network->signal;
 }
 
+#if defined TIZEN_EXT
+void g_supplicant_network_set_signal(GSupplicantNetwork *network, int signal)
+{
+       if (!network)
+               return;
+
+       network->signal = (dbus_int16_t)signal;
+}
+
+void g_supplicant_network_set_bss_signal(GSupplicantNetwork *network,
+               int signal, int snr)
+{
+       struct g_supplicant_bss *best_bss;
+
+       if (!network)
+               return;
+
+       best_bss = network->best_bss;
+       if (!best_bss)
+               return;
+
+       best_bss->signal = (dbus_int16_t)signal;
+       best_bss->snr = (dbus_int16_t)snr;
+}
+#endif
+
 dbus_uint16_t g_supplicant_network_get_frequency(GSupplicantNetwork *network)
 {
        if (!network)
@@ -1761,6 +1791,14 @@ const unsigned char *g_supplicant_network_get_countrycode(GSupplicantNetwork
 
        return network->country_code;
 }
+
+dbus_bool_t g_supplicant_network_is_pmf_required(GSupplicantNetwork *network)
+{
+       if (!network)
+               return 0;
+
+       return network->best_bss->pmf_required;
+}
 #endif
 
 const unsigned char *g_supplicant_peer_get_widi_ies(GSupplicantPeer *peer,
@@ -2303,6 +2341,43 @@ GSupplicantNetwork *g_supplicant_interface_get_network(GSupplicantInterface *int
 
        return g_hash_table_lookup(interface->network_table, group);
 }
+
+static void copy_assoc_reject(gpointer key, gpointer value, gpointer user_data)
+{
+       struct assoc_reject_data *cloned_assoc_data;
+       struct assoc_reject_data *assoc_data = value;
+       GHashTable *cloned_assoc_reject_table = user_data;
+
+       if (assoc_data && cloned_assoc_reject_table) {
+               cloned_assoc_data = g_try_new0(struct assoc_reject_data, 1);
+               if (!cloned_assoc_data)
+                       return;
+
+               cloned_assoc_data->bssid = g_strdup(assoc_data->bssid);
+               cloned_assoc_data->reject_time_list = g_slist_copy(assoc_data->reject_time_list);
+               g_hash_table_insert(cloned_assoc_reject_table,
+                                       cloned_assoc_data->bssid, cloned_assoc_data);
+       }
+}
+
+GHashTable *g_supplicant_network_clone_assoc_reject_table(GSupplicantNetwork *network)
+{
+       GHashTable *cloned_assoc_reject_table;
+
+       if (!network)
+               return NULL;
+
+       GHashTable *assoc_reject_table = g_supplicant_network_get_assoc_reject_table(network);
+       if (!assoc_reject_table)
+               return NULL;
+
+       cloned_assoc_reject_table = g_hash_table_new_full(g_str_hash, g_str_equal,
+                                                               NULL, remove_assoc_data);
+       g_hash_table_foreach(assoc_reject_table, copy_assoc_reject, cloned_assoc_reject_table);
+
+       return cloned_assoc_reject_table;
+}
+
 #endif
 
 static void merge_network(GSupplicantNetwork *network)
@@ -2582,7 +2657,7 @@ static bool update_best_bss(GSupplicantNetwork *network,
 #endif
 
        if (score_new > score_best) {
-               SUPPLICANT_DBG("new[" MACSTR "][%u] : best[" MACSTR "][%u]",
+               SUPPLICANT_DBG("new[" MACSTR "][%d] : best[" MACSTR "][%d]",
                        MAC2STR(bss->bssid), score_new,
                        MAC2STR(network->best_bss->bssid), score_best);
 
@@ -2926,6 +3001,7 @@ static void bss_process_ies(DBusMessageIter *iter, void *user_data)
        unsigned char *ext_rates = NULL;
        unsigned int max_rate = 0;
        unsigned int max_ext_rate = 0;
+       unsigned int offset = 0;
        bool ht = false;
        bool vht = false;
 #endif
@@ -2943,6 +3019,8 @@ static void bss_process_ies(DBusMessageIter *iter, void *user_data)
 #if defined TIZEN_EXT
 #define VENDOR_SPECIFIC_INFO 0xDD
 #define WLAN_EID_COUNTRY 7
+#define WLAN_EID_RSN_INFO 48
+#define RSN_CAPABILITY_MFP_REQ (1 << 6)
 #endif
 
        dbus_message_iter_recurse(iter, &array);
@@ -2960,7 +3038,7 @@ static void bss_process_ies(DBusMessageIter *iter, void *user_data)
                unsigned char *vsie;
                int vsie_len = 0;
 
-               if(ie[0] == VENDOR_SPECIFIC_INFO && memcmp(ie+2, OWE_WFA_OUI, sizeof(OWE_WFA_OUI)) == 0) {
+               if (ie[0] == VENDOR_SPECIFIC_INFO && memcmp(ie+2, OWE_WFA_OUI, sizeof(OWE_WFA_OUI)) == 0) {
                        SUPPLICANT_DBG("IE: match vendor specific data : OWE Transition Mode");
 
 /*
@@ -2990,7 +3068,7 @@ static void bss_process_ies(DBusMessageIter *iter, void *user_data)
                        continue;
                }
 
-               if(ie[0] == VENDOR_SPECIFIC_INFO && memcmp(ie+2, WPS_OUI, sizeof(WPS_OUI)) != 0) {
+               if (ie[0] == VENDOR_SPECIFIC_INFO && memcmp(ie+2, WPS_OUI, sizeof(WPS_OUI)) != 0) {
 
                        if (!simplified_log)
                                SUPPLICANT_DBG("IE: match vendor specific data");
@@ -3006,7 +3084,7 @@ static void bss_process_ies(DBusMessageIter *iter, void *user_data)
                        continue;
                }
 
-               if(ie[0] == WLAN_EID_COUNTRY && ie[1] >= 2) {
+               if (ie[0] == WLAN_EID_COUNTRY && ie[1] >= 2) {
                        /* Add country code only if it is a valid alphabet */
                        if (ie[2] >= 65 && ie[2] <= 90 && ie[3] >= 65 && ie[3] <= 90) {
                                memcpy(bss->country_code, ie+2, COUNTRY_CODE_LENGTH);
@@ -3051,6 +3129,18 @@ static void bss_process_ies(DBusMessageIter *iter, void *user_data)
                        }
                        continue;
                }
+
+               if (ie[0] == WLAN_EID_RSN_INFO && ie[1] >= 20) {
+                       r_len = ie[1];
+                       offset = 10 + ie[8] * 4;
+                       offset += ie[offset] * 4 + 2;
+
+                       if (offset <= r_len + 1 &&
+                                       (ie[offset] & RSN_CAPABILITY_MFP_REQ) != 0)
+                               bss->pmf_required = TRUE;
+
+                       continue;
+               }
 #endif
                if (ie[0] != WMM_WPA1_WPS_INFO || ie[1] < WPS_INFO_MIN_LEN ||
                        memcmp(ie+2, WPS_OUI, sizeof(WPS_OUI)) != 0)
@@ -3483,6 +3573,13 @@ static void interface_current_bss(GSupplicantInterface *interface,
        GSupplicantNetwork *network;
        struct g_supplicant_bss *bss;
        const char *path;
+#if defined TIZEN_EXT
+       char bssid_buff1[WIFI_BSSID_STR_LEN] = {0,};
+       char bssid_buff2[WIFI_BSSID_STR_LEN] = {0,};
+       char *bssid_str1 = bssid_buff1;
+       char *bssid_str2 = bssid_buff2;
+       gboolean update = FALSE;
+#endif
 
        dbus_message_iter_get_basic(iter, &path);
        if (g_strcmp0(path, "/") == 0) {
@@ -3502,7 +3599,16 @@ static void interface_current_bss(GSupplicantInterface *interface,
 
        interface->current_network = network;
 #if defined TIZEN_EXT
-       SUPPLICANT_DBG("current network [%p]", interface->current_network);
+       snprintf(bssid_str1, WIFI_BSSID_STR_LEN, MACSTR, MAC2STR(bss->bssid));
+       snprintf(bssid_str2, WIFI_BSSID_STR_LEN, MACSTR, MAC2STR(network->best_bss->bssid));
+
+       SUPPLICANT_DBG("current network [%p], Passed bss %s, best bss %s",
+                       interface->current_network, bssid_str1, bssid_str2);
+
+       if (network->frequency != bss->frequency) {
+               network->frequency = bss->frequency;
+               update = TRUE;
+       }
 #endif
 
        if (bss != network->best_bss) {
@@ -3515,24 +3621,25 @@ static void interface_current_bss(GSupplicantInterface *interface,
 
                network->best_bss = bss;
 
-#if defined TIZEN_EXT
-               if (network->frequency != bss->frequency)
-                       network->frequency = bss->frequency;
-#endif
-
                if (network->signal != bss->signal) {
                        SUPPLICANT_DBG("New network signal %d dBm",
                                                bss->signal);
 
                        network->signal = bss->signal;
                        callback_network_changed(network, "Signal");
-               }
 #if defined TIZEN_EXT
-               else
-                       callback_network_changed(network, "");
+                       update = FALSE;
+               } else {
+                       update = TRUE;
 #endif
+               }
        }
 
+#if defined TIZEN_EXT
+       if (update)
+               callback_network_changed(network, "");
+#endif
+
        /*
         * wpa_s could notify about CurrentBSS in any state once
         * it got associated. It is not sure such notification will
@@ -5417,7 +5524,7 @@ static void country_result(const char *error,
                regdom->callback(result, regdom->alpha2,
                                        (void *) regdom->user_data);
 
-       dbus_free(regdom);
+       g_free(regdom);
 }
 
 static void country_params(DBusMessageIter *iter, void *user_data)
@@ -5681,7 +5788,7 @@ static void interface_create_result(const char *error,
        SUPPLICANT_DBG("");
 
        if (error) {
-               g_message("error %s", error);
+               g_warning("error %s", error);
                err = -EIO;
                goto done;
        }
@@ -6833,10 +6940,8 @@ static void add_network_security_tls(DBusMessageIter *dict,
        if (!ssid->private_key_path)
                return;
 
-#if !defined TIZEN_EXT
        if (!ssid->private_key_passphrase)
                return;
-#endif
 
        if (ssid->ca_cert_path)
                supplicant_dbus_dict_append_basic(dict, "ca_cert",
@@ -6845,11 +6950,9 @@ static void add_network_security_tls(DBusMessageIter *dict,
        supplicant_dbus_dict_append_basic(dict, "private_key",
                                                DBUS_TYPE_STRING,
                                                &ssid->private_key_path);
-#if !defined TIZEN_EXT
        supplicant_dbus_dict_append_basic(dict, "private_key_passwd",
                                                DBUS_TYPE_STRING,
                                                &ssid->private_key_passphrase);
-#endif
        supplicant_dbus_dict_append_basic(dict, "client_cert",
                                                DBUS_TYPE_STRING,
                                                &ssid->client_cert_path);