4 * Copyright 2012 Samsung Electronics Co., Ltd
6 * Licensed under the Flora License, Version 1.0 (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
10 * http://www.tizenopensource.org/license
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.
25 #include <notification.h>
26 #include <ui-gadget-module.h>
28 #include <tethering.h>
30 #include <wifi-direct.h>
31 #include <efl-assist/efl_assist.h>
33 #include <glib-object.h>
38 #define PACKAGE "ug-setting-wifidirect-efl"
39 #define LOCALEDIR "/usr/share/locale"
40 #define COLOR_TABLE "/usr/apps/setting-wifidirect-efl/shared/res/tables/setting-wifidirect-efl_ChangeableColorTable.xml"
41 #define FONT_TABLE "/usr/apps/setting-wifidirect-efl/shared/res/tables/setting-wifidirect-efl_FontInfoTable.xml"
43 #define DIRECT_TAG "wfd_ug"
44 /* TODO:: To change the log level as LOG_INFO */
45 #define DBG(log_level, format, args...) \
46 LOG(LOG_ERROR, DIRECT_TAG, "[%s()][%d] " format, __FUNCTION__, __LINE__, ##args)
47 #define DBG_SECURE(log_level, format, args...) \
48 SECURE_LOG(LOG_ERROR, DIRECT_TAG, "[%s()][%d] " format, __FUNCTION__, __LINE__, ##args)
50 #define MAC2SECSTR(a) (a)[0], (a)[4], (a)[5]
51 #define MACSECSTR "%02x:%02x:%02x"
53 #define IP2SECSTR(a) (a)[0], (a)[3]
54 #define IPSECSTR "%d..%d"
57 #define __FUNC_ENTER__ DBG(LOG_INFO, "+\n")
58 #define __FUNC_EXIT__ DBG(LOG_INFO, "-\n")
60 #define __FUNC_ENTER__
64 #define VCONF_WFD_APNAME "db/setting/device_name"
66 #define assertm_if(expr, fmt, arg...) do { \
68 DBG(LOG_VERBOSE, " ##(%s) -> %s() assert!!## "fmt, #expr, __FUNCTION__, ##arg); \
73 #define WFD_IF_DEL_OBJ(obj) \
76 evas_object_del(obj); \
81 #define WFD_IF_DEL_ITEM(obj) \
84 elm_object_item_del(obj); \
89 #define WFD_RET_IF(expr, fmt, args...) \
92 DBG(LOG_ERROR, "[%s] Return, message "fmt, #expr, ##args );\
97 #define WFD_RETV_IF(expr, val, fmt, args...) \
100 DBG(LOG_ERROR,"[%s] Return value, message "fmt, #expr, ##args );\
105 #define WFD_IF_FREE_MEM(mem) \
113 #define AP_NAME_LENGTH_MAX 32
114 #define AP_PASSWORD_LENGTH_MAX 64
115 #define AP_PASSWORD_LENGTH_MIN 8
116 #define AP_REJECT_CHAR_LIST "=,"
118 #define DEFAULT_DEV_NAME "ZEQ"
119 #define MAC_LENGTH 18
120 #define SSID_LENGTH 32
121 #define MAX_CONNECTED_PEER_NUM 7
122 #define MAX_PEER_NUM 10
123 #define MAX_POPUP_TEXT_SIZE 256
124 #define MAX_DISPLAY_TIME_OUT 3
125 #define MAX_NO_ACTION_TIME_OUT 300 /*5min*/
126 #define MAX_SCAN_TIME_OUT 0
128 #define GENLIST_HEADER_POS 1
129 #define SR_CHECKBOX_ON_MSG "on/off button on"
130 #define SR_CHECKBOX_OFF_MSG "on/off button off"
131 #define SR_BUTTON_MSG "multiple connect button"
133 #define _(s) dgettext(PACKAGE, s)
134 #define N_(s) dgettext_noop(s)
135 #define S_(s) dgettext("sys_string", s)
137 #define WFD_GLOBALIZATION_STR_LENGTH 256
140 WFD_MULTI_CONNECT_MODE_NONE,
141 WFD_MULTI_CONNECT_MODE_IN_PROGRESS,
142 WFD_MULTI_CONNECT_MODE_COMPLETED,
143 } wfd_multi_connect_mode_e;
146 PEER_CONN_STATUS_DISCONNECTED,
147 PEER_CONN_STATUS_DISCONNECTING,
148 PEER_CONN_STATUS_CONNECTING = PEER_CONN_STATUS_DISCONNECTING,
149 PEER_CONN_STATUS_CONNECTED,
150 PEER_CONN_STATUS_FAILED_TO_CONNECT,
151 PEER_CONN_STATUS_WAIT_FOR_CONNECT,
155 WIFI_DIRECT_DISCOVERY_NONE,
156 WIFI_DIRECT_DISCOVERY_SOCIAL_CHANNEL_START,
157 WIFI_DIRECT_DISCOVERY_FULL_SCAN_START,
158 WIFI_DIRECT_DISCOVERY_STOPPED,
159 WIFI_DIRECT_DISCOVERY_BACKGROUND,
160 } discovery_status_e;
163 typedef struct device_type_s_{
164 char ssid[SSID_LENGTH];
165 unsigned int category;
166 unsigned int sub_category;
167 char mac_addr[MAC_LENGTH];
168 char if_addr[MAC_LENGTH];
169 conn_status_e conn_status;
170 bool is_group_owner; /** Is an active P2P Group Owner */
171 bool is_persistent_group_owner; /** Is a stored Persistent GO */
172 bool is_connected; /** Is peer connected*/
175 Elm_Object_Item *gl_item;
176 struct device_type_s_ *next;
186 Evas_Object *naviframe;
187 Elm_Object_Item *navi_item;
188 Elm_Object_Item *multi_navi_item;
189 Elm_Object_Item *head;
190 Evas_Object *genlist;
191 Evas_Object *multiconn_view_genlist;
192 Evas_Object *multiconn_layout;
194 Evas_Object *act_popup;
195 Evas_Object *warn_popup;
196 Evas_Object *rename_popup;
197 Evas_Object *ctxpopup;
198 Evas_Object *scan_btn;
199 Evas_Object *disconnect_btn;
200 Evas_Object *toolbar;
201 Evas_Object *rename_entry;
202 Evas_Object *rename_button;
204 #ifdef WFD_ON_OFF_GENLIST
205 Evas_Object *on_off_check;
208 Evas_Object *scan_toolbar;
209 Evas_Object *multiconn_scan_stop_btn;
210 Evas_Object *multiconn_conn_btn;
211 Evas_Object *select_all_icon;
215 Elm_Object_Item *multi_connect_toolbar_item;
216 Elm_Object_Item *multi_view_connect_toolbar_item;
218 Elm_Object_Item *select_all_view_genlist;
219 #ifdef WFD_ON_OFF_GENLIST
220 Elm_Object_Item *item_wifi_onoff;
222 Elm_Object_Item *device_name_item;
223 Elm_Genlist_Item_Class *rename_entry_itc;
224 Elm_Genlist_Item_Class *rename_desc_itc;
225 Elm_Object_Item *multi_connect_sep_item;
227 Elm_Object_Item *nodevice_title_item;
228 Elm_Object_Item *nodevice_item;
230 Elm_Object_Item *conn_wfd_item;
231 Elm_Object_Item *conn_failed_wfd_item;
232 Elm_Object_Item *avlbl_wfd_item;
233 Elm_Object_Item *busy_wfd_item;
234 Elm_Object_Item *multi_connect_wfd_item;
236 Elm_Object_Item *mcview_title_item;
237 Elm_Object_Item *mcview_nodevice_item;
238 Elm_Object_Item *more_btn_multiconnect_item;
240 Evas_Object *back_btn;
244 Evas_Object *notify_layout;
248 char *mac_addr_connecting;
251 //Connection is incoming or not
252 bool is_conn_incoming;
255 // title mode of device list
256 int title_content_mode;
259 device_type_s raw_connected_peers[MAX_CONNECTED_PEER_NUM];
260 int raw_connected_peer_cnt;
261 GList *raw_discovered_peer_list;
262 int raw_discovered_peer_cnt;
264 // Peer data in the Genlist
265 int gl_connected_peer_cnt;
266 device_type_s *gl_conn_peers_start;
268 int gl_connected_failed_peer_cnt;
269 device_type_s *gl_failed_peers_start;
271 int gl_available_peer_cnt;
272 device_type_s *gl_avlb_peers_start;
274 int gl_busy_peer_cnt;
275 device_type_s *gl_busy_peers_start;
277 device_type_s raw_multi_selected_peers[MAX_PEER_NUM];
278 int raw_multi_selected_peer_cnt;
280 int gl_multi_connect_peer_cnt;
281 device_type_s *gl_mul_conn_peers_start;
284 bool I_am_group_owner;
287 // Following variables are used at the Multi connect view.
288 wfd_multi_connect_mode_e multi_connect_mode;
289 device_type_s *multi_conn_dev_list_start;
290 int gl_available_dev_cnt_at_multiconn_view;
291 int g_source_multi_connect_next;
293 #ifdef WFD_ON_OFF_GENLIST
296 wifi_direct_state_e wfd_status;
300 // For connect failed peers
301 int last_display_time;
302 Ecore_Timer *display_timer;
306 bool is_hotspot_locally_disabled;
307 tethering_h hotspot_handle;
315 // Whether support auto exit after successed connection
318 //Whether support multi connection
319 bool is_multi_connect;
320 bool is_select_all_checked;
322 //view type for search
328 // The ip address of connected peer
329 char *peer_ip_address;
331 // The service name that supported WFDSP
334 // Whether initialize wfd-namager ok
337 //timer for deleting progress bar
338 int timer_stop_progress_bar;
340 //timer for multi connect reset
341 int timer_multi_reset;
343 //if all the items are selected or not
344 bool is_multi_check_all_selected;
346 //timer for remove not alive peer
347 int timer_delete_not_alive_peer;
349 //wifi direct discovery status
350 int wfd_discovery_status;
354 #ifdef WFD_DBUS_LAUNCH
355 GCancellable *dbus_cancellable;
356 GDBusConnection *conn;
360 extern Elm_Gen_Item_Class device_name_title_itc;
361 #ifdef WFD_ON_OFF_GENLIST
362 extern Elm_Gen_Item_Class wfd_onoff_itc;
364 extern Elm_Gen_Item_Class device_name_itc;
365 extern Elm_Gen_Item_Class title_itc;
366 extern Elm_Gen_Item_Class multi_view_title_itc;
367 extern Elm_Gen_Item_Class peer_itc;
368 extern Elm_Gen_Item_Class title_no_device_itc;
369 extern Elm_Gen_Item_Class noitem_itc;
370 extern Elm_Gen_Item_Class title_available_itc;
372 extern Elm_Gen_Item_Class title_conn_itc;
373 extern Elm_Gen_Item_Class peer_conn_itc;
375 extern Elm_Gen_Item_Class title_busy_itc;
376 extern Elm_Gen_Item_Class peer_busy_itc;
378 extern Elm_Gen_Item_Class title_multi_connect_itc;
379 extern Elm_Gen_Item_Class peer_multi_connect_itc;
380 extern Elm_Gen_Item_Class select_all_multi_connect_itc;
382 extern Elm_Gen_Item_Class title_conn_failed_itc;
383 extern Elm_Gen_Item_Class peer_conn_failed_itc;
386 * This function let the ug destroy the ug
388 * @param[in] data the pointer to the main data structure
390 void wfd_destroy_ug(void *data);
393 * This function is called when ON/OFF button is turned ON/OFF
395 * @param[in] data the pointer to the main data structure
399 void _onoff_changed_cb(void *data, Evas_Object *obj, void *event_info);
400 void toolbar_language_changed(void *data, Evas_Object *obj, void *event_info);
401 void ctxpopup_dismissed_cb(void *data, Evas_Object *obj, void *event_info);
402 void wfd_free_nodivice_item(struct ug_data *ugd);
403 void discover_cb(int error_code, wifi_direct_discovery_state_e discovery_state, void *user_data);
406 #endif /* __WFD_UG_H__ */