[ACR]Add new APIs for TDLS 39/54539/1
authorhyunuktak <hyunuk.tak@samsung.com>
Wed, 16 Dec 2015 04:49:12 +0000 (13:49 +0900)
committerhyunuktak <hyunuk.tak@samsung.com>
Wed, 16 Dec 2015 04:49:16 +0000 (13:49 +0900)
Change-Id: I4679c45379e0da8069bf1bed0be5f605583be4ff
Signed-off-by: hyunuktak <hyunuk.tak@samsung.com>
CMakeLists.txt
include/netdbus.h
include/wifi-tdls.h [new file with mode: 0755]
interfaces/netconfig-iface-wifi.xml
packaging/net-config.spec
resources/etc/dbus-1/system.d/net-config.conf
src/dbus/netdbus.c
src/signal-handler.c
src/wifi-tdls.c [new file with mode: 0755]
src/wifi.c

index d93dd7e..f257b9c 100755 (executable)
@@ -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
index b3e40e4..a4ba8e2 100755 (executable)
@@ -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 (executable)
index 0000000..9f8ef29
--- /dev/null
@@ -0,0 +1,50 @@
+/*\r
+ * Network Configuration Module\r
+ *\r
+ * Copyright (c) 2012-2013 Samsung Electronics Co., Ltd. All rights reserved.\r
+ *\r
+ * Licensed under the Apache License, Version 2.0 (the "License");\r
+ * you may not use this file except in compliance with the License.\r
+ * You may obtain a copy of the License at\r
+ *\r
+ * http://www.apache.org/licenses/LICENSE-2.0\r
+ *\r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * See the License for the specific language governing permissions and\r
+ * limitations under the License.\r
+ *\r
+ */\r
+#ifndef __TIZEN_NETWORK_WIFI_TDLS_H__\r
+#define __TIZEN_NETWORK_WIFI_TDLS_H__\r
+\r
+#ifdef __cplusplus\r
+        extern "C" {\r
+#endif\r
+\r
+#include <glib.h>\r
+#include "netsupplicant.h"\r
+\r
+typedef struct {\r
+       int is_connected;\r
+       int hdcp;\r
+       int port;\r
+       int availability;\r
+       int tdls_support;\r
+       unsigned char ip_add[4];\r
+}wifi_tdls_wfd_info_s;\r
+\r
+void netconfig_wifi_tlds_connected_event(GVariant *message);\r
+void netconfig_wifi_tlds_disconnected_event(GVariant *message);\r
+void __netconfig_wifi_notify_tdls_connected_event(const char *peer_mac);\r
+gboolean handle_tdls_disconnect(Wifi *wifi, GDBusMethodInvocation *context, gchar *peer_mac_addr);\r
+gboolean handle_tdls_connected_peer(Wifi *wifi, GDBusMethodInvocation *context);\r
+\r
+\r
+#ifdef __cplusplus\r
+}\r
+#endif\r
+\r
+#endif /* __TIZEN_NETWORK_WIFI_TDLS_H__ */\r
+\r
index 6a5827b..ac59f08 100755 (executable)
                        <arg type="s" name="eap" direction="in"/>
                        <arg type="b" name="allowed" direction="out"/>
                </method>
+               <method name="TdlsDisconnect">
+                       <arg type="s" name="pee_mac_addr" direction="in"/>
+                       <arg  type="i" name="result" direction="out" />
+               </method>
+               <method name="TdlsConnectedPeer">
+                       <arg  type="s" name="peer_mac_addr" direction="out" />
+               </method>
                <signal name="PowerOnCompleted"></signal>
                <signal name="PowerOffCompleted"></signal>
                <signal name="PowerOperationFailed"></signal>
index e132cec..c3ad78a 100755 (executable)
@@ -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
index 4196cb5..f7e997f 100755 (executable)
@@ -49,6 +49,8 @@
                <check send_destination="net.netconfig" send_interface="net.netconfig.wifi" send_member="PowerOffCompleted" privilege="http://tizen.org/privilege/network.get" />
                <check send_destination="net.netconfig" send_interface="net.netconfig.wifi" send_member="SpecificScanCompleted" privilege="http://tizen.org/privilege/network.get" />
                <check send_destination="net.netconfig" send_interface="net.netconfig.wifi" send_member="WpsScanCompleted" privilege="http://tizen.org/privilege/network.get" />
+               <check send_destination="net.netconfig" send_interface="net.netconfig.wifi" send_member="TdlsDisconnect" privilege="http://tizen.org/privilege/network.set" />
+               <check send_destination="net.netconfig" send_interface="net.netconfig.wifi" send_member="TdlsConnectedPeer" privilege="http://tizen.org/privilege/network.get" />
 
                <check send_destination="net.netconfig" send_interface="net.connman.Agent" send_member="SetField" privilege="http://tizen.org/privilege/network.profile" />
        </policy>
index d63397b..d998fb7 100755 (executable)
@@ -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)
 {
index 90fb9b8..b0d7c1b 100755 (executable)
@@ -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 (executable)
index 0000000..de2ca17
--- /dev/null
@@ -0,0 +1,169 @@
+/*\r
+ * Network Configuration Module\r
+ *\r
+ * Copyright (c) 2012-2013 Samsung Electronics Co., Ltd. All rights reserved.\r
+ *\r
+ * Licensed under the Apache License, Version 2.0 (the "License");\r
+ * you may not use this file except in compliance with the License.\r
+ * You may obtain a copy of the License at\r
+ *\r
+ * http://www.apache.org/licenses/LICENSE-2.0\r
+ *\r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * See the License for the specific language governing permissions and\r
+ * limitations under the License.\r
+ *\r
+ */\r
+\r
+#include <stdio.h>\r
+#include <time.h>\r
+#include <stdlib.h>\r
+#include <sys/time.h>\r
+#include <unistd.h>\r
+#include <string.h>\r
+#include "neterror.h"\r
+#include "netdbus.h"\r
+#include "netsupplicant.h"\r
+#include "network-state.h"\r
+#include <vconf.h>\r
+#include <vconf-keys.h>\r
+#include <arpa/inet.h>\r
+#include <log.h>\r
+#include "util.h"\r
+#include "neterror.h"\r
+#include "wifi-tdls.h"\r
+#include <glib.h>\r
+\r
+wifi_tdls_wfd_info_s peer_info;\r
+char *peer_mac = NULL;\r
+\r
+void __netconfig_wifi_notify_tdls_event(const char *sig_name,const char *peer_mac)\r
+{\r
+       GVariantBuilder *builder;\r
+       GVariant *params;\r
+       builder = g_variant_builder_new(G_VARIANT_TYPE("a{sv}"));\r
+       g_variant_builder_add(builder, "{sv}", "peermac", g_variant_new_string(peer_mac));\r
+\r
+       params = g_variant_new("(@a{sv})", g_variant_builder_end(builder));\r
+       g_variant_builder_unref(builder);\r
+\r
+       netconfig_dbus_emit_signal(NULL,\r
+                               NETCONFIG_WIFI_PATH,\r
+                               NETCONFIG_WIFI_INTERFACE,\r
+                               sig_name,\r
+                               params);\r
+\r
+       INFO("Sent signal (%s) Peer Mac (%s)", sig_name, peer_mac);\r
+}\r
+\r
+static GVariant * __netconfig_wifi_tdls_send_dbus_str(const char* method, const char *str)\r
+{\r
+       GVariant *message = NULL;\r
+       const char *if_path = NULL;\r
+       GVariant *params = NULL;\r
+\r
+       if_path = netconfig_wifi_get_supplicant_interface();\r
+       if (if_path == NULL) {\r
+               ERR("Fail to get wpa_supplicant DBus path");\r
+               return NULL;\r
+       }\r
+\r
+       params = g_variant_new("(s)", str);\r
+       INFO("[TizenMW-->WPAS] Sent Dbus Method :[%s],value[%s]", method,str);\r
+       message = netconfig_invoke_dbus_method(SUPPLICANT_SERVICE,\r
+                       if_path, SUPPLICANT_INTERFACE ".Interface", method, params);\r
+\r
+       INFO("TDLS Returned from Blocking method for Send DBUS Command");\r
+       return message;\r
+}\r
+\r
+gboolean handle_tdls_disconnect(Wifi *wifi, GDBusMethodInvocation *context,\r
+                       gchar *peer_mac_Addr)\r
+{\r
+       DBG("[TizenMW-->WPAS]: TDLS Teardown Request: [%s]", peer_mac_Addr);\r
+\r
+       if(!peer_info.is_connected) {\r
+               ERR(" No active TDLS Connection !!!");\r
+\r
+       } else {\r
+               GVariant *message = NULL;\r
+               message = __netconfig_wifi_tdls_send_dbus_str("TDLSTeardown", (const char*)peer_mac_Addr);\r
+               DBG("[TizenMW<--WPAS] TDLS DBUS Command sent successfully");\r
+               g_variant_unref(message);\r
+               peer_info.is_connected = 0;\r
+       }\r
+\r
+       wifi_complete_tdls_disconnect(wifi, context, 1);\r
+       return TRUE;\r
+}\r
+\r
+gboolean handle_tdls_connected_peer(Wifi *wifi, GDBusMethodInvocation *context)\r
+{\r
+       DBG("[TizenMW-->WPAS]: TDLS Connected Peer Request: ");\r
+\r
+       GVariant *message = NULL;\r
+       const gchar* reply_str = NULL;\r
+\r
+       if (peer_mac == NULL) {\r
+               INFO("TDLS: No Active Connection");\r
+               wifi_complete_tdls_connected_peer(wifi, context, "00.00.00.00.00.00");\r
+               return TRUE;\r
+       }\r
+       message = __netconfig_wifi_tdls_send_dbus_str("TDLSStatus", (const char*)peer_mac);\r
+       if (message == NULL) {\r
+               ERR(" TDLS : No active TDLS Link Setup !!!");\r
+               wifi_complete_tdls_connected_peer(wifi, context, "00.00.00.00.00.00");\r
+               return TRUE;\r
+       }\r
+\r
+       g_variant_get(message, "(&s)", &reply_str);\r
+       INFO("param [%s]", g_variant_print(message,TRUE));\r
+       INFO("TDLS reply: [%s]", reply_str);\r
+       INFO("TDLS :peer_mac [%s]", peer_mac);\r
+\r
+       if (g_strcmp0("connected", reply_str) != 0) {\r
+               ERR("[TizenMW<--WPAS] TDLS Connection not available");\r
+               wifi_complete_tdls_connected_peer(wifi, context, "00.00.00.00.00.00");\r
+               g_variant_unref(message);\r
+               return TRUE;\r
+       }\r
+\r
+       INFO("[TizenMW<--WPAS] TDLS Connection available, Peer Mac address %s", peer_mac);\r
+       wifi_complete_tdls_connected_peer(wifi, context, peer_mac);\r
+\r
+       g_variant_unref(message);\r
+       return TRUE;\r
+}\r
+\r
+void netconfig_wifi_tlds_connected_event(GVariant *message)\r
+{\r
+\r
+       DBG("[TizenMW<--WPAS] WiFi TDLS Connected EVENT");\r
+       if (peer_info.is_connected == 1) {\r
+               INFO("TDLS Peer already connected");\r
+               g_free(peer_mac);\r
+       }\r
+\r
+       g_variant_get(message, "(s)", &peer_mac);\r
+       INFO("Peer Mac Address: [%s]", peer_mac);\r
+\r
+       /*update the Peer Mac address in Gloablestructure*/\r
+       peer_info.is_connected = 1;\r
+       __netconfig_wifi_notify_tdls_event("TDLSConnect", peer_mac);\r
+}\r
+\r
+void netconfig_wifi_tlds_disconnected_event(GVariant *message)\r
+{\r
+       DBG("[TizenMW<--WPAS]: WiFi TDLS Disconnected EVENT");\r
+       const gchar *peer_mac_addr = NULL;\r
+\r
+       g_variant_get(message, "(&s)", &peer_mac_addr);\r
+       if (g_strcmp0(peer_mac, peer_mac_addr) == 0) {\r
+               INFO("TDLS Peer Disconnected Mac Address: [%s]", peer_mac);\r
+               peer_info.is_connected = 0;\r
+               __netconfig_wifi_notify_tdls_event("TDLSDisconnect",peer_mac);\r
+       } else\r
+               INFO("TDLS Peer Disconnected peer_mac(%s) != peer_mac_address(%s)", peer_mac, peer_mac_addr);\r
+}\r
index 2effe8b..796849c 100755 (executable)
@@ -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");