Fix bugs which are reported by static analyzer
[apps/native/ug-wifi-direct.git] / ug-wifidirect / include / wfd_ug.h
1 /*
2 *  WiFi-Direct UG
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
21 #ifndef __WFD_UG_H__
22 #define __WFD_UG_H__
23
24 #include <dlog.h>
25 #include <notification.h>
26 #include <ui-gadget-module.h>
27
28 #include <tethering.h>
29
30 #include <wifi-direct.h>
31 #include <wifi-direct-internal.h>
32
33 #include <glib-object.h>
34 #include <gio/gio.h>
35 #include <glib.h>
36 #include <assert.h>
37
38 #define PACKAGE "ug-setting-wifidirect-efl"
39 #define LOCALEDIR "/usr/ug/res/locale"
40
41 #define DIRECT_TAG  "wfd_ug"
42 /* TODO:: To change the log level as LOG_INFO */
43 #define DBG(log_level, format, args...) \
44         LOG(LOG_ERROR, DIRECT_TAG, "[%s()][%d] " format, __FUNCTION__, __LINE__, ##args)
45 #define DBG_SECURE(log_level, format, args...) \
46         SECURE_LOG(LOG_ERROR, DIRECT_TAG, "[%s()][%d] " format, __FUNCTION__, __LINE__, ##args)
47
48 #define MAC2SECSTR(a) (a)[0], (a)[4], (a)[5]
49 #define MACSECSTR "%02x:%02x:%02x"
50 #if 0
51 #define IP2SECSTR(a) (a)[0], (a)[3]
52 #define IPSECSTR "%d..%d"
53 #endif
54
55 #define __FUNC_ENTER__  DBG(LOG_INFO, "+\n")
56 #define __FUNC_EXIT__   DBG(LOG_INFO, "-\n")
57 #if 0
58 #define __FUNC_ENTER__
59 #define __FUNC_EXIT__
60 #endif
61
62 #define VCONF_WFD_APNAME                        "db/setting/device_name"
63
64 #define MAX_HEX_COLOR_LENGTH 255
65
66 #define assertm_if(expr, fmt, arg...) do { \
67         if (expr) { \
68           DBG(LOG_VERBOSE, " ##(%s) -> %s() assert!!## "fmt, #expr, __FUNCTION__, ##arg); \
69                  assert(1); \
70         } \
71 } while (0)
72
73 #define WFD_IF_DEL_OBJ(obj) \
74                 do { \
75                         if (obj) { \
76                                 evas_object_del(obj); \
77                                 obj = NULL; \
78                         } \
79                 } while (0)
80
81 #define WFD_IF_DEL_ITEM(obj) \
82                 do { \
83                         if (obj) { \
84                                 elm_object_item_del(obj); \
85                                 obj = NULL; \
86                         } \
87                 } while (0)
88
89 #define WFD_RET_IF(expr, fmt, args...) \
90                 do { \
91                         if (expr) { \
92                                 DBG(LOG_ERROR, "[%s] Return, message "fmt, #expr, ##args);\
93                                 return; \
94                         } \
95                 } while (0)
96
97 #define WFD_RETV_IF(expr, val, fmt, args...) \
98                 do { \
99                         if (expr) { \
100                                 DBG(LOG_ERROR, "[%s] Return value, message "fmt, #expr, ##args);\
101                                 return (val); \
102                         } \
103                 } while (0)
104
105 #define WFD_IF_FREE_MEM(mem) \
106                 do { \
107                         g_free(mem); \
108                         mem = NULL; \
109                 } while (0)
110
111 #define AP_NAME_LENGTH_MAX              32
112 #define AP_PASSWORD_LENGTH_MAX  64
113 #define AP_PASSWORD_LENGTH_MIN  8
114 #define AP_REJECT_CHAR_LIST             "=,"
115
116 #define DEFAULT_DEV_NAME        "ZEQ"
117 #define MAC_LENGTH  18
118 #define SSID_LENGTH 32
119 #define MAX_CONNECTED_PEER_NUM 7
120 #define MAX_PEER_NUM 10
121 #define MAX_POPUP_TEXT_SIZE 512
122 #define MAX_DISPLAY_TIME_OUT 3
123 #define MAX_NO_ACTION_TIME_OUT  300            /*5min*/
124 #define MAX_SCAN_TIME_OUT 0
125
126 #define GENLIST_HEADER_POS 1
127 #define SR_CHECKBOX_ON_MSG "on/off button on"
128 #define SR_CHECKBOX_OFF_MSG "on/off button off"
129 #define SR_BUTTON_MSG "multiple connect button"
130
131 #define D_(s)        dgettext(PACKAGE, s)
132 #define N_(s)      dgettext_noop(s)
133 #define S_(s)      dgettext("sys_string", s)
134
135 #define WFD_GLOBALIZATION_STR_LENGTH 256
136
137 typedef enum {
138         WFD_MULTI_CONNECT_MODE_NONE,
139         WFD_MULTI_CONNECT_MODE_IN_PROGRESS,
140         WFD_MULTI_CONNECT_MODE_COMPLETED,
141 } wfd_multi_connect_mode_e;
142
143 typedef enum {
144         PEER_CONN_STATUS_DISCONNECTED,
145         PEER_CONN_STATUS_DISCONNECTING,
146         PEER_CONN_STATUS_CONNECTING = PEER_CONN_STATUS_DISCONNECTING,
147         PEER_CONN_STATUS_CONNECTED,
148         PEER_CONN_STATUS_FAILED_TO_CONNECT,
149         PEER_CONN_STATUS_WAIT_FOR_CONNECT,
150 } conn_status_e;
151
152 typedef enum {
153         WIFI_DIRECT_DISCOVERY_NONE,
154         WIFI_DIRECT_DISCOVERY_SOCIAL_CHANNEL_START,
155         WIFI_DIRECT_DISCOVERY_FULL_SCAN_START,
156         WIFI_DIRECT_DISCOVERY_STOPPED,
157         WIFI_DIRECT_DISCOVERY_BACKGROUND,
158 } discovery_status_e;
159
160
161 typedef struct device_type_s_ {
162         char ssid[SSID_LENGTH + 1];
163         unsigned int category;
164         unsigned int sub_category;
165         char mac_addr[MAC_LENGTH];
166         char if_addr[MAC_LENGTH];
167         conn_status_e conn_status;
168         bool is_group_owner;  /** Is an active P2P Group Owner */
169         bool is_persistent_group_owner;  /** Is a stored Persistent GO */
170         bool is_connected;  /** Is peer connected*/
171         bool is_alive;
172         bool dev_sel_state;
173         Elm_Object_Item *gl_item;
174         struct device_type_s_ *next;
175 } device_type_s;
176
177 struct ug_data {
178         Evas_Object *base;
179         ui_gadget_h ug;
180
181         Evas_Object *win;
182         Evas_Object *bg;
183         Evas_Object *layout;
184         Evas_Object *button_layout;
185         Evas_Object *naviframe;
186         Elm_Object_Item *navi_item;
187         Elm_Object_Item *multi_navi_item;
188         Elm_Object_Item *head;
189         Evas_Object *genlist;
190         Evas_Object *multiconn_view_genlist;
191         Evas_Object *multiconn_layout;
192         Evas_Object *popup;
193         Evas_Object *act_popup;
194         Evas_Object *warn_popup;
195         Evas_Object *rename_popup;
196         Evas_Object *ctxpopup;
197         Evas_Object *scan_btn;
198         Evas_Object *disconnect_btn;
199         Evas_Object *toolbar;
200         Evas_Object *rename_entry;
201         Evas_Object *rename_button;
202
203 #ifdef WFD_ON_OFF_GENLIST
204         Evas_Object *on_off_check;
205 #endif
206
207         Evas_Object *scan_toolbar;
208         Evas_Object *multiconn_scan_stop_btn;
209         Evas_Object *multiconn_conn_btn;
210         Evas_Object *select_all_icon;
211
212
213
214         Elm_Object_Item *multi_connect_toolbar_item;
215         Elm_Object_Item *multi_view_connect_toolbar_item;
216
217         Elm_Object_Item *select_all_view_genlist;
218 #ifdef WFD_ON_OFF_GENLIST
219         Elm_Object_Item *item_wifi_onoff;
220 #endif
221         Elm_Object_Item *device_name_item;
222         Elm_Genlist_Item_Class *rename_entry_itc;
223         Elm_Genlist_Item_Class *rename_desc_itc;
224         Elm_Object_Item *multi_connect_sep_item;
225
226         Elm_Object_Item *nodevice_title_item;
227         Elm_Object_Item *nodevice_item;
228
229         Elm_Object_Item *conn_wfd_item;
230         Elm_Object_Item *conn_failed_wfd_item;
231         Elm_Object_Item *avlbl_wfd_item;
232         Elm_Object_Item *busy_wfd_item;
233         Elm_Object_Item *multi_connect_wfd_item;
234
235         Elm_Object_Item *mcview_title_item;
236         Elm_Object_Item *mcview_nodevice_item;
237         Elm_Object_Item *more_btn_multiconnect_item;
238
239         Evas_Object *back_btn;
240
241         // Notify
242         Evas_Object *notify;
243         Evas_Object *notify_layout;
244
245         int head_text_mode;
246
247         char *mac_addr_connecting;
248         char *mac_addr_req;
249
250         //Connection is incoming or not
251         bool is_conn_incoming;
252
253
254         // title mode of device list
255         int title_content_mode;
256
257         // Raw peer data
258         device_type_s raw_connected_peers[MAX_CONNECTED_PEER_NUM];
259         int raw_connected_peer_cnt;
260         GList *raw_discovered_peer_list;
261         int raw_discovered_peer_cnt;
262
263         // Peer data in the Genlist
264         int gl_connected_peer_cnt;
265         device_type_s *gl_conn_peers_start;
266
267         int gl_connected_failed_peer_cnt;
268         device_type_s *gl_failed_peers_start;
269
270         int gl_available_peer_cnt;
271         device_type_s *gl_avlb_peers_start;
272
273         int gl_busy_peer_cnt;
274         device_type_s *gl_busy_peers_start;
275
276         device_type_s raw_multi_selected_peers[MAX_PEER_NUM];
277         int raw_multi_selected_peer_cnt;
278
279         int gl_multi_connect_peer_cnt;
280         device_type_s *gl_mul_conn_peers_start;
281
282         // My status
283         bool I_am_group_owner;
284         bool I_am_connected;
285
286         // Following variables are used at the Multi connect view.
287         wfd_multi_connect_mode_e multi_connect_mode;
288         device_type_s *multi_conn_dev_list_start;
289         int gl_available_dev_cnt_at_multiconn_view;
290         int g_source_multi_connect_next;
291
292 #ifdef WFD_ON_OFF_GENLIST
293         int wfd_onoff;
294 #endif
295         wifi_direct_state_e wfd_status;
296         char *dev_name;
297         char *dev_pass;
298
299         // For connect failed peers
300         int last_display_time;
301         Ecore_Timer *display_timer;
302
303         // Tethering
304         bool is_hotspot_off;
305         bool is_hotspot_locally_disabled;
306         tethering_h hotspot_handle;
307
308         // wfds service
309         char *wfds;
310
311         // Device filter
312         int device_filter;
313
314         // Whether support auto exit after successed connection
315         bool is_auto_exit;
316
317         //Whether support multi connection
318         bool is_multi_connect;
319         bool is_select_all_checked;
320
321         //view type for search
322         char *view_type;
323
324         //Title of UG
325         char *title;
326
327         // The ip address of connected peer
328         char *peer_ip_address;
329
330         // The service name that supported WFDSP
331         char *service_name;
332
333         // Whether initialize wfd-namager ok
334         bool is_init_ok;
335
336         //timer for deleting progress bar
337         int timer_stop_progress_bar;
338
339         //timer for multi connect reset
340         int timer_multi_reset;
341
342         //if all the items are selected or not
343         bool is_multi_check_all_selected;
344
345         //timer for remove not alive peer
346         int timer_delete_not_alive_peer;
347
348         //wifi direct discovery status
349         int wfd_discovery_status;
350
351         bool is_paused;
352 };
353
354 extern Elm_Gen_Item_Class device_name_title_itc;
355 #ifdef WFD_ON_OFF_GENLIST
356 extern Elm_Gen_Item_Class wfd_onoff_itc;
357 #endif
358 extern Elm_Gen_Item_Class device_name_itc;
359 extern Elm_Gen_Item_Class title_itc;
360 extern Elm_Gen_Item_Class multi_view_title_itc;
361 extern Elm_Gen_Item_Class peer_itc;
362 extern Elm_Gen_Item_Class title_no_device_itc;
363 extern Elm_Gen_Item_Class noitem_itc;
364 extern Elm_Gen_Item_Class title_available_itc;
365
366 extern Elm_Gen_Item_Class title_conn_itc;
367 extern Elm_Gen_Item_Class peer_conn_itc;
368
369 extern Elm_Gen_Item_Class title_busy_itc;
370 extern Elm_Gen_Item_Class peer_busy_itc;
371
372 extern Elm_Gen_Item_Class title_multi_connect_itc;
373 extern Elm_Gen_Item_Class peer_multi_connect_itc;
374 extern Elm_Gen_Item_Class select_all_multi_connect_itc;
375
376 extern Elm_Gen_Item_Class title_conn_failed_itc;
377 extern Elm_Gen_Item_Class peer_conn_failed_itc;
378
379 /**
380  *      This function let the ug destroy the ug
381  *      @return   void
382  *      @param[in] data the pointer to the main data structure
383  */
384 void wfd_destroy_ug(void *data);
385
386 /**
387  *      This function is called when ON/OFF button is turned ON/OFF
388  *      @return   void
389  *      @param[in] data the pointer to the main data structure
390  *      @param[in] object
391  *      @param[in] event
392  */
393 void _onoff_changed_cb(void *data, Evas_Object *obj, void *event_info);
394 void toolbar_language_changed(void *data, Evas_Object *obj, void *event_info);
395 void ctxpopup_dismissed_cb(void *data, Evas_Object *obj, void *event_info);
396 void wfd_free_nodivice_item(struct ug_data *ugd);
397 void discover_cb(int error_code, wifi_direct_discovery_state_e discovery_state, void *user_data);
398
399
400 #endif  /* __WFD_UG_H__ */