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