Fixed DNS address set issue
[apps/native/ug-wifi-efl.git] / sources / libraries / Common / common_ip_info.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 <glib.h>
21
22 #include "common.h"
23 #include "ug_wifi.h"
24 #include "common_ip_info.h"
25 #include "i18nmanager.h"
26
27 #define DEFAULT_PROXY_ADDR              "0.0.0.0:80"
28
29 #define MAX_PORT_NUMBER         65535
30 #define MAX_LABEL_LENGTH        512
31
32 typedef struct {
33         char* title;
34         char* description;
35 } _view_detail_description_data_t;
36
37 static Elm_Object_Item* _add_description(Evas_Object* genlist, char* title,
38                 char* description, Elm_Object_Item* insert_after);
39
40 static Elm_Genlist_Item_Class *ip_toggle_itc ;
41 static Elm_Genlist_Item_Class *description_itc ;
42 static Elm_Genlist_Item_Class *ip_entry_itc;
43 static Evas_Object *curr_unfocus_entry = NULL;
44 static int curr_unfocuc_cursor_pos = 0;
45 static char *ip_info_text_list[ENTRY_TYPE_MAX];
46
47 static void _ip_info_set_current_unfocussed_entry(Evas_Object *entry)
48 {
49         if (entry == NULL)
50                 return;
51
52         curr_unfocus_entry = entry;
53         curr_unfocuc_cursor_pos = elm_entry_cursor_pos_get(entry);
54 }
55
56 static int _ip_info_is_current_unfocused_entry(Evas_Object *entry)
57 {
58         if (curr_unfocus_entry == entry)
59                 return curr_unfocuc_cursor_pos;
60         else
61                 return 0;
62 }
63
64 static void _ip_info_reset_current_unfocused_entry(void)
65 {
66         curr_unfocus_entry = NULL;
67         curr_unfocuc_cursor_pos = 0;
68 }
69
70 static void _gl_editbox_sel_cb(void *data, Evas_Object *obj, void *event_info)
71 {
72         Elm_Object_Item *item = (Elm_Object_Item *)event_info;
73         elm_genlist_item_selected_set(item, FALSE);
74 }
75
76 static void _ip_info_detail_description_del(void *data, Evas_Object *obj)
77 {
78         __COMMON_FUNC_ENTER__;
79
80         retm_if(NULL == data);
81
82         _view_detail_description_data_t* det = (_view_detail_description_data_t*) data;
83
84         g_free(det->description);
85         g_free(det->title);
86         g_free(det);
87         det = NULL;
88
89         __COMMON_FUNC_EXIT__;
90 }
91
92 static Evas_Object *_ip_info_detail_description_content_get(void *data,
93                 Evas_Object *obj, const char *part)
94 {
95         __COMMON_FUNC_ENTER__;
96         retvm_if(NULL == data || NULL == part, NULL);
97
98         _view_detail_description_data_t* det =
99                 (_view_detail_description_data_t*) data;
100
101         Evas_Object *layout = NULL;
102         Evas_Object *title_label = NULL;
103         char buf[MAX_LABEL_LENGTH] = {0, };
104
105         layout = elm_layout_add(obj);
106         elm_layout_file_set(layout, CUSTOM_GENLIST_PATH, "gl_custom_item");
107         evas_object_size_hint_align_set(layout, EVAS_HINT_FILL, EVAS_HINT_FILL);
108         evas_object_size_hint_weight_set(layout, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
109
110         title_label = elm_label_add(obj);
111         snprintf(buf, MAX_LABEL_LENGTH, "<font_size=40>%s</font_size>", dgettext(PACKAGE, det->title));
112
113         elm_object_text_set(title_label, buf);
114         evas_object_size_hint_weight_set(title_label, EVAS_HINT_EXPAND, 0);
115         evas_object_size_hint_align_set(title_label, EVAS_HINT_FILL, EVAS_HINT_FILL);
116         elm_object_part_content_set(layout, "elm.swallow.label", title_label);
117
118         snprintf(buf, MAX_LABEL_LENGTH, "%s", dgettext(PACKAGE, det->description));
119         elm_object_text_set(layout, buf);
120
121         __COMMON_FUNC_EXIT__;
122         return layout;
123 }
124
125 static void _ip_info_entry_key_enter_cb(void *data, Evas_Object *obj, void *event_info)
126 {
127         common_utils_entry_info_t *entry_info = (common_utils_entry_info_t *)data;
128         if (!entry_info)
129                 return;
130
131         Evas_Object *entry = NULL;
132         Elm_Object_Item *next_item = NULL;
133
134         switch (entry_info->entry_id) {
135         case ENTRY_TYPE_IP_ADDR:
136         case ENTRY_TYPE_SUBNET_MASK:
137         case ENTRY_TYPE_GATEWAY:
138         case ENTRY_TYPE_DNS_1:
139         case ENTRY_TYPE_PROXY_ADDR:
140         case ENTRY_TYPE_DNS_2:
141                 next_item = elm_genlist_item_next_get(entry_info->item);
142                 while (next_item) {
143                         if (elm_object_item_disabled_get(next_item) == EINA_FALSE &&
144                                 elm_genlist_item_select_mode_get(next_item) != ELM_OBJECT_SELECT_MODE_DISPLAY_ONLY) {
145                                 entry = elm_object_item_part_content_get(next_item, "elm.swallow.content");
146                                 if (entry) {
147                                         elm_object_focus_set(entry, EINA_TRUE);
148                                         return;
149                                 }
150                         }
151
152                         next_item = elm_genlist_item_next_get(next_item);
153                 }
154                 break;
155         case ENTRY_TYPE_PROXY_PORT:
156                 entry = elm_object_item_part_content_get(entry_info->item, "elm.swallow.content");
157                 if (entry)
158                         elm_object_focus_set(entry, EINA_FALSE);
159
160                 break;
161         default:
162                 break;
163         }
164 }
165
166 static void _ip_info_entry_cursor_changed_cb(void* data, Evas_Object* obj, void* event_info)
167 {
168         common_utils_entry_info_t *entry_info = (common_utils_entry_info_t *)data;
169         if (!entry_info)
170                 return;
171
172         if (elm_object_focus_get(obj)) {
173                 if (elm_entry_is_empty(obj))
174                         elm_object_item_signal_emit(entry_info->item, "elm,state,eraser,hide", "");
175                 else
176                         elm_object_item_signal_emit(entry_info->item, "elm,state,eraser,show", "");
177         }
178
179         if (entry_info->entry_txt) {
180                 g_free(entry_info->entry_txt);
181                 entry_info->entry_txt = NULL;
182         }
183
184         char *entry_text = elm_entry_markup_to_utf8(elm_entry_entry_get(obj));
185         if (entry_text != NULL && entry_text[0] != '\0')
186                 entry_info->entry_txt = elm_entry_markup_to_utf8(elm_entry_entry_get(obj));
187
188         g_free(entry_text);
189         entry_text = NULL;
190 }
191
192 static void _ip_info_entry_changed_cb(void *data,
193                 Evas_Object *obj, void *event_info)
194 {
195         common_utils_entry_info_t *entry_info = (common_utils_entry_info_t *)data;
196         if (!entry_info)
197                 return;
198
199         int entry_pos = 0;
200         char *entry_text = NULL;
201         char **ip_text = NULL;
202         int panel_type = 0;
203
204         if (obj == NULL)
205                 return;
206
207         if (elm_object_focus_get(obj)) {
208                 if (elm_entry_is_empty(obj))
209                         elm_object_item_signal_emit(entry_info->item, "elm,state,eraser,hide", "");
210                 else
211                         elm_object_item_signal_emit(entry_info->item, "elm,state,eraser,show", "");
212         }
213
214         panel_type = elm_entry_input_panel_layout_get(obj);
215         if (panel_type == ELM_INPUT_PANEL_LAYOUT_IP) {
216                 int i = 0;
217                 int ip_addr[4] = { 0 };
218                 char entry_ip_text[16] = { 0, };
219                 gboolean fixed = FALSE;
220                 entry_text = elm_entry_markup_to_utf8(elm_entry_entry_get(obj));
221                 ip_text = g_strsplit(entry_text, ".", 5);
222
223                 if (entry_text == NULL || entry_text[0] == '\0') {
224                         if (entry_info->entry_txt) {
225                                 g_free(entry_info->entry_txt);
226                                 entry_info->entry_txt = NULL;
227                         }
228
229                         entry_info->entry_txt = g_strdup(DEFAULT_GUIDE_IP);
230                         g_free(entry_text);
231                         entry_text = NULL;
232                 } else {
233                         for (i = 0; i < 5; i++) {
234                                 if (ip_text[i] == NULL)
235                                         break;
236
237                                 if (i == 4) {
238                                         fixed = TRUE;
239                                         break;
240                                 }
241
242                                 ip_addr[i] = atoi(ip_text[i]);
243                                 if (ip_addr[i] > 255) {
244                                         ip_addr[i] = 255;
245                                         fixed = TRUE;
246                                 }
247
248                                 if (i < 3)
249                                         g_snprintf(entry_text, 5, "%d.", ip_addr[i]);
250                                 else
251                                         g_snprintf(entry_text, 4, "%d", ip_addr[i]);
252
253                                 g_strlcat(entry_ip_text, entry_text, sizeof(entry_ip_text));
254                         }
255                         g_free(entry_text);
256                         g_strfreev(ip_text);
257                         entry_text = NULL;
258                         ip_text = NULL;
259
260                         if (fixed == TRUE) {
261                                 entry_pos = elm_entry_cursor_pos_get(obj);
262                                 elm_entry_entry_set(obj, entry_ip_text);
263                                 elm_entry_cursor_pos_set(obj, entry_pos+1);
264                         }
265                 }
266         } else if (panel_type == ELM_INPUT_PANEL_LAYOUT_NUMBERONLY) {
267                 int port_num = 0;
268
269                 entry_text = elm_entry_markup_to_utf8(elm_entry_entry_get(obj));
270                 if (entry_text == NULL || *entry_text == '\0')
271                         entry_info->entry_txt = NULL;
272
273                 if (entry_text != NULL)
274                         port_num = (int)strtol(entry_text, NULL, 10);
275
276                 if (port_num > MAX_PORT_NUMBER) {
277                         entry_pos = elm_entry_cursor_pos_get(obj);
278                         g_snprintf(entry_text, 6, "%d", MAX_PORT_NUMBER);
279                         elm_entry_entry_set(obj, entry_text);
280                         elm_entry_cursor_pos_set(obj, entry_pos);
281                 }
282
283                 g_free(entry_text);
284                 entry_text = NULL;
285         } else {
286                 entry_text = elm_entry_markup_to_utf8(elm_entry_entry_get(obj));
287                 if (entry_text == NULL || *entry_text == '\0')
288                         entry_info->entry_txt = NULL;
289
290                 g_free(entry_text);
291                 entry_text = NULL;
292         }
293 }
294
295 static void _ip_info_entry_focused_cb(void *data, Evas_Object *obj, void *event_info)
296 {
297         common_utils_entry_info_t *entry_info = (common_utils_entry_info_t *)data;
298         int curr_entry_pos = 0;
299
300         if (!entry_info)
301                 return;
302
303         curr_entry_pos = _ip_info_is_current_unfocused_entry(obj);
304
305         if (curr_entry_pos)
306                 elm_entry_cursor_pos_set(obj, curr_entry_pos);
307         else
308                 elm_entry_cursor_end_set(obj);
309
310         if (!elm_entry_is_empty(obj))
311                 elm_object_item_signal_emit(entry_info->item, "elm,state,eraser,show", "");
312
313         elm_object_item_signal_emit(entry_info->item, "elm,state,rename,hide", "");
314 }
315
316
317 static gboolean __is_valid_static_ip_string_length(const gchar *text)
318 {
319         if (!text) {
320                 INFO_LOG(UG_NAME_ERR, "IP address text is NULL");
321                 return FALSE;
322         } else {
323                 size_t len = strlen(text);
324                 if (len == 0 || len > 15) {
325                         INFO_LOG(UG_NAME_ERR, "IP address text string length is not valid");
326                         return FALSE;
327                 }
328         }
329         return TRUE;
330 }
331
332 static void _ip_info_entry_unfocused_cb(void *data, Evas_Object *obj, void *event_info)
333 {
334         common_utils_entry_info_t *entry_info = (common_utils_entry_info_t *)data;
335         if (!entry_info)
336                 return;
337
338         _ip_info_set_current_unfocussed_entry(obj);
339
340         int panel_type = elm_entry_input_panel_layout_get(obj);
341         if (panel_type == ELM_INPUT_PANEL_LAYOUT_IP) {
342                 int ip_addr[4] = {0};
343                 char *entry_text = elm_entry_markup_to_utf8(elm_entry_entry_get(obj));
344                 if (!__is_valid_static_ip_string_length(entry_text)) {
345                         INFO_LOG(UG_NAME_ERR, "Invalid IP address.");
346                         free(entry_text);
347                         return;
348                 }
349                 if (entry_text && (strlen(entry_text) > 0)) {
350                         elm_entry_entry_set(obj, entry_text);
351                         if (entry_info->entry_txt) {
352                                 g_free(entry_info->entry_txt);
353                                 entry_info->entry_txt = NULL;
354                         }
355                         entry_info->entry_txt = g_strdup(entry_text);
356                 }
357                 g_free(entry_text);
358                 entry_text = NULL;
359         }
360
361         elm_object_item_signal_emit(entry_info->item, "elm,state,eraser,hide", "");
362         elm_object_item_signal_emit(entry_info->item, "elm,state,rename,show", "");
363 }
364
365 static void _ip_info_entry_del_callbacks(Elm_Object_Item *item)
366 {
367         if (item == NULL)
368                 return;
369
370         Evas_Object *entry = NULL;
371
372         entry = elm_object_item_part_content_get(item, "elm.icon.entry");
373         if (entry == NULL)
374                 return;
375
376         evas_object_smart_callback_del(entry, "activated",
377                         _ip_info_entry_key_enter_cb);
378         evas_object_smart_callback_del(entry, "cursor,changed",
379                         _ip_info_entry_cursor_changed_cb);
380         evas_object_smart_callback_del(entry, "changed",
381                         _ip_info_entry_changed_cb);
382         evas_object_smart_callback_del(entry, "focused",
383                         _ip_info_entry_focused_cb);
384         evas_object_smart_callback_del(entry, "unfocused",
385                         _ip_info_entry_unfocused_cb);
386 }
387
388 static void _ip_info_entry_add_callbacks(Evas_Object *entry,
389                 common_utils_entry_info_t *entry_info)
390 {
391         if (entry == NULL)
392                 return;
393
394         evas_object_smart_callback_add(entry, "activated",
395                         _ip_info_entry_key_enter_cb, entry_info);
396         evas_object_smart_callback_add(entry, "cursor,changed",
397                         _ip_info_entry_cursor_changed_cb, entry_info);
398         evas_object_smart_callback_add(entry, "changed",
399                         _ip_info_entry_changed_cb, entry_info);
400         evas_object_smart_callback_add(entry, "focused",
401                         _ip_info_entry_focused_cb, entry_info);
402         evas_object_smart_callback_add(entry, "unfocused",
403                         _ip_info_entry_unfocused_cb, entry_info);
404 }
405
406 static Evas_Object *_ip_info_entry_item_content_get(void *data, Evas_Object *obj, const char *part)
407 {
408         common_utils_entry_info_t *entry_info = (common_utils_entry_info_t *)data;
409         if (!entry_info)
410                 return NULL;
411
412         Evas_Object *layout = NULL;
413         Evas_Object *label = NULL;
414         Evas_Object *editfield = NULL;
415         char *guide_txt = NULL;
416         char *accepted = NULL;
417         Elm_Input_Panel_Layout panel_type;
418         int return_key_type;
419         char buf[MAX_LABEL_LENGTH] = {0, };
420
421         switch (entry_info->entry_id) {
422         case ENTRY_TYPE_IP_ADDR:
423         case ENTRY_TYPE_SUBNET_MASK:
424         case ENTRY_TYPE_GATEWAY:
425         case ENTRY_TYPE_DNS_1:
426         case ENTRY_TYPE_DNS_2:
427                 guide_txt = entry_info->guide_txt;
428                 panel_type = ELM_INPUT_PANEL_LAYOUT_IP;
429                 return_key_type = ECORE_IMF_INPUT_PANEL_RETURN_KEY_TYPE_NEXT;
430                 accepted = "0123456789.";
431                 break;
432         case ENTRY_TYPE_PROXY_ADDR:
433                 guide_txt = DEFAULT_GUIDE_PROXY_IP;
434                 panel_type = ELM_INPUT_PANEL_LAYOUT_URL;
435                 return_key_type = ECORE_IMF_INPUT_PANEL_RETURN_KEY_TYPE_NEXT;
436                 /* Temporary fix */
437                 /* accepted = "0123456789.abcdefghijklmnopqrstuvwxyz-ABCDEFGHIJKLMNOPQRSTUVWXYZ"; */
438                 break;
439         case ENTRY_TYPE_PROXY_PORT:
440                 guide_txt = DEFAULT_GUIDE_PROXY_PORT;
441                 panel_type = ELM_INPUT_PANEL_LAYOUT_NUMBERONLY;
442                 return_key_type = ECORE_IMF_INPUT_PANEL_RETURN_KEY_TYPE_DONE;
443                 accepted = "0123456789";
444                 break;
445         default:
446                 return NULL;
447         }
448
449         layout = elm_layout_add(obj);
450         elm_layout_file_set(layout, CUSTOM_GENLIST_PATH, "gl_custom_item");
451         evas_object_size_hint_align_set(layout, EVAS_HINT_FILL, EVAS_HINT_FILL);
452         evas_object_size_hint_weight_set(layout, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
453
454         snprintf(buf, MAX_LABEL_LENGTH, "<font_size=40>%s</font_size>",
455                         dgettext(PACKAGE, entry_info->title_txt));
456
457         label = elm_label_add(obj);
458         evas_object_size_hint_weight_set(label, EVAS_HINT_EXPAND, 0);
459         evas_object_size_hint_align_set(label, EVAS_HINT_FILL, EVAS_HINT_FILL);
460         elm_object_text_set(label, buf);
461         elm_object_part_content_set(layout, "elm.swallow.label", label);
462
463         editfield = elm_entry_add(obj);
464         elm_entry_single_line_set(editfield, EINA_TRUE);
465         elm_entry_scrollable_set(editfield, EINA_TRUE);
466
467         if (!g_strcmp0(entry_info->str_pkg_name, "wifi-qs"))
468                 elm_entry_input_panel_imdata_set(editfield, "type=systempopup", 16);
469
470         elm_entry_cnp_mode_set(editfield, ELM_CNP_MODE_PLAINTEXT);
471
472         elm_object_part_text_set(editfield, "elm.guide", guide_txt);
473         if (entry_info->entry_txt && (strlen(entry_info->entry_txt) > 0) &&
474                         g_strcmp0(entry_info->entry_txt, DEFAULT_GUIDE_IP) != 0) {
475                 elm_entry_entry_set(editfield, entry_info->entry_txt);
476         }
477
478         elm_entry_input_panel_layout_set(editfield, panel_type);
479
480         Elm_Entry_Filter_Accept_Set digits_filter_data;
481         memset(&digits_filter_data, 0, sizeof(Elm_Entry_Filter_Accept_Set));
482         digits_filter_data.accepted = accepted;
483         elm_entry_markup_filter_append(editfield, elm_entry_filter_accept_set, &digits_filter_data);
484
485         if (entry_info->input_panel_cb) {
486                 Ecore_IMF_Context *imf_ctxt = elm_entry_imf_context_get(editfield);
487                 if (imf_ctxt) {
488                         ecore_imf_context_input_panel_event_callback_add(
489                                         imf_ctxt,
490                                         ECORE_IMF_INPUT_PANEL_STATE_EVENT,
491                                         entry_info->input_panel_cb,
492                                         entry_info->input_panel_cb_data);
493                 }
494         }
495
496         elm_entry_input_panel_return_key_type_set(editfield, return_key_type);
497         _ip_info_entry_add_callbacks(editfield, entry_info);
498         elm_object_part_content_set(layout, "elm.swallow.content", editfield);
499
500         if (!net_get_device_policy_wifi_profile())
501                 elm_object_disabled_set(editfield, EINA_TRUE);
502         else
503                 elm_object_disabled_set(editfield, EINA_FALSE);
504
505         return layout;
506 }
507
508 static void _ip_info_entry_item_del(void *data, Evas_Object *obj)
509 {
510         common_utils_entry_info_t *entry_info = (common_utils_entry_info_t *)data;
511         if (entry_info == NULL)
512                 return;
513
514         g_free(ip_info_text_list[entry_info->entry_id]);
515         ip_info_text_list[entry_info->entry_id] = NULL;
516
517         if (entry_info->entry_txt) {
518                 ip_info_text_list[entry_info->entry_id] = g_strdup(entry_info->entry_txt);
519                 g_free(entry_info->entry_txt);
520                 entry_info->entry_txt = NULL;
521         }
522
523         g_free(entry_info);
524         entry_info = NULL;
525 }
526
527 #ifdef ACCESSIBLITY_FEATURE
528 static char *_access_info_cb(void *data, Evas_Object *obj)
529 {
530         common_utils_entry_info_t *entry_info = (common_utils_entry_info_t *)data;
531         if (!entry_info)
532                 return NULL;
533
534         if (entry_info->entry_txt)
535                 return g_strdup_printf("%s %s", entry_info->title_txt, entry_info->entry_txt);
536         else
537                 return g_strdup_printf("%s %s", entry_info->title_txt, entry_info->guide_txt);
538 }
539 #endif
540
541 static void _create_static_ip_table(full_ip_info_t *ip_data)
542 {
543         char *txt = NULL;
544         retm_if(NULL == ip_data);
545
546         ip_info_list_t *ip_info_list_data = ip_data->ip_info_list;
547         prev_ip_info_t *prev_ip_info = ip_data->prev_ip_info;
548         common_utils_entry_info_t *edit_box_details;
549         wifi_manager_ip_config_type_e ip_type;
550
551         retm_if(NULL == prev_ip_info || NULL == ip_info_list_data);
552         wifi_manager_ap_h ap = ip_info_list_data->ap;
553         __COMMON_FUNC_ENTER__;
554
555         /* IP Address */
556         int ret = wifi_manager_ap_get_ip_config_type(ap, WIFI_MANAGER_ADDRESS_FAMILY_IPV4, &ip_type);
557         if (ret != WIFI_MANAGER_ERROR_NONE)
558                 INFO_LOG(UG_NAME_ERR, "Failed to get IP config_type! [%d]", ret);
559
560         edit_box_details = g_try_new0(common_utils_entry_info_t, 1);
561         if (edit_box_details == NULL)
562                 return;
563
564         edit_box_details->entry_id = ENTRY_TYPE_IP_ADDR;
565         edit_box_details->title_txt = "IDS_WIFI_BODY_IP_ADDRESS";
566         if (ip_type == WIFI_MANAGER_IP_CONFIG_TYPE_DYNAMIC)
567                 edit_box_details->entry_txt = g_strdup(DEFAULT_GUIDE_IP);
568         else {
569                 ret = wifi_manager_ap_get_ip_address(ap, WIFI_MANAGER_ADDRESS_FAMILY_IPV4, &txt);
570                 if (ret != WIFI_MANAGER_ERROR_NONE)
571                         INFO_LOG(UG_NAME_ERR, "Failed to get IP Address! [%d]", ret);
572                 edit_box_details->entry_txt = txt;
573         }
574         edit_box_details->guide_txt = DEFAULT_GUIDE_IP;
575         edit_box_details->str_pkg_name = ip_info_list_data->str_pkg_name;
576         edit_box_details->input_panel_cb = ip_info_list_data->input_panel_cb;
577         edit_box_details->input_panel_cb_data = ip_info_list_data->input_panel_cb_data;
578         edit_box_details->item = elm_genlist_item_insert_after(
579                         ip_info_list_data->genlist, ip_entry_itc,
580                         edit_box_details, NULL, ip_info_list_data->ip_toggle_item,
581                         ELM_GENLIST_ITEM_NONE, _gl_editbox_sel_cb, NULL);
582 #ifdef ACCESSIBLITY_FEATURE
583         Evas_Object *ao = elm_object_item_access_object_get(edit_box_details->item);
584         elm_access_info_cb_set(ao, ELM_ACCESS_INFO, _access_info_cb, edit_box_details);
585 #endif
586         ip_info_list_data->ip_addr_item = edit_box_details->item;
587
588         if (ip_data->is_first_create == TRUE)
589                 prev_ip_info->ip_addr = g_strdup(txt);
590
591         /* Subnet Mask */
592         edit_box_details = g_try_new0(common_utils_entry_info_t, 1);
593         if (edit_box_details == NULL)
594                 return;
595
596         edit_box_details->entry_id = ENTRY_TYPE_SUBNET_MASK;
597         edit_box_details->title_txt = "IDS_WIFI_BODY_SUBNET_MASK";
598         if (ip_type == WIFI_MANAGER_IP_CONFIG_TYPE_DYNAMIC)
599                 edit_box_details->entry_txt = g_strdup(DEFAULT_GUIDE_IP);
600         else {
601                 ret = wifi_manager_ap_get_subnet_mask(ap, WIFI_MANAGER_ADDRESS_FAMILY_IPV4, &txt);
602                 if (ret != WIFI_MANAGER_ERROR_NONE)
603                         INFO_LOG(UG_NAME_ERR, "Failed to get subnet mask! [%d]", ret);
604                 edit_box_details->entry_txt = txt;
605         }
606         edit_box_details->guide_txt = DEFAULT_GUIDE_IP;
607         edit_box_details->str_pkg_name = ip_info_list_data->str_pkg_name;
608         edit_box_details->input_panel_cb = ip_info_list_data->input_panel_cb;
609         edit_box_details->input_panel_cb_data = ip_info_list_data->input_panel_cb_data;
610         edit_box_details->item = elm_genlist_item_insert_after(
611                         ip_info_list_data->genlist, ip_entry_itc,
612                         edit_box_details, NULL, ip_info_list_data->ip_addr_item,
613                         ELM_GENLIST_ITEM_NONE, _gl_editbox_sel_cb, NULL);
614 #ifdef ACCESSIBLITY_FEATURE
615         ao = elm_object_item_access_object_get(edit_box_details->item);
616         elm_access_info_cb_set(ao, ELM_ACCESS_INFO, _access_info_cb, edit_box_details);
617 #endif
618         ip_info_list_data->subnet_mask_item = edit_box_details->item;
619
620         if (ip_data->is_first_create == TRUE)
621                 prev_ip_info->subnet_mask = g_strdup(txt);
622
623         /* Gateway Address */
624         ret = wifi_manager_ap_get_gateway_address(ap, WIFI_MANAGER_ADDRESS_FAMILY_IPV4, &txt);
625         if (ret != WIFI_MANAGER_ERROR_NONE)
626                 INFO_LOG(UG_NAME_ERR, "Failed to get gateway address! [%d]", ret);
627
628         edit_box_details = g_try_new0(common_utils_entry_info_t, 1);
629         if (edit_box_details == NULL)
630                 return;
631
632         edit_box_details->entry_id = ENTRY_TYPE_GATEWAY;
633         edit_box_details->title_txt = "IDS_WIFI_BODY_GATEWAY_ADDRESS";
634         edit_box_details->entry_txt = txt;
635         edit_box_details->guide_txt = DEFAULT_GUIDE_IP;
636         edit_box_details->str_pkg_name = ip_info_list_data->str_pkg_name;
637         edit_box_details->input_panel_cb = ip_info_list_data->input_panel_cb;
638         edit_box_details->input_panel_cb_data = ip_info_list_data->input_panel_cb_data;
639         edit_box_details->item = elm_genlist_item_insert_after(
640                         ip_info_list_data->genlist, ip_entry_itc,
641                         edit_box_details, NULL, ip_info_list_data->subnet_mask_item,
642                         ELM_GENLIST_ITEM_NONE, _gl_editbox_sel_cb, NULL);
643 #ifdef ACCESSIBLITY_FEATURE
644         ao = elm_object_item_access_object_get(edit_box_details->item);
645         elm_access_info_cb_set(ao, ELM_ACCESS_INFO, _access_info_cb, edit_box_details);
646 #endif
647         ip_info_list_data->gateway_addr_item = edit_box_details->item;
648
649         if (ip_data->is_first_create == TRUE)
650                 prev_ip_info->gateway_addr = g_strdup(txt);
651
652         /* DNS 1 */
653         ret = wifi_manager_ap_get_dns_address(ap, 1, WIFI_MANAGER_ADDRESS_FAMILY_IPV4, &txt);
654         if (ret != WIFI_MANAGER_ERROR_NONE)
655                 INFO_LOG(UG_NAME_ERR, "Failed to get DNS 1 Address! [%d]", ret);
656
657         edit_box_details = g_try_new0(common_utils_entry_info_t, 1);
658         if (edit_box_details == NULL)
659                 return;
660
661         edit_box_details->entry_id = ENTRY_TYPE_DNS_1;
662         edit_box_details->title_txt = "IDS_WIFI_BODY_DNS_1";
663         edit_box_details->entry_txt = txt;
664         edit_box_details->guide_txt = DEFAULT_GUIDE_IP;
665         edit_box_details->str_pkg_name = ip_info_list_data->str_pkg_name;
666         edit_box_details->input_panel_cb = ip_info_list_data->input_panel_cb;
667         edit_box_details->input_panel_cb_data = ip_info_list_data->input_panel_cb_data;
668         edit_box_details->item = elm_genlist_item_insert_after(
669                         ip_info_list_data->genlist, ip_entry_itc,
670                         edit_box_details, NULL, ip_info_list_data->gateway_addr_item,
671                         ELM_GENLIST_ITEM_NONE, _gl_editbox_sel_cb, NULL);
672 #ifdef ACCESSIBLITY_FEATURE
673         ao = elm_object_item_access_object_get(edit_box_details->item);
674         elm_access_info_cb_set(ao, ELM_ACCESS_INFO, _access_info_cb, edit_box_details);
675 #endif
676         ip_info_list_data->dns_1_item = edit_box_details->item;
677
678         if (ip_data->is_first_create == TRUE)
679                 prev_ip_info->dns_1 = g_strdup(txt);
680
681         /* DNS 2 */
682         ret = wifi_manager_ap_get_dns_address(ap, 2, WIFI_MANAGER_ADDRESS_FAMILY_IPV4, &txt);
683         if (ret != WIFI_MANAGER_ERROR_NONE)
684                 INFO_LOG(UG_NAME_ERR, "Failed to get DNS 2 Address! [%d]", ret);
685
686         edit_box_details = g_try_new0(common_utils_entry_info_t, 1);
687         if (edit_box_details == NULL)
688                 return;
689
690         edit_box_details->entry_id = ENTRY_TYPE_DNS_2;
691         edit_box_details->title_txt = "IDS_WIFI_BODY_DNS_2";
692         edit_box_details->entry_txt = txt;
693         edit_box_details->guide_txt = DEFAULT_GUIDE_IP;
694         edit_box_details->str_pkg_name = ip_info_list_data->str_pkg_name;
695         edit_box_details->input_panel_cb = ip_info_list_data->input_panel_cb;
696         edit_box_details->input_panel_cb_data = ip_info_list_data->input_panel_cb_data;
697         edit_box_details->item = elm_genlist_item_insert_after(
698                         ip_info_list_data->genlist, ip_entry_itc,
699                         edit_box_details, NULL, ip_info_list_data->dns_1_item,
700                         ELM_GENLIST_ITEM_NONE, _gl_editbox_sel_cb, NULL);
701 #ifdef ACCESSIBLITY_FEATURE
702         ao = elm_object_item_access_object_get(edit_box_details->item);
703         elm_access_info_cb_set(ao, ELM_ACCESS_INFO, _access_info_cb, edit_box_details);
704 #endif
705         ip_info_list_data->dns_2_item = edit_box_details->item;
706
707         if (ip_data->is_first_create == TRUE)
708                 prev_ip_info->dns_2 = g_strdup(txt);
709
710         ip_data->is_first_create = FALSE;
711
712         __COMMON_FUNC_EXIT__;
713
714         return;
715 }
716
717 static void _delete_static_ip_table(ip_info_list_t *ip_info_list_data)
718 {
719         __COMMON_FUNC_ENTER__;
720
721         retm_if(NULL == ip_info_list_data);
722
723         _ip_info_reset_current_unfocused_entry();
724
725         _ip_info_entry_del_callbacks(ip_info_list_data->ip_addr_item);
726         elm_object_item_del(ip_info_list_data->ip_addr_item);
727         ip_info_list_data->ip_addr_item = NULL;
728
729         _ip_info_entry_del_callbacks(ip_info_list_data->subnet_mask_item);
730         elm_object_item_del(ip_info_list_data->subnet_mask_item);
731         ip_info_list_data->subnet_mask_item = NULL;
732
733         _ip_info_entry_del_callbacks(ip_info_list_data->gateway_addr_item);
734         elm_object_item_del(ip_info_list_data->gateway_addr_item);
735         ip_info_list_data->gateway_addr_item = NULL;
736
737         _ip_info_entry_del_callbacks(ip_info_list_data->dns_1_item);
738         elm_object_item_del(ip_info_list_data->dns_1_item);
739         ip_info_list_data->dns_1_item = NULL;
740
741         _ip_info_entry_del_callbacks(ip_info_list_data->dns_2_item);
742         elm_object_item_del(ip_info_list_data->dns_2_item);
743         ip_info_list_data->dns_2_item = NULL;
744
745         __COMMON_FUNC_EXIT__;
746 }
747
748 static gboolean __genlist_item_disable_later(void *data)
749 {
750         elm_genlist_item_selected_set((Elm_Object_Item *)data, FALSE);
751
752         return FALSE;
753 }
754
755 static void _gl_deselect_callback(void* data,
756                 Evas_Object* obj, void* event_info)
757 {
758         common_util_managed_idle_add(__genlist_item_disable_later, event_info);
759 }
760
761 static char* _ip_info_iptoggle_text_get(void *data, Evas_Object *obj,
762                 const char *part)
763 {
764
765         retvm_if(NULL == data || NULL == part, NULL);
766         full_ip_info_t *ip_data = (full_ip_info_t *) data;
767
768         if (!strcmp("elm.text", part)) {
769                 ip_info_list_t *ip_info_list_data = ip_data->ip_info_list;
770 #ifdef ACCESSIBLITY_FEATURE
771                 char buf[100];
772                 Evas_Object *ao = elm_object_item_access_object_get(ip_info_list_data->ip_toggle_item);
773                 g_snprintf(buf, sizeof(buf), "%s%s%s",
774                                                 sc(ip_info_list_data->str_pkg_name, I18N_TYPE_On),
775                                                 sc(ip_info_list_data->str_pkg_name, I18N_TYPE_Off),
776                                                 sc(ip_info_list_data->str_pkg_name, I18N_TYPE_Button));
777                 elm_access_info_set(ao, ELM_ACCESS_TYPE, buf);
778
779                 if (WIFI_MANAGER_IP_CONFIG_TYPE_STATIC == ip_info_list_data->ip_type)
780                         elm_access_info_set(ao, ELM_ACCESS_STATE, sc(ip_info_list_data->str_pkg_name, I18N_TYPE_On));
781                 else
782                         elm_access_info_set(ao, ELM_ACCESS_STATE, sc(ip_info_list_data->str_pkg_name, I18N_TYPE_Off));
783 #endif
784                 return (char*)g_strdup(sc(ip_info_list_data->str_pkg_name, I18N_TYPE_Static_IP));
785         }
786
787         return NULL;
788 }
789
790 static Elm_Object_Item* _add_description(Evas_Object* genlist, char* title,
791                 char* description, Elm_Object_Item* insert_after)
792 {
793         retvm_if(NULL == genlist, NULL);
794
795         _view_detail_description_data_t* description_data =
796                         g_try_new0(_view_detail_description_data_t, 1);
797         retvm_if(NULL == description_data, NULL);
798
799         description_data->title = g_strdup(title);
800         description_data->description = g_strdup(description);
801
802         Elm_Object_Item* det = NULL;
803         if (insert_after) {
804                 det = elm_genlist_item_insert_after(
805                                 genlist, /*obj*/
806                                 description_itc,/*itc*/
807                                 description_data,/*data*/
808                                 NULL,/*parent*/
809                                 insert_after, /*after than*/
810                                 ELM_GENLIST_ITEM_NONE, /*flags*/
811                                 _gl_deselect_callback,/*func*/
812                                 NULL);/*func_data*/
813         } else {
814                 det = elm_genlist_item_append(
815                                 genlist,
816                                 description_itc,
817                                 description_data,
818                                 NULL,
819                                 ELM_GENLIST_ITEM_NONE,
820                                 _gl_deselect_callback,
821                                 NULL);
822         }
823
824         elm_genlist_item_select_mode_set(det, ELM_OBJECT_SELECT_MODE_DISPLAY_ONLY);
825         elm_object_item_disabled_set(det, TRUE);
826
827         return det;
828 }
829
830 static void __ip_info_toggle_item_sel_cb(void* data,
831                 Evas_Object* obj, void* event_info)
832 {
833         __COMMON_FUNC_ENTER__;
834
835         const char *object_type;
836         ip_info_list_t *ip_info_list_data = NULL;
837         wifi_manager_ip_config_type_e ip_type = WIFI_MANAGER_IP_CONFIG_TYPE_DYNAMIC;
838         full_ip_info_t *ip_data = (full_ip_info_t *)data;
839         retm_if(ip_data == NULL);
840         ip_info_list_data = ip_data->ip_info_list;
841         if (ip_info_list_data == NULL) {
842                 __COMMON_FUNC_EXIT__;
843                 return;
844         }
845
846         if (!net_get_device_policy_wifi_profile()) {
847                 SECURE_DEBUG_LOG(UG_NAME_NORMAL, "Wifi profile device policy restricts");
848                 __COMMON_FUNC_EXIT__;
849                 return;
850         }
851
852         wifi_manager_ap_h ap = ip_info_list_data->ap;
853
854         object_type = evas_object_type_get(obj);
855
856         if (g_strcmp0(object_type, "elm_check") == 0) {
857                 Eina_Bool ip_mode = elm_check_state_get(obj);
858
859                 if (ip_mode == TRUE)
860                         ip_type = WIFI_MANAGER_IP_CONFIG_TYPE_STATIC;
861                 else
862                         ip_type = WIFI_MANAGER_IP_CONFIG_TYPE_DYNAMIC;
863         } else if (g_strcmp0(object_type, "elm_genlist") == 0) {
864                 elm_genlist_item_selected_set(ip_info_list_data->ip_toggle_item,
865                                 EINA_FALSE);
866
867                 if (ip_info_list_data->ip_type == WIFI_MANAGER_IP_CONFIG_TYPE_STATIC)
868                         ip_type = WIFI_MANAGER_IP_CONFIG_TYPE_DYNAMIC;
869                 else
870                         ip_type = WIFI_MANAGER_IP_CONFIG_TYPE_STATIC;
871         }
872
873         if (ip_type == WIFI_MANAGER_IP_CONFIG_TYPE_DYNAMIC) {
874                 char *ip_addr = NULL;
875
876                 /* Hide input keypad if popped out */
877                 ecore_imf_input_panel_hide();
878
879                 _delete_static_ip_table(ip_info_list_data);
880
881                 wifi_manager_ap_get_ip_address(ap, WIFI_MANAGER_ADDRESS_FAMILY_IPV4, &ip_addr);
882
883                 /* Dynamic IP Address */
884                 ip_info_list_data->ip_addr_item = _add_description(
885                                 ip_info_list_data->genlist,
886                                 "IDS_WIFI_BODY_IP_ADDRESS",
887                                 ip_addr,
888                                 ip_info_list_data->ip_toggle_item);
889
890                 g_free(ip_addr);
891                 ip_addr = NULL;
892
893                 ip_info_list_data->ip_type = WIFI_MANAGER_IP_CONFIG_TYPE_DYNAMIC;
894         } else if (ip_type == WIFI_MANAGER_IP_CONFIG_TYPE_STATIC) {
895                 elm_object_item_del(ip_info_list_data->ip_addr_item);
896                 ip_info_list_data->ip_addr_item = NULL;
897                 ip_data->is_first_create = FALSE;
898
899                 /* Create the entry layouts */
900                 _create_static_ip_table(ip_data);
901                 ip_info_list_data->ip_type = WIFI_MANAGER_IP_CONFIG_TYPE_STATIC;
902         }
903
904         if (ip_info_list_data->ip_toggle_item != NULL)
905                 elm_genlist_item_update(ip_info_list_data->ip_toggle_item);
906
907         __COMMON_FUNC_EXIT__;
908 }
909
910 static Evas_Object *_ip_info_iptoggle_content_get(void *data,
911                 Evas_Object *obj, const char *part)
912 {
913         __COMMON_FUNC_ENTER__;
914
915         retvm_if(NULL == data || NULL == obj || NULL == part, NULL);
916         full_ip_info_t *ip_data = (full_ip_info_t *) data;
917         ip_info_list_t *ip_info_list_data = ip_data->ip_info_list;
918         Evas_Object *toggle_btn = NULL;
919
920         if (!strcmp("elm.swallow.end", part)) {
921                 toggle_btn = elm_check_add(obj);
922                 elm_object_style_set(toggle_btn, "on&off");
923                 elm_object_focus_allow_set(toggle_btn, EINA_FALSE);
924
925                 if (WIFI_MANAGER_IP_CONFIG_TYPE_STATIC == ip_info_list_data->ip_type)
926                         elm_check_state_set(toggle_btn, EINA_TRUE);
927                 else
928                         elm_check_state_set(toggle_btn, EINA_FALSE);
929
930                 evas_object_propagate_events_set(toggle_btn, EINA_FALSE);
931                 evas_object_size_hint_align_set(toggle_btn, EVAS_HINT_FILL, EVAS_HINT_FILL);
932                 evas_object_size_hint_weight_set(toggle_btn, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
933                 evas_object_smart_callback_add(toggle_btn, "changed",
934                                 __ip_info_toggle_item_sel_cb, ip_data);
935
936                 if (!net_get_device_policy_wifi_profile())
937                         elm_object_disabled_set(toggle_btn, EINA_TRUE);
938                 else
939                         elm_object_disabled_set(toggle_btn, EINA_FALSE);
940         }
941
942
943
944         __COMMON_FUNC_EXIT__;
945         return toggle_btn;
946 }
947
948 #if 0
949 static void ip_info_print_values(wifi_manager_ap_h ap)
950 {
951         char *txt;
952         wifi_manager_ip_config_type_e type = WIFI_MANAGER_IP_CONFIG_TYPE_NONE;
953
954         wifi_manager_ap_get_ip_config_type(ap, WIFI_MANAGER_ADDRESS_FAMILY_IPV4, &type);
955         if (WIFI_MANAGER_IP_CONFIG_TYPE_STATIC == type) {
956                 DEBUG_LOG(UG_NAME_NORMAL, "* STATIC CONFIGURATION *");
957
958                 /* IP Address */
959                 wifi_manager_ap_get_ip_address(ap, WIFI_MANAGER_ADDRESS_FAMILY_IPV4, &txt);
960                 SECURE_DEBUG_LOG(UG_NAME_NORMAL, "* IP address [%s]", txt);
961                 g_free(txt);
962
963                 /* Subnet Mask */
964                 wifi_manager_ap_get_subnet_mask(ap, WIFI_MANAGER_ADDRESS_FAMILY_IPV4, &txt);
965                 SECURE_DEBUG_LOG(UG_NAME_NORMAL, "* Subnet Mask [%s]", txt);
966                 g_free(txt);
967
968                 /* Gateway Address */
969                 wifi_manager_ap_get_gateway_address(ap, WIFI_MANAGER_ADDRESS_FAMILY_IPV4, &txt);
970                 SECURE_DEBUG_LOG(UG_NAME_NORMAL, "* Gateway address [%s]", txt);
971                 g_free(txt);
972
973                 /* DNS 1 */
974                 wifi_manager_ap_get_dns_address(ap, 1, WIFI_MANAGER_ADDRESS_FAMILY_IPV4, &txt);
975                 SECURE_DEBUG_LOG(UG_NAME_NORMAL, "* DNS-1 address [%s]", txt);
976                 g_free(txt);
977
978                 /* DNS 2 */
979                 wifi_manager_ap_get_dns_address(ap, 2, WIFI_MANAGER_ADDRESS_FAMILY_IPV4, &txt);
980                 SECURE_DEBUG_LOG(UG_NAME_NORMAL, "* DNS-2 address [%s]", txt);
981                 g_free(txt);
982
983         } else if (WIFI_MANAGER_IP_CONFIG_TYPE_DYNAMIC == type) {
984                 DEBUG_LOG(UG_NAME_NORMAL, "* DYNAMIC CONFIGURATION *");
985
986                 /* Dynamic IP Address */
987                 wifi_manager_ap_get_ip_address(ap, WIFI_MANAGER_ADDRESS_FAMILY_IPV4, &txt);
988                 SECURE_DEBUG_LOG(UG_NAME_NORMAL, "* IP address [%s]", txt);
989                 g_free(txt);
990         }
991
992         /* Mac address */
993         wifi_get_mac_address(&txt);
994         SECURE_DEBUG_LOG(UG_NAME_NORMAL, "* MAC address [%s]", txt);
995         g_free(txt);
996         txt = NULL;
997
998         wifi_manager_ap_get_proxy_address(ap, WIFI_MANAGER_ADDRESS_FAMILY_IPV4, &txt);
999         assertm_if(NULL == txt, "NULL!!");
1000
1001         if (!txt || !strlen(txt)) {
1002                 if (txt)
1003                         g_free(txt);
1004                 txt = g_strdup(DEFAULT_PROXY_ADDR);
1005         }
1006
1007         /* Proxy Address */
1008         char *save_str = NULL;
1009         char *proxy_addr = strtok_r(txt, ":", &save_str);
1010         SECURE_DEBUG_LOG(UG_NAME_NORMAL, "* PROXY ADDR [%s]", proxy_addr);
1011
1012         /* Proxy port */
1013         char *proxy_port = strtok_r(NULL, ":", &save_str);
1014         SECURE_DEBUG_LOG(UG_NAME_NORMAL, "* PROXY PORT [%s]", proxy_port);
1015         g_free(txt);
1016 }
1017 #endif
1018
1019 #define EMULATOR_MAC_ADDR_SIZE  6
1020 #define EMULATOR_MAC_ADDR_MAX   20
1021 static int ip_info_emulator_get_random_mac(unsigned char *buf)
1022 {
1023         __COMMON_FUNC_ENTER__;
1024
1025         FILE *fp;
1026         int rc;
1027
1028         fp = fopen("/dev/urandom", "rb");
1029         if (fp == NULL) {
1030                 ERROR_LOG(UG_NAME_ERR, "Could not open /dev/urandom");
1031                 return -1;
1032         }
1033
1034         rc = fread(buf, 1, EMULATOR_MAC_ADDR_SIZE, fp);
1035         if (fp)
1036                 fclose(fp);
1037
1038         return rc != EMULATOR_MAC_ADDR_SIZE ? -1 : 0;
1039 }
1040
1041 void ip_info_delete_prev(prev_ip_info_t *prev_ip_info)
1042 {
1043         retm_if(NULL == prev_ip_info);
1044
1045         __COMMON_FUNC_ENTER__;
1046
1047         g_free(prev_ip_info->ip_addr);
1048         g_free(prev_ip_info->subnet_mask);
1049         g_free(prev_ip_info->gateway_addr);
1050         g_free(prev_ip_info->dns_1);
1051         g_free(prev_ip_info->dns_2);
1052         g_free(prev_ip_info->proxy_data);
1053         g_free(prev_ip_info);
1054
1055         __COMMON_FUNC_EXIT__;
1056 }
1057
1058 full_ip_info_t *ip_info_append_items(wifi_manager_ap_h ap, const char *pkg_name,
1059                 Evas_Object *genlist, imf_ctxt_panel_cb_t input_panel_cb, void *input_panel_cb_data)
1060 {
1061         __COMMON_FUNC_ENTER__;
1062         int ret = WIFI_MANAGER_ERROR_NONE;
1063         char *proxy_data = NULL;
1064         char *proxy_addr = NULL;
1065         char *proxy_port = NULL;
1066         Elm_Object_Item* item = NULL;
1067         common_utils_entry_info_t *edit_box_details;
1068         wifi_manager_proxy_type_e proxy_type;
1069         char *ip_addr = NULL;
1070         char *temp = NULL;
1071         char *str2 = NULL;
1072         full_ip_info_t *ip_data = NULL;
1073         assertm_if(NULL == ap, "NULL!!");
1074         assertm_if(NULL == pkg_name, "NULL!!");
1075         assertm_if(NULL == genlist, "NULL!!");
1076
1077         prev_ip_info_t *prev_ip_info = g_try_new0(prev_ip_info_t, 1);
1078         if (prev_ip_info == NULL)
1079                 return NULL;
1080
1081         ip_info_list_t *ip_info_list_data = g_try_new0(ip_info_list_t, 1);
1082         if (ip_info_list_data == NULL) {
1083                 g_free(prev_ip_info);
1084                 prev_ip_info = NULL;
1085
1086                 return NULL;
1087         }
1088
1089         ip_data = g_try_new0(full_ip_info_t, 1);
1090         if (ip_data == NULL) {
1091                 g_free(prev_ip_info);
1092                 g_free(ip_info_list_data);
1093                 prev_ip_info = NULL;
1094                 ip_info_list_data = NULL;
1095                 return NULL;
1096         }
1097
1098         ip_data->ip_info_list = ip_info_list_data;
1099         ip_data->prev_ip_info = prev_ip_info;
1100
1101         ip_info_list_data->ap = ap;
1102         ip_info_list_data->str_pkg_name = pkg_name;
1103         ip_info_list_data->genlist = genlist;
1104         ip_info_list_data->input_panel_cb = input_panel_cb;
1105         ip_info_list_data->input_panel_cb_data = input_panel_cb_data;
1106
1107         ip_toggle_itc = elm_genlist_item_class_new();
1108         ip_toggle_itc->item_style = WIFI_GENLIST_1LINE_TEXT_ICON_STYLE;
1109         ip_toggle_itc->func.text_get = _ip_info_iptoggle_text_get;
1110         ip_toggle_itc->func.content_get = _ip_info_iptoggle_content_get;
1111         ip_toggle_itc->func.state_get = NULL;
1112         ip_toggle_itc->func.del = NULL;
1113
1114         description_itc = elm_genlist_item_class_new();
1115         description_itc->item_style = WIFI_GENLIST_FULL_STYLE;
1116         description_itc->func.text_get = NULL;
1117         description_itc->func.content_get = _ip_info_detail_description_content_get;
1118         description_itc->func.state_get = NULL;
1119         description_itc->func.del = _ip_info_detail_description_del;
1120
1121         ip_entry_itc = elm_genlist_item_class_new();
1122         ip_entry_itc->item_style = WIFI_GENLIST_FULL_STYLE;
1123         ip_entry_itc->func.text_get = NULL;
1124         ip_entry_itc->func.content_get = _ip_info_entry_item_content_get;
1125         ip_entry_itc->func.state_get = NULL;
1126         ip_entry_itc->func.del = _ip_info_entry_item_del;
1127
1128         elm_genlist_mode_set(genlist, ELM_LIST_COMPRESS);
1129
1130         /* Static/Dynamic switch button */
1131         wifi_manager_ip_config_type_e type = WIFI_MANAGER_IP_CONFIG_TYPE_NONE;
1132         ret = wifi_manager_ap_get_ip_config_type(ap, WIFI_MANAGER_ADDRESS_FAMILY_IPV4, &type);
1133         if (ret != WIFI_MANAGER_ERROR_NONE)
1134                 INFO_LOG(UG_NAME_ERR, "Failed to get ip config type! [%d]", ret);
1135
1136         ip_info_list_data->ip_type = type;
1137         ip_info_list_data->ip_toggle_item = elm_genlist_item_append(genlist,
1138                         ip_toggle_itc, ip_data, NULL, ELM_GENLIST_ITEM_NONE,
1139                         __ip_info_toggle_item_sel_cb, ip_data);
1140
1141         prev_ip_info->ip_type = type;
1142
1143         /* IP address */
1144         if (WIFI_MANAGER_IP_CONFIG_TYPE_STATIC == type) {
1145                 ip_data->is_first_create = TRUE;
1146
1147                 /* Create the entry layouts */
1148                 _create_static_ip_table(ip_data);
1149         } else if (WIFI_MANAGER_IP_CONFIG_TYPE_DYNAMIC == type) {
1150                 wifi_manager_ap_get_ip_address(ap, WIFI_MANAGER_ADDRESS_FAMILY_IPV4, &ip_addr);
1151
1152                 prev_ip_info->ip_addr = g_strdup(ip_addr);
1153
1154                 ip_info_list_data->ip_addr_item = _add_description(genlist,
1155                                 "IDS_WIFI_BODY_IP_ADDRESS", ip_addr, NULL);
1156
1157                 g_free(ip_addr);
1158                 ip_addr = NULL;
1159         }
1160
1161         if (_is_emulator()) {
1162                 char rand_addr[EMULATOR_MAC_ADDR_MAX];
1163                 unsigned char rand_mac_add[EMULATOR_MAC_ADDR_SIZE + 1];
1164                 if (ip_info_emulator_get_random_mac(rand_mac_add) == -1) {
1165                         ERROR_LOG(UG_NAME_ERR, "Failed to get random mac address");
1166                         return NULL;
1167                 }
1168
1169                 rand_mac_add[0] &= 0xFE;
1170                 rand_mac_add[0] |= 0x02;
1171
1172                 snprintf(rand_addr, EMULATOR_MAC_ADDR_MAX, "%x:%x:%x:%x:%x:%x",
1173                                 rand_mac_add[0], rand_mac_add[1],
1174                                 rand_mac_add[2], rand_mac_add[3],
1175                                 rand_mac_add[4], rand_mac_add[5]);
1176                 item = _add_description(genlist,
1177                                 "IDS_WIFI_BODY_MAC_ADDRESS", rand_addr, NULL);
1178                 ip_info_list_data->mac_addr_item = item;
1179         } else {
1180                 char *mac_addr = NULL;
1181                 /* Mac address */
1182                 ret = wifi_manager_ap_get_bssid(ap, &mac_addr);
1183                 if (ret != WIFI_MANAGER_ERROR_NONE)
1184                         INFO_LOG(UG_NAME_ERR, "Failed to get bssid! [%d]", ret);
1185
1186                 item = _add_description(genlist,
1187                                 "IDS_WIFI_BODY_MAC_ADDRESS", mac_addr, NULL);
1188                 ip_info_list_data->mac_addr_item = item;
1189
1190                 g_free(mac_addr);
1191                 mac_addr = NULL;
1192         }
1193
1194         ret = wifi_manager_ap_get_proxy_type(ap, &proxy_type);
1195         assertm_if(WIFI_MANAGER_ERROR_NONE != ret, "NULL!!");
1196         prev_ip_info->proxy_type = proxy_type;
1197
1198         ret = wifi_manager_ap_get_proxy_address(ap, WIFI_MANAGER_ADDRESS_FAMILY_IPV4, &proxy_data);
1199         assertm_if(NULL == proxy_data, "NULL!!");
1200
1201         if (WIFI_MANAGER_ERROR_NONE == ret && proxy_data && strlen(proxy_data)) {
1202                 temp = g_strdup(proxy_data);
1203                 if (temp != NULL) {
1204                         /*Proxy Port*/
1205                         str2 = strrchr(temp, ':');
1206                         if (str2 != NULL) {
1207                                 proxy_port = g_strdup(str2 + 1);
1208                                 *str2 = '\0';
1209                         }
1210
1211                         /*Proxy Address*/
1212                         proxy_addr = g_strdup(temp);
1213
1214                         g_free(temp);
1215                         temp = NULL;
1216                 }
1217
1218                 prev_ip_info->proxy_data = g_strdup(proxy_data);
1219         } else {
1220                 ERROR_LOG(UG_NAME_ERR, "Error = %d", ret);
1221         }
1222
1223         edit_box_details = g_new0(common_utils_entry_info_t, 1);
1224         edit_box_details->str_pkg_name = pkg_name;
1225         edit_box_details->entry_id = ENTRY_TYPE_PROXY_ADDR;
1226         edit_box_details->title_txt = "IDS_ST_SBODY_PROXY_ADDRESS";
1227         edit_box_details->entry_txt = proxy_addr;
1228         edit_box_details->guide_txt = DEFAULT_GUIDE_PROXY_IP;
1229         edit_box_details->input_panel_cb = input_panel_cb;
1230         edit_box_details->input_panel_cb_data = input_panel_cb_data;
1231         edit_box_details->item = elm_genlist_item_append(genlist, ip_entry_itc,
1232                         edit_box_details, NULL, ELM_GENLIST_ITEM_NONE,
1233                         _gl_editbox_sel_cb, NULL);
1234 #ifdef ACCESSIBLITY_FEATURE
1235         Evas_Object *ao = elm_object_item_access_object_get(edit_box_details->item);
1236         elm_access_info_cb_set(ao, ELM_ACCESS_INFO, _access_info_cb, edit_box_details);
1237 #endif
1238         ip_info_list_data->proxy_addr_item = edit_box_details->item;
1239
1240         edit_box_details = g_new0(common_utils_entry_info_t, 1);
1241         edit_box_details->str_pkg_name = pkg_name;
1242         edit_box_details->entry_id = ENTRY_TYPE_PROXY_PORT;
1243         edit_box_details->title_txt = "IDS_ST_SBODY_PROXY_PORT";
1244         edit_box_details->entry_txt = proxy_port;
1245         edit_box_details->guide_txt = DEFAULT_GUIDE_PROXY_PORT;
1246         edit_box_details->input_panel_cb = input_panel_cb;
1247         edit_box_details->input_panel_cb_data = input_panel_cb_data;
1248         edit_box_details->item = elm_genlist_item_append(genlist, ip_entry_itc,
1249                         edit_box_details, NULL, ELM_GENLIST_ITEM_NONE,
1250                         _gl_editbox_sel_cb, NULL);
1251 #ifdef ACCESSIBLITY_FEATURE
1252         ao = elm_object_item_access_object_get(edit_box_details->item);
1253         elm_access_info_cb_set(ao, ELM_ACCESS_INFO, _access_info_cb, edit_box_details);
1254 #endif
1255         ip_info_list_data->proxy_port_item = edit_box_details->item;
1256
1257         g_free(proxy_data);
1258         proxy_data = NULL;
1259
1260         __COMMON_FUNC_EXIT__;
1261         return ip_data;
1262 }
1263
1264 static char* get_ip_info_text(entry_id_type_t e)
1265 {
1266         if (ip_info_text_list[e] != NULL)
1267                 return ip_info_text_list[e];
1268
1269         return NULL;
1270 }
1271
1272 static void free_ip_info_text(entry_id_type_t e)
1273 {
1274         g_free(ip_info_text_list[e]);
1275         ip_info_text_list[e] = NULL;
1276 }
1277
1278 void ip_info_save_data(full_ip_info_t *ip_data)
1279 {
1280         __COMMON_FUNC_ENTER__;
1281         retm_if(ip_data == NULL);
1282         ip_info_list_t *ip_info_list_data = ip_data->ip_info_list;
1283         prev_ip_info_t *prev_ip_info = ip_data->prev_ip_info;
1284         retm_if(NULL == ip_info_list_data || NULL == prev_ip_info);
1285
1286         char* txt = NULL;
1287         char* proxy_addr = NULL;
1288         char* proxy_port = NULL;
1289         wifi_manager_ap_h ap = ip_info_list_data->ap;
1290         int ret = WIFI_MANAGER_ERROR_NONE;
1291         ip_data->is_info_changed = FALSE;
1292
1293         if (prev_ip_info->ip_type != ip_info_list_data->ip_type) {
1294                 if (WIFI_MANAGER_IP_CONFIG_TYPE_DYNAMIC == ip_info_list_data->ip_type) {
1295                         /* Reset the DNS addresses if dynamic */
1296                         ret = wifi_manager_ap_set_dns_address(ap, 1,
1297                                         WIFI_MANAGER_ADDRESS_FAMILY_IPV4, DEFAULT_GUIDE_IP);
1298                         if (ret == WIFI_MANAGER_ERROR_NONE)
1299                                 ip_data->is_info_changed = TRUE;
1300
1301                         ret = wifi_manager_ap_set_dns_address(ap, 2,
1302                                         WIFI_MANAGER_ADDRESS_FAMILY_IPV4, DEFAULT_GUIDE_IP);
1303                         if (ret == WIFI_MANAGER_ERROR_NONE)
1304                                 ip_data->is_info_changed = TRUE;
1305                         ip_info_list_data->dns_type = WIFI_MANAGER_DNS_CONFIG_TYPE_DYNAMIC;
1306
1307                 } else if (WIFI_MANAGER_IP_CONFIG_TYPE_STATIC == ip_info_list_data->ip_type) {
1308                         ip_info_list_data->dns_type = WIFI_MANAGER_DNS_CONFIG_TYPE_STATIC;
1309                 }
1310
1311                 ret = wifi_manager_ap_set_ip_config_type(ap, WIFI_MANAGER_ADDRESS_FAMILY_IPV4,
1312                                 ip_info_list_data->ip_type);
1313                 retm_if(WIFI_MANAGER_ERROR_NONE != ret);
1314
1315                 ret = wifi_manager_ap_set_dns_config_type(ap, WIFI_MANAGER_ADDRESS_FAMILY_IPV4,
1316                                 ip_info_list_data->dns_type);
1317                 retm_if(WIFI_MANAGER_ERROR_NONE != ret);
1318
1319                 ip_data->is_info_changed = TRUE;
1320         }
1321
1322         if (WIFI_MANAGER_IP_CONFIG_TYPE_STATIC == ip_info_list_data->ip_type) {
1323                 txt = g_strdup(get_ip_info_text(ENTRY_TYPE_IP_ADDR));
1324                 if (!txt)
1325                         txt = g_strdup(DEFAULT_GUIDE_IP);
1326                 if (g_strcmp0(prev_ip_info->ip_addr, txt) != 0) {
1327                         ret = wifi_manager_ap_set_ip_address(ap,
1328                                         WIFI_MANAGER_ADDRESS_FAMILY_IPV4, txt);
1329
1330                         if (ret == WIFI_MANAGER_ERROR_NONE)
1331                                 ip_data->is_info_changed = TRUE;
1332                 }
1333                 free_ip_info_text(ENTRY_TYPE_IP_ADDR);
1334                 g_free(txt);
1335
1336                 txt = g_strdup(get_ip_info_text(ENTRY_TYPE_SUBNET_MASK));
1337                 if (!txt)
1338                         txt = g_strdup(DEFAULT_GUIDE_IP);
1339                 if (g_strcmp0(prev_ip_info->subnet_mask, txt) != 0) {
1340                         ret = wifi_manager_ap_set_subnet_mask(ap,
1341                                         WIFI_MANAGER_ADDRESS_FAMILY_IPV4, txt);
1342
1343                         if (ret == WIFI_MANAGER_ERROR_NONE)
1344                                 ip_data->is_info_changed = TRUE;
1345                 }
1346                 free_ip_info_text(ENTRY_TYPE_SUBNET_MASK);
1347                 g_free(txt);
1348
1349                 txt = g_strdup(get_ip_info_text(ENTRY_TYPE_GATEWAY));
1350                 if (!txt)
1351                         txt = g_strdup(DEFAULT_GUIDE_IP);
1352                 if (g_strcmp0(prev_ip_info->gateway_addr, txt) != 0) {
1353                         ret = wifi_manager_ap_set_gateway_address(ap,
1354                                         WIFI_MANAGER_ADDRESS_FAMILY_IPV4, txt);
1355
1356                         if (ret == WIFI_MANAGER_ERROR_NONE)
1357                                 ip_data->is_info_changed = TRUE;
1358                 }
1359                 free_ip_info_text(ENTRY_TYPE_GATEWAY);
1360                 g_free(txt);
1361
1362                 txt = g_strdup(get_ip_info_text(ENTRY_TYPE_DNS_1));
1363                 if (!txt)
1364                         txt = g_strdup(DEFAULT_GUIDE_IP);
1365                 if (g_strcmp0(prev_ip_info->dns_1, txt) != 0) {
1366                         ret = wifi_manager_ap_set_dns_address(ap, 1,
1367                                         WIFI_MANAGER_ADDRESS_FAMILY_IPV4, txt);
1368
1369                         if (ret == WIFI_MANAGER_ERROR_NONE)
1370                                 ip_data->is_info_changed = TRUE;
1371                 }
1372                 free_ip_info_text(ENTRY_TYPE_DNS_1);
1373                 g_free(txt);
1374
1375                 txt = g_strdup(get_ip_info_text(ENTRY_TYPE_DNS_2));
1376                 if (!txt)
1377                         txt = g_strdup(DEFAULT_GUIDE_IP);
1378                 if (g_strcmp0(prev_ip_info->dns_2, txt) != 0) {
1379                         ret = wifi_manager_ap_set_dns_address(ap, 2,
1380                                         WIFI_MANAGER_ADDRESS_FAMILY_IPV4, txt);
1381
1382                         if (ret == WIFI_MANAGER_ERROR_NONE)
1383                                 ip_data->is_info_changed = TRUE;
1384                 }
1385                 free_ip_info_text(ENTRY_TYPE_DNS_2);
1386                 g_free(txt);
1387         }
1388
1389         proxy_addr = g_strdup(get_ip_info_text(ENTRY_TYPE_PROXY_ADDR));
1390         if (proxy_addr == NULL) {
1391                 DEBUG_LOG(UG_NAME_NORMAL, "Set proxy type - auto");
1392                 if (prev_ip_info->proxy_type != WIFI_MANAGER_PROXY_TYPE_AUTO)
1393                         wifi_manager_ap_set_proxy_type(ap, WIFI_MANAGER_PROXY_TYPE_AUTO);
1394         } else {
1395                 proxy_port = g_strdup(get_ip_info_text(ENTRY_TYPE_PROXY_PORT));
1396                 if (proxy_port)
1397                         txt = g_strdup_printf("%s:%s", proxy_addr, proxy_port);
1398                 else
1399                         txt = g_strdup_printf("%s:%s", proxy_addr, DEFAULT_GUIDE_PROXY_PORT);
1400
1401                 DEBUG_LOG(UG_NAME_NORMAL, "Set proxy type - manual : %s", txt);
1402                 if (prev_ip_info->proxy_type != WIFI_MANAGER_PROXY_TYPE_MANUAL)
1403                         wifi_manager_ap_set_proxy_type(ap, WIFI_MANAGER_PROXY_TYPE_MANUAL);
1404
1405                 if (g_strcmp0(prev_ip_info->proxy_data, txt) != 0)
1406                         wifi_manager_ap_set_proxy_address(ap, WIFI_MANAGER_ADDRESS_FAMILY_IPV4, txt);
1407
1408                 free_ip_info_text(ENTRY_TYPE_PROXY_ADDR);
1409                 free_ip_info_text(ENTRY_TYPE_PROXY_PORT);
1410                 g_free(proxy_port);
1411                 proxy_port = NULL;
1412                 g_free(txt);
1413         }
1414         txt = NULL;
1415
1416         g_free(proxy_addr);
1417         proxy_addr = NULL;
1418
1419         /* ip_info_print_values(ap); */
1420
1421         __COMMON_FUNC_EXIT__;
1422 }
1423
1424 void ip_info_remove(ip_info_list_t *ip_info_list)
1425 {
1426         __COMMON_FUNC_ENTER__;
1427
1428         if (ip_info_list)
1429                 g_free(ip_info_list);
1430
1431         __COMMON_FUNC_EXIT__;
1432 }
1433
1434 void ip_info_close_all_keypads(ip_info_list_t *ip_info_list)
1435 {
1436         __COMMON_FUNC_ENTER__;
1437
1438         if (!ip_info_list) {
1439                 __COMMON_FUNC_EXIT__;
1440                 return;
1441         }
1442
1443         if (WIFI_MANAGER_IP_CONFIG_TYPE_STATIC == ip_info_list->ip_type) {
1444                 if (ip_info_list->ip_addr_item)
1445                         common_utils_edit_box_focus_set(ip_info_list->ip_addr_item, EINA_FALSE);
1446                 if (ip_info_list->subnet_mask_item)
1447                         common_utils_edit_box_focus_set(ip_info_list->subnet_mask_item, EINA_FALSE);
1448                 if (ip_info_list->gateway_addr_item)
1449                         common_utils_edit_box_focus_set(ip_info_list->gateway_addr_item, EINA_FALSE);
1450                 if (ip_info_list->dns_1_item)
1451                         common_utils_edit_box_focus_set(ip_info_list->dns_1_item, EINA_FALSE);
1452                 if (ip_info_list->dns_2_item)
1453                         common_utils_edit_box_focus_set(ip_info_list->dns_2_item, EINA_FALSE);
1454                 if (ip_info_list->proxy_addr_item)
1455                         common_utils_edit_box_focus_set(ip_info_list->proxy_addr_item, EINA_FALSE);
1456                 if (ip_info_list->proxy_port_item)
1457                         common_utils_edit_box_focus_set(ip_info_list->proxy_port_item, EINA_FALSE);
1458         }
1459         __COMMON_FUNC_EXIT__;
1460 }
1461
1462 void ip_info_enable_all_keypads(ip_info_list_t *ip_info_list)
1463 {
1464         __COMMON_FUNC_ENTER__;
1465
1466         if (!ip_info_list) {
1467                 __COMMON_FUNC_EXIT__;
1468                 return;
1469         }
1470
1471         if (WIFI_MANAGER_IP_CONFIG_TYPE_STATIC == ip_info_list->ip_type) {
1472                 if (ip_info_list->ip_addr_item)
1473                         common_utils_edit_box_allow_focus_set(ip_info_list->ip_addr_item, EINA_TRUE);
1474                 if (ip_info_list->subnet_mask_item)
1475                         common_utils_edit_box_allow_focus_set(ip_info_list->subnet_mask_item, EINA_TRUE);
1476                 if (ip_info_list->gateway_addr_item)
1477                         common_utils_edit_box_allow_focus_set(ip_info_list->gateway_addr_item, EINA_TRUE);
1478                 if (ip_info_list->dns_1_item)
1479                         common_utils_edit_box_allow_focus_set(ip_info_list->dns_1_item, EINA_TRUE);
1480                 if (ip_info_list->dns_2_item)
1481                         common_utils_edit_box_allow_focus_set(ip_info_list->dns_2_item, EINA_TRUE);
1482                 if (ip_info_list->proxy_addr_item)
1483                         common_utils_edit_box_allow_focus_set(ip_info_list->proxy_addr_item, EINA_TRUE);
1484                 if (ip_info_list->proxy_port_item)
1485                         common_utils_edit_box_allow_focus_set(ip_info_list->proxy_port_item, EINA_TRUE);
1486         }
1487         __COMMON_FUNC_EXIT__;
1488 }