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) {
419 result = wifi_direct_accept_connection(connection->peer_addr);
421 WFD_APP_LOG(WFD_APP_LOG_ERROR, "Failed to accept connection");
424 WFD_APP_LOG(WFD_APP_LOG_HIGH, "Succeeded to accept connection");
426 if (connection->wps_type == WIFI_DIRECT_WPS_TYPE_PBC) {
427 WFD_APP_LOG(WFD_APP_LOG_LOW, "WPS type: WIFI_DIRECT_WPS_TYPE_PBC\n");
428 wfd_prepare_popup(WFD_POP_APRV_CONNECTION_WPS_PUSHBUTTON_REQ, NULL);
429 } else if (connection->wps_type == WIFI_DIRECT_WPS_TYPE_PIN_DISPLAY) {
431 WFD_APP_LOG(WFD_APP_LOG_LOW, "WPS type: WIFI_DIRECT_WPS_TYPE_PIN_DISPLAY");
432 if (wifi_direct_get_wps_pin(&pin) != WIFI_DIRECT_ERROR_NONE) {
433 WFD_APP_LOG(WFD_APP_LOG_ERROR, "Failed to get WPS pin");
436 strncpy(connection->wps_pin, pin, PIN_LENGTH);
437 WFD_IF_FREE_MEM(pin);
438 wfd_prepare_popup(WFD_POP_APRV_CONNECTION_WPS_DISPLAY_REQ, NULL);
439 } else if (connection->wps_type == WIFI_DIRECT_WPS_TYPE_PIN_KEYPAD) {
440 WFD_APP_LOG(WFD_APP_LOG_LOW, "WPS type: WIFI_DIRECT_WPS_TYPE_PIN_KEYPAD");
441 wfd_prepare_popup(WFD_POP_APRV_CONNECTION_WPS_KEYPAD_REQ, NULL);
443 WFD_APP_LOG(WFD_APP_LOG_ERROR, "wps_config is unkown!\n");
446 int res = display_change_state(LCD_NORMAL);
448 WFD_APP_LOG(WFD_APP_LOG_ERROR, "Failed to change PM state(%d)", res);
453 case WIFI_DIRECT_CONNECTION_WPS_REQ:
455 WFD_APP_LOG(WFD_APP_LOG_LOW, "event ------------------ WIFI_DIRECT_CONNECTION_WPS_REQ\n");
456 if (connection->wps_type == WIFI_DIRECT_WPS_TYPE_PIN_KEYPAD) {
457 WFD_APP_LOG(WFD_APP_LOG_LOW, "WPS type: WIFI_DIRECT_WPS_TYPE_PIN_KEYPAD\n");
458 wfd_prepare_popup(WFD_POP_PROG_CONNECT_WITH_KEYPAD, NULL);
459 } else if (connection->wps_type == WIFI_DIRECT_WPS_TYPE_PIN_DISPLAY) {
461 WFD_APP_LOG(WFD_APP_LOG_LOW, "WPS type: WIFI_DIRECT_WPS_TYPE_PIN_DISPLAY\n");
463 if (wifi_direct_get_wps_pin(&pin) != WIFI_DIRECT_ERROR_NONE) {
464 WFD_APP_LOG(WFD_APP_LOG_ERROR, "Failed to get WPS pin");
468 strncpy(connection->wps_pin, pin, PIN_LENGTH);
469 WFD_IF_FREE_MEM(pin);
471 wfd_prepare_popup(WFD_POP_PROG_CONNECT_WITH_PIN, NULL);
473 WFD_APP_LOG(WFD_APP_LOG_ERROR, "WPS type: %d", connection->wps_type);
478 case WIFI_DIRECT_CONNECTION_IN_PROGRESS:
480 WFD_APP_LOG(WFD_APP_LOG_LOW, "event ------------------ WIFI_DIRECT_CONNECTION_IN_PROGRESS\n");
484 case WIFI_DIRECT_CONNECTION_RSP:
487 char txt[WFD_POP_STR_MAX_LEN] = {0};
490 memset(ad->mac_addr_connecting, 0x00, MACSTR_LENGTH);
492 if (error_code != WIFI_DIRECT_ERROR_NONE) {
493 WFD_APP_LOG(WFD_APP_LOG_ERROR, "Failed to connect with peer[%s] -(%d)",
494 connection->peer_name, error_code);
495 snprintf(txt, WFD_POP_STR_MAX_LEN, _("IDS_WIFI_POP_FAILED_TO_CONNECT_TO_PS"),
496 connection->peer_name);
498 WFD_APP_LOG(WFD_APP_LOG_LOW, "Succeeded to connect with peer[%s] -(%d)",
499 connection->peer_name, error_code);
500 snprintf(txt, WFD_POP_STR_MAX_LEN, _("IDS_WIFI_BODY_CONNECTED_TO_PS"),
501 connection->peer_name);
502 #ifdef WFD_SCREEN_MIRRORING_ENABLED
503 result = vconf_get_int(VCONFKEY_SCREEN_MIRRORING_STATE, &screen_mirroring_status);
505 WFD_APP_LOG(WFD_APP_LOG_ERROR, "Failed to get VCONFKEY_SCREEN_MIRRORING_STATE");
507 if (screen_mirroring_status == VCONFKEY_SCREEN_MIRRORING_DEACTIVATED)
508 snprintf(txt, WFD_POP_STR_MAX_LEN, _("IDS_WIFI_BODY_CONNECTED_TO_PS"),
509 connection->peer_name);
513 free(ad->connection);
514 ad->connection = NULL;
516 wfd_app_get_connected_peers(ad);
517 WFD_APP_LOG(WFD_APP_LOG_LOW, "No of connected peers = %d", ad->raw_connected_peer_cnt);
518 /* tickernoti popup */
519 if (ad->raw_connected_peer_cnt < WFD_MAX_CONNECTED_PEER) {
520 if (strlen(txt) > 0) {
521 msg = elm_entry_utf8_to_markup(txt);
522 WFD_RET_IF(!msg, "Failed to elm_entry_markup_to_utf8()!");
523 notification_status_message_post(msg);
524 WFD_IF_FREE_MEM(msg);
530 case WIFI_DIRECT_DISASSOCIATION_IND:
532 WFD_APP_LOG(WFD_APP_LOG_LOW, "event ------------------ WIFI_DIRECT_DISASSOCIATION_IND\n");
533 wfd_app_util_del_wfd_connected_notification(ad);
535 #ifdef WFD_SCREEN_MIRRORING_ENABLED
536 if (connection && connection->wifi_display)
537 wfd_app_util_set_screen_mirroring_deactivated(ad);
540 free(ad->connection);
541 ad->connection = NULL;
546 case WIFI_DIRECT_DISCONNECTION_IND:
548 #if 0 // changed to show notification only when allshare cast device is connected.
549 _del_wfd_notification();
551 WFD_APP_LOG(WFD_APP_LOG_LOW, "event ------------------ WIFI_DIRECT_DISCONNECTION_IND\n");
552 #ifdef WFD_SCREEN_MIRRORING_ENABLED
553 wfd_app_util_set_screen_mirroring_deactivated(ad);
555 notification_status_message_post(_("IDS_WIFI_BODY_THE_WI_FI_DIRECT_CONNECTION_HAS_BEEN_LOST"));
556 wfd_app_util_del_wfd_connected_notification(ad);
560 case WIFI_DIRECT_DISCONNECTION_RSP:
562 #if 0 // changed to show notification only when allshare cast device is connected.
563 _del_wfd_notification();
565 WFD_APP_LOG(WFD_APP_LOG_LOW, "event ------------------ WIFI_DIRECT_DISCONNECTION_RSP\n");
567 wfd_app_util_del_wfd_connected_notification(ad);
569 #ifdef WFD_SCREEN_MIRRORING_ENABLED
570 wfd_app_util_set_screen_mirroring_deactivated(ad);
574 result = wifi_direct_set_autoconnection_mode(false);
575 WFD_APP_LOG(WFD_APP_LOG_LOW, "wifi_direct_set_autoconnection_mode() result=[%d]\n", result);
579 case WIFI_DIRECT_GROUP_DESTROYED:
581 WFD_APP_LOG(WFD_APP_LOG_LOW, "event ------------------ WIFI_DIRECT_GROUP_DESTROYED\n");
582 notification_status_message_post(_("IDS_WIFI_BODY_THE_WI_FI_DIRECT_CONNECTION_HAS_BEEN_LOST"));
592 * To support ON DEMAND popup destroy. API request blocks and popup destroy
595 /* wifi_direct_get_state(&ad->wfd_status); */
597 if (vconf_get_int(VCONFKEY_WIFI_DIRECT_STATE, &wfd_state) < 0) {
598 WFD_APP_LOG(WFD_APP_LOG_ERROR, "Error reading vconf (%s)\n", VCONFKEY_WIFI_DIRECT_STATE);
600 WFD_APP_LOG(WFD_APP_LOG_LOW, "wfd state: %d", wfd_state);
602 if (wfd_state == VCONFKEY_WIFI_DIRECT_DEACTIVATED) {
603 wfd_app_util_del_notification(ad);
606 #ifdef NOT_CONNECTED_INDICATOR_ICON
607 if (wfd_state >= VCONFKEY_WIFI_DIRECT_CONNECTED) {
608 noti_err = notification_delete(ad->noti_wifi_direct_on);
609 if (noti_err != NOTIFICATION_ERROR_NONE) {
610 WFD_APP_LOG(WFD_APP_LOG_ERROR, "Fail to notification_delete.(%d)\n", noti_err);
612 noti_err = notification_free(ad->noti_wifi_direct_on);
613 ad->noti_wifi_direct_on = NULL;
614 if (noti_err != NOTIFICATION_ERROR_NONE) {
615 WFD_APP_LOG(WFD_APP_LOG_ERROR, "Fail to notification_free.(%d)\n", noti_err);
621 if (wfd_state < VCONFKEY_WIFI_DIRECT_CONNECTED) {
622 if (ad->transmit_timer) {
623 ecore_timer_del(ad->transmit_timer);
624 ad->transmit_timer = NULL;
627 if (NULL == ad->transmit_timer) {
628 WFD_APP_LOG(WFD_APP_LOG_LOW, "start the transmit timer\n");
629 ad->last_wfd_transmit_time = time(NULL);
630 ad->transmit_timer = ecore_timer_add(5.0,
631 (Ecore_Task_Cb)wfd_automatic_deactivated_for_connection_cb, ad);
635 if (wfd_state >= VCONFKEY_WIFI_DIRECT_CONNECTED) {
636 #ifdef WFD_FIVE_MIN_IDLE_DEACTIVATION
637 if (ad->monitor_timer) {
638 ecore_timer_del(ad->monitor_timer);
639 ad->monitor_timer = NULL;
643 #ifdef NOT_CONNECTED_INDICATOR_ICON
644 wfd_app_util_add_indicator_icon(ad);
646 #ifdef WFD_FIVE_MIN_IDLE_DEACTIVATION
647 if (NULL == ad->monitor_timer) {
648 ad->last_wfd_time = time(NULL);
649 ad->monitor_timer = ecore_timer_add(5.0,
650 (Ecore_Task_Cb)_wfd_automatic_deactivated_for_no_connection_cb, ad);
655 __WFD_APP_FUNC_EXIT__;
659 * This function let the app do initialization
660 * @return If success, return TRUE, else return FALSE
661 * @param[in] ad the pointer to the main data structure
663 bool init_wfd_client(wfd_appdata_t *ad)
665 __WFD_APP_FUNC_ENTER__;
666 WFD_RETV_IF(NULL == ad, FALSE, "NULL parameters.\n");
670 ad->last_wfd_status = WIFI_DIRECT_STATE_DEACTIVATED;
673 ret = wifi_direct_initialize();
674 if (ret == WIFI_DIRECT_ERROR_NONE ||
675 ret == WIFI_DIRECT_ERROR_ALREADY_INITIALIZED)
677 WFD_APP_LOG(WFD_APP_LOG_ERROR, "Failed to initialize Wi-Fi Direct(%d)\n", ret);
685 ret = wifi_direct_set_device_state_changed_cb(_cb_activation, (void*) ad);
686 if (ret != WIFI_DIRECT_ERROR_NONE) {
687 WFD_APP_LOG(WFD_APP_LOG_ERROR, "Failed to register _cb_activation(%d)\n", ret);
691 ret = wifi_direct_set_connection_state_changed_cb(_cb_connection, (void*) ad);
692 if (ret != WIFI_DIRECT_ERROR_NONE) {
693 WFD_APP_LOG(WFD_APP_LOG_ERROR, "Failed to register _cb_connection(%d)\n", ret);
697 #ifdef WFD_FIVE_MIN_IDLE_DEACTIVATION
698 if (NULL == ad->monitor_timer) {
699 ad->last_wfd_time = time(NULL);
700 ad->monitor_timer = ecore_timer_add(5.0,
701 (Ecore_Task_Cb)_wfd_automatic_deactivated_for_no_connection_cb, ad);
704 __WFD_APP_FUNC_EXIT__;
709 * This function let the app do de-initialization
710 * @return If success, return TRUE, else return FALSE
711 * @param[in] ad the pointer to the main data structure
713 int deinit_wfd_client(wfd_appdata_t *ad)
715 __WFD_APP_FUNC_ENTER__;
719 WFD_APP_LOG(WFD_APP_LOG_LOW, "NULL parameter\n");
723 #ifdef WFD_FIVE_MIN_IDLE_DEACTIVATION
724 if (ad->monitor_timer) {
725 ecore_timer_del(ad->monitor_timer);
726 ad->monitor_timer = NULL;
730 ret = wifi_direct_unset_device_state_changed_cb();
731 if (ret != WIFI_DIRECT_ERROR_NONE) {
732 WFD_APP_LOG(WFD_APP_LOG_ERROR, "Failed to deregister _cb_activation(%d)\n", ret);
735 ret = wifi_direct_unset_connection_state_changed_cb();
736 if (ret != WIFI_DIRECT_ERROR_NONE) {
737 WFD_APP_LOG(WFD_APP_LOG_ERROR, "Failed to deregister _cb_connection(%d)\n", ret);
740 ret = wifi_direct_deinitialize();
741 if (ret != WIFI_DIRECT_ERROR_NONE) {
742 WFD_APP_LOG(WFD_APP_LOG_ERROR, "Failed to deinitialize Wi-Fi Direct. error code = [%d]\n", ret);
745 __WFD_APP_FUNC_EXIT__;