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 <Elementary.h>
32 #include <app_control.h>
34 #include <notification.h>
36 #include <tethering.h>
37 #include <network-cm-intf.h>
38 #include <network-wifi-intf.h>
40 #include <dd-display.h>
43 #include "wfd-app-util.h"
44 #include "wfd-app-strings.h"
45 #include "wfd-app-popup-view.h"
48 * This function let the app make a callback for connected peer
50 * @param[in] peer the pointer to the connected peer
51 * @param[in] user_data the pointer to the main data structure
53 bool _wfd_connected_peer_cb(wifi_direct_connected_peer_info_s *peer, void *user_data)
55 __WFD_APP_FUNC_ENTER__;
57 wfd_appdata_t *ad = (wfd_appdata_t *) user_data;
59 if (NULL == ad || NULL == peer || NULL == peer->device_name || NULL == peer->mac_address) {
60 WFD_APP_LOG(WFD_APP_LOG_ERROR, "NULL parameters.\n");
64 int peer_cnt = ad->raw_connected_peer_cnt;
65 strncpy(ad->raw_connected_peers[peer_cnt].ssid, peer->device_name, sizeof(ad->raw_connected_peers[peer_cnt].ssid) - 1);
66 strncpy(ad->raw_connected_peers[peer_cnt].mac_address, peer->mac_address, WFD_MAC_ADDRESS_SIZE - 1);
68 ad->raw_connected_peer_cnt++;
70 free(peer->device_name);
71 free(peer->mac_address);
74 __WFD_APP_FUNC_EXIT__;
79 * This function let the app get the connected peers
80 * @return If success, return 0, else return -1
81 * @param[in] ugd the pointer to the main data structure
83 int wfd_app_get_connected_peers(void *user_data)
85 __WFD_APP_FUNC_ENTER__;
87 wfd_appdata_t *ad = (wfd_appdata_t *) user_data;
89 WFD_APP_LOG(WFD_APP_LOG_ERROR, "NULL parameters.\n");
95 ad->raw_connected_peer_cnt = 0;
96 res = wifi_direct_foreach_connected_peers(_wfd_connected_peer_cb, (void *)ad);
97 if (res != WIFI_DIRECT_ERROR_NONE) {
98 ad->raw_connected_peer_cnt = 0;
99 WFD_APP_LOG(WFD_APP_LOG_ERROR, "Get connected peer failed: %d\n", res);
102 __WFD_APP_FUNC_EXIT__;
107 * This function let the app make a callback for deactivating wfd automatically when connected
108 * @return if stop the timer, return ECORE_CALLBACK_CANCEL, else return ECORE_CALLBACK_RENEW
109 * @param[in] user_data the pointer to the main data structure
111 Eina_Bool wfd_automatic_deactivated_for_connection_cb(void *user_data)
113 __WFD_APP_FUNC_ENTER__;
115 int wfd_transfer_state = 0;
117 wfd_appdata_t *ad = (wfd_appdata_t *)user_data;
120 WFD_APP_LOG(WFD_APP_LOG_ERROR, "NULL parameters.\n");
121 return ECORE_CALLBACK_CANCEL;
124 /* check the timeout, if not timeout, keep the cb */
125 interval = time(NULL) - ad->last_wfd_transmit_time;
126 if (interval < NO_ACTION_TIME_OUT) {
127 return ECORE_CALLBACK_RENEW;
130 /* get transfer state */
131 if (vconf_get_int(VCONFKEY_WIFI_DIRECT_TRANSFER_STATE, &wfd_transfer_state) < 0) {
132 WFD_APP_LOG(WFD_APP_LOG_ERROR, "Error reading vconf (%s)\n",
133 VCONFKEY_WIFI_DIRECT_TRANSFER_STATE);
134 return ECORE_CALLBACK_CANCEL;
137 res = wifi_direct_get_state(&ad->wfd_status);
138 if (res != WIFI_DIRECT_ERROR_NONE) {
139 return ECORE_CALLBACK_CANCEL;
142 if (ad->wfd_status < WIFI_DIRECT_STATE_CONNECTED) {
143 WFD_APP_LOG(WFD_APP_LOG_ERROR, "Wi-Fi Direct is unconnected!");
144 return ECORE_CALLBACK_CANCEL;
148 if (wfd_transfer_state > VCONFKEY_WIFI_DIRECT_TRANSFER_START) {
149 WFD_APP_LOG(WFD_APP_LOG_LOW, "Display Toast popup.\n");
150 notification_status_message_post(_("IDS_WIFI_BODY_TO_SAVE_BATTERY_POWER_DISABLE_WI_FI_DIRECT_AFTER_USE"));
151 WFD_APP_LOG(WFD_APP_LOG_LOW, "No RX/TX packet, turn off WFD automatically.\n");
152 wfd_app_util_add_wfd_turn_off_notification(ad);
154 WFD_APP_LOG(WFD_APP_LOG_LOW, "Has RX/TX packet, restart.\n");
155 ad->last_wfd_transmit_time = time(NULL);
156 return ECORE_CALLBACK_RENEW;
159 ad->transmit_timer = NULL;
160 __WFD_APP_FUNC_EXIT__;
161 return ECORE_CALLBACK_CANCEL;
164 int wfd_app_client_switch_off(void *data)
166 wfd_appdata_t *ad = (wfd_appdata_t *)data;
169 WFD_APP_LOG(WFD_APP_LOG_ERROR, "NULL == ad!\n");
172 res = wifi_direct_get_state(&ad->wfd_status);
173 if (res != WIFI_DIRECT_ERROR_NONE) {
174 return ECORE_CALLBACK_CANCEL;
177 if (ad->wfd_status >= WIFI_DIRECT_STATE_ACTIVATING) {
178 /*if connected, disconnect all devices*/
179 if (WIFI_DIRECT_STATE_CONNECTED == ad->wfd_status) {
180 res = wifi_direct_disconnect_all();
181 if (res != WIFI_DIRECT_ERROR_NONE) {
185 res = wifi_direct_deactivate();
186 if (res != WIFI_DIRECT_ERROR_NONE) {
187 WFD_APP_LOG(WFD_APP_LOG_ERROR, "Failed to deactivate Wi-Fi Direct. error code = [%d]\n", res);
195 #ifdef WFD_FIVE_MIN_IDLE_DEACTIVATION
197 * This function let the ug make a callback for deactivating wfd automatically
198 * @return if stop the timer, return ECORE_CALLBACK_CANCEL, else return ECORE_CALLBACK_RENEW
199 * @param[in] user_data the pointer to the main data structure
201 static Eina_Bool _wfd_automatic_deactivated_for_no_connection_cb(void *user_data)
205 wfd_appdata_t *ad = (wfd_appdata_t *)user_data;
206 #ifdef WFD_SCREEN_MIRRORING_ENABLED
207 int screen_mirroring_status = 0;
211 return ECORE_CALLBACK_CANCEL;
214 /* check the action, if action is exist, keep the cb */
215 res = wifi_direct_get_state(&ad->wfd_status);
216 if (res != WIFI_DIRECT_ERROR_NONE) {
217 WFD_APP_LOG(WFD_APP_LOG_ERROR, "Get wifi-direct status WIFI_DIRECT_ERROR_NONE!\n");
218 return ECORE_CALLBACK_CANCEL;
221 if (ad->last_wfd_status != ad->wfd_status) {
222 ad->last_wfd_status = ad->wfd_status;
223 ad->last_wfd_time = time(NULL);
224 return ECORE_CALLBACK_RENEW;
227 /* check the timeout, if not timeout, keep the cb */
228 interval = time(NULL) - ad->last_wfd_time;
229 if (interval < MAX_NO_ACTION_TIME_OUT) {
230 return ECORE_CALLBACK_RENEW;
233 /* turn off the Wi-Fi Direct */
234 wifi_direct_get_state(&ad->wfd_status);
235 if (ad->wfd_status < WIFI_DIRECT_STATE_ACTIVATING) {
236 WFD_APP_LOG(WFD_APP_LOG_LOW, "wfd_status < WIFI_DIRECT_STATE_ACTIVATING!\n");
238 #ifdef WFD_SCREEN_MIRRORING_ENABLED
239 if (vconf_get_int(VCONFKEY_SCREEN_MIRRORING_STATE, &screen_mirroring_status) < 0)
241 WFD_APP_LOG(WFD_APP_LOG_ERROR, "Failed to get vconf VCONFKEY_SCREEN_MIRRORING_STATE\n");
244 if (screen_mirroring_status == VCONFKEY_SCREEN_MIRRORING_ACTIVATED) {
245 ad->last_wfd_time = time(NULL);
246 return ECORE_CALLBACK_RENEW;
248 /* turn off the Wi-Fi Direct */
249 wfd_app_client_switch_off(ad);
250 ad->popup = wfd_draw_pop_type_auto_deactivation(ad->win, user_data);
255 /* reset monitor timer */
256 if (ad->monitor_timer) {
257 ad->monitor_timer = NULL; //ECORE_CALLBACK_CANCEL will release timer.
260 return ECORE_CALLBACK_CANCEL;
265 * This function let the app make a callback for registering activation event
267 * @param[in] error_code the returned error code
268 * @param[in] device_state the state of device
269 * @param[in] user_data the pointer to the main data structure
271 void _cb_activation(int error_code, wifi_direct_device_state_e device_state, void *user_data)
273 __WFD_APP_FUNC_ENTER__;
274 wfd_appdata_t *ad = (wfd_appdata_t *)user_data;
276 switch (device_state) {
277 case WIFI_DIRECT_DEVICE_STATE_ACTIVATED:
279 WFD_APP_LOG(WFD_APP_LOG_ERROR, "---------------WIFI_DIRECT_DEVICE_STATE_ACTIVATED\n");
280 #ifdef NOT_CONNECTED_INDICATOR_ICON
281 wfd_app_util_add_indicator_icon(ad);
283 #ifdef WFD_FIVE_MIN_IDLE_DEACTIVATION
284 if (NULL == ad->monitor_timer) {
285 ad->last_wfd_time = time(NULL);
286 ad->monitor_timer = ecore_timer_add(5.0,
287 (Ecore_Task_Cb)_wfd_automatic_deactivated_for_no_connection_cb, ad);
293 case WIFI_DIRECT_DEVICE_STATE_DEACTIVATED:
295 WFD_APP_LOG(WFD_APP_LOG_ERROR, "---------------WIFI_DIRECT_DEVICE_STATE_DEACTIVATED\n");
296 /* when deactivated, stop the timer */
297 if (ad->transmit_timer) {
298 ecore_timer_del(ad->transmit_timer);
299 ad->transmit_timer = NULL;
302 #ifdef WFD_FIVE_MIN_IDLE_DEACTIVATION
303 /* when deactivated, stop the timer */
304 if (ad->monitor_timer) {
305 ecore_timer_del(ad->monitor_timer);
306 ad->monitor_timer = NULL;
309 wfd_app_util_del_notification(ad);
310 #ifdef WFD_SCREEN_MIRRORING_ENABLED
311 wfd_app_util_set_screen_mirroring_deactivated(ad);
320 __WFD_APP_FUNC_EXIT__;
324 * This function let the app make a callback for registering connection event
326 * @param[in] error_code the returned error code
327 * @param[in] connection_state the state of connection
328 * @param[in] mac_address the mac address of peer
329 * @param[in] user_data the pointer to the main data structure
331 void _cb_connection(int error_code, wifi_direct_connection_state_e connection_state, const char *mac_address, void *user_data)
333 __WFD_APP_FUNC_ENTER__;
335 wfd_appdata_t *ad = (wfd_appdata_t *)user_data;
338 #ifdef WFD_SCREEN_MIRRORING_ENABLED
339 int screen_mirroring_status = 0;
341 wifi_direct_discovered_peer_info_s *peer_info = NULL;
342 wfd_connection_info_s *connection = ad->connection;
343 #ifdef NOT_CONNECTED_INDICATOR_ICON
344 notification_error_e noti_err = NOTIFICATION_ERROR_NONE;
346 char popup_text[MAX_POPUP_TEXT_SIZE] = {0, };
348 /* find the peer's name by the mac address */
349 WFD_RET_IF(NULL == mac_address, "ERROR : mac address is NULL !!\n");
351 WFD_APP_LOG(WFD_APP_LOG_ERROR, "-------------------error_code:%d connection_state:%d \n",
352 error_code, connection_state);
354 /* when disconnection, mac_address is empty */
355 if (connection_state <= WIFI_DIRECT_DISASSOCIATION_IND) {
357 result = strncmp(connection->peer_addr, mac_address, MACSTR_LENGTH);
359 WFD_APP_LOG(WFD_APP_LOG_ERROR, "Connection event from unknown peer");
363 result = wifi_direct_get_peer_info((char *)mac_address, &peer_info);
364 if (result < 0 || !peer_info) {
365 WFD_APP_LOG(WFD_APP_LOG_ERROR, "Unknown peer");
366 if (NULL != peer_info)
371 connection = (wfd_connection_info_s*) calloc(1, sizeof(wfd_connection_info_s));
373 WFD_APP_LOG(WFD_APP_LOG_ERROR, "Failed to allocate memory for peer");
378 if (TRUE != dbus_validate_utf8(peer_info->device_name, NULL)) {
379 memcpy(connection->peer_name, peer_info->device_name, DEV_NAME_LENGTH-2);
380 connection->peer_name[DEV_NAME_LENGTH-2] = '\0';
382 memcpy(connection->peer_name, peer_info->device_name, DEV_NAME_LENGTH);
383 connection->peer_name[DEV_NAME_LENGTH] = '\0';
386 strncpy(connection->peer_addr, mac_address, MACSTR_LENGTH);
387 connection->peer_addr[MACSTR_LENGTH] = '\0';
388 connection->device_type = peer_info->primary_device_type;
389 connection->wifi_display = peer_info->is_miracast_device;
390 wifi_direct_get_local_wps_type(&connection->wps_type);
391 wifi_direct_is_autoconnection_mode(&connection->auto_conn);
393 ad->connection = connection;
398 switch (connection_state) {
399 case WIFI_DIRECT_CONNECTION_REQ:
401 WFD_APP_LOG(WFD_APP_LOG_LOW, "event ------------------ WIFI_DIRECT_CONNECTION_REQ\n");
403 memcpy((char*)ad->mac_addr_connecting, connection->peer_addr, MACSTR_LENGTH);
405 wfd_app_get_connected_peers(ad);
406 WFD_APP_LOG(WFD_APP_LOG_LOW, "No of connected peers = %d", ad->raw_connected_peer_cnt);
407 if (ad->raw_connected_peer_cnt >= WFD_MAX_CONNECTED_PEER) {
408 result = wifi_direct_reject_connection(connection->peer_addr);
409 if (result != WIFI_DIRECT_ERROR_NONE)
410 WFD_APP_LOG(WFD_APP_LOG_ERROR, "Failed to reject connection(%d)", result);
411 snprintf(popup_text, MAX_POPUP_TEXT_SIZE,
412 _("IDS_ST_POP_YOU_CAN_CONNECT_UP_TO_PD_DEVICES_AT_THE_SAME_TIME"),
413 WFD_MAX_CONNECTED_PEER);
414 notification_status_message_post(popup_text);
418 if (connection->auto_conn) {
420 result = wifi_direct_accept_connection(connection->peer_addr);
422 WFD_APP_LOG(WFD_APP_LOG_ERROR, "Failed to accept connection");
425 WFD_APP_LOG(WFD_APP_LOG_HIGH, "Succeeded to accept connection");
427 if (connection->wps_type == WIFI_DIRECT_WPS_TYPE_PBC) {
428 WFD_APP_LOG(WFD_APP_LOG_LOW, "WPS type: WIFI_DIRECT_WPS_TYPE_PBC\n");
429 wfd_prepare_popup(WFD_POP_APRV_CONNECTION_WPS_PUSHBUTTON_REQ, NULL);
430 } else if (connection->wps_type == WIFI_DIRECT_WPS_TYPE_PIN_DISPLAY) {
432 WFD_APP_LOG(WFD_APP_LOG_LOW, "WPS type: WIFI_DIRECT_WPS_TYPE_PIN_DISPLAY");
433 if (wifi_direct_get_wps_pin(&pin) != WIFI_DIRECT_ERROR_NONE) {
434 WFD_APP_LOG(WFD_APP_LOG_ERROR, "Failed to get WPS pin");
437 strncpy(connection->wps_pin, pin, PIN_LENGTH);
438 WFD_IF_FREE_MEM(pin);
439 wfd_prepare_popup(WFD_POP_APRV_CONNECTION_WPS_DISPLAY_REQ, NULL);
440 } else if (connection->wps_type == WIFI_DIRECT_WPS_TYPE_PIN_KEYPAD) {
441 WFD_APP_LOG(WFD_APP_LOG_LOW, "WPS type: WIFI_DIRECT_WPS_TYPE_PIN_KEYPAD");
442 wfd_prepare_popup(WFD_POP_APRV_CONNECTION_WPS_KEYPAD_REQ, NULL);
444 WFD_APP_LOG(WFD_APP_LOG_ERROR, "wps_config is unkown!\n");
447 int res = display_change_state(LCD_NORMAL);
449 WFD_APP_LOG(WFD_APP_LOG_ERROR, "Failed to change PM state(%d)", res);
454 case WIFI_DIRECT_CONNECTION_WPS_REQ:
456 WFD_APP_LOG(WFD_APP_LOG_LOW, "event ------------------ WIFI_DIRECT_CONNECTION_WPS_REQ\n");
457 if (connection->wps_type == WIFI_DIRECT_WPS_TYPE_PIN_KEYPAD) {
458 WFD_APP_LOG(WFD_APP_LOG_LOW, "WPS type: WIFI_DIRECT_WPS_TYPE_PIN_KEYPAD\n");
459 wfd_prepare_popup(WFD_POP_PROG_CONNECT_WITH_KEYPAD, NULL);
460 } else if (connection->wps_type == WIFI_DIRECT_WPS_TYPE_PIN_DISPLAY) {
462 WFD_APP_LOG(WFD_APP_LOG_LOW, "WPS type: WIFI_DIRECT_WPS_TYPE_PIN_DISPLAY\n");
464 if (wifi_direct_get_wps_pin(&pin) != WIFI_DIRECT_ERROR_NONE) {
465 WFD_APP_LOG(WFD_APP_LOG_ERROR, "Failed to get WPS pin");
469 strncpy(connection->wps_pin, pin, PIN_LENGTH);
470 WFD_IF_FREE_MEM(pin);
472 wfd_prepare_popup(WFD_POP_PROG_CONNECT_WITH_PIN, NULL);
474 WFD_APP_LOG(WFD_APP_LOG_ERROR, "WPS type: %d", connection->wps_type);
479 case WIFI_DIRECT_CONNECTION_IN_PROGRESS:
481 WFD_APP_LOG(WFD_APP_LOG_LOW, "event ------------------ WIFI_DIRECT_CONNECTION_IN_PROGRESS\n");
485 case WIFI_DIRECT_CONNECTION_RSP:
488 char txt[WFD_POP_STR_MAX_LEN] = {0};
491 memset(ad->mac_addr_connecting, 0x00, MACSTR_LENGTH);
493 if (error_code != WIFI_DIRECT_ERROR_NONE) {
494 WFD_APP_LOG(WFD_APP_LOG_ERROR, "Failed to connect with peer[%s] -(%d)",
495 connection->peer_name, error_code);
496 snprintf(txt, WFD_POP_STR_MAX_LEN, _("IDS_WIFI_POP_FAILED_TO_CONNECT_TO_PS"),
497 connection->peer_name);
499 WFD_APP_LOG(WFD_APP_LOG_LOW, "Succeeded to connect with peer[%s] -(%d)",
500 connection->peer_name, error_code);
501 snprintf(txt, WFD_POP_STR_MAX_LEN, _("IDS_WIFI_BODY_CONNECTED_TO_PS"),
502 connection->peer_name);
503 #ifdef WFD_SCREEN_MIRRORING_ENABLED
504 result = vconf_get_int(VCONFKEY_SCREEN_MIRRORING_STATE, &screen_mirroring_status);
506 WFD_APP_LOG(WFD_APP_LOG_ERROR, "Failed to get VCONFKEY_SCREEN_MIRRORING_STATE");
508 if (screen_mirroring_status == VCONFKEY_SCREEN_MIRRORING_DEACTIVATED)
509 snprintf(txt, WFD_POP_STR_MAX_LEN, _("IDS_WIFI_BODY_CONNECTED_TO_PS"),
510 connection->peer_name);
514 free(ad->connection);
515 ad->connection = NULL;
517 wfd_app_get_connected_peers(ad);
518 WFD_APP_LOG(WFD_APP_LOG_LOW, "No of connected peers = %d", ad->raw_connected_peer_cnt);
519 /* tickernoti popup */
520 if (ad->raw_connected_peer_cnt < WFD_MAX_CONNECTED_PEER) {
521 if (strlen(txt) > 0) {
522 msg = elm_entry_utf8_to_markup(txt);
523 WFD_RET_IF(!msg, "Failed to elm_entry_markup_to_utf8()!");
524 notification_status_message_post(msg);
525 WFD_IF_FREE_MEM(msg);
531 case WIFI_DIRECT_DISASSOCIATION_IND:
533 WFD_APP_LOG(WFD_APP_LOG_LOW, "event ------------------ WIFI_DIRECT_DISASSOCIATION_IND\n");
534 wfd_app_util_del_wfd_connected_notification(ad);
536 #ifdef WFD_SCREEN_MIRRORING_ENABLED
537 if (connection && connection->wifi_display)
538 wfd_app_util_set_screen_mirroring_deactivated(ad);
541 free(ad->connection);
542 ad->connection = NULL;
547 case WIFI_DIRECT_DISCONNECTION_IND:
549 #if 0 // changed to show notification only when allshare cast device is connected.
550 _del_wfd_notification();
552 WFD_APP_LOG(WFD_APP_LOG_LOW, "event ------------------ WIFI_DIRECT_DISCONNECTION_IND\n");
553 #ifdef WFD_SCREEN_MIRRORING_ENABLED
554 wfd_app_util_set_screen_mirroring_deactivated(ad);
556 notification_status_message_post(_("IDS_WIFI_BODY_THE_WI_FI_DIRECT_CONNECTION_HAS_BEEN_LOST"));
557 wfd_app_util_del_wfd_connected_notification(ad);
561 case WIFI_DIRECT_DISCONNECTION_RSP:
563 #if 0 // changed to show notification only when allshare cast device is connected.
564 _del_wfd_notification();
566 WFD_APP_LOG(WFD_APP_LOG_LOW, "event ------------------ WIFI_DIRECT_DISCONNECTION_RSP\n");
568 wfd_app_util_del_wfd_connected_notification(ad);
570 #ifdef WFD_SCREEN_MIRRORING_ENABLED
571 wfd_app_util_set_screen_mirroring_deactivated(ad);
575 result = wifi_direct_set_autoconnection_mode(false);
576 WFD_APP_LOG(WFD_APP_LOG_LOW, "wifi_direct_set_autoconnection_mode() result=[%d]\n", result);
580 case WIFI_DIRECT_GROUP_DESTROYED:
582 WFD_APP_LOG(WFD_APP_LOG_LOW, "event ------------------ WIFI_DIRECT_GROUP_DESTROYED\n");
583 notification_status_message_post(_("IDS_WIFI_BODY_THE_WI_FI_DIRECT_CONNECTION_HAS_BEEN_LOST"));
593 * To support ON DEMAND popup destroy. API request blocks and popup destroy
596 /* wifi_direct_get_state(&ad->wfd_status); */
598 if (vconf_get_int(VCONFKEY_WIFI_DIRECT_STATE, &wfd_state) < 0) {
599 WFD_APP_LOG(WFD_APP_LOG_ERROR, "Error reading vconf (%s)\n", VCONFKEY_WIFI_DIRECT_STATE);
601 WFD_APP_LOG(WFD_APP_LOG_LOW, "wfd state: %d", wfd_state);
603 if (wfd_state == VCONFKEY_WIFI_DIRECT_DEACTIVATED) {
604 wfd_app_util_del_notification(ad);
607 #ifdef NOT_CONNECTED_INDICATOR_ICON
608 if (wfd_state >= VCONFKEY_WIFI_DIRECT_CONNECTED) {
609 noti_err = notification_delete(ad->noti_wifi_direct_on);
610 if (noti_err != NOTIFICATION_ERROR_NONE) {
611 WFD_APP_LOG(WFD_APP_LOG_ERROR, "Fail to notification_delete.(%d)\n", noti_err);
613 noti_err = notification_free(ad->noti_wifi_direct_on);
614 ad->noti_wifi_direct_on = NULL;
615 if (noti_err != NOTIFICATION_ERROR_NONE) {
616 WFD_APP_LOG(WFD_APP_LOG_ERROR, "Fail to notification_free.(%d)\n", noti_err);
622 if (wfd_state < VCONFKEY_WIFI_DIRECT_CONNECTED) {
623 if (ad->transmit_timer) {
624 ecore_timer_del(ad->transmit_timer);
625 ad->transmit_timer = NULL;
628 if (NULL == ad->transmit_timer) {
629 WFD_APP_LOG(WFD_APP_LOG_LOW, "start the transmit timer\n");
630 ad->last_wfd_transmit_time = time(NULL);
631 ad->transmit_timer = ecore_timer_add(5.0,
632 (Ecore_Task_Cb)wfd_automatic_deactivated_for_connection_cb, ad);
636 if (wfd_state >= VCONFKEY_WIFI_DIRECT_CONNECTED) {
637 #ifdef WFD_FIVE_MIN_IDLE_DEACTIVATION
638 if (ad->monitor_timer) {
639 ecore_timer_del(ad->monitor_timer);
640 ad->monitor_timer = NULL;
644 #ifdef NOT_CONNECTED_INDICATOR_ICON
645 wfd_app_util_add_indicator_icon(ad);
647 #ifdef WFD_FIVE_MIN_IDLE_DEACTIVATION
648 if (NULL == ad->monitor_timer) {
649 ad->last_wfd_time = time(NULL);
650 ad->monitor_timer = ecore_timer_add(5.0,
651 (Ecore_Task_Cb)_wfd_automatic_deactivated_for_no_connection_cb, ad);
656 __WFD_APP_FUNC_EXIT__;
660 * This function let the app do initialization
661 * @return If success, return TRUE, else return FALSE
662 * @param[in] ad the pointer to the main data structure
664 bool init_wfd_client(wfd_appdata_t *ad)
666 __WFD_APP_FUNC_ENTER__;
667 WFD_RETV_IF(NULL == ad, FALSE, "NULL parameters.\n");
671 ad->last_wfd_status = WIFI_DIRECT_STATE_DEACTIVATED;
674 ret = wifi_direct_initialize();
675 if (ret == WIFI_DIRECT_ERROR_NONE ||
676 ret == WIFI_DIRECT_ERROR_ALREADY_INITIALIZED)
678 WFD_APP_LOG(WFD_APP_LOG_ERROR, "Failed to initialize Wi-Fi Direct(%d)\n", ret);
686 ret = wifi_direct_set_device_state_changed_cb(_cb_activation, (void*) ad);
687 if (ret != WIFI_DIRECT_ERROR_NONE) {
688 WFD_APP_LOG(WFD_APP_LOG_ERROR, "Failed to register _cb_activation(%d)\n", ret);
692 ret = wifi_direct_set_connection_state_changed_cb(_cb_connection, (void*) ad);
693 if (ret != WIFI_DIRECT_ERROR_NONE) {
694 WFD_APP_LOG(WFD_APP_LOG_ERROR, "Failed to register _cb_connection(%d)\n", ret);
698 #ifdef WFD_FIVE_MIN_IDLE_DEACTIVATION
699 if (NULL == ad->monitor_timer) {
700 ad->last_wfd_time = time(NULL);
701 ad->monitor_timer = ecore_timer_add(5.0,
702 (Ecore_Task_Cb)_wfd_automatic_deactivated_for_no_connection_cb, ad);
705 __WFD_APP_FUNC_EXIT__;
710 * This function let the app do de-initialization
711 * @return If success, return TRUE, else return FALSE
712 * @param[in] ad the pointer to the main data structure
714 int deinit_wfd_client(wfd_appdata_t *ad)
716 __WFD_APP_FUNC_ENTER__;
720 WFD_APP_LOG(WFD_APP_LOG_LOW, "NULL parameter\n");
724 #ifdef WFD_FIVE_MIN_IDLE_DEACTIVATION
725 if (ad->monitor_timer) {
726 ecore_timer_del(ad->monitor_timer);
727 ad->monitor_timer = NULL;
731 ret = wifi_direct_unset_device_state_changed_cb();
732 if (ret != WIFI_DIRECT_ERROR_NONE) {
733 WFD_APP_LOG(WFD_APP_LOG_ERROR, "Failed to deregister _cb_activation(%d)\n", ret);
736 ret = wifi_direct_unset_connection_state_changed_cb();
737 if (ret != WIFI_DIRECT_ERROR_NONE) {
738 WFD_APP_LOG(WFD_APP_LOG_ERROR, "Failed to deregister _cb_connection(%d)\n", ret);
741 ret = wifi_direct_deinitialize();
742 if (ret != WIFI_DIRECT_ERROR_NONE) {
743 WFD_APP_LOG(WFD_APP_LOG_ERROR, "Failed to deinitialize Wi-Fi Direct. error code = [%d]\n", ret);
746 __WFD_APP_FUNC_EXIT__;