Added NameOwnerChanged signal handling for clatd service.
[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 <stdlib.h>
22 #include <string.h>
23 #include <vconf.h>
24 #include <vconf-keys.h>
25 #include <sys/wait.h>
26
27 #include "log.h"
28 #include "util.h"
29 #include "netdbus.h"
30 #include "neterror.h"
31 #include "wifi-wps.h"
32 #include "wifi-bssid-scan.h"
33 #include "wifi-agent.h"
34 #include "wifi-power.h"
35 #include "wifi-state.h"
36 #include "netsupplicant.h"
37 #include "network-state.h"
38 #include "cellular-state.h"
39 #include "signal-handler.h"
40 #include "wifi-background-scan.h"
41 #include "wifi-tdls.h"
42 #include "ip-conflict-detect.h"
43 #include "wifi-key-encryption.h"
44 #include "clatd-handler.h"
45 #if defined TIZEN_DEBUG_ENABLE
46 #include "network-dump.h"
47 #define NETWORK_LOG_DUMP_SCRIPT  "/opt/var/lib/net-config/network_log_dump.sh"
48 #define MAX_SIZE_ERROR_BUFFER 256
49 #endif
50
51 #define DBUS_SERVICE_DBUS                       "org.freedesktop.DBus"
52 #define DBUS_INTERFACE_DBUS                     "org.freedesktop.DBus"
53 #define SIGNAL_INTERFACE_REMOVED                "InterfaceRemoved"
54 #define SIGNAL_SCAN_DONE                        "ScanDone"
55 #define SIGNAL_BSS_ADDED                        "BSSAdded"
56 #define SIGNAL_PROPERTIES_CHANGED               "PropertiesChanged"
57 #define SIGNAL_PROPERTIES_DRIVER_HANGED         "DriverHanged"
58 #define SIGNAL_PROPERTIES_SESSION_OVERLAPPED    "SessionOverlapped"
59 #define SIGNAL_TDLS_CONNECTED                           "TDLSConnected"
60 #define SIGNAL_TDLS_DISCONNECTED                        "TDLSDisconnected"
61 #define SIGNAL_TDLS_PEER_FOUND                          "TDLSPeerFound"
62
63 #define SIGNAL_WPS_CONNECTED                            "WPSConnected"
64 #define SIGNAL_WPS_EVENT                                        "Event"
65 #define SIGNAL_WPS_CREDENTIALS                          "Credentials"
66
67 #define CONNMAN_SIGNAL_SERVICES_CHANGED         "ServicesChanged"
68 #define CONNMAN_SIGNAL_PROPERTY_CHANGED         "PropertyChanged"
69 #define SIGNAL_NAME_OWNER_CHANGED               "NameOwnerChanged"
70
71 #define MAX_SIG_LEN 64
72 #define TOTAL_CONN_SIGNALS 6
73 #define MAX_SOCKET_OPEN_RETRY 5
74
75 typedef enum {
76         SIG_INTERFACE_REMOVED = 0,
77         SIG_PROPERTIES_CHANGED,
78         SIG_BSS_ADDED,
79         SIG_SCAN_DONE,
80         SIG_DRIVER_HANGED,
81         SIG_SESSION_OVERLAPPED,
82         SIG_TDLS_CONNECTED,
83         SIG_TDLS_DISCONNECTED,
84         SIG_TDLS_PEER_FOUND,
85         SIG_MAX
86 } SuppSigArrayIndex;
87
88 static int conn_subscription_ids[TOTAL_CONN_SIGNALS] = {0};
89 static const char supplicant_signals[SIG_MAX][MAX_SIG_LEN] = {
90                 SIGNAL_INTERFACE_REMOVED,
91                 SIGNAL_PROPERTIES_CHANGED,
92                 SIGNAL_BSS_ADDED,
93                 SIGNAL_SCAN_DONE,
94                 SIGNAL_PROPERTIES_DRIVER_HANGED,
95                 SIGNAL_PROPERTIES_SESSION_OVERLAPPED,
96                 SIGNAL_TDLS_CONNECTED,
97                 SIGNAL_TDLS_DISCONNECTED,
98                 SIGNAL_TDLS_PEER_FOUND,
99 };
100
101 static int supp_subscription_ids[SIG_MAX] = {0};
102 #if defined TIZEN_DEBUG_ENABLE
103 static int dumpservice_subscription_id = 0;
104 #endif
105
106 typedef void (*supplicant_signal_cb)(GDBusConnection *conn,
107                 const gchar *name, const gchar *path, const gchar *interface,
108                 const gchar *sig, GVariant *param, gpointer user_data);
109 typedef void (*connman_signal_cb)(GDBusConnection *conn,
110                 const gchar *name, const gchar *path, const gchar *interface,
111                 const gchar *sig, GVariant *param, gpointer user_data);
112
113 static void __netconfig_extract_ipv4_signal_data(GVariant *dictionary,
114                 const gchar *profile)
115 {
116         gchar *key = NULL;
117         const gchar *value = NULL;
118         GVariant *var = NULL;
119         GVariantIter iter;
120         GVariantBuilder *builder;
121         GVariant *params;
122
123         g_variant_iter_init(&iter, dictionary);
124         while (g_variant_iter_loop(&iter, "{sv}", &key, &var)) {
125                 if (g_strcmp0(key, "Address") == 0)  {
126                         g_variant_get(var, "&s", &value);
127                         char *old_ip = vconf_get_str(VCONFKEY_NETWORK_IP);
128
129                         DBG("Old IPv4.Address [%s] Received new IPv4.Address [%s]", old_ip,
130                                                   value);
131                         if (g_strcmp0(old_ip, value) != 0) {
132                                 builder = g_variant_builder_new(G_VARIANT_TYPE("a{sv}"));
133
134                                 if (value != NULL) {
135                                         vconf_set_str(VCONFKEY_NETWORK_IP, value);
136                                         g_variant_builder_add(builder, "{sv}", "IPv4Address",
137                                                                   g_variant_new_string(value));
138                                 } else if (old_ip != NULL && strlen(old_ip) > 0) {
139                                         vconf_set_str(VCONFKEY_NETWORK_IP, "");
140                                         g_variant_builder_add(builder, "{sv}", "IPv4Address",
141                                                                   g_variant_new_string(""));
142                                 }
143
144                                 params = g_variant_new("(@a{sv})",
145                                                                            g_variant_builder_end(builder));
146
147                                 g_variant_builder_unref(builder);
148
149                                 netconfig_dbus_emit_signal(NULL, NETCONFIG_NETWORK_PATH,
150                                                    NETCONFIG_NETWORK_INTERFACE, "NetworkConfigChanged",
151                                                    params);
152                         }
153                         free(old_ip);
154                 }
155         }
156 }
157
158 static void __netconfig_extract_ipv6_signal_data(GVariant *dictionary,
159                                                                                                  const gchar *profile)
160 {
161         gchar *key = NULL;
162         const gchar *value = NULL;
163         GVariant *var = NULL;
164         GVariantIter iter;
165         GVariantBuilder *builder;
166         GVariant *params;
167
168         g_variant_iter_init(&iter, dictionary);
169         while (g_variant_iter_loop(&iter, "{sv}", &key, &var)) {
170                 if (g_strcmp0(key, "Address") == 0)  {
171                         g_variant_get(var, "&s", &value);
172                         char *old_ip6 = vconf_get_str(VCONFKEY_NETWORK_IP6);
173
174                         DBG("Old IPv6.Address [%s] Received new IPv6.Address [%s]", old_ip6,
175                                                         value);
176                         if (g_strcmp0(old_ip6, value) != 0) {
177                                 builder = g_variant_builder_new(G_VARIANT_TYPE("a{sv}"));
178
179                                 if (value != NULL) {
180                                         vconf_set_str(VCONFKEY_NETWORK_IP6, value);
181                                         g_variant_builder_add(builder, "{sv}", "IPv6Address",
182                                                                   g_variant_new_string(value));
183                                 } else if (old_ip6 != NULL && strlen(old_ip6) > 0) {
184                                         vconf_set_str(VCONFKEY_NETWORK_IP6, "");
185                                         g_variant_builder_add(builder, "{sv}", "IPv6Address",
186                                                                   g_variant_new_string(""));
187                                 }
188
189                                 params = g_variant_new("(@a{sv})",
190                                                                            g_variant_builder_end(builder));
191                                 g_variant_builder_unref(builder);
192
193                                 netconfig_dbus_emit_signal(NULL, NETCONFIG_NETWORK_PATH,
194                                                    NETCONFIG_NETWORK_INTERFACE, "NetworkConfigChanged",
195                                                    params);
196                         }
197                         free(old_ip6);
198                 }
199         }
200 }
201
202 #if defined TIZEN_DEBUG_ENABLE
203 static int __netconfig_handle_execute_file(const char *file_path,
204                 char *const args[], char *const envs[])
205 {
206         pid_t pid = 0;
207         int status = 0;
208         int rv = 0;
209         errno = 0;
210         register unsigned int index = 0;
211         char error_buf[MAX_SIZE_ERROR_BUFFER] = {0, };
212
213         while (args[index] != NULL) {
214                 DBG("%s", args[index]);
215                 index++;
216         }
217
218         if (!(pid = fork())) {
219                 DBG("pid(%d), ppid (%d)", getpid(), getppid());
220                 DBG("Inside child, exec (%s) command", file_path);
221
222                 errno = 0;
223                 if (execve(file_path, args, envs) == -1) {
224                         DBG("Fail to execute command (%s)",
225                                         strerror_r(errno, error_buf, MAX_SIZE_ERROR_BUFFER));
226                         exit(1);
227                 }
228         } else if (pid > 0) {
229                 if (waitpid(pid, &status, 0) == -1)
230                         DBG("wait pid (%u) status (%d)", pid, status);
231
232                 if (WIFEXITED(status)) {
233                         rv = WEXITSTATUS(status);
234                         DBG("exited, status=%d", rv);
235                 } else if (WIFSIGNALED(status)) {
236                         DBG("killed by signal %d", WTERMSIG(status));
237                 } else if (WIFSTOPPED(status)) {
238                         DBG("stopped by signal %d", WSTOPSIG(status));
239                 } else if (WIFCONTINUED(status)) {
240                         DBG("continued");
241                 }
242
243                 return rv;
244         }
245
246         DBG("failed to fork(%s)",
247                 strerror_r(errno, error_buf, MAX_SIZE_ERROR_BUFFER));
248         return -EIO;
249 }
250
251 static int _start_dump()
252 {
253         int rv = 0;
254         gchar *path = NETWORK_LOG_DUMP_SCRIPT;
255         char *const args[] = { NETWORK_LOG_DUMP_SCRIPT, NULL };
256         char *const envs[] = { NULL };
257
258         rv = __netconfig_handle_execute_file(path, args, envs);
259         if (rv < 0) {
260                 ERR("Fail to execute network log dump shell");
261                 return -EIO;
262         }
263         return 0;
264 }
265 #endif
266
267 static void _technology_signal_cb(GDBusConnection *conn,
268                 const gchar *name, const gchar *path, const gchar *interface,
269                 const gchar *sig, GVariant *param, gpointer user_data)
270 {
271         gchar *key = NULL;
272         gboolean value = FALSE;
273         GVariant *var = NULL;
274
275         if (param == NULL)
276                 return;
277
278         if (g_str_has_prefix(path, CONNMAN_WIFI_TECHNOLOGY_PREFIX) == TRUE) {
279                 g_variant_get(param, "(sv)", &key, &var);
280                 if (g_strcmp0(key, "Powered") == 0) {
281                         /* Power state */
282                         value = g_variant_get_boolean(var);
283                         if (value == TRUE)
284                                 wifi_state_update_power_state(TRUE);
285                         else
286                                 wifi_state_update_power_state(FALSE);
287                 } else if (g_strcmp0(key, "Connected") == 0) {
288                         /* Connection state */
289                         value = g_variant_get_boolean(var);
290                         if (value == TRUE)
291                                 wifi_state_set_tech_state(NETCONFIG_WIFI_TECH_CONNECTED);
292                         else
293                                 wifi_state_set_tech_state(NETCONFIG_WIFI_TECH_POWERED);
294                 } else if (g_strcmp0(key, "Tethering") == 0) {
295                         /* Tethering state */
296                         wifi_state_set_tech_state(NETCONFIG_WIFI_TECH_TETHERED);
297                 }
298                 g_free(key);
299                 g_variant_unref(var);
300         }
301 }
302
303 static void _service_signal_cb(GDBusConnection *conn,
304                 const gchar *name, const gchar *path,
305                 const gchar *interface, const gchar *sig,
306                 GVariant *param, gpointer user_data)
307 {
308         gchar *sigvalue = NULL;
309         gchar *property;
310         GVariant *variant = NULL, *var;
311         GVariantIter *iter;
312         const gchar *value = NULL;
313         struct sock_data *sd = NULL;
314         gchar *pf = NULL;
315         int idx = 0;
316
317         if (path == NULL || param == NULL)
318                 goto done;
319
320         g_variant_get(param, "(sv)", &sigvalue, &variant);
321         if (sigvalue == NULL)
322                 goto done;
323
324         if (g_strcmp0(sig, CONNMAN_SIGNAL_PROPERTY_CHANGED) != 0)
325                 goto done;
326
327         if (g_strcmp0(sigvalue, "State") == 0) {
328                 g_variant_get(variant, "s", &property);
329
330                 DBG("[%s] %s", property, path);
331
332                 if (netconfig_is_wifi_profile(path) == TRUE) {
333                         int wifi_state = 0;
334
335                         netconfig_vconf_get_int(VCONFKEY_WIFI_STATE, &wifi_state);
336                         if (wifi_state == VCONFKEY_WIFI_OFF) {
337                                 g_free(property);
338                                 goto done;
339                         }
340
341                         if (g_strcmp0(property, "ready") == 0 || g_strcmp0(property, "online") == 0) {
342                                 if (wifi_state >= VCONFKEY_WIFI_CONNECTED) {
343                                         g_free(property);
344                                         goto done;
345                                 }
346
347                                 netconfig_update_default_profile(path);
348
349                                 wifi_state_set_service_state(NETCONFIG_WIFI_CONNECTED);
350
351                         } else if (g_strcmp0(property, "failure") == 0 || g_strcmp0(property, "disconnect") == 0 || g_strcmp0(property, "idle") == 0) {
352                                 if (netconfig_get_default_profile() == NULL ||
353                                                 netconfig_is_wifi_profile(netconfig_get_default_profile())
354                                                 != TRUE) {
355                                         if (g_strcmp0(property, "failure") == 0)
356                                                 wifi_state_set_service_state(NETCONFIG_WIFI_FAILURE);
357                                         else
358                                                 wifi_state_set_service_state(NETCONFIG_WIFI_IDLE);
359                                         g_free(property);
360                                         goto done;
361                                 }
362
363                                 if (g_strcmp0(path, netconfig_get_default_profile()) != 0) {
364                                         g_free(property);
365                                         goto done;
366                                 }
367
368                                 netconfig_update_default_profile(NULL);
369
370                                 if (g_strcmp0(property, "failure") == 0)
371                                         wifi_state_set_service_state(NETCONFIG_WIFI_FAILURE);
372                                 else
373                                         wifi_state_set_service_state(NETCONFIG_WIFI_IDLE);
374
375                         } else if (g_strcmp0(property, "association") == 0 || g_strcmp0(property, "configuration") == 0) {
376                                 if (netconfig_get_default_profile() == NULL ||
377                                                 netconfig_is_wifi_profile(netconfig_get_default_profile()) != TRUE) {
378                                         if (g_strcmp0(property, "association") == 0)
379                                                 wifi_state_set_service_state(NETCONFIG_WIFI_ASSOCIATION);
380                                         else
381                                                 wifi_state_set_service_state(NETCONFIG_WIFI_CONFIGURATION);
382                                         g_free(property);
383                                         goto done;
384                                 }
385
386                                 if (g_strcmp0(path, netconfig_get_default_profile()) != 0) {
387                                         g_free(property);
388                                         goto done;
389                                 }
390
391                                 netconfig_update_default_profile(NULL);
392
393                                 if (g_strcmp0(property, "association") == 0)
394                                         wifi_state_set_service_state(NETCONFIG_WIFI_ASSOCIATION);
395                                 else
396                                         wifi_state_set_service_state(NETCONFIG_WIFI_CONFIGURATION);
397
398                         }
399                 } else {
400                         if (g_strcmp0(property, "ready") == 0 || g_strcmp0(property, "online") == 0) {
401                                 if (netconfig_get_default_profile() == NULL) {
402                                         if (!netconfig_is_cellular_profile(path))
403                                                 netconfig_update_default_profile(path);
404                                         else {
405                                                 if (netconfig_is_cellular_internet_profile(path))
406                                                         netconfig_update_default_profile(path);
407                                         }
408                                 } else {
409                                         pf = netconfig_get_connected_cellular_internet_ipv6only_profile(NULL);
410                                         if (pf)
411                                         {
412                                                 g_free(pf);
413
414                                                 /* Enable clatd if it is not in running state */
415                                                 DBG("Connected to ipv6 only cellular, enable clatd");
416                                                 netconfig_clatd_enable();
417                                         }
418                                 }
419
420                                 if (netconfig_is_cellular_profile(path) && netconfig_is_cellular_internet_profile(path))
421                                         cellular_state_set_service_state(NETCONFIG_CELLULAR_ONLINE);
422
423                         } else if (g_strcmp0(property, "failure") == 0 || g_strcmp0(property, "disconnect") == 0 || g_strcmp0(property, "idle") == 0) {
424                                 if (netconfig_get_default_profile() == NULL) {
425                                         g_free(property);
426                                         goto done;
427                                 }
428
429                                 if (netconfig_is_cellular_profile(path) && netconfig_is_cellular_internet_profile(path)) {
430                                         cellular_state_set_service_state(NETCONFIG_CELLULAR_IDLE);
431
432                                         /* Disable clatd if it is in running state */
433                                         DBG("disable clatd");
434                                         netconfig_clatd_disable();
435                                 }
436
437                                 if (g_strcmp0(path, netconfig_get_default_profile()) != 0) {
438                                         g_free(property);
439                                         goto done;
440                                 }
441
442                                 netconfig_update_default_profile(NULL);
443                         } else if (g_strcmp0(property, "association") == 0 || g_strcmp0(property, "configuration") == 0) {
444                                 if (netconfig_get_default_profile() == NULL) {
445                                         g_free(property);
446                                         goto done;
447                                 }
448
449                                 if (netconfig_is_cellular_profile(path) && netconfig_is_cellular_internet_profile(path))
450                                         cellular_state_set_service_state(NETCONFIG_CELLULAR_CONNECTING);
451
452                                 if (g_strcmp0(path, netconfig_get_default_profile()) != 0) {
453                                         g_free(property);
454                                         goto done;
455                                 }
456
457                                 netconfig_update_default_profile(NULL);
458                         }
459                 }
460
461                 if (netconfig_is_wifi_profile(path) || netconfig_is_ethernet_profile(path)) {
462                         if (g_strcmp0(property, "ready") == 0) {
463                                 for (idx = 0; idx < MAX_SOCKET_OPEN_RETRY; idx++) {
464                                         sd = start_ip_conflict_mon();
465                                         if (sd != NULL)
466                                                 break;
467                                 }
468                         } else if (g_strcmp0(property, "online") == 0) {
469                                 // do nothing
470                         } else {
471                                 stop_ip_conflict_mon();
472                         }
473                 }
474
475                 g_free(property);
476         } else if (g_strcmp0(sigvalue, "Proxy") == 0) {
477                 if (netconfig_is_wifi_profile(path) != TRUE || g_strcmp0(path, netconfig_get_default_profile()) != 0)
478                         goto done;
479
480                 if (!g_variant_is_of_type(variant, G_VARIANT_TYPE_ARRAY))
481                         goto done;
482
483                 g_variant_get(variant, "a{sv}", &iter);
484                 while (g_variant_iter_loop(iter, "{sv}", &property, &var)) {
485                         GVariantBuilder *builder;
486                         GVariant *sig_params;
487                         if (g_strcmp0(property, "Servers") == 0) {
488                                 GVariantIter *iter_sub = NULL;
489
490                                 builder = g_variant_builder_new(G_VARIANT_TYPE("a{sv}"));
491
492                                 g_variant_get(var, "as", &iter_sub);
493                                 g_variant_iter_loop(iter_sub, "s", &value);
494                                 g_variant_iter_free(iter_sub);
495
496                                 DBG("Proxy - [%s]", value);
497                                 vconf_set_str(VCONFKEY_NETWORK_PROXY, value);
498
499                                 g_variant_builder_add(builder, "{sv}", "ProxyAddress",
500                                                                 g_variant_new_string(value));
501
502                                 sig_params = g_variant_new("(@a{sv})",
503                                                                 g_variant_builder_end(builder));
504                                 g_variant_builder_unref(builder);
505
506                                 netconfig_dbus_emit_signal(NULL, NETCONFIG_NETWORK_PATH,
507                                                    NETCONFIG_NETWORK_INTERFACE, "NetworkConfigChanged",
508                                                    sig_params);
509
510                                 g_free(property);
511                                 g_variant_unref(var);
512                                 break;
513                         } else if (g_strcmp0(property, "Method") == 0) {
514                                 value = g_variant_get_string(var, NULL);
515                                 DBG("Method - [%s]", value);
516
517                                 if (g_strcmp0(value, "direct") == 0) {
518                                         builder = g_variant_builder_new(G_VARIANT_TYPE("a{sv}"));
519
520                                         vconf_set_str(VCONFKEY_NETWORK_PROXY, "");
521                                         g_variant_builder_add(builder, "{sv}", "ProxyAddress",
522                                                                 g_variant_new_string(""));
523
524                                         sig_params = g_variant_new("(@a{sv})",
525                                                                 g_variant_builder_end(builder));
526                                         g_variant_builder_unref(builder);
527
528                                         netconfig_dbus_emit_signal(NULL, NETCONFIG_NETWORK_PATH,
529                                                            NETCONFIG_NETWORK_INTERFACE,
530                                                            "NetworkConfigChanged", sig_params);
531                                 }
532
533                                 g_free(property);
534                                 g_variant_unref(var);
535                                 break;
536                         }
537                 }
538
539                 g_variant_iter_free(iter);
540         } else if (g_strcmp0(sigvalue, "IPv4") == 0) {
541                 __netconfig_extract_ipv4_signal_data(variant, path);
542         } else if (g_strcmp0(sigvalue, "IPv6") == 0) {
543                 __netconfig_extract_ipv6_signal_data(variant, path);
544         } else if (g_strcmp0(sigvalue, "Error") == 0) {
545                 g_variant_get(variant, "s", &property);
546                 INFO("[%s] Property : %s", sigvalue, property);
547 #if defined TIZEN_DEBUG_ENABLE
548                 if (g_strcmp0(property, "dhcp-failed") == 0
549                         || g_strcmp0(property, "connect-failed") == 0
550                         || g_strcmp0(property, "login-failed") == 0
551                         || g_strcmp0(property, "auth-failed") == 0
552                         || g_strcmp0(property, "invalid-key") == 0) {
553
554                         INFO("start dump");
555                         _start_dump();
556                 }
557 #endif
558                 g_free(property);
559         }
560 done:
561         g_free(sigvalue);
562
563         if (variant)
564                 g_variant_unref(variant);
565
566         return;
567 }
568
569 static void _dbus_name_changed_cb(GDBusConnection *conn,
570                 const gchar *Name, const gchar *path, const gchar *interface,
571                 const gchar *sig, GVariant *param, gpointer user_data)
572 {
573         gchar *name = NULL;
574         gchar *old = NULL;
575         gchar *new = NULL;
576
577         if (param == NULL)
578                 return;
579
580         g_variant_get(param, "(sss)", &name, &old, &new);
581
582         if (g_strcmp0(name, CONNMAN_SERVICE) == 0 && *new == '\0') {
583                 DBG("ConnMan destroyed: name %s, old %s, new %s", name, old, new);
584
585                 connman_register_agent();
586         } else if (g_strcmp0(name, CLATD_SERVICE) == 0 && *new == '\0') {
587                 DBG("Clat destroyed: name %s, old %s, new %s", name, old, new);
588
589                 /* If clatd is terminated unexpectedly, reset and enable clat service. */
590                 if (NETCONFIG_CELLULAR_ONLINE == cellular_state_get_service_state())
591                         netconfig_clatd_reset();
592         }
593         g_free(name);
594         g_free(old);
595         g_free(new);
596
597         return;
598 }
599
600 static void _services_changed_cb(GDBusConnection *conn, const gchar *name,
601                 const gchar *path, const gchar *interface, const gchar *sig,
602                 GVariant *param, gpointer user_data)
603 {
604         gchar *property, *value;
605         gchar *service_path;
606         GVariant *variant = NULL;
607         GVariantIter *added = NULL, *removed = NULL, *next = NULL;
608
609         if (path == NULL || param == NULL)
610                 return;
611
612         if (g_strcmp0(sig, CONNMAN_SIGNAL_SERVICES_CHANGED) != 0)
613                 return;
614
615         if (netconfig_get_default_profile() != NULL)
616                 return;
617
618         g_variant_get(param, "(a(oa{sv})ao)", &added, &removed);
619
620         while (g_variant_iter_loop(added, "(oa{sv})", &service_path, &next)) {
621                 gboolean is_wifi_prof, is_cell_prof, is_cell_internet_prof;
622                 is_wifi_prof = netconfig_is_wifi_profile(service_path);
623                 is_cell_prof = netconfig_is_cellular_profile(service_path);
624                 is_cell_internet_prof = netconfig_is_cellular_internet_profile(
625                                 service_path);
626                 if (service_path != NULL) {
627                         while (next && g_variant_iter_loop(next, "{sv}", &property,
628                                                 &variant)) {
629                                 if (g_strcmp0(property, "State") == 0) {
630                                         g_variant_get(variant, "s", &value);
631                                         DBG("Profile %s State %s", service_path,
632                                                         value);
633                                         if (g_strcmp0(value, "ready") != 0 &&
634                                                         g_strcmp0(value,
635                                                                 "online") != 0) {
636                                                 g_free(property);
637                                                 g_free(value);
638                                                 g_variant_unref(variant);
639                                                 break;
640                                         }
641
642                                         if (!is_cell_prof)
643                                                 netconfig_update_default_profile(
644                                                                 service_path);
645                                         else if (is_cell_internet_prof) {
646                                                 netconfig_update_default_profile(
647                                                                 service_path);
648                                         }
649                                         if (is_wifi_prof)
650                                                 wifi_state_set_service_state(
651                                                         NETCONFIG_WIFI_CONNECTED);
652                                         else if (is_cell_prof &&
653                                                         is_cell_internet_prof)
654                                                 cellular_state_set_service_state(
655                                                         NETCONFIG_CELLULAR_ONLINE);
656                                         g_free(property);
657                                         g_free(value);
658                                         g_variant_unref(variant);
659                                         break;
660                                 }
661                         }
662                 }
663         }
664
665         g_variant_iter_free(added);
666
667         if (next)
668                 g_variant_iter_free(next);
669
670         if (removed)
671                 g_variant_iter_free(removed);
672
673         return;
674 }
675
676 static void _supplicant_interface_removed(GDBusConnection *conn,
677                 const gchar *name, const gchar *path, const gchar *interface,
678                 const gchar *sig, GVariant *param, gpointer user_data)
679 {
680         DBG("Interface removed handling!");
681         if (netconfig_wifi_is_bssid_scan_started() == TRUE)
682                 netconfig_wifi_bssid_signal_scanaborted();
683
684         return;
685 }
686
687 static void _supplicant_properties_changed(GDBusConnection *conn,
688                 const gchar *name, const gchar *path, const gchar *interface,
689                 const gchar *sig, GVariant *param, gpointer user_data)
690 {
691         DBG("Properties changed handling!");
692         gchar *key = NULL;
693         const gchar *state = NULL;
694         GVariantIter *iter = NULL;
695         GVariant *variant = NULL;
696         gboolean scanning = FALSE;
697
698         if (param == NULL)
699                 return;
700
701         g_variant_get(param, "(a{sv})", &iter);
702         while (g_variant_iter_loop(iter, "{sv}", &key, &variant)) {
703                 if (g_strcmp0(key, "Scanning") == 0) {
704                         scanning = g_variant_get_boolean(variant);
705                         DBG("setting scanning %s", scanning ? "TRUE" : "FALSE");
706                         if (scanning == TRUE)
707                                 netconfig_wifi_set_scanning(TRUE);
708                         else
709                                 netconfig_wifi_set_scanning(FALSE);
710
711                         g_variant_unref(variant);
712                         g_free(key);
713                         variant = NULL;
714                         key = NULL;
715                         break;
716                 } else if (g_strcmp0(key, "State") == 0) {
717                         state = g_variant_get_string(variant, NULL);
718                         if (state != NULL)
719                                 ERR("Supplicant state : %s", state);
720
721                         g_variant_unref(variant);
722                         g_free(key);
723                         variant = NULL;
724                         key = NULL;
725                         break;
726                 } else if (g_strcmp0(key, "DisconnectReason") == 0) {
727                         int reason = g_variant_get_int32(variant);
728                         ERR("Supplicant DisconnReason : %d", reason);
729
730                         g_variant_unref(variant);
731                         g_free(key);
732                         variant = NULL;
733                         key = NULL;
734                         break;
735                 } else {
736                         gchar *value;
737                         value = g_variant_print(variant, TRUE);
738                         DBG("Supplicant %s : %s", key, value);
739
740                         g_free(value);
741                 }
742         }
743
744         g_variant_iter_free(iter);
745
746         return;
747 }
748
749 static void _supplicant_bss_added(GDBusConnection *conn,
750                 const gchar *name, const gchar *path, const gchar *interface,
751                 const gchar *sig, GVariant *param, gpointer user_data)
752 {
753         DBG("BSS added handling!");
754         wifi_state_set_bss_found(TRUE);
755
756         return;
757 }
758
759 static void _supplicant_scan_done(GDBusConnection *conn,
760                 const gchar *name, const gchar *path, const gchar *interface,
761                 const gchar *sig, GVariant *param, gpointer user_data)
762 {
763         DBG("Scan Done handling!");
764         netconfig_wifi_set_scanning(FALSE);
765
766         if (netconfig_wifi_is_bssid_scan_started() == TRUE) {
767                 netconfig_wifi_bssid_signal_scandone();
768                 if (wifi_state_get_technology_state() < NETCONFIG_WIFI_TECH_POWERED)
769                         return;
770         }
771
772         if (netconfig_wifi_get_bgscan_state() == TRUE) {
773                 if (wifi_state_get_technology_state() >=
774                                 NETCONFIG_WIFI_TECH_POWERED)
775                         netconfig_wifi_bgscan_start(FALSE);
776
777                 wifi_start_timer_network_notification();
778         }
779
780         return;
781 }
782
783 static void _supplicant_driver_hanged(GDBusConnection *conn,
784                 const gchar *name, const gchar *path, const gchar *interface,
785                 const gchar *sig, GVariant *param, gpointer user_data)
786 {
787         DBG("Driver Hanged handling!");
788         ERR("Critical. Wi-Fi firmware crashed");
789
790 #if !defined TIZEN_WEARABLE
791         netconfig_send_message_to_net_popup("Wi-Fi Error",
792                 "Wi-Fi Driver Hanged. Please get log dump and report", "popup", NULL);
793 #endif
794         wifi_power_recover_firmware();
795
796         return;
797
798 }
799
800 static void _supplicant_session_overlapped(GDBusConnection *conn,
801                 const gchar *name, const gchar *path, const gchar *interface,
802                 const gchar *sig, GVariant *param, gpointer user_data)
803 {
804         DBG("Driver session overlapped handling!");
805         ERR("WPS PBC SESSION OVERLAPPED");
806 #if defined TIZEN_WEARABLE
807         return;
808 #else
809         netconfig_send_message_to_net_popup("WPS Error",
810                                         "wps session overlapped", "popup", NULL);
811 #endif
812 }
813
814 #if defined TIZEN_DEBUG_ENABLE
815 static void __netconfig_dumpservice_handler(GDBusConnection *conn,
816                 const gchar *name, const gchar *path, const gchar *interface,
817                 const gchar *sig, GVariant *param, gpointer user_data)
818 {
819         int mode;
820         gchar *signal_path = NULL;
821
822         if (param == NULL)
823                 return;
824
825         g_variant_get(param, "(is)", &mode, &signal_path);
826         DBG("Path: %s and mode: %d", signal_path, mode);
827
828         netconfig_dump_log(signal_path);
829         if (signal_path)
830                 g_free(signal_path);
831
832         return;
833 }
834 #endif
835
836 static void _supplicant_tdls_connected(GDBusConnection *conn,
837                 const gchar *name, const gchar *path, const gchar *interface,
838                 const gchar *sig, GVariant *param, gpointer user_data)
839 {
840         DBG("Received TDLS Connected Signal");
841         netconfig_wifi_tdls_connected_event(param);
842
843         return;
844 }
845
846 static void _supplicant_tdls_disconnected(GDBusConnection *conn,
847                 const gchar *name, const gchar *path, const gchar *interface,
848                 const gchar *sig, GVariant *param, gpointer user_data)
849 {
850         DBG("Received TDLS Disconnected Signal");
851         netconfig_wifi_tdls_disconnected_event(param);
852
853         return;
854 }
855
856 static void _supplicant_tdls_peer_found(GDBusConnection *conn,
857                 const gchar *name, const gchar *path, const gchar *interface,
858                 const gchar *sig, GVariant *param, gpointer user_data)
859 {
860         DBG("Received TDLS Peer Found Signal");
861         netconfig_wifi_tdls_peer_found_event(param);
862         return;
863 }
864
865 static void _supplicant_wifi_wps_connected(GVariant *param)
866 {
867         gchar *key;
868         char ssid[32] = {0, };
869         gchar *name;
870         GVariantIter *iter;
871         GVariant *variant;
872         int config_error = 0;
873         int error_indication = 0;
874         gsize ssid_len = 0;
875
876         if (param == NULL) {
877                 ERR("Param is NULL");
878                 return;
879         }
880
881         g_variant_get(param, "(sa{sv})", &name, &iter);
882         INFO("wps Result: %s", name);
883         while (g_variant_iter_loop(iter, "{sv}", &key, &variant)) {
884                 INFO("wps Key is %s", key);
885                 if (g_strcmp0(key, "SSID") == 0) {
886                         const char *t_key = NULL;
887                         t_key = g_variant_get_fixed_array(variant, &ssid_len, sizeof(guchar));
888                         INFO("wps ssid_len is %zd ", ssid_len);
889                         if (t_key == NULL) {
890                                 g_free(key);
891                                 g_variant_unref(variant);
892                                 ERR("WPS PBC Connection Failed");
893                                 goto error;
894                         }
895                         if (ssid_len > 0 && ssid_len <= 32) {
896                                 memcpy(ssid, t_key, ssid_len);
897                         } else {
898                                 memset(ssid, 0, sizeof(ssid));
899                                 ssid_len = 0;
900                         }
901                         INFO("WPS PBC Connection completed with AP %s", ssid);
902                         netconfig_wifi_notify_wps_completed(ssid, ssid_len);
903                 }
904         }
905
906         g_variant_iter_free(iter);
907         g_free(name);
908         return;
909
910 error:
911         g_variant_iter_free(iter);
912         g_free(name);
913         error_indication = WPS_EI_OPERATION_FAILED;
914         config_error = WPS_CFG_NO_ERROR;
915         ERR("Error Occured! Notifying Fail Event");
916         netconfig_wifi_notify_wps_fail_event(config_error, error_indication);
917
918 }
919
920 static void _supplicant_wifi_wps_event(GVariant *param)
921 {
922         gchar *key;
923         gchar *name;
924         GVariantIter *iter;
925         GVariant *variant;
926         gint32 config_error = 0;
927         gint32 error_indication = 0;
928
929         if (param == NULL) {
930                 ERR("Param is NULL");
931                 return;
932         }
933
934         g_variant_get(param, "(sa{sv})", &name, &iter);
935         INFO("Event Result: %s", name);
936         if (g_strcmp0(name, "fail") == 0) {
937                 while (g_variant_iter_loop(iter, "{sv}", &key, &variant)) {
938                         if (key == NULL)
939                                 goto error;
940                         INFO("Key is %s", key);
941                         if (g_strcmp0(key, "config_error") == 0) {
942                                 config_error = g_variant_get_int32(variant);
943                                 ERR("Config Error %d", config_error);
944                         } else if (g_strcmp0(key, "error_indication") == 0) {
945                                 error_indication = g_variant_get_int32(variant);
946                                 ERR("Error Indication %d", error_indication);
947                         }
948                 }
949                 netconfig_wifi_notify_wps_fail_event(config_error, error_indication);
950         }
951
952         g_variant_iter_free(iter);
953         g_free(name);
954         return;
955
956 error:
957         g_variant_iter_free(iter);
958         g_free(name);
959         error_indication = WPS_EI_OPERATION_FAILED;
960         config_error = WPS_CFG_NO_ERROR;
961         ERR("Error Occured! Notifying Fail Event");
962         netconfig_wifi_notify_wps_fail_event(config_error, error_indication);
963 }
964
965 static void _find_service_and_set_passphrase(char *ssid, char *key)
966 {
967         GString *str;
968         GVariant *reply = NULL;
969         int i, j, ssid_len;
970         char *service_path;
971         char *dev_mac_addr;
972         char ident[13];
973         gchar *enc_passphrase;
974
975         ssid_len = strlen(ssid);
976
977         str = g_string_sized_new((ssid_len * 2) + 55);
978         if (!str)
979                 return;
980
981         dev_mac_addr = vconf_get_str(VCONFKEY_WIFI_BSSID_ADDRESS);
982         if (!dev_mac_addr) {
983                 ERR("Failed to get mac address from vconf key");
984                 g_string_free(str, TRUE);
985                 return;
986         }
987
988         j = 0;
989         for (i = 0; dev_mac_addr[i]; i++) {
990                 if (dev_mac_addr[i] != ':')
991                         ident[j++] = dev_mac_addr[i];
992         }
993         ident[j] = '\0';
994
995         g_string_append_printf(str, "%s%s_", CONNMAN_WIFI_SERVICE_PROFILE_PREFIX,
996                                                    ident);
997         free(dev_mac_addr);
998
999         for (i = 0; i < ssid_len; i++) {
1000                 if (ssid[i] != '"')
1001                         g_string_append_printf(str, "%02x", ssid[i]);
1002         }
1003
1004         g_string_append_printf(str, "_managed_psk");
1005
1006         service_path = g_string_free(str, FALSE);
1007
1008         enc_passphrase = _netconfig_encrypt_passphrase(key);
1009         if (!enc_passphrase) {
1010                 ERR("Failed to encrypt passphrase");
1011                 g_free(service_path);
1012                 return;
1013         }
1014
1015         INFO("wps service_path %s Passphrase %s", service_path, enc_passphrase);
1016
1017         reply = netconfig_invoke_dbus_method(CONNMAN_SERVICE, service_path,
1018                                          CONNMAN_SERVICE_INTERFACE, "SetProperty",
1019                                          g_variant_new("(sv)", "Passphrase",
1020                                                                    g_variant_new_string(enc_passphrase)));
1021         if (reply != NULL)
1022                 g_variant_unref(reply);
1023         else
1024                 ERR("Failed to set passphrase");
1025
1026         g_free(service_path);
1027
1028         return;
1029 }
1030
1031 static void _supplicant_wifi_wps_credentials(GVariant *param)
1032 {
1033         gchar *key;
1034         char ssid[32] = {0, };
1035         char wps_key[100] = {0, };
1036         GVariantIter *iter;
1037         GVariant *variant;
1038         int config_error = 0;
1039         int error_indication = 0;
1040         gsize ssid_len = 0;
1041         char *key_mgmt = NULL;
1042
1043         if (param == NULL) {
1044                 ERR("Param is NULL");
1045                 return;
1046         }
1047
1048         g_variant_get(param, "(a{sv})", &iter);
1049         while (g_variant_iter_loop(iter, "{sv}", &key, &variant)) {
1050                 if (key == NULL)
1051                         goto error;
1052                 INFO("wps Key is %s", key);
1053                 if (g_strcmp0(key, "Key") == 0) {
1054                         gsize key_len = 0;
1055                         const char *t_key = NULL;
1056                         key_len = g_variant_get_size(variant);
1057
1058                         INFO("wps password len %zd ", key_len);
1059                         if (key_len > 0) {
1060                                 t_key = g_variant_get_fixed_array(variant, &key_len,
1061                                                   sizeof(guchar));
1062                                 if (!t_key) {
1063                                         g_free(key);
1064                                         g_variant_unref(variant);
1065                                         goto error;
1066                                 }
1067                                 strncpy(wps_key, t_key, key_len);
1068                                 wps_key[key_len] = '\0';
1069                                 INFO("WPS Key in process credentials %s", wps_key);
1070                         } else
1071                                 SLOGI("WPS AP Security ->Open");
1072                 } else if (g_strcmp0(key, "SSID") == 0) {
1073                         const char *t_key = NULL;
1074                         t_key = g_variant_get_fixed_array(variant, &ssid_len,
1075                                                   sizeof(guchar));
1076                         INFO("wps ssid_len is %zd ", ssid_len);
1077                         if (!t_key) {
1078                                 g_free(key);
1079                                 g_variant_unref(variant);
1080                                 goto error;
1081                         }
1082                         if (ssid_len > 0 && ssid_len <= 32) {
1083                                 memcpy(ssid, t_key, ssid_len);
1084                         } else {
1085                                 memset(ssid, 0, sizeof(ssid));
1086                                 ssid_len = 0;
1087                         }
1088                         INFO("SSID in process credentials %s", ssid);
1089                 } else if (g_strcmp0(key, "AuthType") == 0) {
1090                         gchar *auth_type;
1091                         GVariantIter *var_iter;
1092                         g_variant_get(variant, "as", &var_iter);
1093                         while (g_variant_iter_loop(var_iter, "s", &auth_type)) {
1094                                 INFO("wps auth_type %s", auth_type);
1095                                 if (g_strcmp0(auth_type, "wpa-psk") == 0 ||
1096                                         g_strcmp0(auth_type, "wpa2-psk") == 0)
1097                                         key_mgmt = "psk";
1098                                 else if (g_strcmp0(auth_type, "open") == 0)
1099                                         key_mgmt = "none";
1100                         }
1101                         g_variant_iter_free(var_iter);
1102                 } else if (g_strcmp0(key, "EncrType") == 0) {
1103                         gchar *encr_type;
1104                         GVariantIter *var_iter;
1105                         g_variant_get(variant, "as", &var_iter);
1106                         while (g_variant_iter_loop(var_iter, "s", &encr_type))
1107                                 INFO("wps encr_type %s", encr_type);
1108                         g_variant_iter_free(var_iter);
1109                 } else if (g_strcmp0(key, "BSSID") == 0) {
1110                         const guchar *bssid;
1111                         gsize bssid_len;
1112                         bssid = g_variant_get_fixed_array(variant, &bssid_len,
1113                                                                 sizeof(guchar));
1114                         if (bssid && bssid_len == 6)
1115                                 INFO("wps BSSID %2x:%2x:%2x:%2x:%2x:%2x", bssid[0], bssid[1],
1116                                          bssid[2], bssid[3], bssid[4], bssid[5]);
1117                 }
1118         }
1119
1120         g_variant_iter_free(iter);
1121
1122         if (g_strcmp0(key_mgmt, "psk") == 0)
1123                 _find_service_and_set_passphrase(ssid, wps_key);
1124
1125 #if 0
1126         /*
1127          * Notify WPS Credentials only when requested through WPS PBC
1128          * In case of WPS PIN connman will take care of notification
1129          */
1130         if (netconfig_get_wps_field() == TRUE)
1131 #endif
1132         netconfig_wifi_notify_wps_credentials(ssid, ssid_len, wps_key);
1133         return;
1134
1135 error:
1136         g_variant_iter_free(iter);
1137         error_indication = WPS_EI_OPERATION_FAILED;
1138         config_error = WPS_CFG_NO_ERROR;
1139         ERR("Error Occured! Notifying Fail Event");
1140         netconfig_wifi_notify_wps_fail_event(config_error, error_indication);
1141 }
1142
1143 static void __netconfig_wps_signal_filter_handler(GDBusConnection *conn,
1144                 const gchar *name, const gchar *path, const gchar *interface,
1145                 const gchar *sig, GVariant *param, gpointer user_data)
1146 {
1147         if (g_strcmp0(sig, SIGNAL_WPS_CREDENTIALS) == 0) {
1148                 INFO("Received wps CREDENTIALS Signal from Supplicant");
1149                 _supplicant_wifi_wps_credentials(param);
1150         } else if (g_strcmp0(sig, SIGNAL_WPS_EVENT) == 0) {
1151                 INFO("Received wps EVENT Signal from Supplicant");
1152                 _supplicant_wifi_wps_event(param);
1153         } else if (g_strcmp0(sig, SIGNAL_WPS_CONNECTED) == 0) {
1154                 INFO("Received WPSConnected Signal from Supplicant");
1155                 _supplicant_wifi_wps_connected(param);
1156         }
1157
1158         return;
1159 }
1160
1161 static supplicant_signal_cb supplicant_cbs[SIG_MAX] = {
1162                 _supplicant_interface_removed,
1163                 _supplicant_properties_changed,
1164                 _supplicant_bss_added,
1165                 _supplicant_scan_done,
1166                 _supplicant_driver_hanged,
1167                 _supplicant_session_overlapped,
1168                 _supplicant_tdls_connected,
1169                 _supplicant_tdls_disconnected,
1170                 _supplicant_tdls_peer_found
1171 };
1172
1173 void register_gdbus_signal(void)
1174 {
1175         GDBusConnection *connection = NULL;
1176         const char *interface = NULL;
1177         SuppSigArrayIndex sig;
1178         connection = netdbus_get_connection();
1179
1180         if (connection == NULL) {
1181                 ERR("Failed to get GDbus Connection");
1182                 return;
1183         }
1184
1185         /* listening to messages from all objects as no path is specified */
1186         /* see signals from the given interface */
1187         conn_subscription_ids[0] = g_dbus_connection_signal_subscribe(
1188                         connection,
1189                         CONNMAN_SERVICE,
1190                         CONNMAN_TECHNOLOGY_INTERFACE,
1191                         NULL,
1192                         NULL,
1193                         NULL,
1194                         G_DBUS_SIGNAL_FLAGS_NONE,
1195                         _technology_signal_cb,
1196                         NULL,
1197                         NULL);
1198
1199         conn_subscription_ids[1] = g_dbus_connection_signal_subscribe(
1200                         connection,
1201                         CONNMAN_SERVICE,
1202                         CONNMAN_SERVICE_INTERFACE,
1203                         CONNMAN_SIGNAL_PROPERTY_CHANGED,
1204                         NULL,
1205                         NULL,
1206                         G_DBUS_SIGNAL_FLAGS_NONE,
1207                         _service_signal_cb,
1208                         NULL,
1209                         NULL);
1210
1211         conn_subscription_ids[2] = g_dbus_connection_signal_subscribe(
1212                         connection,
1213                         DBUS_SERVICE_DBUS,
1214                         DBUS_INTERFACE_DBUS,
1215                         SIGNAL_NAME_OWNER_CHANGED,
1216                         NULL,
1217                         CONNMAN_SERVICE,
1218                         G_DBUS_SIGNAL_FLAGS_NONE,
1219                         _dbus_name_changed_cb,
1220                         NULL,
1221                         NULL);
1222
1223         conn_subscription_ids[3] = g_dbus_connection_signal_subscribe(
1224                         connection,
1225                         CONNMAN_SERVICE,
1226                         CONNMAN_MANAGER_INTERFACE,
1227                         CONNMAN_SIGNAL_SERVICES_CHANGED,
1228                         NULL,
1229                         NULL,
1230                         G_DBUS_SIGNAL_FLAGS_NONE,
1231                         _services_changed_cb,
1232                         NULL,
1233                         NULL);
1234
1235         INFO("Successfully register connman DBus signal filters");
1236
1237         conn_subscription_ids[4] = g_dbus_connection_signal_subscribe(
1238                         connection,
1239                         SUPPLICANT_SERVICE,
1240                         SUPPLICANT_INTERFACE ".Interface.WPS",
1241                         NULL,
1242                         NULL,
1243                         NULL,
1244                         G_DBUS_SIGNAL_FLAGS_NONE,
1245                         __netconfig_wps_signal_filter_handler,
1246                         NULL,
1247                         NULL);
1248
1249         INFO("Successfully register Supplicant WPS DBus signal filters");
1250
1251         conn_subscription_ids[5] = g_dbus_connection_signal_subscribe(
1252                         connection,
1253                         DBUS_SERVICE_DBUS,
1254                         DBUS_INTERFACE_DBUS,
1255                         SIGNAL_NAME_OWNER_CHANGED,
1256                         NULL,
1257                         CLATD_SERVICE,
1258                         G_DBUS_SIGNAL_FLAGS_NONE,
1259                         _dbus_name_changed_cb,
1260                         NULL,
1261                         NULL);
1262
1263         INFO("Successfully register clat DBus signal filters");
1264
1265         for (sig = SIG_INTERFACE_REMOVED; sig < SIG_MAX; sig++) {
1266                 /*
1267                  * For SIG_INTERFACE_REMOVED INTERFACE_ADDED
1268                  */
1269                 interface = (sig == SIG_INTERFACE_REMOVED) ?
1270                                 SUPPLICANT_INTERFACE : SUPPLICANT_IFACE_INTERFACE;
1271
1272                 supp_subscription_ids[sig] = g_dbus_connection_signal_subscribe(
1273                                 connection,
1274                                 SUPPLICANT_SERVICE,
1275                                 interface,
1276                                 supplicant_signals[sig],
1277                                 NULL,
1278                                 NULL,
1279                                 G_DBUS_SIGNAL_FLAGS_NONE,
1280                                 supplicant_cbs[sig],
1281                                 NULL,
1282                                 NULL);
1283         }
1284
1285         INFO("Successfully register Supplicant DBus signal filters");
1286
1287 #if defined TIZEN_DEBUG_ENABLE
1288         dumpservice_subscription_id = g_dbus_connection_signal_subscribe(
1289                         connection,
1290                         NULL,
1291                         DUMP_SERVICE_INTERFACE,
1292                         DUMP_SIGNAL,
1293                         NULL,
1294                         NULL,
1295                         G_DBUS_SIGNAL_FLAGS_NONE,
1296                         __netconfig_dumpservice_handler,
1297                         NULL,
1298                         NULL);
1299
1300         INFO("Successfully registered Dumpservice DBus signal filter");
1301 #endif
1302
1303         /* In case ConnMan precedes this signal register,
1304          * net-config should update the default connected profile.
1305          */
1306         netconfig_update_default();
1307 }
1308
1309 void deregister_gdbus_signal(void)
1310 {
1311         GDBusConnection *connection = NULL;
1312         int signal;
1313         SuppSigArrayIndex sig;
1314         connection = netdbus_get_connection();
1315         if (!connection) {
1316                 ERR("Already de-registered. Nothing to be done");
1317                 return;
1318         }
1319
1320         for (signal = 0; signal < TOTAL_CONN_SIGNALS; signal++) {
1321                 if (conn_subscription_ids[signal]) {
1322                         g_dbus_connection_signal_unsubscribe(connection,
1323                                                 conn_subscription_ids[signal]);
1324                 }
1325         }
1326
1327         for (sig = SIG_INTERFACE_REMOVED; sig < SIG_MAX; sig++) {
1328                 if (supp_subscription_ids[sig]) {
1329                         g_dbus_connection_signal_unsubscribe(connection,
1330                                                 supp_subscription_ids[sig]);
1331                 }
1332         }
1333
1334 #if defined TIZEN_DEBUG_ENABLE
1335         g_dbus_connection_signal_unsubscribe(connection,
1336                         dumpservice_subscription_id);
1337 #endif
1338 }