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 CONNMAN_SIGNAL_NAME_CHANGED "NameOwnerChanged"
71 #define MAX_SIG_LEN 64
72 #define TOTAL_CONN_SIGNALS 5
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();
594 static void _services_changed_cb(GDBusConnection *conn, const gchar *name,
595 const gchar *path, const gchar *interface, const gchar *sig,
596 GVariant *param, gpointer user_data)
598 gchar *property, *value;
600 GVariant *variant = NULL;
601 GVariantIter *added = NULL, *removed = NULL, *next = NULL;
603 if (path == NULL || param == NULL)
606 if (g_strcmp0(sig, CONNMAN_SIGNAL_SERVICES_CHANGED) != 0)
609 if (netconfig_get_default_profile() != NULL)
612 g_variant_get(param, "(a(oa{sv})ao)", &added, &removed);
614 while (g_variant_iter_loop(added, "(oa{sv})", &service_path, &next)) {
615 gboolean is_wifi_prof, is_cell_prof, is_cell_internet_prof;
616 is_wifi_prof = netconfig_is_wifi_profile(service_path);
617 is_cell_prof = netconfig_is_cellular_profile(service_path);
618 is_cell_internet_prof = netconfig_is_cellular_internet_profile(
620 if (service_path != NULL) {
621 while (next && g_variant_iter_loop(next, "{sv}", &property,
623 if (g_strcmp0(property, "State") == 0) {
624 g_variant_get(variant, "s", &value);
625 DBG("Profile %s State %s", service_path,
627 if (g_strcmp0(value, "ready") != 0 &&
632 g_variant_unref(variant);
637 netconfig_update_default_profile(
639 else if (is_cell_internet_prof) {
640 netconfig_update_default_profile(
644 wifi_state_set_service_state(
645 NETCONFIG_WIFI_CONNECTED);
646 else if (is_cell_prof &&
647 is_cell_internet_prof)
648 cellular_state_set_service_state(
649 NETCONFIG_CELLULAR_ONLINE);
652 g_variant_unref(variant);
659 g_variant_iter_free(added);
662 g_variant_iter_free(next);
665 g_variant_iter_free(removed);
670 static void _supplicant_interface_removed(GDBusConnection *conn,
671 const gchar *name, const gchar *path, const gchar *interface,
672 const gchar *sig, GVariant *param, gpointer user_data)
674 DBG("Interface removed handling!");
675 if (netconfig_wifi_is_bssid_scan_started() == TRUE)
676 netconfig_wifi_bssid_signal_scanaborted();
681 static void _supplicant_properties_changed(GDBusConnection *conn,
682 const gchar *name, const gchar *path, const gchar *interface,
683 const gchar *sig, GVariant *param, gpointer user_data)
685 DBG("Properties changed handling!");
687 const gchar *state = NULL;
688 GVariantIter *iter = NULL;
689 GVariant *variant = NULL;
690 gboolean scanning = FALSE;
695 g_variant_get(param, "(a{sv})", &iter);
696 while (g_variant_iter_loop(iter, "{sv}", &key, &variant)) {
697 if (g_strcmp0(key, "Scanning") == 0) {
698 scanning = g_variant_get_boolean(variant);
699 DBG("setting scanning %s", scanning ? "TRUE" : "FALSE");
700 if (scanning == TRUE)
701 netconfig_wifi_set_scanning(TRUE);
703 netconfig_wifi_set_scanning(FALSE);
705 g_variant_unref(variant);
710 } else if (g_strcmp0(key, "State") == 0) {
711 state = g_variant_get_string(variant, NULL);
713 ERR("Supplicant state : %s", state);
715 g_variant_unref(variant);
720 } else if (g_strcmp0(key, "DisconnectReason") == 0) {
721 int reason = g_variant_get_int32(variant);
722 ERR("Supplicant DisconnReason : %d", reason);
724 g_variant_unref(variant);
731 value = g_variant_print(variant, TRUE);
732 DBG("Supplicant %s : %s", key, value);
738 g_variant_iter_free(iter);
743 static void _supplicant_bss_added(GDBusConnection *conn,
744 const gchar *name, const gchar *path, const gchar *interface,
745 const gchar *sig, GVariant *param, gpointer user_data)
747 DBG("BSS added handling!");
748 wifi_state_set_bss_found(TRUE);
753 static void _supplicant_scan_done(GDBusConnection *conn,
754 const gchar *name, const gchar *path, const gchar *interface,
755 const gchar *sig, GVariant *param, gpointer user_data)
757 DBG("Scan Done handling!");
758 netconfig_wifi_set_scanning(FALSE);
760 if (netconfig_wifi_is_bssid_scan_started() == TRUE) {
761 netconfig_wifi_bssid_signal_scandone();
762 if (wifi_state_get_technology_state() < NETCONFIG_WIFI_TECH_POWERED)
766 if (netconfig_wifi_get_bgscan_state() == TRUE) {
767 if (wifi_state_get_technology_state() >=
768 NETCONFIG_WIFI_TECH_POWERED)
769 netconfig_wifi_bgscan_start(FALSE);
771 wifi_start_timer_network_notification();
777 static void _supplicant_driver_hanged(GDBusConnection *conn,
778 const gchar *name, const gchar *path, const gchar *interface,
779 const gchar *sig, GVariant *param, gpointer user_data)
781 DBG("Driver Hanged handling!");
782 ERR("Critical. Wi-Fi firmware crashed");
784 #if !defined TIZEN_WEARABLE
785 netconfig_send_message_to_net_popup("Wi-Fi Error",
786 "Wi-Fi Driver Hanged. Please get log dump and report", "popup", NULL);
788 wifi_power_recover_firmware();
794 static void _supplicant_session_overlapped(GDBusConnection *conn,
795 const gchar *name, const gchar *path, const gchar *interface,
796 const gchar *sig, GVariant *param, gpointer user_data)
798 DBG("Driver session overlapped handling!");
799 ERR("WPS PBC SESSION OVERLAPPED");
800 #if defined TIZEN_WEARABLE
803 netconfig_send_message_to_net_popup("WPS Error",
804 "wps session overlapped", "popup", NULL);
808 #if defined TIZEN_DEBUG_ENABLE
809 static void __netconfig_dumpservice_handler(GDBusConnection *conn,
810 const gchar *name, const gchar *path, const gchar *interface,
811 const gchar *sig, GVariant *param, gpointer user_data)
814 gchar *signal_path = NULL;
819 g_variant_get(param, "(is)", &mode, &signal_path);
820 DBG("Path: %s and mode: %d", signal_path, mode);
822 netconfig_dump_log(signal_path);
830 static void _supplicant_tdls_connected(GDBusConnection *conn,
831 const gchar *name, const gchar *path, const gchar *interface,
832 const gchar *sig, GVariant *param, gpointer user_data)
834 DBG("Received TDLS Connected Signal");
835 netconfig_wifi_tdls_connected_event(param);
840 static void _supplicant_tdls_disconnected(GDBusConnection *conn,
841 const gchar *name, const gchar *path, const gchar *interface,
842 const gchar *sig, GVariant *param, gpointer user_data)
844 DBG("Received TDLS Disconnected Signal");
845 netconfig_wifi_tdls_disconnected_event(param);
850 static void _supplicant_tdls_peer_found(GDBusConnection *conn,
851 const gchar *name, const gchar *path, const gchar *interface,
852 const gchar *sig, GVariant *param, gpointer user_data)
854 DBG("Received TDLS Peer Found Signal");
855 netconfig_wifi_tdls_peer_found_event(param);
859 static void _supplicant_wifi_wps_connected(GVariant *param)
862 char ssid[32] = {0, };
866 int config_error = 0;
867 int error_indication = 0;
871 ERR("Param is NULL");
875 g_variant_get(param, "(sa{sv})", &name, &iter);
876 INFO("wps Result: %s", name);
877 while (g_variant_iter_loop(iter, "{sv}", &key, &variant)) {
878 INFO("wps Key is %s", key);
879 if (g_strcmp0(key, "SSID") == 0) {
880 const char *t_key = NULL;
881 t_key = g_variant_get_fixed_array(variant, &ssid_len, sizeof(guchar));
882 INFO("wps ssid_len is %zd ", ssid_len);
885 g_variant_unref(variant);
886 ERR("WPS PBC Connection Failed");
889 if (ssid_len > 0 && ssid_len <= 32) {
890 memcpy(ssid, t_key, ssid_len);
892 memset(ssid, 0, sizeof(ssid));
895 INFO("WPS PBC Connection completed with AP %s", ssid);
896 netconfig_wifi_notify_wps_completed(ssid, ssid_len);
900 g_variant_iter_free(iter);
905 g_variant_iter_free(iter);
907 error_indication = WPS_EI_OPERATION_FAILED;
908 config_error = WPS_CFG_NO_ERROR;
909 ERR("Error Occured! Notifying Fail Event");
910 netconfig_wifi_notify_wps_fail_event(config_error, error_indication);
914 static void _supplicant_wifi_wps_event(GVariant *param)
920 gint32 config_error = 0;
921 gint32 error_indication = 0;
924 ERR("Param is NULL");
928 g_variant_get(param, "(sa{sv})", &name, &iter);
929 INFO("Event Result: %s", name);
930 if (g_strcmp0(name, "fail") == 0) {
931 while (g_variant_iter_loop(iter, "{sv}", &key, &variant)) {
934 INFO("Key is %s", key);
935 if (g_strcmp0(key, "config_error") == 0) {
936 config_error = g_variant_get_int32(variant);
937 ERR("Config Error %d", config_error);
938 } else if (g_strcmp0(key, "error_indication") == 0) {
939 error_indication = g_variant_get_int32(variant);
940 ERR("Error Indication %d", error_indication);
943 netconfig_wifi_notify_wps_fail_event(config_error, error_indication);
946 g_variant_iter_free(iter);
951 g_variant_iter_free(iter);
953 error_indication = WPS_EI_OPERATION_FAILED;
954 config_error = WPS_CFG_NO_ERROR;
955 ERR("Error Occured! Notifying Fail Event");
956 netconfig_wifi_notify_wps_fail_event(config_error, error_indication);
959 static void _find_service_and_set_passphrase(char *ssid, char *key)
962 GVariant *reply = NULL;
967 gchar *enc_passphrase;
969 ssid_len = strlen(ssid);
971 str = g_string_sized_new((ssid_len * 2) + 55);
975 dev_mac_addr = vconf_get_str(VCONFKEY_WIFI_BSSID_ADDRESS);
977 ERR("Failed to get mac address from vconf key");
978 g_string_free(str, TRUE);
983 for (i = 0; dev_mac_addr[i]; i++) {
984 if (dev_mac_addr[i] != ':')
985 ident[j++] = dev_mac_addr[i];
989 g_string_append_printf(str, "%s%s_", CONNMAN_WIFI_SERVICE_PROFILE_PREFIX,
993 for (i = 0; i < ssid_len; i++) {
995 g_string_append_printf(str, "%02x", ssid[i]);
998 g_string_append_printf(str, "_managed_psk");
1000 service_path = g_string_free(str, FALSE);
1002 enc_passphrase = _netconfig_encrypt_passphrase(key);
1003 if (!enc_passphrase) {
1004 ERR("Failed to encrypt passphrase");
1005 g_free(service_path);
1009 INFO("wps service_path %s Passphrase %s", service_path, enc_passphrase);
1011 reply = netconfig_invoke_dbus_method(CONNMAN_SERVICE, service_path,
1012 CONNMAN_SERVICE_INTERFACE, "SetProperty",
1013 g_variant_new("(sv)", "Passphrase",
1014 g_variant_new_string(enc_passphrase)));
1016 g_variant_unref(reply);
1018 ERR("Failed to set passphrase");
1020 g_free(service_path);
1025 static void _supplicant_wifi_wps_credentials(GVariant *param)
1028 char ssid[32] = {0, };
1029 char wps_key[100] = {0, };
1032 int config_error = 0;
1033 int error_indication = 0;
1035 char *key_mgmt = NULL;
1037 if (param == NULL) {
1038 ERR("Param is NULL");
1042 g_variant_get(param, "(a{sv})", &iter);
1043 while (g_variant_iter_loop(iter, "{sv}", &key, &variant)) {
1046 INFO("wps Key is %s", key);
1047 if (g_strcmp0(key, "Key") == 0) {
1049 const char *t_key = NULL;
1050 key_len = g_variant_get_size(variant);
1052 INFO("wps password len %zd ", key_len);
1054 t_key = g_variant_get_fixed_array(variant, &key_len,
1058 g_variant_unref(variant);
1061 strncpy(wps_key, t_key, key_len);
1062 wps_key[key_len] = '\0';
1063 INFO("WPS Key in process credentials %s", wps_key);
1065 SLOGI("WPS AP Security ->Open");
1066 } else if (g_strcmp0(key, "SSID") == 0) {
1067 const char *t_key = NULL;
1068 t_key = g_variant_get_fixed_array(variant, &ssid_len,
1070 INFO("wps ssid_len is %zd ", ssid_len);
1073 g_variant_unref(variant);
1076 if (ssid_len > 0 && ssid_len <= 32) {
1077 memcpy(ssid, t_key, ssid_len);
1079 memset(ssid, 0, sizeof(ssid));
1082 INFO("SSID in process credentials %s", ssid);
1083 } else if (g_strcmp0(key, "AuthType") == 0) {
1085 GVariantIter *var_iter;
1086 g_variant_get(variant, "as", &var_iter);
1087 while (g_variant_iter_loop(var_iter, "s", &auth_type)) {
1088 INFO("wps auth_type %s", auth_type);
1089 if (g_strcmp0(auth_type, "wpa-psk") == 0 ||
1090 g_strcmp0(auth_type, "wpa2-psk") == 0)
1092 else if (g_strcmp0(auth_type, "open") == 0)
1095 g_variant_iter_free(var_iter);
1096 } else if (g_strcmp0(key, "EncrType") == 0) {
1098 GVariantIter *var_iter;
1099 g_variant_get(variant, "as", &var_iter);
1100 while (g_variant_iter_loop(var_iter, "s", &encr_type))
1101 INFO("wps encr_type %s", encr_type);
1102 g_variant_iter_free(var_iter);
1103 } else if (g_strcmp0(key, "BSSID") == 0) {
1104 const guchar *bssid;
1106 bssid = g_variant_get_fixed_array(variant, &bssid_len,
1108 if (bssid && bssid_len == 6)
1109 INFO("wps BSSID %2x:%2x:%2x:%2x:%2x:%2x", bssid[0], bssid[1],
1110 bssid[2], bssid[3], bssid[4], bssid[5]);
1114 g_variant_iter_free(iter);
1116 if (g_strcmp0(key_mgmt, "psk") == 0)
1117 _find_service_and_set_passphrase(ssid, wps_key);
1121 * Notify WPS Credentials only when requested through WPS PBC
1122 * In case of WPS PIN connman will take care of notification
1124 if (netconfig_get_wps_field() == TRUE)
1126 netconfig_wifi_notify_wps_credentials(ssid, ssid_len, wps_key);
1130 g_variant_iter_free(iter);
1131 error_indication = WPS_EI_OPERATION_FAILED;
1132 config_error = WPS_CFG_NO_ERROR;
1133 ERR("Error Occured! Notifying Fail Event");
1134 netconfig_wifi_notify_wps_fail_event(config_error, error_indication);
1137 static void __netconfig_wps_signal_filter_handler(GDBusConnection *conn,
1138 const gchar *name, const gchar *path, const gchar *interface,
1139 const gchar *sig, GVariant *param, gpointer user_data)
1141 if (g_strcmp0(sig, SIGNAL_WPS_CREDENTIALS) == 0) {
1142 INFO("Received wps CREDENTIALS Signal from Supplicant");
1143 _supplicant_wifi_wps_credentials(param);
1144 } else if (g_strcmp0(sig, SIGNAL_WPS_EVENT) == 0) {
1145 INFO("Received wps EVENT Signal from Supplicant");
1146 _supplicant_wifi_wps_event(param);
1147 } else if (g_strcmp0(sig, SIGNAL_WPS_CONNECTED) == 0) {
1148 INFO("Received WPSConnected Signal from Supplicant");
1149 _supplicant_wifi_wps_connected(param);
1155 static supplicant_signal_cb supplicant_cbs[SIG_MAX] = {
1156 _supplicant_interface_removed,
1157 _supplicant_properties_changed,
1158 _supplicant_bss_added,
1159 _supplicant_scan_done,
1160 _supplicant_driver_hanged,
1161 _supplicant_session_overlapped,
1162 _supplicant_tdls_connected,
1163 _supplicant_tdls_disconnected,
1164 _supplicant_tdls_peer_found
1167 void register_gdbus_signal(void)
1169 GDBusConnection *connection = NULL;
1170 const char *interface = NULL;
1171 SuppSigArrayIndex sig;
1172 connection = netdbus_get_connection();
1174 if (connection == NULL) {
1175 ERR("Failed to get GDbus Connection");
1179 /* listening to messages from all objects as no path is specified */
1180 /* see signals from the given interface */
1181 conn_subscription_ids[0] = g_dbus_connection_signal_subscribe(
1184 CONNMAN_TECHNOLOGY_INTERFACE,
1188 G_DBUS_SIGNAL_FLAGS_NONE,
1189 _technology_signal_cb,
1193 conn_subscription_ids[1] = g_dbus_connection_signal_subscribe(
1196 CONNMAN_SERVICE_INTERFACE,
1197 CONNMAN_SIGNAL_PROPERTY_CHANGED,
1200 G_DBUS_SIGNAL_FLAGS_NONE,
1205 conn_subscription_ids[2] = g_dbus_connection_signal_subscribe(
1208 DBUS_INTERFACE_DBUS,
1209 CONNMAN_SIGNAL_NAME_CHANGED,
1212 G_DBUS_SIGNAL_FLAGS_NONE,
1213 _dbus_name_changed_cb,
1217 conn_subscription_ids[3] = g_dbus_connection_signal_subscribe(
1220 CONNMAN_MANAGER_INTERFACE,
1221 CONNMAN_SIGNAL_SERVICES_CHANGED,
1224 G_DBUS_SIGNAL_FLAGS_NONE,
1225 _services_changed_cb,
1229 INFO("Successfully register connman DBus signal filters");
1231 conn_subscription_ids[4] = g_dbus_connection_signal_subscribe(
1234 SUPPLICANT_INTERFACE ".Interface.WPS",
1238 G_DBUS_SIGNAL_FLAGS_NONE,
1239 __netconfig_wps_signal_filter_handler,
1243 INFO("Successfully register Supplicant WPS DBus signal filters");
1245 for (sig = SIG_INTERFACE_REMOVED; sig < SIG_MAX; sig++) {
1247 * For SIG_INTERFACE_REMOVED INTERFACE_ADDED
1249 interface = (sig == SIG_INTERFACE_REMOVED) ?
1250 SUPPLICANT_INTERFACE : SUPPLICANT_IFACE_INTERFACE;
1252 supp_subscription_ids[sig] = g_dbus_connection_signal_subscribe(
1256 supplicant_signals[sig],
1259 G_DBUS_SIGNAL_FLAGS_NONE,
1260 supplicant_cbs[sig],
1265 INFO("Successfully register Supplicant DBus signal filters");
1267 #if defined TIZEN_DEBUG_ENABLE
1268 dumpservice_subscription_id = g_dbus_connection_signal_subscribe(
1271 DUMP_SERVICE_INTERFACE,
1275 G_DBUS_SIGNAL_FLAGS_NONE,
1276 __netconfig_dumpservice_handler,
1280 INFO("Successfully registered Dumpservice DBus signal filter");
1283 /* In case ConnMan precedes this signal register,
1284 * net-config should update the default connected profile.
1286 netconfig_update_default();
1289 void deregister_gdbus_signal(void)
1291 GDBusConnection *connection = NULL;
1293 SuppSigArrayIndex sig;
1294 connection = netdbus_get_connection();
1296 ERR("Already de-registered. Nothing to be done");
1300 for (signal = 0; signal < TOTAL_CONN_SIGNALS; signal++) {
1301 if (conn_subscription_ids[signal]) {
1302 g_dbus_connection_signal_unsubscribe(connection,
1303 conn_subscription_ids[signal]);
1307 for (sig = SIG_INTERFACE_REMOVED; sig < SIG_MAX; sig++) {
1308 if (supp_subscription_ids[sig]) {
1309 g_dbus_connection_signal_unsubscribe(connection,
1310 supp_subscription_ids[sig]);
1314 #if defined TIZEN_DEBUG_ENABLE
1315 g_dbus_connection_signal_unsubscribe(connection,
1316 dumpservice_subscription_id);