Add ASP provision discovery request for wpasupplicant plugin
[platform/core/connectivity/wifi-direct-manager.git] / plugin / wpasupplicant / ctrl_iface_dbus / wfd-plugin-wpasupplicant.c
1 /*
2  * Network Configuration Module
3  *
4  * Copyright (c) 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 /**
21  * This file implements wifi direct wpasupplicant dbus plugin functions.
22  *
23  * @file                wfd-plugin-dbus-wpasupplicant.c
24  * @author      Jiung Yu (jiung.yu@samsung.com)
25  * @version     0.7
26  */
27
28 #include <stdio.h>
29 #include <string.h>
30 #include <stdlib.h>
31 #include <sys/types.h>
32 #include <sys/wait.h>
33 #include <sys/socket.h>
34 #include <sys/un.h>
35 #include <unistd.h>
36 #include <fcntl.h>
37 #define _GNU_SOURCE
38 #include <poll.h>
39 #include <errno.h>
40 #include <sys/ioctl.h>
41 #include <net/if.h>
42
43 #include <glib.h>
44 #include <gio/gio.h>
45
46 #include <tzplatform_config.h>
47
48 #include "wifi-direct-oem.h"
49 #include "wfd-plugin-log.h"
50 #include "wfd-plugin-wpasupplicant.h"
51 #include "dbus/wfd-plugin-supplicant-dbus.h"
52
53 #if defined(TIZEN_FEATURE_ASP)
54 #define GLIST_ITER_START(arg_list, elem)\
55         GList *temp = NULL;\
56         temp = g_list_first(arg_list);\
57         while (temp) {\
58                 elem = temp->data;\
59                 temp = g_list_next(temp);\
60
61 #define GLIST_ITER_END() }
62 #endif
63
64 #define NETCONFIG_SERVICE "net.netconfig"
65 #define NETCONFIG_WIFI_INTERFACE "net.netconfig.wifi"
66 #define NETCONFIG_WIFI_PATH "/net/netconfig/wifi"
67
68 #define NETCONFIG_DBUS_REPLY_TIMEOUT (10 * 1000)
69
70 #if defined TIZEN_MOBILE
71 #define DEFAULT_MAC_FILE_PATH tzplatform_mkpath(TZ_SYS_ETC, ".mac.info")
72 #endif
73
74 #if defined TIZEN_WIFI_MODULE_BUNDLE
75 #define DEFAULT_MAC_FILE_PATH "/sys/class/net/wlan0/address"
76 #endif
77
78 #ifndef DEFAULT_MAC_FILE_PATH
79 #define DEFAULT_MAC_FILE_PATH "/sys/class/net/p2p0/address"
80 #endif
81
82 static wfd_oem_ops_s supplicant_ops = {
83         .init = ws_init,
84         .deinit = ws_deinit,
85         .activate = ws_activate,
86         .deactivate = ws_deactivate,
87
88         .start_scan = ws_start_scan,
89         .stop_scan = ws_stop_scan,
90         .get_visibility = ws_get_visibility,
91         .set_visibility = ws_set_visibility,
92         .get_scan_result = ws_get_scan_result,
93         .get_peer_info = ws_get_peer_info,
94
95         .prov_disc_req = ws_prov_disc_req,
96
97         .connect = ws_connect,
98         .disconnect = ws_disconnect,
99         .reject_connection = ws_reject_connection,
100         .cancel_connection = ws_cancel_connection,
101
102         .get_connected_peers = ws_get_connected_peers,
103         .get_pin = ws_get_pin,
104         .set_pin = ws_set_pin,
105         .generate_pin = ws_generate_pin,
106         .get_supported_wps_mode = ws_get_supported_wps_mode,
107
108         .create_group = ws_create_group,
109         .destroy_group = ws_destroy_group,
110         .invite = ws_invite,
111         .wps_start = ws_wps_start,
112         .enrollee_start = ws_enrollee_start,
113         .wps_cancel = ws_wps_cancel,
114
115         .get_dev_name = ws_get_dev_name,
116         .set_dev_name = ws_set_dev_name,
117         .get_dev_mac = ws_get_dev_mac,
118         .get_dev_type = ws_get_dev_type,
119         .set_dev_type = ws_set_dev_type,
120         .get_go_intent = ws_get_go_intent,
121         .set_go_intent = ws_set_go_intent,
122         .set_country = ws_set_country,
123         .get_persistent_groups = ws_get_persistent_groups,
124         .remove_persistent_group = ws_remove_persistent_group,
125         .set_persistent_reconnect = ws_set_persistent_reconnect,
126
127 #ifdef TIZEN_FEATURE_SERVICE_DISCOVERY
128         .start_service_discovery = ws_start_service_discovery,
129         .cancel_service_discovery = ws_cancel_service_discovery,
130
131         .serv_add = ws_serv_add,
132         .serv_del = ws_serv_del,
133 #endif /* TIZEN_FEATURE_SERVICE_DISCOVERY */
134
135 #ifdef TIZEN_FEATURE_WIFI_DISPLAY
136         .miracast_init = ws_miracast_init,
137         .set_display = ws_set_display,
138 #endif /* TIZEN_FEATURE_WIFI_DISPLAY */
139
140         .refresh = ws_refresh,
141         .save_config =  ws_save_config,
142         .set_operating_channel = ws_set_operating_channel,
143         .remove_all_network = ws_remove_all_network,
144         .get_wpa_status = ws_get_wpa_status,
145
146 #if defined(TIZEN_FEATURE_ASP)
147         .advertise_service = ws_advertise_service,
148         .cancel_advertise_service = ws_cancel_advertise_service,
149         .seek_service = ws_seek_service,
150         .cancel_seek_service = ws_cancel_seek_service,
151         .asp_prov_disc_req = ws_asp_prov_disc_req,
152 #endif /* TIZEN_FEATURE_ASP */
153         };
154
155 static ws_dbus_plugin_data_s *g_pd;
156
157 #ifdef TIZEN_FEATURE_SERVICE_DISCOVERY
158 static GList *service_list;
159 #endif /* TIZEN_FEATURE_SERVICE_DISCOVERY */
160
161 static GList *seek_list;
162
163 static void _supplicant_signal_cb(GDBusConnection *connection,
164                 const gchar *sender, const gchar *object_path, const gchar *interface,
165                 const gchar *signal, GVariant *parameters, gpointer user_data);
166
167 static void _p2pdevice_signal_cb(GDBusConnection *connection,
168                 const gchar *sender, const gchar *object_path, const gchar *interface,
169                 const gchar *signal, GVariant *parameters, gpointer user_data);
170
171 static void _group_signal_cb(GDBusConnection *connection,
172                 const gchar *sender, const gchar *object_path, const gchar *interface,
173                 const gchar *signal, GVariant *parameters, gpointer user_data);
174
175 static int __ws_txt_to_mac(unsigned char *txt, unsigned char *mac)
176 {
177         int i = 0;
178
179         if (!txt || !mac) {
180                 WDP_LOGE("Invalid parameter");
181                 return -1;
182         }
183
184         for (;;) {
185                 mac[i++] = (char) strtoul((char *)txt, (char **)&txt, 16);
186                 if (!*txt++ || i == 6)
187                         break;
188         }
189
190         if (i != WS_MACADDR_LEN)
191                 return -1;
192
193         WDP_LOGD("Converted MAC address [" MACSECSTR "]", MAC2SECSTR(mac));
194         return 0;
195 }
196
197 static int __ws_mac_compact_to_normal(char *compact, unsigned char *mac)
198 {
199         g_snprintf((char *)mac, OEM_MACSTR_LEN, "%c%c:%c%c:%c%c:%c%c:%c%c:%c%c",
200                         compact[0], compact[1], compact[2], compact[3],
201                         compact[4], compact[5], compact[6], compact[7],
202                         compact[8], compact[9], compact[10], compact[11]);
203         return 0;
204 }
205
206 static char *__ws_wps_to_txt(int wps_mode)
207 {
208         switch (wps_mode) {
209         case WFD_OEM_WPS_MODE_PBC:
210                 return WS_DBUS_STR_PBC;
211                 break;
212         case WFD_OEM_WPS_MODE_DISPLAY:
213                 return WS_DBUS_STR_DISPLAY;
214                 break;
215         case WFD_OEM_WPS_MODE_KEYPAD:
216                 return WS_DBUS_STR_KEYPAD;
217                 break;
218 #if defined(TIZEN_FEATURE_ASP)
219         case WFD_OEM_WPS_MODE_NONE:
220         case WFD_OEM_WPS_MODE_P2PS:
221                 return WS_DBUS_STR_P2PS;
222 #endif /* TIZEN_FEATURE_ASP */
223         default:
224                 return "";
225                 break;
226         }
227 }
228 #ifdef TIZEN_FEATURE_SERVICE_DISCOVERY
229 static int __ws_byte_to_hex(char *buf, int buf_size, unsigned char *data, int data_len)
230 {
231         int i;
232         char *pos = buf;
233         char *end = buf + buf_size;
234         int ret;
235         if (buf_size == 0)
236                 return 0;
237         for (i = 0; i < data_len; i++) {
238                 ret = snprintf(pos, end - pos, "%02x", data[i]);
239                 if (ret < 0 || ret >= end - pos) {
240                         end[-1] = '\0';
241                         return pos - buf;
242                 }
243                 pos += ret;
244         }
245         end[-1] = '\0';
246         return pos - buf;
247 }
248
249 static int __ws_hex_to_num(char *src, int len)
250 {
251         char *temp = NULL;
252         int num = 0;
253
254         if (!src || len < 0) {
255                 WDP_LOGE("Invalid parameter");
256                 return -1;
257         }
258
259         temp = (char*) g_try_malloc0(len+1);
260         if (!temp) {
261                 WDP_LOGE("Failed to allocate memory");
262                 return -1;
263         }
264
265         memcpy(temp, src, len);
266         num = strtoul(temp, NULL, 16);
267         g_free(temp);
268
269         return num;
270 }
271
272 static int __ws_segment_to_service(char *segment, wfd_oem_new_service_s **service)
273 {
274         wfd_oem_new_service_s *serv_tmp = NULL;
275         char *ptr = NULL;
276         char *temp = NULL;
277         int len = 0;
278         int i = 0;
279
280         if (!segment || !service) {
281                 WDP_LOGE("Invalid parameter");
282                 return -1;
283         }
284
285         ptr = segment;
286         WDP_LOGD("Segment: %s", segment);
287
288         serv_tmp = (wfd_oem_new_service_s*) g_try_malloc0(sizeof(wfd_oem_new_service_s));
289         if (!serv_tmp) {
290                 WDP_LOGE("Failed to allocate memory for service");
291                 return -1;
292         }
293
294         serv_tmp->protocol = __ws_hex_to_num(ptr, 2);
295         serv_tmp->trans_id = __ws_hex_to_num(ptr+2, 2);
296         serv_tmp->status = __ws_hex_to_num(ptr+4, 2);
297         ptr += 6;
298         WDP_LOGD("Protocol[%d], Transaction ID[%d], Status[%d]", serv_tmp->protocol, serv_tmp->trans_id, serv_tmp->status);
299
300         if (serv_tmp->status != 0) {
301                 WDP_LOGE("Service status is not success");
302                 free(serv_tmp);
303                 return -1;
304         }
305
306         if (serv_tmp->protocol == WFD_OEM_SERVICE_TYPE_BONJOUR) {
307                 WDP_LOGD("===== Bonjour service =====");
308                 char compr[5] = {0, };
309                 char query[256] = {0, };
310                 char rdata[256] = {0, };
311                 int dns_type = 0;
312
313                 while (*ptr != 0 && strncmp(ptr, "c0", 2)) {
314                         len = __ws_hex_to_num(ptr, 2);
315                         ptr += 2;
316                         if (len && len <= 0xff) {
317                                 temp = (char*) calloc(1, len+2);
318                                 if (temp) {
319                                         temp[0] = '.';
320                                         for (i = 0; i < len; i++) {
321                                                 temp[i+1] = (char) __ws_hex_to_num(ptr, 2);
322                                                 ptr += 2;
323                                         }
324                                         strncat(query, temp, len+1);
325                                         g_free(temp);
326                                         temp = NULL;
327                                 }
328                         }
329                 }
330
331                 if (!strncmp(ptr, "c0", 2)) {
332                         memcpy(compr, ptr, 4);
333                         ptr += 2;
334
335                         if (!strncmp(ptr, "27", 2)) {
336                                 WDP_LOGD("Segment ended");
337                                 ptr += 2;
338                         } else {
339                                 ptr += 2;
340                                 dns_type = __ws_hex_to_num(ptr, 4);
341                                 ptr += 6;
342                                 if (dns_type == 12) {
343                                         if (!strncmp(compr, "c011", 4))
344                                                 strncat(query, ".local.", 7);
345                                         else if (!strncmp(compr, "c00c", 4))
346                                                 strncat(query, "._tcp.local.", 12);
347                                         else if (!strncmp(compr, "c01c", 4))
348                                                 strncat(query, "._udp.local.", 12);
349                                 }
350                         }
351                 }
352                 serv_tmp->data.bonjour.query = strdup(query + 1);
353                 while (*ptr != 0 && strncmp(ptr, "c0", 2)) {
354                         len = __ws_hex_to_num(ptr, 2);
355                         ptr += 2;
356                         if (len && len <= 0xff) {
357                                 temp = (char*) g_try_malloc0(len+2);
358                                 if (temp) {
359                                         temp[0] = '.';
360                                         for (i = 0; i < len; i++) {
361                                                 temp[i+1] = (char) __ws_hex_to_num(ptr, 2);
362                                                 ptr += 2;
363                                         }
364                                         strncat(rdata, temp, len+1);
365                                         g_free(temp);
366                                         temp = NULL;
367                                 }
368                         }
369                 }
370                 serv_tmp->data.bonjour.rdata = strdup(rdata + 1);
371
372                 WDP_LOGD("Query: %s", serv_tmp->data.bonjour.query);
373                 WDP_LOGD("RData: %s", serv_tmp->data.bonjour.rdata);
374         } else {
375                 WDP_LOGE("Not supported yet. Only bonjour service supproted [%d]",
376                                         serv_tmp->protocol);
377                 g_free(serv_tmp);
378                 return -1;
379         }
380
381         *service = serv_tmp;
382
383         return 0;
384 }
385 #endif /* TIZEN_FEATURE_SERVICE_DISCOVERY */
386
387 static void __ws_path_to_addr(char *peer_path,
388                 unsigned char *dev_addr, GVariant *parameter)
389 {
390         __WDP_LOG_FUNC_ENTER__;
391
392         static unsigned char peer_dev[WS_MACSTR_LEN] = {'\0',};
393         const char *path = NULL;
394         char *loc = NULL;
395
396         g_variant_get(parameter, "(&o)", &path);
397         g_strlcpy(peer_path, path, DBUS_OBJECT_PATH_MAX);
398         WDP_LOGD("Retrive Added path [%s]", peer_path);
399
400         loc = strrchr(peer_path,'/');
401         if(loc != NULL)
402                 __ws_mac_compact_to_normal(loc + 1, peer_dev);
403
404         __ws_txt_to_mac(peer_dev, dev_addr);
405         WDP_LOGD("peer mac [" MACSTR "]", MAC2STR(dev_addr));
406
407         __WDP_LOG_FUNC_EXIT__;
408         return;
409 }
410
411 static int __ws_unpack_ay(unsigned char *dst, GVariant *src, int size)
412 {
413         GVariantIter *iter = NULL;
414         int length = 0;
415         int res = 1;
416
417         if (!dst || !src || size == 0) {
418                 WDP_LOGE("Invalid parameter");
419                 return -1;
420         }
421         g_variant_get(src, "ay", &iter);
422         if (iter == NULL) {
423                 WDP_LOGE("failed to get iterator");
424                 return -1;
425         }
426
427         while (g_variant_iter_loop (iter, "y", &dst[length])) {
428                 length++;
429                 if(length >= size)
430                         break;
431         }
432         g_variant_iter_free(iter);
433
434         if (length < size) {
435                 WDP_LOGE("array is shorter than size");
436                 res = -1;
437         }
438
439         return res;
440 }
441
442 #ifdef TIZEN_FEATURE_WIFI_DISPLAY
443 static int __parsing_wfd_info(unsigned char *wfd_dev_info,
444                 wfd_oem_display_s *display )
445 {
446         __WDP_LOG_FUNC_ENTER__;
447
448         int wfd_info = 0;
449         if (!wfd_dev_info || !display) {
450                 WDP_LOGE("Invalid parameter");
451                 __WDP_LOG_FUNC_EXIT__;
452                 return -1;
453         }
454
455         wfd_info = (wfd_dev_info[3]<<8 | wfd_dev_info[4]);
456
457         if (wfd_info & WS_WFD_INFO_PRIMARY_SINK)
458                 display->type |= WS_WFD_INFO_PRIMARY_SINK;
459         if (wfd_info & WS_WFD_INFO_SECONDARY_SINK)
460                 display->type |= WS_WFD_INFO_SECONDARY_SINK;
461
462         display->availability = (wfd_info & WS_WFD_INFO_AVAILABILITY) >> 4;
463         display->hdcp_support = (wfd_info & WS_WFD_INFO_HDCP_SUPPORT) >> 8;
464
465         display->port = (wfd_dev_info[5]<<8 | wfd_dev_info[6]);
466         display->max_tput = (wfd_dev_info[7]<<8 | wfd_dev_info[8]);
467
468         WDP_LOGD("type [%d],availability [%d],hdcp_support [%d],ctrl_port [%d] "
469                         "max_tput[%d]", display->type, display->availability,
470                         display->hdcp_support, display->port,display->max_tput);
471
472         __WDP_LOG_FUNC_EXIT__;
473         return 0;
474 }
475 #endif /* TIZEN_FEATURE_WIFI_DISPLAY */
476
477 static int _ws_get_local_dev_mac(unsigned char *dev_mac)
478 {
479         __WDP_LOG_FUNC_ENTER__;
480         FILE *fd = NULL;
481         const char *file_path = DEFAULT_MAC_FILE_PATH;
482         char local_mac[OEM_MACSTR_LEN] = {0, };
483         char *ptr = NULL;
484         int res = 0;
485
486         errno = 0;
487         fd = fopen(file_path, "r");
488         if (!fd) {
489                 WDP_LOGE("Failed to open MAC info file [%s] (%s)",file_path, strerror(errno));
490                 __WDP_LOG_FUNC_EXIT__;
491                 return -1;
492         }
493
494         errno = 0;
495         ptr = fgets((char *)local_mac, WS_MACSTR_LEN, fd);
496         if (!ptr) {
497                 WDP_LOGE("Failed to read file or no data read(%s)", strerror(errno));
498                 fclose(fd);
499                 __WDP_LOG_FUNC_EXIT__;
500                 return -1;
501         }
502         WDP_SECLOGD("Local MAC address [%s]", ptr);
503         WDP_SECLOGD("Local MAC address [%s]", local_mac);
504
505         res = __ws_txt_to_mac((unsigned char *)local_mac, dev_mac);
506         if (res < 0) {
507                 WDP_LOGE("Failed to convert text to MAC address");
508                 fclose(fd);
509                 __WDP_LOG_FUNC_EXIT__;
510                 return -1;
511         }
512
513         WDP_LOGD("Local Device MAC address [" MACSECSTR "]", MAC2SECSTR(dev_mac));
514
515         fclose(fd);
516         __WDP_LOG_FUNC_EXIT__;
517         return 0;
518 }
519
520 static void _supplicant_signal_cb(GDBusConnection *connection,
521                 const gchar *sender, const gchar *object_path, const gchar *interface,
522                 const gchar *signal, GVariant *parameters, gpointer user_data)
523 {
524 #if defined (TIZEN_DEBUG_DBUS_VALUE)
525         DEBUG_SIGNAL(sender, object_path, interface, signal, parameters);
526 #endif /* TIZEN_DEBUG_DBUS_VALUE */
527
528         if (!g_pd) {
529                 WDP_LOGE("ws_dbus_plugin_data_s is not created yet");
530                 return;
531         }
532
533         if (!g_strcmp0(signal,"InterfaceAdded")) {
534                 WDP_LOGD("InterfaceAdded");
535
536         } else if (!g_strcmp0(signal,"InterfaceRemoved")) {
537                 WDP_LOGD("InterfaceRemoved");
538                 static char interface_path[DBUS_OBJECT_PATH_MAX] = {'\0',};
539                 const char *path = NULL;
540
541                 g_variant_get(parameters, "(&o)", &path);
542                 g_strlcpy(interface_path, path, DBUS_OBJECT_PATH_MAX);
543
544                 WDP_LOGD("Retrive removed path [%s]", interface_path);
545
546                 if (!g_strcmp0(g_pd->group_iface_path, interface_path)) {
547
548                         WDP_LOGD("p2p group interface removed");
549                         memset(g_pd->group_iface_path, 0x0, DBUS_OBJECT_PATH_MAX);
550                 }
551 #if defined(TIZEN_WLAN_CONCURRENT_ENABLE) && defined(TIZEN_MOBILE)
552                 else if (!g_strcmp0(g_pd->iface_path, interface_path)) {
553
554                         WDP_LOGD("p2p interface removed");
555                         wfd_oem_event_s event;
556
557                         ws_deactivate(1);
558
559                         memset(&event, 0x0, sizeof(wfd_oem_event_s));
560                         event.event_id = WFD_OEM_EVENT_DEACTIVATED;
561                         g_pd->callback(g_pd->user_data, &event);
562
563                         memset(g_pd->iface_path, 0x0, DBUS_OBJECT_PATH_MAX);
564                 }
565 #endif /* TIZEN_WLAN_CONCURRENT_ENABLE && TIZEN_MOBILE */
566         } else if(!g_strcmp0(signal,"PropertiesChanged")){
567                 WDP_LOGD("PropertiesChanged");
568         }
569 }
570
571 static void __ws_get_peer_property(const char *key, GVariant *value, void *user_data)
572 {
573         __WDP_LOG_FUNC_ENTER__;
574
575         wfd_oem_device_s *peer = (wfd_oem_device_s *)user_data;
576         if(!peer) {
577                 __WDP_LOG_FUNC_EXIT__;
578                 return;
579         }
580 #if defined (TIZEN_DEBUG_DBUS_VALUE)
581         CHECK_KEY_VALUE(key, value);
582 #endif /* TIZEN_DEBUG_DBUS_VALUE */
583
584         if (g_strcmp0(key, "DeviceName") == 0) {
585                 const char *name = NULL;
586
587                 g_variant_get(value, "&s", &name);
588                 g_strlcpy(peer->dev_name, name, WS_SSID_LEN);
589                 WDP_LOGD("Device name [%s]", peer->dev_name);
590
591         } else if (g_strcmp0(key, "config_method") == 0) {
592                 int config_methods = 0;
593                 g_variant_get(value, "q", &config_methods);
594
595                 if (config_methods & WS_CONFIG_METHOD_DISPLAY)
596                         peer->config_methods |= WFD_OEM_WPS_MODE_DISPLAY;
597                 if (config_methods & WS_CONFIG_METHOD_PUSHBUTTON)
598                         peer->config_methods |= WFD_OEM_WPS_MODE_PBC;
599                 if (config_methods & WS_CONFIG_METHOD_KEYPAD)
600                         peer->config_methods |= WFD_OEM_WPS_MODE_KEYPAD;
601                 WDP_LOGD("Config method [0x%x]", peer->config_methods);
602
603         } else if (g_strcmp0(key, "level") == 0) {
604
605         } else if (g_strcmp0(key, "devicecapability") == 0) {
606                 unsigned char devicecapability = 0;
607
608                 g_variant_get(value, "y", &devicecapability);
609                 peer->dev_flags = (int)devicecapability;
610                 WDP_LOGD("Device Capa [0x%02x]", peer->dev_flags);
611
612         } else if (g_strcmp0(key, "groupcapability") == 0) {
613                 unsigned char groupcapability = 0;
614
615                 g_variant_get(value, "y", &groupcapability);
616                 WDP_LOGD("Group Capa [0x%02x]", groupcapability);
617                 if (groupcapability & WS_GROUP_CAP_GROUP_OWNER) {
618                         peer->group_flags = WFD_OEM_GROUP_FLAG_GROUP_OWNER;
619                         peer->dev_role = WFD_OEM_DEV_ROLE_GO;
620                 }
621                 if (groupcapability & WS_GROUP_CAP_PERSISTENT_GROUP)
622                         peer->group_flags = WFD_OEM_GROUP_FLAG_PERSISTENT_GROUP;
623
624         } else if (g_strcmp0(key, "PrimaryDeviceType") == 0) {
625                 unsigned char primarydevicetype[WS_DEVTYPE_LEN] = {0,};
626
627                 if(__ws_unpack_ay(primarydevicetype, value, WS_DEVTYPE_LEN)) {
628                         peer->pri_dev_type = primarydevicetype[1];
629                         peer->sec_dev_type = primarydevicetype[WS_DEVTYPE_LEN -1];
630                 }
631         } else if (g_strcmp0(key, "SecondaryDeviceTypes") == 0) {
632         } else if (g_strcmp0(key, "VendorExtension") == 0) {
633 #ifdef TIZEN_FEATURE_WIFI_DISPLAY
634         } else if (g_strcmp0(key, "IEs") == 0) {
635                 unsigned char ies[WFD_SUBELEM_LEN_DEV_INFO + 3] = {0,};
636
637                 if(__ws_unpack_ay(ies, value, WFD_SUBELEM_LEN_DEV_INFO + 3))
638                         __parsing_wfd_info(ies, &(peer->display));
639 #endif /* TIZEN_FEATURE_WIFI_DISPLAY */
640         } else if (g_strcmp0(key, "DeviceAddress") == 0) {
641
642                 if (__ws_unpack_ay(peer->dev_addr, value, WS_MACADDR_LEN))
643                         WDP_LOGD("Device address [" MACSTR "]", MAC2STR(peer->dev_addr));
644
645         } else if (g_strcmp0(key, "InterfaceAddress") == 0) {
646
647                 if (__ws_unpack_ay(peer->intf_addr, value, WS_MACADDR_LEN))
648                         WDP_LOGD("Interface address [" MACSTR "]", MAC2STR(peer->intf_addr));
649
650         } else if (g_strcmp0(key, "GODeviceAddress") == 0) {
651
652                 if (__ws_unpack_ay(peer->go_dev_addr, value, WS_MACADDR_LEN))
653                         WDP_LOGD("GODevice address [" MACSTR "]", MAC2STR(peer->go_dev_addr));
654
655                 if(!ISZEROMACADDR(peer->go_dev_addr))
656                         peer->dev_role = WFD_OEM_DEV_ROLE_GC;
657         } else {
658                 WDP_LOGD("Unknown value");
659         }
660         __WDP_LOG_FUNC_EXIT__;
661         return;
662 }
663
664 static void __ws_peer_property(const char *key, GVariant *value, void *user_data)
665 {
666         __WDP_LOG_FUNC_ENTER__;
667         if(!user_data) {
668                 __WDP_LOG_FUNC_EXIT__;
669                 return;
670         }
671
672         wfd_oem_dev_data_s *peer = (wfd_oem_dev_data_s *)user_data;
673 #if defined (TIZEN_DEBUG_DBUS_VALUE)
674         CHECK_KEY_VALUE(key, value);
675 #endif /* TIZEN_DEBUG_DBUS_VALUE */
676         if (g_strcmp0(key, "DeviceName") == 0) {
677                 const char *name = NULL;
678
679                 g_variant_get(value, "&s", &name);
680                 g_strlcpy(peer->name, name, WS_SSID_LEN);
681                 WDP_LOGD("Device Name [%s]", peer->name);
682
683         } else if (g_strcmp0(key, "config_method") == 0) {
684                 int config_methods = 0;
685
686                 g_variant_get(value, "q", &config_methods);
687
688                 if (config_methods & WS_CONFIG_METHOD_DISPLAY)
689                         peer->config_methods |= WFD_OEM_WPS_MODE_DISPLAY;
690                 if (config_methods & WS_CONFIG_METHOD_PUSHBUTTON)
691                         peer->config_methods |= WFD_OEM_WPS_MODE_PBC;
692                 if (config_methods & WS_CONFIG_METHOD_KEYPAD)
693                         peer->config_methods |= WFD_OEM_WPS_MODE_KEYPAD;
694                 WDP_LOGD("Config method [0x%x]", peer->config_methods);
695
696         } else if (g_strcmp0(key, "level") == 0) {
697
698         } else if (g_strcmp0(key, "devicecapability") == 0) {
699                 unsigned char devicecapability = 0;
700
701                 g_variant_get(value, "y", &devicecapability);
702                 peer->dev_flags = (int)devicecapability;
703                 WDP_LOGD("Device Capa [0x%02x]", peer->dev_flags);
704
705         } else if (g_strcmp0(key, "groupcapability") == 0) {
706                 unsigned char groupcapability = 0;
707
708                 g_variant_get(value, "y", &groupcapability);
709                 WDP_LOGD("Group Capa [0x%02x]", groupcapability);
710                 if (groupcapability & WS_GROUP_CAP_GROUP_OWNER) {
711                         peer->group_flags = WFD_OEM_GROUP_FLAG_GROUP_OWNER;
712                         peer->dev_role = WFD_OEM_DEV_ROLE_GO;
713                 }
714                 if (groupcapability & WS_GROUP_CAP_PERSISTENT_GROUP)
715                         peer->group_flags = WFD_OEM_GROUP_FLAG_PERSISTENT_GROUP;
716
717         } else if (g_strcmp0(key, "PrimaryDeviceType") == 0) {
718                 unsigned char primarydevicetype[WS_DEVTYPE_LEN] = {0,};
719
720                 if (__ws_unpack_ay(primarydevicetype, value, WS_DEVTYPE_LEN)) {
721                         peer->pri_dev_type = primarydevicetype[1];
722                         peer->sec_dev_type = primarydevicetype[WS_DEVTYPE_LEN -1];
723                 }
724         } else if (g_strcmp0(key, "SecondaryDeviceTypes") == 0) {
725         } else if (g_strcmp0(key, "VendorExtension") == 0) {
726 #ifdef TIZEN_FEATURE_WIFI_DISPLAY
727         } else if (g_strcmp0(key, "IEs") == 0) {
728                 unsigned char ies[WFD_SUBELEM_LEN_DEV_INFO + 3] = {0,};
729
730                 if(__ws_unpack_ay(ies, value, WFD_SUBELEM_LEN_DEV_INFO + 3))
731                         __parsing_wfd_info(ies, &(peer->display));
732 #endif /* TIZEN_FEATURE_WIFI_DISPLAY */
733         } else if (g_strcmp0(key, "DeviceAddress") == 0) {
734
735                 if (__ws_unpack_ay(peer->p2p_dev_addr, value, WS_MACADDR_LEN))
736                         WDP_LOGD("Device address [" MACSTR "]", MAC2STR(peer->p2p_dev_addr));
737
738         } else if (g_strcmp0(key, "InterfaceAddress") == 0) {
739
740                 if (__ws_unpack_ay(peer->p2p_intf_addr, value, WS_MACADDR_LEN))
741                         WDP_LOGD("Interface Address [" MACSTR "]", MAC2STR(peer->p2p_intf_addr));
742
743         } else if (g_strcmp0(key, "GODeviceAddress") == 0) {
744
745                 unsigned char go_dev_addr[OEM_MACADDR_LEN] = {0,};
746                 if (__ws_unpack_ay(go_dev_addr, value, WS_MACADDR_LEN))
747                         WDP_LOGD("[" MACSTR "]", MAC2STR(go_dev_addr));
748
749                 if(!ISZEROMACADDR(go_dev_addr))
750                         peer->dev_role = WFD_OEM_DEV_ROLE_GC;
751 #if defined(TIZEN_FEATURE_ASP)
752         } else if (g_strcmp0(key, "AdvertiseService") == 0) {
753                 WDP_LOGD("size [%d]", g_variant_get_size(value));
754                 if (g_variant_get_size(value) != 0) {
755                         peer->has_asp_services = 1;
756                 } else {
757                         peer->has_asp_services = 0;
758                 }
759 #endif /* TIZEN_FEATURE_ASP */
760         } else {
761                 WDP_LOGD("Unknown value");
762         }
763         __WDP_LOG_FUNC_EXIT__;
764         return;
765 }
766
767 void __ws_interface_property(const char *key, GVariant *value, void *user_data)
768 {
769         __WDP_LOG_FUNC_ENTER__;
770         wfd_oem_event_s *event = (wfd_oem_event_s *)user_data;
771         if(!event)
772                 return;
773 #if defined (TIZEN_DEBUG_DBUS_VALUE)
774         CHECK_KEY_VALUE(key, value);
775 #endif /* TIZEN_DEBUG_DBUS_VALUE */
776         if (g_strcmp0(key, "Ifname") == 0) {
777                 const char *ifname = NULL;
778
779                 g_variant_get(value, "&s", &ifname);
780                 g_strlcpy(event->ifname, ifname, OEM_IFACE_NAME_LEN+1);
781                 WDP_LOGD("Ifname [%s]", event->ifname);
782
783         }
784         __WDP_LOG_FUNC_EXIT__;
785         return;
786 }
787
788 void __ws_group_property(const char *key, GVariant *value, void *user_data)
789 {
790         __WDP_LOG_FUNC_ENTER__;
791         wfd_oem_event_s *event = (wfd_oem_event_s *)user_data;
792         if(!event || !event->edata)
793                 return;
794
795         wfd_oem_group_data_s *group = (wfd_oem_group_data_s *)event->edata;
796 #if defined (TIZEN_DEBUG_DBUS_VALUE)
797         CHECK_KEY_VALUE(key, value);
798 #endif /* TIZEN_DEBUG_DBUS_VALUE */
799         if (g_strcmp0(key, "Role") == 0) {
800                 const char *role = NULL;
801
802                 g_variant_get(value, "&s", &role);
803                 WDP_LOGD("Role [%s]", role);
804
805                 if (!strncmp(role, "GO", 2))
806                         event->dev_role = WFD_OEM_DEV_ROLE_GO;
807                 else if (!strncmp(role, "client", 6))
808                         event->dev_role = WFD_OEM_DEV_ROLE_GC;
809
810         } else if (g_strcmp0(key, "Frequency") == 0) {
811                 int frequency = 0;
812
813                 g_variant_get(value, "q", &frequency);
814                 group->freq = (int)frequency;
815
816         } else if (g_strcmp0(key, "Passphrase") == 0) {
817                 const char *passphrase = NULL;
818
819                 g_variant_get(value, "&s", &passphrase);
820                 g_strlcpy(group->pass, passphrase, OEM_PASS_PHRASE_LEN+1);
821                 WDP_LOGD("passphrase [%s]", group->pass);
822
823         } else if (g_strcmp0(key, "Group") == 0) {
824
825         } else if (g_strcmp0(key, "SSID") == 0) {
826                 unsigned char ssid[WS_SSID_LEN +1] = {0,};
827
828                 __ws_unpack_ay(ssid, value, WS_SSID_LEN);
829                 memcpy(group->ssid, ssid, WS_SSID_LEN+1);
830                 WDP_LOGD("ssid [%s]", group->ssid);
831
832         } else if (g_strcmp0(key, "BSSID") == 0) {
833
834                 if (__ws_unpack_ay(group->go_dev_addr, value, WS_MACADDR_LEN))
835                         WDP_LOGD("[" MACSTR "]", MAC2STR(group->go_dev_addr));
836
837         } else {
838                 WDP_LOGD("Unknown value");
839         }
840         __WDP_LOG_FUNC_EXIT__;
841         return;
842 }
843
844 void __ws_extract_invitation_details(const char *key, GVariant *value, void *user_data)
845 {
846         __WDP_LOG_FUNC_ENTER__;
847         wfd_oem_event_s *event = (wfd_oem_event_s *)user_data;
848         if(!event || !event->edata)
849                 return;
850
851         wfd_oem_invite_data_s *invitation = (wfd_oem_invite_data_s *)event->edata;
852 #if defined (TIZEN_DEBUG_DBUS_VALUE)
853         CHECK_KEY_VALUE(key, value);
854 #endif /* TIZEN_DEBUG_DBUS_VALUE */
855         if (g_strcmp0(key, "sa") == 0) {
856                 if (__ws_unpack_ay(invitation->sa, value, WS_MACADDR_LEN))
857                         WDP_LOGD("SA [" MACSTR "]", MAC2STR(invitation->sa));
858
859         } else if (g_strcmp0(key, "go_dev_addr") == 0) {
860                 if (__ws_unpack_ay(invitation->go_dev_addr, value, WS_MACADDR_LEN))
861                                         WDP_LOGD("GO device address [" MACSTR "]", MAC2STR(invitation->go_dev_addr));
862
863         } else if (g_strcmp0(key, "bssid") == 0) {
864                 if (__ws_unpack_ay(invitation->bssid, value, WS_MACADDR_LEN))
865                                         WDP_LOGD("BSSID [" MACSTR "]", MAC2STR(invitation->bssid));
866
867         } else if (g_strcmp0(key, "persistent_id") == 0) {
868                 g_variant_get(value, "i", &(invitation->persistent_id));
869                 WDP_LOGD("persistent id [%d]", invitation->persistent_id);
870
871         } else if (g_strcmp0(key, "op_freq") == 0) {
872                 g_variant_get(value, "i", &(invitation->oper_freq));
873                 WDP_LOGD("op freq [%d]", invitation->oper_freq);
874         } else {
875                 WDP_LOGD("Unknown value");
876         }
877         __WDP_LOG_FUNC_EXIT__;
878         return;
879 }
880
881 void __ws_extract_group_details(const char *key, GVariant *value, void *user_data)
882 {
883         __WDP_LOG_FUNC_ENTER__;
884         wfd_oem_event_s *event = (wfd_oem_event_s *)user_data;
885         if(!event || !event->edata)
886                 return;
887
888         if (!g_pd) {
889                 WDP_LOGE("ws_dbus_plugin_data_s is not created yet");
890                 return;
891         }
892
893 #ifdef TIZEN_FEATURE_IP_OVER_EAPOL
894         wfd_oem_group_data_s *group = (wfd_oem_group_data_s *)event->edata;
895 #endif /* TIZEN_FEATURE_IP_OVER_EAPOL */
896 #if defined (TIZEN_DEBUG_DBUS_VALUE)
897         CHECK_KEY_VALUE(key, value);
898 #endif /* TIZEN_DEBUG_DBUS_VALUE */
899         if (g_strcmp0(key, "interface_object") == 0) {
900                 static char interface_path[DBUS_OBJECT_PATH_MAX] = {'\0',};
901                 const char *i_path = NULL;
902
903                 g_variant_get(value, "&o", &i_path);
904                 g_strlcpy(interface_path, i_path, DBUS_OBJECT_PATH_MAX);
905                 WDP_LOGD("Retrive Added path [%s]", interface_path);
906                 g_strlcpy(g_pd->group_iface_path, interface_path, DBUS_OBJECT_PATH_MAX);
907                 dbus_property_get_all(interface_path, g_pd->g_dbus,
908                                 SUPPLICANT_IFACE, __ws_interface_property, event);
909
910         } else if (g_strcmp0(key, "role") == 0) {
911                 const char *role = NULL;
912
913                 g_variant_get(value, "&s", &role);
914                 WDP_LOGD("Role [%s]", role);
915
916                 if (!strncmp(role, "GO", 2))
917                         event->dev_role = WFD_OEM_DEV_ROLE_GO;
918                 else if (!strncmp(role, "client", 6))
919                         event->dev_role = WFD_OEM_DEV_ROLE_GC;
920 #ifdef TIZEN_FEATURE_IP_OVER_EAPOL
921         } else if (g_strcmp0(key, "IpAddr") == 0) {
922
923                 if (__ws_unpack_ay(group->ip_addr, value, OEM_IPADDR_LEN))
924                         WDP_LOGD("IP address [" IPSTR "]", IP2STR(group->ip_addr));
925
926         } else if (g_strcmp0(key, "IpAddrMask") == 0) {
927
928                 if (__ws_unpack_ay(group->ip_addr_mask, value, OEM_IPADDR_LEN))
929                         WDP_LOGD("IP mask [" IPSTR "]", IP2STR(group->ip_addr_mask));
930
931         } else if (g_strcmp0(key, "IpAddrGo") == 0) {
932
933                 if (__ws_unpack_ay(group->ip_addr_go, value, OEM_IPADDR_LEN))
934                         WDP_LOGD("GO IP address [" IPSTR "]", IP2STR(group->ip_addr_go));
935 #endif /* TIZEN_FEATURE_IP_OVER_EAPOL */
936         } else if (g_strcmp0(key, "group_object") == 0) {
937                 static char group_path[DBUS_OBJECT_PATH_MAX] = {'\0',};
938                 const char *g_path;
939
940                 g_variant_get(value, "&o", &g_path);
941                 g_strlcpy(group_path, g_path, DBUS_OBJECT_PATH_MAX);
942                 WDP_LOGD("Retrive group path [%s]", group_path);
943                 dbus_property_get_all(group_path, g_pd->g_dbus, SUPPLICANT_P2P_GROUP,
944                                 __ws_group_property, event);
945
946                 g_pd->group_sub_id =
947                         g_dbus_connection_signal_subscribe(
948                                 g_pd->g_dbus,
949                                 SUPPLICANT_SERVICE, /* bus name */
950                                 SUPPLICANT_P2P_GROUP, /* interface */
951                                 NULL, /* member */
952                                 group_path, /* object path */
953                                 NULL, /* arg0 */
954                                 G_DBUS_SIGNAL_FLAGS_NONE,
955                                 _group_signal_cb,
956                                 NULL, NULL);
957         }
958         __WDP_LOG_FUNC_EXIT__;
959         return;
960 }
961
962 void __ws_extract_gonegfailaure_details(const char *key, GVariant *value, void *user_data)
963 {
964         __WDP_LOG_FUNC_ENTER__;
965         wfd_oem_event_s *event = (wfd_oem_event_s *)user_data;
966         if(!event || !event->edata)
967                 return;
968
969         wfd_oem_conn_data_s *conn = (wfd_oem_conn_data_s *)event->edata;
970 #if defined (TIZEN_DEBUG_DBUS_VALUE)
971         CHECK_KEY_VALUE(key, value);
972 #endif /* TIZEN_DEBUG_DBUS_VALUE */
973         if (g_strcmp0(key, "peer_object") == 0) {
974                 static char peer_path[DBUS_OBJECT_PATH_MAX] = {'\0',};
975                 const char *path;
976
977                 g_variant_get(value, "&o", &path);
978                 g_strlcpy(peer_path, path, DBUS_OBJECT_PATH_MAX);
979                 WDP_LOGD("Retrive peer path [%s]", peer_path);
980
981         } else if (g_strcmp0(key, "status") == 0) {
982                 int status = 0;
983
984                 g_variant_get(value, "i", &status);
985                 WDP_LOGD("Retrive status [%d]", status);
986                 conn->status = status;
987         }
988         __WDP_LOG_FUNC_EXIT__;
989         return;
990 }
991
992 void __ws_extract_gonegsuccess_details(const char *key, GVariant *value, void *user_data)
993 {
994         __WDP_LOG_FUNC_ENTER__;
995         wfd_oem_event_s *event = (wfd_oem_event_s *)user_data;
996         if(!event || !event->edata)
997                 return;
998
999         wfd_oem_conn_data_s *edata = (wfd_oem_conn_data_s *)event->edata;
1000 #if defined (TIZEN_DEBUG_DBUS_VALUE)
1001         CHECK_KEY_VALUE(key, value);
1002 #endif /* TIZEN_DEBUG_DBUS_VALUE */
1003         if (g_strcmp0(key, "peer_object") == 0) {
1004
1005         } else if (g_strcmp0(key, "status") == 0) {
1006
1007         } else if (g_strcmp0(key, "passphrase") == 0) {
1008
1009         } else if (g_strcmp0(key, "role_go") == 0) {
1010                 //local device role
1011                 const char *role = NULL;
1012
1013                 g_variant_get(value, "&s", &role);
1014                 if (!strncmp(role, "GO", 2))
1015                         event->dev_role = WFD_OEM_DEV_ROLE_GO;
1016                 else if (!strncmp(role, "client", 6))
1017                         event->dev_role = WFD_OEM_DEV_ROLE_GC;
1018
1019         } else if (g_strcmp0(key, "ssid") == 0) {
1020                 unsigned char ssid[WS_SSID_LEN +1] = {0,};
1021
1022                 __ws_unpack_ay(ssid, value, WS_SSID_LEN);
1023                 memcpy(edata->ssid, ssid, WS_SSID_LEN+1);
1024                 WDP_LOGD("ssid [%s]", edata->ssid);
1025
1026         } else if (g_strcmp0(key, "peer_device_addr") == 0) {
1027
1028                 if(__ws_unpack_ay(edata->peer_device_addr, value, WS_MACADDR_LEN))
1029                         WDP_LOGD("Device address[" MACSTR "]", MAC2STR(edata->peer_device_addr));
1030
1031         } else if(g_strcmp0(key, "peer_interface_addr") == 0) {
1032
1033                 if(__ws_unpack_ay(edata->peer_intf_addr, value, WS_MACADDR_LEN))
1034                         WDP_LOGD("Interface address [" MACSTR "]", MAC2STR(edata->peer_intf_addr));
1035
1036         } else if (g_strcmp0(key, "wps_method") == 0) {
1037
1038         } else if (g_strcmp0(key, "frequency_list") == 0) {
1039
1040         } else if (g_strcmp0(key, "persistent_group") == 0) {
1041
1042                 g_variant_get(value, "i", &(edata->persistent_group));
1043                 WDP_LOGD("persistent_group [%d]", edata->persistent_group);
1044
1045         } else if (g_strcmp0(key, "peer_config_timeout") == 0) {
1046
1047         }
1048         __WDP_LOG_FUNC_EXIT__;
1049         return;
1050 }
1051
1052 #ifdef TIZEN_FEATURE_SERVICE_DISCOVERY
1053 void __ws_extract_peer_service(wfd_oem_event_s *data, unsigned char *service_hex, int tlvs_len)
1054 {
1055         GList *services = NULL;
1056         wfd_oem_new_service_s *new_service = NULL;
1057         char *segment = NULL;
1058         int count = 0;
1059         int ptr = 0;
1060         int length = 0;
1061         int res = 0;
1062
1063         while(ptr + 2 < WS_MAX_SERVICE_LEN &&
1064                         (length = (service_hex[ptr+1]*256) + service_hex[ptr]) > 0) {
1065                 segment = (char*) g_try_malloc0(length*2+1);
1066                 if(segment) {
1067                         __ws_byte_to_hex(segment, length * 2 + 1, &service_hex[ptr + 3], length);
1068                         res = __ws_segment_to_service(segment, &new_service);
1069                         if (res < 0) {
1070                                 WDP_LOGE("Failed to convert segment as service instance");
1071                                 g_free(segment);
1072                                 segment = NULL;
1073                                 continue;
1074                         }
1075                         services = g_list_append(services, new_service);
1076                         count++;
1077                         ptr += length + 4;
1078                         g_free(segment);
1079                         segment = NULL;
1080                 }
1081                 data->edata_type = WFD_OEM_EDATA_TYPE_NEW_SERVICE;
1082                 data->dev_role = count;
1083                 data->edata = (void*) services;
1084         }
1085 }
1086
1087 void __ws_extract_servicediscoveryresponse_details(const char *key, GVariant *value, void *user_data)
1088 {
1089         __WDP_LOG_FUNC_ENTER__;
1090         wfd_oem_event_s *event = (wfd_oem_event_s *)user_data;
1091
1092         if(!event)
1093                 return;
1094 #if defined (TIZEN_DEBUG_DBUS_VALUE)
1095         CHECK_KEY_VALUE(key, value);
1096 #endif /* TIZEN_DEBUG_DBUS_VALUE */
1097         if (g_strcmp0(key, "peer_object") == 0) {
1098                 static unsigned char peer_dev[WS_MACSTR_LEN] = {'\0',};
1099                 const char *path = NULL;
1100                 char *loc = NULL;
1101
1102                 g_variant_get(value, "&o", &path);
1103                 if(path == NULL)
1104                         return;
1105
1106                 WDP_LOGD("Retrive Added path [%s]", path);
1107                 loc = strrchr(path,'/');
1108                 if(loc != NULL)
1109                         __ws_mac_compact_to_normal(loc + 1, peer_dev);
1110                 __ws_txt_to_mac(peer_dev, event->dev_addr);
1111
1112         } else if (g_strcmp0(key, "update_indicator")) {
1113
1114         } else if (g_strcmp0(key, "tlvs")) {
1115                 GVariantIter *iter = NULL;
1116                 unsigned char service_hex[WS_MAX_SERVICE_LEN];
1117                 int byte_length = 0;
1118
1119                 g_variant_get(value, "ay", &iter);
1120                 if (iter == NULL) {
1121                         WDP_LOGE("failed to get iterator");
1122                         return;
1123                 }
1124
1125                 memset(service_hex, 0x0, WS_MAX_SERVICE_LEN);
1126                 while (g_variant_iter_loop (iter, "y", &service_hex[byte_length]))
1127                         byte_length++;
1128                 g_variant_iter_free(iter);
1129
1130                 __ws_extract_peer_service(event, service_hex, byte_length);
1131         }
1132
1133         __WDP_LOG_FUNC_EXIT__;
1134 }
1135 #endif /* TIZEN_FEATURE_SERVICE_DISCOVERY */
1136
1137 #if defined(TIZEN_FEATURE_ASP)
1138 static void __ws_extract_serviceaspresponse_details(const char *key, GVariant *value, void *user_data)
1139 {
1140         __WDP_LOG_FUNC_ENTER__;
1141         wfd_oem_event_s *event = (wfd_oem_event_s *)user_data;
1142         if(!event || !event->edata)
1143                 return;
1144
1145         wfd_oem_asp_service_s *service = (wfd_oem_asp_service_s *)event->edata;
1146
1147         if (g_strcmp0(key, "peer_object") == 0) {
1148                 static unsigned char peer_dev[WS_MACSTR_LEN] = {'\0',};
1149                 const char *path = NULL;
1150                 char *loc = NULL;
1151
1152                 g_variant_get(value, "o", &path);
1153                 if(path == NULL)
1154                         return;
1155
1156                 WDP_LOGD("Retrive Added path [%s]", path);
1157                 loc = strrchr(path,'/');
1158                 if(loc != NULL)
1159                         __ws_mac_compact_to_normal(loc + 1, peer_dev);
1160                 __ws_txt_to_mac(peer_dev, event->dev_addr);
1161
1162         } else if (g_strcmp0(key, "srv_trans_id") == 0) {
1163                 unsigned int srv_trans_id = 0;
1164                 g_variant_get(value, "u", &srv_trans_id);
1165                 service->tran_id = srv_trans_id;
1166                 WDP_LOGD("Retrive srv_trans_id [%x]", service->tran_id);
1167
1168         } else if (g_strcmp0(key, "adv_id") == 0) {
1169                 unsigned int adv_id = 0;
1170                 g_variant_get(value, "u", &adv_id);
1171                 service->adv_id = adv_id;
1172                 WDP_LOGD("Retrive adv_id [%x]", service->adv_id);
1173
1174         } else if (g_strcmp0(key, "svc_status") == 0) {
1175                 unsigned char svc_status = 0;
1176                 g_variant_get(value, "u", &svc_status);
1177                 service->status = svc_status;
1178                 WDP_LOGD("Retrive svc_status [%x]", service->status);
1179
1180         } else if (g_strcmp0(key, "config_methods") == 0) {
1181                 unsigned int config_methods = 0;
1182                 g_variant_get(value, "q", &config_methods);
1183                 service->config_method = config_methods;
1184                 WDP_LOGD("Retrive config_methods [%x]", service->config_method);
1185
1186         } else if (g_strcmp0(key, "svc_str") == 0) {
1187                 const char *svc_str = NULL;
1188                 g_variant_get(value, "s", &svc_str);
1189                 if(svc_str != NULL)
1190                         service->service_type = g_strdup(svc_str);
1191                 WDP_LOGD("Retrive srv_name [%s]", service->service_type);
1192
1193         } else if (g_strcmp0(key, "info") == 0) {
1194                 const char *info = NULL;
1195                 g_variant_get(value, "s", &info);
1196                 if(info != NULL)
1197                         service->service_info = g_strdup(info);
1198                 WDP_LOGD("Retrive srv_info [%s]", service->service_info);
1199         }
1200         __WDP_LOG_FUNC_EXIT__;
1201 }
1202
1203 static void __ws_extract_asp_provision_start_details(const char *key, GVariant *value, void *user_data)
1204 {
1205         __WDP_LOG_FUNC_ENTER__;
1206         wfd_oem_event_s *event = (wfd_oem_event_s *)user_data;
1207         wfd_oem_asp_prov_s *asp_params = NULL;
1208         if (!event || !event->edata) {
1209                 __WDP_LOG_FUNC_EXIT__;
1210                 return;
1211         }
1212
1213         asp_params = (wfd_oem_asp_prov_s *)event->edata;
1214
1215         if (g_strcmp0(key, "peer_object") == 0) {
1216                 static unsigned char peer_dev[WS_MACSTR_LEN] = {'\0',};
1217                 const char *path = NULL;
1218                 char *loc = NULL;
1219
1220                 g_variant_get(value, "&o", &path);
1221                 if (path == NULL) {
1222                         __WDP_LOG_FUNC_EXIT__;
1223                         return;
1224                 }
1225
1226                 WDP_LOGD("Retrive Added path [%s]", path);
1227                 loc = strrchr(path,'/');
1228                 if (loc != NULL)
1229                         __ws_mac_compact_to_normal(loc + 1, peer_dev);
1230                 __ws_txt_to_mac(peer_dev, event->dev_addr);
1231
1232         } else if (g_strcmp0(key, "adv_id") == 0) {
1233                 g_variant_get(value, "u", &asp_params->adv_id);
1234                 WDP_LOGD("Retrive adv_id [%u]", asp_params->adv_id);
1235
1236         } else if (g_strcmp0(key, "ses_id") == 0) {
1237                 g_variant_get(value, "u", &asp_params->session_id);
1238                 WDP_LOGD("Retrive session id [%u]", asp_params->session_id);
1239
1240         } else if (g_strcmp0(key, "dev_passwd_id") == 0) {
1241                 g_variant_get(value, "i", &event->wps_mode);
1242                 WDP_LOGD("Retrive dev_passwd_id [%d]", event->wps_mode);
1243
1244         } else if (g_strcmp0(key, "conncap") == 0) {
1245                 g_variant_get(value, "u", &asp_params->network_role);
1246                 WDP_LOGD("Retrive conncap [%x]", asp_params->network_role);
1247
1248         } else if (g_strcmp0(key, "adv_mac") == 0) {
1249                 if(__ws_unpack_ay(asp_params->service_mac, value, WS_MACADDR_LEN))
1250                         WDP_LOGD("Adv address[" MACSTR "]", MAC2STR(asp_params->service_mac));
1251
1252         } else if (g_strcmp0(key, "ses_mac") == 0) {
1253                 if(__ws_unpack_ay(asp_params->session_mac, value, WS_MACADDR_LEN))
1254                         WDP_LOGD("session address[" MACSTR "]", MAC2STR(asp_params->session_mac));
1255
1256         } else if (g_strcmp0(key, "session_info") == 0) {
1257                 const char *session_info = NULL;
1258                 g_variant_get(value, "&s", &session_info);
1259                 if (session_info != NULL)
1260                         asp_params->session_information = g_strdup(session_info);
1261                 WDP_LOGD("Retrive session_info [%s]", asp_params->session_information);
1262         }
1263         __WDP_LOG_FUNC_EXIT__;
1264 }
1265
1266 static void __ws_extract_asp_provision_done_details(const char *key, GVariant *value, void *user_data)
1267 {
1268         __WDP_LOG_FUNC_ENTER__;
1269         wfd_oem_event_s *event = (wfd_oem_event_s *)user_data;
1270         wfd_oem_asp_prov_s *asp_params = NULL;
1271         if (!event || !event->edata) {
1272                 __WDP_LOG_FUNC_EXIT__;
1273                 return;
1274         }
1275
1276         asp_params = (wfd_oem_asp_prov_s *)event->edata;
1277
1278
1279         if (g_strcmp0(key, "peer_object") == 0) {
1280                 static unsigned char peer_dev[WS_MACSTR_LEN] = {'\0',};
1281                 const char *path = NULL;
1282                 char *loc = NULL;
1283
1284                 g_variant_get(value, "&o", &path);
1285                 if (path == NULL) {
1286                         __WDP_LOG_FUNC_EXIT__;
1287                         return;
1288                 }
1289
1290                 WDP_LOGD("Retrive Added path [%s]", path);
1291                 loc = strrchr(path,'/');
1292                 if (loc != NULL)
1293                         __ws_mac_compact_to_normal(loc + 1, peer_dev);
1294                 __ws_txt_to_mac(peer_dev, event->dev_addr);
1295
1296                 WDP_LOGD("peer address[" MACSTR "]", MAC2STR(event->dev_addr));
1297
1298         } else if (g_strcmp0(key, "adv_id") == 0) {
1299                 g_variant_get(value, "u", &asp_params->adv_id);
1300                 WDP_LOGD("Retrive adv_id [%u]", asp_params->adv_id);
1301
1302         } else if (g_strcmp0(key, "ses_id") == 0) {
1303                 g_variant_get(value, "u", &asp_params->session_id);
1304                 WDP_LOGD("Retrive session id [%u]", asp_params->session_id);
1305
1306         } else if (g_strcmp0(key, "dev_passwd_id") == 0) {
1307                 g_variant_get(value, "i", &event->wps_mode);
1308                 WDP_LOGD("Retrive dev_passwd_id [%d]", event->wps_mode);
1309
1310         } else if (g_strcmp0(key, "conncap") == 0) {
1311                 g_variant_get(value, "u", &asp_params->network_role);
1312                 WDP_LOGD("Retrive network role [%x]", asp_params->network_role);
1313
1314         } else if (g_strcmp0(key, "status") == 0) {
1315                 g_variant_get(value, "u", &asp_params->status);
1316                 WDP_LOGD("Retrive status [%x]", asp_params->status);
1317
1318         } else if (g_strcmp0(key, "persist") == 0) {
1319                 g_variant_get(value, "u", &asp_params->persistent_group_id);
1320                 asp_params->persist = 1;
1321                 WDP_LOGD("Retrive persist [%u]", asp_params->persistent_group_id);
1322
1323         }   else if (g_strcmp0(key, "adv_mac") == 0) {
1324                 if(__ws_unpack_ay(asp_params->service_mac, value, WS_MACADDR_LEN))
1325                         WDP_LOGD("Adv address[" MACSTR "]", MAC2STR(asp_params->service_mac));
1326
1327         } else if (g_strcmp0(key, "ses_mac") == 0) {
1328                 if(__ws_unpack_ay(asp_params->session_mac, value, WS_MACADDR_LEN))
1329                         WDP_LOGD("session address[" MACSTR "]", MAC2STR(asp_params->session_mac));
1330
1331         } else if (g_strcmp0(key, "group_mac") == 0) {
1332                 if(__ws_unpack_ay(asp_params->group_mac, value, WS_MACADDR_LEN))
1333                         WDP_LOGD("group address[" MACSTR "]", MAC2STR(asp_params->group_mac));
1334         }
1335         __WDP_LOG_FUNC_EXIT__;
1336 }
1337
1338 static void __ws_extract_provision_fail_details(const char *key, GVariant *value, void *user_data)
1339 {
1340         __WDP_LOG_FUNC_ENTER__;
1341         wfd_oem_event_s *event = (wfd_oem_event_s *)user_data;
1342         wfd_oem_asp_prov_s *asp_params = NULL;
1343         if(!event || !event->edata) {
1344                 __WDP_LOG_FUNC_EXIT__;
1345                 return;
1346         }
1347
1348         asp_params = (wfd_oem_asp_prov_s *)event->edata;
1349
1350         if (g_strcmp0(key, "peer_object") == 0) {
1351                 static unsigned char peer_dev[WS_MACSTR_LEN] = {'\0',};
1352                 const char *path = NULL;
1353                 char *loc = NULL;
1354
1355                 g_variant_get(value, "&o", &path);
1356                 if (path == NULL) {
1357                         __WDP_LOG_FUNC_EXIT__;
1358                         return;
1359                 }
1360
1361                 WDP_LOGD("Retrive Added path [%s]", path);
1362                 loc = strrchr(path,'/');
1363                 if (loc != NULL)
1364                         __ws_mac_compact_to_normal(loc + 1, peer_dev);
1365                 __ws_txt_to_mac(peer_dev, event->dev_addr);
1366
1367         } else if (g_strcmp0(key, "adv_id") == 0) {
1368                 g_variant_get(value, "u", &asp_params->adv_id);
1369                 WDP_LOGD("Retrive adv_id [%d]", asp_params->adv_id);
1370
1371         }  else if (g_strcmp0(key, "status") == 0) {
1372                 g_variant_get(value, "i", &asp_params->status);
1373                 WDP_LOGD("Retrive status [%d]", asp_params->status);
1374
1375         } else if (g_strcmp0(key, "deferred_session_resp") == 0) {
1376                 const char *session_info = NULL;
1377                 g_variant_get(value, "&s", &session_info);
1378                 if(session_info != NULL)
1379                         asp_params->session_information = g_strdup(session_info);
1380                 WDP_LOGD("Retrive deferred_session_resp [%s]", asp_params->session_information);
1381         }
1382         __WDP_LOG_FUNC_EXIT__;
1383 }
1384 #endif /* TIZEN_FEATURE_ASP */
1385
1386 static int _ws_flush()
1387 {
1388         __WDP_LOG_FUNC_ENTER__;
1389         GDBusConnection *g_dbus = NULL;
1390         dbus_method_param_s params;
1391         int res = 0;
1392
1393         if (!g_pd) {
1394                 WDP_LOGE("ws_dbus_plugin_data_s is not created yet");
1395                 __WDP_LOG_FUNC_EXIT__;
1396                 return -1;
1397         }
1398
1399         g_dbus = g_pd->g_dbus;
1400         if (!g_dbus) {
1401                 WDP_LOGE("DBus connection is NULL");
1402                 __WDP_LOG_FUNC_EXIT__;
1403                 return -1;
1404         }
1405         memset(&params, 0x0, sizeof(dbus_method_param_s));
1406
1407         dbus_set_method_param(&params, "Flush", g_pd->iface_path, g_dbus);
1408         params.params = NULL;
1409
1410         res = dbus_method_call(&params, SUPPLICANT_P2PDEVICE, NULL, NULL);
1411         if (res < 0)
1412                 WDP_LOGE("Failed to send command to wpa_supplicant");
1413         else
1414                 WDP_LOGD("Succeeded to flush");
1415
1416         __WDP_LOG_FUNC_EXIT__;
1417         return 0;
1418 }
1419
1420 static int _ws_cancel()
1421 {
1422         __WDP_LOG_FUNC_ENTER__;
1423         GDBusConnection *g_dbus = NULL;
1424         dbus_method_param_s params;
1425         int res = 0;
1426
1427         if (!g_pd) {
1428                 WDP_LOGE("ws_dbus_plugin_data_s is not created yet");
1429                 return -1;
1430         }
1431
1432
1433         g_dbus = g_pd->g_dbus;
1434         if (!g_dbus) {
1435                 WDP_LOGE("DBus connection is NULL");
1436                 return -1;
1437         }
1438         memset(&params, 0x0, sizeof(dbus_method_param_s));
1439
1440         dbus_set_method_param(&params, "Cancel", g_pd->iface_path , g_dbus);
1441         params.params = NULL;
1442
1443         res = dbus_method_call(&params, SUPPLICANT_WPS, NULL, NULL);
1444         if (res < 0)
1445                 WDP_LOGE("Failed to send command to wpa_supplicant");
1446         else
1447                 WDP_LOGD("Succeeded to cancel");
1448
1449         __WDP_LOG_FUNC_EXIT__;
1450         return 0;
1451 }
1452
1453 #if defined(TIZEN_FEATURE_ASP)
1454 int ws_get_advertise_service(const char *peer_path, GList **asp_services)
1455 {
1456         __WDP_LOG_FUNC_ENTER__;
1457         GDBusConnection *g_dbus = NULL;
1458         GVariant *param = NULL;
1459         GVariant *reply = NULL;
1460         GVariant *temp = NULL;
1461         GError *error = NULL;
1462         GVariantIter *iter = NULL;
1463         wfd_oem_advertise_service_s *service;
1464         wfd_oem_asp_service_s *seek = NULL;
1465         unsigned char desc[7];
1466         unsigned int adv_id;
1467         unsigned int config_method;
1468         unsigned char length;
1469         char *value;
1470         int cnt;
1471         int res = 0;
1472
1473         if (!g_pd) {
1474                 WDP_LOGE("ws_dbus_plugin_data_s is not created yet");
1475                 return -1;
1476         }
1477
1478         g_dbus = g_pd->g_dbus;
1479         if (!g_dbus) {
1480                 WDP_LOGE("DBus connection is NULL");
1481                 return -1;
1482         }
1483
1484         param = g_variant_new("(ss)", SUPPLICANT_P2P_PEER, "AdvertiseService");
1485 #if defined (TIZEN_DEBUG_DBUS_VALUE)
1486         DEBUG_PARAMS(param);
1487 #endif /* TIZEN_DEBUG_DBUS_VALUE */
1488
1489         reply = g_dbus_connection_call_sync (
1490                         g_dbus,
1491                         SUPPLICANT_SERVICE, /* bus name */
1492                         peer_path, /* object path */
1493                         DBUS_PROPERTIES_INTERFACE, /* interface name */
1494                         DBUS_PROPERTIES_METHOD_GET, /* method name */
1495                         param, /* GVariant *params */
1496                         NULL, /* reply_type */
1497                         G_DBUS_CALL_FLAGS_NONE, /* flags */
1498                         SUPPLICANT_TIMEOUT , /* timeout */
1499                         NULL, /* cancellable */
1500                         &error); /* error */
1501
1502         if(error != NULL) {
1503                 WDP_LOGE("Error! Failed to get peer advertise service: [%s]",
1504                                 error->message);
1505                 g_error_free(error);
1506                 if(reply)
1507                         g_variant_unref(reply);
1508                 __WDP_LOG_FUNC_EXIT__;
1509                 return -1;
1510         }
1511
1512         if (reply != NULL) {
1513
1514 #if defined (TIZEN_DEBUG_DBUS_VALUE)
1515                 DEBUG_PARAMS(reply);
1516 #endif /* TIZEN_DEBUG_DBUS_VALUE */
1517
1518                 /* replay will have the format <(<ay>,)>
1519                  * So, you need to remove tuple out side of variant and
1520                  * variant out side of byte array
1521                  * */
1522                 temp = g_variant_get_child_value(reply, 0);
1523                 temp = g_variant_get_child_value(temp, 0);
1524                 g_variant_get(temp, "ay", &iter);
1525                 if (iter == NULL) {
1526                         g_variant_unref(reply);
1527                         WDP_LOGE("Failed to get iterator");
1528                         return -1;
1529                 }
1530
1531                 while (1) {
1532                         /* 4byte advertisement ID, 2 byte config method, 1byte length */
1533                         cnt = 0;
1534                         memset(desc, 0x0, 7);
1535                         while (cnt < 7 && g_variant_iter_loop (iter, "y", &desc[cnt])) {
1536                                 cnt++;
1537                         }
1538
1539                         if (cnt != 7 || desc[6] == 0) {
1540                                 WDP_LOGE("Invalid descriptor header length cnt [%d]", cnt);
1541                                 g_variant_unref(reply);
1542                                 return res;
1543                         }
1544
1545                         adv_id = desc[3] << 24 | desc[2] << 16 | desc[1] << 8 | desc[0];
1546                         config_method = desc[4] << 8 | desc[4];
1547                         length = desc[6];
1548                         value = NULL;
1549                         value = g_try_malloc0(length + 1);
1550                         if (value == NULL) {
1551                                 WDP_LOGE("g_try_malloc0 failed");
1552                                 g_variant_unref(reply);
1553                                 return res;
1554                         }
1555                         WDP_LOGD("adv_id[%u] config_method[%u]  length[%hhu]", adv_id, config_method, length);
1556
1557                         cnt = 0;
1558                         while (cnt < length && g_variant_iter_loop (iter, "y", &value[cnt])) {
1559                                 cnt++;
1560                         }
1561
1562                         if (cnt != length) {
1563                                 WDP_LOGE("Length doesn't matched with header value cnt [%d]", cnt);
1564                                 g_variant_unref(reply);
1565                                 g_free(value);
1566                                 return res;
1567                         }
1568
1569                         service = NULL;
1570                         service = (wfd_oem_advertise_service_s *)
1571                                         g_try_malloc0(sizeof(wfd_oem_advertise_service_s));
1572                         if (service == NULL) {
1573                                 WDP_LOGE("g_try_malloc0 failed");
1574                                 g_variant_unref(reply);
1575                                 g_free(value);
1576                                 return res;
1577                         }
1578                         service->adv_id = adv_id;
1579                         service->config_method = config_method;
1580                         service->service_type_length = length;
1581                         service->service_type = value;
1582
1583 GLIST_ITER_START(seek_list, seek)
1584                         if (g_strcmp0(seek->service_type, service->service_type) == 0) {
1585                                 WDP_LOGD("service type matched [%s] search_id [%llu]",
1586                                                 service->service_type, seek->search_id);
1587                         } else {
1588                                 seek = NULL;
1589                         }
1590 GLIST_ITER_END()
1591                         if(seek != NULL && seek->service_info != NULL) {
1592                                 WDP_LOGD("service info exists, service discovery will be performed");
1593                         } else {
1594                                 WDP_LOGD("service info doesn't exists. Add service to list");
1595                                 service->search_id = seek->search_id;
1596                                 *asp_services = g_list_append(*asp_services, service);
1597                         }
1598                 }
1599                 g_variant_unref(reply);
1600         }
1601         __WDP_LOG_FUNC_EXIT__;
1602         return res;
1603 }
1604 #endif /* TIZEN_FEATURE_ASP */
1605
1606 static void _ws_process_device_found(GDBusConnection *connection,
1607                 const gchar *object_path, GVariant *parameters)
1608 {
1609         __WDP_LOG_FUNC_ENTER__;
1610         wfd_oem_event_s event;
1611         wfd_oem_dev_data_s *edata = NULL;
1612         static char peer_path[DBUS_OBJECT_PATH_MAX] = {'\0',};
1613
1614         edata = (wfd_oem_dev_data_s *) g_try_malloc0(sizeof(wfd_oem_dev_data_s));
1615         if (!edata) {
1616                 WDP_LOGF("Failed to allocate memory for event. [%s]",
1617                                 strerror(errno));
1618                 __WDP_LOG_FUNC_EXIT__;
1619                 return;
1620         }
1621         memset(&event, 0x0, sizeof(wfd_oem_event_s));
1622
1623         event.edata = (void*) edata;
1624         event.edata_type = WFD_OEM_EDATA_TYPE_DEVICE;
1625         event.event_id = WFD_OEM_EVENT_PEER_FOUND;
1626
1627         __ws_path_to_addr(peer_path, event.dev_addr, parameters);
1628
1629         dbus_property_get_all(peer_path, g_pd->g_dbus, SUPPLICANT_P2P_PEER,
1630                         __ws_peer_property, event.edata);
1631
1632 #if defined(TIZEN_FEATURE_ASP)
1633         if(edata->has_asp_services)
1634                 ws_get_advertise_service(peer_path, (GList **)&(event.asp_services));
1635 #endif /* TIZEN_FEATURE_ASP */
1636
1637         g_pd->callback(g_pd->user_data, &event);
1638 #if defined(TIZEN_FEATURE_ASP)
1639         if(event.asp_services != NULL) {
1640                 GList *l;
1641                 wfd_oem_advertise_service_s *service;
1642                 for(l = (GList *)event.asp_services; l != NULL; l = l->next) {
1643                         service = (wfd_oem_advertise_service_s *)l->data;
1644                         g_free(service->service_type);
1645                         g_free(service);
1646                         event.asp_services = g_list_remove(l, service);
1647                 }
1648                 g_list_free(l);
1649         }
1650 #endif /* TIZEN_FEATURE_ASP */
1651         g_free(event.edata);
1652
1653         __WDP_LOG_FUNC_EXIT__;
1654 }
1655
1656 static void _ws_process_device_lost(GDBusConnection *connection,
1657                 const gchar *object_path, GVariant *parameters)
1658 {
1659         __WDP_LOG_FUNC_ENTER__;
1660         wfd_oem_event_s event;
1661         static char peer_path[DBUS_OBJECT_PATH_MAX] = {'\0',};
1662
1663         memset(&event, 0x0, sizeof(wfd_oem_event_s));
1664
1665         event.edata_type = WFD_OEM_EDATA_TYPE_NONE;
1666         event.event_id = WFD_OEM_EVENT_PEER_DISAPPEARED;
1667
1668         __ws_path_to_addr(peer_path, event.dev_addr, parameters);
1669
1670         g_pd->callback(g_pd->user_data, &event);
1671
1672         __WDP_LOG_FUNC_EXIT__;
1673 }
1674
1675 static void _ws_process_find_stoppped(GDBusConnection *connection,
1676                 const gchar *object_path, GVariant *parameters)
1677 {
1678         __WDP_LOG_FUNC_ENTER__;
1679         wfd_oem_event_s event;
1680
1681         memset(&event, 0x0, sizeof(wfd_oem_event_s));
1682
1683         event.edata_type = WFD_OEM_EDATA_TYPE_NONE;
1684         event.event_id = WFD_OEM_EVENT_DISCOVERY_FINISHED;
1685
1686         g_pd->callback(g_pd->user_data, &event);
1687
1688         __WDP_LOG_FUNC_EXIT__;
1689 }
1690
1691 static void _ws_process_prov_disc_req_display_pin(GDBusConnection *connection,
1692                 const gchar *object_path, GVariant *parameters)
1693 {
1694         __WDP_LOG_FUNC_ENTER__;
1695
1696         wfd_oem_event_s event;
1697         wfd_oem_dev_data_s *edata = NULL;
1698
1699         static char peer_path[DBUS_OBJECT_PATH_MAX] = {'\0',};
1700         static unsigned char peer_dev[OEM_MACSTR_LEN] = {'\0',};
1701         const char *path = NULL;
1702         const char *pin = NULL;
1703         char *loc = NULL;
1704
1705         edata = (wfd_oem_dev_data_s *) g_try_malloc0(sizeof(wfd_oem_dev_data_s));
1706         if (!edata) {
1707                 WDP_LOGF("Failed to allocate memory for event. [%s]",
1708                                 strerror(errno));
1709                 __WDP_LOG_FUNC_EXIT__;
1710                 return;
1711         }
1712         memset(&event, 0x0, sizeof(wfd_oem_event_s));
1713
1714         event.edata = (void*) edata;
1715         event.edata_type = WFD_OEM_EDATA_TYPE_DEVICE;
1716         event.event_id = WFD_OEM_EVENT_PROV_DISC_REQ;
1717         event.wps_mode = WFD_OEM_WPS_MODE_DISPLAY;
1718
1719         g_variant_get(parameters, "(&o&s)", &path, &pin);
1720         g_strlcpy(peer_path, path, DBUS_OBJECT_PATH_MAX);
1721         WDP_LOGD("Retrive Added path [%s]", peer_path);
1722
1723         loc = strrchr(peer_path,'/');
1724         if(loc != NULL)
1725                 __ws_mac_compact_to_normal(loc + 1, peer_dev);
1726         __ws_txt_to_mac(peer_dev, event.dev_addr);
1727         WDP_LOGD("peer mac [" MACSTR "]", MAC2STR(event.dev_addr));
1728
1729         g_strlcpy(event.wps_pin, pin, WS_PINSTR_LEN + 1);
1730         WDP_LOGD("Retrive pin [%s]", event.wps_pin);
1731
1732         dbus_property_get_all(peer_path, g_pd->g_dbus, SUPPLICANT_P2P_PEER,
1733                         __ws_peer_property, event.edata);
1734
1735         g_pd->callback(g_pd->user_data, &event);
1736         g_free(event.edata);
1737
1738         __WDP_LOG_FUNC_EXIT__;
1739 }
1740
1741 static void _ws_process_prov_disc_resp_display_pin(GDBusConnection *connection,
1742                 const gchar *object_path, GVariant *parameters)
1743 {
1744         __WDP_LOG_FUNC_ENTER__;
1745
1746         wfd_oem_event_s event;
1747         wfd_oem_dev_data_s *edata = NULL;
1748
1749         static char peer_path[DBUS_OBJECT_PATH_MAX] = {'\0',};
1750         static unsigned char peer_dev[OEM_MACSTR_LEN] = {'\0',};
1751         const char *path = NULL;
1752         const char *pin = NULL;
1753         char *loc = NULL;
1754
1755         edata = (wfd_oem_dev_data_s *) g_try_malloc0(sizeof(wfd_oem_dev_data_s));
1756         if (!edata) {
1757                 WDP_LOGF("Failed to allocate memory for event. [%s]",
1758                                 strerror(errno));
1759                 __WDP_LOG_FUNC_EXIT__;
1760                 return;
1761         }
1762         memset(&event, 0x0, sizeof(wfd_oem_event_s));
1763
1764         event.edata = (void*) edata;
1765         event.edata_type = WFD_OEM_EDATA_TYPE_DEVICE;
1766         event.event_id = WFD_OEM_EVENT_PROV_DISC_RESP;
1767         event.wps_mode = WFD_OEM_WPS_MODE_DISPLAY;
1768
1769         g_variant_get(parameters, "(&o&s)", &path, &pin);
1770         g_strlcpy(peer_path, path, DBUS_OBJECT_PATH_MAX);
1771         WDP_LOGD("Retrive Added path [%s]", peer_path);
1772
1773         loc = strrchr(peer_path,'/');
1774         if(loc != NULL)
1775                 __ws_mac_compact_to_normal(loc + 1, peer_dev);
1776         __ws_txt_to_mac(peer_dev, event.dev_addr);
1777         WDP_LOGD("peer mac [" MACSTR "]", MAC2STR(event.dev_addr));
1778
1779         g_strlcpy(event.wps_pin, pin, WS_PINSTR_LEN + 1);
1780         WDP_LOGD("Retrive pin [%s]", event.wps_pin);
1781
1782         dbus_property_get_all(peer_path, g_pd->g_dbus, SUPPLICANT_P2P_PEER,
1783                         __ws_peer_property, event.edata);
1784
1785         g_pd->callback(g_pd->user_data, &event);
1786         g_free(event.edata);
1787
1788         __WDP_LOG_FUNC_EXIT__;
1789 }
1790
1791 static void _ws_process_prov_disc_req_enter_pin(GDBusConnection *connection,
1792                 const gchar *object_path, GVariant *parameters)
1793 {
1794         __WDP_LOG_FUNC_ENTER__;
1795         wfd_oem_event_s event;
1796         wfd_oem_dev_data_s *edata = NULL;
1797         static char peer_path[DBUS_OBJECT_PATH_MAX] = {'\0',};
1798
1799         edata = (wfd_oem_dev_data_s *) g_try_malloc0(sizeof(wfd_oem_dev_data_s));
1800         if (!edata) {
1801                 WDP_LOGF("Failed to allocate memory for event. [%s]",
1802                                 strerror(errno));
1803                 __WDP_LOG_FUNC_EXIT__;
1804                 return;
1805         }
1806         memset(&event, 0x0, sizeof(wfd_oem_event_s));
1807
1808         event.edata = (void*) edata;
1809         event.edata_type = WFD_OEM_EDATA_TYPE_DEVICE;
1810         event.event_id = WFD_OEM_EVENT_PROV_DISC_REQ;
1811         event.wps_mode = WFD_OEM_WPS_MODE_KEYPAD;
1812
1813         __ws_path_to_addr(peer_path, event.dev_addr, parameters);
1814
1815         dbus_property_get_all(peer_path, g_pd->g_dbus, SUPPLICANT_P2P_PEER,
1816                         __ws_peer_property, event.edata);
1817
1818         g_pd->callback(g_pd->user_data, &event);
1819         g_free(event.edata);
1820
1821         __WDP_LOG_FUNC_EXIT__;
1822 }
1823
1824 static void _ws_process_prov_disc_resp_enter_pin(GDBusConnection *connection,
1825                 const gchar *object_path, GVariant *parameters)
1826 {
1827         __WDP_LOG_FUNC_ENTER__;
1828         wfd_oem_event_s event;
1829         wfd_oem_dev_data_s *edata = NULL;
1830         static char peer_path[DBUS_OBJECT_PATH_MAX] = {'\0',};
1831
1832         edata = (wfd_oem_dev_data_s *) g_try_malloc0(sizeof(wfd_oem_dev_data_s));
1833         if (!edata) {
1834                 WDP_LOGF("Failed to allocate memory for event. [%s]",
1835                                 strerror(errno));
1836                 __WDP_LOG_FUNC_EXIT__;
1837                 return;
1838         }
1839         memset(&event, 0x0, sizeof(wfd_oem_event_s));
1840
1841         event.edata = (void*) edata;
1842         event.edata_type = WFD_OEM_EDATA_TYPE_DEVICE;
1843         event.event_id = WFD_OEM_EVENT_PROV_DISC_RESP;
1844         event.wps_mode = WFD_OEM_WPS_MODE_KEYPAD;
1845
1846         __ws_path_to_addr(peer_path, event.dev_addr, parameters);
1847
1848         dbus_property_get_all(peer_path, g_pd->g_dbus, SUPPLICANT_P2P_PEER,
1849                         __ws_peer_property, event.edata);
1850
1851         g_pd->callback(g_pd->user_data, &event);
1852         g_free(event.edata);
1853
1854         __WDP_LOG_FUNC_EXIT__;
1855 }
1856
1857 static void _ws_process_prov_disc_pbc_req(GDBusConnection *connection,
1858                 const gchar *object_path, GVariant *parameters)
1859 {
1860         __WDP_LOG_FUNC_ENTER__;
1861         wfd_oem_event_s event;
1862         wfd_oem_dev_data_s *edata = NULL;
1863         static char peer_path[DBUS_OBJECT_PATH_MAX] = {'\0',};
1864
1865         edata = (wfd_oem_dev_data_s *) g_try_malloc0(sizeof(wfd_oem_dev_data_s));
1866         if (!edata) {
1867                 WDP_LOGF("Failed to allocate memory for event. [%s]",
1868                                 strerror(errno));
1869                 __WDP_LOG_FUNC_EXIT__;
1870                 return;
1871         }
1872         memset(&event, 0x0, sizeof(wfd_oem_event_s));
1873
1874         event.edata = (void*) edata;
1875         event.edata_type = WFD_OEM_EDATA_TYPE_DEVICE;
1876         event.event_id = WFD_OEM_EVENT_PROV_DISC_REQ;
1877         event.wps_mode = WFD_OEM_WPS_MODE_PBC;
1878
1879         __ws_path_to_addr(peer_path, event.dev_addr, parameters);
1880
1881         dbus_property_get_all(peer_path, g_pd->g_dbus, SUPPLICANT_P2P_PEER,
1882                         __ws_peer_property, event.edata);
1883
1884         g_pd->callback(g_pd->user_data, &event);
1885         g_free(event.edata);
1886
1887         __WDP_LOG_FUNC_EXIT__;
1888 }
1889
1890 static void _ws_process_prov_disc_pbc_resp(GDBusConnection *connection,
1891                 const gchar *object_path, GVariant *parameters)
1892 {
1893         __WDP_LOG_FUNC_ENTER__;
1894         wfd_oem_event_s event;
1895         wfd_oem_dev_data_s *edata = NULL;
1896         static char peer_path[DBUS_OBJECT_PATH_MAX] = {'\0',};
1897
1898         edata = (wfd_oem_dev_data_s *) g_try_malloc0(sizeof(wfd_oem_dev_data_s));
1899         if (!edata) {
1900                 WDP_LOGF("Failed to allocate memory for event. [%s]",
1901                                 strerror(errno));
1902                 __WDP_LOG_FUNC_EXIT__;
1903                 return;
1904         }
1905         memset(&event, 0x0, sizeof(wfd_oem_event_s));
1906
1907         event.edata = (void*) edata;
1908         event.edata_type = WFD_OEM_EDATA_TYPE_DEVICE;
1909         event.event_id = WFD_OEM_EVENT_PROV_DISC_RESP;
1910         event.wps_mode = WFD_OEM_WPS_MODE_PBC;
1911
1912         __ws_path_to_addr(peer_path, event.dev_addr, parameters);
1913
1914         dbus_property_get_all(peer_path, g_pd->g_dbus, SUPPLICANT_P2P_PEER,
1915                         __ws_peer_property, event.edata);
1916
1917         g_pd->callback(g_pd->user_data, &event);
1918         g_free(event.edata);
1919
1920         __WDP_LOG_FUNC_EXIT__;
1921 }
1922
1923 #if defined(TIZEN_FEATURE_ASP)
1924 static void _ws_process_prov_disc_failure(GDBusConnection *connection,
1925                 const gchar *object_path, GVariant *parameters)
1926 {
1927         __WDP_LOG_FUNC_ENTER__;
1928         GVariantIter *iter = NULL;
1929         wfd_oem_event_s event;
1930         wfd_oem_asp_prov_s *edata;
1931
1932         edata = (wfd_oem_asp_prov_s *) g_try_malloc0(sizeof(wfd_oem_asp_prov_s));
1933         if (!edata) {
1934                 WDP_LOGF("Failed to allocate memory for event. [%s]",
1935                                 strerror(errno));
1936                 __WDP_LOG_FUNC_EXIT__;
1937                 return;
1938         }
1939         memset(&event, 0x0, sizeof(wfd_oem_event_s));
1940
1941         event.edata = (void*) edata;
1942         event.event_id = WFD_OEM_EVENT_PROV_DISC_FAIL;
1943
1944         if (parameters != NULL) {
1945                 g_variant_get(parameters, "(a{sv})", &iter);
1946                 if (iter != NULL) {
1947                         dbus_property_foreach(iter, __ws_extract_provision_fail_details, &event);
1948                         event.edata_type = WFD_OEM_EDATA_TYPE_ASP_PROV;
1949                         g_variant_iter_free(iter);
1950                 }
1951         } else {
1952                 WDP_LOGE("No Properties");
1953         }
1954
1955         g_pd->callback(g_pd->user_data, &event);
1956
1957         if (event.edata_type == WFD_OEM_EDATA_TYPE_ASP_PROV)
1958                 g_free(edata->session_information);
1959         g_free(edata);
1960
1961         __WDP_LOG_FUNC_EXIT__;
1962 }
1963 #else
1964 static void _ws_process_prov_disc_failure(GDBusConnection *connection,
1965                 const gchar *object_path, GVariant *parameters)
1966 {
1967         __WDP_LOG_FUNC_ENTER__;
1968         wfd_oem_event_s event;
1969         static char peer_path[DBUS_OBJECT_PATH_MAX] = {'\0',};
1970         static unsigned char peer_dev[OEM_MACSTR_LEN] = {'\0',};
1971         const char *path = NULL;
1972         int prov_status = 0;
1973         char *loc = NULL;
1974
1975         memset(&event, 0x0, sizeof(wfd_oem_event_s));
1976
1977         event.edata_type = WFD_OEM_EDATA_TYPE_DEVICE;
1978         event.event_id = WFD_OEM_EVENT_PROV_DISC_FAIL;
1979
1980         g_variant_get(parameters, "(&oi)", &path, &prov_status);
1981         g_strlcpy(peer_path, path, DBUS_OBJECT_PATH_MAX);
1982         WDP_LOGD("Retrive Added path [%s]", peer_path);
1983         WDP_LOGD("Retrive Failure stateus [%d]", prov_status);
1984
1985         loc = strrchr(peer_path,'/');
1986         if(loc != NULL)
1987                 __ws_mac_compact_to_normal(loc + 1, peer_dev);
1988         __ws_txt_to_mac(peer_dev, event.dev_addr);
1989         WDP_LOGE("peer mac [" MACSTR "]", MAC2STR(event.dev_addr));
1990
1991         g_pd->callback(g_pd->user_data, &event);
1992
1993         __WDP_LOG_FUNC_EXIT__;
1994 }
1995 #endif /* TIZEN_FEATURE_ASP */
1996
1997
1998 static void _ws_process_group_started(GDBusConnection *connection,
1999                 const gchar *object_path, GVariant *parameters)
2000 {
2001         __WDP_LOG_FUNC_ENTER__;
2002         GVariantIter *iter = NULL;
2003         wfd_oem_event_s event;
2004         wfd_oem_group_data_s *edata = NULL;
2005
2006         edata = (wfd_oem_group_data_s*)calloc(1, sizeof(wfd_oem_group_data_s));
2007         if (!edata) {
2008                 WDP_LOGF("Failed to allocate memory for event. [%s]",
2009                                 strerror(errno));
2010                 __WDP_LOG_FUNC_EXIT__;
2011                 return;
2012         }
2013         memset(&event, 0x0, sizeof(wfd_oem_event_s));
2014
2015         event.edata = (void*) edata;
2016         event.edata_type = WFD_OEM_EDATA_TYPE_GROUP;
2017         event.event_id = WFD_OEM_EVENT_GROUP_CREATED;
2018
2019         if(parameters != NULL){
2020                 g_variant_get(parameters, "(a{sv})", &iter);
2021
2022                 if (iter != NULL) {
2023                         dbus_property_foreach(iter, __ws_extract_group_details, &event);
2024                         g_variant_iter_free(iter);
2025                 }
2026         } else {
2027                 WDP_LOGE("No properties");
2028         }
2029
2030         g_pd->callback(g_pd->user_data, &event);
2031         g_free(event.edata);
2032
2033         __WDP_LOG_FUNC_EXIT__;
2034 }
2035
2036 static void _ws_process_go_neg_success(GDBusConnection *connection,
2037                 const gchar *object_path, GVariant *parameters)
2038 {
2039         __WDP_LOG_FUNC_ENTER__;
2040         GVariantIter *iter = NULL;
2041         wfd_oem_event_s event;
2042         wfd_oem_conn_data_s *edata = NULL;
2043
2044         edata = (wfd_oem_conn_data_s*)calloc(1, sizeof(wfd_oem_conn_data_s));
2045         if (!edata) {
2046                 WDP_LOGF("Failed to allocate memory for event. [%s]",
2047                                 strerror(errno));
2048                 __WDP_LOG_FUNC_EXIT__;
2049                 return;
2050         }
2051         memset(&event, 0x0, sizeof(wfd_oem_event_s));
2052
2053         event.edata = edata;
2054         event.edata_type = WFD_OEM_EDATA_TYPE_CONN;
2055         event.event_id = WFD_OEM_EVENT_GO_NEG_DONE;
2056
2057         if (parameters != NULL){
2058                 g_variant_get(parameters, "(a{sv})", &iter);
2059
2060                 if (iter != NULL) {
2061                         dbus_property_foreach(iter, __ws_extract_gonegsuccess_details, &event);
2062                         g_variant_iter_free(iter);
2063                 }
2064         } else {
2065                 WDP_LOGE("No properties");
2066         }
2067
2068         g_pd->callback(g_pd->user_data, &event);
2069         g_free(edata);
2070
2071         __WDP_LOG_FUNC_EXIT__;
2072 }
2073
2074 static void _ws_process_go_neg_failure(GDBusConnection *connection,
2075                 const gchar *object_path, GVariant *parameters)
2076 {
2077         __WDP_LOG_FUNC_ENTER__;
2078         GVariantIter *iter = NULL;
2079         wfd_oem_event_s event;
2080         wfd_oem_conn_data_s *edata = NULL;
2081
2082         edata = (wfd_oem_conn_data_s *) g_try_malloc0(sizeof(wfd_oem_conn_data_s));
2083         if (!edata) {
2084                 WDP_LOGF("Failed to allocate memory for event. [%s]",
2085                                 strerror(errno));
2086                 __WDP_LOG_FUNC_EXIT__;
2087                 return;
2088         }
2089         memset(&event, 0x0, sizeof(wfd_oem_event_s));
2090
2091         event.edata = (void*) edata;
2092         event.edata_type = WFD_OEM_EDATA_TYPE_DEVICE;
2093         event.event_id = WFD_OEM_EVENT_GO_NEG_FAIL;
2094
2095         if (parameters != NULL) {
2096                 g_variant_get(parameters, "(a{sv})", &iter);
2097
2098                 if (iter != NULL) {
2099                         dbus_property_foreach(iter, __ws_extract_gonegfailaure_details, &event);
2100                         g_variant_iter_free(iter);
2101                 }
2102         } else {
2103                 WDP_LOGE("No properties");
2104         }
2105
2106         g_pd->callback(g_pd->user_data, &event);
2107         g_free(event.edata);
2108
2109         __WDP_LOG_FUNC_EXIT__;
2110 }
2111
2112 static void _ws_process_go_neg_request(GDBusConnection *connection,
2113                 const gchar *object_path, GVariant *parameters)
2114 {
2115         __WDP_LOG_FUNC_ENTER__;
2116         wfd_oem_event_s event;
2117         wfd_oem_dev_data_s *edata = NULL;
2118         static char peer_path[DBUS_OBJECT_PATH_MAX] = {'\0',};
2119         static unsigned char peer_dev[OEM_MACSTR_LEN] = {'\0',};
2120         const char *path = NULL;
2121         char * loc = NULL;
2122
2123         int dev_passwd_id = 0;
2124         int device_go_intent = 0;
2125
2126         edata = (wfd_oem_dev_data_s *) g_try_malloc0(sizeof(wfd_oem_dev_data_s));
2127         if (!edata) {
2128                 WDP_LOGF("Failed to allocate memory for event. [%s]",
2129                                 strerror(errno));
2130                 __WDP_LOG_FUNC_EXIT__;
2131                 return;
2132         }
2133         memset(&event, 0x0, sizeof(wfd_oem_event_s));
2134
2135         event.edata = (void*) edata;
2136         event.edata_type = WFD_OEM_EDATA_TYPE_DEVICE;
2137         event.event_id = WFD_OEM_EVENT_GO_NEG_REQ;
2138
2139         g_variant_get(parameters, "(&oqy)", &path, &dev_passwd_id, &device_go_intent);
2140         g_strlcpy(peer_path, path, DBUS_OBJECT_PATH_MAX);
2141
2142         WDP_LOGD("Retrive peer path [%s]", peer_path);
2143         WDP_LOGD("Retrive dev_passwd_id [%d]", dev_passwd_id);
2144         WDP_LOGD("Retrive device_go_intent [%d]", device_go_intent);
2145
2146         if (dev_passwd_id == WS_DEV_PASSWD_ID_PUSH_BUTTON)
2147                 event.wps_mode = WFD_OEM_WPS_MODE_PBC;
2148         else if (dev_passwd_id == WS_DEV_PASSWD_ID_REGISTRAR_SPECIFIED)
2149                 event.wps_mode = WFD_OEM_WPS_MODE_DISPLAY;
2150         else if (dev_passwd_id == WS_DEV_PASSWD_ID_USER_SPECIFIED)
2151                 event.wps_mode = WFD_OEM_WPS_MODE_KEYPAD;
2152         else
2153                 event.wps_mode = WFD_OEM_WPS_MODE_NONE;
2154         edata->device_go_intent = device_go_intent;
2155
2156         loc = strrchr(peer_path,'/');
2157         if(loc != NULL)
2158                 __ws_mac_compact_to_normal(loc + 1, peer_dev);
2159         __ws_txt_to_mac(peer_dev, event.dev_addr);
2160         WDP_LOGD("peer mac [" MACSTR "]", MAC2STR(event.dev_addr));
2161
2162         dbus_property_get_all(peer_path, g_pd->g_dbus, SUPPLICANT_P2P_PEER,
2163                         __ws_peer_property, event.edata);
2164
2165         g_pd->callback(g_pd->user_data, &event);
2166         g_free(event.edata);
2167
2168         __WDP_LOG_FUNC_EXIT__;
2169 }
2170 static void _ws_process_invitation_received(GDBusConnection *connection,
2171                 const gchar *object_path, GVariant *parameters)
2172 {
2173         __WDP_LOG_FUNC_ENTER__;
2174         GVariantIter *iter = NULL;
2175         wfd_oem_event_s event;
2176         wfd_oem_invite_data_s *edata = NULL;
2177
2178         edata = (wfd_oem_invite_data_s *) g_try_malloc0(sizeof(wfd_oem_invite_data_s));
2179         if (!edata) {
2180                 WDP_LOGF("Failed to allocate memory for event. [%s]",
2181                                 strerror(errno));
2182                 __WDP_LOG_FUNC_EXIT__;
2183                 return;
2184         }
2185         memset(&event, 0x0, sizeof(wfd_oem_event_s));
2186
2187         event.edata = (void*) edata;
2188         event.edata_type = WFD_OEM_EDATA_TYPE_INVITE;
2189         event.event_id = WFD_OEM_EVENT_INVITATION_REQ;
2190
2191         if (parameters != NULL) {
2192                 g_variant_get(parameters, "(a{sv})", &iter);
2193
2194                 if (iter != NULL) {
2195                         dbus_property_foreach(iter, __ws_extract_invitation_details, &event);
2196                         g_variant_iter_free(iter);
2197                 }
2198         } else {
2199                 WDP_LOGE("No properties");
2200         }
2201         memcpy(&(event.dev_addr), edata->sa, OEM_MACADDR_LEN);
2202
2203         g_pd->callback(g_pd->user_data, &event);
2204         g_free(event.edata);
2205
2206         __WDP_LOG_FUNC_EXIT__;
2207 }
2208
2209 static void _ws_process_invitation_result(GDBusConnection *connection,
2210                 const gchar *object_path, GVariant *parameters)
2211 {
2212         __WDP_LOG_FUNC_ENTER__;
2213         wfd_oem_event_s event;
2214         memset(&event, 0x0, sizeof(wfd_oem_event_s));
2215
2216 //      g_pd->callback(g_pd->user_data, event);
2217
2218         __WDP_LOG_FUNC_EXIT__;
2219 }
2220
2221 static void _ws_process_group_finished(GDBusConnection *connection,
2222                 const gchar *object_path, GVariant *parameters)
2223 {
2224         __WDP_LOG_FUNC_ENTER__;
2225         wfd_oem_event_s event;
2226
2227         memset(&event, 0x0, sizeof(wfd_oem_event_s));
2228
2229         event.event_id = WFD_OEM_EVENT_GROUP_DESTROYED;
2230         event.edata_type = WFD_OEM_EDATA_TYPE_NONE;
2231
2232         g_dbus_connection_signal_unsubscribe(g_pd->g_dbus, g_pd->group_sub_id);
2233         memset(g_pd->group_iface_path, 0x0, DBUS_OBJECT_PATH_MAX);
2234         _ws_flush();
2235
2236         g_pd->callback(g_pd->user_data, &event);
2237
2238         __WDP_LOG_FUNC_EXIT__;
2239 }
2240
2241 #ifdef TIZEN_FEATURE_SERVICE_DISCOVERY
2242 static void _ws_process_service_discovery_response(GDBusConnection *connection,
2243                 const gchar *object_path, GVariant *parameters)
2244 {
2245         __WDP_LOG_FUNC_ENTER__;
2246         GVariantIter *iter = NULL;
2247         wfd_oem_event_s event;
2248
2249         memset(&event, 0x0, sizeof(wfd_oem_event_s));
2250
2251         event.event_id = WFD_OEM_EVENT_SERV_DISC_RESP;
2252
2253         if(parameters != NULL) {
2254                 g_variant_get(parameters, "(a{sv})", &iter);
2255                 if(iter != NULL) {
2256                         dbus_property_foreach(iter, __ws_extract_servicediscoveryresponse_details, &event);
2257                         event.edata_type = WFD_OEM_EDATA_TYPE_NEW_SERVICE;
2258                         g_variant_iter_free(iter);
2259                 }
2260         } else {
2261                 WDP_LOGE("No Properties");
2262         }
2263
2264         g_pd->callback(g_pd->user_data, &event);
2265
2266         if (event.edata_type == WFD_OEM_EDATA_TYPE_NEW_SERVICE)
2267                 g_list_free((GList*) event.edata);
2268
2269         __WDP_LOG_FUNC_EXIT__;
2270 }
2271 #endif /* TIZEN_FEATURE_SERVICE_DISCOVERY */
2272
2273 #if defined(TIZEN_FEATURE_ASP)
2274 static void _ws_process_service_asp_response(GDBusConnection *connection,
2275                 const gchar *object_path, GVariant *parameters)
2276 {
2277         __WDP_LOG_FUNC_ENTER__;
2278         GVariantIter *iter = NULL;
2279         wfd_oem_event_s event;
2280         wfd_oem_asp_service_s *service, *tmp;
2281
2282         service = (wfd_oem_asp_service_s *) g_try_malloc0(sizeof(wfd_oem_asp_service_s));
2283         if (!service) {
2284                 WDP_LOGF("Failed to allocate memory for event. [%s]",
2285                                 strerror(errno));
2286                 __WDP_LOG_FUNC_EXIT__;
2287                 return;
2288         }
2289         memset(&event, 0x0, sizeof(wfd_oem_event_s));
2290
2291         event.edata = (void*) service;
2292         event.edata_type = WFD_OEM_EDATA_TYPE_ASP_SERVICE;
2293         event.event_id = WFD_OEM_EVENT_ASP_SERV_RESP;
2294
2295         if(parameters != NULL) {
2296                 g_variant_get(parameters, "(a{sv})", &iter);
2297                 if(iter != NULL) {
2298                         dbus_property_foreach(iter, __ws_extract_serviceaspresponse_details, &event);
2299                         g_variant_iter_free(iter);
2300                 }
2301         } else {
2302                 WDP_LOGE("No Properties");
2303         }
2304 GLIST_ITER_START(seek_list, tmp)
2305         if(tmp->tran_id == service->tran_id) {
2306                 WDP_LOGD("srv_trans_id matched [%d] search_id [%llu]"
2307                                 ,tmp->tran_id, tmp->search_id);
2308                 service->search_id = tmp->search_id;
2309                 break;
2310         } else {
2311                 tmp = NULL;
2312         }
2313 GLIST_ITER_END()
2314
2315         if(tmp->service_info != NULL)
2316                 g_pd->callback(g_pd->user_data, &event);
2317         else
2318                 WDP_LOGD("service info is not required, don't notify to user");
2319
2320         g_free(service->service_type);
2321         g_free(service->service_info);
2322         g_free(service);
2323
2324         __WDP_LOG_FUNC_EXIT__;
2325 }
2326 #endif /* TIZEN_FEATURE_ASP */
2327
2328 static void _ws_process_persistent_group_added(GDBusConnection *connection,
2329                 const gchar *object_path, GVariant *parameters)
2330 {
2331         __WDP_LOG_FUNC_ENTER__;
2332         wfd_oem_event_s event;
2333         memset(&event, 0x0, sizeof(wfd_oem_event_s));
2334
2335 //      g_pd->callback(g_pd->user_data, &event);
2336
2337         __WDP_LOG_FUNC_EXIT__;
2338 }
2339
2340 static void _ws_process_persistent_group_removed(GDBusConnection *connection,
2341                 const gchar *object_path, GVariant *parameters)
2342 {
2343         __WDP_LOG_FUNC_ENTER__;
2344         wfd_oem_event_s event;
2345         memset(&event, 0x0, sizeof(wfd_oem_event_s));
2346
2347 //      g_pd->callback(g_pd->user_data, &event);
2348
2349         __WDP_LOG_FUNC_EXIT__;
2350 }
2351
2352 static void _ws_process_wps_failed(GDBusConnection *connection,
2353                 const gchar *object_path, GVariant *parameters)
2354 {
2355         __WDP_LOG_FUNC_ENTER__;
2356         GVariantIter *iter = NULL;
2357         wfd_oem_event_s event;
2358         const char *name = NULL;
2359
2360         memset(&event, 0x0, sizeof(wfd_oem_event_s));
2361
2362         event.event_id = WFD_OEM_EVENT_WPS_FAIL;
2363         event.edata_type = WFD_OEM_EDATA_TYPE_NONE;
2364
2365         g_variant_get(parameters, "(&sa{sv})", &name, &iter);
2366
2367         WDP_LOGD("code [%s]", name);
2368
2369         if (iter != NULL) {
2370
2371                 gchar *key = NULL;
2372                 GVariant *value = NULL;
2373
2374                 while (g_variant_iter_loop(iter, "{sv}", &key, &value)) {
2375 #if defined (TIZEN_DEBUG_DBUS_VALUE)
2376                         CHECK_KEY_VALUE(key, value);
2377 #endif /* TIZEN_DEBUG_DBUS_VALUE */
2378                 }
2379                 g_variant_iter_free(iter);
2380         }
2381
2382         g_pd->callback(g_pd->user_data, &event);
2383
2384         __WDP_LOG_FUNC_EXIT__;
2385 }
2386
2387 static void _ws_process_group_formation_failure(GDBusConnection *connection,
2388                 const gchar *object_path, GVariant *parameters)
2389 {
2390         __WDP_LOG_FUNC_ENTER__;
2391         wfd_oem_event_s event;
2392
2393         memset(&event, 0x0, sizeof(wfd_oem_event_s));
2394
2395         event.event_id = WFD_OEM_EVENT_GROUP_FORMATION_FAILURE;
2396         event.edata_type = WFD_OEM_EDATA_TYPE_NONE;
2397
2398         g_pd->callback(g_pd->user_data, &event);
2399
2400         __WDP_LOG_FUNC_EXIT__;
2401 }
2402
2403 static void _ws_process_invitation_accepted(GDBusConnection *connection,
2404                 const gchar *object_path, GVariant *parameters)
2405 {
2406         __WDP_LOG_FUNC_ENTER__;
2407         GVariantIter *iter = NULL;
2408         wfd_oem_event_s event;
2409
2410         memset(&event, 0x0, sizeof(wfd_oem_event_s));
2411
2412         event.event_id = WFD_OEM_EVENT_INVITATION_ACCEPTED;
2413         event.edata_type = WFD_OEM_EDATA_TYPE_NONE;
2414
2415         if (parameters != NULL) {
2416                 g_variant_get(parameters, "(a{sv})", &iter);
2417
2418                 if (iter != NULL) {
2419                         gchar *key = NULL;
2420                         GVariant *value = NULL;
2421
2422                         while (g_variant_iter_loop(iter, "{sv}", &key, &value)) {
2423                                 CHECK_KEY_VALUE(key, value);
2424                                 if(g_strcmp0(key, "sa") == 0)
2425                                         if (__ws_unpack_ay(event.dev_addr, value, WS_MACADDR_LEN))
2426                                                 WDP_LOGI("[" MACSTR "]", MAC2STR(event.dev_addr));
2427                         }
2428                         g_variant_iter_free(iter);
2429                 }
2430         }
2431
2432         g_pd->callback(g_pd->user_data, &event);
2433         __WDP_LOG_FUNC_EXIT__;
2434 }
2435
2436 #if defined(TIZEN_FEATURE_ASP)
2437 static void _ws_process_asp_provision_start(GDBusConnection *connection,
2438                 const gchar *object_path, GVariant *parameters)
2439 {
2440         __WDP_LOG_FUNC_ENTER__;
2441         GVariantIter *iter = NULL;
2442         wfd_oem_event_s event;
2443         wfd_oem_asp_prov_s *edata;
2444
2445         edata = (wfd_oem_asp_prov_s *) g_try_malloc0(sizeof(wfd_oem_asp_prov_s));
2446         if (!edata) {
2447                 WDP_LOGF("Failed to allocate memory for event. [%s]",
2448                                 strerror(errno));
2449                 __WDP_LOG_FUNC_EXIT__;
2450                 return;
2451         }
2452         memset(&event, 0x0, sizeof(wfd_oem_event_s));
2453
2454         event.edata = (void*) edata;
2455         event.event_id = WFD_OEM_EVENT_ASP_PROV_START;
2456
2457         if (parameters != NULL) {
2458                 g_variant_get(parameters, "(a{sv})", &iter);
2459                 if (iter != NULL) {
2460                         dbus_property_foreach(iter, __ws_extract_asp_provision_start_details, &event);
2461                         event.edata_type = WFD_OEM_EDATA_TYPE_ASP_PROV;
2462                         g_variant_iter_free(iter);
2463                 }
2464         } else {
2465                 WDP_LOGE("No Properties");
2466         }
2467
2468         g_pd->callback(g_pd->user_data, &event);
2469
2470         if (event.edata_type == WFD_OEM_EDATA_TYPE_ASP_PROV)
2471                 g_free(edata->session_information);
2472         g_free(edata);
2473
2474         __WDP_LOG_FUNC_EXIT__;
2475 }
2476
2477 static void _ws_process_asp_provision_done(GDBusConnection *connection,
2478                 const gchar *object_path, GVariant *parameters)
2479 {
2480         __WDP_LOG_FUNC_ENTER__;
2481         GVariantIter *iter = NULL;
2482         wfd_oem_event_s event;
2483         wfd_oem_asp_prov_s *edata;
2484
2485         edata = (wfd_oem_asp_prov_s *) g_try_malloc0(sizeof(wfd_oem_asp_prov_s));
2486         if (!edata) {
2487                 WDP_LOGF("Failed to allocate memory for event. [%s]",
2488                                 strerror(errno));
2489                 __WDP_LOG_FUNC_EXIT__;
2490                 return;
2491         }
2492         memset(&event, 0x0, sizeof(wfd_oem_event_s));
2493
2494         event.edata = (void*) edata;
2495         event.event_id = WFD_OEM_EVENT_ASP_PROV_DONE;
2496
2497         if (parameters != NULL) {
2498                 g_variant_get(parameters, "(a{sv})", &iter);
2499                 if (iter != NULL) {
2500                         dbus_property_foreach(iter, __ws_extract_asp_provision_done_details, &event);
2501                         event.edata_type = WFD_OEM_EDATA_TYPE_ASP_PROV;
2502                         g_variant_iter_free(iter);
2503                 }
2504         } else {
2505                 WDP_LOGE("No Properties");
2506         }
2507
2508         g_pd->callback(g_pd->user_data, &event);
2509         g_free(edata);
2510
2511         __WDP_LOG_FUNC_EXIT__;
2512 }
2513 #endif /* TIZEN_FEATURE_ASP */
2514
2515 static struct {
2516         const char *interface;
2517         const char *member;
2518         void (*function) (GDBusConnection *connection,const gchar *object_path,
2519                         GVariant *parameters);
2520 } ws_p2pdevice_signal_map[] = {
2521         {
2522                 SUPPLICANT_P2PDEVICE,
2523                 "DeviceFound",
2524                 _ws_process_device_found
2525         },
2526         {
2527                 SUPPLICANT_P2PDEVICE,
2528                 "DeviceLost",
2529                 _ws_process_device_lost
2530         },
2531         {
2532                 SUPPLICANT_P2PDEVICE,
2533                 "FindStopped",
2534                 _ws_process_find_stoppped
2535         },
2536         {
2537                 SUPPLICANT_P2PDEVICE,
2538                 "ProvisionDiscoveryRequestDisplayPin",
2539                 _ws_process_prov_disc_req_display_pin
2540         },
2541         {
2542                 SUPPLICANT_P2PDEVICE,
2543                 "ProvisionDiscoveryResponseDisplayPin",
2544                 _ws_process_prov_disc_resp_display_pin
2545         },
2546         {
2547                 SUPPLICANT_P2PDEVICE,
2548                 "ProvisionDiscoveryRequestEnterPin",
2549                 _ws_process_prov_disc_req_enter_pin
2550         },
2551         {
2552                 SUPPLICANT_P2PDEVICE,
2553                 "ProvisionDiscoveryResponseEnterPin",
2554                 _ws_process_prov_disc_resp_enter_pin
2555         },
2556         {
2557                 SUPPLICANT_P2PDEVICE,
2558                 "ProvisionDiscoveryPBCRequest",
2559                 _ws_process_prov_disc_pbc_req
2560         },
2561         {
2562                 SUPPLICANT_P2PDEVICE,
2563                 "ProvisionDiscoveryPBCResponse",
2564                 _ws_process_prov_disc_pbc_resp
2565         },
2566         {
2567                 SUPPLICANT_P2PDEVICE,
2568                 "ProvisionDiscoveryFailure",
2569                 _ws_process_prov_disc_failure
2570         },
2571         {
2572                 SUPPLICANT_P2PDEVICE,
2573                 "GroupStarted",
2574                 _ws_process_group_started
2575         },
2576         {
2577                 SUPPLICANT_P2PDEVICE,
2578                 "GONegotiationSuccess",
2579                 _ws_process_go_neg_success
2580         },
2581         {
2582                 SUPPLICANT_P2PDEVICE,
2583                 "GONegotiationFailure",
2584                 _ws_process_go_neg_failure
2585         },
2586         {
2587                 SUPPLICANT_P2PDEVICE,
2588                 "GONegotiationRequest",
2589                 _ws_process_go_neg_request
2590         },
2591         {
2592                 SUPPLICANT_P2PDEVICE,
2593                 "InvitationReceived",
2594                 _ws_process_invitation_received
2595         },
2596         {
2597                 SUPPLICANT_P2PDEVICE,
2598                 "InvitationResult",
2599                 _ws_process_invitation_result
2600         },
2601         {
2602                 SUPPLICANT_P2PDEVICE,
2603                 "GroupFinished",
2604                 _ws_process_group_finished
2605         },
2606 #ifdef TIZEN_FEATURE_SERVICE_DISCOVERY
2607         {
2608                 SUPPLICANT_P2PDEVICE,
2609                 "ServiceDiscoveryResponse",
2610                 _ws_process_service_discovery_response
2611         },
2612 #endif /* TIZEN_FEATURE_SERVICE_DISCOVERY */
2613 #if defined(TIZEN_FEATURE_ASP)
2614         {
2615                 SUPPLICANT_P2PDEVICE,
2616                 "ServiceASPResponse",
2617                 _ws_process_service_asp_response
2618         },
2619         {
2620                 SUPPLICANT_P2PDEVICE,
2621                 "ASPProvisionStart",
2622                 _ws_process_asp_provision_start
2623         },
2624         {
2625                 SUPPLICANT_P2PDEVICE,
2626                 "ASPProvisionDone",
2627                 _ws_process_asp_provision_done
2628         },
2629 #endif /* TIZEN_FEATURE_ASP */
2630         {
2631                 SUPPLICANT_P2PDEVICE,
2632                 "PersistentGroupAdded",
2633                 _ws_process_persistent_group_added
2634         },
2635         {
2636                 SUPPLICANT_P2PDEVICE,
2637                 "PersistentGroupRemoved",
2638                 _ws_process_persistent_group_removed
2639         },
2640         {
2641                 SUPPLICANT_P2PDEVICE,
2642                 "WpsFailed",
2643                 _ws_process_wps_failed
2644         },
2645         {
2646                 SUPPLICANT_P2PDEVICE,
2647                 "GroupFormationFailure",
2648                 _ws_process_group_formation_failure
2649         },
2650         {
2651                 SUPPLICANT_P2PDEVICE,
2652                 "InvitationAccepted",
2653                 _ws_process_invitation_accepted
2654         },
2655         {
2656                 NULL,
2657                 NULL,
2658                 NULL
2659         }
2660 };
2661
2662 static void _p2pdevice_signal_cb(GDBusConnection *connection,
2663                 const gchar *sender, const gchar *object_path, const gchar *interface,
2664                 const gchar *signal, GVariant *parameters, gpointer user_data)
2665 {
2666         int i = 0;
2667 #if defined (TIZEN_DEBUG_DBUS_VALUE)
2668         DEBUG_SIGNAL(sender, object_path, interface, signal, parameters);
2669 #endif /* TIZEN_DEBUG_DBUS_VALUE */
2670
2671         if (!g_pd) {
2672                 WDP_LOGE("ws_dbus_plugin_data_s is not created yet");
2673                 return;
2674         }
2675
2676         for (i = 0; ws_p2pdevice_signal_map[i].member != NULL; i++) {
2677                 if (!g_strcmp0(signal, ws_p2pdevice_signal_map[i].member) &&
2678                                 ws_p2pdevice_signal_map[i].function != NULL)
2679                         ws_p2pdevice_signal_map[i].function(connection, object_path, parameters);
2680         }
2681 }
2682
2683
2684 static void __ws_parse_peer_joined(char *peer_path,
2685                 unsigned char *dev_addr, unsigned char *ip_addr, GVariant *parameter)
2686 {
2687         __WDP_LOG_FUNC_ENTER__;
2688
2689         GVariantIter *iter;
2690         static unsigned char peer_dev[WS_MACSTR_LEN] = {'\0',};
2691         const char *path = NULL;
2692         char *loc = NULL;
2693 #ifdef TIZEN_FEATURE_IP_OVER_EAPOL
2694         int i = 0;
2695 #endif /* TIZEN_FEATURE_IP_OVER_EAPOL */
2696
2697         g_variant_get(parameter, "(&oay)", &path, &iter);
2698         g_strlcpy(peer_path, path, DBUS_OBJECT_PATH_MAX);
2699         WDP_LOGD("Retrive Added path [%s]", peer_path);
2700
2701         loc = strrchr(peer_path,'/');
2702         if(loc != NULL)
2703                 __ws_mac_compact_to_normal(loc + 1, peer_dev);
2704         __ws_txt_to_mac(peer_dev, dev_addr);
2705         WDP_LOGD("peer mac [" MACSTR "]", MAC2STR(dev_addr));
2706 #ifdef TIZEN_FEATURE_IP_OVER_EAPOL
2707         for(i = 0; i < OEM_IPADDR_LEN; i++)
2708                 g_variant_iter_loop (iter, "y", &ip_addr[i]);
2709         g_variant_iter_free(iter);
2710
2711         WDP_LOGD("peer ip [" IPSTR "]", IP2STR(ip_addr));
2712 #endif /* TIZEN_FEATURE_IP_OVER_EAPOL */
2713
2714         __WDP_LOG_FUNC_EXIT__;
2715         return;
2716 }
2717
2718
2719 static void _group_signal_cb(GDBusConnection *connection,
2720                 const gchar *sender, const gchar *object_path, const gchar *interface,
2721                 const gchar *signal, GVariant *parameters, gpointer user_data)
2722 {
2723 #if defined (TIZEN_DEBUG_DBUS_VALUE)
2724         DEBUG_SIGNAL(sender, object_path, interface, signal, parameters);
2725 #endif /* TIZEN_DEBUG_DBUS_VALUE */
2726
2727         if (!g_pd) {
2728                 WDP_LOGE("ws_dbus_plugin_data_s is not created yet");
2729                 return;
2730         }
2731
2732         if (!g_strcmp0(signal,"PeerJoined")) {
2733
2734                 wfd_oem_event_s event;
2735                 wfd_oem_dev_data_s *edata = NULL;
2736
2737                 static char peer_path[DBUS_OBJECT_PATH_MAX] = {'\0',};
2738
2739                 edata = (wfd_oem_dev_data_s *) g_try_malloc0(sizeof(wfd_oem_dev_data_s));
2740                 if (!edata) {
2741                         WDP_LOGF("Failed to allocate memory for event. [%s]",
2742                                         strerror(errno));
2743                         __WDP_LOG_FUNC_EXIT__;
2744                         return;
2745                 }
2746                 memset(&event, 0x0, sizeof(wfd_oem_event_s));
2747
2748                 event.edata = (void*) edata;
2749                 event.edata_type = WFD_OEM_EDATA_TYPE_DEVICE;
2750                 event.event_id = WFD_OEM_EVENT_STA_CONNECTED;
2751
2752                 __ws_parse_peer_joined(peer_path, event.dev_addr, event.ip_addr_peer, parameters);
2753
2754                 dbus_property_get_all(peer_path, g_pd->g_dbus, SUPPLICANT_P2P_PEER,
2755                                 __ws_peer_property, event.edata);
2756
2757                 g_pd->callback(g_pd->user_data, &event);
2758                 g_free(edata);
2759
2760         } else if (!g_strcmp0(signal,"PeerDisconnected")) {
2761
2762                 wfd_oem_event_s event;
2763
2764                 static char peer_path[DBUS_OBJECT_PATH_MAX] = {'\0',};
2765
2766                 memset(&event, 0x0, sizeof(wfd_oem_event_s));
2767
2768                 event.edata_type = WFD_OEM_EDATA_TYPE_NONE;
2769                 event.event_id = WFD_OEM_EVENT_STA_DISCONNECTED;
2770
2771                 __ws_path_to_addr(peer_path, event.dev_addr, parameters);
2772
2773                 g_pd->callback(g_pd->user_data, &event);
2774         }
2775 }
2776
2777 static void __register_p2pdevice_signal(GVariant *value, void *user_data)
2778 {
2779         __WDP_LOG_FUNC_ENTER__;
2780         ws_dbus_plugin_data_s * pd_data;
2781         static char interface_path[DBUS_OBJECT_PATH_MAX] = {'\0',};
2782         const char *path = NULL;
2783
2784         if (!g_pd) {
2785                 WDP_LOGE("ws_dbus_plugin_data_s is not created yet");
2786                 return;
2787         }
2788
2789         pd_data = (ws_dbus_plugin_data_s *)g_pd;
2790
2791         g_variant_get(value, "(&o)", &path);
2792         g_strlcpy(interface_path, path, DBUS_OBJECT_PATH_MAX);
2793         g_strlcpy(pd_data->iface_path, path, DBUS_OBJECT_PATH_MAX);
2794
2795         WDP_LOGD("interface object path [%s]", interface_path);
2796         /* subscribe interface p2p signal */
2797         WDP_LOGD("register P2PDevice iface signal");
2798         pd_data->p2pdevice_sub_id = g_dbus_connection_signal_subscribe(
2799                 pd_data->g_dbus,
2800                 SUPPLICANT_SERVICE, /* bus name */
2801                 SUPPLICANT_P2PDEVICE, /* interface */
2802                 NULL, /* member */
2803                 NULL, /* object path */
2804                 NULL, /* arg0 */
2805                 G_DBUS_SIGNAL_FLAGS_NONE,
2806                 _p2pdevice_signal_cb,
2807                 NULL, NULL);
2808         __WDP_LOG_FUNC_EXIT__;
2809 }
2810
2811 static int _ws_create_interface(const char *iface_name, handle_reply function, void *user_data)
2812 {
2813         __WDP_LOG_FUNC_ENTER__;
2814         GDBusConnection *g_dbus = NULL;
2815         GVariantBuilder *builder = NULL;
2816         dbus_method_param_s params;
2817
2818         int res = 0;
2819
2820         if (!g_pd) {
2821                 WDP_LOGE("ws_dbus_plugin_data_s is not created yet");
2822                 return -1;
2823         }
2824
2825         g_dbus = g_pd->g_dbus;
2826         if (!g_dbus) {
2827                 WDP_LOGE("DBus connection is NULL");
2828                 return -1;
2829         }
2830         memset(&params, 0x0, sizeof(dbus_method_param_s));
2831
2832         dbus_set_method_param(&params, "CreateInterface", SUPPLICANT_PATH, g_dbus);
2833
2834         builder = g_variant_builder_new(G_VARIANT_TYPE ("a{sv}"));
2835         g_variant_builder_add(builder, "{sv}", "Ifname", g_variant_new_string(iface_name));
2836         g_variant_builder_add(builder, "{sv}", "ConfigFile", g_variant_new_string(CONF_FILE_PATH));
2837         params.params = g_variant_new("(a{sv})", builder);
2838         g_variant_builder_unref(builder);
2839         res = dbus_method_call(&params, SUPPLICANT_INTERFACE, function, user_data);
2840         if (res < 0)
2841                 WDP_LOGE("Failed to send command to wpa_supplicant");
2842         else
2843                 WDP_LOGD("Succeeded to CreateInterface");
2844
2845         __WDP_LOG_FUNC_EXIT__;
2846         return 0;
2847 }
2848
2849 static int _ws_get_interface(const char *iface_name, handle_reply function, void *user_data)
2850 {
2851         __WDP_LOG_FUNC_ENTER__;
2852         GDBusConnection *g_dbus = NULL;
2853         dbus_method_param_s params;
2854         int res = 0;
2855
2856         if (!g_pd) {
2857                 WDP_LOGE("ws_dbus_plugin_data_s is not created yet");
2858                 return -1;
2859         }
2860
2861         g_dbus = g_pd->g_dbus;
2862         if (!g_dbus) {
2863                 WDP_LOGE("DBus connection is NULL");
2864                 return -1;
2865         }
2866
2867         dbus_set_method_param(&params, SUPPLICANT_METHOD_GETINTERFACE,
2868                         SUPPLICANT_PATH, g_pd->g_dbus);
2869
2870         params.params = g_variant_new("(s)", iface_name);
2871 #if defined (TIZEN_DEBUG_DBUS_VALUE)
2872         DEBUG_PARAMS(params.params);
2873 #endif /* TIZEN_DEBUG_DBUS_VALUE */
2874
2875         res = dbus_method_call(&params, SUPPLICANT_INTERFACE,
2876                         function, user_data);
2877
2878         if (res < 0)
2879                 WDP_LOGE("Failed to send command to wpa_supplicant");
2880         else
2881                 WDP_LOGD("Succeeded to get interface");
2882
2883         __WDP_LOG_FUNC_EXIT__;
2884         return res;
2885 }
2886
2887 #if defined (TIZEN_MOBILE) && (TIZEN_WLAN_BOARD_SPRD)
2888 static void __ws_remove_interface(GVariant *value, void *user_data)
2889 {
2890         __WDP_LOG_FUNC_ENTER__;
2891         GDBusConnection *g_dbus = NULL;
2892         dbus_method_param_s params;
2893         const char *path = NULL;
2894         static char interface_path[DBUS_OBJECT_PATH_MAX] = {'\0',};
2895         int res = 0;
2896
2897         if (!g_pd) {
2898                 WDP_LOGE("ws_dbus_plugin_data_s is not created yet");
2899                 return;
2900         }
2901
2902         g_dbus = g_pd->g_dbus;
2903         if (!g_dbus) {
2904                 WDP_LOGE("DBus connection is NULL");
2905                 return;
2906         }
2907
2908         g_variant_get(value, "(&o)", &path);
2909         g_strlcpy(interface_path, path, DBUS_OBJECT_PATH_MAX);
2910         WDP_LOGD("interface object path [%s]", interface_path);
2911
2912         memset(&params, 0x0, sizeof(dbus_method_param_s));
2913
2914         dbus_set_method_param(&params, "RemoveInterface", SUPPLICANT_PATH, g_dbus);
2915         params.params = g_variant_new("(o)", interface_path);
2916
2917         res = dbus_method_call(&params, SUPPLICANT_INTERFACE, NULL, NULL);
2918         if (res < 0)
2919                 WDP_LOGE("Failed to send command to wpa_supplicant");
2920         else
2921                 WDP_LOGD("Succeeded to RemoveInterface");
2922
2923         __WDP_LOG_FUNC_EXIT__;
2924         return;
2925 }
2926 #endif /* (TIZEN_MOBILE) && (TIZEN_WLAN_BOARD_SPRD) */
2927
2928 static int _ws_init_dbus_connection(void)
2929 {
2930         __WDP_LOG_FUNC_ENTER__;
2931         GDBusConnection *conn = NULL;
2932         GError *error = NULL;
2933         int res = 0;
2934
2935         if (!g_pd) {
2936                 WDP_LOGE("ws_dbus_plugin_data_s is not created yet");
2937                 return -1;
2938         }
2939
2940         conn = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, &error);
2941
2942         if (conn == NULL) {
2943                 if(error != NULL){
2944                         WDP_LOGE("Error! Failed to connect to the D-BUS daemon: [%s]",
2945                                         error->message);
2946                         g_error_free(error);
2947                 }
2948                 __WDP_LOG_FUNC_EXIT__;
2949                 return -1;
2950         }
2951
2952         g_pd->g_dbus = conn;
2953
2954         WDP_LOGD("register supplicant signal");
2955         /* subscribe supplicant signal */
2956         g_pd->supp_sub_id = g_dbus_connection_signal_subscribe(
2957                 g_pd->g_dbus,
2958                 SUPPLICANT_SERVICE, /* bus name */
2959                 SUPPLICANT_INTERFACE, /* interface */
2960                 NULL, /* member */
2961                 SUPPLICANT_PATH, /* object path */
2962                 NULL, /* arg0 */
2963                 G_DBUS_SIGNAL_FLAGS_NONE,
2964                 _supplicant_signal_cb,
2965                 NULL, NULL);
2966 #if defined (TIZEN_MOBILE) && (TIZEN_WLAN_BOARD_SPRD)
2967         if(_ws_get_interface(COMMON_IFACE_NAME, NULL, NULL) < 0)
2968                 _ws_create_interface(COMMON_IFACE_NAME, NULL, NULL);
2969         if(_ws_get_interface(P2P_IFACE_NAME, __register_p2pdevice_signal, NULL) < 0)
2970                 res = _ws_create_interface(P2P_IFACE_NAME, __register_p2pdevice_signal, NULL);
2971 #else /* (TIZEN_MOBILE) && (TIZEN_WLAN_BOARD_SPRD) */
2972         if(_ws_get_interface(COMMON_IFACE_NAME, __register_p2pdevice_signal, NULL) < 0)
2973                 res = _ws_create_interface(COMMON_IFACE_NAME, __register_p2pdevice_signal, NULL);
2974 #endif /* (TIZEN_MOBILE) && (TIZEN_WLAN_BOARD_SPRD) */
2975
2976         if (res < 0)
2977                         WDP_LOGE("Failed to subscribe interface signal");
2978         else
2979                 WDP_LOGI("Successfully register signal filters");
2980
2981         __WDP_LOG_FUNC_EXIT__;
2982         return res;
2983 }
2984
2985 static int _ws_deinit_dbus_connection(void)
2986 {
2987         GDBusConnection *g_dbus = NULL;
2988
2989         if (!g_pd) {
2990                 WDP_LOGE("Invalid parameter");
2991                 __WDP_LOG_FUNC_EXIT__;
2992                 return -1;
2993         }
2994
2995         g_dbus = g_pd->g_dbus;
2996         if (!g_dbus) {
2997                 WDP_LOGE("DBus connection is NULL");
2998                 return -1;
2999         }
3000
3001         g_dbus_connection_signal_unsubscribe(g_dbus, g_pd->supp_sub_id);
3002         g_dbus_connection_signal_unsubscribe(g_dbus, g_pd->p2pdevice_sub_id);
3003         g_dbus_connection_signal_unsubscribe(g_dbus, g_pd->group_sub_id);
3004
3005         g_pd->group_iface_sub_id = 0;
3006         g_pd->p2pdevice_sub_id = 0;
3007         g_pd->group_sub_id = 0;
3008         memset(g_pd->group_iface_path, 0x0, DBUS_OBJECT_PATH_MAX);
3009         memset(g_pd->iface_path, 0x0, DBUS_OBJECT_PATH_MAX);
3010
3011         g_object_unref(g_dbus);
3012         return 0;
3013 }
3014
3015 int wfd_plugin_load(wfd_oem_ops_s **ops)
3016 {
3017         if (!ops) {
3018                 WDP_LOGE("Invalid parameter");
3019                 return -1;
3020         }
3021
3022         *ops = &supplicant_ops;
3023
3024         return 0;
3025 }
3026
3027 static int _ws_reset_plugin(ws_dbus_plugin_data_s *f_pd)
3028 {
3029         __WDP_LOG_FUNC_ENTER__;
3030
3031         if (!f_pd) {
3032                 WDP_LOGE("Invalid parameter");
3033                 __WDP_LOG_FUNC_EXIT__;
3034                 return -1;
3035         }
3036
3037         _ws_deinit_dbus_connection();
3038
3039         if (f_pd->activated)
3040                 ws_deactivate(f_pd->concurrent);
3041
3042         g_free(f_pd);
3043
3044         __WDP_LOG_FUNC_EXIT__;
3045         return 0;
3046 }
3047
3048 #ifndef TIZEN_WIFI_MODULE_BUNDLE
3049 static int __ws_check_net_interface(char* if_name)
3050 {
3051         struct ifreq ifr;
3052         int fd;
3053
3054         if (if_name == NULL) {
3055                 WDP_LOGE("Invalid param");
3056                 return -1;
3057         }
3058
3059         fd = socket(PF_INET, SOCK_DGRAM | SOCK_CLOEXEC, 0);
3060         if (fd < 0) {
3061                 WDP_LOGE("socket create error: %d", fd);
3062                 return -2;
3063         }
3064
3065         memset(&ifr, 0, sizeof(ifr));
3066         strncpy(ifr.ifr_name, if_name, sizeof(ifr.ifr_name));
3067         ifr.ifr_name[IFNAMSIZ-1] = '\0';
3068
3069         if (ioctl(fd, SIOCGIFFLAGS, &ifr) < 0) {
3070                 close(fd);
3071                 WDP_LOGE("ioctl error: SIOCGIFFLAGS: %s [ %s ]", strerror(errno), if_name); /* interface is not found. */
3072                 return -3;
3073         }
3074
3075         close(fd);
3076
3077         if (ifr.ifr_flags & IFF_UP) {
3078                 WDP_LOGD("%s interface is up", if_name);
3079                 return 1;
3080         } else if (!(ifr.ifr_flags & IFF_UP)) {
3081                 WDP_LOGD("%s interface is down", if_name);
3082                 return 0;
3083         }
3084         return 0;
3085 }
3086 #endif
3087
3088 int ws_init(wfd_oem_event_cb callback, void *user_data)
3089 {
3090         __WDP_LOG_FUNC_ENTER__;
3091
3092         if (g_pd)
3093                 _ws_reset_plugin(g_pd);
3094
3095         errno = 0;
3096         g_pd = (ws_dbus_plugin_data_s*) g_try_malloc0 (sizeof(ws_dbus_plugin_data_s));
3097         if (!g_pd) {
3098                 WDP_LOGE("Failed to allocate memory for plugin data. [%s]", strerror(errno));
3099                 return -1;
3100         }
3101
3102         g_pd->callback = callback;
3103         g_pd->user_data = user_data;
3104         g_pd->initialized = TRUE;
3105
3106         __WDP_LOG_FUNC_EXIT__;
3107         return 0;
3108 }
3109
3110 int ws_deinit()
3111 {
3112         __WDP_LOG_FUNC_ENTER__;
3113
3114         if (g_pd) {
3115                 _ws_reset_plugin(g_pd);
3116                 g_pd = NULL;
3117         }
3118
3119         __WDP_LOG_FUNC_EXIT__;
3120         return 0;
3121 }
3122
3123 gboolean _ws_util_execute_file(const char *file_path,
3124         char *const args[], char *const envs[])
3125 {
3126         pid_t pid = 0;
3127         int rv = 0;
3128         errno = 0;
3129         register unsigned int index = 0;
3130
3131         while (args[index] != NULL) {
3132                 WDP_LOGD("[%s]", args[index]);
3133                 index++;
3134         }
3135
3136         if (!(pid = fork())) {
3137                 WDP_LOGD("pid(%d), ppid(%d)", getpid(), getppid());
3138                 WDP_LOGD("Inside child, exec (%s) command", file_path);
3139
3140                 errno = 0;
3141                 if (execve(file_path, args, envs) == -1) {
3142                         WDP_LOGE("Fail to execute command (%s)", strerror(errno));
3143                         exit(1);
3144                 }
3145         } else if (pid > 0) {
3146                 if (waitpid(pid, &rv, 0) == -1)
3147                         WDP_LOGD("wait pid (%u) rv (%d)", pid, rv);
3148                 if (WIFEXITED(rv)) {
3149                         WDP_LOGD("exited, rv=%d", WEXITSTATUS(rv));
3150                 } else if (WIFSIGNALED(rv)) {
3151                         WDP_LOGD("killed by signal %d", WTERMSIG(rv));
3152                 } else if (WIFSTOPPED(rv)) {
3153                         WDP_LOGD("stopped by signal %d", WSTOPSIG(rv));
3154                 } else if (WIFCONTINUED(rv)) {
3155                         WDP_LOGD("continued");
3156                 }
3157
3158                 return TRUE;
3159         }
3160
3161         WDP_LOGE("failed to fork (%s)", strerror(errno));
3162         return FALSE;
3163 }
3164
3165 #ifndef TIZEN_WIFI_MODULE_BUNDLE
3166 static int __ws_p2p_firmware_start(void)
3167 {
3168         GError *error = NULL;
3169         GVariant *reply = NULL;
3170         GVariant *param = NULL;
3171         GDBusConnection *connection = NULL;
3172         const char *device = "p2p";
3173
3174         connection = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, &error);
3175         if (connection == NULL) {
3176                 if(error != NULL){
3177                         WDP_LOGE("Error! Failed to connect to the D-BUS daemon: [%s]",
3178                                         error->message);
3179                         g_error_free(error);
3180                 }
3181                 __WDP_LOG_FUNC_EXIT__;
3182                 return -1;
3183         }
3184         param = g_variant_new("(s)", device);
3185
3186         reply = g_dbus_connection_call_sync (connection,
3187                         NETCONFIG_SERVICE, /* bus name */
3188                         NETCONFIG_WIFI_PATH, /* object path */
3189                         NETCONFIG_WIFI_INTERFACE ".Firmware", /* interface name */
3190                         "Start", /* method name */
3191                         param, /* GVariant *params */
3192                         NULL, /* reply_type */
3193                         G_DBUS_CALL_FLAGS_NONE, /* flags */
3194                         NETCONFIG_DBUS_REPLY_TIMEOUT , /* timeout */
3195                         NULL, /* cancellable */
3196                         &error); /* error */
3197
3198         if(error != NULL){
3199                 if(strstr(error->message, ".AlreadyExists") != NULL) {
3200                         WDP_LOGD("p2p already enabled");
3201                         g_error_free(error);
3202
3203                 } else {
3204                         WDP_LOGE("Error! Failed to call net-config method: [%s]",
3205                                         error->message);
3206                         g_error_free(error);
3207                         if(reply)
3208                                  g_variant_unref(reply);
3209                         g_object_unref(connection);
3210                         __WDP_LOG_FUNC_EXIT__;
3211                         return -1;
3212                 }
3213         }
3214         if(reply)
3215                  g_variant_unref(reply);
3216         g_object_unref(connection);
3217         return 0;
3218 }
3219
3220 static int __ws_p2p_firmware_stop(void)
3221 {
3222         GError *error = NULL;
3223         GVariant *reply = NULL;
3224         GVariant *param = NULL;
3225         GDBusConnection *connection = NULL;
3226         const char *device = "p2p";
3227
3228         connection = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, &error);
3229         if (connection == NULL) {
3230                 if(error != NULL){
3231                         WDP_LOGE("Error! Failed to connect to the D-BUS daemon: [%s]",
3232                                         error->message);
3233                         g_error_free(error);
3234                 }
3235                 __WDP_LOG_FUNC_EXIT__;
3236                 return -1;
3237         }
3238         param = g_variant_new("(s)", device);
3239
3240         reply = g_dbus_connection_call_sync (connection,
3241                         NETCONFIG_SERVICE, /* bus name */
3242                         NETCONFIG_WIFI_PATH, /* object path */
3243                         NETCONFIG_WIFI_INTERFACE ".Firmware", /* interface name */
3244                         "Stop", /* method name */
3245                         param, /* GVariant *params */
3246                         NULL, /* reply_type */
3247                         G_DBUS_CALL_FLAGS_NONE, /* flags */
3248                         NETCONFIG_DBUS_REPLY_TIMEOUT , /* timeout */
3249                         NULL, /* cancellable */
3250                         &error); /* error */
3251
3252         if(error != NULL){
3253                 if(strstr(error->message, ".AlreadyExists") != NULL) {
3254                         WDP_LOGD("p2p already disabled");
3255                         g_error_free(error);
3256
3257                 } else {
3258                         WDP_LOGE("Error! Failed to call net-config method: [%s]",
3259                                         error->message);
3260                         g_error_free(error);
3261                         if(reply)
3262                                  g_variant_unref(reply);
3263                         g_object_unref(connection);
3264                         __WDP_LOG_FUNC_EXIT__;
3265                         return -1;
3266                 }
3267         }
3268         if(reply)
3269                  g_variant_unref(reply);
3270         g_object_unref(connection);
3271         return 0;
3272 }
3273 #endif
3274
3275 static int __ws_p2p_supplicant_start(void)
3276 {
3277         gboolean rv = FALSE;
3278         const char *path = "/usr/sbin/p2p_supp.sh";
3279         char *const args[] = { "/usr/sbin/p2p_supp.sh", "start_dbus", NULL };
3280         char *const envs[] = { NULL };
3281
3282         rv = _ws_util_execute_file(path, args, envs);
3283
3284         if (rv != TRUE) {
3285                 WDP_LOGE("Failed to start p2p_supp.sh");
3286                 return -1;
3287         }
3288
3289         WDP_LOGI("Successfully started p2p_supp.sh");
3290         return 0;
3291 }
3292
3293
3294 static int __ws_p2p_supplicant_stop(void)
3295 {
3296         gboolean rv = FALSE;
3297         const char *path = "/usr/sbin/p2p_supp.sh";
3298         char *const args[] = { "/usr/sbin/p2p_supp.sh", "stop", NULL };
3299         char *const envs[] = { NULL };
3300
3301         rv = _ws_util_execute_file(path, args, envs);
3302
3303         if (rv != TRUE) {
3304                 WDP_LOGE("Failed to stop p2p_supp.sh");
3305                 return -1;
3306         }
3307
3308         WDP_LOGI("Successfully stopped p2p_supp.sh");
3309         return 0;
3310 }
3311 #if 0
3312 static int __ws_p2p_on(void)
3313 {
3314         DBusError error;
3315         DBusMessage *reply = NULL;
3316         DBusMessage *message = NULL;
3317         DBusConnection *connection = NULL;
3318
3319         connection = dbus_bus_get(DBUS_BUS_SYSTEM, NULL);
3320         if (connection == NULL) {
3321                 WDP_LOGE("Failed to get system bus");
3322                 return -EIO;
3323         }
3324
3325         message = dbus_message_new_method_call(NETCONFIG_SERVICE,
3326                         NETCONFIG_WIFI_PATH, NETCONFIG_WIFI_INTERFACE, "LoadP2pDriver");
3327         if (message == NULL) {
3328                 WDP_LOGE("Failed DBus method call");
3329                 dbus_connection_unref(connection);
3330                 return -EIO;
3331         }
3332
3333         dbus_error_init(&error);
3334
3335         reply = dbus_connection_send_with_reply_and_block(connection, message,
3336                         NETCONFIG_DBUS_REPLY_TIMEOUT, &error);
3337         if (dbus_error_is_set(&error) == TRUE) {
3338                 if (NULL != strstr(error.message, ".AlreadyExists")) {
3339                         // p2p already enabled
3340                 } else {
3341                         WDP_LOGE("dbus_connection_send_with_reply_and_block() failed. "
3342                                         "DBus error [%s: %s]", error.name, error.message);
3343
3344                         dbus_error_free(&error);
3345                 }
3346
3347                 dbus_error_free(&error);
3348         }
3349
3350         if (reply != NULL)
3351                 dbus_message_unref(reply);
3352
3353         dbus_message_unref(message);
3354         dbus_connection_unref(connection);
3355
3356         return 0;
3357 }
3358
3359 static int __ws_p2p_off(void)
3360 {
3361         DBusError error;
3362         DBusMessage *reply = NULL;
3363         DBusMessage *message = NULL;
3364         DBusConnection *connection = NULL;
3365
3366         connection = dbus_bus_get(DBUS_BUS_SYSTEM, NULL);
3367         if (connection == NULL) {
3368                 WDP_LOGE("Failed to get system bus");
3369                 return -EIO;
3370         }
3371
3372         message = dbus_message_new_method_call(NETCONFIG_SERVICE,
3373                         NETCONFIG_WIFI_PATH, NETCONFIG_WIFI_INTERFACE, "RemoveP2pDriver");
3374         if (message == NULL) {
3375                 WDP_LOGE("Failed DBus method call");
3376                 dbus_connection_unref(connection);
3377                 return -EIO;
3378         }
3379
3380         dbus_error_init(&error);
3381
3382         reply = dbus_connection_send_with_reply_and_block(connection, message,
3383                         NETCONFIG_DBUS_REPLY_TIMEOUT, &error);
3384         if (dbus_error_is_set(&error) == TRUE) {
3385                 if (NULL != strstr(error.message, ".AlreadyExists")) {
3386                         // p2p already disabled
3387                 } else {
3388                         WDP_LOGE("dbus_connection_send_with_reply_and_block() failed. "
3389                                         "DBus error [%s: %s]", error.name, error.message);
3390
3391                         dbus_error_free(&error);
3392                 }
3393
3394                 dbus_error_free(&error);
3395         }
3396
3397         if (reply != NULL)
3398                 dbus_message_unref(reply);
3399
3400         dbus_message_unref(message);
3401         dbus_connection_unref(connection);
3402
3403         return 0;
3404 }
3405 #endif
3406
3407 int __ws_init_p2pdevice()
3408 {
3409         __WDP_LOG_FUNC_ENTER__;
3410         GDBusConnection *g_dbus = NULL;
3411
3412         GVariant *value = NULL;
3413         GVariant *param = NULL;
3414         GVariantBuilder *builder = NULL;
3415         GVariantBuilder *type_builder = NULL;
3416         dbus_method_param_s params;
3417
3418         const char *primary_device_type = PRIMARY_DEVICE_TYPE;
3419
3420 #ifdef TIZEN_FEATURE_IP_OVER_EAPOL
3421         const char *ip_addr_go = DEFAULT_IP_GO;
3422         const char *ip_addr_mask = DEFAULT_IP_MASK;
3423         const char *ip_addr_start = DEFAULT_IP_START;
3424         const char *ip_addr_end = DEFAULT_IP_END;
3425 #endif /* TIZEN_FEATURE_IP_OVER_EAPOL */
3426         int i = 0;
3427         int res = 0;
3428
3429         if (!g_pd) {
3430                 WDP_LOGE("ws_dbus_plugin_data_s is not created yet");
3431                 return -1;
3432         }
3433
3434         for(i = 0; i < WS_DEVTYPE_LEN; i++)
3435                 WDP_LOGD("device type[%02x]", primary_device_type[i]);
3436
3437         g_dbus = g_pd->g_dbus;
3438         if (!g_dbus) {
3439                 WDP_LOGE("DBus connection is NULL");
3440                 return -1;
3441         }
3442         memset(&params, 0x0, sizeof(dbus_method_param_s));
3443
3444         dbus_set_method_param(&params, DBUS_PROPERTIES_METHOD_SET, g_pd->iface_path,
3445                          g_dbus);
3446
3447         builder = g_variant_builder_new (G_VARIANT_TYPE ("a{sv}"));
3448         g_variant_builder_add (builder, "{sv}", "DeviceName",
3449                                         g_variant_new_string(DEFAULT_DEVICE_NAME));
3450
3451         g_variant_builder_add (builder, "{sv}", "GOIntent",
3452                                         g_variant_new_uint32(DEFAULT_GO_INTENT));
3453
3454         g_variant_builder_add (builder, "{sv}", "PersistentReconnect",
3455                                         g_variant_new_boolean(DEFAULT_PERSISTENT_RECONNECT));
3456
3457         g_variant_builder_add (builder, "{sv}", "ListenRegClass",
3458                                         g_variant_new_uint32(DEFAULT_LISTEN_REG_CLASS));
3459
3460         g_variant_builder_add (builder, "{sv}", "ListenChannel",
3461                                         g_variant_new_uint32(DEFAULT_LISTEN_CHANNEL));
3462
3463         g_variant_builder_add (builder, "{sv}", "OperRegClass",
3464                                         g_variant_new_uint32(DEFAULT_OPER_REG_CLASS));
3465
3466         g_variant_builder_add (builder, "{sv}", "OperChannel",
3467                                         g_variant_new_uint32(DEFAULT_OPER_CHANNEL));
3468
3469         g_variant_builder_add (builder, "{sv}", "SsidPostfix",
3470                                         g_variant_new_string(DEFAULT_DEVICE_NAME));
3471
3472         g_variant_builder_add (builder, "{sv}", "NoGroupIface",
3473                                         g_variant_new_boolean(DEFAULT_NO_GROUP_IFACE));
3474
3475         type_builder = g_variant_builder_new (G_VARIANT_TYPE ("ay"));
3476         for(i = 0; i < WS_DEVTYPE_LEN; i++)
3477                 g_variant_builder_add(type_builder, "y", primary_device_type[i]);
3478         g_variant_builder_add (builder, "{sv}", "PrimaryDeviceType",
3479                         g_variant_new ("ay", type_builder));
3480         g_variant_builder_unref (type_builder);
3481 #ifdef TIZEN_FEATURE_IP_OVER_EAPOL
3482         type_builder = g_variant_builder_new (G_VARIANT_TYPE ("ay"));
3483         for(i = 0; i < OEM_IPADDR_LEN; i++)
3484                 g_variant_builder_add(type_builder, "y", ip_addr_go[i]);
3485         g_variant_builder_add (builder, "{sv}", "IpAddrGO",
3486                         g_variant_new ("ay", type_builder));
3487         g_variant_builder_unref (type_builder);
3488
3489         type_builder = g_variant_builder_new (G_VARIANT_TYPE ("ay"));
3490         for(i = 0; i < OEM_IPADDR_LEN; i++)
3491                 g_variant_builder_add(type_builder, "y", ip_addr_mask[i]);
3492         g_variant_builder_add (builder, "{sv}", "IpAddrMask",
3493                         g_variant_new ("ay", type_builder));
3494         g_variant_builder_unref (type_builder);
3495
3496         type_builder = g_variant_builder_new (G_VARIANT_TYPE ("ay"));
3497         for(i = 0; i < OEM_IPADDR_LEN; i++)
3498                 g_variant_builder_add(type_builder, "y", ip_addr_start[i]);
3499         g_variant_builder_add (builder, "{sv}", "IpAddrStart",
3500                         g_variant_new ("ay", type_builder));
3501         g_variant_builder_unref (type_builder);
3502
3503         type_builder = g_variant_builder_new (G_VARIANT_TYPE ("ay"));
3504         for(i = 0; i < OEM_IPADDR_LEN; i++)
3505                 g_variant_builder_add(type_builder, "y", ip_addr_end[i]);
3506         g_variant_builder_add (builder, "{sv}", "IpAddrEnd",
3507                         g_variant_new ("ay", type_builder));
3508         g_variant_builder_unref (type_builder);
3509 #endif /* TIZEN_FEATURE_IP_OVER_EAPOL */
3510         value = g_variant_new ("a{sv}", builder);
3511         g_variant_builder_unref (builder);
3512
3513         param = g_variant_new("(ssv)", SUPPLICANT_P2PDEVICE, "P2PDeviceConfig", value);
3514
3515         params.params = param;
3516 #if defined (TIZEN_DEBUG_DBUS_VALUE)
3517         DEBUG_PARAMS(params.params);
3518 #endif /* TIZEN_DEBUG_DBUS_VALUE */
3519
3520         res = dbus_method_call(&params, DBUS_PROPERTIES_INTERFACE, NULL, NULL);
3521         if (res < 0)
3522                 WDP_LOGE("Failed to send command to wpa_supplicant");
3523         else
3524                 WDP_LOGD("Succeeded to initialize p2pdevice");
3525         __WDP_LOG_FUNC_EXIT__;
3526         return res;
3527 }
3528
3529 int __ws_set_config_methods()
3530 {
3531         __WDP_LOG_FUNC_ENTER__;
3532         GDBusConnection *g_dbus = NULL;
3533
3534         GVariant *value = NULL;
3535         GVariant *param = NULL;
3536
3537         dbus_method_param_s params;
3538         int res = 0;
3539
3540         if (!g_pd) {
3541                 WDP_LOGE("ws_dbus_plugin_data_s is not created yet");
3542                 return -1;
3543         }
3544
3545         g_dbus = g_pd->g_dbus;
3546         if (!g_dbus) {
3547                 WDP_LOGE("DBus connection is NULL");
3548                 return -1;
3549         }
3550         memset(&params, 0x0, sizeof(dbus_method_param_s));
3551
3552         dbus_set_method_param(&params, DBUS_PROPERTIES_METHOD_SET, g_pd->iface_path,
3553                          g_dbus);
3554
3555         value = g_variant_new_string(DEFAULT_CONFIG_METHOD);
3556
3557         param = g_variant_new("(ssv)", SUPPLICANT_WPS, "ConfigMethods", value);
3558         params.params = param;
3559
3560         res = dbus_method_call(&params, DBUS_PROPERTIES_INTERFACE, NULL, NULL);
3561         if (res < 0)
3562                 WDP_LOGE("Failed to send command to wpa_supplicant");
3563         else
3564                 WDP_LOGD("Succeeded to set config method(%s)", DEFAULT_CONFIG_METHOD);
3565
3566         __WDP_LOG_FUNC_EXIT__;
3567         return res;
3568 }
3569
3570 int ws_activate(int concurrent)
3571 {
3572         __WDP_LOG_FUNC_ENTER__;
3573         int res = 0;
3574         int retry_count = 0;
3575
3576         if (!g_pd) {
3577                 WDP_LOGE("ws_dbus_plugin_data_s is not created yet");
3578                 return -1;
3579         }
3580
3581         res = __ws_p2p_supplicant_start();
3582         if (res < 0) {
3583                 res = __ws_p2p_supplicant_stop();
3584                 WDP_LOGI("P2P supplicant stopped with error %d", res);
3585                 __WDP_LOG_FUNC_EXIT__;
3586                 return -1;
3587         }
3588 #ifndef TIZEN_WIFI_MODULE_BUNDLE
3589         while (retry_count < WS_CONN_RETRY_COUNT) {
3590                 /* load wlan driver */
3591                 if(concurrent == 0)
3592                         res = __ws_p2p_firmware_start();
3593                 if (res < 0) {
3594                         WDP_LOGE("Failed to load driver [ret=%d]", res);
3595                         return -1;
3596                 }
3597                 WDP_LOGI("P2P firmware started with error %d", res);
3598
3599                 if (__ws_check_net_interface(COMMON_IFACE_NAME) < 0) {
3600                         usleep(150000); // wait for 150ms
3601                         concurrent = 0;
3602                         retry_count++;
3603                         WDP_LOGE("interface is not up: retry, %d", retry_count);
3604                 } else {
3605                         break;
3606                 }
3607         }
3608 #endif
3609         if (retry_count >= WS_CONN_RETRY_COUNT) {
3610                 WDP_LOGE("Driver loading is failed", res);
3611                 __WDP_LOG_FUNC_EXIT__;
3612                 return -1;
3613         }
3614         if (retry_count > 0) {
3615                 // Give driver marginal time to config net
3616                 WDP_LOGE("Driver loading is done. Wait marginal time for driver");
3617                 sleep(1); // 1s
3618         }
3619
3620         g_pd->concurrent = concurrent;
3621
3622         res = _ws_init_dbus_connection();
3623         if (res < 0) {
3624                 res = __ws_p2p_supplicant_stop();
3625                 WDP_LOGI("[/usr/sbin/p2p_supp.sh stop] returns %d", res);
3626 #ifndef TIZEN_WIFI_MODULE_BUNDLE
3627                 res = __ws_p2p_firmware_stop();
3628                 WDP_LOGI("P2P firmware stopped with error %d", res);
3629 #endif
3630                 __WDP_LOG_FUNC_EXIT__;
3631                 return -1;
3632         }
3633
3634         g_pd->activated = TRUE;
3635         __ws_init_p2pdevice();
3636         __ws_set_config_methods();
3637         seek_list = NULL;
3638
3639         __WDP_LOG_FUNC_EXIT__;
3640         return 0;
3641 }
3642
3643 int ws_deactivate(int concurrent)
3644 {
3645         __WDP_LOG_FUNC_ENTER__;
3646 #if defined(TIZEN_FEATURE_ASP)
3647         wfd_oem_asp_service_s *data = NULL;
3648 #endif /* TIZEN_FEATURE_ASP */
3649         int res = 0;
3650
3651         if (!g_pd) {
3652                 WDP_LOGE("ws_dbus_plugin_data_s is not created yet");
3653                 return -1;
3654         }
3655
3656         if (!g_pd->activated) {
3657                 WDP_LOGE("Wi-Fi Direct is not activated");
3658                 return -1;
3659         }
3660
3661         ws_stop_scan();
3662
3663         g_pd->concurrent = concurrent;
3664 #if defined (TIZEN_MOBILE) && (TIZEN_WLAN_BOARD_SPRD)
3665         _ws_get_interface(P2P_IFACE_NAME, __ws_remove_interface, NULL);
3666         if(concurrent == 0)
3667                 _ws_get_interface(COMMON_IFACE_NAME, __ws_remove_interface, NULL);
3668 #endif /* (TIZEN_MOBILE) && (TIZEN_WLAN_BOARD_SPRD) */
3669
3670         _ws_deinit_dbus_connection();
3671
3672         if(concurrent == 0) {
3673                 res = __ws_p2p_supplicant_stop();
3674                 WDP_LOGI("[/usr/sbin/p2p_supp.sh stop] returns %d", res);
3675 #ifndef TIZEN_WIFI_MODULE_BUNDLE
3676                 res = __ws_p2p_firmware_stop();
3677                 WDP_LOGI("P2P firmware stopped with error %d", res);
3678 #endif
3679         }
3680         g_pd->activated = FALSE;
3681
3682 #if defined(TIZEN_FEATURE_ASP)
3683         GLIST_ITER_START(seek_list, data)
3684
3685         if (data) {
3686                 temp = g_list_next(seek_list);
3687                 seek_list = g_list_remove(seek_list, data);
3688                 g_free(data->service_type);
3689                 g_free(data->service_info);
3690                 g_free(data);
3691         }
3692
3693         GLIST_ITER_END()
3694 #endif /* TIZEN_FEATURE_ASP */
3695         __WDP_LOG_FUNC_EXIT__;
3696         return 0;
3697 }
3698
3699 #if 0
3700 static gboolean _retry_start_scan(gpointer data)
3701 {
3702         __WDP_LOG_FUNC_ENTER__;
3703
3704         WDP_LOGD("Succeeded to start scan");
3705
3706         __WDP_LOG_FUNC_EXIT__;
3707         return 0;
3708 }
3709 #endif
3710
3711 #if defined(TIZEN_FEATURE_ASP)
3712 static void __ws_add_seek_params(GVariantBuilder *builder)
3713 {
3714         GVariantBuilder *outter = NULL;
3715         GVariantBuilder *inner = NULL;
3716         wfd_oem_asp_service_s *data = NULL;
3717         int len = 0;
3718         int i = 0;
3719
3720         if(seek_list == NULL || g_list_length(seek_list) == 0) {
3721                 WDP_LOGD("seek list is NULL");
3722                 return;
3723         }
3724         WDP_LOGD("seek list length [%d]", g_list_length(seek_list));
3725
3726         outter = g_variant_builder_new(G_VARIANT_TYPE("aay"));
3727
3728 GLIST_ITER_START(seek_list, data)
3729         if (data && data->service_type) {
3730                 len = strlen(data->service_type) + 1;
3731                 WDP_LOGD("data [%s] len [%d]", data->service_type, len);
3732                 inner = g_variant_builder_new(G_VARIANT_TYPE("ay"));
3733                 for(i = 0; i < len; i++)
3734                         g_variant_builder_add(inner, "y", data->service_type[i]);
3735                 g_variant_builder_add(outter, "ay", inner);
3736                 g_variant_builder_unref(inner);
3737         }
3738 GLIST_ITER_END()
3739         g_variant_builder_add (builder, "{sv}", "Seek", g_variant_new ("aay", outter));
3740         g_variant_builder_unref(outter);
3741
3742         return;
3743 }
3744 #endif /* TIZEN_FEATURE_ASP */
3745
3746
3747 int ws_start_scan(wfd_oem_scan_param_s *param)
3748 {
3749         __WDP_LOG_FUNC_ENTER__;
3750         GDBusConnection *g_dbus = NULL;
3751         GVariantBuilder *builder = NULL;
3752         GVariant *value = NULL;
3753         dbus_method_param_s params;
3754         int res = 0;
3755
3756         if (!param) {
3757                 WDP_LOGE("Invalid parameter");
3758                 return -1;
3759         }
3760
3761         if (!g_pd) {
3762                 WDP_LOGE("ws_dbus_plugin_data_s is not created yet");
3763                 return -1;
3764         }
3765
3766         g_dbus = g_pd->g_dbus;
3767         if (!g_dbus) {
3768                 WDP_LOGE("DBus connection is NULL");
3769                 return -1;
3770         }
3771         memset(&params, 0x0, sizeof(dbus_method_param_s));
3772
3773         if (param->scan_mode == WFD_OEM_SCAN_MODE_ACTIVE) {
3774
3775                 dbus_set_method_param(&params, "Find",  g_pd->iface_path, g_dbus);
3776
3777                 builder = g_variant_builder_new (G_VARIANT_TYPE ("a{sv}") );
3778
3779                         if (param->scan_time)
3780                                 g_variant_builder_add (builder, "{sv}", "Timeout",
3781                                                         g_variant_new_int32(param->scan_time));
3782                         if (param->scan_type == WFD_OEM_SCAN_TYPE_SOCIAL)
3783                                 g_variant_builder_add (builder, "{sv}", "DiscoveryType",
3784                                                         g_variant_new_string("social"));
3785 #if defined(TIZEN_FEATURE_ASP)
3786                         if(seek_list != NULL)
3787                                 __ws_add_seek_params(builder);
3788 #endif /* TIZEN_FEATURE_ASP */
3789
3790                         value = g_variant_new ("(a{sv})", builder);
3791                         g_variant_builder_unref (builder);
3792         } else {
3793
3794                 dbus_set_method_param(&params, "Listen", g_pd->iface_path, g_dbus);
3795                 value = g_variant_new ("(i)", param->scan_time);
3796         }
3797
3798         params.params = value;
3799 #if defined (TIZEN_DEBUG_DBUS_VALUE)
3800         DEBUG_PARAMS(params.params);
3801 #endif /* TIZEN_DEBUG_DBUS_VALUE */
3802
3803         res = dbus_method_call(&params, SUPPLICANT_P2PDEVICE, NULL, NULL);
3804         if (res < 0)
3805                 WDP_LOGE("Failed to send command to wpa_supplicant");
3806         else
3807                 WDP_LOGD("Succeeded to start scan");
3808
3809         __WDP_LOG_FUNC_EXIT__;
3810         return res;
3811 }
3812
3813 int ws_restart_scan(int freq)
3814 {
3815         __WDP_LOG_FUNC_ENTER__;
3816         GDBusConnection *g_dbus = NULL;
3817         GVariantBuilder *builder = NULL;
3818         GVariant *value = NULL;
3819         dbus_method_param_s params;
3820         int res = 0;
3821
3822         if (!g_pd) {
3823                 WDP_LOGE("ws_dbus_plugin_data_s is not created yet");
3824                 return -1;
3825         }
3826
3827         g_dbus = g_pd->g_dbus;
3828         if (!g_dbus) {
3829                 WDP_LOGE("DBus connection is NULL");
3830                 return -1;
3831         }
3832         memset(&params, 0x0, sizeof(dbus_method_param_s));
3833
3834         dbus_set_method_param(&params, "Find", g_pd->iface_path, g_dbus);
3835
3836         builder = g_variant_builder_new (G_VARIANT_TYPE ("a{sv}") );
3837         g_variant_builder_add (builder, "{sv}", "Timeout", g_variant_new_int32(2));
3838         g_variant_builder_add (builder, "{sv}", "DiscoveryType",
3839                                 g_variant_new_string("social"));
3840         value = g_variant_new ("(a{sv})", builder);
3841         g_variant_builder_unref (builder);
3842
3843         params.params = value;
3844 #if defined (TIZEN_DEBUG_DBUS_VALUE)
3845         DEBUG_PARAMS(params.params);
3846 #endif /* TIZEN_DEBUG_DBUS_VALUE */
3847
3848         res = dbus_method_call(&params, SUPPLICANT_P2PDEVICE, NULL, NULL);
3849         if (res < 0)
3850                 WDP_LOGE("Failed to send command to wpa_supplicant");
3851         else
3852                 WDP_LOGD("Succeeded to start scan");
3853
3854         __WDP_LOG_FUNC_EXIT__;
3855         return res;
3856 }
3857
3858 int ws_stop_scan()
3859 {
3860         __WDP_LOG_FUNC_ENTER__;
3861         GDBusConnection *g_dbus = NULL;
3862         dbus_method_param_s params;
3863         int res = 0;
3864
3865         if (!g_pd) {
3866                 WDP_LOGE("ws_dbus_plugin_data_s is not created yet");
3867                 return -1;
3868         }
3869
3870         g_dbus = g_pd->g_dbus;
3871         if (!g_dbus) {
3872                 WDP_LOGE("DBus connection is NULL");
3873                 return -1;
3874         }
3875         memset(&params, 0x0, sizeof(dbus_method_param_s));
3876
3877         dbus_set_method_param(&params, "StopFind", g_pd->iface_path, g_dbus);
3878         params.params = NULL;
3879
3880         res = dbus_method_call(&params, SUPPLICANT_P2PDEVICE, NULL, NULL);
3881         if (res < 0)
3882                         WDP_LOGE("Failed to send command to wpa_supplicant");
3883         else
3884                 WDP_LOGD("Succeeded to stop scan");
3885
3886         __WDP_LOG_FUNC_EXIT__;
3887         return res;
3888 }
3889
3890 int ws_get_visibility(int *visibility)
3891 {
3892         __WDP_LOG_FUNC_ENTER__;
3893
3894         __WDP_LOG_FUNC_EXIT__;
3895         return 0;
3896 }
3897
3898 int ws_set_visibility(int visibility)
3899 {
3900         __WDP_LOG_FUNC_ENTER__;
3901
3902         __WDP_LOG_FUNC_EXIT__;
3903         return 0;
3904 }
3905
3906 int ws_get_scan_result(GList **peers, int *peer_count)
3907 {
3908         __WDP_LOG_FUNC_ENTER__;
3909
3910         __WDP_LOG_FUNC_EXIT__;
3911         return 0;
3912 }
3913
3914 int ws_get_peer_info(unsigned char *peer_addr, wfd_oem_device_s **peer)
3915 {
3916         __WDP_LOG_FUNC_ENTER__;
3917         GDBusConnection *g_dbus = NULL;
3918         wfd_oem_device_s *ws_dev = NULL;
3919         static char peer_path[DBUS_OBJECT_PATH_MAX] = {'\0',};
3920         int res = 0;
3921
3922         if (!peer_addr || !peer) {
3923                 WDP_LOGE("Invalid parameter");
3924                 return -1;
3925         }
3926
3927         if (!g_pd) {
3928                 WDP_LOGE("ws_dbus_plugin_data_s is not created yet");
3929                 return -1;
3930         }
3931
3932         g_dbus = g_pd->g_dbus;
3933         if (!g_dbus) {
3934                 WDP_LOGE("DBus connection is NULL");
3935                 return -1;
3936         }
3937
3938         ws_dev = (wfd_oem_device_s *) g_try_malloc0(sizeof(wfd_oem_device_s));
3939         if (!ws_dev) {
3940                 WDP_LOGF("Failed to allocate memory device. [%s]",
3941                                 strerror(errno));
3942                 __WDP_LOG_FUNC_EXIT__;
3943                 return -1;
3944         }
3945
3946         g_snprintf(peer_path, DBUS_OBJECT_PATH_MAX, "%s/Peers/"
3947                         COMPACT_MACSTR, g_pd->iface_path, MAC2STR(peer_addr));
3948
3949         WDP_LOGD("get peer path [%s]", peer_path);
3950
3951         res = dbus_property_get_all(peer_path, g_dbus, SUPPLICANT_P2P_PEER,
3952                                 __ws_get_peer_property, ws_dev);
3953
3954         if (res < 0) {
3955                         WDP_LOGE("Failed to send command to wpa_supplicant");
3956                         g_free(ws_dev);
3957                         __WDP_LOG_FUNC_EXIT__;
3958                         return -1;
3959         } else {
3960                 WDP_LOGD("succeeded to get peer info");
3961                 *peer = ws_dev;
3962         }
3963         __WDP_LOG_FUNC_EXIT__;
3964         return 0;
3965 }
3966
3967 int ws_prov_disc_req(unsigned char *peer_addr, wfd_oem_wps_mode_e wps_mode, int join)
3968 {
3969         __WDP_LOG_FUNC_ENTER__;
3970         GDBusConnection *g_dbus = NULL;
3971         GVariant *value = NULL;
3972         dbus_method_param_s params;
3973         static char peer_path[DBUS_OBJECT_PATH_MAX] = {'\0',};
3974         int res = 0;
3975
3976         if (!peer_addr) {
3977                 WDP_LOGE("Invalid parameter");
3978                 __WDP_LOG_FUNC_EXIT__;
3979                 return -1;
3980         }
3981
3982         if (!g_pd) {
3983                 WDP_LOGE("ws_dbus_plugin_data_s is not created yet");
3984                 __WDP_LOG_FUNC_EXIT__;
3985                 return -1;
3986         }
3987
3988         g_dbus = g_pd->g_dbus;
3989         if (!g_dbus) {
3990                 WDP_LOGE("DBus connection is NULL");
3991                 __WDP_LOG_FUNC_EXIT__;
3992                 return -1;
3993         }
3994         memset(&params, 0x0, sizeof(dbus_method_param_s));
3995
3996         dbus_set_method_param(&params, "ProvisionDiscoveryRequest", g_pd->iface_path, g_dbus);
3997
3998         g_snprintf(peer_path, DBUS_OBJECT_PATH_MAX, "%s/Peers/"
3999                         COMPACT_MACSTR, g_pd->iface_path, MAC2STR(peer_addr));
4000         WDP_LOGD("get peer path [%s]", peer_path);
4001
4002         value = g_variant_new ("(os)", peer_path, __ws_wps_to_txt(wps_mode));
4003
4004         params.params = value;
4005 #if defined (TIZEN_DEBUG_DBUS_VALUE)
4006         DEBUG_PARAMS(params.params);
4007 #endif /* TIZEN_DEBUG_DBUS_VALUE */
4008
4009         res = dbus_method_call(&params, SUPPLICANT_P2PDEVICE, NULL, NULL);
4010         if (res < 0)
4011                 WDP_LOGE("Failed to send command to wpa_supplicant");
4012         else
4013                 WDP_LOGD("Succeeded to send prov disc to peer[" MACSTR "]", MAC2STR(peer_addr));
4014
4015         __WDP_LOG_FUNC_EXIT__;
4016         return res;
4017 }
4018
4019 int ws_connect(unsigned char *peer_addr, wfd_oem_conn_param_s *param)
4020 {
4021         __WDP_LOG_FUNC_ENTER__;
4022         GDBusConnection *g_dbus = NULL;
4023         GVariantBuilder *builder = NULL;
4024         GVariant *value = NULL;
4025         dbus_method_param_s params;
4026         static char peer_path[DBUS_OBJECT_PATH_MAX] = {'\0',};
4027         int res = 0;
4028
4029         if (!peer_addr || !param) {
4030                 WDP_LOGE("Invalid parameter");
4031                 __WDP_LOG_FUNC_EXIT__;
4032                 return -1;
4033         }
4034
4035         if (!g_pd) {
4036                 WDP_LOGE("ws_dbus_plugin_data_s is not created yet");
4037                 __WDP_LOG_FUNC_EXIT__;
4038                 return -1;
4039         }
4040
4041         g_dbus = g_pd->g_dbus;
4042         if (!g_dbus) {
4043                 WDP_LOGE("DBus connection is NULL");
4044                 __WDP_LOG_FUNC_EXIT__;
4045                 return -1;
4046         }
4047         memset(&params, 0x0, sizeof(dbus_method_param_s));
4048
4049         dbus_set_method_param(&params, "Connect", g_pd->iface_path, g_dbus);
4050
4051         g_snprintf(peer_path, DBUS_OBJECT_PATH_MAX, "%s/Peers/"
4052                         COMPACT_MACSTR, g_pd->iface_path, MAC2STR(peer_addr));
4053         WDP_LOGD("get peer path [%s]", peer_path);
4054
4055         builder = g_variant_builder_new (G_VARIANT_TYPE ("a{sv}") );
4056         g_variant_builder_add (builder, "{sv}", "peer", g_variant_new_object_path(peer_path));
4057         if (param->conn_flags & WFD_OEM_CONN_TYPE_PERSISTENT)
4058                 g_variant_builder_add (builder, "{sv}", "persistent", g_variant_new_boolean(TRUE));
4059
4060         if (param->conn_flags & WFD_OEM_CONN_TYPE_JOIN)
4061                 g_variant_builder_add (builder, "{sv}", "join", g_variant_new_boolean(TRUE));
4062
4063         if (param->conn_flags& WFD_OEM_CONN_TYPE_AUTH)
4064                 g_variant_builder_add (builder, "{sv}", "autorize_only", g_variant_new_boolean(TRUE));
4065
4066         if (param->wps_pin[0] != '\0')
4067                 g_variant_builder_add (builder, "{sv}", "pin", g_variant_new_string(param->wps_pin));
4068
4069         g_variant_builder_add (builder, "{sv}", "wps_method",
4070                                 g_variant_new_string(__ws_wps_to_txt(param->wps_mode)));
4071
4072         value = g_variant_new ("(a{sv})", builder);
4073         g_variant_builder_unref (builder);
4074
4075         params.params = value;
4076 #if defined (TIZEN_DEBUG_DBUS_VALUE)
4077         DEBUG_PARAMS(params.params);
4078 #endif /* TIZEN_DEBUG_DBUS_VALUE */
4079
4080         res = dbus_method_call(&params, SUPPLICANT_P2PDEVICE, NULL, NULL);
4081         if (res < 0)
4082                 WDP_LOGE("Failed to send command to wpa_supplicant");
4083         else
4084                 WDP_LOGD("Succeeded to send connection command to peer[" MACSTR "]", MAC2STR(peer_addr));
4085
4086         __WDP_LOG_FUNC_EXIT__;
4087         return res;
4088 }
4089
4090 int ws_disconnect(unsigned char *peer_addr)
4091 {
4092         __WDP_LOG_FUNC_ENTER__;
4093         GDBusConnection *g_dbus = NULL;
4094         GVariant *value = NULL;
4095         dbus_method_param_s params;
4096         static char peer_path[DBUS_OBJECT_PATH_MAX] = {'\0',};
4097         int res = 0;
4098
4099         if (!peer_addr) {
4100                 WDP_LOGE("Invalid parameter");
4101                 return -1;
4102         }
4103
4104         if (!g_pd) {
4105                 WDP_LOGE("ws_dbus_plugin_data_s is not created yet");
4106                 return -1;
4107         }
4108
4109         g_dbus = g_pd->g_dbus;
4110         if (!g_dbus) {
4111                 WDP_LOGE("DBus connection is NULL");
4112                 return -1;
4113         }
4114         memset(&params, 0x0, sizeof(dbus_method_param_s));
4115
4116         dbus_set_method_param(&params, "RemoveClient", g_pd->iface_path ,g_dbus);
4117
4118         g_snprintf(peer_path, DBUS_OBJECT_PATH_MAX, "%s/Peers/"
4119                         COMPACT_MACSTR, g_pd->iface_path, MAC2STR(peer_addr));
4120         WDP_LOGE("get peer path [%s]", peer_path);
4121
4122         value = g_variant_new ("(oi)", peer_path, 0);
4123
4124         params.params = value;
4125 #if defined (TIZEN_DEBUG_DBUS_VALUE)
4126         DEBUG_PARAMS(params.params);
4127 #endif /* TIZEN_DEBUG_DBUS_VALUE */
4128
4129         res = dbus_method_call(&params, SUPPLICANT_P2PDEVICE, NULL, NULL);
4130         if (res < 0)
4131                 WDP_LOGE("Failed to send command to wpa_supplicant");
4132         else
4133                 WDP_LOGD("Succeeded to stop scan");
4134
4135         __WDP_LOG_FUNC_EXIT__;
4136         return res;
4137 }
4138
4139 int ws_reject_connection(unsigned char *peer_addr)
4140 {
4141         __WDP_LOG_FUNC_ENTER__;
4142         GDBusConnection *g_dbus = NULL;
4143         GVariant *value = NULL;
4144         dbus_method_param_s params;
4145         static char peer_path[DBUS_OBJECT_PATH_MAX] = {'\0',};
4146         int res = 0;
4147
4148         if (!peer_addr) {
4149                 WDP_LOGE("Invalid parameter");
4150                 __WDP_LOG_FUNC_EXIT__;
4151                 return -1;
4152         }
4153
4154         if (!g_pd) {
4155                 WDP_LOGE("ws_dbus_plugin_data_s is not created yet");
4156                 __WDP_LOG_FUNC_EXIT__;
4157                 return -1;
4158         }
4159
4160         g_dbus = g_pd->g_dbus;
4161         if (!g_dbus) {
4162                 WDP_LOGE("DBus connection is NULL");
4163                 __WDP_LOG_FUNC_EXIT__;
4164                 return -1;
4165         }
4166         memset(&params, 0x0, sizeof(dbus_method_param_s));
4167
4168         dbus_set_method_param(&params, "RejectPeer", g_pd->iface_path ,g_dbus);
4169
4170         g_snprintf(peer_path, DBUS_OBJECT_PATH_MAX, "%s/Peers/"
4171                         COMPACT_MACSTR, g_pd->iface_path, MAC2STR(peer_addr));
4172         WDP_LOGE("get peer path [%s]", peer_path);
4173
4174         value = g_variant_new ("(o)", peer_path);
4175
4176         params.params = value;
4177 #if defined (TIZEN_DEBUG_DBUS_VALUE)
4178         DEBUG_PARAMS(params.params);
4179 #endif /* TIZEN_DEBUG_DBUS_VALUE */
4180
4181         res = dbus_method_call(&params, SUPPLICANT_P2PDEVICE, NULL, NULL);
4182         if (res < 0)
4183                 WDP_LOGE("Failed to send command to wpa_supplicant");
4184         else
4185                 WDP_LOGD("Succeeded to reject peer[" MACSTR "]", MAC2STR(peer_addr));
4186
4187         _ws_flush();
4188         __WDP_LOG_FUNC_EXIT__;
4189         return res;
4190 }
4191
4192 int ws_cancel_connection(unsigned char *peer_addr)
4193 {
4194         __WDP_LOG_FUNC_ENTER__;
4195
4196         _ws_cancel();
4197
4198         __WDP_LOG_FUNC_EXIT__;
4199         return 0;
4200 }
4201
4202 int ws_get_connected_peers(GList **peers, int *peer_count)
4203 {
4204         __WDP_LOG_FUNC_ENTER__;
4205
4206         __WDP_LOG_FUNC_EXIT__;
4207         return 0;
4208 }
4209
4210 int ws_get_pin(char *pin)
4211 {
4212         __WDP_LOG_FUNC_ENTER__;
4213
4214         __WDP_LOG_FUNC_EXIT__;
4215         return 0;
4216 }
4217
4218 int ws_set_pin(char *pin)
4219 {
4220         __WDP_LOG_FUNC_ENTER__;
4221
4222         __WDP_LOG_FUNC_EXIT__;
4223         return 0;
4224 }
4225
4226 static void __ws_get_pin(GVariant *value, void *user_data)
4227 {
4228         __WDP_LOG_FUNC_ENTER__;
4229         const char *pin = NULL;
4230
4231         g_variant_get(value, "(&s)", &pin);
4232         g_strlcpy((char *)user_data, pin, OEM_PINSTR_LEN + 1);
4233
4234         __WDP_LOG_FUNC_EXIT__;
4235         return;
4236 }
4237
4238 int ws_generate_pin(char **pin)
4239 {
4240         __WDP_LOG_FUNC_ENTER__;
4241         GDBusConnection *g_dbus = NULL;
4242         dbus_method_param_s params;
4243         char n_pin[9] = {0,};
4244         int res = 0;
4245
4246         if (!g_pd) {
4247                 WDP_LOGE("ws_dbus_plugin_data_s is not created yet");
4248                 return -1;
4249         }
4250
4251         g_dbus = g_pd->g_dbus;
4252         if (!g_dbus) {
4253                 WDP_LOGE("DBus connection is NULL");
4254                 return -1;
4255         }
4256         memset(&params, 0x0, sizeof(dbus_method_param_s));
4257
4258         dbus_set_method_param(&params, "GeneratePin", g_pd->iface_path ,g_dbus);
4259         params.params = NULL;
4260
4261         res = dbus_method_call(&params, SUPPLICANT_WPS, __ws_get_pin, (void *)n_pin);
4262         if (res < 0)
4263                 WDP_LOGE("Failed to send command to wpa_supplicant");
4264         else
4265                 WDP_LOGD("Succeeded to generate_pin [ %s ]", n_pin);
4266
4267         *pin = strndup(n_pin, OEM_PINSTR_LEN);
4268         __WDP_LOG_FUNC_EXIT__;
4269         return 0;
4270 }
4271
4272 int ws_get_supported_wps_mode()
4273 {
4274         __WDP_LOG_FUNC_ENTER__;
4275
4276         __WDP_LOG_FUNC_EXIT__;
4277         return 0;
4278 }
4279
4280 int _ws_get_persistent_net_id(int *persistent_network_id, const unsigned char *go_dev_mac)
4281 {
4282         __WDP_LOG_FUNC_ENTER__;
4283         int persistent_group_count = 0;
4284         int counter = 0;
4285         int res = 0;
4286
4287         wfd_oem_persistent_group_s *plist = NULL;
4288
4289         res = ws_get_persistent_groups(&plist, &persistent_group_count);
4290         if (res < 0) {
4291                 WDP_LOGE("failed to get persistent groups");
4292                 __WDP_LOG_FUNC_EXIT__;
4293                 return -1;
4294         }
4295
4296         if (persistent_group_count > WS_MAX_PERSISTENT_COUNT) {
4297                 WDP_LOGE("persistent group count greater than max Persistent count");
4298                 persistent_group_count = WS_MAX_PERSISTENT_COUNT;
4299         }
4300
4301         WDP_LOGD("Persistent Group Count=%d", persistent_group_count);
4302
4303         for (counter = 0; counter < persistent_group_count ; counter++) {
4304                 if(!memcmp(go_dev_mac, plist[counter].go_mac_address, WS_MACADDR_LEN)) {
4305                         *persistent_network_id = plist[counter].network_id;
4306                         break;
4307                 } else {
4308                         WDP_LOGD("Invite: Persistent GO[" MACSTR "], GO Addr[" MACSTR "]",
4309                                         MAC2STR(plist[counter].go_mac_address), MAC2STR(go_dev_mac));
4310                 }
4311         }
4312
4313         g_free(plist);
4314         plist = NULL;
4315         WDP_LOGD("persistent network ID : [%d]", *persistent_network_id);
4316
4317         __WDP_LOG_FUNC_EXIT__;
4318         return 0;
4319 }
4320
4321 static void __store_group_iface_path(GVariant *value, void *user_data) {
4322         __WDP_LOG_FUNC_ENTER__;
4323         ws_dbus_plugin_data_s * pd_data;
4324         const char *path = NULL;
4325
4326         if (!g_pd) {
4327                 WDP_LOGE("ws_dbus_plugin_data_s is not created yet");
4328                 return;
4329         }
4330
4331         pd_data = (ws_dbus_plugin_data_s *) g_pd;
4332
4333         g_variant_get(value, "(&o)", &path);
4334         g_strlcpy(pd_data->group_iface_path, path, DBUS_OBJECT_PATH_MAX);
4335
4336         WDP_LOGD("group object path [%s]", pd_data->group_iface_path);
4337         /* subscribe interface p2p signal */
4338 }
4339
4340 int ws_create_group(wfd_oem_group_param_s *param)
4341 {
4342         __WDP_LOG_FUNC_ENTER__;
4343         GDBusConnection *g_dbus = NULL;
4344         GVariantBuilder *builder = NULL;
4345         GVariant *value = NULL;
4346         dbus_method_param_s params;
4347         char persistent_group_obj_path[OBJECT_PATH_MAX] = {0,};
4348         int res = 0;
4349
4350         if (!param) {
4351                 WDP_LOGE("Invalid parameter");
4352                 __WDP_LOG_FUNC_EXIT__;
4353                 return -1;
4354         }
4355
4356         if (!g_pd) {
4357                 WDP_LOGE("ws_dbus_plugin_data_s is not created yet");
4358                 __WDP_LOG_FUNC_EXIT__;
4359                 return -1;
4360         }
4361
4362         g_dbus = g_pd->g_dbus;
4363         if (!g_dbus) {
4364                 WDP_LOGE("DBus connection is NULL");
4365                 __WDP_LOG_FUNC_EXIT__;
4366                 return -1;
4367         }
4368         memset(&params, 0x0, sizeof(dbus_method_param_s));
4369
4370         dbus_set_method_param(&params, "GroupAdd", g_pd->iface_path, g_dbus);
4371
4372         builder = g_variant_builder_new (G_VARIANT_TYPE ("a{sv}") );
4373
4374         if (param->persistent > 0) {
4375                 unsigned char mac_address[WS_MACADDR_LEN] = {0x00, };
4376                 int persistent_group_id = -1;
4377
4378                 res = _ws_get_local_dev_mac(mac_address);
4379                 if (res < 0) {
4380                         WDP_LOGE("failed to get local mac address");
4381                         __WDP_LOG_FUNC_EXIT__;
4382                         return -1;
4383                 }
4384
4385                 res = _ws_get_persistent_net_id(&persistent_group_id, mac_address);
4386                 if(res < 0) {
4387                         WDP_LOGE("failed to get persistent group ID");
4388                         __WDP_LOG_FUNC_EXIT__;
4389                         return -1;
4390                 }
4391
4392                 WDP_LOGD("persistent network ID : [%d]", persistent_group_id);
4393
4394                 g_variant_builder_add(builder, "{sv}", "persistent",
4395                                 g_variant_new_boolean(TRUE));
4396                 if(persistent_group_id > -1) {
4397                         g_snprintf(persistent_group_obj_path, OBJECT_PATH_MAX,
4398                                         "%s/" SUPPLICANT_PERSISTENT_GROUPS_PART "/%d",
4399                                         g_pd->iface_path, persistent_group_id);
4400                         g_variant_builder_add(builder, "{sv}", "persistent_group_object",
4401                                         g_variant_new_object_path(persistent_group_obj_path));
4402                 }
4403
4404         } else {
4405                 g_variant_builder_add(builder, "{sv}", "persistent",
4406                                 g_variant_new_boolean(FALSE));
4407         }
4408
4409         if (param->passphrase && strlen(param->passphrase) > 0)
4410                 g_variant_builder_add(builder, "{sv}", "passphrase",
4411                                 g_variant_new_string(param->passphrase));
4412
4413         if (param->freq)
4414                 g_variant_builder_add(builder, "{sv}", "frequency",
4415                                 g_variant_new_int32(param->freq));
4416
4417         value = g_variant_new ("(a{sv})", builder);
4418         g_variant_builder_unref (builder);
4419
4420         params.params = value;
4421 #if defined (TIZEN_DEBUG_DBUS_VALUE)
4422         DEBUG_PARAMS(params.params);
4423 #endif /* TIZEN_DEBUG_DBUS_VALUE */
4424
4425         res = dbus_method_call(&params, SUPPLICANT_P2PDEVICE,
4426                         __store_group_iface_path, g_pd);
4427         if (res < 0)
4428                 WDP_LOGE("Failed to send command to wpa_supplicant");
4429         else
4430                 WDP_LOGD("Succeeded to add group");
4431
4432         __WDP_LOG_FUNC_EXIT__;
4433         return res;
4434 }
4435
4436 int ws_destroy_group(const char *ifname)
4437 {
4438         __WDP_LOG_FUNC_ENTER__;
4439         GDBusConnection *g_dbus = NULL;
4440         dbus_method_param_s params;
4441         int res = 0;
4442
4443         if (!ifname) {
4444                 WDP_LOGE("Invalid parameter");
4445                 return -1;
4446         }
4447
4448         if (!g_pd) {
4449                 WDP_LOGE("ws_dbus_plugin_data_s is not created yet");
4450                 return -1;
4451         }
4452
4453         g_dbus = g_pd->g_dbus;
4454         if (!g_dbus) {
4455                 WDP_LOGE("DBus connection is NULL");
4456                 return -1;
4457         }
4458
4459         if (g_pd->group_iface_path[0] == 0) {
4460                 WDP_LOGE("group iface path is NULL");
4461                 return -1;
4462         }
4463
4464         memset(&params, 0x0, sizeof(dbus_method_param_s));
4465
4466         dbus_set_method_param(&params, "Disconnect", g_pd->group_iface_path, g_dbus);
4467         params.params = NULL;
4468
4469         res = dbus_method_call(&params, SUPPLICANT_P2PDEVICE, NULL, NULL);
4470         if (res < 0) {
4471                 WDP_LOGE("Failed to send command to wpa_supplicant");
4472                 __WDP_LOG_FUNC_EXIT__;
4473                 return -1;
4474         } else {
4475                 _ws_flush();
4476                 WDP_LOGD("Succeeded to remove group");
4477         }
4478
4479         __WDP_LOG_FUNC_EXIT__;
4480         return 0;
4481 }
4482
4483 int ws_invite(unsigned char *peer_addr, wfd_oem_invite_param_s *param)
4484 {
4485         __WDP_LOG_FUNC_ENTER__;
4486         GDBusConnection *g_dbus = NULL;
4487         GVariantBuilder *builder = NULL;
4488         GVariant *value = NULL;
4489         dbus_method_param_s params;
4490         static char peer_path[DBUS_OBJECT_PATH_MAX] = {'\0',};
4491         int res = 0;
4492
4493         if (!peer_addr || !param) {
4494                 WDP_LOGE("Invalid parameter");
4495                 return -1;
4496         }
4497
4498         if (!g_pd) {
4499                 WDP_LOGE("ws_dbus_plugin_data_s is not created yet");
4500                 return -1;
4501         }
4502
4503         g_dbus = g_pd->g_dbus;
4504         if (!g_dbus) {
4505                 WDP_LOGE("DBus connection is NULL");
4506                 return -1;
4507         }
4508         memset(&params, 0x0, sizeof(dbus_method_param_s));
4509
4510         dbus_set_method_param(&params, "Invite", g_pd->group_iface_path, g_dbus);
4511
4512         g_snprintf(peer_path, DBUS_OBJECT_PATH_MAX, "%s/Peers/"
4513                         COMPACT_MACSTR, g_pd->iface_path, MAC2STR(peer_addr));
4514         WDP_LOGE("get peer path [%s]", peer_path);
4515
4516         builder = g_variant_builder_new (G_VARIANT_TYPE ("a{sv}") );
4517         g_variant_builder_add (builder, "{sv}", "peer", g_variant_new_object_path(peer_path));
4518         value = g_variant_new ("(a{sv})", builder);
4519         g_variant_builder_unref (builder);
4520
4521         params.params = value;
4522 #if defined (TIZEN_DEBUG_DBUS_VALUE)
4523         DEBUG_PARAMS(params.params);
4524 #endif /* TIZEN_DEBUG_DBUS_VALUE */
4525
4526         res = dbus_method_call(&params, SUPPLICANT_P2PDEVICE, NULL, NULL);
4527         if (res < 0)
4528                 WDP_LOGE("Failed to send command to wpa_supplicant");
4529         else
4530                 WDP_LOGD("Succeeded to invite peer[" MACSTR "]", MAC2STR(peer_addr));
4531
4532         __WDP_LOG_FUNC_EXIT__;
4533         return 0;
4534 }
4535
4536 // Only group owner can use this command
4537 int ws_wps_start(unsigned char *peer_addr, int wps_mode, const char *pin)
4538 {
4539         __WDP_LOG_FUNC_ENTER__;
4540         GDBusConnection *g_dbus = NULL;
4541         GVariantBuilder *builder = NULL;
4542         GVariant *value = NULL;
4543         GVariant *dev_addr = NULL;
4544         dbus_method_param_s params;
4545         int i = 0;
4546         int res = 0;
4547
4548         if (!g_pd) {
4549                 WDP_LOGE("ws_dbus_plugin_data_s is not created yet");
4550                 return -1;
4551         }
4552
4553         g_dbus = g_pd->g_dbus;
4554         if (!g_dbus) {
4555                 WDP_LOGE("DBus connection is NULL");
4556                 return -1;
4557         }
4558
4559         memset(&params, 0x0, sizeof(dbus_method_param_s));
4560
4561         dbus_set_method_param(&params, "Start", g_pd->group_iface_path, g_dbus);
4562
4563         if (peer_addr != NULL) {
4564                 builder = g_variant_builder_new (G_VARIANT_TYPE ("ay"));
4565                 for(i = 0; i < WS_MACADDR_LEN; i++)
4566                         g_variant_builder_add(builder, "y", peer_addr[i]);
4567
4568                 dev_addr = g_variant_new ("ay", builder);
4569                 g_variant_builder_unref (builder);
4570         }
4571
4572         builder = g_variant_builder_new (G_VARIANT_TYPE ("a{sv}") );
4573         g_variant_builder_add (builder, "{sv}", "Role", g_variant_new_string("enrollee"));
4574         if (peer_addr != NULL)
4575                 g_variant_builder_add (builder, "{sv}", "P2PDeviceAddress", dev_addr);
4576
4577         if (pin != NULL && pin[0] != '\0') {
4578                 g_variant_builder_add (builder, "{sv}", "Type", g_variant_new_string("pin"));
4579                 g_variant_builder_add (builder, "{sv}", "Pin", g_variant_new_string(pin));
4580         } else {
4581                 g_variant_builder_add (builder, "{sv}", "Type", g_variant_new_string("pbc"));
4582         }
4583
4584         value = g_variant_new ("(a{sv})", builder);
4585         g_variant_builder_unref (builder);
4586
4587         params.params = value;
4588 #if defined (TIZEN_DEBUG_DBUS_VALUE)
4589         DEBUG_PARAMS(params.params);
4590 #endif /* TIZEN_DEBUG_DBUS_VALUE */
4591
4592         res = dbus_method_call(&params, SUPPLICANT_WPS, NULL, NULL);
4593         if (res < 0)
4594                 WDP_LOGE("Failed to send command to wpa_supplicant");
4595         else
4596                 WDP_LOGD("Succeeded to run wps");
4597
4598         __WDP_LOG_FUNC_EXIT__;
4599         return 0;
4600 }
4601
4602 int ws_enrollee_start(unsigned char *peer_addr, int wps_mode, const char *pin)
4603 {
4604         __WDP_LOG_FUNC_ENTER__;
4605
4606         WDP_LOGD("Succeeded to start WPS");
4607
4608         __WDP_LOG_FUNC_EXIT__;
4609         return 0;
4610 }
4611
4612 int ws_wps_cancel()
4613 {
4614         __WDP_LOG_FUNC_ENTER__;
4615         GDBusConnection *g_dbus = NULL;
4616         dbus_method_param_s params;
4617         int res = 0;
4618
4619         g_dbus = g_pd->g_dbus;
4620         if (!g_dbus) {
4621                 WDP_LOGE("DBus connection is NULL");
4622                 return -1;
4623         }
4624         memset(&params, 0x0, sizeof(dbus_method_param_s));
4625
4626         dbus_set_method_param(&params, "Cancel", g_pd->group_iface_path, g_dbus);
4627         params.params = NULL;
4628
4629         res = dbus_method_call(&params, SUPPLICANT_WPS, NULL, NULL);
4630         if (res < 0)
4631                 WDP_LOGE("Failed to send command to wpa_supplicant");
4632         else
4633                 WDP_LOGD("Succeeded to cancel WPS");
4634
4635         __WDP_LOG_FUNC_EXIT__;
4636         return 0;
4637 }
4638
4639 int ws_get_dev_name(char *dev_name)
4640 {
4641         __WDP_LOG_FUNC_ENTER__;
4642
4643         __WDP_LOG_FUNC_EXIT__;
4644         return 0;
4645 }
4646
4647 int ws_set_dev_name(char *dev_name)
4648 {
4649         __WDP_LOG_FUNC_ENTER__;
4650         GDBusConnection *g_dbus = NULL;
4651
4652         GVariant *value = NULL;
4653         GVariant *param = NULL;
4654         GVariantBuilder *builder = NULL;
4655         dbus_method_param_s params;
4656         int res = 0;
4657
4658         if (!dev_name) {
4659                 WDP_LOGE("Invalid parameter");
4660                 return -1;
4661         }
4662
4663         if (!g_pd) {
4664                 WDP_LOGE("ws_dbus_plugin_data_s is not created yet");
4665                 return -1;
4666         }
4667
4668         g_dbus = g_pd->g_dbus;
4669         if (!g_dbus) {
4670                 WDP_LOGE("DBus connection is NULL");
4671                 return -1;
4672         }
4673         memset(&params, 0x0, sizeof(dbus_method_param_s));
4674
4675         dbus_set_method_param(&params, DBUS_PROPERTIES_METHOD_SET, g_pd->iface_path,
4676                          g_dbus);
4677
4678         builder = g_variant_builder_new (G_VARIANT_TYPE ("a{sv}"));
4679         g_variant_builder_add (builder, "{sv}", "DeviceName",
4680                                 g_variant_new_string(dev_name));
4681         g_variant_builder_add (builder, "{sv}", "SsidPostfix",
4682                                  g_variant_new_string(dev_name));
4683         value = g_variant_new ("a{sv}", builder);
4684         g_variant_builder_unref (builder);
4685
4686         param = g_variant_new("(ssv)", SUPPLICANT_P2PDEVICE,
4687                                 "P2PDeviceConfig", value);
4688
4689         params.params = param;
4690 #if defined (TIZEN_DEBUG_DBUS_VALUE)
4691         DEBUG_PARAMS(params.params);
4692 #endif /* TIZEN_DEBUG_DBUS_VALUE */
4693
4694         res = dbus_method_call(&params, DBUS_PROPERTIES_INTERFACE, NULL, NULL);
4695         if (res < 0)
4696                 WDP_LOGE("Failed to send command to wpa_supplicant");
4697         else
4698                 WDP_LOGD("Succeeded to set device name");
4699
4700         __WDP_LOG_FUNC_EXIT__;
4701         return res;
4702 }
4703
4704 int ws_get_dev_mac(char *dev_mac)
4705 {
4706         __WDP_LOG_FUNC_ENTER__;
4707
4708         __WDP_LOG_FUNC_EXIT__;
4709         return 0;
4710 }
4711
4712 int ws_get_dev_type(int *pri_dev_type, int *sec_dev_type)
4713 {
4714         __WDP_LOG_FUNC_ENTER__;
4715
4716         __WDP_LOG_FUNC_EXIT__;
4717         return 0;
4718 }
4719
4720 int ws_set_dev_type(int pri_dev_type, int sec_dev_type)
4721 {
4722         __WDP_LOG_FUNC_ENTER__;
4723
4724         __WDP_LOG_FUNC_EXIT__;
4725         return 0;
4726 }
4727
4728 int ws_get_go_intent(int *go_intent)
4729 {
4730         __WDP_LOG_FUNC_ENTER__;
4731         GDBusConnection *g_dbus = NULL;
4732         GVariant *param = NULL;
4733         GVariant *reply = NULL;
4734         GError *error = NULL;
4735         GVariantIter *iter = NULL;
4736
4737
4738         if (!go_intent) {
4739                 WDP_LOGE("Invalid parameter");
4740                 return -1;
4741         }
4742
4743         if (!g_pd) {
4744                 WDP_LOGE("ws_dbus_plugin_data_s is not created yet");
4745                 return -1;
4746         }
4747
4748         g_dbus = g_pd->g_dbus;
4749         if (!g_dbus) {
4750                 WDP_LOGE("DBus connection is NULL");
4751                 return -1;
4752         }
4753
4754         param = g_variant_new("(ss)", SUPPLICANT_P2PDEVICE, "P2PDeviceConfig");
4755 #if defined (TIZEN_DEBUG_DBUS_VALUE)
4756         DEBUG_PARAMS(param);
4757 #endif /* TIZEN_DEBUG_DBUS_VALUE */
4758
4759         reply = g_dbus_connection_call_sync (
4760                         g_dbus,
4761                         SUPPLICANT_SERVICE, /* bus name */
4762                         g_pd->iface_path, /* object path */
4763                         DBUS_PROPERTIES_INTERFACE, /* interface name */
4764                         DBUS_PROPERTIES_METHOD_GET, /* method name */
4765                         param, /* GVariant *params */
4766                         NULL, /* reply_type */
4767                         G_DBUS_CALL_FLAGS_NONE, /* flags */
4768                         SUPPLICANT_TIMEOUT , /* timeout */
4769                         NULL, /* cancellable */
4770                         &error); /* error */
4771
4772         if(error != NULL) {
4773                 WDP_LOGE("Error! Failed to get interface State: [%s]",
4774                                 error->message);
4775                 g_error_free(error);
4776                 if(reply)
4777                         g_variant_unref(reply);
4778                 __WDP_LOG_FUNC_EXIT__;
4779                 return -1;
4780         }
4781
4782         if (reply != NULL) {
4783                 g_variant_get(reply, "(a{sv})", &iter);
4784
4785                 if (iter != NULL) {
4786                         gchar *key = NULL;
4787                         GVariant *value = NULL;
4788
4789                         while (g_variant_iter_loop(iter, "{sv}", &key, &value)) {
4790 #if defined (TIZEN_DEBUG_DBUS_VALUE)
4791                                 CHECK_KEY_VALUE(key, value);
4792 #endif /* TIZEN_DEBUG_DBUS_VALUE */
4793                                 if(g_strcmp0(key, "GOIntent") == 0)
4794                                         g_variant_get(value, "u", go_intent);
4795                         }
4796                         g_variant_iter_free(iter);
4797                 }
4798                 g_variant_unref(reply);
4799         }
4800         __WDP_LOG_FUNC_EXIT__;
4801         return 0;
4802 }
4803
4804 int ws_set_go_intent(int go_intent)
4805 {
4806         __WDP_LOG_FUNC_ENTER__;
4807         GDBusConnection *g_dbus = NULL;
4808
4809         GVariant *value = NULL;
4810         GVariant *param = NULL;
4811         GVariantBuilder *builder = NULL;
4812         dbus_method_param_s params;
4813         int res = 0;
4814
4815         if (!g_pd) {
4816                 WDP_LOGE("ws_dbus_plugin_data_s is not created yet");
4817                 return -1;
4818         }
4819
4820         g_dbus = g_pd->g_dbus;
4821         if (!g_dbus) {
4822                 WDP_LOGE("DBus connection is NULL");
4823                 return -1;
4824         }
4825         memset(&params, 0x0, sizeof(dbus_method_param_s));
4826
4827         dbus_set_method_param(&params, DBUS_PROPERTIES_METHOD_SET, g_pd->iface_path,
4828                          g_dbus);
4829
4830         builder = g_variant_builder_new (G_VARIANT_TYPE ("a{sv}"));
4831         g_variant_builder_add (builder, "{sv}", "GOIntent",
4832                                 g_variant_new_uint32(go_intent));
4833         value = g_variant_new ("a{sv}", builder);
4834         g_variant_builder_unref (builder);
4835
4836         param = g_variant_new("(ssv)", SUPPLICANT_P2PDEVICE, "P2PDeviceConfig", value);
4837
4838         params.params = param;
4839 #if defined (TIZEN_DEBUG_DBUS_VALUE)
4840         DEBUG_PARAMS(params.params);
4841 #endif /* TIZEN_DEBUG_DBUS_VALUE */
4842
4843         res = dbus_method_call(&params, DBUS_PROPERTIES_INTERFACE, NULL, NULL);
4844         if (res < 0)
4845                 WDP_LOGE("Failed to send command to wpa_supplicant");
4846         else
4847                 WDP_LOGE("Succeeded to set go intent");
4848         __WDP_LOG_FUNC_EXIT__;
4849         return res;
4850 }
4851
4852 int ws_set_country(char *ccode)
4853 {
4854         __WDP_LOG_FUNC_ENTER__;
4855         __WDP_LOG_FUNC_ENTER__;
4856         GDBusConnection *g_dbus = NULL;
4857
4858         GVariant *value = NULL;
4859         GVariant *param = NULL;
4860
4861         dbus_method_param_s params;
4862         int res = 0;
4863
4864         if (!g_pd) {
4865                 WDP_LOGE("ws_dbus_plugin_data_s is not created yet");
4866                 return -1;
4867         }
4868
4869         g_dbus = g_pd->g_dbus;
4870         if (!g_dbus) {
4871                 WDP_LOGE("DBus connection is NULL");
4872                 return -1;
4873         }
4874         memset(&params, 0x0, sizeof(dbus_method_param_s));
4875
4876         dbus_set_method_param(&params, DBUS_PROPERTIES_METHOD_SET, g_pd->iface_path,
4877                          g_dbus);
4878
4879         value = g_variant_new_string(ccode);
4880
4881         param = g_variant_new("(ssv)", SUPPLICANT_IFACE, "Country", value);
4882
4883         params.params = param;
4884 #if defined (TIZEN_DEBUG_DBUS_VALUE)
4885         DEBUG_PARAMS(params.params);
4886 #endif /* TIZEN_DEBUG_DBUS_VALUE */
4887
4888         res = dbus_method_call(&params, DBUS_PROPERTIES_INTERFACE, NULL, NULL);
4889         if (res < 0)
4890                 WDP_LOGE("Failed to send command to wpa_supplicant");
4891         else
4892                 WDP_LOGD("Succeeded to set country(%s)", ccode);
4893
4894         __WDP_LOG_FUNC_EXIT__;
4895         return res;
4896 }
4897
4898 void __parsing_networks (const char *key, GVariant *value, void *user_data)
4899 {
4900         __WDP_LOG_FUNC_ENTER__;
4901         if(!user_data) {
4902                 __WDP_LOG_FUNC_EXIT__;
4903                 return;
4904         }
4905
4906         ws_network_info_s *network = (ws_network_info_s *)user_data;
4907 #if defined (TIZEN_DEBUG_DBUS_VALUE)
4908         CHECK_KEY_VALUE(key, value);
4909 #endif /* TIZEN_DEBUG_DBUS_VALUE */
4910         if (g_strcmp0(key, "ssid") == 0) {
4911                 const char *ssid = NULL;
4912                 g_variant_get(value, "&s", &ssid);
4913                 WDP_LOGD("ssid [%s]", ssid);
4914                 g_strlcpy(network->ssid, ssid + 1, WS_SSID_LEN + 1);
4915                 network->ssid[strlen(ssid) - 2] = '\0';
4916
4917         } else if (g_strcmp0(key, "bssid") == 0) {
4918                 unsigned char *bssid = NULL;
4919                 g_variant_get(value, "&s", &bssid);
4920                 WDP_LOGD("bssid [%s]", bssid);
4921                 __ws_txt_to_mac(bssid, network->bssid);
4922
4923         } else if (g_strcmp0(key, "proto") == 0) {
4924                 const char *proto = NULL;
4925                 g_variant_get(value, "&s", &proto);
4926                 WDP_LOGD("proto [%s]", proto);
4927
4928                 if (g_strrstr(proto, WFD_OEM_STR_PROTO_WPA) != NULL)
4929                         network->proto |= WFD_OEM_PROTO_WPA;
4930                 if (g_strrstr(proto, WFD_OEM_STR_PROTO_RSN) != NULL)
4931                         network->proto |= WFD_OEM_PROTO_RSN;
4932
4933         } else if (g_strcmp0(key, "key_mgmt") == 0) {
4934                 const char *key_mgmt = NULL;
4935                 g_variant_get(value, "&s", &key_mgmt);
4936                 WDP_LOGD("key_mgmt [%s]", key_mgmt);
4937
4938                 if (g_strrstr(key_mgmt, WFD_OEM_STR_KEY_MGMT_IEEE8021X) != NULL)
4939                         network->key_mgmt |= WFD_OEM_KEY_MGMT_IEEE8021X;
4940                 if (g_strrstr(key_mgmt, WFD_OEM_STR_KEY_MGMT_PSK) != NULL)
4941                         network->key_mgmt |= WFD_OEM_KEY_MGMT_PSK;
4942                 if (g_strrstr(key_mgmt, WFD_OEM_STR_KEY_MGMT_NONE) != NULL)
4943                         network->key_mgmt |= WFD_OEM_KEY_MGMT_NONE;
4944
4945         } else if (g_strcmp0(key, "pairwise") == 0) {
4946                 const char *pairwise = NULL;
4947                 g_variant_get(value, "&s", &pairwise);
4948                 WDP_LOGD("pairwise [%s]", pairwise);
4949
4950                 if (g_strrstr(pairwise, WFD_OEM_STR_CIPHER_NONE) != NULL)
4951                         network->pairwise |= WFD_OEM_CIPHER_NONE;
4952                 if (g_strrstr(pairwise, WFD_OEM_STR_CIPHER_TKIP) != NULL)
4953                         network->pairwise |= WFD_OEM_CIPHER_TKIP;
4954                 if (g_strrstr(pairwise, WFD_OEM_STR_CIPHER_CCMP) != NULL)
4955                         network->pairwise |= WFD_OEM_CIPHER_CCMP;
4956
4957         }  else if (g_strcmp0(key, "group") == 0) {
4958                 const char *group = NULL;
4959                 g_variant_get(value, "&s", &group);
4960                 WDP_LOGD("group [%s]", group);
4961
4962                 if (g_strrstr(group, WFD_OEM_STR_CIPHER_NONE) != NULL)
4963                         network->group |= WFD_OEM_CIPHER_NONE;
4964                 if (g_strrstr(group, WFD_OEM_STR_CIPHER_WEP40) != NULL)
4965                         network->group |= WFD_OEM_CIPHER_WEP40;
4966                 if (g_strrstr(group, WFD_OEM_STR_CIPHER_WEP104) != NULL)
4967                         network->group |= WFD_OEM_CIPHER_WEP104;
4968                 if (g_strrstr(group, WFD_OEM_STR_CIPHER_TKIP) != NULL)
4969                         network->group |= WFD_OEM_CIPHER_TKIP;
4970                 if (g_strrstr(group, WFD_OEM_STR_CIPHER_CCMP) != NULL)
4971                         network->group |= WFD_OEM_CIPHER_CCMP;
4972
4973         } else if (g_strcmp0(key, "auth_alg") == 0) {
4974                 const char *auth_alg = NULL;
4975                 g_variant_get(value, "&s", &auth_alg);
4976                 WDP_LOGD("auth_alg [%s]", auth_alg);
4977
4978                 if (g_strrstr(auth_alg, WFD_OEM_STR_AUTH_ALG_OPEN) != NULL)
4979                         network->auth_alg |= WFD_OEM_AUTH_ALG_OPEN;
4980
4981         } else if (g_strcmp0(key, "mode") == 0) {
4982                 const char *mode = NULL;
4983                 g_variant_get(value, "&s", &mode);
4984                 WDP_LOGD("mode [%s]", mode);
4985
4986                 if (g_strrstr(mode, WFD_OEM_STR_MODE_GC) != NULL)
4987                         network->mode |= WFD_OEM_PERSISTENT_MODE_GC;
4988                 if (g_strrstr(mode, WFD_OEM_STR_MODE_GO) != NULL)
4989                         network->mode |= WFD_OEM_PERSISTENT_MODE_GO;
4990
4991         } else if (g_strcmp0(key, "p2p_client_list") == 0) {
4992                 const char *p2p_client_list = NULL;
4993                 char *ptr = NULL;
4994                 int list_len = 0;
4995                 int num = 0;
4996
4997                 g_variant_get(value, "&s", &p2p_client_list);
4998                 WDP_LOGD("p2p_client_list [%s]", p2p_client_list);
4999                 ptr = (char *)p2p_client_list;
5000                 list_len = strlen(p2p_client_list);
5001                 WDP_LOGD("list_len [%d]", list_len);
5002                 while (ptr && list_len >= (OEM_MACSTR_LEN - 1)) {
5003                         __ws_txt_to_mac((unsigned char *)ptr, (network->p2p_client_list[num]));
5004                         ptr += OEM_MACSTR_LEN;
5005                         list_len -= OEM_MACSTR_LEN;
5006                         if (ptr && ptr[0] == ' ') {
5007                                 ptr += 1;
5008                                 list_len -= 1;
5009                         }
5010                         num++;
5011                         if (num >= OEM_MAX_PEER_NUM)
5012                                 break;
5013                 }
5014                 network->p2p_client_num = num;
5015                 WDP_LOGD("p2p_client_num [%d]", network->p2p_client_num);
5016         }
5017         return;
5018 }
5019
5020 void __ws_extract_p2pdevice_details(const char *key, GVariant *value, void *user_data)
5021 {
5022         __WDP_LOG_FUNC_ENTER__;
5023 #if defined (TIZEN_DEBUG_DBUS_VALUE)
5024         CHECK_KEY_VALUE(key, value);
5025 #endif /* TIZEN_DEBUG_DBUS_VALUE */
5026         if (g_strcmp0(key, "PersistentGroups") == 0) {
5027                 GVariantIter *iter = NULL;
5028                 const char *path = NULL;
5029                 int num = 0;
5030
5031                 ws_network_info_s *networks = NULL;
5032                 networks = (ws_network_info_s *)user_data;
5033                 if(!networks) {
5034                         WDP_LOGE("network is NULL");
5035                         __WDP_LOG_FUNC_EXIT__;
5036                         return;
5037                 }
5038
5039                 g_variant_get(value, "ao", &iter);
5040                 while(g_variant_iter_loop(iter, "&o", &path)) {
5041                         char *loc = NULL;
5042
5043                         if(num >= WS_MAX_PERSISTENT_COUNT)
5044                                 break;
5045
5046                         WDP_LOGD("Retrive persistent path [%s]", path);
5047                         g_strlcpy(networks[num].persistent_path, path, DBUS_OBJECT_PATH_MAX);
5048
5049                         loc = strrchr(networks[num].persistent_path, '/');
5050                         networks[num].network_id = strtoul(loc+1, NULL, 10);
5051
5052                         WDP_LOGD("Retrive persistent path [%s]", networks[num].persistent_path);
5053                         dbus_property_get_all(networks[num].persistent_path, g_pd->g_dbus,
5054                                         SUPPLICANT_P2P_PERSISTENTGROUP, __parsing_networks, &networks[num]);
5055                         num++;
5056                 }
5057
5058                 networks[0].total = num;
5059                 WDP_LOGI("total number [%d]", num);
5060                 g_variant_iter_free(iter);
5061         }
5062         __WDP_LOG_FUNC_EXIT__;
5063 }
5064
5065
5066 int ws_get_persistent_groups(wfd_oem_persistent_group_s **groups, int *group_count)
5067 {
5068         __WDP_LOG_FUNC_ENTER__;
5069         GDBusConnection *g_dbus = NULL;
5070
5071         ws_network_info_s networks[WS_MAX_PERSISTENT_COUNT];
5072         wfd_oem_persistent_group_s *wfd_persistent_groups = NULL;
5073         int i, cnt = 0;
5074
5075         if (!g_pd) {
5076                 WDP_LOGE("ws_dbus_plugin_data_s is not created yet");
5077                 __WDP_LOG_FUNC_EXIT__;
5078                 return -1;
5079         }
5080
5081         g_dbus = g_pd->g_dbus;
5082         if (!g_dbus) {
5083                 WDP_LOGE("DBus connection is NULL");
5084                 __WDP_LOG_FUNC_EXIT__;
5085                 return -1;
5086         }
5087
5088         memset(&networks, 0x0, WS_MAX_PERSISTENT_COUNT * sizeof(ws_network_info_s));
5089         dbus_property_get_all(g_pd->iface_path, g_dbus, SUPPLICANT_P2PDEVICE,
5090                         __ws_extract_p2pdevice_details, &networks[0]);
5091
5092         cnt = networks[0].total;
5093
5094         WDP_LOGD("Persistent Group Count=%d", cnt);
5095         if (cnt > WS_MAX_PERSISTENT_COUNT) {
5096                 WDP_LOGE("Persistent group count exceeded or parsing error");
5097                 __WDP_LOG_FUNC_EXIT__;
5098                 return -1;
5099         }
5100
5101         if(cnt == 0) {
5102                 WDP_LOGE("Persistent group count zero");
5103                 *group_count = 0;
5104                 *groups = NULL;
5105                 __WDP_LOG_FUNC_EXIT__;
5106                 return 0;
5107         }
5108
5109         wfd_persistent_groups = (wfd_oem_persistent_group_s *) g_try_malloc0(cnt * sizeof(wfd_oem_persistent_group_s));
5110         if (wfd_persistent_groups == NULL) {
5111                 WDP_LOGE("Failed to allocate memory for wfd_persistent_groups ");
5112                 __WDP_LOG_FUNC_EXIT__;
5113                 return -1;
5114         }
5115
5116         for (i = 0; i < cnt; i++) {
5117                 int j = 0;
5118
5119                 WDP_LOGD("----persistent group [%d]----", i);
5120                 WDP_LOGD("network_id [%d]", networks[i].network_id);
5121                 WDP_LOGD("ssid [%s]", networks[i].ssid);
5122                 WDP_LOGD("bssid ["MACSTR"]", MAC2STR(networks[i].bssid));
5123                 WDP_LOGD("p2p_client_num [%d]", networks[i].p2p_client_num);
5124                 for(j = 0; j < networks[i].p2p_client_num; j++)
5125                         WDP_LOGD("p2p_client_list ["MACSTR"]", MAC2STR(networks[i].p2p_client_list[j]));
5126
5127                 wfd_persistent_groups[i].network_id = networks[i].network_id;
5128                 g_strlcpy(wfd_persistent_groups[i].ssid, networks[i].ssid, WS_SSID_LEN + 1);
5129                 memcpy(wfd_persistent_groups[i].go_mac_address, networks[i].bssid, WS_MACADDR_LEN);
5130                 wfd_persistent_groups[i].p2p_client_num = networks[i].p2p_client_num;
5131                 if (wfd_persistent_groups[i].p2p_client_num > 0)
5132                         memcpy(wfd_persistent_groups[i].p2p_client_list, networks[i].p2p_client_list,
5133                                         OEM_MACADDR_LEN * OEM_MAX_PEER_NUM * sizeof(char));
5134         }
5135
5136         *group_count = cnt;
5137         *groups = wfd_persistent_groups;
5138
5139         __WDP_LOG_FUNC_EXIT__;
5140         return 0;
5141 }
5142
5143 int ws_remove_persistent_group(char *ssid, unsigned char *bssid)
5144 {
5145         __WDP_LOG_FUNC_ENTER__;
5146         GDBusConnection *g_dbus = NULL;
5147
5148         dbus_method_param_s params;
5149         ws_network_info_s networks[WS_MAX_PERSISTENT_COUNT];
5150         int i, cnt = 0;
5151         int res = 0;
5152
5153         if (!g_pd) {
5154                 WDP_LOGE("ws_dbus_plugin_data_s is not created yet");
5155                 __WDP_LOG_FUNC_EXIT__;
5156                 return -1;
5157         }
5158
5159         g_dbus = g_pd->g_dbus;
5160         if (!g_dbus) {
5161                 WDP_LOGE("DBus connection is NULL");
5162                 __WDP_LOG_FUNC_EXIT__;
5163                 return -1;
5164         }
5165         dbus_property_get_all(g_pd->iface_path, g_dbus, SUPPLICANT_P2PDEVICE,
5166                         __ws_extract_p2pdevice_details, networks);
5167
5168         cnt = networks[0].total;
5169
5170         WDP_LOGD("Persistent Group Count=%d", cnt);
5171         if (cnt > WS_MAX_PERSISTENT_COUNT) {
5172                 WDP_LOGE("Persistent group count exceeded or parsing error");
5173                 __WDP_LOG_FUNC_EXIT__;
5174                 return -1;
5175         }
5176
5177         for (i = 0; i < cnt; i++) {
5178                 int j = 0;
5179
5180                 WDP_LOGD("----persistent group [%d]----", i);
5181                 WDP_LOGD("network_id [%d]", networks[i].network_id);
5182                 WDP_LOGD("network ssid [%s]", networks[i].ssid);
5183                 WDP_LOGD("network bssid ["MACSTR"]", MAC2STR(networks[i].bssid));
5184                 WDP_LOGD("network p2p_client_num [%d]", networks[i].p2p_client_num);
5185                 for(j = 0; j < networks[i].p2p_client_num; j++)
5186                         WDP_LOGD("network p2p_client_list ["MACSTR"]",
5187                                         MAC2STR(networks[i].p2p_client_list[j]));
5188
5189                 WDP_LOGD("ssid [%s]", ssid);
5190                 WDP_LOGD("bssid ["MACSTR"]", MAC2STR(bssid));
5191
5192                 if (!g_strcmp0(ssid, networks[i].ssid) &&
5193                                 !memcmp(bssid, networks[i].bssid, WS_MACADDR_LEN)) {
5194                         WDP_LOGD("Persistent group owner found [%d: %s]",
5195                                         networks[i].network_id, ssid);
5196
5197                         memset(&params, 0x0, sizeof(dbus_method_param_s));
5198                         dbus_set_method_param(&params, "RemovePersistentGroup",
5199                                         g_pd->iface_path, g_dbus);
5200                         params.params = g_variant_new ("(o)", networks[i].persistent_path);
5201 #if defined (TIZEN_DEBUG_DBUS_VALUE)
5202                         DEBUG_PARAMS(params.params);
5203 #endif /* TIZEN_DEBUG_DBUS_VALUE */
5204
5205                         res = dbus_method_call(&params, SUPPLICANT_P2PDEVICE, NULL, NULL);
5206                         if (res < 0) {
5207                                 WDP_LOGE("Failed to send command to wpa_supplicant");
5208                                 __WDP_LOG_FUNC_EXIT__;
5209                                 return -1;
5210                         }
5211
5212                         WDP_LOGD("Succeeded to remove persistent group");;
5213                         break;
5214                 }
5215         }
5216
5217         if (i == cnt) {
5218                 WDP_LOGE("Persistent group not found [%s]", ssid);
5219                 return -1;
5220         }
5221
5222         __WDP_LOG_FUNC_EXIT__;
5223         return 0;
5224 }
5225
5226 int ws_set_persistent_reconnect(unsigned char *bssid, int reconnect)
5227 {
5228         __WDP_LOG_FUNC_ENTER__;
5229         GDBusConnection *g_dbus = NULL;
5230
5231         GVariant *value = NULL;
5232         GVariant *param = NULL;
5233         GVariantBuilder *builder = NULL;
5234         dbus_method_param_s params;
5235         int res = 0;
5236
5237         if (!g_pd) {
5238                 WDP_LOGE("ws_dbus_plugin_data_s is not created yet");
5239                 return -1;
5240         }
5241
5242         g_dbus = g_pd->g_dbus;
5243         if (!g_dbus) {
5244                 WDP_LOGE("DBus connection is NULL");
5245                 return -1;
5246         }
5247         memset(&params, 0x0, sizeof(dbus_method_param_s));
5248
5249         dbus_set_method_param(&params, DBUS_PROPERTIES_METHOD_SET, g_pd->iface_path,
5250                         g_dbus);
5251
5252         builder = g_variant_builder_new (G_VARIANT_TYPE ("a{sv}"));
5253         g_variant_builder_add (builder, "{sv}", "PersistentReconnect",
5254                                 g_variant_new_boolean(reconnect));
5255         value = g_variant_new ("a{sv}", builder);
5256         g_variant_builder_unref (builder);
5257
5258         param = g_variant_new("(ssv)", SUPPLICANT_P2PDEVICE, "P2PDeviceConfig", value);
5259
5260         params.params = param;
5261 #if defined (TIZEN_DEBUG_DBUS_VALUE)
5262         DEBUG_PARAMS(params.params);
5263 #endif /* TIZEN_DEBUG_DBUS_VALUE */
5264
5265         res = dbus_method_call(&params, DBUS_PROPERTIES_INTERFACE, NULL, NULL);
5266         if (res < 0)
5267                 WDP_LOGE("Failed to send command to wpa_supplicant");
5268         else
5269                 WDP_LOGD("Succeeded to set persistent reconnect");
5270
5271         __WDP_LOG_FUNC_EXIT__;
5272         return res;
5273 }
5274
5275 #ifdef TIZEN_FEATURE_SERVICE_DISCOVERY
5276 static int __ws_compress_query(char *compressed, char *query, int qtype)
5277 {
5278         char *token = NULL;
5279         char *temp = NULL;
5280         int token_num = 0;
5281         int token_len = 0;
5282         int length = 0;
5283
5284         token = strtok_r(query, ".", &temp);
5285         while (token) {
5286                 if (!strcmp(token, "local")) {
5287                         WDP_LOGD("Query conversion done");
5288                         break;
5289
5290                 } else if (!strncmp(token, "_tcp", 4)) {
5291                         memcpy(&compressed[length], WS_TCP_PTR_HEX, 2);
5292                         length+=2;
5293
5294                 } else if (!strncmp(token, "_udp", 4)) {
5295                         memcpy(&compressed[length], WS_UDP_PTR_HEX, 2);
5296                         length+=2;
5297
5298                 } else {
5299                         WDP_LOGD("Token: [%s]", token);
5300                         token_len = strlen(token);
5301                         compressed[length] = token_len;
5302                         length++;
5303
5304                         memcpy(&compressed[length], token, token_len);
5305                         length+=token_len;
5306                 }
5307                 token_num++;
5308                 token = strtok_r(NULL, ".", &temp);
5309         }
5310         if(qtype == WS_QTYPE_PTR || token_num == 2) {
5311                 memcpy(&compressed[length], WS_PTR_TYPE_HEX, 3);
5312         } else if (qtype == WS_QTYPE_TXT || token_num == 3) {
5313                 memcpy(&compressed[length], WS_TXT_TYPE_HEX, 3);
5314         }
5315         length+=3;
5316         WDP_LOGD("converted query length [%d] token num [%d]", length, token_num);
5317
5318         return length;
5319 }
5320
5321 static int __ws_compress_rdata(char *compressed, char *rdata, int qtype)
5322 {
5323         char *token = NULL;
5324         char *temp = NULL;
5325         int token_len = 0;
5326         int length = 0;
5327
5328         if (qtype == WS_QTYPE_PTR) {
5329
5330                 token = strtok_r(rdata, ".", &temp);
5331                 if (token) {
5332                         WDP_LOGD("Token: %s", token);
5333                         token_len = strlen(token);
5334                         compressed[length] = token_len;
5335                         length++;
5336
5337                         memcpy(&compressed[length], token, token_len);
5338                         length+=token_len;
5339                 }
5340
5341                 compressed[length] = 0xc0;
5342                 compressed[length+1] = 0x27;
5343                 length+=2;
5344
5345         } else if (qtype == WS_QTYPE_TXT) {
5346
5347                 token = strtok_r(rdata, ",", &temp);
5348
5349                 while (token) {
5350                         WDP_LOGD("Token: [%s]", token);
5351
5352                         token_len = strlen(token);
5353                         compressed[length] = token_len;
5354                         length++;
5355
5356                         memcpy(&compressed[length], token, token_len);
5357                         length+=token_len;
5358
5359                         token = strtok_r(NULL, ",", &temp);
5360                 }
5361         } else {
5362                 WDP_LOGD("RDATA is NULL");
5363         }
5364         return length;
5365 }
5366
5367 int _convert_bonjour_to_args(char *query, char *rdata, GVariantBuilder *builder)
5368 {
5369         GVariantBuilder *args = NULL;
5370         char compressed[256] = {0, };
5371         char *temp = NULL;
5372         int length = 0;
5373         int qtype = 0;
5374         int i = 0;
5375
5376         if (!query || !builder) {
5377                 WDP_LOGE("Invalid parameter");
5378                 return -1;
5379         }
5380         if (!rdata || !strlen(rdata)) {
5381                 WDP_LOGD("RDATA is NULL\n");
5382         } else {
5383                 temp = strstr(rdata, query);
5384
5385                 if(temp != NULL && temp - rdata > 0)
5386                         qtype = WS_QTYPE_PTR;
5387                 else
5388                         qtype = WS_QTYPE_TXT;
5389                 temp = NULL;
5390         }
5391
5392         g_variant_builder_add (builder, "{sv}", "service_type", g_variant_new_string("bonjour"));
5393
5394         /* compress query */
5395         length = __ws_compress_query(compressed, query, qtype);
5396
5397         args = g_variant_builder_new (G_VARIANT_TYPE ("ay"));
5398         for (i = 0; i < length; i++)
5399                 g_variant_builder_add(args, "y", compressed[i]);
5400         g_variant_builder_add(builder, "{sv}", "query", g_variant_new ("ay", args));
5401         g_variant_builder_unref (args);
5402
5403         memset(compressed, 0x0, 256);
5404         length = 0;
5405         args = NULL;
5406
5407         if(qtype != 0) {
5408                 length = __ws_compress_rdata(compressed, rdata, qtype);
5409
5410                 args = g_variant_builder_new (G_VARIANT_TYPE ("ay"));
5411                 for (i = 0; i < length; i++)
5412                         g_variant_builder_add(args, "y", compressed[i]);
5413                 g_variant_builder_add(builder, "{sv}", "response", g_variant_new ("ay", args));
5414                 g_variant_builder_unref (args);
5415         }
5416
5417         return 0;
5418 }
5419
5420 int _check_service_query_exists(wfd_oem_service_s *service)
5421 {
5422         int count = 0;
5423         wfd_oem_service_s *data = NULL;
5424
5425         for (count = 0; count < g_list_length(service_list); count ++) {
5426                 data = (wfd_oem_service_s*) g_list_nth_data(service_list, count);
5427                 if (strncmp(service->query_id, data->query_id, OEM_QUERY_ID_LEN) == 0) {
5428                         WDP_LOGD("Query already exists");
5429                         return 1;
5430                 }
5431         }
5432         return 0;
5433 }
5434
5435 static wfd_oem_service_s* _remove_service_query(char * s_type, char *mac_str, char *query_id)
5436 {
5437         if (NULL == s_type || NULL == mac_str || NULL == query_id)
5438                 return NULL;
5439
5440         int count = 0;
5441         wfd_oem_service_s *data = NULL;
5442
5443         for (count = 0; count < g_list_length(service_list); count ++) {
5444                 data = (wfd_oem_service_s*) g_list_nth_data(service_list, count);
5445                 if (data && !strncmp(data->service_type, s_type, SERVICE_TYPE_LEN) &&
5446                                 memcmp(data->dev_addr, mac_str, OEM_MACSTR_LEN - 1) == 0) {
5447                         strncpy(query_id, data->query_id, OEM_QUERY_ID_LEN);
5448                         break;
5449                 }
5450         }
5451         if (strlen(query_id) <= 0) {
5452                 WDP_LOGD("!! Query ID not found !!");
5453                 return NULL;
5454         }
5455
5456         WDP_LOGD("query id :[0x%s]",query_id);
5457
5458         return data;
5459 }
5460
5461 void __add_service_query(GVariant *value, void *mac_addr)
5462 {
5463         __WDP_LOG_FUNC_ENTER__;
5464         wfd_oem_service_s *service = NULL;
5465
5466         long long unsigned ref = 0;
5467         unsigned char *mac_address = (unsigned char *)mac_addr;
5468         char mac_str[18] = {0, };
5469
5470         int res = 0;
5471
5472         g_variant_get(value, "(t)", &ref);
5473
5474         service = (wfd_oem_service_s*) g_try_malloc0(sizeof(wfd_oem_service_s));
5475         if (!service) {
5476                 WDP_LOGE("Failed to allocate memory for service");
5477                 return;
5478         }
5479
5480         if (mac_address[0] == 0 && mac_address[1] == 0 && mac_address[2] == 0 &&
5481                         mac_address[3] == 0 && mac_address[4] == 0 && mac_address[5] == 0) {
5482                 g_snprintf(mac_str, WS_MACSTR_LEN , "%s", SERV_BROADCAST_ADDRESS);
5483         } else {
5484                 g_snprintf(mac_str, WS_MACSTR_LEN, MACSTR, MAC2STR(mac_address));
5485         }
5486
5487         g_strlcpy(service->dev_addr, mac_str, OEM_MACSTR_LEN);
5488         g_snprintf(service->query_id, OEM_QUERY_ID_LEN + 1, "0x%llx", ref);
5489
5490         res = _check_service_query_exists(service);
5491         if(res) {
5492                 free(service);
5493         } else {
5494                 service_list = g_list_append(service_list, service);
5495         }
5496
5497         __WDP_LOG_FUNC_EXIT__;
5498         return;
5499
5500 }
5501
5502 /* for now, supplicant dbus interface only provides upnp service fully */
5503 int ws_start_service_discovery(unsigned char *mac_addr, int service_type)
5504 {
5505         __WDP_LOG_FUNC_ENTER__;
5506         GDBusConnection *g_dbus = NULL;
5507         GVariantBuilder *builder = NULL;
5508         GVariant *value = NULL;
5509         dbus_method_param_s params;
5510         static char peer_path[DBUS_OBJECT_PATH_MAX] = {'\0',};
5511         int i = 0;
5512         int res = 0;
5513
5514         if (!mac_addr ) {
5515                 WDP_LOGE("Invalid parameter");
5516                 __WDP_LOG_FUNC_EXIT__;
5517                 return -1;
5518         }
5519
5520         if (!g_pd) {
5521                 WDP_LOGE("ws_dbus_plugin_data_s is not created yet");
5522                 __WDP_LOG_FUNC_EXIT__;
5523                 return -1;
5524         }
5525
5526         g_dbus = g_pd->g_dbus;
5527         if (!g_dbus) {
5528                 WDP_LOGE("DBus connection is NULL");
5529                 __WDP_LOG_FUNC_EXIT__;
5530                 return -1;
5531         }
5532         memset(&params, 0x0, sizeof(dbus_method_param_s));
5533
5534         dbus_set_method_param(&params, "ServiceDiscoveryRequest", g_pd->iface_path, g_dbus);
5535
5536         builder = g_variant_builder_new (G_VARIANT_TYPE ("a{sv}") );
5537
5538         if(mac_addr) {
5539                 g_snprintf(peer_path, DBUS_OBJECT_PATH_MAX, "%s/Peers/"
5540                                 COMPACT_MACSTR, g_pd->iface_path, MAC2STR(mac_addr));
5541                 WDP_LOGD("get peer path [%s]", peer_path);
5542                 g_variant_builder_add (builder, "{sv}", "peer", g_variant_new_object_path(peer_path));
5543         }
5544
5545         if (service_type == WFD_OEM_SERVICE_TYPE_ALL) {
5546
5547                 char *service_all = "\x02\x00\x00\x01";
5548                 GVariantBuilder *query = NULL;
5549
5550                 query = g_variant_builder_new (G_VARIANT_TYPE ("ay"));
5551                 for (i = 0; i < SERVICE_QUERY_LEN; i++)
5552                         g_variant_builder_add(query, "y", service_all[i]);
5553                 g_variant_builder_add (builder, "{sv}", "query", g_variant_new ("ay", query));
5554                 g_variant_builder_unref (query);
5555
5556                 } else if (service_type == WFD_OEM_SERVICE_TYPE_UPNP) {
5557
5558                 g_variant_builder_add (builder, "{sv}", "service_type", g_variant_new_string("upnp"));
5559                 g_variant_builder_add (builder, "{sv}", "version", g_variant_new_uint16(TRUE));
5560
5561         } else if (service_type == WFD_OEM_SERVICE_TYPE_BONJOUR) {
5562
5563                 char *service_bonjour = "\x02\x00\x01\x01";
5564                 GVariantBuilder *query = NULL;
5565
5566                 query = g_variant_builder_new (G_VARIANT_TYPE ("ay"));
5567                 for (i = 0; i < SERVICE_QUERY_LEN; i++)
5568                         g_variant_builder_add(query, "y", service_bonjour[i]);
5569                 g_variant_builder_add (builder, "{sv}", "query", g_variant_new ("ay", query));
5570                 g_variant_builder_unref (query);
5571         }
5572
5573         value = g_variant_new ("(a{sv})", builder);
5574         g_variant_builder_unref (builder);
5575
5576         params.params = value;
5577 #if defined (TIZEN_DEBUG_DBUS_VALUE)
5578         DEBUG_PARAMS(params.params);
5579 #endif /* TIZEN_DEBUG_DBUS_VALUE */
5580
5581         res = dbus_method_call(&params, SUPPLICANT_P2PDEVICE, __add_service_query, mac_addr);
5582         if (res < 0)
5583                 WDP_LOGE("Failed to send command to wpa_supplicant");
5584         else
5585                 WDP_LOGD("Succeeded to start service discovery");
5586
5587         __WDP_LOG_FUNC_EXIT__;
5588         return res;
5589 }
5590
5591 int ws_cancel_service_discovery(unsigned char *mac_addr, int service_type)
5592 {
5593         __WDP_LOG_FUNC_ENTER__;
5594         GDBusConnection *g_dbus = NULL;
5595         dbus_method_param_s params;
5596         wfd_oem_service_s *data = NULL;
5597         char query_id[OEM_QUERY_ID_LEN + 1] = {0, };
5598         char s_type[OEM_SERVICE_TYPE_LEN + 1] ={0, };
5599         char mac_str[18] = {0, };
5600
5601         int res = 0;
5602
5603         if (!mac_addr ) {
5604                 WDP_LOGE("Invalid parameter");
5605                 __WDP_LOG_FUNC_EXIT__;
5606                 return -1;
5607         }
5608
5609         if (!g_pd) {
5610                 WDP_LOGE("ws_dbus_plugin_data_s is not created yet");
5611                 __WDP_LOG_FUNC_EXIT__;
5612                 return -1;
5613         }
5614
5615         g_dbus = g_pd->g_dbus;
5616         if (!g_dbus) {
5617                 WDP_LOGE("DBus connection is NULL");
5618                 __WDP_LOG_FUNC_EXIT__;
5619                 return -1;
5620         }
5621
5622         if (mac_addr[0] == 0 && mac_addr[1] == 0 && mac_addr[2] == 0 &&
5623                 mac_addr[3] == 0 && mac_addr[4] == 0 && mac_addr[5] == 0) {
5624                 snprintf(mac_str, WS_MACSTR_LEN , "%s", SERV_BROADCAST_ADDRESS);
5625         } else {
5626                 snprintf(mac_str, WS_MACSTR_LEN, MACSTR, MAC2STR(mac_addr));
5627         }
5628
5629         switch(service_type) {
5630                 case WFD_OEM_SERVICE_TYPE_ALL:
5631                         strncpy(s_type, SERV_DISC_REQ_ALL, OEM_SERVICE_TYPE_LEN);
5632                 break;
5633                 case WFD_OEM_SERVICE_TYPE_BONJOUR:
5634                         strncpy(s_type, SERV_DISC_REQ_BONJOUR, OEM_SERVICE_TYPE_LEN);
5635                 break;
5636                 case WFD_OEM_SERVICE_TYPE_UPNP:
5637                         strncpy(s_type, SERV_DISC_REQ_UPNP, OEM_SERVICE_TYPE_LEN);
5638                 break;
5639                 default:
5640                         WDP_LOGE("Invalid Service type");
5641                         __WDP_LOG_FUNC_EXIT__;
5642                         return -1;
5643         }
5644
5645         WDP_LOGD("Cancel service discovery service_type [%d]", service_type);
5646         WDP_LOGD("Cancel service discovery s_type [%s]", s_type);
5647
5648         data = _remove_service_query(s_type, mac_str, query_id);
5649         if (NULL == data) {
5650                 __WDP_LOG_FUNC_EXIT__;
5651                 return -1;
5652         }
5653         memset(&params, 0x0, sizeof(dbus_method_param_s));
5654
5655         dbus_set_method_param(&params, "ServiceDiscoveryCancelRequest", g_pd->iface_path, g_dbus);
5656
5657         params.params = g_variant_new ("(t)", strtoul(query_id, NULL, 16));
5658
5659         res = dbus_method_call(&params, SUPPLICANT_P2PDEVICE, NULL, NULL);
5660         if (res < 0)
5661                 WDP_LOGE("Failed to send command to wpa_supplicant");
5662         else
5663                 WDP_LOGD("Succeeded to cancel service discovery");
5664
5665         service_list = g_list_remove(service_list, data);
5666         free(data);
5667
5668         __WDP_LOG_FUNC_EXIT__;
5669         return res;
5670 }
5671
5672 int ws_serv_add(wfd_oem_new_service_s *service)
5673 {
5674         __WDP_LOG_FUNC_ENTER__;
5675         GDBusConnection *g_dbus = NULL;
5676         GVariantBuilder *builder = NULL;
5677         GVariant *value = NULL;
5678         dbus_method_param_s params;
5679         int res = 0;
5680
5681         if (!g_pd) {
5682                 WDP_LOGE("ws_dbus_plugin_data_s is not created yet");
5683                 return -1;
5684         }
5685
5686         g_dbus = g_pd->g_dbus;
5687         if (!g_dbus) {
5688                 WDP_LOGE("DBus connection is NULL");
5689                 return -1;
5690         }
5691         memset(&params, 0x0, sizeof(dbus_method_param_s));
5692
5693         dbus_set_method_param(&params, "AddService", g_pd->iface_path, g_dbus);
5694
5695         builder = g_variant_builder_new (G_VARIANT_TYPE ("a{sv}") );
5696
5697         if (service->protocol == WFD_OEM_SERVICE_TYPE_BONJOUR) {
5698
5699                 WDP_LOGD("Service type: WFD_OEM_SERVICE_TYPE_BONJOUR");
5700                 WDP_LOGD("Query: %s", service->data.bonjour.query);
5701                 WDP_LOGD("RData: %s", service->data.bonjour.rdata);
5702
5703                 res = _convert_bonjour_to_args(service->data.bonjour.query,
5704                                                             service->data.bonjour.rdata, builder);
5705                 if (res < 0) {
5706                         WDP_LOGE("Failed to convert Key string");
5707                         g_variant_builder_unref (builder);
5708                         return -1;
5709                 }
5710
5711         } else if (service->protocol == WFD_OEM_SERVICE_TYPE_UPNP) {
5712                 g_variant_builder_add (builder, "{sv}", "service_type", g_variant_new_string("upnp"));
5713                 g_variant_builder_add (builder, "{sv}", "version", g_variant_new_uint16(TRUE));
5714                 g_variant_builder_add (builder, "{sv}", "service", g_variant_new_string(service->data.upnp.service));
5715         }
5716
5717         value = g_variant_new ("(a{sv})", builder);
5718         g_variant_builder_unref (builder);
5719
5720         params.params = value;
5721 #if defined (TIZEN_DEBUG_DBUS_VALUE)
5722         DEBUG_PARAMS(params.params);
5723 #endif /* TIZEN_DEBUG_DBUS_VALUE */
5724
5725         res = dbus_method_call(&params, SUPPLICANT_P2PDEVICE, NULL, NULL);
5726         if (res < 0)
5727                 WDP_LOGE("Failed to send command to wpa_supplicant");
5728         else
5729                 WDP_LOGD("Succeeded to add service");
5730
5731         __WDP_LOG_FUNC_EXIT__;
5732         return 0;
5733 }
5734
5735 int ws_serv_del(wfd_oem_new_service_s *service)
5736 {
5737         __WDP_LOG_FUNC_ENTER__;
5738         GDBusConnection *g_dbus = NULL;
5739         GVariantBuilder *builder = NULL;
5740         GVariant *value = NULL;
5741         dbus_method_param_s params;
5742         int res = 0;
5743
5744         if (!g_pd) {
5745                 WDP_LOGE("ws_dbus_plugin_data_s is not created yet");
5746                 return -1;
5747         }
5748
5749         g_dbus = g_pd->g_dbus;
5750         if (!g_dbus) {
5751                 WDP_LOGE("DBus connection is NULL");
5752                 return -1;
5753         }
5754         memset(&params, 0x0, sizeof(dbus_method_param_s));
5755
5756         dbus_set_method_param(&params, "DeleteService", g_pd->iface_path, g_dbus);
5757
5758         builder = g_variant_builder_new (G_VARIANT_TYPE ("a{sv}"));
5759
5760         if (service->protocol == WFD_OEM_SERVICE_TYPE_BONJOUR) {
5761
5762                 WDP_LOGD("Service type: WFD_OEM_SERVICE_TYPE_BONJOUR");
5763                 WDP_LOGD("Query: %s", service->data.bonjour.query);
5764
5765                 res = _convert_bonjour_to_args(service->data.bonjour.query,
5766                                                             NULL, builder);
5767                 if (res < 0) {
5768                         WDP_LOGE("Failed to convert Key string");
5769                         g_variant_builder_unref (builder);
5770                         return -1;
5771                 }
5772
5773         } else if (service->protocol == WFD_OEM_SERVICE_TYPE_UPNP) {
5774                 g_variant_builder_add (builder, "{sv}", "service_type", g_variant_new_string("upnp"));
5775                 g_variant_builder_add (builder, "{sv}", "version", g_variant_new_uint16(TRUE));
5776                 g_variant_builder_add (builder, "{sv}", "service", g_variant_new_string(service->data.upnp.service));
5777         }
5778
5779         value = g_variant_new ("(a{sv})", builder);
5780         g_variant_builder_unref (builder);
5781
5782         params.params = value;
5783 #if defined (TIZEN_DEBUG_DBUS_VALUE)
5784         DEBUG_PARAMS(params.params);
5785 #endif /* TIZEN_DEBUG_DBUS_VALUE */
5786
5787         res = dbus_method_call(&params, SUPPLICANT_P2PDEVICE, NULL, NULL);
5788         if (res < 0)
5789                 WDP_LOGE("Failed to send command to wpa_supplicant");
5790         else
5791                 WDP_LOGD("Succeeded to del service");
5792
5793         __WDP_LOG_FUNC_EXIT__;
5794         return 0;
5795 }
5796 #endif /* TIZEN_FEATURE_SERVICE_DISCOVERY */
5797
5798 #ifdef TIZEN_FEATURE_WIFI_DISPLAY
5799
5800 int _ws_disable_display()
5801 {
5802         __WDP_LOG_FUNC_ENTER__;
5803         GDBusConnection *g_dbus = NULL;
5804         GVariantBuilder *builder = NULL;
5805         GVariant *value = NULL;
5806         GVariant *param = NULL;
5807         dbus_method_param_s params;
5808         int res = 0;
5809
5810         if (!g_pd) {
5811                 WDP_LOGE("ws_dbus_plugin_data_s is not created yet");
5812                 return -1;
5813         }
5814
5815         g_dbus = g_pd->g_dbus;
5816         if (!g_dbus) {
5817                 WDP_LOGE("DBus connection is NULL");
5818                 return -1;
5819         }
5820         memset(&params, 0x0, sizeof(dbus_method_param_s));
5821
5822         dbus_set_method_param(&params, DBUS_PROPERTIES_METHOD_SET, SUPPLICANT_PATH,
5823                          g_dbus);
5824
5825         builder = g_variant_builder_new (G_VARIANT_TYPE ("ay"));
5826         value = g_variant_new ("ay", builder);
5827         g_variant_builder_unref (builder);
5828
5829         param = g_variant_new("(ssv)", SUPPLICANT_INTERFACE, "WFDIEs", value);
5830
5831         params.params = param;
5832 #if defined (TIZEN_DEBUG_DBUS_VALUE)
5833         DEBUG_PARAMS(params.params);
5834 #endif /* TIZEN_DEBUG_DBUS_VALUE */
5835
5836         res = dbus_method_call(&params, DBUS_PROPERTIES_INTERFACE, NULL, NULL);
5837         if (res < 0)
5838                 WDP_LOGE("Failed to send command to wpa_supplicant");
5839         else
5840                 WDP_LOGD("Succeeded to disable Wi-Fi display");
5841
5842         __WDP_LOG_FUNC_EXIT__;
5843         return res;
5844 }
5845
5846 int ws_miracast_init(int enable)
5847 {
5848         __WDP_LOG_FUNC_ENTER__;
5849         wfd_oem_display_s wifi_display;
5850         int res = 0;
5851
5852         memset(&wifi_display, 0x0, sizeof(wfd_oem_display_s));
5853
5854         wifi_display.availability = enable;
5855         wifi_display.hdcp_support = 1;
5856         wifi_display.port = 0x07E6;
5857         wifi_display.max_tput = 0x0028;
5858
5859         res = ws_set_display(&wifi_display);
5860         if (res < 0) {
5861                 WDP_LOGE("Failed to set miracast parameter(device info)");
5862                 __WDP_LOG_FUNC_EXIT__;
5863                 return -1;
5864         }
5865
5866         if(!enable) {
5867                 res = _ws_disable_display();
5868                 if (res < 0)
5869                         WDP_LOGE("Failed to disable wifi display");
5870                 else
5871                         WDP_LOGD("Succeeded to disable wifi display");
5872         }
5873         __WDP_LOG_FUNC_EXIT__;
5874         return res;
5875 }
5876
5877 int ws_set_display(wfd_oem_display_s *wifi_display)
5878 {
5879         __WDP_LOG_FUNC_ENTER__;
5880         GDBusConnection *g_dbus = NULL;
5881
5882         GVariant *value = NULL;
5883         GVariant *param = NULL;
5884         GVariantBuilder *builder = NULL;
5885         dbus_method_param_s params;
5886         int i = 0;
5887         int res = 0;
5888
5889         unsigned char ies[WFD_SUBELEM_LEN_DEV_INFO + 3] = {0,};
5890
5891         if (!wifi_display) {
5892                 WDP_LOGE("Invalid parameter");
5893                 return -1;
5894         }
5895         g_dbus = g_pd->g_dbus;
5896         if (!g_dbus) {
5897                 WDP_LOGE("DBus connection is NULL");
5898                 return -1;
5899         }
5900         memset(&params, 0x0, sizeof(dbus_method_param_s));
5901
5902         dbus_set_method_param(&params, DBUS_PROPERTIES_METHOD_SET, SUPPLICANT_PATH,
5903                          g_dbus);
5904
5905         ies[2] = WFD_SUBELEM_LEN_DEV_INFO;
5906         ies[3] = wifi_display->hdcp_support;
5907         ies[4] = (wifi_display->type) | (wifi_display->availability<<4);
5908         ies[5] = wifi_display->port>>8;
5909         ies[6] = wifi_display->port&0xff;
5910         ies[7] = wifi_display->max_tput>>8;
5911         ies[8] = wifi_display->max_tput&0xff;
5912
5913         builder = g_variant_builder_new (G_VARIANT_TYPE ("ay"));
5914         for(i = 0; i < WFD_SUBELEM_LEN_DEV_INFO + 3; i++)
5915                 g_variant_builder_add(builder, "y", ies[i]);
5916         value = g_variant_new ("ay", builder);
5917         g_variant_builder_unref (builder);
5918
5919         param = g_variant_new("(ssv)", SUPPLICANT_INTERFACE, "WFDIEs", value);
5920
5921         params.params = param;
5922 #if defined (TIZEN_DEBUG_DBUS_VALUE)
5923         DEBUG_PARAMS(params.params);
5924 #endif /* TIZEN_DEBUG_DBUS_VALUE */
5925
5926         res = dbus_method_call(&params, DBUS_PROPERTIES_INTERFACE, NULL, NULL);
5927         if (res < 0)
5928                 WDP_LOGE("Failed to send command to wpa_supplicant");
5929         else
5930                 WDP_LOGD("Succeeded to set Wi-Fi Display");
5931
5932         __WDP_LOG_FUNC_EXIT__;
5933         return res;
5934 }
5935 #endif /* TIZEN_FEATURE_WIFI_DISPLAY */
5936
5937 int ws_refresh()
5938 {
5939         __WDP_LOG_FUNC_ENTER__;
5940
5941         _ws_cancel();
5942         _ws_flush();
5943
5944         __WDP_LOG_FUNC_EXIT__;
5945         return 0;
5946 }
5947
5948 int ws_save_config(void)
5949 {
5950         __WDP_LOG_FUNC_ENTER__;
5951         GDBusConnection *g_dbus = NULL;
5952         dbus_method_param_s params;
5953         int res = 0;
5954
5955         g_dbus = g_pd->g_dbus;
5956         if (!g_dbus) {
5957                 WDP_LOGE("DBus connection is NULL");
5958                 __WDP_LOG_FUNC_EXIT__;
5959                 return -1;
5960         }
5961         memset(&params, 0x0, sizeof(dbus_method_param_s));
5962
5963         dbus_set_method_param(&params, "SaveConfig", g_pd->iface_path, g_dbus);
5964         params.params = NULL;
5965
5966         res = dbus_method_call(&params, SUPPLICANT_IFACE, NULL, NULL);
5967         if (res < 0)
5968                 WDP_LOGE("Failed to save config to wpa_supplicant");
5969         else
5970                 WDP_LOGD("Succeeded to save config");
5971
5972         __WDP_LOG_FUNC_EXIT__;
5973         return res;
5974 }
5975
5976 int ws_set_operating_channel(int channel)
5977 {
5978         __WDP_LOG_FUNC_ENTER__;
5979         GDBusConnection *g_dbus = NULL;
5980         GVariant *value = NULL;
5981         GVariant *param = NULL;
5982         GVariantBuilder *builder = NULL;
5983         dbus_method_param_s params;
5984         int res = 0;
5985
5986         g_dbus = g_pd->g_dbus;
5987         if (!g_dbus) {
5988                 WDP_LOGE("DBus connection is NULL");
5989                 __WDP_LOG_FUNC_EXIT__;
5990                 return -1;
5991         }
5992
5993         memset(&params, 0x0, sizeof(dbus_method_param_s));
5994
5995         dbus_set_method_param(&params, DBUS_PROPERTIES_METHOD_SET, g_pd->iface_path, g_dbus);
5996
5997         builder = g_variant_builder_new (G_VARIANT_TYPE ("a{sv}"));
5998         g_variant_builder_add (builder, "{sv}", "OperChannel", g_variant_new_uint32(channel));
5999         value = g_variant_new ("a{sv}", builder);
6000         g_variant_builder_unref (builder);
6001
6002         param = g_variant_new("(ssv)", SUPPLICANT_P2PDEVICE, "P2PDeviceConfig", value);
6003         params.params = param;
6004
6005         res = dbus_method_call(&params, DBUS_PROPERTIES_INTERFACE, NULL, NULL);
6006         if (res < 0)
6007                 WDP_LOGE("Failed to send command to wpa_supplicant");
6008         else
6009                 WDP_LOGD("Succeeded to set Operating Channel");
6010
6011         __WDP_LOG_FUNC_EXIT__;
6012         return res;
6013 }
6014
6015 int ws_remove_all_network(void)
6016 {
6017         __WDP_LOG_FUNC_ENTER__;
6018         GDBusConnection *g_dbus = NULL;
6019         dbus_method_param_s params;
6020         int res = 0;
6021
6022         g_dbus = g_pd->g_dbus;
6023         if (!g_dbus) {
6024                 WDP_LOGE("DBus connection is NULL");
6025                 __WDP_LOG_FUNC_EXIT__;
6026                 return -1;
6027         }
6028         memset(&params, 0x0, sizeof(dbus_method_param_s));
6029
6030         dbus_set_method_param(&params, "RemoveAllNetworks", g_pd->iface_path, g_dbus);
6031         params.params = NULL;
6032
6033         res = dbus_method_call(&params, SUPPLICANT_IFACE, NULL, NULL);
6034         if (res < 0)
6035                 WDP_LOGE("Failed to send [RemoveAllNetworks] command to wpa_supplicant");
6036         else
6037                 WDP_LOGD("Succeeded to remove all networks from supplicant");
6038
6039         WDP_LOGD("Succeeded to remove all network");
6040         __WDP_LOG_FUNC_EXIT__;
6041         return res;
6042 }
6043
6044 int ws_get_wpa_status(int *wpa_status)
6045 {
6046         __WDP_LOG_FUNC_ENTER__;
6047         GDBusConnection *g_dbus = NULL;
6048         GVariant *param = NULL;
6049         GVariant *reply = NULL;
6050         GError *error = NULL;
6051
6052         if (!wpa_status) {
6053                 WDP_LOGE("Invalid parameter");
6054                 __WDP_LOG_FUNC_EXIT__;
6055                 return -1;
6056         }
6057
6058         *wpa_status = WFD_OEM_WPA_STATE_MAX;
6059
6060         g_dbus = g_pd->g_dbus;
6061         if (!g_dbus) {
6062                 WDP_LOGE("DBus connection is NULL");
6063                 __WDP_LOG_FUNC_EXIT__;
6064                 return -1;
6065         }
6066
6067         param = g_variant_new("(s)", SUPPLICANT_IFACE);
6068
6069         reply = g_dbus_connection_call_sync (
6070                         g_pd->g_dbus,
6071                         SUPPLICANT_SERVICE, /* bus name */
6072                         g_pd->iface_path, /* object path */
6073                         DBUS_PROPERTIES_INTERFACE, /* interface name */
6074                         DBUS_PROPERTIES_METHOD_GETALL, /* method name */
6075                         param, /* GVariant *params */
6076                         NULL, /* reply_type */
6077                         G_DBUS_CALL_FLAGS_NONE, /* flags */
6078                         SUPPLICANT_TIMEOUT , /* timeout */
6079                         NULL, /* cancellable */
6080                         &error); /* error */
6081
6082         if(error != NULL) {
6083                 WDP_LOGE("Error! Failed to get properties: [%s]",
6084                                                         error->message);
6085                 g_error_free(error);
6086                 if (reply)
6087                         g_variant_unref(reply);
6088                 __WDP_LOG_FUNC_EXIT__;
6089                 return -1;
6090         }
6091
6092         gchar *reply_str = NULL;
6093         if (reply)
6094                 reply_str = g_variant_print(reply, TRUE);
6095         WDP_LOGE("reply [%s]", reply_str ? reply_str : "NULL");
6096         g_free(reply_str);
6097
6098         if(reply != NULL) {
6099                 GVariantIter *iter = NULL;
6100                 g_variant_get(reply, "(a{sv})", &iter);
6101
6102                 if (iter != NULL) {
6103                         gchar *key = NULL;
6104                         GVariant *value = NULL;
6105
6106                         while (g_variant_iter_loop(iter, "{sv}", &key, &value)) {
6107                                 if(g_strcmp0(key, "State") == 0) {
6108                                         const gchar *state = NULL;
6109                                         g_variant_get(value, "&s", &state);
6110                                         WDP_LOGI("state : [%s]", state);
6111
6112                                         if (g_strcmp0(state, "disconnected") == 0)
6113                                                 *wpa_status = WFD_OEM_WPA_STATE_DISCONNECTED;
6114                                         else if (g_strcmp0(state, "inactive") == 0)
6115                                                 *wpa_status = WFD_OEM_WPA_STATE_INACTIVE;
6116                                         else if (g_strcmp0(state, "scanning") == 0)
6117                                                 *wpa_status = WFD_OEM_WPA_STATE_SCANNING;
6118                                         else if (g_strcmp0(state, "authenticating") == 0)
6119                                                 *wpa_status = WFD_OEM_WPA_STATE_AUTHENTICATING;
6120                                         else if (g_strcmp0(state, "associating") == 0)
6121                                                 *wpa_status = WFD_OEM_WPA_STATE_ASSOCIATING;
6122                                         else if (g_strcmp0(state, "associated") == 0)
6123                                                 *wpa_status = WFD_OEM_WPA_STATE_ASSOCIATED;
6124                                         else if (g_strcmp0(state, "4way_handshake") == 0)
6125                                                 *wpa_status = WFD_OEM_WPA_STATE_4WAY_HANDSHAKE;
6126                                         else if (g_strcmp0(state, "group_handshake") == 0)
6127                                                 *wpa_status = WFD_OEM_WPA_STATE_GROUP_HANDSHAKE;
6128                                         else if (g_strcmp0(state, "completed") == 0)
6129                                                 *wpa_status = WFD_OEM_WPA_STATE_COMPLETED;
6130                                         else
6131                                                 *wpa_status = WFD_OEM_WPA_STATE_MAX;
6132                                 }
6133                         }
6134                         g_variant_iter_free(iter);
6135                 }
6136                 g_variant_unref(reply);
6137         } else {
6138                 WDP_LOGD("No properties");
6139         }
6140
6141         WDP_LOGI("wpa_status : [%d]", *wpa_status);
6142
6143         __WDP_LOG_FUNC_EXIT__;
6144         return 0;
6145 }
6146
6147 #if defined(TIZEN_FEATURE_ASP)
6148 int ws_advertise_service(wfd_oem_asp_service_s *service, int replace)
6149 {
6150         __WDP_LOG_FUNC_ENTER__;
6151         GDBusConnection *g_dbus = NULL;
6152         GVariantBuilder *builder = NULL;
6153         GVariant *value = NULL;
6154         dbus_method_param_s params;
6155         unsigned int config_method = 0x1108;
6156         int auto_accept = 0;
6157         gboolean rep;
6158         int res = 0;
6159
6160         g_dbus = g_pd->g_dbus;
6161         if (!g_dbus) {
6162                 WDP_LOGE("DBus connection is NULL");
6163                 return -1;
6164         }
6165
6166         if (service->config_method == 2) {
6167                 config_method = WS_CONFIG_METHOD_KEYPAD |
6168                                 WS_CONFIG_METHOD_DISPLAY;
6169         } else if (service->config_method == 3) {
6170                 config_method = WS_CONFIG_METHOD_DISPLAY;
6171         } else if (service->config_method == 4) {
6172                 config_method = WS_CONFIG_METHOD_KEYPAD;
6173         }
6174
6175         if(service->auto_accept) {
6176                 if(service->role == 0)
6177                         auto_accept = 1;
6178                 else
6179                         auto_accept = 2;
6180         } else {
6181                 auto_accept = 0;
6182         }
6183
6184         rep = (replace == 1);
6185
6186         memset(&params, 0x0, sizeof(dbus_method_param_s));
6187
6188         dbus_set_method_param(&params, "AddService", g_pd->iface_path, g_dbus);
6189
6190         builder = g_variant_builder_new (G_VARIANT_TYPE ("a{sv}") );
6191
6192         g_variant_builder_add (builder, "{sv}", "service_type", g_variant_new_string("asp"));
6193         g_variant_builder_add (builder, "{sv}", "auto_accept", g_variant_new_int32(auto_accept));
6194         g_variant_builder_add (builder, "{sv}", "adv_id", g_variant_new_uint32(service->adv_id));
6195         g_variant_builder_add (builder, "{sv}", "svc_state", g_variant_new_uint32(service->status));
6196         g_variant_builder_add (builder, "{sv}", "config_method", g_variant_new_uint32(config_method));
6197         g_variant_builder_add (builder, "{sv}", "replace", g_variant_new_boolean(rep));
6198         if(service->service_type != NULL)
6199                 g_variant_builder_add (builder, "{sv}", "adv_str", g_variant_new_string(service->service_type));
6200         if(service->service_info != NULL)
6201                 g_variant_builder_add (builder, "{sv}", "svc_info", g_variant_new_string(service->service_info));
6202
6203         value = g_variant_new ("(a{sv})", builder);
6204         g_variant_builder_unref (builder);
6205 #if defined (TIZEN_DEBUG_DBUS_VALUE)
6206         WDP_LOGE("params [%s]", g_variant_print(value, TRUE));
6207 #endif /* TIZEN_DEBUG_DBUS_VALUE */
6208
6209         params.params = value;
6210
6211         res = dbus_method_call(&params, SUPPLICANT_P2PDEVICE, NULL, NULL);
6212         if (res < 0)
6213                 WDP_LOGE("Failed to send command to wpa_supplicant");
6214         else
6215                 WDP_LOGD("Succeeded to add service");
6216
6217         __WDP_LOG_FUNC_EXIT__;
6218         return 0;
6219 }
6220
6221 int ws_cancel_advertise_service(wfd_oem_asp_service_s *service)
6222 {
6223         __WDP_LOG_FUNC_ENTER__;
6224         GDBusConnection *g_dbus = NULL;
6225         GVariantBuilder *builder = NULL;
6226         GVariant *value = NULL;
6227         dbus_method_param_s params;
6228         int res = 0;
6229
6230         g_dbus = g_pd->g_dbus;
6231         if (!g_dbus) {
6232                 WDP_LOGE("DBus connection is NULL");
6233                 return -1;
6234         }
6235         memset(&params, 0x0, sizeof(dbus_method_param_s));
6236
6237         dbus_set_method_param(&params, "DeleteService", g_pd->iface_path, g_dbus);
6238
6239         builder = g_variant_builder_new (G_VARIANT_TYPE ("a{sv}"));
6240
6241         g_variant_builder_add (builder, "{sv}", "service_type", g_variant_new_string("asp"));
6242         g_variant_builder_add (builder, "{sv}", "adv_id", g_variant_new_uint32(service->adv_id));
6243
6244         value = g_variant_new ("(a{sv})", builder);
6245         g_variant_builder_unref (builder);
6246 #if defined (TIZEN_DEBUG_DBUS_VALUE)
6247         WDP_LOGD("params [%s]", g_variant_print(value, TRUE));
6248 #endif /* TIZEN_DEBUG_DBUS_VALUE */
6249         params.params = value;
6250
6251         res = dbus_method_call(&params, SUPPLICANT_P2PDEVICE, NULL, NULL);
6252         if (res < 0)
6253                 WDP_LOGE("Failed to send command to wpa_supplicant");
6254         else
6255                 WDP_LOGD("Succeeded to del service");
6256
6257         __WDP_LOG_FUNC_EXIT__;
6258         return 0;
6259 }
6260
6261 static void __ws_add_seek(wfd_oem_asp_service_s *service)
6262 {
6263         __WDP_LOG_FUNC_ENTER__;
6264         wfd_oem_asp_service_s *seek = NULL;
6265         if (!service) {
6266                 WDP_LOGE("invalid parameters");
6267                 return;
6268         }
6269
6270         seek = g_try_malloc0(sizeof(wfd_oem_asp_service_s));
6271         if (!seek) {
6272                 WDP_LOGE("Failed to allocate memory for service");
6273                 return;
6274         }
6275
6276         service->search_id = (intptr_t)seek;
6277         memcpy(seek, service, sizeof(wfd_oem_asp_service_s));
6278         if(service->service_type)
6279                 seek->service_type = strdup(service->service_type);
6280         seek_list = g_list_prepend(seek_list, seek);
6281
6282         __WDP_LOG_FUNC_EXIT__;
6283         return;
6284 }
6285
6286 static wfd_oem_asp_service_s * __ws_get_seek(long long unsigned search_id)
6287 {
6288         __WDP_LOG_FUNC_ENTER__;
6289         wfd_oem_asp_service_s *seek = NULL;
6290         GList *list = NULL;
6291
6292         for(list = seek_list; list != NULL; list = list->next) {
6293                 seek = list->data;
6294                 if(seek && (seek->search_id == search_id)) {
6295                         WDP_LOGD("List found");
6296                         break;
6297                 } else {
6298                         seek = NULL;
6299                 }
6300         }
6301         __WDP_LOG_FUNC_EXIT__;
6302         return seek;
6303 }
6304
6305 static void __ws_remove_seek(wfd_oem_asp_service_s *service)
6306 {
6307         __WDP_LOG_FUNC_ENTER__;
6308         wfd_oem_asp_service_s *seek = NULL;
6309         GList *list = NULL;
6310
6311         for(list = seek_list; list != NULL; list = list->next) {
6312
6313                 seek = list->data;
6314                 if (seek && (seek->search_id == service->search_id)) {
6315                         WDP_LOGD("List remove");
6316                         seek_list = g_list_remove(seek_list, seek);
6317                         g_free(seek->service_type);
6318                         g_free(seek->service_info);
6319                         g_free(seek);
6320                 }
6321         }
6322         __WDP_LOG_FUNC_EXIT__;
6323         return;
6324 }
6325
6326 static void __get_asp_search_id(GVariant *value, void *args)
6327 {
6328         __WDP_LOG_FUNC_ENTER__;
6329         wfd_oem_asp_service_s *service = NULL;
6330         wfd_oem_asp_service_s *seek = NULL;
6331         long long unsigned search_id = 0;
6332
6333         g_variant_get(value, "(t)", &search_id);
6334
6335         service = (wfd_oem_asp_service_s *)args;
6336         if (!service) {
6337                 WDP_LOGE("invalid parameters");
6338                 __WDP_LOG_FUNC_EXIT__;
6339                 return;
6340         }
6341
6342         seek = g_try_malloc0(sizeof(wfd_oem_asp_service_s));
6343         if (!seek) {
6344                 WDP_LOGE("Failed to allocate memory for service");
6345                 __WDP_LOG_FUNC_EXIT__;
6346                 return;
6347         }
6348
6349         service->search_id = search_id;
6350         memcpy(seek, service, sizeof(wfd_oem_asp_service_s));
6351         if(service->service_type)
6352                 seek->service_type = strdup(service->service_type);
6353         if(service->service_info)
6354                 seek->service_info = strdup(service->service_info);
6355         seek_list = g_list_append(seek_list, seek);
6356
6357         __WDP_LOG_FUNC_EXIT__;
6358         return;
6359 }
6360
6361 int ws_seek_service(wfd_oem_asp_service_s *service)
6362 {
6363         __WDP_LOG_FUNC_ENTER__;
6364         GDBusConnection *g_dbus = NULL;
6365         GList *list = NULL;
6366         wfd_oem_asp_service_s *seek = NULL;
6367         int res = 0;
6368
6369         g_dbus = g_pd->g_dbus;
6370         if (!g_dbus) {
6371                 WDP_LOGE("DBus connection is NULL");
6372                 __WDP_LOG_FUNC_EXIT__;
6373                 return -1;
6374         }
6375         list = g_list_last(seek_list);
6376         if(list == NULL) {
6377                 service->tran_id = 1;
6378
6379         } else {
6380                 seek = list->data;
6381                 if(seek)
6382                         service->tran_id = seek->tran_id + 1;
6383                 else
6384                         service->tran_id = 1;
6385         }
6386
6387         if(service->service_info) {
6388                 GVariantBuilder *builder = NULL;
6389                 GVariant *value = NULL;
6390                 dbus_method_param_s params;
6391
6392                 memset(&params, 0x0, sizeof(dbus_method_param_s));
6393                 dbus_set_method_param(&params, "ServiceDiscoveryRequest",
6394                                 g_pd->iface_path, g_dbus);
6395
6396                 builder = g_variant_builder_new (G_VARIANT_TYPE ("a{sv}") );
6397
6398                 g_variant_builder_add (builder, "{sv}", "service_type",
6399                                 g_variant_new_string("asp"));
6400                 g_variant_builder_add (builder, "{sv}", "transaction_id",
6401                                 g_variant_new_byte(service->tran_id));
6402                 if(service->service_type != NULL)
6403                         g_variant_builder_add (builder, "{sv}", "svc_str",
6404                                         g_variant_new_string(service->service_type));
6405
6406                 if(service->service_info != NULL)
6407                         g_variant_builder_add (builder, "{sv}", "svc_info",
6408                                         g_variant_new_string(service->service_info));
6409
6410                 value = g_variant_new ("(a{sv})", builder);
6411                 g_variant_builder_unref (builder);
6412
6413 #if defined (TIZEN_DEBUG_DBUS_VALUE)
6414                 WDP_LOGD("params [%s]", g_variant_print(value, TRUE));
6415 #endif /* TIZEN_DEBUG_DBUS_VALUE */
6416
6417                 params.params = value;
6418                 res = dbus_method_call(&params, SUPPLICANT_P2PDEVICE,
6419                                 __get_asp_search_id, service);
6420
6421         } else {
6422                 __ws_add_seek(service);
6423         }
6424
6425         if (res < 0)
6426                 WDP_LOGE("Failed to send command to wpa_supplicant");
6427         else
6428                 WDP_LOGD("Succeeded to seek service");
6429
6430         __WDP_LOG_FUNC_EXIT__;
6431         return res;
6432 }
6433
6434 int ws_cancel_seek_service(wfd_oem_asp_service_s *service)
6435 {
6436         __WDP_LOG_FUNC_ENTER__;
6437         GDBusConnection *g_dbus = NULL;
6438         wfd_oem_asp_service_s *seek = NULL;
6439         dbus_method_param_s params;
6440         int res = 0;
6441
6442         g_dbus = g_pd->g_dbus;
6443         if (!g_dbus) {
6444                 WDP_LOGE("DBus connection is NULL");
6445                 __WDP_LOG_FUNC_EXIT__;
6446                 return -1;
6447         }
6448
6449         seek = __ws_get_seek(service->search_id);
6450         if (!seek) {
6451                 WDP_LOGE("seek data is NULL");
6452                 __WDP_LOG_FUNC_EXIT__;
6453                 return -1;
6454         }
6455
6456         if(seek->service_info) {
6457
6458                 memset(&params, 0x0, sizeof(dbus_method_param_s));
6459                 dbus_set_method_param(&params, "ServiceDiscoveryCancelRequest",
6460                                 g_pd->iface_path, g_dbus);
6461
6462                 params.params = g_variant_new ("(t)", service->search_id);
6463
6464 #if defined (TIZEN_DEBUG_DBUS_VALUE)
6465                 WDP_LOGD("params [%s]", g_variant_print(params.params, TRUE));
6466 #endif /* TIZEN_DEBUG_DBUS_VALUE */
6467
6468                 res = dbus_method_call(&params, SUPPLICANT_P2PDEVICE, NULL, NULL);
6469                 if (res < 0) {
6470                         WDP_LOGE("Failed to send command to wpa_supplicant");
6471                 } else {
6472                         WDP_LOGD("Succeeded to cancel seek service");
6473                 }
6474         }
6475         if(res == 0)
6476                 __ws_remove_seek(seek);
6477
6478         __WDP_LOG_FUNC_EXIT__;
6479         return res;
6480 }
6481
6482 int ws_asp_prov_disc_req(wfd_oem_asp_prov_s *asp_params)
6483 {
6484         __WDP_LOG_FUNC_ENTER__;
6485         GDBusConnection *g_dbus = NULL;
6486         GVariantBuilder *builder = NULL;
6487         GVariantBuilder *mac_builder = NULL;
6488         GVariant *value = NULL;
6489         dbus_method_param_s params;
6490         static char peer_path[DBUS_OBJECT_PATH_MAX] = {'\0',};
6491         int config_method = 0x1000;
6492         int res = 0;
6493         int i = 0;
6494
6495         if (!asp_params) {
6496                 WDP_LOGE("Invalid parameter");
6497                 __WDP_LOG_FUNC_EXIT__;
6498                 return -1;
6499         }
6500         g_dbus = g_pd->g_dbus;
6501         if (!g_dbus) {
6502                 WDP_LOGE("DBus connection is NULL");
6503                 __WDP_LOG_FUNC_EXIT__;
6504                 return -1;
6505         }
6506
6507         if(asp_params->network_config == WFD_OEM_ASP_WPS_TYPE_PIN_DISPLAY)
6508                 config_method = 0x8;
6509         else if(asp_params->network_config == WFD_OEM_ASP_WPS_TYPE_PIN_KEYPAD)
6510                 config_method = 0x100;
6511
6512         memset(&params, 0x0, sizeof(dbus_method_param_s));
6513
6514         dbus_set_method_param(&params, "ASPProvisionDiscoveryRequest", g_pd->iface_path, g_dbus);
6515
6516         g_snprintf(peer_path, DBUS_OBJECT_PATH_MAX, "%s/Peers/"
6517                         COMPACT_MACSTR, g_pd->iface_path, MAC2STR(asp_params->service_mac));
6518         WDP_LOGD("get peer path [%s]", peer_path);
6519
6520         builder = g_variant_builder_new (G_VARIANT_TYPE ("a{sv}") );
6521         g_variant_builder_add (builder, "{sv}", "peer", g_variant_new_object_path(peer_path));
6522
6523         g_variant_builder_add (builder, "{sv}", "adv_id", g_variant_new_uint32(asp_params->adv_id));
6524         g_variant_builder_add (builder, "{sv}", "session_id", g_variant_new_uint32(asp_params->session_id));
6525         g_variant_builder_add (builder, "{sv}", "role", g_variant_new_byte(asp_params->network_role));
6526         g_variant_builder_add (builder, "{sv}", "method", g_variant_new_int32(config_method));
6527         if (asp_params->status > 0)
6528                 g_variant_builder_add (builder, "{sv}", "status", g_variant_new_int32(asp_params->status));
6529         if (asp_params->session_information)
6530                 g_variant_builder_add (builder, "{sv}", "info", g_variant_new_string(asp_params->session_information));
6531
6532         mac_builder = g_variant_builder_new (G_VARIANT_TYPE ("ay"));
6533         for (i = 0; i < OEM_MACADDR_LEN; i++)
6534                 g_variant_builder_add(mac_builder, "y", asp_params->service_mac[i]);
6535         g_variant_builder_add (builder, "{sv}", "adv_mac",
6536                         g_variant_new ("ay", mac_builder));
6537         g_variant_builder_unref (mac_builder);
6538
6539         mac_builder = g_variant_builder_new (G_VARIANT_TYPE ("ay"));
6540         for (i = 0; i < OEM_MACADDR_LEN; i++)
6541                 g_variant_builder_add(mac_builder, "y", asp_params->session_mac[i]);
6542         g_variant_builder_add (builder, "{sv}", "session_mac",
6543                         g_variant_new ("ay", mac_builder));
6544         g_variant_builder_unref (mac_builder);
6545
6546         value = g_variant_new ("(a{sv})", builder);
6547         g_variant_builder_unref (builder);
6548 #if defined (TIZEN_DEBUG_DBUS_VALUE)
6549         WDP_LOGD("params [%s]", g_variant_print(value, TRUE));
6550 #endif /* TIZEN_DEBUG_DBUS_VALUE */
6551
6552         params.params = value;
6553
6554         res = dbus_method_call(&params, SUPPLICANT_P2PDEVICE, NULL, NULL);
6555         if (res < 0)
6556                 WDP_LOGE("Failed to send command to wpa_supplicant");
6557         else
6558                 WDP_LOGD("Succeeded to send connection command to peer[" MACSTR "]", MAC2STR(asp_params->service_mac));
6559
6560         __WDP_LOG_FUNC_EXIT__;
6561         return res;
6562 }
6563 #endif /* TIZEN_FEATURE_ASP */