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