Send Dbus error message to upper layer
[platform/core/connectivity/net-config.git] / src / wifi-tdls.c
index 6e331fc..7b301fb 100755 (executable)
@@ -40,6 +40,7 @@ char *peer_mac = NULL;
 int is_connected = 0;
 static gint tdls_timer_id = 0;
 int is_discover_broadcast = 0;
+int is_timer_expired = 0;
 
 #define TDLS_DISCOVER_TIMOUT 4 /*TDLS Unicast Discovery Timeout*/
 #define TDLS_DISCOVER_BROADCAST_TIMOUT 8 /*TDLS Broadcast Discovery Timeout*/
@@ -101,13 +102,15 @@ static gboolean _tdls_timer_discover_event(gpointer user_data)
        __netconfig_wifi_notify_tdls_discover_event("00:00:00:00:00:00", is_discover_broadcast);
        is_discover_broadcast = 0;
        stop_tdls_timer();
+       is_timer_expired = 1;
+
        return FALSE;
 }
 
 static GVariant * __netconfig_wifi_tdls_send_dbus_str(const char* method, const char *str)
 {
        GVariant *message = NULL;
-       const char *if_path = NULL;
+       char *if_path = NULL;
        GVariant *params = NULL;
 
        if_path = netconfig_wifi_get_supplicant_interface();
@@ -121,6 +124,7 @@ static GVariant * __netconfig_wifi_tdls_send_dbus_str(const char* method, const
        message = netconfig_invoke_dbus_method(SUPPLICANT_SERVICE,
                        if_path, SUPPLICANT_INTERFACE ".Interface", method, params);
 
+       g_free(if_path);
        INFO("TDLS Returned from Blocking method for Send DBUS Command");
        return message;
 }
@@ -180,7 +184,7 @@ gboolean handle_tdls_connect(Wifi *wifi, GDBusMethodInvocation *context,
                if (message == NULL) {
                        ERR(" TDLS : failed to connect !!!");
                        netconfig_error_dbus_method_return(context, NETCONFIG_ERROR_INTERNAL, "FailTdlsConnect");
-                       return FALSE;
+                       return TRUE;
                }
 
                DBG("[TizenMW<--WPAS] TDLS DBUS Command sent successfully");
@@ -199,13 +203,20 @@ gboolean handle_tdls_discover(Wifi *wifi, GDBusMethodInvocation *context,
        int discover_timeout = 0;
 
        GVariant *message = NULL;
+
+       if (tdls_timer_id > 0) {
+               DBG(" TDLS Discover is already progress !!!");
+               wifi_complete_tdls_discover(wifi, context, NETCONFIG_ERROR_TDLS_ALREADY_DONE);
+               return TRUE;
+       }
+
        message = __netconfig_wifi_tdls_send_dbus_str("TDLSDiscover", (const char*)peer_mac_Addr);
 
        if (message == NULL) {
                ERR(" TDLS : failed to discover !!!");
                netconfig_error_dbus_method_return(context, NETCONFIG_ERROR_INTERNAL, "FailTdlsDiscover");
                wifi_complete_tdls_discover(wifi, context, NETCONFIG_ERROR_TDLS_FAIL_DISCOVER);
-               return FALSE;
+               return TRUE;
        }
 
        DBG(" TDLS DBUS Command sent successfully");
@@ -220,6 +231,7 @@ gboolean handle_tdls_discover(Wifi *wifi, GDBusMethodInvocation *context,
                discover_timeout = TDLS_DISCOVER_TIMOUT;
        }
 
+       is_timer_expired = 0;
        tdls_timer_id = g_timeout_add_seconds(discover_timeout,
                                        _tdls_timer_discover_event, NULL);
 
@@ -242,7 +254,7 @@ gboolean handle_tdls_disconnect(Wifi *wifi, GDBusMethodInvocation *context,
                if (message == NULL) {
                        ERR(" TDLS : failed to disconnect !!!");
                        netconfig_error_dbus_method_return(context, NETCONFIG_ERROR_INTERNAL, "FailTdlsDisconnect");
-                       return FALSE;
+                       return TRUE;
                }
 
                DBG("[TizenMW<--WPAS] TDLS DBUS Command sent successfully");
@@ -297,7 +309,7 @@ gboolean handle_tdls_channel_switch(Wifi *wifi, GDBusMethodInvocation *context,
        GVariant *message = NULL;
        GVariantBuilder *builder;
        GVariant *params;
-       const char *if_path = NULL;
+       char *if_path = NULL;
        unsigned char oper_class = 0;
 
        if (peer_mac_Addr == NULL) {
@@ -319,7 +331,7 @@ gboolean handle_tdls_channel_switch(Wifi *wifi, GDBusMethodInvocation *context,
        builder = g_variant_builder_new(G_VARIANT_TYPE("a{sv}"));
 
        g_variant_builder_add(builder, "{sv}", "PeerAddress", g_variant_new_string(peer_mac_Addr));
-       g_variant_builder_add(builder, "{sv}", "Frequency", g_variant_new_int32(freq));
+       g_variant_builder_add(builder, "{sv}", "Frequency", g_variant_new_uint32(freq));
        g_variant_builder_add(builder, "{sv}", "OperClass", g_variant_new_byte(oper_class));
        params = g_variant_new("(@a{sv})", g_variant_builder_end(builder));
        g_variant_builder_unref(builder);
@@ -336,6 +348,7 @@ gboolean handle_tdls_channel_switch(Wifi *wifi, GDBusMethodInvocation *context,
        message = netconfig_invoke_dbus_method(SUPPLICANT_SERVICE,
                                if_path, SUPPLICANT_INTERFACE ".Interface", "TDLSChannelSwitch", params);
 
+       g_free(if_path);
        if (message == NULL) {
                ERR(" TDLS : Fail to Process TDLS Channel Switch Request !!!");
                wifi_complete_tdls_channel_switch(wifi, context,
@@ -408,16 +421,19 @@ void netconfig_wifi_tdls_disconnected_event(GVariant *message)
 
 void netconfig_wifi_tdls_peer_found_event(GVariant *message)
 {
-       DBG("WiFi TDLS Discovery EVENT");
+       DBG("WiFi TDLS Discovery EVENT Received !!");
        const gchar *peer_mac_addr = NULL;
 
-       g_variant_get(message, "(s)", &peer_mac_addr);
-       INFO("Discover Peer Mac Address: [%s]", peer_mac_addr);
+       if (!is_timer_expired) {
 
+               g_variant_get(message, "(s)", &peer_mac_addr);
+               INFO("Discover Peer Mac Address: [%s]", peer_mac_addr);
 
-       if (is_discover_broadcast == 0)
-               stop_tdls_timer();
+               if (is_discover_broadcast == 0)
+                       stop_tdls_timer();
 
-       __netconfig_wifi_notify_tdls_discover_event(peer_mac_addr, is_discover_broadcast);
+               __netconfig_wifi_notify_tdls_discover_event(peer_mac_addr, is_discover_broadcast);
+       } else
+               DBG("Timer expired: Do not process the TDLS Discovery Event");
 }