Fix build warnings
[platform/upstream/connman.git] / plugins / wifi.c
old mode 100644 (file)
new mode 100755 (executable)
index f8c22be..d532e93
 #define P2P_LISTEN_INTERVAL 2000
 
 #define ASSOC_STATUS_NO_CLIENT 17
+#if defined TIZEN_EXT
+#define LOAD_SHAPING_MAX_RETRIES 7
+#else
 #define LOAD_SHAPING_MAX_RETRIES 3
+#endif
+
+#if defined TIZEN_EXT
+#define WIFI_EAP_FAST_PAC_FILE         "/var/lib/wifi/wifi.pac"        /* path of Pac file for EAP-FAST */
+#endif
 
 static struct connman_technology *wifi_technology = NULL;
 static struct connman_technology *p2p_technology = NULL;
@@ -159,10 +167,35 @@ struct wifi_data {
        bool p2p_connecting;
        bool p2p_device;
        int servicing;
+#if defined TIZEN_EXT
+       int assoc_retry_count;
+       struct connman_network *scan_pending_network;
+       bool allow_full_scan;
+       unsigned int automaxspeed_timeout;
+       GSupplicantScanParams *hidden_scan_params;
+#endif
        int disconnect_code;
        int assoc_code;
+#if defined TIZEN_EXT_WIFI_MESH
+       bool mesh_interface;
+       struct wifi_mesh_info *mesh_info;
+#endif
 };
 
+#if defined TIZEN_EXT
+#include "connman.h"
+#include "dbus.h"
+
+#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;
+static GHashTable *failed_bssids = NULL;
+static unsigned char buff_bssid[WIFI_BSSID_LEN_MAX] = { 0, };
+#endif
+
+
 static GList *iface_list = NULL;
 
 static GList *pending_wifi_device = NULL;
@@ -174,6 +207,123 @@ static int tech_set_tethering(struct connman_technology *technology,
                                const char *identifier, const char *passphrase,
                                const char *bridge, bool enabled);
 
+#if defined TIZEN_EXT
+#define NETCONFIG_SERVICE "net.netconfig"
+#define NETCONFIG_WIFI_PATH "/net/netconfig/wifi"
+#define NETCONFIG_WIFI_INTERFACE NETCONFIG_SERVICE ".wifi"
+
+struct enc_method_call_data {
+       DBusConnection *connection;
+       struct connman_network *network;
+};
+
+static struct enc_method_call_data encrypt_request_data;
+
+static void encryption_request_reply(DBusPendingCall *call,
+                                               void *user_data)
+{
+       DBusMessage *reply;
+       DBusError error;
+       DBusMessageIter args;
+       char *out_data;
+       struct connman_service *service;
+       gchar* encrypted_value = NULL;
+       struct connman_network *network = encrypt_request_data.network;
+
+       DBG("");
+
+       reply = dbus_pending_call_steal_reply(call);
+
+       dbus_error_init(&error);
+       if (dbus_set_error_from_message(&error, reply)) {
+               DBG("send_encryption_request() %s %s", error.name, error.message);
+               dbus_error_free(&error);
+               goto done;
+       }
+
+       if (dbus_message_iter_init(reply, &args) == FALSE)
+               goto done;
+
+       dbus_message_iter_get_basic(&args, &out_data);
+
+       encrypted_value = g_strdup((const gchar *)out_data);
+       service = connman_service_lookup_from_network(network);
+
+       if (!service) {
+               DBG("encryption result: no service");
+               goto done;
+       }
+
+       if (connman_service_get_favorite(service)) {
+               __connman_service_set_passphrase(service, encrypted_value);
+               __connman_service_save(service);
+       } else
+               connman_network_set_string(network, "WiFi.Passphrase",
+                                                       encrypted_value);
+
+       DBG("encryption result: succeeded");
+
+done:
+       dbus_message_unref(reply);
+       dbus_pending_call_unref(call);
+       dbus_connection_unref(encrypt_request_data.connection);
+       g_free(encrypted_value);
+
+       encrypt_request_data.connection = NULL;
+       encrypt_request_data.network = NULL;
+}
+
+static int send_encryption_request(const char *passphrase,
+                               struct connman_network *network)
+{
+       DBusConnection *connection = NULL;
+       DBusMessage *msg = NULL;
+       DBusPendingCall *call;
+
+       if (!passphrase) {
+               DBG("Invalid parameter");
+               return -EINVAL;
+       }
+
+       connection = connman_dbus_get_connection();
+       if (!connection) {
+               DBG("dbus connection does not exist");
+               return -EINVAL;
+       }
+
+       msg = dbus_message_new_method_call(NETCONFIG_SERVICE, NETCONFIG_WIFI_PATH,
+                       NETCONFIG_WIFI_INTERFACE, "EncryptPassphrase");
+       if (!msg) {
+               dbus_connection_unref(connection);
+               return -EINVAL;
+       }
+
+       dbus_message_append_args(msg, DBUS_TYPE_STRING, &passphrase,
+                                                       DBUS_TYPE_INVALID);
+
+       if (!dbus_connection_send_with_reply(connection, msg,
+                               &call, DBUS_TIMEOUT_USE_DEFAULT)) {
+               dbus_message_unref(msg);
+               dbus_connection_unref(connection);
+               return -EIO;
+       }
+
+       if (!call) {
+               dbus_message_unref(msg);
+               dbus_connection_unref(connection);
+               return -EIO;
+       }
+
+       encrypt_request_data.connection = connection;
+       encrypt_request_data.network = network;
+
+       dbus_pending_call_set_notify(call, encryption_request_reply, NULL, NULL);
+       dbus_message_unref(msg);
+
+       return 0;
+}
+#endif
+
 static int p2p_tech_probe(struct connman_technology *technology)
 {
        p2p_technology = technology;
@@ -215,6 +365,506 @@ static void add_pending_wifi_device(struct wifi_data *wifi)
        pending_wifi_device = g_list_append(pending_wifi_device, wifi);
 }
 
+#if defined TIZEN_EXT_WIFI_MESH
+struct wifi_mesh_info {
+       struct wifi_data *wifi;
+       GSupplicantInterface *interface;
+       struct connman_mesh *mesh;
+       char *parent_ifname;
+       char *ifname;
+       char *identifier;
+       int index;
+};
+
+struct mesh_change_peer_status_info {
+       char *peer_address;
+       enum connman_mesh_peer_status peer_status;
+       mesh_change_peer_status_cb_t callback;
+       void *user_data;
+};
+
+static struct connman_technology_driver mesh_tech_driver = {
+       .name = "mesh",
+       .type = CONNMAN_SERVICE_TYPE_MESH,
+};
+
+static void mesh_interface_create_callback(int result,
+                                          GSupplicantInterface *interface,
+                                          void *user_data)
+{
+       struct wifi_mesh_info *mesh_info = user_data;
+       struct wifi_data *wifi;
+       bool success = false;
+
+       DBG("result %d ifname %s, mesh_info %p", result,
+                               g_supplicant_interface_get_ifname(interface),
+                               mesh_info);
+
+       if (result < 0 || !mesh_info)
+               goto done;
+
+       wifi = mesh_info->wifi;
+
+       mesh_info->interface = interface;
+       mesh_info->identifier = connman_inet_ifaddr(mesh_info->ifname);
+       mesh_info->index = connman_inet_ifindex(mesh_info->ifname);
+       DBG("Mesh Interface identifier %s", mesh_info->identifier);
+       wifi->mesh_interface = true;
+       wifi->mesh_info = mesh_info;
+       g_supplicant_interface_set_data(interface, wifi);
+       success = true;
+
+done:
+       connman_mesh_notify_interface_create(success);
+}
+
+static int add_mesh_interface(const char *ifname, const char *parent_ifname)
+{
+       GList *list;
+       struct wifi_data *wifi;
+       struct wifi_mesh_info *mesh_info;
+       const char *wifi_ifname;
+       bool parent_found = false;
+       const char *driver = "nl80211";
+
+       for (list = iface_list; list; list = list->next) {
+               wifi = list->data;
+
+               if (!g_supplicant_interface_has_mesh(wifi->interface))
+                       continue;
+
+               wifi_ifname = g_supplicant_interface_get_ifname(wifi->interface);
+               if (!wifi_ifname)
+                       continue;
+
+               if (!g_strcmp0(wifi_ifname, parent_ifname)) {
+                       parent_found = true;
+                       break;
+               }
+       }
+
+       if (!parent_found) {
+               DBG("Parent interface %s doesn't exist", parent_ifname);
+               return -ENODEV;
+       }
+
+       mesh_info = g_try_malloc0(sizeof(struct wifi_mesh_info));
+       if (!mesh_info)
+               return -ENOMEM;
+
+       mesh_info->wifi = wifi;
+       mesh_info->ifname = g_strdup(ifname);
+       mesh_info->parent_ifname = g_strdup(parent_ifname);
+
+       g_supplicant_mesh_interface_create(ifname, driver, NULL, parent_ifname,
+                                               mesh_interface_create_callback, mesh_info);
+       return -EINPROGRESS;
+}
+
+static void mesh_interface_remove_callback(int result,
+                                       GSupplicantInterface *interface,
+                                                       void *user_data)
+{
+       struct wifi_data *wifi = user_data;
+       struct wifi_mesh_info *mesh_info = wifi->mesh_info;
+       bool success = false;
+
+       DBG("result %d mesh_info %p", result, mesh_info);
+
+       if (result < 0 || !mesh_info)
+               goto done;
+
+       mesh_info->interface = NULL;
+       g_free(mesh_info->parent_ifname);
+       g_free(mesh_info->ifname);
+       g_free(mesh_info->identifier);
+       g_free(mesh_info);
+       wifi->mesh_interface = false;
+       wifi->mesh_info = NULL;
+       success = true;
+
+done:
+       connman_mesh_notify_interface_remove(success);
+}
+
+static int remove_mesh_interface(const char *ifname)
+{
+       GList *list;
+       struct wifi_data *wifi;
+       struct wifi_mesh_info *mesh_info;
+       bool mesh_if_found = false;
+       int ret;
+
+       for (list = iface_list; list; list = list->next) {
+               wifi = list->data;
+
+               if (wifi->mesh_interface) {
+                       mesh_if_found = true;
+                       break;
+               }
+       }
+
+       if (!mesh_if_found) {
+               DBG("Mesh interface %s doesn't exist", ifname);
+               return -ENODEV;
+       }
+
+       mesh_info = wifi->mesh_info;
+       ret = g_supplicant_interface_remove(mesh_info->interface,
+                                               mesh_interface_remove_callback, wifi);
+       if (ret < 0)
+               return ret;
+
+       return -EINPROGRESS;
+}
+
+static void mesh_disconnect_callback(int result,
+                                       GSupplicantInterface *interface, void *user_data)
+{
+       struct connman_mesh *mesh = user_data;
+
+       DBG("result %d interface %p mesh %p", result, interface, mesh);
+}
+
+static int mesh_peer_disconnect(struct connman_mesh *mesh)
+{
+       GList *list;
+       struct wifi_data *wifi;
+       struct wifi_mesh_info *mesh_info;
+       bool mesh_if_found = false;
+       GSupplicantInterface *interface;
+
+       for (list = iface_list; list; list = list->next) {
+               wifi = list->data;
+
+               if (wifi->mesh_interface) {
+                       mesh_if_found = true;
+                       break;
+               }
+       }
+
+       if (!mesh_if_found) {
+               DBG("Mesh interface is not created");
+               return -ENODEV;
+       }
+
+       mesh_info = wifi->mesh_info;
+
+       interface = mesh_info->interface;
+       return g_supplicant_interface_disconnect(interface,
+                                               mesh_disconnect_callback, mesh);
+}
+
+static void mesh_connect_callback(int result, GSupplicantInterface *interface,
+                                                                 void *user_data)
+{
+       struct connman_mesh *mesh = user_data;
+       DBG("mesh %p result %d", mesh, result);
+
+       if (result < 0)
+               connman_mesh_peer_set_state(mesh, CONNMAN_MESH_STATE_FAILURE);
+       else
+               connman_mesh_peer_set_state(mesh, CONNMAN_MESH_STATE_ASSOCIATION);
+}
+
+static GSupplicantSecurity mesh_network_security(const char *security)
+{
+       if (g_str_equal(security, "none"))
+               return G_SUPPLICANT_SECURITY_NONE;
+       else if (g_str_equal(security, "sae"))
+               return G_SUPPLICANT_SECURITY_SAE;
+
+       return G_SUPPLICANT_SECURITY_UNKNOWN;
+}
+
+static void mesh_ssid_init(GSupplicantSSID *ssid, struct connman_mesh *mesh)
+{
+       const char *name;
+       const char *security;
+
+       if (ssid->ssid)
+               g_free(ssid->ssid);
+
+       memset(ssid, 0, sizeof(*ssid));
+       ssid->mode = G_SUPPLICANT_MODE_MESH;
+
+       security = connman_mesh_get_security(mesh);
+       ssid->security = mesh_network_security(security);
+
+       if (ssid->security == G_SUPPLICANT_SECURITY_SAE)
+               ssid->passphrase = connman_mesh_get_passphrase(mesh);
+
+       ssid->freq = connman_mesh_get_frequency(mesh);
+       name = connman_mesh_get_name(mesh);
+       if (name) {
+               ssid->ssid_len = strlen(name);
+               ssid->ssid = g_malloc0(ssid->ssid_len + 1);
+               memcpy(ssid->ssid, name, ssid->ssid_len);
+               ssid->scan_ssid = 1;
+       }
+}
+
+static int mesh_peer_connect(struct connman_mesh *mesh)
+{
+       GList *list;
+       struct wifi_data *wifi;
+       struct wifi_mesh_info *mesh_info;
+       bool mesh_if_found = false;
+       GSupplicantInterface *interface;
+       GSupplicantSSID *ssid;
+
+       for (list = iface_list; list; list = list->next) {
+               wifi = list->data;
+
+               if (wifi->mesh_interface) {
+                       mesh_if_found = true;
+                       break;
+               }
+       }
+
+       if (!mesh_if_found) {
+               DBG("Mesh interface is not created");
+               return -ENODEV;
+       }
+
+       mesh_info = wifi->mesh_info;
+
+       interface = mesh_info->interface;
+
+       ssid = g_try_malloc0(sizeof(GSupplicantSSID));
+       if (!ssid)
+               return -ENOMEM;
+
+       mesh_info->mesh = mesh;
+
+       mesh_ssid_init(ssid, mesh);
+       return g_supplicant_interface_connect(interface, ssid,
+                                               mesh_connect_callback, mesh);
+}
+
+static void mesh_peer_change_status_callback(int result,
+                                            GSupplicantInterface *interface,
+                                            void *user_data)
+{
+       struct mesh_change_peer_status_info *data = user_data;
+
+       DBG("result %d Peer Status %d", result, data->peer_status);
+
+       if (result == 0 && data->peer_status == CONNMAN_MESH_PEER_REMOVE) {
+               /* WLAN_REASON_MESH_PEERING_CANCELLED = 52 */
+               connman_mesh_remove_connected_peer(data->peer_address, 52);
+       }
+
+       if (data->callback)
+               data->callback(result, data->user_data);
+
+       g_free(data->peer_address);
+       g_free(data);
+       return;
+}
+
+static int mesh_change_peer_status(const char *peer_address,
+                                  enum connman_mesh_peer_status status,
+                                  mesh_change_peer_status_cb_t callback, void *user_data)
+{
+       GList *list;
+       struct wifi_data *wifi;
+       struct wifi_mesh_info *mesh_info;
+       bool mesh_if_found = false;
+       GSupplicantInterface *interface;
+       struct mesh_change_peer_status_info *data;
+       const char *method;
+
+       for (list = iface_list; list; list = list->next) {
+               wifi = list->data;
+
+               if (wifi->mesh_interface) {
+                       mesh_if_found = true;
+                       break;
+               }
+       }
+
+       if (!mesh_if_found) {
+               DBG("Mesh interface is not created");
+               return -ENODEV;
+       }
+
+       mesh_info = wifi->mesh_info;
+
+       interface = mesh_info->interface;
+
+       switch (status) {
+       case CONNMAN_MESH_PEER_ADD:
+               method = "MeshPeerAdd";
+               break;
+       case CONNMAN_MESH_PEER_REMOVE:
+               method = "MeshPeerRemove";
+               break;
+       default:
+               DBG("Invalid method");
+               return -EINVAL;
+       }
+
+       data = g_try_malloc0(sizeof(struct mesh_change_peer_status_info));
+       if (data == NULL) {
+               DBG("Memory allocation failed");
+               return -ENOMEM;
+       }
+
+       data->peer_address = g_strdup(peer_address);
+       data->peer_status = status;
+       data->callback = callback;
+       data->user_data = user_data;
+
+       return g_supplicant_interface_mesh_peer_change_status(interface,
+                                               mesh_peer_change_status_callback, peer_address, method,
+                                               data);
+}
+
+static struct connman_mesh_driver mesh_driver = {
+       .add_interface      = add_mesh_interface,
+       .remove_interface   = remove_mesh_interface,
+       .connect            = mesh_peer_connect,
+       .disconnect         = mesh_peer_disconnect,
+       .change_peer_status = mesh_change_peer_status,
+};
+
+static void mesh_support(GSupplicantInterface *interface)
+{
+       DBG("");
+
+       if (!g_supplicant_interface_has_mesh(interface))
+               return;
+
+       if (connman_technology_driver_register(&mesh_tech_driver) < 0) {
+               DBG("Could not register Mesh technology driver");
+               return;
+       }
+
+       connman_mesh_driver_register(&mesh_driver);
+}
+
+static void check_mesh_technology(void)
+{
+       bool mesh_exists = false;
+       GList *list;
+
+       for (list = iface_list; list; list = list->next) {
+               struct wifi_data *w = list->data;
+
+               if (w->interface &&
+                               g_supplicant_interface_has_mesh(w->interface))
+                       mesh_exists = true;
+       }
+
+       if (!mesh_exists) {
+               connman_technology_driver_unregister(&mesh_tech_driver);
+               connman_mesh_driver_unregister(&mesh_driver);
+       }
+}
+
+static void mesh_group_started(GSupplicantInterface *interface)
+{
+       struct wifi_data *wifi;
+       struct wifi_mesh_info *mesh_info;
+       struct connman_mesh *mesh;
+       const unsigned char *ssid;
+       unsigned int ssid_len;
+       char name[33];
+
+       ssid = g_supplicant_interface_get_mesh_group_ssid(interface, &ssid_len);
+       memcpy(name, ssid, ssid_len);
+       name[ssid_len] = '\0';
+       DBG("name %s", name);
+       wifi = g_supplicant_interface_get_data(interface);
+       DBG("wifi %p", wifi);
+
+       if (!wifi)
+               return;
+
+       mesh_info = wifi->mesh_info;
+       if (!mesh_info)
+               return;
+
+       mesh = mesh_info->mesh;
+       if (!mesh)
+               return;
+
+       connman_mesh_peer_set_state(mesh, CONNMAN_MESH_STATE_CONFIGURATION);
+}
+
+static void mesh_group_removed(GSupplicantInterface *interface)
+{
+       struct wifi_data *wifi;
+       struct wifi_mesh_info *mesh_info;
+       struct connman_mesh *mesh;
+       const unsigned char *ssid;
+       unsigned int ssid_len;
+       int disconnect_reason;
+       char name[33];
+
+       ssid = g_supplicant_interface_get_mesh_group_ssid(interface, &ssid_len);
+       memcpy(name, ssid, ssid_len);
+       name[ssid_len] = '\0';
+       DBG("name %s", name);
+
+       disconnect_reason = g_supplicant_mesh_get_disconnect_reason(interface);
+       DBG("Disconnect Reason %d", disconnect_reason);
+
+       wifi = g_supplicant_interface_get_data(interface);
+       DBG("wifi %p", wifi);
+
+       if (!wifi)
+               return;
+
+       mesh_info = wifi->mesh_info;
+       if (!mesh_info)
+               return;
+
+       mesh = connman_get_connected_mesh_from_name(name);
+       if (!mesh) {
+               DBG("%s is not connected", name);
+               mesh = connman_get_connecting_mesh_from_name(name);
+               if (!mesh) {
+                       DBG("%s is not connecting", name);
+                       return;
+               }
+       }
+
+       connman_mesh_peer_set_disconnect_reason(mesh, disconnect_reason);
+       connman_mesh_peer_set_state(mesh, CONNMAN_MESH_STATE_DISCONNECT);
+}
+
+static void mesh_peer_connected(GSupplicantMeshPeer *mesh_peer)
+{
+       const char *peer_address;
+
+       peer_address = g_supplicant_mesh_peer_get_address(mesh_peer);
+
+       if (!peer_address)
+               return;
+
+       DBG("Peer %s connected", peer_address);
+       connman_mesh_add_connected_peer(peer_address);
+}
+
+static void mesh_peer_disconnected(GSupplicantMeshPeer *mesh_peer)
+{
+       const char *peer_address;
+       int reason;
+
+       peer_address = g_supplicant_mesh_peer_get_address(mesh_peer);
+
+       if (!peer_address)
+               return;
+
+       reason = g_supplicant_mesh_peer_get_disconnect_reason(mesh_peer);
+
+       DBG("Peer %s disconnected with reason %d", peer_address, reason);
+       connman_mesh_remove_connected_peer(peer_address, reason);
+}
+#endif
+
 static struct wifi_data *get_pending_wifi_data(const char *ifname)
 {
        GList *list;
@@ -552,6 +1202,11 @@ static void register_peer_service_cb(int result,
        struct wifi_data *wifi = g_supplicant_interface_get_data(iface);
        struct peer_service_registration *reg_data = user_data;
 
+#if defined TIZEN_EXT
+       if (!wifi)
+               return;
+#endif
+
        DBG("");
 
        if (result == 0)
@@ -876,6 +1531,35 @@ static void check_p2p_technology(void)
        }
 }
 
+struct last_connected {
+       GTimeVal modified;
+       gchar *ssid;
+       int freq;
+};
+
+static gint sort_entry(gconstpointer a, gconstpointer b, gpointer user_data)
+{
+       GTimeVal *aval = (GTimeVal *)a;
+       GTimeVal *bval = (GTimeVal *)b;
+
+       /* Note that the sort order is descending */
+       if (aval->tv_sec < bval->tv_sec)
+               return 1;
+
+       if (aval->tv_sec > bval->tv_sec)
+               return -1;
+
+       return 0;
+}
+
+static void free_entry(gpointer data)
+{
+       struct last_connected *entry = data;
+
+       g_free(entry->ssid);
+       g_free(entry);
+}
+
 static void wifi_remove(struct connman_device *device)
 {
        struct wifi_data *wifi = connman_device_get_data(device);
@@ -893,6 +1577,9 @@ static void wifi_remove(struct connman_device *device)
                iface_list = g_list_remove(iface_list, wifi);
 
        check_p2p_technology();
+#if defined TIZEN_EXT_WIFI_MESH
+       check_mesh_technology();
+#endif
 
        remove_pending_wifi_device(wifi);
 
@@ -904,6 +1591,13 @@ static void wifi_remove(struct connman_device *device)
        if (wifi->p2p_connection_timeout)
                g_source_remove(wifi->p2p_connection_timeout);
 
+#if defined TIZEN_EXT
+       if (wifi->automaxspeed_timeout != 0) {
+               g_source_remove(wifi->automaxspeed_timeout);
+               wifi->automaxspeed_timeout = 0;
+       }
+#endif
+
        remove_networks(device, wifi);
        remove_peers(wifi);
 
@@ -918,6 +1612,16 @@ static void wifi_remove(struct connman_device *device)
 
        if (wifi->scan_params)
                g_supplicant_free_scan_params(wifi->scan_params);
+#if defined TIZEN_EXT
+       if (wifi->hidden_scan_params) {
+               while (wifi->hidden_scan_params->ssids) {
+                       struct scan_ssid *ssid;
+                       ssid = wifi->hidden_scan_params->ssids->data;
+                       wifi->hidden_scan_params->ssids = g_slist_remove(wifi->hidden_scan_params->ssids, ssid);
+               }
+               g_supplicant_free_scan_params(wifi->hidden_scan_params);
+       }
+#endif
 
        g_free(wifi->autoscan);
        g_free(wifi->identifier);
@@ -1043,12 +1747,25 @@ static int get_hidden_connections(GSupplicantScanParams *scan_data)
 {
        struct connman_config_entry **entries;
        GKeyFile *keyfile;
+#if defined TIZEN_EXT
+       gchar **services = NULL;
+#else
        gchar **services;
+#endif /* defined TIZEN_EXT */
        char *ssid, *name;
        int i, ret;
        bool value;
        int num_ssids = 0, add_param_failed = 0;
+#if defined TIZEN_EXT
+       GSequenceIter *iter;
+       GSequence *latest_list;
+       struct last_connected *entry;
+       GTimeVal modified;
 
+       latest_list = g_sequence_new(free_entry);
+       if (!latest_list)
+               goto out;
+#endif
        services = connman_storage_get_services();
        for (i = 0; services && services[i]; i++) {
                if (strncmp(services[i], "wifi_", 5) != 0)
@@ -1072,12 +1789,46 @@ static int get_hidden_connections(GSupplicantScanParams *scan_data)
                        continue;
                }
 
+#if defined TIZEN_EXT
+               value = g_key_file_get_boolean(keyfile,
+                                       services[i], "AutoConnect", NULL);
+               if (!value) {
+                       g_key_file_free(keyfile);
+                       continue;
+               }
+
+               gchar *str = g_key_file_get_string(keyfile,
+                                       services[i], "Modified", NULL);
+               if (!str) {
+                       g_key_file_free(keyfile);
+                       continue;
+               }
+               g_time_val_from_iso8601(str, &modified);
+               g_free(str);
+#endif
+
                ssid = g_key_file_get_string(keyfile,
                                        services[i], "SSID", NULL);
 
                name = g_key_file_get_string(keyfile, services[i], "Name",
                                                                NULL);
 
+#if defined TIZEN_EXT
+               entry = g_try_new(struct last_connected, 1);
+               if (!entry) {
+                       g_sequence_free(latest_list);
+                       g_free(ssid);
+                       g_free(name);
+                       g_key_file_free(keyfile);
+                       goto out;
+               }
+
+               entry->modified = modified;
+               entry->ssid = ssid;
+
+               g_sequence_insert_sorted(latest_list, entry,
+                               sort_entry, NULL);
+#else
                ret = add_scan_param(ssid, NULL, 0, 0, scan_data, 0, name);
                if (ret < 0)
                        add_param_failed++;
@@ -1085,10 +1836,30 @@ static int get_hidden_connections(GSupplicantScanParams *scan_data)
                        num_ssids++;
 
                g_free(ssid);
+#endif
                g_free(name);
                g_key_file_free(keyfile);
        }
 
+#if defined TIZEN_EXT
+       gint length = g_sequence_get_length(latest_list);
+       iter = g_sequence_get_begin_iter(latest_list);
+
+       for (i = 0; i < length; i++) {
+               entry = g_sequence_get(iter);
+
+               ret = add_scan_param(entry->ssid, NULL, 0, 0, scan_data, 0, entry->ssid);
+               if (ret < 0)
+                       add_param_failed++;
+               else if (ret > 0)
+                       num_ssids++;
+
+               iter = g_sequence_iter_next(iter);
+       }
+
+       g_sequence_free(latest_list);
+out:
+#endif
        /*
         * Check if there are any hidden AP that needs to be provisioned.
         */
@@ -1145,6 +1916,22 @@ static int get_hidden_connections_params(struct wifi_data *wifi,
 
        DBG("max ssids %d", driver_max_ssids);
 
+#if defined TIZEN_EXT
+       if (!wifi->hidden_scan_params) {
+               wifi->hidden_scan_params = g_try_malloc0(sizeof(GSupplicantScanParams));
+               if (!wifi->hidden_scan_params)
+                       return 0;
+
+               if (get_hidden_connections(wifi->hidden_scan_params) == 0) {
+                       g_supplicant_free_scan_params(wifi->hidden_scan_params);
+                       wifi->hidden_scan_params = NULL;
+
+                       return 0;
+               }
+       }
+
+       orig_params = wifi->hidden_scan_params;
+#else
        if (!wifi->scan_params) {
                wifi->scan_params = g_try_malloc0(sizeof(GSupplicantScanParams));
                if (!wifi->scan_params)
@@ -1159,12 +1946,17 @@ static int get_hidden_connections_params(struct wifi_data *wifi,
        }
 
        orig_params = wifi->scan_params;
+#endif
 
        /* Let's transfer driver_max_ssids params */
        for (i = 0; i < driver_max_ssids; i++) {
                struct scan_ssid *ssid;
 
+#if defined TIZEN_EXT
+               if (!wifi->hidden_scan_params->ssids)
+#else
                if (!wifi->scan_params->ssids)
+#endif
                        break;
 
                ssid = orig_params->ssids->data;
@@ -1192,8 +1984,13 @@ static int get_hidden_connections_params(struct wifi_data *wifi,
 
 err:
        g_slist_free_full(scan_params->ssids, g_free);
+#if defined TIZEN_EXT
+       g_supplicant_free_scan_params(wifi->hidden_scan_params);
+       wifi->hidden_scan_params = NULL;
+#else
        g_supplicant_free_scan_params(wifi->scan_params);
        wifi->scan_params = NULL;
+#endif
 
        return 0;
 }
@@ -1212,7 +2009,12 @@ static int throw_wifi_scan(struct connman_device *device,
        if (wifi->tethering)
                return -EBUSY;
 
+#if defined TIZEN_EXT
+       if (connman_device_get_scanning(device, CONNMAN_SERVICE_TYPE_WIFI)
+           && !wifi->allow_full_scan)
+#else
        if (connman_device_get_scanning(device, CONNMAN_SERVICE_TYPE_WIFI))
+#endif
                return -EALREADY;
 
        connman_device_ref(device);
@@ -1241,12 +2043,60 @@ static void hidden_free(struct hidden_params *hidden)
        g_free(hidden);
 }
 
+#if defined TIZEN_EXT
+static void service_state_changed(struct connman_service *service,
+                                       enum connman_service_state state);
+
+static int network_connect(struct connman_network *network);
+
+static struct connman_notifier notifier = {
+       .name                   = "wifi",
+       .priority               = CONNMAN_NOTIFIER_PRIORITY_DEFAULT,
+       .service_state_changed  = service_state_changed,
+};
+
+static void service_state_changed(struct connman_service *service,
+                                       enum connman_service_state state)
+{
+       enum connman_service_type type;
+
+       type = connman_service_get_type(service);
+       if (type != CONNMAN_SERVICE_TYPE_WIFI)
+               return;
+
+       DBG("service %p state %d", service, state);
+
+       switch (state) {
+       case CONNMAN_SERVICE_STATE_READY:
+       case CONNMAN_SERVICE_STATE_ONLINE:
+       case CONNMAN_SERVICE_STATE_FAILURE:
+               connman_notifier_unregister(&notifier);
+               is_wifi_notifier_registered = FALSE;
+
+               __connman_device_request_scan(type);
+               break;
+
+       default:
+               break;
+       }
+}
+
+static void scan_callback_hidden(int result,
+                       GSupplicantInterface *interface, void *user_data);
+#endif
+
 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);
        bool scanning;
+#if defined TIZEN_EXT
+       GSList *list = NULL;
+       bool favorite_exists = false;
+       struct connman_network *network = NULL;
+       struct connman_service *service = NULL;
+#endif
 
        DBG("result %d wifi %p", result, wifi);
 
@@ -1261,6 +2111,13 @@ static void scan_callback(int result, GSupplicantInterface *interface,
                        g_supplicant_free_scan_params(wifi->scan_params);
                        wifi->scan_params = NULL;
                }
+
+#if defined TIZEN_EXT
+               if (wifi->hidden_scan_params && !wifi->hidden_scan_params->ssids) {
+                       g_supplicant_free_scan_params(wifi->hidden_scan_params);
+                       wifi->hidden_scan_params = NULL;
+               }
+#endif
        }
 
        if (result < 0)
@@ -1286,6 +2143,39 @@ static void scan_callback(int result, GSupplicantInterface *interface,
                return scan_callback(ret, interface, user_data);
        }
 
+#if defined TIZEN_EXT
+       if (wifi) {
+               for (list = wifi->networks; list; list = list->next) {
+                       network = list->data;
+                       service = connman_service_lookup_from_network(network);
+
+                       if (service != NULL &&
+                               (connman_service_get_favorite(service) == true) &&
+                               (connman_service_get_autoconnect(service) == true)) {
+                               DBG("Favorite service exists [%s]", connman_network_get_string(network, "Name"));
+                               favorite_exists = true;
+                               break;
+                       }
+               }
+       }
+
+       if (favorite_exists == false) {
+               if (wifi && wifi->allow_full_scan) {
+                       int ret;
+                       DBG("Trigger full channel scan");
+                       wifi->allow_full_scan = false;
+
+                       ret = g_supplicant_interface_scan(wifi->interface, NULL,
+                                                               scan_callback_hidden, device);
+                       if (ret == 0)
+                               return;
+
+                       /* On error, let's recall scan_callback, which will cleanup */
+                       return scan_callback(ret, interface, user_data);
+               }
+       }
+#endif
+
        scanning = connman_device_get_scanning(device, CONNMAN_SERVICE_TYPE_WIFI);
 
        if (scanning) {
@@ -1294,6 +2184,9 @@ static void scan_callback(int result, GSupplicantInterface *interface,
        }
 
        if (result != -ENOLINK)
+#if defined TIZEN_EXT
+       if (result != -EIO)
+#endif
                start_autoscan(device);
 
        /*
@@ -1305,6 +2198,23 @@ static void scan_callback(int result, GSupplicantInterface *interface,
 
        if (scanning)
                connman_device_unref(device);
+
+#if defined TIZEN_EXT
+       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 &&
+                       wifi_first_scan == true && found_with_first_scan == true) {
+               wifi_first_scan = false;
+               found_with_first_scan = false;
+
+               connman_notifier_register(&notifier);
+               is_wifi_notifier_registered = true;
+       }
+#endif
 }
 
 static void scan_callback_hidden(int result,
@@ -1331,7 +2241,11 @@ static void scan_callback_hidden(int result,
        if (get_hidden_connections_params(wifi, scan_params) > 0) {
                ret = g_supplicant_interface_scan(wifi->interface,
                                                        scan_params,
+#if defined TIZEN_EXT
+                                                       scan_callback,
+#else
                                                        scan_callback_hidden,
+#endif
                                                        device);
                if (ret == 0)
                        return;
@@ -1355,13 +2269,22 @@ static gboolean autoscan_timeout(gpointer data)
 
        autoscan = wifi->autoscan;
 
+#if defined TIZEN_EXT
+       if (!autoscan)
+               return FALSE;
+#endif
+
        if (autoscan->interval <= 0) {
                interval = autoscan->base;
                goto set_interval;
        } else
                interval = autoscan->interval * autoscan->base;
 
+#if defined TIZEN_EXT
+       if (autoscan->interval >= autoscan->limit)
+#else
        if (interval > autoscan->limit)
+#endif
                interval = autoscan->limit;
 
        throw_wifi_scan(wifi->device, scan_callback_hidden);
@@ -1472,6 +2395,18 @@ static void setup_autoscan(struct wifi_data *wifi)
                wifi->autoscan = parse_autoscan_params(AUTOSCAN_EXPONENTIAL);
                return;
        }
+#if defined TIZEN_EXT
+       else {
+               if (wifi->autoscan) {
+                       g_free(wifi->autoscan);
+                       wifi->autoscan = NULL;
+               }
+
+               DBG("BackgroundScanning is disabled");
+
+               return;
+       }
+#endif
 
        /*
         * On the contrary, if BackgroundScanning is disabled, update autoscan
@@ -1584,7 +2519,9 @@ static int wifi_disable(struct connman_device *device)
        if (wifi->pending_network)
                wifi->pending_network = NULL;
 
+#if !defined TIZEN_EXT
        stop_autoscan(device);
+#endif
 
        if (connman_device_get_scanning(device, CONNMAN_SERVICE_TYPE_P2P)) {
                g_source_remove(wifi->p2p_find_timeout);
@@ -1593,6 +2530,13 @@ static int wifi_disable(struct connman_device *device)
                connman_device_unref(wifi->device);
        }
 
+#if defined TIZEN_EXT
+       if (wifi->automaxspeed_timeout != 0) {
+               g_source_remove(wifi->automaxspeed_timeout);
+               wifi->automaxspeed_timeout = 0;
+       }
+#endif
+
        /* In case of a user scan, device is still referenced */
        if (connman_device_get_scanning(device, CONNMAN_SERVICE_TYPE_WIFI)) {
                connman_device_set_scanning(device,
@@ -1600,9 +2544,22 @@ static int wifi_disable(struct connman_device *device)
                connman_device_unref(wifi->device);
        }
 
+#if defined TIZEN_EXT
+       stop_autoscan(device);
+#endif
+
        remove_networks(device, wifi);
        remove_peers(wifi);
 
+#if defined TIZEN_EXT
+       wifi->scan_pending_network = NULL;
+
+       if (is_wifi_notifier_registered == true) {
+               connman_notifier_unregister(&notifier);
+               is_wifi_notifier_registered = false;
+       }
+#endif
+
        ret = g_supplicant_interface_remove(wifi->interface, NULL, NULL);
        if (ret < 0)
                return ret;
@@ -1610,35 +2567,6 @@ static int wifi_disable(struct connman_device *device)
        return -EINPROGRESS;
 }
 
-struct last_connected {
-       GTimeVal modified;
-       gchar *ssid;
-       int freq;
-};
-
-static gint sort_entry(gconstpointer a, gconstpointer b, gpointer user_data)
-{
-       GTimeVal *aval = (GTimeVal *)a;
-       GTimeVal *bval = (GTimeVal *)b;
-
-       /* Note that the sort order is descending */
-       if (aval->tv_sec < bval->tv_sec)
-               return 1;
-
-       if (aval->tv_sec > bval->tv_sec)
-               return -1;
-
-       return 0;
-}
-
-static void free_entry(gpointer data)
-{
-       struct last_connected *entry = data;
-
-       g_free(entry->ssid);
-       g_free(entry);
-}
-
 static int get_latest_connections(int max_ssids,
                                GSupplicantScanParams *scan_data)
 {
@@ -1849,6 +2777,341 @@ static int p2p_find(struct connman_device *device)
        return ret;
 }
 
+#if defined TIZEN_EXT
+static void specific_scan_callback(int result, GSupplicantInterface *interface,
+                                               void *user_data)
+{
+       struct connman_device *device = user_data;
+       struct wifi_data *wifi = connman_device_get_data(device);
+       bool scanning;
+
+       DBG("result %d wifi %p", result, wifi);
+
+       if (wifi && wifi->scan_params) {
+               g_supplicant_free_scan_params(wifi->scan_params);
+               wifi->scan_params = NULL;
+       }
+
+       scanning = connman_device_get_scanning(device,
+                                              CONNMAN_SERVICE_TYPE_WIFI);
+       if (scanning) {
+               connman_device_set_scanning(device,
+                               CONNMAN_SERVICE_TYPE_WIFI, false);
+               connman_device_unref(device);
+       }
+}
+
+static int wifi_specific_scan(enum connman_service_type type,
+                       struct connman_device *device, int scan_type,
+                       GSList *specific_scan_list, void *user_data)
+{
+       GSList *list = NULL;
+       char *ssid = NULL;
+       struct wifi_data *wifi = connman_device_get_data(device);
+       GSupplicantScanParams *scan_params = NULL;
+       struct scan_ssid *scan_ssid = NULL;
+       bool scanning;
+       int ret;
+       int freq;
+       int count = 0;
+
+       if (!wifi)
+               return -ENODEV;
+
+       if (wifi->p2p_device)
+               return 0;
+
+       if (type == CONNMAN_SERVICE_TYPE_P2P)
+               return p2p_find(device);
+
+       if (wifi->tethering)
+               return 0;
+
+       scanning =
+               connman_device_get_scanning(device,
+                                           CONNMAN_SERVICE_TYPE_WIFI);
+       if (scanning)
+               return -EALREADY;
+
+       DBG("scan_type: %d", scan_type);
+       if (scan_type == CONNMAN_MULTI_SCAN_SSID) { /* ssid based scan */
+               scan_params = g_try_malloc0(sizeof(GSupplicantScanParams));
+               if (!scan_params) {
+                       DBG("Failed to allocate memory.");
+                       return -ENOMEM;
+               }
+
+               for (list = specific_scan_list; list; list = list->next) {
+                       ssid = (char *)list->data;
+                       int ssid_len = strlen(ssid);
+
+                       scan_ssid = g_try_new0(struct scan_ssid, 1);
+                       if (!scan_ssid) {
+                               DBG("Failed to allocate memory.");
+                               g_supplicant_free_scan_params(scan_params);
+                               return -ENOMEM;
+                       }
+
+                       memcpy(scan_ssid->ssid, ssid, (ssid_len + 1));
+                       /* DBG("scan ssid %s len: %d", scan_ssid->ssid, ssid_len); */
+                       scan_ssid->ssid_len = ssid_len;
+                       scan_params->ssids = g_slist_prepend(scan_params->ssids, scan_ssid);
+                       count++;
+               }
+               scan_params->num_ssids = count;
+
+       } else if (scan_type == CONNMAN_MULTI_SCAN_FREQ) { /* frequency based scan */
+
+               scan_params = g_try_malloc0(sizeof(GSupplicantScanParams));
+               if (!scan_params) {
+                       DBG("Failed to allocate memory.");
+                       return -ENOMEM;
+               }
+
+               guint num_freqs = g_slist_length(specific_scan_list);
+               DBG("num_freqs: %d", num_freqs);
+
+               scan_params->freqs = g_try_new0(uint16_t, num_freqs);
+               if (!scan_params->freqs) {
+                       DBG("Failed to allocate memory.");
+                       g_free(scan_params);
+                       return -ENOMEM;
+               }
+
+               count = 0;
+               for (list = specific_scan_list; list; list = list->next) {
+                       freq = (int)list->data;
+
+                       scan_params->freqs[count] = freq;
+                       DBG("scan_params->freqs[%d]: %d", count, scan_params->freqs[count]);
+                       count++;
+               }
+               scan_params->num_freqs = count;
+
+       } else if (scan_type == CONNMAN_MULTI_SCAN_SSID_FREQ) { /* SSID & Frequency mixed scan */
+               int freq_count, ap_count;
+               scan_params = g_try_malloc0(sizeof(GSupplicantScanParams));
+               if (!scan_params) {
+                       DBG("Failed to allocate memory.");
+                       return -ENOMEM;
+               }
+
+               guint size = g_slist_length(specific_scan_list);
+
+               scan_params->freqs = g_try_new0(uint16_t, size/2);
+               if (!scan_params->freqs) {
+                       DBG("Failed to allocate memory.");
+                       g_free(scan_params);
+                       return -ENOMEM;
+               }
+
+               ap_count = freq_count = 0;
+               for (list = specific_scan_list; list; list = list->next) {
+                       if (((connman_multi_scan_ap_s *)list->data)->flag == true) { /** ssid */
+                               ssid = ((connman_multi_scan_ap_s *)list->data)->str;
+                               int ssid_len = strlen(ssid);
+
+                               scan_ssid = g_try_new0(struct scan_ssid, 1);
+                               if (!scan_ssid) {
+                                       DBG("Failed to allocate memory.");
+                                       g_supplicant_free_scan_params(scan_params);
+                                       return -ENOMEM;
+                               }
+
+                               memcpy(scan_ssid->ssid, ssid, (ssid_len + 1));
+                               /* DBG("scan ssid %s len: %d", scan_ssid->ssid, ssid_len); */
+                               scan_ssid->ssid_len = ssid_len;
+                               scan_params->ssids = g_slist_prepend(scan_params->ssids, scan_ssid);
+                               ap_count++;
+
+                       } else { /* freq */
+                               freq = atoi(((connman_multi_scan_ap_s *)list->data)->str);
+                               scan_params->freqs[freq_count] = freq;
+                               DBG("scan_params->freqs[%d]: %d", freq_count, scan_params->freqs[freq_count]);
+                               freq_count++;
+                       }
+               }
+               scan_params->num_ssids = ap_count;
+               scan_params->num_freqs = freq_count;
+       } else {
+               DBG("Invalid scan");
+               return -EINVAL;
+       }
+
+       reset_autoscan(device);
+       connman_device_ref(device);
+
+       ret = g_supplicant_interface_scan(wifi->interface, scan_params,
+                                               specific_scan_callback, device);
+
+       if (ret == 0) {
+               connman_device_set_scanning(device,
+                               CONNMAN_SERVICE_TYPE_WIFI, true);
+       } else {
+               g_supplicant_free_scan_params(scan_params);
+               connman_device_unref(device);
+       }
+
+       return ret;
+}
+#endif
+
+#if defined TIZEN_EXT_WIFI_MESH
+static void mesh_scan_callback(int result, GSupplicantInterface *interface,
+                                               void *user_data)
+{
+       struct connman_device *device = user_data;
+       struct wifi_data *wifi = connman_device_get_data(device);
+       bool scanning;
+
+       DBG("result %d wifi %p", result, wifi);
+
+       scanning = connman_device_get_scanning(device,
+                                              CONNMAN_SERVICE_TYPE_MESH);
+       if (scanning)
+               connman_device_set_scanning(device,
+                               CONNMAN_SERVICE_TYPE_MESH, false);
+
+       if (scanning)
+               connman_device_unref(device);
+}
+
+static int mesh_scan(struct connman_device *device)
+{
+       struct wifi_data *wifi;
+       struct wifi_mesh_info *mesh_info;
+       int ret;
+
+       DBG("");
+
+       wifi = connman_device_get_data(device);
+
+       if (!wifi || !wifi->mesh_interface)
+               return -ENOTSUP;
+
+       mesh_info = wifi->mesh_info;
+       reset_autoscan(device);
+       connman_device_ref(device);
+
+       ret = g_supplicant_interface_scan(mesh_info->interface, NULL,
+                                               mesh_scan_callback, device);
+       if (ret)
+               connman_device_unref(device);
+       else
+               connman_device_set_scanning(device,
+                               CONNMAN_SERVICE_TYPE_MESH, true);
+
+       return ret;
+}
+
+static void abort_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 wifi %p", result, wifi);
+
+       __connman_technology_notify_abort_scan(CONNMAN_SERVICE_TYPE_MESH, result);
+}
+
+static int mesh_abort_scan(enum connman_service_type type,
+                                               struct connman_device *device)
+{
+       struct wifi_data *wifi = connman_device_get_data(device);
+       struct wifi_mesh_info *mesh_info;
+       bool scanning;
+       int ret;
+
+       if (!wifi || !wifi->mesh_interface)
+               return -ENODEV;
+
+       if (type != CONNMAN_SERVICE_TYPE_MESH)
+               return -EINVAL;
+
+       mesh_info = wifi->mesh_info;
+
+       scanning = connman_device_get_scanning(device,
+                                              CONNMAN_SERVICE_TYPE_MESH);
+       if (!scanning)
+               return -EEXIST;
+
+       ret = g_supplicant_interface_abort_scan(mesh_info->interface,
+                                               abort_scan_callback, device);
+
+       return ret;
+}
+
+static int mesh_specific_scan(enum connman_service_type type,
+                             struct connman_device *device, const char *ssid,
+                             unsigned int freq, void *user_data)
+{
+       struct wifi_data *wifi = connman_device_get_data(device);
+       GSupplicantScanParams *scan_params = NULL;
+       struct wifi_mesh_info *mesh_info;
+       struct scan_ssid *scan_ssid;
+       bool scanning;
+       int ret;
+
+       if (!wifi || !wifi->mesh_interface)
+               return -ENODEV;
+
+       if (type != CONNMAN_SERVICE_TYPE_MESH)
+               return -EINVAL;
+
+       if (wifi->p2p_device)
+               return 0;
+
+       mesh_info = wifi->mesh_info;
+
+       scanning = connman_device_get_scanning(device,
+                                              CONNMAN_SERVICE_TYPE_MESH);
+       if (scanning)
+               return -EALREADY;
+
+       scan_params = g_try_malloc0(sizeof(GSupplicantScanParams));
+       if (!scan_params)
+               return -ENOMEM;
+
+       scan_ssid = g_try_new(struct scan_ssid, 1);
+       if (!scan_ssid) {
+               g_free(scan_params);
+               return -ENOMEM;
+       }
+
+       scan_ssid->ssid_len = strlen(ssid);
+       memcpy(scan_ssid->ssid, ssid, scan_ssid->ssid_len);
+       scan_params->ssids = g_slist_prepend(scan_params->ssids, scan_ssid);
+       scan_params->num_ssids = 1;
+
+       scan_params->freqs = g_try_new(uint16_t, 1);
+       if (!scan_params->freqs) {
+               g_slist_free_full(scan_params->ssids, g_free);
+               g_free(scan_params);
+               return -ENOMEM;
+       }
+
+       scan_params->freqs[0] = freq;
+       scan_params->num_freqs = 1;
+
+       reset_autoscan(device);
+       connman_device_ref(device);
+
+       ret = g_supplicant_interface_scan(mesh_info->interface, scan_params,
+                                               mesh_scan_callback, device);
+
+       if (ret == 0) {
+               connman_device_set_scanning(device,
+                               CONNMAN_SERVICE_TYPE_MESH, true);
+       } else {
+               g_supplicant_free_scan_params(scan_params);
+               connman_device_unref(device);
+       }
+
+       return ret;
+}
+#endif
+
 /*
  * 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.
@@ -1877,6 +3140,11 @@ static int wifi_scan(struct connman_device *device,
        if (params->type == CONNMAN_SERVICE_TYPE_P2P)
                return p2p_find(device);
 
+#if defined TIZEN_EXT_WIFI_MESH
+       if (params->type == CONNMAN_SERVICE_TYPE_MESH)
+               return mesh_scan(device);
+#endif
+
        DBG("device %p wifi %p hidden ssid %s", device, wifi->interface,
                params->ssid);
 
@@ -1961,12 +3229,32 @@ static int wifi_scan(struct connman_device *device,
        connman_device_ref(device);
 
        reset_autoscan(device);
-
+#if defined TIZEN_EXT
+       /*
+        * When doing a full scan, stored hidden networks also need to be scanned
+        * so that we can autoconnect to them.
+        */
+       if (params->force_full_scan)
+               ret = g_supplicant_interface_scan(wifi->interface, scan_params,
+                                                       scan_callback_hidden, device);
+       else
+#endif
        ret = g_supplicant_interface_scan(wifi->interface, scan_params,
                                                scan_callback, device);
        if (ret == 0) {
                connman_device_set_scanning(device,
                                CONNMAN_SERVICE_TYPE_WIFI, true);
+#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.
+                */
+               if (!params->force_full_scan && !do_hidden)
+                       wifi->allow_full_scan = TRUE;
+#endif
        } else {
                g_supplicant_free_scan_params(scan_params);
                connman_device_unref(device);
@@ -2039,6 +3327,13 @@ static struct connman_device_driver wifi_ng_driver = {
        .scan           = wifi_scan,
        .stop_scan      = wifi_stop_scan,
        .set_regdom     = wifi_set_regdom,
+#if defined TIZEN_EXT
+       .specific_scan  = wifi_specific_scan,
+#endif
+#if defined TIZEN_EXT_WIFI_MESH
+       .abort_scan     = mesh_abort_scan,
+       .mesh_specific_scan     = mesh_specific_scan,
+#endif
 };
 
 static void system_ready(void)
@@ -2078,15 +3373,45 @@ static void network_remove(struct connman_network *network)
                return;
 
        wifi->network = NULL;
+
+#if defined TIZEN_EXT
+       wifi->disconnecting = false;
+
+       if (wifi->pending_network == network)
+               wifi->pending_network = NULL;
+
+       if (wifi->scan_pending_network == network)
+               wifi->scan_pending_network = NULL;
+#endif
 }
 
 static void connect_callback(int result, GSupplicantInterface *interface,
                                                        void *user_data)
 {
+#if defined TIZEN_EXT
+       GList *list;
+       struct wifi_data *wifi;
+#endif
        struct connman_network *network = user_data;
 
        DBG("network %p result %d", network, result);
 
+#if defined TIZEN_EXT
+       const char *ifname = g_supplicant_interface_get_ifname(interface);
+       set_connman_bssid(RESET_BSSID, NULL, ifname);
+
+       for (list = iface_list; list; list = list->next) {
+               wifi = list->data;
+
+               if (wifi && wifi->network == network)
+                       goto found;
+       }
+
+       /* wifi_data may be invalid because wifi is already disabled */
+       return;
+
+found:
+#endif
        if (result == -ENOKEY) {
                connman_network_set_error(network,
                                        CONNMAN_NETWORK_ERROR_INVALID_KEY);
@@ -2112,21 +3437,65 @@ 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;
+       else if (g_str_equal(security, "sae"))
+               return G_SUPPLICANT_SECURITY_SAE;
+       else if (g_str_equal(security, "owe"))
+               return G_SUPPLICANT_SECURITY_OWE;
+       else if (g_str_equal(security, "dpp"))
+               return G_SUPPLICANT_SECURITY_DPP;
+#endif
 
        return G_SUPPLICANT_SECURITY_UNKNOWN;
 }
 
+#if defined TIZEN_EXT
+static GSupplicantEapKeymgmt network_eap_keymgmt(const char *security)
+{
+       if (security == NULL)
+               return G_SUPPLICANT_EAP_KEYMGMT_NONE;
+
+       if (g_str_equal(security, "FT") == TRUE)
+               return G_SUPPLICANT_EAP_KEYMGMT_FT;
+       else if (g_str_equal(security, "CCKM") == TRUE)
+               return G_SUPPLICANT_EAP_KEYMGMT_CCKM;
+
+       return G_SUPPLICANT_EAP_KEYMGMT_NONE;
+}
+#endif
+
 static void ssid_init(GSupplicantSSID *ssid, struct connman_network *network)
 {
        const char *security;
+#if defined TIZEN_EXT
+       const void *ssid_data;
+#endif
 
        memset(ssid, 0, sizeof(*ssid));
        ssid->mode = G_SUPPLICANT_MODE_INFRA;
+#if defined TIZEN_EXT
+       ssid_data = connman_network_get_blob(network, "WiFi.SSID",
+                                               &ssid->ssid_len);
+       ssid->ssid = g_try_malloc0(ssid->ssid_len);
+
+       if (!ssid->ssid)
+               ssid->ssid_len = 0;
+       else
+               memcpy(ssid->ssid, ssid_data, ssid->ssid_len);
+#else
        ssid->ssid = connman_network_get_blob(network, "WiFi.SSID",
                                                &ssid->ssid_len);
+#endif
        ssid->scan_ssid = 1;
        security = connman_network_get_string(network, "WiFi.Security");
        ssid->security = network_security(security);
+#if defined TIZEN_EXT
+       ssid->ieee80211w = 1;
+#endif
        ssid->passphrase = connman_network_get_string(network,
                                                "WiFi.Passphrase");
 
@@ -2172,6 +3541,84 @@ static void ssid_init(GSupplicantSSID *ssid, struct connman_network *network)
 
        ssid->use_wps = connman_network_get_bool(network, "WiFi.UseWPS");
        ssid->pin_wps = connman_network_get_string(network, "WiFi.PinWPS");
+#if defined TIZEN_EXT
+       ssid->connector = connman_network_get_string(network,
+                                                       "WiFi.Connector");
+       ssid->c_sign_key = connman_network_get_string(network,
+                                                       "WiFi.CSignKey");
+       ssid->net_access_key = connman_network_get_string(network,
+                                               "WiFi.NetAccessKey");
+#endif
+
+#if defined TIZEN_EXT
+       const char *ifname = connman_device_get_string(
+                       connman_network_get_device(network), "Interface");
+       if (set_connman_bssid(CHECK_BSSID, NULL, ifname) == 6) {
+               ssid->bssid_for_connect_len = 6;
+               set_connman_bssid(GET_BSSID, (char *)ssid->bssid_for_connect, ifname);
+               DBG("BSSID : %02x:%02x:%02x:%02x:%02x:%02x",
+                       ssid->bssid_for_connect[0], ssid->bssid_for_connect[1],
+                       ssid->bssid_for_connect[2], ssid->bssid_for_connect[3],
+                       ssid->bssid_for_connect[4], ssid->bssid_for_connect[5]);
+       } else {
+               ssid->freq = connman_network_get_frequency(network);
+       }
+
+       GSList *bssid_list = (GSList *)connman_network_get_bssid_list(network);
+       if (bssid_list && g_slist_length(bssid_list) > 1) {
+
+               /* If there are more than one bssid,
+                * the user-specified bssid is tried only once at the beginning.
+                * After that, the bssids in the list are tried in order.
+                */
+               if (set_connman_bssid(CHECK_BSSID, NULL, ifname) == 6) {
+                       set_connman_bssid(RESET_BSSID, NULL, ifname);
+                       goto done;
+               }
+
+               GSList *list;
+               char buff[MAC_ADDRESS_LENGTH];
+               for (list = bssid_list; list; list = list->next) {
+                       struct connman_bssids * bssids = (struct connman_bssids *)list->data;
+
+                       g_snprintf(buff, MAC_ADDRESS_LENGTH, "%02x:%02x:%02x:%02x:%02x:%02x",
+                                       bssids->bssid[0], bssids->bssid[1], bssids->bssid[2],
+                                       bssids->bssid[3], bssids->bssid[4], bssids->bssid[5]);
+                       buff[MAC_ADDRESS_LENGTH - 1] = '\0';
+
+                       gchar *curr_bssid = g_strdup((const gchar *)buff);
+
+                       if (g_hash_table_contains(failed_bssids, curr_bssid)) {
+                               DBG("bssid match, try next bssid");
+                               g_free(curr_bssid);
+                               continue;
+                       } else {
+                               g_hash_table_add(failed_bssids, curr_bssid);
+
+                               memcpy(buff_bssid, bssids->bssid, WIFI_BSSID_LEN_MAX);
+                               ssid->bssid = buff_bssid;
+                               ssid->freq = (unsigned int)bssids->frequency;
+                               break;
+                       }
+               }
+
+               if (!list) {
+                       ssid->bssid = connman_network_get_bssid(network);
+                       g_hash_table_remove_all(failed_bssids);
+               }
+       } else
+               ssid->bssid = connman_network_get_bssid(network);
+
+done:
+       ssid->eap_keymgmt = network_eap_keymgmt(
+                       connman_network_get_string(network, "WiFi.KeymgmtType"));
+       ssid->phase1 = connman_network_get_string(network, "WiFi.Phase1");
+
+       if(g_strcmp0(ssid->eap, "fast") == 0)
+               ssid->pac_file = g_strdup(WIFI_EAP_FAST_PAC_FILE);
+
+       ssid->keymgmt = connman_network_get_keymgmt(network);
+#endif
 
        if (connman_setting_get_bool("BackgroundScanning"))
                ssid->bgscan = BGSCAN_DEFAULT;
@@ -2203,10 +3650,16 @@ static int network_connect(struct connman_network *network)
 
        if (wifi->disconnecting) {
                wifi->pending_network = network;
+#if defined TIZEN_EXT
+               g_free(ssid->ssid);
+#endif
                g_free(ssid);
        } else {
                wifi->network = connman_network_ref(network);
                wifi->retries = 0;
+#if defined TIZEN_EXT
+               wifi->scan_pending_network = NULL;
+#endif
 
                return g_supplicant_interface_connect(interface, ssid,
                                                connect_callback, network);
@@ -2218,7 +3671,30 @@ static int network_connect(struct connman_network *network)
 static void disconnect_callback(int result, GSupplicantInterface *interface,
                                                                void *user_data)
 {
+#if defined TIZEN_EXT
+       GList *list;
+       struct wifi_data *wifi;
+       struct connman_network *network = user_data;
+
+       DBG("network %p result %d", network, result);
+
+       for (list = iface_list; list; list = list->next) {
+               wifi = list->data;
+
+               if (wifi->network == NULL && wifi->disconnecting == true)
+                       wifi->disconnecting = false;
+
+               if (wifi->network == network)
+                       goto found;
+       }
+
+       /* wifi_data may be invalid because wifi is already disabled */
+       return;
+
+found:
+#else
        struct wifi_data *wifi = user_data;
+#endif
 
        DBG("result %d supplicant interface %p wifi %p",
                        result, interface, wifi);
@@ -2248,6 +3724,9 @@ static int network_disconnect(struct connman_network *network)
        struct connman_device *device = connman_network_get_device(network);
        struct wifi_data *wifi;
        int err;
+#if defined TIZEN_EXT
+       struct connman_service *service;
+#endif
 
        DBG("network %p", network);
 
@@ -2255,6 +3734,29 @@ static int network_disconnect(struct connman_network *network)
        if (!wifi || !wifi->interface)
                return -ENODEV;
 
+#if defined TIZEN_EXT
+       if (connman_network_get_associating(network) == true) {
+               connman_network_clear_associating(network);
+               connman_network_set_bool(network, "WiFi.UseWPS", false);
+       } else {
+               service = connman_service_lookup_from_network(network);
+
+               if (service != NULL &&
+                       (__connman_service_is_connected_state(service,
+                                       CONNMAN_IPCONFIG_TYPE_IPV4) == false &&
+                       __connman_service_is_connected_state(service,
+                                       CONNMAN_IPCONFIG_TYPE_IPV6) == false) &&
+                       (connman_service_get_favorite(service) == false))
+                                       __connman_service_set_passphrase(service, NULL);
+       }
+
+       if (wifi->pending_network == network)
+               wifi->pending_network = NULL;
+
+       if (wifi->scan_pending_network == network)
+               wifi->scan_pending_network = NULL;
+
+#endif
        connman_network_set_associating(network, false);
 
        if (wifi->disconnecting)
@@ -2262,14 +3764,157 @@ static int network_disconnect(struct connman_network *network)
 
        wifi->disconnecting = true;
 
+#if defined TIZEN_EXT
+       err = g_supplicant_interface_disconnect(wifi->interface,
+                                               disconnect_callback, network);
+#else
        err = g_supplicant_interface_disconnect(wifi->interface,
                                                disconnect_callback, wifi);
+#endif
+
        if (err < 0)
                wifi->disconnecting = false;
 
        return err;
 }
 
+#if defined TIZEN_EXT
+static void set_connection_mode(struct connman_network *network,
+               int linkspeed)
+{
+       ieee80211_modes_e phy_mode;
+       connection_mode_e conn_mode;
+
+       phy_mode = connman_network_get_phy_mode(network);
+       switch (phy_mode) {
+       case IEEE80211_MODE_B:
+               if (linkspeed > 0 && linkspeed <= 11)
+                       conn_mode = CONNECTION_MODE_IEEE80211B;
+               else
+                       conn_mode = CONNECTION_MODE_IEEE80211_UNKNOWN;
+
+               break;
+       case IEEE80211_MODE_BG:
+               if (linkspeed > 0 && linkspeed <= 11)
+                       conn_mode = CONNECTION_MODE_IEEE80211B;
+               else if (linkspeed > 11 && linkspeed <= 54)
+                       conn_mode = CONNECTION_MODE_IEEE80211G;
+               else
+                       conn_mode = CONNECTION_MODE_IEEE80211_UNKNOWN;
+
+               break;
+       case IEEE80211_MODE_BGN:
+               if (linkspeed > 0 && linkspeed <= 11)
+                       conn_mode = CONNECTION_MODE_IEEE80211B;
+               else if (linkspeed > 11 && linkspeed <= 54)
+                       conn_mode = CONNECTION_MODE_IEEE80211G;
+               else if (linkspeed > 54 && linkspeed <= 450)
+                       conn_mode = CONNECTION_MODE_IEEE80211N;
+               else
+                       conn_mode = CONNECTION_MODE_IEEE80211_UNKNOWN;
+
+               break;
+       case IEEE80211_MODE_A:
+               if (linkspeed > 0 && linkspeed <= 54)
+                       conn_mode = CONNECTION_MODE_IEEE80211A;
+               else
+                       conn_mode = CONNECTION_MODE_IEEE80211_UNKNOWN;
+
+               break;
+       case IEEE80211_MODE_AN:
+               if (linkspeed > 0 && linkspeed <= 54)
+                       conn_mode = CONNECTION_MODE_IEEE80211A;
+               else if (linkspeed > 54 && linkspeed <= 450)
+                       conn_mode = CONNECTION_MODE_IEEE80211N;
+               else
+                       conn_mode = CONNECTION_MODE_IEEE80211_UNKNOWN;
+
+               break;
+       case IEEE80211_MODE_ANAC:
+               if (linkspeed > 0 && linkspeed <= 54)
+                       conn_mode = CONNECTION_MODE_IEEE80211A;
+               else if (linkspeed > 54 && linkspeed <= 450)
+                       conn_mode = CONNECTION_MODE_IEEE80211N;
+               else if (linkspeed > 450 && linkspeed <= 1300)
+                       conn_mode = CONNECTION_MODE_IEEE80211AC;
+               else
+                       conn_mode = CONNECTION_MODE_IEEE80211_UNKNOWN;
+
+               break;
+       default:
+                       conn_mode = CONNECTION_MODE_IEEE80211_UNKNOWN;
+               break;
+       }
+
+       DBG("connection mode(%d)", conn_mode);
+       connman_network_set_connection_mode(network, conn_mode);
+}
+
+static void signalpoll_callback(int result, int maxspeed, int strength,
+                               void *user_data)
+{
+       struct connman_network *network = user_data;
+
+       if (result != 0) {
+               DBG("Failed to get maxspeed from signalpoll !");
+               connman_network_unref(network);
+               return;
+       }
+
+       strength += 120;
+       if (strength > 100)
+               strength = 100;
+
+       DBG("maxspeed = %d, strength = %d", maxspeed, strength);
+
+       connman_network_set_strength(network, (uint8_t)strength);
+       connman_network_set_maxspeed(network, maxspeed);
+       set_connection_mode(network, maxspeed);
+
+       connman_network_unref(network);
+}
+
+static int network_signalpoll(struct wifi_data *wifi)
+{
+       GSupplicantInterface *interface;
+       struct connman_network *network;
+
+       if (!wifi || !wifi->network)
+               return -ENODEV;
+
+       wifi->network = connman_network_ref(wifi->network);
+
+       interface = wifi->interface;
+       network = wifi->network;
+
+       DBG("network %p", network);
+
+       return g_supplicant_interface_signalpoll(interface, signalpoll_callback, network);
+}
+
+static gboolean autosignalpoll_timeout(gpointer data)
+{
+       struct wifi_data *wifi = data;
+
+       if (!wifi || !wifi->automaxspeed_timeout) {
+               DBG("automaxspeed_timeout is found to be zero. i.e. currently in disconnected state. !!");
+               return FALSE;
+       }
+
+       int ret = network_signalpoll(wifi);
+       if (ret < 0) {
+               DBG("Fail to get max speed !!");
+               wifi->automaxspeed_timeout = 0;
+
+               if (wifi->network)
+                       connman_network_unref(wifi->network);
+               return FALSE;
+       }
+
+       return TRUE;
+}
+#endif
+
 static struct connman_network_driver network_driver = {
        .name           = "wifi",
        .type           = CONNMAN_NETWORK_TYPE_WIFI,
@@ -2284,6 +3929,19 @@ static void interface_added(GSupplicantInterface *interface)
 {
        const char *ifname = g_supplicant_interface_get_ifname(interface);
        const char *driver = g_supplicant_interface_get_driver(interface);
+#if defined TIZEN_EXT && defined TIZEN_EXT_EAP_ON_ETHERNET
+       /*
+        * Note: If supplicant interface's driver is wired then skip it,
+        * because it meanti only for ethernet not Wi-Fi.
+        */
+       if (!g_strcmp0("wired", g_supplicant_interface_get_driver(interface)))
+               return;
+#endif /* defined TIZEN_EXT && defined TIZEN_EXT_EAP_ON_ETHERNET */
+
+#if defined TIZEN_EXT
+       bool is_5_0_ghz_supported = g_supplicant_interface_get_is_5_0_ghz_supported(interface);
+#endif
+
        struct wifi_data *wifi;
 
        wifi = g_supplicant_interface_get_data(interface);
@@ -2307,6 +3965,12 @@ static void interface_added(GSupplicantInterface *interface)
        }
 
        connman_device_set_powered(wifi->device, true);
+#if defined TIZEN_EXT
+       connman_device_set_wifi_5ghz_supported(wifi->device, is_5_0_ghz_supported);
+       /* Max number of SSIDs supported by wlan chipset that can be scanned */
+       int max_scan_ssids = g_supplicant_interface_get_max_scan_ssids(interface);
+       connman_device_set_max_scan_ssids(wifi->device, max_scan_ssids);
+#endif
 }
 
 static bool is_idle(struct wifi_data *wifi)
@@ -2386,16 +4050,49 @@ static bool handle_wps_completion(GSupplicantInterface *interface,
                if (!wps_ssid || wps_ssid_len != ssid_len ||
                                memcmp(ssid, wps_ssid, ssid_len) != 0) {
                        connman_network_set_associating(network, false);
+#if defined TIZEN_EXT
+                       g_supplicant_interface_disconnect(wifi->interface,
+                                               disconnect_callback, wifi->network);
+
+                       connman_network_set_bool(network, "WiFi.UseWPS", false);
+                       connman_network_set_string(network, "WiFi.PinWPS", NULL);
+#else
                        g_supplicant_interface_disconnect(wifi->interface,
                                                disconnect_callback, wifi);
+#endif
                        return false;
                }
 
                wps_key = g_supplicant_interface_get_wps_key(interface);
+#if defined TIZEN_EXT
+               /* Check the passphrase and encrypt it
+                */
+                int ret;
+                gchar *passphrase = g_strdup(wps_key);
+
+                connman_network_set_string(network, "WiFi.PinWPS", NULL);
+
+                if (check_passphrase_ext(network, passphrase) < 0) {
+                        DBG("[WPS] Invalid passphrase");
+                        g_free(passphrase);
+                        return true;
+                }
+
+                ret = send_encryption_request(passphrase, network);
+
+                g_free(passphrase);
+
+                if (!ret)
+                        DBG("[WPS] Encryption request succeeded");
+                else
+                        DBG("[WPS] Encryption request failed %d", ret);
+
+#else
                connman_network_set_string(network, "WiFi.Passphrase",
                                        wps_key);
 
                connman_network_set_string(network, "WiFi.PinWPS", NULL);
+#endif
        }
 
        return true;
@@ -2405,7 +4102,11 @@ static bool handle_assoc_status_code(GSupplicantInterface *interface,
                                      struct wifi_data *wifi)
 {
        if (wifi->state == G_SUPPLICANT_STATE_ASSOCIATING &&
+#if defined TIZEN_EXT
+                       wifi->assoc_code > 0 &&
+#else
                        wifi->assoc_code == ASSOC_STATUS_NO_CLIENT &&
+#endif
                        wifi->load_shaping_retries < LOAD_SHAPING_MAX_RETRIES) {
                wifi->load_shaping_retries ++;
                return TRUE;
@@ -2418,6 +4119,26 @@ static bool handle_4way_handshake_failure(GSupplicantInterface *interface,
                                        struct connman_network *network,
                                        struct wifi_data *wifi)
 {
+#if defined TIZEN_EXT
+       const char *security;
+       struct connman_service *service;
+
+       if (wifi->connected)
+               return false;
+
+       security = connman_network_get_string(network, "WiFi.Security");
+
+       if (security && g_str_equal(security, "ieee8021x") == true &&
+                       wifi->state == G_SUPPLICANT_STATE_ASSOCIATED) {
+               wifi->retries = 0;
+               connman_network_set_error(network, CONNMAN_NETWORK_ERROR_INVALID_KEY);
+
+               return false;
+       }
+
+       if (wifi->state != G_SUPPLICANT_STATE_4WAY_HANDSHAKE)
+               return false;
+#else
        struct connman_service *service;
 
        if (wifi->state != G_SUPPLICANT_STATE_4WAY_HANDSHAKE)
@@ -2425,6 +4146,7 @@ static bool handle_4way_handshake_failure(GSupplicantInterface *interface,
 
        if (wifi->connected)
                return false;
+#endif
 
        service = connman_service_lookup_from_network(network);
        if (!service)
@@ -2443,12 +4165,62 @@ static bool handle_4way_handshake_failure(GSupplicantInterface *interface,
        return false;
 }
 
+#if defined TIZEN_EXT
+static bool handle_wifi_assoc_retry(struct connman_network *network,
+                                       struct wifi_data *wifi)
+{
+       const char *security;
+
+       if (!wifi->network || wifi->connected || wifi->disconnecting ||
+                       connman_network_get_connecting(network) != true) {
+               wifi->assoc_retry_count = 0;
+               return false;
+       }
+
+       if (wifi->state != G_SUPPLICANT_STATE_ASSOCIATING &&
+                       wifi->state != G_SUPPLICANT_STATE_ASSOCIATED) {
+               wifi->assoc_retry_count = 0;
+               return false;
+       }
+
+       security = connman_network_get_string(network, "WiFi.Security");
+       if (security && g_str_equal(security, "ieee8021x") == true &&
+                       wifi->state == G_SUPPLICANT_STATE_ASSOCIATED) {
+               wifi->assoc_retry_count = 0;
+               return false;
+       }
+
+       if (++wifi->assoc_retry_count >= TIZEN_ASSOC_RETRY_COUNT) {
+               wifi->assoc_retry_count = 0;
+
+               /* Honestly it's not an invalid-key error,
+                * 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_ASSOCIATE_FAIL);
+
+               return false;
+       }
+
+       return true;
+}
+#endif
+
 static void interface_state(GSupplicantInterface *interface)
 {
        struct connman_network *network;
        struct connman_device *device;
        struct wifi_data *wifi;
        GSupplicantState state = g_supplicant_interface_get_state(interface);
+#if defined TIZEN_EXT && defined TIZEN_EXT_EAP_ON_ETHERNET
+       /*
+        * Note: If supplicant interface's driver is wired then skip it,
+        * because it meanti only for ethernet not Wi-Fi.
+        */
+       if (!g_strcmp0("wired", g_supplicant_interface_get_driver(interface)))
+               return;
+#endif /* defined TIZEN_EXT && defined TIZEN_EXT_EAP_ON_ETHERNET */
+
        bool wps;
        bool old_connected;
 
@@ -2493,7 +4265,11 @@ static void interface_state(GSupplicantInterface *interface)
 
        case G_SUPPLICANT_STATE_AUTHENTICATING:
        case G_SUPPLICANT_STATE_ASSOCIATING:
+#if defined TIZEN_EXT
+               reset_autoscan(device);
+#else
                stop_autoscan(device);
+#endif
 
                if (!wifi->connected)
                        connman_network_set_associating(network, true);
@@ -2501,8 +4277,37 @@ static void interface_state(GSupplicantInterface *interface)
                break;
 
        case G_SUPPLICANT_STATE_COMPLETED:
+#if defined TIZEN_EXT
+               /* though it should be already reset: */
+               reset_autoscan(device);
+
+               wifi->assoc_retry_count = 0;
+
+               wifi->scan_pending_network = NULL;
+
+               /* should be cleared scanning flag */
+               bool scanning = connman_device_get_scanning(device,
+                                              CONNMAN_SERVICE_TYPE_WIFI);
+               if (scanning){
+                       connman_device_set_scanning(device,
+                               CONNMAN_SERVICE_TYPE_WIFI, false);
+                       connman_device_unref(device);
+               }
+
+               if (!wifi->automaxspeed_timeout) {
+                       DBG("Going to start signalpoll timer!!");
+                       int ret = network_signalpoll(wifi);
+                       if (ret < 0)
+                               DBG("Fail to get max speed !!");
+                       else
+                               wifi->automaxspeed_timeout = g_timeout_add_seconds(10, autosignalpoll_timeout, wifi);
+               }
+
+               g_hash_table_remove_all(failed_bssids);
+#else
                /* though it should be already stopped: */
                stop_autoscan(device);
+#endif
 
                if (!handle_wps_completion(interface, network, device, wifi))
                        break;
@@ -2515,6 +4320,16 @@ static void interface_state(GSupplicantInterface *interface)
                break;
 
        case G_SUPPLICANT_STATE_DISCONNECTED:
+#if defined TIZEN_EXT
+               connman_network_set_strength(network, 0);
+               connman_network_set_maxspeed(network, 0);
+
+               if (wifi->automaxspeed_timeout != 0) {
+                       g_source_remove(wifi->automaxspeed_timeout);
+                       wifi->automaxspeed_timeout = 0;
+                       DBG("Remove signalpoll timer!!");
+               }
+#endif
                /*
                 * If we're in one of the idle modes, we have
                 * not started association yet and thus setting
@@ -2529,8 +4344,38 @@ static void interface_state(GSupplicantInterface *interface)
                if (is_idle(wifi))
                        break;
 
+#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;
+                       guint bssid_length = 0;
+
+                       if (group) {
+                               supplicant_network = g_supplicant_interface_get_network(interface, group);
+
+                               connman_network_set_assoc_reject_table(network,
+                                       g_supplicant_network_get_assoc_reject_table(supplicant_network));
+
+                               g_supplicant_network_update_assoc_reject(interface, supplicant_network);
+                       }
+
+                       if (bssid_list)
+                               bssid_length = g_slist_length(bssid_list);
+
+                       if (bssid_length > 1 && bssid_length > g_hash_table_size(failed_bssids)) {
+                               network_connect(network);
+                               break;
+                       }
+
+                       wifi->load_shaping_retries = 0;
+               }
+
+               g_hash_table_remove_all(failed_bssids);
+#else
                if (handle_assoc_status_code(interface, wifi))
                        break;
+#endif
 
                /* If previous state was 4way-handshake, then
                 * it's either: psk was incorrect and thus we retry
@@ -2554,6 +4399,21 @@ static void interface_state(GSupplicantInterface *interface)
                        break;
                }
 
+#if defined TIZEN_EXT
+               /* 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) {
+                       throw_wifi_scan(wifi->device, scan_callback);
+                       wifi->scan_pending_network = wifi->network;
+                       break;
+               }
+
+               if(wifi->disconnect_code > 0){
+                       DBG("Set disconnect reason code(%d)", wifi->disconnect_code);
+                       connman_network_set_disconnect_reason(network, wifi->disconnect_code);
+               }
+#endif
+
                if (network != wifi->pending_network) {
                        connman_network_set_connected(network, false);
                        connman_network_set_associating(network, false);
@@ -2565,6 +4425,10 @@ static void interface_state(GSupplicantInterface *interface)
                break;
 
        case G_SUPPLICANT_STATE_INACTIVE:
+#if defined TIZEN_EXT
+               if (handle_wps_completion(interface, network, device, wifi) == false)
+                       break;
+#endif
                connman_network_set_associating(network, false);
                start_autoscan(device);
 
@@ -2620,11 +4484,35 @@ static void interface_removed(GSupplicantInterface *interface)
 {
        const char *ifname = g_supplicant_interface_get_ifname(interface);
        struct wifi_data *wifi;
+#if defined TIZEN_EXT && defined TIZEN_EXT_EAP_ON_ETHERNET
+       /*
+        * Note: If supplicant interface's driver is wired then skip it,
+        * because it meanti only for ethernet not Wi-Fi.
+        */
+       if (!g_strcmp0("wired", g_supplicant_interface_get_driver(interface)))
+               return;
+#endif /* defined TIZEN_EXT && defined TIZEN_EXT_EAP_ON_ETHERNET */
+
 
        DBG("ifname %s", ifname);
 
        wifi = g_supplicant_interface_get_data(interface);
 
+#if defined TIZEN_EXT_WIFI_MESH
+       if (wifi && wifi->mesh_interface) {
+               DBG("Notify mesh interface remove");
+               connman_mesh_notify_interface_remove(true);
+               struct wifi_mesh_info *mesh_info = wifi->mesh_info;
+               g_free(mesh_info->parent_ifname);
+               g_free(mesh_info->ifname);
+               g_free(mesh_info->identifier);
+               g_free(mesh_info);
+               wifi->mesh_interface = false;
+               wifi->mesh_info = NULL;
+               return;
+       }
+#endif
+
        if (wifi)
                wifi->interface = NULL;
 
@@ -2639,6 +4527,9 @@ static void interface_removed(GSupplicantInterface *interface)
        connman_device_set_powered(wifi->device, false);
 
        check_p2p_technology();
+#if defined TIZEN_EXT_WIFI_MESH
+       check_mesh_technology();
+#endif
 }
 
 static void set_device_type(const char *type, char dev_type[17])
@@ -2670,6 +4561,15 @@ static void p2p_support(GSupplicantInterface *interface)
 {
        char dev_type[17] = {};
        const char *hostname;
+#if defined TIZEN_EXT && defined TIZEN_EXT_EAP_ON_ETHERNET
+       /*
+        * Note: If supplicant interface's driver is wired then skip it,
+        * because it meanti only for ethernet not Wi-Fi.
+        */
+       if (!g_strcmp0("wired", g_supplicant_interface_get_driver(interface)))
+               return;
+#endif /* defined TIZEN_EXT && defined TIZEN_EXT_EAP_ON_ETHERNET */
+
 
        DBG("");
 
@@ -2696,16 +4596,74 @@ static void p2p_support(GSupplicantInterface *interface)
 
 static void scan_started(GSupplicantInterface *interface)
 {
+#if defined TIZEN_EXT && defined TIZEN_EXT_EAP_ON_ETHERNET
+       /*
+        * Note: If supplicant interface's driver is wired then skip it,
+        * because it meanti only for ethernet not Wi-Fi.
+        */
+       if (!g_strcmp0("wired", g_supplicant_interface_get_driver(interface)))
+               return;
+#endif /* defined TIZEN_EXT && defined TIZEN_EXT_EAP_ON_ETHERNET */
+
        DBG("");
 }
 
 static void scan_finished(GSupplicantInterface *interface)
 {
+#if defined TIZEN_EXT && defined TIZEN_EXT_EAP_ON_ETHERNET
+       /*
+        * Note: If supplicant interface's driver is wired then skip it,
+        * because it meanti only for ethernet not Wi-Fi.
+        */
+       if (!g_strcmp0("wired", g_supplicant_interface_get_driver(interface)))
+               return;
+#endif /* defined TIZEN_EXT && defined TIZEN_EXT_EAP_ON_ETHERNET */
+
+#if defined TIZEN_EXT
+       struct wifi_data *wifi;
+       bool is_associating = false;
+       static bool is_scanning = true;
+#endif
+
        DBG("");
+
+#if defined TIZEN_EXT
+       wifi = g_supplicant_interface_get_data(interface);
+       if (wifi && wifi->scan_pending_network) {
+               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
 }
 
 static void ap_create_fail(GSupplicantInterface *interface)
 {
+#if defined TIZEN_EXT && defined TIZEN_EXT_EAP_ON_ETHERNET
+       /*
+        * Note: If supplicant interface's driver is wired then skip it,
+        * because it meanti only for ethernet not Wi-Fi.
+        */
+       if (!g_strcmp0("wired", g_supplicant_interface_get_driver(interface)))
+               return;
+#endif /* defined TIZEN_EXT && defined TIZEN_EXT_EAP_ON_ETHERNET */
+
        struct wifi_data *wifi = g_supplicant_interface_get_data(interface);
        int ret;
 
@@ -2737,12 +4695,105 @@ static unsigned char calculate_strength(GSupplicantNetwork *supplicant_network)
        unsigned char strength;
 
        strength = 120 + g_supplicant_network_get_signal(supplicant_network);
+#if !defined TIZEN_EXT
        if (strength > 100)
                strength = 100;
+#endif
 
        return strength;
 }
 
+#if defined TIZEN_EXT_WIFI_MESH
+static void mesh_peer_added(GSupplicantNetwork *supplicant_network)
+{
+       GSupplicantInterface *interface;
+       struct wifi_data *wifi;
+       const char *name, *security;
+       struct connman_mesh *connman_mesh;
+       struct wifi_mesh_info *mesh_info;
+       const unsigned char *bssid;
+       const char *identifier;
+       char *address;
+       uint16_t frequency;
+       int ret;
+
+       interface = g_supplicant_network_get_interface(supplicant_network);
+       wifi = g_supplicant_interface_get_data(interface);
+       if (!wifi || !wifi->mesh_interface) {
+               DBG("Virtual Mesh interface not created");
+               return;
+       }
+
+       bssid = g_supplicant_network_get_bssid(supplicant_network);
+       address = g_malloc0(19);
+       snprintf(address, 19, "%02x:%02x:%02x:%02x:%02x:%02x", bssid[0], bssid[1],
+                                                                bssid[2], bssid[3], bssid[4], bssid[5]);
+
+       identifier = g_supplicant_network_get_identifier(supplicant_network);
+       name = g_supplicant_network_get_name(supplicant_network);
+       security = g_supplicant_network_get_security(supplicant_network);
+       frequency = g_supplicant_network_get_frequency(supplicant_network);
+
+       mesh_info = wifi->mesh_info;
+       connman_mesh = connman_mesh_get(mesh_info->identifier, identifier);
+       if (connman_mesh)
+               goto done;
+
+       DBG("Mesh Peer name %s identifier %s security %s added", name, identifier,
+                                       security);
+       connman_mesh = connman_mesh_create(mesh_info->identifier, identifier);
+       connman_mesh_set_name(connman_mesh, name);
+       connman_mesh_set_security(connman_mesh, security);
+       connman_mesh_set_frequency(connman_mesh, frequency);
+       connman_mesh_set_address(connman_mesh, address);
+       connman_mesh_set_index(connman_mesh, mesh_info->index);
+       connman_mesh_set_strength(connman_mesh,
+                                               calculate_strength(supplicant_network));
+       connman_mesh_set_peer_type(connman_mesh, CONNMAN_MESH_PEER_TYPE_DISCOVERED);
+
+       ret = connman_mesh_register(connman_mesh);
+       if (ret == -EALREADY)
+               DBG("Mesh Peer is already registered");
+
+done:
+       g_free(address);
+}
+
+static void mesh_peer_removed(GSupplicantNetwork *supplicant_network)
+{
+       GSupplicantInterface *interface;
+       struct wifi_data *wifi;
+       struct connman_mesh *connman_mesh;
+       struct wifi_mesh_info *mesh_info;
+       const char *identifier;
+
+       interface = g_supplicant_network_get_interface(supplicant_network);
+       wifi = g_supplicant_interface_get_data(interface);
+       if (!wifi || !wifi->mesh_interface) {
+               DBG("Virtual Mesh interface not created");
+               return;
+       }
+
+       identifier = g_supplicant_network_get_identifier(supplicant_network);
+       if (!identifier) {
+               DBG("Failed to get Mesh Peer identifier");
+               return;
+       }
+
+       mesh_info = wifi->mesh_info;
+       connman_mesh = connman_mesh_get(mesh_info->identifier, identifier);
+       if (connman_mesh) {
+               /* Do not unregister connected mesh peer */
+               if (connman_mesh_peer_is_connected_state(connman_mesh)) {
+                       DBG("Mesh Peer %s is connected", identifier);
+                       return;
+               }
+               DBG("Mesh Peer identifier %s removed", identifier);
+               connman_mesh_unregister(connman_mesh);
+       }
+}
+#endif
+
 static void network_added(GSupplicantNetwork *supplicant_network)
 {
        struct connman_network *network;
@@ -2756,6 +4807,16 @@ static void network_added(GSupplicantNetwork *supplicant_network)
        bool wps_ready;
        bool wps_advertizing;
 
+#if defined TIZEN_EXT
+       bool owe_transition_mode;
+       const unsigned char *transition_mode_ssid;
+       const unsigned char *transition_mode_bssid;
+       unsigned int transition_mode_ssid_len;
+       GSList *vsie_list = NULL;
+       const unsigned char *country_code;
+       ieee80211_modes_e phy_mode;
+#endif
+
        mode = g_supplicant_network_get_mode(supplicant_network);
        identifier = g_supplicant_network_get_identifier(supplicant_network);
 
@@ -2764,7 +4825,23 @@ static void network_added(GSupplicantNetwork *supplicant_network)
        if (!g_strcmp0(mode, "adhoc"))
                return;
 
+#if defined TIZEN_EXT_WIFI_MESH
+       if (!g_strcmp0(mode, "mesh")) {
+               mesh_peer_added(supplicant_network);
+               return;
+       }
+#endif
+
        interface = g_supplicant_network_get_interface(supplicant_network);
+#if defined TIZEN_EXT && defined TIZEN_EXT_EAP_ON_ETHERNET
+       /*
+        * Note: If supplicant interface's driver is wired then skip it,
+        * because it meanti only for ethernet not Wi-Fi.
+        */
+       if (!g_strcmp0("wired", g_supplicant_interface_get_driver(interface)))
+               return;
+#endif /* defined TIZEN_EXT && defined TIZEN_EXT_EAP_ON_ETHERNET */
+
        wifi = g_supplicant_interface_get_data(interface);
        name = g_supplicant_network_get_name(supplicant_network);
        security = g_supplicant_network_get_security(supplicant_network);
@@ -2803,6 +4880,17 @@ static void network_added(GSupplicantNetwork *supplicant_network)
 
        connman_network_set_blob(network, "WiFi.SSID",
                                                ssid, ssid_len);
+#if defined TIZEN_EXT
+       vsie_list = (GSList *)g_supplicant_network_get_wifi_vsie(supplicant_network);
+       if (vsie_list)
+               connman_network_set_vsie_list(network, vsie_list);
+       else
+               DBG("vsie_list is NULL");
+       country_code = g_supplicant_network_get_countrycode(supplicant_network);
+       connman_network_set_countrycode(network, country_code);
+       phy_mode = g_supplicant_network_get_phy_mode(supplicant_network);
+       connman_network_set_phy_mode(network, phy_mode);
+#endif
        connman_network_set_string(network, "WiFi.Security", security);
        connman_network_set_strength(network,
                                calculate_strength(supplicant_network));
@@ -2815,20 +4903,72 @@ static void network_added(GSupplicantNetwork *supplicant_network)
                 * If so, we decide to use WPS by default */
                if (wps_ready && wps_pbc &&
                                                wps_advertizing)
+#if !defined TIZEN_EXT
                        connman_network_set_bool(network, "WiFi.UseWPS", true);
+#else
+                       DBG("wps is activating by ap but ignore it.");
+#endif
        }
 
        connman_network_set_frequency(network,
                        g_supplicant_network_get_frequency(supplicant_network));
 
+#if defined TIZEN_EXT
+       connman_network_set_bssid(network,
+                       g_supplicant_network_get_bssid(supplicant_network));
+       owe_transition_mode = (bool)g_supplicant_network_get_transition_mode(supplicant_network);
+       connman_network_set_bool(network, "WiFi.TRANSITION_MODE", owe_transition_mode);
+       if (owe_transition_mode) {
+               transition_mode_ssid = (unsigned char *)g_supplicant_network_get_transition_mode_ssid(supplicant_network, &transition_mode_ssid_len);
+               connman_network_set_blob(network, "WiFi.TRANSITION_MODE_SSID",
+                                                       transition_mode_ssid, transition_mode_ssid_len);
+               transition_mode_bssid = g_supplicant_network_get_transition_mode_bssid(supplicant_network);
+               connman_network_set_transition_mode_bssid(network, transition_mode_bssid);
+       }
+       connman_network_set_maxrate(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));
+       connman_network_set_bool(network, "WiFi.HS20AP",
+                       g_supplicant_network_is_hs20AP(supplicant_network));
+       connman_network_set_bssid_list(network,
+                       (GSList *)g_supplicant_network_get_bssid_list(supplicant_network));
+       connman_network_set_last_connected_bssid(network,
+                       g_supplicant_network_get_last_connected_bssid(supplicant_network));
+       connman_network_set_assoc_reject_table(network,
+                       g_supplicant_network_get_assoc_reject_table(supplicant_network));
+#endif
        connman_network_set_available(network, true);
        connman_network_set_string(network, "WiFi.Mode", mode);
 
+#if defined TIZEN_EXT
+       if (group)
+#else
        if (ssid)
+#endif
                connman_network_set_group(network, group);
 
+#if defined TIZEN_EXT
+       g_supplicant_network_set_last_connected_bssid(supplicant_network,
+                       connman_network_get_last_connected_bssid(network));
+#endif
+
+#if defined TIZEN_EXT
+       if (wifi_first_scan == true)
+               found_with_first_scan = true;
+#endif
+
        if (wifi->hidden && ssid) {
+#if defined TIZEN_EXT
+               if (network_security(wifi->hidden->security) ==
+                       network_security(security) &&
+#else
                if (!g_strcmp0(wifi->hidden->security, security) &&
+#endif
                                wifi->hidden->ssid_len == ssid_len &&
                                !memcmp(wifi->hidden->ssid, ssid, ssid_len)) {
                        connman_network_connect_hidden(network,
@@ -2849,7 +4989,25 @@ static void network_removed(GSupplicantNetwork *network)
        const char *name, *identifier;
        struct connman_network *connman_network;
 
+#if defined TIZEN_EXT_WIFI_MESH
+       const char *mode;
+       mode = g_supplicant_network_get_mode(network);
+       if (!g_strcmp0(mode, "mesh")) {
+               mesh_peer_removed(network);
+               return;
+       }
+#endif
+
        interface = g_supplicant_network_get_interface(network);
+#if defined TIZEN_EXT && defined TIZEN_EXT_EAP_ON_ETHERNET
+       /*
+        * Note: If supplicant interface's driver is wired then skip it,
+        * because it meanti only for ethernet not Wi-Fi.
+        */
+       if (!g_strcmp0("wired", g_supplicant_interface_get_driver(interface)))
+               return;
+#endif /* defined TIZEN_EXT && defined TIZEN_EXT_EAP_ON_ETHERNET */
+
        wifi = g_supplicant_interface_get_data(interface);
        identifier = g_supplicant_network_get_identifier(network);
        name = g_supplicant_network_get_name(network);
@@ -2863,6 +5021,18 @@ static void network_removed(GSupplicantNetwork *network)
        if (!connman_network)
                return;
 
+#if defined TIZEN_EXT
+       if (connman_network == wifi->scan_pending_network)
+               wifi->scan_pending_network = NULL;
+
+       if (connman_network == wifi->pending_network)
+               wifi->pending_network = NULL;
+
+       if(connman_network_get_connecting(connman_network) == true){
+               connman_network_set_connected(connman_network, false);
+       }
+#endif
+
        wifi->networks = g_slist_remove(wifi->networks, connman_network);
 
        connman_device_remove_network(wifi->device, connman_network);
@@ -2877,12 +5047,35 @@ static void network_changed(GSupplicantNetwork *network, const char *property)
        struct connman_network *connman_network;
        bool update_needed;
 
+#if defined TIZEN_EXT
+       const unsigned char *bssid;
+       unsigned int maxrate;
+       uint16_t frequency;
+       bool wps;
+       const unsigned char *country_code;
+       ieee80211_modes_e phy_mode;
+       GSList *bssid_list;
+#endif
+
        interface = g_supplicant_network_get_interface(network);
+#if defined TIZEN_EXT && defined TIZEN_EXT_EAP_ON_ETHERNET
+       /*
+        * Note: If supplicant interface's driver is wired then skip it,
+        * because it meanti only for ethernet not Wi-Fi.
+        */
+       if (!g_strcmp0("wired", g_supplicant_interface_get_driver(interface)))
+               return;
+#endif /* defined TIZEN_EXT && defined TIZEN_EXT_EAP_ON_ETHERNET */
+
        wifi = g_supplicant_interface_get_data(interface);
        identifier = g_supplicant_network_get_identifier(network);
        name = g_supplicant_network_get_name(network);
 
+#if defined TIZEN_EXT
+       DBG("name %s property %s", name, property);
+#else
        DBG("name %s", name);
+#endif
 
        if (!wifi)
                return;
@@ -2922,11 +5115,61 @@ static void network_changed(GSupplicantNetwork *network, const char *property)
                connman_network_set_strength(connman_network,
                                        calculate_strength(network));
                update_needed = true;
-       } else
+       }
+#if defined TIZEN_EXT
+       else if (g_str_equal(property, "LastConnectedBSSID")) {
+               const char *ident, *group;
+               char *service_ident;
+               bool need_save;
+
+               ident = connman_device_get_ident(wifi->device);
+               group = connman_network_get_group(connman_network);
+               if (ident && group) {
+                       service_ident = g_strdup_printf("%s_%s_%s",
+                               __connman_network_get_type(connman_network), ident, group);
+
+                       need_save = connman_device_set_last_connected_ident(wifi->device, service_ident);
+                       if (need_save)
+                               connman_device_save_last_connected(wifi->device);
+               }
+
+               connman_network_set_last_connected_bssid(connman_network,
+                                       g_supplicant_network_get_last_connected_bssid(network));
+
+               update_needed = true;
+       } else if (g_str_equal(property, "UpdateAssocReject")) {
+               connman_network_set_assoc_reject_table(connman_network,
+                                       g_supplicant_network_get_assoc_reject_table(network));
+               update_needed = true;
+       }
+#endif
+       else
                update_needed = false;
 
        if (update_needed)
                connman_network_update(connman_network);
+
+#if defined TIZEN_EXT
+       bssid = g_supplicant_network_get_bssid(network);
+       maxrate = g_supplicant_network_get_maxrate(network);
+       frequency = g_supplicant_network_get_frequency(network);
+       wps = g_supplicant_network_get_wps(network);
+       phy_mode = g_supplicant_network_get_phy_mode(network);
+
+       connman_network_set_bssid(connman_network, bssid);
+       connman_network_set_maxrate(connman_network, maxrate);
+       connman_network_set_frequency(connman_network, frequency);
+       connman_network_set_bool(connman_network, "WiFi.WPS", wps);
+       country_code = g_supplicant_network_get_countrycode(network);
+       connman_network_set_countrycode(connman_network, country_code);
+       bssid_list = (GSList *)g_supplicant_network_get_bssid_list(network);
+       connman_network_set_bssid_list(connman_network, bssid_list);
+       connman_network_set_phy_mode(connman_network, phy_mode);
+
+       if (g_str_equal(property, "CheckMultiBssidConnect") &&
+                       connman_network_get_associating(connman_network))
+               network_connect(connman_network);
+#endif
 }
 
 static void network_associated(GSupplicantNetwork *network)
@@ -2941,6 +5184,15 @@ static void network_associated(GSupplicantNetwork *network)
        interface = g_supplicant_network_get_interface(network);
        if (!interface)
                return;
+#if defined TIZEN_EXT && defined TIZEN_EXT_EAP_ON_ETHERNET
+       /*
+        * Note: If supplicant interface's driver is wired then skip it,
+        * because it meanti only for ethernet not Wi-Fi.
+        */
+       if (!g_strcmp0("wired", g_supplicant_interface_get_driver(interface)))
+               return;
+#endif /* defined TIZEN_EXT && defined TIZEN_EXT_EAP_ON_ETHERNET */
+
 
        wifi = g_supplicant_interface_get_data(interface);
        if (!wifi)
@@ -2959,7 +5211,22 @@ static void network_associated(GSupplicantNetwork *network)
        if (wifi->network) {
                if (wifi->network == connman_network)
                        return;
-
+#if TIZEN_EXT
+               unsigned int ssid_len;
+               DBG("network1 ssid[%s] , OWE[%d],ssid[%s]",
+                       (char *)connman_network_get_blob(wifi->network,"WiFi.SSID", &ssid_len),
+                       connman_network_get_bool(wifi->network,"WiFi.TRANSITION_MODE"),
+                       (char *)connman_network_get_blob(wifi->network,"WiFi.TRANSITION_MODE_SSID", &ssid_len));
+
+               DBG("network1 ssid[%s], OWE[%d], ssid[%s]",
+                       (char *)connman_network_get_blob(connman_network,"WiFi.SSID",&ssid_len),
+                       connman_network_get_bool(connman_network,"WiFi.TRANSITION_MODE"),
+                       (char *)connman_network_get_blob(connman_network,"WiFi.TRANSITION_MODE_SSID", &ssid_len));
+               if (connman_network_check_transition_mode(wifi->network, connman_network)) {//OWE trasition mode check
+                       DBG("OWE transition mode is TRUE");
+                       return;
+               }
+#endif
                /*
                 * This should never happen, we got associated with
                 * a network different than the one we were expecting.
@@ -2987,6 +5254,15 @@ static void network_associated(GSupplicantNetwork *network)
 static void sta_authorized(GSupplicantInterface *interface,
                                        const char *addr)
 {
+#if defined TIZEN_EXT && defined TIZEN_EXT_EAP_ON_ETHERNET
+       /*
+        * Note: If supplicant interface's driver is wired then skip it,
+        * because it meanti only for ethernet not Wi-Fi.
+        */
+       if (!g_strcmp0("wired", g_supplicant_interface_get_driver(interface)))
+               return;
+#endif /* defined TIZEN_EXT && defined TIZEN_EXT_EAP_ON_ETHERNET */
+
        struct wifi_data *wifi = g_supplicant_interface_get_data(interface);
 
        DBG("wifi %p station %s authorized", wifi, addr);
@@ -3000,6 +5276,15 @@ static void sta_authorized(GSupplicantInterface *interface,
 static void sta_deauthorized(GSupplicantInterface *interface,
                                        const char *addr)
 {
+#if defined TIZEN_EXT && defined TIZEN_EXT_EAP_ON_ETHERNET
+       /*
+        * Note: If supplicant interface's driver is wired then skip it,
+        * because it meanti only for ethernet not Wi-Fi.
+        */
+       if (!g_strcmp0("wired", g_supplicant_interface_get_driver(interface)))
+               return;
+#endif /* defined TIZEN_EXT && defined TIZEN_EXT_EAP_ON_ETHERNET */
+
        struct wifi_data *wifi = g_supplicant_interface_get_data(interface);
 
        DBG("wifi %p station %s deauthorized", wifi, addr);
@@ -3035,6 +5320,10 @@ static void peer_found(GSupplicantPeer *peer)
        const char *identifier, *name;
        int ret;
 
+#if defined TIZEN_EXT
+       if (!wifi)
+               return;
+#endif
        identifier = g_supplicant_peer_get_identifier(peer);
        name = g_supplicant_peer_get_name(peer);
 
@@ -3180,6 +5469,11 @@ static void peer_request(GSupplicantPeer *peer)
        struct connman_peer *connman_peer;
        const char *identifier;
 
+#if defined TIZEN_EXT
+       if (!wifi)
+               return;
+#endif
+
        identifier = g_supplicant_peer_get_identifier(peer);
 
        DBG("ident: %s", identifier);
@@ -3191,15 +5485,161 @@ static void peer_request(GSupplicantPeer *peer)
        connman_peer_request_connection(connman_peer);
 }
 
+#if defined TIZEN_EXT
+static void system_power_off(void)
+{
+       GList *list;
+       struct wifi_data *wifi;
+       struct connman_service *service;
+       struct connman_ipconfig *ipconfig_ipv4;
+
+       if (connman_setting_get_bool("WiFiDHCPRelease") == true) {
+               for (list = iface_list; list; list = list->next) {
+                       wifi = list->data;
+
+                       if (wifi->network != NULL) {
+                               service = connman_service_lookup_from_network(wifi->network);
+                               ipconfig_ipv4 = __connman_service_get_ip4config(service);
+                               __connman_dhcp_stop(ipconfig_ipv4);
+                       }
+               }
+       }
+}
+
+static void network_merged(GSupplicantNetwork *network)
+{
+       GSupplicantInterface *interface;
+       GSupplicantState state;
+       struct wifi_data *wifi;
+       const char *identifier;
+       struct connman_network *connman_network;
+       bool ishs20AP = 0;
+       char *temp = NULL;
+
+       interface = g_supplicant_network_get_interface(network);
+       if (!interface)
+               return;
+
+#if defined TIZEN_EXT && defined TIZEN_EXT_EAP_ON_ETHERNET
+       /*
+        * Note: If supplicant interface's driver is wired then skip it,
+        * because it meanti only for ethernet not Wi-Fi.
+        */
+       if (!g_strcmp0("wired", g_supplicant_interface_get_driver(interface)))
+               return;
+#endif /* defined TIZEN_EXT && defined TIZEN_EXT_EAP_ON_ETHERNET */
+
+       state = g_supplicant_interface_get_state(interface);
+       if (state < G_SUPPLICANT_STATE_AUTHENTICATING)
+               return;
+
+       wifi = g_supplicant_interface_get_data(interface);
+       if (!wifi)
+               return;
+
+       identifier = g_supplicant_network_get_identifier(network);
+
+       connman_network = connman_device_get_network(wifi->device, identifier);
+       if (!connman_network)
+               return;
+
+       DBG("merged identifier %s", identifier);
+
+       if (wifi->connected == FALSE) {
+               switch (state) {
+               case G_SUPPLICANT_STATE_AUTHENTICATING:
+               case G_SUPPLICANT_STATE_ASSOCIATING:
+               case G_SUPPLICANT_STATE_ASSOCIATED:
+               case G_SUPPLICANT_STATE_4WAY_HANDSHAKE:
+               case G_SUPPLICANT_STATE_GROUP_HANDSHAKE:
+                       connman_network_set_associating(connman_network, TRUE);
+                       break;
+               case G_SUPPLICANT_STATE_COMPLETED:
+                       connman_network_set_connected(connman_network, TRUE);
+                       break;
+               default:
+                       DBG("Not handled the state : %d", state);
+                       break;
+               }
+       }
+
+       ishs20AP = g_supplicant_network_is_hs20AP(network);
+
+       if (ishs20AP &&
+               g_strcmp0(g_supplicant_network_get_security(network), "ieee8021x") == 0) {
+               temp = g_ascii_strdown(g_supplicant_network_get_eap(network), -1);
+               connman_network_set_string(connman_network, "WiFi.EAP",
+                               temp);
+               connman_network_set_string(connman_network, "WiFi.Identity",
+                               g_supplicant_network_get_identity(network));
+               connman_network_set_string(connman_network, "WiFi.Phase2",
+                               g_supplicant_network_get_phase2(network));
+
+               g_free(temp);
+       }
+
+       wifi->network = connman_network;
+}
+
+static void assoc_failed(void *user_data)
+{
+       struct connman_network *network = user_data;
+       connman_network_set_associating(network, false);
+}
+
+static void scan_done(GSupplicantInterface *interface)
+{
+#if defined TIZEN_EXT && defined TIZEN_EXT_EAP_ON_ETHERNET
+       /*
+        * Note: If supplicant interface's driver is wired then skip it,
+        * because it meanti only for ethernet not Wi-Fi.
+        */
+       if (!g_strcmp0("wired", g_supplicant_interface_get_driver(interface)))
+               return;
+#endif /* defined TIZEN_EXT && defined TIZEN_EXT_EAP_ON_ETHERNET */
+
+       GList *list;
+       int scan_type = CONNMAN_SCAN_TYPE_WPA_SUPPLICANT;
+       struct wifi_data *wifi;
+       bool scanning;
+
+       for (list = iface_list; list; list = list->next) {
+               wifi = list->data;
+
+               if (interface == wifi->interface) {
+                       scanning = connman_device_get_scanning(wifi->device,
+                                       CONNMAN_SERVICE_TYPE_WIFI);
+                       if (!scanning)
+                               __connman_technology_notify_scan_done(
+                                               connman_device_get_string(wifi->device, "Interface"), scan_type);
+                       break;
+               }
+       }
+}
+#endif
+
 static void debug(const char *str)
 {
+#if defined TIZEN_EXT
+       if (connman_setting_get_bool("ConnmanSupplicantDebug"))
+#else
        if (getenv("CONNMAN_SUPPLICANT_DEBUG"))
+#endif
                connman_debug("%s", str);
 }
 
 static void disconnect_reasoncode(GSupplicantInterface *interface,
                                int reasoncode)
 {
+#if defined TIZEN_EXT && defined TIZEN_EXT_EAP_ON_ETHERNET
+       /*
+        * Note: If supplicant interface's driver is wired then skip it,
+        * because it meanti only for ethernet not Wi-Fi.
+        */
+       if (!g_strcmp0("wired", g_supplicant_interface_get_driver(interface)))
+               return;
+#endif /* defined TIZEN_EXT && defined TIZEN_EXT_EAP_ON_ETHERNET */
+
        struct wifi_data *wifi = g_supplicant_interface_get_data(interface);
 
        if (wifi != NULL) {
@@ -3209,6 +5649,15 @@ static void disconnect_reasoncode(GSupplicantInterface *interface,
 
 static void assoc_status_code(GSupplicantInterface *interface, int status_code)
 {
+#if defined TIZEN_EXT && defined TIZEN_EXT_EAP_ON_ETHERNET
+       /*
+        * Note: If supplicant interface's driver is wired then skip it,
+        * because it meanti only for ethernet not Wi-Fi.
+        */
+       if (!g_strcmp0("wired", g_supplicant_interface_get_driver(interface)))
+               return;
+#endif /* defined TIZEN_EXT && defined TIZEN_EXT_EAP_ON_ETHERNET */
+
        struct wifi_data *wifi = g_supplicant_interface_get_data(interface);
 
        if (wifi != NULL) {
@@ -3216,7 +5665,11 @@ static void assoc_status_code(GSupplicantInterface *interface, int status_code)
        }
 }
 
+#if defined TIZEN_EXT && defined TIZEN_EXT_EAP_ON_ETHERNET
+static GSupplicantCallbacks callbacks = {
+#else /* defined TIZEN_EXT && defined TIZEN_EXT_EAP_ON_ETHERNET */
 static const GSupplicantCallbacks callbacks = {
+#endif /* defined TIZEN_EXT && defined TIZEN_EXT_EAP_ON_ETHERNET */
        .system_ready           = system_ready,
        .system_killed          = system_killed,
        .interface_added        = interface_added,
@@ -3236,9 +5689,22 @@ static const GSupplicantCallbacks callbacks = {
        .peer_lost              = peer_lost,
        .peer_changed           = peer_changed,
        .peer_request           = peer_request,
+#if defined TIZEN_EXT
+       .system_power_off       = system_power_off,
+       .network_merged         = network_merged,
+       .assoc_failed           = assoc_failed,
+       .scan_done              = scan_done,
+#endif
        .debug                  = debug,
        .disconnect_reasoncode  = disconnect_reasoncode,
        .assoc_status_code      = assoc_status_code,
+#if defined TIZEN_EXT_WIFI_MESH
+       .mesh_support           = mesh_support,
+       .mesh_group_started = mesh_group_started,
+       .mesh_group_removed = mesh_group_removed,
+       .mesh_peer_connected = mesh_peer_connected,
+       .mesh_peer_disconnected = mesh_peer_disconnected,
+#endif
 };
 
 
@@ -3263,7 +5729,11 @@ static GSupplicantSSID *ssid_ap_init(const char *ssid, const char *passphrase)
                return NULL;
 
        ap->mode = G_SUPPLICANT_MODE_MASTER;
+#if defined TIZEN_EXT
+       ap->ssid = (void *) ssid;
+#else
        ap->ssid = ssid;
+#endif
        ap->ssid_len = strlen(ssid);
        ap->scan_ssid = 0;
        ap->freq = 2412;
@@ -3356,15 +5826,15 @@ static void sta_remove_callback(int result,
                info->wifi->tethering = false;
                connman_technology_tethering_notify(info->technology, false);
 
-               g_free(info->ifname);
-               g_free(info->ssid);
-               g_free(info);
-
                if (info->wifi->ap_supported == WIFI_AP_SUPPORTED) {
                        g_free(info->wifi->tethering_param->ssid);
                        g_free(info->wifi->tethering_param);
                        info->wifi->tethering_param = NULL;
                }
+
+               g_free(info->ifname);
+               g_free(info->ssid);
+               g_free(info);
                return;
        }
 
@@ -3537,6 +6007,33 @@ static int tech_set_regdom(struct connman_technology *technology, const char *al
        return g_supplicant_set_country(alpha2, regdom_callback, NULL);
 }
 
+#if defined TIZEN_EXT
+static void supp_ins_init(void)
+{
+       const char *string;
+       GSupplicantINSPreferredFreq preferred_freq;
+
+       string = connman_option_get_string("INSPreferredFreqBSSID");
+       if (g_strcmp0(string, "5GHz") == 0)
+               preferred_freq = G_SUPPLICANT_INS_PREFERRED_FREQ_5GHZ;
+       else if (g_strcmp0(string, "2.4GHz") == 0)
+               preferred_freq = G_SUPPLICANT_INS_PREFERRED_FREQ_24GHZ;
+       else
+               preferred_freq = G_SUPPLICANT_INS_PREFERRED_FREQ_UNKNOWN;
+
+       g_supplicant_set_ins_settings(preferred_freq,
+               connman_setting_get_bool("INSLastConnectedBSSID"),
+               connman_setting_get_bool("INSAssocReject"),
+               connman_setting_get_bool("INSSignalBSSID"),
+               connman_setting_get_uint("INSPreferredFreqBSSIDScore"),
+               connman_setting_get_uint("INSLastConnectedBSSIDScore"),
+               connman_setting_get_uint("INSAssocRejectScore"),
+               connman_setting_get_int("INSSignalLevel3_5GHz"),
+               connman_setting_get_int("INSSignalLevel3_24GHz")
+       );
+}
+#endif
+
 static struct connman_technology_driver tech_driver = {
        .name           = "wifi",
        .type           = CONNMAN_SERVICE_TYPE_WIFI,
@@ -3567,6 +6064,13 @@ static int wifi_init(void)
                return err;
        }
 
+#if defined TIZEN_EXT
+       failed_bssids = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, NULL);
+#endif
+
+#if defined TIZEN_EXT
+       supp_ins_init();
+#endif
        return 0;
 }
 
@@ -3579,6 +6083,10 @@ static void wifi_exit(void)
        g_supplicant_unregister(&callbacks);
 
        connman_network_driver_unregister(&network_driver);
+
+#if defined TIZEN_EXT
+       g_hash_table_unref(failed_bssids);
+#endif
 }
 
 CONNMAN_PLUGIN_DEFINE(wifi, "WiFi interface plugin", VERSION,