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