From f8dc25aea5d2babe55ff6d3b405928b67bd1f709 Mon Sep 17 00:00:00 2001 From: Maneesh Jain Date: Fri, 7 Apr 2017 16:55:53 +0530 Subject: [PATCH] [net-config]:Refactor the TDLS Discovery Feature Change-Id: Ifd7fe7b2fa1b59823bdda2d61b375d52aca378ca Signed-off-by: Maneesh Jain --- include/wifi-tdls.h | 10 ++++- src/wifi-tdls.c | 105 +++++++++++++++++++++++++++++++++++++++++----------- 2 files changed, 92 insertions(+), 23 deletions(-) diff --git a/include/wifi-tdls.h b/include/wifi-tdls.h index 3b9bf0e..616e540 100755 --- a/include/wifi-tdls.h +++ b/include/wifi-tdls.h @@ -26,6 +26,15 @@ #include #include "netsupplicant.h" + +typedef enum { + NETCONFIG_ERROR_TDLS_NO_ERROR = 0x00, + NETCONFIG_ERROR_TDLS_FAIL_DISCOVER = 0x01, + NETCONFIG_ERROR_TDLS_FAIL_DISCONNECT = 0x02, + NETCONFIG_ERROR_TDLS_FAIL_CONNECT = 0x03, + NETCONFIG_ERROR_TDLS_ALREADY_DONE = 0x04, +} netconfig_tdls_error_e; + void netconfig_wifi_tdls_peer_found_event(GVariant *message); void netconfig_wifi_tdls_connected_event(GVariant *message); void netconfig_wifi_tdls_disconnected_event(GVariant *message); @@ -35,7 +44,6 @@ gboolean handle_tdls_connected_peer(Wifi *wifi, GDBusMethodInvocation *context); gboolean handle_tdls_connect(Wifi *wifi, GDBusMethodInvocation *context, gchar *peer_mac_Addr); gboolean handle_tdls_discover(Wifi *wifi, GDBusMethodInvocation *context, gchar *peer_mac_Addr); - #ifdef __cplusplus } #endif diff --git a/src/wifi-tdls.c b/src/wifi-tdls.c index 182efea..cd09f21 100755 --- a/src/wifi-tdls.c +++ b/src/wifi-tdls.c @@ -38,6 +38,18 @@ char *peer_mac = NULL; int is_connected = 0; +static gint tdls_timer_id = 0; +int is_discover_broadcast = 0; + +#define TDLS_DISCOVER_TIMOUT 4 /*TDLS Unicast Discovery Timeout*/ +#define TDLS_DISCOVER_BROADCAST_TIMOUT 8 /*TDLS Broadcast Discovery Timeout*/ +static void stop_tdls_timer() +{ + if (tdls_timer_id > 0) { + g_source_remove(tdls_timer_id); + tdls_timer_id = 0; + } +} void __netconfig_wifi_notify_tdls_event(const char *sig_name, const char *peer_mac) { @@ -58,6 +70,40 @@ void __netconfig_wifi_notify_tdls_event(const char *sig_name, const char *peer_m INFO("Sent signal (%s) Peer Mac (%s)", sig_name, peer_mac); } +void __netconfig_wifi_notify_tdls_discover_event(const char *peer_mac, int discover_type) +{ + GVariantBuilder *builder; + GVariant *params; + builder = g_variant_builder_new(G_VARIANT_TYPE("a{sv}")); + + g_variant_builder_add(builder, "{sv}", "peermac", g_variant_new_string(peer_mac)); + g_variant_builder_add(builder, "{sv}", "discover_type", g_variant_new_int32(discover_type)); + + params = g_variant_new("(@a{sv})", g_variant_builder_end(builder)); + g_variant_builder_unref(builder); + + netconfig_dbus_emit_signal(NULL, + NETCONFIG_WIFI_PATH, + NETCONFIG_WIFI_INTERFACE, + "TDLSPeerFound", + params); + + INFO("Sent signal (%s) Peer Mac (%s)", "TDLSPeerFound", peer_mac); +} + +static gboolean _tdls_timer_discover_event(gpointer user_data) +{ + + if (tdls_timer_id == 0) + return FALSE; + + INFO("[TDLS Discover Timer Expired"); + __netconfig_wifi_notify_tdls_discover_event("00:00:00:00:00:00", is_discover_broadcast); + is_discover_broadcast = 0; + stop_tdls_timer(); + return FALSE; +} + static GVariant * __netconfig_wifi_tdls_send_dbus_str(const char* method, const char *str) { GVariant *message = NULL; @@ -71,7 +117,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); @@ -108,25 +154,35 @@ gboolean handle_tdls_connect(Wifi *wifi, GDBusMethodInvocation *context, gboolean handle_tdls_discover(Wifi *wifi, GDBusMethodInvocation *context, gchar *peer_mac_Addr) { - DBG("[TizenMW-->WPAS]: TDLS Discover Request: [%s], peer_mac_Addr"); + DBG("TDLS Discover Request: [%s]", peer_mac_Addr); + int discover_timeout = 0; - if (is_connected) { - ERR(" Already TDLS Connection !!!"); - } else { - GVariant *message = NULL; - message = __netconfig_wifi_tdls_send_dbus_str("TDLSDiscover", (const char*)peer_mac_Addr); + GVariant *message = NULL; + 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"); - return FALSE; - } + 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; + } - DBG("[TizenMW<--WPAS] TDLS DBUS Command sent successfully"); - g_variant_unref(message); + DBG(" TDLS DBUS Command sent successfully"); + g_variant_unref(message); + + if (NULL != strstr(peer_mac_Addr, "ff:ff:ff:ff:ff:ff")) { + DBG("TDLS: Broadcast Discovery"); + is_discover_broadcast = 1; + discover_timeout = TDLS_DISCOVER_BROADCAST_TIMOUT; + } else { + is_discover_broadcast = 0; + discover_timeout = TDLS_DISCOVER_TIMOUT; } - wifi_complete_tdls_discover(wifi, context, 1); + tdls_timer_id = g_timeout_add_seconds(discover_timeout, + _tdls_timer_discover_event, NULL); + + wifi_complete_tdls_discover(wifi, context, NETCONFIG_ERROR_TDLS_NO_ERROR); return TRUE; } @@ -136,7 +192,8 @@ gboolean handle_tdls_disconnect(Wifi *wifi, GDBusMethodInvocation *context, DBG("[TizenMW-->WPAS]: TDLS Teardown Request: [%s]", peer_mac_Addr); if (!is_connected) { - ERR(" Already TDLS discnnection !!!"); + ERR(" Already TDLS disconnection !!!"); + wifi_complete_tdls_disconnect(wifi, context, NETCONFIG_ERROR_TDLS_ALREADY_DONE); } else { GVariant *message = NULL; message = __netconfig_wifi_tdls_send_dbus_str("TDLSTeardown", (const char*)peer_mac_Addr); @@ -152,7 +209,7 @@ gboolean handle_tdls_disconnect(Wifi *wifi, GDBusMethodInvocation *context, is_connected = 0; } - wifi_complete_tdls_disconnect(wifi, context, 1); + wifi_complete_tdls_disconnect(wifi, context, NETCONFIG_ERROR_TDLS_NO_ERROR); return TRUE; } @@ -186,7 +243,7 @@ gboolean handle_tdls_connected_peer(Wifi *wifi, GDBusMethodInvocation *context) return TRUE; } - INFO("[TizenMW<--WPAS] TDLS Connection available, Peer Mac address %s", peer_mac); + INFO("TDLS Connection available, Peer Mac address %s", peer_mac); wifi_complete_tdls_connected_peer(wifi, context, peer_mac); g_variant_unref(message); @@ -196,7 +253,7 @@ gboolean handle_tdls_connected_peer(Wifi *wifi, GDBusMethodInvocation *context) void netconfig_wifi_tdls_connected_event(GVariant *message) { - DBG("[TizenMW<--WPAS] WiFi TDLS Connected EVENT"); + DBG("WiFi TDLS Connected EVENT"); if (is_connected == 1) { INFO("TDLS Peer already connected"); g_free(peer_mac); @@ -211,7 +268,7 @@ void netconfig_wifi_tdls_connected_event(GVariant *message) void netconfig_wifi_tdls_disconnected_event(GVariant *message) { - DBG("[TizenMW<--WPAS]: WiFi TDLS Disconnected EVENT"); + DBG("WiFi TDLS Disconnected EVENT"); const gchar *peer_mac_addr = NULL; g_variant_get(message, "(&s)", &peer_mac_addr); @@ -226,12 +283,16 @@ void netconfig_wifi_tdls_disconnected_event(GVariant *message) void netconfig_wifi_tdls_peer_found_event(GVariant *message) { - DBG("[TizenMW<--WPAS]: WiFi TDLS Discovery EVENT"); + DBG("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); + + if (is_discover_broadcast == 0) + stop_tdls_timer(); + + __netconfig_wifi_notify_tdls_discover_event(peer_mac_addr, is_discover_broadcast); } -- 2.7.4