4 * Copyright 2012 Samsung Electronics Co., Ltd
6 * Licensed under the Flora License, Version 1.1 (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 g_strlcpy(ad->raw_connected_peers[peer_cnt].ssid, peer->device_name, sizeof(ad->raw_connected_peers[peer_cnt].ssid));
68 g_strlcpy(ad->raw_connected_peers[peer_cnt].mac_address, peer->mac_address, WFD_MAC_ADDRESS_SIZE);
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;
131 /* get transfer state */
132 if (vconf_get_int(VCONFKEY_WIFI_DIRECT_TRANSFER_STATE, &wfd_transfer_state) < 0) {
133 WFD_APP_LOG(WFD_APP_LOG_ERROR, "Error reading vconf (%s)\n",
134 VCONFKEY_WIFI_DIRECT_TRANSFER_STATE);
135 return ECORE_CALLBACK_CANCEL;
138 res = wifi_direct_get_state(&ad->wfd_status);
139 if (res != WIFI_DIRECT_ERROR_NONE)
140 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(D_("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;
176 if (ad->wfd_status >= WIFI_DIRECT_STATE_ACTIVATING) {
177 /*if connected, disconnect all devices*/
178 if (WIFI_DIRECT_STATE_CONNECTED == ad->wfd_status) {
179 res = wifi_direct_disconnect_all();
180 if (res != WIFI_DIRECT_ERROR_NONE)
183 res = wifi_direct_deactivate();
184 if (res != WIFI_DIRECT_ERROR_NONE) {
185 WFD_APP_LOG(WFD_APP_LOG_ERROR, "Failed to deactivate Wi-Fi Direct. error code = [%d]\n", res);
193 #ifdef WFD_FIVE_MIN_IDLE_DEACTIVATION
195 * This function let the ug make a callback for deactivating wfd automatically
196 * @return if stop the timer, return ECORE_CALLBACK_CANCEL, else return ECORE_CALLBACK_RENEW
197 * @param[in] user_data the pointer to the main data structure
199 static Eina_Bool _wfd_automatic_deactivated_for_no_connection_cb(void *user_data)
203 wfd_appdata_t *ad = (wfd_appdata_t *)user_data;
204 #ifdef WFD_SCREEN_MIRRORING_ENABLED
205 int screen_mirroring_status = 0;
209 return ECORE_CALLBACK_CANCEL;
211 /* check the action, if action is exist, keep the cb */
212 res = wifi_direct_get_state(&ad->wfd_status);
213 if (res != WIFI_DIRECT_ERROR_NONE) {
214 WFD_APP_LOG(WFD_APP_LOG_ERROR, "Get wifi-direct status WIFI_DIRECT_ERROR_NONE!\n");
215 return ECORE_CALLBACK_CANCEL;
218 if (ad->last_wfd_status != ad->wfd_status) {
219 ad->last_wfd_status = ad->wfd_status;
220 ad->last_wfd_time = time(NULL);
221 return ECORE_CALLBACK_RENEW;
224 /* check the timeout, if not timeout, keep the cb */
225 interval = time(NULL) - ad->last_wfd_time;
226 if (interval < MAX_NO_ACTION_TIME_OUT)
227 return ECORE_CALLBACK_RENEW;
229 /* turn off the Wi-Fi Direct */
230 wifi_direct_get_state(&ad->wfd_status);
231 if (ad->wfd_status < WIFI_DIRECT_STATE_ACTIVATING) {
232 WFD_APP_LOG(WFD_APP_LOG_LOW, "wfd_status < WIFI_DIRECT_STATE_ACTIVATING!\n");
234 #ifdef WFD_SCREEN_MIRRORING_ENABLED
235 if (vconf_get_int(VCONFKEY_SCREEN_MIRRORING_STATE, &screen_mirroring_status) < 0)
236 WFD_APP_LOG(WFD_APP_LOG_ERROR, "Failed to get vconf VCONFKEY_SCREEN_MIRRORING_STATE\n");
238 if (screen_mirroring_status == VCONFKEY_SCREEN_MIRRORING_ACTIVATED) {
239 ad->last_wfd_time = time(NULL);
240 return ECORE_CALLBACK_RENEW;
242 /* turn off the Wi-Fi Direct */
243 wfd_app_client_switch_off(ad);
244 ad->popup = wfd_draw_pop_type_auto_deactivation(ad->win, user_data);
249 /* reset monitor timer */
250 if (ad->monitor_timer)
251 ad->monitor_timer = NULL; //ECORE_CALLBACK_CANCEL will release timer.
253 return ECORE_CALLBACK_CANCEL;
258 * This function let the app make a callback for registering activation event
260 * @param[in] error_code the returned error code
261 * @param[in] device_state the state of device
262 * @param[in] user_data the pointer to the main data structure
264 void _cb_activation(int error_code, wifi_direct_device_state_e device_state, void *user_data)
266 __WFD_APP_FUNC_ENTER__;
267 wfd_appdata_t *ad = (wfd_appdata_t *)user_data;
269 switch (device_state) {
270 case WIFI_DIRECT_DEVICE_STATE_ACTIVATED:
272 WFD_APP_LOG(WFD_APP_LOG_ERROR, "---------------WIFI_DIRECT_DEVICE_STATE_ACTIVATED\n");
273 #ifdef NOT_CONNECTED_INDICATOR_ICON
274 wfd_app_util_add_indicator_icon(ad);
276 #ifdef WFD_FIVE_MIN_IDLE_DEACTIVATION
277 if (NULL == ad->monitor_timer) {
278 ad->last_wfd_time = time(NULL);
279 ad->monitor_timer = ecore_timer_add(5.0,
280 (Ecore_Task_Cb)_wfd_automatic_deactivated_for_no_connection_cb, ad);
286 case WIFI_DIRECT_DEVICE_STATE_DEACTIVATED:
288 WFD_APP_LOG(WFD_APP_LOG_ERROR, "---------------WIFI_DIRECT_DEVICE_STATE_DEACTIVATED\n");
289 /* when deactivated, stop the timer */
290 if (ad->transmit_timer) {
291 ecore_timer_del(ad->transmit_timer);
292 ad->transmit_timer = NULL;
295 #ifdef WFD_FIVE_MIN_IDLE_DEACTIVATION
296 /* when deactivated, stop the timer */
297 if (ad->monitor_timer) {
298 ecore_timer_del(ad->monitor_timer);
299 ad->monitor_timer = NULL;
302 wfd_app_util_del_notification(ad);
303 #ifdef WFD_SCREEN_MIRRORING_ENABLED
304 wfd_app_util_set_screen_mirroring_deactivated(ad);
313 __WFD_APP_FUNC_EXIT__;
317 * This function let the app make a callback for registering connection event
319 * @param[in] error_code the returned error code
320 * @param[in] connection_state the state of connection
321 * @param[in] mac_address the mac address of peer
322 * @param[in] user_data the pointer to the main data structure
324 void _cb_connection(int error_code, wifi_direct_connection_state_e connection_state, const char *mac_address, void *user_data)
326 __WFD_APP_FUNC_ENTER__;
328 wfd_appdata_t *ad = (wfd_appdata_t *)user_data;
331 #ifdef WFD_SCREEN_MIRRORING_ENABLED
332 int screen_mirroring_status = 0;
334 wifi_direct_discovered_peer_info_s *peer_info = NULL;
335 wfd_connection_info_s *connection = ad->connection;
336 #ifdef NOT_CONNECTED_INDICATOR_ICON
337 notification_error_e noti_err = NOTIFICATION_ERROR_NONE;
339 char popup_text[MAX_POPUP_TEXT_SIZE] = {0, };
341 /* find the peer's name by the mac address */
342 WFD_RET_IF(NULL == mac_address, "ERROR : mac address is NULL !!\n");
344 WFD_APP_LOG(WFD_APP_LOG_ERROR, "-------------------error_code:%d connection_state:%d \n",
345 error_code, connection_state);
347 /* when disconnection, mac_address is empty */
348 if (connection_state <= WIFI_DIRECT_DISASSOCIATION_IND) {
350 result = strncmp(connection->peer_addr, mac_address, MACSTR_LENGTH);
352 WFD_APP_LOG(WFD_APP_LOG_ERROR, "Connection event from unknown peer");
356 result = wifi_direct_get_peer_info((char *)mac_address, &peer_info);
357 if (result < 0 || !peer_info) {
358 WFD_APP_LOG(WFD_APP_LOG_ERROR, "Unknown peer");
359 if (NULL != peer_info)
364 connection = (wfd_connection_info_s*) calloc(1, sizeof(wfd_connection_info_s));
366 WFD_APP_LOG(WFD_APP_LOG_ERROR, "Failed to allocate memory for peer");
371 if (TRUE != dbus_validate_utf8(peer_info->device_name, NULL)) {
372 memcpy(connection->peer_name, peer_info->device_name, DEV_NAME_LENGTH-2);
373 connection->peer_name[DEV_NAME_LENGTH-2] = '\0';
375 memcpy(connection->peer_name, peer_info->device_name, DEV_NAME_LENGTH);
376 connection->peer_name[DEV_NAME_LENGTH] = '\0';
379 strncpy(connection->peer_addr, mac_address, MACSTR_LENGTH);
380 connection->peer_addr[MACSTR_LENGTH] = '\0';
381 connection->device_type = peer_info->primary_device_type;
382 connection->wifi_display = peer_info->is_miracast_device;
383 wifi_direct_get_local_wps_type(&connection->wps_type);
384 wifi_direct_is_autoconnection_mode(&connection->auto_conn);
386 ad->connection = connection;
391 switch (connection_state) {
392 case WIFI_DIRECT_CONNECTION_REQ:
394 WFD_APP_LOG(WFD_APP_LOG_LOW, "event ------------------ WIFI_DIRECT_CONNECTION_REQ\n");
395 char *format_str = D_("IDS_ST_POP_YOU_CAN_CONNECT_UP_TO_PD_DEVICES_AT_THE_SAME_TIME");
397 memcpy((char*)ad->mac_addr_connecting, connection->peer_addr, MACSTR_LENGTH);
399 wfd_app_get_connected_peers(ad);
400 WFD_APP_LOG(WFD_APP_LOG_LOW, "No of connected peers = %d", ad->raw_connected_peer_cnt);
401 if (ad->raw_connected_peer_cnt >= WFD_MAX_CONNECTED_PEER) {
402 result = wifi_direct_reject_connection(connection->peer_addr);
403 if (result != WIFI_DIRECT_ERROR_NONE)
404 WFD_APP_LOG(WFD_APP_LOG_ERROR, "Failed to reject connection(%d)", result);
405 g_snprintf(popup_text, MAX_POPUP_TEXT_SIZE,
406 format_str, WFD_MAX_CONNECTED_PEER);
407 notification_status_message_post(popup_text);
411 if (connection->auto_conn) {
412 result = wifi_direct_accept_connection(connection->peer_addr);
414 WFD_APP_LOG(WFD_APP_LOG_ERROR, "Failed to accept connection");
417 WFD_APP_LOG(WFD_APP_LOG_HIGH, "Succeeded to accept connection");
419 if (connection->wps_type == WIFI_DIRECT_WPS_TYPE_PBC) {
420 WFD_APP_LOG(WFD_APP_LOG_LOW, "WPS type: WIFI_DIRECT_WPS_TYPE_PBC\n");
421 wfd_prepare_popup(WFD_POP_APRV_CONNECTION_WPS_PUSHBUTTON_REQ, NULL);
422 } else if (connection->wps_type == WIFI_DIRECT_WPS_TYPE_PIN_DISPLAY) {
424 WFD_APP_LOG(WFD_APP_LOG_LOW, "WPS type: WIFI_DIRECT_WPS_TYPE_PIN_DISPLAY");
425 if (wifi_direct_get_wps_pin(&pin) != WIFI_DIRECT_ERROR_NONE) {
426 WFD_APP_LOG(WFD_APP_LOG_ERROR, "Failed to get WPS pin");
429 strncpy(connection->wps_pin, pin, PIN_LENGTH);
430 WFD_IF_FREE_MEM(pin);
431 wfd_prepare_popup(WFD_POP_APRV_CONNECTION_WPS_DISPLAY_REQ, NULL);
432 } else if (connection->wps_type == WIFI_DIRECT_WPS_TYPE_PIN_KEYPAD) {
433 WFD_APP_LOG(WFD_APP_LOG_LOW, "WPS type: WIFI_DIRECT_WPS_TYPE_PIN_KEYPAD");
434 wfd_prepare_popup(WFD_POP_APRV_CONNECTION_WPS_KEYPAD_REQ, NULL);
436 WFD_APP_LOG(WFD_APP_LOG_ERROR, "wps_config is unknown!\n");
439 int res = display_change_state(LCD_NORMAL);
441 WFD_APP_LOG(WFD_APP_LOG_ERROR, "Failed to change PM state(%d)", res);
446 case WIFI_DIRECT_CONNECTION_WPS_REQ:
448 WFD_APP_LOG(WFD_APP_LOG_LOW, "event ------------------ WIFI_DIRECT_CONNECTION_WPS_REQ\n");
449 if (connection->wps_type == WIFI_DIRECT_WPS_TYPE_PIN_KEYPAD) {
450 WFD_APP_LOG(WFD_APP_LOG_LOW, "WPS type: WIFI_DIRECT_WPS_TYPE_PIN_KEYPAD\n");
451 wfd_prepare_popup(WFD_POP_PROG_CONNECT_WITH_KEYPAD, NULL);
452 } else if (connection->wps_type == WIFI_DIRECT_WPS_TYPE_PIN_DISPLAY) {
454 WFD_APP_LOG(WFD_APP_LOG_LOW, "WPS type: WIFI_DIRECT_WPS_TYPE_PIN_DISPLAY\n");
456 if (wifi_direct_get_wps_pin(&pin) != WIFI_DIRECT_ERROR_NONE) {
457 WFD_APP_LOG(WFD_APP_LOG_ERROR, "Failed to get WPS pin");
461 strncpy(connection->wps_pin, pin, PIN_LENGTH);
462 WFD_IF_FREE_MEM(pin);
464 wfd_prepare_popup(WFD_POP_PROG_CONNECT_WITH_PIN, NULL);
466 WFD_APP_LOG(WFD_APP_LOG_ERROR, "WPS type: %d", connection->wps_type);
471 case WIFI_DIRECT_CONNECTION_IN_PROGRESS:
473 WFD_APP_LOG(WFD_APP_LOG_LOW, "event ------------------ WIFI_DIRECT_CONNECTION_IN_PROGRESS\n");
477 case WIFI_DIRECT_CONNECTION_RSP:
480 char txt[WFD_POP_STR_MAX_LEN] = {0};
481 char *format_str = NULL;
484 memset(ad->mac_addr_connecting, 0x00, MACSTR_LENGTH);
486 if (error_code != WIFI_DIRECT_ERROR_NONE) {
487 WFD_APP_LOG(WFD_APP_LOG_ERROR, "Failed to connect with peer[%s] -(%d)",
488 connection->peer_name, error_code);
489 format_str = D_("IDS_WIFI_POP_FAILED_TO_CONNECT_TO_PS");
490 snprintf(txt, WFD_POP_STR_MAX_LEN, format_str, connection->peer_name);
492 WFD_APP_LOG(WFD_APP_LOG_LOW, "Succeeded to connect with peer[%s] -(%d)",
493 connection->peer_name, error_code);
494 format_str = D_("IDS_WIFI_BODY_CONNECTED_TO_PS");
495 snprintf(txt, WFD_POP_STR_MAX_LEN, format_str, connection->peer_name);
496 #ifdef WFD_SCREEN_MIRRORING_ENABLED
497 result = vconf_get_int(VCONFKEY_SCREEN_MIRRORING_STATE, &screen_mirroring_status);
499 WFD_APP_LOG(WFD_APP_LOG_ERROR, "Failed to get VCONFKEY_SCREEN_MIRRORING_STATE");
501 if (screen_mirroring_status == VCONFKEY_SCREEN_MIRRORING_DEACTIVATED)
502 snprintf(txt, WFD_POP_STR_MAX_LEN, D_("IDS_WIFI_BODY_CONNECTED_TO_PS"),
503 connection->peer_name);
507 free(ad->connection);
508 ad->connection = NULL;
510 wfd_app_get_connected_peers(ad);
511 WFD_APP_LOG(WFD_APP_LOG_LOW, "No of connected peers = %d", ad->raw_connected_peer_cnt);
512 /* tickernoti popup */
513 if (ad->raw_connected_peer_cnt < WFD_MAX_CONNECTED_PEER) {
514 if (strlen(txt) > 0) {
515 msg = elm_entry_utf8_to_markup(txt);
516 WFD_RET_IF(!msg, "Failed to elm_entry_markup_to_utf8()!");
517 notification_status_message_post(msg);
518 WFD_IF_FREE_MEM(msg);
524 case WIFI_DIRECT_DISASSOCIATION_IND:
526 WFD_APP_LOG(WFD_APP_LOG_LOW, "event ------------------ WIFI_DIRECT_DISASSOCIATION_IND\n");
527 wfd_app_util_del_wfd_connected_notification(ad);
529 #ifdef WFD_SCREEN_MIRRORING_ENABLED
530 if (connection && connection->wifi_display)
531 wfd_app_util_set_screen_mirroring_deactivated(ad);
534 free(ad->connection);
535 ad->connection = NULL;
540 case WIFI_DIRECT_DISCONNECTION_IND:
542 #if 0 // changed to show notification only when allshare cast device is connected.
543 _del_wfd_notification();
545 WFD_APP_LOG(WFD_APP_LOG_LOW, "event ------------------ WIFI_DIRECT_DISCONNECTION_IND\n");
546 #ifdef WFD_SCREEN_MIRRORING_ENABLED
547 wfd_app_util_set_screen_mirroring_deactivated(ad);
549 notification_status_message_post(D_("IDS_WIFI_BODY_THE_WI_FI_DIRECT_CONNECTION_HAS_BEEN_LOST"));
550 wfd_app_util_del_wfd_connected_notification(ad);
554 case WIFI_DIRECT_DISCONNECTION_RSP:
556 #if 0 // changed to show notification only when allshare cast device is connected.
557 _del_wfd_notification();
559 WFD_APP_LOG(WFD_APP_LOG_LOW, "event ------------------ WIFI_DIRECT_DISCONNECTION_RSP\n");
561 wfd_app_util_del_wfd_connected_notification(ad);
563 #ifdef WFD_SCREEN_MIRRORING_ENABLED
564 wfd_app_util_set_screen_mirroring_deactivated(ad);
568 result = wifi_direct_set_autoconnection_mode(false);
569 WFD_APP_LOG(WFD_APP_LOG_LOW, "wifi_direct_set_autoconnection_mode() result=[%d]\n", result);
573 case WIFI_DIRECT_GROUP_DESTROYED:
575 WFD_APP_LOG(WFD_APP_LOG_LOW, "event ------------------ WIFI_DIRECT_GROUP_DESTROYED\n");
576 notification_status_message_post(D_("IDS_WIFI_BODY_THE_WI_FI_DIRECT_CONNECTION_HAS_BEEN_LOST"));
586 * To support ON DEMAND popup destroy. API request blocks and popup destroy
589 /* wifi_direct_get_state(&ad->wfd_status); */
591 if (vconf_get_int(VCONFKEY_WIFI_DIRECT_STATE, &wfd_state) < 0)
592 WFD_APP_LOG(WFD_APP_LOG_ERROR, "Error reading vconf (%s)\n", VCONFKEY_WIFI_DIRECT_STATE);
594 WFD_APP_LOG(WFD_APP_LOG_LOW, "wfd state: %d", wfd_state);
596 if (wfd_state == VCONFKEY_WIFI_DIRECT_DEACTIVATED)
597 wfd_app_util_del_notification(ad);
599 #ifdef NOT_CONNECTED_INDICATOR_ICON
600 if (wfd_state >= VCONFKEY_WIFI_DIRECT_CONNECTED) {
601 noti_err = notification_delete(ad->noti_wifi_direct_on);
602 if (noti_err != NOTIFICATION_ERROR_NONE) {
603 WFD_APP_LOG(WFD_APP_LOG_ERROR, "Fail to notification_delete.(%d)\n", noti_err);
605 noti_err = notification_free(ad->noti_wifi_direct_on);
606 ad->noti_wifi_direct_on = NULL;
607 if (noti_err != NOTIFICATION_ERROR_NONE)
608 WFD_APP_LOG(WFD_APP_LOG_ERROR, "Fail to notification_free.(%d)\n", noti_err);
613 if (wfd_state < VCONFKEY_WIFI_DIRECT_CONNECTED) {
614 if (ad->transmit_timer) {
615 ecore_timer_del(ad->transmit_timer);
616 ad->transmit_timer = NULL;
619 if (NULL == ad->transmit_timer) {
620 WFD_APP_LOG(WFD_APP_LOG_LOW, "start the transmit timer\n");
621 ad->last_wfd_transmit_time = time(NULL);
622 ad->transmit_timer = ecore_timer_add(5.0,
623 (Ecore_Task_Cb)wfd_automatic_deactivated_for_connection_cb, ad);
627 if (wfd_state >= VCONFKEY_WIFI_DIRECT_CONNECTED) {
628 #ifdef WFD_FIVE_MIN_IDLE_DEACTIVATION
629 if (ad->monitor_timer) {
630 ecore_timer_del(ad->monitor_timer);
631 ad->monitor_timer = NULL;
635 #ifdef NOT_CONNECTED_INDICATOR_ICON
636 wfd_app_util_add_indicator_icon(ad);
638 #ifdef WFD_FIVE_MIN_IDLE_DEACTIVATION
639 if (NULL == ad->monitor_timer) {
640 ad->last_wfd_time = time(NULL);
641 ad->monitor_timer = ecore_timer_add(5.0,
642 (Ecore_Task_Cb)_wfd_automatic_deactivated_for_no_connection_cb, ad);
647 __WFD_APP_FUNC_EXIT__;
651 * This function let the app do initialization
652 * @return If success, return TRUE, else return FALSE
653 * @param[in] ad the pointer to the main data structure
655 bool init_wfd_client(wfd_appdata_t *ad)
657 __WFD_APP_FUNC_ENTER__;
658 WFD_RETV_IF(NULL == ad, FALSE, "NULL parameters.\n");
662 ad->last_wfd_status = WIFI_DIRECT_STATE_DEACTIVATED;
665 ret = wifi_direct_initialize();
666 if (ret == WIFI_DIRECT_ERROR_NONE ||
667 ret == WIFI_DIRECT_ERROR_ALREADY_INITIALIZED)
669 WFD_APP_LOG(WFD_APP_LOG_ERROR, "Failed to initialize Wi-Fi Direct(%d)\n", ret);
677 ret = wifi_direct_set_device_state_changed_cb(_cb_activation, (void*) ad);
678 if (ret != WIFI_DIRECT_ERROR_NONE) {
679 WFD_APP_LOG(WFD_APP_LOG_ERROR, "Failed to register _cb_activation(%d)\n", ret);
683 ret = wifi_direct_set_connection_state_changed_cb(_cb_connection, (void*) ad);
684 if (ret != WIFI_DIRECT_ERROR_NONE) {
685 WFD_APP_LOG(WFD_APP_LOG_ERROR, "Failed to register _cb_connection(%d)\n", ret);
689 #ifdef WFD_FIVE_MIN_IDLE_DEACTIVATION
690 if (NULL == ad->monitor_timer) {
691 ad->last_wfd_time = time(NULL);
692 ad->monitor_timer = ecore_timer_add(5.0,
693 (Ecore_Task_Cb)_wfd_automatic_deactivated_for_no_connection_cb, ad);
696 __WFD_APP_FUNC_EXIT__;
701 * This function let the app do de-initialization
702 * @return If success, return TRUE, else return FALSE
703 * @param[in] ad the pointer to the main data structure
705 int deinit_wfd_client(wfd_appdata_t *ad)
707 __WFD_APP_FUNC_ENTER__;
711 WFD_APP_LOG(WFD_APP_LOG_LOW, "NULL parameter\n");
715 #ifdef WFD_FIVE_MIN_IDLE_DEACTIVATION
716 if (ad->monitor_timer) {
717 ecore_timer_del(ad->monitor_timer);
718 ad->monitor_timer = NULL;
722 ret = wifi_direct_unset_device_state_changed_cb();
723 if (ret != WIFI_DIRECT_ERROR_NONE)
724 WFD_APP_LOG(WFD_APP_LOG_ERROR, "Failed to deregister _cb_activation(%d)\n", ret);
726 ret = wifi_direct_unset_connection_state_changed_cb();
727 if (ret != WIFI_DIRECT_ERROR_NONE)
728 WFD_APP_LOG(WFD_APP_LOG_ERROR, "Failed to deregister _cb_connection(%d)\n", ret);
730 ret = wifi_direct_deinitialize();
731 if (ret != WIFI_DIRECT_ERROR_NONE)
732 WFD_APP_LOG(WFD_APP_LOG_ERROR, "Failed to deinitialize Wi-Fi Direct. error code = [%d]\n", ret);
734 __WFD_APP_FUNC_EXIT__;