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 #include "clatd-handler.h"
45 #if defined TIZEN_DEBUG_ENABLE
46 #include "network-dump.h"
47 #define NETWORK_LOG_DUMP_SCRIPT "/opt/var/lib/net-config/network_log_dump.sh"
48 #define MAX_SIZE_ERROR_BUFFER 256
51 #define DBUS_SERVICE_DBUS "org.freedesktop.DBus"
52 #define DBUS_INTERFACE_DBUS "org.freedesktop.DBus"
53 #define SIGNAL_INTERFACE_REMOVED "InterfaceRemoved"
54 #define SIGNAL_SCAN_DONE "ScanDone"
55 #define SIGNAL_BSS_ADDED "BSSAdded"
56 #define SIGNAL_PROPERTIES_CHANGED "PropertiesChanged"
57 #define SIGNAL_PROPERTIES_DRIVER_HANGED "DriverHanged"
58 #define SIGNAL_PROPERTIES_SESSION_OVERLAPPED "SessionOverlapped"
59 #define SIGNAL_TDLS_CONNECTED "TDLSConnected"
60 #define SIGNAL_TDLS_DISCONNECTED "TDLSDisconnected"
61 #define SIGNAL_TDLS_PEER_FOUND "TDLSPeerFound"
63 #define SIGNAL_WPS_CONNECTED "WPSConnected"
64 #define SIGNAL_WPS_EVENT "Event"
65 #define SIGNAL_WPS_CREDENTIALS "Credentials"
67 #define CONNMAN_SIGNAL_SERVICES_CHANGED "ServicesChanged"
68 #define CONNMAN_SIGNAL_PROPERTY_CHANGED "PropertyChanged"
69 #define SIGNAL_NAME_OWNER_CHANGED "NameOwnerChanged"
71 #define MAX_SIG_LEN 64
72 #define TOTAL_CONN_SIGNALS 6
73 #define MAX_SOCKET_OPEN_RETRY 5
76 SIG_INTERFACE_REMOVED = 0,
77 SIG_PROPERTIES_CHANGED,
81 SIG_SESSION_OVERLAPPED,
83 SIG_TDLS_DISCONNECTED,
88 static int conn_subscription_ids[TOTAL_CONN_SIGNALS] = {0};
89 static const char supplicant_signals[SIG_MAX][MAX_SIG_LEN] = {
90 SIGNAL_INTERFACE_REMOVED,
91 SIGNAL_PROPERTIES_CHANGED,
94 SIGNAL_PROPERTIES_DRIVER_HANGED,
95 SIGNAL_PROPERTIES_SESSION_OVERLAPPED,
96 SIGNAL_TDLS_CONNECTED,
97 SIGNAL_TDLS_DISCONNECTED,
98 SIGNAL_TDLS_PEER_FOUND,
101 static int supp_subscription_ids[SIG_MAX] = {0};
102 #if defined TIZEN_DEBUG_ENABLE
103 static int dumpservice_subscription_id = 0;
106 typedef void (*supplicant_signal_cb)(GDBusConnection *conn,
107 const gchar *name, const gchar *path, const gchar *interface,
108 const gchar *sig, GVariant *param, gpointer user_data);
109 typedef void (*connman_signal_cb)(GDBusConnection *conn,
110 const gchar *name, const gchar *path, const gchar *interface,
111 const gchar *sig, GVariant *param, gpointer user_data);
113 static void __netconfig_extract_ipv4_signal_data(GVariant *dictionary,
114 const gchar *profile)
117 const gchar *value = NULL;
118 GVariant *var = NULL;
120 GVariantBuilder *builder;
123 g_variant_iter_init(&iter, dictionary);
124 while (g_variant_iter_loop(&iter, "{sv}", &key, &var)) {
125 if (g_strcmp0(key, "Address") == 0) {
126 g_variant_get(var, "&s", &value);
127 char *old_ip = vconf_get_str(VCONFKEY_NETWORK_IP);
129 DBG("Old IPv4.Address [%s] Received new IPv4.Address [%s]", old_ip,
131 if (g_strcmp0(old_ip, value) != 0) {
132 builder = g_variant_builder_new(G_VARIANT_TYPE("a{sv}"));
135 vconf_set_str(VCONFKEY_NETWORK_IP, value);
136 g_variant_builder_add(builder, "{sv}", "IPv4Address",
137 g_variant_new_string(value));
138 } else if (old_ip != NULL && strlen(old_ip) > 0) {
139 vconf_set_str(VCONFKEY_NETWORK_IP, "");
140 g_variant_builder_add(builder, "{sv}", "IPv4Address",
141 g_variant_new_string(""));
144 params = g_variant_new("(@a{sv})",
145 g_variant_builder_end(builder));
147 g_variant_builder_unref(builder);
149 netconfig_dbus_emit_signal(NULL, NETCONFIG_NETWORK_PATH,
150 NETCONFIG_NETWORK_INTERFACE, "NetworkConfigChanged",
158 static void __netconfig_extract_ipv6_signal_data(GVariant *dictionary,
159 const gchar *profile)
162 const gchar *value = NULL;
163 GVariant *var = NULL;
165 GVariantBuilder *builder;
168 g_variant_iter_init(&iter, dictionary);
169 while (g_variant_iter_loop(&iter, "{sv}", &key, &var)) {
170 if (g_strcmp0(key, "Address") == 0) {
171 g_variant_get(var, "&s", &value);
172 char *old_ip6 = vconf_get_str(VCONFKEY_NETWORK_IP6);
174 DBG("Old IPv6.Address [%s] Received new IPv6.Address [%s]", old_ip6,
176 if (g_strcmp0(old_ip6, value) != 0) {
177 builder = g_variant_builder_new(G_VARIANT_TYPE("a{sv}"));
180 vconf_set_str(VCONFKEY_NETWORK_IP6, value);
181 g_variant_builder_add(builder, "{sv}", "IPv6Address",
182 g_variant_new_string(value));
183 } else if (old_ip6 != NULL && strlen(old_ip6) > 0) {
184 vconf_set_str(VCONFKEY_NETWORK_IP6, "");
185 g_variant_builder_add(builder, "{sv}", "IPv6Address",
186 g_variant_new_string(""));
189 params = g_variant_new("(@a{sv})",
190 g_variant_builder_end(builder));
191 g_variant_builder_unref(builder);
193 netconfig_dbus_emit_signal(NULL, NETCONFIG_NETWORK_PATH,
194 NETCONFIG_NETWORK_INTERFACE, "NetworkConfigChanged",
202 #if defined TIZEN_DEBUG_ENABLE
203 static int __netconfig_handle_execute_file(const char *file_path,
204 char *const args[], char *const envs[])
210 register unsigned int index = 0;
211 char error_buf[MAX_SIZE_ERROR_BUFFER] = {0, };
213 while (args[index] != NULL) {
214 DBG("%s", args[index]);
218 if (!(pid = fork())) {
219 DBG("pid(%d), ppid (%d)", getpid(), getppid());
220 DBG("Inside child, exec (%s) command", file_path);
223 if (execve(file_path, args, envs) == -1) {
224 DBG("Fail to execute command (%s)",
225 strerror_r(errno, error_buf, MAX_SIZE_ERROR_BUFFER));
228 } else if (pid > 0) {
229 if (waitpid(pid, &status, 0) == -1)
230 DBG("wait pid (%u) status (%d)", pid, status);
232 if (WIFEXITED(status)) {
233 rv = WEXITSTATUS(status);
234 DBG("exited, status=%d", rv);
235 } else if (WIFSIGNALED(status)) {
236 DBG("killed by signal %d", WTERMSIG(status));
237 } else if (WIFSTOPPED(status)) {
238 DBG("stopped by signal %d", WSTOPSIG(status));
239 } else if (WIFCONTINUED(status)) {
246 DBG("failed to fork(%s)",
247 strerror_r(errno, error_buf, MAX_SIZE_ERROR_BUFFER));
251 static int _start_dump()
254 gchar *path = NETWORK_LOG_DUMP_SCRIPT;
255 char *const args[] = { NETWORK_LOG_DUMP_SCRIPT, NULL };
256 char *const envs[] = { NULL };
258 rv = __netconfig_handle_execute_file(path, args, envs);
260 ERR("Fail to execute network log dump shell");
267 static void _technology_signal_cb(GDBusConnection *conn,
268 const gchar *name, const gchar *path, const gchar *interface,
269 const gchar *sig, GVariant *param, gpointer user_data)
272 gboolean value = FALSE;
273 GVariant *var = NULL;
278 if (g_str_has_prefix(path, CONNMAN_WIFI_TECHNOLOGY_PREFIX) == TRUE) {
279 g_variant_get(param, "(sv)", &key, &var);
280 if (g_strcmp0(key, "Powered") == 0) {
282 value = g_variant_get_boolean(var);
284 wifi_state_update_power_state(TRUE);
286 wifi_state_update_power_state(FALSE);
287 } else if (g_strcmp0(key, "Connected") == 0) {
288 /* Connection state */
289 value = g_variant_get_boolean(var);
291 wifi_state_set_tech_state(NETCONFIG_WIFI_TECH_CONNECTED);
293 wifi_state_set_tech_state(NETCONFIG_WIFI_TECH_POWERED);
294 } else if (g_strcmp0(key, "Tethering") == 0) {
295 /* Tethering state */
296 wifi_state_set_tech_state(NETCONFIG_WIFI_TECH_TETHERED);
299 g_variant_unref(var);
303 static void _service_signal_cb(GDBusConnection *conn,
304 const gchar *name, const gchar *path,
305 const gchar *interface, const gchar *sig,
306 GVariant *param, gpointer user_data)
308 gchar *sigvalue = NULL;
310 GVariant *variant = NULL, *var;
312 const gchar *value = NULL;
313 struct sock_data *sd = NULL;
317 if (path == NULL || param == NULL)
320 g_variant_get(param, "(sv)", &sigvalue, &variant);
321 if (sigvalue == NULL)
324 if (g_strcmp0(sig, CONNMAN_SIGNAL_PROPERTY_CHANGED) != 0)
327 if (g_strcmp0(sigvalue, "State") == 0) {
328 g_variant_get(variant, "s", &property);
330 DBG("[%s] %s", property, path);
332 if (netconfig_is_wifi_profile(path) == TRUE) {
335 netconfig_vconf_get_int(VCONFKEY_WIFI_STATE, &wifi_state);
336 if (wifi_state == VCONFKEY_WIFI_OFF) {
341 if (g_strcmp0(property, "ready") == 0 || g_strcmp0(property, "online") == 0) {
342 if (wifi_state >= VCONFKEY_WIFI_CONNECTED) {
347 netconfig_update_default_profile(path);
349 wifi_state_set_service_state(NETCONFIG_WIFI_CONNECTED);
351 } else if (g_strcmp0(property, "failure") == 0 || g_strcmp0(property, "disconnect") == 0 || g_strcmp0(property, "idle") == 0) {
352 if (netconfig_get_default_profile() == NULL ||
353 netconfig_is_wifi_profile(netconfig_get_default_profile())
355 if (g_strcmp0(property, "failure") == 0)
356 wifi_state_set_service_state(NETCONFIG_WIFI_FAILURE);
358 wifi_state_set_service_state(NETCONFIG_WIFI_IDLE);
363 if (g_strcmp0(path, netconfig_get_default_profile()) != 0) {
368 netconfig_update_default_profile(NULL);
370 if (g_strcmp0(property, "failure") == 0)
371 wifi_state_set_service_state(NETCONFIG_WIFI_FAILURE);
373 wifi_state_set_service_state(NETCONFIG_WIFI_IDLE);
375 } else if (g_strcmp0(property, "association") == 0 || g_strcmp0(property, "configuration") == 0) {
376 if (netconfig_get_default_profile() == NULL ||
377 netconfig_is_wifi_profile(netconfig_get_default_profile()) != TRUE) {
378 if (g_strcmp0(property, "association") == 0)
379 wifi_state_set_service_state(NETCONFIG_WIFI_ASSOCIATION);
381 wifi_state_set_service_state(NETCONFIG_WIFI_CONFIGURATION);
386 if (g_strcmp0(path, netconfig_get_default_profile()) != 0) {
391 netconfig_update_default_profile(NULL);
393 if (g_strcmp0(property, "association") == 0)
394 wifi_state_set_service_state(NETCONFIG_WIFI_ASSOCIATION);
396 wifi_state_set_service_state(NETCONFIG_WIFI_CONFIGURATION);
400 if (g_strcmp0(property, "ready") == 0 || g_strcmp0(property, "online") == 0) {
401 if (netconfig_get_default_profile() == NULL) {
402 if (!netconfig_is_cellular_profile(path))
403 netconfig_update_default_profile(path);
405 if (netconfig_is_cellular_internet_profile(path))
406 netconfig_update_default_profile(path);
409 pf = netconfig_get_connected_cellular_internet_ipv6only_profile(NULL);
414 /* Enable clatd if it is not in running state */
415 DBG("Connected to ipv6 only cellular, enable clatd");
416 netconfig_clatd_enable();
420 if (netconfig_is_cellular_profile(path) && netconfig_is_cellular_internet_profile(path))
421 cellular_state_set_service_state(NETCONFIG_CELLULAR_ONLINE);
423 } else if (g_strcmp0(property, "failure") == 0 || g_strcmp0(property, "disconnect") == 0 || g_strcmp0(property, "idle") == 0) {
424 if (netconfig_get_default_profile() == NULL) {
429 if (netconfig_is_cellular_profile(path) && netconfig_is_cellular_internet_profile(path)) {
430 cellular_state_set_service_state(NETCONFIG_CELLULAR_IDLE);
432 /* Disable clatd if it is in running state */
433 DBG("disable clatd");
434 netconfig_clatd_disable();
437 if (g_strcmp0(path, netconfig_get_default_profile()) != 0) {
442 netconfig_update_default_profile(NULL);
443 } else if (g_strcmp0(property, "association") == 0 || g_strcmp0(property, "configuration") == 0) {
444 if (netconfig_get_default_profile() == NULL) {
449 if (netconfig_is_cellular_profile(path) && netconfig_is_cellular_internet_profile(path))
450 cellular_state_set_service_state(NETCONFIG_CELLULAR_CONNECTING);
452 if (g_strcmp0(path, netconfig_get_default_profile()) != 0) {
457 netconfig_update_default_profile(NULL);
461 if (netconfig_is_wifi_profile(path) || netconfig_is_ethernet_profile(path)) {
462 if (g_strcmp0(property, "ready") == 0) {
463 for (idx = 0; idx < MAX_SOCKET_OPEN_RETRY; idx++) {
464 sd = start_ip_conflict_mon();
468 } else if (g_strcmp0(property, "online") == 0) {
471 stop_ip_conflict_mon();
476 } else if (g_strcmp0(sigvalue, "Proxy") == 0) {
477 if (netconfig_is_wifi_profile(path) != TRUE || g_strcmp0(path, netconfig_get_default_profile()) != 0)
480 if (!g_variant_is_of_type(variant, G_VARIANT_TYPE_ARRAY))
483 g_variant_get(variant, "a{sv}", &iter);
484 while (g_variant_iter_loop(iter, "{sv}", &property, &var)) {
485 GVariantBuilder *builder;
486 GVariant *sig_params;
487 if (g_strcmp0(property, "Servers") == 0) {
488 GVariantIter *iter_sub = NULL;
490 builder = g_variant_builder_new(G_VARIANT_TYPE("a{sv}"));
492 g_variant_get(var, "as", &iter_sub);
493 g_variant_iter_loop(iter_sub, "s", &value);
494 g_variant_iter_free(iter_sub);
496 DBG("Proxy - [%s]", value);
497 vconf_set_str(VCONFKEY_NETWORK_PROXY, value);
499 g_variant_builder_add(builder, "{sv}", "ProxyAddress",
500 g_variant_new_string(value));
502 sig_params = g_variant_new("(@a{sv})",
503 g_variant_builder_end(builder));
504 g_variant_builder_unref(builder);
506 netconfig_dbus_emit_signal(NULL, NETCONFIG_NETWORK_PATH,
507 NETCONFIG_NETWORK_INTERFACE, "NetworkConfigChanged",
511 g_variant_unref(var);
513 } else if (g_strcmp0(property, "Method") == 0) {
514 value = g_variant_get_string(var, NULL);
515 DBG("Method - [%s]", value);
517 if (g_strcmp0(value, "direct") == 0) {
518 builder = g_variant_builder_new(G_VARIANT_TYPE("a{sv}"));
520 vconf_set_str(VCONFKEY_NETWORK_PROXY, "");
521 g_variant_builder_add(builder, "{sv}", "ProxyAddress",
522 g_variant_new_string(""));
524 sig_params = g_variant_new("(@a{sv})",
525 g_variant_builder_end(builder));
526 g_variant_builder_unref(builder);
528 netconfig_dbus_emit_signal(NULL, NETCONFIG_NETWORK_PATH,
529 NETCONFIG_NETWORK_INTERFACE,
530 "NetworkConfigChanged", sig_params);
534 g_variant_unref(var);
539 g_variant_iter_free(iter);
540 } else if (g_strcmp0(sigvalue, "IPv4") == 0) {
541 __netconfig_extract_ipv4_signal_data(variant, path);
542 } else if (g_strcmp0(sigvalue, "IPv6") == 0) {
543 __netconfig_extract_ipv6_signal_data(variant, path);
544 } else if (g_strcmp0(sigvalue, "Error") == 0) {
545 g_variant_get(variant, "s", &property);
546 INFO("[%s] Property : %s", sigvalue, property);
547 #if defined TIZEN_DEBUG_ENABLE
548 if (g_strcmp0(property, "dhcp-failed") == 0
549 || g_strcmp0(property, "connect-failed") == 0
550 || g_strcmp0(property, "login-failed") == 0
551 || g_strcmp0(property, "auth-failed") == 0
552 || g_strcmp0(property, "invalid-key") == 0) {
564 g_variant_unref(variant);
569 static void _dbus_name_changed_cb(GDBusConnection *conn,
570 const gchar *Name, const gchar *path, const gchar *interface,
571 const gchar *sig, GVariant *param, gpointer user_data)
580 g_variant_get(param, "(sss)", &name, &old, &new);
582 if (g_strcmp0(name, CONNMAN_SERVICE) == 0 && *new == '\0') {
583 DBG("ConnMan destroyed: name %s, old %s, new %s", name, old, new);
585 connman_register_agent();
586 } else if (g_strcmp0(name, CLATD_SERVICE) == 0 && *new == '\0') {
587 DBG("Clat destroyed: name %s, old %s, new %s", name, old, new);
589 /* If clatd is terminated unexpectedly, reset and enable clat service. */
590 if (NETCONFIG_CELLULAR_ONLINE == cellular_state_get_service_state())
591 netconfig_clatd_reset();
600 static void _services_changed_cb(GDBusConnection *conn, const gchar *name,
601 const gchar *path, const gchar *interface, const gchar *sig,
602 GVariant *param, gpointer user_data)
604 gchar *property, *value;
606 GVariant *variant = NULL;
607 GVariantIter *added = NULL, *removed = NULL, *next = NULL;
609 if (path == NULL || param == NULL)
612 if (g_strcmp0(sig, CONNMAN_SIGNAL_SERVICES_CHANGED) != 0)
615 if (netconfig_get_default_profile() != NULL)
618 g_variant_get(param, "(a(oa{sv})ao)", &added, &removed);
620 while (g_variant_iter_loop(added, "(oa{sv})", &service_path, &next)) {
621 gboolean is_wifi_prof, is_cell_prof, is_cell_internet_prof;
622 is_wifi_prof = netconfig_is_wifi_profile(service_path);
623 is_cell_prof = netconfig_is_cellular_profile(service_path);
624 is_cell_internet_prof = netconfig_is_cellular_internet_profile(
626 if (service_path != NULL) {
627 while (next && g_variant_iter_loop(next, "{sv}", &property,
629 if (g_strcmp0(property, "State") == 0) {
630 g_variant_get(variant, "s", &value);
631 DBG("Profile %s State %s", service_path,
633 if (g_strcmp0(value, "ready") != 0 &&
638 g_variant_unref(variant);
643 netconfig_update_default_profile(
645 else if (is_cell_internet_prof) {
646 netconfig_update_default_profile(
650 wifi_state_set_service_state(
651 NETCONFIG_WIFI_CONNECTED);
652 else if (is_cell_prof &&
653 is_cell_internet_prof)
654 cellular_state_set_service_state(
655 NETCONFIG_CELLULAR_ONLINE);
658 g_variant_unref(variant);
665 g_variant_iter_free(added);
668 g_variant_iter_free(next);
671 g_variant_iter_free(removed);
676 static void _supplicant_interface_removed(GDBusConnection *conn,
677 const gchar *name, const gchar *path, const gchar *interface,
678 const gchar *sig, GVariant *param, gpointer user_data)
680 DBG("Interface removed handling!");
681 if (netconfig_wifi_is_bssid_scan_started() == TRUE)
682 netconfig_wifi_bssid_signal_scanaborted();
687 static void _supplicant_properties_changed(GDBusConnection *conn,
688 const gchar *name, const gchar *path, const gchar *interface,
689 const gchar *sig, GVariant *param, gpointer user_data)
691 DBG("Properties changed handling!");
693 const gchar *state = NULL;
694 GVariantIter *iter = NULL;
695 GVariant *variant = NULL;
696 gboolean scanning = FALSE;
701 g_variant_get(param, "(a{sv})", &iter);
702 while (g_variant_iter_loop(iter, "{sv}", &key, &variant)) {
703 if (g_strcmp0(key, "Scanning") == 0) {
704 scanning = g_variant_get_boolean(variant);
705 DBG("setting scanning %s", scanning ? "TRUE" : "FALSE");
706 if (scanning == TRUE)
707 netconfig_wifi_set_scanning(TRUE);
709 netconfig_wifi_set_scanning(FALSE);
711 g_variant_unref(variant);
716 } else if (g_strcmp0(key, "State") == 0) {
717 state = g_variant_get_string(variant, NULL);
719 ERR("Supplicant state : %s", state);
721 g_variant_unref(variant);
726 } else if (g_strcmp0(key, "DisconnectReason") == 0) {
727 int reason = g_variant_get_int32(variant);
728 ERR("Supplicant DisconnReason : %d", reason);
730 g_variant_unref(variant);
737 value = g_variant_print(variant, TRUE);
738 DBG("Supplicant %s : %s", key, value);
744 g_variant_iter_free(iter);
749 static void _supplicant_bss_added(GDBusConnection *conn,
750 const gchar *name, const gchar *path, const gchar *interface,
751 const gchar *sig, GVariant *param, gpointer user_data)
753 DBG("BSS added handling!");
754 wifi_state_set_bss_found(TRUE);
759 static void _supplicant_scan_done(GDBusConnection *conn,
760 const gchar *name, const gchar *path, const gchar *interface,
761 const gchar *sig, GVariant *param, gpointer user_data)
763 DBG("Scan Done handling!");
764 netconfig_wifi_set_scanning(FALSE);
766 if (netconfig_wifi_is_bssid_scan_started() == TRUE) {
767 netconfig_wifi_bssid_signal_scandone();
768 if (wifi_state_get_technology_state() < NETCONFIG_WIFI_TECH_POWERED)
772 if (netconfig_wifi_get_bgscan_state() == TRUE) {
773 if (wifi_state_get_technology_state() >=
774 NETCONFIG_WIFI_TECH_POWERED)
775 netconfig_wifi_bgscan_start(FALSE);
777 wifi_start_timer_network_notification();
783 static void _supplicant_driver_hanged(GDBusConnection *conn,
784 const gchar *name, const gchar *path, const gchar *interface,
785 const gchar *sig, GVariant *param, gpointer user_data)
787 DBG("Driver Hanged handling!");
788 ERR("Critical. Wi-Fi firmware crashed");
790 #if !defined TIZEN_WEARABLE
791 netconfig_send_message_to_net_popup("Wi-Fi Error",
792 "Wi-Fi Driver Hanged. Please get log dump and report", "popup", NULL);
794 wifi_power_recover_firmware();
800 static void _supplicant_session_overlapped(GDBusConnection *conn,
801 const gchar *name, const gchar *path, const gchar *interface,
802 const gchar *sig, GVariant *param, gpointer user_data)
804 DBG("Driver session overlapped handling!");
805 ERR("WPS PBC SESSION OVERLAPPED");
806 #if defined TIZEN_WEARABLE
809 netconfig_send_message_to_net_popup("WPS Error",
810 "wps session overlapped", "popup", NULL);
814 #if defined TIZEN_DEBUG_ENABLE
815 static void __netconfig_dumpservice_handler(GDBusConnection *conn,
816 const gchar *name, const gchar *path, const gchar *interface,
817 const gchar *sig, GVariant *param, gpointer user_data)
820 gchar *signal_path = NULL;
825 g_variant_get(param, "(is)", &mode, &signal_path);
826 DBG("Path: %s and mode: %d", signal_path, mode);
828 netconfig_dump_log(signal_path);
836 static void _supplicant_tdls_connected(GDBusConnection *conn,
837 const gchar *name, const gchar *path, const gchar *interface,
838 const gchar *sig, GVariant *param, gpointer user_data)
840 DBG("Received TDLS Connected Signal");
841 netconfig_wifi_tdls_connected_event(param);
846 static void _supplicant_tdls_disconnected(GDBusConnection *conn,
847 const gchar *name, const gchar *path, const gchar *interface,
848 const gchar *sig, GVariant *param, gpointer user_data)
850 DBG("Received TDLS Disconnected Signal");
851 netconfig_wifi_tdls_disconnected_event(param);
856 static void _supplicant_tdls_peer_found(GDBusConnection *conn,
857 const gchar *name, const gchar *path, const gchar *interface,
858 const gchar *sig, GVariant *param, gpointer user_data)
860 DBG("Received TDLS Peer Found Signal");
861 netconfig_wifi_tdls_peer_found_event(param);
865 static void _supplicant_wifi_wps_connected(GVariant *param)
868 char ssid[32] = {0, };
872 int config_error = 0;
873 int error_indication = 0;
877 ERR("Param is NULL");
881 g_variant_get(param, "(sa{sv})", &name, &iter);
882 INFO("wps Result: %s", name);
883 while (g_variant_iter_loop(iter, "{sv}", &key, &variant)) {
884 INFO("wps Key is %s", key);
885 if (g_strcmp0(key, "SSID") == 0) {
886 const char *t_key = NULL;
887 t_key = g_variant_get_fixed_array(variant, &ssid_len, sizeof(guchar));
888 INFO("wps ssid_len is %zd ", ssid_len);
891 g_variant_unref(variant);
892 ERR("WPS PBC Connection Failed");
895 if (ssid_len > 0 && ssid_len <= 32) {
896 memcpy(ssid, t_key, ssid_len);
898 memset(ssid, 0, sizeof(ssid));
901 INFO("WPS PBC Connection completed with AP %s", ssid);
902 netconfig_wifi_notify_wps_completed(ssid, ssid_len);
906 g_variant_iter_free(iter);
911 g_variant_iter_free(iter);
913 error_indication = WPS_EI_OPERATION_FAILED;
914 config_error = WPS_CFG_NO_ERROR;
915 ERR("Error Occured! Notifying Fail Event");
916 netconfig_wifi_notify_wps_fail_event(config_error, error_indication);
920 static void _supplicant_wifi_wps_event(GVariant *param)
926 gint32 config_error = 0;
927 gint32 error_indication = 0;
930 ERR("Param is NULL");
934 g_variant_get(param, "(sa{sv})", &name, &iter);
935 INFO("Event Result: %s", name);
936 if (g_strcmp0(name, "fail") == 0) {
937 while (g_variant_iter_loop(iter, "{sv}", &key, &variant)) {
940 INFO("Key is %s", key);
941 if (g_strcmp0(key, "config_error") == 0) {
942 config_error = g_variant_get_int32(variant);
943 ERR("Config Error %d", config_error);
944 } else if (g_strcmp0(key, "error_indication") == 0) {
945 error_indication = g_variant_get_int32(variant);
946 ERR("Error Indication %d", error_indication);
949 netconfig_wifi_notify_wps_fail_event(config_error, error_indication);
952 g_variant_iter_free(iter);
957 g_variant_iter_free(iter);
959 error_indication = WPS_EI_OPERATION_FAILED;
960 config_error = WPS_CFG_NO_ERROR;
961 ERR("Error Occured! Notifying Fail Event");
962 netconfig_wifi_notify_wps_fail_event(config_error, error_indication);
965 static void _find_service_and_set_passphrase(char *ssid, char *key)
968 GVariant *reply = NULL;
973 gchar *enc_passphrase;
975 ssid_len = strlen(ssid);
977 str = g_string_sized_new((ssid_len * 2) + 55);
981 dev_mac_addr = vconf_get_str(VCONFKEY_WIFI_BSSID_ADDRESS);
983 ERR("Failed to get mac address from vconf key");
984 g_string_free(str, TRUE);
989 for (i = 0; dev_mac_addr[i]; i++) {
990 if (dev_mac_addr[i] != ':')
991 ident[j++] = dev_mac_addr[i];
995 g_string_append_printf(str, "%s%s_", CONNMAN_WIFI_SERVICE_PROFILE_PREFIX,
999 for (i = 0; i < ssid_len; i++) {
1001 g_string_append_printf(str, "%02x", ssid[i]);
1004 g_string_append_printf(str, "_managed_psk");
1006 service_path = g_string_free(str, FALSE);
1008 enc_passphrase = _netconfig_encrypt_passphrase(key);
1009 if (!enc_passphrase) {
1010 ERR("Failed to encrypt passphrase");
1011 g_free(service_path);
1015 INFO("wps service_path %s Passphrase %s", service_path, enc_passphrase);
1017 reply = netconfig_invoke_dbus_method(CONNMAN_SERVICE, service_path,
1018 CONNMAN_SERVICE_INTERFACE, "SetProperty",
1019 g_variant_new("(sv)", "Passphrase",
1020 g_variant_new_string(enc_passphrase)));
1022 g_variant_unref(reply);
1024 ERR("Failed to set passphrase");
1026 g_free(service_path);
1031 static void _supplicant_wifi_wps_credentials(GVariant *param)
1034 char ssid[32] = {0, };
1035 char wps_key[100] = {0, };
1038 int config_error = 0;
1039 int error_indication = 0;
1041 char *key_mgmt = NULL;
1043 if (param == NULL) {
1044 ERR("Param is NULL");
1048 g_variant_get(param, "(a{sv})", &iter);
1049 while (g_variant_iter_loop(iter, "{sv}", &key, &variant)) {
1052 INFO("wps Key is %s", key);
1053 if (g_strcmp0(key, "Key") == 0) {
1055 const char *t_key = NULL;
1056 key_len = g_variant_get_size(variant);
1058 INFO("wps password len %zd ", key_len);
1060 t_key = g_variant_get_fixed_array(variant, &key_len,
1064 g_variant_unref(variant);
1067 strncpy(wps_key, t_key, key_len);
1068 wps_key[key_len] = '\0';
1069 INFO("WPS Key in process credentials %s", wps_key);
1071 SLOGI("WPS AP Security ->Open");
1072 } else if (g_strcmp0(key, "SSID") == 0) {
1073 const char *t_key = NULL;
1074 t_key = g_variant_get_fixed_array(variant, &ssid_len,
1076 INFO("wps ssid_len is %zd ", ssid_len);
1079 g_variant_unref(variant);
1082 if (ssid_len > 0 && ssid_len <= 32) {
1083 memcpy(ssid, t_key, ssid_len);
1085 memset(ssid, 0, sizeof(ssid));
1088 INFO("SSID in process credentials %s", ssid);
1089 } else if (g_strcmp0(key, "AuthType") == 0) {
1091 GVariantIter *var_iter;
1092 g_variant_get(variant, "as", &var_iter);
1093 while (g_variant_iter_loop(var_iter, "s", &auth_type)) {
1094 INFO("wps auth_type %s", auth_type);
1095 if (g_strcmp0(auth_type, "wpa-psk") == 0 ||
1096 g_strcmp0(auth_type, "wpa2-psk") == 0)
1098 else if (g_strcmp0(auth_type, "open") == 0)
1101 g_variant_iter_free(var_iter);
1102 } else if (g_strcmp0(key, "EncrType") == 0) {
1104 GVariantIter *var_iter;
1105 g_variant_get(variant, "as", &var_iter);
1106 while (g_variant_iter_loop(var_iter, "s", &encr_type))
1107 INFO("wps encr_type %s", encr_type);
1108 g_variant_iter_free(var_iter);
1109 } else if (g_strcmp0(key, "BSSID") == 0) {
1110 const guchar *bssid;
1112 bssid = g_variant_get_fixed_array(variant, &bssid_len,
1114 if (bssid && bssid_len == 6)
1115 INFO("wps BSSID %2x:%2x:%2x:%2x:%2x:%2x", bssid[0], bssid[1],
1116 bssid[2], bssid[3], bssid[4], bssid[5]);
1120 g_variant_iter_free(iter);
1122 if (g_strcmp0(key_mgmt, "psk") == 0)
1123 _find_service_and_set_passphrase(ssid, wps_key);
1127 * Notify WPS Credentials only when requested through WPS PBC
1128 * In case of WPS PIN connman will take care of notification
1130 if (netconfig_get_wps_field() == TRUE)
1132 netconfig_wifi_notify_wps_credentials(ssid, ssid_len, wps_key);
1136 g_variant_iter_free(iter);
1137 error_indication = WPS_EI_OPERATION_FAILED;
1138 config_error = WPS_CFG_NO_ERROR;
1139 ERR("Error Occured! Notifying Fail Event");
1140 netconfig_wifi_notify_wps_fail_event(config_error, error_indication);
1143 static void __netconfig_wps_signal_filter_handler(GDBusConnection *conn,
1144 const gchar *name, const gchar *path, const gchar *interface,
1145 const gchar *sig, GVariant *param, gpointer user_data)
1147 if (g_strcmp0(sig, SIGNAL_WPS_CREDENTIALS) == 0) {
1148 INFO("Received wps CREDENTIALS Signal from Supplicant");
1149 _supplicant_wifi_wps_credentials(param);
1150 } else if (g_strcmp0(sig, SIGNAL_WPS_EVENT) == 0) {
1151 INFO("Received wps EVENT Signal from Supplicant");
1152 _supplicant_wifi_wps_event(param);
1153 } else if (g_strcmp0(sig, SIGNAL_WPS_CONNECTED) == 0) {
1154 INFO("Received WPSConnected Signal from Supplicant");
1155 _supplicant_wifi_wps_connected(param);
1161 static supplicant_signal_cb supplicant_cbs[SIG_MAX] = {
1162 _supplicant_interface_removed,
1163 _supplicant_properties_changed,
1164 _supplicant_bss_added,
1165 _supplicant_scan_done,
1166 _supplicant_driver_hanged,
1167 _supplicant_session_overlapped,
1168 _supplicant_tdls_connected,
1169 _supplicant_tdls_disconnected,
1170 _supplicant_tdls_peer_found
1173 void register_gdbus_signal(void)
1175 GDBusConnection *connection = NULL;
1176 const char *interface = NULL;
1177 SuppSigArrayIndex sig;
1178 connection = netdbus_get_connection();
1180 if (connection == NULL) {
1181 ERR("Failed to get GDbus Connection");
1185 /* listening to messages from all objects as no path is specified */
1186 /* see signals from the given interface */
1187 conn_subscription_ids[0] = g_dbus_connection_signal_subscribe(
1190 CONNMAN_TECHNOLOGY_INTERFACE,
1194 G_DBUS_SIGNAL_FLAGS_NONE,
1195 _technology_signal_cb,
1199 conn_subscription_ids[1] = g_dbus_connection_signal_subscribe(
1202 CONNMAN_SERVICE_INTERFACE,
1203 CONNMAN_SIGNAL_PROPERTY_CHANGED,
1206 G_DBUS_SIGNAL_FLAGS_NONE,
1211 conn_subscription_ids[2] = g_dbus_connection_signal_subscribe(
1214 DBUS_INTERFACE_DBUS,
1215 SIGNAL_NAME_OWNER_CHANGED,
1218 G_DBUS_SIGNAL_FLAGS_NONE,
1219 _dbus_name_changed_cb,
1223 conn_subscription_ids[3] = g_dbus_connection_signal_subscribe(
1226 CONNMAN_MANAGER_INTERFACE,
1227 CONNMAN_SIGNAL_SERVICES_CHANGED,
1230 G_DBUS_SIGNAL_FLAGS_NONE,
1231 _services_changed_cb,
1235 INFO("Successfully register connman DBus signal filters");
1237 conn_subscription_ids[4] = g_dbus_connection_signal_subscribe(
1240 SUPPLICANT_INTERFACE ".Interface.WPS",
1244 G_DBUS_SIGNAL_FLAGS_NONE,
1245 __netconfig_wps_signal_filter_handler,
1249 INFO("Successfully register Supplicant WPS DBus signal filters");
1251 conn_subscription_ids[5] = g_dbus_connection_signal_subscribe(
1254 DBUS_INTERFACE_DBUS,
1255 SIGNAL_NAME_OWNER_CHANGED,
1258 G_DBUS_SIGNAL_FLAGS_NONE,
1259 _dbus_name_changed_cb,
1263 INFO("Successfully register clat DBus signal filters");
1265 for (sig = SIG_INTERFACE_REMOVED; sig < SIG_MAX; sig++) {
1267 * For SIG_INTERFACE_REMOVED INTERFACE_ADDED
1269 interface = (sig == SIG_INTERFACE_REMOVED) ?
1270 SUPPLICANT_INTERFACE : SUPPLICANT_IFACE_INTERFACE;
1272 supp_subscription_ids[sig] = g_dbus_connection_signal_subscribe(
1276 supplicant_signals[sig],
1279 G_DBUS_SIGNAL_FLAGS_NONE,
1280 supplicant_cbs[sig],
1285 INFO("Successfully register Supplicant DBus signal filters");
1287 #if defined TIZEN_DEBUG_ENABLE
1288 dumpservice_subscription_id = g_dbus_connection_signal_subscribe(
1291 DUMP_SERVICE_INTERFACE,
1295 G_DBUS_SIGNAL_FLAGS_NONE,
1296 __netconfig_dumpservice_handler,
1300 INFO("Successfully registered Dumpservice DBus signal filter");
1303 /* In case ConnMan precedes this signal register,
1304 * net-config should update the default connected profile.
1306 netconfig_update_default();
1309 void deregister_gdbus_signal(void)
1311 GDBusConnection *connection = NULL;
1313 SuppSigArrayIndex sig;
1314 connection = netdbus_get_connection();
1316 ERR("Already de-registered. Nothing to be done");
1320 for (signal = 0; signal < TOTAL_CONN_SIGNALS; signal++) {
1321 if (conn_subscription_ids[signal]) {
1322 g_dbus_connection_signal_unsubscribe(connection,
1323 conn_subscription_ids[signal]);
1327 for (sig = SIG_INTERFACE_REMOVED; sig < SIG_MAX; sig++) {
1328 if (supp_subscription_ids[sig]) {
1329 g_dbus_connection_signal_unsubscribe(connection,
1330 supp_subscription_ids[sig]);
1334 #if defined TIZEN_DEBUG_ENABLE
1335 g_dbus_connection_signal_unsubscribe(connection,
1336 dumpservice_subscription_id);