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);
632 state = g_variant_get_string(variant, NULL);
634 DBG("Supplicant %s : %s", key, state);
638 g_variant_iter_free(iter);
643 static void _supplicant_bss_added(GDBusConnection *conn,
644 const gchar *name, const gchar *path, const gchar *interface,
645 const gchar *sig, GVariant *param, gpointer user_data)
647 DBG("BSS added handling!");
648 wifi_state_set_bss_found(TRUE);
653 static void _supplicant_scan_done(GDBusConnection *conn,
654 const gchar *name, const gchar *path, const gchar *interface,
655 const gchar *sig, GVariant *param, gpointer user_data)
657 DBG("Scan Done handling!");
658 netconfig_wifi_set_scanning(FALSE);
660 if (netconfig_wifi_is_bssid_scan_started() == TRUE) {
661 netconfig_wifi_bssid_signal_scandone();
662 if (wifi_state_get_technology_state() < NETCONFIG_WIFI_TECH_POWERED)
666 if (netconfig_wifi_get_bgscan_state() == TRUE) {
667 if (wifi_state_get_technology_state() >=
668 NETCONFIG_WIFI_TECH_POWERED)
669 netconfig_wifi_bgscan_start(FALSE);
671 wifi_start_timer_network_notification();
677 static void _supplicant_driver_hanged(GDBusConnection *conn,
678 const gchar *name, const gchar *path, const gchar *interface,
679 const gchar *sig, GVariant *param, gpointer user_data)
681 DBG("Driver Hanged handling!");
682 ERR("Critical. Wi-Fi firmware crashed");
684 #if !defined TIZEN_WEARABLE
685 netconfig_send_message_to_net_popup("Wi-Fi Error",
686 "Wi-Fi Driver Hanged. Please get log dump and report", "popup", NULL);
688 wifi_power_recover_firmware();
694 static void _supplicant_session_overlapped(GDBusConnection *conn,
695 const gchar *name, const gchar *path, const gchar *interface,
696 const gchar *sig, GVariant *param, gpointer user_data)
698 DBG("Driver session overlapped handling!");
699 ERR("WPS PBC SESSION OVERLAPPED");
700 #if defined TIZEN_WEARABLE
703 netconfig_send_message_to_net_popup("WPS Error",
704 "wps session overlapped", "popup", NULL);
708 #if defined TIZEN_DEBUG_ENABLE
709 static void __netconfig_dumpservice_handler(GDBusConnection *conn,
710 const gchar *name, const gchar *path, const gchar *interface,
711 const gchar *sig, GVariant *param, gpointer user_data)
714 gchar *signal_path = NULL;
719 g_variant_get(param, "(is)", &mode, &signal_path);
720 DBG("Path: %s and mode: %d", signal_path, mode);
722 netconfig_dump_log(signal_path);
730 static void _supplicant_tdls_connected(GDBusConnection *conn,
731 const gchar *name, const gchar *path, const gchar *interface,
732 const gchar *sig, GVariant *param, gpointer user_data)
734 DBG("Received TDLS Connected Signal");
735 netconfig_wifi_tdls_connected_event(param);
740 static void _supplicant_tdls_disconnected(GDBusConnection *conn,
741 const gchar *name, const gchar *path, const gchar *interface,
742 const gchar *sig, GVariant *param, gpointer user_data)
744 DBG("Received TDLS Disconnected Signal");
745 netconfig_wifi_tdls_disconnected_event(param);
750 static void _supplicant_tdls_peer_found(GDBusConnection *conn,
751 const gchar *name, const gchar *path, const gchar *interface,
752 const gchar *sig, GVariant *param, gpointer user_data)
754 DBG("Received TDLS Peer Found Signal");
755 netconfig_wifi_tdls_peer_found_event(param);
759 static void _supplicant_wifi_wps_connected(GVariant *param)
762 char ssid[32] = {0, };
766 int config_error = 0;
767 int error_indication = 0;
771 ERR("Param is NULL");
775 g_variant_get(param, "(sa{sv})", &name, &iter);
776 INFO("wps Result: %s", name);
777 while (g_variant_iter_loop(iter, "{sv}", &key, &variant)) {
778 INFO("wps Key is %s", key);
779 if (g_strcmp0(key, "SSID") == 0) {
780 const char *t_key = NULL;
781 t_key = g_variant_get_fixed_array(variant, &ssid_len, sizeof(guchar));
782 INFO("wps ssid_len is %d ", ssid_len);
785 g_variant_unref(variant);
786 ERR("WPS PBC Connection Failed");
789 if (ssid_len > 0 && ssid_len <= 32) {
790 memcpy(ssid, t_key, ssid_len);
792 memset(ssid, 0, sizeof(ssid));
795 INFO("WPS PBC Connection completed with AP %s", ssid);
796 netconfig_wifi_notify_wps_completed(ssid, ssid_len);
800 g_variant_iter_free(iter);
805 g_variant_iter_free(iter);
807 error_indication = WPS_EI_OPERATION_FAILED;
808 config_error = WPS_CFG_NO_ERROR;
809 ERR("Error Occured! Notifying Fail Event");
810 netconfig_wifi_notify_wps_fail_event(config_error, error_indication);
814 static void _supplicant_wifi_wps_event(GVariant *param)
820 gint32 config_error = 0;
821 gint32 error_indication = 0;
824 ERR("Param is NULL");
828 g_variant_get(param, "(sa{sv})", &name, &iter);
829 INFO("Event Result: %s", name);
830 if (g_strcmp0(name, "fail") == 0) {
831 while (g_variant_iter_loop(iter, "{sv}", &key, &variant)) {
834 INFO("Key is %s", key);
835 if (g_strcmp0(key, "config_error") == 0) {
836 config_error = g_variant_get_int32(variant);
837 ERR("Config Error %d", config_error);
838 } else if (g_strcmp0(key, "error_indication") == 0) {
839 error_indication = g_variant_get_int32(variant);
840 ERR("Error Indication %d", error_indication);
843 netconfig_wifi_notify_wps_fail_event(config_error, error_indication);
846 g_variant_iter_free(iter);
851 g_variant_iter_free(iter);
853 error_indication = WPS_EI_OPERATION_FAILED;
854 config_error = WPS_CFG_NO_ERROR;
855 ERR("Error Occured! Notifying Fail Event");
856 netconfig_wifi_notify_wps_fail_event(config_error, error_indication);
859 static void _supplicant_wifi_wps_credentials(GVariant *param)
862 char ssid[32] = {0, };
863 char wps_key[100] = {0, };
866 int config_error = 0;
867 int error_indication = 0;
871 ERR("Param is NULL");
875 g_variant_get(param, "(a{sv})", &iter);
876 while (g_variant_iter_loop(iter, "{sv}", &key, &variant)) {
879 INFO("wps Key is %s", key);
880 if (g_strcmp0(key, "Key") == 0) {
882 const char *t_key = NULL;
883 key_len = g_variant_get_size(variant);
885 INFO("wps password len %d ", key_len);
887 t_key = g_variant_get_fixed_array(variant, &key_len, sizeof(guchar));
890 g_variant_unref(variant);
893 strncpy(wps_key, t_key, key_len);
894 wps_key[key_len] = '\0';
895 INFO("WPS Key in process credentials %s", wps_key);
897 SLOGI("WPS AP Security ->Open");
898 } else if (g_strcmp0(key, "SSID") == 0) {
899 const char *t_key = NULL;
900 t_key = g_variant_get_fixed_array(variant, &ssid_len, sizeof(guchar));
901 INFO("wps ssid_len is %d ", ssid_len);
904 g_variant_unref(variant);
907 if (ssid_len > 0 && ssid_len <= 32) {
908 memcpy(ssid, t_key, ssid_len);
910 memset(ssid, 0, sizeof(ssid));
913 INFO("SSID in process credentials %s", ssid);
917 g_variant_iter_free(iter);
921 * Notify WPS Credentials only when requested through WPS PBC
922 * In case of WPS PIN connman will take care of notification
924 if (netconfig_get_wps_field() == TRUE)
926 netconfig_wifi_notify_wps_credentials(ssid, ssid_len, wps_key);
930 g_variant_iter_free(iter);
931 error_indication = WPS_EI_OPERATION_FAILED;
932 config_error = WPS_CFG_NO_ERROR;
933 ERR("Error Occured! Notifying Fail Event");
934 netconfig_wifi_notify_wps_fail_event(config_error, error_indication);
937 static void __netconfig_wps_signal_filter_handler(GDBusConnection *conn,
938 const gchar *name, const gchar *path, const gchar *interface,
939 const gchar *sig, GVariant *param, gpointer user_data)
941 if (g_strcmp0(sig, SIGNAL_WPS_CREDENTIALS) == 0) {
942 INFO("Received wps CREDENTIALS Signal from Supplicant");
943 _supplicant_wifi_wps_credentials(param);
944 } else if (g_strcmp0(sig, SIGNAL_WPS_EVENT) == 0) {
945 INFO("Received wps EVENT Signal from Supplicant");
946 _supplicant_wifi_wps_event(param);
947 } else if (g_strcmp0(sig, SIGNAL_WPS_CONNECTED) == 0) {
948 INFO("Received WPSConnected Signal from Supplicant");
949 _supplicant_wifi_wps_connected(param);
955 static supplicant_signal_cb supplicant_cbs[SIG_MAX] = {
956 _supplicant_interface_removed,
957 _supplicant_properties_changed,
958 _supplicant_bss_added,
959 _supplicant_scan_done,
960 _supplicant_driver_hanged,
961 _supplicant_session_overlapped,
962 _supplicant_tdls_connected,
963 _supplicant_tdls_disconnected,
964 _supplicant_tdls_peer_found
967 void register_gdbus_signal(void)
969 GDBusConnection *connection = NULL;
970 const char *interface = NULL;
971 SuppSigArrayIndex sig;
972 connection = netdbus_get_connection();
974 if (connection == NULL) {
975 ERR("Failed to get GDbus Connection");
979 /* listening to messages from all objects as no path is specified */
980 /* see signals from the given interface */
981 conn_subscription_ids[0] = g_dbus_connection_signal_subscribe(
984 CONNMAN_TECHNOLOGY_INTERFACE,
988 G_DBUS_SIGNAL_FLAGS_NONE,
989 _technology_signal_cb,
993 conn_subscription_ids[1] = g_dbus_connection_signal_subscribe(
996 CONNMAN_SERVICE_INTERFACE,
997 CONNMAN_SIGNAL_PROPERTY_CHANGED,
1000 G_DBUS_SIGNAL_FLAGS_NONE,
1005 conn_subscription_ids[2] = g_dbus_connection_signal_subscribe(
1008 DBUS_INTERFACE_DBUS,
1009 CONNMAN_SIGNAL_NAME_CHANGED,
1012 G_DBUS_SIGNAL_FLAGS_NONE,
1013 _dbus_name_changed_cb,
1017 conn_subscription_ids[3] = g_dbus_connection_signal_subscribe(
1020 CONNMAN_MANAGER_INTERFACE,
1021 CONNMAN_SIGNAL_SERVICES_CHANGED,
1024 G_DBUS_SIGNAL_FLAGS_NONE,
1025 _services_changed_cb,
1029 INFO("Successfully register connman DBus signal filters");
1031 conn_subscription_ids[4] = g_dbus_connection_signal_subscribe(
1034 SUPPLICANT_INTERFACE ".Interface.WPS",
1038 G_DBUS_SIGNAL_FLAGS_NONE,
1039 __netconfig_wps_signal_filter_handler,
1043 INFO("Successfully register Supplicant WPS DBus signal filters");
1045 for (sig = SIG_INTERFACE_REMOVED; sig < SIG_MAX; sig++) {
1047 * For SIG_INTERFACE_REMOVED INTERFACE_ADDED
1049 interface = (sig == SIG_INTERFACE_REMOVED) ?
1050 SUPPLICANT_INTERFACE : SUPPLICANT_IFACE_INTERFACE;
1052 supp_subscription_ids[sig] = g_dbus_connection_signal_subscribe(
1056 supplicant_signals[sig],
1059 G_DBUS_SIGNAL_FLAGS_NONE,
1060 supplicant_cbs[sig],
1065 INFO("Successfully register Supplicant DBus signal filters");
1067 #if defined TIZEN_DEBUG_ENABLE
1068 dumpservice_subscription_id = g_dbus_connection_signal_subscribe(
1071 DUMP_SERVICE_INTERFACE,
1075 G_DBUS_SIGNAL_FLAGS_NONE,
1076 __netconfig_dumpservice_handler,
1080 INFO("Successfully registered Dumpservice DBus signal filter");
1083 /* In case ConnMan precedes this signal register,
1084 * net-config should update the default connected profile.
1086 netconfig_update_default();
1089 void deregister_gdbus_signal(void)
1091 GDBusConnection *connection = NULL;
1093 SuppSigArrayIndex sig;
1094 connection = netdbus_get_connection();
1096 ERR("Already de-registered. Nothing to be done");
1100 for (signal = 0; signal < TOTAL_CONN_SIGNALS; signal++) {
1101 if (conn_subscription_ids[signal]) {
1102 g_dbus_connection_signal_unsubscribe(connection,
1103 conn_subscription_ids[signal]);
1107 for (sig = SIG_INTERFACE_REMOVED; sig < SIG_MAX; sig++) {
1108 if (supp_subscription_ids[sig]) {
1109 g_dbus_connection_signal_unsubscribe(connection,
1110 supp_subscription_ids[sig]);
1114 #if defined TIZEN_DEBUG_ENABLE
1115 g_dbus_connection_signal_unsubscribe(connection,
1116 dumpservice_subscription_id);