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>
31 #include "wifi-bssid-scan.h"
32 #include "wifi-agent.h"
33 #include "wifi-power.h"
34 #include "wifi-state.h"
35 #include "netsupplicant.h"
36 #include "network-state.h"
37 #include "cellular-state.h"
38 #include "signal-handler.h"
39 #include "wifi-background-scan.h"
40 #include "wifi-tdls.h"
41 #include "ip-conflict-detect.h"
42 #if defined TIZEN_DEBUG_ENABLE
43 #include "network-dump.h"
46 #define DBUS_SERVICE_DBUS "org.freedesktop.DBus"
47 #define DBUS_INTERFACE_DBUS "org.freedesktop.DBus"
48 #define SIGNAL_INTERFACE_REMOVED "InterfaceRemoved"
49 #define SIGNAL_SCAN_DONE "ScanDone"
50 #define SIGNAL_BSS_ADDED "BSSAdded"
51 #define SIGNAL_PROPERTIES_CHANGED "PropertiesChanged"
52 #define SIGNAL_PROPERTIES_DRIVER_HANGED "DriverHanged"
53 #define SIGNAL_PROPERTIES_SESSION_OVERLAPPED "SessionOverlapped"
54 #define SIGNAL_TDLS_CONNECTED "TDLSConnected"
55 #define SIGNAL_TDLS_DISCONNECTED "TDLSDisconnected"
56 #define SIGNAL_TDLS_PEER_FOUND "TDLSPeerFound"
58 #define SIGNAL_WPS_CONNECTED "WPSConnected"
59 #define SIGNAL_WPS_EVENT "Event"
60 #define SIGNAL_WPS_CREDENTIALS "Credentials"
62 #define CONNMAN_SIGNAL_SERVICES_CHANGED "ServicesChanged"
63 #define CONNMAN_SIGNAL_PROPERTY_CHANGED "PropertyChanged"
64 #define CONNMAN_SIGNAL_NAME_CHANGED "NameOwnerChanged"
66 #define MAX_SIG_LEN 64
67 #define TOTAL_CONN_SIGNALS 5
68 #define MAX_SOCKET_OPEN_RETRY 5
71 SIG_INTERFACE_REMOVED = 0,
72 SIG_PROPERTIES_CHANGED,
76 SIG_SESSION_OVERLAPPED,
78 SIG_TDLS_DISCONNECTED,
83 static int conn_subscription_ids[TOTAL_CONN_SIGNALS] = {0};
84 static const char supplicant_signals[SIG_MAX][MAX_SIG_LEN] = {
85 SIGNAL_INTERFACE_REMOVED,
86 SIGNAL_PROPERTIES_CHANGED,
89 SIGNAL_PROPERTIES_DRIVER_HANGED,
90 SIGNAL_PROPERTIES_SESSION_OVERLAPPED,
91 SIGNAL_TDLS_CONNECTED,
92 SIGNAL_TDLS_DISCONNECTED,
93 SIGNAL_TDLS_PEER_FOUND,
96 static int supp_subscription_ids[SIG_MAX] = {0};
97 #if defined TIZEN_DEBUG_ENABLE
98 static int dumpservice_subscription_id = 0;
101 typedef void (*supplicant_signal_cb)(GDBusConnection *conn,
102 const gchar *name, const gchar *path, const gchar *interface,
103 const gchar *sig, GVariant *param, gpointer user_data);
104 typedef void (*connman_signal_cb)(GDBusConnection *conn,
105 const gchar *name, const gchar *path, const gchar *interface,
106 const gchar *sig, GVariant *param, gpointer user_data);
108 static void __netconfig_extract_ipv4_signal_data(GVariant *dictionary,
109 const gchar *profile)
112 const gchar *value = NULL;
113 GVariant *var = NULL;
115 GVariantBuilder *builder;
118 g_variant_iter_init(&iter, dictionary);
119 while (g_variant_iter_loop(&iter, "{sv}", &key, &var)) {
120 if (g_strcmp0(key, "Address") == 0) {
121 g_variant_get(var, "&s", &value);
122 char *old_ip = vconf_get_str(VCONFKEY_NETWORK_IP);
124 DBG("Old IPv4.Address [%s] Received new IPv4.Address [%s]", old_ip,
126 if (g_strcmp0(old_ip, value) != 0) {
127 builder = g_variant_builder_new(G_VARIANT_TYPE("a{sv}"));
130 vconf_set_str(VCONFKEY_NETWORK_IP, value);
131 g_variant_builder_add(builder, "{sv}", "IPv4Address",
132 g_variant_new_string(value));
133 } else if (old_ip != NULL && strlen(old_ip) > 0) {
134 vconf_set_str(VCONFKEY_NETWORK_IP, "");
135 g_variant_builder_add(builder, "{sv}", "IPv4Address",
136 g_variant_new_string(""));
139 params = g_variant_new("(@a{sv})",
140 g_variant_builder_end(builder));
142 netconfig_dbus_emit_signal(NULL, NETCONFIG_NETWORK_PATH,
143 NETCONFIG_NETWORK_INTERFACE, "NetworkConfigChanged",
151 static void __netconfig_extract_ipv6_signal_data(GVariant *dictionary,
152 const gchar *profile)
155 const gchar *value = NULL;
156 GVariant *var = NULL;
158 GVariantBuilder *builder;
161 g_variant_iter_init(&iter, dictionary);
162 while (g_variant_iter_loop(&iter, "{sv}", &key, &var)) {
163 if (g_strcmp0(key, "Address") == 0) {
164 g_variant_get(var, "&s", &value);
165 char *old_ip6 = vconf_get_str(VCONFKEY_NETWORK_IP6);
167 DBG("Old IPv6.Address [%s] Received new IPv6.Address [%s]", old_ip6,
169 if (g_strcmp0(old_ip6, value) != 0) {
170 builder = g_variant_builder_new(G_VARIANT_TYPE("a{sv}"));
173 vconf_set_str(VCONFKEY_NETWORK_IP6, value);
174 g_variant_builder_add(builder, "{sv}", "IPv6Address",
175 g_variant_new_string(value));
176 } else if (old_ip6 != NULL && strlen(old_ip6) > 0) {
177 vconf_set_str(VCONFKEY_NETWORK_IP6, "");
178 g_variant_builder_add(builder, "{sv}", "IPv6Address",
179 g_variant_new_string(""));
182 params = g_variant_new("(@a{sv})",
183 g_variant_builder_end(builder));
185 netconfig_dbus_emit_signal(NULL, NETCONFIG_NETWORK_PATH,
186 NETCONFIG_NETWORK_INTERFACE, "NetworkConfigChanged",
194 static void _technology_signal_cb(GDBusConnection *conn,
195 const gchar *name, const gchar *path, const gchar *interface,
196 const gchar *sig, GVariant *param, gpointer user_data)
199 gboolean value = FALSE;
200 GVariant *var = NULL;
205 if (g_str_has_prefix(path, CONNMAN_WIFI_TECHNOLOGY_PREFIX) == TRUE) {
206 g_variant_get(param, "(sv)", &key, &var);
207 if (g_strcmp0(key, "Powered") == 0) {
209 value = g_variant_get_boolean(var);
211 wifi_state_update_power_state(TRUE);
213 wifi_state_update_power_state(FALSE);
214 } else if (g_strcmp0(key, "Connected") == 0) {
215 /* Connection state */
216 value = g_variant_get_boolean(var);
218 wifi_state_set_tech_state(NETCONFIG_WIFI_TECH_CONNECTED);
220 wifi_state_set_tech_state(NETCONFIG_WIFI_TECH_POWERED);
221 } else if (g_strcmp0(key, "Tethering") == 0) {
222 /* Tethering state */
223 wifi_state_set_tech_state(NETCONFIG_WIFI_TECH_TETHERED);
228 g_variant_unref(var);
232 static void _service_signal_cb(GDBusConnection *conn,
233 const gchar *name, const gchar *path,
234 const gchar *interface, const gchar *sig,
235 GVariant *param, gpointer user_data)
237 gchar *sigvalue = NULL;
239 GVariant *variant = NULL, *var;
241 const gchar *value = NULL;
242 struct sock_data *sd = NULL;
245 if (path == NULL || param == NULL)
248 g_variant_get(param, "(sv)", &sigvalue, &variant);
249 if (sigvalue == NULL)
252 if (g_strcmp0(sig, CONNMAN_SIGNAL_PROPERTY_CHANGED) != 0)
255 if (g_strcmp0(sigvalue, "State") == 0) {
256 g_variant_get(variant, "s", &property);
258 DBG("[%s] %s", property, path);
259 if (netconfig_is_wifi_profile(path) || netconfig_is_ethernet_profile(path)) {
260 if (g_strcmp0(property, "ready") == 0) {
261 for (idx = 0; idx < MAX_SOCKET_OPEN_RETRY; idx++) {
262 sd = start_ip_conflict_mon();
266 } else if (g_strcmp0(property, "online") == 0) {
269 stop_ip_conflict_mon();
273 if (netconfig_is_wifi_profile(path) == TRUE) {
276 netconfig_vconf_get_int(VCONFKEY_WIFI_STATE, &wifi_state);
277 if (wifi_state == VCONFKEY_WIFI_OFF) {
282 if (g_strcmp0(property, "ready") == 0 || g_strcmp0(property, "online") == 0) {
283 if (wifi_state >= VCONFKEY_WIFI_CONNECTED) {
288 netconfig_update_default_profile(path);
290 wifi_state_set_service_state(NETCONFIG_WIFI_CONNECTED);
292 } else if (g_strcmp0(property, "failure") == 0 || g_strcmp0(property, "disconnect") == 0 || g_strcmp0(property, "idle") == 0) {
293 if (netconfig_get_default_profile() == NULL ||
294 netconfig_is_wifi_profile(netconfig_get_default_profile())
296 if (g_strcmp0(property, "failure") == 0)
297 wifi_state_set_service_state(NETCONFIG_WIFI_FAILURE);
299 wifi_state_set_service_state(NETCONFIG_WIFI_IDLE);
304 if (g_strcmp0(path, netconfig_get_default_profile()) != 0) {
309 netconfig_update_default_profile(NULL);
311 if (g_strcmp0(property, "failure") == 0)
312 wifi_state_set_service_state(NETCONFIG_WIFI_FAILURE);
314 wifi_state_set_service_state(NETCONFIG_WIFI_IDLE);
316 } else if (g_strcmp0(property, "association") == 0 || g_strcmp0(property, "configuration") == 0) {
317 if (netconfig_get_default_profile() == NULL ||
318 netconfig_is_wifi_profile(netconfig_get_default_profile()) != TRUE) {
319 if (g_strcmp0(property, "association") == 0)
320 wifi_state_set_service_state(NETCONFIG_WIFI_ASSOCIATION);
322 wifi_state_set_service_state(NETCONFIG_WIFI_CONFIGURATION);
327 if (g_strcmp0(path, netconfig_get_default_profile()) != 0) {
332 netconfig_update_default_profile(NULL);
334 if (g_strcmp0(property, "association") == 0)
335 wifi_state_set_service_state(NETCONFIG_WIFI_ASSOCIATION);
337 wifi_state_set_service_state(NETCONFIG_WIFI_CONFIGURATION);
341 if (g_strcmp0(property, "ready") == 0 || g_strcmp0(property, "online") == 0) {
342 if (netconfig_get_default_profile() == NULL) {
343 if (!netconfig_is_cellular_profile(path))
344 netconfig_update_default_profile(path);
346 if (netconfig_is_cellular_internet_profile(path))
347 netconfig_update_default_profile(path);
351 if (netconfig_is_cellular_profile(path) && netconfig_is_cellular_internet_profile(path))
352 cellular_state_set_service_state(NETCONFIG_CELLULAR_ONLINE);
354 } else if (g_strcmp0(property, "failure") == 0 || g_strcmp0(property, "disconnect") == 0 || g_strcmp0(property, "idle") == 0) {
355 if (netconfig_get_default_profile() == NULL) {
360 if (netconfig_is_cellular_profile(path) && netconfig_is_cellular_internet_profile(path))
361 cellular_state_set_service_state(NETCONFIG_CELLULAR_IDLE);
363 if (g_strcmp0(path, netconfig_get_default_profile()) != 0) {
368 netconfig_update_default_profile(NULL);
369 } else if (g_strcmp0(property, "association") == 0 || g_strcmp0(property, "configuration") == 0) {
370 if (netconfig_get_default_profile() == NULL) {
375 if (netconfig_is_cellular_profile(path) && netconfig_is_cellular_internet_profile(path))
376 cellular_state_set_service_state(NETCONFIG_CELLULAR_CONNECTING);
378 if (g_strcmp0(path, netconfig_get_default_profile()) != 0) {
383 netconfig_update_default_profile(NULL);
387 } else if (g_strcmp0(sigvalue, "Proxy") == 0) {
388 if (netconfig_is_wifi_profile(path) != TRUE || g_strcmp0(path, netconfig_get_default_profile()) != 0)
391 if (!g_variant_type_equal(variant, G_VARIANT_TYPE_ARRAY))
394 g_variant_get(variant, "a{sv}", &iter);
395 while (g_variant_iter_loop(iter, "{sv}", &property, &var)) {
396 GVariantBuilder *builder;
397 GVariant *sig_params;
398 if (g_strcmp0(property, "Servers") == 0) {
399 GVariantIter *iter_sub = NULL;
401 builder = g_variant_builder_new(G_VARIANT_TYPE("a{sv}"));
403 g_variant_get(var, "as", &iter_sub);
404 g_variant_iter_loop(iter_sub, "s", &value);
405 g_variant_iter_free(iter_sub);
407 DBG("Proxy - [%s]", value);
408 vconf_set_str(VCONFKEY_NETWORK_PROXY, value);
410 g_variant_builder_add(builder, "{sv}", "ProxyAddress",
411 g_variant_new_string(value));
413 sig_params = g_variant_new("(@a{sv})",
414 g_variant_builder_end(builder));
416 netconfig_dbus_emit_signal(NULL, NETCONFIG_NETWORK_PATH,
417 NETCONFIG_NETWORK_INTERFACE, "NetworkConfigChanged",
421 g_variant_unref(var);
423 } else if (g_strcmp0(property, "Method") == 0) {
424 value = g_variant_get_string(var, NULL);
425 DBG("Method - [%s]", value);
427 if (g_strcmp0(value, "direct") == 0) {
428 builder = g_variant_builder_new(G_VARIANT_TYPE("a{sv}"));
430 vconf_set_str(VCONFKEY_NETWORK_PROXY, "");
431 g_variant_builder_add(builder, "{sv}", "ProxyAddress",
432 g_variant_new_string(""));
434 sig_params = g_variant_new("(@a{sv})",
435 g_variant_builder_end(builder));
437 netconfig_dbus_emit_signal(NULL, NETCONFIG_NETWORK_PATH,
438 NETCONFIG_NETWORK_INTERFACE,
439 "NetworkConfigChanged", sig_params);
443 g_variant_unref(var);
448 g_variant_iter_free(iter);
449 } else if (g_strcmp0(sigvalue, "IPv4") == 0) {
450 __netconfig_extract_ipv4_signal_data(variant, path);
451 } else if (g_strcmp0(sigvalue, "IPv6") == 0) {
452 __netconfig_extract_ipv6_signal_data(variant, path);
453 } else if (g_strcmp0(sigvalue, "Error") == 0) {
454 g_variant_get(variant, "s", &property);
455 INFO("[%s] Property : %s", sigvalue, property);
463 g_variant_unref(variant);
468 static void _dbus_name_changed_cb(GDBusConnection *conn,
469 const gchar *Name, const gchar *path, const gchar *interface,
470 const gchar *sig, GVariant *param, gpointer user_data)
479 g_variant_get(param, "(sss)", &name, &old, &new);
481 if (g_strcmp0(name, CONNMAN_SERVICE) == 0 && *new == '\0') {
482 DBG("ConnMan destroyed: name %s, old %s, new %s", name, old, new);
484 connman_register_agent();
496 static void _services_changed_cb(GDBusConnection *conn, const gchar *name,
497 const gchar *path, const gchar *interface, const gchar *sig,
498 GVariant *param, gpointer user_data)
500 gchar *property, *value;
502 GVariant *variant = NULL;
503 GVariantIter *added = NULL, *removed = NULL, *next = NULL;
505 if (path == NULL || param == NULL)
508 if (g_strcmp0(sig, CONNMAN_SIGNAL_SERVICES_CHANGED) != 0)
511 if (netconfig_get_default_profile() != NULL)
514 g_variant_get(param, "(a(oa{sv})ao)", &added, &removed);
516 while (g_variant_iter_loop(added, "(oa{sv})", &service_path, &next)) {
517 gboolean is_wifi_prof, is_cell_prof, is_cell_internet_prof;
518 is_wifi_prof = netconfig_is_wifi_profile(service_path);
519 is_cell_prof = netconfig_is_cellular_profile(service_path);
520 is_cell_internet_prof = netconfig_is_cellular_internet_profile(
522 if (service_path != NULL) {
523 while (next && g_variant_iter_loop(next, "{sv}", &property,
525 if (g_strcmp0(property, "State") == 0) {
526 g_variant_get(variant, "s", &value);
527 DBG("Profile %s State %s", service_path,
529 if (g_strcmp0(value, "ready") != 0 &&
534 g_variant_unref(variant);
539 netconfig_update_default_profile(
541 else if (is_cell_internet_prof) {
542 netconfig_update_default_profile(
546 wifi_state_set_service_state(
547 NETCONFIG_WIFI_CONNECTED);
548 else if (is_cell_prof &&
549 is_cell_internet_prof)
550 cellular_state_set_service_state(
551 NETCONFIG_CELLULAR_ONLINE);
554 g_variant_unref(variant);
561 g_variant_iter_free(added);
564 g_variant_iter_free(next);
567 g_variant_iter_free(removed);
572 static void _supplicant_interface_removed(GDBusConnection *conn,
573 const gchar *name, const gchar *path, const gchar *interface,
574 const gchar *sig, GVariant *param, gpointer user_data)
576 DBG("Interface removed handling!");
577 if (netconfig_wifi_is_bssid_scan_started() == TRUE)
578 netconfig_wifi_bssid_signal_scanaborted();
583 static void _supplicant_properties_changed(GDBusConnection *conn,
584 const gchar *name, const gchar *path, const gchar *interface,
585 const gchar *sig, GVariant *param, gpointer user_data)
587 DBG("Properties changed handling!");
589 const gchar *state = NULL;
590 GVariantIter *iter = NULL;
591 GVariant *variant = NULL;
592 gboolean scanning = FALSE;
597 g_variant_get(param, "(a{sv})", &iter);
598 while (g_variant_iter_loop(iter, "{sv}", &key, &variant)) {
599 if (g_strcmp0(key, "Scanning") == 0) {
600 scanning = g_variant_get_boolean(variant);
601 DBG("setting scanning %s", scanning ? "TRUE" : "FALSE");
602 if (scanning == TRUE)
603 netconfig_wifi_set_scanning(TRUE);
605 netconfig_wifi_set_scanning(FALSE);
607 g_variant_unref(variant);
612 } else if (g_strcmp0(key, "State") == 0) {
613 state = g_variant_get_string(variant, NULL);
615 ERR("Supplicant state : %s", state);
617 g_variant_unref(variant);
622 } else if (g_strcmp0(key, "DisconnectReason") == 0) {
623 int reason = g_variant_get_int32(variant);
624 ERR("Supplicant DisconnReason : %d", reason);
626 g_variant_unref(variant);
633 value = g_variant_print(variant, TRUE);
634 DBG("Supplicant %s : %s", key, value);
640 g_variant_iter_free(iter);
645 static void _supplicant_bss_added(GDBusConnection *conn,
646 const gchar *name, const gchar *path, const gchar *interface,
647 const gchar *sig, GVariant *param, gpointer user_data)
649 DBG("BSS added handling!");
650 wifi_state_set_bss_found(TRUE);
655 static void _supplicant_scan_done(GDBusConnection *conn,
656 const gchar *name, const gchar *path, const gchar *interface,
657 const gchar *sig, GVariant *param, gpointer user_data)
659 DBG("Scan Done handling!");
660 netconfig_wifi_set_scanning(FALSE);
662 if (netconfig_wifi_is_bssid_scan_started() == TRUE) {
663 netconfig_wifi_bssid_signal_scandone();
664 if (wifi_state_get_technology_state() < NETCONFIG_WIFI_TECH_POWERED)
668 if (netconfig_wifi_get_bgscan_state() == TRUE) {
669 if (wifi_state_get_technology_state() >=
670 NETCONFIG_WIFI_TECH_POWERED)
671 netconfig_wifi_bgscan_start(FALSE);
673 wifi_start_timer_network_notification();
679 static void _supplicant_driver_hanged(GDBusConnection *conn,
680 const gchar *name, const gchar *path, const gchar *interface,
681 const gchar *sig, GVariant *param, gpointer user_data)
683 DBG("Driver Hanged handling!");
684 ERR("Critical. Wi-Fi firmware crashed");
686 #if !defined TIZEN_WEARABLE
687 netconfig_send_message_to_net_popup("Wi-Fi Error",
688 "Wi-Fi Driver Hanged. Please get log dump and report", "popup", NULL);
690 wifi_power_recover_firmware();
696 static void _supplicant_session_overlapped(GDBusConnection *conn,
697 const gchar *name, const gchar *path, const gchar *interface,
698 const gchar *sig, GVariant *param, gpointer user_data)
700 DBG("Driver session overlapped handling!");
701 ERR("WPS PBC SESSION OVERLAPPED");
702 #if defined TIZEN_WEARABLE
705 netconfig_send_message_to_net_popup("WPS Error",
706 "wps session overlapped", "popup", NULL);
710 #if defined TIZEN_DEBUG_ENABLE
711 static void __netconfig_dumpservice_handler(GDBusConnection *conn,
712 const gchar *name, const gchar *path, const gchar *interface,
713 const gchar *sig, GVariant *param, gpointer user_data)
716 gchar *signal_path = NULL;
721 g_variant_get(param, "(is)", &mode, &signal_path);
722 DBG("Path: %s and mode: %d", signal_path, mode);
724 netconfig_dump_log(signal_path);
732 static void _supplicant_tdls_connected(GDBusConnection *conn,
733 const gchar *name, const gchar *path, const gchar *interface,
734 const gchar *sig, GVariant *param, gpointer user_data)
736 DBG("Received TDLS Connected Signal");
737 netconfig_wifi_tdls_connected_event(param);
742 static void _supplicant_tdls_disconnected(GDBusConnection *conn,
743 const gchar *name, const gchar *path, const gchar *interface,
744 const gchar *sig, GVariant *param, gpointer user_data)
746 DBG("Received TDLS Disconnected Signal");
747 netconfig_wifi_tdls_disconnected_event(param);
752 static void _supplicant_tdls_peer_found(GDBusConnection *conn,
753 const gchar *name, const gchar *path, const gchar *interface,
754 const gchar *sig, GVariant *param, gpointer user_data)
756 DBG("Received TDLS Peer Found Signal");
757 netconfig_wifi_tdls_peer_found_event(param);
761 static void _supplicant_wifi_wps_connected(GVariant *param)
764 char ssid[32] = {0, };
768 int config_error = 0;
769 int error_indication = 0;
773 ERR("Param is NULL");
777 g_variant_get(param, "(sa{sv})", &name, &iter);
778 INFO("wps Result: %s", name);
779 while (g_variant_iter_loop(iter, "{sv}", &key, &variant)) {
780 INFO("wps Key is %s", key);
781 if (g_strcmp0(key, "SSID") == 0) {
782 const char *t_key = NULL;
783 t_key = g_variant_get_fixed_array(variant, &ssid_len, sizeof(guchar));
784 INFO("wps ssid_len is %d ", ssid_len);
787 g_variant_unref(variant);
788 ERR("WPS PBC Connection Failed");
791 if (ssid_len > 0 && ssid_len <= 32) {
792 memcpy(ssid, t_key, ssid_len);
794 memset(ssid, 0, sizeof(ssid));
797 INFO("WPS PBC Connection completed with AP %s", ssid);
798 netconfig_wifi_notify_wps_completed(ssid, ssid_len);
802 g_variant_iter_free(iter);
807 g_variant_iter_free(iter);
809 error_indication = WPS_EI_OPERATION_FAILED;
810 config_error = WPS_CFG_NO_ERROR;
811 ERR("Error Occured! Notifying Fail Event");
812 netconfig_wifi_notify_wps_fail_event(config_error, error_indication);
816 static void _supplicant_wifi_wps_event(GVariant *param)
822 gint32 config_error = 0;
823 gint32 error_indication = 0;
826 ERR("Param is NULL");
830 g_variant_get(param, "(sa{sv})", &name, &iter);
831 INFO("Event Result: %s", name);
832 if (g_strcmp0(name, "fail") == 0) {
833 while (g_variant_iter_loop(iter, "{sv}", &key, &variant)) {
836 INFO("Key is %s", key);
837 if (g_strcmp0(key, "config_error") == 0) {
838 config_error = g_variant_get_int32(variant);
839 ERR("Config Error %d", config_error);
840 } else if (g_strcmp0(key, "error_indication") == 0) {
841 error_indication = g_variant_get_int32(variant);
842 ERR("Error Indication %d", error_indication);
845 netconfig_wifi_notify_wps_fail_event(config_error, error_indication);
848 g_variant_iter_free(iter);
853 g_variant_iter_free(iter);
855 error_indication = WPS_EI_OPERATION_FAILED;
856 config_error = WPS_CFG_NO_ERROR;
857 ERR("Error Occured! Notifying Fail Event");
858 netconfig_wifi_notify_wps_fail_event(config_error, error_indication);
861 static void _supplicant_wifi_wps_credentials(GVariant *param)
864 char ssid[32] = {0, };
865 char wps_key[100] = {0, };
868 int config_error = 0;
869 int error_indication = 0;
873 ERR("Param is NULL");
877 g_variant_get(param, "(a{sv})", &iter);
878 while (g_variant_iter_loop(iter, "{sv}", &key, &variant)) {
881 INFO("wps Key is %s", key);
882 if (g_strcmp0(key, "Key") == 0) {
884 const char *t_key = NULL;
885 key_len = g_variant_get_size(variant);
887 INFO("wps password len %d ", key_len);
889 t_key = g_variant_get_fixed_array(variant, &key_len, sizeof(guchar));
892 g_variant_unref(variant);
895 strncpy(wps_key, t_key, key_len);
896 wps_key[key_len] = '\0';
897 INFO("WPS Key in process credentials %s", wps_key);
899 SLOGI("WPS AP Security ->Open");
900 } else if (g_strcmp0(key, "SSID") == 0) {
901 const char *t_key = NULL;
902 t_key = g_variant_get_fixed_array(variant, &ssid_len, sizeof(guchar));
903 INFO("wps ssid_len is %d ", ssid_len);
906 g_variant_unref(variant);
909 if (ssid_len > 0 && ssid_len <= 32) {
910 memcpy(ssid, t_key, ssid_len);
912 memset(ssid, 0, sizeof(ssid));
915 INFO("SSID in process credentials %s", ssid);
919 g_variant_iter_free(iter);
923 * Notify WPS Credentials only when requested through WPS PBC
924 * In case of WPS PIN connman will take care of notification
926 if (netconfig_get_wps_field() == TRUE)
928 netconfig_wifi_notify_wps_credentials(ssid, ssid_len, wps_key);
932 g_variant_iter_free(iter);
933 error_indication = WPS_EI_OPERATION_FAILED;
934 config_error = WPS_CFG_NO_ERROR;
935 ERR("Error Occured! Notifying Fail Event");
936 netconfig_wifi_notify_wps_fail_event(config_error, error_indication);
939 static void __netconfig_wps_signal_filter_handler(GDBusConnection *conn,
940 const gchar *name, const gchar *path, const gchar *interface,
941 const gchar *sig, GVariant *param, gpointer user_data)
943 if (g_strcmp0(sig, SIGNAL_WPS_CREDENTIALS) == 0) {
944 INFO("Received wps CREDENTIALS Signal from Supplicant");
945 _supplicant_wifi_wps_credentials(param);
946 } else if (g_strcmp0(sig, SIGNAL_WPS_EVENT) == 0) {
947 INFO("Received wps EVENT Signal from Supplicant");
948 _supplicant_wifi_wps_event(param);
949 } else if (g_strcmp0(sig, SIGNAL_WPS_CONNECTED) == 0) {
950 INFO("Received WPSConnected Signal from Supplicant");
951 _supplicant_wifi_wps_connected(param);
957 static supplicant_signal_cb supplicant_cbs[SIG_MAX] = {
958 _supplicant_interface_removed,
959 _supplicant_properties_changed,
960 _supplicant_bss_added,
961 _supplicant_scan_done,
962 _supplicant_driver_hanged,
963 _supplicant_session_overlapped,
964 _supplicant_tdls_connected,
965 _supplicant_tdls_disconnected,
966 _supplicant_tdls_peer_found
969 void register_gdbus_signal(void)
971 GDBusConnection *connection = NULL;
972 const char *interface = NULL;
973 SuppSigArrayIndex sig;
974 connection = netdbus_get_connection();
976 if (connection == NULL) {
977 ERR("Failed to get GDbus Connection");
981 /* listening to messages from all objects as no path is specified */
982 /* see signals from the given interface */
983 conn_subscription_ids[0] = g_dbus_connection_signal_subscribe(
986 CONNMAN_TECHNOLOGY_INTERFACE,
990 G_DBUS_SIGNAL_FLAGS_NONE,
991 _technology_signal_cb,
995 conn_subscription_ids[1] = g_dbus_connection_signal_subscribe(
998 CONNMAN_SERVICE_INTERFACE,
999 CONNMAN_SIGNAL_PROPERTY_CHANGED,
1002 G_DBUS_SIGNAL_FLAGS_NONE,
1007 conn_subscription_ids[2] = g_dbus_connection_signal_subscribe(
1010 DBUS_INTERFACE_DBUS,
1011 CONNMAN_SIGNAL_NAME_CHANGED,
1014 G_DBUS_SIGNAL_FLAGS_NONE,
1015 _dbus_name_changed_cb,
1019 conn_subscription_ids[3] = g_dbus_connection_signal_subscribe(
1022 CONNMAN_MANAGER_INTERFACE,
1023 CONNMAN_SIGNAL_SERVICES_CHANGED,
1026 G_DBUS_SIGNAL_FLAGS_NONE,
1027 _services_changed_cb,
1031 INFO("Successfully register connman DBus signal filters");
1033 conn_subscription_ids[4] = g_dbus_connection_signal_subscribe(
1036 SUPPLICANT_INTERFACE ".Interface.WPS",
1040 G_DBUS_SIGNAL_FLAGS_NONE,
1041 __netconfig_wps_signal_filter_handler,
1045 INFO("Successfully register Supplicant WPS DBus signal filters");
1047 for (sig = SIG_INTERFACE_REMOVED; sig < SIG_MAX; sig++) {
1049 * For SIG_INTERFACE_REMOVED INTERFACE_ADDED
1051 interface = (sig == SIG_INTERFACE_REMOVED) ?
1052 SUPPLICANT_INTERFACE : SUPPLICANT_IFACE_INTERFACE;
1054 supp_subscription_ids[sig] = g_dbus_connection_signal_subscribe(
1058 supplicant_signals[sig],
1061 G_DBUS_SIGNAL_FLAGS_NONE,
1062 supplicant_cbs[sig],
1067 INFO("Successfully register Supplicant DBus signal filters");
1069 #if defined TIZEN_DEBUG_ENABLE
1070 dumpservice_subscription_id = g_dbus_connection_signal_subscribe(
1073 DUMP_SERVICE_INTERFACE,
1077 G_DBUS_SIGNAL_FLAGS_NONE,
1078 __netconfig_dumpservice_handler,
1082 INFO("Successfully registered Dumpservice DBus signal filter");
1085 /* In case ConnMan precedes this signal register,
1086 * net-config should update the default connected profile.
1088 netconfig_update_default();
1091 void deregister_gdbus_signal(void)
1093 GDBusConnection *connection = NULL;
1095 SuppSigArrayIndex sig;
1096 connection = netdbus_get_connection();
1098 ERR("Already de-registered. Nothing to be done");
1102 for (signal = 0; signal < TOTAL_CONN_SIGNALS; signal++) {
1103 if (conn_subscription_ids[signal]) {
1104 g_dbus_connection_signal_unsubscribe(connection,
1105 conn_subscription_ids[signal]);
1109 for (sig = SIG_INTERFACE_REMOVED; sig < SIG_MAX; sig++) {
1110 if (supp_subscription_ids[sig]) {
1111 g_dbus_connection_signal_unsubscribe(connection,
1112 supp_subscription_ids[sig]);
1116 #if defined TIZEN_DEBUG_ENABLE
1117 g_dbus_connection_signal_unsubscribe(connection,
1118 dumpservice_subscription_id);