cf8c0887e46fb84f4e115b218d709dc097f1874e
[platform/core/api/wifi-direct.git] / src / wifi-direct-client-proxy.c
1 /*
2  * libwifi-direct
3  *
4  * Copyright (c) 2012 Samsung Electronics Co., Ltd. All rights reserved.
5  *
6  * Contact: Sungsik Jang <sungsik.jang@samsung.com>, Dongwook Lee <dwmax.lee@samsung.com>
7  *
8  * Licensed under the Apache License, Version 2.0 (the "License");
9  * you may not use this file except in compliance with the License.
10  * You may obtain a copy of the License at
11  *
12  * http://www.apache.org/licenses/LICENSE-2.0
13  *
14  * Unless required by applicable law or agreed to in writing, software
15  * distributed under the License is distributed on an "AS IS" BASIS,
16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  * See the License for the specific language governing permissions and
18  * limitations under the License.
19  *
20  */
21
22
23 /*****************************************************************************
24  *  Standard headers
25  *****************************************************************************/
26 #define _GNU_SOURCE
27 #include <stdio.h>
28 #include <stdlib.h>
29 #include <stdbool.h>
30 #include <unistd.h>
31 #include <netdb.h>
32 #include <sys/socket.h>
33 #include <string.h>
34 #include <sys/un.h>
35 #include <sys/wait.h>
36 #include <fcntl.h>
37 #include <sys/ioctl.h>
38 #include <signal.h>
39 #include <linux/unistd.h>
40 #include <sys/poll.h>
41 #include <pthread.h>
42 #include <errno.h>
43
44 #include <glib.h>
45 #include <gio/gio.h>
46
47 /*****************************************************************************
48  *  System headers
49  *****************************************************************************/
50 #include <vconf.h>
51 #include <system_info.h>
52
53 /*****************************************************************************
54  *  Wi-Fi Direct Service headers
55  *****************************************************************************/
56 #include "wifi-direct.h"
57 #include "wifi-direct-internal.h"
58 #include "wifi-direct-client-proxy.h"
59 #include "wifi-direct-ipc.h"
60 #include "wifi-direct-log.h"
61 #include "wifi-direct-dbus.h"
62
63 /*****************************************************************************
64  *  Macros and Typedefs
65  *****************************************************************************/
66
67 /*****************************************************************************
68  *  Global Variables
69  *****************************************************************************/
70 wifi_direct_client_info_s g_client_info = {
71         .is_registered = FALSE,
72         .client_id = -1,
73         .sync_sockfd = -1,
74         .async_sockfd = -1,
75         .activation_cb = NULL,
76         .discover_cb = NULL,
77         .connection_cb = NULL,
78         .ip_assigned_cb = NULL,
79         .peer_found_cb = NULL,
80         .user_data_for_cb_activation = NULL,
81         .user_data_for_cb_discover = NULL,
82         .user_data_for_cb_connection = NULL,
83         .user_data_for_cb_ip_assigned = NULL,
84         .user_data_for_cb_peer_found = NULL,
85         .user_data_for_cb_device_name = NULL,
86 #ifdef TIZEN_FEATURE_SERVICE_DISCOVERY
87         .service_cb = NULL,
88         .user_data_for_cb_service = NULL,
89 #endif /* TIZEN_FEATURE_SERVICE_DISCOVERY */
90
91         .mutex = PTHREAD_MUTEX_INITIALIZER
92 };
93
94 /*****************************************************************************
95  *  Local Functions Definition
96  *****************************************************************************/
97
98 static wifi_direct_client_info_s *__wfd_get_control()
99 {
100         return &g_client_info;
101 }
102
103 /* Manage */
104 void wifi_direct_process_manage_activation(GDBusConnection *connection,
105                 const gchar *object_path, GVariant *parameters)
106 {
107         __WDC_LOG_FUNC_START__;
108         int error_code;
109         wifi_direct_client_info_s *client = __wfd_get_control();
110
111         if (!client->activation_cb) {
112                 WDC_LOGI("activation_cb is NULL!!");
113                 return;
114         }
115
116         if (!parameters) {
117                 __WDC_LOG_FUNC_END__;
118                 return;
119         }
120
121         g_variant_get(parameters, "(i)", &error_code);
122
123         client->activation_cb(error_code,
124                               WIFI_DIRECT_DEVICE_STATE_ACTIVATED,
125                               client->user_data_for_cb_activation);
126
127         __WDC_LOG_FUNC_END__;
128 }
129
130 void wifi_direct_process_manage_deactivation(GDBusConnection *connection,
131                 const gchar *object_path, GVariant *parameters)
132 {
133         __WDC_LOG_FUNC_START__;
134         int error_code;
135         wifi_direct_client_info_s *client = __wfd_get_control();
136
137         if (!parameters) {
138                 __WDC_LOG_FUNC_END__;
139                 return;
140         }
141
142         if (!client->activation_cb) {
143                 WDC_LOGI("activation_cb is NULL!!");
144                 __WDC_LOG_FUNC_END__;
145                 return;
146         }
147
148         g_variant_get(parameters, "(i)", &error_code);
149
150         client->activation_cb(error_code,
151                               WIFI_DIRECT_DEVICE_STATE_DEACTIVATED,
152                               client->user_data_for_cb_activation);
153
154         __WDC_LOG_FUNC_END__;
155 }
156
157 void wifi_direct_process_manage_connection(GDBusConnection *connection,
158                 const gchar *object_path, GVariant *parameters)
159 {
160         __WDC_LOG_FUNC_START__;
161         int error_code;
162         wifi_direct_connection_state_e connection_state;
163         const gchar *peer_mac_address = NULL;
164         wifi_direct_client_info_s *client = __wfd_get_control();
165
166         if (!parameters) {
167                 __WDC_LOG_FUNC_END__;
168                 return;
169         }
170
171         if (!client->connection_cb) {
172                 WDC_LOGI("connection_cb is NULL!!");
173                 __WDC_LOG_FUNC_END__;
174                 return;
175         }
176
177         g_variant_get(parameters, "(ii&s)",
178                         &error_code, &connection_state, &peer_mac_address);
179
180         client->connection_cb(error_code,
181                               connection_state,
182                               peer_mac_address,
183                               client->user_data_for_cb_connection);
184
185         __WDC_LOG_FUNC_END__;
186 }
187
188 void wifi_direct_process_manage_disconnection(GDBusConnection *connection,
189                 const gchar *object_path, GVariant *parameters)
190 {
191         __WDC_LOG_FUNC_START__;
192         int error_code;
193         wifi_direct_connection_state_e connection_state;
194         const gchar *peer_mac_address = NULL;
195         wifi_direct_client_info_s *client = __wfd_get_control();
196
197         if (!parameters) {
198                 __WDC_LOG_FUNC_END__;
199                 return;
200         }
201
202         if (!client->connection_cb) {
203                 WDC_LOGI("connection_cb is NULL!!");
204                 __WDC_LOG_FUNC_END__;
205                 return;
206         }
207
208         g_variant_get(parameters, "(ii&s)",
209                         &error_code, &connection_state, &peer_mac_address);
210
211         client->connection_cb(error_code,
212                               connection_state,
213                               peer_mac_address,
214                               client->user_data_for_cb_connection);
215
216         __WDC_LOG_FUNC_END__;
217 }
218
219 void wifi_direct_process_manage_peer_ip_assigned(GDBusConnection *connection,
220                 const gchar *object_path, GVariant *parameters)
221 {
222         __WDC_LOG_FUNC_START__;
223         char *get_str = NULL;
224         GError* error = NULL;
225         GVariant *reply = NULL;
226         const gchar *peer_mac_address = NULL;
227         const gchar *assigned_ip_address = NULL;
228         int ret = 0;
229         wifi_direct_client_info_s *client = __wfd_get_control();
230
231         if (!parameters) {
232                 __WDC_LOG_FUNC_END__;
233                 return;
234         }
235
236         g_variant_get(parameters, "(&s&s)",
237                         &peer_mac_address, &assigned_ip_address);
238
239         if (!client->ip_assigned_cb) {
240                 WDC_LOGI("ip_assigned_cb is NULL!!");
241                 __WDC_LOG_FUNC_END__;
242                 return;
243         }
244
245         reply = wifi_direct_dbus_method_call_sync(WFD_MANAGER_CONFIG_INTERFACE,
246                                                   "GetInterfaceName",
247                                                   NULL,
248                                                   &error);
249         if (error != NULL) {
250                 WDC_LOGE("wifi_direct_dbus_method_call_sync() failed."
251                                 "error [%d: %s]", error->code, error->message);
252                 g_error_free(error);
253                 __WDC_LOG_FUNC_END__;
254                 return;
255         }
256
257         g_variant_get(reply, "(i&s)", ret ,&get_str);
258         g_variant_unref(reply);
259
260         WDC_LOGD("Interface Name = [%s]", get_str);
261         WDC_LOGD("%s() return : [%d]", __func__, ret);
262
263         client->ip_assigned_cb(peer_mac_address, assigned_ip_address, get_str,
264                         client->user_data_for_cb_ip_assigned);
265
266         __WDC_LOG_FUNC_END__;
267 }
268
269 void wifi_direct_process_manage_listen_started(GDBusConnection *connection,
270                 const gchar *object_path, GVariant *parameters)
271 {
272         __WDC_LOG_FUNC_START__;
273         wifi_direct_client_info_s *client = __wfd_get_control();
274
275         if (!client->discover_cb) {
276                 WDC_LOGI("discover_cb is NULL!!");
277                 __WDC_LOG_FUNC_END__;
278                 return;
279         }
280
281         client->discover_cb(WIFI_DIRECT_ERROR_NONE,
282                             WIFI_DIRECT_ONLY_LISTEN_STARTED,
283                             client->user_data_for_cb_discover);
284
285         __WDC_LOG_FUNC_END__;
286 }
287
288 void wifi_direct_process_manage_discovery_started(GDBusConnection *connection,
289                 const gchar *object_path, GVariant *parameters)
290 {
291         __WDC_LOG_FUNC_START__;
292         wifi_direct_client_info_s *client = __wfd_get_control();
293
294         if (!client->discover_cb) {
295                 WDC_LOGI("discover_cb is NULL!!");
296                 __WDC_LOG_FUNC_END__;
297                 return;
298         }
299
300         client->discover_cb(WIFI_DIRECT_ERROR_NONE,
301                             WIFI_DIRECT_DISCOVERY_STARTED,
302                             client->user_data_for_cb_discover);
303
304         __WDC_LOG_FUNC_END__;
305 }
306
307 void wifi_direct_process_manage_discovery_finished(GDBusConnection *connection,
308                 const gchar *object_path, GVariant *parameters)
309 {
310         __WDC_LOG_FUNC_START__;
311         wifi_direct_client_info_s *client = __wfd_get_control();
312
313         if (!client->discover_cb) {
314                 WDC_LOGI("discover_cb is NULL!!");
315                 __WDC_LOG_FUNC_END__;
316                 return;
317         }
318
319         client->discover_cb(WIFI_DIRECT_ERROR_NONE,
320                             WIFI_DIRECT_DISCOVERY_FINISHED,
321                             client->user_data_for_cb_discover);
322
323         __WDC_LOG_FUNC_END__;
324 }
325
326 void wifi_direct_process_manage_peer_found(GDBusConnection *connection,
327                 const gchar *object_path, GVariant *parameters)
328 {
329         __WDC_LOG_FUNC_START__;
330         const gchar *peer_mac_address = NULL;
331         wifi_direct_client_info_s *client = __wfd_get_control();
332
333         if (!parameters) {
334                 __WDC_LOG_FUNC_END__;
335                 return;
336         }
337
338         g_variant_get(parameters, "(&s)", &peer_mac_address);
339
340         if (client->peer_found_cb) {
341                 client->peer_found_cb(WIFI_DIRECT_ERROR_NONE,
342                                       WIFI_DIRECT_DISCOVERY_FOUND,
343                                       peer_mac_address,
344                                       client->user_data_for_cb_discover);
345         } else {
346                 WDC_LOGI("peer_found_cb is NULL!!");
347         }
348
349         if (!client->discover_cb) {
350                 WDC_LOGI("discover_cb is NULL!!");
351                 __WDC_LOG_FUNC_END__;
352                 return;
353         }
354
355         client->discover_cb(WIFI_DIRECT_ERROR_NONE,
356                             WIFI_DIRECT_DISCOVERY_FOUND,
357                             client->user_data_for_cb_discover);
358
359         __WDC_LOG_FUNC_END__;
360 }
361
362 void wifi_direct_process_manage_peer_lost(GDBusConnection *connection,
363                 const gchar *object_path, GVariant *parameters)
364 {
365         __WDC_LOG_FUNC_START__;
366         const gchar *peer_mac_address = NULL;
367         wifi_direct_client_info_s *client = __wfd_get_control();
368
369         if (!parameters) {
370                 __WDC_LOG_FUNC_END__;
371                 return;
372         }
373
374         g_variant_get(parameters, "(&s)", &peer_mac_address);
375
376         if (client->peer_found_cb) {
377                 client->peer_found_cb(WIFI_DIRECT_ERROR_NONE,
378                                       WIFI_DIRECT_DISCOVERY_LOST,
379                                       peer_mac_address,
380                                       client->user_data_for_cb_discover);
381         } else {
382                 WDC_LOGI("peer_found_cb is NULL!!");
383         }
384
385         if (!client->discover_cb) {
386                 WDC_LOGI("discover_cb is NULL!!");
387                 __WDC_LOG_FUNC_END__;
388                 return;
389         }
390
391         client->discover_cb(WIFI_DIRECT_ERROR_NONE,
392                             WIFI_DIRECT_DISCOVERY_LOST,
393                             client->user_data_for_cb_discover);
394
395         __WDC_LOG_FUNC_END__;
396 }
397
398 /* Group */
399 void wifi_direct_process_group_created(GDBusConnection *connection,
400                 const gchar *object_path, GVariant *parameters)
401 {
402         __WDC_LOG_FUNC_START__;
403         wifi_direct_client_info_s *client = __wfd_get_control();
404
405         if (!client->connection_cb) {
406                 WDC_LOGI("connection_cb is NULL!!");
407                 __WDC_LOG_FUNC_END__;
408                 return;
409         }
410
411         client->connection_cb(WIFI_DIRECT_ERROR_NONE,
412                               WIFI_DIRECT_GROUP_CREATED,
413                               "",
414                               client->user_data_for_cb_connection);
415
416         __WDC_LOG_FUNC_END__;
417 }
418
419 void wifi_direct_process_group_destroyed(GDBusConnection *connection,
420                 const gchar *object_path, GVariant *parameters)
421 {
422         __WDC_LOG_FUNC_START__;
423         wifi_direct_client_info_s *client = __wfd_get_control();
424
425         if (!client->connection_cb) {
426                 WDC_LOGI("connection_cb is NULL!!");
427                 __WDC_LOG_FUNC_END__;
428                 return;
429         }
430
431         client->connection_cb(WIFI_DIRECT_ERROR_NONE,
432                               WIFI_DIRECT_GROUP_DESTROYED,
433                               "",
434                               client->user_data_for_cb_connection);
435
436         __WDC_LOG_FUNC_END__;
437 }
438
439 #ifdef TIZEN_FEATURE_SERVICE_DISCOVERY
440 /* Service */
441 void wifi_direct_process_service_discovery_started(GDBusConnection *connection,
442                 const gchar *object_path, GVariant *parameters)
443 {
444         __WDC_LOG_FUNC_START__;
445         wifi_direct_client_info_s *client = __wfd_get_control();
446
447         if (!client->service_cb) {
448                 WDC_LOGI("service_cb is NULL!!\n");
449                 __WDC_LOG_FUNC_END__;
450                 return;
451         }
452
453         client->service_cb(WIFI_DIRECT_ERROR_NONE,
454                            WIFI_DIRECT_SERVICE_DISCOVERY_STARTED,
455                            WIFI_DIRECT_SERVICE_TYPE_ALL,
456                            "",
457                            "",
458                            client->user_data_for_cb_service);
459
460         __WDC_LOG_FUNC_END__;
461 }
462
463 void wifi_direct_process_service_discovery_found(GDBusConnection *connection,
464                 const gchar *object_path, GVariant *parameters)
465 {
466         __WDC_LOG_FUNC_START__;
467         wifi_direct_service_type_e service_type;
468         const gchar* response_data = NULL;
469         const gchar* peer_mac_address = NULL;
470         wifi_direct_client_info_s *client = __wfd_get_control();
471
472         if (!parameters) {
473                 __WDC_LOG_FUNC_END__;
474                 return;
475         }
476
477         g_variant_get(parameters, "(i&s&s)",
478                         &service_type, &response_data, &peer_mac_address);
479
480         if (!client->service_cb) {
481                 WDC_LOGI("service_cb is NULL!!\n");
482                 __WDC_LOG_FUNC_END__;
483                 return;
484         }
485
486         client->service_cb(WIFI_DIRECT_ERROR_NONE,
487                            WIFI_DIRECT_SERVICE_DISCOVERY_FOUND,
488                            service_type,
489                            (void *) response_data,
490                            peer_mac_address,
491                            client->user_data_for_cb_service);
492
493         __WDC_LOG_FUNC_END__;
494 }
495
496 void wifi_direct_process_service_discovery_finished(GDBusConnection *connection,
497                 const gchar *object_path, GVariant *parameters)
498 {
499         __WDC_LOG_FUNC_START__;
500         wifi_direct_client_info_s *client = __wfd_get_control();
501
502         if (!client->service_cb) {
503                 WDC_LOGI("service_cb is NULL!!\n");
504                 __WDC_LOG_FUNC_END__;
505                 return;
506         }
507
508         client->service_cb(WIFI_DIRECT_ERROR_NONE,
509                            WIFI_DIRECT_SERVICE_DISCOVERY_FINISHED,
510                            WIFI_DIRECT_SERVICE_TYPE_ALL,
511                            "",
512                            "",
513                            client->user_data_for_cb_service);
514
515         __WDC_LOG_FUNC_END__;
516 }
517 #endif /* TIZEN_FEATURE_SERVICE_DISCOVERY */
518
519 void __wfd_client_print_entry_list(wfd_discovery_entry_s *list, int num)
520 {
521         int i = 0;
522
523         WDC_LOGD("------------------------------------------");
524         for (i = 0; i < num; i++)
525         {
526                 WDC_LOGD("== Peer index : %d ==", i);
527                 WDC_LOGD("is Group Owner ? %s", list[i].is_group_owner ? "YES" : "NO");
528                 WDC_LOGD("device_name : %s", list[i].device_name);
529                 WDC_LOGD("MAC address : "MACSECSTR, MAC2SECSTR(list[i].mac_address));
530                 WDC_LOGD("wps cfg method : %x", list[i].wps_cfg_methods);
531                 WDC_LOGD("Device Type: %d - %d", list[i].category, list[i].subcategory);
532                 WDC_LOGD("Listen channel: %d", list[i].channel);
533         }
534         WDC_LOGD("------------------------------------------");
535 }
536
537 void __wfd_client_print_connected_peer_info(wfd_connected_peer_info_s *list, int num)
538 {
539         int i = 0;
540
541         WDC_LOGD("------------------------------------------\n");
542         for (i = 0; i < num; i++) {
543                 WDC_LOGD("== Peer index : %d ==\n", i);
544                 WDC_LOGD("device_name : %s\n", list[i].device_name);
545                 WDC_LOGD("Device MAC : " MACSECSTR "\n", MAC2SECSTR(list[i].mac_address));
546                 WDC_LOGD("Device Type: %d - %d", list[i].category, list[i].subcategory);
547                 WDC_LOGD("channel : %d\n", list[i].channel);
548                 WDC_LOGD("IP ["IPSECSTR"]\n", IP2SECSTR(list[i].ip_address));
549         }
550         WDC_LOGD("------------------------------------------\n");
551 }
552
553 void __wfd_client_print_persistent_group_info(wfd_persistent_group_info_s *list, int num)
554 {
555         int i = 0;
556
557         WDC_LOGD("------------------------------------------\n");
558         for (i = 0; i < num; i++) {
559                 WDC_LOGD("== Persistent Group index : %d ==", i);
560                 WDC_LOGD("ssid : %s", list[i].ssid);
561                 WDC_LOGD("GO MAC : " MACSECSTR, MAC2SECSTR(list[i].go_mac_address));
562         }
563         WDC_LOGD("------------------------------------------\n");
564 }
565
566 static int __wfd_client_launch_server_dbus(void)
567 {
568         GDBusConnection *netconfig_bus = NULL;
569         GError *g_error = NULL;
570
571 #if !GLIB_CHECK_VERSION(2,36,0)
572         g_type_init();
573 #endif
574         netconfig_bus = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, &g_error);
575         if (netconfig_bus == NULL) {
576                 if(g_error != NULL) {
577                         WDC_LOGE("Couldn't connect to system bus "
578                                         "error [%d: %s]", g_error->code, g_error->message);
579                         g_error_free(g_error);
580                 }
581                 return WIFI_DIRECT_ERROR_COMMUNICATION_FAILED;
582         }
583
584         g_dbus_connection_call_sync(netconfig_bus,
585                         NETCONFIG_SERVICE,
586                         NETCONFIG_WIFI_PATH,
587                         NETCONFIG_WIFI_INTERFACE,
588                         NETCONFIG_WIFI_LAUNCHDIRECT,
589                         NULL,
590                         NULL,
591                         G_DBUS_CALL_FLAGS_NONE,
592                         DBUS_REPLY_TIMEOUT,
593                         NULL,
594                         &g_error);
595
596         if(g_error !=NULL) {
597                 WDC_LOGE("g_dbus_connection_call_sync() failed"
598                                 "error [%d: %s]", g_error->code, g_error->message);
599                 g_error_free(g_error);
600                 return WIFI_DIRECT_ERROR_PERMISSION_DENIED;
601         }
602
603         g_object_unref(netconfig_bus);
604
605         WDC_LOGD("Successfully launched wfd-manager");
606         return WIFI_DIRECT_ERROR_NONE;
607 }
608
609 int wifi_direct_initialize(void)
610 {
611         __WDC_LOG_FUNC_START__;
612
613         CHECK_FEATURE_SUPPORTED(WIFIDIRECT_FEATURE);
614
615         bool wifi_direct_enable;
616         int res = 0;
617
618         if (g_client_info.is_registered == TRUE) {
619                 WDC_LOGW("Warning!!! Already registered\nUpdate user data and callback!");
620                 __WDC_LOG_FUNC_END__;
621                 return WIFI_DIRECT_ERROR_ALREADY_INITIALIZED;
622         }
623
624         res = system_info_get_platform_bool("tizen.org/feature/network.wifi.direct", &wifi_direct_enable);
625         if (res < 0) {
626                 WDC_LOGE("Failed to get sys info");
627                 __WDC_LOG_FUNC_END__;
628                 return res;
629         }
630
631         if(!wifi_direct_enable) {
632                 WDC_LOGE("Wi-Fi Direct not supported");
633                 return WIFI_DIRECT_ERROR_NOT_SUPPORTED;
634         }
635
636         wifi_direct_dbus_init();
637
638         WDC_LOGD("Launching wfd-server..\n");
639         res = __wfd_client_launch_server_dbus();
640         if (res != WIFI_DIRECT_ERROR_NONE)
641                 WDC_LOGE("Failed to send dbus msg[%s]", strerror(errno));
642
643         g_client_info.is_registered = TRUE;
644
645         /* Initialize callbacks */
646         g_client_info.activation_cb = NULL;
647         g_client_info.discover_cb = NULL;
648         g_client_info.connection_cb = NULL;
649         g_client_info.ip_assigned_cb = NULL;
650
651         g_client_info.peer_found_cb = NULL;
652         g_client_info.user_data_for_cb_activation = NULL;
653         g_client_info.user_data_for_cb_discover = NULL;
654         g_client_info.user_data_for_cb_connection = NULL;
655         g_client_info.user_data_for_cb_ip_assigned = NULL;
656         g_client_info.user_data_for_cb_peer_found = NULL;
657         g_client_info.user_data_for_cb_device_name = NULL;
658
659 #ifdef TIZEN_FEATURE_SERVICE_DISCOVERY
660         g_client_info.service_cb = NULL;
661         g_client_info.user_data_for_cb_service= NULL;
662 #endif /* TIZEN_FEATURE_SERVICE_DISCOVERY */
663
664         __WDC_LOG_FUNC_END__;
665         return WIFI_DIRECT_ERROR_NONE;
666 }
667
668 int wifi_direct_deinitialize(void)
669 {
670         __WDC_LOG_FUNC_START__;
671
672         CHECK_FEATURE_SUPPORTED(WIFIDIRECT_FEATURE);
673
674         if (g_client_info.is_registered == false) {
675                 WDC_LOGE("Client is already deregistered");
676                 __WDC_LOG_FUNC_END__;
677                 return WIFI_DIRECT_ERROR_NOT_INITIALIZED;
678         }
679
680         wifi_direct_dbus_deinit();
681
682         g_client_info.activation_cb = NULL;
683         g_client_info.discover_cb = NULL;
684         g_client_info.connection_cb = NULL;
685         g_client_info.ip_assigned_cb = NULL;
686         g_client_info.peer_found_cb = NULL;
687         g_client_info.user_data_for_cb_activation = NULL;
688         g_client_info.user_data_for_cb_discover = NULL;
689         g_client_info.user_data_for_cb_connection = NULL;
690         g_client_info.user_data_for_cb_ip_assigned = NULL;
691         g_client_info.user_data_for_cb_peer_found = NULL;
692
693 #ifdef TIZEN_FEATURE_SERVICE_DISCOVERY
694         g_client_info.service_cb = NULL;
695         g_client_info.user_data_for_cb_service = NULL;
696 #endif /* TIZEN_FEATURE_SERVICE_DISCOVERY */
697
698         g_client_info.is_registered = FALSE;
699
700         __WDC_LOG_FUNC_END__;
701         return WIFI_DIRECT_ERROR_NONE;
702 }
703
704
705 int wifi_direct_set_device_state_changed_cb(wifi_direct_device_state_changed_cb cb,
706                                             void *user_data)
707 {
708         __WDC_LOG_FUNC_START__;
709
710         CHECK_FEATURE_SUPPORTED(WIFIDIRECT_FEATURE);
711
712         if (!cb) {
713                 WDC_LOGE("Invalid parameter");
714                 __WDC_LOG_FUNC_END__;
715                 return WIFI_DIRECT_ERROR_INVALID_PARAMETER;
716         }
717
718         if (g_client_info.is_registered == false) {
719                 WDC_LOGE("Client is not initialized.");
720                 __WDC_LOG_FUNC_END__;
721                 return WIFI_DIRECT_ERROR_NOT_INITIALIZED;
722         }
723
724         g_client_info.activation_cb = cb;
725         g_client_info.user_data_for_cb_activation = user_data;
726
727         __WDC_LOG_FUNC_END__;
728         return WIFI_DIRECT_ERROR_NONE;
729 }
730
731
732 int wifi_direct_unset_device_state_changed_cb(void)
733 {
734         __WDC_LOG_FUNC_START__;
735
736         CHECK_FEATURE_SUPPORTED(WIFIDIRECT_FEATURE);
737
738         if (g_client_info.is_registered == false) {
739                 WDC_LOGE("Client is not initialized.\n");
740                 __WDC_LOG_FUNC_END__;
741                 return WIFI_DIRECT_ERROR_NOT_INITIALIZED;
742         }
743
744         g_client_info.activation_cb = NULL;
745         g_client_info.user_data_for_cb_activation = NULL;
746
747         __WDC_LOG_FUNC_END__;
748         return WIFI_DIRECT_ERROR_NONE;
749 }
750
751
752 int
753 wifi_direct_set_discovery_state_changed_cb(wifi_direct_discovery_state_chagned_cb cb,
754                                            void *user_data)
755 {
756         __WDC_LOG_FUNC_START__;
757
758         CHECK_FEATURE_SUPPORTED(WIFIDIRECT_FEATURE);
759
760         if (!cb) {
761                 WDC_LOGE("Callback is NULL.\n");
762                 __WDC_LOG_FUNC_END__;
763                 return WIFI_DIRECT_ERROR_INVALID_PARAMETER;
764         }
765
766         if (g_client_info.is_registered == false) {
767                 WDC_LOGE("Client is not initialized.\n");
768                 __WDC_LOG_FUNC_END__;
769                 return WIFI_DIRECT_ERROR_NOT_INITIALIZED;
770         }
771
772         g_client_info.discover_cb = cb;
773         g_client_info.user_data_for_cb_discover = user_data;
774
775         __WDC_LOG_FUNC_END__;
776         return WIFI_DIRECT_ERROR_NONE;
777 }
778
779
780 int wifi_direct_unset_discovery_state_changed_cb(void)
781 {
782         __WDC_LOG_FUNC_START__;
783
784         CHECK_FEATURE_SUPPORTED(WIFIDIRECT_FEATURE);
785
786         if (g_client_info.is_registered == false) {
787                 WDC_LOGE("Client is not initialized.\n");
788                 __WDC_LOG_FUNC_END__;
789                 return WIFI_DIRECT_ERROR_NOT_INITIALIZED;
790         }
791
792         g_client_info.discover_cb = NULL;
793         g_client_info.user_data_for_cb_discover = NULL;
794
795         __WDC_LOG_FUNC_END__;
796         return WIFI_DIRECT_ERROR_NONE;
797 }
798
799 int wifi_direct_set_peer_found_cb(wifi_direct_peer_found_cb cb,
800                                   void *user_data)
801 {
802         __WDC_LOG_FUNC_START__;
803
804         CHECK_FEATURE_SUPPORTED(WIFIDIRECT_FEATURE);
805
806         if (!cb) {
807                 WDC_LOGE("Callback is NULL.\n");
808                 __WDC_LOG_FUNC_END__;
809                 return WIFI_DIRECT_ERROR_INVALID_PARAMETER;
810         }
811
812         if (g_client_info.is_registered == false) {
813                 WDC_LOGE("Client is not initialized.\n");
814                 __WDC_LOG_FUNC_END__;
815                 return WIFI_DIRECT_ERROR_NOT_INITIALIZED;
816         }
817
818         g_client_info.peer_found_cb = cb;
819         g_client_info.user_data_for_cb_peer_found = user_data;
820
821         __WDC_LOG_FUNC_END__;
822         return WIFI_DIRECT_ERROR_NONE;
823 }
824
825
826 int wifi_direct_unset_peer_found_cb(void)
827 {
828         __WDC_LOG_FUNC_START__;
829
830         CHECK_FEATURE_SUPPORTED(WIFIDIRECT_FEATURE);
831
832         if (g_client_info.is_registered == false) {
833                 WDC_LOGE("Client is not initialized.\n");
834                 __WDC_LOG_FUNC_END__;
835                 return WIFI_DIRECT_ERROR_NOT_INITIALIZED;
836         }
837
838         g_client_info.peer_found_cb = NULL;
839         g_client_info.user_data_for_cb_peer_found = NULL;
840
841         __WDC_LOG_FUNC_END__;
842         return WIFI_DIRECT_ERROR_NONE;
843 }
844
845 int wifi_direct_set_service_state_changed_cb(wifi_direct_service_state_changed_cb cb,
846                                              void *user_data)
847 {
848 #ifdef TIZEN_FEATURE_SERVICE_DISCOVERY
849         __WDC_LOG_FUNC_START__;
850
851         CHECK_FEATURE_SUPPORTED(WIFIDIRECT_SERVICE_DISCOVERY_FEATURE);
852
853         if (!cb) {
854                 WDC_LOGE("Callback is NULL.");
855                 __WDC_LOG_FUNC_END__;
856                 return WIFI_DIRECT_ERROR_INVALID_PARAMETER;
857         }
858
859         if (g_client_info.is_registered == false) {
860                 WDC_LOGE("Client is not initialized.");
861                 __WDC_LOG_FUNC_END__;
862                 return WIFI_DIRECT_ERROR_NOT_INITIALIZED;
863         }
864
865         g_client_info.service_cb = cb;
866         g_client_info.user_data_for_cb_service = user_data;
867
868         __WDC_LOG_FUNC_END__;
869         return WIFI_DIRECT_ERROR_NONE;
870 #else /* TIZEN_FEATURE_SERVICE_DISCOVERY */
871         return WIFI_DIRECT_ERROR_NOT_SUPPORTED;
872 #endif /* TIZEN_FEATURE_SERVICE_DISCOVERY */
873 }
874
875
876 int wifi_direct_unset_service_state_changed_cb(void)
877 {
878 #ifdef TIZEN_FEATURE_SERVICE_DISCOVERY
879         __WDC_LOG_FUNC_START__;
880
881         CHECK_FEATURE_SUPPORTED(WIFIDIRECT_SERVICE_DISCOVERY_FEATURE);
882
883         if (g_client_info.is_registered == false) {
884                 WDC_LOGE("Client is not initialized.");
885                 __WDC_LOG_FUNC_END__;
886                 return WIFI_DIRECT_ERROR_NOT_INITIALIZED;
887         }
888
889         g_client_info.service_cb = NULL;
890         g_client_info.user_data_for_cb_service = NULL;
891
892         __WDC_LOG_FUNC_END__;
893         return WIFI_DIRECT_ERROR_NONE;
894 #else /* TIZEN_FEATURE_SERVICE_DISCOVERY */
895         return WIFI_DIRECT_ERROR_NOT_SUPPORTED;
896 #endif /* TIZEN_FEATURE_SERVICE_DISCOVERY */
897 }
898
899 int wifi_direct_set_connection_state_changed_cb(wifi_direct_connection_state_changed_cb cb,
900                                                 void *user_data)
901 {
902         __WDC_LOG_FUNC_START__;
903
904         CHECK_FEATURE_SUPPORTED(WIFIDIRECT_FEATURE);
905
906         if (!cb) {
907                 WDC_LOGE("Callback is NULL.\n");
908                 __WDC_LOG_FUNC_END__;
909                 return WIFI_DIRECT_ERROR_INVALID_PARAMETER;
910         }
911
912         if (g_client_info.is_registered == false) {
913                 WDC_LOGE("Client is not initialized.\n");
914                 __WDC_LOG_FUNC_END__;
915                 return WIFI_DIRECT_ERROR_NOT_INITIALIZED;
916         }
917
918         g_client_info.connection_cb = cb;
919         g_client_info.user_data_for_cb_connection = user_data;
920
921         __WDC_LOG_FUNC_END__;
922         return WIFI_DIRECT_ERROR_NONE;
923 }
924
925
926 int wifi_direct_unset_connection_state_changed_cb(void)
927 {
928         __WDC_LOG_FUNC_START__;
929
930         CHECK_FEATURE_SUPPORTED(WIFIDIRECT_FEATURE);
931
932         if (g_client_info.is_registered == false) {
933                 WDC_LOGE("Client is not initialized");
934                 __WDC_LOG_FUNC_END__;
935                 return WIFI_DIRECT_ERROR_NOT_INITIALIZED;
936         }
937
938         g_client_info.connection_cb = NULL;
939         g_client_info.user_data_for_cb_connection = NULL;
940
941         __WDC_LOG_FUNC_END__;
942         return WIFI_DIRECT_ERROR_NONE;
943 }
944
945
946 int wifi_direct_set_client_ip_address_assigned_cb(wifi_direct_client_ip_address_assigned_cb cb,
947                                                   void* user_data)
948 {
949         __WDC_LOG_FUNC_START__;
950
951         CHECK_FEATURE_SUPPORTED(WIFIDIRECT_FEATURE);
952
953         if (!cb) {
954                 WDC_LOGE("Callback is NULL");
955                 __WDC_LOG_FUNC_END__;
956                 return WIFI_DIRECT_ERROR_INVALID_PARAMETER;
957         }
958
959         if (g_client_info.is_registered == false) {
960                 WDC_LOGE("Client is not initialized");
961                 __WDC_LOG_FUNC_END__;
962                 return WIFI_DIRECT_ERROR_NOT_INITIALIZED;
963         }
964
965         g_client_info.ip_assigned_cb = cb;
966         g_client_info.user_data_for_cb_ip_assigned = user_data;
967
968         __WDC_LOG_FUNC_END__;
969         return WIFI_DIRECT_ERROR_NONE;
970 }
971
972 int wifi_direct_unset_client_ip_address_assigned_cb(void)
973 {
974         __WDC_LOG_FUNC_START__;
975
976         CHECK_FEATURE_SUPPORTED(WIFIDIRECT_FEATURE);
977
978         if (g_client_info.is_registered == false) {
979                 WDC_LOGE("Client is not initialized");
980                 __WDC_LOG_FUNC_END__;
981                 return WIFI_DIRECT_ERROR_NOT_INITIALIZED;
982         }
983
984         g_client_info.ip_assigned_cb = NULL;
985         g_client_info.user_data_for_cb_ip_assigned = NULL;
986
987         __WDC_LOG_FUNC_END__;
988         return WIFI_DIRECT_ERROR_NONE;
989 }
990
991 int wifi_direct_activate(void)
992 {
993         __WDC_LOG_FUNC_START__;
994         GError *error = NULL;
995         GVariant *reply = NULL;
996         int ret = WIFI_DIRECT_ERROR_NONE;
997
998         CHECK_FEATURE_SUPPORTED(WIFIDIRECT_FEATURE);
999
1000         if (g_client_info.is_registered == false) {
1001                 WDC_LOGE("Client is NOT registered");
1002                 __WDC_LOG_FUNC_END__;
1003                 return WIFI_DIRECT_ERROR_NOT_INITIALIZED;
1004         }
1005
1006         reply = wifi_direct_dbus_method_call_sync(WFD_MANAGER_MANAGE_INTERFACE,
1007                                                     "Activate", NULL, &error);
1008         if (error != NULL) {
1009                 WDC_LOGE("wifi_direct_dbus_method_call_sync() failed."
1010                                 "error [%d: %s]", error->code, error->message);
1011                 g_error_free(error);
1012                 __WDC_LOG_FUNC_END__;
1013                 return WIFI_DIRECT_ERROR_OPERATION_FAILED;
1014         }
1015
1016         g_variant_get(reply, "(i)", &ret);
1017         g_variant_unref(reply);
1018
1019         WDC_LOGD("%s() return : [%d]", __func__, ret);
1020         __WDC_LOG_FUNC_END__;
1021         return ret;
1022 }
1023
1024 int wifi_direct_deactivate(void)
1025 {
1026         __WDC_LOG_FUNC_START__;
1027         GError *error = NULL;
1028         GVariant *reply = NULL;
1029         int ret = WIFI_DIRECT_ERROR_NONE;
1030
1031         CHECK_FEATURE_SUPPORTED(WIFIDIRECT_FEATURE);
1032
1033         if (g_client_info.is_registered == false) {
1034                 WDC_LOGE("Client is NOT registered");
1035                 __WDC_LOG_FUNC_END__;
1036                 return WIFI_DIRECT_ERROR_NOT_INITIALIZED;
1037         }
1038
1039         reply = wifi_direct_dbus_method_call_sync(WFD_MANAGER_MANAGE_INTERFACE,
1040                                                   "Deactivate", NULL, &error);
1041         if (error != NULL) {
1042                 WDC_LOGE("wifi_direct_dbus_method_call_sync() failed."
1043                                 "error [%d: %s]", error->code, error->message);
1044                 g_error_free(error);
1045                 __WDC_LOG_FUNC_END__;
1046                 return WIFI_DIRECT_ERROR_OPERATION_FAILED;
1047         }
1048
1049         g_variant_get(reply, "(i)", &ret);
1050         g_variant_unref(reply);
1051
1052         WDC_LOGD("%s() return : [%d]", __func__, ret);
1053         __WDC_LOG_FUNC_END__;
1054         return ret;
1055 }
1056
1057 int wifi_direct_start_discovery(bool listen_only, int timeout)
1058 {
1059         __WDC_LOG_FUNC_START__;
1060         GVariantBuilder *builder = NULL;
1061         GVariant *params = NULL;
1062         GError *error = NULL;
1063         GVariant *reply = NULL;
1064         int ret = WIFI_DIRECT_ERROR_NONE;
1065
1066         CHECK_FEATURE_SUPPORTED(WIFIDIRECT_FEATURE);
1067
1068         if (g_client_info.is_registered == false) {
1069                 WDC_LOGE("Client is NOT registered");
1070                 __WDC_LOG_FUNC_END__;
1071                 return WIFI_DIRECT_ERROR_NOT_INITIALIZED;
1072         }
1073
1074         if (timeout < 0) {
1075                 WDC_LOGE("Negative value. Param [timeout]!");
1076                 __WDC_LOG_FUNC_END__;
1077                 return WIFI_DIRECT_ERROR_INVALID_PARAMETER;
1078         }
1079
1080         builder = g_variant_builder_new(G_VARIANT_TYPE ("a{sv}"));
1081         g_variant_builder_add(builder, "{sv}", "Mode", g_variant_new("b", listen_only));
1082         g_variant_builder_add(builder, "{sv}", "Timeout", g_variant_new("i", timeout));
1083         params = g_variant_new("(a{sv})", builder);
1084         g_variant_builder_unref(builder);
1085         WDC_LOGI("listen only (%d) timeout (%d)", listen_only, timeout);
1086
1087         reply = wifi_direct_dbus_method_call_sync(WFD_MANAGER_MANAGE_INTERFACE,
1088                                                   "StartDiscovery", params, &error);
1089         if (error != NULL) {
1090                 WDC_LOGE("wifi_direct_dbus_method_call_sync() failed."
1091                                 "error [%d: %s]", error->code, error->message);
1092                 g_error_free(error);
1093                 __WDC_LOG_FUNC_END__;
1094                 return WIFI_DIRECT_ERROR_OPERATION_FAILED;
1095         }
1096
1097         g_variant_get(reply, "(i)", &ret);
1098         g_variant_unref(reply);
1099
1100         WDC_LOGD("%s() return : [%d]", __func__, ret);
1101         __WDC_LOG_FUNC_END__;
1102         return ret;
1103 }
1104
1105 int wifi_direct_start_discovery_specific_channel(bool listen_only,
1106                                                  int timeout,
1107                                                  wifi_direct_discovery_channel_e channel)
1108 {
1109         __WDC_LOG_FUNC_START__;
1110         GVariantBuilder *builder = NULL;
1111         GVariant *params = NULL;
1112         GError *error = NULL;
1113         GVariant *reply = NULL;
1114         int ret = WIFI_DIRECT_ERROR_NONE;
1115
1116         CHECK_FEATURE_SUPPORTED(WIFIDIRECT_FEATURE);
1117
1118         if (g_client_info.is_registered == false) {
1119                 WDC_LOGE("Client is NOT registered");
1120                 __WDC_LOG_FUNC_END__;
1121                 return WIFI_DIRECT_ERROR_NOT_INITIALIZED;
1122         }
1123
1124         if (timeout < 0) {
1125                 WDC_LOGE("Negative value. Param [timeout]!");
1126                 __WDC_LOG_FUNC_END__;
1127                 return WIFI_DIRECT_ERROR_INVALID_PARAMETER;
1128         }
1129
1130         builder = g_variant_builder_new(G_VARIANT_TYPE ("a{sv}"));
1131         g_variant_builder_add(builder, "{sv}", "Mode", g_variant_new("b", listen_only));
1132         g_variant_builder_add(builder, "{sv}", "Timeout", g_variant_new("i", timeout));
1133         g_variant_builder_add(builder, "{sv}", "Channel", g_variant_new("i", channel));
1134         params = g_variant_new("(a{sv})", builder);
1135         g_variant_builder_unref(builder);
1136         WDC_LOGI("listen only (%d) timeout (%d)", listen_only, timeout);
1137
1138         reply = wifi_direct_dbus_method_call_sync(WFD_MANAGER_MANAGE_INTERFACE,
1139                                                   "StartDiscovery", params, &error);
1140         if (error != NULL) {
1141                 WDC_LOGE("wifi_direct_dbus_method_call_sync() failed."
1142                                 "error [%d: %s]", error->code, error->message);
1143                 g_error_free(error);
1144                 __WDC_LOG_FUNC_END__;
1145                 return WIFI_DIRECT_ERROR_OPERATION_FAILED;
1146         }
1147
1148         g_variant_get(reply, "(i)", &ret);
1149         g_variant_unref(reply);
1150
1151         WDC_LOGD("%s() return : [%d]", __func__, ret);
1152         __WDC_LOG_FUNC_END__;
1153         return ret;
1154 }
1155
1156 int wifi_direct_cancel_discovery(void)
1157 {
1158         __WDC_LOG_FUNC_START__;
1159         GError *error = NULL;
1160         GVariant *reply = NULL;
1161         int ret = WIFI_DIRECT_ERROR_NONE;
1162
1163         CHECK_FEATURE_SUPPORTED(WIFIDIRECT_FEATURE);
1164
1165         if (g_client_info.is_registered == false) {
1166                 WDC_LOGE("Client is NOT registered");
1167                 __WDC_LOG_FUNC_END__;
1168                 return WIFI_DIRECT_ERROR_NOT_INITIALIZED;
1169         }
1170
1171         reply = wifi_direct_dbus_method_call_sync(WFD_MANAGER_MANAGE_INTERFACE,
1172                                                   "StopDiscovery", NULL, &error);
1173         if (error != NULL) {
1174                 WDC_LOGE("wifi_direct_dbus_method_call_sync() failed."
1175                                 "error [%d: %s]", error->code, error->message);
1176                 g_error_free(error);
1177                 __WDC_LOG_FUNC_END__;
1178                 return WIFI_DIRECT_ERROR_OPERATION_FAILED;
1179         }
1180
1181         g_variant_get(reply, "(i)", &ret);
1182         g_variant_unref(reply);
1183
1184         WDC_LOGD("%s() return : [%d]", __func__, ret);
1185         __WDC_LOG_FUNC_END__;
1186         return ret;
1187 }
1188
1189 #ifdef TIZEN_FEATURE_SERVICE_DISCOVERY
1190 static char **get_service_list(char *services, unsigned int *count)
1191 {
1192         __WDC_LOG_FUNC_START__;
1193         char **result = NULL;
1194         char *pos1 = NULL;
1195         char *pos2 = NULL;
1196         unsigned int cnt = 0;
1197         unsigned int i = 0;
1198         unsigned int j = 0;
1199
1200         if (!count || !services || (services && strlen(services) <= 0)) {
1201                 WDC_LOGE("Invalid parameters.");
1202                 __WDC_LOG_FUNC_END__;
1203                 return NULL;
1204         }
1205
1206         pos1 = services;
1207         pos2 = g_strdup(services);
1208
1209         pos1 = strtok (pos1,",\n");
1210         while (pos1) {
1211                 cnt++;
1212                 pos1 = strtok (NULL, ",\n");
1213         }
1214         WDC_LOGD("Total Service Count = %d", cnt);
1215
1216         if (cnt > 0) {
1217                 result = (char**) g_try_malloc0_n(cnt, sizeof(char *));
1218                 if (!result) {
1219                         WDC_LOGE("Failed to allocate memory for result");
1220                         g_free(pos2);
1221                         return NULL;
1222                 }
1223                 pos2 = strtok (pos2,",\n");
1224                 while (pos2 != NULL) {
1225                         char *s = strchr(pos2, ' ');
1226                         if (s) {
1227                                 *s = '\0';
1228                                 result[i++] = strdup(pos2);
1229                                 pos2 = strtok (NULL, ",\n");
1230                         }
1231                 }
1232         }
1233
1234         g_free(pos1);
1235         g_free(pos2);
1236
1237         if (cnt == i) {
1238                 *count = cnt;
1239                 return result;
1240         } else {
1241                 *count = 0;
1242                 if (result) {
1243                         for (j=0; j<i && result[j] != NULL; j++)
1244                                 free(result[j]);
1245                         free(result);
1246                 }
1247                 return NULL;
1248         }
1249 }
1250 #endif /* TIZEN_FEATURE_SERVICE_DISCOVERY */
1251
1252 int wifi_direct_foreach_discovered_peers(wifi_direct_discovered_peer_cb cb,
1253                                          void *user_data)
1254 {
1255         __WDC_LOG_FUNC_START__;
1256
1257         CHECK_FEATURE_SUPPORTED(WIFIDIRECT_FEATURE);
1258
1259         GVariant *params = NULL;
1260         GError *error = NULL;
1261         GVariant *reply = NULL;
1262         GVariantIter *iter_peers = NULL;
1263         GVariantIter *iter_peer = NULL;
1264         GVariant *var = NULL;
1265         gchar *key = NULL;
1266         int ret = WIFI_DIRECT_ERROR_NONE;
1267
1268         if (g_client_info.is_registered == false) {
1269                 WDC_LOGE("Client is NOT registered");
1270                 __WDC_LOG_FUNC_END__;
1271                 return WIFI_DIRECT_ERROR_NOT_INITIALIZED;
1272         }
1273
1274         if (!cb) {
1275                 WDC_LOGE("NULL Param [callback]!");
1276                 __WDC_LOG_FUNC_END__;
1277                 return WIFI_DIRECT_ERROR_INVALID_PARAMETER;
1278         }
1279
1280         reply = wifi_direct_dbus_method_call_sync(WFD_MANAGER_MANAGE_INTERFACE,
1281                                                   "GetDiscoveredPeers", params, &error);
1282         if (error != NULL) {
1283                 WDC_LOGE("wifi_direct_dbus_method_call_sync() failed."
1284                                 "error [%d: %s]", error->code, error->message);
1285                 g_error_free(error);
1286                 __WDC_LOG_FUNC_END__;
1287                 return WIFI_DIRECT_ERROR_OPERATION_FAILED;
1288         }
1289
1290         g_variant_get(reply, "(iaa{sv})", &ret, &iter_peers);
1291         if (ret != WIFI_DIRECT_ERROR_NONE) {
1292                 __WDC_LOG_FUNC_END__;
1293                 return WIFI_DIRECT_ERROR_OPERATION_FAILED;
1294         }
1295
1296         WDC_LOGD("wifi_direct_foreach_discovered_peers() SUCCESS");
1297
1298         while(g_variant_iter_loop(iter_peers, "a{sv}", &iter_peer)) {
1299                 wifi_direct_discovered_peer_info_s *peer_list = NULL;
1300
1301                 peer_list = (wifi_direct_discovered_peer_info_s *) g_try_malloc0(sizeof(wifi_direct_discovered_peer_info_s));
1302                 if (!peer_list) {
1303                         WDC_LOGE("Failed to allocate memory");
1304                         continue;
1305                 }
1306
1307                 while (g_variant_iter_loop(iter_peer, "{sv}", &key, &var)) {
1308                         if (!g_strcmp0(key, "DeviceName")) {
1309                                 const char *device_name = NULL;
1310
1311                                 g_variant_get(var, "&s", &device_name);
1312                                 peer_list->device_name = g_strndup(device_name, WIFI_DIRECT_MAX_DEVICE_NAME_LEN+1);
1313
1314                         } else if (!g_strcmp0(key, "DeviceAddress")) {
1315                                 unsigned char mac_address[MACADDR_LEN] = {0, };
1316
1317                                 wifi_direct_dbus_unpack_ay(mac_address, var, MACADDR_LEN);
1318                                 peer_list->mac_address = (char*) g_try_malloc0(MACSTR_LEN);
1319                                 if (peer_list->mac_address)
1320                                         g_snprintf(peer_list->mac_address, MACSTR_LEN, MACSTR, MAC2STR(mac_address));
1321
1322                         } else if (!g_strcmp0(key, "InterfaceAddress")) {
1323                                 unsigned char intf_address[MACADDR_LEN] = {0, };
1324
1325                                 wifi_direct_dbus_unpack_ay(intf_address, var, MACADDR_LEN);
1326                                 peer_list->interface_address = (char*) g_try_malloc0(MACSTR_LEN);
1327                                 if (peer_list->interface_address)
1328                                         g_snprintf(peer_list->interface_address, MACSTR_LEN, MACSTR, MAC2STR(intf_address));
1329
1330                         } else if (!g_strcmp0(key, "Channel")) {
1331                                 peer_list->channel = g_variant_get_uint16(var);
1332
1333                         } else if (!g_strcmp0(key, "IsGroupOwner")) {
1334                                 peer_list->is_group_owner = g_variant_get_boolean(var);
1335
1336                         } else if (!g_strcmp0(key, "IsPersistentGO")) {
1337                                 peer_list->is_persistent_group_owner = g_variant_get_boolean(var);
1338
1339                         } else if (!g_strcmp0(key, "IsConnected")) {
1340                                 peer_list->is_connected = g_variant_get_boolean(var);
1341
1342                         } else if (!g_strcmp0(key, "Category")) {
1343                                 peer_list->primary_device_type = g_variant_get_uint16(var);
1344
1345                         } else if (!g_strcmp0(key, "SubCategory")) {
1346                                 peer_list->secondary_device_type = g_variant_get_uint16(var);
1347
1348                         } else if (!g_strcmp0(key, "IsWfdDevice")) {
1349 #ifdef TIZEN_FEATURE_WIFI_DISPLAY
1350                                 peer_list->is_miracast_device = g_variant_get_boolean(var);
1351 #endif /* TIZEN_FEATURE_WIFI_DISPLAY */
1352                         } else {
1353                                 ;/* Do Nothing */
1354                         }
1355                 }
1356
1357                 //__wfd_client_print_entry_list(peer_list, 1);
1358                 if (!cb(peer_list, user_data)) {
1359                         g_variant_iter_free(iter_peer);
1360                         break;
1361                 }
1362         }
1363
1364         g_variant_iter_free(iter_peers);
1365         g_variant_unref(reply);
1366         __WDC_LOG_FUNC_END__;
1367         return WIFI_DIRECT_ERROR_NONE;
1368 }
1369
1370 int wifi_direct_connect(char *mac_address)
1371 {
1372         __WDC_LOG_FUNC_START__;
1373
1374         CHECK_FEATURE_SUPPORTED(WIFIDIRECT_FEATURE);
1375
1376         GVariant *params = NULL;
1377         GError *error = NULL;
1378         GVariant *reply = NULL;
1379         int ret = WIFI_DIRECT_ERROR_NONE;
1380
1381         if (g_client_info.is_registered == false) {
1382                 WDC_LOGE("Client is NOT registered");
1383                 __WDC_LOG_FUNC_END__;
1384                 return WIFI_DIRECT_ERROR_NOT_INITIALIZED;
1385         }
1386
1387         if (!mac_address) {
1388                 WDC_LOGE("mac_addr is NULL");
1389                 __WDC_LOG_FUNC_END__;
1390                 return WIFI_DIRECT_ERROR_INVALID_PARAMETER;
1391         }
1392
1393         params = g_variant_new("(s)", mac_address);
1394         reply = wifi_direct_dbus_method_call_sync(WFD_MANAGER_MANAGE_INTERFACE,
1395                                                   "Connect", params, &error);
1396         if (error != NULL) {
1397                 WDC_LOGE("wifi_direct_dbus_method_call_sync() failed."
1398                                 "error [%d: %s]", error->code, error->message);
1399                 g_error_free(error);
1400                 __WDC_LOG_FUNC_END__;
1401                 return WIFI_DIRECT_ERROR_OPERATION_FAILED;
1402         }
1403
1404         g_variant_get(reply, "(i)", &ret);
1405         g_variant_unref(reply);
1406
1407         WDC_LOGD("%s() return : [%d]", __func__, ret);
1408         __WDC_LOG_FUNC_END__;
1409         return ret;
1410 }
1411
1412 int wifi_direct_cancel_connection(char *mac_address)
1413 {
1414         __WDC_LOG_FUNC_START__;
1415
1416         CHECK_FEATURE_SUPPORTED(WIFIDIRECT_FEATURE);
1417
1418         GVariant *params = NULL;
1419         GError *error = NULL;
1420         GVariant *reply = NULL;
1421         int ret = WIFI_DIRECT_ERROR_NONE;
1422
1423         if (g_client_info.is_registered == false) {
1424                 WDC_LOGE("Client is NOT registered");
1425                 __WDC_LOG_FUNC_END__;
1426                 return WIFI_DIRECT_ERROR_NOT_INITIALIZED;
1427         }
1428
1429         if (!mac_address) {
1430                 WDC_LOGE("mac_addr is NULL");
1431                 __WDC_LOG_FUNC_END__;
1432                 return WIFI_DIRECT_ERROR_INVALID_PARAMETER;
1433         }
1434
1435         params = g_variant_new("(s)", mac_address);
1436         reply = wifi_direct_dbus_method_call_sync(WFD_MANAGER_MANAGE_INTERFACE,
1437                                                   "CancelConnection", params, &error);
1438         if (error != NULL) {
1439                 WDC_LOGE("wifi_direct_dbus_method_call_sync() failed."
1440                                 "error [%d: %s]", error->code, error->message);
1441                 g_error_free(error);
1442                 __WDC_LOG_FUNC_END__;
1443                 return WIFI_DIRECT_ERROR_OPERATION_FAILED;
1444         }
1445
1446         g_variant_get(reply, "(i)", &ret);
1447         g_variant_unref(reply);
1448
1449         WDC_LOGD("%s() return : [%d]", __func__, ret);
1450         __WDC_LOG_FUNC_END__;
1451         return ret;
1452 }
1453
1454
1455 int wifi_direct_reject_connection(char *mac_address)
1456 {
1457         __WDC_LOG_FUNC_START__;
1458
1459         CHECK_FEATURE_SUPPORTED(WIFIDIRECT_FEATURE);
1460
1461         GVariant *params = NULL;
1462         GError *error = NULL;
1463         GVariant *reply = NULL;
1464         int ret = WIFI_DIRECT_ERROR_NONE;
1465
1466         if (g_client_info.is_registered == false) {
1467                 WDC_LOGE("Client is NOT registered");
1468                 __WDC_LOG_FUNC_END__;
1469                 return WIFI_DIRECT_ERROR_NOT_INITIALIZED;
1470         }
1471
1472         if (!mac_address) {
1473                 WDC_LOGE("mac_addr is NULL");
1474                 __WDC_LOG_FUNC_END__;
1475                 return WIFI_DIRECT_ERROR_INVALID_PARAMETER;
1476         }
1477
1478         params = g_variant_new("(s)", mac_address);
1479         reply = wifi_direct_dbus_method_call_sync(WFD_MANAGER_MANAGE_INTERFACE,
1480                                                   "RejectConnection", params, &error);
1481         if (error != NULL) {
1482                 WDC_LOGE("wifi_direct_dbus_method_call_sync() failed."
1483                                 "error [%d: %s]", error->code, error->message);
1484                 g_error_free(error);
1485                 __WDC_LOG_FUNC_END__;
1486                 return WIFI_DIRECT_ERROR_OPERATION_FAILED;
1487         }
1488
1489         g_variant_get(reply, "(i)", &ret);
1490         g_variant_unref(reply);
1491
1492         WDC_LOGD("%s() return : [%d]", __func__, ret);
1493         __WDC_LOG_FUNC_END__;
1494         return ret;
1495 }
1496
1497
1498 int wifi_direct_disconnect_all(void)
1499 {
1500         __WDC_LOG_FUNC_START__;
1501
1502         CHECK_FEATURE_SUPPORTED(WIFIDIRECT_FEATURE);
1503
1504         GError *error = NULL;
1505         GVariant *reply = NULL;
1506         int ret = WIFI_DIRECT_ERROR_NONE;
1507
1508         if (g_client_info.is_registered == false) {
1509                 WDC_LOGE("Client is NOT registered");
1510                 __WDC_LOG_FUNC_END__;
1511                 return WIFI_DIRECT_ERROR_NOT_INITIALIZED;
1512         }
1513
1514         reply = wifi_direct_dbus_method_call_sync(WFD_MANAGER_MANAGE_INTERFACE,
1515                                                   "DisconnectAll", NULL, &error);
1516         if (error != NULL) {
1517                 WDC_LOGE("wifi_direct_dbus_method_call_sync() failed."
1518                                 "error [%d: %s]", error->code, error->message);
1519                 g_error_free(error);
1520                 __WDC_LOG_FUNC_END__;
1521                 return WIFI_DIRECT_ERROR_OPERATION_FAILED;
1522         }
1523
1524         g_variant_get(reply, "(i)", &ret);
1525         g_variant_unref(reply);
1526
1527         WDC_LOGD("%s() return : [%d]", __func__, ret);
1528         __WDC_LOG_FUNC_END__;
1529         return ret;
1530 }
1531
1532
1533 int wifi_direct_disconnect(char *mac_address)
1534 {
1535         __WDC_LOG_FUNC_START__;
1536
1537         CHECK_FEATURE_SUPPORTED(WIFIDIRECT_FEATURE);
1538
1539         GVariant *params = NULL;
1540         GError *error = NULL;
1541         GVariant *reply = NULL;
1542         int ret = WIFI_DIRECT_ERROR_NONE;
1543
1544         if (g_client_info.is_registered == false) {
1545                 WDC_LOGE("Client is NOT registered");
1546                 __WDC_LOG_FUNC_END__;
1547                 return WIFI_DIRECT_ERROR_NOT_INITIALIZED;
1548         }
1549
1550         if (!mac_address) {
1551                 WDC_LOGE("mac_addr is NULL");
1552                 __WDC_LOG_FUNC_END__;
1553                 return WIFI_DIRECT_ERROR_INVALID_PARAMETER;
1554         }
1555
1556         params = g_variant_new("(s)", mac_address);
1557         reply = wifi_direct_dbus_method_call_sync(WFD_MANAGER_MANAGE_INTERFACE,
1558                                                   "Disconnect", params, &error);
1559         if (error != NULL) {
1560                 WDC_LOGE("wifi_direct_dbus_method_call_sync() failed."
1561                                 "error [%d: %s]", error->code, error->message);
1562                 g_error_free(error);
1563                 __WDC_LOG_FUNC_END__;
1564                 return WIFI_DIRECT_ERROR_OPERATION_FAILED;
1565         }
1566
1567         g_variant_get(reply, "(i)", &ret);
1568         g_variant_unref(reply);
1569
1570         WDC_LOGD("%s() return : [%d]", __func__, ret);
1571         __WDC_LOG_FUNC_END__;
1572         return ret;
1573 }
1574
1575 int wifi_direct_accept_connection(char *mac_address)
1576 {
1577         __WDC_LOG_FUNC_START__;
1578
1579         CHECK_FEATURE_SUPPORTED(WIFIDIRECT_FEATURE);
1580
1581         GVariant *params = NULL;
1582         GError *error = NULL;
1583         GVariant *reply = NULL;
1584         int ret = WIFI_DIRECT_ERROR_NONE;
1585
1586         if (g_client_info.is_registered == false) {
1587                 WDC_LOGE("Client is NOT registered");
1588                 __WDC_LOG_FUNC_END__;
1589                 return WIFI_DIRECT_ERROR_NOT_INITIALIZED;
1590         }
1591
1592         if (!mac_address) {
1593                 WDC_LOGE("mac_addr is NULL");
1594                 __WDC_LOG_FUNC_END__;
1595                 return WIFI_DIRECT_ERROR_INVALID_PARAMETER;
1596         }
1597
1598         params = g_variant_new("(s)", mac_address);
1599         reply = wifi_direct_dbus_method_call_sync(WFD_MANAGER_MANAGE_INTERFACE,
1600                                                   "AcceptConnection", params, &error);
1601         if (error != NULL) {
1602                 WDC_LOGE("wifi_direct_dbus_method_call_sync() failed."
1603                                 "error [%d: %s]", error->code, error->message);
1604                 g_error_free(error);
1605                 __WDC_LOG_FUNC_END__;
1606                 return WIFI_DIRECT_ERROR_OPERATION_FAILED;
1607         }
1608
1609         g_variant_get(reply, "(i)", &ret);
1610         g_variant_unref(reply);
1611
1612         WDC_LOGD("%s() return : [%d]", __func__, ret);
1613         __WDC_LOG_FUNC_END__;
1614         return ret;
1615 }
1616
1617
1618 int wifi_direct_foreach_connected_peers(wifi_direct_connected_peer_cb cb,
1619                                         void *user_data)
1620 {
1621         __WDC_LOG_FUNC_START__;
1622
1623         CHECK_FEATURE_SUPPORTED(WIFIDIRECT_FEATURE);
1624
1625         GVariant *params = NULL;
1626         GError *error = NULL;
1627         GVariant *reply = NULL;
1628         GVariantIter *iter_peers = NULL;
1629         GVariantIter *iter_peer = NULL;
1630         GVariant *var = NULL;
1631         gchar *key = NULL;
1632         int ret = WIFI_DIRECT_ERROR_NONE;
1633
1634         if (g_client_info.is_registered == false) {
1635                 WDC_LOGE("Client is NOT registered");
1636                 __WDC_LOG_FUNC_END__;
1637                 return WIFI_DIRECT_ERROR_NOT_INITIALIZED;
1638         }
1639
1640         if (!cb) {
1641                 WDC_LOGE("NULL Param [callback]!");
1642                 __WDC_LOG_FUNC_END__;
1643                 return WIFI_DIRECT_ERROR_INVALID_PARAMETER;
1644         }
1645
1646         reply = wifi_direct_dbus_method_call_sync(WFD_MANAGER_MANAGE_INTERFACE,
1647                                                   "GetConnectedPeers", params, &error);
1648         if (error != NULL) {
1649                 WDC_LOGE("wifi_direct_dbus_method_call_sync() failed."
1650                                 "error [%d: %s]", error->code, error->message);
1651                 g_error_free(error);
1652                 __WDC_LOG_FUNC_END__;
1653                 return WIFI_DIRECT_ERROR_OPERATION_FAILED;
1654         }
1655
1656         g_variant_get(reply, "(iaa{sv})", &ret, &iter_peers);
1657         if (ret != WIFI_DIRECT_ERROR_NONE) {
1658                 __WDC_LOG_FUNC_END__;
1659                 return WIFI_DIRECT_ERROR_OPERATION_FAILED;
1660         }
1661
1662         WDC_LOGD("wifi_direct_foreach_connected_peers() SUCCESS");
1663
1664         while(g_variant_iter_loop(iter_peers, "a{sv}", &iter_peer)) {
1665                 wifi_direct_connected_peer_info_s *peer_list = NULL;
1666
1667                 peer_list = (wifi_direct_connected_peer_info_s *) g_try_malloc0(sizeof(wifi_direct_connected_peer_info_s));
1668                 if (!peer_list) {
1669                         WDC_LOGE("Failed to allocate memory");
1670                         continue;
1671                 }
1672
1673                 while (g_variant_iter_loop(iter_peer, "{sv}", &key, &var)) {
1674                         if (!g_strcmp0(key, "DeviceName")) {
1675                                 const char *device_name = NULL;
1676
1677                                 g_variant_get(var, "&s", &device_name);
1678                                 peer_list->device_name = g_strndup(device_name, WIFI_DIRECT_MAX_DEVICE_NAME_LEN+1);
1679
1680                         } else if (!g_strcmp0(key, "DeviceAddress")) {
1681                                 unsigned char mac_address[MACADDR_LEN] = {0, };
1682
1683                                 wifi_direct_dbus_unpack_ay(mac_address, var, MACADDR_LEN);
1684                                 peer_list->mac_address = (char*) g_try_malloc0(MACSTR_LEN);
1685                                 if (peer_list->mac_address)
1686                                         g_snprintf(peer_list->mac_address, MACSTR_LEN, MACSTR, MAC2STR(mac_address));
1687
1688                         } else if (!g_strcmp0(key, "InterfaceAddress")) {
1689                                 unsigned char intf_address[MACADDR_LEN] = {0, };
1690
1691                                 wifi_direct_dbus_unpack_ay(intf_address, var, MACADDR_LEN);
1692                                 peer_list->interface_address = (char*) g_try_malloc0(MACSTR_LEN);
1693                                 if (peer_list->interface_address)
1694                                         g_snprintf(peer_list->interface_address, MACSTR_LEN, MACSTR, MAC2STR(intf_address));
1695
1696                         } else if (!g_strcmp0(key, "IPAddress")) {
1697                                 unsigned char ip_address[IPADDR_LEN] = {0, };
1698
1699                                 wifi_direct_dbus_unpack_ay(ip_address, var, IPADDR_LEN);
1700                                 peer_list->ip_address = (char*) g_try_malloc0(IPSTR_LEN);
1701                                 if (peer_list->ip_address)
1702                                         g_snprintf(peer_list->ip_address, IPSTR_LEN, IPSTR, IP2STR(ip_address));
1703
1704                         } else if (!g_strcmp0(key, "Channel")) {
1705                                 peer_list->channel = g_variant_get_uint16(var);
1706
1707                         } else if (!g_strcmp0(key, "Category")) {
1708                                 peer_list->primary_device_type = g_variant_get_uint16(var);
1709
1710                         } else if (!g_strcmp0(key, "SubCategory")) {
1711                                 peer_list->secondary_device_type = g_variant_get_uint16(var);
1712
1713                         } else if (!g_strcmp0(key, "IsWfdDevice")) {
1714 #ifdef TIZEN_FEATURE_WIFI_DISPLAY
1715                                 peer_list->is_miracast_device = g_variant_get_boolean(var);
1716 #endif /* TIZEN_FEATURE_WIFI_DISPLAY */
1717                         } else if (!g_strcmp0(key, "IsP2P")) {
1718                                 peer_list->p2p_supported = g_variant_get_boolean(var);
1719
1720                         } else {
1721                                 ;/* Do Nothing */
1722                         }
1723                 }
1724
1725                 //__wfd_client_print_connected_peer_info(peer_list, 1);
1726                 if (!cb(peer_list, user_data)) {
1727                         g_variant_iter_free(iter_peer);
1728                         break;
1729                 }
1730         }
1731
1732         g_variant_iter_free(iter_peers);
1733         g_variant_unref(reply);
1734         __WDC_LOG_FUNC_END__;
1735         return WIFI_DIRECT_ERROR_NONE;
1736 }
1737
1738
1739 int wifi_direct_create_group(void)
1740 {
1741         __WDC_LOG_FUNC_START__;
1742
1743         CHECK_FEATURE_SUPPORTED(WIFIDIRECT_FEATURE);
1744
1745         GError *error = NULL;
1746         GVariant *reply = NULL;
1747         int ret = WIFI_DIRECT_ERROR_NONE;
1748
1749         if (g_client_info.is_registered == false) {
1750                 WDC_LOGE("Client is NOT registered");
1751                 __WDC_LOG_FUNC_END__;
1752                 return WIFI_DIRECT_ERROR_NOT_INITIALIZED;
1753         }
1754
1755         reply = wifi_direct_dbus_method_call_sync(WFD_MANAGER_GROUP_INTERFACE,
1756                                                   "CreateGroup", NULL, &error);
1757         if (error != NULL) {
1758                 WDC_LOGE("wifi_direct_dbus_method_call_sync() failed."
1759                                 "error [%d: %s]", error->code, error->message);
1760                 g_error_free(error);
1761                 __WDC_LOG_FUNC_END__;
1762                 return WIFI_DIRECT_ERROR_OPERATION_FAILED;
1763         }
1764
1765         g_variant_get(reply, "(i)", &ret);
1766         g_variant_unref(reply);
1767
1768         WDC_LOGD("%s() return : [%d]", __func__, ret);
1769         __WDC_LOG_FUNC_END__;
1770         return ret;
1771 }
1772
1773
1774 int wifi_direct_destroy_group(void)
1775 {
1776         __WDC_LOG_FUNC_START__;
1777
1778         CHECK_FEATURE_SUPPORTED(WIFIDIRECT_FEATURE);
1779
1780         GError *error = NULL;
1781         GVariant *reply = NULL;
1782         int ret = WIFI_DIRECT_ERROR_NONE;
1783
1784         if (g_client_info.is_registered == false) {
1785                 WDC_LOGE("Client is NOT registered");
1786                 __WDC_LOG_FUNC_END__;
1787                 return WIFI_DIRECT_ERROR_NOT_INITIALIZED;
1788         }
1789
1790         reply = wifi_direct_dbus_method_call_sync(WFD_MANAGER_GROUP_INTERFACE,
1791                                                   "DestroyGroup", NULL, &error);
1792         if (error != NULL) {
1793                 WDC_LOGE("wifi_direct_dbus_method_call_sync() failed."
1794                                 "error [%d: %s]", error->code, error->message);
1795                 g_error_free(error);
1796                 __WDC_LOG_FUNC_END__;
1797                 return WIFI_DIRECT_ERROR_OPERATION_FAILED;
1798         }
1799
1800         g_variant_get(reply, "(i)", &ret);
1801         g_variant_unref(reply);
1802
1803         WDC_LOGD("%s() return : [%d]", __func__, ret);
1804         __WDC_LOG_FUNC_END__;
1805         return ret;
1806 }
1807
1808
1809 int wifi_direct_is_group_owner(bool *owner)
1810 {
1811         __WDC_LOG_FUNC_START__;
1812
1813         CHECK_FEATURE_SUPPORTED(WIFIDIRECT_FEATURE);
1814
1815         GError* error = NULL;
1816         GVariant *reply = NULL;
1817         bool val;
1818
1819         if (g_client_info.is_registered == false) {
1820                 WDC_LOGE("Client is NOT registered");
1821                 __WDC_LOG_FUNC_END__;
1822                 return WIFI_DIRECT_ERROR_NOT_INITIALIZED;
1823         }
1824
1825         if (!owner) {
1826                 WDC_LOGE("NULL Param [owner]!");
1827                 __WDC_LOG_FUNC_END__;
1828                 return WIFI_DIRECT_ERROR_INVALID_PARAMETER;
1829         }
1830
1831         reply = wifi_direct_dbus_method_call_sync(WFD_MANAGER_GROUP_INTERFACE,
1832                                           "IsGroupOwner",
1833                                           NULL,
1834                                           &error);
1835         if (error != NULL) {
1836                 WDC_LOGE("wifi_direct_dbus_method_call_sync() failed."
1837                                 "error [%d: %s]", error->code, error->message);
1838                 g_error_free(error);
1839                 __WDC_LOG_FUNC_END__;
1840                 return WIFI_DIRECT_ERROR_OPERATION_FAILED;
1841         }
1842         WDC_LOGD("%s() SUCCESS", __func__);
1843         g_variant_get(reply, "(b)", &val);
1844         *owner = val;
1845         g_variant_unref(reply);
1846
1847         __WDC_LOG_FUNC_END__;
1848         return WIFI_DIRECT_ERROR_NONE;
1849 }
1850
1851 int wifi_direct_is_autonomous_group(bool *autonomous_group)
1852 {
1853         __WDC_LOG_FUNC_START__;
1854
1855         CHECK_FEATURE_SUPPORTED(WIFIDIRECT_FEATURE);
1856
1857         GError* error = NULL;
1858         GVariant *reply = NULL;
1859         bool val;
1860
1861         if (g_client_info.is_registered == false) {
1862                 WDC_LOGE("Client is NOT registered");
1863                 __WDC_LOG_FUNC_END__;
1864                 return WIFI_DIRECT_ERROR_NOT_INITIALIZED;
1865         }
1866
1867         if (!autonomous_group) {
1868                 WDC_LOGE("NULL Param [autonomous_group]!\n");
1869                 __WDC_LOG_FUNC_END__;
1870                 return WIFI_DIRECT_ERROR_INVALID_PARAMETER;
1871         }
1872
1873         reply = wifi_direct_dbus_method_call_sync(WFD_MANAGER_GROUP_INTERFACE,
1874                                           "IsAutoGroup",
1875                                           NULL,
1876                                           &error);
1877         if (error != NULL) {
1878                 WDC_LOGE("wifi_direct_dbus_method_call_sync() failed."
1879                                 "error [%d: %s]", error->code, error->message);
1880                 g_error_free(error);
1881                 __WDC_LOG_FUNC_END__;
1882                 return WIFI_DIRECT_ERROR_OPERATION_FAILED;
1883         }
1884         WDC_LOGD("%s() SUCCESS", __func__);
1885         g_variant_get(reply, "(b)", &val);
1886         *autonomous_group = val;
1887         g_variant_unref(reply);
1888
1889         __WDC_LOG_FUNC_END__;
1890         return WIFI_DIRECT_ERROR_NONE;
1891 }
1892
1893
1894 int wifi_direct_set_group_owner_intent(int intent)
1895 {
1896         __WDC_LOG_FUNC_START__;
1897
1898         CHECK_FEATURE_SUPPORTED(WIFIDIRECT_FEATURE);
1899
1900         GError* error = NULL;
1901         GVariant *reply = NULL;
1902         GVariant *params = NULL;
1903         int ret = WIFI_DIRECT_ERROR_NONE;
1904
1905         if (g_client_info.is_registered == false) {
1906                 WDC_LOGE("Client is NOT registered");
1907                 __WDC_LOG_FUNC_END__;
1908                 return WIFI_DIRECT_ERROR_NOT_INITIALIZED;
1909         }
1910
1911         if (intent < 0 || intent > 15) {
1912                 WDC_LOGE("Invalid Param : intent[%d]", intent);
1913                 __WDC_LOG_FUNC_END__;
1914                 return WIFI_DIRECT_ERROR_INVALID_PARAMETER;
1915         }
1916
1917         params = g_variant_new("(i)", intent);
1918         reply = wifi_direct_dbus_method_call_sync(WFD_MANAGER_CONFIG_INTERFACE,
1919                                           "SetGoIntent",
1920                                           params,
1921                                           &error);
1922         if (error != NULL) {
1923                 WDC_LOGE("wifi_direct_dbus_method_call_sync() failed."
1924                                 "error [%d: %s]", error->code, error->message);
1925                 g_error_free(error);
1926                 __WDC_LOG_FUNC_END__;
1927                 return WIFI_DIRECT_ERROR_OPERATION_FAILED;
1928         }
1929
1930         g_variant_get(reply, "(i)", &ret);
1931         g_variant_unref(reply);
1932
1933         WDC_LOGD("%s() return : [%d]", __func__, ret);
1934         __WDC_LOG_FUNC_END__;
1935         return ret;
1936 }
1937
1938 int wifi_direct_get_group_owner_intent(int *intent)
1939 {
1940         __WDC_LOG_FUNC_START__;
1941
1942         CHECK_FEATURE_SUPPORTED(WIFIDIRECT_FEATURE);
1943
1944         GError* error = NULL;
1945         GVariant *reply = NULL;
1946         int val = 0;
1947         int ret = WIFI_DIRECT_ERROR_NONE;
1948
1949         if (g_client_info.is_registered == false) {
1950                 WDC_LOGE("Client is NOT registered");
1951                 __WDC_LOG_FUNC_END__;
1952                 return WIFI_DIRECT_ERROR_NOT_INITIALIZED;
1953         }
1954
1955         if (!intent) {
1956                 WDC_LOGE("Invalid Parameter");
1957                 __WDC_LOG_FUNC_END__;
1958                 return WIFI_DIRECT_ERROR_INVALID_PARAMETER;
1959         }
1960
1961         reply = wifi_direct_dbus_method_call_sync(WFD_MANAGER_CONFIG_INTERFACE,
1962                                           "GetGoIntent",
1963                                           NULL,
1964                                           &error);
1965         if (error != NULL) {
1966                 WDC_LOGE("wifi_direct_dbus_method_call_sync() failed."
1967                                 "error [%d: %s]", error->code, error->message);
1968                 g_error_free(error);
1969                 __WDC_LOG_FUNC_END__;
1970                 return WIFI_DIRECT_ERROR_OPERATION_FAILED;
1971         }
1972
1973         g_variant_get(reply, "(ii)", &ret, &val);
1974         *intent = val;
1975         g_variant_unref(reply);
1976
1977         WDC_LOGD("Intent = [%d]", *intent);
1978         WDC_LOGD("%s() return : [%d]", __func__, ret);
1979         __WDC_LOG_FUNC_END__;
1980         return ret;
1981 }
1982
1983 int wifi_direct_set_max_clients(int max)
1984 {
1985         __WDC_LOG_FUNC_START__;
1986
1987         CHECK_FEATURE_SUPPORTED(WIFIDIRECT_FEATURE);
1988
1989         GError* error = NULL;
1990         GVariant *reply = NULL;
1991         GVariant *params = NULL;
1992         int ret = WIFI_DIRECT_ERROR_NONE;
1993
1994         if (g_client_info.is_registered == false) {
1995                 WDC_LOGE("Client is NOT registered");
1996                 __WDC_LOG_FUNC_END__;
1997                 return WIFI_DIRECT_ERROR_NOT_INITIALIZED;
1998         }
1999         WDC_LOGD("max client [%d]\n", max);
2000
2001         params = g_variant_new("(i)", max);
2002         reply = wifi_direct_dbus_method_call_sync(WFD_MANAGER_CONFIG_INTERFACE,
2003                                           "SetMaxClient",
2004                                           params,
2005                                           &error);
2006         if (error != NULL) {
2007                 WDC_LOGE("wifi_direct_dbus_method_call_sync() failed."
2008                                 "error [%d: %s]", error->code, error->message);
2009                 g_error_free(error);
2010                 __WDC_LOG_FUNC_END__;
2011                 return WIFI_DIRECT_ERROR_OPERATION_FAILED;
2012         }
2013
2014         g_variant_get(reply, "(i)", &ret);
2015         g_variant_unref(reply);
2016
2017         WDC_LOGD("%s() return : [%d]", __func__, ret);
2018         __WDC_LOG_FUNC_END__;
2019         return ret;
2020 }
2021
2022 int wifi_direct_get_max_clients(int *max)
2023 {
2024         __WDC_LOG_FUNC_START__;
2025
2026         CHECK_FEATURE_SUPPORTED(WIFIDIRECT_FEATURE);
2027
2028         GError* error = NULL;
2029         GVariant *reply = NULL;
2030         int val = 0;
2031         int ret = WIFI_DIRECT_ERROR_NONE;
2032
2033         if (g_client_info.is_registered == false) {
2034                 WDC_LOGE("Client is NOT registered");
2035                 __WDC_LOG_FUNC_END__;
2036                 return WIFI_DIRECT_ERROR_NOT_INITIALIZED;
2037         }
2038
2039         if (!max) {
2040                 WDC_LOGE("Invalid Parameter");
2041                 __WDC_LOG_FUNC_END__;
2042                 return WIFI_DIRECT_ERROR_INVALID_PARAMETER;
2043         }
2044
2045         reply = wifi_direct_dbus_method_call_sync(WFD_MANAGER_CONFIG_INTERFACE,
2046                                           "GetMaxClient",
2047                                           NULL,
2048                                           &error);
2049         if (error != NULL) {
2050                 WDC_LOGE("wifi_direct_dbus_method_call_sync() failed."
2051                                 "error [%d: %s]", error->code, error->message);
2052                 g_error_free(error);
2053                 __WDC_LOG_FUNC_END__;
2054                 return WIFI_DIRECT_ERROR_OPERATION_FAILED;
2055         }
2056
2057         g_variant_get(reply, "(ii)", &ret, &val);
2058         *max = val;
2059         g_variant_unref(reply);
2060
2061         WDC_LOGD("max_client = [%d]", *max);
2062         WDC_LOGD("%s() return : [%d]", __func__, ret);
2063         __WDC_LOG_FUNC_END__;
2064         return WIFI_DIRECT_ERROR_NONE;
2065 }
2066
2067 int wifi_direct_get_operating_channel(int *channel)
2068 {
2069         __WDC_LOG_FUNC_START__;
2070
2071         CHECK_FEATURE_SUPPORTED(WIFIDIRECT_FEATURE);
2072
2073         GError* error = NULL;
2074         GVariant *reply = NULL;
2075         int val = 0;
2076         int ret = WIFI_DIRECT_ERROR_NONE;
2077
2078         if (g_client_info.is_registered == false) {
2079                 WDC_LOGE("Client is NOT registered");
2080                 __WDC_LOG_FUNC_END__;
2081                 return WIFI_DIRECT_ERROR_NOT_INITIALIZED;
2082         }
2083
2084         if (!channel) {
2085                 WDC_LOGE("NULL Param [channel]!\n");
2086                 __WDC_LOG_FUNC_END__;
2087                 return WIFI_DIRECT_ERROR_INVALID_PARAMETER;
2088         }
2089
2090         reply = wifi_direct_dbus_method_call_sync(WFD_MANAGER_CONFIG_INTERFACE,
2091                                           "GetOperatingChannel",
2092                                           NULL,
2093                                           &error);
2094         if (error != NULL) {
2095                 WDC_LOGE("wifi_direct_dbus_method_call_sync() failed."
2096                                 "error [%d: %s]", error->code, error->message);
2097                 g_error_free(error);
2098                 __WDC_LOG_FUNC_END__;
2099                 return WIFI_DIRECT_ERROR_OPERATION_FAILED;
2100         }
2101
2102         g_variant_get(reply, "(ii)", &ret, &val);
2103         *channel = val;
2104         g_variant_unref(reply);
2105
2106         WDC_LOGD("channel = [%d]", *channel);
2107         WDC_LOGD("%s() return : [%d]", __func__, ret);
2108         __WDC_LOG_FUNC_END__;
2109         return WIFI_DIRECT_ERROR_NONE;
2110 }
2111
2112 int wifi_direct_activate_pushbutton(void)
2113 {
2114         __WDC_LOG_FUNC_START__;
2115
2116         CHECK_FEATURE_SUPPORTED(WIFIDIRECT_FEATURE);
2117
2118         GError* error = NULL;
2119         GVariant *reply = NULL;
2120         int ret = WIFI_DIRECT_ERROR_NONE;
2121
2122         if (g_client_info.is_registered == false) {
2123                 WDC_LOGE("Client is NOT registered");
2124                 __WDC_LOG_FUNC_END__;
2125                 return WIFI_DIRECT_ERROR_NOT_INITIALIZED;
2126         }
2127
2128         reply = wifi_direct_dbus_method_call_sync(WFD_MANAGER_GROUP_INTERFACE,
2129                                           "ActivatePushButton",
2130                                           NULL,
2131                                           &error);
2132         if (error != NULL) {
2133                 WDC_LOGE("wifi_direct_dbus_method_call_sync() failed."
2134                                 "error [%d: %s]", error->code, error->message);
2135                 g_error_free(error);
2136                 __WDC_LOG_FUNC_END__;
2137                 return WIFI_DIRECT_ERROR_OPERATION_FAILED;
2138         }
2139         WDC_LOGD("%s() SUCCESS", __func__);
2140
2141         g_variant_get(reply, "(i)", &ret);
2142         g_variant_unref(reply);
2143
2144         WDC_LOGD("%s() return : [%d]", __func__, ret);
2145         __WDC_LOG_FUNC_END__;
2146         return ret;
2147 }
2148
2149 int wifi_direct_set_wps_pin(char *pin)
2150 {
2151         __WDC_LOG_FUNC_START__;
2152
2153         CHECK_FEATURE_SUPPORTED(WIFIDIRECT_FEATURE);
2154
2155         GError* error = NULL;
2156         GVariant *reply = NULL;
2157         GVariant *params = NULL;
2158         int ret = WIFI_DIRECT_ERROR_NONE;
2159
2160         if (g_client_info.is_registered == false) {
2161                 WDC_LOGE("Client is NOT registered");
2162                 __WDC_LOG_FUNC_END__;
2163                 return WIFI_DIRECT_ERROR_NOT_INITIALIZED;
2164         }
2165
2166         if (!pin) {
2167                 WDC_LOGE("NULL Param [pin]!");
2168                 __WDC_LOG_FUNC_END__;
2169                 return WIFI_DIRECT_ERROR_INVALID_PARAMETER;
2170         }
2171         WDC_LOGE("pin = [%s]\n", pin);
2172
2173         params = g_variant_new("(s)", pin);
2174         reply = wifi_direct_dbus_method_call_sync(WFD_MANAGER_CONFIG_INTERFACE,
2175                                           "SetWpsPin",
2176                                           params,
2177                                           &error);
2178         if (error != NULL) {
2179                 WDC_LOGE("wifi_direct_dbus_method_call_sync() failed."
2180                                 "error [%d: %s]", error->code, error->message);
2181                 g_error_free(error);
2182                 __WDC_LOG_FUNC_END__;
2183                 return WIFI_DIRECT_ERROR_OPERATION_FAILED;
2184         }
2185
2186         g_variant_get(reply, "(i)", &ret);
2187         g_variant_unref(reply);
2188
2189         WDC_LOGD("%s() return : [%d]", __func__, ret);
2190         __WDC_LOG_FUNC_END__;
2191         return ret;
2192 }
2193
2194
2195 int wifi_direct_get_wps_pin(char **pin)
2196 {
2197         __WDC_LOG_FUNC_START__;
2198
2199         CHECK_FEATURE_SUPPORTED(WIFIDIRECT_FEATURE);
2200
2201         GError* error = NULL;
2202         GVariant *reply = NULL;
2203         const char *str = NULL;
2204         int ret = WIFI_DIRECT_ERROR_NONE;
2205
2206         if (g_client_info.is_registered == false) {
2207                 WDC_LOGE("Client is NOT registered");
2208                 __WDC_LOG_FUNC_END__;
2209                 return WIFI_DIRECT_ERROR_NOT_INITIALIZED;
2210         }
2211
2212         reply = wifi_direct_dbus_method_call_sync(WFD_MANAGER_CONFIG_INTERFACE,
2213                                           "GetWpsPin",
2214                                           NULL,
2215                                           &error);
2216         if (error != NULL) {
2217                 WDC_LOGE("wifi_direct_dbus_method_call_sync() failed."
2218                                 "error [%d: %s]", error->code, error->message);
2219                 g_error_free(error);
2220                 __WDC_LOG_FUNC_END__;
2221                 return WIFI_DIRECT_ERROR_OPERATION_FAILED;
2222         }
2223
2224         g_variant_get(reply, "(i&s)", &ret, &str);
2225         if(pin != NULL && str != NULL)
2226                 *pin = g_strdup(str);
2227         g_variant_unref(reply);
2228
2229         WDC_LOGD("%s() return : [%d]", __func__, ret);
2230         __WDC_LOG_FUNC_END__;
2231         return ret;
2232 }
2233
2234 int wifi_direct_get_supported_wps_mode(int *wps_mode)
2235 {
2236         __WDC_LOG_FUNC_START__;
2237
2238         CHECK_FEATURE_SUPPORTED(WIFIDIRECT_FEATURE);
2239
2240         GError* error = NULL;
2241         GVariant *reply = NULL;
2242         int mode = 0;
2243         int ret = WIFI_DIRECT_ERROR_NONE;
2244
2245         if (g_client_info.is_registered == false) {
2246                 WDC_LOGE("Client is NOT registered");
2247                 __WDC_LOG_FUNC_END__;
2248                 return WIFI_DIRECT_ERROR_NOT_INITIALIZED;
2249         }
2250
2251         if (!wps_mode) {
2252                 WDC_LOGE("NULL Param [wps_mode]!");
2253                 __WDC_LOG_FUNC_END__;
2254                 return WIFI_DIRECT_ERROR_INVALID_PARAMETER;
2255         }
2256
2257         reply = wifi_direct_dbus_method_call_sync(WFD_MANAGER_CONFIG_INTERFACE,
2258                                           "GetSupportedWpsMode",
2259                                           NULL,
2260                                           &error);
2261         if (error != NULL) {
2262                 WDC_LOGE("wifi_direct_dbus_method_call_sync() failed."
2263                                 "error [%d: %s]", error->code, error->message);
2264                 g_error_free(error);
2265                 __WDC_LOG_FUNC_END__;
2266                 return WIFI_DIRECT_ERROR_OPERATION_FAILED;
2267         }
2268
2269         g_variant_get(reply, "(ii)", &ret, &mode);
2270         *wps_mode = mode;
2271         g_variant_unref(reply);
2272
2273         WDC_LOGD("%s() return : [%d]", __func__, ret);
2274         __WDC_LOG_FUNC_END__;
2275         return ret;
2276 }
2277
2278 int wifi_direct_foreach_supported_wps_types(wifi_direct_supported_wps_type_cb cb, void* user_data)
2279 {
2280         __WDC_LOG_FUNC_START__;
2281
2282         CHECK_FEATURE_SUPPORTED(WIFIDIRECT_FEATURE);
2283
2284         GError* error = NULL;
2285         GVariant *reply = NULL;
2286         int wps_mode = 0;
2287         int ret = WIFI_DIRECT_ERROR_NONE;
2288         gboolean result = FALSE;
2289
2290         if (g_client_info.is_registered == false) {
2291                 WDC_LOGE("Client is NOT registered");
2292                 __WDC_LOG_FUNC_END__;
2293                 return WIFI_DIRECT_ERROR_NOT_INITIALIZED;
2294         }
2295
2296         if (!cb) {
2297                 WDC_LOGE("NULL Param [callback]!");
2298                 __WDC_LOG_FUNC_END__;
2299                 return WIFI_DIRECT_ERROR_INVALID_PARAMETER;
2300         }
2301
2302         reply = wifi_direct_dbus_method_call_sync(WFD_MANAGER_CONFIG_INTERFACE,
2303                                           "GetSupportedWpsMode",
2304                                           NULL,
2305                                           &error);
2306         if (error != NULL) {
2307                 WDC_LOGE("wifi_direct_dbus_method_call_sync() failed."
2308                                 "error [%d: %s]", error->code, error->message);
2309                 g_error_free(error);
2310                 __WDC_LOG_FUNC_END__;
2311                 return WIFI_DIRECT_ERROR_OPERATION_FAILED;
2312         }
2313
2314         g_variant_get(reply, "(ii)", &ret, &wps_mode);
2315         g_variant_unref(reply);
2316
2317         if (wps_mode & WIFI_DIRECT_WPS_TYPE_PBC)
2318                 result = cb(WIFI_DIRECT_WPS_TYPE_PBC, user_data);
2319         if ((result == TRUE) && (wps_mode & WIFI_DIRECT_WPS_TYPE_PIN_DISPLAY))
2320                 result = cb(WIFI_DIRECT_WPS_TYPE_PIN_DISPLAY, user_data);
2321         if ((result == TRUE) && (wps_mode & WIFI_DIRECT_WPS_TYPE_PIN_KEYPAD))
2322                 result = cb(WIFI_DIRECT_WPS_TYPE_PIN_KEYPAD, user_data);
2323
2324         WDC_LOGD("%s() return : [%d]", __func__, ret);
2325         __WDC_LOG_FUNC_END__;
2326         return ret;
2327 }
2328
2329 int wifi_direct_get_local_wps_type(wifi_direct_wps_type_e *type)
2330 {
2331         __WDC_LOG_FUNC_START__;
2332
2333         CHECK_FEATURE_SUPPORTED(WIFIDIRECT_FEATURE);
2334
2335         GError* error = NULL;
2336         GVariant *reply = NULL;
2337         int mode = 0;
2338         int ret = WIFI_DIRECT_ERROR_NONE;
2339
2340         if (g_client_info.is_registered == false) {
2341                 WDC_LOGE("Client is NOT registered");
2342                 __WDC_LOG_FUNC_END__;
2343                 return WIFI_DIRECT_ERROR_NOT_INITIALIZED;
2344         }
2345
2346         if (type == NULL) {
2347                 WDC_LOGE("NULL Param [type]!\n");
2348                 __WDC_LOG_FUNC_END__;
2349                 return WIFI_DIRECT_ERROR_INVALID_PARAMETER;
2350         }
2351
2352         reply = wifi_direct_dbus_method_call_sync(WFD_MANAGER_CONFIG_INTERFACE,
2353                                           "GetLocalWpsMode",
2354                                           NULL,
2355                                           &error);
2356         if (error != NULL) {
2357                 WDC_LOGE("wifi_direct_dbus_method_call_sync() failed."
2358                                 "error [%d: %s]", error->code, error->message);
2359                 g_error_free(error);
2360                 __WDC_LOG_FUNC_END__;
2361                 return WIFI_DIRECT_ERROR_OPERATION_FAILED;
2362         }
2363
2364         g_variant_get(reply, "(ii)", &ret, &mode);
2365         *type = mode;
2366         g_variant_unref(reply);
2367
2368         WDC_LOGD("%s() return : [%d]", __func__, ret);
2369         __WDC_LOG_FUNC_END__;
2370         return ret;
2371 }
2372
2373 int wifi_direct_set_req_wps_type(wifi_direct_wps_type_e type)
2374 {
2375         __WDC_LOG_FUNC_START__;
2376
2377         CHECK_FEATURE_SUPPORTED(WIFIDIRECT_FEATURE);
2378
2379         GError* error = NULL;
2380         GVariant *reply = NULL;
2381         GVariant *params = NULL;
2382         int ret = WIFI_DIRECT_ERROR_NONE;
2383
2384         if (g_client_info.is_registered == false) {
2385                 WDC_LOGE("Client is NOT registered");
2386                 __WDC_LOG_FUNC_END__;
2387                 return WIFI_DIRECT_ERROR_NOT_INITIALIZED;
2388         }
2389
2390         if (type == WIFI_DIRECT_WPS_TYPE_PBC ||
2391                         type == WIFI_DIRECT_WPS_TYPE_PIN_DISPLAY ||
2392                         type == WIFI_DIRECT_WPS_TYPE_PIN_KEYPAD) {
2393                 WDC_LOGD("Param wps_mode [%d]", type);
2394         } else {
2395                 WDC_LOGE("Invalid Param [wps_mode]!");
2396                 __WDC_LOG_FUNC_END__;
2397                 return WIFI_DIRECT_ERROR_INVALID_PARAMETER;
2398         }
2399
2400         params = g_variant_new("(i)", type);
2401         reply = wifi_direct_dbus_method_call_sync(WFD_MANAGER_CONFIG_INTERFACE,
2402                                           "SetReqWpsMode",
2403                                           params,
2404                                           &error);
2405         if (error != NULL) {
2406                 WDC_LOGE("wifi_direct_dbus_method_call_sync() failed."
2407                                 "error [%d: %s]", error->code, error->message);
2408                 g_error_free(error);
2409                 __WDC_LOG_FUNC_END__;
2410                 return WIFI_DIRECT_ERROR_OPERATION_FAILED;
2411         }
2412
2413         g_variant_get(reply, "(i)", &ret);
2414         g_variant_unref(reply);
2415
2416         WDC_LOGD("%s() return : [%d]", __func__, ret);
2417         __WDC_LOG_FUNC_END__;
2418         return ret;
2419 }
2420
2421 int wifi_direct_get_req_wps_type(wifi_direct_wps_type_e *type)
2422 {
2423         __WDC_LOG_FUNC_START__;
2424
2425         CHECK_FEATURE_SUPPORTED(WIFIDIRECT_FEATURE);
2426
2427         GError* error = NULL;
2428         GVariant *reply = NULL;
2429         int mode = 0;
2430         int ret = 0;
2431
2432         if (g_client_info.is_registered == false) {
2433                 WDC_LOGE("Client is NOT registered");
2434                 __WDC_LOG_FUNC_END__;
2435                 return WIFI_DIRECT_ERROR_NOT_INITIALIZED;
2436         }
2437
2438         if (!type) {
2439                 WDC_LOGE("NULL Param [type]!\n");
2440                 __WDC_LOG_FUNC_END__;
2441                 return WIFI_DIRECT_ERROR_INVALID_PARAMETER;
2442         }
2443
2444         reply = wifi_direct_dbus_method_call_sync(WFD_MANAGER_CONFIG_INTERFACE,
2445                                           "GetReqWpsMode",
2446                                           NULL,
2447                                           &error);
2448         if (error != NULL) {
2449                 WDC_LOGE("wifi_direct_dbus_method_call_sync() failed."
2450                                 "error [%d: %s]", error->code, error->message);
2451                 g_error_free(error);
2452                 __WDC_LOG_FUNC_END__;
2453                 return WIFI_DIRECT_ERROR_OPERATION_FAILED;
2454         }
2455
2456         g_variant_get(reply, "(ii)", &ret, &mode);
2457         *type = mode;
2458         g_variant_unref(reply);
2459
2460         WDC_LOGD("%s() return : [%d]", __func__, ret);
2461         __WDC_LOG_FUNC_END__;
2462         return ret;
2463 }
2464
2465 int wifi_direct_get_ssid(char **ssid)
2466 {
2467         __WDC_LOG_FUNC_START__;
2468
2469         CHECK_FEATURE_SUPPORTED(WIFIDIRECT_FEATURE);
2470
2471         GError* error = NULL;
2472         GVariant *reply = NULL;
2473         const char *str = NULL;
2474         int ret = WIFI_DIRECT_ERROR_NONE;
2475
2476         if (g_client_info.is_registered == false) {
2477                 WDC_LOGE("Client is NOT registered");
2478                 __WDC_LOG_FUNC_END__;
2479                 return WIFI_DIRECT_ERROR_NOT_INITIALIZED;
2480         }
2481
2482         if (!ssid) {
2483                 WDC_LOGE("Invalid Parameter");
2484                 __WDC_LOG_FUNC_END__;
2485                 return WIFI_DIRECT_ERROR_INVALID_PARAMETER;
2486         }
2487
2488         reply = wifi_direct_dbus_method_call_sync(WFD_MANAGER_CONFIG_INTERFACE,
2489                                           "GetDeviceName",
2490                                           NULL,
2491                                           &error);
2492         if (error != NULL) {
2493                 WDC_LOGE("wifi_direct_dbus_method_call_sync() failed."
2494                                 "error [%d: %s]", error->code, error->message);
2495                 g_error_free(error);
2496                 __WDC_LOG_FUNC_END__;
2497                 return WIFI_DIRECT_ERROR_OPERATION_FAILED;
2498         }
2499
2500         g_variant_get(reply, "(i&s)", &ret, &str);
2501         *ssid = g_strdup(str);
2502         g_variant_unref(reply);
2503
2504         WDC_LOGD("%s() return : [%d]", __func__, ret);
2505         __WDC_LOG_FUNC_END__;
2506         return ret;
2507 }
2508
2509 int wifi_direct_get_device_name(char **device_name)
2510 {
2511         __WDC_LOG_FUNC_START__;
2512
2513         CHECK_FEATURE_SUPPORTED(WIFIDIRECT_FEATURE);
2514
2515         GError* error = NULL;
2516         GVariant *reply = NULL;
2517         const char *str = NULL;
2518         int ret = WIFI_DIRECT_ERROR_NONE;
2519
2520         if (g_client_info.is_registered == false) {
2521                 WDC_LOGE("Client is NOT registered");
2522                 __WDC_LOG_FUNC_END__;
2523                 return WIFI_DIRECT_ERROR_NOT_INITIALIZED;
2524         }
2525
2526         if (!device_name) {
2527                 WDC_LOGE("Invalid Parameter");
2528                 __WDC_LOG_FUNC_END__;
2529                 return WIFI_DIRECT_ERROR_INVALID_PARAMETER;
2530         }
2531
2532         reply = wifi_direct_dbus_method_call_sync(WFD_MANAGER_CONFIG_INTERFACE,
2533                                           "GetDeviceName",
2534                                           NULL,
2535                                           &error);
2536         if (error != NULL) {
2537                 WDC_LOGE("wifi_direct_dbus_method_call_sync() failed."
2538                                 "error [%d: %s]", error->code, error->message);
2539                 g_error_free(error);
2540                 __WDC_LOG_FUNC_END__;
2541                 return WIFI_DIRECT_ERROR_OPERATION_FAILED;
2542         }
2543
2544         g_variant_get(reply, "(i&s)", &ret, &str);
2545         *device_name = g_strdup(str);
2546         g_variant_unref(reply);
2547
2548         WDC_LOGD("%s() return : [%d]", __func__, ret);
2549         __WDC_LOG_FUNC_END__;
2550         return ret;
2551 }
2552
2553 int wifi_direct_set_device_name(const char *device_name)
2554 {
2555         __WDC_LOG_FUNC_START__;
2556
2557         CHECK_FEATURE_SUPPORTED(WIFIDIRECT_FEATURE);
2558
2559         GError* error = NULL;
2560         GVariant *reply = NULL;
2561         GVariant *params = NULL;
2562         int ret = WIFI_DIRECT_ERROR_NONE;
2563
2564         if (g_client_info.is_registered == false) {
2565                 WDC_LOGE("Client is NOT registered");
2566                 __WDC_LOG_FUNC_END__;
2567                 return WIFI_DIRECT_ERROR_NOT_INITIALIZED;
2568         }
2569
2570         if (!device_name) {
2571                 WDC_LOGE("NULL Param [device_name]!");
2572                 __WDC_LOG_FUNC_END__;
2573                 return WIFI_DIRECT_ERROR_INVALID_PARAMETER;
2574         }
2575         WDC_LOGE("device_name = [%s]", device_name);
2576
2577         params = g_variant_new("(s)", device_name);
2578         reply = wifi_direct_dbus_method_call_sync(WFD_MANAGER_CONFIG_INTERFACE,
2579                                           "SetDeviceName",
2580                                           params,
2581                                           &error);
2582         if (error != NULL) {
2583                 WDC_LOGE("wifi_direct_dbus_method_call_sync() failed."
2584                                 "error [%d: %s]", error->code, error->message);
2585                 g_error_free(error);
2586                 __WDC_LOG_FUNC_END__;
2587                 return WIFI_DIRECT_ERROR_OPERATION_FAILED;
2588         }
2589
2590         g_variant_get(reply, "(i)", &ret);
2591         g_variant_unref(reply);
2592
2593         WDC_LOGD("%s() return : [%d]", __func__, ret);
2594         __WDC_LOG_FUNC_END__;
2595         return ret;
2596 }
2597
2598 int wifi_direct_get_network_interface_name(char **name)
2599 {
2600         __WDC_LOG_FUNC_START__;
2601
2602         CHECK_FEATURE_SUPPORTED(WIFIDIRECT_FEATURE);
2603
2604         wifi_direct_state_e status = 0;
2605         char *get_str = NULL;
2606         GError* error = NULL;
2607         GVariant *reply = NULL;
2608         int ret = WIFI_DIRECT_ERROR_NONE;
2609
2610         if (g_client_info.is_registered == false) {
2611                 WDC_LOGE("Client is NOT registered");
2612                 __WDC_LOG_FUNC_END__;
2613                 return WIFI_DIRECT_ERROR_NOT_INITIALIZED;
2614         }
2615
2616         if (!name) {
2617                 WDC_LOGE("NULL Param [name]!\n");
2618                 __WDC_LOG_FUNC_END__;
2619                 return WIFI_DIRECT_ERROR_INVALID_PARAMETER;
2620         }
2621
2622         ret = wifi_direct_get_state(&status);
2623         WDC_LOGD("wifi_direct_get_state() state=[%d], ret=[%d]\n", status, ret);
2624
2625         if (status < WIFI_DIRECT_STATE_CONNECTED) {
2626                 WDC_LOGE("Device is not connected!\n");
2627                 __WDC_LOG_FUNC_END__;
2628                 return WIFI_DIRECT_ERROR_NOT_PERMITTED;
2629         }
2630
2631         reply = wifi_direct_dbus_method_call_sync(WFD_MANAGER_CONFIG_INTERFACE,
2632                                                   "GetInterfaceName",
2633                                                   NULL,
2634                                                   &error);
2635         if (error != NULL) {
2636                 WDC_LOGE("wifi_direct_dbus_method_call_sync() failed."
2637                                 "error [%d: %s]", error->code, error->message);
2638                 g_error_free(error);
2639                 __WDC_LOG_FUNC_END__;
2640                 return WIFI_DIRECT_ERROR_OPERATION_FAILED;
2641         }
2642
2643         g_variant_get(reply, "(i&s)", ret ,&get_str);
2644         *name = g_strdup(get_str);
2645         g_variant_unref(reply);
2646
2647         WDC_LOGD("Interface Name = [%s]", *name);
2648         WDC_LOGD("%s() return : [%d]", __func__, ret);
2649
2650         __WDC_LOG_FUNC_END__;
2651         return WIFI_DIRECT_ERROR_NONE;
2652 }
2653
2654 int wifi_direct_get_ip_address(char **ip_address)
2655 {
2656         __WDC_LOG_FUNC_START__;
2657
2658         CHECK_FEATURE_SUPPORTED(WIFIDIRECT_FEATURE);
2659
2660         GError* error = NULL;
2661         GVariant *reply = NULL;
2662         const char *str = NULL;
2663         int ret = WIFI_DIRECT_ERROR_NONE;
2664
2665         if (g_client_info.is_registered == false) {
2666                 WDC_LOGE("Client is NOT registered");
2667                 __WDC_LOG_FUNC_END__;
2668                 return WIFI_DIRECT_ERROR_NOT_INITIALIZED;
2669         }
2670
2671         if (!ip_address) {
2672                 WDC_LOGE("NULL Param [ip_address]!\n");
2673                 __WDC_LOG_FUNC_END__;
2674                 return WIFI_DIRECT_ERROR_INVALID_PARAMETER;
2675         }
2676
2677         reply = wifi_direct_dbus_method_call_sync(WFD_MANAGER_CONFIG_INTERFACE,
2678                                                   "GetIPAddress",
2679                                                   NULL,
2680                                                   &error);
2681         if (error != NULL) {
2682                 WDC_LOGE("wifi_direct_dbus_method_call_sync() failed."
2683                                 "error [%d: %s]", error->code, error->message);
2684                 g_error_free(error);
2685                 __WDC_LOG_FUNC_END__;
2686                 return WIFI_DIRECT_ERROR_OPERATION_FAILED;
2687         }
2688
2689         g_variant_get(reply, "(i&s)", ret ,&str);
2690         *ip_address = g_strdup(str);
2691         g_variant_unref(reply);
2692
2693         WDC_LOGD("IP address = [%s]", *ip_address);
2694         WDC_LOGD("%s() return : [%d]", __func__, ret);
2695         __WDC_LOG_FUNC_END__;
2696         return ret;
2697 }
2698
2699 int wifi_direct_get_subnet_mask(char **subnet_mask)
2700 {
2701         __WDC_LOG_FUNC_START__;
2702
2703         CHECK_FEATURE_SUPPORTED(WIFIDIRECT_FEATURE);
2704
2705         wifi_direct_state_e status = 0;
2706         GError* error = NULL;
2707         GVariant *reply = NULL;
2708         char *get_str = NULL;
2709         int ret = WIFI_DIRECT_ERROR_NONE;
2710
2711         if (g_client_info.is_registered == false) {
2712                 WDC_LOGE("Client is NOT registered");
2713                 __WDC_LOG_FUNC_END__;
2714                 return WIFI_DIRECT_ERROR_NOT_INITIALIZED;
2715         }
2716
2717         if (!subnet_mask) {
2718                 WDC_LOGE("NULL Param [subnet_mask]!");
2719                 __WDC_LOG_FUNC_END__;
2720                 return WIFI_DIRECT_ERROR_INVALID_PARAMETER;
2721         }
2722
2723         ret = wifi_direct_get_state(&status);
2724         WDC_LOGD("wifi_direct_get_state() state=[%d], ret=[%d]", status, ret);
2725         if( status < WIFI_DIRECT_STATE_CONNECTED) {
2726                 WDC_LOGE("Device is not connected!");
2727                 __WDC_LOG_FUNC_END__;
2728                 return WIFI_DIRECT_ERROR_NOT_PERMITTED;
2729         }
2730
2731         reply = wifi_direct_dbus_method_call_sync(WFD_MANAGER_CONFIG_INTERFACE,
2732                                                   "GetSubnetMask",
2733                                                   NULL,
2734                                                   &error);
2735         if (error != NULL) {
2736                 WDC_LOGE("wifi_direct_dbus_method_call_sync() failed."
2737                                 "error [%d: %s]", error->code, error->message);
2738                 g_error_free(error);
2739                 __WDC_LOG_FUNC_END__;
2740                 return WIFI_DIRECT_ERROR_OPERATION_FAILED;
2741         }
2742
2743         g_variant_get(reply, "(i&s)", ret ,&get_str);
2744         *subnet_mask = g_strdup(get_str);
2745         g_variant_unref(reply);
2746
2747         WDC_LOGD("Subnet Mask = [%s]", *subnet_mask);
2748         WDC_LOGD("%s() return : [%d]", __func__, ret);
2749
2750         __WDC_LOG_FUNC_END__;
2751         return WIFI_DIRECT_ERROR_NONE;
2752 }
2753
2754 int wifi_direct_get_gateway_address(char **gateway_address)
2755 {
2756         __WDC_LOG_FUNC_START__;
2757
2758         CHECK_FEATURE_SUPPORTED(WIFIDIRECT_FEATURE);
2759
2760         wifi_direct_state_e status = 0;
2761         GError* error = NULL;
2762         GVariant *reply = NULL;
2763         char *get_str = NULL;
2764         int ret = WIFI_DIRECT_ERROR_NONE;
2765
2766         if (g_client_info.is_registered == false) {
2767                 WDC_LOGE("Client is NOT registered");
2768                 __WDC_LOG_FUNC_END__;
2769                 return WIFI_DIRECT_ERROR_NOT_INITIALIZED;
2770         }
2771
2772         if (!gateway_address) {
2773                 WDC_LOGE("NULL Param [gateway_address]!");
2774                 __WDC_LOG_FUNC_END__;
2775                 return WIFI_DIRECT_ERROR_INVALID_PARAMETER;
2776         }
2777
2778         ret = wifi_direct_get_state(&status);
2779         WDC_LOGD("wifi_direct_get_state() state=[%d], ret=[%d]", status, ret);
2780         if(status < WIFI_DIRECT_STATE_CONNECTED) {
2781                 WDC_LOGE("Device is not connected!");
2782                 __WDC_LOG_FUNC_END__;
2783                 return WIFI_DIRECT_ERROR_NOT_PERMITTED;
2784         }
2785
2786         reply = wifi_direct_dbus_method_call_sync(WFD_MANAGER_CONFIG_INTERFACE,
2787                                                   "GetGateway",
2788                                                   NULL,
2789                                                   &error);
2790         if (error != NULL) {
2791                 WDC_LOGE("wifi_direct_dbus_method_call_sync() failed."
2792                                 "error [%d: %s]", error->code, error->message);
2793                 g_error_free(error);
2794                 __WDC_LOG_FUNC_END__;
2795                 return WIFI_DIRECT_ERROR_OPERATION_FAILED;
2796         }
2797
2798         g_variant_get(reply, "(i&s)", ret ,&get_str);
2799         *gateway_address = g_strdup(get_str);
2800         g_variant_unref(reply);
2801
2802         WDC_LOGD("Gateway Address = [%s]", *gateway_address);
2803         WDC_LOGD("%s() return : [%d]", __func__, ret);
2804
2805         __WDC_LOG_FUNC_END__;
2806         return WIFI_DIRECT_ERROR_NONE;
2807 }
2808
2809 int wifi_direct_get_mac_address(char **mac_address)
2810 {
2811         __WDC_LOG_FUNC_START__;
2812
2813         CHECK_FEATURE_SUPPORTED(WIFIDIRECT_FEATURE);
2814
2815         GError* error = NULL;
2816         GVariant *reply = NULL;
2817         const char *str = NULL;
2818         int ret = WIFI_DIRECT_ERROR_NONE;
2819
2820         if (g_client_info.is_registered == false) {
2821                 WDC_LOGE("Client is NOT registered");
2822                 __WDC_LOG_FUNC_END__;
2823                 return WIFI_DIRECT_ERROR_NOT_INITIALIZED;
2824         }
2825
2826         if (!mac_address) {
2827                 WDC_LOGE("NULL Param [mac_address]!");
2828                 __WDC_LOG_FUNC_END__;
2829                 return WIFI_DIRECT_ERROR_INVALID_PARAMETER;
2830         }
2831
2832         reply = wifi_direct_dbus_method_call_sync(WFD_MANAGER_CONFIG_INTERFACE,
2833                                           "GetMacAddress",
2834                                           NULL,
2835                                           &error);
2836         if (error != NULL) {
2837                 WDC_LOGE("wifi_direct_dbus_method_call_sync() failed."
2838                                 "error [%d: %s]", error->code, error->message);
2839                 g_error_free(error);
2840                 __WDC_LOG_FUNC_END__;
2841                 return WIFI_DIRECT_ERROR_OPERATION_FAILED;
2842         }
2843
2844         g_variant_get(reply, "(i&s)", &ret, &str);
2845         *mac_address = g_strdup(str);
2846         g_variant_unref(reply);
2847
2848         WDC_SECLOGD("MAC address = [%s]", *mac_address);
2849         WDC_LOGD("%s() return : [%d]", __func__, ret);
2850         __WDC_LOG_FUNC_END__;
2851         return ret;
2852 }
2853
2854
2855 int wifi_direct_get_state(wifi_direct_state_e *state)
2856 {
2857         __WDC_LOG_FUNC_START__;
2858
2859         CHECK_FEATURE_SUPPORTED(WIFIDIRECT_FEATURE);
2860
2861         GError* error = NULL;
2862         GVariant *reply = NULL;
2863         int val = 0;
2864         int ret = WIFI_DIRECT_ERROR_NONE;
2865
2866         if (g_client_info.is_registered == false) {
2867                 WDC_LOGE("Client is NOT registered");
2868                 __WDC_LOG_FUNC_END__;
2869                 return WIFI_DIRECT_ERROR_NOT_INITIALIZED;
2870         }
2871
2872         if (!state) {
2873                 WDC_LOGE("Invalid Parameter");
2874                 __WDC_LOG_FUNC_END__;
2875                 return WIFI_DIRECT_ERROR_INVALID_PARAMETER;
2876         }
2877
2878         reply = wifi_direct_dbus_method_call_sync(WFD_MANAGER_MANAGE_INTERFACE,
2879                                                   "GetState", NULL, &error);
2880         if (error != NULL) {
2881                 WDC_LOGE("wifi_direct_dbus_method_call_sync() failed."
2882                                 "error [%d: %s]", error->code, error->message);
2883                 g_error_free(error);
2884                 __WDC_LOG_FUNC_END__;
2885                 return WIFI_DIRECT_ERROR_OPERATION_FAILED;
2886         }
2887
2888         g_variant_get(reply, "(ii)", &ret, &val);
2889         *state = (wifi_direct_state_e) val;
2890         /* for CAPI : there is no WIFI_DIRECT_STATE_GROUP_OWNER type in CAPI */
2891         if(*state == WIFI_DIRECT_STATE_GROUP_OWNER)
2892                 *state = WIFI_DIRECT_STATE_CONNECTED;
2893
2894         g_variant_unref(reply);
2895
2896         WDC_LOGD("State = [%d]", *state);
2897         WDC_LOGD("%s() return : [%d]", __func__, ret);
2898         __WDC_LOG_FUNC_END__;
2899         return ret;
2900 }
2901
2902
2903 int wifi_direct_is_discoverable(bool* discoverable)
2904 {
2905         __WDC_LOG_FUNC_START__;
2906
2907         CHECK_FEATURE_SUPPORTED(WIFIDIRECT_FEATURE);
2908
2909         GError* error = NULL;
2910         GVariant *reply = NULL;
2911
2912         if (g_client_info.is_registered == false) {
2913                 WDC_LOGE("Client is NOT registered");
2914                 __WDC_LOG_FUNC_END__;
2915                 return WIFI_DIRECT_ERROR_NOT_INITIALIZED;
2916         }
2917
2918         if (!discoverable) {
2919                 WDC_LOGE("Invalid Parameter");
2920                 __WDC_LOG_FUNC_END__;
2921                 return WIFI_DIRECT_ERROR_INVALID_PARAMETER;
2922         }
2923
2924         reply = wifi_direct_dbus_method_call_sync(WFD_MANAGER_MANAGE_INTERFACE,
2925                                                   "IsDiscoverable", NULL, &error);
2926         if (error != NULL) {
2927                 WDC_LOGE("wifi_direct_dbus_method_call_sync() failed."
2928                                 "error [%d: %s]", error->code, error->message);
2929                 g_error_free(error);
2930                 __WDC_LOG_FUNC_END__;
2931                 return WIFI_DIRECT_ERROR_OPERATION_FAILED;
2932         }
2933
2934         g_variant_get(reply, "(b)", discoverable);
2935         WDC_LOGD("Discoverable = [%s]", *discoverable ? "Yes":"No");
2936
2937         WDC_LOGD("%s() SUCCESS", __func__);
2938         g_variant_unref(reply);
2939
2940         __WDC_LOG_FUNC_END__;
2941         return WIFI_DIRECT_ERROR_NONE;
2942 }
2943
2944 int wifi_direct_is_listening_only(bool* listen_only)
2945 {
2946         __WDC_LOG_FUNC_START__;
2947
2948         CHECK_FEATURE_SUPPORTED(WIFIDIRECT_FEATURE);
2949
2950         GError* error = NULL;
2951         GVariant *reply = NULL;
2952
2953         if (g_client_info.is_registered == false) {
2954                 WDC_LOGE("Client is NOT registered");
2955                 __WDC_LOG_FUNC_END__;
2956                 return WIFI_DIRECT_ERROR_NOT_INITIALIZED;
2957         }
2958
2959         if (!listen_only) {
2960                 WDC_LOGE("Invalid Parameter");
2961                 __WDC_LOG_FUNC_END__;
2962                 return WIFI_DIRECT_ERROR_INVALID_PARAMETER;
2963         }
2964
2965         reply = wifi_direct_dbus_method_call_sync(WFD_MANAGER_MANAGE_INTERFACE,
2966                                                   "IsListeningOnly", NULL, &error);
2967         if (error != NULL) {
2968                 WDC_LOGE("wifi_direct_dbus_method_call_sync() failed."
2969                                 "error [%d: %s]", error->code, error->message);
2970                 g_error_free(error);
2971                 __WDC_LOG_FUNC_END__;
2972                 return WIFI_DIRECT_ERROR_OPERATION_FAILED;
2973         }
2974
2975         g_variant_get(reply, "(b)", listen_only);
2976
2977         WDC_LOGD("Is listen only = [%s]", *listen_only ? "Yes":"No");
2978         WDC_LOGD("%s() SUCCESS", __func__);
2979         g_variant_unref(reply);
2980
2981         __WDC_LOG_FUNC_END__;
2982         return WIFI_DIRECT_ERROR_NONE;
2983 }
2984
2985
2986 int wifi_direct_get_primary_device_type(wifi_direct_primary_device_type_e* type)
2987 {
2988         __WDC_LOG_FUNC_START__;
2989
2990         CHECK_FEATURE_SUPPORTED(WIFIDIRECT_FEATURE);
2991
2992         if (!type) {
2993                 WDC_LOGE("NULL Param [type]!");
2994                 __WDC_LOG_FUNC_END__;
2995                 return WIFI_DIRECT_ERROR_INVALID_PARAMETER;
2996         }
2997
2998         if (g_client_info.is_registered == false) {
2999                 WDC_LOGE("Client is NOT registered");
3000                 __WDC_LOG_FUNC_END__;
3001                 return WIFI_DIRECT_ERROR_NOT_INITIALIZED;
3002         }
3003
3004 #ifdef TIZEN_TV
3005         WDC_LOGD("Current primary_dev_type [%d]", WIFI_DIRECT_PRIMARY_DEVICE_TYPE_DISPLAY);
3006         *type = WIFI_DIRECT_PRIMARY_DEVICE_TYPE_DISPLAY;
3007 #else /* TIZEN_TV */
3008         WDC_LOGD("Current primary_dev_type [%d]", WIFI_DIRECT_PRIMARY_DEVICE_TYPE_TELEPHONE);
3009         *type = WIFI_DIRECT_PRIMARY_DEVICE_TYPE_TELEPHONE;
3010 #endif /* TIZEN_TV */
3011
3012         __WDC_LOG_FUNC_END__;
3013         return WIFI_DIRECT_ERROR_NONE;
3014 }
3015
3016 int wifi_direct_get_secondary_device_type(wifi_direct_secondary_device_type_e* type)
3017 {
3018         __WDC_LOG_FUNC_START__;
3019
3020         CHECK_FEATURE_SUPPORTED(WIFIDIRECT_FEATURE);
3021
3022         if (g_client_info.is_registered == false) {
3023                 WDC_LOGE("Client is NOT registered");
3024                 __WDC_LOG_FUNC_END__;
3025                 return WIFI_DIRECT_ERROR_NOT_INITIALIZED;
3026         }
3027
3028         if (NULL == type) {
3029                 WDC_LOGE("NULL Param [type]!");
3030                 __WDC_LOG_FUNC_END__;
3031                 return WIFI_DIRECT_ERROR_INVALID_PARAMETER;
3032         }
3033
3034 #ifdef TIZEN_TV
3035         WDC_LOGD("Current second_dev_type [%d]", WIFI_DIRECT_SECONDARY_DEVICE_TYPE_DISPLAY_TV);
3036         *type = WIFI_DIRECT_SECONDARY_DEVICE_TYPE_DISPLAY_TV;
3037 #else /* TIZEN_TV */
3038         WDC_LOGD("Current second_dev_type [%d]", WIFI_DIRECT_SECONDARY_DEVICE_TYPE_TELEPHONE_SMARTPHONE_DUAL);
3039         *type = WIFI_DIRECT_SECONDARY_DEVICE_TYPE_TELEPHONE_SMARTPHONE_DUAL;    /* smart phone dual mode (wifi and cellular) */
3040 #endif /* TIZEN_TV */
3041
3042         __WDC_LOG_FUNC_END__;
3043         return WIFI_DIRECT_ERROR_NONE;
3044 }
3045
3046 int wifi_direct_set_autoconnection_mode(bool mode)
3047 {
3048         __WDC_LOG_FUNC_START__;
3049
3050         CHECK_FEATURE_SUPPORTED(WIFIDIRECT_FEATURE);
3051
3052         GError* error = NULL;
3053         GVariant *reply = NULL;
3054         GVariant *params = NULL;
3055         int ret = WIFI_DIRECT_ERROR_NONE;
3056
3057         if (g_client_info.is_registered == false) {
3058                 WDC_LOGE("Client is NOT registered");
3059                 __WDC_LOG_FUNC_END__;
3060                 return WIFI_DIRECT_ERROR_NOT_INITIALIZED;
3061         }
3062
3063         params = g_variant_new("(b)", mode);
3064         reply = wifi_direct_dbus_method_call_sync(WFD_MANAGER_CONFIG_INTERFACE,
3065                                           "SetAutoConnectionMode",
3066                                           params,
3067                                           &error);
3068         if (error != NULL) {
3069                 WDC_LOGE("wifi_direct_dbus_method_call_sync() failed."
3070                                 "error [%d: %s]", error->code, error->message);
3071                 g_error_free(error);
3072                 __WDC_LOG_FUNC_END__;
3073                 return WIFI_DIRECT_ERROR_OPERATION_FAILED;
3074         }
3075
3076         g_variant_get(reply, "(i)", &ret);
3077         g_variant_unref(reply);
3078
3079         WDC_LOGD("%s() return : [%d]", __func__, ret);
3080         __WDC_LOG_FUNC_END__;
3081         return ret;
3082 }
3083
3084 int wifi_direct_is_autoconnection_mode(bool *mode)
3085 {
3086         __WDC_LOG_FUNC_START__;
3087
3088         CHECK_FEATURE_SUPPORTED(WIFIDIRECT_FEATURE);
3089
3090         GError* error = NULL;
3091         GVariant *reply = NULL;
3092         bool val = FALSE;
3093         int ret = WIFI_DIRECT_ERROR_NONE;
3094
3095         if (g_client_info.is_registered == false) {
3096                 WDC_LOGE("Client is NOT registered");
3097                 __WDC_LOG_FUNC_END__;
3098                 return WIFI_DIRECT_ERROR_NOT_INITIALIZED;
3099         }
3100
3101         if (!mode) {
3102                 WDC_LOGE("NULL Param [mode]!");
3103                 __WDC_LOG_FUNC_END__;
3104                 return WIFI_DIRECT_ERROR_INVALID_PARAMETER;
3105         }
3106
3107         reply = wifi_direct_dbus_method_call_sync(WFD_MANAGER_CONFIG_INTERFACE,
3108                                           "IsAutoConnectionMode",
3109                                           NULL,
3110                                           &error);
3111         if (error != NULL) {
3112                 WDC_LOGE("wifi_direct_dbus_method_call_sync() failed."
3113                                 "error [%d: %s]", error->code, error->message);
3114                 g_error_free(error);
3115                 __WDC_LOG_FUNC_END__;
3116                 return WIFI_DIRECT_ERROR_OPERATION_FAILED;
3117         }
3118
3119         g_variant_get(reply, "(ib)", &ret, &val);
3120         *mode = val;
3121         g_variant_unref(reply);
3122
3123         WDC_LOGD("%s() return : [%d]", __func__, ret);
3124         __WDC_LOG_FUNC_END__;
3125         return ret;
3126 }
3127
3128
3129 int wifi_direct_set_persistent_group_enabled(bool enabled)
3130 {
3131         __WDC_LOG_FUNC_START__;
3132
3133         CHECK_FEATURE_SUPPORTED(WIFIDIRECT_FEATURE);
3134
3135         GError* error = NULL;
3136         GVariant *reply = NULL;
3137         GVariant *params = NULL;
3138
3139         if (g_client_info.is_registered == false) {
3140                 WDC_LOGE("Client is NOT registered");
3141                 __WDC_LOG_FUNC_END__;
3142                 return WIFI_DIRECT_ERROR_NOT_INITIALIZED;
3143         }
3144
3145         params = g_variant_new("(b)", enabled);
3146         reply = wifi_direct_dbus_method_call_sync(WFD_MANAGER_GROUP_INTERFACE,
3147                                           "SetPersistentGroupEnabled",
3148                                           params,
3149                                           &error);
3150         if (error != NULL) {
3151                 WDC_LOGE("wifi_direct_dbus_method_call_sync() failed."
3152                                 "error [%d: %s]", error->code, error->message);
3153                 g_error_free(error);
3154                 __WDC_LOG_FUNC_END__;
3155                 return WIFI_DIRECT_ERROR_OPERATION_FAILED;
3156         }
3157         WDC_LOGD("%s() SUCCESS", __func__);
3158
3159         g_variant_unref(reply);
3160
3161         __WDC_LOG_FUNC_END__;
3162         return WIFI_DIRECT_ERROR_NONE;
3163 }
3164
3165
3166 int wifi_direct_is_persistent_group_enabled(bool *enabled)
3167 {
3168         __WDC_LOG_FUNC_START__;
3169
3170         CHECK_FEATURE_SUPPORTED(WIFIDIRECT_FEATURE);
3171
3172         GError* error = NULL;
3173         GVariant *reply = NULL;
3174         bool val;
3175
3176         if (g_client_info.is_registered == false) {
3177                 WDC_LOGE("Client is NOT registered");
3178                 __WDC_LOG_FUNC_END__;
3179                 return WIFI_DIRECT_ERROR_NOT_INITIALIZED;
3180         }
3181
3182         if (!enabled) {
3183                 WDC_LOGE("NULL Param [enabled]!");
3184                 __WDC_LOG_FUNC_END__;
3185                 return WIFI_DIRECT_ERROR_INVALID_PARAMETER;
3186         }
3187
3188         reply = wifi_direct_dbus_method_call_sync(WFD_MANAGER_GROUP_INTERFACE,
3189                                           "IsPersistentGroupEnabled",
3190                                           NULL,
3191                                           &error);
3192         if (error != NULL) {
3193                 WDC_LOGE("wifi_direct_dbus_method_call_sync() failed."
3194                                 "error [%d: %s]", error->code, error->message);
3195                 g_error_free(error);
3196                 __WDC_LOG_FUNC_END__;
3197                 return WIFI_DIRECT_ERROR_OPERATION_FAILED;
3198         }
3199         WDC_LOGD("%s() SUCCESS", __func__);
3200         g_variant_get(reply, "(b)", &val);
3201         *enabled = val;
3202         g_variant_unref(reply);
3203
3204         __WDC_LOG_FUNC_END__;
3205         return WIFI_DIRECT_ERROR_NONE;
3206 }
3207
3208 int wifi_direct_foreach_persistent_groups(wifi_direct_persistent_group_cb cb,
3209                                         void* user_data)
3210 {
3211         __WDC_LOG_FUNC_START__;
3212
3213         CHECK_FEATURE_SUPPORTED(WIFIDIRECT_FEATURE);
3214
3215         GVariant *params = NULL;
3216         GError *error = NULL;
3217         GVariant *reply = NULL;
3218         GVariantIter *iter_groups = NULL;
3219         GVariantIter *iter_group = NULL;
3220         GVariant *var = NULL;
3221         gchar *key = NULL;
3222         int ret = WIFI_DIRECT_ERROR_NONE;
3223
3224         if (g_client_info.is_registered == false) {
3225                 WDC_LOGE("Client is NOT registered");
3226                 __WDC_LOG_FUNC_END__;
3227                 return WIFI_DIRECT_ERROR_NOT_INITIALIZED;
3228         }
3229
3230         if (!cb) {
3231                 WDC_LOGE("NULL Param [callback]!");
3232                 __WDC_LOG_FUNC_END__;
3233                 return WIFI_DIRECT_ERROR_INVALID_PARAMETER;
3234         }
3235
3236         reply = wifi_direct_dbus_method_call_sync(WFD_MANAGER_GROUP_INTERFACE,
3237                                                   "GetPersistentGroups", params, &error);
3238         if (error != NULL) {
3239                 WDC_LOGE("wifi_direct_dbus_method_call_sync() failed."
3240                                 "error [%d: %s]", error->code, error->message);
3241                 g_error_free(error);
3242                 __WDC_LOG_FUNC_END__;
3243                 return WIFI_DIRECT_ERROR_OPERATION_FAILED;
3244         }
3245
3246         g_variant_get(reply, "(iaa{sv})", &ret, &iter_groups);
3247         if (ret != WIFI_DIRECT_ERROR_NONE) {
3248                 __WDC_LOG_FUNC_END__;
3249                 return WIFI_DIRECT_ERROR_OPERATION_FAILED;
3250         }
3251
3252         WDC_LOGD("wifi_direct_foreach_persistent_groups() SUCCESS");
3253
3254         while(g_variant_iter_loop(iter_groups, "a{sv}", &iter_group)) {
3255                 const char *ssid = NULL;
3256                 char *go_mac_address = NULL;
3257
3258                 while (g_variant_iter_loop(iter_group, "{sv}", &key, &var)) {
3259                         if (!g_strcmp0(key, "SSID")) {
3260                                 g_variant_get(var, "&s", &ssid);
3261
3262                         } else if (!g_strcmp0(key, "GOMacAddress")) {
3263                                 unsigned char mac_address[MACADDR_LEN] = {0, };
3264
3265                                 wifi_direct_dbus_unpack_ay(mac_address, var, MACADDR_LEN);
3266                                 go_mac_address = (char*) g_try_malloc0(MACSTR_LEN);
3267                                 if (go_mac_address)
3268                                         g_snprintf(go_mac_address, MACSTR_LEN, MACSTR, MAC2STR(mac_address));
3269
3270                         } else {
3271                                 ;/* Do Nothing */
3272                         }
3273                 }
3274
3275                 ret = cb(go_mac_address, ssid, user_data);
3276                 g_free(go_mac_address);
3277                 go_mac_address = NULL;
3278                 if (!ret) {
3279                         g_variant_iter_free(iter_group);
3280                         break;
3281                 }
3282         }
3283
3284         g_variant_iter_free(iter_groups);
3285         __WDC_LOG_FUNC_END__;
3286         return WIFI_DIRECT_ERROR_NONE;
3287 }
3288
3289 int wifi_direct_remove_persistent_group(char *mac_address, const char *ssid)
3290 {
3291         __WDC_LOG_FUNC_START__;
3292
3293         CHECK_FEATURE_SUPPORTED(WIFIDIRECT_FEATURE);
3294
3295         GError* error = NULL;
3296         GVariant *reply = NULL;
3297         GVariant *params = NULL;
3298
3299         if (g_client_info.is_registered == false) {
3300                 WDC_LOGE("Client is NOT registered");
3301                 __WDC_LOG_FUNC_END__;
3302                 return WIFI_DIRECT_ERROR_NOT_INITIALIZED;
3303         }
3304
3305         if (!mac_address || !ssid) {
3306                 WDC_LOGE("NULL Param");
3307                 __WDC_LOG_FUNC_END__;
3308                 return WIFI_DIRECT_ERROR_INVALID_PARAMETER;
3309         }
3310
3311         params = g_variant_new("(ss)", mac_address, ssid);
3312         reply = wifi_direct_dbus_method_call_sync(WFD_MANAGER_GROUP_INTERFACE,
3313                                           "RemovePersistentGroup",
3314                                           params,
3315                                           &error);
3316         if (error != NULL) {
3317                 WDC_LOGE("wifi_direct_dbus_method_call_sync() failed."
3318                                 "error [%d: %s]", error->code, error->message);
3319                 g_error_free(error);
3320                 __WDC_LOG_FUNC_END__;
3321                 return WIFI_DIRECT_ERROR_OPERATION_FAILED;
3322         }
3323         WDC_LOGD("%s() SUCCESS", __func__);
3324
3325         g_variant_unref(reply);
3326
3327         __WDC_LOG_FUNC_END__;
3328         return WIFI_DIRECT_ERROR_NONE;
3329 }
3330
3331 int wifi_direct_set_p2poem_loglevel(int increase_log_level)
3332 {
3333         __WDC_LOG_FUNC_START__;
3334 /* TODO:
3335         wifi_direct_client_request_s req;
3336         wifi_direct_client_response_s rsp;
3337         int res = WIFI_DIRECT_ERROR_NONE;
3338
3339         if (g_client_info.is_registered == false) {
3340                 WDC_LOGE("Client is NOT registered");
3341                 __WDC_LOG_FUNC_END__;
3342                 return WIFI_DIRECT_ERROR_NOT_INITIALIZED;
3343         }
3344
3345         memset(&req, 0, sizeof(wifi_direct_client_request_s));
3346         memset(&rsp, 0, sizeof(wifi_direct_client_response_s));
3347
3348         req.cmd = WIFI_DIRECT_CMD_SET_OEM_LOGLEVEL;
3349         req.client_id = g_client_info.client_id;
3350         if (increase_log_level == 0)
3351                 req.data.int1 = false;
3352         else
3353                 req.data.int1 = true;
3354
3355         res = __wfd_client_send_request(g_client_info.sync_sockfd, &req, &rsp);
3356         if (res != WIFI_DIRECT_ERROR_NONE) {
3357                 __WDC_LOG_FUNC_END__;
3358                 return res;
3359         }
3360 */
3361         __WDC_LOG_FUNC_END__;
3362         return WIFI_DIRECT_ERROR_NONE;
3363 }
3364
3365 int wifi_direct_start_service_discovery(char *mac_address,
3366                 wifi_direct_service_type_e type)
3367 {
3368 #ifdef TIZEN_FEATURE_SERVICE_DISCOVERY
3369         __WDC_LOG_FUNC_START__;
3370
3371         CHECK_FEATURE_SUPPORTED(WIFIDIRECT_SERVICE_DISCOVERY_FEATURE);
3372
3373         GError* error = NULL;
3374         GVariant *reply = NULL;
3375         GVariant *params = NULL;
3376         int ret = WIFI_DIRECT_ERROR_NONE;
3377
3378         if (g_client_info.is_registered == false) {
3379                 WDC_LOGE("Client is NOT registered.");
3380                 __WDC_LOG_FUNC_END__;
3381                 return WIFI_DIRECT_ERROR_NOT_INITIALIZED;
3382         }
3383
3384         if (type >= WIFI_DIRECT_SERVICE_TYPE_ALL &&
3385                         type <= WIFI_DIRECT_SERVICE_TYPE_CONTACT_INFO) {
3386                 WDC_LOGD("Param service_type [%d]", type);
3387         } else {
3388                 WDC_LOGE("Invalid Param [type]!");
3389                 __WDC_LOG_FUNC_END__;
3390                 return WIFI_DIRECT_ERROR_INVALID_PARAMETER;
3391         }
3392
3393         if (mac_address)
3394                 params = g_variant_new("(is)", type, mac_address);
3395         else
3396                 params = g_variant_new("(is)", type, "00:00:00:00:00:00");
3397
3398         reply = wifi_direct_dbus_method_call_sync(WFD_MANAGER_SERVICE_INTERFACE,
3399                                                     "StartDiscovery",
3400                                                     params,
3401                                                     &error);
3402         if (error != NULL) {
3403                 WDC_LOGE("wifi_direct_dbus_method_call_sync() failed."
3404                                 "error [%d: %s]", error->code, error->message);
3405                 g_error_free(error);
3406                 __WDC_LOG_FUNC_END__;
3407                 return WIFI_DIRECT_ERROR_OPERATION_FAILED;
3408         }
3409
3410         g_variant_get(reply, "(i)", &ret);
3411         g_variant_unref(reply);
3412
3413         WDC_LOGD("%s() return : [%d]", __func__, ret);
3414         __WDC_LOG_FUNC_END__;
3415         return ret;
3416 #else /* TIZEN_FEATURE_SERVICE_DISCOVERY */
3417         return WIFI_DIRECT_ERROR_NOT_SUPPORTED;
3418 #endif /* TIZEN_FEATURE_SERVICE_DISCOVERY */
3419 }
3420
3421
3422 int wifi_direct_cancel_service_discovery(char *mac_address,
3423                 wifi_direct_service_type_e type)
3424 {
3425 #ifdef TIZEN_FEATURE_SERVICE_DISCOVERY
3426         __WDC_LOG_FUNC_START__;
3427
3428         CHECK_FEATURE_SUPPORTED(WIFIDIRECT_SERVICE_DISCOVERY_FEATURE);
3429
3430         GError* error = NULL;
3431         GVariant *reply = NULL;
3432         GVariant *params = NULL;
3433         int ret = WIFI_DIRECT_ERROR_NONE;
3434
3435         if (g_client_info.is_registered == false) {
3436                 WDC_LOGE("Client is NOT registered.");
3437                 __WDC_LOG_FUNC_END__;
3438                 return WIFI_DIRECT_ERROR_NOT_INITIALIZED;
3439         }
3440
3441         if (type >= WIFI_DIRECT_SERVICE_TYPE_ALL &&
3442                         type <= WIFI_DIRECT_SERVICE_TYPE_CONTACT_INFO) {
3443                 WDC_LOGD("Param service_type [%d]", type);
3444         } else {
3445                 WDC_LOGE("Invalid Param [type]!");
3446                 __WDC_LOG_FUNC_END__;
3447                 return WIFI_DIRECT_ERROR_INVALID_PARAMETER;
3448         }
3449
3450         if (mac_address)
3451                 params = g_variant_new("(is)", type, mac_address);
3452         else
3453                 params = g_variant_new("(is)", type, "00:00:00:00:00:00");
3454
3455         reply = wifi_direct_dbus_method_call_sync(WFD_MANAGER_SERVICE_INTERFACE,
3456                                                     "StopDiscovery",
3457                                                     params,
3458                                                     &error);
3459         if (error != NULL) {
3460                 WDC_LOGE("wifi_direct_dbus_method_call_sync() failed."
3461                                 "error [%d: %s]", error->code, error->message);
3462                 g_error_free(error);
3463                 __WDC_LOG_FUNC_END__;
3464                 return WIFI_DIRECT_ERROR_OPERATION_FAILED;
3465         }
3466
3467         g_variant_get(reply, "(i)", &ret);
3468         g_variant_unref(reply);
3469
3470         WDC_LOGD("%s() return : [%d]", __func__, ret);
3471         __WDC_LOG_FUNC_END__;
3472         return ret;
3473 #else /* TIZEN_FEATURE_SERVICE_DISCOVERY */
3474         return WIFI_DIRECT_ERROR_NOT_SUPPORTED;
3475 #endif /* TIZEN_FEATURE_SERVICE_DISCOVERY */
3476 }
3477
3478 int wifi_direct_register_service(wifi_direct_service_type_e type, char *info1, char *info2, unsigned int *service_id)
3479 {
3480 #ifdef TIZEN_FEATURE_SERVICE_DISCOVERY
3481         __WDC_LOG_FUNC_START__;
3482
3483         CHECK_FEATURE_SUPPORTED(WIFIDIRECT_SERVICE_DISCOVERY_FEATURE);
3484
3485         GError* error = NULL;
3486         GVariant *reply = NULL;
3487         GVariant *params = NULL;
3488         char *buf = NULL;
3489         int ret = WIFI_DIRECT_ERROR_NONE;
3490         int len = 0;
3491
3492         if (g_client_info.is_registered == false) {
3493                 WDC_LOGE("Client is NOT registered.");
3494                 __WDC_LOG_FUNC_END__;
3495                 return WIFI_DIRECT_ERROR_NOT_INITIALIZED;
3496         }
3497
3498         if (!info1 || !info2) {
3499                 WDC_LOGE("info1 or info2 is NULL");
3500                 __WDC_LOG_FUNC_END__;
3501                 return WIFI_DIRECT_ERROR_INVALID_PARAMETER;
3502         }
3503
3504         if (type < WIFI_DIRECT_SERVICE_TYPE_ALL ||
3505                         type > WIFI_DIRECT_SERVICE_TYPE_VENDOR) {
3506                 WDC_LOGE("Invalid Param [type]!");
3507                 __WDC_LOG_FUNC_END__;
3508                 return WIFI_DIRECT_ERROR_INVALID_PARAMETER;
3509         }
3510
3511         if (!service_id) {
3512                 WDC_LOGE("Invalid Param [service_id]!");
3513                 __WDC_LOG_FUNC_END__;
3514                 return WIFI_DIRECT_ERROR_INVALID_PARAMETER;
3515         }
3516
3517         WDC_LOGD("Service type [%d]", type);
3518
3519         len = strlen(info1) + strlen(info2) + 2;
3520         WDC_LOGD("info [%s|%s], len [%d]", info1, info2, len);
3521
3522         buf = g_try_malloc0(len);
3523         if (NULL == buf) {
3524                 WDC_LOGE("Failed to allocate memory for buf");
3525                 return WIFI_DIRECT_ERROR_OUT_OF_MEMORY;
3526         }
3527
3528         g_snprintf(buf, len, "%s|%s", info1, info2);
3529
3530         params = g_variant_new("(is)", type, buf);
3531         reply = wifi_direct_dbus_method_call_sync(WFD_MANAGER_SERVICE_INTERFACE,
3532                                                     "Register",
3533                                                     params,
3534                                                     &error);
3535         if (error != NULL) {
3536                 WDC_LOGE("wifi_direct_dbus_method_call_sync() failed."
3537                                 "error [%d: %s]", error->code, error->message);
3538                 g_error_free(error);
3539                 __WDC_LOG_FUNC_END__;
3540                 return WIFI_DIRECT_ERROR_OPERATION_FAILED;
3541         }
3542
3543         g_variant_get(reply, "(ii)", &ret, service_id);
3544         g_variant_unref(reply);
3545
3546         WDC_LOGD("%s() return : [%d]", __func__, ret);
3547         __WDC_LOG_FUNC_END__;
3548         return ret;
3549 #else /* TIZEN_FEATURE_SERVICE_DISCOVERY */
3550         return WIFI_DIRECT_ERROR_NOT_SUPPORTED;
3551 #endif /* TIZEN_FEATURE_SERVICE_DISCOVERY */
3552 }
3553
3554 int wifi_direct_deregister_service(unsigned int service_id)
3555 {
3556 #ifdef TIZEN_FEATURE_SERVICE_DISCOVERY
3557         __WDC_LOG_FUNC_START__;
3558
3559         CHECK_FEATURE_SUPPORTED(WIFIDIRECT_SERVICE_DISCOVERY_FEATURE);
3560
3561         GError* error = NULL;
3562         GVariant *reply = NULL;
3563         GVariant *params = NULL;
3564         int ret = WIFI_DIRECT_ERROR_NONE;
3565
3566         if (g_client_info.is_registered == false) {
3567                 WDC_LOGE("Client is NOT registered.");
3568                 __WDC_LOG_FUNC_END__;
3569                 return WIFI_DIRECT_ERROR_NOT_INITIALIZED;
3570         }
3571
3572         params = g_variant_new("(i)", service_id);
3573         reply = wifi_direct_dbus_method_call_sync(WFD_MANAGER_SERVICE_INTERFACE,
3574                                                     "Deregister",
3575                                                     params,
3576                                                     &error);
3577         if (error != NULL) {
3578                 WDC_LOGE("wifi_direct_dbus_method_call_sync() failed."
3579                                 "error [%d: %s]", error->code, error->message);
3580                 g_error_free(error);
3581                 __WDC_LOG_FUNC_END__;
3582                 return WIFI_DIRECT_ERROR_OPERATION_FAILED;
3583         }
3584
3585         g_variant_get(reply, "(i)", &ret);
3586         g_variant_unref(reply);
3587
3588         WDC_LOGD("%s() return : [%d]", __func__, ret);
3589         __WDC_LOG_FUNC_END__;
3590         return ret;
3591 #else /* TIZEN_FEATURE_SERVICE_DISCOVERY */
3592         return WIFI_DIRECT_ERROR_NOT_SUPPORTED;
3593 #endif /* TIZEN_FEATURE_SERVICE_DISCOVERY */
3594 }
3595
3596 int wifi_direct_init_miracast(bool enable)
3597 {
3598         __WDC_LOG_FUNC_START__;
3599         int ret = WIFI_DIRECT_ERROR_NONE;
3600
3601         if(enable)
3602                 ret = wifi_direct_init_display();
3603         else
3604                 ret = wifi_direct_deinit_display();
3605
3606         __WDC_LOG_FUNC_END__;
3607         return ret;
3608 }
3609
3610 int wifi_direct_get_peer_info(char* mac_address, wifi_direct_discovered_peer_info_s** peer_info)
3611 {
3612         __WDC_LOG_FUNC_START__;
3613
3614         CHECK_FEATURE_SUPPORTED(WIFIDIRECT_FEATURE);
3615
3616         GVariant *params = NULL;
3617         GError *error = NULL;
3618         GVariant *reply = NULL;
3619         GVariantIter *iter_peer = NULL;
3620         GVariant *var = NULL;
3621         gchar *key = NULL;
3622         int ret = WIFI_DIRECT_ERROR_NONE;
3623
3624         if (g_client_info.is_registered == false) {
3625                 WDC_LOGE("Client is NOT registered");
3626                 __WDC_LOG_FUNC_END__;
3627                 return WIFI_DIRECT_ERROR_NOT_INITIALIZED;
3628         }
3629
3630         if (!mac_address) {
3631                 WDC_LOGE("mac_addr is NULL");
3632                 __WDC_LOG_FUNC_END__;
3633                 return WIFI_DIRECT_ERROR_INVALID_PARAMETER;
3634         }
3635
3636         if (!peer_info) {
3637                 WDC_LOGE("peer_info is NULL");
3638                 __WDC_LOG_FUNC_END__;
3639                 return WIFI_DIRECT_ERROR_INVALID_PARAMETER;
3640         }
3641
3642         params = g_variant_new("(s)", mac_address);
3643         reply = wifi_direct_dbus_method_call_sync(WFD_MANAGER_MANAGE_INTERFACE,
3644                                                   "GetPeerInfo", params, &error);
3645         if (error != NULL) {
3646                 WDC_LOGE("wifi_direct_dbus_method_call_sync() failed."
3647                                 "error [%d: %s]", error->code, error->message);
3648                 g_error_free(error);
3649                 __WDC_LOG_FUNC_END__;
3650                 return WIFI_DIRECT_ERROR_OPERATION_FAILED;
3651         }
3652
3653         g_variant_get(reply, "(ia{sv})", &ret, &iter_peer);
3654         if (ret != WIFI_DIRECT_ERROR_NONE) {
3655                 __WDC_LOG_FUNC_END__;
3656                 return WIFI_DIRECT_ERROR_OPERATION_FAILED;
3657         }
3658
3659         WDC_LOGD("wifi_direct_get_peer() SUCCESS");
3660
3661         wifi_direct_discovered_peer_info_s *peer = NULL;
3662
3663         peer = (wifi_direct_discovered_peer_info_s *) g_try_malloc0(sizeof(wifi_direct_discovered_peer_info_s));
3664         if (!peer) {
3665                 WDC_LOGE("Failed to allocate memory");
3666                 __WDC_LOG_FUNC_END__;
3667                 return WIFI_DIRECT_ERROR_OPERATION_FAILED;
3668         }
3669
3670         while (g_variant_iter_loop(iter_peer, "{sv}", &key, &var)) {
3671                 if (!g_strcmp0(key, "DeviceName")) {
3672                         const char *device_name = NULL;
3673
3674                         g_variant_get(var, "&s", &device_name);
3675                         peer->device_name = g_strndup(device_name, WIFI_DIRECT_MAX_DEVICE_NAME_LEN+1);
3676
3677                 } else if (!g_strcmp0(key, "DeviceAddress")) {
3678                         unsigned char mac_address[MACADDR_LEN] = {0, };
3679
3680                         wifi_direct_dbus_unpack_ay(mac_address, var, MACADDR_LEN);
3681                         peer->mac_address = (char*) g_try_malloc0(MACSTR_LEN);
3682                         if (peer->mac_address)
3683                                 g_snprintf(peer->mac_address, MACSTR_LEN, MACSTR, MAC2STR(mac_address));
3684
3685                 } else if (!g_strcmp0(key, "InterfaceAddress")) {
3686                         unsigned char intf_address[MACADDR_LEN] = {0, };
3687
3688                         wifi_direct_dbus_unpack_ay(intf_address, var, MACADDR_LEN);
3689                         peer->interface_address = (char*) g_try_malloc0(MACSTR_LEN);
3690                         if (peer->interface_address)
3691                                 g_snprintf(peer->interface_address, MACSTR_LEN, MACSTR, MAC2STR(intf_address));
3692
3693                 } else if (!g_strcmp0(key, "Channel")) {
3694                         peer->channel = g_variant_get_uint16(var);
3695
3696                 } else if (!g_strcmp0(key, "IsGroupOwner")) {
3697                         peer->is_group_owner = g_variant_get_boolean(var);
3698
3699                 } else if (!g_strcmp0(key, "IsPersistentGO")) {
3700                         peer->is_persistent_group_owner = g_variant_get_boolean(var);
3701
3702                 } else if (!g_strcmp0(key, "IsConnected")) {
3703                         peer->is_connected = g_variant_get_boolean(var);
3704
3705                 } else if (!g_strcmp0(key, "Category")) {
3706                         peer->primary_device_type = g_variant_get_uint16(var);
3707
3708                 } else if (!g_strcmp0(key, "SubCategory")) {
3709                         peer->secondary_device_type = g_variant_get_uint16(var);
3710
3711                 } else if (!g_strcmp0(key, "IsWfdDevice")) {
3712 #ifdef TIZEN_FEATURE_WIFI_DISPLAY
3713                         peer->is_miracast_device = g_variant_get_boolean(var);
3714 #endif /* TIZEN_FEATURE_WIFI_DISPLAY */
3715                 } else {
3716                         ;/* Do Nothing */
3717                 }
3718         }
3719
3720         *peer_info = peer;
3721
3722         g_variant_unref(reply);
3723         __WDC_LOG_FUNC_END__;
3724         return WIFI_DIRECT_ERROR_NONE;
3725 }
3726
3727 int wifi_direct_set_passphrase(const char *passphrase)
3728 {
3729         __WDC_LOG_FUNC_START__;
3730
3731         CHECK_FEATURE_SUPPORTED(WIFIDIRECT_FEATURE);
3732
3733         GError* error = NULL;
3734         GVariant *reply = NULL;
3735         GVariant *params = NULL;
3736
3737         if (g_client_info.is_registered == false) {
3738                 WDC_LOGE("Client is NOT registered.");
3739                 __WDC_LOG_FUNC_END__;
3740                 return WIFI_DIRECT_ERROR_NOT_INITIALIZED;
3741         }
3742
3743         if (!passphrase) {
3744                 WDC_LOGE("NULL Param [passphrase]!");
3745                 __WDC_LOG_FUNC_END__;
3746                 return WIFI_DIRECT_ERROR_INVALID_PARAMETER;
3747         }
3748         WDC_LOGD("passphrase = [%s]", passphrase);
3749
3750         params = g_variant_new("(s)", passphrase);
3751         reply = wifi_direct_dbus_method_call_sync(WFD_MANAGER_GROUP_INTERFACE,
3752                                           "SetPassphrase",
3753                                           params,
3754                                           &error);
3755         if (error != NULL) {
3756                 WDC_LOGE("wifi_direct_dbus_method_call_sync() failed."
3757                                 "error [%d: %s]", error->code, error->message);
3758                 g_error_free(error);
3759                 __WDC_LOG_FUNC_END__;
3760                 return WIFI_DIRECT_ERROR_OPERATION_FAILED;
3761         }
3762         WDC_LOGD("%s() SUCCESS", __func__);
3763
3764         g_variant_unref(reply);
3765
3766         __WDC_LOG_FUNC_END__;
3767         return WIFI_DIRECT_ERROR_NONE;
3768 }
3769
3770 int wifi_direct_get_passphrase(char** passphrase)
3771 {
3772         __WDC_LOG_FUNC_START__;
3773
3774         CHECK_FEATURE_SUPPORTED(WIFIDIRECT_FEATURE);
3775
3776         GError* error = NULL;
3777         GVariant *reply = NULL;
3778         const char *val = NULL;
3779         int ret = WIFI_DIRECT_ERROR_NONE;
3780
3781         if (g_client_info.is_registered == false) {
3782                 WDC_LOGE("Client is NOT registered.");
3783                 __WDC_LOG_FUNC_END__;
3784                 return WIFI_DIRECT_ERROR_NOT_INITIALIZED;
3785         }
3786
3787         if(!passphrase){
3788                 WDC_LOGE("NULL Param [passphrase]!");
3789                 __WDC_LOG_FUNC_END__;
3790                 return WIFI_DIRECT_ERROR_INVALID_PARAMETER;
3791         }
3792
3793         reply = wifi_direct_dbus_method_call_sync(WFD_MANAGER_GROUP_INTERFACE,
3794                                           "GetPassphrase",
3795                                           NULL,
3796                                           &error);
3797         if (error != NULL) {
3798                 WDC_LOGE("wifi_direct_dbus_method_call_sync() failed."
3799                                 "error [%d: %s]", error->code, error->message);
3800                 g_error_free(error);
3801                 __WDC_LOG_FUNC_END__;
3802                 return WIFI_DIRECT_ERROR_OPERATION_FAILED;
3803         }
3804         WDC_LOGD("%s() SUCCESS", __func__);
3805         g_variant_get(reply, "(i&s)", &ret, &val);
3806         *passphrase = g_strdup(val);
3807         g_variant_unref(reply);
3808
3809         WDC_LOGD("%s() return : [%d]", __func__, ret);
3810         __WDC_LOG_FUNC_END__;
3811         return ret;
3812 }
3813
3814 int wifi_direct_set_autoconnection_peer(char *mac_address)
3815 {
3816         __WDC_LOG_FUNC_START__;
3817
3818         CHECK_FEATURE_SUPPORTED(WIFIDIRECT_FEATURE);
3819
3820         GError* error = NULL;
3821         GVariant *reply = NULL;
3822         GVariant *params = NULL;
3823         int ret = WIFI_DIRECT_ERROR_NONE;
3824
3825         if (g_client_info.is_registered == false) {
3826                 WDC_LOGE("Client is NOT registered.");
3827                 __WDC_LOG_FUNC_END__;
3828                 return WIFI_DIRECT_ERROR_NOT_INITIALIZED;
3829         }
3830
3831         if (!mac_address) {
3832                 WDC_LOGE("NULL Param!");
3833                 __WDC_LOG_FUNC_END__;
3834                 return WIFI_DIRECT_ERROR_INVALID_PARAMETER;
3835         }
3836
3837         params = g_variant_new("(s)", mac_address);
3838         reply = wifi_direct_dbus_method_call_sync(WFD_MANAGER_CONFIG_INTERFACE,
3839                                           "SetAutoConnectionPeer",
3840                                           params,
3841                                           &error);
3842         if (error != NULL) {
3843                 WDC_LOGE("wifi_direct_dbus_method_call_sync() failed."
3844                                 "error [%d: %s]", error->code, error->message);
3845                 g_error_free(error);
3846                 __WDC_LOG_FUNC_END__;
3847                 return WIFI_DIRECT_ERROR_OPERATION_FAILED;
3848         }
3849
3850         g_variant_get(reply, "(i)", &ret);
3851         g_variant_unref(reply);
3852
3853         WDC_LOGD("%s() return : [%d]", __func__, ret);
3854         __WDC_LOG_FUNC_END__;
3855         return ret;
3856 }
3857
3858 int wifi_direct_init_display(void)
3859 {
3860         __WDC_LOG_FUNC_START__;
3861 #ifdef TIZEN_FEATURE_WIFI_DISPLAY
3862
3863         CHECK_FEATURE_SUPPORTED(WIFIDIRECT_DISPLAY_FEATURE);
3864
3865         GError* error = NULL;
3866         GVariant *reply = NULL;
3867         int ret = WIFI_DIRECT_ERROR_NONE;
3868
3869         if (g_client_info.is_registered == false) {
3870                 WDC_LOGE("Client is NOT registered.");
3871                 __WDC_LOG_FUNC_END__;
3872                 return WIFI_DIRECT_ERROR_NOT_INITIALIZED;
3873         }
3874
3875         reply = wifi_direct_dbus_method_call_sync(WFD_MANAGER_DISPLAY_INTERFACE,
3876                                           "Init",
3877                                           NULL,
3878                                           &error);
3879         if (error != NULL) {
3880                 WDC_LOGE("wifi_direct_dbus_method_call_sync() failed."
3881                                 "error [%d: %s]", error->code, error->message);
3882                 g_error_free(error);
3883                 __WDC_LOG_FUNC_END__;
3884                 return WIFI_DIRECT_ERROR_OPERATION_FAILED;
3885         }
3886
3887         g_variant_get(reply, "(i)", &ret);
3888         g_variant_unref(reply);
3889
3890         WDC_LOGD("%s() return : [%d]", __func__, ret);
3891         __WDC_LOG_FUNC_END__;
3892         return ret;
3893 #else /* TIZEN_FEATURE_WIFI_DISPLAY */
3894         return WIFI_DIRECT_ERROR_NOT_SUPPORTED;
3895 #endif /* TIZEN_FEATURE_WIFI_DISPLAY */
3896 }
3897
3898 int wifi_direct_deinit_display(void)
3899 {
3900         __WDC_LOG_FUNC_START__;
3901 #ifdef TIZEN_FEATURE_WIFI_DISPLAY
3902
3903         CHECK_FEATURE_SUPPORTED(WIFIDIRECT_DISPLAY_FEATURE);
3904
3905         GError* error = NULL;
3906         GVariant *reply = NULL;
3907         int ret = WIFI_DIRECT_ERROR_NONE;
3908
3909         if (g_client_info.is_registered == false) {
3910                 WDC_LOGE("Client is NOT registered");
3911                 __WDC_LOG_FUNC_END__;
3912                 return WIFI_DIRECT_ERROR_NOT_INITIALIZED;
3913         }
3914
3915         reply = wifi_direct_dbus_method_call_sync(WFD_MANAGER_DISPLAY_INTERFACE,
3916                                           "Deinit",
3917                                           NULL,
3918                                           &error);
3919         if (error != NULL) {
3920                 WDC_LOGE("wifi_direct_dbus_method_call_sync() failed."
3921                                 "error [%d: %s]", error->code, error->message);
3922                 g_error_free(error);
3923                 __WDC_LOG_FUNC_END__;
3924                 return WIFI_DIRECT_ERROR_OPERATION_FAILED;
3925         }
3926
3927         g_variant_get(reply, "(i)", &ret);
3928         g_variant_unref(reply);
3929
3930         WDC_LOGD("%s() return : [%d]", __func__, ret);
3931         __WDC_LOG_FUNC_END__;
3932         return ret;
3933 #else /* TIZEN_FEATURE_WIFI_DISPLAY */
3934         return WIFI_DIRECT_ERROR_NOT_SUPPORTED;
3935 #endif /* TIZEN_FEATURE_WIFI_DISPLAY */
3936 }
3937
3938 int wifi_direct_set_display(wifi_direct_display_type_e type, int port, int hdcp)
3939 {
3940         __WDC_LOG_FUNC_START__;
3941 #ifdef TIZEN_FEATURE_WIFI_DISPLAY
3942
3943         CHECK_FEATURE_SUPPORTED(WIFIDIRECT_DISPLAY_FEATURE);
3944
3945         GError* error = NULL;
3946         GVariant *reply = NULL;
3947         GVariant *params = NULL;
3948         int ret = WIFI_DIRECT_ERROR_NONE;
3949
3950         if (g_client_info.is_registered == false) {
3951                 WDC_LOGE("Client is NOT registered");
3952                 __WDC_LOG_FUNC_END__;
3953                 return WIFI_DIRECT_ERROR_NOT_INITIALIZED;
3954         }
3955
3956         if (type < WIFI_DIRECT_DISPLAY_TYPE_SOURCE ||
3957                         type > WIFI_DIRECT_DISPLAY_TYPE_DUAL || port < 0 ||
3958                         hdcp < 0) {
3959                 WDC_LOGE("Invalid paramaeters passed type[%d], port[%d], hdcp[%d]!");
3960                 __WDC_LOG_FUNC_END__;
3961                 return WIFI_DIRECT_ERROR_INVALID_PARAMETER;
3962         }
3963
3964         params = g_variant_new("(iii)", type, port, hdcp);
3965         reply = wifi_direct_dbus_method_call_sync(WFD_MANAGER_DISPLAY_INTERFACE,
3966                                           "SetConfig",
3967                                           params,
3968                                           &error);
3969         if (error != NULL) {
3970                 WDC_LOGE("wifi_direct_dbus_method_call_sync() failed."
3971                                 "error [%d: %s]", error->code, error->message);
3972                 g_error_free(error);
3973                 __WDC_LOG_FUNC_END__;
3974                 return WIFI_DIRECT_ERROR_OPERATION_FAILED;
3975         }
3976
3977         g_variant_get(reply, "(i)", &ret);
3978         g_variant_unref(reply);
3979
3980         WDC_LOGD("%s() return : [%d]", __func__, ret);
3981         __WDC_LOG_FUNC_END__;
3982         return ret;
3983 #else /* TIZEN_FEATURE_WIFI_DISPLAY */
3984         return WIFI_DIRECT_ERROR_NOT_SUPPORTED;
3985 #endif /* TIZEN_FEATURE_WIFI_DISPLAY */
3986 }
3987
3988 int wifi_direct_set_display_availability(bool availability)
3989 {
3990         __WDC_LOG_FUNC_START__;
3991 #ifdef TIZEN_FEATURE_WIFI_DISPLAY
3992
3993         CHECK_FEATURE_SUPPORTED(WIFIDIRECT_DISPLAY_FEATURE);
3994
3995         GError* error = NULL;
3996         GVariant *reply = NULL;
3997         GVariant *params = NULL;
3998         int ret = WIFI_DIRECT_ERROR_NONE;
3999
4000         if (g_client_info.is_registered == false) {
4001                 WDC_LOGE("Client is NOT registered.");
4002                 __WDC_LOG_FUNC_END__;
4003                 return WIFI_DIRECT_ERROR_NOT_INITIALIZED;
4004         }
4005
4006
4007         params = g_variant_new("(i)", availability);
4008         reply = wifi_direct_dbus_method_call_sync(WFD_MANAGER_DISPLAY_INTERFACE,
4009                                           "SetAvailiability",
4010                                           params,
4011                                           &error);
4012         if (error != NULL) {
4013                 WDC_LOGE("wifi_direct_dbus_method_call_sync() failed."
4014                                 "error [%d: %s]", error->code, error->message);
4015                 g_error_free(error);
4016                 __WDC_LOG_FUNC_END__;
4017                 return WIFI_DIRECT_ERROR_OPERATION_FAILED;
4018         }
4019
4020         g_variant_get(reply, "(i)", &ret);
4021         g_variant_unref(reply);
4022
4023         WDC_LOGD("%s() return : [%d]", __func__, ret);
4024         __WDC_LOG_FUNC_END__;
4025         return ret;
4026 #else /* TIZEN_FEATURE_WIFI_DISPLAY */
4027         return WIFI_DIRECT_ERROR_NOT_SUPPORTED;
4028 #endif /* TIZEN_FEATURE_WIFI_DISPLAY */
4029 }
4030
4031 int wifi_direct_get_peer_display_type(char *mac_address, wifi_direct_display_type_e *type)
4032 {
4033         __WDC_LOG_FUNC_START__;
4034 #ifdef TIZEN_FEATURE_WIFI_DISPLAY
4035
4036         CHECK_FEATURE_SUPPORTED(WIFIDIRECT_DISPLAY_FEATURE);
4037
4038         GError* error = NULL;
4039         GVariant *reply = NULL;
4040         GVariant *params = NULL;
4041         int val = 0;
4042         int ret = WIFI_DIRECT_ERROR_NONE;
4043
4044         if (g_client_info.is_registered == false) {
4045                 WDC_LOGE("Client is NOT registered");
4046                 __WDC_LOG_FUNC_END__;
4047                 return WIFI_DIRECT_ERROR_NOT_INITIALIZED;
4048         }
4049
4050         if (!mac_address || !type) {
4051                 WDC_LOGE("NULL Param!");
4052                 __WDC_LOG_FUNC_END__;
4053                 return WIFI_DIRECT_ERROR_INVALID_PARAMETER;
4054         }
4055
4056         params = g_variant_new("(s)", mac_address);
4057         reply = wifi_direct_dbus_method_call_sync(WFD_MANAGER_DISPLAY_INTERFACE,
4058                                           "GetPeerType",
4059                                           params,
4060                                           &error);
4061         if (error != NULL) {
4062                 WDC_LOGE("wifi_direct_dbus_method_call_sync() failed."
4063                                 "error [%d: %s]", error->code, error->message);
4064                 g_error_free(error);
4065                 __WDC_LOG_FUNC_END__;
4066                 return WIFI_DIRECT_ERROR_OPERATION_FAILED;
4067         }
4068
4069         g_variant_get(reply, "(ii)", &ret, &val);
4070         *type = val;
4071         g_variant_unref(reply);
4072
4073         WDC_LOGD("%s() return : [%d]", __func__, ret);
4074         __WDC_LOG_FUNC_END__;
4075         return ret;
4076 #else /* TIZEN_FEATURE_WIFI_DISPLAY */
4077         return WIFI_DIRECT_ERROR_NOT_SUPPORTED;
4078 #endif /* TIZEN_FEATURE_WIFI_DISPLAY */
4079 }
4080
4081 int wifi_direct_get_peer_display_availability(char *mac_address, bool *availability)
4082 {
4083         __WDC_LOG_FUNC_START__;
4084 #ifdef TIZEN_FEATURE_WIFI_DISPLAY
4085
4086         CHECK_FEATURE_SUPPORTED(WIFIDIRECT_DISPLAY_FEATURE);
4087
4088         GError* error = NULL;
4089         GVariant *reply = NULL;
4090         GVariant *params = NULL;
4091         int val = 0;
4092         int ret = WIFI_DIRECT_ERROR_NONE;
4093
4094         if (g_client_info.is_registered == false) {
4095                 WDC_LOGE("Client is NOT registered");
4096                 __WDC_LOG_FUNC_END__;
4097                 return WIFI_DIRECT_ERROR_NOT_INITIALIZED;
4098         }
4099
4100         if (!mac_address || !availability) {
4101                 WDC_LOGE("NULL Param!");
4102                 __WDC_LOG_FUNC_END__;
4103                 return WIFI_DIRECT_ERROR_INVALID_PARAMETER;
4104         }
4105
4106         params = g_variant_new("(s)", mac_address);
4107         reply = wifi_direct_dbus_method_call_sync(WFD_MANAGER_DISPLAY_INTERFACE,
4108                                           "GetPeerAvailability",
4109                                           params,
4110                                           &error);
4111         if (error != NULL) {
4112                 WDC_LOGE("wifi_direct_dbus_method_call_sync() failed."
4113                                 "error [%d: %s]", error->code, error->message);
4114                 g_error_free(error);
4115                 __WDC_LOG_FUNC_END__;
4116                 return WIFI_DIRECT_ERROR_OPERATION_FAILED;
4117         }
4118
4119         g_variant_get(reply, "(ii)", &ret, &val);
4120         *availability = val;
4121         g_variant_unref(reply);
4122
4123         WDC_LOGD("%s() return : [%d]", __func__, ret);
4124         __WDC_LOG_FUNC_END__;
4125         return ret;
4126 #else /* TIZEN_FEATURE_WIFI_DISPLAY */
4127         return WIFI_DIRECT_ERROR_NOT_SUPPORTED;
4128 #endif /* TIZEN_FEATURE_WIFI_DISPLAY */
4129 }
4130
4131 int wifi_direct_get_peer_display_hdcp(char *mac_address, int *hdcp)
4132 {
4133         __WDC_LOG_FUNC_START__;
4134 #ifdef TIZEN_FEATURE_WIFI_DISPLAY
4135
4136         CHECK_FEATURE_SUPPORTED(WIFIDIRECT_DISPLAY_FEATURE);
4137
4138         GError* error = NULL;
4139         GVariant *reply = NULL;
4140         GVariant *params = NULL;
4141         int val = 0;
4142         int ret = WIFI_DIRECT_ERROR_NONE;
4143
4144         if (g_client_info.is_registered == false) {
4145                 WDC_LOGE("Client is NOT registered");
4146                 __WDC_LOG_FUNC_END__;
4147                 return WIFI_DIRECT_ERROR_NOT_INITIALIZED;
4148         }
4149
4150         if (!mac_address || !hdcp) {
4151                 WDC_LOGE("NULL Param!");
4152                 __WDC_LOG_FUNC_END__;
4153                 return WIFI_DIRECT_ERROR_INVALID_PARAMETER;
4154         }
4155
4156         params = g_variant_new("(s)", mac_address);
4157         reply = wifi_direct_dbus_method_call_sync(WFD_MANAGER_DISPLAY_INTERFACE,
4158                                           "GetPeerHdcp",
4159                                           params,
4160                                           &error);
4161         if (error != NULL) {
4162                 WDC_LOGE("wifi_direct_dbus_method_call_sync() failed."
4163                                 "error [%d: %s]", error->code, error->message);
4164                 g_error_free(error);
4165                 __WDC_LOG_FUNC_END__;
4166                 return WIFI_DIRECT_ERROR_OPERATION_FAILED;
4167         }
4168
4169         g_variant_get(reply, "(ii)", &ret, &val);
4170         *hdcp = val;
4171         g_variant_unref(reply);
4172
4173         WDC_LOGD("%s() return : [%d]", __func__, ret);
4174         __WDC_LOG_FUNC_END__;
4175         return ret;
4176 #else /* TIZEN_FEATURE_WIFI_DISPLAY */
4177         return WIFI_DIRECT_ERROR_NOT_SUPPORTED;
4178 #endif /* TIZEN_FEATURE_WIFI_DISPLAY */
4179 }
4180
4181 int wifi_direct_get_peer_display_port(char *mac_address, int *port)
4182 {
4183         __WDC_LOG_FUNC_START__;
4184 #ifdef TIZEN_FEATURE_WIFI_DISPLAY
4185
4186         CHECK_FEATURE_SUPPORTED(WIFIDIRECT_DISPLAY_FEATURE);
4187
4188         GError* error = NULL;
4189         GVariant *reply = NULL;
4190         GVariant *params = NULL;
4191         int val = 0;
4192         int ret = WIFI_DIRECT_ERROR_NONE;
4193
4194         if (g_client_info.is_registered == false) {
4195                 WDC_LOGE("Client is NOT registered");
4196                 __WDC_LOG_FUNC_END__;
4197                 return WIFI_DIRECT_ERROR_NOT_INITIALIZED;
4198         }
4199
4200         if (!mac_address || !port) {
4201                 WDC_LOGE("NULL Param!");
4202                 __WDC_LOG_FUNC_END__;
4203                 return WIFI_DIRECT_ERROR_INVALID_PARAMETER;
4204         }
4205
4206         params = g_variant_new("(s)", mac_address);
4207         reply = wifi_direct_dbus_method_call_sync(WFD_MANAGER_DISPLAY_INTERFACE,
4208                                           "GetPeerPort",
4209                                           params,
4210                                           &error);
4211         if (error != NULL) {
4212                 WDC_LOGE("wifi_direct_dbus_method_call_sync() failed."
4213                                 "error [%d: %s]", error->code, error->message);
4214                 g_error_free(error);
4215                 __WDC_LOG_FUNC_END__;
4216                 return WIFI_DIRECT_ERROR_OPERATION_FAILED;
4217         }
4218
4219         g_variant_get(reply, "(ii)", &ret, &val);
4220         *port = val;
4221         g_variant_unref(reply);
4222
4223         WDC_LOGD("%s() return : [%d]", __func__, ret);
4224         __WDC_LOG_FUNC_END__;
4225         return ret;
4226 #else /* TIZEN_FEATURE_WIFI_DISPLAY */
4227         return WIFI_DIRECT_ERROR_NOT_SUPPORTED;
4228 #endif /* TIZEN_FEATURE_WIFI_DISPLAY */
4229 }
4230
4231 int wifi_direct_get_peer_display_throughput(char *mac_address, int *throughput)
4232 {
4233         __WDC_LOG_FUNC_START__;
4234 #ifdef TIZEN_FEATURE_WIFI_DISPLAY
4235
4236         CHECK_FEATURE_SUPPORTED(WIFIDIRECT_DISPLAY_FEATURE);
4237
4238         GError* error = NULL;
4239         GVariant *reply = NULL;
4240         GVariant *params = NULL;
4241         int val = 0;
4242         int ret = WIFI_DIRECT_ERROR_NONE;
4243
4244         if (g_client_info.is_registered == false) {
4245                 WDC_LOGE("Client is NOT registered");
4246                 __WDC_LOG_FUNC_END__;
4247                 return WIFI_DIRECT_ERROR_NOT_INITIALIZED;
4248         }
4249
4250         if (!mac_address || !throughput) {
4251                 WDC_LOGE("NULL Param!");
4252                 __WDC_LOG_FUNC_END__;
4253                 return WIFI_DIRECT_ERROR_INVALID_PARAMETER;
4254         }
4255
4256         params = g_variant_new("(s)", mac_address);
4257         reply = wifi_direct_dbus_method_call_sync(WFD_MANAGER_DISPLAY_INTERFACE,
4258                                           "GetPeerThroughput",
4259                                           params,
4260                                           &error);
4261         if (error != NULL) {
4262                 WDC_LOGE("wifi_direct_dbus_method_call_sync() failed."
4263                                 "error [%d: %s]", error->code, error->message);
4264                 g_error_free(error);
4265                 __WDC_LOG_FUNC_END__;
4266                 return WIFI_DIRECT_ERROR_OPERATION_FAILED;
4267         }
4268
4269         g_variant_get(reply, "(ii)", &ret, &val);
4270         *throughput = val;
4271         g_variant_unref(reply);
4272
4273         WDC_LOGD("%s() return : [%d]", __func__, ret);
4274         __WDC_LOG_FUNC_END__;
4275         return ret;
4276 #else /* TIZEN_FEATURE_WIFI_DISPLAY */
4277         return WIFI_DIRECT_ERROR_NOT_SUPPORTED;
4278 #endif /* TIZEN_FEATURE_WIFI_DISPLAY */
4279 }