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