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