blob: 5ac0c7dfc8e856c238cf55e480f6f4b5de6fad10 [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
20#ifdef CONFIG_LIBNL20
21/* libnl 2.0 compatibility code */
22#define nl_handle nl_sock
23#define nl80211_handle_alloc nl_socket_alloc_cb
24#define nl80211_handle_destroy nl_socket_free
25#endif /* CONFIG_LIBNL20 */
26
27struct nl80211_global {
Dmitry Shmidte4663042016-04-04 10:07:49 -070028 void *ctx;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080029 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_handle *nl;
36 int nl80211_id;
37 int ioctl_sock; /* socket for ioctl() use */
38
39 struct nl_handle *nl_event;
40};
41
42struct nl80211_wiphy_data {
43 struct dl_list list;
44 struct dl_list bsss;
45 struct dl_list drvs;
46
47 struct nl_handle *nl_beacons;
48 struct nl_cb *nl_cb;
49
50 int wiphy_idx;
51};
52
53struct i802_bss {
54 struct wpa_driver_nl80211_data *drv;
55 struct i802_bss *next;
56 int ifindex;
57 int br_ifindex;
58 u64 wdev_id;
59 char ifname[IFNAMSIZ + 1];
60 char brname[IFNAMSIZ];
61 unsigned int beacon_set:1;
62 unsigned int added_if_into_bridge:1;
Hai Shalomc9e41a12018-07-31 14:41:42 -070063 unsigned int already_in_bridge:1;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080064 unsigned int added_bridge:1;
65 unsigned int in_deinit:1;
66 unsigned int wdev_id_set:1;
67 unsigned int added_if:1;
68 unsigned int static_ap:1;
69
70 u8 addr[ETH_ALEN];
71
72 int freq;
73 int bandwidth;
74 int if_dynamic;
75
76 void *ctx;
Roshan Pius3a1667e2018-07-03 15:17:14 -070077 struct nl_handle *nl_preq, *nl_mgmt, *nl_connect;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080078 struct nl_cb *nl_cb;
79
80 struct nl80211_wiphy_data *wiphy_data;
81 struct dl_list wiphy_list;
Dmitry Shmidtebd93af2017-02-21 13:40:44 -080082 u8 rand_addr[ETH_ALEN];
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080083};
84
85struct wpa_driver_nl80211_data {
86 struct nl80211_global *global;
87 struct dl_list list;
88 struct dl_list wiphy_list;
89 char phyname[32];
Dmitry Shmidt7d56b752015-12-22 10:59:44 -080090 unsigned int wiphy_idx;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080091 u8 perm_addr[ETH_ALEN];
92 void *ctx;
93 int ifindex;
94 int if_removed;
95 int if_disabled;
96 int ignore_if_down_event;
97 struct rfkill_data *rfkill;
98 struct wpa_driver_capa capa;
99 u8 *extended_capa, *extended_capa_mask;
100 unsigned int extended_capa_len;
Dmitry Shmidtd5ab1b52016-06-21 12:38:41 -0700101 struct drv_nl80211_ext_capa {
102 enum nl80211_iftype iftype;
103 u8 *ext_capa, *ext_capa_mask;
104 unsigned int ext_capa_len;
105 } iface_ext_capa[NL80211_IFTYPE_MAX];
106 unsigned int num_iface_ext_capa;
107
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800108 int has_capability;
109
110 int operstate;
111
112 int scan_complete_events;
113 enum scan_states {
114 NO_SCAN, SCAN_REQUESTED, SCAN_STARTED, SCAN_COMPLETED,
115 SCAN_ABORTED, SCHED_SCAN_STARTED, SCHED_SCAN_STOPPED,
116 SCHED_SCAN_RESULTS
117 } scan_state;
118
119 u8 auth_bssid[ETH_ALEN];
120 u8 auth_attempt_bssid[ETH_ALEN];
121 u8 bssid[ETH_ALEN];
122 u8 prev_bssid[ETH_ALEN];
123 int associated;
Dmitry Shmidt9d9e6022015-04-23 10:34:55 -0700124 u8 ssid[SSID_MAX_LEN];
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800125 size_t ssid_len;
126 enum nl80211_iftype nlmode;
127 enum nl80211_iftype ap_scan_as_station;
128 unsigned int assoc_freq;
129
130 int monitor_sock;
131 int monitor_ifidx;
132 int monitor_refcount;
133
134 unsigned int disabled_11b_rates:1;
135 unsigned int pending_remain_on_chan:1;
136 unsigned int in_interface_list:1;
137 unsigned int device_ap_sme:1;
138 unsigned int poll_command_supported:1;
139 unsigned int data_tx_status:1;
140 unsigned int scan_for_auth:1;
141 unsigned int retry_auth:1;
142 unsigned int use_monitor:1;
143 unsigned int ignore_next_local_disconnect:1;
144 unsigned int ignore_next_local_deauth:1;
145 unsigned int hostapd:1;
146 unsigned int start_mode_ap:1;
147 unsigned int start_iface_up:1;
148 unsigned int test_use_roc_tx:1;
149 unsigned int ignore_deauth_event:1;
Dmitry Shmidt7f656022015-02-25 14:36:37 -0800150 unsigned int vendor_cmd_test_avail:1;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800151 unsigned int roaming_vendor_cmd_avail:1;
152 unsigned int dfs_vendor_cmd_avail:1;
153 unsigned int have_low_prio_scan:1;
154 unsigned int force_connect_cmd:1;
155 unsigned int addr_changed:1;
156 unsigned int get_features_vendor_cmd_avail:1;
Dmitry Shmidtff787d52015-01-12 13:01:47 -0800157 unsigned int set_rekey_offload:1;
Dmitry Shmidt7f656022015-02-25 14:36:37 -0800158 unsigned int p2p_go_ctwindow_supported:1;
Ravi Joshie6ccb162015-07-16 17:45:41 -0700159 unsigned int setband_vendor_cmd_avail:1;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800160 unsigned int get_pref_freq_list:1;
161 unsigned int set_prob_oper_freq:1;
162 unsigned int scan_vendor_cmd_avail:1;
Dmitry Shmidte4663042016-04-04 10:07:49 -0700163 unsigned int connect_reassoc:1;
Dmitry Shmidt7f2c7532016-08-15 09:48:12 -0700164 unsigned int set_wifi_conf_vendor_cmd_avail:1;
Dmitry Shmidtebd93af2017-02-21 13:40:44 -0800165 unsigned int he_capab_vendor_cmd_avail:1;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700166 unsigned int fetch_bss_trans_status:1;
167 unsigned int roam_vendor_cmd_avail:1;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800168
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800169 u64 vendor_scan_cookie;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800170 u64 remain_on_chan_cookie;
171 u64 send_action_cookie;
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -0800172#define MAX_SEND_ACTION_COOKIES 20
173 u64 send_action_cookies[MAX_SEND_ACTION_COOKIES];
174 unsigned int num_send_action_cookies;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800175
176 unsigned int last_mgmt_freq;
177
178 struct wpa_driver_scan_filter *filter_ssids;
179 size_t num_filter_ssids;
180
181 struct i802_bss *first_bss;
182
183 int eapol_tx_sock;
184
185 int eapol_sock; /* socket for EAPOL frames */
186
187 struct nl_handle *rtnl_sk; /* nl_sock for NETLINK_ROUTE */
188
189 int default_if_indices[16];
Dmitry Shmidt9c175262016-03-03 10:20:07 -0800190 /* the AP/AP_VLAN iface that is in this bridge */
191 int default_if_indices_reason[16];
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800192 int *if_indices;
Dmitry Shmidt9c175262016-03-03 10:20:07 -0800193 int *if_indices_reason;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800194 int num_if_indices;
195
196 /* From failed authentication command */
197 int auth_freq;
198 u8 auth_bssid_[ETH_ALEN];
Dmitry Shmidt9d9e6022015-04-23 10:34:55 -0700199 u8 auth_ssid[SSID_MAX_LEN];
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800200 size_t auth_ssid_len;
201 int auth_alg;
202 u8 *auth_ie;
203 size_t auth_ie_len;
204 u8 auth_wep_key[4][16];
205 size_t auth_wep_key_len[4];
206 int auth_wep_tx_keyidx;
207 int auth_local_state_change;
208 int auth_p2p;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800209
210 /*
211 * Tells whether the last scan issued from wpa_supplicant was a normal
212 * scan (NL80211_CMD_TRIGGER_SCAN) or a vendor scan
213 * (NL80211_CMD_VENDOR). 0 if no pending scan request.
214 */
215 int last_scan_cmd;
Dmitry Shmidtebd93af2017-02-21 13:40:44 -0800216
217 struct he_capabilities he_capab;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800218};
219
220struct nl_msg;
221
222void * nl80211_cmd(struct wpa_driver_nl80211_data *drv,
223 struct nl_msg *msg, int flags, uint8_t cmd);
224struct nl_msg * nl80211_cmd_msg(struct i802_bss *bss, int flags, uint8_t cmd);
225struct nl_msg * nl80211_drv_msg(struct wpa_driver_nl80211_data *drv, int flags,
226 uint8_t cmd);
227struct nl_msg * nl80211_bss_msg(struct i802_bss *bss, int flags, uint8_t cmd);
228int send_and_recv_msgs(struct wpa_driver_nl80211_data *drv, struct nl_msg *msg,
229 int (*valid_handler)(struct nl_msg *, void *),
230 void *valid_data);
231int nl80211_create_iface(struct wpa_driver_nl80211_data *drv,
232 const char *ifname, enum nl80211_iftype iftype,
233 const u8 *addr, int wds,
234 int (*handler)(struct nl_msg *, void *),
235 void *arg, int use_existing);
236void nl80211_remove_iface(struct wpa_driver_nl80211_data *drv, int ifidx);
237unsigned int nl80211_get_assoc_freq(struct wpa_driver_nl80211_data *drv);
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800238int nl80211_get_assoc_ssid(struct wpa_driver_nl80211_data *drv, u8 *ssid);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800239enum chan_width convert2width(int width);
240void nl80211_mark_disconnected(struct wpa_driver_nl80211_data *drv);
241struct i802_bss * get_bss_ifindex(struct wpa_driver_nl80211_data *drv,
242 int ifindex);
243int is_ap_interface(enum nl80211_iftype nlmode);
244int is_sta_interface(enum nl80211_iftype nlmode);
245int wpa_driver_nl80211_authenticate_retry(struct wpa_driver_nl80211_data *drv);
246int nl80211_get_link_signal(struct wpa_driver_nl80211_data *drv,
247 struct wpa_signal_info *sig);
248int nl80211_get_link_noise(struct wpa_driver_nl80211_data *drv,
249 struct wpa_signal_info *sig_change);
250int nl80211_get_wiphy_index(struct i802_bss *bss);
251int wpa_driver_nl80211_set_mode(struct i802_bss *bss,
252 enum nl80211_iftype nlmode);
253int wpa_driver_nl80211_mlme(struct wpa_driver_nl80211_data *drv,
254 const u8 *addr, int cmd, u16 reason_code,
Hai Shalombf6e0ba2019-02-11 12:01:50 -0800255 int local_state_change);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800256
257int nl80211_create_monitor_interface(struct wpa_driver_nl80211_data *drv);
258void nl80211_remove_monitor_interface(struct wpa_driver_nl80211_data *drv);
259int nl80211_send_monitor(struct wpa_driver_nl80211_data *drv,
260 const void *data, size_t len,
261 int encrypt, int noack);
262
263int wpa_driver_nl80211_capa(struct wpa_driver_nl80211_data *drv);
264struct hostapd_hw_modes *
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700265nl80211_get_hw_feature_data(void *priv, u16 *num_modes, u16 *flags,
266 u8 *dfs_domain);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800267
268int process_global_event(struct nl_msg *msg, void *arg);
269int process_bss_event(struct nl_msg *msg, void *arg);
270
Dmitry Shmidtd5ab1b52016-06-21 12:38:41 -0700271const char * nl80211_iftype_str(enum nl80211_iftype mode);
272
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800273#ifdef ANDROID
274int android_nl_socket_set_nonblocking(struct nl_handle *handle);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800275int android_pno_start(struct i802_bss *bss,
276 struct wpa_driver_scan_params *params);
277int android_pno_stop(struct i802_bss *bss);
278extern int wpa_driver_nl80211_driver_cmd(void *priv, char *cmd, char *buf,
279 size_t buf_len);
280
281#ifdef ANDROID_P2P
282int wpa_driver_set_p2p_noa(void *priv, u8 count, int start, int duration);
283int wpa_driver_get_p2p_noa(void *priv, u8 *buf, size_t len);
284int wpa_driver_set_p2p_ps(void *priv, int legacy_ps, int opp_ps, int ctwindow);
285int wpa_driver_set_ap_wps_p2p_ie(void *priv, const struct wpabuf *beacon,
286 const struct wpabuf *proberesp,
287 const struct wpabuf *assocresp);
288#endif /* ANDROID_P2P */
289#endif /* ANDROID */
290
291
292/* driver_nl80211_scan.c */
293
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800294void wpa_driver_nl80211_scan_timeout(void *eloop_ctx, void *timeout_ctx);
295int wpa_driver_nl80211_scan(struct i802_bss *bss,
296 struct wpa_driver_scan_params *params);
297int wpa_driver_nl80211_sched_scan(void *priv,
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -0800298 struct wpa_driver_scan_params *params);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800299int wpa_driver_nl80211_stop_sched_scan(void *priv);
300struct wpa_scan_results * wpa_driver_nl80211_get_scan_results(void *priv);
301void nl80211_dump_scan(struct wpa_driver_nl80211_data *drv);
Dmitry Shmidtabb90a32016-12-05 15:34:39 -0800302int wpa_driver_nl80211_abort_scan(void *priv, u64 scan_cookie);
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800303int wpa_driver_nl80211_vendor_scan(struct i802_bss *bss,
304 struct wpa_driver_scan_params *params);
Dmitry Shmidt7f2c7532016-08-15 09:48:12 -0700305int nl80211_set_default_scan_ies(void *priv, const u8 *ies, size_t ies_len);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800306
307#endif /* DRIVER_NL80211_H */