DLog macro is changed
[platform/core/connectivity/libwifi-direct.git] / src / wifi-direct-client-proxy.c
1 /*
2  * libwifi-direct
3  *
4  * Copyright (c) 2000 - 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 /*****************************************************************************
25  *      Standard headers
26  *****************************************************************************/
27 #define _GNU_SOURCE
28 #include <stdio.h>
29 #include <stdlib.h>
30 #include <stdbool.h>
31 #include <netdb.h>
32 #include <sys/socket.h>
33 #include <string.h>
34 #include <unistd.h>
35 #include <sys/un.h>
36 #include <fcntl.h>
37 #include <errno.h>
38 #include <sys/ioctl.h>
39 #include <signal.h>
40 #include <glib.h>
41 #include <linux/unistd.h>
42 #include <sys/poll.h>
43
44 #include <vconf.h>
45
46 /*****************************************************************************
47  *      Wi-Fi Direct Service headers
48  *****************************************************************************/
49 #include "wifi-direct.h"
50 #include "wifi-direct-client-proxy.h"
51 #include "wifi-direct-internal.h"
52
53 /*****************************************************************************
54  *      Macros and Typedefs
55  *****************************************************************************/
56
57
58 /*****************************************************************************
59  *      Global Variables
60  *****************************************************************************/
61 wifi_direct_client_info_s g_client_info = {
62         .is_registered = FALSE,
63         .client_id = -1,
64         .sync_sockfd = -1,
65         .async_sockfd = -1,
66         .activation_cb = NULL,
67         .discover_cb = NULL,
68         .connection_cb = NULL,
69         .user_data_for_cb_activation = NULL,
70         .user_data_for_cb_discover = NULL,
71         .user_data_for_cb_connection = NULL
72 };
73
74 /*****************************************************************************
75  *      Local Functions Definition
76  *****************************************************************************/
77 static int __wfd_client_read_socket(int sockfd, char *dataptr, int datalen);
78
79 #ifdef __NR_gettid
80 pid_t gettid(void)
81 {
82         return syscall(__NR_gettid);
83 }
84 #else
85 #error "__NR_gettid is not defined, please include linux/unistd.h "
86 #endif
87
88 static wifi_direct_client_info_s *__wfd_get_control()
89 {
90         return &g_client_info;
91 }
92
93 static void __wfd_reset_control()
94 {
95
96         if (g_client_info.g_source_id > 0)
97                 g_source_remove(g_client_info.g_source_id);
98         g_client_info.g_source_id = -1;
99
100         // Protect standard input / output / error
101         if (g_client_info.sync_sockfd > 2)
102                 close(g_client_info.sync_sockfd);
103         g_client_info.sync_sockfd = -1;
104
105         if (g_client_info.async_sockfd > 2)
106                 close(g_client_info.async_sockfd);
107         g_client_info.async_sockfd = -1;
108
109         g_client_info.is_registered = FALSE;
110
111         // Initialize callbacks
112         g_client_info.activation_cb = NULL;
113         g_client_info.discover_cb = NULL;
114         g_client_info.connection_cb = NULL;
115         g_client_info.user_data_for_cb_activation = NULL;
116         g_client_info.user_data_for_cb_discover = NULL;
117         g_client_info.user_data_for_cb_connection = NULL;
118 }
119
120
121 static int macaddr_atoe(char *p, unsigned char mac[])
122 {
123         int i = 0;
124
125         WDC_LOGD( "macaddr_atoe : input MAC = [%s]\n", p);
126
127         for (;;)
128         {
129                 mac[i++] = (char) strtoul(p, &p, 16);
130                 if (!*p++ || i == 6)
131                         break;
132         }
133
134         return (i == 6);
135 }
136
137
138 static char *__wfd_print_event(wfd_client_event_e event)
139 {
140         switch (event)
141         {
142         case WIFI_DIRECT_CLI_EVENT_ACTIVATION:
143                 return "ACTIVATION";
144                 break;
145         case WIFI_DIRECT_CLI_EVENT_DEACTIVATION:
146                 return "DEACTIVATION";
147                 break;
148         case WIFI_DIRECT_CLI_EVENT_INVALID:
149                 return "WIFI_DIRECT_CLI_EVENT_INVALID";
150                 break;
151         case WIFI_DIRECT_CLI_EVENT_DISCOVER_START:
152                 return "WIFI_DIRECT_CLI_EVENT_DISCOVER_START";
153                 break;
154         case WIFI_DIRECT_CLI_EVENT_DISCOVER_START_LISTEN_ONLY:
155                 return "WIFI_DIRECT_CLI_EVENT_DISCOVER_START_LISTEN_ONLY";
156                 break;
157         case WIFI_DIRECT_CLI_EVENT_DISCOVER_START_SEARCH_LISTEN:
158                 return "WIFI_DIRECT_CLI_EVENT_DISCOVER_START_SEARCH_LISTEN";
159                 break;
160         case WIFI_DIRECT_CLI_EVENT_DISCOVER_END:
161                 return "WIFI_DIRECT_CLI_EVENT_DISCOVER_END";
162                 break;
163         case WIFI_DIRECT_CLI_EVENT_DISCOVER_FOUND_PEERS:
164                 return "WIFI_DIRECT_CLI_EVENT_DISCOVER_FOUND_PEERS";
165                 break;
166
167         case WIFI_DIRECT_CLI_EVENT_CONNECTION_REQ:
168                 return "WIFI_DIRECT_CLI_EVENT_CONNECTION_REQ";
169                 break;
170
171         case WIFI_DIRECT_CLI_EVENT_CONNECTION_START:
172                 return "WIFI_DIRECT_CLI_EVENT_CONNECTION_START";
173                 break;
174
175         case WIFI_DIRECT_CLI_EVENT_CONNECTION_RSP:
176                 return "WIFI_DIRECT_CLI_EVENT_CONNECTION_RSP";
177                 break;
178         case WIFI_DIRECT_CLI_EVENT_CONNECTION_WPS_REQ:
179                 return "WIFI_DIRECT_CLI_EVENT_CONNECTION_WPS_REQ";
180                 break;
181
182         case WIFI_DIRECT_CLI_EVENT_DISCONNECTION_RSP:
183                 return "WIFI_DIRECT_CLI_EVENT_DISCONNECTION_RSP";
184                 break;
185         case WIFI_DIRECT_CLI_EVENT_DISCONNECTION_IND:
186                 return "WIFI_DIRECT_CLI_EVENT_DISCONNECTION_IND";
187                 break;
188
189         case WIFI_DIRECT_CLI_EVENT_GROUP_CREATE_RSP:
190                 return "WIFI_DIRECT_CLI_EVENT_GROUP_CREATE_RSP";
191                 break;
192         case WIFI_DIRECT_CLI_EVENT_GROUP_DESTROY_RSP:
193                 return "WIFI_DIRECT_CLI_EVENT_GROUP_DESTROY_RSP";
194                 break;
195         case WIFI_DIRECT_CLI_EVENT_IP_LEASED_IND:
196                 return "WIFI_DIRECT_CLI_EVENT_IP_LEASED_IND";
197                 break;
198
199         default:
200                 return "WIFI_DIRECT_CLI_EVENT_unknown";
201                 break;
202         }
203 }
204
205 static char *__wfd_print_error(wifi_direct_error_e error)
206 {
207         switch (error)
208         {
209         case WIFI_DIRECT_ERROR_OPERATION_FAILED:
210                 return "WIFI_DIRECT_ERROR_OPERATION_FAILED";
211         case WIFI_DIRECT_ERROR_OUT_OF_MEMORY:
212                 return "WIFI_DIRECT_ERROR_OUT_OF_MEMORY";
213         case WIFI_DIRECT_ERROR_COMMUNICATION_FAILED:
214                 return "WIFI_DIRECT_ERROR_COMMUNICATION_FAILED";
215         case WIFI_DIRECT_ERROR_NOT_PERMITTED:
216                 return "WIFI_DIRECT_ERROR_NOT_PERMITTED";
217         case WIFI_DIRECT_ERROR_INVALID_PARAMETER:
218                 return "WIFI_DIRECT_ERROR_INVALID_PARAMETER";
219         case WIFI_DIRECT_ERROR_NOT_INITIALIZED:
220                 return "WIFI_DIRECT_ERROR_NOT_INITIALIZED";
221         case WIFI_DIRECT_ERROR_TOO_MANY_CLIENT:
222                 return "WIFI_DIRECT_ERROR_TOO_MANY_CLIENT";
223         case WIFI_DIRECT_ERROR_RESOURCE_BUSY:
224                 return "WIFI_DIRECT_ERROR_RESOURCE_BUSY";
225         case WIFI_DIRECT_ERROR_NONE:
226                 return "WIFI_DIRECT_ERROR_NONE";
227         default:
228                 WDC_LOGE("Invalid error value: [%d]", error);
229                 return "Invalid error";
230         }
231 }
232
233 static int __wfd_convert_client_event(wfd_client_event_e event)
234 {
235         __WDC_LOG_FUNC_START__;
236
237         switch (event)
238         {
239         case WIFI_DIRECT_CLI_EVENT_ACTIVATION:
240                 return WIFI_DIRECT_DEVICE_STATE_ACTIVATED;
241                 break;
242         case WIFI_DIRECT_CLI_EVENT_DEACTIVATION:
243                 return WIFI_DIRECT_DEVICE_STATE_DEACTIVATED;
244                 break;
245
246         case WIFI_DIRECT_CLI_EVENT_DISCOVER_START_LISTEN_ONLY:
247                 return WIFI_DIRECT_ONLY_LISTEN_STARTED;
248                 break;
249         case WIFI_DIRECT_CLI_EVENT_DISCOVER_START:
250                 return WIFI_DIRECT_DISCOVERY_STARTED;
251                 break;
252         case WIFI_DIRECT_CLI_EVENT_DISCOVER_END:
253                 return WIFI_DIRECT_DISCOVERY_FINISHED;
254                 break;
255         case WIFI_DIRECT_CLI_EVENT_DISCOVER_FOUND_PEERS:
256                 return WIFI_DIRECT_DISCOVERY_FOUND;
257                 break;
258
259         case WIFI_DIRECT_CLI_EVENT_CONNECTION_START:
260                 return WIFI_DIRECT_CONNECTION_IN_PROGRESS;
261                 break;
262         case WIFI_DIRECT_CLI_EVENT_CONNECTION_REQ:
263                 return WIFI_DIRECT_CONNECTION_REQ;
264                 break;
265         case WIFI_DIRECT_CLI_EVENT_CONNECTION_RSP:
266                 return WIFI_DIRECT_CONNECTION_RSP;
267                 break;
268         case WIFI_DIRECT_CLI_EVENT_DISCONNECTION_RSP:
269                 return WIFI_DIRECT_DISCONNECTION_RSP;
270                 break;
271         case WIFI_DIRECT_CLI_EVENT_CONNECTION_WPS_REQ:
272                 return WIFI_DIRECT_CONNECTION_WPS_REQ;
273                 break;
274         case WIFI_DIRECT_CLI_EVENT_DISCONNECTION_IND:
275                 return WIFI_DIRECT_DISCONNECTION_IND;
276                 break;
277         case WIFI_DIRECT_CLI_EVENT_DISASSOCIATION_IND:
278                 return WIFI_DIRECT_DISASSOCIATION_IND;
279                 break;
280         case WIFI_DIRECT_CLI_EVENT_GROUP_CREATE_RSP:
281                 return WIFI_DIRECT_GROUP_CREATED;
282                 break;
283         case WIFI_DIRECT_CLI_EVENT_GROUP_DESTROY_RSP:
284                 return WIFI_DIRECT_GROUP_DESTROYED;
285                 break;
286         default:
287                 WDC_LOGE("Invalid event : [%d]", event);
288                 break;
289         }
290
291         __WDC_LOG_FUNC_END__;
292
293 }
294
295 static gboolean __wfd_client_process_event(GIOChannel * source,
296                                                                                    GIOCondition condition,
297                                                                                    gpointer data)
298 {
299         wfd_client_event_e event = WIFI_DIRECT_CLI_EVENT_INVALID;
300         wifi_direct_client_info_s *client = __wfd_get_control();
301         int sockfd = client->async_sockfd;
302         wifi_direct_client_noti_s client_noti;
303         wifi_direct_error_e error = WIFI_DIRECT_ERROR_NONE;
304         char param1[64] = { 0, };
305         char param2[64] = { 0, };
306
307         memset(&client_noti, 0, sizeof(wifi_direct_client_noti_s));
308
309         // 1.Read socket
310         if (__wfd_client_read_socket(sockfd, (char *) &client_noti,
311                   sizeof(wifi_direct_client_noti_s)) <= 0)
312         {
313                 WDC_LOGE("Error!!! Reading Async Event[%d]", sockfd);
314                 //close(sockfd);
315                 __wfd_reset_control();
316                 __WDC_LOG_FUNC_END__;
317                 return false;
318         }
319
320         WDC_LOGD( "Received Event is [%d,%s], error[%d]\n",
321                                    client_noti.event, __wfd_print_event(client_noti.event),
322                                    client_noti.error);
323
324         event = client_noti.event;
325         error = client_noti.error;
326         memcpy(param1, client_noti.param1, sizeof(client_noti.param1));
327         memcpy(param2, client_noti.param2, sizeof(client_noti.param2));
328
329
330         // 2. dispatch event
331
332         switch (event)
333         {
334         case WIFI_DIRECT_CLI_EVENT_ACTIVATION:
335         case WIFI_DIRECT_CLI_EVENT_DEACTIVATION:
336                 if (client->activation_cb != NULL)
337                         client->activation_cb(error,
338                                                                   (wifi_direct_device_state_e)
339                                                                   __wfd_convert_client_event(event),
340                                                                   client->user_data_for_cb_activation);
341                 else
342                         WDC_LOGE("activation_cb is NULL!!");
343                 break;
344
345         case WIFI_DIRECT_CLI_EVENT_DISCOVER_START:
346         case WIFI_DIRECT_CLI_EVENT_DISCOVER_START_LISTEN_ONLY:
347         case WIFI_DIRECT_CLI_EVENT_DISCOVER_START_SEARCH_LISTEN:
348         case WIFI_DIRECT_CLI_EVENT_DISCOVER_END:
349         case WIFI_DIRECT_CLI_EVENT_DISCOVER_FOUND_PEERS:
350                 if (client->discover_cb != NULL)
351                         client->discover_cb(error,
352                                                                 (wifi_direct_discovery_state_e)
353                                                                 __wfd_convert_client_event(event),
354                                                                 client->user_data_for_cb_discover);
355                 else
356                         WDC_LOGE("discover_cb is NULL!!");
357                 break;
358
359         case WIFI_DIRECT_CLI_EVENT_CONNECTION_START:
360         case WIFI_DIRECT_CLI_EVENT_CONNECTION_REQ:
361         case WIFI_DIRECT_CLI_EVENT_CONNECTION_RSP:
362         case WIFI_DIRECT_CLI_EVENT_DISCONNECTION_RSP:
363         case WIFI_DIRECT_CLI_EVENT_CONNECTION_WPS_REQ:
364         case WIFI_DIRECT_CLI_EVENT_DISCONNECTION_IND:
365         case WIFI_DIRECT_CLI_EVENT_DISASSOCIATION_IND:
366         case WIFI_DIRECT_CLI_EVENT_GROUP_CREATE_RSP:
367         case WIFI_DIRECT_CLI_EVENT_GROUP_DESTROY_RSP:
368                 if (client->connection_cb != NULL)
369                         client->connection_cb(error,
370                                           (wifi_direct_connection_state_e)
371                                           __wfd_convert_client_event(event), param1,
372                                           client->user_data_for_cb_connection);
373                 else
374                         WDC_LOGE("connection_cb is NULL!!");
375                 break;
376
377         // ToDo:  Handling IP lease event...
378         case WIFI_DIRECT_CLI_EVENT_IP_LEASED_IND:
379                 if (client->ip_assigned_cb != NULL)
380                 {
381                         char* ifname = NULL;
382                         ifname = vconf_get_str(VCONFKEY_IFNAME);
383
384                         if (ifname == NULL)
385                                 WDC_LOGD("vconf (%s) value is NULL!!!", VCONFKEY_IFNAME);
386                         else
387                                 WDC_LOGD("VCONFKEY_IFNAME(%s) : %s", VCONFKEY_IFNAME, ifname);
388
389                                 client->ip_assigned_cb(param1,
390                                                                   param2,
391                                                                   ifname,
392                                                                   client->user_data_for_cb_ip_assigned);
393
394                 }
395                 else
396                         WDC_LOGE("ip_assigned_cb is NULL!!");
397                 break;
398
399         default:
400                 break;
401         }
402
403         __WDC_LOG_FUNC_END__;
404
405         return TRUE;
406 }
407
408 static wifi_direct_error_e __wfd_client_send_request(int sockfd, void *req_data, int dataLength)
409 {
410         int retval = 0;
411
412         __WDC_LOG_FUNC_START__;
413
414         if (sockfd > 0)
415         {
416                 WDC_LOGD("Write [%d] bytes to socket [%d].", dataLength, sockfd);
417                 errno = 0;
418                 retval = write(sockfd, (char *) req_data, dataLength);
419
420                 if (retval <= 0)
421                 {
422                         WDC_LOGE("Error!!! writing to the socket. Error = %s", strerror(errno));
423                         __WDC_LOG_FUNC_END__;
424                         return WIFI_DIRECT_ERROR_NONE;
425                 }
426
427                 __WDC_LOG_FUNC_END__;
428                 return WIFI_DIRECT_ERROR_NONE;
429         }
430
431         WDC_LOGE("Error!!! Invalid sockfd [%d]", sockfd);
432         __WDC_LOG_FUNC_END__;
433         return WIFI_DIRECT_ERROR_NONE;
434 }
435
436 static wifi_direct_error_e __wfd_client_async_event_init(int clientid)
437 {
438         int len = 0;
439         int sockfd = 0;
440         struct sockaddr_un servAddr;
441         char *path = "/tmp/wfd_client_socket";
442
443         wifi_direct_client_info_s *client_info = __wfd_get_control();
444
445         __WDC_LOG_FUNC_START__;
446
447         errno = 0;
448         if ((sockfd = socket(AF_UNIX, SOCK_STREAM, 0)) < 0)
449         {
450                 WDC_LOGE("Error!!! creating async socket. Error = [%s].", strerror(errno));
451                 __WDC_LOG_FUNC_END__;
452                 return WIFI_DIRECT_ERROR_COMMUNICATION_FAILED;
453         }
454
455         WDC_LOGD("Created async socket [%d]", sockfd);
456
457         memset(&servAddr, 0, sizeof(servAddr));
458         servAddr.sun_family = AF_UNIX;
459         strcpy(servAddr.sun_path, path);
460         len = sizeof(servAddr.sun_family) + strlen(path);
461
462         WDC_LOGD("Connecting to server socket to register async socket [%d]", sockfd);
463         errno = 0;
464         if ((connect(sockfd, (struct sockaddr *) &servAddr, len)) < 0)
465         {
466                 WDC_LOGE("Error!!! connecting to server socket. Error = [%s].", strerror(errno));
467                 close(sockfd);
468                 __WDC_LOG_FUNC_END__;
469                 return WIFI_DIRECT_ERROR_COMMUNICATION_FAILED;
470         }
471         else
472         {
473                 wifi_direct_client_request_s req;
474                 int result = WIFI_DIRECT_ERROR_NONE;
475
476                 memset(&req, 0, sizeof(wifi_direct_client_request_s));
477
478                 req.cmd = WIFI_DIRECT_CMD_INIT_ASYNC_SOCKET;
479                 req.client_id = clientid;
480
481                 result =
482                         __wfd_client_send_request(sockfd, &req, sizeof(wifi_direct_client_request_s));
483
484                 if (result != WIFI_DIRECT_ERROR_NONE)
485                 {
486                         WDC_LOGE("Error!!! writing to socket, Errno = %s", strerror(errno));
487                         WDC_LOGE("Error!!! [%s]", __wfd_print_error(result));
488                         close(sockfd);
489                         __WDC_LOG_FUNC_END__;
490                         return result;
491                 }
492
493                 client_info->async_sockfd = sockfd;
494
495                 WDC_LOGE("Async socket is created= %d", sockfd);
496
497         }
498
499         return (sockfd);
500 }
501
502
503 static int __wfd_client_read_socket(int sockfd, char *dataptr, int datalen)
504 {
505         int pollret = 0;
506         struct pollfd pollfd;
507         int timeout = 60000; /** for 60 sec */
508         int retval = 0;
509         int total_data_recd = 0;
510
511         __WDC_LOG_FUNC_START__;
512
513         if (sockfd <= 0)
514         {
515                 WDC_LOGE("Error!!! Invalid socket FD [%d]", sockfd);
516                 __WDC_LOG_FUNC_END__;
517                 return -1;
518         }
519
520         if ((dataptr == NULL) || (datalen <= 0))
521         {
522                 WDC_LOGE("Error!!! Invalid parameter");
523                 __WDC_LOG_FUNC_END__;
524                 return -1;
525         }
526
527         WDC_LOGE("@@@@@@@ len = %d  @@@@@@@@@@@", datalen);
528
529         pollfd.fd = sockfd;
530         pollfd.events = POLLIN | POLLERR | POLLHUP;
531         pollret = poll(&pollfd, 1, timeout);
532
533         WDC_LOGE("POLL ret = %d", pollret);
534
535         if (pollret > 0)
536         {
537                 if (pollfd.revents == POLLIN)
538                 {
539                         WDC_LOGE("POLLIN");
540
541                         while (datalen)
542                         {
543                                 errno = 0;
544                                 retval = read(sockfd, (char *) dataptr, datalen);
545                                 WDC_LOGE("sockfd %d retval %d", sockfd,
546                                                            retval);
547                                 if (retval <= 0)
548                                 {
549                                         WDC_LOGE("Error!!! reading data, error [%s]", strerror(errno));
550                                         __WDC_LOG_FUNC_END__;
551                                         return retval;
552                                 }
553                                 total_data_recd += retval;
554                                 dataptr += retval;
555                                 datalen -= retval;
556                         }
557                         __WDC_LOG_FUNC_END__;
558                         return total_data_recd;
559                 }
560                 else if (pollfd.revents & POLLHUP)
561                 {
562                         WDC_LOGE("POLLHUP");
563                         __WDC_LOG_FUNC_END__;
564                         return 0;
565                 }
566                 else if (pollfd.revents & POLLERR)
567                 {
568                         WDC_LOGE("POLLERR");
569                         __WDC_LOG_FUNC_END__;
570                         return 0;
571                 }
572         }
573         else if (pollret == 0)
574         {
575                 WDC_LOGE("POLLing timeout");
576                 __WDC_LOG_FUNC_END__;
577                 return 0;
578         }
579         else
580         {
581                 WDC_LOGE("Polling unknown error");
582                 __WDC_LOG_FUNC_END__;
583                 return -1;
584         }
585         __WDC_LOG_FUNC_END__;
586         return 1;
587 }
588
589
590 static int __wfd_client_read_more_data(int sockfd, void *pData, int Datalen)
591 {
592         int retval = 0;
593
594         __WDC_LOG_FUNC_START__;
595
596         if (sockfd < 0)
597         {
598                 WDC_LOGE("Error!!! Inavlid argument passed");
599                 __WDC_LOG_FUNC_END__;
600                 return WIFI_DIRECT_ERROR_INVALID_PARAMETER;
601         }
602
603         if (pData == NULL)
604         {
605                 WDC_LOGE("Error!!! Inavlid argument passed");
606                 __WDC_LOG_FUNC_END__;
607                 return WIFI_DIRECT_ERROR_INVALID_PARAMETER;
608         }
609
610         if (Datalen <= 0)
611         {
612                 WDC_LOGE("Error!!! Inavlid argument passed");
613                 __WDC_LOG_FUNC_END__;
614                 return WIFI_DIRECT_ERROR_INVALID_PARAMETER;
615         }
616
617         /** Initialising the structure variable */
618         memset(pData, 0, Datalen);
619         errno = 0;
620         retval = __wfd_client_read_socket(sockfd, (char *) pData, Datalen);
621         if (retval <= 0)
622         {
623                 WDC_LOGE("Error!!! reading response from CM. errno = [%d]", errno);
624                 __WDC_LOG_FUNC_END__;
625                 return WIFI_DIRECT_ERROR_OPERATION_FAILED;
626         }
627
628         __WDC_LOG_FUNC_END__;
629         return WIFI_DIRECT_ERROR_NONE;
630 }
631
632 void __wfd_client_print_entry_list(wfd_discovery_entry_s * list, int num)
633 {
634         int i = 0;
635
636         WDC_LOGD("------------------------------------------");
637         for (i = 0; i < num; i++)
638         {
639                 WDC_LOGD("== Peer index : %d ==", i);
640                 WDC_LOGD("is Group Owner ? %s", list[i].is_group_owner ? "YES" : "NO");
641                 WDC_LOGD("device_name : %s", list[i].device_name);
642                 WDC_LOGD("MAC address : "MACSTR, MAC2STR(list[i].mac_address));
643                 WDC_LOGD("wps cfg method : %x", list[i].wps_cfg_methods);
644         }
645         WDC_LOGD("------------------------------------------");
646 }
647
648 void __wfd_client_print_connected_peer_info(wfd_connected_peer_info_s * list, int num)
649 {
650         int i = 0;
651
652         WDC_LOGD("------------------------------------------\n");
653         for (i = 0; i < num; i++)
654         {
655                 WDC_LOGD("== Peer index : %d ==\n", i);
656                 WDC_LOGD("device_name : %s\n", list[i].device_name);
657                 WDC_LOGD("Device MAC : " MACSTR "\n", MAC2STR(list[i].mac_address));
658                 WDC_LOGD("Interface MAC : " MACSTR "\n", MAC2STR(list[i].intf_mac_address));
659                 WDC_LOGD("services : %d\n", list[i].services);
660                 WDC_LOGD("is_p2p : %d\n", list[i].is_p2p);
661                 WDC_LOGD("category : %d\n", list[i].category);
662                 WDC_LOGD("channel : %d\n", list[i].channel);
663                 WDC_LOGD("IP ["IPSTR"]\n", IP2STR(list[i].ip_address));
664         }
665         WDC_LOGD("------------------------------------------\n");
666 }
667
668
669 void __wfd_client_print_persistent_group_info(wfd_persistent_group_info_s * list, int num)
670 {
671         int i = 0;
672
673         WDC_LOGD("------------------------------------------\n");
674         for (i = 0; i < num; i++)
675         {
676                 WDC_LOGD("== Persistent Group index : %d ==\n", i);
677                 WDC_LOGD("ssid : %s\n", list[i].ssid);
678                 WDC_LOGD("GO MAC : " MACSTR "\n",
679                                            MAC2STR(list[i].go_mac_address));
680         }
681         WDC_LOGD("------------------------------------------\n");
682 }
683
684
685
686 void __wfd_client_print_config_data(wfd_config_data_s * config)
687 {
688         if (config == NULL)
689                 return;
690
691         WDC_LOGD("Operating channel = [%d]\n", config->channel);
692         WDC_LOGD("WPS method = [%d, %s]\n", config->wps_config,
693                                 (config->wps_config == WIFI_DIRECT_WPS_TYPE_PBC) ? 
694                                                 "Pushbutton" : (config-> wps_config == WIFI_DIRECT_WPS_TYPE_PIN_DISPLAY)
695                                                         ? "Display" : "Keypad");
696
697         WDC_LOGD("Max client = [%d]\n", config->max_clients);
698         WDC_LOGD("grp_owner_intent = [%d]\n", config->group_owner_intent);
699         WDC_LOGD("hide-SSID = [%d]\n", config->hide_SSID);
700         WDC_LOGD("want_persistent_group = [%d]\n", config->want_persistent_group);
701         WDC_LOGD("auto_connection = [%d]\n", config->auto_connection);
702         WDC_LOGD("primary_dev_type = [%d]\n", config->primary_dev_type);
703         WDC_LOGD("secondary_dev_type = [%d]\n",
704                                    config->secondary_dev_type);
705
706 }
707
708
709 int wifi_direct_initialize(void)
710 {
711         struct sockaddr_un servAddr;
712         char *path = "/tmp/wfd_client_socket";
713         wifi_direct_client_info_s *client_info = __wfd_get_control();
714         int sockfd = 0;
715         int len = 0;
716         int ret = 0;
717
718         __WDC_LOG_FUNC_START__;
719
720         if (client_info->is_registered == TRUE)
721         {
722                 WDC_LOGE("Warning!!! Already registered\nUpdate user data and callback!");
723                 __WDC_LOG_FUNC_END__;
724                 return WIFI_DIRECT_ERROR_NONE;
725         }
726
727         errno = 0;
728         if ((sockfd = socket(AF_UNIX, SOCK_STREAM, 0)) < 0)
729         {
730                 WDC_LOGE("Error!!! creating sync socket. Error = [%s].", strerror(errno));
731                 return WIFI_DIRECT_ERROR_COMMUNICATION_FAILED;
732         }
733
734         WDC_LOGD("Created sync socket [%d]", sockfd);
735
736         memset(&servAddr, 0, sizeof(servAddr));
737         servAddr.sun_family = AF_UNIX;
738         strcpy(servAddr.sun_path, path);
739         len = sizeof(servAddr.sun_family) + strlen(path);
740
741         WDC_LOGD("Connecting to server socket to register sync socket [%d]", sockfd);
742
743         int retry_count = 2;
744         while (retry_count > 0)
745         {
746                 errno = 0;
747                 if ((ret = connect(sockfd, (struct sockaddr *) &servAddr, len)) < 0)
748                 {
749                         WDC_LOGD("Launching wfd-server..\n");
750                         system("dbus-send --system --print-reply --dest=net.netconfig /net/netconfig/wifi net.netconfig.wifi.LaunchDirect");
751                         retry_count--;
752                 }
753                 else
754                 {
755                         break;
756                 }
757         }
758
759         if (ret < 0)
760         {
761                 WDC_LOGE("Error!!! connecting to server socket. Error = [%d] %s.\n",
762                                            errno, strerror(errno));
763                 if (sockfd > 0)
764                         close(sockfd);
765
766                 __WDC_LOG_FUNC_END__;
767                 return WIFI_DIRECT_ERROR_COMMUNICATION_FAILED;
768         }
769         else
770         {
771                 wifi_direct_client_request_s req;
772                 wifi_direct_client_response_s resp;
773
774                 int status = WIFI_DIRECT_ERROR_NONE;
775
776                 memset(&req, 0, sizeof(wifi_direct_client_request_s));
777                 memset(&resp, 0, sizeof(wifi_direct_client_response_s));
778
779                 req.cmd = WIFI_DIRECT_CMD_REGISTER;
780                 req.client_id = gettid();
781                 WDC_LOGD("Client ID = %d\n", req.client_id);
782
783                 status = __wfd_client_send_request(sockfd, &req, sizeof(wifi_direct_client_request_s));
784
785                 if (status != WIFI_DIRECT_ERROR_NONE)
786                 {
787                         WDC_LOGE("Error!!! writing to socket, Errno = %s\n", strerror(errno));
788                         WDC_LOGE("Error!!! [%s]\n", __wfd_print_error(status));
789                         close(sockfd);
790                         __WDC_LOG_FUNC_END__;
791                         return WIFI_DIRECT_ERROR_COMMUNICATION_FAILED;
792                 }
793
794                 /*Get client id */
795                 if ((status = __wfd_client_read_socket(sockfd, (char *) &resp, 
796                         sizeof(wifi_direct_client_response_s))) <= 0)
797                 {
798                         WDC_LOGE("Error!!! reading socket, status = %d errno = %s\n", status, strerror(errno));
799                         __WDC_LOG_FUNC_END__;
800                         return WIFI_DIRECT_ERROR_COMMUNICATION_FAILED;
801                 }
802                 else
803                 {
804                         if (resp.cmd == WIFI_DIRECT_CMD_REGISTER)
805                         {
806                                 if (resp.result == WIFI_DIRECT_ERROR_NONE)
807                                 {
808                                         WDC_LOGD("Client ID received = %d \n",
809                                                                    resp.client_id);
810                                         WDC_LOGD("Connected sync socket %d to the wifi direct server socket\n",
811                                                                    sockfd);
812                                         client_info->sync_sockfd = sockfd;
813                                         client_info->client_id = resp.client_id;
814                                         client_info->is_registered = TRUE;
815                                 }
816                                 else
817                                 {
818                                         WDC_LOGE("Error!!! Client Register = %d\n",
819                                                                    resp.result);
820                                         close(sockfd);
821                                         __WDC_LOG_FUNC_END__;
822                                         return resp.result;
823                                 }
824
825                                 int async_sockfd = -1;
826                                 /* Send request for establishing async communication channel */
827                                 if ((async_sockfd =
828                                          __wfd_client_async_event_init(client_info->client_id)) ==
829                                         WIFI_DIRECT_ERROR_COMMUNICATION_FAILED)
830                                 {
831                                         WDC_LOGE("Error!!! creating Async Socket \n");
832                                         __wfd_reset_control();
833                                         __WDC_LOG_FUNC_END__;
834                                         return WIFI_DIRECT_ERROR_COMMUNICATION_FAILED;
835                                 }
836
837                                 client_info->async_sockfd = async_sockfd;
838                         }
839                         else
840                         {
841                                 WDC_LOGE("Error!!! Invalid Response received from wfd Server. cmd = %d \n",
842                                                            resp.cmd);
843                                 close(sockfd);
844                                 __WDC_LOG_FUNC_END__;
845                                 return WIFI_DIRECT_ERROR_COMMUNICATION_FAILED;
846                         }
847                 }
848         }
849
850         GIOChannel *gio = g_io_channel_unix_new(client_info->async_sockfd);
851
852         int g_source_id =
853                 g_io_add_watch(gio, G_IO_IN | G_IO_ERR | G_IO_HUP,
854                                            (GIOFunc) __wfd_client_process_event, NULL);
855
856         g_io_channel_unref(gio);
857
858         WDC_LOGD("Scoket is successfully registered to g_main_loop.\n");
859
860         client_info->g_source_id = g_source_id;
861
862         // Initialize callbacks
863         client_info->activation_cb = NULL;
864         client_info->discover_cb = NULL;
865         client_info->connection_cb = NULL;
866         client_info->user_data_for_cb_activation = NULL;
867         client_info->user_data_for_cb_discover = NULL;
868         client_info->user_data_for_cb_connection = NULL;
869
870         __WDC_LOG_FUNC_END__;
871
872         return WIFI_DIRECT_ERROR_NONE;
873 }
874
875
876
877 int wifi_direct_deinitialize(void)
878 {
879         wifi_direct_client_info_s *client_info = __wfd_get_control();
880
881         __WDC_LOG_FUNC_START__;
882
883         if (client_info->is_registered == false)
884         {
885                 WDC_LOGE("Client is already deregistered.\n");
886                 __WDC_LOG_FUNC_END__;
887                 return WIFI_DIRECT_ERROR_OPERATION_FAILED;
888         }
889
890         client_info->activation_cb = NULL;
891         client_info->discover_cb = NULL;
892         client_info->connection_cb = NULL;
893         client_info->user_data_for_cb_activation = NULL;
894         client_info->user_data_for_cb_discover = NULL;
895         client_info->user_data_for_cb_connection = NULL;
896
897         wifi_direct_client_request_s req;
898         wifi_direct_client_response_s rsp;
899
900         int status = WIFI_DIRECT_ERROR_NONE;
901
902         memset(&req, 0, sizeof(wifi_direct_client_request_s));
903         memset(&rsp, 0, sizeof(wifi_direct_client_response_s));
904
905         req.cmd = WIFI_DIRECT_CMD_DEREGISTER;
906         req.client_id = client_info->client_id;
907
908         status =
909                 __wfd_client_send_request(client_info->sync_sockfd, &req,
910                                                                   sizeof(wifi_direct_client_request_s));
911         if (status != WIFI_DIRECT_ERROR_NONE)
912         {
913                 WDC_LOGE("Error!!! writing to socket, Errno = %s\n", strerror(errno));
914                 WDC_LOGE("Error!!! [%s]\n", __wfd_print_error(status));
915                 client_info->sync_sockfd = -1;
916                 __wfd_reset_control();
917                 __WDC_LOG_FUNC_END__;
918                 return WIFI_DIRECT_ERROR_COMMUNICATION_FAILED;
919         }
920
921         //
922         // Deinit protocol: Send the deregister cmd and wait for socket close...
923         //
924         if ((status =
925                  __wfd_client_read_socket(client_info->sync_sockfd, (char *) &rsp,
926                                                                   sizeof(wifi_direct_client_response_s))) <= 0)
927         {
928                 WDC_LOGD( "Deinit Successfull\n");
929
930                 if (client_info->g_source_id > 0)
931                         g_source_remove(client_info->g_source_id);
932                 client_info->g_source_id = -1;
933
934                 close(client_info->sync_sockfd);
935                 client_info->sync_sockfd = -1;
936                 __wfd_reset_control();
937                 __WDC_LOG_FUNC_END__;
938                 return WIFI_DIRECT_ERROR_NONE;
939         }
940         else
941         {
942                 WDC_LOGD("Error.. Something wrong...!!!\n");
943         }
944
945         __wfd_reset_control();
946
947         __WDC_LOG_FUNC_END__;
948         return WIFI_DIRECT_ERROR_NONE;
949 }
950
951
952 int wifi_direct_set_device_state_changed_cb(wifi_direct_device_state_changed_cb
953                                                                                         cb, void *user_data)
954 {
955         wifi_direct_client_info_s *client_info = __wfd_get_control();
956
957         __WDC_LOG_FUNC_START__;
958
959         if (NULL == cb)
960         {
961                 WDC_LOGE("Callback is NULL.\n");
962                 __WDC_LOG_FUNC_END__;
963                 return WIFI_DIRECT_ERROR_INVALID_PARAMETER;
964         }
965
966         if (client_info->is_registered == false)
967         {
968                 WDC_LOGE("Client is not initialized.\n");
969                 __WDC_LOG_FUNC_END__;
970                 return WIFI_DIRECT_ERROR_NOT_INITIALIZED;
971         }
972
973         client_info->activation_cb = cb;
974         client_info->user_data_for_cb_activation = user_data;
975
976         return WIFI_DIRECT_ERROR_NONE;
977 }
978
979
980 int wifi_direct_unset_device_state_changed_cb(void)
981 {
982         wifi_direct_client_info_s *client_info = __wfd_get_control();
983
984         __WDC_LOG_FUNC_START__;
985
986         if (client_info->is_registered == false)
987         {
988                 WDC_LOGE("Client is not initialized.\n");
989                 __WDC_LOG_FUNC_END__;
990                 return WIFI_DIRECT_ERROR_NOT_INITIALIZED;
991         }
992
993         client_info->activation_cb = NULL;
994         client_info->user_data_for_cb_activation = NULL;
995
996         return WIFI_DIRECT_ERROR_NONE;
997 }
998
999
1000 int
1001 wifi_direct_set_discovery_state_changed_cb
1002 (wifi_direct_discovery_state_chagned_cb cb, void *user_data)
1003 {
1004         wifi_direct_client_info_s *client_info = __wfd_get_control();
1005
1006         __WDC_LOG_FUNC_START__;
1007
1008         if (NULL == cb)
1009         {
1010                 WDC_LOGE("Callback is NULL.\n");
1011                 __WDC_LOG_FUNC_END__;
1012                 return WIFI_DIRECT_ERROR_INVALID_PARAMETER;
1013         }
1014
1015         if (client_info->is_registered == false)
1016         {
1017                 WDC_LOGE("Client is not initialized.\n");
1018                 __WDC_LOG_FUNC_END__;
1019                 return WIFI_DIRECT_ERROR_NOT_INITIALIZED;
1020         }
1021
1022         client_info->discover_cb = cb;
1023         client_info->user_data_for_cb_discover = user_data;
1024
1025         return WIFI_DIRECT_ERROR_NONE;
1026 }
1027
1028
1029 int wifi_direct_unset_discovery_state_changed_cb(void)
1030 {
1031         wifi_direct_client_info_s *client_info = __wfd_get_control();
1032
1033         __WDC_LOG_FUNC_START__;
1034
1035         if (client_info->is_registered == false)
1036         {
1037                 WDC_LOGE("Client is not initialized.\n");
1038                 __WDC_LOG_FUNC_END__;
1039                 return WIFI_DIRECT_ERROR_NOT_INITIALIZED;
1040         }
1041
1042         client_info->discover_cb = NULL;
1043         client_info->user_data_for_cb_discover = NULL;
1044
1045         return WIFI_DIRECT_ERROR_NONE;
1046 }
1047
1048
1049 int
1050 wifi_direct_set_connection_state_changed_cb
1051 (wifi_direct_connection_state_changed_cb cb, void *user_data)
1052 {
1053         wifi_direct_client_info_s *client_info = __wfd_get_control();
1054
1055         __WDC_LOG_FUNC_START__;
1056
1057         if (NULL == cb)
1058         {
1059                 WDC_LOGE("Callback is NULL.\n");
1060                 __WDC_LOG_FUNC_END__;
1061                 return WIFI_DIRECT_ERROR_INVALID_PARAMETER;
1062         }
1063
1064         if (client_info->is_registered == false)
1065         {
1066                 WDC_LOGE("Client is not initialized.\n");
1067                 __WDC_LOG_FUNC_END__;
1068                 return WIFI_DIRECT_ERROR_NOT_INITIALIZED;
1069         }
1070
1071         client_info->connection_cb = cb;
1072         client_info->user_data_for_cb_connection = user_data;
1073
1074         return WIFI_DIRECT_ERROR_NONE;
1075 }
1076
1077
1078 int wifi_direct_unset_connection_state_changed_cb(void)
1079 {
1080         wifi_direct_client_info_s *client_info = __wfd_get_control();
1081
1082         __WDC_LOG_FUNC_START__;
1083
1084         if (client_info->is_registered == false)
1085         {
1086                 WDC_LOGE("Client is not initialized.\n");
1087                 __WDC_LOG_FUNC_END__;
1088                 return WIFI_DIRECT_ERROR_NOT_INITIALIZED;
1089         }
1090
1091         client_info->connection_cb = NULL;
1092         client_info->user_data_for_cb_connection = NULL;
1093
1094         return WIFI_DIRECT_ERROR_NONE;
1095 }
1096
1097
1098 int wifi_direct_set_client_ip_address_assigned_cb(wifi_direct_client_ip_address_assigned_cb cb, void* user_data)
1099 {
1100         wifi_direct_client_info_s *client_info = __wfd_get_control();
1101
1102         __WDC_LOG_FUNC_START__;
1103
1104         if (NULL == cb)
1105         {
1106                 WDC_LOGE("Callback is NULL.\n");
1107                 __WDC_LOG_FUNC_END__;
1108                 return WIFI_DIRECT_ERROR_INVALID_PARAMETER;
1109         }
1110
1111         if (client_info->is_registered == false)
1112         {
1113                 WDC_LOGE("Client is not initialized.\n");
1114                 __WDC_LOG_FUNC_END__;
1115                 return WIFI_DIRECT_ERROR_NOT_INITIALIZED;
1116         }
1117
1118         client_info->ip_assigned_cb = cb;
1119         client_info->user_data_for_cb_ip_assigned = user_data;
1120
1121         return WIFI_DIRECT_ERROR_NONE;
1122 }
1123
1124 int wifi_direct_unset_client_ip_address_assigned_cb(void)
1125 {
1126         wifi_direct_client_info_s *client_info = __wfd_get_control();
1127
1128         __WDC_LOG_FUNC_START__;
1129
1130         if (client_info->is_registered == false)
1131         {
1132                 WDC_LOGE("Client is not initialized.\n");
1133                 __WDC_LOG_FUNC_END__;
1134                 return WIFI_DIRECT_ERROR_NOT_INITIALIZED;
1135         }
1136
1137         client_info->ip_assigned_cb = NULL;
1138         client_info->user_data_for_cb_ip_assigned = NULL;
1139
1140         return WIFI_DIRECT_ERROR_NONE;
1141 }
1142
1143
1144 int wifi_direct_activate(void)
1145 {
1146         wifi_direct_client_info_s *client_info = __wfd_get_control();
1147
1148         __WDC_LOG_FUNC_START__;
1149
1150         if ((client_info->is_registered == false)
1151                 || (client_info->client_id == WFD_INVALID_ID))
1152         {
1153                 WDC_LOGE("Client is NOT registered.\n");
1154                 __WDC_LOG_FUNC_END__;
1155                 return WIFI_DIRECT_ERROR_NOT_INITIALIZED;
1156         }
1157
1158         wifi_direct_client_request_s req;
1159         wifi_direct_client_response_s rsp;
1160
1161         int status = WIFI_DIRECT_ERROR_NONE;
1162
1163         memset(&req, 0, sizeof(wifi_direct_client_request_s));
1164         memset(&rsp, 0, sizeof(wifi_direct_client_response_s));
1165
1166         req.cmd = WIFI_DIRECT_CMD_ACTIVATE;
1167         req.client_id = client_info->client_id;
1168
1169         status =
1170                 __wfd_client_send_request(client_info->sync_sockfd, &req,
1171                                                                   sizeof(wifi_direct_client_request_s));
1172         if (status != WIFI_DIRECT_ERROR_NONE)
1173         {
1174                 WDC_LOGE("Error!!! writing to socket, Errno = %s\n", strerror(errno));
1175                 WDC_LOGE("Error!!! [%s]\n",
1176                                            __wfd_print_error(status));
1177                 client_info->sync_sockfd = -1;
1178                 __wfd_reset_control();
1179                 __WDC_LOG_FUNC_END__;
1180                 return WIFI_DIRECT_ERROR_COMMUNICATION_FAILED;
1181         }
1182
1183         if ((status =
1184                  __wfd_client_read_socket(client_info->sync_sockfd, (char *) &rsp,
1185                                                                   sizeof(wifi_direct_client_response_s))) <= 0)
1186         {
1187                 WDC_LOGE("Error!!! reading socket, status = %d errno = %s\n", status, strerror(errno));
1188                 client_info->sync_sockfd = -1;
1189                 __wfd_reset_control();
1190                 __WDC_LOG_FUNC_END__;
1191                 return WIFI_DIRECT_ERROR_COMMUNICATION_FAILED;
1192         }
1193         else
1194         {
1195                 if (rsp.cmd == WIFI_DIRECT_CMD_ACTIVATE)
1196                 {
1197                         if (rsp.result != WIFI_DIRECT_ERROR_NONE)
1198                         {
1199                                 WDC_LOGE("Error!!! Result received = %d \n", rsp.result);
1200                                 WDC_LOGE("Error!!! [%s]\n", __wfd_print_error(rsp.result));
1201                                 __WDC_LOG_FUNC_END__;
1202                                 return rsp.result;
1203                         }
1204                         else
1205                         {
1206                                 WDC_LOGE("Activating device is successfull.\n");
1207                         }
1208                 }
1209                 else
1210                 {
1211                         WDC_LOGE("Error!!! Invalid resp cmd = %d\n",
1212                                                    rsp.cmd);
1213                         return WIFI_DIRECT_ERROR_OPERATION_FAILED;
1214                 }
1215         }
1216
1217         __WDC_LOG_FUNC_END__;
1218         return WIFI_DIRECT_ERROR_NONE;
1219 }
1220
1221 int wifi_direct_deactivate(void)
1222 {
1223         wifi_direct_client_info_s *client_info = __wfd_get_control();
1224
1225         __WDC_LOG_FUNC_START__;
1226
1227         if ((client_info->is_registered == false)
1228                 || (client_info->client_id == WFD_INVALID_ID))
1229         {
1230                 WDC_LOGE("Client is NOT registered.\n");
1231                 __WDC_LOG_FUNC_END__;
1232                 return WIFI_DIRECT_ERROR_NOT_INITIALIZED;
1233         }
1234
1235         wifi_direct_client_request_s req;
1236         wifi_direct_client_response_s rsp;
1237
1238         int status = WIFI_DIRECT_ERROR_NONE;
1239
1240         memset(&req, 0, sizeof(wifi_direct_client_request_s));
1241         memset(&rsp, 0, sizeof(wifi_direct_client_response_s));
1242
1243         req.cmd = WIFI_DIRECT_CMD_DEACTIVATE;
1244         req.client_id = client_info->client_id;
1245
1246         status =
1247                 __wfd_client_send_request(client_info->sync_sockfd, &req,
1248                                                                   sizeof(wifi_direct_client_request_s));
1249         if (status != WIFI_DIRECT_ERROR_NONE)
1250         {
1251                 WDC_LOGE("Error!!! writing to socket, Errno = %s\n", strerror(errno));
1252                 WDC_LOGE("Error!!! [%s]\n",
1253                                            __wfd_print_error(status));
1254                 client_info->sync_sockfd = -1;
1255                 __wfd_reset_control();
1256                 __WDC_LOG_FUNC_END__;
1257                 return WIFI_DIRECT_ERROR_COMMUNICATION_FAILED;
1258         }
1259
1260         if ((status =
1261                  __wfd_client_read_socket(client_info->sync_sockfd, (char *) &rsp,
1262                                                                   sizeof(wifi_direct_client_response_s))) <= 0)
1263         {
1264                 WDC_LOGE("Error!!! reading socket, status = %d errno = %s\n", status, strerror(errno));
1265                 client_info->sync_sockfd = -1;
1266                 __wfd_reset_control();
1267                 __WDC_LOG_FUNC_END__;
1268                 return WIFI_DIRECT_ERROR_COMMUNICATION_FAILED;
1269         }
1270         else
1271         {
1272                 if (rsp.cmd == WIFI_DIRECT_CMD_DEACTIVATE)
1273                 {
1274                         if (rsp.result != WIFI_DIRECT_ERROR_NONE)
1275                         {
1276                                 WDC_LOGE("Error!!! Result received = %d \n", rsp.result);
1277                                 WDC_LOGE("Error!!! [%s]\n",
1278                                                            __wfd_print_error(rsp.result));
1279                                 __WDC_LOG_FUNC_END__;
1280                                 return rsp.result;
1281                         }
1282                         else
1283                         {
1284                                 WDC_LOGE("Device Deactivated! \n");
1285                         }
1286                 }
1287                 else
1288                 {
1289                         WDC_LOGE("Error!!! Invalid resp cmd = %d\n",
1290                                                    rsp.cmd);
1291                         return WIFI_DIRECT_ERROR_OPERATION_FAILED;
1292                 }
1293         }
1294
1295         __WDC_LOG_FUNC_END__;
1296         return WIFI_DIRECT_ERROR_NONE;
1297 }
1298
1299 int wifi_direct_start_discovery(bool listen_only, int timeout)
1300 {
1301         wifi_direct_client_info_s *client_info = __wfd_get_control();
1302
1303         __WDC_LOG_FUNC_START__;
1304
1305         if ((client_info->is_registered == false)
1306                 || (client_info->client_id == WFD_INVALID_ID))
1307         {
1308                 WDC_LOGE("Client is NOT registered.\n");
1309                 __WDC_LOG_FUNC_END__;
1310                 return WIFI_DIRECT_ERROR_NOT_INITIALIZED;
1311         }
1312
1313         if (timeout < 0)
1314         {
1315                 WDC_LOGE("Nagative value. Param [timeout]!\n");
1316                 __WDC_LOG_FUNC_END__;
1317                 return WIFI_DIRECT_ERROR_INVALID_PARAMETER;
1318         }
1319
1320         wifi_direct_client_request_s req;
1321         wifi_direct_client_response_s rsp;
1322
1323         int status = WIFI_DIRECT_ERROR_NONE;
1324
1325         memset(&req, 0, sizeof(wifi_direct_client_request_s));
1326         memset(&rsp, 0, sizeof(wifi_direct_client_response_s));
1327
1328         req.cmd = WIFI_DIRECT_CMD_START_DISCOVERY;
1329         req.client_id = client_info->client_id;
1330         req.data.listen_only = listen_only;
1331         req.data.timeout = timeout;
1332
1333         WDC_LOGE("listen only (%d) timeout (%d) \n",
1334                                    listen_only, timeout);
1335
1336         status =
1337                 __wfd_client_send_request(client_info->sync_sockfd, &req,
1338                                                                   sizeof(wifi_direct_client_request_s));
1339         if (status != WIFI_DIRECT_ERROR_NONE)
1340         {
1341                 WDC_LOGE("Error!!! writing to socket, Errno = %s\n", strerror(errno));
1342                 WDC_LOGE("Error!!! [%s]\n", __wfd_print_error(status));
1343                 client_info->sync_sockfd = -1;
1344                 __wfd_reset_control();
1345                 __WDC_LOG_FUNC_END__;
1346                 return WIFI_DIRECT_ERROR_COMMUNICATION_FAILED;
1347         }
1348
1349         if ((status =
1350                  __wfd_client_read_socket(client_info->sync_sockfd, (char *) &rsp,
1351                                                                   sizeof(wifi_direct_client_response_s))) <= 0)
1352         {
1353                 WDC_LOGE("Error!!! reading socket, status = %d errno = %s\n", status, strerror(errno));
1354                 client_info->sync_sockfd = -1;
1355                 __wfd_reset_control();
1356                 return WIFI_DIRECT_ERROR_COMMUNICATION_FAILED;
1357         }
1358         else
1359         {
1360                 if (rsp.cmd == WIFI_DIRECT_CMD_START_DISCOVERY)
1361                 {
1362                         if (rsp.result != WIFI_DIRECT_ERROR_NONE)
1363                         {
1364                                 WDC_LOGE("Error!!! Result received = %d \n", rsp.result);
1365                                 WDC_LOGE("Error!!! [%s]\n",
1366                                                            __wfd_print_error(rsp.result));
1367                                 __WDC_LOG_FUNC_END__;
1368                                 return rsp.result;
1369                         }
1370                         else
1371                         {
1372                                 WDC_LOGE("wifi_direct_start_discovery() SUCCESS \n");
1373                         }
1374                 }
1375                 else
1376                 {
1377                         WDC_LOGE("Error!!! Invalid resp cmd = %d\n",
1378                                                    rsp.cmd);
1379                         return WIFI_DIRECT_ERROR_OPERATION_FAILED;
1380                 }
1381         }
1382
1383         __WDC_LOG_FUNC_END__;
1384
1385         return WIFI_DIRECT_ERROR_NONE;
1386 }
1387
1388 int wifi_direct_cancel_discovery(void)
1389 {
1390         wifi_direct_client_info_s *client_info = __wfd_get_control();
1391
1392         __WDC_LOG_FUNC_START__;
1393
1394         if ((client_info->is_registered == false)
1395                 || (client_info->client_id == WFD_INVALID_ID))
1396         {
1397                 WDC_LOGE("Client is NOT registered.\n");
1398                 __WDC_LOG_FUNC_END__;
1399                 return WIFI_DIRECT_ERROR_NOT_INITIALIZED;
1400         }
1401
1402         wifi_direct_client_request_s req;
1403         wifi_direct_client_response_s rsp;
1404
1405         int status = WIFI_DIRECT_ERROR_NONE;
1406
1407         memset(&req, 0, sizeof(wifi_direct_client_request_s));
1408         memset(&rsp, 0, sizeof(wifi_direct_client_response_s));
1409
1410         req.cmd = WIFI_DIRECT_CMD_CANCEL_DISCOVERY;
1411         req.client_id = client_info->client_id;
1412
1413         status =
1414                 __wfd_client_send_request(client_info->sync_sockfd, &req,
1415                                                                   sizeof(wifi_direct_client_request_s));
1416         if (status != WIFI_DIRECT_ERROR_NONE)
1417         {
1418                 WDC_LOGE("Error!!! writing to socket, Errno = %s\n",
1419                                            strerror(errno));
1420                 WDC_LOGE("Error!!! [%s]\n",
1421                                            __wfd_print_error(status));
1422                 client_info->sync_sockfd = -1;
1423                 __wfd_reset_control();
1424                 __WDC_LOG_FUNC_END__;
1425                 return WIFI_DIRECT_ERROR_COMMUNICATION_FAILED;
1426         }
1427
1428         if ((status =
1429                  __wfd_client_read_socket(client_info->sync_sockfd, (char *) &rsp,
1430                                                                   sizeof(wifi_direct_client_response_s))) <= 0)
1431         {
1432                 WDC_LOGE("Error!!! reading socket, status = %d errno = %s\n",
1433                                            status, strerror(errno));
1434                 client_info->sync_sockfd = -1;
1435                 __wfd_reset_control();
1436                 __WDC_LOG_FUNC_END__;
1437                 return WIFI_DIRECT_ERROR_COMMUNICATION_FAILED;
1438         }
1439         else
1440         {
1441                 if (rsp.cmd == WIFI_DIRECT_CMD_CANCEL_DISCOVERY)
1442                 {
1443                         if (rsp.result != WIFI_DIRECT_ERROR_NONE)
1444                         {
1445                                 WDC_LOGE("Error!!! Result received = %d \n", rsp.result);
1446                                 WDC_LOGE("Error!!! [%s]\n",
1447                                                            __wfd_print_error(rsp.result));
1448                                 __WDC_LOG_FUNC_END__;
1449                                 return rsp.result;
1450                         }
1451                         else
1452                         {
1453                                 WDC_LOGE("wifi_direct_cancel_discovery() SUCCESS \n");
1454                         }
1455                 }
1456                 else
1457                 {
1458                         WDC_LOGE("Error!!! Invalid resp cmd = %d\n",
1459                                                    rsp.cmd);
1460                         return WIFI_DIRECT_ERROR_OPERATION_FAILED;
1461                 }
1462         }
1463
1464         __WDC_LOG_FUNC_END__;
1465
1466         return WIFI_DIRECT_ERROR_NONE;
1467 }
1468
1469
1470 int wifi_direct_foreach_discovered_peers(wifi_direct_discovered_peer_cb callback, void *user_data)
1471 {
1472         wifi_direct_client_info_s *client_info = __wfd_get_control();
1473
1474         __WDC_LOG_FUNC_START__;
1475
1476         if ((client_info->is_registered == false)
1477                 || (client_info->client_id == WFD_INVALID_ID))
1478         {
1479                 WDC_LOGE("Client is NOT registered.\n");
1480                 __WDC_LOG_FUNC_END__;
1481                 return WIFI_DIRECT_ERROR_NOT_INITIALIZED;
1482         }
1483
1484         if (callback == NULL)
1485         {
1486                 WDC_LOGE("NULL Param [callback]!\n");
1487                 __WDC_LOG_FUNC_END__;
1488                 return WIFI_DIRECT_ERROR_INVALID_PARAMETER;
1489         }
1490
1491         wifi_direct_client_request_s req;
1492         wifi_direct_client_response_s rsp;
1493         int i;
1494
1495         int status = WIFI_DIRECT_ERROR_NONE;
1496
1497         memset(&req, 0, sizeof(wifi_direct_client_request_s));
1498         memset(&rsp, 0, sizeof(wifi_direct_client_response_s));
1499
1500         req.cmd = WIFI_DIRECT_CMD_GET_DISCOVERY_RESULT;
1501         req.client_id = client_info->client_id;
1502
1503         status =
1504                 __wfd_client_send_request(client_info->sync_sockfd, &req,
1505                                                                   sizeof(wifi_direct_client_request_s));
1506         if (status != WIFI_DIRECT_ERROR_NONE)
1507         {
1508                 WDC_LOGE("Error!!! writing to socket, Errno = %s\n",
1509                                            strerror(errno));
1510                 WDC_LOGE("Error!!! [%s]\n",
1511                                            __wfd_print_error(status));
1512                 client_info->sync_sockfd = -1;
1513                 __wfd_reset_control();
1514                 __WDC_LOG_FUNC_END__;
1515                 return WIFI_DIRECT_ERROR_COMMUNICATION_FAILED;
1516         }
1517
1518         if ((status =
1519                  __wfd_client_read_socket(client_info->sync_sockfd, (char *) &rsp,
1520                                                                   sizeof(wifi_direct_client_response_s))) <= 0)
1521         {
1522                 WDC_LOGE("Error!!! reading socket, status = %d errno = %s\n",
1523                                            status, strerror(errno));
1524                 client_info->sync_sockfd = -1;
1525                 __wfd_reset_control();
1526                 __WDC_LOG_FUNC_END__;
1527                 return WIFI_DIRECT_ERROR_COMMUNICATION_FAILED;
1528         }
1529         else
1530         {
1531                 if (rsp.cmd == WIFI_DIRECT_CMD_GET_DISCOVERY_RESULT)
1532                 {
1533                         if (rsp.result != WIFI_DIRECT_ERROR_NONE)
1534                         {
1535                                 WDC_LOGE("Error!!! Result received = %d \n", rsp.result);
1536                                 WDC_LOGE("Error!!! [%s]\n", __wfd_print_error(rsp.result));
1537                                 __WDC_LOG_FUNC_END__;
1538                                 return rsp.result;
1539                         }
1540                         else
1541                         {
1542                                 int num = rsp.param1;
1543                                 int status = 0;
1544                                 wfd_discovery_entry_s *buff = NULL;
1545
1546                                 WDC_LOGD("Num of found peers = %d \n",
1547                                                            (int) rsp.param1);
1548
1549                                 if (num > 0)
1550                                 {
1551                                         buff =
1552                                                 (wfd_discovery_entry_s *) malloc(num * sizeof (wfd_discovery_entry_s));
1553                                         if (buff == NULL)
1554                                         {
1555                                                 WDC_LOGE("malloc() failed!!!.\n");
1556                                                 return WIFI_DIRECT_ERROR_OPERATION_FAILED;
1557                                         }
1558
1559                                         status =
1560                                                 __wfd_client_read_more_data(client_info->sync_sockfd,
1561                                                                                         buff,
1562                                                                                         num *
1563                                                                                         sizeof
1564                                                                                         (wfd_discovery_entry_s));
1565                                         if (status != WIFI_DIRECT_ERROR_NONE)
1566                                         {
1567                                                 if (NULL != buff)
1568                                                         free(buff);
1569                                                 //peer_list = NULL;
1570                                                 WDC_LOGE("socket read error.\n");
1571                                                 return WIFI_DIRECT_ERROR_OPERATION_FAILED;
1572                                         }
1573                                 }
1574
1575                                 __wfd_client_print_entry_list(buff, num);
1576
1577                                 WDC_LOGD("wifi_direct_foreach_discovered_peers() SUCCESS\n");
1578
1579
1580                                 wifi_direct_discovered_peer_info_s *peer_list;
1581
1582                                 for (i = 0; i < num; i++)
1583                                 {
1584                                         peer_list = (wifi_direct_discovered_peer_info_s *) calloc(1, sizeof(wifi_direct_discovered_peer_info_s));
1585                                         peer_list->is_group_owner = buff[i].is_group_owner;
1586                                         peer_list->device_name = strdup(buff[i].device_name);
1587                                         peer_list->mac_address = (char *) calloc(1, 18);
1588                                         snprintf(peer_list->mac_address, 18, MACSTR, MAC2STR(buff[i].mac_address));
1589                                         peer_list->channel = buff[i].channel;
1590                                         peer_list->is_connected = buff[i].is_connected;
1591                                         peer_list->is_persistent_group_owner = buff[i].is_persistent_go;
1592                                         peer_list->interface_address = (char *) calloc(1, 18);
1593                                         snprintf(peer_list->interface_address, 18, MACSTR, MAC2STR(buff[i].intf_mac_address));
1594                                         peer_list->supported_wps_types= buff[i].wps_cfg_methods;
1595                                         peer_list->primary_device_type = buff[i].category;
1596                                         peer_list->secondary_device_type = buff[i].subcategory;
1597
1598                                         if (!callback(peer_list, user_data))
1599                                                 break;
1600                                 }
1601
1602                                 if (NULL != buff)
1603                                         free(buff);
1604
1605                         }
1606                 }
1607                 else
1608                 {
1609                         WDC_LOGE("Error!!! Invalid resp cmd = %d\n",
1610                                                    rsp.cmd);
1611                         return WIFI_DIRECT_ERROR_OPERATION_FAILED;
1612                 }
1613         }
1614
1615         __WDC_LOG_FUNC_END__;
1616
1617         return WIFI_DIRECT_ERROR_NONE;
1618 }
1619
1620
1621 int wifi_direct_connect(const char *mac_address)
1622 {
1623         wifi_direct_client_info_s *client_info = __wfd_get_control();
1624         unsigned char la_mac_addr[6];
1625
1626         __WDC_LOG_FUNC_START__;
1627
1628         if ((client_info->is_registered == false)
1629                 || (client_info->client_id == WFD_INVALID_ID))
1630         {
1631                 WDC_LOGE("Client is NOT registered.\n");
1632                 __WDC_LOG_FUNC_END__;
1633                 return WIFI_DIRECT_ERROR_NOT_INITIALIZED;
1634         }
1635
1636         if (mac_address == NULL)
1637         {
1638                 WDC_LOGE("mac_addr is NULL.\n");
1639                 __WDC_LOG_FUNC_END__;
1640                 return WIFI_DIRECT_ERROR_INVALID_PARAMETER;
1641         }
1642
1643         wifi_direct_client_request_s req;
1644         wifi_direct_client_response_s rsp;
1645
1646         int status = WIFI_DIRECT_ERROR_NONE;
1647
1648         memset(&req, 0, sizeof(wifi_direct_client_request_s));
1649         memset(&rsp, 0, sizeof(wifi_direct_client_response_s));
1650
1651         req.cmd = WIFI_DIRECT_CMD_CONNECT;
1652         req.client_id = client_info->client_id;
1653
1654         macaddr_atoe(mac_address, la_mac_addr);
1655
1656         req.data.mac_addr[0] = la_mac_addr[0];
1657         req.data.mac_addr[1] = la_mac_addr[1];
1658         req.data.mac_addr[2] = la_mac_addr[2];
1659         req.data.mac_addr[3] = la_mac_addr[3];
1660         req.data.mac_addr[4] = la_mac_addr[4];
1661         req.data.mac_addr[5] = la_mac_addr[5];
1662
1663
1664         status =
1665                 __wfd_client_send_request(client_info->sync_sockfd, &req,
1666                                                                   sizeof(wifi_direct_client_request_s));
1667         if (status != WIFI_DIRECT_ERROR_NONE)
1668         {
1669                 WDC_LOGE("Error!!! writing to socket, Errno = %s\n",
1670                                            strerror(errno));
1671                 WDC_LOGE("Error!!! [%s]\n",
1672                                            __wfd_print_error(status));
1673                 client_info->sync_sockfd = -1;
1674                 __wfd_reset_control();
1675                 __WDC_LOG_FUNC_END__;
1676                 return WIFI_DIRECT_ERROR_COMMUNICATION_FAILED;
1677         }
1678
1679         if ((status =
1680                  __wfd_client_read_socket(client_info->sync_sockfd, (char *) &rsp,
1681                                                                   sizeof(wifi_direct_client_response_s))) <= 0)
1682         {
1683                 WDC_LOGE("Error!!! reading socket, status = %d errno = %s\n",
1684                                            status, strerror(errno));
1685                 client_info->sync_sockfd = -1;
1686                 __wfd_reset_control();
1687                 __WDC_LOG_FUNC_END__;
1688                 return WIFI_DIRECT_ERROR_COMMUNICATION_FAILED;
1689         }
1690         else
1691         {
1692                 if (rsp.cmd == WIFI_DIRECT_CMD_CONNECT)
1693                 {
1694                         if (rsp.result != WIFI_DIRECT_ERROR_NONE)
1695                         {
1696                                 WDC_LOGE("Error!!! Result received = %d \n", rsp.result);
1697                                 WDC_LOGE("Error!!! [%s]\n",
1698                                                            __wfd_print_error(rsp.result));
1699                                 __WDC_LOG_FUNC_END__;
1700                                 return rsp.result;
1701                         }
1702                         else
1703                         {
1704                                 WDC_LOGD("wifi_direct_connect() SUCCESS \n");
1705                         }
1706                 }
1707                 else
1708                 {
1709                         WDC_LOGE("Error!!! Invalid resp cmd = %d\n",
1710                                                    rsp.cmd);
1711                         return WIFI_DIRECT_ERROR_OPERATION_FAILED;
1712                 }
1713         }
1714
1715         __WDC_LOG_FUNC_END__;
1716
1717         return WIFI_DIRECT_ERROR_NONE;
1718 }
1719
1720
1721 int wifi_direct_disconnect_all(void)
1722 {
1723         wifi_direct_client_info_s *client_info = __wfd_get_control();
1724
1725         __WDC_LOG_FUNC_START__;
1726
1727         if ((client_info->is_registered == false)
1728                 || (client_info->client_id == WFD_INVALID_ID))
1729         {
1730                 WDC_LOGE("Client is NOT registered.\n");
1731                 __WDC_LOG_FUNC_END__;
1732                 return WIFI_DIRECT_ERROR_NOT_INITIALIZED;
1733         }
1734
1735         wifi_direct_client_request_s req;
1736         wifi_direct_client_response_s rsp;
1737
1738         int status = WIFI_DIRECT_ERROR_NONE;
1739
1740         memset(&req, 0, sizeof(wifi_direct_client_request_s));
1741         memset(&rsp, 0, sizeof(wifi_direct_client_response_s));
1742
1743         req.cmd = WIFI_DIRECT_CMD_DISCONNECT_ALL;
1744         req.client_id = client_info->client_id;
1745
1746         status =
1747                 __wfd_client_send_request(client_info->sync_sockfd, &req,
1748                                                                   sizeof(wifi_direct_client_request_s));
1749         if (status != WIFI_DIRECT_ERROR_NONE)
1750         {
1751                 WDC_LOGE("Error!!! writing to socket, Errno = %s\n", strerror(errno));
1752                 WDC_LOGE("Error!!! [%s]\n", __wfd_print_error(status));
1753                 client_info->sync_sockfd = -1;
1754                 __wfd_reset_control();
1755                 __WDC_LOG_FUNC_END__;
1756                 return WIFI_DIRECT_ERROR_COMMUNICATION_FAILED;
1757         }
1758
1759         if ((status =
1760                  __wfd_client_read_socket(client_info->sync_sockfd, (char *) &rsp,
1761                                                                   sizeof(wifi_direct_client_response_s))) <= 0)
1762         {
1763                 WDC_LOGE("Error!!! reading socket, status = %d errno = %s\n", status, strerror(errno));
1764                 client_info->sync_sockfd = -1;
1765                 __wfd_reset_control();
1766                 __WDC_LOG_FUNC_END__;
1767                 return WIFI_DIRECT_ERROR_COMMUNICATION_FAILED;
1768         }
1769         else
1770         {
1771                 if (rsp.cmd == WIFI_DIRECT_CMD_DISCONNECT_ALL)
1772                 {
1773                         if (rsp.result != WIFI_DIRECT_ERROR_NONE)
1774                         {
1775                                 WDC_LOGE("Error!!! Result received = %d \n", rsp.result);
1776                                 WDC_LOGE("Error!!! [%s]\n",
1777                                                            __wfd_print_error(rsp.result));
1778                                 __WDC_LOG_FUNC_END__;
1779                                 return rsp.result;
1780                         }
1781                         else
1782                         {
1783                                 WDC_LOGE("wifi_direct_disconnect_all() SUCCESS \n");
1784                         }
1785                 }
1786                 else
1787                 {
1788                         WDC_LOGE("Error!!! Invalid resp cmd = %d\n",
1789                                                    rsp.cmd);
1790                         return WIFI_DIRECT_ERROR_OPERATION_FAILED;
1791                 }
1792         }
1793
1794         __WDC_LOG_FUNC_END__;
1795
1796         return WIFI_DIRECT_ERROR_NONE;
1797 }
1798
1799
1800 int wifi_direct_disconnect(const char *mac_address)
1801 {
1802         wifi_direct_client_info_s *client_info = __wfd_get_control();
1803         unsigned char la_mac_addr[6];
1804
1805         __WDC_LOG_FUNC_START__;
1806
1807         if (mac_address == NULL)
1808         {
1809                 WDC_LOGE("mac_address is NULL.\n");
1810                 __WDC_LOG_FUNC_END__;
1811                 return WIFI_DIRECT_ERROR_INVALID_PARAMETER;
1812         }
1813
1814         if ((client_info->is_registered == false)
1815                 || (client_info->client_id == WFD_INVALID_ID))
1816         {
1817                 WDC_LOGE("Client is NOT registered.\n");
1818                 __WDC_LOG_FUNC_END__;
1819                 return WIFI_DIRECT_ERROR_NOT_INITIALIZED;
1820         }
1821
1822         wifi_direct_client_request_s req;
1823         wifi_direct_client_response_s rsp;
1824
1825         int status = WIFI_DIRECT_ERROR_NONE;
1826
1827         memset(&req, 0, sizeof(wifi_direct_client_request_s));
1828         memset(&rsp, 0, sizeof(wifi_direct_client_response_s));
1829
1830         req.cmd = WIFI_DIRECT_CMD_DISCONNECT;
1831         req.client_id = client_info->client_id;
1832
1833         macaddr_atoe(mac_address, la_mac_addr);
1834
1835         req.data.mac_addr[0] = la_mac_addr[0];
1836         req.data.mac_addr[1] = la_mac_addr[1];
1837         req.data.mac_addr[2] = la_mac_addr[2];
1838         req.data.mac_addr[3] = la_mac_addr[3];
1839         req.data.mac_addr[4] = la_mac_addr[4];
1840         req.data.mac_addr[5] = la_mac_addr[5];
1841
1842         status =
1843                 __wfd_client_send_request(client_info->sync_sockfd, &req,
1844                                                                   sizeof(wifi_direct_client_request_s));
1845         if (status != WIFI_DIRECT_ERROR_NONE)
1846         {
1847                 WDC_LOGE("Error!!! writing to socket, Errno = %s\n", strerror(errno));
1848                 WDC_LOGE("Error!!! [%s]\n", __wfd_print_error(status));
1849                 client_info->sync_sockfd = -1;
1850                 __wfd_reset_control();
1851                 __WDC_LOG_FUNC_END__;
1852                 return WIFI_DIRECT_ERROR_COMMUNICATION_FAILED;
1853         }
1854
1855         if ((status =
1856                  __wfd_client_read_socket(client_info->sync_sockfd, (char *) &rsp,
1857                                                                   sizeof(wifi_direct_client_response_s))) <= 0)
1858         {
1859                 WDC_LOGE("Error!!! reading socket, status = %d errno = %s\n",
1860                                            status, strerror(errno));
1861                 client_info->sync_sockfd = -1;
1862                 __wfd_reset_control();
1863                 __WDC_LOG_FUNC_END__;
1864                 return WIFI_DIRECT_ERROR_COMMUNICATION_FAILED;
1865         }
1866         else
1867         {
1868                 if (rsp.cmd == WIFI_DIRECT_CMD_DISCONNECT)
1869                 {
1870                         if (rsp.result != WIFI_DIRECT_ERROR_NONE)
1871                         {
1872                                 WDC_LOGE("Error!!! Result received = %d \n", rsp.result);
1873                                 WDC_LOGE("Error!!! [%s]\n", __wfd_print_error(rsp.result));
1874                                 __WDC_LOG_FUNC_END__;
1875                                 return rsp.result;
1876                         }
1877                         else
1878                         {
1879                                 WDC_LOGE("wifi_direct_disconnect() SUCCESS \n");
1880                         }
1881                 }
1882                 else
1883                 {
1884                         WDC_LOGE("Error!!! Invalid resp cmd = %d\n",
1885                                                    rsp.cmd);
1886                         return WIFI_DIRECT_ERROR_OPERATION_FAILED;
1887                 }
1888         }
1889
1890         __WDC_LOG_FUNC_END__;
1891
1892         return WIFI_DIRECT_ERROR_NONE;
1893
1894 }
1895
1896
1897
1898 int wifi_direct_accept_connection(char *mac_address)
1899 {
1900         wifi_direct_client_info_s *client_info = __wfd_get_control();
1901         unsigned char la_mac_addr[6];
1902
1903         __WDC_LOG_FUNC_START__;
1904
1905         if ((client_info->is_registered == false)
1906                 || (client_info->client_id == WFD_INVALID_ID))
1907         {
1908                 WDC_LOGE("Client is NOT registered.\n");
1909                 __WDC_LOG_FUNC_END__;
1910                 return WIFI_DIRECT_ERROR_NOT_INITIALIZED;
1911         }
1912
1913         if (mac_address == NULL)
1914         {
1915                 WDC_LOGE("mac_addr is NULL.\n");
1916                 __WDC_LOG_FUNC_END__;
1917                 return WIFI_DIRECT_ERROR_INVALID_PARAMETER;
1918         }
1919
1920         wifi_direct_client_request_s req;
1921         wifi_direct_client_response_s rsp;
1922
1923         int status = WIFI_DIRECT_ERROR_NONE;
1924
1925         memset(&req, 0, sizeof(wifi_direct_client_request_s));
1926         memset(&rsp, 0, sizeof(wifi_direct_client_response_s));
1927
1928         req.cmd = WIFI_DIRECT_CMD_SEND_CONNECT_REQ;
1929         req.client_id = client_info->client_id;
1930
1931         macaddr_atoe(mac_address, la_mac_addr);
1932
1933         req.data.mac_addr[0] = la_mac_addr[0];
1934         req.data.mac_addr[1] = la_mac_addr[1];
1935         req.data.mac_addr[2] = la_mac_addr[2];
1936         req.data.mac_addr[3] = la_mac_addr[3];
1937         req.data.mac_addr[4] = la_mac_addr[4];
1938         req.data.mac_addr[5] = la_mac_addr[5];
1939
1940         status =
1941                 __wfd_client_send_request(client_info->sync_sockfd, &req,
1942                                                                   sizeof(wifi_direct_client_request_s));
1943         if (status != WIFI_DIRECT_ERROR_NONE)
1944         {
1945                 WDC_LOGE("Error!!! writing to socket, Errno = %s\n",
1946                                            strerror(errno));
1947                 WDC_LOGE("Error!!! [%s]\n",
1948                                            __wfd_print_error(status));
1949                 client_info->sync_sockfd = -1;
1950                 __wfd_reset_control();
1951                 __WDC_LOG_FUNC_END__;
1952                 return WIFI_DIRECT_ERROR_COMMUNICATION_FAILED;
1953         }
1954
1955         if ((status =
1956                  __wfd_client_read_socket(client_info->sync_sockfd, (char *) &rsp,
1957                                                                   sizeof(wifi_direct_client_response_s))) <= 0)
1958         {
1959                 WDC_LOGE("Error!!! reading socket, status = %d errno = %s\n",
1960                                            status, strerror(errno));
1961                 client_info->sync_sockfd = -1;
1962                 __wfd_reset_control();
1963                 __WDC_LOG_FUNC_END__;
1964                 return WIFI_DIRECT_ERROR_COMMUNICATION_FAILED;
1965         }
1966         else
1967         {
1968                 if (rsp.cmd == WIFI_DIRECT_CMD_SEND_CONNECT_REQ)
1969                 {
1970                         if (rsp.result != WIFI_DIRECT_ERROR_NONE)
1971                         {
1972                                 WDC_LOGE("Error!!! Result received = %d \n", rsp.result);
1973                                 WDC_LOGE("Error!!! [%s]\n",
1974                                                            __wfd_print_error(rsp.result));
1975                                 __WDC_LOG_FUNC_END__;
1976                                 return rsp.result;
1977                         }
1978                         else
1979                         {
1980                                 WDC_LOGE("wifi_direct_connect() SUCCESS \n");
1981                         }
1982                 }
1983                 else
1984                 {
1985                         WDC_LOGE("Error!!! Invalid resp cmd = %d\n",
1986                                                    rsp.cmd);
1987                         return WIFI_DIRECT_ERROR_OPERATION_FAILED;
1988                 }
1989         }
1990
1991         __WDC_LOG_FUNC_END__;
1992
1993         return WIFI_DIRECT_ERROR_NONE;
1994 }
1995
1996
1997 int wifi_direct_foreach_connected_peers(wifi_direct_connected_peer_cb callback, void *user_data)
1998 {
1999         wifi_direct_client_info_s *client_info = __wfd_get_control();
2000
2001         __WDC_LOG_FUNC_START__;
2002
2003         if ((client_info->is_registered == false)
2004                 || (client_info->client_id == WFD_INVALID_ID))
2005         {
2006                 WDC_LOGE("Client is NOT registered.\n");
2007                 __WDC_LOG_FUNC_END__;
2008                 return WIFI_DIRECT_ERROR_NOT_INITIALIZED;
2009         }
2010
2011         if (callback == NULL)
2012         {
2013                 WDC_LOGE("NULL Param [callback]!\n");
2014                 __WDC_LOG_FUNC_END__;
2015                 return WIFI_DIRECT_ERROR_INVALID_PARAMETER;
2016         }
2017
2018         wifi_direct_client_request_s req;
2019         wifi_direct_client_response_s rsp;
2020         int i;
2021
2022         int status = WIFI_DIRECT_ERROR_NONE;
2023
2024         memset(&req, 0, sizeof(wifi_direct_client_request_s));
2025         memset(&rsp, 0, sizeof(wifi_direct_client_response_s));
2026
2027         req.cmd = WIFI_DIRECT_CMD_GET_CONNECTED_PEERS_INFO;
2028         req.client_id = client_info->client_id;
2029
2030         status =
2031                 __wfd_client_send_request(client_info->sync_sockfd, &req,
2032                                                                   sizeof(wifi_direct_client_request_s));
2033         if (status != WIFI_DIRECT_ERROR_NONE)
2034         {
2035                 WDC_LOGE("Error!!! writing to socket, Errno = %s\n",
2036                                            strerror(errno));
2037                 WDC_LOGE("Error!!! [%s]\n",
2038                                            __wfd_print_error(status));
2039                 client_info->sync_sockfd = -1;
2040                 __wfd_reset_control();
2041                 __WDC_LOG_FUNC_END__;
2042                 return WIFI_DIRECT_ERROR_COMMUNICATION_FAILED;
2043         }
2044
2045         if ((status =
2046                  __wfd_client_read_socket(client_info->sync_sockfd, (char *) &rsp,
2047                                                                   sizeof(wifi_direct_client_response_s))) <= 0)
2048         {
2049                 WDC_LOGE("Error!!! reading socket, status = %d errno = %s\n",
2050                                            status, strerror(errno));
2051                 client_info->sync_sockfd = -1;
2052                 __wfd_reset_control();
2053                 __WDC_LOG_FUNC_END__;
2054                 return WIFI_DIRECT_ERROR_COMMUNICATION_FAILED;
2055         }
2056         else
2057         {
2058                 if (rsp.cmd == WIFI_DIRECT_CMD_GET_CONNECTED_PEERS_INFO)
2059                 {
2060                         if (rsp.result != WIFI_DIRECT_ERROR_NONE)
2061                         {
2062                                 WDC_LOGE("Error!!! Result received = %d \n", rsp.result);
2063                                 WDC_LOGE("Error!!! [%s]\n", __wfd_print_error(rsp.result));
2064                                 __WDC_LOG_FUNC_END__;
2065                                 return rsp.result;
2066                         }
2067                         else
2068                         {
2069
2070                                 int num = rsp.param1;
2071                                 int status = 0;
2072                                 wfd_connected_peer_info_s *buff = NULL;
2073
2074                                 WDC_LOGD("Num of connected peers = %d \n",
2075                                                            (int) rsp.param1);
2076
2077                                 if (num > 0)
2078                                 {
2079                                         buff =
2080                                                 (wfd_connected_peer_info_s *) malloc(num *
2081                                                                                                                          sizeof
2082                                                                                                                          (wfd_connected_peer_info_s));
2083                                         if (buff == NULL)
2084                                         {
2085                                                 WDC_LOGE("malloc() failed!!!.\n");
2086                                                 return WIFI_DIRECT_ERROR_OPERATION_FAILED;
2087                                         }
2088
2089                                         status =
2090                                                 __wfd_client_read_more_data(client_info->sync_sockfd,
2091                                                                                                         buff,
2092                                                                                                         num *
2093                                                                                                         sizeof
2094                                                                                                         (wfd_connected_peer_info_s));
2095                                         if (status != WIFI_DIRECT_ERROR_NONE)
2096                                         {
2097                                                 if (NULL != buff)
2098                                                         free(buff);
2099                                                 WDC_LOGE("socket read error.\n");
2100                                                 return WIFI_DIRECT_ERROR_OPERATION_FAILED;
2101                                         }
2102                                 }
2103
2104                                 __wfd_client_print_connected_peer_info(buff, num);
2105
2106                                 WDC_LOGD("wifi_direct_foreach_connected_peers() SUCCESS\n");
2107
2108                                 wifi_direct_connected_peer_info_s *peer_list;
2109
2110                                 for (i = 0; i < num; i++)
2111                                 {
2112                                         peer_list = (wifi_direct_connected_peer_info_s *) calloc(1, sizeof(wifi_direct_connected_peer_info_s));
2113                                         peer_list->device_name = strdup(buff[i].device_name);
2114                                         peer_list->ip_address= (char *) calloc(1, 16);
2115                                         snprintf(peer_list->ip_address, 16, IPSTR, IP2STR(buff[i].ip_address));
2116                                         peer_list->mac_address = (char *) calloc(1, 18);
2117                                         snprintf(peer_list->mac_address, 18, MACSTR, MAC2STR(buff[i].mac_address));
2118                                         peer_list->interface_address = (char *) calloc(1, 18);
2119                                         snprintf(peer_list->interface_address, 18, MACSTR, MAC2STR(buff[i].intf_mac_address));
2120                                         peer_list->p2p_supported = buff[i].is_p2p;
2121                                         peer_list->primary_device_type = buff[i].category;
2122                                         peer_list->channel = buff[i].channel;
2123                                         
2124                                         if (!callback(peer_list, user_data))
2125                                                 break;
2126                                 }
2127
2128                                 if (NULL != buff)
2129                                         free(buff);
2130
2131                         }
2132                 }
2133                 else
2134                 {
2135                         WDC_LOGE("Error!!! Invalid resp cmd = %d\n",
2136                                                    rsp.cmd);
2137                         return WIFI_DIRECT_ERROR_OPERATION_FAILED;
2138                 }
2139         }
2140
2141         __WDC_LOG_FUNC_END__;
2142
2143         return WIFI_DIRECT_ERROR_NONE;
2144 }
2145
2146
2147 int wifi_direct_create_group(void)
2148 {
2149         wifi_direct_client_info_s *client_info = __wfd_get_control();
2150
2151         __WDC_LOG_FUNC_START__;
2152
2153         if ((client_info->is_registered == false)
2154                 || (client_info->client_id == WFD_INVALID_ID))
2155         {
2156                 WDC_LOGE("Client is NOT registered.\n");
2157                 __WDC_LOG_FUNC_END__;
2158                 return WIFI_DIRECT_ERROR_NOT_INITIALIZED;
2159         }
2160
2161         wifi_direct_client_request_s req;
2162         wifi_direct_client_response_s rsp;
2163
2164         int status = WIFI_DIRECT_ERROR_NONE;
2165
2166         memset(&req, 0, sizeof(wifi_direct_client_request_s));
2167         memset(&rsp, 0, sizeof(wifi_direct_client_response_s));
2168
2169         req.cmd = WIFI_DIRECT_CMD_CREATE_GROUP;
2170         req.client_id = client_info->client_id;
2171
2172         status =
2173                 __wfd_client_send_request(client_info->sync_sockfd, &req,
2174                                                                   sizeof(wifi_direct_client_request_s));
2175         if (status != WIFI_DIRECT_ERROR_NONE)
2176         {
2177                 WDC_LOGE("Error!!! writing to socket, Errno = %s\n", strerror(errno));
2178                 WDC_LOGE("Error!!! [%s]\n", __wfd_print_error(status));
2179                 client_info->sync_sockfd = -1;
2180                 __wfd_reset_control();
2181                 __WDC_LOG_FUNC_END__;
2182                 return WIFI_DIRECT_ERROR_COMMUNICATION_FAILED;
2183         }
2184
2185         if ((status =
2186                  __wfd_client_read_socket(client_info->sync_sockfd, (char *) &rsp,
2187                                                                   sizeof(wifi_direct_client_response_s))) <= 0)
2188         {
2189                 WDC_LOGE("Error!!! reading socket, status = %d errno = %s\n",
2190                                            status, strerror(errno));
2191                 client_info->sync_sockfd = -1;
2192                 __wfd_reset_control();
2193                 __WDC_LOG_FUNC_END__;
2194                 return WIFI_DIRECT_ERROR_COMMUNICATION_FAILED;
2195         }
2196         else
2197         {
2198                 if (rsp.cmd == WIFI_DIRECT_CMD_CREATE_GROUP)
2199                 {
2200                         if (rsp.result != WIFI_DIRECT_ERROR_NONE)
2201                         {
2202                                 WDC_LOGE("Error!!! Result received = %d \n", rsp.result);
2203                                 WDC_LOGE("Error!!! [%s]\n", __wfd_print_error(rsp.result));
2204                                 __WDC_LOG_FUNC_END__;
2205                                 return rsp.result;
2206                         }
2207                         else
2208                         {
2209                                 WDC_LOGE("wifi_direct_create_group() SUCCESS \n");
2210                         }
2211                 }
2212                 else
2213                 {
2214                         WDC_LOGE("Error!!! Invalid resp cmd = %d\n", rsp.cmd);
2215                         return WIFI_DIRECT_ERROR_OPERATION_FAILED;
2216                 }
2217         }
2218
2219         __WDC_LOG_FUNC_END__;
2220
2221         return WIFI_DIRECT_ERROR_NONE;
2222 }
2223
2224
2225 int wifi_direct_destroy_group(void)
2226 {
2227         wifi_direct_client_info_s *client_info = __wfd_get_control();
2228
2229         __WDC_LOG_FUNC_START__;
2230
2231         if ((client_info->is_registered == false)
2232                 || (client_info->client_id == WFD_INVALID_ID))
2233         {
2234                 WDC_LOGE("Client is NOT registered.\n");
2235                 __WDC_LOG_FUNC_END__;
2236                 return WIFI_DIRECT_ERROR_NOT_INITIALIZED;
2237         }
2238
2239         wifi_direct_client_request_s req;
2240         wifi_direct_client_response_s rsp;
2241
2242         int status = WIFI_DIRECT_ERROR_NONE;
2243
2244         memset(&req, 0, sizeof(wifi_direct_client_request_s));
2245         memset(&rsp, 0, sizeof(wifi_direct_client_response_s));
2246
2247         req.cmd = WIFI_DIRECT_CMD_CANCEL_GROUP;
2248         req.client_id = client_info->client_id;
2249
2250         status =
2251                 __wfd_client_send_request(client_info->sync_sockfd, &req,
2252                                                                   sizeof(wifi_direct_client_request_s));
2253         if (status != WIFI_DIRECT_ERROR_NONE)
2254         {
2255                 WDC_LOGE("Error!!! writing to socket, Errno = %s\n", strerror(errno));
2256                 WDC_LOGE("Error!!! [%s]\n", __wfd_print_error(status));
2257                 client_info->sync_sockfd = -1;
2258                 __wfd_reset_control();
2259                 __WDC_LOG_FUNC_END__;
2260                 return WIFI_DIRECT_ERROR_COMMUNICATION_FAILED;
2261         }
2262
2263         if ((status =
2264                  __wfd_client_read_socket(client_info->sync_sockfd, (char *) &rsp,
2265                                                                   sizeof(wifi_direct_client_response_s))) <= 0)
2266         {
2267                 WDC_LOGE("Error!!! reading socket, status = %d errno = %s\n",
2268                                            status, strerror(errno));
2269                 client_info->sync_sockfd = -1;
2270                 __wfd_reset_control();
2271                 __WDC_LOG_FUNC_END__;
2272                 return WIFI_DIRECT_ERROR_COMMUNICATION_FAILED;
2273         }
2274         else
2275         {
2276                 if (rsp.cmd == WIFI_DIRECT_CMD_CANCEL_GROUP)
2277                 {
2278                         if (rsp.result != WIFI_DIRECT_ERROR_NONE)
2279                         {
2280                                 WDC_LOGE("Error!!! Result received = %d \n", rsp.result);
2281                                 WDC_LOGE("Error!!! [%s]\n", __wfd_print_error(rsp.result));
2282                                 __WDC_LOG_FUNC_END__;
2283                                 return rsp.result;
2284                         }
2285                         else
2286                         {
2287                                 WDC_LOGE("wifi_direct_destroy_group() SUCCESS \n");
2288                         }
2289                 }
2290                 else
2291                 {
2292                         WDC_LOGE("Error!!! Invalid resp cmd = %d\n",
2293                                                    rsp.cmd);
2294                         return WIFI_DIRECT_ERROR_OPERATION_FAILED;
2295                 }
2296         }
2297
2298         __WDC_LOG_FUNC_END__;
2299
2300         return WIFI_DIRECT_ERROR_NONE;
2301 }
2302
2303
2304 int wifi_direct_is_group_owner(bool * owner)
2305 {
2306         wifi_direct_client_info_s *client_info = __wfd_get_control();
2307
2308         __WDC_LOG_FUNC_START__;
2309
2310         if (owner == NULL)
2311         {
2312                 WDC_LOGE("NULL Param [owner]!\n");
2313                 __WDC_LOG_FUNC_END__;
2314                 return WIFI_DIRECT_ERROR_INVALID_PARAMETER;
2315         }
2316
2317         if ((client_info->is_registered == false)
2318                 || (client_info->client_id == WFD_INVALID_ID))
2319         {
2320                 WDC_LOGE("Client is NOT registered.\n");
2321                 __WDC_LOG_FUNC_END__;
2322                 return WIFI_DIRECT_ERROR_NOT_INITIALIZED;
2323         }
2324
2325         wifi_direct_client_request_s req;
2326         wifi_direct_client_response_s rsp;
2327
2328         int status = WIFI_DIRECT_ERROR_NONE;
2329
2330         memset(&req, 0, sizeof(wifi_direct_client_request_s));
2331         memset(&rsp, 0, sizeof(wifi_direct_client_response_s));
2332
2333         req.cmd = WIFI_DIRECT_CMD_IS_GROUPOWNER;
2334         req.client_id = client_info->client_id;
2335
2336         status =
2337                 __wfd_client_send_request(client_info->sync_sockfd, &req,
2338                                                                   sizeof(wifi_direct_client_request_s));
2339         if (status != WIFI_DIRECT_ERROR_NONE)
2340         {
2341                 WDC_LOGE("Error!!! writing to socket, Errno = %s\n", strerror(errno));
2342                 WDC_LOGE("Error!!! [%s]\n", __wfd_print_error(status));
2343                 client_info->sync_sockfd = -1;
2344                 __wfd_reset_control();
2345                 __WDC_LOG_FUNC_END__;
2346                 return WIFI_DIRECT_ERROR_COMMUNICATION_FAILED;
2347         }
2348
2349         if ((status =
2350                  __wfd_client_read_socket(client_info->sync_sockfd, (char *) &rsp,
2351                                                                   sizeof(wifi_direct_client_response_s))) <= 0)
2352         {
2353                 WDC_LOGE("Error!!! reading socket, status = %d errno = %s\n", status, strerror(errno));
2354                 client_info->sync_sockfd = -1;
2355                 __wfd_reset_control();
2356                 __WDC_LOG_FUNC_END__;
2357                 return WIFI_DIRECT_ERROR_COMMUNICATION_FAILED;
2358         }
2359         else
2360         {
2361                 if (rsp.cmd == WIFI_DIRECT_CMD_IS_GROUPOWNER)
2362                 {
2363                         if (rsp.result != WIFI_DIRECT_ERROR_NONE)
2364                         {
2365                                 WDC_LOGD("Error!!! Result received = %d \n",
2366                                                            rsp.result);
2367                                 WDC_LOGD("Error!!! [%s]\n",
2368                                                            __wfd_print_error(rsp.result));
2369                                 __WDC_LOG_FUNC_END__;
2370                                 return rsp.result;
2371                         }
2372                         else
2373                         {
2374                                 WDC_LOGD("wifi_direct_is_group_owner() %s SUCCESS \n", rsp.param2);
2375                                 *owner = (bool) rsp.param1;
2376                         }
2377                 }
2378                 else
2379                 {
2380                         WDC_LOGE("Error!!! Invalid resp cmd = %d\n",
2381                                                    rsp.cmd);
2382                         return WIFI_DIRECT_ERROR_OPERATION_FAILED;
2383                 }
2384         }
2385
2386         __WDC_LOG_FUNC_END__;
2387
2388         return WIFI_DIRECT_ERROR_NONE;
2389
2390 }
2391
2392
2393 int wifi_direct_is_autonomous_group(bool * autonomous_group)
2394 {
2395         wifi_direct_client_info_s *client_info = __wfd_get_control();
2396
2397         __WDC_LOG_FUNC_START__;
2398
2399         if (autonomous_group == NULL)
2400         {
2401                 WDC_LOGE("NULL Param [autonomous_group]!\n");
2402                 __WDC_LOG_FUNC_END__;
2403                 return WIFI_DIRECT_ERROR_INVALID_PARAMETER;
2404         }
2405
2406         if ((client_info->is_registered == false)
2407                 || (client_info->client_id == WFD_INVALID_ID))
2408         {
2409                 WDC_LOGE("Client is NOT registered.\n");
2410                 __WDC_LOG_FUNC_END__;
2411                 return WIFI_DIRECT_ERROR_NOT_INITIALIZED;
2412         }
2413
2414         wifi_direct_client_request_s req;
2415         wifi_direct_client_response_s rsp;
2416
2417         int status = WIFI_DIRECT_ERROR_NONE;
2418
2419         memset(&req, 0, sizeof(wifi_direct_client_request_s));
2420         memset(&rsp, 0, sizeof(wifi_direct_client_response_s));
2421
2422         req.cmd = WIFI_DIRECT_CMD_IS_AUTONOMOUS_GROUP;
2423         req.client_id = client_info->client_id;
2424
2425         status =
2426                 __wfd_client_send_request(client_info->sync_sockfd, &req,
2427                                                                   sizeof(wifi_direct_client_request_s));
2428         if (status != WIFI_DIRECT_ERROR_NONE)
2429         {
2430                 WDC_LOGE("Error!!! writing to socket, Errno = %s\n", strerror(errno));
2431                 WDC_LOGE("Error!!! [%s]\n", __wfd_print_error(status));
2432                 client_info->sync_sockfd = -1;
2433                 __wfd_reset_control();
2434                 __WDC_LOG_FUNC_END__;
2435                 return WIFI_DIRECT_ERROR_COMMUNICATION_FAILED;
2436         }
2437
2438         if ((status =
2439                  __wfd_client_read_socket(client_info->sync_sockfd, (char *) &rsp,
2440                                                                   sizeof(wifi_direct_client_response_s))) <= 0)
2441         {
2442                 WDC_LOGE("Error!!! reading socket, status = %d errno = %s\n",
2443                                            status, strerror(errno));
2444                 client_info->sync_sockfd = -1;
2445                 __wfd_reset_control();
2446                 __WDC_LOG_FUNC_END__;
2447                 return WIFI_DIRECT_ERROR_COMMUNICATION_FAILED;
2448         }
2449         else
2450         {
2451                 if (rsp.cmd == WIFI_DIRECT_CMD_IS_AUTONOMOUS_GROUP)
2452                 {
2453                         if (rsp.result != WIFI_DIRECT_ERROR_NONE)
2454                         {
2455                                 WDC_LOGD("Error!!! Result received = %d \n", rsp.result);
2456                                 WDC_LOGD("Error!!! [%s]\n", __wfd_print_error(rsp.result));
2457                                 __WDC_LOG_FUNC_END__;
2458                                 return rsp.result;
2459                         }
2460                         else
2461                         {
2462                                 WDC_LOGD("wifi_direct_is_autonomous_group() %s SUCCESS \n", rsp.param2);
2463                                 *autonomous_group = (bool) rsp.param1;
2464                         }
2465                 }
2466                 else
2467                 {
2468                         WDC_LOGE("Error!!! Invalid resp cmd = %d\n",
2469                                                    rsp.cmd);
2470                         return WIFI_DIRECT_ERROR_OPERATION_FAILED;
2471                 }
2472         }
2473
2474         __WDC_LOG_FUNC_END__;
2475
2476         return WIFI_DIRECT_ERROR_NONE;
2477
2478 }
2479
2480
2481 int wifi_direct_set_group_owner_intent(int intent)
2482 {
2483         wifi_direct_client_info_s *client_info = __wfd_get_control();
2484
2485         __WDC_LOG_FUNC_START__;
2486
2487         if ((client_info->is_registered == false)
2488                 || (client_info->client_id == WFD_INVALID_ID))
2489         {
2490                 WDC_LOGE("Client is NOT registered.\n");
2491                 __WDC_LOG_FUNC_END__;
2492                 return WIFI_DIRECT_ERROR_NOT_INITIALIZED;
2493         }
2494
2495         if (intent < 0 || intent > 15)
2496         {
2497                 WDC_LOGE("Invalid Param : intent[%d]\n", intent);
2498                 __WDC_LOG_FUNC_END__;
2499                 return WIFI_DIRECT_ERROR_INVALID_PARAMETER;
2500         }
2501
2502         wifi_direct_client_request_s req;
2503         wifi_direct_client_response_s rsp;
2504
2505         int status = WIFI_DIRECT_ERROR_NONE;
2506
2507         memset(&req, 0, sizeof(wifi_direct_client_request_s));
2508         memset(&rsp, 0, sizeof(wifi_direct_client_response_s));
2509
2510         req.cmd = WIFI_DIRECT_CMD_SET_GO_INTENT;
2511         req.client_id = client_info->client_id;
2512
2513         status =__wfd_client_send_request(client_info->sync_sockfd, &req,
2514                                                                   sizeof(wifi_direct_client_request_s));
2515         if (status != WIFI_DIRECT_ERROR_NONE)
2516         {
2517                 WDC_LOGE("Error!!! writing to socket, Errno = %s\n", strerror(errno));
2518                 WDC_LOGE("Error!!! [%s]\n", __wfd_print_error(status));
2519                 client_info->sync_sockfd = -1;
2520                 __wfd_reset_control();
2521                 __WDC_LOG_FUNC_END__;
2522                 return WIFI_DIRECT_ERROR_COMMUNICATION_FAILED;
2523         }
2524
2525         WDC_LOGD("writing msg hdr is success!\n");
2526
2527         status =
2528                 __wfd_client_send_request(client_info->sync_sockfd, &intent,
2529                                                                   sizeof(int));
2530         if (status != WIFI_DIRECT_ERROR_NONE)
2531         {
2532                 WDC_LOGE("Error!!! writing to socket, Errno = %s\n", strerror(errno));
2533                 WDC_LOGE("Error!!! [%s]\n", __wfd_print_error(status));
2534                 client_info->sync_sockfd = -1;
2535                 __wfd_reset_control();
2536                 __WDC_LOG_FUNC_END__;
2537                 return WIFI_DIRECT_ERROR_COMMUNICATION_FAILED;
2538         }
2539
2540         if ((status =
2541                  __wfd_client_read_socket(client_info->sync_sockfd, (char *) &rsp,
2542                                                                   sizeof(wifi_direct_client_response_s))) <= 0)
2543         {
2544                 WDC_LOGE("Error!!! reading socket, status = %d errno = %s\n", status, strerror(errno));
2545                 client_info->sync_sockfd = -1;
2546                 __wfd_reset_control();
2547                 __WDC_LOG_FUNC_END__;
2548                 return WIFI_DIRECT_ERROR_COMMUNICATION_FAILED;
2549         }
2550         else
2551         {
2552                 if (rsp.cmd == WIFI_DIRECT_CMD_SET_GO_INTENT)
2553                 {
2554                         if (rsp.result != WIFI_DIRECT_ERROR_NONE)
2555                         {
2556                                 WDC_LOGD("Error!!! Result received = %d \n",
2557                                                            rsp.result);
2558                                 WDC_LOGD("Error!!! [%s]\n",
2559                                                            __wfd_print_error(rsp.result));
2560                                 __WDC_LOG_FUNC_END__;
2561                                 return rsp.result;
2562                         }
2563                 }
2564                 else
2565                 {
2566                         WDC_LOGE("Error!!! Invalid resp cmd = %d\n",
2567                                                    rsp.cmd);
2568                         return WIFI_DIRECT_ERROR_OPERATION_FAILED;
2569                 }
2570         }
2571
2572         __WDC_LOG_FUNC_END__;
2573
2574         return WIFI_DIRECT_ERROR_NONE;
2575 }
2576
2577
2578 int wifi_direct_get_group_owner_intent(int* intent)
2579 {
2580         wifi_direct_client_info_s *client_info = __wfd_get_control();
2581
2582         __WDC_LOG_FUNC_START__;
2583
2584         if ((client_info->is_registered == false)
2585                 || (client_info->client_id == WFD_INVALID_ID))
2586         {
2587                 WDC_LOGE("Client is NOT registered.\n");
2588                 __WDC_LOG_FUNC_END__;
2589                 return WIFI_DIRECT_ERROR_NOT_INITIALIZED;
2590         }
2591
2592         wifi_direct_client_request_s req;
2593         wifi_direct_client_response_s rsp;
2594
2595         int status = WIFI_DIRECT_ERROR_NONE;
2596
2597         memset(&req, 0, sizeof(wifi_direct_client_request_s));
2598         memset(&rsp, 0, sizeof(wifi_direct_client_response_s));
2599
2600         req.cmd = WIFI_DIRECT_CMD_GET_GO_INTENT;
2601         req.client_id = client_info->client_id;
2602
2603         status =
2604                 __wfd_client_send_request(client_info->sync_sockfd, &req,
2605                                                                   sizeof(wifi_direct_client_request_s));
2606         if (status != WIFI_DIRECT_ERROR_NONE)
2607         {
2608                 WDC_LOGE("Error!!! writing to socket, Errno = %s\n", strerror(errno));
2609                 WDC_LOGE("Error!!! [%s]\n", __wfd_print_error(status));
2610                 client_info->sync_sockfd = -1;
2611                 __wfd_reset_control();
2612                 __WDC_LOG_FUNC_END__;
2613                 return WIFI_DIRECT_ERROR_COMMUNICATION_FAILED;
2614         }
2615
2616         if ((status =
2617                  __wfd_client_read_socket(client_info->sync_sockfd, (char *) &rsp,
2618                                                                   sizeof(wifi_direct_client_response_s))) <= 0)
2619         {
2620                 WDC_LOGE("Error!!! reading socket, status = %d errno = %s\n", status, strerror(errno));
2621                 client_info->sync_sockfd = -1;
2622                 __wfd_reset_control();
2623                 __WDC_LOG_FUNC_END__;
2624                 return WIFI_DIRECT_ERROR_COMMUNICATION_FAILED;
2625         }
2626         else
2627         {
2628                 if (rsp.cmd == WIFI_DIRECT_CMD_GET_GO_INTENT)
2629                 {
2630                         if (rsp.result != WIFI_DIRECT_ERROR_NONE)
2631                         {
2632                                 WDC_LOGD("Error!!! Result received = %d \n",
2633                                                            rsp.result);
2634                                 WDC_LOGD("Error!!! [%s]\n",
2635                                                            __wfd_print_error(rsp.result));
2636                                 __WDC_LOG_FUNC_END__;
2637                                 return rsp.result;
2638                         }
2639                         else
2640                         {
2641                                 WDC_LOGD("int wifi_direct_get_group_owner_intent() intent[%d] SUCCESS \n", rsp.param1);
2642                                 *intent = rsp.param1;
2643                         }
2644                 }
2645                 else
2646                 {
2647                         WDC_LOGE("Error!!! Invalid resp cmd = %d\n", rsp.cmd);
2648                         return WIFI_DIRECT_ERROR_OPERATION_FAILED;
2649                 }
2650         }
2651
2652         __WDC_LOG_FUNC_END__;
2653
2654         return WIFI_DIRECT_ERROR_NONE;
2655 }
2656
2657 int wifi_direct_set_max_clients(int max)
2658 {
2659         wifi_direct_client_info_s *client_info = __wfd_get_control();
2660
2661         __WDC_LOG_FUNC_START__;
2662
2663         if ((client_info->is_registered == false)
2664                 || (client_info->client_id == WFD_INVALID_ID))
2665         {
2666                 WDC_LOGE("Client is NOT registered.\n");
2667                 __WDC_LOG_FUNC_END__;
2668                 return WIFI_DIRECT_ERROR_NOT_INITIALIZED;
2669         }
2670
2671         WDC_LOGD("max client [%d]\n", max);
2672
2673         wifi_direct_client_request_s req;
2674         wifi_direct_client_response_s rsp;
2675
2676         int status = WIFI_DIRECT_ERROR_NONE;
2677
2678         memset(&req, 0, sizeof(wifi_direct_client_request_s));
2679         memset(&rsp, 0, sizeof(wifi_direct_client_response_s));
2680
2681         req.cmd = WIFI_DIRECT_CMD_SET_MAX_CLIENT;
2682         req.client_id = client_info->client_id;
2683
2684         status =__wfd_client_send_request(client_info->sync_sockfd, &req,
2685                                                                   sizeof(wifi_direct_client_request_s));
2686         if (status != WIFI_DIRECT_ERROR_NONE)
2687         {
2688                 WDC_LOGE("Error!!! writing to socket, Errno = %s\n", strerror(errno));
2689                 WDC_LOGE("Error!!! [%s]\n", __wfd_print_error(status));
2690                 client_info->sync_sockfd = -1;
2691                 __wfd_reset_control();
2692                 __WDC_LOG_FUNC_END__;
2693                 return WIFI_DIRECT_ERROR_COMMUNICATION_FAILED;
2694         }
2695
2696         WDC_LOGD("writing msg hdr is success!\n");
2697
2698         status =
2699                 __wfd_client_send_request(client_info->sync_sockfd, &max,
2700                                                                   sizeof(int));
2701         if (status != WIFI_DIRECT_ERROR_NONE)
2702         {
2703                 WDC_LOGE("Error!!! writing to socket, Errno = %s\n", strerror(errno));
2704                 WDC_LOGE("Error!!! [%s]\n", __wfd_print_error(status));
2705                 client_info->sync_sockfd = -1;
2706                 __wfd_reset_control();
2707                 __WDC_LOG_FUNC_END__;
2708                 return WIFI_DIRECT_ERROR_COMMUNICATION_FAILED;
2709         }
2710
2711         if ((status =
2712                  __wfd_client_read_socket(client_info->sync_sockfd, (char *) &rsp,
2713                                                                   sizeof(wifi_direct_client_response_s))) <= 0)
2714         {
2715                 WDC_LOGE("Error!!! reading socket, status = %d errno = %s\n", status, strerror(errno));
2716                 client_info->sync_sockfd = -1;
2717                 __wfd_reset_control();
2718                 __WDC_LOG_FUNC_END__;
2719                 return WIFI_DIRECT_ERROR_COMMUNICATION_FAILED;
2720         }
2721         else
2722         {
2723                 if (rsp.cmd == WIFI_DIRECT_CMD_SET_MAX_CLIENT)
2724                 {
2725                         if (rsp.result != WIFI_DIRECT_ERROR_NONE)
2726                         {
2727                                 WDC_LOGD("Error!!! Result received = %d \n",
2728                                                            rsp.result);
2729                                 WDC_LOGD("Error!!! [%s]\n",
2730                                                            __wfd_print_error(rsp.result));
2731                                 __WDC_LOG_FUNC_END__;
2732                                 return rsp.result;
2733                         }
2734                 }
2735                 else
2736                 {
2737                         WDC_LOGE("Error!!! Invalid resp cmd = %d\n",
2738                                                    rsp.cmd);
2739                         return WIFI_DIRECT_ERROR_OPERATION_FAILED;
2740                 }
2741         }
2742
2743         __WDC_LOG_FUNC_END__;
2744
2745         return WIFI_DIRECT_ERROR_NONE;
2746 }
2747
2748 int wifi_direct_get_max_clients(int* max)
2749 {
2750         wifi_direct_client_info_s *client_info = __wfd_get_control();
2751
2752         __WDC_LOG_FUNC_START__;
2753
2754         if ((client_info->is_registered == false)
2755                 || (client_info->client_id == WFD_INVALID_ID))
2756         {
2757                 WDC_LOGE("Client is NOT registered.\n");
2758                 __WDC_LOG_FUNC_END__;
2759                 return WIFI_DIRECT_ERROR_NOT_INITIALIZED;
2760         }
2761
2762         wifi_direct_client_request_s req;
2763         wifi_direct_client_response_s rsp;
2764
2765         int status = WIFI_DIRECT_ERROR_NONE;
2766
2767         memset(&req, 0, sizeof(wifi_direct_client_request_s));
2768         memset(&rsp, 0, sizeof(wifi_direct_client_response_s));
2769
2770         req.cmd = WIFI_DIRECT_CMD_GET_MAX_CLIENT;
2771         req.client_id = client_info->client_id;
2772
2773         status =
2774                 __wfd_client_send_request(client_info->sync_sockfd, &req,
2775                                                                   sizeof(wifi_direct_client_request_s));
2776         if (status != WIFI_DIRECT_ERROR_NONE)
2777         {
2778                 WDC_LOGE("Error!!! writing to socket, Errno = %s\n", strerror(errno));
2779                 WDC_LOGE("Error!!! [%s]\n", __wfd_print_error(status));
2780                 client_info->sync_sockfd = -1;
2781                 __wfd_reset_control();
2782                 __WDC_LOG_FUNC_END__;
2783                 return WIFI_DIRECT_ERROR_COMMUNICATION_FAILED;
2784         }
2785
2786         if ((status =
2787                  __wfd_client_read_socket(client_info->sync_sockfd, (char *) &rsp,
2788                                                                   sizeof(wifi_direct_client_response_s))) <= 0)
2789         {
2790                 WDC_LOGE("Error!!! reading socket, status = %d errno = %s\n", status, strerror(errno));
2791                 client_info->sync_sockfd = -1;
2792                 __wfd_reset_control();
2793                 __WDC_LOG_FUNC_END__;
2794                 return WIFI_DIRECT_ERROR_COMMUNICATION_FAILED;
2795         }
2796         else
2797         {
2798                 if (rsp.cmd == WIFI_DIRECT_CMD_GET_MAX_CLIENT)
2799                 {
2800                         if (rsp.result != WIFI_DIRECT_ERROR_NONE)
2801                         {
2802                                 WDC_LOGD("Error!!! Result received = %d \n",
2803                                                            rsp.result);
2804                                 WDC_LOGD("Error!!! [%s]\n",
2805                                                            __wfd_print_error(rsp.result));
2806                                 __WDC_LOG_FUNC_END__;
2807                                 return rsp.result;
2808                         }
2809                         else
2810                         {
2811                                 WDC_LOGD("int wifi_direct_get_max_clients() max_client[%d] SUCCESS \n", rsp.param1);
2812                                 *max = rsp.param1;
2813                         }
2814                 }
2815                 else
2816                 {
2817                         WDC_LOGE("Error!!! Invalid resp cmd = %d\n",
2818                                                    rsp.cmd);
2819                         return WIFI_DIRECT_ERROR_OPERATION_FAILED;
2820                 }
2821         }
2822
2823         __WDC_LOG_FUNC_END__;
2824
2825         return WIFI_DIRECT_ERROR_NONE;
2826 }
2827
2828
2829 /* Deprecated */
2830 int wifi_direct_get_own_group_channel(int* channel)
2831 {
2832         wifi_direct_client_info_s *client_info = __wfd_get_control();
2833
2834         __WDC_LOG_FUNC_START__;
2835
2836         if ((client_info->is_registered == false)
2837                 || (client_info->client_id == WFD_INVALID_ID))
2838         {
2839                 WDC_LOGE("Client is NOT registered.\n");
2840                 __WDC_LOG_FUNC_END__;
2841                 return WIFI_DIRECT_ERROR_NOT_INITIALIZED;
2842         }
2843
2844         wifi_direct_client_request_s req;
2845         wifi_direct_client_response_s rsp;
2846
2847         int ret = WIFI_DIRECT_ERROR_NONE;
2848
2849         memset(&req, 0, sizeof(wifi_direct_client_request_s));
2850         memset(&rsp, 0, sizeof(wifi_direct_client_response_s));
2851
2852         req.cmd = WIFI_DIRECT_CMD_GET_OWN_GROUP_CHANNEL;
2853         req.client_id = client_info->client_id;
2854
2855         ret =
2856                 __wfd_client_send_request(client_info->sync_sockfd, &req,
2857                                                                   sizeof(wifi_direct_client_request_s));
2858         if (ret != WIFI_DIRECT_ERROR_NONE)
2859         {
2860                 WDC_LOGE("Error!!! writing to socket, Errno = %s\n", strerror(errno));
2861                 WDC_LOGE("Error!!! [%s]\n",
2862                                            __wfd_print_error(ret));
2863                 client_info->sync_sockfd = -1;
2864                 __wfd_reset_control();
2865                 __WDC_LOG_FUNC_END__;
2866                 return WIFI_DIRECT_ERROR_COMMUNICATION_FAILED;
2867         }
2868
2869         if ((ret =
2870                  __wfd_client_read_socket(client_info->sync_sockfd, (char *) &rsp,
2871                                                                   sizeof(wifi_direct_client_response_s))) <= 0)
2872         {
2873                 WDC_LOGE("Error!!! reading socket, status = %d errno = %s\n", ret, strerror(errno));
2874                 client_info->sync_sockfd = -1;
2875                 __wfd_reset_control();
2876                 __WDC_LOG_FUNC_END__;
2877                 return WIFI_DIRECT_ERROR_COMMUNICATION_FAILED;
2878         }
2879         else
2880         {
2881                 if (rsp.cmd == WIFI_DIRECT_CMD_GET_OWN_GROUP_CHANNEL)
2882                 {
2883                         if (rsp.result != WIFI_DIRECT_ERROR_NONE)
2884                         {
2885                                 WDC_LOGD("Error!!! Result received = %d \n",
2886                                                            rsp.result);
2887                                 WDC_LOGD("Error!!! [%s]\n",
2888                                                            __wfd_print_error(rsp.result));
2889                                 __WDC_LOG_FUNC_END__;
2890                                 return rsp.result;
2891                         }
2892                         else
2893                         {
2894                                 WDC_LOGD("channel = [%d]\n",
2895                                                            (int) rsp.param1);
2896                                 *channel = rsp.param1;
2897                         }
2898                 }
2899                 else
2900                 {
2901                         WDC_LOGE("Error!!! Invalid resp cmd = %d\n", rsp.cmd);
2902                         return WIFI_DIRECT_ERROR_OPERATION_FAILED;
2903                 }
2904         }
2905
2906         __WDC_LOG_FUNC_END__;
2907
2908         return WIFI_DIRECT_ERROR_NONE;
2909
2910 }
2911
2912
2913 int wifi_direct_get_operating_channel(int* channel)
2914 {
2915         wifi_direct_client_info_s *client_info = __wfd_get_control();
2916
2917         __WDC_LOG_FUNC_START__;
2918
2919         if ((client_info->is_registered == false)
2920                 || (client_info->client_id == WFD_INVALID_ID))
2921         {
2922                 WDC_LOGE("Client is NOT registered.\n");
2923                 __WDC_LOG_FUNC_END__;
2924                 return WIFI_DIRECT_ERROR_NOT_INITIALIZED;
2925         }
2926
2927         wifi_direct_client_request_s req;
2928         wifi_direct_client_response_s rsp;
2929
2930         int ret = WIFI_DIRECT_ERROR_NONE;
2931
2932         memset(&req, 0, sizeof(wifi_direct_client_request_s));
2933         memset(&rsp, 0, sizeof(wifi_direct_client_response_s));
2934
2935         req.cmd = WIFI_DIRECT_CMD_GET_OWN_GROUP_CHANNEL;
2936         req.client_id = client_info->client_id;
2937
2938         ret =
2939                 __wfd_client_send_request(client_info->sync_sockfd, &req,
2940                                                                   sizeof(wifi_direct_client_request_s));
2941         if (ret != WIFI_DIRECT_ERROR_NONE)
2942         {
2943                 WDC_LOGE("Error!!! writing to socket, Errno = %s\n", strerror(errno));
2944                 WDC_LOGE("Error!!! [%s]\n", __wfd_print_error(ret));
2945                 client_info->sync_sockfd = -1;
2946                 __wfd_reset_control();
2947                 __WDC_LOG_FUNC_END__;
2948                 return WIFI_DIRECT_ERROR_COMMUNICATION_FAILED;
2949         }
2950
2951         if ((ret =
2952                  __wfd_client_read_socket(client_info->sync_sockfd, (char *) &rsp,
2953                                                                   sizeof(wifi_direct_client_response_s))) <= 0)
2954         {
2955                 WDC_LOGE("Error!!! reading socket, status = %d errno = %s\n", ret, strerror(errno));
2956                 client_info->sync_sockfd = -1;
2957                 __wfd_reset_control();
2958                 __WDC_LOG_FUNC_END__;
2959                 return WIFI_DIRECT_ERROR_COMMUNICATION_FAILED;
2960         }
2961         else
2962         {
2963                 if (rsp.cmd == WIFI_DIRECT_CMD_GET_OWN_GROUP_CHANNEL)
2964                 {
2965                         if (rsp.result != WIFI_DIRECT_ERROR_NONE)
2966                         {
2967                                 WDC_LOGD("Error!!! Result received = %d \n", rsp.result);
2968                                 WDC_LOGD("Error!!! [%s]\n", __wfd_print_error(rsp.result));
2969                                 __WDC_LOG_FUNC_END__;
2970                                 return rsp.result;
2971                         }
2972                         else
2973                         {
2974                                 WDC_LOGD("channel = [%d]\n", (int) rsp.param1);
2975                                 *channel = rsp.param1;
2976                         }
2977                 }
2978                 else
2979                 {
2980                         WDC_LOGE("Error!!! Invalid resp cmd = %d\n", rsp.cmd);
2981                         return WIFI_DIRECT_ERROR_OPERATION_FAILED;
2982                 }
2983         }
2984
2985         __WDC_LOG_FUNC_END__;
2986
2987         return WIFI_DIRECT_ERROR_NONE;
2988
2989 }
2990
2991
2992 int wifi_direct_set_wpa_passphrase(char *passphrase)
2993 {
2994         wifi_direct_client_info_s *client_info = __wfd_get_control();
2995
2996         __WDC_LOG_FUNC_START__;
2997
2998         if ((client_info->is_registered == false)
2999                 || (client_info->client_id == WFD_INVALID_ID))
3000         {
3001                 WDC_LOGE("Client is NOT registered.\n");
3002                 __WDC_LOG_FUNC_END__;
3003                 return WIFI_DIRECT_ERROR_NOT_INITIALIZED;
3004         }
3005
3006         if (NULL == passphrase)
3007         {
3008                 WDC_LOGE("NULL Param [passphrase]!\n");
3009                 __WDC_LOG_FUNC_END__;
3010                 return WIFI_DIRECT_ERROR_INVALID_PARAMETER;
3011         }
3012
3013         WDC_LOGE("passphrase = [%s]\n", passphrase);
3014
3015         wifi_direct_client_request_s req;
3016         wifi_direct_client_response_s rsp;
3017
3018         int status = WIFI_DIRECT_ERROR_NONE;
3019
3020         memset(&req, 0, sizeof(wifi_direct_client_request_s));
3021         memset(&rsp, 0, sizeof(wifi_direct_client_response_s));
3022
3023         req.cmd = WIFI_DIRECT_CMD_SET_WPA;
3024         req.client_id = client_info->client_id;
3025
3026         status =
3027                 __wfd_client_send_request(client_info->sync_sockfd, &req,
3028                                                                   sizeof(wifi_direct_client_request_s));
3029         if (status != WIFI_DIRECT_ERROR_NONE)
3030         {
3031                 WDC_LOGE("Error!!! writing to socket, Errno = %s\n", strerror(errno));
3032                 WDC_LOGE("Error!!! [%s]\n", __wfd_print_error(status));
3033                 client_info->sync_sockfd = -1;
3034                 __wfd_reset_control();
3035                 __WDC_LOG_FUNC_END__;
3036                 return WIFI_DIRECT_ERROR_COMMUNICATION_FAILED;
3037         }
3038
3039         WDC_LOGD("writing msg hdr is success!\n");
3040
3041         status =
3042                 __wfd_client_send_request(client_info->sync_sockfd, passphrase, 64);
3043         if (status != WIFI_DIRECT_ERROR_NONE)
3044         {
3045                 WDC_LOGE("Error!!! writing to socket, Errno = %s\n", strerror(errno));
3046                 WDC_LOGE("Error!!! [%s]\n", __wfd_print_error(status));
3047                 client_info->sync_sockfd = -1;
3048                 __wfd_reset_control();
3049                 __WDC_LOG_FUNC_END__;
3050                 return WIFI_DIRECT_ERROR_COMMUNICATION_FAILED;
3051         }
3052
3053         if ((status =
3054                  __wfd_client_read_socket(client_info->sync_sockfd, (char *) &rsp,
3055                                                                   sizeof(wifi_direct_client_response_s))) <= 0)
3056         {
3057                 WDC_LOGE("Error!!! reading socket, status = %d errno = %s\n", status, strerror(errno));
3058                 client_info->sync_sockfd = -1;
3059                 __wfd_reset_control();
3060                 __WDC_LOG_FUNC_END__;
3061                 return WIFI_DIRECT_ERROR_COMMUNICATION_FAILED;
3062         }
3063         else
3064         {
3065                 if (rsp.cmd == WIFI_DIRECT_CMD_SET_WPA)
3066                 {
3067                         if (rsp.result != WIFI_DIRECT_ERROR_NONE)
3068                         {
3069                                 WDC_LOGE("Error!!! Result received = %d \n", rsp.result);
3070                                 WDC_LOGE("Error!!! [%s]\n", __wfd_print_error(rsp.result));
3071                                 __WDC_LOG_FUNC_END__;
3072                                 return rsp.result;
3073                         }
3074                 }
3075                 else
3076                 {
3077                         WDC_LOGE("Error!!! Invalid resp cmd = %d\n", rsp.cmd);
3078                         return WIFI_DIRECT_ERROR_OPERATION_FAILED;
3079                 }
3080         }
3081
3082         __WDC_LOG_FUNC_END__;
3083
3084         return WIFI_DIRECT_ERROR_NONE;
3085 }
3086
3087
3088 int wifi_direct_activate_pushbutton(void)
3089 {
3090         wifi_direct_client_info_s *client_info = __wfd_get_control();
3091
3092         __WDC_LOG_FUNC_START__;
3093
3094         if ((client_info->is_registered == false)
3095                 || (client_info->client_id == WFD_INVALID_ID))
3096         {
3097                 WDC_LOGE("Client is NOT registered.\n");
3098                 __WDC_LOG_FUNC_END__;
3099                 return WIFI_DIRECT_ERROR_NOT_INITIALIZED;
3100         }
3101
3102         wifi_direct_client_request_s req;
3103         wifi_direct_client_response_s rsp;
3104
3105         int status = WIFI_DIRECT_ERROR_NONE;
3106
3107         memset(&req, 0, sizeof(wifi_direct_client_request_s));
3108         memset(&rsp, 0, sizeof(wifi_direct_client_response_s));
3109
3110         req.cmd = WIFI_DIRECT_CMD_ACTIVATE_PUSHBUTTON;
3111         req.client_id = client_info->client_id;
3112
3113         status =
3114                 __wfd_client_send_request(client_info->sync_sockfd, &req,
3115                                                                   sizeof(wifi_direct_client_request_s));
3116         if (status != WIFI_DIRECT_ERROR_NONE)
3117         {
3118                 WDC_LOGE("Error!!! writing to socket, Errno = %s\n", strerror(errno));
3119                 WDC_LOGE("Error!!! [%s]\n", __wfd_print_error(status));
3120                 client_info->sync_sockfd = -1;
3121                 __wfd_reset_control();
3122                 __WDC_LOG_FUNC_END__;
3123                 return WIFI_DIRECT_ERROR_COMMUNICATION_FAILED;
3124         }
3125
3126         if ((status =
3127                  __wfd_client_read_socket(client_info->sync_sockfd, (char *) &rsp,
3128                                                                   sizeof(wifi_direct_client_response_s))) <= 0)
3129         {
3130                 WDC_LOGE("Error!!! reading socket, status = %d errno = %s\n",
3131                                            status, strerror(errno));
3132                 client_info->sync_sockfd = -1;
3133                 __wfd_reset_control();
3134                 __WDC_LOG_FUNC_END__;
3135                 return WIFI_DIRECT_ERROR_COMMUNICATION_FAILED;
3136         }
3137         else
3138         {
3139                 if (rsp.cmd == WIFI_DIRECT_CMD_ACTIVATE_PUSHBUTTON)
3140                 {
3141                         if (rsp.result != WIFI_DIRECT_ERROR_NONE)
3142                         {
3143                                 WDC_LOGD("Error!!! Result received = %d \n",
3144                                                            rsp.result);
3145                                 WDC_LOGD("Error!!! [%s]\n",
3146                                                            __wfd_print_error(rsp.result));
3147                                 __WDC_LOG_FUNC_END__;
3148                                 return rsp.result;
3149                         }
3150                         else
3151                         {
3152                                 WDC_LOGD("wifi_direct_activate_pushbutton() SUCCESS");
3153                         }
3154                 }
3155                 else
3156                 {
3157                         WDC_LOGE("Error!!! Invalid resp cmd = %d\n",
3158                                                    rsp.cmd);
3159                         return WIFI_DIRECT_ERROR_OPERATION_FAILED;
3160                 }
3161         }
3162
3163         __WDC_LOG_FUNC_END__;
3164
3165         return WIFI_DIRECT_ERROR_NONE;
3166 }
3167
3168
3169 int wifi_direct_set_wps_pin(char *pin)
3170 {
3171
3172         wifi_direct_client_info_s *client_info = __wfd_get_control();
3173
3174         __WDC_LOG_FUNC_START__;
3175
3176         if ((client_info->is_registered == false)
3177                 || (client_info->client_id == WFD_INVALID_ID))
3178         {
3179                 WDC_LOGE("Client is NOT registered.\n");
3180                 __WDC_LOG_FUNC_END__;
3181                 return WIFI_DIRECT_ERROR_NOT_INITIALIZED;
3182         }
3183
3184         if (NULL == pin)
3185         {
3186                 WDC_LOGE("NULL Param [pin]!\n");
3187                 __WDC_LOG_FUNC_END__;
3188                 return WIFI_DIRECT_ERROR_INVALID_PARAMETER;
3189         }
3190         WDC_LOGE("pin = [%s]\n", pin);
3191
3192         wifi_direct_client_request_s req;
3193         wifi_direct_client_response_s rsp;
3194
3195         int status = WIFI_DIRECT_ERROR_NONE;
3196
3197         memset(&req, 0, sizeof(wifi_direct_client_request_s));
3198         memset(&rsp, 0, sizeof(wifi_direct_client_response_s));
3199
3200         req.cmd = WIFI_DIRECT_CMD_SET_WPS_PIN;
3201         req.client_id = client_info->client_id;
3202
3203         status =
3204                 __wfd_client_send_request(client_info->sync_sockfd, &req,
3205                                                                   sizeof(wifi_direct_client_request_s));
3206         if (status != WIFI_DIRECT_ERROR_NONE)
3207         {
3208                 WDC_LOGE("Error!!! writing to socket, Errno = %s\n", strerror(errno));
3209                 WDC_LOGE("Error!!! [%s]\n", __wfd_print_error(status));
3210                 client_info->sync_sockfd = -1;
3211                 __wfd_reset_control();
3212                 __WDC_LOG_FUNC_END__;
3213                 return WIFI_DIRECT_ERROR_COMMUNICATION_FAILED;
3214         }
3215
3216         WDC_LOGD("writing msg hdr is success!\n");
3217
3218         status =
3219                 __wfd_client_send_request(client_info->sync_sockfd, pin,
3220                                                                   WIFI_DIRECT_WPS_PIN_LEN);
3221         if (status != WIFI_DIRECT_ERROR_NONE)
3222         {
3223                 WDC_LOGE("Error!!! writing to socket, Errno = %s\n", strerror(errno));
3224                 WDC_LOGE("Error!!! [%s]\n", __wfd_print_error(status));
3225                 client_info->sync_sockfd = -1;
3226                 __wfd_reset_control();
3227                 __WDC_LOG_FUNC_END__;
3228                 return WIFI_DIRECT_ERROR_COMMUNICATION_FAILED;
3229         }
3230
3231         if ((status =
3232                  __wfd_client_read_socket(client_info->sync_sockfd, (char *) &rsp,
3233                                                                   sizeof(wifi_direct_client_response_s))) <= 0)
3234         {
3235                 WDC_LOGE( "Error!!! reading socket, status = %d errno = %s\n", status, strerror(errno));
3236                 __WDC_LOG_FUNC_END__;
3237                 return WIFI_DIRECT_ERROR_COMMUNICATION_FAILED;
3238         }
3239         else
3240         {
3241                 if (rsp.cmd == WIFI_DIRECT_CMD_SET_WPS_PIN)
3242                 {
3243                         if (rsp.result != WIFI_DIRECT_ERROR_NONE)
3244                         {
3245                                 WDC_LOGD("Error!!! Result received = %d \n",
3246                                                            rsp.result);
3247                                 WDC_LOGD("Error!!! [%s]\n",
3248                                                            __wfd_print_error(rsp.result));
3249                                 __WDC_LOG_FUNC_END__;
3250                                 return rsp.result;
3251                         }
3252                 }
3253                 else
3254                 {
3255                         WDC_LOGE("Error!!! Invalid resp cmd = %d\n",
3256                                                    rsp.cmd);
3257                         return WIFI_DIRECT_ERROR_OPERATION_FAILED;
3258                 }
3259         }
3260
3261         __WDC_LOG_FUNC_END__;
3262
3263         return WIFI_DIRECT_ERROR_NONE;
3264 }
3265
3266
3267 int wifi_direct_get_wps_pin(char **pin)
3268 {
3269         wifi_direct_client_info_s *client_info = __wfd_get_control();
3270
3271         __WDC_LOG_FUNC_START__;
3272
3273         if ((client_info->is_registered == false)
3274                 || (client_info->client_id == WFD_INVALID_ID))
3275         {
3276                 WDC_LOGE("Client is NOT registered.\n");
3277                 __WDC_LOG_FUNC_END__;
3278                 return WIFI_DIRECT_ERROR_NOT_INITIALIZED;
3279         }
3280
3281         wifi_direct_client_request_s req;
3282         wifi_direct_client_response_s rsp;
3283         char la_pin[WIFI_DIRECT_WPS_PIN_LEN + 1] = { 0, };
3284
3285         int status = WIFI_DIRECT_ERROR_NONE;
3286
3287         memset(&req, 0, sizeof(wifi_direct_client_request_s));
3288         memset(&rsp, 0, sizeof(wifi_direct_client_response_s));
3289
3290         req.cmd = WIFI_DIRECT_CMD_GET_WPS_PIN;
3291         req.client_id = client_info->client_id;
3292
3293         status =
3294                 __wfd_client_send_request(client_info->sync_sockfd, &req,
3295                                                                   sizeof(wifi_direct_client_request_s));
3296         if (status != WIFI_DIRECT_ERROR_NONE)
3297         {
3298                 WDC_LOGE("Error!!! writing to socket, Errno = %s\n", strerror(errno));
3299                 WDC_LOGE("Error!!! [%s]\n", __wfd_print_error(status));
3300                 client_info->sync_sockfd = -1;
3301                 __wfd_reset_control();
3302                 __WDC_LOG_FUNC_END__;
3303                 return WIFI_DIRECT_ERROR_COMMUNICATION_FAILED;
3304         }
3305
3306         if ((status =
3307                  __wfd_client_read_socket(client_info->sync_sockfd, (char *) &rsp,
3308                                                                   sizeof(wifi_direct_client_response_s))) <= 0)
3309         {
3310                 WDC_LOGE("Error!!! reading socket, status = %d errno = %s\n", status, strerror(errno));
3311                 client_info->sync_sockfd = -1;
3312                 __wfd_reset_control();
3313                 __WDC_LOG_FUNC_END__;
3314                 return WIFI_DIRECT_ERROR_COMMUNICATION_FAILED;
3315         }
3316         else
3317         {
3318                 if (rsp.cmd == WIFI_DIRECT_CMD_GET_WPS_PIN)
3319                 {
3320                         if (rsp.result != WIFI_DIRECT_ERROR_NONE)
3321                         {
3322                                 WDC_LOGD("Error!!! Result received = %d \n",
3323                                                            rsp.result);
3324                                 WDC_LOGD("Error!!! [%s]\n",
3325                                                            __wfd_print_error(rsp.result));
3326                                 __WDC_LOG_FUNC_END__;
3327                                 return rsp.result;
3328                         }
3329                         else
3330                         {
3331                                 WDC_LOGD("wifi_direct_get_wps_pin() SUCCESS");
3332                                 strncpy(la_pin, rsp.param2, WIFI_DIRECT_WPS_PIN_LEN);
3333
3334                                 char *temp_pin;
3335                                 temp_pin = strdup(la_pin);
3336
3337                                 *pin = temp_pin;
3338                         }
3339                 }
3340                 else
3341                 {
3342                         WDC_LOGE("Error!!! Invalid resp cmd = %d\n",
3343                                                    rsp.cmd);
3344                         return WIFI_DIRECT_ERROR_OPERATION_FAILED;
3345                 }
3346         }
3347
3348         __WDC_LOG_FUNC_END__;
3349
3350         return WIFI_DIRECT_ERROR_NONE;
3351 }
3352
3353
3354 int wifi_direct_generate_wps_pin(void)
3355 {
3356         wifi_direct_client_info_s *client_info = __wfd_get_control();
3357
3358         __WDC_LOG_FUNC_START__;
3359
3360         if ((client_info->is_registered == false)
3361                 || (client_info->client_id == WFD_INVALID_ID))
3362         {
3363                 WDC_LOGE("Client is NOT registered.\n");
3364                 __WDC_LOG_FUNC_END__;
3365                 return WIFI_DIRECT_ERROR_NOT_INITIALIZED;
3366         }
3367
3368         wifi_direct_client_request_s req;
3369         wifi_direct_client_response_s rsp;
3370
3371         int status = WIFI_DIRECT_ERROR_NONE;
3372
3373         memset(&req, 0, sizeof(wifi_direct_client_request_s));
3374         memset(&rsp, 0, sizeof(wifi_direct_client_response_s));
3375
3376         req.cmd = WIFI_DIRECT_CMD_GENERATE_WPS_PIN;
3377         req.client_id = client_info->client_id;
3378
3379         status =
3380                 __wfd_client_send_request(client_info->sync_sockfd, &req,
3381                                                                   sizeof(wifi_direct_client_request_s));
3382         if (status != WIFI_DIRECT_ERROR_NONE)
3383         {
3384                 WDC_LOGE("Error!!! writing to socket, Errno = %s\n", strerror(errno));
3385                 WDC_LOGE("Error!!! [%s]\n", __wfd_print_error(status));
3386                 client_info->sync_sockfd = -1;
3387                 __wfd_reset_control();
3388                 __WDC_LOG_FUNC_END__;
3389                 return WIFI_DIRECT_ERROR_COMMUNICATION_FAILED;
3390         }
3391
3392         if ((status =
3393                  __wfd_client_read_socket(client_info->sync_sockfd, (char *) &rsp,
3394                                                                   sizeof(wifi_direct_client_response_s))) <= 0)
3395         {
3396                 WDC_LOGE("Error!!! reading socket, status = %d errno = %s\n", status, strerror(errno));
3397                 client_info->sync_sockfd = -1;
3398                 __wfd_reset_control();
3399                 __WDC_LOG_FUNC_END__;
3400                 return WIFI_DIRECT_ERROR_COMMUNICATION_FAILED;
3401         }
3402         else
3403         {
3404                 if (rsp.cmd == WIFI_DIRECT_CMD_GENERATE_WPS_PIN)
3405                 {
3406                         if (rsp.result != WIFI_DIRECT_ERROR_NONE)
3407                         {
3408                                 WDC_LOGD("Error!!! Result received = %d",
3409                                                            rsp.result);
3410                                 WDC_LOGD("Error!!! [%s]\n",
3411                                                            __wfd_print_error(rsp.result));
3412                                 __WDC_LOG_FUNC_END__;
3413                                 return rsp.result;
3414                         }
3415                         else
3416                         {
3417                                 WDC_LOGD("wifi_direct_generate_wps_pin() SUCCESS");
3418                         }
3419                 }
3420                 else
3421                 {
3422                         WDC_LOGE("Error!!! Invalid resp cmd = %d\n",
3423                                                    rsp.cmd);
3424                         return WIFI_DIRECT_ERROR_OPERATION_FAILED;
3425                 }
3426         }
3427
3428         __WDC_LOG_FUNC_END__;
3429
3430         return WIFI_DIRECT_ERROR_NONE;
3431 }
3432
3433
3434 int wifi_direct_get_supported_wps_mode(int *wps_mode)
3435 {
3436         wifi_direct_client_info_s *client_info = __wfd_get_control();
3437
3438         __WDC_LOG_FUNC_START__;
3439
3440         if ((client_info->is_registered == false)
3441                 || (client_info->client_id == WFD_INVALID_ID))
3442         {
3443                 WDC_LOGE("Client is NOT registered.\n");
3444                 __WDC_LOG_FUNC_END__;
3445                 return WIFI_DIRECT_ERROR_NOT_INITIALIZED;
3446         }
3447
3448         wifi_direct_client_request_s req;
3449         wifi_direct_client_response_s rsp;
3450
3451         int ret = WIFI_DIRECT_ERROR_NONE;
3452
3453         memset(&req, 0, sizeof(wifi_direct_client_request_s));
3454         memset(&rsp, 0, sizeof(wifi_direct_client_response_s));
3455
3456         req.cmd = WIFI_DIRECT_CMD_GET_SUPPORTED_WPS_MODE;
3457         req.client_id = client_info->client_id;
3458
3459         ret =
3460                 __wfd_client_send_request(client_info->sync_sockfd, &req,
3461                                                                   sizeof(wifi_direct_client_request_s));
3462         if (ret != WIFI_DIRECT_ERROR_NONE)
3463         {
3464                 WDC_LOGE("Error!!! writing to socket, Errno = %s\n", strerror(errno));
3465                 WDC_LOGE("Error!!! [%s]\n", __wfd_print_error(ret));
3466                 client_info->sync_sockfd = -1;
3467                 __wfd_reset_control();
3468                 __WDC_LOG_FUNC_END__;
3469                 return WIFI_DIRECT_ERROR_COMMUNICATION_FAILED;
3470         }
3471
3472         if ((ret =
3473                  __wfd_client_read_socket(client_info->sync_sockfd, (char *) &rsp,
3474                                                                   sizeof(wifi_direct_client_response_s))) <= 0)
3475         {
3476                 WDC_LOGE("Error!!! reading socket, status = %d errno = %s\n", ret, strerror(errno));
3477                 client_info->sync_sockfd = -1;
3478                 __wfd_reset_control();
3479                 __WDC_LOG_FUNC_END__;
3480                 return WIFI_DIRECT_ERROR_COMMUNICATION_FAILED;
3481         }
3482         else
3483         {
3484                 if (rsp.cmd == WIFI_DIRECT_CMD_GET_SUPPORTED_WPS_MODE)
3485                 {
3486                         if (rsp.result != WIFI_DIRECT_ERROR_NONE)
3487                         {
3488                                 WDC_LOGD("Error!!! Result received = %d \n",
3489                                                            rsp.result);
3490                                 WDC_LOGD("Error!!! [%s]\n",
3491                                                            __wfd_print_error(rsp.result));
3492                                 __WDC_LOG_FUNC_END__;
3493                                 return rsp.result;
3494                         }
3495                         else
3496                         {
3497                                 WDC_LOGD("Supported wps config = [%d]\n",
3498                                                            (int) rsp.param1);
3499                                 *wps_mode = rsp.param1;
3500                         }
3501                 }
3502                 else
3503                 {
3504                         WDC_LOGE("Error!!! Invalid resp cmd = %d\n",
3505                                                    rsp.cmd);
3506                         return WIFI_DIRECT_ERROR_OPERATION_FAILED;
3507                 }
3508         }
3509
3510         __WDC_LOG_FUNC_END__;
3511
3512         return WIFI_DIRECT_ERROR_NONE;
3513
3514 }
3515
3516
3517 int wifi_direct_foreach_supported_wps_types(wifi_direct_supported_wps_type_cb callback, void* user_data)
3518 {
3519         wifi_direct_client_info_s *client_info = __wfd_get_control();
3520
3521         __WDC_LOG_FUNC_START__;
3522
3523         if ((client_info->is_registered == false)
3524                 || (client_info->client_id == WFD_INVALID_ID))
3525         {
3526                 WDC_LOGE("Client is NOT registered.\n");
3527                 __WDC_LOG_FUNC_END__;
3528                 return WIFI_DIRECT_ERROR_NOT_INITIALIZED;
3529         }
3530
3531         if (callback == NULL)
3532         {
3533                 WDC_LOGE("NULL Param [callback]!\n");
3534                 __WDC_LOG_FUNC_END__;
3535                 return WIFI_DIRECT_ERROR_INVALID_PARAMETER;
3536         }
3537
3538         wifi_direct_client_request_s req;
3539         wifi_direct_client_response_s rsp;
3540
3541         int ret = WIFI_DIRECT_ERROR_NONE;
3542
3543         memset(&req, 0, sizeof(wifi_direct_client_request_s));
3544         memset(&rsp, 0, sizeof(wifi_direct_client_response_s));
3545
3546         req.cmd = WIFI_DIRECT_CMD_GET_SUPPORTED_WPS_MODE;
3547         req.client_id = client_info->client_id;
3548
3549         ret =
3550                 __wfd_client_send_request(client_info->sync_sockfd, &req,
3551                                                                   sizeof(wifi_direct_client_request_s));
3552         if (ret != WIFI_DIRECT_ERROR_NONE)
3553         {
3554                 WDC_LOGE("Error!!! writing to socket, Errno = %s\n", strerror(errno));
3555                 WDC_LOGE("Error!!! [%s]\n", __wfd_print_error(ret));
3556                 client_info->sync_sockfd = -1;
3557                 __wfd_reset_control();
3558                 __WDC_LOG_FUNC_END__;
3559                 return WIFI_DIRECT_ERROR_COMMUNICATION_FAILED;
3560         }
3561
3562         if ((ret =
3563                  __wfd_client_read_socket(client_info->sync_sockfd, (char *) &rsp,
3564                                                                   sizeof(wifi_direct_client_response_s))) <= 0)
3565         {
3566                 WDC_LOGE(
3567                                            "Error!!! reading socket, status = %d errno = %s\n", ret,
3568                                            strerror(errno));
3569                 client_info->sync_sockfd = -1;
3570                 __wfd_reset_control();
3571                 __WDC_LOG_FUNC_END__;
3572                 return WIFI_DIRECT_ERROR_COMMUNICATION_FAILED;
3573         }
3574         else
3575         {
3576                 if (rsp.cmd == WIFI_DIRECT_CMD_GET_SUPPORTED_WPS_MODE)
3577                 {
3578                         if (rsp.result != WIFI_DIRECT_ERROR_NONE)
3579                         {
3580                                 WDC_LOGD("Error!!! Result received = %d \n",
3581                                                            rsp.result);
3582                                 WDC_LOGD("Error!!! [%s]\n",
3583                                                            __wfd_print_error(rsp.result));
3584                                 __WDC_LOG_FUNC_END__;
3585                                 return rsp.result;
3586                         }
3587                         else
3588                         {
3589                                 WDC_LOGD( "Supported wps config = [%d]\n",
3590                                                            (int) rsp.param1);
3591                                 int wps_mode;
3592                                 bool result;
3593                                 
3594                                 wps_mode = rsp.param1;
3595
3596                                 if (wps_mode & WIFI_DIRECT_WPS_TYPE_PBC)
3597                                         result = callback(WIFI_DIRECT_WPS_TYPE_PBC, user_data);
3598
3599                                 if ((result == true) && (wps_mode & WIFI_DIRECT_WPS_TYPE_PIN_DISPLAY))
3600                                         result = callback(WIFI_DIRECT_WPS_TYPE_PIN_DISPLAY, user_data);
3601                                         
3602
3603                                 if ((result == true) && (wps_mode & WIFI_DIRECT_WPS_TYPE_PIN_KEYPAD))
3604                                         result = callback(WIFI_DIRECT_WPS_TYPE_PIN_KEYPAD, user_data);
3605                         }
3606                 }
3607                 else
3608                 {
3609                         WDC_LOGE("Error!!! Invalid resp cmd = %d\n",
3610                                                    rsp.cmd);
3611                         return WIFI_DIRECT_ERROR_OPERATION_FAILED;
3612                 }
3613         }
3614
3615         __WDC_LOG_FUNC_END__;
3616
3617         return WIFI_DIRECT_ERROR_NONE;
3618
3619 }
3620
3621
3622 int wifi_direct_set_wps_type(wifi_direct_wps_type_e type)
3623 {
3624         wifi_direct_client_info_s *client_info = __wfd_get_control();
3625
3626         __WDC_LOG_FUNC_START__;
3627
3628         if ((client_info->is_registered == false)
3629                 || (client_info->client_id == WFD_INVALID_ID))
3630         {
3631                 WDC_LOGE("Client is NOT registered.\n");
3632                 __WDC_LOG_FUNC_END__;
3633                 return WIFI_DIRECT_ERROR_NOT_INITIALIZED;
3634         }
3635
3636         if (type == WIFI_DIRECT_WPS_TYPE_PBC
3637                 || type == WIFI_DIRECT_WPS_TYPE_PIN_DISPLAY
3638                 || type == WIFI_DIRECT_WPS_TYPE_PIN_KEYPAD)
3639         {
3640                 WDC_LOGD("Param wps_mode [%d]\n", type);
3641         }
3642         else
3643         {
3644                 WDC_LOGE("Invalid Param [wps_mode]!\n");
3645                 __WDC_LOG_FUNC_END__;
3646                 return WIFI_DIRECT_ERROR_INVALID_PARAMETER;
3647         }
3648
3649         wifi_direct_client_request_s req;
3650         wifi_direct_client_response_s rsp;
3651
3652         int status = WIFI_DIRECT_ERROR_NONE;
3653
3654         memset(&req, 0, sizeof(wifi_direct_client_request_s));
3655         memset(&rsp, 0, sizeof(wifi_direct_client_response_s));
3656
3657         req.cmd = WIFI_DIRECT_CMD_SET_CURRENT_WPS_MODE;
3658         req.client_id = client_info->client_id;
3659
3660         status =__wfd_client_send_request(client_info->sync_sockfd, &req,
3661                                                                   sizeof(wifi_direct_client_request_s));
3662         if (status != WIFI_DIRECT_ERROR_NONE)
3663         {
3664                 WDC_LOGE("Error!!! writing to socket, Errno = %s\n", strerror(errno));
3665                 WDC_LOGE("Error!!! [%s]\n", __wfd_print_error(status));
3666                 client_info->sync_sockfd = -1;
3667                 __wfd_reset_control();
3668                 __WDC_LOG_FUNC_END__;
3669                 return WIFI_DIRECT_ERROR_COMMUNICATION_FAILED;
3670         }
3671
3672         WDC_LOGD("writing msg hdr is success!\n");
3673
3674         status =
3675                 __wfd_client_send_request(client_info->sync_sockfd, &type,
3676                                                                   sizeof(wifi_direct_wps_type_e));
3677         if (status != WIFI_DIRECT_ERROR_NONE)
3678         {
3679                 WDC_LOGE("Error!!! writing to socket, Errno = %s\n", strerror(errno));
3680                 WDC_LOGE("Error!!! [%s]\n", __wfd_print_error(status));
3681                 client_info->sync_sockfd = -1;
3682                 __wfd_reset_control();
3683                 __WDC_LOG_FUNC_END__;
3684                 return WIFI_DIRECT_ERROR_COMMUNICATION_FAILED;
3685         }
3686
3687         if ((status =
3688                  __wfd_client_read_socket(client_info->sync_sockfd, (char *) &rsp,
3689                                                                   sizeof(wifi_direct_client_response_s))) <= 0)
3690         {
3691                 WDC_LOGE("Error!!! reading socket, status = %d errno = %s\n", status, strerror(errno));
3692                 client_info->sync_sockfd = -1;
3693                 __wfd_reset_control();
3694                 __WDC_LOG_FUNC_END__;
3695                 return WIFI_DIRECT_ERROR_COMMUNICATION_FAILED;
3696         }
3697         else
3698         {
3699                 if (rsp.cmd == WIFI_DIRECT_CMD_SET_CURRENT_WPS_MODE)
3700                 {
3701                         if (rsp.result != WIFI_DIRECT_ERROR_NONE)
3702                         {
3703                                 WDC_LOGD("Error!!! Result received = %d \n",
3704                                                            rsp.result);
3705                                 WDC_LOGD("Error!!! [%s]\n",
3706                                                            __wfd_print_error(rsp.result));
3707                                 __WDC_LOG_FUNC_END__;
3708                                 return rsp.result;
3709                         }
3710                 }
3711                 else
3712                 {
3713                         WDC_LOGE("Error!!! Invalid resp cmd = %d\n",
3714                                                    rsp.cmd);
3715                         return WIFI_DIRECT_ERROR_OPERATION_FAILED;
3716                 }
3717         }
3718
3719         __WDC_LOG_FUNC_END__;
3720
3721         return WIFI_DIRECT_ERROR_NONE;
3722 }
3723
3724 int wifi_direct_get_wps_type(wifi_direct_wps_type_e* type)
3725 {
3726         wifi_direct_client_info_s *client_info = __wfd_get_control();
3727
3728         __WDC_LOG_FUNC_START__;
3729
3730         if ((client_info->is_registered == false)
3731                 || (client_info->client_id == WFD_INVALID_ID))
3732         {
3733                 WDC_LOGE("Client is NOT registered.\n");
3734                 __WDC_LOG_FUNC_END__;
3735                 return WIFI_DIRECT_ERROR_NOT_INITIALIZED;
3736         }
3737
3738         if (type == NULL)
3739         {
3740                 WDC_LOGE("NULL Param [type]!\n");
3741                 __WDC_LOG_FUNC_END__;
3742                 return WIFI_DIRECT_ERROR_INVALID_PARAMETER;
3743         }
3744
3745         wifi_direct_client_request_s req;
3746         wifi_direct_client_response_s rsp;
3747         wfd_config_data_s ls_config;
3748
3749         int status = WIFI_DIRECT_ERROR_NONE;
3750
3751         memset(&req, 0, sizeof(wifi_direct_client_request_s));
3752         memset(&rsp, 0, sizeof(wifi_direct_client_response_s));
3753
3754         req.cmd = WIFI_DIRECT_CMD_GET_CONFIG;
3755         req.client_id = client_info->client_id;
3756
3757         status =
3758                 __wfd_client_send_request(client_info->sync_sockfd, &req,
3759                                                                   sizeof(wifi_direct_client_request_s));
3760         if (status != WIFI_DIRECT_ERROR_NONE)
3761         {
3762                 WDC_LOGE("Error!!! writing to socket, Errno = %s\n", strerror(errno));
3763                 WDC_LOGE("Error!!! [%s]\n",
3764                                            __wfd_print_error(status));
3765                 client_info->sync_sockfd = -1;
3766                 __wfd_reset_control();
3767                 __WDC_LOG_FUNC_END__;
3768                 return WIFI_DIRECT_ERROR_COMMUNICATION_FAILED;
3769         }
3770
3771         if ((status =
3772                  __wfd_client_read_socket(client_info->sync_sockfd, (char *) &rsp,
3773                                                                   sizeof(wifi_direct_client_response_s))) <= 0)
3774         {
3775                 WDC_LOGE("Error!!! reading socket, status = %d errno = %s\n", status, strerror(errno));
3776                 client_info->sync_sockfd = -1;
3777                 __wfd_reset_control();
3778                 __WDC_LOG_FUNC_END__;
3779                 return WIFI_DIRECT_ERROR_COMMUNICATION_FAILED;
3780         }
3781         else
3782         {
3783                 if (rsp.cmd == WIFI_DIRECT_CMD_GET_CONFIG)
3784                 {
3785                         if (rsp.result != WIFI_DIRECT_ERROR_NONE)
3786                         {
3787                                 WDC_LOGE("Error!!! Result received = %d \n", rsp.result);
3788                                 WDC_LOGE("Error!!! [%s]\n", __wfd_print_error(rsp.result));
3789                                 __WDC_LOG_FUNC_END__;
3790                                 return rsp.result;
3791                         }
3792                         else
3793                         {
3794                                 int status = 0;
3795
3796                                 WDC_LOGD("Link status = %d \n",
3797                                                            (int) rsp.param1);
3798
3799                                 status =
3800                                         __wfd_client_read_more_data(client_info->sync_sockfd,
3801                                                                                                 &ls_config,
3802                                                                                                 sizeof(wfd_config_data_s));
3803                                 if (status != WIFI_DIRECT_ERROR_NONE)
3804                                 {
3805                                         WDC_LOGE("socket read error.");
3806                                         return WIFI_DIRECT_ERROR_OPERATION_FAILED;
3807                                 }
3808
3809                                 __wfd_client_print_config_data(&ls_config);
3810
3811                                 *type = ls_config.wps_config;
3812
3813                                 WDC_LOGD("wifi_direct_get_wps_type() SUCCESS");
3814                         }
3815                 }
3816                 else
3817                 {
3818                         WDC_LOGE("Error!!! Invalid resp cmd = %d\n", rsp.cmd);
3819                         return WIFI_DIRECT_ERROR_OPERATION_FAILED;
3820                 }
3821         }
3822
3823         __WDC_LOG_FUNC_END__;
3824
3825         return WIFI_DIRECT_ERROR_NONE;
3826 }
3827
3828 /* DPRECATED */
3829 int wifi_direct_set_ssid(const char *ssid)
3830 {
3831         wifi_direct_client_info_s *client_info = __wfd_get_control();
3832
3833         __WDC_LOG_FUNC_START__;
3834
3835         if ((client_info->is_registered == false)
3836                 || (client_info->client_id == WFD_INVALID_ID))
3837         {
3838                 WDC_LOGE("Client is NOT registered.\n");
3839                 __WDC_LOG_FUNC_END__;
3840                 return WIFI_DIRECT_ERROR_NOT_INITIALIZED;
3841         }
3842
3843         if (NULL == ssid)
3844         {
3845                 WDC_LOGE("NULL Param [ssid]!\n");
3846                 __WDC_LOG_FUNC_END__;
3847                 return WIFI_DIRECT_ERROR_INVALID_PARAMETER;
3848         }
3849
3850         WDC_LOGE("ssid = [%s]\n", ssid);
3851
3852         wifi_direct_client_request_s req;
3853         wifi_direct_client_response_s rsp;
3854
3855         int status = WIFI_DIRECT_ERROR_NONE;
3856
3857         memset(&req, 0, sizeof(wifi_direct_client_request_s));
3858         memset(&rsp, 0, sizeof(wifi_direct_client_response_s));
3859
3860         req.cmd = WIFI_DIRECT_CMD_SET_SSID;
3861         req.client_id = client_info->client_id;
3862
3863         status =
3864                 __wfd_client_send_request(client_info->sync_sockfd, &req,
3865                                                                   sizeof(wifi_direct_client_request_s));
3866         if (status != WIFI_DIRECT_ERROR_NONE)
3867         {
3868                 WDC_LOGE("Error!!! writing to socket, Errno = %s\n",
3869                                            strerror(errno));
3870                 WDC_LOGE("Error!!! [%s]\n",
3871                                            __wfd_print_error(status));
3872                 client_info->sync_sockfd = -1;
3873                 __wfd_reset_control();
3874                 __WDC_LOG_FUNC_END__;
3875                 return WIFI_DIRECT_ERROR_COMMUNICATION_FAILED;
3876         }
3877
3878         WDC_LOGD("writing msg hdr is success!");
3879
3880         status =
3881                 __wfd_client_send_request(client_info->sync_sockfd, ssid,
3882                                                                   WIFI_DIRECT_MAX_SSID_LEN);
3883         if (status != WIFI_DIRECT_ERROR_NONE)
3884         {
3885                 WDC_LOGE(
3886                                            "Error!!! writing to socket, Errno = %s\n",
3887                                            strerror(errno));
3888                 WDC_LOGE("Error!!! [%s]\n",
3889                                            __wfd_print_error(status));
3890                 client_info->sync_sockfd = -1;
3891                 __wfd_reset_control();
3892                 __WDC_LOG_FUNC_END__;
3893                 return WIFI_DIRECT_ERROR_COMMUNICATION_FAILED;
3894         }
3895
3896         if ((status =
3897                  __wfd_client_read_socket(client_info->sync_sockfd, (char *) &rsp,
3898                                                                   sizeof(wifi_direct_client_response_s))) <= 0)
3899         {
3900                 WDC_LOGE("Error!!! reading socket, status = %d errno = %s\n", status, strerror(errno));
3901                 client_info->sync_sockfd = -1;
3902                 __wfd_reset_control();
3903                 __WDC_LOG_FUNC_END__;
3904                 return WIFI_DIRECT_ERROR_COMMUNICATION_FAILED;
3905         }
3906         else
3907         {
3908                 if (rsp.cmd == WIFI_DIRECT_CMD_SET_SSID)
3909                 {
3910                         if (rsp.result != WIFI_DIRECT_ERROR_NONE)
3911                         {
3912                                 WDC_LOGE("Error!!! Result received = %d \n", rsp.result);
3913                                 WDC_LOGE("Error!!! [%s]\n",  __wfd_print_error(rsp.result));
3914                                 __WDC_LOG_FUNC_END__;
3915                                 return rsp.result;
3916                         }
3917                 }
3918                 else
3919                 {
3920                         WDC_LOGE("Error!!! Invalid resp cmd = %d\n",
3921                                                    rsp.cmd);
3922                         return WIFI_DIRECT_ERROR_OPERATION_FAILED;
3923                 }
3924         }
3925
3926         __WDC_LOG_FUNC_END__;
3927
3928         return WIFI_DIRECT_ERROR_NONE;
3929 }
3930
3931 int wifi_direct_get_ssid(char **ssid)
3932 {
3933         wifi_direct_client_info_s *client_info = __wfd_get_control();
3934
3935         __WDC_LOG_FUNC_START__;
3936
3937         if (NULL == ssid)
3938         {
3939                 WDC_LOGE("NULL Param [ssid]!\n");
3940                 __WDC_LOG_FUNC_END__;
3941                 return WIFI_DIRECT_ERROR_INVALID_PARAMETER;
3942         }
3943
3944         if ((client_info->is_registered == false)
3945                 || (client_info->client_id == WFD_INVALID_ID))
3946         {
3947                 WDC_LOGE("Client is NOT registered.\n");
3948                 __WDC_LOG_FUNC_END__;
3949                 return WIFI_DIRECT_ERROR_NOT_INITIALIZED;
3950         }
3951
3952         wifi_direct_client_request_s req;
3953         wifi_direct_client_response_s rsp;
3954         char la_ssid[WIFI_DIRECT_MAX_SSID_LEN + 1] = { 0, };
3955
3956         int status = WIFI_DIRECT_ERROR_NONE;
3957
3958         memset(&req, 0, sizeof(wifi_direct_client_request_s));
3959         memset(&rsp, 0, sizeof(wifi_direct_client_response_s));
3960
3961         req.cmd = WIFI_DIRECT_CMD_GET_SSID;
3962         req.client_id = client_info->client_id;
3963
3964         status =
3965                 __wfd_client_send_request(client_info->sync_sockfd, &req,
3966                                                                   sizeof(wifi_direct_client_request_s));
3967         if (status != WIFI_DIRECT_ERROR_NONE)
3968         {
3969                 WDC_LOGE("Error!!! writing to socket, Errno = %s\n", strerror(errno));
3970                 WDC_LOGE("Error!!! [%s]\n",
3971                                            __wfd_print_error(status));
3972                 client_info->sync_sockfd = -1;
3973                 __wfd_reset_control();
3974                 __WDC_LOG_FUNC_END__;
3975                 return WIFI_DIRECT_ERROR_COMMUNICATION_FAILED;
3976         }
3977
3978         if ((status =
3979                  __wfd_client_read_socket(client_info->sync_sockfd, (char *) &rsp,
3980                                                                   sizeof(wifi_direct_client_response_s))) <= 0)
3981         {
3982                 WDC_LOGE("Error!!! reading socket, status = %d errno = %s\n", status, strerror(errno));
3983                 client_info->sync_sockfd = -1;
3984                 __wfd_reset_control();
3985                 __WDC_LOG_FUNC_END__;
3986                 return WIFI_DIRECT_ERROR_COMMUNICATION_FAILED;
3987         }
3988         else
3989         {
3990                 if (rsp.cmd == WIFI_DIRECT_CMD_GET_SSID)
3991                 {
3992                         if (rsp.result != WIFI_DIRECT_ERROR_NONE)
3993                         {
3994                                 WDC_LOGD("Error!!! Result received = %d \n",
3995                                                            rsp.result);
3996                                 WDC_LOGD("Error!!! [%s]\n",
3997                                                            __wfd_print_error(rsp.result));
3998                                 __WDC_LOG_FUNC_END__;
3999                                 return rsp.result;
4000                         }
4001                         else
4002                         {
4003                                 WDC_LOGD(
4004                                                            "wifi_direct_get_ssid() %s SUCCESS \n",
4005                                                            rsp.param2);
4006                                 strncpy(la_ssid, rsp.param2, WIFI_DIRECT_MAX_SSID_LEN);
4007
4008                                 char *temp_ssid = NULL;
4009                                 temp_ssid = strdup(la_ssid);
4010                                 if (NULL == temp_ssid)
4011                                 {
4012                                         WDC_LOGE("Failed to allocate memory for SSID\n");
4013                                         return WIFI_DIRECT_ERROR_OUT_OF_MEMORY;
4014                                 }
4015
4016                                 *ssid = temp_ssid;
4017                         }
4018
4019                 }
4020                 else
4021                 {
4022                         WDC_LOGE("Error!!! Invalid resp cmd = %d\n",
4023                                                    rsp.cmd);
4024                         return WIFI_DIRECT_ERROR_OPERATION_FAILED;
4025                 }
4026         }
4027
4028         __WDC_LOG_FUNC_END__;
4029
4030         return WIFI_DIRECT_ERROR_NONE;
4031 }
4032
4033 int wifi_direct_get_device_name(char** device_name)
4034 {
4035         wifi_direct_client_info_s *client_info = __wfd_get_control();
4036
4037         __WDC_LOG_FUNC_START__;
4038
4039         if (NULL == device_name)
4040         {
4041                 WDC_LOGE("NULL Param [device_name]!\n");
4042                 __WDC_LOG_FUNC_END__;
4043                 return WIFI_DIRECT_ERROR_INVALID_PARAMETER;
4044         }
4045
4046         if ((client_info->is_registered == false)
4047                 || (client_info->client_id == WFD_INVALID_ID))
4048         {
4049                 WDC_LOGE("Client is NOT registered.\n");
4050                 __WDC_LOG_FUNC_END__;
4051                 return WIFI_DIRECT_ERROR_NOT_INITIALIZED;
4052         }
4053
4054         wifi_direct_client_request_s req;
4055         wifi_direct_client_response_s rsp;
4056         char la_device_name[WIFI_DIRECT_MAX_DEVICE_NAME_LEN + 1] = { 0, };
4057
4058         int status = WIFI_DIRECT_ERROR_NONE;
4059
4060         memset(&req, 0, sizeof(wifi_direct_client_request_s));
4061         memset(&rsp, 0, sizeof(wifi_direct_client_response_s));
4062
4063         req.cmd = WIFI_DIRECT_CMD_GET_DEVICE_NAME;
4064         req.client_id = client_info->client_id;
4065
4066         status =
4067                 __wfd_client_send_request(client_info->sync_sockfd, &req,
4068                                                                   sizeof(wifi_direct_client_request_s));
4069         if (status != WIFI_DIRECT_ERROR_NONE)
4070         {
4071                 WDC_LOGE("Error!!! writing to socket, Errno = %s", strerror(errno));
4072                 WDC_LOGE("Error!!! [%s]", __wfd_print_error(status));
4073                 client_info->sync_sockfd = -1;
4074                 __wfd_reset_control();
4075                 __WDC_LOG_FUNC_END__;
4076                 return WIFI_DIRECT_ERROR_COMMUNICATION_FAILED;
4077         }
4078
4079         if ((status =
4080                  __wfd_client_read_socket(client_info->sync_sockfd, (char *) &rsp,
4081                                                                   sizeof(wifi_direct_client_response_s))) <= 0)
4082         {
4083                 WDC_LOGE("Error!!! reading socket, status = %d errno = %s\n", status, strerror(errno));
4084                 client_info->sync_sockfd = -1;
4085                 __wfd_reset_control();
4086                 __WDC_LOG_FUNC_END__;
4087                 return WIFI_DIRECT_ERROR_COMMUNICATION_FAILED;
4088         }
4089         else
4090         {
4091                 if (rsp.cmd == WIFI_DIRECT_CMD_GET_DEVICE_NAME)
4092                 {
4093                         if (rsp.result != WIFI_DIRECT_ERROR_NONE)
4094                         {
4095                                 WDC_LOGD("Error!!! Result received = %d \n",
4096                                                            rsp.result);
4097                                 WDC_LOGD("Error!!! [%s]\n",
4098                                                            __wfd_print_error(rsp.result));
4099                                 __WDC_LOG_FUNC_END__;
4100                                 return rsp.result;
4101                         }
4102                         else
4103                         {
4104                                 WDC_LOGD("wifi_direct_get_device_name() %s SUCCESS \n", rsp.param2);
4105                                 strncpy(la_device_name, rsp.param2, WIFI_DIRECT_MAX_DEVICE_NAME_LEN);
4106
4107                                 char *temp_device_name = NULL;
4108                                 temp_device_name = strdup(la_device_name);
4109                                 if (NULL == temp_device_name)
4110                                 {
4111                                         WDC_LOGE("Failed to allocate memory for device name\n");
4112                                         return WIFI_DIRECT_ERROR_OUT_OF_MEMORY;
4113                                 }
4114
4115                                 *device_name = temp_device_name;
4116                         }
4117
4118                 }
4119                 else
4120                 {
4121                         WDC_LOGE("Error!!! Invalid resp cmd = %d\n",
4122                                                    rsp.cmd);
4123                         return WIFI_DIRECT_ERROR_OPERATION_FAILED;
4124                 }
4125         }
4126
4127         __WDC_LOG_FUNC_END__;
4128
4129         return WIFI_DIRECT_ERROR_NONE;
4130 }
4131
4132
4133 int wifi_direct_set_device_name(const char *device_name)
4134 {
4135         wifi_direct_client_info_s *client_info = __wfd_get_control();
4136
4137         __WDC_LOG_FUNC_START__;
4138
4139         if ((client_info->is_registered == false)
4140                 || (client_info->client_id == WFD_INVALID_ID))
4141         {
4142                 WDC_LOGE("Client is NOT registered.\n");
4143                 __WDC_LOG_FUNC_END__;
4144                 return WIFI_DIRECT_ERROR_NOT_INITIALIZED;
4145         }
4146
4147         if (NULL == device_name)
4148         {
4149                 WDC_LOGE("NULL Param [device_name]!\n");
4150                 __WDC_LOG_FUNC_END__;
4151                 return WIFI_DIRECT_ERROR_INVALID_PARAMETER;
4152         }
4153
4154         WDC_LOGE("device_name = [%s]\n", device_name);
4155
4156         wifi_direct_client_request_s req;
4157         wifi_direct_client_response_s rsp;
4158
4159         int status = WIFI_DIRECT_ERROR_NONE;
4160
4161         memset(&req, 0, sizeof(wifi_direct_client_request_s));
4162         memset(&rsp, 0, sizeof(wifi_direct_client_response_s));
4163
4164         req.cmd = WIFI_DIRECT_CMD_SET_DEVICE_NAME;
4165         req.client_id = client_info->client_id;
4166
4167         status =
4168                 __wfd_client_send_request(client_info->sync_sockfd, &req,
4169                                                                   sizeof(wifi_direct_client_request_s));
4170         if (status != WIFI_DIRECT_ERROR_NONE)
4171         {
4172                 WDC_LOGE("Error!!! writing to socket, Errno = %s\n", strerror(errno));
4173                 WDC_LOGE("Error!!! [%s]\n",
4174                                            __wfd_print_error(status));
4175                 client_info->sync_sockfd = -1;
4176                 __wfd_reset_control();
4177                 __WDC_LOG_FUNC_END__;
4178                 return WIFI_DIRECT_ERROR_COMMUNICATION_FAILED;
4179         }
4180
4181         WDC_LOGD( "writing msg hdr is success!\n");
4182
4183         status =
4184                 __wfd_client_send_request(client_info->sync_sockfd, device_name,
4185                                                                   WIFI_DIRECT_MAX_DEVICE_NAME_LEN);
4186         if (status != WIFI_DIRECT_ERROR_NONE)
4187         {
4188                 WDC_LOGE("Error!!! writing to socket, Errno = %s\n", strerror(errno));
4189                 WDC_LOGE("Error!!! [%s]\n", __wfd_print_error(status));
4190                 client_info->sync_sockfd = -1;
4191                 __wfd_reset_control();
4192                 __WDC_LOG_FUNC_END__;
4193                 return WIFI_DIRECT_ERROR_COMMUNICATION_FAILED;
4194         }
4195
4196         if ((status =
4197                  __wfd_client_read_socket(client_info->sync_sockfd, (char *) &rsp,
4198                                                                   sizeof(wifi_direct_client_response_s))) <= 0)
4199         {
4200                 WDC_LOGE("Error!!! reading socket, status = %d errno = %s\n", status, strerror(errno));
4201                 client_info->sync_sockfd = -1;
4202                 __wfd_reset_control();
4203                 __WDC_LOG_FUNC_END__;
4204                 return WIFI_DIRECT_ERROR_COMMUNICATION_FAILED;
4205         }
4206         else
4207         {
4208                 if (rsp.cmd == WIFI_DIRECT_CMD_SET_DEVICE_NAME)
4209                 {
4210                         if (rsp.result != WIFI_DIRECT_ERROR_NONE)
4211                         {
4212                                 WDC_LOGE("Error!!! Result received = %d \n", rsp.result);
4213                                 WDC_LOGE("Error!!! [%s]\n",
4214                                                            __wfd_print_error(rsp.result));
4215                                 __WDC_LOG_FUNC_END__;
4216                                 return rsp.result;
4217                         }
4218                 }
4219                 else
4220                 {
4221                         WDC_LOGE("Error!!! Invalid resp cmd = %d\n",
4222                                                    rsp.cmd);
4223                         return WIFI_DIRECT_ERROR_OPERATION_FAILED;
4224                 }
4225         }
4226
4227         __WDC_LOG_FUNC_END__;
4228
4229         return WIFI_DIRECT_ERROR_NONE;
4230 }
4231
4232
4233 int wifi_direct_get_network_interface_name(char** name)
4234 {
4235         wifi_direct_client_info_s *client_info = __wfd_get_control();
4236
4237         __WDC_LOG_FUNC_START__;
4238
4239         if (NULL == name)
4240         {
4241                 WDC_LOGE("NULL Param [name]!\n");
4242                 __WDC_LOG_FUNC_END__;
4243                 return WIFI_DIRECT_ERROR_INVALID_PARAMETER;
4244         }
4245
4246         if ((client_info->is_registered == false)
4247                 || (client_info->client_id == WFD_INVALID_ID))
4248         {
4249                 WDC_LOGE("Client is NOT registered.\n");
4250                 __WDC_LOG_FUNC_END__;
4251                 return WIFI_DIRECT_ERROR_NOT_INITIALIZED;
4252         }
4253
4254         wifi_direct_state_e status = 0;
4255         int result;
4256         result = wifi_direct_get_state(&status);
4257         WDC_LOGD("wifi_direct_get_state() state=[%d], result=[%d]\n", status, result);
4258
4259         if( status < WIFI_DIRECT_STATE_CONNECTED)
4260         {
4261                 WDC_LOGE("Device is not connected!\n");
4262                 __WDC_LOG_FUNC_END__;
4263                 return WIFI_DIRECT_ERROR_NOT_PERMITTED;
4264         }
4265
4266         char* get_str = NULL;
4267         get_str = vconf_get_str(VCONFKEY_IFNAME);
4268
4269         if (get_str == NULL)
4270         {
4271                 WDC_LOGD( "vconf (%s) value is NULL!!!\n", VCONFKEY_IFNAME);
4272                 __WDC_LOG_FUNC_END__;
4273                 return WIFI_DIRECT_ERROR_NOT_PERMITTED;
4274         }
4275         else
4276         {
4277                 WDC_LOGD( "VCONFKEY_IFNAME(%s) : %s\n", VCONFKEY_IFNAME, get_str);
4278
4279                 char *temp_ifname = NULL;
4280                 temp_ifname = strdup(get_str);
4281                 if (NULL == temp_ifname)
4282                 {
4283                         WDC_LOGE("Failed to allocate memory for ifname.\n");
4284                         return WIFI_DIRECT_ERROR_OUT_OF_MEMORY;
4285                 }
4286
4287                 *name = temp_ifname;
4288         }
4289
4290         __WDC_LOG_FUNC_END__;
4291
4292         return WIFI_DIRECT_ERROR_NONE;
4293 }
4294
4295
4296
4297 int wifi_direct_get_ip_address(char **ip_address)
4298 {
4299         wifi_direct_client_info_s *client_info = __wfd_get_control();
4300
4301         __WDC_LOG_FUNC_START__;
4302
4303         if (NULL == ip_address)
4304         {
4305                 WDC_LOGE("NULL Param [ip_address]!\n");
4306                 __WDC_LOG_FUNC_END__;
4307                 return WIFI_DIRECT_ERROR_INVALID_PARAMETER;
4308         }
4309
4310         if ((client_info->is_registered == false)
4311                 || (client_info->client_id == WFD_INVALID_ID))
4312         {
4313                 WDC_LOGE("Client is NOT registered.\n");
4314                 __WDC_LOG_FUNC_END__;
4315                 return WIFI_DIRECT_ERROR_NOT_INITIALIZED;
4316         }
4317
4318         wifi_direct_state_e state = 0;
4319         int result;
4320         result = wifi_direct_get_state(&state);
4321         WDC_LOGD( "wifi_direct_get_state() state=[%d], result=[%d]\n", state, result);
4322
4323         if( state < WIFI_DIRECT_STATE_CONNECTED)
4324         {
4325                 WDC_LOGE("Device is not connected!\n");
4326                 __WDC_LOG_FUNC_END__;
4327                 return WIFI_DIRECT_ERROR_NOT_PERMITTED;
4328         }
4329
4330         char* get_str = NULL;
4331         get_str = vconf_get_str(VCONFKEY_LOCAL_IP);
4332
4333         if (get_str == NULL)
4334         {
4335                 WDC_LOGD("vconf (%s) value is NULL!!!\n", VCONFKEY_LOCAL_IP);
4336                 __WDC_LOG_FUNC_END__;
4337                 return WIFI_DIRECT_ERROR_NOT_PERMITTED;
4338         }
4339         else
4340         {
4341                 WDC_LOGD("VCONFKEY_LOCAL_IP(%s) : %s\n", VCONFKEY_LOCAL_IP, get_str);
4342
4343                 char *temp_ip = NULL;
4344                 temp_ip = strdup(get_str);
4345                 if (NULL == temp_ip)
4346                 {
4347                         WDC_LOGE("Failed to allocate memory for local ip address.\n");
4348                         return WIFI_DIRECT_ERROR_OUT_OF_MEMORY;
4349                 }
4350
4351                 *ip_address = temp_ip;
4352         }
4353
4354
4355 #if 0
4356         wifi_direct_client_request_s req;
4357         wifi_direct_client_response_s rsp;
4358         char la_ip[64] = { 0, };
4359
4360         int status = WIFI_DIRECT_ERROR_NONE;
4361
4362         memset(&req, 0, sizeof(wifi_direct_client_request_s));
4363         memset(&rsp, 0, sizeof(wifi_direct_client_response_s));
4364
4365         req.cmd = WIFI_DIRECT_CMD_GET_IP_ADDR;
4366         req.client_id = client_info->client_id;
4367
4368         status =
4369                 __wfd_client_send_request(client_info->sync_sockfd, &req,
4370                                                                   sizeof(wifi_direct_client_request_s));
4371         if (status != WIFI_DIRECT_ERROR_NONE)
4372         {
4373                 WDC_LOGE("Error!!! writing to socket, Errno = %s\n", strerror(errno));
4374                 WDC_LOGE("Error!!! [%s]\n",
4375                                            __wfd_print_error(status));
4376                 client_info->sync_sockfd = -1;
4377                 __wfd_reset_control();
4378                 __WDC_LOG_FUNC_END__;
4379                 return WIFI_DIRECT_ERROR_COMMUNICATION_FAILED;
4380         }
4381
4382         if ((status =
4383                  __wfd_client_read_socket(client_info->sync_sockfd, (char *) &rsp,
4384                                                                   sizeof(wifi_direct_client_response_s))) <= 0)
4385         {
4386                 WDC_LOGE("Error!!! reading socket, status = %d errno = %s\n", status, strerror(errno));
4387                 client_info->sync_sockfd = -1;
4388                 __wfd_reset_control();
4389                 __WDC_LOG_FUNC_END__;
4390                 return WIFI_DIRECT_ERROR_COMMUNICATION_FAILED;
4391         }
4392         else
4393         {
4394                 if (rsp.cmd == WIFI_DIRECT_CMD_GET_IP_ADDR)
4395                 {
4396                         if (rsp.result != WIFI_DIRECT_ERROR_NONE)
4397                         {
4398                                 WDC_LOGD("Error!!! Result received = %d \n",
4399                                                            rsp.result);
4400                                 WDC_LOGD("Error!!! [%s]\n",
4401                                                            __wfd_print_error(rsp.result));
4402                                 __WDC_LOG_FUNC_END__;
4403                                 return rsp.result;
4404                         }
4405                         else
4406                         {
4407                                 WDC_LOGD("wifi_direct_get_ip_address() SUCCESS \n");
4408                                 strncpy(la_ip, rsp.param2, strlen(rsp.param2));
4409
4410                                 char *temp_ip = NULL;
4411                                 temp_ip = strdup(la_ip);
4412                                 if (NULL == temp_ip)
4413                                 {
4414                                         WDC_LOGE("Failed to allocate memory for IP address\n");
4415                                         return WIFI_DIRECT_ERROR_OUT_OF_MEMORY;
4416                                 }
4417
4418                                 *ip_address = temp_ip;
4419                         }
4420                 }
4421                 else
4422                 {
4423                         WDC_LOGE("Error!!! Invalid resp cmd = %d\n",
4424                                                    rsp.cmd);
4425                         return WIFI_DIRECT_ERROR_OPERATION_FAILED;
4426                 }
4427         }
4428 #endif
4429
4430         __WDC_LOG_FUNC_END__;
4431
4432         return WIFI_DIRECT_ERROR_NONE;
4433 }
4434
4435
4436 int wifi_direct_get_subnet_mask(char** subnet_mask)
4437 {
4438         wifi_direct_client_info_s *client_info = __wfd_get_control();
4439
4440         __WDC_LOG_FUNC_START__;
4441
4442         if (NULL == subnet_mask)
4443         {
4444                 WDC_LOGE("NULL Param [subnet_mask]!\n");
4445                 __WDC_LOG_FUNC_END__;
4446                 return WIFI_DIRECT_ERROR_INVALID_PARAMETER;
4447         }
4448
4449         if ((client_info->is_registered == false)
4450                 || (client_info->client_id == WFD_INVALID_ID))
4451         {
4452                 WDC_LOGE("Client is NOT registered.\n");
4453                 __WDC_LOG_FUNC_END__;
4454                 return WIFI_DIRECT_ERROR_NOT_INITIALIZED;
4455         }
4456
4457         wifi_direct_state_e status = 0;
4458         int result;
4459         result = wifi_direct_get_state(&status);
4460         WDC_LOGD("wifi_direct_get_state() state=[%d], result=[%d]\n", status, result);
4461
4462         if( status < WIFI_DIRECT_STATE_CONNECTED)
4463         {
4464                 WDC_LOGE("Device is not connected!\n");
4465                 __WDC_LOG_FUNC_END__;
4466                 return WIFI_DIRECT_ERROR_NOT_PERMITTED;
4467         }
4468
4469
4470         char* get_str = NULL;
4471         get_str = vconf_get_str(VCONFKEY_SUBNET_MASK);
4472
4473         if (get_str == NULL)
4474         {
4475                 WDC_LOGD("vconf (%s) value is NULL!!!\n", VCONFKEY_SUBNET_MASK);
4476                 __WDC_LOG_FUNC_END__;
4477                 return WIFI_DIRECT_ERROR_NOT_PERMITTED;
4478         }
4479         else
4480         {
4481                 WDC_LOGD(VCONFKEY_SUBNET_MASK(%s) : %s\n", VCONFKEY_SUBNET_MASK, get_str);
4482
4483                 char *temp_subnetmask = NULL;
4484                 temp_subnetmask = strdup(get_str);
4485                 if (NULL == temp_subnetmask)
4486                 {
4487                         WDC_LOGE("Failed to allocate memory for subnet mask.\n");
4488                         return WIFI_DIRECT_ERROR_OUT_OF_MEMORY;
4489                 }
4490
4491                 *subnet_mask = temp_subnetmask;
4492         }
4493
4494         __WDC_LOG_FUNC_END__;
4495
4496         return WIFI_DIRECT_ERROR_NONE;
4497 }
4498
4499
4500 int wifi_direct_get_gateway_address(char** gateway_address)
4501 {
4502         wifi_direct_client_info_s *client_info = __wfd_get_control();
4503
4504         __WDC_LOG_FUNC_START__;
4505
4506         if (NULL == gateway_address)
4507         {
4508                 WDC_LOGE("NULL Param [gateway_address]!\n");
4509                 __WDC_LOG_FUNC_END__;
4510                 return WIFI_DIRECT_ERROR_INVALID_PARAMETER;
4511         }
4512
4513         if ((client_info->is_registered == false)
4514                 || (client_info->client_id == WFD_INVALID_ID))
4515         {
4516                 WDC_LOGE("Client is NOT registered.\n");
4517                 __WDC_LOG_FUNC_END__;
4518                 return WIFI_DIRECT_ERROR_NOT_INITIALIZED;
4519         }
4520
4521         wifi_direct_state_e status = 0;
4522         int result;
4523         result = wifi_direct_get_state(&status);
4524         WDC_LOGD("wifi_direct_get_state() state=[%d], result=[%d]\n", status, result);
4525
4526         if( status < WIFI_DIRECT_STATE_CONNECTED)
4527         {
4528                 WDC_LOGE("Device is not connected!\n");
4529                 __WDC_LOG_FUNC_END__;
4530                 return WIFI_DIRECT_ERROR_NOT_PERMITTED;
4531         }
4532
4533         char* get_str = NULL;
4534         get_str = vconf_get_str(VCONFKEY_GATEWAY);
4535
4536         if (get_str == NULL)
4537         {
4538                 WDC_LOGD("vconf (%s) value is NULL!!!\n", VCONFKEY_GATEWAY);
4539                 __WDC_LOG_FUNC_END__;
4540                 return WIFI_DIRECT_ERROR_NOT_PERMITTED;
4541         }
4542         else
4543         {
4544                 WDC_LOGD("VCONFKEY_GATEWAY(%s) : %s", VCONFKEY_GATEWAY, get_str);
4545
4546                 char *temp_gateway = NULL;
4547                 temp_gateway = strdup(get_str);
4548                 if (NULL == temp_gateway)
4549                 {
4550                         WDC_LOGE("Failed to allocate memory for gateway address.");
4551                         return WIFI_DIRECT_ERROR_OUT_OF_MEMORY;
4552                 }
4553
4554                 *gateway_address = temp_gateway;
4555         }
4556
4557         __WDC_LOG_FUNC_END__;
4558
4559         return WIFI_DIRECT_ERROR_NONE;
4560 }
4561
4562
4563 int wifi_direct_get_mac_address(char **mac_address)
4564 {
4565         wifi_direct_client_info_s *client_info = __wfd_get_control();
4566
4567         __WDC_LOG_FUNC_START__;
4568
4569         if (NULL == mac_address)
4570         {
4571                 WDC_LOGE("NULL Param [mac_address]!");
4572                 __WDC_LOG_FUNC_END__;
4573                 return WIFI_DIRECT_ERROR_INVALID_PARAMETER;
4574         }
4575
4576         if ((client_info->is_registered == false)
4577                 || (client_info->client_id == WFD_INVALID_ID))
4578         {
4579                 WDC_LOGD("Client is NOT registered.");
4580                 __WDC_LOG_FUNC_END__;
4581                 return WIFI_DIRECT_ERROR_NOT_INITIALIZED;
4582         }
4583
4584 #if 0
4585         wifi_direct_client_request_s req;
4586         wifi_direct_client_response_s rsp;
4587         unsigned char la_mac_addr[6] = { 0, };
4588
4589         int status = WIFI_DIRECT_ERROR_NONE;
4590
4591         memset(&req, 0, sizeof(wifi_direct_client_request_s));
4592         memset(&rsp, 0, sizeof(wifi_direct_client_response_s));
4593
4594         req.cmd = WIFI_DIRECT_CMD_GET_DEVICE_MAC;
4595         req.client_id = client_info->client_id;
4596
4597         status =
4598                 __wfd_client_send_request(client_info->sync_sockfd, &req,
4599                                                                   sizeof(wifi_direct_client_request_s));
4600         if (status != WIFI_DIRECT_ERROR_NONE)
4601         {
4602                 WDC_LOGD("Error!!! writing to socket, Errno = %s\n", strerror(errno));
4603                 WDC_LOGD("Error!!! [%s]\n", __wfd_print_error(status));
4604                 close(client_info->sync_sockfd);
4605                 __WDC_LOG_FUNC_END__;
4606                 return WIFI_DIRECT_ERROR_COMMUNICATION_FAILED;
4607         }
4608
4609         if ((status =
4610                  __wfd_client_read_socket(client_info->sync_sockfd, (char *) &rsp,
4611                                                                   sizeof(wifi_direct_client_response_s))) <= 0)
4612         {
4613                 WDC_LOGD("Error!!! reading socket, status = %d errno = %s", status, strerror(errno));
4614                 __WDC_LOG_FUNC_END__;
4615                 return WIFI_DIRECT_ERROR_COMMUNICATION_FAILED;
4616         }
4617         else
4618         {
4619                 if (rsp.cmd == WIFI_DIRECT_CMD_GET_DEVICE_MAC)
4620                 {
4621                         if (rsp.result != WIFI_DIRECT_ERROR_NONE)
4622                         {
4623                                 WDC_LOGD("Error!!! Result received = %d", rsp.result);
4624                                 WDC_LOGD("Error!!! [%s]", __wfd_print_error(rsp.result));
4625                                 __WDC_LOG_FUNC_END__;
4626                                 return rsp.result;
4627                         }
4628                         else
4629                         {
4630                                 WDC_LOGD("wifi_direct_get_mac_addr() SUCCESS");
4631                                 strncpy((char *) la_mac_addr, (char *) rsp.param2,
4632                                                 strlen(rsp.param2));
4633
4634                                 char *temp_mac = NULL;
4635                                 temp_mac = (char *) calloc(1, 18);
4636                                 if (NULL == temp_mac)
4637                                 {
4638                                         WDC_LOGE("Failed to allocate memory for MAC address");
4639                                         return WIFI_DIRECT_ERROR_OUT_OF_MEMORY;
4640                                 }
4641     
4642                                 sprintf(temp_mac, MACSTR, MAC2STR(la_mac_addr));
4643
4644                                 *mac_address = temp_mac;
4645
4646                         }
4647                 }
4648                 else
4649                 {
4650                         WDC_LOGE("Error!!! Invalid resp cmd = %d",
4651                                                    rsp.cmd);
4652                         return WIFI_DIRECT_ERROR_OPERATION_FAILED;
4653                 }
4654         }
4655
4656 #else
4657         int fd;
4658         int n;
4659         char mac_info[18];
4660         unsigned char la_mac_addr[6];
4661
4662         memset(mac_info, 0, sizeof(mac_info));
4663         
4664         if( (fd = open(WIFI_DIRECT_MAC_ADDRESS_INFO_FILE, O_RDONLY)) == -1)
4665         {
4666                 WDC_LOGE("[.mac.info] file open failed.");
4667                 __WDC_LOG_FUNC_END__;
4668                 return WIFI_DIRECT_ERROR_OPERATION_FAILED;
4669         }
4670
4671         n = read(fd, mac_info, 18);
4672         if(n < 0)
4673         {
4674                 WDC_LOGE("[.mac.info] file read failed.");
4675                 __WDC_LOG_FUNC_END__;
4676                 return WIFI_DIRECT_ERROR_OPERATION_FAILED;
4677         }
4678
4679         WDC_LOGD("mac_address = [%s]", mac_info);
4680
4681         memset(la_mac_addr, 0, sizeof(la_mac_addr));
4682         macaddr_atoe(mac_info, la_mac_addr);
4683         la_mac_addr[0] = la_mac_addr[0] | 0x02;
4684         la_mac_addr[1] = la_mac_addr[1];
4685         la_mac_addr[2] = la_mac_addr[2];
4686         la_mac_addr[3] = la_mac_addr[3];
4687         la_mac_addr[4] = la_mac_addr[4];
4688         la_mac_addr[5] = la_mac_addr[5];
4689
4690         char *temp_mac = NULL;
4691         temp_mac = (char *) calloc(1, 18);
4692         if (NULL == temp_mac)
4693         {
4694                 WDC_LOGE("Failed to allocate memory for MAC address");
4695                 return WIFI_DIRECT_ERROR_OUT_OF_MEMORY;
4696         }
4697
4698         //strncpy(temp_mac, mac_info, strlen(mac_info));
4699         snprintf(temp_mac, 18, MACSTR, MAC2STR(la_mac_addr));
4700
4701         *mac_address = temp_mac;
4702         
4703 #endif
4704
4705         __WDC_LOG_FUNC_END__;
4706
4707         return WIFI_DIRECT_ERROR_NONE;
4708 }
4709
4710
4711 int wifi_direct_get_state(wifi_direct_state_e * state)
4712 {
4713         wifi_direct_client_info_s *client_info = __wfd_get_control();
4714
4715         __WDC_LOG_FUNC_START__;
4716
4717         if (NULL == state)
4718         {
4719                 WDC_LOGE("NULL Param [state]!");
4720                 __WDC_LOG_FUNC_END__;
4721                 return WIFI_DIRECT_ERROR_INVALID_PARAMETER;
4722         }
4723
4724         if ((client_info->is_registered == false)
4725                 || (client_info->client_id == WFD_INVALID_ID))
4726         {
4727                 WDC_LOGE("Client is NOT registered.");
4728                 __WDC_LOG_FUNC_END__;
4729                 return WIFI_DIRECT_ERROR_NOT_INITIALIZED;
4730         }
4731
4732         wifi_direct_client_request_s req;
4733         wifi_direct_client_response_s rsp;
4734
4735         int ret = WIFI_DIRECT_ERROR_NONE;
4736
4737         memset(&req, 0, sizeof(wifi_direct_client_request_s));
4738         memset(&rsp, 0, sizeof(wifi_direct_client_response_s));
4739
4740         req.cmd = WIFI_DIRECT_CMD_GET_LINK_STATUS;
4741         req.client_id = client_info->client_id;
4742
4743         ret =
4744                 __wfd_client_send_request(client_info->sync_sockfd, &req,
4745                                                                   sizeof(wifi_direct_client_request_s));
4746         if (ret != WIFI_DIRECT_ERROR_NONE)
4747         {
4748                 WDC_LOGE("Error!!! writing to socket, Errno = %s", strerror(errno));
4749                 WDC_LOGE("Error!!! [%s]", __wfd_print_error(ret));
4750                 client_info->sync_sockfd = -1;
4751                 __wfd_reset_control();
4752                 __WDC_LOG_FUNC_END__;
4753                 return WIFI_DIRECT_ERROR_COMMUNICATION_FAILED;
4754         }
4755
4756         if ((ret =
4757                  __wfd_client_read_socket(client_info->sync_sockfd, (char *) &rsp,
4758                                                                   sizeof(wifi_direct_client_response_s))) <= 0)
4759         {
4760                 WDC_LOGE("Error!!! reading socket, status = %d errno = %s", ret,
4761                                            strerror(errno));
4762                 client_info->sync_sockfd = -1;
4763                 __wfd_reset_control();
4764                 __WDC_LOG_FUNC_END__;
4765                 return WIFI_DIRECT_ERROR_COMMUNICATION_FAILED;
4766         }
4767         else
4768         {
4769                 if (rsp.cmd == WIFI_DIRECT_CMD_GET_LINK_STATUS)
4770                 {
4771                         if (rsp.result != WIFI_DIRECT_ERROR_NONE)
4772                         {
4773                                 WDC_LOGD("Error!!! Result received = %d %s", rsp.result, __wfd_print_error(rsp.result));
4774                                 __WDC_LOG_FUNC_END__;
4775                                 return rsp.result;
4776                         }
4777                         else
4778                         {
4779                                 WDC_LOGD("Link Status = %d", (int) rsp.param1);
4780                                 *state = (wifi_direct_state_e) rsp.param1;
4781
4782                                 /* for CAPI : there is no WIFI_DIRECT_STATE_GROUP_OWNER type in CAPI */
4783                                 if(*state == WIFI_DIRECT_STATE_GROUP_OWNER)
4784                                         *state = WIFI_DIRECT_STATE_CONNECTED;
4785                                 
4786                         }
4787                 }
4788                 else
4789                 {
4790                         WDC_LOGE("Error!!! Invalid resp cmd = %d", rsp.cmd);
4791                         return WIFI_DIRECT_ERROR_OPERATION_FAILED;
4792                 }
4793         }
4794
4795         __WDC_LOG_FUNC_END__;
4796
4797         return WIFI_DIRECT_ERROR_NONE;
4798 }
4799
4800
4801 int wifi_direct_is_discoverable(bool* discoverable)
4802 {
4803         wifi_direct_client_info_s *client_info = __wfd_get_control();
4804
4805         __WDC_LOG_FUNC_START__;
4806
4807         if (discoverable == NULL)
4808         {
4809                 WDC_LOGE("NULL Param [discoverable]!");
4810                 __WDC_LOG_FUNC_END__;
4811                 return WIFI_DIRECT_ERROR_INVALID_PARAMETER;
4812         }
4813
4814         if ((client_info->is_registered == false)
4815                 || (client_info->client_id == WFD_INVALID_ID))
4816         {
4817                 WDC_LOGE("Client is NOT registered.");
4818                 __WDC_LOG_FUNC_END__;
4819                 return WIFI_DIRECT_ERROR_NOT_INITIALIZED;
4820         }
4821
4822         wifi_direct_client_request_s req;
4823         wifi_direct_client_response_s rsp;
4824
4825         int status = WIFI_DIRECT_ERROR_NONE;
4826
4827         memset(&req, 0, sizeof(wifi_direct_client_request_s));
4828         memset(&rsp, 0, sizeof(wifi_direct_client_response_s));
4829
4830         req.cmd = WIFI_DIRECT_CMD_IS_DISCOVERABLE;
4831         req.client_id = client_info->client_id;
4832
4833         status =
4834                 __wfd_client_send_request(client_info->sync_sockfd, &req,
4835                                                                   sizeof(wifi_direct_client_request_s));
4836         if (status != WIFI_DIRECT_ERROR_NONE)
4837         {
4838                 WDC_LOGE("Error!!! writing to socket, Errno = %s", strerror(errno));
4839                 WDC_LOGE("Error!!! [%s]", __wfd_print_error(status));
4840                 client_info->sync_sockfd = -1;
4841                 __wfd_reset_control();
4842                 __WDC_LOG_FUNC_END__;
4843                 return WIFI_DIRECT_ERROR_COMMUNICATION_FAILED;
4844         }
4845
4846         if ((status =
4847                  __wfd_client_read_socket(client_info->sync_sockfd, (char *) &rsp,
4848                                                                   sizeof(wifi_direct_client_response_s))) <= 0)
4849         {
4850                 WDC_LOGE("Error!!! reading socket, status = %d errno = %s", status, strerror(errno));
4851                 client_info->sync_sockfd = -1;
4852                 __wfd_reset_control();
4853                 __WDC_LOG_FUNC_END__;
4854                 return WIFI_DIRECT_ERROR_COMMUNICATION_FAILED;
4855         }
4856         else
4857         {
4858                 if (rsp.cmd == WIFI_DIRECT_CMD_IS_DISCOVERABLE)
4859                 {
4860                         if (rsp.result != WIFI_DIRECT_ERROR_NONE)
4861                         {
4862                                 WDC_LOGD("Error!!! Result received = %d", rsp.result);
4863                                 WDC_LOGD("Error!!! [%s]", __wfd_print_error(rsp.result));
4864                                 __WDC_LOG_FUNC_END__;
4865                                 return rsp.result;
4866                         }
4867                         else
4868                         {
4869                                 WDC_LOGD("wifi_direct_is_discoverable() %s SUCCESS", rsp.param2);
4870                                 *discoverable = (bool) rsp.param1;
4871                         }
4872                 }
4873                 else
4874                 {
4875                         WDC_LOGE("Error!!! Invalid resp cmd = %d", rsp.cmd);
4876                         return WIFI_DIRECT_ERROR_OPERATION_FAILED;
4877                 }
4878         }
4879
4880         __WDC_LOG_FUNC_END__;
4881
4882         return WIFI_DIRECT_ERROR_NONE;
4883
4884 }
4885
4886
4887 int wifi_direct_is_listening_only(bool* listen_only)
4888 {
4889         wifi_direct_client_info_s *client_info = __wfd_get_control();
4890
4891         __WDC_LOG_FUNC_START__;
4892
4893         if (listen_only == NULL)
4894         {
4895                 WDC_LOGE("NULL Param [listen_only]!");
4896                 __WDC_LOG_FUNC_END__;
4897                 return WIFI_DIRECT_ERROR_INVALID_PARAMETER;
4898         }
4899
4900         if ((client_info->is_registered == false)
4901                 || (client_info->client_id == WFD_INVALID_ID))
4902         {
4903                 WDC_LOGE("Client is NOT registered.");
4904                 __WDC_LOG_FUNC_END__;
4905                 return WIFI_DIRECT_ERROR_NOT_INITIALIZED;
4906         }
4907
4908         wifi_direct_client_request_s req;
4909         wifi_direct_client_response_s rsp;
4910
4911         int status = WIFI_DIRECT_ERROR_NONE;
4912
4913         memset(&req, 0, sizeof(wifi_direct_client_request_s));
4914         memset(&rsp, 0, sizeof(wifi_direct_client_response_s));
4915
4916         req.cmd = WIFI_DIRECT_CMD_IS_LISTENING_ONLY;
4917         req.client_id = client_info->client_id;
4918
4919         status =
4920                 __wfd_client_send_request(client_info->sync_sockfd, &req,
4921                                                                   sizeof(wifi_direct_client_request_s));
4922         if (status != WIFI_DIRECT_ERROR_NONE)
4923         {
4924                 WDC_LOGE("Error!!! writing to socket, Errno = %s", strerror(errno));
4925                 WDC_LOGE("Error!!! [%s]", __wfd_print_error(status));
4926                 client_info->sync_sockfd = -1;
4927                 __wfd_reset_control();
4928                 __WDC_LOG_FUNC_END__;
4929                 return WIFI_DIRECT_ERROR_COMMUNICATION_FAILED;
4930         }
4931
4932         if ((status =
4933                  __wfd_client_read_socket(client_info->sync_sockfd, (char *) &rsp,
4934                                                                   sizeof(wifi_direct_client_response_s))) <= 0)
4935         {
4936                 WDC_LOGE("Error!!! reading socket, status = %d errno = %s", status, strerror(errno));
4937                 client_info->sync_sockfd = -1;
4938                 __wfd_reset_control();
4939                 __WDC_LOG_FUNC_END__;
4940                 return WIFI_DIRECT_ERROR_COMMUNICATION_FAILED;
4941         }
4942         else
4943         {
4944                 if (rsp.cmd == WIFI_DIRECT_CMD_IS_LISTENING_ONLY)
4945                 {
4946                         if (rsp.result != WIFI_DIRECT_ERROR_NONE)
4947                         {
4948                                 WDC_LOGD("Error!!! Result received = %d", rsp.result);
4949                                 WDC_LOGD("Error!!! [%s]", __wfd_print_error(rsp.result));
4950                                 __WDC_LOG_FUNC_END__;
4951                                 return rsp.result;
4952                         }
4953                         else
4954                         {
4955                                 WDC_LOGD("wifi_direct_is_listening_only() %s SUCCESS", rsp.param2);
4956                                 *listen_only = (bool) rsp.param1;
4957                         }
4958                 }
4959                 else
4960                 {
4961                         WDC_LOGE("Error!!! Invalid resp cmd = %d", rsp.cmd);
4962                         return WIFI_DIRECT_ERROR_OPERATION_FAILED;
4963                 }
4964         }
4965
4966         __WDC_LOG_FUNC_END__;
4967
4968         return WIFI_DIRECT_ERROR_NONE;
4969
4970 }
4971
4972
4973 int wifi_direct_get_primary_device_type(wifi_direct_primary_device_type_e* type)
4974 {
4975         wifi_direct_client_info_s *client_info = __wfd_get_control();
4976
4977         __WDC_LOG_FUNC_START__;
4978
4979         if (NULL == type)
4980         {
4981                 WDC_LOGE("NULL Param [type]!");
4982                 __WDC_LOG_FUNC_END__;
4983                 return WIFI_DIRECT_ERROR_INVALID_PARAMETER;
4984         }
4985
4986         if ((client_info->is_registered == false)
4987                 || (client_info->client_id == WFD_INVALID_ID))
4988         {
4989                 WDC_LOGE("Client is NOT registered.");
4990                 __WDC_LOG_FUNC_END__;
4991                 return WIFI_DIRECT_ERROR_NOT_INITIALIZED;
4992         }
4993
4994         WDC_LOGD("Current primary_dev_type [%d]", WIFI_DIRECT_PRIMARY_DEVICE_TYPE_TELEPHONE);
4995
4996         *type = WIFI_DIRECT_PRIMARY_DEVICE_TYPE_TELEPHONE;      // Telephone
4997
4998         __WDC_LOG_FUNC_END__;
4999
5000         return WIFI_DIRECT_ERROR_NONE;
5001 }
5002
5003 int wifi_direct_get_secondary_device_type(wifi_direct_secondary_device_type_e* type)
5004 {
5005         wifi_direct_client_info_s *client_info = __wfd_get_control();
5006
5007         __WDC_LOG_FUNC_START__;
5008
5009         if (NULL == type)
5010         {
5011                 WDC_LOGE("NULL Param [type]!");
5012                 __WDC_LOG_FUNC_END__;
5013                 return WIFI_DIRECT_ERROR_INVALID_PARAMETER;
5014         }
5015
5016         if ((client_info->is_registered == false)
5017                 || (client_info->client_id == WFD_INVALID_ID))
5018         {
5019                 WDC_LOGE("Client is NOT registered.");
5020                 __WDC_LOG_FUNC_END__;
5021                 return WIFI_DIRECT_ERROR_NOT_INITIALIZED;
5022         }
5023
5024
5025         WDC_LOGD("Current second_dev_type [%d]", WIFI_DIRECT_SECONDARY_DEVICE_TYPE_PHONE_SM_DUAL);
5026
5027         *type = WIFI_DIRECT_SECONDARY_DEVICE_TYPE_PHONE_SM_DUAL;        // smart phone dual mode (wifi and cellular)
5028
5029         __WDC_LOG_FUNC_END__;
5030
5031         return WIFI_DIRECT_ERROR_NONE;
5032 }
5033
5034 int wifi_direct_set_autoconnection_mode(bool mode)
5035 {
5036         wifi_direct_client_info_s *client_info = __wfd_get_control();
5037
5038         __WDC_LOG_FUNC_START__;
5039
5040         if ((client_info->is_registered == false)
5041                 || (client_info->client_id == WFD_INVALID_ID))
5042         {
5043                 WDC_LOGE("Client is NOT registered.");
5044                 __WDC_LOG_FUNC_END__;
5045                 return WIFI_DIRECT_ERROR_NOT_INITIALIZED;
5046         }
5047
5048         wifi_direct_client_request_s req;
5049         wifi_direct_client_response_s rsp;
5050
5051         int status = WIFI_DIRECT_ERROR_NONE;
5052
5053         memset(&req, 0, sizeof(wifi_direct_client_request_s));
5054         memset(&rsp, 0, sizeof(wifi_direct_client_response_s));
5055
5056         req.cmd = WIFI_DIRECT_CMD_SET_AUTOCONNECTION_MODE;
5057         req.client_id = client_info->client_id;
5058
5059         status =__wfd_client_send_request(client_info->sync_sockfd, &req,
5060                                                                   sizeof(wifi_direct_client_request_s));
5061         if (status != WIFI_DIRECT_ERROR_NONE)
5062         {
5063                 WDC_LOGE("Error!!! writing to socket, Errno = %s", strerror(errno));
5064                 WDC_LOGE("Error!!! [%s]\n",
5065                                            __wfd_print_error(status));
5066                 client_info->sync_sockfd = -1;
5067                 __wfd_reset_control();
5068                 __WDC_LOG_FUNC_END__;
5069                 return WIFI_DIRECT_ERROR_COMMUNICATION_FAILED;
5070         }
5071
5072         WDC_LOGD("writing msg hdr is success!");
5073
5074         status =
5075                 __wfd_client_send_request(client_info->sync_sockfd, &mode,
5076                                                                   sizeof(bool));
5077         if (status != WIFI_DIRECT_ERROR_NONE)
5078         {
5079                 WDC_LOGE("Error!!! writing to socket, Errno = %s", strerror(errno));
5080                 WDC_LOGE("Error!!! [%s]", __wfd_print_error(status));
5081                 client_info->sync_sockfd = -1;
5082                 __wfd_reset_control();
5083                 __WDC_LOG_FUNC_END__;
5084                 return WIFI_DIRECT_ERROR_COMMUNICATION_FAILED;
5085         }
5086
5087         if ((status =
5088                  __wfd_client_read_socket(client_info->sync_sockfd, (char *) &rsp,
5089                                                                   sizeof(wifi_direct_client_response_s))) <= 0)
5090         {
5091                 WDC_LOGE("Error!!! reading socket, status = %d errno = %s", status, strerror(errno));
5092                 client_info->sync_sockfd = -1;
5093                 __wfd_reset_control();
5094                 __WDC_LOG_FUNC_END__;
5095                 return WIFI_DIRECT_ERROR_COMMUNICATION_FAILED;
5096         }
5097         else
5098         {
5099                 if (rsp.cmd == WIFI_DIRECT_CMD_SET_AUTOCONNECTION_MODE)
5100                 {
5101                         if (rsp.result != WIFI_DIRECT_ERROR_NONE)
5102                         {
5103                                 WDC_LOGD("Error!!! Result received = %d", rsp.result);
5104                                 WDC_LOGD("Error!!! [%s]", __wfd_print_error(rsp.result));
5105                                 __WDC_LOG_FUNC_END__;
5106                                 return rsp.result;
5107                         }
5108                 }
5109                 else
5110                 {
5111                         WDC_LOGE("Error!!! Invalid resp cmd = %d", rsp.cmd);
5112                         return WIFI_DIRECT_ERROR_OPERATION_FAILED;
5113                 }
5114         }
5115
5116         __WDC_LOG_FUNC_END__;
5117
5118         return WIFI_DIRECT_ERROR_NONE;
5119 }
5120
5121 int wifi_direct_is_autoconnection_mode(bool* mode)
5122 {
5123         wifi_direct_client_info_s *client_info = __wfd_get_control();
5124
5125         __WDC_LOG_FUNC_START__;
5126
5127         if (mode == NULL)
5128         {
5129                 WDC_LOGE("NULL Param [mode]!");
5130                 __WDC_LOG_FUNC_END__;
5131                 return WIFI_DIRECT_ERROR_INVALID_PARAMETER;
5132         }
5133
5134         if ((client_info->is_registered == false)
5135                 || (client_info->client_id == WFD_INVALID_ID))
5136         {
5137                 WDC_LOGE("Client is NOT registered.");
5138                 __WDC_LOG_FUNC_END__;
5139                 return WIFI_DIRECT_ERROR_NOT_INITIALIZED;
5140         }
5141
5142         wifi_direct_client_request_s req;
5143         wifi_direct_client_response_s rsp;
5144
5145         int status = WIFI_DIRECT_ERROR_NONE;
5146
5147         memset(&req, 0, sizeof(wifi_direct_client_request_s));
5148         memset(&rsp, 0, sizeof(wifi_direct_client_response_s));
5149
5150         req.cmd = WIFI_DIRECT_CMD_IS_AUTOCONNECTION_MODE;
5151         req.client_id = client_info->client_id;
5152
5153         status =
5154                 __wfd_client_send_request(client_info->sync_sockfd, &req,
5155                                                                   sizeof(wifi_direct_client_request_s));
5156         if (status != WIFI_DIRECT_ERROR_NONE)
5157         {
5158                 WDC_LOGE("Error!!! writing to socket, Errno = %s", strerror(errno));
5159                 WDC_LOGE("Error!!! [%s]", __wfd_print_error(status));
5160                 client_info->sync_sockfd = -1;
5161                 __wfd_reset_control();
5162                 __WDC_LOG_FUNC_END__;
5163                 return WIFI_DIRECT_ERROR_COMMUNICATION_FAILED;
5164         }
5165
5166         if ((status =
5167                  __wfd_client_read_socket(client_info->sync_sockfd, (char *) &rsp,
5168                                                                   sizeof(wifi_direct_client_response_s))) <= 0)
5169         {
5170                 WDC_LOGE("Error!!! reading socket, status = %d errno = %s", status, strerror(errno));
5171                 client_info->sync_sockfd = -1;
5172                 __wfd_reset_control();
5173                 __WDC_LOG_FUNC_END__;
5174                 return WIFI_DIRECT_ERROR_COMMUNICATION_FAILED;
5175         }
5176         else
5177         {
5178                 if (rsp.cmd == WIFI_DIRECT_CMD_IS_AUTOCONNECTION_MODE)
5179                 {
5180                         if (rsp.result != WIFI_DIRECT_ERROR_NONE)
5181                         {
5182                                 WDC_LOGD("Error!!! Result received = %d", rsp.result);
5183                                 WDC_LOGD("Error!!! [%s]", __wfd_print_error(rsp.result));
5184                                 __WDC_LOG_FUNC_END__;
5185                                 return rsp.result;
5186                         }
5187                         else
5188                         {
5189                                 WDC_LOGD("wifi_direct_is_autoconnection_mode() %s SUCCESS", rsp.param2);
5190                                 *mode = (bool) rsp.param1;
5191                         }
5192                 }
5193                 else
5194                 {
5195                         WDC_LOGE("Error!!! Invalid resp cmd = %d", rsp.cmd);
5196                         return WIFI_DIRECT_ERROR_OPERATION_FAILED;
5197                 }
5198         }
5199
5200         __WDC_LOG_FUNC_END__;
5201
5202         return WIFI_DIRECT_ERROR_NONE;
5203
5204 }
5205
5206
5207 int wifi_direct_set_persistent_group_enabled(bool enabled)
5208 {
5209         wifi_direct_client_info_s *client_info = __wfd_get_control();
5210
5211         __WDC_LOG_FUNC_START__;
5212
5213         if ((client_info->is_registered == false)
5214                 || (client_info->client_id == WFD_INVALID_ID))
5215         {
5216                 WDC_LOGE("Client is NOT registered.");
5217                 __WDC_LOG_FUNC_END__;
5218                 return WIFI_DIRECT_ERROR_NOT_INITIALIZED;
5219         }
5220
5221         wifi_direct_client_request_s req;
5222         wifi_direct_client_response_s rsp;
5223
5224         int status = WIFI_DIRECT_ERROR_NONE;
5225
5226         memset(&req, 0, sizeof(wifi_direct_client_request_s));
5227         memset(&rsp, 0, sizeof(wifi_direct_client_response_s));
5228
5229         if (enabled == true)
5230                 req.cmd = WIFI_DIRECT_CMD_ACTIVATE_PERSISTENT_GROUP;
5231         else
5232                 req.cmd = WIFI_DIRECT_CMD_DEACTIVATE_PERSISTENT_GROUP;
5233
5234         req.client_id = client_info->client_id;
5235
5236         status =
5237                 __wfd_client_send_request(client_info->sync_sockfd, &req,
5238                                                                   sizeof(wifi_direct_client_request_s));
5239         if (status != WIFI_DIRECT_ERROR_NONE)
5240         {
5241                 WDC_LOGE("Error!!! writing to socket, Errno = %s", strerror(errno));
5242                 WDC_LOGE("Error!!! [%s]",
5243                                            __wfd_print_error(status));
5244                 client_info->sync_sockfd = -1;
5245                 __wfd_reset_control();
5246                 __WDC_LOG_FUNC_END__;
5247                 return WIFI_DIRECT_ERROR_COMMUNICATION_FAILED;
5248         }
5249
5250         if ((status =
5251                  __wfd_client_read_socket(client_info->sync_sockfd, (char *) &rsp,
5252                                                                   sizeof(wifi_direct_client_response_s))) <= 0)
5253         {
5254                 WDC_LOGE("Error!!! reading socket, status = %d errno = %s", status, strerror(errno));
5255                 client_info->sync_sockfd = -1;
5256                 __wfd_reset_control();
5257                 __WDC_LOG_FUNC_END__;
5258                 return WIFI_DIRECT_ERROR_COMMUNICATION_FAILED;
5259         }
5260         else
5261         {
5262                 if (rsp.cmd == WIFI_DIRECT_CMD_ACTIVATE_PERSISTENT_GROUP
5263                         || rsp.cmd == WIFI_DIRECT_CMD_DEACTIVATE_PERSISTENT_GROUP)
5264                 {
5265                         if (rsp.result != WIFI_DIRECT_ERROR_NONE)
5266                         {
5267                                 WDC_LOGD( "Error!!! Result received = %d", rsp.result);
5268                                 WDC_LOGD( "Error!!! [%s]", __wfd_print_error(rsp.result));
5269                                 __WDC_LOG_FUNC_END__;
5270                                 return rsp.result;
5271                         }
5272                         else
5273                         {
5274                                 WDC_LOGD("wifi_direct_set_persistent_group_enabled() SUCCESS");
5275                         }
5276                 }
5277                 else
5278                 {
5279                         WDC_LOGE("Error!!! Invalid resp cmd = %d", rsp.cmd);
5280                         return WIFI_DIRECT_ERROR_OPERATION_FAILED;
5281                 }
5282         }
5283
5284         __WDC_LOG_FUNC_END__;
5285
5286         return WIFI_DIRECT_ERROR_NONE;
5287 }
5288
5289
5290 int wifi_direct_is_persistent_group_enabled(bool* enabled)
5291 {
5292         wifi_direct_client_info_s *client_info = __wfd_get_control();
5293
5294         __WDC_LOG_FUNC_START__;
5295
5296         if (enabled == NULL)
5297         {
5298                 WDC_LOGE("NULL Param [enabled]!");
5299                 __WDC_LOG_FUNC_END__;
5300                 return WIFI_DIRECT_ERROR_INVALID_PARAMETER;
5301         }
5302
5303         if ((client_info->is_registered == false)
5304                 || (client_info->client_id == WFD_INVALID_ID))
5305         {
5306                 WDC_LOGE("Client is NOT registered.");
5307                 __WDC_LOG_FUNC_END__;
5308                 return WIFI_DIRECT_ERROR_NOT_INITIALIZED;
5309         }
5310
5311         wifi_direct_client_request_s req;
5312         wifi_direct_client_response_s rsp;
5313
5314         int status = WIFI_DIRECT_ERROR_NONE;
5315
5316         memset(&req, 0, sizeof(wifi_direct_client_request_s));
5317         memset(&rsp, 0, sizeof(wifi_direct_client_response_s));
5318
5319         req.cmd = WIFI_DIRECT_CMD_IS_PERSISTENT_GROUP;
5320         req.client_id = client_info->client_id;
5321
5322         status =
5323                 __wfd_client_send_request(client_info->sync_sockfd, &req,
5324                                                                   sizeof(wifi_direct_client_request_s));
5325         if (status != WIFI_DIRECT_ERROR_NONE)
5326         {
5327                 WDC_LOGE("Error!!! writing to socket, Errno = %s", strerror(errno));
5328                 WDC_LOGE("Error!!! [%s]\n",
5329                                            __wfd_print_error(status));
5330                 client_info->sync_sockfd = -1;
5331                 __wfd_reset_control();
5332                 __WDC_LOG_FUNC_END__;
5333                 return WIFI_DIRECT_ERROR_COMMUNICATION_FAILED;
5334         }
5335
5336         if ((status =
5337                  __wfd_client_read_socket(client_info->sync_sockfd, (char *) &rsp,
5338                                                                   sizeof(wifi_direct_client_response_s))) <= 0)
5339         {
5340                 WDC_LOGE("Error!!! reading socket, status = %d errno = %s", status, strerror(errno));
5341                 client_info->sync_sockfd = -1;
5342                 __wfd_reset_control();
5343                 __WDC_LOG_FUNC_END__;
5344                 return WIFI_DIRECT_ERROR_COMMUNICATION_FAILED;
5345         }
5346         else
5347         {
5348                 if (rsp.cmd == WIFI_DIRECT_CMD_IS_PERSISTENT_GROUP)
5349                 {
5350                         if (rsp.result != WIFI_DIRECT_ERROR_NONE)
5351                         {
5352                                 WDC_LOGD("Error!!! Result received = %d", rsp.result);
5353                                 WDC_LOGD("Error!!! [%s]", __wfd_print_error(rsp.result));
5354                                 __WDC_LOG_FUNC_END__;
5355                                 return rsp.result;
5356                         }
5357                         else
5358                         {
5359                                 WDC_LOGD("wifi_direct_is_persistent_group_enabled() %s SUCCESS", rsp.param2);
5360                                 *enabled = (bool) rsp.param1;
5361                         }
5362                 }
5363                 else
5364                 {
5365                         WDC_LOGE("Error!!! Invalid resp cmd = %d", rsp.cmd);
5366                         return WIFI_DIRECT_ERROR_OPERATION_FAILED;
5367                 }
5368         }
5369
5370         __WDC_LOG_FUNC_END__;
5371
5372         return WIFI_DIRECT_ERROR_NONE;
5373
5374 }
5375
5376 int wifi_direct_foreach_persistent_groups(wifi_direct_persistent_group_cb callback, void* user_data)
5377 {
5378         wifi_direct_client_info_s *client_info = __wfd_get_control();
5379
5380         __WDC_LOG_FUNC_START__;
5381
5382         if ((client_info->is_registered == false)
5383                 || (client_info->client_id == WFD_INVALID_ID))
5384         {
5385                 WDC_LOGE("Client is NOT registered.");
5386                 __WDC_LOG_FUNC_END__;
5387                 return WIFI_DIRECT_ERROR_NOT_INITIALIZED;
5388         }
5389
5390         if (callback == NULL)
5391         {
5392                 WDC_LOGE("NULL Param [callback]!");
5393                 __WDC_LOG_FUNC_END__;
5394                 return WIFI_DIRECT_ERROR_INVALID_PARAMETER;
5395         }
5396
5397         wifi_direct_client_request_s req;
5398         wifi_direct_client_response_s rsp;
5399         int i;
5400
5401         int status = WIFI_DIRECT_ERROR_NONE;
5402
5403         memset(&req, 0, sizeof(wifi_direct_client_request_s));
5404         memset(&rsp, 0, sizeof(wifi_direct_client_response_s));
5405
5406         req.cmd = WIFI_DIRECT_CMD_GET_PERSISTENT_GROUP_INFO;
5407         req.client_id = client_info->client_id;
5408
5409         status =
5410                 __wfd_client_send_request(client_info->sync_sockfd, &req,
5411                                                                   sizeof(wifi_direct_client_request_s));
5412         if (status != WIFI_DIRECT_ERROR_NONE)
5413         {
5414                 WDC_LOGE("Error!!! writing to socket, Errno = %s", strerror(errno));
5415                 WDC_LOGE("Error!!! [%s]", __wfd_print_error(status));
5416                 client_info->sync_sockfd = -1;
5417                 __wfd_reset_control();
5418                 __WDC_LOG_FUNC_END__;
5419                 return WIFI_DIRECT_ERROR_COMMUNICATION_FAILED;
5420         }
5421
5422         if ((status =
5423                  __wfd_client_read_socket(client_info->sync_sockfd, (char *) &rsp,
5424                                                                   sizeof(wifi_direct_client_response_s))) <= 0)
5425         {
5426                 WDC_LOGE("Error!!! reading socket, status = %d errno = %s", status, strerror(errno));
5427                 client_info->sync_sockfd = -1;
5428                 __wfd_reset_control();
5429                 __WDC_LOG_FUNC_END__;
5430                 return WIFI_DIRECT_ERROR_COMMUNICATION_FAILED;
5431         }
5432         else
5433         {
5434                 if (rsp.cmd == WIFI_DIRECT_CMD_GET_PERSISTENT_GROUP_INFO)
5435                 {
5436                         if (rsp.result != WIFI_DIRECT_ERROR_NONE)
5437                         {
5438                                 WDC_LOGE("Error!!! Result received = %d", rsp.result);
5439                                 WDC_LOGE("Error!!! [%s]", __wfd_print_error(rsp.result));
5440                                 __WDC_LOG_FUNC_END__;
5441                                 return rsp.result;
5442                         }
5443                         else
5444                         {
5445
5446                                 int num = rsp.param1;
5447                                 int status = 0;
5448                                 wfd_persistent_group_info_s *buff = NULL;
5449
5450                                 WDC_LOGD("Num of persistent groups = %d", (int) rsp.param1);
5451
5452                                 if (num > 0)
5453                                 {
5454                                         buff = (wfd_persistent_group_info_s *) malloc(num * sizeof(wfd_persistent_group_info_s));
5455                                         if (buff == NULL)
5456                                         {
5457                                                 WDC_LOGE("malloc() failed!!!.");
5458                                                 return WIFI_DIRECT_ERROR_OPERATION_FAILED;
5459                                         }
5460
5461                                         status =
5462                                                 __wfd_client_read_more_data(client_info->sync_sockfd,
5463                                                                                                         buff,
5464                                                                                                         num *
5465                                                                                                         sizeof
5466                                                                                                         (wfd_persistent_group_info_s));
5467                                         if (status != WIFI_DIRECT_ERROR_NONE)
5468                                         {
5469                                                 if (NULL != buff)
5470                                                         free(buff);
5471                                                 WDC_LOGE("socket read error.");
5472                                                 return WIFI_DIRECT_ERROR_OPERATION_FAILED;
5473                                         }
5474                                 }
5475
5476                                 __wfd_client_print_persistent_group_info(buff, num);
5477
5478                                 WDC_LOGD("wifi_direct_foreach_persistent_groups() SUCCESS");
5479
5480                                 char* ssid;
5481                                 char* go_mac_address;
5482
5483                                 for (i = 0; i < num; i++)
5484                                 {
5485                                         ssid = strdup(buff[i].ssid);
5486                                         go_mac_address = (char *) calloc(1, 18);
5487                                         snprintf(go_mac_address, 18, MACSTR, MAC2STR(buff[i].go_mac_address));
5488
5489                                         if (!callback(go_mac_address, ssid, user_data))
5490                                                 break;
5491                                 }
5492
5493                                 if (NULL != buff)
5494                                         free(buff);
5495
5496                         }
5497                 }
5498                 else
5499                 {
5500                         WDC_LOGE("Error!!! Invalid resp cmd = %d", rsp.cmd);
5501                         return WIFI_DIRECT_ERROR_OPERATION_FAILED;
5502                 }
5503         }
5504
5505         __WDC_LOG_FUNC_END__;
5506
5507         return WIFI_DIRECT_ERROR_NONE;
5508 }
5509
5510 int wifi_direct_remove_persistent_group(const char* mac_address, const char* ssid)
5511 {
5512         __WDC_LOG_FUNC_START__;
5513
5514         wifi_direct_client_info_s *client_info = __wfd_get_control();
5515
5516         if ((client_info->is_registered == false)
5517                 || (client_info->client_id == WFD_INVALID_ID))
5518         {
5519                 WDC_LOGE("Client is NOT registered.");
5520                 __WDC_LOG_FUNC_END__;
5521                 return WIFI_DIRECT_ERROR_NOT_INITIALIZED;
5522         }
5523
5524         if ( NULL== mac_address )
5525         {
5526                 WDC_LOGE("NULL Param [mac_address]!");
5527                 __WDC_LOG_FUNC_END__;
5528                 return WIFI_DIRECT_ERROR_INVALID_PARAMETER;
5529         }
5530
5531         if ( NULL== ssid )
5532         {
5533                 WDC_LOGE("NULL Param [ssid]!");
5534                 __WDC_LOG_FUNC_END__;
5535                 return WIFI_DIRECT_ERROR_INVALID_PARAMETER;
5536         }
5537
5538         wifi_direct_client_request_s req;
5539         wifi_direct_client_response_s rsp;
5540         wfd_persistent_group_info_s persistent_group_info;
5541         unsigned char la_mac_addr[6];
5542
5543         int status = WIFI_DIRECT_ERROR_NONE;
5544
5545         memset(&req, 0, sizeof(wifi_direct_client_request_s));
5546         memset(&rsp, 0, sizeof(wifi_direct_client_response_s));
5547
5548         req.cmd = WIFI_DIRECT_CMD_REMOVE_PERSISTENT_GROUP;
5549         req.client_id = client_info->client_id;
5550
5551         status =
5552                 __wfd_client_send_request(client_info->sync_sockfd, &req,
5553                                                                   sizeof(wifi_direct_client_request_s));
5554         if (status != WIFI_DIRECT_ERROR_NONE)
5555         {
5556                 WDC_LOGE("Error!!! writing to socket, Errno = %s", strerror(errno));
5557                 WDC_LOGE("Error!!! [%s]", __wfd_print_error(status));
5558                 client_info->sync_sockfd = -1;
5559                 __wfd_reset_control();
5560                 __WDC_LOG_FUNC_END__;
5561                 return WIFI_DIRECT_ERROR_COMMUNICATION_FAILED;
5562         }
5563
5564         WDC_LOGD("writing msg hdr is success!");
5565
5566         strncpy(persistent_group_info.ssid, ssid, strlen(ssid));
5567
5568         memset(la_mac_addr, 0, sizeof(la_mac_addr));
5569         macaddr_atoe(mac_address, la_mac_addr);
5570         persistent_group_info.go_mac_address[0] = la_mac_addr[0];
5571         persistent_group_info.go_mac_address[1] = la_mac_addr[1];
5572         persistent_group_info.go_mac_address[2] = la_mac_addr[2];
5573         persistent_group_info.go_mac_address[3] = la_mac_addr[3];
5574         persistent_group_info.go_mac_address[4] = la_mac_addr[4];
5575         persistent_group_info.go_mac_address[5] = la_mac_addr[5];
5576
5577         status =
5578                 __wfd_client_send_request(client_info->sync_sockfd, &persistent_group_info,
5579                                                                   sizeof(wfd_persistent_group_info_s));
5580         if (status != WIFI_DIRECT_ERROR_NONE)
5581         {
5582                 WDC_LOGE("Error!!! writing to socket, Errno = %s", strerror(errno));
5583                 WDC_LOGE("Error!!! [%s]", __wfd_print_error(status));
5584                 client_info->sync_sockfd = -1;
5585                 __wfd_reset_control();
5586                 __WDC_LOG_FUNC_END__;
5587                 return WIFI_DIRECT_ERROR_COMMUNICATION_FAILED;
5588         }
5589
5590         if ((status =
5591                  __wfd_client_read_socket(client_info->sync_sockfd, (char *) &rsp,
5592                                                                   sizeof(wifi_direct_client_response_s))) <= 0)
5593         {
5594                 WDC_LOGE("Error!!! reading socket, status = %d errno = %s\n", status, strerror(errno));
5595                 client_info->sync_sockfd = -1;
5596                 __wfd_reset_control();
5597                 __WDC_LOG_FUNC_END__;
5598                 return WIFI_DIRECT_ERROR_COMMUNICATION_FAILED;
5599         }
5600         else
5601         {
5602                 if (rsp.cmd == WIFI_DIRECT_CMD_REMOVE_PERSISTENT_GROUP)
5603                 {
5604                         if (rsp.result != WIFI_DIRECT_ERROR_NONE)
5605                         {
5606                                 WDC_LOGD("Error!!! Result received = %d", rsp.result);
5607                                 WDC_LOGD("Error!!! [%s]", __wfd_print_error(rsp.result));
5608                                 __WDC_LOG_FUNC_END__;
5609                                 return rsp.result;
5610                         }
5611                 }
5612                 else
5613                 {
5614                         WDC_LOGE("Error!!! Invalid resp cmd = %d", rsp.cmd);
5615                         return WIFI_DIRECT_ERROR_OPERATION_FAILED;
5616                 }
5617         }
5618
5619         __WDC_LOG_FUNC_END__;
5620
5621         return WIFI_DIRECT_ERROR_NONE;
5622 }
5623
5624 int wifi_direct_set_p2poem_loglevel(int increase_log_level)
5625 {
5626         wifi_direct_client_info_s *client_info = __wfd_get_control();
5627
5628         __WDC_LOG_FUNC_START__;
5629
5630         if ((client_info->is_registered == false)
5631                 || (client_info->client_id == WFD_INVALID_ID))
5632         {
5633                 WDC_LOGE("Client is NOT registered.");
5634                 __WDC_LOG_FUNC_END__;
5635                 return WIFI_DIRECT_ERROR_NOT_INITIALIZED;
5636         }
5637
5638         wifi_direct_client_request_s req;
5639         wifi_direct_client_response_s rsp;
5640
5641         int ret = WIFI_DIRECT_ERROR_NONE;
5642
5643         memset(&req, 0, sizeof(wifi_direct_client_request_s));
5644         memset(&rsp, 0, sizeof(wifi_direct_client_response_s));
5645
5646         req.cmd = WIFI_DIRECT_CMD_SET_OEM_LOGLEVEL;
5647         req.client_id = client_info->client_id;
5648         if (increase_log_level == 0)
5649                 req.data.listen_only = false;
5650         else
5651                 req.data.listen_only = true;
5652
5653         ret =
5654                 __wfd_client_send_request(client_info->sync_sockfd, &req,
5655                                                                   sizeof(wifi_direct_client_request_s));
5656         if (ret != WIFI_DIRECT_ERROR_NONE)
5657         {
5658                 WDC_LOGE("Error!!! writing to socket, Errno = %s", strerror(errno));
5659                 WDC_LOGE("Error!!! [%s]", __wfd_print_error(ret));
5660                 client_info->sync_sockfd = -1;
5661                 __wfd_reset_control();
5662                 __WDC_LOG_FUNC_END__;
5663                 return WIFI_DIRECT_ERROR_COMMUNICATION_FAILED;
5664         }
5665
5666         if ((ret =
5667                  __wfd_client_read_socket(client_info->sync_sockfd, (char *) &rsp,
5668                                                                   sizeof(wifi_direct_client_response_s))) <= 0)
5669         {
5670                 WDC_LOGE("Error!!! reading socket, status = %d errno = %s", ret, strerror(errno));
5671                 client_info->sync_sockfd = -1;
5672                 __wfd_reset_control();
5673                 __WDC_LOG_FUNC_END__;
5674                 return WIFI_DIRECT_ERROR_COMMUNICATION_FAILED;
5675         }
5676         else
5677         {
5678                 if (rsp.cmd == WIFI_DIRECT_CMD_SET_OEM_LOGLEVEL)
5679                 {
5680                         if (rsp.result != WIFI_DIRECT_ERROR_NONE)
5681                         {
5682                                 WDC_LOGD("Error!!! Result received = %d", rsp.result);
5683                                 WDC_LOGD("Error!!! [%s]", __wfd_print_error(rsp.result));
5684                                 __WDC_LOG_FUNC_END__;
5685                                 return rsp.result;
5686                         }
5687                 }
5688                 else
5689                 {
5690                         WDC_LOGE("Error!!! Invalid resp cmd = %d", rsp.cmd);
5691                         return WIFI_DIRECT_ERROR_OPERATION_FAILED;
5692                 }
5693         }
5694
5695         __WDC_LOG_FUNC_END__;
5696
5697         return WIFI_DIRECT_ERROR_NONE;
5698 }