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