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);
120 } else if (g_strcmp0(key, "Connected") == 0) {
121 /* Connection state */
122 wifi_state_set_tech_state(NETCONFIG_WIFI_TECH_CONNECTED);
123 } else if (g_strcmp0(key, "Tethering") == 0) {
124 /* Tethering state */
125 wifi_state_set_tech_state(NETCONFIG_WIFI_TECH_TETHERED);
130 g_variant_unref(var);
134 static void _service_signal_cb(GDBusConnection *conn,
135 const gchar *name, const gchar *path,
136 const gchar *interface, const gchar *sig, GVariant *param, gpointer user_data)
138 gchar *sigvalue = NULL;
140 GVariant *variant = NULL, *var;
142 const gchar *value = NULL;
144 if (path == NULL || param == NULL)
147 g_variant_get(param, "(sv)", &sigvalue, &variant);
148 if (sigvalue == NULL)
151 if (g_strcmp0(sig, CONNMAN_SIGNAL_PROPERTY_CHANGED) != 0) {
155 if (g_strcmp0(sigvalue, "State") == 0) {
156 g_variant_get(variant, "s", &property);
158 DBG("[%s] %s", property, path);
159 if (netconfig_is_wifi_profile(path) == TRUE) {
162 vconf_get_int(VCONFKEY_WIFI_STATE, &wifi_state);
163 if (wifi_state == VCONFKEY_WIFI_OFF)
166 if (g_strcmp0(property, "ready") == 0 || g_strcmp0(property, "online") == 0) {
167 if (wifi_state >= VCONFKEY_WIFI_CONNECTED)
170 netconfig_update_default_profile(path);
172 wifi_state_set_service_state(NETCONFIG_WIFI_CONNECTED);
174 } else if (g_strcmp0(property, "failure") == 0 || g_strcmp0(property, "disconnect") == 0 || g_strcmp0(property, "idle") == 0) {
175 if (netconfig_get_default_profile() == NULL ||
176 netconfig_is_wifi_profile(netconfig_get_default_profile())
178 if (g_strcmp0(property, "failure") == 0)
179 wifi_state_set_service_state(NETCONFIG_WIFI_FAILURE);
181 wifi_state_set_service_state(NETCONFIG_WIFI_IDLE);
185 if (g_strcmp0(path, netconfig_get_default_profile()) != 0)
188 netconfig_update_default_profile(NULL);
190 if (g_strcmp0(property, "failure") == 0)
191 wifi_state_set_service_state(NETCONFIG_WIFI_FAILURE);
193 wifi_state_set_service_state(NETCONFIG_WIFI_IDLE);
195 } else if (g_strcmp0(property, "association") == 0 || g_strcmp0(property, "configuration") == 0) {
196 if (netconfig_get_default_profile() == NULL ||
197 netconfig_is_wifi_profile(netconfig_get_default_profile()) != TRUE) {
198 if (g_strcmp0(property, "association") == 0)
199 wifi_state_set_service_state(NETCONFIG_WIFI_ASSOCIATION);
201 wifi_state_set_service_state(NETCONFIG_WIFI_CONFIGURATION);
205 if (g_strcmp0(path, netconfig_get_default_profile()) != 0)
208 netconfig_update_default_profile(NULL);
210 if (g_strcmp0(property, "association") == 0)
211 wifi_state_set_service_state(NETCONFIG_WIFI_ASSOCIATION);
213 wifi_state_set_service_state(NETCONFIG_WIFI_CONFIGURATION);
217 if (g_strcmp0(property, "ready") == 0 || g_strcmp0(property, "online") == 0) {
218 if (netconfig_get_default_profile() == NULL) {
219 if(!netconfig_is_cellular_profile(path)) {
220 netconfig_update_default_profile(path);
222 if (netconfig_is_cellular_internet_profile(path)) {
223 netconfig_update_default_profile(path);
228 if (netconfig_is_cellular_profile(path) && netconfig_is_cellular_internet_profile(path))
229 cellular_state_set_service_state(NETCONFIG_CELLULAR_ONLINE);
231 } else if (g_strcmp0(property, "failure") == 0 || g_strcmp0(property, "disconnect") == 0 || g_strcmp0(property, "idle") == 0) {
232 if (netconfig_get_default_profile() == NULL)
235 if (netconfig_is_cellular_profile(path) && netconfig_is_cellular_internet_profile(path))
236 cellular_state_set_service_state(NETCONFIG_CELLULAR_IDLE);
238 if (g_strcmp0(path, netconfig_get_default_profile()) != 0)
241 netconfig_update_default_profile(NULL);
242 } else if (g_strcmp0(property, "association") == 0 || g_strcmp0(property, "configuration") == 0) {
243 if (netconfig_get_default_profile() == NULL)
246 if (netconfig_is_cellular_profile(path) && netconfig_is_cellular_internet_profile(path))
247 cellular_state_set_service_state(NETCONFIG_CELLULAR_CONNECTING);
249 if (g_strcmp0(path, netconfig_get_default_profile()) != 0)
252 netconfig_update_default_profile(NULL);
255 } else if (g_strcmp0(sigvalue, "Proxy") == 0) {
256 if (netconfig_is_wifi_profile(path) != TRUE || g_strcmp0(path, netconfig_get_default_profile()) != 0)
259 if (!g_variant_type_equal(variant, G_VARIANT_TYPE_ARRAY))
262 g_variant_get(variant, "a{sv}", &iter);
263 while (g_variant_iter_loop(iter, "{sv}", &property, &var)) {
264 if (g_strcmp0(property, "Servers") == 0) {
265 GVariantIter *iter_sub = NULL;
267 g_variant_get(var, "as", &iter_sub);
268 g_variant_iter_loop(iter_sub, "s", &value);
269 g_variant_iter_free(iter_sub);
271 DBG("Proxy - [%s]", value);
272 vconf_set_str(VCONFKEY_NETWORK_PROXY, value);
275 g_variant_unref(var);
277 } else if (g_strcmp0(property, "Method") == 0) {
278 value = g_variant_get_string(var, NULL);
279 DBG("Method - [%s]", value);
281 if (g_strcmp0(value, "direct") == 0)
282 vconf_set_str(VCONFKEY_NETWORK_PROXY, "");
285 g_variant_unref(var);
290 g_variant_iter_free(iter);
291 } else if (g_strcmp0(sigvalue, "Error") == 0) {
292 g_variant_get(variant, "s", &property);
293 INFO("[%s] Property : %s", sigvalue, property);
300 g_variant_unref(variant);
305 static void _dbus_name_changed_cb(GDBusConnection *conn,
306 const gchar *Name, const gchar *path, const gchar *interface,
307 const gchar *sig, GVariant *param, gpointer user_data)
316 g_variant_get(param, "(sss)", &name, &old, &new);
318 if (g_strcmp0(name, CONNMAN_SERVICE) == 0 && *new == '\0') {
319 DBG("ConnMan destroyed: name %s, old %s, new %s", name, old, new);
321 connman_register_agent();
333 static void _services_changed_cb(GDBusConnection *conn, const gchar *name,
334 const gchar *path, const gchar *interface, const gchar *sig,
335 GVariant *param, gpointer user_data)
337 gchar *property, *value;
339 GVariant *variant = NULL;
340 GVariantIter *added = NULL, *removed = NULL, *next = NULL;
342 if (path == NULL || param == NULL)
345 if (g_strcmp0(sig, CONNMAN_SIGNAL_SERVICES_CHANGED) != 0)
348 if (netconfig_get_default_profile() != NULL)
351 g_variant_get(param, "(a(oa{sv})ao)", &added, &removed);
353 while (g_variant_iter_loop(added, "(oa{sv})", &service_path, &next)) {
354 gboolean is_wifi_prof, is_cell_prof, is_cell_internet_prof;
355 is_wifi_prof = netconfig_is_wifi_profile(service_path);
356 is_cell_prof = netconfig_is_cellular_profile(service_path);
357 is_cell_internet_prof = netconfig_is_cellular_internet_profile(
359 if (service_path != NULL) {
360 while (g_variant_iter_loop(next, "{sv}", &property,
362 if (g_strcmp0(property, "State") == 0) {
363 g_variant_get(variant, "s", &value);
364 DBG("Profile %s State %s", service_path,
366 if (g_strcmp0(value, "ready") != 0 &&
370 g_variant_unref(variant);
375 netconfig_update_default_profile(
377 else if (is_cell_internet_prof) {
378 netconfig_update_default_profile(
382 wifi_state_set_service_state(
383 NETCONFIG_WIFI_CONNECTED);
384 else if (is_cell_prof &&
385 is_cell_internet_prof)
386 cellular_state_set_service_state(
387 NETCONFIG_CELLULAR_ONLINE);
389 g_variant_unref(variant);
396 g_variant_iter_free(next);
398 g_variant_iter_free(added);
400 g_variant_iter_free(removed);
404 static void _supplicant_interface_removed(GDBusConnection *conn,
405 const gchar *name, const gchar *path, const gchar *interface,
406 const gchar *sig, GVariant *param, gpointer user_data)
408 DBG("Interface removed handling!");
409 if (netconfig_wifi_is_wps_enabled() == TRUE)
410 netconfig_wifi_wps_signal_scanaborted();
415 static void _supplicant_properties_changed(GDBusConnection *conn,
416 const gchar *name, const gchar *path, const gchar *interface,
417 const gchar *sig, GVariant *param, gpointer user_data)
419 DBG("Properties changed handling!");
423 gboolean scanning = FALSE;
428 g_variant_get(param, "(a{sv})", &iter);
429 while (g_variant_iter_loop(iter, "{sv}", &key, &variant)) {
430 if (g_strcmp0(key, "Scanning") == 0) {
431 scanning = g_variant_get_boolean(variant);
432 if (scanning == TRUE)
433 netconfig_wifi_set_scanning(TRUE);
435 g_variant_unref(variant);
441 g_variant_iter_free(iter);
446 static void _supplicant_bss_added(GDBusConnection *conn,
447 const gchar *name, const gchar *path, const gchar *interface,
448 const gchar *sig, GVariant *param, gpointer user_data)
450 DBG("BSS added handling!");
451 if (wifi_ssid_scan_get_state() == TRUE)
452 wifi_ssid_scan_add_bss(param);
454 wifi_state_set_bss_found(TRUE);
459 static void _supplicant_scan_done(GDBusConnection *conn,
460 const gchar *name, const gchar *path, const gchar *interface,
461 const gchar *sig, GVariant *param, gpointer user_data)
463 DBG("Scan Done handling!");
464 netconfig_wifi_set_scanning(FALSE);
466 if (netconfig_wifi_is_wps_enabled() == TRUE) {
467 netconfig_wifi_wps_signal_scandone();
468 if (wifi_state_get_technology_state() < NETCONFIG_WIFI_TECH_POWERED)
472 if (netconfig_wifi_get_bgscan_state() != TRUE) {
473 if (wifi_ssid_scan_get_state() == TRUE)
474 wifi_ssid_scan_emit_scan_completed();
476 wifi_ssid_scan(NULL);
478 if (wifi_state_get_technology_state() >=
479 NETCONFIG_WIFI_TECH_POWERED)
480 netconfig_wifi_bgscan_start(FALSE);
482 wifi_start_timer_network_notification();
488 static void _supplicant_driver_hanged(GDBusConnection *conn,
489 const gchar *name, const gchar *path, const gchar *interface,
490 const gchar *sig, GVariant *param, gpointer user_data)
492 DBG("Driver Hanged handling!");
493 ERR("Critical. Wi-Fi firmware crashed");
495 wifi_power_recover_firmware();
500 static void _supplicant_session_overlapped(GDBusConnection *conn,
501 const gchar *name, const gchar *path, const gchar *interface,
502 const gchar *sig, GVariant *param, gpointer user_data)
504 DBG("Driver session overlapped handling!");
505 ERR("WPS PBC SESSION OVERLAPPED");
506 #if defined TIZEN_WEARABLE
507 wc_launch_syspopup(WC_POPUP_TYPE_SESSION_OVERLAPPED);
509 netconfig_send_message_to_net_popup("WPS Error",
510 "wps session overlapped", "popup", NULL);
514 static void _supplicant_tdls_connected(GDBusConnection *conn,
515 const gchar *name, const gchar *path, const gchar *interface,
516 const gchar *sig, GVariant *param, gpointer user_data)
518 ERR("Received TDLS Connected Signal");
519 netconfig_wifi_tlds_connected_event(param);
524 static void _supplicant_tdls_disconnected(GDBusConnection *conn,
525 const gchar *name, const gchar *path, const gchar *interface,
526 const gchar *sig, GVariant *param, gpointer user_data)
528 ERR("Received TDLS Disconnected Signal");
529 netconfig_wifi_tlds_disconnected_event(param);
534 static void _supplicant_tdls_peer_found(GDBusConnection *conn,
535 const gchar *name, const gchar *path, const gchar *interface,
536 const gchar *sig, GVariant *param, gpointer user_data)
538 ERR("Received TDLS Peer Found Signal");
542 static supplicant_signal_cb supplicant_cbs[SIG_MAX] = {
543 _supplicant_interface_removed,
544 _supplicant_properties_changed,
545 _supplicant_bss_added,
546 _supplicant_scan_done,
547 _supplicant_driver_hanged,
548 _supplicant_session_overlapped,
549 _supplicant_tdls_connected,
550 _supplicant_tdls_disconnected,
551 _supplicant_tdls_peer_found
554 #if defined TIZEN_DEBUG_DISABLE
555 static void __netconfig_dumpservice_handler(GDBusConnection *conn,
556 const gchar *name, const gchar *path, const gchar *interface,
557 const gchar *sig, GVariant *param, gpointer user_data)
560 gchar *signal_path = NULL;
565 g_variant_get(param, "(io)", &mode, &signal_path);
566 DBG("Path: %s and mode: %d", signal_path, mode);
567 netconfig_dump_log(path);
575 void register_gdbus_signal(void)
577 GDBusConnection *connection = NULL;
578 const char *interface = NULL;
579 SuppSigArrayIndex sig;
580 connection = netdbus_get_connection();
582 if (connection == NULL) {
583 ERR("Failed to get GDbus Connection");
587 /* listening to messages from all objects as no path is specified */
588 /* see signals from the given interface */
589 conn_subscription_ids[0] = g_dbus_connection_signal_subscribe(
592 CONNMAN_TECHNOLOGY_INTERFACE,
596 G_DBUS_SIGNAL_FLAGS_NONE,
597 _technology_signal_cb,
601 conn_subscription_ids[1] = g_dbus_connection_signal_subscribe(
604 CONNMAN_SERVICE_INTERFACE,
605 CONNMAN_SIGNAL_PROPERTY_CHANGED,
608 G_DBUS_SIGNAL_FLAGS_NONE,
613 conn_subscription_ids[2] = g_dbus_connection_signal_subscribe(
617 CONNMAN_SIGNAL_NAME_CHANGED,
620 G_DBUS_SIGNAL_FLAGS_NONE,
621 _dbus_name_changed_cb,
625 conn_subscription_ids[3] = g_dbus_connection_signal_subscribe(
628 CONNMAN_MANAGER_INTERFACE,
629 CONNMAN_SIGNAL_SERVICES_CHANGED,
632 G_DBUS_SIGNAL_FLAGS_NONE,
633 _services_changed_cb,
637 INFO("Successfully register connman DBus signal filters");
639 for (sig = SIG_INTERFACE_REMOVED; sig < SIG_MAX; sig++) {
641 * For SIG_INTERFACE_REMOVED INTERFACE_ADDED
643 interface = (sig == SIG_INTERFACE_REMOVED) ?
644 SUPPLICANT_INTERFACE : SUPPLICANT_IFACE_INTERFACE;
646 supp_subscription_ids[sig] = g_dbus_connection_signal_subscribe(
650 supplicant_signals[sig],
653 G_DBUS_SIGNAL_FLAGS_NONE,
659 INFO("Successfully register Supplicant DBus signal filters");
661 #if defined TIZEN_DEBUG_DISABLE
662 dumpservice_subscription_id = g_dbus_connection_signal_subscribe(
665 * Sender => For testing purpose made NULL
669 DUMP_SERVICE_INTERFACE,
673 G_DBUS_SIGNAL_FLAGS_NONE,
674 __netconfig_dumpservice_handler,
678 INFO("Successfully register Dumpservice DBus signal filter");
680 /* In case ConnMan precedes this signal register,
681 * net-config should update the default connected profile.
683 netconfig_update_default();
686 void deregister_gdbus_signal(void)
688 GDBusConnection *connection = NULL;
690 SuppSigArrayIndex sig;
691 connection = netdbus_get_connection();
693 ERR("Already de-registered. Nothing to be done");
697 for (signal = 0; signal < TOTAL_CONN_SIGNALS; signal++) {
698 if (conn_subscription_ids[signal]) {
699 g_dbus_connection_signal_unsubscribe(connection,
700 conn_subscription_ids[signal]);
704 for (sig = SIG_INTERFACE_REMOVED; sig < SIG_MAX; sig++) {
705 if (supp_subscription_ids[sig]) {
706 g_dbus_connection_signal_unsubscribe(connection,
707 supp_subscription_ids[sig]);
711 g_dbus_connection_signal_unsubscribe(connection,
712 dumpservice_subscription_id);