2 * Network Configuration Module
4 * Copyright (c) 2000 - 2012 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.
24 #include <vconf-keys.h>
32 #include "wifi-bssid-scan.h"
33 #include "wifi-agent.h"
34 #include "wifi-power.h"
35 #include "wifi-state.h"
36 #include "netsupplicant.h"
37 #include "network-state.h"
38 #include "cellular-state.h"
39 #include "signal-handler.h"
40 #include "wifi-background-scan.h"
41 #include "wifi-tdls.h"
42 #include "ip-conflict-detect.h"
43 #include "wifi-key-encryption.h"
44 #if defined TIZEN_DEBUG_ENABLE
45 #include "network-dump.h"
46 #define NETWORK_LOG_DUMP_SCRIPT "/opt/var/lib/net-config/network_log_dump.sh"
47 #define MAX_SIZE_ERROR_BUFFER 256
50 #define DBUS_SERVICE_DBUS "org.freedesktop.DBus"
51 #define DBUS_INTERFACE_DBUS "org.freedesktop.DBus"
52 #define SIGNAL_INTERFACE_REMOVED "InterfaceRemoved"
53 #define SIGNAL_SCAN_DONE "ScanDone"
54 #define SIGNAL_BSS_ADDED "BSSAdded"
55 #define SIGNAL_PROPERTIES_CHANGED "PropertiesChanged"
56 #define SIGNAL_PROPERTIES_DRIVER_HANGED "DriverHanged"
57 #define SIGNAL_PROPERTIES_SESSION_OVERLAPPED "SessionOverlapped"
58 #define SIGNAL_TDLS_CONNECTED "TDLSConnected"
59 #define SIGNAL_TDLS_DISCONNECTED "TDLSDisconnected"
60 #define SIGNAL_TDLS_PEER_FOUND "TDLSPeerFound"
62 #define SIGNAL_WPS_CONNECTED "WPSConnected"
63 #define SIGNAL_WPS_EVENT "Event"
64 #define SIGNAL_WPS_CREDENTIALS "Credentials"
66 #define CONNMAN_SIGNAL_SERVICES_CHANGED "ServicesChanged"
67 #define CONNMAN_SIGNAL_PROPERTY_CHANGED "PropertyChanged"
68 #define CONNMAN_SIGNAL_NAME_CHANGED "NameOwnerChanged"
70 #define MAX_SIG_LEN 64
71 #define TOTAL_CONN_SIGNALS 5
72 #define MAX_SOCKET_OPEN_RETRY 5
75 SIG_INTERFACE_REMOVED = 0,
76 SIG_PROPERTIES_CHANGED,
80 SIG_SESSION_OVERLAPPED,
82 SIG_TDLS_DISCONNECTED,
87 static int conn_subscription_ids[TOTAL_CONN_SIGNALS] = {0};
88 static const char supplicant_signals[SIG_MAX][MAX_SIG_LEN] = {
89 SIGNAL_INTERFACE_REMOVED,
90 SIGNAL_PROPERTIES_CHANGED,
93 SIGNAL_PROPERTIES_DRIVER_HANGED,
94 SIGNAL_PROPERTIES_SESSION_OVERLAPPED,
95 SIGNAL_TDLS_CONNECTED,
96 SIGNAL_TDLS_DISCONNECTED,
97 SIGNAL_TDLS_PEER_FOUND,
100 static int supp_subscription_ids[SIG_MAX] = {0};
101 #if defined TIZEN_DEBUG_ENABLE
102 static int dumpservice_subscription_id = 0;
105 typedef void (*supplicant_signal_cb)(GDBusConnection *conn,
106 const gchar *name, const gchar *path, const gchar *interface,
107 const gchar *sig, GVariant *param, gpointer user_data);
108 typedef void (*connman_signal_cb)(GDBusConnection *conn,
109 const gchar *name, const gchar *path, const gchar *interface,
110 const gchar *sig, GVariant *param, gpointer user_data);
112 static void __netconfig_extract_ipv4_signal_data(GVariant *dictionary,
113 const gchar *profile)
116 const gchar *value = NULL;
117 GVariant *var = NULL;
119 GVariantBuilder *builder;
122 g_variant_iter_init(&iter, dictionary);
123 while (g_variant_iter_loop(&iter, "{sv}", &key, &var)) {
124 if (g_strcmp0(key, "Address") == 0) {
125 g_variant_get(var, "&s", &value);
126 char *old_ip = vconf_get_str(VCONFKEY_NETWORK_IP);
128 DBG("Old IPv4.Address [%s] Received new IPv4.Address [%s]", old_ip,
130 if (g_strcmp0(old_ip, value) != 0) {
131 builder = g_variant_builder_new(G_VARIANT_TYPE("a{sv}"));
134 vconf_set_str(VCONFKEY_NETWORK_IP, value);
135 g_variant_builder_add(builder, "{sv}", "IPv4Address",
136 g_variant_new_string(value));
137 } else if (old_ip != NULL && strlen(old_ip) > 0) {
138 vconf_set_str(VCONFKEY_NETWORK_IP, "");
139 g_variant_builder_add(builder, "{sv}", "IPv4Address",
140 g_variant_new_string(""));
143 params = g_variant_new("(@a{sv})",
144 g_variant_builder_end(builder));
146 netconfig_dbus_emit_signal(NULL, NETCONFIG_NETWORK_PATH,
147 NETCONFIG_NETWORK_INTERFACE, "NetworkConfigChanged",
155 static void __netconfig_extract_ipv6_signal_data(GVariant *dictionary,
156 const gchar *profile)
159 const gchar *value = NULL;
160 GVariant *var = NULL;
162 GVariantBuilder *builder;
165 g_variant_iter_init(&iter, dictionary);
166 while (g_variant_iter_loop(&iter, "{sv}", &key, &var)) {
167 if (g_strcmp0(key, "Address") == 0) {
168 g_variant_get(var, "&s", &value);
169 char *old_ip6 = vconf_get_str(VCONFKEY_NETWORK_IP6);
171 DBG("Old IPv6.Address [%s] Received new IPv6.Address [%s]", old_ip6,
173 if (g_strcmp0(old_ip6, value) != 0) {
174 builder = g_variant_builder_new(G_VARIANT_TYPE("a{sv}"));
177 vconf_set_str(VCONFKEY_NETWORK_IP6, value);
178 g_variant_builder_add(builder, "{sv}", "IPv6Address",
179 g_variant_new_string(value));
180 } else if (old_ip6 != NULL && strlen(old_ip6) > 0) {
181 vconf_set_str(VCONFKEY_NETWORK_IP6, "");
182 g_variant_builder_add(builder, "{sv}", "IPv6Address",
183 g_variant_new_string(""));
186 params = g_variant_new("(@a{sv})",
187 g_variant_builder_end(builder));
189 netconfig_dbus_emit_signal(NULL, NETCONFIG_NETWORK_PATH,
190 NETCONFIG_NETWORK_INTERFACE, "NetworkConfigChanged",
198 #if defined TIZEN_DEBUG_ENABLE
199 static int __netconfig_handle_execute_file(const char *file_path,
200 char *const args[], char *const envs[])
206 register unsigned int index = 0;
207 char error_buf[MAX_SIZE_ERROR_BUFFER] = {0, };
209 while (args[index] != NULL) {
210 DBG("%s", args[index]);
214 if (!(pid = fork())) {
215 DBG("pid(%d), ppid (%d)", getpid(), getppid());
216 DBG("Inside child, exec (%s) command", file_path);
219 if (execve(file_path, args, envs) == -1) {
220 strerror_r(errno, error_buf, MAX_SIZE_ERROR_BUFFER);
221 DBG("Fail to execute command (%s)", error_buf);
224 } else if (pid > 0) {
225 if (waitpid(pid, &status, 0) == -1)
226 DBG("wait pid (%u) status (%d)", pid, status);
228 if (WIFEXITED(status)) {
229 rv = WEXITSTATUS(status);
230 DBG("exited, status=%d", rv);
231 } else if (WIFSIGNALED(status)) {
232 DBG("killed by signal %d", WTERMSIG(status));
233 } else if (WIFSTOPPED(status)) {
234 DBG("stopped by signal %d", WSTOPSIG(status));
235 } else if (WIFCONTINUED(status)) {
242 strerror_r(errno, error_buf, MAX_SIZE_ERROR_BUFFER);
243 DBG("failed to fork(%s)", error_buf);
247 static int _start_dump()
250 gchar *path = NETWORK_LOG_DUMP_SCRIPT;
251 char *const args[] = { NETWORK_LOG_DUMP_SCRIPT, NULL };
252 char *const envs[] = { NULL };
254 rv = __netconfig_handle_execute_file(path, args, envs);
256 ERR("Fail to execute network log dump shell");
263 static void _technology_signal_cb(GDBusConnection *conn,
264 const gchar *name, const gchar *path, const gchar *interface,
265 const gchar *sig, GVariant *param, gpointer user_data)
268 gboolean value = FALSE;
269 GVariant *var = NULL;
274 if (g_str_has_prefix(path, CONNMAN_WIFI_TECHNOLOGY_PREFIX) == TRUE) {
275 g_variant_get(param, "(sv)", &key, &var);
276 if (g_strcmp0(key, "Powered") == 0) {
278 value = g_variant_get_boolean(var);
280 wifi_state_update_power_state(TRUE);
282 wifi_state_update_power_state(FALSE);
283 } else if (g_strcmp0(key, "Connected") == 0) {
284 /* Connection state */
285 value = g_variant_get_boolean(var);
287 wifi_state_set_tech_state(NETCONFIG_WIFI_TECH_CONNECTED);
289 wifi_state_set_tech_state(NETCONFIG_WIFI_TECH_POWERED);
290 } else if (g_strcmp0(key, "Tethering") == 0) {
291 /* Tethering state */
292 wifi_state_set_tech_state(NETCONFIG_WIFI_TECH_TETHERED);
297 g_variant_unref(var);
301 static void _service_signal_cb(GDBusConnection *conn,
302 const gchar *name, const gchar *path,
303 const gchar *interface, const gchar *sig,
304 GVariant *param, gpointer user_data)
306 gchar *sigvalue = NULL;
308 GVariant *variant = NULL, *var;
310 const gchar *value = NULL;
311 struct sock_data *sd = NULL;
314 if (path == NULL || param == NULL)
317 g_variant_get(param, "(sv)", &sigvalue, &variant);
318 if (sigvalue == NULL)
321 if (g_strcmp0(sig, CONNMAN_SIGNAL_PROPERTY_CHANGED) != 0)
324 if (g_strcmp0(sigvalue, "State") == 0) {
325 g_variant_get(variant, "s", &property);
327 DBG("[%s] %s", property, path);
328 if (netconfig_is_wifi_profile(path) || netconfig_is_ethernet_profile(path)) {
329 if (g_strcmp0(property, "ready") == 0) {
330 for (idx = 0; idx < MAX_SOCKET_OPEN_RETRY; idx++) {
331 sd = start_ip_conflict_mon();
335 } else if (g_strcmp0(property, "online") == 0) {
338 stop_ip_conflict_mon();
342 if (netconfig_is_wifi_profile(path) == TRUE) {
345 netconfig_vconf_get_int(VCONFKEY_WIFI_STATE, &wifi_state);
346 if (wifi_state == VCONFKEY_WIFI_OFF) {
351 if (g_strcmp0(property, "ready") == 0 || g_strcmp0(property, "online") == 0) {
352 if (wifi_state >= VCONFKEY_WIFI_CONNECTED) {
357 netconfig_update_default_profile(path);
359 wifi_state_set_service_state(NETCONFIG_WIFI_CONNECTED);
361 } else if (g_strcmp0(property, "failure") == 0 || g_strcmp0(property, "disconnect") == 0 || g_strcmp0(property, "idle") == 0) {
362 if (netconfig_get_default_profile() == NULL ||
363 netconfig_is_wifi_profile(netconfig_get_default_profile())
365 if (g_strcmp0(property, "failure") == 0)
366 wifi_state_set_service_state(NETCONFIG_WIFI_FAILURE);
368 wifi_state_set_service_state(NETCONFIG_WIFI_IDLE);
373 if (g_strcmp0(path, netconfig_get_default_profile()) != 0) {
378 netconfig_update_default_profile(NULL);
380 if (g_strcmp0(property, "failure") == 0)
381 wifi_state_set_service_state(NETCONFIG_WIFI_FAILURE);
383 wifi_state_set_service_state(NETCONFIG_WIFI_IDLE);
385 } else if (g_strcmp0(property, "association") == 0 || g_strcmp0(property, "configuration") == 0) {
386 if (netconfig_get_default_profile() == NULL ||
387 netconfig_is_wifi_profile(netconfig_get_default_profile()) != TRUE) {
388 if (g_strcmp0(property, "association") == 0)
389 wifi_state_set_service_state(NETCONFIG_WIFI_ASSOCIATION);
391 wifi_state_set_service_state(NETCONFIG_WIFI_CONFIGURATION);
396 if (g_strcmp0(path, netconfig_get_default_profile()) != 0) {
401 netconfig_update_default_profile(NULL);
403 if (g_strcmp0(property, "association") == 0)
404 wifi_state_set_service_state(NETCONFIG_WIFI_ASSOCIATION);
406 wifi_state_set_service_state(NETCONFIG_WIFI_CONFIGURATION);
410 if (g_strcmp0(property, "ready") == 0 || g_strcmp0(property, "online") == 0) {
411 if (netconfig_get_default_profile() == NULL) {
412 if (!netconfig_is_cellular_profile(path))
413 netconfig_update_default_profile(path);
415 if (netconfig_is_cellular_internet_profile(path))
416 netconfig_update_default_profile(path);
420 if (netconfig_is_cellular_profile(path) && netconfig_is_cellular_internet_profile(path))
421 cellular_state_set_service_state(NETCONFIG_CELLULAR_ONLINE);
423 } else if (g_strcmp0(property, "failure") == 0 || g_strcmp0(property, "disconnect") == 0 || g_strcmp0(property, "idle") == 0) {
424 if (netconfig_get_default_profile() == NULL) {
429 if (netconfig_is_cellular_profile(path) && netconfig_is_cellular_internet_profile(path))
430 cellular_state_set_service_state(NETCONFIG_CELLULAR_IDLE);
432 if (g_strcmp0(path, netconfig_get_default_profile()) != 0) {
437 netconfig_update_default_profile(NULL);
438 } else if (g_strcmp0(property, "association") == 0 || g_strcmp0(property, "configuration") == 0) {
439 if (netconfig_get_default_profile() == NULL) {
444 if (netconfig_is_cellular_profile(path) && netconfig_is_cellular_internet_profile(path))
445 cellular_state_set_service_state(NETCONFIG_CELLULAR_CONNECTING);
447 if (g_strcmp0(path, netconfig_get_default_profile()) != 0) {
452 netconfig_update_default_profile(NULL);
456 } else if (g_strcmp0(sigvalue, "Proxy") == 0) {
457 if (netconfig_is_wifi_profile(path) != TRUE || g_strcmp0(path, netconfig_get_default_profile()) != 0)
460 if (!g_variant_type_equal(variant, G_VARIANT_TYPE_ARRAY))
463 g_variant_get(variant, "a{sv}", &iter);
464 while (g_variant_iter_loop(iter, "{sv}", &property, &var)) {
465 GVariantBuilder *builder;
466 GVariant *sig_params;
467 if (g_strcmp0(property, "Servers") == 0) {
468 GVariantIter *iter_sub = NULL;
470 builder = g_variant_builder_new(G_VARIANT_TYPE("a{sv}"));
472 g_variant_get(var, "as", &iter_sub);
473 g_variant_iter_loop(iter_sub, "s", &value);
474 g_variant_iter_free(iter_sub);
476 DBG("Proxy - [%s]", value);
477 vconf_set_str(VCONFKEY_NETWORK_PROXY, value);
479 g_variant_builder_add(builder, "{sv}", "ProxyAddress",
480 g_variant_new_string(value));
482 sig_params = g_variant_new("(@a{sv})",
483 g_variant_builder_end(builder));
485 netconfig_dbus_emit_signal(NULL, NETCONFIG_NETWORK_PATH,
486 NETCONFIG_NETWORK_INTERFACE, "NetworkConfigChanged",
490 g_variant_unref(var);
492 } else if (g_strcmp0(property, "Method") == 0) {
493 value = g_variant_get_string(var, NULL);
494 DBG("Method - [%s]", value);
496 if (g_strcmp0(value, "direct") == 0) {
497 builder = g_variant_builder_new(G_VARIANT_TYPE("a{sv}"));
499 vconf_set_str(VCONFKEY_NETWORK_PROXY, "");
500 g_variant_builder_add(builder, "{sv}", "ProxyAddress",
501 g_variant_new_string(""));
503 sig_params = g_variant_new("(@a{sv})",
504 g_variant_builder_end(builder));
506 netconfig_dbus_emit_signal(NULL, NETCONFIG_NETWORK_PATH,
507 NETCONFIG_NETWORK_INTERFACE,
508 "NetworkConfigChanged", sig_params);
512 g_variant_unref(var);
517 g_variant_iter_free(iter);
518 } else if (g_strcmp0(sigvalue, "IPv4") == 0) {
519 __netconfig_extract_ipv4_signal_data(variant, path);
520 } else if (g_strcmp0(sigvalue, "IPv6") == 0) {
521 __netconfig_extract_ipv6_signal_data(variant, path);
522 } else if (g_strcmp0(sigvalue, "Error") == 0) {
523 g_variant_get(variant, "s", &property);
524 INFO("[%s] Property : %s", sigvalue, property);
525 #if defined TIZEN_DEBUG_ENABLE
526 if (g_strcmp0(property, "dhcp-failed") == 0
527 || g_strcmp0(property, "connect-failed") == 0
528 || g_strcmp0(property, "login-failed") == 0
529 || g_strcmp0(property, "auth-failed") == 0
530 || g_strcmp0(property, "invalid-key") == 0) {
543 g_variant_unref(variant);
548 static void _dbus_name_changed_cb(GDBusConnection *conn,
549 const gchar *Name, const gchar *path, const gchar *interface,
550 const gchar *sig, GVariant *param, gpointer user_data)
559 g_variant_get(param, "(sss)", &name, &old, &new);
561 if (g_strcmp0(name, CONNMAN_SERVICE) == 0 && *new == '\0') {
562 DBG("ConnMan destroyed: name %s, old %s, new %s", name, old, new);
564 connman_register_agent();
576 static void _services_changed_cb(GDBusConnection *conn, const gchar *name,
577 const gchar *path, const gchar *interface, const gchar *sig,
578 GVariant *param, gpointer user_data)
580 gchar *property, *value;
582 GVariant *variant = NULL;
583 GVariantIter *added = NULL, *removed = NULL, *next = NULL;
585 if (path == NULL || param == NULL)
588 if (g_strcmp0(sig, CONNMAN_SIGNAL_SERVICES_CHANGED) != 0)
591 if (netconfig_get_default_profile() != NULL)
594 g_variant_get(param, "(a(oa{sv})ao)", &added, &removed);
596 while (g_variant_iter_loop(added, "(oa{sv})", &service_path, &next)) {
597 gboolean is_wifi_prof, is_cell_prof, is_cell_internet_prof;
598 is_wifi_prof = netconfig_is_wifi_profile(service_path);
599 is_cell_prof = netconfig_is_cellular_profile(service_path);
600 is_cell_internet_prof = netconfig_is_cellular_internet_profile(
602 if (service_path != NULL) {
603 while (next && g_variant_iter_loop(next, "{sv}", &property,
605 if (g_strcmp0(property, "State") == 0) {
606 g_variant_get(variant, "s", &value);
607 DBG("Profile %s State %s", service_path,
609 if (g_strcmp0(value, "ready") != 0 &&
614 g_variant_unref(variant);
619 netconfig_update_default_profile(
621 else if (is_cell_internet_prof) {
622 netconfig_update_default_profile(
626 wifi_state_set_service_state(
627 NETCONFIG_WIFI_CONNECTED);
628 else if (is_cell_prof &&
629 is_cell_internet_prof)
630 cellular_state_set_service_state(
631 NETCONFIG_CELLULAR_ONLINE);
634 g_variant_unref(variant);
641 g_variant_iter_free(added);
644 g_variant_iter_free(next);
647 g_variant_iter_free(removed);
652 static void _supplicant_interface_removed(GDBusConnection *conn,
653 const gchar *name, const gchar *path, const gchar *interface,
654 const gchar *sig, GVariant *param, gpointer user_data)
656 DBG("Interface removed handling!");
657 if (netconfig_wifi_is_bssid_scan_started() == TRUE)
658 netconfig_wifi_bssid_signal_scanaborted();
663 static void _supplicant_properties_changed(GDBusConnection *conn,
664 const gchar *name, const gchar *path, const gchar *interface,
665 const gchar *sig, GVariant *param, gpointer user_data)
667 DBG("Properties changed handling!");
669 const gchar *state = NULL;
670 GVariantIter *iter = NULL;
671 GVariant *variant = NULL;
672 gboolean scanning = FALSE;
677 g_variant_get(param, "(a{sv})", &iter);
678 while (g_variant_iter_loop(iter, "{sv}", &key, &variant)) {
679 if (g_strcmp0(key, "Scanning") == 0) {
680 scanning = g_variant_get_boolean(variant);
681 DBG("setting scanning %s", scanning ? "TRUE" : "FALSE");
682 if (scanning == TRUE)
683 netconfig_wifi_set_scanning(TRUE);
685 netconfig_wifi_set_scanning(FALSE);
687 g_variant_unref(variant);
692 } else if (g_strcmp0(key, "State") == 0) {
693 state = g_variant_get_string(variant, NULL);
695 ERR("Supplicant state : %s", state);
697 g_variant_unref(variant);
702 } else if (g_strcmp0(key, "DisconnectReason") == 0) {
703 int reason = g_variant_get_int32(variant);
704 ERR("Supplicant DisconnReason : %d", reason);
706 g_variant_unref(variant);
713 value = g_variant_print(variant, TRUE);
714 DBG("Supplicant %s : %s", key, value);
720 g_variant_iter_free(iter);
725 static void _supplicant_bss_added(GDBusConnection *conn,
726 const gchar *name, const gchar *path, const gchar *interface,
727 const gchar *sig, GVariant *param, gpointer user_data)
729 DBG("BSS added handling!");
730 wifi_state_set_bss_found(TRUE);
735 static void _supplicant_scan_done(GDBusConnection *conn,
736 const gchar *name, const gchar *path, const gchar *interface,
737 const gchar *sig, GVariant *param, gpointer user_data)
739 DBG("Scan Done handling!");
740 netconfig_wifi_set_scanning(FALSE);
742 if (netconfig_wifi_is_bssid_scan_started() == TRUE) {
743 netconfig_wifi_bssid_signal_scandone();
744 if (wifi_state_get_technology_state() < NETCONFIG_WIFI_TECH_POWERED)
748 if (netconfig_wifi_get_bgscan_state() == TRUE) {
749 if (wifi_state_get_technology_state() >=
750 NETCONFIG_WIFI_TECH_POWERED)
751 netconfig_wifi_bgscan_start(FALSE);
753 wifi_start_timer_network_notification();
759 static void _supplicant_driver_hanged(GDBusConnection *conn,
760 const gchar *name, const gchar *path, const gchar *interface,
761 const gchar *sig, GVariant *param, gpointer user_data)
763 DBG("Driver Hanged handling!");
764 ERR("Critical. Wi-Fi firmware crashed");
766 #if !defined TIZEN_WEARABLE
767 netconfig_send_message_to_net_popup("Wi-Fi Error",
768 "Wi-Fi Driver Hanged. Please get log dump and report", "popup", NULL);
770 wifi_power_recover_firmware();
776 static void _supplicant_session_overlapped(GDBusConnection *conn,
777 const gchar *name, const gchar *path, const gchar *interface,
778 const gchar *sig, GVariant *param, gpointer user_data)
780 DBG("Driver session overlapped handling!");
781 ERR("WPS PBC SESSION OVERLAPPED");
782 #if defined TIZEN_WEARABLE
785 netconfig_send_message_to_net_popup("WPS Error",
786 "wps session overlapped", "popup", NULL);
790 #if defined TIZEN_DEBUG_ENABLE
791 static void __netconfig_dumpservice_handler(GDBusConnection *conn,
792 const gchar *name, const gchar *path, const gchar *interface,
793 const gchar *sig, GVariant *param, gpointer user_data)
796 gchar *signal_path = NULL;
801 g_variant_get(param, "(is)", &mode, &signal_path);
802 DBG("Path: %s and mode: %d", signal_path, mode);
804 netconfig_dump_log(signal_path);
812 static void _supplicant_tdls_connected(GDBusConnection *conn,
813 const gchar *name, const gchar *path, const gchar *interface,
814 const gchar *sig, GVariant *param, gpointer user_data)
816 DBG("Received TDLS Connected Signal");
817 netconfig_wifi_tdls_connected_event(param);
822 static void _supplicant_tdls_disconnected(GDBusConnection *conn,
823 const gchar *name, const gchar *path, const gchar *interface,
824 const gchar *sig, GVariant *param, gpointer user_data)
826 DBG("Received TDLS Disconnected Signal");
827 netconfig_wifi_tdls_disconnected_event(param);
832 static void _supplicant_tdls_peer_found(GDBusConnection *conn,
833 const gchar *name, const gchar *path, const gchar *interface,
834 const gchar *sig, GVariant *param, gpointer user_data)
836 DBG("Received TDLS Peer Found Signal");
837 netconfig_wifi_tdls_peer_found_event(param);
841 static void _supplicant_wifi_wps_connected(GVariant *param)
844 char ssid[32] = {0, };
848 int config_error = 0;
849 int error_indication = 0;
853 ERR("Param is NULL");
857 g_variant_get(param, "(sa{sv})", &name, &iter);
858 INFO("wps Result: %s", name);
859 while (g_variant_iter_loop(iter, "{sv}", &key, &variant)) {
860 INFO("wps Key is %s", key);
861 if (g_strcmp0(key, "SSID") == 0) {
862 const char *t_key = NULL;
863 t_key = g_variant_get_fixed_array(variant, &ssid_len, sizeof(guchar));
864 INFO("wps ssid_len is %d ", ssid_len);
867 g_variant_unref(variant);
868 ERR("WPS PBC Connection Failed");
871 if (ssid_len > 0 && ssid_len <= 32) {
872 memcpy(ssid, t_key, ssid_len);
874 memset(ssid, 0, sizeof(ssid));
877 INFO("WPS PBC Connection completed with AP %s", ssid);
878 netconfig_wifi_notify_wps_completed(ssid, ssid_len);
882 g_variant_iter_free(iter);
887 g_variant_iter_free(iter);
889 error_indication = WPS_EI_OPERATION_FAILED;
890 config_error = WPS_CFG_NO_ERROR;
891 ERR("Error Occured! Notifying Fail Event");
892 netconfig_wifi_notify_wps_fail_event(config_error, error_indication);
896 static void _supplicant_wifi_wps_event(GVariant *param)
902 gint32 config_error = 0;
903 gint32 error_indication = 0;
906 ERR("Param is NULL");
910 g_variant_get(param, "(sa{sv})", &name, &iter);
911 INFO("Event Result: %s", name);
912 if (g_strcmp0(name, "fail") == 0) {
913 while (g_variant_iter_loop(iter, "{sv}", &key, &variant)) {
916 INFO("Key is %s", key);
917 if (g_strcmp0(key, "config_error") == 0) {
918 config_error = g_variant_get_int32(variant);
919 ERR("Config Error %d", config_error);
920 } else if (g_strcmp0(key, "error_indication") == 0) {
921 error_indication = g_variant_get_int32(variant);
922 ERR("Error Indication %d", error_indication);
925 netconfig_wifi_notify_wps_fail_event(config_error, error_indication);
928 g_variant_iter_free(iter);
933 g_variant_iter_free(iter);
935 error_indication = WPS_EI_OPERATION_FAILED;
936 config_error = WPS_CFG_NO_ERROR;
937 ERR("Error Occured! Notifying Fail Event");
938 netconfig_wifi_notify_wps_fail_event(config_error, error_indication);
941 static void _find_service_and_set_passphrase(char *ssid, char *key)
944 GVariant *reply = NULL;
949 gchar *enc_passphrase;
951 ssid_len = strlen(ssid);
953 str = g_string_sized_new((ssid_len * 2) + 55);
957 dev_mac_addr = vconf_get_str(VCONFKEY_WIFI_BSSID_ADDRESS);
959 ERR("Failed to get mac address from vconf key");
960 g_string_free(str, TRUE);
965 for (i = 0; dev_mac_addr[i]; i++) {
966 if (dev_mac_addr[i] != ':')
967 ident[j++] = dev_mac_addr[i];
971 g_string_append_printf(str, "%s%s_", CONNMAN_WIFI_SERVICE_PROFILE_PREFIX,
975 for (i = 0; i < ssid_len; i++) {
977 g_string_append_printf(str, "%02x", ssid[i]);
980 g_string_append_printf(str, "_managed_psk");
982 service_path = g_string_free(str, FALSE);
984 enc_passphrase = _netconfig_encrypt_passphrase(key);
985 if (!enc_passphrase) {
986 ERR("Failed to encrypt passphrase");
987 g_free(service_path);
991 INFO("wps service_path %s Passphrase %s", service_path, enc_passphrase);
993 reply = netconfig_invoke_dbus_method(CONNMAN_SERVICE, service_path,
994 CONNMAN_SERVICE_INTERFACE, "SetProperty",
995 g_variant_new("(sv)", "Passphrase",
996 g_variant_new_string(enc_passphrase)));
998 g_variant_unref(reply);
1000 ERR("Failed to set passphrase");
1002 g_free(service_path);
1007 static void _supplicant_wifi_wps_credentials(GVariant *param)
1010 char ssid[32] = {0, };
1011 char wps_key[100] = {0, };
1014 int config_error = 0;
1015 int error_indication = 0;
1017 char *key_mgmt = NULL;
1019 if (param == NULL) {
1020 ERR("Param is NULL");
1024 g_variant_get(param, "(a{sv})", &iter);
1025 while (g_variant_iter_loop(iter, "{sv}", &key, &variant)) {
1028 INFO("wps Key is %s", key);
1029 if (g_strcmp0(key, "Key") == 0) {
1031 const char *t_key = NULL;
1032 key_len = g_variant_get_size(variant);
1034 INFO("wps password len %d ", key_len);
1036 t_key = g_variant_get_fixed_array(variant, &key_len,
1040 g_variant_unref(variant);
1043 strncpy(wps_key, t_key, key_len);
1044 wps_key[key_len] = '\0';
1045 INFO("WPS Key in process credentials %s", wps_key);
1047 SLOGI("WPS AP Security ->Open");
1048 } else if (g_strcmp0(key, "SSID") == 0) {
1049 const char *t_key = NULL;
1050 t_key = g_variant_get_fixed_array(variant, &ssid_len,
1052 INFO("wps ssid_len is %d ", ssid_len);
1055 g_variant_unref(variant);
1058 if (ssid_len > 0 && ssid_len <= 32) {
1059 memcpy(ssid, t_key, ssid_len);
1061 memset(ssid, 0, sizeof(ssid));
1064 INFO("SSID in process credentials %s", ssid);
1065 } else if (g_strcmp0(key, "AuthType") == 0) {
1067 GVariantIter *var_iter;
1068 g_variant_get(variant, "as", &var_iter);
1069 while (g_variant_iter_loop(var_iter, "s", &auth_type)) {
1070 INFO("wps auth_type %s", auth_type);
1071 if (g_strcmp0(auth_type, "wpa-psk") == 0 ||
1072 g_strcmp0(auth_type, "wpa2-psk") == 0)
1074 else if (g_strcmp0(auth_type, "open") == 0)
1077 g_variant_iter_free(var_iter);
1078 } else if (g_strcmp0(key, "EncrType") == 0) {
1080 GVariantIter *var_iter;
1081 g_variant_get(variant, "as", &var_iter);
1082 while (g_variant_iter_loop(var_iter, "s", &encr_type))
1083 INFO("wps encr_type %s", encr_type);
1084 g_variant_iter_free(var_iter);
1085 } else if (g_strcmp0(key, "BSSID") == 0) {
1086 const guchar *bssid;
1088 bssid = g_variant_get_fixed_array(variant, &bssid_len,
1090 if (bssid && bssid_len == 6)
1091 INFO("wps BSSID %2x:%2x:%2x:%2x:%2x:%2x", bssid[0], bssid[1],
1092 bssid[2], bssid[3], bssid[4], bssid[5]);
1096 g_variant_iter_free(iter);
1098 if (g_strcmp0(key_mgmt, "psk") == 0)
1099 _find_service_and_set_passphrase(ssid, wps_key);
1103 * Notify WPS Credentials only when requested through WPS PBC
1104 * In case of WPS PIN connman will take care of notification
1106 if (netconfig_get_wps_field() == TRUE)
1108 netconfig_wifi_notify_wps_credentials(ssid, ssid_len, wps_key);
1112 g_variant_iter_free(iter);
1113 error_indication = WPS_EI_OPERATION_FAILED;
1114 config_error = WPS_CFG_NO_ERROR;
1115 ERR("Error Occured! Notifying Fail Event");
1116 netconfig_wifi_notify_wps_fail_event(config_error, error_indication);
1119 static void __netconfig_wps_signal_filter_handler(GDBusConnection *conn,
1120 const gchar *name, const gchar *path, const gchar *interface,
1121 const gchar *sig, GVariant *param, gpointer user_data)
1123 if (g_strcmp0(sig, SIGNAL_WPS_CREDENTIALS) == 0) {
1124 INFO("Received wps CREDENTIALS Signal from Supplicant");
1125 _supplicant_wifi_wps_credentials(param);
1126 } else if (g_strcmp0(sig, SIGNAL_WPS_EVENT) == 0) {
1127 INFO("Received wps EVENT Signal from Supplicant");
1128 _supplicant_wifi_wps_event(param);
1129 } else if (g_strcmp0(sig, SIGNAL_WPS_CONNECTED) == 0) {
1130 INFO("Received WPSConnected Signal from Supplicant");
1131 _supplicant_wifi_wps_connected(param);
1137 static supplicant_signal_cb supplicant_cbs[SIG_MAX] = {
1138 _supplicant_interface_removed,
1139 _supplicant_properties_changed,
1140 _supplicant_bss_added,
1141 _supplicant_scan_done,
1142 _supplicant_driver_hanged,
1143 _supplicant_session_overlapped,
1144 _supplicant_tdls_connected,
1145 _supplicant_tdls_disconnected,
1146 _supplicant_tdls_peer_found
1149 void register_gdbus_signal(void)
1151 GDBusConnection *connection = NULL;
1152 const char *interface = NULL;
1153 SuppSigArrayIndex sig;
1154 connection = netdbus_get_connection();
1156 if (connection == NULL) {
1157 ERR("Failed to get GDbus Connection");
1161 /* listening to messages from all objects as no path is specified */
1162 /* see signals from the given interface */
1163 conn_subscription_ids[0] = g_dbus_connection_signal_subscribe(
1166 CONNMAN_TECHNOLOGY_INTERFACE,
1170 G_DBUS_SIGNAL_FLAGS_NONE,
1171 _technology_signal_cb,
1175 conn_subscription_ids[1] = g_dbus_connection_signal_subscribe(
1178 CONNMAN_SERVICE_INTERFACE,
1179 CONNMAN_SIGNAL_PROPERTY_CHANGED,
1182 G_DBUS_SIGNAL_FLAGS_NONE,
1187 conn_subscription_ids[2] = g_dbus_connection_signal_subscribe(
1190 DBUS_INTERFACE_DBUS,
1191 CONNMAN_SIGNAL_NAME_CHANGED,
1194 G_DBUS_SIGNAL_FLAGS_NONE,
1195 _dbus_name_changed_cb,
1199 conn_subscription_ids[3] = g_dbus_connection_signal_subscribe(
1202 CONNMAN_MANAGER_INTERFACE,
1203 CONNMAN_SIGNAL_SERVICES_CHANGED,
1206 G_DBUS_SIGNAL_FLAGS_NONE,
1207 _services_changed_cb,
1211 INFO("Successfully register connman DBus signal filters");
1213 conn_subscription_ids[4] = g_dbus_connection_signal_subscribe(
1216 SUPPLICANT_INTERFACE ".Interface.WPS",
1220 G_DBUS_SIGNAL_FLAGS_NONE,
1221 __netconfig_wps_signal_filter_handler,
1225 INFO("Successfully register Supplicant WPS DBus signal filters");
1227 for (sig = SIG_INTERFACE_REMOVED; sig < SIG_MAX; sig++) {
1229 * For SIG_INTERFACE_REMOVED INTERFACE_ADDED
1231 interface = (sig == SIG_INTERFACE_REMOVED) ?
1232 SUPPLICANT_INTERFACE : SUPPLICANT_IFACE_INTERFACE;
1234 supp_subscription_ids[sig] = g_dbus_connection_signal_subscribe(
1238 supplicant_signals[sig],
1241 G_DBUS_SIGNAL_FLAGS_NONE,
1242 supplicant_cbs[sig],
1247 INFO("Successfully register Supplicant DBus signal filters");
1249 #if defined TIZEN_DEBUG_ENABLE
1250 dumpservice_subscription_id = g_dbus_connection_signal_subscribe(
1253 DUMP_SERVICE_INTERFACE,
1257 G_DBUS_SIGNAL_FLAGS_NONE,
1258 __netconfig_dumpservice_handler,
1262 INFO("Successfully registered Dumpservice DBus signal filter");
1265 /* In case ConnMan precedes this signal register,
1266 * net-config should update the default connected profile.
1268 netconfig_update_default();
1271 void deregister_gdbus_signal(void)
1273 GDBusConnection *connection = NULL;
1275 SuppSigArrayIndex sig;
1276 connection = netdbus_get_connection();
1278 ERR("Already de-registered. Nothing to be done");
1282 for (signal = 0; signal < TOTAL_CONN_SIGNALS; signal++) {
1283 if (conn_subscription_ids[signal]) {
1284 g_dbus_connection_signal_unsubscribe(connection,
1285 conn_subscription_ids[signal]);
1289 for (sig = SIG_INTERFACE_REMOVED; sig < SIG_MAX; sig++) {
1290 if (supp_subscription_ids[sig]) {
1291 g_dbus_connection_signal_unsubscribe(connection,
1292 supp_subscription_ids[sig]);
1296 #if defined TIZEN_DEBUG_ENABLE
1297 g_dbus_connection_signal_unsubscribe(connection,
1298 dumpservice_subscription_id);