24da12072ff96cf4f748c622734e85979c68759a
[apps/native/ug-wifi-efl.git] / sources / ui-gadget / viewers-layout / wifi_viewer_list.c
1 /*
2  * Wi-Fi
3  *
4  * Copyright 2012 Samsung Electronics Co., Ltd
5  *
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
9  *
10  * http://www.tizenopensource.org/license
11  *
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.
17  *
18  */
19
20 #include "common.h"
21 #include "ug_wifi.h"
22 #include "common_utils.h"
23 #include "common_generate_pin.h"
24 #include "connection_manager.h"
25 #include "wlan_manager.h"
26 #include "view_detail.h"
27 #include "viewer_list.h"
28 #include "viewer_manager.h"
29 #include "appcoreWrapper.h"
30 #include "i18nmanager.h"
31
32 #define LIST_ITEM_CONNECTED_AP_FONT_SIZE                28
33
34 static Evas_Object* viewer_list = NULL;
35 static Elm_Object_Item* first_item = NULL;
36 static Elm_Object_Item* last_item = NULL;
37
38 static Elm_Genlist_Item_Class *itc;
39 static Elm_Genlist_Item_Class *no_wifi_device_itc;
40 static Elm_Genlist_Item_Class *grouptitle_itc;
41 static Elm_Object_Item *grouptitle = NULL;
42
43 extern wifi_appdata *ug_app_state;
44
45 struct connecting_cancel_popup_data {
46         Evas_Object *popup;
47         wifi_ap_h ap;
48 };
49
50 static struct connecting_cancel_popup_data *g_disconnect_popup = NULL;
51
52 static void _gl_listview_more_btn_cb(void *data, Evas_Object *obj, void *event_info)
53 {
54         __COMMON_FUNC_ENTER__;
55
56         elm_object_disabled_set(obj, EINA_TRUE);
57
58         wifi_device_info_t *device_info = (wifi_device_info_t *)data;
59
60         if (data == NULL) {
61                 __COMMON_FUNC_EXIT__;
62                 return;
63         }
64
65         SECURE_DEBUG_LOG(UG_NAME_NORMAL, "ssid [%s]", device_info->ssid);
66
67         view_detail(device_info, ug_app_state->layout_main, obj);
68
69         __COMMON_FUNC_EXIT__;
70 }
71
72 char* ConvertRGBAtoHex(int r, int g, int b, int a)
73 {
74         int hexcolor = 0;
75         char* string = NULL;
76
77         string = g_try_malloc0(sizeof(char )* 255);
78         if (string != NULL) {
79                 hexcolor = (r << 24) + (g << 16) + (b << 8) + a;
80                 g_snprintf(string, sizeof(string), "%08x", hexcolor);
81         }
82
83         return string;
84 }
85
86 static char* _gl_listview_text_get(void *data, Evas_Object *obj, const char *part)
87 {
88         char* det = NULL;
89         char* buf = NULL;
90         char* convertedColor = NULL;
91
92         ug_genlist_data_t* gdata = (ug_genlist_data_t*) data;
93         retvm_if(NULL == gdata || NULL == gdata->device_info, NULL);
94
95         assertm_if(NULL == gdata->device_info->ssid, "NULL!!");
96
97         if (!strcmp("elm.text", part)) {
98                 det = evas_textblock_text_utf8_to_markup(NULL,
99                                 gdata->device_info->ssid);
100                 assertm_if(NULL == det, "NULL!!");
101
102                 convertedColor = ConvertRGBAtoHex(61, 185, 204, 255);
103                 assertm_if(NULL == convertedColor, "NULL!!");
104                 if (VIEWER_ITEM_RADIO_MODE_CONNECTED == gdata->radio_mode) {
105                         buf = g_strdup_printf("<color=#%s>%s</color>",
106                                 convertedColor, det);
107
108                         g_free(det);
109                         g_free(convertedColor);
110                         return buf;
111                 }
112         } else if (!strcmp("elm.text.sub", part)
113                         && gdata->device_info->ap_status_txt != NULL) {
114                 det = g_strdup(gdata->device_info->ap_status_txt);
115
116                 assertm_if(NULL == det, "NULL!!");
117         }
118         return det;
119 }
120
121 static Evas_Object *_gl_listview_content_get(void *data, Evas_Object *obj, const char *part)
122 {
123         ug_genlist_data_t *gdata = (ug_genlist_data_t *)data;
124         retvm_if(NULL == gdata, NULL);
125
126         Evas_Object *icon = NULL;
127         Evas_Object *btn = NULL;
128
129         if (gdata->device_info->ap_image_path == NULL) {
130                 /* if there is no ap_image_path (NO AP Found situation) */
131                 DEBUG_LOG(UG_NAME_ERR, "Fatal: Image path is NULL");
132
133         } else if (!strcmp("elm.swallow.icon", part)) {
134                 icon = elm_image_add(obj);
135                 retvm_if(NULL == icon, NULL);
136
137                 /* for strength */
138                 char *temp_str = NULL;
139                 temp_str = g_strdup_printf("%s.png", gdata->device_info->ap_image_path);
140                 elm_image_file_set(icon, CUSTOM_EDITFIELD_PATH, temp_str);
141                 g_free(temp_str);
142
143                 evas_object_color_set(icon, 2, 61, 132, 204);
144                 evas_object_size_hint_min_set(icon, ELM_SCALE_SIZE(DEFAULT_BUTTON_CIRCLE_SIZE), ELM_SCALE_SIZE(DEFAULT_BUTTON_CIRCLE_SIZE));
145
146         } else if (!strcmp("elm.swallow.end", part)) {
147                 if (VIEWER_ITEM_RADIO_MODE_CONNECTING == gdata->radio_mode ||
148                                 VIEWER_ITEM_RADIO_MODE_CONFIGURATION == gdata->radio_mode) {
149
150                         icon = elm_progressbar_add(obj);
151
152                         elm_object_style_set(icon, "process_medium");
153                         evas_object_size_hint_align_set(icon, EVAS_HINT_FILL, 0.5);
154                         evas_object_size_hint_weight_set(icon, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
155                         elm_progressbar_pulse(icon, TRUE);
156                         evas_object_propagate_events_set(icon, EINA_FALSE);
157
158                 } else {
159                         btn = elm_button_add(obj);
160                         elm_object_style_set(btn, "circle_custom");
161                         icon = elm_image_add(btn);
162                         elm_image_file_set(icon, CUSTOM_EDITFIELD_PATH, "wifi_icon_badge_info.png");
163                         elm_image_resizable_set(icon, EINA_TRUE, EINA_TRUE);
164                         elm_object_part_content_set(btn, "elm.swallow.content", icon);
165                         evas_object_propagate_events_set(btn, EINA_FALSE);
166                         evas_object_smart_callback_add(btn, "clicked", _gl_listview_more_btn_cb,gdata->device_info);
167                         evas_object_show(btn);
168
169                         return btn;
170                 }
171         }
172         return icon;
173 }
174
175 static void _gl_listview_del(void *data, Evas_Object *obj)
176 {
177         if (data == NULL)
178                 return;
179
180         ug_genlist_data_t *gdata = (ug_genlist_data_t *)data;
181         retm_if(NULL == gdata || NULL == gdata->device_info);
182
183         g_free(gdata->device_info->ap_image_path);
184         g_free(gdata->device_info->ap_status_txt);
185         g_free(gdata->device_info->ssid);
186         wifi_ap_destroy(gdata->device_info->ap);
187         g_free(gdata->device_info);
188         g_free(gdata);
189 }
190
191 static char *_gl_text_available_networks_get(void *data, Evas_Object *obj,
192                 const char *part)
193 {
194         if (!strcmp("elm.text", part))
195                 return g_strdup(sc(PACKAGE, I18N_TYPE_Available_networks));
196
197         return NULL;
198 }
199
200 static Evas_Object *_gl_content_scanning_icon_get(void *data, Evas_Object *obj,
201                 const char *part)
202 {
203         Evas_Object *title_progressbar = NULL;
204
205         if (HEADER_MODE_SEARCHING == viewer_manager_header_mode_get()) {
206                 title_progressbar  = elm_progressbar_add(obj);
207                 elm_object_style_set(title_progressbar, "process_small");
208                 elm_progressbar_horizontal_set(title_progressbar, EINA_TRUE);
209                 elm_progressbar_pulse(title_progressbar, EINA_TRUE);
210         }
211
212         return title_progressbar;
213 }
214
215 Elm_Object_Item* viewer_list_get_first_item(void)
216 {
217         return first_item;
218 }
219
220 Elm_Object_Item* viewer_list_get_last_item(void)
221 {
222         return last_item;
223 }
224
225 #ifdef ACCESSIBLITY_FEATURE
226 static char *_access_info_cb(void *data, Evas_Object *obj)
227 {
228         char *strength = NULL;
229         char *buf = NULL;
230
231         ug_genlist_data_t *gdata = (ug_genlist_data_t *)data;
232         if (!gdata) {
233                 return NULL;
234         }
235
236         strength = common_utils_get_rssi_text(PACKAGE, gdata->device_info->rssi);
237         buf = g_strdup_printf("%s. %s. %s.", strength, gdata->device_info->ssid, gdata->device_info->ap_status_txt);
238
239         g_free(strength);
240         return buf;
241 }
242 #endif
243
244 static void gl_lang_changed(void *data, Evas_Object *obj, void *event_info)
245 {
246         elm_genlist_realized_items_update(obj);
247 }
248
249 static void _gl_realized(void *data, Evas_Object *obj, void *event_info)
250 {
251 #ifdef ACCESSIBLITY_FEATURE
252         HEADER_MODES header_mode = viewer_manager_header_mode_get();
253         Elm_Object_Item *item = (Elm_Object_Item *)event_info;
254
255         if (header_mode == HEADER_MODE_ACTIVATING ||
256                 header_mode == HEADER_MODE_DEACTIVATING ||
257                 header_mode == HEADER_MODE_OFF) {
258                 return ;
259         }
260
261         Elm_Object_Item *first_item = viewer_list_get_first_item();
262         Elm_Object_Item *last_item = viewer_list_get_last_item();
263
264         if (first_item == NULL || last_item == NULL) {
265                 return;
266         }
267
268         int index = (int)elm_genlist_item_index_get(item);
269         int first_item_index = (int)elm_genlist_item_index_get(first_item);
270         int last_item_index = (int)elm_genlist_item_index_get(last_item);
271         char buf[100] = "";
272
273         if (first_item_index == -1) {
274                 int group_index = (int)elm_genlist_item_index_get(grouptitle);
275                 first_item_index = group_index + 1;
276         }
277
278         if (index >= first_item_index && index <= last_item_index &&
279                         first_item_index < last_item_index) {
280
281                 Evas_Object *ao = elm_object_item_access_object_get(item);
282                 elm_access_info_cb_set(ao, ELM_ACCESS_INFO, _access_info_cb, elm_object_item_data_get(item));
283                 g_snprintf(buf, sizeof(buf), "%s%s",
284                                                 sc(PACKAGE, I18N_TYPE_Double_tap),
285                                                 sc(PACKAGE, I18N_TYPE_Connect_to_device));
286                 elm_access_info_set(ao, ELM_ACCESS_TYPE, buf);
287                 elm_access_info_set(ao, ELM_ACCESS_STATE, sc(PACKAGE, I18N_TYPE_Wi_Fi_network_info));
288         }
289 #else
290         Elm_Object_Item *first_item = viewer_list_get_first_item();
291
292         if (first_item == NULL) {
293                 return;
294         }
295
296         int first_item_index = (int)elm_genlist_item_index_get(first_item);
297
298         if (first_item_index == -1) {
299                 int group_index = (int)elm_genlist_item_index_get(grouptitle);
300                 first_item_index = group_index + 1;
301         }
302 #endif
303 }
304
305 static void _info_popup_ok_cb(void *data, Evas_Object *obj, void *event_info)
306 {
307         pswd_popup_t *passpopup = (pswd_popup_t *)data;
308
309         if (passpopup != NULL && passpopup->info_popup != NULL) {
310                 evas_object_del(passpopup->info_popup);
311                 passpopup->info_popup = NULL;
312         }
313 }
314
315 static void __passwd_popup_cancel_cb(void *data,  Evas_Object *obj,
316                 void *event_info)
317 {
318         __COMMON_FUNC_ENTER__;
319
320         if (ug_app_state->passpopup == NULL) {
321                 return;
322         }
323
324         passwd_popup_free(ug_app_state->passpopup);
325         ug_app_state->passpopup = NULL;
326
327         if (data) {
328                 g_free(data);
329         }
330
331         __COMMON_FUNC_EXIT__;
332 }
333
334 static void __passwd_popup_ok_cb(void *data, Evas_Object *obj, void *event_info)
335 {
336         __COMMON_FUNC_ENTER__;
337
338         wifi_ap_h ap = NULL;
339         int password_len = 0;
340         const char *password = NULL;
341         wifi_security_type_e sec_type = WIFI_SECURITY_TYPE_NONE;
342
343         if (ug_app_state->passpopup == NULL) {
344                 return;
345         }
346
347         ap = passwd_popup_get_ap(ug_app_state->passpopup);
348         password = passwd_popup_get_txt(ug_app_state->passpopup);
349         if (password != NULL)
350                 password_len = strlen(password);
351
352         wifi_ap_get_security_type(ap, &sec_type);
353
354         switch (sec_type) {
355         case WIFI_SECURITY_TYPE_WEP:
356                 if (password_len != 5 && password_len != 13 &&
357                                 password_len != 26 && password_len != 10) {
358                         common_utils_send_message_to_net_popup(
359                                         "Network connection popup",
360                                         "wrong password", "toast_popup", NULL);
361
362                         if (ug_app_state->passpopup->entry) {
363                                 elm_object_focus_set(
364                                                 ug_app_state->passpopup->entry,
365                                                 EINA_TRUE);
366                         }
367                         goto failure;
368                 }
369                 break;
370
371         case WIFI_SECURITY_TYPE_WPA_PSK:
372         case WIFI_SECURITY_TYPE_WPA2_PSK:
373                 if (password_len < 8 || password_len > 64) {
374                         common_utils_send_message_to_net_popup(
375                                         "Network connection popup",
376                                         "wrong password", "toast_popup", NULL);
377
378                         if (ug_app_state->passpopup->entry) {
379                                 elm_object_focus_set(
380                                                 ug_app_state->passpopup->entry,
381                                                 EINA_TRUE);
382                         }
383                         goto failure;
384                 }
385                 break;
386
387         default:
388                 ERROR_LOG(UG_NAME_NORMAL, "Wrong security mode: %d", sec_type);
389                 passwd_popup_free(ug_app_state->passpopup);
390                 ug_app_state->passpopup = NULL;
391
392                 goto popup_ok_cb_exit;
393         }
394
395         bool favorite = FALSE;
396         if(wifi_ap_is_favorite(ap, &favorite) == WIFI_ERROR_NONE
397                 && favorite == TRUE) {
398                 wlan_manager_forget(ap);
399                 wifi_ap_refresh(ap);
400         }
401
402         if (ug_app_state->is_hidden) {
403                 wifi_ap_h hidden_ap;
404                 char *ssid;
405                 wifi_ap_get_essid(ap, &ssid);
406                 wifi_ap_hidden_create(ssid, &hidden_ap);
407                 g_free(ssid);
408                 wifi_ap_set_security_type(hidden_ap, sec_type);
409                 wlan_manager_connect_with_password(hidden_ap, password);
410         } else
411                 wlan_manager_connect_with_password(ap, password);
412
413         passwd_popup_free(ug_app_state->passpopup);
414         ug_app_state->passpopup = NULL;
415
416 popup_ok_cb_exit:
417         if (data) {
418                 g_free(data);
419         }
420
421 failure:
422         g_free((gpointer)password);
423
424         __COMMON_FUNC_EXIT__;
425 }
426
427 static void __wps_pbc_popup_cancel_connecting(void *data, Evas_Object *obj,
428                 void *event_info)
429 {
430         __COMMON_FUNC_ENTER__;
431
432         if (ug_app_state->passpopup == NULL) {
433                 return;
434         }
435
436         wifi_ap_h ap = passwd_popup_get_ap(ug_app_state->passpopup);
437
438         int ret = wlan_manager_disconnect(ap);
439         if (ret != WLAN_MANAGER_ERR_NONE) {
440                 ERROR_LOG(UG_NAME_NORMAL, "Failed WPS PBC cancellation [0x%x]", ap);
441         }
442
443         passwd_popup_free(ug_app_state->passpopup);
444         ug_app_state->passpopup = NULL;
445
446         viewer_manager_header_mode_set(HEADER_MODE_ON);
447         ug_app_state->is_wifi_scan_indication_block = 0;
448
449         __COMMON_FUNC_EXIT__;
450 }
451
452 static void _wps_btn_cb(void* data, Evas_Object* obj, void* event_info)
453 {
454         __COMMON_FUNC_ENTER__;
455
456         if (!ug_app_state->passpopup) {
457                 return;
458         }
459
460         ug_app_state->is_wifi_scan_indication_block = 1;
461         wifi_ap_h ap = passwd_popup_get_ap(ug_app_state->passpopup);
462         int ret = wlan_manager_wps_connect(ap);
463         if (ret == WLAN_MANAGER_ERR_NONE) {
464                 create_pbc_popup(ug_app_state->passpopup,
465                                 __wps_pbc_popup_cancel_connecting, NULL,
466                                 POPUP_WPS_BTN, NULL);
467         } else {
468                 ERROR_LOG(UG_NAME_NORMAL, "wlan_manager_wps_connect failed");
469                 passwd_popup_free(ug_app_state->passpopup);
470                 ug_app_state->passpopup = NULL;
471                 ug_app_state->is_wifi_scan_indication_block = 0;
472         }
473
474         __COMMON_FUNC_EXIT__;
475 }
476
477 static void _wps_cancel_cb(void* data, Evas_Object* obj, void* event_info)
478 {
479         __COMMON_FUNC_ENTER__;
480
481         ug_app_state->is_wifi_scan_indication_block = 0;
482
483         if (ug_app_state->passpopup == NULL) {
484                 return;
485         }
486
487         current_popup_free(ug_app_state->passpopup, POPUP_WPS_OPTIONS);
488
489         __COMMON_FUNC_EXIT__;
490 }
491
492 static void _wps_pin_cb(void* data, Evas_Object* obj, void* event_info)
493 {
494         __COMMON_FUNC_ENTER__;
495         unsigned int rpin = 0;
496         char npin[9] = { '\0' };
497         int pin_len = 0;
498         int ret = WLAN_MANAGER_ERR_NONE;
499         wifi_ap_h ap = NULL;
500         Evas_Object *info_popup = NULL;
501
502         if (!ug_app_state->passpopup) {
503                 return;
504         }
505
506         ug_app_state->is_wifi_scan_indication_block = 1;
507
508         /* Generate WPS pin */
509         rpin = wps_generate_pin();
510         if (rpin > 0)
511                 g_snprintf(npin, sizeof(npin), "%08d", rpin);
512
513         pin_len = strlen(npin);
514         if (pin_len != 8) {
515                 info_popup = common_utils_show_info_ok_popup(
516                                 ug_app_state->layout_main, PACKAGE,
517                                 sc(PACKAGE, I18N_TYPE_Invalid_pin),
518                                 _info_popup_ok_cb,
519                                 ug_app_state->passpopup);
520                 ug_app_state->passpopup->info_popup = info_popup;
521
522                 __COMMON_FUNC_EXIT__;
523                 return;
524         }
525
526         ap = passwd_popup_get_ap(ug_app_state->passpopup);
527
528         ret = wlan_manager_wps_pin_connect(ap, npin);
529         if (ret == WLAN_MANAGER_ERR_NONE) {
530                 INFO_LOG(UG_NAME_NORMAL, "wlan_manager_wps_pin_connect successful");
531
532                 create_pbc_popup(ug_app_state->passpopup,
533                                 __wps_pbc_popup_cancel_connecting, NULL,
534                                 POPUP_WPS_PIN, npin);
535         } else {
536                 ERROR_LOG(UG_NAME_NORMAL, "wlan_manager_wps_pin_connect failed");
537                 passwd_popup_free(ug_app_state->passpopup);
538                 ug_app_state->passpopup = NULL;
539                 ug_app_state->is_wifi_scan_indication_block = 0;
540         }
541
542         __COMMON_FUNC_EXIT__;
543 }
544
545 static void __wps_options_popup_cb(void* data, Evas_Object* obj, void* event_info)
546 {
547         __COMMON_FUNC_ENTER__;
548         pswd_popup_create_req_data_t popup_info;
549
550         if (!ug_app_state->passpopup) {
551                 return;
552         }
553
554         memset(&popup_info, 0, sizeof(pswd_popup_create_req_data_t));
555
556         popup_info.title = "IDS_WIFI_HEADER_SELECT_WPS_METHOD_ABB";
557         popup_info.ok_cb = NULL;
558         popup_info.cancel_cb = _wps_cancel_cb;
559         popup_info.show_wps_btn = EINA_FALSE;
560         popup_info.wps_btn_cb = _wps_btn_cb;
561         popup_info.wps_pin_cb = _wps_pin_cb;
562         popup_info.ap = passwd_popup_get_ap(ug_app_state->passpopup);
563         popup_info.cb_data = NULL;
564         create_wps_options_popup(ug_app_state->layout_main, ug_app_state->passpopup,
565                         &popup_info);
566
567         __COMMON_FUNC_EXIT__;
568 }
569
570 void viewer_list_wifi_reconnect(wifi_device_info_t *device_info)
571 {
572         pswd_popup_create_req_data_t popup_info;
573         wifi_security_type_e sec_type = WIFI_SECURITY_TYPE_NONE;
574         wifi_device_info_t *device_info_temp = NULL;
575         struct ug_data *ugd = (struct ug_data *)ug_app_state->gadget;
576
577         if (device_info == NULL)
578                 return;
579
580         if (ug_app_state->passpopup != NULL || ug_app_state->eap_view != NULL) {
581                 INFO_LOG(UG_NAME_ERR, "already launched popup");
582                 return;
583         }
584
585         wifi_ap_get_security_type(device_info->ap, &sec_type);
586
587         switch (sec_type) {
588         case WIFI_SECURITY_TYPE_WEP:
589         case WIFI_SECURITY_TYPE_WPA_PSK:
590         case WIFI_SECURITY_TYPE_WPA2_PSK:
591                 memset(&popup_info, 0, sizeof(pswd_popup_create_req_data_t));
592
593                 device_info_temp = view_list_item_device_info_create(device_info->ap);
594
595                 popup_info.title = device_info->ssid;
596                 popup_info.ok_cb = __passwd_popup_ok_cb;
597                 popup_info.cancel_cb = __passwd_popup_cancel_cb;
598                 popup_info.show_wps_btn = device_info->wps_mode;
599                 popup_info.wps_btn_cb = __wps_options_popup_cb;
600                 popup_info.ap = device_info->ap;
601                 popup_info.cb_data = device_info_temp;
602                 popup_info.sec_type = sec_type;
603
604                 /* TODO: parameter with device_info */
605                 /* TODO: finally parameter with wifi_ap_h, WPA, EAP */
606                 ug_app_state->passpopup = create_passwd_popup(
607                                 ug_app_state->conformant,
608                                 ug_app_state->layout_main, PACKAGE, &popup_info);
609
610                 if (ug_app_state->passpopup == NULL) {
611                         INFO_LOG(UG_NAME_ERR, "Fail to create password popup");
612                 }
613
614                 break;
615         case WIFI_SECURITY_TYPE_EAP:
616                 ug_app_state->eap_view = create_eap_view(
617                                 ug_app_state->layout_main, ugd->win_main,
618                                 ug_app_state->conformant,
619                                 PACKAGE, device_info,
620                                 viewer_manager_eap_view_deref);
621                 break;
622         default:
623                 ERROR_LOG(UG_NAME_NORMAL, "Unknown security type [%d]", sec_type);
624                 return;
625         }
626
627 }
628
629 void viewer_list_wifi_connect(wifi_device_info_t *device_info)
630 {
631         bool favorite = false;
632         pswd_popup_create_req_data_t popup_info;
633         wifi_security_type_e sec_type = WIFI_SECURITY_TYPE_NONE;
634         wifi_device_info_t *dev_info_temp = NULL;
635         struct ug_data *ugd = (struct ug_data *)ug_app_state->gadget;
636
637         if (device_info == NULL)
638                 return;
639
640         wifi_ap_is_favorite(device_info->ap, &favorite);
641         if (favorite == true) {
642                 wlan_manager_connect(device_info->ap);
643                 return;
644         }
645
646         if (ug_app_state->passpopup != NULL || ug_app_state->eap_view != NULL) {
647                 INFO_LOG(UG_NAME_ERR, "already launched popup");
648                 return;
649         }
650
651         wifi_ap_get_security_type(device_info->ap, &sec_type);
652
653         switch (sec_type) {
654         case WIFI_SECURITY_TYPE_NONE:
655                 if(ug_app_state->is_hidden) {
656                         wifi_ap_h ap;
657                         char *ssid;
658                         wifi_ap_get_essid(device_info->ap, &ssid);
659                         wifi_ap_hidden_create(ssid, &ap);
660                         g_free(ssid);
661                         wifi_ap_set_security_type(ap, WIFI_SECURITY_TYPE_NONE);
662                         wlan_manager_connect(ap);
663                 } else
664                         wlan_manager_connect(device_info->ap);
665                 break;
666
667         case WIFI_SECURITY_TYPE_WEP:
668         case WIFI_SECURITY_TYPE_WPA_PSK:
669         case WIFI_SECURITY_TYPE_WPA2_PSK:
670                 memset(&popup_info, 0, sizeof(pswd_popup_create_req_data_t));
671
672                 dev_info_temp = view_list_item_device_info_create(device_info->ap);
673
674                 popup_info.title = device_info->ssid;
675                 popup_info.ok_cb = __passwd_popup_ok_cb;
676                 popup_info.cancel_cb = __passwd_popup_cancel_cb;
677                 popup_info.show_wps_btn = device_info->wps_mode;
678                 popup_info.wps_btn_cb = __wps_options_popup_cb;
679                 popup_info.ap = device_info->ap;
680                 popup_info.cb_data = dev_info_temp;
681                 popup_info.sec_type = sec_type;
682
683                 /* TODO: parameter with device_info */
684                 /* TODO: finally parameter with wifi_ap_h, WPA, EAP */
685                 ug_app_state->passpopup = create_passwd_popup(
686                                 ug_app_state->conformant,
687                                 ug_app_state->layout_main, PACKAGE, &popup_info);
688
689                 if (ug_app_state->passpopup == NULL) {
690                         INFO_LOG(UG_NAME_ERR, "Fail to create password popup");
691                 }
692
693                 break;
694
695         case WIFI_SECURITY_TYPE_EAP:
696                 ug_app_state->eap_view = create_eap_view(
697                                 ug_app_state->layout_main, ugd->win_main,
698                                 ug_app_state->conformant,
699                                 PACKAGE, device_info,
700                                 viewer_manager_eap_view_deref);
701                 break;
702
703         default:
704                 ERROR_LOG(UG_NAME_NORMAL, "Unknown security type[%d]", sec_type);
705                 break;
706         }
707 }
708
709 void viewer_list_clear_disconnect_popup(wifi_ap_h ap)
710 {
711         if (!g_disconnect_popup)
712                 return;
713
714         if (ap && g_disconnect_popup->ap &&
715                         wlan_manager_is_same_network(g_disconnect_popup->ap, ap) != TRUE)
716                 return;
717
718         if (g_disconnect_popup->popup)
719                 evas_object_del(g_disconnect_popup->popup);
720
721         if (g_disconnect_popup->ap)
722                 wifi_ap_destroy(g_disconnect_popup->ap);
723
724         g_free(g_disconnect_popup);
725         g_disconnect_popup = NULL;
726 }
727
728 static void __viewer_list_disconnect_cancel_cb(void *data,
729                 Evas_Object *obj, void *event_info)
730 {
731         struct connecting_cancel_popup_data *popup =
732                         (struct connecting_cancel_popup_data *)data;
733         if (!popup)
734                 return;
735
736         if (popup->popup)
737                 evas_object_del(popup->popup);
738
739         if (popup->ap)
740                 wifi_ap_destroy(popup->ap);
741
742         g_free(popup);
743         g_disconnect_popup = NULL;
744 }
745
746 static gboolean __viewer_list_update_ap(gpointer data)
747 {
748         wifi_ap_h ap = (wifi_ap_h)data;
749
750         viewer_manager_update_item_favorite_status(ap);
751         wifi_ap_destroy(ap);
752
753         return FALSE;
754 }
755
756 static void __viewer_list_disconnect_ok_cb(void *data,
757                 Evas_Object *obj, void *event_info)
758 {
759         guint id;
760         struct connecting_cancel_popup_data *popup =
761                         (struct connecting_cancel_popup_data *)data;
762         if (!popup)
763                 return;
764
765         wlan_manager_disconnect(popup->ap);
766         wlan_manager_forget(popup->ap);
767
768         if (popup->popup)
769                 evas_object_del(popup->popup);
770
771         id = common_util_managed_idle_add(__viewer_list_update_ap, (gpointer)popup->ap);
772         if (!id) {
773                 viewer_manager_update_item_favorite_status(popup->ap);
774                 wifi_ap_destroy(popup->ap);
775         }
776
777         g_free(popup);
778         g_disconnect_popup = NULL;
779 }
780
781 static void __viewer_list_disconnect_popup(wifi_device_info_t *device_info,
782                 Evas_Object *win_main)
783 {
784         popup_btn_info_t popup_data;
785         struct connecting_cancel_popup_data *popup = NULL;
786
787         memset(&popup_data, 0, sizeof(popup_data));
788
789         popup = g_try_new0(struct connecting_cancel_popup_data, 1);
790         if (!popup)
791                 return;
792
793         g_disconnect_popup = popup;
794         wifi_ap_clone(&popup->ap, device_info->ap);
795
796         popup_data.title_txt = "IDS_WIFI_OPT_FORGET_NETWORK";
797         popup_data.info_txt = "IDS_WIFI_POP_CURRENT_NETWORK_WILL_BE_DISCONNECTED";
798         popup_data.btn1_cb = __viewer_list_disconnect_cancel_cb;
799         popup_data.btn1_txt = "IDS_WIFI_SK_CANCEL";
800         popup_data.btn1_data = popup;
801         popup_data.btn2_cb = __viewer_list_disconnect_ok_cb;
802         popup_data.btn2_txt = "IDS_WIFI_SK_FORGET";
803         popup_data.btn2_data = popup;
804
805         popup->popup = common_utils_show_info_popup(win_main, &popup_data);
806 }
807
808 static void __viewer_list_item_clicked_cb(void *data, Evas_Object *obj,
809                 void *event_info)
810 {
811         __COMMON_FUNC_ENTER__;
812
813         assertm_if(NULL == event_info, "event_info is NULL!!");
814         assertm_if(NULL == obj, "obj is NULL!!");
815
816         Elm_Object_Item *it = (Elm_Object_Item *)event_info;
817         ug_genlist_data_t *gdata = NULL;
818         wifi_device_info_t *device_info = NULL;
819
820         gdata = (ug_genlist_data_t *)elm_object_item_data_get(it);
821         retm_if(NULL == gdata);
822
823         device_info = gdata->device_info;
824         retm_if(NULL == device_info || NULL == device_info->ssid);
825
826         int item_state = gdata->radio_mode;
827         int current_state = 0;
828
829         SECURE_INFO_LOG(UG_NAME_NORMAL, "ssid --- %s", device_info->ssid);
830         INFO_LOG(UG_NAME_NORMAL, "ap --- 0x%x", device_info->ap);
831         INFO_LOG(UG_NAME_NORMAL, "current item_state state is --- %d", item_state);
832
833         if (ug_app_state->is_lbhome == EINA_TRUE &&
834                         ug_app_state->app_control != NULL) {
835                 INFO_LOG(UG_NAME_NORMAL, "exit with reply");
836                 char *bssid = NULL;
837                 app_control_h reply;
838
839                 app_control_create(&reply);
840                 wifi_ap_get_bssid(device_info->ap, &bssid);
841                 SECURE_INFO_LOG(UG_NAME_NORMAL, "bssid %s, ssid %s", bssid, device_info->ssid);
842
843                 app_control_add_extra_data(reply, "bssid", bssid);
844                 app_control_add_extra_data(reply, "ssid", device_info->ssid);
845                 app_control_reply_to_launch_request(reply, ug_app_state->app_control,
846                                 APP_CONTROL_RESULT_SUCCEEDED);
847                 app_control_destroy(reply);
848                 g_free(bssid);
849                 wifi_exit();
850                 return;
851         }
852
853         switch (item_state) {
854         case VIEWER_ITEM_RADIO_MODE_OFF:
855                 current_state = viewer_manager_header_mode_get();
856
857                 INFO_LOG(UG_NAME_NORMAL, "Clicked AP information\n");
858                 INFO_LOG(UG_NAME_NORMAL, "header mode [%d]", current_state);
859
860                 switch (current_state) {
861                 case HEADER_MODE_ON:
862                 case HEADER_MODE_CONNECTED:
863                 case HEADER_MODE_CONNECTING:
864                 case HEADER_MODE_SEARCHING:
865                         viewer_list_wifi_connect(device_info);
866                         break;
867
868                 case HEADER_MODE_OFF:
869                 case HEADER_MODE_ACTIVATING:
870                 case HEADER_MODE_DEACTIVATING:
871                 default:
872                         INFO_LOG(UG_NAME_NORMAL, "Ignore click");
873                         break;
874                 }
875                 break;
876
877         case VIEWER_ITEM_RADIO_MODE_CONNECTING:
878         case VIEWER_ITEM_RADIO_MODE_CONFIGURATION:
879                 __viewer_list_disconnect_popup(device_info, ug_app_state->layout_main);
880                 break;
881         case VIEWER_ITEM_RADIO_MODE_CONNECTED:
882         default:
883                 INFO_LOG(UG_NAME_NORMAL, "Ignore click");
884                 break;
885         }
886
887         elm_genlist_item_selected_set((Elm_Object_Item *)event_info, EINA_FALSE);
888
889         __COMMON_FUNC_EXIT__;
890 }
891
892 static char *viewer_list_get_device_status_txt(wifi_device_info_t *wifi_device,
893                 VIEWER_ITEM_RADIO_MODES mode)
894 {
895         char *status_txt = NULL;
896         int current_state = 0;
897
898         current_state = viewer_manager_header_mode_get();
899         /* The strings are currently hard coded. It will be replaced with string ids later */
900         if (VIEWER_ITEM_RADIO_MODE_CONNECTING == mode) {
901                 status_txt = g_strdup(sc(PACKAGE, I18N_TYPE_Connecting));
902         } else if (VIEWER_ITEM_RADIO_MODE_CONFIGURATION == mode) {
903                 status_txt = g_strdup(sc(PACKAGE, I18N_TYPE_Obtaining_IP_addr));
904         } else if (VIEWER_ITEM_RADIO_MODE_CONNECTED == mode) {
905                 if (connection_manager_is_wifi_connection_used() ||
906                                 current_state == HEADER_MODE_CONNECTED ) {
907                         status_txt = g_strdup(sc(PACKAGE, I18N_TYPE_Connected));
908                 }
909         } else if (VIEWER_ITEM_RADIO_MODE_OFF == mode) {
910                 status_txt = common_utils_get_ap_security_type_info_txt(PACKAGE,
911                         wifi_device, true);
912         } else {
913                 status_txt = g_strdup(sc(PACKAGE, I18N_TYPE_Unknown));
914                 INFO_LOG(UG_NAME_NORMAL, "Invalid mode: %d", mode);
915         }
916
917         return status_txt;
918 }
919
920 Evas_Object* viewer_list_create(Evas_Object *win)
921 {
922         __COMMON_FUNC_ENTER__;
923
924         assertm_if(NULL == win, "NULL!!");
925         assertm_if(NULL != viewer_list, "Err!!");
926
927         viewer_list = elm_genlist_add(win);
928         assertm_if(NULL == viewer_list, "NULL!!");
929
930         // To use multiline textblock/entry/editfield in genlist, set height_for_width mode
931         // then the item's height is calculated while the item's width fits to genlist width.
932         elm_genlist_mode_set(viewer_list, ELM_LIST_COMPRESS);
933         //elm_genlist_realization_mode_set(viewer_list, EINA_TRUE);
934
935         evas_object_size_hint_weight_set(viewer_list, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
936         evas_object_size_hint_align_set(viewer_list, EVAS_HINT_FILL, EVAS_HINT_FILL);
937
938         itc = elm_genlist_item_class_new();
939         itc->item_style = WIFI_GENLIST_2LINE_TOP_TEXT_ICON_STYLE;
940         itc->func.text_get = _gl_listview_text_get;
941         itc->func.content_get = _gl_listview_content_get;
942         itc->func.state_get = NULL;
943         itc->func.del = _gl_listview_del;
944
945         no_wifi_device_itc = elm_genlist_item_class_new();
946         no_wifi_device_itc->item_style = WIFI_GENLIST_1LINE_TEXT_STYLE;
947         no_wifi_device_itc->func.text_get = _gl_listview_text_get;
948         no_wifi_device_itc->func.content_get = NULL;
949         no_wifi_device_itc->func.state_get = NULL;
950         no_wifi_device_itc->func.del = _gl_listview_del;
951
952         first_item = last_item = NULL;
953
954         evas_object_smart_callback_add(viewer_list, "realized",
955                         _gl_realized, NULL);
956         evas_object_smart_callback_add(viewer_list, "language,changed",
957                         gl_lang_changed, NULL);
958
959         __COMMON_FUNC_EXIT__;
960         return viewer_list;
961 }
962
963 void viewer_list_title_item_del(void)
964 {
965         if (grouptitle != NULL) {
966                 elm_object_item_del(grouptitle);
967                 grouptitle = NULL;
968         }
969 }
970
971 void viewer_list_title_item_update(void)
972 {
973         if (grouptitle != NULL)
974                 elm_genlist_item_update(grouptitle);
975 }
976
977 void viewer_list_title_item_set(Elm_Object_Item *item_header)
978 {
979         if (item_header == NULL)
980                 return;
981
982         if (grouptitle != NULL) {
983                 elm_genlist_item_update(grouptitle);
984                 return;
985         }
986
987         //memset(&grouptitle_itc, 0, sizeof(grouptitle_itc));
988         grouptitle_itc = elm_genlist_item_class_new();
989         grouptitle_itc->item_style = WIFI_GENLIST_GROUP_INDEX_STYLE;
990         grouptitle_itc->func.text_get = _gl_text_available_networks_get;
991         grouptitle_itc->func.content_get = _gl_content_scanning_icon_get;
992
993         grouptitle = elm_genlist_item_insert_after(viewer_list,
994                         grouptitle_itc, NULL, NULL, item_header,
995                         ELM_GENLIST_ITEM_NONE, NULL, NULL);
996
997         assertm_if(NULL == grouptitle, "NULL!!");
998
999         elm_genlist_item_select_mode_set(grouptitle,
1000                         ELM_OBJECT_SELECT_MODE_DISPLAY_ONLY);
1001 }
1002
1003 int viewer_list_item_radio_mode_set(Elm_Object_Item* item,
1004                 VIEWER_ITEM_RADIO_MODES mode)
1005 {
1006         __COMMON_FUNC_ENTER__;
1007
1008         if (NULL == item) {
1009                 INFO_LOG(COMMON_NAME_ERR, "item is NULL");
1010                 return FALSE;
1011         }
1012
1013         ug_genlist_data_t* gdata = (ug_genlist_data_t *) elm_object_item_data_get(item);
1014         if (NULL == gdata || NULL == gdata->device_info) {
1015                 INFO_LOG(COMMON_NAME_ERR, "gdata or device_info is NULL");
1016                 return FALSE;
1017         }
1018
1019         if (gdata->radio_mode == mode) {
1020                 SECURE_INFO_LOG(UG_NAME_NORMAL, "[%s] is already in requested state", gdata->device_info->ssid);
1021                 return FALSE;
1022         }
1023
1024         SECURE_INFO_LOG(UG_NAME_NORMAL, "[%s] AP Item State Transition from [%d] --> [%d]", gdata->device_info->ssid, gdata->radio_mode, mode);
1025         gdata->radio_mode = mode;
1026         if (gdata->device_info->ap_status_txt) {
1027                 g_free(gdata->device_info->ap_status_txt);
1028                 gdata->device_info->ap_status_txt = viewer_list_get_device_status_txt(gdata->device_info, mode);
1029         }
1030
1031         if(item != NULL)
1032                 elm_genlist_item_update(item);
1033
1034         __COMMON_FUNC_EXIT__;
1035         return TRUE;
1036 }
1037
1038 #ifndef TIZEN_EMULATOR
1039 static wifi_connection_state_e _convert_wifi_state_to_viewer_radio_mode(
1040                 wifi_connection_state_e state)
1041 {
1042         switch (state) {
1043                 case WIFI_CONNECTION_STATE_ASSOCIATION:
1044                         return VIEWER_ITEM_RADIO_MODE_CONNECTING;
1045                 case WIFI_CONNECTION_STATE_CONFIGURATION:
1046                         return VIEWER_ITEM_RADIO_MODE_CONFIGURATION;
1047                 case WIFI_CONNECTION_STATE_CONNECTED:
1048                         return VIEWER_ITEM_RADIO_MODE_CONNECTED;
1049                 default:
1050                         return VIEWER_ITEM_RADIO_MODE_OFF;
1051         }
1052 }
1053 #endif
1054
1055 Elm_Object_Item *viewer_list_item_insert_after(wifi_device_info_t *wifi_device,
1056                 Elm_Object_Item *after)
1057 {
1058         Elm_Object_Item* ret = NULL;
1059         ug_genlist_data_t* gdata = NULL;
1060         wifi_device_info_t *no_wifi_device = NULL;
1061         retvm_if(NULL == viewer_list, NULL);
1062
1063 #ifdef TIZEN_EMULATOR
1064         if (wifi_device != NULL) {
1065                 wifi_device->ap_status_txt = viewer_list_get_device_status_txt(
1066                                                 wifi_device,
1067                                                 VIEWER_ITEM_RADIO_MODE_OFF);
1068         } else {
1069                 no_wifi_device = g_try_new0(wifi_device_info_t, 1);
1070                 if (no_wifi_device == NULL)
1071                         return NULL;
1072
1073                 no_wifi_device->ssid = g_strdup(sc(PACKAGE, I18N_TYPE_No_Wi_Fi_AP_Found));
1074                 wifi_device = no_wifi_device;
1075         }
1076 #else
1077         wifi_connection_state_e state = WIFI_CONNECTION_STATE_DISCONNECTED;
1078         VIEWER_ITEM_RADIO_MODES rad_mode = VIEWER_ITEM_RADIO_MODE_OFF;
1079         if (wifi_device != NULL && wifi_device->ap != NULL) {
1080                 if (wifi_ap_get_connection_state(wifi_device->ap, &state) ==
1081                                 WIFI_ERROR_NONE) {
1082                         rad_mode = _convert_wifi_state_to_viewer_radio_mode(state);
1083                 }
1084                 wifi_device->ap_status_txt = viewer_list_get_device_status_txt(
1085                                                 wifi_device,
1086                                                 rad_mode);
1087         } else {
1088                 if (ug_app_state->is_first_scan == true) {
1089                         int scan_result = wlan_manager_scan();
1090                         if (scan_result != WLAN_MANAGER_ERR_NONE) {
1091                                 viewer_manager_hide(VIEWER_WINSET_SEARCHING);
1092                                 viewer_manager_header_mode_set(viewer_manager_header_mode_get());
1093                         }
1094                         ug_app_state->is_first_scan = false;
1095                         return NULL;
1096                 }
1097                 no_wifi_device = g_try_new0(wifi_device_info_t, 1);
1098                 if (no_wifi_device == NULL)
1099                         return NULL;
1100
1101                 no_wifi_device->ssid = g_strdup(sc(PACKAGE, I18N_TYPE_No_Wi_Fi_AP_Found));
1102                 wifi_device = no_wifi_device;
1103         }
1104 #endif
1105
1106         gdata = g_try_new0(ug_genlist_data_t, 1);
1107         retvm_if(NULL == gdata, NULL);
1108         gdata->device_info = wifi_device;
1109         gdata->radio_mode = VIEWER_ITEM_RADIO_MODE_OFF;
1110
1111         if (!after) {
1112                 /* If the after item is NULL then insert it as first item */
1113                 after = grouptitle;
1114         }
1115
1116         if (no_wifi_device == NULL) {
1117                 ret = elm_genlist_item_insert_after(
1118                                 viewer_list, /*obj*/
1119                                 itc,/*itc*/
1120                                 gdata,/*data*/
1121                                 NULL,/*parent*/
1122                                 after, /*after than*/
1123                                 ELM_GENLIST_ITEM_NONE, /*flags*/
1124                                 __viewer_list_item_clicked_cb,/*func*/
1125                                 NULL);/*func_data*/
1126         } else {
1127                 ret = elm_genlist_item_insert_after(
1128                                 viewer_list, /*obj*/
1129                                 no_wifi_device_itc,/*itc*/
1130                                 gdata,/*data*/
1131                                 NULL,/*parent*/
1132                                 after, /*after than*/
1133                                 ELM_GENLIST_ITEM_NONE, /*flags*/
1134                                 __viewer_list_item_clicked_cb,/*func*/
1135                                 NULL);/*func_data*/
1136         }
1137
1138         if (!ret) {
1139                 assertm_if(NULL == ret, "NULL!!");
1140                 g_free(gdata);
1141         } else {
1142                 /* SECURE_DEBUG_LOG(UG_NAME_NORMAL,
1143                                 "* item add complete item [0x%x] ssid:[%s] security[%d] size:[%d]",
1144                                 ret,
1145                                 wifi_device->ssid,
1146                                 wifi_device->security_mode,
1147                                 viewer_list_item_size_get()); */
1148
1149                 if (after == grouptitle) {
1150                         first_item = ret;
1151                         if (!last_item) {
1152                                 last_item = ret;
1153                         }
1154                 } else {
1155                         last_item = ret;
1156                         if (!first_item) {
1157                                 first_item = ret;
1158                         }
1159                 }
1160
1161                 if(ret != NULL)
1162                         elm_genlist_item_update(ret);
1163         }
1164
1165         return ret;
1166 }
1167
1168 void viewer_list_item_del(Elm_Object_Item *it)
1169 {
1170         if (it == NULL) {
1171                 return;
1172         }
1173
1174         if (it == first_item) {
1175                 first_item = elm_genlist_item_next_get(first_item);
1176         } else if (it == last_item) {
1177                 last_item = elm_genlist_item_prev_get(last_item);
1178         }
1179         elm_object_item_del(it);
1180 }
1181
1182 int viewer_list_item_size_get()
1183 {
1184         int ret = 0;
1185         Elm_Object_Item *it = first_item;
1186
1187         while(it) {
1188                 ret++;
1189                 if (it == last_item) {
1190                         break;
1191                 }
1192                 it = elm_genlist_item_next_get(it);
1193         }
1194
1195         return ret;
1196 }
1197
1198 void viewer_list_item_clear(void)
1199 {
1200         __COMMON_FUNC_ENTER__;
1201
1202         Elm_Object_Item *it = first_item;
1203         Elm_Object_Item *nxt = NULL;
1204
1205         while(it) {
1206                 nxt = elm_genlist_item_next_get(it);
1207                 elm_object_item_del(it);
1208                 if (it == last_item) {
1209                         break;
1210                 }
1211                 it = nxt;
1212         }
1213
1214         first_item = last_item = NULL;
1215
1216         __COMMON_FUNC_EXIT__;
1217 }
1218
1219 void viewer_list_item_enable_all(void)
1220 {
1221         __COMMON_FUNC_ENTER__;
1222
1223         Elm_Object_Item *it = first_item;
1224
1225         while(it) {
1226                 elm_object_item_disabled_set(it, EINA_FALSE);
1227
1228                 if (it == last_item) {
1229                         break;
1230                 }
1231
1232                 it = elm_genlist_item_next_get(it);
1233         }
1234
1235         __COMMON_FUNC_EXIT__;
1236 }
1237
1238 void viewer_list_item_disable_all(void)
1239 {
1240         __COMMON_FUNC_ENTER__;
1241
1242         Elm_Object_Item *it = first_item;
1243
1244         while(it) {
1245                 elm_object_item_disabled_set(it, EINA_TRUE);
1246
1247                 if (it == last_item) {
1248                         break;
1249                 }
1250
1251                 it = elm_genlist_item_next_get(it);
1252         }
1253
1254         __COMMON_FUNC_EXIT__;
1255 }
1256
1257 Elm_Object_Item* item_get_for_ap(wifi_ap_h ap)
1258 {
1259         __COMMON_FUNC_ENTER__;
1260         if (!ap) {
1261                 __COMMON_FUNC_EXIT__;
1262                 return NULL;
1263         }
1264
1265         char *essid = NULL;
1266         wifi_security_type_e type = WIFI_SECURITY_TYPE_NONE;
1267
1268         if (WIFI_ERROR_NONE != wifi_ap_get_essid(ap, &essid)) {
1269                 __COMMON_FUNC_EXIT__;
1270                 return NULL;
1271         } else if (WIFI_ERROR_NONE != wifi_ap_get_security_type(ap, &type)) {
1272                 __COMMON_FUNC_EXIT__;
1273                 return NULL;
1274         }
1275
1276         Elm_Object_Item *it = first_item;
1277         wlan_security_mode_type_t sec_mode = common_utils_get_sec_mode(type);
1278         while(it) {
1279                 ug_genlist_data_t* gdata = elm_object_item_data_get(it);
1280                 wifi_device_info_t *device_info = NULL;
1281                 if (gdata && (device_info = gdata->device_info)) {
1282                         if (!g_strcmp0(device_info->ssid, essid) && device_info->security_mode == sec_mode) {
1283                                 break;
1284                         }
1285                 }
1286                 if (it == last_item) {
1287                         it = NULL;
1288                         break;
1289                 }
1290                 it = elm_genlist_item_next_get(it);
1291         }
1292
1293         g_free(essid);
1294         __COMMON_FUNC_EXIT__;
1295         return it;
1296 }
1297
1298 Elm_Object_Item* item_get_for_ssid(const char *ssid)
1299 {
1300         Elm_Object_Item *it = first_item;
1301         while (it) {
1302                 ug_genlist_data_t* gdata = elm_object_item_data_get(it);
1303                 wifi_device_info_t *device_info = NULL;
1304                 if (gdata && (device_info = gdata->device_info)) {
1305                         if (!g_strcmp0(device_info->ssid, ssid)) {
1306                                 break;
1307                         }
1308                 }
1309                 if (it == last_item) {
1310                         it = NULL;
1311                         break;
1312                 }
1313                 it = elm_genlist_item_next_get(it);
1314         }
1315
1316         return it;
1317 }