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://floralicense.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)
32 #include <notification.h>
36 #include "wfd-app-util.h"
37 #include "wfd-app-strings.h"
40 * This function let the app make a callback for connected peer
42 * @param[in] peer the pointer to the connected peer
43 * @param[in] user_data the pointer to the main data structure
45 bool _wfd_connected_peer_cb(wifi_direct_connected_peer_info_s *peer, void *user_data)
47 __WDPOP_LOG_FUNC_ENTER__;
49 wfd_appdata_t *ad = (wfd_appdata_t *) user_data;
50 if (NULL == ad || NULL == peer || NULL == peer->device_name || NULL == peer->mac_address) {
51 WDPOP_LOGD( "NULL parameters.\n");
55 int peer_cnt = ad->raw_connected_peer_cnt;
56 WDPOP_LOGD( "%dth connected peer. [%s]\n", peer_cnt, peer->device_name);
58 strncpy(ad->raw_connected_peers[peer_cnt].ssid, peer->device_name, sizeof(ad->raw_connected_peers[peer_cnt].ssid));
59 strncpy(ad->raw_connected_peers[peer_cnt].mac_address, peer->mac_address, WFD_MAC_ADDRESS_SIZE);
60 WDPOP_LOGD( "\tSSID: [%s]\n", ad->raw_connected_peers[peer_cnt].ssid);
61 ad->raw_connected_peer_cnt++;
63 free(peer->device_name);
64 free(peer->mac_address);
67 __WDPOP_LOG_FUNC_EXIT__;
72 * This function let the app get the connected peers
73 * @return If success, return 0, else return -1
74 * @param[in] ugd the pointer to the main data structure
76 int _wfd_app_get_connected_peers(void *user_data)
78 __WDPOP_LOG_FUNC_ENTER__;
80 wfd_appdata_t *ad = (wfd_appdata_t *) user_data;
82 WDPOP_LOGD( "NULL parameters.\n");
88 ad->raw_connected_peer_cnt = 0;
89 res = wifi_direct_foreach_connected_peers(_wfd_connected_peer_cb, (void *)ad);
90 if (res != WIFI_DIRECT_ERROR_NONE) {
91 ad->raw_connected_peer_cnt = 0;
92 WDPOP_LOGD( "Get connected peer failed: %d\n", res);
95 __WDPOP_LOG_FUNC_EXIT__;
100 * This function let the app delete the notification
103 void _del_wfd_notification()
105 __WDPOP_LOG_FUNC_ENTER__;
107 /* delete the notification */
108 notification_error_e noti_err = NOTIFICATION_ERROR_NONE;
109 noti_err = notification_delete_all_by_type(NULL, NOTIFICATION_TYPE_NOTI);
110 if (noti_err != NOTIFICATION_ERROR_NONE) {
111 WDPOP_LOGD( "Fail to notification_delete_all_by_type.(%d)\n", noti_err);
115 __WDPOP_LOG_FUNC_EXIT__;
119 * This function let the app add the notification when it is connected
121 * @param[in] user_data the pointer to the main data structure
123 void _add_wfd_peers_connected_notification(void *user_data)
125 __WDPOP_LOG_FUNC_ENTER__;
127 wfd_appdata_t *ad = (wfd_appdata_t *) user_data;
128 if (NULL == ad || NULL == ad->noti) {
129 WDPOP_LOGD( "NULL parameters.\n");
133 char msg[WFD_MAX_SIZE] = {0};
134 notification_error_e noti_err = NOTIFICATION_ERROR_NONE;
136 /* delete all notifications */
137 _del_wfd_notification();
140 noti_err = notification_set_image(ad->noti, NOTIFICATION_IMAGE_TYPE_ICON, RESDIR"/images/A09_notification_icon.png");
141 if (noti_err != NOTIFICATION_ERROR_NONE) {
142 WDPOP_LOGD( "Fail to notification_set_image. (%d)\n", noti_err);
146 /* set the title and content */
147 _wfd_app_get_connected_peers(ad);
148 snprintf(msg, WFD_MAX_SIZE, "Connected with %d devices via Wi-Fi Direct", ad->raw_connected_peer_cnt);
149 noti_err = notification_set_text(ad->noti, NOTIFICATION_TEXT_TYPE_TITLE, msg, NULL, NOTIFICATION_VARIABLE_TYPE_NONE);
150 if (noti_err != NOTIFICATION_ERROR_NONE) {
151 WDPOP_LOGD( "Fail to notification_set_text. (%d)\n", noti_err);
155 noti_err = notification_set_text(ad->noti, NOTIFICATION_TEXT_TYPE_CONTENT,
156 "Tap to change settings", NULL, NOTIFICATION_VARIABLE_TYPE_NONE);
157 if (noti_err != NOTIFICATION_ERROR_NONE) {
158 WDPOP_LOGD( "Fail to notification_set_text. (%d)\n", noti_err);
164 appsvc_set_pkgname(b, PACKAGE);
165 appsvc_add_data(b, NOTIFICATION_BUNDLE_PARAM, NOTIFICATION_BUNDLE_VALUE);
167 int res = NOTIFICATION_ERROR_NONE;
168 res = notification_set_execute_option(ad->noti, NOTIFICATION_EXECUTE_TYPE_SINGLE_LAUNCH, /*Button Text*/NULL, NULL, b);
169 if (res != NOTIFICATION_ERROR_NONE) {
170 WDPOP_LOGD( "Failed to notification_set_execute_option. [%d]", res);
176 /* set display application list */
177 noti_err = notification_set_display_applist(ad->noti, NOTIFICATION_DISPLAY_APP_NOTIFICATION_TRAY);
178 if (noti_err != NOTIFICATION_ERROR_NONE) {
179 WDPOP_LOGD( "Fail to notification_set_display_applist : %d\n", noti_err);
183 /* notify the quick panel */
184 noti_err = notification_insert(ad->noti, NULL);
185 if (noti_err != NOTIFICATION_ERROR_NONE) {
186 WDPOP_LOGD( "Fail to notification_insert.(%d)\n", noti_err);
190 __WDPOP_LOG_FUNC_EXIT__;
194 * This function let the app add the notification when it shoule be turned off
196 * @param[in] user_data the pointer to the main data structure
198 void _add_wfd_turn_off_notification(void *user_data)
200 __WDPOP_LOG_FUNC_ENTER__;
202 wfd_appdata_t *ad = (wfd_appdata_t *) user_data;
203 if (NULL == ad || NULL == ad->noti) {
204 WDPOP_LOGD( "NULL parameters.\n");
208 notification_error_e noti_err = NOTIFICATION_ERROR_NONE;
210 /* delete all notifications */
211 _del_wfd_notification();
214 noti_err = notification_set_image(ad->noti, NOTIFICATION_IMAGE_TYPE_ICON, RESDIR"/images/A09_notification_icon.png");
215 if (noti_err != NOTIFICATION_ERROR_NONE) {
216 WDPOP_LOGD( "Fail to notification_set_image. (%d)\n", noti_err);
220 /* set the title and content */
221 noti_err = notification_set_text(ad->noti, NOTIFICATION_TEXT_TYPE_TITLE,
222 "Disable Wi-Fi Direct after use", NULL, NOTIFICATION_VARIABLE_TYPE_NONE);
223 if (noti_err != NOTIFICATION_ERROR_NONE) {
224 WDPOP_LOGD( "Fail to notification_set_text. (%d)\n", noti_err);
228 noti_err = notification_set_text(ad->noti, NOTIFICATION_TEXT_TYPE_CONTENT,
229 "Disable Wi-Fi Direct after use to save battery", NULL, NOTIFICATION_VARIABLE_TYPE_NONE);
230 if (noti_err != NOTIFICATION_ERROR_NONE) {
231 WDPOP_LOGD( "Fail to notification_set_text. (%d)\n", noti_err);
237 appsvc_set_pkgname(b, PACKAGE);
238 appsvc_add_data(b, NOTIFICATION_BUNDLE_PARAM, NOTIFICATION_BUNDLE_VALUE);
240 int res = NOTIFICATION_ERROR_NONE;
241 res = notification_set_execute_option(ad->noti, NOTIFICATION_EXECUTE_TYPE_SINGLE_LAUNCH, /*Button Text*/NULL, NULL, b);
242 if (res != NOTIFICATION_ERROR_NONE) {
243 WDPOP_LOGD( "Failed to notification_set_execute_option. [%d]", res);
249 /* set display application list */
250 noti_err = notification_set_display_applist(ad->noti, NOTIFICATION_DISPLAY_APP_NOTIFICATION_TRAY);
251 if (noti_err != NOTIFICATION_ERROR_NONE) {
252 WDPOP_LOGD( "Fail to notification_set_display_applist : %d\n", noti_err);
256 /* notify the quick panel */
257 noti_err = notification_insert(ad->noti, NULL);
258 if (noti_err != NOTIFICATION_ERROR_NONE) {
259 WDPOP_LOGD( "Fail to notification_insert.(%d)\n", noti_err);
263 __WDPOP_LOG_FUNC_EXIT__;
267 * This function let the app make a callback for deactivating wfd automatically when connected
268 * @return if stop the timer, return ECORE_CALLBACK_CANCEL, else return ECORE_CALLBACK_RENEW
269 * @param[in] user_data the pointer to the main data structure
271 static Eina_Bool _wfd_automatic_deactivated_for_connection_cb(void *user_data)
274 int wfd_transfer_state = 0;
275 wfd_appdata_t *ad = (wfd_appdata_t *)user_data;
278 WDPOP_LOGD( "NULL parameters.\n");
279 return ECORE_CALLBACK_CANCEL;
282 /* check the timeout, if not timeout, keep the cb */
283 interval = time(NULL) - ad->last_wfd_transmit_time;
284 if (interval < NO_ACTION_TIME_OUT) {
285 return ECORE_CALLBACK_RENEW;
288 /* get transfer state */
289 if (vconf_get_int(VCONFKEY_WIFI_DIRECT_TRANSFER_STATE, &wfd_transfer_state) < 0) {
290 WDPOP_LOGD( "Error reading vconf (%s)\n",
291 VCONFKEY_WIFI_DIRECT_TRANSFER_STATE);
292 return ECORE_CALLBACK_CANCEL;
296 if (wfd_transfer_state > VCONFKEY_WIFI_DIRECT_TRANSFER_START) {
297 WDPOP_LOGD( "No RX/TX packet, turn off WFD automatically.\n");
298 _add_wfd_turn_off_notification(ad);
300 WDPOP_LOGD( "Has RX/TX packet, restart.\n");
301 ad->last_wfd_transmit_time = time(NULL);
302 return ECORE_CALLBACK_RENEW;
305 return ECORE_CALLBACK_CANCEL;
309 * This function let the app make a callback for registering activation event
311 * @param[in] error_code the returned error code
312 * @param[in] device_state the state of device
313 * @param[in] user_data the pointer to the main data structure
315 void _cb_activation(int error_code, wifi_direct_device_state_e device_state, void *user_data)
317 __WDPOP_LOG_FUNC_ENTER__;
318 wfd_appdata_t *ad = (wfd_appdata_t *)user_data;
320 switch (device_state) {
321 case WIFI_DIRECT_DEVICE_STATE_ACTIVATED:
322 WDPOP_LOGD( "event ------------------ WIFI_DIRECT_DEVICE_STATE_ACTIVATED\n");
325 case WIFI_DIRECT_DEVICE_STATE_DEACTIVATED:
326 WDPOP_LOGD( "event ------------------ WIFI_DIRECT_DEVICE_STATE_DEACTIVATED\n");
327 WDPOP_LOGD( "Termination process of wifi-direct popup begins...\n");
329 /* when deactivated, stop the timer */
330 if (ad->transmit_timer) {
331 ecore_timer_del(ad->transmit_timer);
332 ad->transmit_timer = NULL;
342 __WDPOP_LOG_FUNC_EXIT__;
346 * This function let the app find the peer by mac address
347 * @return the found peer
348 * @param[in] data the pointer to the main data structure
349 * @param[in] mac_address the pointer to mac address
351 static wfd_device_info_t *_wfd_app_find_peer_by_mac_address(void *data, const char *mac_address)
353 __WDPOP_LOG_FUNC_ENTER__;
354 wfd_appdata_t *ad = (wfd_appdata_t *) data;
358 WDPOP_LOGD( "Incorrect parameter(NULL)\n");
362 WDPOP_LOGD( "find peer by MAC [%s] \n", mac_address);
364 for (i = 0; i < ad->discovered_peer_count; i++) {
365 WDPOP_LOGD( "check %dth peer\n", i);
367 if (!strncmp(mac_address, (const char *) ad->discovered_peers[i].mac_address, 18)) {
368 WDPOP_LOGD( "found peer. [%d]\n", i);
369 __WDPOP_LOG_FUNC_EXIT__;
370 return &ad->discovered_peers[i];
374 __WDPOP_LOG_FUNC_EXIT__;
379 * This function let the app make a callback for discovering peer
381 * @param[in] peer the pointer to the discovered peer
382 * @param[in] user_data the pointer to the main data structure
384 bool _wfd_app_discoverd_peer_cb(wifi_direct_discovered_peer_info_s *peer, void *user_data)
386 __WDPOP_LOG_FUNC_ENTER__;
387 wfd_appdata_t *ad = (wfd_appdata_t *) user_data;
389 if (NULL != peer->device_name) {
390 WDPOP_LOGD( "discovered peer ssid[%s]\n", peer->device_name);
391 strncpy(ad->discovered_peers[ad->discovered_peer_count].ssid, peer->device_name, 32);
393 WDPOP_LOGD( "peer's device name is NULL\n");
396 if (NULL != peer->mac_address) {
397 WDPOP_LOGD( "discovered peer mac[%s]\n", peer->mac_address);
398 strncpy(ad->discovered_peers[ad->discovered_peer_count].mac_address, peer->mac_address, 18);
400 WDPOP_LOGD( "peer's mac is NULL\n");
403 ad->discovered_peer_count++;
405 __WDPOP_LOG_FUNC_EXIT__;
411 * This function let the app make a callback for registering discover event
413 * @param[in] error_code the returned error code
414 * @param[in] discovery_state the state of discover
415 * @param[in] user_data the pointer to the main data structure
417 void _cb_discover(int error_code, wifi_direct_discovery_state_e discovery_state, void *user_data)
419 __WDPOP_LOG_FUNC_ENTER__;
420 wfd_appdata_t *ad = (wfd_appdata_t *)user_data;
423 switch (discovery_state) {
424 case WIFI_DIRECT_DISCOVERY_STARTED:
425 WDPOP_LOGD( "event ------------------ WIFI_DIRECT_DISCOVERY_STARTED\n");
428 case WIFI_DIRECT_ONLY_LISTEN_STARTED:
429 WDPOP_LOGD( "event ------------------ WIFI_DIRECT_ONLY_LISTEN_STARTED\n");
432 case WIFI_DIRECT_DISCOVERY_FINISHED:
433 WDPOP_LOGD( "event ------------------ WIFI_DIRECT_DISCOVERY_FINISHED\n");
436 case WIFI_DIRECT_DISCOVERY_FOUND:
437 WDPOP_LOGD( "event ------------------ WIFI_DIRECT_DISCOVERY_FOUND\n");
439 if (NULL != ad->discovered_peers) {
440 free(ad->discovered_peers);
441 ad->discovered_peers = NULL;
444 ad->discovered_peers = calloc(10, sizeof(wfd_device_info_t));
445 ad->discovered_peer_count = 0;
447 ret = wifi_direct_foreach_discovered_peers(_wfd_app_discoverd_peer_cb, (void *) ad);
448 if (ret != WIFI_DIRECT_ERROR_NONE) {
449 WDPOP_LOGD( "get discovery result failed: %d\n", ret);
457 __WDPOP_LOG_FUNC_EXIT__;
461 * This function let the app make a callback for registering connection event
463 * @param[in] error_code the returned error code
464 * @param[in] connection_state the state of connection
465 * @param[in] mac_address the mac address of peer
466 * @param[in] user_data the pointer to the main data structure
468 void _cb_connection(int error_code, wifi_direct_connection_state_e connection_state, const char *mac_address, void *user_data)
470 __WDPOP_LOG_FUNC_ENTER__;
472 wfd_appdata_t *ad = (wfd_appdata_t *)user_data;
474 char msg[WFD_POP_STR_MAX_LEN] = {0};
475 wfd_device_info_t *peer_info = NULL;
477 /* find the peer's name by the mac address */
478 if (NULL == mac_address) {
479 WDPOP_LOGE("ERROR : mac address is NULL !!\n");
483 /* when disconnection, mac_address is empty */
484 if (connection_state <= WIFI_DIRECT_CONNECTION_RSP ||
485 connection_state == WIFI_DIRECT_INVITATION_REQ) {
486 memset(ad->peer_mac, 0, sizeof(ad->peer_mac));
487 memset(ad->peer_name, 0, sizeof(ad->peer_name));
488 strncpy(ad->peer_mac, mac_address, strlen(mac_address));
489 peer_info = _wfd_app_find_peer_by_mac_address(ad, mac_address);
491 if (NULL == peer_info) {
492 WDPOP_LOGD( "peer_info is NULL !!\n");
493 } else if (0 == strlen(peer_info->ssid)) {
494 WDPOP_LOGD( "SSID from connection is invalid !!\n");
496 WDPOP_LOGD( "SSID from connection is %s.\n", peer_info->ssid);
497 strncpy(ad->peer_name, peer_info->ssid, strlen(peer_info->ssid));
500 if (0 == strlen(ad->peer_name)) {
501 strncpy(ad->peer_name, ad->peer_mac, strlen(ad->peer_mac));
505 switch (connection_state) {
506 case WIFI_DIRECT_CONNECTION_RSP:
508 WDPOP_LOGD( "event ------------------ WIFI_DIRECT_CONNECTION_RSP\n");
511 if (error_code == WIFI_DIRECT_ERROR_NONE) {
512 WDPOP_LOGD( "Link Complete!\n");
514 /* add connected notification */
515 _add_wfd_peers_connected_notification(ad);
517 /* tickernoti popup */
518 snprintf(msg, WFD_POP_STR_MAX_LEN, IDS_WFD_POP_CONNECTED, ad->peer_name);
519 notification_status_message_post(msg);
520 } else if (error_code == WIFI_DIRECT_ERROR_AUTH_FAILED) {
522 "Error Code - WIFI_DIRECT_ERROR_AUTH_FAILED\n");
523 notification_status_message_post(_("IDS_WFD_POP_PIN_INVALID"));
525 if (error_code == WIFI_DIRECT_ERROR_CONNECTION_TIME_OUT) {
527 "Error Code - WIFI_DIRECT_ERROR_CONNECTION_TIME_OUT\n");
528 } else if (error_code == WIFI_DIRECT_ERROR_CONNECTION_FAILED) {
530 "Error Code - WIFI_DIRECT_ERROR_CONNECTION_FAILED\n");
533 /* tickernoti popup */
534 snprintf(msg, WFD_POP_STR_MAX_LEN, IDS_WFD_POP_CONNECT_FAILED, ad->peer_name);
535 notification_status_message_post(msg);
540 case WIFI_DIRECT_CONNECTION_WPS_REQ:
542 wifi_direct_wps_type_e wps_mode;
544 memcpy(ad->peer_mac, mac_address, sizeof(ad->peer_mac));
547 "event ------------------ WIFI_DIRECT_CONNECTION_WPS_REQ\n");
548 result = wifi_direct_get_wps_type(&wps_mode);
550 "wifi_direct_get_wps_type() result=[%d]\n", result);
552 if (wps_mode == WIFI_DIRECT_WPS_TYPE_PBC) {
554 "wps_config is WIFI_DIRECT_WPS_TYPE_PBC. Ignore it..\n");
555 } else if (wps_mode == WIFI_DIRECT_WPS_TYPE_PIN_DISPLAY) {
557 WDPOP_LOGD( "wps_config is WIFI_DIRECT_WPS_TYPE_PIN_DISPLAY\n");
559 if (wifi_direct_generate_wps_pin() != WIFI_DIRECT_ERROR_NONE) {
560 WDPOP_LOGD( "wifi_direct_generate_wps_pin() is failed\n");
564 if (wifi_direct_get_wps_pin(&pin) != WIFI_DIRECT_ERROR_NONE) {
565 WDPOP_LOGD( "wifi_direct_generate_wps_pin() is failed\n");
569 strncpy(ad->pin_number, pin, 64);
573 WDPOP_LOGD( "pin=[%s]\n", ad->pin_number);
575 wfd_prepare_popup(WFD_POP_PROG_CONNECT_WITH_PIN, NULL);
576 } else if (wps_mode == WIFI_DIRECT_WPS_TYPE_PIN_KEYPAD) {
577 WDPOP_LOGD( "wps_config is WIFI_DIRECT_WPS_TYPE_PIN_KEYPAD\n");
578 wfd_prepare_popup(WFD_POP_PROG_CONNECT_WITH_KEYPAD, (void *) NULL);
580 WDPOP_LOGD( "wps_config is unkown!\n");
586 case WIFI_DIRECT_CONNECTION_REQ:
588 WDPOP_LOGD( "event ------------------ WIFI_DIRECT_CONNECTION_REQ\n");
590 wifi_direct_wps_type_e wps_mode;
591 bool auto_connection_mode;
593 result = wifi_direct_get_wps_type(&wps_mode);
594 WDPOP_LOGD( "wifi_direct_get_wps_type() result=[%d]\n", result);
596 result = wifi_direct_is_autoconnection_mode(&auto_connection_mode);
597 WDPOP_LOGD( "wifi_direct_is_autoconnection_mode() result=[%d]\n", result);
599 if (auto_connection_mode == TRUE) {
600 result = wifi_direct_accept_connection(ad->peer_mac);
601 printf("wifi_direct_accept_connection() result=[%d]\n", result);
603 if (wps_mode == WIFI_DIRECT_WPS_TYPE_PBC) {
604 WDPOP_LOGD( "wps_config is WIFI_DIRECT_WPS_TYPE_PBC\n");
605 wfd_prepare_popup(WFD_POP_APRV_CONNECTION_WPS_PUSHBUTTON_REQ, NULL);
606 } else if (wps_mode == WIFI_DIRECT_WPS_TYPE_PIN_DISPLAY) {
607 WDPOP_LOGD( "wps_config is WIFI_DIRECT_WPS_TYPE_PIN_DISPLAY\n");
608 wfd_prepare_popup(WFD_POP_APRV_CONNECTION_WPS_DISPLAY_REQ, NULL);
609 } else if (wps_mode == WIFI_DIRECT_WPS_TYPE_PIN_KEYPAD) {
610 WDPOP_LOGD( "wps_config is WIFI_DIRECT_WPS_TYPE_PIN_KEYPAD\n");
611 wfd_prepare_popup(WFD_POP_APRV_CONNECTION_WPS_KEYPAD_REQ, (void *) NULL);
613 WDPOP_LOGD( "wps_config is unkown!\n");
619 case WIFI_DIRECT_DISCONNECTION_IND:
621 _del_wfd_notification();
622 WDPOP_LOGD( "event ------------------ WIFI_DIRECT_DISCONNECTION_IND\n");
624 result = wifi_direct_set_autoconnection_mode(false);
625 WDPOP_LOGD( "wifi_direct_set_autoconnection_mode() result=[%d]\n", result);
627 /* tickernoti popup */
628 snprintf(msg, WFD_POP_STR_MAX_LEN, IDS_WFD_POP_DISCONNECTED, ad->peer_name);
629 notification_status_message_post(msg);
633 case WIFI_DIRECT_DISCONNECTION_RSP:
635 _del_wfd_notification();
638 result = wifi_direct_set_autoconnection_mode(false);
639 WDPOP_LOGD( "wifi_direct_set_autoconnection_mode() result=[%d]\n", result);
641 /* tickernoti popup */
642 snprintf(msg, WFD_POP_STR_MAX_LEN, IDS_WFD_POP_DISCONNECTED, ad->peer_name);
643 notification_status_message_post(msg);
646 case WIFI_DIRECT_CONNECTION_IN_PROGRESS:
648 WDPOP_LOGD( "event ------------------ WIFI_DIRECT_CONNECTION_IN_PROGRESS\n");
649 /* tickernoti popup */
650 notification_status_message_post(_("IDS_WFD_POP_CONNECTING"));
653 case WIFI_DIRECT_INVITATION_REQ:
655 WDPOP_LOGD( "event ------------------ WIFI_DIRECT_INVITATION_REQ\n");
656 bool auto_connection_mode = FALSE;
658 wifi_direct_is_autoconnection_mode(&auto_connection_mode);
659 if (auto_connection_mode == TRUE) {
660 result = wifi_direct_connect(ad->peer_mac);
661 printf("wifi_direct_accept_connection() result=[%d]\n", result);
663 wfd_prepare_popup(WFD_POP_APRV_CONNECTION_INVITATION_REQ, NULL);
672 /* if connected, start the transmit timer */
673 wifi_direct_get_state(&ad->wfd_status);
674 WDPOP_LOGD( "status: %d", ad->wfd_status);
676 if (ad->wfd_status < WIFI_DIRECT_STATE_CONNECTED) {
677 if (ad->transmit_timer) {
678 ecore_timer_del(ad->transmit_timer);
679 ad->transmit_timer = NULL;
682 if (NULL == ad->transmit_timer) {
683 WDPOP_LOGD( "start the transmit timer\n");
684 ad->last_wfd_transmit_time = time(NULL);
685 ad->transmit_timer = ecore_timer_add(5.0,
686 (Ecore_Task_Cb)_wfd_automatic_deactivated_for_connection_cb, ad);
690 __WDPOP_LOG_FUNC_EXIT__;
694 * This function let the app make a change callback for flight mode
696 * @param[in] key the pointer to the key
697 * @param[in] user_data the pointer to the main data structure
699 static void _wfd_flight_mode_changed(keynode_t *node, void *user_data)
701 __WDPOP_LOG_FUNC_ENTER__;
704 wfd_appdata_t *ad = (wfd_appdata_t *)user_data;
707 WDPOP_LOGE("NULL parameters.\n");
711 res = vconf_get_bool(VCONFKEY_SETAPPL_FLIGHT_MODE_BOOL, &flight_mode);
713 WDPOP_LOGE("Failed to get flight state from vconf. [%d]\n", res);
717 if (flight_mode == FALSE) {
718 WDPOP_LOGD( "Flight mode is off\n");
722 /* If flight mode is on, turn off WFD */
723 wifi_direct_get_state(&ad->wfd_status);
724 if (WIFI_DIRECT_STATE_DEACTIVATED == ad->wfd_status) {
725 WDPOP_LOGD( "Wi-Fi Direct is deactivated.\n");
729 /*if connected, disconnect all devices*/
730 if (WIFI_DIRECT_STATE_CONNECTED == ad->wfd_status) {
731 res = wifi_direct_disconnect_all();
732 if (res != WIFI_DIRECT_ERROR_NONE) {
733 WDPOP_LOGE("Failed to send disconnection request to all. [%d]\n", res);
738 res = wifi_direct_deactivate();
739 if (res != WIFI_DIRECT_ERROR_NONE) {
740 WDPOP_LOGE("Failed to deactivate Wi-Fi Direct. error code = [%d]\n", res);
744 __WDPOP_LOG_FUNC_EXIT__;
748 * This function let the app do initialization
749 * @return If success, return TRUE, else return FALSE
750 * @param[in] ad the pointer to the main data structure
752 int init_wfd_popup_client(wfd_appdata_t *ad)
754 __WDPOP_LOG_FUNC_ENTER__;
757 WDPOP_LOGD( "NULL parameters.\n");
763 ret = wifi_direct_initialize();
764 if (ret != WIFI_DIRECT_ERROR_NONE) {
765 WDPOP_LOGE("Failed to initialize Wi-Fi Direct. error code = [%d]\n", ret);
769 ret = wifi_direct_set_device_state_changed_cb(_cb_activation, (void *)ad);
770 if (ret != WIFI_DIRECT_ERROR_NONE) {
771 WDPOP_LOGE("Failed to register _cb_activation. error code = [%d]\n", ret);
775 ret = wifi_direct_set_discovery_state_changed_cb(_cb_discover, (void *)ad);
776 if (ret != WIFI_DIRECT_ERROR_NONE) {
777 WDPOP_LOGE("Failed to register _cb_discover. error code = [%d]\n", ret);
781 ret = wifi_direct_set_connection_state_changed_cb(_cb_connection, (void *)ad);
782 if (ret != WIFI_DIRECT_ERROR_NONE) {
783 WDPOP_LOGE("Failed to register _cb_connection. error code = [%d]\n", ret);
787 /* initialize notification */
788 ad->noti = notification_new(NOTIFICATION_TYPE_NOTI, NOTIFICATION_GROUP_ID_NONE, NOTIFICATION_PRIV_ID_NONE);
789 if (NULL == ad->noti) {
790 WDPOP_LOGD( "notification_new failed.\n");
794 /* register flight mode */
796 result = vconf_notify_key_changed(VCONFKEY_SETAPPL_FLIGHT_MODE_BOOL, _wfd_flight_mode_changed, ad);
798 WDPOP_LOGE("Failed to register vconf callback for flight mode\n");
802 __WDPOP_LOG_FUNC_EXIT__;
804 if (ret == WIFI_DIRECT_ERROR_NONE) {
812 * This function let the app do de-initialization
813 * @return If success, return TRUE, else return FALSE
814 * @param[in] ad the pointer to the main data structure
816 int deinit_wfd_popup_client(wfd_appdata_t *ad)
818 __WDPOP_LOG_FUNC_ENTER__;
820 if (NULL == ad || NULL == ad->noti) {
821 WDPOP_LOGD( "NULL parameters.\n");
827 ret = wifi_direct_deinitialize();
829 _del_wfd_notification(ad);
830 notification_error_e noti_err = NOTIFICATION_ERROR_NONE;
831 noti_err = notification_free(ad->noti);
832 if (noti_err != NOTIFICATION_ERROR_NONE) {
833 WDPOP_LOGD( "Fail to notification_free.(%d)\n", noti_err);
834 ret = WIFI_DIRECT_ERROR_RESOURCE_BUSY;
837 /* remove callback for flight mode */
839 result = vconf_ignore_key_changed(VCONFKEY_WIFI_STATE, _wfd_flight_mode_changed);
841 WDPOP_LOGE("Failed to ignore vconf key callback for flight mode\n");
844 if (ad->transmit_timer) {
845 ecore_timer_del(ad->transmit_timer);
846 ad->transmit_timer = NULL;
849 __WDPOP_LOG_FUNC_EXIT__;
850 if (ret == WIFI_DIRECT_ERROR_NONE) {