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.
23 #include <vconf-keys.h>
30 #include "wifi-agent.h"
31 #include "wifi-power.h"
32 #include "wifi-state.h"
33 #include "netsupplicant.h"
34 #include "network-state.h"
35 #include "cellular-state.h"
36 #include "signal-handler.h"
37 #include "wifi-ssid-scan.h"
38 #include "wifi-background-scan.h"
39 #include "wifi-tdls.h"
41 #if defined TIZEN_DEBUG_DISABLE
42 #include "wifi-dump.h"
45 #define DBUS_SERVICE_DBUS "org.freedesktop.DBus"
46 #define DBUS_INTERFACE_DBUS "org.freedesktop.DBus"
47 #define SIGNAL_INTERFACE_REMOVED "InterfaceRemoved"
48 #define SIGNAL_SCAN_DONE "ScanDone"
49 #define SIGNAL_BSS_ADDED "BSSAdded"
50 #define SIGNAL_PROPERTIES_CHANGED "PropertiesChanged"
51 #define SIGNAL_PROPERTIES_DRIVER_HANGED "DriverHanged"
52 #define SIGNAL_PROPERTIES_SESSION_OVERLAPPED "SessionOverlapped"
53 #define SIGNAL_TDLS_CONNECTED "TDLSConnected"
54 #define SIGNAL_TDLS_DISCONNECTED "TDLSDisconnected"
55 #define SIGNAL_TDLS_PEER_FOUND "TDLSPeerFound"
56 #define CONNMAN_SIGNAL_SERVICES_CHANGED "ServicesChanged"
57 #define CONNMAN_SIGNAL_PROPERTY_CHANGED "PropertyChanged"
58 #define CONNMAN_SIGNAL_NAME_CHANGED "NameOwnerChanged"
60 #define MAX_SIG_LEN 64
61 #define TOTAL_CONN_SIGNALS 4
64 SIG_INTERFACE_REMOVED = 0,
65 SIG_PROPERTIES_CHANGED,
69 SIG_SESSION_OVERLAPPED,
71 SIG_TDLS_DISCONNECTED,
76 static int conn_subscription_ids[TOTAL_CONN_SIGNALS] = {0};
77 static const char supplicant_signals[SIG_MAX][MAX_SIG_LEN] = {
78 SIGNAL_INTERFACE_REMOVED,
79 SIGNAL_PROPERTIES_CHANGED,
82 SIGNAL_PROPERTIES_DRIVER_HANGED,
83 SIGNAL_PROPERTIES_SESSION_OVERLAPPED,
84 SIGNAL_TDLS_CONNECTED,
85 SIGNAL_TDLS_DISCONNECTED,
86 SIGNAL_TDLS_PEER_FOUND,
89 static int supp_subscription_ids[SIG_MAX] = {0};
90 static int dumpservice_subscription_id = 0;
92 typedef void (*supplicant_signal_cb)(GDBusConnection *conn,
93 const gchar *name, const gchar *path, const gchar *interface,
94 const gchar *sig, GVariant *param, gpointer user_data);
95 typedef void (*connman_signal_cb)(GDBusConnection *conn,
96 const gchar *name, const gchar *path, const gchar *interface,
97 const gchar *sig, GVariant *param, gpointer user_data);
99 static void _technology_signal_cb(GDBusConnection *conn,
100 const gchar *name, const gchar *path, const gchar *interface,
101 const gchar *sig, GVariant *param, gpointer user_data)
104 gboolean value = FALSE;
105 GVariant *var = NULL;
110 if (g_str_has_prefix(path, CONNMAN_WIFI_TECHNOLOGY_PREFIX) == TRUE) {
111 g_variant_get(param, "(sv)", &key, &var);
112 if (g_strcmp0(key, "Powered") == 0) {
114 value = g_variant_get_boolean(var);
116 wifi_state_update_power_state(TRUE);
118 wifi_state_update_power_state(FALSE);
119 } else if (g_strcmp0(key, "Connected") == 0) {
120 /* Connection state */
121 value = g_variant_get_boolean(var);
123 wifi_state_set_tech_state(NETCONFIG_WIFI_TECH_CONNECTED);
125 wifi_state_set_tech_state(NETCONFIG_WIFI_TECH_POWERED);
126 } else if (g_strcmp0(key, "Tethering") == 0) {
127 /* Tethering state */
128 wifi_state_set_tech_state(NETCONFIG_WIFI_TECH_TETHERED);
133 g_variant_unref(var);
137 static void _service_signal_cb(GDBusConnection *conn,
138 const gchar *name, const gchar *path,
139 const gchar *interface, const gchar *sig, GVariant *param, gpointer user_data)
141 gchar *sigvalue = NULL;
143 GVariant *variant = NULL, *var;
145 const gchar *value = NULL;
147 if (path == NULL || param == NULL)
150 g_variant_get(param, "(sv)", &sigvalue, &variant);
151 if (sigvalue == NULL)
154 if (g_strcmp0(sig, CONNMAN_SIGNAL_PROPERTY_CHANGED) != 0)
157 if (g_strcmp0(sigvalue, "State") == 0) {
158 g_variant_get(variant, "s", &property);
160 DBG("[%s] %s", property, path);
161 if (netconfig_is_wifi_profile(path) == TRUE) {
164 vconf_get_int(VCONFKEY_WIFI_STATE, &wifi_state);
165 if (wifi_state == VCONFKEY_WIFI_OFF) {
170 if (g_strcmp0(property, "ready") == 0 || g_strcmp0(property, "online") == 0) {
171 if (wifi_state >= VCONFKEY_WIFI_CONNECTED) {
176 netconfig_update_default_profile(path);
178 wifi_state_set_service_state(NETCONFIG_WIFI_CONNECTED);
180 } else if (g_strcmp0(property, "failure") == 0 || g_strcmp0(property, "disconnect") == 0 || g_strcmp0(property, "idle") == 0) {
181 if (netconfig_get_default_profile() == NULL ||
182 netconfig_is_wifi_profile(netconfig_get_default_profile())
184 if (g_strcmp0(property, "failure") == 0)
185 wifi_state_set_service_state(NETCONFIG_WIFI_FAILURE);
187 wifi_state_set_service_state(NETCONFIG_WIFI_IDLE);
192 if (g_strcmp0(path, netconfig_get_default_profile()) != 0) {
197 netconfig_update_default_profile(NULL);
199 if (g_strcmp0(property, "failure") == 0)
200 wifi_state_set_service_state(NETCONFIG_WIFI_FAILURE);
202 wifi_state_set_service_state(NETCONFIG_WIFI_IDLE);
204 } else if (g_strcmp0(property, "association") == 0 || g_strcmp0(property, "configuration") == 0) {
205 if (netconfig_get_default_profile() == NULL ||
206 netconfig_is_wifi_profile(netconfig_get_default_profile()) != TRUE) {
207 if (g_strcmp0(property, "association") == 0)
208 wifi_state_set_service_state(NETCONFIG_WIFI_ASSOCIATION);
210 wifi_state_set_service_state(NETCONFIG_WIFI_CONFIGURATION);
215 if (g_strcmp0(path, netconfig_get_default_profile()) != 0) {
220 netconfig_update_default_profile(NULL);
222 if (g_strcmp0(property, "association") == 0)
223 wifi_state_set_service_state(NETCONFIG_WIFI_ASSOCIATION);
225 wifi_state_set_service_state(NETCONFIG_WIFI_CONFIGURATION);
229 if (g_strcmp0(property, "ready") == 0 || g_strcmp0(property, "online") == 0) {
230 if (netconfig_get_default_profile() == NULL) {
231 if (!netconfig_is_cellular_profile(path))
232 netconfig_update_default_profile(path);
234 if (netconfig_is_cellular_internet_profile(path))
235 netconfig_update_default_profile(path);
239 if (netconfig_is_cellular_profile(path) && netconfig_is_cellular_internet_profile(path))
240 cellular_state_set_service_state(NETCONFIG_CELLULAR_ONLINE);
242 } else if (g_strcmp0(property, "failure") == 0 || g_strcmp0(property, "disconnect") == 0 || g_strcmp0(property, "idle") == 0) {
243 if (netconfig_get_default_profile() == NULL) {
248 if (netconfig_is_cellular_profile(path) && netconfig_is_cellular_internet_profile(path))
249 cellular_state_set_service_state(NETCONFIG_CELLULAR_IDLE);
251 if (g_strcmp0(path, netconfig_get_default_profile()) != 0) {
256 netconfig_update_default_profile(NULL);
257 } else if (g_strcmp0(property, "association") == 0 || g_strcmp0(property, "configuration") == 0) {
258 if (netconfig_get_default_profile() == NULL) {
263 if (netconfig_is_cellular_profile(path) && netconfig_is_cellular_internet_profile(path))
264 cellular_state_set_service_state(NETCONFIG_CELLULAR_CONNECTING);
266 if (g_strcmp0(path, netconfig_get_default_profile()) != 0) {
271 netconfig_update_default_profile(NULL);
275 } else if (g_strcmp0(sigvalue, "Proxy") == 0) {
276 if (netconfig_is_wifi_profile(path) != TRUE || g_strcmp0(path, netconfig_get_default_profile()) != 0)
279 if (!g_variant_type_equal(variant, G_VARIANT_TYPE_ARRAY))
282 g_variant_get(variant, "a{sv}", &iter);
283 while (g_variant_iter_loop(iter, "{sv}", &property, &var)) {
284 if (g_strcmp0(property, "Servers") == 0) {
285 GVariantIter *iter_sub = NULL;
287 g_variant_get(var, "as", &iter_sub);
288 g_variant_iter_loop(iter_sub, "s", &value);
289 g_variant_iter_free(iter_sub);
291 DBG("Proxy - [%s]", value);
292 vconf_set_str(VCONFKEY_NETWORK_PROXY, value);
295 g_variant_unref(var);
297 } else if (g_strcmp0(property, "Method") == 0) {
298 value = g_variant_get_string(var, NULL);
299 DBG("Method - [%s]", value);
301 if (g_strcmp0(value, "direct") == 0)
302 vconf_set_str(VCONFKEY_NETWORK_PROXY, "");
305 g_variant_unref(var);
310 g_variant_iter_free(iter);
311 } else if (g_strcmp0(sigvalue, "Error") == 0) {
312 g_variant_get(variant, "s", &property);
313 INFO("[%s] Property : %s", sigvalue, property);
321 g_variant_unref(variant);
326 static void _dbus_name_changed_cb(GDBusConnection *conn,
327 const gchar *Name, const gchar *path, const gchar *interface,
328 const gchar *sig, GVariant *param, gpointer user_data)
337 g_variant_get(param, "(sss)", &name, &old, &new);
339 if (g_strcmp0(name, CONNMAN_SERVICE) == 0 && *new == '\0') {
340 DBG("ConnMan destroyed: name %s, old %s, new %s", name, old, new);
342 connman_register_agent();
354 static void _services_changed_cb(GDBusConnection *conn, const gchar *name,
355 const gchar *path, const gchar *interface, const gchar *sig,
356 GVariant *param, gpointer user_data)
358 gchar *property, *value;
360 GVariant *variant = NULL;
361 GVariantIter *added = NULL, *removed = NULL, *next = NULL;
363 if (path == NULL || param == NULL)
366 if (g_strcmp0(sig, CONNMAN_SIGNAL_SERVICES_CHANGED) != 0)
369 if (netconfig_get_default_profile() != NULL)
372 g_variant_get(param, "(a(oa{sv})ao)", &added, &removed);
374 while (g_variant_iter_loop(added, "(oa{sv})", &service_path, &next)) {
375 gboolean is_wifi_prof, is_cell_prof, is_cell_internet_prof;
376 is_wifi_prof = netconfig_is_wifi_profile(service_path);
377 is_cell_prof = netconfig_is_cellular_profile(service_path);
378 is_cell_internet_prof = netconfig_is_cellular_internet_profile(
380 if (service_path != NULL) {
381 while (g_variant_iter_loop(next, "{sv}", &property,
383 if (g_strcmp0(property, "State") == 0) {
384 g_variant_get(variant, "s", &value);
385 DBG("Profile %s State %s", service_path,
387 if (g_strcmp0(value, "ready") != 0 &&
392 g_variant_unref(variant);
397 netconfig_update_default_profile(
399 else if (is_cell_internet_prof) {
400 netconfig_update_default_profile(
404 wifi_state_set_service_state(
405 NETCONFIG_WIFI_CONNECTED);
406 else if (is_cell_prof &&
407 is_cell_internet_prof)
408 cellular_state_set_service_state(
409 NETCONFIG_CELLULAR_ONLINE);
412 g_variant_unref(variant);
419 g_variant_iter_free(added);
422 g_variant_iter_free(next);
425 g_variant_iter_free(removed);
430 static void _supplicant_interface_removed(GDBusConnection *conn,
431 const gchar *name, const gchar *path, const gchar *interface,
432 const gchar *sig, GVariant *param, gpointer user_data)
434 DBG("Interface removed handling!");
435 if (netconfig_wifi_is_wps_enabled() == TRUE)
436 netconfig_wifi_wps_signal_scanaborted();
441 static void _supplicant_properties_changed(GDBusConnection *conn,
442 const gchar *name, const gchar *path, const gchar *interface,
443 const gchar *sig, GVariant *param, gpointer user_data)
445 DBG("Properties changed handling!");
449 gboolean scanning = FALSE;
454 g_variant_get(param, "(a{sv})", &iter);
455 while (g_variant_iter_loop(iter, "{sv}", &key, &variant)) {
456 if (g_strcmp0(key, "Scanning") == 0) {
457 scanning = g_variant_get_boolean(variant);
458 if (scanning == TRUE)
459 netconfig_wifi_set_scanning(TRUE);
461 g_variant_unref(variant);
467 g_variant_iter_free(iter);
472 static void _supplicant_bss_added(GDBusConnection *conn,
473 const gchar *name, const gchar *path, const gchar *interface,
474 const gchar *sig, GVariant *param, gpointer user_data)
476 DBG("BSS added handling!");
477 if (wifi_ssid_scan_get_state() == TRUE)
478 wifi_ssid_scan_add_bss(param);
480 wifi_state_set_bss_found(TRUE);
485 static void _supplicant_scan_done(GDBusConnection *conn,
486 const gchar *name, const gchar *path, const gchar *interface,
487 const gchar *sig, GVariant *param, gpointer user_data)
489 DBG("Scan Done handling!");
490 netconfig_wifi_set_scanning(FALSE);
492 if (netconfig_wifi_is_wps_enabled() == TRUE) {
493 netconfig_wifi_wps_signal_scandone();
494 if (wifi_state_get_technology_state() < NETCONFIG_WIFI_TECH_POWERED)
498 if (netconfig_wifi_get_bgscan_state() != TRUE) {
499 if (wifi_ssid_scan_get_state() == TRUE)
500 wifi_ssid_scan_emit_scan_completed();
502 wifi_ssid_scan(NULL);
504 if (wifi_state_get_technology_state() >=
505 NETCONFIG_WIFI_TECH_POWERED)
506 netconfig_wifi_bgscan_start(FALSE);
508 wifi_start_timer_network_notification();
514 static void _supplicant_driver_hanged(GDBusConnection *conn,
515 const gchar *name, const gchar *path, const gchar *interface,
516 const gchar *sig, GVariant *param, gpointer user_data)
518 DBG("Driver Hanged handling!");
519 ERR("Critical. Wi-Fi firmware crashed");
521 wifi_power_recover_firmware();
526 static void _supplicant_session_overlapped(GDBusConnection *conn,
527 const gchar *name, const gchar *path, const gchar *interface,
528 const gchar *sig, GVariant *param, gpointer user_data)
530 DBG("Driver session overlapped handling!");
531 ERR("WPS PBC SESSION OVERLAPPED");
532 #if defined TIZEN_WEARABLE
533 wc_launch_syspopup(WC_POPUP_TYPE_SESSION_OVERLAPPED);
535 netconfig_send_message_to_net_popup("WPS Error",
536 "wps session overlapped", "popup", NULL);
540 static void _supplicant_tdls_connected(GDBusConnection *conn,
541 const gchar *name, const gchar *path, const gchar *interface,
542 const gchar *sig, GVariant *param, gpointer user_data)
544 ERR("Received TDLS Connected Signal");
545 netconfig_wifi_tlds_connected_event(param);
550 static void _supplicant_tdls_disconnected(GDBusConnection *conn,
551 const gchar *name, const gchar *path, const gchar *interface,
552 const gchar *sig, GVariant *param, gpointer user_data)
554 ERR("Received TDLS Disconnected Signal");
555 netconfig_wifi_tlds_disconnected_event(param);
560 static void _supplicant_tdls_peer_found(GDBusConnection *conn,
561 const gchar *name, const gchar *path, const gchar *interface,
562 const gchar *sig, GVariant *param, gpointer user_data)
564 ERR("Received TDLS Peer Found Signal");
568 static supplicant_signal_cb supplicant_cbs[SIG_MAX] = {
569 _supplicant_interface_removed,
570 _supplicant_properties_changed,
571 _supplicant_bss_added,
572 _supplicant_scan_done,
573 _supplicant_driver_hanged,
574 _supplicant_session_overlapped,
575 _supplicant_tdls_connected,
576 _supplicant_tdls_disconnected,
577 _supplicant_tdls_peer_found
580 #if defined TIZEN_DEBUG_DISABLE
581 static void __netconfig_dumpservice_handler(GDBusConnection *conn,
582 const gchar *name, const gchar *path, const gchar *interface,
583 const gchar *sig, GVariant *param, gpointer user_data)
586 gchar *signal_path = NULL;
591 g_variant_get(param, "(io)", &mode, &signal_path);
592 DBG("Path: %s and mode: %d", signal_path, mode);
593 netconfig_dump_log(path);
601 void register_gdbus_signal(void)
603 GDBusConnection *connection = NULL;
604 const char *interface = NULL;
605 SuppSigArrayIndex sig;
606 connection = netdbus_get_connection();
608 if (connection == NULL) {
609 ERR("Failed to get GDbus Connection");
613 /* listening to messages from all objects as no path is specified */
614 /* see signals from the given interface */
615 conn_subscription_ids[0] = g_dbus_connection_signal_subscribe(
618 CONNMAN_TECHNOLOGY_INTERFACE,
622 G_DBUS_SIGNAL_FLAGS_NONE,
623 _technology_signal_cb,
627 conn_subscription_ids[1] = g_dbus_connection_signal_subscribe(
630 CONNMAN_SERVICE_INTERFACE,
631 CONNMAN_SIGNAL_PROPERTY_CHANGED,
634 G_DBUS_SIGNAL_FLAGS_NONE,
639 conn_subscription_ids[2] = g_dbus_connection_signal_subscribe(
643 CONNMAN_SIGNAL_NAME_CHANGED,
646 G_DBUS_SIGNAL_FLAGS_NONE,
647 _dbus_name_changed_cb,
651 conn_subscription_ids[3] = g_dbus_connection_signal_subscribe(
654 CONNMAN_MANAGER_INTERFACE,
655 CONNMAN_SIGNAL_SERVICES_CHANGED,
658 G_DBUS_SIGNAL_FLAGS_NONE,
659 _services_changed_cb,
663 INFO("Successfully register connman DBus signal filters");
665 for (sig = SIG_INTERFACE_REMOVED; sig < SIG_MAX; sig++) {
667 * For SIG_INTERFACE_REMOVED INTERFACE_ADDED
669 interface = (sig == SIG_INTERFACE_REMOVED) ?
670 SUPPLICANT_INTERFACE : SUPPLICANT_IFACE_INTERFACE;
672 supp_subscription_ids[sig] = g_dbus_connection_signal_subscribe(
676 supplicant_signals[sig],
679 G_DBUS_SIGNAL_FLAGS_NONE,
685 INFO("Successfully register Supplicant DBus signal filters");
687 #if defined TIZEN_DEBUG_DISABLE
688 dumpservice_subscription_id = g_dbus_connection_signal_subscribe(
691 * Sender => For testing purpose made NULL
695 DUMP_SERVICE_INTERFACE,
699 G_DBUS_SIGNAL_FLAGS_NONE,
700 __netconfig_dumpservice_handler,
704 INFO("Successfully register Dumpservice DBus signal filter");
706 /* In case ConnMan precedes this signal register,
707 * net-config should update the default connected profile.
709 netconfig_update_default();
712 void deregister_gdbus_signal(void)
714 GDBusConnection *connection = NULL;
716 SuppSigArrayIndex sig;
717 connection = netdbus_get_connection();
719 ERR("Already de-registered. Nothing to be done");
723 for (signal = 0; signal < TOTAL_CONN_SIGNALS; signal++) {
724 if (conn_subscription_ids[signal]) {
725 g_dbus_connection_signal_unsubscribe(connection,
726 conn_subscription_ids[signal]);
730 for (sig = SIG_INTERFACE_REMOVED; sig < SIG_MAX; sig++) {
731 if (supp_subscription_ids[sig]) {
732 g_dbus_connection_signal_unsubscribe(connection,
733 supp_subscription_ids[sig]);
737 g_dbus_connection_signal_unsubscribe(connection,
738 dumpservice_subscription_id);