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 netconfig_dbus_emit_signal(NULL, NETCONFIG_NETWORK_PATH,
147 NETCONFIG_NETWORK_INTERFACE, "NetworkConfigChanged",
155 static void __netconfig_extract_ipv6_signal_data(GVariant *dictionary,
156 const gchar *profile)
159 const gchar *value = NULL;
160 GVariant *var = NULL;
162 GVariantBuilder *builder;
165 g_variant_iter_init(&iter, dictionary);
166 while (g_variant_iter_loop(&iter, "{sv}", &key, &var)) {
167 if (g_strcmp0(key, "Address") == 0) {
168 g_variant_get(var, "&s", &value);
169 char *old_ip6 = vconf_get_str(VCONFKEY_NETWORK_IP6);
171 DBG("Old IPv6.Address [%s] Received new IPv6.Address [%s]", old_ip6,
173 if (g_strcmp0(old_ip6, value) != 0) {
174 builder = g_variant_builder_new(G_VARIANT_TYPE("a{sv}"));
177 vconf_set_str(VCONFKEY_NETWORK_IP6, value);
178 g_variant_builder_add(builder, "{sv}", "IPv6Address",
179 g_variant_new_string(value));
180 } else if (old_ip6 != NULL && strlen(old_ip6) > 0) {
181 vconf_set_str(VCONFKEY_NETWORK_IP6, "");
182 g_variant_builder_add(builder, "{sv}", "IPv6Address",
183 g_variant_new_string(""));
186 params = g_variant_new("(@a{sv})",
187 g_variant_builder_end(builder));
189 netconfig_dbus_emit_signal(NULL, NETCONFIG_NETWORK_PATH,
190 NETCONFIG_NETWORK_INTERFACE, "NetworkConfigChanged",
198 #if defined TIZEN_DEBUG_ENABLE
199 static int __netconfig_handle_execute_file(const char *file_path,
200 char *const args[], char *const envs[])
206 register unsigned int index = 0;
207 char error_buf[MAX_SIZE_ERROR_BUFFER] = {0, };
209 while (args[index] != NULL) {
210 DBG("%s", args[index]);
214 if (!(pid = fork())) {
215 DBG("pid(%d), ppid (%d)", getpid(), getppid());
216 DBG("Inside child, exec (%s) command", file_path);
219 if (execve(file_path, args, envs) == -1) {
220 strerror_r(errno, error_buf, MAX_SIZE_ERROR_BUFFER);
221 DBG("Fail to execute command (%s)", error_buf);
224 } else if (pid > 0) {
225 if (waitpid(pid, &status, 0) == -1)
226 DBG("wait pid (%u) status (%d)", pid, status);
228 if (WIFEXITED(status)) {
229 rv = WEXITSTATUS(status);
230 DBG("exited, status=%d", rv);
231 } else if (WIFSIGNALED(status)) {
232 DBG("killed by signal %d", WTERMSIG(status));
233 } else if (WIFSTOPPED(status)) {
234 DBG("stopped by signal %d", WSTOPSIG(status));
235 } else if (WIFCONTINUED(status)) {
242 strerror_r(errno, error_buf, MAX_SIZE_ERROR_BUFFER);
243 DBG("failed to fork(%s)", error_buf);
247 static int _start_dump()
250 gchar *path = NETWORK_LOG_DUMP_SCRIPT;
251 char *const args[] = { NETWORK_LOG_DUMP_SCRIPT, NULL };
252 char *const envs[] = { NULL };
254 rv = __netconfig_handle_execute_file(path, args, envs);
256 ERR("Fail to execute network log dump shell");
263 static void _technology_signal_cb(GDBusConnection *conn,
264 const gchar *name, const gchar *path, const gchar *interface,
265 const gchar *sig, GVariant *param, gpointer user_data)
268 gboolean value = FALSE;
269 GVariant *var = NULL;
274 if (g_str_has_prefix(path, CONNMAN_WIFI_TECHNOLOGY_PREFIX) == TRUE) {
275 g_variant_get(param, "(sv)", &key, &var);
276 if (g_strcmp0(key, "Powered") == 0) {
278 value = g_variant_get_boolean(var);
280 wifi_state_update_power_state(TRUE);
282 wifi_state_update_power_state(FALSE);
283 } else if (g_strcmp0(key, "Connected") == 0) {
284 /* Connection state */
285 value = g_variant_get_boolean(var);
287 wifi_state_set_tech_state(NETCONFIG_WIFI_TECH_CONNECTED);
289 wifi_state_set_tech_state(NETCONFIG_WIFI_TECH_POWERED);
290 } else if (g_strcmp0(key, "Tethering") == 0) {
291 /* Tethering state */
292 wifi_state_set_tech_state(NETCONFIG_WIFI_TECH_TETHERED);
295 g_variant_unref(var);
299 static void _service_signal_cb(GDBusConnection *conn,
300 const gchar *name, const gchar *path,
301 const gchar *interface, const gchar *sig,
302 GVariant *param, gpointer user_data)
304 gchar *sigvalue = NULL;
306 GVariant *variant = NULL, *var;
308 const gchar *value = NULL;
309 struct sock_data *sd = NULL;
312 if (path == NULL || param == NULL)
315 g_variant_get(param, "(sv)", &sigvalue, &variant);
316 if (sigvalue == NULL)
319 if (g_strcmp0(sig, CONNMAN_SIGNAL_PROPERTY_CHANGED) != 0)
322 if (g_strcmp0(sigvalue, "State") == 0) {
323 g_variant_get(variant, "s", &property);
325 DBG("[%s] %s", property, path);
326 if (netconfig_is_wifi_profile(path) || netconfig_is_ethernet_profile(path)) {
327 if (g_strcmp0(property, "ready") == 0) {
328 for (idx = 0; idx < MAX_SOCKET_OPEN_RETRY; idx++) {
329 sd = start_ip_conflict_mon();
333 } else if (g_strcmp0(property, "online") == 0) {
336 stop_ip_conflict_mon();
340 if (netconfig_is_wifi_profile(path) == TRUE) {
343 netconfig_vconf_get_int(VCONFKEY_WIFI_STATE, &wifi_state);
344 if (wifi_state == VCONFKEY_WIFI_OFF) {
349 if (g_strcmp0(property, "ready") == 0 || g_strcmp0(property, "online") == 0) {
350 if (wifi_state >= VCONFKEY_WIFI_CONNECTED) {
355 netconfig_update_default_profile(path);
357 wifi_state_set_service_state(NETCONFIG_WIFI_CONNECTED);
359 } else if (g_strcmp0(property, "failure") == 0 || g_strcmp0(property, "disconnect") == 0 || g_strcmp0(property, "idle") == 0) {
360 if (netconfig_get_default_profile() == NULL ||
361 netconfig_is_wifi_profile(netconfig_get_default_profile())
363 if (g_strcmp0(property, "failure") == 0)
364 wifi_state_set_service_state(NETCONFIG_WIFI_FAILURE);
366 wifi_state_set_service_state(NETCONFIG_WIFI_IDLE);
371 if (g_strcmp0(path, netconfig_get_default_profile()) != 0) {
376 netconfig_update_default_profile(NULL);
378 if (g_strcmp0(property, "failure") == 0)
379 wifi_state_set_service_state(NETCONFIG_WIFI_FAILURE);
381 wifi_state_set_service_state(NETCONFIG_WIFI_IDLE);
383 } else if (g_strcmp0(property, "association") == 0 || g_strcmp0(property, "configuration") == 0) {
384 if (netconfig_get_default_profile() == NULL ||
385 netconfig_is_wifi_profile(netconfig_get_default_profile()) != TRUE) {
386 if (g_strcmp0(property, "association") == 0)
387 wifi_state_set_service_state(NETCONFIG_WIFI_ASSOCIATION);
389 wifi_state_set_service_state(NETCONFIG_WIFI_CONFIGURATION);
394 if (g_strcmp0(path, netconfig_get_default_profile()) != 0) {
399 netconfig_update_default_profile(NULL);
401 if (g_strcmp0(property, "association") == 0)
402 wifi_state_set_service_state(NETCONFIG_WIFI_ASSOCIATION);
404 wifi_state_set_service_state(NETCONFIG_WIFI_CONFIGURATION);
408 if (g_strcmp0(property, "ready") == 0 || g_strcmp0(property, "online") == 0) {
409 if (netconfig_get_default_profile() == NULL) {
410 if (!netconfig_is_cellular_profile(path))
411 netconfig_update_default_profile(path);
413 if (netconfig_is_cellular_internet_profile(path))
414 netconfig_update_default_profile(path);
418 if (netconfig_is_cellular_profile(path) && netconfig_is_cellular_internet_profile(path))
419 cellular_state_set_service_state(NETCONFIG_CELLULAR_ONLINE);
421 } else if (g_strcmp0(property, "failure") == 0 || g_strcmp0(property, "disconnect") == 0 || g_strcmp0(property, "idle") == 0) {
422 if (netconfig_get_default_profile() == NULL) {
427 if (netconfig_is_cellular_profile(path) && netconfig_is_cellular_internet_profile(path))
428 cellular_state_set_service_state(NETCONFIG_CELLULAR_IDLE);
430 if (g_strcmp0(path, netconfig_get_default_profile()) != 0) {
435 netconfig_update_default_profile(NULL);
436 } else if (g_strcmp0(property, "association") == 0 || g_strcmp0(property, "configuration") == 0) {
437 if (netconfig_get_default_profile() == NULL) {
442 if (netconfig_is_cellular_profile(path) && netconfig_is_cellular_internet_profile(path))
443 cellular_state_set_service_state(NETCONFIG_CELLULAR_CONNECTING);
445 if (g_strcmp0(path, netconfig_get_default_profile()) != 0) {
450 netconfig_update_default_profile(NULL);
454 } else if (g_strcmp0(sigvalue, "Proxy") == 0) {
455 if (netconfig_is_wifi_profile(path) != TRUE || g_strcmp0(path, netconfig_get_default_profile()) != 0)
458 if (!g_variant_type_equal(variant, G_VARIANT_TYPE_ARRAY))
461 g_variant_get(variant, "a{sv}", &iter);
462 while (g_variant_iter_loop(iter, "{sv}", &property, &var)) {
463 GVariantBuilder *builder;
464 GVariant *sig_params;
465 if (g_strcmp0(property, "Servers") == 0) {
466 GVariantIter *iter_sub = NULL;
468 builder = g_variant_builder_new(G_VARIANT_TYPE("a{sv}"));
470 g_variant_get(var, "as", &iter_sub);
471 g_variant_iter_loop(iter_sub, "s", &value);
472 g_variant_iter_free(iter_sub);
474 DBG("Proxy - [%s]", value);
475 vconf_set_str(VCONFKEY_NETWORK_PROXY, value);
477 g_variant_builder_add(builder, "{sv}", "ProxyAddress",
478 g_variant_new_string(value));
480 sig_params = g_variant_new("(@a{sv})",
481 g_variant_builder_end(builder));
483 netconfig_dbus_emit_signal(NULL, NETCONFIG_NETWORK_PATH,
484 NETCONFIG_NETWORK_INTERFACE, "NetworkConfigChanged",
488 g_variant_unref(var);
490 } else if (g_strcmp0(property, "Method") == 0) {
491 value = g_variant_get_string(var, NULL);
492 DBG("Method - [%s]", value);
494 if (g_strcmp0(value, "direct") == 0) {
495 builder = g_variant_builder_new(G_VARIANT_TYPE("a{sv}"));
497 vconf_set_str(VCONFKEY_NETWORK_PROXY, "");
498 g_variant_builder_add(builder, "{sv}", "ProxyAddress",
499 g_variant_new_string(""));
501 sig_params = g_variant_new("(@a{sv})",
502 g_variant_builder_end(builder));
504 netconfig_dbus_emit_signal(NULL, NETCONFIG_NETWORK_PATH,
505 NETCONFIG_NETWORK_INTERFACE,
506 "NetworkConfigChanged", sig_params);
510 g_variant_unref(var);
515 g_variant_iter_free(iter);
516 } else if (g_strcmp0(sigvalue, "IPv4") == 0) {
517 __netconfig_extract_ipv4_signal_data(variant, path);
518 } else if (g_strcmp0(sigvalue, "IPv6") == 0) {
519 __netconfig_extract_ipv6_signal_data(variant, path);
520 } else if (g_strcmp0(sigvalue, "Error") == 0) {
521 g_variant_get(variant, "s", &property);
522 INFO("[%s] Property : %s", sigvalue, property);
523 #if defined TIZEN_DEBUG_ENABLE
524 if (g_strcmp0(property, "dhcp-failed") == 0
525 || g_strcmp0(property, "connect-failed") == 0
526 || g_strcmp0(property, "login-failed") == 0
527 || g_strcmp0(property, "auth-failed") == 0
528 || g_strcmp0(property, "invalid-key") == 0) {
540 g_variant_unref(variant);
545 static void _dbus_name_changed_cb(GDBusConnection *conn,
546 const gchar *Name, const gchar *path, const gchar *interface,
547 const gchar *sig, GVariant *param, gpointer user_data)
556 g_variant_get(param, "(sss)", &name, &old, &new);
558 if (g_strcmp0(name, CONNMAN_SERVICE) == 0 && *new == '\0') {
559 DBG("ConnMan destroyed: name %s, old %s, new %s", name, old, new);
561 connman_register_agent();
570 static void _services_changed_cb(GDBusConnection *conn, const gchar *name,
571 const gchar *path, const gchar *interface, const gchar *sig,
572 GVariant *param, gpointer user_data)
574 gchar *property, *value;
576 GVariant *variant = NULL;
577 GVariantIter *added = NULL, *removed = NULL, *next = NULL;
579 if (path == NULL || param == NULL)
582 if (g_strcmp0(sig, CONNMAN_SIGNAL_SERVICES_CHANGED) != 0)
585 if (netconfig_get_default_profile() != NULL)
588 g_variant_get(param, "(a(oa{sv})ao)", &added, &removed);
590 while (g_variant_iter_loop(added, "(oa{sv})", &service_path, &next)) {
591 gboolean is_wifi_prof, is_cell_prof, is_cell_internet_prof;
592 is_wifi_prof = netconfig_is_wifi_profile(service_path);
593 is_cell_prof = netconfig_is_cellular_profile(service_path);
594 is_cell_internet_prof = netconfig_is_cellular_internet_profile(
596 if (service_path != NULL) {
597 while (next && g_variant_iter_loop(next, "{sv}", &property,
599 if (g_strcmp0(property, "State") == 0) {
600 g_variant_get(variant, "s", &value);
601 DBG("Profile %s State %s", service_path,
603 if (g_strcmp0(value, "ready") != 0 &&
608 g_variant_unref(variant);
613 netconfig_update_default_profile(
615 else if (is_cell_internet_prof) {
616 netconfig_update_default_profile(
620 wifi_state_set_service_state(
621 NETCONFIG_WIFI_CONNECTED);
622 else if (is_cell_prof &&
623 is_cell_internet_prof)
624 cellular_state_set_service_state(
625 NETCONFIG_CELLULAR_ONLINE);
628 g_variant_unref(variant);
635 g_variant_iter_free(added);
638 g_variant_iter_free(next);
641 g_variant_iter_free(removed);
646 static void _supplicant_interface_removed(GDBusConnection *conn,
647 const gchar *name, const gchar *path, const gchar *interface,
648 const gchar *sig, GVariant *param, gpointer user_data)
650 DBG("Interface removed handling!");
651 if (netconfig_wifi_is_bssid_scan_started() == TRUE)
652 netconfig_wifi_bssid_signal_scanaborted();
657 static void _supplicant_properties_changed(GDBusConnection *conn,
658 const gchar *name, const gchar *path, const gchar *interface,
659 const gchar *sig, GVariant *param, gpointer user_data)
661 DBG("Properties changed handling!");
663 const gchar *state = NULL;
664 GVariantIter *iter = NULL;
665 GVariant *variant = NULL;
666 gboolean scanning = FALSE;
671 g_variant_get(param, "(a{sv})", &iter);
672 while (g_variant_iter_loop(iter, "{sv}", &key, &variant)) {
673 if (g_strcmp0(key, "Scanning") == 0) {
674 scanning = g_variant_get_boolean(variant);
675 DBG("setting scanning %s", scanning ? "TRUE" : "FALSE");
676 if (scanning == TRUE)
677 netconfig_wifi_set_scanning(TRUE);
679 netconfig_wifi_set_scanning(FALSE);
681 g_variant_unref(variant);
686 } else if (g_strcmp0(key, "State") == 0) {
687 state = g_variant_get_string(variant, NULL);
689 ERR("Supplicant state : %s", state);
691 g_variant_unref(variant);
696 } else if (g_strcmp0(key, "DisconnectReason") == 0) {
697 int reason = g_variant_get_int32(variant);
698 ERR("Supplicant DisconnReason : %d", reason);
700 g_variant_unref(variant);
707 value = g_variant_print(variant, TRUE);
708 DBG("Supplicant %s : %s", key, value);
714 g_variant_iter_free(iter);
719 static void _supplicant_bss_added(GDBusConnection *conn,
720 const gchar *name, const gchar *path, const gchar *interface,
721 const gchar *sig, GVariant *param, gpointer user_data)
723 DBG("BSS added handling!");
724 wifi_state_set_bss_found(TRUE);
729 static void _supplicant_scan_done(GDBusConnection *conn,
730 const gchar *name, const gchar *path, const gchar *interface,
731 const gchar *sig, GVariant *param, gpointer user_data)
733 DBG("Scan Done handling!");
734 netconfig_wifi_set_scanning(FALSE);
736 if (netconfig_wifi_is_bssid_scan_started() == TRUE) {
737 netconfig_wifi_bssid_signal_scandone();
738 if (wifi_state_get_technology_state() < NETCONFIG_WIFI_TECH_POWERED)
742 if (netconfig_wifi_get_bgscan_state() == TRUE) {
743 if (wifi_state_get_technology_state() >=
744 NETCONFIG_WIFI_TECH_POWERED)
745 netconfig_wifi_bgscan_start(FALSE);
747 wifi_start_timer_network_notification();
753 static void _supplicant_driver_hanged(GDBusConnection *conn,
754 const gchar *name, const gchar *path, const gchar *interface,
755 const gchar *sig, GVariant *param, gpointer user_data)
757 DBG("Driver Hanged handling!");
758 ERR("Critical. Wi-Fi firmware crashed");
760 #if !defined TIZEN_WEARABLE
761 netconfig_send_message_to_net_popup("Wi-Fi Error",
762 "Wi-Fi Driver Hanged. Please get log dump and report", "popup", NULL);
764 wifi_power_recover_firmware();
770 static void _supplicant_session_overlapped(GDBusConnection *conn,
771 const gchar *name, const gchar *path, const gchar *interface,
772 const gchar *sig, GVariant *param, gpointer user_data)
774 DBG("Driver session overlapped handling!");
775 ERR("WPS PBC SESSION OVERLAPPED");
776 #if defined TIZEN_WEARABLE
779 netconfig_send_message_to_net_popup("WPS Error",
780 "wps session overlapped", "popup", NULL);
784 #if defined TIZEN_DEBUG_ENABLE
785 static void __netconfig_dumpservice_handler(GDBusConnection *conn,
786 const gchar *name, const gchar *path, const gchar *interface,
787 const gchar *sig, GVariant *param, gpointer user_data)
790 gchar *signal_path = NULL;
795 g_variant_get(param, "(is)", &mode, &signal_path);
796 DBG("Path: %s and mode: %d", signal_path, mode);
798 netconfig_dump_log(signal_path);
806 static void _supplicant_tdls_connected(GDBusConnection *conn,
807 const gchar *name, const gchar *path, const gchar *interface,
808 const gchar *sig, GVariant *param, gpointer user_data)
810 DBG("Received TDLS Connected Signal");
811 netconfig_wifi_tdls_connected_event(param);
816 static void _supplicant_tdls_disconnected(GDBusConnection *conn,
817 const gchar *name, const gchar *path, const gchar *interface,
818 const gchar *sig, GVariant *param, gpointer user_data)
820 DBG("Received TDLS Disconnected Signal");
821 netconfig_wifi_tdls_disconnected_event(param);
826 static void _supplicant_tdls_peer_found(GDBusConnection *conn,
827 const gchar *name, const gchar *path, const gchar *interface,
828 const gchar *sig, GVariant *param, gpointer user_data)
830 DBG("Received TDLS Peer Found Signal");
831 netconfig_wifi_tdls_peer_found_event(param);
835 static void _supplicant_wifi_wps_connected(GVariant *param)
838 char ssid[32] = {0, };
842 int config_error = 0;
843 int error_indication = 0;
847 ERR("Param is NULL");
851 g_variant_get(param, "(sa{sv})", &name, &iter);
852 INFO("wps Result: %s", name);
853 while (g_variant_iter_loop(iter, "{sv}", &key, &variant)) {
854 INFO("wps Key is %s", key);
855 if (g_strcmp0(key, "SSID") == 0) {
856 const char *t_key = NULL;
857 t_key = g_variant_get_fixed_array(variant, &ssid_len, sizeof(guchar));
858 INFO("wps ssid_len is %d ", ssid_len);
861 g_variant_unref(variant);
862 ERR("WPS PBC Connection Failed");
865 if (ssid_len > 0 && ssid_len <= 32) {
866 memcpy(ssid, t_key, ssid_len);
868 memset(ssid, 0, sizeof(ssid));
871 INFO("WPS PBC Connection completed with AP %s", ssid);
872 netconfig_wifi_notify_wps_completed(ssid, ssid_len);
876 g_variant_iter_free(iter);
881 g_variant_iter_free(iter);
883 error_indication = WPS_EI_OPERATION_FAILED;
884 config_error = WPS_CFG_NO_ERROR;
885 ERR("Error Occured! Notifying Fail Event");
886 netconfig_wifi_notify_wps_fail_event(config_error, error_indication);
890 static void _supplicant_wifi_wps_event(GVariant *param)
896 gint32 config_error = 0;
897 gint32 error_indication = 0;
900 ERR("Param is NULL");
904 g_variant_get(param, "(sa{sv})", &name, &iter);
905 INFO("Event Result: %s", name);
906 if (g_strcmp0(name, "fail") == 0) {
907 while (g_variant_iter_loop(iter, "{sv}", &key, &variant)) {
910 INFO("Key is %s", key);
911 if (g_strcmp0(key, "config_error") == 0) {
912 config_error = g_variant_get_int32(variant);
913 ERR("Config Error %d", config_error);
914 } else if (g_strcmp0(key, "error_indication") == 0) {
915 error_indication = g_variant_get_int32(variant);
916 ERR("Error Indication %d", error_indication);
919 netconfig_wifi_notify_wps_fail_event(config_error, error_indication);
922 g_variant_iter_free(iter);
927 g_variant_iter_free(iter);
929 error_indication = WPS_EI_OPERATION_FAILED;
930 config_error = WPS_CFG_NO_ERROR;
931 ERR("Error Occured! Notifying Fail Event");
932 netconfig_wifi_notify_wps_fail_event(config_error, error_indication);
935 static void _find_service_and_set_passphrase(char *ssid, char *key)
938 GVariant *reply = NULL;
943 gchar *enc_passphrase;
945 ssid_len = strlen(ssid);
947 str = g_string_sized_new((ssid_len * 2) + 55);
951 dev_mac_addr = vconf_get_str(VCONFKEY_WIFI_BSSID_ADDRESS);
953 ERR("Failed to get mac address from vconf key");
954 g_string_free(str, TRUE);
959 for (i = 0; dev_mac_addr[i]; i++) {
960 if (dev_mac_addr[i] != ':')
961 ident[j++] = dev_mac_addr[i];
965 g_string_append_printf(str, "%s%s_", CONNMAN_WIFI_SERVICE_PROFILE_PREFIX,
969 for (i = 0; i < ssid_len; i++) {
971 g_string_append_printf(str, "%02x", ssid[i]);
974 g_string_append_printf(str, "_managed_psk");
976 service_path = g_string_free(str, FALSE);
978 enc_passphrase = _netconfig_encrypt_passphrase(key);
979 if (!enc_passphrase) {
980 ERR("Failed to encrypt passphrase");
981 g_free(service_path);
985 INFO("wps service_path %s Passphrase %s", service_path, enc_passphrase);
987 reply = netconfig_invoke_dbus_method(CONNMAN_SERVICE, service_path,
988 CONNMAN_SERVICE_INTERFACE, "SetProperty",
989 g_variant_new("(sv)", "Passphrase",
990 g_variant_new_string(enc_passphrase)));
992 g_variant_unref(reply);
994 ERR("Failed to set passphrase");
996 g_free(service_path);
1001 static void _supplicant_wifi_wps_credentials(GVariant *param)
1004 char ssid[32] = {0, };
1005 char wps_key[100] = {0, };
1008 int config_error = 0;
1009 int error_indication = 0;
1011 char *key_mgmt = NULL;
1013 if (param == NULL) {
1014 ERR("Param is NULL");
1018 g_variant_get(param, "(a{sv})", &iter);
1019 while (g_variant_iter_loop(iter, "{sv}", &key, &variant)) {
1022 INFO("wps Key is %s", key);
1023 if (g_strcmp0(key, "Key") == 0) {
1025 const char *t_key = NULL;
1026 key_len = g_variant_get_size(variant);
1028 INFO("wps password len %d ", key_len);
1030 t_key = g_variant_get_fixed_array(variant, &key_len,
1034 g_variant_unref(variant);
1037 strncpy(wps_key, t_key, key_len);
1038 wps_key[key_len] = '\0';
1039 INFO("WPS Key in process credentials %s", wps_key);
1041 SLOGI("WPS AP Security ->Open");
1042 } else if (g_strcmp0(key, "SSID") == 0) {
1043 const char *t_key = NULL;
1044 t_key = g_variant_get_fixed_array(variant, &ssid_len,
1046 INFO("wps ssid_len is %d ", ssid_len);
1049 g_variant_unref(variant);
1052 if (ssid_len > 0 && ssid_len <= 32) {
1053 memcpy(ssid, t_key, ssid_len);
1055 memset(ssid, 0, sizeof(ssid));
1058 INFO("SSID in process credentials %s", ssid);
1059 } else if (g_strcmp0(key, "AuthType") == 0) {
1061 GVariantIter *var_iter;
1062 g_variant_get(variant, "as", &var_iter);
1063 while (g_variant_iter_loop(var_iter, "s", &auth_type)) {
1064 INFO("wps auth_type %s", auth_type);
1065 if (g_strcmp0(auth_type, "wpa-psk") == 0 ||
1066 g_strcmp0(auth_type, "wpa2-psk") == 0)
1068 else if (g_strcmp0(auth_type, "open") == 0)
1071 g_variant_iter_free(var_iter);
1072 } else if (g_strcmp0(key, "EncrType") == 0) {
1074 GVariantIter *var_iter;
1075 g_variant_get(variant, "as", &var_iter);
1076 while (g_variant_iter_loop(var_iter, "s", &encr_type))
1077 INFO("wps encr_type %s", encr_type);
1078 g_variant_iter_free(var_iter);
1079 } else if (g_strcmp0(key, "BSSID") == 0) {
1080 const guchar *bssid;
1082 bssid = g_variant_get_fixed_array(variant, &bssid_len,
1084 if (bssid && bssid_len == 6)
1085 INFO("wps BSSID %2x:%2x:%2x:%2x:%2x:%2x", bssid[0], bssid[1],
1086 bssid[2], bssid[3], bssid[4], bssid[5]);
1090 g_variant_iter_free(iter);
1092 if (g_strcmp0(key_mgmt, "psk") == 0)
1093 _find_service_and_set_passphrase(ssid, wps_key);
1097 * Notify WPS Credentials only when requested through WPS PBC
1098 * In case of WPS PIN connman will take care of notification
1100 if (netconfig_get_wps_field() == TRUE)
1102 netconfig_wifi_notify_wps_credentials(ssid, ssid_len, wps_key);
1106 g_variant_iter_free(iter);
1107 error_indication = WPS_EI_OPERATION_FAILED;
1108 config_error = WPS_CFG_NO_ERROR;
1109 ERR("Error Occured! Notifying Fail Event");
1110 netconfig_wifi_notify_wps_fail_event(config_error, error_indication);
1113 static void __netconfig_wps_signal_filter_handler(GDBusConnection *conn,
1114 const gchar *name, const gchar *path, const gchar *interface,
1115 const gchar *sig, GVariant *param, gpointer user_data)
1117 if (g_strcmp0(sig, SIGNAL_WPS_CREDENTIALS) == 0) {
1118 INFO("Received wps CREDENTIALS Signal from Supplicant");
1119 _supplicant_wifi_wps_credentials(param);
1120 } else if (g_strcmp0(sig, SIGNAL_WPS_EVENT) == 0) {
1121 INFO("Received wps EVENT Signal from Supplicant");
1122 _supplicant_wifi_wps_event(param);
1123 } else if (g_strcmp0(sig, SIGNAL_WPS_CONNECTED) == 0) {
1124 INFO("Received WPSConnected Signal from Supplicant");
1125 _supplicant_wifi_wps_connected(param);
1131 static supplicant_signal_cb supplicant_cbs[SIG_MAX] = {
1132 _supplicant_interface_removed,
1133 _supplicant_properties_changed,
1134 _supplicant_bss_added,
1135 _supplicant_scan_done,
1136 _supplicant_driver_hanged,
1137 _supplicant_session_overlapped,
1138 _supplicant_tdls_connected,
1139 _supplicant_tdls_disconnected,
1140 _supplicant_tdls_peer_found
1143 void register_gdbus_signal(void)
1145 GDBusConnection *connection = NULL;
1146 const char *interface = NULL;
1147 SuppSigArrayIndex sig;
1148 connection = netdbus_get_connection();
1150 if (connection == NULL) {
1151 ERR("Failed to get GDbus Connection");
1155 /* listening to messages from all objects as no path is specified */
1156 /* see signals from the given interface */
1157 conn_subscription_ids[0] = g_dbus_connection_signal_subscribe(
1160 CONNMAN_TECHNOLOGY_INTERFACE,
1164 G_DBUS_SIGNAL_FLAGS_NONE,
1165 _technology_signal_cb,
1169 conn_subscription_ids[1] = g_dbus_connection_signal_subscribe(
1172 CONNMAN_SERVICE_INTERFACE,
1173 CONNMAN_SIGNAL_PROPERTY_CHANGED,
1176 G_DBUS_SIGNAL_FLAGS_NONE,
1181 conn_subscription_ids[2] = g_dbus_connection_signal_subscribe(
1184 DBUS_INTERFACE_DBUS,
1185 CONNMAN_SIGNAL_NAME_CHANGED,
1188 G_DBUS_SIGNAL_FLAGS_NONE,
1189 _dbus_name_changed_cb,
1193 conn_subscription_ids[3] = g_dbus_connection_signal_subscribe(
1196 CONNMAN_MANAGER_INTERFACE,
1197 CONNMAN_SIGNAL_SERVICES_CHANGED,
1200 G_DBUS_SIGNAL_FLAGS_NONE,
1201 _services_changed_cb,
1205 INFO("Successfully register connman DBus signal filters");
1207 conn_subscription_ids[4] = g_dbus_connection_signal_subscribe(
1210 SUPPLICANT_INTERFACE ".Interface.WPS",
1214 G_DBUS_SIGNAL_FLAGS_NONE,
1215 __netconfig_wps_signal_filter_handler,
1219 INFO("Successfully register Supplicant WPS DBus signal filters");
1221 for (sig = SIG_INTERFACE_REMOVED; sig < SIG_MAX; sig++) {
1223 * For SIG_INTERFACE_REMOVED INTERFACE_ADDED
1225 interface = (sig == SIG_INTERFACE_REMOVED) ?
1226 SUPPLICANT_INTERFACE : SUPPLICANT_IFACE_INTERFACE;
1228 supp_subscription_ids[sig] = g_dbus_connection_signal_subscribe(
1232 supplicant_signals[sig],
1235 G_DBUS_SIGNAL_FLAGS_NONE,
1236 supplicant_cbs[sig],
1241 INFO("Successfully register Supplicant DBus signal filters");
1243 #if defined TIZEN_DEBUG_ENABLE
1244 dumpservice_subscription_id = g_dbus_connection_signal_subscribe(
1247 DUMP_SERVICE_INTERFACE,
1251 G_DBUS_SIGNAL_FLAGS_NONE,
1252 __netconfig_dumpservice_handler,
1256 INFO("Successfully registered Dumpservice DBus signal filter");
1259 /* In case ConnMan precedes this signal register,
1260 * net-config should update the default connected profile.
1262 netconfig_update_default();
1265 void deregister_gdbus_signal(void)
1267 GDBusConnection *connection = NULL;
1269 SuppSigArrayIndex sig;
1270 connection = netdbus_get_connection();
1272 ERR("Already de-registered. Nothing to be done");
1276 for (signal = 0; signal < TOTAL_CONN_SIGNALS; signal++) {
1277 if (conn_subscription_ids[signal]) {
1278 g_dbus_connection_signal_unsubscribe(connection,
1279 conn_subscription_ids[signal]);
1283 for (sig = SIG_INTERFACE_REMOVED; sig < SIG_MAX; sig++) {
1284 if (supp_subscription_ids[sig]) {
1285 g_dbus_connection_signal_unsubscribe(connection,
1286 supp_subscription_ids[sig]);
1290 #if defined TIZEN_DEBUG_ENABLE
1291 g_dbus_connection_signal_unsubscribe(connection,
1292 dumpservice_subscription_id);