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