Removed build warnings and deprecated function
[apps/native/ug-wifi-efl.git] / sources / libraries / Common / common_eap_connect.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 <openssl/x509.h>
21 #include <openssl/pem.h>
22 #include <cert-svc/cpkcs12.h>
23 #include <cert-svc/cprimitives.h>
24 #include <ui-gadget.h>
25 #include <efl_assist.h>
26 #include <vconf-keys.h>
27 #include <glib/gstdio.h>
28 #include <efl_extension.h>
29
30 #include "common.h"
31 #include "ug_wifi.h"
32 #include "common_eap_connect.h"
33 #include "i18nmanager.h"
34 #include "common_utils.h"
35 #include "common_ip_info.h"
36
37 #define GENLIST_ITEM_HEIGHT                             96
38
39 #define EAP_TLS_PATH                    "/tmp/"
40 #define EAP_TLS_CA_CERT_PATH            "ca_cert.pem"
41 #define EAP_TLS_USER_CERT_PATH          "user_cert.pem"
42 #define EAP_TLS_PRIVATEKEY_PATH         "privatekey.pem"
43
44 #define EAP_TYPE_UNKNOWN                "UNKNOWN"
45 #define EAP_TYPE_PEAP                   "PEAP"
46 #define EAP_TYPE_TLS                            "TLS"
47 #define EAP_TYPE_TTLS                   "TTLS"
48 #define EAP_TYPE_SIM                            "SIM"
49 #define EAP_TYPE_AKA                            "AKA"
50
51 #define EAP_AUTH_TYPE_PAP                       "PAP"
52 #define EAP_AUTH_TYPE_MSCHAP                            "MSCHAP"
53 #define EAP_AUTH_TYPE_MSCHAPV2                  "MSCHAPV2"
54 #define EAP_AUTH_TYPE_GTC                               "GTC"
55 #define EAP_AUTH_TYPE_MD5                               "MD5"
56 #define VCONF_TELEPHONY_DEFAULT_DATA_SERVICE    "db/telephony/dualsim/default_data_service"
57
58 typedef enum {
59         EAP_SEC_TYPE_UNKNOWN  = 0,
60         EAP_SEC_TYPE_PEAP,
61         EAP_SEC_TYPE_TLS,
62         EAP_SEC_TYPE_TTLS,
63         EAP_SEC_TYPE_SIM,
64         EAP_SEC_TYPE_AKA,
65         EAP_SEC_TYPE_NULL
66 } eap_type_t;
67
68 typedef enum {
69         EAP_SEC_AUTH_NONE  = 0,
70         EAP_SEC_AUTH_PAP,
71         EAP_SEC_AUTH_MSCHAP,
72         EAP_SEC_AUTH_MSCHAPV2,
73         EAP_SEC_AUTH_GTC,
74         EAP_SEC_AUTH_MD5,
75         EAP_SEC_AUTH_NULL
76 } eap_auth_t;
77
78 typedef enum {
79         EAP_TYPE_BTN = 0,
80         EAP_AUTH_BTN,
81         EAP_CERT_BTN,
82 } eap_btn_t;
83
84 typedef struct {
85         char *name;
86         Elm_Genlist_Item_Type flags;
87 } _Expand_List_t;
88
89 typedef struct {
90         int btn_click[3];
91         Evas_Object *btn_obj[3];
92 } _Btn_click_t;
93
94 struct eap_info_list {
95         wifi_ap_h ap;
96         eap_type_t eap_type;
97         Elm_Object_Item *eap_method_item;
98         Elm_Object_Item *eap_auth_item;
99         Elm_Object_Item *user_cert_item;
100         Elm_Object_Item *id_item;
101         Elm_Object_Item *pswd_item;
102 };
103
104 static const _Expand_List_t list_eap_type[] = {
105         {"UNKNOWN", ELM_GENLIST_ITEM_NONE},
106         {"PEAP", ELM_GENLIST_ITEM_NONE},
107         {"TLS", ELM_GENLIST_ITEM_NONE},
108         {"TTLS", ELM_GENLIST_ITEM_NONE},
109         {"SIM", ELM_GENLIST_ITEM_NONE},
110         {"AKA", ELM_GENLIST_ITEM_NONE},
111         {NULL, ELM_GENLIST_ITEM_NONE}
112 };
113
114 static const _Expand_List_t list_eap_auth[] = {
115         {"IDS_ST_BODY_NONE", ELM_GENLIST_ITEM_NONE},
116         {"PAP", ELM_GENLIST_ITEM_NONE},
117         {"MSCHAP", ELM_GENLIST_ITEM_NONE},
118         {"MSCHAPV2", ELM_GENLIST_ITEM_NONE},
119         {"GTC", ELM_GENLIST_ITEM_NONE},
120         {NULL, ELM_GENLIST_ITEM_NONE}
121 };
122
123 static unsigned short selected_cert = 0;
124
125 struct common_eap_connect_data {
126         Elm_Object_Item *eap_type_item;
127         Elm_Object_Item *eap_auth_item;
128         Elm_Object_Item *eap_user_cert_item;
129         Elm_Object_Item *eap_id_item;
130         Elm_Object_Item *eap_pw_item;
131         Elm_Object_Item *eap_chkbox_item;
132         Evas_Object *popup;
133         Evas_Object *sub_popup;
134         Evas_Object *info_popup;
135         Evas_Object *genlist;
136         Eina_Bool eap_done_ok;
137         Evas_Object *win;
138         Evas_Object *conf;
139         const char *str_pkg_name;
140         wifi_ap_h ap;
141         char *cert_alias;
142         char *ca_cert_path;
143         char *user_cert_path;
144         char *privatekey_path;
145         GSList *cert_candidates;
146         Evas_Object *confirm;
147         char *ssid;
148
149         int key_status;
150
151         bool is_hidden;
152 };
153
154 static Elm_Genlist_Item_Class g_eap_type_itc;
155 static Elm_Genlist_Item_Class g_eap_auth_itc;
156 static Elm_Genlist_Item_Class g_eap_user_cert_itc;
157 static Elm_Genlist_Item_Class g_eap_entry_itc;
158 static Elm_Genlist_Item_Class g_eap_chkbox_itc;
159 static Evas_Object *g_pwd_entry = NULL;
160 static gboolean keypad_state = FALSE;
161 static _Btn_click_t click;
162
163 static void (*_eap_view_deref_cb)(void) = NULL;
164
165 static void _create_and_update_list_items_based_on_rules(eap_type_t new_type, eap_connect_data_t *eap_data);
166 static void _update_eap_id_item_enter_key(eap_connect_data_t *eap_data);
167 static void _delete_eap_auth_item(eap_connect_data_t *eap_data);
168 static void _delete_eap_user_cert_item(eap_connect_data_t *eap_data);
169 static void _delete_eap_id_item(eap_connect_data_t *eap_data);
170 static void _delete_eap_pw_items(eap_connect_data_t *eap_data);
171 static void _delete_eap_entry_items(eap_connect_data_t *eap_data);
172 static eap_type_t __common_eap_connect_popup_get_eap_type(wifi_ap_h ap);
173 static eap_auth_t __common_eap_connect_popup_get_auth_type(wifi_ap_h ap);
174 static wifi_eap_type_e __common_eap_connect_popup_get_wlan_eap_type(eap_type_t eap_type);
175 static wifi_eap_auth_type_e __common_eap_connect_popup_get_wlan_auth_type(eap_auth_t auth_type);
176 static void _info_popup_ok_cb(void *data, Evas_Object *obj, void *event_info);
177 static gboolean __cert_extract_files(const char *cert_alias,eap_connect_data_t *eap_data);
178 static void _eap_popup_keypad_off_cb(void *data, Evas_Object *obj,
179                 void *event_info);
180 static void _eap_popup_keypad_on_cb(void *data, Evas_Object *obj,
181                 void *event_info);
182
183 static void ctxpopup_dismissed_cb(void *data, Evas_Object *obj,
184                 void *event_info)
185 {
186         eap_connect_data_t *eap_data = (eap_connect_data_t *)data;
187
188         if (eap_data->sub_popup != NULL) {
189                 evas_object_del(eap_data->sub_popup);
190                 eap_data->sub_popup = NULL;
191         }
192 }
193
194 static void cert_ctxpopup_dismissed_cb(void *data, Evas_Object *obj,
195                 void *event_info)
196 {
197         eap_connect_data_t *eap_data = (eap_connect_data_t *)data;
198
199         if (eap_data->sub_popup != NULL) {
200                 evas_object_del(eap_data->sub_popup);
201                 eap_data->sub_popup = NULL;
202         }
203
204         if (eap_data->cert_candidates != NULL) {
205                 g_slist_free_full(eap_data->cert_candidates, g_free);
206                 eap_data->cert_candidates = NULL;
207         }
208 }
209
210 static void move_dropdown(eap_connect_data_t *eap_data, Evas_Object *obj)
211 {
212         Evas_Coord x, y, w , h;
213
214         evas_object_geometry_get(obj, &x, &y, &w, &h);
215         evas_object_move(eap_data->sub_popup, x + (w / 2), y + h);
216 }
217
218 static void _gl_editbox_sel_cb(void *data, Evas_Object *obj, void *event_info)
219 {
220         Elm_Object_Item *item = (Elm_Object_Item *)event_info;
221         elm_genlist_item_selected_set(item, FALSE);
222 }
223
224 static void _select_confirm_popup_ok_cb(void *data, Evas_Object *obj, void *event_info)
225 {
226         eap_connect_data_t *eap_data = (eap_connect_data_t *)data;
227         retm_if(eap_data == NULL);
228
229         if (eap_data->confirm != NULL) {
230                 evas_object_del(eap_data->confirm);
231                 eap_data->confirm = NULL;
232         }
233 }
234
235 static void __gl_eap_type_sub_sel_language_changed_cb(void *data, Evas_Object *obj, void *event_info)
236 {
237         __COMMON_FUNC_ENTER__;
238         retm_if(obj == NULL);
239
240         int val = (int)data;
241         char str[1024];
242         char *txt = NULL;
243
244         g_snprintf(str, 1024, sc(PACKAGE,I18N_TYPE_SIM_method_desc_popup),
245                         (val == 1) ? "SIM2" : "SIM1");
246         txt = evas_textblock_text_utf8_to_markup(NULL, str);
247         elm_object_domain_translatable_text_set(obj, PACKAGE, txt);
248         g_free(txt);
249         __COMMON_FUNC_EXIT__;
250 }
251
252 static void _gl_eap_type_sub_sel(void *data, Evas_Object *obj, void *event_info)
253 {
254         eap_connect_data_t *eap_data = (eap_connect_data_t *) data;
255         eap_type_t sel_index = EAP_SEC_TYPE_UNKNOWN;
256         char buf[1024] = {'\0'};
257
258         eap_type_t pre_index = __common_eap_connect_popup_get_eap_type(eap_data->ap);
259         const char *label = elm_object_item_text_get((Elm_Object_Item *) event_info);
260
261         if (strcmp(label, EAP_TYPE_UNKNOWN) == 0)
262                 sel_index = EAP_SEC_TYPE_UNKNOWN;
263         else if (strcmp(label, EAP_TYPE_PEAP) == 0)
264                 sel_index = EAP_SEC_TYPE_PEAP;
265         else if (strcmp(label, EAP_TYPE_TLS) == 0)
266                 sel_index = EAP_SEC_TYPE_TLS;
267         else if (strcmp(label, EAP_TYPE_TTLS) == 0)
268                 sel_index = EAP_SEC_TYPE_TTLS;
269         else if (strcmp(label, EAP_TYPE_SIM) == 0)
270                 sel_index = EAP_SEC_TYPE_SIM;
271         else if (strcmp(label, EAP_TYPE_AKA) == 0)
272                 sel_index = EAP_SEC_TYPE_AKA;
273
274         DEBUG_LOG(UG_NAME_NORMAL, "previous index = %d; selected index = %d;",
275                         pre_index, sel_index);
276         if ((pre_index != EAP_SEC_TYPE_SIM && sel_index == EAP_SEC_TYPE_SIM) ||
277                         (pre_index != EAP_SEC_TYPE_AKA && sel_index == EAP_SEC_TYPE_AKA)) {
278                 popup_btn_info_t popup_data;
279                 int value = -1;
280                 value = common_util_get_system_registry(
281                                 VCONF_TELEPHONY_DEFAULT_DATA_SERVICE);
282
283                 memset(&popup_data, 0, sizeof(popup_data));
284                 g_snprintf(buf, sizeof(buf),
285                                 sc(PACKAGE, I18N_TYPE_SIM_method_desc_popup),
286                                 (value == 1) ? "SIM2" : "SIM1");
287                 popup_data.title_txt = "IDS_WIFI_BODY_EAP_METHOD";
288                 popup_data.info_txt = evas_textblock_text_utf8_to_markup(NULL, buf);
289                 popup_data.btn1_txt = "IDS_WIFI_SK2_OK";
290                 popup_data.btn1_cb = _select_confirm_popup_ok_cb;
291                 popup_data.btn1_data = eap_data;
292
293                 eap_data->confirm = common_utils_show_info_popup(eap_data->win,
294                                 &popup_data);
295                 g_free(popup_data.info_txt);
296                 evas_object_smart_callback_add(eap_data->confirm, "language,changed",
297                                 __gl_eap_type_sub_sel_language_changed_cb, (void *)value);
298
299                 _create_and_update_list_items_based_on_rules(sel_index, data);
300                 wifi_eap_type_e type;
301                 wifi_ap_set_eap_type(eap_data->ap,
302                                 __common_eap_connect_popup_get_wlan_eap_type(sel_index));
303                 wifi_ap_get_eap_type(eap_data->ap, &type);
304                 DEBUG_LOG(UG_NAME_NORMAL, "set to new index = %d", type);
305         }
306
307         if (eap_data->sub_popup != NULL) {
308                 evas_object_del(eap_data->sub_popup);
309                 eap_data->sub_popup = NULL;
310         }
311
312         if (pre_index != sel_index) {
313                 wifi_eap_type_e type;
314                 wifi_ap_set_eap_type(eap_data->ap,
315                                 __common_eap_connect_popup_get_wlan_eap_type(sel_index));
316                 wifi_ap_get_eap_type(eap_data->ap, &type);
317                 DEBUG_LOG(UG_NAME_NORMAL, "set to new index = %d", type);
318                 _create_and_update_list_items_based_on_rules(sel_index, eap_data);
319
320                 if (sel_index == EAP_SEC_TYPE_PEAP) {
321                         /* If previous auth type was PAP or MSCHAP & when PEAP
322                          * EAP method is selected, then set back MSCHAPV2
323                          */
324                         eap_auth_t auth_type;
325
326                         auth_type = __common_eap_connect_popup_get_auth_type(eap_data->ap);
327                         if (auth_type == EAP_SEC_AUTH_PAP ||
328                                         auth_type == EAP_SEC_AUTH_MSCHAP) {
329                                 wifi_ap_set_eap_auth_type(eap_data->ap,
330                                                 WIFI_EAP_AUTH_TYPE_MSCHAPV2);
331
332                                 if(eap_data->eap_auth_item != NULL)
333                                         elm_genlist_item_update(eap_data->eap_auth_item);
334                         }
335                 }
336         } else {
337                 DEBUG_LOG(UG_NAME_NORMAL, "pre_index == sel_index[%d]",
338                                 sel_index);
339         }
340
341         if(eap_data->eap_type_item != NULL)
342                 elm_genlist_item_update(eap_data->eap_type_item);
343 }
344
345 static CertSvcInstance instance;
346 static CertSvcStoreCertList *certList = NULL;
347
348 static void _gl_eap_user_cert_sel(void *data, Evas_Object *obj,
349                 void *event_info)
350 {
351         eap_connect_data_t *eap_data = (eap_connect_data_t *) data;
352         const char *cert_alias = elm_object_item_text_get((Elm_Object_Item *) event_info);
353
354         if (!eap_data)
355                 return;
356
357         if (eap_data->sub_popup != NULL) {
358                 evas_object_del(eap_data->sub_popup);
359                 eap_data->sub_popup = NULL;
360         }
361
362         if (eap_data->ca_cert_path) {
363                 g_unlink(eap_data->ca_cert_path);
364                 eap_data->ca_cert_path = NULL;
365         }
366         if (eap_data->user_cert_path) {
367                 g_unlink(eap_data->user_cert_path);
368                 eap_data->user_cert_path = NULL;
369         }
370         if (eap_data->privatekey_path) {
371                 g_unlink(eap_data->privatekey_path);
372                 eap_data->privatekey_path = NULL;
373         }
374
375         if (strcmp(cert_alias, sc(PACKAGE, I18N_TYPE_None)) == 0) {
376                 if (eap_data->cert_alias != NULL) {
377                         g_free(eap_data->cert_alias);
378                         eap_data->cert_alias = NULL;
379                 }
380         } else if (__cert_extract_files(cert_alias, eap_data)) {
381                 if (eap_data->cert_alias != NULL) {
382                         g_free(eap_data->cert_alias);
383                         eap_data->cert_alias = NULL;
384                 }
385                 eap_data->cert_alias = g_strdup(cert_alias);
386         }
387
388         if(eap_data->eap_user_cert_item != NULL)
389                 elm_genlist_item_update(eap_data->eap_user_cert_item);
390
391         if (eap_data->cert_candidates != NULL) {
392                 g_slist_free_full(eap_data->cert_candidates, g_free);
393                 eap_data->cert_candidates = NULL;
394         }
395 }
396
397 static void _create_eap_cert_list(eap_connect_data_t *eap_data,
398                 Evas_Object *btn)
399 {
400         size_t list_length = 0;
401         Evas_Object *ctxpopup;
402         Elm_Object_Item *it = NULL;
403
404         if (!eap_data)
405                 return;
406
407         if (eap_data->sub_popup != NULL) {
408                 evas_object_del(eap_data->sub_popup);
409                 eap_data->sub_popup = NULL;
410         }
411
412         ctxpopup = elm_ctxpopup_add(eap_data->win);
413         eap_data->sub_popup = ctxpopup;
414         elm_object_style_set(ctxpopup, "dropdown/list");
415         eext_object_event_callback_add(ctxpopup, EEXT_CALLBACK_BACK,
416                         cert_ctxpopup_dismissed_cb, NULL);
417         evas_object_smart_callback_add(ctxpopup,"dismissed",
418                         cert_ctxpopup_dismissed_cb, eap_data);
419         elm_ctxpopup_direction_priority_set(ctxpopup,
420                         ELM_CTXPOPUP_DIRECTION_DOWN,
421                         ELM_CTXPOPUP_DIRECTION_UNKNOWN,
422                         ELM_CTXPOPUP_DIRECTION_UNKNOWN,
423                         ELM_CTXPOPUP_DIRECTION_UNKNOWN);
424
425         if (certsvc_instance_new(&instance) == CERTSVC_FAIL) {
426                 INFO_LOG(UG_NAME_ERR, "Failed to create new instance");
427                 return;
428         }
429
430         certsvc_pkcs12_get_certificate_list_from_store(instance, WIFI_STORE, DISABLED, &certList, &list_length);
431
432         if (eap_data->cert_candidates) {
433                 g_slist_free_full(eap_data->cert_candidates, g_free);
434                 eap_data->cert_candidates = NULL;
435         }
436
437         it = elm_ctxpopup_item_append(ctxpopup, "IDS_ST_BODY_NONE", NULL,
438                         _gl_eap_user_cert_sel, eap_data);
439         elm_object_item_domain_text_translatable_set(it,
440                         PACKAGE, EINA_TRUE);
441
442         while(certList != NULL) {
443                 char *char_buffer = NULL;
444                 CertSvcString buffer;
445
446                 buffer.privateHandler = (char *)certList->gname;
447                 buffer.privateLength = strlen(certList->gname);
448                 INFO_LOG(UG_NAME_NORMAL, "gname in processing : %s", certList->gname);
449
450                 char_buffer = g_strndup(buffer.privateHandler, buffer.privateLength);
451                 if (char_buffer == NULL)
452                         goto exit;
453
454                 elm_ctxpopup_item_append(ctxpopup, char_buffer, NULL,
455                                 _gl_eap_user_cert_sel, eap_data);
456                 eap_data->cert_candidates =
457                                 g_slist_prepend(eap_data->cert_candidates, char_buffer);
458
459                 certsvc_string_free(buffer);
460                 certList = certList->next;
461         }
462
463         move_dropdown(eap_data, btn);
464         evas_object_show(ctxpopup);
465
466 exit:
467                 certsvc_instance_free(instance);
468 }
469
470 static void _gl_eap_cert_list_btn_cb(void *data, Evas_Object *obj,
471                 void *event_info)
472 {
473         Elm_Object_Item *item = (Elm_Object_Item *)event_info;
474         eap_connect_data_t *eap_data = (eap_connect_data_t *) data;
475
476         if (item)
477                 elm_genlist_item_selected_set(item, EINA_FALSE);
478
479         if (keypad_state == FALSE) {
480                 _create_eap_cert_list(eap_data, obj);
481
482                 click.btn_click[EAP_CERT_BTN] = FALSE;
483                 click.btn_obj[EAP_CERT_BTN] = NULL;
484         } else {
485                 click.btn_click[EAP_CERT_BTN] = TRUE;
486                 click.btn_obj[EAP_CERT_BTN] = obj;
487         }
488 }
489
490 static char *_gl_eap_user_cert_text_get(void *data, Evas_Object *obj, const char *part)
491 {
492         eap_connect_data_t *eap_data = (eap_connect_data_t *)data;
493
494         if (!g_strcmp0(part, "elm.text.sub")) {
495                 return g_strdup(sc(eap_data->str_pkg_name,
496                                 I18N_TYPE_User_Certificate));
497         }
498
499         return NULL;
500 }
501
502 static Evas_Object *_gl_eap_user_cert_content_get(void *data,
503                 Evas_Object *obj, const char *part)
504 {
505         eap_connect_data_t *eap_data = (eap_connect_data_t *)data;
506         Evas_Object *btn = NULL;
507         Evas_Object *ly = NULL;
508         char buf[100];
509
510         if (!strcmp(part, "elm.swallow.icon.0")) {
511                 ly = elm_layout_add(obj);
512                 elm_layout_file_set(ly, CUSTOM_EDITFIELD_PATH,
513                                 "eap_dropdown_button");
514                 btn = elm_button_add(obj);
515
516                 if (eap_data->cert_alias == NULL) {
517                         g_snprintf(buf, sizeof(buf), "<align=left>%s</align>",
518                                         sc(eap_data->str_pkg_name, I18N_TYPE_None));
519                 } else {
520                         g_snprintf(buf, sizeof(buf), "<align=left>%s</align>",
521                                         eap_data->cert_alias);
522                 }
523
524                 elm_object_domain_translatable_text_set(btn, PACKAGE, buf);
525                 elm_object_style_set(btn, "dropdown/label");
526                 evas_object_propagate_events_set(btn, EINA_FALSE);
527                 evas_object_size_hint_weight_set(btn, EVAS_HINT_EXPAND,
528                                 EVAS_HINT_EXPAND);
529                 evas_object_size_hint_align_set(btn, EVAS_HINT_FILL,
530                                 EVAS_HINT_FILL);
531                 evas_object_smart_callback_add(btn, "clicked",
532                                 _gl_eap_cert_list_btn_cb, eap_data);
533
534                 elm_layout_content_set(ly, "btn", btn);
535                 return ly;
536         }
537         return NULL;
538 }
539
540 static void _gl_eap_item_sel_cb(void *data, Evas_Object *obj, void *event_info)
541 {
542         Elm_Object_Item *item = (Elm_Object_Item *)event_info;
543
544         if (item) {
545                 elm_genlist_item_selected_set(item, EINA_FALSE);
546         }
547 }
548
549 static void _create_eap_type_list(eap_connect_data_t *eap_data,
550                 Evas_Object *btn)
551 {
552         Evas_Object *ctxpopup = NULL;
553         int i = EAP_SEC_TYPE_PEAP;
554         int sim_state = VCONFKEY_TELEPHONY_SIM_UNKNOWN;
555         Elm_Object_Item *it = NULL;
556
557         sim_state = common_utils_get_sim_state();
558
559         if (eap_data->sub_popup != NULL) {
560                 evas_object_del(eap_data->sub_popup);
561         }
562
563         ctxpopup = elm_ctxpopup_add(eap_data->win);
564         eap_data->sub_popup = ctxpopup;
565         elm_object_style_set(ctxpopup, "dropdown/list");
566         eext_object_event_callback_add(ctxpopup, EEXT_CALLBACK_BACK,
567                         eext_ctxpopup_back_cb, NULL);
568         evas_object_smart_callback_add(ctxpopup,"dismissed",
569                         ctxpopup_dismissed_cb, eap_data);
570         elm_ctxpopup_direction_priority_set(ctxpopup,
571                         ELM_CTXPOPUP_DIRECTION_DOWN,
572                         ELM_CTXPOPUP_DIRECTION_UNKNOWN,
573                         ELM_CTXPOPUP_DIRECTION_UNKNOWN,
574                         ELM_CTXPOPUP_DIRECTION_UNKNOWN);
575
576         /* eap_type = __common_eap_connect_popup_get_eap_type(eap_data->ap); */
577         while (list_eap_type[i].name != NULL) {
578                 it = elm_ctxpopup_item_append(ctxpopup, list_eap_type[i].name,
579                                 NULL, _gl_eap_type_sub_sel, eap_data);
580
581                 if ((i == EAP_SEC_TYPE_SIM || i == EAP_SEC_TYPE_AKA) &&
582                                 sim_state != VCONFKEY_TELEPHONY_SIM_INSERTED) {
583                         elm_object_item_disabled_set(it, EINA_TRUE);
584                 }
585
586                 i++;
587         }
588         move_dropdown(eap_data, btn);
589         evas_object_show(ctxpopup);
590 }
591
592 static void _gl_eap_type_btn_cb(void *data, Evas_Object *obj, void *event_info)
593 {
594         Elm_Object_Item *item = (Elm_Object_Item *)event_info;
595         eap_connect_data_t *eap_data = (eap_connect_data_t *) data;
596
597         if (item)
598                 elm_genlist_item_selected_set(item, EINA_FALSE);
599
600         if (keypad_state == FALSE) {
601                 _create_eap_type_list(eap_data, obj);
602
603                 click.btn_click[EAP_TYPE_BTN] = FALSE;
604                 click.btn_obj[EAP_TYPE_BTN] = NULL;
605         } else {
606                 click.btn_click[EAP_TYPE_BTN] = TRUE;
607                 click.btn_obj[EAP_TYPE_BTN] = obj;
608         }
609 }
610
611 static char *_gl_eap_type_text_get(void *data, Evas_Object *obj, const char *part)
612 {
613         eap_connect_data_t *eap_data = (eap_connect_data_t *)data;
614
615         if (!g_strcmp0(part, "elm.text.sub")) {
616                 return g_strdup(sc(eap_data->str_pkg_name, I18N_TYPE_EAP_method));
617         }
618
619         return NULL;
620 }
621
622 static Evas_Object *_gl_eap_type_content_get(void *data,
623                 Evas_Object *obj, const char *part)
624 {
625         eap_connect_data_t *eap_data = (eap_connect_data_t *)data;
626         eap_type_t sel_sub_item_id = __common_eap_connect_popup_get_eap_type(eap_data->ap);
627         Evas_Object *btn = NULL;
628         Evas_Object *ly = NULL;
629         char buf[100];
630
631         if (!strcmp(part, "elm.swallow.icon.0")) {
632                 ly = elm_layout_add(obj);
633                 elm_layout_file_set(ly, CUSTOM_EDITFIELD_PATH,
634                                 "eap_dropdown_button");
635                 btn = elm_button_add(obj);
636
637                 g_snprintf(buf, sizeof(buf), "<align=left>%s</align>",
638                                 list_eap_type[sel_sub_item_id].name);
639
640                 elm_object_text_set(btn, buf);
641                 elm_object_style_set(btn, "dropdown/label");
642                 evas_object_propagate_events_set(btn, EINA_FALSE);
643                 evas_object_size_hint_weight_set(btn, EVAS_HINT_EXPAND,
644                                 EVAS_HINT_EXPAND);
645                 evas_object_size_hint_align_set(btn, EVAS_HINT_FILL,
646                                 EVAS_HINT_FILL);
647                 evas_object_smart_callback_add(btn, "clicked",
648                                 _gl_eap_type_btn_cb, eap_data);
649
650                 elm_layout_content_set(ly, "btn", btn);
651                 return ly;
652         }
653         return NULL;
654 }
655
656 static void _gl_eap_auth_sub_sel(void *data, Evas_Object *obj, void *event_info)
657 {
658         eap_connect_data_t *eap_data = (eap_connect_data_t *) data;
659         eap_auth_t sel_index = EAP_SEC_AUTH_NONE;
660
661         const char *label = elm_object_item_text_get((Elm_Object_Item *) event_info);
662
663         if (strcmp(label, sc(PACKAGE, I18N_TYPE_None)) == 0)
664                 sel_index = EAP_SEC_AUTH_NONE;
665         else if (strcmp(label, EAP_AUTH_TYPE_PAP) == 0)
666                 sel_index = EAP_SEC_AUTH_PAP;
667         else if (strcmp(label, EAP_AUTH_TYPE_MSCHAP) == 0)
668                 sel_index = EAP_SEC_AUTH_MSCHAP;
669         else if (strcmp(label, EAP_AUTH_TYPE_MSCHAPV2) == 0)
670                 sel_index = EAP_SEC_AUTH_MSCHAPV2;
671         else if (strcmp(label, EAP_AUTH_TYPE_GTC) == 0)
672                 sel_index = EAP_SEC_AUTH_GTC;
673         else if (strcmp(label, EAP_AUTH_TYPE_MD5) == 0)
674                 sel_index = EAP_SEC_AUTH_MD5;
675
676         wifi_ap_set_eap_auth_type(eap_data->ap,
677                 __common_eap_connect_popup_get_wlan_auth_type(sel_index));
678
679         if (eap_data->sub_popup != NULL) {
680                 evas_object_del(eap_data->sub_popup);
681                 eap_data->sub_popup = NULL;
682         }
683
684         if(eap_data->eap_auth_item != NULL)
685                 elm_genlist_item_update(eap_data->eap_auth_item);
686 }
687
688 static void _create_eap_auth_list(eap_connect_data_t *eap_data,
689                 Evas_Object *btn)
690 {
691         Elm_Object_Item *it = NULL;
692         eap_type_t eap_type = EAP_SEC_TYPE_UNKNOWN;
693         Evas_Object *ctxpopup;
694         int i = 0;
695
696         eap_type = __common_eap_connect_popup_get_eap_type(eap_data->ap);
697
698         if (eap_data->sub_popup != NULL) {
699                 evas_object_del(eap_data->sub_popup);
700         }
701
702         ctxpopup = elm_ctxpopup_add(eap_data->win);
703         eap_data->sub_popup = ctxpopup;
704         elm_object_style_set(ctxpopup, "dropdown/list");
705         eext_object_event_callback_add(ctxpopup, EEXT_CALLBACK_BACK, eext_ctxpopup_back_cb, NULL);
706         evas_object_smart_callback_add(ctxpopup,"dismissed", ctxpopup_dismissed_cb, eap_data);
707         elm_ctxpopup_direction_priority_set(ctxpopup,
708                         ELM_CTXPOPUP_DIRECTION_DOWN,
709                         ELM_CTXPOPUP_DIRECTION_UNKNOWN,
710                         ELM_CTXPOPUP_DIRECTION_UNKNOWN,
711                         ELM_CTXPOPUP_DIRECTION_UNKNOWN);
712
713         while (list_eap_auth[i].name != NULL) {
714                 if ((eap_type != EAP_SEC_TYPE_PEAP) ||
715                                 (eap_type == EAP_SEC_TYPE_PEAP && i != 1 &&
716                                                 i != 2)) {
717                         it = elm_ctxpopup_item_append(ctxpopup, list_eap_auth[i].name,
718                                 NULL, _gl_eap_auth_sub_sel, eap_data);
719                         if (i == 0) {
720                                 elm_object_item_domain_text_translatable_set(it,
721                                                 PACKAGE, EINA_TRUE);
722                         }
723                 }
724                 i++;
725         }
726         move_dropdown(eap_data, btn);
727         evas_object_show(ctxpopup);
728 }
729
730 static void _gl_eap_auth_btn_cb(void *data, Evas_Object *obj, void *event_info)
731 {
732         Elm_Object_Item *item = (Elm_Object_Item *)event_info;
733         eap_connect_data_t *eap_data = (eap_connect_data_t *) data;
734
735         if (item)
736                 elm_genlist_item_selected_set(item, EINA_FALSE);
737
738         if (keypad_state == FALSE) {
739                 _create_eap_auth_list(eap_data, obj);
740
741                 click.btn_click[EAP_AUTH_BTN] = FALSE;
742                 click.btn_obj[EAP_AUTH_BTN] = NULL;
743         } else {
744                 click.btn_click[EAP_AUTH_BTN] = TRUE;
745                 click.btn_obj[EAP_AUTH_BTN] = obj;
746         }
747 }
748
749 static char *_gl_eap_auth_text_get(void *data, Evas_Object *obj, const char *part)
750 {
751         eap_connect_data_t *eap_data = (eap_connect_data_t *)data;
752
753         if (!g_strcmp0(part, "elm.text.sub")) {
754                 return g_strdup(sc(eap_data->str_pkg_name,
755                                 I18N_TYPE_Phase_2_authentication));
756         }
757
758         return NULL;
759 }
760
761 static Evas_Object *_gl_eap_auth_content_get(void *data,
762                 Evas_Object *obj, const char *part)
763 {
764         eap_connect_data_t *eap_data = (eap_connect_data_t *)data;
765         eap_auth_t sel_sub_item_id = __common_eap_connect_popup_get_auth_type(eap_data->ap);
766         Evas_Object *btn = NULL;
767         Evas_Object *ly = NULL;
768         char buf[100];
769
770         if (!strcmp(part, "elm.swallow.icon.0")) {
771                 ly = elm_layout_add(obj);
772                 elm_layout_file_set(ly, CUSTOM_EDITFIELD_PATH,
773                                 "eap_dropdown_button");
774                 btn = elm_button_add(obj);
775
776                 if (sel_sub_item_id == EAP_SEC_AUTH_NONE) {
777                         g_snprintf(buf, sizeof(buf), "<align=left>%s</align>",
778                                         sc(PACKAGE, I18N_TYPE_None));
779                 } else {
780                         g_snprintf(buf, sizeof(buf), "<align=left>%s</align>",
781                                         list_eap_auth[sel_sub_item_id].name);
782                 }
783
784                 elm_object_domain_translatable_text_set(btn, PACKAGE, buf);
785                 elm_object_style_set(btn, "dropdown/label");
786                 evas_object_propagate_events_set(btn, EINA_FALSE);
787                 evas_object_size_hint_weight_set(btn, EVAS_HINT_EXPAND,
788                                 EVAS_HINT_EXPAND);
789                 evas_object_size_hint_align_set(btn, EVAS_HINT_FILL,
790                                 EVAS_HINT_FILL);
791                 evas_object_smart_callback_add(btn, "clicked",
792                                 _gl_eap_auth_btn_cb, eap_data);
793
794                 elm_layout_content_set(ly, "btn", btn);
795                 return ly;
796         }
797         return NULL;
798 }
799
800 static void _gl_eap_entry_key_enter_cb(void *data, Evas_Object *obj, void *event_info)
801 {
802         common_utils_entry_info_t *entry_info = (common_utils_entry_info_t *)data;
803         if (!entry_info) {
804                 return;
805         }
806
807         Evas_Object *entry = NULL;
808         Elm_Object_Item *next_item = NULL;
809         eap_type_t eap_type;
810
811         switch (entry_info->entry_id) {
812         case ENTRY_TYPE_USER_ID:
813                 eap_type = __common_eap_connect_popup_get_eap_type(
814                                 entry_info->ap);
815
816                 if (eap_type == EAP_SEC_TYPE_TLS) {
817                         entry = elm_object_item_part_content_get(entry_info->item,
818                                         "elm.icon.entry");
819                         if (entry) {
820                                 elm_object_focus_set(entry, EINA_FALSE);
821                         }
822                 } else {
823                         next_item = elm_genlist_item_next_get(entry_info->item);
824                         while (next_item) {
825                                 if (elm_object_item_disabled_get(next_item) == EINA_FALSE &&
826                                         elm_genlist_item_select_mode_get(next_item) !=
827                                                         ELM_OBJECT_SELECT_MODE_DISPLAY_ONLY) {
828                                         entry = elm_object_item_part_content_get(
829                                                         next_item, "elm.icon.entry");
830                                         if (entry) {
831                                                 elm_object_focus_set(entry, EINA_TRUE);
832                                                 return;
833                                         }
834                                 }
835
836                                 next_item = elm_genlist_item_next_get(next_item);
837                         }
838                 }
839                 break;
840         case ENTRY_TYPE_PASSWORD:
841                 entry = elm_object_item_part_content_get(entry_info->item,
842                                 "elm.icon.entry");
843                 if (entry) {
844                         elm_object_focus_set(entry, EINA_FALSE);
845                 }
846                 break;
847         default:
848                 break;
849         }
850 }
851
852 static void _gl_eap_entry_cursor_changed_cb(void* data, Evas_Object* obj, void* event_info)
853 {
854         common_utils_entry_info_t *entry_info = (common_utils_entry_info_t *)data;
855         if (!entry_info) {
856                 return;
857         }
858
859         if (elm_object_focus_get(obj)) {
860                 if (elm_entry_is_empty(obj)) {
861                         elm_object_item_signal_emit(entry_info->item, "elm,state,eraser,hide", "");
862                 } else {
863                         elm_object_item_signal_emit(entry_info->item, "elm,state,eraser,show", "");
864                 }
865         }
866
867         if (entry_info->entry_txt) {
868                 g_free(entry_info->entry_txt);
869                 entry_info->entry_txt = NULL;
870         }
871
872         char *entry_text = elm_entry_markup_to_utf8(elm_entry_entry_get(obj));
873
874         if (entry_text != NULL && entry_text[0] != '\0') {
875                 entry_info->entry_txt = elm_entry_markup_to_utf8(elm_entry_entry_get(obj));
876         }
877
878         g_free(entry_text);
879 }
880
881 static void _gl_eap_entry_changed_cb(void* data, Evas_Object* obj, void* event_info)
882 {
883         common_utils_entry_info_t *entry_info = (common_utils_entry_info_t *)data;
884         if (!entry_info) {
885                 return;
886         }
887
888         if (obj == NULL) {
889                 return;
890         }
891
892         if (elm_object_focus_get(obj)) {
893                 if (elm_entry_is_empty(obj)) {
894                         elm_object_item_signal_emit(entry_info->item, "elm,state,eraser,hide", "");
895                 } else {
896                         elm_object_item_signal_emit(entry_info->item, "elm,state,eraser,show", "");
897                 }
898         }
899 }
900
901 static void _gl_eap_entry_focused_cb(void *data, Evas_Object *obj, void *event_info)
902 {
903         common_utils_entry_info_t *entry_info = (common_utils_entry_info_t *)data;
904         if (!entry_info) {
905                 return;
906         }
907
908         if (!elm_entry_is_empty(obj)) {
909                 elm_object_item_signal_emit(entry_info->item, "elm,state,eraser,show", "");
910         }
911
912         elm_object_item_signal_emit(entry_info->item, "elm,state,rename,hide", "");
913 }
914
915 static void _gl_eap_entry_unfocused_cb(void *data, Evas_Object *obj, void *event_info)
916 {
917         common_utils_entry_info_t *entry_info = (common_utils_entry_info_t *)data;
918         if (!entry_info) {
919                 return;
920         }
921
922         if (entry_info->entry_txt) {
923                 g_free(entry_info->entry_txt);
924                 entry_info->entry_txt = NULL;
925         }
926
927         char *entry_text = elm_entry_markup_to_utf8(elm_entry_entry_get(obj));
928         if (entry_text != NULL && entry_text[0] != '\0')
929                 entry_info->entry_txt = elm_entry_markup_to_utf8(elm_entry_entry_get(obj));
930
931         g_free(entry_text);
932
933         elm_object_item_signal_emit(entry_info->item, "elm,state,eraser,hide", "");
934         elm_object_item_signal_emit(entry_info->item, "elm,state,rename,show", "");
935 }
936
937 static void _gl_eap_entry_maxlength_reached(void *data, Evas_Object *obj,
938                 void *event_info)
939 {
940         common_utils_send_message_to_net_popup("Password length",
941                         "Lengthy Password", "notification", NULL);
942 }
943
944 static void _gl_eap_entry_eraser_clicked_cb(void *data, Evas_Object *obj, void *event_info)
945 {
946         common_utils_entry_info_t *entry_info = (common_utils_entry_info_t *)data;
947         if (!entry_info) {
948                 return;
949         }
950
951         Evas_Object *entry = elm_object_item_part_content_get(entry_info->item, "elm.icon.entry");
952         if (entry) {
953                 elm_object_focus_set(entry, EINA_TRUE);
954                 elm_entry_entry_set(entry, "");
955         }
956 }
957
958 static char *_gl_eap_entry_item_text_get(void *data, Evas_Object *obj, const char *part)
959 {
960         common_utils_entry_info_t *entry_info = (common_utils_entry_info_t *)data;
961         if (!entry_info) {
962                 return NULL;
963         }
964
965         if (!g_strcmp0(part, "elm.text.sub")) {
966                 return g_strdup(dgettext(PACKAGE, entry_info->title_txt));
967         }
968
969         return NULL;
970 }
971
972 static Evas_Object *_gl_eap_entry_item_content_get(void *data, Evas_Object *obj, const char *part)
973 {
974         common_utils_entry_info_t *entry_info = (common_utils_entry_info_t *)data;
975         if (!entry_info) {
976                 return NULL;
977         }
978
979         if (g_strcmp0(part, "elm.swallow.icon.0") == 0) {
980                 Evas_Object *entry = NULL;
981                 char *guide_txt = NULL;
982                 char *accepted = NULL;
983                 Eina_Bool hide_entry_txt = EINA_FALSE;
984                 Elm_Input_Panel_Layout panel_type;
985                 int return_key_type;
986                 eap_type_t eap_type;
987
988                 eap_type = __common_eap_connect_popup_get_eap_type(entry_info->ap);
989
990                 static Elm_Entry_Filter_Limit_Size limit_filter_data;
991
992                 switch (entry_info->entry_id)
993                 {
994                 case ENTRY_TYPE_USER_ID:
995                         panel_type = ELM_INPUT_PANEL_LAYOUT_NORMAL;
996                         guide_txt = entry_info->guide_txt;
997
998                         if (eap_type == EAP_SEC_TYPE_TLS) {
999                                 return_key_type = ECORE_IMF_INPUT_PANEL_RETURN_KEY_TYPE_DONE;
1000                         } else {
1001                                 return_key_type = ECORE_IMF_INPUT_PANEL_RETURN_KEY_TYPE_NEXT;
1002                         }
1003                         break;
1004                 case ENTRY_TYPE_PASSWORD:
1005                         panel_type = ELM_INPUT_PANEL_LAYOUT_PASSWORD;
1006                         guide_txt = entry_info->guide_txt;
1007                         hide_entry_txt = EINA_TRUE;
1008                         return_key_type = ECORE_IMF_INPUT_PANEL_RETURN_KEY_TYPE_DONE;
1009                         break;
1010                 default:
1011                         return NULL;
1012                 }
1013
1014                 entry = elm_entry_add(obj);
1015                 retvm_if(NULL == entry, NULL);
1016
1017                 elm_entry_single_line_set(entry, EINA_TRUE);
1018                 elm_entry_scrollable_set(entry, EINA_TRUE);
1019                 elm_entry_password_set(entry, hide_entry_txt);
1020                 elm_entry_prediction_allow_set(entry, EINA_FALSE);
1021                 elm_entry_autocapital_type_set(entry, ELM_AUTOCAPITAL_TYPE_NONE);
1022
1023                 elm_object_domain_translatable_part_text_set(entry, "elm.guide",
1024                                 PACKAGE, guide_txt);
1025                 if (entry_info->entry_txt && (strlen(entry_info->entry_txt) > 0)) {
1026                         elm_entry_entry_set(entry, entry_info->entry_txt);
1027                 }
1028
1029                 elm_entry_input_panel_layout_set(entry, panel_type);
1030                 elm_entry_input_panel_return_key_type_set(entry, return_key_type);
1031
1032                 limit_filter_data.max_char_count = 200;
1033                 elm_entry_markup_filter_append(entry, elm_entry_filter_limit_size, &limit_filter_data);
1034
1035                 Elm_Entry_Filter_Accept_Set digits_filter_data;
1036                 memset(&digits_filter_data, 0, sizeof(Elm_Entry_Filter_Accept_Set));
1037                 digits_filter_data.accepted = accepted;
1038                 elm_entry_markup_filter_append(entry, elm_entry_filter_accept_set, &digits_filter_data);
1039
1040                 Ecore_IMF_Context *imf_ctxt = elm_entry_imf_context_get(entry);
1041                 if (imf_ctxt && entry_info->input_panel_cb) {
1042                         ecore_imf_context_input_panel_event_callback_add(imf_ctxt,
1043                                         ECORE_IMF_INPUT_PANEL_STATE_EVENT,
1044                                         entry_info->input_panel_cb,
1045                                         entry_info->input_panel_cb_data);
1046                         DEBUG_LOG(UG_NAME_NORMAL, "set the imf ctxt cbs");
1047                 }
1048
1049                 evas_object_smart_callback_add(entry, "activated", _gl_eap_entry_key_enter_cb, entry_info);
1050                 evas_object_smart_callback_add(entry, "cursor,changed", _gl_eap_entry_cursor_changed_cb, entry_info);
1051                 evas_object_smart_callback_add(entry, "changed", _gl_eap_entry_changed_cb, entry_info);
1052                 evas_object_smart_callback_add(entry, "focused", _gl_eap_entry_focused_cb, entry_info);
1053                 evas_object_smart_callback_add(entry, "unfocused", _gl_eap_entry_unfocused_cb, entry_info);
1054                 evas_object_smart_callback_add(entry, "maxlength,reached", _gl_eap_entry_maxlength_reached, NULL);
1055
1056                 if (entry_info->entry_id == ENTRY_TYPE_PASSWORD) {
1057                         g_pwd_entry = entry;
1058                 }
1059
1060                 return entry;
1061         } else if (g_strcmp0(part, "elm.icon.eraser") == 0) {
1062                 Evas_Object *btn = elm_button_add(obj);
1063                 elm_object_style_set(btn, "editfield_clear");
1064                 evas_object_smart_callback_add(btn, "clicked", _gl_eap_entry_eraser_clicked_cb, entry_info);
1065                 return btn;
1066         }
1067
1068         return NULL;
1069 }
1070
1071 static void _gl_eap_entry_item_del(void *data, Evas_Object *obj)
1072 {
1073         common_utils_entry_info_t *entry_info = (common_utils_entry_info_t *)data;
1074         if (entry_info == NULL) {
1075                 return;
1076         }
1077
1078         if (entry_info->entry_txt) {
1079                 g_free(entry_info->entry_txt);
1080         }
1081
1082         g_free(entry_info);
1083 }
1084
1085 static void _chk_changed_cb(void *data, Evas_Object *obj, void *ei)
1086 {
1087         if (obj == NULL || g_pwd_entry == NULL) {
1088                 return;
1089         }
1090
1091         Eina_Bool state = elm_check_state_get(obj);
1092         if (state) {
1093                 elm_entry_password_set(g_pwd_entry, EINA_FALSE);
1094         } else {
1095                 elm_entry_password_set(g_pwd_entry, EINA_TRUE);
1096         }
1097 }
1098
1099 static char *_gl_eap_chkbox_item_text_get(void *data, Evas_Object *obj,
1100                 const char *part)
1101 {
1102         char *str_pkg_name = (char *)data;
1103
1104         if (!strcmp("elm.text", part)) {
1105                 char buf[1024];
1106                 snprintf(buf, 1023, "%s", sc(str_pkg_name, I18N_TYPE_Show_password));
1107                 return strdup(buf);
1108         }
1109         return NULL;
1110
1111 }
1112
1113 static Evas_Object *_gl_eap_chkbox_item_content_get(void *data,
1114                 Evas_Object *obj, const char *part)
1115 {
1116         Evas_Object *check = NULL;
1117
1118         if (!strcmp("elm.swallow.end", part)) {
1119                 check = elm_check_add(obj);
1120                 evas_object_propagate_events_set(check, EINA_FALSE);
1121
1122                 evas_object_size_hint_align_set(check, EVAS_HINT_FILL, EVAS_HINT_FILL);
1123                 evas_object_size_hint_weight_set(check, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
1124                 evas_object_smart_callback_add(check, "changed",
1125                                 _chk_changed_cb, NULL);
1126
1127                 elm_object_focus_allow_set(check, EINA_FALSE);
1128
1129                 return check;
1130         }
1131         return NULL;
1132 }
1133
1134 static void _gl_eap_chkbox_sel(void *data, Evas_Object *obj, void *ei)
1135 {
1136         Elm_Object_Item *item = NULL;
1137
1138         item = (Elm_Object_Item *)ei;
1139         if (item == NULL) {
1140                 return;
1141         }
1142
1143         Evas_Object *ck = elm_object_item_part_content_get(ei, "elm.icon.right");
1144
1145         elm_genlist_item_selected_set(item, EINA_FALSE);
1146
1147         Eina_Bool state = elm_check_state_get(ck);
1148         elm_check_state_set(ck, !state);
1149
1150         _chk_changed_cb(NULL, ck, NULL);
1151 }
1152
1153 static void gl_lang_changed(void *data, Evas_Object *obj, void *event_info)
1154 {
1155         elm_genlist_realized_items_update(obj);
1156 }
1157
1158 static void __common_eap_connect_popup_init_item_class(void *data)
1159 {
1160         g_eap_type_itc.item_style = WIFI_GENLIST_2LINE_BOTTOM_SWALLOW_STYLE;
1161         g_eap_type_itc.func.text_get = _gl_eap_type_text_get;
1162         g_eap_type_itc.func.content_get = _gl_eap_type_content_get;
1163         g_eap_type_itc.func.state_get = NULL;
1164         g_eap_type_itc.func.del = NULL;
1165
1166         g_eap_auth_itc.item_style = WIFI_GENLIST_2LINE_BOTTOM_SWALLOW_STYLE;
1167         g_eap_auth_itc.func.text_get = _gl_eap_auth_text_get;
1168         g_eap_auth_itc.func.content_get = _gl_eap_auth_content_get;
1169         g_eap_auth_itc.func.state_get = NULL;
1170         g_eap_auth_itc.func.del = NULL;
1171
1172         g_eap_user_cert_itc.item_style = WIFI_GENLIST_2LINE_BOTTOM_SWALLOW_STYLE;
1173         g_eap_user_cert_itc.func.text_get = _gl_eap_user_cert_text_get;
1174         g_eap_user_cert_itc.func.content_get = _gl_eap_user_cert_content_get;
1175         g_eap_user_cert_itc.func.state_get = NULL;
1176         g_eap_user_cert_itc.func.del = NULL;
1177
1178         g_eap_entry_itc.item_style = WIFI_GENLIST_2LINE_BOTTOM_SWALLOW_STYLE;
1179         g_eap_entry_itc.func.text_get = _gl_eap_entry_item_text_get;
1180         g_eap_entry_itc.func.content_get = _gl_eap_entry_item_content_get;
1181         g_eap_entry_itc.func.state_get = NULL;
1182         g_eap_entry_itc.func.del = _gl_eap_entry_item_del;
1183
1184         g_eap_chkbox_itc.item_style = WIFI_GENLIST_1LINE_TEXT_ICON_STYLE;
1185         g_eap_chkbox_itc.func.text_get = _gl_eap_chkbox_item_text_get;
1186         g_eap_chkbox_itc.func.content_get = _gl_eap_chkbox_item_content_get;
1187         g_eap_chkbox_itc.func.state_get = NULL;
1188         g_eap_chkbox_itc.func.del = NULL;
1189 }
1190
1191 static gboolean __cert_extract_files(const char *cert_alias,
1192                 eap_connect_data_t *eap_data)
1193 {
1194         int ret;
1195         int validity;
1196         size_t cert_counts = 0;
1197         int cert_index;
1198         gchar *ca_cert_path = NULL;
1199         gchar *user_cert_path = NULL;
1200         gchar *privatekey_path = NULL;
1201         FILE *fp;
1202         CertSvcInstance cert_instance;
1203         CertSvcString cert_alias_str;
1204         CertSvcCertificateList cert_list;
1205         CertSvcCertificate user_certificate;
1206         CertSvcCertificate ca_certificate;
1207         CertSvcCertificate *selected_certificate = NULL;
1208         X509 *x509 = NULL;
1209         EVP_PKEY *privatekey = NULL;
1210
1211         ret = certsvc_instance_new(&cert_instance);
1212         if (ret != CERTSVC_SUCCESS) {
1213                 ERROR_LOG(UG_NAME_NORMAL, "failed to certsvc_instance_new");
1214                 goto error;
1215         }
1216         ret = certsvc_string_new(cert_instance, cert_alias, strlen(cert_alias), &cert_alias_str);
1217         if (ret != CERTSVC_SUCCESS) {
1218                 ERROR_LOG(UG_NAME_NORMAL, "failed to certsvc_string_new");
1219                 goto error;
1220         }
1221         ret = certsvc_pkcs12_load_certificate_list_from_store(cert_instance, WIFI_STORE, cert_alias_str, &cert_list);
1222         if (ret != CERTSVC_SUCCESS) {
1223                 ERROR_LOG(UG_NAME_NORMAL, "failed to certsvc_pkcs12_load_certificate_list_from_store");
1224                 goto error;
1225         }
1226         ret = certsvc_certificate_list_get_length(cert_list, &cert_counts);
1227         if (cert_counts < 1) {
1228                 ERROR_LOG(UG_NAME_NORMAL, "there is no certificates");
1229                 goto error;
1230         }
1231         INFO_LOG(UG_NAME_NORMAL, "cert counts: %d", cert_counts);
1232         selected_certificate = g_try_new0(CertSvcCertificate, cert_counts);
1233         if (selected_certificate == NULL) {
1234                 ERROR_LOG(UG_NAME_NORMAL, "failed to allocate memory");
1235                 goto error;
1236         }
1237         ret = certsvc_certificate_list_get_one(cert_list, 0, &user_certificate);
1238         if (ret != CERTSVC_SUCCESS) {
1239                 ERROR_LOG(UG_NAME_NORMAL, "failed to certsvc_certificate_list_get_one");
1240                 goto error;
1241         }
1242         cert_index = cert_counts - 1;
1243
1244         selected_certificate[0] = user_certificate;
1245
1246         ret = certsvc_certificate_dup_x509(user_certificate, &x509);
1247
1248         user_cert_path = g_strdup_printf("%s%s_%s", EAP_TLS_PATH,
1249                                 cert_alias, EAP_TLS_USER_CERT_PATH);
1250         if ((fp = fopen(user_cert_path, "w")) == NULL) {
1251                 goto error;
1252         }
1253         ret = PEM_write_X509(fp, x509);
1254         fclose(fp);
1255         certsvc_certificate_free_x509(x509);
1256         INFO_LOG(UG_NAME_NORMAL, "success to save user_cert file");
1257
1258         ca_cert_path = g_strdup_printf("%s%s_%s", EAP_TLS_PATH, cert_alias,
1259                                 EAP_TLS_CA_CERT_PATH);
1260         while (cert_index) {
1261                 ret = certsvc_certificate_list_get_one(cert_list, cert_index, &ca_certificate);
1262                 if (ret != CERTSVC_SUCCESS) {
1263                         ERROR_LOG(UG_NAME_NORMAL, "failed to certsvc_certificate_list_get_one");
1264                         goto error;
1265                 }
1266
1267                 selected_certificate[cert_counts-cert_index] = ca_certificate;
1268                 cert_index--;
1269
1270                 ret = certsvc_certificate_dup_x509(ca_certificate, &x509);
1271                 if ((fp = fopen(ca_cert_path, "a")) == NULL) {
1272                         goto error;
1273                 }
1274                 ret = PEM_write_X509(fp, x509);
1275                 fclose(fp);
1276                 certsvc_certificate_free_x509(x509);
1277         }
1278         INFO_LOG(UG_NAME_NORMAL, "success to save ca_cert file");
1279         ret = certsvc_certificate_verify(selected_certificate[0], selected_certificate, cert_counts, NULL, 0, &validity);
1280         if (ret != CERTSVC_SUCCESS) {
1281                 ERROR_LOG(UG_NAME_NORMAL, "failed to verify ca_certificate");
1282                 goto error;
1283         }
1284         if (validity == 0) {
1285                 ERROR_LOG(UG_NAME_NORMAL, "Invalid certificate");
1286                 goto error;
1287         }
1288
1289         ret = certsvc_pkcs12_dup_evp_pkey_from_store(cert_instance, WIFI_STORE, cert_alias_str, &privatekey);
1290
1291         privatekey_path = g_strdup_printf("%s%s_%s", EAP_TLS_PATH,
1292                                 cert_alias, EAP_TLS_PRIVATEKEY_PATH);
1293
1294         if ((fp = fopen(privatekey_path, "w")) == NULL) {
1295                 goto error;
1296         }
1297         ret = PEM_write_PrivateKey(fp, privatekey, NULL, NULL, 0, NULL, NULL);
1298         fclose(fp);
1299         certsvc_pkcs12_free_evp_pkey(privatekey);
1300         INFO_LOG(UG_NAME_NORMAL, "success to save privatekey file");
1301
1302         g_free(selected_certificate);
1303         certsvc_instance_free(cert_instance);
1304
1305         eap_data->ca_cert_path = ca_cert_path;
1306         eap_data->user_cert_path = user_cert_path;
1307         eap_data->privatekey_path = privatekey_path;
1308
1309         return TRUE;
1310
1311 error:
1312         g_free(ca_cert_path);
1313         g_free(user_cert_path);
1314         g_free(privatekey_path);
1315
1316         if (selected_certificate) {
1317                 g_free(selected_certificate);
1318         }
1319
1320         certsvc_instance_free(cert_instance);
1321         return FALSE;
1322 }
1323
1324 /* This creates EAP type, Auth type, CA certificate, User certificate,
1325  * User Id, Anonymous Id and Password items.
1326  */
1327 static void _create_and_update_list_items_based_on_rules(eap_type_t new_type,
1328                 eap_connect_data_t *eap_data)
1329 {
1330         __COMMON_FUNC_ENTER__;
1331         Evas_Object* view_list = eap_data->genlist;
1332         Elm_Object_Item *insert_after_item = NULL;
1333         Elm_Object_Item *prev_item = NULL;
1334         common_utils_entry_info_t *edit_box_details;
1335         Eina_Bool auth_reqd = EINA_FALSE;
1336         Eina_Bool user_cert_reqd = EINA_FALSE;
1337         Eina_Bool id_reqd = EINA_FALSE;
1338         Eina_Bool pw_reqd = EINA_FALSE;
1339
1340         if (NULL == eap_data->eap_type_item) {
1341                 /* Create EAP method/type */
1342                 eap_data->eap_type_item = elm_genlist_item_append(
1343                                                 view_list, &g_eap_type_itc,
1344                                                 eap_data, NULL,
1345                                                 ELM_GENLIST_ITEM_NONE,
1346                                                 _gl_eap_item_sel_cb, eap_data);
1347         }
1348
1349         switch (new_type) {
1350         case EAP_SEC_TYPE_PEAP:
1351                 insert_after_item = eap_data->eap_type_item;
1352                 auth_reqd = EINA_TRUE;
1353                 user_cert_reqd = EINA_FALSE;
1354                 id_reqd = EINA_TRUE;
1355                 pw_reqd = EINA_TRUE;
1356                 break;
1357         case EAP_SEC_TYPE_TLS:
1358                 insert_after_item = eap_data->eap_type_item;
1359                 auth_reqd = EINA_FALSE;
1360                 user_cert_reqd = EINA_TRUE;
1361                 id_reqd = EINA_TRUE;
1362                 pw_reqd = EINA_FALSE;
1363                 break;
1364         case EAP_SEC_TYPE_TTLS:
1365                 insert_after_item = eap_data->eap_type_item;
1366                 auth_reqd = EINA_TRUE;
1367                 user_cert_reqd = EINA_FALSE;
1368                 id_reqd = EINA_TRUE;
1369                 pw_reqd = EINA_TRUE;
1370                 break;
1371         case EAP_SEC_TYPE_SIM:
1372         case EAP_SEC_TYPE_AKA:
1373                 _delete_eap_entry_items(eap_data);
1374                 auth_reqd = EINA_FALSE;
1375                 user_cert_reqd = EINA_FALSE;
1376                 id_reqd = EINA_FALSE;
1377                 pw_reqd = EINA_FALSE;
1378                 break;
1379         default:
1380                 break;
1381         }
1382
1383         if (auth_reqd == EINA_TRUE) {
1384                 if (eap_data->eap_auth_item == NULL) {
1385                         /* Add EAP phase2 authentication */
1386                         eap_data->eap_auth_item = elm_genlist_item_insert_after(
1387                                         view_list, &g_eap_auth_itc, eap_data, NULL,
1388                                         insert_after_item, ELM_GENLIST_ITEM_NONE,
1389                                         _gl_eap_item_sel_cb, eap_data);
1390                 }
1391         } else {
1392                 _delete_eap_auth_item(eap_data);
1393         }
1394
1395         if (user_cert_reqd == EINA_TRUE) {
1396                 if (eap_data->eap_user_cert_item == NULL) {
1397                         prev_item = eap_data->eap_type_item;
1398
1399                         /* Add User certificate */
1400                         eap_data->eap_user_cert_item = elm_genlist_item_insert_after(
1401                                         view_list, &g_eap_user_cert_itc, eap_data, NULL,
1402                                         prev_item, ELM_GENLIST_ITEM_NONE,
1403                                         _gl_eap_item_sel_cb, eap_data);
1404                 }
1405         } else {
1406                 _delete_eap_user_cert_item(eap_data);
1407         }
1408
1409         if (id_reqd == EINA_TRUE) {
1410                 if (eap_data->eap_id_item == NULL) {
1411                         if (new_type == EAP_SEC_TYPE_PEAP ||
1412                                         new_type == EAP_SEC_TYPE_TTLS) {
1413                                 prev_item = eap_data->eap_auth_item;
1414                         } else {
1415                                 prev_item = eap_data->eap_user_cert_item;
1416                         }
1417
1418                         /* Add EAP ID */
1419                         edit_box_details = g_try_new0(common_utils_entry_info_t, 1);
1420                         if (edit_box_details == NULL) {
1421                                 return;
1422                         }
1423
1424                         edit_box_details->ap = eap_data->ap;
1425                         edit_box_details->entry_id = ENTRY_TYPE_USER_ID;
1426                         edit_box_details->title_txt = "IDS_WIFI_BODY_IDENTITY";
1427                         edit_box_details->guide_txt = "IDS_WIFI_BODY_ENTER_IDENTITY";
1428                         edit_box_details->item = elm_genlist_item_insert_after(
1429                                         view_list, &g_eap_entry_itc, edit_box_details,
1430                                         NULL, prev_item,
1431                                         ELM_GENLIST_ITEM_NONE, _gl_editbox_sel_cb, NULL);
1432                         eap_data->eap_id_item = edit_box_details->item;
1433                 }
1434         } else {
1435                 _delete_eap_id_item(eap_data);
1436         }
1437
1438         if (pw_reqd == EINA_TRUE) {
1439                 if (eap_data->eap_pw_item == NULL) {
1440                         /* Add EAP Password */
1441                         edit_box_details = g_try_new0(common_utils_entry_info_t, 1);
1442                         if (edit_box_details == NULL) {
1443                                 return;
1444                         }
1445
1446                         edit_box_details->ap = eap_data->ap;
1447                         edit_box_details->entry_id = ENTRY_TYPE_PASSWORD;
1448                         edit_box_details->title_txt = "IDS_WIFI_HEADER_PASSWORD";
1449                         edit_box_details->guide_txt = "IDS_WIFI_HEADER_ENTER_PASSWORD";
1450                         edit_box_details->item = elm_genlist_item_insert_after(
1451                                         view_list, &g_eap_entry_itc,
1452                                         edit_box_details, NULL,
1453                                         eap_data->eap_id_item,
1454                                         ELM_GENLIST_ITEM_NONE,
1455                                         _gl_editbox_sel_cb, NULL);
1456                         eap_data->eap_pw_item = edit_box_details->item;
1457
1458                         _update_eap_id_item_enter_key(eap_data);
1459                 }
1460
1461                 if (eap_data->eap_chkbox_item == NULL) {
1462                         /* Add Show Password checkbox */
1463                         eap_data->eap_chkbox_item = elm_genlist_item_insert_after(
1464                                         view_list, &g_eap_chkbox_itc,
1465                                         eap_data->str_pkg_name, NULL,
1466                                         eap_data->eap_pw_item,
1467                                         ELM_GENLIST_ITEM_NONE,
1468                                         _gl_eap_chkbox_sel, NULL);
1469                 }
1470         } else {
1471                 _delete_eap_pw_items(eap_data);
1472         }
1473
1474         __COMMON_FUNC_EXIT__;
1475         return;
1476 }
1477
1478 static void _update_eap_id_item_enter_key(eap_connect_data_t *eap_data)
1479 {
1480         if (eap_data->eap_id_item == NULL)
1481                 return;
1482
1483         Evas_Object *entry = NULL;
1484         eap_type_t eap_type;
1485
1486         eap_type = __common_eap_connect_popup_get_eap_type(eap_data->ap);
1487         entry = elm_object_item_part_content_get(eap_data->eap_id_item,
1488                         "elm.icon.entry");
1489         if (entry) {
1490                 if (eap_type == EAP_SEC_TYPE_TLS) {
1491                         elm_entry_input_panel_return_key_type_set(entry,
1492                                         ECORE_IMF_INPUT_PANEL_RETURN_KEY_TYPE_DONE);
1493                 } else {
1494                         elm_entry_input_panel_return_key_type_set(entry,
1495                                         ECORE_IMF_INPUT_PANEL_RETURN_KEY_TYPE_NEXT);
1496                 }
1497         }
1498 }
1499
1500 static void _delete_eap_auth_item(eap_connect_data_t *eap_data)
1501 {
1502         __COMMON_FUNC_ENTER__;
1503
1504         if (eap_data->eap_auth_item != NULL) {
1505                 elm_object_item_del(eap_data->eap_auth_item);
1506                 eap_data->eap_auth_item = NULL;
1507         }
1508
1509         __COMMON_FUNC_EXIT__;
1510         return;
1511 }
1512
1513 static void _delete_eap_user_cert_item(eap_connect_data_t *eap_data)
1514 {
1515         __COMMON_FUNC_ENTER__;
1516
1517         if (eap_data->eap_user_cert_item != NULL) {
1518                 elm_object_item_del(eap_data->eap_user_cert_item);
1519                 eap_data->eap_user_cert_item = NULL;
1520         }
1521
1522         __COMMON_FUNC_EXIT__;
1523         return;
1524 }
1525
1526 static void _delete_eap_id_item(eap_connect_data_t *eap_data)
1527 {
1528         __COMMON_FUNC_ENTER__;
1529
1530         if (eap_data->eap_id_item != NULL) {
1531                 elm_object_item_del(eap_data->eap_id_item);
1532                 eap_data->eap_id_item = NULL;
1533         }
1534
1535         __COMMON_FUNC_EXIT__;
1536         return;
1537 }
1538
1539 static void _delete_eap_pw_items(eap_connect_data_t *eap_data)
1540 {
1541         __COMMON_FUNC_ENTER__;
1542
1543         _update_eap_id_item_enter_key(eap_data);
1544
1545         if (eap_data->eap_pw_item != NULL) {
1546                 elm_object_item_del(eap_data->eap_pw_item);
1547                 eap_data->eap_pw_item = NULL;
1548         }
1549
1550         if (eap_data->eap_chkbox_item) {
1551                 elm_object_item_del(eap_data->eap_chkbox_item);
1552                 eap_data->eap_chkbox_item = NULL;
1553         }
1554
1555         __COMMON_FUNC_EXIT__;
1556         return;
1557 }
1558
1559 void _delete_eap_entry_items(eap_connect_data_t *eap_data)
1560 {
1561         __COMMON_FUNC_ENTER__;
1562
1563         if (eap_data->eap_auth_item != NULL) {
1564                 elm_object_item_del(eap_data->eap_auth_item);
1565                 eap_data->eap_auth_item = NULL;
1566         }
1567
1568         if (eap_data->eap_user_cert_item != NULL) {
1569                 elm_object_item_del(eap_data->eap_user_cert_item);
1570                 eap_data->eap_user_cert_item = NULL;
1571         }
1572
1573         if (eap_data->eap_id_item != NULL) {
1574                 elm_object_item_del(eap_data->eap_id_item);
1575                 eap_data->eap_id_item = NULL;
1576         }
1577
1578         if (eap_data->eap_pw_item != NULL) {
1579                 elm_object_item_del(eap_data->eap_pw_item);
1580                 eap_data->eap_pw_item = NULL;
1581         }
1582
1583         if (eap_data->eap_chkbox_item != NULL) {
1584                 elm_object_item_del(eap_data->eap_chkbox_item);
1585                 eap_data->eap_chkbox_item = NULL;
1586         }
1587
1588         __COMMON_FUNC_EXIT__;
1589         return;
1590 }
1591
1592 static Evas_Object* _create_list(Evas_Object* parent, void *data)
1593 {
1594         __COMMON_FUNC_ENTER__;
1595         assertm_if(NULL == parent, "NULL!!");
1596
1597         eap_connect_data_t *eap_data = (eap_connect_data_t *)data;
1598         Evas_Object* view_list = NULL;
1599         eap_type_t eap_type = EAP_SEC_TYPE_UNKNOWN;
1600         retvm_if(eap_data == NULL, NULL);
1601
1602         __common_eap_connect_popup_init_item_class(eap_data);
1603
1604         eap_data->eap_done_ok = FALSE;
1605         eap_data->genlist = view_list = elm_genlist_add(parent);
1606         //elm_genlist_realization_mode_set(view_list, EINA_TRUE);
1607         elm_genlist_mode_set(view_list, ELM_LIST_COMPRESS);
1608         elm_scroller_content_min_limit(view_list, EINA_FALSE, EINA_TRUE);
1609
1610         evas_object_size_hint_weight_set(view_list, EVAS_HINT_EXPAND,
1611                         EVAS_HINT_EXPAND);
1612         evas_object_size_hint_align_set(view_list, EVAS_HINT_FILL, EVAS_HINT_FILL);
1613
1614         /* Set default values. eap type = PEAP, auth type = MSCHAPv2 */
1615         eap_type = __common_eap_connect_popup_get_eap_type(eap_data->ap);
1616         wifi_ap_set_eap_type(eap_data->ap,
1617                         (eap_type == EAP_SEC_TYPE_UNKNOWN) ?
1618                         WIFI_EAP_TYPE_PEAP :
1619                         __common_eap_connect_popup_get_wlan_eap_type(eap_type));
1620
1621         wifi_ap_set_eap_auth_type(eap_data->ap,
1622                                         WIFI_EAP_AUTH_TYPE_MSCHAPV2);
1623
1624         selected_cert = 0;
1625
1626         /* Create the entry items */
1627         _create_and_update_list_items_based_on_rules(eap_type, eap_data);
1628
1629         evas_object_smart_callback_add(view_list, "language,changed",
1630                         gl_lang_changed, NULL);
1631
1632         __COMMON_FUNC_EXIT__;
1633         return view_list;
1634 }
1635
1636 static Eina_Bool _enable_scan_updates_cb(void *data)
1637 {
1638         /* Lets enable the scan updates */
1639         wlan_manager_enable_scan_result_update();
1640
1641         /* Reset the ecore timer handle */
1642         common_util_manager_ecore_scan_update_timer_reset();
1643
1644         return ECORE_CALLBACK_CANCEL;
1645 }
1646
1647 static void __common_eap_connect_cleanup(eap_connect_data_t *eap_data)
1648 {
1649         if (eap_data == NULL) {
1650                 return;
1651         }
1652
1653         if (eap_data->conf != NULL) {
1654                 evas_object_smart_callback_del(eap_data->conf,
1655                                 "virtualkeypad,state,on",
1656                                 _eap_popup_keypad_on_cb);
1657                 evas_object_smart_callback_del(eap_data->conf,
1658                                 "virtualkeypad,state,off",
1659                                 _eap_popup_keypad_off_cb);
1660         }
1661
1662         if (eap_data->ssid != NULL) {
1663                 g_free(eap_data->ssid);
1664                 eap_data->ssid = NULL;
1665         }
1666
1667         if (eap_data->cert_alias) {
1668                 g_free(eap_data->cert_alias);
1669                 eap_data->cert_alias = NULL;
1670         }
1671
1672         if (eap_data->ca_cert_path) {
1673                 g_free(eap_data->ca_cert_path);
1674                 eap_data->ca_cert_path = NULL;
1675         }
1676
1677         if (eap_data->user_cert_path) {
1678                 g_free(eap_data->user_cert_path);
1679                 eap_data->user_cert_path = NULL;
1680         }
1681
1682         if (eap_data->privatekey_path) {
1683                 g_free(eap_data->privatekey_path);
1684                 eap_data->privatekey_path = NULL;
1685         }
1686
1687         wifi_ap_destroy(eap_data->ap);
1688         eap_data->ap = NULL;
1689
1690         if(eap_data->info_popup){
1691                 evas_object_del(eap_data->info_popup);
1692                 eap_data->info_popup = NULL;
1693         }
1694
1695         if (eap_data->popup != NULL) {
1696                 evas_object_hide(eap_data->popup);
1697                 evas_object_del(eap_data->popup);
1698         }
1699
1700         if(_eap_view_deref_cb != NULL) {
1701                 _eap_view_deref_cb();
1702                 _eap_view_deref_cb = NULL;
1703         }
1704
1705         /* A delay is needed to get the smooth Input panel closing animation effect */
1706         common_util_managed_ecore_scan_update_timer_add(0.1,
1707                         _enable_scan_updates_cb, NULL);
1708 }
1709
1710 static void __common_eap_connect_destroy_cb(void *data,  Evas_Object *obj,
1711                 void *event_info)
1712 {
1713         __common_eap_connect_cleanup((eap_connect_data_t *)data);
1714 }
1715
1716 static void _info_popup_ok_cb(void *data, Evas_Object *obj, void *event_info)
1717 {
1718         eap_connect_data_t *eap_data = (eap_connect_data_t *)data;
1719
1720         if (eap_data->info_popup != NULL) {
1721                 evas_object_del(eap_data->info_popup);
1722                 eap_data->info_popup = NULL;
1723         }
1724 }
1725
1726 static void __common_eap_connect_done_cb(void *data, Evas_Object *obj,
1727                 void *event_info)
1728 {
1729         char *str_id = NULL;
1730         char *str_pw = NULL;
1731         bool favorite = FALSE;
1732         wifi_eap_type_e eap_type;
1733         wifi_eap_auth_type_e eap_auth_type;
1734         eap_connect_data_t *eap_data = (eap_connect_data_t *)data;
1735         popup_btn_info_t popup_data;
1736
1737         __COMMON_FUNC_ENTER__;
1738         if (eap_data->eap_done_ok == TRUE) {
1739                 __COMMON_FUNC_EXIT__;
1740                 return;
1741         }
1742
1743         eap_data->eap_done_ok = TRUE;
1744
1745         wifi_ap_get_eap_type(eap_data->ap, &eap_type);
1746         wifi_ap_get_eap_auth_type(eap_data->ap, &eap_auth_type);
1747
1748         wifi_ap_is_favorite(eap_data->ap, &favorite);
1749         if (favorite == TRUE) {
1750                 wlan_manager_forget(eap_data->ap);
1751                 wifi_ap_refresh(eap_data->ap);
1752
1753                 wifi_ap_set_eap_type(eap_data->ap, eap_type);
1754                 wifi_ap_set_eap_auth_type(eap_data->ap, eap_auth_type);
1755         }
1756
1757         wifi_ap_set_eap_ca_cert_file(eap_data->ap, "");
1758         wifi_ap_set_eap_client_cert_file(eap_data->ap, "");
1759         wifi_ap_set_eap_private_key_info(eap_data->ap, "", "");
1760
1761         switch (eap_type) {
1762         case WIFI_EAP_TYPE_PEAP:
1763         case WIFI_EAP_TYPE_TTLS:
1764
1765                 str_id = common_utils_get_list_item_entry_txt(eap_data->eap_id_item);
1766                 if (str_id == NULL || str_id[0] == '\0') {
1767                         memset(&popup_data, 0, sizeof(popup_data));
1768                         popup_data.title_txt = eap_data->ssid;
1769                         popup_data.btn1_txt = "IDS_WIFI_SK2_OK";
1770                         popup_data.btn1_cb = _info_popup_ok_cb;
1771                         popup_data.btn1_data = eap_data;
1772                         popup_data.info_txt = "IDS_WIFI_BODY_ENTER_IDENTITY";
1773                         eap_data->eap_done_ok = FALSE;
1774                         eap_data->info_popup = common_utils_show_info_popup(eap_data->win,
1775                                                 &popup_data);
1776                         return;
1777                 }
1778
1779                 str_pw = common_utils_get_list_item_entry_txt(eap_data->eap_pw_item);
1780                 if (str_pw == NULL || str_pw[0] == '\0') {
1781                         memset(&popup_data, 0, sizeof(popup_data));
1782                         popup_data.title_txt = eap_data->ssid;
1783                         popup_data.btn1_txt = "IDS_WIFI_SK2_OK";
1784                         popup_data.btn1_cb = _info_popup_ok_cb;
1785                         popup_data.btn1_data = eap_data;
1786                         popup_data.info_txt = "IDS_WIFI_HEADER_ENTER_PASSWORD";
1787                         eap_data->eap_done_ok = FALSE;
1788                         eap_data->info_popup = common_utils_show_info_popup(eap_data->win,
1789                                                 &popup_data);
1790                         return;
1791                 }
1792
1793                 wifi_ap_set_eap_type(eap_data->ap, eap_type);
1794                 wifi_ap_set_eap_auth_type(eap_data->ap, eap_auth_type);
1795                 wifi_ap_set_eap_passphrase(eap_data->ap, str_id, str_pw);
1796                 break;
1797
1798         case WIFI_EAP_TYPE_TLS:
1799                 str_id = common_utils_get_list_item_entry_txt(eap_data->eap_id_item);
1800                 str_pw = common_utils_get_list_item_entry_txt(eap_data->eap_pw_item);
1801
1802                 wifi_ap_set_eap_type(eap_data->ap, eap_type);
1803                 wifi_ap_set_eap_auth_type(eap_data->ap, eap_auth_type);
1804                 wifi_ap_set_eap_passphrase(eap_data->ap, str_id, str_pw);
1805                 wifi_ap_set_eap_ca_cert_file(eap_data->ap, eap_data->ca_cert_path);
1806                 wifi_ap_set_eap_client_cert_file(eap_data->ap, eap_data->user_cert_path);
1807                 wifi_ap_set_eap_private_key_info(eap_data->ap,
1808                                 eap_data->privatekey_path, NULL);
1809                 break;
1810
1811         case WIFI_EAP_TYPE_SIM:
1812         case WIFI_EAP_TYPE_AKA:
1813                 break;
1814
1815         default:
1816                 ERROR_LOG(UG_NAME_NORMAL, "Unknown EAP method %d", eap_type);
1817                 break;
1818         }
1819
1820         if (eap_data->is_hidden) {
1821                 wifi_ap_h hidden_ap;
1822                 char *ssid;
1823                 wifi_ap_get_essid(eap_data->ap, &ssid);
1824                 wifi_ap_hidden_create(ssid, &hidden_ap);
1825                 g_free(ssid);
1826
1827                 switch (eap_type) {
1828                         case WIFI_EAP_TYPE_PEAP:
1829                         case WIFI_EAP_TYPE_TTLS:
1830                                 wifi_ap_set_eap_type(hidden_ap, eap_type);
1831                                 wifi_ap_set_eap_auth_type(hidden_ap, eap_auth_type);
1832                                 wifi_ap_set_eap_passphrase(hidden_ap, str_id, str_pw);
1833                                 break;
1834                         case WIFI_EAP_TYPE_TLS:
1835                         wifi_ap_set_eap_type(hidden_ap, eap_type);
1836                         wifi_ap_set_eap_auth_type(hidden_ap, eap_auth_type);
1837                         wifi_ap_set_eap_passphrase(hidden_ap, str_id, str_pw);
1838                         wifi_ap_set_eap_ca_cert_file(hidden_ap, eap_data->ca_cert_path);
1839                         wifi_ap_set_eap_client_cert_file(hidden_ap,eap_data->user_cert_path);
1840                         wifi_ap_set_eap_private_key_info(hidden_ap, eap_data->privatekey_path, NULL);
1841                                 break;
1842                         case WIFI_EAP_TYPE_SIM:
1843                         case WIFI_EAP_TYPE_AKA:
1844                                 break;
1845                 }
1846                 wlan_manager_connect(hidden_ap);
1847         } else
1848                 wlan_manager_connect(eap_data->ap);
1849
1850         __common_eap_connect_cleanup(eap_data);
1851
1852         __COMMON_FUNC_EXIT__;
1853 }
1854
1855 static gboolean delay_create_context_popup(gpointer data)
1856 {
1857         eap_connect_data_t *eap_data = (eap_connect_data_t *)data;
1858
1859         if (click.btn_click[EAP_CERT_BTN] == TRUE) {
1860                 _create_eap_cert_list(eap_data, click.btn_obj[EAP_CERT_BTN]);
1861
1862                 click.btn_click[EAP_CERT_BTN] = FALSE;
1863                 click.btn_obj[EAP_CERT_BTN] = NULL;
1864         } else if (click.btn_click[EAP_AUTH_BTN] == TRUE) {
1865                 _create_eap_auth_list(eap_data, click.btn_obj[EAP_AUTH_BTN]);
1866
1867                 click.btn_click[EAP_AUTH_BTN] = FALSE;
1868                 click.btn_obj[EAP_AUTH_BTN] = NULL;
1869         } else if (click.btn_click[EAP_TYPE_BTN] == TRUE) {
1870                 _create_eap_type_list(eap_data, click.btn_obj[EAP_TYPE_BTN]);
1871
1872                 click.btn_click[EAP_TYPE_BTN] = FALSE;
1873                 click.btn_obj[EAP_TYPE_BTN] = NULL;
1874         }
1875         return FALSE;
1876 }
1877
1878 static void _eap_popup_keypad_off_cb(void *data, Evas_Object *obj,
1879                 void *event_info)
1880 {
1881         if (data == NULL) {
1882                 return;
1883         }
1884
1885         eap_connect_data_t *eap_data = (eap_connect_data_t *)data;
1886
1887         keypad_state = FALSE;
1888
1889         common_util_managed_idle_add(delay_create_context_popup,
1890                         (gpointer)eap_data);
1891
1892         INFO_LOG(UG_NAME_NORMAL,"Keypad is down");
1893 }
1894
1895 static void _eap_popup_keypad_on_cb(void *data, Evas_Object *obj,
1896                 void *event_info)
1897 {
1898         if (data == NULL) {
1899                 return;
1900         }
1901
1902         keypad_state = TRUE;
1903         INFO_LOG(UG_NAME_NORMAL,"Keypad is up");
1904 }
1905
1906 eap_connect_data_t *create_eap_view(Evas_Object *layout_main, Evas_Object *win,
1907                 Evas_Object *conf, const char *pkg_name,
1908                 wifi_device_info_t *device_info, void (*deref_func)(void))
1909 {
1910         __COMMON_FUNC_ENTER__;
1911
1912         Evas_Object *popup = NULL;
1913         Evas_Object *list = NULL;
1914
1915         if (layout_main == NULL || device_info == NULL || pkg_name == NULL) {
1916                 return NULL;
1917         }
1918
1919         eap_connect_data_t *eap_data = g_try_new0(eap_connect_data_t, 1);
1920         if (eap_data == NULL) {
1921                 return NULL;
1922         }
1923
1924         eap_data->str_pkg_name = pkg_name;
1925         eap_data->win = win;
1926         eap_data->conf = conf;
1927         eap_data->ssid = g_strdup(device_info->ssid);
1928
1929         if (device_info->is_hidden == true) {
1930                 /* Hidden Wi-Fi network */
1931                 char *ssid = NULL;
1932
1933                 wifi_ap_get_essid(device_info->ap, &ssid);
1934                 if (ssid == NULL)
1935                         return NULL;
1936
1937                 wifi_ap_hidden_create(ssid, &(eap_data->ap));
1938                 g_free(ssid);
1939
1940                 eap_data->is_hidden = TRUE;
1941         } else {
1942                 /* Clone the Wi-Fi AP handle */
1943                 wifi_ap_clone(&(eap_data->ap), device_info->ap);
1944         }
1945
1946         /* Lets disable the scan updates so that the UI is not refreshed unnecessarily */
1947         wlan_manager_disable_scan_result_update();
1948
1949         _eap_view_deref_cb = deref_func;
1950         click.btn_click[EAP_TYPE_BTN] = FALSE;
1951         click.btn_obj[EAP_TYPE_BTN] = NULL;
1952         click.btn_click[EAP_AUTH_BTN] = FALSE;
1953         click.btn_obj[EAP_AUTH_BTN] = NULL;
1954         click.btn_click[EAP_CERT_BTN] = FALSE;
1955         click.btn_obj[EAP_CERT_BTN] = NULL;
1956         keypad_state = FALSE;
1957
1958         popup_btn_info_t popup_btn_data;
1959         memset(&popup_btn_data, 0, sizeof(popup_btn_data));
1960
1961         popup_btn_data.title_txt = device_info->ssid;
1962         popup_btn_data.btn1_cb = __common_eap_connect_destroy_cb;
1963         popup_btn_data.btn1_data = eap_data;
1964         popup_btn_data.btn1_txt = "IDS_WIFI_SK_CANCEL";
1965         popup_btn_data.btn2_cb = __common_eap_connect_done_cb;
1966         popup_btn_data.btn2_data = eap_data;
1967         popup_btn_data.btn2_txt = "IDS_WIFI_BODY_CONNECT";
1968
1969         popup = common_utils_show_info_popup(layout_main,
1970                         &popup_btn_data);
1971         eap_data->popup = popup;
1972         evas_object_show(popup);
1973         elm_object_focus_set(popup, EINA_TRUE);
1974
1975         /* Create an EAP connect view list */
1976         list = _create_list(popup, eap_data);
1977         elm_object_content_set(popup, list);
1978
1979         evas_object_smart_callback_add(eap_data->conf,
1980                         "virtualkeypad,state,on", _eap_popup_keypad_on_cb,
1981                         eap_data);
1982         evas_object_smart_callback_add(eap_data->conf,
1983                         "virtualkeypad,state,off", _eap_popup_keypad_off_cb,
1984                         eap_data);
1985
1986         __COMMON_FUNC_EXIT__;
1987         return eap_data;
1988 }
1989
1990 static wifi_eap_type_e __common_eap_connect_popup_get_wlan_eap_type(eap_type_t eap_type)
1991 {
1992         wifi_eap_type_e wlan_eap_type = WLAN_SEC_EAP_TYPE_PEAP;
1993         switch (eap_type) {
1994         case EAP_SEC_TYPE_PEAP:
1995                 wlan_eap_type = WIFI_EAP_TYPE_PEAP;
1996                 break;
1997         case EAP_SEC_TYPE_TLS:
1998                 wlan_eap_type = WIFI_EAP_TYPE_TLS;
1999                 break;
2000         case EAP_SEC_TYPE_TTLS:
2001                 wlan_eap_type = WIFI_EAP_TYPE_TTLS;
2002                 break;
2003         case EAP_SEC_TYPE_SIM:
2004                 wlan_eap_type = WIFI_EAP_TYPE_SIM;
2005                 break;
2006         case EAP_SEC_TYPE_AKA:
2007                 wlan_eap_type = WIFI_EAP_TYPE_AKA;
2008                 break;
2009         default:
2010                 ERROR_LOG(UG_NAME_NORMAL, "Err! This case should never occur");
2011                 break;
2012         }
2013
2014         return wlan_eap_type;
2015 }
2016
2017 static wifi_eap_auth_type_e __common_eap_connect_popup_get_wlan_auth_type(eap_auth_t auth_type)
2018 {
2019         wifi_eap_auth_type_e wlan_auth_type = WIFI_EAP_AUTH_TYPE_NONE;
2020         switch (auth_type) {
2021         case EAP_SEC_AUTH_NONE:
2022                 wlan_auth_type = WIFI_EAP_AUTH_TYPE_NONE;
2023                 break;
2024         case EAP_SEC_AUTH_PAP:
2025                 wlan_auth_type = WIFI_EAP_AUTH_TYPE_PAP;
2026                 break;
2027         case EAP_SEC_AUTH_MSCHAP:
2028                 wlan_auth_type = WIFI_EAP_AUTH_TYPE_MSCHAP;
2029                 break;
2030         case EAP_SEC_AUTH_MSCHAPV2:
2031                 wlan_auth_type = WIFI_EAP_AUTH_TYPE_MSCHAPV2;
2032                 break;
2033         case EAP_SEC_AUTH_GTC:
2034                 wlan_auth_type = WIFI_EAP_AUTH_TYPE_GTC;
2035                 break;
2036         case EAP_SEC_AUTH_MD5:
2037                 wlan_auth_type = WIFI_EAP_AUTH_TYPE_MD5;
2038                 break;
2039         default:
2040                 /* This case should never occur */
2041                 ERROR_LOG(UG_NAME_NORMAL, "Err!");
2042                 break;
2043         }
2044         return wlan_auth_type;
2045 }
2046
2047 static eap_type_t __common_eap_connect_popup_get_eap_type(wifi_ap_h ap)
2048 {
2049         wifi_eap_type_e wlan_eap_type = 0;
2050         int ret = wifi_ap_get_eap_type(ap, &wlan_eap_type);
2051         if (WIFI_ERROR_OPERATION_FAILED == ret) {
2052                 ret = wifi_ap_set_eap_type(ap, WIFI_EAP_TYPE_PEAP);
2053         }
2054
2055         if (WIFI_ERROR_NONE != ret) {
2056                 ERROR_LOG(UG_NAME_ERR, "Unable to get the eap type. err = %d", ret);
2057                 return EAP_SEC_TYPE_UNKNOWN;
2058         }
2059
2060         switch (wlan_eap_type) {
2061         case WIFI_EAP_TYPE_PEAP:  /**< EAP PEAP type */
2062                 return EAP_SEC_TYPE_PEAP;
2063
2064         case WIFI_EAP_TYPE_TLS:  /**< EAP TLS type */
2065                 return EAP_SEC_TYPE_TLS;
2066
2067         case WIFI_EAP_TYPE_TTLS:  /**< EAP TTLS type */
2068                 return EAP_SEC_TYPE_TTLS;
2069
2070         case WIFI_EAP_TYPE_SIM:  /**< EAP SIM type */
2071                 return EAP_SEC_TYPE_SIM;
2072
2073         case WIFI_EAP_TYPE_AKA:  /**< EAP AKA type */
2074                 return EAP_SEC_TYPE_AKA;
2075
2076         default:
2077                 return EAP_SEC_TYPE_PEAP;
2078         }
2079         return EAP_SEC_TYPE_PEAP;
2080 }
2081
2082 static eap_auth_t __common_eap_connect_popup_get_auth_type(wifi_ap_h ap)
2083 {
2084         wifi_eap_auth_type_e wlan_auth_type = 0;
2085         int ret = wifi_ap_get_eap_auth_type(ap, &wlan_auth_type);
2086         if (WIFI_ERROR_OPERATION_FAILED == ret) {
2087                 ret = wifi_ap_set_eap_auth_type(ap, EAP_SEC_AUTH_NONE);
2088         }
2089
2090         if (WIFI_ERROR_NONE != ret) {
2091                 ERROR_LOG(UG_NAME_ERR, "Unable to get the eap auth type. err = %d", ret);
2092                 return EAP_SEC_AUTH_NONE;
2093         }
2094
2095         switch (wlan_auth_type) {
2096         case WIFI_EAP_AUTH_TYPE_NONE:  /**< EAP phase2 authentication none */
2097                 return EAP_SEC_AUTH_NONE;
2098
2099         case WIFI_EAP_AUTH_TYPE_PAP:  /**< EAP phase2 authentication PAP */
2100                 return EAP_SEC_AUTH_PAP;
2101
2102         case WIFI_EAP_AUTH_TYPE_MSCHAP:  /**< EAP phase2 authentication MSCHAP */
2103                 return EAP_SEC_AUTH_MSCHAP;
2104
2105         case WIFI_EAP_AUTH_TYPE_MSCHAPV2:  /**< EAP phase2 authentication MSCHAPv2 */
2106                 return EAP_SEC_AUTH_MSCHAPV2;
2107
2108         case WIFI_EAP_AUTH_TYPE_GTC:  /**< EAP phase2 authentication GTC */
2109                 return EAP_SEC_AUTH_GTC;
2110
2111         case WIFI_EAP_AUTH_TYPE_MD5:  /**< EAP phase2 authentication MD5 */
2112                 return EAP_SEC_AUTH_MD5;
2113
2114         default:
2115                 return EAP_SEC_AUTH_NONE;
2116         }
2117         return EAP_SEC_AUTH_NONE;
2118 }
2119
2120 static char *_eap_info_get_user_cert_alias(wifi_ap_h ap)
2121 {
2122         char *path = NULL;
2123         char *alias = NULL;
2124         char *filename = NULL;
2125         char *cert_name = NULL;
2126         int alias_len = 0;
2127         int filename_len = 0;
2128
2129         wifi_ap_get_eap_client_cert_file(ap, &path);
2130         if (path == NULL)
2131                 return NULL;
2132
2133         filename = strrchr(path, '/');
2134         if (filename == NULL) {
2135                 ERROR_LOG(UG_NAME_ERR, "Invalid file name");
2136                 goto EXIT;
2137         }
2138
2139         filename++;
2140         cert_name = strstr(filename, EAP_TLS_USER_CERT_PATH);
2141         if (cert_name == NULL) {
2142                 /* For truncated path, available filename will be followed
2143                  * with ellipsis(...) & excluding any remaining part of
2144                  * "_user_cert.pem" - 14 chars (-14+3+1=10)*/
2145                 filename_len = strlen(filename);
2146                 alias = g_try_malloc0(filename_len - 10);
2147                 if (alias == NULL) {
2148                         ERROR_LOG(UG_NAME_ERR, "malloc fail");
2149                         goto EXIT;
2150                 }
2151                 g_strlcpy(alias, filename, filename_len - 13);
2152                 g_strlcat(alias, "...", filename_len - 10);
2153                 INFO_LOG(UG_NAME_NORMAL, "Truncated alias [%s]", alias);
2154                 goto EXIT;
2155         }
2156
2157         cert_name--;
2158         alias_len = cert_name - filename;
2159
2160         alias = g_try_malloc0(alias_len + 1);
2161         if (alias == NULL) {
2162                 ERROR_LOG(UG_NAME_ERR, "malloc fail");
2163                 goto EXIT;
2164         }
2165
2166         g_strlcpy(alias, filename, alias_len + 1);
2167         INFO_LOG(UG_NAME_NORMAL, "Alias [%s] length [%d]", alias, alias_len);
2168
2169 EXIT:
2170         g_free(path);
2171
2172         return alias;
2173 }
2174
2175 /* This creates Auth type, ID, Anonymous Id and Password items
2176  * This function should be called after creating the EAP type item
2177  */
2178 eap_info_list_t *eap_info_append_items(wifi_ap_h ap, Evas_Object* view_list,
2179                 const char *str_pkg_name, imf_ctxt_panel_cb_t input_panel_cb,
2180                 void *input_panel_cb_data)
2181 {
2182         __COMMON_FUNC_ENTER__;
2183
2184         eap_type_t eap_type;
2185         eap_auth_t auth_type;
2186         char *temp_str = NULL;
2187         Eina_Bool append_continue = TRUE;
2188         eap_info_list_t *eap_info_list_data = NULL;
2189         Elm_Object_Item* item = NULL;
2190         if (!view_list || !str_pkg_name || !ap) {
2191                 ERROR_LOG(UG_NAME_ERR, "Invalid params passed!");
2192                 return NULL;
2193         }
2194
2195         eap_info_list_data = g_try_new0(eap_info_list_t, 1);
2196         if (eap_info_list_data == NULL) {
2197                 return NULL;
2198         }
2199
2200         eap_info_list_data->ap = ap;
2201         eap_type = __common_eap_connect_popup_get_eap_type(ap);
2202         auth_type = __common_eap_connect_popup_get_auth_type(ap);
2203
2204         item = common_utils_add_2_line_txt_disabled_item(view_list,
2205                         WIFI_GENLIST_2LINE_TOP_TEXT_STYLE,
2206                         sc(str_pkg_name, I18N_TYPE_EAP_method),
2207                         list_eap_type[eap_type].name);
2208         eap_info_list_data->eap_method_item = item;
2209
2210         eap_info_list_data->eap_type = eap_type;
2211
2212         switch (eap_type) {
2213         case EAP_SEC_TYPE_UNKNOWN:
2214         case EAP_SEC_TYPE_PEAP:
2215         case EAP_SEC_TYPE_TLS:
2216         case EAP_SEC_TYPE_TTLS:
2217                 break;
2218         case EAP_SEC_TYPE_SIM:
2219         case EAP_SEC_TYPE_AKA:
2220         default:
2221                 append_continue = FALSE;
2222                 break;
2223         }
2224
2225         if (append_continue) {
2226                 if (eap_type == EAP_SEC_TYPE_PEAP ||
2227                                 eap_type == EAP_SEC_TYPE_TTLS) {
2228                         /* Add EAP phase2 authentication */
2229                         item = common_utils_add_2_line_txt_disabled_item(view_list,
2230                                         WIFI_GENLIST_2LINE_TOP_TEXT_STYLE,
2231                                         sc(str_pkg_name, I18N_TYPE_Phase_2_authentication),
2232                                         list_eap_auth[auth_type].name);
2233                         eap_info_list_data->eap_auth_item = item;
2234                 }
2235
2236                 if (eap_type == EAP_SEC_TYPE_TLS) {
2237                         /* Add User certificate */
2238                         temp_str = _eap_info_get_user_cert_alias(ap);
2239
2240                         if (temp_str == NULL || strlen(temp_str) == 0) {
2241                                 if (temp_str != NULL) {
2242                                         g_free(temp_str);
2243                                 }
2244                                 temp_str = g_strdup(sc(str_pkg_name,
2245                                                 I18N_TYPE_Unspecified));
2246                         }
2247
2248                         item = common_utils_add_2_line_txt_disabled_item(view_list,
2249                                         WIFI_GENLIST_2LINE_TOP_TEXT_STYLE,
2250                                         sc(str_pkg_name, I18N_TYPE_User_Certificate),
2251                                         temp_str);
2252                         eap_info_list_data->user_cert_item = item;
2253                         g_free(temp_str);
2254                 }
2255
2256                 /* Add EAP ID */
2257                 bool is_paswd_set;
2258                 temp_str = NULL;
2259                 wifi_ap_get_eap_passphrase(ap, &temp_str, &is_paswd_set);
2260                 item = common_utils_add_2_line_txt_disabled_item(view_list,
2261                                 WIFI_GENLIST_2LINE_TOP_TEXT_STYLE,
2262                                 sc(str_pkg_name, I18N_TYPE_Identity),
2263                                 temp_str);
2264                 eap_info_list_data->id_item = item;
2265                 g_free(temp_str);
2266
2267 #if 0
2268                 common_utils_entry_info_t *edit_box_details;
2269
2270                 /* Add EAP Password */
2271                 g_eap_entry_itc.item_style = "entry.main";
2272                 g_eap_entry_itc.func.text_get = _gl_eap_entry_item_text_get;
2273                 g_eap_entry_itc.func.content_get = _gl_eap_entry_item_content_get;
2274                 g_eap_entry_itc.func.state_get = NULL;
2275                 g_eap_entry_itc.func.del = _gl_eap_entry_item_del;
2276
2277                 edit_box_details = g_try_new0(common_utils_entry_info_t, 1);
2278                 if (edit_box_details == NULL) {
2279                         g_free(eap_info_list_data);
2280                         return NULL;
2281                 }
2282
2283                 edit_box_details->entry_id = ENTRY_TYPE_PASSWORD;
2284                 edit_box_details->title_txt = sc(str_pkg_name, I18N_TYPE_Password);
2285                 edit_box_details->entry_txt = NULL;
2286                 edit_box_details->guide_txt = sc(str_pkg_name, I18N_TYPE_Enter_password);
2287                 edit_box_details->input_panel_cb = input_panel_cb;
2288                 edit_box_details->input_panel_cb_data = input_panel_cb_data;
2289                 edit_box_details->item = elm_genlist_item_append(view_list,
2290                                 &g_eap_entry_itc, edit_box_details, NULL,
2291                                 ELM_GENLIST_ITEM_NONE, _gl_editbox_sel_cb, NULL);
2292                 elm_genlist_item_select_mode_set(edit_box_details->item,
2293                                 ELM_OBJECT_SELECT_MODE_NONE);
2294                 eap_info_list_data->pswd_item = edit_box_details->item;
2295 #endif
2296         }
2297
2298         __COMMON_FUNC_EXIT__;
2299         return eap_info_list_data;
2300 }
2301
2302 #if 0
2303 void eap_info_save_data(eap_info_list_t *eap_info_list_data)
2304 {
2305         if (!eap_info_list_data) {
2306                 ERROR_LOG(UG_NAME_ERR, "Invalid params passed!");
2307                 return;
2308         }
2309         char *txt = common_utils_get_list_item_entry_txt(eap_info_list_data->pswd_item);
2310
2311         wifi_ap_set_eap_passphrase(eap_info_list_data->ap, NULL, txt);
2312         g_free(txt);
2313         return;
2314 }
2315 #endif
2316
2317 void eap_info_remove(eap_info_list_t *eap_info_list_data)
2318 {
2319         if (!eap_info_list_data) {
2320                 ERROR_LOG(UG_NAME_ERR, "Invalid params passed!");
2321                 return;
2322         }
2323
2324         g_free(eap_info_list_data);
2325 }
2326
2327 void eap_connect_data_free(eap_connect_data_t *eap_data)
2328 {
2329         __common_eap_connect_cleanup(eap_data);
2330 }