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