summaryrefslogtreecommitdiff
path: root/ug-wifidirect/include/wfd_ug.h
blob: 306d1788650d13fc46654fe1941bcb00098d036f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
/*
*  WiFi-Direct UG
*
* Copyright 2012  Samsung Electronics Co., Ltd

* Licensed under the Flora License, Version 1.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at

* http://www.tizenopensource.org/license

* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/


#ifndef __WFD_UG_H__
#define __WFD_UG_H__

#include <dlog.h>
#include <notification.h>
#include <ui-gadget-module.h>

#include <tethering.h>

#include <wifi-direct.h>
#include <efl-assist/efl_assist.h>

#include <glib-object.h>
#include <gio/gio.h>
#include <glib.h>
#include <assert.h>

#define PACKAGE "ug-setting-wifidirect-efl"
#define LOCALEDIR "/usr/share/locale"
#define COLOR_TABLE "/usr/apps/setting-wifidirect-efl/shared/res/tables/setting-wifidirect-efl_ChangeableColorTable.xml"
#define FONT_TABLE "/usr/apps/setting-wifidirect-efl/shared/res/tables/setting-wifidirect-efl_FontInfoTable.xml"

#define DIRECT_TAG  "wfd_ug"
/* TODO:: To change the log level as LOG_INFO */
#define DBG(log_level, format, args...) \
	LOG(LOG_ERROR, DIRECT_TAG, "[%s()][%d] " format, __FUNCTION__, __LINE__, ##args)
#define DBG_SECURE(log_level, format, args...) \
	SECURE_LOG(LOG_ERROR, DIRECT_TAG, "[%s()][%d] " format, __FUNCTION__, __LINE__, ##args)

#define MAC2SECSTR(a) (a)[0], (a)[4], (a)[5]
#define MACSECSTR "%02x:%02x:%02x"
#if 0
#define IP2SECSTR(a) (a)[0], (a)[3]
#define IPSECSTR "%d..%d"
#endif

#define __FUNC_ENTER__  DBG(LOG_INFO, "+\n")
#define __FUNC_EXIT__   DBG(LOG_INFO, "-\n")
#if 0
#define __FUNC_ENTER__
#define __FUNC_EXIT__
#endif

#define VCONF_WFD_APNAME			"db/setting/device_name"

#define assertm_if(expr, fmt, arg...) do { \
	if (expr) { \
	  DBG(LOG_VERBOSE, " ##(%s) -> %s() assert!!## "fmt, #expr, __FUNCTION__, ##arg); \
		 assert(1); \
	} \
} while (0)

#define WFD_IF_DEL_OBJ(obj) \
		do { \
			if(obj) { \
				evas_object_del(obj); \
				obj = NULL; \
			} \
		} while (0)

#define WFD_IF_DEL_ITEM(obj) \
		do { \
			if(obj) { \
				elm_object_item_del(obj); \
				obj = NULL; \
			} \
		} while (0)

#define WFD_RET_IF(expr, fmt, args...) \
		do { \
			if(expr) { \
				DBG(LOG_ERROR, "[%s] Return, message "fmt, #expr, ##args );\
				return; \
			} \
		} while (0)

#define WFD_RETV_IF(expr, val, fmt, args...) \
		do { \
			if(expr) { \
				DBG(LOG_ERROR,"[%s] Return value, message "fmt, #expr, ##args );\
				return (val); \
			} \
		} while (0)

#define WFD_IF_FREE_MEM(mem) \
		do { \
			if(mem) { \
				free(mem); \
				mem = NULL; \
			} \
		} while (0)

#define AP_NAME_LENGTH_MAX		32
#define AP_PASSWORD_LENGTH_MAX	64
#define AP_PASSWORD_LENGTH_MIN	8
#define AP_REJECT_CHAR_LIST		"=,"

#define DEFAULT_DEV_NAME        "ZEQ"
#define MAC_LENGTH  18
#define SSID_LENGTH 32
#define MAX_CONNECTED_PEER_NUM 7
#define MAX_PEER_NUM 10
#define MAX_POPUP_TEXT_SIZE 256
#define MAX_DISPLAY_TIME_OUT 3
#define MAX_NO_ACTION_TIME_OUT	300            /*5min*/
#define MAX_SCAN_TIME_OUT 0

#define GENLIST_HEADER_POS 1
#define SR_CHECKBOX_ON_MSG "on/off button on"
#define SR_CHECKBOX_OFF_MSG "on/off button off"
#define SR_BUTTON_MSG "multiple connect button"

#define _(s)        dgettext(PACKAGE, s)
#define N_(s)      dgettext_noop(s)
#define S_(s)      dgettext("sys_string", s)

#define WFD_GLOBALIZATION_STR_LENGTH 256

typedef enum {
	WFD_MULTI_CONNECT_MODE_NONE,
	WFD_MULTI_CONNECT_MODE_IN_PROGRESS,
	WFD_MULTI_CONNECT_MODE_COMPLETED,
} wfd_multi_connect_mode_e;

typedef enum {
	PEER_CONN_STATUS_DISCONNECTED,
	PEER_CONN_STATUS_DISCONNECTING,
	PEER_CONN_STATUS_CONNECTING = PEER_CONN_STATUS_DISCONNECTING,
	PEER_CONN_STATUS_CONNECTED,
	PEER_CONN_STATUS_FAILED_TO_CONNECT,
	PEER_CONN_STATUS_WAIT_FOR_CONNECT,
} conn_status_e;

typedef enum {
	WIFI_DIRECT_DISCOVERY_NONE,
	WIFI_DIRECT_DISCOVERY_SOCIAL_CHANNEL_START,
	WIFI_DIRECT_DISCOVERY_FULL_SCAN_START,
	WIFI_DIRECT_DISCOVERY_STOPPED,
	WIFI_DIRECT_DISCOVERY_BACKGROUND,
} discovery_status_e;


typedef struct device_type_s_{
	char ssid[SSID_LENGTH];
	unsigned int category;
	unsigned int sub_category;
	char mac_addr[MAC_LENGTH];
	char if_addr[MAC_LENGTH];
	conn_status_e conn_status;
	bool is_group_owner;  /** Is an active P2P Group Owner */
	bool is_persistent_group_owner;  /** Is a stored Persistent GO */
	bool is_connected;  /** Is peer connected*/
	bool is_alive;
	bool dev_sel_state;
	Elm_Object_Item *gl_item;
	struct device_type_s_ *next;
} device_type_s;

struct ug_data {
	Evas_Object *base;
	ui_gadget_h ug;

	Evas_Object *win;
	Evas_Object *bg;
	Evas_Object *layout;
	Evas_Object *naviframe;
	Elm_Object_Item *navi_item;
	Elm_Object_Item *multi_navi_item;
	Elm_Object_Item *head;
	Evas_Object *genlist;
	Evas_Object *multiconn_view_genlist;
	Evas_Object *multiconn_layout;
	Evas_Object *popup;
	Evas_Object *act_popup;
	Evas_Object *warn_popup;
	Evas_Object *rename_popup;
	Evas_Object *ctxpopup;
	Evas_Object *scan_btn;
	Evas_Object *disconnect_btn;
	Evas_Object *toolbar;
	Evas_Object *rename_entry;
	Evas_Object *rename_button;

#ifdef WFD_ON_OFF_GENLIST
	Evas_Object *on_off_check;
#endif

	Evas_Object *scan_toolbar;
	Evas_Object *multiconn_scan_stop_btn;
	Evas_Object *multiconn_conn_btn;
	Evas_Object *select_all_icon;



	Elm_Object_Item *multi_connect_toolbar_item;
	Elm_Object_Item *multi_view_connect_toolbar_item;

	Elm_Object_Item *select_all_view_genlist;
#ifdef WFD_ON_OFF_GENLIST
	Elm_Object_Item *item_wifi_onoff;
#endif
	Elm_Object_Item *device_name_item;
	Elm_Genlist_Item_Class *rename_entry_itc;
	Elm_Genlist_Item_Class *rename_desc_itc;
	Elm_Object_Item *multi_connect_sep_item;

	Elm_Object_Item *nodevice_title_item;
	Elm_Object_Item *nodevice_item;

	Elm_Object_Item *conn_wfd_item;
	Elm_Object_Item *conn_failed_wfd_item;
	Elm_Object_Item *avlbl_wfd_item;
	Elm_Object_Item *busy_wfd_item;
	Elm_Object_Item *multi_connect_wfd_item;

	Elm_Object_Item *mcview_title_item;
	Elm_Object_Item *mcview_nodevice_item;
	Elm_Object_Item *more_btn_multiconnect_item;

	Evas_Object *back_btn;

	// Notify
	Evas_Object *notify;
	Evas_Object *notify_layout;

	int head_text_mode;

	char *mac_addr_connecting;
	char *mac_addr_req;

	//Connection is incoming or not
	bool is_conn_incoming;


	// title mode of device list
	int title_content_mode;

	// Raw peer data
	device_type_s raw_connected_peers[MAX_CONNECTED_PEER_NUM];
	int raw_connected_peer_cnt;
	GList *raw_discovered_peer_list;
	int raw_discovered_peer_cnt;

	// Peer data in the Genlist
	int gl_connected_peer_cnt;
	device_type_s *gl_conn_peers_start;

	int gl_connected_failed_peer_cnt;
	device_type_s *gl_failed_peers_start;

	int gl_available_peer_cnt;
	device_type_s *gl_avlb_peers_start;

	int gl_busy_peer_cnt;
	device_type_s *gl_busy_peers_start;

	device_type_s raw_multi_selected_peers[MAX_PEER_NUM];
	int raw_multi_selected_peer_cnt;

	int gl_multi_connect_peer_cnt;
	device_type_s *gl_mul_conn_peers_start;

	// My status
	bool I_am_group_owner;
	bool I_am_connected;

	// Following variables are used at the Multi connect view.
	wfd_multi_connect_mode_e multi_connect_mode;
	device_type_s *multi_conn_dev_list_start;
	int gl_available_dev_cnt_at_multiconn_view;
	int g_source_multi_connect_next;

#ifdef WFD_ON_OFF_GENLIST
	int wfd_onoff;
#endif
	wifi_direct_state_e wfd_status;
	char *dev_name;
	char *dev_pass;

	// For connect failed peers
	int last_display_time;
	Ecore_Timer *display_timer;

	// Tethering
	bool is_hotspot_off;
	bool is_hotspot_locally_disabled;
	tethering_h hotspot_handle;

	// wfds service
	char *wfds;

	// Device filter
	int device_filter;

	// Whether support auto exit after successed connection
	bool is_auto_exit;

	//Whether support multi connection
	bool is_multi_connect;
	bool is_select_all_checked;

	//view type for search
	char *view_type;

	//Title of UG
	char *title;

	// The ip address of connected peer
	char *peer_ip_address;

	// The service name that supported WFDSP
	char *service_name;

	// Whether initialize wfd-namager ok
	bool is_init_ok;

	//timer for deleting progress bar
	int timer_stop_progress_bar;

	//timer for multi connect reset
	int timer_multi_reset;

	//if all the items are selected or not
	bool is_multi_check_all_selected;

	//timer for remove not alive peer
	int timer_delete_not_alive_peer;

	//wifi direct discovery status
	int wfd_discovery_status;

	bool is_paused;

#ifdef WFD_DBUS_LAUNCH
	GCancellable *dbus_cancellable;
	GDBusConnection *conn;
#endif
	Ea_Theme_Color_Table *color_table;
	Ea_Theme_Font_Table *font_table;
};

extern Elm_Gen_Item_Class device_name_title_itc;
#ifdef WFD_ON_OFF_GENLIST
extern Elm_Gen_Item_Class wfd_onoff_itc;
#endif
extern Elm_Gen_Item_Class device_name_itc;
extern Elm_Gen_Item_Class title_itc;
extern Elm_Gen_Item_Class multi_view_title_itc;
extern Elm_Gen_Item_Class peer_itc;
extern Elm_Gen_Item_Class title_no_device_itc;
extern Elm_Gen_Item_Class noitem_itc;
extern Elm_Gen_Item_Class title_available_itc;

extern Elm_Gen_Item_Class title_conn_itc;
extern Elm_Gen_Item_Class peer_conn_itc;

extern Elm_Gen_Item_Class title_busy_itc;
extern Elm_Gen_Item_Class peer_busy_itc;

extern Elm_Gen_Item_Class title_multi_connect_itc;
extern Elm_Gen_Item_Class peer_multi_connect_itc;
extern Elm_Gen_Item_Class select_all_multi_connect_itc;

extern Elm_Gen_Item_Class title_conn_failed_itc;
extern Elm_Gen_Item_Class peer_conn_failed_itc;

/**
 *	This function let the ug destroy the ug
 *	@return   void
 *	@param[in] data the pointer to the main data structure
 */
void wfd_destroy_ug(void *data);

/**
 *	This function is called when ON/OFF button is turned ON/OFF
 *	@return   void
 *	@param[in] data the pointer to the main data structure
 *	@param[in] object
 *	@param[in] event
 */
void _onoff_changed_cb(void *data, Evas_Object *obj, void *event_info);
void toolbar_language_changed(void *data, Evas_Object *obj, void *event_info);
void ctxpopup_dismissed_cb(void *data, Evas_Object *obj, void *event_info);
void wfd_free_nodivice_item(struct ug_data *ugd);
void discover_cb(int error_code, wifi_direct_discovery_state_e discovery_state, void *user_data);


#endif  /* __WFD_UG_H__ */