• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Driver interaction with Linux nl80211/cfg80211 - definitions
3  * Copyright (c) 2002-2014, Jouni Malinen <j@w1.fi>
4  * Copyright (c) 2003-2004, Instant802 Networks, Inc.
5  * Copyright (c) 2005-2006, Devicescape Software, Inc.
6  * Copyright (c) 2007, Johannes Berg <johannes@sipsolutions.net>
7  * Copyright (c) 2009-2010, Atheros Communications
8  *
9  * This software may be distributed under the terms of the BSD license.
10  * See README for more details.
11  */
12 
13 #ifndef DRIVER_NL80211_H
14 #define DRIVER_NL80211_H
15 
16 #include "nl80211_copy.h"
17 #include "utils/list.h"
18 #include "driver.h"
19 
20 #ifndef NL_CAPABILITY_VERSION_3_5_0
21 #define nla_nest_start(msg, attrtype) \
22 	nla_nest_start(msg, NLA_F_NESTED | (attrtype))
23 #endif
24 
25 struct nl80211_global {
26 	void *ctx;
27 	struct dl_list interfaces;
28 	int if_add_ifindex;
29 	u64 if_add_wdevid;
30 	int if_add_wdevid_set;
31 	struct netlink_data *netlink;
32 	struct nl_cb *nl_cb;
33 	struct nl_sock *nl;
34 	int nl80211_id;
35 	int nlctrl_id;
36 	int ioctl_sock; /* socket for ioctl() use */
37 
38 	struct nl_sock *nl_event;
39 };
40 
41 struct nl80211_wiphy_data {
42 	struct dl_list list;
43 	struct dl_list bsss;
44 	struct dl_list drvs;
45 
46 	struct nl_sock *nl_beacons;
47 	struct nl_cb *nl_cb;
48 
49 	int wiphy_idx;
50 };
51 
52 struct i802_bss {
53 	struct wpa_driver_nl80211_data *drv;
54 	struct i802_bss *next;
55 	int ifindex;
56 	int br_ifindex;
57 	u64 wdev_id;
58 	char ifname[IFNAMSIZ + 1];
59 	char brname[IFNAMSIZ];
60 	unsigned int beacon_set:1;
61 	unsigned int added_if_into_bridge:1;
62 	unsigned int already_in_bridge:1;
63 	unsigned int added_bridge:1;
64 	unsigned int in_deinit:1;
65 	unsigned int wdev_id_set:1;
66 	unsigned int added_if:1;
67 	unsigned int static_ap:1;
68 	unsigned int use_nl_connect:1;
69 #ifdef CONFIG_VENDOR_EXT
70 	unsigned int p2p_enhance_iface:1;   /* vendor extension */
71 #endif
72 
73 	u8 addr[ETH_ALEN];
74 
75 	int freq;
76 	int bandwidth;
77 	int if_dynamic;
78 
79 	void *ctx;
80 	struct nl_sock *nl_preq, *nl_mgmt, *nl_connect;
81 	struct nl_cb *nl_cb;
82 
83 	struct nl80211_wiphy_data *wiphy_data;
84 	struct dl_list wiphy_list;
85 	u8 rand_addr[ETH_ALEN];
86 };
87 
88 struct drv_nl80211_if_info {
89 	int ifindex;
90 	/* the AP/AP_VLAN iface that is in this bridge */
91 	int reason;
92 };
93 
94 struct wpa_driver_nl80211_data {
95 	struct nl80211_global *global;
96 	struct dl_list list;
97 	struct dl_list wiphy_list;
98 	char phyname[32];
99 	unsigned int wiphy_idx;
100 	u8 perm_addr[ETH_ALEN];
101 	void *ctx;
102 	int ifindex;
103 	int if_removed;
104 	int if_disabled;
105 	int ignore_if_down_event;
106 	struct rfkill_data *rfkill;
107 	struct wpa_driver_capa capa;
108 	u8 *extended_capa, *extended_capa_mask;
109 	unsigned int extended_capa_len;
110 	struct drv_nl80211_ext_capa {
111 		enum nl80211_iftype iftype;
112 		u8 *ext_capa, *ext_capa_mask;
113 		unsigned int ext_capa_len;
114 	} iface_ext_capa[NL80211_IFTYPE_MAX];
115 	unsigned int num_iface_ext_capa;
116 
117 	int has_capability;
118 	int has_driver_key_mgmt;
119 
120 	int operstate;
121 
122 	int scan_complete_events;
123 	enum scan_states {
124 		NO_SCAN, SCAN_REQUESTED, SCAN_STARTED, SCAN_COMPLETED,
125 		SCAN_ABORTED, SCHED_SCAN_STARTED, SCHED_SCAN_STOPPED,
126 		SCHED_SCAN_RESULTS
127 	} scan_state;
128 
129 	u8 auth_bssid[ETH_ALEN];
130 	u8 auth_attempt_bssid[ETH_ALEN];
131 	u8 bssid[ETH_ALEN];
132 	u8 prev_bssid[ETH_ALEN];
133 	int associated;
134 	u8 ssid[SSID_MAX_LEN];
135 	size_t ssid_len;
136 	enum nl80211_iftype nlmode;
137 	enum nl80211_iftype ap_scan_as_station;
138 	unsigned int assoc_freq;
139 
140 	int monitor_sock;
141 	int monitor_ifidx;
142 	int monitor_refcount;
143 
144 	unsigned int disabled_11b_rates:1;
145 	unsigned int pending_remain_on_chan:1;
146 	unsigned int in_interface_list:1;
147 	unsigned int device_ap_sme:1;
148 	unsigned int poll_command_supported:1;
149 	unsigned int data_tx_status:1;
150 	unsigned int scan_for_auth:1;
151 	unsigned int retry_auth:1;
152 	unsigned int use_monitor:1;
153 	unsigned int ignore_next_local_disconnect:1;
154 	unsigned int ignore_next_local_deauth:1;
155 	unsigned int hostapd:1;
156 	unsigned int start_mode_sta:1;
157 	unsigned int start_iface_up:1;
158 	unsigned int test_use_roc_tx:1;
159 	unsigned int ignore_deauth_event:1;
160 	unsigned int vendor_cmd_test_avail:1;
161 	unsigned int roaming_vendor_cmd_avail:1;
162 	unsigned int dfs_vendor_cmd_avail:1;
163 	unsigned int have_low_prio_scan:1;
164 	unsigned int force_connect_cmd:1;
165 	unsigned int addr_changed:1;
166 	unsigned int get_features_vendor_cmd_avail:1;
167 	unsigned int set_rekey_offload:1;
168 	unsigned int p2p_go_ctwindow_supported:1;
169 	unsigned int setband_vendor_cmd_avail:1;
170 	unsigned int get_pref_freq_list:1;
171 	unsigned int set_prob_oper_freq:1;
172 	unsigned int scan_vendor_cmd_avail:1;
173 	unsigned int connect_reassoc:1;
174 	unsigned int set_wifi_conf_vendor_cmd_avail:1;
175 	unsigned int fetch_bss_trans_status:1;
176 	unsigned int roam_vendor_cmd_avail:1;
177 	unsigned int add_sta_node_vendor_cmd_avail:1;
178 	unsigned int control_port_ap:1;
179 	unsigned int multicast_registrations:1;
180 	unsigned int no_rrm:1;
181 	unsigned int get_sta_info_vendor_cmd_avail:1;
182 	unsigned int fils_discovery:1;
183 	unsigned int unsol_bcast_probe_resp:1;
184 	unsigned int qca_do_acs:1;
185 	unsigned int brcm_do_acs:1;
186 
187 	u64 vendor_scan_cookie;
188 	u64 remain_on_chan_cookie;
189 	u64 send_frame_cookie;
190 #define MAX_SEND_FRAME_COOKIES 20
191 	u64 send_frame_cookies[MAX_SEND_FRAME_COOKIES];
192 	unsigned int num_send_frame_cookies;
193 	u64 eapol_tx_cookie;
194 
195 	unsigned int last_mgmt_freq;
196 
197 	struct wpa_driver_scan_filter *filter_ssids;
198 	size_t num_filter_ssids;
199 
200 	struct i802_bss *first_bss;
201 
202 	int eapol_tx_sock;
203 
204 	int eapol_sock; /* socket for EAPOL frames */
205 
206 	struct nl_sock *rtnl_sk; /* nl_sock for NETLINK_ROUTE */
207 
208 	struct drv_nl80211_if_info default_if_indices[16];
209 	struct drv_nl80211_if_info *if_indices;
210 	int num_if_indices;
211 
212 	/* From failed authentication command */
213 	int auth_freq;
214 	u8 auth_bssid_[ETH_ALEN];
215 	u8 auth_ssid[SSID_MAX_LEN];
216 	size_t auth_ssid_len;
217 	int auth_alg;
218 	u8 *auth_ie;
219 	size_t auth_ie_len;
220 	u8 *auth_data;
221 	size_t auth_data_len;
222 	u8 auth_wep_key[4][16];
223 	size_t auth_wep_key_len[4];
224 	int auth_wep_tx_keyidx;
225 	int auth_local_state_change;
226 	int auth_p2p;
227 
228 	/*
229 	 * Tells whether the last scan issued from wpa_supplicant was a normal
230 	 * scan (NL80211_CMD_TRIGGER_SCAN) or a vendor scan
231 	 * (NL80211_CMD_VENDOR). 0 if no pending scan request.
232 	 */
233 	int last_scan_cmd;
234 #ifdef CONFIG_DRIVER_NL80211_QCA
235 	bool roam_indication_done;
236 	u8 *pending_roam_data;
237 	size_t pending_roam_data_len;
238 	struct os_reltime pending_roam_ind_time;
239 #endif /* CONFIG_DRIVER_NL80211_QCA */
240 };
241 
242 struct nl_msg;
243 
244 void * nl80211_cmd(struct wpa_driver_nl80211_data *drv,
245 		   struct nl_msg *msg, int flags, uint8_t cmd);
246 struct nl_msg * nl80211_cmd_msg(struct i802_bss *bss, int flags, uint8_t cmd);
247 struct nl_msg * nl80211_drv_msg(struct wpa_driver_nl80211_data *drv, int flags,
248 				uint8_t cmd);
249 struct nl_msg * nl80211_bss_msg(struct i802_bss *bss, int flags, uint8_t cmd);
250 int send_and_recv_msgs(struct wpa_driver_nl80211_data *drv, struct nl_msg *msg,
251 		       int (*valid_handler)(struct nl_msg *, void *),
252 		       void *valid_data,
253 		       int (*ack_handler_custom)(struct nl_msg *, void *),
254 		       void *ack_data);
255 struct nl_sock * get_connect_handle(struct i802_bss *bss);
256 int nl80211_create_iface(struct wpa_driver_nl80211_data *drv,
257 			 const char *ifname, enum nl80211_iftype iftype,
258 			 const u8 *addr, int wds,
259 			 int (*handler)(struct nl_msg *, void *),
260 			 void *arg, int use_existing);
261 void nl80211_remove_iface(struct wpa_driver_nl80211_data *drv, int ifidx);
262 unsigned int nl80211_get_assoc_freq(struct wpa_driver_nl80211_data *drv);
263 int nl80211_get_assoc_ssid(struct wpa_driver_nl80211_data *drv, u8 *ssid);
264 enum chan_width convert2width(int width);
265 void nl80211_mark_disconnected(struct wpa_driver_nl80211_data *drv);
266 struct i802_bss * get_bss_ifindex(struct wpa_driver_nl80211_data *drv,
267 				  int ifindex);
268 int is_ap_interface(enum nl80211_iftype nlmode);
269 int is_sta_interface(enum nl80211_iftype nlmode);
270 int wpa_driver_nl80211_authenticate_retry(struct wpa_driver_nl80211_data *drv);
271 int nl80211_get_link_signal(struct wpa_driver_nl80211_data *drv,
272 			    struct wpa_signal_info *sig);
273 int nl80211_get_link_noise(struct wpa_driver_nl80211_data *drv,
274 			   struct wpa_signal_info *sig_change);
275 int nl80211_get_wiphy_index(struct i802_bss *bss);
276 int wpa_driver_nl80211_set_mode(struct i802_bss *bss,
277 				enum nl80211_iftype nlmode);
278 int wpa_driver_nl80211_mlme(struct wpa_driver_nl80211_data *drv,
279 			    const u8 *addr, int cmd, u16 reason_code,
280 			    int local_state_change,
281 			    struct i802_bss *bss);
282 int nl80211_create_monitor_interface(struct wpa_driver_nl80211_data *drv);
283 void nl80211_remove_monitor_interface(struct wpa_driver_nl80211_data *drv);
284 int nl80211_send_monitor(struct wpa_driver_nl80211_data *drv,
285 			 const void *data, size_t len,
286 			 int encrypt, int noack);
287 
288 int wpa_driver_nl80211_capa(struct wpa_driver_nl80211_data *drv);
289 struct hostapd_hw_modes *
290 nl80211_get_hw_feature_data(void *priv, u16 *num_modes, u16 *flags,
291 			    u8 *dfs_domain);
292 
293 int process_global_event(struct nl_msg *msg, void *arg);
294 int process_bss_event(struct nl_msg *msg, void *arg);
295 
296 const char * nl80211_iftype_str(enum nl80211_iftype mode);
297 
298 void nl80211_restore_ap_mode(struct i802_bss *bss);
299 
300 #if defined(ANDROID) || defined(CONFIG_DRIVER_NL80211_HISI)
301 int android_nl_socket_set_nonblocking(struct nl_sock *handle);
302 int android_pno_start(struct i802_bss *bss,
303 		      struct wpa_driver_scan_params *params);
304 int android_pno_stop(struct i802_bss *bss);
305 extern int wpa_driver_nl80211_driver_cmd(void *priv, char *cmd, char *buf,
306 					 size_t buf_len);
307 extern int wpa_driver_nl80211_driver_event(struct wpa_driver_nl80211_data *drv,
308 					   u32 vendor_id, u32 subcmd,
309 					   u8 *data, size_t len);
310 #endif /* ANDROID */
311 
312 #if (defined(ANDROID_P2P) && defined(ANDROID)) || (defined(CONFIG_DRIVER_NL80211_HISI))
313 int wpa_driver_set_p2p_noa(void *priv, u8 count, int start, int duration);
314 int wpa_driver_get_p2p_noa(void *priv, u8 *buf, size_t len);
315 int wpa_driver_set_p2p_ps(void *priv, int legacy_ps, int opp_ps, int ctwindow);
316 int wpa_driver_set_ap_wps_p2p_ie(void *priv, const struct wpabuf *beacon,
317 				 const struct wpabuf *proberesp,
318 				 const struct wpabuf *assocresp);
319 #endif /* (ANDROID_P2P && ANDROID) || CONFIG_DRIVER_NL80211_HISI */
320 
321 
322 /* driver_nl80211_scan.c */
323 
324 void wpa_driver_nl80211_scan_timeout(void *eloop_ctx, void *timeout_ctx);
325 int wpa_driver_nl80211_scan(struct i802_bss *bss,
326 			    struct wpa_driver_scan_params *params);
327 int wpa_driver_nl80211_sched_scan(void *priv,
328 				  struct wpa_driver_scan_params *params);
329 int wpa_driver_nl80211_stop_sched_scan(void *priv);
330 struct wpa_scan_results * wpa_driver_nl80211_get_scan_results(void *priv);
331 void nl80211_dump_scan(struct wpa_driver_nl80211_data *drv);
332 int wpa_driver_nl80211_abort_scan(void *priv, u64 scan_cookie);
333 int wpa_driver_nl80211_vendor_scan(struct i802_bss *bss,
334 				   struct wpa_driver_scan_params *params);
335 int nl80211_set_default_scan_ies(void *priv, const u8 *ies, size_t ies_len);
336 
337 #endif /* DRIVER_NL80211_H */
338