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