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