blob: ea5f0583e73a7060a4e3fc3296de7bccdb5952d8 [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 {
28 struct dl_list interfaces;
29 int if_add_ifindex;
30 u64 if_add_wdevid;
31 int if_add_wdevid_set;
32 struct netlink_data *netlink;
33 struct nl_cb *nl_cb;
34 struct nl_handle *nl;
35 int nl80211_id;
36 int ioctl_sock; /* socket for ioctl() use */
37
38 struct nl_handle *nl_event;
39};
40
41struct nl80211_wiphy_data {
42 struct dl_list list;
43 struct dl_list bsss;
44 struct dl_list drvs;
45
46 struct nl_handle *nl_beacons;
47 struct nl_cb *nl_cb;
48
49 int wiphy_idx;
50};
51
52struct i802_bss {
53 struct wpa_driver_nl80211_data *drv;
54 struct i802_bss *next;
55 int ifindex;
56 int br_ifindex;
57 u64 wdev_id;
58 char ifname[IFNAMSIZ + 1];
59 char brname[IFNAMSIZ];
60 unsigned int beacon_set:1;
61 unsigned int added_if_into_bridge:1;
62 unsigned int added_bridge:1;
63 unsigned int in_deinit:1;
64 unsigned int wdev_id_set:1;
65 unsigned int added_if:1;
66 unsigned int static_ap:1;
67
68 u8 addr[ETH_ALEN];
69
70 int freq;
71 int bandwidth;
72 int if_dynamic;
73
74 void *ctx;
75 struct nl_handle *nl_preq, *nl_mgmt;
76 struct nl_cb *nl_cb;
77
78 struct nl80211_wiphy_data *wiphy_data;
79 struct dl_list wiphy_list;
80};
81
82struct wpa_driver_nl80211_data {
83 struct nl80211_global *global;
84 struct dl_list list;
85 struct dl_list wiphy_list;
86 char phyname[32];
87 u8 perm_addr[ETH_ALEN];
88 void *ctx;
89 int ifindex;
90 int if_removed;
91 int if_disabled;
92 int ignore_if_down_event;
93 struct rfkill_data *rfkill;
94 struct wpa_driver_capa capa;
95 u8 *extended_capa, *extended_capa_mask;
96 unsigned int extended_capa_len;
97 int has_capability;
98
99 int operstate;
100
101 int scan_complete_events;
102 enum scan_states {
103 NO_SCAN, SCAN_REQUESTED, SCAN_STARTED, SCAN_COMPLETED,
104 SCAN_ABORTED, SCHED_SCAN_STARTED, SCHED_SCAN_STOPPED,
105 SCHED_SCAN_RESULTS
106 } scan_state;
107
108 u8 auth_bssid[ETH_ALEN];
109 u8 auth_attempt_bssid[ETH_ALEN];
110 u8 bssid[ETH_ALEN];
111 u8 prev_bssid[ETH_ALEN];
112 int associated;
Dmitry Shmidt9d9e6022015-04-23 10:34:55 -0700113 u8 ssid[SSID_MAX_LEN];
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800114 size_t ssid_len;
115 enum nl80211_iftype nlmode;
116 enum nl80211_iftype ap_scan_as_station;
117 unsigned int assoc_freq;
118
119 int monitor_sock;
120 int monitor_ifidx;
121 int monitor_refcount;
122
123 unsigned int disabled_11b_rates:1;
124 unsigned int pending_remain_on_chan:1;
125 unsigned int in_interface_list:1;
126 unsigned int device_ap_sme:1;
127 unsigned int poll_command_supported:1;
128 unsigned int data_tx_status:1;
129 unsigned int scan_for_auth:1;
130 unsigned int retry_auth:1;
131 unsigned int use_monitor:1;
132 unsigned int ignore_next_local_disconnect:1;
133 unsigned int ignore_next_local_deauth:1;
134 unsigned int hostapd:1;
135 unsigned int start_mode_ap:1;
136 unsigned int start_iface_up:1;
137 unsigned int test_use_roc_tx:1;
138 unsigned int ignore_deauth_event:1;
Dmitry Shmidt7f656022015-02-25 14:36:37 -0800139 unsigned int vendor_cmd_test_avail:1;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800140 unsigned int roaming_vendor_cmd_avail:1;
141 unsigned int dfs_vendor_cmd_avail:1;
142 unsigned int have_low_prio_scan:1;
143 unsigned int force_connect_cmd:1;
144 unsigned int addr_changed:1;
145 unsigned int get_features_vendor_cmd_avail:1;
Dmitry Shmidtff787d52015-01-12 13:01:47 -0800146 unsigned int set_rekey_offload:1;
Dmitry Shmidt7f656022015-02-25 14:36:37 -0800147 unsigned int p2p_go_ctwindow_supported:1;
Ravi Joshie6ccb162015-07-16 17:45:41 -0700148 unsigned int setband_vendor_cmd_avail:1;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800149 unsigned int get_pref_freq_list:1;
150 unsigned int set_prob_oper_freq:1;
151 unsigned int scan_vendor_cmd_avail:1;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800152
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800153 u64 vendor_scan_cookie;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800154 u64 remain_on_chan_cookie;
155 u64 send_action_cookie;
156
157 unsigned int last_mgmt_freq;
158
159 struct wpa_driver_scan_filter *filter_ssids;
160 size_t num_filter_ssids;
161
162 struct i802_bss *first_bss;
163
164 int eapol_tx_sock;
165
166 int eapol_sock; /* socket for EAPOL frames */
167
168 struct nl_handle *rtnl_sk; /* nl_sock for NETLINK_ROUTE */
169
170 int default_if_indices[16];
171 int *if_indices;
172 int num_if_indices;
173
174 /* From failed authentication command */
175 int auth_freq;
176 u8 auth_bssid_[ETH_ALEN];
Dmitry Shmidt9d9e6022015-04-23 10:34:55 -0700177 u8 auth_ssid[SSID_MAX_LEN];
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800178 size_t auth_ssid_len;
179 int auth_alg;
180 u8 *auth_ie;
181 size_t auth_ie_len;
182 u8 auth_wep_key[4][16];
183 size_t auth_wep_key_len[4];
184 int auth_wep_tx_keyidx;
185 int auth_local_state_change;
186 int auth_p2p;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800187
188 /*
189 * Tells whether the last scan issued from wpa_supplicant was a normal
190 * scan (NL80211_CMD_TRIGGER_SCAN) or a vendor scan
191 * (NL80211_CMD_VENDOR). 0 if no pending scan request.
192 */
193 int last_scan_cmd;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800194};
195
196struct nl_msg;
197
198void * nl80211_cmd(struct wpa_driver_nl80211_data *drv,
199 struct nl_msg *msg, int flags, uint8_t cmd);
200struct nl_msg * nl80211_cmd_msg(struct i802_bss *bss, int flags, uint8_t cmd);
201struct nl_msg * nl80211_drv_msg(struct wpa_driver_nl80211_data *drv, int flags,
202 uint8_t cmd);
203struct nl_msg * nl80211_bss_msg(struct i802_bss *bss, int flags, uint8_t cmd);
204int send_and_recv_msgs(struct wpa_driver_nl80211_data *drv, struct nl_msg *msg,
205 int (*valid_handler)(struct nl_msg *, void *),
206 void *valid_data);
207int nl80211_create_iface(struct wpa_driver_nl80211_data *drv,
208 const char *ifname, enum nl80211_iftype iftype,
209 const u8 *addr, int wds,
210 int (*handler)(struct nl_msg *, void *),
211 void *arg, int use_existing);
212void nl80211_remove_iface(struct wpa_driver_nl80211_data *drv, int ifidx);
213unsigned int nl80211_get_assoc_freq(struct wpa_driver_nl80211_data *drv);
214enum chan_width convert2width(int width);
215void nl80211_mark_disconnected(struct wpa_driver_nl80211_data *drv);
216struct i802_bss * get_bss_ifindex(struct wpa_driver_nl80211_data *drv,
217 int ifindex);
218int is_ap_interface(enum nl80211_iftype nlmode);
219int is_sta_interface(enum nl80211_iftype nlmode);
220int wpa_driver_nl80211_authenticate_retry(struct wpa_driver_nl80211_data *drv);
221int nl80211_get_link_signal(struct wpa_driver_nl80211_data *drv,
222 struct wpa_signal_info *sig);
223int nl80211_get_link_noise(struct wpa_driver_nl80211_data *drv,
224 struct wpa_signal_info *sig_change);
225int nl80211_get_wiphy_index(struct i802_bss *bss);
226int wpa_driver_nl80211_set_mode(struct i802_bss *bss,
227 enum nl80211_iftype nlmode);
228int wpa_driver_nl80211_mlme(struct wpa_driver_nl80211_data *drv,
229 const u8 *addr, int cmd, u16 reason_code,
230 int local_state_change);
231
232int nl80211_create_monitor_interface(struct wpa_driver_nl80211_data *drv);
233void nl80211_remove_monitor_interface(struct wpa_driver_nl80211_data *drv);
234int nl80211_send_monitor(struct wpa_driver_nl80211_data *drv,
235 const void *data, size_t len,
236 int encrypt, int noack);
237
238int wpa_driver_nl80211_capa(struct wpa_driver_nl80211_data *drv);
239struct hostapd_hw_modes *
240nl80211_get_hw_feature_data(void *priv, u16 *num_modes, u16 *flags);
241
242int process_global_event(struct nl_msg *msg, void *arg);
243int process_bss_event(struct nl_msg *msg, void *arg);
244
245#ifdef ANDROID
246int android_nl_socket_set_nonblocking(struct nl_handle *handle);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800247int android_pno_start(struct i802_bss *bss,
248 struct wpa_driver_scan_params *params);
249int android_pno_stop(struct i802_bss *bss);
250extern int wpa_driver_nl80211_driver_cmd(void *priv, char *cmd, char *buf,
251 size_t buf_len);
252
253#ifdef ANDROID_P2P
254int wpa_driver_set_p2p_noa(void *priv, u8 count, int start, int duration);
255int wpa_driver_get_p2p_noa(void *priv, u8 *buf, size_t len);
256int wpa_driver_set_p2p_ps(void *priv, int legacy_ps, int opp_ps, int ctwindow);
257int wpa_driver_set_ap_wps_p2p_ie(void *priv, const struct wpabuf *beacon,
258 const struct wpabuf *proberesp,
259 const struct wpabuf *assocresp);
260#endif /* ANDROID_P2P */
261#endif /* ANDROID */
262
263
264/* driver_nl80211_scan.c */
265
266struct nl80211_bss_info_arg {
267 struct wpa_driver_nl80211_data *drv;
268 struct wpa_scan_results *res;
269 unsigned int assoc_freq;
270 unsigned int ibss_freq;
271 u8 assoc_bssid[ETH_ALEN];
272};
273
274int bss_info_handler(struct nl_msg *msg, void *arg);
275void wpa_driver_nl80211_scan_timeout(void *eloop_ctx, void *timeout_ctx);
276int wpa_driver_nl80211_scan(struct i802_bss *bss,
277 struct wpa_driver_scan_params *params);
278int wpa_driver_nl80211_sched_scan(void *priv,
279 struct wpa_driver_scan_params *params,
280 u32 interval);
281int wpa_driver_nl80211_stop_sched_scan(void *priv);
282struct wpa_scan_results * wpa_driver_nl80211_get_scan_results(void *priv);
283void nl80211_dump_scan(struct wpa_driver_nl80211_data *drv);
Dmitry Shmidtdda10c22015-03-24 16:05:01 -0700284const u8 * nl80211_get_ie(const u8 *ies, size_t ies_len, u8 ie);
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800285int wpa_driver_nl80211_vendor_scan(struct i802_bss *bss,
286 struct wpa_driver_scan_params *params);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800287
288#endif /* DRIVER_NL80211_H */