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