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, "dhcp-failed") == 0
526 || g_strcmp0(property, "connect-failed") == 0
527 || g_strcmp0(property, "login-failed") == 0
528 || g_strcmp0(property, "auth-failed") == 0
529 || g_strcmp0(property, "invalid-key") == 0) {
542 g_variant_unref(variant);
547 static void _dbus_name_changed_cb(GDBusConnection *conn,
548 const gchar *Name, const gchar *path, const gchar *interface,
549 const gchar *sig, GVariant *param, gpointer user_data)
558 g_variant_get(param, "(sss)", &name, &old, &new);
560 if (g_strcmp0(name, CONNMAN_SERVICE) == 0 && *new == '\0') {
561 DBG("ConnMan destroyed: name %s, old %s, new %s", name, old, new);
563 connman_register_agent();
575 static void _services_changed_cb(GDBusConnection *conn, const gchar *name,
576 const gchar *path, const gchar *interface, const gchar *sig,
577 GVariant *param, gpointer user_data)
579 gchar *property, *value;
581 GVariant *variant = NULL;
582 GVariantIter *added = NULL, *removed = NULL, *next = NULL;
584 if (path == NULL || param == NULL)
587 if (g_strcmp0(sig, CONNMAN_SIGNAL_SERVICES_CHANGED) != 0)
590 if (netconfig_get_default_profile() != NULL)
593 g_variant_get(param, "(a(oa{sv})ao)", &added, &removed);
595 while (g_variant_iter_loop(added, "(oa{sv})", &service_path, &next)) {
596 gboolean is_wifi_prof, is_cell_prof, is_cell_internet_prof;
597 is_wifi_prof = netconfig_is_wifi_profile(service_path);
598 is_cell_prof = netconfig_is_cellular_profile(service_path);
599 is_cell_internet_prof = netconfig_is_cellular_internet_profile(
601 if (service_path != NULL) {
602 while (next && g_variant_iter_loop(next, "{sv}", &property,
604 if (g_strcmp0(property, "State") == 0) {
605 g_variant_get(variant, "s", &value);
606 DBG("Profile %s State %s", service_path,
608 if (g_strcmp0(value, "ready") != 0 &&
613 g_variant_unref(variant);
618 netconfig_update_default_profile(
620 else if (is_cell_internet_prof) {
621 netconfig_update_default_profile(
625 wifi_state_set_service_state(
626 NETCONFIG_WIFI_CONNECTED);
627 else if (is_cell_prof &&
628 is_cell_internet_prof)
629 cellular_state_set_service_state(
630 NETCONFIG_CELLULAR_ONLINE);
633 g_variant_unref(variant);
640 g_variant_iter_free(added);
643 g_variant_iter_free(next);
646 g_variant_iter_free(removed);
651 static void _supplicant_interface_removed(GDBusConnection *conn,
652 const gchar *name, const gchar *path, const gchar *interface,
653 const gchar *sig, GVariant *param, gpointer user_data)
655 DBG("Interface removed handling!");
656 if (netconfig_wifi_is_bssid_scan_started() == TRUE)
657 netconfig_wifi_bssid_signal_scanaborted();
662 static void _supplicant_properties_changed(GDBusConnection *conn,
663 const gchar *name, const gchar *path, const gchar *interface,
664 const gchar *sig, GVariant *param, gpointer user_data)
666 DBG("Properties changed handling!");
668 const gchar *state = NULL;
669 GVariantIter *iter = NULL;
670 GVariant *variant = NULL;
671 gboolean scanning = FALSE;
676 g_variant_get(param, "(a{sv})", &iter);
677 while (g_variant_iter_loop(iter, "{sv}", &key, &variant)) {
678 if (g_strcmp0(key, "Scanning") == 0) {
679 scanning = g_variant_get_boolean(variant);
680 DBG("setting scanning %s", scanning ? "TRUE" : "FALSE");
681 if (scanning == TRUE)
682 netconfig_wifi_set_scanning(TRUE);
684 netconfig_wifi_set_scanning(FALSE);
686 g_variant_unref(variant);
691 } else if (g_strcmp0(key, "State") == 0) {
692 state = g_variant_get_string(variant, NULL);
694 ERR("Supplicant state : %s", state);
696 g_variant_unref(variant);
701 } else if (g_strcmp0(key, "DisconnectReason") == 0) {
702 int reason = g_variant_get_int32(variant);
703 ERR("Supplicant DisconnReason : %d", reason);
705 g_variant_unref(variant);
712 value = g_variant_print(variant, TRUE);
713 DBG("Supplicant %s : %s", key, value);
719 g_variant_iter_free(iter);
724 static void _supplicant_bss_added(GDBusConnection *conn,
725 const gchar *name, const gchar *path, const gchar *interface,
726 const gchar *sig, GVariant *param, gpointer user_data)
728 DBG("BSS added handling!");
729 wifi_state_set_bss_found(TRUE);
734 static void _supplicant_scan_done(GDBusConnection *conn,
735 const gchar *name, const gchar *path, const gchar *interface,
736 const gchar *sig, GVariant *param, gpointer user_data)
738 DBG("Scan Done handling!");
739 netconfig_wifi_set_scanning(FALSE);
741 if (netconfig_wifi_is_bssid_scan_started() == TRUE) {
742 netconfig_wifi_bssid_signal_scandone();
743 if (wifi_state_get_technology_state() < NETCONFIG_WIFI_TECH_POWERED)
747 if (netconfig_wifi_get_bgscan_state() == TRUE) {
748 if (wifi_state_get_technology_state() >=
749 NETCONFIG_WIFI_TECH_POWERED)
750 netconfig_wifi_bgscan_start(FALSE);
752 wifi_start_timer_network_notification();
758 static void _supplicant_driver_hanged(GDBusConnection *conn,
759 const gchar *name, const gchar *path, const gchar *interface,
760 const gchar *sig, GVariant *param, gpointer user_data)
762 DBG("Driver Hanged handling!");
763 ERR("Critical. Wi-Fi firmware crashed");
765 #if !defined TIZEN_WEARABLE
766 netconfig_send_message_to_net_popup("Wi-Fi Error",
767 "Wi-Fi Driver Hanged. Please get log dump and report", "popup", NULL);
769 wifi_power_recover_firmware();
775 static void _supplicant_session_overlapped(GDBusConnection *conn,
776 const gchar *name, const gchar *path, const gchar *interface,
777 const gchar *sig, GVariant *param, gpointer user_data)
779 DBG("Driver session overlapped handling!");
780 ERR("WPS PBC SESSION OVERLAPPED");
781 #if defined TIZEN_WEARABLE
784 netconfig_send_message_to_net_popup("WPS Error",
785 "wps session overlapped", "popup", NULL);
789 #if defined TIZEN_DEBUG_ENABLE
790 static void __netconfig_dumpservice_handler(GDBusConnection *conn,
791 const gchar *name, const gchar *path, const gchar *interface,
792 const gchar *sig, GVariant *param, gpointer user_data)
795 gchar *signal_path = NULL;
800 g_variant_get(param, "(is)", &mode, &signal_path);
801 DBG("Path: %s and mode: %d", signal_path, mode);
803 netconfig_dump_log(signal_path);
811 static void _supplicant_tdls_connected(GDBusConnection *conn,
812 const gchar *name, const gchar *path, const gchar *interface,
813 const gchar *sig, GVariant *param, gpointer user_data)
815 DBG("Received TDLS Connected Signal");
816 netconfig_wifi_tdls_connected_event(param);
821 static void _supplicant_tdls_disconnected(GDBusConnection *conn,
822 const gchar *name, const gchar *path, const gchar *interface,
823 const gchar *sig, GVariant *param, gpointer user_data)
825 DBG("Received TDLS Disconnected Signal");
826 netconfig_wifi_tdls_disconnected_event(param);
831 static void _supplicant_tdls_peer_found(GDBusConnection *conn,
832 const gchar *name, const gchar *path, const gchar *interface,
833 const gchar *sig, GVariant *param, gpointer user_data)
835 DBG("Received TDLS Peer Found Signal");
836 netconfig_wifi_tdls_peer_found_event(param);
840 static void _supplicant_wifi_wps_connected(GVariant *param)
843 char ssid[32] = {0, };
847 int config_error = 0;
848 int error_indication = 0;
852 ERR("Param is NULL");
856 g_variant_get(param, "(sa{sv})", &name, &iter);
857 INFO("wps Result: %s", name);
858 while (g_variant_iter_loop(iter, "{sv}", &key, &variant)) {
859 INFO("wps Key is %s", key);
860 if (g_strcmp0(key, "SSID") == 0) {
861 const char *t_key = NULL;
862 t_key = g_variant_get_fixed_array(variant, &ssid_len, sizeof(guchar));
863 INFO("wps ssid_len is %d ", ssid_len);
866 g_variant_unref(variant);
867 ERR("WPS PBC Connection Failed");
870 if (ssid_len > 0 && ssid_len <= 32) {
871 memcpy(ssid, t_key, ssid_len);
873 memset(ssid, 0, sizeof(ssid));
876 INFO("WPS PBC Connection completed with AP %s", ssid);
877 netconfig_wifi_notify_wps_completed(ssid, ssid_len);
881 g_variant_iter_free(iter);
886 g_variant_iter_free(iter);
888 error_indication = WPS_EI_OPERATION_FAILED;
889 config_error = WPS_CFG_NO_ERROR;
890 ERR("Error Occured! Notifying Fail Event");
891 netconfig_wifi_notify_wps_fail_event(config_error, error_indication);
895 static void _supplicant_wifi_wps_event(GVariant *param)
901 gint32 config_error = 0;
902 gint32 error_indication = 0;
905 ERR("Param is NULL");
909 g_variant_get(param, "(sa{sv})", &name, &iter);
910 INFO("Event Result: %s", name);
911 if (g_strcmp0(name, "fail") == 0) {
912 while (g_variant_iter_loop(iter, "{sv}", &key, &variant)) {
915 INFO("Key is %s", key);
916 if (g_strcmp0(key, "config_error") == 0) {
917 config_error = g_variant_get_int32(variant);
918 ERR("Config Error %d", config_error);
919 } else if (g_strcmp0(key, "error_indication") == 0) {
920 error_indication = g_variant_get_int32(variant);
921 ERR("Error Indication %d", error_indication);
924 netconfig_wifi_notify_wps_fail_event(config_error, error_indication);
927 g_variant_iter_free(iter);
932 g_variant_iter_free(iter);
934 error_indication = WPS_EI_OPERATION_FAILED;
935 config_error = WPS_CFG_NO_ERROR;
936 ERR("Error Occured! Notifying Fail Event");
937 netconfig_wifi_notify_wps_fail_event(config_error, error_indication);
940 static void _supplicant_wifi_wps_credentials(GVariant *param)
943 char ssid[32] = {0, };
944 char wps_key[100] = {0, };
947 int config_error = 0;
948 int error_indication = 0;
952 ERR("Param is NULL");
956 g_variant_get(param, "(a{sv})", &iter);
957 while (g_variant_iter_loop(iter, "{sv}", &key, &variant)) {
960 INFO("wps Key is %s", key);
961 if (g_strcmp0(key, "Key") == 0) {
963 const char *t_key = NULL;
964 key_len = g_variant_get_size(variant);
966 INFO("wps password len %d ", key_len);
968 t_key = g_variant_get_fixed_array(variant, &key_len, sizeof(guchar));
971 g_variant_unref(variant);
974 strncpy(wps_key, t_key, key_len);
975 wps_key[key_len] = '\0';
976 INFO("WPS Key in process credentials %s", wps_key);
978 SLOGI("WPS AP Security ->Open");
979 } else if (g_strcmp0(key, "SSID") == 0) {
980 const char *t_key = NULL;
981 t_key = g_variant_get_fixed_array(variant, &ssid_len, sizeof(guchar));
982 INFO("wps ssid_len is %d ", ssid_len);
985 g_variant_unref(variant);
988 if (ssid_len > 0 && ssid_len <= 32) {
989 memcpy(ssid, t_key, ssid_len);
991 memset(ssid, 0, sizeof(ssid));
994 INFO("SSID in process credentials %s", ssid);
998 g_variant_iter_free(iter);
1002 * Notify WPS Credentials only when requested through WPS PBC
1003 * In case of WPS PIN connman will take care of notification
1005 if (netconfig_get_wps_field() == TRUE)
1007 netconfig_wifi_notify_wps_credentials(ssid, ssid_len, wps_key);
1011 g_variant_iter_free(iter);
1012 error_indication = WPS_EI_OPERATION_FAILED;
1013 config_error = WPS_CFG_NO_ERROR;
1014 ERR("Error Occured! Notifying Fail Event");
1015 netconfig_wifi_notify_wps_fail_event(config_error, error_indication);
1018 static void __netconfig_wps_signal_filter_handler(GDBusConnection *conn,
1019 const gchar *name, const gchar *path, const gchar *interface,
1020 const gchar *sig, GVariant *param, gpointer user_data)
1022 if (g_strcmp0(sig, SIGNAL_WPS_CREDENTIALS) == 0) {
1023 INFO("Received wps CREDENTIALS Signal from Supplicant");
1024 _supplicant_wifi_wps_credentials(param);
1025 } else if (g_strcmp0(sig, SIGNAL_WPS_EVENT) == 0) {
1026 INFO("Received wps EVENT Signal from Supplicant");
1027 _supplicant_wifi_wps_event(param);
1028 } else if (g_strcmp0(sig, SIGNAL_WPS_CONNECTED) == 0) {
1029 INFO("Received WPSConnected Signal from Supplicant");
1030 _supplicant_wifi_wps_connected(param);
1036 static supplicant_signal_cb supplicant_cbs[SIG_MAX] = {
1037 _supplicant_interface_removed,
1038 _supplicant_properties_changed,
1039 _supplicant_bss_added,
1040 _supplicant_scan_done,
1041 _supplicant_driver_hanged,
1042 _supplicant_session_overlapped,
1043 _supplicant_tdls_connected,
1044 _supplicant_tdls_disconnected,
1045 _supplicant_tdls_peer_found
1048 void register_gdbus_signal(void)
1050 GDBusConnection *connection = NULL;
1051 const char *interface = NULL;
1052 SuppSigArrayIndex sig;
1053 connection = netdbus_get_connection();
1055 if (connection == NULL) {
1056 ERR("Failed to get GDbus Connection");
1060 /* listening to messages from all objects as no path is specified */
1061 /* see signals from the given interface */
1062 conn_subscription_ids[0] = g_dbus_connection_signal_subscribe(
1065 CONNMAN_TECHNOLOGY_INTERFACE,
1069 G_DBUS_SIGNAL_FLAGS_NONE,
1070 _technology_signal_cb,
1074 conn_subscription_ids[1] = g_dbus_connection_signal_subscribe(
1077 CONNMAN_SERVICE_INTERFACE,
1078 CONNMAN_SIGNAL_PROPERTY_CHANGED,
1081 G_DBUS_SIGNAL_FLAGS_NONE,
1086 conn_subscription_ids[2] = g_dbus_connection_signal_subscribe(
1089 DBUS_INTERFACE_DBUS,
1090 CONNMAN_SIGNAL_NAME_CHANGED,
1093 G_DBUS_SIGNAL_FLAGS_NONE,
1094 _dbus_name_changed_cb,
1098 conn_subscription_ids[3] = g_dbus_connection_signal_subscribe(
1101 CONNMAN_MANAGER_INTERFACE,
1102 CONNMAN_SIGNAL_SERVICES_CHANGED,
1105 G_DBUS_SIGNAL_FLAGS_NONE,
1106 _services_changed_cb,
1110 INFO("Successfully register connman DBus signal filters");
1112 conn_subscription_ids[4] = g_dbus_connection_signal_subscribe(
1115 SUPPLICANT_INTERFACE ".Interface.WPS",
1119 G_DBUS_SIGNAL_FLAGS_NONE,
1120 __netconfig_wps_signal_filter_handler,
1124 INFO("Successfully register Supplicant WPS DBus signal filters");
1126 for (sig = SIG_INTERFACE_REMOVED; sig < SIG_MAX; sig++) {
1128 * For SIG_INTERFACE_REMOVED INTERFACE_ADDED
1130 interface = (sig == SIG_INTERFACE_REMOVED) ?
1131 SUPPLICANT_INTERFACE : SUPPLICANT_IFACE_INTERFACE;
1133 supp_subscription_ids[sig] = g_dbus_connection_signal_subscribe(
1137 supplicant_signals[sig],
1140 G_DBUS_SIGNAL_FLAGS_NONE,
1141 supplicant_cbs[sig],
1146 INFO("Successfully register Supplicant DBus signal filters");
1148 #if defined TIZEN_DEBUG_ENABLE
1149 dumpservice_subscription_id = g_dbus_connection_signal_subscribe(
1152 DUMP_SERVICE_INTERFACE,
1156 G_DBUS_SIGNAL_FLAGS_NONE,
1157 __netconfig_dumpservice_handler,
1161 INFO("Successfully registered Dumpservice DBus signal filter");
1164 /* In case ConnMan precedes this signal register,
1165 * net-config should update the default connected profile.
1167 netconfig_update_default();
1170 void deregister_gdbus_signal(void)
1172 GDBusConnection *connection = NULL;
1174 SuppSigArrayIndex sig;
1175 connection = netdbus_get_connection();
1177 ERR("Already de-registered. Nothing to be done");
1181 for (signal = 0; signal < TOTAL_CONN_SIGNALS; signal++) {
1182 if (conn_subscription_ids[signal]) {
1183 g_dbus_connection_signal_unsubscribe(connection,
1184 conn_subscription_ids[signal]);
1188 for (sig = SIG_INTERFACE_REMOVED; sig < SIG_MAX; sig++) {
1189 if (supp_subscription_ids[sig]) {
1190 g_dbus_connection_signal_unsubscribe(connection,
1191 supp_subscription_ids[sig]);
1195 #if defined TIZEN_DEBUG_ENABLE
1196 g_dbus_connection_signal_unsubscribe(connection,
1197 dumpservice_subscription_id);