Home | History | Annotate | Download | only in drivers
      1 /*
      2  * Driver interaction with Linux nl80211/cfg80211 - definitions
      3  * Copyright (c) 2002-2014, Jouni Malinen <j (at) 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 (at) 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 {
     28 	void *ctx;
     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 	u8 rand_addr[ETH_ALEN];
     82 };
     83 
     84 struct wpa_driver_nl80211_data {
     85 	struct nl80211_global *global;
     86 	struct dl_list list;
     87 	struct dl_list wiphy_list;
     88 	char phyname[32];
     89 	unsigned int wiphy_idx;
     90 	u8 perm_addr[ETH_ALEN];
     91 	void *ctx;
     92 	int ifindex;
     93 	int if_removed;
     94 	int if_disabled;
     95 	int ignore_if_down_event;
     96 	struct rfkill_data *rfkill;
     97 	struct wpa_driver_capa capa;
     98 	u8 *extended_capa, *extended_capa_mask;
     99 	unsigned int extended_capa_len;
    100 	struct drv_nl80211_ext_capa {
    101 		enum nl80211_iftype iftype;
    102 		u8 *ext_capa, *ext_capa_mask;
    103 		unsigned int ext_capa_len;
    104 	} iface_ext_capa[NL80211_IFTYPE_MAX];
    105 	unsigned int num_iface_ext_capa;
    106 
    107 	int has_capability;
    108 
    109 	int operstate;
    110 
    111 	int scan_complete_events;
    112 	enum scan_states {
    113 		NO_SCAN, SCAN_REQUESTED, SCAN_STARTED, SCAN_COMPLETED,
    114 		SCAN_ABORTED, SCHED_SCAN_STARTED, SCHED_SCAN_STOPPED,
    115 		SCHED_SCAN_RESULTS
    116 	} scan_state;
    117 
    118 	u8 auth_bssid[ETH_ALEN];
    119 	u8 auth_attempt_bssid[ETH_ALEN];
    120 	u8 bssid[ETH_ALEN];
    121 	u8 prev_bssid[ETH_ALEN];
    122 	int associated;
    123 	u8 ssid[SSID_MAX_LEN];
    124 	size_t ssid_len;
    125 	enum nl80211_iftype nlmode;
    126 	enum nl80211_iftype ap_scan_as_station;
    127 	unsigned int assoc_freq;
    128 
    129 	int monitor_sock;
    130 	int monitor_ifidx;
    131 	int monitor_refcount;
    132 
    133 	unsigned int disabled_11b_rates:1;
    134 	unsigned int pending_remain_on_chan:1;
    135 	unsigned int in_interface_list:1;
    136 	unsigned int device_ap_sme:1;
    137 	unsigned int poll_command_supported:1;
    138 	unsigned int data_tx_status:1;
    139 	unsigned int scan_for_auth:1;
    140 	unsigned int retry_auth:1;
    141 	unsigned int use_monitor:1;
    142 	unsigned int ignore_next_local_disconnect:1;
    143 	unsigned int ignore_next_local_deauth:1;
    144 	unsigned int hostapd:1;
    145 	unsigned int start_mode_ap:1;
    146 	unsigned int start_iface_up:1;
    147 	unsigned int test_use_roc_tx:1;
    148 	unsigned int ignore_deauth_event:1;
    149 	unsigned int vendor_cmd_test_avail:1;
    150 	unsigned int roaming_vendor_cmd_avail:1;
    151 	unsigned int dfs_vendor_cmd_avail:1;
    152 	unsigned int have_low_prio_scan:1;
    153 	unsigned int force_connect_cmd:1;
    154 	unsigned int addr_changed:1;
    155 	unsigned int get_features_vendor_cmd_avail:1;
    156 	unsigned int set_rekey_offload:1;
    157 	unsigned int p2p_go_ctwindow_supported:1;
    158 	unsigned int setband_vendor_cmd_avail:1;
    159 	unsigned int get_pref_freq_list:1;
    160 	unsigned int set_prob_oper_freq:1;
    161 	unsigned int scan_vendor_cmd_avail:1;
    162 	unsigned int connect_reassoc:1;
    163 	unsigned int set_wifi_conf_vendor_cmd_avail:1;
    164 	unsigned int he_capab_vendor_cmd_avail:1;
    165 	unsigned int fetch_bss_trans_status:1;
    166 	unsigned int roam_vendor_cmd_avail:1;
    167 
    168 	u64 vendor_scan_cookie;
    169 	u64 remain_on_chan_cookie;
    170 	u64 send_action_cookie;
    171 #define MAX_SEND_ACTION_COOKIES 20
    172 	u64 send_action_cookies[MAX_SEND_ACTION_COOKIES];
    173 	unsigned int num_send_action_cookies;
    174 
    175 	unsigned int last_mgmt_freq;
    176 
    177 	struct wpa_driver_scan_filter *filter_ssids;
    178 	size_t num_filter_ssids;
    179 
    180 	struct i802_bss *first_bss;
    181 
    182 	int eapol_tx_sock;
    183 
    184 	int eapol_sock; /* socket for EAPOL frames */
    185 
    186 	struct nl_handle *rtnl_sk; /* nl_sock for NETLINK_ROUTE */
    187 
    188 	int default_if_indices[16];
    189 	/* the AP/AP_VLAN iface that is in this bridge */
    190 	int default_if_indices_reason[16];
    191 	int *if_indices;
    192 	int *if_indices_reason;
    193 	int num_if_indices;
    194 
    195 	/* From failed authentication command */
    196 	int auth_freq;
    197 	u8 auth_bssid_[ETH_ALEN];
    198 	u8 auth_ssid[SSID_MAX_LEN];
    199 	size_t auth_ssid_len;
    200 	int auth_alg;
    201 	u8 *auth_ie;
    202 	size_t auth_ie_len;
    203 	u8 auth_wep_key[4][16];
    204 	size_t auth_wep_key_len[4];
    205 	int auth_wep_tx_keyidx;
    206 	int auth_local_state_change;
    207 	int auth_p2p;
    208 
    209 	/*
    210 	 * Tells whether the last scan issued from wpa_supplicant was a normal
    211 	 * scan (NL80211_CMD_TRIGGER_SCAN) or a vendor scan
    212 	 * (NL80211_CMD_VENDOR). 0 if no pending scan request.
    213 	 */
    214 	int last_scan_cmd;
    215 
    216 	struct he_capabilities he_capab;
    217 };
    218 
    219 struct nl_msg;
    220 
    221 void * nl80211_cmd(struct wpa_driver_nl80211_data *drv,
    222 		   struct nl_msg *msg, int flags, uint8_t cmd);
    223 struct nl_msg * nl80211_cmd_msg(struct i802_bss *bss, int flags, uint8_t cmd);
    224 struct nl_msg * nl80211_drv_msg(struct wpa_driver_nl80211_data *drv, int flags,
    225 				uint8_t cmd);
    226 struct nl_msg * nl80211_bss_msg(struct i802_bss *bss, int flags, uint8_t cmd);
    227 int send_and_recv_msgs(struct wpa_driver_nl80211_data *drv, struct nl_msg *msg,
    228 		       int (*valid_handler)(struct nl_msg *, void *),
    229 		       void *valid_data);
    230 int nl80211_create_iface(struct wpa_driver_nl80211_data *drv,
    231 			 const char *ifname, enum nl80211_iftype iftype,
    232 			 const u8 *addr, int wds,
    233 			 int (*handler)(struct nl_msg *, void *),
    234 			 void *arg, int use_existing);
    235 void nl80211_remove_iface(struct wpa_driver_nl80211_data *drv, int ifidx);
    236 unsigned int nl80211_get_assoc_freq(struct wpa_driver_nl80211_data *drv);
    237 int nl80211_get_assoc_ssid(struct wpa_driver_nl80211_data *drv, u8 *ssid);
    238 enum chan_width convert2width(int width);
    239 void nl80211_mark_disconnected(struct wpa_driver_nl80211_data *drv);
    240 struct i802_bss * get_bss_ifindex(struct wpa_driver_nl80211_data *drv,
    241 				  int ifindex);
    242 int is_ap_interface(enum nl80211_iftype nlmode);
    243 int is_sta_interface(enum nl80211_iftype nlmode);
    244 int wpa_driver_nl80211_authenticate_retry(struct wpa_driver_nl80211_data *drv);
    245 int nl80211_get_link_signal(struct wpa_driver_nl80211_data *drv,
    246 			    struct wpa_signal_info *sig);
    247 int nl80211_get_link_noise(struct wpa_driver_nl80211_data *drv,
    248 			   struct wpa_signal_info *sig_change);
    249 int nl80211_get_wiphy_index(struct i802_bss *bss);
    250 int wpa_driver_nl80211_set_mode(struct i802_bss *bss,
    251 				enum nl80211_iftype nlmode);
    252 int wpa_driver_nl80211_mlme(struct wpa_driver_nl80211_data *drv,
    253 			    const u8 *addr, int cmd, u16 reason_code,
    254 			    int local_state_change);
    255 
    256 int nl80211_create_monitor_interface(struct wpa_driver_nl80211_data *drv);
    257 void nl80211_remove_monitor_interface(struct wpa_driver_nl80211_data *drv);
    258 int nl80211_send_monitor(struct wpa_driver_nl80211_data *drv,
    259 			 const void *data, size_t len,
    260 			 int encrypt, int noack);
    261 
    262 int wpa_driver_nl80211_capa(struct wpa_driver_nl80211_data *drv);
    263 struct hostapd_hw_modes *
    264 nl80211_get_hw_feature_data(void *priv, u16 *num_modes, u16 *flags,
    265 			    u8 *dfs_domain);
    266 
    267 int process_global_event(struct nl_msg *msg, void *arg);
    268 int process_bss_event(struct nl_msg *msg, void *arg);
    269 
    270 const char * nl80211_iftype_str(enum nl80211_iftype mode);
    271 
    272 #ifdef ANDROID
    273 int android_nl_socket_set_nonblocking(struct nl_handle *handle);
    274 int android_pno_start(struct i802_bss *bss,
    275 		      struct wpa_driver_scan_params *params);
    276 int android_pno_stop(struct i802_bss *bss);
    277 extern int wpa_driver_nl80211_driver_cmd(void *priv, char *cmd, char *buf,
    278 					 size_t buf_len);
    279 
    280 #ifdef ANDROID_P2P
    281 int wpa_driver_set_p2p_noa(void *priv, u8 count, int start, int duration);
    282 int wpa_driver_get_p2p_noa(void *priv, u8 *buf, size_t len);
    283 int wpa_driver_set_p2p_ps(void *priv, int legacy_ps, int opp_ps, int ctwindow);
    284 int wpa_driver_set_ap_wps_p2p_ie(void *priv, const struct wpabuf *beacon,
    285 				 const struct wpabuf *proberesp,
    286 				 const struct wpabuf *assocresp);
    287 #endif /* ANDROID_P2P */
    288 #endif /* ANDROID */
    289 
    290 
    291 /* driver_nl80211_scan.c */
    292 
    293 void wpa_driver_nl80211_scan_timeout(void *eloop_ctx, void *timeout_ctx);
    294 int wpa_driver_nl80211_scan(struct i802_bss *bss,
    295 			    struct wpa_driver_scan_params *params);
    296 int wpa_driver_nl80211_sched_scan(void *priv,
    297 				  struct wpa_driver_scan_params *params);
    298 int wpa_driver_nl80211_stop_sched_scan(void *priv);
    299 struct wpa_scan_results * wpa_driver_nl80211_get_scan_results(void *priv);
    300 void nl80211_dump_scan(struct wpa_driver_nl80211_data *drv);
    301 int wpa_driver_nl80211_abort_scan(void *priv, u64 scan_cookie);
    302 int wpa_driver_nl80211_vendor_scan(struct i802_bss *bss,
    303 				   struct wpa_driver_scan_params *params);
    304 int nl80211_set_default_scan_ies(void *priv, const u8 *ies, size_t ies_len);
    305 
    306 #endif /* DRIVER_NL80211_H */
    307