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");
404 char *format_str = D_("IDS_ST_POP_YOU_CAN_CONNECT_UP_TO_PD_DEVICES_AT_THE_SAME_TIME");
406 memcpy((char*)ad->mac_addr_connecting, connection->peer_addr, MACSTR_LENGTH);
408 wfd_app_get_connected_peers(ad);
409 WFD_APP_LOG(WFD_APP_LOG_LOW, "No of connected peers = %d", ad->raw_connected_peer_cnt);
410 if (ad->raw_connected_peer_cnt >= WFD_MAX_CONNECTED_PEER) {
411 result = wifi_direct_reject_connection(connection->peer_addr);
412 if (result != WIFI_DIRECT_ERROR_NONE)
413 WFD_APP_LOG(WFD_APP_LOG_ERROR, "Failed to reject connection(%d)", result);
414 g_snprintf(popup_text, MAX_POPUP_TEXT_SIZE,
415 format_str, 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 unknown!\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};
490 char *format_str = NULL;
493 memset(ad->mac_addr_connecting, 0x00, MACSTR_LENGTH);
495 if (error_code != WIFI_DIRECT_ERROR_NONE) {
496 WFD_APP_LOG(WFD_APP_LOG_ERROR, "Failed to connect with peer[%s] -(%d)",
497 connection->peer_name, error_code);
498 format_str = D_("IDS_WIFI_POP_FAILED_TO_CONNECT_TO_PS");
499 snprintf(txt, WFD_POP_STR_MAX_LEN, format_str, connection->peer_name);
501 WFD_APP_LOG(WFD_APP_LOG_LOW, "Succeeded to connect with peer[%s] -(%d)",
502 connection->peer_name, error_code);
503 format_str = D_("IDS_WIFI_BODY_CONNECTED_TO_PS");
504 snprintf(txt, WFD_POP_STR_MAX_LEN, format_str, connection->peer_name);
505 #ifdef WFD_SCREEN_MIRRORING_ENABLED
506 result = vconf_get_int(VCONFKEY_SCREEN_MIRRORING_STATE, &screen_mirroring_status);
508 WFD_APP_LOG(WFD_APP_LOG_ERROR, "Failed to get VCONFKEY_SCREEN_MIRRORING_STATE");
510 if (screen_mirroring_status == VCONFKEY_SCREEN_MIRRORING_DEACTIVATED)
511 snprintf(txt, WFD_POP_STR_MAX_LEN, D_("IDS_WIFI_BODY_CONNECTED_TO_PS"),
512 connection->peer_name);
516 free(ad->connection);
517 ad->connection = NULL;
519 wfd_app_get_connected_peers(ad);
520 WFD_APP_LOG(WFD_APP_LOG_LOW, "No of connected peers = %d", ad->raw_connected_peer_cnt);
521 /* tickernoti popup */
522 if (ad->raw_connected_peer_cnt < WFD_MAX_CONNECTED_PEER) {
523 if (strlen(txt) > 0) {
524 msg = elm_entry_utf8_to_markup(txt);
525 WFD_RET_IF(!msg, "Failed to elm_entry_markup_to_utf8()!");
526 notification_status_message_post(msg);
527 WFD_IF_FREE_MEM(msg);
533 case WIFI_DIRECT_DISASSOCIATION_IND:
535 WFD_APP_LOG(WFD_APP_LOG_LOW, "event ------------------ WIFI_DIRECT_DISASSOCIATION_IND\n");
536 wfd_app_util_del_wfd_connected_notification(ad);
538 #ifdef WFD_SCREEN_MIRRORING_ENABLED
539 if (connection && connection->wifi_display)
540 wfd_app_util_set_screen_mirroring_deactivated(ad);
543 free(ad->connection);
544 ad->connection = NULL;
549 case WIFI_DIRECT_DISCONNECTION_IND:
551 #if 0 // changed to show notification only when allshare cast device is connected.
552 _del_wfd_notification();
554 WFD_APP_LOG(WFD_APP_LOG_LOW, "event ------------------ WIFI_DIRECT_DISCONNECTION_IND\n");
555 #ifdef WFD_SCREEN_MIRRORING_ENABLED
556 wfd_app_util_set_screen_mirroring_deactivated(ad);
558 notification_status_message_post(D_("IDS_WIFI_BODY_THE_WI_FI_DIRECT_CONNECTION_HAS_BEEN_LOST"));
559 wfd_app_util_del_wfd_connected_notification(ad);
563 case WIFI_DIRECT_DISCONNECTION_RSP:
565 #if 0 // changed to show notification only when allshare cast device is connected.
566 _del_wfd_notification();
568 WFD_APP_LOG(WFD_APP_LOG_LOW, "event ------------------ WIFI_DIRECT_DISCONNECTION_RSP\n");
570 wfd_app_util_del_wfd_connected_notification(ad);
572 #ifdef WFD_SCREEN_MIRRORING_ENABLED
573 wfd_app_util_set_screen_mirroring_deactivated(ad);
577 result = wifi_direct_set_autoconnection_mode(false);
578 WFD_APP_LOG(WFD_APP_LOG_LOW, "wifi_direct_set_autoconnection_mode() result=[%d]\n", result);
582 case WIFI_DIRECT_GROUP_DESTROYED:
584 WFD_APP_LOG(WFD_APP_LOG_LOW, "event ------------------ WIFI_DIRECT_GROUP_DESTROYED\n");
585 notification_status_message_post(D_("IDS_WIFI_BODY_THE_WI_FI_DIRECT_CONNECTION_HAS_BEEN_LOST"));
595 * To support ON DEMAND popup destroy. API request blocks and popup destroy
598 /* wifi_direct_get_state(&ad->wfd_status); */
600 if (vconf_get_int(VCONFKEY_WIFI_DIRECT_STATE, &wfd_state) < 0) {
601 WFD_APP_LOG(WFD_APP_LOG_ERROR, "Error reading vconf (%s)\n", VCONFKEY_WIFI_DIRECT_STATE);
603 WFD_APP_LOG(WFD_APP_LOG_LOW, "wfd state: %d", wfd_state);
605 if (wfd_state == VCONFKEY_WIFI_DIRECT_DEACTIVATED) {
606 wfd_app_util_del_notification(ad);
609 #ifdef NOT_CONNECTED_INDICATOR_ICON
610 if (wfd_state >= VCONFKEY_WIFI_DIRECT_CONNECTED) {
611 noti_err = notification_delete(ad->noti_wifi_direct_on);
612 if (noti_err != NOTIFICATION_ERROR_NONE) {
613 WFD_APP_LOG(WFD_APP_LOG_ERROR, "Fail to notification_delete.(%d)\n", noti_err);
615 noti_err = notification_free(ad->noti_wifi_direct_on);
616 ad->noti_wifi_direct_on = NULL;
617 if (noti_err != NOTIFICATION_ERROR_NONE) {
618 WFD_APP_LOG(WFD_APP_LOG_ERROR, "Fail to notification_free.(%d)\n", noti_err);
624 if (wfd_state < VCONFKEY_WIFI_DIRECT_CONNECTED) {
625 if (ad->transmit_timer) {
626 ecore_timer_del(ad->transmit_timer);
627 ad->transmit_timer = NULL;
630 if (NULL == ad->transmit_timer) {
631 WFD_APP_LOG(WFD_APP_LOG_LOW, "start the transmit timer\n");
632 ad->last_wfd_transmit_time = time(NULL);
633 ad->transmit_timer = ecore_timer_add(5.0,
634 (Ecore_Task_Cb)wfd_automatic_deactivated_for_connection_cb, ad);
638 if (wfd_state >= VCONFKEY_WIFI_DIRECT_CONNECTED) {
639 #ifdef WFD_FIVE_MIN_IDLE_DEACTIVATION
640 if (ad->monitor_timer) {
641 ecore_timer_del(ad->monitor_timer);
642 ad->monitor_timer = NULL;
646 #ifdef NOT_CONNECTED_INDICATOR_ICON
647 wfd_app_util_add_indicator_icon(ad);
649 #ifdef WFD_FIVE_MIN_IDLE_DEACTIVATION
650 if (NULL == ad->monitor_timer) {
651 ad->last_wfd_time = time(NULL);
652 ad->monitor_timer = ecore_timer_add(5.0,
653 (Ecore_Task_Cb)_wfd_automatic_deactivated_for_no_connection_cb, ad);
658 __WFD_APP_FUNC_EXIT__;
662 * This function let the app do initialization
663 * @return If success, return TRUE, else return FALSE
664 * @param[in] ad the pointer to the main data structure
666 bool init_wfd_client(wfd_appdata_t *ad)
668 __WFD_APP_FUNC_ENTER__;
669 WFD_RETV_IF(NULL == ad, FALSE, "NULL parameters.\n");
673 ad->last_wfd_status = WIFI_DIRECT_STATE_DEACTIVATED;
676 ret = wifi_direct_initialize();
677 if (ret == WIFI_DIRECT_ERROR_NONE ||
678 ret == WIFI_DIRECT_ERROR_ALREADY_INITIALIZED)
680 WFD_APP_LOG(WFD_APP_LOG_ERROR, "Failed to initialize Wi-Fi Direct(%d)\n", ret);
688 ret = wifi_direct_set_device_state_changed_cb(_cb_activation, (void*) ad);
689 if (ret != WIFI_DIRECT_ERROR_NONE) {
690 WFD_APP_LOG(WFD_APP_LOG_ERROR, "Failed to register _cb_activation(%d)\n", ret);
694 ret = wifi_direct_set_connection_state_changed_cb(_cb_connection, (void*) ad);
695 if (ret != WIFI_DIRECT_ERROR_NONE) {
696 WFD_APP_LOG(WFD_APP_LOG_ERROR, "Failed to register _cb_connection(%d)\n", ret);
700 #ifdef WFD_FIVE_MIN_IDLE_DEACTIVATION
701 if (NULL == ad->monitor_timer) {
702 ad->last_wfd_time = time(NULL);
703 ad->monitor_timer = ecore_timer_add(5.0,
704 (Ecore_Task_Cb)_wfd_automatic_deactivated_for_no_connection_cb, ad);
707 __WFD_APP_FUNC_EXIT__;
712 * This function let the app do de-initialization
713 * @return If success, return TRUE, else return FALSE
714 * @param[in] ad the pointer to the main data structure
716 int deinit_wfd_client(wfd_appdata_t *ad)
718 __WFD_APP_FUNC_ENTER__;
722 WFD_APP_LOG(WFD_APP_LOG_LOW, "NULL parameter\n");
726 #ifdef WFD_FIVE_MIN_IDLE_DEACTIVATION
727 if (ad->monitor_timer) {
728 ecore_timer_del(ad->monitor_timer);
729 ad->monitor_timer = NULL;
733 ret = wifi_direct_unset_device_state_changed_cb();
734 if (ret != WIFI_DIRECT_ERROR_NONE) {
735 WFD_APP_LOG(WFD_APP_LOG_ERROR, "Failed to deregister _cb_activation(%d)\n", ret);
738 ret = wifi_direct_unset_connection_state_changed_cb();
739 if (ret != WIFI_DIRECT_ERROR_NONE) {
740 WFD_APP_LOG(WFD_APP_LOG_ERROR, "Failed to deregister _cb_connection(%d)\n", ret);
743 ret = wifi_direct_deinitialize();
744 if (ret != WIFI_DIRECT_ERROR_NONE) {
745 WFD_APP_LOG(WFD_APP_LOG_ERROR, "Failed to deinitialize Wi-Fi Direct. error code = [%d]\n", ret);
748 __WFD_APP_FUNC_EXIT__;