2 * Network Configuration Module
4 * Copyright (c) 2000 - 2012 Samsung Electronics Co., Ltd. All rights reserved.
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
24 #include <vconf-keys.h>
32 #include "wifi-bssid-scan.h"
33 #include "wifi-agent.h"
34 #include "wifi-power.h"
35 #include "wifi-state.h"
36 #include "netsupplicant.h"
37 #include "network-state.h"
38 #include "cellular-state.h"
39 #include "signal-handler.h"
40 #include "wifi-background-scan.h"
41 #include "wifi-tdls.h"
42 #include "ip-conflict-detect.h"
43 #include "wifi-key-encryption.h"
44 #if defined TIZEN_DEBUG_ENABLE
45 #include "network-dump.h"
46 #define NETWORK_LOG_DUMP_SCRIPT "/opt/var/lib/net-config/network_log_dump.sh"
47 #define MAX_SIZE_ERROR_BUFFER 256
50 #define DBUS_SERVICE_DBUS "org.freedesktop.DBus"
51 #define DBUS_INTERFACE_DBUS "org.freedesktop.DBus"
52 #define SIGNAL_INTERFACE_REMOVED "InterfaceRemoved"
53 #define SIGNAL_SCAN_DONE "ScanDone"
54 #define SIGNAL_BSS_ADDED "BSSAdded"
55 #define SIGNAL_PROPERTIES_CHANGED "PropertiesChanged"
56 #define SIGNAL_PROPERTIES_DRIVER_HANGED "DriverHanged"
57 #define SIGNAL_PROPERTIES_SESSION_OVERLAPPED "SessionOverlapped"
58 #define SIGNAL_TDLS_CONNECTED "TDLSConnected"
59 #define SIGNAL_TDLS_DISCONNECTED "TDLSDisconnected"
60 #define SIGNAL_TDLS_PEER_FOUND "TDLSPeerFound"
62 #define SIGNAL_WPS_CONNECTED "WPSConnected"
63 #define SIGNAL_WPS_EVENT "Event"
64 #define SIGNAL_WPS_CREDENTIALS "Credentials"
66 #define CONNMAN_SIGNAL_SERVICES_CHANGED "ServicesChanged"
67 #define CONNMAN_SIGNAL_PROPERTY_CHANGED "PropertyChanged"
68 #define CONNMAN_SIGNAL_NAME_CHANGED "NameOwnerChanged"
70 #define MAX_SIG_LEN 64
71 #define TOTAL_CONN_SIGNALS 5
72 #define MAX_SOCKET_OPEN_RETRY 5
75 SIG_INTERFACE_REMOVED = 0,
76 SIG_PROPERTIES_CHANGED,
80 SIG_SESSION_OVERLAPPED,
82 SIG_TDLS_DISCONNECTED,
87 static int conn_subscription_ids[TOTAL_CONN_SIGNALS] = {0};
88 static const char supplicant_signals[SIG_MAX][MAX_SIG_LEN] = {
89 SIGNAL_INTERFACE_REMOVED,
90 SIGNAL_PROPERTIES_CHANGED,
93 SIGNAL_PROPERTIES_DRIVER_HANGED,
94 SIGNAL_PROPERTIES_SESSION_OVERLAPPED,
95 SIGNAL_TDLS_CONNECTED,
96 SIGNAL_TDLS_DISCONNECTED,
97 SIGNAL_TDLS_PEER_FOUND,
100 static int supp_subscription_ids[SIG_MAX] = {0};
101 #if defined TIZEN_DEBUG_ENABLE
102 static int dumpservice_subscription_id = 0;
105 typedef void (*supplicant_signal_cb)(GDBusConnection *conn,
106 const gchar *name, const gchar *path, const gchar *interface,
107 const gchar *sig, GVariant *param, gpointer user_data);
108 typedef void (*connman_signal_cb)(GDBusConnection *conn,
109 const gchar *name, const gchar *path, const gchar *interface,
110 const gchar *sig, GVariant *param, gpointer user_data);
112 static void __netconfig_extract_ipv4_signal_data(GVariant *dictionary,
113 const gchar *profile)
116 const gchar *value = NULL;
117 GVariant *var = NULL;
119 GVariantBuilder *builder;
122 g_variant_iter_init(&iter, dictionary);
123 while (g_variant_iter_loop(&iter, "{sv}", &key, &var)) {
124 if (g_strcmp0(key, "Address") == 0) {
125 g_variant_get(var, "&s", &value);
126 char *old_ip = vconf_get_str(VCONFKEY_NETWORK_IP);
128 DBG("Old IPv4.Address [%s] Received new IPv4.Address [%s]", old_ip,
130 if (g_strcmp0(old_ip, value) != 0) {
131 builder = g_variant_builder_new(G_VARIANT_TYPE("a{sv}"));
134 vconf_set_str(VCONFKEY_NETWORK_IP, value);
135 g_variant_builder_add(builder, "{sv}", "IPv4Address",
136 g_variant_new_string(value));
137 } else if (old_ip != NULL && strlen(old_ip) > 0) {
138 vconf_set_str(VCONFKEY_NETWORK_IP, "");
139 g_variant_builder_add(builder, "{sv}", "IPv4Address",
140 g_variant_new_string(""));
143 params = g_variant_new("(@a{sv})",
144 g_variant_builder_end(builder));
146 g_variant_builder_unref(builder);
148 netconfig_dbus_emit_signal(NULL, NETCONFIG_NETWORK_PATH,
149 NETCONFIG_NETWORK_INTERFACE, "NetworkConfigChanged",
157 static void __netconfig_extract_ipv6_signal_data(GVariant *dictionary,
158 const gchar *profile)
161 const gchar *value = NULL;
162 GVariant *var = NULL;
164 GVariantBuilder *builder;
167 g_variant_iter_init(&iter, dictionary);
168 while (g_variant_iter_loop(&iter, "{sv}", &key, &var)) {
169 if (g_strcmp0(key, "Address") == 0) {
170 g_variant_get(var, "&s", &value);
171 char *old_ip6 = vconf_get_str(VCONFKEY_NETWORK_IP6);
173 DBG("Old IPv6.Address [%s] Received new IPv6.Address [%s]", old_ip6,
175 if (g_strcmp0(old_ip6, value) != 0) {
176 builder = g_variant_builder_new(G_VARIANT_TYPE("a{sv}"));
179 vconf_set_str(VCONFKEY_NETWORK_IP6, value);
180 g_variant_builder_add(builder, "{sv}", "IPv6Address",
181 g_variant_new_string(value));
182 } else if (old_ip6 != NULL && strlen(old_ip6) > 0) {
183 vconf_set_str(VCONFKEY_NETWORK_IP6, "");
184 g_variant_builder_add(builder, "{sv}", "IPv6Address",
185 g_variant_new_string(""));
188 params = g_variant_new("(@a{sv})",
189 g_variant_builder_end(builder));
190 g_variant_builder_unref(builder);
192 netconfig_dbus_emit_signal(NULL, NETCONFIG_NETWORK_PATH,
193 NETCONFIG_NETWORK_INTERFACE, "NetworkConfigChanged",
201 #if defined TIZEN_DEBUG_ENABLE
202 static int __netconfig_handle_execute_file(const char *file_path,
203 char *const args[], char *const envs[])
209 register unsigned int index = 0;
210 char error_buf[MAX_SIZE_ERROR_BUFFER] = {0, };
212 while (args[index] != NULL) {
213 DBG("%s", args[index]);
217 if (!(pid = fork())) {
218 DBG("pid(%d), ppid (%d)", getpid(), getppid());
219 DBG("Inside child, exec (%s) command", file_path);
222 if (execve(file_path, args, envs) == -1) {
223 strerror_r(errno, error_buf, MAX_SIZE_ERROR_BUFFER);
224 DBG("Fail to execute command (%s)", error_buf);
227 } else if (pid > 0) {
228 if (waitpid(pid, &status, 0) == -1)
229 DBG("wait pid (%u) status (%d)", pid, status);
231 if (WIFEXITED(status)) {
232 rv = WEXITSTATUS(status);
233 DBG("exited, status=%d", rv);
234 } else if (WIFSIGNALED(status)) {
235 DBG("killed by signal %d", WTERMSIG(status));
236 } else if (WIFSTOPPED(status)) {
237 DBG("stopped by signal %d", WSTOPSIG(status));
238 } else if (WIFCONTINUED(status)) {
245 strerror_r(errno, error_buf, MAX_SIZE_ERROR_BUFFER);
246 DBG("failed to fork(%s)", error_buf);
250 static int _start_dump()
253 gchar *path = NETWORK_LOG_DUMP_SCRIPT;
254 char *const args[] = { NETWORK_LOG_DUMP_SCRIPT, NULL };
255 char *const envs[] = { NULL };
257 rv = __netconfig_handle_execute_file(path, args, envs);
259 ERR("Fail to execute network log dump shell");
266 static void _technology_signal_cb(GDBusConnection *conn,
267 const gchar *name, const gchar *path, const gchar *interface,
268 const gchar *sig, GVariant *param, gpointer user_data)
271 gboolean value = FALSE;
272 GVariant *var = NULL;
277 if (g_str_has_prefix(path, CONNMAN_WIFI_TECHNOLOGY_PREFIX) == TRUE) {
278 g_variant_get(param, "(sv)", &key, &var);
279 if (g_strcmp0(key, "Powered") == 0) {
281 value = g_variant_get_boolean(var);
283 wifi_state_update_power_state(TRUE);
285 wifi_state_update_power_state(FALSE);
286 } else if (g_strcmp0(key, "Connected") == 0) {
287 /* Connection state */
288 value = g_variant_get_boolean(var);
290 wifi_state_set_tech_state(NETCONFIG_WIFI_TECH_CONNECTED);
292 wifi_state_set_tech_state(NETCONFIG_WIFI_TECH_POWERED);
293 } else if (g_strcmp0(key, "Tethering") == 0) {
294 /* Tethering state */
295 wifi_state_set_tech_state(NETCONFIG_WIFI_TECH_TETHERED);
298 g_variant_unref(var);
302 static void _service_signal_cb(GDBusConnection *conn,
303 const gchar *name, const gchar *path,
304 const gchar *interface, const gchar *sig,
305 GVariant *param, gpointer user_data)
307 gchar *sigvalue = NULL;
309 GVariant *variant = NULL, *var;
311 const gchar *value = NULL;
312 struct sock_data *sd = NULL;
315 if (path == NULL || param == NULL)
318 g_variant_get(param, "(sv)", &sigvalue, &variant);
319 if (sigvalue == NULL)
322 if (g_strcmp0(sig, CONNMAN_SIGNAL_PROPERTY_CHANGED) != 0)
325 if (g_strcmp0(sigvalue, "State") == 0) {
326 g_variant_get(variant, "s", &property);
328 DBG("[%s] %s", property, path);
329 if (netconfig_is_wifi_profile(path) || netconfig_is_ethernet_profile(path)) {
330 if (g_strcmp0(property, "ready") == 0) {
331 for (idx = 0; idx < MAX_SOCKET_OPEN_RETRY; idx++) {
332 sd = start_ip_conflict_mon();
336 } else if (g_strcmp0(property, "online") == 0) {
339 stop_ip_conflict_mon();
343 if (netconfig_is_wifi_profile(path) == TRUE) {
346 netconfig_vconf_get_int(VCONFKEY_WIFI_STATE, &wifi_state);
347 if (wifi_state == VCONFKEY_WIFI_OFF) {
352 if (g_strcmp0(property, "ready") == 0 || g_strcmp0(property, "online") == 0) {
353 if (wifi_state >= VCONFKEY_WIFI_CONNECTED) {
358 netconfig_update_default_profile(path);
360 wifi_state_set_service_state(NETCONFIG_WIFI_CONNECTED);
362 } else if (g_strcmp0(property, "failure") == 0 || g_strcmp0(property, "disconnect") == 0 || g_strcmp0(property, "idle") == 0) {
363 if (netconfig_get_default_profile() == NULL ||
364 netconfig_is_wifi_profile(netconfig_get_default_profile())
366 if (g_strcmp0(property, "failure") == 0)
367 wifi_state_set_service_state(NETCONFIG_WIFI_FAILURE);
369 wifi_state_set_service_state(NETCONFIG_WIFI_IDLE);
374 if (g_strcmp0(path, netconfig_get_default_profile()) != 0) {
379 netconfig_update_default_profile(NULL);
381 if (g_strcmp0(property, "failure") == 0)
382 wifi_state_set_service_state(NETCONFIG_WIFI_FAILURE);
384 wifi_state_set_service_state(NETCONFIG_WIFI_IDLE);
386 } else if (g_strcmp0(property, "association") == 0 || g_strcmp0(property, "configuration") == 0) {
387 if (netconfig_get_default_profile() == NULL ||
388 netconfig_is_wifi_profile(netconfig_get_default_profile()) != TRUE) {
389 if (g_strcmp0(property, "association") == 0)
390 wifi_state_set_service_state(NETCONFIG_WIFI_ASSOCIATION);
392 wifi_state_set_service_state(NETCONFIG_WIFI_CONFIGURATION);
397 if (g_strcmp0(path, netconfig_get_default_profile()) != 0) {
402 netconfig_update_default_profile(NULL);
404 if (g_strcmp0(property, "association") == 0)
405 wifi_state_set_service_state(NETCONFIG_WIFI_ASSOCIATION);
407 wifi_state_set_service_state(NETCONFIG_WIFI_CONFIGURATION);
411 if (g_strcmp0(property, "ready") == 0 || g_strcmp0(property, "online") == 0) {
412 if (netconfig_get_default_profile() == NULL) {
413 if (!netconfig_is_cellular_profile(path))
414 netconfig_update_default_profile(path);
416 if (netconfig_is_cellular_internet_profile(path))
417 netconfig_update_default_profile(path);
421 if (netconfig_is_cellular_profile(path) && netconfig_is_cellular_internet_profile(path))
422 cellular_state_set_service_state(NETCONFIG_CELLULAR_ONLINE);
424 } else if (g_strcmp0(property, "failure") == 0 || g_strcmp0(property, "disconnect") == 0 || g_strcmp0(property, "idle") == 0) {
425 if (netconfig_get_default_profile() == NULL) {
430 if (netconfig_is_cellular_profile(path) && netconfig_is_cellular_internet_profile(path))
431 cellular_state_set_service_state(NETCONFIG_CELLULAR_IDLE);
433 if (g_strcmp0(path, netconfig_get_default_profile()) != 0) {
438 netconfig_update_default_profile(NULL);
439 } else if (g_strcmp0(property, "association") == 0 || g_strcmp0(property, "configuration") == 0) {
440 if (netconfig_get_default_profile() == NULL) {
445 if (netconfig_is_cellular_profile(path) && netconfig_is_cellular_internet_profile(path))
446 cellular_state_set_service_state(NETCONFIG_CELLULAR_CONNECTING);
448 if (g_strcmp0(path, netconfig_get_default_profile()) != 0) {
453 netconfig_update_default_profile(NULL);
457 } else if (g_strcmp0(sigvalue, "Proxy") == 0) {
458 if (netconfig_is_wifi_profile(path) != TRUE || g_strcmp0(path, netconfig_get_default_profile()) != 0)
461 if (!g_variant_is_of_type(variant, G_VARIANT_TYPE_ARRAY))
464 g_variant_get(variant, "a{sv}", &iter);
465 while (g_variant_iter_loop(iter, "{sv}", &property, &var)) {
466 GVariantBuilder *builder;
467 GVariant *sig_params;
468 if (g_strcmp0(property, "Servers") == 0) {
469 GVariantIter *iter_sub = NULL;
471 builder = g_variant_builder_new(G_VARIANT_TYPE("a{sv}"));
473 g_variant_get(var, "as", &iter_sub);
474 g_variant_iter_loop(iter_sub, "s", &value);
475 g_variant_iter_free(iter_sub);
477 DBG("Proxy - [%s]", value);
478 vconf_set_str(VCONFKEY_NETWORK_PROXY, value);
480 g_variant_builder_add(builder, "{sv}", "ProxyAddress",
481 g_variant_new_string(value));
483 sig_params = g_variant_new("(@a{sv})",
484 g_variant_builder_end(builder));
485 g_variant_builder_unref(builder);
487 netconfig_dbus_emit_signal(NULL, NETCONFIG_NETWORK_PATH,
488 NETCONFIG_NETWORK_INTERFACE, "NetworkConfigChanged",
492 g_variant_unref(var);
494 } else if (g_strcmp0(property, "Method") == 0) {
495 value = g_variant_get_string(var, NULL);
496 DBG("Method - [%s]", value);
498 if (g_strcmp0(value, "direct") == 0) {
499 builder = g_variant_builder_new(G_VARIANT_TYPE("a{sv}"));
501 vconf_set_str(VCONFKEY_NETWORK_PROXY, "");
502 g_variant_builder_add(builder, "{sv}", "ProxyAddress",
503 g_variant_new_string(""));
505 sig_params = g_variant_new("(@a{sv})",
506 g_variant_builder_end(builder));
507 g_variant_builder_unref(builder);
509 netconfig_dbus_emit_signal(NULL, NETCONFIG_NETWORK_PATH,
510 NETCONFIG_NETWORK_INTERFACE,
511 "NetworkConfigChanged", sig_params);
515 g_variant_unref(var);
520 g_variant_iter_free(iter);
521 } else if (g_strcmp0(sigvalue, "IPv4") == 0) {
522 __netconfig_extract_ipv4_signal_data(variant, path);
523 } else if (g_strcmp0(sigvalue, "IPv6") == 0) {
524 __netconfig_extract_ipv6_signal_data(variant, path);
525 } else if (g_strcmp0(sigvalue, "Error") == 0) {
526 g_variant_get(variant, "s", &property);
527 INFO("[%s] Property : %s", sigvalue, property);
528 #if defined TIZEN_DEBUG_ENABLE
529 if (g_strcmp0(property, "dhcp-failed") == 0
530 || g_strcmp0(property, "connect-failed") == 0
531 || g_strcmp0(property, "login-failed") == 0
532 || g_strcmp0(property, "auth-failed") == 0
533 || g_strcmp0(property, "invalid-key") == 0) {
545 g_variant_unref(variant);
550 static void _dbus_name_changed_cb(GDBusConnection *conn,
551 const gchar *Name, const gchar *path, const gchar *interface,
552 const gchar *sig, GVariant *param, gpointer user_data)
561 g_variant_get(param, "(sss)", &name, &old, &new);
563 if (g_strcmp0(name, CONNMAN_SERVICE) == 0 && *new == '\0') {
564 DBG("ConnMan destroyed: name %s, old %s, new %s", name, old, new);
566 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 _find_service_and_set_passphrase(char *ssid, char *key)
943 GVariant *reply = NULL;
948 gchar *enc_passphrase;
950 ssid_len = strlen(ssid);
952 str = g_string_sized_new((ssid_len * 2) + 55);
956 dev_mac_addr = vconf_get_str(VCONFKEY_WIFI_BSSID_ADDRESS);
958 ERR("Failed to get mac address from vconf key");
959 g_string_free(str, TRUE);
964 for (i = 0; dev_mac_addr[i]; i++) {
965 if (dev_mac_addr[i] != ':')
966 ident[j++] = dev_mac_addr[i];
970 g_string_append_printf(str, "%s%s_", CONNMAN_WIFI_SERVICE_PROFILE_PREFIX,
974 for (i = 0; i < ssid_len; i++) {
976 g_string_append_printf(str, "%02x", ssid[i]);
979 g_string_append_printf(str, "_managed_psk");
981 service_path = g_string_free(str, FALSE);
983 enc_passphrase = _netconfig_encrypt_passphrase(key);
984 if (!enc_passphrase) {
985 ERR("Failed to encrypt passphrase");
986 g_free(service_path);
990 INFO("wps service_path %s Passphrase %s", service_path, enc_passphrase);
992 reply = netconfig_invoke_dbus_method(CONNMAN_SERVICE, service_path,
993 CONNMAN_SERVICE_INTERFACE, "SetProperty",
994 g_variant_new("(sv)", "Passphrase",
995 g_variant_new_string(enc_passphrase)));
997 g_variant_unref(reply);
999 ERR("Failed to set passphrase");
1001 g_free(service_path);
1006 static void _supplicant_wifi_wps_credentials(GVariant *param)
1009 char ssid[32] = {0, };
1010 char wps_key[100] = {0, };
1013 int config_error = 0;
1014 int error_indication = 0;
1016 char *key_mgmt = NULL;
1018 if (param == NULL) {
1019 ERR("Param is NULL");
1023 g_variant_get(param, "(a{sv})", &iter);
1024 while (g_variant_iter_loop(iter, "{sv}", &key, &variant)) {
1027 INFO("wps Key is %s", key);
1028 if (g_strcmp0(key, "Key") == 0) {
1030 const char *t_key = NULL;
1031 key_len = g_variant_get_size(variant);
1033 INFO("wps password len %d ", key_len);
1035 t_key = g_variant_get_fixed_array(variant, &key_len,
1039 g_variant_unref(variant);
1042 strncpy(wps_key, t_key, key_len);
1043 wps_key[key_len] = '\0';
1044 INFO("WPS Key in process credentials %s", wps_key);
1046 SLOGI("WPS AP Security ->Open");
1047 } else if (g_strcmp0(key, "SSID") == 0) {
1048 const char *t_key = NULL;
1049 t_key = g_variant_get_fixed_array(variant, &ssid_len,
1051 INFO("wps ssid_len is %d ", ssid_len);
1054 g_variant_unref(variant);
1057 if (ssid_len > 0 && ssid_len <= 32) {
1058 memcpy(ssid, t_key, ssid_len);
1060 memset(ssid, 0, sizeof(ssid));
1063 INFO("SSID in process credentials %s", ssid);
1064 } else if (g_strcmp0(key, "AuthType") == 0) {
1066 GVariantIter *var_iter;
1067 g_variant_get(variant, "as", &var_iter);
1068 while (g_variant_iter_loop(var_iter, "s", &auth_type)) {
1069 INFO("wps auth_type %s", auth_type);
1070 if (g_strcmp0(auth_type, "wpa-psk") == 0 ||
1071 g_strcmp0(auth_type, "wpa2-psk") == 0)
1073 else if (g_strcmp0(auth_type, "open") == 0)
1076 g_variant_iter_free(var_iter);
1077 } else if (g_strcmp0(key, "EncrType") == 0) {
1079 GVariantIter *var_iter;
1080 g_variant_get(variant, "as", &var_iter);
1081 while (g_variant_iter_loop(var_iter, "s", &encr_type))
1082 INFO("wps encr_type %s", encr_type);
1083 g_variant_iter_free(var_iter);
1084 } else if (g_strcmp0(key, "BSSID") == 0) {
1085 const guchar *bssid;
1087 bssid = g_variant_get_fixed_array(variant, &bssid_len,
1089 if (bssid && bssid_len == 6)
1090 INFO("wps BSSID %2x:%2x:%2x:%2x:%2x:%2x", bssid[0], bssid[1],
1091 bssid[2], bssid[3], bssid[4], bssid[5]);
1095 g_variant_iter_free(iter);
1097 if (g_strcmp0(key_mgmt, "psk") == 0)
1098 _find_service_and_set_passphrase(ssid, wps_key);
1102 * Notify WPS Credentials only when requested through WPS PBC
1103 * In case of WPS PIN connman will take care of notification
1105 if (netconfig_get_wps_field() == TRUE)
1107 netconfig_wifi_notify_wps_credentials(ssid, ssid_len, wps_key);
1111 g_variant_iter_free(iter);
1112 error_indication = WPS_EI_OPERATION_FAILED;
1113 config_error = WPS_CFG_NO_ERROR;
1114 ERR("Error Occured! Notifying Fail Event");
1115 netconfig_wifi_notify_wps_fail_event(config_error, error_indication);
1118 static void __netconfig_wps_signal_filter_handler(GDBusConnection *conn,
1119 const gchar *name, const gchar *path, const gchar *interface,
1120 const gchar *sig, GVariant *param, gpointer user_data)
1122 if (g_strcmp0(sig, SIGNAL_WPS_CREDENTIALS) == 0) {
1123 INFO("Received wps CREDENTIALS Signal from Supplicant");
1124 _supplicant_wifi_wps_credentials(param);
1125 } else if (g_strcmp0(sig, SIGNAL_WPS_EVENT) == 0) {
1126 INFO("Received wps EVENT Signal from Supplicant");
1127 _supplicant_wifi_wps_event(param);
1128 } else if (g_strcmp0(sig, SIGNAL_WPS_CONNECTED) == 0) {
1129 INFO("Received WPSConnected Signal from Supplicant");
1130 _supplicant_wifi_wps_connected(param);
1136 static supplicant_signal_cb supplicant_cbs[SIG_MAX] = {
1137 _supplicant_interface_removed,
1138 _supplicant_properties_changed,
1139 _supplicant_bss_added,
1140 _supplicant_scan_done,
1141 _supplicant_driver_hanged,
1142 _supplicant_session_overlapped,
1143 _supplicant_tdls_connected,
1144 _supplicant_tdls_disconnected,
1145 _supplicant_tdls_peer_found
1148 void register_gdbus_signal(void)
1150 GDBusConnection *connection = NULL;
1151 const char *interface = NULL;
1152 SuppSigArrayIndex sig;
1153 connection = netdbus_get_connection();
1155 if (connection == NULL) {
1156 ERR("Failed to get GDbus Connection");
1160 /* listening to messages from all objects as no path is specified */
1161 /* see signals from the given interface */
1162 conn_subscription_ids[0] = g_dbus_connection_signal_subscribe(
1165 CONNMAN_TECHNOLOGY_INTERFACE,
1169 G_DBUS_SIGNAL_FLAGS_NONE,
1170 _technology_signal_cb,
1174 conn_subscription_ids[1] = g_dbus_connection_signal_subscribe(
1177 CONNMAN_SERVICE_INTERFACE,
1178 CONNMAN_SIGNAL_PROPERTY_CHANGED,
1181 G_DBUS_SIGNAL_FLAGS_NONE,
1186 conn_subscription_ids[2] = g_dbus_connection_signal_subscribe(
1189 DBUS_INTERFACE_DBUS,
1190 CONNMAN_SIGNAL_NAME_CHANGED,
1193 G_DBUS_SIGNAL_FLAGS_NONE,
1194 _dbus_name_changed_cb,
1198 conn_subscription_ids[3] = g_dbus_connection_signal_subscribe(
1201 CONNMAN_MANAGER_INTERFACE,
1202 CONNMAN_SIGNAL_SERVICES_CHANGED,
1205 G_DBUS_SIGNAL_FLAGS_NONE,
1206 _services_changed_cb,
1210 INFO("Successfully register connman DBus signal filters");
1212 conn_subscription_ids[4] = g_dbus_connection_signal_subscribe(
1215 SUPPLICANT_INTERFACE ".Interface.WPS",
1219 G_DBUS_SIGNAL_FLAGS_NONE,
1220 __netconfig_wps_signal_filter_handler,
1224 INFO("Successfully register Supplicant WPS DBus signal filters");
1226 for (sig = SIG_INTERFACE_REMOVED; sig < SIG_MAX; sig++) {
1228 * For SIG_INTERFACE_REMOVED INTERFACE_ADDED
1230 interface = (sig == SIG_INTERFACE_REMOVED) ?
1231 SUPPLICANT_INTERFACE : SUPPLICANT_IFACE_INTERFACE;
1233 supp_subscription_ids[sig] = g_dbus_connection_signal_subscribe(
1237 supplicant_signals[sig],
1240 G_DBUS_SIGNAL_FLAGS_NONE,
1241 supplicant_cbs[sig],
1246 INFO("Successfully register Supplicant DBus signal filters");
1248 #if defined TIZEN_DEBUG_ENABLE
1249 dumpservice_subscription_id = g_dbus_connection_signal_subscribe(
1252 DUMP_SERVICE_INTERFACE,
1256 G_DBUS_SIGNAL_FLAGS_NONE,
1257 __netconfig_dumpservice_handler,
1261 INFO("Successfully registered Dumpservice DBus signal filter");
1264 /* In case ConnMan precedes this signal register,
1265 * net-config should update the default connected profile.
1267 netconfig_update_default();
1270 void deregister_gdbus_signal(void)
1272 GDBusConnection *connection = NULL;
1274 SuppSigArrayIndex sig;
1275 connection = netdbus_get_connection();
1277 ERR("Already de-registered. Nothing to be done");
1281 for (signal = 0; signal < TOTAL_CONN_SIGNALS; signal++) {
1282 if (conn_subscription_ids[signal]) {
1283 g_dbus_connection_signal_unsubscribe(connection,
1284 conn_subscription_ids[signal]);
1288 for (sig = SIG_INTERFACE_REMOVED; sig < SIG_MAX; sig++) {
1289 if (supp_subscription_ids[sig]) {
1290 g_dbus_connection_signal_unsubscribe(connection,
1291 supp_subscription_ids[sig]);
1295 #if defined TIZEN_DEBUG_ENABLE
1296 g_dbus_connection_signal_unsubscribe(connection,
1297 dumpservice_subscription_id);