From c7efe4303db9ea507f3ef1e035455db0d034ad52 Mon Sep 17 00:00:00 2001 From: hyunuktak Date: Wed, 16 Dec 2015 13:49:12 +0900 Subject: [PATCH] [ACR]Add new APIs for TDLS Change-Id: I4679c45379e0da8069bf1bed0be5f605583be4ff Signed-off-by: hyunuktak --- CMakeLists.txt | 1 + include/netdbus.h | 5 + include/wifi-tdls.h | 50 ++++++++ interfaces/netconfig-iface-wifi.xml | 7 ++ packaging/net-config.spec | 2 +- resources/etc/dbus-1/system.d/net-config.conf | 2 + src/dbus/netdbus.c | 29 +++++ src/signal-handler.c | 43 ++++++- src/wifi-tdls.c | 169 ++++++++++++++++++++++++++ src/wifi.c | 7 ++ 10 files changed, 313 insertions(+), 2 deletions(-) create mode 100755 include/wifi-tdls.h create mode 100755 src/wifi-tdls.c diff --git a/CMakeLists.txt b/CMakeLists.txt index d93dd7e..f257b9c 100755 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -9,6 +9,7 @@ SET(INTERFACES "${CMAKE_SOURCE_DIR}/interfaces") SET(SRCS src/main.c + src/wifi-tdls.c src/wifi.c src/neterror.c src/wifi-eap.c diff --git a/include/netdbus.h b/include/netdbus.h index b3e40e4..a4ba8e2 100755 --- a/include/netdbus.h +++ b/include/netdbus.h @@ -94,6 +94,11 @@ gboolean netconfig_invoke_dbus_method_nonblock(const char *dest, const char *pat GVariant *netconfig_invoke_dbus_method(const char *dest, const char *path, const char *interface_name, const char *method, GVariant *params); +gboolean netconfig_dbus_emit_signal(const gchar *destination_bus_name, + const gchar *object_path, + const gchar *interface_name, + const gchar *signal_name, + GVariant *params); int setup_gdbus(got_name_cb cb); void cleanup_gdbus(void); diff --git a/include/wifi-tdls.h b/include/wifi-tdls.h new file mode 100755 index 0000000..9f8ef29 --- /dev/null +++ b/include/wifi-tdls.h @@ -0,0 +1,50 @@ +/* + * Network Configuration Module + * + * Copyright (c) 2012-2013 Samsung Electronics Co., Ltd. All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ +#ifndef __TIZEN_NETWORK_WIFI_TDLS_H__ +#define __TIZEN_NETWORK_WIFI_TDLS_H__ + +#ifdef __cplusplus + extern "C" { +#endif + +#include +#include "netsupplicant.h" + +typedef struct { + int is_connected; + int hdcp; + int port; + int availability; + int tdls_support; + unsigned char ip_add[4]; +}wifi_tdls_wfd_info_s; + +void netconfig_wifi_tlds_connected_event(GVariant *message); +void netconfig_wifi_tlds_disconnected_event(GVariant *message); +void __netconfig_wifi_notify_tdls_connected_event(const char *peer_mac); +gboolean handle_tdls_disconnect(Wifi *wifi, GDBusMethodInvocation *context, gchar *peer_mac_addr); +gboolean handle_tdls_connected_peer(Wifi *wifi, GDBusMethodInvocation *context); + + +#ifdef __cplusplus +} +#endif + +#endif /* __TIZEN_NETWORK_WIFI_TDLS_H__ */ + diff --git a/interfaces/netconfig-iface-wifi.xml b/interfaces/netconfig-iface-wifi.xml index 6a5827b..ac59f08 100755 --- a/interfaces/netconfig-iface-wifi.xml +++ b/interfaces/netconfig-iface-wifi.xml @@ -101,6 +101,13 @@ + + + + + + + diff --git a/packaging/net-config.spec b/packaging/net-config.spec index e132cec..c3ad78a 100755 --- a/packaging/net-config.spec +++ b/packaging/net-config.spec @@ -1,6 +1,6 @@ Name: net-config Summary: TIZEN Network Configuration service -Version: 1.1.48 +Version: 1.1.49 Release: 2 Group: System/Network License: Apache-2.0 diff --git a/resources/etc/dbus-1/system.d/net-config.conf b/resources/etc/dbus-1/system.d/net-config.conf index 4196cb5..f7e997f 100755 --- a/resources/etc/dbus-1/system.d/net-config.conf +++ b/resources/etc/dbus-1/system.d/net-config.conf @@ -49,6 +49,8 @@ + + diff --git a/src/dbus/netdbus.c b/src/dbus/netdbus.c index d63397b..d998fb7 100755 --- a/src/dbus/netdbus.c +++ b/src/dbus/netdbus.c @@ -238,6 +238,35 @@ GVariant *netconfig_invoke_dbus_method(const char *dest, const char *path, return reply; } +gboolean netconfig_dbus_emit_signal(const gchar *destination_bus_name, + const gchar *object_path, + const gchar *interface_name, + const gchar *signal_name, + GVariant *params) +{ + gboolean rv = FALSE; + GError *Error = NULL; + GDBusConnection *connection; + + connection = netdbus_get_connection(); + if (connection == NULL) { + ERR("[NET_DBUS] GDBusconnection is NULL"); + return 0; + } + + rv = g_dbus_connection_emit_signal(connection, destination_bus_name, + object_path, interface_name, signal_name, params, &Error); + if (rv != TRUE) { + ERR("[NET_DBUS] Failed to emit signal, Error: %s", Error->message); + g_clear_error(&Error); + return rv; + } + + INFO("Sent signal (%s), Interface (%s)", signal_name, interface_name); + + return rv; +} + static void _got_bus_cb(GDBusConnection *conn, const gchar *name, gpointer user_data) { diff --git a/src/signal-handler.c b/src/signal-handler.c index 90fb9b8..b0d7c1b 100755 --- a/src/signal-handler.c +++ b/src/signal-handler.c @@ -36,6 +36,7 @@ #include "signal-handler.h" #include "wifi-ssid-scan.h" #include "wifi-background-scan.h" +#include "wifi-tdls.h" #if defined TIZEN_DEBUG_DISABLE #include "wifi-dump.h" @@ -49,6 +50,9 @@ #define SIGNAL_PROPERTIES_CHANGED "PropertiesChanged" #define SIGNAL_PROPERTIES_DRIVER_HANGED "DriverHanged" #define SIGNAL_PROPERTIES_SESSION_OVERLAPPED "SessionOverlapped" +#define SIGNAL_TDLS_CONNECTED "TDLSConnected" +#define SIGNAL_TDLS_DISCONNECTED "TDLSDisconnected" +#define SIGNAL_TDLS_PEER_FOUND "TDLSPeerFound" #define CONNMAN_SIGNAL_SERVICES_CHANGED "ServicesChanged" #define CONNMAN_SIGNAL_PROPERTY_CHANGED "PropertyChanged" #define CONNMAN_SIGNAL_NAME_CHANGED "NameOwnerChanged" @@ -63,6 +67,9 @@ typedef enum { SIG_SCAN_DONE, SIG_DRIVER_HANGED, SIG_SESSION_OVERLAPPED, + SIG_TDLS_CONNECTED, + SIG_TDLS_DISCONNECTED, + SIG_TDLS_PEER_FOUND, SIG_MAX } SuppSigArrayIndex; @@ -74,6 +81,9 @@ static const char supplicant_signals[SIG_MAX][MAX_SIG_LEN] = { SIGNAL_SCAN_DONE, SIGNAL_PROPERTIES_DRIVER_HANGED, SIGNAL_PROPERTIES_SESSION_OVERLAPPED, + SIGNAL_TDLS_CONNECTED, + SIGNAL_TDLS_DISCONNECTED, + SIGNAL_TDLS_PEER_FOUND, }; static int supp_subscription_ids[SIG_MAX] = {0}; @@ -430,13 +440,44 @@ static void _supplicant_session_overlapped(GDBusConnection *conn, #endif } +static void _supplicant_tdls_connected(GDBusConnection *conn, + const gchar *name, const gchar *path, const gchar *interface, + const gchar *sig, GVariant *param, gpointer user_data) +{ + ERR("Received TDLS Connected Signal"); + netconfig_wifi_tlds_connected_event(param); + + return; +} + +static void _supplicant_tdls_disconnected(GDBusConnection *conn, + const gchar *name, const gchar *path, const gchar *interface, + const gchar *sig, GVariant *param, gpointer user_data) +{ + ERR("Received TDLS Disconnected Signal"); + netconfig_wifi_tlds_disconnected_event(param); + + return; +} + +static void _supplicant_tdls_peer_found(GDBusConnection *conn, + const gchar *name, const gchar *path, const gchar *interface, + const gchar *sig, GVariant *param, gpointer user_data) +{ + ERR("Received TDLS Peer Found Signal"); + return; +} + static supplicant_signal_cb supplicant_cbs[SIG_MAX] = { _supplicant_interface_removed, _supplicant_properties_changed, _supplicant_bss_added, _supplicant_scan_done, _supplicant_driver_hanged, - _supplicant_session_overlapped + _supplicant_session_overlapped, + _supplicant_tdls_connected, + _supplicant_tdls_disconnected, + _supplicant_tdls_peer_found }; #if defined TIZEN_DEBUG_DISABLE diff --git a/src/wifi-tdls.c b/src/wifi-tdls.c new file mode 100755 index 0000000..de2ca17 --- /dev/null +++ b/src/wifi-tdls.c @@ -0,0 +1,169 @@ +/* + * Network Configuration Module + * + * Copyright (c) 2012-2013 Samsung Electronics Co., Ltd. All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +#include +#include +#include +#include +#include +#include +#include "neterror.h" +#include "netdbus.h" +#include "netsupplicant.h" +#include "network-state.h" +#include +#include +#include +#include +#include "util.h" +#include "neterror.h" +#include "wifi-tdls.h" +#include + +wifi_tdls_wfd_info_s peer_info; +char *peer_mac = NULL; + +void __netconfig_wifi_notify_tdls_event(const char *sig_name,const char *peer_mac) +{ + 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)); + + 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, + sig_name, + params); + + INFO("Sent signal (%s) Peer Mac (%s)", sig_name, peer_mac); +} + +static GVariant * __netconfig_wifi_tdls_send_dbus_str(const char* method, const char *str) +{ + GVariant *message = NULL; + const char *if_path = NULL; + GVariant *params = NULL; + + if_path = netconfig_wifi_get_supplicant_interface(); + if (if_path == NULL) { + ERR("Fail to get wpa_supplicant DBus path"); + return NULL; + } + + params = g_variant_new("(s)", 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); + + INFO("TDLS Returned from Blocking method for Send DBUS Command"); + return message; +} + +gboolean handle_tdls_disconnect(Wifi *wifi, GDBusMethodInvocation *context, + gchar *peer_mac_Addr) +{ + DBG("[TizenMW-->WPAS]: TDLS Teardown Request: [%s]", peer_mac_Addr); + + if(!peer_info.is_connected) { + ERR(" No active TDLS Connection !!!"); + + } else { + GVariant *message = NULL; + message = __netconfig_wifi_tdls_send_dbus_str("TDLSTeardown", (const char*)peer_mac_Addr); + DBG("[TizenMW<--WPAS] TDLS DBUS Command sent successfully"); + g_variant_unref(message); + peer_info.is_connected = 0; + } + + wifi_complete_tdls_disconnect(wifi, context, 1); + return TRUE; +} + +gboolean handle_tdls_connected_peer(Wifi *wifi, GDBusMethodInvocation *context) +{ + DBG("[TizenMW-->WPAS]: TDLS Connected Peer Request: "); + + GVariant *message = NULL; + const gchar* reply_str = NULL; + + if (peer_mac == NULL) { + INFO("TDLS: No Active Connection"); + wifi_complete_tdls_connected_peer(wifi, context, "00.00.00.00.00.00"); + return TRUE; + } + message = __netconfig_wifi_tdls_send_dbus_str("TDLSStatus", (const char*)peer_mac); + if (message == NULL) { + ERR(" TDLS : No active TDLS Link Setup !!!"); + wifi_complete_tdls_connected_peer(wifi, context, "00.00.00.00.00.00"); + return TRUE; + } + + g_variant_get(message, "(&s)", &reply_str); + INFO("param [%s]", g_variant_print(message,TRUE)); + INFO("TDLS reply: [%s]", reply_str); + INFO("TDLS :peer_mac [%s]", peer_mac); + + if (g_strcmp0("connected", reply_str) != 0) { + ERR("[TizenMW<--WPAS] TDLS Connection not available"); + wifi_complete_tdls_connected_peer(wifi, context, "00.00.00.00.00.00"); + g_variant_unref(message); + return TRUE; + } + + INFO("[TizenMW<--WPAS] TDLS Connection available, Peer Mac address %s", peer_mac); + wifi_complete_tdls_connected_peer(wifi, context, peer_mac); + + g_variant_unref(message); + return TRUE; +} + +void netconfig_wifi_tlds_connected_event(GVariant *message) +{ + + DBG("[TizenMW<--WPAS] WiFi TDLS Connected EVENT"); + if (peer_info.is_connected == 1) { + INFO("TDLS Peer already connected"); + g_free(peer_mac); + } + + g_variant_get(message, "(s)", &peer_mac); + INFO("Peer Mac Address: [%s]", peer_mac); + + /*update the Peer Mac address in Gloablestructure*/ + peer_info.is_connected = 1; + __netconfig_wifi_notify_tdls_event("TDLSConnect", peer_mac); +} + +void netconfig_wifi_tlds_disconnected_event(GVariant *message) +{ + DBG("[TizenMW<--WPAS]: WiFi TDLS Disconnected EVENT"); + const gchar *peer_mac_addr = NULL; + + g_variant_get(message, "(&s)", &peer_mac_addr); + if (g_strcmp0(peer_mac, peer_mac_addr) == 0) { + INFO("TDLS Peer Disconnected Mac Address: [%s]", peer_mac); + peer_info.is_connected = 0; + __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); +} diff --git a/src/wifi.c b/src/wifi.c index 2effe8b..796849c 100755 --- a/src/wifi.c +++ b/src/wifi.c @@ -38,6 +38,7 @@ #include "wifi-eap-config.h" #include "wifi-background-scan.h" #include "wifi-config.h" +#include "wifi-tdls.h" static Wifi *wifi_object = NULL; static NetConnmanAgent *connman_agent_object = NULL; @@ -165,6 +166,12 @@ void wifi_object_create_and_init(void) g_signal_connect(wifi_object, "handle-check-black-list", G_CALLBACK(handle_check_black_list), NULL); + //TDLS methods + g_signal_connect(wifi_object, "handle-tdls-disconnect", + G_CALLBACK(handle_tdls_disconnect), NULL); + g_signal_connect(wifi_object, "handle-tdls-connected-peer", + G_CALLBACK(handle_tdls_connected_peer), NULL); + if (!g_dbus_interface_skeleton_export(interface_wifi, connection, NETCONFIG_WIFI_PATH, NULL)) { ERR("Export WIFI_PATH for wifi failed"); -- 2.7.4