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, GVariant *param, gpointer user_data)
236 gchar *sigvalue = NULL;
238 GVariant *variant = NULL, *var;
240 const gchar *value = NULL;
241 struct sock_data *sd = NULL;
244 if (path == NULL || param == NULL)
247 g_variant_get(param, "(sv)", &sigvalue, &variant);
248 if (sigvalue == NULL)
251 if (g_strcmp0(sig, CONNMAN_SIGNAL_PROPERTY_CHANGED) != 0)
254 if (g_strcmp0(sigvalue, "State") == 0) {
255 g_variant_get(variant, "s", &property);
257 DBG("[%s] %s", property, path);
258 if (netconfig_is_wifi_profile(path) || netconfig_is_ethernet_profile(path)) {
259 if (g_strcmp0(property, "ready") == 0) {
260 for (idx = 0; idx < MAX_SOCKET_OPEN_RETRY; idx++) {
261 sd = start_ip_conflict_mon();
265 } else if (g_strcmp0(property, "online") == 0) {
268 stop_ip_conflict_mon();
272 if (netconfig_is_wifi_profile(path) == TRUE) {
275 netconfig_vconf_get_int(VCONFKEY_WIFI_STATE, &wifi_state);
276 if (wifi_state == VCONFKEY_WIFI_OFF) {
281 if (g_strcmp0(property, "ready") == 0 || g_strcmp0(property, "online") == 0) {
282 if (wifi_state >= VCONFKEY_WIFI_CONNECTED) {
287 netconfig_update_default_profile(path);
289 wifi_state_set_service_state(NETCONFIG_WIFI_CONNECTED);
291 } else if (g_strcmp0(property, "failure") == 0 || g_strcmp0(property, "disconnect") == 0 || g_strcmp0(property, "idle") == 0) {
292 if (netconfig_get_default_profile() == NULL ||
293 netconfig_is_wifi_profile(netconfig_get_default_profile())
295 if (g_strcmp0(property, "failure") == 0)
296 wifi_state_set_service_state(NETCONFIG_WIFI_FAILURE);
298 wifi_state_set_service_state(NETCONFIG_WIFI_IDLE);
303 if (g_strcmp0(path, netconfig_get_default_profile()) != 0) {
308 netconfig_update_default_profile(NULL);
310 if (g_strcmp0(property, "failure") == 0)
311 wifi_state_set_service_state(NETCONFIG_WIFI_FAILURE);
313 wifi_state_set_service_state(NETCONFIG_WIFI_IDLE);
315 } else if (g_strcmp0(property, "association") == 0 || g_strcmp0(property, "configuration") == 0) {
316 if (netconfig_get_default_profile() == NULL ||
317 netconfig_is_wifi_profile(netconfig_get_default_profile()) != TRUE) {
318 if (g_strcmp0(property, "association") == 0)
319 wifi_state_set_service_state(NETCONFIG_WIFI_ASSOCIATION);
321 wifi_state_set_service_state(NETCONFIG_WIFI_CONFIGURATION);
326 if (g_strcmp0(path, netconfig_get_default_profile()) != 0) {
331 netconfig_update_default_profile(NULL);
333 if (g_strcmp0(property, "association") == 0)
334 wifi_state_set_service_state(NETCONFIG_WIFI_ASSOCIATION);
336 wifi_state_set_service_state(NETCONFIG_WIFI_CONFIGURATION);
340 if (g_strcmp0(property, "ready") == 0 || g_strcmp0(property, "online") == 0) {
341 if (netconfig_get_default_profile() == NULL) {
342 if (!netconfig_is_cellular_profile(path))
343 netconfig_update_default_profile(path);
345 if (netconfig_is_cellular_internet_profile(path))
346 netconfig_update_default_profile(path);
350 if (netconfig_is_cellular_profile(path) && netconfig_is_cellular_internet_profile(path))
351 cellular_state_set_service_state(NETCONFIG_CELLULAR_ONLINE);
353 } else if (g_strcmp0(property, "failure") == 0 || g_strcmp0(property, "disconnect") == 0 || g_strcmp0(property, "idle") == 0) {
354 if (netconfig_get_default_profile() == NULL) {
359 if (netconfig_is_cellular_profile(path) && netconfig_is_cellular_internet_profile(path))
360 cellular_state_set_service_state(NETCONFIG_CELLULAR_IDLE);
362 if (g_strcmp0(path, netconfig_get_default_profile()) != 0) {
367 netconfig_update_default_profile(NULL);
368 } else if (g_strcmp0(property, "association") == 0 || g_strcmp0(property, "configuration") == 0) {
369 if (netconfig_get_default_profile() == NULL) {
374 if (netconfig_is_cellular_profile(path) && netconfig_is_cellular_internet_profile(path))
375 cellular_state_set_service_state(NETCONFIG_CELLULAR_CONNECTING);
377 if (g_strcmp0(path, netconfig_get_default_profile()) != 0) {
382 netconfig_update_default_profile(NULL);
386 } else if (g_strcmp0(sigvalue, "Proxy") == 0) {
387 if (netconfig_is_wifi_profile(path) != TRUE || g_strcmp0(path, netconfig_get_default_profile()) != 0)
390 if (!g_variant_type_equal(variant, G_VARIANT_TYPE_ARRAY))
393 g_variant_get(variant, "a{sv}", &iter);
394 while (g_variant_iter_loop(iter, "{sv}", &property, &var)) {
395 GVariantBuilder *builder;
396 GVariant *sig_params;
397 if (g_strcmp0(property, "Servers") == 0) {
398 GVariantIter *iter_sub = NULL;
400 builder = g_variant_builder_new(G_VARIANT_TYPE("a{sv}"));
402 g_variant_get(var, "as", &iter_sub);
403 g_variant_iter_loop(iter_sub, "s", &value);
404 g_variant_iter_free(iter_sub);
406 DBG("Proxy - [%s]", value);
407 vconf_set_str(VCONFKEY_NETWORK_PROXY, value);
409 g_variant_builder_add(builder, "{sv}", "ProxyAddress",
410 g_variant_new_string(value));
412 sig_params = g_variant_new("(@a{sv})",
413 g_variant_builder_end(builder));
415 netconfig_dbus_emit_signal(NULL, NETCONFIG_NETWORK_PATH,
416 NETCONFIG_NETWORK_INTERFACE, "NetworkConfigChanged",
420 g_variant_unref(var);
422 } else if (g_strcmp0(property, "Method") == 0) {
423 value = g_variant_get_string(var, NULL);
424 DBG("Method - [%s]", value);
426 if (g_strcmp0(value, "direct") == 0) {
427 builder = g_variant_builder_new(G_VARIANT_TYPE("a{sv}"));
429 vconf_set_str(VCONFKEY_NETWORK_PROXY, "");
430 g_variant_builder_add(builder, "{sv}", "ProxyAddress",
431 g_variant_new_string(""));
433 sig_params = g_variant_new("(@a{sv})",
434 g_variant_builder_end(builder));
436 netconfig_dbus_emit_signal(NULL, NETCONFIG_NETWORK_PATH,
437 NETCONFIG_NETWORK_INTERFACE,
438 "NetworkConfigChanged", sig_params);
442 g_variant_unref(var);
447 g_variant_iter_free(iter);
448 } else if (g_strcmp0(sigvalue, "IPv4") == 0) {
449 __netconfig_extract_ipv4_signal_data(variant, path);
450 } else if (g_strcmp0(sigvalue, "IPv6") == 0) {
451 __netconfig_extract_ipv6_signal_data(variant, path);
452 } else if (g_strcmp0(sigvalue, "Error") == 0) {
453 g_variant_get(variant, "s", &property);
454 INFO("[%s] Property : %s", sigvalue, property);
462 g_variant_unref(variant);
467 static void _dbus_name_changed_cb(GDBusConnection *conn,
468 const gchar *Name, const gchar *path, const gchar *interface,
469 const gchar *sig, GVariant *param, gpointer user_data)
478 g_variant_get(param, "(sss)", &name, &old, &new);
480 if (g_strcmp0(name, CONNMAN_SERVICE) == 0 && *new == '\0') {
481 DBG("ConnMan destroyed: name %s, old %s, new %s", name, old, new);
483 connman_register_agent();
495 static void _services_changed_cb(GDBusConnection *conn, const gchar *name,
496 const gchar *path, const gchar *interface, const gchar *sig,
497 GVariant *param, gpointer user_data)
499 gchar *property, *value;
501 GVariant *variant = NULL;
502 GVariantIter *added = NULL, *removed = NULL, *next = NULL;
504 if (path == NULL || param == NULL)
507 if (g_strcmp0(sig, CONNMAN_SIGNAL_SERVICES_CHANGED) != 0)
510 if (netconfig_get_default_profile() != NULL)
513 g_variant_get(param, "(a(oa{sv})ao)", &added, &removed);
515 while (g_variant_iter_loop(added, "(oa{sv})", &service_path, &next)) {
516 gboolean is_wifi_prof, is_cell_prof, is_cell_internet_prof;
517 is_wifi_prof = netconfig_is_wifi_profile(service_path);
518 is_cell_prof = netconfig_is_cellular_profile(service_path);
519 is_cell_internet_prof = netconfig_is_cellular_internet_profile(
521 if (service_path != NULL) {
522 while (next && g_variant_iter_loop(next, "{sv}", &property,
524 if (g_strcmp0(property, "State") == 0) {
525 g_variant_get(variant, "s", &value);
526 DBG("Profile %s State %s", service_path,
528 if (g_strcmp0(value, "ready") != 0 &&
533 g_variant_unref(variant);
538 netconfig_update_default_profile(
540 else if (is_cell_internet_prof) {
541 netconfig_update_default_profile(
545 wifi_state_set_service_state(
546 NETCONFIG_WIFI_CONNECTED);
547 else if (is_cell_prof &&
548 is_cell_internet_prof)
549 cellular_state_set_service_state(
550 NETCONFIG_CELLULAR_ONLINE);
553 g_variant_unref(variant);
560 g_variant_iter_free(added);
563 g_variant_iter_free(next);
566 g_variant_iter_free(removed);
571 static void _supplicant_interface_removed(GDBusConnection *conn,
572 const gchar *name, const gchar *path, const gchar *interface,
573 const gchar *sig, GVariant *param, gpointer user_data)
575 DBG("Interface removed handling!");
576 if (netconfig_wifi_is_bssid_scan_started() == TRUE)
577 netconfig_wifi_bssid_signal_scanaborted();
582 static void _supplicant_properties_changed(GDBusConnection *conn,
583 const gchar *name, const gchar *path, const gchar *interface,
584 const gchar *sig, GVariant *param, gpointer user_data)
589 gboolean scanning = FALSE;
594 g_variant_get(param, "(a{sv})", &iter);
595 while (g_variant_iter_loop(iter, "{sv}", &key, &variant)) {
596 if (g_strcmp0(key, "Scanning") == 0) {
597 scanning = g_variant_get_boolean(variant);
598 DBG("setting scanning %s", scanning ? "TRUE" : "FALSE");
599 if (scanning == TRUE)
600 netconfig_wifi_set_scanning(TRUE);
602 netconfig_wifi_set_scanning(FALSE);
604 g_variant_unref(variant);
610 g_variant_iter_free(iter);
615 static void _supplicant_bss_added(GDBusConnection *conn,
616 const gchar *name, const gchar *path, const gchar *interface,
617 const gchar *sig, GVariant *param, gpointer user_data)
619 DBG("BSS added handling!");
620 wifi_state_set_bss_found(TRUE);
625 static void _supplicant_scan_done(GDBusConnection *conn,
626 const gchar *name, const gchar *path, const gchar *interface,
627 const gchar *sig, GVariant *param, gpointer user_data)
629 DBG("Scan Done handling!");
630 netconfig_wifi_set_scanning(FALSE);
632 if (netconfig_wifi_is_bssid_scan_started() == TRUE) {
633 netconfig_wifi_bssid_signal_scandone();
634 if (wifi_state_get_technology_state() < NETCONFIG_WIFI_TECH_POWERED)
638 if (netconfig_wifi_get_bgscan_state() == TRUE) {
639 if (wifi_state_get_technology_state() >=
640 NETCONFIG_WIFI_TECH_POWERED)
641 netconfig_wifi_bgscan_start(FALSE);
643 wifi_start_timer_network_notification();
649 static void _supplicant_driver_hanged(GDBusConnection *conn,
650 const gchar *name, const gchar *path, const gchar *interface,
651 const gchar *sig, GVariant *param, gpointer user_data)
653 DBG("Driver Hanged handling!");
654 ERR("Critical. Wi-Fi firmware crashed");
656 #if !defined TIZEN_WEARABLE
657 netconfig_send_message_to_net_popup("Wi-Fi Error",
658 "Wi-Fi Driver Hanged. Please get log dump and report", "popup", NULL);
660 wifi_power_recover_firmware();
666 static void _supplicant_session_overlapped(GDBusConnection *conn,
667 const gchar *name, const gchar *path, const gchar *interface,
668 const gchar *sig, GVariant *param, gpointer user_data)
670 DBG("Driver session overlapped handling!");
671 ERR("WPS PBC SESSION OVERLAPPED");
672 #if defined TIZEN_WEARABLE
675 netconfig_send_message_to_net_popup("WPS Error",
676 "wps session overlapped", "popup", NULL);
680 #if defined TIZEN_DEBUG_ENABLE
681 static void __netconfig_dumpservice_handler(GDBusConnection *conn,
682 const gchar *name, const gchar *path, const gchar *interface,
683 const gchar *sig, GVariant *param, gpointer user_data)
686 gchar *signal_path = NULL;
691 g_variant_get(param, "(is)", &mode, &signal_path);
692 DBG("Path: %s and mode: %d", signal_path, mode);
694 netconfig_dump_log(signal_path);
702 static void _supplicant_tdls_connected(GDBusConnection *conn,
703 const gchar *name, const gchar *path, const gchar *interface,
704 const gchar *sig, GVariant *param, gpointer user_data)
706 DBG("Received TDLS Connected Signal");
707 netconfig_wifi_tdls_connected_event(param);
712 static void _supplicant_tdls_disconnected(GDBusConnection *conn,
713 const gchar *name, const gchar *path, const gchar *interface,
714 const gchar *sig, GVariant *param, gpointer user_data)
716 DBG("Received TDLS Disconnected Signal");
717 netconfig_wifi_tdls_disconnected_event(param);
722 static void _supplicant_tdls_peer_found(GDBusConnection *conn,
723 const gchar *name, const gchar *path, const gchar *interface,
724 const gchar *sig, GVariant *param, gpointer user_data)
726 DBG("Received TDLS Peer Found Signal");
727 netconfig_wifi_tdls_peer_found_event(param);
731 static void _supplicant_wifi_wps_connected(GVariant *param)
734 char ssid[32] = {0, };
738 int config_error = 0;
739 int error_indication = 0;
743 ERR("Param is NULL");
747 g_variant_get(param, "(sa{sv})", &name, &iter);
748 INFO("wps Result: %s", name);
749 while (g_variant_iter_loop(iter, "{sv}", &key, &variant)) {
750 INFO("wps Key is %s", key);
751 if (g_strcmp0(key, "SSID") == 0) {
752 const char *t_key = NULL;
753 t_key = g_variant_get_fixed_array(variant, &ssid_len, sizeof(guchar));
754 INFO("wps ssid_len is %d ", ssid_len);
757 g_variant_unref(variant);
758 ERR("WPS PBC Connection Failed");
761 if (ssid_len > 0 && ssid_len <= 32) {
762 memcpy(ssid, t_key, ssid_len);
764 memset(ssid, 0, sizeof(ssid));
767 INFO("WPS PBC Connection completed with AP %s", ssid);
768 netconfig_wifi_notify_wps_completed(ssid, ssid_len);
772 g_variant_iter_free(iter);
777 g_variant_iter_free(iter);
779 error_indication = WPS_EI_OPERATION_FAILED;
780 config_error = WPS_CFG_NO_ERROR;
781 ERR("Error Occured! Notifying Fail Event");
782 netconfig_wifi_notify_wps_fail_event(config_error, error_indication);
786 static void _supplicant_wifi_wps_event(GVariant *param)
792 gint32 config_error = 0;
793 gint32 error_indication = 0;
796 ERR("Param is NULL");
800 g_variant_get(param, "(sa{sv})", &name, &iter);
801 INFO("Event Result: %s", name);
802 if (g_strcmp0(name, "fail") == 0) {
803 while (g_variant_iter_loop(iter, "{sv}", &key, &variant)) {
806 INFO("Key is %s", key);
807 if (g_strcmp0(key, "config_error") == 0) {
808 config_error = g_variant_get_int32(variant);
809 ERR("Config Error %d", config_error);
810 } else if (g_strcmp0(key, "error_indication") == 0) {
811 error_indication = g_variant_get_int32(variant);
812 ERR("Error Indication %d", error_indication);
815 netconfig_wifi_notify_wps_fail_event(config_error, error_indication);
818 g_variant_iter_free(iter);
823 g_variant_iter_free(iter);
825 error_indication = WPS_EI_OPERATION_FAILED;
826 config_error = WPS_CFG_NO_ERROR;
827 ERR("Error Occured! Notifying Fail Event");
828 netconfig_wifi_notify_wps_fail_event(config_error, error_indication);
831 static void _supplicant_wifi_wps_credentials(GVariant *param)
838 int config_error = 0;
839 int error_indication = 0;
843 ERR("Param is NULL");
847 g_variant_get(param, "(a{sv})", &iter);
848 while (g_variant_iter_loop(iter, "{sv}", &key, &variant)) {
851 INFO("wps Key is %s", key);
852 if (g_strcmp0(key, "Key") == 0) {
854 const char *t_key = NULL;
855 key_len = g_variant_get_size(variant);
857 INFO("wps password len %d ", key_len);
859 t_key = g_variant_get_fixed_array(variant, &key_len, sizeof(guchar));
862 g_variant_unref(variant);
865 strncpy(wps_key, t_key, key_len);
866 wps_key[key_len] = '\0';
867 INFO("WPS Key in process credentials %s", wps_key);
869 SLOGI("WPS AP Security ->Open");
870 } else if (g_strcmp0(key, "SSID") == 0) {
871 const char *t_key = NULL;
872 t_key = g_variant_get_fixed_array(variant, &ssid_len, sizeof(guchar));
873 INFO("wps ssid_len is %d ", ssid_len);
876 g_variant_unref(variant);
879 if (ssid_len > 0 && ssid_len <= 32) {
880 memcpy(ssid, t_key, ssid_len);
882 memset(ssid, 0, sizeof(ssid));
885 INFO("SSID in process credentials %s", ssid);
889 g_variant_iter_free(iter);
893 * Notify WPS Credentials only when requested through WPS PBC
894 * In case of WPS PIN connman will take care of notification
896 if (netconfig_get_wps_field() == TRUE)
898 netconfig_wifi_notify_wps_credentials(ssid, ssid_len, wps_key);
902 g_variant_iter_free(iter);
903 error_indication = WPS_EI_OPERATION_FAILED;
904 config_error = WPS_CFG_NO_ERROR;
905 ERR("Error Occured! Notifying Fail Event");
906 netconfig_wifi_notify_wps_fail_event(config_error, error_indication);
909 static void __netconfig_wps_signal_filter_handler(GDBusConnection *conn,
910 const gchar *name, const gchar *path, const gchar *interface,
911 const gchar *sig, GVariant *param, gpointer user_data)
913 if (g_strcmp0(sig, SIGNAL_WPS_CREDENTIALS) == 0) {
914 INFO("Received wps CREDENTIALS Signal from Supplicant");
915 _supplicant_wifi_wps_credentials(param);
916 } else if (g_strcmp0(sig, SIGNAL_WPS_EVENT) == 0) {
917 INFO("Received wps EVENT Signal from Supplicant");
918 _supplicant_wifi_wps_event(param);
919 } else if (g_strcmp0(sig, SIGNAL_WPS_CONNECTED) == 0) {
920 INFO("Received WPSConnected Signal from Supplicant");
921 _supplicant_wifi_wps_connected(param);
927 static supplicant_signal_cb supplicant_cbs[SIG_MAX] = {
928 _supplicant_interface_removed,
929 _supplicant_properties_changed,
930 _supplicant_bss_added,
931 _supplicant_scan_done,
932 _supplicant_driver_hanged,
933 _supplicant_session_overlapped,
934 _supplicant_tdls_connected,
935 _supplicant_tdls_disconnected,
936 _supplicant_tdls_peer_found
939 void register_gdbus_signal(void)
941 GDBusConnection *connection = NULL;
942 const char *interface = NULL;
943 SuppSigArrayIndex sig;
944 connection = netdbus_get_connection();
946 if (connection == NULL) {
947 ERR("Failed to get GDbus Connection");
951 /* listening to messages from all objects as no path is specified */
952 /* see signals from the given interface */
953 conn_subscription_ids[0] = g_dbus_connection_signal_subscribe(
956 CONNMAN_TECHNOLOGY_INTERFACE,
960 G_DBUS_SIGNAL_FLAGS_NONE,
961 _technology_signal_cb,
965 conn_subscription_ids[1] = g_dbus_connection_signal_subscribe(
968 CONNMAN_SERVICE_INTERFACE,
969 CONNMAN_SIGNAL_PROPERTY_CHANGED,
972 G_DBUS_SIGNAL_FLAGS_NONE,
977 conn_subscription_ids[2] = g_dbus_connection_signal_subscribe(
981 CONNMAN_SIGNAL_NAME_CHANGED,
984 G_DBUS_SIGNAL_FLAGS_NONE,
985 _dbus_name_changed_cb,
989 conn_subscription_ids[3] = g_dbus_connection_signal_subscribe(
992 CONNMAN_MANAGER_INTERFACE,
993 CONNMAN_SIGNAL_SERVICES_CHANGED,
996 G_DBUS_SIGNAL_FLAGS_NONE,
997 _services_changed_cb,
1001 INFO("Successfully register connman DBus signal filters");
1003 conn_subscription_ids[4] = g_dbus_connection_signal_subscribe(
1006 SUPPLICANT_INTERFACE ".Interface.WPS",
1010 G_DBUS_SIGNAL_FLAGS_NONE,
1011 __netconfig_wps_signal_filter_handler,
1015 INFO("Successfully register Supplicant WPS DBus signal filters");
1017 for (sig = SIG_INTERFACE_REMOVED; sig < SIG_MAX; sig++) {
1019 * For SIG_INTERFACE_REMOVED INTERFACE_ADDED
1021 interface = (sig == SIG_INTERFACE_REMOVED) ?
1022 SUPPLICANT_INTERFACE : SUPPLICANT_IFACE_INTERFACE;
1024 supp_subscription_ids[sig] = g_dbus_connection_signal_subscribe(
1028 supplicant_signals[sig],
1031 G_DBUS_SIGNAL_FLAGS_NONE,
1032 supplicant_cbs[sig],
1037 INFO("Successfully register Supplicant DBus signal filters");
1039 #if defined TIZEN_DEBUG_ENABLE
1040 dumpservice_subscription_id = g_dbus_connection_signal_subscribe(
1043 DUMP_SERVICE_INTERFACE,
1047 G_DBUS_SIGNAL_FLAGS_NONE,
1048 __netconfig_dumpservice_handler,
1052 INFO("Successfully registered Dumpservice DBus signal filter");
1055 /* In case ConnMan precedes this signal register,
1056 * net-config should update the default connected profile.
1058 netconfig_update_default();
1061 void deregister_gdbus_signal(void)
1063 GDBusConnection *connection = NULL;
1065 SuppSigArrayIndex sig;
1066 connection = netdbus_get_connection();
1068 ERR("Already de-registered. Nothing to be done");
1072 for (signal = 0; signal < TOTAL_CONN_SIGNALS; signal++) {
1073 if (conn_subscription_ids[signal]) {
1074 g_dbus_connection_signal_unsubscribe(connection,
1075 conn_subscription_ids[signal]);
1079 for (sig = SIG_INTERFACE_REMOVED; sig < SIG_MAX; sig++) {
1080 if (supp_subscription_ids[sig]) {
1081 g_dbus_connection_signal_unsubscribe(connection,
1082 supp_subscription_ids[sig]);
1086 #if defined TIZEN_DEBUG_ENABLE
1087 g_dbus_connection_signal_unsubscribe(connection,
1088 dumpservice_subscription_id);