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)
168 if (g_strcmp0(property, "ready") == 0 || g_strcmp0(property, "online") == 0) {
169 if (wifi_state >= VCONFKEY_WIFI_CONNECTED)
172 netconfig_update_default_profile(path);
174 wifi_state_set_service_state(NETCONFIG_WIFI_CONNECTED);
176 } else if (g_strcmp0(property, "failure") == 0 || g_strcmp0(property, "disconnect") == 0 || g_strcmp0(property, "idle") == 0) {
177 if (netconfig_get_default_profile() == NULL ||
178 netconfig_is_wifi_profile(netconfig_get_default_profile())
180 if (g_strcmp0(property, "failure") == 0)
181 wifi_state_set_service_state(NETCONFIG_WIFI_FAILURE);
183 wifi_state_set_service_state(NETCONFIG_WIFI_IDLE);
187 if (g_strcmp0(path, netconfig_get_default_profile()) != 0)
190 netconfig_update_default_profile(NULL);
192 if (g_strcmp0(property, "failure") == 0)
193 wifi_state_set_service_state(NETCONFIG_WIFI_FAILURE);
195 wifi_state_set_service_state(NETCONFIG_WIFI_IDLE);
197 } else if (g_strcmp0(property, "association") == 0 || g_strcmp0(property, "configuration") == 0) {
198 if (netconfig_get_default_profile() == NULL ||
199 netconfig_is_wifi_profile(netconfig_get_default_profile()) != TRUE) {
200 if (g_strcmp0(property, "association") == 0)
201 wifi_state_set_service_state(NETCONFIG_WIFI_ASSOCIATION);
203 wifi_state_set_service_state(NETCONFIG_WIFI_CONFIGURATION);
207 if (g_strcmp0(path, netconfig_get_default_profile()) != 0)
210 netconfig_update_default_profile(NULL);
212 if (g_strcmp0(property, "association") == 0)
213 wifi_state_set_service_state(NETCONFIG_WIFI_ASSOCIATION);
215 wifi_state_set_service_state(NETCONFIG_WIFI_CONFIGURATION);
219 if (g_strcmp0(property, "ready") == 0 || g_strcmp0(property, "online") == 0) {
220 if (netconfig_get_default_profile() == NULL) {
221 if (!netconfig_is_cellular_profile(path))
222 netconfig_update_default_profile(path);
224 if (netconfig_is_cellular_internet_profile(path))
225 netconfig_update_default_profile(path);
229 if (netconfig_is_cellular_profile(path) && netconfig_is_cellular_internet_profile(path))
230 cellular_state_set_service_state(NETCONFIG_CELLULAR_ONLINE);
232 } else if (g_strcmp0(property, "failure") == 0 || g_strcmp0(property, "disconnect") == 0 || g_strcmp0(property, "idle") == 0) {
233 if (netconfig_get_default_profile() == NULL)
236 if (netconfig_is_cellular_profile(path) && netconfig_is_cellular_internet_profile(path))
237 cellular_state_set_service_state(NETCONFIG_CELLULAR_IDLE);
239 if (g_strcmp0(path, netconfig_get_default_profile()) != 0)
242 netconfig_update_default_profile(NULL);
243 } else if (g_strcmp0(property, "association") == 0 || g_strcmp0(property, "configuration") == 0) {
244 if (netconfig_get_default_profile() == NULL)
247 if (netconfig_is_cellular_profile(path) && netconfig_is_cellular_internet_profile(path))
248 cellular_state_set_service_state(NETCONFIG_CELLULAR_CONNECTING);
250 if (g_strcmp0(path, netconfig_get_default_profile()) != 0)
253 netconfig_update_default_profile(NULL);
256 } else if (g_strcmp0(sigvalue, "Proxy") == 0) {
257 if (netconfig_is_wifi_profile(path) != TRUE || g_strcmp0(path, netconfig_get_default_profile()) != 0)
260 if (!g_variant_type_equal(variant, G_VARIANT_TYPE_ARRAY))
263 g_variant_get(variant, "a{sv}", &iter);
264 while (g_variant_iter_loop(iter, "{sv}", &property, &var)) {
265 if (g_strcmp0(property, "Servers") == 0) {
266 GVariantIter *iter_sub = NULL;
268 g_variant_get(var, "as", &iter_sub);
269 g_variant_iter_loop(iter_sub, "s", &value);
270 g_variant_iter_free(iter_sub);
272 DBG("Proxy - [%s]", value);
273 vconf_set_str(VCONFKEY_NETWORK_PROXY, value);
276 g_variant_unref(var);
278 } else if (g_strcmp0(property, "Method") == 0) {
279 value = g_variant_get_string(var, NULL);
280 DBG("Method - [%s]", value);
282 if (g_strcmp0(value, "direct") == 0)
283 vconf_set_str(VCONFKEY_NETWORK_PROXY, "");
286 g_variant_unref(var);
291 g_variant_iter_free(iter);
292 } else if (g_strcmp0(sigvalue, "Error") == 0) {
293 g_variant_get(variant, "s", &property);
294 INFO("[%s] Property : %s", sigvalue, property);
301 g_variant_unref(variant);
306 static void _dbus_name_changed_cb(GDBusConnection *conn,
307 const gchar *Name, const gchar *path, const gchar *interface,
308 const gchar *sig, GVariant *param, gpointer user_data)
317 g_variant_get(param, "(sss)", &name, &old, &new);
319 if (g_strcmp0(name, CONNMAN_SERVICE) == 0 && *new == '\0') {
320 DBG("ConnMan destroyed: name %s, old %s, new %s", name, old, new);
322 connman_register_agent();
334 static void _services_changed_cb(GDBusConnection *conn, const gchar *name,
335 const gchar *path, const gchar *interface, const gchar *sig,
336 GVariant *param, gpointer user_data)
338 gchar *property, *value;
340 GVariant *variant = NULL;
341 GVariantIter *added = NULL, *removed = NULL, *next = NULL;
343 if (path == NULL || param == NULL)
346 if (g_strcmp0(sig, CONNMAN_SIGNAL_SERVICES_CHANGED) != 0)
349 if (netconfig_get_default_profile() != NULL)
352 g_variant_get(param, "(a(oa{sv})ao)", &added, &removed);
354 while (g_variant_iter_loop(added, "(oa{sv})", &service_path, &next)) {
355 gboolean is_wifi_prof, is_cell_prof, is_cell_internet_prof;
356 is_wifi_prof = netconfig_is_wifi_profile(service_path);
357 is_cell_prof = netconfig_is_cellular_profile(service_path);
358 is_cell_internet_prof = netconfig_is_cellular_internet_profile(
360 if (service_path != NULL) {
361 while (g_variant_iter_loop(next, "{sv}", &property,
363 if (g_strcmp0(property, "State") == 0) {
364 g_variant_get(variant, "s", &value);
365 DBG("Profile %s State %s", service_path,
367 if (g_strcmp0(value, "ready") != 0 &&
371 g_variant_unref(variant);
376 netconfig_update_default_profile(
378 else if (is_cell_internet_prof) {
379 netconfig_update_default_profile(
383 wifi_state_set_service_state(
384 NETCONFIG_WIFI_CONNECTED);
385 else if (is_cell_prof &&
386 is_cell_internet_prof)
387 cellular_state_set_service_state(
388 NETCONFIG_CELLULAR_ONLINE);
390 g_variant_unref(variant);
397 g_variant_iter_free(added);
400 g_variant_iter_free(next);
402 g_variant_iter_free(removed);
407 static void _supplicant_interface_removed(GDBusConnection *conn,
408 const gchar *name, const gchar *path, const gchar *interface,
409 const gchar *sig, GVariant *param, gpointer user_data)
411 DBG("Interface removed handling!");
412 if (netconfig_wifi_is_wps_enabled() == TRUE)
413 netconfig_wifi_wps_signal_scanaborted();
418 static void _supplicant_properties_changed(GDBusConnection *conn,
419 const gchar *name, const gchar *path, const gchar *interface,
420 const gchar *sig, GVariant *param, gpointer user_data)
422 DBG("Properties changed handling!");
426 gboolean scanning = FALSE;
431 g_variant_get(param, "(a{sv})", &iter);
432 while (g_variant_iter_loop(iter, "{sv}", &key, &variant)) {
433 if (g_strcmp0(key, "Scanning") == 0) {
434 scanning = g_variant_get_boolean(variant);
435 if (scanning == TRUE)
436 netconfig_wifi_set_scanning(TRUE);
438 g_variant_unref(variant);
444 g_variant_iter_free(iter);
449 static void _supplicant_bss_added(GDBusConnection *conn,
450 const gchar *name, const gchar *path, const gchar *interface,
451 const gchar *sig, GVariant *param, gpointer user_data)
453 DBG("BSS added handling!");
454 if (wifi_ssid_scan_get_state() == TRUE)
455 wifi_ssid_scan_add_bss(param);
457 wifi_state_set_bss_found(TRUE);
462 static void _supplicant_scan_done(GDBusConnection *conn,
463 const gchar *name, const gchar *path, const gchar *interface,
464 const gchar *sig, GVariant *param, gpointer user_data)
466 DBG("Scan Done handling!");
467 netconfig_wifi_set_scanning(FALSE);
469 if (netconfig_wifi_is_wps_enabled() == TRUE) {
470 netconfig_wifi_wps_signal_scandone();
471 if (wifi_state_get_technology_state() < NETCONFIG_WIFI_TECH_POWERED)
475 if (netconfig_wifi_get_bgscan_state() != TRUE) {
476 if (wifi_ssid_scan_get_state() == TRUE)
477 wifi_ssid_scan_emit_scan_completed();
479 wifi_ssid_scan(NULL);
481 if (wifi_state_get_technology_state() >=
482 NETCONFIG_WIFI_TECH_POWERED)
483 netconfig_wifi_bgscan_start(FALSE);
485 wifi_start_timer_network_notification();
491 static void _supplicant_driver_hanged(GDBusConnection *conn,
492 const gchar *name, const gchar *path, const gchar *interface,
493 const gchar *sig, GVariant *param, gpointer user_data)
495 DBG("Driver Hanged handling!");
496 ERR("Critical. Wi-Fi firmware crashed");
498 wifi_power_recover_firmware();
503 static void _supplicant_session_overlapped(GDBusConnection *conn,
504 const gchar *name, const gchar *path, const gchar *interface,
505 const gchar *sig, GVariant *param, gpointer user_data)
507 DBG("Driver session overlapped handling!");
508 ERR("WPS PBC SESSION OVERLAPPED");
509 #if defined TIZEN_WEARABLE
510 wc_launch_syspopup(WC_POPUP_TYPE_SESSION_OVERLAPPED);
512 netconfig_send_message_to_net_popup("WPS Error",
513 "wps session overlapped", "popup", NULL);
517 static void _supplicant_tdls_connected(GDBusConnection *conn,
518 const gchar *name, const gchar *path, const gchar *interface,
519 const gchar *sig, GVariant *param, gpointer user_data)
521 ERR("Received TDLS Connected Signal");
522 netconfig_wifi_tlds_connected_event(param);
527 static void _supplicant_tdls_disconnected(GDBusConnection *conn,
528 const gchar *name, const gchar *path, const gchar *interface,
529 const gchar *sig, GVariant *param, gpointer user_data)
531 ERR("Received TDLS Disconnected Signal");
532 netconfig_wifi_tlds_disconnected_event(param);
537 static void _supplicant_tdls_peer_found(GDBusConnection *conn,
538 const gchar *name, const gchar *path, const gchar *interface,
539 const gchar *sig, GVariant *param, gpointer user_data)
541 ERR("Received TDLS Peer Found Signal");
545 static supplicant_signal_cb supplicant_cbs[SIG_MAX] = {
546 _supplicant_interface_removed,
547 _supplicant_properties_changed,
548 _supplicant_bss_added,
549 _supplicant_scan_done,
550 _supplicant_driver_hanged,
551 _supplicant_session_overlapped,
552 _supplicant_tdls_connected,
553 _supplicant_tdls_disconnected,
554 _supplicant_tdls_peer_found
557 #if defined TIZEN_DEBUG_DISABLE
558 static void __netconfig_dumpservice_handler(GDBusConnection *conn,
559 const gchar *name, const gchar *path, const gchar *interface,
560 const gchar *sig, GVariant *param, gpointer user_data)
563 gchar *signal_path = NULL;
568 g_variant_get(param, "(io)", &mode, &signal_path);
569 DBG("Path: %s and mode: %d", signal_path, mode);
570 netconfig_dump_log(path);
578 void register_gdbus_signal(void)
580 GDBusConnection *connection = NULL;
581 const char *interface = NULL;
582 SuppSigArrayIndex sig;
583 connection = netdbus_get_connection();
585 if (connection == NULL) {
586 ERR("Failed to get GDbus Connection");
590 /* listening to messages from all objects as no path is specified */
591 /* see signals from the given interface */
592 conn_subscription_ids[0] = g_dbus_connection_signal_subscribe(
595 CONNMAN_TECHNOLOGY_INTERFACE,
599 G_DBUS_SIGNAL_FLAGS_NONE,
600 _technology_signal_cb,
604 conn_subscription_ids[1] = g_dbus_connection_signal_subscribe(
607 CONNMAN_SERVICE_INTERFACE,
608 CONNMAN_SIGNAL_PROPERTY_CHANGED,
611 G_DBUS_SIGNAL_FLAGS_NONE,
616 conn_subscription_ids[2] = g_dbus_connection_signal_subscribe(
620 CONNMAN_SIGNAL_NAME_CHANGED,
623 G_DBUS_SIGNAL_FLAGS_NONE,
624 _dbus_name_changed_cb,
628 conn_subscription_ids[3] = g_dbus_connection_signal_subscribe(
631 CONNMAN_MANAGER_INTERFACE,
632 CONNMAN_SIGNAL_SERVICES_CHANGED,
635 G_DBUS_SIGNAL_FLAGS_NONE,
636 _services_changed_cb,
640 INFO("Successfully register connman DBus signal filters");
642 for (sig = SIG_INTERFACE_REMOVED; sig < SIG_MAX; sig++) {
644 * For SIG_INTERFACE_REMOVED INTERFACE_ADDED
646 interface = (sig == SIG_INTERFACE_REMOVED) ?
647 SUPPLICANT_INTERFACE : SUPPLICANT_IFACE_INTERFACE;
649 supp_subscription_ids[sig] = g_dbus_connection_signal_subscribe(
653 supplicant_signals[sig],
656 G_DBUS_SIGNAL_FLAGS_NONE,
662 INFO("Successfully register Supplicant DBus signal filters");
664 #if defined TIZEN_DEBUG_DISABLE
665 dumpservice_subscription_id = g_dbus_connection_signal_subscribe(
668 * Sender => For testing purpose made NULL
672 DUMP_SERVICE_INTERFACE,
676 G_DBUS_SIGNAL_FLAGS_NONE,
677 __netconfig_dumpservice_handler,
681 INFO("Successfully register Dumpservice DBus signal filter");
683 /* In case ConnMan precedes this signal register,
684 * net-config should update the default connected profile.
686 netconfig_update_default();
689 void deregister_gdbus_signal(void)
691 GDBusConnection *connection = NULL;
693 SuppSigArrayIndex sig;
694 connection = netdbus_get_connection();
696 ERR("Already de-registered. Nothing to be done");
700 for (signal = 0; signal < TOTAL_CONN_SIGNALS; signal++) {
701 if (conn_subscription_ids[signal]) {
702 g_dbus_connection_signal_unsubscribe(connection,
703 conn_subscription_ids[signal]);
707 for (sig = SIG_INTERFACE_REMOVED; sig < SIG_MAX; sig++) {
708 if (supp_subscription_ids[sig]) {
709 g_dbus_connection_signal_unsubscribe(connection,
710 supp_subscription_ids[sig]);
714 g_dbus_connection_signal_unsubscribe(connection,
715 dumpservice_subscription_id);