4 * Copyright 2012 Samsung Electronics Co., Ltd
6 * Licensed under the Flora License, Version 1.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
10 * http://www.tizenopensource.org/license
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
21 * This file implements wifi direct application client functions.
23 * @file wfd-app-client.c
24 * @author Sungsik Jang (sungsik.jang@samsung.com)
31 #include "wifi-direct.h"
33 #include "wfd-app-util.h"
37 bool _wfd_connected_peer_cb(wifi_direct_connected_peer_info_s *peer, void *user_data)
39 __WFD_APP_FUNC_ENTER__;
41 wfd_appdata_t *ad = (wfd_appdata_t *) user_data;
42 if (NULL == ad || NULL == peer || NULL == peer->ssid || NULL == peer->mac_address) {
43 WFD_APP_LOG(WFD_APP_LOG_LOW, "NULL parameters.\n");
47 int peer_cnt = ad->raw_connected_peer_cnt;
48 WFD_APP_LOG(WFD_APP_LOG_LOW, "%dth connected peer. [%s]\n", peer_cnt, peer->ssid);
50 strncpy(ad->raw_connected_peers[peer_cnt].ssid, peer->ssid, sizeof(ad->raw_connected_peers[peer_cnt].ssid));
51 strncpy(ad->raw_connected_peers[peer_cnt].mac_address, peer->mac_address, WFD_MAC_ADDRESS_SIZE);
52 WFD_APP_LOG(WFD_APP_LOG_LOW, "\tSSID: [%s]\n", ad->raw_connected_peers[peer_cnt].ssid);
53 ad->raw_connected_peer_cnt++;
56 free(peer->mac_address);
59 __WFD_APP_FUNC_EXIT__;
63 int _wfd_app_get_connected_peers(void *user_data)
65 __WFD_APP_FUNC_ENTER__;
67 wfd_appdata_t *ad = (wfd_appdata_t *) user_data;
69 WFD_APP_LOG(WFD_APP_LOG_LOW, "NULL parameters.\n");
75 ad->raw_connected_peer_cnt = 0;
76 res = wifi_direct_foreach_connected_peers(_wfd_connected_peer_cb, (void *)ad);
77 if (res != WIFI_DIRECT_ERROR_NONE) {
78 ad->raw_connected_peer_cnt = 0;
79 WFD_APP_LOG(WFD_APP_LOG_LOW, "Get connected peer failed: %d\n", res);
82 __WFD_APP_FUNC_EXIT__;
86 void _del_wfd_notification()
88 __WFD_APP_FUNC_ENTER__;
90 /* delete the notification */
91 notification_error_e noti_err = NOTIFICATION_ERROR_NONE;
92 noti_err = notification_delete_all_by_type(NULL, NOTIFICATION_TYPE_NOTI);
93 if(noti_err != NOTIFICATION_ERROR_NONE) {
94 WFD_APP_LOG(WFD_APP_LOG_LOW, "Fail to notification_delete_all_by_type.(%d)\n", noti_err);
98 __WFD_APP_FUNC_EXIT__;
102 void _add_wfd_actived_notification(void *user_data)
104 __WFD_APP_FUNC_ENTER__;
106 wfd_appdata_t *ad = (wfd_appdata_t *) user_data;
107 if (NULL == ad || NULL == ad->noti) {
108 WFD_APP_LOG(WFD_APP_LOG_LOW, "NULL parameters.\n");
112 notification_error_e noti_err = NOTIFICATION_ERROR_NONE;
115 noti_err = notification_set_image(ad->noti, NOTIFICATION_IMAGE_TYPE_ICON, RESDIR"/images/A09_notification_icon.png");
116 if (noti_err != NOTIFICATION_ERROR_NONE) {
117 WFD_APP_LOG(WFD_APP_LOG_LOW, "Fail to notification_set_image. (%d)\n", noti_err);
121 /* set the title and content */
122 noti_err = notification_set_text(ad->noti, NOTIFICATION_TEXT_TYPE_TITLE,
123 "Wi-Fi Direct activated", NULL, NOTIFICATION_VARIABLE_TYPE_NONE);
124 if (noti_err != NOTIFICATION_ERROR_NONE) {
125 WFD_APP_LOG(WFD_APP_LOG_LOW, "Fail to notification_set_text. (%d)\n", noti_err);
129 noti_err = notification_set_text(ad->noti, NOTIFICATION_TEXT_TYPE_CONTENT,
130 "Tap to change settings", NULL, NOTIFICATION_VARIABLE_TYPE_NONE);
131 if (noti_err != NOTIFICATION_ERROR_NONE) {
132 WFD_APP_LOG(WFD_APP_LOG_LOW, "Fail to notification_set_text. (%d)\n", noti_err);
138 appsvc_set_pkgname(b, PACKAGE);
139 appsvc_add_data(b, NOTIFICATION_BUNDLE_PARAM, NOTIFICATION_BUNDLE_VALUE);
141 int res = NOTIFICATION_ERROR_NONE;
142 res = notification_set_execute_option(ad->noti, NOTIFICATION_EXECUTE_TYPE_SINGLE_LAUNCH, /*Button Text*/NULL, NULL, b);
143 if (res != NOTIFICATION_ERROR_NONE) {
144 WFD_APP_LOG(WFD_APP_LOG_LOW,"Failed to notification_set_execute_option. [%d]", res);
150 /* set display application list */
151 noti_err = notification_set_display_applist(ad->noti, NOTIFICATION_DISPLAY_APP_NOTIFICATION_TRAY);
152 if(noti_err != NOTIFICATION_ERROR_NONE) {
153 WFD_APP_LOG(WFD_APP_LOG_LOW, "Fail to notification_set_display_applist : %d\n", noti_err);
157 /* notify the quick panel */
158 if (0 == ad->is_insert) {
159 noti_err = notification_insert(ad->noti, NULL);
160 if (noti_err != NOTIFICATION_ERROR_NONE) {
161 WFD_APP_LOG(WFD_APP_LOG_LOW, "Fail to notification_insert.(%d)\n", noti_err);
167 noti_err = notification_update(ad->noti);
168 if (noti_err != NOTIFICATION_ERROR_NONE) {
169 WFD_APP_LOG(WFD_APP_LOG_LOW, "Fail to notification_update. (%d)\n", noti_err);
174 __WFD_APP_FUNC_EXIT__;
178 void _add_wfd_peers_connected_notification(void *user_data)
180 __WFD_APP_FUNC_ENTER__;
182 wfd_appdata_t *ad = (wfd_appdata_t *) user_data;
183 if (NULL == ad || NULL == ad->noti) {
184 WFD_APP_LOG(WFD_APP_LOG_LOW, "NULL parameters.\n");
188 char msg[WFD_MAX_SIZE] = {0};
189 notification_error_e noti_err = NOTIFICATION_ERROR_NONE;
191 /* delete all notifications */
192 _del_wfd_notification();
195 noti_err = notification_set_image(ad->noti, NOTIFICATION_IMAGE_TYPE_ICON, RESDIR"/images/A09_notification_icon.png");
196 if (noti_err != NOTIFICATION_ERROR_NONE) {
197 WFD_APP_LOG(WFD_APP_LOG_LOW, "Fail to notification_set_image. (%d)\n", noti_err);
201 /* set the title and content */
202 _wfd_app_get_connected_peers(ad);
203 snprintf(msg, WFD_MAX_SIZE, "Connected with %d devices via Wi-Fi Direct", ad->raw_connected_peer_cnt);
204 noti_err = notification_set_text(ad->noti, NOTIFICATION_TEXT_TYPE_TITLE, msg, NULL, NOTIFICATION_VARIABLE_TYPE_NONE);
205 if (noti_err != NOTIFICATION_ERROR_NONE) {
206 WFD_APP_LOG(WFD_APP_LOG_LOW, "Fail to notification_set_text. (%d)\n", noti_err);
210 noti_err = notification_set_text(ad->noti, NOTIFICATION_TEXT_TYPE_CONTENT,
211 "Tap to change settings", NULL, NOTIFICATION_VARIABLE_TYPE_NONE);
212 if (noti_err != NOTIFICATION_ERROR_NONE) {
213 WFD_APP_LOG(WFD_APP_LOG_LOW, "Fail to notification_set_text. (%d)\n", noti_err);
219 appsvc_set_pkgname(b, PACKAGE);
220 appsvc_add_data(b, NOTIFICATION_BUNDLE_PARAM, NOTIFICATION_BUNDLE_VALUE);
222 int res = NOTIFICATION_ERROR_NONE;
223 res = notification_set_execute_option(ad->noti, NOTIFICATION_EXECUTE_TYPE_SINGLE_LAUNCH, /*Button Text*/NULL, NULL, b);
224 if (res != NOTIFICATION_ERROR_NONE) {
225 WFD_APP_LOG(WFD_APP_LOG_LOW,"Failed to notification_set_execute_option. [%d]", res);
231 /* set display application list */
232 noti_err = notification_set_display_applist(ad->noti, NOTIFICATION_DISPLAY_APP_NOTIFICATION_TRAY);
233 if(noti_err != NOTIFICATION_ERROR_NONE) {
234 WFD_APP_LOG(WFD_APP_LOG_LOW, "Fail to notification_set_display_applist : %d\n", noti_err);
238 /* notify the quick panel */
239 noti_err = notification_insert(ad->noti, NULL);
240 if (noti_err != NOTIFICATION_ERROR_NONE) {
241 WFD_APP_LOG(WFD_APP_LOG_LOW, "Fail to notification_insert.(%d)\n", noti_err);
245 __WFD_APP_FUNC_EXIT__;
248 void _add_wfd_turn_off_notification(void *user_data)
250 __WFD_APP_FUNC_ENTER__;
252 wfd_appdata_t *ad = (wfd_appdata_t *) user_data;
253 if (NULL == ad || NULL == ad->noti) {
254 WFD_APP_LOG(WFD_APP_LOG_LOW, "NULL parameters.\n");
258 notification_error_e noti_err = NOTIFICATION_ERROR_NONE;
260 /* delete all notifications */
261 _del_wfd_notification();
264 noti_err = notification_set_image(ad->noti, NOTIFICATION_IMAGE_TYPE_ICON, RESDIR"/images/A09_notification_icon.png");
265 if (noti_err != NOTIFICATION_ERROR_NONE) {
266 WFD_APP_LOG(WFD_APP_LOG_LOW, "Fail to notification_set_image. (%d)\n", noti_err);
270 /* set the title and content */
271 noti_err = notification_set_text(ad->noti, NOTIFICATION_TEXT_TYPE_TITLE,
272 "Turn off Wi-Fi direct after using", NULL, NOTIFICATION_VARIABLE_TYPE_NONE);
273 if (noti_err != NOTIFICATION_ERROR_NONE) {
274 WFD_APP_LOG(WFD_APP_LOG_LOW, "Fail to notification_set_text. (%d)\n", noti_err);
278 noti_err = notification_set_text(ad->noti, NOTIFICATION_TEXT_TYPE_CONTENT,
279 "To save battery turn off Wi-Fi direct after using", NULL, NOTIFICATION_VARIABLE_TYPE_NONE);
280 if (noti_err != NOTIFICATION_ERROR_NONE) {
281 WFD_APP_LOG(WFD_APP_LOG_LOW, "Fail to notification_set_text. (%d)\n", noti_err);
287 appsvc_set_pkgname(b, PACKAGE);
288 appsvc_add_data(b, NOTIFICATION_BUNDLE_PARAM, NOTIFICATION_BUNDLE_VALUE);
290 int res = NOTIFICATION_ERROR_NONE;
291 res = notification_set_execute_option(ad->noti, NOTIFICATION_EXECUTE_TYPE_SINGLE_LAUNCH, /*Button Text*/NULL, NULL, b);
292 if (res != NOTIFICATION_ERROR_NONE) {
293 WFD_APP_LOG(WFD_APP_LOG_LOW,"Failed to notification_set_execute_option. [%d]", res);
299 /* set display application list */
300 noti_err = notification_set_display_applist(ad->noti, NOTIFICATION_DISPLAY_APP_NOTIFICATION_TRAY);
301 if(noti_err != NOTIFICATION_ERROR_NONE) {
302 WFD_APP_LOG(WFD_APP_LOG_LOW, "Fail to notification_set_display_applist : %d\n", noti_err);
306 /* notify the quick panel */
307 noti_err = notification_insert(ad->noti, NULL);
308 if (noti_err != NOTIFICATION_ERROR_NONE) {
309 WFD_APP_LOG(WFD_APP_LOG_LOW, "Fail to notification_insert.(%d)\n", noti_err);
313 __WFD_APP_FUNC_EXIT__;
316 static Eina_Bool _wfd_automatic_deactivated_for_connection_cb(void *user_data)
319 unsigned int transmit_packet = 0;
320 int wfd_transfer_state = 0;
321 wfd_appdata_t *ad = (wfd_appdata_t*) user_data;
324 WFD_APP_LOG(WFD_APP_LOG_LOW, "NULL parameters.\n");
325 return ECORE_CALLBACK_CANCEL;
328 /* check the timeout, if not timeout, keep the cb */
329 interval = time(NULL) - ad->last_wfd_transmit_time;
330 if (interval < NO_ACTION_TIME_OUT) {
331 return ECORE_CALLBACK_RENEW;
334 /* get transfer state */
335 if (vconf_get_int(VCONFKEY_WIFI_DIRECT_TRANSFER_STATE, &wfd_transfer_state) < 0) {
336 WFD_APP_LOG(WFD_APP_LOG_LOW, "Error reading vconf (%s)\n",
337 VCONFKEY_WIFI_DIRECT_TRANSFER_STATE);
338 return ECORE_CALLBACK_CANCEL;
342 if (wfd_transfer_state > VCONFKEY_WIFI_DIRECT_TRANSFER_START) {
343 WFD_APP_LOG(WFD_APP_LOG_LOW, "No RX/TX packet, turn off WFD automatically.\n");
344 _add_wfd_turn_off_notification(ad);
346 WFD_APP_LOG(WFD_APP_LOG_LOW, "Has RX/TX packet, restart.\n");
347 ad->last_wfd_transmit_time = time(NULL);
348 return ECORE_CALLBACK_RENEW;
351 return ECORE_CALLBACK_CANCEL;
354 /* automatic deactivated wfd callback*/
355 static Eina_Bool _wfd_automatic_deactivated_for_no_connection_cb(void *user_data)
359 wfd_appdata_t *ad = (wfd_appdata_t*) user_data;
362 WFD_APP_LOG(WFD_APP_LOG_LOW, "NULL parameters.\n");
363 return ECORE_CALLBACK_CANCEL;
366 /* check the action, if action is exist, keep the cb */
367 res = wifi_direct_get_state(&ad->wfd_status);
368 if (res != WIFI_DIRECT_ERROR_NONE) {
369 WFD_APP_LOG(WFD_APP_LOG_LOW, "Failed to get link status. [%d]\n", res);
370 return ECORE_CALLBACK_CANCEL;
373 if (ad->last_wfd_status != ad->wfd_status) {
374 WFD_APP_LOG(WFD_APP_LOG_LOW, "Action is exist, last status: %d\n",
375 ad->last_wfd_status);
376 ad->last_wfd_status = ad->wfd_status;
377 ad->last_wfd_time = time(NULL);
378 return ECORE_CALLBACK_RENEW;
381 /* check the timeout, if not timeout, keep the cb */
382 interval = time(NULL) - ad->last_wfd_time;
383 if (interval < NO_ACTION_TIME_OUT) {
384 return ECORE_CALLBACK_RENEW;
387 /* turn off the Wi-Fi Direct */
388 wifi_direct_get_state(&ad->wfd_status);
389 if (ad->wfd_status < WIFI_DIRECT_STATE_ACTIVATING) {
390 WFD_APP_LOG(WFD_APP_LOG_LOW, "Wi-Fi Direct is already deactivated\n");
392 wfd_prepare_popup(WFD_POP_AUTOMATIC_TURN_OFF, NULL);
395 return ECORE_CALLBACK_CANCEL;
398 void _cb_activation(int error_code, wifi_direct_device_state_e device_state,
401 __WFD_APP_FUNC_ENTER__;
403 wfd_appdata_t *ad = (wfd_appdata_t *) user_data;
405 switch (device_state)
407 case WIFI_DIRECT_DEVICE_STATE_ACTIVATED:
408 WFD_APP_LOG(WFD_APP_LOG_LOW,
409 "event ------------------ WIFI_DIRECT_DEVICE_STATE_ACTIVATED\n");
412 case WIFI_DIRECT_DEVICE_STATE_DEACTIVATED:
413 WFD_APP_LOG(WFD_APP_LOG_LOW,
414 "event ------------------ WIFI_DIRECT_DEVICE_STATE_DEACTIVATED\n");
415 WFD_APP_LOG(WFD_APP_LOG_LOW,
416 "Termination process of wifi-direct popup begins...\n");
418 /* when deactivated, stop the timer */
419 if (ad->transmit_timer) {
420 ecore_timer_del(ad->transmit_timer);
421 ad->transmit_timer = NULL;
424 if (ad->monitor_timer) {
425 ecore_timer_del(ad->monitor_timer);
426 ad->monitor_timer = NULL;
436 __WFD_APP_FUNC_EXIT__;
441 static wfd_device_info_t *_wfd_app_find_peer_by_mac_address(void *data,
442 const char *mac_address)
444 __WFD_APP_FUNC_ENTER__;
446 wfd_appdata_t *ad = (wfd_appdata_t *) data;
452 WFD_APP_LOG(WFD_APP_LOG_LOW, "Incorrect parameter(NULL)\n");
456 WFD_APP_LOG(WFD_APP_LOG_LOW, "find peer by MAC [%s] \n", mac_address);
458 for (i = 0; i < ad->discovered_peer_count; i++)
460 WFD_APP_LOG(WFD_APP_LOG_LOW, "check %dth peer\n", i);
462 if (!strncmp(mac_address, (const char *) ad->discovered_peers[i].mac_address, 18))
464 WFD_APP_LOG(WFD_APP_LOG_LOW, "found peer. [%d]\n", i);
465 __WFD_APP_FUNC_EXIT__;
466 return &ad->discovered_peers[i];
470 __WFD_APP_FUNC_EXIT__;
476 bool _wfd_app_discoverd_peer_cb(wifi_direct_discovered_peer_info_s * peer,
479 __WFD_APP_FUNC_ENTER__;
481 wfd_appdata_t *ad = (wfd_appdata_t *) user_data;
483 if (NULL != peer->ssid)
485 WFD_APP_LOG(WFD_APP_LOG_LOW, "discovered peer ssid[%s]\n", peer->ssid);
486 strncpy(ad->discovered_peers[ad->discovered_peer_count].ssid, peer->ssid, 32);
490 WFD_APP_LOG(WFD_APP_LOG_LOW, "peer's ssid is NULL\n");
493 if (NULL != peer->mac_address)
495 WFD_APP_LOG(WFD_APP_LOG_LOW, "discovered peer mac[%s]\n", peer->mac_address);
496 strncpy(ad->discovered_peers[ad->discovered_peer_count].mac_address, peer->mac_address, 18);
500 WFD_APP_LOG(WFD_APP_LOG_LOW, "peer's mac is NULL\n");
503 ad->discovered_peer_count++;
505 __WFD_APP_FUNC_EXIT__;
512 void _cb_discover(int error_code, wifi_direct_discovery_state_e discovery_state,
515 __WFD_APP_FUNC_ENTER__;
517 wfd_appdata_t *ad = (wfd_appdata_t *) user_data;
520 switch (discovery_state)
522 case WIFI_DIRECT_DISCOVERY_STARTED:
524 WFD_APP_LOG(WFD_APP_LOG_LOW, "event ------------------ WIFI_DIRECT_DISCOVERY_STARTED\n");
528 case WIFI_DIRECT_ONLY_LISTEN_STARTED:
530 WFD_APP_LOG(WFD_APP_LOG_LOW, "event ------------------ WIFI_DIRECT_ONLY_LISTEN_STARTED\n");
534 case WIFI_DIRECT_DISCOVERY_FINISHED:
536 WFD_APP_LOG(WFD_APP_LOG_LOW, "event ------------------ WIFI_DIRECT_DISCOVERY_FINISHED\n");
540 case WIFI_DIRECT_DISCOVERY_FOUND:
542 WFD_APP_LOG(WFD_APP_LOG_LOW, "event ------------------ WIFI_DIRECT_DISCOVERY_FOUND\n");
544 if (NULL != ad->discovered_peers)
545 free(ad->discovered_peers);
547 ad->discovered_peers = calloc(10, sizeof(wfd_device_info_t));
548 ad->discovered_peer_count = 0;
550 ret = wifi_direct_foreach_discovered_peers(_wfd_app_discoverd_peer_cb, (void *) ad);
551 if (ret != WIFI_DIRECT_ERROR_NONE)
552 WFD_APP_LOG(WFD_APP_LOG_LOW, "get discovery result failed: %d\n", ret);
560 __WFD_APP_FUNC_EXIT__;
564 void _cb_connection(int error_code,
565 wifi_direct_connection_state_e connection_state,
566 const char *mac_address, void *user_data)
568 __WFD_APP_FUNC_ENTER__;
570 wfd_appdata_t *ad = (wfd_appdata_t *) user_data;
572 char msg[WFD_POP_STR_MAX_LEN] = {0};
573 wfd_device_info_t *peer_info = NULL;
575 /* find the peer's name by the mac address */
576 if (NULL == mac_address) {
577 WFD_APP_LOG(WFD_APP_LOG_ERROR, "ERROR : mac address is NULL !!\n");
581 strncpy(ad->peer_mac, mac_address, strlen(mac_address));
583 peer_info = _wfd_app_find_peer_by_mac_address(ad, mac_address);
585 if (NULL == peer_info)
587 WFD_APP_LOG(WFD_APP_LOG_LOW, "peer_info is NULL !!\n");
589 else if (NULL == peer_info->ssid)
591 WFD_APP_LOG(WFD_APP_LOG_LOW, "SSID from connection is NULL !!\n");
595 WFD_APP_LOG(WFD_APP_LOG_LOW, "SSID from connection is %s.\n", peer_info->ssid);
596 strncpy(ad->peer_name, peer_info->ssid, strlen(peer_info->ssid));
599 if (ad->peer_name == NULL || strlen(ad->peer_name) == 0) {
600 strncpy(ad->peer_name, ad->peer_mac, strlen(ad->peer_mac));
603 switch (connection_state)
605 case WIFI_DIRECT_CONNECTION_RSP:
607 WFD_APP_LOG(WFD_APP_LOG_LOW,
608 "event ------------------ WIFI_DIRECT_CONNECTION_RSP\n");
611 if (error_code == WIFI_DIRECT_ERROR_NONE)
613 WFD_APP_LOG(WFD_APP_LOG_LOW, "Link Complete!\n");
615 /* add connected notification */
616 _add_wfd_peers_connected_notification(ad);
618 /* tickernoti popup */
619 snprintf(msg, WFD_POP_STR_MAX_LEN, _("IDS_WFD_POP_CONNECTED"), ad->peer_name);
620 wfd_tickernoti_popup(msg);
624 if (error_code == WIFI_DIRECT_ERROR_CONNECTION_TIME_OUT)
625 WFD_APP_LOG(WFD_APP_LOG_LOW,
626 "Error Code - WIFI_DIRECT_ERROR_CONNECTION_TIME_OUT\n");
627 else if (error_code == WIFI_DIRECT_ERROR_AUTH_FAILED)
628 WFD_APP_LOG(WFD_APP_LOG_LOW,
629 "Error Code - WIFI_DIRECT_ERROR_AUTH_FAILED\n");
630 else if (error_code == WIFI_DIRECT_ERROR_CONNECTION_FAILED)
631 WFD_APP_LOG(WFD_APP_LOG_LOW,
632 "Error Code - WIFI_DIRECT_ERROR_CONNECTION_FAILED\n");
634 result = wifi_direct_start_discovery(FALSE, 0);
635 WFD_APP_LOG(WFD_APP_LOG_LOW,
636 "wifi_direct_start_discovery() result=[%d]\n",
642 case WIFI_DIRECT_CONNECTION_WPS_REQ:
644 wifi_direct_config_data_s *config = NULL;
646 memcpy(ad->peer_mac, mac_address, sizeof(ad->peer_mac));
648 WFD_APP_LOG(WFD_APP_LOG_LOW,
649 "event ------------------ WIFI_DIRECT_CONNECTION_WPS_REQ\n");
650 result = wifi_direct_get_config_data(&config);
651 WFD_APP_LOG(WFD_APP_LOG_LOW,
652 "wifi_direct_client_get_config_data() result=[%d]\n",
655 if (config->wps_config == WIFI_DIRECT_WPS_TYPE_PBC)
657 WFD_APP_LOG(WFD_APP_LOG_LOW,
658 "wps_config is WIFI_DIRECT_WPS_TYPE_PBC. Ignore it..\n");
660 else if (config->wps_config == WIFI_DIRECT_WPS_TYPE_PIN_KEYPAD)
663 WFD_APP_LOG(WFD_APP_LOG_LOW, "wps_config is WIFI_DIRECT_WPS_TYPE_PIN_KEYPAD\n");
665 if (wifi_direct_generate_wps_pin() != WIFI_DIRECT_ERROR_NONE)
667 WFD_APP_LOG(WFD_APP_LOG_LOW, "wifi_direct_generate_wps_pin() is failed\n");
671 if (wifi_direct_get_wps_pin(&pin) != WIFI_DIRECT_ERROR_NONE)
673 WFD_APP_LOG(WFD_APP_LOG_LOW, "wifi_direct_generate_wps_pin() is failed\n");
676 strncpy(ad->pin_number, pin, 32);
680 WFD_APP_LOG(WFD_APP_LOG_LOW, "pin=[%s]\n", ad->pin_number);
682 wfd_prepare_popup(WFD_POP_PROG_CONNECT_WITH_PIN, NULL);
684 else if (config->wps_config == WIFI_DIRECT_WPS_TYPE_PIN_DISPLAY)
686 WFD_APP_LOG(WFD_APP_LOG_LOW, "wps_config is WIFI_DIRECT_WPS_TYPE_PIN_DISPLAY\n");
687 wfd_prepare_popup(WFD_POP_PROG_CONNECT_WITH_KEYPAD, (void *) NULL);
691 WFD_APP_LOG(WFD_APP_LOG_LOW, "wps_config is unkown!\n");
699 case WIFI_DIRECT_CONNECTION_REQ:
701 WFD_APP_LOG(WFD_APP_LOG_LOW, "event ------------------ WIFI_DIRECT_CONNECTION_REQ\n");
703 wifi_direct_config_data_s *config = NULL;
705 result = wifi_direct_get_config_data(&config);
706 WFD_APP_LOG(WFD_APP_LOG_LOW, "wifi_direct_client_get_config_data() result=[%d]\n", result);
708 if(config->auto_connection == TRUE)
710 result = wifi_direct_accept_connection(ad->peer_mac);
711 printf("wifi_direct_accept_connection() result=[%d]\n", result);
716 if (config->wps_config == WIFI_DIRECT_WPS_TYPE_PBC)
719 WFD_APP_LOG(WFD_APP_LOG_LOW, "wps_config is WIFI_DIRECT_WPS_TYPE_PBC\n");
721 wfd_prepare_popup(WFD_POP_APRV_CONNECTION_WPS_PUSHBUTTON_REQ, NULL);
723 else if (config->wps_config == WIFI_DIRECT_WPS_TYPE_PIN_DISPLAY)
725 WFD_APP_LOG(WFD_APP_LOG_LOW, "wps_config is WIFI_DIRECT_WPS_TYPE_PIN_DISPLAY\n");
727 wfd_prepare_popup(WFD_POP_APRV_CONNECTION_WPS_DISPLAY_REQ, NULL);
729 else if (config->wps_config == WIFI_DIRECT_WPS_TYPE_PIN_KEYPAD)
731 WFD_APP_LOG(WFD_APP_LOG_LOW, "wps_config is WIFI_DIRECT_WPS_TYPE_PIN_KEYPAD\n");
732 wfd_prepare_popup(WFD_POP_APRV_CONNECTION_WPS_KEYPAD_REQ, (void *) NULL);
736 WFD_APP_LOG(WFD_APP_LOG_LOW, "wps_config is unkown!\n");
746 case WIFI_DIRECT_DISCONNECTION_IND:
748 _del_wfd_notification();
749 WFD_APP_LOG(WFD_APP_LOG_LOW,
750 "event ------------------ WIFI_DIRECT_DISCONNECTION_IND\n");
752 result = wifi_direct_set_autoconnection_mode(false);
753 WFD_APP_LOG(WFD_APP_LOG_LOW,"wifi_direct_set_autoconnection_mode() result=[%d]\n", result);
755 /* tickernoti popup */
756 snprintf(msg, WFD_POP_STR_MAX_LEN, _("IDS_WFD_POP_DISCONNECTED"), ad->peer_name);
757 wfd_tickernoti_popup(msg);
761 case WIFI_DIRECT_DISCONNECTION_RSP:
763 _del_wfd_notification();
766 result = wifi_direct_set_autoconnection_mode(false);
767 WFD_APP_LOG(WFD_APP_LOG_LOW,"wifi_direct_set_autoconnection_mode() result=[%d]\n", result);
769 result = wifi_direct_start_discovery(FALSE, 0);
770 WFD_APP_LOG(WFD_APP_LOG_LOW,
771 "wifi_direct_start_discovery() result=[%d]\n", result);
773 /* tickernoti popup */
774 snprintf(msg, WFD_POP_STR_MAX_LEN, _("IDS_WFD_POP_DISCONNECTED"), ad->peer_name);
775 wfd_tickernoti_popup(msg);
778 case WIFI_DIRECT_CONNECTION_IN_PROGRESS:
780 WFD_APP_LOG(WFD_APP_LOG_LOW,
781 "event ------------------ WIFI_DIRECT_CONNECTION_IN_PROGRESS\n");
782 /* tickernoti popup */
783 wfd_tickernoti_popup(_("IDS_WFD_POP_CONNECTING"));
790 /* if connected, switch to the transmit timer; Otherwise, switch to monitor timer */
791 wifi_direct_get_state(&ad->wfd_status);
792 WFD_APP_LOG(WFD_APP_LOG_LOW,"status: %d", ad->wfd_status);
794 if (ad->wfd_status > WIFI_DIRECT_STATE_CONNECTING) {
795 if (ad->monitor_timer) {
796 ecore_timer_del(ad->monitor_timer);
797 ad->monitor_timer = NULL;
800 if (NULL == ad->transmit_timer) {
801 WFD_APP_LOG(WFD_APP_LOG_LOW, "switch to the transmit timer\n");
802 ad->last_wfd_transmit_time = time(NULL);
803 ad->transmit_timer = ecore_timer_add(5.0,
804 (Ecore_Task_Cb)_wfd_automatic_deactivated_for_connection_cb, ad);
807 if (ad->transmit_timer) {
808 ecore_timer_del(ad->transmit_timer);
809 ad->transmit_timer = NULL;
812 if (NULL == ad->monitor_timer) {
813 WFD_APP_LOG(WFD_APP_LOG_LOW, "switch to the monitor timer\n");
814 ad->last_wfd_time = time(NULL);
815 ad->monitor_timer = ecore_timer_add(5.0,
816 (Ecore_Task_Cb)_wfd_automatic_deactivated_for_no_connection_cb, ad);
820 __WFD_APP_FUNC_EXIT__;
824 int init_wfd_popup_client(wfd_appdata_t * ad)
826 __WFD_APP_FUNC_ENTER__;
829 WFD_APP_LOG(WFD_APP_LOG_LOW, "NULL parameters.\n");
835 ret = wifi_direct_initialize();
837 ret = wifi_direct_set_device_state_changed_cb(_cb_activation, (void *) ad);
838 ret = wifi_direct_set_discovery_state_changed_cb(_cb_discover, (void *) ad);
840 wifi_direct_set_connection_state_changed_cb(_cb_connection,
843 /* initialize notification */
845 ad->raw_connected_peer_cnt = 0;
847 ad->noti = notification_new(NOTIFICATION_TYPE_NOTI, NOTIFICATION_GROUP_ID_NONE, NOTIFICATION_PRIV_ID_NONE);
848 if (NULL == ad->noti) {
849 WFD_APP_LOG(WFD_APP_LOG_LOW, "notification_new failed.\n");
853 /* start the monitor timer */
854 ad->last_wfd_time = time(NULL);
855 ad->last_wfd_status = WIFI_DIRECT_STATE_DEACTIVATED;
856 ad->monitor_timer = ecore_timer_add(5.0, (Ecore_Task_Cb)_wfd_automatic_deactivated_for_no_connection_cb, ad);
858 __WFD_APP_FUNC_EXIT__;
860 if (ret == WIFI_DIRECT_ERROR_NONE)
866 int deinit_wfd_popup_client(wfd_appdata_t * ad)
868 __WFD_APP_FUNC_ENTER__;
870 if (NULL == ad || NULL == ad->noti) {
871 WFD_APP_LOG(WFD_APP_LOG_LOW, "NULL parameters.\n");
877 ret = wifi_direct_deinitialize();
879 _del_wfd_notification(ad);
881 notification_error_e noti_err = NOTIFICATION_ERROR_NONE;
882 noti_err = notification_free(ad->noti);
883 if (noti_err != NOTIFICATION_ERROR_NONE) {
884 WFD_APP_LOG(WFD_APP_LOG_LOW, "Fail to notification_free.(%d)\n", noti_err);
885 ret = WIFI_DIRECT_ERROR_RESOURCE_BUSY;
888 if (ad->transmit_timer) {
889 ecore_timer_del(ad->transmit_timer);
890 ad->transmit_timer = NULL;
893 if (ad->monitor_timer) {
894 ecore_timer_del(ad->monitor_timer);
895 ad->monitor_timer = NULL;
898 __WFD_APP_FUNC_EXIT__;
900 if (ret == WIFI_DIRECT_ERROR_NONE)