-/*\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
+/*
+ * 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 <stdio.h>
+#include <time.h>
+#include <stdlib.h>
+#include <sys/time.h>
+#include <unistd.h>
+#include <string.h>
+#include "neterror.h"
+#include "netdbus.h"
+#include "netsupplicant.h"
+#include "network-state.h"
+#include <vconf.h>
+#include <vconf-keys.h>
+#include <arpa/inet.h>
+#include <log.h>
+#include "util.h"
+#include "neterror.h"
+#include "wifi-tdls.h"
+#include <glib.h>
+
+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*/
+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)
+{
+ 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);
+}
+
+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();
+ is_timer_expired = 1;
+
+ return FALSE;
+}
+
+static GVariant * __netconfig_wifi_tdls_send_dbus_str(const char* method, const char *str)
+{
+ GVariant *message = NULL;
+ 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);
+
+ g_free(if_path);
+ INFO("TDLS Returned from Blocking method for Send DBUS Command");
+ return message;
+}
+
+static unsigned char _netconfig_freq_to_channel(int freq)
+{
+ if (freq < 2412 || freq > 5825 ||
+ (freq > 2484 && freq < 5180)) {
+ ERR("Invalid Frequence Range");
+ return 0;
+ }
+ if (freq >= 5180)
+ return 36 + (freq - 5180)/5;
+ else if (freq <= 2472)
+ return 1 + (freq - 2412)/5;
+ else if (freq == 2484)
+ return 14;
+ else
+ return 0;
+}
+
+static unsigned char _netconfig_get_operating_class(int freq)
+{
+ unsigned char channel = 0;
+ unsigned char oper_class = 0;
+
+ channel = _netconfig_freq_to_channel(freq);
+
+ if (channel) {
+ /* Operating class 81 - 2.4 GHz band channels 1..13 */
+ if (channel >= 1 && channel <= 13)
+ oper_class = 81;
+ /* Operating class 115 - 5 GHz, channels 36-48 */
+ else if (channel >= 36 && channel <= 48)
+ oper_class = 115;
+ /* Operating class 124 - 5 GHz, channels 149,153,157,161 */
+ else
+ oper_class = 124;
+
+ INFO("TDLS: Operating Class is [%d]", oper_class);
+ return oper_class;
+ }
+ return 0;
+}
+
+gboolean handle_tdls_connect(Wifi *wifi, GDBusMethodInvocation *context,
+ gchar *peer_mac_Addr)
+{
+ DBG("[TizenMW-->WPAS]: TDLS Setup Request: [%s]", peer_mac_Addr);
+
+ if (is_connected) {
+ ERR(" Already TDLS Connection !!!");
+ } else {
+ GVariant *message = NULL;
+ message = __netconfig_wifi_tdls_send_dbus_str("TDLSSetup", (const char*)peer_mac_Addr);
+
+ if (message == NULL) {
+ ERR(" TDLS : failed to connect !!!");
+ netconfig_error_dbus_method_return(context, NETCONFIG_ERROR_INTERNAL, "FailTdlsConnect");
+ return TRUE;
+ }
+
+ DBG("[TizenMW<--WPAS] TDLS DBUS Command sent successfully");
+ g_variant_unref(message);
+ is_connected = 1;
+ }
+
+ wifi_complete_tdls_connect(wifi, context, 1);
+ return TRUE;
+}
+
+gboolean handle_tdls_discover(Wifi *wifi, GDBusMethodInvocation *context,
+ gchar *peer_mac_Addr)
+{
+ DBG("TDLS Discover Request: [%s]", peer_mac_Addr);
+ 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 TRUE;
+ }
+
+ 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;
+ }
+
+ is_timer_expired = 0;
+ 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;
+}
+
+gboolean handle_tdls_disconnect(Wifi *wifi, GDBusMethodInvocation *context,
+ gchar *peer_mac_Addr)
+{
+ DBG("[TizenMW-->WPAS]: TDLS Teardown Request: [%s]", peer_mac_Addr);
+
+ if (!is_connected) {
+ 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);
+
+ if (message == NULL) {
+ ERR(" TDLS : failed to disconnect !!!");
+ netconfig_error_dbus_method_return(context, NETCONFIG_ERROR_INTERNAL, "FailTdlsDisconnect");
+ return TRUE;
+ }
+
+ DBG("[TizenMW<--WPAS] TDLS DBUS Command sent successfully");
+ g_variant_unref(message);
+ is_connected = 0;
+ }
+
+ wifi_complete_tdls_disconnect(wifi, context, NETCONFIG_ERROR_TDLS_NO_ERROR);
+ 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("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("TDLS Connection available, Peer Mac address %s", peer_mac);
+ wifi_complete_tdls_connected_peer(wifi, context, peer_mac);
+
+ g_variant_unref(message);
+ return TRUE;
+}
+
+gboolean handle_tdls_channel_switch(Wifi *wifi, GDBusMethodInvocation *context,
+ gchar *peer_mac_Addr, int freq)
+{
+ GVariant *message = NULL;
+ GVariantBuilder *builder;
+ GVariant *params;
+ char *if_path = NULL;
+ unsigned char oper_class = 0;
+
+ if (peer_mac_Addr == NULL) {
+ ERR("TDLS: Invalid Parameter");
+ wifi_complete_tdls_channel_switch(wifi, context,
+ NETCONFIG_ERROR_TDLS_FAIL_CHANNEL_SWITCH);
+ return TRUE;
+ }
+
+ oper_class = _netconfig_get_operating_class(freq);
+
+ if (!oper_class) {
+ ERR("TDLS: Invalid Parameter");
+ wifi_complete_tdls_channel_switch(wifi, context,
+ NETCONFIG_ERROR_TDLS_FAIL_CHANNEL_SWITCH);
+ return TRUE;
+ }
+
+ 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_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);
+
+ if_path = netconfig_wifi_get_supplicant_interface();
+
+ if (if_path == NULL) {
+ ERR("Fail to get wpa_supplicant DBus path");
+ wifi_complete_tdls_channel_switch(wifi, context,
+ NETCONFIG_ERROR_TDLS_FAIL_CHANNEL_SWITCH);
+ return TRUE;
+ }
+
+ 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,
+ NETCONFIG_ERROR_TDLS_FAIL_CHANNEL_SWITCH);
+ return TRUE;
+ }
+
+ INFO("TDLS Channel Change Request: Success");
+ wifi_complete_tdls_channel_switch(wifi, context, NETCONFIG_ERROR_TDLS_NO_ERROR);
+
+ g_variant_unref(message);
+ return TRUE;
+}
+
+
+gboolean handle_tdls_cancel_channel_switch(Wifi *wifi, GDBusMethodInvocation *context,
+ gchar *peer_mac_Addr)
+{
+ GVariant *message = NULL;
+
+ if (peer_mac_Addr == NULL) {
+ INFO("TDLS: Invalid Parameter");
+ wifi_complete_tdls_cancel_channel_switch(wifi, context, NETCONFIG_ERROR_TDLS_FAIL_CHANNEL_SWITCH);
+ return TRUE;
+ }
+ message = __netconfig_wifi_tdls_send_dbus_str("TDLSCancelChannelSwitch", (const char*)peer_mac_Addr);
+ if (message == NULL) {
+ ERR(" TDLS : Fail to TDLS Cancel Channel Swicth Request !!!");
+ wifi_complete_tdls_cancel_channel_switch(wifi, context, NETCONFIG_ERROR_TDLS_FAIL_CHANNEL_SWITCH);
+ return TRUE;
+ }
+
+ INFO("TDLS Cancel Channel Swicth Request : Success");
+ wifi_complete_tdls_cancel_channel_switch(wifi, context, NETCONFIG_ERROR_TDLS_NO_ERROR);
+
+ g_variant_unref(message);
+ return TRUE;
+}
+
+void netconfig_wifi_tdls_connected_event(GVariant *message)
+{
+
+ DBG("WiFi TDLS Connected EVENT");
+ if (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);
+
+ is_connected = 1;
+ __netconfig_wifi_notify_tdls_event("TDLSConnect", peer_mac);
+}
+
+void netconfig_wifi_tdls_disconnected_event(GVariant *message)
+{
+ DBG("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);
+ 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);
+}
+
+
+void netconfig_wifi_tdls_peer_found_event(GVariant *message)
+{
+ DBG("WiFi TDLS Discovery EVENT Received !!");
+ const gchar *peer_mac_addr = NULL;
+
+ 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();
+
+ __netconfig_wifi_notify_tdls_discover_event(peer_mac_addr, is_discover_broadcast);
+ } else
+ DBG("Timer expired: Do not process the TDLS Discovery Event");
+}
+