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