[connman] Added Tizen Wi-Fi Mesh
[platform/upstream/connman.git] / plugins / wifi.c
old mode 100755 (executable)
new mode 100644 (file)
index 7b416fc..8e8017d
 #define P2P_LISTEN_PERIOD 500
 #define P2P_LISTEN_INTERVAL 2000
 
+#define ASSOC_STATUS_NO_CLIENT 17
+#define LOAD_SHAPING_MAX_RETRIES 3
+
+#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;
 
+enum wifi_ap_capability{
+       WIFI_AP_UNKNOWN         = 0,
+       WIFI_AP_SUPPORTED       = 1,
+       WIFI_AP_NOT_SUPPORTED   = 2,
+};
+
 struct hidden_params {
        char ssid[32];
        unsigned int ssid_len;
        char *identity;
+       char *anonymous_identity;
+       char *subject_match;
+       char *altsubject_match;
+       char *domain_suffix_match;
+       char *domain_match;
        char *passphrase;
        char *security;
        GSupplicantScanParams *scan_params;
@@ -95,6 +113,13 @@ struct autoscan_params {
        unsigned int timeout;
 };
 
+struct wifi_tethering_info {
+       struct wifi_data *wifi;
+       struct connman_technology *technology;
+       char *ifname;
+       GSupplicantSSID *ssid;
+};
+
 struct wifi_data {
        char *identifier;
        struct connman_device *device;
@@ -106,6 +131,7 @@ struct wifi_data {
        bool connected;
        bool disconnecting;
        bool tethering;
+       enum wifi_ap_capability ap_supported;
        bool bridged;
        bool interface_ready;
        const char *bridge;
@@ -113,8 +139,10 @@ struct wifi_data {
        unsigned flags;
        unsigned int watch;
        int retries;
+       int load_shaping_retries;
        struct hidden_params *hidden;
        bool postpone_hidden;
+       struct wifi_tethering_info *tethering_param;
        /**
         * autoscan "emulation".
         */
@@ -124,7 +152,7 @@ struct wifi_data {
        unsigned int p2p_find_timeout;
        unsigned int p2p_connection_timeout;
        struct connman_peer *pending_peer;
-       GSupplicantPeer *peer;
+       GSList *peers;
        bool p2p_connecting;
        bool p2p_device;
        int servicing;
@@ -134,10 +162,16 @@ struct wifi_data {
        bool allow_full_scan;
 #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
 
@@ -153,48 +187,669 @@ static GList *pending_wifi_device = NULL;
 static GList *p2p_iface_list = NULL;
 bool wfd_service_registered = false;
 
-static void start_autoscan(struct connman_device *device);
+static void start_autoscan(struct connman_device *device);
+
+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;
+
+       return 0;
+}
+
+static void p2p_tech_remove(struct connman_technology *technology)
+{
+       p2p_technology = NULL;
+}
+
+static struct connman_technology_driver p2p_tech_driver = {
+       .name           = "p2p",
+       .type           = CONNMAN_SERVICE_TYPE_P2P,
+       .probe          = p2p_tech_probe,
+       .remove         = p2p_tech_remove,
+};
+
+static bool is_p2p_connecting(void)
+{
+       GList *list;
+
+       for (list = iface_list; list; list = list->next) {
+               struct wifi_data *wifi = list->data;
+
+               if (wifi->p2p_connecting)
+                       return true;
+       }
+
+       return false;
+}
+
+static void add_pending_wifi_device(struct wifi_data *wifi)
+{
+       if (g_list_find(pending_wifi_device, wifi))
+               return;
+
+       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);
 
-static int p2p_tech_probe(struct connman_technology *technology)
-{
-       p2p_technology = technology;
+       if (!wifi)
+               return;
 
-       return 0;
-}
+       mesh_info = wifi->mesh_info;
+       if (!mesh_info)
+               return;
 
-static void p2p_tech_remove(struct connman_technology *technology)
-{
-       p2p_technology = NULL;
-}
+       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;
+               }
+       }
 
-static struct connman_technology_driver p2p_tech_driver = {
-       .name           = "p2p",
-       .type           = CONNMAN_SERVICE_TYPE_P2P,
-       .probe          = p2p_tech_probe,
-       .remove         = p2p_tech_remove,
-};
+       connman_mesh_peer_set_disconnect_reason(mesh, disconnect_reason);
+       connman_mesh_peer_set_state(mesh, CONNMAN_MESH_STATE_DISCONNECT);
+}
 
-static bool is_p2p_connecting(void)
+static void mesh_peer_connected(GSupplicantMeshPeer *mesh_peer)
 {
-       GList *list;
+       const char *peer_address;
 
-       for (list = iface_list; list; list = list->next) {
-               struct wifi_data *wifi = list->data;
+       peer_address = g_supplicant_mesh_peer_get_address(mesh_peer);
 
-               if (wifi->p2p_connecting)
-                       return true;
-       }
+       if (!peer_address)
+               return;
 
-       return false;
+       DBG("Peer %s connected", peer_address);
+       connman_mesh_add_connected_peer(peer_address);
 }
 
-static void add_pending_wifi_device(struct wifi_data *wifi)
+static void mesh_peer_disconnected(GSupplicantMeshPeer *mesh_peer)
 {
-       if (g_list_find(pending_wifi_device, wifi))
+       const char *peer_address;
+       int reason;
+
+       peer_address = g_supplicant_mesh_peer_get_address(mesh_peer);
+
+       if (!peer_address)
                return;
 
-       pending_wifi_device = g_list_append(pending_wifi_device, wifi);
+       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)
 {
@@ -243,8 +898,6 @@ static void peer_cancel_timeout(struct wifi_data *wifi)
                connman_peer_unref(wifi->pending_peer);
                wifi->pending_peer = NULL;
        }
-
-       wifi->peer = NULL;
 }
 
 static gboolean peer_connect_timeout(gpointer data)
@@ -255,8 +908,11 @@ static gboolean peer_connect_timeout(gpointer data)
 
        if (wifi->p2p_connecting) {
                enum connman_peer_state state = CONNMAN_PEER_STATE_FAILURE;
+               GSupplicantPeer *gs_peer =
+                       g_supplicant_interface_peer_lookup(wifi->interface,
+                               connman_peer_get_identifier(wifi->pending_peer));
 
-               if (g_supplicant_peer_has_requested_connection(wifi->peer))
+               if (g_supplicant_peer_has_requested_connection(gs_peer))
                        state = CONNMAN_PEER_STATE_IDLE;
 
                connman_peer_set_state(wifi->pending_peer, state);
@@ -307,14 +963,12 @@ static int peer_connect(struct connman_peer *peer,
                return -ENODEV;
 
        wifi = connman_device_get_data(device);
-       if (!wifi)
+       if (!wifi || !wifi->interface)
                return -ENODEV;
 
        if (wifi->p2p_connecting)
                return -EBUSY;
 
-       wifi->peer = NULL;
-
        gs_peer = g_supplicant_interface_peer_lookup(wifi->interface,
                                        connman_peer_get_identifier(peer));
        if (!gs_peer)
@@ -353,10 +1007,12 @@ static int peer_connect(struct connman_peer *peer,
                                                peer_connect_callback, wifi);
        if (ret == -EINPROGRESS) {
                wifi->pending_peer = connman_peer_ref(peer);
-               wifi->peer = gs_peer;
                wifi->p2p_connecting = true;
-       } else if (ret < 0)
+       } else if (ret < 0) {
+               g_free(peer_params->path);
+               g_free(peer_params->wps_pin);
                g_free(peer_params);
+       }
 
        return ret;
 }
@@ -389,8 +1045,10 @@ static int peer_disconnect(struct connman_peer *peer)
                                                        &peer_params);
        g_free(peer_params.path);
 
-       if (ret == -EINPROGRESS)
+       if (ret == -EINPROGRESS) {
                peer_cancel_timeout(wifi);
+               wifi->p2p_device = false;
+       }
 
        return ret;
 }
@@ -530,6 +1188,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)
@@ -754,6 +1417,8 @@ static int wifi_probe(struct connman_device *device)
                return -ENOMEM;
 
        wifi->state = G_SUPPLICANT_STATE_INACTIVE;
+       wifi->ap_supported = WIFI_AP_UNKNOWN;
+       wifi->tethering_param = NULL;
 
        connman_device_set_data(device, wifi);
        wifi->device = connman_device_ref(device);
@@ -787,6 +1452,21 @@ static void remove_networks(struct connman_device *device,
        wifi->networks = NULL;
 }
 
+static void remove_peers(struct wifi_data *wifi)
+{
+       GSList *list;
+
+       for (list = wifi->peers; list; list = list->next) {
+               struct connman_peer *peer = list->data;
+
+               connman_peer_unregister(peer);
+               connman_peer_unref(peer);
+       }
+
+       g_slist_free(wifi->peers);
+       wifi->peers = NULL;
+}
+
 static void reset_autoscan(struct connman_device *device)
 {
        struct wifi_data *wifi = connman_device_get_data(device);
@@ -858,6 +1538,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);
 
@@ -870,6 +1553,7 @@ static void wifi_remove(struct connman_device *device)
                g_source_remove(wifi->p2p_connection_timeout);
 
        remove_networks(device, wifi);
+       remove_peers(wifi);
 
        connman_device_set_powered(device, false);
        connman_device_set_data(device, NULL);
@@ -1301,12 +1985,24 @@ static void scan_callback(int result, GSupplicantInterface *interface,
                return scan_callback(ret, interface, user_data);
        }
 
-       scanning = connman_device_get_scanning(device);
 #if defined TIZEN_EXT
-       if (scanning && wifi && !wifi->allow_full_scan)
-#else
-       if (scanning)
+       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, 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);
+       if (scanning)
                connman_device_set_scanning(device,
                                CONNMAN_SERVICE_TYPE_WIFI, false);
 
@@ -1327,11 +2023,6 @@ static void scan_callback(int result, GSupplicantInterface *interface,
                connman_device_unref(device);
 
 #if defined TIZEN_EXT
-       if (wifi && wifi->allow_full_scan) {
-               DBG("Trigger Full Channel Scan");
-               throw_wifi_scan(device, scan_callback);
-               wifi->allow_full_scan = FALSE;
-       }
        if (wifi && wifi->scan_pending_network && result != -EIO) {
                network_connect(wifi->scan_pending_network);
                wifi->scan_pending_network = NULL;
@@ -1599,6 +2290,7 @@ static int wifi_disable(struct connman_device *device)
        }
 
        remove_networks(device, wifi);
+       remove_peers(wifi);
 
 #if defined TIZEN_EXT
        wifi->scan_pending_network = NULL;
@@ -1713,123 +2405,457 @@ static int get_latest_connections(int max_ssids,
                                return -ENOMEM;
                        }
 
-                       entry->ssid = ssid;
-                       entry->modified = modified;
-                       entry->freq = freq;
+                       entry->ssid = ssid;
+                       entry->modified = modified;
+                       entry->freq = freq;
+
+                       g_sequence_insert_sorted(latest_list, entry,
+                                               sort_entry, NULL);
+                       num_ssids++;
+               } else
+                       g_free(ssid);
+
+               g_key_file_free(keyfile);
+       }
+
+       g_strfreev(services);
+
+       num_ssids = num_ssids > max_ssids ? max_ssids : num_ssids;
+
+       iter = g_sequence_get_begin_iter(latest_list);
+
+       for (i = 0; i < num_ssids; i++) {
+               entry = g_sequence_get(iter);
+
+               DBG("ssid %s freq %d modified %lu", entry->ssid, entry->freq,
+                                               entry->modified.tv_sec);
+
+               add_scan_param(entry->ssid, NULL, 0, entry->freq, scan_data,
+                                               max_ssids, entry->ssid);
+
+               iter = g_sequence_iter_next(iter);
+       }
+
+       g_sequence_free(latest_list);
+       return num_ssids;
+}
+
+static int wifi_scan_simple(struct connman_device *device)
+{
+       reset_autoscan(device);
+
+       return throw_wifi_scan(device, scan_callback_hidden);
+}
+
+static gboolean p2p_find_stop(gpointer data)
+{
+       struct connman_device *device = data;
+       struct wifi_data *wifi = connman_device_get_data(device);
+
+       DBG("");
+
+       if (wifi) {
+               wifi->p2p_find_timeout = 0;
+
+               g_supplicant_interface_p2p_stop_find(wifi->interface);
+       }
+
+       connman_device_set_scanning(device, CONNMAN_SERVICE_TYPE_P2P, false);
+
+       connman_device_unref(device);
+       reset_autoscan(device);
+
+       return FALSE;
+}
+
+static void p2p_find_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);
+
+       if (!wifi)
+               goto error;
+
+       if (wifi->p2p_find_timeout) {
+               g_source_remove(wifi->p2p_find_timeout);
+               wifi->p2p_find_timeout = 0;
+       }
+
+       if (result)
+               goto error;
+
+       wifi->p2p_find_timeout = g_timeout_add_seconds(P2P_FIND_TIMEOUT,
+                                                       p2p_find_stop, device);
+       if (!wifi->p2p_find_timeout)
+               goto error;
+
+       return;
+error:
+       p2p_find_stop(device);
+}
+
+static int p2p_find(struct connman_device *device)
+{
+       struct wifi_data *wifi;
+       int ret;
+
+       DBG("");
+
+       if (!p2p_technology)
+               return -ENOTSUP;
+
+       wifi = connman_device_get_data(device);
+
+       if (g_supplicant_interface_is_p2p_finding(wifi->interface))
+               return -EALREADY;
+
+       reset_autoscan(device);
+       connman_device_ref(device);
+
+       ret = g_supplicant_interface_p2p_find(wifi->interface,
+                                               p2p_find_callback, device);
+       if (ret) {
+               connman_device_unref(device);
+               start_autoscan(device);
+       } else {
+               connman_device_set_scanning(device,
+                               CONNMAN_SERVICE_TYPE_P2P, true);
+       }
+
+       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);
+       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);
+       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 */
 
-                       g_sequence_insert_sorted(latest_list, entry,
-                                               sort_entry, NULL);
-                       num_ssids++;
-               } else
-                       g_free(ssid);
+               scan_params = g_try_malloc0(sizeof(GSupplicantScanParams));
+               if (!scan_params) {
+                       DBG("Failed to allocate memory.");
+                       return -ENOMEM;
+               }
 
-               g_key_file_free(keyfile);
-       }
+               guint num_freqs = g_slist_length(specific_scan_list);
+               DBG("num_freqs: %d", num_freqs);
 
-       g_strfreev(services);
+               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;
+               }
 
-       num_ssids = num_ssids > max_ssids ? max_ssids : num_ssids;
+               count = 0;
+               for (list = specific_scan_list; list; list = list->next) {
+                       freq = (int)list->data;
 
-       iter = g_sequence_get_begin_iter(latest_list);
+                       scan_params->freqs[count] = freq;
+                       DBG("scan_params->freqs[%d]: %d", count, scan_params->freqs[count]);
+                       count++;
+               }
+               scan_params->num_freqs = count;
 
-       for (i = 0; i < num_ssids; i++) {
-               entry = g_sequence_get(iter);
+       } 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;
+               }
 
-               DBG("ssid %s freq %d modified %lu", entry->ssid, entry->freq,
-                                               entry->modified.tv_sec);
+               guint size = g_slist_length(specific_scan_list);
 
-               add_scan_param(entry->ssid, NULL, 0, entry->freq, scan_data,
-                                               max_ssids, entry->ssid);
+               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;
+               }
 
-               iter = g_sequence_iter_next(iter);
+               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;
        }
 
-       g_sequence_free(latest_list);
-       return num_ssids;
+       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
 
-static int wifi_scan_simple(struct connman_device *device)
+#if defined TIZEN_EXT_WIFI_MESH
+static void mesh_scan_callback(int result, GSupplicantInterface *interface,
+                                               void *user_data)
 {
-       reset_autoscan(device);
+       struct connman_device *device = user_data;
+       struct wifi_data *wifi = connman_device_get_data(device);
+       bool scanning;
 
-       return throw_wifi_scan(device, scan_callback_hidden);
+       DBG("result %d wifi %p", result, wifi);
+
+       scanning = connman_device_get_scanning(device);
+       if (scanning)
+               connman_device_set_scanning(device,
+                               CONNMAN_SERVICE_TYPE_MESH, false);
+
+       if (scanning)
+               connman_device_unref(device);
 }
 
-static gboolean p2p_find_stop(gpointer data)
+static int mesh_scan(struct connman_device *device)
 {
-       struct connman_device *device = data;
-       struct wifi_data *wifi = connman_device_get_data(device);
+       struct wifi_data *wifi;
+       struct wifi_mesh_info *mesh_info;
+       int ret;
 
        DBG("");
 
-       wifi->p2p_find_timeout = 0;
-
-       connman_device_set_scanning(device, CONNMAN_SERVICE_TYPE_P2P, false);
+       wifi = connman_device_get_data(device);
 
-       g_supplicant_interface_p2p_stop_find(wifi->interface);
+       if (!wifi->mesh_interface)
+               return -ENOTSUP;
 
-       connman_device_unref(device);
+       mesh_info = wifi->mesh_info;
        reset_autoscan(device);
+       connman_device_ref(device);
 
-       return FALSE;
+       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 p2p_find_callback(int result, GSupplicantInterface *interface,
-                                                       void *user_data)
+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);
 
-       if (wifi->p2p_find_timeout) {
-               g_source_remove(wifi->p2p_find_timeout);
-               wifi->p2p_find_timeout = 0;
-       }
+       __connman_technology_notify_abort_scan(CONNMAN_SERVICE_TYPE_MESH, result);
+}
 
-       if (result)
-               goto error;
+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;
 
-       wifi->p2p_find_timeout = g_timeout_add_seconds(P2P_FIND_TIMEOUT,
-                                                       p2p_find_stop, device);
-       if (!wifi->p2p_find_timeout)
-               goto error;
+       if (!wifi || !wifi->mesh_interface)
+               return -ENODEV;
 
-       return;
-error:
-       p2p_find_stop(device);
+       if (type != CONNMAN_SERVICE_TYPE_MESH)
+               return -EINVAL;
+
+       mesh_info = wifi->mesh_info;
+
+       scanning = connman_device_get_scanning(device);
+       if (!scanning)
+               return -EEXIST;
+
+       ret = g_supplicant_interface_abort_scan(mesh_info->interface,
+                                               abort_scan_callback, device);
+
+       return ret;
 }
 
-static int p2p_find(struct connman_device *device)
+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;
+       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;
 
-       DBG("");
+       if (!wifi || !wifi->mesh_interface)
+               return -ENODEV;
 
-       if (!p2p_technology)
-               return -ENOTSUP;
+       if (type != CONNMAN_SERVICE_TYPE_MESH)
+               return -EINVAL;
 
-       wifi = connman_device_get_data(device);
+       if (wifi->p2p_device)
+               return 0;
 
-       if (g_supplicant_interface_is_p2p_finding(wifi->interface))
+       mesh_info = wifi->mesh_info;
+
+       scanning = connman_device_get_scanning(device);
+       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_p2p_find(wifi->interface,
-                                               p2p_find_callback, device);
-       if (ret) {
-               connman_device_unref(device);
-               start_autoscan(device);
-       } else {
+       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_P2P, true);
+                               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
@@ -1854,15 +2880,20 @@ static int wifi_scan(enum connman_service_type type,
                return -ENODEV;
 
        if (wifi->p2p_device)
-               return 0;
+               return -EBUSY;
+
+       if (wifi->tethering)
+               return -EBUSY;
 
        if (type == CONNMAN_SERVICE_TYPE_P2P)
                return p2p_find(device);
 
-       DBG("device %p wifi %p hidden ssid %s", device, wifi->interface, ssid);
+#if defined TIZEN_EXT_WIFI_MESH
+       if (type == CONNMAN_SERVICE_TYPE_MESH)
+               return mesh_scan(device);
+#endif
 
-       if (wifi->tethering)
-               return 0;
+       DBG("device %p wifi %p hidden ssid %s", device, wifi->interface, ssid);
 
        scanning = connman_device_get_scanning(device);
 
@@ -1941,13 +2972,6 @@ static int wifi_scan(enum connman_service_type type,
 
        connman_device_ref(device);
 
-#if defined TIZEN_EXT
-       /*To allow the Full Scan after ssid based scan, set the flag here
-     It is required because Tizen does not use the ConnMan specific
-     backgroung Scan feature.Tizen has added the BG Scan feature in net-config
-     To sync with up ConnMan, we need to issue the Full Scan after SSID specific scan.*/
-        wifi->allow_full_scan = TRUE;
-#endif
        reset_autoscan(device);
 
        ret = g_supplicant_interface_scan(wifi->interface, scan_params,
@@ -1956,6 +2980,14 @@ static int wifi_scan(enum connman_service_type type,
        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.*/
+               wifi->allow_full_scan = TRUE;
+#endif
        } else {
                g_supplicant_free_scan_params(scan_params);
                connman_device_unref(device);
@@ -2009,6 +3041,13 @@ static struct connman_device_driver wifi_ng_driver = {
        .disable        = wifi_disable,
        .scan           = wifi_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)
@@ -2072,6 +3111,8 @@ static void connect_callback(int result, GSupplicantInterface *interface,
        DBG("network %p result %d", network, result);
 
 #if defined TIZEN_EXT
+       set_connman_bssid(RESET_BSSID, NULL);
+
        for (list = iface_list; list; list = list->next) {
                wifi = list->data;
 
@@ -2119,20 +3160,44 @@ static GSupplicantSecurity network_security(const char *security)
        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);
+       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);
        ssid->passphrase = connman_network_get_string(network,
                                                "WiFi.Passphrase");
-
        ssid->eap = connman_network_get_string(network, "WiFi.EAP");
 
        /*
@@ -2153,8 +3218,18 @@ static void ssid_init(GSupplicantSSID *ssid, struct connman_network *network)
                ssid->identity = connman_network_get_string(network,
                                                        "WiFi.AgentIdentity");
 
+       ssid->anonymous_identity = connman_network_get_string(network,
+                                               "WiFi.AnonymousIdentity");
        ssid->ca_cert_path = connman_network_get_string(network,
                                                        "WiFi.CACertFile");
+       ssid->subject_match = connman_network_get_string(network,
+                                                       "WiFi.SubjectMatch");
+       ssid->altsubject_match = connman_network_get_string(network,
+                                                       "WiFi.AltSubjectMatch");
+       ssid->domain_suffix_match = connman_network_get_string(network,
+                                                       "WiFi.DomainSuffixMatch");
+       ssid->domain_match = connman_network_get_string(network,
+                                                       "WiFi.DomainMatch");
        ssid->client_cert_path = connman_network_get_string(network,
                                                        "WiFi.ClientCertFile");
        ssid->private_key_path = connman_network_get_string(network,
@@ -2168,9 +3243,24 @@ static void ssid_init(GSupplicantSSID *ssid, struct connman_network *network)
 
 #if defined TIZEN_EXT
        ssid->bssid = connman_network_get_bssid(network);
-#endif
-#if defined TIZEN_EXT
-       ssid->freq = connman_network_get_frequency(network);
+
+       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);
+
+       if (set_connman_bssid(CHECK_BSSID, NULL) == 6) {
+               ssid->bssid_for_connect_len = 6;
+               set_connman_bssid(GET_BSSID, (char *)ssid->bssid_for_connect);
+               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);
+       }
 #endif
 
        if (connman_setting_get_bool("BackgroundScanning"))
@@ -2203,6 +3293,9 @@ 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);
@@ -2255,20 +3348,12 @@ found:
        }
 
        if (wifi->network) {
-               /*
-                * if result < 0 supplican return an error because
-                * the network is not current.
-                * we wont receive G_SUPPLICANT_STATE_DISCONNECTED since it
-                * failed, call connman_network_set_connected to report
-                * disconnect is completed.
-                */
-               if (result < 0)
-                       connman_network_set_connected(wifi->network, false);
+               connman_network_set_connected(wifi->network, false);
+               wifi->network = NULL;
        }
 
-       wifi->network = NULL;
-
        wifi->disconnecting = false;
+       wifi->connected = false;
 
        if (wifi->pending_network) {
                network_connect(wifi->pending_network);
@@ -2359,6 +3444,7 @@ static void interface_added(GSupplicantInterface *interface)
                if (!wifi)
                        return;
 
+               wifi->interface = interface;
                g_supplicant_interface_set_data(interface, wifi);
                p2p_iface_list = g_list_append(p2p_iface_list, wifi);
                wifi->p2p_device = true;
@@ -2466,15 +3552,53 @@ static bool handle_wps_completion(GSupplicantInterface *interface,
                }
 
                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;
 }
 
+static bool handle_assoc_status_code(GSupplicantInterface *interface,
+                                     struct wifi_data *wifi)
+{
+       if (wifi->state == G_SUPPLICANT_STATE_ASSOCIATING &&
+                       wifi->assoc_code == ASSOC_STATUS_NO_CLIENT &&
+                       wifi->load_shaping_retries < LOAD_SHAPING_MAX_RETRIES) {
+               wifi->load_shaping_retries ++;
+               return TRUE;
+       }
+       wifi->load_shaping_retries = 0;
+       return FALSE;
+}
+
 static bool handle_4way_handshake_failure(GSupplicantInterface *interface,
                                        struct connman_network *network,
                                        struct wifi_data *wifi)
@@ -2488,7 +3612,7 @@ static bool handle_4way_handshake_failure(GSupplicantInterface *interface,
 
        security = connman_network_get_string(network, "WiFi.Security");
 
-       if (g_str_equal(security, "ieee8021x") == true &&
+       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);
@@ -2544,7 +3668,7 @@ static bool handle_wifi_assoc_retry(struct connman_network *network,
        }
 
        security = connman_network_get_string(network, "WiFi.Security");
-       if (g_str_equal(security, "ieee8021x") == true &&
+       if (security && g_str_equal(security, "ieee8021x") == true &&
                        wifi->state == G_SUPPLICANT_STATE_ASSOCIATED) {
                wifi->assoc_retry_count = 0;
                return false;
@@ -2573,6 +3697,7 @@ static void interface_state(GSupplicantInterface *interface)
        struct wifi_data *wifi;
        GSupplicantState state = g_supplicant_interface_get_state(interface);
        bool wps;
+       bool old_connected;
 
        wifi = g_supplicant_interface_get_data(interface);
 
@@ -2581,6 +3706,14 @@ static void interface_state(GSupplicantInterface *interface)
        if (!wifi)
                return;
 
+       if (state == G_SUPPLICANT_STATE_COMPLETED) {
+               if (wifi->tethering_param) {
+                       g_free(wifi->tethering_param->ssid);
+                       g_free(wifi->tethering_param);
+                       wifi->tethering_param = NULL;
+               }
+       }
+
        device = wifi->device;
        if (!device)
                return;
@@ -2597,6 +3730,9 @@ static void interface_state(GSupplicantInterface *interface)
 
        switch (state) {
        case G_SUPPLICANT_STATE_SCANNING:
+               if (wifi->connected)
+                       connman_network_set_connected(network, false);
+
                break;
 
        case G_SUPPLICANT_STATE_AUTHENTICATING:
@@ -2637,7 +3773,10 @@ static void interface_state(GSupplicantInterface *interface)
                        break;
 
                connman_network_set_connected(network, true);
+
                wifi->disconnect_code = 0;
+               wifi->assoc_code = 0;
+               wifi->load_shaping_retries = 0;
                break;
 
        case G_SUPPLICANT_STATE_DISCONNECTED:
@@ -2655,6 +3794,9 @@ static void interface_state(GSupplicantInterface *interface)
                if (is_idle(wifi))
                        break;
 
+               if (handle_assoc_status_code(interface, wifi))
+                       break;
+
                /* If previous state was 4way-handshake, then
                 * it's either: psk was incorrect and thus we retry
                 * or if we reach the maximum retries we declare the
@@ -2677,21 +3819,7 @@ static void interface_state(GSupplicantInterface *interface)
                        break;
                }
 
-
-               /* We disable the selected network, if not then
-                * wpa_supplicant will loop retrying */
-               if (g_supplicant_interface_enable_selected_network(interface,
-                                               FALSE) != 0)
-                       DBG("Could not disables selected network");
-
 #if defined TIZEN_EXT
-               int err;
-
-               err = g_supplicant_interface_remove_network(wifi->interface);
-               if (err < 0)
-                       DBG("Failed to remove network(%d)", err);
-
-
                /* 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) {
@@ -2704,23 +3832,6 @@ static void interface_state(GSupplicantInterface *interface)
                        DBG("Set disconnect reason code(%d)", wifi->disconnect_code);
                        connman_network_set_disconnect_reason(network, wifi->disconnect_code);
                }
-
-               /* To avoid unnecessary repeated association in wpa_supplicant,
-                * "RemoveNetwork" should be made when Wi-Fi is disconnected */
-               if (wps != true && wifi->network && wifi->disconnecting == false) {
-                       wifi->disconnecting = true;
-                       err = g_supplicant_interface_disconnect(wifi->interface,
-                                                       disconnect_callback, wifi->network);
-                       if (err < 0)
-                               wifi->disconnecting = false;
-
-               connman_network_set_connected(network, false);
-               connman_network_set_associating(network, false);
-
-               start_autoscan(device);
-
-               break;
-               }
 #endif
 
                connman_network_set_connected(network, false);
@@ -2749,6 +3860,7 @@ static void interface_state(GSupplicantInterface *interface)
                break;
        }
 
+       old_connected = wifi->connected;
        wifi->state = state;
 
        /* Saving wpa_s state policy:
@@ -2760,10 +3872,6 @@ static void interface_state(GSupplicantInterface *interface)
         * --> We are not connected
         * */
        switch (state) {
-#if defined TIZEN_EXT
-       case G_SUPPLICANT_STATE_SCANNING:
-               break;
-#endif
        case G_SUPPLICANT_STATE_AUTHENTICATING:
        case G_SUPPLICANT_STATE_ASSOCIATING:
        case G_SUPPLICANT_STATE_ASSOCIATED:
@@ -2772,8 +3880,12 @@ static void interface_state(GSupplicantInterface *interface)
                if (wifi->connected)
                        connman_warn("Probably roaming right now!"
                                                " Staying connected...");
-               else
-                       wifi->connected = false;
+               break;
+       case G_SUPPLICANT_STATE_SCANNING:
+               wifi->connected = false;
+
+               if (old_connected)
+                       start_autoscan(device);
                break;
        case G_SUPPLICANT_STATE_COMPLETED:
                wifi->connected = true;
@@ -2795,6 +3907,21 @@ static void interface_removed(GSupplicantInterface *interface)
 
        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;
 
@@ -2809,29 +3936,32 @@ 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])
 {
        const char *oui = "0050F204";
-       const char *category = "0100";
+       const char *category = "0001";
        const char *sub_category = "0000";
 
        if (!g_strcmp0(type, "handset")) {
-               category = "0A00";
-               sub_category = "0500";
+               category = "000A";
+               sub_category = "0005";
        } else if (!g_strcmp0(type, "vm") || !g_strcmp0(type, "container"))
-               sub_category = "0100";
+               sub_category = "0001";
        else if (!g_strcmp0(type, "server"))
-               sub_category = "0200";
+               sub_category = "0002";
        else if (!g_strcmp0(type, "laptop"))
-               sub_category = "0500";
+               sub_category = "0005";
        else if (!g_strcmp0(type, "desktop"))
-               sub_category = "0600";
+               sub_category = "0006";
        else if (!g_strcmp0(type, "tablet"))
-               sub_category = "0900";
+               sub_category = "0009";
        else if (!g_strcmp0(type, "watch"))
-               category = "FF00";
+               category = "00FF";
 
        snprintf(dev_type, 17, "%s%s%s", category, oui, sub_category);
 }
@@ -2843,6 +3973,9 @@ static void p2p_support(GSupplicantInterface *interface)
 
        DBG("");
 
+       if (!interface)
+               return;
+
        if (!g_supplicant_interface_has_p2p(interface))
                return;
 
@@ -2902,17 +4035,140 @@ static void scan_finished(GSupplicantInterface *interface)
 #endif
 }
 
+static void ap_create_fail(GSupplicantInterface *interface)
+{
+       struct wifi_data *wifi = g_supplicant_interface_get_data(interface);
+       int ret;
+
+       if ((wifi->tethering) && (wifi->tethering_param)) {
+               DBG("%s create AP fail \n",
+                               g_supplicant_interface_get_ifname(wifi->interface));
+
+               connman_inet_remove_from_bridge(wifi->index, wifi->bridge);
+               wifi->ap_supported = WIFI_AP_NOT_SUPPORTED;
+               wifi->tethering = false;
+
+               ret = tech_set_tethering(wifi->tethering_param->technology,
+                               wifi->tethering_param->ssid->ssid,
+                               wifi->tethering_param->ssid->passphrase,
+                               wifi->bridge, true);
+
+               if ((ret == -EOPNOTSUPP) && (wifi_technology)) {
+                       connman_technology_tethering_notify(wifi_technology,false);
+               }
+
+               g_free(wifi->tethering_param->ssid);
+               g_free(wifi->tethering_param);
+               wifi->tethering_param = NULL;
+       }
+
+       return;
+}
+
 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;
@@ -2926,6 +4182,11 @@ static void network_added(GSupplicantNetwork *supplicant_network)
        bool wps_ready;
        bool wps_advertizing;
 
+#if defined TIZEN_EXT
+       GSList *vsie_list = NULL;
+       const unsigned char *country_code;
+#endif
+
        mode = g_supplicant_network_get_mode(supplicant_network);
        identifier = g_supplicant_network_get_identifier(supplicant_network);
 
@@ -2934,6 +4195,13 @@ 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);
        wifi = g_supplicant_interface_get_data(interface);
        name = g_supplicant_network_get_name(supplicant_network);
@@ -2973,6 +4241,15 @@ 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);
+#endif
        connman_network_set_string(network, "WiFi.Security", security);
        connman_network_set_strength(network,
                                calculate_strength(supplicant_network));
@@ -3004,6 +4281,10 @@ static void network_added(GSupplicantNetwork *supplicant_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));
 #endif
        connman_network_set_available(network, true);
        connman_network_set_string(network, "WiFi.Mode", mode);
@@ -3047,6 +4328,15 @@ 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);
        wifi = g_supplicant_interface_get_data(interface);
        identifier = g_supplicant_network_get_identifier(network);
@@ -3091,6 +4381,8 @@ static void network_changed(GSupplicantNetwork *network, const char *property)
        unsigned int maxrate;
        uint16_t frequency;
        bool wps;
+       const unsigned char *country_code;
+       GSList *bssid_list;
 #endif
 
        interface = g_supplicant_network_get_interface(network);
@@ -3123,9 +4415,64 @@ static void network_changed(GSupplicantNetwork *network, const char *property)
        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);
 #endif
 }
 
+static void network_associated(GSupplicantNetwork *network)
+{
+       GSupplicantInterface *interface;
+       struct wifi_data *wifi;
+       struct connman_network *connman_network;
+       const char *identifier;
+
+       DBG("");
+
+       interface = g_supplicant_network_get_interface(network);
+       if (!interface)
+               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;
+
+       if (wifi->network) {
+               if (wifi->network == connman_network)
+                       return;
+
+               /*
+                * This should never happen, we got associated with
+                * a network different than the one we were expecting.
+                */
+               DBG("Associated to %p while expecting %p",
+                                       connman_network, wifi->network);
+
+               connman_network_set_associating(wifi->network, false);
+       }
+
+       DBG("Reconnecting to previous network %p from wpa_s", connman_network);
+
+       wifi->network = connman_network_ref(connman_network);
+       wifi->retries = 0;
+
+       /*
+        * Interface state changes callback (interface_state) is always
+        * called before network_associated callback thus we need to call
+        * interface_state again in order to process the new state now that
+        * we have the network properly set.
+        */
+       interface_state(interface);
+}
+
 static void apply_peer_services(GSupplicantPeer *peer,
                                struct connman_peer *connman_peer)
 {
@@ -3161,7 +4508,10 @@ static void peer_found(GSupplicantPeer *peer)
        struct connman_peer *connman_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);
 
@@ -3179,6 +4529,8 @@ static void peer_found(GSupplicantPeer *peer)
        ret = connman_peer_register(connman_peer);
        if (ret < 0 && ret != -EALREADY)
                connman_peer_unref(connman_peer);
+       else
+               wifi->peers = g_slist_prepend(wifi->peers, connman_peer);
 }
 
 static void peer_lost(GSupplicantPeer *peer)
@@ -3204,6 +4556,8 @@ static void peer_lost(GSupplicantPeer *peer)
                connman_peer_unregister(connman_peer);
                connman_peer_unref(connman_peer);
        }
+
+       wifi->peers = g_slist_remove(wifi->peers, connman_peer);
 }
 
 static void peer_changed(GSupplicantPeer *peer, GSupplicantPeerState state)
@@ -3218,6 +4572,9 @@ static void peer_changed(GSupplicantPeer *peer, GSupplicantPeerState state)
 
        DBG("ident: %s", identifier);
 
+       if (!wifi)
+               return;
+
        connman_peer = connman_peer_get(wifi->device, identifier);
        if (!connman_peer)
                return;
@@ -3280,6 +4637,14 @@ static void peer_changed(GSupplicantPeer *peer, GSupplicantPeerState state)
                connman_peer_set_as_master(connman_peer,
                                        !g_supplicant_peer_is_client(peer));
                connman_peer_set_sub_device(connman_peer, g_wifi->device);
+
+               /*
+                * If wpa_supplicant didn't create a dedicated p2p-group
+                * interface then mark this interface as p2p_device to avoid
+                * scan and auto-scan are launched on it while P2P is connected.
+                */
+               if (!g_list_find(p2p_iface_list, g_wifi))
+                       wifi->p2p_device = true;
        }
 
        connman_peer_set_state(connman_peer, p_state);
@@ -3292,6 +4657,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);
@@ -3331,7 +4701,7 @@ static void network_merged(GSupplicantNetwork *network)
        struct wifi_data *wifi;
        const char *identifier;
        struct connman_network *connman_network;
-       unsigned int ishs20AP = 0;
+       bool ishs20AP = 0;
        char *temp = NULL;
 
        interface = g_supplicant_network_get_interface(network);
@@ -3373,7 +4743,6 @@ static void network_merged(GSupplicantNetwork *network)
        }
 
        ishs20AP = g_supplicant_network_is_hs20AP(network);
-       connman_network_set_is_hs20AP(connman_network, ishs20AP);
 
        if (ishs20AP &&
                g_strcmp0(g_supplicant_network_get_security(network), "ieee8021x") == 0) {
@@ -3390,6 +4759,12 @@ static void network_merged(GSupplicantNetwork *network)
 
        wifi->network = connman_network;
 }
+
+static void assoc_failed(void *user_data)
+{
+       struct connman_network *network = user_data;
+       connman_network_set_associating(network, false);
+}
 #endif
 
 static void debug(const char *str)
@@ -3408,6 +4783,14 @@ static void disconnect_reasoncode(GSupplicantInterface *interface,
        }
 }
 
+static void assoc_status_code(GSupplicantInterface *interface, int status_code)
+{
+       struct wifi_data *wifi = g_supplicant_interface_get_data(interface);
+
+       if (wifi != NULL) {
+               wifi->assoc_code = status_code;
+       }
+}
 
 static const GSupplicantCallbacks callbacks = {
        .system_ready           = system_ready,
@@ -3418,9 +4801,11 @@ static const GSupplicantCallbacks callbacks = {
        .p2p_support            = p2p_support,
        .scan_started           = scan_started,
        .scan_finished          = scan_finished,
+       .ap_create_fail         = ap_create_fail,
        .network_added          = network_added,
        .network_removed        = network_removed,
        .network_changed        = network_changed,
+       .network_associated     = network_associated,
        .add_station            = add_station,
        .remove_station         = remove_station,
        .peer_found             = peer_found,
@@ -3430,9 +4815,18 @@ static const GSupplicantCallbacks callbacks = {
 #if defined TIZEN_EXT
        .system_power_off       = system_power_off,
        .network_merged = network_merged,
+       .assoc_failed           = assoc_failed,
 #endif
-       .disconnect_reasoncode  = disconnect_reasoncode,
        .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
 };
 
 
@@ -3448,15 +4842,8 @@ static void tech_remove(struct connman_technology *technology)
        wifi_technology = NULL;
 }
 
-struct wifi_tethering_info {
-       struct wifi_data *wifi;
-       struct connman_technology *technology;
-       char *ifname;
-       GSupplicantSSID *ssid;
-};
-
 static GSupplicantSSID *ssid_ap_init(const char *ssid,
-               const char *passphrase, bool hidden)
+               const char *passphrase)
 {
        GSupplicantSSID *ap;
 
@@ -3465,7 +4852,11 @@ static GSupplicantSSID *ssid_ap_init(const char *ssid,
                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;
@@ -3481,12 +4872,6 @@ static GSupplicantSSID *ssid_ap_init(const char *ssid,
               ap->passphrase = passphrase;
        }
 
-       if (hidden)
-               ap->ignore_broadcast_ssid =
-                               G_SUPPLICANT_AP_HIDDEN_SSID_ZERO_CONTENTS;
-       else
-               ap->ignore_broadcast_ssid = G_SUPPLICANT_AP_NO_SSID_HIDING;
-
        return ap;
 }
 
@@ -3498,10 +4883,16 @@ static void ap_start_callback(int result, GSupplicantInterface *interface,
        DBG("result %d index %d bridge %s",
                result, info->wifi->index, info->wifi->bridge);
 
-       if (result < 0) {
+       if ((result < 0) || (info->wifi->ap_supported != WIFI_AP_SUPPORTED)) {
                connman_inet_remove_from_bridge(info->wifi->index,
                                                        info->wifi->bridge);
-               connman_technology_tethering_notify(info->technology, false);
+
+               if (info->wifi->ap_supported == WIFI_AP_SUPPORTED) {
+                       connman_technology_tethering_notify(info->technology, false);
+                       g_free(info->wifi->tethering_param->ssid);
+                       g_free(info->wifi->tethering_param);
+                       info->wifi->tethering_param = NULL;
+               }
        }
 
        g_free(info->ifname);
@@ -3517,10 +4908,17 @@ static void ap_create_callback(int result,
        DBG("result %d ifname %s", result,
                                g_supplicant_interface_get_ifname(interface));
 
-       if (result < 0) {
+       if ((result < 0) || (info->wifi->ap_supported != WIFI_AP_SUPPORTED)) {
                connman_inet_remove_from_bridge(info->wifi->index,
                                                        info->wifi->bridge);
-               connman_technology_tethering_notify(info->technology, false);
+
+               if (info->wifi->ap_supported == WIFI_AP_SUPPORTED) {
+                       connman_technology_tethering_notify(info->technology, false);
+                       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);
@@ -3547,27 +4945,32 @@ static void sta_remove_callback(int result,
 
        DBG("ifname %s result %d ", info->ifname, result);
 
-       if (result < 0) {
-               info->wifi->tethering = true;
+       if (result < 0 || (info->wifi->ap_supported != WIFI_AP_SUPPORTED)) {
+               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;
+               }
                return;
        }
 
        info->wifi->interface = NULL;
 
-       connman_technology_tethering_notify(info->technology, true);
-
        g_supplicant_interface_create(info->ifname, driver, info->wifi->bridge,
                                                ap_create_callback,
                                                        info);
 }
 
-static int tech_set_tethering(struct connman_technology *technology,
-                               const char *identifier, const char *passphrase,
-                               const char *bridge, bool enabled, bool hidden)
+static int enable_wifi_tethering(struct connman_technology *technology,
+                               const char *bridge, const char *identifier,
+                               const char *passphrase, bool available)
 {
        GList *list;
        GSupplicantInterface *interface;
@@ -3575,75 +4978,143 @@ static int tech_set_tethering(struct connman_technology *technology,
        struct wifi_tethering_info *info;
        const char *ifname;
        unsigned int mode;
-       int err;
-
-       DBG("");
-
-       if (!enabled) {
-               for (list = iface_list; list; list = list->next) {
-                       wifi = list->data;
-
-                       if (wifi->tethering) {
-                               wifi->tethering = false;
-
-                               connman_inet_remove_from_bridge(wifi->index,
-                                                                       bridge);
-                               wifi->bridged = false;
-                       }
-               }
-
-               connman_technology_tethering_notify(technology, false);
-
-               return 0;
-       }
+       int err, berr = 0;
 
        for (list = iface_list; list; list = list->next) {
                wifi = list->data;
 
+               DBG("wifi %p network %p pending_network %p", wifi,
+                       wifi->network, wifi->pending_network);
+
                interface = wifi->interface;
 
                if (!interface)
                        continue;
 
+               if (wifi->ap_supported == WIFI_AP_NOT_SUPPORTED)
+                       continue;
+
                ifname = g_supplicant_interface_get_ifname(wifi->interface);
 
+               if (wifi->ap_supported == WIFI_AP_NOT_SUPPORTED) {
+                       DBG("%s does not support AP mode (detected)", ifname);
+                       continue;
+               }
+
                mode = g_supplicant_interface_get_mode(interface);
                if ((mode & G_SUPPLICANT_CAPABILITY_MODE_AP) == 0) {
-                       DBG("%s does not support AP mode", ifname);
+                       wifi->ap_supported = WIFI_AP_NOT_SUPPORTED;
+                       DBG("%s does not support AP mode (capability)", ifname);
                        continue;
                }
 
+               if (wifi->network && available)
+                       continue;
+
                info = g_try_malloc0(sizeof(struct wifi_tethering_info));
                if (!info)
                        return -ENOMEM;
 
+               wifi->tethering_param = g_try_malloc0(sizeof(struct wifi_tethering_info));
+               if (!wifi->tethering_param) {
+                       g_free(info);
+                       return -ENOMEM;
+               }
+
                info->wifi = wifi;
                info->technology = technology;
                info->wifi->bridge = bridge;
-               info->ssid = ssid_ap_init(identifier, passphrase, hidden);
-               if (!info->ssid) {
-                       g_free(info);
-                       continue;
-               }
+               info->ssid = ssid_ap_init(identifier, passphrase);
+               if (!info->ssid)
+                       goto failed;
+
                info->ifname = g_strdup(ifname);
-               if (!info->ifname) {
-                       g_free(info->ssid);
-                       g_free(info);
-                       continue;
-               }
+               if (!info->ifname)
+                       goto failed;
+
+               wifi->tethering_param->technology = technology;
+               wifi->tethering_param->ssid = ssid_ap_init(identifier, passphrase);
+               if (!wifi->tethering_param->ssid)
+                       goto failed;
 
                info->wifi->tethering = true;
+               info->wifi->ap_supported = WIFI_AP_SUPPORTED;
+
+               berr = connman_technology_tethering_notify(technology, true);
+               if (berr < 0)
+                       goto failed;
 
                err = g_supplicant_interface_remove(interface,
                                                sta_remove_callback,
                                                        info);
-               if (err == 0)
-                       return err;
+               if (err >= 0) {
+                       DBG("tethering wifi %p ifname %s", wifi, ifname);
+                       return 0;
+               }
+
+       failed:
+               g_free(info->ifname);
+               g_free(info->ssid);
+               g_free(info);
+               g_free(wifi->tethering_param);
+               wifi->tethering_param = NULL;
+
+               /*
+                * Remove bridge if it was correctly created but remove
+                * operation failed. Instead, if bridge creation failed then
+                * break out and do not try again on another interface,
+                * bridge set-up does not depend on it.
+                */
+               if (berr == 0)
+                       connman_technology_tethering_notify(technology, false);
+               else
+                       break;
        }
 
        return -EOPNOTSUPP;
 }
 
+static int tech_set_tethering(struct connman_technology *technology,
+                               const char *identifier, const char *passphrase,
+                               const char *bridge, bool enabled)
+{
+       GList *list;
+       struct wifi_data *wifi;
+       int err;
+
+       DBG("");
+
+       if (!enabled) {
+               for (list = iface_list; list; list = list->next) {
+                       wifi = list->data;
+
+                       if (wifi->tethering) {
+                               wifi->tethering = false;
+
+                               connman_inet_remove_from_bridge(wifi->index,
+                                                                       bridge);
+                               wifi->bridged = false;
+                       }
+               }
+
+               connman_technology_tethering_notify(technology, false);
+
+               return 0;
+       }
+
+       DBG("trying tethering for available devices");
+       err = enable_wifi_tethering(technology, bridge, identifier, passphrase,
+                               true);
+
+       if (err < 0) {
+               DBG("trying tethering for any device");
+               err = enable_wifi_tethering(technology, bridge, identifier,
+                                       passphrase, false);
+       }
+
+       return err;
+}
+
 static void regdom_callback(int result, const char *alpha2, void *user_data)
 {
        DBG("");