2 * Network Configuration Module
4 * Copyright (c) 2012-2013 Samsung Electronics Co., Ltd. All rights reserved.
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
28 #include "netsupplicant.h"
29 #include "network-state.h"
31 #include <vconf-keys.h>
32 #include <arpa/inet.h>
36 #include "wifi-tdls.h"
39 char *peer_mac = NULL;
42 void __netconfig_wifi_notify_tdls_event(const char *sig_name, const char *peer_mac)
44 GVariantBuilder *builder;
46 builder = g_variant_builder_new(G_VARIANT_TYPE("a{sv}"));
47 g_variant_builder_add(builder, "{sv}", "peermac", g_variant_new_string(peer_mac));
49 params = g_variant_new("(@a{sv})", g_variant_builder_end(builder));
50 g_variant_builder_unref(builder);
52 netconfig_dbus_emit_signal(NULL,
54 NETCONFIG_WIFI_INTERFACE,
58 INFO("Sent signal (%s) Peer Mac (%s)", sig_name, peer_mac);
61 static GVariant * __netconfig_wifi_tdls_send_dbus_str(const char* method, const char *str)
63 GVariant *message = NULL;
64 const char *if_path = NULL;
65 GVariant *params = NULL;
67 if_path = netconfig_wifi_get_supplicant_interface();
68 if (if_path == NULL) {
69 ERR("Fail to get wpa_supplicant DBus path");
73 params = g_variant_new("(s)", str);
74 INFO("[TizenMW-->WPAS] Sent Dbus Method :[%s],value[%s]", method, str);
75 message = netconfig_invoke_dbus_method(SUPPLICANT_SERVICE,
76 if_path, SUPPLICANT_INTERFACE ".Interface", method, params);
78 INFO("TDLS Returned from Blocking method for Send DBUS Command");
82 gboolean handle_tdls_connect(Wifi *wifi, GDBusMethodInvocation *context,
85 DBG("[TizenMW-->WPAS]: TDLS Setup Request: [%s]", peer_mac_Addr);
88 ERR(" Already active TDLS Connection !!!");
90 GVariant *message = NULL;
91 message = __netconfig_wifi_tdls_send_dbus_str("TDLSSetup", (const char*)peer_mac_Addr);
93 if (message == NULL) {
94 ERR(" TDLS : failed to connect !!!");
95 netconfig_error_dbus_method_return(context, NETCONFIG_ERROR_INTERNAL, "FailTdlsConnect");
99 DBG("[TizenMW<--WPAS] TDLS DBUS Command sent successfully");
100 g_variant_unref(message);
104 wifi_complete_tdls_connect(wifi, context, 1);
108 gboolean handle_tdls_discover(Wifi *wifi, GDBusMethodInvocation *context)
110 DBG("[TizenMW-->WPAS]: TDLS Discover Request ");
113 ERR(" Already active TDLS Connection !!!");
115 GVariant *message = NULL;
116 message = __netconfig_wifi_tdls_send_dbus_str("TDLSDiscover", "ff:ff:ff:ff:ff:ff");
118 if (message == NULL) {
119 ERR(" TDLS : failed to discover !!!");
120 netconfig_error_dbus_method_return(context, NETCONFIG_ERROR_INTERNAL, "FailTdlsDiscover");
124 DBG("[TizenMW<--WPAS] TDLS DBUS Command sent successfully");
125 g_variant_unref(message);
128 wifi_complete_tdls_discover(wifi, context);
132 gboolean handle_tdls_disconnect(Wifi *wifi, GDBusMethodInvocation *context,
133 gchar *peer_mac_Addr)
135 DBG("[TizenMW-->WPAS]: TDLS Teardown Request: [%s]", peer_mac_Addr);
138 ERR(" No active TDLS Connection !!!");
140 GVariant *message = NULL;
141 message = __netconfig_wifi_tdls_send_dbus_str("TDLSTeardown", (const char*)peer_mac_Addr);
143 if (message == NULL) {
144 ERR(" TDLS : failed to disconnect !!!");
145 netconfig_error_dbus_method_return(context, NETCONFIG_ERROR_INTERNAL, "FailTdlsDisconnect");
149 DBG("[TizenMW<--WPAS] TDLS DBUS Command sent successfully");
150 g_variant_unref(message);
154 wifi_complete_tdls_disconnect(wifi, context, 1);
158 gboolean handle_tdls_connected_peer(Wifi *wifi, GDBusMethodInvocation *context)
160 DBG("[TizenMW-->WPAS]: TDLS Connected Peer Request: ");
162 GVariant *message = NULL;
163 const gchar* reply_str = NULL;
165 if (peer_mac == NULL) {
166 INFO("TDLS: No Active Connection");
167 wifi_complete_tdls_connected_peer(wifi, context, "00.00.00.00.00.00");
170 message = __netconfig_wifi_tdls_send_dbus_str("TDLSStatus", (const char*)peer_mac);
171 if (message == NULL) {
172 ERR(" TDLS : No active TDLS Link Setup !!!");
173 wifi_complete_tdls_connected_peer(wifi, context, "00.00.00.00.00.00");
177 g_variant_get(message, "(&s)", &reply_str);
178 INFO("TDLS reply: [%s]", reply_str);
179 INFO("TDLS :peer_mac [%s]", peer_mac);
181 if (g_strcmp0("connected", reply_str) != 0) {
182 ERR("[TizenMW<--WPAS] TDLS Connection not available");
183 wifi_complete_tdls_connected_peer(wifi, context, "00.00.00.00.00.00");
184 g_variant_unref(message);
188 INFO("[TizenMW<--WPAS] TDLS Connection available, Peer Mac address %s", peer_mac);
189 wifi_complete_tdls_connected_peer(wifi, context, peer_mac);
191 g_variant_unref(message);
195 void netconfig_wifi_tdls_connected_event(GVariant *message)
198 DBG("[TizenMW<--WPAS] WiFi TDLS Connected EVENT");
199 if (is_connected == 1) {
200 INFO("TDLS Peer already connected");
204 g_variant_get(message, "(s)", &peer_mac);
205 INFO("Peer Mac Address: [%s]", peer_mac);
208 __netconfig_wifi_notify_tdls_event("TDLSConnect", peer_mac);
211 void netconfig_wifi_tdls_disconnected_event(GVariant *message)
213 DBG("[TizenMW<--WPAS]: WiFi TDLS Disconnected EVENT");
214 const gchar *peer_mac_addr = NULL;
216 g_variant_get(message, "(&s)", &peer_mac_addr);
217 if (g_strcmp0(peer_mac, peer_mac_addr) == 0) {
218 INFO("TDLS Peer Disconnected Mac Address: [%s]", peer_mac);
220 __netconfig_wifi_notify_tdls_event("TDLSDisconnect", peer_mac);
222 INFO("TDLS Peer Disconnected peer_mac(%s) != peer_mac_address(%s)", peer_mac, peer_mac_addr);
226 void netconfig_wifi_tdls_peer_found_event(GVariant *message)
228 DBG("[TizenMW<--WPAS]: WiFi TDLS Discovery EVENT");
229 const gchar *peer_mac_addr = NULL;
231 g_variant_get(message, "(s)", &peer_mac_addr);
232 INFO("Discover Peer Mac Address: [%s]", peer_mac_addr);
234 __netconfig_wifi_notify_tdls_event("TDLSPeerFound", peer_mac_addr);