]>
Commit | Line | Data |
---|---|---|
3f5285e8 | 1 | /* |
c5121837 | 2 | * Driver interaction with Linux nl80211/cfg80211 |
3d9975d5 | 3 | * Copyright (c) 2002-2012, Jouni Malinen <j@w1.fi> |
072ad14c JM |
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> | |
58f6fbe0 | 7 | * Copyright (c) 2009-2010, Atheros Communications |
3f5285e8 | 8 | * |
0f3d578e JM |
9 | * This software may be distributed under the terms of the BSD license. |
10 | * See README for more details. | |
3f5285e8 JM |
11 | */ |
12 | ||
13 | #include "includes.h" | |
14 | #include <sys/ioctl.h> | |
6859f1cb BG |
15 | #include <sys/types.h> |
16 | #include <sys/stat.h> | |
17 | #include <fcntl.h> | |
37b7d082 | 18 | #include <net/if.h> |
3f5285e8 JM |
19 | #include <netlink/genl/genl.h> |
20 | #include <netlink/genl/family.h> | |
21 | #include <netlink/genl/ctrl.h> | |
8602b0f2 | 22 | #include <linux/rtnetlink.h> |
1b648c7e JM |
23 | #include <netpacket/packet.h> |
24 | #include <linux/filter.h> | |
32ab4855 | 25 | #include <linux/errqueue.h> |
7e45830a | 26 | #include "nl80211_copy.h" |
625f587b | 27 | |
3f5285e8 | 28 | #include "common.h" |
1b648c7e | 29 | #include "eloop.h" |
f2ed8023 | 30 | #include "utils/list.h" |
1b648c7e | 31 | #include "common/ieee802_11_defs.h" |
9b90955e | 32 | #include "common/ieee802_11_common.h" |
f10bfc9a | 33 | #include "l2_packet/l2_packet.h" |
e2d02c29 | 34 | #include "netlink.h" |
34f2f814 | 35 | #include "linux_ioctl.h" |
e2d02c29 JM |
36 | #include "radiotap.h" |
37 | #include "radiotap_iter.h" | |
8401a6b0 | 38 | #include "rfkill.h" |
1b648c7e | 39 | #include "driver.h" |
0915d02c | 40 | |
32ab4855 JB |
41 | #ifndef SO_WIFI_STATUS |
42 | # if defined(__sparc__) | |
43 | # define SO_WIFI_STATUS 0x0025 | |
44 | # elif defined(__parisc__) | |
45 | # define SO_WIFI_STATUS 0x4022 | |
46 | # else | |
47 | # define SO_WIFI_STATUS 41 | |
48 | # endif | |
49 | ||
50 | # define SCM_WIFI_STATUS SO_WIFI_STATUS | |
51 | #endif | |
52 | ||
53 | #ifndef SO_EE_ORIGIN_TXSTATUS | |
54 | #define SO_EE_ORIGIN_TXSTATUS 4 | |
55 | #endif | |
56 | ||
57 | #ifndef PACKET_TX_TIMESTAMP | |
58 | #define PACKET_TX_TIMESTAMP 16 | |
59 | #endif | |
60 | ||
216eede8 DS |
61 | #ifdef ANDROID |
62 | #include "android_drv.h" | |
63 | #endif /* ANDROID */ | |
c5121837 JM |
64 | #ifdef CONFIG_LIBNL20 |
65 | /* libnl 2.0 compatibility code */ | |
2e8eac2d | 66 | #define nl_handle nl_sock |
a65a9aed JB |
67 | #define nl80211_handle_alloc nl_socket_alloc_cb |
68 | #define nl80211_handle_destroy nl_socket_free | |
69 | #else | |
70 | /* | |
71 | * libnl 1.1 has a bug, it tries to allocate socket numbers densely | |
72 | * but when you free a socket again it will mess up its bitmap and | |
73 | * and use the wrong number the next time it needs a socket ID. | |
74 | * Therefore, we wrap the handle alloc/destroy and add our own pid | |
75 | * accounting. | |
76 | */ | |
77 | static uint32_t port_bitmap[32] = { 0 }; | |
78 | ||
79 | static struct nl_handle *nl80211_handle_alloc(void *cb) | |
80 | { | |
81 | struct nl_handle *handle; | |
82 | uint32_t pid = getpid() & 0x3FFFFF; | |
83 | int i; | |
84 | ||
85 | handle = nl_handle_alloc_cb(cb); | |
86 | ||
87 | for (i = 0; i < 1024; i++) { | |
88 | if (port_bitmap[i / 32] & (1 << (i % 32))) | |
89 | continue; | |
90 | port_bitmap[i / 32] |= 1 << (i % 32); | |
91 | pid += i << 22; | |
92 | break; | |
93 | } | |
94 | ||
95 | nl_socket_set_local_port(handle, pid); | |
96 | ||
97 | return handle; | |
98 | } | |
99 | ||
100 | static void nl80211_handle_destroy(struct nl_handle *handle) | |
101 | { | |
102 | uint32_t port = nl_socket_get_local_port(handle); | |
103 | ||
104 | port >>= 22; | |
105 | port_bitmap[port / 32] &= ~(1 << (port % 32)); | |
106 | ||
107 | nl_handle_destroy(handle); | |
108 | } | |
c5121837 JM |
109 | #endif /* CONFIG_LIBNL20 */ |
110 | ||
c5121837 | 111 | |
481234cf | 112 | static struct nl_handle * nl_create_handle(struct nl_cb *cb, const char *dbg) |
a92dfde8 | 113 | { |
481234cf | 114 | struct nl_handle *handle; |
a92dfde8 | 115 | |
481234cf JM |
116 | handle = nl80211_handle_alloc(cb); |
117 | if (handle == NULL) { | |
a92dfde8 JB |
118 | wpa_printf(MSG_ERROR, "nl80211: Failed to allocate netlink " |
119 | "callbacks (%s)", dbg); | |
481234cf | 120 | return NULL; |
a92dfde8 JB |
121 | } |
122 | ||
481234cf | 123 | if (genl_connect(handle)) { |
a92dfde8 JB |
124 | wpa_printf(MSG_ERROR, "nl80211: Failed to connect to generic " |
125 | "netlink (%s)", dbg); | |
481234cf JM |
126 | nl80211_handle_destroy(handle); |
127 | return NULL; | |
a92dfde8 JB |
128 | } |
129 | ||
481234cf | 130 | return handle; |
a92dfde8 JB |
131 | } |
132 | ||
133 | ||
481234cf | 134 | static void nl_destroy_handles(struct nl_handle **handle) |
a92dfde8 | 135 | { |
481234cf | 136 | if (*handle == NULL) |
a92dfde8 | 137 | return; |
481234cf JM |
138 | nl80211_handle_destroy(*handle); |
139 | *handle = NULL; | |
a92dfde8 JB |
140 | } |
141 | ||
142 | ||
10b85921 JB |
143 | #if __WORDSIZE == 64 |
144 | #define ELOOP_SOCKET_INVALID (intptr_t) 0x8888888888888889ULL | |
145 | #else | |
146 | #define ELOOP_SOCKET_INVALID (intptr_t) 0x88888889ULL | |
147 | #endif | |
148 | ||
5f65e9f7 JB |
149 | static void nl80211_register_eloop_read(struct nl_handle **handle, |
150 | eloop_sock_handler handler, | |
151 | void *eloop_data) | |
152 | { | |
10b85921 | 153 | nl_socket_set_nonblocking(*handle); |
5f65e9f7 JB |
154 | eloop_register_read_sock(nl_socket_get_fd(*handle), handler, |
155 | eloop_data, *handle); | |
10b85921 | 156 | *handle = (void *) (((intptr_t) *handle) ^ ELOOP_SOCKET_INVALID); |
5f65e9f7 JB |
157 | } |
158 | ||
159 | ||
160 | static void nl80211_destroy_eloop_handle(struct nl_handle **handle) | |
161 | { | |
10b85921 | 162 | *handle = (void *) (((intptr_t) *handle) ^ ELOOP_SOCKET_INVALID); |
5f65e9f7 JB |
163 | eloop_unregister_read_sock(nl_socket_get_fd(*handle)); |
164 | nl_destroy_handles(handle); | |
165 | } | |
166 | ||
167 | ||
3f5285e8 JM |
168 | #ifndef IFF_LOWER_UP |
169 | #define IFF_LOWER_UP 0x10000 /* driver signals L1 up */ | |
170 | #endif | |
171 | #ifndef IFF_DORMANT | |
172 | #define IFF_DORMANT 0x20000 /* driver signals dormant */ | |
173 | #endif | |
174 | ||
175 | #ifndef IF_OPER_DORMANT | |
176 | #define IF_OPER_DORMANT 5 | |
177 | #endif | |
178 | #ifndef IF_OPER_UP | |
179 | #define IF_OPER_UP 6 | |
180 | #endif | |
181 | ||
f2ed8023 JM |
182 | struct nl80211_global { |
183 | struct dl_list interfaces; | |
ff6a158b | 184 | int if_add_ifindex; |
f632e483 AS |
185 | u64 if_add_wdevid; |
186 | int if_add_wdevid_set; | |
36d84860 | 187 | struct netlink_data *netlink; |
2a7b66f5 | 188 | struct nl_cb *nl_cb; |
481234cf | 189 | struct nl_handle *nl; |
335d42b1 | 190 | int nl80211_id; |
c81eff1a | 191 | int ioctl_sock; /* socket for ioctl() use */ |
d6c9aab8 | 192 | |
481234cf | 193 | struct nl_handle *nl_event; |
f2ed8023 JM |
194 | }; |
195 | ||
e32ad281 JB |
196 | struct nl80211_wiphy_data { |
197 | struct dl_list list; | |
198 | struct dl_list bsss; | |
199 | struct dl_list drvs; | |
200 | ||
481234cf | 201 | struct nl_handle *nl_beacons; |
e32ad281 JB |
202 | struct nl_cb *nl_cb; |
203 | ||
204 | int wiphy_idx; | |
205 | }; | |
206 | ||
36d84860 BG |
207 | static void nl80211_global_deinit(void *priv); |
208 | ||
c5121837 | 209 | struct i802_bss { |
a2e40bb6 | 210 | struct wpa_driver_nl80211_data *drv; |
c5121837 | 211 | struct i802_bss *next; |
b4fd6fab | 212 | int ifindex; |
d3aaef80 | 213 | u64 wdev_id; |
a2e40bb6 | 214 | char ifname[IFNAMSIZ + 1]; |
e17a2477 | 215 | char brname[IFNAMSIZ]; |
c5121837 | 216 | unsigned int beacon_set:1; |
e17a2477 JM |
217 | unsigned int added_if_into_bridge:1; |
218 | unsigned int added_bridge:1; | |
873d0fcf | 219 | unsigned int in_deinit:1; |
d3aaef80 | 220 | unsigned int wdev_id_set:1; |
221a59c9 | 221 | |
341eebee JB |
222 | u8 addr[ETH_ALEN]; |
223 | ||
e4fb2167 | 224 | int freq; |
60b13c20 | 225 | int if_dynamic; |
e4fb2167 | 226 | |
a5e1eb20 | 227 | void *ctx; |
481234cf | 228 | struct nl_handle *nl_preq, *nl_mgmt; |
cc7a48d1 | 229 | struct nl_cb *nl_cb; |
e32ad281 JB |
230 | |
231 | struct nl80211_wiphy_data *wiphy_data; | |
232 | struct dl_list wiphy_list; | |
c5121837 | 233 | }; |
3f5285e8 JM |
234 | |
235 | struct wpa_driver_nl80211_data { | |
f2ed8023 JM |
236 | struct nl80211_global *global; |
237 | struct dl_list list; | |
e32ad281 | 238 | struct dl_list wiphy_list; |
6859f1cb | 239 | char phyname[32]; |
3f5285e8 | 240 | void *ctx; |
3f5285e8 | 241 | int ifindex; |
7524cfb1 | 242 | int if_removed; |
a63063b4 | 243 | int if_disabled; |
7d9c3698 | 244 | int ignore_if_down_event; |
8401a6b0 | 245 | struct rfkill_data *rfkill; |
c2a04078 | 246 | struct wpa_driver_capa capa; |
8cd6b7bc JB |
247 | u8 *extended_capa, *extended_capa_mask; |
248 | unsigned int extended_capa_len; | |
c2a04078 | 249 | int has_capability; |
c2a04078 | 250 | |
3f5285e8 JM |
251 | int operstate; |
252 | ||
3f5285e8 | 253 | int scan_complete_events; |
a771c07d JM |
254 | enum scan_states { |
255 | NO_SCAN, SCAN_REQUESTED, SCAN_STARTED, SCAN_COMPLETED, | |
256 | SCAN_ABORTED, SCHED_SCAN_STARTED, SCHED_SCAN_STOPPED, | |
257 | SCHED_SCAN_RESULTS | |
258 | } scan_state; | |
3f5285e8 | 259 | |
1afc986d | 260 | struct nl_cb *nl_cb; |
1c873584 | 261 | |
e6b8efeb | 262 | u8 auth_bssid[ETH_ALEN]; |
add9b7a4 | 263 | u8 auth_attempt_bssid[ETH_ALEN]; |
c2a04078 | 264 | u8 bssid[ETH_ALEN]; |
add9b7a4 | 265 | u8 prev_bssid[ETH_ALEN]; |
c2a04078 | 266 | int associated; |
fd05d64e JM |
267 | u8 ssid[32]; |
268 | size_t ssid_len; | |
b1f625e0 EP |
269 | enum nl80211_iftype nlmode; |
270 | enum nl80211_iftype ap_scan_as_station; | |
4832ecd7 | 271 | unsigned int assoc_freq; |
d2440ba0 | 272 | |
0915d02c JM |
273 | int monitor_sock; |
274 | int monitor_ifidx; | |
3fd1cefb | 275 | int monitor_refcount; |
7da3abe7 | 276 | |
b3af99d2 | 277 | unsigned int disabled_11b_rates:1; |
55777702 | 278 | unsigned int pending_remain_on_chan:1; |
dac12351 | 279 | unsigned int in_interface_list:1; |
61cbe2ff | 280 | unsigned int device_ap_sme:1; |
39718852 | 281 | unsigned int poll_command_supported:1; |
32ab4855 | 282 | unsigned int data_tx_status:1; |
536fd62d JM |
283 | unsigned int scan_for_auth:1; |
284 | unsigned int retry_auth:1; | |
a11241fa | 285 | unsigned int use_monitor:1; |
a8c5b43a | 286 | unsigned int ignore_next_local_disconnect:1; |
851b0c55 | 287 | unsigned int allow_p2p_device:1; |
55777702 JM |
288 | |
289 | u64 remain_on_chan_cookie; | |
58f6fbe0 | 290 | u64 send_action_cookie; |
c5121837 | 291 | |
5582a5d1 JB |
292 | unsigned int last_mgmt_freq; |
293 | ||
3812464c JM |
294 | struct wpa_driver_scan_filter *filter_ssids; |
295 | size_t num_filter_ssids; | |
296 | ||
a2e40bb6 FF |
297 | struct i802_bss first_bss; |
298 | ||
d12dab4c | 299 | int eapol_tx_sock; |
f10bfc9a | 300 | |
c5121837 | 301 | #ifdef HOSTAPD |
c5121837 | 302 | int eapol_sock; /* socket for EAPOL frames */ |
c5121837 JM |
303 | |
304 | int default_if_indices[16]; | |
305 | int *if_indices; | |
306 | int num_if_indices; | |
307 | ||
c5121837 JM |
308 | int last_freq; |
309 | int last_freq_ht; | |
c5121837 | 310 | #endif /* HOSTAPD */ |
536fd62d JM |
311 | |
312 | /* From failed authentication command */ | |
313 | int auth_freq; | |
314 | u8 auth_bssid_[ETH_ALEN]; | |
315 | u8 auth_ssid[32]; | |
316 | size_t auth_ssid_len; | |
317 | int auth_alg; | |
318 | u8 *auth_ie; | |
319 | size_t auth_ie_len; | |
320 | u8 auth_wep_key[4][16]; | |
321 | size_t auth_wep_key_len[4]; | |
322 | int auth_wep_tx_keyidx; | |
323 | int auth_local_state_change; | |
324 | int auth_p2p; | |
3f5285e8 JM |
325 | }; |
326 | ||
327 | ||
9ebce9c5 | 328 | static void wpa_driver_nl80211_deinit(struct i802_bss *bss); |
3f5285e8 JM |
329 | static void wpa_driver_nl80211_scan_timeout(void *eloop_ctx, |
330 | void *timeout_ctx); | |
b1f625e0 EP |
331 | static int wpa_driver_nl80211_set_mode(struct i802_bss *bss, |
332 | enum nl80211_iftype nlmode); | |
362f781e | 333 | static int |
7524cfb1 | 334 | wpa_driver_nl80211_finish_drv_init(struct wpa_driver_nl80211_data *drv); |
d72aad94 | 335 | static int wpa_driver_nl80211_mlme(struct wpa_driver_nl80211_data *drv, |
77339912 JM |
336 | const u8 *addr, int cmd, u16 reason_code, |
337 | int local_state_change); | |
460456f8 JM |
338 | static void nl80211_remove_monitor_interface( |
339 | struct wpa_driver_nl80211_data *drv); | |
88df0ef7 | 340 | static int nl80211_send_frame_cmd(struct i802_bss *bss, |
5dfca53f | 341 | unsigned int freq, unsigned int wait, |
b106173a | 342 | const u8 *buf, size_t buf_len, u64 *cookie, |
88df0ef7 | 343 | int no_cck, int no_ack, int offchanok); |
b21990b4 AQ |
344 | static int nl80211_register_frame(struct i802_bss *bss, |
345 | struct nl_handle *hl_handle, | |
346 | u16 type, const u8 *match, size_t match_len); | |
9ebce9c5 JM |
347 | static int wpa_driver_nl80211_probe_req_report(struct i802_bss *bss, |
348 | int report); | |
216eede8 DS |
349 | #ifdef ANDROID |
350 | static int android_pno_start(struct i802_bss *bss, | |
351 | struct wpa_driver_scan_params *params); | |
352 | static int android_pno_stop(struct i802_bss *bss); | |
353 | #endif /* ANDROID */ | |
0915d02c | 354 | |
072ad14c | 355 | #ifdef HOSTAPD |
2135f224 JM |
356 | static void add_ifidx(struct wpa_driver_nl80211_data *drv, int ifidx); |
357 | static void del_ifidx(struct wpa_driver_nl80211_data *drv, int ifidx); | |
97cfcf64 | 358 | static int have_ifidx(struct wpa_driver_nl80211_data *drv, int ifidx); |
9ebce9c5 | 359 | static int wpa_driver_nl80211_if_remove(struct i802_bss *bss, |
fbbfcbac FF |
360 | enum wpa_driver_if_type type, |
361 | const char *ifname); | |
37eb8da9 | 362 | #else /* HOSTAPD */ |
bd2df892 JM |
363 | static inline void add_ifidx(struct wpa_driver_nl80211_data *drv, int ifidx) |
364 | { | |
365 | } | |
366 | ||
367 | static inline void del_ifidx(struct wpa_driver_nl80211_data *drv, int ifidx) | |
368 | { | |
369 | } | |
370 | ||
371 | static inline int have_ifidx(struct wpa_driver_nl80211_data *drv, int ifidx) | |
37eb8da9 JM |
372 | { |
373 | return 0; | |
374 | } | |
072ad14c JM |
375 | #endif /* HOSTAPD */ |
376 | ||
9ebce9c5 JM |
377 | static int wpa_driver_nl80211_set_freq(struct i802_bss *bss, |
378 | struct hostapd_freq_params *freq); | |
4e5cb1a3 JM |
379 | static int nl80211_disable_11b_rates(struct wpa_driver_nl80211_data *drv, |
380 | int ifindex, int disabled); | |
504e905c | 381 | |
21bdbe38 | 382 | static int nl80211_leave_ibss(struct wpa_driver_nl80211_data *drv); |
536fd62d JM |
383 | static int wpa_driver_nl80211_authenticate_retry( |
384 | struct wpa_driver_nl80211_data *drv); | |
21bdbe38 | 385 | |
bf83eab5 IP |
386 | static int i802_set_iface_flags(struct i802_bss *bss, int up); |
387 | ||
3f5285e8 | 388 | |
2090a0b4 DS |
389 | static const char * nl80211_command_to_string(enum nl80211_commands cmd) |
390 | { | |
391 | #define C2S(x) case x: return #x; | |
392 | switch (cmd) { | |
393 | C2S(NL80211_CMD_UNSPEC) | |
394 | C2S(NL80211_CMD_GET_WIPHY) | |
395 | C2S(NL80211_CMD_SET_WIPHY) | |
396 | C2S(NL80211_CMD_NEW_WIPHY) | |
397 | C2S(NL80211_CMD_DEL_WIPHY) | |
398 | C2S(NL80211_CMD_GET_INTERFACE) | |
399 | C2S(NL80211_CMD_SET_INTERFACE) | |
400 | C2S(NL80211_CMD_NEW_INTERFACE) | |
401 | C2S(NL80211_CMD_DEL_INTERFACE) | |
402 | C2S(NL80211_CMD_GET_KEY) | |
403 | C2S(NL80211_CMD_SET_KEY) | |
404 | C2S(NL80211_CMD_NEW_KEY) | |
405 | C2S(NL80211_CMD_DEL_KEY) | |
406 | C2S(NL80211_CMD_GET_BEACON) | |
407 | C2S(NL80211_CMD_SET_BEACON) | |
408 | C2S(NL80211_CMD_START_AP) | |
409 | C2S(NL80211_CMD_STOP_AP) | |
410 | C2S(NL80211_CMD_GET_STATION) | |
411 | C2S(NL80211_CMD_SET_STATION) | |
412 | C2S(NL80211_CMD_NEW_STATION) | |
413 | C2S(NL80211_CMD_DEL_STATION) | |
414 | C2S(NL80211_CMD_GET_MPATH) | |
415 | C2S(NL80211_CMD_SET_MPATH) | |
416 | C2S(NL80211_CMD_NEW_MPATH) | |
417 | C2S(NL80211_CMD_DEL_MPATH) | |
418 | C2S(NL80211_CMD_SET_BSS) | |
419 | C2S(NL80211_CMD_SET_REG) | |
420 | C2S(NL80211_CMD_REQ_SET_REG) | |
421 | C2S(NL80211_CMD_GET_MESH_CONFIG) | |
422 | C2S(NL80211_CMD_SET_MESH_CONFIG) | |
423 | C2S(NL80211_CMD_SET_MGMT_EXTRA_IE) | |
424 | C2S(NL80211_CMD_GET_REG) | |
425 | C2S(NL80211_CMD_GET_SCAN) | |
426 | C2S(NL80211_CMD_TRIGGER_SCAN) | |
427 | C2S(NL80211_CMD_NEW_SCAN_RESULTS) | |
428 | C2S(NL80211_CMD_SCAN_ABORTED) | |
429 | C2S(NL80211_CMD_REG_CHANGE) | |
430 | C2S(NL80211_CMD_AUTHENTICATE) | |
431 | C2S(NL80211_CMD_ASSOCIATE) | |
432 | C2S(NL80211_CMD_DEAUTHENTICATE) | |
433 | C2S(NL80211_CMD_DISASSOCIATE) | |
434 | C2S(NL80211_CMD_MICHAEL_MIC_FAILURE) | |
435 | C2S(NL80211_CMD_REG_BEACON_HINT) | |
436 | C2S(NL80211_CMD_JOIN_IBSS) | |
437 | C2S(NL80211_CMD_LEAVE_IBSS) | |
438 | C2S(NL80211_CMD_TESTMODE) | |
439 | C2S(NL80211_CMD_CONNECT) | |
440 | C2S(NL80211_CMD_ROAM) | |
441 | C2S(NL80211_CMD_DISCONNECT) | |
442 | C2S(NL80211_CMD_SET_WIPHY_NETNS) | |
443 | C2S(NL80211_CMD_GET_SURVEY) | |
444 | C2S(NL80211_CMD_NEW_SURVEY_RESULTS) | |
445 | C2S(NL80211_CMD_SET_PMKSA) | |
446 | C2S(NL80211_CMD_DEL_PMKSA) | |
447 | C2S(NL80211_CMD_FLUSH_PMKSA) | |
448 | C2S(NL80211_CMD_REMAIN_ON_CHANNEL) | |
449 | C2S(NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL) | |
450 | C2S(NL80211_CMD_SET_TX_BITRATE_MASK) | |
451 | C2S(NL80211_CMD_REGISTER_FRAME) | |
452 | C2S(NL80211_CMD_FRAME) | |
453 | C2S(NL80211_CMD_FRAME_TX_STATUS) | |
454 | C2S(NL80211_CMD_SET_POWER_SAVE) | |
455 | C2S(NL80211_CMD_GET_POWER_SAVE) | |
456 | C2S(NL80211_CMD_SET_CQM) | |
457 | C2S(NL80211_CMD_NOTIFY_CQM) | |
458 | C2S(NL80211_CMD_SET_CHANNEL) | |
459 | C2S(NL80211_CMD_SET_WDS_PEER) | |
460 | C2S(NL80211_CMD_FRAME_WAIT_CANCEL) | |
461 | C2S(NL80211_CMD_JOIN_MESH) | |
462 | C2S(NL80211_CMD_LEAVE_MESH) | |
463 | C2S(NL80211_CMD_UNPROT_DEAUTHENTICATE) | |
464 | C2S(NL80211_CMD_UNPROT_DISASSOCIATE) | |
465 | C2S(NL80211_CMD_NEW_PEER_CANDIDATE) | |
466 | C2S(NL80211_CMD_GET_WOWLAN) | |
467 | C2S(NL80211_CMD_SET_WOWLAN) | |
468 | C2S(NL80211_CMD_START_SCHED_SCAN) | |
469 | C2S(NL80211_CMD_STOP_SCHED_SCAN) | |
470 | C2S(NL80211_CMD_SCHED_SCAN_RESULTS) | |
471 | C2S(NL80211_CMD_SCHED_SCAN_STOPPED) | |
472 | C2S(NL80211_CMD_SET_REKEY_OFFLOAD) | |
473 | C2S(NL80211_CMD_PMKSA_CANDIDATE) | |
474 | C2S(NL80211_CMD_TDLS_OPER) | |
475 | C2S(NL80211_CMD_TDLS_MGMT) | |
476 | C2S(NL80211_CMD_UNEXPECTED_FRAME) | |
477 | C2S(NL80211_CMD_PROBE_CLIENT) | |
478 | C2S(NL80211_CMD_REGISTER_BEACONS) | |
479 | C2S(NL80211_CMD_UNEXPECTED_4ADDR_FRAME) | |
480 | C2S(NL80211_CMD_SET_NOACK_MAP) | |
481 | C2S(NL80211_CMD_CH_SWITCH_NOTIFY) | |
482 | C2S(NL80211_CMD_START_P2P_DEVICE) | |
483 | C2S(NL80211_CMD_STOP_P2P_DEVICE) | |
484 | C2S(NL80211_CMD_CONN_FAILED) | |
485 | C2S(NL80211_CMD_SET_MCAST_RATE) | |
486 | C2S(NL80211_CMD_SET_MAC_ACL) | |
487 | C2S(NL80211_CMD_RADAR_DETECT) | |
488 | C2S(NL80211_CMD_GET_PROTOCOL_FEATURES) | |
489 | C2S(NL80211_CMD_UPDATE_FT_IES) | |
490 | C2S(NL80211_CMD_FT_EVENT) | |
491 | C2S(NL80211_CMD_CRIT_PROTOCOL_START) | |
492 | C2S(NL80211_CMD_CRIT_PROTOCOL_STOP) | |
493 | default: | |
494 | return "NL80211_CMD_UNKNOWN"; | |
495 | } | |
496 | #undef C2S | |
497 | } | |
498 | ||
499 | ||
b1f625e0 EP |
500 | static int is_ap_interface(enum nl80211_iftype nlmode) |
501 | { | |
502 | return (nlmode == NL80211_IFTYPE_AP || | |
503 | nlmode == NL80211_IFTYPE_P2P_GO); | |
504 | } | |
505 | ||
506 | ||
507 | static int is_sta_interface(enum nl80211_iftype nlmode) | |
508 | { | |
509 | return (nlmode == NL80211_IFTYPE_STATION || | |
510 | nlmode == NL80211_IFTYPE_P2P_CLIENT); | |
511 | } | |
512 | ||
513 | ||
6a71413e | 514 | static int is_p2p_net_interface(enum nl80211_iftype nlmode) |
b3af99d2 JM |
515 | { |
516 | return (nlmode == NL80211_IFTYPE_P2P_CLIENT || | |
517 | nlmode == NL80211_IFTYPE_P2P_GO); | |
518 | } | |
519 | ||
520 | ||
add9b7a4 JM |
521 | static void nl80211_mark_disconnected(struct wpa_driver_nl80211_data *drv) |
522 | { | |
523 | if (drv->associated) | |
524 | os_memcpy(drv->prev_bssid, drv->bssid, ETH_ALEN); | |
525 | drv->associated = 0; | |
526 | os_memset(drv->bssid, 0, ETH_ALEN); | |
527 | } | |
528 | ||
529 | ||
f5a8d422 JM |
530 | struct nl80211_bss_info_arg { |
531 | struct wpa_driver_nl80211_data *drv; | |
532 | struct wpa_scan_results *res; | |
533 | unsigned int assoc_freq; | |
20f5a4c2 | 534 | u8 assoc_bssid[ETH_ALEN]; |
f5a8d422 JM |
535 | }; |
536 | ||
537 | static int bss_info_handler(struct nl_msg *msg, void *arg); | |
538 | ||
539 | ||
6241fcb1 JM |
540 | /* nl80211 code */ |
541 | static int ack_handler(struct nl_msg *msg, void *arg) | |
542 | { | |
543 | int *err = arg; | |
544 | *err = 0; | |
545 | return NL_STOP; | |
546 | } | |
547 | ||
548 | static int finish_handler(struct nl_msg *msg, void *arg) | |
549 | { | |
8e8df255 JM |
550 | int *ret = arg; |
551 | *ret = 0; | |
6241fcb1 JM |
552 | return NL_SKIP; |
553 | } | |
554 | ||
555 | static int error_handler(struct sockaddr_nl *nla, struct nlmsgerr *err, | |
556 | void *arg) | |
557 | { | |
558 | int *ret = arg; | |
559 | *ret = err->error; | |
560 | return NL_SKIP; | |
561 | } | |
562 | ||
5b7b85f6 JM |
563 | |
564 | static int no_seq_check(struct nl_msg *msg, void *arg) | |
565 | { | |
566 | return NL_OK; | |
567 | } | |
568 | ||
569 | ||
d6c9aab8 | 570 | static int send_and_recv(struct nl80211_global *global, |
58f6fbe0 JM |
571 | struct nl_handle *nl_handle, struct nl_msg *msg, |
572 | int (*valid_handler)(struct nl_msg *, void *), | |
573 | void *valid_data) | |
6241fcb1 JM |
574 | { |
575 | struct nl_cb *cb; | |
576 | int err = -ENOMEM; | |
577 | ||
d6c9aab8 | 578 | cb = nl_cb_clone(global->nl_cb); |
6241fcb1 JM |
579 | if (!cb) |
580 | goto out; | |
581 | ||
58f6fbe0 | 582 | err = nl_send_auto_complete(nl_handle, msg); |
6241fcb1 JM |
583 | if (err < 0) |
584 | goto out; | |
585 | ||
586 | err = 1; | |
587 | ||
588 | nl_cb_err(cb, NL_CB_CUSTOM, error_handler, &err); | |
8e8df255 | 589 | nl_cb_set(cb, NL_CB_FINISH, NL_CB_CUSTOM, finish_handler, &err); |
6241fcb1 JM |
590 | nl_cb_set(cb, NL_CB_ACK, NL_CB_CUSTOM, ack_handler, &err); |
591 | ||
592 | if (valid_handler) | |
593 | nl_cb_set(cb, NL_CB_VALID, NL_CB_CUSTOM, | |
594 | valid_handler, valid_data); | |
595 | ||
34068ac3 JM |
596 | while (err > 0) { |
597 | int res = nl_recvmsgs(nl_handle, cb); | |
598 | if (res) { | |
599 | wpa_printf(MSG_INFO, | |
600 | "nl80211: %s->nl_recvmsgs failed: %d", | |
601 | __func__, res); | |
602 | } | |
603 | } | |
6241fcb1 JM |
604 | out: |
605 | nl_cb_put(cb); | |
606 | nlmsg_free(msg); | |
607 | return err; | |
608 | } | |
609 | ||
610 | ||
d6c9aab8 JB |
611 | static int send_and_recv_msgs_global(struct nl80211_global *global, |
612 | struct nl_msg *msg, | |
613 | int (*valid_handler)(struct nl_msg *, void *), | |
614 | void *valid_data) | |
615 | { | |
481234cf | 616 | return send_and_recv(global, global->nl, msg, valid_handler, |
d6c9aab8 JB |
617 | valid_data); |
618 | } | |
619 | ||
620 | ||
58f6fbe0 JM |
621 | static int send_and_recv_msgs(struct wpa_driver_nl80211_data *drv, |
622 | struct nl_msg *msg, | |
623 | int (*valid_handler)(struct nl_msg *, void *), | |
624 | void *valid_data) | |
625 | { | |
481234cf | 626 | return send_and_recv(drv->global, drv->global->nl, msg, |
d6c9aab8 | 627 | valid_handler, valid_data); |
58f6fbe0 JM |
628 | } |
629 | ||
630 | ||
97865538 JM |
631 | struct family_data { |
632 | const char *group; | |
633 | int id; | |
634 | }; | |
635 | ||
636 | ||
d3aaef80 DS |
637 | static int nl80211_set_iface_id(struct nl_msg *msg, struct i802_bss *bss) |
638 | { | |
639 | if (bss->wdev_id_set) | |
640 | NLA_PUT_U64(msg, NL80211_ATTR_WDEV, bss->wdev_id); | |
641 | else | |
642 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, bss->ifindex); | |
643 | return 0; | |
644 | ||
645 | nla_put_failure: | |
646 | return -1; | |
647 | } | |
648 | ||
649 | ||
97865538 JM |
650 | static int family_handler(struct nl_msg *msg, void *arg) |
651 | { | |
652 | struct family_data *res = arg; | |
653 | struct nlattr *tb[CTRL_ATTR_MAX + 1]; | |
654 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); | |
655 | struct nlattr *mcgrp; | |
656 | int i; | |
657 | ||
658 | nla_parse(tb, CTRL_ATTR_MAX, genlmsg_attrdata(gnlh, 0), | |
659 | genlmsg_attrlen(gnlh, 0), NULL); | |
660 | if (!tb[CTRL_ATTR_MCAST_GROUPS]) | |
661 | return NL_SKIP; | |
662 | ||
663 | nla_for_each_nested(mcgrp, tb[CTRL_ATTR_MCAST_GROUPS], i) { | |
664 | struct nlattr *tb2[CTRL_ATTR_MCAST_GRP_MAX + 1]; | |
665 | nla_parse(tb2, CTRL_ATTR_MCAST_GRP_MAX, nla_data(mcgrp), | |
666 | nla_len(mcgrp), NULL); | |
667 | if (!tb2[CTRL_ATTR_MCAST_GRP_NAME] || | |
668 | !tb2[CTRL_ATTR_MCAST_GRP_ID] || | |
669 | os_strncmp(nla_data(tb2[CTRL_ATTR_MCAST_GRP_NAME]), | |
670 | res->group, | |
671 | nla_len(tb2[CTRL_ATTR_MCAST_GRP_NAME])) != 0) | |
672 | continue; | |
673 | res->id = nla_get_u32(tb2[CTRL_ATTR_MCAST_GRP_ID]); | |
674 | break; | |
675 | }; | |
676 | ||
677 | return NL_SKIP; | |
678 | } | |
679 | ||
680 | ||
d6c9aab8 | 681 | static int nl_get_multicast_id(struct nl80211_global *global, |
97865538 JM |
682 | const char *family, const char *group) |
683 | { | |
684 | struct nl_msg *msg; | |
685 | int ret = -1; | |
686 | struct family_data res = { group, -ENOENT }; | |
687 | ||
688 | msg = nlmsg_alloc(); | |
689 | if (!msg) | |
690 | return -ENOMEM; | |
481234cf | 691 | genlmsg_put(msg, 0, 0, genl_ctrl_resolve(global->nl, "nlctrl"), |
97865538 JM |
692 | 0, 0, CTRL_CMD_GETFAMILY, 0); |
693 | NLA_PUT_STRING(msg, CTRL_ATTR_FAMILY_NAME, family); | |
694 | ||
d6c9aab8 | 695 | ret = send_and_recv_msgs_global(global, msg, family_handler, &res); |
97865538 JM |
696 | msg = NULL; |
697 | if (ret == 0) | |
698 | ret = res.id; | |
699 | ||
700 | nla_put_failure: | |
701 | nlmsg_free(msg); | |
702 | return ret; | |
703 | } | |
704 | ||
705 | ||
9fb04070 JM |
706 | static void * nl80211_cmd(struct wpa_driver_nl80211_data *drv, |
707 | struct nl_msg *msg, int flags, uint8_t cmd) | |
708 | { | |
335d42b1 | 709 | return genlmsg_put(msg, 0, 0, drv->global->nl80211_id, |
276e2d67 | 710 | 0, flags, cmd, 0); |
9fb04070 JM |
711 | } |
712 | ||
713 | ||
e32ad281 JB |
714 | struct wiphy_idx_data { |
715 | int wiphy_idx; | |
01517c8b | 716 | enum nl80211_iftype nlmode; |
597b94f5 | 717 | u8 *macaddr; |
e32ad281 JB |
718 | }; |
719 | ||
720 | ||
721 | static int netdev_info_handler(struct nl_msg *msg, void *arg) | |
722 | { | |
723 | struct nlattr *tb[NL80211_ATTR_MAX + 1]; | |
724 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); | |
725 | struct wiphy_idx_data *info = arg; | |
726 | ||
727 | nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), | |
728 | genlmsg_attrlen(gnlh, 0), NULL); | |
729 | ||
730 | if (tb[NL80211_ATTR_WIPHY]) | |
731 | info->wiphy_idx = nla_get_u32(tb[NL80211_ATTR_WIPHY]); | |
732 | ||
01517c8b JB |
733 | if (tb[NL80211_ATTR_IFTYPE]) |
734 | info->nlmode = nla_get_u32(tb[NL80211_ATTR_IFTYPE]); | |
735 | ||
597b94f5 AS |
736 | if (tb[NL80211_ATTR_MAC] && info->macaddr) |
737 | os_memcpy(info->macaddr, nla_data(tb[NL80211_ATTR_MAC]), | |
738 | ETH_ALEN); | |
739 | ||
e32ad281 JB |
740 | return NL_SKIP; |
741 | } | |
742 | ||
743 | ||
744 | static int nl80211_get_wiphy_index(struct i802_bss *bss) | |
745 | { | |
746 | struct nl_msg *msg; | |
747 | struct wiphy_idx_data data = { | |
748 | .wiphy_idx = -1, | |
597b94f5 | 749 | .macaddr = NULL, |
e32ad281 JB |
750 | }; |
751 | ||
752 | msg = nlmsg_alloc(); | |
753 | if (!msg) | |
8e12685c | 754 | return NL80211_IFTYPE_UNSPECIFIED; |
e32ad281 JB |
755 | |
756 | nl80211_cmd(bss->drv, msg, 0, NL80211_CMD_GET_INTERFACE); | |
757 | ||
27ce1d64 AS |
758 | if (nl80211_set_iface_id(msg, bss) < 0) |
759 | goto nla_put_failure; | |
e32ad281 JB |
760 | |
761 | if (send_and_recv_msgs(bss->drv, msg, netdev_info_handler, &data) == 0) | |
762 | return data.wiphy_idx; | |
763 | msg = NULL; | |
764 | nla_put_failure: | |
765 | nlmsg_free(msg); | |
766 | return -1; | |
767 | } | |
768 | ||
769 | ||
01517c8b JB |
770 | static enum nl80211_iftype nl80211_get_ifmode(struct i802_bss *bss) |
771 | { | |
772 | struct nl_msg *msg; | |
773 | struct wiphy_idx_data data = { | |
597b94f5 AS |
774 | .nlmode = NL80211_IFTYPE_UNSPECIFIED, |
775 | .macaddr = NULL, | |
01517c8b JB |
776 | }; |
777 | ||
778 | msg = nlmsg_alloc(); | |
779 | if (!msg) | |
780 | return -1; | |
781 | ||
782 | nl80211_cmd(bss->drv, msg, 0, NL80211_CMD_GET_INTERFACE); | |
783 | ||
f632e483 AS |
784 | if (nl80211_set_iface_id(msg, bss) < 0) |
785 | goto nla_put_failure; | |
01517c8b JB |
786 | |
787 | if (send_and_recv_msgs(bss->drv, msg, netdev_info_handler, &data) == 0) | |
788 | return data.nlmode; | |
789 | msg = NULL; | |
790 | nla_put_failure: | |
791 | nlmsg_free(msg); | |
792 | return NL80211_IFTYPE_UNSPECIFIED; | |
793 | } | |
01517c8b JB |
794 | |
795 | ||
597b94f5 AS |
796 | #ifndef HOSTAPD |
797 | static int nl80211_get_macaddr(struct i802_bss *bss) | |
798 | { | |
799 | struct nl_msg *msg; | |
800 | struct wiphy_idx_data data = { | |
801 | .macaddr = bss->addr, | |
802 | }; | |
803 | ||
804 | msg = nlmsg_alloc(); | |
805 | if (!msg) | |
806 | return NL80211_IFTYPE_UNSPECIFIED; | |
807 | ||
808 | nl80211_cmd(bss->drv, msg, 0, NL80211_CMD_GET_INTERFACE); | |
809 | if (nl80211_set_iface_id(msg, bss) < 0) | |
810 | goto nla_put_failure; | |
811 | ||
812 | return send_and_recv_msgs(bss->drv, msg, netdev_info_handler, &data); | |
813 | ||
814 | nla_put_failure: | |
815 | nlmsg_free(msg); | |
816 | return NL80211_IFTYPE_UNSPECIFIED; | |
817 | } | |
818 | #endif /* HOSTAPD */ | |
819 | ||
820 | ||
e32ad281 JB |
821 | static int nl80211_register_beacons(struct wpa_driver_nl80211_data *drv, |
822 | struct nl80211_wiphy_data *w) | |
823 | { | |
824 | struct nl_msg *msg; | |
825 | int ret = -1; | |
826 | ||
827 | msg = nlmsg_alloc(); | |
828 | if (!msg) | |
829 | return -1; | |
830 | ||
831 | nl80211_cmd(drv, msg, 0, NL80211_CMD_REGISTER_BEACONS); | |
832 | ||
833 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, w->wiphy_idx); | |
834 | ||
481234cf | 835 | ret = send_and_recv(drv->global, w->nl_beacons, msg, NULL, NULL); |
e32ad281 JB |
836 | msg = NULL; |
837 | if (ret) { | |
838 | wpa_printf(MSG_DEBUG, "nl80211: Register beacons command " | |
839 | "failed: ret=%d (%s)", | |
840 | ret, strerror(-ret)); | |
841 | goto nla_put_failure; | |
842 | } | |
843 | ret = 0; | |
844 | nla_put_failure: | |
845 | nlmsg_free(msg); | |
846 | return ret; | |
847 | } | |
848 | ||
849 | ||
850 | static void nl80211_recv_beacons(int sock, void *eloop_ctx, void *handle) | |
851 | { | |
852 | struct nl80211_wiphy_data *w = eloop_ctx; | |
34068ac3 | 853 | int res; |
e32ad281 | 854 | |
ee9fc67a | 855 | wpa_printf(MSG_EXCESSIVE, "nl80211: Beacon event message available"); |
e32ad281 | 856 | |
34068ac3 JM |
857 | res = nl_recvmsgs(handle, w->nl_cb); |
858 | if (res) { | |
859 | wpa_printf(MSG_INFO, "nl80211: %s->nl_recvmsgs failed: %d", | |
860 | __func__, res); | |
861 | } | |
e32ad281 JB |
862 | } |
863 | ||
864 | ||
865 | static int process_beacon_event(struct nl_msg *msg, void *arg) | |
866 | { | |
867 | struct nl80211_wiphy_data *w = arg; | |
868 | struct wpa_driver_nl80211_data *drv; | |
869 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); | |
870 | struct nlattr *tb[NL80211_ATTR_MAX + 1]; | |
871 | union wpa_event_data event; | |
872 | ||
873 | nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), | |
874 | genlmsg_attrlen(gnlh, 0), NULL); | |
875 | ||
876 | if (gnlh->cmd != NL80211_CMD_FRAME) { | |
877 | wpa_printf(MSG_DEBUG, "nl80211: Unexpected beacon event? (%d)", | |
878 | gnlh->cmd); | |
879 | return NL_SKIP; | |
880 | } | |
881 | ||
882 | if (!tb[NL80211_ATTR_FRAME]) | |
883 | return NL_SKIP; | |
884 | ||
885 | dl_list_for_each(drv, &w->drvs, struct wpa_driver_nl80211_data, | |
886 | wiphy_list) { | |
887 | os_memset(&event, 0, sizeof(event)); | |
888 | event.rx_mgmt.frame = nla_data(tb[NL80211_ATTR_FRAME]); | |
889 | event.rx_mgmt.frame_len = nla_len(tb[NL80211_ATTR_FRAME]); | |
890 | wpa_supplicant_event(drv->ctx, EVENT_RX_MGMT, &event); | |
891 | } | |
892 | ||
893 | return NL_SKIP; | |
894 | } | |
895 | ||
896 | ||
897 | static struct nl80211_wiphy_data * | |
898 | nl80211_get_wiphy_data_ap(struct i802_bss *bss) | |
899 | { | |
900 | static DEFINE_DL_LIST(nl80211_wiphys); | |
901 | struct nl80211_wiphy_data *w; | |
902 | int wiphy_idx, found = 0; | |
903 | struct i802_bss *tmp_bss; | |
904 | ||
905 | if (bss->wiphy_data != NULL) | |
906 | return bss->wiphy_data; | |
907 | ||
908 | wiphy_idx = nl80211_get_wiphy_index(bss); | |
909 | ||
910 | dl_list_for_each(w, &nl80211_wiphys, struct nl80211_wiphy_data, list) { | |
911 | if (w->wiphy_idx == wiphy_idx) | |
912 | goto add; | |
913 | } | |
914 | ||
915 | /* alloc new one */ | |
916 | w = os_zalloc(sizeof(*w)); | |
917 | if (w == NULL) | |
918 | return NULL; | |
919 | w->wiphy_idx = wiphy_idx; | |
920 | dl_list_init(&w->bsss); | |
921 | dl_list_init(&w->drvs); | |
922 | ||
923 | w->nl_cb = nl_cb_alloc(NL_CB_DEFAULT); | |
924 | if (!w->nl_cb) { | |
925 | os_free(w); | |
926 | return NULL; | |
927 | } | |
928 | nl_cb_set(w->nl_cb, NL_CB_SEQ_CHECK, NL_CB_CUSTOM, no_seq_check, NULL); | |
929 | nl_cb_set(w->nl_cb, NL_CB_VALID, NL_CB_CUSTOM, process_beacon_event, | |
930 | w); | |
931 | ||
481234cf JM |
932 | w->nl_beacons = nl_create_handle(bss->drv->global->nl_cb, |
933 | "wiphy beacons"); | |
934 | if (w->nl_beacons == NULL) { | |
e32ad281 JB |
935 | os_free(w); |
936 | return NULL; | |
937 | } | |
938 | ||
939 | if (nl80211_register_beacons(bss->drv, w)) { | |
940 | nl_destroy_handles(&w->nl_beacons); | |
941 | os_free(w); | |
942 | return NULL; | |
943 | } | |
944 | ||
5f65e9f7 | 945 | nl80211_register_eloop_read(&w->nl_beacons, nl80211_recv_beacons, w); |
e32ad281 JB |
946 | |
947 | dl_list_add(&nl80211_wiphys, &w->list); | |
948 | ||
949 | add: | |
950 | /* drv entry for this bss already there? */ | |
951 | dl_list_for_each(tmp_bss, &w->bsss, struct i802_bss, wiphy_list) { | |
952 | if (tmp_bss->drv == bss->drv) { | |
953 | found = 1; | |
954 | break; | |
955 | } | |
956 | } | |
957 | /* if not add it */ | |
958 | if (!found) | |
959 | dl_list_add(&w->drvs, &bss->drv->wiphy_list); | |
960 | ||
961 | dl_list_add(&w->bsss, &bss->wiphy_list); | |
962 | bss->wiphy_data = w; | |
963 | return w; | |
964 | } | |
965 | ||
966 | ||
967 | static void nl80211_put_wiphy_data_ap(struct i802_bss *bss) | |
968 | { | |
969 | struct nl80211_wiphy_data *w = bss->wiphy_data; | |
970 | struct i802_bss *tmp_bss; | |
971 | int found = 0; | |
972 | ||
973 | if (w == NULL) | |
974 | return; | |
975 | bss->wiphy_data = NULL; | |
976 | dl_list_del(&bss->wiphy_list); | |
977 | ||
978 | /* still any for this drv present? */ | |
979 | dl_list_for_each(tmp_bss, &w->bsss, struct i802_bss, wiphy_list) { | |
980 | if (tmp_bss->drv == bss->drv) { | |
981 | found = 1; | |
982 | break; | |
983 | } | |
984 | } | |
985 | /* if not remove it */ | |
986 | if (!found) | |
987 | dl_list_del(&bss->drv->wiphy_list); | |
988 | ||
989 | if (!dl_list_empty(&w->bsss)) | |
990 | return; | |
991 | ||
5f65e9f7 | 992 | nl80211_destroy_eloop_handle(&w->nl_beacons); |
e32ad281 JB |
993 | |
994 | nl_cb_put(w->nl_cb); | |
e32ad281 JB |
995 | dl_list_del(&w->list); |
996 | os_free(w); | |
997 | } | |
998 | ||
999 | ||
3f5285e8 JM |
1000 | static int wpa_driver_nl80211_get_bssid(void *priv, u8 *bssid) |
1001 | { | |
a2e40bb6 FF |
1002 | struct i802_bss *bss = priv; |
1003 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
c2a04078 JM |
1004 | if (!drv->associated) |
1005 | return -1; | |
1006 | os_memcpy(bssid, drv->bssid, ETH_ALEN); | |
1007 | return 0; | |
3f5285e8 JM |
1008 | } |
1009 | ||
1010 | ||
3f5285e8 JM |
1011 | static int wpa_driver_nl80211_get_ssid(void *priv, u8 *ssid) |
1012 | { | |
a2e40bb6 FF |
1013 | struct i802_bss *bss = priv; |
1014 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
fd05d64e JM |
1015 | if (!drv->associated) |
1016 | return -1; | |
1017 | os_memcpy(ssid, drv->ssid, drv->ssid_len); | |
1018 | return drv->ssid_len; | |
3f5285e8 JM |
1019 | } |
1020 | ||
1021 | ||
7524cfb1 | 1022 | static void wpa_driver_nl80211_event_link(struct wpa_driver_nl80211_data *drv, |
08063178 | 1023 | char *buf, size_t len, int del) |
3f5285e8 JM |
1024 | { |
1025 | union wpa_event_data event; | |
1026 | ||
1027 | os_memset(&event, 0, sizeof(event)); | |
1028 | if (len > sizeof(event.interface_status.ifname)) | |
1029 | len = sizeof(event.interface_status.ifname) - 1; | |
1030 | os_memcpy(event.interface_status.ifname, buf, len); | |
1031 | event.interface_status.ievent = del ? EVENT_INTERFACE_REMOVED : | |
1032 | EVENT_INTERFACE_ADDED; | |
1033 | ||
1034 | wpa_printf(MSG_DEBUG, "RTM_%sLINK, IFLA_IFNAME: Interface '%s' %s", | |
1035 | del ? "DEL" : "NEW", | |
1036 | event.interface_status.ifname, | |
1037 | del ? "removed" : "added"); | |
1038 | ||
a2e40bb6 | 1039 | if (os_strcmp(drv->first_bss.ifname, event.interface_status.ifname) == 0) { |
d1f4942b JM |
1040 | if (del) { |
1041 | if (drv->if_removed) { | |
1042 | wpa_printf(MSG_DEBUG, "nl80211: if_removed " | |
1043 | "already set - ignore event"); | |
1044 | return; | |
1045 | } | |
7524cfb1 | 1046 | drv->if_removed = 1; |
d1f4942b JM |
1047 | } else { |
1048 | if (if_nametoindex(drv->first_bss.ifname) == 0) { | |
1049 | wpa_printf(MSG_DEBUG, "nl80211: Interface %s " | |
1050 | "does not exist - ignore " | |
1051 | "RTM_NEWLINK", | |
1052 | drv->first_bss.ifname); | |
1053 | return; | |
1054 | } | |
1055 | if (!drv->if_removed) { | |
1056 | wpa_printf(MSG_DEBUG, "nl80211: if_removed " | |
1057 | "already cleared - ignore event"); | |
1058 | return; | |
1059 | } | |
7524cfb1 | 1060 | drv->if_removed = 0; |
d1f4942b | 1061 | } |
7524cfb1 JM |
1062 | } |
1063 | ||
08063178 | 1064 | wpa_supplicant_event(drv->ctx, EVENT_INTERFACE_STATUS, &event); |
3f5285e8 JM |
1065 | } |
1066 | ||
1067 | ||
7524cfb1 | 1068 | static int wpa_driver_nl80211_own_ifname(struct wpa_driver_nl80211_data *drv, |
62d680c3 | 1069 | u8 *buf, size_t len) |
7524cfb1 | 1070 | { |
62d680c3 | 1071 | int attrlen, rta_len; |
7524cfb1 JM |
1072 | struct rtattr *attr; |
1073 | ||
62d680c3 JM |
1074 | attrlen = len; |
1075 | attr = (struct rtattr *) buf; | |
7524cfb1 JM |
1076 | |
1077 | rta_len = RTA_ALIGN(sizeof(struct rtattr)); | |
1078 | while (RTA_OK(attr, attrlen)) { | |
1079 | if (attr->rta_type == IFLA_IFNAME) { | |
a2e40bb6 | 1080 | if (os_strcmp(((char *) attr) + rta_len, drv->first_bss.ifname) |
7524cfb1 JM |
1081 | == 0) |
1082 | return 1; | |
1083 | else | |
1084 | break; | |
1085 | } | |
1086 | attr = RTA_NEXT(attr, attrlen); | |
1087 | } | |
1088 | ||
1089 | return 0; | |
1090 | } | |
1091 | ||
1092 | ||
1093 | static int wpa_driver_nl80211_own_ifindex(struct wpa_driver_nl80211_data *drv, | |
62d680c3 | 1094 | int ifindex, u8 *buf, size_t len) |
7524cfb1 JM |
1095 | { |
1096 | if (drv->ifindex == ifindex) | |
1097 | return 1; | |
1098 | ||
62d680c3 | 1099 | if (drv->if_removed && wpa_driver_nl80211_own_ifname(drv, buf, len)) { |
7524cfb1 JM |
1100 | wpa_printf(MSG_DEBUG, "nl80211: Update ifindex for a removed " |
1101 | "interface"); | |
1102 | wpa_driver_nl80211_finish_drv_init(drv); | |
1103 | return 1; | |
1104 | } | |
1105 | ||
1106 | return 0; | |
1107 | } | |
1108 | ||
1109 | ||
36d84860 BG |
1110 | static struct wpa_driver_nl80211_data * |
1111 | nl80211_find_drv(struct nl80211_global *global, int idx, u8 *buf, size_t len) | |
1112 | { | |
1113 | struct wpa_driver_nl80211_data *drv; | |
1114 | dl_list_for_each(drv, &global->interfaces, | |
1115 | struct wpa_driver_nl80211_data, list) { | |
1116 | if (wpa_driver_nl80211_own_ifindex(drv, idx, buf, len) || | |
1117 | have_ifidx(drv, idx)) | |
1118 | return drv; | |
1119 | } | |
1120 | return NULL; | |
1121 | } | |
1122 | ||
1123 | ||
62d680c3 JM |
1124 | static void wpa_driver_nl80211_event_rtm_newlink(void *ctx, |
1125 | struct ifinfomsg *ifi, | |
1126 | u8 *buf, size_t len) | |
3f5285e8 | 1127 | { |
36d84860 BG |
1128 | struct nl80211_global *global = ctx; |
1129 | struct wpa_driver_nl80211_data *drv; | |
62d680c3 JM |
1130 | int attrlen, rta_len; |
1131 | struct rtattr *attr; | |
97cfcf64 | 1132 | u32 brid = 0; |
aef85ba2 | 1133 | char namebuf[IFNAMSIZ]; |
3f5285e8 | 1134 | |
36d84860 BG |
1135 | drv = nl80211_find_drv(global, ifi->ifi_index, buf, len); |
1136 | if (!drv) { | |
97cfcf64 B |
1137 | wpa_printf(MSG_DEBUG, "nl80211: Ignore event for foreign " |
1138 | "ifindex %d", ifi->ifi_index); | |
3f5285e8 JM |
1139 | return; |
1140 | } | |
1141 | ||
1142 | wpa_printf(MSG_DEBUG, "RTM_NEWLINK: operstate=%d ifi_flags=0x%x " | |
1143 | "(%s%s%s%s)", | |
1144 | drv->operstate, ifi->ifi_flags, | |
1145 | (ifi->ifi_flags & IFF_UP) ? "[UP]" : "", | |
1146 | (ifi->ifi_flags & IFF_RUNNING) ? "[RUNNING]" : "", | |
1147 | (ifi->ifi_flags & IFF_LOWER_UP) ? "[LOWER_UP]" : "", | |
1148 | (ifi->ifi_flags & IFF_DORMANT) ? "[DORMANT]" : ""); | |
a63063b4 JM |
1149 | |
1150 | if (!drv->if_disabled && !(ifi->ifi_flags & IFF_UP)) { | |
59d24925 JM |
1151 | if (if_indextoname(ifi->ifi_index, namebuf) && |
1152 | linux_iface_up(drv->global->ioctl_sock, | |
1153 | drv->first_bss.ifname) > 0) { | |
1154 | wpa_printf(MSG_DEBUG, "nl80211: Ignore interface down " | |
1155 | "event since interface %s is up", namebuf); | |
1156 | return; | |
1157 | } | |
a63063b4 | 1158 | wpa_printf(MSG_DEBUG, "nl80211: Interface down"); |
7d9c3698 JM |
1159 | if (drv->ignore_if_down_event) { |
1160 | wpa_printf(MSG_DEBUG, "nl80211: Ignore interface down " | |
1161 | "event generated by mode change"); | |
1162 | drv->ignore_if_down_event = 0; | |
1163 | } else { | |
1164 | drv->if_disabled = 1; | |
1165 | wpa_supplicant_event(drv->ctx, | |
1166 | EVENT_INTERFACE_DISABLED, NULL); | |
1167 | } | |
a63063b4 JM |
1168 | } |
1169 | ||
1170 | if (drv->if_disabled && (ifi->ifi_flags & IFF_UP)) { | |
aef85ba2 JM |
1171 | if (if_indextoname(ifi->ifi_index, namebuf) && |
1172 | linux_iface_up(drv->global->ioctl_sock, | |
1173 | drv->first_bss.ifname) == 0) { | |
1174 | wpa_printf(MSG_DEBUG, "nl80211: Ignore interface up " | |
1175 | "event since interface %s is down", | |
1176 | namebuf); | |
d1f4942b JM |
1177 | } else if (if_nametoindex(drv->first_bss.ifname) == 0) { |
1178 | wpa_printf(MSG_DEBUG, "nl80211: Ignore interface up " | |
1179 | "event since interface %s does not exist", | |
1180 | drv->first_bss.ifname); | |
1181 | } else if (drv->if_removed) { | |
1182 | wpa_printf(MSG_DEBUG, "nl80211: Ignore interface up " | |
1183 | "event since interface %s is marked " | |
1184 | "removed", drv->first_bss.ifname); | |
aef85ba2 JM |
1185 | } else { |
1186 | wpa_printf(MSG_DEBUG, "nl80211: Interface up"); | |
1187 | drv->if_disabled = 0; | |
1188 | wpa_supplicant_event(drv->ctx, EVENT_INTERFACE_ENABLED, | |
1189 | NULL); | |
1190 | } | |
a63063b4 JM |
1191 | } |
1192 | ||
3f5285e8 JM |
1193 | /* |
1194 | * Some drivers send the association event before the operup event--in | |
1195 | * this case, lifting operstate in wpa_driver_nl80211_set_operstate() | |
1196 | * fails. This will hit us when wpa_supplicant does not need to do | |
1197 | * IEEE 802.1X authentication | |
1198 | */ | |
1199 | if (drv->operstate == 1 && | |
1200 | (ifi->ifi_flags & (IFF_LOWER_UP | IFF_DORMANT)) == IFF_LOWER_UP && | |
1201 | !(ifi->ifi_flags & IFF_RUNNING)) | |
36d84860 | 1202 | netlink_send_oper_ifla(drv->global->netlink, drv->ifindex, |
e2d02c29 | 1203 | -1, IF_OPER_UP); |
3f5285e8 | 1204 | |
62d680c3 JM |
1205 | attrlen = len; |
1206 | attr = (struct rtattr *) buf; | |
3f5285e8 JM |
1207 | rta_len = RTA_ALIGN(sizeof(struct rtattr)); |
1208 | while (RTA_OK(attr, attrlen)) { | |
d8816397 | 1209 | if (attr->rta_type == IFLA_IFNAME) { |
7524cfb1 | 1210 | wpa_driver_nl80211_event_link( |
08063178 | 1211 | drv, |
7524cfb1 JM |
1212 | ((char *) attr) + rta_len, |
1213 | attr->rta_len - rta_len, 0); | |
97cfcf64 B |
1214 | } else if (attr->rta_type == IFLA_MASTER) |
1215 | brid = nla_get_u32((struct nlattr *) attr); | |
3f5285e8 JM |
1216 | attr = RTA_NEXT(attr, attrlen); |
1217 | } | |
97cfcf64 B |
1218 | |
1219 | if (ifi->ifi_family == AF_BRIDGE && brid) { | |
1220 | /* device has been added to bridge */ | |
97cfcf64 B |
1221 | if_indextoname(brid, namebuf); |
1222 | wpa_printf(MSG_DEBUG, "nl80211: Add ifindex %u for bridge %s", | |
1223 | brid, namebuf); | |
1224 | add_ifidx(drv, brid); | |
1225 | } | |
3f5285e8 JM |
1226 | } |
1227 | ||
1228 | ||
62d680c3 JM |
1229 | static void wpa_driver_nl80211_event_rtm_dellink(void *ctx, |
1230 | struct ifinfomsg *ifi, | |
1231 | u8 *buf, size_t len) | |
3f5285e8 | 1232 | { |
36d84860 BG |
1233 | struct nl80211_global *global = ctx; |
1234 | struct wpa_driver_nl80211_data *drv; | |
62d680c3 JM |
1235 | int attrlen, rta_len; |
1236 | struct rtattr *attr; | |
97cfcf64 | 1237 | u32 brid = 0; |
3f5285e8 | 1238 | |
36d84860 BG |
1239 | drv = nl80211_find_drv(global, ifi->ifi_index, buf, len); |
1240 | if (!drv) { | |
1241 | wpa_printf(MSG_DEBUG, "nl80211: Ignore dellink event for " | |
1242 | "foreign ifindex %d", ifi->ifi_index); | |
1243 | return; | |
1244 | } | |
1245 | ||
62d680c3 JM |
1246 | attrlen = len; |
1247 | attr = (struct rtattr *) buf; | |
3f5285e8 JM |
1248 | |
1249 | rta_len = RTA_ALIGN(sizeof(struct rtattr)); | |
1250 | while (RTA_OK(attr, attrlen)) { | |
1251 | if (attr->rta_type == IFLA_IFNAME) { | |
7524cfb1 | 1252 | wpa_driver_nl80211_event_link( |
08063178 | 1253 | drv, |
7524cfb1 JM |
1254 | ((char *) attr) + rta_len, |
1255 | attr->rta_len - rta_len, 1); | |
97cfcf64 B |
1256 | } else if (attr->rta_type == IFLA_MASTER) |
1257 | brid = nla_get_u32((struct nlattr *) attr); | |
3f5285e8 JM |
1258 | attr = RTA_NEXT(attr, attrlen); |
1259 | } | |
97cfcf64 B |
1260 | |
1261 | if (ifi->ifi_family == AF_BRIDGE && brid) { | |
1262 | /* device has been removed from bridge */ | |
1263 | char namebuf[IFNAMSIZ]; | |
1264 | if_indextoname(brid, namebuf); | |
1265 | wpa_printf(MSG_DEBUG, "nl80211: Remove ifindex %u for bridge " | |
1266 | "%s", brid, namebuf); | |
1267 | del_ifidx(drv, brid); | |
1268 | } | |
3f5285e8 JM |
1269 | } |
1270 | ||
1271 | ||
c2a04078 JM |
1272 | static void mlme_event_auth(struct wpa_driver_nl80211_data *drv, |
1273 | const u8 *frame, size_t len) | |
1274 | { | |
1275 | const struct ieee80211_mgmt *mgmt; | |
1276 | union wpa_event_data event; | |
1277 | ||
7d81932d | 1278 | wpa_printf(MSG_DEBUG, "nl80211: Authenticate event"); |
c2a04078 JM |
1279 | mgmt = (const struct ieee80211_mgmt *) frame; |
1280 | if (len < 24 + sizeof(mgmt->u.auth)) { | |
1281 | wpa_printf(MSG_DEBUG, "nl80211: Too short association event " | |
1282 | "frame"); | |
1283 | return; | |
1284 | } | |
1285 | ||
e6b8efeb | 1286 | os_memcpy(drv->auth_bssid, mgmt->sa, ETH_ALEN); |
add9b7a4 | 1287 | os_memset(drv->auth_attempt_bssid, 0, ETH_ALEN); |
c2a04078 JM |
1288 | os_memset(&event, 0, sizeof(event)); |
1289 | os_memcpy(event.auth.peer, mgmt->sa, ETH_ALEN); | |
1290 | event.auth.auth_type = le_to_host16(mgmt->u.auth.auth_alg); | |
569fed90 JM |
1291 | event.auth.auth_transaction = |
1292 | le_to_host16(mgmt->u.auth.auth_transaction); | |
c2a04078 JM |
1293 | event.auth.status_code = le_to_host16(mgmt->u.auth.status_code); |
1294 | if (len > 24 + sizeof(mgmt->u.auth)) { | |
1295 | event.auth.ies = mgmt->u.auth.variable; | |
1296 | event.auth.ies_len = len - 24 - sizeof(mgmt->u.auth); | |
1297 | } | |
1298 | ||
1299 | wpa_supplicant_event(drv->ctx, EVENT_AUTH, &event); | |
1300 | } | |
1301 | ||
1302 | ||
f5a8d422 JM |
1303 | static unsigned int nl80211_get_assoc_freq(struct wpa_driver_nl80211_data *drv) |
1304 | { | |
1305 | struct nl_msg *msg; | |
1306 | int ret; | |
1307 | struct nl80211_bss_info_arg arg; | |
1308 | ||
1309 | os_memset(&arg, 0, sizeof(arg)); | |
1310 | msg = nlmsg_alloc(); | |
1311 | if (!msg) | |
1312 | goto nla_put_failure; | |
1313 | ||
9fb04070 | 1314 | nl80211_cmd(drv, msg, NLM_F_DUMP, NL80211_CMD_GET_SCAN); |
f5a8d422 JM |
1315 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, drv->ifindex); |
1316 | ||
1317 | arg.drv = drv; | |
1318 | ret = send_and_recv_msgs(drv, msg, bss_info_handler, &arg); | |
1319 | msg = NULL; | |
1320 | if (ret == 0) { | |
1321 | wpa_printf(MSG_DEBUG, "nl80211: Operating frequency for the " | |
1322 | "associated BSS from scan results: %u MHz", | |
1323 | arg.assoc_freq); | |
30158a0d SD |
1324 | if (arg.assoc_freq) |
1325 | drv->assoc_freq = arg.assoc_freq; | |
1326 | return drv->assoc_freq; | |
f5a8d422 JM |
1327 | } |
1328 | wpa_printf(MSG_DEBUG, "nl80211: Scan result fetch failed: ret=%d " | |
1329 | "(%s)", ret, strerror(-ret)); | |
1330 | nla_put_failure: | |
1331 | nlmsg_free(msg); | |
1332 | return drv->assoc_freq; | |
1333 | } | |
1334 | ||
1335 | ||
c2a04078 JM |
1336 | static void mlme_event_assoc(struct wpa_driver_nl80211_data *drv, |
1337 | const u8 *frame, size_t len) | |
1338 | { | |
1339 | const struct ieee80211_mgmt *mgmt; | |
1340 | union wpa_event_data event; | |
1341 | u16 status; | |
1342 | ||
7d81932d | 1343 | wpa_printf(MSG_DEBUG, "nl80211: Associate event"); |
c2a04078 JM |
1344 | mgmt = (const struct ieee80211_mgmt *) frame; |
1345 | if (len < 24 + sizeof(mgmt->u.assoc_resp)) { | |
1346 | wpa_printf(MSG_DEBUG, "nl80211: Too short association event " | |
1347 | "frame"); | |
1348 | return; | |
1349 | } | |
1350 | ||
1351 | status = le_to_host16(mgmt->u.assoc_resp.status_code); | |
1352 | if (status != WLAN_STATUS_SUCCESS) { | |
efa46078 | 1353 | os_memset(&event, 0, sizeof(event)); |
59ddf221 | 1354 | event.assoc_reject.bssid = mgmt->bssid; |
efa46078 JM |
1355 | if (len > 24 + sizeof(mgmt->u.assoc_resp)) { |
1356 | event.assoc_reject.resp_ies = | |
1357 | (u8 *) mgmt->u.assoc_resp.variable; | |
1358 | event.assoc_reject.resp_ies_len = | |
1359 | len - 24 - sizeof(mgmt->u.assoc_resp); | |
1360 | } | |
1361 | event.assoc_reject.status_code = status; | |
1362 | ||
1363 | wpa_supplicant_event(drv->ctx, EVENT_ASSOC_REJECT, &event); | |
c2a04078 JM |
1364 | return; |
1365 | } | |
1366 | ||
1367 | drv->associated = 1; | |
1368 | os_memcpy(drv->bssid, mgmt->sa, ETH_ALEN); | |
add9b7a4 | 1369 | os_memcpy(drv->prev_bssid, mgmt->sa, ETH_ALEN); |
c2a04078 JM |
1370 | |
1371 | os_memset(&event, 0, sizeof(event)); | |
1372 | if (len > 24 + sizeof(mgmt->u.assoc_resp)) { | |
1373 | event.assoc_info.resp_ies = (u8 *) mgmt->u.assoc_resp.variable; | |
1374 | event.assoc_info.resp_ies_len = | |
efa46078 | 1375 | len - 24 - sizeof(mgmt->u.assoc_resp); |
c2a04078 JM |
1376 | } |
1377 | ||
4832ecd7 JM |
1378 | event.assoc_info.freq = drv->assoc_freq; |
1379 | ||
c2a04078 JM |
1380 | wpa_supplicant_event(drv->ctx, EVENT_ASSOC, &event); |
1381 | } | |
1382 | ||
c1bb3e0a | 1383 | |
da72a1c1 ZY |
1384 | static void mlme_event_connect(struct wpa_driver_nl80211_data *drv, |
1385 | enum nl80211_commands cmd, struct nlattr *status, | |
1386 | struct nlattr *addr, struct nlattr *req_ie, | |
1387 | struct nlattr *resp_ie) | |
1388 | { | |
1389 | union wpa_event_data event; | |
1390 | ||
7da2c527 JM |
1391 | if (drv->capa.flags & WPA_DRIVER_FLAGS_SME) { |
1392 | /* | |
1393 | * Avoid reporting two association events that would confuse | |
1394 | * the core code. | |
1395 | */ | |
1396 | wpa_printf(MSG_DEBUG, "nl80211: Ignore connect event (cmd=%d) " | |
1397 | "when using userspace SME", cmd); | |
1398 | return; | |
1399 | } | |
1400 | ||
7d81932d JM |
1401 | if (cmd == NL80211_CMD_CONNECT) |
1402 | wpa_printf(MSG_DEBUG, "nl80211: Connect event"); | |
1403 | else if (cmd == NL80211_CMD_ROAM) | |
1404 | wpa_printf(MSG_DEBUG, "nl80211: Roam event"); | |
1405 | ||
da72a1c1 ZY |
1406 | os_memset(&event, 0, sizeof(event)); |
1407 | if (cmd == NL80211_CMD_CONNECT && | |
1408 | nla_get_u16(status) != WLAN_STATUS_SUCCESS) { | |
df89c1c8 JM |
1409 | if (addr) |
1410 | event.assoc_reject.bssid = nla_data(addr); | |
da72a1c1 ZY |
1411 | if (resp_ie) { |
1412 | event.assoc_reject.resp_ies = nla_data(resp_ie); | |
1413 | event.assoc_reject.resp_ies_len = nla_len(resp_ie); | |
1414 | } | |
1415 | event.assoc_reject.status_code = nla_get_u16(status); | |
1416 | wpa_supplicant_event(drv->ctx, EVENT_ASSOC_REJECT, &event); | |
1417 | return; | |
1418 | } | |
1419 | ||
1420 | drv->associated = 1; | |
add9b7a4 | 1421 | if (addr) { |
da72a1c1 | 1422 | os_memcpy(drv->bssid, nla_data(addr), ETH_ALEN); |
add9b7a4 JM |
1423 | os_memcpy(drv->prev_bssid, drv->bssid, ETH_ALEN); |
1424 | } | |
da72a1c1 ZY |
1425 | |
1426 | if (req_ie) { | |
1427 | event.assoc_info.req_ies = nla_data(req_ie); | |
1428 | event.assoc_info.req_ies_len = nla_len(req_ie); | |
1429 | } | |
1430 | if (resp_ie) { | |
1431 | event.assoc_info.resp_ies = nla_data(resp_ie); | |
1432 | event.assoc_info.resp_ies_len = nla_len(resp_ie); | |
1433 | } | |
1434 | ||
f5a8d422 JM |
1435 | event.assoc_info.freq = nl80211_get_assoc_freq(drv); |
1436 | ||
da72a1c1 ZY |
1437 | wpa_supplicant_event(drv->ctx, EVENT_ASSOC, &event); |
1438 | } | |
c2a04078 | 1439 | |
c1bb3e0a | 1440 | |
20f5a4c2 | 1441 | static void mlme_event_disconnect(struct wpa_driver_nl80211_data *drv, |
3d9975d5 JM |
1442 | struct nlattr *reason, struct nlattr *addr, |
1443 | struct nlattr *by_ap) | |
20f5a4c2 JM |
1444 | { |
1445 | union wpa_event_data data; | |
a8c5b43a | 1446 | unsigned int locally_generated = by_ap == NULL; |
20f5a4c2 JM |
1447 | |
1448 | if (drv->capa.flags & WPA_DRIVER_FLAGS_SME) { | |
1449 | /* | |
1450 | * Avoid reporting two disassociation events that could | |
1451 | * confuse the core code. | |
1452 | */ | |
1453 | wpa_printf(MSG_DEBUG, "nl80211: Ignore disconnect " | |
1454 | "event when using userspace SME"); | |
1455 | return; | |
1456 | } | |
1457 | ||
a8c5b43a CW |
1458 | if (drv->ignore_next_local_disconnect) { |
1459 | drv->ignore_next_local_disconnect = 0; | |
1460 | if (locally_generated) { | |
1461 | wpa_printf(MSG_DEBUG, "nl80211: Ignore disconnect " | |
1462 | "event triggered during reassociation"); | |
1463 | return; | |
1464 | } | |
1465 | wpa_printf(MSG_WARNING, "nl80211: Was expecting local " | |
1466 | "disconnect but got another disconnect " | |
1467 | "event first"); | |
1468 | } | |
1469 | ||
7d81932d | 1470 | wpa_printf(MSG_DEBUG, "nl80211: Disconnect event"); |
add9b7a4 | 1471 | nl80211_mark_disconnected(drv); |
20f5a4c2 JM |
1472 | os_memset(&data, 0, sizeof(data)); |
1473 | if (reason) | |
2e9f078c JM |
1474 | data.deauth_info.reason_code = nla_get_u16(reason); |
1475 | data.deauth_info.locally_generated = by_ap == NULL; | |
1476 | wpa_supplicant_event(drv->ctx, EVENT_DEAUTH, &data); | |
20f5a4c2 JM |
1477 | } |
1478 | ||
1479 | ||
1b487b8b TP |
1480 | static void mlme_event_ch_switch(struct wpa_driver_nl80211_data *drv, |
1481 | struct nlattr *freq, struct nlattr *type) | |
1482 | { | |
1483 | union wpa_event_data data; | |
1484 | int ht_enabled = 1; | |
1485 | int chan_offset = 0; | |
1486 | ||
1487 | wpa_printf(MSG_DEBUG, "nl80211: Channel switch event"); | |
1488 | ||
1489 | if (!freq || !type) | |
1490 | return; | |
1491 | ||
1492 | switch (nla_get_u32(type)) { | |
1493 | case NL80211_CHAN_NO_HT: | |
1494 | ht_enabled = 0; | |
1495 | break; | |
1496 | case NL80211_CHAN_HT20: | |
1497 | break; | |
1498 | case NL80211_CHAN_HT40PLUS: | |
1499 | chan_offset = 1; | |
1500 | break; | |
1501 | case NL80211_CHAN_HT40MINUS: | |
1502 | chan_offset = -1; | |
1503 | break; | |
1504 | } | |
1505 | ||
1506 | data.ch_switch.freq = nla_get_u32(freq); | |
1507 | data.ch_switch.ht_enabled = ht_enabled; | |
1508 | data.ch_switch.ch_offset = chan_offset; | |
1509 | ||
1510 | wpa_supplicant_event(drv->ctx, EVENT_CH_SWITCH, &data); | |
1511 | } | |
1512 | ||
1513 | ||
da1fb17c JM |
1514 | static void mlme_timeout_event(struct wpa_driver_nl80211_data *drv, |
1515 | enum nl80211_commands cmd, struct nlattr *addr) | |
1516 | { | |
1517 | union wpa_event_data event; | |
1518 | enum wpa_event_type ev; | |
1519 | ||
1520 | if (nla_len(addr) != ETH_ALEN) | |
1521 | return; | |
1522 | ||
1523 | wpa_printf(MSG_DEBUG, "nl80211: MLME event %d; timeout with " MACSTR, | |
1524 | cmd, MAC2STR((u8 *) nla_data(addr))); | |
1525 | ||
1526 | if (cmd == NL80211_CMD_AUTHENTICATE) | |
1527 | ev = EVENT_AUTH_TIMED_OUT; | |
1528 | else if (cmd == NL80211_CMD_ASSOCIATE) | |
1529 | ev = EVENT_ASSOC_TIMED_OUT; | |
1530 | else | |
1531 | return; | |
1532 | ||
1533 | os_memset(&event, 0, sizeof(event)); | |
1534 | os_memcpy(event.timeout_event.addr, nla_data(addr), ETH_ALEN); | |
1535 | wpa_supplicant_event(drv->ctx, ev, &event); | |
1536 | } | |
1537 | ||
1538 | ||
5582a5d1 | 1539 | static void mlme_event_mgmt(struct wpa_driver_nl80211_data *drv, |
da873dbb JB |
1540 | struct nlattr *freq, struct nlattr *sig, |
1541 | const u8 *frame, size_t len) | |
58f6fbe0 JM |
1542 | { |
1543 | const struct ieee80211_mgmt *mgmt; | |
1544 | union wpa_event_data event; | |
1545 | u16 fc, stype; | |
da873dbb | 1546 | int ssi_signal = 0; |
f18b7817 | 1547 | int rx_freq = 0; |
58f6fbe0 | 1548 | |
cc2ada86 | 1549 | wpa_printf(MSG_MSGDUMP, "nl80211: Frame event"); |
58f6fbe0 JM |
1550 | mgmt = (const struct ieee80211_mgmt *) frame; |
1551 | if (len < 24) { | |
1552 | wpa_printf(MSG_DEBUG, "nl80211: Too short action frame"); | |
1553 | return; | |
1554 | } | |
1555 | ||
1556 | fc = le_to_host16(mgmt->frame_control); | |
1557 | stype = WLAN_FC_GET_STYPE(fc); | |
1558 | ||
da873dbb JB |
1559 | if (sig) |
1560 | ssi_signal = (s32) nla_get_u32(sig); | |
1561 | ||
58f6fbe0 | 1562 | os_memset(&event, 0, sizeof(event)); |
5582a5d1 | 1563 | if (freq) { |
58f6fbe0 | 1564 | event.rx_action.freq = nla_get_u32(freq); |
f18b7817 | 1565 | rx_freq = drv->last_mgmt_freq = event.rx_action.freq; |
5582a5d1 | 1566 | } |
f18b7817 JM |
1567 | wpa_printf(MSG_DEBUG, |
1568 | "nl80211: RX frame freq=%d ssi_signal=%d stype=%u len=%u", | |
1569 | rx_freq, ssi_signal, stype, (unsigned int) len); | |
5582a5d1 JB |
1570 | if (stype == WLAN_FC_STYPE_ACTION) { |
1571 | event.rx_action.da = mgmt->da; | |
1572 | event.rx_action.sa = mgmt->sa; | |
1573 | event.rx_action.bssid = mgmt->bssid; | |
1574 | event.rx_action.category = mgmt->u.action.category; | |
1575 | event.rx_action.data = &mgmt->u.action.category + 1; | |
1576 | event.rx_action.len = frame + len - event.rx_action.data; | |
1577 | wpa_supplicant_event(drv->ctx, EVENT_RX_ACTION, &event); | |
1578 | } else { | |
1579 | event.rx_mgmt.frame = frame; | |
1580 | event.rx_mgmt.frame_len = len; | |
da873dbb | 1581 | event.rx_mgmt.ssi_signal = ssi_signal; |
5582a5d1 JB |
1582 | wpa_supplicant_event(drv->ctx, EVENT_RX_MGMT, &event); |
1583 | } | |
58f6fbe0 JM |
1584 | } |
1585 | ||
1586 | ||
a11241fa JB |
1587 | static void mlme_event_mgmt_tx_status(struct wpa_driver_nl80211_data *drv, |
1588 | struct nlattr *cookie, const u8 *frame, | |
1589 | size_t len, struct nlattr *ack) | |
58f6fbe0 JM |
1590 | { |
1591 | union wpa_event_data event; | |
1592 | const struct ieee80211_hdr *hdr; | |
1593 | u16 fc; | |
58f6fbe0 | 1594 | |
7d81932d | 1595 | wpa_printf(MSG_DEBUG, "nl80211: Frame TX status event"); |
a11241fa JB |
1596 | if (!is_ap_interface(drv->nlmode)) { |
1597 | u64 cookie_val; | |
58f6fbe0 | 1598 | |
a11241fa JB |
1599 | if (!cookie) |
1600 | return; | |
1601 | ||
1602 | cookie_val = nla_get_u64(cookie); | |
1603 | wpa_printf(MSG_DEBUG, "nl80211: Action TX status:" | |
1604 | " cookie=0%llx%s (ack=%d)", | |
1605 | (long long unsigned int) cookie_val, | |
1606 | cookie_val == drv->send_action_cookie ? | |
1607 | " (match)" : " (unknown)", ack != NULL); | |
1608 | if (cookie_val != drv->send_action_cookie) | |
1609 | return; | |
1610 | } | |
58f6fbe0 JM |
1611 | |
1612 | hdr = (const struct ieee80211_hdr *) frame; | |
1613 | fc = le_to_host16(hdr->frame_control); | |
1614 | ||
1615 | os_memset(&event, 0, sizeof(event)); | |
1616 | event.tx_status.type = WLAN_FC_GET_TYPE(fc); | |
1617 | event.tx_status.stype = WLAN_FC_GET_STYPE(fc); | |
1618 | event.tx_status.dst = hdr->addr1; | |
1619 | event.tx_status.data = frame; | |
1620 | event.tx_status.data_len = len; | |
1621 | event.tx_status.ack = ack != NULL; | |
1622 | wpa_supplicant_event(drv->ctx, EVENT_TX_STATUS, &event); | |
1623 | } | |
1624 | ||
1625 | ||
0544b242 JM |
1626 | static void mlme_event_deauth_disassoc(struct wpa_driver_nl80211_data *drv, |
1627 | enum wpa_event_type type, | |
1628 | const u8 *frame, size_t len) | |
1629 | { | |
1630 | const struct ieee80211_mgmt *mgmt; | |
1631 | union wpa_event_data event; | |
1632 | const u8 *bssid = NULL; | |
1633 | u16 reason_code = 0; | |
1634 | ||
7d81932d JM |
1635 | if (type == EVENT_DEAUTH) |
1636 | wpa_printf(MSG_DEBUG, "nl80211: Deauthenticate event"); | |
1637 | else | |
1638 | wpa_printf(MSG_DEBUG, "nl80211: Disassociate event"); | |
1639 | ||
cb30b297 PS |
1640 | mgmt = (const struct ieee80211_mgmt *) frame; |
1641 | if (len >= 24) { | |
1642 | bssid = mgmt->bssid; | |
1643 | ||
add9b7a4 JM |
1644 | if ((drv->capa.flags & WPA_DRIVER_FLAGS_SME) && |
1645 | !drv->associated && | |
1646 | os_memcmp(bssid, drv->auth_bssid, ETH_ALEN) != 0 && | |
1647 | os_memcmp(bssid, drv->auth_attempt_bssid, ETH_ALEN) != 0 && | |
1648 | os_memcmp(bssid, drv->prev_bssid, ETH_ALEN) == 0) { | |
1649 | /* | |
1650 | * Avoid issues with some roaming cases where | |
1651 | * disconnection event for the old AP may show up after | |
1652 | * we have started connection with the new AP. | |
1653 | */ | |
1654 | wpa_printf(MSG_DEBUG, "nl80211: Ignore deauth/disassoc event from old AP " MACSTR " when already authenticating with " MACSTR, | |
1655 | MAC2STR(bssid), | |
1656 | MAC2STR(drv->auth_attempt_bssid)); | |
1657 | return; | |
1658 | } | |
1659 | ||
cb30b297 PS |
1660 | if (drv->associated != 0 && |
1661 | os_memcmp(bssid, drv->bssid, ETH_ALEN) != 0 && | |
1662 | os_memcmp(bssid, drv->auth_bssid, ETH_ALEN) != 0) { | |
1663 | /* | |
1664 | * We have presumably received this deauth as a | |
1665 | * response to a clear_state_mismatch() outgoing | |
1666 | * deauth. Don't let it take us offline! | |
1667 | */ | |
1668 | wpa_printf(MSG_DEBUG, "nl80211: Deauth received " | |
1669 | "from Unknown BSSID " MACSTR " -- ignoring", | |
1670 | MAC2STR(bssid)); | |
1671 | return; | |
1672 | } | |
1673 | } | |
1674 | ||
add9b7a4 | 1675 | nl80211_mark_disconnected(drv); |
0544b242 JM |
1676 | os_memset(&event, 0, sizeof(event)); |
1677 | ||
0544b242 JM |
1678 | /* Note: Same offset for Reason Code in both frame subtypes */ |
1679 | if (len >= 24 + sizeof(mgmt->u.deauth)) | |
1680 | reason_code = le_to_host16(mgmt->u.deauth.reason_code); | |
1681 | ||
1682 | if (type == EVENT_DISASSOC) { | |
3d9975d5 JM |
1683 | event.disassoc_info.locally_generated = |
1684 | !os_memcmp(mgmt->sa, drv->first_bss.addr, ETH_ALEN); | |
0544b242 JM |
1685 | event.disassoc_info.addr = bssid; |
1686 | event.disassoc_info.reason_code = reason_code; | |
046b26a2 JM |
1687 | if (frame + len > mgmt->u.disassoc.variable) { |
1688 | event.disassoc_info.ie = mgmt->u.disassoc.variable; | |
1689 | event.disassoc_info.ie_len = frame + len - | |
1690 | mgmt->u.disassoc.variable; | |
1691 | } | |
0544b242 | 1692 | } else { |
3d9975d5 JM |
1693 | event.deauth_info.locally_generated = |
1694 | !os_memcmp(mgmt->sa, drv->first_bss.addr, ETH_ALEN); | |
0544b242 JM |
1695 | event.deauth_info.addr = bssid; |
1696 | event.deauth_info.reason_code = reason_code; | |
046b26a2 JM |
1697 | if (frame + len > mgmt->u.deauth.variable) { |
1698 | event.deauth_info.ie = mgmt->u.deauth.variable; | |
1699 | event.deauth_info.ie_len = frame + len - | |
1700 | mgmt->u.deauth.variable; | |
1701 | } | |
0544b242 JM |
1702 | } |
1703 | ||
1704 | wpa_supplicant_event(drv->ctx, type, &event); | |
1705 | } | |
1706 | ||
1707 | ||
7d878ca7 JM |
1708 | static void mlme_event_unprot_disconnect(struct wpa_driver_nl80211_data *drv, |
1709 | enum wpa_event_type type, | |
1710 | const u8 *frame, size_t len) | |
1711 | { | |
1712 | const struct ieee80211_mgmt *mgmt; | |
1713 | union wpa_event_data event; | |
1714 | u16 reason_code = 0; | |
1715 | ||
7d81932d JM |
1716 | if (type == EVENT_UNPROT_DEAUTH) |
1717 | wpa_printf(MSG_DEBUG, "nl80211: Unprot Deauthenticate event"); | |
1718 | else | |
1719 | wpa_printf(MSG_DEBUG, "nl80211: Unprot Disassociate event"); | |
1720 | ||
7d878ca7 JM |
1721 | if (len < 24) |
1722 | return; | |
1723 | ||
1724 | mgmt = (const struct ieee80211_mgmt *) frame; | |
1725 | ||
1726 | os_memset(&event, 0, sizeof(event)); | |
1727 | /* Note: Same offset for Reason Code in both frame subtypes */ | |
1728 | if (len >= 24 + sizeof(mgmt->u.deauth)) | |
1729 | reason_code = le_to_host16(mgmt->u.deauth.reason_code); | |
1730 | ||
1731 | if (type == EVENT_UNPROT_DISASSOC) { | |
1732 | event.unprot_disassoc.sa = mgmt->sa; | |
1733 | event.unprot_disassoc.da = mgmt->da; | |
1734 | event.unprot_disassoc.reason_code = reason_code; | |
1735 | } else { | |
1736 | event.unprot_deauth.sa = mgmt->sa; | |
1737 | event.unprot_deauth.da = mgmt->da; | |
1738 | event.unprot_deauth.reason_code = reason_code; | |
1739 | } | |
1740 | ||
1741 | wpa_supplicant_event(drv->ctx, type, &event); | |
1742 | } | |
1743 | ||
1744 | ||
97279d8d | 1745 | static void mlme_event(struct i802_bss *bss, |
da1fb17c | 1746 | enum nl80211_commands cmd, struct nlattr *frame, |
58f6fbe0 JM |
1747 | struct nlattr *addr, struct nlattr *timed_out, |
1748 | struct nlattr *freq, struct nlattr *ack, | |
da873dbb | 1749 | struct nlattr *cookie, struct nlattr *sig) |
c2a04078 | 1750 | { |
97279d8d JM |
1751 | struct wpa_driver_nl80211_data *drv = bss->drv; |
1752 | const u8 *data; | |
1753 | size_t len; | |
1754 | ||
da1fb17c JM |
1755 | if (timed_out && addr) { |
1756 | mlme_timeout_event(drv, cmd, addr); | |
1757 | return; | |
1758 | } | |
1759 | ||
c2a04078 | 1760 | if (frame == NULL) { |
2090a0b4 DS |
1761 | wpa_printf(MSG_DEBUG, |
1762 | "nl80211: MLME event %d (%s) without frame data", | |
1763 | cmd, nl80211_command_to_string(cmd)); | |
c2a04078 JM |
1764 | return; |
1765 | } | |
1766 | ||
97279d8d JM |
1767 | data = nla_data(frame); |
1768 | len = nla_len(frame); | |
455299fb | 1769 | if (len < 4 + 2 * ETH_ALEN) { |
2090a0b4 DS |
1770 | wpa_printf(MSG_MSGDUMP, "nl80211: MLME event %d (%s) on %s(" |
1771 | MACSTR ") - too short", | |
1772 | cmd, nl80211_command_to_string(cmd), bss->ifname, | |
1773 | MAC2STR(bss->addr)); | |
97279d8d JM |
1774 | return; |
1775 | } | |
2090a0b4 DS |
1776 | wpa_printf(MSG_MSGDUMP, "nl80211: MLME event %d (%s) on %s(" MACSTR |
1777 | ") A1=" MACSTR " A2=" MACSTR, cmd, | |
1778 | nl80211_command_to_string(cmd), bss->ifname, | |
1779 | MAC2STR(bss->addr), MAC2STR(data + 4), | |
1780 | MAC2STR(data + 4 + ETH_ALEN)); | |
97279d8d | 1781 | if (cmd != NL80211_CMD_FRAME_TX_STATUS && !(data[4] & 0x01) && |
455299fb JM |
1782 | os_memcmp(bss->addr, data + 4, ETH_ALEN) != 0 && |
1783 | os_memcmp(bss->addr, data + 4 + ETH_ALEN, ETH_ALEN) != 0) { | |
97279d8d JM |
1784 | wpa_printf(MSG_MSGDUMP, "nl80211: %s: Ignore MLME frame event " |
1785 | "for foreign address", bss->ifname); | |
1786 | return; | |
1787 | } | |
c2a04078 JM |
1788 | wpa_hexdump(MSG_MSGDUMP, "nl80211: MLME event frame", |
1789 | nla_data(frame), nla_len(frame)); | |
1790 | ||
1791 | switch (cmd) { | |
1792 | case NL80211_CMD_AUTHENTICATE: | |
1793 | mlme_event_auth(drv, nla_data(frame), nla_len(frame)); | |
1794 | break; | |
1795 | case NL80211_CMD_ASSOCIATE: | |
1796 | mlme_event_assoc(drv, nla_data(frame), nla_len(frame)); | |
1797 | break; | |
1798 | case NL80211_CMD_DEAUTHENTICATE: | |
0544b242 JM |
1799 | mlme_event_deauth_disassoc(drv, EVENT_DEAUTH, |
1800 | nla_data(frame), nla_len(frame)); | |
c2a04078 JM |
1801 | break; |
1802 | case NL80211_CMD_DISASSOCIATE: | |
0544b242 JM |
1803 | mlme_event_deauth_disassoc(drv, EVENT_DISASSOC, |
1804 | nla_data(frame), nla_len(frame)); | |
c2a04078 | 1805 | break; |
bd94971e | 1806 | case NL80211_CMD_FRAME: |
da873dbb JB |
1807 | mlme_event_mgmt(drv, freq, sig, nla_data(frame), |
1808 | nla_len(frame)); | |
58f6fbe0 | 1809 | break; |
bd94971e | 1810 | case NL80211_CMD_FRAME_TX_STATUS: |
a11241fa JB |
1811 | mlme_event_mgmt_tx_status(drv, cookie, nla_data(frame), |
1812 | nla_len(frame), ack); | |
58f6fbe0 | 1813 | break; |
7d878ca7 JM |
1814 | case NL80211_CMD_UNPROT_DEAUTHENTICATE: |
1815 | mlme_event_unprot_disconnect(drv, EVENT_UNPROT_DEAUTH, | |
1816 | nla_data(frame), nla_len(frame)); | |
1817 | break; | |
1818 | case NL80211_CMD_UNPROT_DISASSOCIATE: | |
1819 | mlme_event_unprot_disconnect(drv, EVENT_UNPROT_DISASSOC, | |
1820 | nla_data(frame), nla_len(frame)); | |
1821 | break; | |
c2a04078 JM |
1822 | default: |
1823 | break; | |
1824 | } | |
1825 | } | |
1826 | ||
1827 | ||
a5e1eb20 | 1828 | static void mlme_event_michael_mic_failure(struct i802_bss *bss, |
35583f3f JM |
1829 | struct nlattr *tb[]) |
1830 | { | |
1831 | union wpa_event_data data; | |
1832 | ||
1833 | wpa_printf(MSG_DEBUG, "nl80211: MLME event Michael MIC failure"); | |
1834 | os_memset(&data, 0, sizeof(data)); | |
1835 | if (tb[NL80211_ATTR_MAC]) { | |
1836 | wpa_hexdump(MSG_DEBUG, "nl80211: Source MAC address", | |
1837 | nla_data(tb[NL80211_ATTR_MAC]), | |
1838 | nla_len(tb[NL80211_ATTR_MAC])); | |
ad1e68e6 | 1839 | data.michael_mic_failure.src = nla_data(tb[NL80211_ATTR_MAC]); |
35583f3f JM |
1840 | } |
1841 | if (tb[NL80211_ATTR_KEY_SEQ]) { | |
1842 | wpa_hexdump(MSG_DEBUG, "nl80211: TSC", | |
1843 | nla_data(tb[NL80211_ATTR_KEY_SEQ]), | |
1844 | nla_len(tb[NL80211_ATTR_KEY_SEQ])); | |
1845 | } | |
1846 | if (tb[NL80211_ATTR_KEY_TYPE]) { | |
1847 | enum nl80211_key_type key_type = | |
1848 | nla_get_u32(tb[NL80211_ATTR_KEY_TYPE]); | |
1849 | wpa_printf(MSG_DEBUG, "nl80211: Key Type %d", key_type); | |
1850 | if (key_type == NL80211_KEYTYPE_PAIRWISE) | |
1851 | data.michael_mic_failure.unicast = 1; | |
1852 | } else | |
1853 | data.michael_mic_failure.unicast = 1; | |
1854 | ||
1855 | if (tb[NL80211_ATTR_KEY_IDX]) { | |
1856 | u8 key_id = nla_get_u8(tb[NL80211_ATTR_KEY_IDX]); | |
1857 | wpa_printf(MSG_DEBUG, "nl80211: Key Id %d", key_id); | |
1858 | } | |
1859 | ||
a5e1eb20 | 1860 | wpa_supplicant_event(bss->ctx, EVENT_MICHAEL_MIC_FAILURE, &data); |
35583f3f JM |
1861 | } |
1862 | ||
1863 | ||
5cc4d64b JM |
1864 | static void mlme_event_join_ibss(struct wpa_driver_nl80211_data *drv, |
1865 | struct nlattr *tb[]) | |
1866 | { | |
1867 | if (tb[NL80211_ATTR_MAC] == NULL) { | |
1868 | wpa_printf(MSG_DEBUG, "nl80211: No address in IBSS joined " | |
1869 | "event"); | |
1870 | return; | |
1871 | } | |
1872 | os_memcpy(drv->bssid, nla_data(tb[NL80211_ATTR_MAC]), ETH_ALEN); | |
b21990b4 | 1873 | |
5cc4d64b JM |
1874 | drv->associated = 1; |
1875 | wpa_printf(MSG_DEBUG, "nl80211: IBSS " MACSTR " joined", | |
1876 | MAC2STR(drv->bssid)); | |
1877 | ||
1878 | wpa_supplicant_event(drv->ctx, EVENT_ASSOC, NULL); | |
1879 | } | |
1880 | ||
1881 | ||
55777702 JM |
1882 | static void mlme_event_remain_on_channel(struct wpa_driver_nl80211_data *drv, |
1883 | int cancel_event, struct nlattr *tb[]) | |
1884 | { | |
1885 | unsigned int freq, chan_type, duration; | |
1886 | union wpa_event_data data; | |
1887 | u64 cookie; | |
1888 | ||
1889 | if (tb[NL80211_ATTR_WIPHY_FREQ]) | |
1890 | freq = nla_get_u32(tb[NL80211_ATTR_WIPHY_FREQ]); | |
1891 | else | |
1892 | freq = 0; | |
1893 | ||
1894 | if (tb[NL80211_ATTR_WIPHY_CHANNEL_TYPE]) | |
1895 | chan_type = nla_get_u32(tb[NL80211_ATTR_WIPHY_CHANNEL_TYPE]); | |
1896 | else | |
1897 | chan_type = 0; | |
1898 | ||
1899 | if (tb[NL80211_ATTR_DURATION]) | |
1900 | duration = nla_get_u32(tb[NL80211_ATTR_DURATION]); | |
1901 | else | |
1902 | duration = 0; | |
1903 | ||
1904 | if (tb[NL80211_ATTR_COOKIE]) | |
1905 | cookie = nla_get_u64(tb[NL80211_ATTR_COOKIE]); | |
1906 | else | |
1907 | cookie = 0; | |
1908 | ||
1909 | wpa_printf(MSG_DEBUG, "nl80211: Remain-on-channel event (cancel=%d " | |
1910 | "freq=%u channel_type=%u duration=%u cookie=0x%llx (%s))", | |
1911 | cancel_event, freq, chan_type, duration, | |
1912 | (long long unsigned int) cookie, | |
1913 | cookie == drv->remain_on_chan_cookie ? "match" : "unknown"); | |
1914 | ||
1915 | if (cookie != drv->remain_on_chan_cookie) | |
1916 | return; /* not for us */ | |
1917 | ||
531f0331 JB |
1918 | if (cancel_event) |
1919 | drv->pending_remain_on_chan = 0; | |
55777702 JM |
1920 | |
1921 | os_memset(&data, 0, sizeof(data)); | |
1922 | data.remain_on_channel.freq = freq; | |
1923 | data.remain_on_channel.duration = duration; | |
1924 | wpa_supplicant_event(drv->ctx, cancel_event ? | |
1925 | EVENT_CANCEL_REMAIN_ON_CHANNEL : | |
1926 | EVENT_REMAIN_ON_CHANNEL, &data); | |
1927 | } | |
1928 | ||
1929 | ||
6a1ce395 DG |
1930 | static void mlme_event_ft_event(struct wpa_driver_nl80211_data *drv, |
1931 | struct nlattr *tb[]) | |
1932 | { | |
1933 | union wpa_event_data data; | |
1934 | ||
1935 | os_memset(&data, 0, sizeof(data)); | |
1936 | ||
1937 | if (tb[NL80211_ATTR_IE]) { | |
1938 | data.ft_ies.ies = nla_data(tb[NL80211_ATTR_IE]); | |
1939 | data.ft_ies.ies_len = nla_len(tb[NL80211_ATTR_IE]); | |
1940 | } | |
1941 | ||
1942 | if (tb[NL80211_ATTR_IE_RIC]) { | |
1943 | data.ft_ies.ric_ies = nla_data(tb[NL80211_ATTR_IE_RIC]); | |
1944 | data.ft_ies.ric_ies_len = nla_len(tb[NL80211_ATTR_IE_RIC]); | |
1945 | } | |
1946 | ||
1947 | if (tb[NL80211_ATTR_MAC]) | |
1948 | os_memcpy(data.ft_ies.target_ap, | |
1949 | nla_data(tb[NL80211_ATTR_MAC]), ETH_ALEN); | |
1950 | ||
1951 | wpa_printf(MSG_DEBUG, "nl80211: FT event target_ap " MACSTR, | |
1952 | MAC2STR(data.ft_ies.target_ap)); | |
1953 | ||
1954 | wpa_supplicant_event(drv->ctx, EVENT_FT_RESPONSE, &data); | |
1955 | } | |
1956 | ||
1957 | ||
8d923a4a JM |
1958 | static void send_scan_event(struct wpa_driver_nl80211_data *drv, int aborted, |
1959 | struct nlattr *tb[]) | |
1960 | { | |
1961 | union wpa_event_data event; | |
1962 | struct nlattr *nl; | |
1963 | int rem; | |
1964 | struct scan_info *info; | |
1965 | #define MAX_REPORT_FREQS 50 | |
1966 | int freqs[MAX_REPORT_FREQS]; | |
1967 | int num_freqs = 0; | |
1968 | ||
536fd62d JM |
1969 | if (drv->scan_for_auth) { |
1970 | drv->scan_for_auth = 0; | |
1971 | wpa_printf(MSG_DEBUG, "nl80211: Scan results for missing " | |
1972 | "cfg80211 BSS entry"); | |
1973 | wpa_driver_nl80211_authenticate_retry(drv); | |
1974 | return; | |
1975 | } | |
1976 | ||
8d923a4a JM |
1977 | os_memset(&event, 0, sizeof(event)); |
1978 | info = &event.scan_info; | |
1979 | info->aborted = aborted; | |
1980 | ||
1981 | if (tb[NL80211_ATTR_SCAN_SSIDS]) { | |
1982 | nla_for_each_nested(nl, tb[NL80211_ATTR_SCAN_SSIDS], rem) { | |
1983 | struct wpa_driver_scan_ssid *s = | |
1984 | &info->ssids[info->num_ssids]; | |
1985 | s->ssid = nla_data(nl); | |
1986 | s->ssid_len = nla_len(nl); | |
1987 | info->num_ssids++; | |
1988 | if (info->num_ssids == WPAS_MAX_SCAN_SSIDS) | |
1989 | break; | |
1990 | } | |
1991 | } | |
1992 | if (tb[NL80211_ATTR_SCAN_FREQUENCIES]) { | |
1993 | nla_for_each_nested(nl, tb[NL80211_ATTR_SCAN_FREQUENCIES], rem) | |
1994 | { | |
1995 | freqs[num_freqs] = nla_get_u32(nl); | |
1996 | num_freqs++; | |
1997 | if (num_freqs == MAX_REPORT_FREQS - 1) | |
1998 | break; | |
1999 | } | |
2000 | info->freqs = freqs; | |
2001 | info->num_freqs = num_freqs; | |
2002 | } | |
2003 | wpa_supplicant_event(drv->ctx, EVENT_SCAN_RESULTS, &event); | |
2004 | } | |
2005 | ||
2006 | ||
60a972a6 JM |
2007 | static int get_link_signal(struct nl_msg *msg, void *arg) |
2008 | { | |
2009 | struct nlattr *tb[NL80211_ATTR_MAX + 1]; | |
2010 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); | |
2011 | struct nlattr *sinfo[NL80211_STA_INFO_MAX + 1]; | |
2012 | static struct nla_policy policy[NL80211_STA_INFO_MAX + 1] = { | |
2013 | [NL80211_STA_INFO_SIGNAL] = { .type = NLA_U8 }, | |
95783298 | 2014 | [NL80211_STA_INFO_SIGNAL_AVG] = { .type = NLA_U8 }, |
60a972a6 | 2015 | }; |
7ee35bf3 PS |
2016 | struct nlattr *rinfo[NL80211_RATE_INFO_MAX + 1]; |
2017 | static struct nla_policy rate_policy[NL80211_RATE_INFO_MAX + 1] = { | |
2018 | [NL80211_RATE_INFO_BITRATE] = { .type = NLA_U16 }, | |
2019 | [NL80211_RATE_INFO_MCS] = { .type = NLA_U8 }, | |
2020 | [NL80211_RATE_INFO_40_MHZ_WIDTH] = { .type = NLA_FLAG }, | |
2021 | [NL80211_RATE_INFO_SHORT_GI] = { .type = NLA_FLAG }, | |
2022 | }; | |
1c5c7273 | 2023 | struct wpa_signal_info *sig_change = arg; |
60a972a6 JM |
2024 | |
2025 | nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), | |
2026 | genlmsg_attrlen(gnlh, 0), NULL); | |
2027 | if (!tb[NL80211_ATTR_STA_INFO] || | |
2028 | nla_parse_nested(sinfo, NL80211_STA_INFO_MAX, | |
2029 | tb[NL80211_ATTR_STA_INFO], policy)) | |
2030 | return NL_SKIP; | |
2031 | if (!sinfo[NL80211_STA_INFO_SIGNAL]) | |
2032 | return NL_SKIP; | |
2033 | ||
7ee35bf3 PS |
2034 | sig_change->current_signal = |
2035 | (s8) nla_get_u8(sinfo[NL80211_STA_INFO_SIGNAL]); | |
2036 | ||
95783298 AO |
2037 | if (sinfo[NL80211_STA_INFO_SIGNAL_AVG]) |
2038 | sig_change->avg_signal = | |
2039 | (s8) nla_get_u8(sinfo[NL80211_STA_INFO_SIGNAL_AVG]); | |
2040 | else | |
2041 | sig_change->avg_signal = 0; | |
2042 | ||
7ee35bf3 PS |
2043 | if (sinfo[NL80211_STA_INFO_TX_BITRATE]) { |
2044 | if (nla_parse_nested(rinfo, NL80211_RATE_INFO_MAX, | |
2045 | sinfo[NL80211_STA_INFO_TX_BITRATE], | |
2046 | rate_policy)) { | |
2047 | sig_change->current_txrate = 0; | |
2048 | } else { | |
2049 | if (rinfo[NL80211_RATE_INFO_BITRATE]) { | |
2050 | sig_change->current_txrate = | |
2051 | nla_get_u16(rinfo[ | |
2052 | NL80211_RATE_INFO_BITRATE]) * 100; | |
2053 | } | |
2054 | } | |
2055 | } | |
2056 | ||
60a972a6 JM |
2057 | return NL_SKIP; |
2058 | } | |
2059 | ||
2060 | ||
2061 | static int nl80211_get_link_signal(struct wpa_driver_nl80211_data *drv, | |
1c5c7273 | 2062 | struct wpa_signal_info *sig) |
60a972a6 JM |
2063 | { |
2064 | struct nl_msg *msg; | |
2065 | ||
7ee35bf3 PS |
2066 | sig->current_signal = -9999; |
2067 | sig->current_txrate = 0; | |
60a972a6 JM |
2068 | |
2069 | msg = nlmsg_alloc(); | |
2070 | if (!msg) | |
2071 | return -ENOMEM; | |
2072 | ||
9fb04070 | 2073 | nl80211_cmd(drv, msg, 0, NL80211_CMD_GET_STATION); |
60a972a6 JM |
2074 | |
2075 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, drv->ifindex); | |
2076 | NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, drv->bssid); | |
2077 | ||
2078 | return send_and_recv_msgs(drv, msg, get_link_signal, sig); | |
2079 | nla_put_failure: | |
5883168a | 2080 | nlmsg_free(msg); |
60a972a6 JM |
2081 | return -ENOBUFS; |
2082 | } | |
2083 | ||
2084 | ||
7ee35bf3 PS |
2085 | static int get_link_noise(struct nl_msg *msg, void *arg) |
2086 | { | |
2087 | struct nlattr *tb[NL80211_ATTR_MAX + 1]; | |
2088 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); | |
2089 | struct nlattr *sinfo[NL80211_SURVEY_INFO_MAX + 1]; | |
2090 | static struct nla_policy survey_policy[NL80211_SURVEY_INFO_MAX + 1] = { | |
2091 | [NL80211_SURVEY_INFO_FREQUENCY] = { .type = NLA_U32 }, | |
2092 | [NL80211_SURVEY_INFO_NOISE] = { .type = NLA_U8 }, | |
2093 | }; | |
1c5c7273 | 2094 | struct wpa_signal_info *sig_change = arg; |
7ee35bf3 PS |
2095 | |
2096 | nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), | |
2097 | genlmsg_attrlen(gnlh, 0), NULL); | |
2098 | ||
2099 | if (!tb[NL80211_ATTR_SURVEY_INFO]) { | |
2100 | wpa_printf(MSG_DEBUG, "nl80211: survey data missing!"); | |
2101 | return NL_SKIP; | |
2102 | } | |
2103 | ||
2104 | if (nla_parse_nested(sinfo, NL80211_SURVEY_INFO_MAX, | |
2105 | tb[NL80211_ATTR_SURVEY_INFO], | |
2106 | survey_policy)) { | |
2107 | wpa_printf(MSG_DEBUG, "nl80211: failed to parse nested " | |
2108 | "attributes!"); | |
2109 | return NL_SKIP; | |
2110 | } | |
2111 | ||
2112 | if (!sinfo[NL80211_SURVEY_INFO_FREQUENCY]) | |
2113 | return NL_SKIP; | |
2114 | ||
2115 | if (nla_get_u32(sinfo[NL80211_SURVEY_INFO_FREQUENCY]) != | |
2116 | sig_change->frequency) | |
2117 | return NL_SKIP; | |
2118 | ||
2119 | if (!sinfo[NL80211_SURVEY_INFO_NOISE]) | |
2120 | return NL_SKIP; | |
2121 | ||
2122 | sig_change->current_noise = | |
2123 | (s8) nla_get_u8(sinfo[NL80211_SURVEY_INFO_NOISE]); | |
2124 | ||
2125 | return NL_SKIP; | |
2126 | } | |
2127 | ||
2128 | ||
2129 | static int nl80211_get_link_noise(struct wpa_driver_nl80211_data *drv, | |
1c5c7273 | 2130 | struct wpa_signal_info *sig_change) |
7ee35bf3 PS |
2131 | { |
2132 | struct nl_msg *msg; | |
2133 | ||
2134 | sig_change->current_noise = 9999; | |
2135 | sig_change->frequency = drv->assoc_freq; | |
2136 | ||
2137 | msg = nlmsg_alloc(); | |
2138 | if (!msg) | |
2139 | return -ENOMEM; | |
2140 | ||
9fb04070 | 2141 | nl80211_cmd(drv, msg, NLM_F_DUMP, NL80211_CMD_GET_SURVEY); |
7ee35bf3 PS |
2142 | |
2143 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, drv->ifindex); | |
2144 | ||
2145 | return send_and_recv_msgs(drv, msg, get_link_noise, sig_change); | |
2146 | nla_put_failure: | |
5883168a | 2147 | nlmsg_free(msg); |
7ee35bf3 PS |
2148 | return -ENOBUFS; |
2149 | } | |
2150 | ||
2151 | ||
577db0ae GM |
2152 | static int get_noise_for_scan_results(struct nl_msg *msg, void *arg) |
2153 | { | |
2154 | struct nlattr *tb[NL80211_ATTR_MAX + 1]; | |
2155 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); | |
2156 | struct nlattr *sinfo[NL80211_SURVEY_INFO_MAX + 1]; | |
2157 | static struct nla_policy survey_policy[NL80211_SURVEY_INFO_MAX + 1] = { | |
2158 | [NL80211_SURVEY_INFO_FREQUENCY] = { .type = NLA_U32 }, | |
2159 | [NL80211_SURVEY_INFO_NOISE] = { .type = NLA_U8 }, | |
2160 | }; | |
2161 | struct wpa_scan_results *scan_results = arg; | |
2162 | struct wpa_scan_res *scan_res; | |
2163 | size_t i; | |
2164 | ||
2165 | nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), | |
2166 | genlmsg_attrlen(gnlh, 0), NULL); | |
2167 | ||
2168 | if (!tb[NL80211_ATTR_SURVEY_INFO]) { | |
2169 | wpa_printf(MSG_DEBUG, "nl80211: Survey data missing"); | |
2170 | return NL_SKIP; | |
2171 | } | |
2172 | ||
2173 | if (nla_parse_nested(sinfo, NL80211_SURVEY_INFO_MAX, | |
2174 | tb[NL80211_ATTR_SURVEY_INFO], | |
2175 | survey_policy)) { | |
2176 | wpa_printf(MSG_DEBUG, "nl80211: Failed to parse nested " | |
2177 | "attributes"); | |
2178 | return NL_SKIP; | |
2179 | } | |
2180 | ||
2181 | if (!sinfo[NL80211_SURVEY_INFO_NOISE]) | |
2182 | return NL_SKIP; | |
2183 | ||
2184 | if (!sinfo[NL80211_SURVEY_INFO_FREQUENCY]) | |
2185 | return NL_SKIP; | |
2186 | ||
2187 | for (i = 0; i < scan_results->num; ++i) { | |
2188 | scan_res = scan_results->res[i]; | |
2189 | if (!scan_res) | |
2190 | continue; | |
2191 | if ((int) nla_get_u32(sinfo[NL80211_SURVEY_INFO_FREQUENCY]) != | |
2192 | scan_res->freq) | |
2193 | continue; | |
2194 | if (!(scan_res->flags & WPA_SCAN_NOISE_INVALID)) | |
2195 | continue; | |
2196 | scan_res->noise = (s8) | |
2197 | nla_get_u8(sinfo[NL80211_SURVEY_INFO_NOISE]); | |
2198 | scan_res->flags &= ~WPA_SCAN_NOISE_INVALID; | |
2199 | } | |
2200 | ||
2201 | return NL_SKIP; | |
2202 | } | |
2203 | ||
2204 | ||
2205 | static int nl80211_get_noise_for_scan_results( | |
2206 | struct wpa_driver_nl80211_data *drv, | |
2207 | struct wpa_scan_results *scan_res) | |
2208 | { | |
2209 | struct nl_msg *msg; | |
2210 | ||
2211 | msg = nlmsg_alloc(); | |
2212 | if (!msg) | |
2213 | return -ENOMEM; | |
2214 | ||
2215 | nl80211_cmd(drv, msg, NLM_F_DUMP, NL80211_CMD_GET_SURVEY); | |
2216 | ||
2217 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, drv->ifindex); | |
2218 | ||
2219 | return send_and_recv_msgs(drv, msg, get_noise_for_scan_results, | |
2220 | scan_res); | |
2221 | nla_put_failure: | |
9e088e74 | 2222 | nlmsg_free(msg); |
577db0ae GM |
2223 | return -ENOBUFS; |
2224 | } | |
2225 | ||
2226 | ||
93910401 JM |
2227 | static void nl80211_cqm_event(struct wpa_driver_nl80211_data *drv, |
2228 | struct nlattr *tb[]) | |
2229 | { | |
2230 | static struct nla_policy cqm_policy[NL80211_ATTR_CQM_MAX + 1] = { | |
2231 | [NL80211_ATTR_CQM_RSSI_THOLD] = { .type = NLA_U32 }, | |
2232 | [NL80211_ATTR_CQM_RSSI_HYST] = { .type = NLA_U8 }, | |
2233 | [NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT] = { .type = NLA_U32 }, | |
0d7e5a3a | 2234 | [NL80211_ATTR_CQM_PKT_LOSS_EVENT] = { .type = NLA_U32 }, |
93910401 JM |
2235 | }; |
2236 | struct nlattr *cqm[NL80211_ATTR_CQM_MAX + 1]; | |
2237 | enum nl80211_cqm_rssi_threshold_event event; | |
b625473c | 2238 | union wpa_event_data ed; |
1c5c7273 | 2239 | struct wpa_signal_info sig; |
7ee35bf3 | 2240 | int res; |
93910401 JM |
2241 | |
2242 | if (tb[NL80211_ATTR_CQM] == NULL || | |
2243 | nla_parse_nested(cqm, NL80211_ATTR_CQM_MAX, tb[NL80211_ATTR_CQM], | |
2244 | cqm_policy)) { | |
2245 | wpa_printf(MSG_DEBUG, "nl80211: Ignore invalid CQM event"); | |
2246 | return; | |
2247 | } | |
2248 | ||
0d7e5a3a JB |
2249 | os_memset(&ed, 0, sizeof(ed)); |
2250 | ||
2251 | if (cqm[NL80211_ATTR_CQM_PKT_LOSS_EVENT]) { | |
2252 | if (!tb[NL80211_ATTR_MAC]) | |
2253 | return; | |
2254 | os_memcpy(ed.low_ack.addr, nla_data(tb[NL80211_ATTR_MAC]), | |
2255 | ETH_ALEN); | |
2256 | wpa_supplicant_event(drv->ctx, EVENT_STATION_LOW_ACK, &ed); | |
2257 | return; | |
2258 | } | |
2259 | ||
93910401 JM |
2260 | if (cqm[NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT] == NULL) |
2261 | return; | |
2262 | event = nla_get_u32(cqm[NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT]); | |
b625473c | 2263 | |
93910401 JM |
2264 | if (event == NL80211_CQM_RSSI_THRESHOLD_EVENT_HIGH) { |
2265 | wpa_printf(MSG_DEBUG, "nl80211: Connection quality monitor " | |
2266 | "event: RSSI high"); | |
b625473c | 2267 | ed.signal_change.above_threshold = 1; |
93910401 JM |
2268 | } else if (event == NL80211_CQM_RSSI_THRESHOLD_EVENT_LOW) { |
2269 | wpa_printf(MSG_DEBUG, "nl80211: Connection quality monitor " | |
2270 | "event: RSSI low"); | |
b625473c JM |
2271 | ed.signal_change.above_threshold = 0; |
2272 | } else | |
2273 | return; | |
2274 | ||
60a972a6 JM |
2275 | res = nl80211_get_link_signal(drv, &sig); |
2276 | if (res == 0) { | |
7ee35bf3 PS |
2277 | ed.signal_change.current_signal = sig.current_signal; |
2278 | ed.signal_change.current_txrate = sig.current_txrate; | |
2279 | wpa_printf(MSG_DEBUG, "nl80211: Signal: %d dBm txrate: %d", | |
2280 | sig.current_signal, sig.current_txrate); | |
2281 | } | |
2282 | ||
2283 | res = nl80211_get_link_noise(drv, &sig); | |
2284 | if (res == 0) { | |
2285 | ed.signal_change.current_noise = sig.current_noise; | |
2286 | wpa_printf(MSG_DEBUG, "nl80211: Noise: %d dBm", | |
2287 | sig.current_noise); | |
60a972a6 JM |
2288 | } |
2289 | ||
b625473c | 2290 | wpa_supplicant_event(drv->ctx, EVENT_SIGNAL_CHANGE, &ed); |
93910401 JM |
2291 | } |
2292 | ||
2293 | ||
18d2ba08 JM |
2294 | static void nl80211_new_station_event(struct wpa_driver_nl80211_data *drv, |
2295 | struct nlattr **tb) | |
2296 | { | |
2297 | u8 *addr; | |
2298 | union wpa_event_data data; | |
2299 | ||
2300 | if (tb[NL80211_ATTR_MAC] == NULL) | |
2301 | return; | |
2302 | addr = nla_data(tb[NL80211_ATTR_MAC]); | |
2303 | wpa_printf(MSG_DEBUG, "nl80211: New station " MACSTR, MAC2STR(addr)); | |
5f310a9e | 2304 | |
61cbe2ff | 2305 | if (is_ap_interface(drv->nlmode) && drv->device_ap_sme) { |
5f310a9e JM |
2306 | u8 *ies = NULL; |
2307 | size_t ies_len = 0; | |
2308 | if (tb[NL80211_ATTR_IE]) { | |
2309 | ies = nla_data(tb[NL80211_ATTR_IE]); | |
2310 | ies_len = nla_len(tb[NL80211_ATTR_IE]); | |
2311 | } | |
2312 | wpa_hexdump(MSG_DEBUG, "nl80211: Assoc Req IEs", ies, ies_len); | |
2313 | drv_event_assoc(drv->ctx, addr, ies, ies_len, 0); | |
2314 | return; | |
2315 | } | |
2316 | ||
18d2ba08 JM |
2317 | if (drv->nlmode != NL80211_IFTYPE_ADHOC) |
2318 | return; | |
2319 | ||
2320 | os_memset(&data, 0, sizeof(data)); | |
2321 | os_memcpy(data.ibss_rsn_start.peer, addr, ETH_ALEN); | |
2322 | wpa_supplicant_event(drv->ctx, EVENT_IBSS_RSN_START, &data); | |
2323 | } | |
2324 | ||
2325 | ||
ef985058 JM |
2326 | static void nl80211_del_station_event(struct wpa_driver_nl80211_data *drv, |
2327 | struct nlattr **tb) | |
2328 | { | |
2329 | u8 *addr; | |
2330 | union wpa_event_data data; | |
2331 | ||
2332 | if (tb[NL80211_ATTR_MAC] == NULL) | |
2333 | return; | |
2334 | addr = nla_data(tb[NL80211_ATTR_MAC]); | |
2335 | wpa_printf(MSG_DEBUG, "nl80211: Delete station " MACSTR, | |
2336 | MAC2STR(addr)); | |
5f310a9e | 2337 | |
61cbe2ff | 2338 | if (is_ap_interface(drv->nlmode) && drv->device_ap_sme) { |
5f310a9e JM |
2339 | drv_event_disassoc(drv->ctx, addr); |
2340 | return; | |
2341 | } | |
2342 | ||
ef985058 JM |
2343 | if (drv->nlmode != NL80211_IFTYPE_ADHOC) |
2344 | return; | |
2345 | ||
2346 | os_memset(&data, 0, sizeof(data)); | |
2347 | os_memcpy(data.ibss_peer_lost.peer, addr, ETH_ALEN); | |
2348 | wpa_supplicant_event(drv->ctx, EVENT_IBSS_PEER_LOST, &data); | |
2349 | } | |
2350 | ||
2351 | ||
b14a210c JB |
2352 | static void nl80211_rekey_offload_event(struct wpa_driver_nl80211_data *drv, |
2353 | struct nlattr **tb) | |
2354 | { | |
2355 | struct nlattr *rekey_info[NUM_NL80211_REKEY_DATA]; | |
2356 | static struct nla_policy rekey_policy[NUM_NL80211_REKEY_DATA] = { | |
2357 | [NL80211_REKEY_DATA_KEK] = { | |
2358 | .minlen = NL80211_KEK_LEN, | |
2359 | .maxlen = NL80211_KEK_LEN, | |
2360 | }, | |
2361 | [NL80211_REKEY_DATA_KCK] = { | |
2362 | .minlen = NL80211_KCK_LEN, | |
2363 | .maxlen = NL80211_KCK_LEN, | |
2364 | }, | |
2365 | [NL80211_REKEY_DATA_REPLAY_CTR] = { | |
2366 | .minlen = NL80211_REPLAY_CTR_LEN, | |
2367 | .maxlen = NL80211_REPLAY_CTR_LEN, | |
2368 | }, | |
2369 | }; | |
2370 | union wpa_event_data data; | |
2371 | ||
2372 | if (!tb[NL80211_ATTR_MAC]) | |
2373 | return; | |
2374 | if (!tb[NL80211_ATTR_REKEY_DATA]) | |
2375 | return; | |
2376 | if (nla_parse_nested(rekey_info, MAX_NL80211_REKEY_DATA, | |
2377 | tb[NL80211_ATTR_REKEY_DATA], rekey_policy)) | |
2378 | return; | |
2379 | if (!rekey_info[NL80211_REKEY_DATA_REPLAY_CTR]) | |
2380 | return; | |
2381 | ||
2382 | os_memset(&data, 0, sizeof(data)); | |
2383 | data.driver_gtk_rekey.bssid = nla_data(tb[NL80211_ATTR_MAC]); | |
2384 | wpa_printf(MSG_DEBUG, "nl80211: Rekey offload event for BSSID " MACSTR, | |
2385 | MAC2STR(data.driver_gtk_rekey.bssid)); | |
2386 | data.driver_gtk_rekey.replay_ctr = | |
2387 | nla_data(rekey_info[NL80211_REKEY_DATA_REPLAY_CTR]); | |
2388 | wpa_hexdump(MSG_DEBUG, "nl80211: Rekey offload - Replay Counter", | |
2389 | data.driver_gtk_rekey.replay_ctr, NL80211_REPLAY_CTR_LEN); | |
2390 | wpa_supplicant_event(drv->ctx, EVENT_DRIVER_GTK_REKEY, &data); | |
2391 | } | |
2392 | ||
2393 | ||
c36d5242 JM |
2394 | static void nl80211_pmksa_candidate_event(struct wpa_driver_nl80211_data *drv, |
2395 | struct nlattr **tb) | |
2396 | { | |
2397 | struct nlattr *cand[NUM_NL80211_PMKSA_CANDIDATE]; | |
2398 | static struct nla_policy cand_policy[NUM_NL80211_PMKSA_CANDIDATE] = { | |
2399 | [NL80211_PMKSA_CANDIDATE_INDEX] = { .type = NLA_U32 }, | |
2400 | [NL80211_PMKSA_CANDIDATE_BSSID] = { | |
2401 | .minlen = ETH_ALEN, | |
2402 | .maxlen = ETH_ALEN, | |
2403 | }, | |
2404 | [NL80211_PMKSA_CANDIDATE_PREAUTH] = { .type = NLA_FLAG }, | |
2405 | }; | |
2406 | union wpa_event_data data; | |
2407 | ||
7d81932d JM |
2408 | wpa_printf(MSG_DEBUG, "nl80211: PMKSA candidate event"); |
2409 | ||
c36d5242 JM |
2410 | if (!tb[NL80211_ATTR_PMKSA_CANDIDATE]) |
2411 | return; | |
2412 | if (nla_parse_nested(cand, MAX_NL80211_PMKSA_CANDIDATE, | |
2413 | tb[NL80211_ATTR_PMKSA_CANDIDATE], cand_policy)) | |
2414 | return; | |
2415 | if (!cand[NL80211_PMKSA_CANDIDATE_INDEX] || | |
2416 | !cand[NL80211_PMKSA_CANDIDATE_BSSID]) | |
2417 | return; | |
2418 | ||
2419 | os_memset(&data, 0, sizeof(data)); | |
2420 | os_memcpy(data.pmkid_candidate.bssid, | |
2421 | nla_data(cand[NL80211_PMKSA_CANDIDATE_BSSID]), ETH_ALEN); | |
2422 | data.pmkid_candidate.index = | |
2423 | nla_get_u32(cand[NL80211_PMKSA_CANDIDATE_INDEX]); | |
2424 | data.pmkid_candidate.preauth = | |
2425 | cand[NL80211_PMKSA_CANDIDATE_PREAUTH] != NULL; | |
2426 | wpa_supplicant_event(drv->ctx, EVENT_PMKID_CANDIDATE, &data); | |
2427 | } | |
2428 | ||
2429 | ||
39718852 JB |
2430 | static void nl80211_client_probe_event(struct wpa_driver_nl80211_data *drv, |
2431 | struct nlattr **tb) | |
2432 | { | |
2433 | union wpa_event_data data; | |
2434 | ||
7d81932d JM |
2435 | wpa_printf(MSG_DEBUG, "nl80211: Probe client event"); |
2436 | ||
39718852 JB |
2437 | if (!tb[NL80211_ATTR_MAC] || !tb[NL80211_ATTR_ACK]) |
2438 | return; | |
2439 | ||
2440 | os_memset(&data, 0, sizeof(data)); | |
2441 | os_memcpy(data.client_poll.addr, | |
2442 | nla_data(tb[NL80211_ATTR_MAC]), ETH_ALEN); | |
2443 | ||
2444 | wpa_supplicant_event(drv->ctx, EVENT_DRIVER_CLIENT_POLL_OK, &data); | |
2445 | } | |
2446 | ||
2447 | ||
6201b052 JM |
2448 | static void nl80211_tdls_oper_event(struct wpa_driver_nl80211_data *drv, |
2449 | struct nlattr **tb) | |
2450 | { | |
2451 | union wpa_event_data data; | |
2452 | ||
2453 | wpa_printf(MSG_DEBUG, "nl80211: TDLS operation event"); | |
2454 | ||
2455 | if (!tb[NL80211_ATTR_MAC] || !tb[NL80211_ATTR_TDLS_OPERATION]) | |
2456 | return; | |
2457 | ||
2458 | os_memset(&data, 0, sizeof(data)); | |
2459 | os_memcpy(data.tdls.peer, nla_data(tb[NL80211_ATTR_MAC]), ETH_ALEN); | |
2460 | switch (nla_get_u8(tb[NL80211_ATTR_TDLS_OPERATION])) { | |
2461 | case NL80211_TDLS_SETUP: | |
2462 | wpa_printf(MSG_DEBUG, "nl80211: TDLS setup request for peer " | |
2463 | MACSTR, MAC2STR(data.tdls.peer)); | |
2464 | data.tdls.oper = TDLS_REQUEST_SETUP; | |
2465 | break; | |
2466 | case NL80211_TDLS_TEARDOWN: | |
2467 | wpa_printf(MSG_DEBUG, "nl80211: TDLS teardown request for peer " | |
2468 | MACSTR, MAC2STR(data.tdls.peer)); | |
2469 | data.tdls.oper = TDLS_REQUEST_TEARDOWN; | |
2470 | break; | |
2471 | default: | |
2472 | wpa_printf(MSG_DEBUG, "nl80211: Unsupported TDLS operatione " | |
2473 | "event"); | |
2474 | return; | |
2475 | } | |
2476 | if (tb[NL80211_ATTR_REASON_CODE]) { | |
2477 | data.tdls.reason_code = | |
2478 | nla_get_u16(tb[NL80211_ATTR_REASON_CODE]); | |
2479 | } | |
2480 | ||
2481 | wpa_supplicant_event(drv->ctx, EVENT_TDLS, &data); | |
2482 | } | |
2483 | ||
2484 | ||
7239ea7f ST |
2485 | static void nl80211_stop_ap(struct wpa_driver_nl80211_data *drv, |
2486 | struct nlattr **tb) | |
2487 | { | |
2488 | wpa_supplicant_event(drv->ctx, EVENT_INTERFACE_UNAVAILABLE, NULL); | |
2489 | } | |
2490 | ||
2491 | ||
3140803b RM |
2492 | static void nl80211_connect_failed_event(struct wpa_driver_nl80211_data *drv, |
2493 | struct nlattr **tb) | |
2494 | { | |
2495 | union wpa_event_data data; | |
2496 | u32 reason; | |
2497 | ||
2498 | wpa_printf(MSG_DEBUG, "nl80211: Connect failed event"); | |
2499 | ||
2500 | if (!tb[NL80211_ATTR_MAC] || !tb[NL80211_ATTR_CONN_FAILED_REASON]) | |
2501 | return; | |
2502 | ||
2503 | os_memset(&data, 0, sizeof(data)); | |
2504 | os_memcpy(data.connect_failed_reason.addr, | |
2505 | nla_data(tb[NL80211_ATTR_MAC]), ETH_ALEN); | |
2506 | ||
2507 | reason = nla_get_u32(tb[NL80211_ATTR_CONN_FAILED_REASON]); | |
2508 | switch (reason) { | |
2509 | case NL80211_CONN_FAIL_MAX_CLIENTS: | |
2510 | wpa_printf(MSG_DEBUG, "nl80211: Max client reached"); | |
2511 | data.connect_failed_reason.code = MAX_CLIENT_REACHED; | |
2512 | break; | |
2513 | case NL80211_CONN_FAIL_BLOCKED_CLIENT: | |
2514 | wpa_printf(MSG_DEBUG, "nl80211: Blocked client " MACSTR | |
2515 | " tried to connect", | |
2516 | MAC2STR(data.connect_failed_reason.addr)); | |
2517 | data.connect_failed_reason.code = BLOCKED_CLIENT; | |
2518 | break; | |
2519 | default: | |
2520 | wpa_printf(MSG_DEBUG, "nl8021l: Unknown connect failed reason " | |
2521 | "%u", reason); | |
2522 | return; | |
2523 | } | |
2524 | ||
2525 | wpa_supplicant_event(drv->ctx, EVENT_CONNECT_FAILED_REASON, &data); | |
2526 | } | |
2527 | ||
2528 | ||
846de15d JD |
2529 | static enum chan_width convert2width(int width); |
2530 | ||
04be54fa SW |
2531 | static void nl80211_radar_event(struct wpa_driver_nl80211_data *drv, |
2532 | struct nlattr **tb) | |
2533 | { | |
2534 | union wpa_event_data data; | |
2535 | enum nl80211_radar_event event_type; | |
2536 | ||
2537 | if (!tb[NL80211_ATTR_WIPHY_FREQ] || !tb[NL80211_ATTR_RADAR_EVENT]) | |
2538 | return; | |
2539 | ||
2540 | os_memset(&data, 0, sizeof(data)); | |
cd3b0700 MK |
2541 | data.dfs_event.freq = nla_get_u32(tb[NL80211_ATTR_WIPHY_FREQ]); |
2542 | event_type = nla_get_u32(tb[NL80211_ATTR_RADAR_EVENT]); | |
04be54fa | 2543 | |
846de15d JD |
2544 | /* Check HT params */ |
2545 | if (tb[NL80211_ATTR_WIPHY_CHANNEL_TYPE]) { | |
2546 | data.dfs_event.ht_enabled = 1; | |
2547 | data.dfs_event.chan_offset = 0; | |
2548 | ||
2549 | switch (nla_get_u32(tb[NL80211_ATTR_WIPHY_CHANNEL_TYPE])) { | |
2550 | case NL80211_CHAN_NO_HT: | |
2551 | data.dfs_event.ht_enabled = 0; | |
2552 | break; | |
2553 | case NL80211_CHAN_HT20: | |
2554 | break; | |
2555 | case NL80211_CHAN_HT40PLUS: | |
2556 | data.dfs_event.chan_offset = 1; | |
2557 | break; | |
2558 | case NL80211_CHAN_HT40MINUS: | |
2559 | data.dfs_event.chan_offset = -1; | |
2560 | break; | |
2561 | } | |
2562 | } | |
2563 | ||
2564 | /* Get VHT params */ | |
2565 | data.dfs_event.chan_width = | |
2566 | convert2width(nla_get_u32(tb[NL80211_ATTR_CHANNEL_WIDTH])); | |
2567 | data.dfs_event.cf1 = nla_get_u32(tb[NL80211_ATTR_CENTER_FREQ1]); | |
2568 | if (tb[NL80211_ATTR_CENTER_FREQ2]) | |
2569 | data.dfs_event.cf2 = nla_get_u32(tb[NL80211_ATTR_CENTER_FREQ2]); | |
2570 | ||
2571 | wpa_printf(MSG_DEBUG, "nl80211: DFS event on freq %d MHz, ht: %d, offset: %d, width: %d, cf1: %dMHz, cf2: %dMHz", | |
2572 | data.dfs_event.freq, data.dfs_event.ht_enabled, | |
2573 | data.dfs_event.chan_offset, data.dfs_event.chan_width, | |
2574 | data.dfs_event.cf1, data.dfs_event.cf2); | |
04be54fa SW |
2575 | |
2576 | switch (event_type) { | |
2577 | case NL80211_RADAR_DETECTED: | |
2578 | wpa_supplicant_event(drv->ctx, EVENT_DFS_RADAR_DETECTED, &data); | |
2579 | break; | |
2580 | case NL80211_RADAR_CAC_FINISHED: | |
2581 | wpa_supplicant_event(drv->ctx, EVENT_DFS_CAC_FINISHED, &data); | |
2582 | break; | |
2583 | case NL80211_RADAR_CAC_ABORTED: | |
2584 | wpa_supplicant_event(drv->ctx, EVENT_DFS_CAC_ABORTED, &data); | |
2585 | break; | |
2586 | case NL80211_RADAR_NOP_FINISHED: | |
2587 | wpa_supplicant_event(drv->ctx, EVENT_DFS_NOP_FINISHED, &data); | |
2588 | break; | |
2589 | default: | |
2590 | wpa_printf(MSG_DEBUG, "nl80211: Unknown radar event %d " | |
2591 | "received", event_type); | |
2592 | break; | |
2593 | } | |
2594 | } | |
2595 | ||
2596 | ||
3088e4e5 JB |
2597 | static void nl80211_spurious_frame(struct i802_bss *bss, struct nlattr **tb, |
2598 | int wds) | |
02bb32c3 JB |
2599 | { |
2600 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
2601 | union wpa_event_data event; | |
02bb32c3 JB |
2602 | |
2603 | if (!tb[NL80211_ATTR_MAC]) | |
2604 | return; | |
2605 | ||
02bb32c3 | 2606 | os_memset(&event, 0, sizeof(event)); |
341eebee | 2607 | event.rx_from_unknown.bssid = bss->addr; |
02bb32c3 | 2608 | event.rx_from_unknown.addr = nla_data(tb[NL80211_ATTR_MAC]); |
3088e4e5 | 2609 | event.rx_from_unknown.wds = wds; |
02bb32c3 JB |
2610 | |
2611 | wpa_supplicant_event(drv->ctx, EVENT_RX_FROM_UNKNOWN, &event); | |
2612 | } | |
2613 | ||
2614 | ||
a5e1eb20 SE |
2615 | static void do_process_drv_event(struct i802_bss *bss, int cmd, |
2616 | struct nlattr **tb) | |
97865538 | 2617 | { |
a5e1eb20 SE |
2618 | struct wpa_driver_nl80211_data *drv = bss->drv; |
2619 | ||
2090a0b4 DS |
2620 | wpa_printf(MSG_DEBUG, "nl80211: Drv Event %d (%s) received for %s", |
2621 | cmd, nl80211_command_to_string(cmd), bss->ifname); | |
2622 | ||
b1f625e0 | 2623 | if (drv->ap_scan_as_station != NL80211_IFTYPE_UNSPECIFIED && |
d6c9aab8 JB |
2624 | (cmd == NL80211_CMD_NEW_SCAN_RESULTS || |
2625 | cmd == NL80211_CMD_SCAN_ABORTED)) { | |
a2e40bb6 | 2626 | wpa_driver_nl80211_set_mode(&drv->first_bss, |
b1f625e0 EP |
2627 | drv->ap_scan_as_station); |
2628 | drv->ap_scan_as_station = NL80211_IFTYPE_UNSPECIFIED; | |
ad1e68e6 JM |
2629 | } |
2630 | ||
d6c9aab8 | 2631 | switch (cmd) { |
d942a79e | 2632 | case NL80211_CMD_TRIGGER_SCAN: |
565110cd | 2633 | wpa_dbg(drv->ctx, MSG_DEBUG, "nl80211: Scan trigger"); |
a771c07d | 2634 | drv->scan_state = SCAN_STARTED; |
d942a79e | 2635 | break; |
d21c63b9 | 2636 | case NL80211_CMD_START_SCHED_SCAN: |
565110cd | 2637 | wpa_dbg(drv->ctx, MSG_DEBUG, "nl80211: Sched scan started"); |
a771c07d | 2638 | drv->scan_state = SCHED_SCAN_STARTED; |
d21c63b9 LC |
2639 | break; |
2640 | case NL80211_CMD_SCHED_SCAN_STOPPED: | |
565110cd | 2641 | wpa_dbg(drv->ctx, MSG_DEBUG, "nl80211: Sched scan stopped"); |
a771c07d | 2642 | drv->scan_state = SCHED_SCAN_STOPPED; |
d21c63b9 LC |
2643 | wpa_supplicant_event(drv->ctx, EVENT_SCHED_SCAN_STOPPED, NULL); |
2644 | break; | |
97865538 | 2645 | case NL80211_CMD_NEW_SCAN_RESULTS: |
565110cd JM |
2646 | wpa_dbg(drv->ctx, MSG_DEBUG, |
2647 | "nl80211: New scan results available"); | |
a771c07d | 2648 | drv->scan_state = SCAN_COMPLETED; |
97865538 JM |
2649 | drv->scan_complete_events = 1; |
2650 | eloop_cancel_timeout(wpa_driver_nl80211_scan_timeout, drv, | |
2651 | drv->ctx); | |
8d923a4a | 2652 | send_scan_event(drv, 0, tb); |
97865538 | 2653 | break; |
d21c63b9 | 2654 | case NL80211_CMD_SCHED_SCAN_RESULTS: |
565110cd JM |
2655 | wpa_dbg(drv->ctx, MSG_DEBUG, |
2656 | "nl80211: New sched scan results available"); | |
a771c07d | 2657 | drv->scan_state = SCHED_SCAN_RESULTS; |
d21c63b9 LC |
2658 | send_scan_event(drv, 0, tb); |
2659 | break; | |
97865538 | 2660 | case NL80211_CMD_SCAN_ABORTED: |
565110cd | 2661 | wpa_dbg(drv->ctx, MSG_DEBUG, "nl80211: Scan aborted"); |
a771c07d | 2662 | drv->scan_state = SCAN_ABORTED; |
97865538 JM |
2663 | /* |
2664 | * Need to indicate that scan results are available in order | |
2665 | * not to make wpa_supplicant stop its scanning. | |
2666 | */ | |
2667 | eloop_cancel_timeout(wpa_driver_nl80211_scan_timeout, drv, | |
2668 | drv->ctx); | |
8d923a4a | 2669 | send_scan_event(drv, 1, tb); |
97865538 | 2670 | break; |
c2a04078 JM |
2671 | case NL80211_CMD_AUTHENTICATE: |
2672 | case NL80211_CMD_ASSOCIATE: | |
2673 | case NL80211_CMD_DEAUTHENTICATE: | |
2674 | case NL80211_CMD_DISASSOCIATE: | |
bd94971e | 2675 | case NL80211_CMD_FRAME_TX_STATUS: |
7d878ca7 JM |
2676 | case NL80211_CMD_UNPROT_DEAUTHENTICATE: |
2677 | case NL80211_CMD_UNPROT_DISASSOCIATE: | |
97279d8d | 2678 | mlme_event(bss, cmd, tb[NL80211_ATTR_FRAME], |
58f6fbe0 JM |
2679 | tb[NL80211_ATTR_MAC], tb[NL80211_ATTR_TIMED_OUT], |
2680 | tb[NL80211_ATTR_WIPHY_FREQ], tb[NL80211_ATTR_ACK], | |
da873dbb JB |
2681 | tb[NL80211_ATTR_COOKIE], |
2682 | tb[NL80211_ATTR_RX_SIGNAL_DBM]); | |
c2a04078 | 2683 | break; |
da72a1c1 ZY |
2684 | case NL80211_CMD_CONNECT: |
2685 | case NL80211_CMD_ROAM: | |
d6c9aab8 | 2686 | mlme_event_connect(drv, cmd, |
da72a1c1 ZY |
2687 | tb[NL80211_ATTR_STATUS_CODE], |
2688 | tb[NL80211_ATTR_MAC], | |
2689 | tb[NL80211_ATTR_REQ_IE], | |
2690 | tb[NL80211_ATTR_RESP_IE]); | |
2691 | break; | |
1b487b8b TP |
2692 | case NL80211_CMD_CH_SWITCH_NOTIFY: |
2693 | mlme_event_ch_switch(drv, tb[NL80211_ATTR_WIPHY_FREQ], | |
2694 | tb[NL80211_ATTR_WIPHY_CHANNEL_TYPE]); | |
2695 | break; | |
da72a1c1 | 2696 | case NL80211_CMD_DISCONNECT: |
20f5a4c2 | 2697 | mlme_event_disconnect(drv, tb[NL80211_ATTR_REASON_CODE], |
3d9975d5 JM |
2698 | tb[NL80211_ATTR_MAC], |
2699 | tb[NL80211_ATTR_DISCONNECTED_BY_AP]); | |
da72a1c1 | 2700 | break; |
35583f3f | 2701 | case NL80211_CMD_MICHAEL_MIC_FAILURE: |
a5e1eb20 | 2702 | mlme_event_michael_mic_failure(bss, tb); |
35583f3f | 2703 | break; |
5cc4d64b JM |
2704 | case NL80211_CMD_JOIN_IBSS: |
2705 | mlme_event_join_ibss(drv, tb); | |
2706 | break; | |
55777702 JM |
2707 | case NL80211_CMD_REMAIN_ON_CHANNEL: |
2708 | mlme_event_remain_on_channel(drv, 0, tb); | |
2709 | break; | |
2710 | case NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL: | |
2711 | mlme_event_remain_on_channel(drv, 1, tb); | |
2712 | break; | |
93910401 JM |
2713 | case NL80211_CMD_NOTIFY_CQM: |
2714 | nl80211_cqm_event(drv, tb); | |
2715 | break; | |
33c5deb8 JM |
2716 | case NL80211_CMD_REG_CHANGE: |
2717 | wpa_printf(MSG_DEBUG, "nl80211: Regulatory domain change"); | |
2718 | wpa_supplicant_event(drv->ctx, EVENT_CHANNEL_LIST_CHANGED, | |
2719 | NULL); | |
2720 | break; | |
2721 | case NL80211_CMD_REG_BEACON_HINT: | |
2722 | wpa_printf(MSG_DEBUG, "nl80211: Regulatory beacon hint"); | |
2723 | wpa_supplicant_event(drv->ctx, EVENT_CHANNEL_LIST_CHANGED, | |
2724 | NULL); | |
2725 | break; | |
18d2ba08 JM |
2726 | case NL80211_CMD_NEW_STATION: |
2727 | nl80211_new_station_event(drv, tb); | |
2728 | break; | |
ef985058 JM |
2729 | case NL80211_CMD_DEL_STATION: |
2730 | nl80211_del_station_event(drv, tb); | |
2731 | break; | |
b14a210c JB |
2732 | case NL80211_CMD_SET_REKEY_OFFLOAD: |
2733 | nl80211_rekey_offload_event(drv, tb); | |
2734 | break; | |
c36d5242 JM |
2735 | case NL80211_CMD_PMKSA_CANDIDATE: |
2736 | nl80211_pmksa_candidate_event(drv, tb); | |
2737 | break; | |
39718852 JB |
2738 | case NL80211_CMD_PROBE_CLIENT: |
2739 | nl80211_client_probe_event(drv, tb); | |
2740 | break; | |
6201b052 JM |
2741 | case NL80211_CMD_TDLS_OPER: |
2742 | nl80211_tdls_oper_event(drv, tb); | |
2743 | break; | |
3140803b RM |
2744 | case NL80211_CMD_CONN_FAILED: |
2745 | nl80211_connect_failed_event(drv, tb); | |
2746 | break; | |
6a1ce395 DG |
2747 | case NL80211_CMD_FT_EVENT: |
2748 | mlme_event_ft_event(drv, tb); | |
2749 | break; | |
04be54fa SW |
2750 | case NL80211_CMD_RADAR_DETECT: |
2751 | nl80211_radar_event(drv, tb); | |
2752 | break; | |
7239ea7f ST |
2753 | case NL80211_CMD_STOP_AP: |
2754 | nl80211_stop_ap(drv, tb); | |
2755 | break; | |
97865538 | 2756 | default: |
565110cd JM |
2757 | wpa_dbg(drv->ctx, MSG_DEBUG, "nl80211: Ignored unknown event " |
2758 | "(cmd=%d)", cmd); | |
97865538 JM |
2759 | break; |
2760 | } | |
d6c9aab8 JB |
2761 | } |
2762 | ||
2763 | ||
2764 | static int process_drv_event(struct nl_msg *msg, void *arg) | |
2765 | { | |
2766 | struct wpa_driver_nl80211_data *drv = arg; | |
2767 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); | |
2768 | struct nlattr *tb[NL80211_ATTR_MAX + 1]; | |
a5e1eb20 SE |
2769 | struct i802_bss *bss; |
2770 | int ifidx = -1; | |
d6c9aab8 JB |
2771 | |
2772 | nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), | |
2773 | genlmsg_attrlen(gnlh, 0), NULL); | |
2774 | ||
d3aaef80 | 2775 | if (tb[NL80211_ATTR_IFINDEX]) { |
a5e1eb20 SE |
2776 | ifidx = nla_get_u32(tb[NL80211_ATTR_IFINDEX]); |
2777 | ||
d3aaef80 DS |
2778 | for (bss = &drv->first_bss; bss; bss = bss->next) |
2779 | if (ifidx == -1 || ifidx == bss->ifindex) { | |
2780 | do_process_drv_event(bss, gnlh->cmd, tb); | |
2781 | return NL_SKIP; | |
2782 | } | |
2783 | wpa_printf(MSG_DEBUG, | |
2784 | "nl80211: Ignored event (cmd=%d) for foreign interface (ifindex %d)", | |
2785 | gnlh->cmd, ifidx); | |
2786 | } else if (tb[NL80211_ATTR_WDEV]) { | |
2787 | u64 wdev_id = nla_get_u64(tb[NL80211_ATTR_WDEV]); | |
2788 | wpa_printf(MSG_DEBUG, "nl80211: Process event on P2P device"); | |
2789 | for (bss = &drv->first_bss; bss; bss = bss->next) { | |
2790 | if (bss->wdev_id_set && wdev_id == bss->wdev_id) { | |
2791 | do_process_drv_event(bss, gnlh->cmd, tb); | |
2792 | return NL_SKIP; | |
2793 | } | |
d6c9aab8 | 2794 | } |
d3aaef80 DS |
2795 | wpa_printf(MSG_DEBUG, |
2796 | "nl80211: Ignored event (cmd=%d) for foreign interface (wdev 0x%llx)", | |
2797 | gnlh->cmd, (long long unsigned int) wdev_id); | |
d6c9aab8 JB |
2798 | } |
2799 | ||
d6c9aab8 JB |
2800 | return NL_SKIP; |
2801 | } | |
2802 | ||
2803 | ||
2804 | static int process_global_event(struct nl_msg *msg, void *arg) | |
2805 | { | |
2806 | struct nl80211_global *global = arg; | |
2807 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); | |
2808 | struct nlattr *tb[NL80211_ATTR_MAX + 1]; | |
24b5bd8b | 2809 | struct wpa_driver_nl80211_data *drv, *tmp; |
d6c9aab8 | 2810 | int ifidx = -1; |
a5e1eb20 | 2811 | struct i802_bss *bss; |
54d4ba42 | 2812 | u64 wdev_id = 0; |
d3aaef80 | 2813 | int wdev_id_set = 0; |
d6c9aab8 JB |
2814 | |
2815 | nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), | |
2816 | genlmsg_attrlen(gnlh, 0), NULL); | |
2817 | ||
2818 | if (tb[NL80211_ATTR_IFINDEX]) | |
2819 | ifidx = nla_get_u32(tb[NL80211_ATTR_IFINDEX]); | |
d3aaef80 DS |
2820 | else if (tb[NL80211_ATTR_WDEV]) { |
2821 | wdev_id = nla_get_u64(tb[NL80211_ATTR_WDEV]); | |
2822 | wdev_id_set = 1; | |
2823 | } | |
d6c9aab8 | 2824 | |
24b5bd8b JB |
2825 | dl_list_for_each_safe(drv, tmp, &global->interfaces, |
2826 | struct wpa_driver_nl80211_data, list) { | |
a5e1eb20 | 2827 | for (bss = &drv->first_bss; bss; bss = bss->next) { |
d3aaef80 DS |
2828 | if ((ifidx == -1 && !wdev_id_set) || |
2829 | ifidx == bss->ifindex || | |
2830 | (wdev_id_set && bss->wdev_id_set && | |
2831 | wdev_id == bss->wdev_id)) { | |
a5e1eb20 SE |
2832 | do_process_drv_event(bss, gnlh->cmd, tb); |
2833 | return NL_SKIP; | |
2834 | } | |
2835 | } | |
d6c9aab8 | 2836 | } |
97865538 JM |
2837 | |
2838 | return NL_SKIP; | |
2839 | } | |
2840 | ||
2841 | ||
cc7a48d1 JB |
2842 | static int process_bss_event(struct nl_msg *msg, void *arg) |
2843 | { | |
a11241fa | 2844 | struct i802_bss *bss = arg; |
cc7a48d1 JB |
2845 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); |
2846 | struct nlattr *tb[NL80211_ATTR_MAX + 1]; | |
2847 | ||
2848 | nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), | |
2849 | genlmsg_attrlen(gnlh, 0), NULL); | |
2850 | ||
2090a0b4 DS |
2851 | wpa_printf(MSG_DEBUG, "nl80211: BSS Event %d (%s) received for %s", |
2852 | gnlh->cmd, nl80211_command_to_string(gnlh->cmd), | |
2853 | bss->ifname); | |
2854 | ||
cc7a48d1 | 2855 | switch (gnlh->cmd) { |
a11241fa JB |
2856 | case NL80211_CMD_FRAME: |
2857 | case NL80211_CMD_FRAME_TX_STATUS: | |
97279d8d | 2858 | mlme_event(bss, gnlh->cmd, tb[NL80211_ATTR_FRAME], |
a11241fa JB |
2859 | tb[NL80211_ATTR_MAC], tb[NL80211_ATTR_TIMED_OUT], |
2860 | tb[NL80211_ATTR_WIPHY_FREQ], tb[NL80211_ATTR_ACK], | |
da873dbb JB |
2861 | tb[NL80211_ATTR_COOKIE], |
2862 | tb[NL80211_ATTR_RX_SIGNAL_DBM]); | |
a11241fa | 2863 | break; |
02bb32c3 | 2864 | case NL80211_CMD_UNEXPECTED_FRAME: |
3088e4e5 JB |
2865 | nl80211_spurious_frame(bss, tb, 0); |
2866 | break; | |
2867 | case NL80211_CMD_UNEXPECTED_4ADDR_FRAME: | |
2868 | nl80211_spurious_frame(bss, tb, 1); | |
02bb32c3 | 2869 | break; |
cc7a48d1 JB |
2870 | default: |
2871 | wpa_printf(MSG_DEBUG, "nl80211: Ignored unknown event " | |
2872 | "(cmd=%d)", gnlh->cmd); | |
2873 | break; | |
2874 | } | |
2875 | ||
2876 | return NL_SKIP; | |
2877 | } | |
2878 | ||
2879 | ||
97865538 | 2880 | static void wpa_driver_nl80211_event_receive(int sock, void *eloop_ctx, |
5582a5d1 | 2881 | void *handle) |
97865538 | 2882 | { |
a4ae123c | 2883 | struct nl_cb *cb = eloop_ctx; |
34068ac3 | 2884 | int res; |
97865538 | 2885 | |
cc2ada86 | 2886 | wpa_printf(MSG_MSGDUMP, "nl80211: Event message available"); |
97865538 | 2887 | |
34068ac3 JM |
2888 | res = nl_recvmsgs(handle, cb); |
2889 | if (res) { | |
2890 | wpa_printf(MSG_INFO, "nl80211: %s->nl_recvmsgs failed: %d", | |
2891 | __func__, res); | |
2892 | } | |
97865538 JM |
2893 | } |
2894 | ||
2895 | ||
6d158490 LR |
2896 | /** |
2897 | * wpa_driver_nl80211_set_country - ask nl80211 to set the regulatory domain | |
2898 | * @priv: driver_nl80211 private data | |
2899 | * @alpha2_arg: country to which to switch to | |
2900 | * Returns: 0 on success, -1 on failure | |
2901 | * | |
2902 | * This asks nl80211 to set the regulatory domain for given | |
2903 | * country ISO / IEC alpha2. | |
2904 | */ | |
2905 | static int wpa_driver_nl80211_set_country(void *priv, const char *alpha2_arg) | |
2906 | { | |
a2e40bb6 FF |
2907 | struct i802_bss *bss = priv; |
2908 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
6d158490 LR |
2909 | char alpha2[3]; |
2910 | struct nl_msg *msg; | |
2911 | ||
2912 | msg = nlmsg_alloc(); | |
2913 | if (!msg) | |
e785c2ba | 2914 | return -ENOMEM; |
6d158490 LR |
2915 | |
2916 | alpha2[0] = alpha2_arg[0]; | |
2917 | alpha2[1] = alpha2_arg[1]; | |
2918 | alpha2[2] = '\0'; | |
2919 | ||
9fb04070 | 2920 | nl80211_cmd(drv, msg, 0, NL80211_CMD_REQ_SET_REG); |
6d158490 LR |
2921 | |
2922 | NLA_PUT_STRING(msg, NL80211_ATTR_REG_ALPHA2, alpha2); | |
2923 | if (send_and_recv_msgs(drv, msg, NULL, NULL)) | |
2924 | return -EINVAL; | |
2925 | return 0; | |
2926 | nla_put_failure: | |
5883168a | 2927 | nlmsg_free(msg); |
6d158490 LR |
2928 | return -EINVAL; |
2929 | } | |
2930 | ||
2931 | ||
43245552 DJ |
2932 | static int protocol_feature_handler(struct nl_msg *msg, void *arg) |
2933 | { | |
2934 | u32 *feat = arg; | |
2935 | struct nlattr *tb_msg[NL80211_ATTR_MAX + 1]; | |
2936 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); | |
2937 | ||
2938 | nla_parse(tb_msg, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), | |
2939 | genlmsg_attrlen(gnlh, 0), NULL); | |
2940 | ||
2941 | if (tb_msg[NL80211_ATTR_PROTOCOL_FEATURES]) | |
2942 | *feat = nla_get_u32(tb_msg[NL80211_ATTR_PROTOCOL_FEATURES]); | |
2943 | ||
2944 | return NL_SKIP; | |
2945 | } | |
2946 | ||
2947 | ||
2948 | static u32 get_nl80211_protocol_features(struct wpa_driver_nl80211_data *drv) | |
2949 | { | |
2950 | u32 feat = 0; | |
2951 | struct nl_msg *msg; | |
2952 | ||
2953 | msg = nlmsg_alloc(); | |
2954 | if (!msg) | |
2955 | goto nla_put_failure; | |
2956 | ||
2957 | nl80211_cmd(drv, msg, 0, NL80211_CMD_GET_PROTOCOL_FEATURES); | |
2958 | if (send_and_recv_msgs(drv, msg, protocol_feature_handler, &feat) == 0) | |
2959 | return feat; | |
2960 | ||
2961 | msg = NULL; | |
2962 | nla_put_failure: | |
2963 | nlmsg_free(msg); | |
2964 | return 0; | |
2965 | } | |
2966 | ||
2967 | ||
80bc75f1 | 2968 | struct wiphy_info_data { |
8cd6b7bc | 2969 | struct wpa_driver_nl80211_data *drv; |
e8b5e24e JB |
2970 | struct wpa_driver_capa *capa; |
2971 | ||
4752147d IP |
2972 | unsigned int num_multichan_concurrent; |
2973 | ||
e8b5e24e | 2974 | unsigned int error:1; |
61cbe2ff | 2975 | unsigned int device_ap_sme:1; |
39718852 | 2976 | unsigned int poll_command_supported:1; |
32ab4855 | 2977 | unsigned int data_tx_status:1; |
536062f2 | 2978 | unsigned int monitor_supported:1; |
43245552 DJ |
2979 | unsigned int auth_supported:1; |
2980 | unsigned int connect_supported:1; | |
2981 | unsigned int p2p_go_supported:1; | |
2982 | unsigned int p2p_client_supported:1; | |
2983 | unsigned int p2p_concurrent:1; | |
80bc75f1 JM |
2984 | }; |
2985 | ||
2986 | ||
562c9d97 AN |
2987 | static unsigned int probe_resp_offload_support(int supp_protocols) |
2988 | { | |
2989 | unsigned int prot = 0; | |
2990 | ||
2991 | if (supp_protocols & NL80211_PROBE_RESP_OFFLOAD_SUPPORT_WPS) | |
2992 | prot |= WPA_DRIVER_PROBE_RESP_OFFLOAD_WPS; | |
2993 | if (supp_protocols & NL80211_PROBE_RESP_OFFLOAD_SUPPORT_WPS2) | |
2994 | prot |= WPA_DRIVER_PROBE_RESP_OFFLOAD_WPS2; | |
2995 | if (supp_protocols & NL80211_PROBE_RESP_OFFLOAD_SUPPORT_P2P) | |
2996 | prot |= WPA_DRIVER_PROBE_RESP_OFFLOAD_P2P; | |
2997 | if (supp_protocols & NL80211_PROBE_RESP_OFFLOAD_SUPPORT_80211U) | |
2998 | prot |= WPA_DRIVER_PROBE_RESP_OFFLOAD_INTERWORKING; | |
2999 | ||
3000 | return prot; | |
3001 | } | |
3002 | ||
3003 | ||
5f439107 JM |
3004 | static void wiphy_info_supported_iftypes(struct wiphy_info_data *info, |
3005 | struct nlattr *tb) | |
80bc75f1 | 3006 | { |
5f439107 JM |
3007 | struct nlattr *nl_mode; |
3008 | int i; | |
3009 | ||
3010 | if (tb == NULL) | |
3011 | return; | |
3012 | ||
3013 | nla_for_each_nested(nl_mode, tb, i) { | |
3014 | switch (nla_type(nl_mode)) { | |
3015 | case NL80211_IFTYPE_AP: | |
3016 | info->capa->flags |= WPA_DRIVER_FLAGS_AP; | |
3017 | break; | |
65d52fc1 BR |
3018 | case NL80211_IFTYPE_ADHOC: |
3019 | info->capa->flags |= WPA_DRIVER_FLAGS_IBSS; | |
3020 | break; | |
7aad838c NS |
3021 | case NL80211_IFTYPE_P2P_DEVICE: |
3022 | info->capa->flags |= | |
3023 | WPA_DRIVER_FLAGS_DEDICATED_P2P_DEVICE; | |
3024 | break; | |
5f439107 JM |
3025 | case NL80211_IFTYPE_P2P_GO: |
3026 | info->p2p_go_supported = 1; | |
3027 | break; | |
3028 | case NL80211_IFTYPE_P2P_CLIENT: | |
3029 | info->p2p_client_supported = 1; | |
3030 | break; | |
3031 | case NL80211_IFTYPE_MONITOR: | |
3032 | info->monitor_supported = 1; | |
3033 | break; | |
3034 | } | |
3035 | } | |
3036 | } | |
3037 | ||
3038 | ||
3039 | static int wiphy_info_iface_comb_process(struct wiphy_info_data *info, | |
3040 | struct nlattr *nl_combi) | |
3041 | { | |
3042 | struct nlattr *tb_comb[NUM_NL80211_IFACE_COMB]; | |
3043 | struct nlattr *tb_limit[NUM_NL80211_IFACE_LIMIT]; | |
3044 | struct nlattr *nl_limit, *nl_mode; | |
3045 | int err, rem_limit, rem_mode; | |
3046 | int combination_has_p2p = 0, combination_has_mgd = 0; | |
7626850d JB |
3047 | static struct nla_policy |
3048 | iface_combination_policy[NUM_NL80211_IFACE_COMB] = { | |
3049 | [NL80211_IFACE_COMB_LIMITS] = { .type = NLA_NESTED }, | |
3050 | [NL80211_IFACE_COMB_MAXNUM] = { .type = NLA_U32 }, | |
3051 | [NL80211_IFACE_COMB_STA_AP_BI_MATCH] = { .type = NLA_FLAG }, | |
3052 | [NL80211_IFACE_COMB_NUM_CHANNELS] = { .type = NLA_U32 }, | |
f295d0c8 | 3053 | [NL80211_IFACE_COMB_RADAR_DETECT_WIDTHS] = { .type = NLA_U32 }, |
7626850d JB |
3054 | }, |
3055 | iface_limit_policy[NUM_NL80211_IFACE_LIMIT] = { | |
3056 | [NL80211_IFACE_LIMIT_TYPES] = { .type = NLA_NESTED }, | |
3057 | [NL80211_IFACE_LIMIT_MAX] = { .type = NLA_U32 }, | |
3058 | }; | |
80bc75f1 | 3059 | |
5f439107 JM |
3060 | err = nla_parse_nested(tb_comb, MAX_NL80211_IFACE_COMB, |
3061 | nl_combi, iface_combination_policy); | |
3062 | if (err || !tb_comb[NL80211_IFACE_COMB_LIMITS] || | |
3063 | !tb_comb[NL80211_IFACE_COMB_MAXNUM] || | |
3064 | !tb_comb[NL80211_IFACE_COMB_NUM_CHANNELS]) | |
3065 | return 0; /* broken combination */ | |
3066 | ||
f295d0c8 SW |
3067 | if (tb_comb[NL80211_IFACE_COMB_RADAR_DETECT_WIDTHS]) |
3068 | info->capa->flags |= WPA_DRIVER_FLAGS_RADAR; | |
3069 | ||
5f439107 JM |
3070 | nla_for_each_nested(nl_limit, tb_comb[NL80211_IFACE_COMB_LIMITS], |
3071 | rem_limit) { | |
3072 | err = nla_parse_nested(tb_limit, MAX_NL80211_IFACE_LIMIT, | |
3073 | nl_limit, iface_limit_policy); | |
3074 | if (err || !tb_limit[NL80211_IFACE_LIMIT_TYPES]) | |
3075 | return 0; /* broken combination */ | |
3076 | ||
3077 | nla_for_each_nested(nl_mode, | |
3078 | tb_limit[NL80211_IFACE_LIMIT_TYPES], | |
3079 | rem_mode) { | |
3080 | int ift = nla_type(nl_mode); | |
3081 | if (ift == NL80211_IFTYPE_P2P_GO || | |
3082 | ift == NL80211_IFTYPE_P2P_CLIENT) | |
3083 | combination_has_p2p = 1; | |
3084 | if (ift == NL80211_IFTYPE_STATION) | |
3085 | combination_has_mgd = 1; | |
3086 | } | |
3087 | if (combination_has_p2p && combination_has_mgd) | |
3088 | break; | |
3089 | } | |
3090 | ||
3091 | if (combination_has_p2p && combination_has_mgd) { | |
3092 | info->p2p_concurrent = 1; | |
4752147d IP |
3093 | info->num_multichan_concurrent = |
3094 | nla_get_u32(tb_comb[NL80211_IFACE_COMB_NUM_CHANNELS]); | |
5f439107 JM |
3095 | return 1; |
3096 | } | |
3097 | ||
3098 | return 0; | |
3099 | } | |
3100 | ||
3101 | ||
3102 | static void wiphy_info_iface_comb(struct wiphy_info_data *info, | |
3103 | struct nlattr *tb) | |
3104 | { | |
3105 | struct nlattr *nl_combi; | |
3106 | int rem_combi; | |
3107 | ||
3108 | if (tb == NULL) | |
3109 | return; | |
3110 | ||
3111 | nla_for_each_nested(nl_combi, tb, rem_combi) { | |
3112 | if (wiphy_info_iface_comb_process(info, nl_combi) > 0) | |
3113 | break; | |
3114 | } | |
3115 | } | |
3116 | ||
3117 | ||
3118 | static void wiphy_info_supp_cmds(struct wiphy_info_data *info, | |
3119 | struct nlattr *tb) | |
3120 | { | |
3121 | struct nlattr *nl_cmd; | |
3122 | int i; | |
3123 | ||
3124 | if (tb == NULL) | |
3125 | return; | |
3126 | ||
3127 | nla_for_each_nested(nl_cmd, tb, i) { | |
3128 | switch (nla_get_u32(nl_cmd)) { | |
3129 | case NL80211_CMD_AUTHENTICATE: | |
3130 | info->auth_supported = 1; | |
3131 | break; | |
3132 | case NL80211_CMD_CONNECT: | |
3133 | info->connect_supported = 1; | |
3134 | break; | |
3135 | case NL80211_CMD_START_SCHED_SCAN: | |
3136 | info->capa->sched_scan_supported = 1; | |
3137 | break; | |
3138 | case NL80211_CMD_PROBE_CLIENT: | |
3139 | info->poll_command_supported = 1; | |
3140 | break; | |
3141 | } | |
3142 | } | |
3143 | } | |
3144 | ||
3145 | ||
3146 | static void wiphy_info_max_roc(struct wpa_driver_capa *capa, | |
3147 | struct nlattr *tb) | |
3148 | { | |
5f439107 JM |
3149 | if (tb) |
3150 | capa->max_remain_on_chan = nla_get_u32(tb); | |
3151 | } | |
3152 | ||
3153 | ||
3154 | static void wiphy_info_tdls(struct wpa_driver_capa *capa, struct nlattr *tdls, | |
3155 | struct nlattr *ext_setup) | |
3156 | { | |
3157 | if (tdls == NULL) | |
3158 | return; | |
3159 | ||
3160 | wpa_printf(MSG_DEBUG, "nl80211: TDLS supported"); | |
3161 | capa->flags |= WPA_DRIVER_FLAGS_TDLS_SUPPORT; | |
3162 | ||
3163 | if (ext_setup) { | |
3164 | wpa_printf(MSG_DEBUG, "nl80211: TDLS external setup"); | |
3165 | capa->flags |= WPA_DRIVER_FLAGS_TDLS_EXTERNAL_SETUP; | |
3166 | } | |
3167 | } | |
3168 | ||
3169 | ||
3170 | static void wiphy_info_feature_flags(struct wiphy_info_data *info, | |
3171 | struct nlattr *tb) | |
3172 | { | |
3173 | u32 flags; | |
3174 | struct wpa_driver_capa *capa = info->capa; | |
3175 | ||
3176 | if (tb == NULL) | |
3177 | return; | |
3178 | ||
3179 | flags = nla_get_u32(tb); | |
3180 | ||
3181 | if (flags & NL80211_FEATURE_SK_TX_STATUS) | |
3182 | info->data_tx_status = 1; | |
3183 | ||
3184 | if (flags & NL80211_FEATURE_INACTIVITY_TIMER) | |
3185 | capa->flags |= WPA_DRIVER_FLAGS_INACTIVITY_TIMER; | |
3186 | ||
3187 | if (flags & NL80211_FEATURE_SAE) | |
3188 | capa->flags |= WPA_DRIVER_FLAGS_SAE; | |
3189 | ||
3190 | if (flags & NL80211_FEATURE_NEED_OBSS_SCAN) | |
3191 | capa->flags |= WPA_DRIVER_FLAGS_OBSS_SCAN; | |
3192 | } | |
3193 | ||
3194 | ||
3195 | static void wiphy_info_probe_resp_offload(struct wpa_driver_capa *capa, | |
3196 | struct nlattr *tb) | |
3197 | { | |
3198 | u32 protocols; | |
3199 | ||
3200 | if (tb == NULL) | |
3201 | return; | |
3202 | ||
3203 | protocols = nla_get_u32(tb); | |
3204 | wpa_printf(MSG_DEBUG, "nl80211: Supports Probe Response offload in AP " | |
3205 | "mode"); | |
3206 | capa->flags |= WPA_DRIVER_FLAGS_PROBE_RESP_OFFLOAD; | |
3207 | capa->probe_resp_offloads = probe_resp_offload_support(protocols); | |
3208 | } | |
3209 | ||
3210 | ||
3211 | static int wiphy_info_handler(struct nl_msg *msg, void *arg) | |
3212 | { | |
3213 | struct nlattr *tb[NL80211_ATTR_MAX + 1]; | |
3214 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); | |
3215 | struct wiphy_info_data *info = arg; | |
3216 | struct wpa_driver_capa *capa = info->capa; | |
8cd6b7bc | 3217 | struct wpa_driver_nl80211_data *drv = info->drv; |
5f439107 | 3218 | |
80bc75f1 JM |
3219 | nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), |
3220 | genlmsg_attrlen(gnlh, 0), NULL); | |
3221 | ||
5fbcb45d | 3222 | if (tb[NL80211_ATTR_WIPHY_NAME]) |
24f051eb | 3223 | os_strlcpy(drv->phyname, |
5fbcb45d AS |
3224 | nla_get_string(tb[NL80211_ATTR_WIPHY_NAME]), |
3225 | sizeof(drv->phyname)); | |
80bc75f1 | 3226 | if (tb[NL80211_ATTR_MAX_NUM_SCAN_SSIDS]) |
e8b5e24e | 3227 | capa->max_scan_ssids = |
80bc75f1 JM |
3228 | nla_get_u8(tb[NL80211_ATTR_MAX_NUM_SCAN_SSIDS]); |
3229 | ||
d21c63b9 | 3230 | if (tb[NL80211_ATTR_MAX_NUM_SCHED_SCAN_SSIDS]) |
e8b5e24e | 3231 | capa->max_sched_scan_ssids = |
d21c63b9 LC |
3232 | nla_get_u8(tb[NL80211_ATTR_MAX_NUM_SCHED_SCAN_SSIDS]); |
3233 | ||
bd525934 | 3234 | if (tb[NL80211_ATTR_MAX_MATCH_SETS]) |
e8b5e24e | 3235 | capa->max_match_sets = |
bd525934 LC |
3236 | nla_get_u8(tb[NL80211_ATTR_MAX_MATCH_SETS]); |
3237 | ||
3c4ca363 VN |
3238 | if (tb[NL80211_ATTR_MAC_ACL_MAX]) |
3239 | capa->max_acl_mac_addrs = | |
3240 | nla_get_u8(tb[NL80211_ATTR_MAC_ACL_MAX]); | |
3241 | ||
5f439107 JM |
3242 | wiphy_info_supported_iftypes(info, tb[NL80211_ATTR_SUPPORTED_IFTYPES]); |
3243 | wiphy_info_iface_comb(info, tb[NL80211_ATTR_INTERFACE_COMBINATIONS]); | |
3244 | wiphy_info_supp_cmds(info, tb[NL80211_ATTR_SUPPORTED_COMMANDS]); | |
93d11400 | 3245 | |
e8b5e24e JB |
3246 | if (tb[NL80211_ATTR_OFFCHANNEL_TX_OK]) { |
3247 | wpa_printf(MSG_DEBUG, "nl80211: Using driver-based " | |
3248 | "off-channel TX"); | |
3249 | capa->flags |= WPA_DRIVER_FLAGS_OFFCHANNEL_TX; | |
3250 | } | |
3251 | ||
3252 | if (tb[NL80211_ATTR_ROAM_SUPPORT]) { | |
3253 | wpa_printf(MSG_DEBUG, "nl80211: Using driver-based roaming"); | |
3254 | capa->flags |= WPA_DRIVER_FLAGS_BSS_SELECTION; | |
3255 | } | |
5dfca53f | 3256 | |
5f439107 JM |
3257 | wiphy_info_max_roc(capa, |
3258 | tb[NL80211_ATTR_MAX_REMAIN_ON_CHANNEL_DURATION]); | |
004ba773 | 3259 | |
70619a5d EP |
3260 | if (tb[NL80211_ATTR_SUPPORT_AP_UAPSD]) |
3261 | capa->flags |= WPA_DRIVER_FLAGS_AP_UAPSD; | |
3262 | ||
5f439107 JM |
3263 | wiphy_info_tdls(capa, tb[NL80211_ATTR_TDLS_SUPPORT], |
3264 | tb[NL80211_ATTR_TDLS_EXTERNAL_SETUP]); | |
03ea1786 | 3265 | |
61cbe2ff JB |
3266 | if (tb[NL80211_ATTR_DEVICE_AP_SME]) |
3267 | info->device_ap_sme = 1; | |
3268 | ||
5f439107 JM |
3269 | wiphy_info_feature_flags(info, tb[NL80211_ATTR_FEATURE_FLAGS]); |
3270 | wiphy_info_probe_resp_offload(capa, | |
3271 | tb[NL80211_ATTR_PROBE_RESP_OFFLOAD]); | |
562c9d97 | 3272 | |
8cd6b7bc JB |
3273 | if (tb[NL80211_ATTR_EXT_CAPA] && tb[NL80211_ATTR_EXT_CAPA_MASK] && |
3274 | drv->extended_capa == NULL) { | |
3275 | drv->extended_capa = | |
3276 | os_malloc(nla_len(tb[NL80211_ATTR_EXT_CAPA])); | |
3277 | if (drv->extended_capa) { | |
3278 | os_memcpy(drv->extended_capa, | |
3279 | nla_data(tb[NL80211_ATTR_EXT_CAPA]), | |
3280 | nla_len(tb[NL80211_ATTR_EXT_CAPA])); | |
3281 | drv->extended_capa_len = | |
3282 | nla_len(tb[NL80211_ATTR_EXT_CAPA]); | |
3283 | } | |
3284 | drv->extended_capa_mask = | |
3285 | os_malloc(nla_len(tb[NL80211_ATTR_EXT_CAPA])); | |
3286 | if (drv->extended_capa_mask) { | |
3287 | os_memcpy(drv->extended_capa_mask, | |
3288 | nla_data(tb[NL80211_ATTR_EXT_CAPA]), | |
3289 | nla_len(tb[NL80211_ATTR_EXT_CAPA])); | |
3290 | } else { | |
3291 | os_free(drv->extended_capa); | |
3292 | drv->extended_capa = NULL; | |
3293 | drv->extended_capa_len = 0; | |
3294 | } | |
3295 | } | |
3296 | ||
80bc75f1 JM |
3297 | return NL_SKIP; |
3298 | } | |
3299 | ||
3300 | ||
3301 | static int wpa_driver_nl80211_get_info(struct wpa_driver_nl80211_data *drv, | |
3302 | struct wiphy_info_data *info) | |
3303 | { | |
43245552 | 3304 | u32 feat; |
80bc75f1 JM |
3305 | struct nl_msg *msg; |
3306 | ||
3307 | os_memset(info, 0, sizeof(*info)); | |
e8b5e24e | 3308 | info->capa = &drv->capa; |
8cd6b7bc | 3309 | info->drv = drv; |
89e07afb | 3310 | |
80bc75f1 JM |
3311 | msg = nlmsg_alloc(); |
3312 | if (!msg) | |
3313 | return -1; | |
3314 | ||
43245552 DJ |
3315 | feat = get_nl80211_protocol_features(drv); |
3316 | if (feat & NL80211_PROTOCOL_FEATURE_SPLIT_WIPHY_DUMP) | |
3317 | nl80211_cmd(drv, msg, NLM_F_DUMP, NL80211_CMD_GET_WIPHY); | |
3318 | else | |
3319 | nl80211_cmd(drv, msg, 0, NL80211_CMD_GET_WIPHY); | |
80bc75f1 | 3320 | |
43245552 | 3321 | NLA_PUT_FLAG(msg, NL80211_ATTR_SPLIT_WIPHY_DUMP); |
f632e483 AS |
3322 | if (nl80211_set_iface_id(msg, &drv->first_bss) < 0) |
3323 | goto nla_put_failure; | |
80bc75f1 | 3324 | |
43245552 DJ |
3325 | if (send_and_recv_msgs(drv, msg, wiphy_info_handler, info)) |
3326 | return -1; | |
3327 | ||
3328 | if (info->auth_supported) | |
3329 | drv->capa.flags |= WPA_DRIVER_FLAGS_SME; | |
3330 | else if (!info->connect_supported) { | |
3331 | wpa_printf(MSG_INFO, "nl80211: Driver does not support " | |
3332 | "authentication/association or connect commands"); | |
3333 | info->error = 1; | |
3334 | } | |
3335 | ||
3336 | if (info->p2p_go_supported && info->p2p_client_supported) | |
3337 | drv->capa.flags |= WPA_DRIVER_FLAGS_P2P_CAPABLE; | |
3338 | if (info->p2p_concurrent) { | |
3339 | wpa_printf(MSG_DEBUG, "nl80211: Use separate P2P group " | |
3340 | "interface (driver advertised support)"); | |
3341 | drv->capa.flags |= WPA_DRIVER_FLAGS_P2P_CONCURRENT; | |
3342 | drv->capa.flags |= WPA_DRIVER_FLAGS_P2P_MGMT_AND_NON_P2P; | |
3343 | } | |
4752147d | 3344 | if (info->num_multichan_concurrent > 1) { |
43245552 DJ |
3345 | wpa_printf(MSG_DEBUG, "nl80211: Enable multi-channel " |
3346 | "concurrent (driver advertised support)"); | |
4752147d IP |
3347 | drv->capa.num_multichan_concurrent = |
3348 | info->num_multichan_concurrent; | |
43245552 | 3349 | } |
b691dcb1 IP |
3350 | |
3351 | /* default to 5000 since early versions of mac80211 don't set it */ | |
3352 | if (!drv->capa.max_remain_on_chan) | |
3353 | drv->capa.max_remain_on_chan = 5000; | |
3354 | ||
43245552 | 3355 | return 0; |
80bc75f1 JM |
3356 | nla_put_failure: |
3357 | nlmsg_free(msg); | |
3358 | return -1; | |
3359 | } | |
3360 | ||
3361 | ||
93d11400 | 3362 | static int wpa_driver_nl80211_capa(struct wpa_driver_nl80211_data *drv) |
80bc75f1 JM |
3363 | { |
3364 | struct wiphy_info_data info; | |
3365 | if (wpa_driver_nl80211_get_info(drv, &info)) | |
93d11400 | 3366 | return -1; |
e8b5e24e JB |
3367 | |
3368 | if (info.error) | |
3369 | return -1; | |
3370 | ||
80bc75f1 | 3371 | drv->has_capability = 1; |
1b2a72e8 JM |
3372 | /* For now, assume TKIP, CCMP, WPA, WPA2 are supported */ |
3373 | drv->capa.key_mgmt = WPA_DRIVER_CAPA_KEY_MGMT_WPA | | |
3374 | WPA_DRIVER_CAPA_KEY_MGMT_WPA_PSK | | |
3375 | WPA_DRIVER_CAPA_KEY_MGMT_WPA2 | | |
3376 | WPA_DRIVER_CAPA_KEY_MGMT_WPA2_PSK; | |
3377 | drv->capa.enc = WPA_DRIVER_CAPA_ENC_WEP40 | | |
3378 | WPA_DRIVER_CAPA_ENC_WEP104 | | |
3379 | WPA_DRIVER_CAPA_ENC_TKIP | | |
3380 | WPA_DRIVER_CAPA_ENC_CCMP; | |
291b6068 JM |
3381 | drv->capa.auth = WPA_DRIVER_AUTH_OPEN | |
3382 | WPA_DRIVER_AUTH_SHARED | | |
3383 | WPA_DRIVER_AUTH_LEAP; | |
1b2a72e8 | 3384 | |
871f4dd0 | 3385 | drv->capa.flags |= WPA_DRIVER_FLAGS_SANE_ERROR_CODES; |
0194fedb | 3386 | drv->capa.flags |= WPA_DRIVER_FLAGS_SET_KEYS_AFTER_ASSOC_DONE; |
2fee890a | 3387 | drv->capa.flags |= WPA_DRIVER_FLAGS_EAPOL_TX_STATUS; |
e1bd4e19 | 3388 | |
e5091674 | 3389 | if (!info.device_ap_sme) { |
e1bd4e19 | 3390 | drv->capa.flags |= WPA_DRIVER_FLAGS_DEAUTH_TX_STATUS; |
0194fedb | 3391 | |
e5091674 JM |
3392 | /* |
3393 | * No AP SME is currently assumed to also indicate no AP MLME | |
3394 | * in the driver/firmware. | |
3395 | */ | |
3396 | drv->capa.flags |= WPA_DRIVER_FLAGS_AP_MLME; | |
3397 | } | |
3398 | ||
61cbe2ff | 3399 | drv->device_ap_sme = info.device_ap_sme; |
39718852 | 3400 | drv->poll_command_supported = info.poll_command_supported; |
32ab4855 | 3401 | drv->data_tx_status = info.data_tx_status; |
61cbe2ff | 3402 | |
a11241fa | 3403 | /* |
73a3c6ff FF |
3404 | * If poll command and tx status are supported, mac80211 is new enough |
3405 | * to have everything we need to not need monitor interfaces. | |
a11241fa | 3406 | */ |
73a3c6ff | 3407 | drv->use_monitor = !info.poll_command_supported || !info.data_tx_status; |
a11241fa | 3408 | |
536062f2 JM |
3409 | if (drv->device_ap_sme && drv->use_monitor) { |
3410 | /* | |
3411 | * Non-mac80211 drivers may not support monitor interface. | |
3412 | * Make sure we do not get stuck with incorrect capability here | |
3413 | * by explicitly testing this. | |
3414 | */ | |
3415 | if (!info.monitor_supported) { | |
3416 | wpa_printf(MSG_DEBUG, "nl80211: Disable use_monitor " | |
3417 | "with device_ap_sme since no monitor mode " | |
3418 | "support detected"); | |
3419 | drv->use_monitor = 0; | |
3420 | } | |
3421 | } | |
3422 | ||
a11241fa JB |
3423 | /* |
3424 | * If we aren't going to use monitor interfaces, but the | |
3425 | * driver doesn't support data TX status, we won't get TX | |
3426 | * status for EAPOL frames. | |
3427 | */ | |
3428 | if (!drv->use_monitor && !info.data_tx_status) | |
3429 | drv->capa.flags &= ~WPA_DRIVER_FLAGS_EAPOL_TX_STATUS; | |
3430 | ||
93d11400 | 3431 | return 0; |
80bc75f1 JM |
3432 | } |
3433 | ||
3434 | ||
b088cf82 JM |
3435 | #ifdef ANDROID |
3436 | static int android_genl_ctrl_resolve(struct nl_handle *handle, | |
3437 | const char *name) | |
3438 | { | |
3439 | /* | |
3440 | * Android ICS has very minimal genl_ctrl_resolve() implementation, so | |
3441 | * need to work around that. | |
3442 | */ | |
3443 | struct nl_cache *cache = NULL; | |
3444 | struct genl_family *nl80211 = NULL; | |
3445 | int id = -1; | |
3446 | ||
3447 | if (genl_ctrl_alloc_cache(handle, &cache) < 0) { | |
3448 | wpa_printf(MSG_ERROR, "nl80211: Failed to allocate generic " | |
3449 | "netlink cache"); | |
3450 | goto fail; | |
3451 | } | |
3452 | ||
3453 | nl80211 = genl_ctrl_search_by_name(cache, name); | |
3454 | if (nl80211 == NULL) | |
3455 | goto fail; | |
3456 | ||
3457 | id = genl_family_get_id(nl80211); | |
3458 | ||
3459 | fail: | |
3460 | if (nl80211) | |
3461 | genl_family_put(nl80211); | |
3462 | if (cache) | |
3463 | nl_cache_free(cache); | |
3464 | ||
3465 | return id; | |
3466 | } | |
3467 | #define genl_ctrl_resolve android_genl_ctrl_resolve | |
3468 | #endif /* ANDROID */ | |
3469 | ||
3470 | ||
2a7b66f5 BG |
3471 | static int wpa_driver_nl80211_init_nl_global(struct nl80211_global *global) |
3472 | { | |
d6c9aab8 JB |
3473 | int ret; |
3474 | ||
2a7b66f5 BG |
3475 | global->nl_cb = nl_cb_alloc(NL_CB_DEFAULT); |
3476 | if (global->nl_cb == NULL) { | |
3477 | wpa_printf(MSG_ERROR, "nl80211: Failed to allocate netlink " | |
3478 | "callbacks"); | |
3479 | return -1; | |
3480 | } | |
3481 | ||
481234cf JM |
3482 | global->nl = nl_create_handle(global->nl_cb, "nl"); |
3483 | if (global->nl == NULL) | |
d6c9aab8 | 3484 | goto err; |
276e2d67 | 3485 | |
481234cf | 3486 | global->nl80211_id = genl_ctrl_resolve(global->nl, "nl80211"); |
335d42b1 | 3487 | if (global->nl80211_id < 0) { |
276e2d67 BG |
3488 | wpa_printf(MSG_ERROR, "nl80211: 'nl80211' generic netlink not " |
3489 | "found"); | |
d6c9aab8 | 3490 | goto err; |
276e2d67 BG |
3491 | } |
3492 | ||
481234cf JM |
3493 | global->nl_event = nl_create_handle(global->nl_cb, "event"); |
3494 | if (global->nl_event == NULL) | |
d6c9aab8 | 3495 | goto err; |
9fff9fdc | 3496 | |
d6c9aab8 | 3497 | ret = nl_get_multicast_id(global, "nl80211", "scan"); |
97865538 | 3498 | if (ret >= 0) |
481234cf | 3499 | ret = nl_socket_add_membership(global->nl_event, ret); |
97865538 JM |
3500 | if (ret < 0) { |
3501 | wpa_printf(MSG_ERROR, "nl80211: Could not add multicast " | |
3502 | "membership for scan events: %d (%s)", | |
3503 | ret, strerror(-ret)); | |
d6c9aab8 | 3504 | goto err; |
97865538 | 3505 | } |
c2a04078 | 3506 | |
d6c9aab8 | 3507 | ret = nl_get_multicast_id(global, "nl80211", "mlme"); |
c2a04078 | 3508 | if (ret >= 0) |
481234cf | 3509 | ret = nl_socket_add_membership(global->nl_event, ret); |
c2a04078 JM |
3510 | if (ret < 0) { |
3511 | wpa_printf(MSG_ERROR, "nl80211: Could not add multicast " | |
3512 | "membership for mlme events: %d (%s)", | |
3513 | ret, strerror(-ret)); | |
d6c9aab8 | 3514 | goto err; |
c2a04078 | 3515 | } |
c2a04078 | 3516 | |
d6c9aab8 | 3517 | ret = nl_get_multicast_id(global, "nl80211", "regulatory"); |
33c5deb8 | 3518 | if (ret >= 0) |
481234cf | 3519 | ret = nl_socket_add_membership(global->nl_event, ret); |
33c5deb8 JM |
3520 | if (ret < 0) { |
3521 | wpa_printf(MSG_DEBUG, "nl80211: Could not add multicast " | |
3522 | "membership for regulatory events: %d (%s)", | |
3523 | ret, strerror(-ret)); | |
3524 | /* Continue without regulatory events */ | |
3525 | } | |
3526 | ||
d6c9aab8 JB |
3527 | nl_cb_set(global->nl_cb, NL_CB_SEQ_CHECK, NL_CB_CUSTOM, |
3528 | no_seq_check, NULL); | |
3529 | nl_cb_set(global->nl_cb, NL_CB_VALID, NL_CB_CUSTOM, | |
3530 | process_global_event, global); | |
3531 | ||
5f65e9f7 JB |
3532 | nl80211_register_eloop_read(&global->nl_event, |
3533 | wpa_driver_nl80211_event_receive, | |
3534 | global->nl_cb); | |
d6c9aab8 JB |
3535 | |
3536 | return 0; | |
3537 | ||
3538 | err: | |
3539 | nl_destroy_handles(&global->nl_event); | |
3540 | nl_destroy_handles(&global->nl); | |
3541 | nl_cb_put(global->nl_cb); | |
671a5039 | 3542 | global->nl_cb = NULL; |
d6c9aab8 JB |
3543 | return -1; |
3544 | } | |
3545 | ||
3546 | ||
3547 | static int wpa_driver_nl80211_init_nl(struct wpa_driver_nl80211_data *drv) | |
3548 | { | |
1afc986d JB |
3549 | drv->nl_cb = nl_cb_alloc(NL_CB_DEFAULT); |
3550 | if (!drv->nl_cb) { | |
3551 | wpa_printf(MSG_ERROR, "nl80211: Failed to alloc cb struct"); | |
d6c9aab8 | 3552 | return -1; |
1afc986d JB |
3553 | } |
3554 | ||
3555 | nl_cb_set(drv->nl_cb, NL_CB_SEQ_CHECK, NL_CB_CUSTOM, | |
3556 | no_seq_check, NULL); | |
f06aedd9 JB |
3557 | nl_cb_set(drv->nl_cb, NL_CB_VALID, NL_CB_CUSTOM, |
3558 | process_drv_event, drv); | |
1afc986d | 3559 | |
9fff9fdc | 3560 | return 0; |
9fff9fdc JM |
3561 | } |
3562 | ||
3563 | ||
8401a6b0 JM |
3564 | static void wpa_driver_nl80211_rfkill_blocked(void *ctx) |
3565 | { | |
8401a6b0 | 3566 | wpa_printf(MSG_DEBUG, "nl80211: RFKILL blocked"); |
a63063b4 JM |
3567 | /* |
3568 | * This may be for any interface; use ifdown event to disable | |
3569 | * interface. | |
3570 | */ | |
8401a6b0 JM |
3571 | } |
3572 | ||
3573 | ||
3574 | static void wpa_driver_nl80211_rfkill_unblocked(void *ctx) | |
3575 | { | |
3576 | struct wpa_driver_nl80211_data *drv = ctx; | |
3577 | wpa_printf(MSG_DEBUG, "nl80211: RFKILL unblocked"); | |
bf83eab5 | 3578 | if (i802_set_iface_flags(&drv->first_bss, 1)) { |
8401a6b0 JM |
3579 | wpa_printf(MSG_DEBUG, "nl80211: Could not set interface UP " |
3580 | "after rfkill unblock"); | |
3581 | return; | |
3582 | } | |
a63063b4 | 3583 | /* rtnetlink ifup handler will report interface as enabled */ |
8401a6b0 JM |
3584 | } |
3585 | ||
3586 | ||
32ab4855 JB |
3587 | static void wpa_driver_nl80211_handle_eapol_tx_status(int sock, |
3588 | void *eloop_ctx, | |
3589 | void *handle) | |
3590 | { | |
3591 | struct wpa_driver_nl80211_data *drv = eloop_ctx; | |
3592 | u8 data[2048]; | |
3593 | struct msghdr msg; | |
3594 | struct iovec entry; | |
cad0f50e | 3595 | u8 control[512]; |
32ab4855 JB |
3596 | struct cmsghdr *cmsg; |
3597 | int res, found_ee = 0, found_wifi = 0, acked = 0; | |
3598 | union wpa_event_data event; | |
3599 | ||
3600 | memset(&msg, 0, sizeof(msg)); | |
3601 | msg.msg_iov = &entry; | |
3602 | msg.msg_iovlen = 1; | |
3603 | entry.iov_base = data; | |
3604 | entry.iov_len = sizeof(data); | |
3605 | msg.msg_control = &control; | |
3606 | msg.msg_controllen = sizeof(control); | |
3607 | ||
3608 | res = recvmsg(sock, &msg, MSG_ERRQUEUE); | |
3609 | /* if error or not fitting 802.3 header, return */ | |
3610 | if (res < 14) | |
3611 | return; | |
3612 | ||
3613 | for (cmsg = CMSG_FIRSTHDR(&msg); cmsg; cmsg = CMSG_NXTHDR(&msg, cmsg)) | |
3614 | { | |
3615 | if (cmsg->cmsg_level == SOL_SOCKET && | |
3616 | cmsg->cmsg_type == SCM_WIFI_STATUS) { | |
3617 | int *ack; | |
3618 | ||
3619 | found_wifi = 1; | |
3620 | ack = (void *)CMSG_DATA(cmsg); | |
3621 | acked = *ack; | |
3622 | } | |
3623 | ||
3624 | if (cmsg->cmsg_level == SOL_PACKET && | |
3625 | cmsg->cmsg_type == PACKET_TX_TIMESTAMP) { | |
3626 | struct sock_extended_err *err = | |
3627 | (struct sock_extended_err *)CMSG_DATA(cmsg); | |
3628 | ||
3629 | if (err->ee_origin == SO_EE_ORIGIN_TXSTATUS) | |
3630 | found_ee = 1; | |
3631 | } | |
3632 | } | |
3633 | ||
3634 | if (!found_ee || !found_wifi) | |
3635 | return; | |
3636 | ||
3637 | memset(&event, 0, sizeof(event)); | |
3638 | event.eapol_tx_status.dst = data; | |
3639 | event.eapol_tx_status.data = data + 14; | |
3640 | event.eapol_tx_status.data_len = res - 14; | |
3641 | event.eapol_tx_status.ack = acked; | |
3642 | wpa_supplicant_event(drv->ctx, EVENT_EAPOL_TX_STATUS, &event); | |
3643 | } | |
3644 | ||
3645 | ||
cc7a48d1 JB |
3646 | static int nl80211_init_bss(struct i802_bss *bss) |
3647 | { | |
3648 | bss->nl_cb = nl_cb_alloc(NL_CB_DEFAULT); | |
3649 | if (!bss->nl_cb) | |
3650 | return -1; | |
3651 | ||
3652 | nl_cb_set(bss->nl_cb, NL_CB_SEQ_CHECK, NL_CB_CUSTOM, | |
3653 | no_seq_check, NULL); | |
3654 | nl_cb_set(bss->nl_cb, NL_CB_VALID, NL_CB_CUSTOM, | |
3655 | process_bss_event, bss); | |
3656 | ||
3657 | return 0; | |
3658 | } | |
3659 | ||
3660 | ||
3661 | static void nl80211_destroy_bss(struct i802_bss *bss) | |
3662 | { | |
3663 | nl_cb_put(bss->nl_cb); | |
3664 | bss->nl_cb = NULL; | |
3665 | } | |
3666 | ||
3667 | ||
9fff9fdc JM |
3668 | /** |
3669 | * wpa_driver_nl80211_init - Initialize nl80211 driver interface | |
3670 | * @ctx: context to be used when calling wpa_supplicant functions, | |
3671 | * e.g., wpa_supplicant_event() | |
3672 | * @ifname: interface name, e.g., wlan0 | |
f2ed8023 | 3673 | * @global_priv: private driver global data from global_init() |
9fff9fdc JM |
3674 | * Returns: Pointer to private data, %NULL on failure |
3675 | */ | |
f2ed8023 JM |
3676 | static void * wpa_driver_nl80211_init(void *ctx, const char *ifname, |
3677 | void *global_priv) | |
9fff9fdc | 3678 | { |
9fff9fdc | 3679 | struct wpa_driver_nl80211_data *drv; |
8401a6b0 | 3680 | struct rfkill_config *rcfg; |
a2e40bb6 | 3681 | struct i802_bss *bss; |
9fff9fdc | 3682 | |
a5c696ad JM |
3683 | if (global_priv == NULL) |
3684 | return NULL; | |
9fff9fdc JM |
3685 | drv = os_zalloc(sizeof(*drv)); |
3686 | if (drv == NULL) | |
3687 | return NULL; | |
f2ed8023 | 3688 | drv->global = global_priv; |
9fff9fdc | 3689 | drv->ctx = ctx; |
a2e40bb6 FF |
3690 | bss = &drv->first_bss; |
3691 | bss->drv = drv; | |
a5e1eb20 SE |
3692 | bss->ctx = ctx; |
3693 | ||
a2e40bb6 | 3694 | os_strlcpy(bss->ifname, ifname, sizeof(bss->ifname)); |
9fff9fdc JM |
3695 | drv->monitor_ifidx = -1; |
3696 | drv->monitor_sock = -1; | |
d12dab4c | 3697 | drv->eapol_tx_sock = -1; |
b1f625e0 | 3698 | drv->ap_scan_as_station = NL80211_IFTYPE_UNSPECIFIED; |
9fff9fdc | 3699 | |
ba2d0d7d | 3700 | if (wpa_driver_nl80211_init_nl(drv)) { |
bbaf0837 JM |
3701 | os_free(drv); |
3702 | return NULL; | |
3703 | } | |
9fff9fdc | 3704 | |
cc7a48d1 JB |
3705 | if (nl80211_init_bss(bss)) |
3706 | goto failed; | |
3707 | ||
8401a6b0 JM |
3708 | rcfg = os_zalloc(sizeof(*rcfg)); |
3709 | if (rcfg == NULL) | |
3710 | goto failed; | |
3711 | rcfg->ctx = drv; | |
3712 | os_strlcpy(rcfg->ifname, ifname, sizeof(rcfg->ifname)); | |
3713 | rcfg->blocked_cb = wpa_driver_nl80211_rfkill_blocked; | |
3714 | rcfg->unblocked_cb = wpa_driver_nl80211_rfkill_unblocked; | |
3715 | drv->rfkill = rfkill_init(rcfg); | |
52169389 | 3716 | if (drv->rfkill == NULL) { |
8401a6b0 | 3717 | wpa_printf(MSG_DEBUG, "nl80211: RFKILL status not available"); |
52169389 JM |
3718 | os_free(rcfg); |
3719 | } | |
8401a6b0 | 3720 | |
08063178 | 3721 | if (wpa_driver_nl80211_finish_drv_init(drv)) |
bbaf0837 | 3722 | goto failed; |
7524cfb1 | 3723 | |
d12dab4c | 3724 | drv->eapol_tx_sock = socket(PF_PACKET, SOCK_DGRAM, 0); |
32ab4855 JB |
3725 | if (drv->eapol_tx_sock < 0) |
3726 | goto failed; | |
3727 | ||
3728 | if (drv->data_tx_status) { | |
3729 | int enabled = 1; | |
3730 | ||
3731 | if (setsockopt(drv->eapol_tx_sock, SOL_SOCKET, SO_WIFI_STATUS, | |
3732 | &enabled, sizeof(enabled)) < 0) { | |
3733 | wpa_printf(MSG_DEBUG, | |
3734 | "nl80211: wifi status sockopt failed\n"); | |
3735 | drv->data_tx_status = 0; | |
a11241fa JB |
3736 | if (!drv->use_monitor) |
3737 | drv->capa.flags &= | |
3738 | ~WPA_DRIVER_FLAGS_EAPOL_TX_STATUS; | |
32ab4855 JB |
3739 | } else { |
3740 | eloop_register_read_sock(drv->eapol_tx_sock, | |
3741 | wpa_driver_nl80211_handle_eapol_tx_status, | |
3742 | drv, NULL); | |
3743 | } | |
3744 | } | |
f10bfc9a | 3745 | |
dac12351 | 3746 | if (drv->global) { |
c4bb8817 | 3747 | dl_list_add(&drv->global->interfaces, &drv->list); |
dac12351 BG |
3748 | drv->in_interface_list = 1; |
3749 | } | |
c4bb8817 | 3750 | |
a2e40bb6 | 3751 | return bss; |
7524cfb1 | 3752 | |
bbaf0837 | 3753 | failed: |
dac12351 | 3754 | wpa_driver_nl80211_deinit(bss); |
7524cfb1 JM |
3755 | return NULL; |
3756 | } | |
3757 | ||
3758 | ||
a11241fa | 3759 | static int nl80211_register_frame(struct i802_bss *bss, |
5582a5d1 | 3760 | struct nl_handle *nl_handle, |
bd94971e | 3761 | u16 type, const u8 *match, size_t match_len) |
58f6fbe0 | 3762 | { |
a11241fa | 3763 | struct wpa_driver_nl80211_data *drv = bss->drv; |
58f6fbe0 JM |
3764 | struct nl_msg *msg; |
3765 | int ret = -1; | |
3766 | ||
3767 | msg = nlmsg_alloc(); | |
3768 | if (!msg) | |
3769 | return -1; | |
3770 | ||
36488c05 JM |
3771 | wpa_printf(MSG_DEBUG, "nl80211: Register frame type=0x%x nl_handle=%p", |
3772 | type, nl_handle); | |
3773 | wpa_hexdump(MSG_DEBUG, "nl80211: Register frame match", | |
3774 | match, match_len); | |
3775 | ||
9fb04070 | 3776 | nl80211_cmd(drv, msg, 0, NL80211_CMD_REGISTER_ACTION); |
58f6fbe0 | 3777 | |
f632e483 | 3778 | if (nl80211_set_iface_id(msg, bss) < 0) |
d3aaef80 DS |
3779 | goto nla_put_failure; |
3780 | ||
bd94971e | 3781 | NLA_PUT_U16(msg, NL80211_ATTR_FRAME_TYPE, type); |
58f6fbe0 JM |
3782 | NLA_PUT(msg, NL80211_ATTR_FRAME_MATCH, match_len, match); |
3783 | ||
d6c9aab8 | 3784 | ret = send_and_recv(drv->global, nl_handle, msg, NULL, NULL); |
58f6fbe0 JM |
3785 | msg = NULL; |
3786 | if (ret) { | |
5582a5d1 JB |
3787 | wpa_printf(MSG_DEBUG, "nl80211: Register frame command " |
3788 | "failed (type=%u): ret=%d (%s)", | |
3789 | type, ret, strerror(-ret)); | |
3790 | wpa_hexdump(MSG_DEBUG, "nl80211: Register frame match", | |
58f6fbe0 JM |
3791 | match, match_len); |
3792 | goto nla_put_failure; | |
3793 | } | |
3794 | ret = 0; | |
3795 | nla_put_failure: | |
3796 | nlmsg_free(msg); | |
3797 | return ret; | |
3798 | } | |
3799 | ||
3800 | ||
a11241fa JB |
3801 | static int nl80211_alloc_mgmt_handle(struct i802_bss *bss) |
3802 | { | |
3803 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
3804 | ||
481234cf | 3805 | if (bss->nl_mgmt) { |
a11241fa | 3806 | wpa_printf(MSG_DEBUG, "nl80211: Mgmt reporting " |
36488c05 | 3807 | "already on! (nl_mgmt=%p)", bss->nl_mgmt); |
a11241fa JB |
3808 | return -1; |
3809 | } | |
3810 | ||
481234cf JM |
3811 | bss->nl_mgmt = nl_create_handle(drv->nl_cb, "mgmt"); |
3812 | if (bss->nl_mgmt == NULL) | |
a11241fa JB |
3813 | return -1; |
3814 | ||
a11241fa JB |
3815 | return 0; |
3816 | } | |
3817 | ||
3818 | ||
5f65e9f7 JB |
3819 | static void nl80211_mgmt_handle_register_eloop(struct i802_bss *bss) |
3820 | { | |
3821 | nl80211_register_eloop_read(&bss->nl_mgmt, | |
3822 | wpa_driver_nl80211_event_receive, | |
3823 | bss->nl_cb); | |
3824 | } | |
3825 | ||
3826 | ||
a11241fa | 3827 | static int nl80211_register_action_frame(struct i802_bss *bss, |
bd94971e JB |
3828 | const u8 *match, size_t match_len) |
3829 | { | |
3830 | u16 type = (WLAN_FC_TYPE_MGMT << 2) | (WLAN_FC_STYPE_ACTION << 4); | |
481234cf | 3831 | return nl80211_register_frame(bss, bss->nl_mgmt, |
5582a5d1 | 3832 | type, match, match_len); |
bd94971e JB |
3833 | } |
3834 | ||
3835 | ||
a11241fa | 3836 | static int nl80211_mgmt_subscribe_non_ap(struct i802_bss *bss) |
58f6fbe0 | 3837 | { |
a11241fa JB |
3838 | struct wpa_driver_nl80211_data *drv = bss->drv; |
3839 | ||
3840 | if (nl80211_alloc_mgmt_handle(bss)) | |
3841 | return -1; | |
36488c05 JM |
3842 | wpa_printf(MSG_DEBUG, "nl80211: Subscribe to mgmt frames with non-AP " |
3843 | "handle %p", bss->nl_mgmt); | |
a11241fa | 3844 | |
e8d1168b JB |
3845 | if (drv->nlmode == NL80211_IFTYPE_ADHOC) { |
3846 | u16 type = (WLAN_FC_TYPE_MGMT << 2) | (WLAN_FC_STYPE_AUTH << 4); | |
3847 | ||
3848 | /* register for any AUTH message */ | |
3849 | nl80211_register_frame(bss, bss->nl_mgmt, type, NULL, 0); | |
3850 | } | |
3851 | ||
56f5af48 JM |
3852 | #ifdef CONFIG_INTERWORKING |
3853 | /* QoS Map Configure */ | |
3854 | if (nl80211_register_action_frame(bss, (u8 *) "\x01\x04", 2) < 0) | |
3855 | return -1; | |
3856 | #endif /* CONFIG_INTERWORKING */ | |
4fe9fa0d | 3857 | #if defined(CONFIG_P2P) || defined(CONFIG_INTERWORKING) |
046b26a2 | 3858 | /* GAS Initial Request */ |
a11241fa | 3859 | if (nl80211_register_action_frame(bss, (u8 *) "\x04\x0a", 2) < 0) |
046b26a2 JM |
3860 | return -1; |
3861 | /* GAS Initial Response */ | |
a11241fa | 3862 | if (nl80211_register_action_frame(bss, (u8 *) "\x04\x0b", 2) < 0) |
046b26a2 | 3863 | return -1; |
18708aad | 3864 | /* GAS Comeback Request */ |
a11241fa | 3865 | if (nl80211_register_action_frame(bss, (u8 *) "\x04\x0c", 2) < 0) |
18708aad JM |
3866 | return -1; |
3867 | /* GAS Comeback Response */ | |
a11241fa | 3868 | if (nl80211_register_action_frame(bss, (u8 *) "\x04\x0d", 2) < 0) |
18708aad | 3869 | return -1; |
4fe9fa0d JM |
3870 | #endif /* CONFIG_P2P || CONFIG_INTERWORKING */ |
3871 | #ifdef CONFIG_P2P | |
046b26a2 | 3872 | /* P2P Public Action */ |
a11241fa | 3873 | if (nl80211_register_action_frame(bss, |
046b26a2 JM |
3874 | (u8 *) "\x04\x09\x50\x6f\x9a\x09", |
3875 | 6) < 0) | |
3876 | return -1; | |
3877 | /* P2P Action */ | |
a11241fa | 3878 | if (nl80211_register_action_frame(bss, |
046b26a2 JM |
3879 | (u8 *) "\x7f\x50\x6f\x9a\x09", |
3880 | 5) < 0) | |
3881 | return -1; | |
3882 | #endif /* CONFIG_P2P */ | |
7d878ca7 JM |
3883 | #ifdef CONFIG_IEEE80211W |
3884 | /* SA Query Response */ | |
a11241fa | 3885 | if (nl80211_register_action_frame(bss, (u8 *) "\x08\x01", 2) < 0) |
7d878ca7 JM |
3886 | return -1; |
3887 | #endif /* CONFIG_IEEE80211W */ | |
35287637 AN |
3888 | #ifdef CONFIG_TDLS |
3889 | if ((drv->capa.flags & WPA_DRIVER_FLAGS_TDLS_SUPPORT)) { | |
3890 | /* TDLS Discovery Response */ | |
aa543c0c | 3891 | if (nl80211_register_action_frame(bss, (u8 *) "\x04\x0e", 2) < |
35287637 AN |
3892 | 0) |
3893 | return -1; | |
3894 | } | |
3895 | #endif /* CONFIG_TDLS */ | |
046b26a2 | 3896 | |
7b90c16a | 3897 | /* FT Action frames */ |
a11241fa | 3898 | if (nl80211_register_action_frame(bss, (u8 *) "\x06", 1) < 0) |
7b90c16a JM |
3899 | return -1; |
3900 | else | |
3901 | drv->capa.key_mgmt |= WPA_DRIVER_CAPA_KEY_MGMT_FT | | |
3902 | WPA_DRIVER_CAPA_KEY_MGMT_FT_PSK; | |
3903 | ||
71269b37 | 3904 | /* WNM - BSS Transition Management Request */ |
a11241fa JB |
3905 | if (nl80211_register_action_frame(bss, (u8 *) "\x0a\x07", 2) < 0) |
3906 | return -1; | |
bd896433 JM |
3907 | /* WNM-Sleep Mode Response */ |
3908 | if (nl80211_register_action_frame(bss, (u8 *) "\x0a\x11", 2) < 0) | |
3909 | return -1; | |
a11241fa | 3910 | |
5f65e9f7 JB |
3911 | nl80211_mgmt_handle_register_eloop(bss); |
3912 | ||
a11241fa JB |
3913 | return 0; |
3914 | } | |
3915 | ||
3916 | ||
02bb32c3 JB |
3917 | static int nl80211_register_spurious_class3(struct i802_bss *bss) |
3918 | { | |
3919 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
3920 | struct nl_msg *msg; | |
3921 | int ret = -1; | |
3922 | ||
3923 | msg = nlmsg_alloc(); | |
3924 | if (!msg) | |
3925 | return -1; | |
3926 | ||
3927 | nl80211_cmd(drv, msg, 0, NL80211_CMD_UNEXPECTED_FRAME); | |
3928 | ||
3929 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, bss->ifindex); | |
3930 | ||
481234cf | 3931 | ret = send_and_recv(drv->global, bss->nl_mgmt, msg, NULL, NULL); |
02bb32c3 JB |
3932 | msg = NULL; |
3933 | if (ret) { | |
3934 | wpa_printf(MSG_DEBUG, "nl80211: Register spurious class3 " | |
3935 | "failed: ret=%d (%s)", | |
3936 | ret, strerror(-ret)); | |
3937 | goto nla_put_failure; | |
3938 | } | |
3939 | ret = 0; | |
3940 | nla_put_failure: | |
3941 | nlmsg_free(msg); | |
3942 | return ret; | |
3943 | } | |
3944 | ||
3945 | ||
a11241fa JB |
3946 | static int nl80211_mgmt_subscribe_ap(struct i802_bss *bss) |
3947 | { | |
3948 | static const int stypes[] = { | |
3949 | WLAN_FC_STYPE_AUTH, | |
3950 | WLAN_FC_STYPE_ASSOC_REQ, | |
3951 | WLAN_FC_STYPE_REASSOC_REQ, | |
3952 | WLAN_FC_STYPE_DISASSOC, | |
3953 | WLAN_FC_STYPE_DEAUTH, | |
3954 | WLAN_FC_STYPE_ACTION, | |
3955 | WLAN_FC_STYPE_PROBE_REQ, | |
3956 | /* Beacon doesn't work as mac80211 doesn't currently allow | |
3957 | * it, but it wouldn't really be the right thing anyway as | |
3958 | * it isn't per interface ... maybe just dump the scan | |
3959 | * results periodically for OLBC? | |
3960 | */ | |
3961 | // WLAN_FC_STYPE_BEACON, | |
3962 | }; | |
3963 | unsigned int i; | |
3964 | ||
3965 | if (nl80211_alloc_mgmt_handle(bss)) | |
71269b37 | 3966 | return -1; |
36488c05 JM |
3967 | wpa_printf(MSG_DEBUG, "nl80211: Subscribe to mgmt frames with AP " |
3968 | "handle %p", bss->nl_mgmt); | |
71269b37 | 3969 | |
e7ecab4a | 3970 | for (i = 0; i < ARRAY_SIZE(stypes); i++) { |
481234cf | 3971 | if (nl80211_register_frame(bss, bss->nl_mgmt, |
a11241fa JB |
3972 | (WLAN_FC_TYPE_MGMT << 2) | |
3973 | (stypes[i] << 4), | |
3974 | NULL, 0) < 0) { | |
3975 | goto out_err; | |
3976 | } | |
3977 | } | |
3978 | ||
02bb32c3 JB |
3979 | if (nl80211_register_spurious_class3(bss)) |
3980 | goto out_err; | |
3981 | ||
e32ad281 JB |
3982 | if (nl80211_get_wiphy_data_ap(bss) == NULL) |
3983 | goto out_err; | |
3984 | ||
5f65e9f7 | 3985 | nl80211_mgmt_handle_register_eloop(bss); |
58f6fbe0 | 3986 | return 0; |
a11241fa JB |
3987 | |
3988 | out_err: | |
a11241fa JB |
3989 | nl_destroy_handles(&bss->nl_mgmt); |
3990 | return -1; | |
3991 | } | |
3992 | ||
3993 | ||
a6cc0602 JM |
3994 | static int nl80211_mgmt_subscribe_ap_dev_sme(struct i802_bss *bss) |
3995 | { | |
3996 | if (nl80211_alloc_mgmt_handle(bss)) | |
3997 | return -1; | |
3998 | wpa_printf(MSG_DEBUG, "nl80211: Subscribe to mgmt frames with AP " | |
3999 | "handle %p (device SME)", bss->nl_mgmt); | |
4000 | ||
4001 | if (nl80211_register_frame(bss, bss->nl_mgmt, | |
4002 | (WLAN_FC_TYPE_MGMT << 2) | | |
4003 | (WLAN_FC_STYPE_ACTION << 4), | |
4004 | NULL, 0) < 0) | |
4005 | goto out_err; | |
4006 | ||
5f65e9f7 | 4007 | nl80211_mgmt_handle_register_eloop(bss); |
a6cc0602 JM |
4008 | return 0; |
4009 | ||
4010 | out_err: | |
a6cc0602 JM |
4011 | nl_destroy_handles(&bss->nl_mgmt); |
4012 | return -1; | |
4013 | } | |
4014 | ||
4015 | ||
36488c05 | 4016 | static void nl80211_mgmt_unsubscribe(struct i802_bss *bss, const char *reason) |
a11241fa | 4017 | { |
481234cf | 4018 | if (bss->nl_mgmt == NULL) |
a11241fa | 4019 | return; |
36488c05 JM |
4020 | wpa_printf(MSG_DEBUG, "nl80211: Unsubscribe mgmt frames handle %p " |
4021 | "(%s)", bss->nl_mgmt, reason); | |
5f65e9f7 | 4022 | nl80211_destroy_eloop_handle(&bss->nl_mgmt); |
e32ad281 JB |
4023 | |
4024 | nl80211_put_wiphy_data_ap(bss); | |
58f6fbe0 JM |
4025 | } |
4026 | ||
4027 | ||
8401a6b0 JM |
4028 | static void wpa_driver_nl80211_send_rfkill(void *eloop_ctx, void *timeout_ctx) |
4029 | { | |
4030 | wpa_supplicant_event(timeout_ctx, EVENT_INTERFACE_DISABLED, NULL); | |
4031 | } | |
4032 | ||
4033 | ||
eb4582f2 AS |
4034 | static void nl80211_del_p2pdev(struct i802_bss *bss) |
4035 | { | |
4036 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
4037 | struct nl_msg *msg; | |
4038 | int ret; | |
4039 | ||
4040 | msg = nlmsg_alloc(); | |
4041 | if (!msg) | |
4042 | return; | |
4043 | ||
4044 | nl80211_cmd(drv, msg, 0, NL80211_CMD_DEL_INTERFACE); | |
4045 | NLA_PUT_U64(msg, NL80211_ATTR_WDEV, bss->wdev_id); | |
4046 | ||
4047 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); | |
4048 | msg = NULL; | |
4049 | ||
4050 | wpa_printf(MSG_DEBUG, "nl80211: Delete P2P Device %s (0x%llx): %s", | |
4051 | bss->ifname, (long long unsigned int) bss->wdev_id, | |
6cb4f11d | 4052 | strerror(-ret)); |
eb4582f2 AS |
4053 | |
4054 | nla_put_failure: | |
4055 | nlmsg_free(msg); | |
4056 | } | |
4057 | ||
4058 | ||
eb4582f2 | 4059 | static int nl80211_set_p2pdev(struct i802_bss *bss, int start) |
f632e483 AS |
4060 | { |
4061 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
4062 | struct nl_msg *msg; | |
4063 | int ret = -1; | |
4064 | ||
f632e483 AS |
4065 | msg = nlmsg_alloc(); |
4066 | if (!msg) | |
4067 | return -1; | |
4068 | ||
eb4582f2 AS |
4069 | if (start) |
4070 | nl80211_cmd(drv, msg, 0, NL80211_CMD_START_P2P_DEVICE); | |
4071 | else | |
4072 | nl80211_cmd(drv, msg, 0, NL80211_CMD_STOP_P2P_DEVICE); | |
4073 | ||
f632e483 AS |
4074 | NLA_PUT_U64(msg, NL80211_ATTR_WDEV, bss->wdev_id); |
4075 | ||
4076 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); | |
4077 | msg = NULL; | |
4078 | ||
eb4582f2 AS |
4079 | wpa_printf(MSG_DEBUG, "nl80211: %s P2P Device %s (0x%llx): %s", |
4080 | start ? "Start" : "Stop", | |
4081 | bss->ifname, (long long unsigned int) bss->wdev_id, | |
6cb4f11d | 4082 | strerror(-ret)); |
eb4582f2 | 4083 | |
f632e483 AS |
4084 | nla_put_failure: |
4085 | nlmsg_free(msg); | |
4086 | return ret; | |
4087 | } | |
f632e483 AS |
4088 | |
4089 | ||
91724d6f AS |
4090 | static int i802_set_iface_flags(struct i802_bss *bss, int up) |
4091 | { | |
4092 | enum nl80211_iftype nlmode; | |
4093 | ||
4094 | nlmode = nl80211_get_ifmode(bss); | |
4095 | if (nlmode != NL80211_IFTYPE_P2P_DEVICE) { | |
4096 | return linux_set_iface_flags(bss->drv->global->ioctl_sock, | |
4097 | bss->ifname, up); | |
4098 | } | |
4099 | ||
4100 | /* P2P Device has start/stop which is equivalent */ | |
4101 | return nl80211_set_p2pdev(bss, up); | |
4102 | } | |
4103 | ||
4104 | ||
362f781e | 4105 | static int |
7524cfb1 JM |
4106 | wpa_driver_nl80211_finish_drv_init(struct wpa_driver_nl80211_data *drv) |
4107 | { | |
f632e483 | 4108 | #ifndef HOSTAPD |
8e12685c | 4109 | enum nl80211_iftype nlmode = NL80211_IFTYPE_STATION; |
f632e483 | 4110 | #endif /* HOSTAPD */ |
a2e40bb6 | 4111 | struct i802_bss *bss = &drv->first_bss; |
8401a6b0 | 4112 | int send_rfkill_event = 0; |
a2e40bb6 FF |
4113 | |
4114 | drv->ifindex = if_nametoindex(bss->ifname); | |
f632e483 AS |
4115 | bss->ifindex = drv->ifindex; |
4116 | bss->wdev_id = drv->global->if_add_wdevid; | |
4117 | bss->wdev_id_set = drv->global->if_add_wdevid_set; | |
4118 | ||
60b13c20 IP |
4119 | bss->if_dynamic = drv->ifindex == drv->global->if_add_ifindex; |
4120 | bss->if_dynamic = bss->if_dynamic || drv->global->if_add_wdevid_set; | |
f632e483 AS |
4121 | drv->global->if_add_wdevid_set = 0; |
4122 | ||
4123 | if (wpa_driver_nl80211_capa(drv)) | |
4124 | return -1; | |
a87c9d96 | 4125 | |
5fbcb45d AS |
4126 | wpa_printf(MSG_DEBUG, "nl80211: interface %s in phy %s", |
4127 | bss->ifname, drv->phyname); | |
4128 | ||
bbaf0837 | 4129 | #ifndef HOSTAPD |
60b13c20 | 4130 | if (bss->if_dynamic) |
8e12685c | 4131 | nlmode = nl80211_get_ifmode(bss); |
f632e483 | 4132 | |
ff6a158b JM |
4133 | /* |
4134 | * Make sure the interface starts up in station mode unless this is a | |
4135 | * dynamically added interface (e.g., P2P) that was already configured | |
4136 | * with proper iftype. | |
4137 | */ | |
8e12685c AS |
4138 | if (wpa_driver_nl80211_set_mode(bss, nlmode) < 0) { |
4139 | wpa_printf(MSG_ERROR, "nl80211: Could not configure driver to use managed mode"); | |
4140 | return -1; | |
a87c9d96 | 4141 | } |
8e12685c | 4142 | drv->nlmode = nlmode; |
a87c9d96 | 4143 | |
f632e483 | 4144 | if (nlmode == NL80211_IFTYPE_P2P_DEVICE) { |
eb4582f2 | 4145 | int ret = nl80211_set_p2pdev(bss, 1); |
f632e483 AS |
4146 | if (ret < 0) |
4147 | wpa_printf(MSG_ERROR, "nl80211: Could not start P2P device"); | |
597b94f5 | 4148 | nl80211_get_macaddr(bss); |
f632e483 AS |
4149 | return ret; |
4150 | } | |
4151 | ||
c81eff1a | 4152 | if (linux_set_iface_flags(drv->global->ioctl_sock, bss->ifname, 1)) { |
8401a6b0 JM |
4153 | if (rfkill_is_blocked(drv->rfkill)) { |
4154 | wpa_printf(MSG_DEBUG, "nl80211: Could not yet enable " | |
4155 | "interface '%s' due to rfkill", | |
4156 | bss->ifname); | |
a63063b4 | 4157 | drv->if_disabled = 1; |
8401a6b0 JM |
4158 | send_rfkill_event = 1; |
4159 | } else { | |
4160 | wpa_printf(MSG_ERROR, "nl80211: Could not set " | |
4161 | "interface '%s' UP", bss->ifname); | |
4162 | return -1; | |
4163 | } | |
362f781e | 4164 | } |
3f5285e8 | 4165 | |
36d84860 | 4166 | netlink_send_oper_ifla(drv->global->netlink, drv->ifindex, |
e2d02c29 | 4167 | 1, IF_OPER_DORMANT); |
bbaf0837 | 4168 | #endif /* HOSTAPD */ |
362f781e | 4169 | |
c81eff1a | 4170 | if (linux_get_ifhwaddr(drv->global->ioctl_sock, bss->ifname, |
341eebee | 4171 | bss->addr)) |
2136f480 | 4172 | return -1; |
f2ed8023 | 4173 | |
8401a6b0 JM |
4174 | if (send_rfkill_event) { |
4175 | eloop_register_timeout(0, 0, wpa_driver_nl80211_send_rfkill, | |
4176 | drv, drv->ctx); | |
4177 | } | |
4178 | ||
362f781e | 4179 | return 0; |
3f5285e8 JM |
4180 | } |
4181 | ||
4182 | ||
8a27af5c JM |
4183 | static int wpa_driver_nl80211_del_beacon(struct wpa_driver_nl80211_data *drv) |
4184 | { | |
4185 | struct nl_msg *msg; | |
4186 | ||
4187 | msg = nlmsg_alloc(); | |
4188 | if (!msg) | |
4189 | return -ENOMEM; | |
4190 | ||
9fb04070 | 4191 | nl80211_cmd(drv, msg, 0, NL80211_CMD_DEL_BEACON); |
8a27af5c JM |
4192 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, drv->ifindex); |
4193 | ||
4194 | return send_and_recv_msgs(drv, msg, NULL, NULL); | |
4195 | nla_put_failure: | |
5883168a | 4196 | nlmsg_free(msg); |
8a27af5c JM |
4197 | return -ENOBUFS; |
4198 | } | |
8a27af5c JM |
4199 | |
4200 | ||
3f5285e8 | 4201 | /** |
7e5ba1b9 | 4202 | * wpa_driver_nl80211_deinit - Deinitialize nl80211 driver interface |
9ebce9c5 | 4203 | * @bss: Pointer to private nl80211 data from wpa_driver_nl80211_init() |
3f5285e8 JM |
4204 | * |
4205 | * Shut down driver interface and processing of driver events. Free | |
4206 | * private data buffer if one was allocated in wpa_driver_nl80211_init(). | |
4207 | */ | |
9ebce9c5 | 4208 | static void wpa_driver_nl80211_deinit(struct i802_bss *bss) |
3f5285e8 | 4209 | { |
a2e40bb6 | 4210 | struct wpa_driver_nl80211_data *drv = bss->drv; |
3f5285e8 | 4211 | |
873d0fcf | 4212 | bss->in_deinit = 1; |
32ab4855 JB |
4213 | if (drv->data_tx_status) |
4214 | eloop_unregister_read_sock(drv->eapol_tx_sock); | |
d12dab4c JB |
4215 | if (drv->eapol_tx_sock >= 0) |
4216 | close(drv->eapol_tx_sock); | |
f10bfc9a | 4217 | |
481234cf | 4218 | if (bss->nl_preq) |
5582a5d1 | 4219 | wpa_driver_nl80211_probe_req_report(bss, 0); |
e17a2477 | 4220 | if (bss->added_if_into_bridge) { |
c81eff1a BG |
4221 | if (linux_br_del_if(drv->global->ioctl_sock, bss->brname, |
4222 | bss->ifname) < 0) | |
94627f6c JM |
4223 | wpa_printf(MSG_INFO, "nl80211: Failed to remove " |
4224 | "interface %s from bridge %s: %s", | |
e17a2477 | 4225 | bss->ifname, bss->brname, strerror(errno)); |
94627f6c | 4226 | } |
e17a2477 | 4227 | if (bss->added_bridge) { |
c81eff1a | 4228 | if (linux_br_del(drv->global->ioctl_sock, bss->brname) < 0) |
94627f6c JM |
4229 | wpa_printf(MSG_INFO, "nl80211: Failed to remove " |
4230 | "bridge %s: %s", | |
e17a2477 | 4231 | bss->brname, strerror(errno)); |
94627f6c JM |
4232 | } |
4233 | ||
460456f8 | 4234 | nl80211_remove_monitor_interface(drv); |
8a27af5c | 4235 | |
b1f625e0 | 4236 | if (is_ap_interface(drv->nlmode)) |
8a27af5c | 4237 | wpa_driver_nl80211_del_beacon(drv); |
0915d02c | 4238 | |
bbaf0837 JM |
4239 | #ifdef HOSTAPD |
4240 | if (drv->last_freq_ht) { | |
4241 | /* Clear HT flags from the driver */ | |
4242 | struct hostapd_freq_params freq; | |
4243 | os_memset(&freq, 0, sizeof(freq)); | |
4244 | freq.freq = drv->last_freq; | |
9ebce9c5 | 4245 | wpa_driver_nl80211_set_freq(bss, &freq); |
bbaf0837 JM |
4246 | } |
4247 | ||
bbaf0837 JM |
4248 | if (drv->eapol_sock >= 0) { |
4249 | eloop_unregister_read_sock(drv->eapol_sock); | |
4250 | close(drv->eapol_sock); | |
4251 | } | |
4252 | ||
4253 | if (drv->if_indices != drv->default_if_indices) | |
4254 | os_free(drv->if_indices); | |
1b648c7e | 4255 | #endif /* HOSTAPD */ |
3f5285e8 | 4256 | |
b3af99d2 | 4257 | if (drv->disabled_11b_rates) |
4e5cb1a3 JM |
4258 | nl80211_disable_11b_rates(drv, drv->ifindex, 0); |
4259 | ||
36d84860 BG |
4260 | netlink_send_oper_ifla(drv->global->netlink, drv->ifindex, 0, |
4261 | IF_OPER_UP); | |
8401a6b0 | 4262 | rfkill_deinit(drv->rfkill); |
3f5285e8 | 4263 | |
bbaf0837 JM |
4264 | eloop_cancel_timeout(wpa_driver_nl80211_scan_timeout, drv, drv->ctx); |
4265 | ||
91724d6f | 4266 | (void) i802_set_iface_flags(bss, 0); |
8e12685c AS |
4267 | if (drv->nlmode != NL80211_IFTYPE_P2P_DEVICE) { |
4268 | wpa_driver_nl80211_set_mode(bss, NL80211_IFTYPE_STATION); | |
b378c41f | 4269 | nl80211_mgmt_unsubscribe(bss, "deinit"); |
8e12685c AS |
4270 | } else { |
4271 | nl80211_mgmt_unsubscribe(bss, "deinit"); | |
eb4582f2 | 4272 | nl80211_del_p2pdev(bss); |
8e12685c | 4273 | } |
1afc986d | 4274 | nl_cb_put(drv->nl_cb); |
3f5285e8 | 4275 | |
cc7a48d1 JB |
4276 | nl80211_destroy_bss(&drv->first_bss); |
4277 | ||
3812464c JM |
4278 | os_free(drv->filter_ssids); |
4279 | ||
536fd62d JM |
4280 | os_free(drv->auth_ie); |
4281 | ||
dac12351 | 4282 | if (drv->in_interface_list) |
f2ed8023 JM |
4283 | dl_list_del(&drv->list); |
4284 | ||
8cd6b7bc JB |
4285 | os_free(drv->extended_capa); |
4286 | os_free(drv->extended_capa_mask); | |
3f5285e8 JM |
4287 | os_free(drv); |
4288 | } | |
4289 | ||
4290 | ||
4291 | /** | |
4292 | * wpa_driver_nl80211_scan_timeout - Scan timeout to report scan completion | |
ad1e68e6 | 4293 | * @eloop_ctx: Driver private data |
3f5285e8 JM |
4294 | * @timeout_ctx: ctx argument given to wpa_driver_nl80211_init() |
4295 | * | |
4296 | * This function can be used as registered timeout when starting a scan to | |
4297 | * generate a scan completed event if the driver does not report this. | |
4298 | */ | |
4299 | static void wpa_driver_nl80211_scan_timeout(void *eloop_ctx, void *timeout_ctx) | |
4300 | { | |
ad1e68e6 | 4301 | struct wpa_driver_nl80211_data *drv = eloop_ctx; |
b1f625e0 | 4302 | if (drv->ap_scan_as_station != NL80211_IFTYPE_UNSPECIFIED) { |
a2e40bb6 | 4303 | wpa_driver_nl80211_set_mode(&drv->first_bss, |
b1f625e0 EP |
4304 | drv->ap_scan_as_station); |
4305 | drv->ap_scan_as_station = NL80211_IFTYPE_UNSPECIFIED; | |
ad1e68e6 | 4306 | } |
3f5285e8 JM |
4307 | wpa_printf(MSG_DEBUG, "Scan timeout - try to get results"); |
4308 | wpa_supplicant_event(timeout_ctx, EVENT_SCAN_RESULTS, NULL); | |
4309 | } | |
4310 | ||
4311 | ||
95ac3bf4 JM |
4312 | static struct nl_msg * |
4313 | nl80211_scan_common(struct wpa_driver_nl80211_data *drv, u8 cmd, | |
d3aaef80 | 4314 | struct wpa_driver_scan_params *params, u64 *wdev_id) |
3f5285e8 | 4315 | { |
95ac3bf4 | 4316 | struct nl_msg *msg; |
6a1063e0 | 4317 | size_t i; |
3f5285e8 | 4318 | |
0e75527f | 4319 | msg = nlmsg_alloc(); |
f0494d0f | 4320 | if (!msg) |
95ac3bf4 | 4321 | return NULL; |
3812464c | 4322 | |
95ac3bf4 | 4323 | nl80211_cmd(drv, msg, 0, cmd); |
0e75527f | 4324 | |
d3aaef80 DS |
4325 | if (!wdev_id) |
4326 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, drv->ifindex); | |
4327 | else | |
4328 | NLA_PUT_U64(msg, NL80211_ATTR_WDEV, *wdev_id); | |
3f5285e8 | 4329 | |
f0494d0f | 4330 | if (params->num_ssids) { |
8970bae8 JB |
4331 | struct nlattr *ssids; |
4332 | ||
4333 | ssids = nla_nest_start(msg, NL80211_ATTR_SCAN_SSIDS); | |
f0494d0f | 4334 | if (ssids == NULL) |
95ac3bf4 | 4335 | goto fail; |
f0494d0f JM |
4336 | for (i = 0; i < params->num_ssids; i++) { |
4337 | wpa_hexdump_ascii(MSG_MSGDUMP, "nl80211: Scan SSID", | |
4338 | params->ssids[i].ssid, | |
4339 | params->ssids[i].ssid_len); | |
8970bae8 JB |
4340 | if (nla_put(msg, i + 1, params->ssids[i].ssid_len, |
4341 | params->ssids[i].ssid) < 0) | |
95ac3bf4 | 4342 | goto fail; |
f0494d0f | 4343 | } |
8970bae8 | 4344 | nla_nest_end(msg, ssids); |
3f5285e8 JM |
4345 | } |
4346 | ||
d173df52 | 4347 | if (params->extra_ies) { |
3b1c7bfd JM |
4348 | wpa_hexdump(MSG_MSGDUMP, "nl80211: Scan extra IEs", |
4349 | params->extra_ies, params->extra_ies_len); | |
95ac3bf4 JM |
4350 | if (nla_put(msg, NL80211_ATTR_IE, params->extra_ies_len, |
4351 | params->extra_ies) < 0) | |
4352 | goto fail; | |
d173df52 JM |
4353 | } |
4354 | ||
d3a98225 | 4355 | if (params->freqs) { |
8970bae8 JB |
4356 | struct nlattr *freqs; |
4357 | freqs = nla_nest_start(msg, NL80211_ATTR_SCAN_FREQUENCIES); | |
f0494d0f | 4358 | if (freqs == NULL) |
95ac3bf4 | 4359 | goto fail; |
9fad706c JM |
4360 | for (i = 0; params->freqs[i]; i++) { |
4361 | wpa_printf(MSG_MSGDUMP, "nl80211: Scan frequency %u " | |
4362 | "MHz", params->freqs[i]); | |
8970bae8 | 4363 | if (nla_put_u32(msg, i + 1, params->freqs[i]) < 0) |
95ac3bf4 | 4364 | goto fail; |
9fad706c | 4365 | } |
8970bae8 | 4366 | nla_nest_end(msg, freqs); |
d3a98225 JM |
4367 | } |
4368 | ||
95ac3bf4 JM |
4369 | os_free(drv->filter_ssids); |
4370 | drv->filter_ssids = params->filter_ssids; | |
4371 | params->filter_ssids = NULL; | |
4372 | drv->num_filter_ssids = params->num_filter_ssids; | |
4373 | ||
4374 | return msg; | |
4375 | ||
4376 | fail: | |
d3aaef80 | 4377 | nla_put_failure: |
95ac3bf4 JM |
4378 | nlmsg_free(msg); |
4379 | return NULL; | |
4380 | } | |
4381 | ||
4382 | ||
4383 | /** | |
4384 | * wpa_driver_nl80211_scan - Request the driver to initiate scan | |
9ebce9c5 | 4385 | * @bss: Pointer to private driver data from wpa_driver_nl80211_init() |
95ac3bf4 JM |
4386 | * @params: Scan parameters |
4387 | * Returns: 0 on success, -1 on failure | |
4388 | */ | |
9ebce9c5 | 4389 | static int wpa_driver_nl80211_scan(struct i802_bss *bss, |
95ac3bf4 JM |
4390 | struct wpa_driver_scan_params *params) |
4391 | { | |
95ac3bf4 JM |
4392 | struct wpa_driver_nl80211_data *drv = bss->drv; |
4393 | int ret = -1, timeout; | |
8970bae8 | 4394 | struct nl_msg *msg = NULL; |
95ac3bf4 | 4395 | |
565110cd | 4396 | wpa_dbg(drv->ctx, MSG_DEBUG, "nl80211: scan request"); |
95ac3bf4 JM |
4397 | drv->scan_for_auth = 0; |
4398 | ||
d3aaef80 DS |
4399 | msg = nl80211_scan_common(drv, NL80211_CMD_TRIGGER_SCAN, params, |
4400 | bss->wdev_id_set ? &bss->wdev_id : NULL); | |
95ac3bf4 JM |
4401 | if (!msg) |
4402 | return -1; | |
4403 | ||
47185fc7 | 4404 | if (params->p2p_probe) { |
8970bae8 JB |
4405 | struct nlattr *rates; |
4406 | ||
8a6a1e1b JM |
4407 | wpa_printf(MSG_DEBUG, "nl80211: P2P probe - mask SuppRates"); |
4408 | ||
8970bae8 | 4409 | rates = nla_nest_start(msg, NL80211_ATTR_SCAN_SUPP_RATES); |
f0494d0f JM |
4410 | if (rates == NULL) |
4411 | goto nla_put_failure; | |
4412 | ||
47185fc7 RM |
4413 | /* |
4414 | * Remove 2.4 GHz rates 1, 2, 5.5, 11 Mbps from supported rates | |
4415 | * by masking out everything else apart from the OFDM rates 6, | |
4416 | * 9, 12, 18, 24, 36, 48, 54 Mbps from non-MCS rates. All 5 GHz | |
4417 | * rates are left enabled. | |
4418 | */ | |
8970bae8 | 4419 | NLA_PUT(msg, NL80211_BAND_2GHZ, 8, |
47185fc7 | 4420 | "\x0c\x12\x18\x24\x30\x48\x60\x6c"); |
8970bae8 | 4421 | nla_nest_end(msg, rates); |
970fa12e RM |
4422 | |
4423 | NLA_PUT_FLAG(msg, NL80211_ATTR_TX_NO_CCK_RATE); | |
47185fc7 RM |
4424 | } |
4425 | ||
0e75527f JM |
4426 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
4427 | msg = NULL; | |
4428 | if (ret) { | |
4429 | wpa_printf(MSG_DEBUG, "nl80211: Scan trigger failed: ret=%d " | |
4430 | "(%s)", ret, strerror(-ret)); | |
ad1e68e6 | 4431 | #ifdef HOSTAPD |
b1f625e0 | 4432 | if (is_ap_interface(drv->nlmode)) { |
ad1e68e6 JM |
4433 | /* |
4434 | * mac80211 does not allow scan requests in AP mode, so | |
4435 | * try to do this in station mode. | |
4436 | */ | |
b1f625e0 EP |
4437 | if (wpa_driver_nl80211_set_mode( |
4438 | bss, NL80211_IFTYPE_STATION)) | |
ad1e68e6 JM |
4439 | goto nla_put_failure; |
4440 | ||
085b29f1 | 4441 | if (wpa_driver_nl80211_scan(bss, params)) { |
b1f625e0 | 4442 | wpa_driver_nl80211_set_mode(bss, drv->nlmode); |
ad1e68e6 JM |
4443 | goto nla_put_failure; |
4444 | } | |
4445 | ||
4446 | /* Restore AP mode when processing scan results */ | |
b1f625e0 | 4447 | drv->ap_scan_as_station = drv->nlmode; |
ad1e68e6 JM |
4448 | ret = 0; |
4449 | } else | |
4450 | goto nla_put_failure; | |
4451 | #else /* HOSTAPD */ | |
0e75527f | 4452 | goto nla_put_failure; |
ad1e68e6 | 4453 | #endif /* HOSTAPD */ |
3f5285e8 JM |
4454 | } |
4455 | ||
a771c07d | 4456 | drv->scan_state = SCAN_REQUESTED; |
3f5285e8 JM |
4457 | /* Not all drivers generate "scan completed" wireless event, so try to |
4458 | * read results after a timeout. */ | |
0e75527f | 4459 | timeout = 10; |
3f5285e8 JM |
4460 | if (drv->scan_complete_events) { |
4461 | /* | |
d173df52 JM |
4462 | * The driver seems to deliver events to notify when scan is |
4463 | * complete, so use longer timeout to avoid race conditions | |
4464 | * with scanning and following association request. | |
3f5285e8 JM |
4465 | */ |
4466 | timeout = 30; | |
4467 | } | |
4468 | wpa_printf(MSG_DEBUG, "Scan requested (ret=%d) - scan timeout %d " | |
4469 | "seconds", ret, timeout); | |
4470 | eloop_cancel_timeout(wpa_driver_nl80211_scan_timeout, drv, drv->ctx); | |
0e75527f JM |
4471 | eloop_register_timeout(timeout, 0, wpa_driver_nl80211_scan_timeout, |
4472 | drv, drv->ctx); | |
3f5285e8 | 4473 | |
0e75527f | 4474 | nla_put_failure: |
0e75527f | 4475 | nlmsg_free(msg); |
3f5285e8 JM |
4476 | return ret; |
4477 | } | |
4478 | ||
4479 | ||
d21c63b9 LC |
4480 | /** |
4481 | * wpa_driver_nl80211_sched_scan - Initiate a scheduled scan | |
4482 | * @priv: Pointer to private driver data from wpa_driver_nl80211_init() | |
4483 | * @params: Scan parameters | |
4484 | * @interval: Interval between scan cycles in milliseconds | |
4485 | * Returns: 0 on success, -1 on failure or if not supported | |
4486 | */ | |
4487 | static int wpa_driver_nl80211_sched_scan(void *priv, | |
4488 | struct wpa_driver_scan_params *params, | |
4489 | u32 interval) | |
4490 | { | |
4491 | struct i802_bss *bss = priv; | |
4492 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
6afbc3d6 | 4493 | int ret = -1; |
95ac3bf4 | 4494 | struct nl_msg *msg; |
d21c63b9 LC |
4495 | size_t i; |
4496 | ||
565110cd JM |
4497 | wpa_dbg(drv->ctx, MSG_DEBUG, "nl80211: sched_scan request"); |
4498 | ||
216eede8 DS |
4499 | #ifdef ANDROID |
4500 | if (!drv->capa.sched_scan_supported) | |
4501 | return android_pno_start(bss, params); | |
4502 | #endif /* ANDROID */ | |
4503 | ||
d3aaef80 DS |
4504 | msg = nl80211_scan_common(drv, NL80211_CMD_START_SCHED_SCAN, params, |
4505 | bss->wdev_id_set ? &bss->wdev_id : NULL); | |
6afbc3d6 JM |
4506 | if (!msg) |
4507 | goto nla_put_failure; | |
d21c63b9 | 4508 | |
d21c63b9 LC |
4509 | NLA_PUT_U32(msg, NL80211_ATTR_SCHED_SCAN_INTERVAL, interval); |
4510 | ||
bf8d6d24 TP |
4511 | if ((drv->num_filter_ssids && |
4512 | (int) drv->num_filter_ssids <= drv->capa.max_match_sets) || | |
4513 | params->filter_rssi) { | |
8970bae8 JB |
4514 | struct nlattr *match_sets; |
4515 | match_sets = nla_nest_start(msg, NL80211_ATTR_SCHED_SCAN_MATCH); | |
6afbc3d6 JM |
4516 | if (match_sets == NULL) |
4517 | goto nla_put_failure; | |
bd525934 LC |
4518 | |
4519 | for (i = 0; i < drv->num_filter_ssids; i++) { | |
8970bae8 | 4520 | struct nlattr *match_set_ssid; |
bd525934 LC |
4521 | wpa_hexdump_ascii(MSG_MSGDUMP, |
4522 | "nl80211: Sched scan filter SSID", | |
4523 | drv->filter_ssids[i].ssid, | |
4524 | drv->filter_ssids[i].ssid_len); | |
4525 | ||
8970bae8 | 4526 | match_set_ssid = nla_nest_start(msg, i + 1); |
6afbc3d6 JM |
4527 | if (match_set_ssid == NULL) |
4528 | goto nla_put_failure; | |
8970bae8 | 4529 | NLA_PUT(msg, NL80211_ATTR_SCHED_SCAN_MATCH_SSID, |
bd525934 LC |
4530 | drv->filter_ssids[i].ssid_len, |
4531 | drv->filter_ssids[i].ssid); | |
4532 | ||
adc96dc2 | 4533 | nla_nest_end(msg, match_set_ssid); |
bd525934 LC |
4534 | } |
4535 | ||
bf8d6d24 | 4536 | if (params->filter_rssi) { |
8970bae8 JB |
4537 | struct nlattr *match_set_rssi; |
4538 | match_set_rssi = nla_nest_start(msg, 0); | |
6afbc3d6 JM |
4539 | if (match_set_rssi == NULL) |
4540 | goto nla_put_failure; | |
8970bae8 | 4541 | NLA_PUT_U32(msg, NL80211_SCHED_SCAN_MATCH_ATTR_RSSI, |
bf8d6d24 TP |
4542 | params->filter_rssi); |
4543 | wpa_printf(MSG_MSGDUMP, | |
4544 | "nl80211: Sched scan RSSI filter %d dBm", | |
4545 | params->filter_rssi); | |
8970bae8 | 4546 | nla_nest_end(msg, match_set_rssi); |
bf8d6d24 TP |
4547 | } |
4548 | ||
8970bae8 | 4549 | nla_nest_end(msg, match_sets); |
bd525934 LC |
4550 | } |
4551 | ||
d21c63b9 LC |
4552 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
4553 | ||
4554 | /* TODO: if we get an error here, we should fall back to normal scan */ | |
4555 | ||
4556 | msg = NULL; | |
4557 | if (ret) { | |
4558 | wpa_printf(MSG_DEBUG, "nl80211: Sched scan start failed: " | |
4559 | "ret=%d (%s)", ret, strerror(-ret)); | |
4560 | goto nla_put_failure; | |
4561 | } | |
4562 | ||
4563 | wpa_printf(MSG_DEBUG, "nl80211: Sched scan requested (ret=%d) - " | |
4564 | "scan interval %d msec", ret, interval); | |
4565 | ||
4566 | nla_put_failure: | |
d21c63b9 | 4567 | nlmsg_free(msg); |
d21c63b9 LC |
4568 | return ret; |
4569 | } | |
4570 | ||
4571 | ||
4572 | /** | |
4573 | * wpa_driver_nl80211_stop_sched_scan - Stop a scheduled scan | |
4574 | * @priv: Pointer to private driver data from wpa_driver_nl80211_init() | |
4575 | * Returns: 0 on success, -1 on failure or if not supported | |
4576 | */ | |
4577 | static int wpa_driver_nl80211_stop_sched_scan(void *priv) | |
4578 | { | |
4579 | struct i802_bss *bss = priv; | |
4580 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
4581 | int ret = 0; | |
4582 | struct nl_msg *msg; | |
4583 | ||
216eede8 DS |
4584 | #ifdef ANDROID |
4585 | if (!drv->capa.sched_scan_supported) | |
4586 | return android_pno_stop(bss); | |
4587 | #endif /* ANDROID */ | |
4588 | ||
d21c63b9 LC |
4589 | msg = nlmsg_alloc(); |
4590 | if (!msg) | |
4591 | return -1; | |
4592 | ||
9fb04070 | 4593 | nl80211_cmd(drv, msg, 0, NL80211_CMD_STOP_SCHED_SCAN); |
d21c63b9 LC |
4594 | |
4595 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, drv->ifindex); | |
4596 | ||
4597 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); | |
4598 | msg = NULL; | |
4599 | if (ret) { | |
4600 | wpa_printf(MSG_DEBUG, "nl80211: Sched scan stop failed: " | |
4601 | "ret=%d (%s)", ret, strerror(-ret)); | |
4602 | goto nla_put_failure; | |
4603 | } | |
4604 | ||
4605 | wpa_printf(MSG_DEBUG, "nl80211: Sched scan stop sent (ret=%d)", ret); | |
4606 | ||
4607 | nla_put_failure: | |
4608 | nlmsg_free(msg); | |
4609 | return ret; | |
4610 | } | |
4611 | ||
4612 | ||
3812464c JM |
4613 | static const u8 * nl80211_get_ie(const u8 *ies, size_t ies_len, u8 ie) |
4614 | { | |
4615 | const u8 *end, *pos; | |
4616 | ||
4617 | if (ies == NULL) | |
4618 | return NULL; | |
4619 | ||
4620 | pos = ies; | |
4621 | end = ies + ies_len; | |
4622 | ||
4623 | while (pos + 1 < end) { | |
4624 | if (pos + 2 + pos[1] > end) | |
4625 | break; | |
4626 | if (pos[0] == ie) | |
4627 | return pos; | |
4628 | pos += 2 + pos[1]; | |
4629 | } | |
4630 | ||
4631 | return NULL; | |
4632 | } | |
4633 | ||
4634 | ||
4635 | static int nl80211_scan_filtered(struct wpa_driver_nl80211_data *drv, | |
4636 | const u8 *ie, size_t ie_len) | |
4637 | { | |
4638 | const u8 *ssid; | |
4639 | size_t i; | |
4640 | ||
4641 | if (drv->filter_ssids == NULL) | |
4642 | return 0; | |
4643 | ||
4644 | ssid = nl80211_get_ie(ie, ie_len, WLAN_EID_SSID); | |
4645 | if (ssid == NULL) | |
4646 | return 1; | |
4647 | ||
4648 | for (i = 0; i < drv->num_filter_ssids; i++) { | |
4649 | if (ssid[1] == drv->filter_ssids[i].ssid_len && | |
4650 | os_memcmp(ssid + 2, drv->filter_ssids[i].ssid, ssid[1]) == | |
4651 | 0) | |
4652 | return 0; | |
4653 | } | |
4654 | ||
4655 | return 1; | |
4656 | } | |
4657 | ||
4658 | ||
b3db1e1c | 4659 | static int bss_info_handler(struct nl_msg *msg, void *arg) |
3f5285e8 | 4660 | { |
b3db1e1c JM |
4661 | struct nlattr *tb[NL80211_ATTR_MAX + 1]; |
4662 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); | |
4663 | struct nlattr *bss[NL80211_BSS_MAX + 1]; | |
4664 | static struct nla_policy bss_policy[NL80211_BSS_MAX + 1] = { | |
4665 | [NL80211_BSS_BSSID] = { .type = NLA_UNSPEC }, | |
4666 | [NL80211_BSS_FREQUENCY] = { .type = NLA_U32 }, | |
4667 | [NL80211_BSS_TSF] = { .type = NLA_U64 }, | |
4668 | [NL80211_BSS_BEACON_INTERVAL] = { .type = NLA_U16 }, | |
4669 | [NL80211_BSS_CAPABILITY] = { .type = NLA_U16 }, | |
4670 | [NL80211_BSS_INFORMATION_ELEMENTS] = { .type = NLA_UNSPEC }, | |
4671 | [NL80211_BSS_SIGNAL_MBM] = { .type = NLA_U32 }, | |
4672 | [NL80211_BSS_SIGNAL_UNSPEC] = { .type = NLA_U8 }, | |
e6b8efeb | 4673 | [NL80211_BSS_STATUS] = { .type = NLA_U32 }, |
b3ad11bb | 4674 | [NL80211_BSS_SEEN_MS_AGO] = { .type = NLA_U32 }, |
8c090654 | 4675 | [NL80211_BSS_BEACON_IES] = { .type = NLA_UNSPEC }, |
b3db1e1c | 4676 | }; |
3812464c JM |
4677 | struct nl80211_bss_info_arg *_arg = arg; |
4678 | struct wpa_scan_results *res = _arg->res; | |
3f5285e8 JM |
4679 | struct wpa_scan_res **tmp; |
4680 | struct wpa_scan_res *r; | |
8c090654 JM |
4681 | const u8 *ie, *beacon_ie; |
4682 | size_t ie_len, beacon_ie_len; | |
4683 | u8 *pos; | |
46957a9b | 4684 | size_t i; |
3f5285e8 | 4685 | |
b3db1e1c JM |
4686 | nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), |
4687 | genlmsg_attrlen(gnlh, 0), NULL); | |
4688 | if (!tb[NL80211_ATTR_BSS]) | |
4689 | return NL_SKIP; | |
4690 | if (nla_parse_nested(bss, NL80211_BSS_MAX, tb[NL80211_ATTR_BSS], | |
4691 | bss_policy)) | |
4692 | return NL_SKIP; | |
f5a8d422 JM |
4693 | if (bss[NL80211_BSS_STATUS]) { |
4694 | enum nl80211_bss_status status; | |
4695 | status = nla_get_u32(bss[NL80211_BSS_STATUS]); | |
4696 | if (status == NL80211_BSS_STATUS_ASSOCIATED && | |
4697 | bss[NL80211_BSS_FREQUENCY]) { | |
4698 | _arg->assoc_freq = | |
4699 | nla_get_u32(bss[NL80211_BSS_FREQUENCY]); | |
4700 | wpa_printf(MSG_DEBUG, "nl80211: Associated on %u MHz", | |
4701 | _arg->assoc_freq); | |
4702 | } | |
20f5a4c2 JM |
4703 | if (status == NL80211_BSS_STATUS_ASSOCIATED && |
4704 | bss[NL80211_BSS_BSSID]) { | |
4705 | os_memcpy(_arg->assoc_bssid, | |
4706 | nla_data(bss[NL80211_BSS_BSSID]), ETH_ALEN); | |
4707 | wpa_printf(MSG_DEBUG, "nl80211: Associated with " | |
4708 | MACSTR, MAC2STR(_arg->assoc_bssid)); | |
4709 | } | |
f5a8d422 JM |
4710 | } |
4711 | if (!res) | |
4712 | return NL_SKIP; | |
b3db1e1c JM |
4713 | if (bss[NL80211_BSS_INFORMATION_ELEMENTS]) { |
4714 | ie = nla_data(bss[NL80211_BSS_INFORMATION_ELEMENTS]); | |
4715 | ie_len = nla_len(bss[NL80211_BSS_INFORMATION_ELEMENTS]); | |
4716 | } else { | |
4717 | ie = NULL; | |
4718 | ie_len = 0; | |
4719 | } | |
8c090654 JM |
4720 | if (bss[NL80211_BSS_BEACON_IES]) { |
4721 | beacon_ie = nla_data(bss[NL80211_BSS_BEACON_IES]); | |
4722 | beacon_ie_len = nla_len(bss[NL80211_BSS_BEACON_IES]); | |
4723 | } else { | |
4724 | beacon_ie = NULL; | |
4725 | beacon_ie_len = 0; | |
4726 | } | |
3f5285e8 | 4727 | |
3812464c JM |
4728 | if (nl80211_scan_filtered(_arg->drv, ie ? ie : beacon_ie, |
4729 | ie ? ie_len : beacon_ie_len)) | |
4730 | return NL_SKIP; | |
4731 | ||
8c090654 | 4732 | r = os_zalloc(sizeof(*r) + ie_len + beacon_ie_len); |
3f5285e8 | 4733 | if (r == NULL) |
b3db1e1c JM |
4734 | return NL_SKIP; |
4735 | if (bss[NL80211_BSS_BSSID]) | |
4736 | os_memcpy(r->bssid, nla_data(bss[NL80211_BSS_BSSID]), | |
4737 | ETH_ALEN); | |
4738 | if (bss[NL80211_BSS_FREQUENCY]) | |
4739 | r->freq = nla_get_u32(bss[NL80211_BSS_FREQUENCY]); | |
4740 | if (bss[NL80211_BSS_BEACON_INTERVAL]) | |
4741 | r->beacon_int = nla_get_u16(bss[NL80211_BSS_BEACON_INTERVAL]); | |
4742 | if (bss[NL80211_BSS_CAPABILITY]) | |
4743 | r->caps = nla_get_u16(bss[NL80211_BSS_CAPABILITY]); | |
7c2849d2 JM |
4744 | r->flags |= WPA_SCAN_NOISE_INVALID; |
4745 | if (bss[NL80211_BSS_SIGNAL_MBM]) { | |
b3db1e1c | 4746 | r->level = nla_get_u32(bss[NL80211_BSS_SIGNAL_MBM]); |
7c2849d2 JM |
4747 | r->level /= 100; /* mBm to dBm */ |
4748 | r->flags |= WPA_SCAN_LEVEL_DBM | WPA_SCAN_QUAL_INVALID; | |
4749 | } else if (bss[NL80211_BSS_SIGNAL_UNSPEC]) { | |
4750 | r->level = nla_get_u8(bss[NL80211_BSS_SIGNAL_UNSPEC]); | |
98ac6763 | 4751 | r->flags |= WPA_SCAN_QUAL_INVALID; |
7c2849d2 JM |
4752 | } else |
4753 | r->flags |= WPA_SCAN_LEVEL_INVALID | WPA_SCAN_QUAL_INVALID; | |
b3db1e1c JM |
4754 | if (bss[NL80211_BSS_TSF]) |
4755 | r->tsf = nla_get_u64(bss[NL80211_BSS_TSF]); | |
b3ad11bb JM |
4756 | if (bss[NL80211_BSS_SEEN_MS_AGO]) |
4757 | r->age = nla_get_u32(bss[NL80211_BSS_SEEN_MS_AGO]); | |
b3db1e1c | 4758 | r->ie_len = ie_len; |
8c090654 JM |
4759 | pos = (u8 *) (r + 1); |
4760 | if (ie) { | |
4761 | os_memcpy(pos, ie, ie_len); | |
4762 | pos += ie_len; | |
4763 | } | |
4764 | r->beacon_ie_len = beacon_ie_len; | |
4765 | if (beacon_ie) | |
4766 | os_memcpy(pos, beacon_ie, beacon_ie_len); | |
3f5285e8 | 4767 | |
e6b8efeb JM |
4768 | if (bss[NL80211_BSS_STATUS]) { |
4769 | enum nl80211_bss_status status; | |
4770 | status = nla_get_u32(bss[NL80211_BSS_STATUS]); | |
4771 | switch (status) { | |
4772 | case NL80211_BSS_STATUS_AUTHENTICATED: | |
4773 | r->flags |= WPA_SCAN_AUTHENTICATED; | |
4774 | break; | |
4775 | case NL80211_BSS_STATUS_ASSOCIATED: | |
4776 | r->flags |= WPA_SCAN_ASSOCIATED; | |
4777 | break; | |
4778 | default: | |
4779 | break; | |
4780 | } | |
4781 | } | |
4782 | ||
46957a9b JM |
4783 | /* |
4784 | * cfg80211 maintains separate BSS table entries for APs if the same | |
4785 | * BSSID,SSID pair is seen on multiple channels. wpa_supplicant does | |
4786 | * not use frequency as a separate key in the BSS table, so filter out | |
4787 | * duplicated entries. Prefer associated BSS entry in such a case in | |
4788 | * order to get the correct frequency into the BSS table. | |
4789 | */ | |
4790 | for (i = 0; i < res->num; i++) { | |
4791 | const u8 *s1, *s2; | |
4792 | if (os_memcmp(res->res[i]->bssid, r->bssid, ETH_ALEN) != 0) | |
4793 | continue; | |
4794 | ||
4795 | s1 = nl80211_get_ie((u8 *) (res->res[i] + 1), | |
4796 | res->res[i]->ie_len, WLAN_EID_SSID); | |
4797 | s2 = nl80211_get_ie((u8 *) (r + 1), r->ie_len, WLAN_EID_SSID); | |
4798 | if (s1 == NULL || s2 == NULL || s1[1] != s2[1] || | |
4799 | os_memcmp(s1, s2, 2 + s1[1]) != 0) | |
4800 | continue; | |
4801 | ||
4802 | /* Same BSSID,SSID was already included in scan results */ | |
4803 | wpa_printf(MSG_DEBUG, "nl80211: Remove duplicated scan result " | |
4804 | "for " MACSTR, MAC2STR(r->bssid)); | |
4805 | ||
4806 | if ((r->flags & WPA_SCAN_ASSOCIATED) && | |
4807 | !(res->res[i]->flags & WPA_SCAN_ASSOCIATED)) { | |
4808 | os_free(res->res[i]); | |
4809 | res->res[i] = r; | |
4810 | } else | |
4811 | os_free(r); | |
4812 | return NL_SKIP; | |
4813 | } | |
4814 | ||
067ffa26 JM |
4815 | tmp = os_realloc_array(res->res, res->num + 1, |
4816 | sizeof(struct wpa_scan_res *)); | |
3f5285e8 JM |
4817 | if (tmp == NULL) { |
4818 | os_free(r); | |
b3db1e1c | 4819 | return NL_SKIP; |
3f5285e8 JM |
4820 | } |
4821 | tmp[res->num++] = r; | |
4822 | res->res = tmp; | |
b3db1e1c JM |
4823 | |
4824 | return NL_SKIP; | |
3f5285e8 | 4825 | } |
b3db1e1c | 4826 | |
3f5285e8 | 4827 | |
d72aad94 JM |
4828 | static void clear_state_mismatch(struct wpa_driver_nl80211_data *drv, |
4829 | const u8 *addr) | |
4830 | { | |
4831 | if (drv->capa.flags & WPA_DRIVER_FLAGS_SME) { | |
4832 | wpa_printf(MSG_DEBUG, "nl80211: Clear possible state " | |
582507be | 4833 | "mismatch (" MACSTR ")", MAC2STR(addr)); |
d72aad94 JM |
4834 | wpa_driver_nl80211_mlme(drv, addr, |
4835 | NL80211_CMD_DEAUTHENTICATE, | |
77339912 | 4836 | WLAN_REASON_PREV_AUTH_NOT_VALID, 1); |
d72aad94 JM |
4837 | } |
4838 | } | |
4839 | ||
4840 | ||
e6b8efeb JM |
4841 | static void wpa_driver_nl80211_check_bss_status( |
4842 | struct wpa_driver_nl80211_data *drv, struct wpa_scan_results *res) | |
4843 | { | |
4844 | size_t i; | |
4845 | ||
4846 | for (i = 0; i < res->num; i++) { | |
4847 | struct wpa_scan_res *r = res->res[i]; | |
4848 | if (r->flags & WPA_SCAN_AUTHENTICATED) { | |
4849 | wpa_printf(MSG_DEBUG, "nl80211: Scan results " | |
4850 | "indicates BSS status with " MACSTR | |
4851 | " as authenticated", | |
4852 | MAC2STR(r->bssid)); | |
b1f625e0 | 4853 | if (is_sta_interface(drv->nlmode) && |
e6b8efeb JM |
4854 | os_memcmp(r->bssid, drv->bssid, ETH_ALEN) != 0 && |
4855 | os_memcmp(r->bssid, drv->auth_bssid, ETH_ALEN) != | |
4856 | 0) { | |
4857 | wpa_printf(MSG_DEBUG, "nl80211: Unknown BSSID" | |
4858 | " in local state (auth=" MACSTR | |
4859 | " assoc=" MACSTR ")", | |
4860 | MAC2STR(drv->auth_bssid), | |
4861 | MAC2STR(drv->bssid)); | |
582507be | 4862 | clear_state_mismatch(drv, r->bssid); |
e6b8efeb JM |
4863 | } |
4864 | } | |
4865 | ||
4866 | if (r->flags & WPA_SCAN_ASSOCIATED) { | |
4867 | wpa_printf(MSG_DEBUG, "nl80211: Scan results " | |
4868 | "indicate BSS status with " MACSTR | |
4869 | " as associated", | |
4870 | MAC2STR(r->bssid)); | |
b1f625e0 | 4871 | if (is_sta_interface(drv->nlmode) && |
e6b8efeb JM |
4872 | !drv->associated) { |
4873 | wpa_printf(MSG_DEBUG, "nl80211: Local state " | |
4874 | "(not associated) does not match " | |
4875 | "with BSS state"); | |
d72aad94 | 4876 | clear_state_mismatch(drv, r->bssid); |
b1f625e0 | 4877 | } else if (is_sta_interface(drv->nlmode) && |
e6b8efeb JM |
4878 | os_memcmp(drv->bssid, r->bssid, ETH_ALEN) != |
4879 | 0) { | |
4880 | wpa_printf(MSG_DEBUG, "nl80211: Local state " | |
4881 | "(associated with " MACSTR ") does " | |
4882 | "not match with BSS state", | |
d72aad94 JM |
4883 | MAC2STR(drv->bssid)); |
4884 | clear_state_mismatch(drv, r->bssid); | |
4885 | clear_state_mismatch(drv, drv->bssid); | |
e6b8efeb JM |
4886 | } |
4887 | } | |
4888 | } | |
4889 | } | |
4890 | ||
4891 | ||
7e5ba1b9 | 4892 | static struct wpa_scan_results * |
8856462d | 4893 | nl80211_get_scan_results(struct wpa_driver_nl80211_data *drv) |
3f5285e8 | 4894 | { |
b3db1e1c | 4895 | struct nl_msg *msg; |
3f5285e8 | 4896 | struct wpa_scan_results *res; |
b3db1e1c | 4897 | int ret; |
3812464c | 4898 | struct nl80211_bss_info_arg arg; |
3f5285e8 JM |
4899 | |
4900 | res = os_zalloc(sizeof(*res)); | |
b3db1e1c | 4901 | if (res == NULL) |
8e2c104f | 4902 | return NULL; |
b3db1e1c JM |
4903 | msg = nlmsg_alloc(); |
4904 | if (!msg) | |
4905 | goto nla_put_failure; | |
3f5285e8 | 4906 | |
9fb04070 | 4907 | nl80211_cmd(drv, msg, NLM_F_DUMP, NL80211_CMD_GET_SCAN); |
fdc554b8 AS |
4908 | if (nl80211_set_iface_id(msg, &drv->first_bss) < 0) |
4909 | goto nla_put_failure; | |
3f5285e8 | 4910 | |
3812464c JM |
4911 | arg.drv = drv; |
4912 | arg.res = res; | |
4913 | ret = send_and_recv_msgs(drv, msg, bss_info_handler, &arg); | |
b3db1e1c JM |
4914 | msg = NULL; |
4915 | if (ret == 0) { | |
577db0ae GM |
4916 | wpa_printf(MSG_DEBUG, "nl80211: Received scan results (%lu " |
4917 | "BSSes)", (unsigned long) res->num); | |
4918 | nl80211_get_noise_for_scan_results(drv, res); | |
b3db1e1c | 4919 | return res; |
3f5285e8 | 4920 | } |
b3db1e1c JM |
4921 | wpa_printf(MSG_DEBUG, "nl80211: Scan result fetch failed: ret=%d " |
4922 | "(%s)", ret, strerror(-ret)); | |
4923 | nla_put_failure: | |
4924 | nlmsg_free(msg); | |
4925 | wpa_scan_results_free(res); | |
4926 | return NULL; | |
3f5285e8 JM |
4927 | } |
4928 | ||
4929 | ||
8856462d JM |
4930 | /** |
4931 | * wpa_driver_nl80211_get_scan_results - Fetch the latest scan results | |
4932 | * @priv: Pointer to private wext data from wpa_driver_nl80211_init() | |
4933 | * Returns: Scan results on success, -1 on failure | |
4934 | */ | |
4935 | static struct wpa_scan_results * | |
4936 | wpa_driver_nl80211_get_scan_results(void *priv) | |
4937 | { | |
a2e40bb6 FF |
4938 | struct i802_bss *bss = priv; |
4939 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
8856462d JM |
4940 | struct wpa_scan_results *res; |
4941 | ||
4942 | res = nl80211_get_scan_results(drv); | |
4943 | if (res) | |
4944 | wpa_driver_nl80211_check_bss_status(drv, res); | |
4945 | return res; | |
4946 | } | |
4947 | ||
4948 | ||
4949 | static void nl80211_dump_scan(struct wpa_driver_nl80211_data *drv) | |
4950 | { | |
4951 | struct wpa_scan_results *res; | |
4952 | size_t i; | |
4953 | ||
4954 | res = nl80211_get_scan_results(drv); | |
4955 | if (res == NULL) { | |
4956 | wpa_printf(MSG_DEBUG, "nl80211: Failed to get scan results"); | |
4957 | return; | |
4958 | } | |
4959 | ||
4960 | wpa_printf(MSG_DEBUG, "nl80211: Scan result dump"); | |
4961 | for (i = 0; i < res->num; i++) { | |
4962 | struct wpa_scan_res *r = res->res[i]; | |
4963 | wpa_printf(MSG_DEBUG, "nl80211: %d/%d " MACSTR "%s%s", | |
4964 | (int) i, (int) res->num, MAC2STR(r->bssid), | |
4965 | r->flags & WPA_SCAN_AUTHENTICATED ? " [auth]" : "", | |
4966 | r->flags & WPA_SCAN_ASSOCIATED ? " [assoc]" : ""); | |
4967 | } | |
4968 | ||
4969 | wpa_scan_results_free(res); | |
4970 | } | |
4971 | ||
4972 | ||
9ebce9c5 | 4973 | static int wpa_driver_nl80211_set_key(const char *ifname, struct i802_bss *bss, |
71934751 JM |
4974 | enum wpa_alg alg, const u8 *addr, |
4975 | int key_idx, int set_tx, | |
642187d6 JM |
4976 | const u8 *seq, size_t seq_len, |
4977 | const u8 *key, size_t key_len) | |
3f5285e8 | 4978 | { |
a2e40bb6 | 4979 | struct wpa_driver_nl80211_data *drv = bss->drv; |
e472e1b4 | 4980 | int ifindex; |
3f5285e8 | 4981 | struct nl_msg *msg; |
1ad1cdc2 | 4982 | int ret; |
dc01de8a | 4983 | int tdls = 0; |
3f5285e8 | 4984 | |
e472e1b4 AS |
4985 | /* Ignore for P2P Device */ |
4986 | if (drv->nlmode == NL80211_IFTYPE_P2P_DEVICE) | |
4987 | return 0; | |
4988 | ||
4989 | ifindex = if_nametoindex(ifname); | |
8393e1a0 | 4990 | wpa_printf(MSG_DEBUG, "%s: ifindex=%d (%s) alg=%d addr=%p key_idx=%d " |
1ad1cdc2 | 4991 | "set_tx=%d seq_len=%lu key_len=%lu", |
8393e1a0 | 4992 | __func__, ifindex, ifname, alg, addr, key_idx, set_tx, |
3f5285e8 | 4993 | (unsigned long) seq_len, (unsigned long) key_len); |
8c66e185 | 4994 | #ifdef CONFIG_TDLS |
dc01de8a | 4995 | if (key_idx == -1) { |
8c66e185 | 4996 | key_idx = 0; |
dc01de8a JM |
4997 | tdls = 1; |
4998 | } | |
8c66e185 | 4999 | #endif /* CONFIG_TDLS */ |
3f5285e8 JM |
5000 | |
5001 | msg = nlmsg_alloc(); | |
1ad1cdc2 JM |
5002 | if (!msg) |
5003 | return -ENOMEM; | |
3f5285e8 JM |
5004 | |
5005 | if (alg == WPA_ALG_NONE) { | |
9fb04070 | 5006 | nl80211_cmd(drv, msg, 0, NL80211_CMD_DEL_KEY); |
3f5285e8 | 5007 | } else { |
9fb04070 | 5008 | nl80211_cmd(drv, msg, 0, NL80211_CMD_NEW_KEY); |
3f5285e8 | 5009 | NLA_PUT(msg, NL80211_ATTR_KEY_DATA, key_len, key); |
d723bab4 JM |
5010 | switch (alg) { |
5011 | case WPA_ALG_WEP: | |
5012 | if (key_len == 5) | |
5013 | NLA_PUT_U32(msg, NL80211_ATTR_KEY_CIPHER, | |
5014 | WLAN_CIPHER_SUITE_WEP40); | |
5015 | else | |
5016 | NLA_PUT_U32(msg, NL80211_ATTR_KEY_CIPHER, | |
5017 | WLAN_CIPHER_SUITE_WEP104); | |
5018 | break; | |
5019 | case WPA_ALG_TKIP: | |
5020 | NLA_PUT_U32(msg, NL80211_ATTR_KEY_CIPHER, | |
5021 | WLAN_CIPHER_SUITE_TKIP); | |
5022 | break; | |
5023 | case WPA_ALG_CCMP: | |
5024 | NLA_PUT_U32(msg, NL80211_ATTR_KEY_CIPHER, | |
5025 | WLAN_CIPHER_SUITE_CCMP); | |
5026 | break; | |
eb7719ff JM |
5027 | case WPA_ALG_GCMP: |
5028 | NLA_PUT_U32(msg, NL80211_ATTR_KEY_CIPHER, | |
5029 | WLAN_CIPHER_SUITE_GCMP); | |
5030 | break; | |
d723bab4 JM |
5031 | case WPA_ALG_IGTK: |
5032 | NLA_PUT_U32(msg, NL80211_ATTR_KEY_CIPHER, | |
5033 | WLAN_CIPHER_SUITE_AES_CMAC); | |
5034 | break; | |
369c8d7b JM |
5035 | case WPA_ALG_SMS4: |
5036 | NLA_PUT_U32(msg, NL80211_ATTR_KEY_CIPHER, | |
5037 | WLAN_CIPHER_SUITE_SMS4); | |
5038 | break; | |
5039 | case WPA_ALG_KRK: | |
5040 | NLA_PUT_U32(msg, NL80211_ATTR_KEY_CIPHER, | |
5041 | WLAN_CIPHER_SUITE_KRK); | |
5042 | break; | |
d723bab4 JM |
5043 | default: |
5044 | wpa_printf(MSG_ERROR, "%s: Unsupported encryption " | |
5045 | "algorithm %d", __func__, alg); | |
3f5285e8 JM |
5046 | nlmsg_free(msg); |
5047 | return -1; | |
5048 | } | |
5049 | } | |
5050 | ||
849ef835 | 5051 | if (seq && seq_len) |
1ad1cdc2 JM |
5052 | NLA_PUT(msg, NL80211_ATTR_KEY_SEQ, seq_len, seq); |
5053 | ||
0382097e | 5054 | if (addr && !is_broadcast_ether_addr(addr)) { |
3f5285e8 JM |
5055 | wpa_printf(MSG_DEBUG, " addr=" MACSTR, MAC2STR(addr)); |
5056 | NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, addr); | |
89c38e32 JM |
5057 | |
5058 | if (alg != WPA_ALG_WEP && key_idx && !set_tx) { | |
5059 | wpa_printf(MSG_DEBUG, " RSN IBSS RX GTK"); | |
5060 | NLA_PUT_U32(msg, NL80211_ATTR_KEY_TYPE, | |
5061 | NL80211_KEYTYPE_GROUP); | |
5062 | } | |
60ea8187 | 5063 | } else if (addr && is_broadcast_ether_addr(addr)) { |
8970bae8 JB |
5064 | struct nlattr *types; |
5065 | ||
60ea8187 | 5066 | wpa_printf(MSG_DEBUG, " broadcast key"); |
8970bae8 JB |
5067 | |
5068 | types = nla_nest_start(msg, NL80211_ATTR_KEY_DEFAULT_TYPES); | |
60ea8187 JM |
5069 | if (!types) |
5070 | goto nla_put_failure; | |
8970bae8 JB |
5071 | NLA_PUT_FLAG(msg, NL80211_KEY_DEFAULT_TYPE_MULTICAST); |
5072 | nla_nest_end(msg, types); | |
3f5285e8 JM |
5073 | } |
5074 | NLA_PUT_U8(msg, NL80211_ATTR_KEY_IDX, key_idx); | |
1ad1cdc2 | 5075 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, ifindex); |
3f5285e8 | 5076 | |
1ad1cdc2 | 5077 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
15664ad0 | 5078 | if ((ret == -ENOENT || ret == -ENOLINK) && alg == WPA_ALG_NONE) |
1ad1cdc2 JM |
5079 | ret = 0; |
5080 | if (ret) | |
5081 | wpa_printf(MSG_DEBUG, "nl80211: set_key failed; err=%d %s)", | |
5082 | ret, strerror(-ret)); | |
3f5285e8 | 5083 | |
1ad1cdc2 JM |
5084 | /* |
5085 | * If we failed or don't need to set the default TX key (below), | |
5086 | * we're done here. | |
5087 | */ | |
dc01de8a | 5088 | if (ret || !set_tx || alg == WPA_ALG_NONE || tdls) |
1ad1cdc2 | 5089 | return ret; |
b1f625e0 | 5090 | if (is_ap_interface(drv->nlmode) && addr && |
0382097e | 5091 | !is_broadcast_ether_addr(addr)) |
de12717a | 5092 | return ret; |
3f5285e8 | 5093 | |
1ad1cdc2 JM |
5094 | msg = nlmsg_alloc(); |
5095 | if (!msg) | |
5096 | return -ENOMEM; | |
3f5285e8 | 5097 | |
9fb04070 | 5098 | nl80211_cmd(drv, msg, 0, NL80211_CMD_SET_KEY); |
1ad1cdc2 JM |
5099 | NLA_PUT_U8(msg, NL80211_ATTR_KEY_IDX, key_idx); |
5100 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, ifindex); | |
5101 | if (alg == WPA_ALG_IGTK) | |
5102 | NLA_PUT_FLAG(msg, NL80211_ATTR_KEY_DEFAULT_MGMT); | |
5103 | else | |
5104 | NLA_PUT_FLAG(msg, NL80211_ATTR_KEY_DEFAULT); | |
60ea8187 | 5105 | if (addr && is_broadcast_ether_addr(addr)) { |
8970bae8 JB |
5106 | struct nlattr *types; |
5107 | ||
5108 | types = nla_nest_start(msg, NL80211_ATTR_KEY_DEFAULT_TYPES); | |
60ea8187 JM |
5109 | if (!types) |
5110 | goto nla_put_failure; | |
8970bae8 JB |
5111 | NLA_PUT_FLAG(msg, NL80211_KEY_DEFAULT_TYPE_MULTICAST); |
5112 | nla_nest_end(msg, types); | |
60ea8187 | 5113 | } else if (addr) { |
8970bae8 JB |
5114 | struct nlattr *types; |
5115 | ||
5116 | types = nla_nest_start(msg, NL80211_ATTR_KEY_DEFAULT_TYPES); | |
60ea8187 JM |
5117 | if (!types) |
5118 | goto nla_put_failure; | |
8970bae8 JB |
5119 | NLA_PUT_FLAG(msg, NL80211_KEY_DEFAULT_TYPE_UNICAST); |
5120 | nla_nest_end(msg, types); | |
60ea8187 | 5121 | } |
3f5285e8 | 5122 | |
1ad1cdc2 JM |
5123 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
5124 | if (ret == -ENOENT) | |
5125 | ret = 0; | |
5126 | if (ret) | |
5127 | wpa_printf(MSG_DEBUG, "nl80211: set_key default failed; " | |
5128 | "err=%d %s)", ret, strerror(-ret)); | |
5129 | return ret; | |
3f5285e8 JM |
5130 | |
5131 | nla_put_failure: | |
5883168a | 5132 | nlmsg_free(msg); |
6241fcb1 | 5133 | return -ENOBUFS; |
3f5285e8 JM |
5134 | } |
5135 | ||
5136 | ||
71934751 | 5137 | static int nl_add_key(struct nl_msg *msg, enum wpa_alg alg, |
0194fedb JB |
5138 | int key_idx, int defkey, |
5139 | const u8 *seq, size_t seq_len, | |
5140 | const u8 *key, size_t key_len) | |
5141 | { | |
5142 | struct nlattr *key_attr = nla_nest_start(msg, NL80211_ATTR_KEY); | |
5143 | if (!key_attr) | |
5144 | return -1; | |
5145 | ||
5146 | if (defkey && alg == WPA_ALG_IGTK) | |
5147 | NLA_PUT_FLAG(msg, NL80211_KEY_DEFAULT_MGMT); | |
5148 | else if (defkey) | |
5149 | NLA_PUT_FLAG(msg, NL80211_KEY_DEFAULT); | |
5150 | ||
5151 | NLA_PUT_U8(msg, NL80211_KEY_IDX, key_idx); | |
5152 | ||
d723bab4 JM |
5153 | switch (alg) { |
5154 | case WPA_ALG_WEP: | |
5155 | if (key_len == 5) | |
2aa5f847 JM |
5156 | NLA_PUT_U32(msg, NL80211_KEY_CIPHER, |
5157 | WLAN_CIPHER_SUITE_WEP40); | |
d723bab4 | 5158 | else |
2aa5f847 JM |
5159 | NLA_PUT_U32(msg, NL80211_KEY_CIPHER, |
5160 | WLAN_CIPHER_SUITE_WEP104); | |
d723bab4 JM |
5161 | break; |
5162 | case WPA_ALG_TKIP: | |
2aa5f847 | 5163 | NLA_PUT_U32(msg, NL80211_KEY_CIPHER, WLAN_CIPHER_SUITE_TKIP); |
d723bab4 JM |
5164 | break; |
5165 | case WPA_ALG_CCMP: | |
2aa5f847 | 5166 | NLA_PUT_U32(msg, NL80211_KEY_CIPHER, WLAN_CIPHER_SUITE_CCMP); |
d723bab4 | 5167 | break; |
eb7719ff JM |
5168 | case WPA_ALG_GCMP: |
5169 | NLA_PUT_U32(msg, NL80211_KEY_CIPHER, WLAN_CIPHER_SUITE_GCMP); | |
5170 | break; | |
d723bab4 | 5171 | case WPA_ALG_IGTK: |
2aa5f847 JM |
5172 | NLA_PUT_U32(msg, NL80211_KEY_CIPHER, |
5173 | WLAN_CIPHER_SUITE_AES_CMAC); | |
d723bab4 JM |
5174 | break; |
5175 | default: | |
5176 | wpa_printf(MSG_ERROR, "%s: Unsupported encryption " | |
5177 | "algorithm %d", __func__, alg); | |
0194fedb | 5178 | return -1; |
d723bab4 | 5179 | } |
0194fedb JB |
5180 | |
5181 | if (seq && seq_len) | |
5182 | NLA_PUT(msg, NL80211_KEY_SEQ, seq_len, seq); | |
5183 | ||
5184 | NLA_PUT(msg, NL80211_KEY_DATA, key_len, key); | |
5185 | ||
5186 | nla_nest_end(msg, key_attr); | |
5187 | ||
5188 | return 0; | |
5189 | nla_put_failure: | |
5190 | return -1; | |
5191 | } | |
5192 | ||
c811d5bc | 5193 | |
cfaab580 ZY |
5194 | static int nl80211_set_conn_keys(struct wpa_driver_associate_params *params, |
5195 | struct nl_msg *msg) | |
5196 | { | |
5197 | int i, privacy = 0; | |
5198 | struct nlattr *nl_keys, *nl_key; | |
5199 | ||
5200 | for (i = 0; i < 4; i++) { | |
5201 | if (!params->wep_key[i]) | |
5202 | continue; | |
5203 | privacy = 1; | |
5204 | break; | |
5205 | } | |
ce04af5a JM |
5206 | if (params->wps == WPS_MODE_PRIVACY) |
5207 | privacy = 1; | |
5208 | if (params->pairwise_suite && | |
5209 | params->pairwise_suite != WPA_CIPHER_NONE) | |
5210 | privacy = 1; | |
5211 | ||
cfaab580 ZY |
5212 | if (!privacy) |
5213 | return 0; | |
5214 | ||
5215 | NLA_PUT_FLAG(msg, NL80211_ATTR_PRIVACY); | |
5216 | ||
5217 | nl_keys = nla_nest_start(msg, NL80211_ATTR_KEYS); | |
5218 | if (!nl_keys) | |
5219 | goto nla_put_failure; | |
5220 | ||
5221 | for (i = 0; i < 4; i++) { | |
5222 | if (!params->wep_key[i]) | |
5223 | continue; | |
5224 | ||
5225 | nl_key = nla_nest_start(msg, i); | |
5226 | if (!nl_key) | |
5227 | goto nla_put_failure; | |
5228 | ||
5229 | NLA_PUT(msg, NL80211_KEY_DATA, params->wep_key_len[i], | |
5230 | params->wep_key[i]); | |
5231 | if (params->wep_key_len[i] == 5) | |
5232 | NLA_PUT_U32(msg, NL80211_KEY_CIPHER, | |
5233 | WLAN_CIPHER_SUITE_WEP40); | |
5234 | else | |
5235 | NLA_PUT_U32(msg, NL80211_KEY_CIPHER, | |
5236 | WLAN_CIPHER_SUITE_WEP104); | |
5237 | ||
5238 | NLA_PUT_U8(msg, NL80211_KEY_IDX, i); | |
5239 | ||
5240 | if (i == params->wep_tx_keyidx) | |
5241 | NLA_PUT_FLAG(msg, NL80211_KEY_DEFAULT); | |
5242 | ||
5243 | nla_nest_end(msg, nl_key); | |
5244 | } | |
5245 | nla_nest_end(msg, nl_keys); | |
5246 | ||
5247 | return 0; | |
5248 | ||
5249 | nla_put_failure: | |
5250 | return -ENOBUFS; | |
5251 | } | |
5252 | ||
5253 | ||
c2a04078 | 5254 | static int wpa_driver_nl80211_mlme(struct wpa_driver_nl80211_data *drv, |
77339912 JM |
5255 | const u8 *addr, int cmd, u16 reason_code, |
5256 | int local_state_change) | |
c2a04078 JM |
5257 | { |
5258 | int ret = -1; | |
5259 | struct nl_msg *msg; | |
5260 | ||
5261 | msg = nlmsg_alloc(); | |
5262 | if (!msg) | |
5263 | return -1; | |
5264 | ||
9fb04070 | 5265 | nl80211_cmd(drv, msg, 0, cmd); |
c2a04078 JM |
5266 | |
5267 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, drv->ifindex); | |
5268 | NLA_PUT_U16(msg, NL80211_ATTR_REASON_CODE, reason_code); | |
817762d9 MI |
5269 | if (addr) |
5270 | NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, addr); | |
77339912 JM |
5271 | if (local_state_change) |
5272 | NLA_PUT_FLAG(msg, NL80211_ATTR_LOCAL_STATE_CHANGE); | |
c2a04078 JM |
5273 | |
5274 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); | |
5275 | msg = NULL; | |
5276 | if (ret) { | |
3b7ea880 BG |
5277 | wpa_dbg(drv->ctx, MSG_DEBUG, |
5278 | "nl80211: MLME command failed: reason=%u ret=%d (%s)", | |
5279 | reason_code, ret, strerror(-ret)); | |
c2a04078 JM |
5280 | goto nla_put_failure; |
5281 | } | |
5282 | ret = 0; | |
5283 | ||
5284 | nla_put_failure: | |
5285 | nlmsg_free(msg); | |
5286 | return ret; | |
5287 | } | |
3f5285e8 JM |
5288 | |
5289 | ||
cfaab580 | 5290 | static int wpa_driver_nl80211_disconnect(struct wpa_driver_nl80211_data *drv, |
817762d9 | 5291 | int reason_code) |
cfaab580 | 5292 | { |
3f53c006 JJ |
5293 | int ret; |
5294 | ||
817762d9 | 5295 | wpa_printf(MSG_DEBUG, "%s(reason_code=%d)", __func__, reason_code); |
add9b7a4 | 5296 | nl80211_mark_disconnected(drv); |
817762d9 | 5297 | /* Disconnect command doesn't need BSSID - it uses cached value */ |
3f53c006 JJ |
5298 | ret = wpa_driver_nl80211_mlme(drv, NULL, NL80211_CMD_DISCONNECT, |
5299 | reason_code, 0); | |
5300 | /* | |
5301 | * For locally generated disconnect, supplicant already generates a | |
5302 | * DEAUTH event, so ignore the event from NL80211. | |
5303 | */ | |
5304 | drv->ignore_next_local_disconnect = ret == 0; | |
5305 | ||
5306 | return ret; | |
cfaab580 ZY |
5307 | } |
5308 | ||
5309 | ||
9ebce9c5 JM |
5310 | static int wpa_driver_nl80211_deauthenticate(struct i802_bss *bss, |
5311 | const u8 *addr, int reason_code) | |
3f5285e8 | 5312 | { |
a2e40bb6 | 5313 | struct wpa_driver_nl80211_data *drv = bss->drv; |
cfaab580 | 5314 | if (!(drv->capa.flags & WPA_DRIVER_FLAGS_SME)) |
817762d9 | 5315 | return wpa_driver_nl80211_disconnect(drv, reason_code); |
2e75a2b3 JM |
5316 | wpa_printf(MSG_DEBUG, "%s(addr=" MACSTR " reason_code=%d)", |
5317 | __func__, MAC2STR(addr), reason_code); | |
add9b7a4 | 5318 | nl80211_mark_disconnected(drv); |
21bdbe38 JM |
5319 | if (drv->nlmode == NL80211_IFTYPE_ADHOC) |
5320 | return nl80211_leave_ibss(drv); | |
c2a04078 | 5321 | return wpa_driver_nl80211_mlme(drv, addr, NL80211_CMD_DEAUTHENTICATE, |
77339912 | 5322 | reason_code, 0); |
3f5285e8 JM |
5323 | } |
5324 | ||
5325 | ||
536fd62d JM |
5326 | static void nl80211_copy_auth_params(struct wpa_driver_nl80211_data *drv, |
5327 | struct wpa_driver_auth_params *params) | |
5328 | { | |
5329 | int i; | |
5330 | ||
5331 | drv->auth_freq = params->freq; | |
5332 | drv->auth_alg = params->auth_alg; | |
5333 | drv->auth_wep_tx_keyidx = params->wep_tx_keyidx; | |
5334 | drv->auth_local_state_change = params->local_state_change; | |
5335 | drv->auth_p2p = params->p2p; | |
5336 | ||
5337 | if (params->bssid) | |
5338 | os_memcpy(drv->auth_bssid_, params->bssid, ETH_ALEN); | |
5339 | else | |
5340 | os_memset(drv->auth_bssid_, 0, ETH_ALEN); | |
5341 | ||
5342 | if (params->ssid) { | |
5343 | os_memcpy(drv->auth_ssid, params->ssid, params->ssid_len); | |
5344 | drv->auth_ssid_len = params->ssid_len; | |
5345 | } else | |
5346 | drv->auth_ssid_len = 0; | |
5347 | ||
5348 | ||
5349 | os_free(drv->auth_ie); | |
5350 | drv->auth_ie = NULL; | |
5351 | drv->auth_ie_len = 0; | |
5352 | if (params->ie) { | |
5353 | drv->auth_ie = os_malloc(params->ie_len); | |
5354 | if (drv->auth_ie) { | |
5355 | os_memcpy(drv->auth_ie, params->ie, params->ie_len); | |
5356 | drv->auth_ie_len = params->ie_len; | |
5357 | } | |
5358 | } | |
5359 | ||
5360 | for (i = 0; i < 4; i++) { | |
5361 | if (params->wep_key[i] && params->wep_key_len[i] && | |
5362 | params->wep_key_len[i] <= 16) { | |
5363 | os_memcpy(drv->auth_wep_key[i], params->wep_key[i], | |
5364 | params->wep_key_len[i]); | |
5365 | drv->auth_wep_key_len[i] = params->wep_key_len[i]; | |
5366 | } else | |
5367 | drv->auth_wep_key_len[i] = 0; | |
5368 | } | |
5369 | } | |
5370 | ||
5371 | ||
c2a04078 | 5372 | static int wpa_driver_nl80211_authenticate( |
9ebce9c5 | 5373 | struct i802_bss *bss, struct wpa_driver_auth_params *params) |
c2a04078 | 5374 | { |
a2e40bb6 | 5375 | struct wpa_driver_nl80211_data *drv = bss->drv; |
a0b2f99b | 5376 | int ret = -1, i; |
c2a04078 JM |
5377 | struct nl_msg *msg; |
5378 | enum nl80211_auth_type type; | |
2f4f73b1 | 5379 | enum nl80211_iftype nlmode; |
6d6f4bb8 | 5380 | int count = 0; |
536fd62d JM |
5381 | int is_retry; |
5382 | ||
5383 | is_retry = drv->retry_auth; | |
5384 | drv->retry_auth = 0; | |
c2a04078 | 5385 | |
add9b7a4 | 5386 | nl80211_mark_disconnected(drv); |
e6b8efeb | 5387 | os_memset(drv->auth_bssid, 0, ETH_ALEN); |
add9b7a4 JM |
5388 | if (params->bssid) |
5389 | os_memcpy(drv->auth_attempt_bssid, params->bssid, ETH_ALEN); | |
5390 | else | |
5391 | os_memset(drv->auth_attempt_bssid, 0, ETH_ALEN); | |
af473088 | 5392 | /* FIX: IBSS mode */ |
2f4f73b1 EP |
5393 | nlmode = params->p2p ? |
5394 | NL80211_IFTYPE_P2P_CLIENT : NL80211_IFTYPE_STATION; | |
5395 | if (drv->nlmode != nlmode && | |
9ebce9c5 | 5396 | wpa_driver_nl80211_set_mode(bss, nlmode) < 0) |
4a867032 JM |
5397 | return -1; |
5398 | ||
6d6f4bb8 | 5399 | retry: |
c2a04078 JM |
5400 | msg = nlmsg_alloc(); |
5401 | if (!msg) | |
5402 | return -1; | |
5403 | ||
5404 | wpa_printf(MSG_DEBUG, "nl80211: Authenticate (ifindex=%d)", | |
5405 | drv->ifindex); | |
a0b2f99b | 5406 | |
9fb04070 | 5407 | nl80211_cmd(drv, msg, 0, NL80211_CMD_AUTHENTICATE); |
0194fedb | 5408 | |
a0b2f99b JM |
5409 | for (i = 0; i < 4; i++) { |
5410 | if (!params->wep_key[i]) | |
5411 | continue; | |
9ebce9c5 | 5412 | wpa_driver_nl80211_set_key(bss->ifname, bss, WPA_ALG_WEP, |
2ea2fcc7 | 5413 | NULL, i, |
a0b2f99b JM |
5414 | i == params->wep_tx_keyidx, NULL, 0, |
5415 | params->wep_key[i], | |
5416 | params->wep_key_len[i]); | |
0194fedb JB |
5417 | if (params->wep_tx_keyidx != i) |
5418 | continue; | |
5419 | if (nl_add_key(msg, WPA_ALG_WEP, i, 1, NULL, 0, | |
5420 | params->wep_key[i], params->wep_key_len[i])) { | |
5421 | nlmsg_free(msg); | |
5422 | return -1; | |
5423 | } | |
a0b2f99b JM |
5424 | } |
5425 | ||
c2a04078 JM |
5426 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, drv->ifindex); |
5427 | if (params->bssid) { | |
5428 | wpa_printf(MSG_DEBUG, " * bssid=" MACSTR, | |
5429 | MAC2STR(params->bssid)); | |
5430 | NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, params->bssid); | |
5431 | } | |
5432 | if (params->freq) { | |
5433 | wpa_printf(MSG_DEBUG, " * freq=%d", params->freq); | |
5434 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_FREQ, params->freq); | |
5435 | } | |
5436 | if (params->ssid) { | |
5437 | wpa_hexdump_ascii(MSG_DEBUG, " * SSID", | |
5438 | params->ssid, params->ssid_len); | |
5439 | NLA_PUT(msg, NL80211_ATTR_SSID, params->ssid_len, | |
5440 | params->ssid); | |
5441 | } | |
5442 | wpa_hexdump(MSG_DEBUG, " * IEs", params->ie, params->ie_len); | |
5443 | if (params->ie) | |
5444 | NLA_PUT(msg, NL80211_ATTR_IE, params->ie_len, params->ie); | |
569fed90 JM |
5445 | if (params->sae_data) { |
5446 | wpa_hexdump(MSG_DEBUG, " * SAE data", params->sae_data, | |
5447 | params->sae_data_len); | |
5448 | NLA_PUT(msg, NL80211_ATTR_SAE_DATA, params->sae_data_len, | |
5449 | params->sae_data); | |
5450 | } | |
abd9fafa | 5451 | if (params->auth_alg & WPA_AUTH_ALG_OPEN) |
c2a04078 | 5452 | type = NL80211_AUTHTYPE_OPEN_SYSTEM; |
abd9fafa | 5453 | else if (params->auth_alg & WPA_AUTH_ALG_SHARED) |
c2a04078 | 5454 | type = NL80211_AUTHTYPE_SHARED_KEY; |
abd9fafa | 5455 | else if (params->auth_alg & WPA_AUTH_ALG_LEAP) |
c2a04078 | 5456 | type = NL80211_AUTHTYPE_NETWORK_EAP; |
abd9fafa | 5457 | else if (params->auth_alg & WPA_AUTH_ALG_FT) |
c2a04078 | 5458 | type = NL80211_AUTHTYPE_FT; |
569fed90 JM |
5459 | else if (params->auth_alg & WPA_AUTH_ALG_SAE) |
5460 | type = NL80211_AUTHTYPE_SAE; | |
c2a04078 JM |
5461 | else |
5462 | goto nla_put_failure; | |
5463 | wpa_printf(MSG_DEBUG, " * Auth Type %d", type); | |
5464 | NLA_PUT_U32(msg, NL80211_ATTR_AUTH_TYPE, type); | |
77339912 JM |
5465 | if (params->local_state_change) { |
5466 | wpa_printf(MSG_DEBUG, " * Local state change only"); | |
5467 | NLA_PUT_FLAG(msg, NL80211_ATTR_LOCAL_STATE_CHANGE); | |
5468 | } | |
c2a04078 JM |
5469 | |
5470 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); | |
5471 | msg = NULL; | |
5472 | if (ret) { | |
3b7ea880 BG |
5473 | wpa_dbg(drv->ctx, MSG_DEBUG, |
5474 | "nl80211: MLME command failed (auth): ret=%d (%s)", | |
5475 | ret, strerror(-ret)); | |
6d6f4bb8 | 5476 | count++; |
77339912 JM |
5477 | if (ret == -EALREADY && count == 1 && params->bssid && |
5478 | !params->local_state_change) { | |
6d6f4bb8 JM |
5479 | /* |
5480 | * mac80211 does not currently accept new | |
5481 | * authentication if we are already authenticated. As a | |
5482 | * workaround, force deauthentication and try again. | |
5483 | */ | |
5484 | wpa_printf(MSG_DEBUG, "nl80211: Retry authentication " | |
5485 | "after forced deauthentication"); | |
5486 | wpa_driver_nl80211_deauthenticate( | |
5205c4f9 | 5487 | bss, params->bssid, |
6d6f4bb8 JM |
5488 | WLAN_REASON_PREV_AUTH_NOT_VALID); |
5489 | nlmsg_free(msg); | |
5490 | goto retry; | |
5491 | } | |
536fd62d JM |
5492 | |
5493 | if (ret == -ENOENT && params->freq && !is_retry) { | |
5494 | /* | |
5495 | * cfg80211 has likely expired the BSS entry even | |
5496 | * though it was previously available in our internal | |
5497 | * BSS table. To recover quickly, start a single | |
5498 | * channel scan on the specified channel. | |
5499 | */ | |
5500 | struct wpa_driver_scan_params scan; | |
5501 | int freqs[2]; | |
5502 | ||
5503 | os_memset(&scan, 0, sizeof(scan)); | |
5504 | scan.num_ssids = 1; | |
5505 | if (params->ssid) { | |
5506 | scan.ssids[0].ssid = params->ssid; | |
5507 | scan.ssids[0].ssid_len = params->ssid_len; | |
5508 | } | |
5509 | freqs[0] = params->freq; | |
5510 | freqs[1] = 0; | |
5511 | scan.freqs = freqs; | |
5512 | wpa_printf(MSG_DEBUG, "nl80211: Trigger single " | |
5513 | "channel scan to refresh cfg80211 BSS " | |
5514 | "entry"); | |
5515 | ret = wpa_driver_nl80211_scan(bss, &scan); | |
5516 | if (ret == 0) { | |
5517 | nl80211_copy_auth_params(drv, params); | |
5518 | drv->scan_for_auth = 1; | |
5519 | } | |
8c3ba078 JM |
5520 | } else if (is_retry) { |
5521 | /* | |
5522 | * Need to indicate this with an event since the return | |
5523 | * value from the retry is not delivered to core code. | |
5524 | */ | |
5525 | union wpa_event_data event; | |
5526 | wpa_printf(MSG_DEBUG, "nl80211: Authentication retry " | |
5527 | "failed"); | |
5528 | os_memset(&event, 0, sizeof(event)); | |
5529 | os_memcpy(event.timeout_event.addr, drv->auth_bssid_, | |
5530 | ETH_ALEN); | |
5531 | wpa_supplicant_event(drv->ctx, EVENT_AUTH_TIMED_OUT, | |
5532 | &event); | |
536fd62d JM |
5533 | } |
5534 | ||
c2a04078 JM |
5535 | goto nla_put_failure; |
5536 | } | |
5537 | ret = 0; | |
5538 | wpa_printf(MSG_DEBUG, "nl80211: Authentication request send " | |
5539 | "successfully"); | |
5540 | ||
5541 | nla_put_failure: | |
5542 | nlmsg_free(msg); | |
5543 | return ret; | |
5544 | } | |
5545 | ||
5546 | ||
536fd62d JM |
5547 | static int wpa_driver_nl80211_authenticate_retry( |
5548 | struct wpa_driver_nl80211_data *drv) | |
5549 | { | |
5550 | struct wpa_driver_auth_params params; | |
5551 | struct i802_bss *bss = &drv->first_bss; | |
5552 | int i; | |
5553 | ||
5554 | wpa_printf(MSG_DEBUG, "nl80211: Try to authenticate again"); | |
5555 | ||
5556 | os_memset(¶ms, 0, sizeof(params)); | |
5557 | params.freq = drv->auth_freq; | |
5558 | params.auth_alg = drv->auth_alg; | |
5559 | params.wep_tx_keyidx = drv->auth_wep_tx_keyidx; | |
5560 | params.local_state_change = drv->auth_local_state_change; | |
5561 | params.p2p = drv->auth_p2p; | |
5562 | ||
5563 | if (!is_zero_ether_addr(drv->auth_bssid_)) | |
5564 | params.bssid = drv->auth_bssid_; | |
5565 | ||
5566 | if (drv->auth_ssid_len) { | |
5567 | params.ssid = drv->auth_ssid; | |
5568 | params.ssid_len = drv->auth_ssid_len; | |
5569 | } | |
5570 | ||
5571 | params.ie = drv->auth_ie; | |
5572 | params.ie_len = drv->auth_ie_len; | |
5573 | ||
5574 | for (i = 0; i < 4; i++) { | |
5575 | if (drv->auth_wep_key_len[i]) { | |
5576 | params.wep_key[i] = drv->auth_wep_key[i]; | |
5577 | params.wep_key_len[i] = drv->auth_wep_key_len[i]; | |
5578 | } | |
5579 | } | |
5580 | ||
5581 | drv->retry_auth = 1; | |
5582 | return wpa_driver_nl80211_authenticate(bss, ¶ms); | |
5583 | } | |
5584 | ||
5585 | ||
282d5590 JM |
5586 | struct phy_info_arg { |
5587 | u16 *num_modes; | |
5588 | struct hostapd_hw_modes *modes; | |
43245552 | 5589 | int last_mode, last_chan_idx; |
282d5590 JM |
5590 | }; |
5591 | ||
e62a1d43 JM |
5592 | static void phy_info_ht_capa(struct hostapd_hw_modes *mode, struct nlattr *capa, |
5593 | struct nlattr *ampdu_factor, | |
5594 | struct nlattr *ampdu_density, | |
5595 | struct nlattr *mcs_set) | |
5596 | { | |
5597 | if (capa) | |
5598 | mode->ht_capab = nla_get_u16(capa); | |
5599 | ||
5600 | if (ampdu_factor) | |
5601 | mode->a_mpdu_params |= nla_get_u8(ampdu_factor) & 0x03; | |
5602 | ||
5603 | if (ampdu_density) | |
5604 | mode->a_mpdu_params |= nla_get_u8(ampdu_density) << 2; | |
5605 | ||
5606 | if (mcs_set && nla_len(mcs_set) >= 16) { | |
5607 | u8 *mcs; | |
5608 | mcs = nla_data(mcs_set); | |
5609 | os_memcpy(mode->mcs_set, mcs, 16); | |
5610 | } | |
5611 | } | |
5612 | ||
5613 | ||
5614 | static void phy_info_vht_capa(struct hostapd_hw_modes *mode, | |
5615 | struct nlattr *capa, | |
5616 | struct nlattr *mcs_set) | |
5617 | { | |
5618 | if (capa) | |
5619 | mode->vht_capab = nla_get_u32(capa); | |
5620 | ||
5621 | if (mcs_set && nla_len(mcs_set) >= 8) { | |
5622 | u8 *mcs; | |
5623 | mcs = nla_data(mcs_set); | |
5624 | os_memcpy(mode->vht_mcs_set, mcs, 8); | |
5625 | } | |
5626 | } | |
5627 | ||
5628 | ||
214a77b0 JM |
5629 | static void phy_info_freq(struct hostapd_hw_modes *mode, |
5630 | struct hostapd_channel_data *chan, | |
5631 | struct nlattr *tb_freq[]) | |
5632 | { | |
e864c0ae | 5633 | u8 channel; |
214a77b0 JM |
5634 | chan->freq = nla_get_u32(tb_freq[NL80211_FREQUENCY_ATTR_FREQ]); |
5635 | chan->flag = 0; | |
e864c0ae JM |
5636 | if (ieee80211_freq_to_chan(chan->freq, &channel) != NUM_HOSTAPD_MODES) |
5637 | chan->chan = channel; | |
214a77b0 JM |
5638 | |
5639 | if (tb_freq[NL80211_FREQUENCY_ATTR_DISABLED]) | |
5640 | chan->flag |= HOSTAPD_CHAN_DISABLED; | |
5641 | if (tb_freq[NL80211_FREQUENCY_ATTR_PASSIVE_SCAN]) | |
5642 | chan->flag |= HOSTAPD_CHAN_PASSIVE_SCAN; | |
5643 | if (tb_freq[NL80211_FREQUENCY_ATTR_NO_IBSS]) | |
5644 | chan->flag |= HOSTAPD_CHAN_NO_IBSS; | |
5645 | if (tb_freq[NL80211_FREQUENCY_ATTR_RADAR]) | |
5646 | chan->flag |= HOSTAPD_CHAN_RADAR; | |
5647 | ||
5648 | if (tb_freq[NL80211_FREQUENCY_ATTR_MAX_TX_POWER] && | |
5649 | !tb_freq[NL80211_FREQUENCY_ATTR_DISABLED]) | |
5650 | chan->max_tx_power = nla_get_u32( | |
5651 | tb_freq[NL80211_FREQUENCY_ATTR_MAX_TX_POWER]) / 100; | |
fc96522e SW |
5652 | if (tb_freq[NL80211_FREQUENCY_ATTR_DFS_STATE]) { |
5653 | enum nl80211_dfs_state state = | |
5654 | nla_get_u32(tb_freq[NL80211_FREQUENCY_ATTR_DFS_STATE]); | |
5655 | ||
5656 | switch (state) { | |
5657 | case NL80211_DFS_USABLE: | |
5658 | chan->flag |= HOSTAPD_CHAN_DFS_USABLE; | |
5659 | break; | |
5660 | case NL80211_DFS_AVAILABLE: | |
5661 | chan->flag |= HOSTAPD_CHAN_DFS_AVAILABLE; | |
5662 | break; | |
5663 | case NL80211_DFS_UNAVAILABLE: | |
5664 | chan->flag |= HOSTAPD_CHAN_DFS_UNAVAILABLE; | |
5665 | break; | |
5666 | } | |
5667 | } | |
214a77b0 JM |
5668 | } |
5669 | ||
5670 | ||
e62a1d43 JM |
5671 | static int phy_info_freqs(struct phy_info_arg *phy_info, |
5672 | struct hostapd_hw_modes *mode, struct nlattr *tb) | |
282d5590 | 5673 | { |
282d5590 JM |
5674 | static struct nla_policy freq_policy[NL80211_FREQUENCY_ATTR_MAX + 1] = { |
5675 | [NL80211_FREQUENCY_ATTR_FREQ] = { .type = NLA_U32 }, | |
5676 | [NL80211_FREQUENCY_ATTR_DISABLED] = { .type = NLA_FLAG }, | |
5677 | [NL80211_FREQUENCY_ATTR_PASSIVE_SCAN] = { .type = NLA_FLAG }, | |
5678 | [NL80211_FREQUENCY_ATTR_NO_IBSS] = { .type = NLA_FLAG }, | |
5679 | [NL80211_FREQUENCY_ATTR_RADAR] = { .type = NLA_FLAG }, | |
5680 | [NL80211_FREQUENCY_ATTR_MAX_TX_POWER] = { .type = NLA_U32 }, | |
fc96522e | 5681 | [NL80211_FREQUENCY_ATTR_DFS_STATE] = { .type = NLA_U32 }, |
282d5590 | 5682 | }; |
e62a1d43 JM |
5683 | int new_channels = 0; |
5684 | struct hostapd_channel_data *channel; | |
5685 | struct nlattr *tb_freq[NL80211_FREQUENCY_ATTR_MAX + 1]; | |
5686 | struct nlattr *nl_freq; | |
5687 | int rem_freq, idx; | |
5688 | ||
5689 | if (tb == NULL) | |
5690 | return NL_OK; | |
5691 | ||
5692 | nla_for_each_nested(nl_freq, tb, rem_freq) { | |
5693 | nla_parse(tb_freq, NL80211_FREQUENCY_ATTR_MAX, | |
5694 | nla_data(nl_freq), nla_len(nl_freq), freq_policy); | |
5695 | if (!tb_freq[NL80211_FREQUENCY_ATTR_FREQ]) | |
5696 | continue; | |
5697 | new_channels++; | |
5698 | } | |
5699 | ||
5700 | channel = os_realloc_array(mode->channels, | |
5701 | mode->num_channels + new_channels, | |
5702 | sizeof(struct hostapd_channel_data)); | |
5703 | if (!channel) | |
5704 | return NL_SKIP; | |
5705 | ||
5706 | mode->channels = channel; | |
5707 | mode->num_channels += new_channels; | |
5708 | ||
5709 | idx = phy_info->last_chan_idx; | |
5710 | ||
5711 | nla_for_each_nested(nl_freq, tb, rem_freq) { | |
5712 | nla_parse(tb_freq, NL80211_FREQUENCY_ATTR_MAX, | |
5713 | nla_data(nl_freq), nla_len(nl_freq), freq_policy); | |
5714 | if (!tb_freq[NL80211_FREQUENCY_ATTR_FREQ]) | |
5715 | continue; | |
214a77b0 | 5716 | phy_info_freq(mode, &mode->channels[idx], tb_freq); |
e62a1d43 JM |
5717 | idx++; |
5718 | } | |
5719 | phy_info->last_chan_idx = idx; | |
5720 | ||
5721 | return NL_OK; | |
5722 | } | |
5723 | ||
5724 | ||
5725 | static int phy_info_rates(struct hostapd_hw_modes *mode, struct nlattr *tb) | |
5726 | { | |
282d5590 JM |
5727 | static struct nla_policy rate_policy[NL80211_BITRATE_ATTR_MAX + 1] = { |
5728 | [NL80211_BITRATE_ATTR_RATE] = { .type = NLA_U32 }, | |
3cfcad1b JM |
5729 | [NL80211_BITRATE_ATTR_2GHZ_SHORTPREAMBLE] = |
5730 | { .type = NLA_FLAG }, | |
282d5590 | 5731 | }; |
e62a1d43 | 5732 | struct nlattr *tb_rate[NL80211_BITRATE_ATTR_MAX + 1]; |
282d5590 | 5733 | struct nlattr *nl_rate; |
e62a1d43 JM |
5734 | int rem_rate, idx; |
5735 | ||
5736 | if (tb == NULL) | |
5737 | return NL_OK; | |
5738 | ||
5739 | nla_for_each_nested(nl_rate, tb, rem_rate) { | |
5740 | nla_parse(tb_rate, NL80211_BITRATE_ATTR_MAX, | |
5741 | nla_data(nl_rate), nla_len(nl_rate), | |
5742 | rate_policy); | |
5743 | if (!tb_rate[NL80211_BITRATE_ATTR_RATE]) | |
5744 | continue; | |
5745 | mode->num_rates++; | |
5746 | } | |
5747 | ||
5748 | mode->rates = os_calloc(mode->num_rates, sizeof(int)); | |
5749 | if (!mode->rates) | |
5750 | return NL_SKIP; | |
5751 | ||
5752 | idx = 0; | |
5753 | ||
5754 | nla_for_each_nested(nl_rate, tb, rem_rate) { | |
5755 | nla_parse(tb_rate, NL80211_BITRATE_ATTR_MAX, | |
5756 | nla_data(nl_rate), nla_len(nl_rate), | |
5757 | rate_policy); | |
5758 | if (!tb_rate[NL80211_BITRATE_ATTR_RATE]) | |
5759 | continue; | |
5760 | mode->rates[idx] = nla_get_u32( | |
5761 | tb_rate[NL80211_BITRATE_ATTR_RATE]); | |
e62a1d43 JM |
5762 | idx++; |
5763 | } | |
5764 | ||
5765 | return NL_OK; | |
5766 | } | |
5767 | ||
5768 | ||
5769 | static int phy_info_band(struct phy_info_arg *phy_info, struct nlattr *nl_band) | |
5770 | { | |
5771 | struct nlattr *tb_band[NL80211_BAND_ATTR_MAX + 1]; | |
282d5590 | 5772 | struct hostapd_hw_modes *mode; |
e62a1d43 | 5773 | int ret; |
282d5590 | 5774 | |
3cfcad1b JM |
5775 | if (phy_info->last_mode != nl_band->nla_type) { |
5776 | mode = os_realloc_array(phy_info->modes, | |
5777 | *phy_info->num_modes + 1, | |
5778 | sizeof(*mode)); | |
5779 | if (!mode) | |
5780 | return NL_SKIP; | |
5781 | phy_info->modes = mode; | |
5782 | ||
5783 | mode = &phy_info->modes[*(phy_info->num_modes)]; | |
5784 | os_memset(mode, 0, sizeof(*mode)); | |
5785 | mode->mode = NUM_HOSTAPD_MODES; | |
c8ebeda4 MK |
5786 | mode->flags = HOSTAPD_MODE_FLAG_HT_INFO_KNOWN | |
5787 | HOSTAPD_MODE_FLAG_VHT_INFO_KNOWN; | |
5788 | ||
5789 | /* | |
5790 | * Unsupported VHT MCS stream is defined as value 3, so the VHT | |
5791 | * MCS RX/TX map must be initialized with 0xffff to mark all 8 | |
5792 | * possible streams as unsupported. This will be overridden if | |
5793 | * driver advertises VHT support. | |
5794 | */ | |
5795 | mode->vht_mcs_set[0] = 0xff; | |
5796 | mode->vht_mcs_set[1] = 0xff; | |
5797 | mode->vht_mcs_set[4] = 0xff; | |
5798 | mode->vht_mcs_set[5] = 0xff; | |
5799 | ||
3cfcad1b JM |
5800 | *(phy_info->num_modes) += 1; |
5801 | phy_info->last_mode = nl_band->nla_type; | |
5802 | phy_info->last_chan_idx = 0; | |
5803 | } else | |
5804 | mode = &phy_info->modes[*(phy_info->num_modes) - 1]; | |
282d5590 | 5805 | |
3cfcad1b JM |
5806 | nla_parse(tb_band, NL80211_BAND_ATTR_MAX, nla_data(nl_band), |
5807 | nla_len(nl_band), NULL); | |
282d5590 | 5808 | |
e62a1d43 JM |
5809 | phy_info_ht_capa(mode, tb_band[NL80211_BAND_ATTR_HT_CAPA], |
5810 | tb_band[NL80211_BAND_ATTR_HT_AMPDU_FACTOR], | |
5811 | tb_band[NL80211_BAND_ATTR_HT_AMPDU_DENSITY], | |
5812 | tb_band[NL80211_BAND_ATTR_HT_MCS_SET]); | |
5813 | phy_info_vht_capa(mode, tb_band[NL80211_BAND_ATTR_VHT_CAPA], | |
5814 | tb_band[NL80211_BAND_ATTR_VHT_MCS_SET]); | |
5815 | ret = phy_info_freqs(phy_info, mode, tb_band[NL80211_BAND_ATTR_FREQS]); | |
5816 | if (ret != NL_OK) | |
5817 | return ret; | |
5818 | ret = phy_info_rates(mode, tb_band[NL80211_BAND_ATTR_RATES]); | |
5819 | if (ret != NL_OK) | |
5820 | return ret; | |
282d5590 | 5821 | |
3cfcad1b JM |
5822 | return NL_OK; |
5823 | } | |
5824 | ||
5825 | ||
5826 | static int phy_info_handler(struct nl_msg *msg, void *arg) | |
5827 | { | |
5828 | struct nlattr *tb_msg[NL80211_ATTR_MAX + 1]; | |
5829 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); | |
5830 | struct phy_info_arg *phy_info = arg; | |
5831 | struct nlattr *nl_band; | |
5832 | int rem_band; | |
5833 | ||
5834 | nla_parse(tb_msg, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), | |
5835 | genlmsg_attrlen(gnlh, 0), NULL); | |
5836 | ||
5837 | if (!tb_msg[NL80211_ATTR_WIPHY_BANDS]) | |
5838 | return NL_SKIP; | |
5839 | ||
5840 | nla_for_each_nested(nl_band, tb_msg[NL80211_ATTR_WIPHY_BANDS], rem_band) | |
5841 | { | |
5842 | int res = phy_info_band(phy_info, nl_band); | |
5843 | if (res != NL_OK) | |
5844 | return res; | |
5845 | } | |
5846 | ||
282d5590 JM |
5847 | return NL_SKIP; |
5848 | } | |
5849 | ||
3cfcad1b | 5850 | |
282d5590 | 5851 | static struct hostapd_hw_modes * |
c30a4ab0 JB |
5852 | wpa_driver_nl80211_postprocess_modes(struct hostapd_hw_modes *modes, |
5853 | u16 *num_modes) | |
282d5590 JM |
5854 | { |
5855 | u16 m; | |
5856 | struct hostapd_hw_modes *mode11g = NULL, *nmodes, *mode; | |
5857 | int i, mode11g_idx = -1; | |
5858 | ||
c30a4ab0 JB |
5859 | /* heuristic to set up modes */ |
5860 | for (m = 0; m < *num_modes; m++) { | |
5861 | if (!modes[m].num_channels) | |
5862 | continue; | |
5863 | if (modes[m].channels[0].freq < 4000) { | |
5864 | modes[m].mode = HOSTAPD_MODE_IEEE80211B; | |
5865 | for (i = 0; i < modes[m].num_rates; i++) { | |
5866 | if (modes[m].rates[i] > 200) { | |
5867 | modes[m].mode = HOSTAPD_MODE_IEEE80211G; | |
5868 | break; | |
5869 | } | |
5870 | } | |
5871 | } else if (modes[m].channels[0].freq > 50000) | |
5872 | modes[m].mode = HOSTAPD_MODE_IEEE80211AD; | |
5873 | else | |
5874 | modes[m].mode = HOSTAPD_MODE_IEEE80211A; | |
5875 | } | |
5876 | ||
282d5590 JM |
5877 | /* If only 802.11g mode is included, use it to construct matching |
5878 | * 802.11b mode data. */ | |
5879 | ||
5880 | for (m = 0; m < *num_modes; m++) { | |
5881 | if (modes[m].mode == HOSTAPD_MODE_IEEE80211B) | |
5882 | return modes; /* 802.11b already included */ | |
5883 | if (modes[m].mode == HOSTAPD_MODE_IEEE80211G) | |
5884 | mode11g_idx = m; | |
5885 | } | |
5886 | ||
5887 | if (mode11g_idx < 0) | |
5888 | return modes; /* 2.4 GHz band not supported at all */ | |
5889 | ||
067ffa26 | 5890 | nmodes = os_realloc_array(modes, *num_modes + 1, sizeof(*nmodes)); |
282d5590 JM |
5891 | if (nmodes == NULL) |
5892 | return modes; /* Could not add 802.11b mode */ | |
5893 | ||
5894 | mode = &nmodes[*num_modes]; | |
5895 | os_memset(mode, 0, sizeof(*mode)); | |
5896 | (*num_modes)++; | |
5897 | modes = nmodes; | |
5898 | ||
5899 | mode->mode = HOSTAPD_MODE_IEEE80211B; | |
5900 | ||
5901 | mode11g = &modes[mode11g_idx]; | |
5902 | mode->num_channels = mode11g->num_channels; | |
5903 | mode->channels = os_malloc(mode11g->num_channels * | |
5904 | sizeof(struct hostapd_channel_data)); | |
5905 | if (mode->channels == NULL) { | |
5906 | (*num_modes)--; | |
5907 | return modes; /* Could not add 802.11b mode */ | |
5908 | } | |
5909 | os_memcpy(mode->channels, mode11g->channels, | |
5910 | mode11g->num_channels * sizeof(struct hostapd_channel_data)); | |
5911 | ||
5912 | mode->num_rates = 0; | |
fb7842aa | 5913 | mode->rates = os_malloc(4 * sizeof(int)); |
282d5590 JM |
5914 | if (mode->rates == NULL) { |
5915 | os_free(mode->channels); | |
5916 | (*num_modes)--; | |
5917 | return modes; /* Could not add 802.11b mode */ | |
5918 | } | |
5919 | ||
5920 | for (i = 0; i < mode11g->num_rates; i++) { | |
fb7842aa JM |
5921 | if (mode11g->rates[i] != 10 && mode11g->rates[i] != 20 && |
5922 | mode11g->rates[i] != 55 && mode11g->rates[i] != 110) | |
282d5590 JM |
5923 | continue; |
5924 | mode->rates[mode->num_rates] = mode11g->rates[i]; | |
5925 | mode->num_rates++; | |
5926 | if (mode->num_rates == 4) | |
5927 | break; | |
5928 | } | |
5929 | ||
5930 | if (mode->num_rates == 0) { | |
5931 | os_free(mode->channels); | |
5932 | os_free(mode->rates); | |
5933 | (*num_modes)--; | |
5934 | return modes; /* No 802.11b rates */ | |
5935 | } | |
5936 | ||
5937 | wpa_printf(MSG_DEBUG, "nl80211: Added 802.11b mode based on 802.11g " | |
5938 | "information"); | |
5939 | ||
5940 | return modes; | |
5941 | } | |
5942 | ||
5943 | ||
d8e66e80 JM |
5944 | static void nl80211_set_ht40_mode(struct hostapd_hw_modes *mode, int start, |
5945 | int end) | |
5946 | { | |
5947 | int c; | |
5948 | ||
5949 | for (c = 0; c < mode->num_channels; c++) { | |
5950 | struct hostapd_channel_data *chan = &mode->channels[c]; | |
5951 | if (chan->freq - 10 >= start && chan->freq + 10 <= end) | |
5952 | chan->flag |= HOSTAPD_CHAN_HT40; | |
5953 | } | |
5954 | } | |
5955 | ||
5956 | ||
5957 | static void nl80211_set_ht40_mode_sec(struct hostapd_hw_modes *mode, int start, | |
5958 | int end) | |
5959 | { | |
5960 | int c; | |
5961 | ||
5962 | for (c = 0; c < mode->num_channels; c++) { | |
5963 | struct hostapd_channel_data *chan = &mode->channels[c]; | |
5964 | if (!(chan->flag & HOSTAPD_CHAN_HT40)) | |
5965 | continue; | |
5966 | if (chan->freq - 30 >= start && chan->freq - 10 <= end) | |
5967 | chan->flag |= HOSTAPD_CHAN_HT40MINUS; | |
5968 | if (chan->freq + 10 >= start && chan->freq + 30 <= end) | |
5969 | chan->flag |= HOSTAPD_CHAN_HT40PLUS; | |
5970 | } | |
5971 | } | |
5972 | ||
5973 | ||
5974 | static void nl80211_reg_rule_ht40(struct nlattr *tb[], | |
5975 | struct phy_info_arg *results) | |
5976 | { | |
5977 | u32 start, end, max_bw; | |
5978 | u16 m; | |
5979 | ||
5980 | if (tb[NL80211_ATTR_FREQ_RANGE_START] == NULL || | |
5981 | tb[NL80211_ATTR_FREQ_RANGE_END] == NULL || | |
5982 | tb[NL80211_ATTR_FREQ_RANGE_MAX_BW] == NULL) | |
5983 | return; | |
5984 | ||
5985 | start = nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_START]) / 1000; | |
5986 | end = nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_END]) / 1000; | |
5987 | max_bw = nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_MAX_BW]) / 1000; | |
5988 | ||
5989 | wpa_printf(MSG_DEBUG, "nl80211: %u-%u @ %u MHz", | |
5990 | start, end, max_bw); | |
5991 | if (max_bw < 40) | |
5992 | return; | |
5993 | ||
5994 | for (m = 0; m < *results->num_modes; m++) { | |
5995 | if (!(results->modes[m].ht_capab & | |
5996 | HT_CAP_INFO_SUPP_CHANNEL_WIDTH_SET)) | |
5997 | continue; | |
5998 | nl80211_set_ht40_mode(&results->modes[m], start, end); | |
5999 | } | |
6000 | } | |
6001 | ||
6002 | ||
6003 | static void nl80211_reg_rule_sec(struct nlattr *tb[], | |
6004 | struct phy_info_arg *results) | |
6005 | { | |
6006 | u32 start, end, max_bw; | |
6007 | u16 m; | |
6008 | ||
6009 | if (tb[NL80211_ATTR_FREQ_RANGE_START] == NULL || | |
6010 | tb[NL80211_ATTR_FREQ_RANGE_END] == NULL || | |
6011 | tb[NL80211_ATTR_FREQ_RANGE_MAX_BW] == NULL) | |
6012 | return; | |
6013 | ||
6014 | start = nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_START]) / 1000; | |
6015 | end = nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_END]) / 1000; | |
6016 | max_bw = nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_MAX_BW]) / 1000; | |
6017 | ||
6018 | if (max_bw < 20) | |
6019 | return; | |
6020 | ||
6021 | for (m = 0; m < *results->num_modes; m++) { | |
6022 | if (!(results->modes[m].ht_capab & | |
6023 | HT_CAP_INFO_SUPP_CHANNEL_WIDTH_SET)) | |
6024 | continue; | |
6025 | nl80211_set_ht40_mode_sec(&results->modes[m], start, end); | |
6026 | } | |
6027 | } | |
6028 | ||
6029 | ||
6030 | static int nl80211_get_reg(struct nl_msg *msg, void *arg) | |
6031 | { | |
6032 | struct phy_info_arg *results = arg; | |
6033 | struct nlattr *tb_msg[NL80211_ATTR_MAX + 1]; | |
6034 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); | |
6035 | struct nlattr *nl_rule; | |
6036 | struct nlattr *tb_rule[NL80211_FREQUENCY_ATTR_MAX + 1]; | |
6037 | int rem_rule; | |
6038 | static struct nla_policy reg_policy[NL80211_FREQUENCY_ATTR_MAX + 1] = { | |
6039 | [NL80211_ATTR_REG_RULE_FLAGS] = { .type = NLA_U32 }, | |
6040 | [NL80211_ATTR_FREQ_RANGE_START] = { .type = NLA_U32 }, | |
6041 | [NL80211_ATTR_FREQ_RANGE_END] = { .type = NLA_U32 }, | |
6042 | [NL80211_ATTR_FREQ_RANGE_MAX_BW] = { .type = NLA_U32 }, | |
6043 | [NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN] = { .type = NLA_U32 }, | |
6044 | [NL80211_ATTR_POWER_RULE_MAX_EIRP] = { .type = NLA_U32 }, | |
6045 | }; | |
6046 | ||
6047 | nla_parse(tb_msg, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), | |
6048 | genlmsg_attrlen(gnlh, 0), NULL); | |
6049 | if (!tb_msg[NL80211_ATTR_REG_ALPHA2] || | |
6050 | !tb_msg[NL80211_ATTR_REG_RULES]) { | |
6051 | wpa_printf(MSG_DEBUG, "nl80211: No regulatory information " | |
6052 | "available"); | |
6053 | return NL_SKIP; | |
6054 | } | |
6055 | ||
6056 | wpa_printf(MSG_DEBUG, "nl80211: Regulatory information - country=%s", | |
6057 | (char *) nla_data(tb_msg[NL80211_ATTR_REG_ALPHA2])); | |
6058 | ||
6059 | nla_for_each_nested(nl_rule, tb_msg[NL80211_ATTR_REG_RULES], rem_rule) | |
6060 | { | |
6061 | nla_parse(tb_rule, NL80211_FREQUENCY_ATTR_MAX, | |
6062 | nla_data(nl_rule), nla_len(nl_rule), reg_policy); | |
6063 | nl80211_reg_rule_ht40(tb_rule, results); | |
6064 | } | |
6065 | ||
6066 | nla_for_each_nested(nl_rule, tb_msg[NL80211_ATTR_REG_RULES], rem_rule) | |
6067 | { | |
6068 | nla_parse(tb_rule, NL80211_FREQUENCY_ATTR_MAX, | |
6069 | nla_data(nl_rule), nla_len(nl_rule), reg_policy); | |
6070 | nl80211_reg_rule_sec(tb_rule, results); | |
6071 | } | |
6072 | ||
6073 | return NL_SKIP; | |
6074 | } | |
6075 | ||
6076 | ||
6077 | static int nl80211_set_ht40_flags(struct wpa_driver_nl80211_data *drv, | |
6078 | struct phy_info_arg *results) | |
6079 | { | |
6080 | struct nl_msg *msg; | |
6081 | ||
6082 | msg = nlmsg_alloc(); | |
6083 | if (!msg) | |
6084 | return -ENOMEM; | |
6085 | ||
9fb04070 | 6086 | nl80211_cmd(drv, msg, 0, NL80211_CMD_GET_REG); |
d8e66e80 JM |
6087 | return send_and_recv_msgs(drv, msg, nl80211_get_reg, results); |
6088 | } | |
6089 | ||
6090 | ||
282d5590 JM |
6091 | static struct hostapd_hw_modes * |
6092 | wpa_driver_nl80211_get_hw_feature_data(void *priv, u16 *num_modes, u16 *flags) | |
6093 | { | |
43245552 | 6094 | u32 feat; |
a2e40bb6 FF |
6095 | struct i802_bss *bss = priv; |
6096 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
282d5590 JM |
6097 | struct nl_msg *msg; |
6098 | struct phy_info_arg result = { | |
6099 | .num_modes = num_modes, | |
6100 | .modes = NULL, | |
43245552 | 6101 | .last_mode = -1, |
282d5590 JM |
6102 | }; |
6103 | ||
6104 | *num_modes = 0; | |
6105 | *flags = 0; | |
6106 | ||
6107 | msg = nlmsg_alloc(); | |
6108 | if (!msg) | |
6109 | return NULL; | |
6110 | ||
43245552 DJ |
6111 | feat = get_nl80211_protocol_features(drv); |
6112 | if (feat & NL80211_PROTOCOL_FEATURE_SPLIT_WIPHY_DUMP) | |
6113 | nl80211_cmd(drv, msg, NLM_F_DUMP, NL80211_CMD_GET_WIPHY); | |
6114 | else | |
6115 | nl80211_cmd(drv, msg, 0, NL80211_CMD_GET_WIPHY); | |
282d5590 | 6116 | |
43245552 | 6117 | NLA_PUT_FLAG(msg, NL80211_ATTR_SPLIT_WIPHY_DUMP); |
282d5590 JM |
6118 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, drv->ifindex); |
6119 | ||
d8e66e80 JM |
6120 | if (send_and_recv_msgs(drv, msg, phy_info_handler, &result) == 0) { |
6121 | nl80211_set_ht40_flags(drv, &result); | |
c30a4ab0 JB |
6122 | return wpa_driver_nl80211_postprocess_modes(result.modes, |
6123 | num_modes); | |
d8e66e80 | 6124 | } |
5883168a | 6125 | msg = NULL; |
282d5590 | 6126 | nla_put_failure: |
5883168a | 6127 | nlmsg_free(msg); |
282d5590 JM |
6128 | return NULL; |
6129 | } | |
6130 | ||
6131 | ||
a11241fa JB |
6132 | static int wpa_driver_nl80211_send_mntr(struct wpa_driver_nl80211_data *drv, |
6133 | const void *data, size_t len, | |
6134 | int encrypt, int noack) | |
2c2010ac JM |
6135 | { |
6136 | __u8 rtap_hdr[] = { | |
6137 | 0x00, 0x00, /* radiotap version */ | |
6138 | 0x0e, 0x00, /* radiotap length */ | |
6139 | 0x02, 0xc0, 0x00, 0x00, /* bmap: flags, tx and rx flags */ | |
6140 | IEEE80211_RADIOTAP_F_FRAG, /* F_FRAG (fragment if required) */ | |
6141 | 0x00, /* padding */ | |
6142 | 0x00, 0x00, /* RX and TX flags to indicate that */ | |
6143 | 0x00, 0x00, /* this is the injected frame directly */ | |
6144 | }; | |
6145 | struct iovec iov[2] = { | |
6146 | { | |
6147 | .iov_base = &rtap_hdr, | |
6148 | .iov_len = sizeof(rtap_hdr), | |
6149 | }, | |
6150 | { | |
6151 | .iov_base = (void *) data, | |
6152 | .iov_len = len, | |
6153 | } | |
6154 | }; | |
6155 | struct msghdr msg = { | |
6156 | .msg_name = NULL, | |
6157 | .msg_namelen = 0, | |
6158 | .msg_iov = iov, | |
6159 | .msg_iovlen = 2, | |
6160 | .msg_control = NULL, | |
6161 | .msg_controllen = 0, | |
6162 | .msg_flags = 0, | |
6163 | }; | |
ebbec8b2 | 6164 | int res; |
fab25336 | 6165 | u16 txflags = 0; |
2c2010ac JM |
6166 | |
6167 | if (encrypt) | |
6168 | rtap_hdr[8] |= IEEE80211_RADIOTAP_F_WEP; | |
6169 | ||
866af8b6 JM |
6170 | if (drv->monitor_sock < 0) { |
6171 | wpa_printf(MSG_DEBUG, "nl80211: No monitor socket available " | |
6172 | "for %s", __func__); | |
6173 | return -1; | |
6174 | } | |
6175 | ||
fab25336 HS |
6176 | if (noack) |
6177 | txflags |= IEEE80211_RADIOTAP_F_TX_NOACK; | |
9d7a63dc | 6178 | WPA_PUT_LE16(&rtap_hdr[12], txflags); |
fab25336 | 6179 | |
ebbec8b2 JM |
6180 | res = sendmsg(drv->monitor_sock, &msg, 0); |
6181 | if (res < 0) { | |
6182 | wpa_printf(MSG_INFO, "nl80211: sendmsg: %s", strerror(errno)); | |
6183 | return -1; | |
6184 | } | |
6185 | return 0; | |
2c2010ac JM |
6186 | } |
6187 | ||
6188 | ||
a11241fa JB |
6189 | static int wpa_driver_nl80211_send_frame(struct i802_bss *bss, |
6190 | const void *data, size_t len, | |
55231068 JM |
6191 | int encrypt, int noack, |
6192 | unsigned int freq, int no_cck, | |
6193 | int offchanok, unsigned int wait_time) | |
a11241fa JB |
6194 | { |
6195 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
6196 | u64 cookie; | |
41cc50d1 | 6197 | int res; |
a11241fa | 6198 | |
af964484 JM |
6199 | if (freq == 0) { |
6200 | wpa_printf(MSG_DEBUG, "nl80211: send_frame - Use bss->freq=%u", | |
6201 | bss->freq); | |
55231068 | 6202 | freq = bss->freq; |
af964484 | 6203 | } |
55231068 | 6204 | |
739faee2 JM |
6205 | if (drv->use_monitor) { |
6206 | wpa_printf(MSG_DEBUG, "nl80211: send_frame(freq=%u bss->freq=%u) -> send_mntr", | |
6207 | freq, bss->freq); | |
a11241fa JB |
6208 | return wpa_driver_nl80211_send_mntr(drv, data, len, |
6209 | encrypt, noack); | |
739faee2 | 6210 | } |
a11241fa | 6211 | |
739faee2 | 6212 | wpa_printf(MSG_DEBUG, "nl80211: send_frame -> send_frame_cmd"); |
41cc50d1 JM |
6213 | res = nl80211_send_frame_cmd(bss, freq, wait_time, data, len, |
6214 | &cookie, no_cck, noack, offchanok); | |
6215 | if (res == 0 && !noack) { | |
6216 | const struct ieee80211_mgmt *mgmt; | |
6217 | u16 fc; | |
6218 | ||
6219 | mgmt = (const struct ieee80211_mgmt *) data; | |
6220 | fc = le_to_host16(mgmt->frame_control); | |
6221 | if (WLAN_FC_GET_TYPE(fc) == WLAN_FC_TYPE_MGMT && | |
6222 | WLAN_FC_GET_STYPE(fc) == WLAN_FC_STYPE_ACTION) { | |
6223 | wpa_printf(MSG_MSGDUMP, | |
6224 | "nl80211: Update send_action_cookie from 0x%llx to 0x%llx", | |
6225 | (long long unsigned int) | |
6226 | drv->send_action_cookie, | |
6227 | (long long unsigned int) cookie); | |
6228 | drv->send_action_cookie = cookie; | |
6229 | } | |
6230 | } | |
6231 | ||
6232 | return res; | |
a11241fa JB |
6233 | } |
6234 | ||
6235 | ||
9ebce9c5 JM |
6236 | static int wpa_driver_nl80211_send_mlme(struct i802_bss *bss, const u8 *data, |
6237 | size_t data_len, int noack, | |
6238 | unsigned int freq, int no_cck, | |
6239 | int offchanok, | |
6240 | unsigned int wait_time) | |
2c2010ac | 6241 | { |
a2e40bb6 | 6242 | struct wpa_driver_nl80211_data *drv = bss->drv; |
2c2010ac | 6243 | struct ieee80211_mgmt *mgmt; |
7a47d567 | 6244 | int encrypt = 1; |
2c2010ac JM |
6245 | u16 fc; |
6246 | ||
6247 | mgmt = (struct ieee80211_mgmt *) data; | |
6248 | fc = le_to_host16(mgmt->frame_control); | |
af964484 JM |
6249 | wpa_printf(MSG_DEBUG, "nl80211: send_mlme - noack=%d freq=%u no_cck=%d offchanok=%d wait_time=%u fc=0x%x nlmode=%d", |
6250 | noack, freq, no_cck, offchanok, wait_time, fc, drv->nlmode); | |
2c2010ac | 6251 | |
8e12685c AS |
6252 | if ((is_sta_interface(drv->nlmode) || |
6253 | drv->nlmode == NL80211_IFTYPE_P2P_DEVICE) && | |
5582a5d1 JB |
6254 | WLAN_FC_GET_TYPE(fc) == WLAN_FC_TYPE_MGMT && |
6255 | WLAN_FC_GET_STYPE(fc) == WLAN_FC_STYPE_PROBE_RESP) { | |
6256 | /* | |
6257 | * The use of last_mgmt_freq is a bit of a hack, | |
6258 | * but it works due to the single-threaded nature | |
6259 | * of wpa_supplicant. | |
6260 | */ | |
af964484 JM |
6261 | if (freq == 0) { |
6262 | wpa_printf(MSG_DEBUG, "nl80211: Use last_mgmt_freq=%d", | |
6263 | drv->last_mgmt_freq); | |
55231068 | 6264 | freq = drv->last_mgmt_freq; |
af964484 | 6265 | } |
55231068 | 6266 | return nl80211_send_frame_cmd(bss, freq, 0, |
88df0ef7 JB |
6267 | data, data_len, NULL, 1, noack, |
6268 | 1); | |
5582a5d1 JB |
6269 | } |
6270 | ||
61cbe2ff | 6271 | if (drv->device_ap_sme && is_ap_interface(drv->nlmode)) { |
af964484 JM |
6272 | if (freq == 0) { |
6273 | wpa_printf(MSG_DEBUG, "nl80211: Use bss->freq=%d", | |
6274 | bss->freq); | |
55231068 | 6275 | freq = bss->freq; |
af964484 | 6276 | } |
b5671498 JM |
6277 | return nl80211_send_frame_cmd(bss, freq, |
6278 | (int) freq == bss->freq ? 0 : | |
6279 | wait_time, | |
d8d6b32e DG |
6280 | data, data_len, |
6281 | &drv->send_action_cookie, | |
55231068 | 6282 | no_cck, noack, offchanok); |
86957e62 JM |
6283 | } |
6284 | ||
2c2010ac JM |
6285 | if (WLAN_FC_GET_TYPE(fc) == WLAN_FC_TYPE_MGMT && |
6286 | WLAN_FC_GET_STYPE(fc) == WLAN_FC_STYPE_AUTH) { | |
6287 | /* | |
6288 | * Only one of the authentication frame types is encrypted. | |
6289 | * In order for static WEP encryption to work properly (i.e., | |
6290 | * to not encrypt the frame), we need to tell mac80211 about | |
6291 | * the frames that must not be encrypted. | |
6292 | */ | |
6293 | u16 auth_alg = le_to_host16(mgmt->u.auth.auth_alg); | |
6294 | u16 auth_trans = le_to_host16(mgmt->u.auth.auth_transaction); | |
7a47d567 JB |
6295 | if (auth_alg != WLAN_AUTH_SHARED_KEY || auth_trans != 3) |
6296 | encrypt = 0; | |
2c2010ac JM |
6297 | } |
6298 | ||
739faee2 | 6299 | wpa_printf(MSG_DEBUG, "nl80211: send_mlme -> send_frame"); |
a11241fa | 6300 | return wpa_driver_nl80211_send_frame(bss, data, data_len, encrypt, |
55231068 JM |
6301 | noack, freq, no_cck, offchanok, |
6302 | wait_time); | |
6303 | } | |
6304 | ||
6305 | ||
31357268 | 6306 | static int nl80211_set_bss(struct i802_bss *bss, int cts, int preamble, |
e5693c47 JM |
6307 | int slot, int ht_opmode, int ap_isolate, |
6308 | int *basic_rates) | |
31357268 JM |
6309 | { |
6310 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
6311 | struct nl_msg *msg; | |
6312 | ||
6313 | msg = nlmsg_alloc(); | |
6314 | if (!msg) | |
6315 | return -ENOMEM; | |
6316 | ||
9fb04070 | 6317 | nl80211_cmd(drv, msg, 0, NL80211_CMD_SET_BSS); |
31357268 JM |
6318 | |
6319 | if (cts >= 0) | |
6320 | NLA_PUT_U8(msg, NL80211_ATTR_BSS_CTS_PROT, cts); | |
6321 | if (preamble >= 0) | |
6322 | NLA_PUT_U8(msg, NL80211_ATTR_BSS_SHORT_PREAMBLE, preamble); | |
6323 | if (slot >= 0) | |
6324 | NLA_PUT_U8(msg, NL80211_ATTR_BSS_SHORT_SLOT_TIME, slot); | |
6325 | if (ht_opmode >= 0) | |
6326 | NLA_PUT_U16(msg, NL80211_ATTR_BSS_HT_OPMODE, ht_opmode); | |
d03e8d11 JM |
6327 | if (ap_isolate >= 0) |
6328 | NLA_PUT_U8(msg, NL80211_ATTR_AP_ISOLATE, ap_isolate); | |
e5693c47 JM |
6329 | |
6330 | if (basic_rates) { | |
6331 | u8 rates[NL80211_MAX_SUPP_RATES]; | |
6332 | u8 rates_len = 0; | |
6333 | int i; | |
6334 | ||
6335 | for (i = 0; i < NL80211_MAX_SUPP_RATES && basic_rates[i] >= 0; | |
6336 | i++) | |
6337 | rates[rates_len++] = basic_rates[i] / 5; | |
6338 | ||
6339 | NLA_PUT(msg, NL80211_ATTR_BSS_BASIC_RATES, rates_len, rates); | |
6340 | } | |
6341 | ||
31357268 JM |
6342 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, if_nametoindex(bss->ifname)); |
6343 | ||
6344 | return send_and_recv_msgs(drv, msg, NULL, NULL); | |
6345 | nla_put_failure: | |
5883168a | 6346 | nlmsg_free(msg); |
31357268 JM |
6347 | return -ENOBUFS; |
6348 | } | |
6349 | ||
6350 | ||
3c4ca363 VN |
6351 | static int wpa_driver_nl80211_set_acl(void *priv, |
6352 | struct hostapd_acl_params *params) | |
6353 | { | |
6354 | struct i802_bss *bss = priv; | |
6355 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
6356 | struct nl_msg *msg; | |
6357 | struct nlattr *acl; | |
6358 | unsigned int i; | |
6359 | int ret = 0; | |
6360 | ||
6361 | if (!(drv->capa.max_acl_mac_addrs)) | |
6362 | return -ENOTSUP; | |
6363 | ||
6364 | if (params->num_mac_acl > drv->capa.max_acl_mac_addrs) | |
6365 | return -ENOTSUP; | |
6366 | ||
6367 | msg = nlmsg_alloc(); | |
6368 | if (!msg) | |
6369 | return -ENOMEM; | |
6370 | ||
6371 | wpa_printf(MSG_DEBUG, "nl80211: Set %s ACL (num_mac_acl=%u)", | |
6372 | params->acl_policy ? "Accept" : "Deny", params->num_mac_acl); | |
6373 | ||
6374 | nl80211_cmd(drv, msg, 0, NL80211_CMD_SET_MAC_ACL); | |
6375 | ||
6376 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, drv->ifindex); | |
6377 | ||
6378 | NLA_PUT_U32(msg, NL80211_ATTR_ACL_POLICY, params->acl_policy ? | |
6379 | NL80211_ACL_POLICY_DENY_UNLESS_LISTED : | |
6380 | NL80211_ACL_POLICY_ACCEPT_UNLESS_LISTED); | |
6381 | ||
6382 | acl = nla_nest_start(msg, NL80211_ATTR_MAC_ADDRS); | |
6383 | if (acl == NULL) | |
6384 | goto nla_put_failure; | |
6385 | ||
6386 | for (i = 0; i < params->num_mac_acl; i++) | |
6387 | NLA_PUT(msg, i + 1, ETH_ALEN, params->mac_acl[i].addr); | |
6388 | ||
6389 | nla_nest_end(msg, acl); | |
6390 | ||
6391 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); | |
6392 | msg = NULL; | |
6393 | if (ret) { | |
6394 | wpa_printf(MSG_DEBUG, "nl80211: Failed to set MAC ACL: %d (%s)", | |
6395 | ret, strerror(-ret)); | |
6396 | } | |
6397 | ||
6398 | nla_put_failure: | |
6399 | nlmsg_free(msg); | |
6400 | ||
6401 | return ret; | |
6402 | } | |
6403 | ||
6404 | ||
19c3b566 JM |
6405 | static int wpa_driver_nl80211_set_ap(void *priv, |
6406 | struct wpa_driver_ap_params *params) | |
d2440ba0 | 6407 | { |
a2e40bb6 FF |
6408 | struct i802_bss *bss = priv; |
6409 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
d2440ba0 JM |
6410 | struct nl_msg *msg; |
6411 | u8 cmd = NL80211_CMD_NEW_BEACON; | |
6412 | int ret; | |
b4fd6fab | 6413 | int beacon_set; |
8b897f5a | 6414 | int ifindex = if_nametoindex(bss->ifname); |
b11d1d64 JM |
6415 | int num_suites; |
6416 | u32 suites[10]; | |
6417 | u32 ver; | |
b4fd6fab | 6418 | |
b4fd6fab | 6419 | beacon_set = bss->beacon_set; |
d2440ba0 JM |
6420 | |
6421 | msg = nlmsg_alloc(); | |
6422 | if (!msg) | |
6423 | return -ENOMEM; | |
6424 | ||
6425 | wpa_printf(MSG_DEBUG, "nl80211: Set beacon (beacon_set=%d)", | |
b4fd6fab JM |
6426 | beacon_set); |
6427 | if (beacon_set) | |
d2440ba0 JM |
6428 | cmd = NL80211_CMD_SET_BEACON; |
6429 | ||
9fb04070 | 6430 | nl80211_cmd(drv, msg, 0, cmd); |
b92e08fc JM |
6431 | wpa_hexdump(MSG_DEBUG, "nl80211: Beacon head", |
6432 | params->head, params->head_len); | |
19c3b566 | 6433 | NLA_PUT(msg, NL80211_ATTR_BEACON_HEAD, params->head_len, params->head); |
b92e08fc JM |
6434 | wpa_hexdump(MSG_DEBUG, "nl80211: Beacon tail", |
6435 | params->tail, params->tail_len); | |
19c3b566 | 6436 | NLA_PUT(msg, NL80211_ATTR_BEACON_TAIL, params->tail_len, params->tail); |
b92e08fc | 6437 | wpa_printf(MSG_DEBUG, "nl80211: ifindex=%d", ifindex); |
b4fd6fab | 6438 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, ifindex); |
b92e08fc | 6439 | wpa_printf(MSG_DEBUG, "nl80211: beacon_int=%d", params->beacon_int); |
19c3b566 | 6440 | NLA_PUT_U32(msg, NL80211_ATTR_BEACON_INTERVAL, params->beacon_int); |
b92e08fc | 6441 | wpa_printf(MSG_DEBUG, "nl80211: dtim_period=%d", params->dtim_period); |
19c3b566 | 6442 | NLA_PUT_U32(msg, NL80211_ATTR_DTIM_PERIOD, params->dtim_period); |
b92e08fc JM |
6443 | wpa_hexdump_ascii(MSG_DEBUG, "nl80211: ssid", |
6444 | params->ssid, params->ssid_len); | |
ccb941e6 JM |
6445 | NLA_PUT(msg, NL80211_ATTR_SSID, params->ssid_len, |
6446 | params->ssid); | |
b92e08fc JM |
6447 | if (params->proberesp && params->proberesp_len) { |
6448 | wpa_hexdump(MSG_DEBUG, "nl80211: proberesp (offload)", | |
6449 | params->proberesp, params->proberesp_len); | |
5ed33546 AN |
6450 | NLA_PUT(msg, NL80211_ATTR_PROBE_RESP, params->proberesp_len, |
6451 | params->proberesp); | |
b92e08fc | 6452 | } |
97a7a0b5 JM |
6453 | switch (params->hide_ssid) { |
6454 | case NO_SSID_HIDING: | |
b92e08fc | 6455 | wpa_printf(MSG_DEBUG, "nl80211: hidden SSID not in use"); |
97a7a0b5 JM |
6456 | NLA_PUT_U32(msg, NL80211_ATTR_HIDDEN_SSID, |
6457 | NL80211_HIDDEN_SSID_NOT_IN_USE); | |
6458 | break; | |
6459 | case HIDDEN_SSID_ZERO_LEN: | |
b92e08fc | 6460 | wpa_printf(MSG_DEBUG, "nl80211: hidden SSID zero len"); |
97a7a0b5 JM |
6461 | NLA_PUT_U32(msg, NL80211_ATTR_HIDDEN_SSID, |
6462 | NL80211_HIDDEN_SSID_ZERO_LEN); | |
6463 | break; | |
6464 | case HIDDEN_SSID_ZERO_CONTENTS: | |
b92e08fc | 6465 | wpa_printf(MSG_DEBUG, "nl80211: hidden SSID zero contents"); |
97a7a0b5 JM |
6466 | NLA_PUT_U32(msg, NL80211_ATTR_HIDDEN_SSID, |
6467 | NL80211_HIDDEN_SSID_ZERO_CONTENTS); | |
6468 | break; | |
6469 | } | |
b92e08fc | 6470 | wpa_printf(MSG_DEBUG, "nl80211: privacy=%d", params->privacy); |
b11d1d64 JM |
6471 | if (params->privacy) |
6472 | NLA_PUT_FLAG(msg, NL80211_ATTR_PRIVACY); | |
b92e08fc | 6473 | wpa_printf(MSG_DEBUG, "nl80211: auth_algs=0x%x", params->auth_algs); |
b11d1d64 JM |
6474 | if ((params->auth_algs & (WPA_AUTH_ALG_OPEN | WPA_AUTH_ALG_SHARED)) == |
6475 | (WPA_AUTH_ALG_OPEN | WPA_AUTH_ALG_SHARED)) { | |
6476 | /* Leave out the attribute */ | |
6477 | } else if (params->auth_algs & WPA_AUTH_ALG_SHARED) | |
6478 | NLA_PUT_U32(msg, NL80211_ATTR_AUTH_TYPE, | |
6479 | NL80211_AUTHTYPE_SHARED_KEY); | |
6480 | else | |
6481 | NLA_PUT_U32(msg, NL80211_ATTR_AUTH_TYPE, | |
6482 | NL80211_AUTHTYPE_OPEN_SYSTEM); | |
6483 | ||
b92e08fc | 6484 | wpa_printf(MSG_DEBUG, "nl80211: wpa_version=0x%x", params->wpa_version); |
b11d1d64 JM |
6485 | ver = 0; |
6486 | if (params->wpa_version & WPA_PROTO_WPA) | |
6487 | ver |= NL80211_WPA_VERSION_1; | |
6488 | if (params->wpa_version & WPA_PROTO_RSN) | |
6489 | ver |= NL80211_WPA_VERSION_2; | |
6490 | if (ver) | |
6491 | NLA_PUT_U32(msg, NL80211_ATTR_WPA_VERSIONS, ver); | |
6492 | ||
b92e08fc JM |
6493 | wpa_printf(MSG_DEBUG, "nl80211: key_mgmt_suites=0x%x", |
6494 | params->key_mgmt_suites); | |
b11d1d64 JM |
6495 | num_suites = 0; |
6496 | if (params->key_mgmt_suites & WPA_KEY_MGMT_IEEE8021X) | |
6497 | suites[num_suites++] = WLAN_AKM_SUITE_8021X; | |
6498 | if (params->key_mgmt_suites & WPA_KEY_MGMT_PSK) | |
6499 | suites[num_suites++] = WLAN_AKM_SUITE_PSK; | |
6500 | if (num_suites) { | |
6501 | NLA_PUT(msg, NL80211_ATTR_AKM_SUITES, | |
6502 | num_suites * sizeof(u32), suites); | |
6503 | } | |
6504 | ||
9f12614b JB |
6505 | if (params->key_mgmt_suites & WPA_KEY_MGMT_IEEE8021X && |
6506 | params->pairwise_ciphers & (WPA_CIPHER_WEP104 | WPA_CIPHER_WEP40)) | |
6507 | NLA_PUT_FLAG(msg, NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT); | |
6508 | ||
b92e08fc JM |
6509 | wpa_printf(MSG_DEBUG, "nl80211: pairwise_ciphers=0x%x", |
6510 | params->pairwise_ciphers); | |
b11d1d64 JM |
6511 | num_suites = 0; |
6512 | if (params->pairwise_ciphers & WPA_CIPHER_CCMP) | |
6513 | suites[num_suites++] = WLAN_CIPHER_SUITE_CCMP; | |
eb7719ff JM |
6514 | if (params->pairwise_ciphers & WPA_CIPHER_GCMP) |
6515 | suites[num_suites++] = WLAN_CIPHER_SUITE_GCMP; | |
b11d1d64 JM |
6516 | if (params->pairwise_ciphers & WPA_CIPHER_TKIP) |
6517 | suites[num_suites++] = WLAN_CIPHER_SUITE_TKIP; | |
6518 | if (params->pairwise_ciphers & WPA_CIPHER_WEP104) | |
6519 | suites[num_suites++] = WLAN_CIPHER_SUITE_WEP104; | |
6520 | if (params->pairwise_ciphers & WPA_CIPHER_WEP40) | |
6521 | suites[num_suites++] = WLAN_CIPHER_SUITE_WEP40; | |
6522 | if (num_suites) { | |
6523 | NLA_PUT(msg, NL80211_ATTR_CIPHER_SUITES_PAIRWISE, | |
6524 | num_suites * sizeof(u32), suites); | |
6525 | } | |
6526 | ||
b92e08fc JM |
6527 | wpa_printf(MSG_DEBUG, "nl80211: group_cipher=0x%x", |
6528 | params->group_cipher); | |
b11d1d64 JM |
6529 | switch (params->group_cipher) { |
6530 | case WPA_CIPHER_CCMP: | |
6531 | NLA_PUT_U32(msg, NL80211_ATTR_CIPHER_SUITE_GROUP, | |
6532 | WLAN_CIPHER_SUITE_CCMP); | |
6533 | break; | |
eb7719ff JM |
6534 | case WPA_CIPHER_GCMP: |
6535 | NLA_PUT_U32(msg, NL80211_ATTR_CIPHER_SUITE_GROUP, | |
6536 | WLAN_CIPHER_SUITE_GCMP); | |
6537 | break; | |
b11d1d64 JM |
6538 | case WPA_CIPHER_TKIP: |
6539 | NLA_PUT_U32(msg, NL80211_ATTR_CIPHER_SUITE_GROUP, | |
6540 | WLAN_CIPHER_SUITE_TKIP); | |
6541 | break; | |
6542 | case WPA_CIPHER_WEP104: | |
6543 | NLA_PUT_U32(msg, NL80211_ATTR_CIPHER_SUITE_GROUP, | |
6544 | WLAN_CIPHER_SUITE_WEP104); | |
6545 | break; | |
6546 | case WPA_CIPHER_WEP40: | |
6547 | NLA_PUT_U32(msg, NL80211_ATTR_CIPHER_SUITE_GROUP, | |
6548 | WLAN_CIPHER_SUITE_WEP40); | |
6549 | break; | |
6550 | } | |
d2440ba0 | 6551 | |
fb91db56 | 6552 | if (params->beacon_ies) { |
b92e08fc JM |
6553 | wpa_hexdump_buf(MSG_DEBUG, "nl80211: beacon_ies", |
6554 | params->beacon_ies); | |
fb91db56 JM |
6555 | NLA_PUT(msg, NL80211_ATTR_IE, wpabuf_len(params->beacon_ies), |
6556 | wpabuf_head(params->beacon_ies)); | |
6557 | } | |
6558 | if (params->proberesp_ies) { | |
b92e08fc JM |
6559 | wpa_hexdump_buf(MSG_DEBUG, "nl80211: proberesp_ies", |
6560 | params->proberesp_ies); | |
fb91db56 JM |
6561 | NLA_PUT(msg, NL80211_ATTR_IE_PROBE_RESP, |
6562 | wpabuf_len(params->proberesp_ies), | |
6563 | wpabuf_head(params->proberesp_ies)); | |
6564 | } | |
6565 | if (params->assocresp_ies) { | |
b92e08fc JM |
6566 | wpa_hexdump_buf(MSG_DEBUG, "nl80211: assocresp_ies", |
6567 | params->assocresp_ies); | |
fb91db56 JM |
6568 | NLA_PUT(msg, NL80211_ATTR_IE_ASSOC_RESP, |
6569 | wpabuf_len(params->assocresp_ies), | |
6570 | wpabuf_head(params->assocresp_ies)); | |
6571 | } | |
6572 | ||
a0133ee1 | 6573 | if (drv->capa.flags & WPA_DRIVER_FLAGS_INACTIVITY_TIMER) { |
b92e08fc JM |
6574 | wpa_printf(MSG_DEBUG, "nl80211: ap_max_inactivity=%d", |
6575 | params->ap_max_inactivity); | |
a0133ee1 VT |
6576 | NLA_PUT_U16(msg, NL80211_ATTR_INACTIVITY_TIMEOUT, |
6577 | params->ap_max_inactivity); | |
6578 | } | |
6579 | ||
d2440ba0 JM |
6580 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
6581 | if (ret) { | |
6582 | wpa_printf(MSG_DEBUG, "nl80211: Beacon set failed: %d (%s)", | |
6583 | ret, strerror(-ret)); | |
b4fd6fab | 6584 | } else { |
b4fd6fab | 6585 | bss->beacon_set = 1; |
31357268 | 6586 | nl80211_set_bss(bss, params->cts_protect, params->preamble, |
d03e8d11 | 6587 | params->short_slot_time, params->ht_opmode, |
e5693c47 | 6588 | params->isolate, params->basic_rates); |
b4fd6fab | 6589 | } |
d2440ba0 JM |
6590 | return ret; |
6591 | nla_put_failure: | |
5883168a | 6592 | nlmsg_free(msg); |
d2440ba0 JM |
6593 | return -ENOBUFS; |
6594 | } | |
6595 | ||
6596 | ||
e4fb2167 | 6597 | static int wpa_driver_nl80211_set_freq(struct i802_bss *bss, |
89b800d7 | 6598 | struct hostapd_freq_params *freq) |
1581b38b | 6599 | { |
e4fb2167 | 6600 | struct wpa_driver_nl80211_data *drv = bss->drv; |
1581b38b | 6601 | struct nl_msg *msg; |
d2440ba0 | 6602 | int ret; |
1581b38b | 6603 | |
89b800d7 JB |
6604 | wpa_printf(MSG_DEBUG, "nl80211: Set freq %d (ht_enabled=%d, vht_enabled=%d," |
6605 | " bandwidth=%d MHz, cf1=%d MHz, cf2=%d MHz)", | |
6606 | freq->freq, freq->ht_enabled, freq->vht_enabled, | |
6607 | freq->bandwidth, freq->center_freq1, freq->center_freq2); | |
1581b38b JM |
6608 | msg = nlmsg_alloc(); |
6609 | if (!msg) | |
6610 | return -1; | |
6611 | ||
9fb04070 | 6612 | nl80211_cmd(drv, msg, 0, NL80211_CMD_SET_WIPHY); |
1581b38b JM |
6613 | |
6614 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, drv->ifindex); | |
89b800d7 JB |
6615 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_FREQ, freq->freq); |
6616 | if (freq->vht_enabled) { | |
6617 | switch (freq->bandwidth) { | |
6618 | case 20: | |
6619 | NLA_PUT_U32(msg, NL80211_ATTR_CHANNEL_WIDTH, | |
6620 | NL80211_CHAN_WIDTH_20); | |
6621 | break; | |
6622 | case 40: | |
6623 | NLA_PUT_U32(msg, NL80211_ATTR_CHANNEL_WIDTH, | |
6624 | NL80211_CHAN_WIDTH_40); | |
6625 | break; | |
6626 | case 80: | |
6627 | if (freq->center_freq2) | |
6628 | NLA_PUT_U32(msg, NL80211_ATTR_CHANNEL_WIDTH, | |
6629 | NL80211_CHAN_WIDTH_80P80); | |
6630 | else | |
6631 | NLA_PUT_U32(msg, NL80211_ATTR_CHANNEL_WIDTH, | |
6632 | NL80211_CHAN_WIDTH_80); | |
6633 | break; | |
6634 | case 160: | |
6635 | NLA_PUT_U32(msg, NL80211_ATTR_CHANNEL_WIDTH, | |
6636 | NL80211_CHAN_WIDTH_160); | |
6637 | break; | |
6638 | default: | |
6639 | return -1; | |
6640 | } | |
6641 | NLA_PUT_U32(msg, NL80211_ATTR_CENTER_FREQ1, freq->center_freq1); | |
6642 | if (freq->center_freq2) | |
6643 | NLA_PUT_U32(msg, NL80211_ATTR_CENTER_FREQ2, | |
6644 | freq->center_freq2); | |
6645 | } else if (freq->ht_enabled) { | |
6646 | switch (freq->sec_channel_offset) { | |
f019981a JM |
6647 | case -1: |
6648 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE, | |
6649 | NL80211_CHAN_HT40MINUS); | |
6650 | break; | |
6651 | case 1: | |
6652 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE, | |
6653 | NL80211_CHAN_HT40PLUS); | |
6654 | break; | |
6655 | default: | |
6656 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE, | |
6657 | NL80211_CHAN_HT20); | |
6658 | break; | |
6659 | } | |
6660 | } | |
1581b38b | 6661 | |
d2440ba0 | 6662 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
5883168a | 6663 | msg = NULL; |
e4fb2167 | 6664 | if (ret == 0) { |
89b800d7 | 6665 | bss->freq = freq->freq; |
1581b38b | 6666 | return 0; |
e4fb2167 | 6667 | } |
f019981a | 6668 | wpa_printf(MSG_DEBUG, "nl80211: Failed to set channel (freq=%d): " |
89b800d7 | 6669 | "%d (%s)", freq->freq, ret, strerror(-ret)); |
1581b38b | 6670 | nla_put_failure: |
5883168a | 6671 | nlmsg_free(msg); |
1581b38b JM |
6672 | return -1; |
6673 | } | |
6674 | ||
0f4e8b4f | 6675 | |
95ab6063 AN |
6676 | static u32 sta_flags_nl80211(int flags) |
6677 | { | |
6678 | u32 f = 0; | |
6679 | ||
6680 | if (flags & WPA_STA_AUTHORIZED) | |
6681 | f |= BIT(NL80211_STA_FLAG_AUTHORIZED); | |
6682 | if (flags & WPA_STA_WMM) | |
6683 | f |= BIT(NL80211_STA_FLAG_WME); | |
6684 | if (flags & WPA_STA_SHORT_PREAMBLE) | |
6685 | f |= BIT(NL80211_STA_FLAG_SHORT_PREAMBLE); | |
6686 | if (flags & WPA_STA_MFP) | |
6687 | f |= BIT(NL80211_STA_FLAG_MFP); | |
45b722f1 AN |
6688 | if (flags & WPA_STA_TDLS_PEER) |
6689 | f |= BIT(NL80211_STA_FLAG_TDLS_PEER); | |
95ab6063 AN |
6690 | |
6691 | return f; | |
6692 | } | |
6693 | ||
6694 | ||
62847751 | 6695 | static int wpa_driver_nl80211_sta_add(void *priv, |
0f4e8b4f JM |
6696 | struct hostapd_sta_add_params *params) |
6697 | { | |
a2e40bb6 FF |
6698 | struct i802_bss *bss = priv; |
6699 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
8970bae8 | 6700 | struct nl_msg *msg; |
95ab6063 | 6701 | struct nl80211_sta_flag_update upd; |
0f4e8b4f JM |
6702 | int ret = -ENOBUFS; |
6703 | ||
45b722f1 AN |
6704 | if ((params->flags & WPA_STA_TDLS_PEER) && |
6705 | !(drv->capa.flags & WPA_DRIVER_FLAGS_TDLS_SUPPORT)) | |
6706 | return -EOPNOTSUPP; | |
6707 | ||
0f4e8b4f JM |
6708 | msg = nlmsg_alloc(); |
6709 | if (!msg) | |
6710 | return -ENOMEM; | |
6711 | ||
e4dea253 JM |
6712 | wpa_printf(MSG_DEBUG, "nl80211: %s STA " MACSTR, |
6713 | params->set ? "Set" : "Add", MAC2STR(params->addr)); | |
45b722f1 AN |
6714 | nl80211_cmd(drv, msg, 0, params->set ? NL80211_CMD_SET_STATION : |
6715 | NL80211_CMD_NEW_STATION); | |
0f4e8b4f | 6716 | |
62847751 | 6717 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, if_nametoindex(bss->ifname)); |
0f4e8b4f | 6718 | NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, params->addr); |
0f4e8b4f JM |
6719 | NLA_PUT(msg, NL80211_ATTR_STA_SUPPORTED_RATES, params->supp_rates_len, |
6720 | params->supp_rates); | |
e4dea253 JM |
6721 | wpa_hexdump(MSG_DEBUG, " * supported rates", params->supp_rates, |
6722 | params->supp_rates_len); | |
45b722f1 | 6723 | if (!params->set) { |
f11b72c3 JM |
6724 | if (params->aid) { |
6725 | wpa_printf(MSG_DEBUG, " * aid=%u", params->aid); | |
6726 | NLA_PUT_U16(msg, NL80211_ATTR_STA_AID, params->aid); | |
6727 | } else { | |
6728 | /* | |
6729 | * cfg80211 validates that AID is non-zero, so we have | |
6730 | * to make this a non-zero value for the TDLS case where | |
6731 | * a dummy STA entry is used for now. | |
6732 | */ | |
6733 | wpa_printf(MSG_DEBUG, " * aid=1 (TDLS workaround)"); | |
6734 | NLA_PUT_U16(msg, NL80211_ATTR_STA_AID, 1); | |
6735 | } | |
e4dea253 JM |
6736 | wpa_printf(MSG_DEBUG, " * listen_interval=%u", |
6737 | params->listen_interval); | |
45b722f1 AN |
6738 | NLA_PUT_U16(msg, NL80211_ATTR_STA_LISTEN_INTERVAL, |
6739 | params->listen_interval); | |
e112764e JM |
6740 | } else if (params->aid && (params->flags & WPA_STA_TDLS_PEER)) { |
6741 | wpa_printf(MSG_DEBUG, " * peer_aid=%u", params->aid); | |
6742 | NLA_PUT_U16(msg, NL80211_ATTR_PEER_AID, params->aid); | |
45b722f1 | 6743 | } |
0f4e8b4f | 6744 | if (params->ht_capabilities) { |
e4dea253 JM |
6745 | wpa_hexdump(MSG_DEBUG, " * ht_capabilities", |
6746 | (u8 *) params->ht_capabilities, | |
6747 | sizeof(*params->ht_capabilities)); | |
0f4e8b4f | 6748 | NLA_PUT(msg, NL80211_ATTR_HT_CAPABILITY, |
fc4e2d95 JM |
6749 | sizeof(*params->ht_capabilities), |
6750 | params->ht_capabilities); | |
0f4e8b4f | 6751 | } |
0f4e8b4f | 6752 | |
05a8d422 | 6753 | if (params->vht_capabilities) { |
e4dea253 JM |
6754 | wpa_hexdump(MSG_DEBUG, " * vht_capabilities", |
6755 | (u8 *) params->vht_capabilities, | |
6756 | sizeof(*params->vht_capabilities)); | |
05a8d422 JB |
6757 | NLA_PUT(msg, NL80211_ATTR_VHT_CAPABILITY, |
6758 | sizeof(*params->vht_capabilities), | |
6759 | params->vht_capabilities); | |
6760 | } | |
6761 | ||
122d16f2 SD |
6762 | wpa_printf(MSG_DEBUG, " * capability=0x%x", params->capability); |
6763 | NLA_PUT_U16(msg, NL80211_ATTR_STA_CAPABILITY, params->capability); | |
6764 | ||
6765 | if (params->ext_capab) { | |
6766 | wpa_hexdump(MSG_DEBUG, " * ext_capab", | |
6767 | params->ext_capab, params->ext_capab_len); | |
6768 | NLA_PUT(msg, NL80211_ATTR_STA_EXT_CAPABILITY, | |
6769 | params->ext_capab_len, params->ext_capab); | |
6770 | } | |
6771 | ||
95ab6063 AN |
6772 | os_memset(&upd, 0, sizeof(upd)); |
6773 | upd.mask = sta_flags_nl80211(params->flags); | |
6774 | upd.set = upd.mask; | |
e4dea253 JM |
6775 | wpa_printf(MSG_DEBUG, " * flags set=0x%x mask=0x%x", |
6776 | upd.set, upd.mask); | |
95ab6063 AN |
6777 | NLA_PUT(msg, NL80211_ATTR_STA_FLAGS2, sizeof(upd), &upd); |
6778 | ||
774bfa62 | 6779 | if (params->flags & WPA_STA_WMM) { |
8970bae8 JB |
6780 | struct nlattr *wme = nla_nest_start(msg, NL80211_ATTR_STA_WME); |
6781 | ||
774bfa62 EP |
6782 | if (!wme) |
6783 | goto nla_put_failure; | |
6784 | ||
e4dea253 | 6785 | wpa_printf(MSG_DEBUG, " * qosinfo=0x%x", params->qosinfo); |
8970bae8 | 6786 | NLA_PUT_U8(msg, NL80211_STA_WME_UAPSD_QUEUES, |
5d061637 | 6787 | params->qosinfo & WMM_QOSINFO_STA_AC_MASK); |
8970bae8 | 6788 | NLA_PUT_U8(msg, NL80211_STA_WME_MAX_SP, |
bdaf1748 | 6789 | (params->qosinfo >> WMM_QOSINFO_STA_SP_SHIFT) & |
5d061637 | 6790 | WMM_QOSINFO_STA_SP_MASK); |
8970bae8 | 6791 | nla_nest_end(msg, wme); |
774bfa62 EP |
6792 | } |
6793 | ||
0f4e8b4f | 6794 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
5883168a | 6795 | msg = NULL; |
0f4e8b4f | 6796 | if (ret) |
45b722f1 AN |
6797 | wpa_printf(MSG_DEBUG, "nl80211: NL80211_CMD_%s_STATION " |
6798 | "result: %d (%s)", params->set ? "SET" : "NEW", ret, | |
6799 | strerror(-ret)); | |
0f4e8b4f JM |
6800 | if (ret == -EEXIST) |
6801 | ret = 0; | |
6802 | nla_put_failure: | |
5883168a | 6803 | nlmsg_free(msg); |
0f4e8b4f JM |
6804 | return ret; |
6805 | } | |
6806 | ||
6807 | ||
9ebce9c5 | 6808 | static int wpa_driver_nl80211_sta_remove(struct i802_bss *bss, const u8 *addr) |
0f4e8b4f | 6809 | { |
a2e40bb6 | 6810 | struct wpa_driver_nl80211_data *drv = bss->drv; |
0f4e8b4f JM |
6811 | struct nl_msg *msg; |
6812 | int ret; | |
6813 | ||
6814 | msg = nlmsg_alloc(); | |
6815 | if (!msg) | |
6816 | return -ENOMEM; | |
6817 | ||
9fb04070 | 6818 | nl80211_cmd(drv, msg, 0, NL80211_CMD_DEL_STATION); |
0f4e8b4f JM |
6819 | |
6820 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, | |
a2e40bb6 | 6821 | if_nametoindex(bss->ifname)); |
0f4e8b4f JM |
6822 | NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, addr); |
6823 | ||
6824 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); | |
83e7bb0e JM |
6825 | wpa_printf(MSG_DEBUG, "nl80211: sta_remove -> DEL_STATION %s " MACSTR |
6826 | " --> %d (%s)", | |
6827 | bss->ifname, MAC2STR(addr), ret, strerror(-ret)); | |
0f4e8b4f JM |
6828 | if (ret == -ENOENT) |
6829 | return 0; | |
6830 | return ret; | |
6831 | nla_put_failure: | |
5883168a | 6832 | nlmsg_free(msg); |
0f4e8b4f JM |
6833 | return -ENOBUFS; |
6834 | } | |
6835 | ||
1581b38b | 6836 | |
0915d02c JM |
6837 | static void nl80211_remove_iface(struct wpa_driver_nl80211_data *drv, |
6838 | int ifidx) | |
6839 | { | |
6840 | struct nl_msg *msg; | |
6841 | ||
c6e8e8e4 JM |
6842 | wpa_printf(MSG_DEBUG, "nl80211: Remove interface ifindex=%d", ifidx); |
6843 | ||
2135f224 JM |
6844 | /* stop listening for EAPOL on this interface */ |
6845 | del_ifidx(drv, ifidx); | |
2135f224 | 6846 | |
0915d02c JM |
6847 | msg = nlmsg_alloc(); |
6848 | if (!msg) | |
6849 | goto nla_put_failure; | |
6850 | ||
9fb04070 | 6851 | nl80211_cmd(drv, msg, 0, NL80211_CMD_DEL_INTERFACE); |
0915d02c JM |
6852 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, ifidx); |
6853 | ||
6854 | if (send_and_recv_msgs(drv, msg, NULL, NULL) == 0) | |
6855 | return; | |
5883168a | 6856 | msg = NULL; |
0915d02c | 6857 | nla_put_failure: |
5883168a | 6858 | nlmsg_free(msg); |
e748062b | 6859 | wpa_printf(MSG_ERROR, "Failed to remove interface (ifidx=%d)", ifidx); |
0915d02c JM |
6860 | } |
6861 | ||
6862 | ||
a1922f93 JM |
6863 | static const char * nl80211_iftype_str(enum nl80211_iftype mode) |
6864 | { | |
6865 | switch (mode) { | |
6866 | case NL80211_IFTYPE_ADHOC: | |
6867 | return "ADHOC"; | |
6868 | case NL80211_IFTYPE_STATION: | |
6869 | return "STATION"; | |
6870 | case NL80211_IFTYPE_AP: | |
6871 | return "AP"; | |
1045ec36 JM |
6872 | case NL80211_IFTYPE_AP_VLAN: |
6873 | return "AP_VLAN"; | |
6874 | case NL80211_IFTYPE_WDS: | |
6875 | return "WDS"; | |
a1922f93 JM |
6876 | case NL80211_IFTYPE_MONITOR: |
6877 | return "MONITOR"; | |
1045ec36 JM |
6878 | case NL80211_IFTYPE_MESH_POINT: |
6879 | return "MESH_POINT"; | |
a1922f93 JM |
6880 | case NL80211_IFTYPE_P2P_CLIENT: |
6881 | return "P2P_CLIENT"; | |
6882 | case NL80211_IFTYPE_P2P_GO: | |
6883 | return "P2P_GO"; | |
7aad838c NS |
6884 | case NL80211_IFTYPE_P2P_DEVICE: |
6885 | return "P2P_DEVICE"; | |
a1922f93 JM |
6886 | default: |
6887 | return "unknown"; | |
6888 | } | |
6889 | } | |
6890 | ||
6891 | ||
a35187e7 KH |
6892 | static int nl80211_create_iface_once(struct wpa_driver_nl80211_data *drv, |
6893 | const char *ifname, | |
6894 | enum nl80211_iftype iftype, | |
d6dcfcda DS |
6895 | const u8 *addr, int wds, |
6896 | int (*handler)(struct nl_msg *, void *), | |
6897 | void *arg) | |
0915d02c | 6898 | { |
8970bae8 | 6899 | struct nl_msg *msg; |
0915d02c JM |
6900 | int ifidx; |
6901 | int ret = -ENOBUFS; | |
6902 | ||
a1922f93 JM |
6903 | wpa_printf(MSG_DEBUG, "nl80211: Create interface iftype %d (%s)", |
6904 | iftype, nl80211_iftype_str(iftype)); | |
6905 | ||
0915d02c JM |
6906 | msg = nlmsg_alloc(); |
6907 | if (!msg) | |
6908 | return -1; | |
6909 | ||
9fb04070 | 6910 | nl80211_cmd(drv, msg, 0, NL80211_CMD_NEW_INTERFACE); |
fa93de40 AS |
6911 | if (nl80211_set_iface_id(msg, &drv->first_bss) < 0) |
6912 | goto nla_put_failure; | |
0915d02c JM |
6913 | NLA_PUT_STRING(msg, NL80211_ATTR_IFNAME, ifname); |
6914 | NLA_PUT_U32(msg, NL80211_ATTR_IFTYPE, iftype); | |
6915 | ||
6916 | if (iftype == NL80211_IFTYPE_MONITOR) { | |
8970bae8 | 6917 | struct nlattr *flags; |
0915d02c | 6918 | |
8970bae8 | 6919 | flags = nla_nest_start(msg, NL80211_ATTR_MNTR_FLAGS); |
0915d02c JM |
6920 | if (!flags) |
6921 | goto nla_put_failure; | |
6922 | ||
8970bae8 | 6923 | NLA_PUT_FLAG(msg, NL80211_MNTR_FLAG_COOK_FRAMES); |
0915d02c | 6924 | |
8970bae8 | 6925 | nla_nest_end(msg, flags); |
fbbfcbac FF |
6926 | } else if (wds) { |
6927 | NLA_PUT_U8(msg, NL80211_ATTR_4ADDR, wds); | |
0915d02c JM |
6928 | } |
6929 | ||
d6dcfcda | 6930 | ret = send_and_recv_msgs(drv, msg, handler, arg); |
5883168a | 6931 | msg = NULL; |
0915d02c JM |
6932 | if (ret) { |
6933 | nla_put_failure: | |
5883168a | 6934 | nlmsg_free(msg); |
a35187e7 KH |
6935 | wpa_printf(MSG_ERROR, "Failed to create interface %s: %d (%s)", |
6936 | ifname, ret, strerror(-ret)); | |
0915d02c JM |
6937 | return ret; |
6938 | } | |
6939 | ||
f632e483 | 6940 | if (iftype == NL80211_IFTYPE_P2P_DEVICE) |
6bae92e0 | 6941 | return 0; |
6bae92e0 | 6942 | |
0915d02c | 6943 | ifidx = if_nametoindex(ifname); |
c6e8e8e4 JM |
6944 | wpa_printf(MSG_DEBUG, "nl80211: New interface %s created: ifindex=%d", |
6945 | ifname, ifidx); | |
0915d02c JM |
6946 | |
6947 | if (ifidx <= 0) | |
6948 | return -1; | |
6949 | ||
2135f224 JM |
6950 | /* start listening for EAPOL on this interface */ |
6951 | add_ifidx(drv, ifidx); | |
6952 | ||
7bfc47c3 | 6953 | if (addr && iftype != NL80211_IFTYPE_MONITOR && |
c81eff1a | 6954 | linux_set_ifhwaddr(drv->global->ioctl_sock, ifname, addr)) { |
41d931ee JM |
6955 | nl80211_remove_iface(drv, ifidx); |
6956 | return -1; | |
2135f224 | 6957 | } |
2135f224 | 6958 | |
0915d02c JM |
6959 | return ifidx; |
6960 | } | |
22a7c9d7 JM |
6961 | |
6962 | ||
a35187e7 KH |
6963 | static int nl80211_create_iface(struct wpa_driver_nl80211_data *drv, |
6964 | const char *ifname, enum nl80211_iftype iftype, | |
d6dcfcda DS |
6965 | const u8 *addr, int wds, |
6966 | int (*handler)(struct nl_msg *, void *), | |
6967 | void *arg) | |
a35187e7 KH |
6968 | { |
6969 | int ret; | |
6970 | ||
d6dcfcda DS |
6971 | ret = nl80211_create_iface_once(drv, ifname, iftype, addr, wds, handler, |
6972 | arg); | |
a35187e7 | 6973 | |
ffbf1eaa | 6974 | /* if error occurred and interface exists already */ |
a35187e7 KH |
6975 | if (ret == -ENFILE && if_nametoindex(ifname)) { |
6976 | wpa_printf(MSG_INFO, "Try to remove and re-create %s", ifname); | |
6977 | ||
6978 | /* Try to remove the interface that was already there. */ | |
6979 | nl80211_remove_iface(drv, if_nametoindex(ifname)); | |
6980 | ||
6981 | /* Try to create the interface again */ | |
fbbfcbac | 6982 | ret = nl80211_create_iface_once(drv, ifname, iftype, addr, |
d6dcfcda | 6983 | wds, handler, arg); |
a35187e7 KH |
6984 | } |
6985 | ||
6a71413e | 6986 | if (ret >= 0 && is_p2p_net_interface(iftype)) |
4e5cb1a3 JM |
6987 | nl80211_disable_11b_rates(drv, ret, 1); |
6988 | ||
a35187e7 KH |
6989 | return ret; |
6990 | } | |
0915d02c | 6991 | |
2135f224 | 6992 | |
0915d02c JM |
6993 | static void handle_tx_callback(void *ctx, u8 *buf, size_t len, int ok) |
6994 | { | |
6995 | struct ieee80211_hdr *hdr; | |
f8b1f695 JM |
6996 | u16 fc; |
6997 | union wpa_event_data event; | |
0915d02c JM |
6998 | |
6999 | hdr = (struct ieee80211_hdr *) buf; | |
7000 | fc = le_to_host16(hdr->frame_control); | |
7001 | ||
f8b1f695 JM |
7002 | os_memset(&event, 0, sizeof(event)); |
7003 | event.tx_status.type = WLAN_FC_GET_TYPE(fc); | |
7004 | event.tx_status.stype = WLAN_FC_GET_STYPE(fc); | |
7005 | event.tx_status.dst = hdr->addr1; | |
7006 | event.tx_status.data = buf; | |
7007 | event.tx_status.data_len = len; | |
7008 | event.tx_status.ack = ok; | |
7009 | wpa_supplicant_event(ctx, EVENT_TX_STATUS, &event); | |
0915d02c JM |
7010 | } |
7011 | ||
7012 | ||
4b9841d3 | 7013 | static void from_unknown_sta(struct wpa_driver_nl80211_data *drv, |
0d9fc3d8 | 7014 | u8 *buf, size_t len) |
0915d02c | 7015 | { |
9b90955e JB |
7016 | struct ieee80211_hdr *hdr = (void *)buf; |
7017 | u16 fc; | |
f8b1f695 | 7018 | union wpa_event_data event; |
9b90955e JB |
7019 | |
7020 | if (len < sizeof(*hdr)) | |
7021 | return; | |
7022 | ||
7023 | fc = le_to_host16(hdr->frame_control); | |
7024 | ||
f8b1f695 | 7025 | os_memset(&event, 0, sizeof(event)); |
9b90955e JB |
7026 | event.rx_from_unknown.bssid = get_hdr_bssid(hdr, len); |
7027 | event.rx_from_unknown.addr = hdr->addr2; | |
7028 | event.rx_from_unknown.wds = (fc & (WLAN_FC_FROMDS | WLAN_FC_TODS)) == | |
7029 | (WLAN_FC_FROMDS | WLAN_FC_TODS); | |
f8b1f695 | 7030 | wpa_supplicant_event(drv->ctx, EVENT_RX_FROM_UNKNOWN, &event); |
4b9841d3 | 7031 | } |
0915d02c | 7032 | |
4b9841d3 JM |
7033 | |
7034 | static void handle_frame(struct wpa_driver_nl80211_data *drv, | |
2a8b7416 | 7035 | u8 *buf, size_t len, int datarate, int ssi_signal) |
4b9841d3 JM |
7036 | { |
7037 | struct ieee80211_hdr *hdr; | |
f8b1f695 JM |
7038 | u16 fc; |
7039 | union wpa_event_data event; | |
0915d02c JM |
7040 | |
7041 | hdr = (struct ieee80211_hdr *) buf; | |
7042 | fc = le_to_host16(hdr->frame_control); | |
0915d02c | 7043 | |
4b9841d3 | 7044 | switch (WLAN_FC_GET_TYPE(fc)) { |
0915d02c | 7045 | case WLAN_FC_TYPE_MGMT: |
f8b1f695 JM |
7046 | os_memset(&event, 0, sizeof(event)); |
7047 | event.rx_mgmt.frame = buf; | |
7048 | event.rx_mgmt.frame_len = len; | |
2a8b7416 JM |
7049 | event.rx_mgmt.datarate = datarate; |
7050 | event.rx_mgmt.ssi_signal = ssi_signal; | |
f8b1f695 | 7051 | wpa_supplicant_event(drv->ctx, EVENT_RX_MGMT, &event); |
0915d02c JM |
7052 | break; |
7053 | case WLAN_FC_TYPE_CTRL: | |
7054 | /* can only get here with PS-Poll frames */ | |
7055 | wpa_printf(MSG_DEBUG, "CTRL"); | |
0d9fc3d8 | 7056 | from_unknown_sta(drv, buf, len); |
0915d02c JM |
7057 | break; |
7058 | case WLAN_FC_TYPE_DATA: | |
0d9fc3d8 | 7059 | from_unknown_sta(drv, buf, len); |
0915d02c JM |
7060 | break; |
7061 | } | |
7062 | } | |
7063 | ||
7064 | ||
7065 | static void handle_monitor_read(int sock, void *eloop_ctx, void *sock_ctx) | |
7066 | { | |
7067 | struct wpa_driver_nl80211_data *drv = eloop_ctx; | |
7068 | int len; | |
7069 | unsigned char buf[3000]; | |
7070 | struct ieee80211_radiotap_iterator iter; | |
7071 | int ret; | |
2a8b7416 | 7072 | int datarate = 0, ssi_signal = 0; |
4b9841d3 | 7073 | int injected = 0, failed = 0, rxflags = 0; |
0915d02c JM |
7074 | |
7075 | len = recv(sock, buf, sizeof(buf), 0); | |
7076 | if (len < 0) { | |
7077 | perror("recv"); | |
7078 | return; | |
7079 | } | |
7080 | ||
7081 | if (ieee80211_radiotap_iterator_init(&iter, (void*)buf, len)) { | |
7082 | printf("received invalid radiotap frame\n"); | |
7083 | return; | |
7084 | } | |
7085 | ||
0915d02c JM |
7086 | while (1) { |
7087 | ret = ieee80211_radiotap_iterator_next(&iter); | |
7088 | if (ret == -ENOENT) | |
7089 | break; | |
7090 | if (ret) { | |
7091 | printf("received invalid radiotap frame (%d)\n", ret); | |
7092 | return; | |
7093 | } | |
7094 | switch (iter.this_arg_index) { | |
7095 | case IEEE80211_RADIOTAP_FLAGS: | |
7096 | if (*iter.this_arg & IEEE80211_RADIOTAP_F_FCS) | |
7097 | len -= 4; | |
7098 | break; | |
7099 | case IEEE80211_RADIOTAP_RX_FLAGS: | |
7100 | rxflags = 1; | |
7101 | break; | |
7102 | case IEEE80211_RADIOTAP_TX_FLAGS: | |
7103 | injected = 1; | |
7104 | failed = le_to_host16((*(uint16_t *) iter.this_arg)) & | |
7105 | IEEE80211_RADIOTAP_F_TX_FAIL; | |
7106 | break; | |
7107 | case IEEE80211_RADIOTAP_DATA_RETRIES: | |
7108 | break; | |
7109 | case IEEE80211_RADIOTAP_CHANNEL: | |
2a8b7416 | 7110 | /* TODO: convert from freq/flags to channel number */ |
0915d02c JM |
7111 | break; |
7112 | case IEEE80211_RADIOTAP_RATE: | |
2a8b7416 | 7113 | datarate = *iter.this_arg * 5; |
0915d02c | 7114 | break; |
baf513d6 JB |
7115 | case IEEE80211_RADIOTAP_DBM_ANTSIGNAL: |
7116 | ssi_signal = (s8) *iter.this_arg; | |
0915d02c JM |
7117 | break; |
7118 | } | |
7119 | } | |
7120 | ||
7121 | if (rxflags && injected) | |
7122 | return; | |
7123 | ||
7124 | if (!injected) | |
4b9841d3 | 7125 | handle_frame(drv, buf + iter.max_length, |
2a8b7416 | 7126 | len - iter.max_length, datarate, ssi_signal); |
0915d02c | 7127 | else |
4b9841d3 JM |
7128 | handle_tx_callback(drv->ctx, buf + iter.max_length, |
7129 | len - iter.max_length, !failed); | |
0915d02c JM |
7130 | } |
7131 | ||
7132 | ||
7133 | /* | |
7134 | * we post-process the filter code later and rewrite | |
7135 | * this to the offset to the last instruction | |
7136 | */ | |
7137 | #define PASS 0xFF | |
7138 | #define FAIL 0xFE | |
7139 | ||
7140 | static struct sock_filter msock_filter_insns[] = { | |
7141 | /* | |
7142 | * do a little-endian load of the radiotap length field | |
7143 | */ | |
7144 | /* load lower byte into A */ | |
7145 | BPF_STMT(BPF_LD | BPF_B | BPF_ABS, 2), | |
7146 | /* put it into X (== index register) */ | |
7147 | BPF_STMT(BPF_MISC| BPF_TAX, 0), | |
7148 | /* load upper byte into A */ | |
7149 | BPF_STMT(BPF_LD | BPF_B | BPF_ABS, 3), | |
7150 | /* left-shift it by 8 */ | |
7151 | BPF_STMT(BPF_ALU | BPF_LSH | BPF_K, 8), | |
7152 | /* or with X */ | |
7153 | BPF_STMT(BPF_ALU | BPF_OR | BPF_X, 0), | |
7154 | /* put result into X */ | |
7155 | BPF_STMT(BPF_MISC| BPF_TAX, 0), | |
7156 | ||
7157 | /* | |
7158 | * Allow management frames through, this also gives us those | |
7159 | * management frames that we sent ourselves with status | |
7160 | */ | |
7161 | /* load the lower byte of the IEEE 802.11 frame control field */ | |
7162 | BPF_STMT(BPF_LD | BPF_B | BPF_IND, 0), | |
7163 | /* mask off frame type and version */ | |
7164 | BPF_STMT(BPF_ALU | BPF_AND | BPF_K, 0xF), | |
7165 | /* accept frame if it's both 0, fall through otherwise */ | |
7166 | BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 0, PASS, 0), | |
7167 | ||
7168 | /* | |
7169 | * TODO: add a bit to radiotap RX flags that indicates | |
7170 | * that the sending station is not associated, then | |
7171 | * add a filter here that filters on our DA and that flag | |
7172 | * to allow us to deauth frames to that bad station. | |
7173 | * | |
65ae1afd | 7174 | * For now allow all To DS data frames through. |
0915d02c | 7175 | */ |
65ae1afd HS |
7176 | /* load the IEEE 802.11 frame control field */ |
7177 | BPF_STMT(BPF_LD | BPF_H | BPF_IND, 0), | |
7178 | /* mask off frame type, version and DS status */ | |
7179 | BPF_STMT(BPF_ALU | BPF_AND | BPF_K, 0x0F03), | |
7180 | /* accept frame if version 0, type 2 and To DS, fall through otherwise | |
7181 | */ | |
7182 | BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 0x0801, PASS, 0), | |
0915d02c JM |
7183 | |
7184 | #if 0 | |
7185 | /* | |
fbbfcbac | 7186 | * drop non-data frames |
0915d02c JM |
7187 | */ |
7188 | /* load the lower byte of the frame control field */ | |
7189 | BPF_STMT(BPF_LD | BPF_B | BPF_IND, 0), | |
7190 | /* mask off QoS bit */ | |
7191 | BPF_STMT(BPF_ALU | BPF_AND | BPF_K, 0x0c), | |
7192 | /* drop non-data frames */ | |
7193 | BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 8, 0, FAIL), | |
fbbfcbac | 7194 | #endif |
0915d02c | 7195 | /* load the upper byte of the frame control field */ |
fbbfcbac | 7196 | BPF_STMT(BPF_LD | BPF_B | BPF_IND, 1), |
0915d02c JM |
7197 | /* mask off toDS/fromDS */ |
7198 | BPF_STMT(BPF_ALU | BPF_AND | BPF_K, 0x03), | |
fbbfcbac FF |
7199 | /* accept WDS frames */ |
7200 | BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 3, PASS, 0), | |
0915d02c JM |
7201 | |
7202 | /* | |
7203 | * add header length to index | |
7204 | */ | |
7205 | /* load the lower byte of the frame control field */ | |
7206 | BPF_STMT(BPF_LD | BPF_B | BPF_IND, 0), | |
7207 | /* mask off QoS bit */ | |
7208 | BPF_STMT(BPF_ALU | BPF_AND | BPF_K, 0x80), | |
7209 | /* right shift it by 6 to give 0 or 2 */ | |
7210 | BPF_STMT(BPF_ALU | BPF_RSH | BPF_K, 6), | |
7211 | /* add data frame header length */ | |
7212 | BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, 24), | |
7213 | /* add index, was start of 802.11 header */ | |
7214 | BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0), | |
7215 | /* move to index, now start of LL header */ | |
7216 | BPF_STMT(BPF_MISC | BPF_TAX, 0), | |
7217 | ||
7218 | /* | |
7219 | * Accept empty data frames, we use those for | |
7220 | * polling activity. | |
7221 | */ | |
7222 | BPF_STMT(BPF_LD | BPF_W | BPF_LEN, 0), | |
7223 | BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_X, 0, PASS, 0), | |
7224 | ||
7225 | /* | |
7226 | * Accept EAPOL frames | |
7227 | */ | |
7228 | BPF_STMT(BPF_LD | BPF_W | BPF_IND, 0), | |
7229 | BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 0xAAAA0300, 0, FAIL), | |
7230 | BPF_STMT(BPF_LD | BPF_W | BPF_IND, 4), | |
7231 | BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 0x0000888E, PASS, FAIL), | |
7232 | ||
7233 | /* keep these last two statements or change the code below */ | |
7234 | /* return 0 == "DROP" */ | |
7235 | BPF_STMT(BPF_RET | BPF_K, 0), | |
7236 | /* return ~0 == "keep all" */ | |
7237 | BPF_STMT(BPF_RET | BPF_K, ~0), | |
7238 | }; | |
7239 | ||
7240 | static struct sock_fprog msock_filter = { | |
e7ecab4a | 7241 | .len = ARRAY_SIZE(msock_filter_insns), |
0915d02c JM |
7242 | .filter = msock_filter_insns, |
7243 | }; | |
7244 | ||
7245 | ||
7246 | static int add_monitor_filter(int s) | |
7247 | { | |
7248 | int idx; | |
7249 | ||
7250 | /* rewrite all PASS/FAIL jump offsets */ | |
7251 | for (idx = 0; idx < msock_filter.len; idx++) { | |
7252 | struct sock_filter *insn = &msock_filter_insns[idx]; | |
7253 | ||
7254 | if (BPF_CLASS(insn->code) == BPF_JMP) { | |
7255 | if (insn->code == (BPF_JMP|BPF_JA)) { | |
7256 | if (insn->k == PASS) | |
7257 | insn->k = msock_filter.len - idx - 2; | |
7258 | else if (insn->k == FAIL) | |
7259 | insn->k = msock_filter.len - idx - 3; | |
7260 | } | |
7261 | ||
7262 | if (insn->jt == PASS) | |
7263 | insn->jt = msock_filter.len - idx - 2; | |
7264 | else if (insn->jt == FAIL) | |
7265 | insn->jt = msock_filter.len - idx - 3; | |
7266 | ||
7267 | if (insn->jf == PASS) | |
7268 | insn->jf = msock_filter.len - idx - 2; | |
7269 | else if (insn->jf == FAIL) | |
7270 | insn->jf = msock_filter.len - idx - 3; | |
7271 | } | |
7272 | } | |
7273 | ||
7274 | if (setsockopt(s, SOL_SOCKET, SO_ATTACH_FILTER, | |
7275 | &msock_filter, sizeof(msock_filter))) { | |
7276 | perror("SO_ATTACH_FILTER"); | |
7277 | return -1; | |
7278 | } | |
7279 | ||
7280 | return 0; | |
7281 | } | |
7282 | ||
7283 | ||
460456f8 JM |
7284 | static void nl80211_remove_monitor_interface( |
7285 | struct wpa_driver_nl80211_data *drv) | |
7286 | { | |
3fd1cefb JB |
7287 | drv->monitor_refcount--; |
7288 | if (drv->monitor_refcount > 0) | |
7289 | return; | |
7290 | ||
460456f8 JM |
7291 | if (drv->monitor_ifidx >= 0) { |
7292 | nl80211_remove_iface(drv, drv->monitor_ifidx); | |
7293 | drv->monitor_ifidx = -1; | |
7294 | } | |
504e905c JM |
7295 | if (drv->monitor_sock >= 0) { |
7296 | eloop_unregister_read_sock(drv->monitor_sock); | |
7297 | close(drv->monitor_sock); | |
7298 | drv->monitor_sock = -1; | |
7299 | } | |
460456f8 JM |
7300 | } |
7301 | ||
7302 | ||
0915d02c JM |
7303 | static int |
7304 | nl80211_create_monitor_interface(struct wpa_driver_nl80211_data *drv) | |
7305 | { | |
7306 | char buf[IFNAMSIZ]; | |
7307 | struct sockaddr_ll ll; | |
7308 | int optval; | |
7309 | socklen_t optlen; | |
0915d02c | 7310 | |
3fd1cefb JB |
7311 | if (drv->monitor_ifidx >= 0) { |
7312 | drv->monitor_refcount++; | |
7313 | return 0; | |
7314 | } | |
7315 | ||
6758b167 JJ |
7316 | if (os_strncmp(drv->first_bss.ifname, "p2p-", 4) == 0) { |
7317 | /* | |
7318 | * P2P interface name is of the format p2p-%s-%d. For monitor | |
7319 | * interface name corresponding to P2P GO, replace "p2p-" with | |
7320 | * "mon-" to retain the same interface name length and to | |
7321 | * indicate that it is a monitor interface. | |
7322 | */ | |
7323 | snprintf(buf, IFNAMSIZ, "mon-%s", drv->first_bss.ifname + 4); | |
7324 | } else { | |
7325 | /* Non-P2P interface with AP functionality. */ | |
7326 | snprintf(buf, IFNAMSIZ, "mon.%s", drv->first_bss.ifname); | |
7327 | } | |
7328 | ||
0915d02c JM |
7329 | buf[IFNAMSIZ - 1] = '\0'; |
7330 | ||
7331 | drv->monitor_ifidx = | |
fbbfcbac | 7332 | nl80211_create_iface(drv, buf, NL80211_IFTYPE_MONITOR, NULL, |
d6dcfcda | 7333 | 0, NULL, NULL); |
0915d02c | 7334 | |
866af8b6 | 7335 | if (drv->monitor_ifidx == -EOPNOTSUPP) { |
61cbe2ff JB |
7336 | /* |
7337 | * This is backward compatibility for a few versions of | |
7338 | * the kernel only that didn't advertise the right | |
7339 | * attributes for the only driver that then supported | |
7340 | * AP mode w/o monitor -- ath6kl. | |
7341 | */ | |
866af8b6 JM |
7342 | wpa_printf(MSG_DEBUG, "nl80211: Driver does not support " |
7343 | "monitor interface type - try to run without it"); | |
61cbe2ff | 7344 | drv->device_ap_sme = 1; |
866af8b6 JM |
7345 | } |
7346 | ||
0915d02c JM |
7347 | if (drv->monitor_ifidx < 0) |
7348 | return -1; | |
7349 | ||
c81eff1a | 7350 | if (linux_set_iface_flags(drv->global->ioctl_sock, buf, 1)) |
0915d02c | 7351 | goto error; |
0915d02c JM |
7352 | |
7353 | memset(&ll, 0, sizeof(ll)); | |
7354 | ll.sll_family = AF_PACKET; | |
7355 | ll.sll_ifindex = drv->monitor_ifidx; | |
7356 | drv->monitor_sock = socket(PF_PACKET, SOCK_RAW, htons(ETH_P_ALL)); | |
7357 | if (drv->monitor_sock < 0) { | |
7358 | perror("socket[PF_PACKET,SOCK_RAW]"); | |
7359 | goto error; | |
7360 | } | |
7361 | ||
7362 | if (add_monitor_filter(drv->monitor_sock)) { | |
7363 | wpa_printf(MSG_INFO, "Failed to set socket filter for monitor " | |
7364 | "interface; do filtering in user space"); | |
7365 | /* This works, but will cost in performance. */ | |
7366 | } | |
7367 | ||
2135f224 | 7368 | if (bind(drv->monitor_sock, (struct sockaddr *) &ll, sizeof(ll)) < 0) { |
0915d02c JM |
7369 | perror("monitor socket bind"); |
7370 | goto error; | |
7371 | } | |
7372 | ||
7373 | optlen = sizeof(optval); | |
7374 | optval = 20; | |
7375 | if (setsockopt | |
7376 | (drv->monitor_sock, SOL_SOCKET, SO_PRIORITY, &optval, optlen)) { | |
7377 | perror("Failed to set socket priority"); | |
7378 | goto error; | |
7379 | } | |
7380 | ||
7381 | if (eloop_register_read_sock(drv->monitor_sock, handle_monitor_read, | |
7382 | drv, NULL)) { | |
7383 | printf("Could not register monitor read socket\n"); | |
7384 | goto error; | |
7385 | } | |
7386 | ||
7387 | return 0; | |
7388 | error: | |
460456f8 | 7389 | nl80211_remove_monitor_interface(drv); |
0915d02c JM |
7390 | return -1; |
7391 | } | |
7392 | ||
db149ac9 | 7393 | |
3fd1cefb JB |
7394 | static int nl80211_setup_ap(struct i802_bss *bss) |
7395 | { | |
7396 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
7397 | ||
36488c05 JM |
7398 | wpa_printf(MSG_DEBUG, "nl80211: Setup AP - device_ap_sme=%d " |
7399 | "use_monitor=%d", drv->device_ap_sme, drv->use_monitor); | |
7400 | ||
a11241fa JB |
7401 | /* |
7402 | * Disable Probe Request reporting unless we need it in this way for | |
7403 | * devices that include the AP SME, in the other case (unless using | |
7404 | * monitor iface) we'll get it through the nl_mgmt socket instead. | |
7405 | */ | |
7406 | if (!drv->device_ap_sme) | |
7407 | wpa_driver_nl80211_probe_req_report(bss, 0); | |
7408 | ||
7409 | if (!drv->device_ap_sme && !drv->use_monitor) | |
7410 | if (nl80211_mgmt_subscribe_ap(bss)) | |
7411 | return -1; | |
7412 | ||
a6cc0602 JM |
7413 | if (drv->device_ap_sme && !drv->use_monitor) |
7414 | if (nl80211_mgmt_subscribe_ap_dev_sme(bss)) | |
7415 | return -1; | |
7416 | ||
a11241fa | 7417 | if (!drv->device_ap_sme && drv->use_monitor && |
3fd1cefb JB |
7418 | nl80211_create_monitor_interface(drv) && |
7419 | !drv->device_ap_sme) | |
7420 | return -1; | |
7421 | ||
7422 | if (drv->device_ap_sme && | |
7423 | wpa_driver_nl80211_probe_req_report(bss, 1) < 0) { | |
7424 | wpa_printf(MSG_DEBUG, "nl80211: Failed to enable " | |
7425 | "Probe Request frame reporting in AP mode"); | |
7426 | /* Try to survive without this */ | |
7427 | } | |
7428 | ||
7429 | return 0; | |
7430 | } | |
7431 | ||
7432 | ||
7433 | static void nl80211_teardown_ap(struct i802_bss *bss) | |
7434 | { | |
7435 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
7436 | ||
a6cc0602 | 7437 | if (drv->device_ap_sme) { |
3fd1cefb | 7438 | wpa_driver_nl80211_probe_req_report(bss, 0); |
a6cc0602 JM |
7439 | if (!drv->use_monitor) |
7440 | nl80211_mgmt_unsubscribe(bss, "AP teardown (dev SME)"); | |
7441 | } else if (drv->use_monitor) | |
3fd1cefb | 7442 | nl80211_remove_monitor_interface(drv); |
a11241fa | 7443 | else |
36488c05 | 7444 | nl80211_mgmt_unsubscribe(bss, "AP teardown"); |
a11241fa | 7445 | |
3fd1cefb JB |
7446 | bss->beacon_set = 0; |
7447 | } | |
7448 | ||
7449 | ||
f10bfc9a JM |
7450 | static int nl80211_send_eapol_data(struct i802_bss *bss, |
7451 | const u8 *addr, const u8 *data, | |
d12dab4c | 7452 | size_t data_len) |
f10bfc9a | 7453 | { |
d12dab4c JB |
7454 | struct sockaddr_ll ll; |
7455 | int ret; | |
7456 | ||
7457 | if (bss->drv->eapol_tx_sock < 0) { | |
7458 | wpa_printf(MSG_DEBUG, "nl80211: No socket to send EAPOL"); | |
f10bfc9a JM |
7459 | return -1; |
7460 | } | |
7461 | ||
d12dab4c JB |
7462 | os_memset(&ll, 0, sizeof(ll)); |
7463 | ll.sll_family = AF_PACKET; | |
7464 | ll.sll_ifindex = bss->ifindex; | |
7465 | ll.sll_protocol = htons(ETH_P_PAE); | |
7466 | ll.sll_halen = ETH_ALEN; | |
7467 | os_memcpy(ll.sll_addr, addr, ETH_ALEN); | |
7468 | ret = sendto(bss->drv->eapol_tx_sock, data, data_len, 0, | |
7469 | (struct sockaddr *) &ll, sizeof(ll)); | |
7470 | if (ret < 0) | |
7471 | wpa_printf(MSG_ERROR, "nl80211: EAPOL TX: %s", | |
7472 | strerror(errno)); | |
7473 | ||
7474 | return ret; | |
f10bfc9a | 7475 | } |
5fb1a232 | 7476 | |
f10bfc9a | 7477 | |
db149ac9 JM |
7478 | static const u8 rfc1042_header[6] = { 0xaa, 0xaa, 0x03, 0x00, 0x00, 0x00 }; |
7479 | ||
7480 | static int wpa_driver_nl80211_hapd_send_eapol( | |
7481 | void *priv, const u8 *addr, const u8 *data, | |
4378fc14 | 7482 | size_t data_len, int encrypt, const u8 *own_addr, u32 flags) |
db149ac9 | 7483 | { |
a2e40bb6 FF |
7484 | struct i802_bss *bss = priv; |
7485 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
db149ac9 JM |
7486 | struct ieee80211_hdr *hdr; |
7487 | size_t len; | |
7488 | u8 *pos; | |
7489 | int res; | |
4378fc14 | 7490 | int qos = flags & WPA_STA_WMM; |
db149ac9 | 7491 | |
a11241fa | 7492 | if (drv->device_ap_sme || !drv->use_monitor) |
d12dab4c | 7493 | return nl80211_send_eapol_data(bss, addr, data, data_len); |
f10bfc9a | 7494 | |
db149ac9 JM |
7495 | len = sizeof(*hdr) + (qos ? 2 : 0) + sizeof(rfc1042_header) + 2 + |
7496 | data_len; | |
7497 | hdr = os_zalloc(len); | |
7498 | if (hdr == NULL) { | |
7499 | printf("malloc() failed for i802_send_data(len=%lu)\n", | |
7500 | (unsigned long) len); | |
7501 | return -1; | |
7502 | } | |
7503 | ||
7504 | hdr->frame_control = | |
7505 | IEEE80211_FC(WLAN_FC_TYPE_DATA, WLAN_FC_STYPE_DATA); | |
7506 | hdr->frame_control |= host_to_le16(WLAN_FC_FROMDS); | |
7507 | if (encrypt) | |
7508 | hdr->frame_control |= host_to_le16(WLAN_FC_ISWEP); | |
db149ac9 JM |
7509 | if (qos) { |
7510 | hdr->frame_control |= | |
7511 | host_to_le16(WLAN_FC_STYPE_QOS_DATA << 4); | |
7512 | } | |
db149ac9 JM |
7513 | |
7514 | memcpy(hdr->IEEE80211_DA_FROMDS, addr, ETH_ALEN); | |
7515 | memcpy(hdr->IEEE80211_BSSID_FROMDS, own_addr, ETH_ALEN); | |
7516 | memcpy(hdr->IEEE80211_SA_FROMDS, own_addr, ETH_ALEN); | |
7517 | pos = (u8 *) (hdr + 1); | |
7518 | ||
db149ac9 | 7519 | if (qos) { |
92d521d8 FF |
7520 | /* Set highest priority in QoS header */ |
7521 | pos[0] = 7; | |
db149ac9 JM |
7522 | pos[1] = 0; |
7523 | pos += 2; | |
7524 | } | |
db149ac9 JM |
7525 | |
7526 | memcpy(pos, rfc1042_header, sizeof(rfc1042_header)); | |
7527 | pos += sizeof(rfc1042_header); | |
7528 | WPA_PUT_BE16(pos, ETH_P_PAE); | |
7529 | pos += 2; | |
7530 | memcpy(pos, data, data_len); | |
7531 | ||
55231068 JM |
7532 | res = wpa_driver_nl80211_send_frame(bss, (u8 *) hdr, len, encrypt, 0, |
7533 | 0, 0, 0, 0); | |
db149ac9 JM |
7534 | if (res < 0) { |
7535 | wpa_printf(MSG_ERROR, "i802_send_eapol - packet len: %lu - " | |
7536 | "failed: %d (%s)", | |
7537 | (unsigned long) len, errno, strerror(errno)); | |
7538 | } | |
7bf12757 | 7539 | os_free(hdr); |
db149ac9 JM |
7540 | |
7541 | return res; | |
7542 | } | |
7543 | ||
a8d6ffa4 | 7544 | |
3234cba4 JM |
7545 | static int wpa_driver_nl80211_sta_set_flags(void *priv, const u8 *addr, |
7546 | int total_flags, | |
4c32757d | 7547 | int flags_or, int flags_and) |
a8d6ffa4 | 7548 | { |
a2e40bb6 FF |
7549 | struct i802_bss *bss = priv; |
7550 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
8970bae8 JB |
7551 | struct nl_msg *msg; |
7552 | struct nlattr *flags; | |
7e76ee9c | 7553 | struct nl80211_sta_flag_update upd; |
a8d6ffa4 JM |
7554 | |
7555 | msg = nlmsg_alloc(); | |
7556 | if (!msg) | |
7557 | return -ENOMEM; | |
7558 | ||
9fb04070 | 7559 | nl80211_cmd(drv, msg, 0, NL80211_CMD_SET_STATION); |
a8d6ffa4 JM |
7560 | |
7561 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, | |
3234cba4 | 7562 | if_nametoindex(bss->ifname)); |
a8d6ffa4 JM |
7563 | NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, addr); |
7564 | ||
7e76ee9c JM |
7565 | /* |
7566 | * Backwards compatibility version using NL80211_ATTR_STA_FLAGS. This | |
7567 | * can be removed eventually. | |
7568 | */ | |
8970bae8 JB |
7569 | flags = nla_nest_start(msg, NL80211_ATTR_STA_FLAGS); |
7570 | if (!flags) | |
7571 | goto nla_put_failure; | |
0de39516 | 7572 | if (total_flags & WPA_STA_AUTHORIZED) |
8970bae8 | 7573 | NLA_PUT_FLAG(msg, NL80211_STA_FLAG_AUTHORIZED); |
a8d6ffa4 | 7574 | |
0de39516 | 7575 | if (total_flags & WPA_STA_WMM) |
8970bae8 | 7576 | NLA_PUT_FLAG(msg, NL80211_STA_FLAG_WME); |
a8d6ffa4 | 7577 | |
0de39516 | 7578 | if (total_flags & WPA_STA_SHORT_PREAMBLE) |
8970bae8 | 7579 | NLA_PUT_FLAG(msg, NL80211_STA_FLAG_SHORT_PREAMBLE); |
a8d6ffa4 | 7580 | |
0de39516 | 7581 | if (total_flags & WPA_STA_MFP) |
8970bae8 | 7582 | NLA_PUT_FLAG(msg, NL80211_STA_FLAG_MFP); |
a8d6ffa4 | 7583 | |
45b722f1 | 7584 | if (total_flags & WPA_STA_TDLS_PEER) |
8970bae8 | 7585 | NLA_PUT_FLAG(msg, NL80211_STA_FLAG_TDLS_PEER); |
45b722f1 | 7586 | |
8970bae8 | 7587 | nla_nest_end(msg, flags); |
a8d6ffa4 | 7588 | |
7e76ee9c JM |
7589 | os_memset(&upd, 0, sizeof(upd)); |
7590 | upd.mask = sta_flags_nl80211(flags_or | ~flags_and); | |
7591 | upd.set = sta_flags_nl80211(flags_or); | |
7592 | NLA_PUT(msg, NL80211_ATTR_STA_FLAGS2, sizeof(upd), &upd); | |
7593 | ||
a8d6ffa4 JM |
7594 | return send_and_recv_msgs(drv, msg, NULL, NULL); |
7595 | nla_put_failure: | |
5883168a | 7596 | nlmsg_free(msg); |
a8d6ffa4 JM |
7597 | return -ENOBUFS; |
7598 | } | |
7599 | ||
0915d02c | 7600 | |
1581b38b JM |
7601 | static int wpa_driver_nl80211_ap(struct wpa_driver_nl80211_data *drv, |
7602 | struct wpa_driver_associate_params *params) | |
7603 | { | |
708bc8e0 | 7604 | enum nl80211_iftype nlmode, old_mode; |
89b800d7 JB |
7605 | struct hostapd_freq_params freq = { |
7606 | .freq = params->freq, | |
7607 | }; | |
b1f625e0 EP |
7608 | |
7609 | if (params->p2p) { | |
046b26a2 JM |
7610 | wpa_printf(MSG_DEBUG, "nl80211: Setup AP operations for P2P " |
7611 | "group (GO)"); | |
b1f625e0 EP |
7612 | nlmode = NL80211_IFTYPE_P2P_GO; |
7613 | } else | |
7614 | nlmode = NL80211_IFTYPE_AP; | |
7615 | ||
708bc8e0 JM |
7616 | old_mode = drv->nlmode; |
7617 | if (wpa_driver_nl80211_set_mode(&drv->first_bss, nlmode)) { | |
7618 | nl80211_remove_monitor_interface(drv); | |
7619 | return -1; | |
7620 | } | |
7621 | ||
89b800d7 | 7622 | if (wpa_driver_nl80211_set_freq(&drv->first_bss, &freq)) { |
708bc8e0 JM |
7623 | if (old_mode != nlmode) |
7624 | wpa_driver_nl80211_set_mode(&drv->first_bss, old_mode); | |
460456f8 | 7625 | nl80211_remove_monitor_interface(drv); |
1581b38b | 7626 | return -1; |
0915d02c | 7627 | } |
1581b38b | 7628 | |
1581b38b JM |
7629 | return 0; |
7630 | } | |
1581b38b JM |
7631 | |
7632 | ||
5cc4d64b JM |
7633 | static int nl80211_leave_ibss(struct wpa_driver_nl80211_data *drv) |
7634 | { | |
7635 | struct nl_msg *msg; | |
7636 | int ret = -1; | |
7637 | ||
7638 | msg = nlmsg_alloc(); | |
7639 | if (!msg) | |
7640 | return -1; | |
7641 | ||
9fb04070 | 7642 | nl80211_cmd(drv, msg, 0, NL80211_CMD_LEAVE_IBSS); |
5cc4d64b JM |
7643 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, drv->ifindex); |
7644 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); | |
7645 | msg = NULL; | |
7646 | if (ret) { | |
7647 | wpa_printf(MSG_DEBUG, "nl80211: Leave IBSS failed: ret=%d " | |
7648 | "(%s)", ret, strerror(-ret)); | |
7649 | goto nla_put_failure; | |
7650 | } | |
7651 | ||
7652 | ret = 0; | |
7653 | wpa_printf(MSG_DEBUG, "nl80211: Leave IBSS request sent successfully"); | |
7654 | ||
7655 | nla_put_failure: | |
5d4c78fb JM |
7656 | if (wpa_driver_nl80211_set_mode(&drv->first_bss, |
7657 | NL80211_IFTYPE_STATION)) { | |
7658 | wpa_printf(MSG_INFO, "nl80211: Failed to set interface into " | |
7659 | "station mode"); | |
7660 | } | |
7661 | ||
5cc4d64b JM |
7662 | nlmsg_free(msg); |
7663 | return ret; | |
7664 | } | |
7665 | ||
7666 | ||
7667 | static int wpa_driver_nl80211_ibss(struct wpa_driver_nl80211_data *drv, | |
7668 | struct wpa_driver_associate_params *params) | |
7669 | { | |
7670 | struct nl_msg *msg; | |
7671 | int ret = -1; | |
7672 | int count = 0; | |
7673 | ||
7674 | wpa_printf(MSG_DEBUG, "nl80211: Join IBSS (ifindex=%d)", drv->ifindex); | |
7675 | ||
b1f625e0 EP |
7676 | if (wpa_driver_nl80211_set_mode(&drv->first_bss, |
7677 | NL80211_IFTYPE_ADHOC)) { | |
5cc4d64b JM |
7678 | wpa_printf(MSG_INFO, "nl80211: Failed to set interface into " |
7679 | "IBSS mode"); | |
7680 | return -1; | |
7681 | } | |
7682 | ||
7683 | retry: | |
7684 | msg = nlmsg_alloc(); | |
7685 | if (!msg) | |
7686 | return -1; | |
7687 | ||
9fb04070 | 7688 | nl80211_cmd(drv, msg, 0, NL80211_CMD_JOIN_IBSS); |
5cc4d64b JM |
7689 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, drv->ifindex); |
7690 | ||
7691 | if (params->ssid == NULL || params->ssid_len > sizeof(drv->ssid)) | |
7692 | goto nla_put_failure; | |
7693 | ||
7694 | wpa_hexdump_ascii(MSG_DEBUG, " * SSID", | |
7695 | params->ssid, params->ssid_len); | |
7696 | NLA_PUT(msg, NL80211_ATTR_SSID, params->ssid_len, | |
7697 | params->ssid); | |
7698 | os_memcpy(drv->ssid, params->ssid, params->ssid_len); | |
7699 | drv->ssid_len = params->ssid_len; | |
7700 | ||
7701 | wpa_printf(MSG_DEBUG, " * freq=%d", params->freq); | |
7702 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_FREQ, params->freq); | |
7703 | ||
7704 | ret = nl80211_set_conn_keys(params, msg); | |
7705 | if (ret) | |
7706 | goto nla_put_failure; | |
7707 | ||
913e3cf7 NC |
7708 | if (params->bssid && params->fixed_bssid) { |
7709 | wpa_printf(MSG_DEBUG, " * BSSID=" MACSTR, | |
7710 | MAC2STR(params->bssid)); | |
7711 | NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, params->bssid); | |
7712 | } | |
7713 | ||
e640888c AQ |
7714 | if (params->key_mgmt_suite == KEY_MGMT_802_1X || |
7715 | params->key_mgmt_suite == KEY_MGMT_PSK || | |
7716 | params->key_mgmt_suite == KEY_MGMT_802_1X_SHA256 || | |
7717 | params->key_mgmt_suite == KEY_MGMT_PSK_SHA256) { | |
7718 | wpa_printf(MSG_DEBUG, " * control port"); | |
7719 | NLA_PUT_FLAG(msg, NL80211_ATTR_CONTROL_PORT); | |
7720 | } | |
7721 | ||
a95795ad JM |
7722 | if (params->wpa_ie) { |
7723 | wpa_hexdump(MSG_DEBUG, | |
7724 | " * Extra IEs for Beacon/Probe Response frames", | |
7725 | params->wpa_ie, params->wpa_ie_len); | |
7726 | NLA_PUT(msg, NL80211_ATTR_IE, params->wpa_ie_len, | |
7727 | params->wpa_ie); | |
7728 | } | |
7729 | ||
5cc4d64b JM |
7730 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
7731 | msg = NULL; | |
7732 | if (ret) { | |
7733 | wpa_printf(MSG_DEBUG, "nl80211: Join IBSS failed: ret=%d (%s)", | |
7734 | ret, strerror(-ret)); | |
7735 | count++; | |
7736 | if (ret == -EALREADY && count == 1) { | |
7737 | wpa_printf(MSG_DEBUG, "nl80211: Retry IBSS join after " | |
7738 | "forced leave"); | |
7739 | nl80211_leave_ibss(drv); | |
7740 | nlmsg_free(msg); | |
7741 | goto retry; | |
7742 | } | |
7743 | ||
7744 | goto nla_put_failure; | |
7745 | } | |
7746 | ret = 0; | |
7747 | wpa_printf(MSG_DEBUG, "nl80211: Join IBSS request sent successfully"); | |
7748 | ||
7749 | nla_put_failure: | |
7750 | nlmsg_free(msg); | |
7751 | return ret; | |
7752 | } | |
7753 | ||
7754 | ||
a8c5b43a | 7755 | static int wpa_driver_nl80211_try_connect( |
cfaab580 ZY |
7756 | struct wpa_driver_nl80211_data *drv, |
7757 | struct wpa_driver_associate_params *params) | |
7758 | { | |
7759 | struct nl_msg *msg; | |
7760 | enum nl80211_auth_type type; | |
7761 | int ret = 0; | |
3f360238 | 7762 | int algs; |
cfaab580 ZY |
7763 | |
7764 | msg = nlmsg_alloc(); | |
7765 | if (!msg) | |
7766 | return -1; | |
7767 | ||
7768 | wpa_printf(MSG_DEBUG, "nl80211: Connect (ifindex=%d)", drv->ifindex); | |
9fb04070 | 7769 | nl80211_cmd(drv, msg, 0, NL80211_CMD_CONNECT); |
cfaab580 ZY |
7770 | |
7771 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, drv->ifindex); | |
7772 | if (params->bssid) { | |
7773 | wpa_printf(MSG_DEBUG, " * bssid=" MACSTR, | |
7774 | MAC2STR(params->bssid)); | |
7775 | NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, params->bssid); | |
7776 | } | |
7777 | if (params->freq) { | |
7778 | wpa_printf(MSG_DEBUG, " * freq=%d", params->freq); | |
7779 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_FREQ, params->freq); | |
30158a0d SD |
7780 | drv->assoc_freq = params->freq; |
7781 | } else | |
7782 | drv->assoc_freq = 0; | |
1f6c0ab8 BS |
7783 | if (params->bg_scan_period >= 0) { |
7784 | wpa_printf(MSG_DEBUG, " * bg scan period=%d", | |
7785 | params->bg_scan_period); | |
7786 | NLA_PUT_U16(msg, NL80211_ATTR_BG_SCAN_PERIOD, | |
7787 | params->bg_scan_period); | |
7788 | } | |
cfaab580 ZY |
7789 | if (params->ssid) { |
7790 | wpa_hexdump_ascii(MSG_DEBUG, " * SSID", | |
7791 | params->ssid, params->ssid_len); | |
7792 | NLA_PUT(msg, NL80211_ATTR_SSID, params->ssid_len, | |
7793 | params->ssid); | |
7794 | if (params->ssid_len > sizeof(drv->ssid)) | |
7795 | goto nla_put_failure; | |
7796 | os_memcpy(drv->ssid, params->ssid, params->ssid_len); | |
7797 | drv->ssid_len = params->ssid_len; | |
7798 | } | |
7799 | wpa_hexdump(MSG_DEBUG, " * IEs", params->wpa_ie, params->wpa_ie_len); | |
7800 | if (params->wpa_ie) | |
7801 | NLA_PUT(msg, NL80211_ATTR_IE, params->wpa_ie_len, | |
7802 | params->wpa_ie); | |
7803 | ||
3f360238 JM |
7804 | algs = 0; |
7805 | if (params->auth_alg & WPA_AUTH_ALG_OPEN) | |
7806 | algs++; | |
7807 | if (params->auth_alg & WPA_AUTH_ALG_SHARED) | |
7808 | algs++; | |
7809 | if (params->auth_alg & WPA_AUTH_ALG_LEAP) | |
7810 | algs++; | |
7811 | if (algs > 1) { | |
7812 | wpa_printf(MSG_DEBUG, " * Leave out Auth Type for automatic " | |
7813 | "selection"); | |
7814 | goto skip_auth_type; | |
7815 | } | |
7816 | ||
abd9fafa | 7817 | if (params->auth_alg & WPA_AUTH_ALG_OPEN) |
cfaab580 | 7818 | type = NL80211_AUTHTYPE_OPEN_SYSTEM; |
abd9fafa | 7819 | else if (params->auth_alg & WPA_AUTH_ALG_SHARED) |
cfaab580 | 7820 | type = NL80211_AUTHTYPE_SHARED_KEY; |
abd9fafa | 7821 | else if (params->auth_alg & WPA_AUTH_ALG_LEAP) |
cfaab580 | 7822 | type = NL80211_AUTHTYPE_NETWORK_EAP; |
abd9fafa | 7823 | else if (params->auth_alg & WPA_AUTH_ALG_FT) |
cfaab580 ZY |
7824 | type = NL80211_AUTHTYPE_FT; |
7825 | else | |
7826 | goto nla_put_failure; | |
7827 | ||
7828 | wpa_printf(MSG_DEBUG, " * Auth Type %d", type); | |
7829 | NLA_PUT_U32(msg, NL80211_ATTR_AUTH_TYPE, type); | |
7830 | ||
3f360238 | 7831 | skip_auth_type: |
64fa840a JM |
7832 | if (params->wpa_proto) { |
7833 | enum nl80211_wpa_versions ver = 0; | |
cfaab580 | 7834 | |
64fa840a JM |
7835 | if (params->wpa_proto & WPA_PROTO_WPA) |
7836 | ver |= NL80211_WPA_VERSION_1; | |
7837 | if (params->wpa_proto & WPA_PROTO_RSN) | |
7838 | ver |= NL80211_WPA_VERSION_2; | |
cfaab580 | 7839 | |
64fa840a | 7840 | wpa_printf(MSG_DEBUG, " * WPA Versions 0x%x", ver); |
cfaab580 ZY |
7841 | NLA_PUT_U32(msg, NL80211_ATTR_WPA_VERSIONS, ver); |
7842 | } | |
7843 | ||
7844 | if (params->pairwise_suite != CIPHER_NONE) { | |
c1bb3e0a | 7845 | int cipher; |
cfaab580 ZY |
7846 | |
7847 | switch (params->pairwise_suite) { | |
369c8d7b JM |
7848 | case CIPHER_SMS4: |
7849 | cipher = WLAN_CIPHER_SUITE_SMS4; | |
7850 | break; | |
cfaab580 ZY |
7851 | case CIPHER_WEP40: |
7852 | cipher = WLAN_CIPHER_SUITE_WEP40; | |
7853 | break; | |
7854 | case CIPHER_WEP104: | |
7855 | cipher = WLAN_CIPHER_SUITE_WEP104; | |
7856 | break; | |
7857 | case CIPHER_CCMP: | |
7858 | cipher = WLAN_CIPHER_SUITE_CCMP; | |
7859 | break; | |
eb7719ff JM |
7860 | case CIPHER_GCMP: |
7861 | cipher = WLAN_CIPHER_SUITE_GCMP; | |
7862 | break; | |
cfaab580 ZY |
7863 | case CIPHER_TKIP: |
7864 | default: | |
7865 | cipher = WLAN_CIPHER_SUITE_TKIP; | |
7866 | break; | |
7867 | } | |
7868 | NLA_PUT_U32(msg, NL80211_ATTR_CIPHER_SUITES_PAIRWISE, cipher); | |
7869 | } | |
7870 | ||
7871 | if (params->group_suite != CIPHER_NONE) { | |
c1bb3e0a | 7872 | int cipher; |
cfaab580 ZY |
7873 | |
7874 | switch (params->group_suite) { | |
369c8d7b JM |
7875 | case CIPHER_SMS4: |
7876 | cipher = WLAN_CIPHER_SUITE_SMS4; | |
7877 | break; | |
cfaab580 ZY |
7878 | case CIPHER_WEP40: |
7879 | cipher = WLAN_CIPHER_SUITE_WEP40; | |
7880 | break; | |
7881 | case CIPHER_WEP104: | |
7882 | cipher = WLAN_CIPHER_SUITE_WEP104; | |
7883 | break; | |
7884 | case CIPHER_CCMP: | |
7885 | cipher = WLAN_CIPHER_SUITE_CCMP; | |
7886 | break; | |
eb7719ff JM |
7887 | case CIPHER_GCMP: |
7888 | cipher = WLAN_CIPHER_SUITE_GCMP; | |
7889 | break; | |
cfaab580 ZY |
7890 | case CIPHER_TKIP: |
7891 | default: | |
7892 | cipher = WLAN_CIPHER_SUITE_TKIP; | |
7893 | break; | |
7894 | } | |
7895 | NLA_PUT_U32(msg, NL80211_ATTR_CIPHER_SUITE_GROUP, cipher); | |
7896 | } | |
7897 | ||
7898 | if (params->key_mgmt_suite == KEY_MGMT_802_1X || | |
369c8d7b | 7899 | params->key_mgmt_suite == KEY_MGMT_PSK || |
6a1ce395 DG |
7900 | params->key_mgmt_suite == KEY_MGMT_FT_802_1X || |
7901 | params->key_mgmt_suite == KEY_MGMT_FT_PSK || | |
369c8d7b | 7902 | params->key_mgmt_suite == KEY_MGMT_CCKM) { |
cfaab580 ZY |
7903 | int mgmt = WLAN_AKM_SUITE_PSK; |
7904 | ||
7905 | switch (params->key_mgmt_suite) { | |
369c8d7b JM |
7906 | case KEY_MGMT_CCKM: |
7907 | mgmt = WLAN_AKM_SUITE_CCKM; | |
7908 | break; | |
cfaab580 ZY |
7909 | case KEY_MGMT_802_1X: |
7910 | mgmt = WLAN_AKM_SUITE_8021X; | |
7911 | break; | |
6a1ce395 DG |
7912 | case KEY_MGMT_FT_802_1X: |
7913 | mgmt = WLAN_AKM_SUITE_FT_8021X; | |
7914 | break; | |
7915 | case KEY_MGMT_FT_PSK: | |
7916 | mgmt = WLAN_AKM_SUITE_FT_PSK; | |
7917 | break; | |
cfaab580 ZY |
7918 | case KEY_MGMT_PSK: |
7919 | default: | |
7920 | mgmt = WLAN_AKM_SUITE_PSK; | |
7921 | break; | |
7922 | } | |
7923 | NLA_PUT_U32(msg, NL80211_ATTR_AKM_SUITES, mgmt); | |
7924 | } | |
7925 | ||
8b706a99 JM |
7926 | #ifdef CONFIG_IEEE80211W |
7927 | if (params->mgmt_frame_protection == MGMT_FRAME_PROTECTION_REQUIRED) | |
7928 | NLA_PUT_U32(msg, NL80211_ATTR_USE_MFP, NL80211_MFP_REQUIRED); | |
7929 | #endif /* CONFIG_IEEE80211W */ | |
7930 | ||
80e8a5ee BG |
7931 | if (params->disable_ht) |
7932 | NLA_PUT_FLAG(msg, NL80211_ATTR_DISABLE_HT); | |
7933 | ||
7934 | if (params->htcaps && params->htcaps_mask) { | |
7935 | int sz = sizeof(struct ieee80211_ht_capabilities); | |
7936 | NLA_PUT(msg, NL80211_ATTR_HT_CAPABILITY, sz, params->htcaps); | |
7937 | NLA_PUT(msg, NL80211_ATTR_HT_CAPABILITY_MASK, sz, | |
7938 | params->htcaps_mask); | |
7939 | } | |
7940 | ||
e9ee8dc3 JB |
7941 | #ifdef CONFIG_VHT_OVERRIDES |
7942 | if (params->disable_vht) { | |
7943 | wpa_printf(MSG_DEBUG, " * VHT disabled"); | |
7944 | NLA_PUT_FLAG(msg, NL80211_ATTR_DISABLE_VHT); | |
7945 | } | |
7946 | ||
7947 | if (params->vhtcaps && params->vhtcaps_mask) { | |
7948 | int sz = sizeof(struct ieee80211_vht_capabilities); | |
7949 | NLA_PUT(msg, NL80211_ATTR_VHT_CAPABILITY, sz, params->vhtcaps); | |
7950 | NLA_PUT(msg, NL80211_ATTR_VHT_CAPABILITY_MASK, sz, | |
7951 | params->vhtcaps_mask); | |
7952 | } | |
7953 | #endif /* CONFIG_VHT_OVERRIDES */ | |
7954 | ||
cfaab580 ZY |
7955 | ret = nl80211_set_conn_keys(params, msg); |
7956 | if (ret) | |
7957 | goto nla_put_failure; | |
7958 | ||
7959 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); | |
7960 | msg = NULL; | |
7961 | if (ret) { | |
7962 | wpa_printf(MSG_DEBUG, "nl80211: MLME connect failed: ret=%d " | |
7963 | "(%s)", ret, strerror(-ret)); | |
7964 | goto nla_put_failure; | |
7965 | } | |
7966 | ret = 0; | |
7967 | wpa_printf(MSG_DEBUG, "nl80211: Connect request send successfully"); | |
7968 | ||
7969 | nla_put_failure: | |
7970 | nlmsg_free(msg); | |
7971 | return ret; | |
7972 | ||
7973 | } | |
7974 | ||
7975 | ||
a8c5b43a CW |
7976 | static int wpa_driver_nl80211_connect( |
7977 | struct wpa_driver_nl80211_data *drv, | |
7978 | struct wpa_driver_associate_params *params) | |
7979 | { | |
7980 | int ret = wpa_driver_nl80211_try_connect(drv, params); | |
7981 | if (ret == -EALREADY) { | |
7982 | /* | |
7983 | * cfg80211 does not currently accept new connections if | |
7984 | * we are already connected. As a workaround, force | |
7985 | * disconnection and try again. | |
7986 | */ | |
7987 | wpa_printf(MSG_DEBUG, "nl80211: Explicitly " | |
7988 | "disconnecting before reassociation " | |
7989 | "attempt"); | |
7990 | if (wpa_driver_nl80211_disconnect( | |
7991 | drv, WLAN_REASON_PREV_AUTH_NOT_VALID)) | |
7992 | return -1; | |
a8c5b43a CW |
7993 | ret = wpa_driver_nl80211_try_connect(drv, params); |
7994 | } | |
7995 | return ret; | |
7996 | } | |
7997 | ||
7998 | ||
c2a04078 JM |
7999 | static int wpa_driver_nl80211_associate( |
8000 | void *priv, struct wpa_driver_associate_params *params) | |
8001 | { | |
a2e40bb6 FF |
8002 | struct i802_bss *bss = priv; |
8003 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
c2a04078 JM |
8004 | int ret = -1; |
8005 | struct nl_msg *msg; | |
8006 | ||
5cc4d64b | 8007 | if (params->mode == IEEE80211_MODE_AP) |
1581b38b | 8008 | return wpa_driver_nl80211_ap(drv, params); |
1581b38b | 8009 | |
5cc4d64b JM |
8010 | if (params->mode == IEEE80211_MODE_IBSS) |
8011 | return wpa_driver_nl80211_ibss(drv, params); | |
8012 | ||
4a867032 | 8013 | if (!(drv->capa.flags & WPA_DRIVER_FLAGS_SME)) { |
b1f625e0 EP |
8014 | enum nl80211_iftype nlmode = params->p2p ? |
8015 | NL80211_IFTYPE_P2P_CLIENT : NL80211_IFTYPE_STATION; | |
8016 | ||
8017 | if (wpa_driver_nl80211_set_mode(priv, nlmode) < 0) | |
4a867032 | 8018 | return -1; |
cfaab580 | 8019 | return wpa_driver_nl80211_connect(drv, params); |
4a867032 | 8020 | } |
cfaab580 | 8021 | |
add9b7a4 | 8022 | nl80211_mark_disconnected(drv); |
c2a04078 JM |
8023 | |
8024 | msg = nlmsg_alloc(); | |
8025 | if (!msg) | |
8026 | return -1; | |
8027 | ||
8028 | wpa_printf(MSG_DEBUG, "nl80211: Associate (ifindex=%d)", | |
8029 | drv->ifindex); | |
9fb04070 | 8030 | nl80211_cmd(drv, msg, 0, NL80211_CMD_ASSOCIATE); |
c2a04078 JM |
8031 | |
8032 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, drv->ifindex); | |
8033 | if (params->bssid) { | |
8034 | wpa_printf(MSG_DEBUG, " * bssid=" MACSTR, | |
8035 | MAC2STR(params->bssid)); | |
8036 | NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, params->bssid); | |
8037 | } | |
8038 | if (params->freq) { | |
8039 | wpa_printf(MSG_DEBUG, " * freq=%d", params->freq); | |
8040 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_FREQ, params->freq); | |
4832ecd7 JM |
8041 | drv->assoc_freq = params->freq; |
8042 | } else | |
8043 | drv->assoc_freq = 0; | |
1f6c0ab8 BS |
8044 | if (params->bg_scan_period >= 0) { |
8045 | wpa_printf(MSG_DEBUG, " * bg scan period=%d", | |
8046 | params->bg_scan_period); | |
8047 | NLA_PUT_U16(msg, NL80211_ATTR_BG_SCAN_PERIOD, | |
8048 | params->bg_scan_period); | |
8049 | } | |
c2a04078 JM |
8050 | if (params->ssid) { |
8051 | wpa_hexdump_ascii(MSG_DEBUG, " * SSID", | |
8052 | params->ssid, params->ssid_len); | |
8053 | NLA_PUT(msg, NL80211_ATTR_SSID, params->ssid_len, | |
8054 | params->ssid); | |
fd05d64e JM |
8055 | if (params->ssid_len > sizeof(drv->ssid)) |
8056 | goto nla_put_failure; | |
8057 | os_memcpy(drv->ssid, params->ssid, params->ssid_len); | |
8058 | drv->ssid_len = params->ssid_len; | |
c2a04078 JM |
8059 | } |
8060 | wpa_hexdump(MSG_DEBUG, " * IEs", params->wpa_ie, params->wpa_ie_len); | |
8061 | if (params->wpa_ie) | |
8062 | NLA_PUT(msg, NL80211_ATTR_IE, params->wpa_ie_len, | |
8063 | params->wpa_ie); | |
8064 | ||
aca01605 JM |
8065 | if (params->pairwise_suite != CIPHER_NONE) { |
8066 | int cipher; | |
8067 | ||
8068 | switch (params->pairwise_suite) { | |
8069 | case CIPHER_WEP40: | |
8070 | cipher = WLAN_CIPHER_SUITE_WEP40; | |
8071 | break; | |
8072 | case CIPHER_WEP104: | |
8073 | cipher = WLAN_CIPHER_SUITE_WEP104; | |
8074 | break; | |
8075 | case CIPHER_CCMP: | |
8076 | cipher = WLAN_CIPHER_SUITE_CCMP; | |
8077 | break; | |
eb7719ff JM |
8078 | case CIPHER_GCMP: |
8079 | cipher = WLAN_CIPHER_SUITE_GCMP; | |
8080 | break; | |
aca01605 JM |
8081 | case CIPHER_TKIP: |
8082 | default: | |
8083 | cipher = WLAN_CIPHER_SUITE_TKIP; | |
8084 | break; | |
8085 | } | |
79c3124c | 8086 | wpa_printf(MSG_DEBUG, " * pairwise=0x%x", cipher); |
aca01605 JM |
8087 | NLA_PUT_U32(msg, NL80211_ATTR_CIPHER_SUITES_PAIRWISE, cipher); |
8088 | } | |
8089 | ||
8090 | if (params->group_suite != CIPHER_NONE) { | |
8091 | int cipher; | |
8092 | ||
8093 | switch (params->group_suite) { | |
8094 | case CIPHER_WEP40: | |
8095 | cipher = WLAN_CIPHER_SUITE_WEP40; | |
8096 | break; | |
8097 | case CIPHER_WEP104: | |
8098 | cipher = WLAN_CIPHER_SUITE_WEP104; | |
8099 | break; | |
8100 | case CIPHER_CCMP: | |
8101 | cipher = WLAN_CIPHER_SUITE_CCMP; | |
8102 | break; | |
eb7719ff JM |
8103 | case CIPHER_GCMP: |
8104 | cipher = WLAN_CIPHER_SUITE_GCMP; | |
8105 | break; | |
aca01605 JM |
8106 | case CIPHER_TKIP: |
8107 | default: | |
8108 | cipher = WLAN_CIPHER_SUITE_TKIP; | |
8109 | break; | |
8110 | } | |
79c3124c | 8111 | wpa_printf(MSG_DEBUG, " * group=0x%x", cipher); |
aca01605 JM |
8112 | NLA_PUT_U32(msg, NL80211_ATTR_CIPHER_SUITE_GROUP, cipher); |
8113 | } | |
8114 | ||
e572fa33 JM |
8115 | #ifdef CONFIG_IEEE80211W |
8116 | if (params->mgmt_frame_protection == MGMT_FRAME_PROTECTION_REQUIRED) | |
8117 | NLA_PUT_U32(msg, NL80211_ATTR_USE_MFP, NL80211_MFP_REQUIRED); | |
8118 | #endif /* CONFIG_IEEE80211W */ | |
8119 | ||
01652550 JM |
8120 | NLA_PUT_FLAG(msg, NL80211_ATTR_CONTROL_PORT); |
8121 | ||
62fa124c JM |
8122 | if (params->prev_bssid) { |
8123 | wpa_printf(MSG_DEBUG, " * prev_bssid=" MACSTR, | |
8124 | MAC2STR(params->prev_bssid)); | |
8125 | NLA_PUT(msg, NL80211_ATTR_PREV_BSSID, ETH_ALEN, | |
8126 | params->prev_bssid); | |
8127 | } | |
8128 | ||
80e8a5ee BG |
8129 | if (params->disable_ht) |
8130 | NLA_PUT_FLAG(msg, NL80211_ATTR_DISABLE_HT); | |
8131 | ||
8132 | if (params->htcaps && params->htcaps_mask) { | |
8133 | int sz = sizeof(struct ieee80211_ht_capabilities); | |
8134 | NLA_PUT(msg, NL80211_ATTR_HT_CAPABILITY, sz, params->htcaps); | |
8135 | NLA_PUT(msg, NL80211_ATTR_HT_CAPABILITY_MASK, sz, | |
8136 | params->htcaps_mask); | |
8137 | } | |
8138 | ||
e9ee8dc3 JB |
8139 | #ifdef CONFIG_VHT_OVERRIDES |
8140 | if (params->disable_vht) { | |
8141 | wpa_printf(MSG_DEBUG, " * VHT disabled"); | |
8142 | NLA_PUT_FLAG(msg, NL80211_ATTR_DISABLE_VHT); | |
8143 | } | |
8144 | ||
8145 | if (params->vhtcaps && params->vhtcaps_mask) { | |
8146 | int sz = sizeof(struct ieee80211_vht_capabilities); | |
8147 | NLA_PUT(msg, NL80211_ATTR_VHT_CAPABILITY, sz, params->vhtcaps); | |
8148 | NLA_PUT(msg, NL80211_ATTR_VHT_CAPABILITY_MASK, sz, | |
8149 | params->vhtcaps_mask); | |
8150 | } | |
8151 | #endif /* CONFIG_VHT_OVERRIDES */ | |
8152 | ||
046b26a2 JM |
8153 | if (params->p2p) |
8154 | wpa_printf(MSG_DEBUG, " * P2P group"); | |
8155 | ||
c2a04078 JM |
8156 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
8157 | msg = NULL; | |
8158 | if (ret) { | |
3b7ea880 BG |
8159 | wpa_dbg(drv->ctx, MSG_DEBUG, |
8160 | "nl80211: MLME command failed (assoc): ret=%d (%s)", | |
8161 | ret, strerror(-ret)); | |
8856462d | 8162 | nl80211_dump_scan(drv); |
c2a04078 JM |
8163 | goto nla_put_failure; |
8164 | } | |
8165 | ret = 0; | |
8166 | wpa_printf(MSG_DEBUG, "nl80211: Association request send " | |
8167 | "successfully"); | |
8168 | ||
8169 | nla_put_failure: | |
8170 | nlmsg_free(msg); | |
8171 | return ret; | |
8172 | } | |
3f5285e8 JM |
8173 | |
8174 | ||
ad1e68e6 | 8175 | static int nl80211_set_mode(struct wpa_driver_nl80211_data *drv, |
a1922f93 | 8176 | int ifindex, enum nl80211_iftype mode) |
3f5285e8 | 8177 | { |
3f5285e8 | 8178 | struct nl_msg *msg; |
ad1e68e6 JM |
8179 | int ret = -ENOBUFS; |
8180 | ||
a1922f93 JM |
8181 | wpa_printf(MSG_DEBUG, "nl80211: Set mode ifindex %d iftype %d (%s)", |
8182 | ifindex, mode, nl80211_iftype_str(mode)); | |
8183 | ||
ad1e68e6 JM |
8184 | msg = nlmsg_alloc(); |
8185 | if (!msg) | |
8186 | return -ENOMEM; | |
8187 | ||
9fb04070 | 8188 | nl80211_cmd(drv, msg, 0, NL80211_CMD_SET_INTERFACE); |
f632e483 AS |
8189 | if (nl80211_set_iface_id(msg, &drv->first_bss) < 0) |
8190 | goto nla_put_failure; | |
ad1e68e6 JM |
8191 | NLA_PUT_U32(msg, NL80211_ATTR_IFTYPE, mode); |
8192 | ||
8193 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); | |
5883168a | 8194 | msg = NULL; |
ad1e68e6 JM |
8195 | if (!ret) |
8196 | return 0; | |
8197 | nla_put_failure: | |
5883168a | 8198 | nlmsg_free(msg); |
ad1e68e6 JM |
8199 | wpa_printf(MSG_DEBUG, "nl80211: Failed to set interface %d to mode %d:" |
8200 | " %d (%s)", ifindex, mode, ret, strerror(-ret)); | |
8201 | return ret; | |
8202 | } | |
8203 | ||
8204 | ||
b1f625e0 EP |
8205 | static int wpa_driver_nl80211_set_mode(struct i802_bss *bss, |
8206 | enum nl80211_iftype nlmode) | |
ad1e68e6 | 8207 | { |
a2e40bb6 | 8208 | struct wpa_driver_nl80211_data *drv = bss->drv; |
ad1e68e6 | 8209 | int ret = -1; |
26af9dca | 8210 | int i; |
86957e62 | 8211 | int was_ap = is_ap_interface(drv->nlmode); |
671a5039 | 8212 | int res; |
1581b38b | 8213 | |
671a5039 | 8214 | res = nl80211_set_mode(drv, drv->ifindex, nlmode); |
8e12685c AS |
8215 | if (res && nlmode == nl80211_get_ifmode(bss)) |
8216 | res = 0; | |
8217 | ||
671a5039 | 8218 | if (res == 0) { |
ad1e68e6 | 8219 | drv->nlmode = nlmode; |
460456f8 JM |
8220 | ret = 0; |
8221 | goto done; | |
ad1e68e6 | 8222 | } |
3f5285e8 | 8223 | |
671a5039 JM |
8224 | if (res == -ENODEV) |
8225 | return -1; | |
8226 | ||
460456f8 | 8227 | if (nlmode == drv->nlmode) { |
c6e8e8e4 JM |
8228 | wpa_printf(MSG_DEBUG, "nl80211: Interface already in " |
8229 | "requested mode - ignore error"); | |
460456f8 JM |
8230 | ret = 0; |
8231 | goto done; /* Already in the requested mode */ | |
8232 | } | |
3f5285e8 | 8233 | |
3f5285e8 JM |
8234 | /* mac80211 doesn't allow mode changes while the device is up, so |
8235 | * take the device down, try to set the mode again, and bring the | |
8236 | * device back up. | |
8237 | */ | |
26af9dca JM |
8238 | wpa_printf(MSG_DEBUG, "nl80211: Try mode change after setting " |
8239 | "interface down"); | |
8240 | for (i = 0; i < 10; i++) { | |
91724d6f | 8241 | res = i802_set_iface_flags(bss, 0); |
6e8183d7 JM |
8242 | if (res == -EACCES || res == -ENODEV) |
8243 | break; | |
8244 | if (res == 0) { | |
26af9dca JM |
8245 | /* Try to set the mode again while the interface is |
8246 | * down */ | |
8247 | ret = nl80211_set_mode(drv, drv->ifindex, nlmode); | |
6e8183d7 JM |
8248 | if (ret == -EACCES) |
8249 | break; | |
91724d6f | 8250 | res = i802_set_iface_flags(bss, 1); |
6e8183d7 | 8251 | if (res && !ret) |
26af9dca | 8252 | ret = -1; |
6e8183d7 | 8253 | else if (ret != -EBUSY) |
26af9dca JM |
8254 | break; |
8255 | } else | |
8256 | wpa_printf(MSG_DEBUG, "nl80211: Failed to set " | |
8257 | "interface down"); | |
8258 | os_sleep(0, 100000); | |
3f5285e8 JM |
8259 | } |
8260 | ||
c6e8e8e4 JM |
8261 | if (!ret) { |
8262 | wpa_printf(MSG_DEBUG, "nl80211: Mode change succeeded while " | |
8263 | "interface is down"); | |
ad1e68e6 | 8264 | drv->nlmode = nlmode; |
7d9c3698 | 8265 | drv->ignore_if_down_event = 1; |
c6e8e8e4 | 8266 | } |
ad1e68e6 | 8267 | |
460456f8 | 8268 | done: |
3fd1cefb JB |
8269 | if (ret) { |
8270 | wpa_printf(MSG_DEBUG, "nl80211: Interface mode change to %d " | |
8271 | "from %d failed", nlmode, drv->nlmode); | |
8272 | return ret; | |
8273 | } | |
8274 | ||
6a71413e | 8275 | if (is_p2p_net_interface(nlmode)) |
edb9bfba | 8276 | nl80211_disable_11b_rates(drv, drv->ifindex, 1); |
1d0c6fb1 JM |
8277 | else if (drv->disabled_11b_rates) |
8278 | nl80211_disable_11b_rates(drv, drv->ifindex, 0); | |
edb9bfba | 8279 | |
3fd1cefb | 8280 | if (is_ap_interface(nlmode)) { |
36488c05 | 8281 | nl80211_mgmt_unsubscribe(bss, "start AP"); |
460456f8 | 8282 | /* Setup additional AP mode functionality if needed */ |
3fd1cefb | 8283 | if (nl80211_setup_ap(bss)) |
460456f8 | 8284 | return -1; |
3fd1cefb | 8285 | } else if (was_ap) { |
460456f8 | 8286 | /* Remove additional AP mode functionality */ |
3fd1cefb | 8287 | nl80211_teardown_ap(bss); |
a11241fa | 8288 | } else { |
36488c05 | 8289 | nl80211_mgmt_unsubscribe(bss, "mode change"); |
460456f8 | 8290 | } |
460456f8 | 8291 | |
873d0fcf | 8292 | if (!bss->in_deinit && !is_ap_interface(nlmode) && |
a11241fa JB |
8293 | nl80211_mgmt_subscribe_non_ap(bss) < 0) |
8294 | wpa_printf(MSG_DEBUG, "nl80211: Failed to register Action " | |
8295 | "frame processing - ignore for now"); | |
08359050 | 8296 | |
3fd1cefb | 8297 | return 0; |
3f5285e8 JM |
8298 | } |
8299 | ||
8300 | ||
3f5285e8 JM |
8301 | static int wpa_driver_nl80211_get_capa(void *priv, |
8302 | struct wpa_driver_capa *capa) | |
8303 | { | |
a2e40bb6 FF |
8304 | struct i802_bss *bss = priv; |
8305 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
3f5285e8 JM |
8306 | if (!drv->has_capability) |
8307 | return -1; | |
8308 | os_memcpy(capa, &drv->capa, sizeof(*capa)); | |
8cd6b7bc JB |
8309 | if (drv->extended_capa && drv->extended_capa_mask) { |
8310 | capa->extended_capa = drv->extended_capa; | |
8311 | capa->extended_capa_mask = drv->extended_capa_mask; | |
8312 | capa->extended_capa_len = drv->extended_capa_len; | |
8313 | } | |
851b0c55 JM |
8314 | |
8315 | if ((capa->flags & WPA_DRIVER_FLAGS_DEDICATED_P2P_DEVICE) && | |
8316 | !drv->allow_p2p_device) { | |
8317 | wpa_printf(MSG_DEBUG, "nl80211: Do not indicate P2P_DEVICE support (p2p_device=1 driver param not specified)"); | |
8318 | capa->flags &= ~WPA_DRIVER_FLAGS_DEDICATED_P2P_DEVICE; | |
8319 | } | |
8320 | ||
3f5285e8 JM |
8321 | return 0; |
8322 | } | |
8323 | ||
8324 | ||
8325 | static int wpa_driver_nl80211_set_operstate(void *priv, int state) | |
8326 | { | |
a2e40bb6 FF |
8327 | struct i802_bss *bss = priv; |
8328 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
3f5285e8 JM |
8329 | |
8330 | wpa_printf(MSG_DEBUG, "%s: operstate %d->%d (%s)", | |
8331 | __func__, drv->operstate, state, state ? "UP" : "DORMANT"); | |
8332 | drv->operstate = state; | |
36d84860 | 8333 | return netlink_send_oper_ifla(drv->global->netlink, drv->ifindex, -1, |
e2d02c29 | 8334 | state ? IF_OPER_UP : IF_OPER_DORMANT); |
3f5285e8 JM |
8335 | } |
8336 | ||
01652550 JM |
8337 | |
8338 | static int wpa_driver_nl80211_set_supp_port(void *priv, int authorized) | |
8339 | { | |
a2e40bb6 FF |
8340 | struct i802_bss *bss = priv; |
8341 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
01652550 JM |
8342 | struct nl_msg *msg; |
8343 | struct nl80211_sta_flag_update upd; | |
8344 | ||
1ba51ec0 JM |
8345 | wpa_printf(MSG_DEBUG, "nl80211: Set supplicant port %sauthorized for " |
8346 | MACSTR, authorized ? "" : "un", MAC2STR(drv->bssid)); | |
8347 | ||
01652550 JM |
8348 | msg = nlmsg_alloc(); |
8349 | if (!msg) | |
8350 | return -ENOMEM; | |
8351 | ||
9fb04070 | 8352 | nl80211_cmd(drv, msg, 0, NL80211_CMD_SET_STATION); |
01652550 JM |
8353 | |
8354 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, | |
a2e40bb6 | 8355 | if_nametoindex(bss->ifname)); |
01652550 JM |
8356 | NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, drv->bssid); |
8357 | ||
8358 | os_memset(&upd, 0, sizeof(upd)); | |
8359 | upd.mask = BIT(NL80211_STA_FLAG_AUTHORIZED); | |
8360 | if (authorized) | |
8361 | upd.set = BIT(NL80211_STA_FLAG_AUTHORIZED); | |
8362 | NLA_PUT(msg, NL80211_ATTR_STA_FLAGS2, sizeof(upd), &upd); | |
8363 | ||
8364 | return send_and_recv_msgs(drv, msg, NULL, NULL); | |
8365 | nla_put_failure: | |
5883168a | 8366 | nlmsg_free(msg); |
01652550 JM |
8367 | return -ENOBUFS; |
8368 | } | |
8369 | ||
3f5285e8 | 8370 | |
f07ead6a JM |
8371 | /* Set kernel driver on given frequency (MHz) */ |
8372 | static int i802_set_freq(void *priv, struct hostapd_freq_params *freq) | |
c5121837 | 8373 | { |
f07ead6a | 8374 | struct i802_bss *bss = priv; |
89b800d7 | 8375 | return wpa_driver_nl80211_set_freq(bss, freq); |
c5121837 JM |
8376 | } |
8377 | ||
f7b3920c JM |
8378 | |
8379 | #if defined(HOSTAPD) || defined(CONFIG_AP) | |
c5121837 | 8380 | |
c5121837 JM |
8381 | static inline int min_int(int a, int b) |
8382 | { | |
8383 | if (a < b) | |
8384 | return a; | |
8385 | return b; | |
8386 | } | |
8387 | ||
8388 | ||
8389 | static int get_key_handler(struct nl_msg *msg, void *arg) | |
8390 | { | |
8391 | struct nlattr *tb[NL80211_ATTR_MAX + 1]; | |
8392 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); | |
8393 | ||
8394 | nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), | |
8395 | genlmsg_attrlen(gnlh, 0), NULL); | |
8396 | ||
8397 | /* | |
8398 | * TODO: validate the key index and mac address! | |
8399 | * Otherwise, there's a race condition as soon as | |
8400 | * the kernel starts sending key notifications. | |
8401 | */ | |
8402 | ||
8403 | if (tb[NL80211_ATTR_KEY_SEQ]) | |
8404 | memcpy(arg, nla_data(tb[NL80211_ATTR_KEY_SEQ]), | |
8405 | min_int(nla_len(tb[NL80211_ATTR_KEY_SEQ]), 6)); | |
8406 | return NL_SKIP; | |
8407 | } | |
8408 | ||
8409 | ||
8410 | static int i802_get_seqnum(const char *iface, void *priv, const u8 *addr, | |
8411 | int idx, u8 *seq) | |
8412 | { | |
a2e40bb6 FF |
8413 | struct i802_bss *bss = priv; |
8414 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
c5121837 JM |
8415 | struct nl_msg *msg; |
8416 | ||
8417 | msg = nlmsg_alloc(); | |
8418 | if (!msg) | |
8419 | return -ENOMEM; | |
8420 | ||
9fb04070 | 8421 | nl80211_cmd(drv, msg, 0, NL80211_CMD_GET_KEY); |
c5121837 JM |
8422 | |
8423 | if (addr) | |
8424 | NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, addr); | |
8425 | NLA_PUT_U8(msg, NL80211_ATTR_KEY_IDX, idx); | |
8426 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, if_nametoindex(iface)); | |
8427 | ||
8428 | memset(seq, 0, 6); | |
8429 | ||
8430 | return send_and_recv_msgs(drv, msg, get_key_handler, seq); | |
8431 | nla_put_failure: | |
9e088e74 | 8432 | nlmsg_free(msg); |
c5121837 JM |
8433 | return -ENOBUFS; |
8434 | } | |
8435 | ||
8436 | ||
c5121837 JM |
8437 | static int i802_set_rts(void *priv, int rts) |
8438 | { | |
a2e40bb6 FF |
8439 | struct i802_bss *bss = priv; |
8440 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
ad649451 JM |
8441 | struct nl_msg *msg; |
8442 | int ret = -ENOBUFS; | |
8443 | u32 val; | |
c5121837 | 8444 | |
ad649451 JM |
8445 | msg = nlmsg_alloc(); |
8446 | if (!msg) | |
8447 | return -ENOMEM; | |
c5121837 | 8448 | |
ad649451 JM |
8449 | if (rts >= 2347) |
8450 | val = (u32) -1; | |
8451 | else | |
8452 | val = rts; | |
c5121837 | 8453 | |
9fb04070 | 8454 | nl80211_cmd(drv, msg, 0, NL80211_CMD_SET_WIPHY); |
ad649451 JM |
8455 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, drv->ifindex); |
8456 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_RTS_THRESHOLD, val); | |
8457 | ||
8458 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); | |
5883168a | 8459 | msg = NULL; |
ad649451 JM |
8460 | if (!ret) |
8461 | return 0; | |
8462 | nla_put_failure: | |
5883168a | 8463 | nlmsg_free(msg); |
ad649451 JM |
8464 | wpa_printf(MSG_DEBUG, "nl80211: Failed to set RTS threshold %d: " |
8465 | "%d (%s)", rts, ret, strerror(-ret)); | |
8466 | return ret; | |
c5121837 JM |
8467 | } |
8468 | ||
8469 | ||
8470 | static int i802_set_frag(void *priv, int frag) | |
8471 | { | |
a2e40bb6 FF |
8472 | struct i802_bss *bss = priv; |
8473 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
ad649451 JM |
8474 | struct nl_msg *msg; |
8475 | int ret = -ENOBUFS; | |
8476 | u32 val; | |
c5121837 | 8477 | |
ad649451 JM |
8478 | msg = nlmsg_alloc(); |
8479 | if (!msg) | |
8480 | return -ENOMEM; | |
c5121837 | 8481 | |
ad649451 JM |
8482 | if (frag >= 2346) |
8483 | val = (u32) -1; | |
8484 | else | |
8485 | val = frag; | |
c5121837 | 8486 | |
9fb04070 | 8487 | nl80211_cmd(drv, msg, 0, NL80211_CMD_SET_WIPHY); |
ad649451 JM |
8488 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, drv->ifindex); |
8489 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_FRAG_THRESHOLD, val); | |
8490 | ||
8491 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); | |
5883168a | 8492 | msg = NULL; |
ad649451 JM |
8493 | if (!ret) |
8494 | return 0; | |
8495 | nla_put_failure: | |
5883168a | 8496 | nlmsg_free(msg); |
ad649451 JM |
8497 | wpa_printf(MSG_DEBUG, "nl80211: Failed to set fragmentation threshold " |
8498 | "%d: %d (%s)", frag, ret, strerror(-ret)); | |
8499 | return ret; | |
c5121837 JM |
8500 | } |
8501 | ||
8502 | ||
c5121837 JM |
8503 | static int i802_flush(void *priv) |
8504 | { | |
a2e40bb6 FF |
8505 | struct i802_bss *bss = priv; |
8506 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
c5121837 | 8507 | struct nl_msg *msg; |
82554b10 | 8508 | int res; |
c5121837 JM |
8509 | |
8510 | msg = nlmsg_alloc(); | |
8511 | if (!msg) | |
8512 | return -1; | |
8513 | ||
83e7bb0e JM |
8514 | wpa_printf(MSG_DEBUG, "nl80211: flush -> DEL_STATION %s (all)", |
8515 | bss->ifname); | |
9fb04070 | 8516 | nl80211_cmd(drv, msg, 0, NL80211_CMD_DEL_STATION); |
c5121837 JM |
8517 | |
8518 | /* | |
8519 | * XXX: FIX! this needs to flush all VLANs too | |
8520 | */ | |
8521 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, | |
a2e40bb6 | 8522 | if_nametoindex(bss->ifname)); |
c5121837 | 8523 | |
82554b10 JM |
8524 | res = send_and_recv_msgs(drv, msg, NULL, NULL); |
8525 | if (res) { | |
8526 | wpa_printf(MSG_DEBUG, "nl80211: Station flush failed: ret=%d " | |
8527 | "(%s)", res, strerror(-res)); | |
8528 | } | |
8529 | return res; | |
c5121837 | 8530 | nla_put_failure: |
9e088e74 | 8531 | nlmsg_free(msg); |
c5121837 JM |
8532 | return -ENOBUFS; |
8533 | } | |
8534 | ||
d732463c JM |
8535 | #endif /* HOSTAPD || CONFIG_AP */ |
8536 | ||
c5121837 JM |
8537 | |
8538 | static int get_sta_handler(struct nl_msg *msg, void *arg) | |
8539 | { | |
8540 | struct nlattr *tb[NL80211_ATTR_MAX + 1]; | |
8541 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); | |
8542 | struct hostap_sta_driver_data *data = arg; | |
8543 | struct nlattr *stats[NL80211_STA_INFO_MAX + 1]; | |
8544 | static struct nla_policy stats_policy[NL80211_STA_INFO_MAX + 1] = { | |
8545 | [NL80211_STA_INFO_INACTIVE_TIME] = { .type = NLA_U32 }, | |
8546 | [NL80211_STA_INFO_RX_BYTES] = { .type = NLA_U32 }, | |
8547 | [NL80211_STA_INFO_TX_BYTES] = { .type = NLA_U32 }, | |
8548 | [NL80211_STA_INFO_RX_PACKETS] = { .type = NLA_U32 }, | |
8549 | [NL80211_STA_INFO_TX_PACKETS] = { .type = NLA_U32 }, | |
dc7785f8 | 8550 | [NL80211_STA_INFO_TX_FAILED] = { .type = NLA_U32 }, |
c5121837 JM |
8551 | }; |
8552 | ||
8553 | nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), | |
8554 | genlmsg_attrlen(gnlh, 0), NULL); | |
8555 | ||
8556 | /* | |
8557 | * TODO: validate the interface and mac address! | |
8558 | * Otherwise, there's a race condition as soon as | |
8559 | * the kernel starts sending station notifications. | |
8560 | */ | |
8561 | ||
8562 | if (!tb[NL80211_ATTR_STA_INFO]) { | |
8563 | wpa_printf(MSG_DEBUG, "sta stats missing!"); | |
8564 | return NL_SKIP; | |
8565 | } | |
8566 | if (nla_parse_nested(stats, NL80211_STA_INFO_MAX, | |
8567 | tb[NL80211_ATTR_STA_INFO], | |
8568 | stats_policy)) { | |
8569 | wpa_printf(MSG_DEBUG, "failed to parse nested attributes!"); | |
8570 | return NL_SKIP; | |
8571 | } | |
8572 | ||
8573 | if (stats[NL80211_STA_INFO_INACTIVE_TIME]) | |
8574 | data->inactive_msec = | |
8575 | nla_get_u32(stats[NL80211_STA_INFO_INACTIVE_TIME]); | |
8576 | if (stats[NL80211_STA_INFO_RX_BYTES]) | |
8577 | data->rx_bytes = nla_get_u32(stats[NL80211_STA_INFO_RX_BYTES]); | |
8578 | if (stats[NL80211_STA_INFO_TX_BYTES]) | |
8579 | data->tx_bytes = nla_get_u32(stats[NL80211_STA_INFO_TX_BYTES]); | |
8580 | if (stats[NL80211_STA_INFO_RX_PACKETS]) | |
8581 | data->rx_packets = | |
8582 | nla_get_u32(stats[NL80211_STA_INFO_RX_PACKETS]); | |
8583 | if (stats[NL80211_STA_INFO_TX_PACKETS]) | |
8584 | data->tx_packets = | |
8585 | nla_get_u32(stats[NL80211_STA_INFO_TX_PACKETS]); | |
dc7785f8 YZ |
8586 | if (stats[NL80211_STA_INFO_TX_FAILED]) |
8587 | data->tx_retry_failed = | |
8588 | nla_get_u32(stats[NL80211_STA_INFO_TX_FAILED]); | |
c5121837 JM |
8589 | |
8590 | return NL_SKIP; | |
8591 | } | |
8592 | ||
9ebce9c5 JM |
8593 | static int i802_read_sta_data(struct i802_bss *bss, |
8594 | struct hostap_sta_driver_data *data, | |
c5121837 JM |
8595 | const u8 *addr) |
8596 | { | |
a2e40bb6 | 8597 | struct wpa_driver_nl80211_data *drv = bss->drv; |
c5121837 JM |
8598 | struct nl_msg *msg; |
8599 | ||
8600 | os_memset(data, 0, sizeof(*data)); | |
8601 | msg = nlmsg_alloc(); | |
8602 | if (!msg) | |
8603 | return -ENOMEM; | |
8604 | ||
9fb04070 | 8605 | nl80211_cmd(drv, msg, 0, NL80211_CMD_GET_STATION); |
c5121837 JM |
8606 | |
8607 | NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, addr); | |
a2e40bb6 | 8608 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, if_nametoindex(bss->ifname)); |
c5121837 JM |
8609 | |
8610 | return send_and_recv_msgs(drv, msg, get_sta_handler, data); | |
8611 | nla_put_failure: | |
9e088e74 | 8612 | nlmsg_free(msg); |
c5121837 JM |
8613 | return -ENOBUFS; |
8614 | } | |
8615 | ||
8616 | ||
d732463c JM |
8617 | #if defined(HOSTAPD) || defined(CONFIG_AP) |
8618 | ||
c5121837 JM |
8619 | static int i802_set_tx_queue_params(void *priv, int queue, int aifs, |
8620 | int cw_min, int cw_max, int burst_time) | |
8621 | { | |
a2e40bb6 FF |
8622 | struct i802_bss *bss = priv; |
8623 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
c5121837 JM |
8624 | struct nl_msg *msg; |
8625 | struct nlattr *txq, *params; | |
8626 | ||
8627 | msg = nlmsg_alloc(); | |
8628 | if (!msg) | |
8629 | return -1; | |
8630 | ||
9fb04070 | 8631 | nl80211_cmd(drv, msg, 0, NL80211_CMD_SET_WIPHY); |
c5121837 | 8632 | |
a2e40bb6 | 8633 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, if_nametoindex(bss->ifname)); |
c5121837 JM |
8634 | |
8635 | txq = nla_nest_start(msg, NL80211_ATTR_WIPHY_TXQ_PARAMS); | |
8636 | if (!txq) | |
8637 | goto nla_put_failure; | |
8638 | ||
8639 | /* We are only sending parameters for a single TXQ at a time */ | |
8640 | params = nla_nest_start(msg, 1); | |
8641 | if (!params) | |
8642 | goto nla_put_failure; | |
8643 | ||
7e3c1781 JM |
8644 | switch (queue) { |
8645 | case 0: | |
8646 | NLA_PUT_U8(msg, NL80211_TXQ_ATTR_QUEUE, NL80211_TXQ_Q_VO); | |
8647 | break; | |
8648 | case 1: | |
8649 | NLA_PUT_U8(msg, NL80211_TXQ_ATTR_QUEUE, NL80211_TXQ_Q_VI); | |
8650 | break; | |
8651 | case 2: | |
8652 | NLA_PUT_U8(msg, NL80211_TXQ_ATTR_QUEUE, NL80211_TXQ_Q_BE); | |
8653 | break; | |
8654 | case 3: | |
8655 | NLA_PUT_U8(msg, NL80211_TXQ_ATTR_QUEUE, NL80211_TXQ_Q_BK); | |
8656 | break; | |
8657 | } | |
c5121837 JM |
8658 | /* Burst time is configured in units of 0.1 msec and TXOP parameter in |
8659 | * 32 usec, so need to convert the value here. */ | |
8660 | NLA_PUT_U16(msg, NL80211_TXQ_ATTR_TXOP, (burst_time * 100 + 16) / 32); | |
8661 | NLA_PUT_U16(msg, NL80211_TXQ_ATTR_CWMIN, cw_min); | |
8662 | NLA_PUT_U16(msg, NL80211_TXQ_ATTR_CWMAX, cw_max); | |
8663 | NLA_PUT_U8(msg, NL80211_TXQ_ATTR_AIFS, aifs); | |
8664 | ||
8665 | nla_nest_end(msg, params); | |
8666 | ||
8667 | nla_nest_end(msg, txq); | |
8668 | ||
8669 | if (send_and_recv_msgs(drv, msg, NULL, NULL) == 0) | |
8670 | return 0; | |
9e088e74 | 8671 | msg = NULL; |
c5121837 | 8672 | nla_put_failure: |
9e088e74 | 8673 | nlmsg_free(msg); |
c5121837 JM |
8674 | return -1; |
8675 | } | |
8676 | ||
8677 | ||
9ebce9c5 | 8678 | static int i802_set_sta_vlan(struct i802_bss *bss, const u8 *addr, |
c5121837 JM |
8679 | const char *ifname, int vlan_id) |
8680 | { | |
a2e40bb6 | 8681 | struct wpa_driver_nl80211_data *drv = bss->drv; |
c5121837 | 8682 | struct nl_msg *msg; |
cd1d72c1 | 8683 | int ret = -ENOBUFS; |
c5121837 JM |
8684 | |
8685 | msg = nlmsg_alloc(); | |
8686 | if (!msg) | |
8687 | return -ENOMEM; | |
8688 | ||
9fb04070 | 8689 | nl80211_cmd(drv, msg, 0, NL80211_CMD_SET_STATION); |
c5121837 JM |
8690 | |
8691 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, | |
a2e40bb6 | 8692 | if_nametoindex(bss->ifname)); |
c5121837 | 8693 | NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, addr); |
1c766b09 | 8694 | NLA_PUT_U32(msg, NL80211_ATTR_STA_VLAN, |
c5121837 JM |
8695 | if_nametoindex(ifname)); |
8696 | ||
cd1d72c1 | 8697 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
9e088e74 | 8698 | msg = NULL; |
cd1d72c1 JM |
8699 | if (ret < 0) { |
8700 | wpa_printf(MSG_ERROR, "nl80211: NL80211_ATTR_STA_VLAN (addr=" | |
8701 | MACSTR " ifname=%s vlan_id=%d) failed: %d (%s)", | |
8702 | MAC2STR(addr), ifname, vlan_id, ret, | |
8703 | strerror(-ret)); | |
8704 | } | |
c5121837 | 8705 | nla_put_failure: |
9e088e74 | 8706 | nlmsg_free(msg); |
cd1d72c1 | 8707 | return ret; |
c5121837 JM |
8708 | } |
8709 | ||
fbbfcbac | 8710 | |
c5121837 JM |
8711 | static int i802_get_inact_sec(void *priv, const u8 *addr) |
8712 | { | |
8713 | struct hostap_sta_driver_data data; | |
8714 | int ret; | |
8715 | ||
8716 | data.inactive_msec = (unsigned long) -1; | |
8717 | ret = i802_read_sta_data(priv, &data, addr); | |
8718 | if (ret || data.inactive_msec == (unsigned long) -1) | |
8719 | return -1; | |
8720 | return data.inactive_msec / 1000; | |
8721 | } | |
8722 | ||
8723 | ||
8724 | static int i802_sta_clear_stats(void *priv, const u8 *addr) | |
8725 | { | |
8726 | #if 0 | |
8727 | /* TODO */ | |
8728 | #endif | |
8729 | return 0; | |
8730 | } | |
8731 | ||
8732 | ||
731723a5 JM |
8733 | static int i802_sta_deauth(void *priv, const u8 *own_addr, const u8 *addr, |
8734 | int reason) | |
c5121837 | 8735 | { |
a2e40bb6 | 8736 | struct i802_bss *bss = priv; |
e1bd4e19 | 8737 | struct wpa_driver_nl80211_data *drv = bss->drv; |
c5121837 JM |
8738 | struct ieee80211_mgmt mgmt; |
8739 | ||
e1bd4e19 AT |
8740 | if (drv->device_ap_sme) |
8741 | return wpa_driver_nl80211_sta_remove(bss, addr); | |
8742 | ||
c5121837 JM |
8743 | memset(&mgmt, 0, sizeof(mgmt)); |
8744 | mgmt.frame_control = IEEE80211_FC(WLAN_FC_TYPE_MGMT, | |
8745 | WLAN_FC_STYPE_DEAUTH); | |
8746 | memcpy(mgmt.da, addr, ETH_ALEN); | |
731723a5 JM |
8747 | memcpy(mgmt.sa, own_addr, ETH_ALEN); |
8748 | memcpy(mgmt.bssid, own_addr, ETH_ALEN); | |
c5121837 | 8749 | mgmt.u.deauth.reason_code = host_to_le16(reason); |
a2e40bb6 | 8750 | return wpa_driver_nl80211_send_mlme(bss, (u8 *) &mgmt, |
9f324b61 | 8751 | IEEE80211_HDRLEN + |
9ebce9c5 JM |
8752 | sizeof(mgmt.u.deauth), 0, 0, 0, 0, |
8753 | 0); | |
c5121837 JM |
8754 | } |
8755 | ||
8756 | ||
731723a5 JM |
8757 | static int i802_sta_disassoc(void *priv, const u8 *own_addr, const u8 *addr, |
8758 | int reason) | |
c5121837 | 8759 | { |
a2e40bb6 | 8760 | struct i802_bss *bss = priv; |
e1bd4e19 | 8761 | struct wpa_driver_nl80211_data *drv = bss->drv; |
c5121837 JM |
8762 | struct ieee80211_mgmt mgmt; |
8763 | ||
e1bd4e19 AT |
8764 | if (drv->device_ap_sme) |
8765 | return wpa_driver_nl80211_sta_remove(bss, addr); | |
8766 | ||
c5121837 JM |
8767 | memset(&mgmt, 0, sizeof(mgmt)); |
8768 | mgmt.frame_control = IEEE80211_FC(WLAN_FC_TYPE_MGMT, | |
8769 | WLAN_FC_STYPE_DISASSOC); | |
8770 | memcpy(mgmt.da, addr, ETH_ALEN); | |
731723a5 JM |
8771 | memcpy(mgmt.sa, own_addr, ETH_ALEN); |
8772 | memcpy(mgmt.bssid, own_addr, ETH_ALEN); | |
c5121837 | 8773 | mgmt.u.disassoc.reason_code = host_to_le16(reason); |
a2e40bb6 | 8774 | return wpa_driver_nl80211_send_mlme(bss, (u8 *) &mgmt, |
9f324b61 | 8775 | IEEE80211_HDRLEN + |
9ebce9c5 JM |
8776 | sizeof(mgmt.u.disassoc), 0, 0, 0, 0, |
8777 | 0); | |
c5121837 JM |
8778 | } |
8779 | ||
ee7ab173 JB |
8780 | #endif /* HOSTAPD || CONFIG_AP */ |
8781 | ||
8782 | #ifdef HOSTAPD | |
c5121837 | 8783 | |
f07ead6a JM |
8784 | static void add_ifidx(struct wpa_driver_nl80211_data *drv, int ifidx) |
8785 | { | |
8786 | int i; | |
8787 | int *old; | |
8788 | ||
8789 | wpa_printf(MSG_DEBUG, "nl80211: Add own interface ifindex %d", | |
8790 | ifidx); | |
8791 | for (i = 0; i < drv->num_if_indices; i++) { | |
8792 | if (drv->if_indices[i] == 0) { | |
8793 | drv->if_indices[i] = ifidx; | |
8794 | return; | |
8795 | } | |
8796 | } | |
8797 | ||
8798 | if (drv->if_indices != drv->default_if_indices) | |
8799 | old = drv->if_indices; | |
8800 | else | |
8801 | old = NULL; | |
8802 | ||
067ffa26 JM |
8803 | drv->if_indices = os_realloc_array(old, drv->num_if_indices + 1, |
8804 | sizeof(int)); | |
f07ead6a JM |
8805 | if (!drv->if_indices) { |
8806 | if (!old) | |
8807 | drv->if_indices = drv->default_if_indices; | |
8808 | else | |
8809 | drv->if_indices = old; | |
8810 | wpa_printf(MSG_ERROR, "Failed to reallocate memory for " | |
8811 | "interfaces"); | |
8812 | wpa_printf(MSG_ERROR, "Ignoring EAPOL on interface %d", ifidx); | |
8813 | return; | |
8814 | } else if (!old) | |
8815 | os_memcpy(drv->if_indices, drv->default_if_indices, | |
8816 | sizeof(drv->default_if_indices)); | |
8817 | drv->if_indices[drv->num_if_indices] = ifidx; | |
8818 | drv->num_if_indices++; | |
8819 | } | |
8820 | ||
8821 | ||
8822 | static void del_ifidx(struct wpa_driver_nl80211_data *drv, int ifidx) | |
8823 | { | |
8824 | int i; | |
8825 | ||
8826 | for (i = 0; i < drv->num_if_indices; i++) { | |
8827 | if (drv->if_indices[i] == ifidx) { | |
8828 | drv->if_indices[i] = 0; | |
8829 | break; | |
8830 | } | |
8831 | } | |
8832 | } | |
8833 | ||
8834 | ||
8835 | static int have_ifidx(struct wpa_driver_nl80211_data *drv, int ifidx) | |
8836 | { | |
8837 | int i; | |
8838 | ||
8839 | for (i = 0; i < drv->num_if_indices; i++) | |
8840 | if (drv->if_indices[i] == ifidx) | |
8841 | return 1; | |
8842 | ||
8843 | return 0; | |
8844 | } | |
8845 | ||
8846 | ||
8847 | static int i802_set_wds_sta(void *priv, const u8 *addr, int aid, int val, | |
69dd2967 | 8848 | const char *bridge_ifname, char *ifname_wds) |
f07ead6a JM |
8849 | { |
8850 | struct i802_bss *bss = priv; | |
8851 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
8852 | char name[IFNAMSIZ + 1]; | |
8853 | ||
8854 | os_snprintf(name, sizeof(name), "%s.sta%d", bss->ifname, aid); | |
69dd2967 SM |
8855 | if (ifname_wds) |
8856 | os_strlcpy(ifname_wds, name, IFNAMSIZ + 1); | |
8857 | ||
f07ead6a JM |
8858 | wpa_printf(MSG_DEBUG, "nl80211: Set WDS STA addr=" MACSTR |
8859 | " aid=%d val=%d name=%s", MAC2STR(addr), aid, val, name); | |
8860 | if (val) { | |
8861 | if (!if_nametoindex(name)) { | |
8862 | if (nl80211_create_iface(drv, name, | |
8863 | NL80211_IFTYPE_AP_VLAN, | |
d6dcfcda | 8864 | bss->addr, 1, NULL, NULL) < 0) |
f07ead6a JM |
8865 | return -1; |
8866 | if (bridge_ifname && | |
c81eff1a BG |
8867 | linux_br_add_if(drv->global->ioctl_sock, |
8868 | bridge_ifname, name) < 0) | |
f07ead6a JM |
8869 | return -1; |
8870 | } | |
75227f3a JM |
8871 | if (linux_set_iface_flags(drv->global->ioctl_sock, name, 1)) { |
8872 | wpa_printf(MSG_ERROR, "nl80211: Failed to set WDS STA " | |
8873 | "interface %s up", name); | |
8874 | } | |
f07ead6a JM |
8875 | return i802_set_sta_vlan(priv, addr, name, 0); |
8876 | } else { | |
c34e618d FF |
8877 | if (bridge_ifname) |
8878 | linux_br_del_if(drv->global->ioctl_sock, bridge_ifname, | |
8879 | name); | |
8880 | ||
f07ead6a JM |
8881 | i802_set_sta_vlan(priv, addr, bss->ifname, 0); |
8882 | return wpa_driver_nl80211_if_remove(priv, WPA_IF_AP_VLAN, | |
8883 | name); | |
8884 | } | |
8885 | } | |
8886 | ||
8887 | ||
8888 | static void handle_eapol(int sock, void *eloop_ctx, void *sock_ctx) | |
8889 | { | |
8890 | struct wpa_driver_nl80211_data *drv = eloop_ctx; | |
8891 | struct sockaddr_ll lladdr; | |
8892 | unsigned char buf[3000]; | |
8893 | int len; | |
8894 | socklen_t fromlen = sizeof(lladdr); | |
8895 | ||
8896 | len = recvfrom(sock, buf, sizeof(buf), 0, | |
8897 | (struct sockaddr *)&lladdr, &fromlen); | |
8898 | if (len < 0) { | |
8899 | perror("recv"); | |
8900 | return; | |
8901 | } | |
8902 | ||
8903 | if (have_ifidx(drv, lladdr.sll_ifindex)) | |
8904 | drv_event_eapol_rx(drv->ctx, lladdr.sll_addr, buf, len); | |
8905 | } | |
8906 | ||
8907 | ||
94627f6c | 8908 | static int i802_check_bridge(struct wpa_driver_nl80211_data *drv, |
e17a2477 | 8909 | struct i802_bss *bss, |
94627f6c JM |
8910 | const char *brname, const char *ifname) |
8911 | { | |
8912 | int ifindex; | |
8913 | char in_br[IFNAMSIZ]; | |
8914 | ||
e17a2477 | 8915 | os_strlcpy(bss->brname, brname, IFNAMSIZ); |
94627f6c JM |
8916 | ifindex = if_nametoindex(brname); |
8917 | if (ifindex == 0) { | |
8918 | /* | |
8919 | * Bridge was configured, but the bridge device does | |
8920 | * not exist. Try to add it now. | |
8921 | */ | |
c81eff1a | 8922 | if (linux_br_add(drv->global->ioctl_sock, brname) < 0) { |
94627f6c JM |
8923 | wpa_printf(MSG_ERROR, "nl80211: Failed to add the " |
8924 | "bridge interface %s: %s", | |
8925 | brname, strerror(errno)); | |
8926 | return -1; | |
8927 | } | |
e17a2477 | 8928 | bss->added_bridge = 1; |
94627f6c JM |
8929 | add_ifidx(drv, if_nametoindex(brname)); |
8930 | } | |
8931 | ||
8932 | if (linux_br_get(in_br, ifname) == 0) { | |
8933 | if (os_strcmp(in_br, brname) == 0) | |
8934 | return 0; /* already in the bridge */ | |
8935 | ||
8936 | wpa_printf(MSG_DEBUG, "nl80211: Removing interface %s from " | |
8937 | "bridge %s", ifname, in_br); | |
c81eff1a BG |
8938 | if (linux_br_del_if(drv->global->ioctl_sock, in_br, ifname) < |
8939 | 0) { | |
94627f6c JM |
8940 | wpa_printf(MSG_ERROR, "nl80211: Failed to " |
8941 | "remove interface %s from bridge " | |
8942 | "%s: %s", | |
8943 | ifname, brname, strerror(errno)); | |
8944 | return -1; | |
8945 | } | |
8946 | } | |
8947 | ||
8948 | wpa_printf(MSG_DEBUG, "nl80211: Adding interface %s into bridge %s", | |
8949 | ifname, brname); | |
c81eff1a | 8950 | if (linux_br_add_if(drv->global->ioctl_sock, brname, ifname) < 0) { |
94627f6c JM |
8951 | wpa_printf(MSG_ERROR, "nl80211: Failed to add interface %s " |
8952 | "into bridge %s: %s", | |
8953 | ifname, brname, strerror(errno)); | |
8954 | return -1; | |
8955 | } | |
e17a2477 | 8956 | bss->added_if_into_bridge = 1; |
94627f6c JM |
8957 | |
8958 | return 0; | |
8959 | } | |
8960 | ||
8961 | ||
92f475b4 JM |
8962 | static void *i802_init(struct hostapd_data *hapd, |
8963 | struct wpa_init_params *params) | |
c5121837 JM |
8964 | { |
8965 | struct wpa_driver_nl80211_data *drv; | |
a2e40bb6 | 8966 | struct i802_bss *bss; |
c5121837 | 8967 | size_t i; |
94627f6c JM |
8968 | char brname[IFNAMSIZ]; |
8969 | int ifindex, br_ifindex; | |
8970 | int br_added = 0; | |
c5121837 | 8971 | |
4b24282a JM |
8972 | bss = wpa_driver_nl80211_init(hapd, params->ifname, |
8973 | params->global_priv); | |
a2e40bb6 | 8974 | if (bss == NULL) |
c5121837 | 8975 | return NULL; |
c5121837 | 8976 | |
a2e40bb6 | 8977 | drv = bss->drv; |
0382097e | 8978 | drv->nlmode = NL80211_IFTYPE_AP; |
7635bfb0 JB |
8979 | drv->eapol_sock = -1; |
8980 | ||
94627f6c JM |
8981 | if (linux_br_get(brname, params->ifname) == 0) { |
8982 | wpa_printf(MSG_DEBUG, "nl80211: Interface %s is in bridge %s", | |
8983 | params->ifname, brname); | |
8984 | br_ifindex = if_nametoindex(brname); | |
8985 | } else { | |
8986 | brname[0] = '\0'; | |
8987 | br_ifindex = 0; | |
8988 | } | |
8989 | ||
c5121837 JM |
8990 | drv->num_if_indices = sizeof(drv->default_if_indices) / sizeof(int); |
8991 | drv->if_indices = drv->default_if_indices; | |
92f475b4 | 8992 | for (i = 0; i < params->num_bridge; i++) { |
94627f6c JM |
8993 | if (params->bridge[i]) { |
8994 | ifindex = if_nametoindex(params->bridge[i]); | |
8995 | if (ifindex) | |
8996 | add_ifidx(drv, ifindex); | |
8997 | if (ifindex == br_ifindex) | |
8998 | br_added = 1; | |
8999 | } | |
c5121837 | 9000 | } |
94627f6c JM |
9001 | if (!br_added && br_ifindex && |
9002 | (params->num_bridge == 0 || !params->bridge[0])) | |
9003 | add_ifidx(drv, br_ifindex); | |
c5121837 | 9004 | |
ad1e68e6 JM |
9005 | /* start listening for EAPOL on the default AP interface */ |
9006 | add_ifidx(drv, drv->ifindex); | |
9007 | ||
c81eff1a | 9008 | if (linux_set_iface_flags(drv->global->ioctl_sock, bss->ifname, 0)) |
6980c191 | 9009 | goto failed; |
ad1e68e6 | 9010 | |
6980c191 | 9011 | if (params->bssid) { |
c81eff1a | 9012 | if (linux_set_ifhwaddr(drv->global->ioctl_sock, bss->ifname, |
2ac9688e | 9013 | params->bssid)) |
460456f8 JM |
9014 | goto failed; |
9015 | } | |
ad1e68e6 | 9016 | |
b1f625e0 | 9017 | if (wpa_driver_nl80211_set_mode(bss, drv->nlmode)) { |
ad1e68e6 | 9018 | wpa_printf(MSG_ERROR, "nl80211: Failed to set interface %s " |
a2e40bb6 | 9019 | "into AP mode", bss->ifname); |
bbaf0837 | 9020 | goto failed; |
ad1e68e6 JM |
9021 | } |
9022 | ||
94627f6c | 9023 | if (params->num_bridge && params->bridge[0] && |
e17a2477 | 9024 | i802_check_bridge(drv, bss, params->bridge[0], params->ifname) < 0) |
94627f6c JM |
9025 | goto failed; |
9026 | ||
c81eff1a | 9027 | if (linux_set_iface_flags(drv->global->ioctl_sock, bss->ifname, 1)) |
bbaf0837 | 9028 | goto failed; |
ad1e68e6 JM |
9029 | |
9030 | drv->eapol_sock = socket(PF_PACKET, SOCK_DGRAM, htons(ETH_P_PAE)); | |
9031 | if (drv->eapol_sock < 0) { | |
9032 | perror("socket(PF_PACKET, SOCK_DGRAM, ETH_P_PAE)"); | |
bbaf0837 | 9033 | goto failed; |
ad1e68e6 JM |
9034 | } |
9035 | ||
9036 | if (eloop_register_read_sock(drv->eapol_sock, handle_eapol, drv, NULL)) | |
9037 | { | |
9038 | printf("Could not register read socket for eapol\n"); | |
c5121837 | 9039 | goto failed; |
ad1e68e6 JM |
9040 | } |
9041 | ||
c81eff1a BG |
9042 | if (linux_get_ifhwaddr(drv->global->ioctl_sock, bss->ifname, |
9043 | params->own_addr)) | |
bbaf0837 | 9044 | goto failed; |
c5121837 | 9045 | |
341eebee JB |
9046 | memcpy(bss->addr, params->own_addr, ETH_ALEN); |
9047 | ||
a2e40bb6 | 9048 | return bss; |
c5121837 JM |
9049 | |
9050 | failed: | |
7635bfb0 | 9051 | wpa_driver_nl80211_deinit(bss); |
bbaf0837 JM |
9052 | return NULL; |
9053 | } | |
c5121837 | 9054 | |
c5121837 | 9055 | |
bbaf0837 JM |
9056 | static void i802_deinit(void *priv) |
9057 | { | |
9ebce9c5 JM |
9058 | struct i802_bss *bss = priv; |
9059 | wpa_driver_nl80211_deinit(bss); | |
c5121837 JM |
9060 | } |
9061 | ||
9062 | #endif /* HOSTAPD */ | |
9063 | ||
9064 | ||
22a7c9d7 JM |
9065 | static enum nl80211_iftype wpa_driver_nl80211_if_type( |
9066 | enum wpa_driver_if_type type) | |
9067 | { | |
9068 | switch (type) { | |
9069 | case WPA_IF_STATION: | |
9f51b113 | 9070 | return NL80211_IFTYPE_STATION; |
75bde05d JM |
9071 | case WPA_IF_P2P_CLIENT: |
9072 | case WPA_IF_P2P_GROUP: | |
9f51b113 | 9073 | return NL80211_IFTYPE_P2P_CLIENT; |
22a7c9d7 JM |
9074 | case WPA_IF_AP_VLAN: |
9075 | return NL80211_IFTYPE_AP_VLAN; | |
9076 | case WPA_IF_AP_BSS: | |
9077 | return NL80211_IFTYPE_AP; | |
9f51b113 JB |
9078 | case WPA_IF_P2P_GO: |
9079 | return NL80211_IFTYPE_P2P_GO; | |
7aad838c NS |
9080 | case WPA_IF_P2P_DEVICE: |
9081 | return NL80211_IFTYPE_P2P_DEVICE; | |
22a7c9d7 JM |
9082 | } |
9083 | return -1; | |
9084 | } | |
9085 | ||
9086 | ||
482856c8 JM |
9087 | #ifdef CONFIG_P2P |
9088 | ||
f2ed8023 JM |
9089 | static int nl80211_addr_in_use(struct nl80211_global *global, const u8 *addr) |
9090 | { | |
9091 | struct wpa_driver_nl80211_data *drv; | |
9092 | dl_list_for_each(drv, &global->interfaces, | |
9093 | struct wpa_driver_nl80211_data, list) { | |
341eebee | 9094 | if (os_memcmp(addr, drv->first_bss.addr, ETH_ALEN) == 0) |
f2ed8023 JM |
9095 | return 1; |
9096 | } | |
9097 | return 0; | |
9098 | } | |
9099 | ||
9100 | ||
9101 | static int nl80211_p2p_interface_addr(struct wpa_driver_nl80211_data *drv, | |
9102 | u8 *new_addr) | |
9103 | { | |
9104 | unsigned int idx; | |
9105 | ||
9106 | if (!drv->global) | |
9107 | return -1; | |
9108 | ||
341eebee | 9109 | os_memcpy(new_addr, drv->first_bss.addr, ETH_ALEN); |
f2ed8023 | 9110 | for (idx = 0; idx < 64; idx++) { |
341eebee | 9111 | new_addr[0] = drv->first_bss.addr[0] | 0x02; |
f2ed8023 JM |
9112 | new_addr[0] ^= idx << 2; |
9113 | if (!nl80211_addr_in_use(drv->global, new_addr)) | |
9114 | break; | |
9115 | } | |
9116 | if (idx == 64) | |
9117 | return -1; | |
9118 | ||
9119 | wpa_printf(MSG_DEBUG, "nl80211: Assigned new P2P Interface Address " | |
9120 | MACSTR, MAC2STR(new_addr)); | |
9121 | ||
9122 | return 0; | |
9123 | } | |
9124 | ||
482856c8 JM |
9125 | #endif /* CONFIG_P2P */ |
9126 | ||
f2ed8023 | 9127 | |
f632e483 AS |
9128 | struct wdev_info { |
9129 | u64 wdev_id; | |
9130 | int wdev_id_set; | |
9131 | u8 macaddr[ETH_ALEN]; | |
9132 | }; | |
9133 | ||
9134 | static int nl80211_wdev_handler(struct nl_msg *msg, void *arg) | |
e472e1b4 AS |
9135 | { |
9136 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); | |
9137 | struct nlattr *tb[NL80211_ATTR_MAX + 1]; | |
f632e483 | 9138 | struct wdev_info *wi = arg; |
e472e1b4 AS |
9139 | |
9140 | nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), | |
9141 | genlmsg_attrlen(gnlh, 0), NULL); | |
9142 | if (tb[NL80211_ATTR_WDEV]) { | |
f632e483 AS |
9143 | wi->wdev_id = nla_get_u64(tb[NL80211_ATTR_WDEV]); |
9144 | wi->wdev_id_set = 1; | |
e472e1b4 AS |
9145 | } |
9146 | ||
9147 | if (tb[NL80211_ATTR_MAC]) | |
f632e483 | 9148 | os_memcpy(wi->macaddr, nla_data(tb[NL80211_ATTR_MAC]), |
e472e1b4 AS |
9149 | ETH_ALEN); |
9150 | ||
9151 | return NL_SKIP; | |
9152 | } | |
9153 | ||
9154 | ||
7ab68865 | 9155 | static int wpa_driver_nl80211_if_add(void *priv, enum wpa_driver_if_type type, |
8043e725 | 9156 | const char *ifname, const u8 *addr, |
f3585c8a | 9157 | void *bss_ctx, void **drv_priv, |
e17a2477 JM |
9158 | char *force_ifname, u8 *if_addr, |
9159 | const char *bridge) | |
22a7c9d7 | 9160 | { |
e472e1b4 | 9161 | enum nl80211_iftype nlmode; |
a2e40bb6 FF |
9162 | struct i802_bss *bss = priv; |
9163 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
22a7c9d7 | 9164 | int ifidx; |
22a7c9d7 | 9165 | |
f3585c8a JM |
9166 | if (addr) |
9167 | os_memcpy(if_addr, addr, ETH_ALEN); | |
e472e1b4 AS |
9168 | nlmode = wpa_driver_nl80211_if_type(type); |
9169 | if (nlmode == NL80211_IFTYPE_P2P_DEVICE) { | |
f632e483 AS |
9170 | struct wdev_info p2pdev_info; |
9171 | ||
9172 | os_memset(&p2pdev_info, 0, sizeof(p2pdev_info)); | |
e472e1b4 | 9173 | ifidx = nl80211_create_iface(drv, ifname, nlmode, addr, |
f632e483 AS |
9174 | 0, nl80211_wdev_handler, |
9175 | &p2pdev_info); | |
9176 | if (!p2pdev_info.wdev_id_set || ifidx != 0) { | |
e472e1b4 AS |
9177 | wpa_printf(MSG_ERROR, "nl80211: Failed to create a P2P Device interface %s", |
9178 | ifname); | |
e472e1b4 AS |
9179 | return -1; |
9180 | } | |
f632e483 AS |
9181 | |
9182 | drv->global->if_add_wdevid = p2pdev_info.wdev_id; | |
9183 | drv->global->if_add_wdevid_set = p2pdev_info.wdev_id_set; | |
9184 | if (!is_zero_ether_addr(p2pdev_info.macaddr)) | |
9185 | os_memcpy(if_addr, p2pdev_info.macaddr, ETH_ALEN); | |
9186 | wpa_printf(MSG_DEBUG, "nl80211: New P2P Device interface %s (0x%llx) created", | |
9187 | ifname, | |
9188 | (long long unsigned int) p2pdev_info.wdev_id); | |
e472e1b4 AS |
9189 | } else { |
9190 | ifidx = nl80211_create_iface(drv, ifname, nlmode, addr, | |
9191 | 0, NULL, NULL); | |
9192 | if (ifidx < 0) { | |
e472e1b4 AS |
9193 | return -1; |
9194 | } | |
22a7c9d7 JM |
9195 | } |
9196 | ||
ab7a1add AS |
9197 | if (!addr) { |
9198 | if (drv->nlmode == NL80211_IFTYPE_P2P_DEVICE) | |
9199 | os_memcpy(if_addr, bss->addr, ETH_ALEN); | |
9200 | else if (linux_get_ifhwaddr(drv->global->ioctl_sock, | |
9201 | bss->ifname, if_addr) < 0) { | |
9202 | nl80211_remove_iface(drv, ifidx); | |
9203 | return -1; | |
9204 | } | |
c55f774d JM |
9205 | } |
9206 | ||
9207 | #ifdef CONFIG_P2P | |
9208 | if (!addr && | |
9209 | (type == WPA_IF_P2P_CLIENT || type == WPA_IF_P2P_GROUP || | |
9210 | type == WPA_IF_P2P_GO)) { | |
9211 | /* Enforce unique P2P Interface Address */ | |
ab7a1add | 9212 | u8 new_addr[ETH_ALEN]; |
c55f774d | 9213 | |
ab7a1add | 9214 | if (linux_get_ifhwaddr(drv->global->ioctl_sock, ifname, |
c81eff1a | 9215 | new_addr) < 0) { |
c55f774d JM |
9216 | nl80211_remove_iface(drv, ifidx); |
9217 | return -1; | |
9218 | } | |
f608081c | 9219 | if (nl80211_addr_in_use(drv->global, new_addr)) { |
c55f774d JM |
9220 | wpa_printf(MSG_DEBUG, "nl80211: Allocate new address " |
9221 | "for P2P group interface"); | |
f2ed8023 | 9222 | if (nl80211_p2p_interface_addr(drv, new_addr) < 0) { |
c55f774d JM |
9223 | nl80211_remove_iface(drv, ifidx); |
9224 | return -1; | |
9225 | } | |
c81eff1a | 9226 | if (linux_set_ifhwaddr(drv->global->ioctl_sock, ifname, |
c55f774d JM |
9227 | new_addr) < 0) { |
9228 | nl80211_remove_iface(drv, ifidx); | |
9229 | return -1; | |
9230 | } | |
c55f774d | 9231 | } |
f67eeb5c | 9232 | os_memcpy(if_addr, new_addr, ETH_ALEN); |
c55f774d JM |
9233 | } |
9234 | #endif /* CONFIG_P2P */ | |
f3585c8a | 9235 | |
22a7c9d7 JM |
9236 | #ifdef HOSTAPD |
9237 | if (type == WPA_IF_AP_BSS) { | |
f5eb9da3 JM |
9238 | struct i802_bss *new_bss = os_zalloc(sizeof(*new_bss)); |
9239 | if (new_bss == NULL) { | |
9240 | nl80211_remove_iface(drv, ifidx); | |
9241 | return -1; | |
9242 | } | |
9243 | ||
9244 | if (bridge && | |
9245 | i802_check_bridge(drv, new_bss, bridge, ifname) < 0) { | |
9246 | wpa_printf(MSG_ERROR, "nl80211: Failed to add the new " | |
9247 | "interface %s to a bridge %s", | |
9248 | ifname, bridge); | |
9249 | nl80211_remove_iface(drv, ifidx); | |
9250 | os_free(new_bss); | |
9251 | return -1; | |
9252 | } | |
9253 | ||
c81eff1a BG |
9254 | if (linux_set_iface_flags(drv->global->ioctl_sock, ifname, 1)) |
9255 | { | |
34f2f814 | 9256 | nl80211_remove_iface(drv, ifidx); |
07179987 | 9257 | os_free(new_bss); |
22a7c9d7 JM |
9258 | return -1; |
9259 | } | |
a2e40bb6 | 9260 | os_strlcpy(new_bss->ifname, ifname, IFNAMSIZ); |
341eebee | 9261 | os_memcpy(new_bss->addr, if_addr, ETH_ALEN); |
a2e40bb6 FF |
9262 | new_bss->ifindex = ifidx; |
9263 | new_bss->drv = drv; | |
9264 | new_bss->next = drv->first_bss.next; | |
a7a6af4c | 9265 | new_bss->freq = drv->first_bss.freq; |
a5e1eb20 | 9266 | new_bss->ctx = bss_ctx; |
a2e40bb6 FF |
9267 | drv->first_bss.next = new_bss; |
9268 | if (drv_priv) | |
9269 | *drv_priv = new_bss; | |
cc7a48d1 | 9270 | nl80211_init_bss(new_bss); |
3dd1d890 YAP |
9271 | |
9272 | /* Subscribe management frames for this WPA_IF_AP_BSS */ | |
9273 | if (nl80211_setup_ap(new_bss)) | |
9274 | return -1; | |
22a7c9d7 JM |
9275 | } |
9276 | #endif /* HOSTAPD */ | |
9277 | ||
ff6a158b JM |
9278 | if (drv->global) |
9279 | drv->global->if_add_ifindex = ifidx; | |
9280 | ||
22a7c9d7 JM |
9281 | return 0; |
9282 | } | |
9283 | ||
9284 | ||
9ebce9c5 | 9285 | static int wpa_driver_nl80211_if_remove(struct i802_bss *bss, |
22a7c9d7 JM |
9286 | enum wpa_driver_if_type type, |
9287 | const char *ifname) | |
9288 | { | |
a2e40bb6 | 9289 | struct wpa_driver_nl80211_data *drv = bss->drv; |
22a7c9d7 JM |
9290 | int ifindex = if_nametoindex(ifname); |
9291 | ||
e748062b JM |
9292 | wpa_printf(MSG_DEBUG, "nl80211: %s(type=%d ifname=%s) ifindex=%d", |
9293 | __func__, type, ifname, ifindex); | |
2b72df63 JM |
9294 | if (ifindex > 0) |
9295 | nl80211_remove_iface(drv, ifindex); | |
c34e618d | 9296 | |
e17a2477 | 9297 | #ifdef HOSTAPD |
c34e618d FF |
9298 | if (type != WPA_IF_AP_BSS) |
9299 | return 0; | |
9300 | ||
e17a2477 | 9301 | if (bss->added_if_into_bridge) { |
c81eff1a BG |
9302 | if (linux_br_del_if(drv->global->ioctl_sock, bss->brname, |
9303 | bss->ifname) < 0) | |
e17a2477 JM |
9304 | wpa_printf(MSG_INFO, "nl80211: Failed to remove " |
9305 | "interface %s from bridge %s: %s", | |
9306 | bss->ifname, bss->brname, strerror(errno)); | |
9307 | } | |
9308 | if (bss->added_bridge) { | |
c81eff1a | 9309 | if (linux_br_del(drv->global->ioctl_sock, bss->brname) < 0) |
e17a2477 JM |
9310 | wpa_printf(MSG_INFO, "nl80211: Failed to remove " |
9311 | "bridge %s: %s", | |
9312 | bss->brname, strerror(errno)); | |
9313 | } | |
a2e40bb6 FF |
9314 | |
9315 | if (bss != &drv->first_bss) { | |
8546ea19 | 9316 | struct i802_bss *tbss; |
a2e40bb6 | 9317 | |
8546ea19 JM |
9318 | for (tbss = &drv->first_bss; tbss; tbss = tbss->next) { |
9319 | if (tbss->next == bss) { | |
9320 | tbss->next = bss->next; | |
3dd1d890 YAP |
9321 | /* Unsubscribe management frames */ |
9322 | nl80211_teardown_ap(bss); | |
cc7a48d1 | 9323 | nl80211_destroy_bss(bss); |
8546ea19 JM |
9324 | os_free(bss); |
9325 | bss = NULL; | |
9326 | break; | |
9327 | } | |
22a7c9d7 | 9328 | } |
8546ea19 JM |
9329 | if (bss) |
9330 | wpa_printf(MSG_INFO, "nl80211: %s - could not find " | |
9331 | "BSS %p in the list", __func__, bss); | |
22a7c9d7 JM |
9332 | } |
9333 | #endif /* HOSTAPD */ | |
9334 | ||
9335 | return 0; | |
9336 | } | |
9337 | ||
9338 | ||
55777702 JM |
9339 | static int cookie_handler(struct nl_msg *msg, void *arg) |
9340 | { | |
9341 | struct nlattr *tb[NL80211_ATTR_MAX + 1]; | |
9342 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); | |
9343 | u64 *cookie = arg; | |
9344 | nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), | |
9345 | genlmsg_attrlen(gnlh, 0), NULL); | |
9346 | if (tb[NL80211_ATTR_COOKIE]) | |
9347 | *cookie = nla_get_u64(tb[NL80211_ATTR_COOKIE]); | |
9348 | return NL_SKIP; | |
9349 | } | |
9350 | ||
9351 | ||
88df0ef7 | 9352 | static int nl80211_send_frame_cmd(struct i802_bss *bss, |
5dfca53f JB |
9353 | unsigned int freq, unsigned int wait, |
9354 | const u8 *buf, size_t buf_len, | |
88df0ef7 JB |
9355 | u64 *cookie_out, int no_cck, int no_ack, |
9356 | int offchanok) | |
9884f9cc | 9357 | { |
88df0ef7 | 9358 | struct wpa_driver_nl80211_data *drv = bss->drv; |
9884f9cc JB |
9359 | struct nl_msg *msg; |
9360 | u64 cookie; | |
9361 | int ret = -1; | |
9362 | ||
9363 | msg = nlmsg_alloc(); | |
9364 | if (!msg) | |
9365 | return -1; | |
9366 | ||
cc2ada86 | 9367 | wpa_printf(MSG_MSGDUMP, "nl80211: CMD_FRAME freq=%u wait=%u no_cck=%d " |
2e3e4566 JM |
9368 | "no_ack=%d offchanok=%d", |
9369 | freq, wait, no_cck, no_ack, offchanok); | |
c91f796f | 9370 | wpa_hexdump(MSG_MSGDUMP, "CMD_FRAME", buf, buf_len); |
9fb04070 | 9371 | nl80211_cmd(drv, msg, 0, NL80211_CMD_FRAME); |
9884f9cc | 9372 | |
f632e483 | 9373 | if (nl80211_set_iface_id(msg, bss) < 0) |
d3aaef80 | 9374 | goto nla_put_failure; |
c91f796f NC |
9375 | if (freq) |
9376 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_FREQ, freq); | |
9db931ed JM |
9377 | if (wait) |
9378 | NLA_PUT_U32(msg, NL80211_ATTR_DURATION, wait); | |
b9fd8ce8 | 9379 | if (offchanok && (drv->capa.flags & WPA_DRIVER_FLAGS_OFFCHANNEL_TX)) |
88df0ef7 | 9380 | NLA_PUT_FLAG(msg, NL80211_ATTR_OFFCHANNEL_TX_OK); |
b106173a JM |
9381 | if (no_cck) |
9382 | NLA_PUT_FLAG(msg, NL80211_ATTR_TX_NO_CCK_RATE); | |
ddc53271 JM |
9383 | if (no_ack) |
9384 | NLA_PUT_FLAG(msg, NL80211_ATTR_DONT_WAIT_FOR_ACK); | |
970fa12e | 9385 | |
9884f9cc JB |
9386 | NLA_PUT(msg, NL80211_ATTR_FRAME, buf_len, buf); |
9387 | ||
9388 | cookie = 0; | |
9389 | ret = send_and_recv_msgs(drv, msg, cookie_handler, &cookie); | |
9390 | msg = NULL; | |
9391 | if (ret) { | |
9392 | wpa_printf(MSG_DEBUG, "nl80211: Frame command failed: ret=%d " | |
a05225c8 JM |
9393 | "(%s) (freq=%u wait=%u)", ret, strerror(-ret), |
9394 | freq, wait); | |
9884f9cc JB |
9395 | goto nla_put_failure; |
9396 | } | |
cc2ada86 | 9397 | wpa_printf(MSG_MSGDUMP, "nl80211: Frame TX command accepted%s; " |
ddc53271 JM |
9398 | "cookie 0x%llx", no_ack ? " (no ACK)" : "", |
9399 | (long long unsigned int) cookie); | |
9884f9cc JB |
9400 | |
9401 | if (cookie_out) | |
ddc53271 | 9402 | *cookie_out = no_ack ? (u64) -1 : cookie; |
9884f9cc JB |
9403 | |
9404 | nla_put_failure: | |
9405 | nlmsg_free(msg); | |
9406 | return ret; | |
9407 | } | |
9408 | ||
9409 | ||
9ebce9c5 JM |
9410 | static int wpa_driver_nl80211_send_action(struct i802_bss *bss, |
9411 | unsigned int freq, | |
190b9062 | 9412 | unsigned int wait_time, |
58f6fbe0 JM |
9413 | const u8 *dst, const u8 *src, |
9414 | const u8 *bssid, | |
b106173a JM |
9415 | const u8 *data, size_t data_len, |
9416 | int no_cck) | |
58f6fbe0 | 9417 | { |
a2e40bb6 | 9418 | struct wpa_driver_nl80211_data *drv = bss->drv; |
58f6fbe0 | 9419 | int ret = -1; |
58f6fbe0 JM |
9420 | u8 *buf; |
9421 | struct ieee80211_hdr *hdr; | |
58f6fbe0 | 9422 | |
5dfca53f | 9423 | wpa_printf(MSG_DEBUG, "nl80211: Send Action frame (ifindex=%d, " |
55231068 JM |
9424 | "freq=%u MHz wait=%d ms no_cck=%d)", |
9425 | drv->ifindex, freq, wait_time, no_cck); | |
58f6fbe0 JM |
9426 | |
9427 | buf = os_zalloc(24 + data_len); | |
9428 | if (buf == NULL) | |
9429 | return ret; | |
9430 | os_memcpy(buf + 24, data, data_len); | |
9431 | hdr = (struct ieee80211_hdr *) buf; | |
9432 | hdr->frame_control = | |
9433 | IEEE80211_FC(WLAN_FC_TYPE_MGMT, WLAN_FC_STYPE_ACTION); | |
9434 | os_memcpy(hdr->addr1, dst, ETH_ALEN); | |
9435 | os_memcpy(hdr->addr2, src, ETH_ALEN); | |
9436 | os_memcpy(hdr->addr3, bssid, ETH_ALEN); | |
9437 | ||
f78f2785 JM |
9438 | if (is_ap_interface(drv->nlmode) && |
9439 | (!(drv->capa.flags & WPA_DRIVER_FLAGS_OFFCHANNEL_TX) || | |
9440 | (int) freq == bss->freq || drv->device_ap_sme || | |
9441 | !drv->use_monitor)) | |
9ebce9c5 JM |
9442 | ret = wpa_driver_nl80211_send_mlme(bss, buf, 24 + data_len, |
9443 | 0, freq, no_cck, 1, | |
9444 | wait_time); | |
9884f9cc | 9445 | else |
88df0ef7 | 9446 | ret = nl80211_send_frame_cmd(bss, freq, wait_time, buf, |
5dfca53f | 9447 | 24 + data_len, |
b106173a | 9448 | &drv->send_action_cookie, |
88df0ef7 | 9449 | no_cck, 0, 1); |
58f6fbe0 | 9450 | |
f8bf1421 | 9451 | os_free(buf); |
58f6fbe0 JM |
9452 | return ret; |
9453 | } | |
9454 | ||
9455 | ||
5dfca53f JB |
9456 | static void wpa_driver_nl80211_send_action_cancel_wait(void *priv) |
9457 | { | |
9458 | struct i802_bss *bss = priv; | |
9459 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
9460 | struct nl_msg *msg; | |
9461 | int ret; | |
9462 | ||
9463 | msg = nlmsg_alloc(); | |
9464 | if (!msg) | |
9465 | return; | |
9466 | ||
316a9e4d JM |
9467 | wpa_printf(MSG_DEBUG, "nl80211: Cancel TX frame wait: cookie=0x%llx", |
9468 | (long long unsigned int) drv->send_action_cookie); | |
9fb04070 | 9469 | nl80211_cmd(drv, msg, 0, NL80211_CMD_FRAME_WAIT_CANCEL); |
5dfca53f | 9470 | |
7940c790 AS |
9471 | if (nl80211_set_iface_id(msg, bss) < 0) |
9472 | goto nla_put_failure; | |
5dfca53f JB |
9473 | NLA_PUT_U64(msg, NL80211_ATTR_COOKIE, drv->send_action_cookie); |
9474 | ||
9475 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); | |
9476 | msg = NULL; | |
9477 | if (ret) | |
9478 | wpa_printf(MSG_DEBUG, "nl80211: wait cancel failed: ret=%d " | |
9479 | "(%s)", ret, strerror(-ret)); | |
9480 | ||
9481 | nla_put_failure: | |
9482 | nlmsg_free(msg); | |
9483 | } | |
9484 | ||
9485 | ||
55777702 JM |
9486 | static int wpa_driver_nl80211_remain_on_channel(void *priv, unsigned int freq, |
9487 | unsigned int duration) | |
9488 | { | |
a2e40bb6 FF |
9489 | struct i802_bss *bss = priv; |
9490 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
55777702 JM |
9491 | struct nl_msg *msg; |
9492 | int ret; | |
9493 | u64 cookie; | |
9494 | ||
9495 | msg = nlmsg_alloc(); | |
9496 | if (!msg) | |
9497 | return -1; | |
9498 | ||
9fb04070 | 9499 | nl80211_cmd(drv, msg, 0, NL80211_CMD_REMAIN_ON_CHANNEL); |
55777702 | 9500 | |
f632e483 | 9501 | if (nl80211_set_iface_id(msg, bss) < 0) |
d3aaef80 DS |
9502 | goto nla_put_failure; |
9503 | ||
55777702 JM |
9504 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_FREQ, freq); |
9505 | NLA_PUT_U32(msg, NL80211_ATTR_DURATION, duration); | |
9506 | ||
9507 | cookie = 0; | |
9508 | ret = send_and_recv_msgs(drv, msg, cookie_handler, &cookie); | |
5883168a | 9509 | msg = NULL; |
55777702 JM |
9510 | if (ret == 0) { |
9511 | wpa_printf(MSG_DEBUG, "nl80211: Remain-on-channel cookie " | |
9512 | "0x%llx for freq=%u MHz duration=%u", | |
9513 | (long long unsigned int) cookie, freq, duration); | |
9514 | drv->remain_on_chan_cookie = cookie; | |
531f0331 | 9515 | drv->pending_remain_on_chan = 1; |
55777702 JM |
9516 | return 0; |
9517 | } | |
9518 | wpa_printf(MSG_DEBUG, "nl80211: Failed to request remain-on-channel " | |
15ed5535 JM |
9519 | "(freq=%d duration=%u): %d (%s)", |
9520 | freq, duration, ret, strerror(-ret)); | |
55777702 | 9521 | nla_put_failure: |
5883168a | 9522 | nlmsg_free(msg); |
55777702 JM |
9523 | return -1; |
9524 | } | |
9525 | ||
9526 | ||
9527 | static int wpa_driver_nl80211_cancel_remain_on_channel(void *priv) | |
9528 | { | |
a2e40bb6 FF |
9529 | struct i802_bss *bss = priv; |
9530 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
55777702 JM |
9531 | struct nl_msg *msg; |
9532 | int ret; | |
9533 | ||
9534 | if (!drv->pending_remain_on_chan) { | |
9535 | wpa_printf(MSG_DEBUG, "nl80211: No pending remain-on-channel " | |
9536 | "to cancel"); | |
9537 | return -1; | |
9538 | } | |
9539 | ||
9540 | wpa_printf(MSG_DEBUG, "nl80211: Cancel remain-on-channel with cookie " | |
9541 | "0x%llx", | |
9542 | (long long unsigned int) drv->remain_on_chan_cookie); | |
9543 | ||
9544 | msg = nlmsg_alloc(); | |
9545 | if (!msg) | |
9546 | return -1; | |
9547 | ||
9fb04070 | 9548 | nl80211_cmd(drv, msg, 0, NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL); |
55777702 | 9549 | |
f632e483 | 9550 | if (nl80211_set_iface_id(msg, bss) < 0) |
d3aaef80 DS |
9551 | goto nla_put_failure; |
9552 | ||
55777702 JM |
9553 | NLA_PUT_U64(msg, NL80211_ATTR_COOKIE, drv->remain_on_chan_cookie); |
9554 | ||
9555 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); | |
5883168a | 9556 | msg = NULL; |
55777702 JM |
9557 | if (ret == 0) |
9558 | return 0; | |
9559 | wpa_printf(MSG_DEBUG, "nl80211: Failed to cancel remain-on-channel: " | |
9560 | "%d (%s)", ret, strerror(-ret)); | |
9561 | nla_put_failure: | |
5883168a | 9562 | nlmsg_free(msg); |
55777702 JM |
9563 | return -1; |
9564 | } | |
9565 | ||
9566 | ||
9ebce9c5 | 9567 | static int wpa_driver_nl80211_probe_req_report(struct i802_bss *bss, int report) |
504e905c | 9568 | { |
a2e40bb6 | 9569 | struct wpa_driver_nl80211_data *drv = bss->drv; |
504e905c | 9570 | |
5582a5d1 | 9571 | if (!report) { |
0d891981 JM |
9572 | if (bss->nl_preq && drv->device_ap_sme && |
9573 | is_ap_interface(drv->nlmode)) { | |
9574 | /* | |
9575 | * Do not disable Probe Request reporting that was | |
9576 | * enabled in nl80211_setup_ap(). | |
9577 | */ | |
9578 | wpa_printf(MSG_DEBUG, "nl80211: Skip disabling of " | |
9579 | "Probe Request reporting nl_preq=%p while " | |
9580 | "in AP mode", bss->nl_preq); | |
9581 | } else if (bss->nl_preq) { | |
36488c05 JM |
9582 | wpa_printf(MSG_DEBUG, "nl80211: Disable Probe Request " |
9583 | "reporting nl_preq=%p", bss->nl_preq); | |
5f65e9f7 | 9584 | nl80211_destroy_eloop_handle(&bss->nl_preq); |
5582a5d1 JB |
9585 | } |
9586 | return 0; | |
9587 | } | |
9588 | ||
481234cf | 9589 | if (bss->nl_preq) { |
5582a5d1 | 9590 | wpa_printf(MSG_DEBUG, "nl80211: Probe Request reporting " |
36488c05 | 9591 | "already on! nl_preq=%p", bss->nl_preq); |
5582a5d1 JB |
9592 | return 0; |
9593 | } | |
9594 | ||
481234cf JM |
9595 | bss->nl_preq = nl_create_handle(drv->global->nl_cb, "preq"); |
9596 | if (bss->nl_preq == NULL) | |
5582a5d1 | 9597 | return -1; |
36488c05 JM |
9598 | wpa_printf(MSG_DEBUG, "nl80211: Enable Probe Request " |
9599 | "reporting nl_preq=%p", bss->nl_preq); | |
5582a5d1 | 9600 | |
481234cf | 9601 | if (nl80211_register_frame(bss, bss->nl_preq, |
5582a5d1 JB |
9602 | (WLAN_FC_TYPE_MGMT << 2) | |
9603 | (WLAN_FC_STYPE_PROBE_REQ << 4), | |
a92dfde8 JB |
9604 | NULL, 0) < 0) |
9605 | goto out_err; | |
5582a5d1 | 9606 | |
5f65e9f7 JB |
9607 | nl80211_register_eloop_read(&bss->nl_preq, |
9608 | wpa_driver_nl80211_event_receive, | |
9609 | bss->nl_cb); | |
5582a5d1 | 9610 | |
504e905c | 9611 | return 0; |
5582a5d1 | 9612 | |
a92dfde8 | 9613 | out_err: |
221a59c9 | 9614 | nl_destroy_handles(&bss->nl_preq); |
5582a5d1 | 9615 | return -1; |
504e905c JM |
9616 | } |
9617 | ||
9618 | ||
4e5cb1a3 JM |
9619 | static int nl80211_disable_11b_rates(struct wpa_driver_nl80211_data *drv, |
9620 | int ifindex, int disabled) | |
9621 | { | |
9622 | struct nl_msg *msg; | |
9623 | struct nlattr *bands, *band; | |
9624 | int ret; | |
9625 | ||
9626 | msg = nlmsg_alloc(); | |
9627 | if (!msg) | |
9628 | return -1; | |
9629 | ||
9fb04070 | 9630 | nl80211_cmd(drv, msg, 0, NL80211_CMD_SET_TX_BITRATE_MASK); |
4e5cb1a3 JM |
9631 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, ifindex); |
9632 | ||
9633 | bands = nla_nest_start(msg, NL80211_ATTR_TX_RATES); | |
9634 | if (!bands) | |
9635 | goto nla_put_failure; | |
9636 | ||
9637 | /* | |
9638 | * Disable 2 GHz rates 1, 2, 5.5, 11 Mbps by masking out everything | |
9639 | * else apart from 6, 9, 12, 18, 24, 36, 48, 54 Mbps from non-MCS | |
9640 | * rates. All 5 GHz rates are left enabled. | |
9641 | */ | |
9642 | band = nla_nest_start(msg, NL80211_BAND_2GHZ); | |
9643 | if (!band) | |
9644 | goto nla_put_failure; | |
1dea5882 JM |
9645 | if (disabled) { |
9646 | NLA_PUT(msg, NL80211_TXRATE_LEGACY, 8, | |
9647 | "\x0c\x12\x18\x24\x30\x48\x60\x6c"); | |
9648 | } | |
4e5cb1a3 JM |
9649 | nla_nest_end(msg, band); |
9650 | ||
9651 | nla_nest_end(msg, bands); | |
9652 | ||
9653 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); | |
9654 | msg = NULL; | |
9655 | if (ret) { | |
9656 | wpa_printf(MSG_DEBUG, "nl80211: Set TX rates failed: ret=%d " | |
9657 | "(%s)", ret, strerror(-ret)); | |
1d0c6fb1 JM |
9658 | } else |
9659 | drv->disabled_11b_rates = disabled; | |
4e5cb1a3 JM |
9660 | |
9661 | return ret; | |
9662 | ||
9663 | nla_put_failure: | |
9664 | nlmsg_free(msg); | |
9665 | return -1; | |
9666 | } | |
9667 | ||
9668 | ||
af473088 JM |
9669 | static int wpa_driver_nl80211_deinit_ap(void *priv) |
9670 | { | |
a2e40bb6 FF |
9671 | struct i802_bss *bss = priv; |
9672 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
b1f625e0 | 9673 | if (!is_ap_interface(drv->nlmode)) |
af473088 JM |
9674 | return -1; |
9675 | wpa_driver_nl80211_del_beacon(drv); | |
60b13c20 IP |
9676 | |
9677 | /* | |
9678 | * If the P2P GO interface was dynamically added, then it is | |
9679 | * possible that the interface change to station is not possible. | |
9680 | */ | |
9681 | if (drv->nlmode == NL80211_IFTYPE_P2P_GO && bss->if_dynamic) | |
9682 | return 0; | |
9683 | ||
b1f625e0 | 9684 | return wpa_driver_nl80211_set_mode(priv, NL80211_IFTYPE_STATION); |
af473088 JM |
9685 | } |
9686 | ||
9687 | ||
695c7038 SW |
9688 | static int wpa_driver_nl80211_stop_ap(void *priv) |
9689 | { | |
9690 | struct i802_bss *bss = priv; | |
9691 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
9692 | if (!is_ap_interface(drv->nlmode)) | |
9693 | return -1; | |
9694 | wpa_driver_nl80211_del_beacon(drv); | |
9695 | bss->beacon_set = 0; | |
9696 | return 0; | |
9697 | } | |
9698 | ||
9699 | ||
3c29244e EP |
9700 | static int wpa_driver_nl80211_deinit_p2p_cli(void *priv) |
9701 | { | |
9702 | struct i802_bss *bss = priv; | |
9703 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
9704 | if (drv->nlmode != NL80211_IFTYPE_P2P_CLIENT) | |
9705 | return -1; | |
60b13c20 IP |
9706 | |
9707 | /* | |
9708 | * If the P2P Client interface was dynamically added, then it is | |
9709 | * possible that the interface change to station is not possible. | |
9710 | */ | |
9711 | if (bss->if_dynamic) | |
9712 | return 0; | |
9713 | ||
3c29244e EP |
9714 | return wpa_driver_nl80211_set_mode(priv, NL80211_IFTYPE_STATION); |
9715 | } | |
9716 | ||
9717 | ||
207ef3fb JM |
9718 | static void wpa_driver_nl80211_resume(void *priv) |
9719 | { | |
a2e40bb6 | 9720 | struct i802_bss *bss = priv; |
91724d6f AS |
9721 | |
9722 | if (i802_set_iface_flags(bss, 1)) | |
9723 | wpa_printf(MSG_DEBUG, "nl80211: Failed to set interface up on resume event"); | |
207ef3fb JM |
9724 | } |
9725 | ||
9726 | ||
7b90c16a JM |
9727 | static int nl80211_send_ft_action(void *priv, u8 action, const u8 *target_ap, |
9728 | const u8 *ies, size_t ies_len) | |
9729 | { | |
9730 | struct i802_bss *bss = priv; | |
9731 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
9732 | int ret; | |
9733 | u8 *data, *pos; | |
9734 | size_t data_len; | |
341eebee | 9735 | const u8 *own_addr = bss->addr; |
7b90c16a JM |
9736 | |
9737 | if (action != 1) { | |
9738 | wpa_printf(MSG_ERROR, "nl80211: Unsupported send_ft_action " | |
9739 | "action %d", action); | |
9740 | return -1; | |
9741 | } | |
9742 | ||
9743 | /* | |
9744 | * Action frame payload: | |
9745 | * Category[1] = 6 (Fast BSS Transition) | |
9746 | * Action[1] = 1 (Fast BSS Transition Request) | |
9747 | * STA Address | |
9748 | * Target AP Address | |
9749 | * FT IEs | |
9750 | */ | |
9751 | ||
73fc617d JM |
9752 | data_len = 2 + 2 * ETH_ALEN + ies_len; |
9753 | data = os_malloc(data_len); | |
7b90c16a JM |
9754 | if (data == NULL) |
9755 | return -1; | |
9756 | pos = data; | |
9757 | *pos++ = 0x06; /* FT Action category */ | |
9758 | *pos++ = action; | |
9759 | os_memcpy(pos, own_addr, ETH_ALEN); | |
9760 | pos += ETH_ALEN; | |
9761 | os_memcpy(pos, target_ap, ETH_ALEN); | |
9762 | pos += ETH_ALEN; | |
9763 | os_memcpy(pos, ies, ies_len); | |
9764 | ||
190b9062 JB |
9765 | ret = wpa_driver_nl80211_send_action(bss, drv->assoc_freq, 0, |
9766 | drv->bssid, own_addr, drv->bssid, | |
b106173a | 9767 | data, data_len, 0); |
7b90c16a JM |
9768 | os_free(data); |
9769 | ||
9770 | return ret; | |
9771 | } | |
9772 | ||
9773 | ||
b625473c JM |
9774 | static int nl80211_signal_monitor(void *priv, int threshold, int hysteresis) |
9775 | { | |
9776 | struct i802_bss *bss = priv; | |
9777 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
8970bae8 JB |
9778 | struct nl_msg *msg; |
9779 | struct nlattr *cqm; | |
f0494d0f | 9780 | int ret = -1; |
b625473c JM |
9781 | |
9782 | wpa_printf(MSG_DEBUG, "nl80211: Signal monitor threshold=%d " | |
9783 | "hysteresis=%d", threshold, hysteresis); | |
9784 | ||
9785 | msg = nlmsg_alloc(); | |
9786 | if (!msg) | |
9787 | return -1; | |
9788 | ||
9fb04070 | 9789 | nl80211_cmd(drv, msg, 0, NL80211_CMD_SET_CQM); |
b625473c JM |
9790 | |
9791 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, bss->ifindex); | |
9792 | ||
8970bae8 | 9793 | cqm = nla_nest_start(msg, NL80211_ATTR_CQM); |
b625473c | 9794 | if (cqm == NULL) |
21270bb4 | 9795 | goto nla_put_failure; |
b625473c | 9796 | |
8970bae8 JB |
9797 | NLA_PUT_U32(msg, NL80211_ATTR_CQM_RSSI_THOLD, threshold); |
9798 | NLA_PUT_U32(msg, NL80211_ATTR_CQM_RSSI_HYST, hysteresis); | |
9799 | nla_nest_end(msg, cqm); | |
21270bb4 | 9800 | |
f0494d0f | 9801 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
b625473c JM |
9802 | msg = NULL; |
9803 | ||
9804 | nla_put_failure: | |
b625473c | 9805 | nlmsg_free(msg); |
f0494d0f | 9806 | return ret; |
b625473c JM |
9807 | } |
9808 | ||
9809 | ||
2cc8d8f4 AO |
9810 | /* Converts nl80211_chan_width to a common format */ |
9811 | static enum chan_width convert2width(int width) | |
9812 | { | |
9813 | switch (width) { | |
9814 | case NL80211_CHAN_WIDTH_20_NOHT: | |
9815 | return CHAN_WIDTH_20_NOHT; | |
9816 | case NL80211_CHAN_WIDTH_20: | |
9817 | return CHAN_WIDTH_20; | |
9818 | case NL80211_CHAN_WIDTH_40: | |
9819 | return CHAN_WIDTH_40; | |
9820 | case NL80211_CHAN_WIDTH_80: | |
9821 | return CHAN_WIDTH_80; | |
9822 | case NL80211_CHAN_WIDTH_80P80: | |
9823 | return CHAN_WIDTH_80P80; | |
9824 | case NL80211_CHAN_WIDTH_160: | |
9825 | return CHAN_WIDTH_160; | |
9826 | } | |
9827 | return CHAN_WIDTH_UNKNOWN; | |
9828 | } | |
9829 | ||
9830 | ||
9831 | static int get_channel_width(struct nl_msg *msg, void *arg) | |
9832 | { | |
9833 | struct nlattr *tb[NL80211_ATTR_MAX + 1]; | |
9834 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); | |
9835 | struct wpa_signal_info *sig_change = arg; | |
9836 | ||
9837 | nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), | |
9838 | genlmsg_attrlen(gnlh, 0), NULL); | |
9839 | ||
9840 | sig_change->center_frq1 = -1; | |
9841 | sig_change->center_frq2 = -1; | |
9842 | sig_change->chanwidth = CHAN_WIDTH_UNKNOWN; | |
9843 | ||
9844 | if (tb[NL80211_ATTR_CHANNEL_WIDTH]) { | |
9845 | sig_change->chanwidth = convert2width( | |
9846 | nla_get_u32(tb[NL80211_ATTR_CHANNEL_WIDTH])); | |
9847 | if (tb[NL80211_ATTR_CENTER_FREQ1]) | |
9848 | sig_change->center_frq1 = | |
9849 | nla_get_u32(tb[NL80211_ATTR_CENTER_FREQ1]); | |
9850 | if (tb[NL80211_ATTR_CENTER_FREQ2]) | |
9851 | sig_change->center_frq2 = | |
9852 | nla_get_u32(tb[NL80211_ATTR_CENTER_FREQ2]); | |
9853 | } | |
9854 | ||
9855 | return NL_SKIP; | |
9856 | } | |
9857 | ||
9858 | ||
9859 | static int nl80211_get_channel_width(struct wpa_driver_nl80211_data *drv, | |
9860 | struct wpa_signal_info *sig) | |
9861 | { | |
9862 | struct nl_msg *msg; | |
9863 | ||
9864 | msg = nlmsg_alloc(); | |
9865 | if (!msg) | |
9866 | return -ENOMEM; | |
9867 | ||
9868 | nl80211_cmd(drv, msg, 0, NL80211_CMD_GET_INTERFACE); | |
9869 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, drv->ifindex); | |
9870 | ||
9871 | return send_and_recv_msgs(drv, msg, get_channel_width, sig); | |
9872 | ||
9873 | nla_put_failure: | |
9874 | nlmsg_free(msg); | |
9875 | return -ENOBUFS; | |
9876 | } | |
9877 | ||
9878 | ||
1c5c7273 PS |
9879 | static int nl80211_signal_poll(void *priv, struct wpa_signal_info *si) |
9880 | { | |
9881 | struct i802_bss *bss = priv; | |
9882 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
9883 | int res; | |
9884 | ||
9885 | os_memset(si, 0, sizeof(*si)); | |
9886 | res = nl80211_get_link_signal(drv, si); | |
9887 | if (res != 0) | |
9888 | return res; | |
9889 | ||
2cc8d8f4 AO |
9890 | res = nl80211_get_channel_width(drv, si); |
9891 | if (res != 0) | |
9892 | return res; | |
9893 | ||
1c5c7273 PS |
9894 | return nl80211_get_link_noise(drv, si); |
9895 | } | |
9896 | ||
9897 | ||
57ebba59 JJ |
9898 | static int wpa_driver_nl80211_shared_freq(void *priv) |
9899 | { | |
9900 | struct i802_bss *bss = priv; | |
9901 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
9902 | struct wpa_driver_nl80211_data *driver; | |
9903 | int freq = 0; | |
9904 | ||
9905 | /* | |
9906 | * If the same PHY is in connected state with some other interface, | |
9907 | * then retrieve the assoc freq. | |
9908 | */ | |
9909 | wpa_printf(MSG_DEBUG, "nl80211: Get shared freq for PHY %s", | |
9910 | drv->phyname); | |
9911 | ||
9912 | dl_list_for_each(driver, &drv->global->interfaces, | |
9913 | struct wpa_driver_nl80211_data, list) { | |
9914 | if (drv == driver || | |
9915 | os_strcmp(drv->phyname, driver->phyname) != 0 || | |
9916 | !driver->associated) | |
9917 | continue; | |
9918 | ||
9919 | wpa_printf(MSG_DEBUG, "nl80211: Found a match for PHY %s - %s " | |
9920 | MACSTR, | |
9921 | driver->phyname, driver->first_bss.ifname, | |
341eebee | 9922 | MAC2STR(driver->first_bss.addr)); |
d3bd0f05 JJ |
9923 | if (is_ap_interface(driver->nlmode)) |
9924 | freq = driver->first_bss.freq; | |
9925 | else | |
9926 | freq = nl80211_get_assoc_freq(driver); | |
57ebba59 JJ |
9927 | wpa_printf(MSG_DEBUG, "nl80211: Shared freq for PHY %s: %d", |
9928 | drv->phyname, freq); | |
9929 | } | |
9930 | ||
9931 | if (!freq) | |
9932 | wpa_printf(MSG_DEBUG, "nl80211: No shared interface for " | |
9933 | "PHY (%s) in associated state", drv->phyname); | |
9934 | ||
9935 | return freq; | |
9936 | } | |
9937 | ||
9938 | ||
b91ab76e JM |
9939 | static int nl80211_send_frame(void *priv, const u8 *data, size_t data_len, |
9940 | int encrypt) | |
9941 | { | |
9942 | struct i802_bss *bss = priv; | |
55231068 JM |
9943 | return wpa_driver_nl80211_send_frame(bss, data, data_len, encrypt, 0, |
9944 | 0, 0, 0, 0); | |
b91ab76e JM |
9945 | } |
9946 | ||
9947 | ||
c55f774d JM |
9948 | static int nl80211_set_param(void *priv, const char *param) |
9949 | { | |
c55f774d JM |
9950 | wpa_printf(MSG_DEBUG, "nl80211: driver param='%s'", param); |
9951 | if (param == NULL) | |
9952 | return 0; | |
9953 | ||
9954 | #ifdef CONFIG_P2P | |
9955 | if (os_strstr(param, "use_p2p_group_interface=1")) { | |
482856c8 JM |
9956 | struct i802_bss *bss = priv; |
9957 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
9958 | ||
c55f774d JM |
9959 | wpa_printf(MSG_DEBUG, "nl80211: Use separate P2P group " |
9960 | "interface"); | |
9961 | drv->capa.flags |= WPA_DRIVER_FLAGS_P2P_CONCURRENT; | |
9962 | drv->capa.flags |= WPA_DRIVER_FLAGS_P2P_MGMT_AND_NON_P2P; | |
9963 | } | |
851b0c55 JM |
9964 | |
9965 | if (os_strstr(param, "p2p_device=1")) { | |
9966 | struct i802_bss *bss = priv; | |
9967 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
9968 | drv->allow_p2p_device = 1; | |
9969 | } | |
c55f774d JM |
9970 | #endif /* CONFIG_P2P */ |
9971 | ||
9972 | return 0; | |
9973 | } | |
9974 | ||
9975 | ||
f2ed8023 JM |
9976 | static void * nl80211_global_init(void) |
9977 | { | |
9978 | struct nl80211_global *global; | |
36d84860 BG |
9979 | struct netlink_config *cfg; |
9980 | ||
f2ed8023 JM |
9981 | global = os_zalloc(sizeof(*global)); |
9982 | if (global == NULL) | |
9983 | return NULL; | |
c81eff1a | 9984 | global->ioctl_sock = -1; |
f2ed8023 | 9985 | dl_list_init(&global->interfaces); |
ff6a158b | 9986 | global->if_add_ifindex = -1; |
36d84860 BG |
9987 | |
9988 | cfg = os_zalloc(sizeof(*cfg)); | |
9989 | if (cfg == NULL) | |
9990 | goto err; | |
9991 | ||
9992 | cfg->ctx = global; | |
9993 | cfg->newlink_cb = wpa_driver_nl80211_event_rtm_newlink; | |
9994 | cfg->dellink_cb = wpa_driver_nl80211_event_rtm_dellink; | |
9995 | global->netlink = netlink_init(cfg); | |
9996 | if (global->netlink == NULL) { | |
9997 | os_free(cfg); | |
9998 | goto err; | |
9999 | } | |
10000 | ||
2a7b66f5 BG |
10001 | if (wpa_driver_nl80211_init_nl_global(global) < 0) |
10002 | goto err; | |
10003 | ||
c81eff1a BG |
10004 | global->ioctl_sock = socket(PF_INET, SOCK_DGRAM, 0); |
10005 | if (global->ioctl_sock < 0) { | |
10006 | perror("socket(PF_INET,SOCK_DGRAM)"); | |
10007 | goto err; | |
10008 | } | |
10009 | ||
f2ed8023 | 10010 | return global; |
36d84860 BG |
10011 | |
10012 | err: | |
10013 | nl80211_global_deinit(global); | |
10014 | return NULL; | |
f2ed8023 JM |
10015 | } |
10016 | ||
10017 | ||
10018 | static void nl80211_global_deinit(void *priv) | |
10019 | { | |
10020 | struct nl80211_global *global = priv; | |
10021 | if (global == NULL) | |
10022 | return; | |
10023 | if (!dl_list_empty(&global->interfaces)) { | |
10024 | wpa_printf(MSG_ERROR, "nl80211: %u interface(s) remain at " | |
10025 | "nl80211_global_deinit", | |
10026 | dl_list_len(&global->interfaces)); | |
10027 | } | |
36d84860 BG |
10028 | |
10029 | if (global->netlink) | |
10030 | netlink_deinit(global->netlink); | |
10031 | ||
276e2d67 BG |
10032 | nl_destroy_handles(&global->nl); |
10033 | ||
5f65e9f7 JB |
10034 | if (global->nl_event) |
10035 | nl80211_destroy_eloop_handle(&global->nl_event); | |
d6c9aab8 JB |
10036 | |
10037 | nl_cb_put(global->nl_cb); | |
2a7b66f5 | 10038 | |
c81eff1a BG |
10039 | if (global->ioctl_sock >= 0) |
10040 | close(global->ioctl_sock); | |
10041 | ||
f2ed8023 JM |
10042 | os_free(global); |
10043 | } | |
10044 | ||
10045 | ||
6859f1cb BG |
10046 | static const char * nl80211_get_radio_name(void *priv) |
10047 | { | |
10048 | struct i802_bss *bss = priv; | |
10049 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
10050 | return drv->phyname; | |
10051 | } | |
10052 | ||
10053 | ||
a6efc65d JM |
10054 | static int nl80211_pmkid(struct i802_bss *bss, int cmd, const u8 *bssid, |
10055 | const u8 *pmkid) | |
10056 | { | |
10057 | struct nl_msg *msg; | |
10058 | ||
10059 | msg = nlmsg_alloc(); | |
10060 | if (!msg) | |
10061 | return -ENOMEM; | |
10062 | ||
9fb04070 | 10063 | nl80211_cmd(bss->drv, msg, 0, cmd); |
a6efc65d JM |
10064 | |
10065 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, if_nametoindex(bss->ifname)); | |
10066 | if (pmkid) | |
10067 | NLA_PUT(msg, NL80211_ATTR_PMKID, 16, pmkid); | |
10068 | if (bssid) | |
10069 | NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid); | |
10070 | ||
10071 | return send_and_recv_msgs(bss->drv, msg, NULL, NULL); | |
10072 | nla_put_failure: | |
9e088e74 | 10073 | nlmsg_free(msg); |
a6efc65d JM |
10074 | return -ENOBUFS; |
10075 | } | |
10076 | ||
10077 | ||
10078 | static int nl80211_add_pmkid(void *priv, const u8 *bssid, const u8 *pmkid) | |
10079 | { | |
10080 | struct i802_bss *bss = priv; | |
10081 | wpa_printf(MSG_DEBUG, "nl80211: Add PMKID for " MACSTR, MAC2STR(bssid)); | |
10082 | return nl80211_pmkid(bss, NL80211_CMD_SET_PMKSA, bssid, pmkid); | |
10083 | } | |
10084 | ||
10085 | ||
10086 | static int nl80211_remove_pmkid(void *priv, const u8 *bssid, const u8 *pmkid) | |
10087 | { | |
10088 | struct i802_bss *bss = priv; | |
10089 | wpa_printf(MSG_DEBUG, "nl80211: Delete PMKID for " MACSTR, | |
10090 | MAC2STR(bssid)); | |
10091 | return nl80211_pmkid(bss, NL80211_CMD_DEL_PMKSA, bssid, pmkid); | |
10092 | } | |
10093 | ||
10094 | ||
10095 | static int nl80211_flush_pmkid(void *priv) | |
10096 | { | |
10097 | struct i802_bss *bss = priv; | |
10098 | wpa_printf(MSG_DEBUG, "nl80211: Flush PMKIDs"); | |
10099 | return nl80211_pmkid(bss, NL80211_CMD_FLUSH_PMKSA, NULL, NULL); | |
10100 | } | |
10101 | ||
10102 | ||
0185007c MK |
10103 | static void clean_survey_results(struct survey_results *survey_results) |
10104 | { | |
10105 | struct freq_survey *survey, *tmp; | |
10106 | ||
10107 | if (dl_list_empty(&survey_results->survey_list)) | |
10108 | return; | |
10109 | ||
10110 | dl_list_for_each_safe(survey, tmp, &survey_results->survey_list, | |
10111 | struct freq_survey, list) { | |
10112 | dl_list_del(&survey->list); | |
10113 | os_free(survey); | |
10114 | } | |
10115 | } | |
10116 | ||
10117 | ||
10118 | static void add_survey(struct nlattr **sinfo, u32 ifidx, | |
10119 | struct dl_list *survey_list) | |
10120 | { | |
10121 | struct freq_survey *survey; | |
10122 | ||
10123 | survey = os_zalloc(sizeof(struct freq_survey)); | |
10124 | if (!survey) | |
10125 | return; | |
10126 | ||
10127 | survey->ifidx = ifidx; | |
10128 | survey->freq = nla_get_u32(sinfo[NL80211_SURVEY_INFO_FREQUENCY]); | |
10129 | survey->filled = 0; | |
10130 | ||
10131 | if (sinfo[NL80211_SURVEY_INFO_NOISE]) { | |
10132 | survey->nf = (int8_t) | |
10133 | nla_get_u8(sinfo[NL80211_SURVEY_INFO_NOISE]); | |
10134 | survey->filled |= SURVEY_HAS_NF; | |
10135 | } | |
10136 | ||
10137 | if (sinfo[NL80211_SURVEY_INFO_CHANNEL_TIME]) { | |
10138 | survey->channel_time = | |
10139 | nla_get_u64(sinfo[NL80211_SURVEY_INFO_CHANNEL_TIME]); | |
10140 | survey->filled |= SURVEY_HAS_CHAN_TIME; | |
10141 | } | |
10142 | ||
10143 | if (sinfo[NL80211_SURVEY_INFO_CHANNEL_TIME_BUSY]) { | |
10144 | survey->channel_time_busy = | |
10145 | nla_get_u64(sinfo[NL80211_SURVEY_INFO_CHANNEL_TIME_BUSY]); | |
10146 | survey->filled |= SURVEY_HAS_CHAN_TIME_BUSY; | |
10147 | } | |
10148 | ||
10149 | if (sinfo[NL80211_SURVEY_INFO_CHANNEL_TIME_RX]) { | |
10150 | survey->channel_time_rx = | |
10151 | nla_get_u64(sinfo[NL80211_SURVEY_INFO_CHANNEL_TIME_RX]); | |
10152 | survey->filled |= SURVEY_HAS_CHAN_TIME_RX; | |
10153 | } | |
10154 | ||
10155 | if (sinfo[NL80211_SURVEY_INFO_CHANNEL_TIME_TX]) { | |
10156 | survey->channel_time_tx = | |
10157 | nla_get_u64(sinfo[NL80211_SURVEY_INFO_CHANNEL_TIME_TX]); | |
10158 | survey->filled |= SURVEY_HAS_CHAN_TIME_TX; | |
10159 | } | |
10160 | ||
10161 | wpa_printf(MSG_DEBUG, "nl80211: Freq survey dump event (freq=%d MHz noise=%d channel_time=%ld busy_time=%ld tx_time=%ld rx_time=%ld filled=%04x)", | |
10162 | survey->freq, | |
10163 | survey->nf, | |
10164 | (unsigned long int) survey->channel_time, | |
10165 | (unsigned long int) survey->channel_time_busy, | |
10166 | (unsigned long int) survey->channel_time_tx, | |
10167 | (unsigned long int) survey->channel_time_rx, | |
10168 | survey->filled); | |
10169 | ||
10170 | dl_list_add_tail(survey_list, &survey->list); | |
10171 | } | |
10172 | ||
10173 | ||
10174 | static int check_survey_ok(struct nlattr **sinfo, u32 surveyed_freq, | |
10175 | unsigned int freq_filter) | |
10176 | { | |
10177 | if (!freq_filter) | |
10178 | return 1; | |
10179 | ||
10180 | return freq_filter == surveyed_freq; | |
10181 | } | |
10182 | ||
10183 | ||
10184 | static int survey_handler(struct nl_msg *msg, void *arg) | |
10185 | { | |
10186 | struct nlattr *tb[NL80211_ATTR_MAX + 1]; | |
10187 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); | |
10188 | struct nlattr *sinfo[NL80211_SURVEY_INFO_MAX + 1]; | |
10189 | struct survey_results *survey_results; | |
10190 | u32 surveyed_freq = 0; | |
10191 | u32 ifidx; | |
10192 | ||
10193 | static struct nla_policy survey_policy[NL80211_SURVEY_INFO_MAX + 1] = { | |
10194 | [NL80211_SURVEY_INFO_FREQUENCY] = { .type = NLA_U32 }, | |
10195 | [NL80211_SURVEY_INFO_NOISE] = { .type = NLA_U8 }, | |
10196 | }; | |
10197 | ||
10198 | survey_results = (struct survey_results *) arg; | |
10199 | ||
10200 | nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), | |
10201 | genlmsg_attrlen(gnlh, 0), NULL); | |
10202 | ||
10203 | ifidx = nla_get_u32(tb[NL80211_ATTR_IFINDEX]); | |
10204 | ||
10205 | if (!tb[NL80211_ATTR_SURVEY_INFO]) | |
10206 | return NL_SKIP; | |
10207 | ||
10208 | if (nla_parse_nested(sinfo, NL80211_SURVEY_INFO_MAX, | |
10209 | tb[NL80211_ATTR_SURVEY_INFO], | |
10210 | survey_policy)) | |
10211 | return NL_SKIP; | |
10212 | ||
10213 | if (!sinfo[NL80211_SURVEY_INFO_FREQUENCY]) { | |
10214 | wpa_printf(MSG_ERROR, "nl80211: Invalid survey data"); | |
10215 | return NL_SKIP; | |
10216 | } | |
10217 | ||
10218 | surveyed_freq = nla_get_u32(sinfo[NL80211_SURVEY_INFO_FREQUENCY]); | |
10219 | ||
10220 | if (!check_survey_ok(sinfo, surveyed_freq, | |
10221 | survey_results->freq_filter)) | |
10222 | return NL_SKIP; | |
10223 | ||
10224 | if (survey_results->freq_filter && | |
10225 | survey_results->freq_filter != surveyed_freq) { | |
10226 | wpa_printf(MSG_EXCESSIVE, "nl80211: Ignoring survey data for freq %d MHz", | |
10227 | surveyed_freq); | |
10228 | return NL_SKIP; | |
10229 | } | |
10230 | ||
10231 | add_survey(sinfo, ifidx, &survey_results->survey_list); | |
10232 | ||
10233 | return NL_SKIP; | |
10234 | } | |
10235 | ||
10236 | ||
10237 | static int wpa_driver_nl80211_get_survey(void *priv, unsigned int freq) | |
10238 | { | |
10239 | struct i802_bss *bss = priv; | |
10240 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
10241 | struct nl_msg *msg; | |
10242 | int err = -ENOBUFS; | |
10243 | union wpa_event_data data; | |
10244 | struct survey_results *survey_results; | |
10245 | ||
10246 | os_memset(&data, 0, sizeof(data)); | |
10247 | survey_results = &data.survey_results; | |
10248 | ||
10249 | dl_list_init(&survey_results->survey_list); | |
10250 | ||
10251 | msg = nlmsg_alloc(); | |
10252 | if (!msg) | |
10253 | goto nla_put_failure; | |
10254 | ||
10255 | nl80211_cmd(drv, msg, NLM_F_DUMP, NL80211_CMD_GET_SURVEY); | |
10256 | ||
10257 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, drv->ifindex); | |
10258 | ||
10259 | if (freq) | |
10260 | data.survey_results.freq_filter = freq; | |
10261 | ||
10262 | do { | |
10263 | wpa_printf(MSG_DEBUG, "nl80211: Fetch survey data"); | |
10264 | err = send_and_recv_msgs(drv, msg, survey_handler, | |
10265 | survey_results); | |
10266 | } while (err > 0); | |
10267 | ||
10268 | if (err) { | |
10269 | wpa_printf(MSG_ERROR, "nl80211: Failed to process survey data"); | |
10270 | goto out_clean; | |
10271 | } | |
10272 | ||
10273 | wpa_supplicant_event(drv->ctx, EVENT_SURVEY, &data); | |
10274 | ||
10275 | out_clean: | |
10276 | clean_survey_results(survey_results); | |
10277 | nla_put_failure: | |
10278 | return err; | |
10279 | } | |
10280 | ||
10281 | ||
b14a210c JB |
10282 | static void nl80211_set_rekey_info(void *priv, const u8 *kek, const u8 *kck, |
10283 | const u8 *replay_ctr) | |
10284 | { | |
10285 | struct i802_bss *bss = priv; | |
10286 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
10287 | struct nlattr *replay_nested; | |
10288 | struct nl_msg *msg; | |
10289 | ||
10290 | msg = nlmsg_alloc(); | |
10291 | if (!msg) | |
10292 | return; | |
10293 | ||
9fb04070 | 10294 | nl80211_cmd(drv, msg, 0, NL80211_CMD_SET_REKEY_OFFLOAD); |
b14a210c JB |
10295 | |
10296 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, bss->ifindex); | |
10297 | ||
10298 | replay_nested = nla_nest_start(msg, NL80211_ATTR_REKEY_DATA); | |
10299 | if (!replay_nested) | |
10300 | goto nla_put_failure; | |
10301 | ||
10302 | NLA_PUT(msg, NL80211_REKEY_DATA_KEK, NL80211_KEK_LEN, kek); | |
10303 | NLA_PUT(msg, NL80211_REKEY_DATA_KCK, NL80211_KCK_LEN, kck); | |
10304 | NLA_PUT(msg, NL80211_REKEY_DATA_REPLAY_CTR, NL80211_REPLAY_CTR_LEN, | |
10305 | replay_ctr); | |
10306 | ||
10307 | nla_nest_end(msg, replay_nested); | |
10308 | ||
10309 | send_and_recv_msgs(drv, msg, NULL, NULL); | |
10310 | return; | |
10311 | nla_put_failure: | |
10312 | nlmsg_free(msg); | |
10313 | } | |
10314 | ||
10315 | ||
39718852 JB |
10316 | static void nl80211_send_null_frame(struct i802_bss *bss, const u8 *own_addr, |
10317 | const u8 *addr, int qos) | |
bcf24348 | 10318 | { |
39718852 JB |
10319 | /* send data frame to poll STA and check whether |
10320 | * this frame is ACKed */ | |
bcf24348 JB |
10321 | struct { |
10322 | struct ieee80211_hdr hdr; | |
10323 | u16 qos_ctl; | |
10324 | } STRUCT_PACKED nulldata; | |
10325 | size_t size; | |
10326 | ||
10327 | /* Send data frame to poll STA and check whether this frame is ACKed */ | |
10328 | ||
10329 | os_memset(&nulldata, 0, sizeof(nulldata)); | |
10330 | ||
10331 | if (qos) { | |
10332 | nulldata.hdr.frame_control = | |
10333 | IEEE80211_FC(WLAN_FC_TYPE_DATA, | |
10334 | WLAN_FC_STYPE_QOS_NULL); | |
10335 | size = sizeof(nulldata); | |
10336 | } else { | |
10337 | nulldata.hdr.frame_control = | |
10338 | IEEE80211_FC(WLAN_FC_TYPE_DATA, | |
10339 | WLAN_FC_STYPE_NULLFUNC); | |
10340 | size = sizeof(struct ieee80211_hdr); | |
10341 | } | |
10342 | ||
10343 | nulldata.hdr.frame_control |= host_to_le16(WLAN_FC_FROMDS); | |
10344 | os_memcpy(nulldata.hdr.IEEE80211_DA_FROMDS, addr, ETH_ALEN); | |
10345 | os_memcpy(nulldata.hdr.IEEE80211_BSSID_FROMDS, own_addr, ETH_ALEN); | |
10346 | os_memcpy(nulldata.hdr.IEEE80211_SA_FROMDS, own_addr, ETH_ALEN); | |
10347 | ||
9ebce9c5 JM |
10348 | if (wpa_driver_nl80211_send_mlme(bss, (u8 *) &nulldata, size, 0, 0, 0, |
10349 | 0, 0) < 0) | |
bcf24348 JB |
10350 | wpa_printf(MSG_DEBUG, "nl80211_send_null_frame: Failed to " |
10351 | "send poll frame"); | |
10352 | } | |
10353 | ||
39718852 JB |
10354 | static void nl80211_poll_client(void *priv, const u8 *own_addr, const u8 *addr, |
10355 | int qos) | |
10356 | { | |
10357 | struct i802_bss *bss = priv; | |
10358 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
10359 | struct nl_msg *msg; | |
10360 | ||
10361 | if (!drv->poll_command_supported) { | |
10362 | nl80211_send_null_frame(bss, own_addr, addr, qos); | |
10363 | return; | |
10364 | } | |
10365 | ||
10366 | msg = nlmsg_alloc(); | |
10367 | if (!msg) | |
10368 | return; | |
10369 | ||
10370 | nl80211_cmd(drv, msg, 0, NL80211_CMD_PROBE_CLIENT); | |
10371 | ||
10372 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, bss->ifindex); | |
10373 | NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, addr); | |
10374 | ||
10375 | send_and_recv_msgs(drv, msg, NULL, NULL); | |
10376 | return; | |
10377 | nla_put_failure: | |
10378 | nlmsg_free(msg); | |
10379 | } | |
10380 | ||
bcf24348 | 10381 | |
29f338af JM |
10382 | static int nl80211_set_power_save(struct i802_bss *bss, int enabled) |
10383 | { | |
10384 | struct nl_msg *msg; | |
10385 | ||
10386 | msg = nlmsg_alloc(); | |
10387 | if (!msg) | |
10388 | return -ENOMEM; | |
10389 | ||
10390 | nl80211_cmd(bss->drv, msg, 0, NL80211_CMD_SET_POWER_SAVE); | |
10391 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, bss->ifindex); | |
10392 | NLA_PUT_U32(msg, NL80211_ATTR_PS_STATE, | |
10393 | enabled ? NL80211_PS_ENABLED : NL80211_PS_DISABLED); | |
10394 | return send_and_recv_msgs(bss->drv, msg, NULL, NULL); | |
10395 | nla_put_failure: | |
10396 | nlmsg_free(msg); | |
10397 | return -ENOBUFS; | |
10398 | } | |
10399 | ||
10400 | ||
10401 | static int nl80211_set_p2p_powersave(void *priv, int legacy_ps, int opp_ps, | |
10402 | int ctwindow) | |
10403 | { | |
10404 | struct i802_bss *bss = priv; | |
10405 | ||
10406 | wpa_printf(MSG_DEBUG, "nl80211: set_p2p_powersave (legacy_ps=%d " | |
10407 | "opp_ps=%d ctwindow=%d)", legacy_ps, opp_ps, ctwindow); | |
10408 | ||
10409 | if (opp_ps != -1 || ctwindow != -1) | |
10410 | return -1; /* Not yet supported */ | |
10411 | ||
10412 | if (legacy_ps == -1) | |
10413 | return 0; | |
10414 | if (legacy_ps != 0 && legacy_ps != 1) | |
10415 | return -1; /* Not yet supported */ | |
10416 | ||
10417 | return nl80211_set_power_save(bss, legacy_ps); | |
10418 | } | |
10419 | ||
10420 | ||
04e8003c JD |
10421 | static int nl80211_start_radar_detection(void *priv, |
10422 | struct hostapd_freq_params *freq) | |
f90e9c1c SW |
10423 | { |
10424 | struct i802_bss *bss = priv; | |
10425 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
10426 | struct nl_msg *msg; | |
10427 | int ret; | |
10428 | ||
04e8003c JD |
10429 | wpa_printf(MSG_DEBUG, "nl80211: Start radar detection (CAC) %d MHz (ht_enabled=%d, vht_enabled=%d, bandwidth=%d MHz, cf1=%d MHz, cf2=%d MHz)", |
10430 | freq->freq, freq->ht_enabled, freq->vht_enabled, | |
10431 | freq->bandwidth, freq->center_freq1, freq->center_freq2); | |
10432 | ||
f90e9c1c SW |
10433 | if (!(drv->capa.flags & WPA_DRIVER_FLAGS_RADAR)) { |
10434 | wpa_printf(MSG_DEBUG, "nl80211: Driver does not support radar " | |
10435 | "detection"); | |
10436 | return -1; | |
10437 | } | |
10438 | ||
10439 | msg = nlmsg_alloc(); | |
10440 | if (!msg) | |
10441 | return -1; | |
10442 | ||
10443 | nl80211_cmd(bss->drv, msg, 0, NL80211_CMD_RADAR_DETECT); | |
10444 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, drv->ifindex); | |
04e8003c | 10445 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_FREQ, freq->freq); |
f90e9c1c | 10446 | |
04e8003c JD |
10447 | if (freq->vht_enabled) { |
10448 | switch (freq->bandwidth) { | |
10449 | case 20: | |
10450 | NLA_PUT_U32(msg, NL80211_ATTR_CHANNEL_WIDTH, | |
10451 | NL80211_CHAN_WIDTH_20); | |
10452 | break; | |
10453 | case 40: | |
10454 | NLA_PUT_U32(msg, NL80211_ATTR_CHANNEL_WIDTH, | |
10455 | NL80211_CHAN_WIDTH_40); | |
10456 | break; | |
10457 | case 80: | |
10458 | if (freq->center_freq2) | |
10459 | NLA_PUT_U32(msg, NL80211_ATTR_CHANNEL_WIDTH, | |
10460 | NL80211_CHAN_WIDTH_80P80); | |
10461 | else | |
10462 | NLA_PUT_U32(msg, NL80211_ATTR_CHANNEL_WIDTH, | |
10463 | NL80211_CHAN_WIDTH_80); | |
10464 | break; | |
10465 | case 160: | |
10466 | NLA_PUT_U32(msg, NL80211_ATTR_CHANNEL_WIDTH, | |
10467 | NL80211_CHAN_WIDTH_160); | |
10468 | break; | |
10469 | default: | |
10470 | return -1; | |
10471 | } | |
10472 | NLA_PUT_U32(msg, NL80211_ATTR_CENTER_FREQ1, freq->center_freq1); | |
10473 | if (freq->center_freq2) | |
10474 | NLA_PUT_U32(msg, NL80211_ATTR_CENTER_FREQ2, | |
10475 | freq->center_freq2); | |
10476 | } else if (freq->ht_enabled) { | |
10477 | switch (freq->sec_channel_offset) { | |
10478 | case -1: | |
10479 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE, | |
10480 | NL80211_CHAN_HT40MINUS); | |
10481 | break; | |
10482 | case 1: | |
10483 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE, | |
10484 | NL80211_CHAN_HT40PLUS); | |
10485 | break; | |
10486 | default: | |
10487 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE, | |
10488 | NL80211_CHAN_HT20); | |
10489 | break; | |
10490 | } | |
10491 | } | |
f90e9c1c SW |
10492 | |
10493 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); | |
10494 | if (ret == 0) | |
10495 | return 0; | |
10496 | wpa_printf(MSG_DEBUG, "nl80211: Failed to start radar detection: " | |
10497 | "%d (%s)", ret, strerror(-ret)); | |
10498 | nla_put_failure: | |
10499 | return -1; | |
10500 | } | |
10501 | ||
03ea1786 AN |
10502 | #ifdef CONFIG_TDLS |
10503 | ||
10504 | static int nl80211_send_tdls_mgmt(void *priv, const u8 *dst, u8 action_code, | |
10505 | u8 dialog_token, u16 status_code, | |
10506 | const u8 *buf, size_t len) | |
10507 | { | |
10508 | struct i802_bss *bss = priv; | |
10509 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
10510 | struct nl_msg *msg; | |
10511 | ||
10512 | if (!(drv->capa.flags & WPA_DRIVER_FLAGS_TDLS_SUPPORT)) | |
10513 | return -EOPNOTSUPP; | |
10514 | ||
10515 | if (!dst) | |
10516 | return -EINVAL; | |
10517 | ||
10518 | msg = nlmsg_alloc(); | |
10519 | if (!msg) | |
10520 | return -ENOMEM; | |
10521 | ||
10522 | nl80211_cmd(drv, msg, 0, NL80211_CMD_TDLS_MGMT); | |
10523 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, drv->ifindex); | |
10524 | NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, dst); | |
10525 | NLA_PUT_U8(msg, NL80211_ATTR_TDLS_ACTION, action_code); | |
10526 | NLA_PUT_U8(msg, NL80211_ATTR_TDLS_DIALOG_TOKEN, dialog_token); | |
10527 | NLA_PUT_U16(msg, NL80211_ATTR_STATUS_CODE, status_code); | |
10528 | NLA_PUT(msg, NL80211_ATTR_IE, len, buf); | |
10529 | ||
10530 | return send_and_recv_msgs(drv, msg, NULL, NULL); | |
10531 | ||
10532 | nla_put_failure: | |
10533 | nlmsg_free(msg); | |
10534 | return -ENOBUFS; | |
10535 | } | |
10536 | ||
10537 | ||
10538 | static int nl80211_tdls_oper(void *priv, enum tdls_oper oper, const u8 *peer) | |
10539 | { | |
10540 | struct i802_bss *bss = priv; | |
10541 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
10542 | struct nl_msg *msg; | |
10543 | enum nl80211_tdls_operation nl80211_oper; | |
10544 | ||
10545 | if (!(drv->capa.flags & WPA_DRIVER_FLAGS_TDLS_SUPPORT)) | |
10546 | return -EOPNOTSUPP; | |
10547 | ||
10548 | switch (oper) { | |
10549 | case TDLS_DISCOVERY_REQ: | |
10550 | nl80211_oper = NL80211_TDLS_DISCOVERY_REQ; | |
10551 | break; | |
10552 | case TDLS_SETUP: | |
10553 | nl80211_oper = NL80211_TDLS_SETUP; | |
10554 | break; | |
10555 | case TDLS_TEARDOWN: | |
10556 | nl80211_oper = NL80211_TDLS_TEARDOWN; | |
10557 | break; | |
10558 | case TDLS_ENABLE_LINK: | |
10559 | nl80211_oper = NL80211_TDLS_ENABLE_LINK; | |
10560 | break; | |
10561 | case TDLS_DISABLE_LINK: | |
10562 | nl80211_oper = NL80211_TDLS_DISABLE_LINK; | |
10563 | break; | |
10564 | case TDLS_ENABLE: | |
10565 | return 0; | |
10566 | case TDLS_DISABLE: | |
10567 | return 0; | |
10568 | default: | |
10569 | return -EINVAL; | |
10570 | } | |
10571 | ||
10572 | msg = nlmsg_alloc(); | |
10573 | if (!msg) | |
10574 | return -ENOMEM; | |
10575 | ||
10576 | nl80211_cmd(drv, msg, 0, NL80211_CMD_TDLS_OPER); | |
10577 | NLA_PUT_U8(msg, NL80211_ATTR_TDLS_OPERATION, nl80211_oper); | |
10578 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, drv->ifindex); | |
10579 | NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, peer); | |
10580 | ||
10581 | return send_and_recv_msgs(drv, msg, NULL, NULL); | |
10582 | ||
10583 | nla_put_failure: | |
10584 | nlmsg_free(msg); | |
10585 | return -ENOBUFS; | |
10586 | } | |
10587 | ||
10588 | #endif /* CONFIG TDLS */ | |
10589 | ||
10590 | ||
216eede8 DS |
10591 | #ifdef ANDROID |
10592 | ||
10593 | typedef struct android_wifi_priv_cmd { | |
10594 | char *buf; | |
10595 | int used_len; | |
10596 | int total_len; | |
10597 | } android_wifi_priv_cmd; | |
10598 | ||
10599 | static int drv_errors = 0; | |
10600 | ||
10601 | static void wpa_driver_send_hang_msg(struct wpa_driver_nl80211_data *drv) | |
10602 | { | |
10603 | drv_errors++; | |
10604 | if (drv_errors > DRV_NUMBER_SEQUENTIAL_ERRORS) { | |
10605 | drv_errors = 0; | |
10606 | wpa_msg(drv->ctx, MSG_INFO, WPA_EVENT_DRIVER_STATE "HANGED"); | |
10607 | } | |
10608 | } | |
10609 | ||
10610 | ||
10611 | static int android_priv_cmd(struct i802_bss *bss, const char *cmd) | |
10612 | { | |
10613 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
10614 | struct ifreq ifr; | |
10615 | android_wifi_priv_cmd priv_cmd; | |
10616 | char buf[MAX_DRV_CMD_SIZE]; | |
10617 | int ret; | |
10618 | ||
10619 | os_memset(&ifr, 0, sizeof(ifr)); | |
10620 | os_memset(&priv_cmd, 0, sizeof(priv_cmd)); | |
10621 | os_strlcpy(ifr.ifr_name, bss->ifname, IFNAMSIZ); | |
10622 | ||
10623 | os_memset(buf, 0, sizeof(buf)); | |
10624 | os_strlcpy(buf, cmd, sizeof(buf)); | |
10625 | ||
10626 | priv_cmd.buf = buf; | |
10627 | priv_cmd.used_len = sizeof(buf); | |
10628 | priv_cmd.total_len = sizeof(buf); | |
10629 | ifr.ifr_data = &priv_cmd; | |
10630 | ||
10631 | ret = ioctl(drv->global->ioctl_sock, SIOCDEVPRIVATE + 1, &ifr); | |
10632 | if (ret < 0) { | |
10633 | wpa_printf(MSG_ERROR, "%s: failed to issue private commands", | |
10634 | __func__); | |
10635 | wpa_driver_send_hang_msg(drv); | |
10636 | return ret; | |
10637 | } | |
10638 | ||
10639 | drv_errors = 0; | |
10640 | return 0; | |
10641 | } | |
10642 | ||
10643 | ||
10644 | static int android_pno_start(struct i802_bss *bss, | |
10645 | struct wpa_driver_scan_params *params) | |
10646 | { | |
10647 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
10648 | struct ifreq ifr; | |
10649 | android_wifi_priv_cmd priv_cmd; | |
10650 | int ret = 0, i = 0, bp; | |
10651 | char buf[WEXT_PNO_MAX_COMMAND_SIZE]; | |
10652 | ||
10653 | bp = WEXT_PNOSETUP_HEADER_SIZE; | |
10654 | os_memcpy(buf, WEXT_PNOSETUP_HEADER, bp); | |
10655 | buf[bp++] = WEXT_PNO_TLV_PREFIX; | |
10656 | buf[bp++] = WEXT_PNO_TLV_VERSION; | |
10657 | buf[bp++] = WEXT_PNO_TLV_SUBVERSION; | |
10658 | buf[bp++] = WEXT_PNO_TLV_RESERVED; | |
10659 | ||
10660 | while (i < WEXT_PNO_AMOUNT && (size_t) i < params->num_ssids) { | |
10661 | /* Check that there is enough space needed for 1 more SSID, the | |
10662 | * other sections and null termination */ | |
10663 | if ((bp + WEXT_PNO_SSID_HEADER_SIZE + MAX_SSID_LEN + | |
10664 | WEXT_PNO_NONSSID_SECTIONS_SIZE + 1) >= (int) sizeof(buf)) | |
10665 | break; | |
10666 | wpa_hexdump_ascii(MSG_DEBUG, "For PNO Scan", | |
a97bde0a JM |
10667 | params->ssids[i].ssid, |
10668 | params->ssids[i].ssid_len); | |
216eede8 DS |
10669 | buf[bp++] = WEXT_PNO_SSID_SECTION; |
10670 | buf[bp++] = params->ssids[i].ssid_len; | |
10671 | os_memcpy(&buf[bp], params->ssids[i].ssid, | |
10672 | params->ssids[i].ssid_len); | |
10673 | bp += params->ssids[i].ssid_len; | |
10674 | i++; | |
10675 | } | |
10676 | ||
10677 | buf[bp++] = WEXT_PNO_SCAN_INTERVAL_SECTION; | |
10678 | os_snprintf(&buf[bp], WEXT_PNO_SCAN_INTERVAL_LENGTH + 1, "%x", | |
10679 | WEXT_PNO_SCAN_INTERVAL); | |
10680 | bp += WEXT_PNO_SCAN_INTERVAL_LENGTH; | |
10681 | ||
10682 | buf[bp++] = WEXT_PNO_REPEAT_SECTION; | |
10683 | os_snprintf(&buf[bp], WEXT_PNO_REPEAT_LENGTH + 1, "%x", | |
10684 | WEXT_PNO_REPEAT); | |
10685 | bp += WEXT_PNO_REPEAT_LENGTH; | |
10686 | ||
10687 | buf[bp++] = WEXT_PNO_MAX_REPEAT_SECTION; | |
10688 | os_snprintf(&buf[bp], WEXT_PNO_MAX_REPEAT_LENGTH + 1, "%x", | |
10689 | WEXT_PNO_MAX_REPEAT); | |
10690 | bp += WEXT_PNO_MAX_REPEAT_LENGTH + 1; | |
10691 | ||
10692 | memset(&ifr, 0, sizeof(ifr)); | |
10693 | memset(&priv_cmd, 0, sizeof(priv_cmd)); | |
24f051eb | 10694 | os_strlcpy(ifr.ifr_name, bss->ifname, IFNAMSIZ); |
216eede8 DS |
10695 | |
10696 | priv_cmd.buf = buf; | |
10697 | priv_cmd.used_len = bp; | |
10698 | priv_cmd.total_len = bp; | |
10699 | ifr.ifr_data = &priv_cmd; | |
10700 | ||
10701 | ret = ioctl(drv->global->ioctl_sock, SIOCDEVPRIVATE + 1, &ifr); | |
10702 | ||
10703 | if (ret < 0) { | |
10704 | wpa_printf(MSG_ERROR, "ioctl[SIOCSIWPRIV] (pnosetup): %d", | |
10705 | ret); | |
10706 | wpa_driver_send_hang_msg(drv); | |
10707 | return ret; | |
10708 | } | |
10709 | ||
10710 | drv_errors = 0; | |
10711 | ||
10712 | return android_priv_cmd(bss, "PNOFORCE 1"); | |
10713 | } | |
10714 | ||
10715 | ||
10716 | static int android_pno_stop(struct i802_bss *bss) | |
10717 | { | |
10718 | return android_priv_cmd(bss, "PNOFORCE 0"); | |
10719 | } | |
10720 | ||
10721 | #endif /* ANDROID */ | |
10722 | ||
10723 | ||
9ebce9c5 JM |
10724 | static int driver_nl80211_set_key(const char *ifname, void *priv, |
10725 | enum wpa_alg alg, const u8 *addr, | |
10726 | int key_idx, int set_tx, | |
10727 | const u8 *seq, size_t seq_len, | |
10728 | const u8 *key, size_t key_len) | |
10729 | { | |
10730 | struct i802_bss *bss = priv; | |
10731 | return wpa_driver_nl80211_set_key(ifname, bss, alg, addr, key_idx, | |
10732 | set_tx, seq, seq_len, key, key_len); | |
10733 | } | |
10734 | ||
10735 | ||
10736 | static int driver_nl80211_scan2(void *priv, | |
10737 | struct wpa_driver_scan_params *params) | |
10738 | { | |
10739 | struct i802_bss *bss = priv; | |
10740 | return wpa_driver_nl80211_scan(bss, params); | |
10741 | } | |
10742 | ||
10743 | ||
10744 | static int driver_nl80211_deauthenticate(void *priv, const u8 *addr, | |
10745 | int reason_code) | |
10746 | { | |
10747 | struct i802_bss *bss = priv; | |
10748 | return wpa_driver_nl80211_deauthenticate(bss, addr, reason_code); | |
10749 | } | |
10750 | ||
10751 | ||
10752 | static int driver_nl80211_authenticate(void *priv, | |
10753 | struct wpa_driver_auth_params *params) | |
10754 | { | |
10755 | struct i802_bss *bss = priv; | |
10756 | return wpa_driver_nl80211_authenticate(bss, params); | |
10757 | } | |
10758 | ||
10759 | ||
10760 | static void driver_nl80211_deinit(void *priv) | |
10761 | { | |
10762 | struct i802_bss *bss = priv; | |
10763 | wpa_driver_nl80211_deinit(bss); | |
10764 | } | |
10765 | ||
10766 | ||
10767 | static int driver_nl80211_if_remove(void *priv, enum wpa_driver_if_type type, | |
10768 | const char *ifname) | |
10769 | { | |
10770 | struct i802_bss *bss = priv; | |
10771 | return wpa_driver_nl80211_if_remove(bss, type, ifname); | |
10772 | } | |
10773 | ||
10774 | ||
10775 | static int driver_nl80211_send_mlme(void *priv, const u8 *data, | |
10776 | size_t data_len, int noack) | |
10777 | { | |
10778 | struct i802_bss *bss = priv; | |
10779 | return wpa_driver_nl80211_send_mlme(bss, data, data_len, noack, | |
10780 | 0, 0, 0, 0); | |
10781 | } | |
10782 | ||
10783 | ||
10784 | static int driver_nl80211_sta_remove(void *priv, const u8 *addr) | |
10785 | { | |
10786 | struct i802_bss *bss = priv; | |
10787 | return wpa_driver_nl80211_sta_remove(bss, addr); | |
10788 | } | |
10789 | ||
10790 | ||
10791 | #if defined(HOSTAPD) || defined(CONFIG_AP) | |
10792 | static int driver_nl80211_set_sta_vlan(void *priv, const u8 *addr, | |
10793 | const char *ifname, int vlan_id) | |
10794 | { | |
10795 | struct i802_bss *bss = priv; | |
10796 | return i802_set_sta_vlan(bss, addr, ifname, vlan_id); | |
10797 | } | |
10798 | #endif /* HOSTAPD || CONFIG_AP */ | |
10799 | ||
10800 | ||
10801 | static int driver_nl80211_read_sta_data(void *priv, | |
10802 | struct hostap_sta_driver_data *data, | |
10803 | const u8 *addr) | |
10804 | { | |
10805 | struct i802_bss *bss = priv; | |
10806 | return i802_read_sta_data(bss, data, addr); | |
10807 | } | |
10808 | ||
10809 | ||
10810 | static int driver_nl80211_send_action(void *priv, unsigned int freq, | |
10811 | unsigned int wait_time, | |
10812 | const u8 *dst, const u8 *src, | |
10813 | const u8 *bssid, | |
10814 | const u8 *data, size_t data_len, | |
10815 | int no_cck) | |
10816 | { | |
10817 | struct i802_bss *bss = priv; | |
10818 | return wpa_driver_nl80211_send_action(bss, freq, wait_time, dst, src, | |
10819 | bssid, data, data_len, no_cck); | |
10820 | } | |
10821 | ||
10822 | ||
10823 | static int driver_nl80211_probe_req_report(void *priv, int report) | |
10824 | { | |
10825 | struct i802_bss *bss = priv; | |
10826 | return wpa_driver_nl80211_probe_req_report(bss, report); | |
10827 | } | |
10828 | ||
10829 | ||
6a1ce395 DG |
10830 | static int wpa_driver_nl80211_update_ft_ies(void *priv, const u8 *md, |
10831 | const u8 *ies, size_t ies_len) | |
10832 | { | |
10833 | int ret; | |
10834 | struct nl_msg *msg; | |
10835 | struct i802_bss *bss = priv; | |
10836 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
10837 | u16 mdid = WPA_GET_LE16(md); | |
10838 | ||
10839 | msg = nlmsg_alloc(); | |
10840 | if (!msg) | |
10841 | return -ENOMEM; | |
10842 | ||
10843 | wpa_printf(MSG_DEBUG, "nl80211: Updating FT IEs"); | |
10844 | nl80211_cmd(drv, msg, 0, NL80211_CMD_UPDATE_FT_IES); | |
10845 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, drv->ifindex); | |
10846 | NLA_PUT(msg, NL80211_ATTR_IE, ies_len, ies); | |
10847 | NLA_PUT_U16(msg, NL80211_ATTR_MDID, mdid); | |
10848 | ||
10849 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); | |
10850 | if (ret) { | |
10851 | wpa_printf(MSG_DEBUG, "nl80211: update_ft_ies failed " | |
10852 | "err=%d (%s)", ret, strerror(-ret)); | |
10853 | } | |
10854 | ||
10855 | return ret; | |
10856 | ||
10857 | nla_put_failure: | |
10858 | nlmsg_free(msg); | |
10859 | return -ENOBUFS; | |
10860 | } | |
10861 | ||
10862 | ||
597b94f5 AS |
10863 | const u8 * wpa_driver_nl80211_get_macaddr(void *priv) |
10864 | { | |
10865 | struct i802_bss *bss = priv; | |
10866 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
10867 | ||
10868 | if (drv->nlmode != NL80211_IFTYPE_P2P_DEVICE) | |
10869 | return NULL; | |
10870 | ||
10871 | return bss->addr; | |
10872 | } | |
10873 | ||
10874 | ||
a771c07d JM |
10875 | static const char * scan_state_str(enum scan_states scan_state) |
10876 | { | |
10877 | switch (scan_state) { | |
10878 | case NO_SCAN: | |
10879 | return "NO_SCAN"; | |
10880 | case SCAN_REQUESTED: | |
10881 | return "SCAN_REQUESTED"; | |
10882 | case SCAN_STARTED: | |
10883 | return "SCAN_STARTED"; | |
10884 | case SCAN_COMPLETED: | |
10885 | return "SCAN_COMPLETED"; | |
10886 | case SCAN_ABORTED: | |
10887 | return "SCAN_ABORTED"; | |
10888 | case SCHED_SCAN_STARTED: | |
10889 | return "SCHED_SCAN_STARTED"; | |
10890 | case SCHED_SCAN_STOPPED: | |
10891 | return "SCHED_SCAN_STOPPED"; | |
10892 | case SCHED_SCAN_RESULTS: | |
10893 | return "SCHED_SCAN_RESULTS"; | |
10894 | } | |
10895 | ||
10896 | return "??"; | |
10897 | } | |
10898 | ||
10899 | ||
10900 | static int wpa_driver_nl80211_status(void *priv, char *buf, size_t buflen) | |
10901 | { | |
10902 | struct i802_bss *bss = priv; | |
10903 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
10904 | int res; | |
10905 | char *pos, *end; | |
10906 | ||
10907 | pos = buf; | |
10908 | end = buf + buflen; | |
10909 | ||
10910 | res = os_snprintf(pos, end - pos, | |
10911 | "ifindex=%d\n" | |
10912 | "ifname=%s\n" | |
10913 | "brname=%s\n" | |
10914 | "addr=" MACSTR "\n" | |
10915 | "freq=%d\n" | |
10916 | "%s%s%s%s%s", | |
10917 | bss->ifindex, | |
10918 | bss->ifname, | |
10919 | bss->brname, | |
10920 | MAC2STR(bss->addr), | |
10921 | bss->freq, | |
10922 | bss->beacon_set ? "beacon_set=1\n" : "", | |
10923 | bss->added_if_into_bridge ? | |
10924 | "added_if_into_bridge=1\n" : "", | |
10925 | bss->added_bridge ? "added_bridge=1\n" : "", | |
10926 | bss->in_deinit ? "in_deinit=1\n" : "", | |
10927 | bss->if_dynamic ? "if_dynamic=1\n" : ""); | |
10928 | if (res < 0 || res >= end - pos) | |
10929 | return pos - buf; | |
10930 | pos += res; | |
10931 | ||
10932 | if (bss->wdev_id_set) { | |
10933 | res = os_snprintf(pos, end - pos, "wdev_id=%llu\n", | |
10934 | (unsigned long long) bss->wdev_id); | |
10935 | if (res < 0 || res >= end - pos) | |
10936 | return pos - buf; | |
10937 | pos += res; | |
10938 | } | |
10939 | ||
10940 | res = os_snprintf(pos, end - pos, | |
10941 | "phyname=%s\n" | |
10942 | "drv_ifindex=%d\n" | |
10943 | "operstate=%d\n" | |
10944 | "scan_state=%s\n" | |
10945 | "auth_bssid=" MACSTR "\n" | |
10946 | "auth_attempt_bssid=" MACSTR "\n" | |
10947 | "bssid=" MACSTR "\n" | |
10948 | "prev_bssid=" MACSTR "\n" | |
10949 | "associated=%d\n" | |
10950 | "assoc_freq=%u\n" | |
10951 | "monitor_sock=%d\n" | |
10952 | "monitor_ifidx=%d\n" | |
10953 | "monitor_refcount=%d\n" | |
10954 | "last_mgmt_freq=%u\n" | |
10955 | "eapol_tx_sock=%d\n" | |
10956 | "%s%s%s%s%s%s%s%s%s%s%s%s%s", | |
10957 | drv->phyname, | |
10958 | drv->ifindex, | |
10959 | drv->operstate, | |
10960 | scan_state_str(drv->scan_state), | |
10961 | MAC2STR(drv->auth_bssid), | |
10962 | MAC2STR(drv->auth_attempt_bssid), | |
10963 | MAC2STR(drv->bssid), | |
10964 | MAC2STR(drv->prev_bssid), | |
10965 | drv->associated, | |
10966 | drv->assoc_freq, | |
10967 | drv->monitor_sock, | |
10968 | drv->monitor_ifidx, | |
10969 | drv->monitor_refcount, | |
10970 | drv->last_mgmt_freq, | |
10971 | drv->eapol_tx_sock, | |
10972 | drv->ignore_if_down_event ? | |
10973 | "ignore_if_down_event=1\n" : "", | |
10974 | drv->scan_complete_events ? | |
10975 | "scan_complete_events=1\n" : "", | |
10976 | drv->disabled_11b_rates ? | |
10977 | "disabled_11b_rates=1\n" : "", | |
10978 | drv->pending_remain_on_chan ? | |
10979 | "pending_remain_on_chan=1\n" : "", | |
10980 | drv->in_interface_list ? "in_interface_list=1\n" : "", | |
10981 | drv->device_ap_sme ? "device_ap_sme=1\n" : "", | |
10982 | drv->poll_command_supported ? | |
10983 | "poll_command_supported=1\n" : "", | |
10984 | drv->data_tx_status ? "data_tx_status=1\n" : "", | |
10985 | drv->scan_for_auth ? "scan_for_auth=1\n" : "", | |
10986 | drv->retry_auth ? "retry_auth=1\n" : "", | |
10987 | drv->use_monitor ? "use_monitor=1\n" : "", | |
10988 | drv->ignore_next_local_disconnect ? | |
10989 | "ignore_next_local_disconnect=1\n" : "", | |
10990 | drv->allow_p2p_device ? "allow_p2p_device=1\n" : ""); | |
10991 | if (res < 0 || res >= end - pos) | |
10992 | return pos - buf; | |
10993 | pos += res; | |
10994 | ||
10995 | if (drv->has_capability) { | |
10996 | res = os_snprintf(pos, end - pos, | |
10997 | "capa.key_mgmt=0x%x\n" | |
10998 | "capa.enc=0x%x\n" | |
10999 | "capa.auth=0x%x\n" | |
11000 | "capa.flags=0x%x\n" | |
11001 | "capa.max_scan_ssids=%d\n" | |
11002 | "capa.max_sched_scan_ssids=%d\n" | |
11003 | "capa.sched_scan_supported=%d\n" | |
11004 | "capa.max_match_sets=%d\n" | |
11005 | "capa.max_remain_on_chan=%u\n" | |
11006 | "capa.max_stations=%u\n" | |
11007 | "capa.probe_resp_offloads=0x%x\n" | |
11008 | "capa.max_acl_mac_addrs=%u\n" | |
11009 | "capa.num_multichan_concurrent=%u\n", | |
11010 | drv->capa.key_mgmt, | |
11011 | drv->capa.enc, | |
11012 | drv->capa.auth, | |
11013 | drv->capa.flags, | |
11014 | drv->capa.max_scan_ssids, | |
11015 | drv->capa.max_sched_scan_ssids, | |
11016 | drv->capa.sched_scan_supported, | |
11017 | drv->capa.max_match_sets, | |
11018 | drv->capa.max_remain_on_chan, | |
11019 | drv->capa.max_stations, | |
11020 | drv->capa.probe_resp_offloads, | |
11021 | drv->capa.max_acl_mac_addrs, | |
11022 | drv->capa.num_multichan_concurrent); | |
11023 | if (res < 0 || res >= end - pos) | |
11024 | return pos - buf; | |
11025 | pos += res; | |
11026 | } | |
11027 | ||
11028 | return pos - buf; | |
11029 | } | |
11030 | ||
11031 | ||
3f5285e8 JM |
11032 | const struct wpa_driver_ops wpa_driver_nl80211_ops = { |
11033 | .name = "nl80211", | |
11034 | .desc = "Linux nl80211/cfg80211", | |
11035 | .get_bssid = wpa_driver_nl80211_get_bssid, | |
11036 | .get_ssid = wpa_driver_nl80211_get_ssid, | |
9ebce9c5 JM |
11037 | .set_key = driver_nl80211_set_key, |
11038 | .scan2 = driver_nl80211_scan2, | |
d21c63b9 LC |
11039 | .sched_scan = wpa_driver_nl80211_sched_scan, |
11040 | .stop_sched_scan = wpa_driver_nl80211_stop_sched_scan, | |
3f5285e8 | 11041 | .get_scan_results2 = wpa_driver_nl80211_get_scan_results, |
9ebce9c5 JM |
11042 | .deauthenticate = driver_nl80211_deauthenticate, |
11043 | .authenticate = driver_nl80211_authenticate, | |
3f5285e8 | 11044 | .associate = wpa_driver_nl80211_associate, |
f2ed8023 JM |
11045 | .global_init = nl80211_global_init, |
11046 | .global_deinit = nl80211_global_deinit, | |
11047 | .init2 = wpa_driver_nl80211_init, | |
9ebce9c5 | 11048 | .deinit = driver_nl80211_deinit, |
3f5285e8 JM |
11049 | .get_capa = wpa_driver_nl80211_get_capa, |
11050 | .set_operstate = wpa_driver_nl80211_set_operstate, | |
01652550 | 11051 | .set_supp_port = wpa_driver_nl80211_set_supp_port, |
6d158490 | 11052 | .set_country = wpa_driver_nl80211_set_country, |
19c3b566 | 11053 | .set_ap = wpa_driver_nl80211_set_ap, |
3c4ca363 | 11054 | .set_acl = wpa_driver_nl80211_set_acl, |
22a7c9d7 | 11055 | .if_add = wpa_driver_nl80211_if_add, |
9ebce9c5 JM |
11056 | .if_remove = driver_nl80211_if_remove, |
11057 | .send_mlme = driver_nl80211_send_mlme, | |
c3965310 | 11058 | .get_hw_feature_data = wpa_driver_nl80211_get_hw_feature_data, |
0f4e8b4f | 11059 | .sta_add = wpa_driver_nl80211_sta_add, |
9ebce9c5 | 11060 | .sta_remove = driver_nl80211_sta_remove, |
db149ac9 | 11061 | .hapd_send_eapol = wpa_driver_nl80211_hapd_send_eapol, |
a8d6ffa4 | 11062 | .sta_set_flags = wpa_driver_nl80211_sta_set_flags, |
c5121837 JM |
11063 | #ifdef HOSTAPD |
11064 | .hapd_init = i802_init, | |
c5121837 | 11065 | .hapd_deinit = i802_deinit, |
f7b3920c JM |
11066 | .set_wds_sta = i802_set_wds_sta, |
11067 | #endif /* HOSTAPD */ | |
11068 | #if defined(HOSTAPD) || defined(CONFIG_AP) | |
c5121837 JM |
11069 | .get_seqnum = i802_get_seqnum, |
11070 | .flush = i802_flush, | |
c5121837 JM |
11071 | .get_inact_sec = i802_get_inact_sec, |
11072 | .sta_clear_stats = i802_sta_clear_stats, | |
c5121837 JM |
11073 | .set_rts = i802_set_rts, |
11074 | .set_frag = i802_set_frag, | |
c5121837 | 11075 | .set_tx_queue_params = i802_set_tx_queue_params, |
9ebce9c5 | 11076 | .set_sta_vlan = driver_nl80211_set_sta_vlan, |
ee7ab173 JB |
11077 | .sta_deauth = i802_sta_deauth, |
11078 | .sta_disassoc = i802_sta_disassoc, | |
11079 | #endif /* HOSTAPD || CONFIG_AP */ | |
9ebce9c5 | 11080 | .read_sta_data = driver_nl80211_read_sta_data, |
e3802622 | 11081 | .set_freq = i802_set_freq, |
9ebce9c5 | 11082 | .send_action = driver_nl80211_send_action, |
5dfca53f | 11083 | .send_action_cancel_wait = wpa_driver_nl80211_send_action_cancel_wait, |
55777702 JM |
11084 | .remain_on_channel = wpa_driver_nl80211_remain_on_channel, |
11085 | .cancel_remain_on_channel = | |
11086 | wpa_driver_nl80211_cancel_remain_on_channel, | |
9ebce9c5 | 11087 | .probe_req_report = driver_nl80211_probe_req_report, |
af473088 | 11088 | .deinit_ap = wpa_driver_nl80211_deinit_ap, |
3c29244e | 11089 | .deinit_p2p_cli = wpa_driver_nl80211_deinit_p2p_cli, |
207ef3fb | 11090 | .resume = wpa_driver_nl80211_resume, |
7b90c16a | 11091 | .send_ft_action = nl80211_send_ft_action, |
b625473c | 11092 | .signal_monitor = nl80211_signal_monitor, |
1c5c7273 | 11093 | .signal_poll = nl80211_signal_poll, |
b91ab76e | 11094 | .send_frame = nl80211_send_frame, |
57ebba59 | 11095 | .shared_freq = wpa_driver_nl80211_shared_freq, |
c55f774d | 11096 | .set_param = nl80211_set_param, |
6859f1cb | 11097 | .get_radio_name = nl80211_get_radio_name, |
a6efc65d JM |
11098 | .add_pmkid = nl80211_add_pmkid, |
11099 | .remove_pmkid = nl80211_remove_pmkid, | |
11100 | .flush_pmkid = nl80211_flush_pmkid, | |
b14a210c | 11101 | .set_rekey_info = nl80211_set_rekey_info, |
bcf24348 | 11102 | .poll_client = nl80211_poll_client, |
29f338af | 11103 | .set_p2p_powersave = nl80211_set_p2p_powersave, |
f90e9c1c | 11104 | .start_dfs_cac = nl80211_start_radar_detection, |
695c7038 | 11105 | .stop_ap = wpa_driver_nl80211_stop_ap, |
03ea1786 AN |
11106 | #ifdef CONFIG_TDLS |
11107 | .send_tdls_mgmt = nl80211_send_tdls_mgmt, | |
11108 | .tdls_oper = nl80211_tdls_oper, | |
11109 | #endif /* CONFIG_TDLS */ | |
6a1ce395 | 11110 | .update_ft_ies = wpa_driver_nl80211_update_ft_ies, |
597b94f5 | 11111 | .get_mac_addr = wpa_driver_nl80211_get_macaddr, |
0185007c | 11112 | .get_survey = wpa_driver_nl80211_get_survey, |
a771c07d | 11113 | .status = wpa_driver_nl80211_status, |
3f5285e8 | 11114 | }; |