[wifi-direct]: Added support of "wifi_direct_set_auto_group_removal()" CAPI
[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         int state = 0;
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_MANAGE_INTERFACE,
643                                                   "GetState", 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, "(ii)", &res, &state);
650         WDC_LOGD("State = [%d]", state);
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
2750 int wifi_direct_get_state(wifi_direct_state_e *state)
2751 {
2752         __WDC_LOG_FUNC_START__;
2753
2754         CHECK_FEATURE_SUPPORTED(WIFIDIRECT_FEATURE);
2755
2756         GError* error = NULL;
2757         GVariant *reply = NULL;
2758         int val = 0;
2759         int ret = WIFI_DIRECT_ERROR_NONE;
2760
2761         if (g_client_info.is_registered == false) {
2762                 WDC_LOGE("Client is NOT registered");
2763                 __WDC_LOG_FUNC_END__;
2764                 return WIFI_DIRECT_ERROR_NOT_INITIALIZED;
2765         }
2766
2767         if (!state) {
2768                 WDC_LOGE("Invalid Parameter");
2769                 __WDC_LOG_FUNC_END__;
2770                 return WIFI_DIRECT_ERROR_INVALID_PARAMETER;
2771         }
2772
2773         reply = wifi_direct_dbus_method_call_sync(WFD_MANAGER_MANAGE_INTERFACE,
2774                                                   "GetState", NULL, &error);
2775
2776         ret = __net_wifidirect_gerror_to_enum(error);
2777         if (ret != WIFI_DIRECT_ERROR_NONE)
2778                 return ret;
2779
2780         g_variant_get(reply, "(ii)", &ret, &val);
2781         *state = (wifi_direct_state_e) val;
2782         /* for CAPI : there is no WIFI_DIRECT_STATE_GROUP_OWNER type in CAPI */
2783         if (*state == WIFI_DIRECT_STATE_GROUP_OWNER)
2784                 *state = WIFI_DIRECT_STATE_CONNECTED;
2785
2786         g_variant_unref(reply);
2787
2788         WDC_LOGD("State = [%d]", *state);
2789         WDC_LOGD("%s() return : [%d]", __func__, ret);
2790         __WDC_LOG_FUNC_END__;
2791         return ret;
2792 }
2793
2794
2795 int wifi_direct_is_discoverable(bool* discoverable)
2796 {
2797         __WDC_LOG_FUNC_START__;
2798
2799         CHECK_FEATURE_SUPPORTED(WIFIDIRECT_FEATURE);
2800
2801         GError* error = NULL;
2802         GVariant *reply = NULL;
2803         int ret = WIFI_DIRECT_ERROR_NONE;
2804
2805         if (g_client_info.is_registered == false) {
2806                 WDC_LOGE("Client is NOT registered");
2807                 __WDC_LOG_FUNC_END__;
2808                 return WIFI_DIRECT_ERROR_NOT_INITIALIZED;
2809         }
2810
2811         if (!discoverable) {
2812                 WDC_LOGE("Invalid Parameter");
2813                 __WDC_LOG_FUNC_END__;
2814                 return WIFI_DIRECT_ERROR_INVALID_PARAMETER;
2815         }
2816
2817         reply = wifi_direct_dbus_method_call_sync(WFD_MANAGER_MANAGE_INTERFACE,
2818                                                   "IsDiscoverable", NULL, &error);
2819
2820         ret = __net_wifidirect_gerror_to_enum(error);
2821         if (ret != WIFI_DIRECT_ERROR_NONE)
2822                 return ret;
2823
2824         g_variant_get(reply, "(b)", discoverable);
2825         WDC_LOGD("Discoverable = [%s]", *discoverable ? "Yes" : "No");
2826
2827         WDC_LOGD("%s() SUCCESS", __func__);
2828         g_variant_unref(reply);
2829
2830         __WDC_LOG_FUNC_END__;
2831         return WIFI_DIRECT_ERROR_NONE;
2832 }
2833
2834 int wifi_direct_is_listening_only(bool* listen_only)
2835 {
2836         __WDC_LOG_FUNC_START__;
2837
2838         CHECK_FEATURE_SUPPORTED(WIFIDIRECT_FEATURE);
2839
2840         GError* error = NULL;
2841         GVariant *reply = NULL;
2842         int ret = WIFI_DIRECT_ERROR_NONE;
2843
2844         if (g_client_info.is_registered == false) {
2845                 WDC_LOGE("Client is NOT registered");
2846                 __WDC_LOG_FUNC_END__;
2847                 return WIFI_DIRECT_ERROR_NOT_INITIALIZED;
2848         }
2849
2850         if (!listen_only) {
2851                 WDC_LOGE("Invalid Parameter");
2852                 __WDC_LOG_FUNC_END__;
2853                 return WIFI_DIRECT_ERROR_INVALID_PARAMETER;
2854         }
2855
2856         reply = wifi_direct_dbus_method_call_sync(WFD_MANAGER_MANAGE_INTERFACE,
2857                                                   "IsListeningOnly", NULL, &error);
2858
2859         ret = __net_wifidirect_gerror_to_enum(error);
2860         if (ret != WIFI_DIRECT_ERROR_NONE)
2861                 return ret;
2862
2863         g_variant_get(reply, "(b)", listen_only);
2864
2865         WDC_LOGD("Is listen only = [%s]", *listen_only ? "Yes" : "No");
2866         WDC_LOGD("%s() SUCCESS", __func__);
2867         g_variant_unref(reply);
2868
2869         __WDC_LOG_FUNC_END__;
2870         return WIFI_DIRECT_ERROR_NONE;
2871 }
2872
2873
2874 int wifi_direct_get_primary_device_type(wifi_direct_primary_device_type_e* type)
2875 {
2876         __WDC_LOG_FUNC_START__;
2877
2878         CHECK_FEATURE_SUPPORTED(WIFIDIRECT_FEATURE);
2879
2880         if (!type) {
2881                 WDC_LOGE("NULL Param [type]!");
2882                 __WDC_LOG_FUNC_END__;
2883                 return WIFI_DIRECT_ERROR_INVALID_PARAMETER;
2884         }
2885
2886         if (g_client_info.is_registered == false) {
2887                 WDC_LOGE("Client is NOT registered");
2888                 __WDC_LOG_FUNC_END__;
2889                 return WIFI_DIRECT_ERROR_NOT_INITIALIZED;
2890         }
2891
2892 #ifdef TIZEN_TV
2893         WDC_LOGD("Current primary_dev_type [%d]", WIFI_DIRECT_PRIMARY_DEVICE_TYPE_DISPLAY);
2894         *type = WIFI_DIRECT_PRIMARY_DEVICE_TYPE_DISPLAY;
2895 #else /* TIZEN_TV */
2896         WDC_LOGD("Current primary_dev_type [%d]", WIFI_DIRECT_PRIMARY_DEVICE_TYPE_TELEPHONE);
2897         *type = WIFI_DIRECT_PRIMARY_DEVICE_TYPE_TELEPHONE;
2898 #endif /* TIZEN_TV */
2899
2900         __WDC_LOG_FUNC_END__;
2901         return WIFI_DIRECT_ERROR_NONE;
2902 }
2903
2904 int wifi_direct_get_secondary_device_type(wifi_direct_secondary_device_type_e* type)
2905 {
2906         __WDC_LOG_FUNC_START__;
2907
2908         CHECK_FEATURE_SUPPORTED(WIFIDIRECT_FEATURE);
2909
2910         if (g_client_info.is_registered == false) {
2911                 WDC_LOGE("Client is NOT registered");
2912                 __WDC_LOG_FUNC_END__;
2913                 return WIFI_DIRECT_ERROR_NOT_INITIALIZED;
2914         }
2915
2916         if (NULL == type) {
2917                 WDC_LOGE("NULL Param [type]!");
2918                 __WDC_LOG_FUNC_END__;
2919                 return WIFI_DIRECT_ERROR_INVALID_PARAMETER;
2920         }
2921
2922 #ifdef TIZEN_TV
2923         WDC_LOGD("Current second_dev_type [%d]", WIFI_DIRECT_SECONDARY_DEVICE_TYPE_DISPLAY_TV);
2924         *type = WIFI_DIRECT_SECONDARY_DEVICE_TYPE_DISPLAY_TV;
2925 #else /* TIZEN_TV */
2926         WDC_LOGD("Current second_dev_type [%d]", WIFI_DIRECT_SECONDARY_DEVICE_TYPE_TELEPHONE_SMARTPHONE_DUAL);
2927         *type = WIFI_DIRECT_SECONDARY_DEVICE_TYPE_TELEPHONE_SMARTPHONE_DUAL;    /* smart phone dual mode (wifi and cellular) */
2928 #endif /* TIZEN_TV */
2929
2930         __WDC_LOG_FUNC_END__;
2931         return WIFI_DIRECT_ERROR_NONE;
2932 }
2933
2934 int wifi_direct_set_autoconnection_mode(bool mode)
2935 {
2936         __WDC_LOG_FUNC_START__;
2937
2938         CHECK_FEATURE_SUPPORTED(WIFIDIRECT_FEATURE);
2939
2940         GError* error = NULL;
2941         GVariant *reply = NULL;
2942         GVariant *params = NULL;
2943         int ret = WIFI_DIRECT_ERROR_NONE;
2944
2945         if (g_client_info.is_registered == false) {
2946                 WDC_LOGE("Client is NOT registered");
2947                 __WDC_LOG_FUNC_END__;
2948                 return WIFI_DIRECT_ERROR_NOT_INITIALIZED;
2949         }
2950
2951         params = g_variant_new("(b)", mode);
2952         reply = wifi_direct_dbus_method_call_sync(WFD_MANAGER_CONFIG_INTERFACE,
2953                                           "SetAutoConnectionMode",
2954                                           params,
2955                                           &error);
2956
2957         ret = __net_wifidirect_gerror_to_enum(error);
2958         if (ret == WIFI_DIRECT_ERROR_NONE) {
2959                 g_variant_get(reply, "(i)", &ret);
2960                 g_variant_unref(reply);
2961         }
2962
2963         WDC_LOGD("%s() return : [%d]", __func__, ret);
2964         __WDC_LOG_FUNC_END__;
2965         return ret;
2966 }
2967
2968 int wifi_direct_is_autoconnection_mode(bool *mode)
2969 {
2970         __WDC_LOG_FUNC_START__;
2971
2972         CHECK_FEATURE_SUPPORTED(WIFIDIRECT_FEATURE);
2973
2974         GError* error = NULL;
2975         GVariant *reply = NULL;
2976         bool val = FALSE;
2977         int ret = WIFI_DIRECT_ERROR_NONE;
2978
2979         if (g_client_info.is_registered == false) {
2980                 WDC_LOGE("Client is NOT registered");
2981                 __WDC_LOG_FUNC_END__;
2982                 return WIFI_DIRECT_ERROR_NOT_INITIALIZED;
2983         }
2984
2985         if (!mode) {
2986                 WDC_LOGE("NULL Param [mode]!");
2987                 __WDC_LOG_FUNC_END__;
2988                 return WIFI_DIRECT_ERROR_INVALID_PARAMETER;
2989         }
2990
2991         reply = wifi_direct_dbus_method_call_sync(WFD_MANAGER_CONFIG_INTERFACE,
2992                                           "IsAutoConnectionMode",
2993                                           NULL,
2994                                           &error);
2995
2996         ret = __net_wifidirect_gerror_to_enum(error);
2997         if (ret != WIFI_DIRECT_ERROR_NONE)
2998                 return ret;
2999
3000         g_variant_get(reply, "(ib)", &ret, &val);
3001         *mode = val;
3002         g_variant_unref(reply);
3003
3004         WDC_LOGD("%s() return : [%d]", __func__, ret);
3005         __WDC_LOG_FUNC_END__;
3006         return ret;
3007 }
3008
3009
3010 int wifi_direct_set_persistent_group_enabled(bool enabled)
3011 {
3012         __WDC_LOG_FUNC_START__;
3013
3014         CHECK_FEATURE_SUPPORTED(WIFIDIRECT_FEATURE);
3015
3016         GError* error = NULL;
3017         GVariant *reply = NULL;
3018         GVariant *params = NULL;
3019         int ret = WIFI_DIRECT_ERROR_NONE;
3020
3021         if (g_client_info.is_registered == false) {
3022                 WDC_LOGE("Client is NOT registered");
3023                 __WDC_LOG_FUNC_END__;
3024                 return WIFI_DIRECT_ERROR_NOT_INITIALIZED;
3025         }
3026
3027         params = g_variant_new("(b)", enabled);
3028         reply = wifi_direct_dbus_method_call_sync(WFD_MANAGER_GROUP_INTERFACE,
3029                                           "SetPersistentGroupEnabled",
3030                                           params,
3031                                           &error);
3032
3033         ret = __net_wifidirect_gerror_to_enum(error);
3034         if (ret == WIFI_DIRECT_ERROR_NONE) {
3035                 g_variant_get(reply, "(i)", &ret);
3036                 g_variant_unref(reply);
3037         }
3038
3039         WDC_LOGD("%s() return : [%d]", __func__, ret);
3040
3041         __WDC_LOG_FUNC_END__;
3042         return WIFI_DIRECT_ERROR_NONE;
3043 }
3044
3045
3046 int wifi_direct_is_persistent_group_enabled(bool *enabled)
3047 {
3048         __WDC_LOG_FUNC_START__;
3049
3050         CHECK_FEATURE_SUPPORTED(WIFIDIRECT_FEATURE);
3051
3052         GError* error = NULL;
3053         GVariant *reply = NULL;
3054         int ret = WIFI_DIRECT_ERROR_NONE;
3055         bool val;
3056
3057         if (g_client_info.is_registered == false) {
3058                 WDC_LOGE("Client is NOT registered");
3059                 __WDC_LOG_FUNC_END__;
3060                 return WIFI_DIRECT_ERROR_NOT_INITIALIZED;
3061         }
3062
3063         if (!enabled) {
3064                 WDC_LOGE("NULL Param [enabled]!");
3065                 __WDC_LOG_FUNC_END__;
3066                 return WIFI_DIRECT_ERROR_INVALID_PARAMETER;
3067         }
3068
3069         reply = wifi_direct_dbus_method_call_sync(WFD_MANAGER_GROUP_INTERFACE,
3070                                           "IsPersistentGroupEnabled",
3071                                           NULL,
3072                                           &error);
3073
3074         ret = __net_wifidirect_gerror_to_enum(error);
3075         if (ret != WIFI_DIRECT_ERROR_NONE)
3076                 return ret;
3077
3078         WDC_LOGD("%s() SUCCESS", __func__);
3079         g_variant_get(reply, "(b)", &val);
3080         *enabled = val;
3081         g_variant_unref(reply);
3082
3083         __WDC_LOG_FUNC_END__;
3084         return WIFI_DIRECT_ERROR_NONE;
3085 }
3086
3087 int wifi_direct_foreach_persistent_groups(wifi_direct_persistent_group_cb cb,
3088                                         void* user_data)
3089 {
3090         __WDC_LOG_FUNC_START__;
3091
3092         CHECK_FEATURE_SUPPORTED(WIFIDIRECT_FEATURE);
3093
3094         GVariant *params = NULL;
3095         GError *error = NULL;
3096         GVariant *reply = NULL;
3097         GVariantIter *iter_groups = NULL;
3098         GVariantIter *iter_group = NULL;
3099         GVariant *var = NULL;
3100         gchar *key = NULL;
3101         int ret = WIFI_DIRECT_ERROR_NONE;
3102
3103         if (g_client_info.is_registered == false) {
3104                 WDC_LOGE("Client is NOT registered");
3105                 __WDC_LOG_FUNC_END__;
3106                 return WIFI_DIRECT_ERROR_NOT_INITIALIZED;
3107         }
3108
3109         if (!cb) {
3110                 WDC_LOGE("NULL Param [callback]!");
3111                 __WDC_LOG_FUNC_END__;
3112                 return WIFI_DIRECT_ERROR_INVALID_PARAMETER;
3113         }
3114
3115         reply = wifi_direct_dbus_method_call_sync(WFD_MANAGER_GROUP_INTERFACE,
3116                                                   "GetPersistentGroups", params, &error);
3117
3118         ret = __net_wifidirect_gerror_to_enum(error);
3119         if (ret != WIFI_DIRECT_ERROR_NONE)
3120                 return ret;
3121
3122         g_variant_get(reply, "(iaa{sv})", &ret, &iter_groups);
3123         if (ret != WIFI_DIRECT_ERROR_NONE) {
3124                 __WDC_LOG_FUNC_END__;
3125                 return WIFI_DIRECT_ERROR_OPERATION_FAILED;
3126         }
3127
3128         WDC_LOGD("wifi_direct_foreach_persistent_groups() SUCCESS");
3129 //LCOV_EXCL_START
3130         while (g_variant_iter_loop(iter_groups, "a{sv}", &iter_group)) {
3131                 const char *ssid = NULL;
3132                 char *go_mac_address = NULL;
3133
3134                 while (g_variant_iter_loop(iter_group, "{sv}", &key, &var)) {
3135                         if (!g_strcmp0(key, "SSID")) {
3136                                 g_variant_get(var, "&s", &ssid);
3137
3138                         } else if (!g_strcmp0(key, "GOMacAddress")) {
3139                                 unsigned char mac_address[MACADDR_LEN] = {0, };
3140
3141                                 wifi_direct_dbus_unpack_ay(mac_address, var, MACADDR_LEN);
3142                                 go_mac_address = (char*) g_try_malloc0(MACSTR_LEN);
3143                                 if (go_mac_address)
3144                                         g_snprintf(go_mac_address, MACSTR_LEN, MACSTR, MAC2STR(mac_address));
3145
3146                         } else {
3147                                 ;/* Do Nothing */
3148                         }
3149                 }
3150
3151                 ret = cb(go_mac_address, ssid, user_data);
3152                 g_free(go_mac_address);
3153                 go_mac_address = NULL;
3154                 if (!ret) {
3155                         g_variant_iter_free(iter_group);
3156                         break;
3157                 }
3158         }
3159 //LCOV_EXCL_STOP
3160         g_variant_iter_free(iter_groups);
3161         __WDC_LOG_FUNC_END__;
3162         return WIFI_DIRECT_ERROR_NONE;
3163 }
3164
3165 //LCOV_EXCL_START
3166 int wifi_direct_remove_persistent_group(char *mac_address, const char *ssid)
3167 {
3168         __WDC_LOG_FUNC_START__;
3169
3170         CHECK_FEATURE_SUPPORTED(WIFIDIRECT_FEATURE);
3171
3172         GError* error = NULL;
3173         GVariant *reply = NULL;
3174         GVariant *params = NULL;
3175         int ret = WIFI_DIRECT_ERROR_NONE;
3176
3177         if (g_client_info.is_registered == false) {
3178                 WDC_LOGE("Client is NOT registered");
3179                 __WDC_LOG_FUNC_END__;
3180                 return WIFI_DIRECT_ERROR_NOT_INITIALIZED;
3181         }
3182
3183         if (!mac_address || !ssid) {
3184                 WDC_LOGE("NULL Param");
3185                 __WDC_LOG_FUNC_END__;
3186                 return WIFI_DIRECT_ERROR_INVALID_PARAMETER;
3187         }
3188
3189         params = g_variant_new("(ss)", mac_address, ssid);
3190         reply = wifi_direct_dbus_method_call_sync(WFD_MANAGER_GROUP_INTERFACE,
3191                                           "RemovePersistentGroup",
3192                                           params,
3193                                           &error);
3194
3195         ret = __net_wifidirect_gerror_to_enum(error);
3196         if (ret == WIFI_DIRECT_ERROR_NONE) {
3197                 g_variant_get(reply, "(i)", &ret);
3198                 g_variant_unref(reply);
3199         }
3200
3201         WDC_LOGD("%s() return : [%d]", __func__, ret);
3202
3203         __WDC_LOG_FUNC_END__;
3204         return WIFI_DIRECT_ERROR_NONE;
3205 }
3206 //LCOV_EXCL_STOP
3207
3208 int wifi_direct_start_service_discovery(char *mac_address,
3209                 wifi_direct_service_type_e type)
3210 {
3211 #ifdef TIZEN_FEATURE_SERVICE_DISCOVERY
3212         __WDC_LOG_FUNC_START__;
3213
3214         CHECK_FEATURE_SUPPORTED(WIFIDIRECT_SERVICE_DISCOVERY_FEATURE);
3215
3216 //LCOV_EXCL_START
3217
3218         GError* error = NULL;
3219         GVariant *reply = NULL;
3220         GVariant *params = NULL;
3221         int ret = WIFI_DIRECT_ERROR_NONE;
3222
3223         if (g_client_info.is_registered == false) {
3224                 WDC_LOGE("Client is NOT registered.");
3225                 __WDC_LOG_FUNC_END__;
3226                 return WIFI_DIRECT_ERROR_NOT_INITIALIZED;
3227         }
3228
3229         if (type >= WIFI_DIRECT_SERVICE_TYPE_ALL &&
3230                         type <= WIFI_DIRECT_SERVICE_TYPE_CONTACT_INFO) {
3231                 WDC_LOGD("Param service_type [%d]", type);
3232         } else {
3233                 WDC_LOGE("Invalid Param [type]!");
3234                 __WDC_LOG_FUNC_END__;
3235                 return WIFI_DIRECT_ERROR_INVALID_PARAMETER;
3236         }
3237
3238         if (mac_address)
3239                 params = g_variant_new("(is)", type, mac_address);
3240         else
3241                 params = g_variant_new("(is)", type, "00:00:00:00:00:00");
3242
3243         reply = wifi_direct_dbus_method_call_sync(WFD_MANAGER_SERVICE_INTERFACE,
3244                                                     "StartDiscovery",
3245                                                     params,
3246                                                     &error);
3247
3248         ret = __net_wifidirect_gerror_to_enum(error);
3249         if (ret == WIFI_DIRECT_ERROR_NONE) {
3250                 g_variant_get(reply, "(i)", &ret);
3251                 g_variant_unref(reply);
3252         }
3253
3254         WDC_LOGD("%s() return : [%d]", __func__, ret);
3255         __WDC_LOG_FUNC_END__;
3256         return ret;
3257 //LCOV_EXCL_STOP
3258 #else /* TIZEN_FEATURE_SERVICE_DISCOVERY */
3259         return WIFI_DIRECT_ERROR_NOT_SUPPORTED;
3260 #endif /* TIZEN_FEATURE_SERVICE_DISCOVERY */
3261 }
3262
3263
3264 int wifi_direct_cancel_service_discovery(char *mac_address,
3265                 wifi_direct_service_type_e type)
3266 {
3267 #ifdef TIZEN_FEATURE_SERVICE_DISCOVERY
3268         __WDC_LOG_FUNC_START__;
3269
3270         CHECK_FEATURE_SUPPORTED(WIFIDIRECT_SERVICE_DISCOVERY_FEATURE);
3271 //LCOV_EXCL_START
3272         GError* error = NULL;
3273         GVariant *reply = NULL;
3274         GVariant *params = NULL;
3275         int ret = WIFI_DIRECT_ERROR_NONE;
3276
3277         if (g_client_info.is_registered == false) {
3278                 WDC_LOGE("Client is NOT registered.");
3279                 __WDC_LOG_FUNC_END__;
3280                 return WIFI_DIRECT_ERROR_NOT_INITIALIZED;
3281         }
3282
3283         if (type >= WIFI_DIRECT_SERVICE_TYPE_ALL &&
3284                         type <= WIFI_DIRECT_SERVICE_TYPE_CONTACT_INFO) {
3285                 WDC_LOGD("Param service_type [%d]", type);
3286         } else {
3287                 WDC_LOGE("Invalid Param [type]!");
3288                 __WDC_LOG_FUNC_END__;
3289                 return WIFI_DIRECT_ERROR_INVALID_PARAMETER;
3290         }
3291
3292         if (mac_address)
3293                 params = g_variant_new("(is)", type, mac_address);
3294         else
3295                 params = g_variant_new("(is)", type, "00:00:00:00:00:00");
3296
3297         reply = wifi_direct_dbus_method_call_sync(WFD_MANAGER_SERVICE_INTERFACE,
3298                                                     "StopDiscovery",
3299                                                     params,
3300                                                     &error);
3301
3302         ret = __net_wifidirect_gerror_to_enum(error);
3303         if (ret == WIFI_DIRECT_ERROR_NONE) {
3304                 g_variant_get(reply, "(i)", &ret);
3305                 g_variant_unref(reply);
3306         }
3307
3308         WDC_LOGD("%s() return : [%d]", __func__, ret);
3309         __WDC_LOG_FUNC_END__;
3310         return ret;
3311 //LCOV_EXCL_STOP
3312 #else /* TIZEN_FEATURE_SERVICE_DISCOVERY */
3313         return WIFI_DIRECT_ERROR_NOT_SUPPORTED;
3314 #endif /* TIZEN_FEATURE_SERVICE_DISCOVERY */
3315 }
3316
3317 int wifi_direct_register_service(wifi_direct_service_type_e type, char *info1, char *info2, unsigned int *service_id)
3318 {
3319 #ifdef TIZEN_FEATURE_SERVICE_DISCOVERY
3320         __WDC_LOG_FUNC_START__;
3321
3322         CHECK_FEATURE_SUPPORTED(WIFIDIRECT_SERVICE_DISCOVERY_FEATURE);
3323 //LCOV_EXCL_START
3324         GError* error = NULL;
3325         GVariant *reply = NULL;
3326         GVariant *params = NULL;
3327         char *buf = NULL;
3328         int ret = WIFI_DIRECT_ERROR_NONE;
3329         int len = 0;
3330
3331         if (g_client_info.is_registered == false) {
3332                 WDC_LOGE("Client is NOT registered.");
3333                 __WDC_LOG_FUNC_END__;
3334                 return WIFI_DIRECT_ERROR_NOT_INITIALIZED;
3335         }
3336
3337         if (!info1 || !info2) {
3338                 WDC_LOGE("info1 or info2 is NULL");
3339                 __WDC_LOG_FUNC_END__;
3340                 return WIFI_DIRECT_ERROR_INVALID_PARAMETER;
3341         }
3342
3343         if (type < WIFI_DIRECT_SERVICE_TYPE_ALL ||
3344                         type > WIFI_DIRECT_SERVICE_TYPE_VENDOR) {
3345                 WDC_LOGE("Invalid Param [type]!");
3346                 __WDC_LOG_FUNC_END__;
3347                 return WIFI_DIRECT_ERROR_INVALID_PARAMETER;
3348         }
3349
3350         if (!service_id) {
3351                 WDC_LOGE("Invalid Param [service_id]!");
3352                 __WDC_LOG_FUNC_END__;
3353                 return WIFI_DIRECT_ERROR_INVALID_PARAMETER;
3354         }
3355
3356         WDC_LOGD("Service type [%d]", type);
3357
3358         len = strlen(info1) + strlen(info2) + 2;
3359         WDC_LOGD("info [%s|%s], len [%d]", info1, info2, len);
3360
3361         buf = g_try_malloc0(len);
3362         if (NULL == buf) {
3363                 WDC_LOGE("Failed to allocate memory for buf");
3364                 return WIFI_DIRECT_ERROR_OUT_OF_MEMORY;
3365         }
3366
3367         g_snprintf(buf, len, "%s|%s", info1, info2);
3368
3369         params = g_variant_new("(is)", type, buf);
3370         reply = wifi_direct_dbus_method_call_sync(WFD_MANAGER_SERVICE_INTERFACE,
3371                                                     "Register",
3372                                                     params,
3373                                                     &error);
3374
3375         ret = __net_wifidirect_gerror_to_enum(error);
3376         if (ret != WIFI_DIRECT_ERROR_NONE) {
3377                 g_free(buf);
3378                 return ret;
3379         }
3380
3381         g_variant_get(reply, "(ii)", &ret, service_id);
3382         g_variant_unref(reply);
3383         g_free(buf);
3384
3385         WDC_LOGD("%s() return : [%d]", __func__, ret);
3386         __WDC_LOG_FUNC_END__;
3387         return ret;
3388 //LCOV_EXCL_STOP
3389 #else /* TIZEN_FEATURE_SERVICE_DISCOVERY */
3390         return WIFI_DIRECT_ERROR_NOT_SUPPORTED;
3391 #endif /* TIZEN_FEATURE_SERVICE_DISCOVERY */
3392 }
3393
3394 int wifi_direct_deregister_service(unsigned int service_id)
3395 {
3396 #ifdef TIZEN_FEATURE_SERVICE_DISCOVERY
3397         __WDC_LOG_FUNC_START__;
3398
3399         CHECK_FEATURE_SUPPORTED(WIFIDIRECT_SERVICE_DISCOVERY_FEATURE);
3400 //LCOV_EXCL_START
3401         GError* error = NULL;
3402         GVariant *reply = NULL;
3403         GVariant *params = NULL;
3404         int ret = WIFI_DIRECT_ERROR_NONE;
3405
3406         if (g_client_info.is_registered == false) {
3407                 WDC_LOGE("Client is NOT registered.");
3408                 __WDC_LOG_FUNC_END__;
3409                 return WIFI_DIRECT_ERROR_NOT_INITIALIZED;
3410         }
3411
3412         params = g_variant_new("(i)", service_id);
3413         reply = wifi_direct_dbus_method_call_sync(WFD_MANAGER_SERVICE_INTERFACE,
3414                                                     "Deregister",
3415                                                     params,
3416                                                     &error);
3417
3418         ret = __net_wifidirect_gerror_to_enum(error);
3419         if (ret == WIFI_DIRECT_ERROR_NONE) {
3420                 g_variant_get(reply, "(i)", &ret);
3421                 g_variant_unref(reply);
3422         }
3423
3424         WDC_LOGD("%s() return : [%d]", __func__, ret);
3425         __WDC_LOG_FUNC_END__;
3426         return ret;
3427 //LCOV_EXCL_STOP
3428 #else /* TIZEN_FEATURE_SERVICE_DISCOVERY */
3429         return WIFI_DIRECT_ERROR_NOT_SUPPORTED;
3430 #endif /* TIZEN_FEATURE_SERVICE_DISCOVERY */
3431 }
3432
3433 int wifi_direct_init_miracast(bool enable)
3434 {
3435         __WDC_LOG_FUNC_START__;
3436         int ret = WIFI_DIRECT_ERROR_NONE;
3437
3438         if (enable)
3439                 ret = wifi_direct_init_display();
3440         else
3441                 ret = wifi_direct_deinit_display();
3442
3443         __WDC_LOG_FUNC_END__;
3444         return ret;
3445 }
3446
3447 int wifi_direct_get_peer_info(char* mac_address, wifi_direct_discovered_peer_info_s** peer_info)
3448 {
3449         __WDC_LOG_FUNC_START__;
3450
3451         CHECK_FEATURE_SUPPORTED(WIFIDIRECT_FEATURE);
3452
3453         GVariant *params = NULL;
3454         GError *error = NULL;
3455         GVariant *reply = NULL;
3456         GVariantIter *iter_peer = NULL;
3457         GVariant *var = NULL;
3458         gchar *key = NULL;
3459         int ret = WIFI_DIRECT_ERROR_NONE;
3460
3461         if (g_client_info.is_registered == false) {
3462                 WDC_LOGE("Client is NOT registered");
3463                 __WDC_LOG_FUNC_END__;
3464                 return WIFI_DIRECT_ERROR_NOT_INITIALIZED;
3465         }
3466
3467         if (!mac_address) {
3468                 WDC_LOGE("mac_addr is NULL");
3469                 __WDC_LOG_FUNC_END__;
3470                 return WIFI_DIRECT_ERROR_INVALID_PARAMETER;
3471         }
3472
3473         if (!peer_info) {
3474                 WDC_LOGE("peer_info is NULL");
3475                 __WDC_LOG_FUNC_END__;
3476                 return WIFI_DIRECT_ERROR_INVALID_PARAMETER;
3477         }
3478 //LCOV_EXCL_START
3479         params = g_variant_new("(s)", mac_address);
3480         reply = wifi_direct_dbus_method_call_sync(WFD_MANAGER_MANAGE_INTERFACE,
3481                                                   "GetPeerInfo", params, &error);
3482
3483         ret = __net_wifidirect_gerror_to_enum(error);
3484         if (ret != WIFI_DIRECT_ERROR_NONE)
3485                 return ret;
3486
3487         g_variant_get(reply, "(ia{sv})", &ret, &iter_peer);
3488         if (ret != WIFI_DIRECT_ERROR_NONE) {
3489                 __WDC_LOG_FUNC_END__;
3490                 return WIFI_DIRECT_ERROR_OPERATION_FAILED;
3491         }
3492
3493         WDC_LOGD("wifi_direct_get_peer() SUCCESS");
3494
3495         wifi_direct_discovered_peer_info_s *peer = NULL;
3496
3497         peer = (wifi_direct_discovered_peer_info_s *) g_try_malloc0(sizeof(wifi_direct_discovered_peer_info_s));
3498         if (!peer) {
3499                 WDC_LOGE("Failed to allocate memory");
3500                 __WDC_LOG_FUNC_END__;
3501                 return WIFI_DIRECT_ERROR_OPERATION_FAILED;
3502         }
3503
3504         while (g_variant_iter_loop(iter_peer, "{sv}", &key, &var)) {
3505                 if (!g_strcmp0(key, "DeviceName")) {
3506                         const char *device_name = NULL;
3507
3508                         g_variant_get(var, "&s", &device_name);
3509                         peer->device_name = g_strndup(device_name, WIFI_DIRECT_MAX_DEVICE_NAME_LEN+1);
3510
3511                 } else if (!g_strcmp0(key, "DeviceAddress")) {
3512                         unsigned char mac_address[MACADDR_LEN] = {0, };
3513
3514                         wifi_direct_dbus_unpack_ay(mac_address, var, MACADDR_LEN);
3515                         peer->mac_address = (char*) g_try_malloc0(MACSTR_LEN);
3516                         if (peer->mac_address)
3517                                 g_snprintf(peer->mac_address, MACSTR_LEN, MACSTR, MAC2STR(mac_address));
3518
3519                 } else if (!g_strcmp0(key, "InterfaceAddress")) {
3520                         unsigned char intf_address[MACADDR_LEN] = {0, };
3521
3522                         wifi_direct_dbus_unpack_ay(intf_address, var, MACADDR_LEN);
3523                         peer->interface_address = (char*) g_try_malloc0(MACSTR_LEN);
3524                         if (peer->interface_address)
3525                                 g_snprintf(peer->interface_address, MACSTR_LEN, MACSTR, MAC2STR(intf_address));
3526
3527                 } else if (!g_strcmp0(key, "Channel")) {
3528                         peer->channel = g_variant_get_uint16(var);
3529
3530                 } else if (!g_strcmp0(key, "IsGroupOwner")) {
3531                         peer->is_group_owner = g_variant_get_boolean(var);
3532
3533                 } else if (!g_strcmp0(key, "IsPersistentGO")) {
3534                         peer->is_persistent_group_owner = g_variant_get_boolean(var);
3535
3536                 } else if (!g_strcmp0(key, "IsConnected")) {
3537                         peer->is_connected = g_variant_get_boolean(var);
3538
3539                 } else if (!g_strcmp0(key, "Category")) {
3540                         peer->primary_device_type = g_variant_get_uint16(var);
3541
3542                 } else if (!g_strcmp0(key, "SubCategory")) {
3543                         peer->secondary_device_type = g_variant_get_uint16(var);
3544
3545                 } else if (!g_strcmp0(key, "IsWfdDevice")) {
3546 #ifdef TIZEN_FEATURE_WIFI_DISPLAY
3547                         peer->is_miracast_device = g_variant_get_boolean(var);
3548 #endif /* TIZEN_FEATURE_WIFI_DISPLAY */
3549                 } else {
3550                         ;/* Do Nothing */
3551                 }
3552         }
3553
3554         *peer_info = peer;
3555
3556         g_variant_unref(reply);
3557 //LCOV_EXCL_STOP
3558         __WDC_LOG_FUNC_END__;
3559         return WIFI_DIRECT_ERROR_NONE;
3560 }
3561
3562 int wifi_direct_set_passphrase(const char *passphrase)
3563 {
3564         __WDC_LOG_FUNC_START__;
3565
3566         CHECK_FEATURE_SUPPORTED(WIFIDIRECT_FEATURE);
3567
3568         GError* error = NULL;
3569         GVariant *reply = NULL;
3570         GVariant *params = NULL;
3571         int ret = WIFI_DIRECT_ERROR_NONE;
3572
3573         if (g_client_info.is_registered == false) {
3574                 WDC_LOGE("Client is NOT registered.");
3575                 __WDC_LOG_FUNC_END__;
3576                 return WIFI_DIRECT_ERROR_NOT_INITIALIZED;
3577         }
3578
3579         if (!passphrase) {
3580                 WDC_LOGE("NULL Param [passphrase]!");
3581                 __WDC_LOG_FUNC_END__;
3582                 return WIFI_DIRECT_ERROR_INVALID_PARAMETER;
3583         }
3584         WDC_LOGD("passphrase = [%s]", passphrase);
3585
3586         params = g_variant_new("(s)", passphrase);
3587         reply = wifi_direct_dbus_method_call_sync(WFD_MANAGER_GROUP_INTERFACE,
3588                                           "SetPassphrase",
3589                                           params,
3590                                           &error);
3591
3592         ret = __net_wifidirect_gerror_to_enum(error);
3593         if (ret == WIFI_DIRECT_ERROR_NONE) {
3594                 g_variant_get(reply, "(i)", &ret);
3595                 g_variant_unref(reply);
3596         }
3597
3598         WDC_LOGD("%s() SUCCESS", __func__);
3599
3600         __WDC_LOG_FUNC_END__;
3601         return WIFI_DIRECT_ERROR_NONE;
3602 }
3603
3604 int wifi_direct_get_passphrase(char** passphrase)
3605 {
3606         __WDC_LOG_FUNC_START__;
3607
3608         CHECK_FEATURE_SUPPORTED(WIFIDIRECT_FEATURE);
3609
3610         GError* error = NULL;
3611         GVariant *reply = NULL;
3612         const char *val = NULL;
3613         int ret = WIFI_DIRECT_ERROR_NONE;
3614
3615         if (g_client_info.is_registered == false) {
3616                 WDC_LOGE("Client is NOT registered.");
3617                 __WDC_LOG_FUNC_END__;
3618                 return WIFI_DIRECT_ERROR_NOT_INITIALIZED;
3619         }
3620
3621         if (!passphrase) {
3622                 WDC_LOGE("NULL Param [passphrase]!");
3623                 __WDC_LOG_FUNC_END__;
3624                 return WIFI_DIRECT_ERROR_INVALID_PARAMETER;
3625         }
3626
3627         reply = wifi_direct_dbus_method_call_sync(WFD_MANAGER_GROUP_INTERFACE,
3628                                           "GetPassphrase",
3629                                           NULL,
3630                                           &error);
3631
3632         ret = __net_wifidirect_gerror_to_enum(error);
3633         if (ret != WIFI_DIRECT_ERROR_NONE)
3634                 return ret;
3635
3636         WDC_LOGD("%s() SUCCESS", __func__);
3637         g_variant_get(reply, "(i&s)", &ret, &val);
3638         *passphrase = g_strdup(val);
3639         g_variant_unref(reply);
3640
3641         WDC_LOGD("%s() return : [%d]", __func__, ret);
3642         __WDC_LOG_FUNC_END__;
3643         return ret;
3644 }
3645
3646 int wifi_direct_set_autoconnection_peer(char *mac_address)
3647 {
3648         __WDC_LOG_FUNC_START__;
3649
3650         CHECK_FEATURE_SUPPORTED(WIFIDIRECT_FEATURE);
3651
3652         GError* error = NULL;
3653         GVariant *reply = NULL;
3654         GVariant *params = NULL;
3655         int ret = WIFI_DIRECT_ERROR_NONE;
3656
3657         if (g_client_info.is_registered == false) {
3658                 WDC_LOGE("Client is NOT registered.");
3659                 __WDC_LOG_FUNC_END__;
3660                 return WIFI_DIRECT_ERROR_NOT_INITIALIZED;
3661         }
3662
3663         if (!mac_address) {
3664                 WDC_LOGE("NULL Param!");
3665                 __WDC_LOG_FUNC_END__;
3666                 return WIFI_DIRECT_ERROR_INVALID_PARAMETER;
3667         }
3668
3669         params = g_variant_new("(s)", mac_address);
3670         reply = wifi_direct_dbus_method_call_sync(WFD_MANAGER_CONFIG_INTERFACE,
3671                                           "SetAutoConnectionPeer",
3672                                           params,
3673                                           &error);
3674
3675         ret = __net_wifidirect_gerror_to_enum(error);
3676         if (ret == WIFI_DIRECT_ERROR_NONE) {
3677                 g_variant_get(reply, "(i)", &ret);
3678                 g_variant_unref(reply);
3679         }
3680
3681         WDC_LOGD("%s() return : [%d]", __func__, ret);
3682         __WDC_LOG_FUNC_END__;
3683         return ret;
3684 }
3685
3686 int wifi_direct_init_display(void)
3687 {
3688         __WDC_LOG_FUNC_START__;
3689 #ifdef TIZEN_FEATURE_WIFI_DISPLAY
3690
3691         CHECK_FEATURE_SUPPORTED(WIFIDIRECT_DISPLAY_FEATURE);
3692
3693         GError* error = NULL;
3694         GVariant *reply = NULL;
3695         int ret = WIFI_DIRECT_ERROR_NONE;
3696
3697         if (g_client_info.is_registered == false) {
3698                 WDC_LOGE("Client is NOT registered.");
3699                 __WDC_LOG_FUNC_END__;
3700                 return WIFI_DIRECT_ERROR_NOT_INITIALIZED;
3701         }
3702
3703         reply = wifi_direct_dbus_method_call_sync(WFD_MANAGER_DISPLAY_INTERFACE,
3704                                           "Init",
3705                                           NULL,
3706                                           &error);
3707
3708         ret = __net_wifidirect_gerror_to_enum(error);
3709         if (ret == WIFI_DIRECT_ERROR_NONE) {
3710                 g_variant_get(reply, "(i)", &ret);
3711                 g_variant_unref(reply);
3712         }
3713
3714         WDC_LOGD("%s() return : [%d]", __func__, ret);
3715         __WDC_LOG_FUNC_END__;
3716         return ret;
3717 #else /* TIZEN_FEATURE_WIFI_DISPLAY */
3718         return WIFI_DIRECT_ERROR_NOT_SUPPORTED;
3719 #endif /* TIZEN_FEATURE_WIFI_DISPLAY */
3720 }
3721
3722 int wifi_direct_deinit_display(void)
3723 {
3724         __WDC_LOG_FUNC_START__;
3725 #ifdef TIZEN_FEATURE_WIFI_DISPLAY
3726
3727         CHECK_FEATURE_SUPPORTED(WIFIDIRECT_DISPLAY_FEATURE);
3728
3729         GError* error = NULL;
3730         GVariant *reply = NULL;
3731         int ret = WIFI_DIRECT_ERROR_NONE;
3732
3733         if (g_client_info.is_registered == false) {
3734                 WDC_LOGE("Client is NOT registered");
3735                 __WDC_LOG_FUNC_END__;
3736                 return WIFI_DIRECT_ERROR_NOT_INITIALIZED;
3737         }
3738
3739         reply = wifi_direct_dbus_method_call_sync(WFD_MANAGER_DISPLAY_INTERFACE,
3740                                           "Deinit",
3741                                           NULL,
3742                                           &error);
3743
3744         ret = __net_wifidirect_gerror_to_enum(error);
3745         if (ret == WIFI_DIRECT_ERROR_NONE) {
3746                 g_variant_get(reply, "(i)", &ret);
3747                 g_variant_unref(reply);
3748         }
3749
3750         WDC_LOGD("%s() return : [%d]", __func__, ret);
3751         __WDC_LOG_FUNC_END__;
3752         return ret;
3753 #else /* TIZEN_FEATURE_WIFI_DISPLAY */
3754         return WIFI_DIRECT_ERROR_NOT_SUPPORTED;
3755 #endif /* TIZEN_FEATURE_WIFI_DISPLAY */
3756 }
3757
3758 int wifi_direct_set_display(wifi_direct_display_type_e type, int port, int hdcp)
3759 {
3760         __WDC_LOG_FUNC_START__;
3761 #ifdef TIZEN_FEATURE_WIFI_DISPLAY
3762
3763         CHECK_FEATURE_SUPPORTED(WIFIDIRECT_DISPLAY_FEATURE);
3764
3765         GError* error = NULL;
3766         GVariant *reply = NULL;
3767         GVariant *params = NULL;
3768         int ret = WIFI_DIRECT_ERROR_NONE;
3769
3770         if (g_client_info.is_registered == false) {
3771                 WDC_LOGE("Client is NOT registered");
3772                 __WDC_LOG_FUNC_END__;
3773                 return WIFI_DIRECT_ERROR_NOT_INITIALIZED;
3774         }
3775
3776         if (type < WIFI_DIRECT_DISPLAY_TYPE_SOURCE ||
3777                         type > WIFI_DIRECT_DISPLAY_TYPE_DUAL || port < 0 ||
3778                         hdcp < 0) {
3779                 WDC_LOGE("Invalid paramaeters passed type[%d], port[%d], hdcp[%d]!");
3780                 __WDC_LOG_FUNC_END__;
3781                 return WIFI_DIRECT_ERROR_INVALID_PARAMETER;
3782         }
3783
3784         params = g_variant_new("(iii)", type, port, hdcp);
3785         reply = wifi_direct_dbus_method_call_sync(WFD_MANAGER_DISPLAY_INTERFACE,
3786                                           "SetConfig",
3787                                           params,
3788                                           &error);
3789
3790         ret = __net_wifidirect_gerror_to_enum(error);
3791         if (ret == WIFI_DIRECT_ERROR_NONE) {
3792                 g_variant_get(reply, "(i)", &ret);
3793                 g_variant_unref(reply);
3794         }
3795
3796         WDC_LOGD("%s() return : [%d]", __func__, ret);
3797         __WDC_LOG_FUNC_END__;
3798         return ret;
3799 #else /* TIZEN_FEATURE_WIFI_DISPLAY */
3800         return WIFI_DIRECT_ERROR_NOT_SUPPORTED;
3801 #endif /* TIZEN_FEATURE_WIFI_DISPLAY */
3802 }
3803
3804 int wifi_direct_set_display_availability(bool availability)
3805 {
3806         __WDC_LOG_FUNC_START__;
3807 #ifdef TIZEN_FEATURE_WIFI_DISPLAY
3808
3809         CHECK_FEATURE_SUPPORTED(WIFIDIRECT_DISPLAY_FEATURE);
3810
3811         GError* error = NULL;
3812         GVariant *reply = NULL;
3813         GVariant *params = NULL;
3814         int ret = WIFI_DIRECT_ERROR_NONE;
3815
3816         if (g_client_info.is_registered == false) {
3817                 WDC_LOGE("Client is NOT registered.");
3818                 __WDC_LOG_FUNC_END__;
3819                 return WIFI_DIRECT_ERROR_NOT_INITIALIZED;
3820         }
3821
3822
3823         params = g_variant_new("(i)", availability);
3824         reply = wifi_direct_dbus_method_call_sync(WFD_MANAGER_DISPLAY_INTERFACE,
3825                                           "SetAvailiability",
3826                                           params,
3827                                           &error);
3828
3829         ret = __net_wifidirect_gerror_to_enum(error);
3830         if (ret == WIFI_DIRECT_ERROR_NONE) {
3831                 g_variant_get(reply, "(i)", &ret);
3832                 g_variant_unref(reply);
3833         }
3834
3835         WDC_LOGD("%s() return : [%d]", __func__, ret);
3836         __WDC_LOG_FUNC_END__;
3837         return ret;
3838 #else /* TIZEN_FEATURE_WIFI_DISPLAY */
3839         return WIFI_DIRECT_ERROR_NOT_SUPPORTED;
3840 #endif /* TIZEN_FEATURE_WIFI_DISPLAY */
3841 }
3842
3843 //LCOV_EXCL_START
3844 int wifi_direct_get_peer_display_type(char *mac_address, wifi_direct_display_type_e *type)
3845 {
3846         __WDC_LOG_FUNC_START__;
3847 #ifdef TIZEN_FEATURE_WIFI_DISPLAY
3848
3849         CHECK_FEATURE_SUPPORTED(WIFIDIRECT_DISPLAY_FEATURE);
3850
3851         GError* error = NULL;
3852         GVariant *reply = NULL;
3853         GVariant *params = NULL;
3854         int val = 0;
3855         int ret = WIFI_DIRECT_ERROR_NONE;
3856
3857         if (g_client_info.is_registered == false) {
3858                 WDC_LOGE("Client is NOT registered");
3859                 __WDC_LOG_FUNC_END__;
3860                 return WIFI_DIRECT_ERROR_NOT_INITIALIZED;
3861         }
3862
3863         if (!mac_address || !type) {
3864                 WDC_LOGE("NULL Param!");
3865                 __WDC_LOG_FUNC_END__;
3866                 return WIFI_DIRECT_ERROR_INVALID_PARAMETER;
3867         }
3868
3869         params = g_variant_new("(s)", mac_address);
3870         reply = wifi_direct_dbus_method_call_sync(WFD_MANAGER_DISPLAY_INTERFACE,
3871                                           "GetPeerType",
3872                                           params,
3873                                           &error);
3874
3875         ret = __net_wifidirect_gerror_to_enum(error);
3876         if (ret != WIFI_DIRECT_ERROR_NONE)
3877                 return ret;
3878
3879         g_variant_get(reply, "(ii)", &ret, &val);
3880         *type = val;
3881         g_variant_unref(reply);
3882
3883         WDC_LOGD("%s() return : [%d]", __func__, ret);
3884         __WDC_LOG_FUNC_END__;
3885         return ret;
3886 #else /* TIZEN_FEATURE_WIFI_DISPLAY */
3887         return WIFI_DIRECT_ERROR_NOT_SUPPORTED;
3888 #endif /* TIZEN_FEATURE_WIFI_DISPLAY */
3889 }
3890
3891 int wifi_direct_get_peer_display_availability(char *mac_address, bool *availability)
3892 {
3893         __WDC_LOG_FUNC_START__;
3894 #ifdef TIZEN_FEATURE_WIFI_DISPLAY
3895
3896         CHECK_FEATURE_SUPPORTED(WIFIDIRECT_DISPLAY_FEATURE);
3897
3898         GError* error = NULL;
3899         GVariant *reply = NULL;
3900         GVariant *params = NULL;
3901         int val = 0;
3902         int ret = WIFI_DIRECT_ERROR_NONE;
3903
3904         if (g_client_info.is_registered == false) {
3905                 WDC_LOGE("Client is NOT registered");
3906                 __WDC_LOG_FUNC_END__;
3907                 return WIFI_DIRECT_ERROR_NOT_INITIALIZED;
3908         }
3909
3910         if (!mac_address || !availability) {
3911                 WDC_LOGE("NULL Param!");
3912                 __WDC_LOG_FUNC_END__;
3913                 return WIFI_DIRECT_ERROR_INVALID_PARAMETER;
3914         }
3915
3916         params = g_variant_new("(s)", mac_address);
3917         reply = wifi_direct_dbus_method_call_sync(WFD_MANAGER_DISPLAY_INTERFACE,
3918                                           "GetPeerAvailability",
3919                                           params,
3920                                           &error);
3921
3922         ret = __net_wifidirect_gerror_to_enum(error);
3923         if (ret != WIFI_DIRECT_ERROR_NONE)
3924                 return ret;
3925
3926         g_variant_get(reply, "(ii)", &ret, &val);
3927         *availability = val;
3928         g_variant_unref(reply);
3929
3930         WDC_LOGD("%s() return : [%d]", __func__, ret);
3931         __WDC_LOG_FUNC_END__;
3932         return ret;
3933 #else /* TIZEN_FEATURE_WIFI_DISPLAY */
3934         return WIFI_DIRECT_ERROR_NOT_SUPPORTED;
3935 #endif /* TIZEN_FEATURE_WIFI_DISPLAY */
3936 }
3937
3938 int wifi_direct_get_peer_display_hdcp(char *mac_address, int *hdcp)
3939 {
3940         __WDC_LOG_FUNC_START__;
3941 #ifdef TIZEN_FEATURE_WIFI_DISPLAY
3942
3943         CHECK_FEATURE_SUPPORTED(WIFIDIRECT_DISPLAY_FEATURE);
3944
3945         GError* error = NULL;
3946         GVariant *reply = NULL;
3947         GVariant *params = NULL;
3948         int val = 0;
3949         int ret = WIFI_DIRECT_ERROR_NONE;
3950
3951         if (g_client_info.is_registered == false) {
3952                 WDC_LOGE("Client is NOT registered");
3953                 __WDC_LOG_FUNC_END__;
3954                 return WIFI_DIRECT_ERROR_NOT_INITIALIZED;
3955         }
3956
3957         if (!mac_address || !hdcp) {
3958                 WDC_LOGE("NULL Param!");
3959                 __WDC_LOG_FUNC_END__;
3960                 return WIFI_DIRECT_ERROR_INVALID_PARAMETER;
3961         }
3962
3963         params = g_variant_new("(s)", mac_address);
3964         reply = wifi_direct_dbus_method_call_sync(WFD_MANAGER_DISPLAY_INTERFACE,
3965                                           "GetPeerHdcp",
3966                                           params,
3967                                           &error);
3968
3969         ret = __net_wifidirect_gerror_to_enum(error);
3970         if (ret != WIFI_DIRECT_ERROR_NONE)
3971                 return ret;
3972
3973         g_variant_get(reply, "(ii)", &ret, &val);
3974         *hdcp = val;
3975         g_variant_unref(reply);
3976
3977         WDC_LOGD("%s() return : [%d]", __func__, ret);
3978         __WDC_LOG_FUNC_END__;
3979         return ret;
3980 #else /* TIZEN_FEATURE_WIFI_DISPLAY */
3981         return WIFI_DIRECT_ERROR_NOT_SUPPORTED;
3982 #endif /* TIZEN_FEATURE_WIFI_DISPLAY */
3983 }
3984
3985 int wifi_direct_get_peer_display_port(char *mac_address, int *port)
3986 {
3987         __WDC_LOG_FUNC_START__;
3988 #ifdef TIZEN_FEATURE_WIFI_DISPLAY
3989
3990         CHECK_FEATURE_SUPPORTED(WIFIDIRECT_DISPLAY_FEATURE);
3991
3992         GError* error = NULL;
3993         GVariant *reply = NULL;
3994         GVariant *params = NULL;
3995         int val = 0;
3996         int ret = WIFI_DIRECT_ERROR_NONE;
3997
3998         if (g_client_info.is_registered == false) {
3999                 WDC_LOGE("Client is NOT registered");
4000                 __WDC_LOG_FUNC_END__;
4001                 return WIFI_DIRECT_ERROR_NOT_INITIALIZED;
4002         }
4003
4004         if (!mac_address || !port) {
4005                 WDC_LOGE("NULL Param!");
4006                 __WDC_LOG_FUNC_END__;
4007                 return WIFI_DIRECT_ERROR_INVALID_PARAMETER;
4008         }
4009
4010         params = g_variant_new("(s)", mac_address);
4011         reply = wifi_direct_dbus_method_call_sync(WFD_MANAGER_DISPLAY_INTERFACE,
4012                                           "GetPeerPort",
4013                                           params,
4014                                           &error);
4015
4016         ret = __net_wifidirect_gerror_to_enum(error);
4017         if (ret != WIFI_DIRECT_ERROR_NONE)
4018                 return ret;
4019
4020         g_variant_get(reply, "(ii)", &ret, &val);
4021         *port = val;
4022         g_variant_unref(reply);
4023
4024         WDC_LOGD("%s() return : [%d]", __func__, ret);
4025         __WDC_LOG_FUNC_END__;
4026         return ret;
4027 #else /* TIZEN_FEATURE_WIFI_DISPLAY */
4028         return WIFI_DIRECT_ERROR_NOT_SUPPORTED;
4029 #endif /* TIZEN_FEATURE_WIFI_DISPLAY */
4030 }
4031
4032 int wifi_direct_get_peer_display_throughput(char *mac_address, int *throughput)
4033 {
4034         __WDC_LOG_FUNC_START__;
4035 #ifdef TIZEN_FEATURE_WIFI_DISPLAY
4036
4037         CHECK_FEATURE_SUPPORTED(WIFIDIRECT_DISPLAY_FEATURE);
4038
4039         GError* error = NULL;
4040         GVariant *reply = NULL;
4041         GVariant *params = NULL;
4042         int val = 0;
4043         int ret = WIFI_DIRECT_ERROR_NONE;
4044
4045         if (g_client_info.is_registered == false) {
4046                 WDC_LOGE("Client is NOT registered");
4047                 __WDC_LOG_FUNC_END__;
4048                 return WIFI_DIRECT_ERROR_NOT_INITIALIZED;
4049         }
4050
4051         if (!mac_address || !throughput) {
4052                 WDC_LOGE("NULL Param!");
4053                 __WDC_LOG_FUNC_END__;
4054                 return WIFI_DIRECT_ERROR_INVALID_PARAMETER;
4055         }
4056
4057         params = g_variant_new("(s)", mac_address);
4058         reply = wifi_direct_dbus_method_call_sync(WFD_MANAGER_DISPLAY_INTERFACE,
4059                                           "GetPeerThroughput",
4060                                           params,
4061                                           &error);
4062
4063         ret = __net_wifidirect_gerror_to_enum(error);
4064         if (ret != WIFI_DIRECT_ERROR_NONE)
4065                 return ret;
4066
4067         g_variant_get(reply, "(ii)", &ret, &val);
4068         *throughput = val;
4069         g_variant_unref(reply);
4070
4071         WDC_LOGD("%s() return : [%d]", __func__, ret);
4072         __WDC_LOG_FUNC_END__;
4073         return ret;
4074 #else /* TIZEN_FEATURE_WIFI_DISPLAY */
4075         return WIFI_DIRECT_ERROR_NOT_SUPPORTED;
4076 #endif /* TIZEN_FEATURE_WIFI_DISPLAY */
4077 }
4078
4079 int wifi_direct_set_session_timer(int seconds)
4080 {
4081         __WDC_LOG_FUNC_START__;
4082
4083         CHECK_FEATURE_SUPPORTED(WIFIDIRECT_FEATURE);
4084
4085         GError* error = NULL;
4086         GVariant *reply = NULL;
4087         GVariant *params = NULL;
4088         int ret = WIFI_DIRECT_ERROR_NONE;
4089
4090         if (g_client_info.is_registered == false) {
4091                 WDC_LOGE("Client is NOT registered.");
4092                 __WDC_LOG_FUNC_END__;
4093                 return WIFI_DIRECT_ERROR_NOT_INITIALIZED;
4094         }
4095         if (seconds < 0) {
4096                 WDC_LOGE("Negative Timer Value");
4097                 __WDC_LOG_FUNC_END__;
4098                 return WIFI_DIRECT_ERROR_INVALID_PARAMETER;
4099         }
4100
4101         WDC_LOGD("seconds = [%d]", seconds);
4102
4103         params = g_variant_new("(i)", seconds);
4104         reply = wifi_direct_dbus_method_call_sync(WFD_MANAGER_CONFIG_INTERFACE,
4105                                           "SetSessionTimer",
4106                                           params,
4107                                           &error);
4108
4109         ret = __net_wifidirect_gerror_to_enum(error);
4110         if(ret == WIFI_DIRECT_ERROR_NONE) {
4111                 g_variant_get(reply, "(i)", &ret);
4112                 g_variant_unref(reply);
4113         }
4114
4115         WDC_LOGD("%s() SUCCESS", __func__);
4116
4117         __WDC_LOG_FUNC_END__;
4118         return WIFI_DIRECT_ERROR_NONE;
4119
4120 }
4121
4122 int wifi_direct_get_session_timer(int *seconds)
4123 {
4124         __WDC_LOG_FUNC_START__;
4125
4126         CHECK_FEATURE_SUPPORTED(WIFIDIRECT_FEATURE);
4127
4128         GError* error = NULL;
4129         GVariant *reply = NULL;
4130         int val = 0;
4131         int ret = WIFI_DIRECT_ERROR_NONE;
4132
4133         if (g_client_info.is_registered == false) {
4134                 WDC_LOGE("Client is NOT registered");
4135                 __WDC_LOG_FUNC_END__;
4136                 return WIFI_DIRECT_ERROR_NOT_INITIALIZED;
4137         }
4138
4139         if (!seconds) {
4140                 WDC_LOGE("Invalid Parameter");
4141                 __WDC_LOG_FUNC_END__;
4142                 return WIFI_DIRECT_ERROR_INVALID_PARAMETER;
4143         }
4144
4145         reply = wifi_direct_dbus_method_call_sync(WFD_MANAGER_CONFIG_INTERFACE,
4146                                           "GetSessionTimer",
4147                                           NULL,
4148                                           &error);
4149
4150         ret = __net_wifidirect_gerror_to_enum(error);
4151         if (ret != WIFI_DIRECT_ERROR_NONE)
4152                 return ret;
4153
4154         g_variant_get(reply, "(ii)", &ret, &val);
4155         *seconds = val;
4156         g_variant_unref(reply);
4157
4158         WDC_LOGD("Session Timer = [%d] Seconds", *seconds);
4159         WDC_LOGD("%s() return : [%d]", __func__, ret);
4160
4161         __WDC_LOG_FUNC_END__;
4162         return ret;
4163 }
4164
4165 int wifi_direct_set_auto_group_removal(bool enable)
4166 {
4167         __WDC_LOG_FUNC_START__;
4168
4169         CHECK_FEATURE_SUPPORTED(WIFIDIRECT_FEATURE);
4170
4171         GError* error = NULL;
4172         GVariant *reply = NULL;
4173         GVariant *params = NULL;
4174         int ret = WIFI_DIRECT_ERROR_NONE;
4175
4176         if (g_client_info.is_registered == false) {
4177                 WDC_LOGE("Client is NOT registered");
4178                 __WDC_LOG_FUNC_END__;
4179                 return WIFI_DIRECT_ERROR_NOT_INITIALIZED;
4180         }
4181
4182         params = g_variant_new("(b)", enable);
4183         reply = wifi_direct_dbus_method_call_sync(WFD_MANAGER_CONFIG_INTERFACE,
4184                                           "SetAutoGroupRemoval",
4185                                           params,
4186                                           &error);
4187
4188         ret = __net_wifidirect_gerror_to_enum(error);
4189         if (ret == WIFI_DIRECT_ERROR_NONE) {
4190                 g_variant_get(reply, "(i)", &ret);
4191                 g_variant_unref(reply);
4192         }
4193
4194         WDC_LOGD("%s() return : [%d]", __func__, ret);
4195         __WDC_LOG_FUNC_END__;
4196         return ret;
4197 }
4198 //LCOV_EXCL_STOP