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)
586 DBG("Properties changed handling!");
588 const gchar *state = NULL;
589 GVariantIter *iter = NULL;
590 GVariant *variant = NULL;
591 gboolean scanning = FALSE;
596 g_variant_get(param, "(a{sv})", &iter);
597 while (g_variant_iter_loop(iter, "{sv}", &key, &variant)) {
598 if (g_strcmp0(key, "Scanning") == 0) {
599 scanning = g_variant_get_boolean(variant);
600 DBG("setting scanning %s", scanning ? "TRUE" : "FALSE");
601 if (scanning == TRUE)
602 netconfig_wifi_set_scanning(TRUE);
604 netconfig_wifi_set_scanning(FALSE);
606 g_variant_unref(variant);
611 } else if (g_strcmp0(key, "State") == 0) {
612 state = g_variant_get_string(variant, NULL);
614 ERR("Supplicant state : %s", state);
616 g_variant_unref(variant);
621 } else if (g_strcmp0(key, "DisconnectReason") == 0) {
622 int reason = g_variant_get_int32(variant);
623 ERR("Supplicant DisconnReason : %d", reason);
625 g_variant_unref(variant);
631 state = g_variant_get_string(variant, NULL);
633 DBG("Supplicant %s : %s", key, state);
637 g_variant_iter_free(iter);
642 static void _supplicant_bss_added(GDBusConnection *conn,
643 const gchar *name, const gchar *path, const gchar *interface,
644 const gchar *sig, GVariant *param, gpointer user_data)
646 DBG("BSS added handling!");
647 wifi_state_set_bss_found(TRUE);
652 static void _supplicant_scan_done(GDBusConnection *conn,
653 const gchar *name, const gchar *path, const gchar *interface,
654 const gchar *sig, GVariant *param, gpointer user_data)
656 DBG("Scan Done handling!");
657 netconfig_wifi_set_scanning(FALSE);
659 if (netconfig_wifi_is_bssid_scan_started() == TRUE) {
660 netconfig_wifi_bssid_signal_scandone();
661 if (wifi_state_get_technology_state() < NETCONFIG_WIFI_TECH_POWERED)
665 if (netconfig_wifi_get_bgscan_state() == TRUE) {
666 if (wifi_state_get_technology_state() >=
667 NETCONFIG_WIFI_TECH_POWERED)
668 netconfig_wifi_bgscan_start(FALSE);
670 wifi_start_timer_network_notification();
676 static void _supplicant_driver_hanged(GDBusConnection *conn,
677 const gchar *name, const gchar *path, const gchar *interface,
678 const gchar *sig, GVariant *param, gpointer user_data)
680 DBG("Driver Hanged handling!");
681 ERR("Critical. Wi-Fi firmware crashed");
683 #if !defined TIZEN_WEARABLE
684 netconfig_send_message_to_net_popup("Wi-Fi Error",
685 "Wi-Fi Driver Hanged. Please get log dump and report", "popup", NULL);
687 wifi_power_recover_firmware();
693 static void _supplicant_session_overlapped(GDBusConnection *conn,
694 const gchar *name, const gchar *path, const gchar *interface,
695 const gchar *sig, GVariant *param, gpointer user_data)
697 DBG("Driver session overlapped handling!");
698 ERR("WPS PBC SESSION OVERLAPPED");
699 #if defined TIZEN_WEARABLE
702 netconfig_send_message_to_net_popup("WPS Error",
703 "wps session overlapped", "popup", NULL);
707 #if defined TIZEN_DEBUG_ENABLE
708 static void __netconfig_dumpservice_handler(GDBusConnection *conn,
709 const gchar *name, const gchar *path, const gchar *interface,
710 const gchar *sig, GVariant *param, gpointer user_data)
713 gchar *signal_path = NULL;
718 g_variant_get(param, "(is)", &mode, &signal_path);
719 DBG("Path: %s and mode: %d", signal_path, mode);
721 netconfig_dump_log(signal_path);
729 static void _supplicant_tdls_connected(GDBusConnection *conn,
730 const gchar *name, const gchar *path, const gchar *interface,
731 const gchar *sig, GVariant *param, gpointer user_data)
733 DBG("Received TDLS Connected Signal");
734 netconfig_wifi_tdls_connected_event(param);
739 static void _supplicant_tdls_disconnected(GDBusConnection *conn,
740 const gchar *name, const gchar *path, const gchar *interface,
741 const gchar *sig, GVariant *param, gpointer user_data)
743 DBG("Received TDLS Disconnected Signal");
744 netconfig_wifi_tdls_disconnected_event(param);
749 static void _supplicant_tdls_peer_found(GDBusConnection *conn,
750 const gchar *name, const gchar *path, const gchar *interface,
751 const gchar *sig, GVariant *param, gpointer user_data)
753 DBG("Received TDLS Peer Found Signal");
754 netconfig_wifi_tdls_peer_found_event(param);
758 static void _supplicant_wifi_wps_connected(GVariant *param)
761 char ssid[32] = {0, };
765 int config_error = 0;
766 int error_indication = 0;
770 ERR("Param is NULL");
774 g_variant_get(param, "(sa{sv})", &name, &iter);
775 INFO("wps Result: %s", name);
776 while (g_variant_iter_loop(iter, "{sv}", &key, &variant)) {
777 INFO("wps Key is %s", key);
778 if (g_strcmp0(key, "SSID") == 0) {
779 const char *t_key = NULL;
780 t_key = g_variant_get_fixed_array(variant, &ssid_len, sizeof(guchar));
781 INFO("wps ssid_len is %d ", ssid_len);
784 g_variant_unref(variant);
785 ERR("WPS PBC Connection Failed");
788 if (ssid_len > 0 && ssid_len <= 32) {
789 memcpy(ssid, t_key, ssid_len);
791 memset(ssid, 0, sizeof(ssid));
794 INFO("WPS PBC Connection completed with AP %s", ssid);
795 netconfig_wifi_notify_wps_completed(ssid, ssid_len);
799 g_variant_iter_free(iter);
804 g_variant_iter_free(iter);
806 error_indication = WPS_EI_OPERATION_FAILED;
807 config_error = WPS_CFG_NO_ERROR;
808 ERR("Error Occured! Notifying Fail Event");
809 netconfig_wifi_notify_wps_fail_event(config_error, error_indication);
813 static void _supplicant_wifi_wps_event(GVariant *param)
819 gint32 config_error = 0;
820 gint32 error_indication = 0;
823 ERR("Param is NULL");
827 g_variant_get(param, "(sa{sv})", &name, &iter);
828 INFO("Event Result: %s", name);
829 if (g_strcmp0(name, "fail") == 0) {
830 while (g_variant_iter_loop(iter, "{sv}", &key, &variant)) {
833 INFO("Key is %s", key);
834 if (g_strcmp0(key, "config_error") == 0) {
835 config_error = g_variant_get_int32(variant);
836 ERR("Config Error %d", config_error);
837 } else if (g_strcmp0(key, "error_indication") == 0) {
838 error_indication = g_variant_get_int32(variant);
839 ERR("Error Indication %d", error_indication);
842 netconfig_wifi_notify_wps_fail_event(config_error, error_indication);
845 g_variant_iter_free(iter);
850 g_variant_iter_free(iter);
852 error_indication = WPS_EI_OPERATION_FAILED;
853 config_error = WPS_CFG_NO_ERROR;
854 ERR("Error Occured! Notifying Fail Event");
855 netconfig_wifi_notify_wps_fail_event(config_error, error_indication);
858 static void _supplicant_wifi_wps_credentials(GVariant *param)
865 int config_error = 0;
866 int error_indication = 0;
870 ERR("Param is NULL");
874 g_variant_get(param, "(a{sv})", &iter);
875 while (g_variant_iter_loop(iter, "{sv}", &key, &variant)) {
878 INFO("wps Key is %s", key);
879 if (g_strcmp0(key, "Key") == 0) {
881 const char *t_key = NULL;
882 key_len = g_variant_get_size(variant);
884 INFO("wps password len %d ", key_len);
886 t_key = g_variant_get_fixed_array(variant, &key_len, sizeof(guchar));
889 g_variant_unref(variant);
892 strncpy(wps_key, t_key, key_len);
893 wps_key[key_len] = '\0';
894 INFO("WPS Key in process credentials %s", wps_key);
896 SLOGI("WPS AP Security ->Open");
897 } else if (g_strcmp0(key, "SSID") == 0) {
898 const char *t_key = NULL;
899 t_key = g_variant_get_fixed_array(variant, &ssid_len, sizeof(guchar));
900 INFO("wps ssid_len is %d ", ssid_len);
903 g_variant_unref(variant);
906 if (ssid_len > 0 && ssid_len <= 32) {
907 memcpy(ssid, t_key, ssid_len);
909 memset(ssid, 0, sizeof(ssid));
912 INFO("SSID in process credentials %s", ssid);
916 g_variant_iter_free(iter);
920 * Notify WPS Credentials only when requested through WPS PBC
921 * In case of WPS PIN connman will take care of notification
923 if (netconfig_get_wps_field() == TRUE)
925 netconfig_wifi_notify_wps_credentials(ssid, ssid_len, wps_key);
929 g_variant_iter_free(iter);
930 error_indication = WPS_EI_OPERATION_FAILED;
931 config_error = WPS_CFG_NO_ERROR;
932 ERR("Error Occured! Notifying Fail Event");
933 netconfig_wifi_notify_wps_fail_event(config_error, error_indication);
936 static void __netconfig_wps_signal_filter_handler(GDBusConnection *conn,
937 const gchar *name, const gchar *path, const gchar *interface,
938 const gchar *sig, GVariant *param, gpointer user_data)
940 if (g_strcmp0(sig, SIGNAL_WPS_CREDENTIALS) == 0) {
941 INFO("Received wps CREDENTIALS Signal from Supplicant");
942 _supplicant_wifi_wps_credentials(param);
943 } else if (g_strcmp0(sig, SIGNAL_WPS_EVENT) == 0) {
944 INFO("Received wps EVENT Signal from Supplicant");
945 _supplicant_wifi_wps_event(param);
946 } else if (g_strcmp0(sig, SIGNAL_WPS_CONNECTED) == 0) {
947 INFO("Received WPSConnected Signal from Supplicant");
948 _supplicant_wifi_wps_connected(param);
954 static supplicant_signal_cb supplicant_cbs[SIG_MAX] = {
955 _supplicant_interface_removed,
956 _supplicant_properties_changed,
957 _supplicant_bss_added,
958 _supplicant_scan_done,
959 _supplicant_driver_hanged,
960 _supplicant_session_overlapped,
961 _supplicant_tdls_connected,
962 _supplicant_tdls_disconnected,
963 _supplicant_tdls_peer_found
966 void register_gdbus_signal(void)
968 GDBusConnection *connection = NULL;
969 const char *interface = NULL;
970 SuppSigArrayIndex sig;
971 connection = netdbus_get_connection();
973 if (connection == NULL) {
974 ERR("Failed to get GDbus Connection");
978 /* listening to messages from all objects as no path is specified */
979 /* see signals from the given interface */
980 conn_subscription_ids[0] = g_dbus_connection_signal_subscribe(
983 CONNMAN_TECHNOLOGY_INTERFACE,
987 G_DBUS_SIGNAL_FLAGS_NONE,
988 _technology_signal_cb,
992 conn_subscription_ids[1] = g_dbus_connection_signal_subscribe(
995 CONNMAN_SERVICE_INTERFACE,
996 CONNMAN_SIGNAL_PROPERTY_CHANGED,
999 G_DBUS_SIGNAL_FLAGS_NONE,
1004 conn_subscription_ids[2] = g_dbus_connection_signal_subscribe(
1007 DBUS_INTERFACE_DBUS,
1008 CONNMAN_SIGNAL_NAME_CHANGED,
1011 G_DBUS_SIGNAL_FLAGS_NONE,
1012 _dbus_name_changed_cb,
1016 conn_subscription_ids[3] = g_dbus_connection_signal_subscribe(
1019 CONNMAN_MANAGER_INTERFACE,
1020 CONNMAN_SIGNAL_SERVICES_CHANGED,
1023 G_DBUS_SIGNAL_FLAGS_NONE,
1024 _services_changed_cb,
1028 INFO("Successfully register connman DBus signal filters");
1030 conn_subscription_ids[4] = g_dbus_connection_signal_subscribe(
1033 SUPPLICANT_INTERFACE ".Interface.WPS",
1037 G_DBUS_SIGNAL_FLAGS_NONE,
1038 __netconfig_wps_signal_filter_handler,
1042 INFO("Successfully register Supplicant WPS DBus signal filters");
1044 for (sig = SIG_INTERFACE_REMOVED; sig < SIG_MAX; sig++) {
1046 * For SIG_INTERFACE_REMOVED INTERFACE_ADDED
1048 interface = (sig == SIG_INTERFACE_REMOVED) ?
1049 SUPPLICANT_INTERFACE : SUPPLICANT_IFACE_INTERFACE;
1051 supp_subscription_ids[sig] = g_dbus_connection_signal_subscribe(
1055 supplicant_signals[sig],
1058 G_DBUS_SIGNAL_FLAGS_NONE,
1059 supplicant_cbs[sig],
1064 INFO("Successfully register Supplicant DBus signal filters");
1066 #if defined TIZEN_DEBUG_ENABLE
1067 dumpservice_subscription_id = g_dbus_connection_signal_subscribe(
1070 DUMP_SERVICE_INTERFACE,
1074 G_DBUS_SIGNAL_FLAGS_NONE,
1075 __netconfig_dumpservice_handler,
1079 INFO("Successfully registered Dumpservice DBus signal filter");
1082 /* In case ConnMan precedes this signal register,
1083 * net-config should update the default connected profile.
1085 netconfig_update_default();
1088 void deregister_gdbus_signal(void)
1090 GDBusConnection *connection = NULL;
1092 SuppSigArrayIndex sig;
1093 connection = netdbus_get_connection();
1095 ERR("Already de-registered. Nothing to be done");
1099 for (signal = 0; signal < TOTAL_CONN_SIGNALS; signal++) {
1100 if (conn_subscription_ids[signal]) {
1101 g_dbus_connection_signal_unsubscribe(connection,
1102 conn_subscription_ids[signal]);
1106 for (sig = SIG_INTERFACE_REMOVED; sig < SIG_MAX; sig++) {
1107 if (supp_subscription_ids[sig]) {
1108 g_dbus_connection_signal_unsubscribe(connection,
1109 supp_subscription_ids[sig]);
1113 #if defined TIZEN_DEBUG_ENABLE
1114 g_dbus_connection_signal_unsubscribe(connection,
1115 dumpservice_subscription_id);