Added handling to support TDLS feature #2
[platform/core/connectivity/net-config.git] / src / wifi-tdls.c
index 14366c9..3ae0291 100755 (executable)
@@ -39,7 +39,7 @@
 char *peer_mac = NULL;
 int is_connected = 0;
 
-void __netconfig_wifi_notify_tdls_event(const char *sig_name,const char *peer_mac)
+void __netconfig_wifi_notify_tdls_event(const char *sig_name, const char *peer_mac)
 {
        GVariantBuilder *builder;
        GVariant *params;
@@ -71,7 +71,7 @@ static GVariant * __netconfig_wifi_tdls_send_dbus_str(const char* method, const
        }
 
        params = g_variant_new("(s)", str);
-       INFO("[TizenMW-->WPAS] Sent Dbus Method :[%s],value[%s]", method,str);
+       INFO("[TizenMW-->WPAS] Sent Dbus Method :[%s],value[%s]", method, str);
        message = netconfig_invoke_dbus_method(SUPPLICANT_SERVICE,
                        if_path, SUPPLICANT_INTERFACE ".Interface", method, params);
 
@@ -79,17 +79,73 @@ static GVariant * __netconfig_wifi_tdls_send_dbus_str(const char* method, const
        return message;
 }
 
+gboolean handle_tdls_connect(Wifi *wifi, GDBusMethodInvocation *context,
+                       gchar *peer_mac_Addr)
+{
+       DBG("[TizenMW-->WPAS]: TDLS Setup Request: [%s]", peer_mac_Addr);
+
+       if (is_connected) {
+               ERR(" Already active TDLS Connection !!!");
+       } else {
+               GVariant *message = NULL;
+               message = __netconfig_wifi_tdls_send_dbus_str("TDLSSetup", (const char*)peer_mac_Addr);
+
+               if (message == NULL) {
+                       ERR(" TDLS : failed to connect !!!");
+                       netconfig_error_dbus_method_return(context, NETCONFIG_ERROR_INTERNAL, "FailTdlsConnect");
+                       return FALSE;
+               }
+
+               DBG("[TizenMW<--WPAS] TDLS DBUS Command sent successfully");
+               g_variant_unref(message);
+               is_connected = 1;
+       }
+
+       wifi_complete_tdls_connect(wifi, context, 1);
+       return TRUE;
+}
+
+gboolean handle_tdls_discover(Wifi *wifi, GDBusMethodInvocation *context)
+{
+       DBG("[TizenMW-->WPAS]: TDLS Discover Request ");
+
+       if (is_connected) {
+               ERR(" Already active TDLS Connection !!!");
+       } else {
+               GVariant *message = NULL;
+               message = __netconfig_wifi_tdls_send_dbus_str("TDLSDiscover", "ff:ff:ff:ff:ff:ff");
+
+               if (message == NULL) {
+                       ERR(" TDLS : failed to discover !!!");
+                       netconfig_error_dbus_method_return(context, NETCONFIG_ERROR_INTERNAL, "FailTdlsDiscover");
+                       return FALSE;
+               }
+
+               DBG("[TizenMW<--WPAS] TDLS DBUS Command sent successfully");
+               g_variant_unref(message);
+       }
+
+       wifi_complete_tdls_discover(wifi, context);
+       return TRUE;
+}
+
 gboolean handle_tdls_disconnect(Wifi *wifi, GDBusMethodInvocation *context,
                        gchar *peer_mac_Addr)
 {
        DBG("[TizenMW-->WPAS]: TDLS Teardown Request: [%s]", peer_mac_Addr);
 
-       if(!is_connected) {
+       if (!is_connected) {
                ERR(" No active TDLS Connection !!!");
-
        } else {
                GVariant *message = NULL;
                message = __netconfig_wifi_tdls_send_dbus_str("TDLSTeardown", (const char*)peer_mac_Addr);
+
+               if (message == NULL) {
+                       ERR(" TDLS : failed to disconnect !!!");
+                       netconfig_error_dbus_method_return(context, NETCONFIG_ERROR_INTERNAL, "FailTdlsDisconnect");
+                       return FALSE;
+               }
+
                DBG("[TizenMW<--WPAS] TDLS DBUS Command sent successfully");
                g_variant_unref(message);
                is_connected = 0;
@@ -136,7 +192,7 @@ gboolean handle_tdls_connected_peer(Wifi *wifi, GDBusMethodInvocation *context)
        return TRUE;
 }
 
-void netconfig_wifi_tlds_connected_event(GVariant *message)
+void netconfig_wifi_tdls_connected_event(GVariant *message)
 {
 
        DBG("[TizenMW<--WPAS] WiFi TDLS Connected EVENT");
@@ -152,7 +208,7 @@ void netconfig_wifi_tlds_connected_event(GVariant *message)
        __netconfig_wifi_notify_tdls_event("TDLSConnect", peer_mac);
 }
 
-void netconfig_wifi_tlds_disconnected_event(GVariant *message)
+void netconfig_wifi_tdls_disconnected_event(GVariant *message)
 {
        DBG("[TizenMW<--WPAS]: WiFi TDLS Disconnected EVENT");
        const gchar *peer_mac_addr = NULL;
@@ -161,7 +217,20 @@ void netconfig_wifi_tlds_disconnected_event(GVariant *message)
        if (g_strcmp0(peer_mac, peer_mac_addr) == 0) {
                INFO("TDLS Peer Disconnected Mac Address: [%s]", peer_mac);
                is_connected = 0;
-               __netconfig_wifi_notify_tdls_event("TDLSDisconnect",peer_mac);
+               __netconfig_wifi_notify_tdls_event("TDLSDisconnect", peer_mac);
        } else
                INFO("TDLS Peer Disconnected peer_mac(%s) != peer_mac_address(%s)", peer_mac, peer_mac_addr);
 }
+
+
+void netconfig_wifi_tdls_peer_found_event(GVariant *message)
+{
+       DBG("[TizenMW<--WPAS]: WiFi TDLS Discovery EVENT");
+       const gchar *peer_mac_addr = NULL;
+
+       g_variant_get(message, "(s)", &peer_mac_addr);
+       INFO("Discover Peer Mac Address: [%s]", peer_mac_addr);
+
+       __netconfig_wifi_notify_tdls_event("TDLSPeerFound", peer_mac_addr);
+}
+