4c7ec98ea9ca3ee785b7543b5530b6f47fe5d148
[platform/core/connectivity/net-config.git] / src / signal-handler.c
1 /*
2  * Network Configuration Module
3  *
4  * Copyright (c) 2000 - 2012 Samsung Electronics Co., Ltd. All rights reserved.
5  *
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
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
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.
17  *
18  */
19
20 #include <stdio.h>
21 #include <string.h>
22 #include <vconf.h>
23 #include <vconf-keys.h>
24
25 #include "log.h"
26 #include "util.h"
27 #include "netdbus.h"
28 #include "neterror.h"
29 #include "wifi-wps.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"
40
41 #if defined TIZEN_DEBUG_DISABLE
42 #include "wifi-dump.h"
43 #endif
44
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"
59
60 #define MAX_SIG_LEN 64
61 #define TOTAL_CONN_SIGNALS 4
62
63 typedef enum {
64         SIG_INTERFACE_REMOVED = 0,
65         SIG_PROPERTIES_CHANGED,
66         SIG_BSS_ADDED,
67         SIG_SCAN_DONE,
68         SIG_DRIVER_HANGED,
69         SIG_SESSION_OVERLAPPED,
70         SIG_TDLS_CONNECTED,
71         SIG_TDLS_DISCONNECTED,
72         SIG_TDLS_PEER_FOUND,
73         SIG_MAX
74 } SuppSigArrayIndex;
75
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,
80                 SIGNAL_BSS_ADDED,
81                 SIGNAL_SCAN_DONE,
82                 SIGNAL_PROPERTIES_DRIVER_HANGED,
83                 SIGNAL_PROPERTIES_SESSION_OVERLAPPED,
84                 SIGNAL_TDLS_CONNECTED,
85                 SIGNAL_TDLS_DISCONNECTED,
86                 SIGNAL_TDLS_PEER_FOUND,
87 };
88
89 static int supp_subscription_ids[SIG_MAX] = {0};
90 static int dumpservice_subscription_id = 0;
91
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);
98
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)
102 {
103         gchar *key = NULL;
104         gboolean value = FALSE;
105         GVariant *var = NULL;
106
107         if (param == NULL)
108                 return;
109
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) {
113                         /* Power state */
114                         value = g_variant_get_boolean(var);
115                         if (value == TRUE) {
116                                 wifi_state_update_power_state(TRUE);
117                         } else {
118                                 wifi_state_update_power_state(FALSE);
119                         }
120                 } else if (g_strcmp0(key, "Connected") == 0) {
121                         /* Connection state */
122                         value = g_variant_get_boolean(var);
123                         if (value == TRUE) {
124                                 wifi_state_set_tech_state(NETCONFIG_WIFI_TECH_CONNECTED);
125                         } else {
126                                 wifi_state_set_tech_state(NETCONFIG_WIFI_TECH_POWERED);
127                         }
128                 } else if (g_strcmp0(key, "Tethering") == 0) {
129                         /* Tethering state */
130                         wifi_state_set_tech_state(NETCONFIG_WIFI_TECH_TETHERED);
131                 }
132                 if (key)
133                         g_free(key);
134                 if (var)
135                         g_variant_unref(var);
136         }
137 }
138
139 static void _service_signal_cb(GDBusConnection *conn,
140                 const gchar *name, const gchar *path,
141                 const gchar *interface, const gchar *sig, GVariant *param, gpointer user_data)
142 {
143         gchar *sigvalue = NULL;
144         gchar *property;
145         GVariant *variant = NULL, *var;
146         GVariantIter *iter;
147         const gchar *value = NULL;
148
149         if (path == NULL || param == NULL)
150                 goto done;
151
152         g_variant_get(param, "(sv)", &sigvalue, &variant);
153         if (sigvalue == NULL)
154                 goto done;
155
156         if (g_strcmp0(sig, CONNMAN_SIGNAL_PROPERTY_CHANGED) != 0) {
157                 goto done;
158         }
159
160         if (g_strcmp0(sigvalue, "State") == 0) {
161                 g_variant_get(variant, "s", &property);
162
163                 DBG("[%s] %s", property, path);
164                 if (netconfig_is_wifi_profile(path) == TRUE) {
165                         int wifi_state = 0;
166
167                         vconf_get_int(VCONFKEY_WIFI_STATE, &wifi_state);
168                         if (wifi_state == VCONFKEY_WIFI_OFF)
169                                 goto done;
170
171                         if (g_strcmp0(property, "ready") == 0 || g_strcmp0(property, "online") == 0) {
172                                 if (wifi_state >= VCONFKEY_WIFI_CONNECTED)
173                                         goto done;
174
175                                 netconfig_update_default_profile(path);
176
177                                 wifi_state_set_service_state(NETCONFIG_WIFI_CONNECTED);
178
179                         } else if (g_strcmp0(property, "failure") == 0 || g_strcmp0(property, "disconnect") == 0 || g_strcmp0(property, "idle") == 0) {
180                                 if (netconfig_get_default_profile() == NULL ||
181                                                 netconfig_is_wifi_profile(netconfig_get_default_profile())
182                                                 != TRUE) {
183                                         if (g_strcmp0(property, "failure") == 0)
184                                                 wifi_state_set_service_state(NETCONFIG_WIFI_FAILURE);
185                                         else
186                                                 wifi_state_set_service_state(NETCONFIG_WIFI_IDLE);
187                                         goto done;
188                                 }
189
190                                 if (g_strcmp0(path, netconfig_get_default_profile()) != 0)
191                                         goto done;
192
193                                 netconfig_update_default_profile(NULL);
194
195                                 if (g_strcmp0(property, "failure") == 0)
196                                         wifi_state_set_service_state(NETCONFIG_WIFI_FAILURE);
197                                 else
198                                         wifi_state_set_service_state(NETCONFIG_WIFI_IDLE);
199
200                         } else if (g_strcmp0(property, "association") == 0 || g_strcmp0(property, "configuration") == 0) {
201                                 if (netconfig_get_default_profile() == NULL ||
202                                                 netconfig_is_wifi_profile(netconfig_get_default_profile()) != TRUE) {
203                                         if (g_strcmp0(property, "association") == 0)
204                                                 wifi_state_set_service_state(NETCONFIG_WIFI_ASSOCIATION);
205                                         else
206                                                 wifi_state_set_service_state(NETCONFIG_WIFI_CONFIGURATION);
207                                         goto done;
208                                 }
209
210                                 if (g_strcmp0(path, netconfig_get_default_profile()) != 0)
211                                         goto done;
212
213                                 netconfig_update_default_profile(NULL);
214
215                                 if (g_strcmp0(property, "association") == 0)
216                                         wifi_state_set_service_state(NETCONFIG_WIFI_ASSOCIATION);
217                                 else
218                                         wifi_state_set_service_state(NETCONFIG_WIFI_CONFIGURATION);
219
220                         }
221                 } else {
222                         if (g_strcmp0(property, "ready") == 0 || g_strcmp0(property, "online") == 0) {
223                                 if (netconfig_get_default_profile() == NULL) {
224                                         if(!netconfig_is_cellular_profile(path)) {
225                                                 netconfig_update_default_profile(path);
226                                         } else {
227                                                 if (netconfig_is_cellular_internet_profile(path)) {
228                                                         netconfig_update_default_profile(path);
229                                                 }
230                                         }
231                                 }
232
233                                 if (netconfig_is_cellular_profile(path) && netconfig_is_cellular_internet_profile(path))
234                                         cellular_state_set_service_state(NETCONFIG_CELLULAR_ONLINE);
235
236                         } else if (g_strcmp0(property, "failure") == 0 || g_strcmp0(property, "disconnect") == 0 || g_strcmp0(property, "idle") == 0) {
237                                 if (netconfig_get_default_profile() == NULL)
238                                         goto done;
239
240                                 if (netconfig_is_cellular_profile(path) && netconfig_is_cellular_internet_profile(path))
241                                         cellular_state_set_service_state(NETCONFIG_CELLULAR_IDLE);
242
243                                 if (g_strcmp0(path, netconfig_get_default_profile()) != 0)
244                                         goto done;
245
246                                 netconfig_update_default_profile(NULL);
247                         } else if (g_strcmp0(property, "association") == 0 ||   g_strcmp0(property, "configuration") == 0) {
248                                 if (netconfig_get_default_profile() == NULL)
249                                         goto done;
250
251                                 if (netconfig_is_cellular_profile(path) && netconfig_is_cellular_internet_profile(path))
252                                         cellular_state_set_service_state(NETCONFIG_CELLULAR_CONNECTING);
253
254                                 if (g_strcmp0(path, netconfig_get_default_profile()) != 0)
255                                         goto done;
256
257                                 netconfig_update_default_profile(NULL);
258                         }
259                 }
260         } else if (g_strcmp0(sigvalue, "Proxy") == 0) {
261                 if (netconfig_is_wifi_profile(path) != TRUE || g_strcmp0(path, netconfig_get_default_profile()) != 0)
262                         goto done;
263
264                 if (!g_variant_type_equal(variant, G_VARIANT_TYPE_ARRAY))
265                         goto done;
266
267                 g_variant_get(variant, "a{sv}", &iter);
268                 while (g_variant_iter_loop(iter, "{sv}", &property, &var)) {
269                         if (g_strcmp0(property, "Servers") == 0) {
270                                 GVariantIter *iter_sub = NULL;
271
272                                 g_variant_get(var, "as", &iter_sub);
273                                 g_variant_iter_loop(iter_sub, "s", &value);
274                                 g_variant_iter_free(iter_sub);
275
276                                 DBG("Proxy - [%s]", value);
277                                 vconf_set_str(VCONFKEY_NETWORK_PROXY, value);
278
279                                 g_free(property);
280                                 g_variant_unref(var);
281                                 break;
282                         } else if (g_strcmp0(property, "Method") == 0) {
283                                 value = g_variant_get_string(var, NULL);
284                                 DBG("Method - [%s]", value);
285
286                                 if (g_strcmp0(value, "direct") == 0)
287                                         vconf_set_str(VCONFKEY_NETWORK_PROXY, "");
288
289                                 g_free(property);
290                                 g_variant_unref(var);
291                                 break;
292                         }
293                 }
294
295                 g_variant_iter_free(iter);
296         } else if (g_strcmp0(sigvalue, "Error") == 0) {
297                 g_variant_get(variant, "s", &property);
298                 INFO("[%s] Property : %s", sigvalue, property);
299         }
300 done:
301         if (sigvalue)
302                 g_free(sigvalue);
303
304         if (variant)
305                 g_variant_unref(variant);
306
307         return;
308 }
309
310 static void _dbus_name_changed_cb(GDBusConnection *conn,
311                 const gchar *Name, const gchar *path, const gchar *interface,
312                 const gchar *sig, GVariant *param, gpointer user_data)
313 {
314         gchar *name = NULL;
315         gchar *old = NULL;
316         gchar *new = NULL;
317
318         if (param == NULL)
319                 return;
320
321         g_variant_get(param, "(sss)", &name, &old, &new);
322
323         if (g_strcmp0(name, CONNMAN_SERVICE) == 0 && *new == '\0') {
324                 DBG("ConnMan destroyed: name %s, old %s, new %s", name, old, new);
325
326                 connman_register_agent();
327         }
328         if (name)
329                 g_free(name);
330         if (old)
331                 g_free(old);
332         if (new)
333                 g_free(new);
334
335         return;
336 }
337
338 static void _services_changed_cb(GDBusConnection *conn, const gchar *name,
339                 const gchar *path, const gchar *interface, const gchar *sig,
340                 GVariant *param, gpointer user_data)
341 {
342         gchar *property, *value;
343         gchar *service_path;
344         GVariant *variant = NULL;
345         GVariantIter *added = NULL, *removed = NULL, *next = NULL;
346
347         if (path == NULL || param == NULL)
348                 return;
349
350         if (g_strcmp0(sig, CONNMAN_SIGNAL_SERVICES_CHANGED) != 0)
351                 return;
352
353         if (netconfig_get_default_profile() != NULL)
354                 return;
355
356         g_variant_get(param, "(a(oa{sv})ao)", &added, &removed);
357
358         while (g_variant_iter_loop(added, "(oa{sv})", &service_path, &next)) {
359                 gboolean is_wifi_prof, is_cell_prof, is_cell_internet_prof;
360                 is_wifi_prof = netconfig_is_wifi_profile(service_path);
361                 is_cell_prof = netconfig_is_cellular_profile(service_path);
362                 is_cell_internet_prof = netconfig_is_cellular_internet_profile(
363                                 service_path);
364                 if (service_path != NULL) {
365                         while (g_variant_iter_loop(next, "{sv}", &property,
366                                                 &variant)) {
367                                 if (g_strcmp0(property, "State") == 0) {
368                                         g_variant_get(variant, "s", &value);
369                                         DBG("Profile %s State %s", service_path,
370                                                         value);
371                                         if (g_strcmp0(value, "ready") != 0 &&
372                                                         g_strcmp0(value,
373                                                                 "online") != 0) {
374                                                 g_free(property);
375                                                 g_variant_unref(variant);
376                                                 break;
377                                         }
378
379                                         if(!is_cell_prof)
380                                                 netconfig_update_default_profile(
381                                                                 service_path);
382                                         else if (is_cell_internet_prof) {
383                                                 netconfig_update_default_profile(
384                                                                 service_path);
385                                         }
386                                         if (is_wifi_prof)
387                                                 wifi_state_set_service_state(
388                                                         NETCONFIG_WIFI_CONNECTED);
389                                         else if (is_cell_prof &&
390                                                         is_cell_internet_prof)
391                                                 cellular_state_set_service_state(
392                                                         NETCONFIG_CELLULAR_ONLINE);
393                                         g_free(property);
394                                         g_variant_unref(variant);
395                                         break;
396                                 }
397                         }
398                 }
399         }
400         if (next)
401                 g_variant_iter_free(next);
402         if (added)
403                 g_variant_iter_free(added);
404         if (removed)
405                 g_variant_iter_free(removed);
406         return;
407 }
408
409 static void _supplicant_interface_removed(GDBusConnection *conn,
410                 const gchar *name, const gchar *path, const gchar *interface,
411                 const gchar *sig, GVariant *param, gpointer user_data)
412 {
413         DBG("Interface removed handling!");
414         if (netconfig_wifi_is_wps_enabled() == TRUE)
415                 netconfig_wifi_wps_signal_scanaborted();
416
417         return;
418 }
419
420 static void _supplicant_properties_changed(GDBusConnection *conn,
421                 const gchar *name, const gchar *path, const gchar *interface,
422                 const gchar *sig, GVariant *param, gpointer user_data)
423 {
424         DBG("Properties changed handling!");
425         gchar *key;
426         GVariantIter *iter;
427         GVariant *variant;
428         gboolean scanning = FALSE;
429
430         if (param == NULL)
431                 return;
432
433         g_variant_get(param, "(a{sv})", &iter);
434         while (g_variant_iter_loop(iter, "{sv}", &key, &variant)) {
435                 if (g_strcmp0(key, "Scanning") == 0) {
436                         scanning = g_variant_get_boolean(variant);
437                         if (scanning == TRUE)
438                                 netconfig_wifi_set_scanning(TRUE);
439
440                         g_variant_unref(variant);
441                         g_free(key);
442                         break;
443                 }
444         }
445
446         g_variant_iter_free(iter);
447
448         return;
449 }
450
451 static void _supplicant_bss_added(GDBusConnection *conn,
452                 const gchar *name, const gchar *path, const gchar *interface,
453                 const gchar *sig, GVariant *param, gpointer user_data)
454 {
455         DBG("BSS added handling!");
456         if (wifi_ssid_scan_get_state() == TRUE)
457                 wifi_ssid_scan_add_bss(param);
458         else
459                 wifi_state_set_bss_found(TRUE);
460
461         return;
462 }
463
464 static void _supplicant_scan_done(GDBusConnection *conn,
465                 const gchar *name, const gchar *path, const gchar *interface,
466                 const gchar *sig, GVariant *param, gpointer user_data)
467 {
468         DBG("Scan Done handling!");
469         netconfig_wifi_set_scanning(FALSE);
470
471         if (netconfig_wifi_is_wps_enabled() == TRUE) {
472                 netconfig_wifi_wps_signal_scandone();
473                 if (wifi_state_get_technology_state() < NETCONFIG_WIFI_TECH_POWERED)
474                         return;
475         }
476
477         if (netconfig_wifi_get_bgscan_state() != TRUE) {
478                 if (wifi_ssid_scan_get_state() == TRUE)
479                         wifi_ssid_scan_emit_scan_completed();
480                 else
481                         wifi_ssid_scan(NULL);
482         } else {
483                 if (wifi_state_get_technology_state() >=
484                                 NETCONFIG_WIFI_TECH_POWERED)
485                         netconfig_wifi_bgscan_start(FALSE);
486
487                 wifi_start_timer_network_notification();
488         }
489
490         return;
491 }
492
493 static void _supplicant_driver_hanged(GDBusConnection *conn,
494                 const gchar *name, const gchar *path, const gchar *interface,
495                 const gchar *sig, GVariant *param, gpointer user_data)
496 {
497         DBG("Driver Hanged handling!");
498         ERR("Critical. Wi-Fi firmware crashed");
499
500         wifi_power_recover_firmware();
501
502         return;
503 }
504
505 static void _supplicant_session_overlapped(GDBusConnection *conn,
506                 const gchar *name, const gchar *path, const gchar *interface,
507                 const gchar *sig, GVariant *param, gpointer user_data)
508 {
509         DBG("Driver session overlapped handling!");
510         ERR("WPS PBC SESSION OVERLAPPED");
511 #if defined TIZEN_WEARABLE
512         wc_launch_syspopup(WC_POPUP_TYPE_SESSION_OVERLAPPED);
513 #else
514         netconfig_send_message_to_net_popup("WPS Error",
515                                         "wps session overlapped", "popup", NULL);
516 #endif
517 }
518
519 static void _supplicant_tdls_connected(GDBusConnection *conn,
520                 const gchar *name, const gchar *path, const gchar *interface,
521                 const gchar *sig, GVariant *param, gpointer user_data)
522 {
523         ERR("Received TDLS Connected Signal");
524         netconfig_wifi_tlds_connected_event(param);
525
526         return;
527 }
528
529 static void _supplicant_tdls_disconnected(GDBusConnection *conn,
530                 const gchar *name, const gchar *path, const gchar *interface,
531                 const gchar *sig, GVariant *param, gpointer user_data)
532 {
533         ERR("Received TDLS Disconnected Signal");
534         netconfig_wifi_tlds_disconnected_event(param);
535
536         return;
537 }
538
539 static void _supplicant_tdls_peer_found(GDBusConnection *conn,
540                 const gchar *name, const gchar *path, const gchar *interface,
541                 const gchar *sig, GVariant *param, gpointer user_data)
542 {
543         ERR("Received TDLS Peer Found Signal");
544         return;
545 }
546
547 static supplicant_signal_cb supplicant_cbs[SIG_MAX] = {
548                 _supplicant_interface_removed,
549                 _supplicant_properties_changed,
550                 _supplicant_bss_added,
551                 _supplicant_scan_done,
552                 _supplicant_driver_hanged,
553                 _supplicant_session_overlapped,
554                 _supplicant_tdls_connected,
555                 _supplicant_tdls_disconnected,
556                 _supplicant_tdls_peer_found
557 };
558
559 #if defined TIZEN_DEBUG_DISABLE
560 static void __netconfig_dumpservice_handler(GDBusConnection *conn,
561                 const gchar *name, const gchar *path, const gchar *interface,
562                 const gchar *sig, GVariant *param, gpointer user_data)
563 {
564         int mode;
565         gchar *signal_path = NULL;
566
567         if (param == NULL)
568                 return;
569
570         g_variant_get(param, "(io)", &mode, &signal_path);
571         DBG("Path: %s and mode: %d", signal_path, mode);
572         netconfig_dump_log(path);
573         if (signal_path)
574                 g_free(signal_path);
575
576         return;
577 }
578 #endif
579
580 void register_gdbus_signal(void)
581 {
582         GDBusConnection *connection = NULL;
583         const char *interface = NULL;
584         SuppSigArrayIndex sig;
585         connection = netdbus_get_connection();
586
587         if (connection == NULL) {
588                 ERR("Failed to get GDbus Connection");
589                 return;
590         }
591
592         /* listening to messages from all objects as no path is specified */
593         /* see signals from the given interface */
594         conn_subscription_ids[0] = g_dbus_connection_signal_subscribe(
595                         connection,
596                         CONNMAN_SERVICE,
597                         CONNMAN_TECHNOLOGY_INTERFACE,
598                         NULL,
599                         NULL,
600                         NULL,
601                         G_DBUS_SIGNAL_FLAGS_NONE,
602                         _technology_signal_cb,
603                         NULL,
604                         NULL);
605
606         conn_subscription_ids[1] = g_dbus_connection_signal_subscribe(
607                         connection,
608                         CONNMAN_SERVICE,
609                         CONNMAN_SERVICE_INTERFACE,
610                         CONNMAN_SIGNAL_PROPERTY_CHANGED,
611                         NULL,
612                         NULL,
613                         G_DBUS_SIGNAL_FLAGS_NONE,
614                         _service_signal_cb,
615                         NULL,
616                         NULL);
617
618         conn_subscription_ids[2] = g_dbus_connection_signal_subscribe(
619                         connection,
620                         DBUS_SERVICE_DBUS,
621                         DBUS_INTERFACE_DBUS,
622                         CONNMAN_SIGNAL_NAME_CHANGED,
623                         NULL,
624                         CONNMAN_SERVICE,
625                         G_DBUS_SIGNAL_FLAGS_NONE,
626                         _dbus_name_changed_cb,
627                         NULL,
628                         NULL);
629
630         conn_subscription_ids[3] = g_dbus_connection_signal_subscribe(
631                         connection,
632                         CONNMAN_SERVICE,
633                         CONNMAN_MANAGER_INTERFACE,
634                         CONNMAN_SIGNAL_SERVICES_CHANGED,
635                         NULL,
636                         NULL,
637                         G_DBUS_SIGNAL_FLAGS_NONE,
638                         _services_changed_cb,
639                         NULL,
640                         NULL);
641
642         INFO("Successfully register connman DBus signal filters");
643
644         for (sig = SIG_INTERFACE_REMOVED; sig < SIG_MAX; sig++) {
645                 /*
646                  * For SIG_INTERFACE_REMOVED INTERFACE_ADDED
647                  */
648                 interface = (sig == SIG_INTERFACE_REMOVED) ?
649                                 SUPPLICANT_INTERFACE : SUPPLICANT_IFACE_INTERFACE;
650
651                 supp_subscription_ids[sig] = g_dbus_connection_signal_subscribe(
652                                 connection,
653                                 SUPPLICANT_SERVICE,
654                                 interface,
655                                 supplicant_signals[sig],
656                                 NULL,
657                                 NULL,
658                                 G_DBUS_SIGNAL_FLAGS_NONE,
659                                 supplicant_cbs[sig],
660                                 NULL,
661                                 NULL);
662         }
663
664         INFO("Successfully register Supplicant DBus signal filters");
665
666 #if defined TIZEN_DEBUG_DISABLE
667         dumpservice_subscription_id = g_dbus_connection_signal_subscribe(
668                         connection,
669                         /*
670                          * Sender => For testing purpose made NULL
671                          *WPA_SUPPLICANT,
672                          */
673                         NULL,
674                         DUMP_SERVICE_INTERFACE,
675                         DUMP_SIGNAL,
676                         NULL,
677                         NULL,
678                         G_DBUS_SIGNAL_FLAGS_NONE,
679                         __netconfig_dumpservice_handler,
680                         NULL,
681                         NULL);
682
683         INFO("Successfully register Dumpservice DBus signal filter");
684 #endif
685         /* In case ConnMan precedes this signal register,
686          * net-config should update the default connected profile.
687          */
688         netconfig_update_default();
689 }
690
691 void deregister_gdbus_signal(void)
692 {
693         GDBusConnection *connection = NULL;
694         int signal;
695         SuppSigArrayIndex sig;
696         connection = netdbus_get_connection();
697         if (!connection) {
698                 ERR("Already de-registered. Nothing to be done");
699                 return;
700         }
701
702         for (signal = 0; signal < TOTAL_CONN_SIGNALS; signal++) {
703                 if (conn_subscription_ids[signal]) {
704                         g_dbus_connection_signal_unsubscribe(connection,
705                                                 conn_subscription_ids[signal]);
706                 }
707         }
708
709         for (sig = SIG_INTERFACE_REMOVED; sig < SIG_MAX; sig++) {
710                 if (supp_subscription_ids[sig]) {
711                         g_dbus_connection_signal_unsubscribe(connection,
712                                                 supp_subscription_ids[sig]);
713                 }
714         }
715
716         g_dbus_connection_signal_unsubscribe(connection,
717                         dumpservice_subscription_id);
718 }