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 nl80211_global { 26 void *ctx; 27 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; 33 struct nl_sock *nl; 34 int nl80211_id; 35 int nlctrl_id; 36 int ioctl_sock; /* socket for ioctl() use */ 37 38 struct nl_sock *nl_event; 39 }; 40 41 struct nl80211_wiphy_data { 42 struct dl_list list; 43 struct dl_list bsss; 44 struct dl_list drvs; 45 46 struct nl_sock *nl_beacons; 47 struct nl_cb *nl_cb; 48 49 int wiphy_idx; 50 }; 51 52 struct 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 already_in_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 unsigned int use_nl_connect:1; 69 70 u8 addr[ETH_ALEN]; 71 72 int freq; 73 int bandwidth; 74 int if_dynamic; 75 76 void *ctx; 77 struct nl_sock *nl_preq, *nl_mgmt, *nl_connect; 78 struct nl_cb *nl_cb; 79 80 struct nl80211_wiphy_data *wiphy_data; 81 struct dl_list wiphy_list; 82 u8 rand_addr[ETH_ALEN]; 83 }; 84 85 struct drv_nl80211_if_info { 86 int ifindex; 87 /* the AP/AP_VLAN iface that is in this bridge */ 88 int reason; 89 }; 90 91 struct wpa_driver_nl80211_data { 92 struct nl80211_global *global; 93 struct dl_list list; 94 struct dl_list wiphy_list; 95 char phyname[32]; 96 unsigned int wiphy_idx; 97 u8 perm_addr[ETH_ALEN]; 98 void *ctx; 99 int ifindex; 100 int if_removed; 101 int if_disabled; 102 int ignore_if_down_event; 103 struct rfkill_data *rfkill; 104 struct wpa_driver_capa capa; 105 u8 *extended_capa, *extended_capa_mask; 106 unsigned int extended_capa_len; 107 struct drv_nl80211_ext_capa { 108 enum nl80211_iftype iftype; 109 u8 *ext_capa, *ext_capa_mask; 110 unsigned int ext_capa_len; 111 } iface_ext_capa[NL80211_IFTYPE_MAX]; 112 unsigned int num_iface_ext_capa; 113 114 int has_capability; 115 int has_driver_key_mgmt; 116 117 int operstate; 118 119 int scan_complete_events; 120 enum scan_states { 121 NO_SCAN, SCAN_REQUESTED, SCAN_STARTED, SCAN_COMPLETED, 122 SCAN_ABORTED, SCHED_SCAN_STARTED, SCHED_SCAN_STOPPED, 123 SCHED_SCAN_RESULTS 124 } scan_state; 125 126 u8 auth_bssid[ETH_ALEN]; 127 u8 auth_attempt_bssid[ETH_ALEN]; 128 u8 bssid[ETH_ALEN]; 129 u8 prev_bssid[ETH_ALEN]; 130 int associated; 131 u8 ssid[SSID_MAX_LEN]; 132 size_t ssid_len; 133 enum nl80211_iftype nlmode; 134 enum nl80211_iftype ap_scan_as_station; 135 unsigned int assoc_freq; 136 137 int monitor_sock; 138 int monitor_ifidx; 139 int monitor_refcount; 140 141 unsigned int disabled_11b_rates:1; 142 unsigned int pending_remain_on_chan:1; 143 unsigned int in_interface_list:1; 144 unsigned int device_ap_sme:1; 145 unsigned int poll_command_supported:1; 146 unsigned int data_tx_status:1; 147 unsigned int scan_for_auth:1; 148 unsigned int retry_auth:1; 149 unsigned int use_monitor:1; 150 unsigned int ignore_next_local_disconnect:1; 151 unsigned int ignore_next_local_deauth:1; 152 unsigned int hostapd:1; 153 unsigned int start_mode_sta:1; 154 unsigned int start_iface_up:1; 155 unsigned int test_use_roc_tx:1; 156 unsigned int ignore_deauth_event:1; 157 unsigned int vendor_cmd_test_avail:1; 158 unsigned int roaming_vendor_cmd_avail:1; 159 unsigned int dfs_vendor_cmd_avail:1; 160 unsigned int have_low_prio_scan:1; 161 unsigned int force_connect_cmd:1; 162 unsigned int addr_changed:1; 163 unsigned int get_features_vendor_cmd_avail:1; 164 unsigned int set_rekey_offload:1; 165 unsigned int p2p_go_ctwindow_supported:1; 166 unsigned int setband_vendor_cmd_avail:1; 167 unsigned int get_pref_freq_list:1; 168 unsigned int set_prob_oper_freq:1; 169 unsigned int scan_vendor_cmd_avail:1; 170 unsigned int connect_reassoc:1; 171 unsigned int set_wifi_conf_vendor_cmd_avail:1; 172 unsigned int fetch_bss_trans_status:1; 173 unsigned int roam_vendor_cmd_avail:1; 174 unsigned int add_sta_node_vendor_cmd_avail:1; 175 unsigned int control_port_ap:1; 176 unsigned int multicast_registrations:1; 177 unsigned int no_rrm:1; 178 unsigned int get_sta_info_vendor_cmd_avail:1; 179 unsigned int fils_discovery:1; 180 unsigned int unsol_bcast_probe_resp:1; 181 unsigned int qca_do_acs:1; 182 unsigned int brcm_do_acs:1; 183 184 u64 vendor_scan_cookie; 185 u64 remain_on_chan_cookie; 186 u64 send_frame_cookie; 187 #define MAX_SEND_FRAME_COOKIES 20 188 u64 send_frame_cookies[MAX_SEND_FRAME_COOKIES]; 189 unsigned int num_send_frame_cookies; 190 u64 eapol_tx_cookie; 191 192 unsigned int last_mgmt_freq; 193 194 struct wpa_driver_scan_filter *filter_ssids; 195 size_t num_filter_ssids; 196 197 struct i802_bss *first_bss; 198 199 int eapol_tx_sock; 200 201 int eapol_sock; /* socket for EAPOL frames */ 202 203 struct nl_sock *rtnl_sk; /* nl_sock for NETLINK_ROUTE */ 204 205 struct drv_nl80211_if_info default_if_indices[16]; 206 struct drv_nl80211_if_info *if_indices; 207 int num_if_indices; 208 209 /* From failed authentication command */ 210 int auth_freq; 211 u8 auth_bssid_[ETH_ALEN]; 212 u8 auth_ssid[SSID_MAX_LEN]; 213 size_t auth_ssid_len; 214 int auth_alg; 215 u8 *auth_ie; 216 size_t auth_ie_len; 217 u8 *auth_data; 218 size_t auth_data_len; 219 u8 auth_wep_key[4][16]; 220 size_t auth_wep_key_len[4]; 221 int auth_wep_tx_keyidx; 222 int auth_local_state_change; 223 int auth_p2p; 224 225 /* 226 * Tells whether the last scan issued from wpa_supplicant was a normal 227 * scan (NL80211_CMD_TRIGGER_SCAN) or a vendor scan 228 * (NL80211_CMD_VENDOR). 0 if no pending scan request. 229 */ 230 int last_scan_cmd; 231 #ifdef CONFIG_DRIVER_NL80211_QCA 232 bool roam_indication_done; 233 u8 *pending_roam_data; 234 size_t pending_roam_data_len; 235 struct os_reltime pending_roam_ind_time; 236 #endif /* CONFIG_DRIVER_NL80211_QCA */ 237 }; 238 239 struct nl_msg; 240 241 void * nl80211_cmd(struct wpa_driver_nl80211_data *drv, 242 struct nl_msg *msg, int flags, uint8_t cmd); 243 struct nl_msg * nl80211_cmd_msg(struct i802_bss *bss, int flags, uint8_t cmd); 244 struct nl_msg * nl80211_drv_msg(struct wpa_driver_nl80211_data *drv, int flags, 245 uint8_t cmd); 246 struct nl_msg * nl80211_bss_msg(struct i802_bss *bss, int flags, uint8_t cmd); 247 int send_and_recv_msgs(struct wpa_driver_nl80211_data *drv, struct nl_msg *msg, 248 int (*valid_handler)(struct nl_msg *, void *), 249 void *valid_data, 250 int (*ack_handler_custom)(struct nl_msg *, void *), 251 void *ack_data); 252 struct nl_sock * get_connect_handle(struct i802_bss *bss); 253 int nl80211_create_iface(struct wpa_driver_nl80211_data *drv, 254 const char *ifname, enum nl80211_iftype iftype, 255 const u8 *addr, int wds, 256 int (*handler)(struct nl_msg *, void *), 257 void *arg, int use_existing); 258 void nl80211_remove_iface(struct wpa_driver_nl80211_data *drv, int ifidx); 259 unsigned int nl80211_get_assoc_freq(struct wpa_driver_nl80211_data *drv); 260 int nl80211_get_assoc_ssid(struct wpa_driver_nl80211_data *drv, u8 *ssid); 261 enum chan_width convert2width(int width); 262 void nl80211_mark_disconnected(struct wpa_driver_nl80211_data *drv); 263 struct i802_bss * get_bss_ifindex(struct wpa_driver_nl80211_data *drv, 264 int ifindex); 265 int is_ap_interface(enum nl80211_iftype nlmode); 266 int is_sta_interface(enum nl80211_iftype nlmode); 267 int wpa_driver_nl80211_authenticate_retry(struct wpa_driver_nl80211_data *drv); 268 int nl80211_get_link_signal(struct wpa_driver_nl80211_data *drv, 269 struct wpa_signal_info *sig); 270 int nl80211_get_link_noise(struct wpa_driver_nl80211_data *drv, 271 struct wpa_signal_info *sig_change); 272 int nl80211_get_wiphy_index(struct i802_bss *bss); 273 int wpa_driver_nl80211_set_mode(struct i802_bss *bss, 274 enum nl80211_iftype nlmode); 275 int wpa_driver_nl80211_mlme(struct wpa_driver_nl80211_data *drv, 276 const u8 *addr, int cmd, u16 reason_code, 277 int local_state_change, 278 struct i802_bss *bss); 279 280 int nl80211_create_monitor_interface(struct wpa_driver_nl80211_data *drv); 281 void nl80211_remove_monitor_interface(struct wpa_driver_nl80211_data *drv); 282 int nl80211_send_monitor(struct wpa_driver_nl80211_data *drv, 283 const void *data, size_t len, 284 int encrypt, int noack); 285 286 int wpa_driver_nl80211_capa(struct wpa_driver_nl80211_data *drv); 287 struct hostapd_hw_modes * 288 nl80211_get_hw_feature_data(void *priv, u16 *num_modes, u16 *flags, 289 u8 *dfs_domain); 290 291 int process_global_event(struct nl_msg *msg, void *arg); 292 int process_bss_event(struct nl_msg *msg, void *arg); 293 294 const char * nl80211_iftype_str(enum nl80211_iftype mode); 295 296 void nl80211_restore_ap_mode(struct i802_bss *bss); 297 298 #ifdef ANDROID 299 int android_nl_socket_set_nonblocking(struct nl_sock *handle); 300 int android_pno_start(struct i802_bss *bss, 301 struct wpa_driver_scan_params *params); 302 int android_pno_stop(struct i802_bss *bss); 303 extern int wpa_driver_nl80211_driver_cmd(void *priv, char *cmd, char *buf, 304 size_t buf_len); 305 extern int wpa_driver_nl80211_driver_event(struct wpa_driver_nl80211_data *drv, 306 u32 vendor_id, u32 subcmd, 307 u8 *data, size_t len); 308 309 310 #ifdef ANDROID_P2P 311 int wpa_driver_set_p2p_noa(void *priv, u8 count, int start, int duration); 312 int wpa_driver_get_p2p_noa(void *priv, u8 *buf, size_t len); 313 int wpa_driver_set_p2p_ps(void *priv, int legacy_ps, int opp_ps, int ctwindow); 314 int wpa_driver_set_ap_wps_p2p_ie(void *priv, const struct wpabuf *beacon, 315 const struct wpabuf *proberesp, 316 const struct wpabuf *assocresp); 317 #endif /* ANDROID_P2P */ 318 #endif /* ANDROID */ 319 320 321 /* driver_nl80211_scan.c */ 322 323 void wpa_driver_nl80211_scan_timeout(void *eloop_ctx, void *timeout_ctx); 324 int wpa_driver_nl80211_scan(struct i802_bss *bss, 325 struct wpa_driver_scan_params *params); 326 int wpa_driver_nl80211_sched_scan(void *priv, 327 struct wpa_driver_scan_params *params); 328 int wpa_driver_nl80211_stop_sched_scan(void *priv); 329 struct wpa_scan_results * wpa_driver_nl80211_get_scan_results(void *priv); 330 void nl80211_dump_scan(struct wpa_driver_nl80211_data *drv); 331 int wpa_driver_nl80211_abort_scan(void *priv, u64 scan_cookie); 332 int wpa_driver_nl80211_vendor_scan(struct i802_bss *bss, 333 struct wpa_driver_scan_params *params); 334 int nl80211_set_default_scan_ies(void *priv, const u8 *ies, size_t ies_len); 335 336 #endif /* DRIVER_NL80211_H */ 337