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