2e980715e26e17687f385d5feb8cb2cd2bd0fbc1
[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 <vconf-keys.h>
26 #include <glib/gstdio.h>
27 #include <efl_extension.h>
28
29 #include "common.h"
30 #include "ug_wifi.h"
31 #include "common_eap_connect.h"
32 #include "i18nmanager.h"
33 #include "common_utils.h"
34 #include "common_ip_info.h"
35
36 #define GENLIST_ITEM_HEIGHT                             96
37 #define MAX_LABEL_LENGTH                                512
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, "eap_dropdown_button");
773                 btn = elm_button_add(obj);
774
775                 if (sel_sub_item_id == EAP_SEC_AUTH_NONE) {
776                         g_snprintf(buf, sizeof(buf), "<align=left>%s</align>",
777                                         sc(PACKAGE, I18N_TYPE_None));
778                 } else {
779                         g_snprintf(buf, sizeof(buf), "<align=left>%s</align>",
780                                         list_eap_auth[sel_sub_item_id].name);
781                 }
782
783                 elm_object_domain_translatable_text_set(btn, PACKAGE, buf);
784                 elm_object_style_set(btn, "dropdown/label");
785                 evas_object_propagate_events_set(btn, EINA_FALSE);
786                 evas_object_size_hint_weight_set(btn, EVAS_HINT_EXPAND,
787                                 EVAS_HINT_EXPAND);
788                 evas_object_size_hint_align_set(btn, EVAS_HINT_FILL,
789                                 EVAS_HINT_FILL);
790                 evas_object_smart_callback_add(btn, "clicked",
791                                 _gl_eap_auth_btn_cb, eap_data);
792
793                 elm_layout_content_set(ly, "btn", btn);
794                 return ly;
795         }
796         return NULL;
797 }
798
799 static void _gl_eap_entry_key_enter_cb(void *data, Evas_Object *obj, void *event_info)
800 {
801         common_utils_entry_info_t *entry_info = (common_utils_entry_info_t *)data;
802         if (!entry_info) {
803                 return;
804         }
805
806         Evas_Object *entry = NULL;
807         Elm_Object_Item *next_item = NULL;
808         eap_type_t eap_type;
809
810         switch (entry_info->entry_id) {
811         case ENTRY_TYPE_USER_ID:
812                 eap_type = __common_eap_connect_popup_get_eap_type(
813                                 entry_info->ap);
814
815                 if (eap_type == EAP_SEC_TYPE_TLS) {
816                         entry = elm_object_item_part_content_get(entry_info->item,
817                                         "elm.icon.entry");
818                         if (entry) {
819                                 elm_object_focus_set(entry, EINA_FALSE);
820                         }
821                 } else {
822                         next_item = elm_genlist_item_next_get(entry_info->item);
823                         while (next_item) {
824                                 if (elm_object_item_disabled_get(next_item) == EINA_FALSE &&
825                                         elm_genlist_item_select_mode_get(next_item) !=
826                                                         ELM_OBJECT_SELECT_MODE_DISPLAY_ONLY) {
827                                         entry = elm_object_item_part_content_get(
828                                                         next_item, "elm.icon.entry");
829                                         if (entry) {
830                                                 elm_object_focus_set(entry, EINA_TRUE);
831                                                 return;
832                                         }
833                                 }
834
835                                 next_item = elm_genlist_item_next_get(next_item);
836                         }
837                 }
838                 break;
839         case ENTRY_TYPE_PASSWORD:
840                 entry = elm_object_item_part_content_get(entry_info->item,
841                                 "elm.icon.entry");
842                 if (entry) {
843                         elm_object_focus_set(entry, EINA_FALSE);
844                 }
845                 break;
846         default:
847                 break;
848         }
849 }
850
851 static void _gl_eap_entry_cursor_changed_cb(void* data, Evas_Object* obj, void* event_info)
852 {
853         common_utils_entry_info_t *entry_info = (common_utils_entry_info_t *)data;
854         if (!entry_info) {
855                 return;
856         }
857
858         if (elm_object_focus_get(obj)) {
859                 if (elm_entry_is_empty(obj)) {
860                         elm_object_item_signal_emit(entry_info->item, "elm,state,eraser,hide", "");
861                 } else {
862                         elm_object_item_signal_emit(entry_info->item, "elm,state,eraser,show", "");
863                 }
864         }
865
866         if (entry_info->entry_txt) {
867                 g_free(entry_info->entry_txt);
868                 entry_info->entry_txt = NULL;
869         }
870
871         char *entry_text = elm_entry_markup_to_utf8(elm_entry_entry_get(obj));
872
873         if (entry_text != NULL && entry_text[0] != '\0') {
874                 entry_info->entry_txt = elm_entry_markup_to_utf8(elm_entry_entry_get(obj));
875         }
876
877         g_free(entry_text);
878 }
879
880 static void _gl_eap_entry_changed_cb(void* data, Evas_Object* obj, void* event_info)
881 {
882         common_utils_entry_info_t *entry_info = (common_utils_entry_info_t *)data;
883         if (!entry_info) {
884                 return;
885         }
886
887         if (obj == NULL) {
888                 return;
889         }
890
891         if (elm_object_focus_get(obj)) {
892                 if (elm_entry_is_empty(obj)) {
893                         elm_object_item_signal_emit(entry_info->item, "elm,state,eraser,hide", "");
894                 } else {
895                         elm_object_item_signal_emit(entry_info->item, "elm,state,eraser,show", "");
896                 }
897         }
898 }
899
900 static void _gl_eap_entry_focused_cb(void *data, Evas_Object *obj, void *event_info)
901 {
902         common_utils_entry_info_t *entry_info = (common_utils_entry_info_t *)data;
903         if (!entry_info) {
904                 return;
905         }
906
907         if (!elm_entry_is_empty(obj)) {
908                 elm_object_item_signal_emit(entry_info->item, "elm,state,eraser,show", "");
909         }
910
911         elm_object_item_signal_emit(entry_info->item, "elm,state,rename,hide", "");
912 }
913
914 static void _gl_eap_entry_unfocused_cb(void *data, Evas_Object *obj, void *event_info)
915 {
916         common_utils_entry_info_t *entry_info = (common_utils_entry_info_t *)data;
917         if (!entry_info) {
918                 return;
919         }
920
921         if (entry_info->entry_txt) {
922                 g_free(entry_info->entry_txt);
923                 entry_info->entry_txt = NULL;
924         }
925
926         char *entry_text = elm_entry_markup_to_utf8(elm_entry_entry_get(obj));
927         if (entry_text != NULL && entry_text[0] != '\0')
928                 entry_info->entry_txt = elm_entry_markup_to_utf8(elm_entry_entry_get(obj));
929
930         g_free(entry_text);
931
932         elm_object_item_signal_emit(entry_info->item, "elm,state,eraser,hide", "");
933         elm_object_item_signal_emit(entry_info->item, "elm,state,rename,show", "");
934 }
935
936 static void _gl_eap_entry_maxlength_reached(void *data, Evas_Object *obj,
937                 void *event_info)
938 {
939         common_utils_send_message_to_net_popup("Password length",
940                         "Lengthy Password", "notification", NULL);
941 }
942
943 static void _gl_eap_entry_eraser_clicked_cb(void *data, Evas_Object *obj, void *event_info)
944 {
945         common_utils_entry_info_t *entry_info = (common_utils_entry_info_t *)data;
946         if (!entry_info) {
947                 return;
948         }
949
950         Evas_Object *entry = elm_object_item_part_content_get(entry_info->item, "elm.icon.entry");
951         if (entry) {
952                 elm_object_focus_set(entry, EINA_TRUE);
953                 elm_entry_entry_set(entry, "");
954         }
955 }
956
957 static char *_gl_eap_entry_item_text_get(void *data, Evas_Object *obj, const char *part)
958 {
959         common_utils_entry_info_t *entry_info = (common_utils_entry_info_t *)data;
960         if (!entry_info) {
961                 return NULL;
962         }
963
964         if (!g_strcmp0(part, "elm.text.sub")) {
965                 return g_strdup(dgettext(PACKAGE, entry_info->title_txt));
966         }
967
968         return NULL;
969 }
970
971 static Evas_Object *_gl_eap_entry_item_content_get(void *data, Evas_Object *obj, const char *part)
972 {
973         common_utils_entry_info_t *entry_info = (common_utils_entry_info_t *)data;
974         if (!entry_info) {
975                 return NULL;
976         }
977
978         if (g_strcmp0(part, "elm.swallow.content") == 0) {
979                 Evas_Object *entry = NULL;
980                 Evas_Object *box = NULL;
981                 Evas_Object *tpad = NULL;
982                 Evas_Object *lpad = NULL;
983                 Evas_Object *label = NULL;
984                 Evas_Object *layout = NULL;
985                 Evas_Object *editfield = NULL;
986                 char buf[MAX_LABEL_LENGTH] = {0, };
987                 char *guide_txt = NULL;
988                 char *accepted = NULL;
989                 Eina_Bool hide_entry_txt = EINA_FALSE;
990                 Elm_Input_Panel_Layout panel_type;
991                 int return_key_type;
992                 eap_type_t eap_type;
993                 int height = 60;
994
995                 eap_type = __common_eap_connect_popup_get_eap_type(entry_info->ap);
996
997                 static Elm_Entry_Filter_Limit_Size limit_filter_data;
998
999                 switch (entry_info->entry_id)
1000                 {
1001                 case ENTRY_TYPE_USER_ID:
1002                         panel_type = ELM_INPUT_PANEL_LAYOUT_NORMAL;
1003                         guide_txt = entry_info->guide_txt;
1004
1005                         if (eap_type == EAP_SEC_TYPE_TLS) {
1006                                 return_key_type = ECORE_IMF_INPUT_PANEL_RETURN_KEY_TYPE_DONE;
1007                         } else {
1008                                 return_key_type = ECORE_IMF_INPUT_PANEL_RETURN_KEY_TYPE_NEXT;
1009                         }
1010                         break;
1011                 case ENTRY_TYPE_PASSWORD:
1012                         panel_type = ELM_INPUT_PANEL_LAYOUT_PASSWORD;
1013                         guide_txt = entry_info->guide_txt;
1014                         hide_entry_txt = EINA_TRUE;
1015                         return_key_type = ECORE_IMF_INPUT_PANEL_RETURN_KEY_TYPE_DONE;
1016                         break;
1017                 default:
1018                         return NULL;
1019                 }
1020
1021                 entry = elm_box_add(obj);
1022                 elm_box_align_set(entry, 0.0, 0.0);
1023
1024                 tpad = evas_object_rectangle_add(entry);
1025                 evas_object_size_hint_min_set(tpad, 0, ELM_SCALE_SIZE(10));
1026                 evas_object_show(tpad);
1027                 elm_box_pack_end(entry, tpad);
1028
1029                 box = elm_box_add(entry);
1030                 evas_object_size_hint_align_set(box, 0.0, 0.0);
1031                 elm_box_horizontal_set(box, EINA_TRUE);
1032                 elm_box_pack_end(entry, box);
1033                 evas_object_show(box);
1034
1035                 lpad = evas_object_rectangle_add(box);
1036                 evas_object_size_hint_min_set(lpad, ELM_SCALE_SIZE(15), 0);
1037                 evas_object_show(lpad);
1038                 elm_box_pack_end(box, lpad);
1039                 evas_object_show(box);
1040
1041                 label = elm_label_add(box);
1042                 snprintf(buf, MAX_LABEL_LENGTH, "<font_size=30>%s</font_size>",
1043                                         dgettext(PACKAGE, entry_info->title_txt));
1044                 elm_object_text_set(label, buf);
1045                 evas_object_size_hint_align_set(label, EVAS_HINT_FILL, EVAS_HINT_FILL);
1046                 evas_object_size_hint_weight_set(label, 0.9, EVAS_HINT_EXPAND);
1047                 elm_box_pack_end(box, label);
1048                 evas_object_show(label);
1049
1050                 layout = elm_layout_add(entry);
1051                 elm_layout_theme_set(layout, "layout", "editfield", "singleline");
1052                 evas_object_size_hint_align_set(layout, EVAS_HINT_FILL, EVAS_HINT_FILL);
1053                 evas_object_size_hint_weight_set(layout, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
1054
1055                 editfield = elm_entry_add(layout);
1056                 elm_entry_single_line_set(editfield, EINA_TRUE);
1057                 elm_entry_scrollable_set(editfield, EINA_TRUE);
1058                 elm_entry_password_set(editfield, hide_entry_txt);
1059                 elm_entry_prediction_allow_set(editfield, EINA_FALSE);
1060                 elm_entry_autocapital_type_set(editfield, ELM_AUTOCAPITAL_TYPE_NONE);
1061
1062                 elm_object_domain_translatable_part_text_set(editfield, "elm.guide",
1063                                 PACKAGE, guide_txt);
1064                 if (entry_info->entry_txt && (strlen(entry_info->entry_txt) > 0)) {
1065                         elm_entry_entry_set(editfield, entry_info->entry_txt);
1066                 }
1067
1068                 elm_entry_input_panel_layout_set(editfield, panel_type);
1069                 elm_entry_input_panel_return_key_type_set(editfield, return_key_type);
1070
1071                 limit_filter_data.max_char_count = 200;
1072                 elm_entry_markup_filter_append(editfield, elm_entry_filter_limit_size, &limit_filter_data);
1073
1074                 Elm_Entry_Filter_Accept_Set digits_filter_data;
1075                 memset(&digits_filter_data, 0, sizeof(Elm_Entry_Filter_Accept_Set));
1076                 digits_filter_data.accepted = accepted;
1077                 elm_entry_markup_filter_append(editfield, elm_entry_filter_accept_set, &digits_filter_data);
1078
1079                 Ecore_IMF_Context *imf_ctxt = elm_entry_imf_context_get(editfield);
1080                 if (imf_ctxt && entry_info->input_panel_cb) {
1081                         ecore_imf_context_input_panel_event_callback_add(imf_ctxt,
1082                                         ECORE_IMF_INPUT_PANEL_STATE_EVENT,
1083                                         entry_info->input_panel_cb,
1084                                         entry_info->input_panel_cb_data);
1085                         DEBUG_LOG(UG_NAME_NORMAL, "set the imf ctxt cbs");
1086                 }
1087
1088                 evas_object_smart_callback_add(editfield, "activated", _gl_eap_entry_key_enter_cb, entry_info);
1089                 evas_object_smart_callback_add(editfield, "cursor,changed", _gl_eap_entry_cursor_changed_cb, entry_info);
1090                 evas_object_smart_callback_add(editfield, "changed", _gl_eap_entry_changed_cb, entry_info);
1091                 evas_object_smart_callback_add(editfield, "focused", _gl_eap_entry_focused_cb, entry_info);
1092                 evas_object_smart_callback_add(editfield, "unfocused", _gl_eap_entry_unfocused_cb, entry_info);
1093                 evas_object_smart_callback_add(editfield, "maxlength,reached", _gl_eap_entry_maxlength_reached, NULL);
1094
1095                 elm_object_part_content_set(layout, "elm.swallow.content", editfield);
1096                 evas_object_show(layout);
1097                 elm_box_pack_end(entry, layout);
1098
1099                 evas_object_size_hint_min_set(entry, 0, ELM_SCALE_SIZE(height));
1100                 elm_object_focus_set(entry, EINA_FALSE);
1101                 evas_object_show(entry);
1102
1103                 if (entry_info->entry_id == ENTRY_TYPE_PASSWORD) {
1104                         g_pwd_entry = editfield;
1105                 }
1106
1107                 return entry;
1108         } else if (g_strcmp0(part, "elm.icon.eraser") == 0) {
1109                 Evas_Object *btn = elm_button_add(obj);
1110                 elm_object_style_set(btn, "editfield_clear");
1111                 evas_object_smart_callback_add(btn, "clicked", _gl_eap_entry_eraser_clicked_cb, entry_info);
1112                 return btn;
1113         }
1114
1115         return NULL;
1116 }
1117
1118 static void _gl_eap_entry_item_del(void *data, Evas_Object *obj)
1119 {
1120         common_utils_entry_info_t *entry_info = (common_utils_entry_info_t *)data;
1121         if (entry_info == NULL) {
1122                 return;
1123         }
1124
1125         if (entry_info->entry_txt) {
1126                 g_free(entry_info->entry_txt);
1127         }
1128
1129         g_free(entry_info);
1130 }
1131
1132 static void _chk_changed_cb(void *data, Evas_Object *obj, void *ei)
1133 {
1134         if (obj == NULL || g_pwd_entry == NULL) {
1135                 return;
1136         }
1137
1138         Eina_Bool state = elm_check_state_get(obj);
1139         if (state) {
1140                 elm_entry_password_set(g_pwd_entry, EINA_FALSE);
1141         } else {
1142                 elm_entry_password_set(g_pwd_entry, EINA_TRUE);
1143         }
1144 }
1145
1146 static char *_gl_eap_chkbox_item_text_get(void *data, Evas_Object *obj,
1147                 const char *part)
1148 {
1149         char *str_pkg_name = (char *)data;
1150
1151         if (!strcmp("elm.text", part)) {
1152                 char buf[1024];
1153                 snprintf(buf, 1023, "%s", sc(str_pkg_name, I18N_TYPE_Show_password));
1154                 return strdup(buf);
1155         }
1156         return NULL;
1157
1158 }
1159
1160 static Evas_Object *_gl_eap_chkbox_item_content_get(void *data,
1161                 Evas_Object *obj, const char *part)
1162 {
1163         Evas_Object *check = NULL;
1164
1165         if (!strcmp("elm.swallow.end", part)) {
1166                 check = elm_check_add(obj);
1167                 evas_object_propagate_events_set(check, EINA_FALSE);
1168
1169                 evas_object_size_hint_align_set(check, EVAS_HINT_FILL, EVAS_HINT_FILL);
1170                 evas_object_size_hint_weight_set(check, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
1171                 evas_object_smart_callback_add(check, "changed",
1172                                 _chk_changed_cb, NULL);
1173
1174                 elm_object_focus_allow_set(check, EINA_FALSE);
1175
1176                 return check;
1177         }
1178         return NULL;
1179 }
1180
1181 static void _gl_eap_chkbox_sel(void *data, Evas_Object *obj, void *ei)
1182 {
1183         Elm_Object_Item *item = NULL;
1184
1185         item = (Elm_Object_Item *)ei;
1186         if (item == NULL) {
1187                 return;
1188         }
1189
1190         Evas_Object *ck = elm_object_item_part_content_get(ei, "elm.icon.right");
1191
1192         elm_genlist_item_selected_set(item, EINA_FALSE);
1193
1194         Eina_Bool state = elm_check_state_get(ck);
1195         elm_check_state_set(ck, !state);
1196
1197         _chk_changed_cb(NULL, ck, NULL);
1198 }
1199
1200 static void gl_lang_changed(void *data, Evas_Object *obj, void *event_info)
1201 {
1202         elm_genlist_realized_items_update(obj);
1203 }
1204
1205 static void __common_eap_connect_popup_init_item_class(void *data)
1206 {
1207         g_eap_type_itc.item_style = WIFI_GENLIST_2LINE_BOTTOM_SWALLOW_STYLE;
1208         g_eap_type_itc.func.text_get = _gl_eap_type_text_get;
1209         g_eap_type_itc.func.content_get = _gl_eap_type_content_get;
1210         g_eap_type_itc.func.state_get = NULL;
1211         g_eap_type_itc.func.del = NULL;
1212
1213         g_eap_auth_itc.item_style = WIFI_GENLIST_2LINE_BOTTOM_SWALLOW_STYLE;
1214         g_eap_auth_itc.func.text_get = _gl_eap_auth_text_get;
1215         g_eap_auth_itc.func.content_get = _gl_eap_auth_content_get;
1216         g_eap_auth_itc.func.state_get = NULL;
1217         g_eap_auth_itc.func.del = NULL;
1218
1219         g_eap_user_cert_itc.item_style = WIFI_GENLIST_2LINE_BOTTOM_SWALLOW_STYLE;
1220         g_eap_user_cert_itc.func.text_get = _gl_eap_user_cert_text_get;
1221         g_eap_user_cert_itc.func.content_get = _gl_eap_user_cert_content_get;
1222         g_eap_user_cert_itc.func.state_get = NULL;
1223         g_eap_user_cert_itc.func.del = NULL;
1224
1225         g_eap_entry_itc.item_style = WIFI_GENLIST_FULL_STYLE;
1226         g_eap_entry_itc.func.text_get = _gl_eap_entry_item_text_get;
1227         g_eap_entry_itc.func.content_get = _gl_eap_entry_item_content_get;
1228         g_eap_entry_itc.func.state_get = NULL;
1229         g_eap_entry_itc.func.del = _gl_eap_entry_item_del;
1230
1231         g_eap_chkbox_itc.item_style = WIFI_GENLIST_1LINE_TEXT_ICON_STYLE;
1232         g_eap_chkbox_itc.func.text_get = _gl_eap_chkbox_item_text_get;
1233         g_eap_chkbox_itc.func.content_get = _gl_eap_chkbox_item_content_get;
1234         g_eap_chkbox_itc.func.state_get = NULL;
1235         g_eap_chkbox_itc.func.del = NULL;
1236 }
1237
1238 static gboolean __cert_extract_files(const char *cert_alias,
1239                 eap_connect_data_t *eap_data)
1240 {
1241         int ret;
1242         int validity;
1243         size_t cert_counts = 0;
1244         int cert_index;
1245         gchar *ca_cert_path = NULL;
1246         gchar *user_cert_path = NULL;
1247         gchar *privatekey_path = NULL;
1248         FILE *fp;
1249         CertSvcInstance cert_instance;
1250         CertSvcString cert_alias_str;
1251         CertSvcCertificateList cert_list;
1252         CertSvcCertificate user_certificate;
1253         CertSvcCertificate ca_certificate;
1254         CertSvcCertificate *selected_certificate = NULL;
1255         X509 *x509 = NULL;
1256         EVP_PKEY *privatekey = NULL;
1257
1258         ret = certsvc_instance_new(&cert_instance);
1259         if (ret != CERTSVC_SUCCESS) {
1260                 ERROR_LOG(UG_NAME_NORMAL, "failed to certsvc_instance_new");
1261                 goto error;
1262         }
1263         ret = certsvc_string_new(cert_instance, cert_alias, strlen(cert_alias), &cert_alias_str);
1264         if (ret != CERTSVC_SUCCESS) {
1265                 ERROR_LOG(UG_NAME_NORMAL, "failed to certsvc_string_new");
1266                 goto error;
1267         }
1268         ret = certsvc_pkcs12_load_certificate_list_from_store(cert_instance, WIFI_STORE, cert_alias_str, &cert_list);
1269         if (ret != CERTSVC_SUCCESS) {
1270                 ERROR_LOG(UG_NAME_NORMAL, "failed to certsvc_pkcs12_load_certificate_list_from_store");
1271                 goto error;
1272         }
1273         ret = certsvc_certificate_list_get_length(cert_list, &cert_counts);
1274         if (cert_counts < 1) {
1275                 ERROR_LOG(UG_NAME_NORMAL, "there is no certificates");
1276                 goto error;
1277         }
1278         INFO_LOG(UG_NAME_NORMAL, "cert counts: %d", cert_counts);
1279         selected_certificate = g_try_new0(CertSvcCertificate, cert_counts);
1280         if (selected_certificate == NULL) {
1281                 ERROR_LOG(UG_NAME_NORMAL, "failed to allocate memory");
1282                 goto error;
1283         }
1284         ret = certsvc_certificate_list_get_one(cert_list, 0, &user_certificate);
1285         if (ret != CERTSVC_SUCCESS) {
1286                 ERROR_LOG(UG_NAME_NORMAL, "failed to certsvc_certificate_list_get_one");
1287                 goto error;
1288         }
1289         cert_index = cert_counts - 1;
1290
1291         selected_certificate[0] = user_certificate;
1292
1293         ret = certsvc_certificate_dup_x509(user_certificate, &x509);
1294
1295         user_cert_path = g_strdup_printf("%s%s_%s", EAP_TLS_PATH,
1296                                 cert_alias, EAP_TLS_USER_CERT_PATH);
1297         if ((fp = fopen(user_cert_path, "w")) == NULL) {
1298                 goto error;
1299         }
1300         ret = PEM_write_X509(fp, x509);
1301         fclose(fp);
1302         certsvc_certificate_free_x509(x509);
1303         INFO_LOG(UG_NAME_NORMAL, "success to save user_cert file");
1304
1305         ca_cert_path = g_strdup_printf("%s%s_%s", EAP_TLS_PATH, cert_alias,
1306                                 EAP_TLS_CA_CERT_PATH);
1307         while (cert_index) {
1308                 ret = certsvc_certificate_list_get_one(cert_list, cert_index, &ca_certificate);
1309                 if (ret != CERTSVC_SUCCESS) {
1310                         ERROR_LOG(UG_NAME_NORMAL, "failed to certsvc_certificate_list_get_one");
1311                         goto error;
1312                 }
1313
1314                 selected_certificate[cert_counts-cert_index] = ca_certificate;
1315                 cert_index--;
1316
1317                 ret = certsvc_certificate_dup_x509(ca_certificate, &x509);
1318                 if ((fp = fopen(ca_cert_path, "a")) == NULL) {
1319                         goto error;
1320                 }
1321                 ret = PEM_write_X509(fp, x509);
1322                 fclose(fp);
1323                 certsvc_certificate_free_x509(x509);
1324         }
1325         INFO_LOG(UG_NAME_NORMAL, "success to save ca_cert file");
1326         ret = certsvc_certificate_verify(selected_certificate[0], selected_certificate, cert_counts, NULL, 0, &validity);
1327         if (ret != CERTSVC_SUCCESS) {
1328                 ERROR_LOG(UG_NAME_NORMAL, "failed to verify ca_certificate");
1329                 goto error;
1330         }
1331         if (validity == 0) {
1332                 ERROR_LOG(UG_NAME_NORMAL, "Invalid certificate");
1333                 goto error;
1334         }
1335
1336         ret = certsvc_pkcs12_dup_evp_pkey_from_store(cert_instance, WIFI_STORE, cert_alias_str, &privatekey);
1337
1338         privatekey_path = g_strdup_printf("%s%s_%s", EAP_TLS_PATH,
1339                                 cert_alias, EAP_TLS_PRIVATEKEY_PATH);
1340
1341         if ((fp = fopen(privatekey_path, "w")) == NULL) {
1342                 goto error;
1343         }
1344         ret = PEM_write_PrivateKey(fp, privatekey, NULL, NULL, 0, NULL, NULL);
1345         fclose(fp);
1346         certsvc_pkcs12_free_evp_pkey(privatekey);
1347         INFO_LOG(UG_NAME_NORMAL, "success to save privatekey file");
1348
1349         g_free(selected_certificate);
1350         certsvc_instance_free(cert_instance);
1351
1352         eap_data->ca_cert_path = ca_cert_path;
1353         eap_data->user_cert_path = user_cert_path;
1354         eap_data->privatekey_path = privatekey_path;
1355
1356         return TRUE;
1357
1358 error:
1359         g_free(ca_cert_path);
1360         g_free(user_cert_path);
1361         g_free(privatekey_path);
1362
1363         if (selected_certificate) {
1364                 g_free(selected_certificate);
1365         }
1366
1367         certsvc_instance_free(cert_instance);
1368         return FALSE;
1369 }
1370
1371 /* This creates EAP type, Auth type, CA certificate, User certificate,
1372  * User Id, Anonymous Id and Password items.
1373  */
1374 static void _create_and_update_list_items_based_on_rules(eap_type_t new_type,
1375                 eap_connect_data_t *eap_data)
1376 {
1377         __COMMON_FUNC_ENTER__;
1378         Evas_Object* view_list = eap_data->genlist;
1379         Elm_Object_Item *insert_after_item = NULL;
1380         Elm_Object_Item *prev_item = NULL;
1381         common_utils_entry_info_t *edit_box_details;
1382         Eina_Bool auth_reqd = EINA_FALSE;
1383         Eina_Bool user_cert_reqd = EINA_FALSE;
1384         Eina_Bool id_reqd = EINA_FALSE;
1385         Eina_Bool pw_reqd = EINA_FALSE;
1386
1387         if (NULL == eap_data->eap_type_item) {
1388                 /* Create EAP method/type */
1389                 eap_data->eap_type_item = elm_genlist_item_append(
1390                                                 view_list, &g_eap_type_itc,
1391                                                 eap_data, NULL,
1392                                                 ELM_GENLIST_ITEM_NONE,
1393                                                 _gl_eap_item_sel_cb, eap_data);
1394         }
1395
1396         switch (new_type) {
1397         case EAP_SEC_TYPE_PEAP:
1398                 insert_after_item = eap_data->eap_type_item;
1399                 auth_reqd = EINA_TRUE;
1400                 user_cert_reqd = EINA_FALSE;
1401                 id_reqd = EINA_TRUE;
1402                 pw_reqd = EINA_TRUE;
1403                 break;
1404         case EAP_SEC_TYPE_TLS:
1405                 insert_after_item = eap_data->eap_type_item;
1406                 auth_reqd = EINA_FALSE;
1407                 user_cert_reqd = EINA_TRUE;
1408                 id_reqd = EINA_TRUE;
1409                 pw_reqd = EINA_FALSE;
1410                 break;
1411         case EAP_SEC_TYPE_TTLS:
1412                 insert_after_item = eap_data->eap_type_item;
1413                 auth_reqd = EINA_TRUE;
1414                 user_cert_reqd = EINA_FALSE;
1415                 id_reqd = EINA_TRUE;
1416                 pw_reqd = EINA_TRUE;
1417                 break;
1418         case EAP_SEC_TYPE_SIM:
1419         case EAP_SEC_TYPE_AKA:
1420                 _delete_eap_entry_items(eap_data);
1421                 auth_reqd = EINA_FALSE;
1422                 user_cert_reqd = EINA_FALSE;
1423                 id_reqd = EINA_FALSE;
1424                 pw_reqd = EINA_FALSE;
1425                 break;
1426         default:
1427                 break;
1428         }
1429
1430         if (auth_reqd == EINA_TRUE) {
1431                 if (eap_data->eap_auth_item == NULL) {
1432                         /* Add EAP phase2 authentication */
1433                         eap_data->eap_auth_item = elm_genlist_item_insert_after(
1434                                         view_list, &g_eap_auth_itc, eap_data, NULL,
1435                                         insert_after_item, ELM_GENLIST_ITEM_NONE,
1436                                         _gl_eap_item_sel_cb, eap_data);
1437                 }
1438         } else {
1439                 _delete_eap_auth_item(eap_data);
1440         }
1441
1442         if (user_cert_reqd == EINA_TRUE) {
1443                 if (eap_data->eap_user_cert_item == NULL) {
1444                         prev_item = eap_data->eap_type_item;
1445
1446                         /* Add User certificate */
1447                         eap_data->eap_user_cert_item = elm_genlist_item_insert_after(
1448                                         view_list, &g_eap_user_cert_itc, eap_data, NULL,
1449                                         prev_item, ELM_GENLIST_ITEM_NONE,
1450                                         _gl_eap_item_sel_cb, eap_data);
1451                 }
1452         } else {
1453                 _delete_eap_user_cert_item(eap_data);
1454         }
1455
1456         if (id_reqd == EINA_TRUE) {
1457                 if (eap_data->eap_id_item == NULL) {
1458                         if (new_type == EAP_SEC_TYPE_PEAP ||
1459                                         new_type == EAP_SEC_TYPE_TTLS) {
1460                                 prev_item = eap_data->eap_auth_item;
1461                         } else {
1462                                 prev_item = eap_data->eap_user_cert_item;
1463                         }
1464
1465                         /* Add EAP ID */
1466                         edit_box_details = g_try_new0(common_utils_entry_info_t, 1);
1467                         if (edit_box_details == NULL) {
1468                                 return;
1469                         }
1470
1471                         edit_box_details->ap = eap_data->ap;
1472                         edit_box_details->entry_id = ENTRY_TYPE_USER_ID;
1473                         edit_box_details->title_txt = "IDS_WIFI_BODY_IDENTITY";
1474                         edit_box_details->guide_txt = "IDS_WIFI_BODY_ENTER_IDENTITY";
1475                         edit_box_details->item = elm_genlist_item_insert_after(
1476                                         view_list, &g_eap_entry_itc, edit_box_details,
1477                                         NULL, prev_item,
1478                                         ELM_GENLIST_ITEM_NONE, _gl_editbox_sel_cb, NULL);
1479                         eap_data->eap_id_item = edit_box_details->item;
1480                 }
1481         } else {
1482                 _delete_eap_id_item(eap_data);
1483         }
1484
1485         if (pw_reqd == EINA_TRUE) {
1486                 if (eap_data->eap_pw_item == NULL) {
1487                         /* Add EAP Password */
1488                         edit_box_details = g_try_new0(common_utils_entry_info_t, 1);
1489                         if (edit_box_details == NULL) {
1490                                 return;
1491                         }
1492
1493                         edit_box_details->ap = eap_data->ap;
1494                         edit_box_details->entry_id = ENTRY_TYPE_PASSWORD;
1495                         edit_box_details->title_txt = "IDS_WIFI_HEADER_PASSWORD";
1496                         edit_box_details->guide_txt = "IDS_WIFI_HEADER_ENTER_PASSWORD";
1497                         edit_box_details->item = elm_genlist_item_insert_after(
1498                                         view_list, &g_eap_entry_itc,
1499                                         edit_box_details, NULL,
1500                                         eap_data->eap_id_item,
1501                                         ELM_GENLIST_ITEM_NONE,
1502                                         _gl_editbox_sel_cb, NULL);
1503                         eap_data->eap_pw_item = edit_box_details->item;
1504
1505                         _update_eap_id_item_enter_key(eap_data);
1506                 }
1507
1508                 if (eap_data->eap_chkbox_item == NULL) {
1509                         /* Add Show Password checkbox */
1510                         eap_data->eap_chkbox_item = elm_genlist_item_insert_after(
1511                                         view_list, &g_eap_chkbox_itc,
1512                                         eap_data->str_pkg_name, NULL,
1513                                         eap_data->eap_pw_item,
1514                                         ELM_GENLIST_ITEM_NONE,
1515                                         _gl_eap_chkbox_sel, NULL);
1516                 }
1517         } else {
1518                 _delete_eap_pw_items(eap_data);
1519         }
1520
1521         __COMMON_FUNC_EXIT__;
1522         return;
1523 }
1524
1525 static void _update_eap_id_item_enter_key(eap_connect_data_t *eap_data)
1526 {
1527         if (eap_data->eap_id_item == NULL)
1528                 return;
1529
1530         Evas_Object *entry = NULL;
1531         eap_type_t eap_type;
1532
1533         eap_type = __common_eap_connect_popup_get_eap_type(eap_data->ap);
1534         entry = elm_object_item_part_content_get(eap_data->eap_id_item,
1535                         "elm.icon.entry");
1536         if (entry) {
1537                 if (eap_type == EAP_SEC_TYPE_TLS) {
1538                         elm_entry_input_panel_return_key_type_set(entry,
1539                                         ECORE_IMF_INPUT_PANEL_RETURN_KEY_TYPE_DONE);
1540                 } else {
1541                         elm_entry_input_panel_return_key_type_set(entry,
1542                                         ECORE_IMF_INPUT_PANEL_RETURN_KEY_TYPE_NEXT);
1543                 }
1544         }
1545 }
1546
1547 static void _delete_eap_auth_item(eap_connect_data_t *eap_data)
1548 {
1549         __COMMON_FUNC_ENTER__;
1550
1551         if (eap_data->eap_auth_item != NULL) {
1552                 elm_object_item_del(eap_data->eap_auth_item);
1553                 eap_data->eap_auth_item = NULL;
1554         }
1555
1556         __COMMON_FUNC_EXIT__;
1557         return;
1558 }
1559
1560 static void _delete_eap_user_cert_item(eap_connect_data_t *eap_data)
1561 {
1562         __COMMON_FUNC_ENTER__;
1563
1564         if (eap_data->eap_user_cert_item != NULL) {
1565                 elm_object_item_del(eap_data->eap_user_cert_item);
1566                 eap_data->eap_user_cert_item = NULL;
1567         }
1568
1569         __COMMON_FUNC_EXIT__;
1570         return;
1571 }
1572
1573 static void _delete_eap_id_item(eap_connect_data_t *eap_data)
1574 {
1575         __COMMON_FUNC_ENTER__;
1576
1577         if (eap_data->eap_id_item != NULL) {
1578                 elm_object_item_del(eap_data->eap_id_item);
1579                 eap_data->eap_id_item = NULL;
1580         }
1581
1582         __COMMON_FUNC_EXIT__;
1583         return;
1584 }
1585
1586 static void _delete_eap_pw_items(eap_connect_data_t *eap_data)
1587 {
1588         __COMMON_FUNC_ENTER__;
1589
1590         _update_eap_id_item_enter_key(eap_data);
1591
1592         if (eap_data->eap_pw_item != NULL) {
1593                 elm_object_item_del(eap_data->eap_pw_item);
1594                 eap_data->eap_pw_item = NULL;
1595         }
1596
1597         if (eap_data->eap_chkbox_item) {
1598                 elm_object_item_del(eap_data->eap_chkbox_item);
1599                 eap_data->eap_chkbox_item = NULL;
1600         }
1601
1602         __COMMON_FUNC_EXIT__;
1603         return;
1604 }
1605
1606 void _delete_eap_entry_items(eap_connect_data_t *eap_data)
1607 {
1608         __COMMON_FUNC_ENTER__;
1609
1610         if (eap_data->eap_auth_item != NULL) {
1611                 elm_object_item_del(eap_data->eap_auth_item);
1612                 eap_data->eap_auth_item = NULL;
1613         }
1614
1615         if (eap_data->eap_user_cert_item != NULL) {
1616                 elm_object_item_del(eap_data->eap_user_cert_item);
1617                 eap_data->eap_user_cert_item = NULL;
1618         }
1619
1620         if (eap_data->eap_id_item != NULL) {
1621                 elm_object_item_del(eap_data->eap_id_item);
1622                 eap_data->eap_id_item = NULL;
1623         }
1624
1625         if (eap_data->eap_pw_item != NULL) {
1626                 elm_object_item_del(eap_data->eap_pw_item);
1627                 eap_data->eap_pw_item = NULL;
1628         }
1629
1630         if (eap_data->eap_chkbox_item != NULL) {
1631                 elm_object_item_del(eap_data->eap_chkbox_item);
1632                 eap_data->eap_chkbox_item = NULL;
1633         }
1634
1635         __COMMON_FUNC_EXIT__;
1636         return;
1637 }
1638
1639 static Evas_Object* _create_list(Evas_Object* parent, void *data)
1640 {
1641         __COMMON_FUNC_ENTER__;
1642         assertm_if(NULL == parent, "NULL!!");
1643
1644         eap_connect_data_t *eap_data = (eap_connect_data_t *)data;
1645         Evas_Object* view_list = NULL;
1646         eap_type_t eap_type = EAP_SEC_TYPE_UNKNOWN;
1647         retvm_if(eap_data == NULL, NULL);
1648
1649         __common_eap_connect_popup_init_item_class(eap_data);
1650
1651         eap_data->eap_done_ok = FALSE;
1652         eap_data->genlist = view_list = elm_genlist_add(parent);
1653         //elm_genlist_realization_mode_set(view_list, EINA_TRUE);
1654         elm_genlist_mode_set(view_list, ELM_LIST_COMPRESS);
1655         elm_scroller_content_min_limit(view_list, EINA_FALSE, EINA_TRUE);
1656
1657         evas_object_size_hint_weight_set(view_list, EVAS_HINT_EXPAND,
1658                         EVAS_HINT_EXPAND);
1659         evas_object_size_hint_align_set(view_list, EVAS_HINT_FILL, EVAS_HINT_FILL);
1660
1661         /* Set default values. eap type = PEAP, auth type = MSCHAPv2 */
1662         eap_type = __common_eap_connect_popup_get_eap_type(eap_data->ap);
1663         wifi_ap_set_eap_type(eap_data->ap,
1664                         (eap_type == EAP_SEC_TYPE_UNKNOWN) ?
1665                         WIFI_EAP_TYPE_PEAP :
1666                         __common_eap_connect_popup_get_wlan_eap_type(eap_type));
1667
1668         wifi_ap_set_eap_auth_type(eap_data->ap,
1669                                         WIFI_EAP_AUTH_TYPE_MSCHAPV2);
1670
1671         selected_cert = 0;
1672
1673         /* Create the entry items */
1674         _create_and_update_list_items_based_on_rules(eap_type, eap_data);
1675
1676         evas_object_smart_callback_add(view_list, "language,changed",
1677                         gl_lang_changed, NULL);
1678
1679         __COMMON_FUNC_EXIT__;
1680         return view_list;
1681 }
1682
1683 static Eina_Bool _enable_scan_updates_cb(void *data)
1684 {
1685         /* Lets enable the scan updates */
1686         wlan_manager_enable_scan_result_update();
1687
1688         /* Reset the ecore timer handle */
1689         common_util_manager_ecore_scan_update_timer_reset();
1690
1691         return ECORE_CALLBACK_CANCEL;
1692 }
1693
1694 static void __common_eap_connect_cleanup(eap_connect_data_t *eap_data)
1695 {
1696         if (eap_data == NULL) {
1697                 return;
1698         }
1699
1700         if (eap_data->conf != NULL) {
1701                 evas_object_smart_callback_del(eap_data->conf,
1702                                 "virtualkeypad,state,on",
1703                                 _eap_popup_keypad_on_cb);
1704                 evas_object_smart_callback_del(eap_data->conf,
1705                                 "virtualkeypad,state,off",
1706                                 _eap_popup_keypad_off_cb);
1707         }
1708
1709         if (eap_data->ssid != NULL) {
1710                 g_free(eap_data->ssid);
1711                 eap_data->ssid = NULL;
1712         }
1713
1714         if (eap_data->cert_alias) {
1715                 g_free(eap_data->cert_alias);
1716                 eap_data->cert_alias = NULL;
1717         }
1718
1719         if (eap_data->ca_cert_path) {
1720                 g_free(eap_data->ca_cert_path);
1721                 eap_data->ca_cert_path = NULL;
1722         }
1723
1724         if (eap_data->user_cert_path) {
1725                 g_free(eap_data->user_cert_path);
1726                 eap_data->user_cert_path = NULL;
1727         }
1728
1729         if (eap_data->privatekey_path) {
1730                 g_free(eap_data->privatekey_path);
1731                 eap_data->privatekey_path = NULL;
1732         }
1733
1734         wifi_ap_destroy(eap_data->ap);
1735         eap_data->ap = NULL;
1736
1737         if(eap_data->info_popup){
1738                 evas_object_del(eap_data->info_popup);
1739                 eap_data->info_popup = NULL;
1740         }
1741
1742         if (eap_data->popup != NULL) {
1743                 evas_object_hide(eap_data->popup);
1744                 evas_object_del(eap_data->popup);
1745         }
1746
1747         if(_eap_view_deref_cb != NULL) {
1748                 _eap_view_deref_cb();
1749                 _eap_view_deref_cb = NULL;
1750         }
1751
1752         /* A delay is needed to get the smooth Input panel closing animation effect */
1753         common_util_managed_ecore_scan_update_timer_add(0.1,
1754                         _enable_scan_updates_cb, NULL);
1755 }
1756
1757 static void __common_eap_connect_destroy_cb(void *data,  Evas_Object *obj,
1758                 void *event_info)
1759 {
1760         __common_eap_connect_cleanup((eap_connect_data_t *)data);
1761 }
1762
1763 static void _info_popup_ok_cb(void *data, Evas_Object *obj, void *event_info)
1764 {
1765         eap_connect_data_t *eap_data = (eap_connect_data_t *)data;
1766
1767         if (eap_data->info_popup != NULL) {
1768                 evas_object_del(eap_data->info_popup);
1769                 eap_data->info_popup = NULL;
1770         }
1771 }
1772
1773 static void __common_eap_connect_done_cb(void *data, Evas_Object *obj,
1774                 void *event_info)
1775 {
1776         char *str_id = NULL;
1777         char *str_pw = NULL;
1778         bool favorite = FALSE;
1779         wifi_eap_type_e eap_type;
1780         wifi_eap_auth_type_e eap_auth_type;
1781         eap_connect_data_t *eap_data = (eap_connect_data_t *)data;
1782         popup_btn_info_t popup_data;
1783
1784         __COMMON_FUNC_ENTER__;
1785         if (eap_data->eap_done_ok == TRUE) {
1786                 __COMMON_FUNC_EXIT__;
1787                 return;
1788         }
1789
1790         eap_data->eap_done_ok = TRUE;
1791
1792         wifi_ap_get_eap_type(eap_data->ap, &eap_type);
1793         wifi_ap_get_eap_auth_type(eap_data->ap, &eap_auth_type);
1794
1795         wifi_ap_is_favorite(eap_data->ap, &favorite);
1796         if (favorite == TRUE) {
1797                 wlan_manager_forget(eap_data->ap);
1798                 wifi_ap_refresh(eap_data->ap);
1799
1800                 wifi_ap_set_eap_type(eap_data->ap, eap_type);
1801                 wifi_ap_set_eap_auth_type(eap_data->ap, eap_auth_type);
1802         }
1803
1804         wifi_ap_set_eap_ca_cert_file(eap_data->ap, "");
1805         wifi_ap_set_eap_client_cert_file(eap_data->ap, "");
1806         wifi_ap_set_eap_private_key_info(eap_data->ap, "", "");
1807
1808         switch (eap_type) {
1809         case WIFI_EAP_TYPE_PEAP:
1810         case WIFI_EAP_TYPE_TTLS:
1811
1812                 str_id = common_utils_get_list_item_entry_txt(eap_data->eap_id_item);
1813                 if (str_id == NULL || str_id[0] == '\0') {
1814                         memset(&popup_data, 0, sizeof(popup_data));
1815                         popup_data.title_txt = eap_data->ssid;
1816                         popup_data.btn1_txt = "IDS_WIFI_SK2_OK";
1817                         popup_data.btn1_cb = _info_popup_ok_cb;
1818                         popup_data.btn1_data = eap_data;
1819                         popup_data.info_txt = "IDS_WIFI_BODY_ENTER_IDENTITY";
1820                         eap_data->eap_done_ok = FALSE;
1821                         eap_data->info_popup = common_utils_show_info_popup(eap_data->win,
1822                                                 &popup_data);
1823
1824                         g_free(str_id);
1825
1826                         return;
1827                 }
1828
1829                 str_pw = common_utils_get_list_item_entry_txt(eap_data->eap_pw_item);
1830                 if (str_pw == NULL || str_pw[0] == '\0') {
1831                         memset(&popup_data, 0, sizeof(popup_data));
1832                         popup_data.title_txt = eap_data->ssid;
1833                         popup_data.btn1_txt = "IDS_WIFI_SK2_OK";
1834                         popup_data.btn1_cb = _info_popup_ok_cb;
1835                         popup_data.btn1_data = eap_data;
1836                         popup_data.info_txt = "IDS_WIFI_HEADER_ENTER_PASSWORD";
1837                         eap_data->eap_done_ok = FALSE;
1838                         eap_data->info_popup = common_utils_show_info_popup(eap_data->win,
1839                                                 &popup_data);
1840
1841                         g_free(str_id);
1842                         g_free(str_pw);
1843
1844                         return;
1845                 }
1846
1847                 wifi_ap_set_eap_type(eap_data->ap, eap_type);
1848                 wifi_ap_set_eap_auth_type(eap_data->ap, eap_auth_type);
1849                 wifi_ap_set_eap_passphrase(eap_data->ap, str_id, str_pw);
1850                 break;
1851
1852         case WIFI_EAP_TYPE_TLS:
1853                 str_id = common_utils_get_list_item_entry_txt(eap_data->eap_id_item);
1854                 str_pw = common_utils_get_list_item_entry_txt(eap_data->eap_pw_item);
1855
1856                 wifi_ap_set_eap_type(eap_data->ap, eap_type);
1857                 wifi_ap_set_eap_auth_type(eap_data->ap, eap_auth_type);
1858                 wifi_ap_set_eap_passphrase(eap_data->ap, str_id, str_pw);
1859                 wifi_ap_set_eap_ca_cert_file(eap_data->ap, eap_data->ca_cert_path);
1860                 wifi_ap_set_eap_client_cert_file(eap_data->ap, eap_data->user_cert_path);
1861                 wifi_ap_set_eap_private_key_info(eap_data->ap,
1862                                 eap_data->privatekey_path, NULL);
1863                 break;
1864
1865         case WIFI_EAP_TYPE_SIM:
1866         case WIFI_EAP_TYPE_AKA:
1867                 break;
1868
1869         default:
1870                 ERROR_LOG(UG_NAME_NORMAL, "Unknown EAP method %d", eap_type);
1871                 break;
1872         }
1873
1874         if (eap_data->is_hidden) {
1875                 wifi_ap_h hidden_ap;
1876                 char *ssid;
1877                 wifi_ap_get_essid(eap_data->ap, &ssid);
1878                 wifi_ap_hidden_create(ssid, &hidden_ap);
1879                 g_free(ssid);
1880
1881                 switch (eap_type) {
1882                         case WIFI_EAP_TYPE_PEAP:
1883                         case WIFI_EAP_TYPE_TTLS:
1884                                 wifi_ap_set_eap_type(hidden_ap, eap_type);
1885                                 wifi_ap_set_eap_auth_type(hidden_ap, eap_auth_type);
1886                                 wifi_ap_set_eap_passphrase(hidden_ap, str_id, str_pw);
1887                                 break;
1888                         case WIFI_EAP_TYPE_TLS:
1889                         wifi_ap_set_eap_type(hidden_ap, eap_type);
1890                         wifi_ap_set_eap_auth_type(hidden_ap, eap_auth_type);
1891                         wifi_ap_set_eap_passphrase(hidden_ap, str_id, str_pw);
1892                         wifi_ap_set_eap_ca_cert_file(hidden_ap, eap_data->ca_cert_path);
1893                         wifi_ap_set_eap_client_cert_file(hidden_ap,eap_data->user_cert_path);
1894                         wifi_ap_set_eap_private_key_info(hidden_ap, eap_data->privatekey_path, NULL);
1895                                 break;
1896                         case WIFI_EAP_TYPE_SIM:
1897                         case WIFI_EAP_TYPE_AKA:
1898                                 break;
1899                 }
1900                 wlan_manager_connect(hidden_ap);
1901         } else
1902                 wlan_manager_connect(eap_data->ap);
1903
1904         __common_eap_connect_cleanup(eap_data);
1905
1906         __COMMON_FUNC_EXIT__;
1907 }
1908
1909 static gboolean delay_create_context_popup(gpointer data)
1910 {
1911         eap_connect_data_t *eap_data = (eap_connect_data_t *)data;
1912
1913         if (click.btn_click[EAP_CERT_BTN] == TRUE) {
1914                 _create_eap_cert_list(eap_data, click.btn_obj[EAP_CERT_BTN]);
1915
1916                 click.btn_click[EAP_CERT_BTN] = FALSE;
1917                 click.btn_obj[EAP_CERT_BTN] = NULL;
1918         } else if (click.btn_click[EAP_AUTH_BTN] == TRUE) {
1919                 _create_eap_auth_list(eap_data, click.btn_obj[EAP_AUTH_BTN]);
1920
1921                 click.btn_click[EAP_AUTH_BTN] = FALSE;
1922                 click.btn_obj[EAP_AUTH_BTN] = NULL;
1923         } else if (click.btn_click[EAP_TYPE_BTN] == TRUE) {
1924                 _create_eap_type_list(eap_data, click.btn_obj[EAP_TYPE_BTN]);
1925
1926                 click.btn_click[EAP_TYPE_BTN] = FALSE;
1927                 click.btn_obj[EAP_TYPE_BTN] = NULL;
1928         }
1929         return FALSE;
1930 }
1931
1932 static void _eap_popup_keypad_off_cb(void *data, Evas_Object *obj,
1933                 void *event_info)
1934 {
1935         if (data == NULL) {
1936                 return;
1937         }
1938
1939         eap_connect_data_t *eap_data = (eap_connect_data_t *)data;
1940
1941         keypad_state = FALSE;
1942
1943         common_util_managed_idle_add(delay_create_context_popup,
1944                         (gpointer)eap_data);
1945
1946         INFO_LOG(UG_NAME_NORMAL,"Keypad is down");
1947 }
1948
1949 static void _eap_popup_keypad_on_cb(void *data, Evas_Object *obj,
1950                 void *event_info)
1951 {
1952         if (data == NULL) {
1953                 return;
1954         }
1955
1956         keypad_state = TRUE;
1957         INFO_LOG(UG_NAME_NORMAL,"Keypad is up");
1958 }
1959
1960 eap_connect_data_t *create_eap_view(Evas_Object *layout_main, Evas_Object *win,
1961                 Evas_Object *conf, const char *pkg_name,
1962                 wifi_device_info_t *device_info, void (*deref_func)(void))
1963 {
1964         __COMMON_FUNC_ENTER__;
1965
1966         Evas_Object *popup = NULL;
1967         Evas_Object *list = NULL;
1968
1969         if (layout_main == NULL || device_info == NULL || pkg_name == NULL) {
1970                 return NULL;
1971         }
1972
1973         eap_connect_data_t *eap_data = g_try_new0(eap_connect_data_t, 1);
1974         if (eap_data == NULL) {
1975                 return NULL;
1976         }
1977
1978         eap_data->str_pkg_name = pkg_name;
1979         eap_data->win = win;
1980         eap_data->conf = conf;
1981         eap_data->ssid = g_strdup(device_info->ssid);
1982
1983         if (device_info->is_hidden == true) {
1984                 /* Hidden Wi-Fi network */
1985                 char *ssid = NULL;
1986
1987                 wifi_ap_get_essid(device_info->ap, &ssid);
1988                 if (ssid == NULL) {
1989                         if(eap_data->ssid)
1990                                 g_free(eap_data->ssid);
1991                         return NULL;
1992                 }
1993
1994                 wifi_ap_hidden_create(ssid, &(eap_data->ap));
1995                 g_free(ssid);
1996
1997                 eap_data->is_hidden = TRUE;
1998         } else {
1999                 /* Clone the Wi-Fi AP handle */
2000                 wifi_ap_clone(&(eap_data->ap), device_info->ap);
2001         }
2002
2003         /* Lets disable the scan updates so that the UI is not refreshed unnecessarily */
2004         wlan_manager_disable_scan_result_update();
2005
2006         _eap_view_deref_cb = deref_func;
2007         click.btn_click[EAP_TYPE_BTN] = FALSE;
2008         click.btn_obj[EAP_TYPE_BTN] = NULL;
2009         click.btn_click[EAP_AUTH_BTN] = FALSE;
2010         click.btn_obj[EAP_AUTH_BTN] = NULL;
2011         click.btn_click[EAP_CERT_BTN] = FALSE;
2012         click.btn_obj[EAP_CERT_BTN] = NULL;
2013         keypad_state = FALSE;
2014
2015         popup_btn_info_t popup_btn_data;
2016         memset(&popup_btn_data, 0, sizeof(popup_btn_data));
2017
2018         popup_btn_data.title_txt = device_info->ssid;
2019         popup_btn_data.btn1_cb = __common_eap_connect_destroy_cb;
2020         popup_btn_data.btn1_data = eap_data;
2021         popup_btn_data.btn1_txt = "IDS_WIFI_SK_CANCEL";
2022         popup_btn_data.btn2_cb = __common_eap_connect_done_cb;
2023         popup_btn_data.btn2_data = eap_data;
2024         popup_btn_data.btn2_txt = "IDS_WIFI_BODY_CONNECT";
2025
2026         popup = common_utils_show_info_popup(layout_main,
2027                         &popup_btn_data);
2028         eap_data->popup = popup;
2029         evas_object_show(popup);
2030         elm_object_focus_set(popup, EINA_TRUE);
2031
2032         /* Create an EAP connect view list */
2033         list = _create_list(popup, eap_data);
2034         elm_object_content_set(popup, list);
2035
2036         evas_object_smart_callback_add(eap_data->conf,
2037                         "virtualkeypad,state,on", _eap_popup_keypad_on_cb,
2038                         eap_data);
2039         evas_object_smart_callback_add(eap_data->conf,
2040                         "virtualkeypad,state,off", _eap_popup_keypad_off_cb,
2041                         eap_data);
2042
2043         __COMMON_FUNC_EXIT__;
2044         return eap_data;
2045 }
2046
2047 static wifi_eap_type_e __common_eap_connect_popup_get_wlan_eap_type(eap_type_t eap_type)
2048 {
2049         wifi_eap_type_e wlan_eap_type = WLAN_SEC_EAP_TYPE_PEAP;
2050         switch (eap_type) {
2051         case EAP_SEC_TYPE_PEAP:
2052                 wlan_eap_type = WIFI_EAP_TYPE_PEAP;
2053                 break;
2054         case EAP_SEC_TYPE_TLS:
2055                 wlan_eap_type = WIFI_EAP_TYPE_TLS;
2056                 break;
2057         case EAP_SEC_TYPE_TTLS:
2058                 wlan_eap_type = WIFI_EAP_TYPE_TTLS;
2059                 break;
2060         case EAP_SEC_TYPE_SIM:
2061                 wlan_eap_type = WIFI_EAP_TYPE_SIM;
2062                 break;
2063         case EAP_SEC_TYPE_AKA:
2064                 wlan_eap_type = WIFI_EAP_TYPE_AKA;
2065                 break;
2066         default:
2067                 ERROR_LOG(UG_NAME_NORMAL, "Err! This case should never occur");
2068                 break;
2069         }
2070
2071         return wlan_eap_type;
2072 }
2073
2074 static wifi_eap_auth_type_e __common_eap_connect_popup_get_wlan_auth_type(eap_auth_t auth_type)
2075 {
2076         wifi_eap_auth_type_e wlan_auth_type = WIFI_EAP_AUTH_TYPE_NONE;
2077         switch (auth_type) {
2078         case EAP_SEC_AUTH_NONE:
2079                 wlan_auth_type = WIFI_EAP_AUTH_TYPE_NONE;
2080                 break;
2081         case EAP_SEC_AUTH_PAP:
2082                 wlan_auth_type = WIFI_EAP_AUTH_TYPE_PAP;
2083                 break;
2084         case EAP_SEC_AUTH_MSCHAP:
2085                 wlan_auth_type = WIFI_EAP_AUTH_TYPE_MSCHAP;
2086                 break;
2087         case EAP_SEC_AUTH_MSCHAPV2:
2088                 wlan_auth_type = WIFI_EAP_AUTH_TYPE_MSCHAPV2;
2089                 break;
2090         case EAP_SEC_AUTH_GTC:
2091                 wlan_auth_type = WIFI_EAP_AUTH_TYPE_GTC;
2092                 break;
2093         case EAP_SEC_AUTH_MD5:
2094                 wlan_auth_type = WIFI_EAP_AUTH_TYPE_MD5;
2095                 break;
2096         default:
2097                 /* This case should never occur */
2098                 ERROR_LOG(UG_NAME_NORMAL, "Err!");
2099                 break;
2100         }
2101         return wlan_auth_type;
2102 }
2103
2104 static eap_type_t __common_eap_connect_popup_get_eap_type(wifi_ap_h ap)
2105 {
2106         wifi_eap_type_e wlan_eap_type = 0;
2107         int ret = wifi_ap_get_eap_type(ap, &wlan_eap_type);
2108         if (WIFI_ERROR_OPERATION_FAILED == ret) {
2109                 ret = wifi_ap_set_eap_type(ap, WIFI_EAP_TYPE_PEAP);
2110         }
2111
2112         if (WIFI_ERROR_NONE != ret) {
2113                 ERROR_LOG(UG_NAME_ERR, "Unable to get the eap type. err = %d", ret);
2114                 return EAP_SEC_TYPE_UNKNOWN;
2115         }
2116
2117         switch (wlan_eap_type) {
2118         case WIFI_EAP_TYPE_PEAP:  /**< EAP PEAP type */
2119                 return EAP_SEC_TYPE_PEAP;
2120
2121         case WIFI_EAP_TYPE_TLS:  /**< EAP TLS type */
2122                 return EAP_SEC_TYPE_TLS;
2123
2124         case WIFI_EAP_TYPE_TTLS:  /**< EAP TTLS type */
2125                 return EAP_SEC_TYPE_TTLS;
2126
2127         case WIFI_EAP_TYPE_SIM:  /**< EAP SIM type */
2128                 return EAP_SEC_TYPE_SIM;
2129
2130         case WIFI_EAP_TYPE_AKA:  /**< EAP AKA type */
2131                 return EAP_SEC_TYPE_AKA;
2132
2133         default:
2134                 return EAP_SEC_TYPE_PEAP;
2135         }
2136         return EAP_SEC_TYPE_PEAP;
2137 }
2138
2139 static eap_auth_t __common_eap_connect_popup_get_auth_type(wifi_ap_h ap)
2140 {
2141         wifi_eap_auth_type_e wlan_auth_type = 0;
2142         int ret = wifi_ap_get_eap_auth_type(ap, &wlan_auth_type);
2143         if (WIFI_ERROR_OPERATION_FAILED == ret) {
2144                 ret = wifi_ap_set_eap_auth_type(ap, EAP_SEC_AUTH_NONE);
2145         }
2146
2147         if (WIFI_ERROR_NONE != ret) {
2148                 ERROR_LOG(UG_NAME_ERR, "Unable to get the eap auth type. err = %d", ret);
2149                 return EAP_SEC_AUTH_NONE;
2150         }
2151
2152         switch (wlan_auth_type) {
2153         case WIFI_EAP_AUTH_TYPE_NONE:  /**< EAP phase2 authentication none */
2154                 return EAP_SEC_AUTH_NONE;
2155
2156         case WIFI_EAP_AUTH_TYPE_PAP:  /**< EAP phase2 authentication PAP */
2157                 return EAP_SEC_AUTH_PAP;
2158
2159         case WIFI_EAP_AUTH_TYPE_MSCHAP:  /**< EAP phase2 authentication MSCHAP */
2160                 return EAP_SEC_AUTH_MSCHAP;
2161
2162         case WIFI_EAP_AUTH_TYPE_MSCHAPV2:  /**< EAP phase2 authentication MSCHAPv2 */
2163                 return EAP_SEC_AUTH_MSCHAPV2;
2164
2165         case WIFI_EAP_AUTH_TYPE_GTC:  /**< EAP phase2 authentication GTC */
2166                 return EAP_SEC_AUTH_GTC;
2167
2168         case WIFI_EAP_AUTH_TYPE_MD5:  /**< EAP phase2 authentication MD5 */
2169                 return EAP_SEC_AUTH_MD5;
2170
2171         default:
2172                 return EAP_SEC_AUTH_NONE;
2173         }
2174         return EAP_SEC_AUTH_NONE;
2175 }
2176
2177 static char *_eap_info_get_user_cert_alias(wifi_ap_h ap)
2178 {
2179         char *path = NULL;
2180         char *alias = NULL;
2181         char *filename = NULL;
2182         char *cert_name = NULL;
2183         int alias_len = 0;
2184         int filename_len = 0;
2185
2186         wifi_ap_get_eap_client_cert_file(ap, &path);
2187         if (path == NULL)
2188                 return NULL;
2189
2190         filename = strrchr(path, '/');
2191         if (filename == NULL) {
2192                 ERROR_LOG(UG_NAME_ERR, "Invalid file name");
2193                 goto EXIT;
2194         }
2195
2196         filename++;
2197         cert_name = strstr(filename, EAP_TLS_USER_CERT_PATH);
2198         if (cert_name == NULL) {
2199                 /* For truncated path, available filename will be followed
2200                  * with ellipsis(...) & excluding any remaining part of
2201                  * "_user_cert.pem" - 14 chars (-14+3+1=10)*/
2202                 filename_len = strlen(filename);
2203                 alias = g_try_malloc0(filename_len - 10);
2204                 if (alias == NULL) {
2205                         ERROR_LOG(UG_NAME_ERR, "malloc fail");
2206                         goto EXIT;
2207                 }
2208                 g_strlcpy(alias, filename, filename_len - 13);
2209                 g_strlcat(alias, "...", filename_len - 10);
2210                 INFO_LOG(UG_NAME_NORMAL, "Truncated alias [%s]", alias);
2211                 goto EXIT;
2212         }
2213
2214         cert_name--;
2215         alias_len = cert_name - filename;
2216
2217         alias = g_try_malloc0(alias_len + 1);
2218         if (alias == NULL) {
2219                 ERROR_LOG(UG_NAME_ERR, "malloc fail");
2220                 goto EXIT;
2221         }
2222
2223         g_strlcpy(alias, filename, alias_len + 1);
2224         INFO_LOG(UG_NAME_NORMAL, "Alias [%s] length [%d]", alias, alias_len);
2225
2226 EXIT:
2227         g_free(path);
2228
2229         return alias;
2230 }
2231
2232 /* This creates Auth type, ID, Anonymous Id and Password items
2233  * This function should be called after creating the EAP type item
2234  */
2235 eap_info_list_t *eap_info_append_items(wifi_ap_h ap, Evas_Object* view_list,
2236                 const char *str_pkg_name, imf_ctxt_panel_cb_t input_panel_cb,
2237                 void *input_panel_cb_data)
2238 {
2239         __COMMON_FUNC_ENTER__;
2240
2241         eap_type_t eap_type;
2242         eap_auth_t auth_type;
2243         char *temp_str = NULL;
2244         Eina_Bool append_continue = TRUE;
2245         eap_info_list_t *eap_info_list_data = NULL;
2246         Elm_Object_Item* item = NULL;
2247         if (!view_list || !str_pkg_name || !ap) {
2248                 ERROR_LOG(UG_NAME_ERR, "Invalid params passed!");
2249                 return NULL;
2250         }
2251
2252         eap_info_list_data = g_try_new0(eap_info_list_t, 1);
2253         if (eap_info_list_data == NULL) {
2254                 return NULL;
2255         }
2256
2257         eap_info_list_data->ap = ap;
2258         eap_type = __common_eap_connect_popup_get_eap_type(ap);
2259         auth_type = __common_eap_connect_popup_get_auth_type(ap);
2260
2261         item = common_utils_add_2_line_txt_disabled_item(view_list,
2262                         WIFI_GENLIST_2LINE_TOP_TEXT_STYLE,
2263                         sc(str_pkg_name, I18N_TYPE_EAP_method),
2264                         list_eap_type[eap_type].name);
2265         eap_info_list_data->eap_method_item = item;
2266
2267         eap_info_list_data->eap_type = eap_type;
2268
2269         switch (eap_type) {
2270         case EAP_SEC_TYPE_UNKNOWN:
2271         case EAP_SEC_TYPE_PEAP:
2272         case EAP_SEC_TYPE_TLS:
2273         case EAP_SEC_TYPE_TTLS:
2274                 break;
2275         case EAP_SEC_TYPE_SIM:
2276         case EAP_SEC_TYPE_AKA:
2277         default:
2278                 append_continue = FALSE;
2279                 break;
2280         }
2281
2282         if (append_continue) {
2283                 if (eap_type == EAP_SEC_TYPE_PEAP ||
2284                                 eap_type == EAP_SEC_TYPE_TTLS) {
2285                         /* Add EAP phase2 authentication */
2286                         item = common_utils_add_2_line_txt_disabled_item(view_list,
2287                                         WIFI_GENLIST_2LINE_TOP_TEXT_STYLE,
2288                                         sc(str_pkg_name, I18N_TYPE_Phase_2_authentication),
2289                                         list_eap_auth[auth_type].name);
2290                         eap_info_list_data->eap_auth_item = item;
2291                 }
2292
2293                 if (eap_type == EAP_SEC_TYPE_TLS) {
2294                         /* Add User certificate */
2295                         temp_str = _eap_info_get_user_cert_alias(ap);
2296
2297                         if (temp_str == NULL || strlen(temp_str) == 0) {
2298                                 if (temp_str != NULL) {
2299                                         g_free(temp_str);
2300                                 }
2301                                 temp_str = g_strdup(sc(str_pkg_name,
2302                                                 I18N_TYPE_Unspecified));
2303                         }
2304
2305                         item = common_utils_add_2_line_txt_disabled_item(view_list,
2306                                         WIFI_GENLIST_2LINE_TOP_TEXT_STYLE,
2307                                         sc(str_pkg_name, I18N_TYPE_User_Certificate),
2308                                         temp_str);
2309                         eap_info_list_data->user_cert_item = item;
2310                         g_free(temp_str);
2311                 }
2312
2313                 /* Add EAP ID */
2314                 bool is_paswd_set;
2315                 temp_str = NULL;
2316                 wifi_ap_get_eap_passphrase(ap, &temp_str, &is_paswd_set);
2317                 item = common_utils_add_2_line_txt_disabled_item(view_list,
2318                                 WIFI_GENLIST_2LINE_TOP_TEXT_STYLE,
2319                                 sc(str_pkg_name, I18N_TYPE_Identity),
2320                                 temp_str);
2321                 eap_info_list_data->id_item = item;
2322                 g_free(temp_str);
2323
2324 #if 0
2325                 common_utils_entry_info_t *edit_box_details;
2326
2327                 /* Add EAP Password */
2328                 g_eap_entry_itc.item_style = "entry.main";
2329                 g_eap_entry_itc.func.text_get = _gl_eap_entry_item_text_get;
2330                 g_eap_entry_itc.func.content_get = _gl_eap_entry_item_content_get;
2331                 g_eap_entry_itc.func.state_get = NULL;
2332                 g_eap_entry_itc.func.del = _gl_eap_entry_item_del;
2333
2334                 edit_box_details = g_try_new0(common_utils_entry_info_t, 1);
2335                 if (edit_box_details == NULL) {
2336                         g_free(eap_info_list_data);
2337                         return NULL;
2338                 }
2339
2340                 edit_box_details->entry_id = ENTRY_TYPE_PASSWORD;
2341                 edit_box_details->title_txt = sc(str_pkg_name, I18N_TYPE_Password);
2342                 edit_box_details->entry_txt = NULL;
2343                 edit_box_details->guide_txt = sc(str_pkg_name, I18N_TYPE_Enter_password);
2344                 edit_box_details->input_panel_cb = input_panel_cb;
2345                 edit_box_details->input_panel_cb_data = input_panel_cb_data;
2346                 edit_box_details->item = elm_genlist_item_append(view_list,
2347                                 &g_eap_entry_itc, edit_box_details, NULL,
2348                                 ELM_GENLIST_ITEM_NONE, _gl_editbox_sel_cb, NULL);
2349                 elm_genlist_item_select_mode_set(edit_box_details->item,
2350                                 ELM_OBJECT_SELECT_MODE_NONE);
2351                 eap_info_list_data->pswd_item = edit_box_details->item;
2352 #endif
2353         }
2354
2355         __COMMON_FUNC_EXIT__;
2356         return eap_info_list_data;
2357 }
2358
2359 #if 0
2360 void eap_info_save_data(eap_info_list_t *eap_info_list_data)
2361 {
2362         if (!eap_info_list_data) {
2363                 ERROR_LOG(UG_NAME_ERR, "Invalid params passed!");
2364                 return;
2365         }
2366         char *txt = common_utils_get_list_item_entry_txt(eap_info_list_data->pswd_item);
2367
2368         wifi_ap_set_eap_passphrase(eap_info_list_data->ap, NULL, txt);
2369         g_free(txt);
2370         return;
2371 }
2372 #endif
2373
2374 void eap_info_remove(eap_info_list_t *eap_info_list_data)
2375 {
2376         if (!eap_info_list_data) {
2377                 ERROR_LOG(UG_NAME_ERR, "Invalid params passed!");
2378                 return;
2379         }
2380
2381         g_free(eap_info_list_data);
2382 }
2383
2384 void eap_connect_data_free(eap_connect_data_t *eap_data)
2385 {
2386         __common_eap_connect_cleanup(eap_data);
2387 }