1 /* 2 * Driver interaction with Linux nl80211/cfg80211 3 * Copyright (c) 2002-2012, 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 "includes.h" 17 #include <sys/ioctl.h> 18 #include <sys/types.h> 19 #include <sys/stat.h> 20 #include <fcntl.h> 21 #include <net/if.h> 22 #include <netlink/genl/genl.h> 23 #include <netlink/genl/family.h> 24 #include <netlink/genl/ctrl.h> 25 #include <linux/rtnetlink.h> 26 #include <netpacket/packet.h> 27 #include <linux/filter.h> 28 #include <linux/errqueue.h> 29 #include "nl80211_copy.h" 30 31 #include "common.h" 32 #include "eloop.h" 33 #include "utils/list.h" 34 #include "common/ieee802_11_defs.h" 35 #include "common/ieee802_11_common.h" 36 #include "l2_packet/l2_packet.h" 37 #include "netlink.h" 38 #include "linux_ioctl.h" 39 #include "radiotap.h" 40 #include "radiotap_iter.h" 41 #include "rfkill.h" 42 #include "driver.h" 43 44 #ifdef CONFIG_LIBNL20 45 /* libnl 2.0 compatibility code */ 46 #define nl_handle nl_sock 47 #define nl80211_handle_alloc nl_socket_alloc_cb 48 #define nl80211_handle_destroy nl_socket_free 49 #endif /* CONFIG_LIBNL20 */ 50 51 #ifndef IFF_LOWER_UP 52 #define IFF_LOWER_UP 0x10000 /* driver signals L1 up */ 53 #endif 54 #ifndef IFF_DORMANT 55 #define IFF_DORMANT 0x20000 /* driver signals dormant */ 56 #endif 57 58 #ifndef IF_OPER_DORMANT 59 #define IF_OPER_DORMANT 5 60 #endif 61 #ifndef IF_OPER_UP 62 #define IF_OPER_UP 6 63 #endif 64 65 struct nl80211_global { 66 struct dl_list interfaces; 67 int if_add_ifindex; 68 u64 if_add_wdevid; 69 int if_add_wdevid_set; 70 struct netlink_data *netlink; 71 struct nl_cb *nl_cb; 72 struct nl_handle *nl; 73 int nl80211_id; 74 int ioctl_sock; /* socket for ioctl() use */ 75 76 struct nl_handle *nl_event; 77 }; 78 79 struct nl80211_wiphy_data { 80 struct dl_list list; 81 struct dl_list bsss; 82 struct dl_list drvs; 83 84 struct nl_handle *nl_beacons; 85 struct nl_cb *nl_cb; 86 87 int wiphy_idx; 88 }; 89 90 struct i802_bss { 91 struct wpa_driver_nl80211_data *drv; 92 struct i802_bss *next; 93 int ifindex; 94 u64 wdev_id; 95 char ifname[IFNAMSIZ + 1]; 96 char brname[IFNAMSIZ]; 97 unsigned int beacon_set:1; 98 unsigned int added_if_into_bridge:1; 99 unsigned int added_bridge:1; 100 unsigned int in_deinit:1; 101 unsigned int wdev_id_set:1; 102 103 u8 addr[ETH_ALEN]; 104 105 int freq; 106 107 void *ctx; 108 struct nl_handle *nl_preq, *nl_mgmt; 109 struct nl_cb *nl_cb; 110 111 struct nl80211_wiphy_data *wiphy_data; 112 struct dl_list wiphy_list; 113 }; 114 115 struct wpa_driver_nl80211_data { 116 struct nl80211_global *global; 117 struct dl_list list; 118 struct dl_list wiphy_list; 119 char phyname[32]; 120 void *ctx; 121 int ifindex; 122 int if_removed; 123 int if_disabled; 124 int ignore_if_down_event; 125 struct rfkill_data *rfkill; 126 struct wpa_driver_capa capa; 127 u8 *extended_capa, *extended_capa_mask; 128 unsigned int extended_capa_len; 129 int has_capability; 130 131 int operstate; 132 133 int scan_complete_events; 134 135 struct nl_cb *nl_cb; 136 137 u8 auth_bssid[ETH_ALEN]; 138 u8 auth_attempt_bssid[ETH_ALEN]; 139 u8 bssid[ETH_ALEN]; 140 u8 prev_bssid[ETH_ALEN]; 141 int associated; 142 u8 ssid[32]; 143 size_t ssid_len; 144 enum nl80211_iftype nlmode; 145 enum nl80211_iftype ap_scan_as_station; 146 unsigned int assoc_freq; 147 148 int monitor_sock; 149 int monitor_ifidx; 150 int monitor_refcount; 151 152 unsigned int disabled_11b_rates:1; 153 unsigned int pending_remain_on_chan:1; 154 unsigned int in_interface_list:1; 155 unsigned int device_ap_sme:1; 156 unsigned int poll_command_supported:1; 157 unsigned int data_tx_status:1; 158 unsigned int scan_for_auth:1; 159 unsigned int retry_auth:1; 160 unsigned int use_monitor:1; 161 unsigned int ignore_next_local_disconnect:1; 162 unsigned int allow_p2p_device:1; 163 164 u64 remain_on_chan_cookie; 165 u64 send_action_cookie; 166 167 unsigned int last_mgmt_freq; 168 169 struct wpa_driver_scan_filter *filter_ssids; 170 size_t num_filter_ssids; 171 172 struct i802_bss first_bss; 173 174 int eapol_tx_sock; 175 176 #ifdef HOSTAPD 177 int eapol_sock; /* socket for EAPOL frames */ 178 179 int default_if_indices[16]; 180 int *if_indices; 181 int num_if_indices; 182 183 int last_freq; 184 int last_freq_ht; 185 #endif /* HOSTAPD */ 186 187 /* From failed authentication command */ 188 int auth_freq; 189 u8 auth_bssid_[ETH_ALEN]; 190 u8 auth_ssid[32]; 191 size_t auth_ssid_len; 192 int auth_alg; 193 u8 *auth_ie; 194 size_t auth_ie_len; 195 u8 auth_wep_key[4][16]; 196 size_t auth_wep_key_len[4]; 197 int auth_wep_tx_keyidx; 198 int auth_local_state_change; 199 int auth_p2p; 200 }; 201 202 #endif 203