Fix referencing incorrect bssid_list
[platform/upstream/connman.git] / plugins / wifi.c
index a1da419..8216816 100755 (executable)
 
 #include <gsupplicant/gsupplicant.h>
 
+#include "src/shared/util.h"
+
 #define CLEANUP_TIMEOUT   8    /* in seconds */
 #define INACTIVE_TIMEOUT  12   /* in seconds */
 #define FAVORITE_MAXIMUM_RETRIES 2
 
-#define BGSCAN_DEFAULT "simple:30:-45:300"
+#define BGSCAN_DEFAULT "simple:30:-65:300"
 #define AUTOSCAN_EXPONENTIAL "exponential:3:300"
 #define AUTOSCAN_SINGLE "single:3"
 
@@ -173,6 +175,9 @@ struct wifi_data {
        bool allow_full_scan;
        unsigned int automaxspeed_timeout;
        GSupplicantScanParams *hidden_scan_params;
+       unsigned int mac_policy;
+       unsigned int preassoc_mac_policy;
+       unsigned int mac_lifetime;
 #endif
        int disconnect_code;
        int assoc_code;
@@ -2406,7 +2411,7 @@ static void setup_autoscan(struct wifi_data *wifi)
 
                return;
        }
-#endif
+#else
 
        /*
         * On the contrary, if BackgroundScanning is disabled, update autoscan
@@ -2430,6 +2435,7 @@ static void setup_autoscan(struct wifi_data *wifi)
                wifi->autoscan = parse_autoscan_params(AUTOSCAN_SINGLE);
                break;
        }
+#endif
 }
 
 static void finalize_interface_creation(struct wifi_data *wifi)
@@ -2493,6 +2499,11 @@ static int wifi_enable(struct connman_device *device)
 
        interface = connman_inet_ifname(index);
        ret = g_supplicant_interface_create(interface, driver, NULL,
+#ifdef TIZEN_EXT
+                       connman_device_get_mac_policy(device),
+                       connman_device_get_preassoc_mac_policy(device),
+                       connman_device_get_random_mac_lifetime(device),
+#endif /* TIZEN_EXT */
                                                interface_create_callback,
                                                        wifi);
        g_free(interface);
@@ -2618,7 +2629,7 @@ static int get_latest_connections(int max_ssids,
                        g_key_file_free(keyfile);
                        continue;
                }
-               g_time_val_from_iso8601(str, &modified);
+               util_iso8601_to_timeval(str, &modified);
                g_free(str);
 
                ssid = g_key_file_get_string(keyfile,
@@ -2632,6 +2643,9 @@ static int get_latest_connections(int max_ssids,
                                g_sequence_free(latest_list);
                                g_key_file_free(keyfile);
                                g_free(ssid);
+#if defined TIZEN_EXT
+                               g_strfreev(services);
+#endif
                                return -ENOMEM;
                        }
 
@@ -2954,6 +2968,99 @@ static int wifi_specific_scan(enum connman_service_type type,
 
        return ret;
 }
+
+static void wifi_mac_policy_callback(int result,
+                                       unsigned int policy,
+                                               void *user_data)
+{
+       struct connman_device *device = user_data;
+
+       if (result == 0)
+               connman_device_mac_policy_notify(device, result, policy);
+
+       connman_device_unref(device);
+}
+
+int wifi_set_mac_policy(struct connman_device *device, unsigned int policy)
+{
+       struct wifi_data *wifi = connman_device_get_data(device);
+       int ret;
+
+       if (!wifi)
+               return -EINVAL;
+
+       connman_device_ref(device);
+
+       ret = g_supplicant_interface_set_mac_policy(wifi->interface,
+                                       wifi_mac_policy_callback,
+                                       policy, device);
+       if (ret != 0)
+               connman_device_unref(device);
+
+       return ret;
+}
+
+static void wifi_preassoc_mac_policy_callback(int result,
+                                       unsigned int policy,
+                                               void *user_data)
+{
+       struct connman_device *device = user_data;
+
+       if (result == 0)
+               connman_device_preassoc_mac_policy_notify(device, result, policy);
+
+       connman_device_unref(device);
+}
+
+int wifi_set_preassoc_mac_policy(struct connman_device *device, unsigned int policy)
+{
+       struct wifi_data *wifi = connman_device_get_data(device);
+       int ret;
+
+       if (!wifi)
+               return -EINVAL;
+
+       connman_device_ref(device);
+
+       ret = g_supplicant_interface_set_preassoc_mac_policy(wifi->interface,
+                                       wifi_preassoc_mac_policy_callback,
+                                       policy, device);
+       if (ret != 0)
+               connman_device_unref(device);
+
+       return ret;
+}
+
+static void wifi_random_mac_lifetime_callback(int result,
+                                       unsigned int lifetime,
+                                               void *user_data)
+{
+       struct connman_device *device = user_data;
+
+       if (result == 0)
+               connman_device_random_mac_lifetime_notify(device, result, lifetime);
+
+       connman_device_unref(device);
+}
+
+int wifi_set_random_mac_lifetime(struct connman_device *device, unsigned int lifetime)
+{
+       struct wifi_data *wifi = connman_device_get_data(device);
+       int ret;
+
+       if (!wifi)
+               return -EINVAL;
+
+       connman_device_ref(device);
+
+       ret = g_supplicant_interface_set_random_mac_lifetime(wifi->interface,
+                                       wifi_random_mac_lifetime_callback,
+                                       lifetime, device);
+       if (ret != 0)
+               connman_device_unref(device);
+
+       return ret;
+}
 #endif
 
 #if defined TIZEN_EXT_WIFI_MESH
@@ -3329,6 +3436,9 @@ static struct connman_device_driver wifi_ng_driver = {
        .set_regdom     = wifi_set_regdom,
 #if defined TIZEN_EXT
        .specific_scan  = wifi_specific_scan,
+       .set_mac_policy           = wifi_set_mac_policy,
+       .set_preassoc_mac_policy  = wifi_set_preassoc_mac_policy,
+       .set_random_mac_lifetime  = wifi_set_random_mac_lifetime,
 #endif
 #if defined TIZEN_EXT_WIFI_MESH
        .abort_scan     = mesh_abort_scan,
@@ -3353,6 +3463,9 @@ static void system_killed(void)
 
 static int network_probe(struct connman_network *network)
 {
+#if defined TIZEN_EXT
+       if (!simplified_log)
+#endif
        DBG("network %p", network);
 
        return 0;
@@ -3397,7 +3510,7 @@ static void connect_callback(int result, GSupplicantInterface *interface,
        DBG("network %p result %d", network, result);
 
 #if defined TIZEN_EXT
-       char *ifname = g_supplicant_interface_get_ifname(interface);
+       const char *ifname = g_supplicant_interface_get_ifname(interface);
        set_connman_bssid(RESET_BSSID, NULL, ifname);
 
        for (list = iface_list; list; list = list->next) {
@@ -3704,7 +3817,7 @@ found:
                return;
        }
 
-       if (wifi->network != wifi->pending_network)
+       if (wifi->network && wifi->network != wifi->pending_network)
                connman_network_set_connected(wifi->network, false);
        wifi->network = NULL;
 
@@ -4346,9 +4459,9 @@ static void interface_state(GSupplicantInterface *interface)
 
 #if defined TIZEN_EXT
                if (handle_assoc_status_code(interface, wifi)) {
-                       GSList *bssid_list = (GSList *)connman_network_get_bssid_list(network);
                        const char *group = connman_network_get_group(network);
                        GSupplicantNetwork *supplicant_network;
+                       GSList *bssid_list = NULL;
                        guint bssid_length = 0;
 
                        if (group) {
@@ -4360,6 +4473,7 @@ static void interface_state(GSupplicantInterface *interface)
                                g_supplicant_network_update_assoc_reject(interface, supplicant_network);
                        }
 
+                       bssid_list = (GSList *)connman_network_get_bssid_list(network);
                        if (bssid_list)
                                bssid_length = g_slist_length(bssid_list);
 
@@ -4819,7 +4933,9 @@ static void network_added(GSupplicantNetwork *supplicant_network)
 
        mode = g_supplicant_network_get_mode(supplicant_network);
        identifier = g_supplicant_network_get_identifier(supplicant_network);
-
+#if defined TIZEN_EXT
+       if (!simplified_log)
+#endif
        DBG("%s", identifier);
 
        if (!g_strcmp0(mode, "adhoc"))
@@ -5072,7 +5188,8 @@ static void network_changed(GSupplicantNetwork *network, const char *property)
        name = g_supplicant_network_get_name(network);
 
 #if defined TIZEN_EXT
-       DBG("name %s property %s", name, property);
+       if (!simplified_log)
+               DBG("name %s property %s", name, property);
 #else
        DBG("name %s", name);
 #endif
@@ -5131,6 +5248,8 @@ static void network_changed(GSupplicantNetwork *network, const char *property)
                        need_save = connman_device_set_last_connected_ident(wifi->device, service_ident);
                        if (need_save)
                                connman_device_save_last_connected(wifi->device);
+
+                       g_free(service_ident);
                }
 
                connman_network_set_last_connected_bssid(connman_network,
@@ -5841,6 +5960,9 @@ static void sta_remove_callback(int result,
        info->wifi->interface = NULL;
 
        g_supplicant_interface_create(info->ifname, driver, info->wifi->bridge,
+#ifdef TIZEN_EXT
+                       0, 0, 60,
+#endif /* TIZEN_EXT */
                                                ap_create_callback,
                                                        info);
 }