From a25bceb37686d5f9ef1929f30f46a654fdf14441 Mon Sep 17 00:00:00 2001 From: hyunuktak Date: Wed, 16 Dec 2015 13:48:42 +0900 Subject: [PATCH] [ACR]Add new APIs for TDLS Change-Id: I0171927d83dff8d71ed194e088ba0fb877a37fbd Signed-off-by: hyunuktak --- include/common/network-cm-error.h | 2 +- include/common/network-cm-intf.h | 6 +++ include/profile/network-pm-wlan.h | 6 +-- include/wifi/network-wifi-intf.h | 14 +++--- packaging/libnet-client.spec | 2 +- src/include/network-dbus-request.h | 2 + src/include/network-internal.h | 3 ++ src/include/network-signal-handler.h | 2 +- src/network-dbus-request.c | 74 ++++++++++++++++++++++++++++++ src/network-signal-handler.c | 87 ++++++++++++++++++++++++++++++++++++ src/network-wifi-intf.c | 58 ++++++++++++++++++++++++ 11 files changed, 245 insertions(+), 11 deletions(-) diff --git a/include/common/network-cm-error.h b/include/common/network-cm-error.h index 275f5f6..c9a1f18 100755 --- a/include/common/network-cm-error.h +++ b/include/common/network-cm-error.h @@ -171,5 +171,5 @@ typedef enum { #ifdef __cplusplus } #endif - + #endif diff --git a/include/common/network-cm-intf.h b/include/common/network-cm-intf.h index b00f3ca..eb702ff 100755 --- a/include/common/network-cm-intf.h +++ b/include/common/network-cm-intf.h @@ -126,6 +126,12 @@ typedef enum /** Ethernet Cable Detached Event */ NET_EVENT_ETHERNET_CABLE_DETACHED, + + /** Wi-Fi TDLS Peer Connected EVENT) */ + NET_EVENT_TDLS_CONNECTED_IND, + + /** Wi-Fi TDLS Peer Disconnect EVENT) */ + NET_EVENT_TDLS_DISCONNECTED_IND, } net_event_t; /** diff --git a/include/profile/network-pm-wlan.h b/include/profile/network-pm-wlan.h index 32c2141..95dc0a3 100755 --- a/include/profile/network-pm-wlan.h +++ b/include/profile/network-pm-wlan.h @@ -51,11 +51,11 @@ extern "C" /** Length of bssid */ #define NET_WLAN_BSSID_LEN 17 -/** - * Length of WPS PIN code +/** + * Length of WPS PIN code * WPS PIN code should be 4 or 8 digits */ -#define NET_WLAN_MAX_WPSPIN_LEN 8 +#define NET_WLAN_MAX_WPSPIN_LEN 8 /** * Passphrase length should be between 8..63, diff --git a/include/wifi/network-wifi-intf.h b/include/wifi/network-wifi-intf.h index e900edf..18709c7 100755 --- a/include/wifi/network-wifi-intf.h +++ b/include/wifi/network-wifi-intf.h @@ -44,7 +44,7 @@ extern "C" { /***************************************************************************** - * Global Enums + * Global Enums *****************************************************************************/ /** @@ -93,7 +93,7 @@ typedef enum typedef struct { /** PBC / PIN */ net_wifi_wps_type_t type; - + /** Optional. This pin is needed when the user input PIN code */ char pin[NET_WLAN_MAX_WPSPIN_LEN + 1]; } net_wifi_wps_info_t; @@ -129,15 +129,15 @@ struct wps_scan_bss_info_t { }; /***************************************************************************** - * Typedefs + * Typedefs *****************************************************************************/ /***************************************************************************** - * Global Functions + * Global Functions *****************************************************************************/ - + /***************************************************************************** * ConnMan Wi-Fi Client Interface Synchronous API Declaration *****************************************************************************/ @@ -438,6 +438,10 @@ int net_check_profile_privilege(); int net_wifi_enroll_wps_without_ssid(net_wifi_wps_info_t *wps_info); #endif + +int net_wifi_tdls_disconnect(const char* peer_mac_addr); +int net_wifi_tdls_connected_peer(char** peer_mac_addr); + /** * \} */ diff --git a/packaging/libnet-client.spec b/packaging/libnet-client.spec index 9c24ab4..3dc8b20 100755 --- a/packaging/libnet-client.spec +++ b/packaging/libnet-client.spec @@ -1,6 +1,6 @@ Name: libnet-client Summary: Network Client library (Shared library) -Version: 1.1.43 +Version: 1.1.44 Release: 1 Group: System/Network License: Flora-1.1 diff --git a/src/include/network-dbus-request.h b/src/include/network-dbus-request.h index d40503f..a4599b6 100755 --- a/src/include/network-dbus-request.h +++ b/src/include/network-dbus-request.h @@ -141,6 +141,8 @@ int _net_dbus_set_agent_wps_pin(const char *wps_pin); #endif +int _net_dbus_tdls_disconnect(const char* peer_mac_addr); +int _net_dbus_tdls_connected_peer(char** peer_mac_addr); #ifdef __cplusplus } diff --git a/src/include/network-internal.h b/src/include/network-internal.h index 5163a00..ff265ec 100755 --- a/src/include/network-internal.h +++ b/src/include/network-internal.h @@ -131,6 +131,9 @@ extern "C" { #define NETCONFIG_SIGNAL_SPECIFIC_SCAN_DONE "SpecificScanCompleted" #define NETCONFIG_SIGNAL_WPS_SCAN_DONE "WpsScanCompleted" #define NETCONFIG_SIGNAL_ETHERNET_CABLE_STATE "EthernetCableState" +#define NETCONFIG_SIGNAL_TDLS_CONNECTED "TDLSConnect" +#define NETCONFIG_SIGNAL_TDLS_DISCONNECTED "TDLSDisconnect" +#define NETCONFIG_SIGNAL_TDLS_PEER_FOUND "TDLSPeerFound" #undef LOG_TAG #define LOG_TAG "NET_CLIENT" diff --git a/src/include/network-signal-handler.h b/src/include/network-signal-handler.h index f851136..1648fce 100755 --- a/src/include/network-signal-handler.h +++ b/src/include/network-signal-handler.h @@ -33,7 +33,7 @@ extern "C" { *****************************************************************************/ /***************************************************************************** - * Global Functions + * Global Functions *****************************************************************************/ int _net_deregister_signal(void); int _net_register_signal(void); diff --git a/src/network-dbus-request.c b/src/network-dbus-request.c index 97712b5..5960add 100755 --- a/src/network-dbus-request.c +++ b/src/network-dbus-request.c @@ -2440,3 +2440,77 @@ int _net_dbus_set_agent_wps_pin(const char *wps_pin) return NET_ERR_NONE; } #endif + +int _net_dbus_tdls_disconnect(const char* peer_mac_addr) +{ + + __NETWORK_FUNC_ENTER__; + + net_err_t Error = NET_ERR_NONE; + GVariant *message = NULL; + GVariant *params = NULL; + const char *method = "TdlsDisconnect"; + gint32 ret = -1; + + params = g_variant_new("(s)", peer_mac_addr); + + message = _net_invoke_dbus_method( + NETCONFIG_SERVICE, NETCONFIG_WIFI_PATH, + NETCONFIG_WIFI_INTERFACE, method, params, &Error); + + if (message == NULL) { + NETWORK_LOG(NETWORK_ERROR, "Failed to TDLS Disconnect Request\n"); + __NETWORK_FUNC_EXIT__; + return Error; + } + + g_variant_get(message, "(i)", &ret); + + NETWORK_LOG(NETWORK_HIGH, "Status [%d]\n", ret); + + if(ret) + Error = NET_ERR_NONE; + else + Error = NET_ERR_UNKNOWN; + + g_variant_unref(message); + __NETWORK_FUNC_EXIT__; + + return Error; +} + +int _net_dbus_tdls_connected_peer(char** peer_mac_addr) +{ + + __NETWORK_FUNC_ENTER__; + + net_err_t Error = NET_ERR_NONE; + GVariant *message = NULL; + const char *method = "TdlsConnectedPeer"; + + + if(NULL == peer_mac_addr) { + NETWORK_LOG(NETWORK_ERROR,"Invalid Parameter\n"); + __NETWORK_FUNC_EXIT__; + return NET_ERR_INVALID_PARAM; + } + + message = _net_invoke_dbus_method( + NETCONFIG_SERVICE, NETCONFIG_WIFI_PATH, + NETCONFIG_WIFI_INTERFACE, method, NULL, &Error); + + if (message == NULL) { + NETWORK_LOG(NETWORK_ERROR, "Failed to Get Peer Connected Mac address\n"); + __NETWORK_FUNC_EXIT__; + return Error; + } + + g_variant_get(message, "(s)", peer_mac_addr); + + NETWORK_LOG(NETWORK_HIGH, "TDLS Peer Mac address [%s]\n", *peer_mac_addr); + + g_variant_unref(message); + __NETWORK_FUNC_EXIT__; + + return Error; +} \ No newline at end of file diff --git a/src/network-signal-handler.c b/src/network-signal-handler.c index bcc4d34..1ba86f7 100755 --- a/src/network-signal-handler.c +++ b/src/network-signal-handler.c @@ -701,6 +701,89 @@ static void __net_connman_service_signal_filter(GDBusConnection *conn, g_variant_unref(var); } } +static int __net_handle_wifi_tdls_connected_event(GVariant *param) +{ + __NETWORK_FUNC_ENTER__; + + GVariantIter *iter = NULL; + GVariant *value = NULL; + const char *key = NULL; + const gchar *sig_value = NULL; + + g_variant_get(param, "(a{sv})", &iter); + + while (g_variant_iter_loop(iter, "{sv}", &key, &value)) { + if (g_strcmp0(key, "peermac") == 0) { + sig_value = g_variant_get_string(value, NULL); + + NETWORK_LOG(NETWORK_ERROR, "TDLS Connected Peer Mac Adress: %s", + sig_value); + } + } + g_variant_iter_free(iter); + + net_event_info_t event_data; + memset(&event_data, 0, sizeof(event_data)); + + event_data.Error = NET_ERR_NONE; + event_data.Event = NET_EVENT_TDLS_CONNECTED_IND; + event_data.Data = g_strdup(sig_value); + + if(event_data.Data) + event_data.Datalength = strlen(event_data.Data); + else + event_data.Datalength = 0; + + NETWORK_LOG(NETWORK_ERROR,"Sending NET_EVENT_TDLS_CONNECTED_IND"); + _net_client_callback(&event_data); + g_free(event_data.Data); + + __NETWORK_FUNC_EXIT__; + return NET_ERR_NONE; +} + +static int __net_handle_wifi_tdls_disconnected_event(GVariant *param) +{ + __NETWORK_FUNC_ENTER__; + + GVariantIter *iter = NULL; + GVariant *value = NULL; + const char *key = NULL; + const gchar *sig_value = NULL; + + g_variant_get(param, "(a{sv})", &iter); + + while (g_variant_iter_loop(iter, "{sv}", &key, &value)) { + if (g_strcmp0(key, "peermac") == 0) { + sig_value = g_variant_get_string(value, NULL); + + NETWORK_LOG(NETWORK_ERROR, "TDLS Connected Peer Mac Adress: %s", + sig_value); + } + } + g_variant_iter_free(iter); + + net_event_info_t event_data; + memset(&event_data, 0, sizeof(event_data)); + + event_data.Error = NET_ERR_NONE; + event_data.Event = NET_EVENT_TDLS_DISCONNECTED_IND; + event_data.Data = g_strdup(sig_value); + + if(event_data.Data) + event_data.Datalength = strlen(event_data.Data); + else + event_data.Datalength = 0; + + NETWORK_LOG(NETWORK_ERROR,"Sending NET_EVENT_TDLS_DISCONNECTED_IND"); + _net_client_callback(&event_data); + g_free(event_data.Data); + + __NETWORK_FUNC_EXIT__; + return NET_ERR_NONE; +} + + static void __net_supplicant_signal_filter(GDBusConnection *conn, const gchar *name, const gchar *path, const gchar *interface, @@ -722,6 +805,10 @@ static void __net_netconfig_signal_filter(GDBusConnection *conn, __net_handle_wifi_specific_scan_rsp(param); else if (g_strcmp0(sig, NETCONFIG_SIGNAL_WPS_SCAN_DONE) == 0) __net_handle_wifi_wps_scan_rsp(param); + else if (g_strcmp0(sig, NETCONFIG_SIGNAL_TDLS_CONNECTED) == 0) + __net_handle_wifi_tdls_connected_event(param); + else if (g_strcmp0(sig, NETCONFIG_SIGNAL_TDLS_DISCONNECTED) == 0) + __net_handle_wifi_tdls_disconnected_event(param); } static void __net_netconfig_network_signal_filter(GDBusConnection *conn, diff --git a/src/network-wifi-intf.c b/src/network-wifi-intf.c index e03e1b3..d6cf7e9 100755 --- a/src/network-wifi-intf.c +++ b/src/network-wifi-intf.c @@ -876,3 +876,61 @@ EXPORT_API int net_wifi_enroll_wps_without_ssid(net_wifi_wps_info_t *wps_info) return Error; } #endif + +EXPORT_API int net_wifi_tdls_disconnect(const char* peer_mac_addr) +{ + __NETWORK_FUNC_ENTER__; + + net_err_t Error = NET_ERR_NONE; + + if (peer_mac_addr == NULL) { + NETWORK_LOG(NETWORK_ERROR, "invalid parameter\n"); + __NETWORK_FUNC_EXIT__; + return NET_ERR_INVALID_PARAM; + } + + if (g_atomic_int_get(&NetworkInfo.ref_count) == 0) { + NETWORK_LOG(NETWORK_ERROR, "Application is not registered\n"); + __NETWORK_FUNC_EXIT__; + return NET_ERR_APP_NOT_REGISTERED; + } + + Error = _net_dbus_tdls_disconnect(peer_mac_addr); + + if (Error != NET_ERR_NONE) + NETWORK_LOG(NETWORK_ERROR, "_net_dbus_tdls_set_device_type failed\n"); + + + __NETWORK_FUNC_EXIT__; + return Error; + +} + +EXPORT_API int net_wifi_tdls_connected_peer(char** peer_mac_addr) +{ + __NETWORK_FUNC_ENTER__; + + net_err_t Error = NET_ERR_NONE; + + if (peer_mac_addr == NULL) { + NETWORK_LOG(NETWORK_ERROR, "invalid parameter\n"); + __NETWORK_FUNC_EXIT__; + return NET_ERR_INVALID_PARAM; + } + + if (g_atomic_int_get(&NetworkInfo.ref_count) == 0) { + NETWORK_LOG(NETWORK_ERROR, "Application is not registered\n"); + __NETWORK_FUNC_EXIT__; + return NET_ERR_APP_NOT_REGISTERED; + } + + Error = _net_dbus_tdls_connected_peer(peer_mac_addr); + + if (Error != NET_ERR_NONE) + NETWORK_LOG(NETWORK_ERROR, "net_wifi_tdls_connected_peer failed\n"); + + + __NETWORK_FUNC_EXIT__; + return Error; + +} \ No newline at end of file -- 2.7.4