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>
42 #include <dbus/dbus.h>
45 #include "wfd-app-util.h"
46 #include "wfd-app-strings.h"
47 #include "wfd-app-popup-view.h"
50 * This function let the app make a callback for connected peer
52 * @param[in] peer the pointer to the connected peer
53 * @param[in] user_data the pointer to the main data structure
55 bool _wfd_connected_peer_cb(wifi_direct_connected_peer_info_s *peer, void *user_data)
57 __WFD_APP_FUNC_ENTER__;
59 wfd_appdata_t *ad = (wfd_appdata_t *) user_data;
61 if (NULL == ad || NULL == peer || NULL == peer->device_name || NULL == peer->mac_address) {
62 WFD_APP_LOG(WFD_APP_LOG_ERROR, "NULL parameters.\n");
66 int peer_cnt = ad->raw_connected_peer_cnt;
67 strncpy(ad->raw_connected_peers[peer_cnt].ssid, peer->device_name, sizeof(ad->raw_connected_peers[peer_cnt].ssid) - 1);
68 strncpy(ad->raw_connected_peers[peer_cnt].mac_address, peer->mac_address, WFD_MAC_ADDRESS_SIZE - 1);
70 ad->raw_connected_peer_cnt++;
72 free(peer->device_name);
73 free(peer->mac_address);
76 __WFD_APP_FUNC_EXIT__;
81 * This function let the app get the connected peers
82 * @return If success, return 0, else return -1
83 * @param[in] ugd the pointer to the main data structure
85 int wfd_app_get_connected_peers(void *user_data)
87 __WFD_APP_FUNC_ENTER__;
89 wfd_appdata_t *ad = (wfd_appdata_t *) user_data;
91 WFD_APP_LOG(WFD_APP_LOG_ERROR, "NULL parameters.\n");
97 ad->raw_connected_peer_cnt = 0;
98 res = wifi_direct_foreach_connected_peers(_wfd_connected_peer_cb, (void *)ad);
99 if (res != WIFI_DIRECT_ERROR_NONE) {
100 ad->raw_connected_peer_cnt = 0;
101 WFD_APP_LOG(WFD_APP_LOG_ERROR, "Get connected peer failed: %d\n", res);
104 __WFD_APP_FUNC_EXIT__;
109 * This function let the app make a callback for deactivating wfd automatically when connected
110 * @return if stop the timer, return ECORE_CALLBACK_CANCEL, else return ECORE_CALLBACK_RENEW
111 * @param[in] user_data the pointer to the main data structure
113 Eina_Bool wfd_automatic_deactivated_for_connection_cb(void *user_data)
115 __WFD_APP_FUNC_ENTER__;
117 int wfd_transfer_state = 0;
119 wfd_appdata_t *ad = (wfd_appdata_t *)user_data;
122 WFD_APP_LOG(WFD_APP_LOG_ERROR, "NULL parameters.\n");
123 return ECORE_CALLBACK_CANCEL;
126 /* check the timeout, if not timeout, keep the cb */
127 interval = time(NULL) - ad->last_wfd_transmit_time;
128 if (interval < NO_ACTION_TIME_OUT) {
129 return ECORE_CALLBACK_RENEW;
132 /* get transfer state */
133 if (vconf_get_int(VCONFKEY_WIFI_DIRECT_TRANSFER_STATE, &wfd_transfer_state) < 0) {
134 WFD_APP_LOG(WFD_APP_LOG_ERROR, "Error reading vconf (%s)\n",
135 VCONFKEY_WIFI_DIRECT_TRANSFER_STATE);
136 return ECORE_CALLBACK_CANCEL;
139 res = wifi_direct_get_state(&ad->wfd_status);
140 if (res != WIFI_DIRECT_ERROR_NONE) {
141 return ECORE_CALLBACK_CANCEL;
144 if (ad->wfd_status < WIFI_DIRECT_STATE_CONNECTED) {
145 WFD_APP_LOG(WFD_APP_LOG_ERROR, "Wi-Fi Direct is unconnected!");
146 return ECORE_CALLBACK_CANCEL;
150 if (wfd_transfer_state > VCONFKEY_WIFI_DIRECT_TRANSFER_START) {
151 WFD_APP_LOG(WFD_APP_LOG_LOW, "Display Toast popup.\n");
152 notification_status_message_post(D_("IDS_WIFI_BODY_TO_SAVE_BATTERY_POWER_DISABLE_WI_FI_DIRECT_AFTER_USE"));
153 WFD_APP_LOG(WFD_APP_LOG_LOW, "No RX/TX packet, turn off WFD automatically.\n");
154 wfd_app_util_add_wfd_turn_off_notification(ad);
156 WFD_APP_LOG(WFD_APP_LOG_LOW, "Has RX/TX packet, restart.\n");
157 ad->last_wfd_transmit_time = time(NULL);
158 return ECORE_CALLBACK_RENEW;
161 ad->transmit_timer = NULL;
162 __WFD_APP_FUNC_EXIT__;
163 return ECORE_CALLBACK_CANCEL;
166 int wfd_app_client_switch_off(void *data)
168 wfd_appdata_t *ad = (wfd_appdata_t *)data;
171 WFD_APP_LOG(WFD_APP_LOG_ERROR, "NULL == ad!\n");
174 res = wifi_direct_get_state(&ad->wfd_status);
175 if (res != WIFI_DIRECT_ERROR_NONE) {
176 return ECORE_CALLBACK_CANCEL;
179 if (ad->wfd_status >= WIFI_DIRECT_STATE_ACTIVATING) {
180 /*if connected, disconnect all devices*/
181 if (WIFI_DIRECT_STATE_CONNECTED == ad->wfd_status) {
182 res = wifi_direct_disconnect_all();
183 if (res != WIFI_DIRECT_ERROR_NONE) {
187 res = wifi_direct_deactivate();
188 if (res != WIFI_DIRECT_ERROR_NONE) {
189 WFD_APP_LOG(WFD_APP_LOG_ERROR, "Failed to deactivate Wi-Fi Direct. error code = [%d]\n", res);
197 #ifdef WFD_FIVE_MIN_IDLE_DEACTIVATION
199 * This function let the ug make a callback for deactivating wfd automatically
200 * @return if stop the timer, return ECORE_CALLBACK_CANCEL, else return ECORE_CALLBACK_RENEW
201 * @param[in] user_data the pointer to the main data structure
203 static Eina_Bool _wfd_automatic_deactivated_for_no_connection_cb(void *user_data)
207 wfd_appdata_t *ad = (wfd_appdata_t *)user_data;
208 #ifdef WFD_SCREEN_MIRRORING_ENABLED
209 int screen_mirroring_status = 0;
213 return ECORE_CALLBACK_CANCEL;
216 /* check the action, if action is exist, keep the cb */
217 res = wifi_direct_get_state(&ad->wfd_status);
218 if (res != WIFI_DIRECT_ERROR_NONE) {
219 WFD_APP_LOG(WFD_APP_LOG_ERROR, "Get wifi-direct status WIFI_DIRECT_ERROR_NONE!\n");
220 return ECORE_CALLBACK_CANCEL;
223 if (ad->last_wfd_status != ad->wfd_status) {
224 ad->last_wfd_status = ad->wfd_status;
225 ad->last_wfd_time = time(NULL);
226 return ECORE_CALLBACK_RENEW;
229 /* check the timeout, if not timeout, keep the cb */
230 interval = time(NULL) - ad->last_wfd_time;
231 if (interval < MAX_NO_ACTION_TIME_OUT) {
232 return ECORE_CALLBACK_RENEW;
235 /* turn off the Wi-Fi Direct */
236 wifi_direct_get_state(&ad->wfd_status);
237 if (ad->wfd_status < WIFI_DIRECT_STATE_ACTIVATING) {
238 WFD_APP_LOG(WFD_APP_LOG_LOW, "wfd_status < WIFI_DIRECT_STATE_ACTIVATING!\n");
240 #ifdef WFD_SCREEN_MIRRORING_ENABLED
241 if (vconf_get_int(VCONFKEY_SCREEN_MIRRORING_STATE, &screen_mirroring_status) < 0)
243 WFD_APP_LOG(WFD_APP_LOG_ERROR, "Failed to get vconf VCONFKEY_SCREEN_MIRRORING_STATE\n");
246 if (screen_mirroring_status == VCONFKEY_SCREEN_MIRRORING_ACTIVATED) {
247 ad->last_wfd_time = time(NULL);
248 return ECORE_CALLBACK_RENEW;
250 /* turn off the Wi-Fi Direct */
251 wfd_app_client_switch_off(ad);
252 ad->popup = wfd_draw_pop_type_auto_deactivation(ad->win, user_data);
257 /* reset monitor timer */
258 if (ad->monitor_timer) {
259 ad->monitor_timer = NULL; //ECORE_CALLBACK_CANCEL will release timer.
262 return ECORE_CALLBACK_CANCEL;
267 * This function let the app make a callback for registering activation event
269 * @param[in] error_code the returned error code
270 * @param[in] device_state the state of device
271 * @param[in] user_data the pointer to the main data structure
273 void _cb_activation(int error_code, wifi_direct_device_state_e device_state, void *user_data)
275 __WFD_APP_FUNC_ENTER__;
276 wfd_appdata_t *ad = (wfd_appdata_t *)user_data;
278 switch (device_state) {
279 case WIFI_DIRECT_DEVICE_STATE_ACTIVATED:
281 WFD_APP_LOG(WFD_APP_LOG_ERROR, "---------------WIFI_DIRECT_DEVICE_STATE_ACTIVATED\n");
282 #ifdef NOT_CONNECTED_INDICATOR_ICON
283 wfd_app_util_add_indicator_icon(ad);
285 #ifdef WFD_FIVE_MIN_IDLE_DEACTIVATION
286 if (NULL == ad->monitor_timer) {
287 ad->last_wfd_time = time(NULL);
288 ad->monitor_timer = ecore_timer_add(5.0,
289 (Ecore_Task_Cb)_wfd_automatic_deactivated_for_no_connection_cb, ad);
295 case WIFI_DIRECT_DEVICE_STATE_DEACTIVATED:
297 WFD_APP_LOG(WFD_APP_LOG_ERROR, "---------------WIFI_DIRECT_DEVICE_STATE_DEACTIVATED\n");
298 /* when deactivated, stop the timer */
299 if (ad->transmit_timer) {
300 ecore_timer_del(ad->transmit_timer);
301 ad->transmit_timer = NULL;
304 #ifdef WFD_FIVE_MIN_IDLE_DEACTIVATION
305 /* when deactivated, stop the timer */
306 if (ad->monitor_timer) {
307 ecore_timer_del(ad->monitor_timer);
308 ad->monitor_timer = NULL;
311 wfd_app_util_del_notification(ad);
312 #ifdef WFD_SCREEN_MIRRORING_ENABLED
313 wfd_app_util_set_screen_mirroring_deactivated(ad);
322 __WFD_APP_FUNC_EXIT__;
326 * This function let the app make a callback for registering connection event
328 * @param[in] error_code the returned error code
329 * @param[in] connection_state the state of connection
330 * @param[in] mac_address the mac address of peer
331 * @param[in] user_data the pointer to the main data structure
333 void _cb_connection(int error_code, wifi_direct_connection_state_e connection_state, const char *mac_address, void *user_data)
335 __WFD_APP_FUNC_ENTER__;
337 wfd_appdata_t *ad = (wfd_appdata_t *)user_data;
340 #ifdef WFD_SCREEN_MIRRORING_ENABLED
341 int screen_mirroring_status = 0;
343 wifi_direct_discovered_peer_info_s *peer_info = NULL;
344 wfd_connection_info_s *connection = ad->connection;
345 #ifdef NOT_CONNECTED_INDICATOR_ICON
346 notification_error_e noti_err = NOTIFICATION_ERROR_NONE;
348 char popup_text[MAX_POPUP_TEXT_SIZE] = {0, };
350 /* find the peer's name by the mac address */
351 WFD_RET_IF(NULL == mac_address, "ERROR : mac address is NULL !!\n");
353 WFD_APP_LOG(WFD_APP_LOG_ERROR, "-------------------error_code:%d connection_state:%d \n",
354 error_code, connection_state);
356 /* when disconnection, mac_address is empty */
357 if (connection_state <= WIFI_DIRECT_DISASSOCIATION_IND) {
359 result = strncmp(connection->peer_addr, mac_address, MACSTR_LENGTH);
361 WFD_APP_LOG(WFD_APP_LOG_ERROR, "Connection event from unknown peer");
365 result = wifi_direct_get_peer_info((char *)mac_address, &peer_info);
366 if (result < 0 || !peer_info) {
367 WFD_APP_LOG(WFD_APP_LOG_ERROR, "Unknown peer");
368 if (NULL != peer_info)
373 connection = (wfd_connection_info_s*) calloc(1, sizeof(wfd_connection_info_s));
375 WFD_APP_LOG(WFD_APP_LOG_ERROR, "Failed to allocate memory for peer");
380 if (TRUE != dbus_validate_utf8(peer_info->device_name, NULL)) {
381 memcpy(connection->peer_name, peer_info->device_name, DEV_NAME_LENGTH-2);
382 connection->peer_name[DEV_NAME_LENGTH-2] = '\0';
384 memcpy(connection->peer_name, peer_info->device_name, DEV_NAME_LENGTH);
385 connection->peer_name[DEV_NAME_LENGTH] = '\0';
388 strncpy(connection->peer_addr, mac_address, MACSTR_LENGTH);
389 connection->peer_addr[MACSTR_LENGTH] = '\0';
390 connection->device_type = peer_info->primary_device_type;
391 connection->wifi_display = peer_info->is_miracast_device;
392 wifi_direct_get_local_wps_type(&connection->wps_type);
393 wifi_direct_is_autoconnection_mode(&connection->auto_conn);
395 ad->connection = connection;
400 switch (connection_state) {
401 case WIFI_DIRECT_CONNECTION_REQ:
403 WFD_APP_LOG(WFD_APP_LOG_LOW, "event ------------------ WIFI_DIRECT_CONNECTION_REQ\n");
405 memcpy((char*)ad->mac_addr_connecting, connection->peer_addr, MACSTR_LENGTH);
407 wfd_app_get_connected_peers(ad);
408 WFD_APP_LOG(WFD_APP_LOG_LOW, "No of connected peers = %d", ad->raw_connected_peer_cnt);
409 if (ad->raw_connected_peer_cnt >= WFD_MAX_CONNECTED_PEER) {
410 result = wifi_direct_reject_connection(connection->peer_addr);
411 if (result != WIFI_DIRECT_ERROR_NONE)
412 WFD_APP_LOG(WFD_APP_LOG_ERROR, "Failed to reject connection(%d)", result);
413 snprintf(popup_text, MAX_POPUP_TEXT_SIZE,
414 D_("IDS_ST_POP_YOU_CAN_CONNECT_UP_TO_PD_DEVICES_AT_THE_SAME_TIME"),
415 WFD_MAX_CONNECTED_PEER);
416 notification_status_message_post(popup_text);
420 if (connection->auto_conn) {
421 result = wifi_direct_accept_connection(connection->peer_addr);
423 WFD_APP_LOG(WFD_APP_LOG_ERROR, "Failed to accept connection");
426 WFD_APP_LOG(WFD_APP_LOG_HIGH, "Succeeded to accept connection");
428 if (connection->wps_type == WIFI_DIRECT_WPS_TYPE_PBC) {
429 WFD_APP_LOG(WFD_APP_LOG_LOW, "WPS type: WIFI_DIRECT_WPS_TYPE_PBC\n");
430 wfd_prepare_popup(WFD_POP_APRV_CONNECTION_WPS_PUSHBUTTON_REQ, NULL);
431 } else if (connection->wps_type == WIFI_DIRECT_WPS_TYPE_PIN_DISPLAY) {
433 WFD_APP_LOG(WFD_APP_LOG_LOW, "WPS type: WIFI_DIRECT_WPS_TYPE_PIN_DISPLAY");
434 if (wifi_direct_get_wps_pin(&pin) != WIFI_DIRECT_ERROR_NONE) {
435 WFD_APP_LOG(WFD_APP_LOG_ERROR, "Failed to get WPS pin");
438 strncpy(connection->wps_pin, pin, PIN_LENGTH);
439 WFD_IF_FREE_MEM(pin);
440 wfd_prepare_popup(WFD_POP_APRV_CONNECTION_WPS_DISPLAY_REQ, NULL);
441 } else if (connection->wps_type == WIFI_DIRECT_WPS_TYPE_PIN_KEYPAD) {
442 WFD_APP_LOG(WFD_APP_LOG_LOW, "WPS type: WIFI_DIRECT_WPS_TYPE_PIN_KEYPAD");
443 wfd_prepare_popup(WFD_POP_APRV_CONNECTION_WPS_KEYPAD_REQ, NULL);
445 WFD_APP_LOG(WFD_APP_LOG_ERROR, "wps_config is unkown!\n");
448 int res = display_change_state(LCD_NORMAL);
450 WFD_APP_LOG(WFD_APP_LOG_ERROR, "Failed to change PM state(%d)", res);
455 case WIFI_DIRECT_CONNECTION_WPS_REQ:
457 WFD_APP_LOG(WFD_APP_LOG_LOW, "event ------------------ WIFI_DIRECT_CONNECTION_WPS_REQ\n");
458 if (connection->wps_type == WIFI_DIRECT_WPS_TYPE_PIN_KEYPAD) {
459 WFD_APP_LOG(WFD_APP_LOG_LOW, "WPS type: WIFI_DIRECT_WPS_TYPE_PIN_KEYPAD\n");
460 wfd_prepare_popup(WFD_POP_PROG_CONNECT_WITH_KEYPAD, NULL);
461 } else if (connection->wps_type == WIFI_DIRECT_WPS_TYPE_PIN_DISPLAY) {
463 WFD_APP_LOG(WFD_APP_LOG_LOW, "WPS type: WIFI_DIRECT_WPS_TYPE_PIN_DISPLAY\n");
465 if (wifi_direct_get_wps_pin(&pin) != WIFI_DIRECT_ERROR_NONE) {
466 WFD_APP_LOG(WFD_APP_LOG_ERROR, "Failed to get WPS pin");
470 strncpy(connection->wps_pin, pin, PIN_LENGTH);
471 WFD_IF_FREE_MEM(pin);
473 wfd_prepare_popup(WFD_POP_PROG_CONNECT_WITH_PIN, NULL);
475 WFD_APP_LOG(WFD_APP_LOG_ERROR, "WPS type: %d", connection->wps_type);
480 case WIFI_DIRECT_CONNECTION_IN_PROGRESS:
482 WFD_APP_LOG(WFD_APP_LOG_LOW, "event ------------------ WIFI_DIRECT_CONNECTION_IN_PROGRESS\n");
486 case WIFI_DIRECT_CONNECTION_RSP:
489 char txt[WFD_POP_STR_MAX_LEN] = {0};
492 memset(ad->mac_addr_connecting, 0x00, MACSTR_LENGTH);
494 if (error_code != WIFI_DIRECT_ERROR_NONE) {
495 WFD_APP_LOG(WFD_APP_LOG_ERROR, "Failed to connect with peer[%s] -(%d)",
496 connection->peer_name, error_code);
497 snprintf(txt, WFD_POP_STR_MAX_LEN, D_("IDS_WIFI_POP_FAILED_TO_CONNECT_TO_PS"),
498 connection->peer_name);
500 WFD_APP_LOG(WFD_APP_LOG_LOW, "Succeeded to connect with peer[%s] -(%d)",
501 connection->peer_name, error_code);
502 snprintf(txt, WFD_POP_STR_MAX_LEN, D_("IDS_WIFI_BODY_CONNECTED_TO_PS"),
503 connection->peer_name);
504 #ifdef WFD_SCREEN_MIRRORING_ENABLED
505 result = vconf_get_int(VCONFKEY_SCREEN_MIRRORING_STATE, &screen_mirroring_status);
507 WFD_APP_LOG(WFD_APP_LOG_ERROR, "Failed to get VCONFKEY_SCREEN_MIRRORING_STATE");
509 if (screen_mirroring_status == VCONFKEY_SCREEN_MIRRORING_DEACTIVATED)
510 snprintf(txt, WFD_POP_STR_MAX_LEN, D_("IDS_WIFI_BODY_CONNECTED_TO_PS"),
511 connection->peer_name);
515 free(ad->connection);
516 ad->connection = NULL;
518 wfd_app_get_connected_peers(ad);
519 WFD_APP_LOG(WFD_APP_LOG_LOW, "No of connected peers = %d", ad->raw_connected_peer_cnt);
520 /* tickernoti popup */
521 if (ad->raw_connected_peer_cnt < WFD_MAX_CONNECTED_PEER) {
522 if (strlen(txt) > 0) {
523 msg = elm_entry_utf8_to_markup(txt);
524 WFD_RET_IF(!msg, "Failed to elm_entry_markup_to_utf8()!");
525 notification_status_message_post(msg);
526 WFD_IF_FREE_MEM(msg);
532 case WIFI_DIRECT_DISASSOCIATION_IND:
534 WFD_APP_LOG(WFD_APP_LOG_LOW, "event ------------------ WIFI_DIRECT_DISASSOCIATION_IND\n");
535 wfd_app_util_del_wfd_connected_notification(ad);
537 #ifdef WFD_SCREEN_MIRRORING_ENABLED
538 if (connection && connection->wifi_display)
539 wfd_app_util_set_screen_mirroring_deactivated(ad);
542 free(ad->connection);
543 ad->connection = NULL;
548 case WIFI_DIRECT_DISCONNECTION_IND:
550 #if 0 // changed to show notification only when allshare cast device is connected.
551 _del_wfd_notification();
553 WFD_APP_LOG(WFD_APP_LOG_LOW, "event ------------------ WIFI_DIRECT_DISCONNECTION_IND\n");
554 #ifdef WFD_SCREEN_MIRRORING_ENABLED
555 wfd_app_util_set_screen_mirroring_deactivated(ad);
557 notification_status_message_post(D_("IDS_WIFI_BODY_THE_WI_FI_DIRECT_CONNECTION_HAS_BEEN_LOST"));
558 wfd_app_util_del_wfd_connected_notification(ad);
562 case WIFI_DIRECT_DISCONNECTION_RSP:
564 #if 0 // changed to show notification only when allshare cast device is connected.
565 _del_wfd_notification();
567 WFD_APP_LOG(WFD_APP_LOG_LOW, "event ------------------ WIFI_DIRECT_DISCONNECTION_RSP\n");
569 wfd_app_util_del_wfd_connected_notification(ad);
571 #ifdef WFD_SCREEN_MIRRORING_ENABLED
572 wfd_app_util_set_screen_mirroring_deactivated(ad);
576 result = wifi_direct_set_autoconnection_mode(false);
577 WFD_APP_LOG(WFD_APP_LOG_LOW, "wifi_direct_set_autoconnection_mode() result=[%d]\n", result);
581 case WIFI_DIRECT_GROUP_DESTROYED:
583 WFD_APP_LOG(WFD_APP_LOG_LOW, "event ------------------ WIFI_DIRECT_GROUP_DESTROYED\n");
584 notification_status_message_post(D_("IDS_WIFI_BODY_THE_WI_FI_DIRECT_CONNECTION_HAS_BEEN_LOST"));
594 * To support ON DEMAND popup destroy. API request blocks and popup destroy
597 /* wifi_direct_get_state(&ad->wfd_status); */
599 if (vconf_get_int(VCONFKEY_WIFI_DIRECT_STATE, &wfd_state) < 0) {
600 WFD_APP_LOG(WFD_APP_LOG_ERROR, "Error reading vconf (%s)\n", VCONFKEY_WIFI_DIRECT_STATE);
602 WFD_APP_LOG(WFD_APP_LOG_LOW, "wfd state: %d", wfd_state);
604 if (wfd_state == VCONFKEY_WIFI_DIRECT_DEACTIVATED) {
605 wfd_app_util_del_notification(ad);
608 #ifdef NOT_CONNECTED_INDICATOR_ICON
609 if (wfd_state >= VCONFKEY_WIFI_DIRECT_CONNECTED) {
610 noti_err = notification_delete(ad->noti_wifi_direct_on);
611 if (noti_err != NOTIFICATION_ERROR_NONE) {
612 WFD_APP_LOG(WFD_APP_LOG_ERROR, "Fail to notification_delete.(%d)\n", noti_err);
614 noti_err = notification_free(ad->noti_wifi_direct_on);
615 ad->noti_wifi_direct_on = NULL;
616 if (noti_err != NOTIFICATION_ERROR_NONE) {
617 WFD_APP_LOG(WFD_APP_LOG_ERROR, "Fail to notification_free.(%d)\n", noti_err);
623 if (wfd_state < VCONFKEY_WIFI_DIRECT_CONNECTED) {
624 if (ad->transmit_timer) {
625 ecore_timer_del(ad->transmit_timer);
626 ad->transmit_timer = NULL;
629 if (NULL == ad->transmit_timer) {
630 WFD_APP_LOG(WFD_APP_LOG_LOW, "start the transmit timer\n");
631 ad->last_wfd_transmit_time = time(NULL);
632 ad->transmit_timer = ecore_timer_add(5.0,
633 (Ecore_Task_Cb)wfd_automatic_deactivated_for_connection_cb, ad);
637 if (wfd_state >= VCONFKEY_WIFI_DIRECT_CONNECTED) {
638 #ifdef WFD_FIVE_MIN_IDLE_DEACTIVATION
639 if (ad->monitor_timer) {
640 ecore_timer_del(ad->monitor_timer);
641 ad->monitor_timer = NULL;
645 #ifdef NOT_CONNECTED_INDICATOR_ICON
646 wfd_app_util_add_indicator_icon(ad);
648 #ifdef WFD_FIVE_MIN_IDLE_DEACTIVATION
649 if (NULL == ad->monitor_timer) {
650 ad->last_wfd_time = time(NULL);
651 ad->monitor_timer = ecore_timer_add(5.0,
652 (Ecore_Task_Cb)_wfd_automatic_deactivated_for_no_connection_cb, ad);
657 __WFD_APP_FUNC_EXIT__;
661 * This function let the app do initialization
662 * @return If success, return TRUE, else return FALSE
663 * @param[in] ad the pointer to the main data structure
665 bool init_wfd_client(wfd_appdata_t *ad)
667 __WFD_APP_FUNC_ENTER__;
668 WFD_RETV_IF(NULL == ad, FALSE, "NULL parameters.\n");
672 ad->last_wfd_status = WIFI_DIRECT_STATE_DEACTIVATED;
675 ret = wifi_direct_initialize();
676 if (ret == WIFI_DIRECT_ERROR_NONE ||
677 ret == WIFI_DIRECT_ERROR_ALREADY_INITIALIZED)
679 WFD_APP_LOG(WFD_APP_LOG_ERROR, "Failed to initialize Wi-Fi Direct(%d)\n", ret);
687 ret = wifi_direct_set_device_state_changed_cb(_cb_activation, (void*) ad);
688 if (ret != WIFI_DIRECT_ERROR_NONE) {
689 WFD_APP_LOG(WFD_APP_LOG_ERROR, "Failed to register _cb_activation(%d)\n", ret);
693 ret = wifi_direct_set_connection_state_changed_cb(_cb_connection, (void*) ad);
694 if (ret != WIFI_DIRECT_ERROR_NONE) {
695 WFD_APP_LOG(WFD_APP_LOG_ERROR, "Failed to register _cb_connection(%d)\n", ret);
699 #ifdef WFD_FIVE_MIN_IDLE_DEACTIVATION
700 if (NULL == ad->monitor_timer) {
701 ad->last_wfd_time = time(NULL);
702 ad->monitor_timer = ecore_timer_add(5.0,
703 (Ecore_Task_Cb)_wfd_automatic_deactivated_for_no_connection_cb, ad);
706 __WFD_APP_FUNC_EXIT__;
711 * This function let the app do de-initialization
712 * @return If success, return TRUE, else return FALSE
713 * @param[in] ad the pointer to the main data structure
715 int deinit_wfd_client(wfd_appdata_t *ad)
717 __WFD_APP_FUNC_ENTER__;
721 WFD_APP_LOG(WFD_APP_LOG_LOW, "NULL parameter\n");
725 #ifdef WFD_FIVE_MIN_IDLE_DEACTIVATION
726 if (ad->monitor_timer) {
727 ecore_timer_del(ad->monitor_timer);
728 ad->monitor_timer = NULL;
732 ret = wifi_direct_unset_device_state_changed_cb();
733 if (ret != WIFI_DIRECT_ERROR_NONE) {
734 WFD_APP_LOG(WFD_APP_LOG_ERROR, "Failed to deregister _cb_activation(%d)\n", ret);
737 ret = wifi_direct_unset_connection_state_changed_cb();
738 if (ret != WIFI_DIRECT_ERROR_NONE) {
739 WFD_APP_LOG(WFD_APP_LOG_ERROR, "Failed to deregister _cb_connection(%d)\n", ret);
742 ret = wifi_direct_deinitialize();
743 if (ret != WIFI_DIRECT_ERROR_NONE) {
744 WFD_APP_LOG(WFD_APP_LOG_ERROR, "Failed to deinitialize Wi-Fi Direct. error code = [%d]\n", ret);
747 __WFD_APP_FUNC_EXIT__;