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 g_variant_builder_unref(builder);
148 netconfig_dbus_emit_signal(NULL, NETCONFIG_NETWORK_PATH,
149 NETCONFIG_NETWORK_INTERFACE, "NetworkConfigChanged",
157 static void __netconfig_extract_ipv6_signal_data(GVariant *dictionary,
158 const gchar *profile)
161 const gchar *value = NULL;
162 GVariant *var = NULL;
164 GVariantBuilder *builder;
167 g_variant_iter_init(&iter, dictionary);
168 while (g_variant_iter_loop(&iter, "{sv}", &key, &var)) {
169 if (g_strcmp0(key, "Address") == 0) {
170 g_variant_get(var, "&s", &value);
171 char *old_ip6 = vconf_get_str(VCONFKEY_NETWORK_IP6);
173 DBG("Old IPv6.Address [%s] Received new IPv6.Address [%s]", old_ip6,
175 if (g_strcmp0(old_ip6, value) != 0) {
176 builder = g_variant_builder_new(G_VARIANT_TYPE("a{sv}"));
179 vconf_set_str(VCONFKEY_NETWORK_IP6, value);
180 g_variant_builder_add(builder, "{sv}", "IPv6Address",
181 g_variant_new_string(value));
182 } else if (old_ip6 != NULL && strlen(old_ip6) > 0) {
183 vconf_set_str(VCONFKEY_NETWORK_IP6, "");
184 g_variant_builder_add(builder, "{sv}", "IPv6Address",
185 g_variant_new_string(""));
188 params = g_variant_new("(@a{sv})",
189 g_variant_builder_end(builder));
190 g_variant_builder_unref(builder);
192 netconfig_dbus_emit_signal(NULL, NETCONFIG_NETWORK_PATH,
193 NETCONFIG_NETWORK_INTERFACE, "NetworkConfigChanged",
201 #if defined TIZEN_DEBUG_ENABLE
202 static int __netconfig_handle_execute_file(const char *file_path,
203 char *const args[], char *const envs[])
209 register unsigned int index = 0;
210 char error_buf[MAX_SIZE_ERROR_BUFFER] = {0, };
212 while (args[index] != NULL) {
213 DBG("%s", args[index]);
217 if (!(pid = fork())) {
218 DBG("pid(%d), ppid (%d)", getpid(), getppid());
219 DBG("Inside child, exec (%s) command", file_path);
222 if (execve(file_path, args, envs) == -1) {
223 DBG("Fail to execute command (%s)",
224 strerror_r(errno, error_buf, MAX_SIZE_ERROR_BUFFER));
227 } else if (pid > 0) {
228 if (waitpid(pid, &status, 0) == -1)
229 DBG("wait pid (%u) status (%d)", pid, status);
231 if (WIFEXITED(status)) {
232 rv = WEXITSTATUS(status);
233 DBG("exited, status=%d", rv);
234 } else if (WIFSIGNALED(status)) {
235 DBG("killed by signal %d", WTERMSIG(status));
236 } else if (WIFSTOPPED(status)) {
237 DBG("stopped by signal %d", WSTOPSIG(status));
238 } else if (WIFCONTINUED(status)) {
245 DBG("failed to fork(%s)",
246 strerror_r(errno, error_buf, MAX_SIZE_ERROR_BUFFER));
250 static int _start_dump()
253 gchar *path = NETWORK_LOG_DUMP_SCRIPT;
254 char *const args[] = { NETWORK_LOG_DUMP_SCRIPT, NULL };
255 char *const envs[] = { NULL };
257 rv = __netconfig_handle_execute_file(path, args, envs);
259 ERR("Fail to execute network log dump shell");
266 static void _technology_signal_cb(GDBusConnection *conn,
267 const gchar *name, const gchar *path, const gchar *interface,
268 const gchar *sig, GVariant *param, gpointer user_data)
271 gboolean value = FALSE;
272 GVariant *var = NULL;
277 if (g_str_has_prefix(path, CONNMAN_WIFI_TECHNOLOGY_PREFIX) == TRUE) {
278 g_variant_get(param, "(sv)", &key, &var);
279 if (g_strcmp0(key, "Powered") == 0) {
281 value = g_variant_get_boolean(var);
283 wifi_state_update_power_state(TRUE);
285 wifi_state_update_power_state(FALSE);
286 } else if (g_strcmp0(key, "Connected") == 0) {
287 /* Connection state */
288 value = g_variant_get_boolean(var);
290 wifi_state_set_tech_state(NETCONFIG_WIFI_TECH_CONNECTED);
292 wifi_state_set_tech_state(NETCONFIG_WIFI_TECH_POWERED);
293 } else if (g_strcmp0(key, "Tethering") == 0) {
294 /* Tethering state */
295 wifi_state_set_tech_state(NETCONFIG_WIFI_TECH_TETHERED);
298 g_variant_unref(var);
302 static void _service_signal_cb(GDBusConnection *conn,
303 const gchar *name, const gchar *path,
304 const gchar *interface, const gchar *sig,
305 GVariant *param, gpointer user_data)
307 gchar *sigvalue = NULL;
309 GVariant *variant = NULL, *var;
311 const gchar *value = NULL;
312 struct sock_data *sd = NULL;
315 if (path == NULL || param == NULL)
318 g_variant_get(param, "(sv)", &sigvalue, &variant);
319 if (sigvalue == NULL)
322 if (g_strcmp0(sig, CONNMAN_SIGNAL_PROPERTY_CHANGED) != 0)
325 if (g_strcmp0(sigvalue, "State") == 0) {
326 g_variant_get(variant, "s", &property);
328 DBG("[%s] %s", property, path);
330 if (netconfig_is_wifi_profile(path) == TRUE) {
333 netconfig_vconf_get_int(VCONFKEY_WIFI_STATE, &wifi_state);
334 if (wifi_state == VCONFKEY_WIFI_OFF) {
339 if (g_strcmp0(property, "ready") == 0 || g_strcmp0(property, "online") == 0) {
340 if (wifi_state >= VCONFKEY_WIFI_CONNECTED) {
345 netconfig_update_default_profile(path);
347 wifi_state_set_service_state(NETCONFIG_WIFI_CONNECTED);
349 } else if (g_strcmp0(property, "failure") == 0 || g_strcmp0(property, "disconnect") == 0 || g_strcmp0(property, "idle") == 0) {
350 if (netconfig_get_default_profile() == NULL ||
351 netconfig_is_wifi_profile(netconfig_get_default_profile())
353 if (g_strcmp0(property, "failure") == 0)
354 wifi_state_set_service_state(NETCONFIG_WIFI_FAILURE);
356 wifi_state_set_service_state(NETCONFIG_WIFI_IDLE);
361 if (g_strcmp0(path, netconfig_get_default_profile()) != 0) {
366 netconfig_update_default_profile(NULL);
368 if (g_strcmp0(property, "failure") == 0)
369 wifi_state_set_service_state(NETCONFIG_WIFI_FAILURE);
371 wifi_state_set_service_state(NETCONFIG_WIFI_IDLE);
373 } else if (g_strcmp0(property, "association") == 0 || g_strcmp0(property, "configuration") == 0) {
374 if (netconfig_get_default_profile() == NULL ||
375 netconfig_is_wifi_profile(netconfig_get_default_profile()) != TRUE) {
376 if (g_strcmp0(property, "association") == 0)
377 wifi_state_set_service_state(NETCONFIG_WIFI_ASSOCIATION);
379 wifi_state_set_service_state(NETCONFIG_WIFI_CONFIGURATION);
384 if (g_strcmp0(path, netconfig_get_default_profile()) != 0) {
389 netconfig_update_default_profile(NULL);
391 if (g_strcmp0(property, "association") == 0)
392 wifi_state_set_service_state(NETCONFIG_WIFI_ASSOCIATION);
394 wifi_state_set_service_state(NETCONFIG_WIFI_CONFIGURATION);
398 if (g_strcmp0(property, "ready") == 0 || g_strcmp0(property, "online") == 0) {
399 if (netconfig_get_default_profile() == NULL) {
400 if (!netconfig_is_cellular_profile(path))
401 netconfig_update_default_profile(path);
403 if (netconfig_is_cellular_internet_profile(path))
404 netconfig_update_default_profile(path);
408 if (netconfig_is_cellular_profile(path) && netconfig_is_cellular_internet_profile(path))
409 cellular_state_set_service_state(NETCONFIG_CELLULAR_ONLINE);
411 } else if (g_strcmp0(property, "failure") == 0 || g_strcmp0(property, "disconnect") == 0 || g_strcmp0(property, "idle") == 0) {
412 if (netconfig_get_default_profile() == NULL) {
417 if (netconfig_is_cellular_profile(path) && netconfig_is_cellular_internet_profile(path))
418 cellular_state_set_service_state(NETCONFIG_CELLULAR_IDLE);
420 if (g_strcmp0(path, netconfig_get_default_profile()) != 0) {
425 netconfig_update_default_profile(NULL);
426 } else if (g_strcmp0(property, "association") == 0 || g_strcmp0(property, "configuration") == 0) {
427 if (netconfig_get_default_profile() == NULL) {
432 if (netconfig_is_cellular_profile(path) && netconfig_is_cellular_internet_profile(path))
433 cellular_state_set_service_state(NETCONFIG_CELLULAR_CONNECTING);
435 if (g_strcmp0(path, netconfig_get_default_profile()) != 0) {
440 netconfig_update_default_profile(NULL);
444 if (netconfig_is_wifi_profile(path) || netconfig_is_ethernet_profile(path)) {
445 if (g_strcmp0(property, "ready") == 0) {
446 for (idx = 0; idx < MAX_SOCKET_OPEN_RETRY; idx++) {
447 sd = start_ip_conflict_mon();
451 } else if (g_strcmp0(property, "online") == 0) {
454 stop_ip_conflict_mon();
459 } else if (g_strcmp0(sigvalue, "Proxy") == 0) {
460 if (netconfig_is_wifi_profile(path) != TRUE || g_strcmp0(path, netconfig_get_default_profile()) != 0)
463 if (!g_variant_is_of_type(variant, G_VARIANT_TYPE_ARRAY))
466 g_variant_get(variant, "a{sv}", &iter);
467 while (g_variant_iter_loop(iter, "{sv}", &property, &var)) {
468 GVariantBuilder *builder;
469 GVariant *sig_params;
470 if (g_strcmp0(property, "Servers") == 0) {
471 GVariantIter *iter_sub = NULL;
473 builder = g_variant_builder_new(G_VARIANT_TYPE("a{sv}"));
475 g_variant_get(var, "as", &iter_sub);
476 g_variant_iter_loop(iter_sub, "s", &value);
477 g_variant_iter_free(iter_sub);
479 DBG("Proxy - [%s]", value);
480 vconf_set_str(VCONFKEY_NETWORK_PROXY, value);
482 g_variant_builder_add(builder, "{sv}", "ProxyAddress",
483 g_variant_new_string(value));
485 sig_params = g_variant_new("(@a{sv})",
486 g_variant_builder_end(builder));
487 g_variant_builder_unref(builder);
489 netconfig_dbus_emit_signal(NULL, NETCONFIG_NETWORK_PATH,
490 NETCONFIG_NETWORK_INTERFACE, "NetworkConfigChanged",
494 g_variant_unref(var);
496 } else if (g_strcmp0(property, "Method") == 0) {
497 value = g_variant_get_string(var, NULL);
498 DBG("Method - [%s]", value);
500 if (g_strcmp0(value, "direct") == 0) {
501 builder = g_variant_builder_new(G_VARIANT_TYPE("a{sv}"));
503 vconf_set_str(VCONFKEY_NETWORK_PROXY, "");
504 g_variant_builder_add(builder, "{sv}", "ProxyAddress",
505 g_variant_new_string(""));
507 sig_params = g_variant_new("(@a{sv})",
508 g_variant_builder_end(builder));
509 g_variant_builder_unref(builder);
511 netconfig_dbus_emit_signal(NULL, NETCONFIG_NETWORK_PATH,
512 NETCONFIG_NETWORK_INTERFACE,
513 "NetworkConfigChanged", sig_params);
517 g_variant_unref(var);
522 g_variant_iter_free(iter);
523 } else if (g_strcmp0(sigvalue, "IPv4") == 0) {
524 __netconfig_extract_ipv4_signal_data(variant, path);
525 } else if (g_strcmp0(sigvalue, "IPv6") == 0) {
526 __netconfig_extract_ipv6_signal_data(variant, path);
527 } else if (g_strcmp0(sigvalue, "Error") == 0) {
528 g_variant_get(variant, "s", &property);
529 INFO("[%s] Property : %s", sigvalue, property);
530 #if defined TIZEN_DEBUG_ENABLE
531 if (g_strcmp0(property, "dhcp-failed") == 0
532 || g_strcmp0(property, "connect-failed") == 0
533 || g_strcmp0(property, "login-failed") == 0
534 || g_strcmp0(property, "auth-failed") == 0
535 || g_strcmp0(property, "invalid-key") == 0) {
547 g_variant_unref(variant);
552 static void _dbus_name_changed_cb(GDBusConnection *conn,
553 const gchar *Name, const gchar *path, const gchar *interface,
554 const gchar *sig, GVariant *param, gpointer user_data)
563 g_variant_get(param, "(sss)", &name, &old, &new);
565 if (g_strcmp0(name, CONNMAN_SERVICE) == 0 && *new == '\0') {
566 DBG("ConnMan destroyed: name %s, old %s, new %s", name, old, new);
568 connman_register_agent();
577 static void _services_changed_cb(GDBusConnection *conn, const gchar *name,
578 const gchar *path, const gchar *interface, const gchar *sig,
579 GVariant *param, gpointer user_data)
581 gchar *property, *value;
583 GVariant *variant = NULL;
584 GVariantIter *added = NULL, *removed = NULL, *next = NULL;
586 if (path == NULL || param == NULL)
589 if (g_strcmp0(sig, CONNMAN_SIGNAL_SERVICES_CHANGED) != 0)
592 if (netconfig_get_default_profile() != NULL)
595 g_variant_get(param, "(a(oa{sv})ao)", &added, &removed);
597 while (g_variant_iter_loop(added, "(oa{sv})", &service_path, &next)) {
598 gboolean is_wifi_prof, is_cell_prof, is_cell_internet_prof;
599 is_wifi_prof = netconfig_is_wifi_profile(service_path);
600 is_cell_prof = netconfig_is_cellular_profile(service_path);
601 is_cell_internet_prof = netconfig_is_cellular_internet_profile(
603 if (service_path != NULL) {
604 while (next && g_variant_iter_loop(next, "{sv}", &property,
606 if (g_strcmp0(property, "State") == 0) {
607 g_variant_get(variant, "s", &value);
608 DBG("Profile %s State %s", service_path,
610 if (g_strcmp0(value, "ready") != 0 &&
615 g_variant_unref(variant);
620 netconfig_update_default_profile(
622 else if (is_cell_internet_prof) {
623 netconfig_update_default_profile(
627 wifi_state_set_service_state(
628 NETCONFIG_WIFI_CONNECTED);
629 else if (is_cell_prof &&
630 is_cell_internet_prof)
631 cellular_state_set_service_state(
632 NETCONFIG_CELLULAR_ONLINE);
635 g_variant_unref(variant);
642 g_variant_iter_free(added);
645 g_variant_iter_free(next);
648 g_variant_iter_free(removed);
653 static void _supplicant_interface_removed(GDBusConnection *conn,
654 const gchar *name, const gchar *path, const gchar *interface,
655 const gchar *sig, GVariant *param, gpointer user_data)
657 DBG("Interface removed handling!");
658 if (netconfig_wifi_is_bssid_scan_started() == TRUE)
659 netconfig_wifi_bssid_signal_scanaborted();
664 static void _supplicant_properties_changed(GDBusConnection *conn,
665 const gchar *name, const gchar *path, const gchar *interface,
666 const gchar *sig, GVariant *param, gpointer user_data)
668 DBG("Properties changed handling!");
670 const gchar *state = NULL;
671 GVariantIter *iter = NULL;
672 GVariant *variant = NULL;
673 gboolean scanning = FALSE;
678 g_variant_get(param, "(a{sv})", &iter);
679 while (g_variant_iter_loop(iter, "{sv}", &key, &variant)) {
680 if (g_strcmp0(key, "Scanning") == 0) {
681 scanning = g_variant_get_boolean(variant);
682 DBG("setting scanning %s", scanning ? "TRUE" : "FALSE");
683 if (scanning == TRUE)
684 netconfig_wifi_set_scanning(TRUE);
686 netconfig_wifi_set_scanning(FALSE);
688 g_variant_unref(variant);
693 } else if (g_strcmp0(key, "State") == 0) {
694 state = g_variant_get_string(variant, NULL);
696 ERR("Supplicant state : %s", state);
698 g_variant_unref(variant);
703 } else if (g_strcmp0(key, "DisconnectReason") == 0) {
704 int reason = g_variant_get_int32(variant);
705 ERR("Supplicant DisconnReason : %d", reason);
707 g_variant_unref(variant);
714 value = g_variant_print(variant, TRUE);
715 DBG("Supplicant %s : %s", key, value);
721 g_variant_iter_free(iter);
726 static void _supplicant_bss_added(GDBusConnection *conn,
727 const gchar *name, const gchar *path, const gchar *interface,
728 const gchar *sig, GVariant *param, gpointer user_data)
730 DBG("BSS added handling!");
731 wifi_state_set_bss_found(TRUE);
736 static void _supplicant_scan_done(GDBusConnection *conn,
737 const gchar *name, const gchar *path, const gchar *interface,
738 const gchar *sig, GVariant *param, gpointer user_data)
740 DBG("Scan Done handling!");
741 netconfig_wifi_set_scanning(FALSE);
743 if (netconfig_wifi_is_bssid_scan_started() == TRUE) {
744 netconfig_wifi_bssid_signal_scandone();
745 if (wifi_state_get_technology_state() < NETCONFIG_WIFI_TECH_POWERED)
749 if (netconfig_wifi_get_bgscan_state() == TRUE) {
750 if (wifi_state_get_technology_state() >=
751 NETCONFIG_WIFI_TECH_POWERED)
752 netconfig_wifi_bgscan_start(FALSE);
754 wifi_start_timer_network_notification();
760 static void _supplicant_driver_hanged(GDBusConnection *conn,
761 const gchar *name, const gchar *path, const gchar *interface,
762 const gchar *sig, GVariant *param, gpointer user_data)
764 DBG("Driver Hanged handling!");
765 ERR("Critical. Wi-Fi firmware crashed");
767 #if !defined TIZEN_WEARABLE
768 netconfig_send_message_to_net_popup("Wi-Fi Error",
769 "Wi-Fi Driver Hanged. Please get log dump and report", "popup", NULL);
771 wifi_power_recover_firmware();
777 static void _supplicant_session_overlapped(GDBusConnection *conn,
778 const gchar *name, const gchar *path, const gchar *interface,
779 const gchar *sig, GVariant *param, gpointer user_data)
781 DBG("Driver session overlapped handling!");
782 ERR("WPS PBC SESSION OVERLAPPED");
783 #if defined TIZEN_WEARABLE
786 netconfig_send_message_to_net_popup("WPS Error",
787 "wps session overlapped", "popup", NULL);
791 #if defined TIZEN_DEBUG_ENABLE
792 static void __netconfig_dumpservice_handler(GDBusConnection *conn,
793 const gchar *name, const gchar *path, const gchar *interface,
794 const gchar *sig, GVariant *param, gpointer user_data)
797 gchar *signal_path = NULL;
802 g_variant_get(param, "(is)", &mode, &signal_path);
803 DBG("Path: %s and mode: %d", signal_path, mode);
805 netconfig_dump_log(signal_path);
813 static void _supplicant_tdls_connected(GDBusConnection *conn,
814 const gchar *name, const gchar *path, const gchar *interface,
815 const gchar *sig, GVariant *param, gpointer user_data)
817 DBG("Received TDLS Connected Signal");
818 netconfig_wifi_tdls_connected_event(param);
823 static void _supplicant_tdls_disconnected(GDBusConnection *conn,
824 const gchar *name, const gchar *path, const gchar *interface,
825 const gchar *sig, GVariant *param, gpointer user_data)
827 DBG("Received TDLS Disconnected Signal");
828 netconfig_wifi_tdls_disconnected_event(param);
833 static void _supplicant_tdls_peer_found(GDBusConnection *conn,
834 const gchar *name, const gchar *path, const gchar *interface,
835 const gchar *sig, GVariant *param, gpointer user_data)
837 DBG("Received TDLS Peer Found Signal");
838 netconfig_wifi_tdls_peer_found_event(param);
842 static void _supplicant_wifi_wps_connected(GVariant *param)
845 char ssid[32] = {0, };
849 int config_error = 0;
850 int error_indication = 0;
854 ERR("Param is NULL");
858 g_variant_get(param, "(sa{sv})", &name, &iter);
859 INFO("wps Result: %s", name);
860 while (g_variant_iter_loop(iter, "{sv}", &key, &variant)) {
861 INFO("wps Key is %s", key);
862 if (g_strcmp0(key, "SSID") == 0) {
863 const char *t_key = NULL;
864 t_key = g_variant_get_fixed_array(variant, &ssid_len, sizeof(guchar));
865 INFO("wps ssid_len is %d ", ssid_len);
868 g_variant_unref(variant);
869 ERR("WPS PBC Connection Failed");
872 if (ssid_len > 0 && ssid_len <= 32) {
873 memcpy(ssid, t_key, ssid_len);
875 memset(ssid, 0, sizeof(ssid));
878 INFO("WPS PBC Connection completed with AP %s", ssid);
879 netconfig_wifi_notify_wps_completed(ssid, ssid_len);
883 g_variant_iter_free(iter);
888 g_variant_iter_free(iter);
890 error_indication = WPS_EI_OPERATION_FAILED;
891 config_error = WPS_CFG_NO_ERROR;
892 ERR("Error Occured! Notifying Fail Event");
893 netconfig_wifi_notify_wps_fail_event(config_error, error_indication);
897 static void _supplicant_wifi_wps_event(GVariant *param)
903 gint32 config_error = 0;
904 gint32 error_indication = 0;
907 ERR("Param is NULL");
911 g_variant_get(param, "(sa{sv})", &name, &iter);
912 INFO("Event Result: %s", name);
913 if (g_strcmp0(name, "fail") == 0) {
914 while (g_variant_iter_loop(iter, "{sv}", &key, &variant)) {
917 INFO("Key is %s", key);
918 if (g_strcmp0(key, "config_error") == 0) {
919 config_error = g_variant_get_int32(variant);
920 ERR("Config Error %d", config_error);
921 } else if (g_strcmp0(key, "error_indication") == 0) {
922 error_indication = g_variant_get_int32(variant);
923 ERR("Error Indication %d", error_indication);
926 netconfig_wifi_notify_wps_fail_event(config_error, error_indication);
929 g_variant_iter_free(iter);
934 g_variant_iter_free(iter);
936 error_indication = WPS_EI_OPERATION_FAILED;
937 config_error = WPS_CFG_NO_ERROR;
938 ERR("Error Occured! Notifying Fail Event");
939 netconfig_wifi_notify_wps_fail_event(config_error, error_indication);
942 static void _find_service_and_set_passphrase(char *ssid, char *key)
945 GVariant *reply = NULL;
950 gchar *enc_passphrase;
952 ssid_len = strlen(ssid);
954 str = g_string_sized_new((ssid_len * 2) + 55);
958 dev_mac_addr = vconf_get_str(VCONFKEY_WIFI_BSSID_ADDRESS);
960 ERR("Failed to get mac address from vconf key");
961 g_string_free(str, TRUE);
966 for (i = 0; dev_mac_addr[i]; i++) {
967 if (dev_mac_addr[i] != ':')
968 ident[j++] = dev_mac_addr[i];
972 g_string_append_printf(str, "%s%s_", CONNMAN_WIFI_SERVICE_PROFILE_PREFIX,
976 for (i = 0; i < ssid_len; i++) {
978 g_string_append_printf(str, "%02x", ssid[i]);
981 g_string_append_printf(str, "_managed_psk");
983 service_path = g_string_free(str, FALSE);
985 enc_passphrase = _netconfig_encrypt_passphrase(key);
986 if (!enc_passphrase) {
987 ERR("Failed to encrypt passphrase");
988 g_free(service_path);
992 INFO("wps service_path %s Passphrase %s", service_path, enc_passphrase);
994 reply = netconfig_invoke_dbus_method(CONNMAN_SERVICE, service_path,
995 CONNMAN_SERVICE_INTERFACE, "SetProperty",
996 g_variant_new("(sv)", "Passphrase",
997 g_variant_new_string(enc_passphrase)));
999 g_variant_unref(reply);
1001 ERR("Failed to set passphrase");
1003 g_free(service_path);
1008 static void _supplicant_wifi_wps_credentials(GVariant *param)
1011 char ssid[32] = {0, };
1012 char wps_key[100] = {0, };
1015 int config_error = 0;
1016 int error_indication = 0;
1018 char *key_mgmt = NULL;
1020 if (param == NULL) {
1021 ERR("Param is NULL");
1025 g_variant_get(param, "(a{sv})", &iter);
1026 while (g_variant_iter_loop(iter, "{sv}", &key, &variant)) {
1029 INFO("wps Key is %s", key);
1030 if (g_strcmp0(key, "Key") == 0) {
1032 const char *t_key = NULL;
1033 key_len = g_variant_get_size(variant);
1035 INFO("wps password len %d ", key_len);
1037 t_key = g_variant_get_fixed_array(variant, &key_len,
1041 g_variant_unref(variant);
1044 strncpy(wps_key, t_key, key_len);
1045 wps_key[key_len] = '\0';
1046 INFO("WPS Key in process credentials %s", wps_key);
1048 SLOGI("WPS AP Security ->Open");
1049 } else if (g_strcmp0(key, "SSID") == 0) {
1050 const char *t_key = NULL;
1051 t_key = g_variant_get_fixed_array(variant, &ssid_len,
1053 INFO("wps ssid_len is %d ", ssid_len);
1056 g_variant_unref(variant);
1059 if (ssid_len > 0 && ssid_len <= 32) {
1060 memcpy(ssid, t_key, ssid_len);
1062 memset(ssid, 0, sizeof(ssid));
1065 INFO("SSID in process credentials %s", ssid);
1066 } else if (g_strcmp0(key, "AuthType") == 0) {
1068 GVariantIter *var_iter;
1069 g_variant_get(variant, "as", &var_iter);
1070 while (g_variant_iter_loop(var_iter, "s", &auth_type)) {
1071 INFO("wps auth_type %s", auth_type);
1072 if (g_strcmp0(auth_type, "wpa-psk") == 0 ||
1073 g_strcmp0(auth_type, "wpa2-psk") == 0)
1075 else if (g_strcmp0(auth_type, "open") == 0)
1078 g_variant_iter_free(var_iter);
1079 } else if (g_strcmp0(key, "EncrType") == 0) {
1081 GVariantIter *var_iter;
1082 g_variant_get(variant, "as", &var_iter);
1083 while (g_variant_iter_loop(var_iter, "s", &encr_type))
1084 INFO("wps encr_type %s", encr_type);
1085 g_variant_iter_free(var_iter);
1086 } else if (g_strcmp0(key, "BSSID") == 0) {
1087 const guchar *bssid;
1089 bssid = g_variant_get_fixed_array(variant, &bssid_len,
1091 if (bssid && bssid_len == 6)
1092 INFO("wps BSSID %2x:%2x:%2x:%2x:%2x:%2x", bssid[0], bssid[1],
1093 bssid[2], bssid[3], bssid[4], bssid[5]);
1097 g_variant_iter_free(iter);
1099 if (g_strcmp0(key_mgmt, "psk") == 0)
1100 _find_service_and_set_passphrase(ssid, wps_key);
1104 * Notify WPS Credentials only when requested through WPS PBC
1105 * In case of WPS PIN connman will take care of notification
1107 if (netconfig_get_wps_field() == TRUE)
1109 netconfig_wifi_notify_wps_credentials(ssid, ssid_len, wps_key);
1113 g_variant_iter_free(iter);
1114 error_indication = WPS_EI_OPERATION_FAILED;
1115 config_error = WPS_CFG_NO_ERROR;
1116 ERR("Error Occured! Notifying Fail Event");
1117 netconfig_wifi_notify_wps_fail_event(config_error, error_indication);
1120 static void __netconfig_wps_signal_filter_handler(GDBusConnection *conn,
1121 const gchar *name, const gchar *path, const gchar *interface,
1122 const gchar *sig, GVariant *param, gpointer user_data)
1124 if (g_strcmp0(sig, SIGNAL_WPS_CREDENTIALS) == 0) {
1125 INFO("Received wps CREDENTIALS Signal from Supplicant");
1126 _supplicant_wifi_wps_credentials(param);
1127 } else if (g_strcmp0(sig, SIGNAL_WPS_EVENT) == 0) {
1128 INFO("Received wps EVENT Signal from Supplicant");
1129 _supplicant_wifi_wps_event(param);
1130 } else if (g_strcmp0(sig, SIGNAL_WPS_CONNECTED) == 0) {
1131 INFO("Received WPSConnected Signal from Supplicant");
1132 _supplicant_wifi_wps_connected(param);
1138 static supplicant_signal_cb supplicant_cbs[SIG_MAX] = {
1139 _supplicant_interface_removed,
1140 _supplicant_properties_changed,
1141 _supplicant_bss_added,
1142 _supplicant_scan_done,
1143 _supplicant_driver_hanged,
1144 _supplicant_session_overlapped,
1145 _supplicant_tdls_connected,
1146 _supplicant_tdls_disconnected,
1147 _supplicant_tdls_peer_found
1150 void register_gdbus_signal(void)
1152 GDBusConnection *connection = NULL;
1153 const char *interface = NULL;
1154 SuppSigArrayIndex sig;
1155 connection = netdbus_get_connection();
1157 if (connection == NULL) {
1158 ERR("Failed to get GDbus Connection");
1162 /* listening to messages from all objects as no path is specified */
1163 /* see signals from the given interface */
1164 conn_subscription_ids[0] = g_dbus_connection_signal_subscribe(
1167 CONNMAN_TECHNOLOGY_INTERFACE,
1171 G_DBUS_SIGNAL_FLAGS_NONE,
1172 _technology_signal_cb,
1176 conn_subscription_ids[1] = g_dbus_connection_signal_subscribe(
1179 CONNMAN_SERVICE_INTERFACE,
1180 CONNMAN_SIGNAL_PROPERTY_CHANGED,
1183 G_DBUS_SIGNAL_FLAGS_NONE,
1188 conn_subscription_ids[2] = g_dbus_connection_signal_subscribe(
1191 DBUS_INTERFACE_DBUS,
1192 CONNMAN_SIGNAL_NAME_CHANGED,
1195 G_DBUS_SIGNAL_FLAGS_NONE,
1196 _dbus_name_changed_cb,
1200 conn_subscription_ids[3] = g_dbus_connection_signal_subscribe(
1203 CONNMAN_MANAGER_INTERFACE,
1204 CONNMAN_SIGNAL_SERVICES_CHANGED,
1207 G_DBUS_SIGNAL_FLAGS_NONE,
1208 _services_changed_cb,
1212 INFO("Successfully register connman DBus signal filters");
1214 conn_subscription_ids[4] = g_dbus_connection_signal_subscribe(
1217 SUPPLICANT_INTERFACE ".Interface.WPS",
1221 G_DBUS_SIGNAL_FLAGS_NONE,
1222 __netconfig_wps_signal_filter_handler,
1226 INFO("Successfully register Supplicant WPS DBus signal filters");
1228 for (sig = SIG_INTERFACE_REMOVED; sig < SIG_MAX; sig++) {
1230 * For SIG_INTERFACE_REMOVED INTERFACE_ADDED
1232 interface = (sig == SIG_INTERFACE_REMOVED) ?
1233 SUPPLICANT_INTERFACE : SUPPLICANT_IFACE_INTERFACE;
1235 supp_subscription_ids[sig] = g_dbus_connection_signal_subscribe(
1239 supplicant_signals[sig],
1242 G_DBUS_SIGNAL_FLAGS_NONE,
1243 supplicant_cbs[sig],
1248 INFO("Successfully register Supplicant DBus signal filters");
1250 #if defined TIZEN_DEBUG_ENABLE
1251 dumpservice_subscription_id = g_dbus_connection_signal_subscribe(
1254 DUMP_SERVICE_INTERFACE,
1258 G_DBUS_SIGNAL_FLAGS_NONE,
1259 __netconfig_dumpservice_handler,
1263 INFO("Successfully registered Dumpservice DBus signal filter");
1266 /* In case ConnMan precedes this signal register,
1267 * net-config should update the default connected profile.
1269 netconfig_update_default();
1272 void deregister_gdbus_signal(void)
1274 GDBusConnection *connection = NULL;
1276 SuppSigArrayIndex sig;
1277 connection = netdbus_get_connection();
1279 ERR("Already de-registered. Nothing to be done");
1283 for (signal = 0; signal < TOTAL_CONN_SIGNALS; signal++) {
1284 if (conn_subscription_ids[signal]) {
1285 g_dbus_connection_signal_unsubscribe(connection,
1286 conn_subscription_ids[signal]);
1290 for (sig = SIG_INTERFACE_REMOVED; sig < SIG_MAX; sig++) {
1291 if (supp_subscription_ids[sig]) {
1292 g_dbus_connection_signal_unsubscribe(connection,
1293 supp_subscription_ids[sig]);
1297 #if defined TIZEN_DEBUG_ENABLE
1298 g_dbus_connection_signal_unsubscribe(connection,
1299 dumpservice_subscription_id);