4 * Copyright (c) 2000 - 2012 Samsung Electronics Co., Ltd. All rights reserved.
6 * Contact: Sungsik Jang <sungsik.jang@samsung.com>, Dongwook Lee <dwmax.lee@samsung.com>
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
12 * http://www.apache.org/licenses/LICENSE-2.0
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.
24 /*****************************************************************************
26 *****************************************************************************/
31 #include <sys/socket.h>
37 #include <sys/ioctl.h>
40 #include <linux/unistd.h>
43 /*****************************************************************************
44 * Wi-Fi Direct Service headers
45 *****************************************************************************/
46 #include "wifi-direct.h"
47 #include "wifi-direct-client-proxy.h"
48 #include "wifi-direct-internal.h"
50 /*****************************************************************************
52 *****************************************************************************/
55 /*****************************************************************************
57 *****************************************************************************/
58 wifi_direct_client_info_s g_client_info = {
59 .is_registered = FALSE,
63 .activation_cb = NULL,
65 .connection_cb = NULL,
66 .user_data_for_cb_activation = NULL,
67 .user_data_for_cb_discover = NULL,
68 .user_data_for_cb_connection = NULL
71 /*****************************************************************************
72 * Local Functions Definition
73 *****************************************************************************/
74 static int __wfd_client_read_socket(int sockfd, char *dataptr, int datalen);
79 return syscall(__NR_gettid);
82 #error "__NR_gettid is not defined, please include linux/unistd.h "
85 static wifi_direct_client_info_s *__wfd_get_control()
87 return &g_client_info;
90 static void __wfd_reset_control()
93 if (g_client_info.g_source_id > 0)
94 g_source_remove(g_client_info.g_source_id);
95 g_client_info.g_source_id = -1;
97 // Protect standard input / output / error
98 if (g_client_info.sync_sockfd > 2)
99 close(g_client_info.sync_sockfd);
100 g_client_info.sync_sockfd = -1;
102 if (g_client_info.async_sockfd > 2)
103 close(g_client_info.async_sockfd);
104 g_client_info.async_sockfd = -1;
106 g_client_info.is_registered = FALSE;
108 // Initialize callbacks
109 g_client_info.activation_cb = NULL;
110 g_client_info.discover_cb = NULL;
111 g_client_info.connection_cb = NULL;
112 g_client_info.user_data_for_cb_activation = NULL;
113 g_client_info.user_data_for_cb_discover = NULL;
114 g_client_info.user_data_for_cb_connection = NULL;
118 static int macaddr_atoe(char *p, unsigned char mac[])
122 printf("MAC [%s]\n", p);
126 mac[i++] = (char) strtoul(p, &p, 16);
135 static char *__wfd_print_event(wfd_client_event_e event)
139 case WIFI_DIRECT_CLI_EVENT_ACTIVATION:
142 case WIFI_DIRECT_CLI_EVENT_DEACTIVATION:
143 return "DEACTIVATION";
145 case WIFI_DIRECT_CLI_EVENT_INVALID:
146 return "WIFI_DIRECT_CLI_EVENT_INVALID";
148 case WIFI_DIRECT_CLI_EVENT_DISCOVER_START:
149 return "WIFI_DIRECT_CLI_EVENT_DISCOVER_START";
151 case WIFI_DIRECT_CLI_EVENT_DISCOVER_START_LISTEN_ONLY:
152 return "WIFI_DIRECT_CLI_EVENT_DISCOVER_START_LISTEN_ONLY";
154 case WIFI_DIRECT_CLI_EVENT_DISCOVER_START_SEARCH_LISTEN:
155 return "WIFI_DIRECT_CLI_EVENT_DISCOVER_START_SEARCH_LISTEN";
157 case WIFI_DIRECT_CLI_EVENT_DISCOVER_END:
158 return "WIFI_DIRECT_CLI_EVENT_DISCOVER_END";
160 case WIFI_DIRECT_CLI_EVENT_DISCOVER_FOUND_PEERS:
161 return "WIFI_DIRECT_CLI_EVENT_DISCOVER_FOUND_PEERS";
164 case WIFI_DIRECT_CLI_EVENT_CONNECTION_REQ:
165 return "WIFI_DIRECT_CLI_EVENT_CONNECTION_REQ";
168 case WIFI_DIRECT_CLI_EVENT_CONNECTION_START:
169 return "WIFI_DIRECT_CLI_EVENT_CONNECTION_START";
172 case WIFI_DIRECT_CLI_EVENT_CONNECTION_RSP:
173 return "WIFI_DIRECT_CLI_EVENT_CONNECTION_RSP";
175 case WIFI_DIRECT_CLI_EVENT_CONNECTION_WPS_REQ:
176 return "WIFI_DIRECT_CLI_EVENT_CONNECTION_WPS_REQ";
179 case WIFI_DIRECT_CLI_EVENT_DISCONNECTION_RSP:
180 return "WIFI_DIRECT_CLI_EVENT_DISCONNECTION_RSP";
182 case WIFI_DIRECT_CLI_EVENT_DISCONNECTION_IND:
183 return "WIFI_DIRECT_CLI_EVENT_DISCONNECTION_IND";
186 case WIFI_DIRECT_CLI_EVENT_GROUP_CREATE_RSP:
187 return "WIFI_DIRECT_CLI_EVENT_GROUP_CREATE_RSP";
189 case WIFI_DIRECT_CLI_EVENT_GROUP_DESTROY_RSP:
190 return "WIFI_DIRECT_CLI_EVENT_GROUP_DESTROY_RSP";
194 return "WIFI_DIRECT_CLI_EVENT_unknown";
199 static char *__wfd_print_error(wifi_direct_error_e error)
203 case WIFI_DIRECT_ERROR_OPERATION_FAILED:
204 return "WIFI_DIRECT_ERROR_OPERATION_FAILED";
205 case WIFI_DIRECT_ERROR_OUT_OF_MEMORY:
206 return "WIFI_DIRECT_ERROR_OUT_OF_MEMORY";
207 case WIFI_DIRECT_ERROR_COMMUNICATION_FAILED:
208 return "WIFI_DIRECT_ERROR_COMMUNICATION_FAILED";
209 case WIFI_DIRECT_ERROR_NOT_PERMITTED:
210 return "WIFI_DIRECT_ERROR_NOT_PERMITTED";
211 case WIFI_DIRECT_ERROR_INVALID_PARAMETER:
212 return "WIFI_DIRECT_ERROR_INVALID_PARAMETER";
213 case WIFI_DIRECT_ERROR_STRANGE_CLIENT:
214 return "WIFI_DIRECT_ERROR_STRANGE_CLIENT";
215 case WIFI_DIRECT_ERROR_NONE:
216 return "WIFI_DIRECT_ERROR_NONE";
218 WFD_CLIENT_LOG(WFD_LOG_LOW, "Invalid error value: [%d]\n", error);
219 return "Invalid error";
223 static int __wfd_convert_client_event(wfd_client_event_e event)
225 __WFD_CLIENT_FUNC_START__;
229 case WIFI_DIRECT_CLI_EVENT_ACTIVATION:
230 return WIFI_DIRECT_DEVICE_STATE_ACTIVATED;
232 case WIFI_DIRECT_CLI_EVENT_DEACTIVATION:
233 return WIFI_DIRECT_DEVICE_STATE_DEACTIVATED;
236 case WIFI_DIRECT_CLI_EVENT_DISCOVER_START_LISTEN_ONLY:
237 return WIFI_DIRECT_ONLY_LISTEN_STARTED;
239 case WIFI_DIRECT_CLI_EVENT_DISCOVER_START:
240 return WIFI_DIRECT_DISCOVERY_STARTED;
242 case WIFI_DIRECT_CLI_EVENT_DISCOVER_END:
243 return WIFI_DIRECT_DISCOVERY_FINISHED;
245 case WIFI_DIRECT_CLI_EVENT_DISCOVER_FOUND_PEERS:
246 return WIFI_DIRECT_DISCOVERY_FOUND;
249 case WIFI_DIRECT_CLI_EVENT_CONNECTION_START:
250 return WIFI_DIRECT_CONNECTION_IN_PROGRESS;
252 case WIFI_DIRECT_CLI_EVENT_CONNECTION_REQ:
253 return WIFI_DIRECT_CONNECTION_REQ;
255 case WIFI_DIRECT_CLI_EVENT_CONNECTION_RSP:
256 return WIFI_DIRECT_CONNECTION_RSP;
258 case WIFI_DIRECT_CLI_EVENT_DISCONNECTION_RSP:
259 return WIFI_DIRECT_DISCONNECTION_RSP;
261 case WIFI_DIRECT_CLI_EVENT_CONNECTION_WPS_REQ:
262 return WIFI_DIRECT_CONNECTION_WPS_REQ;
264 case WIFI_DIRECT_CLI_EVENT_DISCONNECTION_IND:
265 return WIFI_DIRECT_DISCONNECTION_IND;
267 case WIFI_DIRECT_CLI_EVENT_DISASSOCIATION_IND:
268 return WIFI_DIRECT_DISASSOCIATION_IND;
270 case WIFI_DIRECT_CLI_EVENT_GROUP_CREATE_RSP:
271 return WIFI_DIRECT_GROUP_CREATED;
273 case WIFI_DIRECT_CLI_EVENT_GROUP_DESTROY_RSP:
274 return WIFI_DIRECT_GROUP_DESTROYED;
278 WFD_CLIENT_LOG(WFD_LOG_LOW, "Invalid event : [%d]\n", event);
282 __WFD_CLIENT_FUNC_END__;
286 static gboolean __wfd_client_process_event(GIOChannel * source,
287 GIOCondition condition,
290 wfd_client_event_e event = WIFI_DIRECT_CLI_EVENT_INVALID;
291 wifi_direct_client_info_s *client = __wfd_get_control();
292 int sockfd = client->async_sockfd;
293 wifi_direct_client_noti_s client_noti;
294 wifi_direct_error_e error = WIFI_DIRECT_ERROR_NONE;
295 char param1[64] = { 0, };
296 char param2[64] = { 0, };
298 memset(&client_noti, 0, sizeof(wifi_direct_client_noti_s));
301 if ((__wfd_client_read_socket
302 (sockfd, (char *) &client_noti,
303 sizeof(wifi_direct_client_noti_s))) <= 0)
305 WFD_CLIENT_LOG(WFD_LOG_ERROR, "Error!!! Reading Async Event[%d]\n",
308 __wfd_reset_control();
309 __WFD_CLIENT_FUNC_END__;
313 WFD_CLIENT_LOG(WFD_LOG_LOW, "Received Event is [%d,%s], error[%d]\n",
314 client_noti.event, __wfd_print_event(client_noti.event),
317 event = client_noti.event;
318 error = client_noti.error;
319 memcpy(param1, client_noti.param1, sizeof(client_noti.param1));
320 memcpy(param2, client_noti.param2, sizeof(client_noti.param2));
327 case WIFI_DIRECT_CLI_EVENT_ACTIVATION:
328 case WIFI_DIRECT_CLI_EVENT_DEACTIVATION:
329 if (client->activation_cb != NULL)
330 client->activation_cb(error,
331 (wifi_direct_device_state_e)
332 __wfd_convert_client_event(event),
333 client->user_data_for_cb_activation);
335 WFD_CLIENT_LOG(WFD_LOG_ERROR, "activation_cb is NULL!!\n");
338 case WIFI_DIRECT_CLI_EVENT_DISCOVER_START:
339 case WIFI_DIRECT_CLI_EVENT_DISCOVER_START_LISTEN_ONLY:
340 case WIFI_DIRECT_CLI_EVENT_DISCOVER_START_SEARCH_LISTEN:
341 case WIFI_DIRECT_CLI_EVENT_DISCOVER_END:
342 case WIFI_DIRECT_CLI_EVENT_DISCOVER_FOUND_PEERS:
343 if (client->discover_cb != NULL)
344 client->discover_cb(error,
345 (wifi_direct_discovery_state_e)
346 __wfd_convert_client_event(event),
347 client->user_data_for_cb_discover);
349 WFD_CLIENT_LOG(WFD_LOG_ERROR, "discover_cb is NULL!!\n");
352 case WIFI_DIRECT_CLI_EVENT_CONNECTION_START:
353 case WIFI_DIRECT_CLI_EVENT_CONNECTION_REQ:
354 case WIFI_DIRECT_CLI_EVENT_CONNECTION_RSP:
355 case WIFI_DIRECT_CLI_EVENT_DISCONNECTION_RSP:
356 case WIFI_DIRECT_CLI_EVENT_CONNECTION_WPS_REQ:
357 case WIFI_DIRECT_CLI_EVENT_DISCONNECTION_IND:
358 case WIFI_DIRECT_CLI_EVENT_DISASSOCIATION_IND:
359 case WIFI_DIRECT_CLI_EVENT_GROUP_CREATE_RSP:
360 case WIFI_DIRECT_CLI_EVENT_GROUP_DESTROY_RSP:
361 if (client->connection_cb != NULL)
362 client->connection_cb(error,
363 (wifi_direct_connection_state_e)
364 __wfd_convert_client_event(event), param1,
365 client->user_data_for_cb_connection);
367 WFD_CLIENT_LOG(WFD_LOG_ERROR, "connection_cb is NULL!!\n");
374 __WFD_CLIENT_FUNC_END__;
379 static wifi_direct_error_e __wfd_client_send_request(int sockfd, void *req_data, int dataLength)
383 __WFD_CLIENT_FUNC_START__;
387 WFD_CLIENT_LOG(WFD_LOG_LOW, "Write [%d] bytes to socket [%d].\n",
390 retval = write(sockfd, (char *) req_data, dataLength);
394 WFD_CLIENT_LOG(WFD_LOG_ERROR,
395 "Error!!! writing to the socket. Error = %s \n",
397 __WFD_CLIENT_FUNC_END__;
398 return WIFI_DIRECT_ERROR_NONE;
401 __WFD_CLIENT_FUNC_END__;
402 return WIFI_DIRECT_ERROR_NONE;
405 WFD_CLIENT_LOG(WFD_LOG_ERROR, "Error!!! Invalid sockfd [%d]\n", sockfd);
406 __WFD_CLIENT_FUNC_END__;
407 return WIFI_DIRECT_ERROR_NONE;
410 static wifi_direct_error_e __wfd_client_async_event_init(int clientid)
414 struct sockaddr_un servAddr;
415 char *path = "/tmp/wfd_client_socket";
417 wifi_direct_client_info_s *client_info = __wfd_get_control();
419 __WFD_CLIENT_FUNC_START__;
422 if ((sockfd = socket(AF_UNIX, SOCK_STREAM, 0)) < 0)
424 WFD_CLIENT_LOG(WFD_LOG_ERROR,
425 "Error!!! creating async socket. Error = [%s].\n",
427 __WFD_CLIENT_FUNC_END__;
428 return WIFI_DIRECT_ERROR_COMMUNICATION_FAILED;
431 WFD_CLIENT_LOG(WFD_LOG_LOW, "Created async socket [%d]\n", sockfd);
433 memset(&servAddr, 0, sizeof(servAddr));
434 servAddr.sun_family = AF_UNIX;
435 strcpy(servAddr.sun_path, path);
436 len = sizeof(servAddr.sun_family) + strlen(path);
438 WFD_CLIENT_LOG(WFD_LOG_LOW,
439 "Connecting to server socket to register async socket [%d]\n",
442 if ((connect(sockfd, (struct sockaddr *) &servAddr, len)) < 0)
444 WFD_CLIENT_LOG(WFD_LOG_ERROR,
445 "Error!!! connecting to server socket. Error = [%s].\n",
448 __WFD_CLIENT_FUNC_END__;
449 return WIFI_DIRECT_ERROR_COMMUNICATION_FAILED;
453 wifi_direct_client_request_s req;
454 int result = WIFI_DIRECT_ERROR_NONE;
456 memset(&req, 0, sizeof(wifi_direct_client_request_s));
458 req.cmd = WIFI_DIRECT_CMD_INIT_ASYNC_SOCKET;
459 req.client_id = clientid;
462 __wfd_client_send_request(sockfd, &req, sizeof(wifi_direct_client_request_s));
464 if (result != WIFI_DIRECT_ERROR_NONE)
466 WFD_CLIENT_LOG(WFD_LOG_ERROR,
467 "Error!!! writing to socket, Errno = %s\n",
469 WFD_CLIENT_LOG(WFD_LOG_ERROR, "Error!!! [%s]\n",
470 __wfd_print_error(result));
472 __WFD_CLIENT_FUNC_END__;
476 client_info->async_sockfd = sockfd;
478 WFD_CLIENT_LOG(WFD_LOG_ERROR, "Async socket is created= %d\n", sockfd);
486 static int __wfd_client_read_socket(int sockfd, char *dataptr, int datalen)
489 struct pollfd pollfd;
490 int timeout = 60000; /** for 60 sec */
492 int total_data_recd = 0;
494 __WFD_CLIENT_FUNC_START__;
498 WFD_CLIENT_LOG(WFD_LOG_ERROR, "Error!!! Invalid socket FD [%d]\n",
500 __WFD_CLIENT_FUNC_END__;
504 if ((dataptr == NULL) || (datalen <= 0))
506 WFD_CLIENT_LOG(WFD_LOG_ERROR, "Error!!! Invalid parameter\n");
507 __WFD_CLIENT_FUNC_END__;
511 WFD_CLIENT_LOG(WFD_LOG_LOW, "@@@@@@@ len = %d @@@@@@@@@@@\n", datalen);
514 pollfd.events = POLLIN | POLLERR | POLLHUP;
515 pollret = poll(&pollfd, 1, timeout);
517 WFD_CLIENT_LOG(WFD_LOG_LOW, "POLL ret = %d, \n", pollret);
521 if (pollfd.revents == POLLIN)
523 WFD_CLIENT_LOG(WFD_LOG_LOW, "POLLIN \n");
528 retval = read(sockfd, (char *) dataptr, datalen);
529 WFD_CLIENT_LOG(WFD_LOG_LOW, "sockfd %d retval %d\n", sockfd,
533 WFD_CLIENT_LOG(WFD_LOG_ERROR,
534 "Error!!! reading data, error [%s]\n",
536 __WFD_CLIENT_FUNC_END__;
539 total_data_recd += retval;
543 __WFD_CLIENT_FUNC_END__;
544 return total_data_recd;
546 else if (pollfd.revents & POLLHUP)
548 WFD_CLIENT_LOG(WFD_LOG_LOW, "POLLHUP\n");
549 __WFD_CLIENT_FUNC_END__;
552 else if (pollfd.revents & POLLERR)
554 WFD_CLIENT_LOG(WFD_LOG_ERROR, "POLLERR\n");
555 __WFD_CLIENT_FUNC_END__;
559 else if (pollret == 0)
561 WFD_CLIENT_LOG(WFD_LOG_ERROR, "POLLing timeout \n");
562 __WFD_CLIENT_FUNC_END__;
567 WFD_CLIENT_LOG(WFD_LOG_ERROR, "Polling unknown error \n");
568 __WFD_CLIENT_FUNC_END__;
571 __WFD_CLIENT_FUNC_END__;
576 static int __wfd_client_read_more_data(int sockfd, void *pData, int Datalen)
580 __WFD_CLIENT_FUNC_START__;
584 WFD_CLIENT_LOG(WFD_LOG_ERROR, "Error!!! Inavlid argument passed\n");
585 __WFD_CLIENT_FUNC_END__;
586 return WIFI_DIRECT_ERROR_INVALID_PARAMETER;
591 WFD_CLIENT_LOG(WFD_LOG_ERROR, "Error!!! Inavlid argument passed\n");
592 __WFD_CLIENT_FUNC_END__;
593 return WIFI_DIRECT_ERROR_INVALID_PARAMETER;
598 WFD_CLIENT_LOG(WFD_LOG_ERROR, "Error!!! Inavlid argument passed\n");
599 __WFD_CLIENT_FUNC_END__;
600 return WIFI_DIRECT_ERROR_INVALID_PARAMETER;
603 /** Initialising the structure variable */
604 memset(pData, 0, Datalen);
606 retval = __wfd_client_read_socket(sockfd, (char *) pData, Datalen);
609 WFD_CLIENT_LOG(WFD_LOG_ERROR,
610 "Error!!! reading response from CM. errno = [%d] \n",
612 __WFD_CLIENT_FUNC_END__;
613 return WIFI_DIRECT_ERROR_OPERATION_FAILED;
616 __WFD_CLIENT_FUNC_END__;
617 return WIFI_DIRECT_ERROR_NONE;
620 void __wfd_client_print_entry_list(wfd_discovery_entry_s * list, int num)
624 WFD_CLIENT_LOG(WFD_LOG_LOW, "------------------------------------------\n");
625 for (i = 0; i < num; i++)
627 WFD_CLIENT_LOG(WFD_LOG_LOW, "== Peer index : %d ==\n", i);
628 WFD_CLIENT_LOG(WFD_LOG_LOW, "is Group Owner ? %s\n",
629 list[i].is_group_owner ? "YES" : "NO");
630 WFD_CLIENT_LOG(WFD_LOG_LOW, "SSID : %s\n", list[i].ssid);
631 WFD_CLIENT_LOG(WFD_LOG_LOW, "MAC address : " MACSTR "\n",
632 MAC2STR(list[i].mac_address));
634 WFD_CLIENT_LOG(WFD_LOG_ERROR,
635 "------------------------------------------\n");
638 void __wfd_client_print_connected_peer_info(wfd_connected_peer_info_s * list, int num)
642 WFD_CLIENT_LOG(WFD_LOG_LOW, "------------------------------------------\n");
643 for (i = 0; i < num; i++)
645 WFD_CLIENT_LOG(WFD_LOG_LOW, "== Peer index : %d ==\n", i);
646 WFD_CLIENT_LOG(WFD_LOG_LOW, "ssid : %s\n", list[i].ssid);
647 WFD_CLIENT_LOG(WFD_LOG_LOW, "Device MAC : " MACSTR "\n",
648 MAC2STR(list[i].mac_address));
649 WFD_CLIENT_LOG(WFD_LOG_LOW, "Interface MAC : " MACSTR "\n",
650 MAC2STR(list[i].intf_mac_address));
651 WFD_CLIENT_LOG(WFD_LOG_LOW, "services : %d\n", list[i].services);
652 WFD_CLIENT_LOG(WFD_LOG_LOW, "is_p2p : %d\n", list[i].is_p2p);
653 WFD_CLIENT_LOG(WFD_LOG_LOW, "category : %d\n", list[i].category);
655 WFD_CLIENT_LOG(WFD_LOG_ERROR,
656 "------------------------------------------\n");
660 void __wfd_client_print_config_data(wfd_config_data_s * config)
665 WFD_CLIENT_LOG(WFD_LOG_LOW, "Operating channel = [%d]\n", config->channel);
666 WFD_CLIENT_LOG(WFD_LOG_LOW, "WPS method = [%d, %s]\n", config->wps_config,
667 (config->wps_config ==
668 WIFI_DIRECT_WPS_PUSHBUTTON) ?
669 "Pushbutton" : (config-> wps_config == WIFI_DIRECT_WPS_DISPLAY)
670 ? "Display" : "Keypad");
672 WFD_CLIENT_LOG(WFD_LOG_LOW, "Max client = [%d]\n", config->max_clients);
673 WFD_CLIENT_LOG(WFD_LOG_LOW, "grp_owner_intent = [%d]\n",
674 config->group_owner_intent);
675 WFD_CLIENT_LOG(WFD_LOG_LOW, "hide-SSID = [%d]\n", config->hide_SSID);
676 WFD_CLIENT_LOG(WFD_LOG_LOW, "want_persistent_group = [%d]\n",
677 config->want_persistent_group);
678 WFD_CLIENT_LOG(WFD_LOG_LOW, "auto_connection = [%d]\n",
679 config->auto_connection);
680 WFD_CLIENT_LOG(WFD_LOG_LOW, "primary_dev_type = [%d]\n",
681 config->primary_dev_type);
682 WFD_CLIENT_LOG(WFD_LOG_LOW, "secondary_dev_type = [%d]\n",
683 config->secondary_dev_type);
688 int wifi_direct_initialize(void)
690 struct sockaddr_un servAddr;
691 char *path = "/tmp/wfd_client_socket";
692 wifi_direct_client_info_s *client_info = __wfd_get_control();
697 __WFD_CLIENT_FUNC_START__;
699 if (client_info->is_registered == TRUE)
701 WFD_CLIENT_LOG(WFD_LOG_ERROR,
702 "Warning!!! Already registered\nUpdate user data and callback!\n");
703 __WFD_CLIENT_FUNC_END__;
704 return WIFI_DIRECT_ERROR_NONE;
708 if ((sockfd = socket(AF_UNIX, SOCK_STREAM, 0)) < 0)
710 WFD_CLIENT_LOG(WFD_LOG_ERROR,
711 "Error!!! creating sync socket. Error = [%s].\n",
713 return WIFI_DIRECT_ERROR_COMMUNICATION_FAILED;
716 WFD_CLIENT_LOG(WFD_LOG_LOW, "Created sync socket [%d]\n", sockfd);
718 memset(&servAddr, 0, sizeof(servAddr));
719 servAddr.sun_family = AF_UNIX;
720 strcpy(servAddr.sun_path, path);
721 len = sizeof(servAddr.sun_family) + strlen(path);
723 WFD_CLIENT_LOG(WFD_LOG_LOW,
724 "Connecting to server socket to register sync socket [%d]\n",
730 while (retry_count > 0)
733 if ((ret = connect(sockfd, (struct sockaddr *) &servAddr, len)) < 0)
735 WFD_CLIENT_LOG(WFD_LOG_LOW, "Launching wfd-server..\n");
737 ("dbus-send --system --print-reply --dest=net.netconfig /net/netconfig/wifi net.netconfig.wifi.LaunchDirect");
748 WFD_CLIENT_LOG(WFD_LOG_ERROR,
749 "Error!!! connecting to server socket. Error = [%d] %s.\n",
750 errno, strerror(errno));
754 __WFD_CLIENT_FUNC_END__;
755 return WIFI_DIRECT_ERROR_COMMUNICATION_FAILED;
759 wifi_direct_client_request_s req;
760 wifi_direct_client_response_s resp;
762 int status = WIFI_DIRECT_ERROR_NONE;
764 memset(&req, 0, sizeof(wifi_direct_client_request_s));
765 memset(&resp, 0, sizeof(wifi_direct_client_response_s));
767 req.cmd = WIFI_DIRECT_CMD_REGISTER;
768 req.client_id = gettid();
769 WFD_CLIENT_LOG(WFD_LOG_LOW, "Client ID = %d\n", req.client_id);
771 status = __wfd_client_send_request(sockfd, &req, sizeof(wifi_direct_client_request_s));
773 if (status != WIFI_DIRECT_ERROR_NONE)
775 WFD_CLIENT_LOG(WFD_LOG_ERROR,
776 "Error!!! writing to socket, Errno = %s\n",
778 WFD_CLIENT_LOG(WFD_LOG_ERROR, "Error!!! [%s]\n",
779 __wfd_print_error(status));
781 __WFD_CLIENT_FUNC_END__;
782 return WIFI_DIRECT_ERROR_COMMUNICATION_FAILED;
786 if ((status = __wfd_client_read_socket(sockfd, (char *) &resp,
787 sizeof(wifi_direct_client_response_s))) <= 0)
789 WFD_CLIENT_LOG(WFD_LOG_ERROR,
790 "Error!!! reading socket, status = %d errno = %s\n",
791 status, strerror(errno));
792 __WFD_CLIENT_FUNC_END__;
793 return WIFI_DIRECT_ERROR_COMMUNICATION_FAILED;
797 if (resp.cmd == WIFI_DIRECT_CMD_REGISTER)
799 if (resp.result == WIFI_DIRECT_ERROR_NONE)
801 WFD_CLIENT_LOG(WFD_LOG_LOW, "Client ID received = %d \n",
803 WFD_CLIENT_LOG(WFD_LOG_LOW,
804 "Connected sync socket %d to the wifi direct server socket\n",
806 client_info->sync_sockfd = sockfd;
807 client_info->client_id = resp.client_id;
808 client_info->is_registered = TRUE;
812 WFD_CLIENT_LOG(WFD_LOG_ERROR,
813 "Error!!! Client Register = %d\n",
816 __WFD_CLIENT_FUNC_END__;
820 int async_sockfd = -1;
821 /* Send request for establishing async communication channel */
823 __wfd_client_async_event_init(client_info->client_id)) ==
824 WIFI_DIRECT_ERROR_COMMUNICATION_FAILED)
826 WFD_CLIENT_LOG(WFD_LOG_ERROR,
827 "Error!!! creating Async Socket \n");
828 __wfd_reset_control();
829 __WFD_CLIENT_FUNC_END__;
830 return WIFI_DIRECT_ERROR_COMMUNICATION_FAILED;
833 client_info->async_sockfd = async_sockfd;
837 WFD_CLIENT_LOG(WFD_LOG_ERROR,
838 "Error!!! Invalid Response received from wfd Server. cmd = %d \n",
841 __WFD_CLIENT_FUNC_END__;
842 return WIFI_DIRECT_ERROR_COMMUNICATION_FAILED;
847 GIOChannel *gio = g_io_channel_unix_new(client_info->async_sockfd);
850 g_io_add_watch(gio, G_IO_IN | G_IO_ERR | G_IO_HUP,
851 (GIOFunc) __wfd_client_process_event, NULL);
853 g_io_channel_unref(gio);
855 WFD_CLIENT_LOG(WFD_LOG_LOW,
856 "Scoket is successfully registered to g_main_loop.\n");
858 client_info->g_source_id = g_source_id;
860 // Initialize callbacks
861 client_info->activation_cb = NULL;
862 client_info->discover_cb = NULL;
863 client_info->connection_cb = NULL;
864 client_info->user_data_for_cb_activation = NULL;
865 client_info->user_data_for_cb_discover = NULL;
866 client_info->user_data_for_cb_connection = NULL;
868 __WFD_CLIENT_FUNC_END__;
870 return WIFI_DIRECT_ERROR_NONE;
875 int wifi_direct_deinitialize(void)
877 wifi_direct_client_info_s *client_info = __wfd_get_control();
879 __WFD_CLIENT_FUNC_START__;
881 if (client_info->is_registered == false)
883 WFD_CLIENT_LOG(WFD_LOG_ERROR, "Client is already deregistered.\n");
884 __WFD_CLIENT_FUNC_END__;
885 return WIFI_DIRECT_ERROR_OPERATION_FAILED;
888 client_info->activation_cb = NULL;
889 client_info->discover_cb = NULL;
890 client_info->connection_cb = NULL;
891 client_info->user_data_for_cb_activation = NULL;
892 client_info->user_data_for_cb_discover = NULL;
893 client_info->user_data_for_cb_connection = NULL;
895 wifi_direct_client_request_s req;
896 wifi_direct_client_response_s rsp;
898 int status = WIFI_DIRECT_ERROR_NONE;
900 memset(&req, 0, sizeof(wifi_direct_client_request_s));
901 memset(&rsp, 0, sizeof(wifi_direct_client_response_s));
903 req.cmd = WIFI_DIRECT_CMD_DEREGISTER;
904 req.client_id = client_info->client_id;
907 __wfd_client_send_request(client_info->sync_sockfd, &req,
908 sizeof(wifi_direct_client_request_s));
909 if (status != WIFI_DIRECT_ERROR_NONE)
911 WFD_CLIENT_LOG(WFD_LOG_ERROR,
912 "Error!!! writing to socket, Errno = %s\n",
914 WFD_CLIENT_LOG(WFD_LOG_ERROR, "Error!!! [%s]\n",
915 __wfd_print_error(status));
916 client_info->sync_sockfd = -1;
917 __wfd_reset_control();
918 __WFD_CLIENT_FUNC_END__;
919 return WIFI_DIRECT_ERROR_COMMUNICATION_FAILED;
923 // Deinit protocol: Send the deregister cmd and wait for socket close...
926 __wfd_client_read_socket(client_info->sync_sockfd, (char *) &rsp,
927 sizeof(wifi_direct_client_response_s))) <= 0)
929 WFD_CLIENT_LOG(WFD_LOG_LOW, "Deinit Successfull\n");
931 if (client_info->g_source_id > 0)
932 g_source_remove(client_info->g_source_id);
933 client_info->g_source_id = -1;
935 close(client_info->sync_sockfd);
936 client_info->sync_sockfd = -1;
937 __wfd_reset_control();
938 __WFD_CLIENT_FUNC_END__;
939 return WIFI_DIRECT_ERROR_NONE;
943 WFD_CLIENT_LOG(WFD_LOG_LOW, "Error.. Something wrong...!!!\n");
946 __wfd_reset_control();
948 __WFD_CLIENT_FUNC_END__;
949 return WIFI_DIRECT_ERROR_NONE;
953 int wifi_direct_set_device_state_changed_cb(wifi_direct_device_state_changed_cb
956 wifi_direct_client_info_s *client_info = __wfd_get_control();
958 __WFD_CLIENT_FUNC_START__;
962 WFD_CLIENT_LOG(WFD_LOG_ERROR, "Callback is NULL.\n");
963 __WFD_CLIENT_FUNC_END__;
964 return WIFI_DIRECT_ERROR_INVALID_PARAMETER;
967 if (client_info->is_registered == false)
969 WFD_CLIENT_LOG(WFD_LOG_ERROR, "Client is not initialized.\n");
970 __WFD_CLIENT_FUNC_END__;
971 return WIFI_DIRECT_ERROR_NOT_PERMITTED;
974 client_info->activation_cb = cb;
975 client_info->user_data_for_cb_activation = user_data;
977 return WIFI_DIRECT_ERROR_NONE;
981 int wifi_direct_unset_device_state_changed_cb(void)
983 wifi_direct_client_info_s *client_info = __wfd_get_control();
985 __WFD_CLIENT_FUNC_START__;
987 if (client_info->is_registered == false)
989 WFD_CLIENT_LOG(WFD_LOG_ERROR, "Client is not initialized.\n");
990 __WFD_CLIENT_FUNC_END__;
991 return WIFI_DIRECT_ERROR_NOT_PERMITTED;
994 client_info->activation_cb = NULL;
995 client_info->user_data_for_cb_activation = NULL;
997 return WIFI_DIRECT_ERROR_NONE;
1002 wifi_direct_set_discovery_state_changed_cb
1003 (wifi_direct_discovery_state_chagned_cb cb, void *user_data)
1005 wifi_direct_client_info_s *client_info = __wfd_get_control();
1007 __WFD_CLIENT_FUNC_START__;
1011 WFD_CLIENT_LOG(WFD_LOG_ERROR, "Callback is NULL.\n");
1012 __WFD_CLIENT_FUNC_END__;
1013 return WIFI_DIRECT_ERROR_INVALID_PARAMETER;
1016 if (client_info->is_registered == false)
1018 WFD_CLIENT_LOG(WFD_LOG_ERROR, "Client is not initialized.\n");
1019 __WFD_CLIENT_FUNC_END__;
1020 return WIFI_DIRECT_ERROR_NOT_PERMITTED;
1023 client_info->discover_cb = cb;
1024 client_info->user_data_for_cb_discover = user_data;
1026 return WIFI_DIRECT_ERROR_NONE;
1030 int wifi_direct_unset_discovery_state_changed_cb(void)
1032 wifi_direct_client_info_s *client_info = __wfd_get_control();
1034 __WFD_CLIENT_FUNC_START__;
1036 if (client_info->is_registered == false)
1038 WFD_CLIENT_LOG(WFD_LOG_ERROR, "Client is not initialized.\n");
1039 __WFD_CLIENT_FUNC_END__;
1040 return WIFI_DIRECT_ERROR_NOT_PERMITTED;
1043 client_info->discover_cb = NULL;
1044 client_info->user_data_for_cb_discover = NULL;
1046 return WIFI_DIRECT_ERROR_NONE;
1051 wifi_direct_set_connection_state_changed_cb
1052 (wifi_direct_connection_state_changed_cb cb, void *user_data)
1054 wifi_direct_client_info_s *client_info = __wfd_get_control();
1056 __WFD_CLIENT_FUNC_START__;
1060 WFD_CLIENT_LOG(WFD_LOG_ERROR, "Callback is NULL.\n");
1061 __WFD_CLIENT_FUNC_END__;
1062 return WIFI_DIRECT_ERROR_INVALID_PARAMETER;
1065 if (client_info->is_registered == false)
1067 WFD_CLIENT_LOG(WFD_LOG_ERROR, "Client is not initialized.\n");
1068 __WFD_CLIENT_FUNC_END__;
1069 return WIFI_DIRECT_ERROR_NOT_PERMITTED;
1072 client_info->connection_cb = cb;
1073 client_info->user_data_for_cb_connection = user_data;
1075 return WIFI_DIRECT_ERROR_NONE;
1079 int wifi_direct_unset_connection_state_changed_cb(void)
1081 wifi_direct_client_info_s *client_info = __wfd_get_control();
1083 __WFD_CLIENT_FUNC_START__;
1085 if (client_info->is_registered == false)
1087 WFD_CLIENT_LOG(WFD_LOG_ERROR, "Client is not initialized.\n");
1088 __WFD_CLIENT_FUNC_END__;
1089 return WIFI_DIRECT_ERROR_NOT_PERMITTED;
1092 client_info->connection_cb = NULL;
1093 client_info->user_data_for_cb_connection = NULL;
1095 return WIFI_DIRECT_ERROR_NONE;
1099 int wifi_direct_activate(void)
1101 wifi_direct_client_info_s *client_info = __wfd_get_control();
1103 __WFD_CLIENT_FUNC_START__;
1105 if ((client_info->is_registered == false)
1106 || (client_info->client_id == WFD_INVALID_ID))
1108 WFD_CLIENT_LOG(WFD_LOG_ERROR, "Client is NOT registered.\n");
1109 __WFD_CLIENT_FUNC_END__;
1110 return WIFI_DIRECT_ERROR_STRANGE_CLIENT;
1113 wifi_direct_client_request_s req;
1114 wifi_direct_client_response_s rsp;
1116 int status = WIFI_DIRECT_ERROR_NONE;
1118 memset(&req, 0, sizeof(wifi_direct_client_request_s));
1119 memset(&rsp, 0, sizeof(wifi_direct_client_response_s));
1121 req.cmd = WIFI_DIRECT_CMD_ACTIVATE;
1122 req.client_id = client_info->client_id;
1125 __wfd_client_send_request(client_info->sync_sockfd, &req,
1126 sizeof(wifi_direct_client_request_s));
1127 if (status != WIFI_DIRECT_ERROR_NONE)
1129 WFD_CLIENT_LOG(WFD_LOG_ERROR,
1130 "Error!!! writing to socket, Errno = %s\n",
1132 WFD_CLIENT_LOG(WFD_LOG_ERROR, "Error!!! [%s]\n",
1133 __wfd_print_error(status));
1134 client_info->sync_sockfd = -1;
1135 __wfd_reset_control();
1136 __WFD_CLIENT_FUNC_END__;
1137 return WIFI_DIRECT_ERROR_COMMUNICATION_FAILED;
1141 __wfd_client_read_socket(client_info->sync_sockfd, (char *) &rsp,
1142 sizeof(wifi_direct_client_response_s))) <= 0)
1144 WFD_CLIENT_LOG(WFD_LOG_ERROR,
1145 "Error!!! reading socket, status = %d errno = %s\n",
1146 status, strerror(errno));
1147 client_info->sync_sockfd = -1;
1148 __wfd_reset_control();
1149 __WFD_CLIENT_FUNC_END__;
1150 return WIFI_DIRECT_ERROR_COMMUNICATION_FAILED;
1154 if (rsp.cmd == WIFI_DIRECT_CMD_ACTIVATE)
1156 if (rsp.result != WIFI_DIRECT_ERROR_NONE)
1158 WFD_CLIENT_LOG(WFD_LOG_ERROR,
1159 "Error!!! Result received = %d \n", rsp.result);
1160 WFD_CLIENT_LOG(WFD_LOG_ERROR, "Error!!! [%s]\n",
1161 __wfd_print_error(rsp.result));
1162 __WFD_CLIENT_FUNC_END__;
1167 WFD_CLIENT_LOG(WFD_LOG_ERROR,
1168 "Activating device is successfull.\n");
1173 WFD_CLIENT_LOG(WFD_LOG_ERROR, "Error!!! Invalid resp cmd = %d\n",
1175 return WIFI_DIRECT_ERROR_OPERATION_FAILED;
1179 __WFD_CLIENT_FUNC_END__;
1180 return WIFI_DIRECT_ERROR_NONE;
1183 int wifi_direct_deactivate(void)
1185 wifi_direct_client_info_s *client_info = __wfd_get_control();
1187 __WFD_CLIENT_FUNC_START__;
1189 if ((client_info->is_registered == false)
1190 || (client_info->client_id == WFD_INVALID_ID))
1192 WFD_CLIENT_LOG(WFD_LOG_ERROR, "Client is NOT registered.\n");
1193 __WFD_CLIENT_FUNC_END__;
1194 return WIFI_DIRECT_ERROR_STRANGE_CLIENT;
1197 wifi_direct_client_request_s req;
1198 wifi_direct_client_response_s rsp;
1200 int status = WIFI_DIRECT_ERROR_NONE;
1202 memset(&req, 0, sizeof(wifi_direct_client_request_s));
1203 memset(&rsp, 0, sizeof(wifi_direct_client_response_s));
1205 req.cmd = WIFI_DIRECT_CMD_DEACTIVATE;
1206 req.client_id = client_info->client_id;
1209 __wfd_client_send_request(client_info->sync_sockfd, &req,
1210 sizeof(wifi_direct_client_request_s));
1211 if (status != WIFI_DIRECT_ERROR_NONE)
1213 WFD_CLIENT_LOG(WFD_LOG_ERROR,
1214 "Error!!! writing to socket, Errno = %s\n",
1216 WFD_CLIENT_LOG(WFD_LOG_ERROR, "Error!!! [%s]\n",
1217 __wfd_print_error(status));
1218 client_info->sync_sockfd = -1;
1219 __wfd_reset_control();
1220 __WFD_CLIENT_FUNC_END__;
1221 return WIFI_DIRECT_ERROR_COMMUNICATION_FAILED;
1225 __wfd_client_read_socket(client_info->sync_sockfd, (char *) &rsp,
1226 sizeof(wifi_direct_client_response_s))) <= 0)
1228 WFD_CLIENT_LOG(WFD_LOG_ERROR,
1229 "Error!!! reading socket, status = %d errno = %s\n",
1230 status, strerror(errno));
1231 client_info->sync_sockfd = -1;
1232 __wfd_reset_control();
1233 __WFD_CLIENT_FUNC_END__;
1234 return WIFI_DIRECT_ERROR_COMMUNICATION_FAILED;
1238 if (rsp.cmd == WIFI_DIRECT_CMD_DEACTIVATE)
1240 if (rsp.result != WIFI_DIRECT_ERROR_NONE)
1242 WFD_CLIENT_LOG(WFD_LOG_ERROR,
1243 "Error!!! Result received = %d \n", rsp.result);
1244 WFD_CLIENT_LOG(WFD_LOG_ERROR, "Error!!! [%s]\n",
1245 __wfd_print_error(rsp.result));
1246 __WFD_CLIENT_FUNC_END__;
1251 WFD_CLIENT_LOG(WFD_LOG_ERROR, "Device Deactivated! \n");
1256 WFD_CLIENT_LOG(WFD_LOG_ERROR, "Error!!! Invalid resp cmd = %d\n",
1258 return WIFI_DIRECT_ERROR_OPERATION_FAILED;
1262 __WFD_CLIENT_FUNC_END__;
1263 return WIFI_DIRECT_ERROR_NONE;
1266 int wifi_direct_start_discovery(bool listen_only, int timeout)
1268 wifi_direct_client_info_s *client_info = __wfd_get_control();
1270 __WFD_CLIENT_FUNC_START__;
1272 if ((client_info->is_registered == false)
1273 || (client_info->client_id == WFD_INVALID_ID))
1275 WFD_CLIENT_LOG(WFD_LOG_ERROR, "Client is NOT registered.\n");
1276 __WFD_CLIENT_FUNC_END__;
1277 return WIFI_DIRECT_ERROR_STRANGE_CLIENT;
1280 wifi_direct_client_request_s req;
1281 wifi_direct_client_response_s rsp;
1283 int status = WIFI_DIRECT_ERROR_NONE;
1285 memset(&req, 0, sizeof(wifi_direct_client_request_s));
1286 memset(&rsp, 0, sizeof(wifi_direct_client_response_s));
1288 req.cmd = WIFI_DIRECT_CMD_START_DISCOVERY;
1289 req.client_id = client_info->client_id;
1290 req.data.listen_only = listen_only;
1291 req.data.timeout = timeout;
1293 WFD_CLIENT_LOG(WFD_LOG_ERROR, "listen only (%d) timeout (%d) \n",
1294 listen_only, timeout);
1297 __wfd_client_send_request(client_info->sync_sockfd, &req,
1298 sizeof(wifi_direct_client_request_s));
1299 if (status != WIFI_DIRECT_ERROR_NONE)
1301 WFD_CLIENT_LOG(WFD_LOG_ERROR,
1302 "Error!!! writing to socket, Errno = %s\n",
1304 WFD_CLIENT_LOG(WFD_LOG_ERROR, "Error!!! [%s]\n",
1305 __wfd_print_error(status));
1306 client_info->sync_sockfd = -1;
1307 __wfd_reset_control();
1308 __WFD_CLIENT_FUNC_END__;
1309 return WIFI_DIRECT_ERROR_COMMUNICATION_FAILED;
1313 __wfd_client_read_socket(client_info->sync_sockfd, (char *) &rsp,
1314 sizeof(wifi_direct_client_response_s))) <= 0)
1316 WFD_CLIENT_LOG(WFD_LOG_ERROR,
1317 "Error!!! reading socket, status = %d errno = %s\n",
1318 status, strerror(errno));
1319 client_info->sync_sockfd = -1;
1320 __wfd_reset_control();
1321 return WIFI_DIRECT_ERROR_COMMUNICATION_FAILED;
1325 if (rsp.cmd == WIFI_DIRECT_CMD_START_DISCOVERY)
1327 if (rsp.result != WIFI_DIRECT_ERROR_NONE)
1329 WFD_CLIENT_LOG(WFD_LOG_ERROR,
1330 "Error!!! Result received = %d \n", rsp.result);
1331 WFD_CLIENT_LOG(WFD_LOG_ERROR, "Error!!! [%s]\n",
1332 __wfd_print_error(rsp.result));
1333 __WFD_CLIENT_FUNC_END__;
1338 WFD_CLIENT_LOG(WFD_LOG_ERROR,
1339 "wifi_direct_start_discovery() SUCCESS \n");
1344 WFD_CLIENT_LOG(WFD_LOG_ERROR, "Error!!! Invalid resp cmd = %d\n",
1346 return WIFI_DIRECT_ERROR_OPERATION_FAILED;
1350 __WFD_CLIENT_FUNC_END__;
1352 return WIFI_DIRECT_ERROR_NONE;
1355 int wifi_direct_cancel_discovery(void)
1357 wifi_direct_client_info_s *client_info = __wfd_get_control();
1359 __WFD_CLIENT_FUNC_START__;
1361 if ((client_info->is_registered == false)
1362 || (client_info->client_id == WFD_INVALID_ID))
1364 WFD_CLIENT_LOG(WFD_LOG_ERROR, "Client is NOT registered.\n");
1365 __WFD_CLIENT_FUNC_END__;
1366 return WIFI_DIRECT_ERROR_STRANGE_CLIENT;
1369 wifi_direct_client_request_s req;
1370 wifi_direct_client_response_s rsp;
1372 int status = WIFI_DIRECT_ERROR_NONE;
1374 memset(&req, 0, sizeof(wifi_direct_client_request_s));
1375 memset(&rsp, 0, sizeof(wifi_direct_client_response_s));
1377 req.cmd = WIFI_DIRECT_CMD_CANCEL_DISCOVERY;
1378 req.client_id = client_info->client_id;
1381 __wfd_client_send_request(client_info->sync_sockfd, &req,
1382 sizeof(wifi_direct_client_request_s));
1383 if (status != WIFI_DIRECT_ERROR_NONE)
1385 WFD_CLIENT_LOG(WFD_LOG_ERROR,
1386 "Error!!! writing to socket, Errno = %s\n",
1388 WFD_CLIENT_LOG(WFD_LOG_ERROR, "Error!!! [%s]\n",
1389 __wfd_print_error(status));
1390 client_info->sync_sockfd = -1;
1391 __wfd_reset_control();
1392 __WFD_CLIENT_FUNC_END__;
1393 return WIFI_DIRECT_ERROR_COMMUNICATION_FAILED;
1397 __wfd_client_read_socket(client_info->sync_sockfd, (char *) &rsp,
1398 sizeof(wifi_direct_client_response_s))) <= 0)
1400 WFD_CLIENT_LOG(WFD_LOG_ERROR,
1401 "Error!!! reading socket, status = %d errno = %s\n",
1402 status, strerror(errno));
1403 client_info->sync_sockfd = -1;
1404 __wfd_reset_control();
1405 __WFD_CLIENT_FUNC_END__;
1406 return WIFI_DIRECT_ERROR_COMMUNICATION_FAILED;
1410 if (rsp.cmd == WIFI_DIRECT_CMD_CANCEL_DISCOVERY)
1412 if (rsp.result != WIFI_DIRECT_ERROR_NONE)
1414 WFD_CLIENT_LOG(WFD_LOG_ERROR,
1415 "Error!!! Result received = %d \n", rsp.result);
1416 WFD_CLIENT_LOG(WFD_LOG_ERROR, "Error!!! [%s]\n",
1417 __wfd_print_error(rsp.result));
1418 __WFD_CLIENT_FUNC_END__;
1423 WFD_CLIENT_LOG(WFD_LOG_ERROR,
1424 "wifi_direct_cancel_discovery() SUCCESS \n");
1429 WFD_CLIENT_LOG(WFD_LOG_ERROR, "Error!!! Invalid resp cmd = %d\n",
1431 return WIFI_DIRECT_ERROR_OPERATION_FAILED;
1435 __WFD_CLIENT_FUNC_END__;
1437 return WIFI_DIRECT_ERROR_NONE;
1441 int wifi_direct_foreach_discovered_peers(wifi_direct_discovered_peer_cb callback, void *user_data)
1443 wifi_direct_client_info_s *client_info = __wfd_get_control();
1445 __WFD_CLIENT_FUNC_START__;
1447 if ((client_info->is_registered == false)
1448 || (client_info->client_id == WFD_INVALID_ID))
1450 WFD_CLIENT_LOG(WFD_LOG_ERROR, "Client is NOT registered.\n");
1451 __WFD_CLIENT_FUNC_END__;
1452 return WIFI_DIRECT_ERROR_STRANGE_CLIENT;
1455 if (callback == NULL)
1457 WFD_CLIENT_LOG(WFD_LOG_ERROR, "NULL Param [callback]!\n");
1458 __WFD_CLIENT_FUNC_END__;
1459 return WIFI_DIRECT_ERROR_INVALID_PARAMETER;
1462 wifi_direct_client_request_s req;
1463 wifi_direct_client_response_s rsp;
1466 int status = WIFI_DIRECT_ERROR_NONE;
1468 memset(&req, 0, sizeof(wifi_direct_client_request_s));
1469 memset(&rsp, 0, sizeof(wifi_direct_client_response_s));
1471 req.cmd = WIFI_DIRECT_CMD_GET_DISCOVERY_RESULT;
1472 req.client_id = client_info->client_id;
1475 __wfd_client_send_request(client_info->sync_sockfd, &req,
1476 sizeof(wifi_direct_client_request_s));
1477 if (status != WIFI_DIRECT_ERROR_NONE)
1479 WFD_CLIENT_LOG(WFD_LOG_ERROR,
1480 "Error!!! writing to socket, Errno = %s\n",
1482 WFD_CLIENT_LOG(WFD_LOG_ERROR, "Error!!! [%s]\n",
1483 __wfd_print_error(status));
1484 client_info->sync_sockfd = -1;
1485 __wfd_reset_control();
1486 __WFD_CLIENT_FUNC_END__;
1487 return WIFI_DIRECT_ERROR_COMMUNICATION_FAILED;
1491 __wfd_client_read_socket(client_info->sync_sockfd, (char *) &rsp,
1492 sizeof(wifi_direct_client_response_s))) <= 0)
1494 WFD_CLIENT_LOG(WFD_LOG_ERROR,
1495 "Error!!! reading socket, status = %d errno = %s\n",
1496 status, strerror(errno));
1497 client_info->sync_sockfd = -1;
1498 __wfd_reset_control();
1499 __WFD_CLIENT_FUNC_END__;
1500 return WIFI_DIRECT_ERROR_COMMUNICATION_FAILED;
1504 if (rsp.cmd == WIFI_DIRECT_CMD_GET_DISCOVERY_RESULT)
1506 if (rsp.result != WIFI_DIRECT_ERROR_NONE)
1508 WFD_CLIENT_LOG(WFD_LOG_ERROR, "Error!!! Result received = %d \n", rsp.result);
1509 WFD_CLIENT_LOG(WFD_LOG_ERROR, "Error!!! [%s]\n", __wfd_print_error(rsp.result));
1510 __WFD_CLIENT_FUNC_END__;
1515 int num = rsp.param1;
1517 wfd_discovery_entry_s *buff = NULL;
1519 WFD_CLIENT_LOG(WFD_LOG_LOW, "Num of found peers = %d \n",
1525 (wfd_discovery_entry_s *) malloc(num * sizeof (wfd_discovery_entry_s));
1528 WFD_CLIENT_LOG(WFD_LOG_ERROR, "malloc() failed!!!.\n");
1529 return WIFI_DIRECT_ERROR_OPERATION_FAILED;
1533 __wfd_client_read_more_data(client_info->sync_sockfd,
1537 (wfd_discovery_entry_s));
1538 if (status != WIFI_DIRECT_ERROR_NONE)
1543 WFD_CLIENT_LOG(WFD_LOG_ERROR, "socket read error.\n");
1544 return WIFI_DIRECT_ERROR_OPERATION_FAILED;
1548 __wfd_client_print_entry_list(buff, num);
1550 WFD_CLIENT_LOG(WFD_LOG_LOW,
1551 "wifi_direct_foreach_discovered_peers() SUCCESS\n");
1554 wifi_direct_discovered_peer_info_s *peer_list;
1556 for (i = 0; i < num; i++)
1558 peer_list = (wifi_direct_discovered_peer_info_s *) calloc(1, sizeof(wifi_direct_discovered_peer_info_s));
1559 peer_list->is_group_owner = buff[i].is_group_owner;
1560 peer_list->ssid = strdup(buff[i].ssid);
1561 peer_list->mac_address = (char *) calloc(1, 18);
1562 snprintf(peer_list->mac_address, 18, MACSTR, MAC2STR(buff[i].mac_address));
1563 peer_list->channel = buff[i].channel;
1564 peer_list->is_connected = buff[i].is_connected;
1565 peer_list->is_persistent_group_owner = buff[i].is_persistent_go;
1566 peer_list->interface_address = (char *) calloc(1, 18);
1567 snprintf(peer_list->interface_address, 18, MACSTR, MAC2STR(buff[i].intf_mac_address));
1568 peer_list->primary_device_type = buff[i].category;
1569 peer_list->secondary_device_type = buff[i].subcategory;
1571 if (!callback(peer_list, user_data))
1582 WFD_CLIENT_LOG(WFD_LOG_ERROR, "Error!!! Invalid resp cmd = %d\n",
1584 return WIFI_DIRECT_ERROR_OPERATION_FAILED;
1588 __WFD_CLIENT_FUNC_END__;
1590 return WIFI_DIRECT_ERROR_NONE;
1594 int wifi_direct_connect(const char *mac_address)
1596 wifi_direct_client_info_s *client_info = __wfd_get_control();
1597 unsigned char la_mac_addr[6];
1599 __WFD_CLIENT_FUNC_START__;
1601 if ((client_info->is_registered == false)
1602 || (client_info->client_id == WFD_INVALID_ID))
1604 WFD_CLIENT_LOG(WFD_LOG_ERROR, "Client is NOT registered.\n");
1605 __WFD_CLIENT_FUNC_END__;
1606 return WIFI_DIRECT_ERROR_STRANGE_CLIENT;
1609 if (mac_address == NULL)
1611 WFD_CLIENT_LOG(WFD_LOG_ERROR, "mac_addr is NULL.\n");
1612 __WFD_CLIENT_FUNC_END__;
1613 return WIFI_DIRECT_ERROR_INVALID_PARAMETER;
1616 wifi_direct_client_request_s req;
1617 wifi_direct_client_response_s rsp;
1619 int status = WIFI_DIRECT_ERROR_NONE;
1621 memset(&req, 0, sizeof(wifi_direct_client_request_s));
1622 memset(&rsp, 0, sizeof(wifi_direct_client_response_s));
1624 req.cmd = WIFI_DIRECT_CMD_CONNECT;
1625 req.client_id = client_info->client_id;
1627 macaddr_atoe(mac_address, la_mac_addr);
1629 req.data.mac_addr[0] = la_mac_addr[0];
1630 req.data.mac_addr[1] = la_mac_addr[1];
1631 req.data.mac_addr[2] = la_mac_addr[2];
1632 req.data.mac_addr[3] = la_mac_addr[3];
1633 req.data.mac_addr[4] = la_mac_addr[4];
1634 req.data.mac_addr[5] = la_mac_addr[5];
1638 __wfd_client_send_request(client_info->sync_sockfd, &req,
1639 sizeof(wifi_direct_client_request_s));
1640 if (status != WIFI_DIRECT_ERROR_NONE)
1642 WFD_CLIENT_LOG(WFD_LOG_ERROR,
1643 "Error!!! writing to socket, Errno = %s\n",
1645 WFD_CLIENT_LOG(WFD_LOG_ERROR, "Error!!! [%s]\n",
1646 __wfd_print_error(status));
1647 client_info->sync_sockfd = -1;
1648 __wfd_reset_control();
1649 __WFD_CLIENT_FUNC_END__;
1650 return WIFI_DIRECT_ERROR_COMMUNICATION_FAILED;
1654 __wfd_client_read_socket(client_info->sync_sockfd, (char *) &rsp,
1655 sizeof(wifi_direct_client_response_s))) <= 0)
1657 WFD_CLIENT_LOG(WFD_LOG_ERROR,
1658 "Error!!! reading socket, status = %d errno = %s\n",
1659 status, strerror(errno));
1660 client_info->sync_sockfd = -1;
1661 __wfd_reset_control();
1662 __WFD_CLIENT_FUNC_END__;
1663 return WIFI_DIRECT_ERROR_COMMUNICATION_FAILED;
1667 if (rsp.cmd == WIFI_DIRECT_CMD_CONNECT)
1669 if (rsp.result != WIFI_DIRECT_ERROR_NONE)
1671 WFD_CLIENT_LOG(WFD_LOG_ERROR,
1672 "Error!!! Result received = %d \n", rsp.result);
1673 WFD_CLIENT_LOG(WFD_LOG_ERROR, "Error!!! [%s]\n",
1674 __wfd_print_error(rsp.result));
1675 __WFD_CLIENT_FUNC_END__;
1680 WFD_CLIENT_LOG(WFD_LOG_ERROR,
1681 "wifi_direct_connect() SUCCESS \n");
1686 WFD_CLIENT_LOG(WFD_LOG_ERROR, "Error!!! Invalid resp cmd = %d\n",
1688 return WIFI_DIRECT_ERROR_OPERATION_FAILED;
1692 __WFD_CLIENT_FUNC_END__;
1694 return WIFI_DIRECT_ERROR_NONE;
1698 int wifi_direct_disconnect_all(void)
1700 wifi_direct_client_info_s *client_info = __wfd_get_control();
1702 __WFD_CLIENT_FUNC_START__;
1704 if ((client_info->is_registered == false)
1705 || (client_info->client_id == WFD_INVALID_ID))
1707 WFD_CLIENT_LOG(WFD_LOG_ERROR, "Client is NOT registered.\n");
1708 __WFD_CLIENT_FUNC_END__;
1709 return WIFI_DIRECT_ERROR_STRANGE_CLIENT;
1712 wifi_direct_client_request_s req;
1713 wifi_direct_client_response_s rsp;
1715 int status = WIFI_DIRECT_ERROR_NONE;
1717 memset(&req, 0, sizeof(wifi_direct_client_request_s));
1718 memset(&rsp, 0, sizeof(wifi_direct_client_response_s));
1720 req.cmd = WIFI_DIRECT_CMD_DISCONNECT_ALL;
1721 req.client_id = client_info->client_id;
1724 __wfd_client_send_request(client_info->sync_sockfd, &req,
1725 sizeof(wifi_direct_client_request_s));
1726 if (status != WIFI_DIRECT_ERROR_NONE)
1728 WFD_CLIENT_LOG(WFD_LOG_ERROR,
1729 "Error!!! writing to socket, Errno = %s\n",
1731 WFD_CLIENT_LOG(WFD_LOG_ERROR, "Error!!! [%s]\n",
1732 __wfd_print_error(status));
1733 client_info->sync_sockfd = -1;
1734 __wfd_reset_control();
1735 __WFD_CLIENT_FUNC_END__;
1736 return WIFI_DIRECT_ERROR_COMMUNICATION_FAILED;
1740 __wfd_client_read_socket(client_info->sync_sockfd, (char *) &rsp,
1741 sizeof(wifi_direct_client_response_s))) <= 0)
1743 WFD_CLIENT_LOG(WFD_LOG_ERROR,
1744 "Error!!! reading socket, status = %d errno = %s\n",
1745 status, strerror(errno));
1746 client_info->sync_sockfd = -1;
1747 __wfd_reset_control();
1748 __WFD_CLIENT_FUNC_END__;
1749 return WIFI_DIRECT_ERROR_COMMUNICATION_FAILED;
1753 if (rsp.cmd == WIFI_DIRECT_CMD_DISCONNECT_ALL)
1755 if (rsp.result != WIFI_DIRECT_ERROR_NONE)
1757 WFD_CLIENT_LOG(WFD_LOG_ERROR,
1758 "Error!!! Result received = %d \n", rsp.result);
1759 WFD_CLIENT_LOG(WFD_LOG_ERROR, "Error!!! [%s]\n",
1760 __wfd_print_error(rsp.result));
1761 __WFD_CLIENT_FUNC_END__;
1766 WFD_CLIENT_LOG(WFD_LOG_ERROR,
1767 "wifi_direct_disconnect_all() SUCCESS \n");
1772 WFD_CLIENT_LOG(WFD_LOG_ERROR, "Error!!! Invalid resp cmd = %d\n",
1774 return WIFI_DIRECT_ERROR_OPERATION_FAILED;
1778 __WFD_CLIENT_FUNC_END__;
1780 return WIFI_DIRECT_ERROR_NONE;
1784 int wifi_direct_disconnect(const char *mac_address)
1786 wifi_direct_client_info_s *client_info = __wfd_get_control();
1787 unsigned char la_mac_addr[6];
1789 __WFD_CLIENT_FUNC_START__;
1791 if (mac_address == NULL)
1793 WFD_CLIENT_LOG(WFD_LOG_ERROR, "mac_address is NULL.\n");
1794 __WFD_CLIENT_FUNC_END__;
1795 return WIFI_DIRECT_ERROR_INVALID_PARAMETER;
1798 if ((client_info->is_registered == false)
1799 || (client_info->client_id == WFD_INVALID_ID))
1801 WFD_CLIENT_LOG(WFD_LOG_ERROR, "Client is NOT registered.\n");
1802 __WFD_CLIENT_FUNC_END__;
1803 return WIFI_DIRECT_ERROR_STRANGE_CLIENT;
1806 wifi_direct_client_request_s req;
1807 wifi_direct_client_response_s rsp;
1809 int status = WIFI_DIRECT_ERROR_NONE;
1811 memset(&req, 0, sizeof(wifi_direct_client_request_s));
1812 memset(&rsp, 0, sizeof(wifi_direct_client_response_s));
1814 req.cmd = WIFI_DIRECT_CMD_DISCONNECT;
1815 req.client_id = client_info->client_id;
1817 macaddr_atoe(mac_address, la_mac_addr);
1819 req.data.mac_addr[0] = la_mac_addr[0];
1820 req.data.mac_addr[1] = la_mac_addr[1];
1821 req.data.mac_addr[2] = la_mac_addr[2];
1822 req.data.mac_addr[3] = la_mac_addr[3];
1823 req.data.mac_addr[4] = la_mac_addr[4];
1824 req.data.mac_addr[5] = la_mac_addr[5];
1827 __wfd_client_send_request(client_info->sync_sockfd, &req,
1828 sizeof(wifi_direct_client_request_s));
1829 if (status != WIFI_DIRECT_ERROR_NONE)
1831 WFD_CLIENT_LOG(WFD_LOG_ERROR,
1832 "Error!!! writing to socket, Errno = %s\n",
1834 WFD_CLIENT_LOG(WFD_LOG_ERROR, "Error!!! [%s]\n",
1835 __wfd_print_error(status));
1836 client_info->sync_sockfd = -1;
1837 __wfd_reset_control();
1838 __WFD_CLIENT_FUNC_END__;
1839 return WIFI_DIRECT_ERROR_COMMUNICATION_FAILED;
1843 __wfd_client_read_socket(client_info->sync_sockfd, (char *) &rsp,
1844 sizeof(wifi_direct_client_response_s))) <= 0)
1846 WFD_CLIENT_LOG(WFD_LOG_ERROR,
1847 "Error!!! reading socket, status = %d errno = %s\n",
1848 status, strerror(errno));
1849 client_info->sync_sockfd = -1;
1850 __wfd_reset_control();
1851 __WFD_CLIENT_FUNC_END__;
1852 return WIFI_DIRECT_ERROR_COMMUNICATION_FAILED;
1856 if (rsp.cmd == WIFI_DIRECT_CMD_DISCONNECT)
1858 if (rsp.result != WIFI_DIRECT_ERROR_NONE)
1860 WFD_CLIENT_LOG(WFD_LOG_ERROR,
1861 "Error!!! Result received = %d \n", rsp.result);
1862 WFD_CLIENT_LOG(WFD_LOG_ERROR, "Error!!! [%s]\n",
1863 __wfd_print_error(rsp.result));
1864 __WFD_CLIENT_FUNC_END__;
1869 WFD_CLIENT_LOG(WFD_LOG_ERROR,
1870 "wifi_direct_disconnect() SUCCESS \n");
1875 WFD_CLIENT_LOG(WFD_LOG_ERROR, "Error!!! Invalid resp cmd = %d\n",
1877 return WIFI_DIRECT_ERROR_OPERATION_FAILED;
1881 __WFD_CLIENT_FUNC_END__;
1883 return WIFI_DIRECT_ERROR_NONE;
1889 int wifi_direct_accept_connection(char *mac_address)
1891 wifi_direct_client_info_s *client_info = __wfd_get_control();
1892 unsigned char la_mac_addr[6];
1894 __WFD_CLIENT_FUNC_START__;
1896 if ((client_info->is_registered == false)
1897 || (client_info->client_id == WFD_INVALID_ID))
1899 WFD_CLIENT_LOG(WFD_LOG_ERROR, "Client is NOT registered.\n");
1900 __WFD_CLIENT_FUNC_END__;
1901 return WIFI_DIRECT_ERROR_STRANGE_CLIENT;
1904 if (mac_address == NULL)
1906 WFD_CLIENT_LOG(WFD_LOG_ERROR, "mac_addr is NULL.\n");
1907 __WFD_CLIENT_FUNC_END__;
1908 return WIFI_DIRECT_ERROR_INVALID_PARAMETER;
1911 wifi_direct_client_request_s req;
1912 wifi_direct_client_response_s rsp;
1914 int status = WIFI_DIRECT_ERROR_NONE;
1916 memset(&req, 0, sizeof(wifi_direct_client_request_s));
1917 memset(&rsp, 0, sizeof(wifi_direct_client_response_s));
1919 req.cmd = WIFI_DIRECT_CMD_SEND_CONNECT_REQ;
1920 req.client_id = client_info->client_id;
1922 macaddr_atoe(mac_address, la_mac_addr);
1924 req.data.mac_addr[0] = la_mac_addr[0];
1925 req.data.mac_addr[1] = la_mac_addr[1];
1926 req.data.mac_addr[2] = la_mac_addr[2];
1927 req.data.mac_addr[3] = la_mac_addr[3];
1928 req.data.mac_addr[4] = la_mac_addr[4];
1929 req.data.mac_addr[5] = la_mac_addr[5];
1932 __wfd_client_send_request(client_info->sync_sockfd, &req,
1933 sizeof(wifi_direct_client_request_s));
1934 if (status != WIFI_DIRECT_ERROR_NONE)
1936 WFD_CLIENT_LOG(WFD_LOG_ERROR,
1937 "Error!!! writing to socket, Errno = %s\n",
1939 WFD_CLIENT_LOG(WFD_LOG_ERROR, "Error!!! [%s]\n",
1940 __wfd_print_error(status));
1941 client_info->sync_sockfd = -1;
1942 __wfd_reset_control();
1943 __WFD_CLIENT_FUNC_END__;
1944 return WIFI_DIRECT_ERROR_COMMUNICATION_FAILED;
1948 __wfd_client_read_socket(client_info->sync_sockfd, (char *) &rsp,
1949 sizeof(wifi_direct_client_response_s))) <= 0)
1951 WFD_CLIENT_LOG(WFD_LOG_ERROR,
1952 "Error!!! reading socket, status = %d errno = %s\n",
1953 status, strerror(errno));
1954 client_info->sync_sockfd = -1;
1955 __wfd_reset_control();
1956 __WFD_CLIENT_FUNC_END__;
1957 return WIFI_DIRECT_ERROR_COMMUNICATION_FAILED;
1961 if (rsp.cmd == WIFI_DIRECT_CMD_SEND_CONNECT_REQ)
1963 if (rsp.result != WIFI_DIRECT_ERROR_NONE)
1965 WFD_CLIENT_LOG(WFD_LOG_ERROR,
1966 "Error!!! Result received = %d \n", rsp.result);
1967 WFD_CLIENT_LOG(WFD_LOG_ERROR, "Error!!! [%s]\n",
1968 __wfd_print_error(rsp.result));
1969 __WFD_CLIENT_FUNC_END__;
1974 WFD_CLIENT_LOG(WFD_LOG_ERROR,
1975 "wifi_direct_connect() SUCCESS \n");
1980 WFD_CLIENT_LOG(WFD_LOG_ERROR, "Error!!! Invalid resp cmd = %d\n",
1982 return WIFI_DIRECT_ERROR_OPERATION_FAILED;
1986 __WFD_CLIENT_FUNC_END__;
1988 return WIFI_DIRECT_ERROR_NONE;
1992 int wifi_direct_foreach_connected_peers(wifi_direct_connected_peer_cb callback, void *user_data)
1994 wifi_direct_client_info_s *client_info = __wfd_get_control();
1996 __WFD_CLIENT_FUNC_START__;
1998 if ((client_info->is_registered == false)
1999 || (client_info->client_id == WFD_INVALID_ID))
2001 WFD_CLIENT_LOG(WFD_LOG_ERROR, "Client is NOT registered.\n");
2002 __WFD_CLIENT_FUNC_END__;
2003 return WIFI_DIRECT_ERROR_STRANGE_CLIENT;
2006 if (callback == NULL)
2008 WFD_CLIENT_LOG(WFD_LOG_ERROR, "NULL Param [callback]!\n");
2009 __WFD_CLIENT_FUNC_END__;
2010 return WIFI_DIRECT_ERROR_INVALID_PARAMETER;
2013 wifi_direct_client_request_s req;
2014 wifi_direct_client_response_s rsp;
2017 int status = WIFI_DIRECT_ERROR_NONE;
2019 memset(&req, 0, sizeof(wifi_direct_client_request_s));
2020 memset(&rsp, 0, sizeof(wifi_direct_client_response_s));
2022 req.cmd = WIFI_DIRECT_CMD_GET_CONNECTED_PEERS_INFO;
2023 req.client_id = client_info->client_id;
2026 __wfd_client_send_request(client_info->sync_sockfd, &req,
2027 sizeof(wifi_direct_client_request_s));
2028 if (status != WIFI_DIRECT_ERROR_NONE)
2030 WFD_CLIENT_LOG(WFD_LOG_ERROR,
2031 "Error!!! writing to socket, Errno = %s\n",
2033 WFD_CLIENT_LOG(WFD_LOG_ERROR, "Error!!! [%s]\n",
2034 __wfd_print_error(status));
2035 client_info->sync_sockfd = -1;
2036 __wfd_reset_control();
2037 __WFD_CLIENT_FUNC_END__;
2038 return WIFI_DIRECT_ERROR_COMMUNICATION_FAILED;
2042 __wfd_client_read_socket(client_info->sync_sockfd, (char *) &rsp,
2043 sizeof(wifi_direct_client_response_s))) <= 0)
2045 WFD_CLIENT_LOG(WFD_LOG_ERROR,
2046 "Error!!! reading socket, status = %d errno = %s\n",
2047 status, strerror(errno));
2048 client_info->sync_sockfd = -1;
2049 __wfd_reset_control();
2050 __WFD_CLIENT_FUNC_END__;
2051 return WIFI_DIRECT_ERROR_COMMUNICATION_FAILED;
2055 if (rsp.cmd == WIFI_DIRECT_CMD_GET_CONNECTED_PEERS_INFO)
2057 if (rsp.result != WIFI_DIRECT_ERROR_NONE)
2059 WFD_CLIENT_LOG(WFD_LOG_ERROR,
2060 "Error!!! Result received = %d \n", rsp.result);
2061 WFD_CLIENT_LOG(WFD_LOG_ERROR, "Error!!! [%s]\n",
2062 __wfd_print_error(rsp.result));
2063 __WFD_CLIENT_FUNC_END__;
2069 int num = rsp.param1;
2071 wfd_connected_peer_info_s *buff = NULL;
2073 WFD_CLIENT_LOG(WFD_LOG_LOW, "Num of connected peers = %d \n",
2079 (wfd_connected_peer_info_s *) malloc(num *
2081 (wfd_connected_peer_info_s));
2084 WFD_CLIENT_LOG(WFD_LOG_ERROR, "malloc() failed!!!.\n");
2085 return WIFI_DIRECT_ERROR_OPERATION_FAILED;
2089 __wfd_client_read_more_data(client_info->sync_sockfd,
2093 (wfd_connected_peer_info_s));
2094 if (status != WIFI_DIRECT_ERROR_NONE)
2098 WFD_CLIENT_LOG(WFD_LOG_ERROR, "socket read error.\n");
2099 return WIFI_DIRECT_ERROR_OPERATION_FAILED;
2103 __wfd_client_print_connected_peer_info(buff, num);
2105 WFD_CLIENT_LOG(WFD_LOG_LOW,
2106 "wifi_direct_foreach_connected_peers() SUCCESS\n");
2108 wifi_direct_connected_peer_info_s *peer_list;
2110 for (i = 0; i < num; i++)
2112 peer_list = (wifi_direct_connected_peer_info_s *) calloc(1, sizeof(wifi_direct_connected_peer_info_s));
2113 peer_list->ssid = strdup(buff[i].ssid);
2114 peer_list->mac_address = (char *) calloc(1, 18);
2115 snprintf(peer_list->mac_address, 18, MACSTR, MAC2STR(buff[i].mac_address));
2116 peer_list->interface_address = (char *) calloc(1, 18);
2117 snprintf(peer_list->interface_address, 18, MACSTR, MAC2STR(buff[i].intf_mac_address));
2118 peer_list->p2p_supported = buff[i].is_p2p;
2119 peer_list->primary_device_type = buff[i].category;
2121 if (!callback(peer_list, user_data))
2132 WFD_CLIENT_LOG(WFD_LOG_ERROR, "Error!!! Invalid resp cmd = %d\n",
2134 return WIFI_DIRECT_ERROR_OPERATION_FAILED;
2138 __WFD_CLIENT_FUNC_END__;
2140 return WIFI_DIRECT_ERROR_NONE;
2144 int wifi_direct_create_group(void)
2146 wifi_direct_client_info_s *client_info = __wfd_get_control();
2148 __WFD_CLIENT_FUNC_START__;
2150 if ((client_info->is_registered == false)
2151 || (client_info->client_id == WFD_INVALID_ID))
2153 WFD_CLIENT_LOG(WFD_LOG_ERROR, "Client is NOT registered.\n");
2154 __WFD_CLIENT_FUNC_END__;
2155 return WIFI_DIRECT_ERROR_STRANGE_CLIENT;
2158 wifi_direct_client_request_s req;
2159 wifi_direct_client_response_s rsp;
2161 int status = WIFI_DIRECT_ERROR_NONE;
2163 memset(&req, 0, sizeof(wifi_direct_client_request_s));
2164 memset(&rsp, 0, sizeof(wifi_direct_client_response_s));
2166 req.cmd = WIFI_DIRECT_CMD_CREATE_GROUP;
2167 req.client_id = client_info->client_id;
2170 __wfd_client_send_request(client_info->sync_sockfd, &req,
2171 sizeof(wifi_direct_client_request_s));
2172 if (status != WIFI_DIRECT_ERROR_NONE)
2174 WFD_CLIENT_LOG(WFD_LOG_ERROR,
2175 "Error!!! writing to socket, Errno = %s\n",
2177 WFD_CLIENT_LOG(WFD_LOG_ERROR, "Error!!! [%s]\n",
2178 __wfd_print_error(status));
2179 client_info->sync_sockfd = -1;
2180 __wfd_reset_control();
2181 __WFD_CLIENT_FUNC_END__;
2182 return WIFI_DIRECT_ERROR_COMMUNICATION_FAILED;
2186 __wfd_client_read_socket(client_info->sync_sockfd, (char *) &rsp,
2187 sizeof(wifi_direct_client_response_s))) <= 0)
2189 WFD_CLIENT_LOG(WFD_LOG_ERROR,
2190 "Error!!! reading socket, status = %d errno = %s\n",
2191 status, strerror(errno));
2192 client_info->sync_sockfd = -1;
2193 __wfd_reset_control();
2194 __WFD_CLIENT_FUNC_END__;
2195 return WIFI_DIRECT_ERROR_COMMUNICATION_FAILED;
2199 if (rsp.cmd == WIFI_DIRECT_CMD_CREATE_GROUP)
2201 if (rsp.result != WIFI_DIRECT_ERROR_NONE)
2203 WFD_CLIENT_LOG(WFD_LOG_ERROR,
2204 "Error!!! Result received = %d \n", rsp.result);
2205 WFD_CLIENT_LOG(WFD_LOG_ERROR, "Error!!! [%s]\n",
2206 __wfd_print_error(rsp.result));
2207 __WFD_CLIENT_FUNC_END__;
2212 WFD_CLIENT_LOG(WFD_LOG_ERROR,
2213 "wifi_direct_create_group() SUCCESS \n");
2218 WFD_CLIENT_LOG(WFD_LOG_ERROR, "Error!!! Invalid resp cmd = %d\n",
2220 return WIFI_DIRECT_ERROR_OPERATION_FAILED;
2224 __WFD_CLIENT_FUNC_END__;
2226 return WIFI_DIRECT_ERROR_NONE;
2230 int wifi_direct_destroy_group(void)
2232 wifi_direct_client_info_s *client_info = __wfd_get_control();
2234 __WFD_CLIENT_FUNC_START__;
2236 if ((client_info->is_registered == false)
2237 || (client_info->client_id == WFD_INVALID_ID))
2239 WFD_CLIENT_LOG(WFD_LOG_ERROR, "Client is NOT registered.\n");
2240 __WFD_CLIENT_FUNC_END__;
2241 return WIFI_DIRECT_ERROR_STRANGE_CLIENT;
2244 wifi_direct_client_request_s req;
2245 wifi_direct_client_response_s rsp;
2247 int status = WIFI_DIRECT_ERROR_NONE;
2249 memset(&req, 0, sizeof(wifi_direct_client_request_s));
2250 memset(&rsp, 0, sizeof(wifi_direct_client_response_s));
2252 req.cmd = WIFI_DIRECT_CMD_CANCEL_GROUP;
2253 req.client_id = client_info->client_id;
2256 __wfd_client_send_request(client_info->sync_sockfd, &req,
2257 sizeof(wifi_direct_client_request_s));
2258 if (status != WIFI_DIRECT_ERROR_NONE)
2260 WFD_CLIENT_LOG(WFD_LOG_ERROR,
2261 "Error!!! writing to socket, Errno = %s\n",
2263 WFD_CLIENT_LOG(WFD_LOG_ERROR, "Error!!! [%s]\n",
2264 __wfd_print_error(status));
2265 client_info->sync_sockfd = -1;
2266 __wfd_reset_control();
2267 __WFD_CLIENT_FUNC_END__;
2268 return WIFI_DIRECT_ERROR_COMMUNICATION_FAILED;
2272 __wfd_client_read_socket(client_info->sync_sockfd, (char *) &rsp,
2273 sizeof(wifi_direct_client_response_s))) <= 0)
2275 WFD_CLIENT_LOG(WFD_LOG_ERROR,
2276 "Error!!! reading socket, status = %d errno = %s\n",
2277 status, strerror(errno));
2278 client_info->sync_sockfd = -1;
2279 __wfd_reset_control();
2280 __WFD_CLIENT_FUNC_END__;
2281 return WIFI_DIRECT_ERROR_COMMUNICATION_FAILED;
2285 if (rsp.cmd == WIFI_DIRECT_CMD_CANCEL_GROUP)
2287 if (rsp.result != WIFI_DIRECT_ERROR_NONE)
2289 WFD_CLIENT_LOG(WFD_LOG_ERROR,
2290 "Error!!! Result received = %d \n", rsp.result);
2291 WFD_CLIENT_LOG(WFD_LOG_ERROR, "Error!!! [%s]\n",
2292 __wfd_print_error(rsp.result));
2293 __WFD_CLIENT_FUNC_END__;
2298 WFD_CLIENT_LOG(WFD_LOG_ERROR,
2299 "wifi_direct_destroy_group() SUCCESS \n");
2304 WFD_CLIENT_LOG(WFD_LOG_ERROR, "Error!!! Invalid resp cmd = %d\n",
2306 return WIFI_DIRECT_ERROR_OPERATION_FAILED;
2310 __WFD_CLIENT_FUNC_END__;
2312 return WIFI_DIRECT_ERROR_NONE;
2316 int wifi_direct_is_group_owner(bool * owner)
2318 wifi_direct_client_info_s *client_info = __wfd_get_control();
2320 __WFD_CLIENT_FUNC_START__;
2324 WFD_CLIENT_LOG(WFD_LOG_ERROR, "NULL Param [owner]!\n");
2325 __WFD_CLIENT_FUNC_END__;
2326 return WIFI_DIRECT_ERROR_INVALID_PARAMETER;
2329 if ((client_info->is_registered == false)
2330 || (client_info->client_id == WFD_INVALID_ID))
2332 WFD_CLIENT_LOG(WFD_LOG_ERROR, "Client is NOT registered.\n");
2333 __WFD_CLIENT_FUNC_END__;
2334 return WIFI_DIRECT_ERROR_STRANGE_CLIENT;
2337 wifi_direct_client_request_s req;
2338 wifi_direct_client_response_s rsp;
2340 int status = WIFI_DIRECT_ERROR_NONE;
2342 memset(&req, 0, sizeof(wifi_direct_client_request_s));
2343 memset(&rsp, 0, sizeof(wifi_direct_client_response_s));
2345 req.cmd = WIFI_DIRECT_CMD_IS_GROUPOWNER;
2346 req.client_id = client_info->client_id;
2349 __wfd_client_send_request(client_info->sync_sockfd, &req,
2350 sizeof(wifi_direct_client_request_s));
2351 if (status != WIFI_DIRECT_ERROR_NONE)
2353 WFD_CLIENT_LOG(WFD_LOG_ERROR,
2354 "Error!!! writing to socket, Errno = %s\n",
2356 WFD_CLIENT_LOG(WFD_LOG_ERROR, "Error!!! [%s]\n",
2357 __wfd_print_error(status));
2358 client_info->sync_sockfd = -1;
2359 __wfd_reset_control();
2360 __WFD_CLIENT_FUNC_END__;
2361 return WIFI_DIRECT_ERROR_COMMUNICATION_FAILED;
2365 __wfd_client_read_socket(client_info->sync_sockfd, (char *) &rsp,
2366 sizeof(wifi_direct_client_response_s))) <= 0)
2368 WFD_CLIENT_LOG(WFD_LOG_ERROR,
2369 "Error!!! reading socket, status = %d errno = %s\n",
2370 status, strerror(errno));
2371 client_info->sync_sockfd = -1;
2372 __wfd_reset_control();
2373 __WFD_CLIENT_FUNC_END__;
2374 return WIFI_DIRECT_ERROR_COMMUNICATION_FAILED;
2378 if (rsp.cmd == WIFI_DIRECT_CMD_IS_GROUPOWNER)
2380 if (rsp.result != WIFI_DIRECT_ERROR_NONE)
2382 WFD_CLIENT_LOG(WFD_LOG_LOW, "Error!!! Result received = %d \n",
2384 WFD_CLIENT_LOG(WFD_LOG_LOW, "Error!!! [%s]\n",
2385 __wfd_print_error(rsp.result));
2386 __WFD_CLIENT_FUNC_END__;
2391 WFD_CLIENT_LOG(WFD_LOG_LOW,
2392 "wifi_direct_is_group_owner() %s SUCCESS \n",
2394 *owner = (bool) rsp.param1;
2399 WFD_CLIENT_LOG(WFD_LOG_ERROR, "Error!!! Invalid resp cmd = %d\n",
2401 return WIFI_DIRECT_ERROR_OPERATION_FAILED;
2405 __WFD_CLIENT_FUNC_END__;
2407 return WIFI_DIRECT_ERROR_NONE;
2412 int wifi_direct_is_autonomous_group(bool * autonomous_group)
2414 wifi_direct_client_info_s *client_info = __wfd_get_control();
2416 __WFD_CLIENT_FUNC_START__;
2418 if (autonomous_group == NULL)
2420 WFD_CLIENT_LOG(WFD_LOG_ERROR, "NULL Param [autonomous_group]!\n");
2421 __WFD_CLIENT_FUNC_END__;
2422 return WIFI_DIRECT_ERROR_INVALID_PARAMETER;
2425 if ((client_info->is_registered == false)
2426 || (client_info->client_id == WFD_INVALID_ID))
2428 WFD_CLIENT_LOG(WFD_LOG_ERROR, "Client is NOT registered.\n");
2429 __WFD_CLIENT_FUNC_END__;
2430 return WIFI_DIRECT_ERROR_STRANGE_CLIENT;
2433 wifi_direct_client_request_s req;
2434 wifi_direct_client_response_s rsp;
2436 int status = WIFI_DIRECT_ERROR_NONE;
2438 memset(&req, 0, sizeof(wifi_direct_client_request_s));
2439 memset(&rsp, 0, sizeof(wifi_direct_client_response_s));
2441 req.cmd = WIFI_DIRECT_CMD_IS_AUTONOMOUS_GROUP;
2442 req.client_id = client_info->client_id;
2445 __wfd_client_send_request(client_info->sync_sockfd, &req,
2446 sizeof(wifi_direct_client_request_s));
2447 if (status != WIFI_DIRECT_ERROR_NONE)
2449 WFD_CLIENT_LOG(WFD_LOG_ERROR,
2450 "Error!!! writing to socket, Errno = %s\n",
2452 WFD_CLIENT_LOG(WFD_LOG_ERROR, "Error!!! [%s]\n",
2453 __wfd_print_error(status));
2454 client_info->sync_sockfd = -1;
2455 __wfd_reset_control();
2456 __WFD_CLIENT_FUNC_END__;
2457 return WIFI_DIRECT_ERROR_COMMUNICATION_FAILED;
2461 __wfd_client_read_socket(client_info->sync_sockfd, (char *) &rsp,
2462 sizeof(wifi_direct_client_response_s))) <= 0)
2464 WFD_CLIENT_LOG(WFD_LOG_ERROR,
2465 "Error!!! reading socket, status = %d errno = %s\n",
2466 status, strerror(errno));
2467 client_info->sync_sockfd = -1;
2468 __wfd_reset_control();
2469 __WFD_CLIENT_FUNC_END__;
2470 return WIFI_DIRECT_ERROR_COMMUNICATION_FAILED;
2474 if (rsp.cmd == WIFI_DIRECT_CMD_IS_AUTONOMOUS_GROUP)
2476 if (rsp.result != WIFI_DIRECT_ERROR_NONE)
2478 WFD_CLIENT_LOG(WFD_LOG_LOW, "Error!!! Result received = %d \n",
2480 WFD_CLIENT_LOG(WFD_LOG_LOW, "Error!!! [%s]\n",
2481 __wfd_print_error(rsp.result));
2482 __WFD_CLIENT_FUNC_END__;
2487 WFD_CLIENT_LOG(WFD_LOG_LOW,
2488 "wifi_direct_is_autonomous_group() %s SUCCESS \n",
2490 *autonomous_group = (bool) rsp.param1;
2495 WFD_CLIENT_LOG(WFD_LOG_ERROR, "Error!!! Invalid resp cmd = %d\n",
2497 return WIFI_DIRECT_ERROR_OPERATION_FAILED;
2501 __WFD_CLIENT_FUNC_END__;
2503 return WIFI_DIRECT_ERROR_NONE;
2508 int wifi_direct_get_go_intent(int *intent)
2510 wifi_direct_client_info_s *client_info = __wfd_get_control();
2512 __WFD_CLIENT_FUNC_START__;
2514 if ((client_info->is_registered == false)
2515 || (client_info->client_id == WFD_INVALID_ID))
2517 WFD_CLIENT_LOG(WFD_LOG_ERROR, "Client is NOT registered.\n");
2518 __WFD_CLIENT_FUNC_END__;
2519 return WIFI_DIRECT_ERROR_STRANGE_CLIENT;
2522 wifi_direct_client_request_s req;
2523 wifi_direct_client_response_s rsp;
2525 int status = WIFI_DIRECT_ERROR_NONE;
2527 memset(&req, 0, sizeof(wifi_direct_client_request_s));
2528 memset(&rsp, 0, sizeof(wifi_direct_client_response_s));
2530 req.cmd = WIFI_DIRECT_CMD_GET_GO_INTENT;
2531 req.client_id = client_info->client_id;
2534 __wfd_client_send_request(client_info->sync_sockfd, &req,
2535 sizeof(wifi_direct_client_request_s));
2536 if (status != WIFI_DIRECT_ERROR_NONE)
2538 WFD_CLIENT_LOG(WFD_LOG_ERROR,
2539 "Error!!! writing to socket, Errno = %s\n",
2541 WFD_CLIENT_LOG(WFD_LOG_ERROR, "Error!!! [%s]\n",
2542 __wfd_print_error(status));
2543 client_info->sync_sockfd = -1;
2544 __wfd_reset_control();
2545 __WFD_CLIENT_FUNC_END__;
2546 return WIFI_DIRECT_ERROR_COMMUNICATION_FAILED;
2550 __wfd_client_read_socket(client_info->sync_sockfd, (char *) &rsp,
2551 sizeof(wifi_direct_client_response_s))) <= 0)
2553 WFD_CLIENT_LOG(WFD_LOG_ERROR,
2554 "Error!!! reading socket, status = %d errno = %s\n",
2555 status, strerror(errno));
2556 client_info->sync_sockfd = -1;
2557 __wfd_reset_control();
2558 __WFD_CLIENT_FUNC_END__;
2559 return WIFI_DIRECT_ERROR_COMMUNICATION_FAILED;
2563 if (rsp.cmd == WIFI_DIRECT_CMD_GET_GO_INTENT)
2565 if (rsp.result != WIFI_DIRECT_ERROR_NONE)
2567 WFD_CLIENT_LOG(WFD_LOG_LOW, "Error!!! Result received = %d \n",
2569 WFD_CLIENT_LOG(WFD_LOG_LOW, "Error!!! [%s]\n",
2570 __wfd_print_error(rsp.result));
2571 __WFD_CLIENT_FUNC_END__;
2576 WFD_CLIENT_LOG(WFD_LOG_LOW,
2577 "wifi_direct_get_go_intent() intent[%d] SUCCESS \n",
2579 *intent = rsp.param1;
2584 WFD_CLIENT_LOG(WFD_LOG_ERROR, "Error!!! Invalid resp cmd = %d\n",
2586 return WIFI_DIRECT_ERROR_OPERATION_FAILED;
2590 __WFD_CLIENT_FUNC_END__;
2592 return WIFI_DIRECT_ERROR_NONE;
2596 int wifi_direct_set_wpa_passphrase(char *passphrase)
2598 wifi_direct_client_info_s *client_info = __wfd_get_control();
2600 __WFD_CLIENT_FUNC_START__;
2602 if ((client_info->is_registered == false)
2603 || (client_info->client_id == WFD_INVALID_ID))
2605 WFD_CLIENT_LOG(WFD_LOG_ERROR, "Client is NOT registered.\n");
2606 __WFD_CLIENT_FUNC_END__;
2607 return WIFI_DIRECT_ERROR_STRANGE_CLIENT;
2610 if (NULL == passphrase)
2612 WFD_CLIENT_LOG(WFD_LOG_ERROR, "NULL Param [passphrase]!\n");
2613 __WFD_CLIENT_FUNC_END__;
2614 return WIFI_DIRECT_ERROR_INVALID_PARAMETER;
2617 WFD_CLIENT_LOG(WFD_LOG_ERROR, "passphrase = [%s]\n", passphrase);
2619 wifi_direct_client_request_s req;
2620 wifi_direct_client_response_s rsp;
2622 int status = WIFI_DIRECT_ERROR_NONE;
2624 memset(&req, 0, sizeof(wifi_direct_client_request_s));
2625 memset(&rsp, 0, sizeof(wifi_direct_client_response_s));
2627 req.cmd = WIFI_DIRECT_CMD_SET_WPA;
2628 req.client_id = client_info->client_id;
2631 __wfd_client_send_request(client_info->sync_sockfd, &req,
2632 sizeof(wifi_direct_client_request_s));
2633 if (status != WIFI_DIRECT_ERROR_NONE)
2635 WFD_CLIENT_LOG(WFD_LOG_ERROR,
2636 "Error!!! writing to socket, Errno = %s\n",
2638 WFD_CLIENT_LOG(WFD_LOG_ERROR, "Error!!! [%s]\n",
2639 __wfd_print_error(status));
2640 client_info->sync_sockfd = -1;
2641 __wfd_reset_control();
2642 __WFD_CLIENT_FUNC_END__;
2643 return WIFI_DIRECT_ERROR_COMMUNICATION_FAILED;
2646 WFD_CLIENT_LOG(WFD_LOG_LOW, "writing msg hdr is success!\n");
2649 __wfd_client_send_request(client_info->sync_sockfd, passphrase, 64);
2650 if (status != WIFI_DIRECT_ERROR_NONE)
2652 WFD_CLIENT_LOG(WFD_LOG_ERROR,
2653 "Error!!! writing to socket, Errno = %s\n",
2655 WFD_CLIENT_LOG(WFD_LOG_ERROR, "Error!!! [%s]\n",
2656 __wfd_print_error(status));
2657 client_info->sync_sockfd = -1;
2658 __wfd_reset_control();
2659 __WFD_CLIENT_FUNC_END__;
2660 return WIFI_DIRECT_ERROR_COMMUNICATION_FAILED;
2664 __wfd_client_read_socket(client_info->sync_sockfd, (char *) &rsp,
2665 sizeof(wifi_direct_client_response_s))) <= 0)
2667 WFD_CLIENT_LOG(WFD_LOG_ERROR,
2668 "Error!!! reading socket, status = %d errno = %s\n",
2669 status, strerror(errno));
2670 client_info->sync_sockfd = -1;
2671 __wfd_reset_control();
2672 __WFD_CLIENT_FUNC_END__;
2673 return WIFI_DIRECT_ERROR_COMMUNICATION_FAILED;
2677 if (rsp.cmd == WIFI_DIRECT_CMD_SET_WPA)
2679 if (rsp.result != WIFI_DIRECT_ERROR_NONE)
2681 WFD_CLIENT_LOG(WFD_LOG_ERROR,
2682 "Error!!! Result received = %d \n", rsp.result);
2683 WFD_CLIENT_LOG(WFD_LOG_ERROR, "Error!!! [%s]\n",
2684 __wfd_print_error(rsp.result));
2685 __WFD_CLIENT_FUNC_END__;
2691 WFD_CLIENT_LOG(WFD_LOG_ERROR, "Error!!! Invalid resp cmd = %d\n",
2693 return WIFI_DIRECT_ERROR_OPERATION_FAILED;
2697 __WFD_CLIENT_FUNC_END__;
2699 return WIFI_DIRECT_ERROR_NONE;
2703 int wifi_direct_activate_pushbutton(void)
2705 wifi_direct_client_info_s *client_info = __wfd_get_control();
2707 __WFD_CLIENT_FUNC_START__;
2709 if ((client_info->is_registered == false)
2710 || (client_info->client_id == WFD_INVALID_ID))
2712 WFD_CLIENT_LOG(WFD_LOG_ERROR, "Client is NOT registered.\n");
2713 __WFD_CLIENT_FUNC_END__;
2714 return WIFI_DIRECT_ERROR_STRANGE_CLIENT;
2717 wifi_direct_client_request_s req;
2718 wifi_direct_client_response_s rsp;
2720 int status = WIFI_DIRECT_ERROR_NONE;
2722 memset(&req, 0, sizeof(wifi_direct_client_request_s));
2723 memset(&rsp, 0, sizeof(wifi_direct_client_response_s));
2725 req.cmd = WIFI_DIRECT_CMD_ACTIVATE_PUSHBUTTON;
2726 req.client_id = client_info->client_id;
2729 __wfd_client_send_request(client_info->sync_sockfd, &req,
2730 sizeof(wifi_direct_client_request_s));
2731 if (status != WIFI_DIRECT_ERROR_NONE)
2733 WFD_CLIENT_LOG(WFD_LOG_ERROR,
2734 "Error!!! writing to socket, Errno = %s\n",
2736 WFD_CLIENT_LOG(WFD_LOG_ERROR, "Error!!! [%s]\n",
2737 __wfd_print_error(status));
2738 client_info->sync_sockfd = -1;
2739 __wfd_reset_control();
2740 __WFD_CLIENT_FUNC_END__;
2741 return WIFI_DIRECT_ERROR_COMMUNICATION_FAILED;
2745 __wfd_client_read_socket(client_info->sync_sockfd, (char *) &rsp,
2746 sizeof(wifi_direct_client_response_s))) <= 0)
2748 WFD_CLIENT_LOG(WFD_LOG_ERROR,
2749 "Error!!! reading socket, status = %d errno = %s\n",
2750 status, strerror(errno));
2751 client_info->sync_sockfd = -1;
2752 __wfd_reset_control();
2753 __WFD_CLIENT_FUNC_END__;
2754 return WIFI_DIRECT_ERROR_COMMUNICATION_FAILED;
2758 if (rsp.cmd == WIFI_DIRECT_CMD_ACTIVATE_PUSHBUTTON)
2760 if (rsp.result != WIFI_DIRECT_ERROR_NONE)
2762 WFD_CLIENT_LOG(WFD_LOG_LOW, "Error!!! Result received = %d \n",
2764 WFD_CLIENT_LOG(WFD_LOG_LOW, "Error!!! [%s]\n",
2765 __wfd_print_error(rsp.result));
2766 __WFD_CLIENT_FUNC_END__;
2771 WFD_CLIENT_LOG(WFD_LOG_LOW,
2772 "wifi_direct_activate_pushbutton() SUCCESS \n");
2777 WFD_CLIENT_LOG(WFD_LOG_ERROR, "Error!!! Invalid resp cmd = %d\n",
2779 return WIFI_DIRECT_ERROR_OPERATION_FAILED;
2783 __WFD_CLIENT_FUNC_END__;
2785 return WIFI_DIRECT_ERROR_NONE;
2789 int wifi_direct_set_wps_pin(char *pin)
2792 wifi_direct_client_info_s *client_info = __wfd_get_control();
2794 __WFD_CLIENT_FUNC_START__;
2796 if ((client_info->is_registered == false)
2797 || (client_info->client_id == WFD_INVALID_ID))
2799 WFD_CLIENT_LOG(WFD_LOG_ERROR, "Client is NOT registered.\n");
2800 __WFD_CLIENT_FUNC_END__;
2801 return WIFI_DIRECT_ERROR_STRANGE_CLIENT;
2806 WFD_CLIENT_LOG(WFD_LOG_ERROR, "NULL Param [pin]!\n");
2807 __WFD_CLIENT_FUNC_END__;
2808 return WIFI_DIRECT_ERROR_INVALID_PARAMETER;
2810 WFD_CLIENT_LOG(WFD_LOG_ERROR, "pin = [%s]\n", pin);
2812 wifi_direct_client_request_s req;
2813 wifi_direct_client_response_s rsp;
2815 int status = WIFI_DIRECT_ERROR_NONE;
2817 memset(&req, 0, sizeof(wifi_direct_client_request_s));
2818 memset(&rsp, 0, sizeof(wifi_direct_client_response_s));
2820 req.cmd = WIFI_DIRECT_CMD_SET_WPS_PIN;
2821 req.client_id = client_info->client_id;
2824 __wfd_client_send_request(client_info->sync_sockfd, &req,
2825 sizeof(wifi_direct_client_request_s));
2826 if (status != WIFI_DIRECT_ERROR_NONE)
2828 WFD_CLIENT_LOG(WFD_LOG_ERROR,
2829 "Error!!! writing to socket, Errno = %s\n",
2831 WFD_CLIENT_LOG(WFD_LOG_ERROR, "Error!!! [%s]\n",
2832 __wfd_print_error(status));
2833 client_info->sync_sockfd = -1;
2834 __wfd_reset_control();
2835 __WFD_CLIENT_FUNC_END__;
2836 return WIFI_DIRECT_ERROR_COMMUNICATION_FAILED;
2839 WFD_CLIENT_LOG(WFD_LOG_LOW, "writing msg hdr is success!\n");
2842 __wfd_client_send_request(client_info->sync_sockfd, pin,
2843 WIFI_DIRECT_WPS_PIN_LEN);
2844 if (status != WIFI_DIRECT_ERROR_NONE)
2846 WFD_CLIENT_LOG(WFD_LOG_ERROR,
2847 "Error!!! writing to socket, Errno = %s\n",
2849 WFD_CLIENT_LOG(WFD_LOG_ERROR, "Error!!! [%s]\n",
2850 __wfd_print_error(status));
2851 client_info->sync_sockfd = -1;
2852 __wfd_reset_control();
2853 __WFD_CLIENT_FUNC_END__;
2854 return WIFI_DIRECT_ERROR_COMMUNICATION_FAILED;
2858 __wfd_client_read_socket(client_info->sync_sockfd, (char *) &rsp,
2859 sizeof(wifi_direct_client_response_s))) <= 0)
2861 WFD_CLIENT_LOG(WFD_LOG_ERROR,
2862 "Error!!! reading socket, status = %d errno = %s\n",
2863 status, strerror(errno));
2864 __WFD_CLIENT_FUNC_END__;
2865 return WIFI_DIRECT_ERROR_COMMUNICATION_FAILED;
2869 if (rsp.cmd == WIFI_DIRECT_CMD_SET_WPS_PIN)
2871 if (rsp.result != WIFI_DIRECT_ERROR_NONE)
2873 WFD_CLIENT_LOG(WFD_LOG_LOW, "Error!!! Result received = %d \n",
2875 WFD_CLIENT_LOG(WFD_LOG_LOW, "Error!!! [%s]\n",
2876 __wfd_print_error(rsp.result));
2877 __WFD_CLIENT_FUNC_END__;
2883 WFD_CLIENT_LOG(WFD_LOG_ERROR, "Error!!! Invalid resp cmd = %d\n",
2885 return WIFI_DIRECT_ERROR_OPERATION_FAILED;
2889 __WFD_CLIENT_FUNC_END__;
2891 return WIFI_DIRECT_ERROR_NONE;
2895 int wifi_direct_get_wps_pin(char **pin)
2897 wifi_direct_client_info_s *client_info = __wfd_get_control();
2899 __WFD_CLIENT_FUNC_START__;
2901 if ((client_info->is_registered == false)
2902 || (client_info->client_id == WFD_INVALID_ID))
2904 WFD_CLIENT_LOG(WFD_LOG_ERROR, "Client is NOT registered.\n");
2905 __WFD_CLIENT_FUNC_END__;
2906 return WIFI_DIRECT_ERROR_STRANGE_CLIENT;
2909 wifi_direct_client_request_s req;
2910 wifi_direct_client_response_s rsp;
2911 char la_pin[WIFI_DIRECT_WPS_PIN_LEN + 1] = { 0, };
2913 int status = WIFI_DIRECT_ERROR_NONE;
2915 memset(&req, 0, sizeof(wifi_direct_client_request_s));
2916 memset(&rsp, 0, sizeof(wifi_direct_client_response_s));
2918 req.cmd = WIFI_DIRECT_CMD_GET_WPS_PIN;
2919 req.client_id = client_info->client_id;
2922 __wfd_client_send_request(client_info->sync_sockfd, &req,
2923 sizeof(wifi_direct_client_request_s));
2924 if (status != WIFI_DIRECT_ERROR_NONE)
2926 WFD_CLIENT_LOG(WFD_LOG_ERROR,
2927 "Error!!! writing to socket, Errno = %s\n",
2929 WFD_CLIENT_LOG(WFD_LOG_ERROR, "Error!!! [%s]\n",
2930 __wfd_print_error(status));
2931 client_info->sync_sockfd = -1;
2932 __wfd_reset_control();
2933 __WFD_CLIENT_FUNC_END__;
2934 return WIFI_DIRECT_ERROR_COMMUNICATION_FAILED;
2938 __wfd_client_read_socket(client_info->sync_sockfd, (char *) &rsp,
2939 sizeof(wifi_direct_client_response_s))) <= 0)
2941 WFD_CLIENT_LOG(WFD_LOG_ERROR,
2942 "Error!!! reading socket, status = %d errno = %s\n",
2943 status, strerror(errno));
2944 client_info->sync_sockfd = -1;
2945 __wfd_reset_control();
2946 __WFD_CLIENT_FUNC_END__;
2947 return WIFI_DIRECT_ERROR_COMMUNICATION_FAILED;
2951 if (rsp.cmd == WIFI_DIRECT_CMD_GET_WPS_PIN)
2953 if (rsp.result != WIFI_DIRECT_ERROR_NONE)
2955 WFD_CLIENT_LOG(WFD_LOG_LOW, "Error!!! Result received = %d \n",
2957 WFD_CLIENT_LOG(WFD_LOG_LOW, "Error!!! [%s]\n",
2958 __wfd_print_error(rsp.result));
2959 __WFD_CLIENT_FUNC_END__;
2964 WFD_CLIENT_LOG(WFD_LOG_LOW,
2965 "wifi_direct_get_wps_pin() SUCCESS \n");
2966 strncpy(la_pin, rsp.param2, WIFI_DIRECT_WPS_PIN_LEN);
2969 temp_pin = strdup(la_pin);
2976 WFD_CLIENT_LOG(WFD_LOG_ERROR, "Error!!! Invalid resp cmd = %d\n",
2978 return WIFI_DIRECT_ERROR_OPERATION_FAILED;
2982 __WFD_CLIENT_FUNC_END__;
2984 return WIFI_DIRECT_ERROR_NONE;
2988 int wifi_direct_generate_wps_pin(void)
2990 wifi_direct_client_info_s *client_info = __wfd_get_control();
2992 __WFD_CLIENT_FUNC_START__;
2994 if ((client_info->is_registered == false)
2995 || (client_info->client_id == WFD_INVALID_ID))
2997 WFD_CLIENT_LOG(WFD_LOG_ERROR, "Client is NOT registered.\n");
2998 __WFD_CLIENT_FUNC_END__;
2999 return WIFI_DIRECT_ERROR_STRANGE_CLIENT;
3002 wifi_direct_client_request_s req;
3003 wifi_direct_client_response_s rsp;
3005 int status = WIFI_DIRECT_ERROR_NONE;
3007 memset(&req, 0, sizeof(wifi_direct_client_request_s));
3008 memset(&rsp, 0, sizeof(wifi_direct_client_response_s));
3010 req.cmd = WIFI_DIRECT_CMD_GENERATE_WPS_PIN;
3011 req.client_id = client_info->client_id;
3014 __wfd_client_send_request(client_info->sync_sockfd, &req,
3015 sizeof(wifi_direct_client_request_s));
3016 if (status != WIFI_DIRECT_ERROR_NONE)
3018 WFD_CLIENT_LOG(WFD_LOG_ERROR,
3019 "Error!!! writing to socket, Errno = %s\n",
3021 WFD_CLIENT_LOG(WFD_LOG_ERROR, "Error!!! [%s]\n",
3022 __wfd_print_error(status));
3023 client_info->sync_sockfd = -1;
3024 __wfd_reset_control();
3025 __WFD_CLIENT_FUNC_END__;
3026 return WIFI_DIRECT_ERROR_COMMUNICATION_FAILED;
3030 __wfd_client_read_socket(client_info->sync_sockfd, (char *) &rsp,
3031 sizeof(wifi_direct_client_response_s))) <= 0)
3033 WFD_CLIENT_LOG(WFD_LOG_ERROR,
3034 "Error!!! reading socket, status = %d errno = %s\n",
3035 status, strerror(errno));
3036 client_info->sync_sockfd = -1;
3037 __wfd_reset_control();
3038 __WFD_CLIENT_FUNC_END__;
3039 return WIFI_DIRECT_ERROR_COMMUNICATION_FAILED;
3043 if (rsp.cmd == WIFI_DIRECT_CMD_GENERATE_WPS_PIN)
3045 if (rsp.result != WIFI_DIRECT_ERROR_NONE)
3047 WFD_CLIENT_LOG(WFD_LOG_LOW, "Error!!! Result received = %d \n",
3049 WFD_CLIENT_LOG(WFD_LOG_LOW, "Error!!! [%s]\n",
3050 __wfd_print_error(rsp.result));
3051 __WFD_CLIENT_FUNC_END__;
3056 WFD_CLIENT_LOG(WFD_LOG_LOW,
3057 "wifi_direct_generate_wps_pin() SUCCESS \n");
3062 WFD_CLIENT_LOG(WFD_LOG_ERROR, "Error!!! Invalid resp cmd = %d\n",
3064 return WIFI_DIRECT_ERROR_OPERATION_FAILED;
3068 __WFD_CLIENT_FUNC_END__;
3070 return WIFI_DIRECT_ERROR_NONE;
3074 int wifi_direct_get_supported_wps_mode(int *wps_mode)
3076 wifi_direct_client_info_s *client_info = __wfd_get_control();
3078 __WFD_CLIENT_FUNC_START__;
3080 if ((client_info->is_registered == false)
3081 || (client_info->client_id == WFD_INVALID_ID))
3083 WFD_CLIENT_LOG(WFD_LOG_ERROR, "Client is NOT registered.\n");
3084 __WFD_CLIENT_FUNC_END__;
3085 return WIFI_DIRECT_ERROR_STRANGE_CLIENT;
3088 wifi_direct_client_request_s req;
3089 wifi_direct_client_response_s rsp;
3091 int ret = WIFI_DIRECT_ERROR_NONE;
3093 memset(&req, 0, sizeof(wifi_direct_client_request_s));
3094 memset(&rsp, 0, sizeof(wifi_direct_client_response_s));
3096 req.cmd = WIFI_DIRECT_CMD_GET_SUPPORTED_WPS_MODE;
3097 req.client_id = client_info->client_id;
3100 __wfd_client_send_request(client_info->sync_sockfd, &req,
3101 sizeof(wifi_direct_client_request_s));
3102 if (ret != WIFI_DIRECT_ERROR_NONE)
3104 WFD_CLIENT_LOG(WFD_LOG_ERROR,
3105 "Error!!! writing to socket, Errno = %s\n",
3107 WFD_CLIENT_LOG(WFD_LOG_ERROR, "Error!!! [%s]\n",
3108 __wfd_print_error(ret));
3109 client_info->sync_sockfd = -1;
3110 __wfd_reset_control();
3111 __WFD_CLIENT_FUNC_END__;
3112 return WIFI_DIRECT_ERROR_COMMUNICATION_FAILED;
3116 __wfd_client_read_socket(client_info->sync_sockfd, (char *) &rsp,
3117 sizeof(wifi_direct_client_response_s))) <= 0)
3119 WFD_CLIENT_LOG(WFD_LOG_ERROR,
3120 "Error!!! reading socket, status = %d errno = %s\n", ret,
3122 client_info->sync_sockfd = -1;
3123 __wfd_reset_control();
3124 __WFD_CLIENT_FUNC_END__;
3125 return WIFI_DIRECT_ERROR_COMMUNICATION_FAILED;
3129 if (rsp.cmd == WIFI_DIRECT_CMD_GET_SUPPORTED_WPS_MODE)
3131 if (rsp.result != WIFI_DIRECT_ERROR_NONE)
3133 WFD_CLIENT_LOG(WFD_LOG_LOW, "Error!!! Result received = %d \n",
3135 WFD_CLIENT_LOG(WFD_LOG_LOW, "Error!!! [%s]\n",
3136 __wfd_print_error(rsp.result));
3137 __WFD_CLIENT_FUNC_END__;
3142 WFD_CLIENT_LOG(WFD_LOG_LOW, "Supported wps config = [%d]\n",
3144 *wps_mode = rsp.param1;
3149 WFD_CLIENT_LOG(WFD_LOG_ERROR, "Error!!! Invalid resp cmd = %d\n",
3151 return WIFI_DIRECT_ERROR_OPERATION_FAILED;
3155 __WFD_CLIENT_FUNC_END__;
3157 return WIFI_DIRECT_ERROR_NONE;
3162 int wifi_direct_set_ssid(const char *ssid)
3164 wifi_direct_client_info_s *client_info = __wfd_get_control();
3166 __WFD_CLIENT_FUNC_START__;
3168 if ((client_info->is_registered == false)
3169 || (client_info->client_id == WFD_INVALID_ID))
3171 WFD_CLIENT_LOG(WFD_LOG_ERROR, "Client is NOT registered.\n");
3172 __WFD_CLIENT_FUNC_END__;
3173 return WIFI_DIRECT_ERROR_STRANGE_CLIENT;
3178 WFD_CLIENT_LOG(WFD_LOG_ERROR, "NULL Param [ssid]!\n");
3179 __WFD_CLIENT_FUNC_END__;
3180 return WIFI_DIRECT_ERROR_INVALID_PARAMETER;
3183 WFD_CLIENT_LOG(WFD_LOG_ERROR, "ssid = [%s]\n", ssid);
3185 wifi_direct_client_request_s req;
3186 wifi_direct_client_response_s rsp;
3188 int status = WIFI_DIRECT_ERROR_NONE;
3190 memset(&req, 0, sizeof(wifi_direct_client_request_s));
3191 memset(&rsp, 0, sizeof(wifi_direct_client_response_s));
3193 req.cmd = WIFI_DIRECT_CMD_SET_SSID;
3194 req.client_id = client_info->client_id;
3197 __wfd_client_send_request(client_info->sync_sockfd, &req,
3198 sizeof(wifi_direct_client_request_s));
3199 if (status != WIFI_DIRECT_ERROR_NONE)
3201 WFD_CLIENT_LOG(WFD_LOG_ERROR,
3202 "Error!!! writing to socket, Errno = %s\n",
3204 WFD_CLIENT_LOG(WFD_LOG_ERROR, "Error!!! [%s]\n",
3205 __wfd_print_error(status));
3206 client_info->sync_sockfd = -1;
3207 __wfd_reset_control();
3208 __WFD_CLIENT_FUNC_END__;
3209 return WIFI_DIRECT_ERROR_COMMUNICATION_FAILED;
3212 WFD_CLIENT_LOG(WFD_LOG_LOW, "writing msg hdr is success!\n");
3215 __wfd_client_send_request(client_info->sync_sockfd, ssid,
3216 WIFI_DIRECT_MAX_SSID_LEN);
3217 if (status != WIFI_DIRECT_ERROR_NONE)
3219 WFD_CLIENT_LOG(WFD_LOG_ERROR,
3220 "Error!!! writing to socket, Errno = %s\n",
3222 WFD_CLIENT_LOG(WFD_LOG_ERROR, "Error!!! [%s]\n",
3223 __wfd_print_error(status));
3224 client_info->sync_sockfd = -1;
3225 __wfd_reset_control();
3226 __WFD_CLIENT_FUNC_END__;
3227 return WIFI_DIRECT_ERROR_COMMUNICATION_FAILED;
3231 __wfd_client_read_socket(client_info->sync_sockfd, (char *) &rsp,
3232 sizeof(wifi_direct_client_response_s))) <= 0)
3234 WFD_CLIENT_LOG(WFD_LOG_ERROR,
3235 "Error!!! reading socket, status = %d errno = %s\n",
3236 status, strerror(errno));
3237 client_info->sync_sockfd = -1;
3238 __wfd_reset_control();
3239 __WFD_CLIENT_FUNC_END__;
3240 return WIFI_DIRECT_ERROR_COMMUNICATION_FAILED;
3244 if (rsp.cmd == WIFI_DIRECT_CMD_SET_SSID)
3246 if (rsp.result != WIFI_DIRECT_ERROR_NONE)
3248 WFD_CLIENT_LOG(WFD_LOG_ERROR,
3249 "Error!!! Result received = %d \n", rsp.result);
3250 WFD_CLIENT_LOG(WFD_LOG_ERROR, "Error!!! [%s]\n",
3251 __wfd_print_error(rsp.result));
3252 __WFD_CLIENT_FUNC_END__;
3258 WFD_CLIENT_LOG(WFD_LOG_ERROR, "Error!!! Invalid resp cmd = %d\n",
3260 return WIFI_DIRECT_ERROR_OPERATION_FAILED;
3264 __WFD_CLIENT_FUNC_END__;
3266 return WIFI_DIRECT_ERROR_NONE;
3271 int wifi_direct_get_ssid(char **ssid)
3273 wifi_direct_client_info_s *client_info = __wfd_get_control();
3275 __WFD_CLIENT_FUNC_START__;
3279 WFD_CLIENT_LOG(WFD_LOG_ERROR, "NULL Param [ssid]!\n");
3280 __WFD_CLIENT_FUNC_END__;
3281 return WIFI_DIRECT_ERROR_INVALID_PARAMETER;
3284 if ((client_info->is_registered == false)
3285 || (client_info->client_id == WFD_INVALID_ID))
3287 WFD_CLIENT_LOG(WFD_LOG_ERROR, "Client is NOT registered.\n");
3288 __WFD_CLIENT_FUNC_END__;
3289 return WIFI_DIRECT_ERROR_STRANGE_CLIENT;
3292 wifi_direct_client_request_s req;
3293 wifi_direct_client_response_s rsp;
3294 char la_ssid[WIFI_DIRECT_MAX_SSID_LEN + 1] = { 0, };
3296 int status = WIFI_DIRECT_ERROR_NONE;
3298 memset(&req, 0, sizeof(wifi_direct_client_request_s));
3299 memset(&rsp, 0, sizeof(wifi_direct_client_response_s));
3301 req.cmd = WIFI_DIRECT_CMD_GET_SSID;
3302 req.client_id = client_info->client_id;
3305 __wfd_client_send_request(client_info->sync_sockfd, &req,
3306 sizeof(wifi_direct_client_request_s));
3307 if (status != WIFI_DIRECT_ERROR_NONE)
3309 WFD_CLIENT_LOG(WFD_LOG_ERROR,
3310 "Error!!! writing to socket, Errno = %s\n",
3312 WFD_CLIENT_LOG(WFD_LOG_ERROR, "Error!!! [%s]\n",
3313 __wfd_print_error(status));
3314 client_info->sync_sockfd = -1;
3315 __wfd_reset_control();
3316 __WFD_CLIENT_FUNC_END__;
3317 return WIFI_DIRECT_ERROR_COMMUNICATION_FAILED;
3321 __wfd_client_read_socket(client_info->sync_sockfd, (char *) &rsp,
3322 sizeof(wifi_direct_client_response_s))) <= 0)
3324 WFD_CLIENT_LOG(WFD_LOG_ERROR,
3325 "Error!!! reading socket, status = %d errno = %s\n",
3326 status, strerror(errno));
3327 client_info->sync_sockfd = -1;
3328 __wfd_reset_control();
3329 __WFD_CLIENT_FUNC_END__;
3330 return WIFI_DIRECT_ERROR_COMMUNICATION_FAILED;
3334 if (rsp.cmd == WIFI_DIRECT_CMD_GET_SSID)
3336 if (rsp.result != WIFI_DIRECT_ERROR_NONE)
3338 WFD_CLIENT_LOG(WFD_LOG_LOW, "Error!!! Result received = %d \n",
3340 WFD_CLIENT_LOG(WFD_LOG_LOW, "Error!!! [%s]\n",
3341 __wfd_print_error(rsp.result));
3342 __WFD_CLIENT_FUNC_END__;
3347 WFD_CLIENT_LOG(WFD_LOG_LOW,
3348 "wifi_direct_get_ssid() %s SUCCESS \n",
3350 strncpy(la_ssid, rsp.param2, WIFI_DIRECT_MAX_SSID_LEN);
3353 temp_ssid = strdup(la_ssid);
3361 WFD_CLIENT_LOG(WFD_LOG_ERROR, "Error!!! Invalid resp cmd = %d\n",
3363 return WIFI_DIRECT_ERROR_OPERATION_FAILED;
3367 __WFD_CLIENT_FUNC_END__;
3369 return WIFI_DIRECT_ERROR_NONE;
3373 int wifi_direct_get_ip_address(char **ip_address)
3375 wifi_direct_client_info_s *client_info = __wfd_get_control();
3377 __WFD_CLIENT_FUNC_START__;
3379 if (NULL == ip_address)
3381 WFD_CLIENT_LOG(WFD_LOG_ERROR, "NULL Param [ip_address]!\n");
3382 __WFD_CLIENT_FUNC_END__;
3383 return WIFI_DIRECT_ERROR_INVALID_PARAMETER;
3386 if ((client_info->is_registered == false)
3387 || (client_info->client_id == WFD_INVALID_ID))
3389 WFD_CLIENT_LOG(WFD_LOG_ERROR, "Client is NOT registered.\n");
3390 __WFD_CLIENT_FUNC_END__;
3391 return WIFI_DIRECT_ERROR_STRANGE_CLIENT;
3394 wifi_direct_client_request_s req;
3395 wifi_direct_client_response_s rsp;
3396 char la_ip[64] = { 0, };
3398 int status = WIFI_DIRECT_ERROR_NONE;
3400 memset(&req, 0, sizeof(wifi_direct_client_request_s));
3401 memset(&rsp, 0, sizeof(wifi_direct_client_response_s));
3403 req.cmd = WIFI_DIRECT_CMD_GET_IP_ADDR;
3404 req.client_id = client_info->client_id;
3407 __wfd_client_send_request(client_info->sync_sockfd, &req,
3408 sizeof(wifi_direct_client_request_s));
3409 if (status != WIFI_DIRECT_ERROR_NONE)
3411 WFD_CLIENT_LOG(WFD_LOG_ERROR,
3412 "Error!!! writing to socket, Errno = %s\n",
3414 WFD_CLIENT_LOG(WFD_LOG_ERROR, "Error!!! [%s]\n",
3415 __wfd_print_error(status));
3416 client_info->sync_sockfd = -1;
3417 __wfd_reset_control();
3418 __WFD_CLIENT_FUNC_END__;
3419 return WIFI_DIRECT_ERROR_COMMUNICATION_FAILED;
3423 __wfd_client_read_socket(client_info->sync_sockfd, (char *) &rsp,
3424 sizeof(wifi_direct_client_response_s))) <= 0)
3426 WFD_CLIENT_LOG(WFD_LOG_ERROR,
3427 "Error!!! reading socket, status = %d errno = %s\n",
3428 status, strerror(errno));
3429 client_info->sync_sockfd = -1;
3430 __wfd_reset_control();
3431 __WFD_CLIENT_FUNC_END__;
3432 return WIFI_DIRECT_ERROR_COMMUNICATION_FAILED;
3436 if (rsp.cmd == WIFI_DIRECT_CMD_GET_IP_ADDR)
3438 if (rsp.result != WIFI_DIRECT_ERROR_NONE)
3440 WFD_CLIENT_LOG(WFD_LOG_LOW, "Error!!! Result received = %d \n",
3442 WFD_CLIENT_LOG(WFD_LOG_LOW, "Error!!! [%s]\n",
3443 __wfd_print_error(rsp.result));
3444 __WFD_CLIENT_FUNC_END__;
3449 WFD_CLIENT_LOG(WFD_LOG_LOW,
3450 "wifi_direct_get_ip_address() SUCCESS \n");
3451 strncpy(la_ip, rsp.param2, strlen(rsp.param2));
3454 temp_ip = strdup(la_ip);
3456 *ip_address = temp_ip;
3461 WFD_CLIENT_LOG(WFD_LOG_ERROR, "Error!!! Invalid resp cmd = %d\n",
3463 return WIFI_DIRECT_ERROR_OPERATION_FAILED;
3467 __WFD_CLIENT_FUNC_END__;
3469 return WIFI_DIRECT_ERROR_NONE;
3473 int wifi_direct_get_mac_address(char **mac_address)
3475 wifi_direct_client_info_s *client_info = __wfd_get_control();
3477 __WFD_CLIENT_FUNC_START__;
3479 if (NULL == mac_address)
3481 WFD_CLIENT_LOG(WFD_LOG_ERROR, "NULL Param [mac_address]!\n");
3482 __WFD_CLIENT_FUNC_END__;
3483 return WIFI_DIRECT_ERROR_INVALID_PARAMETER;
3486 if ((client_info->is_registered == false)
3487 || (client_info->client_id == WFD_INVALID_ID))
3489 WFD_CLIENT_LOG(WFD_LOG_LOW, "Client is NOT registered.\n");
3490 __WFD_CLIENT_FUNC_END__;
3491 return WIFI_DIRECT_ERROR_STRANGE_CLIENT;
3494 wifi_direct_client_request_s req;
3495 wifi_direct_client_response_s rsp;
3496 unsigned char la_mac_addr[6] = { 0, };
3498 int status = WIFI_DIRECT_ERROR_NONE;
3500 memset(&req, 0, sizeof(wifi_direct_client_request_s));
3501 memset(&rsp, 0, sizeof(wifi_direct_client_response_s));
3503 req.cmd = WIFI_DIRECT_CMD_GET_DEVICE_MAC;
3504 req.client_id = client_info->client_id;
3507 __wfd_client_send_request(client_info->sync_sockfd, &req,
3508 sizeof(wifi_direct_client_request_s));
3509 if (status != WIFI_DIRECT_ERROR_NONE)
3511 WFD_CLIENT_LOG(WFD_LOG_LOW, "Error!!! writing to socket, Errno = %s\n",
3513 WFD_CLIENT_LOG(WFD_LOG_LOW, "Error!!! [%s]\n",
3514 __wfd_print_error(status));
3515 close(client_info->sync_sockfd);
3516 __WFD_CLIENT_FUNC_END__;
3517 return WIFI_DIRECT_ERROR_COMMUNICATION_FAILED;
3521 __wfd_client_read_socket(client_info->sync_sockfd, (char *) &rsp,
3522 sizeof(wifi_direct_client_response_s))) <= 0)
3524 WFD_CLIENT_LOG(WFD_LOG_LOW,
3525 "Error!!! reading socket, status = %d errno = %s\n",
3526 status, strerror(errno));
3527 __WFD_CLIENT_FUNC_END__;
3528 return WIFI_DIRECT_ERROR_COMMUNICATION_FAILED;
3532 if (rsp.cmd == WIFI_DIRECT_CMD_GET_DEVICE_MAC)
3534 if (rsp.result != WIFI_DIRECT_ERROR_NONE)
3536 WFD_CLIENT_LOG(WFD_LOG_LOW, "Error!!! Result received = %d \n",
3538 WFD_CLIENT_LOG(WFD_LOG_LOW, "Error!!! [%s]\n",
3539 __wfd_print_error(rsp.result));
3540 __WFD_CLIENT_FUNC_END__;
3545 WFD_CLIENT_LOG(WFD_LOG_LOW,
3546 "wifi_direct_get_mac_addr() SUCCESS \n");
3547 strncpy((char *) la_mac_addr, (char *) rsp.param2,
3548 strlen(rsp.param2));
3550 char *temp_mac = NULL;
3551 temp_mac = (char *) calloc(1, 18);
3553 sprintf(temp_mac, MACSTR, MAC2STR(la_mac_addr));
3555 *mac_address = temp_mac;
3561 WFD_CLIENT_LOG(WFD_LOG_ERROR, "Error!!! Invalid resp cmd = %d\n",
3563 return WIFI_DIRECT_ERROR_OPERATION_FAILED;
3567 __WFD_CLIENT_FUNC_END__;
3569 return WIFI_DIRECT_ERROR_NONE;
3573 int wifi_direct_get_state(wifi_direct_state_e * state)
3575 wifi_direct_client_info_s *client_info = __wfd_get_control();
3577 __WFD_CLIENT_FUNC_START__;
3581 WFD_CLIENT_LOG(WFD_LOG_ERROR, "NULL Param [state]!\n");
3582 __WFD_CLIENT_FUNC_END__;
3583 return WIFI_DIRECT_ERROR_INVALID_PARAMETER;
3586 if ((client_info->is_registered == false)
3587 || (client_info->client_id == WFD_INVALID_ID))
3589 WFD_CLIENT_LOG(WFD_LOG_ERROR, "Client is NOT registered.\n");
3590 __WFD_CLIENT_FUNC_END__;
3591 return WIFI_DIRECT_ERROR_STRANGE_CLIENT;
3594 wifi_direct_client_request_s req;
3595 wifi_direct_client_response_s rsp;
3597 int ret = WIFI_DIRECT_ERROR_NONE;
3599 memset(&req, 0, sizeof(wifi_direct_client_request_s));
3600 memset(&rsp, 0, sizeof(wifi_direct_client_response_s));
3602 req.cmd = WIFI_DIRECT_CMD_GET_LINK_STATUS;
3603 req.client_id = client_info->client_id;
3606 __wfd_client_send_request(client_info->sync_sockfd, &req,
3607 sizeof(wifi_direct_client_request_s));
3608 if (ret != WIFI_DIRECT_ERROR_NONE)
3610 WFD_CLIENT_LOG(WFD_LOG_ERROR,
3611 "Error!!! writing to socket, Errno = %s\n",
3613 WFD_CLIENT_LOG(WFD_LOG_ERROR, "Error!!! [%s]\n",
3614 __wfd_print_error(ret));
3615 client_info->sync_sockfd = -1;
3616 __wfd_reset_control();
3617 __WFD_CLIENT_FUNC_END__;
3618 return WIFI_DIRECT_ERROR_COMMUNICATION_FAILED;
3622 __wfd_client_read_socket(client_info->sync_sockfd, (char *) &rsp,
3623 sizeof(wifi_direct_client_response_s))) <= 0)
3625 WFD_CLIENT_LOG(WFD_LOG_ERROR,
3626 "Error!!! reading socket, status = %d errno = %s\n", ret,
3628 client_info->sync_sockfd = -1;
3629 __wfd_reset_control();
3630 __WFD_CLIENT_FUNC_END__;
3631 return WIFI_DIRECT_ERROR_COMMUNICATION_FAILED;
3635 if (rsp.cmd == WIFI_DIRECT_CMD_GET_LINK_STATUS)
3637 if (rsp.result != WIFI_DIRECT_ERROR_NONE)
3639 WFD_CLIENT_LOG(WFD_LOG_LOW,
3640 "Error!!! Result received = %d %s\n", rsp.result,
3641 __wfd_print_error(rsp.result));
3642 __WFD_CLIENT_FUNC_END__;
3647 WFD_CLIENT_LOG(WFD_LOG_LOW, "Link Status = %d \n",
3649 *state = (wifi_direct_state_e) rsp.param1;
3654 WFD_CLIENT_LOG(WFD_LOG_ERROR, "Error!!! Invalid resp cmd = %d\n",
3656 return WIFI_DIRECT_ERROR_OPERATION_FAILED;
3660 __WFD_CLIENT_FUNC_END__;
3662 return WIFI_DIRECT_ERROR_NONE;
3666 int wifi_direct_get_config_data(wifi_direct_config_data_s ** config)
3668 wifi_direct_client_info_s *client_info = __wfd_get_control();
3670 __WFD_CLIENT_FUNC_START__;
3672 if ((client_info->is_registered == false)
3673 || (client_info->client_id == WFD_INVALID_ID))
3675 WFD_CLIENT_LOG(WFD_LOG_ERROR, "Client is NOT registered.\n");
3676 __WFD_CLIENT_FUNC_END__;
3677 return WIFI_DIRECT_ERROR_STRANGE_CLIENT;
3682 WFD_CLIENT_LOG(WFD_LOG_ERROR, "NULL Param [config]!\n");
3683 __WFD_CLIENT_FUNC_END__;
3684 return WIFI_DIRECT_ERROR_INVALID_PARAMETER;
3687 wifi_direct_client_request_s req;
3688 wifi_direct_client_response_s rsp;
3689 wfd_config_data_s ls_config;
3691 int status = WIFI_DIRECT_ERROR_NONE;
3693 memset(&req, 0, sizeof(wifi_direct_client_request_s));
3694 memset(&rsp, 0, sizeof(wifi_direct_client_response_s));
3696 req.cmd = WIFI_DIRECT_CMD_GET_CONFIG;
3697 req.client_id = client_info->client_id;
3700 __wfd_client_send_request(client_info->sync_sockfd, &req,
3701 sizeof(wifi_direct_client_request_s));
3702 if (status != WIFI_DIRECT_ERROR_NONE)
3704 WFD_CLIENT_LOG(WFD_LOG_ERROR,
3705 "Error!!! writing to socket, Errno = %s\n",
3707 WFD_CLIENT_LOG(WFD_LOG_ERROR, "Error!!! [%s]\n",
3708 __wfd_print_error(status));
3709 client_info->sync_sockfd = -1;
3710 __wfd_reset_control();
3711 __WFD_CLIENT_FUNC_END__;
3712 return WIFI_DIRECT_ERROR_COMMUNICATION_FAILED;
3716 __wfd_client_read_socket(client_info->sync_sockfd, (char *) &rsp,
3717 sizeof(wifi_direct_client_response_s))) <= 0)
3719 WFD_CLIENT_LOG(WFD_LOG_ERROR,
3720 "Error!!! reading socket, status = %d errno = %s\n",
3721 status, strerror(errno));
3722 client_info->sync_sockfd = -1;
3723 __wfd_reset_control();
3724 __WFD_CLIENT_FUNC_END__;
3725 return WIFI_DIRECT_ERROR_COMMUNICATION_FAILED;
3729 if (rsp.cmd == WIFI_DIRECT_CMD_GET_CONFIG)
3731 if (rsp.result != WIFI_DIRECT_ERROR_NONE)
3733 WFD_CLIENT_LOG(WFD_LOG_ERROR,
3734 "Error!!! Result received = %d \n", rsp.result);
3735 WFD_CLIENT_LOG(WFD_LOG_ERROR, "Error!!! [%s]\n",
3736 __wfd_print_error(rsp.result));
3737 __WFD_CLIENT_FUNC_END__;
3744 WFD_CLIENT_LOG(WFD_LOG_LOW, "Link status = %d \n",
3748 __wfd_client_read_more_data(client_info->sync_sockfd,
3750 sizeof(wfd_config_data_s));
3751 if (status != WIFI_DIRECT_ERROR_NONE)
3753 WFD_CLIENT_LOG(WFD_LOG_ERROR, "socket read error.\n");
3754 return WIFI_DIRECT_ERROR_OPERATION_FAILED;
3757 __wfd_client_print_config_data(&ls_config);
3759 wifi_direct_config_data_s *temp_config;
3761 (wifi_direct_config_data_s *) calloc(1,
3763 (wifi_direct_config_data_s));
3765 temp_config->ssid = strdup(ls_config.ssid);
3766 temp_config->channel = ls_config.channel;
3767 temp_config->wps_config = ls_config.wps_config;
3768 temp_config->max_clients = ls_config.max_clients;
3769 temp_config->hide_SSID = ls_config.hide_SSID;
3770 temp_config->group_owner_intent = ls_config.group_owner_intent;
3771 temp_config->want_persistent_group =
3772 ls_config.want_persistent_group;
3773 temp_config->auto_connection = ls_config.auto_connection;
3774 temp_config->primary_dev_type = ls_config.primary_dev_type;
3775 temp_config->secondary_dev_type = ls_config.secondary_dev_type;
3777 *config = temp_config;
3779 WFD_CLIENT_LOG(WFD_LOG_LOW,
3780 "wifi_direct_get_config_data() SUCCESS\n");
3785 WFD_CLIENT_LOG(WFD_LOG_ERROR, "Error!!! Invalid resp cmd = %d\n",
3787 return WIFI_DIRECT_ERROR_OPERATION_FAILED;
3791 __WFD_CLIENT_FUNC_END__;
3793 return WIFI_DIRECT_ERROR_NONE;
3798 int wifi_direct_set_config_data(wifi_direct_config_data_s * config)
3800 wifi_direct_client_info_s *client_info = __wfd_get_control();
3802 __WFD_CLIENT_FUNC_START__;
3804 if ((client_info->is_registered == false)
3805 || (client_info->client_id == WFD_INVALID_ID))
3807 WFD_CLIENT_LOG(WFD_LOG_ERROR, "Client is NOT registered.\n");
3808 __WFD_CLIENT_FUNC_END__;
3809 return WIFI_DIRECT_ERROR_STRANGE_CLIENT;
3814 WFD_CLIENT_LOG(WFD_LOG_ERROR, "NULL Param [config]!\n");
3815 __WFD_CLIENT_FUNC_END__;
3816 return WIFI_DIRECT_ERROR_INVALID_PARAMETER;
3819 wifi_direct_client_request_s req;
3820 wifi_direct_client_response_s rsp;
3821 wfd_config_data_s ls_config;
3823 int status = WIFI_DIRECT_ERROR_NONE;
3825 memset(&req, 0, sizeof(wifi_direct_client_request_s));
3826 memset(&rsp, 0, sizeof(wifi_direct_client_response_s));
3828 req.cmd = WIFI_DIRECT_CMD_SET_CONFIG;
3829 req.client_id = client_info->client_id;
3832 __wfd_client_send_request(client_info->sync_sockfd, &req,
3833 sizeof(wifi_direct_client_request_s));
3834 if (status != WIFI_DIRECT_ERROR_NONE)
3836 WFD_CLIENT_LOG(WFD_LOG_ERROR,
3837 "Error!!! writing to socket, Errno = %s\n",
3839 WFD_CLIENT_LOG(WFD_LOG_ERROR, "Error!!! [%s]\n",
3840 __wfd_print_error(status));
3841 client_info->sync_sockfd = -1;
3842 __wfd_reset_control();
3843 __WFD_CLIENT_FUNC_END__;
3844 return WIFI_DIRECT_ERROR_COMMUNICATION_FAILED;
3847 WFD_CLIENT_LOG(WFD_LOG_LOW, "writing msg hdr is success!\n");
3850 strncpy(ls_config.ssid, config->ssid, strlen(config->ssid));
3851 ls_config.channel = config->channel;
3852 ls_config.wps_config = config->wps_config;
3853 ls_config.max_clients = config->max_clients;
3854 ls_config.hide_SSID = config->hide_SSID;
3855 ls_config.group_owner_intent = config->group_owner_intent;
3856 ls_config.want_persistent_group = config->want_persistent_group;
3857 ls_config.auto_connection = config->auto_connection;
3858 ls_config.primary_dev_type = config->primary_dev_type;
3859 ls_config.secondary_dev_type = config->secondary_dev_type;
3861 __wfd_client_print_config_data(&ls_config);
3864 __wfd_client_send_request(client_info->sync_sockfd, &ls_config,
3865 sizeof(wfd_config_data_s));
3866 if (status != WIFI_DIRECT_ERROR_NONE)
3868 WFD_CLIENT_LOG(WFD_LOG_ERROR,
3869 "Error!!! writing to socket, Errno = %s\n",
3871 WFD_CLIENT_LOG(WFD_LOG_ERROR, "Error!!! [%s]\n",
3872 __wfd_print_error(status));
3873 client_info->sync_sockfd = -1;
3874 __wfd_reset_control();
3875 __WFD_CLIENT_FUNC_END__;
3876 return WIFI_DIRECT_ERROR_COMMUNICATION_FAILED;
3880 __wfd_client_read_socket(client_info->sync_sockfd, (char *) &rsp,
3881 sizeof(wifi_direct_client_response_s))) <= 0)
3883 WFD_CLIENT_LOG(WFD_LOG_ERROR,
3884 "Error!!! reading socket, status = %d errno = %s\n",
3885 status, strerror(errno));
3886 client_info->sync_sockfd = -1;
3887 __wfd_reset_control();
3888 __WFD_CLIENT_FUNC_END__;
3889 return WIFI_DIRECT_ERROR_COMMUNICATION_FAILED;
3893 if (rsp.cmd == WIFI_DIRECT_CMD_SET_CONFIG)
3895 if (rsp.result != WIFI_DIRECT_ERROR_NONE)
3897 WFD_CLIENT_LOG(WFD_LOG_LOW, "Error!!! Result received = %d \n",
3899 WFD_CLIENT_LOG(WFD_LOG_LOW, "Error!!! [%s]\n",
3900 __wfd_print_error(rsp.result));
3901 __WFD_CLIENT_FUNC_END__;
3907 WFD_CLIENT_LOG(WFD_LOG_ERROR, "Error!!! Invalid resp cmd = %d\n",
3909 return WIFI_DIRECT_ERROR_OPERATION_FAILED;
3913 __WFD_CLIENT_FUNC_END__;
3915 return WIFI_DIRECT_ERROR_NONE;
3919 int wifi_direct_set_p2poem_loglevel(int increase_log_level)
3921 wifi_direct_client_info_s *client_info = __wfd_get_control();
3923 __WFD_CLIENT_FUNC_START__;
3925 if ((client_info->is_registered == false)
3926 || (client_info->client_id == WFD_INVALID_ID))
3928 WFD_CLIENT_LOG(WFD_LOG_ERROR, "Client is NOT registered.\n");
3929 __WFD_CLIENT_FUNC_END__;
3930 return WIFI_DIRECT_ERROR_STRANGE_CLIENT;
3933 wifi_direct_client_request_s req;
3934 wifi_direct_client_response_s rsp;
3936 int ret = WIFI_DIRECT_ERROR_NONE;
3938 memset(&req, 0, sizeof(wifi_direct_client_request_s));
3939 memset(&rsp, 0, sizeof(wifi_direct_client_response_s));
3941 req.cmd = WIFI_DIRECT_CMD_SET_OEM_LOGLEVEL;
3942 req.client_id = client_info->client_id;
3943 if (increase_log_level == 0)
3944 req.data.listen_only = false;
3946 req.data.listen_only = true;
3949 __wfd_client_send_request(client_info->sync_sockfd, &req,
3950 sizeof(wifi_direct_client_request_s));
3951 if (ret != WIFI_DIRECT_ERROR_NONE)
3953 WFD_CLIENT_LOG(WFD_LOG_ERROR,
3954 "Error!!! writing to socket, Errno = %s\n",
3956 WFD_CLIENT_LOG(WFD_LOG_ERROR, "Error!!! [%s]\n",
3957 __wfd_print_error(ret));
3958 client_info->sync_sockfd = -1;
3959 __wfd_reset_control();
3960 __WFD_CLIENT_FUNC_END__;
3961 return WIFI_DIRECT_ERROR_COMMUNICATION_FAILED;
3965 __wfd_client_read_socket(client_info->sync_sockfd, (char *) &rsp,
3966 sizeof(wifi_direct_client_response_s))) <= 0)
3968 WFD_CLIENT_LOG(WFD_LOG_ERROR,
3969 "Error!!! reading socket, status = %d errno = %s\n", ret,
3971 client_info->sync_sockfd = -1;
3972 __wfd_reset_control();
3973 __WFD_CLIENT_FUNC_END__;
3974 return WIFI_DIRECT_ERROR_COMMUNICATION_FAILED;
3978 if (rsp.cmd == WIFI_DIRECT_CMD_SET_OEM_LOGLEVEL)
3980 if (rsp.result != WIFI_DIRECT_ERROR_NONE)
3982 WFD_CLIENT_LOG(WFD_LOG_LOW, "Error!!! Result received = %d \n",
3984 WFD_CLIENT_LOG(WFD_LOG_LOW, "Error!!! [%s]\n",
3985 __wfd_print_error(rsp.result));
3986 __WFD_CLIENT_FUNC_END__;
3992 WFD_CLIENT_LOG(WFD_LOG_ERROR, "Error!!! Invalid resp cmd = %d\n",
3994 return WIFI_DIRECT_ERROR_OPERATION_FAILED;
3998 __WFD_CLIENT_FUNC_END__;
4000 return WIFI_DIRECT_ERROR_NONE;