Bug Fix and Code Cleanup
[platform/core/connectivity/wifi-direct-manager.git] / plugin / wpasupplicant / ctrl_iface_dbus / include / wfd-plugin-wpasupplicant.h
1 /*
2  * Network Configuration Module
3  *
4  * Copyright (c) 2012 Samsung Electronics Co., Ltd. All rights reserved.
5  *
6  * Licensed under the Apache License, Version 2.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
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
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  * This file declares wifi direct wpasupplicant plugin functions and structures.
22  *
23  * @file                wfd-plugin-wpasupplicant.h
24  * @author      Gibyoung Kim (lastkgb.kim@samsung.com)
25  * @version     0.7
26  */
27
28 #ifndef __WFD_PLUGIN_WPASUPPLICANT_H__
29 #define __WFD_PLUGIN_WPASUPPLICANT_H__
30
31
32 #define MAC2STR(a) (a)[0], (a)[1], (a)[2], (a)[3], (a)[4], (a)[5]
33 #define MACSTR "%02x:%02x:%02x:%02x:%02x:%02x"
34 #define IP2STR(a) (a)[0], (a)[1], (a)[2], (a)[3]
35 #define IPSTR "%d.%d.%d.%d"
36 #define MAC2SECSTR(a) (a)[0], (a)[4], (a)[5]
37 #define MACSECSTR "%02x:%02x:%02x"
38 #define ISZEROMACADDR(a) !(a[0] | a[1] | a[2] | a[3] | a[4] | a[5])
39 #define IP2SECSTR(a) (a)[0], (a)[3]
40 #define IPSECSTR "%d..%d"
41 #define OBJECT_PATH_MAX 150
42 #define MAX_SIZE_ERROR_BUFFER 256
43
44 #if defined(TIZEN_PROFILE_MOBILE) || defined(TIZEN_PROFILE_COMMON)
45 #define COMMON_IFACE_NAME "wlan0"
46
47 #       if defined TIZEN_WLAN_BOARD_SPRD
48 #               define P2P_IFACE_NAME "p2p0"
49 #               define GROUP_IFACE_NAME "p2p0"
50 #               define GROUP_IFACE_PREFIX "p2p"
51 #       else /* TIZEN_WLAN_BOARD_SPRD */
52 #               define GROUP_IFACE_NAME "p2p-wlan0-0"
53 #               define GROUP_IFACE_PREFIX "p2p-wlan0-"
54 #       endif /* TIZEN_WLAN_BOARD_SPRD */
55
56 #       define PRIMARY_DEVICE_TYPE "\x00\x0a\x00\x50\xf2\x04\x00\x05"
57 #       define DEFAULT_DEVICE_NAME "Tizen"
58 #       define DEFAULT_GO_INTENT 7
59 #       define DEFAULT_PERSISTENT_RECONNECT 1
60 #       define DEFAULT_LISTEN_REG_CLASS 81
61 #       define DEFAULT_LISTEN_CHANNEL 1
62 #       define DEFAULT_OPER_REG_CLASS 81
63 #       define DEFAULT_OPER_CHANNEL 1
64 #if !defined(TIZEN_FEATURE_ASP)
65 #       define DEFAULT_CONFIG_METHOD "display push_button keypad"
66 #else
67 #       define DEFAULT_CONFIG_METHOD "display push_button keypad p2ps"
68 #endif
69 #       define DEFAULT_NO_GROUP_IFACE 0
70 #endif /* TIZEN_PROFILE_MOBILE */
71
72 #if defined TIZEN_PROFILE_TV
73
74 #       if defined TIZEN_WIFI_MODULE_BUNDLE
75 #               define COMMON_IFACE_NAME "wlan0"
76 #               define GROUP_IFACE_NAME "wlan0"
77 #               define GROUP_IFACE_PREFIX "wlan"
78 #       else /* TIZEN_WIFI_MODULE_BUNDLE */
79 #               define COMMON_IFACE_NAME "p2p0"
80 #               define GROUP_IFACE_NAME "p2p0"
81 #               define GROUP_IFACE_PREFIX "p2p"
82 #       endif /* TIZEN_WIFI_MODULE_BUNDLE */
83
84 #       define PRIMARY_DEVICE_TYPE "\x00\x07\x00\x50\xf2\x04\x00\x01"
85 #       define DEFAULT_DEVICE_NAME "[TV]Tizen"
86 #       define DEFAULT_GO_INTENT 7
87 #       define DEFAULT_PERSISTENT_RECONNECT 1
88 #       define DEFAULT_LISTEN_REG_CLASS 81
89 #       define DEFAULT_LISTEN_CHANNEL 1
90 #       define DEFAULT_OPER_REG_CLASS 81
91 #       define DEFAULT_OPER_CHANNEL 1
92 #       define DEFAULT_CONFIG_METHOD "keypad virtual_push_button physical_display"
93 #       define DEFAULT_NO_GROUP_IFACE 1
94 #endif /* TIZEN_PROFILE_TV */
95
96 #if 0
97 #define COMMON_IFACE_NAME "p2p0"
98 #define DEFAULT_CONFIG_METHOD "push_button"
99 #define DEFAULT_NO_GROUP_IFACE 0
100 #define GROUP_IFACE_NAME "p2p0"
101 #define GROUP_IFACE_PREFIX "p2p"
102 #define PRIMARY_DEVICE_TYPE "\x00\x07\x00\x50\xf2\x04\x00\x01"
103 #define DEFAULT_DEVICE_NAME "[TV]Tizen"
104 #define DEFAULT_GO_INTENT 7
105 #define DEFAULT_PERSISTENT_RECONNECT 1
106 #define DEFAULT_LISTEN_REG_CLASS 81
107 #define DEFAULT_LISTEN_CHANNEL 1
108 #define DEFAULT_OPER_REG_CLASS 115
109 #define DEFAULT_OPER_CHANNEL 48
110 #define DEFAULT_CONFIG_METHOD "keypad virtual_push_button physical_display"
111 #define DEFAULT_NO_GROUP_IFACE 1
112 #endif
113
114 #ifdef TIZEN_FEATURE_IP_OVER_EAPOL
115 #define DEFAULT_IP_GO "\xc0\xa8\x31\x01"
116 #define DEFAULT_IP_MASK "\xff\xff\xff\x00"
117 #define DEFAULT_IP_START "\xc0\xa8\x31\x33"
118 #define DEFAULT_IP_END "\xc0\xa8\x31\x64"
119 #endif /* TIZEN_FEATURE_IP_OVER_EAPOL */
120
121 #define WS_POLL_TIMEOUT 5000
122 #define WS_CONN_RETRY_COUNT 10
123 #define WS_PINSTR_LEN 8
124 #define WS_SSID_LEN 32
125 #define WS_MACSTR_LEN 18
126 #define WS_MACADDR_LEN 6
127 #define WS_MAX_PERSISTENT_COUNT 20
128
129 #define WS_DEVTYPE_LEN 8
130
131 #ifdef TIZEN_FEATURE_SERVICE_DISCOVERY
132 #define SERV_DISC_REQ_ALL "02000001"
133 #define SERV_DISC_REQ_BONJOUR "02000101"
134 #define SERV_DISC_REQ_UPNP "02000201"
135
136 #define SERVICE_TYPE_LEN 8
137 #define WS_MAX_SERVICE_LEN 1024
138 #define SERVICE_QUERY_LEN 4
139
140 #define SERVICE_TYPE_ALL "0000f00c"
141 #define SERV_BROADCAST_ADDRESS "00:00:00:00:00:00"
142
143 #define WS_QTYPE_PTR 0x0c
144 #define WS_QTYPE_TXT 0x10
145 #define WS_TCP_PTR_HEX "\xc0\x0c"
146 #define WS_UDP_PTR_HEX "\xc0\x1e"
147 #define WS_PTR_TYPE_HEX "\x00\x0c\x01"
148 #define WS_TXT_TYPE_HEX "\x00\x10\x01"
149 #endif /* TIZEN_FEATURE_SERVICE_DISCOVERY */
150
151 /* Config Method bitmap */
152 #define WS_CONFIG_METHOD_DISPLAY 0x0008
153 #define WS_CONFIG_METHOD_PUSHBUTTON 0x0080
154 #define WS_CONFIG_METHOD_KEYPAD 0x0100
155 #if defined(TIZEN_FEATURE_ASP)
156 #define WS_CONFIG_METHOD_P2PS 0x1000
157 #endif /* TIZEN_FEATURE_ASP */
158
159 #define WS_DBUS_STR_PBC "pbc"
160 #define WS_DBUS_STR_DISPLAY "display"
161 #define WS_DBUS_STR_KEYPAD "keypad"
162 #if defined(TIZEN_FEATURE_ASP)
163 #define WS_DBUS_STR_P2PS "p2ps"
164 #endif /* TIZEN_FEATURE_ASP */
165 #define WS_DBUS_STR_JOIN "join"
166 #define WS_DBUS_STR_AUTH "auth"
167 #define WS_DBUS_STR_PERSISTENT "persistent"
168
169 #ifdef TIZEN_FEATURE_WIFI_DISPLAY
170 #define WS_WFD_INFO_PRIMARY_SINK 0x01
171 #define WS_WFD_INFO_SECONDARY_SINK 0x02
172 #define WS_WFD_INFO_AVAILABILITY 0x10
173 #define WS_WFD_INFO_WSD_SUPPORT 0x40
174 #define WS_WFD_INFO_TDLS_SUPPORT 0x80
175 #define WS_WFD_INFO_HDCP_SUPPORT 0x100
176 #define WS_WFD_INFO_SYNC_SUPPORT 0x200
177 #endif /* TIZEN_FEATURE_WIFI_DISPLAY */
178
179 typedef enum {
180         WS_IFTYPE_NONE,
181         WS_IFTYPE_STATION,
182         WS_IFTYPE_GROUP,
183 } ws_iftype_e;
184
185 typedef enum {
186         WS_PRI_DEV_TYPE_NONE,
187         WS_PRI_DEV_TYPE_COMPUTER = 1,
188         WS_PRI_DEV_TYPE_INPUT_DEVICE = 2,
189         WS_PRI_DEV_TYPE_PRINTER = 3,
190         WS_PRI_DEV_TYPE_CAMERA = 4,
191         WS_PRI_DEV_TYPE_STORAGE = 5,
192         WS_PRI_DEV_TYPE_NETWORK_INFRA = 6,
193         WS_PRI_DEV_TYPE_DISPLAY = 7,
194         WS_PRI_DEV_TYPE_MULTIMEDIA_DEVICE = 8,
195         WS_PRI_DEV_TYPE_GAME_DEVICE = 9,
196         WS_PRI_DEV_TYPE_TELEPHONE = 10,
197         WS_PRI_DEV_TYPE_AUDIO = 11,
198         WS_PRI_DEV_TYPE_OTHER = 255,
199 } ws_device_type_e;
200
201 typedef enum {
202         /* The Service Discovery field shall be set to 1
203          * if the P2P Device supports Service Discovery,
204          * and is set to 0 otherwise. */
205         WS_DEVICE_CAP_SERVICE_DISCOVERY = 0x01,
206
207         /* Within a P2P Group Info attribute and a (Re)association
208          * request frame the P2P Client Discoverability field shall be set to 1
209          * when the P2P Device supports P2P Client Discoverability,
210          * and is set to 0 otherwise.
211          * This field shall be reserved and set to 0 in all other frames or uses. */
212         WS_DEVICE_CAP_CLIENT_DISCOVERABILITY = 0x02,
213
214         /* The Concurrent Operation field shall be set to 1
215          * when the P2P Device supports Concurrent Operation with WLAN,
216          * and is set to 0 otherwise. */
217         WS_DEVICE_CAP_CONCURRENT_OPERATION = 0x04,
218
219         /* The P2P Infrastructure Managed field shall be set to 1
220          * when the P2P interface of the P2P Device is capable of being
221          * managed by the WLAN (infrastructure network) based on
222          * P2P Coexistence Parameters, and set to 0 otherwise. */
223         WS_DEVICE_CAP_INFRASTRUCTURE_MANAGED = 0x08,
224
225         /* The P2P Device Limit field shall be set to 1
226          * when the P2P Device is unable to participate in additional P2P Groups,
227          * and set to 0 otherwise. */
228         WS_DEVICE_CAP_DEVICE_LIMIT = 0x10,
229
230         /* The P2P Invitation Procedure field shall be set to 1
231          * if the P2P Device is capable of processing P2P Invitation Procedure
232          * signaling, and set to 0 otherwise. */
233         WS_DEVICE_CAP_INVITATION_PROCEDURE = 0x20,
234 } ws_device_cap_flag_e;
235
236 typedef enum {
237         /* The P2P Group Owner field shall be set to 1
238          * when the P2P Device is operating as a Group Owner,
239          * and set to 0 otherwise. */
240         WS_GROUP_CAP_GROUP_OWNER = 0x01,
241
242         /* The Persistent P2P Group field shall be set to 1
243          * when the P2P Device is hosting, or intends to host,
244          * a persistent P2P Group, and set to 0 otherwise. */
245         WS_GROUP_CAP_PERSISTENT_GROUP = 0x02,
246
247         /* The P2P Group Limit field shall be set to 1
248          * when the P2P Group Owner is unable to add additional Clients
249          * to its P2P Group, and set to 0 otherwise. */
250         WS_GROUP_CAP_GROUP_LIMIT = 0x04,
251
252         /* The Intra-BSS Distribution field shall be set to 1
253          * if the P2P Device is hosting, or intends to host,
254          * a P2P Group that provides a data distribution service
255          * between Clients in the P2P Group.
256          * The Intra-BSS Distribution field shall be set to 0,
257          * if the P2P Device is not a P2P Group Owner,
258          * or is not providing such a data distribution service. */
259         WS_GROUP_CAP_INTRA_BSS_DISTRIB = 0x08,
260
261         /* The Cross Connection field shall be set to 1
262          * if the P2P Device is hosting, or intends to host,
263          * a P2P Group that provides cross connection
264          * between the P2P Group and a WLAN.
265          * The Cross Connection field shall be set to 0
266          * if the P2P Device is not a P2P Group Owner,
267          * or is not providing a cross connection service. */
268         WS_GROUP_CAP_CROSS_CONNECTION = 0x10,
269
270         /* The Persistent Reconnect field shall be set to 1
271          * when the P2P Device is hosting, or intends to host,
272          * a persistent P2P Group that allows reconnection
273          * without user intervention, and set to 0 otherwise. */
274         WS_GROUP_CAP_PERSISTENT_RECONN = 0x20,
275
276         /* The Group Formation field shall be set to 1
277          * when the P2P Device is operating as a Group Owner
278          * in the Provisioning phase of Group Formation,
279          * and set to 0 otherwise. */
280         WS_GROUP_CAP_GROUP_FORMATION = 0x40,
281 } ws_group_cap_flag_e;
282
283 typedef enum {
284         /* If the Device Password ID is Default, the Enrollee should use
285          * its PIN password (from the label or display). This password may
286          * correspond to the label, display, or a user-defined password
287          * that has been configured to replace the original device password. */
288         WS_DEV_PASSWD_ID_DEFAULT = 0x0000,
289
290         /* User-specified indicates that the user has overridden the password
291          * with a manually selected value. */
292         WS_DEV_PASSWD_ID_USER_SPECIFIED = 0x0001,
293
294         /* Machine-specified indicates that the original PIN password has been
295          * overridden by a strong, machine-generated device password value. */
296         WS_DEV_PASSWD_ID_MACHINE_SPECIFIED = 0x0002,
297
298         /* The Rekey value indicates that the device's 256-bit rekeying
299          * password will be used. */
300         WS_DEV_PASSWD_ID_REKEY = 0x0003,
301
302         /* The PushButton value indicates that the PIN is the all-zero value
303          * reserved for the Push Button Configuration method. */
304         WS_DEV_PASSWD_ID_PUSH_BUTTON = 0x0004,
305
306         /* The Registrar-specified value indicates a PIN that has been
307          * obtained from the Registrar (via a display or other out-of-band
308          * method). This value may be further augmented with the optional
309          * "Identity" attribute in M1. */
310         WS_DEV_PASSWD_ID_REGISTRAR_SPECIFIED = 0x0005,  /* ENTER-PIN */
311
312 #if defined(TIZEN_FEATURE_ASP)
313         WS_DEV_PASSWD_ID_P2PS = 0x0008,
314 #endif /* TIZEN_FEATURE_ASP */
315 } ws_dev_passwd_id_e;
316
317 typedef enum {
318         WPS_ERROR_NONE,
319
320         WPS_ERROR_OOBINFO_READ_FAIL,
321         WPS_ERROR_DECRYPTION_FAIL,
322         WPS_ERROR_2G_NOT_SUPPORTED,
323         WPS_ERROR_5G_NOT_SUPPORTED,
324         WPS_ERROR_WEAK_SIGNAL,
325         WPS_ERROR_NET_AUTH_FAIL,
326         WPS_ERROR_NET_ASSOC_FAIL,
327         WPS_ERROR_NO_DHCP_RESPONSE,
328         WPS_ERROR_DHCP_CONFIG_FAIL,
329         WPS_ERROR_IP_CONFLICT,
330
331         WPS_ERROR_REGISTRAT_CONN_FAIL,
332         WPS_ERROR_PBC_SESSION_OVERLAP,
333         WPS_ERROR_ROGUE_ACTIVITY,
334         WPS_ERROR_DEVICE_BUSY,
335         WPS_ERROR_SETUP_LOCKED,
336         WPS_ERROR_MESSAGE_TIMEOUT,
337         WPS_ERROR_SESSION_TIMEOUT,
338         WPS_ERROR_PASSWORD_MISMATCH,
339 } ws_wps_error_e;
340
341 #ifdef TIZEN_FEATURE_WIFI_DISPLAY
342 typedef enum {
343         WFD_SUBELM_ID_DEV_INFO,
344         WFD_SUBELM_ID_ASSOC_BSSID,
345         WFD_SUBELM_ID_AUDIO_FORMAT,
346         WFD_SUBELM_ID_VIDEO_FORMAT,
347         WFD_SUBELM_ID_3D_FORMAT,
348         WFD_SUBELM_ID_CONTENT_PROTECTION,
349
350         WFD_SUBELM_ID_CUPLED_SYNC_INFO,
351         WFD_SUBELM_ID_EXT_CAPAB,
352         WFD_SUBELM_ID_LOCAL_IP,
353         WFD_SUBELM_ID_SESSION_INFO,
354         WFD_SUBELM_ID_ALT_MAC,
355 } ws_wfd_subelm_id_e;
356 #define WFD_SUBELEM_LEN_DEV_INFO 6
357 #define WFD_SUBELM_LEN_ASSOC_BSSID 6
358 #define WFD_SUBELM_LEN_CUPLED_SYNC_INFO 7
359 #endif /* TIZEN_FEATURE_WIFI_DISPLAY */
360
361 typedef enum {
362         WFD_OEM_NETFLAG_CURRENT,
363         WFD_OEM_NETFLAG_DISABLED,
364         WFD_OEM_NETFLAG_TEMP_DISABLED,
365         WFD_OEM_NETFLAG_P2P_PERSISTENT,
366 } ws_netowrk_flag_e;
367
368 typedef struct {
369         int network_id;
370         char ssid[OEM_DEV_NAME_LEN+1];
371         unsigned char bssid[OEM_MACADDR_LEN];
372         char psk[OEM_PASS_PHRASE_LEN +1];
373         int proto;
374         int key_mgmt;
375         int pairwise;
376         int group;
377         int auth_alg;
378         int mode;
379         int p2p_client_num;
380         unsigned char p2p_client_list[OEM_MAX_PEER_NUM][OEM_MACADDR_LEN];
381         char persistent_path[OBJECT_PATH_MAX];
382         int total;
383 } ws_network_info_s;
384
385 typedef struct {
386         int initialized;        /* check whether plugin is initialized or not. block init function if initialized */
387         int activated;
388         int concurrent;
389
390         GDBusConnection *g_dbus;
391         char iface_path[150];
392         char group_iface_path[150];
393         unsigned char local_dev_addr[WS_MACADDR_LEN];
394         wfd_oem_event_cbs_s *callback;
395 } ws_dbus_plugin_data_s;
396
397 int ws_init(wfd_oem_event_cbs_s *event_cbs);
398 int ws_deinit(void);
399 int ws_activate(int concurrent);
400 int ws_deactivate(int concurrent);
401 int ws_start_scan(wfd_oem_scan_param_s *param);
402 int ws_restart_scan(int freq);
403 int ws_stop_scan(void);
404 int ws_get_visibility(int *visibility);
405 int ws_set_visibility(int visibility);
406 int ws_get_scan_result(GList **peers, int *peer_count);
407 int ws_get_peer_info(unsigned char *peer_addr, wfd_oem_device_s **peer);
408 int ws_prov_disc_req(unsigned char *peer_addr, wfd_oem_wps_mode_e wps_mode, int join);
409 int ws_connect(unsigned char *peer_addr, wfd_oem_conn_param_s *param);
410 int ws_disconnect(unsigned char *peer_addr, int is_iface_addr);
411 int ws_reject_connection(unsigned char *peer_addr);
412 int ws_cancel_connection(unsigned char *peer_addr);
413 int ws_get_connected_peers(GList **peers, int *peer_count);
414 int ws_get_pin(char *pin);
415 int ws_set_pin(char *pin);
416 int ws_generate_pin(char **pin);
417 int ws_get_supported_wps_mode(int *wps_mode);
418 int ws_create_group(wfd_oem_group_param_s *param);
419 int ws_destroy_group(const char *ifname);
420 int ws_invite(unsigned char *peer_addr, wfd_oem_invite_param_s *param);
421 int ws_wps_start(unsigned char *peer_addr, int wps_mode, const char *pin);
422 int ws_enrollee_start(unsigned char *peer_addr, int wps_mode, const char *pin);
423 int ws_wps_cancel(void);
424 int ws_get_dev_name(char *dev_name);
425 int ws_set_dev_name(char *dev_name);
426 int ws_get_dev_mac(char *dev_mac);
427 int ws_get_dev_type(int *pri_dev_type, int *sec_dev_type);
428 int ws_set_dev_type(int pri_dev_type, int sec_dev_type);
429 int ws_get_go_intent(int *go_intent);
430 int ws_set_go_intent(int go_intent);
431 int ws_set_country(char *ccode);
432
433 int ws_get_persistent_groups(wfd_oem_persistent_group_s **groups, int *group_count);
434 int ws_remove_persistent_group(char *ssid, unsigned char *bssid);
435 int ws_set_persistent_reconnect(unsigned char *bssid, int reconnect);
436
437 #ifdef TIZEN_FEATURE_SERVICE_DISCOVERY
438 int ws_start_service_discovery(unsigned char *mac_addr, int service_type);
439 int ws_cancel_service_discovery(unsigned char *mac_addr, int service_type);
440
441 int ws_serv_add(wfd_oem_new_service_s *service);
442 int ws_serv_del(wfd_oem_new_service_s *service);
443 #endif /* TIZEN_FEATURE_SERVICE_DISCOVERY */
444
445 #ifdef TIZEN_FEATURE_WIFI_DISPLAY
446 int ws_miracast_init(int enable);
447 int ws_set_display(wfd_oem_display_s *wifi_display);
448 #endif /* TIZEN_FEATURE_WIFI_DISPLAY */
449
450 int ws_refresh(void);
451 int ws_save_config(void);
452 int ws_set_operating_channel(int channel);
453 int ws_remove_all_network(void);
454 int ws_get_wpa_status(int *wpa_status);
455
456 #if defined(TIZEN_FEATURE_ASP)
457 int ws_advertise_service(wfd_oem_asp_service_s *service, int replace);
458 int ws_cancel_advertise_service(wfd_oem_asp_service_s *service);
459 int ws_seek_service(wfd_oem_asp_service_s *service);
460 int ws_cancel_seek_service(wfd_oem_asp_service_s *service);
461 int ws_asp_prov_disc_req(wfd_oem_asp_prov_s *asp_params);
462 #endif /* TIZEN_FEATURE_ASP */
463
464 #endif /* __WFD_PLUGIN_WPASUPPLICANT_H__ */