blob: c597295643bf738b3b6f1e8a2e45a0e88f645f1b [file] [log] [blame]
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001/*
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
Hai Shalomfdcde762020-04-02 11:19:20 -070020#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
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080024
25struct nl80211_global {
Dmitry Shmidte4663042016-04-04 10:07:49 -070026 void *ctx;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080027 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;
Hai Shalomfdcde762020-04-02 11:19:20 -070033 struct nl_sock *nl;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080034 int nl80211_id;
Hai Shalomc1a21442022-02-04 13:43:00 -080035 int nlctrl_id;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080036 int ioctl_sock; /* socket for ioctl() use */
Hai Shalomfdcde762020-04-02 11:19:20 -070037 struct nl_sock *nl_event;
Mir Ali8a8f1002020-10-06 22:41:40 +053038 u8 p2p_perm_addr[ETH_ALEN];
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080039};
40
41struct nl80211_wiphy_data {
42 struct dl_list list;
43 struct dl_list bsss;
44 struct dl_list drvs;
45
Hai Shalomfdcde762020-04-02 11:19:20 -070046 struct nl_sock *nl_beacons;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080047 struct nl_cb *nl_cb;
48
49 int wiphy_idx;
50};
51
Sunil Ravi036cec52023-03-29 11:35:17 -070052#define NL80211_DRV_LINK_ID_NA (-1)
53
54struct 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
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080064struct i802_bss {
65 struct wpa_driver_nl80211_data *drv;
66 struct i802_bss *next;
Sunil Ravi036cec52023-03-29 11:35:17 -070067
68 size_t n_links;
69 struct i802_link links[MAX_NUM_MLD_LINKS];
70 struct i802_link *flink;
71
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080072 int ifindex;
73 int br_ifindex;
74 u64 wdev_id;
75 char ifname[IFNAMSIZ + 1];
76 char brname[IFNAMSIZ];
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080077 unsigned int added_if_into_bridge:1;
Hai Shalomc9e41a12018-07-31 14:41:42 -070078 unsigned int already_in_bridge:1;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080079 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;
Hai Shalom74f70d42019-02-11 14:42:39 -080084 unsigned int use_nl_connect:1;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080085
86 u8 addr[ETH_ALEN];
Sunil Ravi77d572f2023-01-17 23:58:31 +000087 u8 prev_addr[ETH_ALEN];
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080088
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080089 int if_dynamic;
90
91 void *ctx;
Hai Shalomfdcde762020-04-02 11:19:20 -070092 struct nl_sock *nl_preq, *nl_mgmt, *nl_connect;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080093 struct nl_cb *nl_cb;
94
95 struct nl80211_wiphy_data *wiphy_data;
96 struct dl_list wiphy_list;
Dmitry Shmidtebd93af2017-02-21 13:40:44 -080097 u8 rand_addr[ETH_ALEN];
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080098};
99
Hai Shalom81f62d82019-07-22 12:10:00 -0700100struct drv_nl80211_if_info {
101 int ifindex;
102 /* the AP/AP_VLAN iface that is in this bridge */
103 int reason;
104};
105
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800106struct wpa_driver_nl80211_data {
107 struct nl80211_global *global;
108 struct dl_list list;
109 struct dl_list wiphy_list;
110 char phyname[32];
Dmitry Shmidt7d56b752015-12-22 10:59:44 -0800111 unsigned int wiphy_idx;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800112 u8 perm_addr[ETH_ALEN];
113 void *ctx;
114 int ifindex;
115 int if_removed;
116 int if_disabled;
117 int ignore_if_down_event;
118 struct rfkill_data *rfkill;
119 struct wpa_driver_capa capa;
120 u8 *extended_capa, *extended_capa_mask;
121 unsigned int extended_capa_len;
Dmitry Shmidtd5ab1b52016-06-21 12:38:41 -0700122 struct drv_nl80211_ext_capa {
123 enum nl80211_iftype iftype;
124 u8 *ext_capa, *ext_capa_mask;
125 unsigned int ext_capa_len;
126 } iface_ext_capa[NL80211_IFTYPE_MAX];
127 unsigned int num_iface_ext_capa;
128
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800129 int has_capability;
Hai Shalom4fbc08f2020-05-18 12:37:00 -0700130 int has_driver_key_mgmt;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800131
132 int operstate;
133
134 int scan_complete_events;
135 enum scan_states {
136 NO_SCAN, SCAN_REQUESTED, SCAN_STARTED, SCAN_COMPLETED,
137 SCAN_ABORTED, SCHED_SCAN_STARTED, SCHED_SCAN_STOPPED,
138 SCHED_SCAN_RESULTS
139 } scan_state;
140
141 u8 auth_bssid[ETH_ALEN];
142 u8 auth_attempt_bssid[ETH_ALEN];
143 u8 bssid[ETH_ALEN];
144 u8 prev_bssid[ETH_ALEN];
145 int associated;
Sunil Ravi89eba102022-09-13 21:04:37 -0700146 struct driver_sta_mlo_info sta_mlo_info;
Dmitry Shmidt9d9e6022015-04-23 10:34:55 -0700147 u8 ssid[SSID_MAX_LEN];
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800148 size_t ssid_len;
149 enum nl80211_iftype nlmode;
150 enum nl80211_iftype ap_scan_as_station;
151 unsigned int assoc_freq;
152
153 int monitor_sock;
154 int monitor_ifidx;
155 int monitor_refcount;
156
157 unsigned int disabled_11b_rates:1;
158 unsigned int pending_remain_on_chan:1;
159 unsigned int in_interface_list:1;
160 unsigned int device_ap_sme:1;
161 unsigned int poll_command_supported:1;
162 unsigned int data_tx_status:1;
163 unsigned int scan_for_auth:1;
164 unsigned int retry_auth:1;
165 unsigned int use_monitor:1;
166 unsigned int ignore_next_local_disconnect:1;
167 unsigned int ignore_next_local_deauth:1;
168 unsigned int hostapd:1;
Hai Shalomc1a21442022-02-04 13:43:00 -0800169 unsigned int start_mode_sta:1;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800170 unsigned int start_iface_up:1;
171 unsigned int test_use_roc_tx:1;
172 unsigned int ignore_deauth_event:1;
Dmitry Shmidt7f656022015-02-25 14:36:37 -0800173 unsigned int vendor_cmd_test_avail:1;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800174 unsigned int roaming_vendor_cmd_avail:1;
175 unsigned int dfs_vendor_cmd_avail:1;
176 unsigned int have_low_prio_scan:1;
177 unsigned int force_connect_cmd:1;
178 unsigned int addr_changed:1;
179 unsigned int get_features_vendor_cmd_avail:1;
Dmitry Shmidtff787d52015-01-12 13:01:47 -0800180 unsigned int set_rekey_offload:1;
Dmitry Shmidt7f656022015-02-25 14:36:37 -0800181 unsigned int p2p_go_ctwindow_supported:1;
Ravi Joshie6ccb162015-07-16 17:45:41 -0700182 unsigned int setband_vendor_cmd_avail:1;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800183 unsigned int get_pref_freq_list:1;
184 unsigned int set_prob_oper_freq:1;
185 unsigned int scan_vendor_cmd_avail:1;
Dmitry Shmidte4663042016-04-04 10:07:49 -0700186 unsigned int connect_reassoc:1;
Dmitry Shmidt7f2c7532016-08-15 09:48:12 -0700187 unsigned int set_wifi_conf_vendor_cmd_avail:1;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700188 unsigned int fetch_bss_trans_status:1;
189 unsigned int roam_vendor_cmd_avail:1;
Hai Shalomc3565922019-10-28 11:58:20 -0700190 unsigned int add_sta_node_vendor_cmd_avail:1;
Hai Shalomb755a2a2020-04-23 21:49:02 -0700191 unsigned int control_port_ap:1;
Hai Shalome21d4e82020-04-29 16:34:06 -0700192 unsigned int multicast_registrations:1;
Hai Shalom899fcc72020-10-19 14:38:18 -0700193 unsigned int no_rrm:1;
Hai Shalom60840252021-02-19 19:02:11 -0800194 unsigned int get_sta_info_vendor_cmd_avail:1;
195 unsigned int fils_discovery:1;
196 unsigned int unsol_bcast_probe_resp:1;
Hai Shalomc1a21442022-02-04 13:43:00 -0800197 unsigned int qca_do_acs:1;
198 unsigned int brcm_do_acs:1;
Sunil Ravi89eba102022-09-13 21:04:37 -0700199 unsigned int uses_6ghz:1;
200 unsigned int secure_ranging_ctx_vendor_cmd_avail:1;
Sunil Ravi036cec52023-03-29 11:35:17 -0700201 unsigned int puncturing:1;
Sunil Ravi640215c2023-06-28 23:08:09 +0000202 unsigned int qca_ap_allowed_freqs:1;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800203
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800204 u64 vendor_scan_cookie;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800205 u64 remain_on_chan_cookie;
Hai Shalomfdcde762020-04-02 11:19:20 -0700206 u64 send_frame_cookie;
207#define MAX_SEND_FRAME_COOKIES 20
208 u64 send_frame_cookies[MAX_SEND_FRAME_COOKIES];
209 unsigned int num_send_frame_cookies;
Hai Shalom899fcc72020-10-19 14:38:18 -0700210 u64 eapol_tx_cookie;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800211
212 unsigned int last_mgmt_freq;
213
214 struct wpa_driver_scan_filter *filter_ssids;
215 size_t num_filter_ssids;
216
217 struct i802_bss *first_bss;
218
219 int eapol_tx_sock;
220
221 int eapol_sock; /* socket for EAPOL frames */
222
Hai Shalomfdcde762020-04-02 11:19:20 -0700223 struct nl_sock *rtnl_sk; /* nl_sock for NETLINK_ROUTE */
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800224
Hai Shalom81f62d82019-07-22 12:10:00 -0700225 struct drv_nl80211_if_info default_if_indices[16];
226 struct drv_nl80211_if_info *if_indices;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800227 int num_if_indices;
228
229 /* From failed authentication command */
230 int auth_freq;
231 u8 auth_bssid_[ETH_ALEN];
Dmitry Shmidt9d9e6022015-04-23 10:34:55 -0700232 u8 auth_ssid[SSID_MAX_LEN];
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800233 size_t auth_ssid_len;
234 int auth_alg;
235 u8 *auth_ie;
236 size_t auth_ie_len;
Hai Shalom60840252021-02-19 19:02:11 -0800237 u8 *auth_data;
238 size_t auth_data_len;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800239 u8 auth_wep_key[4][16];
240 size_t auth_wep_key_len[4];
241 int auth_wep_tx_keyidx;
242 int auth_local_state_change;
243 int auth_p2p;
Sunil Ravi77d572f2023-01-17 23:58:31 +0000244 bool auth_mld;
245 u8 auth_mld_link_id;
246 u8 auth_ap_mld_addr[ETH_ALEN];
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800247
248 /*
249 * Tells whether the last scan issued from wpa_supplicant was a normal
250 * scan (NL80211_CMD_TRIGGER_SCAN) or a vendor scan
251 * (NL80211_CMD_VENDOR). 0 if no pending scan request.
252 */
253 int last_scan_cmd;
Andy Kuoaba17c12022-04-14 16:05:31 +0800254#if defined(CONFIG_DRIVER_NL80211_BRCM) || defined(CONFIG_DRIVER_NL80211_SYNA)
Mir Ali677e7482020-11-12 19:49:02 +0530255 unsigned int vendor_set_pmk:1; /* for legacy set_pmk method before NL80211_CMD_SET_PMK */
Andy Kuoaba17c12022-04-14 16:05:31 +0800256#endif /* CONFIG_DRIVER_NL80211_BRCM || CONFIG_DRIVER_NL80211_SYNA */
Hai Shalom60840252021-02-19 19:02:11 -0800257#ifdef CONFIG_DRIVER_NL80211_QCA
258 bool roam_indication_done;
259 u8 *pending_roam_data;
260 size_t pending_roam_data_len;
Sunil Ravi640215c2023-06-28 23:08:09 +0000261 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;
Hai Shalom60840252021-02-19 19:02:11 -0800265#endif /* CONFIG_DRIVER_NL80211_QCA */
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800266};
267
268struct nl_msg;
269
270void * nl80211_cmd(struct wpa_driver_nl80211_data *drv,
271 struct nl_msg *msg, int flags, uint8_t cmd);
272struct nl_msg * nl80211_cmd_msg(struct i802_bss *bss, int flags, uint8_t cmd);
273struct nl_msg * nl80211_drv_msg(struct wpa_driver_nl80211_data *drv, int flags,
274 uint8_t cmd);
275struct nl_msg * nl80211_bss_msg(struct i802_bss *bss, int flags, uint8_t cmd);
276int send_and_recv_msgs(struct wpa_driver_nl80211_data *drv, struct nl_msg *msg,
277 int (*valid_handler)(struct nl_msg *, void *),
Hai Shalom899fcc72020-10-19 14:38:18 -0700278 void *valid_data,
279 int (*ack_handler_custom)(struct nl_msg *, void *),
280 void *ack_data);
Hai Shalomb755a2a2020-04-23 21:49:02 -0700281struct nl_sock * get_connect_handle(struct i802_bss *bss);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800282int nl80211_create_iface(struct wpa_driver_nl80211_data *drv,
283 const char *ifname, enum nl80211_iftype iftype,
284 const u8 *addr, int wds,
285 int (*handler)(struct nl_msg *, void *),
286 void *arg, int use_existing);
287void nl80211_remove_iface(struct wpa_driver_nl80211_data *drv, int ifidx);
288unsigned int nl80211_get_assoc_freq(struct wpa_driver_nl80211_data *drv);
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800289int nl80211_get_assoc_ssid(struct wpa_driver_nl80211_data *drv, u8 *ssid);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800290enum chan_width convert2width(int width);
291void nl80211_mark_disconnected(struct wpa_driver_nl80211_data *drv);
292struct i802_bss * get_bss_ifindex(struct wpa_driver_nl80211_data *drv,
293 int ifindex);
294int is_ap_interface(enum nl80211_iftype nlmode);
295int is_sta_interface(enum nl80211_iftype nlmode);
296int wpa_driver_nl80211_authenticate_retry(struct wpa_driver_nl80211_data *drv);
297int nl80211_get_link_signal(struct wpa_driver_nl80211_data *drv,
Sunil Ravi77d572f2023-01-17 23:58:31 +0000298 const u8 *bssid,
299 struct hostap_sta_driver_data *data);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800300int nl80211_get_link_noise(struct wpa_driver_nl80211_data *drv,
301 struct wpa_signal_info *sig_change);
302int nl80211_get_wiphy_index(struct i802_bss *bss);
303int wpa_driver_nl80211_set_mode(struct i802_bss *bss,
304 enum nl80211_iftype nlmode);
305int wpa_driver_nl80211_mlme(struct wpa_driver_nl80211_data *drv,
306 const u8 *addr, int cmd, u16 reason_code,
Hai Shalom74f70d42019-02-11 14:42:39 -0800307 int local_state_change,
Hai Shalomc1a21442022-02-04 13:43:00 -0800308 struct i802_bss *bss);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800309
310int nl80211_create_monitor_interface(struct wpa_driver_nl80211_data *drv);
311void nl80211_remove_monitor_interface(struct wpa_driver_nl80211_data *drv);
312int nl80211_send_monitor(struct wpa_driver_nl80211_data *drv,
313 const void *data, size_t len,
314 int encrypt, int noack);
315
316int wpa_driver_nl80211_capa(struct wpa_driver_nl80211_data *drv);
317struct hostapd_hw_modes *
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700318nl80211_get_hw_feature_data(void *priv, u16 *num_modes, u16 *flags,
319 u8 *dfs_domain);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800320
321int process_global_event(struct nl_msg *msg, void *arg);
322int process_bss_event(struct nl_msg *msg, void *arg);
323
Dmitry Shmidtd5ab1b52016-06-21 12:38:41 -0700324const char * nl80211_iftype_str(enum nl80211_iftype mode);
325
Hai Shalom4fbc08f2020-05-18 12:37:00 -0700326void nl80211_restore_ap_mode(struct i802_bss *bss);
327
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800328#ifdef ANDROID
Hai Shalomfdcde762020-04-02 11:19:20 -0700329int android_nl_socket_set_nonblocking(struct nl_sock *handle);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800330int android_pno_start(struct i802_bss *bss,
331 struct wpa_driver_scan_params *params);
332int android_pno_stop(struct i802_bss *bss);
333extern int wpa_driver_nl80211_driver_cmd(void *priv, char *cmd, char *buf,
334 size_t buf_len);
Hai Shalom60840252021-02-19 19:02:11 -0800335extern int wpa_driver_nl80211_driver_event(struct wpa_driver_nl80211_data *drv,
336 u32 vendor_id, u32 subcmd,
337 u8 *data, size_t len);
338
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800339
340#ifdef ANDROID_P2P
341int wpa_driver_set_p2p_noa(void *priv, u8 count, int start, int duration);
342int wpa_driver_get_p2p_noa(void *priv, u8 *buf, size_t len);
343int wpa_driver_set_p2p_ps(void *priv, int legacy_ps, int opp_ps, int ctwindow);
344int wpa_driver_set_ap_wps_p2p_ie(void *priv, const struct wpabuf *beacon,
345 const struct wpabuf *proberesp,
346 const struct wpabuf *assocresp);
347#endif /* ANDROID_P2P */
348#endif /* ANDROID */
349
350
351/* driver_nl80211_scan.c */
352
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800353void wpa_driver_nl80211_scan_timeout(void *eloop_ctx, void *timeout_ctx);
354int wpa_driver_nl80211_scan(struct i802_bss *bss,
355 struct wpa_driver_scan_params *params);
356int wpa_driver_nl80211_sched_scan(void *priv,
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -0800357 struct wpa_driver_scan_params *params);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800358int wpa_driver_nl80211_stop_sched_scan(void *priv);
359struct wpa_scan_results * wpa_driver_nl80211_get_scan_results(void *priv);
360void nl80211_dump_scan(struct wpa_driver_nl80211_data *drv);
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800361int wpa_driver_nl80211_abort_scan(void *priv, u64 scan_cookie);
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800362int wpa_driver_nl80211_vendor_scan(struct i802_bss *bss,
363 struct wpa_driver_scan_params *params);
Dmitry Shmidt7f2c7532016-08-15 09:48:12 -0700364int nl80211_set_default_scan_ies(void *priv, const u8 *ies, size_t ies_len);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800365
366#endif /* DRIVER_NL80211_H */