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"
43 #include "ip-conflict-detect.h"
44 #include "wifi-key-encryption.h"
45 #include "clatd-handler.h"
46 #if defined TIZEN_DEBUG_ENABLE
47 #include "network-dump.h"
48 #define NETWORK_LOG_DUMP_SCRIPT "/opt/var/lib/net-config/network_log_dump.sh"
49 #define MAX_SIZE_ERROR_BUFFER 256
52 #define DBUS_SERVICE_DBUS "org.freedesktop.DBus"
53 #define DBUS_INTERFACE_DBUS "org.freedesktop.DBus"
54 #define SIGNAL_INTERFACE_REMOVED "InterfaceRemoved"
55 #define SIGNAL_SCAN_DONE "ScanDone"
56 #define SIGNAL_BSS_ADDED "BSSAdded"
57 #define SIGNAL_PROPERTIES_CHANGED "PropertiesChanged"
58 #define SIGNAL_PROPERTIES_DRIVER_HANGED "DriverHanged"
59 #define SIGNAL_PROPERTIES_SESSION_OVERLAPPED "SessionOverlapped"
60 #define SIGNAL_TDLS_CONNECTED "TDLSConnected"
61 #define SIGNAL_TDLS_DISCONNECTED "TDLSDisconnected"
62 #define SIGNAL_TDLS_PEER_FOUND "TDLSPeerFound"
64 #define SIGNAL_DPP_AUTH_SUCCESS "DPPAuthSuccess"
65 #define SIGNAL_DPP_AUTH_FAILED "DPPAuthFailed"
66 #define SIGNAL_DPP_NOT_COMPATIBLE "DPPNotCompatible"
67 #define SIGNAL_DPP_CONF_FAILED "DPPConfFailed"
68 #define SIGNAL_DPP_SCAN_PEER_QR "DPPScanPeerQrCode"
69 #define SIGNAL_DPP_NETWORK_ID "DPPNetworkID"
70 #define SIGNAL_DPP_CONF_SENT "DPPConfSent"
71 #define SIGNAL_DPP_CONF_RECEIVED "DPPConfReceived"
72 #define SIGNAL_DPP_CONF_OBJ "DPPConfObj"
74 #define SIGNAL_WPS_CONNECTED "WPSConnected"
75 #define SIGNAL_WPS_EVENT "Event"
76 #define SIGNAL_WPS_CREDENTIALS "Credentials"
78 #define CONNMAN_SIGNAL_SERVICES_CHANGED "ServicesChanged"
79 #define CONNMAN_SIGNAL_PROPERTY_CHANGED "PropertyChanged"
80 #define SIGNAL_NAME_OWNER_CHANGED "NameOwnerChanged"
82 #define MAX_SIG_LEN 64
83 #define TOTAL_CONN_SIGNALS 6
84 #define MAX_SOCKET_OPEN_RETRY 5
87 SIG_INTERFACE_REMOVED = 0,
88 SIG_PROPERTIES_CHANGED,
92 SIG_SESSION_OVERLAPPED,
94 SIG_TDLS_DISCONNECTED,
98 SIG_DPP_NOT_COMPATIBLE,
100 SIG_DPP_SCAN_PEER_QR,
103 SIG_DPP_CONF_RECEIVED,
108 static int conn_subscription_ids[TOTAL_CONN_SIGNALS] = {0};
109 static const char supplicant_signals[SIG_MAX][MAX_SIG_LEN] = {
110 SIGNAL_INTERFACE_REMOVED,
111 SIGNAL_PROPERTIES_CHANGED,
114 SIGNAL_PROPERTIES_DRIVER_HANGED,
115 SIGNAL_PROPERTIES_SESSION_OVERLAPPED,
116 SIGNAL_TDLS_CONNECTED,
117 SIGNAL_TDLS_DISCONNECTED,
118 SIGNAL_TDLS_PEER_FOUND,
119 SIGNAL_DPP_AUTH_SUCCESS,
120 SIGNAL_DPP_AUTH_FAILED,
121 SIGNAL_DPP_NOT_COMPATIBLE,
122 SIGNAL_DPP_CONF_FAILED,
123 SIGNAL_DPP_SCAN_PEER_QR,
124 SIGNAL_DPP_NETWORK_ID,
125 SIGNAL_DPP_CONF_SENT,
126 SIGNAL_DPP_CONF_RECEIVED,
129 static const char *supplicant_iface_for_sig[SIG_MAX] = {
130 SUPPLICANT_INTERFACE,
131 SUPPLICANT_IFACE_INTERFACE,
132 SUPPLICANT_IFACE_INTERFACE,
133 SUPPLICANT_IFACE_INTERFACE,
134 SUPPLICANT_IFACE_INTERFACE,
135 SUPPLICANT_IFACE_INTERFACE,
136 SUPPLICANT_IFACE_INTERFACE,
137 SUPPLICANT_IFACE_INTERFACE,
138 SUPPLICANT_IFACE_INTERFACE,
139 SUPPLICANT_IFACE_DPP,
140 SUPPLICANT_IFACE_DPP,
141 SUPPLICANT_IFACE_DPP,
142 SUPPLICANT_IFACE_DPP,
143 SUPPLICANT_IFACE_DPP,
144 SUPPLICANT_IFACE_DPP,
145 SUPPLICANT_IFACE_DPP,
146 SUPPLICANT_IFACE_DPP,
147 SUPPLICANT_IFACE_DPP,
150 static int supp_subscription_ids[SIG_MAX] = {0};
151 #if defined TIZEN_DEBUG_ENABLE
152 static int dumpservice_subscription_id = 0;
155 typedef void (*supplicant_signal_cb)(GDBusConnection *conn,
156 const gchar *name, const gchar *path, const gchar *interface,
157 const gchar *sig, GVariant *param, gpointer user_data);
158 typedef void (*connman_signal_cb)(GDBusConnection *conn,
159 const gchar *name, const gchar *path, const gchar *interface,
160 const gchar *sig, GVariant *param, gpointer user_data);
162 static void __netconfig_extract_ipv4_signal_data(GVariant *dictionary,
163 const gchar *profile)
166 const gchar *value = NULL;
167 GVariant *var = NULL;
169 GVariantBuilder *builder;
172 g_variant_iter_init(&iter, dictionary);
173 while (g_variant_iter_loop(&iter, "{sv}", &key, &var)) {
174 if (g_strcmp0(key, "Address") == 0) {
175 g_variant_get(var, "&s", &value);
176 char *old_ip = vconf_get_str(VCONFKEY_NETWORK_IP);
178 DBG("Old IPv4.Address [%s] Received new IPv4.Address [%s]", old_ip,
180 if (g_strcmp0(old_ip, value) != 0) {
181 builder = g_variant_builder_new(G_VARIANT_TYPE("a{sv}"));
184 vconf_set_str(VCONFKEY_NETWORK_IP, value);
185 g_variant_builder_add(builder, "{sv}", "IPv4Address",
186 g_variant_new_string(value));
187 } else if (old_ip != NULL && strlen(old_ip) > 0) {
188 vconf_set_str(VCONFKEY_NETWORK_IP, "");
189 g_variant_builder_add(builder, "{sv}", "IPv4Address",
190 g_variant_new_string(""));
193 params = g_variant_new("(@a{sv})",
194 g_variant_builder_end(builder));
196 g_variant_builder_unref(builder);
198 netconfig_dbus_emit_signal(NULL, NETCONFIG_NETWORK_PATH,
199 NETCONFIG_NETWORK_INTERFACE, "NetworkConfigChanged",
207 static void __netconfig_extract_ipv6_signal_data(GVariant *dictionary,
208 const gchar *profile)
211 const gchar *value = NULL;
212 GVariant *var = NULL;
214 GVariantBuilder *builder;
217 g_variant_iter_init(&iter, dictionary);
218 while (g_variant_iter_loop(&iter, "{sv}", &key, &var)) {
219 if (g_strcmp0(key, "Address") == 0) {
220 g_variant_get(var, "&s", &value);
221 char *old_ip6 = vconf_get_str(VCONFKEY_NETWORK_IP6);
223 DBG("Old IPv6.Address [%s] Received new IPv6.Address [%s]", old_ip6,
225 if (g_strcmp0(old_ip6, value) != 0) {
226 builder = g_variant_builder_new(G_VARIANT_TYPE("a{sv}"));
229 vconf_set_str(VCONFKEY_NETWORK_IP6, value);
230 g_variant_builder_add(builder, "{sv}", "IPv6Address",
231 g_variant_new_string(value));
232 } else if (old_ip6 != NULL && strlen(old_ip6) > 0) {
233 vconf_set_str(VCONFKEY_NETWORK_IP6, "");
234 g_variant_builder_add(builder, "{sv}", "IPv6Address",
235 g_variant_new_string(""));
238 params = g_variant_new("(@a{sv})",
239 g_variant_builder_end(builder));
240 g_variant_builder_unref(builder);
242 netconfig_dbus_emit_signal(NULL, NETCONFIG_NETWORK_PATH,
243 NETCONFIG_NETWORK_INTERFACE, "NetworkConfigChanged",
251 #if defined TIZEN_DEBUG_ENABLE
252 static int __netconfig_handle_execute_file(const char *file_path,
253 char *const args[], char *const envs[])
259 register unsigned int index = 0;
260 char error_buf[MAX_SIZE_ERROR_BUFFER] = {0, };
262 while (args[index] != NULL) {
263 DBG("%s", args[index]);
267 if (!(pid = fork())) {
268 DBG("pid(%d), ppid (%d)", getpid(), getppid());
269 DBG("Inside child, exec (%s) command", file_path);
272 if (execve(file_path, args, envs) == -1) {
273 DBG("Fail to execute command (%s)",
274 strerror_r(errno, error_buf, MAX_SIZE_ERROR_BUFFER));
277 } else if (pid > 0) {
278 if (waitpid(pid, &status, 0) == -1)
279 DBG("wait pid (%u) status (%d)", pid, status);
281 if (WIFEXITED(status)) {
282 rv = WEXITSTATUS(status);
283 DBG("exited, status=%d", rv);
284 } else if (WIFSIGNALED(status)) {
285 DBG("killed by signal %d", WTERMSIG(status));
286 } else if (WIFSTOPPED(status)) {
287 DBG("stopped by signal %d", WSTOPSIG(status));
288 } else if (WIFCONTINUED(status)) {
295 DBG("failed to fork(%s)",
296 strerror_r(errno, error_buf, MAX_SIZE_ERROR_BUFFER));
300 static int _start_dump()
303 gchar *path = NETWORK_LOG_DUMP_SCRIPT;
304 char *const args[] = { NETWORK_LOG_DUMP_SCRIPT, NULL };
305 char *const envs[] = { NULL };
307 rv = __netconfig_handle_execute_file(path, args, envs);
309 ERR("Fail to execute network log dump shell");
316 static void _technology_signal_cb(GDBusConnection *conn,
317 const gchar *name, const gchar *path, const gchar *interface,
318 const gchar *sig, GVariant *param, gpointer user_data)
321 gboolean value = FALSE;
322 GVariant *var = NULL;
327 if (g_str_has_prefix(path, CONNMAN_WIFI_TECHNOLOGY_PREFIX) == TRUE) {
328 g_variant_get(param, "(sv)", &key, &var);
329 if (g_strcmp0(key, "Powered") == 0) {
331 value = g_variant_get_boolean(var);
333 wifi_state_update_power_state(TRUE);
335 wifi_state_update_power_state(FALSE);
336 } else if (g_strcmp0(key, "Connected") == 0) {
337 /* Connection state */
338 value = g_variant_get_boolean(var);
340 wifi_state_set_tech_state(NETCONFIG_WIFI_TECH_CONNECTED);
342 wifi_state_set_tech_state(NETCONFIG_WIFI_TECH_POWERED);
343 } else if (g_strcmp0(key, "Tethering") == 0) {
344 /* Tethering state */
345 wifi_state_set_tech_state(NETCONFIG_WIFI_TECH_TETHERED);
348 g_variant_unref(var);
352 static void _service_signal_cb(GDBusConnection *conn,
353 const gchar *name, const gchar *path,
354 const gchar *interface, const gchar *sig,
355 GVariant *param, gpointer user_data)
357 gchar *sigvalue = NULL;
359 GVariant *variant = NULL, *var;
361 const gchar *value = NULL;
362 struct sock_data *sd = NULL;
366 if (path == NULL || param == NULL)
369 g_variant_get(param, "(sv)", &sigvalue, &variant);
370 if (sigvalue == NULL)
373 if (g_strcmp0(sig, CONNMAN_SIGNAL_PROPERTY_CHANGED) != 0)
376 if (g_strcmp0(sigvalue, "State") == 0) {
377 g_variant_get(variant, "s", &property);
379 DBG("[%s] %s", property, path);
381 if (netconfig_is_wifi_profile(path) == TRUE) {
384 netconfig_vconf_get_int(VCONFKEY_WIFI_STATE, &wifi_state);
385 if (wifi_state == VCONFKEY_WIFI_OFF) {
390 if (g_strcmp0(property, "ready") == 0 || g_strcmp0(property, "online") == 0) {
391 if (wifi_state >= VCONFKEY_WIFI_CONNECTED) {
396 netconfig_update_default_profile(path);
398 wifi_state_set_service_state(NETCONFIG_WIFI_CONNECTED);
400 } else if (g_strcmp0(property, "failure") == 0 || g_strcmp0(property, "disconnect") == 0 || g_strcmp0(property, "idle") == 0) {
401 if (netconfig_get_default_profile() == NULL ||
402 netconfig_is_wifi_profile(netconfig_get_default_profile())
404 if (g_strcmp0(property, "failure") == 0)
405 wifi_state_set_service_state(NETCONFIG_WIFI_FAILURE);
407 wifi_state_set_service_state(NETCONFIG_WIFI_IDLE);
412 if (g_strcmp0(path, netconfig_get_default_profile()) != 0) {
417 netconfig_update_default_profile(NULL);
419 if (g_strcmp0(property, "failure") == 0)
420 wifi_state_set_service_state(NETCONFIG_WIFI_FAILURE);
422 wifi_state_set_service_state(NETCONFIG_WIFI_IDLE);
424 } else if (g_strcmp0(property, "association") == 0 || g_strcmp0(property, "configuration") == 0) {
425 if (netconfig_get_default_profile() == NULL ||
426 netconfig_is_wifi_profile(netconfig_get_default_profile()) != TRUE) {
427 if (g_strcmp0(property, "association") == 0)
428 wifi_state_set_service_state(NETCONFIG_WIFI_ASSOCIATION);
430 wifi_state_set_service_state(NETCONFIG_WIFI_CONFIGURATION);
435 if (g_strcmp0(path, netconfig_get_default_profile()) != 0) {
440 netconfig_update_default_profile(NULL);
442 if (g_strcmp0(property, "association") == 0)
443 wifi_state_set_service_state(NETCONFIG_WIFI_ASSOCIATION);
445 wifi_state_set_service_state(NETCONFIG_WIFI_CONFIGURATION);
449 if (g_strcmp0(property, "ready") == 0 || g_strcmp0(property, "online") == 0) {
450 if (netconfig_get_default_profile() == NULL) {
451 if (!netconfig_is_cellular_profile(path))
452 netconfig_update_default_profile(path);
454 if (netconfig_is_cellular_internet_profile(path))
455 netconfig_update_default_profile(path);
458 pf = netconfig_get_connected_cellular_internet_ipv6only_profile(NULL);
463 /* Enable clatd if it is not in running state */
464 DBG("Connected to ipv6 only cellular, enable clatd");
465 netconfig_clatd_enable();
469 if (netconfig_is_cellular_profile(path) && netconfig_is_cellular_internet_profile(path))
470 cellular_state_set_service_state(NETCONFIG_CELLULAR_ONLINE);
472 } else if (g_strcmp0(property, "failure") == 0 || g_strcmp0(property, "disconnect") == 0 || g_strcmp0(property, "idle") == 0) {
473 if (netconfig_get_default_profile() == NULL) {
478 if (netconfig_is_cellular_profile(path) && netconfig_is_cellular_internet_profile(path)) {
479 cellular_state_set_service_state(NETCONFIG_CELLULAR_IDLE);
481 /* Disable clatd if it is in running state */
482 DBG("disable clatd");
483 netconfig_clatd_disable();
486 if (g_strcmp0(path, netconfig_get_default_profile()) != 0) {
491 netconfig_update_default_profile(NULL);
492 } else if (g_strcmp0(property, "association") == 0 || g_strcmp0(property, "configuration") == 0) {
493 if (netconfig_get_default_profile() == NULL) {
498 if (netconfig_is_cellular_profile(path) && netconfig_is_cellular_internet_profile(path))
499 cellular_state_set_service_state(NETCONFIG_CELLULAR_CONNECTING);
501 if (g_strcmp0(path, netconfig_get_default_profile()) != 0) {
506 netconfig_update_default_profile(NULL);
510 if (netconfig_is_wifi_profile(path) || netconfig_is_ethernet_profile(path)) {
511 if (g_strcmp0(property, "ready") == 0) {
512 for (idx = 0; idx < MAX_SOCKET_OPEN_RETRY; idx++) {
513 sd = start_ip_conflict_mon();
517 } else if (g_strcmp0(property, "online") == 0) {
520 stop_ip_conflict_mon();
525 } else if (g_strcmp0(sigvalue, "Proxy") == 0) {
526 if (netconfig_is_wifi_profile(path) != TRUE || g_strcmp0(path, netconfig_get_default_profile()) != 0)
529 if (!g_variant_is_of_type(variant, G_VARIANT_TYPE_ARRAY))
532 g_variant_get(variant, "a{sv}", &iter);
533 while (g_variant_iter_loop(iter, "{sv}", &property, &var)) {
534 GVariantBuilder *builder;
535 GVariant *sig_params;
536 if (g_strcmp0(property, "Servers") == 0) {
537 GVariantIter *iter_sub = NULL;
539 builder = g_variant_builder_new(G_VARIANT_TYPE("a{sv}"));
541 g_variant_get(var, "as", &iter_sub);
542 g_variant_iter_loop(iter_sub, "s", &value);
543 g_variant_iter_free(iter_sub);
545 DBG("Proxy - [%s]", value);
546 vconf_set_str(VCONFKEY_NETWORK_PROXY, value);
548 g_variant_builder_add(builder, "{sv}", "ProxyAddress",
549 g_variant_new_string(value));
551 sig_params = g_variant_new("(@a{sv})",
552 g_variant_builder_end(builder));
553 g_variant_builder_unref(builder);
555 netconfig_dbus_emit_signal(NULL, NETCONFIG_NETWORK_PATH,
556 NETCONFIG_NETWORK_INTERFACE, "NetworkConfigChanged",
560 g_variant_unref(var);
562 } else if (g_strcmp0(property, "Method") == 0) {
563 value = g_variant_get_string(var, NULL);
564 DBG("Method - [%s]", value);
566 if (g_strcmp0(value, "direct") == 0) {
567 builder = g_variant_builder_new(G_VARIANT_TYPE("a{sv}"));
569 vconf_set_str(VCONFKEY_NETWORK_PROXY, "");
570 g_variant_builder_add(builder, "{sv}", "ProxyAddress",
571 g_variant_new_string(""));
573 sig_params = g_variant_new("(@a{sv})",
574 g_variant_builder_end(builder));
575 g_variant_builder_unref(builder);
577 netconfig_dbus_emit_signal(NULL, NETCONFIG_NETWORK_PATH,
578 NETCONFIG_NETWORK_INTERFACE,
579 "NetworkConfigChanged", sig_params);
583 g_variant_unref(var);
588 g_variant_iter_free(iter);
589 } else if (g_strcmp0(sigvalue, "IPv4") == 0) {
590 __netconfig_extract_ipv4_signal_data(variant, path);
591 } else if (g_strcmp0(sigvalue, "IPv6") == 0) {
592 __netconfig_extract_ipv6_signal_data(variant, path);
593 } else if (g_strcmp0(sigvalue, "Error") == 0) {
594 g_variant_get(variant, "s", &property);
595 INFO("[%s] Property : %s", sigvalue, property);
596 #if defined TIZEN_DEBUG_ENABLE
597 if (g_strcmp0(property, "dhcp-failed") == 0
598 || g_strcmp0(property, "connect-failed") == 0
599 || g_strcmp0(property, "login-failed") == 0
600 || g_strcmp0(property, "auth-failed") == 0
601 || g_strcmp0(property, "invalid-key") == 0) {
613 g_variant_unref(variant);
618 static void _dbus_name_changed_cb(GDBusConnection *conn,
619 const gchar *Name, const gchar *path, const gchar *interface,
620 const gchar *sig, GVariant *param, gpointer user_data)
629 g_variant_get(param, "(sss)", &name, &old, &new);
631 if (g_strcmp0(name, CONNMAN_SERVICE) == 0 && *new == '\0') {
632 DBG("ConnMan destroyed: name %s, old %s, new %s", name, old, new);
634 connman_register_agent();
635 } else if (g_strcmp0(name, CLATD_SERVICE) == 0 && *new == '\0') {
636 DBG("Clat destroyed: name %s, old %s, new %s", name, old, new);
638 /* If clatd is terminated unexpectedly, reset and enable clat service. */
639 if (NETCONFIG_CELLULAR_ONLINE == cellular_state_get_service_state())
640 netconfig_clatd_reset();
649 static void _services_changed_cb(GDBusConnection *conn, const gchar *name,
650 const gchar *path, const gchar *interface, const gchar *sig,
651 GVariant *param, gpointer user_data)
653 gchar *property, *value;
655 GVariant *variant = NULL;
656 GVariantIter *added = NULL, *removed = NULL, *next = NULL;
658 if (path == NULL || param == NULL)
661 if (g_strcmp0(sig, CONNMAN_SIGNAL_SERVICES_CHANGED) != 0)
664 if (netconfig_get_default_profile() != NULL)
667 g_variant_get(param, "(a(oa{sv})ao)", &added, &removed);
669 while (g_variant_iter_loop(added, "(oa{sv})", &service_path, &next)) {
670 gboolean is_wifi_prof, is_cell_prof, is_cell_internet_prof;
671 is_wifi_prof = netconfig_is_wifi_profile(service_path);
672 is_cell_prof = netconfig_is_cellular_profile(service_path);
673 is_cell_internet_prof = netconfig_is_cellular_internet_profile(
675 if (service_path != NULL) {
676 while (next && g_variant_iter_loop(next, "{sv}", &property,
678 if (g_strcmp0(property, "State") == 0) {
679 g_variant_get(variant, "s", &value);
680 DBG("Profile %s State %s", service_path,
682 if (g_strcmp0(value, "ready") != 0 &&
687 g_variant_unref(variant);
692 netconfig_update_default_profile(
694 else if (is_cell_internet_prof) {
695 netconfig_update_default_profile(
699 wifi_state_set_service_state(
700 NETCONFIG_WIFI_CONNECTED);
701 else if (is_cell_prof &&
702 is_cell_internet_prof)
703 cellular_state_set_service_state(
704 NETCONFIG_CELLULAR_ONLINE);
707 g_variant_unref(variant);
714 g_variant_iter_free(added);
717 g_variant_iter_free(next);
720 g_variant_iter_free(removed);
725 static void _supplicant_interface_removed(GDBusConnection *conn,
726 const gchar *name, const gchar *path, const gchar *interface,
727 const gchar *sig, GVariant *param, gpointer user_data)
729 DBG("Interface removed handling!");
730 if (netconfig_wifi_is_bssid_scan_started() == TRUE)
731 netconfig_wifi_bssid_signal_scanaborted();
736 static void _supplicant_properties_changed(GDBusConnection *conn,
737 const gchar *name, const gchar *path, const gchar *interface,
738 const gchar *sig, GVariant *param, gpointer user_data)
740 DBG("Properties changed handling!");
742 const gchar *state = NULL;
743 GVariantIter *iter = NULL;
744 GVariant *variant = NULL;
745 gboolean scanning = FALSE;
750 g_variant_get(param, "(a{sv})", &iter);
751 while (g_variant_iter_loop(iter, "{sv}", &key, &variant)) {
752 if (g_strcmp0(key, "Scanning") == 0) {
753 scanning = g_variant_get_boolean(variant);
754 DBG("setting scanning %s", scanning ? "TRUE" : "FALSE");
755 if (scanning == TRUE)
756 netconfig_wifi_set_scanning(TRUE);
758 netconfig_wifi_set_scanning(FALSE);
760 g_variant_unref(variant);
765 } else if (g_strcmp0(key, "State") == 0) {
766 state = g_variant_get_string(variant, NULL);
768 ERR("Supplicant state : %s", state);
770 g_variant_unref(variant);
775 } else if (g_strcmp0(key, "DisconnectReason") == 0) {
776 int reason = g_variant_get_int32(variant);
777 ERR("Supplicant DisconnReason : %d", reason);
779 g_variant_unref(variant);
786 value = g_variant_print(variant, TRUE);
787 DBG("Supplicant %s : %s", key, value);
793 g_variant_iter_free(iter);
798 static void _supplicant_bss_added(GDBusConnection *conn,
799 const gchar *name, const gchar *path, const gchar *interface,
800 const gchar *sig, GVariant *param, gpointer user_data)
802 DBG("BSS added handling!");
803 wifi_state_set_bss_found(TRUE);
808 static void _supplicant_scan_done(GDBusConnection *conn,
809 const gchar *name, const gchar *path, const gchar *interface,
810 const gchar *sig, GVariant *param, gpointer user_data)
812 DBG("Scan Done handling!");
813 netconfig_wifi_set_scanning(FALSE);
815 if (netconfig_wifi_is_bssid_scan_started() == TRUE) {
816 netconfig_wifi_bssid_signal_scandone();
817 if (wifi_state_get_technology_state() < NETCONFIG_WIFI_TECH_POWERED)
821 if (netconfig_wifi_get_bgscan_state() == TRUE) {
822 if (wifi_state_get_technology_state() >=
823 NETCONFIG_WIFI_TECH_POWERED)
824 netconfig_wifi_bgscan_start(FALSE);
826 wifi_start_timer_network_notification();
832 static void _supplicant_driver_hanged(GDBusConnection *conn,
833 const gchar *name, const gchar *path, const gchar *interface,
834 const gchar *sig, GVariant *param, gpointer user_data)
836 DBG("Driver Hanged handling!");
837 ERR("Critical. Wi-Fi firmware crashed");
839 #if !defined TIZEN_WEARABLE
840 netconfig_send_message_to_net_popup("Wi-Fi Error",
841 "Wi-Fi Driver Hanged. Please get log dump and report", "popup", NULL);
843 wifi_power_recover_firmware();
849 static void _supplicant_session_overlapped(GDBusConnection *conn,
850 const gchar *name, const gchar *path, const gchar *interface,
851 const gchar *sig, GVariant *param, gpointer user_data)
853 DBG("Driver session overlapped handling!");
854 ERR("WPS PBC SESSION OVERLAPPED");
855 #if defined TIZEN_WEARABLE
858 netconfig_send_message_to_net_popup("WPS Error",
859 "wps session overlapped", "popup", NULL);
863 #if defined TIZEN_DEBUG_ENABLE
864 static void __netconfig_dumpservice_handler(GDBusConnection *conn,
865 const gchar *name, const gchar *path, const gchar *interface,
866 const gchar *sig, GVariant *param, gpointer user_data)
869 gchar *signal_path = NULL;
874 g_variant_get(param, "(is)", &mode, &signal_path);
875 DBG("Path: %s and mode: %d", signal_path, mode);
877 netconfig_dump_log(signal_path);
885 static void _supplicant_tdls_connected(GDBusConnection *conn,
886 const gchar *name, const gchar *path, const gchar *interface,
887 const gchar *sig, GVariant *param, gpointer user_data)
889 DBG("Received TDLS Connected Signal");
890 netconfig_wifi_tdls_connected_event(param);
895 static void _supplicant_tdls_disconnected(GDBusConnection *conn,
896 const gchar *name, const gchar *path, const gchar *interface,
897 const gchar *sig, GVariant *param, gpointer user_data)
899 DBG("Received TDLS Disconnected Signal");
900 netconfig_wifi_tdls_disconnected_event(param);
905 static void _supplicant_tdls_peer_found(GDBusConnection *conn,
906 const gchar *name, const gchar *path, const gchar *interface,
907 const gchar *sig, GVariant *param, gpointer user_data)
909 DBG("Received TDLS Peer Found Signal");
910 netconfig_wifi_tdls_peer_found_event(param);
914 static void _supplicant_dpp_auth_success(GDBusConnection *conn,
915 const gchar *name, const gchar *path, const gchar *interface,
916 const gchar *sig, GVariant *param, gpointer user_data)
918 DBG("Received DPP Auth Success Signal");
919 netconfig_wifi_dpp_auth_success_event(param);
923 static void _supplicant_dpp_auth_failed(GDBusConnection *conn,
924 const gchar *name, const gchar *path, const gchar *interface,
925 const gchar *sig, GVariant *param, gpointer user_data)
927 DBG("Received DPP Auth Failed Signal");
928 netconfig_wifi_dpp_auth_failed_event(param);
932 static void _supplicant_dpp_not_compatible(GDBusConnection *conn,
933 const gchar *name, const gchar *path, const gchar *interface,
934 const gchar *sig, GVariant *param, gpointer user_data)
936 DBG("Received DPP Not Compatible Signal");
937 netconfig_wifi_dpp_not_compatible_event(param);
941 static void _supplicant_dpp_conf_failed(GDBusConnection *conn,
942 const gchar *name, const gchar *path, const gchar *interface,
943 const gchar *sig, GVariant *param, gpointer user_data)
945 DBG("Received DPP Conf Failed Signal");
946 netconfig_wifi_dpp_conf_failed_event(param);
950 static void _supplicant_dpp_scan_peer_qr(GDBusConnection *conn,
951 const gchar *name, const gchar *path, const gchar *interface,
952 const gchar *sig, GVariant *param, gpointer user_data)
954 DBG("Received DPP Scan Peer QR Signal");
955 netconfig_wifi_dpp_scan_peer_qr_event(param);
959 static void _supplicant_dpp_network_id(GDBusConnection *conn,
960 const gchar *name, const gchar *path, const gchar *interface,
961 const gchar *sig, GVariant *param, gpointer user_data)
963 DBG("Received DPP Network Id Signal");
964 netconfig_wifi_dpp_network_id_event(param);
968 static void _supplicant_dpp_conf_sent(GDBusConnection *conn,
969 const gchar *name, const gchar *path, const gchar *interface,
970 const gchar *sig, GVariant *param, gpointer user_data)
972 DBG("Received DPP Conf Sent Signal");
973 netconfig_wifi_dpp_conf_sent_event(param);
977 static void _supplicant_dpp_conf_received(GDBusConnection *conn,
978 const gchar *name, const gchar *path, const gchar *interface,
979 const gchar *sig, GVariant *param, gpointer user_data)
981 DBG("Received DPP Conf Received Signal");
982 netconfig_wifi_dpp_conf_received_event(param);
986 static void _supplicant_dpp_conf_obj(GDBusConnection *conn,
987 const gchar *name, const gchar *path, const gchar *interface,
988 const gchar *sig, GVariant *param, gpointer user_data)
990 DBG("Received DPP Conf Obj Signal");
991 netconfig_wifi_dpp_conf_obj_event(param);
995 static void _supplicant_wifi_wps_connected(GVariant *param)
998 char ssid[32] = {0, };
1002 int config_error = 0;
1003 int error_indication = 0;
1006 if (param == NULL) {
1007 ERR("Param is NULL");
1011 g_variant_get(param, "(sa{sv})", &name, &iter);
1012 INFO("wps Result: %s", name);
1013 while (g_variant_iter_loop(iter, "{sv}", &key, &variant)) {
1014 INFO("wps Key is %s", key);
1015 if (g_strcmp0(key, "SSID") == 0) {
1016 const char *t_key = NULL;
1017 t_key = g_variant_get_fixed_array(variant, &ssid_len, sizeof(guchar));
1018 INFO("wps ssid_len is %zd ", ssid_len);
1019 if (t_key == NULL) {
1021 g_variant_unref(variant);
1022 ERR("WPS PBC Connection Failed");
1025 if (ssid_len > 0 && ssid_len <= 32) {
1026 memcpy(ssid, t_key, ssid_len);
1028 memset(ssid, 0, sizeof(ssid));
1031 INFO("WPS PBC Connection completed with AP %s", ssid);
1032 netconfig_wifi_notify_wps_completed(ssid, ssid_len);
1036 g_variant_iter_free(iter);
1041 g_variant_iter_free(iter);
1043 error_indication = WPS_EI_OPERATION_FAILED;
1044 config_error = WPS_CFG_NO_ERROR;
1045 ERR("Error Occured! Notifying Fail Event");
1046 netconfig_wifi_notify_wps_fail_event(config_error, error_indication);
1050 static void _supplicant_wifi_wps_event(GVariant *param)
1056 gint32 config_error = 0;
1057 gint32 error_indication = 0;
1059 if (param == NULL) {
1060 ERR("Param is NULL");
1064 g_variant_get(param, "(sa{sv})", &name, &iter);
1065 INFO("Event Result: %s", name);
1066 if (g_strcmp0(name, "fail") == 0) {
1067 while (g_variant_iter_loop(iter, "{sv}", &key, &variant)) {
1070 INFO("Key is %s", key);
1071 if (g_strcmp0(key, "config_error") == 0) {
1072 config_error = g_variant_get_int32(variant);
1073 ERR("Config Error %d", config_error);
1074 } else if (g_strcmp0(key, "error_indication") == 0) {
1075 error_indication = g_variant_get_int32(variant);
1076 ERR("Error Indication %d", error_indication);
1079 netconfig_wifi_notify_wps_fail_event(config_error, error_indication);
1082 g_variant_iter_free(iter);
1087 g_variant_iter_free(iter);
1089 error_indication = WPS_EI_OPERATION_FAILED;
1090 config_error = WPS_CFG_NO_ERROR;
1091 ERR("Error Occured! Notifying Fail Event");
1092 netconfig_wifi_notify_wps_fail_event(config_error, error_indication);
1095 static void _find_service_and_set_passphrase(char *ssid, char *key)
1098 GVariant *reply = NULL;
1103 gchar *enc_passphrase;
1105 ssid_len = strlen(ssid);
1107 str = g_string_sized_new((ssid_len * 2) + 55);
1111 dev_mac_addr = vconf_get_str(VCONFKEY_WIFI_BSSID_ADDRESS);
1112 if (!dev_mac_addr) {
1113 ERR("Failed to get mac address from vconf key");
1114 g_string_free(str, TRUE);
1119 for (i = 0; dev_mac_addr[i]; i++) {
1120 if (dev_mac_addr[i] != ':')
1121 ident[j++] = dev_mac_addr[i];
1125 g_string_append_printf(str, "%s%s_", CONNMAN_WIFI_SERVICE_PROFILE_PREFIX,
1129 for (i = 0; i < ssid_len; i++) {
1131 g_string_append_printf(str, "%02x", ssid[i]);
1134 g_string_append_printf(str, "_managed_psk");
1136 service_path = g_string_free(str, FALSE);
1138 enc_passphrase = _netconfig_encrypt_passphrase(key);
1139 if (!enc_passphrase) {
1140 ERR("Failed to encrypt passphrase");
1141 g_free(service_path);
1145 INFO("wps service_path %s Passphrase %s", service_path, enc_passphrase);
1147 reply = netconfig_invoke_dbus_method(CONNMAN_SERVICE, service_path,
1148 CONNMAN_SERVICE_INTERFACE, "SetProperty",
1149 g_variant_new("(sv)", "Passphrase",
1150 g_variant_new_string(enc_passphrase)));
1152 g_variant_unref(reply);
1154 ERR("Failed to set passphrase");
1156 g_free(service_path);
1161 static void _supplicant_wifi_wps_credentials(GVariant *param)
1164 char ssid[32] = {0, };
1165 char wps_key[100] = {0, };
1168 int config_error = 0;
1169 int error_indication = 0;
1171 char *key_mgmt = NULL;
1173 if (param == NULL) {
1174 ERR("Param is NULL");
1178 g_variant_get(param, "(a{sv})", &iter);
1179 while (g_variant_iter_loop(iter, "{sv}", &key, &variant)) {
1182 INFO("wps Key is %s", key);
1183 if (g_strcmp0(key, "Key") == 0) {
1185 const char *t_key = NULL;
1186 key_len = g_variant_get_size(variant);
1188 INFO("wps password len %zd ", key_len);
1190 t_key = g_variant_get_fixed_array(variant, &key_len,
1194 g_variant_unref(variant);
1197 strncpy(wps_key, t_key, key_len);
1198 wps_key[key_len] = '\0';
1199 INFO("WPS Key in process credentials %s", wps_key);
1201 SLOGI("WPS AP Security ->Open");
1202 } else if (g_strcmp0(key, "SSID") == 0) {
1203 const char *t_key = NULL;
1204 t_key = g_variant_get_fixed_array(variant, &ssid_len,
1206 INFO("wps ssid_len is %zd ", ssid_len);
1209 g_variant_unref(variant);
1212 if (ssid_len > 0 && ssid_len <= 32) {
1213 memcpy(ssid, t_key, ssid_len);
1215 memset(ssid, 0, sizeof(ssid));
1218 INFO("SSID in process credentials %s", ssid);
1219 } else if (g_strcmp0(key, "AuthType") == 0) {
1221 GVariantIter *var_iter;
1222 g_variant_get(variant, "as", &var_iter);
1223 while (g_variant_iter_loop(var_iter, "s", &auth_type)) {
1224 INFO("wps auth_type %s", auth_type);
1225 if (g_strcmp0(auth_type, "wpa-psk") == 0 ||
1226 g_strcmp0(auth_type, "wpa2-psk") == 0)
1228 else if (g_strcmp0(auth_type, "open") == 0)
1231 g_variant_iter_free(var_iter);
1232 } else if (g_strcmp0(key, "EncrType") == 0) {
1234 GVariantIter *var_iter;
1235 g_variant_get(variant, "as", &var_iter);
1236 while (g_variant_iter_loop(var_iter, "s", &encr_type))
1237 INFO("wps encr_type %s", encr_type);
1238 g_variant_iter_free(var_iter);
1239 } else if (g_strcmp0(key, "BSSID") == 0) {
1240 const guchar *bssid;
1242 bssid = g_variant_get_fixed_array(variant, &bssid_len,
1244 if (bssid && bssid_len == 6)
1245 INFO("wps BSSID %2x:%2x:%2x:%2x:%2x:%2x", bssid[0], bssid[1],
1246 bssid[2], bssid[3], bssid[4], bssid[5]);
1250 g_variant_iter_free(iter);
1252 if (g_strcmp0(key_mgmt, "psk") == 0)
1253 _find_service_and_set_passphrase(ssid, wps_key);
1257 * Notify WPS Credentials only when requested through WPS PBC
1258 * In case of WPS PIN connman will take care of notification
1260 if (netconfig_get_wps_field() == TRUE)
1262 netconfig_wifi_notify_wps_credentials(ssid, ssid_len, wps_key);
1266 g_variant_iter_free(iter);
1267 error_indication = WPS_EI_OPERATION_FAILED;
1268 config_error = WPS_CFG_NO_ERROR;
1269 ERR("Error Occured! Notifying Fail Event");
1270 netconfig_wifi_notify_wps_fail_event(config_error, error_indication);
1273 static void __netconfig_wps_signal_filter_handler(GDBusConnection *conn,
1274 const gchar *name, const gchar *path, const gchar *interface,
1275 const gchar *sig, GVariant *param, gpointer user_data)
1277 if (g_strcmp0(sig, SIGNAL_WPS_CREDENTIALS) == 0) {
1278 INFO("Received wps CREDENTIALS Signal from Supplicant");
1279 _supplicant_wifi_wps_credentials(param);
1280 } else if (g_strcmp0(sig, SIGNAL_WPS_EVENT) == 0) {
1281 INFO("Received wps EVENT Signal from Supplicant");
1282 _supplicant_wifi_wps_event(param);
1283 } else if (g_strcmp0(sig, SIGNAL_WPS_CONNECTED) == 0) {
1284 INFO("Received WPSConnected Signal from Supplicant");
1285 _supplicant_wifi_wps_connected(param);
1291 static supplicant_signal_cb supplicant_cbs[SIG_MAX] = {
1292 _supplicant_interface_removed,
1293 _supplicant_properties_changed,
1294 _supplicant_bss_added,
1295 _supplicant_scan_done,
1296 _supplicant_driver_hanged,
1297 _supplicant_session_overlapped,
1298 _supplicant_tdls_connected,
1299 _supplicant_tdls_disconnected,
1300 _supplicant_tdls_peer_found,
1301 _supplicant_dpp_auth_success,
1302 _supplicant_dpp_auth_failed,
1303 _supplicant_dpp_not_compatible,
1304 _supplicant_dpp_conf_failed,
1305 _supplicant_dpp_scan_peer_qr,
1306 _supplicant_dpp_network_id,
1307 _supplicant_dpp_conf_sent,
1308 _supplicant_dpp_conf_received,
1309 _supplicant_dpp_conf_obj,
1312 void register_gdbus_signal(void)
1314 GDBusConnection *connection = NULL;
1315 SuppSigArrayIndex sig;
1316 connection = netdbus_get_connection();
1318 if (connection == NULL) {
1319 ERR("Failed to get GDbus Connection");
1323 /* listening to messages from all objects as no path is specified */
1324 /* see signals from the given interface */
1325 conn_subscription_ids[0] = g_dbus_connection_signal_subscribe(
1328 CONNMAN_TECHNOLOGY_INTERFACE,
1332 G_DBUS_SIGNAL_FLAGS_NONE,
1333 _technology_signal_cb,
1337 conn_subscription_ids[1] = g_dbus_connection_signal_subscribe(
1340 CONNMAN_SERVICE_INTERFACE,
1341 CONNMAN_SIGNAL_PROPERTY_CHANGED,
1344 G_DBUS_SIGNAL_FLAGS_NONE,
1349 conn_subscription_ids[2] = g_dbus_connection_signal_subscribe(
1352 DBUS_INTERFACE_DBUS,
1353 SIGNAL_NAME_OWNER_CHANGED,
1356 G_DBUS_SIGNAL_FLAGS_NONE,
1357 _dbus_name_changed_cb,
1361 conn_subscription_ids[3] = g_dbus_connection_signal_subscribe(
1364 CONNMAN_MANAGER_INTERFACE,
1365 CONNMAN_SIGNAL_SERVICES_CHANGED,
1368 G_DBUS_SIGNAL_FLAGS_NONE,
1369 _services_changed_cb,
1373 INFO("Successfully register connman DBus signal filters");
1375 conn_subscription_ids[4] = g_dbus_connection_signal_subscribe(
1378 SUPPLICANT_INTERFACE ".Interface.WPS",
1382 G_DBUS_SIGNAL_FLAGS_NONE,
1383 __netconfig_wps_signal_filter_handler,
1387 INFO("Successfully register Supplicant WPS DBus signal filters");
1389 conn_subscription_ids[5] = g_dbus_connection_signal_subscribe(
1392 DBUS_INTERFACE_DBUS,
1393 SIGNAL_NAME_OWNER_CHANGED,
1396 G_DBUS_SIGNAL_FLAGS_NONE,
1397 _dbus_name_changed_cb,
1401 INFO("Successfully register clat DBus signal filters");
1403 for (sig = SIG_INTERFACE_REMOVED; sig < SIG_MAX; sig++) {
1404 supp_subscription_ids[sig] = g_dbus_connection_signal_subscribe(
1407 supplicant_iface_for_sig[sig],
1408 supplicant_signals[sig],
1411 G_DBUS_SIGNAL_FLAGS_NONE,
1412 supplicant_cbs[sig],
1417 INFO("Successfully register Supplicant DBus signal filters");
1419 #if defined TIZEN_DEBUG_ENABLE
1420 dumpservice_subscription_id = g_dbus_connection_signal_subscribe(
1423 DUMP_SERVICE_INTERFACE,
1427 G_DBUS_SIGNAL_FLAGS_NONE,
1428 __netconfig_dumpservice_handler,
1432 INFO("Successfully registered Dumpservice DBus signal filter");
1435 /* In case ConnMan precedes this signal register,
1436 * net-config should update the default connected profile.
1438 netconfig_update_default();
1441 void deregister_gdbus_signal(void)
1443 GDBusConnection *connection = NULL;
1445 SuppSigArrayIndex sig;
1446 connection = netdbus_get_connection();
1448 ERR("Already de-registered. Nothing to be done");
1452 for (signal = 0; signal < TOTAL_CONN_SIGNALS; signal++) {
1453 if (conn_subscription_ids[signal]) {
1454 g_dbus_connection_signal_unsubscribe(connection,
1455 conn_subscription_ids[signal]);
1459 for (sig = SIG_INTERFACE_REMOVED; sig < SIG_MAX; sig++) {
1460 if (supp_subscription_ids[sig]) {
1461 g_dbus_connection_signal_unsubscribe(connection,
1462 supp_subscription_ids[sig]);
1466 #if defined TIZEN_DEBUG_ENABLE
1467 g_dbus_connection_signal_unsubscribe(connection,
1468 dumpservice_subscription_id);