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