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