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