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 #if defined TIZEN_DEBUG_ENABLE
44 #include "network-dump.h"
45 #define NETWORK_LOG_DUMP_SCRIPT "/opt/var/lib/net-config/network_log_dump.sh"
46 #define MAX_SIZE_ERROR_BUFFER 256
49 #define DBUS_SERVICE_DBUS "org.freedesktop.DBus"
50 #define DBUS_INTERFACE_DBUS "org.freedesktop.DBus"
51 #define SIGNAL_INTERFACE_REMOVED "InterfaceRemoved"
52 #define SIGNAL_SCAN_DONE "ScanDone"
53 #define SIGNAL_BSS_ADDED "BSSAdded"
54 #define SIGNAL_PROPERTIES_CHANGED "PropertiesChanged"
55 #define SIGNAL_PROPERTIES_DRIVER_HANGED "DriverHanged"
56 #define SIGNAL_PROPERTIES_SESSION_OVERLAPPED "SessionOverlapped"
57 #define SIGNAL_TDLS_CONNECTED "TDLSConnected"
58 #define SIGNAL_TDLS_DISCONNECTED "TDLSDisconnected"
59 #define SIGNAL_TDLS_PEER_FOUND "TDLSPeerFound"
61 #define SIGNAL_WPS_CONNECTED "WPSConnected"
62 #define SIGNAL_WPS_EVENT "Event"
63 #define SIGNAL_WPS_CREDENTIALS "Credentials"
65 #define CONNMAN_SIGNAL_SERVICES_CHANGED "ServicesChanged"
66 #define CONNMAN_SIGNAL_PROPERTY_CHANGED "PropertyChanged"
67 #define CONNMAN_SIGNAL_NAME_CHANGED "NameOwnerChanged"
69 #define MAX_SIG_LEN 64
70 #define TOTAL_CONN_SIGNALS 5
71 #define MAX_SOCKET_OPEN_RETRY 5
74 SIG_INTERFACE_REMOVED = 0,
75 SIG_PROPERTIES_CHANGED,
79 SIG_SESSION_OVERLAPPED,
81 SIG_TDLS_DISCONNECTED,
86 static int conn_subscription_ids[TOTAL_CONN_SIGNALS] = {0};
87 static const char supplicant_signals[SIG_MAX][MAX_SIG_LEN] = {
88 SIGNAL_INTERFACE_REMOVED,
89 SIGNAL_PROPERTIES_CHANGED,
92 SIGNAL_PROPERTIES_DRIVER_HANGED,
93 SIGNAL_PROPERTIES_SESSION_OVERLAPPED,
94 SIGNAL_TDLS_CONNECTED,
95 SIGNAL_TDLS_DISCONNECTED,
96 SIGNAL_TDLS_PEER_FOUND,
99 static int supp_subscription_ids[SIG_MAX] = {0};
100 #if defined TIZEN_DEBUG_ENABLE
101 static int dumpservice_subscription_id = 0;
104 typedef void (*supplicant_signal_cb)(GDBusConnection *conn,
105 const gchar *name, const gchar *path, const gchar *interface,
106 const gchar *sig, GVariant *param, gpointer user_data);
107 typedef void (*connman_signal_cb)(GDBusConnection *conn,
108 const gchar *name, const gchar *path, const gchar *interface,
109 const gchar *sig, GVariant *param, gpointer user_data);
111 static void __netconfig_extract_ipv4_signal_data(GVariant *dictionary,
112 const gchar *profile)
115 const gchar *value = NULL;
116 GVariant *var = NULL;
118 GVariantBuilder *builder;
121 g_variant_iter_init(&iter, dictionary);
122 while (g_variant_iter_loop(&iter, "{sv}", &key, &var)) {
123 if (g_strcmp0(key, "Address") == 0) {
124 g_variant_get(var, "&s", &value);
125 char *old_ip = vconf_get_str(VCONFKEY_NETWORK_IP);
127 DBG("Old IPv4.Address [%s] Received new IPv4.Address [%s]", old_ip,
129 if (g_strcmp0(old_ip, value) != 0) {
130 builder = g_variant_builder_new(G_VARIANT_TYPE("a{sv}"));
133 vconf_set_str(VCONFKEY_NETWORK_IP, value);
134 g_variant_builder_add(builder, "{sv}", "IPv4Address",
135 g_variant_new_string(value));
136 } else if (old_ip != NULL && strlen(old_ip) > 0) {
137 vconf_set_str(VCONFKEY_NETWORK_IP, "");
138 g_variant_builder_add(builder, "{sv}", "IPv4Address",
139 g_variant_new_string(""));
142 params = g_variant_new("(@a{sv})",
143 g_variant_builder_end(builder));
145 netconfig_dbus_emit_signal(NULL, NETCONFIG_NETWORK_PATH,
146 NETCONFIG_NETWORK_INTERFACE, "NetworkConfigChanged",
154 static void __netconfig_extract_ipv6_signal_data(GVariant *dictionary,
155 const gchar *profile)
158 const gchar *value = NULL;
159 GVariant *var = NULL;
161 GVariantBuilder *builder;
164 g_variant_iter_init(&iter, dictionary);
165 while (g_variant_iter_loop(&iter, "{sv}", &key, &var)) {
166 if (g_strcmp0(key, "Address") == 0) {
167 g_variant_get(var, "&s", &value);
168 char *old_ip6 = vconf_get_str(VCONFKEY_NETWORK_IP6);
170 DBG("Old IPv6.Address [%s] Received new IPv6.Address [%s]", old_ip6,
172 if (g_strcmp0(old_ip6, value) != 0) {
173 builder = g_variant_builder_new(G_VARIANT_TYPE("a{sv}"));
176 vconf_set_str(VCONFKEY_NETWORK_IP6, value);
177 g_variant_builder_add(builder, "{sv}", "IPv6Address",
178 g_variant_new_string(value));
179 } else if (old_ip6 != NULL && strlen(old_ip6) > 0) {
180 vconf_set_str(VCONFKEY_NETWORK_IP6, "");
181 g_variant_builder_add(builder, "{sv}", "IPv6Address",
182 g_variant_new_string(""));
185 params = g_variant_new("(@a{sv})",
186 g_variant_builder_end(builder));
188 netconfig_dbus_emit_signal(NULL, NETCONFIG_NETWORK_PATH,
189 NETCONFIG_NETWORK_INTERFACE, "NetworkConfigChanged",
197 #if defined TIZEN_DEBUG_ENABLE
198 static int __netconfig_handle_execute_file(const char *file_path,
199 char *const args[], char *const envs[])
205 register unsigned int index = 0;
206 char error_buf[MAX_SIZE_ERROR_BUFFER] = {0, };
208 while (args[index] != NULL) {
209 DBG("%s", args[index]);
213 if (!(pid = fork())) {
214 DBG("pid(%d), ppid (%d)", getpid(), getppid());
215 DBG("Inside child, exec (%s) command", file_path);
218 if (execve(file_path, args, envs) == -1) {
219 strerror_r(errno, error_buf, MAX_SIZE_ERROR_BUFFER);
220 DBG("Fail to execute command (%s)", error_buf);
223 } else if (pid > 0) {
224 if (waitpid(pid, &status, 0) == -1)
225 DBG("wait pid (%u) status (%d)", pid, status);
227 if (WIFEXITED(status)) {
228 rv = WEXITSTATUS(status);
229 DBG("exited, status=%d", rv);
230 } else if (WIFSIGNALED(status)) {
231 DBG("killed by signal %d", WTERMSIG(status));
232 } else if (WIFSTOPPED(status)) {
233 DBG("stopped by signal %d", WSTOPSIG(status));
234 } else if (WIFCONTINUED(status)) {
241 strerror_r(errno, error_buf, MAX_SIZE_ERROR_BUFFER);
242 DBG("failed to fork(%s)", error_buf);
246 static int _start_dump()
249 gchar *path = NETWORK_LOG_DUMP_SCRIPT;
250 char *const args[] = { NETWORK_LOG_DUMP_SCRIPT, NULL };
251 char *const envs[] = { NULL };
253 rv = __netconfig_handle_execute_file(path, args, envs);
255 ERR("Fail to execute network log dump shell");
262 static void _technology_signal_cb(GDBusConnection *conn,
263 const gchar *name, const gchar *path, const gchar *interface,
264 const gchar *sig, GVariant *param, gpointer user_data)
267 gboolean value = FALSE;
268 GVariant *var = NULL;
273 if (g_str_has_prefix(path, CONNMAN_WIFI_TECHNOLOGY_PREFIX) == TRUE) {
274 g_variant_get(param, "(sv)", &key, &var);
275 if (g_strcmp0(key, "Powered") == 0) {
277 value = g_variant_get_boolean(var);
279 wifi_state_update_power_state(TRUE);
281 wifi_state_update_power_state(FALSE);
282 } else if (g_strcmp0(key, "Connected") == 0) {
283 /* Connection state */
284 value = g_variant_get_boolean(var);
286 wifi_state_set_tech_state(NETCONFIG_WIFI_TECH_CONNECTED);
288 wifi_state_set_tech_state(NETCONFIG_WIFI_TECH_POWERED);
289 } else if (g_strcmp0(key, "Tethering") == 0) {
290 /* Tethering state */
291 wifi_state_set_tech_state(NETCONFIG_WIFI_TECH_TETHERED);
296 g_variant_unref(var);
300 static void _service_signal_cb(GDBusConnection *conn,
301 const gchar *name, const gchar *path,
302 const gchar *interface, const gchar *sig,
303 GVariant *param, gpointer user_data)
305 gchar *sigvalue = NULL;
307 GVariant *variant = NULL, *var;
309 const gchar *value = NULL;
310 struct sock_data *sd = NULL;
313 if (path == NULL || param == NULL)
316 g_variant_get(param, "(sv)", &sigvalue, &variant);
317 if (sigvalue == NULL)
320 if (g_strcmp0(sig, CONNMAN_SIGNAL_PROPERTY_CHANGED) != 0)
323 if (g_strcmp0(sigvalue, "State") == 0) {
324 g_variant_get(variant, "s", &property);
326 DBG("[%s] %s", property, path);
327 if (netconfig_is_wifi_profile(path) || netconfig_is_ethernet_profile(path)) {
328 if (g_strcmp0(property, "ready") == 0) {
329 for (idx = 0; idx < MAX_SOCKET_OPEN_RETRY; idx++) {
330 sd = start_ip_conflict_mon();
334 } else if (g_strcmp0(property, "online") == 0) {
337 stop_ip_conflict_mon();
341 if (netconfig_is_wifi_profile(path) == TRUE) {
344 netconfig_vconf_get_int(VCONFKEY_WIFI_STATE, &wifi_state);
345 if (wifi_state == VCONFKEY_WIFI_OFF) {
350 if (g_strcmp0(property, "ready") == 0 || g_strcmp0(property, "online") == 0) {
351 if (wifi_state >= VCONFKEY_WIFI_CONNECTED) {
356 netconfig_update_default_profile(path);
358 wifi_state_set_service_state(NETCONFIG_WIFI_CONNECTED);
360 } else if (g_strcmp0(property, "failure") == 0 || g_strcmp0(property, "disconnect") == 0 || g_strcmp0(property, "idle") == 0) {
361 if (netconfig_get_default_profile() == NULL ||
362 netconfig_is_wifi_profile(netconfig_get_default_profile())
364 if (g_strcmp0(property, "failure") == 0)
365 wifi_state_set_service_state(NETCONFIG_WIFI_FAILURE);
367 wifi_state_set_service_state(NETCONFIG_WIFI_IDLE);
372 if (g_strcmp0(path, netconfig_get_default_profile()) != 0) {
377 netconfig_update_default_profile(NULL);
379 if (g_strcmp0(property, "failure") == 0)
380 wifi_state_set_service_state(NETCONFIG_WIFI_FAILURE);
382 wifi_state_set_service_state(NETCONFIG_WIFI_IDLE);
384 } else if (g_strcmp0(property, "association") == 0 || g_strcmp0(property, "configuration") == 0) {
385 if (netconfig_get_default_profile() == NULL ||
386 netconfig_is_wifi_profile(netconfig_get_default_profile()) != TRUE) {
387 if (g_strcmp0(property, "association") == 0)
388 wifi_state_set_service_state(NETCONFIG_WIFI_ASSOCIATION);
390 wifi_state_set_service_state(NETCONFIG_WIFI_CONFIGURATION);
395 if (g_strcmp0(path, netconfig_get_default_profile()) != 0) {
400 netconfig_update_default_profile(NULL);
402 if (g_strcmp0(property, "association") == 0)
403 wifi_state_set_service_state(NETCONFIG_WIFI_ASSOCIATION);
405 wifi_state_set_service_state(NETCONFIG_WIFI_CONFIGURATION);
409 if (g_strcmp0(property, "ready") == 0 || g_strcmp0(property, "online") == 0) {
410 if (netconfig_get_default_profile() == NULL) {
411 if (!netconfig_is_cellular_profile(path))
412 netconfig_update_default_profile(path);
414 if (netconfig_is_cellular_internet_profile(path))
415 netconfig_update_default_profile(path);
419 if (netconfig_is_cellular_profile(path) && netconfig_is_cellular_internet_profile(path))
420 cellular_state_set_service_state(NETCONFIG_CELLULAR_ONLINE);
422 } else if (g_strcmp0(property, "failure") == 0 || g_strcmp0(property, "disconnect") == 0 || g_strcmp0(property, "idle") == 0) {
423 if (netconfig_get_default_profile() == NULL) {
428 if (netconfig_is_cellular_profile(path) && netconfig_is_cellular_internet_profile(path))
429 cellular_state_set_service_state(NETCONFIG_CELLULAR_IDLE);
431 if (g_strcmp0(path, netconfig_get_default_profile()) != 0) {
436 netconfig_update_default_profile(NULL);
437 } else if (g_strcmp0(property, "association") == 0 || g_strcmp0(property, "configuration") == 0) {
438 if (netconfig_get_default_profile() == NULL) {
443 if (netconfig_is_cellular_profile(path) && netconfig_is_cellular_internet_profile(path))
444 cellular_state_set_service_state(NETCONFIG_CELLULAR_CONNECTING);
446 if (g_strcmp0(path, netconfig_get_default_profile()) != 0) {
451 netconfig_update_default_profile(NULL);
455 } else if (g_strcmp0(sigvalue, "Proxy") == 0) {
456 if (netconfig_is_wifi_profile(path) != TRUE || g_strcmp0(path, netconfig_get_default_profile()) != 0)
459 if (!g_variant_type_equal(variant, G_VARIANT_TYPE_ARRAY))
462 g_variant_get(variant, "a{sv}", &iter);
463 while (g_variant_iter_loop(iter, "{sv}", &property, &var)) {
464 GVariantBuilder *builder;
465 GVariant *sig_params;
466 if (g_strcmp0(property, "Servers") == 0) {
467 GVariantIter *iter_sub = NULL;
469 builder = g_variant_builder_new(G_VARIANT_TYPE("a{sv}"));
471 g_variant_get(var, "as", &iter_sub);
472 g_variant_iter_loop(iter_sub, "s", &value);
473 g_variant_iter_free(iter_sub);
475 DBG("Proxy - [%s]", value);
476 vconf_set_str(VCONFKEY_NETWORK_PROXY, value);
478 g_variant_builder_add(builder, "{sv}", "ProxyAddress",
479 g_variant_new_string(value));
481 sig_params = g_variant_new("(@a{sv})",
482 g_variant_builder_end(builder));
484 netconfig_dbus_emit_signal(NULL, NETCONFIG_NETWORK_PATH,
485 NETCONFIG_NETWORK_INTERFACE, "NetworkConfigChanged",
489 g_variant_unref(var);
491 } else if (g_strcmp0(property, "Method") == 0) {
492 value = g_variant_get_string(var, NULL);
493 DBG("Method - [%s]", value);
495 if (g_strcmp0(value, "direct") == 0) {
496 builder = g_variant_builder_new(G_VARIANT_TYPE("a{sv}"));
498 vconf_set_str(VCONFKEY_NETWORK_PROXY, "");
499 g_variant_builder_add(builder, "{sv}", "ProxyAddress",
500 g_variant_new_string(""));
502 sig_params = g_variant_new("(@a{sv})",
503 g_variant_builder_end(builder));
505 netconfig_dbus_emit_signal(NULL, NETCONFIG_NETWORK_PATH,
506 NETCONFIG_NETWORK_INTERFACE,
507 "NetworkConfigChanged", sig_params);
511 g_variant_unref(var);
516 g_variant_iter_free(iter);
517 } else if (g_strcmp0(sigvalue, "IPv4") == 0) {
518 __netconfig_extract_ipv4_signal_data(variant, path);
519 } else if (g_strcmp0(sigvalue, "IPv6") == 0) {
520 __netconfig_extract_ipv6_signal_data(variant, path);
521 } else if (g_strcmp0(sigvalue, "Error") == 0) {
522 g_variant_get(variant, "s", &property);
523 INFO("[%s] Property : %s", sigvalue, property);
524 #if defined TIZEN_DEBUG_ENABLE
525 if (g_strcmp0(property, "connect-failed") == 0 || g_strcmp0(property, "invalid-key") == 0 || g_strcmp0(property, "auth-failed") == 0)
535 g_variant_unref(variant);
540 static void _dbus_name_changed_cb(GDBusConnection *conn,
541 const gchar *Name, const gchar *path, const gchar *interface,
542 const gchar *sig, GVariant *param, gpointer user_data)
551 g_variant_get(param, "(sss)", &name, &old, &new);
553 if (g_strcmp0(name, CONNMAN_SERVICE) == 0 && *new == '\0') {
554 DBG("ConnMan destroyed: name %s, old %s, new %s", name, old, new);
556 connman_register_agent();
568 static void _services_changed_cb(GDBusConnection *conn, const gchar *name,
569 const gchar *path, const gchar *interface, const gchar *sig,
570 GVariant *param, gpointer user_data)
572 gchar *property, *value;
574 GVariant *variant = NULL;
575 GVariantIter *added = NULL, *removed = NULL, *next = NULL;
577 if (path == NULL || param == NULL)
580 if (g_strcmp0(sig, CONNMAN_SIGNAL_SERVICES_CHANGED) != 0)
583 if (netconfig_get_default_profile() != NULL)
586 g_variant_get(param, "(a(oa{sv})ao)", &added, &removed);
588 while (g_variant_iter_loop(added, "(oa{sv})", &service_path, &next)) {
589 gboolean is_wifi_prof, is_cell_prof, is_cell_internet_prof;
590 is_wifi_prof = netconfig_is_wifi_profile(service_path);
591 is_cell_prof = netconfig_is_cellular_profile(service_path);
592 is_cell_internet_prof = netconfig_is_cellular_internet_profile(
594 if (service_path != NULL) {
595 while (next && g_variant_iter_loop(next, "{sv}", &property,
597 if (g_strcmp0(property, "State") == 0) {
598 g_variant_get(variant, "s", &value);
599 DBG("Profile %s State %s", service_path,
601 if (g_strcmp0(value, "ready") != 0 &&
606 g_variant_unref(variant);
611 netconfig_update_default_profile(
613 else if (is_cell_internet_prof) {
614 netconfig_update_default_profile(
618 wifi_state_set_service_state(
619 NETCONFIG_WIFI_CONNECTED);
620 else if (is_cell_prof &&
621 is_cell_internet_prof)
622 cellular_state_set_service_state(
623 NETCONFIG_CELLULAR_ONLINE);
626 g_variant_unref(variant);
633 g_variant_iter_free(added);
636 g_variant_iter_free(next);
639 g_variant_iter_free(removed);
644 static void _supplicant_interface_removed(GDBusConnection *conn,
645 const gchar *name, const gchar *path, const gchar *interface,
646 const gchar *sig, GVariant *param, gpointer user_data)
648 DBG("Interface removed handling!");
649 if (netconfig_wifi_is_bssid_scan_started() == TRUE)
650 netconfig_wifi_bssid_signal_scanaborted();
655 static void _supplicant_properties_changed(GDBusConnection *conn,
656 const gchar *name, const gchar *path, const gchar *interface,
657 const gchar *sig, GVariant *param, gpointer user_data)
659 DBG("Properties changed handling!");
661 const gchar *state = NULL;
662 GVariantIter *iter = NULL;
663 GVariant *variant = NULL;
664 gboolean scanning = FALSE;
669 g_variant_get(param, "(a{sv})", &iter);
670 while (g_variant_iter_loop(iter, "{sv}", &key, &variant)) {
671 if (g_strcmp0(key, "Scanning") == 0) {
672 scanning = g_variant_get_boolean(variant);
673 DBG("setting scanning %s", scanning ? "TRUE" : "FALSE");
674 if (scanning == TRUE)
675 netconfig_wifi_set_scanning(TRUE);
677 netconfig_wifi_set_scanning(FALSE);
679 g_variant_unref(variant);
684 } else if (g_strcmp0(key, "State") == 0) {
685 state = g_variant_get_string(variant, NULL);
687 ERR("Supplicant state : %s", state);
689 g_variant_unref(variant);
694 } else if (g_strcmp0(key, "DisconnectReason") == 0) {
695 int reason = g_variant_get_int32(variant);
696 ERR("Supplicant DisconnReason : %d", reason);
698 g_variant_unref(variant);
705 value = g_variant_print(variant, TRUE);
706 DBG("Supplicant %s : %s", key, value);
712 g_variant_iter_free(iter);
717 static void _supplicant_bss_added(GDBusConnection *conn,
718 const gchar *name, const gchar *path, const gchar *interface,
719 const gchar *sig, GVariant *param, gpointer user_data)
721 DBG("BSS added handling!");
722 wifi_state_set_bss_found(TRUE);
727 static void _supplicant_scan_done(GDBusConnection *conn,
728 const gchar *name, const gchar *path, const gchar *interface,
729 const gchar *sig, GVariant *param, gpointer user_data)
731 DBG("Scan Done handling!");
732 netconfig_wifi_set_scanning(FALSE);
734 if (netconfig_wifi_is_bssid_scan_started() == TRUE) {
735 netconfig_wifi_bssid_signal_scandone();
736 if (wifi_state_get_technology_state() < NETCONFIG_WIFI_TECH_POWERED)
740 if (netconfig_wifi_get_bgscan_state() == TRUE) {
741 if (wifi_state_get_technology_state() >=
742 NETCONFIG_WIFI_TECH_POWERED)
743 netconfig_wifi_bgscan_start(FALSE);
745 wifi_start_timer_network_notification();
751 static void _supplicant_driver_hanged(GDBusConnection *conn,
752 const gchar *name, const gchar *path, const gchar *interface,
753 const gchar *sig, GVariant *param, gpointer user_data)
755 DBG("Driver Hanged handling!");
756 ERR("Critical. Wi-Fi firmware crashed");
758 #if !defined TIZEN_WEARABLE
759 netconfig_send_message_to_net_popup("Wi-Fi Error",
760 "Wi-Fi Driver Hanged. Please get log dump and report", "popup", NULL);
762 wifi_power_recover_firmware();
768 static void _supplicant_session_overlapped(GDBusConnection *conn,
769 const gchar *name, const gchar *path, const gchar *interface,
770 const gchar *sig, GVariant *param, gpointer user_data)
772 DBG("Driver session overlapped handling!");
773 ERR("WPS PBC SESSION OVERLAPPED");
774 #if defined TIZEN_WEARABLE
777 netconfig_send_message_to_net_popup("WPS Error",
778 "wps session overlapped", "popup", NULL);
782 #if defined TIZEN_DEBUG_ENABLE
783 static void __netconfig_dumpservice_handler(GDBusConnection *conn,
784 const gchar *name, const gchar *path, const gchar *interface,
785 const gchar *sig, GVariant *param, gpointer user_data)
788 gchar *signal_path = NULL;
793 g_variant_get(param, "(is)", &mode, &signal_path);
794 DBG("Path: %s and mode: %d", signal_path, mode);
796 netconfig_dump_log(signal_path);
804 static void _supplicant_tdls_connected(GDBusConnection *conn,
805 const gchar *name, const gchar *path, const gchar *interface,
806 const gchar *sig, GVariant *param, gpointer user_data)
808 DBG("Received TDLS Connected Signal");
809 netconfig_wifi_tdls_connected_event(param);
814 static void _supplicant_tdls_disconnected(GDBusConnection *conn,
815 const gchar *name, const gchar *path, const gchar *interface,
816 const gchar *sig, GVariant *param, gpointer user_data)
818 DBG("Received TDLS Disconnected Signal");
819 netconfig_wifi_tdls_disconnected_event(param);
824 static void _supplicant_tdls_peer_found(GDBusConnection *conn,
825 const gchar *name, const gchar *path, const gchar *interface,
826 const gchar *sig, GVariant *param, gpointer user_data)
828 DBG("Received TDLS Peer Found Signal");
829 netconfig_wifi_tdls_peer_found_event(param);
833 static void _supplicant_wifi_wps_connected(GVariant *param)
836 char ssid[32] = {0, };
840 int config_error = 0;
841 int error_indication = 0;
845 ERR("Param is NULL");
849 g_variant_get(param, "(sa{sv})", &name, &iter);
850 INFO("wps Result: %s", name);
851 while (g_variant_iter_loop(iter, "{sv}", &key, &variant)) {
852 INFO("wps Key is %s", key);
853 if (g_strcmp0(key, "SSID") == 0) {
854 const char *t_key = NULL;
855 t_key = g_variant_get_fixed_array(variant, &ssid_len, sizeof(guchar));
856 INFO("wps ssid_len is %d ", ssid_len);
859 g_variant_unref(variant);
860 ERR("WPS PBC Connection Failed");
863 if (ssid_len > 0 && ssid_len <= 32) {
864 memcpy(ssid, t_key, ssid_len);
866 memset(ssid, 0, sizeof(ssid));
869 INFO("WPS PBC Connection completed with AP %s", ssid);
870 netconfig_wifi_notify_wps_completed(ssid, ssid_len);
874 g_variant_iter_free(iter);
879 g_variant_iter_free(iter);
881 error_indication = WPS_EI_OPERATION_FAILED;
882 config_error = WPS_CFG_NO_ERROR;
883 ERR("Error Occured! Notifying Fail Event");
884 netconfig_wifi_notify_wps_fail_event(config_error, error_indication);
888 static void _supplicant_wifi_wps_event(GVariant *param)
894 gint32 config_error = 0;
895 gint32 error_indication = 0;
898 ERR("Param is NULL");
902 g_variant_get(param, "(sa{sv})", &name, &iter);
903 INFO("Event Result: %s", name);
904 if (g_strcmp0(name, "fail") == 0) {
905 while (g_variant_iter_loop(iter, "{sv}", &key, &variant)) {
908 INFO("Key is %s", key);
909 if (g_strcmp0(key, "config_error") == 0) {
910 config_error = g_variant_get_int32(variant);
911 ERR("Config Error %d", config_error);
912 } else if (g_strcmp0(key, "error_indication") == 0) {
913 error_indication = g_variant_get_int32(variant);
914 ERR("Error Indication %d", error_indication);
917 netconfig_wifi_notify_wps_fail_event(config_error, error_indication);
920 g_variant_iter_free(iter);
925 g_variant_iter_free(iter);
927 error_indication = WPS_EI_OPERATION_FAILED;
928 config_error = WPS_CFG_NO_ERROR;
929 ERR("Error Occured! Notifying Fail Event");
930 netconfig_wifi_notify_wps_fail_event(config_error, error_indication);
933 static void _supplicant_wifi_wps_credentials(GVariant *param)
936 char ssid[32] = {0, };
937 char wps_key[100] = {0, };
940 int config_error = 0;
941 int error_indication = 0;
945 ERR("Param is NULL");
949 g_variant_get(param, "(a{sv})", &iter);
950 while (g_variant_iter_loop(iter, "{sv}", &key, &variant)) {
953 INFO("wps Key is %s", key);
954 if (g_strcmp0(key, "Key") == 0) {
956 const char *t_key = NULL;
957 key_len = g_variant_get_size(variant);
959 INFO("wps password len %d ", key_len);
961 t_key = g_variant_get_fixed_array(variant, &key_len, sizeof(guchar));
964 g_variant_unref(variant);
967 strncpy(wps_key, t_key, key_len);
968 wps_key[key_len] = '\0';
969 INFO("WPS Key in process credentials %s", wps_key);
971 SLOGI("WPS AP Security ->Open");
972 } else if (g_strcmp0(key, "SSID") == 0) {
973 const char *t_key = NULL;
974 t_key = g_variant_get_fixed_array(variant, &ssid_len, sizeof(guchar));
975 INFO("wps ssid_len is %d ", ssid_len);
978 g_variant_unref(variant);
981 if (ssid_len > 0 && ssid_len <= 32) {
982 memcpy(ssid, t_key, ssid_len);
984 memset(ssid, 0, sizeof(ssid));
987 INFO("SSID in process credentials %s", ssid);
991 g_variant_iter_free(iter);
995 * Notify WPS Credentials only when requested through WPS PBC
996 * In case of WPS PIN connman will take care of notification
998 if (netconfig_get_wps_field() == TRUE)
1000 netconfig_wifi_notify_wps_credentials(ssid, ssid_len, wps_key);
1004 g_variant_iter_free(iter);
1005 error_indication = WPS_EI_OPERATION_FAILED;
1006 config_error = WPS_CFG_NO_ERROR;
1007 ERR("Error Occured! Notifying Fail Event");
1008 netconfig_wifi_notify_wps_fail_event(config_error, error_indication);
1011 static void __netconfig_wps_signal_filter_handler(GDBusConnection *conn,
1012 const gchar *name, const gchar *path, const gchar *interface,
1013 const gchar *sig, GVariant *param, gpointer user_data)
1015 if (g_strcmp0(sig, SIGNAL_WPS_CREDENTIALS) == 0) {
1016 INFO("Received wps CREDENTIALS Signal from Supplicant");
1017 _supplicant_wifi_wps_credentials(param);
1018 } else if (g_strcmp0(sig, SIGNAL_WPS_EVENT) == 0) {
1019 INFO("Received wps EVENT Signal from Supplicant");
1020 _supplicant_wifi_wps_event(param);
1021 } else if (g_strcmp0(sig, SIGNAL_WPS_CONNECTED) == 0) {
1022 INFO("Received WPSConnected Signal from Supplicant");
1023 _supplicant_wifi_wps_connected(param);
1029 static supplicant_signal_cb supplicant_cbs[SIG_MAX] = {
1030 _supplicant_interface_removed,
1031 _supplicant_properties_changed,
1032 _supplicant_bss_added,
1033 _supplicant_scan_done,
1034 _supplicant_driver_hanged,
1035 _supplicant_session_overlapped,
1036 _supplicant_tdls_connected,
1037 _supplicant_tdls_disconnected,
1038 _supplicant_tdls_peer_found
1041 void register_gdbus_signal(void)
1043 GDBusConnection *connection = NULL;
1044 const char *interface = NULL;
1045 SuppSigArrayIndex sig;
1046 connection = netdbus_get_connection();
1048 if (connection == NULL) {
1049 ERR("Failed to get GDbus Connection");
1053 /* listening to messages from all objects as no path is specified */
1054 /* see signals from the given interface */
1055 conn_subscription_ids[0] = g_dbus_connection_signal_subscribe(
1058 CONNMAN_TECHNOLOGY_INTERFACE,
1062 G_DBUS_SIGNAL_FLAGS_NONE,
1063 _technology_signal_cb,
1067 conn_subscription_ids[1] = g_dbus_connection_signal_subscribe(
1070 CONNMAN_SERVICE_INTERFACE,
1071 CONNMAN_SIGNAL_PROPERTY_CHANGED,
1074 G_DBUS_SIGNAL_FLAGS_NONE,
1079 conn_subscription_ids[2] = g_dbus_connection_signal_subscribe(
1082 DBUS_INTERFACE_DBUS,
1083 CONNMAN_SIGNAL_NAME_CHANGED,
1086 G_DBUS_SIGNAL_FLAGS_NONE,
1087 _dbus_name_changed_cb,
1091 conn_subscription_ids[3] = g_dbus_connection_signal_subscribe(
1094 CONNMAN_MANAGER_INTERFACE,
1095 CONNMAN_SIGNAL_SERVICES_CHANGED,
1098 G_DBUS_SIGNAL_FLAGS_NONE,
1099 _services_changed_cb,
1103 INFO("Successfully register connman DBus signal filters");
1105 conn_subscription_ids[4] = g_dbus_connection_signal_subscribe(
1108 SUPPLICANT_INTERFACE ".Interface.WPS",
1112 G_DBUS_SIGNAL_FLAGS_NONE,
1113 __netconfig_wps_signal_filter_handler,
1117 INFO("Successfully register Supplicant WPS DBus signal filters");
1119 for (sig = SIG_INTERFACE_REMOVED; sig < SIG_MAX; sig++) {
1121 * For SIG_INTERFACE_REMOVED INTERFACE_ADDED
1123 interface = (sig == SIG_INTERFACE_REMOVED) ?
1124 SUPPLICANT_INTERFACE : SUPPLICANT_IFACE_INTERFACE;
1126 supp_subscription_ids[sig] = g_dbus_connection_signal_subscribe(
1130 supplicant_signals[sig],
1133 G_DBUS_SIGNAL_FLAGS_NONE,
1134 supplicant_cbs[sig],
1139 INFO("Successfully register Supplicant DBus signal filters");
1141 #if defined TIZEN_DEBUG_ENABLE
1142 dumpservice_subscription_id = g_dbus_connection_signal_subscribe(
1145 DUMP_SERVICE_INTERFACE,
1149 G_DBUS_SIGNAL_FLAGS_NONE,
1150 __netconfig_dumpservice_handler,
1154 INFO("Successfully registered Dumpservice DBus signal filter");
1157 /* In case ConnMan precedes this signal register,
1158 * net-config should update the default connected profile.
1160 netconfig_update_default();
1163 void deregister_gdbus_signal(void)
1165 GDBusConnection *connection = NULL;
1167 SuppSigArrayIndex sig;
1168 connection = netdbus_get_connection();
1170 ERR("Already de-registered. Nothing to be done");
1174 for (signal = 0; signal < TOTAL_CONN_SIGNALS; signal++) {
1175 if (conn_subscription_ids[signal]) {
1176 g_dbus_connection_signal_unsubscribe(connection,
1177 conn_subscription_ids[signal]);
1181 for (sig = SIG_INTERFACE_REMOVED; sig < SIG_MAX; sig++) {
1182 if (supp_subscription_ids[sig]) {
1183 g_dbus_connection_signal_unsubscribe(connection,
1184 supp_subscription_ids[sig]);
1188 #if defined TIZEN_DEBUG_ENABLE
1189 g_dbus_connection_signal_unsubscribe(connection,
1190 dumpservice_subscription_id);