• 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 #ifdef CONFIG_MLD_PATCH
52 #define NL80211_DRV_LINK_ID_NA (-1)
53 
54 struct i802_link {
55 	unsigned int beacon_set:1;
56 
57 	s8 link_id;
58 	int freq;
59 	int bandwidth;
60 	u8 addr[ETH_ALEN];
61 	void *ctx;
62 };
63 #endif
64 struct i802_bss {
65 	struct wpa_driver_nl80211_data *drv;
66 	struct i802_bss *next;
67 #ifdef CONFIG_MLD_PATCH
68 	u16 valid_links;
69 	struct i802_link links[MAX_NUM_MLD_LINKS];
70 	struct i802_link *flink;
71 #endif
72 	int ifindex;
73 	int br_ifindex;
74 	u64 wdev_id;
75 	char ifname[IFNAMSIZ + 1];
76 	char brname[IFNAMSIZ];
77 	unsigned int beacon_set:1;
78 	unsigned int added_if_into_bridge:1;
79 	unsigned int already_in_bridge:1;
80 	unsigned int added_bridge:1;
81 	unsigned int in_deinit:1;
82 	unsigned int wdev_id_set:1;
83 	unsigned int added_if:1;
84 	unsigned int static_ap:1;
85 	unsigned int use_nl_connect:1;
86 #ifdef CONFIG_VENDOR_EXT
87 	unsigned int p2p_enhance_iface:1;   /* vendor extension */
88 #endif
89 
90 	u8 addr[ETH_ALEN];
91 
92 	int freq;
93 	int bandwidth;
94 	int if_dynamic;
95 
96 	void *ctx;
97 	struct nl_sock *nl_preq, *nl_mgmt, *nl_connect;
98 	struct nl_cb *nl_cb;
99 
100 	struct nl80211_wiphy_data *wiphy_data;
101 	struct dl_list wiphy_list;
102 	u8 rand_addr[ETH_ALEN];
103 };
104 
105 struct drv_nl80211_if_info {
106 	int ifindex;
107 	/* the AP/AP_VLAN iface that is in this bridge */
108 	int reason;
109 };
110 
111 struct wpa_driver_nl80211_data {
112 	struct nl80211_global *global;
113 	struct dl_list list;
114 	struct dl_list wiphy_list;
115 	char phyname[32];
116 	unsigned int wiphy_idx;
117 	u8 perm_addr[ETH_ALEN];
118 	void *ctx;
119 	int ifindex;
120 	int if_removed;
121 	int if_disabled;
122 	int ignore_if_down_event;
123 	struct rfkill_data *rfkill;
124 	struct wpa_driver_capa capa;
125 	u8 *extended_capa, *extended_capa_mask;
126 	unsigned int extended_capa_len;
127 	struct drv_nl80211_ext_capa {
128 		enum nl80211_iftype iftype;
129 		u8 *ext_capa, *ext_capa_mask;
130 		unsigned int ext_capa_len;
131 	} iface_ext_capa[NL80211_IFTYPE_MAX];
132 	unsigned int num_iface_ext_capa;
133 
134 	int has_capability;
135 	int has_driver_key_mgmt;
136 
137 	int operstate;
138 
139 	int scan_complete_events;
140 	enum scan_states {
141 		NO_SCAN, SCAN_REQUESTED, SCAN_STARTED, SCAN_COMPLETED,
142 		SCAN_ABORTED, SCHED_SCAN_STARTED, SCHED_SCAN_STOPPED,
143 		SCHED_SCAN_RESULTS
144 	} scan_state;
145 
146 	u8 auth_bssid[ETH_ALEN];
147 	u8 auth_attempt_bssid[ETH_ALEN];
148 	u8 bssid[ETH_ALEN];
149 	u8 prev_bssid[ETH_ALEN];
150 	int associated;
151 #ifdef CONFIG_MLD_PATCH
152 	struct driver_sta_mlo_info sta_mlo_info;
153 #endif
154 	u8 ssid[SSID_MAX_LEN];
155 	size_t ssid_len;
156 	enum nl80211_iftype nlmode;
157 	enum nl80211_iftype ap_scan_as_station;
158 	unsigned int assoc_freq;
159 
160 	int monitor_sock;
161 	int monitor_ifidx;
162 	int monitor_refcount;
163 
164 	unsigned int disabled_11b_rates:1;
165 	unsigned int pending_remain_on_chan:1;
166 	unsigned int in_interface_list:1;
167 	unsigned int device_ap_sme:1;
168 	unsigned int poll_command_supported:1;
169 	unsigned int data_tx_status:1;
170 	unsigned int scan_for_auth:1;
171 	unsigned int retry_auth:1;
172 	unsigned int use_monitor:1;
173 	unsigned int ignore_next_local_disconnect:1;
174 	unsigned int ignore_next_local_deauth:1;
175 	unsigned int hostapd:1;
176 	unsigned int start_mode_sta:1;
177 	unsigned int start_iface_up:1;
178 	unsigned int test_use_roc_tx:1;
179 	unsigned int ignore_deauth_event:1;
180 	unsigned int vendor_cmd_test_avail:1;
181 	unsigned int roaming_vendor_cmd_avail:1;
182 	unsigned int dfs_vendor_cmd_avail:1;
183 	unsigned int have_low_prio_scan:1;
184 	unsigned int force_connect_cmd:1;
185 	unsigned int addr_changed:1;
186 	unsigned int get_features_vendor_cmd_avail:1;
187 	unsigned int set_rekey_offload:1;
188 	unsigned int p2p_go_ctwindow_supported:1;
189 	unsigned int setband_vendor_cmd_avail:1;
190 	unsigned int get_pref_freq_list:1;
191 	unsigned int set_prob_oper_freq:1;
192 	unsigned int scan_vendor_cmd_avail:1;
193 	unsigned int connect_reassoc:1;
194 	unsigned int set_wifi_conf_vendor_cmd_avail:1;
195 	unsigned int fetch_bss_trans_status:1;
196 	unsigned int roam_vendor_cmd_avail:1;
197 	unsigned int add_sta_node_vendor_cmd_avail:1;
198 	unsigned int control_port_ap:1;
199 	unsigned int multicast_registrations:1;
200 	unsigned int no_rrm:1;
201 	unsigned int get_sta_info_vendor_cmd_avail:1;
202 	unsigned int fils_discovery:1;
203 	unsigned int unsol_bcast_probe_resp:1;
204 	unsigned int qca_do_acs:1;
205 	unsigned int brcm_do_acs:1;
206 
207 	u64 vendor_scan_cookie;
208 	u64 remain_on_chan_cookie;
209 	u64 send_frame_cookie;
210 #define MAX_SEND_FRAME_COOKIES 20
211 	u64 send_frame_cookies[MAX_SEND_FRAME_COOKIES];
212 	unsigned int num_send_frame_cookies;
213 	u64 eapol_tx_cookie;
214 
215 	unsigned int last_mgmt_freq;
216 
217 	struct wpa_driver_scan_filter *filter_ssids;
218 	size_t num_filter_ssids;
219 
220 	struct i802_bss *first_bss;
221 
222 	int eapol_tx_sock;
223 
224 	int eapol_sock; /* socket for EAPOL frames */
225 
226 	struct nl_sock *rtnl_sk; /* nl_sock for NETLINK_ROUTE */
227 
228 	struct drv_nl80211_if_info default_if_indices[16];
229 	struct drv_nl80211_if_info *if_indices;
230 	int num_if_indices;
231 
232 	/* From failed authentication command */
233 	int auth_freq;
234 	u8 auth_bssid_[ETH_ALEN];
235 	u8 auth_ssid[SSID_MAX_LEN];
236 	size_t auth_ssid_len;
237 	int auth_alg;
238 	u8 *auth_ie;
239 	size_t auth_ie_len;
240 	u8 *auth_data;
241 	size_t auth_data_len;
242 	u8 auth_wep_key[4][16];
243 	size_t auth_wep_key_len[4];
244 	int auth_wep_tx_keyidx;
245 	int auth_local_state_change;
246 	int auth_p2p;
247 #ifdef CONFIG_MLD_PATCH
248 	bool auth_mld;
249 	u8 auth_mld_link_id;
250 	u8 auth_ap_mld_addr[ETH_ALEN];
251 #endif
252 	/*
253 	 * Tells whether the last scan issued from wpa_supplicant was a normal
254 	 * scan (NL80211_CMD_TRIGGER_SCAN) or a vendor scan
255 	 * (NL80211_CMD_VENDOR). 0 if no pending scan request.
256 	 */
257 	int last_scan_cmd;
258 #ifdef CONFIG_DRIVER_NL80211_QCA
259 	bool roam_indication_done;
260 	u8 *pending_roam_data;
261 	size_t pending_roam_data_len;
262 	struct os_reltime pending_roam_ind_time;
263 #endif /* CONFIG_DRIVER_NL80211_QCA */
264 };
265 
266 struct nl_msg;
267 
268 void * nl80211_cmd(struct wpa_driver_nl80211_data *drv,
269 		   struct nl_msg *msg, int flags, uint8_t cmd);
270 struct nl_msg * nl80211_cmd_msg(struct i802_bss *bss, int flags, uint8_t cmd);
271 struct nl_msg * nl80211_drv_msg(struct wpa_driver_nl80211_data *drv, int flags,
272 				uint8_t cmd);
273 struct nl_msg * nl80211_bss_msg(struct i802_bss *bss, int flags, uint8_t cmd);
274 int send_and_recv_msgs(struct wpa_driver_nl80211_data *drv, struct nl_msg *msg,
275 		       int (*valid_handler)(struct nl_msg *, void *),
276 		       void *valid_data,
277 		       int (*ack_handler_custom)(struct nl_msg *, void *),
278 		       void *ack_data);
279 struct nl_sock * get_connect_handle(struct i802_bss *bss);
280 int nl80211_create_iface(struct wpa_driver_nl80211_data *drv,
281 			 const char *ifname, enum nl80211_iftype iftype,
282 			 const u8 *addr, int wds,
283 			 int (*handler)(struct nl_msg *, void *),
284 			 void *arg, int use_existing);
285 void nl80211_remove_iface(struct wpa_driver_nl80211_data *drv, int ifidx);
286 unsigned int nl80211_get_assoc_freq(struct wpa_driver_nl80211_data *drv);
287 int nl80211_get_assoc_ssid(struct wpa_driver_nl80211_data *drv, u8 *ssid);
288 enum chan_width convert2width(int width);
289 void nl80211_mark_disconnected(struct wpa_driver_nl80211_data *drv);
290 struct i802_bss * get_bss_ifindex(struct wpa_driver_nl80211_data *drv,
291 				  int ifindex);
292 int is_ap_interface(enum nl80211_iftype nlmode);
293 int is_sta_interface(enum nl80211_iftype nlmode);
294 int wpa_driver_nl80211_authenticate_retry(struct wpa_driver_nl80211_data *drv);
295 int nl80211_get_link_signal(struct wpa_driver_nl80211_data *drv,
296 			    struct wpa_signal_info *sig);
297 int nl80211_get_link_noise(struct wpa_driver_nl80211_data *drv,
298 			   struct wpa_signal_info *sig_change);
299 int nl80211_get_wiphy_index(struct i802_bss *bss);
300 int wpa_driver_nl80211_set_mode(struct i802_bss *bss,
301 				enum nl80211_iftype nlmode);
302 int wpa_driver_nl80211_mlme(struct wpa_driver_nl80211_data *drv,
303 			    const u8 *addr, int cmd, u16 reason_code,
304 			    int local_state_change,
305 			    struct i802_bss *bss);
306 int nl80211_create_monitor_interface(struct wpa_driver_nl80211_data *drv);
307 void nl80211_remove_monitor_interface(struct wpa_driver_nl80211_data *drv);
308 int nl80211_send_monitor(struct wpa_driver_nl80211_data *drv,
309 			 const void *data, size_t len,
310 			 int encrypt, int noack);
311 
312 int wpa_driver_nl80211_capa(struct wpa_driver_nl80211_data *drv);
313 struct hostapd_hw_modes *
314 nl80211_get_hw_feature_data(void *priv, u16 *num_modes, u16 *flags,
315 			    u8 *dfs_domain);
316 
317 int process_global_event(struct nl_msg *msg, void *arg);
318 int process_bss_event(struct nl_msg *msg, void *arg);
319 
320 const char * nl80211_iftype_str(enum nl80211_iftype mode);
321 
322 void nl80211_restore_ap_mode(struct i802_bss *bss);
323 #ifdef CONFIG_MLD_PATCH
nl80211_link_valid(u16 links,s8 link_id)324 static inline bool nl80211_link_valid(u16 links, s8 link_id)
325 {
326 	if (link_id < 0 || link_id >= MAX_NUM_MLD_LINKS)
327 		return false;
328 
329 	if (links & BIT(link_id))
330 		return true;
331 
332 	return false;
333 }
334 #endif
335 
336 #if defined(ANDROID) || defined(CONFIG_DRIVER_NL80211_HISI)
337 int android_nl_socket_set_nonblocking(struct nl_sock *handle);
338 int android_pno_start(struct i802_bss *bss,
339 		      struct wpa_driver_scan_params *params);
340 int android_pno_stop(struct i802_bss *bss);
341 extern int wpa_driver_nl80211_driver_cmd(void *priv, char *cmd, char *buf,
342 					 size_t buf_len);
343 extern int wpa_driver_nl80211_driver_event(struct wpa_driver_nl80211_data *drv,
344 					   u32 vendor_id, u32 subcmd,
345 					   u8 *data, size_t len);
346 #endif /* ANDROID */
347 
348 #if (defined(ANDROID_P2P) && defined(ANDROID)) || (defined(CONFIG_DRIVER_NL80211_HISI))
349 int wpa_driver_set_p2p_noa(void *priv, u8 count, int start, int duration);
350 int wpa_driver_get_p2p_noa(void *priv, u8 *buf, size_t len);
351 int wpa_driver_set_p2p_ps(void *priv, int legacy_ps, int opp_ps, int ctwindow);
352 int wpa_driver_set_ap_wps_p2p_ie(void *priv, const struct wpabuf *beacon,
353 				 const struct wpabuf *proberesp,
354 				 const struct wpabuf *assocresp);
355 #endif /* (ANDROID_P2P && ANDROID) || CONFIG_DRIVER_NL80211_HISI */
356 
357 
358 /* driver_nl80211_scan.c */
359 
360 void wpa_driver_nl80211_scan_timeout(void *eloop_ctx, void *timeout_ctx);
361 int wpa_driver_nl80211_scan(struct i802_bss *bss,
362 			    struct wpa_driver_scan_params *params);
363 int wpa_driver_nl80211_sched_scan(void *priv,
364 				  struct wpa_driver_scan_params *params);
365 int wpa_driver_nl80211_stop_sched_scan(void *priv);
366 struct wpa_scan_results * wpa_driver_nl80211_get_scan_results(void *priv);
367 void nl80211_dump_scan(struct wpa_driver_nl80211_data *drv);
368 int wpa_driver_nl80211_abort_scan(void *priv, u64 scan_cookie);
369 int wpa_driver_nl80211_vendor_scan(struct i802_bss *bss,
370 				   struct wpa_driver_scan_params *params);
371 int nl80211_set_default_scan_ies(void *priv, const u8 *ies, size_t ies_len);
372 
373 #endif /* DRIVER_NL80211_H */
374