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  	unsigned int nl80211_maxattr;
36  	int nlctrl_id;
37  	int ioctl_sock; /* socket for ioctl() use */
38  
39  	struct nl_sock *nl_event;
40  };
41  
42  struct nl80211_wiphy_data {
43  	struct dl_list list;
44  	struct dl_list bsss;
45  	struct dl_list drvs;
46  
47  	struct nl_sock *nl_beacons;
48  	struct nl_cb *nl_cb;
49  
50  	int wiphy_idx;
51  };
52  
53  #define NL80211_DRV_LINK_ID_NA (-1)
54  
55  struct i802_link {
56  	unsigned int beacon_set:1;
57  
58  	int freq;
59  	int bandwidth;
60  	u8 addr[ETH_ALEN];
61  	void *ctx;
62  };
63  
64  struct i802_bss {
65  	struct wpa_driver_nl80211_data *drv;
66  	struct i802_bss *next;
67  
68  	u16 valid_links;
69  	struct i802_link links[MAX_NUM_MLD_LINKS];
70  	struct i802_link *flink, *scan_link;
71  
72  	int ifindex;
73  	int br_ifindex;
74  	u64 wdev_id;
75  	char ifname[IFNAMSIZ + 1];
76  	char brname[IFNAMSIZ];
77  	unsigned int added_if_into_bridge:1;
78  	unsigned int already_in_bridge:1;
79  	unsigned int added_bridge:1;
80  	unsigned int in_deinit:1;
81  	unsigned int wdev_id_set:1;
82  	unsigned int added_if:1;
83  	unsigned int static_ap:1;
84  
85  	u8 addr[ETH_ALEN];
86  	u8 prev_addr[ETH_ALEN];
87  
88  	int if_dynamic;
89  
90  	void *ctx;
91  	struct nl_sock *nl_preq, *nl_mgmt, *nl_connect;
92  	struct nl_cb *nl_cb;
93  
94  	struct nl80211_wiphy_data *wiphy_data;
95  	struct dl_list wiphy_list;
96  	u8 rand_addr[ETH_ALEN];
97  };
98  
99  struct drv_nl80211_if_info {
100  	int ifindex;
101  	/* the AP/AP_VLAN iface that is in this bridge */
102  	int reason;
103  };
104  
105  struct wpa_driver_nl80211_data {
106  	struct nl80211_global *global;
107  	struct dl_list list;
108  	struct dl_list wiphy_list;
109  	char phyname[32];
110  	unsigned int wiphy_idx;
111  	u8 perm_addr[ETH_ALEN];
112  	void *ctx;
113  	int ifindex;
114  	int if_removed;
115  	int if_disabled;
116  	int ignore_if_down_event;
117  	struct rfkill_data *rfkill;
118  	struct wpa_driver_capa capa;
119  	u8 *extended_capa, *extended_capa_mask;
120  	unsigned int extended_capa_len;
121  	struct drv_nl80211_iface_capa {
122  		enum nl80211_iftype iftype;
123  		u8 *ext_capa, *ext_capa_mask;
124  		unsigned int ext_capa_len;
125  		u16 eml_capa;
126  		u16 mld_capa_and_ops;
127  	} iface_capa[NL80211_IFTYPE_MAX];
128  	unsigned int num_iface_capa;
129  
130  	int has_capability;
131  	int has_driver_key_mgmt;
132  
133  	int operstate;
134  
135  	int scan_complete_events;
136  	enum scan_states {
137  		NO_SCAN, SCAN_REQUESTED, SCAN_STARTED, SCAN_COMPLETED,
138  		SCAN_ABORTED, SCHED_SCAN_STARTED, SCHED_SCAN_STOPPED,
139  		SCHED_SCAN_RESULTS
140  	} scan_state;
141  
142  	u8 auth_bssid[ETH_ALEN];
143  	u8 auth_attempt_bssid[ETH_ALEN];
144  	u8 bssid[ETH_ALEN];
145  	u8 prev_bssid[ETH_ALEN];
146  	int associated;
147  	struct driver_sta_mlo_info sta_mlo_info;
148  	u8 ssid[SSID_MAX_LEN];
149  	size_t ssid_len;
150  	enum nl80211_iftype nlmode;
151  	enum nl80211_iftype ap_scan_as_station;
152  	unsigned int assoc_freq;
153  
154  	unsigned int disabled_11b_rates:1;
155  	unsigned int pending_remain_on_chan:1;
156  	unsigned int in_interface_list:1;
157  	unsigned int device_ap_sme:1;
158  	unsigned int poll_command_supported:1;
159  	unsigned int data_tx_status:1;
160  	unsigned int scan_for_auth:1;
161  	unsigned int retry_auth:1;
162  	unsigned int hostapd:1;
163  	unsigned int start_mode_sta:1;
164  	unsigned int start_iface_up:1;
165  	unsigned int test_use_roc_tx:1;
166  	unsigned int ignore_deauth_event:1;
167  	unsigned int vendor_cmd_test_avail:1;
168  	unsigned int roaming_vendor_cmd_avail:1;
169  	unsigned int dfs_vendor_cmd_avail:1;
170  	unsigned int have_low_prio_scan:1;
171  	unsigned int force_connect_cmd:1;
172  	unsigned int addr_changed:1;
173  	unsigned int get_features_vendor_cmd_avail:1;
174  	unsigned int set_rekey_offload:1;
175  	unsigned int p2p_go_ctwindow_supported:1;
176  	unsigned int setband_vendor_cmd_avail:1;
177  	unsigned int get_pref_freq_list:1;
178  	unsigned int set_prob_oper_freq:1;
179  	unsigned int scan_vendor_cmd_avail:1;
180  	unsigned int connect_reassoc:1;
181  	unsigned int set_wifi_conf_vendor_cmd_avail:1;
182  	unsigned int fetch_bss_trans_status:1;
183  	unsigned int roam_vendor_cmd_avail:1;
184  	unsigned int add_sta_node_vendor_cmd_avail:1;
185  	unsigned int control_port_ap:1;
186  	unsigned int multicast_registrations:1;
187  	unsigned int no_rrm:1;
188  	unsigned int get_sta_info_vendor_cmd_avail:1;
189  	unsigned int fils_discovery:1;
190  	unsigned int unsol_bcast_probe_resp:1;
191  	unsigned int qca_do_acs:1;
192  	unsigned int brcm_do_acs:1;
193  	unsigned int uses_6ghz:1;
194  	unsigned int uses_s1g:1;
195  	unsigned int secure_ranging_ctx_vendor_cmd_avail:1;
196  	unsigned int puncturing:1;
197  	unsigned int qca_ap_allowed_freqs:1;
198  	unsigned int connect_ext_vendor_cmd_avail:1;
199  
200  	u8 extra_bss_membership_selectors[8];
201  
202  	u32 ignore_next_local_disconnect;
203  	u32 ignore_next_local_deauth;
204  
205  	u64 vendor_scan_cookie;
206  	u64 remain_on_chan_cookie;
207  	u64 send_frame_cookie;
208  	int send_frame_link_id;
209  #define MAX_SEND_FRAME_COOKIES 20
210  	u64 send_frame_cookies[MAX_SEND_FRAME_COOKIES];
211  	unsigned int num_send_frame_cookies;
212  	u64 eapol_tx_cookie;
213  	int eapol_tx_link_id;
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  	bool auth_mld;
248  	u8 auth_mld_link_id;
249  	u8 auth_ap_mld_addr[ETH_ALEN];
250  
251  	/*
252  	 * Tells whether the last scan issued from wpa_supplicant was a normal
253  	 * scan (NL80211_CMD_TRIGGER_SCAN) or a vendor scan
254  	 * (NL80211_CMD_VENDOR). 0 if no pending scan request.
255  	 */
256  	int last_scan_cmd;
257  #ifdef CONFIG_DRIVER_NL80211_QCA
258  	bool roam_indication_done;
259  	u8 *pending_roam_data;
260  	size_t pending_roam_data_len;
261  	u8 *pending_t2lm_data;
262  	size_t pending_t2lm_data_len;
263  	u8 *pending_link_reconfig_data;
264  	size_t pending_link_reconfig_data_len;
265  #endif /* CONFIG_DRIVER_NL80211_QCA */
266  };
267  
268  struct nl_msg;
269  
270  struct nl80211_err_info {
271  	int link_id;
272  };
273  
274  void * nl80211_cmd(struct wpa_driver_nl80211_data *drv,
275  		   struct nl_msg *msg, int flags, uint8_t cmd);
276  struct nl_msg * nl80211_cmd_msg(struct i802_bss *bss, int flags, uint8_t cmd);
277  struct nl_msg * nl80211_drv_msg(struct wpa_driver_nl80211_data *drv, int flags,
278  				uint8_t cmd);
279  struct nl_msg * nl80211_bss_msg(struct i802_bss *bss, int flags, uint8_t cmd);
280  
281  int send_and_recv_glb(struct nl80211_global *global,
282  		      struct wpa_driver_nl80211_data *drv, /* may be NULL */
283  		      struct nl_sock *nl_handle, struct nl_msg *msg,
284  		      int (*valid_handler)(struct nl_msg *, void *),
285  		      void *valid_data,
286  		      int (*ack_handler_custom)(struct nl_msg *, void *),
287  		      void *ack_data,
288  		      struct nl80211_err_info *err_info);
289  
290  static inline int
send_and_recv(struct wpa_driver_nl80211_data * drv,struct nl_sock * nl_handle,struct nl_msg * msg,int (* valid_handler)(struct nl_msg *,void *),void * valid_data,int (* ack_handler_custom)(struct nl_msg *,void *),void * ack_data,struct nl80211_err_info * err_info)291  send_and_recv(struct wpa_driver_nl80211_data *drv,
292  	      struct nl_sock *nl_handle, struct nl_msg *msg,
293  	      int (*valid_handler)(struct nl_msg *, void *),
294  	      void *valid_data,
295  	      int (*ack_handler_custom)(struct nl_msg *, void *),
296  	      void *ack_data,
297  	      struct nl80211_err_info *err_info)
298  {
299  	return send_and_recv_glb(drv->global, drv, nl_handle, msg,
300  				 valid_handler, valid_data,
301  				 ack_handler_custom, ack_data, err_info);
302  }
303  
304  static inline int
send_and_recv_cmd(struct wpa_driver_nl80211_data * drv,struct nl_msg * msg)305  send_and_recv_cmd(struct wpa_driver_nl80211_data *drv,
306  		  struct nl_msg *msg)
307  {
308  	return send_and_recv(drv, drv->global->nl, msg,
309  			     NULL, NULL, NULL, NULL, NULL);
310  }
311  
312  static inline int
send_and_recv_resp(struct wpa_driver_nl80211_data * drv,struct nl_msg * msg,int (* valid_handler)(struct nl_msg *,void *),void * valid_data)313  send_and_recv_resp(struct wpa_driver_nl80211_data *drv,
314  		   struct nl_msg *msg,
315  		   int (*valid_handler)(struct nl_msg *, void *),
316  		   void *valid_data)
317  {
318  	return send_and_recv(drv, drv->global->nl, msg,
319  			     valid_handler, valid_data, NULL, NULL, NULL);
320  }
321  
322  int nl80211_create_iface(struct wpa_driver_nl80211_data *drv,
323  			 const char *ifname, enum nl80211_iftype iftype,
324  			 const u8 *addr, int wds,
325  			 int (*handler)(struct nl_msg *, void *),
326  			 void *arg, int use_existing);
327  void nl80211_remove_iface(struct wpa_driver_nl80211_data *drv, int ifidx);
328  unsigned int nl80211_get_assoc_freq(struct wpa_driver_nl80211_data *drv);
329  int nl80211_get_assoc_ssid(struct wpa_driver_nl80211_data *drv, u8 *ssid);
330  enum chan_width convert2width(int width);
331  void nl80211_mark_disconnected(struct wpa_driver_nl80211_data *drv);
332  struct i802_bss * get_bss_ifindex(struct wpa_driver_nl80211_data *drv,
333  				  int ifindex);
334  int is_ap_interface(enum nl80211_iftype nlmode);
335  int is_sta_interface(enum nl80211_iftype nlmode);
336  int wpa_driver_nl80211_authenticate_retry(struct wpa_driver_nl80211_data *drv);
337  int nl80211_get_link_signal(struct wpa_driver_nl80211_data *drv,
338  			    const u8 *bssid,
339  			    struct hostap_sta_driver_data *data);
340  int nl80211_get_link_noise(struct wpa_driver_nl80211_data *drv,
341  			   struct wpa_signal_info *sig_change);
342  int nl80211_get_wiphy_index(struct i802_bss *bss);
343  int wpa_driver_nl80211_set_mode(struct i802_bss *bss,
344  				enum nl80211_iftype nlmode);
345  int wpa_driver_nl80211_mlme(struct wpa_driver_nl80211_data *drv,
346  			    const u8 *addr, int cmd, u16 reason_code,
347  			    int local_state_change,
348  			    struct i802_bss *bss);
349  
350  int nl80211_send_monitor(struct wpa_driver_nl80211_data *drv,
351  			 const void *data, size_t len,
352  			 int encrypt, int noack);
353  
354  int wpa_driver_nl80211_capa(struct wpa_driver_nl80211_data *drv);
355  struct hostapd_hw_modes *
356  nl80211_get_hw_feature_data(void *priv, u16 *num_modes, u16 *flags,
357  			    u8 *dfs_domain);
358  
359  int process_global_event(struct nl_msg *msg, void *arg);
360  int process_bss_event(struct nl_msg *msg, void *arg);
361  
362  const char * nl80211_iftype_str(enum nl80211_iftype mode);
363  
364  void nl80211_restore_ap_mode(struct i802_bss *bss);
365  struct i802_link * nl80211_get_link(struct i802_bss *bss, s8 link_id);
366  u8 nl80211_get_link_id_from_link(struct i802_bss *bss, struct i802_link *link);
367  int nl80211_remove_link(struct i802_bss *bss, int link_id);
368  
nl80211_link_valid(u16 links,s8 link_id)369  static inline bool nl80211_link_valid(u16 links, s8 link_id)
370  {
371  	if (link_id < 0 || link_id >= MAX_NUM_MLD_LINKS)
372  		return false;
373  
374  	if (links & BIT(link_id))
375  		return true;
376  
377  	return false;
378  }
379  
380  
381  static inline bool
nl80211_attr_supported(struct wpa_driver_nl80211_data * drv,unsigned int attr)382  nl80211_attr_supported(struct wpa_driver_nl80211_data *drv, unsigned int attr)
383  {
384  	return attr <= drv->global->nl80211_maxattr;
385  }
386  
387  #ifdef ANDROID
388  int android_nl_socket_set_nonblocking(struct nl_sock *handle);
389  int android_pno_start(struct i802_bss *bss,
390  		      struct wpa_driver_scan_params *params);
391  int android_pno_stop(struct i802_bss *bss);
392  extern int wpa_driver_nl80211_driver_cmd(void *priv, char *cmd, char *buf,
393  					 size_t buf_len);
394  extern int wpa_driver_nl80211_driver_event(struct wpa_driver_nl80211_data *drv,
395  					   u32 vendor_id, u32 subcmd,
396  					   u8 *data, size_t len);
397  
398  
399  #ifdef ANDROID_P2P
400  int wpa_driver_set_p2p_noa(void *priv, u8 count, int start, int duration);
401  int wpa_driver_get_p2p_noa(void *priv, u8 *buf, size_t len);
402  int wpa_driver_set_p2p_ps(void *priv, int legacy_ps, int opp_ps, int ctwindow);
403  int wpa_driver_set_ap_wps_p2p_ie(void *priv, const struct wpabuf *beacon,
404  				 const struct wpabuf *proberesp,
405  				 const struct wpabuf *assocresp);
406  #endif /* ANDROID_P2P */
407  #endif /* ANDROID */
408  
409  
410  /* driver_nl80211_scan.c */
411  
412  void wpa_driver_nl80211_scan_timeout(void *eloop_ctx, void *timeout_ctx);
413  int wpa_driver_nl80211_scan(struct i802_bss *bss,
414  			    struct wpa_driver_scan_params *params);
415  int wpa_driver_nl80211_sched_scan(void *priv,
416  				  struct wpa_driver_scan_params *params);
417  int wpa_driver_nl80211_stop_sched_scan(void *priv);
418  struct wpa_scan_results * wpa_driver_nl80211_get_scan_results(void *priv,
419  							      const u8 *bssid);
420  void nl80211_dump_scan(struct wpa_driver_nl80211_data *drv);
421  int wpa_driver_nl80211_abort_scan(void *priv, u64 scan_cookie);
422  int wpa_driver_nl80211_vendor_scan(struct i802_bss *bss,
423  				   struct wpa_driver_scan_params *params);
424  int nl80211_set_default_scan_ies(void *priv, const u8 *ies, size_t ies_len);
425  struct hostapd_multi_hw_info *
426  nl80211_get_multi_hw_info(struct i802_bss *bss, unsigned int *num_multi_hws);
427  u32 get_nl80211_protocol_features(struct wpa_driver_nl80211_data *drv);
428  
429  #endif /* DRIVER_NL80211_H */
430