]>
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" | |
df2f9ec6 JM |
63 | |
64 | /* system/core/libnl_2 in AOSP does not include nla_put_u32() */ | |
65 | int nla_put_u32(struct nl_msg *msg, int attrtype, uint32_t value) | |
66 | { | |
67 | return nla_put(msg, attrtype, sizeof(uint32_t), &value); | |
68 | } | |
216eede8 | 69 | #endif /* ANDROID */ |
c5121837 JM |
70 | #ifdef CONFIG_LIBNL20 |
71 | /* libnl 2.0 compatibility code */ | |
2e8eac2d | 72 | #define nl_handle nl_sock |
a65a9aed JB |
73 | #define nl80211_handle_alloc nl_socket_alloc_cb |
74 | #define nl80211_handle_destroy nl_socket_free | |
75 | #else | |
76 | /* | |
77 | * libnl 1.1 has a bug, it tries to allocate socket numbers densely | |
78 | * but when you free a socket again it will mess up its bitmap and | |
79 | * and use the wrong number the next time it needs a socket ID. | |
80 | * Therefore, we wrap the handle alloc/destroy and add our own pid | |
81 | * accounting. | |
82 | */ | |
83 | static uint32_t port_bitmap[32] = { 0 }; | |
84 | ||
85 | static struct nl_handle *nl80211_handle_alloc(void *cb) | |
86 | { | |
87 | struct nl_handle *handle; | |
88 | uint32_t pid = getpid() & 0x3FFFFF; | |
89 | int i; | |
90 | ||
91 | handle = nl_handle_alloc_cb(cb); | |
92 | ||
93 | for (i = 0; i < 1024; i++) { | |
94 | if (port_bitmap[i / 32] & (1 << (i % 32))) | |
95 | continue; | |
96 | port_bitmap[i / 32] |= 1 << (i % 32); | |
97 | pid += i << 22; | |
98 | break; | |
99 | } | |
100 | ||
101 | nl_socket_set_local_port(handle, pid); | |
102 | ||
103 | return handle; | |
104 | } | |
105 | ||
106 | static void nl80211_handle_destroy(struct nl_handle *handle) | |
107 | { | |
108 | uint32_t port = nl_socket_get_local_port(handle); | |
109 | ||
110 | port >>= 22; | |
111 | port_bitmap[port / 32] &= ~(1 << (port % 32)); | |
112 | ||
113 | nl_handle_destroy(handle); | |
114 | } | |
c5121837 JM |
115 | #endif /* CONFIG_LIBNL20 */ |
116 | ||
c5121837 | 117 | |
481234cf | 118 | static struct nl_handle * nl_create_handle(struct nl_cb *cb, const char *dbg) |
a92dfde8 | 119 | { |
481234cf | 120 | struct nl_handle *handle; |
a92dfde8 | 121 | |
481234cf JM |
122 | handle = nl80211_handle_alloc(cb); |
123 | if (handle == NULL) { | |
a92dfde8 JB |
124 | wpa_printf(MSG_ERROR, "nl80211: Failed to allocate netlink " |
125 | "callbacks (%s)", dbg); | |
481234cf | 126 | return NULL; |
a92dfde8 JB |
127 | } |
128 | ||
481234cf | 129 | if (genl_connect(handle)) { |
a92dfde8 JB |
130 | wpa_printf(MSG_ERROR, "nl80211: Failed to connect to generic " |
131 | "netlink (%s)", dbg); | |
481234cf JM |
132 | nl80211_handle_destroy(handle); |
133 | return NULL; | |
a92dfde8 JB |
134 | } |
135 | ||
481234cf | 136 | return handle; |
a92dfde8 JB |
137 | } |
138 | ||
139 | ||
481234cf | 140 | static void nl_destroy_handles(struct nl_handle **handle) |
a92dfde8 | 141 | { |
481234cf | 142 | if (*handle == NULL) |
a92dfde8 | 143 | return; |
481234cf JM |
144 | nl80211_handle_destroy(*handle); |
145 | *handle = NULL; | |
a92dfde8 JB |
146 | } |
147 | ||
148 | ||
3f5285e8 JM |
149 | #ifndef IFF_LOWER_UP |
150 | #define IFF_LOWER_UP 0x10000 /* driver signals L1 up */ | |
151 | #endif | |
152 | #ifndef IFF_DORMANT | |
153 | #define IFF_DORMANT 0x20000 /* driver signals dormant */ | |
154 | #endif | |
155 | ||
156 | #ifndef IF_OPER_DORMANT | |
157 | #define IF_OPER_DORMANT 5 | |
158 | #endif | |
159 | #ifndef IF_OPER_UP | |
160 | #define IF_OPER_UP 6 | |
161 | #endif | |
162 | ||
f2ed8023 JM |
163 | struct nl80211_global { |
164 | struct dl_list interfaces; | |
ff6a158b | 165 | int if_add_ifindex; |
36d84860 | 166 | struct netlink_data *netlink; |
2a7b66f5 | 167 | struct nl_cb *nl_cb; |
481234cf | 168 | struct nl_handle *nl; |
335d42b1 | 169 | int nl80211_id; |
c81eff1a | 170 | int ioctl_sock; /* socket for ioctl() use */ |
d6c9aab8 | 171 | |
481234cf | 172 | struct nl_handle *nl_event; |
f2ed8023 JM |
173 | }; |
174 | ||
e32ad281 JB |
175 | struct nl80211_wiphy_data { |
176 | struct dl_list list; | |
177 | struct dl_list bsss; | |
178 | struct dl_list drvs; | |
179 | ||
481234cf | 180 | struct nl_handle *nl_beacons; |
e32ad281 JB |
181 | struct nl_cb *nl_cb; |
182 | ||
183 | int wiphy_idx; | |
184 | }; | |
185 | ||
36d84860 BG |
186 | static void nl80211_global_deinit(void *priv); |
187 | ||
c5121837 | 188 | struct i802_bss { |
a2e40bb6 | 189 | struct wpa_driver_nl80211_data *drv; |
c5121837 | 190 | struct i802_bss *next; |
b4fd6fab | 191 | int ifindex; |
a2e40bb6 | 192 | char ifname[IFNAMSIZ + 1]; |
e17a2477 | 193 | char brname[IFNAMSIZ]; |
c5121837 | 194 | unsigned int beacon_set:1; |
e17a2477 JM |
195 | unsigned int added_if_into_bridge:1; |
196 | unsigned int added_bridge:1; | |
873d0fcf | 197 | unsigned int in_deinit:1; |
221a59c9 | 198 | |
341eebee JB |
199 | u8 addr[ETH_ALEN]; |
200 | ||
e4fb2167 JB |
201 | int freq; |
202 | ||
a5e1eb20 | 203 | void *ctx; |
481234cf | 204 | struct nl_handle *nl_preq, *nl_mgmt; |
cc7a48d1 | 205 | struct nl_cb *nl_cb; |
e32ad281 JB |
206 | |
207 | struct nl80211_wiphy_data *wiphy_data; | |
208 | struct dl_list wiphy_list; | |
c5121837 | 209 | }; |
3f5285e8 JM |
210 | |
211 | struct wpa_driver_nl80211_data { | |
f2ed8023 JM |
212 | struct nl80211_global *global; |
213 | struct dl_list list; | |
e32ad281 | 214 | struct dl_list wiphy_list; |
6859f1cb | 215 | char phyname[32]; |
3f5285e8 | 216 | void *ctx; |
3f5285e8 | 217 | int ifindex; |
7524cfb1 | 218 | int if_removed; |
a63063b4 | 219 | int if_disabled; |
7d9c3698 | 220 | int ignore_if_down_event; |
8401a6b0 | 221 | struct rfkill_data *rfkill; |
c2a04078 JM |
222 | struct wpa_driver_capa capa; |
223 | int has_capability; | |
c2a04078 | 224 | |
3f5285e8 JM |
225 | int operstate; |
226 | ||
3f5285e8 JM |
227 | int scan_complete_events; |
228 | ||
1afc986d | 229 | struct nl_cb *nl_cb; |
1c873584 | 230 | |
e6b8efeb | 231 | u8 auth_bssid[ETH_ALEN]; |
c2a04078 JM |
232 | u8 bssid[ETH_ALEN]; |
233 | int associated; | |
fd05d64e JM |
234 | u8 ssid[32]; |
235 | size_t ssid_len; | |
b1f625e0 EP |
236 | enum nl80211_iftype nlmode; |
237 | enum nl80211_iftype ap_scan_as_station; | |
4832ecd7 | 238 | unsigned int assoc_freq; |
d2440ba0 | 239 | |
0915d02c JM |
240 | int monitor_sock; |
241 | int monitor_ifidx; | |
3fd1cefb | 242 | int monitor_refcount; |
7da3abe7 | 243 | |
b3af99d2 | 244 | unsigned int disabled_11b_rates:1; |
55777702 | 245 | unsigned int pending_remain_on_chan:1; |
dac12351 | 246 | unsigned int in_interface_list:1; |
61cbe2ff | 247 | unsigned int device_ap_sme:1; |
39718852 | 248 | unsigned int poll_command_supported:1; |
32ab4855 | 249 | unsigned int data_tx_status:1; |
536fd62d JM |
250 | unsigned int scan_for_auth:1; |
251 | unsigned int retry_auth:1; | |
a11241fa | 252 | unsigned int use_monitor:1; |
a8c5b43a | 253 | unsigned int ignore_next_local_disconnect:1; |
55777702 JM |
254 | |
255 | u64 remain_on_chan_cookie; | |
58f6fbe0 | 256 | u64 send_action_cookie; |
c5121837 | 257 | |
5582a5d1 JB |
258 | unsigned int last_mgmt_freq; |
259 | ||
3812464c JM |
260 | struct wpa_driver_scan_filter *filter_ssids; |
261 | size_t num_filter_ssids; | |
262 | ||
a2e40bb6 FF |
263 | struct i802_bss first_bss; |
264 | ||
d12dab4c | 265 | int eapol_tx_sock; |
f10bfc9a | 266 | |
c5121837 | 267 | #ifdef HOSTAPD |
c5121837 | 268 | int eapol_sock; /* socket for EAPOL frames */ |
c5121837 JM |
269 | |
270 | int default_if_indices[16]; | |
271 | int *if_indices; | |
272 | int num_if_indices; | |
273 | ||
c5121837 JM |
274 | int last_freq; |
275 | int last_freq_ht; | |
c5121837 | 276 | #endif /* HOSTAPD */ |
536fd62d JM |
277 | |
278 | /* From failed authentication command */ | |
279 | int auth_freq; | |
280 | u8 auth_bssid_[ETH_ALEN]; | |
281 | u8 auth_ssid[32]; | |
282 | size_t auth_ssid_len; | |
283 | int auth_alg; | |
284 | u8 *auth_ie; | |
285 | size_t auth_ie_len; | |
286 | u8 auth_wep_key[4][16]; | |
287 | size_t auth_wep_key_len[4]; | |
288 | int auth_wep_tx_keyidx; | |
289 | int auth_local_state_change; | |
290 | int auth_p2p; | |
3f5285e8 JM |
291 | }; |
292 | ||
293 | ||
9ebce9c5 | 294 | static void wpa_driver_nl80211_deinit(struct i802_bss *bss); |
3f5285e8 JM |
295 | static void wpa_driver_nl80211_scan_timeout(void *eloop_ctx, |
296 | void *timeout_ctx); | |
b1f625e0 EP |
297 | static int wpa_driver_nl80211_set_mode(struct i802_bss *bss, |
298 | enum nl80211_iftype nlmode); | |
362f781e | 299 | static int |
7524cfb1 | 300 | wpa_driver_nl80211_finish_drv_init(struct wpa_driver_nl80211_data *drv); |
d72aad94 | 301 | static int wpa_driver_nl80211_mlme(struct wpa_driver_nl80211_data *drv, |
77339912 JM |
302 | const u8 *addr, int cmd, u16 reason_code, |
303 | int local_state_change); | |
460456f8 JM |
304 | static void nl80211_remove_monitor_interface( |
305 | struct wpa_driver_nl80211_data *drv); | |
88df0ef7 | 306 | static int nl80211_send_frame_cmd(struct i802_bss *bss, |
5dfca53f | 307 | unsigned int freq, unsigned int wait, |
b106173a | 308 | const u8 *buf, size_t buf_len, u64 *cookie, |
88df0ef7 | 309 | int no_cck, int no_ack, int offchanok); |
9ebce9c5 JM |
310 | static int wpa_driver_nl80211_probe_req_report(struct i802_bss *bss, |
311 | int report); | |
216eede8 DS |
312 | #ifdef ANDROID |
313 | static int android_pno_start(struct i802_bss *bss, | |
314 | struct wpa_driver_scan_params *params); | |
315 | static int android_pno_stop(struct i802_bss *bss); | |
316 | #endif /* ANDROID */ | |
0915d02c | 317 | |
072ad14c | 318 | #ifdef HOSTAPD |
2135f224 JM |
319 | static void add_ifidx(struct wpa_driver_nl80211_data *drv, int ifidx); |
320 | static void del_ifidx(struct wpa_driver_nl80211_data *drv, int ifidx); | |
97cfcf64 | 321 | static int have_ifidx(struct wpa_driver_nl80211_data *drv, int ifidx); |
9ebce9c5 | 322 | static int wpa_driver_nl80211_if_remove(struct i802_bss *bss, |
fbbfcbac FF |
323 | enum wpa_driver_if_type type, |
324 | const char *ifname); | |
37eb8da9 | 325 | #else /* HOSTAPD */ |
bd2df892 JM |
326 | static inline void add_ifidx(struct wpa_driver_nl80211_data *drv, int ifidx) |
327 | { | |
328 | } | |
329 | ||
330 | static inline void del_ifidx(struct wpa_driver_nl80211_data *drv, int ifidx) | |
331 | { | |
332 | } | |
333 | ||
334 | static inline int have_ifidx(struct wpa_driver_nl80211_data *drv, int ifidx) | |
37eb8da9 JM |
335 | { |
336 | return 0; | |
337 | } | |
072ad14c JM |
338 | #endif /* HOSTAPD */ |
339 | ||
9ebce9c5 JM |
340 | static int wpa_driver_nl80211_set_freq(struct i802_bss *bss, |
341 | struct hostapd_freq_params *freq); | |
4e5cb1a3 JM |
342 | static int nl80211_disable_11b_rates(struct wpa_driver_nl80211_data *drv, |
343 | int ifindex, int disabled); | |
504e905c | 344 | |
21bdbe38 | 345 | static int nl80211_leave_ibss(struct wpa_driver_nl80211_data *drv); |
536fd62d JM |
346 | static int wpa_driver_nl80211_authenticate_retry( |
347 | struct wpa_driver_nl80211_data *drv); | |
21bdbe38 | 348 | |
3f5285e8 | 349 | |
b1f625e0 EP |
350 | static int is_ap_interface(enum nl80211_iftype nlmode) |
351 | { | |
352 | return (nlmode == NL80211_IFTYPE_AP || | |
353 | nlmode == NL80211_IFTYPE_P2P_GO); | |
354 | } | |
355 | ||
356 | ||
357 | static int is_sta_interface(enum nl80211_iftype nlmode) | |
358 | { | |
359 | return (nlmode == NL80211_IFTYPE_STATION || | |
360 | nlmode == NL80211_IFTYPE_P2P_CLIENT); | |
361 | } | |
362 | ||
363 | ||
b3af99d2 JM |
364 | static int is_p2p_interface(enum nl80211_iftype nlmode) |
365 | { | |
366 | return (nlmode == NL80211_IFTYPE_P2P_CLIENT || | |
367 | nlmode == NL80211_IFTYPE_P2P_GO); | |
368 | } | |
369 | ||
370 | ||
f5a8d422 JM |
371 | struct nl80211_bss_info_arg { |
372 | struct wpa_driver_nl80211_data *drv; | |
373 | struct wpa_scan_results *res; | |
374 | unsigned int assoc_freq; | |
20f5a4c2 | 375 | u8 assoc_bssid[ETH_ALEN]; |
f5a8d422 JM |
376 | }; |
377 | ||
378 | static int bss_info_handler(struct nl_msg *msg, void *arg); | |
379 | ||
380 | ||
6241fcb1 JM |
381 | /* nl80211 code */ |
382 | static int ack_handler(struct nl_msg *msg, void *arg) | |
383 | { | |
384 | int *err = arg; | |
385 | *err = 0; | |
386 | return NL_STOP; | |
387 | } | |
388 | ||
389 | static int finish_handler(struct nl_msg *msg, void *arg) | |
390 | { | |
8e8df255 JM |
391 | int *ret = arg; |
392 | *ret = 0; | |
6241fcb1 JM |
393 | return NL_SKIP; |
394 | } | |
395 | ||
396 | static int error_handler(struct sockaddr_nl *nla, struct nlmsgerr *err, | |
397 | void *arg) | |
398 | { | |
399 | int *ret = arg; | |
400 | *ret = err->error; | |
401 | return NL_SKIP; | |
402 | } | |
403 | ||
5b7b85f6 JM |
404 | |
405 | static int no_seq_check(struct nl_msg *msg, void *arg) | |
406 | { | |
407 | return NL_OK; | |
408 | } | |
409 | ||
410 | ||
d6c9aab8 | 411 | static int send_and_recv(struct nl80211_global *global, |
58f6fbe0 JM |
412 | struct nl_handle *nl_handle, struct nl_msg *msg, |
413 | int (*valid_handler)(struct nl_msg *, void *), | |
414 | void *valid_data) | |
6241fcb1 JM |
415 | { |
416 | struct nl_cb *cb; | |
417 | int err = -ENOMEM; | |
418 | ||
d6c9aab8 | 419 | cb = nl_cb_clone(global->nl_cb); |
6241fcb1 JM |
420 | if (!cb) |
421 | goto out; | |
422 | ||
58f6fbe0 | 423 | err = nl_send_auto_complete(nl_handle, msg); |
6241fcb1 JM |
424 | if (err < 0) |
425 | goto out; | |
426 | ||
427 | err = 1; | |
428 | ||
429 | nl_cb_err(cb, NL_CB_CUSTOM, error_handler, &err); | |
8e8df255 | 430 | nl_cb_set(cb, NL_CB_FINISH, NL_CB_CUSTOM, finish_handler, &err); |
6241fcb1 JM |
431 | nl_cb_set(cb, NL_CB_ACK, NL_CB_CUSTOM, ack_handler, &err); |
432 | ||
433 | if (valid_handler) | |
434 | nl_cb_set(cb, NL_CB_VALID, NL_CB_CUSTOM, | |
435 | valid_handler, valid_data); | |
436 | ||
437 | while (err > 0) | |
58f6fbe0 | 438 | nl_recvmsgs(nl_handle, cb); |
6241fcb1 JM |
439 | out: |
440 | nl_cb_put(cb); | |
441 | nlmsg_free(msg); | |
442 | return err; | |
443 | } | |
444 | ||
445 | ||
d6c9aab8 JB |
446 | static int send_and_recv_msgs_global(struct nl80211_global *global, |
447 | struct nl_msg *msg, | |
448 | int (*valid_handler)(struct nl_msg *, void *), | |
449 | void *valid_data) | |
450 | { | |
481234cf | 451 | return send_and_recv(global, global->nl, msg, valid_handler, |
d6c9aab8 JB |
452 | valid_data); |
453 | } | |
454 | ||
455 | ||
58f6fbe0 JM |
456 | static int send_and_recv_msgs(struct wpa_driver_nl80211_data *drv, |
457 | struct nl_msg *msg, | |
458 | int (*valid_handler)(struct nl_msg *, void *), | |
459 | void *valid_data) | |
460 | { | |
481234cf | 461 | return send_and_recv(drv->global, drv->global->nl, msg, |
d6c9aab8 | 462 | valid_handler, valid_data); |
58f6fbe0 JM |
463 | } |
464 | ||
465 | ||
97865538 JM |
466 | struct family_data { |
467 | const char *group; | |
468 | int id; | |
469 | }; | |
470 | ||
471 | ||
472 | static int family_handler(struct nl_msg *msg, void *arg) | |
473 | { | |
474 | struct family_data *res = arg; | |
475 | struct nlattr *tb[CTRL_ATTR_MAX + 1]; | |
476 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); | |
477 | struct nlattr *mcgrp; | |
478 | int i; | |
479 | ||
480 | nla_parse(tb, CTRL_ATTR_MAX, genlmsg_attrdata(gnlh, 0), | |
481 | genlmsg_attrlen(gnlh, 0), NULL); | |
482 | if (!tb[CTRL_ATTR_MCAST_GROUPS]) | |
483 | return NL_SKIP; | |
484 | ||
485 | nla_for_each_nested(mcgrp, tb[CTRL_ATTR_MCAST_GROUPS], i) { | |
486 | struct nlattr *tb2[CTRL_ATTR_MCAST_GRP_MAX + 1]; | |
487 | nla_parse(tb2, CTRL_ATTR_MCAST_GRP_MAX, nla_data(mcgrp), | |
488 | nla_len(mcgrp), NULL); | |
489 | if (!tb2[CTRL_ATTR_MCAST_GRP_NAME] || | |
490 | !tb2[CTRL_ATTR_MCAST_GRP_ID] || | |
491 | os_strncmp(nla_data(tb2[CTRL_ATTR_MCAST_GRP_NAME]), | |
492 | res->group, | |
493 | nla_len(tb2[CTRL_ATTR_MCAST_GRP_NAME])) != 0) | |
494 | continue; | |
495 | res->id = nla_get_u32(tb2[CTRL_ATTR_MCAST_GRP_ID]); | |
496 | break; | |
497 | }; | |
498 | ||
499 | return NL_SKIP; | |
500 | } | |
501 | ||
502 | ||
d6c9aab8 | 503 | static int nl_get_multicast_id(struct nl80211_global *global, |
97865538 JM |
504 | const char *family, const char *group) |
505 | { | |
506 | struct nl_msg *msg; | |
507 | int ret = -1; | |
508 | struct family_data res = { group, -ENOENT }; | |
509 | ||
510 | msg = nlmsg_alloc(); | |
511 | if (!msg) | |
512 | return -ENOMEM; | |
481234cf | 513 | genlmsg_put(msg, 0, 0, genl_ctrl_resolve(global->nl, "nlctrl"), |
97865538 JM |
514 | 0, 0, CTRL_CMD_GETFAMILY, 0); |
515 | NLA_PUT_STRING(msg, CTRL_ATTR_FAMILY_NAME, family); | |
516 | ||
d6c9aab8 | 517 | ret = send_and_recv_msgs_global(global, msg, family_handler, &res); |
97865538 JM |
518 | msg = NULL; |
519 | if (ret == 0) | |
520 | ret = res.id; | |
521 | ||
522 | nla_put_failure: | |
523 | nlmsg_free(msg); | |
524 | return ret; | |
525 | } | |
526 | ||
527 | ||
9fb04070 JM |
528 | static void * nl80211_cmd(struct wpa_driver_nl80211_data *drv, |
529 | struct nl_msg *msg, int flags, uint8_t cmd) | |
530 | { | |
335d42b1 | 531 | return genlmsg_put(msg, 0, 0, drv->global->nl80211_id, |
276e2d67 | 532 | 0, flags, cmd, 0); |
9fb04070 JM |
533 | } |
534 | ||
535 | ||
e32ad281 JB |
536 | struct wiphy_idx_data { |
537 | int wiphy_idx; | |
538 | }; | |
539 | ||
540 | ||
541 | static int netdev_info_handler(struct nl_msg *msg, void *arg) | |
542 | { | |
543 | struct nlattr *tb[NL80211_ATTR_MAX + 1]; | |
544 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); | |
545 | struct wiphy_idx_data *info = arg; | |
546 | ||
547 | nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), | |
548 | genlmsg_attrlen(gnlh, 0), NULL); | |
549 | ||
550 | if (tb[NL80211_ATTR_WIPHY]) | |
551 | info->wiphy_idx = nla_get_u32(tb[NL80211_ATTR_WIPHY]); | |
552 | ||
553 | return NL_SKIP; | |
554 | } | |
555 | ||
556 | ||
557 | static int nl80211_get_wiphy_index(struct i802_bss *bss) | |
558 | { | |
559 | struct nl_msg *msg; | |
560 | struct wiphy_idx_data data = { | |
561 | .wiphy_idx = -1, | |
562 | }; | |
563 | ||
564 | msg = nlmsg_alloc(); | |
565 | if (!msg) | |
566 | return -1; | |
567 | ||
568 | nl80211_cmd(bss->drv, msg, 0, NL80211_CMD_GET_INTERFACE); | |
569 | ||
570 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, bss->ifindex); | |
571 | ||
572 | if (send_and_recv_msgs(bss->drv, msg, netdev_info_handler, &data) == 0) | |
573 | return data.wiphy_idx; | |
574 | msg = NULL; | |
575 | nla_put_failure: | |
576 | nlmsg_free(msg); | |
577 | return -1; | |
578 | } | |
579 | ||
580 | ||
581 | static int nl80211_register_beacons(struct wpa_driver_nl80211_data *drv, | |
582 | struct nl80211_wiphy_data *w) | |
583 | { | |
584 | struct nl_msg *msg; | |
585 | int ret = -1; | |
586 | ||
587 | msg = nlmsg_alloc(); | |
588 | if (!msg) | |
589 | return -1; | |
590 | ||
591 | nl80211_cmd(drv, msg, 0, NL80211_CMD_REGISTER_BEACONS); | |
592 | ||
593 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, w->wiphy_idx); | |
594 | ||
481234cf | 595 | ret = send_and_recv(drv->global, w->nl_beacons, msg, NULL, NULL); |
e32ad281 JB |
596 | msg = NULL; |
597 | if (ret) { | |
598 | wpa_printf(MSG_DEBUG, "nl80211: Register beacons command " | |
599 | "failed: ret=%d (%s)", | |
600 | ret, strerror(-ret)); | |
601 | goto nla_put_failure; | |
602 | } | |
603 | ret = 0; | |
604 | nla_put_failure: | |
605 | nlmsg_free(msg); | |
606 | return ret; | |
607 | } | |
608 | ||
609 | ||
610 | static void nl80211_recv_beacons(int sock, void *eloop_ctx, void *handle) | |
611 | { | |
612 | struct nl80211_wiphy_data *w = eloop_ctx; | |
613 | ||
ee9fc67a | 614 | wpa_printf(MSG_EXCESSIVE, "nl80211: Beacon event message available"); |
e32ad281 JB |
615 | |
616 | nl_recvmsgs(handle, w->nl_cb); | |
617 | } | |
618 | ||
619 | ||
620 | static int process_beacon_event(struct nl_msg *msg, void *arg) | |
621 | { | |
622 | struct nl80211_wiphy_data *w = arg; | |
623 | struct wpa_driver_nl80211_data *drv; | |
624 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); | |
625 | struct nlattr *tb[NL80211_ATTR_MAX + 1]; | |
626 | union wpa_event_data event; | |
627 | ||
628 | nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), | |
629 | genlmsg_attrlen(gnlh, 0), NULL); | |
630 | ||
631 | if (gnlh->cmd != NL80211_CMD_FRAME) { | |
632 | wpa_printf(MSG_DEBUG, "nl80211: Unexpected beacon event? (%d)", | |
633 | gnlh->cmd); | |
634 | return NL_SKIP; | |
635 | } | |
636 | ||
637 | if (!tb[NL80211_ATTR_FRAME]) | |
638 | return NL_SKIP; | |
639 | ||
640 | dl_list_for_each(drv, &w->drvs, struct wpa_driver_nl80211_data, | |
641 | wiphy_list) { | |
642 | os_memset(&event, 0, sizeof(event)); | |
643 | event.rx_mgmt.frame = nla_data(tb[NL80211_ATTR_FRAME]); | |
644 | event.rx_mgmt.frame_len = nla_len(tb[NL80211_ATTR_FRAME]); | |
645 | wpa_supplicant_event(drv->ctx, EVENT_RX_MGMT, &event); | |
646 | } | |
647 | ||
648 | return NL_SKIP; | |
649 | } | |
650 | ||
651 | ||
652 | static struct nl80211_wiphy_data * | |
653 | nl80211_get_wiphy_data_ap(struct i802_bss *bss) | |
654 | { | |
655 | static DEFINE_DL_LIST(nl80211_wiphys); | |
656 | struct nl80211_wiphy_data *w; | |
657 | int wiphy_idx, found = 0; | |
658 | struct i802_bss *tmp_bss; | |
659 | ||
660 | if (bss->wiphy_data != NULL) | |
661 | return bss->wiphy_data; | |
662 | ||
663 | wiphy_idx = nl80211_get_wiphy_index(bss); | |
664 | ||
665 | dl_list_for_each(w, &nl80211_wiphys, struct nl80211_wiphy_data, list) { | |
666 | if (w->wiphy_idx == wiphy_idx) | |
667 | goto add; | |
668 | } | |
669 | ||
670 | /* alloc new one */ | |
671 | w = os_zalloc(sizeof(*w)); | |
672 | if (w == NULL) | |
673 | return NULL; | |
674 | w->wiphy_idx = wiphy_idx; | |
675 | dl_list_init(&w->bsss); | |
676 | dl_list_init(&w->drvs); | |
677 | ||
678 | w->nl_cb = nl_cb_alloc(NL_CB_DEFAULT); | |
679 | if (!w->nl_cb) { | |
680 | os_free(w); | |
681 | return NULL; | |
682 | } | |
683 | nl_cb_set(w->nl_cb, NL_CB_SEQ_CHECK, NL_CB_CUSTOM, no_seq_check, NULL); | |
684 | nl_cb_set(w->nl_cb, NL_CB_VALID, NL_CB_CUSTOM, process_beacon_event, | |
685 | w); | |
686 | ||
481234cf JM |
687 | w->nl_beacons = nl_create_handle(bss->drv->global->nl_cb, |
688 | "wiphy beacons"); | |
689 | if (w->nl_beacons == NULL) { | |
e32ad281 JB |
690 | os_free(w); |
691 | return NULL; | |
692 | } | |
693 | ||
694 | if (nl80211_register_beacons(bss->drv, w)) { | |
695 | nl_destroy_handles(&w->nl_beacons); | |
696 | os_free(w); | |
697 | return NULL; | |
698 | } | |
699 | ||
481234cf JM |
700 | eloop_register_read_sock(nl_socket_get_fd(w->nl_beacons), |
701 | nl80211_recv_beacons, w, w->nl_beacons); | |
e32ad281 JB |
702 | |
703 | dl_list_add(&nl80211_wiphys, &w->list); | |
704 | ||
705 | add: | |
706 | /* drv entry for this bss already there? */ | |
707 | dl_list_for_each(tmp_bss, &w->bsss, struct i802_bss, wiphy_list) { | |
708 | if (tmp_bss->drv == bss->drv) { | |
709 | found = 1; | |
710 | break; | |
711 | } | |
712 | } | |
713 | /* if not add it */ | |
714 | if (!found) | |
715 | dl_list_add(&w->drvs, &bss->drv->wiphy_list); | |
716 | ||
717 | dl_list_add(&w->bsss, &bss->wiphy_list); | |
718 | bss->wiphy_data = w; | |
719 | return w; | |
720 | } | |
721 | ||
722 | ||
723 | static void nl80211_put_wiphy_data_ap(struct i802_bss *bss) | |
724 | { | |
725 | struct nl80211_wiphy_data *w = bss->wiphy_data; | |
726 | struct i802_bss *tmp_bss; | |
727 | int found = 0; | |
728 | ||
729 | if (w == NULL) | |
730 | return; | |
731 | bss->wiphy_data = NULL; | |
732 | dl_list_del(&bss->wiphy_list); | |
733 | ||
734 | /* still any for this drv present? */ | |
735 | dl_list_for_each(tmp_bss, &w->bsss, struct i802_bss, wiphy_list) { | |
736 | if (tmp_bss->drv == bss->drv) { | |
737 | found = 1; | |
738 | break; | |
739 | } | |
740 | } | |
741 | /* if not remove it */ | |
742 | if (!found) | |
743 | dl_list_del(&bss->drv->wiphy_list); | |
744 | ||
745 | if (!dl_list_empty(&w->bsss)) | |
746 | return; | |
747 | ||
481234cf | 748 | eloop_unregister_read_sock(nl_socket_get_fd(w->nl_beacons)); |
e32ad281 JB |
749 | |
750 | nl_cb_put(w->nl_cb); | |
751 | nl_destroy_handles(&w->nl_beacons); | |
752 | dl_list_del(&w->list); | |
753 | os_free(w); | |
754 | } | |
755 | ||
756 | ||
3f5285e8 JM |
757 | static int wpa_driver_nl80211_get_bssid(void *priv, u8 *bssid) |
758 | { | |
a2e40bb6 FF |
759 | struct i802_bss *bss = priv; |
760 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
c2a04078 JM |
761 | if (!drv->associated) |
762 | return -1; | |
763 | os_memcpy(bssid, drv->bssid, ETH_ALEN); | |
764 | return 0; | |
3f5285e8 JM |
765 | } |
766 | ||
767 | ||
3f5285e8 JM |
768 | static int wpa_driver_nl80211_get_ssid(void *priv, u8 *ssid) |
769 | { | |
a2e40bb6 FF |
770 | struct i802_bss *bss = priv; |
771 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
fd05d64e JM |
772 | if (!drv->associated) |
773 | return -1; | |
774 | os_memcpy(ssid, drv->ssid, drv->ssid_len); | |
775 | return drv->ssid_len; | |
3f5285e8 JM |
776 | } |
777 | ||
778 | ||
7524cfb1 | 779 | static void wpa_driver_nl80211_event_link(struct wpa_driver_nl80211_data *drv, |
08063178 | 780 | char *buf, size_t len, int del) |
3f5285e8 JM |
781 | { |
782 | union wpa_event_data event; | |
783 | ||
784 | os_memset(&event, 0, sizeof(event)); | |
785 | if (len > sizeof(event.interface_status.ifname)) | |
786 | len = sizeof(event.interface_status.ifname) - 1; | |
787 | os_memcpy(event.interface_status.ifname, buf, len); | |
788 | event.interface_status.ievent = del ? EVENT_INTERFACE_REMOVED : | |
789 | EVENT_INTERFACE_ADDED; | |
790 | ||
791 | wpa_printf(MSG_DEBUG, "RTM_%sLINK, IFLA_IFNAME: Interface '%s' %s", | |
792 | del ? "DEL" : "NEW", | |
793 | event.interface_status.ifname, | |
794 | del ? "removed" : "added"); | |
795 | ||
a2e40bb6 | 796 | if (os_strcmp(drv->first_bss.ifname, event.interface_status.ifname) == 0) { |
d1f4942b JM |
797 | if (del) { |
798 | if (drv->if_removed) { | |
799 | wpa_printf(MSG_DEBUG, "nl80211: if_removed " | |
800 | "already set - ignore event"); | |
801 | return; | |
802 | } | |
7524cfb1 | 803 | drv->if_removed = 1; |
d1f4942b JM |
804 | } else { |
805 | if (if_nametoindex(drv->first_bss.ifname) == 0) { | |
806 | wpa_printf(MSG_DEBUG, "nl80211: Interface %s " | |
807 | "does not exist - ignore " | |
808 | "RTM_NEWLINK", | |
809 | drv->first_bss.ifname); | |
810 | return; | |
811 | } | |
812 | if (!drv->if_removed) { | |
813 | wpa_printf(MSG_DEBUG, "nl80211: if_removed " | |
814 | "already cleared - ignore event"); | |
815 | return; | |
816 | } | |
7524cfb1 | 817 | drv->if_removed = 0; |
d1f4942b | 818 | } |
7524cfb1 JM |
819 | } |
820 | ||
08063178 | 821 | wpa_supplicant_event(drv->ctx, EVENT_INTERFACE_STATUS, &event); |
3f5285e8 JM |
822 | } |
823 | ||
824 | ||
7524cfb1 | 825 | static int wpa_driver_nl80211_own_ifname(struct wpa_driver_nl80211_data *drv, |
62d680c3 | 826 | u8 *buf, size_t len) |
7524cfb1 | 827 | { |
62d680c3 | 828 | int attrlen, rta_len; |
7524cfb1 JM |
829 | struct rtattr *attr; |
830 | ||
62d680c3 JM |
831 | attrlen = len; |
832 | attr = (struct rtattr *) buf; | |
7524cfb1 JM |
833 | |
834 | rta_len = RTA_ALIGN(sizeof(struct rtattr)); | |
835 | while (RTA_OK(attr, attrlen)) { | |
836 | if (attr->rta_type == IFLA_IFNAME) { | |
a2e40bb6 | 837 | if (os_strcmp(((char *) attr) + rta_len, drv->first_bss.ifname) |
7524cfb1 JM |
838 | == 0) |
839 | return 1; | |
840 | else | |
841 | break; | |
842 | } | |
843 | attr = RTA_NEXT(attr, attrlen); | |
844 | } | |
845 | ||
846 | return 0; | |
847 | } | |
848 | ||
849 | ||
850 | static int wpa_driver_nl80211_own_ifindex(struct wpa_driver_nl80211_data *drv, | |
62d680c3 | 851 | int ifindex, u8 *buf, size_t len) |
7524cfb1 JM |
852 | { |
853 | if (drv->ifindex == ifindex) | |
854 | return 1; | |
855 | ||
62d680c3 | 856 | if (drv->if_removed && wpa_driver_nl80211_own_ifname(drv, buf, len)) { |
a2e40bb6 | 857 | drv->first_bss.ifindex = if_nametoindex(drv->first_bss.ifname); |
7524cfb1 JM |
858 | wpa_printf(MSG_DEBUG, "nl80211: Update ifindex for a removed " |
859 | "interface"); | |
860 | wpa_driver_nl80211_finish_drv_init(drv); | |
861 | return 1; | |
862 | } | |
863 | ||
864 | return 0; | |
865 | } | |
866 | ||
867 | ||
36d84860 BG |
868 | static struct wpa_driver_nl80211_data * |
869 | nl80211_find_drv(struct nl80211_global *global, int idx, u8 *buf, size_t len) | |
870 | { | |
871 | struct wpa_driver_nl80211_data *drv; | |
872 | dl_list_for_each(drv, &global->interfaces, | |
873 | struct wpa_driver_nl80211_data, list) { | |
874 | if (wpa_driver_nl80211_own_ifindex(drv, idx, buf, len) || | |
875 | have_ifidx(drv, idx)) | |
876 | return drv; | |
877 | } | |
878 | return NULL; | |
879 | } | |
880 | ||
881 | ||
62d680c3 JM |
882 | static void wpa_driver_nl80211_event_rtm_newlink(void *ctx, |
883 | struct ifinfomsg *ifi, | |
884 | u8 *buf, size_t len) | |
3f5285e8 | 885 | { |
36d84860 BG |
886 | struct nl80211_global *global = ctx; |
887 | struct wpa_driver_nl80211_data *drv; | |
62d680c3 JM |
888 | int attrlen, rta_len; |
889 | struct rtattr *attr; | |
97cfcf64 | 890 | u32 brid = 0; |
aef85ba2 | 891 | char namebuf[IFNAMSIZ]; |
3f5285e8 | 892 | |
36d84860 BG |
893 | drv = nl80211_find_drv(global, ifi->ifi_index, buf, len); |
894 | if (!drv) { | |
97cfcf64 B |
895 | wpa_printf(MSG_DEBUG, "nl80211: Ignore event for foreign " |
896 | "ifindex %d", ifi->ifi_index); | |
3f5285e8 JM |
897 | return; |
898 | } | |
899 | ||
900 | wpa_printf(MSG_DEBUG, "RTM_NEWLINK: operstate=%d ifi_flags=0x%x " | |
901 | "(%s%s%s%s)", | |
902 | drv->operstate, ifi->ifi_flags, | |
903 | (ifi->ifi_flags & IFF_UP) ? "[UP]" : "", | |
904 | (ifi->ifi_flags & IFF_RUNNING) ? "[RUNNING]" : "", | |
905 | (ifi->ifi_flags & IFF_LOWER_UP) ? "[LOWER_UP]" : "", | |
906 | (ifi->ifi_flags & IFF_DORMANT) ? "[DORMANT]" : ""); | |
a63063b4 JM |
907 | |
908 | if (!drv->if_disabled && !(ifi->ifi_flags & IFF_UP)) { | |
59d24925 JM |
909 | if (if_indextoname(ifi->ifi_index, namebuf) && |
910 | linux_iface_up(drv->global->ioctl_sock, | |
911 | drv->first_bss.ifname) > 0) { | |
912 | wpa_printf(MSG_DEBUG, "nl80211: Ignore interface down " | |
913 | "event since interface %s is up", namebuf); | |
914 | return; | |
915 | } | |
a63063b4 | 916 | wpa_printf(MSG_DEBUG, "nl80211: Interface down"); |
7d9c3698 JM |
917 | if (drv->ignore_if_down_event) { |
918 | wpa_printf(MSG_DEBUG, "nl80211: Ignore interface down " | |
919 | "event generated by mode change"); | |
920 | drv->ignore_if_down_event = 0; | |
921 | } else { | |
922 | drv->if_disabled = 1; | |
923 | wpa_supplicant_event(drv->ctx, | |
924 | EVENT_INTERFACE_DISABLED, NULL); | |
925 | } | |
a63063b4 JM |
926 | } |
927 | ||
928 | if (drv->if_disabled && (ifi->ifi_flags & IFF_UP)) { | |
aef85ba2 JM |
929 | if (if_indextoname(ifi->ifi_index, namebuf) && |
930 | linux_iface_up(drv->global->ioctl_sock, | |
931 | drv->first_bss.ifname) == 0) { | |
932 | wpa_printf(MSG_DEBUG, "nl80211: Ignore interface up " | |
933 | "event since interface %s is down", | |
934 | namebuf); | |
d1f4942b JM |
935 | } else if (if_nametoindex(drv->first_bss.ifname) == 0) { |
936 | wpa_printf(MSG_DEBUG, "nl80211: Ignore interface up " | |
937 | "event since interface %s does not exist", | |
938 | drv->first_bss.ifname); | |
939 | } else if (drv->if_removed) { | |
940 | wpa_printf(MSG_DEBUG, "nl80211: Ignore interface up " | |
941 | "event since interface %s is marked " | |
942 | "removed", drv->first_bss.ifname); | |
aef85ba2 JM |
943 | } else { |
944 | wpa_printf(MSG_DEBUG, "nl80211: Interface up"); | |
945 | drv->if_disabled = 0; | |
946 | wpa_supplicant_event(drv->ctx, EVENT_INTERFACE_ENABLED, | |
947 | NULL); | |
948 | } | |
a63063b4 JM |
949 | } |
950 | ||
3f5285e8 JM |
951 | /* |
952 | * Some drivers send the association event before the operup event--in | |
953 | * this case, lifting operstate in wpa_driver_nl80211_set_operstate() | |
954 | * fails. This will hit us when wpa_supplicant does not need to do | |
955 | * IEEE 802.1X authentication | |
956 | */ | |
957 | if (drv->operstate == 1 && | |
958 | (ifi->ifi_flags & (IFF_LOWER_UP | IFF_DORMANT)) == IFF_LOWER_UP && | |
959 | !(ifi->ifi_flags & IFF_RUNNING)) | |
36d84860 | 960 | netlink_send_oper_ifla(drv->global->netlink, drv->ifindex, |
e2d02c29 | 961 | -1, IF_OPER_UP); |
3f5285e8 | 962 | |
62d680c3 JM |
963 | attrlen = len; |
964 | attr = (struct rtattr *) buf; | |
3f5285e8 JM |
965 | rta_len = RTA_ALIGN(sizeof(struct rtattr)); |
966 | while (RTA_OK(attr, attrlen)) { | |
d8816397 | 967 | if (attr->rta_type == IFLA_IFNAME) { |
7524cfb1 | 968 | wpa_driver_nl80211_event_link( |
08063178 | 969 | drv, |
7524cfb1 JM |
970 | ((char *) attr) + rta_len, |
971 | attr->rta_len - rta_len, 0); | |
97cfcf64 B |
972 | } else if (attr->rta_type == IFLA_MASTER) |
973 | brid = nla_get_u32((struct nlattr *) attr); | |
3f5285e8 JM |
974 | attr = RTA_NEXT(attr, attrlen); |
975 | } | |
97cfcf64 B |
976 | |
977 | if (ifi->ifi_family == AF_BRIDGE && brid) { | |
978 | /* device has been added to bridge */ | |
97cfcf64 B |
979 | if_indextoname(brid, namebuf); |
980 | wpa_printf(MSG_DEBUG, "nl80211: Add ifindex %u for bridge %s", | |
981 | brid, namebuf); | |
982 | add_ifidx(drv, brid); | |
983 | } | |
3f5285e8 JM |
984 | } |
985 | ||
986 | ||
62d680c3 JM |
987 | static void wpa_driver_nl80211_event_rtm_dellink(void *ctx, |
988 | struct ifinfomsg *ifi, | |
989 | u8 *buf, size_t len) | |
3f5285e8 | 990 | { |
36d84860 BG |
991 | struct nl80211_global *global = ctx; |
992 | struct wpa_driver_nl80211_data *drv; | |
62d680c3 JM |
993 | int attrlen, rta_len; |
994 | struct rtattr *attr; | |
97cfcf64 | 995 | u32 brid = 0; |
3f5285e8 | 996 | |
36d84860 BG |
997 | drv = nl80211_find_drv(global, ifi->ifi_index, buf, len); |
998 | if (!drv) { | |
999 | wpa_printf(MSG_DEBUG, "nl80211: Ignore dellink event for " | |
1000 | "foreign ifindex %d", ifi->ifi_index); | |
1001 | return; | |
1002 | } | |
1003 | ||
62d680c3 JM |
1004 | attrlen = len; |
1005 | attr = (struct rtattr *) buf; | |
3f5285e8 JM |
1006 | |
1007 | rta_len = RTA_ALIGN(sizeof(struct rtattr)); | |
1008 | while (RTA_OK(attr, attrlen)) { | |
1009 | if (attr->rta_type == IFLA_IFNAME) { | |
7524cfb1 | 1010 | wpa_driver_nl80211_event_link( |
08063178 | 1011 | drv, |
7524cfb1 JM |
1012 | ((char *) attr) + rta_len, |
1013 | attr->rta_len - rta_len, 1); | |
97cfcf64 B |
1014 | } else if (attr->rta_type == IFLA_MASTER) |
1015 | brid = nla_get_u32((struct nlattr *) attr); | |
3f5285e8 JM |
1016 | attr = RTA_NEXT(attr, attrlen); |
1017 | } | |
97cfcf64 B |
1018 | |
1019 | if (ifi->ifi_family == AF_BRIDGE && brid) { | |
1020 | /* device has been removed from bridge */ | |
1021 | char namebuf[IFNAMSIZ]; | |
1022 | if_indextoname(brid, namebuf); | |
1023 | wpa_printf(MSG_DEBUG, "nl80211: Remove ifindex %u for bridge " | |
1024 | "%s", brid, namebuf); | |
1025 | del_ifidx(drv, brid); | |
1026 | } | |
3f5285e8 JM |
1027 | } |
1028 | ||
1029 | ||
c2a04078 JM |
1030 | static void mlme_event_auth(struct wpa_driver_nl80211_data *drv, |
1031 | const u8 *frame, size_t len) | |
1032 | { | |
1033 | const struct ieee80211_mgmt *mgmt; | |
1034 | union wpa_event_data event; | |
1035 | ||
7d81932d | 1036 | wpa_printf(MSG_DEBUG, "nl80211: Authenticate event"); |
c2a04078 JM |
1037 | mgmt = (const struct ieee80211_mgmt *) frame; |
1038 | if (len < 24 + sizeof(mgmt->u.auth)) { | |
1039 | wpa_printf(MSG_DEBUG, "nl80211: Too short association event " | |
1040 | "frame"); | |
1041 | return; | |
1042 | } | |
1043 | ||
e6b8efeb | 1044 | os_memcpy(drv->auth_bssid, mgmt->sa, ETH_ALEN); |
c2a04078 JM |
1045 | os_memset(&event, 0, sizeof(event)); |
1046 | os_memcpy(event.auth.peer, mgmt->sa, ETH_ALEN); | |
1047 | event.auth.auth_type = le_to_host16(mgmt->u.auth.auth_alg); | |
569fed90 JM |
1048 | event.auth.auth_transaction = |
1049 | le_to_host16(mgmt->u.auth.auth_transaction); | |
c2a04078 JM |
1050 | event.auth.status_code = le_to_host16(mgmt->u.auth.status_code); |
1051 | if (len > 24 + sizeof(mgmt->u.auth)) { | |
1052 | event.auth.ies = mgmt->u.auth.variable; | |
1053 | event.auth.ies_len = len - 24 - sizeof(mgmt->u.auth); | |
1054 | } | |
1055 | ||
1056 | wpa_supplicant_event(drv->ctx, EVENT_AUTH, &event); | |
1057 | } | |
1058 | ||
1059 | ||
f5a8d422 JM |
1060 | static unsigned int nl80211_get_assoc_freq(struct wpa_driver_nl80211_data *drv) |
1061 | { | |
1062 | struct nl_msg *msg; | |
1063 | int ret; | |
1064 | struct nl80211_bss_info_arg arg; | |
1065 | ||
1066 | os_memset(&arg, 0, sizeof(arg)); | |
1067 | msg = nlmsg_alloc(); | |
1068 | if (!msg) | |
1069 | goto nla_put_failure; | |
1070 | ||
9fb04070 | 1071 | nl80211_cmd(drv, msg, NLM_F_DUMP, NL80211_CMD_GET_SCAN); |
f5a8d422 JM |
1072 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, drv->ifindex); |
1073 | ||
1074 | arg.drv = drv; | |
1075 | ret = send_and_recv_msgs(drv, msg, bss_info_handler, &arg); | |
1076 | msg = NULL; | |
1077 | if (ret == 0) { | |
1078 | wpa_printf(MSG_DEBUG, "nl80211: Operating frequency for the " | |
1079 | "associated BSS from scan results: %u MHz", | |
1080 | arg.assoc_freq); | |
1081 | return arg.assoc_freq ? arg.assoc_freq : drv->assoc_freq; | |
1082 | } | |
1083 | wpa_printf(MSG_DEBUG, "nl80211: Scan result fetch failed: ret=%d " | |
1084 | "(%s)", ret, strerror(-ret)); | |
1085 | nla_put_failure: | |
1086 | nlmsg_free(msg); | |
1087 | return drv->assoc_freq; | |
1088 | } | |
1089 | ||
1090 | ||
c2a04078 JM |
1091 | static void mlme_event_assoc(struct wpa_driver_nl80211_data *drv, |
1092 | const u8 *frame, size_t len) | |
1093 | { | |
1094 | const struct ieee80211_mgmt *mgmt; | |
1095 | union wpa_event_data event; | |
1096 | u16 status; | |
1097 | ||
7d81932d | 1098 | wpa_printf(MSG_DEBUG, "nl80211: Associate event"); |
c2a04078 JM |
1099 | mgmt = (const struct ieee80211_mgmt *) frame; |
1100 | if (len < 24 + sizeof(mgmt->u.assoc_resp)) { | |
1101 | wpa_printf(MSG_DEBUG, "nl80211: Too short association event " | |
1102 | "frame"); | |
1103 | return; | |
1104 | } | |
1105 | ||
1106 | status = le_to_host16(mgmt->u.assoc_resp.status_code); | |
1107 | if (status != WLAN_STATUS_SUCCESS) { | |
efa46078 | 1108 | os_memset(&event, 0, sizeof(event)); |
59ddf221 | 1109 | event.assoc_reject.bssid = mgmt->bssid; |
efa46078 JM |
1110 | if (len > 24 + sizeof(mgmt->u.assoc_resp)) { |
1111 | event.assoc_reject.resp_ies = | |
1112 | (u8 *) mgmt->u.assoc_resp.variable; | |
1113 | event.assoc_reject.resp_ies_len = | |
1114 | len - 24 - sizeof(mgmt->u.assoc_resp); | |
1115 | } | |
1116 | event.assoc_reject.status_code = status; | |
1117 | ||
1118 | wpa_supplicant_event(drv->ctx, EVENT_ASSOC_REJECT, &event); | |
c2a04078 JM |
1119 | return; |
1120 | } | |
1121 | ||
1122 | drv->associated = 1; | |
1123 | os_memcpy(drv->bssid, mgmt->sa, ETH_ALEN); | |
1124 | ||
1125 | os_memset(&event, 0, sizeof(event)); | |
1126 | if (len > 24 + sizeof(mgmt->u.assoc_resp)) { | |
1127 | event.assoc_info.resp_ies = (u8 *) mgmt->u.assoc_resp.variable; | |
1128 | event.assoc_info.resp_ies_len = | |
efa46078 | 1129 | len - 24 - sizeof(mgmt->u.assoc_resp); |
c2a04078 JM |
1130 | } |
1131 | ||
4832ecd7 JM |
1132 | event.assoc_info.freq = drv->assoc_freq; |
1133 | ||
c2a04078 JM |
1134 | wpa_supplicant_event(drv->ctx, EVENT_ASSOC, &event); |
1135 | } | |
1136 | ||
c1bb3e0a | 1137 | |
da72a1c1 ZY |
1138 | static void mlme_event_connect(struct wpa_driver_nl80211_data *drv, |
1139 | enum nl80211_commands cmd, struct nlattr *status, | |
1140 | struct nlattr *addr, struct nlattr *req_ie, | |
1141 | struct nlattr *resp_ie) | |
1142 | { | |
1143 | union wpa_event_data event; | |
1144 | ||
7da2c527 JM |
1145 | if (drv->capa.flags & WPA_DRIVER_FLAGS_SME) { |
1146 | /* | |
1147 | * Avoid reporting two association events that would confuse | |
1148 | * the core code. | |
1149 | */ | |
1150 | wpa_printf(MSG_DEBUG, "nl80211: Ignore connect event (cmd=%d) " | |
1151 | "when using userspace SME", cmd); | |
1152 | return; | |
1153 | } | |
1154 | ||
7d81932d JM |
1155 | if (cmd == NL80211_CMD_CONNECT) |
1156 | wpa_printf(MSG_DEBUG, "nl80211: Connect event"); | |
1157 | else if (cmd == NL80211_CMD_ROAM) | |
1158 | wpa_printf(MSG_DEBUG, "nl80211: Roam event"); | |
1159 | ||
da72a1c1 ZY |
1160 | os_memset(&event, 0, sizeof(event)); |
1161 | if (cmd == NL80211_CMD_CONNECT && | |
1162 | nla_get_u16(status) != WLAN_STATUS_SUCCESS) { | |
df89c1c8 JM |
1163 | if (addr) |
1164 | event.assoc_reject.bssid = nla_data(addr); | |
da72a1c1 ZY |
1165 | if (resp_ie) { |
1166 | event.assoc_reject.resp_ies = nla_data(resp_ie); | |
1167 | event.assoc_reject.resp_ies_len = nla_len(resp_ie); | |
1168 | } | |
1169 | event.assoc_reject.status_code = nla_get_u16(status); | |
1170 | wpa_supplicant_event(drv->ctx, EVENT_ASSOC_REJECT, &event); | |
1171 | return; | |
1172 | } | |
1173 | ||
1174 | drv->associated = 1; | |
1175 | if (addr) | |
1176 | os_memcpy(drv->bssid, nla_data(addr), ETH_ALEN); | |
1177 | ||
1178 | if (req_ie) { | |
1179 | event.assoc_info.req_ies = nla_data(req_ie); | |
1180 | event.assoc_info.req_ies_len = nla_len(req_ie); | |
1181 | } | |
1182 | if (resp_ie) { | |
1183 | event.assoc_info.resp_ies = nla_data(resp_ie); | |
1184 | event.assoc_info.resp_ies_len = nla_len(resp_ie); | |
1185 | } | |
1186 | ||
f5a8d422 JM |
1187 | event.assoc_info.freq = nl80211_get_assoc_freq(drv); |
1188 | ||
da72a1c1 ZY |
1189 | wpa_supplicant_event(drv->ctx, EVENT_ASSOC, &event); |
1190 | } | |
c2a04078 | 1191 | |
c1bb3e0a | 1192 | |
20f5a4c2 | 1193 | static void mlme_event_disconnect(struct wpa_driver_nl80211_data *drv, |
3d9975d5 JM |
1194 | struct nlattr *reason, struct nlattr *addr, |
1195 | struct nlattr *by_ap) | |
20f5a4c2 JM |
1196 | { |
1197 | union wpa_event_data data; | |
a8c5b43a | 1198 | unsigned int locally_generated = by_ap == NULL; |
20f5a4c2 JM |
1199 | |
1200 | if (drv->capa.flags & WPA_DRIVER_FLAGS_SME) { | |
1201 | /* | |
1202 | * Avoid reporting two disassociation events that could | |
1203 | * confuse the core code. | |
1204 | */ | |
1205 | wpa_printf(MSG_DEBUG, "nl80211: Ignore disconnect " | |
1206 | "event when using userspace SME"); | |
1207 | return; | |
1208 | } | |
1209 | ||
a8c5b43a CW |
1210 | if (drv->ignore_next_local_disconnect) { |
1211 | drv->ignore_next_local_disconnect = 0; | |
1212 | if (locally_generated) { | |
1213 | wpa_printf(MSG_DEBUG, "nl80211: Ignore disconnect " | |
1214 | "event triggered during reassociation"); | |
1215 | return; | |
1216 | } | |
1217 | wpa_printf(MSG_WARNING, "nl80211: Was expecting local " | |
1218 | "disconnect but got another disconnect " | |
1219 | "event first"); | |
1220 | } | |
1221 | ||
7d81932d | 1222 | wpa_printf(MSG_DEBUG, "nl80211: Disconnect event"); |
20f5a4c2 JM |
1223 | drv->associated = 0; |
1224 | os_memset(&data, 0, sizeof(data)); | |
1225 | if (reason) | |
2e9f078c JM |
1226 | data.deauth_info.reason_code = nla_get_u16(reason); |
1227 | data.deauth_info.locally_generated = by_ap == NULL; | |
1228 | wpa_supplicant_event(drv->ctx, EVENT_DEAUTH, &data); | |
20f5a4c2 JM |
1229 | } |
1230 | ||
1231 | ||
1b487b8b TP |
1232 | static void mlme_event_ch_switch(struct wpa_driver_nl80211_data *drv, |
1233 | struct nlattr *freq, struct nlattr *type) | |
1234 | { | |
1235 | union wpa_event_data data; | |
1236 | int ht_enabled = 1; | |
1237 | int chan_offset = 0; | |
1238 | ||
1239 | wpa_printf(MSG_DEBUG, "nl80211: Channel switch event"); | |
1240 | ||
1241 | if (!freq || !type) | |
1242 | return; | |
1243 | ||
1244 | switch (nla_get_u32(type)) { | |
1245 | case NL80211_CHAN_NO_HT: | |
1246 | ht_enabled = 0; | |
1247 | break; | |
1248 | case NL80211_CHAN_HT20: | |
1249 | break; | |
1250 | case NL80211_CHAN_HT40PLUS: | |
1251 | chan_offset = 1; | |
1252 | break; | |
1253 | case NL80211_CHAN_HT40MINUS: | |
1254 | chan_offset = -1; | |
1255 | break; | |
1256 | } | |
1257 | ||
1258 | data.ch_switch.freq = nla_get_u32(freq); | |
1259 | data.ch_switch.ht_enabled = ht_enabled; | |
1260 | data.ch_switch.ch_offset = chan_offset; | |
1261 | ||
1262 | wpa_supplicant_event(drv->ctx, EVENT_CH_SWITCH, &data); | |
1263 | } | |
1264 | ||
1265 | ||
da1fb17c JM |
1266 | static void mlme_timeout_event(struct wpa_driver_nl80211_data *drv, |
1267 | enum nl80211_commands cmd, struct nlattr *addr) | |
1268 | { | |
1269 | union wpa_event_data event; | |
1270 | enum wpa_event_type ev; | |
1271 | ||
1272 | if (nla_len(addr) != ETH_ALEN) | |
1273 | return; | |
1274 | ||
1275 | wpa_printf(MSG_DEBUG, "nl80211: MLME event %d; timeout with " MACSTR, | |
1276 | cmd, MAC2STR((u8 *) nla_data(addr))); | |
1277 | ||
1278 | if (cmd == NL80211_CMD_AUTHENTICATE) | |
1279 | ev = EVENT_AUTH_TIMED_OUT; | |
1280 | else if (cmd == NL80211_CMD_ASSOCIATE) | |
1281 | ev = EVENT_ASSOC_TIMED_OUT; | |
1282 | else | |
1283 | return; | |
1284 | ||
1285 | os_memset(&event, 0, sizeof(event)); | |
1286 | os_memcpy(event.timeout_event.addr, nla_data(addr), ETH_ALEN); | |
1287 | wpa_supplicant_event(drv->ctx, ev, &event); | |
1288 | } | |
1289 | ||
1290 | ||
5582a5d1 | 1291 | static void mlme_event_mgmt(struct wpa_driver_nl80211_data *drv, |
da873dbb JB |
1292 | struct nlattr *freq, struct nlattr *sig, |
1293 | const u8 *frame, size_t len) | |
58f6fbe0 JM |
1294 | { |
1295 | const struct ieee80211_mgmt *mgmt; | |
1296 | union wpa_event_data event; | |
1297 | u16 fc, stype; | |
da873dbb | 1298 | int ssi_signal = 0; |
58f6fbe0 | 1299 | |
7d81932d | 1300 | wpa_printf(MSG_DEBUG, "nl80211: Frame event"); |
58f6fbe0 JM |
1301 | mgmt = (const struct ieee80211_mgmt *) frame; |
1302 | if (len < 24) { | |
1303 | wpa_printf(MSG_DEBUG, "nl80211: Too short action frame"); | |
1304 | return; | |
1305 | } | |
1306 | ||
1307 | fc = le_to_host16(mgmt->frame_control); | |
1308 | stype = WLAN_FC_GET_STYPE(fc); | |
1309 | ||
da873dbb JB |
1310 | if (sig) |
1311 | ssi_signal = (s32) nla_get_u32(sig); | |
1312 | ||
58f6fbe0 | 1313 | os_memset(&event, 0, sizeof(event)); |
5582a5d1 | 1314 | if (freq) { |
58f6fbe0 | 1315 | event.rx_action.freq = nla_get_u32(freq); |
5582a5d1 JB |
1316 | drv->last_mgmt_freq = event.rx_action.freq; |
1317 | } | |
1318 | if (stype == WLAN_FC_STYPE_ACTION) { | |
1319 | event.rx_action.da = mgmt->da; | |
1320 | event.rx_action.sa = mgmt->sa; | |
1321 | event.rx_action.bssid = mgmt->bssid; | |
1322 | event.rx_action.category = mgmt->u.action.category; | |
1323 | event.rx_action.data = &mgmt->u.action.category + 1; | |
1324 | event.rx_action.len = frame + len - event.rx_action.data; | |
1325 | wpa_supplicant_event(drv->ctx, EVENT_RX_ACTION, &event); | |
1326 | } else { | |
1327 | event.rx_mgmt.frame = frame; | |
1328 | event.rx_mgmt.frame_len = len; | |
da873dbb | 1329 | event.rx_mgmt.ssi_signal = ssi_signal; |
5582a5d1 JB |
1330 | wpa_supplicant_event(drv->ctx, EVENT_RX_MGMT, &event); |
1331 | } | |
58f6fbe0 JM |
1332 | } |
1333 | ||
1334 | ||
a11241fa JB |
1335 | static void mlme_event_mgmt_tx_status(struct wpa_driver_nl80211_data *drv, |
1336 | struct nlattr *cookie, const u8 *frame, | |
1337 | size_t len, struct nlattr *ack) | |
58f6fbe0 JM |
1338 | { |
1339 | union wpa_event_data event; | |
1340 | const struct ieee80211_hdr *hdr; | |
1341 | u16 fc; | |
58f6fbe0 | 1342 | |
7d81932d | 1343 | wpa_printf(MSG_DEBUG, "nl80211: Frame TX status event"); |
a11241fa JB |
1344 | if (!is_ap_interface(drv->nlmode)) { |
1345 | u64 cookie_val; | |
58f6fbe0 | 1346 | |
a11241fa JB |
1347 | if (!cookie) |
1348 | return; | |
1349 | ||
1350 | cookie_val = nla_get_u64(cookie); | |
1351 | wpa_printf(MSG_DEBUG, "nl80211: Action TX status:" | |
1352 | " cookie=0%llx%s (ack=%d)", | |
1353 | (long long unsigned int) cookie_val, | |
1354 | cookie_val == drv->send_action_cookie ? | |
1355 | " (match)" : " (unknown)", ack != NULL); | |
1356 | if (cookie_val != drv->send_action_cookie) | |
1357 | return; | |
1358 | } | |
58f6fbe0 JM |
1359 | |
1360 | hdr = (const struct ieee80211_hdr *) frame; | |
1361 | fc = le_to_host16(hdr->frame_control); | |
1362 | ||
1363 | os_memset(&event, 0, sizeof(event)); | |
1364 | event.tx_status.type = WLAN_FC_GET_TYPE(fc); | |
1365 | event.tx_status.stype = WLAN_FC_GET_STYPE(fc); | |
1366 | event.tx_status.dst = hdr->addr1; | |
1367 | event.tx_status.data = frame; | |
1368 | event.tx_status.data_len = len; | |
1369 | event.tx_status.ack = ack != NULL; | |
1370 | wpa_supplicant_event(drv->ctx, EVENT_TX_STATUS, &event); | |
1371 | } | |
1372 | ||
1373 | ||
0544b242 JM |
1374 | static void mlme_event_deauth_disassoc(struct wpa_driver_nl80211_data *drv, |
1375 | enum wpa_event_type type, | |
1376 | const u8 *frame, size_t len) | |
1377 | { | |
1378 | const struct ieee80211_mgmt *mgmt; | |
1379 | union wpa_event_data event; | |
1380 | const u8 *bssid = NULL; | |
1381 | u16 reason_code = 0; | |
1382 | ||
7d81932d JM |
1383 | if (type == EVENT_DEAUTH) |
1384 | wpa_printf(MSG_DEBUG, "nl80211: Deauthenticate event"); | |
1385 | else | |
1386 | wpa_printf(MSG_DEBUG, "nl80211: Disassociate event"); | |
1387 | ||
cb30b297 PS |
1388 | mgmt = (const struct ieee80211_mgmt *) frame; |
1389 | if (len >= 24) { | |
1390 | bssid = mgmt->bssid; | |
1391 | ||
1392 | if (drv->associated != 0 && | |
1393 | os_memcmp(bssid, drv->bssid, ETH_ALEN) != 0 && | |
1394 | os_memcmp(bssid, drv->auth_bssid, ETH_ALEN) != 0) { | |
1395 | /* | |
1396 | * We have presumably received this deauth as a | |
1397 | * response to a clear_state_mismatch() outgoing | |
1398 | * deauth. Don't let it take us offline! | |
1399 | */ | |
1400 | wpa_printf(MSG_DEBUG, "nl80211: Deauth received " | |
1401 | "from Unknown BSSID " MACSTR " -- ignoring", | |
1402 | MAC2STR(bssid)); | |
1403 | return; | |
1404 | } | |
1405 | } | |
1406 | ||
0544b242 JM |
1407 | drv->associated = 0; |
1408 | os_memset(&event, 0, sizeof(event)); | |
1409 | ||
0544b242 JM |
1410 | /* Note: Same offset for Reason Code in both frame subtypes */ |
1411 | if (len >= 24 + sizeof(mgmt->u.deauth)) | |
1412 | reason_code = le_to_host16(mgmt->u.deauth.reason_code); | |
1413 | ||
1414 | if (type == EVENT_DISASSOC) { | |
3d9975d5 JM |
1415 | event.disassoc_info.locally_generated = |
1416 | !os_memcmp(mgmt->sa, drv->first_bss.addr, ETH_ALEN); | |
0544b242 JM |
1417 | event.disassoc_info.addr = bssid; |
1418 | event.disassoc_info.reason_code = reason_code; | |
046b26a2 JM |
1419 | if (frame + len > mgmt->u.disassoc.variable) { |
1420 | event.disassoc_info.ie = mgmt->u.disassoc.variable; | |
1421 | event.disassoc_info.ie_len = frame + len - | |
1422 | mgmt->u.disassoc.variable; | |
1423 | } | |
0544b242 | 1424 | } else { |
3d9975d5 JM |
1425 | event.deauth_info.locally_generated = |
1426 | !os_memcmp(mgmt->sa, drv->first_bss.addr, ETH_ALEN); | |
0544b242 JM |
1427 | event.deauth_info.addr = bssid; |
1428 | event.deauth_info.reason_code = reason_code; | |
046b26a2 JM |
1429 | if (frame + len > mgmt->u.deauth.variable) { |
1430 | event.deauth_info.ie = mgmt->u.deauth.variable; | |
1431 | event.deauth_info.ie_len = frame + len - | |
1432 | mgmt->u.deauth.variable; | |
1433 | } | |
0544b242 JM |
1434 | } |
1435 | ||
1436 | wpa_supplicant_event(drv->ctx, type, &event); | |
1437 | } | |
1438 | ||
1439 | ||
7d878ca7 JM |
1440 | static void mlme_event_unprot_disconnect(struct wpa_driver_nl80211_data *drv, |
1441 | enum wpa_event_type type, | |
1442 | const u8 *frame, size_t len) | |
1443 | { | |
1444 | const struct ieee80211_mgmt *mgmt; | |
1445 | union wpa_event_data event; | |
1446 | u16 reason_code = 0; | |
1447 | ||
7d81932d JM |
1448 | if (type == EVENT_UNPROT_DEAUTH) |
1449 | wpa_printf(MSG_DEBUG, "nl80211: Unprot Deauthenticate event"); | |
1450 | else | |
1451 | wpa_printf(MSG_DEBUG, "nl80211: Unprot Disassociate event"); | |
1452 | ||
7d878ca7 JM |
1453 | if (len < 24) |
1454 | return; | |
1455 | ||
1456 | mgmt = (const struct ieee80211_mgmt *) frame; | |
1457 | ||
1458 | os_memset(&event, 0, sizeof(event)); | |
1459 | /* Note: Same offset for Reason Code in both frame subtypes */ | |
1460 | if (len >= 24 + sizeof(mgmt->u.deauth)) | |
1461 | reason_code = le_to_host16(mgmt->u.deauth.reason_code); | |
1462 | ||
1463 | if (type == EVENT_UNPROT_DISASSOC) { | |
1464 | event.unprot_disassoc.sa = mgmt->sa; | |
1465 | event.unprot_disassoc.da = mgmt->da; | |
1466 | event.unprot_disassoc.reason_code = reason_code; | |
1467 | } else { | |
1468 | event.unprot_deauth.sa = mgmt->sa; | |
1469 | event.unprot_deauth.da = mgmt->da; | |
1470 | event.unprot_deauth.reason_code = reason_code; | |
1471 | } | |
1472 | ||
1473 | wpa_supplicant_event(drv->ctx, type, &event); | |
1474 | } | |
1475 | ||
1476 | ||
c2a04078 | 1477 | static void mlme_event(struct wpa_driver_nl80211_data *drv, |
da1fb17c | 1478 | enum nl80211_commands cmd, struct nlattr *frame, |
58f6fbe0 JM |
1479 | struct nlattr *addr, struct nlattr *timed_out, |
1480 | struct nlattr *freq, struct nlattr *ack, | |
da873dbb | 1481 | struct nlattr *cookie, struct nlattr *sig) |
c2a04078 | 1482 | { |
da1fb17c JM |
1483 | if (timed_out && addr) { |
1484 | mlme_timeout_event(drv, cmd, addr); | |
1485 | return; | |
1486 | } | |
1487 | ||
c2a04078 JM |
1488 | if (frame == NULL) { |
1489 | wpa_printf(MSG_DEBUG, "nl80211: MLME event %d without frame " | |
1490 | "data", cmd); | |
1491 | return; | |
1492 | } | |
1493 | ||
1494 | wpa_printf(MSG_DEBUG, "nl80211: MLME event %d", cmd); | |
1495 | wpa_hexdump(MSG_MSGDUMP, "nl80211: MLME event frame", | |
1496 | nla_data(frame), nla_len(frame)); | |
1497 | ||
1498 | switch (cmd) { | |
1499 | case NL80211_CMD_AUTHENTICATE: | |
1500 | mlme_event_auth(drv, nla_data(frame), nla_len(frame)); | |
1501 | break; | |
1502 | case NL80211_CMD_ASSOCIATE: | |
1503 | mlme_event_assoc(drv, nla_data(frame), nla_len(frame)); | |
1504 | break; | |
1505 | case NL80211_CMD_DEAUTHENTICATE: | |
0544b242 JM |
1506 | mlme_event_deauth_disassoc(drv, EVENT_DEAUTH, |
1507 | nla_data(frame), nla_len(frame)); | |
c2a04078 JM |
1508 | break; |
1509 | case NL80211_CMD_DISASSOCIATE: | |
0544b242 JM |
1510 | mlme_event_deauth_disassoc(drv, EVENT_DISASSOC, |
1511 | nla_data(frame), nla_len(frame)); | |
c2a04078 | 1512 | break; |
bd94971e | 1513 | case NL80211_CMD_FRAME: |
da873dbb JB |
1514 | mlme_event_mgmt(drv, freq, sig, nla_data(frame), |
1515 | nla_len(frame)); | |
58f6fbe0 | 1516 | break; |
bd94971e | 1517 | case NL80211_CMD_FRAME_TX_STATUS: |
a11241fa JB |
1518 | mlme_event_mgmt_tx_status(drv, cookie, nla_data(frame), |
1519 | nla_len(frame), ack); | |
58f6fbe0 | 1520 | break; |
7d878ca7 JM |
1521 | case NL80211_CMD_UNPROT_DEAUTHENTICATE: |
1522 | mlme_event_unprot_disconnect(drv, EVENT_UNPROT_DEAUTH, | |
1523 | nla_data(frame), nla_len(frame)); | |
1524 | break; | |
1525 | case NL80211_CMD_UNPROT_DISASSOCIATE: | |
1526 | mlme_event_unprot_disconnect(drv, EVENT_UNPROT_DISASSOC, | |
1527 | nla_data(frame), nla_len(frame)); | |
1528 | break; | |
c2a04078 JM |
1529 | default: |
1530 | break; | |
1531 | } | |
1532 | } | |
1533 | ||
1534 | ||
a5e1eb20 | 1535 | static void mlme_event_michael_mic_failure(struct i802_bss *bss, |
35583f3f JM |
1536 | struct nlattr *tb[]) |
1537 | { | |
1538 | union wpa_event_data data; | |
1539 | ||
1540 | wpa_printf(MSG_DEBUG, "nl80211: MLME event Michael MIC failure"); | |
1541 | os_memset(&data, 0, sizeof(data)); | |
1542 | if (tb[NL80211_ATTR_MAC]) { | |
1543 | wpa_hexdump(MSG_DEBUG, "nl80211: Source MAC address", | |
1544 | nla_data(tb[NL80211_ATTR_MAC]), | |
1545 | nla_len(tb[NL80211_ATTR_MAC])); | |
ad1e68e6 | 1546 | data.michael_mic_failure.src = nla_data(tb[NL80211_ATTR_MAC]); |
35583f3f JM |
1547 | } |
1548 | if (tb[NL80211_ATTR_KEY_SEQ]) { | |
1549 | wpa_hexdump(MSG_DEBUG, "nl80211: TSC", | |
1550 | nla_data(tb[NL80211_ATTR_KEY_SEQ]), | |
1551 | nla_len(tb[NL80211_ATTR_KEY_SEQ])); | |
1552 | } | |
1553 | if (tb[NL80211_ATTR_KEY_TYPE]) { | |
1554 | enum nl80211_key_type key_type = | |
1555 | nla_get_u32(tb[NL80211_ATTR_KEY_TYPE]); | |
1556 | wpa_printf(MSG_DEBUG, "nl80211: Key Type %d", key_type); | |
1557 | if (key_type == NL80211_KEYTYPE_PAIRWISE) | |
1558 | data.michael_mic_failure.unicast = 1; | |
1559 | } else | |
1560 | data.michael_mic_failure.unicast = 1; | |
1561 | ||
1562 | if (tb[NL80211_ATTR_KEY_IDX]) { | |
1563 | u8 key_id = nla_get_u8(tb[NL80211_ATTR_KEY_IDX]); | |
1564 | wpa_printf(MSG_DEBUG, "nl80211: Key Id %d", key_id); | |
1565 | } | |
1566 | ||
a5e1eb20 | 1567 | wpa_supplicant_event(bss->ctx, EVENT_MICHAEL_MIC_FAILURE, &data); |
35583f3f JM |
1568 | } |
1569 | ||
1570 | ||
5cc4d64b JM |
1571 | static void mlme_event_join_ibss(struct wpa_driver_nl80211_data *drv, |
1572 | struct nlattr *tb[]) | |
1573 | { | |
1574 | if (tb[NL80211_ATTR_MAC] == NULL) { | |
1575 | wpa_printf(MSG_DEBUG, "nl80211: No address in IBSS joined " | |
1576 | "event"); | |
1577 | return; | |
1578 | } | |
1579 | os_memcpy(drv->bssid, nla_data(tb[NL80211_ATTR_MAC]), ETH_ALEN); | |
1580 | drv->associated = 1; | |
1581 | wpa_printf(MSG_DEBUG, "nl80211: IBSS " MACSTR " joined", | |
1582 | MAC2STR(drv->bssid)); | |
1583 | ||
1584 | wpa_supplicant_event(drv->ctx, EVENT_ASSOC, NULL); | |
1585 | } | |
1586 | ||
1587 | ||
55777702 JM |
1588 | static void mlme_event_remain_on_channel(struct wpa_driver_nl80211_data *drv, |
1589 | int cancel_event, struct nlattr *tb[]) | |
1590 | { | |
1591 | unsigned int freq, chan_type, duration; | |
1592 | union wpa_event_data data; | |
1593 | u64 cookie; | |
1594 | ||
1595 | if (tb[NL80211_ATTR_WIPHY_FREQ]) | |
1596 | freq = nla_get_u32(tb[NL80211_ATTR_WIPHY_FREQ]); | |
1597 | else | |
1598 | freq = 0; | |
1599 | ||
1600 | if (tb[NL80211_ATTR_WIPHY_CHANNEL_TYPE]) | |
1601 | chan_type = nla_get_u32(tb[NL80211_ATTR_WIPHY_CHANNEL_TYPE]); | |
1602 | else | |
1603 | chan_type = 0; | |
1604 | ||
1605 | if (tb[NL80211_ATTR_DURATION]) | |
1606 | duration = nla_get_u32(tb[NL80211_ATTR_DURATION]); | |
1607 | else | |
1608 | duration = 0; | |
1609 | ||
1610 | if (tb[NL80211_ATTR_COOKIE]) | |
1611 | cookie = nla_get_u64(tb[NL80211_ATTR_COOKIE]); | |
1612 | else | |
1613 | cookie = 0; | |
1614 | ||
1615 | wpa_printf(MSG_DEBUG, "nl80211: Remain-on-channel event (cancel=%d " | |
1616 | "freq=%u channel_type=%u duration=%u cookie=0x%llx (%s))", | |
1617 | cancel_event, freq, chan_type, duration, | |
1618 | (long long unsigned int) cookie, | |
1619 | cookie == drv->remain_on_chan_cookie ? "match" : "unknown"); | |
1620 | ||
1621 | if (cookie != drv->remain_on_chan_cookie) | |
1622 | return; /* not for us */ | |
1623 | ||
531f0331 JB |
1624 | if (cancel_event) |
1625 | drv->pending_remain_on_chan = 0; | |
55777702 JM |
1626 | |
1627 | os_memset(&data, 0, sizeof(data)); | |
1628 | data.remain_on_channel.freq = freq; | |
1629 | data.remain_on_channel.duration = duration; | |
1630 | wpa_supplicant_event(drv->ctx, cancel_event ? | |
1631 | EVENT_CANCEL_REMAIN_ON_CHANNEL : | |
1632 | EVENT_REMAIN_ON_CHANNEL, &data); | |
1633 | } | |
1634 | ||
1635 | ||
8d923a4a JM |
1636 | static void send_scan_event(struct wpa_driver_nl80211_data *drv, int aborted, |
1637 | struct nlattr *tb[]) | |
1638 | { | |
1639 | union wpa_event_data event; | |
1640 | struct nlattr *nl; | |
1641 | int rem; | |
1642 | struct scan_info *info; | |
1643 | #define MAX_REPORT_FREQS 50 | |
1644 | int freqs[MAX_REPORT_FREQS]; | |
1645 | int num_freqs = 0; | |
1646 | ||
536fd62d JM |
1647 | if (drv->scan_for_auth) { |
1648 | drv->scan_for_auth = 0; | |
1649 | wpa_printf(MSG_DEBUG, "nl80211: Scan results for missing " | |
1650 | "cfg80211 BSS entry"); | |
1651 | wpa_driver_nl80211_authenticate_retry(drv); | |
1652 | return; | |
1653 | } | |
1654 | ||
8d923a4a JM |
1655 | os_memset(&event, 0, sizeof(event)); |
1656 | info = &event.scan_info; | |
1657 | info->aborted = aborted; | |
1658 | ||
1659 | if (tb[NL80211_ATTR_SCAN_SSIDS]) { | |
1660 | nla_for_each_nested(nl, tb[NL80211_ATTR_SCAN_SSIDS], rem) { | |
1661 | struct wpa_driver_scan_ssid *s = | |
1662 | &info->ssids[info->num_ssids]; | |
1663 | s->ssid = nla_data(nl); | |
1664 | s->ssid_len = nla_len(nl); | |
1665 | info->num_ssids++; | |
1666 | if (info->num_ssids == WPAS_MAX_SCAN_SSIDS) | |
1667 | break; | |
1668 | } | |
1669 | } | |
1670 | if (tb[NL80211_ATTR_SCAN_FREQUENCIES]) { | |
1671 | nla_for_each_nested(nl, tb[NL80211_ATTR_SCAN_FREQUENCIES], rem) | |
1672 | { | |
1673 | freqs[num_freqs] = nla_get_u32(nl); | |
1674 | num_freqs++; | |
1675 | if (num_freqs == MAX_REPORT_FREQS - 1) | |
1676 | break; | |
1677 | } | |
1678 | info->freqs = freqs; | |
1679 | info->num_freqs = num_freqs; | |
1680 | } | |
1681 | wpa_supplicant_event(drv->ctx, EVENT_SCAN_RESULTS, &event); | |
1682 | } | |
1683 | ||
1684 | ||
60a972a6 JM |
1685 | static int get_link_signal(struct nl_msg *msg, void *arg) |
1686 | { | |
1687 | struct nlattr *tb[NL80211_ATTR_MAX + 1]; | |
1688 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); | |
1689 | struct nlattr *sinfo[NL80211_STA_INFO_MAX + 1]; | |
1690 | static struct nla_policy policy[NL80211_STA_INFO_MAX + 1] = { | |
1691 | [NL80211_STA_INFO_SIGNAL] = { .type = NLA_U8 }, | |
1692 | }; | |
7ee35bf3 PS |
1693 | struct nlattr *rinfo[NL80211_RATE_INFO_MAX + 1]; |
1694 | static struct nla_policy rate_policy[NL80211_RATE_INFO_MAX + 1] = { | |
1695 | [NL80211_RATE_INFO_BITRATE] = { .type = NLA_U16 }, | |
1696 | [NL80211_RATE_INFO_MCS] = { .type = NLA_U8 }, | |
1697 | [NL80211_RATE_INFO_40_MHZ_WIDTH] = { .type = NLA_FLAG }, | |
1698 | [NL80211_RATE_INFO_SHORT_GI] = { .type = NLA_FLAG }, | |
1699 | }; | |
1c5c7273 | 1700 | struct wpa_signal_info *sig_change = arg; |
60a972a6 JM |
1701 | |
1702 | nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), | |
1703 | genlmsg_attrlen(gnlh, 0), NULL); | |
1704 | if (!tb[NL80211_ATTR_STA_INFO] || | |
1705 | nla_parse_nested(sinfo, NL80211_STA_INFO_MAX, | |
1706 | tb[NL80211_ATTR_STA_INFO], policy)) | |
1707 | return NL_SKIP; | |
1708 | if (!sinfo[NL80211_STA_INFO_SIGNAL]) | |
1709 | return NL_SKIP; | |
1710 | ||
7ee35bf3 PS |
1711 | sig_change->current_signal = |
1712 | (s8) nla_get_u8(sinfo[NL80211_STA_INFO_SIGNAL]); | |
1713 | ||
1714 | if (sinfo[NL80211_STA_INFO_TX_BITRATE]) { | |
1715 | if (nla_parse_nested(rinfo, NL80211_RATE_INFO_MAX, | |
1716 | sinfo[NL80211_STA_INFO_TX_BITRATE], | |
1717 | rate_policy)) { | |
1718 | sig_change->current_txrate = 0; | |
1719 | } else { | |
1720 | if (rinfo[NL80211_RATE_INFO_BITRATE]) { | |
1721 | sig_change->current_txrate = | |
1722 | nla_get_u16(rinfo[ | |
1723 | NL80211_RATE_INFO_BITRATE]) * 100; | |
1724 | } | |
1725 | } | |
1726 | } | |
1727 | ||
60a972a6 JM |
1728 | return NL_SKIP; |
1729 | } | |
1730 | ||
1731 | ||
1732 | static int nl80211_get_link_signal(struct wpa_driver_nl80211_data *drv, | |
1c5c7273 | 1733 | struct wpa_signal_info *sig) |
60a972a6 JM |
1734 | { |
1735 | struct nl_msg *msg; | |
1736 | ||
7ee35bf3 PS |
1737 | sig->current_signal = -9999; |
1738 | sig->current_txrate = 0; | |
60a972a6 JM |
1739 | |
1740 | msg = nlmsg_alloc(); | |
1741 | if (!msg) | |
1742 | return -ENOMEM; | |
1743 | ||
9fb04070 | 1744 | nl80211_cmd(drv, msg, 0, NL80211_CMD_GET_STATION); |
60a972a6 JM |
1745 | |
1746 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, drv->ifindex); | |
1747 | NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, drv->bssid); | |
1748 | ||
1749 | return send_and_recv_msgs(drv, msg, get_link_signal, sig); | |
1750 | nla_put_failure: | |
5883168a | 1751 | nlmsg_free(msg); |
60a972a6 JM |
1752 | return -ENOBUFS; |
1753 | } | |
1754 | ||
1755 | ||
7ee35bf3 PS |
1756 | static int get_link_noise(struct nl_msg *msg, void *arg) |
1757 | { | |
1758 | struct nlattr *tb[NL80211_ATTR_MAX + 1]; | |
1759 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); | |
1760 | struct nlattr *sinfo[NL80211_SURVEY_INFO_MAX + 1]; | |
1761 | static struct nla_policy survey_policy[NL80211_SURVEY_INFO_MAX + 1] = { | |
1762 | [NL80211_SURVEY_INFO_FREQUENCY] = { .type = NLA_U32 }, | |
1763 | [NL80211_SURVEY_INFO_NOISE] = { .type = NLA_U8 }, | |
1764 | }; | |
1c5c7273 | 1765 | struct wpa_signal_info *sig_change = arg; |
7ee35bf3 PS |
1766 | |
1767 | nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), | |
1768 | genlmsg_attrlen(gnlh, 0), NULL); | |
1769 | ||
1770 | if (!tb[NL80211_ATTR_SURVEY_INFO]) { | |
1771 | wpa_printf(MSG_DEBUG, "nl80211: survey data missing!"); | |
1772 | return NL_SKIP; | |
1773 | } | |
1774 | ||
1775 | if (nla_parse_nested(sinfo, NL80211_SURVEY_INFO_MAX, | |
1776 | tb[NL80211_ATTR_SURVEY_INFO], | |
1777 | survey_policy)) { | |
1778 | wpa_printf(MSG_DEBUG, "nl80211: failed to parse nested " | |
1779 | "attributes!"); | |
1780 | return NL_SKIP; | |
1781 | } | |
1782 | ||
1783 | if (!sinfo[NL80211_SURVEY_INFO_FREQUENCY]) | |
1784 | return NL_SKIP; | |
1785 | ||
1786 | if (nla_get_u32(sinfo[NL80211_SURVEY_INFO_FREQUENCY]) != | |
1787 | sig_change->frequency) | |
1788 | return NL_SKIP; | |
1789 | ||
1790 | if (!sinfo[NL80211_SURVEY_INFO_NOISE]) | |
1791 | return NL_SKIP; | |
1792 | ||
1793 | sig_change->current_noise = | |
1794 | (s8) nla_get_u8(sinfo[NL80211_SURVEY_INFO_NOISE]); | |
1795 | ||
1796 | return NL_SKIP; | |
1797 | } | |
1798 | ||
1799 | ||
1800 | static int nl80211_get_link_noise(struct wpa_driver_nl80211_data *drv, | |
1c5c7273 | 1801 | struct wpa_signal_info *sig_change) |
7ee35bf3 PS |
1802 | { |
1803 | struct nl_msg *msg; | |
1804 | ||
1805 | sig_change->current_noise = 9999; | |
1806 | sig_change->frequency = drv->assoc_freq; | |
1807 | ||
1808 | msg = nlmsg_alloc(); | |
1809 | if (!msg) | |
1810 | return -ENOMEM; | |
1811 | ||
9fb04070 | 1812 | nl80211_cmd(drv, msg, NLM_F_DUMP, NL80211_CMD_GET_SURVEY); |
7ee35bf3 PS |
1813 | |
1814 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, drv->ifindex); | |
1815 | ||
1816 | return send_and_recv_msgs(drv, msg, get_link_noise, sig_change); | |
1817 | nla_put_failure: | |
5883168a | 1818 | nlmsg_free(msg); |
7ee35bf3 PS |
1819 | return -ENOBUFS; |
1820 | } | |
1821 | ||
1822 | ||
577db0ae GM |
1823 | static int get_noise_for_scan_results(struct nl_msg *msg, void *arg) |
1824 | { | |
1825 | struct nlattr *tb[NL80211_ATTR_MAX + 1]; | |
1826 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); | |
1827 | struct nlattr *sinfo[NL80211_SURVEY_INFO_MAX + 1]; | |
1828 | static struct nla_policy survey_policy[NL80211_SURVEY_INFO_MAX + 1] = { | |
1829 | [NL80211_SURVEY_INFO_FREQUENCY] = { .type = NLA_U32 }, | |
1830 | [NL80211_SURVEY_INFO_NOISE] = { .type = NLA_U8 }, | |
1831 | }; | |
1832 | struct wpa_scan_results *scan_results = arg; | |
1833 | struct wpa_scan_res *scan_res; | |
1834 | size_t i; | |
1835 | ||
1836 | nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), | |
1837 | genlmsg_attrlen(gnlh, 0), NULL); | |
1838 | ||
1839 | if (!tb[NL80211_ATTR_SURVEY_INFO]) { | |
1840 | wpa_printf(MSG_DEBUG, "nl80211: Survey data missing"); | |
1841 | return NL_SKIP; | |
1842 | } | |
1843 | ||
1844 | if (nla_parse_nested(sinfo, NL80211_SURVEY_INFO_MAX, | |
1845 | tb[NL80211_ATTR_SURVEY_INFO], | |
1846 | survey_policy)) { | |
1847 | wpa_printf(MSG_DEBUG, "nl80211: Failed to parse nested " | |
1848 | "attributes"); | |
1849 | return NL_SKIP; | |
1850 | } | |
1851 | ||
1852 | if (!sinfo[NL80211_SURVEY_INFO_NOISE]) | |
1853 | return NL_SKIP; | |
1854 | ||
1855 | if (!sinfo[NL80211_SURVEY_INFO_FREQUENCY]) | |
1856 | return NL_SKIP; | |
1857 | ||
1858 | for (i = 0; i < scan_results->num; ++i) { | |
1859 | scan_res = scan_results->res[i]; | |
1860 | if (!scan_res) | |
1861 | continue; | |
1862 | if ((int) nla_get_u32(sinfo[NL80211_SURVEY_INFO_FREQUENCY]) != | |
1863 | scan_res->freq) | |
1864 | continue; | |
1865 | if (!(scan_res->flags & WPA_SCAN_NOISE_INVALID)) | |
1866 | continue; | |
1867 | scan_res->noise = (s8) | |
1868 | nla_get_u8(sinfo[NL80211_SURVEY_INFO_NOISE]); | |
1869 | scan_res->flags &= ~WPA_SCAN_NOISE_INVALID; | |
1870 | } | |
1871 | ||
1872 | return NL_SKIP; | |
1873 | } | |
1874 | ||
1875 | ||
1876 | static int nl80211_get_noise_for_scan_results( | |
1877 | struct wpa_driver_nl80211_data *drv, | |
1878 | struct wpa_scan_results *scan_res) | |
1879 | { | |
1880 | struct nl_msg *msg; | |
1881 | ||
1882 | msg = nlmsg_alloc(); | |
1883 | if (!msg) | |
1884 | return -ENOMEM; | |
1885 | ||
1886 | nl80211_cmd(drv, msg, NLM_F_DUMP, NL80211_CMD_GET_SURVEY); | |
1887 | ||
1888 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, drv->ifindex); | |
1889 | ||
1890 | return send_and_recv_msgs(drv, msg, get_noise_for_scan_results, | |
1891 | scan_res); | |
1892 | nla_put_failure: | |
9e088e74 | 1893 | nlmsg_free(msg); |
577db0ae GM |
1894 | return -ENOBUFS; |
1895 | } | |
1896 | ||
1897 | ||
93910401 JM |
1898 | static void nl80211_cqm_event(struct wpa_driver_nl80211_data *drv, |
1899 | struct nlattr *tb[]) | |
1900 | { | |
1901 | static struct nla_policy cqm_policy[NL80211_ATTR_CQM_MAX + 1] = { | |
1902 | [NL80211_ATTR_CQM_RSSI_THOLD] = { .type = NLA_U32 }, | |
1903 | [NL80211_ATTR_CQM_RSSI_HYST] = { .type = NLA_U8 }, | |
1904 | [NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT] = { .type = NLA_U32 }, | |
0d7e5a3a | 1905 | [NL80211_ATTR_CQM_PKT_LOSS_EVENT] = { .type = NLA_U32 }, |
93910401 JM |
1906 | }; |
1907 | struct nlattr *cqm[NL80211_ATTR_CQM_MAX + 1]; | |
1908 | enum nl80211_cqm_rssi_threshold_event event; | |
b625473c | 1909 | union wpa_event_data ed; |
1c5c7273 | 1910 | struct wpa_signal_info sig; |
7ee35bf3 | 1911 | int res; |
93910401 JM |
1912 | |
1913 | if (tb[NL80211_ATTR_CQM] == NULL || | |
1914 | nla_parse_nested(cqm, NL80211_ATTR_CQM_MAX, tb[NL80211_ATTR_CQM], | |
1915 | cqm_policy)) { | |
1916 | wpa_printf(MSG_DEBUG, "nl80211: Ignore invalid CQM event"); | |
1917 | return; | |
1918 | } | |
1919 | ||
0d7e5a3a JB |
1920 | os_memset(&ed, 0, sizeof(ed)); |
1921 | ||
1922 | if (cqm[NL80211_ATTR_CQM_PKT_LOSS_EVENT]) { | |
1923 | if (!tb[NL80211_ATTR_MAC]) | |
1924 | return; | |
1925 | os_memcpy(ed.low_ack.addr, nla_data(tb[NL80211_ATTR_MAC]), | |
1926 | ETH_ALEN); | |
1927 | wpa_supplicant_event(drv->ctx, EVENT_STATION_LOW_ACK, &ed); | |
1928 | return; | |
1929 | } | |
1930 | ||
93910401 JM |
1931 | if (cqm[NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT] == NULL) |
1932 | return; | |
1933 | event = nla_get_u32(cqm[NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT]); | |
b625473c | 1934 | |
93910401 JM |
1935 | if (event == NL80211_CQM_RSSI_THRESHOLD_EVENT_HIGH) { |
1936 | wpa_printf(MSG_DEBUG, "nl80211: Connection quality monitor " | |
1937 | "event: RSSI high"); | |
b625473c | 1938 | ed.signal_change.above_threshold = 1; |
93910401 JM |
1939 | } else if (event == NL80211_CQM_RSSI_THRESHOLD_EVENT_LOW) { |
1940 | wpa_printf(MSG_DEBUG, "nl80211: Connection quality monitor " | |
1941 | "event: RSSI low"); | |
b625473c JM |
1942 | ed.signal_change.above_threshold = 0; |
1943 | } else | |
1944 | return; | |
1945 | ||
60a972a6 JM |
1946 | res = nl80211_get_link_signal(drv, &sig); |
1947 | if (res == 0) { | |
7ee35bf3 PS |
1948 | ed.signal_change.current_signal = sig.current_signal; |
1949 | ed.signal_change.current_txrate = sig.current_txrate; | |
1950 | wpa_printf(MSG_DEBUG, "nl80211: Signal: %d dBm txrate: %d", | |
1951 | sig.current_signal, sig.current_txrate); | |
1952 | } | |
1953 | ||
1954 | res = nl80211_get_link_noise(drv, &sig); | |
1955 | if (res == 0) { | |
1956 | ed.signal_change.current_noise = sig.current_noise; | |
1957 | wpa_printf(MSG_DEBUG, "nl80211: Noise: %d dBm", | |
1958 | sig.current_noise); | |
60a972a6 JM |
1959 | } |
1960 | ||
b625473c | 1961 | wpa_supplicant_event(drv->ctx, EVENT_SIGNAL_CHANGE, &ed); |
93910401 JM |
1962 | } |
1963 | ||
1964 | ||
18d2ba08 JM |
1965 | static void nl80211_new_station_event(struct wpa_driver_nl80211_data *drv, |
1966 | struct nlattr **tb) | |
1967 | { | |
1968 | u8 *addr; | |
1969 | union wpa_event_data data; | |
1970 | ||
1971 | if (tb[NL80211_ATTR_MAC] == NULL) | |
1972 | return; | |
1973 | addr = nla_data(tb[NL80211_ATTR_MAC]); | |
1974 | wpa_printf(MSG_DEBUG, "nl80211: New station " MACSTR, MAC2STR(addr)); | |
5f310a9e | 1975 | |
61cbe2ff | 1976 | if (is_ap_interface(drv->nlmode) && drv->device_ap_sme) { |
5f310a9e JM |
1977 | u8 *ies = NULL; |
1978 | size_t ies_len = 0; | |
1979 | if (tb[NL80211_ATTR_IE]) { | |
1980 | ies = nla_data(tb[NL80211_ATTR_IE]); | |
1981 | ies_len = nla_len(tb[NL80211_ATTR_IE]); | |
1982 | } | |
1983 | wpa_hexdump(MSG_DEBUG, "nl80211: Assoc Req IEs", ies, ies_len); | |
1984 | drv_event_assoc(drv->ctx, addr, ies, ies_len, 0); | |
1985 | return; | |
1986 | } | |
1987 | ||
18d2ba08 JM |
1988 | if (drv->nlmode != NL80211_IFTYPE_ADHOC) |
1989 | return; | |
1990 | ||
1991 | os_memset(&data, 0, sizeof(data)); | |
1992 | os_memcpy(data.ibss_rsn_start.peer, addr, ETH_ALEN); | |
1993 | wpa_supplicant_event(drv->ctx, EVENT_IBSS_RSN_START, &data); | |
1994 | } | |
1995 | ||
1996 | ||
ef985058 JM |
1997 | static void nl80211_del_station_event(struct wpa_driver_nl80211_data *drv, |
1998 | struct nlattr **tb) | |
1999 | { | |
2000 | u8 *addr; | |
2001 | union wpa_event_data data; | |
2002 | ||
2003 | if (tb[NL80211_ATTR_MAC] == NULL) | |
2004 | return; | |
2005 | addr = nla_data(tb[NL80211_ATTR_MAC]); | |
2006 | wpa_printf(MSG_DEBUG, "nl80211: Delete station " MACSTR, | |
2007 | MAC2STR(addr)); | |
5f310a9e | 2008 | |
61cbe2ff | 2009 | if (is_ap_interface(drv->nlmode) && drv->device_ap_sme) { |
5f310a9e JM |
2010 | drv_event_disassoc(drv->ctx, addr); |
2011 | return; | |
2012 | } | |
2013 | ||
ef985058 JM |
2014 | if (drv->nlmode != NL80211_IFTYPE_ADHOC) |
2015 | return; | |
2016 | ||
2017 | os_memset(&data, 0, sizeof(data)); | |
2018 | os_memcpy(data.ibss_peer_lost.peer, addr, ETH_ALEN); | |
2019 | wpa_supplicant_event(drv->ctx, EVENT_IBSS_PEER_LOST, &data); | |
2020 | } | |
2021 | ||
2022 | ||
b14a210c JB |
2023 | static void nl80211_rekey_offload_event(struct wpa_driver_nl80211_data *drv, |
2024 | struct nlattr **tb) | |
2025 | { | |
2026 | struct nlattr *rekey_info[NUM_NL80211_REKEY_DATA]; | |
2027 | static struct nla_policy rekey_policy[NUM_NL80211_REKEY_DATA] = { | |
2028 | [NL80211_REKEY_DATA_KEK] = { | |
2029 | .minlen = NL80211_KEK_LEN, | |
2030 | .maxlen = NL80211_KEK_LEN, | |
2031 | }, | |
2032 | [NL80211_REKEY_DATA_KCK] = { | |
2033 | .minlen = NL80211_KCK_LEN, | |
2034 | .maxlen = NL80211_KCK_LEN, | |
2035 | }, | |
2036 | [NL80211_REKEY_DATA_REPLAY_CTR] = { | |
2037 | .minlen = NL80211_REPLAY_CTR_LEN, | |
2038 | .maxlen = NL80211_REPLAY_CTR_LEN, | |
2039 | }, | |
2040 | }; | |
2041 | union wpa_event_data data; | |
2042 | ||
2043 | if (!tb[NL80211_ATTR_MAC]) | |
2044 | return; | |
2045 | if (!tb[NL80211_ATTR_REKEY_DATA]) | |
2046 | return; | |
2047 | if (nla_parse_nested(rekey_info, MAX_NL80211_REKEY_DATA, | |
2048 | tb[NL80211_ATTR_REKEY_DATA], rekey_policy)) | |
2049 | return; | |
2050 | if (!rekey_info[NL80211_REKEY_DATA_REPLAY_CTR]) | |
2051 | return; | |
2052 | ||
2053 | os_memset(&data, 0, sizeof(data)); | |
2054 | data.driver_gtk_rekey.bssid = nla_data(tb[NL80211_ATTR_MAC]); | |
2055 | wpa_printf(MSG_DEBUG, "nl80211: Rekey offload event for BSSID " MACSTR, | |
2056 | MAC2STR(data.driver_gtk_rekey.bssid)); | |
2057 | data.driver_gtk_rekey.replay_ctr = | |
2058 | nla_data(rekey_info[NL80211_REKEY_DATA_REPLAY_CTR]); | |
2059 | wpa_hexdump(MSG_DEBUG, "nl80211: Rekey offload - Replay Counter", | |
2060 | data.driver_gtk_rekey.replay_ctr, NL80211_REPLAY_CTR_LEN); | |
2061 | wpa_supplicant_event(drv->ctx, EVENT_DRIVER_GTK_REKEY, &data); | |
2062 | } | |
2063 | ||
2064 | ||
c36d5242 JM |
2065 | static void nl80211_pmksa_candidate_event(struct wpa_driver_nl80211_data *drv, |
2066 | struct nlattr **tb) | |
2067 | { | |
2068 | struct nlattr *cand[NUM_NL80211_PMKSA_CANDIDATE]; | |
2069 | static struct nla_policy cand_policy[NUM_NL80211_PMKSA_CANDIDATE] = { | |
2070 | [NL80211_PMKSA_CANDIDATE_INDEX] = { .type = NLA_U32 }, | |
2071 | [NL80211_PMKSA_CANDIDATE_BSSID] = { | |
2072 | .minlen = ETH_ALEN, | |
2073 | .maxlen = ETH_ALEN, | |
2074 | }, | |
2075 | [NL80211_PMKSA_CANDIDATE_PREAUTH] = { .type = NLA_FLAG }, | |
2076 | }; | |
2077 | union wpa_event_data data; | |
2078 | ||
7d81932d JM |
2079 | wpa_printf(MSG_DEBUG, "nl80211: PMKSA candidate event"); |
2080 | ||
c36d5242 JM |
2081 | if (!tb[NL80211_ATTR_PMKSA_CANDIDATE]) |
2082 | return; | |
2083 | if (nla_parse_nested(cand, MAX_NL80211_PMKSA_CANDIDATE, | |
2084 | tb[NL80211_ATTR_PMKSA_CANDIDATE], cand_policy)) | |
2085 | return; | |
2086 | if (!cand[NL80211_PMKSA_CANDIDATE_INDEX] || | |
2087 | !cand[NL80211_PMKSA_CANDIDATE_BSSID]) | |
2088 | return; | |
2089 | ||
2090 | os_memset(&data, 0, sizeof(data)); | |
2091 | os_memcpy(data.pmkid_candidate.bssid, | |
2092 | nla_data(cand[NL80211_PMKSA_CANDIDATE_BSSID]), ETH_ALEN); | |
2093 | data.pmkid_candidate.index = | |
2094 | nla_get_u32(cand[NL80211_PMKSA_CANDIDATE_INDEX]); | |
2095 | data.pmkid_candidate.preauth = | |
2096 | cand[NL80211_PMKSA_CANDIDATE_PREAUTH] != NULL; | |
2097 | wpa_supplicant_event(drv->ctx, EVENT_PMKID_CANDIDATE, &data); | |
2098 | } | |
2099 | ||
2100 | ||
39718852 JB |
2101 | static void nl80211_client_probe_event(struct wpa_driver_nl80211_data *drv, |
2102 | struct nlattr **tb) | |
2103 | { | |
2104 | union wpa_event_data data; | |
2105 | ||
7d81932d JM |
2106 | wpa_printf(MSG_DEBUG, "nl80211: Probe client event"); |
2107 | ||
39718852 JB |
2108 | if (!tb[NL80211_ATTR_MAC] || !tb[NL80211_ATTR_ACK]) |
2109 | return; | |
2110 | ||
2111 | os_memset(&data, 0, sizeof(data)); | |
2112 | os_memcpy(data.client_poll.addr, | |
2113 | nla_data(tb[NL80211_ATTR_MAC]), ETH_ALEN); | |
2114 | ||
2115 | wpa_supplicant_event(drv->ctx, EVENT_DRIVER_CLIENT_POLL_OK, &data); | |
2116 | } | |
2117 | ||
2118 | ||
6201b052 JM |
2119 | static void nl80211_tdls_oper_event(struct wpa_driver_nl80211_data *drv, |
2120 | struct nlattr **tb) | |
2121 | { | |
2122 | union wpa_event_data data; | |
2123 | ||
2124 | wpa_printf(MSG_DEBUG, "nl80211: TDLS operation event"); | |
2125 | ||
2126 | if (!tb[NL80211_ATTR_MAC] || !tb[NL80211_ATTR_TDLS_OPERATION]) | |
2127 | return; | |
2128 | ||
2129 | os_memset(&data, 0, sizeof(data)); | |
2130 | os_memcpy(data.tdls.peer, nla_data(tb[NL80211_ATTR_MAC]), ETH_ALEN); | |
2131 | switch (nla_get_u8(tb[NL80211_ATTR_TDLS_OPERATION])) { | |
2132 | case NL80211_TDLS_SETUP: | |
2133 | wpa_printf(MSG_DEBUG, "nl80211: TDLS setup request for peer " | |
2134 | MACSTR, MAC2STR(data.tdls.peer)); | |
2135 | data.tdls.oper = TDLS_REQUEST_SETUP; | |
2136 | break; | |
2137 | case NL80211_TDLS_TEARDOWN: | |
2138 | wpa_printf(MSG_DEBUG, "nl80211: TDLS teardown request for peer " | |
2139 | MACSTR, MAC2STR(data.tdls.peer)); | |
2140 | data.tdls.oper = TDLS_REQUEST_TEARDOWN; | |
2141 | break; | |
2142 | default: | |
2143 | wpa_printf(MSG_DEBUG, "nl80211: Unsupported TDLS operatione " | |
2144 | "event"); | |
2145 | return; | |
2146 | } | |
2147 | if (tb[NL80211_ATTR_REASON_CODE]) { | |
2148 | data.tdls.reason_code = | |
2149 | nla_get_u16(tb[NL80211_ATTR_REASON_CODE]); | |
2150 | } | |
2151 | ||
2152 | wpa_supplicant_event(drv->ctx, EVENT_TDLS, &data); | |
2153 | } | |
2154 | ||
2155 | ||
3140803b RM |
2156 | static void nl80211_connect_failed_event(struct wpa_driver_nl80211_data *drv, |
2157 | struct nlattr **tb) | |
2158 | { | |
2159 | union wpa_event_data data; | |
2160 | u32 reason; | |
2161 | ||
2162 | wpa_printf(MSG_DEBUG, "nl80211: Connect failed event"); | |
2163 | ||
2164 | if (!tb[NL80211_ATTR_MAC] || !tb[NL80211_ATTR_CONN_FAILED_REASON]) | |
2165 | return; | |
2166 | ||
2167 | os_memset(&data, 0, sizeof(data)); | |
2168 | os_memcpy(data.connect_failed_reason.addr, | |
2169 | nla_data(tb[NL80211_ATTR_MAC]), ETH_ALEN); | |
2170 | ||
2171 | reason = nla_get_u32(tb[NL80211_ATTR_CONN_FAILED_REASON]); | |
2172 | switch (reason) { | |
2173 | case NL80211_CONN_FAIL_MAX_CLIENTS: | |
2174 | wpa_printf(MSG_DEBUG, "nl80211: Max client reached"); | |
2175 | data.connect_failed_reason.code = MAX_CLIENT_REACHED; | |
2176 | break; | |
2177 | case NL80211_CONN_FAIL_BLOCKED_CLIENT: | |
2178 | wpa_printf(MSG_DEBUG, "nl80211: Blocked client " MACSTR | |
2179 | " tried to connect", | |
2180 | MAC2STR(data.connect_failed_reason.addr)); | |
2181 | data.connect_failed_reason.code = BLOCKED_CLIENT; | |
2182 | break; | |
2183 | default: | |
2184 | wpa_printf(MSG_DEBUG, "nl8021l: Unknown connect failed reason " | |
2185 | "%u", reason); | |
2186 | return; | |
2187 | } | |
2188 | ||
2189 | wpa_supplicant_event(drv->ctx, EVENT_CONNECT_FAILED_REASON, &data); | |
2190 | } | |
2191 | ||
2192 | ||
3088e4e5 JB |
2193 | static void nl80211_spurious_frame(struct i802_bss *bss, struct nlattr **tb, |
2194 | int wds) | |
02bb32c3 JB |
2195 | { |
2196 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
2197 | union wpa_event_data event; | |
02bb32c3 JB |
2198 | |
2199 | if (!tb[NL80211_ATTR_MAC]) | |
2200 | return; | |
2201 | ||
02bb32c3 | 2202 | os_memset(&event, 0, sizeof(event)); |
341eebee | 2203 | event.rx_from_unknown.bssid = bss->addr; |
02bb32c3 | 2204 | event.rx_from_unknown.addr = nla_data(tb[NL80211_ATTR_MAC]); |
3088e4e5 | 2205 | event.rx_from_unknown.wds = wds; |
02bb32c3 JB |
2206 | |
2207 | wpa_supplicant_event(drv->ctx, EVENT_RX_FROM_UNKNOWN, &event); | |
2208 | } | |
2209 | ||
2210 | ||
a5e1eb20 SE |
2211 | static void do_process_drv_event(struct i802_bss *bss, int cmd, |
2212 | struct nlattr **tb) | |
97865538 | 2213 | { |
a5e1eb20 SE |
2214 | struct wpa_driver_nl80211_data *drv = bss->drv; |
2215 | ||
b1f625e0 | 2216 | if (drv->ap_scan_as_station != NL80211_IFTYPE_UNSPECIFIED && |
d6c9aab8 JB |
2217 | (cmd == NL80211_CMD_NEW_SCAN_RESULTS || |
2218 | cmd == NL80211_CMD_SCAN_ABORTED)) { | |
a2e40bb6 | 2219 | wpa_driver_nl80211_set_mode(&drv->first_bss, |
b1f625e0 EP |
2220 | drv->ap_scan_as_station); |
2221 | drv->ap_scan_as_station = NL80211_IFTYPE_UNSPECIFIED; | |
ad1e68e6 JM |
2222 | } |
2223 | ||
d6c9aab8 | 2224 | switch (cmd) { |
d942a79e JM |
2225 | case NL80211_CMD_TRIGGER_SCAN: |
2226 | wpa_printf(MSG_DEBUG, "nl80211: Scan trigger"); | |
2227 | break; | |
d21c63b9 LC |
2228 | case NL80211_CMD_START_SCHED_SCAN: |
2229 | wpa_printf(MSG_DEBUG, "nl80211: Sched scan started"); | |
2230 | break; | |
2231 | case NL80211_CMD_SCHED_SCAN_STOPPED: | |
2232 | wpa_printf(MSG_DEBUG, "nl80211: Sched scan stopped"); | |
2233 | wpa_supplicant_event(drv->ctx, EVENT_SCHED_SCAN_STOPPED, NULL); | |
2234 | break; | |
97865538 JM |
2235 | case NL80211_CMD_NEW_SCAN_RESULTS: |
2236 | wpa_printf(MSG_DEBUG, "nl80211: New scan results available"); | |
2237 | drv->scan_complete_events = 1; | |
2238 | eloop_cancel_timeout(wpa_driver_nl80211_scan_timeout, drv, | |
2239 | drv->ctx); | |
8d923a4a | 2240 | send_scan_event(drv, 0, tb); |
97865538 | 2241 | break; |
d21c63b9 LC |
2242 | case NL80211_CMD_SCHED_SCAN_RESULTS: |
2243 | wpa_printf(MSG_DEBUG, | |
2244 | "nl80211: New sched scan results available"); | |
2245 | send_scan_event(drv, 0, tb); | |
2246 | break; | |
97865538 JM |
2247 | case NL80211_CMD_SCAN_ABORTED: |
2248 | wpa_printf(MSG_DEBUG, "nl80211: Scan aborted"); | |
2249 | /* | |
2250 | * Need to indicate that scan results are available in order | |
2251 | * not to make wpa_supplicant stop its scanning. | |
2252 | */ | |
2253 | eloop_cancel_timeout(wpa_driver_nl80211_scan_timeout, drv, | |
2254 | drv->ctx); | |
8d923a4a | 2255 | send_scan_event(drv, 1, tb); |
97865538 | 2256 | break; |
c2a04078 JM |
2257 | case NL80211_CMD_AUTHENTICATE: |
2258 | case NL80211_CMD_ASSOCIATE: | |
2259 | case NL80211_CMD_DEAUTHENTICATE: | |
2260 | case NL80211_CMD_DISASSOCIATE: | |
bd94971e | 2261 | case NL80211_CMD_FRAME_TX_STATUS: |
7d878ca7 JM |
2262 | case NL80211_CMD_UNPROT_DEAUTHENTICATE: |
2263 | case NL80211_CMD_UNPROT_DISASSOCIATE: | |
d6c9aab8 | 2264 | mlme_event(drv, cmd, tb[NL80211_ATTR_FRAME], |
58f6fbe0 JM |
2265 | tb[NL80211_ATTR_MAC], tb[NL80211_ATTR_TIMED_OUT], |
2266 | tb[NL80211_ATTR_WIPHY_FREQ], tb[NL80211_ATTR_ACK], | |
da873dbb JB |
2267 | tb[NL80211_ATTR_COOKIE], |
2268 | tb[NL80211_ATTR_RX_SIGNAL_DBM]); | |
c2a04078 | 2269 | break; |
da72a1c1 ZY |
2270 | case NL80211_CMD_CONNECT: |
2271 | case NL80211_CMD_ROAM: | |
d6c9aab8 | 2272 | mlme_event_connect(drv, cmd, |
da72a1c1 ZY |
2273 | tb[NL80211_ATTR_STATUS_CODE], |
2274 | tb[NL80211_ATTR_MAC], | |
2275 | tb[NL80211_ATTR_REQ_IE], | |
2276 | tb[NL80211_ATTR_RESP_IE]); | |
2277 | break; | |
1b487b8b TP |
2278 | case NL80211_CMD_CH_SWITCH_NOTIFY: |
2279 | mlme_event_ch_switch(drv, tb[NL80211_ATTR_WIPHY_FREQ], | |
2280 | tb[NL80211_ATTR_WIPHY_CHANNEL_TYPE]); | |
2281 | break; | |
da72a1c1 | 2282 | case NL80211_CMD_DISCONNECT: |
20f5a4c2 | 2283 | mlme_event_disconnect(drv, tb[NL80211_ATTR_REASON_CODE], |
3d9975d5 JM |
2284 | tb[NL80211_ATTR_MAC], |
2285 | tb[NL80211_ATTR_DISCONNECTED_BY_AP]); | |
da72a1c1 | 2286 | break; |
35583f3f | 2287 | case NL80211_CMD_MICHAEL_MIC_FAILURE: |
a5e1eb20 | 2288 | mlme_event_michael_mic_failure(bss, tb); |
35583f3f | 2289 | break; |
5cc4d64b JM |
2290 | case NL80211_CMD_JOIN_IBSS: |
2291 | mlme_event_join_ibss(drv, tb); | |
2292 | break; | |
55777702 JM |
2293 | case NL80211_CMD_REMAIN_ON_CHANNEL: |
2294 | mlme_event_remain_on_channel(drv, 0, tb); | |
2295 | break; | |
2296 | case NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL: | |
2297 | mlme_event_remain_on_channel(drv, 1, tb); | |
2298 | break; | |
93910401 JM |
2299 | case NL80211_CMD_NOTIFY_CQM: |
2300 | nl80211_cqm_event(drv, tb); | |
2301 | break; | |
33c5deb8 JM |
2302 | case NL80211_CMD_REG_CHANGE: |
2303 | wpa_printf(MSG_DEBUG, "nl80211: Regulatory domain change"); | |
2304 | wpa_supplicant_event(drv->ctx, EVENT_CHANNEL_LIST_CHANGED, | |
2305 | NULL); | |
2306 | break; | |
2307 | case NL80211_CMD_REG_BEACON_HINT: | |
2308 | wpa_printf(MSG_DEBUG, "nl80211: Regulatory beacon hint"); | |
2309 | wpa_supplicant_event(drv->ctx, EVENT_CHANNEL_LIST_CHANGED, | |
2310 | NULL); | |
2311 | break; | |
18d2ba08 JM |
2312 | case NL80211_CMD_NEW_STATION: |
2313 | nl80211_new_station_event(drv, tb); | |
2314 | break; | |
ef985058 JM |
2315 | case NL80211_CMD_DEL_STATION: |
2316 | nl80211_del_station_event(drv, tb); | |
2317 | break; | |
b14a210c JB |
2318 | case NL80211_CMD_SET_REKEY_OFFLOAD: |
2319 | nl80211_rekey_offload_event(drv, tb); | |
2320 | break; | |
c36d5242 JM |
2321 | case NL80211_CMD_PMKSA_CANDIDATE: |
2322 | nl80211_pmksa_candidate_event(drv, tb); | |
2323 | break; | |
39718852 JB |
2324 | case NL80211_CMD_PROBE_CLIENT: |
2325 | nl80211_client_probe_event(drv, tb); | |
2326 | break; | |
6201b052 JM |
2327 | case NL80211_CMD_TDLS_OPER: |
2328 | nl80211_tdls_oper_event(drv, tb); | |
2329 | break; | |
3140803b RM |
2330 | case NL80211_CMD_CONN_FAILED: |
2331 | nl80211_connect_failed_event(drv, tb); | |
2332 | break; | |
97865538 | 2333 | default: |
c2a04078 | 2334 | wpa_printf(MSG_DEBUG, "nl80211: Ignored unknown event " |
d6c9aab8 | 2335 | "(cmd=%d)", cmd); |
97865538 JM |
2336 | break; |
2337 | } | |
d6c9aab8 JB |
2338 | } |
2339 | ||
2340 | ||
2341 | static int process_drv_event(struct nl_msg *msg, void *arg) | |
2342 | { | |
2343 | struct wpa_driver_nl80211_data *drv = arg; | |
2344 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); | |
2345 | struct nlattr *tb[NL80211_ATTR_MAX + 1]; | |
a5e1eb20 SE |
2346 | struct i802_bss *bss; |
2347 | int ifidx = -1; | |
d6c9aab8 JB |
2348 | |
2349 | nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), | |
2350 | genlmsg_attrlen(gnlh, 0), NULL); | |
2351 | ||
a5e1eb20 SE |
2352 | if (tb[NL80211_ATTR_IFINDEX]) |
2353 | ifidx = nla_get_u32(tb[NL80211_ATTR_IFINDEX]); | |
2354 | ||
2355 | for (bss = &drv->first_bss; bss; bss = bss->next) { | |
2356 | if (ifidx == -1 || ifidx == bss->ifindex) { | |
2357 | do_process_drv_event(bss, gnlh->cmd, tb); | |
d6c9aab8 JB |
2358 | return NL_SKIP; |
2359 | } | |
2360 | } | |
2361 | ||
a5e1eb20 SE |
2362 | wpa_printf(MSG_DEBUG, "nl80211: Ignored event (cmd=%d) for foreign " |
2363 | "interface (ifindex %d)", gnlh->cmd, ifidx); | |
2364 | ||
d6c9aab8 JB |
2365 | return NL_SKIP; |
2366 | } | |
2367 | ||
2368 | ||
2369 | static int process_global_event(struct nl_msg *msg, void *arg) | |
2370 | { | |
2371 | struct nl80211_global *global = arg; | |
2372 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); | |
2373 | struct nlattr *tb[NL80211_ATTR_MAX + 1]; | |
24b5bd8b | 2374 | struct wpa_driver_nl80211_data *drv, *tmp; |
d6c9aab8 | 2375 | int ifidx = -1; |
a5e1eb20 | 2376 | struct i802_bss *bss; |
d6c9aab8 JB |
2377 | |
2378 | nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), | |
2379 | genlmsg_attrlen(gnlh, 0), NULL); | |
2380 | ||
2381 | if (tb[NL80211_ATTR_IFINDEX]) | |
2382 | ifidx = nla_get_u32(tb[NL80211_ATTR_IFINDEX]); | |
2383 | ||
24b5bd8b JB |
2384 | dl_list_for_each_safe(drv, tmp, &global->interfaces, |
2385 | struct wpa_driver_nl80211_data, list) { | |
a5e1eb20 SE |
2386 | for (bss = &drv->first_bss; bss; bss = bss->next) { |
2387 | if (ifidx == -1 || ifidx == bss->ifindex) { | |
2388 | do_process_drv_event(bss, gnlh->cmd, tb); | |
2389 | return NL_SKIP; | |
2390 | } | |
2391 | } | |
d6c9aab8 | 2392 | } |
97865538 JM |
2393 | |
2394 | return NL_SKIP; | |
2395 | } | |
2396 | ||
2397 | ||
cc7a48d1 JB |
2398 | static int process_bss_event(struct nl_msg *msg, void *arg) |
2399 | { | |
a11241fa | 2400 | struct i802_bss *bss = arg; |
cc7a48d1 JB |
2401 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); |
2402 | struct nlattr *tb[NL80211_ATTR_MAX + 1]; | |
2403 | ||
2404 | nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), | |
2405 | genlmsg_attrlen(gnlh, 0), NULL); | |
2406 | ||
2407 | switch (gnlh->cmd) { | |
a11241fa JB |
2408 | case NL80211_CMD_FRAME: |
2409 | case NL80211_CMD_FRAME_TX_STATUS: | |
2410 | mlme_event(bss->drv, gnlh->cmd, tb[NL80211_ATTR_FRAME], | |
2411 | tb[NL80211_ATTR_MAC], tb[NL80211_ATTR_TIMED_OUT], | |
2412 | tb[NL80211_ATTR_WIPHY_FREQ], tb[NL80211_ATTR_ACK], | |
da873dbb JB |
2413 | tb[NL80211_ATTR_COOKIE], |
2414 | tb[NL80211_ATTR_RX_SIGNAL_DBM]); | |
a11241fa | 2415 | break; |
02bb32c3 | 2416 | case NL80211_CMD_UNEXPECTED_FRAME: |
3088e4e5 JB |
2417 | nl80211_spurious_frame(bss, tb, 0); |
2418 | break; | |
2419 | case NL80211_CMD_UNEXPECTED_4ADDR_FRAME: | |
2420 | nl80211_spurious_frame(bss, tb, 1); | |
02bb32c3 | 2421 | break; |
cc7a48d1 JB |
2422 | default: |
2423 | wpa_printf(MSG_DEBUG, "nl80211: Ignored unknown event " | |
2424 | "(cmd=%d)", gnlh->cmd); | |
2425 | break; | |
2426 | } | |
2427 | ||
2428 | return NL_SKIP; | |
2429 | } | |
2430 | ||
2431 | ||
97865538 | 2432 | static void wpa_driver_nl80211_event_receive(int sock, void *eloop_ctx, |
5582a5d1 | 2433 | void *handle) |
97865538 | 2434 | { |
a4ae123c | 2435 | struct nl_cb *cb = eloop_ctx; |
97865538 JM |
2436 | |
2437 | wpa_printf(MSG_DEBUG, "nl80211: Event message available"); | |
2438 | ||
a4ae123c | 2439 | nl_recvmsgs(handle, cb); |
97865538 JM |
2440 | } |
2441 | ||
2442 | ||
6d158490 LR |
2443 | /** |
2444 | * wpa_driver_nl80211_set_country - ask nl80211 to set the regulatory domain | |
2445 | * @priv: driver_nl80211 private data | |
2446 | * @alpha2_arg: country to which to switch to | |
2447 | * Returns: 0 on success, -1 on failure | |
2448 | * | |
2449 | * This asks nl80211 to set the regulatory domain for given | |
2450 | * country ISO / IEC alpha2. | |
2451 | */ | |
2452 | static int wpa_driver_nl80211_set_country(void *priv, const char *alpha2_arg) | |
2453 | { | |
a2e40bb6 FF |
2454 | struct i802_bss *bss = priv; |
2455 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
6d158490 LR |
2456 | char alpha2[3]; |
2457 | struct nl_msg *msg; | |
2458 | ||
2459 | msg = nlmsg_alloc(); | |
2460 | if (!msg) | |
e785c2ba | 2461 | return -ENOMEM; |
6d158490 LR |
2462 | |
2463 | alpha2[0] = alpha2_arg[0]; | |
2464 | alpha2[1] = alpha2_arg[1]; | |
2465 | alpha2[2] = '\0'; | |
2466 | ||
9fb04070 | 2467 | nl80211_cmd(drv, msg, 0, NL80211_CMD_REQ_SET_REG); |
6d158490 LR |
2468 | |
2469 | NLA_PUT_STRING(msg, NL80211_ATTR_REG_ALPHA2, alpha2); | |
2470 | if (send_and_recv_msgs(drv, msg, NULL, NULL)) | |
2471 | return -EINVAL; | |
2472 | return 0; | |
2473 | nla_put_failure: | |
5883168a | 2474 | nlmsg_free(msg); |
6d158490 LR |
2475 | return -EINVAL; |
2476 | } | |
2477 | ||
2478 | ||
80bc75f1 | 2479 | struct wiphy_info_data { |
e8b5e24e JB |
2480 | struct wpa_driver_capa *capa; |
2481 | ||
2482 | unsigned int error:1; | |
61cbe2ff | 2483 | unsigned int device_ap_sme:1; |
39718852 | 2484 | unsigned int poll_command_supported:1; |
32ab4855 | 2485 | unsigned int data_tx_status:1; |
536062f2 | 2486 | unsigned int monitor_supported:1; |
80bc75f1 JM |
2487 | }; |
2488 | ||
2489 | ||
562c9d97 AN |
2490 | static unsigned int probe_resp_offload_support(int supp_protocols) |
2491 | { | |
2492 | unsigned int prot = 0; | |
2493 | ||
2494 | if (supp_protocols & NL80211_PROBE_RESP_OFFLOAD_SUPPORT_WPS) | |
2495 | prot |= WPA_DRIVER_PROBE_RESP_OFFLOAD_WPS; | |
2496 | if (supp_protocols & NL80211_PROBE_RESP_OFFLOAD_SUPPORT_WPS2) | |
2497 | prot |= WPA_DRIVER_PROBE_RESP_OFFLOAD_WPS2; | |
2498 | if (supp_protocols & NL80211_PROBE_RESP_OFFLOAD_SUPPORT_P2P) | |
2499 | prot |= WPA_DRIVER_PROBE_RESP_OFFLOAD_P2P; | |
2500 | if (supp_protocols & NL80211_PROBE_RESP_OFFLOAD_SUPPORT_80211U) | |
2501 | prot |= WPA_DRIVER_PROBE_RESP_OFFLOAD_INTERWORKING; | |
2502 | ||
2503 | return prot; | |
2504 | } | |
2505 | ||
2506 | ||
80bc75f1 JM |
2507 | static int wiphy_info_handler(struct nl_msg *msg, void *arg) |
2508 | { | |
2509 | struct nlattr *tb[NL80211_ATTR_MAX + 1]; | |
2510 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); | |
2511 | struct wiphy_info_data *info = arg; | |
9f51b113 | 2512 | int p2p_go_supported = 0, p2p_client_supported = 0; |
e3e234fa | 2513 | int p2p_concurrent = 0, p2p_multichan_concurrent = 0; |
e8b5e24e JB |
2514 | int auth_supported = 0, connect_supported = 0; |
2515 | struct wpa_driver_capa *capa = info->capa; | |
7626850d JB |
2516 | static struct nla_policy |
2517 | iface_combination_policy[NUM_NL80211_IFACE_COMB] = { | |
2518 | [NL80211_IFACE_COMB_LIMITS] = { .type = NLA_NESTED }, | |
2519 | [NL80211_IFACE_COMB_MAXNUM] = { .type = NLA_U32 }, | |
2520 | [NL80211_IFACE_COMB_STA_AP_BI_MATCH] = { .type = NLA_FLAG }, | |
2521 | [NL80211_IFACE_COMB_NUM_CHANNELS] = { .type = NLA_U32 }, | |
2522 | }, | |
2523 | iface_limit_policy[NUM_NL80211_IFACE_LIMIT] = { | |
2524 | [NL80211_IFACE_LIMIT_TYPES] = { .type = NLA_NESTED }, | |
2525 | [NL80211_IFACE_LIMIT_MAX] = { .type = NLA_U32 }, | |
2526 | }; | |
80bc75f1 JM |
2527 | |
2528 | nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), | |
2529 | genlmsg_attrlen(gnlh, 0), NULL); | |
2530 | ||
2531 | if (tb[NL80211_ATTR_MAX_NUM_SCAN_SSIDS]) | |
e8b5e24e | 2532 | capa->max_scan_ssids = |
80bc75f1 JM |
2533 | nla_get_u8(tb[NL80211_ATTR_MAX_NUM_SCAN_SSIDS]); |
2534 | ||
d21c63b9 | 2535 | if (tb[NL80211_ATTR_MAX_NUM_SCHED_SCAN_SSIDS]) |
e8b5e24e | 2536 | capa->max_sched_scan_ssids = |
d21c63b9 LC |
2537 | nla_get_u8(tb[NL80211_ATTR_MAX_NUM_SCHED_SCAN_SSIDS]); |
2538 | ||
bd525934 | 2539 | if (tb[NL80211_ATTR_MAX_MATCH_SETS]) |
e8b5e24e | 2540 | capa->max_match_sets = |
bd525934 LC |
2541 | nla_get_u8(tb[NL80211_ATTR_MAX_MATCH_SETS]); |
2542 | ||
1581b38b JM |
2543 | if (tb[NL80211_ATTR_SUPPORTED_IFTYPES]) { |
2544 | struct nlattr *nl_mode; | |
2545 | int i; | |
2546 | nla_for_each_nested(nl_mode, | |
2547 | tb[NL80211_ATTR_SUPPORTED_IFTYPES], i) { | |
58708b3b | 2548 | switch (nla_type(nl_mode)) { |
9f51b113 | 2549 | case NL80211_IFTYPE_AP: |
e8b5e24e | 2550 | capa->flags |= WPA_DRIVER_FLAGS_AP; |
1581b38b | 2551 | break; |
9f51b113 JB |
2552 | case NL80211_IFTYPE_P2P_GO: |
2553 | p2p_go_supported = 1; | |
2554 | break; | |
2555 | case NL80211_IFTYPE_P2P_CLIENT: | |
2556 | p2p_client_supported = 1; | |
2557 | break; | |
536062f2 JM |
2558 | case NL80211_IFTYPE_MONITOR: |
2559 | info->monitor_supported = 1; | |
2560 | break; | |
1581b38b JM |
2561 | } |
2562 | } | |
2563 | } | |
2564 | ||
7626850d JB |
2565 | if (tb[NL80211_ATTR_INTERFACE_COMBINATIONS]) { |
2566 | struct nlattr *nl_combi; | |
2567 | int rem_combi; | |
2568 | ||
2569 | nla_for_each_nested(nl_combi, | |
2570 | tb[NL80211_ATTR_INTERFACE_COMBINATIONS], | |
2571 | rem_combi) { | |
2572 | struct nlattr *tb_comb[NUM_NL80211_IFACE_COMB]; | |
2573 | struct nlattr *tb_limit[NUM_NL80211_IFACE_LIMIT]; | |
2574 | struct nlattr *nl_limit, *nl_mode; | |
2575 | int err, rem_limit, rem_mode; | |
2576 | int combination_has_p2p = 0, combination_has_mgd = 0; | |
2577 | ||
2578 | err = nla_parse_nested(tb_comb, MAX_NL80211_IFACE_COMB, | |
2579 | nl_combi, | |
2580 | iface_combination_policy); | |
2581 | if (err || !tb_comb[NL80211_IFACE_COMB_LIMITS] || | |
2582 | !tb_comb[NL80211_IFACE_COMB_MAXNUM] || | |
2583 | !tb_comb[NL80211_IFACE_COMB_NUM_CHANNELS]) | |
2584 | goto broken_combination; | |
2585 | ||
2586 | nla_for_each_nested(nl_limit, | |
2587 | tb_comb[NL80211_IFACE_COMB_LIMITS], | |
2588 | rem_limit) { | |
2589 | err = nla_parse_nested(tb_limit, | |
2590 | MAX_NL80211_IFACE_LIMIT, | |
2591 | nl_limit, | |
2592 | iface_limit_policy); | |
2593 | if (err || | |
2594 | !tb_limit[NL80211_IFACE_LIMIT_TYPES]) | |
2595 | goto broken_combination; | |
2596 | ||
2597 | nla_for_each_nested( | |
2598 | nl_mode, | |
2599 | tb_limit[NL80211_IFACE_LIMIT_TYPES], | |
2600 | rem_mode) { | |
2601 | int ift = nla_type(nl_mode); | |
2602 | if (ift == NL80211_IFTYPE_P2P_GO || | |
2603 | ift == NL80211_IFTYPE_P2P_CLIENT) | |
2604 | combination_has_p2p = 1; | |
2605 | if (ift == NL80211_IFTYPE_STATION) | |
2606 | combination_has_mgd = 1; | |
2607 | } | |
2608 | if (combination_has_p2p && combination_has_mgd) | |
2609 | break; | |
2610 | } | |
2611 | ||
2612 | if (combination_has_p2p && combination_has_mgd) { | |
e8b5e24e | 2613 | p2p_concurrent = 1; |
e3e234fa WJL |
2614 | if (nla_get_u32(tb_comb[NL80211_IFACE_COMB_NUM_CHANNELS]) > 1) |
2615 | p2p_multichan_concurrent = 1; | |
7626850d JB |
2616 | break; |
2617 | } | |
2618 | ||
2619 | broken_combination: | |
2620 | ; | |
2621 | } | |
2622 | } | |
2623 | ||
93d11400 ZY |
2624 | if (tb[NL80211_ATTR_SUPPORTED_COMMANDS]) { |
2625 | struct nlattr *nl_cmd; | |
2626 | int i; | |
2627 | ||
2628 | nla_for_each_nested(nl_cmd, | |
2629 | tb[NL80211_ATTR_SUPPORTED_COMMANDS], i) { | |
e8b5e24e JB |
2630 | switch (nla_get_u32(nl_cmd)) { |
2631 | case NL80211_CMD_AUTHENTICATE: | |
2632 | auth_supported = 1; | |
2633 | break; | |
2634 | case NL80211_CMD_CONNECT: | |
2635 | connect_supported = 1; | |
2636 | break; | |
2637 | case NL80211_CMD_START_SCHED_SCAN: | |
2638 | capa->sched_scan_supported = 1; | |
2639 | break; | |
39718852 JB |
2640 | case NL80211_CMD_PROBE_CLIENT: |
2641 | info->poll_command_supported = 1; | |
2642 | break; | |
e8b5e24e | 2643 | } |
93d11400 ZY |
2644 | } |
2645 | } | |
2646 | ||
e8b5e24e JB |
2647 | if (tb[NL80211_ATTR_OFFCHANNEL_TX_OK]) { |
2648 | wpa_printf(MSG_DEBUG, "nl80211: Using driver-based " | |
2649 | "off-channel TX"); | |
2650 | capa->flags |= WPA_DRIVER_FLAGS_OFFCHANNEL_TX; | |
2651 | } | |
2652 | ||
2653 | if (tb[NL80211_ATTR_ROAM_SUPPORT]) { | |
2654 | wpa_printf(MSG_DEBUG, "nl80211: Using driver-based roaming"); | |
2655 | capa->flags |= WPA_DRIVER_FLAGS_BSS_SELECTION; | |
2656 | } | |
5dfca53f | 2657 | |
e8b5e24e JB |
2658 | /* default to 5000 since early versions of mac80211 don't set it */ |
2659 | capa->max_remain_on_chan = 5000; | |
004ba773 | 2660 | |
70619a5d EP |
2661 | if (tb[NL80211_ATTR_SUPPORT_AP_UAPSD]) |
2662 | capa->flags |= WPA_DRIVER_FLAGS_AP_UAPSD; | |
2663 | ||
89e07afb | 2664 | if (tb[NL80211_ATTR_MAX_REMAIN_ON_CHANNEL_DURATION]) |
e8b5e24e | 2665 | capa->max_remain_on_chan = |
89e07afb JB |
2666 | nla_get_u32(tb[NL80211_ATTR_MAX_REMAIN_ON_CHANNEL_DURATION]); |
2667 | ||
e8b5e24e JB |
2668 | if (auth_supported) |
2669 | capa->flags |= WPA_DRIVER_FLAGS_SME; | |
2670 | else if (!connect_supported) { | |
2671 | wpa_printf(MSG_INFO, "nl80211: Driver does not support " | |
2672 | "authentication/association or connect commands"); | |
2673 | info->error = 1; | |
2674 | } | |
2675 | ||
2676 | if (p2p_go_supported && p2p_client_supported) | |
2677 | capa->flags |= WPA_DRIVER_FLAGS_P2P_CAPABLE; | |
2678 | if (p2p_concurrent) { | |
2679 | wpa_printf(MSG_DEBUG, "nl80211: Use separate P2P group " | |
2680 | "interface (driver advertised support)"); | |
2681 | capa->flags |= WPA_DRIVER_FLAGS_P2P_CONCURRENT; | |
2682 | capa->flags |= WPA_DRIVER_FLAGS_P2P_MGMT_AND_NON_P2P; | |
e3e234fa WJL |
2683 | |
2684 | if (p2p_multichan_concurrent) { | |
2685 | wpa_printf(MSG_DEBUG, "nl80211: Enable multi-channel " | |
2686 | "concurrent (driver advertised support)"); | |
2687 | capa->flags |= | |
2688 | WPA_DRIVER_FLAGS_MULTI_CHANNEL_CONCURRENT; | |
2689 | } | |
e8b5e24e JB |
2690 | } |
2691 | ||
03ea1786 AN |
2692 | if (tb[NL80211_ATTR_TDLS_SUPPORT]) { |
2693 | wpa_printf(MSG_DEBUG, "nl80211: TDLS supported"); | |
2694 | capa->flags |= WPA_DRIVER_FLAGS_TDLS_SUPPORT; | |
2695 | ||
2696 | if (tb[NL80211_ATTR_TDLS_EXTERNAL_SETUP]) { | |
2697 | wpa_printf(MSG_DEBUG, "nl80211: TDLS external setup"); | |
2698 | capa->flags |= | |
2699 | WPA_DRIVER_FLAGS_TDLS_EXTERNAL_SETUP; | |
2700 | } | |
2701 | } | |
2702 | ||
61cbe2ff JB |
2703 | if (tb[NL80211_ATTR_DEVICE_AP_SME]) |
2704 | info->device_ap_sme = 1; | |
2705 | ||
32ab4855 JB |
2706 | if (tb[NL80211_ATTR_FEATURE_FLAGS]) { |
2707 | u32 flags = nla_get_u32(tb[NL80211_ATTR_FEATURE_FLAGS]); | |
2708 | ||
2709 | if (flags & NL80211_FEATURE_SK_TX_STATUS) | |
2710 | info->data_tx_status = 1; | |
a0133ee1 VT |
2711 | |
2712 | if (flags & NL80211_FEATURE_INACTIVITY_TIMER) | |
2713 | capa->flags |= WPA_DRIVER_FLAGS_INACTIVITY_TIMER; | |
569fed90 JM |
2714 | |
2715 | if (flags & NL80211_FEATURE_SAE) | |
2716 | capa->flags |= WPA_DRIVER_FLAGS_SAE; | |
368b1957 AK |
2717 | |
2718 | if (flags & NL80211_FEATURE_NEED_OBSS_SCAN) | |
2719 | capa->flags |= WPA_DRIVER_FLAGS_OBSS_SCAN; | |
32ab4855 JB |
2720 | } |
2721 | ||
562c9d97 AN |
2722 | if (tb[NL80211_ATTR_PROBE_RESP_OFFLOAD]) { |
2723 | int protocols = | |
2724 | nla_get_u32(tb[NL80211_ATTR_PROBE_RESP_OFFLOAD]); | |
2725 | wpa_printf(MSG_DEBUG, "nl80211: Supports Probe Response " | |
2726 | "offload in AP mode"); | |
2727 | capa->flags |= WPA_DRIVER_FLAGS_PROBE_RESP_OFFLOAD; | |
2728 | capa->probe_resp_offloads = | |
2729 | probe_resp_offload_support(protocols); | |
2730 | } | |
2731 | ||
80bc75f1 JM |
2732 | return NL_SKIP; |
2733 | } | |
2734 | ||
2735 | ||
2736 | static int wpa_driver_nl80211_get_info(struct wpa_driver_nl80211_data *drv, | |
2737 | struct wiphy_info_data *info) | |
2738 | { | |
2739 | struct nl_msg *msg; | |
2740 | ||
2741 | os_memset(info, 0, sizeof(*info)); | |
e8b5e24e | 2742 | info->capa = &drv->capa; |
89e07afb | 2743 | |
80bc75f1 JM |
2744 | msg = nlmsg_alloc(); |
2745 | if (!msg) | |
2746 | return -1; | |
2747 | ||
9fb04070 | 2748 | nl80211_cmd(drv, msg, 0, NL80211_CMD_GET_WIPHY); |
80bc75f1 | 2749 | |
a2e40bb6 | 2750 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, drv->first_bss.ifindex); |
80bc75f1 JM |
2751 | |
2752 | if (send_and_recv_msgs(drv, msg, wiphy_info_handler, info) == 0) | |
2753 | return 0; | |
2754 | msg = NULL; | |
2755 | nla_put_failure: | |
2756 | nlmsg_free(msg); | |
2757 | return -1; | |
2758 | } | |
2759 | ||
2760 | ||
93d11400 | 2761 | static int wpa_driver_nl80211_capa(struct wpa_driver_nl80211_data *drv) |
80bc75f1 JM |
2762 | { |
2763 | struct wiphy_info_data info; | |
2764 | if (wpa_driver_nl80211_get_info(drv, &info)) | |
93d11400 | 2765 | return -1; |
e8b5e24e JB |
2766 | |
2767 | if (info.error) | |
2768 | return -1; | |
2769 | ||
80bc75f1 | 2770 | drv->has_capability = 1; |
1b2a72e8 JM |
2771 | /* For now, assume TKIP, CCMP, WPA, WPA2 are supported */ |
2772 | drv->capa.key_mgmt = WPA_DRIVER_CAPA_KEY_MGMT_WPA | | |
2773 | WPA_DRIVER_CAPA_KEY_MGMT_WPA_PSK | | |
2774 | WPA_DRIVER_CAPA_KEY_MGMT_WPA2 | | |
2775 | WPA_DRIVER_CAPA_KEY_MGMT_WPA2_PSK; | |
2776 | drv->capa.enc = WPA_DRIVER_CAPA_ENC_WEP40 | | |
2777 | WPA_DRIVER_CAPA_ENC_WEP104 | | |
2778 | WPA_DRIVER_CAPA_ENC_TKIP | | |
2779 | WPA_DRIVER_CAPA_ENC_CCMP; | |
291b6068 JM |
2780 | drv->capa.auth = WPA_DRIVER_AUTH_OPEN | |
2781 | WPA_DRIVER_AUTH_SHARED | | |
2782 | WPA_DRIVER_AUTH_LEAP; | |
1b2a72e8 | 2783 | |
871f4dd0 | 2784 | drv->capa.flags |= WPA_DRIVER_FLAGS_SANE_ERROR_CODES; |
0194fedb | 2785 | drv->capa.flags |= WPA_DRIVER_FLAGS_SET_KEYS_AFTER_ASSOC_DONE; |
2fee890a | 2786 | drv->capa.flags |= WPA_DRIVER_FLAGS_EAPOL_TX_STATUS; |
e1bd4e19 | 2787 | |
e5091674 | 2788 | if (!info.device_ap_sme) { |
e1bd4e19 | 2789 | drv->capa.flags |= WPA_DRIVER_FLAGS_DEAUTH_TX_STATUS; |
0194fedb | 2790 | |
e5091674 JM |
2791 | /* |
2792 | * No AP SME is currently assumed to also indicate no AP MLME | |
2793 | * in the driver/firmware. | |
2794 | */ | |
2795 | drv->capa.flags |= WPA_DRIVER_FLAGS_AP_MLME; | |
2796 | } | |
2797 | ||
61cbe2ff | 2798 | drv->device_ap_sme = info.device_ap_sme; |
39718852 | 2799 | drv->poll_command_supported = info.poll_command_supported; |
32ab4855 | 2800 | drv->data_tx_status = info.data_tx_status; |
61cbe2ff | 2801 | |
a11241fa | 2802 | /* |
73a3c6ff FF |
2803 | * If poll command and tx status are supported, mac80211 is new enough |
2804 | * to have everything we need to not need monitor interfaces. | |
a11241fa | 2805 | */ |
73a3c6ff | 2806 | drv->use_monitor = !info.poll_command_supported || !info.data_tx_status; |
a11241fa | 2807 | |
536062f2 JM |
2808 | if (drv->device_ap_sme && drv->use_monitor) { |
2809 | /* | |
2810 | * Non-mac80211 drivers may not support monitor interface. | |
2811 | * Make sure we do not get stuck with incorrect capability here | |
2812 | * by explicitly testing this. | |
2813 | */ | |
2814 | if (!info.monitor_supported) { | |
2815 | wpa_printf(MSG_DEBUG, "nl80211: Disable use_monitor " | |
2816 | "with device_ap_sme since no monitor mode " | |
2817 | "support detected"); | |
2818 | drv->use_monitor = 0; | |
2819 | } | |
2820 | } | |
2821 | ||
a11241fa JB |
2822 | /* |
2823 | * If we aren't going to use monitor interfaces, but the | |
2824 | * driver doesn't support data TX status, we won't get TX | |
2825 | * status for EAPOL frames. | |
2826 | */ | |
2827 | if (!drv->use_monitor && !info.data_tx_status) | |
2828 | drv->capa.flags &= ~WPA_DRIVER_FLAGS_EAPOL_TX_STATUS; | |
2829 | ||
93d11400 | 2830 | return 0; |
80bc75f1 JM |
2831 | } |
2832 | ||
2833 | ||
b088cf82 JM |
2834 | #ifdef ANDROID |
2835 | static int android_genl_ctrl_resolve(struct nl_handle *handle, | |
2836 | const char *name) | |
2837 | { | |
2838 | /* | |
2839 | * Android ICS has very minimal genl_ctrl_resolve() implementation, so | |
2840 | * need to work around that. | |
2841 | */ | |
2842 | struct nl_cache *cache = NULL; | |
2843 | struct genl_family *nl80211 = NULL; | |
2844 | int id = -1; | |
2845 | ||
2846 | if (genl_ctrl_alloc_cache(handle, &cache) < 0) { | |
2847 | wpa_printf(MSG_ERROR, "nl80211: Failed to allocate generic " | |
2848 | "netlink cache"); | |
2849 | goto fail; | |
2850 | } | |
2851 | ||
2852 | nl80211 = genl_ctrl_search_by_name(cache, name); | |
2853 | if (nl80211 == NULL) | |
2854 | goto fail; | |
2855 | ||
2856 | id = genl_family_get_id(nl80211); | |
2857 | ||
2858 | fail: | |
2859 | if (nl80211) | |
2860 | genl_family_put(nl80211); | |
2861 | if (cache) | |
2862 | nl_cache_free(cache); | |
2863 | ||
2864 | return id; | |
2865 | } | |
2866 | #define genl_ctrl_resolve android_genl_ctrl_resolve | |
2867 | #endif /* ANDROID */ | |
2868 | ||
2869 | ||
2a7b66f5 BG |
2870 | static int wpa_driver_nl80211_init_nl_global(struct nl80211_global *global) |
2871 | { | |
d6c9aab8 JB |
2872 | int ret; |
2873 | ||
2a7b66f5 BG |
2874 | global->nl_cb = nl_cb_alloc(NL_CB_DEFAULT); |
2875 | if (global->nl_cb == NULL) { | |
2876 | wpa_printf(MSG_ERROR, "nl80211: Failed to allocate netlink " | |
2877 | "callbacks"); | |
2878 | return -1; | |
2879 | } | |
2880 | ||
481234cf JM |
2881 | global->nl = nl_create_handle(global->nl_cb, "nl"); |
2882 | if (global->nl == NULL) | |
d6c9aab8 | 2883 | goto err; |
276e2d67 | 2884 | |
481234cf | 2885 | global->nl80211_id = genl_ctrl_resolve(global->nl, "nl80211"); |
335d42b1 | 2886 | if (global->nl80211_id < 0) { |
276e2d67 BG |
2887 | wpa_printf(MSG_ERROR, "nl80211: 'nl80211' generic netlink not " |
2888 | "found"); | |
d6c9aab8 | 2889 | goto err; |
276e2d67 BG |
2890 | } |
2891 | ||
481234cf JM |
2892 | global->nl_event = nl_create_handle(global->nl_cb, "event"); |
2893 | if (global->nl_event == NULL) | |
d6c9aab8 | 2894 | goto err; |
9fff9fdc | 2895 | |
d6c9aab8 | 2896 | ret = nl_get_multicast_id(global, "nl80211", "scan"); |
97865538 | 2897 | if (ret >= 0) |
481234cf | 2898 | ret = nl_socket_add_membership(global->nl_event, ret); |
97865538 JM |
2899 | if (ret < 0) { |
2900 | wpa_printf(MSG_ERROR, "nl80211: Could not add multicast " | |
2901 | "membership for scan events: %d (%s)", | |
2902 | ret, strerror(-ret)); | |
d6c9aab8 | 2903 | goto err; |
97865538 | 2904 | } |
c2a04078 | 2905 | |
d6c9aab8 | 2906 | ret = nl_get_multicast_id(global, "nl80211", "mlme"); |
c2a04078 | 2907 | if (ret >= 0) |
481234cf | 2908 | ret = nl_socket_add_membership(global->nl_event, ret); |
c2a04078 JM |
2909 | if (ret < 0) { |
2910 | wpa_printf(MSG_ERROR, "nl80211: Could not add multicast " | |
2911 | "membership for mlme events: %d (%s)", | |
2912 | ret, strerror(-ret)); | |
d6c9aab8 | 2913 | goto err; |
c2a04078 | 2914 | } |
c2a04078 | 2915 | |
d6c9aab8 | 2916 | ret = nl_get_multicast_id(global, "nl80211", "regulatory"); |
33c5deb8 | 2917 | if (ret >= 0) |
481234cf | 2918 | ret = nl_socket_add_membership(global->nl_event, ret); |
33c5deb8 JM |
2919 | if (ret < 0) { |
2920 | wpa_printf(MSG_DEBUG, "nl80211: Could not add multicast " | |
2921 | "membership for regulatory events: %d (%s)", | |
2922 | ret, strerror(-ret)); | |
2923 | /* Continue without regulatory events */ | |
2924 | } | |
2925 | ||
d6c9aab8 JB |
2926 | nl_cb_set(global->nl_cb, NL_CB_SEQ_CHECK, NL_CB_CUSTOM, |
2927 | no_seq_check, NULL); | |
2928 | nl_cb_set(global->nl_cb, NL_CB_VALID, NL_CB_CUSTOM, | |
2929 | process_global_event, global); | |
2930 | ||
481234cf | 2931 | eloop_register_read_sock(nl_socket_get_fd(global->nl_event), |
d6c9aab8 | 2932 | wpa_driver_nl80211_event_receive, |
481234cf | 2933 | global->nl_cb, global->nl_event); |
d6c9aab8 JB |
2934 | |
2935 | return 0; | |
2936 | ||
2937 | err: | |
2938 | nl_destroy_handles(&global->nl_event); | |
2939 | nl_destroy_handles(&global->nl); | |
2940 | nl_cb_put(global->nl_cb); | |
671a5039 | 2941 | global->nl_cb = NULL; |
d6c9aab8 JB |
2942 | return -1; |
2943 | } | |
2944 | ||
2945 | ||
2946 | static int wpa_driver_nl80211_init_nl(struct wpa_driver_nl80211_data *drv) | |
2947 | { | |
1afc986d JB |
2948 | drv->nl_cb = nl_cb_alloc(NL_CB_DEFAULT); |
2949 | if (!drv->nl_cb) { | |
2950 | wpa_printf(MSG_ERROR, "nl80211: Failed to alloc cb struct"); | |
d6c9aab8 | 2951 | return -1; |
1afc986d JB |
2952 | } |
2953 | ||
2954 | nl_cb_set(drv->nl_cb, NL_CB_SEQ_CHECK, NL_CB_CUSTOM, | |
2955 | no_seq_check, NULL); | |
f06aedd9 JB |
2956 | nl_cb_set(drv->nl_cb, NL_CB_VALID, NL_CB_CUSTOM, |
2957 | process_drv_event, drv); | |
1afc986d | 2958 | |
9fff9fdc | 2959 | return 0; |
9fff9fdc JM |
2960 | } |
2961 | ||
2962 | ||
8401a6b0 JM |
2963 | static void wpa_driver_nl80211_rfkill_blocked(void *ctx) |
2964 | { | |
8401a6b0 | 2965 | wpa_printf(MSG_DEBUG, "nl80211: RFKILL blocked"); |
a63063b4 JM |
2966 | /* |
2967 | * This may be for any interface; use ifdown event to disable | |
2968 | * interface. | |
2969 | */ | |
8401a6b0 JM |
2970 | } |
2971 | ||
2972 | ||
2973 | static void wpa_driver_nl80211_rfkill_unblocked(void *ctx) | |
2974 | { | |
2975 | struct wpa_driver_nl80211_data *drv = ctx; | |
2976 | wpa_printf(MSG_DEBUG, "nl80211: RFKILL unblocked"); | |
c81eff1a BG |
2977 | if (linux_set_iface_flags(drv->global->ioctl_sock, |
2978 | drv->first_bss.ifname, 1)) { | |
8401a6b0 JM |
2979 | wpa_printf(MSG_DEBUG, "nl80211: Could not set interface UP " |
2980 | "after rfkill unblock"); | |
2981 | return; | |
2982 | } | |
a63063b4 | 2983 | /* rtnetlink ifup handler will report interface as enabled */ |
8401a6b0 JM |
2984 | } |
2985 | ||
2986 | ||
6859f1cb BG |
2987 | static void nl80211_get_phy_name(struct wpa_driver_nl80211_data *drv) |
2988 | { | |
2989 | /* Find phy (radio) to which this interface belongs */ | |
2990 | char buf[90], *pos; | |
2991 | int f, rv; | |
2992 | ||
2993 | drv->phyname[0] = '\0'; | |
2994 | snprintf(buf, sizeof(buf) - 1, "/sys/class/net/%s/phy80211/name", | |
2995 | drv->first_bss.ifname); | |
2996 | f = open(buf, O_RDONLY); | |
2997 | if (f < 0) { | |
2998 | wpa_printf(MSG_DEBUG, "Could not open file %s: %s", | |
2999 | buf, strerror(errno)); | |
3000 | return; | |
3001 | } | |
3002 | ||
3003 | rv = read(f, drv->phyname, sizeof(drv->phyname) - 1); | |
3004 | close(f); | |
3005 | if (rv < 0) { | |
3006 | wpa_printf(MSG_DEBUG, "Could not read file %s: %s", | |
3007 | buf, strerror(errno)); | |
3008 | return; | |
3009 | } | |
3010 | ||
3011 | drv->phyname[rv] = '\0'; | |
3012 | pos = os_strchr(drv->phyname, '\n'); | |
3013 | if (pos) | |
3014 | *pos = '\0'; | |
3015 | wpa_printf(MSG_DEBUG, "nl80211: interface %s in phy %s", | |
3016 | drv->first_bss.ifname, drv->phyname); | |
3017 | } | |
3018 | ||
3019 | ||
32ab4855 JB |
3020 | static void wpa_driver_nl80211_handle_eapol_tx_status(int sock, |
3021 | void *eloop_ctx, | |
3022 | void *handle) | |
3023 | { | |
3024 | struct wpa_driver_nl80211_data *drv = eloop_ctx; | |
3025 | u8 data[2048]; | |
3026 | struct msghdr msg; | |
3027 | struct iovec entry; | |
cad0f50e | 3028 | u8 control[512]; |
32ab4855 JB |
3029 | struct cmsghdr *cmsg; |
3030 | int res, found_ee = 0, found_wifi = 0, acked = 0; | |
3031 | union wpa_event_data event; | |
3032 | ||
3033 | memset(&msg, 0, sizeof(msg)); | |
3034 | msg.msg_iov = &entry; | |
3035 | msg.msg_iovlen = 1; | |
3036 | entry.iov_base = data; | |
3037 | entry.iov_len = sizeof(data); | |
3038 | msg.msg_control = &control; | |
3039 | msg.msg_controllen = sizeof(control); | |
3040 | ||
3041 | res = recvmsg(sock, &msg, MSG_ERRQUEUE); | |
3042 | /* if error or not fitting 802.3 header, return */ | |
3043 | if (res < 14) | |
3044 | return; | |
3045 | ||
3046 | for (cmsg = CMSG_FIRSTHDR(&msg); cmsg; cmsg = CMSG_NXTHDR(&msg, cmsg)) | |
3047 | { | |
3048 | if (cmsg->cmsg_level == SOL_SOCKET && | |
3049 | cmsg->cmsg_type == SCM_WIFI_STATUS) { | |
3050 | int *ack; | |
3051 | ||
3052 | found_wifi = 1; | |
3053 | ack = (void *)CMSG_DATA(cmsg); | |
3054 | acked = *ack; | |
3055 | } | |
3056 | ||
3057 | if (cmsg->cmsg_level == SOL_PACKET && | |
3058 | cmsg->cmsg_type == PACKET_TX_TIMESTAMP) { | |
3059 | struct sock_extended_err *err = | |
3060 | (struct sock_extended_err *)CMSG_DATA(cmsg); | |
3061 | ||
3062 | if (err->ee_origin == SO_EE_ORIGIN_TXSTATUS) | |
3063 | found_ee = 1; | |
3064 | } | |
3065 | } | |
3066 | ||
3067 | if (!found_ee || !found_wifi) | |
3068 | return; | |
3069 | ||
3070 | memset(&event, 0, sizeof(event)); | |
3071 | event.eapol_tx_status.dst = data; | |
3072 | event.eapol_tx_status.data = data + 14; | |
3073 | event.eapol_tx_status.data_len = res - 14; | |
3074 | event.eapol_tx_status.ack = acked; | |
3075 | wpa_supplicant_event(drv->ctx, EVENT_EAPOL_TX_STATUS, &event); | |
3076 | } | |
3077 | ||
3078 | ||
cc7a48d1 JB |
3079 | static int nl80211_init_bss(struct i802_bss *bss) |
3080 | { | |
3081 | bss->nl_cb = nl_cb_alloc(NL_CB_DEFAULT); | |
3082 | if (!bss->nl_cb) | |
3083 | return -1; | |
3084 | ||
3085 | nl_cb_set(bss->nl_cb, NL_CB_SEQ_CHECK, NL_CB_CUSTOM, | |
3086 | no_seq_check, NULL); | |
3087 | nl_cb_set(bss->nl_cb, NL_CB_VALID, NL_CB_CUSTOM, | |
3088 | process_bss_event, bss); | |
3089 | ||
3090 | return 0; | |
3091 | } | |
3092 | ||
3093 | ||
3094 | static void nl80211_destroy_bss(struct i802_bss *bss) | |
3095 | { | |
3096 | nl_cb_put(bss->nl_cb); | |
3097 | bss->nl_cb = NULL; | |
3098 | } | |
3099 | ||
3100 | ||
9fff9fdc JM |
3101 | /** |
3102 | * wpa_driver_nl80211_init - Initialize nl80211 driver interface | |
3103 | * @ctx: context to be used when calling wpa_supplicant functions, | |
3104 | * e.g., wpa_supplicant_event() | |
3105 | * @ifname: interface name, e.g., wlan0 | |
f2ed8023 | 3106 | * @global_priv: private driver global data from global_init() |
9fff9fdc JM |
3107 | * Returns: Pointer to private data, %NULL on failure |
3108 | */ | |
f2ed8023 JM |
3109 | static void * wpa_driver_nl80211_init(void *ctx, const char *ifname, |
3110 | void *global_priv) | |
9fff9fdc | 3111 | { |
9fff9fdc | 3112 | struct wpa_driver_nl80211_data *drv; |
8401a6b0 | 3113 | struct rfkill_config *rcfg; |
a2e40bb6 | 3114 | struct i802_bss *bss; |
9fff9fdc | 3115 | |
a5c696ad JM |
3116 | if (global_priv == NULL) |
3117 | return NULL; | |
9fff9fdc JM |
3118 | drv = os_zalloc(sizeof(*drv)); |
3119 | if (drv == NULL) | |
3120 | return NULL; | |
f2ed8023 | 3121 | drv->global = global_priv; |
9fff9fdc | 3122 | drv->ctx = ctx; |
a2e40bb6 FF |
3123 | bss = &drv->first_bss; |
3124 | bss->drv = drv; | |
a5e1eb20 SE |
3125 | bss->ctx = ctx; |
3126 | ||
a2e40bb6 | 3127 | os_strlcpy(bss->ifname, ifname, sizeof(bss->ifname)); |
9fff9fdc JM |
3128 | drv->monitor_ifidx = -1; |
3129 | drv->monitor_sock = -1; | |
d12dab4c | 3130 | drv->eapol_tx_sock = -1; |
b1f625e0 | 3131 | drv->ap_scan_as_station = NL80211_IFTYPE_UNSPECIFIED; |
9fff9fdc | 3132 | |
ba2d0d7d | 3133 | if (wpa_driver_nl80211_init_nl(drv)) { |
bbaf0837 JM |
3134 | os_free(drv); |
3135 | return NULL; | |
3136 | } | |
9fff9fdc | 3137 | |
cc7a48d1 JB |
3138 | if (nl80211_init_bss(bss)) |
3139 | goto failed; | |
3140 | ||
6859f1cb BG |
3141 | nl80211_get_phy_name(drv); |
3142 | ||
8401a6b0 JM |
3143 | rcfg = os_zalloc(sizeof(*rcfg)); |
3144 | if (rcfg == NULL) | |
3145 | goto failed; | |
3146 | rcfg->ctx = drv; | |
3147 | os_strlcpy(rcfg->ifname, ifname, sizeof(rcfg->ifname)); | |
3148 | rcfg->blocked_cb = wpa_driver_nl80211_rfkill_blocked; | |
3149 | rcfg->unblocked_cb = wpa_driver_nl80211_rfkill_unblocked; | |
3150 | drv->rfkill = rfkill_init(rcfg); | |
52169389 | 3151 | if (drv->rfkill == NULL) { |
8401a6b0 | 3152 | wpa_printf(MSG_DEBUG, "nl80211: RFKILL status not available"); |
52169389 JM |
3153 | os_free(rcfg); |
3154 | } | |
8401a6b0 | 3155 | |
08063178 | 3156 | if (wpa_driver_nl80211_finish_drv_init(drv)) |
bbaf0837 | 3157 | goto failed; |
7524cfb1 | 3158 | |
d12dab4c | 3159 | drv->eapol_tx_sock = socket(PF_PACKET, SOCK_DGRAM, 0); |
32ab4855 JB |
3160 | if (drv->eapol_tx_sock < 0) |
3161 | goto failed; | |
3162 | ||
3163 | if (drv->data_tx_status) { | |
3164 | int enabled = 1; | |
3165 | ||
3166 | if (setsockopt(drv->eapol_tx_sock, SOL_SOCKET, SO_WIFI_STATUS, | |
3167 | &enabled, sizeof(enabled)) < 0) { | |
3168 | wpa_printf(MSG_DEBUG, | |
3169 | "nl80211: wifi status sockopt failed\n"); | |
3170 | drv->data_tx_status = 0; | |
a11241fa JB |
3171 | if (!drv->use_monitor) |
3172 | drv->capa.flags &= | |
3173 | ~WPA_DRIVER_FLAGS_EAPOL_TX_STATUS; | |
32ab4855 JB |
3174 | } else { |
3175 | eloop_register_read_sock(drv->eapol_tx_sock, | |
3176 | wpa_driver_nl80211_handle_eapol_tx_status, | |
3177 | drv, NULL); | |
3178 | } | |
3179 | } | |
f10bfc9a | 3180 | |
dac12351 | 3181 | if (drv->global) { |
c4bb8817 | 3182 | dl_list_add(&drv->global->interfaces, &drv->list); |
dac12351 BG |
3183 | drv->in_interface_list = 1; |
3184 | } | |
c4bb8817 | 3185 | |
a2e40bb6 | 3186 | return bss; |
7524cfb1 | 3187 | |
bbaf0837 | 3188 | failed: |
dac12351 | 3189 | wpa_driver_nl80211_deinit(bss); |
7524cfb1 JM |
3190 | return NULL; |
3191 | } | |
3192 | ||
3193 | ||
a11241fa | 3194 | static int nl80211_register_frame(struct i802_bss *bss, |
5582a5d1 | 3195 | struct nl_handle *nl_handle, |
bd94971e | 3196 | u16 type, const u8 *match, size_t match_len) |
58f6fbe0 | 3197 | { |
a11241fa | 3198 | struct wpa_driver_nl80211_data *drv = bss->drv; |
58f6fbe0 JM |
3199 | struct nl_msg *msg; |
3200 | int ret = -1; | |
3201 | ||
3202 | msg = nlmsg_alloc(); | |
3203 | if (!msg) | |
3204 | return -1; | |
3205 | ||
36488c05 JM |
3206 | wpa_printf(MSG_DEBUG, "nl80211: Register frame type=0x%x nl_handle=%p", |
3207 | type, nl_handle); | |
3208 | wpa_hexdump(MSG_DEBUG, "nl80211: Register frame match", | |
3209 | match, match_len); | |
3210 | ||
9fb04070 | 3211 | nl80211_cmd(drv, msg, 0, NL80211_CMD_REGISTER_ACTION); |
58f6fbe0 | 3212 | |
a11241fa | 3213 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, bss->ifindex); |
bd94971e | 3214 | NLA_PUT_U16(msg, NL80211_ATTR_FRAME_TYPE, type); |
58f6fbe0 JM |
3215 | NLA_PUT(msg, NL80211_ATTR_FRAME_MATCH, match_len, match); |
3216 | ||
d6c9aab8 | 3217 | ret = send_and_recv(drv->global, nl_handle, msg, NULL, NULL); |
58f6fbe0 JM |
3218 | msg = NULL; |
3219 | if (ret) { | |
5582a5d1 JB |
3220 | wpa_printf(MSG_DEBUG, "nl80211: Register frame command " |
3221 | "failed (type=%u): ret=%d (%s)", | |
3222 | type, ret, strerror(-ret)); | |
3223 | wpa_hexdump(MSG_DEBUG, "nl80211: Register frame match", | |
58f6fbe0 JM |
3224 | match, match_len); |
3225 | goto nla_put_failure; | |
3226 | } | |
3227 | ret = 0; | |
3228 | nla_put_failure: | |
3229 | nlmsg_free(msg); | |
3230 | return ret; | |
3231 | } | |
3232 | ||
3233 | ||
a11241fa JB |
3234 | static int nl80211_alloc_mgmt_handle(struct i802_bss *bss) |
3235 | { | |
3236 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
3237 | ||
481234cf | 3238 | if (bss->nl_mgmt) { |
a11241fa | 3239 | wpa_printf(MSG_DEBUG, "nl80211: Mgmt reporting " |
36488c05 | 3240 | "already on! (nl_mgmt=%p)", bss->nl_mgmt); |
a11241fa JB |
3241 | return -1; |
3242 | } | |
3243 | ||
481234cf JM |
3244 | bss->nl_mgmt = nl_create_handle(drv->nl_cb, "mgmt"); |
3245 | if (bss->nl_mgmt == NULL) | |
a11241fa JB |
3246 | return -1; |
3247 | ||
481234cf | 3248 | eloop_register_read_sock(nl_socket_get_fd(bss->nl_mgmt), |
a11241fa | 3249 | wpa_driver_nl80211_event_receive, bss->nl_cb, |
481234cf | 3250 | bss->nl_mgmt); |
a11241fa JB |
3251 | |
3252 | return 0; | |
3253 | } | |
3254 | ||
3255 | ||
3256 | static int nl80211_register_action_frame(struct i802_bss *bss, | |
bd94971e JB |
3257 | const u8 *match, size_t match_len) |
3258 | { | |
3259 | u16 type = (WLAN_FC_TYPE_MGMT << 2) | (WLAN_FC_STYPE_ACTION << 4); | |
481234cf | 3260 | return nl80211_register_frame(bss, bss->nl_mgmt, |
5582a5d1 | 3261 | type, match, match_len); |
bd94971e JB |
3262 | } |
3263 | ||
3264 | ||
a11241fa | 3265 | static int nl80211_mgmt_subscribe_non_ap(struct i802_bss *bss) |
58f6fbe0 | 3266 | { |
a11241fa JB |
3267 | struct wpa_driver_nl80211_data *drv = bss->drv; |
3268 | ||
3269 | if (nl80211_alloc_mgmt_handle(bss)) | |
3270 | return -1; | |
36488c05 JM |
3271 | wpa_printf(MSG_DEBUG, "nl80211: Subscribe to mgmt frames with non-AP " |
3272 | "handle %p", bss->nl_mgmt); | |
a11241fa | 3273 | |
4fe9fa0d | 3274 | #if defined(CONFIG_P2P) || defined(CONFIG_INTERWORKING) |
046b26a2 | 3275 | /* GAS Initial Request */ |
a11241fa | 3276 | if (nl80211_register_action_frame(bss, (u8 *) "\x04\x0a", 2) < 0) |
046b26a2 JM |
3277 | return -1; |
3278 | /* GAS Initial Response */ | |
a11241fa | 3279 | if (nl80211_register_action_frame(bss, (u8 *) "\x04\x0b", 2) < 0) |
046b26a2 | 3280 | return -1; |
18708aad | 3281 | /* GAS Comeback Request */ |
a11241fa | 3282 | if (nl80211_register_action_frame(bss, (u8 *) "\x04\x0c", 2) < 0) |
18708aad JM |
3283 | return -1; |
3284 | /* GAS Comeback Response */ | |
a11241fa | 3285 | if (nl80211_register_action_frame(bss, (u8 *) "\x04\x0d", 2) < 0) |
18708aad | 3286 | return -1; |
4fe9fa0d JM |
3287 | #endif /* CONFIG_P2P || CONFIG_INTERWORKING */ |
3288 | #ifdef CONFIG_P2P | |
046b26a2 | 3289 | /* P2P Public Action */ |
a11241fa | 3290 | if (nl80211_register_action_frame(bss, |
046b26a2 JM |
3291 | (u8 *) "\x04\x09\x50\x6f\x9a\x09", |
3292 | 6) < 0) | |
3293 | return -1; | |
3294 | /* P2P Action */ | |
a11241fa | 3295 | if (nl80211_register_action_frame(bss, |
046b26a2 JM |
3296 | (u8 *) "\x7f\x50\x6f\x9a\x09", |
3297 | 5) < 0) | |
3298 | return -1; | |
3299 | #endif /* CONFIG_P2P */ | |
7d878ca7 JM |
3300 | #ifdef CONFIG_IEEE80211W |
3301 | /* SA Query Response */ | |
a11241fa | 3302 | if (nl80211_register_action_frame(bss, (u8 *) "\x08\x01", 2) < 0) |
7d878ca7 JM |
3303 | return -1; |
3304 | #endif /* CONFIG_IEEE80211W */ | |
35287637 AN |
3305 | #ifdef CONFIG_TDLS |
3306 | if ((drv->capa.flags & WPA_DRIVER_FLAGS_TDLS_SUPPORT)) { | |
3307 | /* TDLS Discovery Response */ | |
aa543c0c | 3308 | if (nl80211_register_action_frame(bss, (u8 *) "\x04\x0e", 2) < |
35287637 AN |
3309 | 0) |
3310 | return -1; | |
3311 | } | |
3312 | #endif /* CONFIG_TDLS */ | |
046b26a2 | 3313 | |
7b90c16a | 3314 | /* FT Action frames */ |
a11241fa | 3315 | if (nl80211_register_action_frame(bss, (u8 *) "\x06", 1) < 0) |
7b90c16a JM |
3316 | return -1; |
3317 | else | |
3318 | drv->capa.key_mgmt |= WPA_DRIVER_CAPA_KEY_MGMT_FT | | |
3319 | WPA_DRIVER_CAPA_KEY_MGMT_FT_PSK; | |
3320 | ||
71269b37 | 3321 | /* WNM - BSS Transition Management Request */ |
a11241fa JB |
3322 | if (nl80211_register_action_frame(bss, (u8 *) "\x0a\x07", 2) < 0) |
3323 | return -1; | |
bd896433 JM |
3324 | /* WNM-Sleep Mode Response */ |
3325 | if (nl80211_register_action_frame(bss, (u8 *) "\x0a\x11", 2) < 0) | |
3326 | return -1; | |
a11241fa JB |
3327 | |
3328 | return 0; | |
3329 | } | |
3330 | ||
3331 | ||
02bb32c3 JB |
3332 | static int nl80211_register_spurious_class3(struct i802_bss *bss) |
3333 | { | |
3334 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
3335 | struct nl_msg *msg; | |
3336 | int ret = -1; | |
3337 | ||
3338 | msg = nlmsg_alloc(); | |
3339 | if (!msg) | |
3340 | return -1; | |
3341 | ||
3342 | nl80211_cmd(drv, msg, 0, NL80211_CMD_UNEXPECTED_FRAME); | |
3343 | ||
3344 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, bss->ifindex); | |
3345 | ||
481234cf | 3346 | ret = send_and_recv(drv->global, bss->nl_mgmt, msg, NULL, NULL); |
02bb32c3 JB |
3347 | msg = NULL; |
3348 | if (ret) { | |
3349 | wpa_printf(MSG_DEBUG, "nl80211: Register spurious class3 " | |
3350 | "failed: ret=%d (%s)", | |
3351 | ret, strerror(-ret)); | |
3352 | goto nla_put_failure; | |
3353 | } | |
3354 | ret = 0; | |
3355 | nla_put_failure: | |
3356 | nlmsg_free(msg); | |
3357 | return ret; | |
3358 | } | |
3359 | ||
3360 | ||
a11241fa JB |
3361 | static int nl80211_mgmt_subscribe_ap(struct i802_bss *bss) |
3362 | { | |
3363 | static const int stypes[] = { | |
3364 | WLAN_FC_STYPE_AUTH, | |
3365 | WLAN_FC_STYPE_ASSOC_REQ, | |
3366 | WLAN_FC_STYPE_REASSOC_REQ, | |
3367 | WLAN_FC_STYPE_DISASSOC, | |
3368 | WLAN_FC_STYPE_DEAUTH, | |
3369 | WLAN_FC_STYPE_ACTION, | |
3370 | WLAN_FC_STYPE_PROBE_REQ, | |
3371 | /* Beacon doesn't work as mac80211 doesn't currently allow | |
3372 | * it, but it wouldn't really be the right thing anyway as | |
3373 | * it isn't per interface ... maybe just dump the scan | |
3374 | * results periodically for OLBC? | |
3375 | */ | |
3376 | // WLAN_FC_STYPE_BEACON, | |
3377 | }; | |
3378 | unsigned int i; | |
3379 | ||
3380 | if (nl80211_alloc_mgmt_handle(bss)) | |
71269b37 | 3381 | return -1; |
36488c05 JM |
3382 | wpa_printf(MSG_DEBUG, "nl80211: Subscribe to mgmt frames with AP " |
3383 | "handle %p", bss->nl_mgmt); | |
71269b37 | 3384 | |
a11241fa | 3385 | for (i = 0; i < sizeof(stypes) / sizeof(stypes[0]); i++) { |
481234cf | 3386 | if (nl80211_register_frame(bss, bss->nl_mgmt, |
a11241fa JB |
3387 | (WLAN_FC_TYPE_MGMT << 2) | |
3388 | (stypes[i] << 4), | |
3389 | NULL, 0) < 0) { | |
3390 | goto out_err; | |
3391 | } | |
3392 | } | |
3393 | ||
02bb32c3 JB |
3394 | if (nl80211_register_spurious_class3(bss)) |
3395 | goto out_err; | |
3396 | ||
e32ad281 JB |
3397 | if (nl80211_get_wiphy_data_ap(bss) == NULL) |
3398 | goto out_err; | |
3399 | ||
58f6fbe0 | 3400 | return 0; |
a11241fa JB |
3401 | |
3402 | out_err: | |
481234cf | 3403 | eloop_unregister_read_sock(nl_socket_get_fd(bss->nl_mgmt)); |
a11241fa JB |
3404 | nl_destroy_handles(&bss->nl_mgmt); |
3405 | return -1; | |
3406 | } | |
3407 | ||
3408 | ||
a6cc0602 JM |
3409 | static int nl80211_mgmt_subscribe_ap_dev_sme(struct i802_bss *bss) |
3410 | { | |
3411 | if (nl80211_alloc_mgmt_handle(bss)) | |
3412 | return -1; | |
3413 | wpa_printf(MSG_DEBUG, "nl80211: Subscribe to mgmt frames with AP " | |
3414 | "handle %p (device SME)", bss->nl_mgmt); | |
3415 | ||
3416 | if (nl80211_register_frame(bss, bss->nl_mgmt, | |
3417 | (WLAN_FC_TYPE_MGMT << 2) | | |
3418 | (WLAN_FC_STYPE_ACTION << 4), | |
3419 | NULL, 0) < 0) | |
3420 | goto out_err; | |
3421 | ||
3422 | return 0; | |
3423 | ||
3424 | out_err: | |
3425 | eloop_unregister_read_sock(nl_socket_get_fd(bss->nl_mgmt)); | |
3426 | nl_destroy_handles(&bss->nl_mgmt); | |
3427 | return -1; | |
3428 | } | |
3429 | ||
3430 | ||
36488c05 | 3431 | static void nl80211_mgmt_unsubscribe(struct i802_bss *bss, const char *reason) |
a11241fa | 3432 | { |
481234cf | 3433 | if (bss->nl_mgmt == NULL) |
a11241fa | 3434 | return; |
36488c05 JM |
3435 | wpa_printf(MSG_DEBUG, "nl80211: Unsubscribe mgmt frames handle %p " |
3436 | "(%s)", bss->nl_mgmt, reason); | |
481234cf | 3437 | eloop_unregister_read_sock(nl_socket_get_fd(bss->nl_mgmt)); |
a11241fa | 3438 | nl_destroy_handles(&bss->nl_mgmt); |
e32ad281 JB |
3439 | |
3440 | nl80211_put_wiphy_data_ap(bss); | |
58f6fbe0 JM |
3441 | } |
3442 | ||
3443 | ||
8401a6b0 JM |
3444 | static void wpa_driver_nl80211_send_rfkill(void *eloop_ctx, void *timeout_ctx) |
3445 | { | |
3446 | wpa_supplicant_event(timeout_ctx, EVENT_INTERFACE_DISABLED, NULL); | |
3447 | } | |
3448 | ||
3449 | ||
362f781e | 3450 | static int |
7524cfb1 JM |
3451 | wpa_driver_nl80211_finish_drv_init(struct wpa_driver_nl80211_data *drv) |
3452 | { | |
a2e40bb6 | 3453 | struct i802_bss *bss = &drv->first_bss; |
8401a6b0 | 3454 | int send_rfkill_event = 0; |
a2e40bb6 FF |
3455 | |
3456 | drv->ifindex = if_nametoindex(bss->ifname); | |
3457 | drv->first_bss.ifindex = drv->ifindex; | |
a87c9d96 | 3458 | |
bbaf0837 | 3459 | #ifndef HOSTAPD |
ff6a158b JM |
3460 | /* |
3461 | * Make sure the interface starts up in station mode unless this is a | |
3462 | * dynamically added interface (e.g., P2P) that was already configured | |
3463 | * with proper iftype. | |
3464 | */ | |
a5c696ad | 3465 | if (drv->ifindex != drv->global->if_add_ifindex && |
b1f625e0 | 3466 | wpa_driver_nl80211_set_mode(bss, NL80211_IFTYPE_STATION) < 0) { |
6e8183d7 | 3467 | wpa_printf(MSG_ERROR, "nl80211: Could not configure driver to " |
a87c9d96 | 3468 | "use managed mode"); |
6e8183d7 | 3469 | return -1; |
a87c9d96 JM |
3470 | } |
3471 | ||
c81eff1a | 3472 | if (linux_set_iface_flags(drv->global->ioctl_sock, bss->ifname, 1)) { |
8401a6b0 JM |
3473 | if (rfkill_is_blocked(drv->rfkill)) { |
3474 | wpa_printf(MSG_DEBUG, "nl80211: Could not yet enable " | |
3475 | "interface '%s' due to rfkill", | |
3476 | bss->ifname); | |
a63063b4 | 3477 | drv->if_disabled = 1; |
8401a6b0 JM |
3478 | send_rfkill_event = 1; |
3479 | } else { | |
3480 | wpa_printf(MSG_ERROR, "nl80211: Could not set " | |
3481 | "interface '%s' UP", bss->ifname); | |
3482 | return -1; | |
3483 | } | |
362f781e | 3484 | } |
3f5285e8 | 3485 | |
36d84860 | 3486 | netlink_send_oper_ifla(drv->global->netlink, drv->ifindex, |
e2d02c29 | 3487 | 1, IF_OPER_DORMANT); |
bbaf0837 | 3488 | #endif /* HOSTAPD */ |
362f781e | 3489 | |
2fee890a JM |
3490 | if (wpa_driver_nl80211_capa(drv)) |
3491 | return -1; | |
3492 | ||
c81eff1a | 3493 | if (linux_get_ifhwaddr(drv->global->ioctl_sock, bss->ifname, |
341eebee | 3494 | bss->addr)) |
2136f480 | 3495 | return -1; |
f2ed8023 | 3496 | |
8401a6b0 JM |
3497 | if (send_rfkill_event) { |
3498 | eloop_register_timeout(0, 0, wpa_driver_nl80211_send_rfkill, | |
3499 | drv, drv->ctx); | |
3500 | } | |
3501 | ||
362f781e | 3502 | return 0; |
3f5285e8 JM |
3503 | } |
3504 | ||
3505 | ||
8a27af5c JM |
3506 | static int wpa_driver_nl80211_del_beacon(struct wpa_driver_nl80211_data *drv) |
3507 | { | |
3508 | struct nl_msg *msg; | |
3509 | ||
3510 | msg = nlmsg_alloc(); | |
3511 | if (!msg) | |
3512 | return -ENOMEM; | |
3513 | ||
9fb04070 | 3514 | nl80211_cmd(drv, msg, 0, NL80211_CMD_DEL_BEACON); |
8a27af5c JM |
3515 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, drv->ifindex); |
3516 | ||
3517 | return send_and_recv_msgs(drv, msg, NULL, NULL); | |
3518 | nla_put_failure: | |
5883168a | 3519 | nlmsg_free(msg); |
8a27af5c JM |
3520 | return -ENOBUFS; |
3521 | } | |
8a27af5c JM |
3522 | |
3523 | ||
3f5285e8 | 3524 | /** |
7e5ba1b9 | 3525 | * wpa_driver_nl80211_deinit - Deinitialize nl80211 driver interface |
9ebce9c5 | 3526 | * @bss: Pointer to private nl80211 data from wpa_driver_nl80211_init() |
3f5285e8 JM |
3527 | * |
3528 | * Shut down driver interface and processing of driver events. Free | |
3529 | * private data buffer if one was allocated in wpa_driver_nl80211_init(). | |
3530 | */ | |
9ebce9c5 | 3531 | static void wpa_driver_nl80211_deinit(struct i802_bss *bss) |
3f5285e8 | 3532 | { |
a2e40bb6 | 3533 | struct wpa_driver_nl80211_data *drv = bss->drv; |
3f5285e8 | 3534 | |
873d0fcf | 3535 | bss->in_deinit = 1; |
32ab4855 JB |
3536 | if (drv->data_tx_status) |
3537 | eloop_unregister_read_sock(drv->eapol_tx_sock); | |
d12dab4c JB |
3538 | if (drv->eapol_tx_sock >= 0) |
3539 | close(drv->eapol_tx_sock); | |
f10bfc9a | 3540 | |
481234cf | 3541 | if (bss->nl_preq) |
5582a5d1 | 3542 | wpa_driver_nl80211_probe_req_report(bss, 0); |
e17a2477 | 3543 | if (bss->added_if_into_bridge) { |
c81eff1a BG |
3544 | if (linux_br_del_if(drv->global->ioctl_sock, bss->brname, |
3545 | bss->ifname) < 0) | |
94627f6c JM |
3546 | wpa_printf(MSG_INFO, "nl80211: Failed to remove " |
3547 | "interface %s from bridge %s: %s", | |
e17a2477 | 3548 | bss->ifname, bss->brname, strerror(errno)); |
94627f6c | 3549 | } |
e17a2477 | 3550 | if (bss->added_bridge) { |
c81eff1a | 3551 | if (linux_br_del(drv->global->ioctl_sock, bss->brname) < 0) |
94627f6c JM |
3552 | wpa_printf(MSG_INFO, "nl80211: Failed to remove " |
3553 | "bridge %s: %s", | |
e17a2477 | 3554 | bss->brname, strerror(errno)); |
94627f6c JM |
3555 | } |
3556 | ||
460456f8 | 3557 | nl80211_remove_monitor_interface(drv); |
8a27af5c | 3558 | |
b1f625e0 | 3559 | if (is_ap_interface(drv->nlmode)) |
8a27af5c | 3560 | wpa_driver_nl80211_del_beacon(drv); |
0915d02c | 3561 | |
bbaf0837 JM |
3562 | #ifdef HOSTAPD |
3563 | if (drv->last_freq_ht) { | |
3564 | /* Clear HT flags from the driver */ | |
3565 | struct hostapd_freq_params freq; | |
3566 | os_memset(&freq, 0, sizeof(freq)); | |
3567 | freq.freq = drv->last_freq; | |
9ebce9c5 | 3568 | wpa_driver_nl80211_set_freq(bss, &freq); |
bbaf0837 JM |
3569 | } |
3570 | ||
bbaf0837 JM |
3571 | if (drv->eapol_sock >= 0) { |
3572 | eloop_unregister_read_sock(drv->eapol_sock); | |
3573 | close(drv->eapol_sock); | |
3574 | } | |
3575 | ||
3576 | if (drv->if_indices != drv->default_if_indices) | |
3577 | os_free(drv->if_indices); | |
1b648c7e | 3578 | #endif /* HOSTAPD */ |
3f5285e8 | 3579 | |
b3af99d2 | 3580 | if (drv->disabled_11b_rates) |
4e5cb1a3 JM |
3581 | nl80211_disable_11b_rates(drv, drv->ifindex, 0); |
3582 | ||
36d84860 BG |
3583 | netlink_send_oper_ifla(drv->global->netlink, drv->ifindex, 0, |
3584 | IF_OPER_UP); | |
8401a6b0 | 3585 | rfkill_deinit(drv->rfkill); |
3f5285e8 | 3586 | |
bbaf0837 JM |
3587 | eloop_cancel_timeout(wpa_driver_nl80211_scan_timeout, drv, drv->ctx); |
3588 | ||
c81eff1a | 3589 | (void) linux_set_iface_flags(drv->global->ioctl_sock, bss->ifname, 0); |
b1f625e0 | 3590 | wpa_driver_nl80211_set_mode(bss, NL80211_IFTYPE_STATION); |
36488c05 | 3591 | nl80211_mgmt_unsubscribe(bss, "deinit"); |
3f5285e8 | 3592 | |
1afc986d | 3593 | nl_cb_put(drv->nl_cb); |
3f5285e8 | 3594 | |
cc7a48d1 JB |
3595 | nl80211_destroy_bss(&drv->first_bss); |
3596 | ||
3812464c JM |
3597 | os_free(drv->filter_ssids); |
3598 | ||
536fd62d JM |
3599 | os_free(drv->auth_ie); |
3600 | ||
dac12351 | 3601 | if (drv->in_interface_list) |
f2ed8023 JM |
3602 | dl_list_del(&drv->list); |
3603 | ||
3f5285e8 JM |
3604 | os_free(drv); |
3605 | } | |
3606 | ||
3607 | ||
3608 | /** | |
3609 | * wpa_driver_nl80211_scan_timeout - Scan timeout to report scan completion | |
ad1e68e6 | 3610 | * @eloop_ctx: Driver private data |
3f5285e8 JM |
3611 | * @timeout_ctx: ctx argument given to wpa_driver_nl80211_init() |
3612 | * | |
3613 | * This function can be used as registered timeout when starting a scan to | |
3614 | * generate a scan completed event if the driver does not report this. | |
3615 | */ | |
3616 | static void wpa_driver_nl80211_scan_timeout(void *eloop_ctx, void *timeout_ctx) | |
3617 | { | |
ad1e68e6 | 3618 | struct wpa_driver_nl80211_data *drv = eloop_ctx; |
b1f625e0 | 3619 | if (drv->ap_scan_as_station != NL80211_IFTYPE_UNSPECIFIED) { |
a2e40bb6 | 3620 | wpa_driver_nl80211_set_mode(&drv->first_bss, |
b1f625e0 EP |
3621 | drv->ap_scan_as_station); |
3622 | drv->ap_scan_as_station = NL80211_IFTYPE_UNSPECIFIED; | |
ad1e68e6 | 3623 | } |
3f5285e8 JM |
3624 | wpa_printf(MSG_DEBUG, "Scan timeout - try to get results"); |
3625 | wpa_supplicant_event(timeout_ctx, EVENT_SCAN_RESULTS, NULL); | |
3626 | } | |
3627 | ||
3628 | ||
95ac3bf4 JM |
3629 | static struct nl_msg * |
3630 | nl80211_scan_common(struct wpa_driver_nl80211_data *drv, u8 cmd, | |
3631 | struct wpa_driver_scan_params *params) | |
3f5285e8 | 3632 | { |
95ac3bf4 JM |
3633 | struct nl_msg *msg; |
3634 | int err; | |
6a1063e0 | 3635 | size_t i; |
3f5285e8 | 3636 | |
0e75527f | 3637 | msg = nlmsg_alloc(); |
f0494d0f | 3638 | if (!msg) |
95ac3bf4 | 3639 | return NULL; |
3812464c | 3640 | |
95ac3bf4 | 3641 | nl80211_cmd(drv, msg, 0, cmd); |
0e75527f | 3642 | |
95ac3bf4 JM |
3643 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, drv->ifindex) < 0) |
3644 | goto fail; | |
3f5285e8 | 3645 | |
f0494d0f | 3646 | if (params->num_ssids) { |
95ac3bf4 | 3647 | struct nl_msg *ssids = nlmsg_alloc(); |
f0494d0f | 3648 | if (ssids == NULL) |
95ac3bf4 | 3649 | goto fail; |
f0494d0f JM |
3650 | for (i = 0; i < params->num_ssids; i++) { |
3651 | wpa_hexdump_ascii(MSG_MSGDUMP, "nl80211: Scan SSID", | |
3652 | params->ssids[i].ssid, | |
3653 | params->ssids[i].ssid_len); | |
95ac3bf4 JM |
3654 | if (nla_put(ssids, i + 1, params->ssids[i].ssid_len, |
3655 | params->ssids[i].ssid) < 0) { | |
3656 | nlmsg_free(ssids); | |
3657 | goto fail; | |
3658 | } | |
f0494d0f | 3659 | } |
95ac3bf4 JM |
3660 | err = nla_put_nested(msg, NL80211_ATTR_SCAN_SSIDS, ssids); |
3661 | nlmsg_free(ssids); | |
3662 | if (err < 0) | |
3663 | goto fail; | |
3f5285e8 JM |
3664 | } |
3665 | ||
d173df52 | 3666 | if (params->extra_ies) { |
3b1c7bfd JM |
3667 | wpa_hexdump(MSG_MSGDUMP, "nl80211: Scan extra IEs", |
3668 | params->extra_ies, params->extra_ies_len); | |
95ac3bf4 JM |
3669 | if (nla_put(msg, NL80211_ATTR_IE, params->extra_ies_len, |
3670 | params->extra_ies) < 0) | |
3671 | goto fail; | |
d173df52 JM |
3672 | } |
3673 | ||
d3a98225 | 3674 | if (params->freqs) { |
95ac3bf4 | 3675 | struct nl_msg *freqs = nlmsg_alloc(); |
f0494d0f | 3676 | if (freqs == NULL) |
95ac3bf4 | 3677 | goto fail; |
9fad706c JM |
3678 | for (i = 0; params->freqs[i]; i++) { |
3679 | wpa_printf(MSG_MSGDUMP, "nl80211: Scan frequency %u " | |
3680 | "MHz", params->freqs[i]); | |
95ac3bf4 JM |
3681 | if (nla_put_u32(freqs, i + 1, params->freqs[i]) < 0) { |
3682 | nlmsg_free(freqs); | |
3683 | goto fail; | |
3684 | } | |
9fad706c | 3685 | } |
95ac3bf4 JM |
3686 | err = nla_put_nested(msg, NL80211_ATTR_SCAN_FREQUENCIES, |
3687 | freqs); | |
3688 | nlmsg_free(freqs); | |
3689 | if (err < 0) | |
3690 | goto fail; | |
d3a98225 JM |
3691 | } |
3692 | ||
95ac3bf4 JM |
3693 | os_free(drv->filter_ssids); |
3694 | drv->filter_ssids = params->filter_ssids; | |
3695 | params->filter_ssids = NULL; | |
3696 | drv->num_filter_ssids = params->num_filter_ssids; | |
3697 | ||
3698 | return msg; | |
3699 | ||
3700 | fail: | |
3701 | nlmsg_free(msg); | |
3702 | return NULL; | |
3703 | } | |
3704 | ||
3705 | ||
3706 | /** | |
3707 | * wpa_driver_nl80211_scan - Request the driver to initiate scan | |
9ebce9c5 | 3708 | * @bss: Pointer to private driver data from wpa_driver_nl80211_init() |
95ac3bf4 JM |
3709 | * @params: Scan parameters |
3710 | * Returns: 0 on success, -1 on failure | |
3711 | */ | |
9ebce9c5 | 3712 | static int wpa_driver_nl80211_scan(struct i802_bss *bss, |
95ac3bf4 JM |
3713 | struct wpa_driver_scan_params *params) |
3714 | { | |
95ac3bf4 JM |
3715 | struct wpa_driver_nl80211_data *drv = bss->drv; |
3716 | int ret = -1, timeout; | |
3717 | struct nl_msg *msg, *rates = NULL; | |
3718 | ||
3719 | drv->scan_for_auth = 0; | |
3720 | ||
3721 | msg = nl80211_scan_common(drv, NL80211_CMD_TRIGGER_SCAN, params); | |
3722 | if (!msg) | |
3723 | return -1; | |
3724 | ||
47185fc7 | 3725 | if (params->p2p_probe) { |
8a6a1e1b JM |
3726 | wpa_printf(MSG_DEBUG, "nl80211: P2P probe - mask SuppRates"); |
3727 | ||
f0494d0f JM |
3728 | rates = nlmsg_alloc(); |
3729 | if (rates == NULL) | |
3730 | goto nla_put_failure; | |
3731 | ||
47185fc7 RM |
3732 | /* |
3733 | * Remove 2.4 GHz rates 1, 2, 5.5, 11 Mbps from supported rates | |
3734 | * by masking out everything else apart from the OFDM rates 6, | |
3735 | * 9, 12, 18, 24, 36, 48, 54 Mbps from non-MCS rates. All 5 GHz | |
3736 | * rates are left enabled. | |
3737 | */ | |
3738 | NLA_PUT(rates, NL80211_BAND_2GHZ, 8, | |
3739 | "\x0c\x12\x18\x24\x30\x48\x60\x6c"); | |
f0494d0f JM |
3740 | if (nla_put_nested(msg, NL80211_ATTR_SCAN_SUPP_RATES, rates) < |
3741 | 0) | |
3742 | goto nla_put_failure; | |
970fa12e RM |
3743 | |
3744 | NLA_PUT_FLAG(msg, NL80211_ATTR_TX_NO_CCK_RATE); | |
47185fc7 RM |
3745 | } |
3746 | ||
0e75527f JM |
3747 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
3748 | msg = NULL; | |
3749 | if (ret) { | |
3750 | wpa_printf(MSG_DEBUG, "nl80211: Scan trigger failed: ret=%d " | |
3751 | "(%s)", ret, strerror(-ret)); | |
ad1e68e6 | 3752 | #ifdef HOSTAPD |
b1f625e0 | 3753 | if (is_ap_interface(drv->nlmode)) { |
ad1e68e6 JM |
3754 | /* |
3755 | * mac80211 does not allow scan requests in AP mode, so | |
3756 | * try to do this in station mode. | |
3757 | */ | |
b1f625e0 EP |
3758 | if (wpa_driver_nl80211_set_mode( |
3759 | bss, NL80211_IFTYPE_STATION)) | |
ad1e68e6 JM |
3760 | goto nla_put_failure; |
3761 | ||
085b29f1 | 3762 | if (wpa_driver_nl80211_scan(bss, params)) { |
b1f625e0 | 3763 | wpa_driver_nl80211_set_mode(bss, drv->nlmode); |
ad1e68e6 JM |
3764 | goto nla_put_failure; |
3765 | } | |
3766 | ||
3767 | /* Restore AP mode when processing scan results */ | |
b1f625e0 | 3768 | drv->ap_scan_as_station = drv->nlmode; |
ad1e68e6 JM |
3769 | ret = 0; |
3770 | } else | |
3771 | goto nla_put_failure; | |
3772 | #else /* HOSTAPD */ | |
0e75527f | 3773 | goto nla_put_failure; |
ad1e68e6 | 3774 | #endif /* HOSTAPD */ |
3f5285e8 JM |
3775 | } |
3776 | ||
3777 | /* Not all drivers generate "scan completed" wireless event, so try to | |
3778 | * read results after a timeout. */ | |
0e75527f | 3779 | timeout = 10; |
3f5285e8 JM |
3780 | if (drv->scan_complete_events) { |
3781 | /* | |
d173df52 JM |
3782 | * The driver seems to deliver events to notify when scan is |
3783 | * complete, so use longer timeout to avoid race conditions | |
3784 | * with scanning and following association request. | |
3f5285e8 JM |
3785 | */ |
3786 | timeout = 30; | |
3787 | } | |
3788 | wpa_printf(MSG_DEBUG, "Scan requested (ret=%d) - scan timeout %d " | |
3789 | "seconds", ret, timeout); | |
3790 | eloop_cancel_timeout(wpa_driver_nl80211_scan_timeout, drv, drv->ctx); | |
0e75527f JM |
3791 | eloop_register_timeout(timeout, 0, wpa_driver_nl80211_scan_timeout, |
3792 | drv, drv->ctx); | |
3f5285e8 | 3793 | |
0e75527f | 3794 | nla_put_failure: |
0e75527f | 3795 | nlmsg_free(msg); |
47185fc7 | 3796 | nlmsg_free(rates); |
3f5285e8 JM |
3797 | return ret; |
3798 | } | |
3799 | ||
3800 | ||
d21c63b9 LC |
3801 | /** |
3802 | * wpa_driver_nl80211_sched_scan - Initiate a scheduled scan | |
3803 | * @priv: Pointer to private driver data from wpa_driver_nl80211_init() | |
3804 | * @params: Scan parameters | |
3805 | * @interval: Interval between scan cycles in milliseconds | |
3806 | * Returns: 0 on success, -1 on failure or if not supported | |
3807 | */ | |
3808 | static int wpa_driver_nl80211_sched_scan(void *priv, | |
3809 | struct wpa_driver_scan_params *params, | |
3810 | u32 interval) | |
3811 | { | |
3812 | struct i802_bss *bss = priv; | |
3813 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
6afbc3d6 | 3814 | int ret = -1; |
95ac3bf4 | 3815 | struct nl_msg *msg; |
6afbc3d6 JM |
3816 | struct nl_msg *match_set_ssid = NULL, *match_sets = NULL; |
3817 | struct nl_msg *match_set_rssi = NULL; | |
d21c63b9 LC |
3818 | size_t i; |
3819 | ||
216eede8 DS |
3820 | #ifdef ANDROID |
3821 | if (!drv->capa.sched_scan_supported) | |
3822 | return android_pno_start(bss, params); | |
3823 | #endif /* ANDROID */ | |
3824 | ||
95ac3bf4 | 3825 | msg = nl80211_scan_common(drv, NL80211_CMD_START_SCHED_SCAN, params); |
6afbc3d6 JM |
3826 | if (!msg) |
3827 | goto nla_put_failure; | |
d21c63b9 | 3828 | |
d21c63b9 LC |
3829 | NLA_PUT_U32(msg, NL80211_ATTR_SCHED_SCAN_INTERVAL, interval); |
3830 | ||
bf8d6d24 TP |
3831 | if ((drv->num_filter_ssids && |
3832 | (int) drv->num_filter_ssids <= drv->capa.max_match_sets) || | |
3833 | params->filter_rssi) { | |
bd525934 | 3834 | match_sets = nlmsg_alloc(); |
6afbc3d6 JM |
3835 | if (match_sets == NULL) |
3836 | goto nla_put_failure; | |
bd525934 LC |
3837 | |
3838 | for (i = 0; i < drv->num_filter_ssids; i++) { | |
3839 | wpa_hexdump_ascii(MSG_MSGDUMP, | |
3840 | "nl80211: Sched scan filter SSID", | |
3841 | drv->filter_ssids[i].ssid, | |
3842 | drv->filter_ssids[i].ssid_len); | |
3843 | ||
3844 | match_set_ssid = nlmsg_alloc(); | |
6afbc3d6 JM |
3845 | if (match_set_ssid == NULL) |
3846 | goto nla_put_failure; | |
3847 | NLA_PUT(match_set_ssid, | |
bd525934 LC |
3848 | NL80211_ATTR_SCHED_SCAN_MATCH_SSID, |
3849 | drv->filter_ssids[i].ssid_len, | |
3850 | drv->filter_ssids[i].ssid); | |
3851 | ||
6afbc3d6 JM |
3852 | if (nla_put_nested(match_sets, i + 1, match_set_ssid) < |
3853 | 0) | |
3854 | goto nla_put_failure; | |
bd525934 LC |
3855 | } |
3856 | ||
bf8d6d24 TP |
3857 | if (params->filter_rssi) { |
3858 | match_set_rssi = nlmsg_alloc(); | |
6afbc3d6 JM |
3859 | if (match_set_rssi == NULL) |
3860 | goto nla_put_failure; | |
bf8d6d24 TP |
3861 | NLA_PUT_U32(match_set_rssi, |
3862 | NL80211_SCHED_SCAN_MATCH_ATTR_RSSI, | |
3863 | params->filter_rssi); | |
3864 | wpa_printf(MSG_MSGDUMP, | |
3865 | "nl80211: Sched scan RSSI filter %d dBm", | |
3866 | params->filter_rssi); | |
6afbc3d6 JM |
3867 | if (nla_put_nested(match_sets, 0, match_set_rssi) < 0) |
3868 | goto nla_put_failure; | |
bf8d6d24 TP |
3869 | } |
3870 | ||
6afbc3d6 JM |
3871 | if (nla_put_nested(msg, NL80211_ATTR_SCHED_SCAN_MATCH, |
3872 | match_sets) < 0) | |
3873 | goto nla_put_failure; | |
bd525934 LC |
3874 | } |
3875 | ||
d21c63b9 LC |
3876 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
3877 | ||
3878 | /* TODO: if we get an error here, we should fall back to normal scan */ | |
3879 | ||
3880 | msg = NULL; | |
3881 | if (ret) { | |
3882 | wpa_printf(MSG_DEBUG, "nl80211: Sched scan start failed: " | |
3883 | "ret=%d (%s)", ret, strerror(-ret)); | |
3884 | goto nla_put_failure; | |
3885 | } | |
3886 | ||
3887 | wpa_printf(MSG_DEBUG, "nl80211: Sched scan requested (ret=%d) - " | |
3888 | "scan interval %d msec", ret, interval); | |
3889 | ||
3890 | nla_put_failure: | |
6afbc3d6 JM |
3891 | nlmsg_free(match_set_ssid); |
3892 | nlmsg_free(match_sets); | |
3893 | nlmsg_free(match_set_rssi); | |
d21c63b9 | 3894 | nlmsg_free(msg); |
d21c63b9 LC |
3895 | return ret; |
3896 | } | |
3897 | ||
3898 | ||
3899 | /** | |
3900 | * wpa_driver_nl80211_stop_sched_scan - Stop a scheduled scan | |
3901 | * @priv: Pointer to private driver data from wpa_driver_nl80211_init() | |
3902 | * Returns: 0 on success, -1 on failure or if not supported | |
3903 | */ | |
3904 | static int wpa_driver_nl80211_stop_sched_scan(void *priv) | |
3905 | { | |
3906 | struct i802_bss *bss = priv; | |
3907 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
3908 | int ret = 0; | |
3909 | struct nl_msg *msg; | |
3910 | ||
216eede8 DS |
3911 | #ifdef ANDROID |
3912 | if (!drv->capa.sched_scan_supported) | |
3913 | return android_pno_stop(bss); | |
3914 | #endif /* ANDROID */ | |
3915 | ||
d21c63b9 LC |
3916 | msg = nlmsg_alloc(); |
3917 | if (!msg) | |
3918 | return -1; | |
3919 | ||
9fb04070 | 3920 | nl80211_cmd(drv, msg, 0, NL80211_CMD_STOP_SCHED_SCAN); |
d21c63b9 LC |
3921 | |
3922 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, drv->ifindex); | |
3923 | ||
3924 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); | |
3925 | msg = NULL; | |
3926 | if (ret) { | |
3927 | wpa_printf(MSG_DEBUG, "nl80211: Sched scan stop failed: " | |
3928 | "ret=%d (%s)", ret, strerror(-ret)); | |
3929 | goto nla_put_failure; | |
3930 | } | |
3931 | ||
3932 | wpa_printf(MSG_DEBUG, "nl80211: Sched scan stop sent (ret=%d)", ret); | |
3933 | ||
3934 | nla_put_failure: | |
3935 | nlmsg_free(msg); | |
3936 | return ret; | |
3937 | } | |
3938 | ||
3939 | ||
3812464c JM |
3940 | static const u8 * nl80211_get_ie(const u8 *ies, size_t ies_len, u8 ie) |
3941 | { | |
3942 | const u8 *end, *pos; | |
3943 | ||
3944 | if (ies == NULL) | |
3945 | return NULL; | |
3946 | ||
3947 | pos = ies; | |
3948 | end = ies + ies_len; | |
3949 | ||
3950 | while (pos + 1 < end) { | |
3951 | if (pos + 2 + pos[1] > end) | |
3952 | break; | |
3953 | if (pos[0] == ie) | |
3954 | return pos; | |
3955 | pos += 2 + pos[1]; | |
3956 | } | |
3957 | ||
3958 | return NULL; | |
3959 | } | |
3960 | ||
3961 | ||
3962 | static int nl80211_scan_filtered(struct wpa_driver_nl80211_data *drv, | |
3963 | const u8 *ie, size_t ie_len) | |
3964 | { | |
3965 | const u8 *ssid; | |
3966 | size_t i; | |
3967 | ||
3968 | if (drv->filter_ssids == NULL) | |
3969 | return 0; | |
3970 | ||
3971 | ssid = nl80211_get_ie(ie, ie_len, WLAN_EID_SSID); | |
3972 | if (ssid == NULL) | |
3973 | return 1; | |
3974 | ||
3975 | for (i = 0; i < drv->num_filter_ssids; i++) { | |
3976 | if (ssid[1] == drv->filter_ssids[i].ssid_len && | |
3977 | os_memcmp(ssid + 2, drv->filter_ssids[i].ssid, ssid[1]) == | |
3978 | 0) | |
3979 | return 0; | |
3980 | } | |
3981 | ||
3982 | return 1; | |
3983 | } | |
3984 | ||
3985 | ||
b3db1e1c | 3986 | static int bss_info_handler(struct nl_msg *msg, void *arg) |
3f5285e8 | 3987 | { |
b3db1e1c JM |
3988 | struct nlattr *tb[NL80211_ATTR_MAX + 1]; |
3989 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); | |
3990 | struct nlattr *bss[NL80211_BSS_MAX + 1]; | |
3991 | static struct nla_policy bss_policy[NL80211_BSS_MAX + 1] = { | |
3992 | [NL80211_BSS_BSSID] = { .type = NLA_UNSPEC }, | |
3993 | [NL80211_BSS_FREQUENCY] = { .type = NLA_U32 }, | |
3994 | [NL80211_BSS_TSF] = { .type = NLA_U64 }, | |
3995 | [NL80211_BSS_BEACON_INTERVAL] = { .type = NLA_U16 }, | |
3996 | [NL80211_BSS_CAPABILITY] = { .type = NLA_U16 }, | |
3997 | [NL80211_BSS_INFORMATION_ELEMENTS] = { .type = NLA_UNSPEC }, | |
3998 | [NL80211_BSS_SIGNAL_MBM] = { .type = NLA_U32 }, | |
3999 | [NL80211_BSS_SIGNAL_UNSPEC] = { .type = NLA_U8 }, | |
e6b8efeb | 4000 | [NL80211_BSS_STATUS] = { .type = NLA_U32 }, |
b3ad11bb | 4001 | [NL80211_BSS_SEEN_MS_AGO] = { .type = NLA_U32 }, |
8c090654 | 4002 | [NL80211_BSS_BEACON_IES] = { .type = NLA_UNSPEC }, |
b3db1e1c | 4003 | }; |
3812464c JM |
4004 | struct nl80211_bss_info_arg *_arg = arg; |
4005 | struct wpa_scan_results *res = _arg->res; | |
3f5285e8 JM |
4006 | struct wpa_scan_res **tmp; |
4007 | struct wpa_scan_res *r; | |
8c090654 JM |
4008 | const u8 *ie, *beacon_ie; |
4009 | size_t ie_len, beacon_ie_len; | |
4010 | u8 *pos; | |
46957a9b | 4011 | size_t i; |
3f5285e8 | 4012 | |
b3db1e1c JM |
4013 | nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), |
4014 | genlmsg_attrlen(gnlh, 0), NULL); | |
4015 | if (!tb[NL80211_ATTR_BSS]) | |
4016 | return NL_SKIP; | |
4017 | if (nla_parse_nested(bss, NL80211_BSS_MAX, tb[NL80211_ATTR_BSS], | |
4018 | bss_policy)) | |
4019 | return NL_SKIP; | |
f5a8d422 JM |
4020 | if (bss[NL80211_BSS_STATUS]) { |
4021 | enum nl80211_bss_status status; | |
4022 | status = nla_get_u32(bss[NL80211_BSS_STATUS]); | |
4023 | if (status == NL80211_BSS_STATUS_ASSOCIATED && | |
4024 | bss[NL80211_BSS_FREQUENCY]) { | |
4025 | _arg->assoc_freq = | |
4026 | nla_get_u32(bss[NL80211_BSS_FREQUENCY]); | |
4027 | wpa_printf(MSG_DEBUG, "nl80211: Associated on %u MHz", | |
4028 | _arg->assoc_freq); | |
4029 | } | |
20f5a4c2 JM |
4030 | if (status == NL80211_BSS_STATUS_ASSOCIATED && |
4031 | bss[NL80211_BSS_BSSID]) { | |
4032 | os_memcpy(_arg->assoc_bssid, | |
4033 | nla_data(bss[NL80211_BSS_BSSID]), ETH_ALEN); | |
4034 | wpa_printf(MSG_DEBUG, "nl80211: Associated with " | |
4035 | MACSTR, MAC2STR(_arg->assoc_bssid)); | |
4036 | } | |
f5a8d422 JM |
4037 | } |
4038 | if (!res) | |
4039 | return NL_SKIP; | |
b3db1e1c JM |
4040 | if (bss[NL80211_BSS_INFORMATION_ELEMENTS]) { |
4041 | ie = nla_data(bss[NL80211_BSS_INFORMATION_ELEMENTS]); | |
4042 | ie_len = nla_len(bss[NL80211_BSS_INFORMATION_ELEMENTS]); | |
4043 | } else { | |
4044 | ie = NULL; | |
4045 | ie_len = 0; | |
4046 | } | |
8c090654 JM |
4047 | if (bss[NL80211_BSS_BEACON_IES]) { |
4048 | beacon_ie = nla_data(bss[NL80211_BSS_BEACON_IES]); | |
4049 | beacon_ie_len = nla_len(bss[NL80211_BSS_BEACON_IES]); | |
4050 | } else { | |
4051 | beacon_ie = NULL; | |
4052 | beacon_ie_len = 0; | |
4053 | } | |
3f5285e8 | 4054 | |
3812464c JM |
4055 | if (nl80211_scan_filtered(_arg->drv, ie ? ie : beacon_ie, |
4056 | ie ? ie_len : beacon_ie_len)) | |
4057 | return NL_SKIP; | |
4058 | ||
8c090654 | 4059 | r = os_zalloc(sizeof(*r) + ie_len + beacon_ie_len); |
3f5285e8 | 4060 | if (r == NULL) |
b3db1e1c JM |
4061 | return NL_SKIP; |
4062 | if (bss[NL80211_BSS_BSSID]) | |
4063 | os_memcpy(r->bssid, nla_data(bss[NL80211_BSS_BSSID]), | |
4064 | ETH_ALEN); | |
4065 | if (bss[NL80211_BSS_FREQUENCY]) | |
4066 | r->freq = nla_get_u32(bss[NL80211_BSS_FREQUENCY]); | |
4067 | if (bss[NL80211_BSS_BEACON_INTERVAL]) | |
4068 | r->beacon_int = nla_get_u16(bss[NL80211_BSS_BEACON_INTERVAL]); | |
4069 | if (bss[NL80211_BSS_CAPABILITY]) | |
4070 | r->caps = nla_get_u16(bss[NL80211_BSS_CAPABILITY]); | |
7c2849d2 JM |
4071 | r->flags |= WPA_SCAN_NOISE_INVALID; |
4072 | if (bss[NL80211_BSS_SIGNAL_MBM]) { | |
b3db1e1c | 4073 | r->level = nla_get_u32(bss[NL80211_BSS_SIGNAL_MBM]); |
7c2849d2 JM |
4074 | r->level /= 100; /* mBm to dBm */ |
4075 | r->flags |= WPA_SCAN_LEVEL_DBM | WPA_SCAN_QUAL_INVALID; | |
4076 | } else if (bss[NL80211_BSS_SIGNAL_UNSPEC]) { | |
4077 | r->level = nla_get_u8(bss[NL80211_BSS_SIGNAL_UNSPEC]); | |
98ac6763 | 4078 | r->flags |= WPA_SCAN_QUAL_INVALID; |
7c2849d2 JM |
4079 | } else |
4080 | r->flags |= WPA_SCAN_LEVEL_INVALID | WPA_SCAN_QUAL_INVALID; | |
b3db1e1c JM |
4081 | if (bss[NL80211_BSS_TSF]) |
4082 | r->tsf = nla_get_u64(bss[NL80211_BSS_TSF]); | |
b3ad11bb JM |
4083 | if (bss[NL80211_BSS_SEEN_MS_AGO]) |
4084 | r->age = nla_get_u32(bss[NL80211_BSS_SEEN_MS_AGO]); | |
b3db1e1c | 4085 | r->ie_len = ie_len; |
8c090654 JM |
4086 | pos = (u8 *) (r + 1); |
4087 | if (ie) { | |
4088 | os_memcpy(pos, ie, ie_len); | |
4089 | pos += ie_len; | |
4090 | } | |
4091 | r->beacon_ie_len = beacon_ie_len; | |
4092 | if (beacon_ie) | |
4093 | os_memcpy(pos, beacon_ie, beacon_ie_len); | |
3f5285e8 | 4094 | |
e6b8efeb JM |
4095 | if (bss[NL80211_BSS_STATUS]) { |
4096 | enum nl80211_bss_status status; | |
4097 | status = nla_get_u32(bss[NL80211_BSS_STATUS]); | |
4098 | switch (status) { | |
4099 | case NL80211_BSS_STATUS_AUTHENTICATED: | |
4100 | r->flags |= WPA_SCAN_AUTHENTICATED; | |
4101 | break; | |
4102 | case NL80211_BSS_STATUS_ASSOCIATED: | |
4103 | r->flags |= WPA_SCAN_ASSOCIATED; | |
4104 | break; | |
4105 | default: | |
4106 | break; | |
4107 | } | |
4108 | } | |
4109 | ||
46957a9b JM |
4110 | /* |
4111 | * cfg80211 maintains separate BSS table entries for APs if the same | |
4112 | * BSSID,SSID pair is seen on multiple channels. wpa_supplicant does | |
4113 | * not use frequency as a separate key in the BSS table, so filter out | |
4114 | * duplicated entries. Prefer associated BSS entry in such a case in | |
4115 | * order to get the correct frequency into the BSS table. | |
4116 | */ | |
4117 | for (i = 0; i < res->num; i++) { | |
4118 | const u8 *s1, *s2; | |
4119 | if (os_memcmp(res->res[i]->bssid, r->bssid, ETH_ALEN) != 0) | |
4120 | continue; | |
4121 | ||
4122 | s1 = nl80211_get_ie((u8 *) (res->res[i] + 1), | |
4123 | res->res[i]->ie_len, WLAN_EID_SSID); | |
4124 | s2 = nl80211_get_ie((u8 *) (r + 1), r->ie_len, WLAN_EID_SSID); | |
4125 | if (s1 == NULL || s2 == NULL || s1[1] != s2[1] || | |
4126 | os_memcmp(s1, s2, 2 + s1[1]) != 0) | |
4127 | continue; | |
4128 | ||
4129 | /* Same BSSID,SSID was already included in scan results */ | |
4130 | wpa_printf(MSG_DEBUG, "nl80211: Remove duplicated scan result " | |
4131 | "for " MACSTR, MAC2STR(r->bssid)); | |
4132 | ||
4133 | if ((r->flags & WPA_SCAN_ASSOCIATED) && | |
4134 | !(res->res[i]->flags & WPA_SCAN_ASSOCIATED)) { | |
4135 | os_free(res->res[i]); | |
4136 | res->res[i] = r; | |
4137 | } else | |
4138 | os_free(r); | |
4139 | return NL_SKIP; | |
4140 | } | |
4141 | ||
067ffa26 JM |
4142 | tmp = os_realloc_array(res->res, res->num + 1, |
4143 | sizeof(struct wpa_scan_res *)); | |
3f5285e8 JM |
4144 | if (tmp == NULL) { |
4145 | os_free(r); | |
b3db1e1c | 4146 | return NL_SKIP; |
3f5285e8 JM |
4147 | } |
4148 | tmp[res->num++] = r; | |
4149 | res->res = tmp; | |
b3db1e1c JM |
4150 | |
4151 | return NL_SKIP; | |
3f5285e8 | 4152 | } |
b3db1e1c | 4153 | |
3f5285e8 | 4154 | |
d72aad94 JM |
4155 | static void clear_state_mismatch(struct wpa_driver_nl80211_data *drv, |
4156 | const u8 *addr) | |
4157 | { | |
4158 | if (drv->capa.flags & WPA_DRIVER_FLAGS_SME) { | |
4159 | wpa_printf(MSG_DEBUG, "nl80211: Clear possible state " | |
582507be | 4160 | "mismatch (" MACSTR ")", MAC2STR(addr)); |
d72aad94 JM |
4161 | wpa_driver_nl80211_mlme(drv, addr, |
4162 | NL80211_CMD_DEAUTHENTICATE, | |
77339912 | 4163 | WLAN_REASON_PREV_AUTH_NOT_VALID, 1); |
d72aad94 JM |
4164 | } |
4165 | } | |
4166 | ||
4167 | ||
e6b8efeb JM |
4168 | static void wpa_driver_nl80211_check_bss_status( |
4169 | struct wpa_driver_nl80211_data *drv, struct wpa_scan_results *res) | |
4170 | { | |
4171 | size_t i; | |
4172 | ||
4173 | for (i = 0; i < res->num; i++) { | |
4174 | struct wpa_scan_res *r = res->res[i]; | |
4175 | if (r->flags & WPA_SCAN_AUTHENTICATED) { | |
4176 | wpa_printf(MSG_DEBUG, "nl80211: Scan results " | |
4177 | "indicates BSS status with " MACSTR | |
4178 | " as authenticated", | |
4179 | MAC2STR(r->bssid)); | |
b1f625e0 | 4180 | if (is_sta_interface(drv->nlmode) && |
e6b8efeb JM |
4181 | os_memcmp(r->bssid, drv->bssid, ETH_ALEN) != 0 && |
4182 | os_memcmp(r->bssid, drv->auth_bssid, ETH_ALEN) != | |
4183 | 0) { | |
4184 | wpa_printf(MSG_DEBUG, "nl80211: Unknown BSSID" | |
4185 | " in local state (auth=" MACSTR | |
4186 | " assoc=" MACSTR ")", | |
4187 | MAC2STR(drv->auth_bssid), | |
4188 | MAC2STR(drv->bssid)); | |
582507be | 4189 | clear_state_mismatch(drv, r->bssid); |
e6b8efeb JM |
4190 | } |
4191 | } | |
4192 | ||
4193 | if (r->flags & WPA_SCAN_ASSOCIATED) { | |
4194 | wpa_printf(MSG_DEBUG, "nl80211: Scan results " | |
4195 | "indicate BSS status with " MACSTR | |
4196 | " as associated", | |
4197 | MAC2STR(r->bssid)); | |
b1f625e0 | 4198 | if (is_sta_interface(drv->nlmode) && |
e6b8efeb JM |
4199 | !drv->associated) { |
4200 | wpa_printf(MSG_DEBUG, "nl80211: Local state " | |
4201 | "(not associated) does not match " | |
4202 | "with BSS state"); | |
d72aad94 | 4203 | clear_state_mismatch(drv, r->bssid); |
b1f625e0 | 4204 | } else if (is_sta_interface(drv->nlmode) && |
e6b8efeb JM |
4205 | os_memcmp(drv->bssid, r->bssid, ETH_ALEN) != |
4206 | 0) { | |
4207 | wpa_printf(MSG_DEBUG, "nl80211: Local state " | |
4208 | "(associated with " MACSTR ") does " | |
4209 | "not match with BSS state", | |
d72aad94 JM |
4210 | MAC2STR(drv->bssid)); |
4211 | clear_state_mismatch(drv, r->bssid); | |
4212 | clear_state_mismatch(drv, drv->bssid); | |
e6b8efeb JM |
4213 | } |
4214 | } | |
4215 | } | |
4216 | } | |
4217 | ||
4218 | ||
7e5ba1b9 | 4219 | static struct wpa_scan_results * |
8856462d | 4220 | nl80211_get_scan_results(struct wpa_driver_nl80211_data *drv) |
3f5285e8 | 4221 | { |
b3db1e1c | 4222 | struct nl_msg *msg; |
3f5285e8 | 4223 | struct wpa_scan_results *res; |
b3db1e1c | 4224 | int ret; |
3812464c | 4225 | struct nl80211_bss_info_arg arg; |
3f5285e8 JM |
4226 | |
4227 | res = os_zalloc(sizeof(*res)); | |
b3db1e1c | 4228 | if (res == NULL) |
8e2c104f | 4229 | return NULL; |
b3db1e1c JM |
4230 | msg = nlmsg_alloc(); |
4231 | if (!msg) | |
4232 | goto nla_put_failure; | |
3f5285e8 | 4233 | |
9fb04070 | 4234 | nl80211_cmd(drv, msg, NLM_F_DUMP, NL80211_CMD_GET_SCAN); |
b3db1e1c | 4235 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, drv->ifindex); |
3f5285e8 | 4236 | |
3812464c JM |
4237 | arg.drv = drv; |
4238 | arg.res = res; | |
4239 | ret = send_and_recv_msgs(drv, msg, bss_info_handler, &arg); | |
b3db1e1c JM |
4240 | msg = NULL; |
4241 | if (ret == 0) { | |
577db0ae GM |
4242 | wpa_printf(MSG_DEBUG, "nl80211: Received scan results (%lu " |
4243 | "BSSes)", (unsigned long) res->num); | |
4244 | nl80211_get_noise_for_scan_results(drv, res); | |
b3db1e1c | 4245 | return res; |
3f5285e8 | 4246 | } |
b3db1e1c JM |
4247 | wpa_printf(MSG_DEBUG, "nl80211: Scan result fetch failed: ret=%d " |
4248 | "(%s)", ret, strerror(-ret)); | |
4249 | nla_put_failure: | |
4250 | nlmsg_free(msg); | |
4251 | wpa_scan_results_free(res); | |
4252 | return NULL; | |
3f5285e8 JM |
4253 | } |
4254 | ||
4255 | ||
8856462d JM |
4256 | /** |
4257 | * wpa_driver_nl80211_get_scan_results - Fetch the latest scan results | |
4258 | * @priv: Pointer to private wext data from wpa_driver_nl80211_init() | |
4259 | * Returns: Scan results on success, -1 on failure | |
4260 | */ | |
4261 | static struct wpa_scan_results * | |
4262 | wpa_driver_nl80211_get_scan_results(void *priv) | |
4263 | { | |
a2e40bb6 FF |
4264 | struct i802_bss *bss = priv; |
4265 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
8856462d JM |
4266 | struct wpa_scan_results *res; |
4267 | ||
4268 | res = nl80211_get_scan_results(drv); | |
4269 | if (res) | |
4270 | wpa_driver_nl80211_check_bss_status(drv, res); | |
4271 | return res; | |
4272 | } | |
4273 | ||
4274 | ||
4275 | static void nl80211_dump_scan(struct wpa_driver_nl80211_data *drv) | |
4276 | { | |
4277 | struct wpa_scan_results *res; | |
4278 | size_t i; | |
4279 | ||
4280 | res = nl80211_get_scan_results(drv); | |
4281 | if (res == NULL) { | |
4282 | wpa_printf(MSG_DEBUG, "nl80211: Failed to get scan results"); | |
4283 | return; | |
4284 | } | |
4285 | ||
4286 | wpa_printf(MSG_DEBUG, "nl80211: Scan result dump"); | |
4287 | for (i = 0; i < res->num; i++) { | |
4288 | struct wpa_scan_res *r = res->res[i]; | |
4289 | wpa_printf(MSG_DEBUG, "nl80211: %d/%d " MACSTR "%s%s", | |
4290 | (int) i, (int) res->num, MAC2STR(r->bssid), | |
4291 | r->flags & WPA_SCAN_AUTHENTICATED ? " [auth]" : "", | |
4292 | r->flags & WPA_SCAN_ASSOCIATED ? " [assoc]" : ""); | |
4293 | } | |
4294 | ||
4295 | wpa_scan_results_free(res); | |
4296 | } | |
4297 | ||
4298 | ||
9ebce9c5 | 4299 | static int wpa_driver_nl80211_set_key(const char *ifname, struct i802_bss *bss, |
71934751 JM |
4300 | enum wpa_alg alg, const u8 *addr, |
4301 | int key_idx, int set_tx, | |
642187d6 JM |
4302 | const u8 *seq, size_t seq_len, |
4303 | const u8 *key, size_t key_len) | |
3f5285e8 | 4304 | { |
a2e40bb6 | 4305 | struct wpa_driver_nl80211_data *drv = bss->drv; |
642187d6 | 4306 | int ifindex = if_nametoindex(ifname); |
3f5285e8 | 4307 | struct nl_msg *msg; |
1ad1cdc2 | 4308 | int ret; |
3f5285e8 | 4309 | |
1ad1cdc2 JM |
4310 | wpa_printf(MSG_DEBUG, "%s: ifindex=%d alg=%d addr=%p key_idx=%d " |
4311 | "set_tx=%d seq_len=%lu key_len=%lu", | |
4312 | __func__, ifindex, alg, addr, key_idx, set_tx, | |
3f5285e8 | 4313 | (unsigned long) seq_len, (unsigned long) key_len); |
8c66e185 JM |
4314 | #ifdef CONFIG_TDLS |
4315 | if (key_idx == -1) | |
4316 | key_idx = 0; | |
4317 | #endif /* CONFIG_TDLS */ | |
3f5285e8 JM |
4318 | |
4319 | msg = nlmsg_alloc(); | |
1ad1cdc2 JM |
4320 | if (!msg) |
4321 | return -ENOMEM; | |
3f5285e8 JM |
4322 | |
4323 | if (alg == WPA_ALG_NONE) { | |
9fb04070 | 4324 | nl80211_cmd(drv, msg, 0, NL80211_CMD_DEL_KEY); |
3f5285e8 | 4325 | } else { |
9fb04070 | 4326 | nl80211_cmd(drv, msg, 0, NL80211_CMD_NEW_KEY); |
3f5285e8 | 4327 | NLA_PUT(msg, NL80211_ATTR_KEY_DATA, key_len, key); |
d723bab4 JM |
4328 | switch (alg) { |
4329 | case WPA_ALG_WEP: | |
4330 | if (key_len == 5) | |
4331 | NLA_PUT_U32(msg, NL80211_ATTR_KEY_CIPHER, | |
4332 | WLAN_CIPHER_SUITE_WEP40); | |
4333 | else | |
4334 | NLA_PUT_U32(msg, NL80211_ATTR_KEY_CIPHER, | |
4335 | WLAN_CIPHER_SUITE_WEP104); | |
4336 | break; | |
4337 | case WPA_ALG_TKIP: | |
4338 | NLA_PUT_U32(msg, NL80211_ATTR_KEY_CIPHER, | |
4339 | WLAN_CIPHER_SUITE_TKIP); | |
4340 | break; | |
4341 | case WPA_ALG_CCMP: | |
4342 | NLA_PUT_U32(msg, NL80211_ATTR_KEY_CIPHER, | |
4343 | WLAN_CIPHER_SUITE_CCMP); | |
4344 | break; | |
eb7719ff JM |
4345 | case WPA_ALG_GCMP: |
4346 | NLA_PUT_U32(msg, NL80211_ATTR_KEY_CIPHER, | |
4347 | WLAN_CIPHER_SUITE_GCMP); | |
4348 | break; | |
d723bab4 JM |
4349 | case WPA_ALG_IGTK: |
4350 | NLA_PUT_U32(msg, NL80211_ATTR_KEY_CIPHER, | |
4351 | WLAN_CIPHER_SUITE_AES_CMAC); | |
4352 | break; | |
369c8d7b JM |
4353 | case WPA_ALG_SMS4: |
4354 | NLA_PUT_U32(msg, NL80211_ATTR_KEY_CIPHER, | |
4355 | WLAN_CIPHER_SUITE_SMS4); | |
4356 | break; | |
4357 | case WPA_ALG_KRK: | |
4358 | NLA_PUT_U32(msg, NL80211_ATTR_KEY_CIPHER, | |
4359 | WLAN_CIPHER_SUITE_KRK); | |
4360 | break; | |
d723bab4 JM |
4361 | default: |
4362 | wpa_printf(MSG_ERROR, "%s: Unsupported encryption " | |
4363 | "algorithm %d", __func__, alg); | |
3f5285e8 JM |
4364 | nlmsg_free(msg); |
4365 | return -1; | |
4366 | } | |
4367 | } | |
4368 | ||
849ef835 | 4369 | if (seq && seq_len) |
1ad1cdc2 JM |
4370 | NLA_PUT(msg, NL80211_ATTR_KEY_SEQ, seq_len, seq); |
4371 | ||
0382097e | 4372 | if (addr && !is_broadcast_ether_addr(addr)) { |
3f5285e8 JM |
4373 | wpa_printf(MSG_DEBUG, " addr=" MACSTR, MAC2STR(addr)); |
4374 | NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, addr); | |
89c38e32 JM |
4375 | |
4376 | if (alg != WPA_ALG_WEP && key_idx && !set_tx) { | |
4377 | wpa_printf(MSG_DEBUG, " RSN IBSS RX GTK"); | |
4378 | NLA_PUT_U32(msg, NL80211_ATTR_KEY_TYPE, | |
4379 | NL80211_KEYTYPE_GROUP); | |
4380 | } | |
60ea8187 JM |
4381 | } else if (addr && is_broadcast_ether_addr(addr)) { |
4382 | struct nl_msg *types; | |
4383 | int err; | |
4384 | wpa_printf(MSG_DEBUG, " broadcast key"); | |
4385 | types = nlmsg_alloc(); | |
4386 | if (!types) | |
4387 | goto nla_put_failure; | |
4388 | NLA_PUT_FLAG(types, NL80211_KEY_DEFAULT_TYPE_MULTICAST); | |
4389 | err = nla_put_nested(msg, NL80211_ATTR_KEY_DEFAULT_TYPES, | |
4390 | types); | |
4391 | nlmsg_free(types); | |
4392 | if (err) | |
4393 | goto nla_put_failure; | |
3f5285e8 JM |
4394 | } |
4395 | NLA_PUT_U8(msg, NL80211_ATTR_KEY_IDX, key_idx); | |
1ad1cdc2 | 4396 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, ifindex); |
3f5285e8 | 4397 | |
1ad1cdc2 | 4398 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
15664ad0 | 4399 | if ((ret == -ENOENT || ret == -ENOLINK) && alg == WPA_ALG_NONE) |
1ad1cdc2 JM |
4400 | ret = 0; |
4401 | if (ret) | |
4402 | wpa_printf(MSG_DEBUG, "nl80211: set_key failed; err=%d %s)", | |
4403 | ret, strerror(-ret)); | |
3f5285e8 | 4404 | |
1ad1cdc2 JM |
4405 | /* |
4406 | * If we failed or don't need to set the default TX key (below), | |
4407 | * we're done here. | |
4408 | */ | |
4409 | if (ret || !set_tx || alg == WPA_ALG_NONE) | |
4410 | return ret; | |
b1f625e0 | 4411 | if (is_ap_interface(drv->nlmode) && addr && |
0382097e | 4412 | !is_broadcast_ether_addr(addr)) |
de12717a | 4413 | return ret; |
3f5285e8 | 4414 | |
1ad1cdc2 JM |
4415 | msg = nlmsg_alloc(); |
4416 | if (!msg) | |
4417 | return -ENOMEM; | |
3f5285e8 | 4418 | |
9fb04070 | 4419 | nl80211_cmd(drv, msg, 0, NL80211_CMD_SET_KEY); |
1ad1cdc2 JM |
4420 | NLA_PUT_U8(msg, NL80211_ATTR_KEY_IDX, key_idx); |
4421 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, ifindex); | |
4422 | if (alg == WPA_ALG_IGTK) | |
4423 | NLA_PUT_FLAG(msg, NL80211_ATTR_KEY_DEFAULT_MGMT); | |
4424 | else | |
4425 | NLA_PUT_FLAG(msg, NL80211_ATTR_KEY_DEFAULT); | |
60ea8187 JM |
4426 | if (addr && is_broadcast_ether_addr(addr)) { |
4427 | struct nl_msg *types; | |
4428 | int err; | |
4429 | types = nlmsg_alloc(); | |
4430 | if (!types) | |
4431 | goto nla_put_failure; | |
4432 | NLA_PUT_FLAG(types, NL80211_KEY_DEFAULT_TYPE_MULTICAST); | |
4433 | err = nla_put_nested(msg, NL80211_ATTR_KEY_DEFAULT_TYPES, | |
4434 | types); | |
4435 | nlmsg_free(types); | |
4436 | if (err) | |
4437 | goto nla_put_failure; | |
4438 | } else if (addr) { | |
4439 | struct nl_msg *types; | |
4440 | int err; | |
4441 | types = nlmsg_alloc(); | |
4442 | if (!types) | |
4443 | goto nla_put_failure; | |
4444 | NLA_PUT_FLAG(types, NL80211_KEY_DEFAULT_TYPE_UNICAST); | |
4445 | err = nla_put_nested(msg, NL80211_ATTR_KEY_DEFAULT_TYPES, | |
4446 | types); | |
4447 | nlmsg_free(types); | |
4448 | if (err) | |
4449 | goto nla_put_failure; | |
4450 | } | |
3f5285e8 | 4451 | |
1ad1cdc2 JM |
4452 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
4453 | if (ret == -ENOENT) | |
4454 | ret = 0; | |
4455 | if (ret) | |
4456 | wpa_printf(MSG_DEBUG, "nl80211: set_key default failed; " | |
4457 | "err=%d %s)", ret, strerror(-ret)); | |
4458 | return ret; | |
3f5285e8 JM |
4459 | |
4460 | nla_put_failure: | |
5883168a | 4461 | nlmsg_free(msg); |
6241fcb1 | 4462 | return -ENOBUFS; |
3f5285e8 JM |
4463 | } |
4464 | ||
4465 | ||
71934751 | 4466 | static int nl_add_key(struct nl_msg *msg, enum wpa_alg alg, |
0194fedb JB |
4467 | int key_idx, int defkey, |
4468 | const u8 *seq, size_t seq_len, | |
4469 | const u8 *key, size_t key_len) | |
4470 | { | |
4471 | struct nlattr *key_attr = nla_nest_start(msg, NL80211_ATTR_KEY); | |
4472 | if (!key_attr) | |
4473 | return -1; | |
4474 | ||
4475 | if (defkey && alg == WPA_ALG_IGTK) | |
4476 | NLA_PUT_FLAG(msg, NL80211_KEY_DEFAULT_MGMT); | |
4477 | else if (defkey) | |
4478 | NLA_PUT_FLAG(msg, NL80211_KEY_DEFAULT); | |
4479 | ||
4480 | NLA_PUT_U8(msg, NL80211_KEY_IDX, key_idx); | |
4481 | ||
d723bab4 JM |
4482 | switch (alg) { |
4483 | case WPA_ALG_WEP: | |
4484 | if (key_len == 5) | |
2aa5f847 JM |
4485 | NLA_PUT_U32(msg, NL80211_KEY_CIPHER, |
4486 | WLAN_CIPHER_SUITE_WEP40); | |
d723bab4 | 4487 | else |
2aa5f847 JM |
4488 | NLA_PUT_U32(msg, NL80211_KEY_CIPHER, |
4489 | WLAN_CIPHER_SUITE_WEP104); | |
d723bab4 JM |
4490 | break; |
4491 | case WPA_ALG_TKIP: | |
2aa5f847 | 4492 | NLA_PUT_U32(msg, NL80211_KEY_CIPHER, WLAN_CIPHER_SUITE_TKIP); |
d723bab4 JM |
4493 | break; |
4494 | case WPA_ALG_CCMP: | |
2aa5f847 | 4495 | NLA_PUT_U32(msg, NL80211_KEY_CIPHER, WLAN_CIPHER_SUITE_CCMP); |
d723bab4 | 4496 | break; |
eb7719ff JM |
4497 | case WPA_ALG_GCMP: |
4498 | NLA_PUT_U32(msg, NL80211_KEY_CIPHER, WLAN_CIPHER_SUITE_GCMP); | |
4499 | break; | |
d723bab4 | 4500 | case WPA_ALG_IGTK: |
2aa5f847 JM |
4501 | NLA_PUT_U32(msg, NL80211_KEY_CIPHER, |
4502 | WLAN_CIPHER_SUITE_AES_CMAC); | |
d723bab4 JM |
4503 | break; |
4504 | default: | |
4505 | wpa_printf(MSG_ERROR, "%s: Unsupported encryption " | |
4506 | "algorithm %d", __func__, alg); | |
0194fedb | 4507 | return -1; |
d723bab4 | 4508 | } |
0194fedb JB |
4509 | |
4510 | if (seq && seq_len) | |
4511 | NLA_PUT(msg, NL80211_KEY_SEQ, seq_len, seq); | |
4512 | ||
4513 | NLA_PUT(msg, NL80211_KEY_DATA, key_len, key); | |
4514 | ||
4515 | nla_nest_end(msg, key_attr); | |
4516 | ||
4517 | return 0; | |
4518 | nla_put_failure: | |
4519 | return -1; | |
4520 | } | |
4521 | ||
c811d5bc | 4522 | |
cfaab580 ZY |
4523 | static int nl80211_set_conn_keys(struct wpa_driver_associate_params *params, |
4524 | struct nl_msg *msg) | |
4525 | { | |
4526 | int i, privacy = 0; | |
4527 | struct nlattr *nl_keys, *nl_key; | |
4528 | ||
4529 | for (i = 0; i < 4; i++) { | |
4530 | if (!params->wep_key[i]) | |
4531 | continue; | |
4532 | privacy = 1; | |
4533 | break; | |
4534 | } | |
ce04af5a JM |
4535 | if (params->wps == WPS_MODE_PRIVACY) |
4536 | privacy = 1; | |
4537 | if (params->pairwise_suite && | |
4538 | params->pairwise_suite != WPA_CIPHER_NONE) | |
4539 | privacy = 1; | |
4540 | ||
cfaab580 ZY |
4541 | if (!privacy) |
4542 | return 0; | |
4543 | ||
4544 | NLA_PUT_FLAG(msg, NL80211_ATTR_PRIVACY); | |
4545 | ||
4546 | nl_keys = nla_nest_start(msg, NL80211_ATTR_KEYS); | |
4547 | if (!nl_keys) | |
4548 | goto nla_put_failure; | |
4549 | ||
4550 | for (i = 0; i < 4; i++) { | |
4551 | if (!params->wep_key[i]) | |
4552 | continue; | |
4553 | ||
4554 | nl_key = nla_nest_start(msg, i); | |
4555 | if (!nl_key) | |
4556 | goto nla_put_failure; | |
4557 | ||
4558 | NLA_PUT(msg, NL80211_KEY_DATA, params->wep_key_len[i], | |
4559 | params->wep_key[i]); | |
4560 | if (params->wep_key_len[i] == 5) | |
4561 | NLA_PUT_U32(msg, NL80211_KEY_CIPHER, | |
4562 | WLAN_CIPHER_SUITE_WEP40); | |
4563 | else | |
4564 | NLA_PUT_U32(msg, NL80211_KEY_CIPHER, | |
4565 | WLAN_CIPHER_SUITE_WEP104); | |
4566 | ||
4567 | NLA_PUT_U8(msg, NL80211_KEY_IDX, i); | |
4568 | ||
4569 | if (i == params->wep_tx_keyidx) | |
4570 | NLA_PUT_FLAG(msg, NL80211_KEY_DEFAULT); | |
4571 | ||
4572 | nla_nest_end(msg, nl_key); | |
4573 | } | |
4574 | nla_nest_end(msg, nl_keys); | |
4575 | ||
4576 | return 0; | |
4577 | ||
4578 | nla_put_failure: | |
4579 | return -ENOBUFS; | |
4580 | } | |
4581 | ||
4582 | ||
c2a04078 | 4583 | static int wpa_driver_nl80211_mlme(struct wpa_driver_nl80211_data *drv, |
77339912 JM |
4584 | const u8 *addr, int cmd, u16 reason_code, |
4585 | int local_state_change) | |
c2a04078 JM |
4586 | { |
4587 | int ret = -1; | |
4588 | struct nl_msg *msg; | |
4589 | ||
4590 | msg = nlmsg_alloc(); | |
4591 | if (!msg) | |
4592 | return -1; | |
4593 | ||
9fb04070 | 4594 | nl80211_cmd(drv, msg, 0, cmd); |
c2a04078 JM |
4595 | |
4596 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, drv->ifindex); | |
4597 | NLA_PUT_U16(msg, NL80211_ATTR_REASON_CODE, reason_code); | |
817762d9 MI |
4598 | if (addr) |
4599 | NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, addr); | |
77339912 JM |
4600 | if (local_state_change) |
4601 | NLA_PUT_FLAG(msg, NL80211_ATTR_LOCAL_STATE_CHANGE); | |
c2a04078 JM |
4602 | |
4603 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); | |
4604 | msg = NULL; | |
4605 | if (ret) { | |
3b7ea880 BG |
4606 | wpa_dbg(drv->ctx, MSG_DEBUG, |
4607 | "nl80211: MLME command failed: reason=%u ret=%d (%s)", | |
4608 | reason_code, ret, strerror(-ret)); | |
c2a04078 JM |
4609 | goto nla_put_failure; |
4610 | } | |
4611 | ret = 0; | |
4612 | ||
4613 | nla_put_failure: | |
4614 | nlmsg_free(msg); | |
4615 | return ret; | |
4616 | } | |
3f5285e8 JM |
4617 | |
4618 | ||
cfaab580 | 4619 | static int wpa_driver_nl80211_disconnect(struct wpa_driver_nl80211_data *drv, |
817762d9 | 4620 | int reason_code) |
cfaab580 | 4621 | { |
817762d9 | 4622 | wpa_printf(MSG_DEBUG, "%s(reason_code=%d)", __func__, reason_code); |
cfaab580 | 4623 | drv->associated = 0; |
a8c5b43a | 4624 | drv->ignore_next_local_disconnect = 0; |
817762d9 MI |
4625 | /* Disconnect command doesn't need BSSID - it uses cached value */ |
4626 | return wpa_driver_nl80211_mlme(drv, NULL, NL80211_CMD_DISCONNECT, | |
77339912 | 4627 | reason_code, 0); |
cfaab580 ZY |
4628 | } |
4629 | ||
4630 | ||
9ebce9c5 JM |
4631 | static int wpa_driver_nl80211_deauthenticate(struct i802_bss *bss, |
4632 | const u8 *addr, int reason_code) | |
3f5285e8 | 4633 | { |
a2e40bb6 | 4634 | struct wpa_driver_nl80211_data *drv = bss->drv; |
cfaab580 | 4635 | if (!(drv->capa.flags & WPA_DRIVER_FLAGS_SME)) |
817762d9 | 4636 | return wpa_driver_nl80211_disconnect(drv, reason_code); |
2e75a2b3 JM |
4637 | wpa_printf(MSG_DEBUG, "%s(addr=" MACSTR " reason_code=%d)", |
4638 | __func__, MAC2STR(addr), reason_code); | |
13405f35 | 4639 | drv->associated = 0; |
21bdbe38 JM |
4640 | if (drv->nlmode == NL80211_IFTYPE_ADHOC) |
4641 | return nl80211_leave_ibss(drv); | |
c2a04078 | 4642 | return wpa_driver_nl80211_mlme(drv, addr, NL80211_CMD_DEAUTHENTICATE, |
77339912 | 4643 | reason_code, 0); |
3f5285e8 JM |
4644 | } |
4645 | ||
4646 | ||
536fd62d JM |
4647 | static void nl80211_copy_auth_params(struct wpa_driver_nl80211_data *drv, |
4648 | struct wpa_driver_auth_params *params) | |
4649 | { | |
4650 | int i; | |
4651 | ||
4652 | drv->auth_freq = params->freq; | |
4653 | drv->auth_alg = params->auth_alg; | |
4654 | drv->auth_wep_tx_keyidx = params->wep_tx_keyidx; | |
4655 | drv->auth_local_state_change = params->local_state_change; | |
4656 | drv->auth_p2p = params->p2p; | |
4657 | ||
4658 | if (params->bssid) | |
4659 | os_memcpy(drv->auth_bssid_, params->bssid, ETH_ALEN); | |
4660 | else | |
4661 | os_memset(drv->auth_bssid_, 0, ETH_ALEN); | |
4662 | ||
4663 | if (params->ssid) { | |
4664 | os_memcpy(drv->auth_ssid, params->ssid, params->ssid_len); | |
4665 | drv->auth_ssid_len = params->ssid_len; | |
4666 | } else | |
4667 | drv->auth_ssid_len = 0; | |
4668 | ||
4669 | ||
4670 | os_free(drv->auth_ie); | |
4671 | drv->auth_ie = NULL; | |
4672 | drv->auth_ie_len = 0; | |
4673 | if (params->ie) { | |
4674 | drv->auth_ie = os_malloc(params->ie_len); | |
4675 | if (drv->auth_ie) { | |
4676 | os_memcpy(drv->auth_ie, params->ie, params->ie_len); | |
4677 | drv->auth_ie_len = params->ie_len; | |
4678 | } | |
4679 | } | |
4680 | ||
4681 | for (i = 0; i < 4; i++) { | |
4682 | if (params->wep_key[i] && params->wep_key_len[i] && | |
4683 | params->wep_key_len[i] <= 16) { | |
4684 | os_memcpy(drv->auth_wep_key[i], params->wep_key[i], | |
4685 | params->wep_key_len[i]); | |
4686 | drv->auth_wep_key_len[i] = params->wep_key_len[i]; | |
4687 | } else | |
4688 | drv->auth_wep_key_len[i] = 0; | |
4689 | } | |
4690 | } | |
4691 | ||
4692 | ||
c2a04078 | 4693 | static int wpa_driver_nl80211_authenticate( |
9ebce9c5 | 4694 | struct i802_bss *bss, struct wpa_driver_auth_params *params) |
c2a04078 | 4695 | { |
a2e40bb6 | 4696 | struct wpa_driver_nl80211_data *drv = bss->drv; |
a0b2f99b | 4697 | int ret = -1, i; |
c2a04078 JM |
4698 | struct nl_msg *msg; |
4699 | enum nl80211_auth_type type; | |
2f4f73b1 | 4700 | enum nl80211_iftype nlmode; |
6d6f4bb8 | 4701 | int count = 0; |
536fd62d JM |
4702 | int is_retry; |
4703 | ||
4704 | is_retry = drv->retry_auth; | |
4705 | drv->retry_auth = 0; | |
c2a04078 JM |
4706 | |
4707 | drv->associated = 0; | |
e6b8efeb | 4708 | os_memset(drv->auth_bssid, 0, ETH_ALEN); |
af473088 | 4709 | /* FIX: IBSS mode */ |
2f4f73b1 EP |
4710 | nlmode = params->p2p ? |
4711 | NL80211_IFTYPE_P2P_CLIENT : NL80211_IFTYPE_STATION; | |
4712 | if (drv->nlmode != nlmode && | |
9ebce9c5 | 4713 | wpa_driver_nl80211_set_mode(bss, nlmode) < 0) |
4a867032 JM |
4714 | return -1; |
4715 | ||
6d6f4bb8 | 4716 | retry: |
c2a04078 JM |
4717 | msg = nlmsg_alloc(); |
4718 | if (!msg) | |
4719 | return -1; | |
4720 | ||
4721 | wpa_printf(MSG_DEBUG, "nl80211: Authenticate (ifindex=%d)", | |
4722 | drv->ifindex); | |
a0b2f99b | 4723 | |
9fb04070 | 4724 | nl80211_cmd(drv, msg, 0, NL80211_CMD_AUTHENTICATE); |
0194fedb | 4725 | |
a0b2f99b JM |
4726 | for (i = 0; i < 4; i++) { |
4727 | if (!params->wep_key[i]) | |
4728 | continue; | |
9ebce9c5 | 4729 | wpa_driver_nl80211_set_key(bss->ifname, bss, WPA_ALG_WEP, |
2ea2fcc7 | 4730 | NULL, i, |
a0b2f99b JM |
4731 | i == params->wep_tx_keyidx, NULL, 0, |
4732 | params->wep_key[i], | |
4733 | params->wep_key_len[i]); | |
0194fedb JB |
4734 | if (params->wep_tx_keyidx != i) |
4735 | continue; | |
4736 | if (nl_add_key(msg, WPA_ALG_WEP, i, 1, NULL, 0, | |
4737 | params->wep_key[i], params->wep_key_len[i])) { | |
4738 | nlmsg_free(msg); | |
4739 | return -1; | |
4740 | } | |
a0b2f99b JM |
4741 | } |
4742 | ||
c2a04078 JM |
4743 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, drv->ifindex); |
4744 | if (params->bssid) { | |
4745 | wpa_printf(MSG_DEBUG, " * bssid=" MACSTR, | |
4746 | MAC2STR(params->bssid)); | |
4747 | NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, params->bssid); | |
4748 | } | |
4749 | if (params->freq) { | |
4750 | wpa_printf(MSG_DEBUG, " * freq=%d", params->freq); | |
4751 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_FREQ, params->freq); | |
4752 | } | |
4753 | if (params->ssid) { | |
4754 | wpa_hexdump_ascii(MSG_DEBUG, " * SSID", | |
4755 | params->ssid, params->ssid_len); | |
4756 | NLA_PUT(msg, NL80211_ATTR_SSID, params->ssid_len, | |
4757 | params->ssid); | |
4758 | } | |
4759 | wpa_hexdump(MSG_DEBUG, " * IEs", params->ie, params->ie_len); | |
4760 | if (params->ie) | |
4761 | NLA_PUT(msg, NL80211_ATTR_IE, params->ie_len, params->ie); | |
569fed90 JM |
4762 | if (params->sae_data) { |
4763 | wpa_hexdump(MSG_DEBUG, " * SAE data", params->sae_data, | |
4764 | params->sae_data_len); | |
4765 | NLA_PUT(msg, NL80211_ATTR_SAE_DATA, params->sae_data_len, | |
4766 | params->sae_data); | |
4767 | } | |
abd9fafa | 4768 | if (params->auth_alg & WPA_AUTH_ALG_OPEN) |
c2a04078 | 4769 | type = NL80211_AUTHTYPE_OPEN_SYSTEM; |
abd9fafa | 4770 | else if (params->auth_alg & WPA_AUTH_ALG_SHARED) |
c2a04078 | 4771 | type = NL80211_AUTHTYPE_SHARED_KEY; |
abd9fafa | 4772 | else if (params->auth_alg & WPA_AUTH_ALG_LEAP) |
c2a04078 | 4773 | type = NL80211_AUTHTYPE_NETWORK_EAP; |
abd9fafa | 4774 | else if (params->auth_alg & WPA_AUTH_ALG_FT) |
c2a04078 | 4775 | type = NL80211_AUTHTYPE_FT; |
569fed90 JM |
4776 | else if (params->auth_alg & WPA_AUTH_ALG_SAE) |
4777 | type = NL80211_AUTHTYPE_SAE; | |
c2a04078 JM |
4778 | else |
4779 | goto nla_put_failure; | |
4780 | wpa_printf(MSG_DEBUG, " * Auth Type %d", type); | |
4781 | NLA_PUT_U32(msg, NL80211_ATTR_AUTH_TYPE, type); | |
77339912 JM |
4782 | if (params->local_state_change) { |
4783 | wpa_printf(MSG_DEBUG, " * Local state change only"); | |
4784 | NLA_PUT_FLAG(msg, NL80211_ATTR_LOCAL_STATE_CHANGE); | |
4785 | } | |
c2a04078 JM |
4786 | |
4787 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); | |
4788 | msg = NULL; | |
4789 | if (ret) { | |
3b7ea880 BG |
4790 | wpa_dbg(drv->ctx, MSG_DEBUG, |
4791 | "nl80211: MLME command failed (auth): ret=%d (%s)", | |
4792 | ret, strerror(-ret)); | |
6d6f4bb8 | 4793 | count++; |
77339912 JM |
4794 | if (ret == -EALREADY && count == 1 && params->bssid && |
4795 | !params->local_state_change) { | |
6d6f4bb8 JM |
4796 | /* |
4797 | * mac80211 does not currently accept new | |
4798 | * authentication if we are already authenticated. As a | |
4799 | * workaround, force deauthentication and try again. | |
4800 | */ | |
4801 | wpa_printf(MSG_DEBUG, "nl80211: Retry authentication " | |
4802 | "after forced deauthentication"); | |
4803 | wpa_driver_nl80211_deauthenticate( | |
5205c4f9 | 4804 | bss, params->bssid, |
6d6f4bb8 JM |
4805 | WLAN_REASON_PREV_AUTH_NOT_VALID); |
4806 | nlmsg_free(msg); | |
4807 | goto retry; | |
4808 | } | |
536fd62d JM |
4809 | |
4810 | if (ret == -ENOENT && params->freq && !is_retry) { | |
4811 | /* | |
4812 | * cfg80211 has likely expired the BSS entry even | |
4813 | * though it was previously available in our internal | |
4814 | * BSS table. To recover quickly, start a single | |
4815 | * channel scan on the specified channel. | |
4816 | */ | |
4817 | struct wpa_driver_scan_params scan; | |
4818 | int freqs[2]; | |
4819 | ||
4820 | os_memset(&scan, 0, sizeof(scan)); | |
4821 | scan.num_ssids = 1; | |
4822 | if (params->ssid) { | |
4823 | scan.ssids[0].ssid = params->ssid; | |
4824 | scan.ssids[0].ssid_len = params->ssid_len; | |
4825 | } | |
4826 | freqs[0] = params->freq; | |
4827 | freqs[1] = 0; | |
4828 | scan.freqs = freqs; | |
4829 | wpa_printf(MSG_DEBUG, "nl80211: Trigger single " | |
4830 | "channel scan to refresh cfg80211 BSS " | |
4831 | "entry"); | |
4832 | ret = wpa_driver_nl80211_scan(bss, &scan); | |
4833 | if (ret == 0) { | |
4834 | nl80211_copy_auth_params(drv, params); | |
4835 | drv->scan_for_auth = 1; | |
4836 | } | |
8c3ba078 JM |
4837 | } else if (is_retry) { |
4838 | /* | |
4839 | * Need to indicate this with an event since the return | |
4840 | * value from the retry is not delivered to core code. | |
4841 | */ | |
4842 | union wpa_event_data event; | |
4843 | wpa_printf(MSG_DEBUG, "nl80211: Authentication retry " | |
4844 | "failed"); | |
4845 | os_memset(&event, 0, sizeof(event)); | |
4846 | os_memcpy(event.timeout_event.addr, drv->auth_bssid_, | |
4847 | ETH_ALEN); | |
4848 | wpa_supplicant_event(drv->ctx, EVENT_AUTH_TIMED_OUT, | |
4849 | &event); | |
536fd62d JM |
4850 | } |
4851 | ||
c2a04078 JM |
4852 | goto nla_put_failure; |
4853 | } | |
4854 | ret = 0; | |
4855 | wpa_printf(MSG_DEBUG, "nl80211: Authentication request send " | |
4856 | "successfully"); | |
4857 | ||
4858 | nla_put_failure: | |
4859 | nlmsg_free(msg); | |
4860 | return ret; | |
4861 | } | |
4862 | ||
4863 | ||
536fd62d JM |
4864 | static int wpa_driver_nl80211_authenticate_retry( |
4865 | struct wpa_driver_nl80211_data *drv) | |
4866 | { | |
4867 | struct wpa_driver_auth_params params; | |
4868 | struct i802_bss *bss = &drv->first_bss; | |
4869 | int i; | |
4870 | ||
4871 | wpa_printf(MSG_DEBUG, "nl80211: Try to authenticate again"); | |
4872 | ||
4873 | os_memset(¶ms, 0, sizeof(params)); | |
4874 | params.freq = drv->auth_freq; | |
4875 | params.auth_alg = drv->auth_alg; | |
4876 | params.wep_tx_keyidx = drv->auth_wep_tx_keyidx; | |
4877 | params.local_state_change = drv->auth_local_state_change; | |
4878 | params.p2p = drv->auth_p2p; | |
4879 | ||
4880 | if (!is_zero_ether_addr(drv->auth_bssid_)) | |
4881 | params.bssid = drv->auth_bssid_; | |
4882 | ||
4883 | if (drv->auth_ssid_len) { | |
4884 | params.ssid = drv->auth_ssid; | |
4885 | params.ssid_len = drv->auth_ssid_len; | |
4886 | } | |
4887 | ||
4888 | params.ie = drv->auth_ie; | |
4889 | params.ie_len = drv->auth_ie_len; | |
4890 | ||
4891 | for (i = 0; i < 4; i++) { | |
4892 | if (drv->auth_wep_key_len[i]) { | |
4893 | params.wep_key[i] = drv->auth_wep_key[i]; | |
4894 | params.wep_key_len[i] = drv->auth_wep_key_len[i]; | |
4895 | } | |
4896 | } | |
4897 | ||
4898 | drv->retry_auth = 1; | |
4899 | return wpa_driver_nl80211_authenticate(bss, ¶ms); | |
4900 | } | |
4901 | ||
4902 | ||
282d5590 JM |
4903 | struct phy_info_arg { |
4904 | u16 *num_modes; | |
4905 | struct hostapd_hw_modes *modes; | |
4906 | }; | |
4907 | ||
4908 | static int phy_info_handler(struct nl_msg *msg, void *arg) | |
4909 | { | |
4910 | struct nlattr *tb_msg[NL80211_ATTR_MAX + 1]; | |
4911 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); | |
4912 | struct phy_info_arg *phy_info = arg; | |
4913 | ||
4914 | struct nlattr *tb_band[NL80211_BAND_ATTR_MAX + 1]; | |
4915 | ||
4916 | struct nlattr *tb_freq[NL80211_FREQUENCY_ATTR_MAX + 1]; | |
4917 | static struct nla_policy freq_policy[NL80211_FREQUENCY_ATTR_MAX + 1] = { | |
4918 | [NL80211_FREQUENCY_ATTR_FREQ] = { .type = NLA_U32 }, | |
4919 | [NL80211_FREQUENCY_ATTR_DISABLED] = { .type = NLA_FLAG }, | |
4920 | [NL80211_FREQUENCY_ATTR_PASSIVE_SCAN] = { .type = NLA_FLAG }, | |
4921 | [NL80211_FREQUENCY_ATTR_NO_IBSS] = { .type = NLA_FLAG }, | |
4922 | [NL80211_FREQUENCY_ATTR_RADAR] = { .type = NLA_FLAG }, | |
4923 | [NL80211_FREQUENCY_ATTR_MAX_TX_POWER] = { .type = NLA_U32 }, | |
4924 | }; | |
4925 | ||
4926 | struct nlattr *tb_rate[NL80211_BITRATE_ATTR_MAX + 1]; | |
4927 | static struct nla_policy rate_policy[NL80211_BITRATE_ATTR_MAX + 1] = { | |
4928 | [NL80211_BITRATE_ATTR_RATE] = { .type = NLA_U32 }, | |
4929 | [NL80211_BITRATE_ATTR_2GHZ_SHORTPREAMBLE] = { .type = NLA_FLAG }, | |
4930 | }; | |
4931 | ||
4932 | struct nlattr *nl_band; | |
4933 | struct nlattr *nl_freq; | |
4934 | struct nlattr *nl_rate; | |
4935 | int rem_band, rem_freq, rem_rate; | |
4936 | struct hostapd_hw_modes *mode; | |
4937 | int idx, mode_is_set; | |
4938 | ||
4939 | nla_parse(tb_msg, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), | |
4940 | genlmsg_attrlen(gnlh, 0), NULL); | |
4941 | ||
4942 | if (!tb_msg[NL80211_ATTR_WIPHY_BANDS]) | |
4943 | return NL_SKIP; | |
4944 | ||
4945 | nla_for_each_nested(nl_band, tb_msg[NL80211_ATTR_WIPHY_BANDS], rem_band) { | |
067ffa26 JM |
4946 | mode = os_realloc_array(phy_info->modes, |
4947 | *phy_info->num_modes + 1, | |
4948 | sizeof(*mode)); | |
282d5590 JM |
4949 | if (!mode) |
4950 | return NL_SKIP; | |
4951 | phy_info->modes = mode; | |
4952 | ||
4953 | mode_is_set = 0; | |
4954 | ||
4955 | mode = &phy_info->modes[*(phy_info->num_modes)]; | |
4956 | memset(mode, 0, sizeof(*mode)); | |
e3b473eb | 4957 | mode->flags = HOSTAPD_MODE_FLAG_HT_INFO_KNOWN; |
282d5590 JM |
4958 | *(phy_info->num_modes) += 1; |
4959 | ||
4960 | nla_parse(tb_band, NL80211_BAND_ATTR_MAX, nla_data(nl_band), | |
4961 | nla_len(nl_band), NULL); | |
4962 | ||
4963 | if (tb_band[NL80211_BAND_ATTR_HT_CAPA]) { | |
4964 | mode->ht_capab = nla_get_u16( | |
4965 | tb_band[NL80211_BAND_ATTR_HT_CAPA]); | |
4966 | } | |
4967 | ||
be8eb8ab JM |
4968 | if (tb_band[NL80211_BAND_ATTR_HT_AMPDU_FACTOR]) { |
4969 | mode->a_mpdu_params |= nla_get_u8( | |
4970 | tb_band[NL80211_BAND_ATTR_HT_AMPDU_FACTOR]) & | |
4971 | 0x03; | |
4972 | } | |
4973 | ||
4974 | if (tb_band[NL80211_BAND_ATTR_HT_AMPDU_DENSITY]) { | |
4975 | mode->a_mpdu_params |= nla_get_u8( | |
4976 | tb_band[NL80211_BAND_ATTR_HT_AMPDU_DENSITY]) << | |
4977 | 2; | |
4978 | } | |
4979 | ||
08eb154d JM |
4980 | if (tb_band[NL80211_BAND_ATTR_HT_MCS_SET] && |
4981 | nla_len(tb_band[NL80211_BAND_ATTR_HT_MCS_SET])) { | |
4982 | u8 *mcs; | |
4983 | mcs = nla_data(tb_band[NL80211_BAND_ATTR_HT_MCS_SET]); | |
4984 | os_memcpy(mode->mcs_set, mcs, 16); | |
4985 | } | |
4986 | ||
990933fb MP |
4987 | if (tb_band[NL80211_BAND_ATTR_VHT_CAPA]) { |
4988 | mode->vht_capab = nla_get_u32( | |
4989 | tb_band[NL80211_BAND_ATTR_VHT_CAPA]); | |
4990 | } | |
4991 | ||
4992 | if (tb_band[NL80211_BAND_ATTR_VHT_MCS_SET] && | |
4993 | nla_len(tb_band[NL80211_BAND_ATTR_VHT_MCS_SET])) { | |
4994 | u8 *mcs; | |
4995 | mcs = nla_data(tb_band[NL80211_BAND_ATTR_VHT_MCS_SET]); | |
4996 | os_memcpy(mode->vht_mcs_set, mcs, 8); | |
4997 | } | |
4998 | ||
282d5590 JM |
4999 | nla_for_each_nested(nl_freq, tb_band[NL80211_BAND_ATTR_FREQS], rem_freq) { |
5000 | nla_parse(tb_freq, NL80211_FREQUENCY_ATTR_MAX, nla_data(nl_freq), | |
5001 | nla_len(nl_freq), freq_policy); | |
5002 | if (!tb_freq[NL80211_FREQUENCY_ATTR_FREQ]) | |
5003 | continue; | |
5004 | mode->num_channels++; | |
5005 | } | |
5006 | ||
f9884c09 JM |
5007 | mode->channels = os_calloc(mode->num_channels, |
5008 | sizeof(struct hostapd_channel_data)); | |
282d5590 JM |
5009 | if (!mode->channels) |
5010 | return NL_SKIP; | |
5011 | ||
5012 | idx = 0; | |
5013 | ||
5014 | nla_for_each_nested(nl_freq, tb_band[NL80211_BAND_ATTR_FREQS], rem_freq) { | |
5015 | nla_parse(tb_freq, NL80211_FREQUENCY_ATTR_MAX, nla_data(nl_freq), | |
5016 | nla_len(nl_freq), freq_policy); | |
5017 | if (!tb_freq[NL80211_FREQUENCY_ATTR_FREQ]) | |
5018 | continue; | |
5019 | ||
5020 | mode->channels[idx].freq = nla_get_u32(tb_freq[NL80211_FREQUENCY_ATTR_FREQ]); | |
5021 | mode->channels[idx].flag = 0; | |
5022 | ||
5023 | if (!mode_is_set) { | |
5024 | /* crude heuristic */ | |
5025 | if (mode->channels[idx].freq < 4000) | |
5026 | mode->mode = HOSTAPD_MODE_IEEE80211B; | |
7829894c VK |
5027 | else if (mode->channels[idx].freq > 50000) |
5028 | mode->mode = HOSTAPD_MODE_IEEE80211AD; | |
282d5590 JM |
5029 | else |
5030 | mode->mode = HOSTAPD_MODE_IEEE80211A; | |
5031 | mode_is_set = 1; | |
5032 | } | |
5033 | ||
7829894c VK |
5034 | switch (mode->mode) { |
5035 | case HOSTAPD_MODE_IEEE80211AD: | |
5036 | mode->channels[idx].chan = | |
5037 | (mode->channels[idx].freq - 56160) / | |
5038 | 2160; | |
5039 | break; | |
5040 | case HOSTAPD_MODE_IEEE80211A: | |
5041 | mode->channels[idx].chan = | |
5042 | mode->channels[idx].freq / 5 - 1000; | |
5043 | break; | |
5044 | case HOSTAPD_MODE_IEEE80211B: | |
5045 | case HOSTAPD_MODE_IEEE80211G: | |
5a0ffb5f | 5046 | if (mode->channels[idx].freq == 2484) |
282d5590 JM |
5047 | mode->channels[idx].chan = 14; |
5048 | else | |
7829894c VK |
5049 | mode->channels[idx].chan = |
5050 | (mode->channels[idx].freq - | |
5051 | 2407) / 5; | |
5052 | break; | |
5053 | default: | |
5054 | break; | |
5055 | } | |
282d5590 JM |
5056 | |
5057 | if (tb_freq[NL80211_FREQUENCY_ATTR_DISABLED]) | |
5058 | mode->channels[idx].flag |= | |
5059 | HOSTAPD_CHAN_DISABLED; | |
5060 | if (tb_freq[NL80211_FREQUENCY_ATTR_PASSIVE_SCAN]) | |
5061 | mode->channels[idx].flag |= | |
5062 | HOSTAPD_CHAN_PASSIVE_SCAN; | |
5063 | if (tb_freq[NL80211_FREQUENCY_ATTR_NO_IBSS]) | |
5064 | mode->channels[idx].flag |= | |
5065 | HOSTAPD_CHAN_NO_IBSS; | |
5066 | if (tb_freq[NL80211_FREQUENCY_ATTR_RADAR]) | |
5067 | mode->channels[idx].flag |= | |
5068 | HOSTAPD_CHAN_RADAR; | |
5069 | ||
5070 | if (tb_freq[NL80211_FREQUENCY_ATTR_MAX_TX_POWER] && | |
5071 | !tb_freq[NL80211_FREQUENCY_ATTR_DISABLED]) | |
5072 | mode->channels[idx].max_tx_power = | |
5073 | nla_get_u32(tb_freq[NL80211_FREQUENCY_ATTR_MAX_TX_POWER]) / 100; | |
5074 | ||
5075 | idx++; | |
5076 | } | |
5077 | ||
5078 | nla_for_each_nested(nl_rate, tb_band[NL80211_BAND_ATTR_RATES], rem_rate) { | |
5079 | nla_parse(tb_rate, NL80211_BITRATE_ATTR_MAX, nla_data(nl_rate), | |
5080 | nla_len(nl_rate), rate_policy); | |
5081 | if (!tb_rate[NL80211_BITRATE_ATTR_RATE]) | |
5082 | continue; | |
5083 | mode->num_rates++; | |
5084 | } | |
5085 | ||
f9884c09 | 5086 | mode->rates = os_calloc(mode->num_rates, sizeof(int)); |
282d5590 JM |
5087 | if (!mode->rates) |
5088 | return NL_SKIP; | |
5089 | ||
5090 | idx = 0; | |
5091 | ||
5092 | nla_for_each_nested(nl_rate, tb_band[NL80211_BAND_ATTR_RATES], rem_rate) { | |
5093 | nla_parse(tb_rate, NL80211_BITRATE_ATTR_MAX, nla_data(nl_rate), | |
5094 | nla_len(nl_rate), rate_policy); | |
5095 | if (!tb_rate[NL80211_BITRATE_ATTR_RATE]) | |
5096 | continue; | |
fb7842aa | 5097 | mode->rates[idx] = nla_get_u32(tb_rate[NL80211_BITRATE_ATTR_RATE]); |
282d5590 JM |
5098 | |
5099 | /* crude heuristic */ | |
5100 | if (mode->mode == HOSTAPD_MODE_IEEE80211B && | |
fb7842aa | 5101 | mode->rates[idx] > 200) |
282d5590 JM |
5102 | mode->mode = HOSTAPD_MODE_IEEE80211G; |
5103 | ||
282d5590 JM |
5104 | idx++; |
5105 | } | |
5106 | } | |
5107 | ||
5108 | return NL_SKIP; | |
5109 | } | |
5110 | ||
5111 | static struct hostapd_hw_modes * | |
5112 | wpa_driver_nl80211_add_11b(struct hostapd_hw_modes *modes, u16 *num_modes) | |
5113 | { | |
5114 | u16 m; | |
5115 | struct hostapd_hw_modes *mode11g = NULL, *nmodes, *mode; | |
5116 | int i, mode11g_idx = -1; | |
5117 | ||
5118 | /* If only 802.11g mode is included, use it to construct matching | |
5119 | * 802.11b mode data. */ | |
5120 | ||
5121 | for (m = 0; m < *num_modes; m++) { | |
5122 | if (modes[m].mode == HOSTAPD_MODE_IEEE80211B) | |
5123 | return modes; /* 802.11b already included */ | |
5124 | if (modes[m].mode == HOSTAPD_MODE_IEEE80211G) | |
5125 | mode11g_idx = m; | |
5126 | } | |
5127 | ||
5128 | if (mode11g_idx < 0) | |
5129 | return modes; /* 2.4 GHz band not supported at all */ | |
5130 | ||
067ffa26 | 5131 | nmodes = os_realloc_array(modes, *num_modes + 1, sizeof(*nmodes)); |
282d5590 JM |
5132 | if (nmodes == NULL) |
5133 | return modes; /* Could not add 802.11b mode */ | |
5134 | ||
5135 | mode = &nmodes[*num_modes]; | |
5136 | os_memset(mode, 0, sizeof(*mode)); | |
5137 | (*num_modes)++; | |
5138 | modes = nmodes; | |
5139 | ||
5140 | mode->mode = HOSTAPD_MODE_IEEE80211B; | |
5141 | ||
5142 | mode11g = &modes[mode11g_idx]; | |
5143 | mode->num_channels = mode11g->num_channels; | |
5144 | mode->channels = os_malloc(mode11g->num_channels * | |
5145 | sizeof(struct hostapd_channel_data)); | |
5146 | if (mode->channels == NULL) { | |
5147 | (*num_modes)--; | |
5148 | return modes; /* Could not add 802.11b mode */ | |
5149 | } | |
5150 | os_memcpy(mode->channels, mode11g->channels, | |
5151 | mode11g->num_channels * sizeof(struct hostapd_channel_data)); | |
5152 | ||
5153 | mode->num_rates = 0; | |
fb7842aa | 5154 | mode->rates = os_malloc(4 * sizeof(int)); |
282d5590 JM |
5155 | if (mode->rates == NULL) { |
5156 | os_free(mode->channels); | |
5157 | (*num_modes)--; | |
5158 | return modes; /* Could not add 802.11b mode */ | |
5159 | } | |
5160 | ||
5161 | for (i = 0; i < mode11g->num_rates; i++) { | |
fb7842aa JM |
5162 | if (mode11g->rates[i] != 10 && mode11g->rates[i] != 20 && |
5163 | mode11g->rates[i] != 55 && mode11g->rates[i] != 110) | |
282d5590 JM |
5164 | continue; |
5165 | mode->rates[mode->num_rates] = mode11g->rates[i]; | |
5166 | mode->num_rates++; | |
5167 | if (mode->num_rates == 4) | |
5168 | break; | |
5169 | } | |
5170 | ||
5171 | if (mode->num_rates == 0) { | |
5172 | os_free(mode->channels); | |
5173 | os_free(mode->rates); | |
5174 | (*num_modes)--; | |
5175 | return modes; /* No 802.11b rates */ | |
5176 | } | |
5177 | ||
5178 | wpa_printf(MSG_DEBUG, "nl80211: Added 802.11b mode based on 802.11g " | |
5179 | "information"); | |
5180 | ||
5181 | return modes; | |
5182 | } | |
5183 | ||
5184 | ||
d8e66e80 JM |
5185 | static void nl80211_set_ht40_mode(struct hostapd_hw_modes *mode, int start, |
5186 | int end) | |
5187 | { | |
5188 | int c; | |
5189 | ||
5190 | for (c = 0; c < mode->num_channels; c++) { | |
5191 | struct hostapd_channel_data *chan = &mode->channels[c]; | |
5192 | if (chan->freq - 10 >= start && chan->freq + 10 <= end) | |
5193 | chan->flag |= HOSTAPD_CHAN_HT40; | |
5194 | } | |
5195 | } | |
5196 | ||
5197 | ||
5198 | static void nl80211_set_ht40_mode_sec(struct hostapd_hw_modes *mode, int start, | |
5199 | int end) | |
5200 | { | |
5201 | int c; | |
5202 | ||
5203 | for (c = 0; c < mode->num_channels; c++) { | |
5204 | struct hostapd_channel_data *chan = &mode->channels[c]; | |
5205 | if (!(chan->flag & HOSTAPD_CHAN_HT40)) | |
5206 | continue; | |
5207 | if (chan->freq - 30 >= start && chan->freq - 10 <= end) | |
5208 | chan->flag |= HOSTAPD_CHAN_HT40MINUS; | |
5209 | if (chan->freq + 10 >= start && chan->freq + 30 <= end) | |
5210 | chan->flag |= HOSTAPD_CHAN_HT40PLUS; | |
5211 | } | |
5212 | } | |
5213 | ||
5214 | ||
5215 | static void nl80211_reg_rule_ht40(struct nlattr *tb[], | |
5216 | struct phy_info_arg *results) | |
5217 | { | |
5218 | u32 start, end, max_bw; | |
5219 | u16 m; | |
5220 | ||
5221 | if (tb[NL80211_ATTR_FREQ_RANGE_START] == NULL || | |
5222 | tb[NL80211_ATTR_FREQ_RANGE_END] == NULL || | |
5223 | tb[NL80211_ATTR_FREQ_RANGE_MAX_BW] == NULL) | |
5224 | return; | |
5225 | ||
5226 | start = nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_START]) / 1000; | |
5227 | end = nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_END]) / 1000; | |
5228 | max_bw = nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_MAX_BW]) / 1000; | |
5229 | ||
5230 | wpa_printf(MSG_DEBUG, "nl80211: %u-%u @ %u MHz", | |
5231 | start, end, max_bw); | |
5232 | if (max_bw < 40) | |
5233 | return; | |
5234 | ||
5235 | for (m = 0; m < *results->num_modes; m++) { | |
5236 | if (!(results->modes[m].ht_capab & | |
5237 | HT_CAP_INFO_SUPP_CHANNEL_WIDTH_SET)) | |
5238 | continue; | |
5239 | nl80211_set_ht40_mode(&results->modes[m], start, end); | |
5240 | } | |
5241 | } | |
5242 | ||
5243 | ||
5244 | static void nl80211_reg_rule_sec(struct nlattr *tb[], | |
5245 | struct phy_info_arg *results) | |
5246 | { | |
5247 | u32 start, end, max_bw; | |
5248 | u16 m; | |
5249 | ||
5250 | if (tb[NL80211_ATTR_FREQ_RANGE_START] == NULL || | |
5251 | tb[NL80211_ATTR_FREQ_RANGE_END] == NULL || | |
5252 | tb[NL80211_ATTR_FREQ_RANGE_MAX_BW] == NULL) | |
5253 | return; | |
5254 | ||
5255 | start = nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_START]) / 1000; | |
5256 | end = nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_END]) / 1000; | |
5257 | max_bw = nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_MAX_BW]) / 1000; | |
5258 | ||
5259 | if (max_bw < 20) | |
5260 | return; | |
5261 | ||
5262 | for (m = 0; m < *results->num_modes; m++) { | |
5263 | if (!(results->modes[m].ht_capab & | |
5264 | HT_CAP_INFO_SUPP_CHANNEL_WIDTH_SET)) | |
5265 | continue; | |
5266 | nl80211_set_ht40_mode_sec(&results->modes[m], start, end); | |
5267 | } | |
5268 | } | |
5269 | ||
5270 | ||
5271 | static int nl80211_get_reg(struct nl_msg *msg, void *arg) | |
5272 | { | |
5273 | struct phy_info_arg *results = arg; | |
5274 | struct nlattr *tb_msg[NL80211_ATTR_MAX + 1]; | |
5275 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); | |
5276 | struct nlattr *nl_rule; | |
5277 | struct nlattr *tb_rule[NL80211_FREQUENCY_ATTR_MAX + 1]; | |
5278 | int rem_rule; | |
5279 | static struct nla_policy reg_policy[NL80211_FREQUENCY_ATTR_MAX + 1] = { | |
5280 | [NL80211_ATTR_REG_RULE_FLAGS] = { .type = NLA_U32 }, | |
5281 | [NL80211_ATTR_FREQ_RANGE_START] = { .type = NLA_U32 }, | |
5282 | [NL80211_ATTR_FREQ_RANGE_END] = { .type = NLA_U32 }, | |
5283 | [NL80211_ATTR_FREQ_RANGE_MAX_BW] = { .type = NLA_U32 }, | |
5284 | [NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN] = { .type = NLA_U32 }, | |
5285 | [NL80211_ATTR_POWER_RULE_MAX_EIRP] = { .type = NLA_U32 }, | |
5286 | }; | |
5287 | ||
5288 | nla_parse(tb_msg, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), | |
5289 | genlmsg_attrlen(gnlh, 0), NULL); | |
5290 | if (!tb_msg[NL80211_ATTR_REG_ALPHA2] || | |
5291 | !tb_msg[NL80211_ATTR_REG_RULES]) { | |
5292 | wpa_printf(MSG_DEBUG, "nl80211: No regulatory information " | |
5293 | "available"); | |
5294 | return NL_SKIP; | |
5295 | } | |
5296 | ||
5297 | wpa_printf(MSG_DEBUG, "nl80211: Regulatory information - country=%s", | |
5298 | (char *) nla_data(tb_msg[NL80211_ATTR_REG_ALPHA2])); | |
5299 | ||
5300 | nla_for_each_nested(nl_rule, tb_msg[NL80211_ATTR_REG_RULES], rem_rule) | |
5301 | { | |
5302 | nla_parse(tb_rule, NL80211_FREQUENCY_ATTR_MAX, | |
5303 | nla_data(nl_rule), nla_len(nl_rule), reg_policy); | |
5304 | nl80211_reg_rule_ht40(tb_rule, results); | |
5305 | } | |
5306 | ||
5307 | nla_for_each_nested(nl_rule, tb_msg[NL80211_ATTR_REG_RULES], rem_rule) | |
5308 | { | |
5309 | nla_parse(tb_rule, NL80211_FREQUENCY_ATTR_MAX, | |
5310 | nla_data(nl_rule), nla_len(nl_rule), reg_policy); | |
5311 | nl80211_reg_rule_sec(tb_rule, results); | |
5312 | } | |
5313 | ||
5314 | return NL_SKIP; | |
5315 | } | |
5316 | ||
5317 | ||
5318 | static int nl80211_set_ht40_flags(struct wpa_driver_nl80211_data *drv, | |
5319 | struct phy_info_arg *results) | |
5320 | { | |
5321 | struct nl_msg *msg; | |
5322 | ||
5323 | msg = nlmsg_alloc(); | |
5324 | if (!msg) | |
5325 | return -ENOMEM; | |
5326 | ||
9fb04070 | 5327 | nl80211_cmd(drv, msg, 0, NL80211_CMD_GET_REG); |
d8e66e80 JM |
5328 | return send_and_recv_msgs(drv, msg, nl80211_get_reg, results); |
5329 | } | |
5330 | ||
5331 | ||
282d5590 JM |
5332 | static struct hostapd_hw_modes * |
5333 | wpa_driver_nl80211_get_hw_feature_data(void *priv, u16 *num_modes, u16 *flags) | |
5334 | { | |
a2e40bb6 FF |
5335 | struct i802_bss *bss = priv; |
5336 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
282d5590 JM |
5337 | struct nl_msg *msg; |
5338 | struct phy_info_arg result = { | |
5339 | .num_modes = num_modes, | |
5340 | .modes = NULL, | |
5341 | }; | |
5342 | ||
5343 | *num_modes = 0; | |
5344 | *flags = 0; | |
5345 | ||
5346 | msg = nlmsg_alloc(); | |
5347 | if (!msg) | |
5348 | return NULL; | |
5349 | ||
9fb04070 | 5350 | nl80211_cmd(drv, msg, 0, NL80211_CMD_GET_WIPHY); |
282d5590 JM |
5351 | |
5352 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, drv->ifindex); | |
5353 | ||
d8e66e80 JM |
5354 | if (send_and_recv_msgs(drv, msg, phy_info_handler, &result) == 0) { |
5355 | nl80211_set_ht40_flags(drv, &result); | |
282d5590 | 5356 | return wpa_driver_nl80211_add_11b(result.modes, num_modes); |
d8e66e80 | 5357 | } |
5883168a | 5358 | msg = NULL; |
282d5590 | 5359 | nla_put_failure: |
5883168a | 5360 | nlmsg_free(msg); |
282d5590 JM |
5361 | return NULL; |
5362 | } | |
5363 | ||
5364 | ||
a11241fa JB |
5365 | static int wpa_driver_nl80211_send_mntr(struct wpa_driver_nl80211_data *drv, |
5366 | const void *data, size_t len, | |
5367 | int encrypt, int noack) | |
2c2010ac JM |
5368 | { |
5369 | __u8 rtap_hdr[] = { | |
5370 | 0x00, 0x00, /* radiotap version */ | |
5371 | 0x0e, 0x00, /* radiotap length */ | |
5372 | 0x02, 0xc0, 0x00, 0x00, /* bmap: flags, tx and rx flags */ | |
5373 | IEEE80211_RADIOTAP_F_FRAG, /* F_FRAG (fragment if required) */ | |
5374 | 0x00, /* padding */ | |
5375 | 0x00, 0x00, /* RX and TX flags to indicate that */ | |
5376 | 0x00, 0x00, /* this is the injected frame directly */ | |
5377 | }; | |
5378 | struct iovec iov[2] = { | |
5379 | { | |
5380 | .iov_base = &rtap_hdr, | |
5381 | .iov_len = sizeof(rtap_hdr), | |
5382 | }, | |
5383 | { | |
5384 | .iov_base = (void *) data, | |
5385 | .iov_len = len, | |
5386 | } | |
5387 | }; | |
5388 | struct msghdr msg = { | |
5389 | .msg_name = NULL, | |
5390 | .msg_namelen = 0, | |
5391 | .msg_iov = iov, | |
5392 | .msg_iovlen = 2, | |
5393 | .msg_control = NULL, | |
5394 | .msg_controllen = 0, | |
5395 | .msg_flags = 0, | |
5396 | }; | |
ebbec8b2 | 5397 | int res; |
fab25336 | 5398 | u16 txflags = 0; |
2c2010ac JM |
5399 | |
5400 | if (encrypt) | |
5401 | rtap_hdr[8] |= IEEE80211_RADIOTAP_F_WEP; | |
5402 | ||
866af8b6 JM |
5403 | if (drv->monitor_sock < 0) { |
5404 | wpa_printf(MSG_DEBUG, "nl80211: No monitor socket available " | |
5405 | "for %s", __func__); | |
5406 | return -1; | |
5407 | } | |
5408 | ||
fab25336 HS |
5409 | if (noack) |
5410 | txflags |= IEEE80211_RADIOTAP_F_TX_NOACK; | |
9d7a63dc | 5411 | WPA_PUT_LE16(&rtap_hdr[12], txflags); |
fab25336 | 5412 | |
ebbec8b2 JM |
5413 | res = sendmsg(drv->monitor_sock, &msg, 0); |
5414 | if (res < 0) { | |
5415 | wpa_printf(MSG_INFO, "nl80211: sendmsg: %s", strerror(errno)); | |
5416 | return -1; | |
5417 | } | |
5418 | return 0; | |
2c2010ac JM |
5419 | } |
5420 | ||
5421 | ||
a11241fa JB |
5422 | static int wpa_driver_nl80211_send_frame(struct i802_bss *bss, |
5423 | const void *data, size_t len, | |
55231068 JM |
5424 | int encrypt, int noack, |
5425 | unsigned int freq, int no_cck, | |
5426 | int offchanok, unsigned int wait_time) | |
a11241fa JB |
5427 | { |
5428 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
5429 | u64 cookie; | |
5430 | ||
55231068 JM |
5431 | if (freq == 0) |
5432 | freq = bss->freq; | |
5433 | ||
a11241fa JB |
5434 | if (drv->use_monitor) |
5435 | return wpa_driver_nl80211_send_mntr(drv, data, len, | |
5436 | encrypt, noack); | |
5437 | ||
55231068 JM |
5438 | return nl80211_send_frame_cmd(bss, freq, wait_time, data, len, |
5439 | &cookie, no_cck, noack, offchanok); | |
a11241fa JB |
5440 | } |
5441 | ||
5442 | ||
9ebce9c5 JM |
5443 | static int wpa_driver_nl80211_send_mlme(struct i802_bss *bss, const u8 *data, |
5444 | size_t data_len, int noack, | |
5445 | unsigned int freq, int no_cck, | |
5446 | int offchanok, | |
5447 | unsigned int wait_time) | |
2c2010ac | 5448 | { |
a2e40bb6 | 5449 | struct wpa_driver_nl80211_data *drv = bss->drv; |
2c2010ac | 5450 | struct ieee80211_mgmt *mgmt; |
7a47d567 | 5451 | int encrypt = 1; |
2c2010ac JM |
5452 | u16 fc; |
5453 | ||
5454 | mgmt = (struct ieee80211_mgmt *) data; | |
5455 | fc = le_to_host16(mgmt->frame_control); | |
5456 | ||
b1f625e0 | 5457 | if (is_sta_interface(drv->nlmode) && |
5582a5d1 JB |
5458 | WLAN_FC_GET_TYPE(fc) == WLAN_FC_TYPE_MGMT && |
5459 | WLAN_FC_GET_STYPE(fc) == WLAN_FC_STYPE_PROBE_RESP) { | |
5460 | /* | |
5461 | * The use of last_mgmt_freq is a bit of a hack, | |
5462 | * but it works due to the single-threaded nature | |
5463 | * of wpa_supplicant. | |
5464 | */ | |
55231068 JM |
5465 | if (freq == 0) |
5466 | freq = drv->last_mgmt_freq; | |
5467 | return nl80211_send_frame_cmd(bss, freq, 0, | |
88df0ef7 JB |
5468 | data, data_len, NULL, 1, noack, |
5469 | 1); | |
5582a5d1 JB |
5470 | } |
5471 | ||
61cbe2ff | 5472 | if (drv->device_ap_sme && is_ap_interface(drv->nlmode)) { |
55231068 JM |
5473 | if (freq == 0) |
5474 | freq = bss->freq; | |
b5671498 JM |
5475 | return nl80211_send_frame_cmd(bss, freq, |
5476 | (int) freq == bss->freq ? 0 : | |
5477 | wait_time, | |
d8d6b32e DG |
5478 | data, data_len, |
5479 | &drv->send_action_cookie, | |
55231068 | 5480 | no_cck, noack, offchanok); |
86957e62 JM |
5481 | } |
5482 | ||
2c2010ac JM |
5483 | if (WLAN_FC_GET_TYPE(fc) == WLAN_FC_TYPE_MGMT && |
5484 | WLAN_FC_GET_STYPE(fc) == WLAN_FC_STYPE_AUTH) { | |
5485 | /* | |
5486 | * Only one of the authentication frame types is encrypted. | |
5487 | * In order for static WEP encryption to work properly (i.e., | |
5488 | * to not encrypt the frame), we need to tell mac80211 about | |
5489 | * the frames that must not be encrypted. | |
5490 | */ | |
5491 | u16 auth_alg = le_to_host16(mgmt->u.auth.auth_alg); | |
5492 | u16 auth_trans = le_to_host16(mgmt->u.auth.auth_transaction); | |
7a47d567 JB |
5493 | if (auth_alg != WLAN_AUTH_SHARED_KEY || auth_trans != 3) |
5494 | encrypt = 0; | |
2c2010ac JM |
5495 | } |
5496 | ||
a11241fa | 5497 | return wpa_driver_nl80211_send_frame(bss, data, data_len, encrypt, |
55231068 JM |
5498 | noack, freq, no_cck, offchanok, |
5499 | wait_time); | |
5500 | } | |
5501 | ||
5502 | ||
31357268 | 5503 | static int nl80211_set_bss(struct i802_bss *bss, int cts, int preamble, |
e5693c47 JM |
5504 | int slot, int ht_opmode, int ap_isolate, |
5505 | int *basic_rates) | |
31357268 JM |
5506 | { |
5507 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
5508 | struct nl_msg *msg; | |
5509 | ||
5510 | msg = nlmsg_alloc(); | |
5511 | if (!msg) | |
5512 | return -ENOMEM; | |
5513 | ||
9fb04070 | 5514 | nl80211_cmd(drv, msg, 0, NL80211_CMD_SET_BSS); |
31357268 JM |
5515 | |
5516 | if (cts >= 0) | |
5517 | NLA_PUT_U8(msg, NL80211_ATTR_BSS_CTS_PROT, cts); | |
5518 | if (preamble >= 0) | |
5519 | NLA_PUT_U8(msg, NL80211_ATTR_BSS_SHORT_PREAMBLE, preamble); | |
5520 | if (slot >= 0) | |
5521 | NLA_PUT_U8(msg, NL80211_ATTR_BSS_SHORT_SLOT_TIME, slot); | |
5522 | if (ht_opmode >= 0) | |
5523 | NLA_PUT_U16(msg, NL80211_ATTR_BSS_HT_OPMODE, ht_opmode); | |
d03e8d11 JM |
5524 | if (ap_isolate >= 0) |
5525 | NLA_PUT_U8(msg, NL80211_ATTR_AP_ISOLATE, ap_isolate); | |
e5693c47 JM |
5526 | |
5527 | if (basic_rates) { | |
5528 | u8 rates[NL80211_MAX_SUPP_RATES]; | |
5529 | u8 rates_len = 0; | |
5530 | int i; | |
5531 | ||
5532 | for (i = 0; i < NL80211_MAX_SUPP_RATES && basic_rates[i] >= 0; | |
5533 | i++) | |
5534 | rates[rates_len++] = basic_rates[i] / 5; | |
5535 | ||
5536 | NLA_PUT(msg, NL80211_ATTR_BSS_BASIC_RATES, rates_len, rates); | |
5537 | } | |
5538 | ||
31357268 JM |
5539 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, if_nametoindex(bss->ifname)); |
5540 | ||
5541 | return send_and_recv_msgs(drv, msg, NULL, NULL); | |
5542 | nla_put_failure: | |
5883168a | 5543 | nlmsg_free(msg); |
31357268 JM |
5544 | return -ENOBUFS; |
5545 | } | |
5546 | ||
5547 | ||
19c3b566 JM |
5548 | static int wpa_driver_nl80211_set_ap(void *priv, |
5549 | struct wpa_driver_ap_params *params) | |
d2440ba0 | 5550 | { |
a2e40bb6 FF |
5551 | struct i802_bss *bss = priv; |
5552 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
d2440ba0 JM |
5553 | struct nl_msg *msg; |
5554 | u8 cmd = NL80211_CMD_NEW_BEACON; | |
5555 | int ret; | |
b4fd6fab | 5556 | int beacon_set; |
8b897f5a | 5557 | int ifindex = if_nametoindex(bss->ifname); |
b11d1d64 JM |
5558 | int num_suites; |
5559 | u32 suites[10]; | |
5560 | u32 ver; | |
b4fd6fab | 5561 | |
b4fd6fab | 5562 | beacon_set = bss->beacon_set; |
d2440ba0 JM |
5563 | |
5564 | msg = nlmsg_alloc(); | |
5565 | if (!msg) | |
5566 | return -ENOMEM; | |
5567 | ||
5568 | wpa_printf(MSG_DEBUG, "nl80211: Set beacon (beacon_set=%d)", | |
b4fd6fab JM |
5569 | beacon_set); |
5570 | if (beacon_set) | |
d2440ba0 JM |
5571 | cmd = NL80211_CMD_SET_BEACON; |
5572 | ||
9fb04070 | 5573 | nl80211_cmd(drv, msg, 0, cmd); |
19c3b566 JM |
5574 | NLA_PUT(msg, NL80211_ATTR_BEACON_HEAD, params->head_len, params->head); |
5575 | NLA_PUT(msg, NL80211_ATTR_BEACON_TAIL, params->tail_len, params->tail); | |
b4fd6fab | 5576 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, ifindex); |
19c3b566 JM |
5577 | NLA_PUT_U32(msg, NL80211_ATTR_BEACON_INTERVAL, params->beacon_int); |
5578 | NLA_PUT_U32(msg, NL80211_ATTR_DTIM_PERIOD, params->dtim_period); | |
ccb941e6 JM |
5579 | NLA_PUT(msg, NL80211_ATTR_SSID, params->ssid_len, |
5580 | params->ssid); | |
5ed33546 AN |
5581 | if (params->proberesp && params->proberesp_len) |
5582 | NLA_PUT(msg, NL80211_ATTR_PROBE_RESP, params->proberesp_len, | |
5583 | params->proberesp); | |
97a7a0b5 JM |
5584 | switch (params->hide_ssid) { |
5585 | case NO_SSID_HIDING: | |
5586 | NLA_PUT_U32(msg, NL80211_ATTR_HIDDEN_SSID, | |
5587 | NL80211_HIDDEN_SSID_NOT_IN_USE); | |
5588 | break; | |
5589 | case HIDDEN_SSID_ZERO_LEN: | |
5590 | NLA_PUT_U32(msg, NL80211_ATTR_HIDDEN_SSID, | |
5591 | NL80211_HIDDEN_SSID_ZERO_LEN); | |
5592 | break; | |
5593 | case HIDDEN_SSID_ZERO_CONTENTS: | |
5594 | NLA_PUT_U32(msg, NL80211_ATTR_HIDDEN_SSID, | |
5595 | NL80211_HIDDEN_SSID_ZERO_CONTENTS); | |
5596 | break; | |
5597 | } | |
b11d1d64 JM |
5598 | if (params->privacy) |
5599 | NLA_PUT_FLAG(msg, NL80211_ATTR_PRIVACY); | |
5600 | if ((params->auth_algs & (WPA_AUTH_ALG_OPEN | WPA_AUTH_ALG_SHARED)) == | |
5601 | (WPA_AUTH_ALG_OPEN | WPA_AUTH_ALG_SHARED)) { | |
5602 | /* Leave out the attribute */ | |
5603 | } else if (params->auth_algs & WPA_AUTH_ALG_SHARED) | |
5604 | NLA_PUT_U32(msg, NL80211_ATTR_AUTH_TYPE, | |
5605 | NL80211_AUTHTYPE_SHARED_KEY); | |
5606 | else | |
5607 | NLA_PUT_U32(msg, NL80211_ATTR_AUTH_TYPE, | |
5608 | NL80211_AUTHTYPE_OPEN_SYSTEM); | |
5609 | ||
5610 | ver = 0; | |
5611 | if (params->wpa_version & WPA_PROTO_WPA) | |
5612 | ver |= NL80211_WPA_VERSION_1; | |
5613 | if (params->wpa_version & WPA_PROTO_RSN) | |
5614 | ver |= NL80211_WPA_VERSION_2; | |
5615 | if (ver) | |
5616 | NLA_PUT_U32(msg, NL80211_ATTR_WPA_VERSIONS, ver); | |
5617 | ||
5618 | num_suites = 0; | |
5619 | if (params->key_mgmt_suites & WPA_KEY_MGMT_IEEE8021X) | |
5620 | suites[num_suites++] = WLAN_AKM_SUITE_8021X; | |
5621 | if (params->key_mgmt_suites & WPA_KEY_MGMT_PSK) | |
5622 | suites[num_suites++] = WLAN_AKM_SUITE_PSK; | |
5623 | if (num_suites) { | |
5624 | NLA_PUT(msg, NL80211_ATTR_AKM_SUITES, | |
5625 | num_suites * sizeof(u32), suites); | |
5626 | } | |
5627 | ||
9f12614b JB |
5628 | if (params->key_mgmt_suites & WPA_KEY_MGMT_IEEE8021X && |
5629 | params->pairwise_ciphers & (WPA_CIPHER_WEP104 | WPA_CIPHER_WEP40)) | |
5630 | NLA_PUT_FLAG(msg, NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT); | |
5631 | ||
b11d1d64 JM |
5632 | num_suites = 0; |
5633 | if (params->pairwise_ciphers & WPA_CIPHER_CCMP) | |
5634 | suites[num_suites++] = WLAN_CIPHER_SUITE_CCMP; | |
eb7719ff JM |
5635 | if (params->pairwise_ciphers & WPA_CIPHER_GCMP) |
5636 | suites[num_suites++] = WLAN_CIPHER_SUITE_GCMP; | |
b11d1d64 JM |
5637 | if (params->pairwise_ciphers & WPA_CIPHER_TKIP) |
5638 | suites[num_suites++] = WLAN_CIPHER_SUITE_TKIP; | |
5639 | if (params->pairwise_ciphers & WPA_CIPHER_WEP104) | |
5640 | suites[num_suites++] = WLAN_CIPHER_SUITE_WEP104; | |
5641 | if (params->pairwise_ciphers & WPA_CIPHER_WEP40) | |
5642 | suites[num_suites++] = WLAN_CIPHER_SUITE_WEP40; | |
5643 | if (num_suites) { | |
5644 | NLA_PUT(msg, NL80211_ATTR_CIPHER_SUITES_PAIRWISE, | |
5645 | num_suites * sizeof(u32), suites); | |
5646 | } | |
5647 | ||
5648 | switch (params->group_cipher) { | |
5649 | case WPA_CIPHER_CCMP: | |
5650 | NLA_PUT_U32(msg, NL80211_ATTR_CIPHER_SUITE_GROUP, | |
5651 | WLAN_CIPHER_SUITE_CCMP); | |
5652 | break; | |
eb7719ff JM |
5653 | case WPA_CIPHER_GCMP: |
5654 | NLA_PUT_U32(msg, NL80211_ATTR_CIPHER_SUITE_GROUP, | |
5655 | WLAN_CIPHER_SUITE_GCMP); | |
5656 | break; | |
b11d1d64 JM |
5657 | case WPA_CIPHER_TKIP: |
5658 | NLA_PUT_U32(msg, NL80211_ATTR_CIPHER_SUITE_GROUP, | |
5659 | WLAN_CIPHER_SUITE_TKIP); | |
5660 | break; | |
5661 | case WPA_CIPHER_WEP104: | |
5662 | NLA_PUT_U32(msg, NL80211_ATTR_CIPHER_SUITE_GROUP, | |
5663 | WLAN_CIPHER_SUITE_WEP104); | |
5664 | break; | |
5665 | case WPA_CIPHER_WEP40: | |
5666 | NLA_PUT_U32(msg, NL80211_ATTR_CIPHER_SUITE_GROUP, | |
5667 | WLAN_CIPHER_SUITE_WEP40); | |
5668 | break; | |
5669 | } | |
d2440ba0 | 5670 | |
fb91db56 JM |
5671 | if (params->beacon_ies) { |
5672 | NLA_PUT(msg, NL80211_ATTR_IE, wpabuf_len(params->beacon_ies), | |
5673 | wpabuf_head(params->beacon_ies)); | |
5674 | } | |
5675 | if (params->proberesp_ies) { | |
5676 | NLA_PUT(msg, NL80211_ATTR_IE_PROBE_RESP, | |
5677 | wpabuf_len(params->proberesp_ies), | |
5678 | wpabuf_head(params->proberesp_ies)); | |
5679 | } | |
5680 | if (params->assocresp_ies) { | |
5681 | NLA_PUT(msg, NL80211_ATTR_IE_ASSOC_RESP, | |
5682 | wpabuf_len(params->assocresp_ies), | |
5683 | wpabuf_head(params->assocresp_ies)); | |
5684 | } | |
5685 | ||
a0133ee1 VT |
5686 | if (drv->capa.flags & WPA_DRIVER_FLAGS_INACTIVITY_TIMER) { |
5687 | NLA_PUT_U16(msg, NL80211_ATTR_INACTIVITY_TIMEOUT, | |
5688 | params->ap_max_inactivity); | |
5689 | } | |
5690 | ||
d2440ba0 JM |
5691 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
5692 | if (ret) { | |
5693 | wpa_printf(MSG_DEBUG, "nl80211: Beacon set failed: %d (%s)", | |
5694 | ret, strerror(-ret)); | |
b4fd6fab | 5695 | } else { |
b4fd6fab | 5696 | bss->beacon_set = 1; |
31357268 | 5697 | nl80211_set_bss(bss, params->cts_protect, params->preamble, |
d03e8d11 | 5698 | params->short_slot_time, params->ht_opmode, |
e5693c47 | 5699 | params->isolate, params->basic_rates); |
b4fd6fab | 5700 | } |
d2440ba0 JM |
5701 | return ret; |
5702 | nla_put_failure: | |
5883168a | 5703 | nlmsg_free(msg); |
d2440ba0 JM |
5704 | return -ENOBUFS; |
5705 | } | |
5706 | ||
5707 | ||
e4fb2167 | 5708 | static int wpa_driver_nl80211_set_freq(struct i802_bss *bss, |
89b800d7 | 5709 | struct hostapd_freq_params *freq) |
1581b38b | 5710 | { |
e4fb2167 | 5711 | struct wpa_driver_nl80211_data *drv = bss->drv; |
1581b38b | 5712 | struct nl_msg *msg; |
d2440ba0 | 5713 | int ret; |
1581b38b | 5714 | |
89b800d7 JB |
5715 | wpa_printf(MSG_DEBUG, "nl80211: Set freq %d (ht_enabled=%d, vht_enabled=%d," |
5716 | " bandwidth=%d MHz, cf1=%d MHz, cf2=%d MHz)", | |
5717 | freq->freq, freq->ht_enabled, freq->vht_enabled, | |
5718 | freq->bandwidth, freq->center_freq1, freq->center_freq2); | |
1581b38b JM |
5719 | msg = nlmsg_alloc(); |
5720 | if (!msg) | |
5721 | return -1; | |
5722 | ||
9fb04070 | 5723 | nl80211_cmd(drv, msg, 0, NL80211_CMD_SET_WIPHY); |
1581b38b JM |
5724 | |
5725 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, drv->ifindex); | |
89b800d7 JB |
5726 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_FREQ, freq->freq); |
5727 | if (freq->vht_enabled) { | |
5728 | switch (freq->bandwidth) { | |
5729 | case 20: | |
5730 | NLA_PUT_U32(msg, NL80211_ATTR_CHANNEL_WIDTH, | |
5731 | NL80211_CHAN_WIDTH_20); | |
5732 | break; | |
5733 | case 40: | |
5734 | NLA_PUT_U32(msg, NL80211_ATTR_CHANNEL_WIDTH, | |
5735 | NL80211_CHAN_WIDTH_40); | |
5736 | break; | |
5737 | case 80: | |
5738 | if (freq->center_freq2) | |
5739 | NLA_PUT_U32(msg, NL80211_ATTR_CHANNEL_WIDTH, | |
5740 | NL80211_CHAN_WIDTH_80P80); | |
5741 | else | |
5742 | NLA_PUT_U32(msg, NL80211_ATTR_CHANNEL_WIDTH, | |
5743 | NL80211_CHAN_WIDTH_80); | |
5744 | break; | |
5745 | case 160: | |
5746 | NLA_PUT_U32(msg, NL80211_ATTR_CHANNEL_WIDTH, | |
5747 | NL80211_CHAN_WIDTH_160); | |
5748 | break; | |
5749 | default: | |
5750 | return -1; | |
5751 | } | |
5752 | NLA_PUT_U32(msg, NL80211_ATTR_CENTER_FREQ1, freq->center_freq1); | |
5753 | if (freq->center_freq2) | |
5754 | NLA_PUT_U32(msg, NL80211_ATTR_CENTER_FREQ2, | |
5755 | freq->center_freq2); | |
5756 | } else if (freq->ht_enabled) { | |
5757 | switch (freq->sec_channel_offset) { | |
f019981a JM |
5758 | case -1: |
5759 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE, | |
5760 | NL80211_CHAN_HT40MINUS); | |
5761 | break; | |
5762 | case 1: | |
5763 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE, | |
5764 | NL80211_CHAN_HT40PLUS); | |
5765 | break; | |
5766 | default: | |
5767 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE, | |
5768 | NL80211_CHAN_HT20); | |
5769 | break; | |
5770 | } | |
5771 | } | |
1581b38b | 5772 | |
d2440ba0 | 5773 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
5883168a | 5774 | msg = NULL; |
e4fb2167 | 5775 | if (ret == 0) { |
89b800d7 | 5776 | bss->freq = freq->freq; |
1581b38b | 5777 | return 0; |
e4fb2167 | 5778 | } |
f019981a | 5779 | wpa_printf(MSG_DEBUG, "nl80211: Failed to set channel (freq=%d): " |
89b800d7 | 5780 | "%d (%s)", freq->freq, ret, strerror(-ret)); |
1581b38b | 5781 | nla_put_failure: |
5883168a | 5782 | nlmsg_free(msg); |
1581b38b JM |
5783 | return -1; |
5784 | } | |
5785 | ||
0f4e8b4f | 5786 | |
95ab6063 AN |
5787 | static u32 sta_flags_nl80211(int flags) |
5788 | { | |
5789 | u32 f = 0; | |
5790 | ||
5791 | if (flags & WPA_STA_AUTHORIZED) | |
5792 | f |= BIT(NL80211_STA_FLAG_AUTHORIZED); | |
5793 | if (flags & WPA_STA_WMM) | |
5794 | f |= BIT(NL80211_STA_FLAG_WME); | |
5795 | if (flags & WPA_STA_SHORT_PREAMBLE) | |
5796 | f |= BIT(NL80211_STA_FLAG_SHORT_PREAMBLE); | |
5797 | if (flags & WPA_STA_MFP) | |
5798 | f |= BIT(NL80211_STA_FLAG_MFP); | |
45b722f1 AN |
5799 | if (flags & WPA_STA_TDLS_PEER) |
5800 | f |= BIT(NL80211_STA_FLAG_TDLS_PEER); | |
95ab6063 AN |
5801 | |
5802 | return f; | |
5803 | } | |
5804 | ||
5805 | ||
62847751 | 5806 | static int wpa_driver_nl80211_sta_add(void *priv, |
0f4e8b4f JM |
5807 | struct hostapd_sta_add_params *params) |
5808 | { | |
a2e40bb6 FF |
5809 | struct i802_bss *bss = priv; |
5810 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
774bfa62 | 5811 | struct nl_msg *msg, *wme = NULL; |
95ab6063 | 5812 | struct nl80211_sta_flag_update upd; |
0f4e8b4f JM |
5813 | int ret = -ENOBUFS; |
5814 | ||
45b722f1 AN |
5815 | if ((params->flags & WPA_STA_TDLS_PEER) && |
5816 | !(drv->capa.flags & WPA_DRIVER_FLAGS_TDLS_SUPPORT)) | |
5817 | return -EOPNOTSUPP; | |
5818 | ||
0f4e8b4f JM |
5819 | msg = nlmsg_alloc(); |
5820 | if (!msg) | |
5821 | return -ENOMEM; | |
5822 | ||
45b722f1 AN |
5823 | nl80211_cmd(drv, msg, 0, params->set ? NL80211_CMD_SET_STATION : |
5824 | NL80211_CMD_NEW_STATION); | |
0f4e8b4f | 5825 | |
62847751 | 5826 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, if_nametoindex(bss->ifname)); |
0f4e8b4f | 5827 | NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, params->addr); |
0f4e8b4f JM |
5828 | NLA_PUT(msg, NL80211_ATTR_STA_SUPPORTED_RATES, params->supp_rates_len, |
5829 | params->supp_rates); | |
45b722f1 AN |
5830 | if (!params->set) { |
5831 | NLA_PUT_U16(msg, NL80211_ATTR_STA_AID, params->aid); | |
5832 | NLA_PUT_U16(msg, NL80211_ATTR_STA_LISTEN_INTERVAL, | |
5833 | params->listen_interval); | |
5834 | } | |
0f4e8b4f JM |
5835 | if (params->ht_capabilities) { |
5836 | NLA_PUT(msg, NL80211_ATTR_HT_CAPABILITY, | |
fc4e2d95 JM |
5837 | sizeof(*params->ht_capabilities), |
5838 | params->ht_capabilities); | |
0f4e8b4f | 5839 | } |
0f4e8b4f | 5840 | |
05a8d422 JB |
5841 | if (params->vht_capabilities) { |
5842 | NLA_PUT(msg, NL80211_ATTR_VHT_CAPABILITY, | |
5843 | sizeof(*params->vht_capabilities), | |
5844 | params->vht_capabilities); | |
5845 | } | |
5846 | ||
95ab6063 AN |
5847 | os_memset(&upd, 0, sizeof(upd)); |
5848 | upd.mask = sta_flags_nl80211(params->flags); | |
5849 | upd.set = upd.mask; | |
5850 | NLA_PUT(msg, NL80211_ATTR_STA_FLAGS2, sizeof(upd), &upd); | |
5851 | ||
774bfa62 EP |
5852 | if (params->flags & WPA_STA_WMM) { |
5853 | wme = nlmsg_alloc(); | |
5854 | if (!wme) | |
5855 | goto nla_put_failure; | |
5856 | ||
5857 | NLA_PUT_U8(wme, NL80211_STA_WME_UAPSD_QUEUES, | |
5d061637 JY |
5858 | params->qosinfo & WMM_QOSINFO_STA_AC_MASK); |
5859 | NLA_PUT_U8(wme, NL80211_STA_WME_MAX_SP, | |
5860 | (params->qosinfo > WMM_QOSINFO_STA_SP_SHIFT) & | |
5861 | WMM_QOSINFO_STA_SP_MASK); | |
f0494d0f JM |
5862 | if (nla_put_nested(msg, NL80211_ATTR_STA_WME, wme) < 0) |
5863 | goto nla_put_failure; | |
774bfa62 EP |
5864 | } |
5865 | ||
0f4e8b4f | 5866 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
5883168a | 5867 | msg = NULL; |
0f4e8b4f | 5868 | if (ret) |
45b722f1 AN |
5869 | wpa_printf(MSG_DEBUG, "nl80211: NL80211_CMD_%s_STATION " |
5870 | "result: %d (%s)", params->set ? "SET" : "NEW", ret, | |
5871 | strerror(-ret)); | |
0f4e8b4f JM |
5872 | if (ret == -EEXIST) |
5873 | ret = 0; | |
5874 | nla_put_failure: | |
5d061637 | 5875 | nlmsg_free(wme); |
5883168a | 5876 | nlmsg_free(msg); |
0f4e8b4f JM |
5877 | return ret; |
5878 | } | |
5879 | ||
5880 | ||
9ebce9c5 | 5881 | static int wpa_driver_nl80211_sta_remove(struct i802_bss *bss, const u8 *addr) |
0f4e8b4f | 5882 | { |
a2e40bb6 | 5883 | struct wpa_driver_nl80211_data *drv = bss->drv; |
0f4e8b4f JM |
5884 | struct nl_msg *msg; |
5885 | int ret; | |
5886 | ||
5887 | msg = nlmsg_alloc(); | |
5888 | if (!msg) | |
5889 | return -ENOMEM; | |
5890 | ||
9fb04070 | 5891 | nl80211_cmd(drv, msg, 0, NL80211_CMD_DEL_STATION); |
0f4e8b4f JM |
5892 | |
5893 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, | |
a2e40bb6 | 5894 | if_nametoindex(bss->ifname)); |
0f4e8b4f JM |
5895 | NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, addr); |
5896 | ||
5897 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); | |
5898 | if (ret == -ENOENT) | |
5899 | return 0; | |
5900 | return ret; | |
5901 | nla_put_failure: | |
5883168a | 5902 | nlmsg_free(msg); |
0f4e8b4f JM |
5903 | return -ENOBUFS; |
5904 | } | |
5905 | ||
1581b38b | 5906 | |
0915d02c JM |
5907 | static void nl80211_remove_iface(struct wpa_driver_nl80211_data *drv, |
5908 | int ifidx) | |
5909 | { | |
5910 | struct nl_msg *msg; | |
5911 | ||
c6e8e8e4 JM |
5912 | wpa_printf(MSG_DEBUG, "nl80211: Remove interface ifindex=%d", ifidx); |
5913 | ||
2135f224 JM |
5914 | /* stop listening for EAPOL on this interface */ |
5915 | del_ifidx(drv, ifidx); | |
2135f224 | 5916 | |
0915d02c JM |
5917 | msg = nlmsg_alloc(); |
5918 | if (!msg) | |
5919 | goto nla_put_failure; | |
5920 | ||
9fb04070 | 5921 | nl80211_cmd(drv, msg, 0, NL80211_CMD_DEL_INTERFACE); |
0915d02c JM |
5922 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, ifidx); |
5923 | ||
5924 | if (send_and_recv_msgs(drv, msg, NULL, NULL) == 0) | |
5925 | return; | |
5883168a | 5926 | msg = NULL; |
0915d02c | 5927 | nla_put_failure: |
5883168a | 5928 | nlmsg_free(msg); |
e748062b | 5929 | wpa_printf(MSG_ERROR, "Failed to remove interface (ifidx=%d)", ifidx); |
0915d02c JM |
5930 | } |
5931 | ||
5932 | ||
a1922f93 JM |
5933 | static const char * nl80211_iftype_str(enum nl80211_iftype mode) |
5934 | { | |
5935 | switch (mode) { | |
5936 | case NL80211_IFTYPE_ADHOC: | |
5937 | return "ADHOC"; | |
5938 | case NL80211_IFTYPE_STATION: | |
5939 | return "STATION"; | |
5940 | case NL80211_IFTYPE_AP: | |
5941 | return "AP"; | |
5942 | case NL80211_IFTYPE_MONITOR: | |
5943 | return "MONITOR"; | |
5944 | case NL80211_IFTYPE_P2P_CLIENT: | |
5945 | return "P2P_CLIENT"; | |
5946 | case NL80211_IFTYPE_P2P_GO: | |
5947 | return "P2P_GO"; | |
5948 | default: | |
5949 | return "unknown"; | |
5950 | } | |
5951 | } | |
5952 | ||
5953 | ||
a35187e7 KH |
5954 | static int nl80211_create_iface_once(struct wpa_driver_nl80211_data *drv, |
5955 | const char *ifname, | |
5956 | enum nl80211_iftype iftype, | |
fbbfcbac | 5957 | const u8 *addr, int wds) |
0915d02c JM |
5958 | { |
5959 | struct nl_msg *msg, *flags = NULL; | |
5960 | int ifidx; | |
5961 | int ret = -ENOBUFS; | |
5962 | ||
a1922f93 JM |
5963 | wpa_printf(MSG_DEBUG, "nl80211: Create interface iftype %d (%s)", |
5964 | iftype, nl80211_iftype_str(iftype)); | |
5965 | ||
0915d02c JM |
5966 | msg = nlmsg_alloc(); |
5967 | if (!msg) | |
5968 | return -1; | |
5969 | ||
9fb04070 | 5970 | nl80211_cmd(drv, msg, 0, NL80211_CMD_NEW_INTERFACE); |
0915d02c JM |
5971 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, drv->ifindex); |
5972 | NLA_PUT_STRING(msg, NL80211_ATTR_IFNAME, ifname); | |
5973 | NLA_PUT_U32(msg, NL80211_ATTR_IFTYPE, iftype); | |
5974 | ||
5975 | if (iftype == NL80211_IFTYPE_MONITOR) { | |
5976 | int err; | |
5977 | ||
5978 | flags = nlmsg_alloc(); | |
5979 | if (!flags) | |
5980 | goto nla_put_failure; | |
5981 | ||
5982 | NLA_PUT_FLAG(flags, NL80211_MNTR_FLAG_COOK_FRAMES); | |
5983 | ||
5984 | err = nla_put_nested(msg, NL80211_ATTR_MNTR_FLAGS, flags); | |
5985 | ||
5986 | nlmsg_free(flags); | |
5987 | ||
5988 | if (err) | |
5989 | goto nla_put_failure; | |
fbbfcbac FF |
5990 | } else if (wds) { |
5991 | NLA_PUT_U8(msg, NL80211_ATTR_4ADDR, wds); | |
0915d02c JM |
5992 | } |
5993 | ||
5994 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); | |
5883168a | 5995 | msg = NULL; |
0915d02c JM |
5996 | if (ret) { |
5997 | nla_put_failure: | |
5883168a | 5998 | nlmsg_free(msg); |
a35187e7 KH |
5999 | wpa_printf(MSG_ERROR, "Failed to create interface %s: %d (%s)", |
6000 | ifname, ret, strerror(-ret)); | |
0915d02c JM |
6001 | return ret; |
6002 | } | |
6003 | ||
6004 | ifidx = if_nametoindex(ifname); | |
c6e8e8e4 JM |
6005 | wpa_printf(MSG_DEBUG, "nl80211: New interface %s created: ifindex=%d", |
6006 | ifname, ifidx); | |
0915d02c JM |
6007 | |
6008 | if (ifidx <= 0) | |
6009 | return -1; | |
6010 | ||
2135f224 JM |
6011 | /* start listening for EAPOL on this interface */ |
6012 | add_ifidx(drv, ifidx); | |
6013 | ||
7bfc47c3 | 6014 | if (addr && iftype != NL80211_IFTYPE_MONITOR && |
c81eff1a | 6015 | linux_set_ifhwaddr(drv->global->ioctl_sock, ifname, addr)) { |
41d931ee JM |
6016 | nl80211_remove_iface(drv, ifidx); |
6017 | return -1; | |
2135f224 | 6018 | } |
2135f224 | 6019 | |
0915d02c JM |
6020 | return ifidx; |
6021 | } | |
22a7c9d7 JM |
6022 | |
6023 | ||
a35187e7 KH |
6024 | static int nl80211_create_iface(struct wpa_driver_nl80211_data *drv, |
6025 | const char *ifname, enum nl80211_iftype iftype, | |
fbbfcbac | 6026 | const u8 *addr, int wds) |
a35187e7 KH |
6027 | { |
6028 | int ret; | |
6029 | ||
fbbfcbac | 6030 | ret = nl80211_create_iface_once(drv, ifname, iftype, addr, wds); |
a35187e7 | 6031 | |
ffbf1eaa | 6032 | /* if error occurred and interface exists already */ |
a35187e7 KH |
6033 | if (ret == -ENFILE && if_nametoindex(ifname)) { |
6034 | wpa_printf(MSG_INFO, "Try to remove and re-create %s", ifname); | |
6035 | ||
6036 | /* Try to remove the interface that was already there. */ | |
6037 | nl80211_remove_iface(drv, if_nametoindex(ifname)); | |
6038 | ||
6039 | /* Try to create the interface again */ | |
fbbfcbac FF |
6040 | ret = nl80211_create_iface_once(drv, ifname, iftype, addr, |
6041 | wds); | |
a35187e7 KH |
6042 | } |
6043 | ||
b3af99d2 | 6044 | if (ret >= 0 && is_p2p_interface(iftype)) |
4e5cb1a3 JM |
6045 | nl80211_disable_11b_rates(drv, ret, 1); |
6046 | ||
a35187e7 KH |
6047 | return ret; |
6048 | } | |
0915d02c | 6049 | |
2135f224 | 6050 | |
0915d02c JM |
6051 | static void handle_tx_callback(void *ctx, u8 *buf, size_t len, int ok) |
6052 | { | |
6053 | struct ieee80211_hdr *hdr; | |
f8b1f695 JM |
6054 | u16 fc; |
6055 | union wpa_event_data event; | |
0915d02c JM |
6056 | |
6057 | hdr = (struct ieee80211_hdr *) buf; | |
6058 | fc = le_to_host16(hdr->frame_control); | |
6059 | ||
f8b1f695 JM |
6060 | os_memset(&event, 0, sizeof(event)); |
6061 | event.tx_status.type = WLAN_FC_GET_TYPE(fc); | |
6062 | event.tx_status.stype = WLAN_FC_GET_STYPE(fc); | |
6063 | event.tx_status.dst = hdr->addr1; | |
6064 | event.tx_status.data = buf; | |
6065 | event.tx_status.data_len = len; | |
6066 | event.tx_status.ack = ok; | |
6067 | wpa_supplicant_event(ctx, EVENT_TX_STATUS, &event); | |
0915d02c JM |
6068 | } |
6069 | ||
6070 | ||
4b9841d3 | 6071 | static void from_unknown_sta(struct wpa_driver_nl80211_data *drv, |
0d9fc3d8 | 6072 | u8 *buf, size_t len) |
0915d02c | 6073 | { |
9b90955e JB |
6074 | struct ieee80211_hdr *hdr = (void *)buf; |
6075 | u16 fc; | |
f8b1f695 | 6076 | union wpa_event_data event; |
9b90955e JB |
6077 | |
6078 | if (len < sizeof(*hdr)) | |
6079 | return; | |
6080 | ||
6081 | fc = le_to_host16(hdr->frame_control); | |
6082 | ||
f8b1f695 | 6083 | os_memset(&event, 0, sizeof(event)); |
9b90955e JB |
6084 | event.rx_from_unknown.bssid = get_hdr_bssid(hdr, len); |
6085 | event.rx_from_unknown.addr = hdr->addr2; | |
6086 | event.rx_from_unknown.wds = (fc & (WLAN_FC_FROMDS | WLAN_FC_TODS)) == | |
6087 | (WLAN_FC_FROMDS | WLAN_FC_TODS); | |
f8b1f695 | 6088 | wpa_supplicant_event(drv->ctx, EVENT_RX_FROM_UNKNOWN, &event); |
4b9841d3 | 6089 | } |
0915d02c | 6090 | |
4b9841d3 JM |
6091 | |
6092 | static void handle_frame(struct wpa_driver_nl80211_data *drv, | |
2a8b7416 | 6093 | u8 *buf, size_t len, int datarate, int ssi_signal) |
4b9841d3 JM |
6094 | { |
6095 | struct ieee80211_hdr *hdr; | |
f8b1f695 JM |
6096 | u16 fc; |
6097 | union wpa_event_data event; | |
0915d02c JM |
6098 | |
6099 | hdr = (struct ieee80211_hdr *) buf; | |
6100 | fc = le_to_host16(hdr->frame_control); | |
0915d02c | 6101 | |
4b9841d3 | 6102 | switch (WLAN_FC_GET_TYPE(fc)) { |
0915d02c | 6103 | case WLAN_FC_TYPE_MGMT: |
f8b1f695 JM |
6104 | os_memset(&event, 0, sizeof(event)); |
6105 | event.rx_mgmt.frame = buf; | |
6106 | event.rx_mgmt.frame_len = len; | |
2a8b7416 JM |
6107 | event.rx_mgmt.datarate = datarate; |
6108 | event.rx_mgmt.ssi_signal = ssi_signal; | |
f8b1f695 | 6109 | wpa_supplicant_event(drv->ctx, EVENT_RX_MGMT, &event); |
0915d02c JM |
6110 | break; |
6111 | case WLAN_FC_TYPE_CTRL: | |
6112 | /* can only get here with PS-Poll frames */ | |
6113 | wpa_printf(MSG_DEBUG, "CTRL"); | |
0d9fc3d8 | 6114 | from_unknown_sta(drv, buf, len); |
0915d02c JM |
6115 | break; |
6116 | case WLAN_FC_TYPE_DATA: | |
0d9fc3d8 | 6117 | from_unknown_sta(drv, buf, len); |
0915d02c JM |
6118 | break; |
6119 | } | |
6120 | } | |
6121 | ||
6122 | ||
6123 | static void handle_monitor_read(int sock, void *eloop_ctx, void *sock_ctx) | |
6124 | { | |
6125 | struct wpa_driver_nl80211_data *drv = eloop_ctx; | |
6126 | int len; | |
6127 | unsigned char buf[3000]; | |
6128 | struct ieee80211_radiotap_iterator iter; | |
6129 | int ret; | |
2a8b7416 | 6130 | int datarate = 0, ssi_signal = 0; |
4b9841d3 | 6131 | int injected = 0, failed = 0, rxflags = 0; |
0915d02c JM |
6132 | |
6133 | len = recv(sock, buf, sizeof(buf), 0); | |
6134 | if (len < 0) { | |
6135 | perror("recv"); | |
6136 | return; | |
6137 | } | |
6138 | ||
6139 | if (ieee80211_radiotap_iterator_init(&iter, (void*)buf, len)) { | |
6140 | printf("received invalid radiotap frame\n"); | |
6141 | return; | |
6142 | } | |
6143 | ||
0915d02c JM |
6144 | while (1) { |
6145 | ret = ieee80211_radiotap_iterator_next(&iter); | |
6146 | if (ret == -ENOENT) | |
6147 | break; | |
6148 | if (ret) { | |
6149 | printf("received invalid radiotap frame (%d)\n", ret); | |
6150 | return; | |
6151 | } | |
6152 | switch (iter.this_arg_index) { | |
6153 | case IEEE80211_RADIOTAP_FLAGS: | |
6154 | if (*iter.this_arg & IEEE80211_RADIOTAP_F_FCS) | |
6155 | len -= 4; | |
6156 | break; | |
6157 | case IEEE80211_RADIOTAP_RX_FLAGS: | |
6158 | rxflags = 1; | |
6159 | break; | |
6160 | case IEEE80211_RADIOTAP_TX_FLAGS: | |
6161 | injected = 1; | |
6162 | failed = le_to_host16((*(uint16_t *) iter.this_arg)) & | |
6163 | IEEE80211_RADIOTAP_F_TX_FAIL; | |
6164 | break; | |
6165 | case IEEE80211_RADIOTAP_DATA_RETRIES: | |
6166 | break; | |
6167 | case IEEE80211_RADIOTAP_CHANNEL: | |
2a8b7416 | 6168 | /* TODO: convert from freq/flags to channel number */ |
0915d02c JM |
6169 | break; |
6170 | case IEEE80211_RADIOTAP_RATE: | |
2a8b7416 | 6171 | datarate = *iter.this_arg * 5; |
0915d02c | 6172 | break; |
baf513d6 JB |
6173 | case IEEE80211_RADIOTAP_DBM_ANTSIGNAL: |
6174 | ssi_signal = (s8) *iter.this_arg; | |
0915d02c JM |
6175 | break; |
6176 | } | |
6177 | } | |
6178 | ||
6179 | if (rxflags && injected) | |
6180 | return; | |
6181 | ||
6182 | if (!injected) | |
4b9841d3 | 6183 | handle_frame(drv, buf + iter.max_length, |
2a8b7416 | 6184 | len - iter.max_length, datarate, ssi_signal); |
0915d02c | 6185 | else |
4b9841d3 JM |
6186 | handle_tx_callback(drv->ctx, buf + iter.max_length, |
6187 | len - iter.max_length, !failed); | |
0915d02c JM |
6188 | } |
6189 | ||
6190 | ||
6191 | /* | |
6192 | * we post-process the filter code later and rewrite | |
6193 | * this to the offset to the last instruction | |
6194 | */ | |
6195 | #define PASS 0xFF | |
6196 | #define FAIL 0xFE | |
6197 | ||
6198 | static struct sock_filter msock_filter_insns[] = { | |
6199 | /* | |
6200 | * do a little-endian load of the radiotap length field | |
6201 | */ | |
6202 | /* load lower byte into A */ | |
6203 | BPF_STMT(BPF_LD | BPF_B | BPF_ABS, 2), | |
6204 | /* put it into X (== index register) */ | |
6205 | BPF_STMT(BPF_MISC| BPF_TAX, 0), | |
6206 | /* load upper byte into A */ | |
6207 | BPF_STMT(BPF_LD | BPF_B | BPF_ABS, 3), | |
6208 | /* left-shift it by 8 */ | |
6209 | BPF_STMT(BPF_ALU | BPF_LSH | BPF_K, 8), | |
6210 | /* or with X */ | |
6211 | BPF_STMT(BPF_ALU | BPF_OR | BPF_X, 0), | |
6212 | /* put result into X */ | |
6213 | BPF_STMT(BPF_MISC| BPF_TAX, 0), | |
6214 | ||
6215 | /* | |
6216 | * Allow management frames through, this also gives us those | |
6217 | * management frames that we sent ourselves with status | |
6218 | */ | |
6219 | /* load the lower byte of the IEEE 802.11 frame control field */ | |
6220 | BPF_STMT(BPF_LD | BPF_B | BPF_IND, 0), | |
6221 | /* mask off frame type and version */ | |
6222 | BPF_STMT(BPF_ALU | BPF_AND | BPF_K, 0xF), | |
6223 | /* accept frame if it's both 0, fall through otherwise */ | |
6224 | BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 0, PASS, 0), | |
6225 | ||
6226 | /* | |
6227 | * TODO: add a bit to radiotap RX flags that indicates | |
6228 | * that the sending station is not associated, then | |
6229 | * add a filter here that filters on our DA and that flag | |
6230 | * to allow us to deauth frames to that bad station. | |
6231 | * | |
65ae1afd | 6232 | * For now allow all To DS data frames through. |
0915d02c | 6233 | */ |
65ae1afd HS |
6234 | /* load the IEEE 802.11 frame control field */ |
6235 | BPF_STMT(BPF_LD | BPF_H | BPF_IND, 0), | |
6236 | /* mask off frame type, version and DS status */ | |
6237 | BPF_STMT(BPF_ALU | BPF_AND | BPF_K, 0x0F03), | |
6238 | /* accept frame if version 0, type 2 and To DS, fall through otherwise | |
6239 | */ | |
6240 | BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 0x0801, PASS, 0), | |
0915d02c JM |
6241 | |
6242 | #if 0 | |
6243 | /* | |
fbbfcbac | 6244 | * drop non-data frames |
0915d02c JM |
6245 | */ |
6246 | /* load the lower byte of the frame control field */ | |
6247 | BPF_STMT(BPF_LD | BPF_B | BPF_IND, 0), | |
6248 | /* mask off QoS bit */ | |
6249 | BPF_STMT(BPF_ALU | BPF_AND | BPF_K, 0x0c), | |
6250 | /* drop non-data frames */ | |
6251 | BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 8, 0, FAIL), | |
fbbfcbac | 6252 | #endif |
0915d02c | 6253 | /* load the upper byte of the frame control field */ |
fbbfcbac | 6254 | BPF_STMT(BPF_LD | BPF_B | BPF_IND, 1), |
0915d02c JM |
6255 | /* mask off toDS/fromDS */ |
6256 | BPF_STMT(BPF_ALU | BPF_AND | BPF_K, 0x03), | |
fbbfcbac FF |
6257 | /* accept WDS frames */ |
6258 | BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 3, PASS, 0), | |
0915d02c JM |
6259 | |
6260 | /* | |
6261 | * add header length to index | |
6262 | */ | |
6263 | /* load the lower byte of the frame control field */ | |
6264 | BPF_STMT(BPF_LD | BPF_B | BPF_IND, 0), | |
6265 | /* mask off QoS bit */ | |
6266 | BPF_STMT(BPF_ALU | BPF_AND | BPF_K, 0x80), | |
6267 | /* right shift it by 6 to give 0 or 2 */ | |
6268 | BPF_STMT(BPF_ALU | BPF_RSH | BPF_K, 6), | |
6269 | /* add data frame header length */ | |
6270 | BPF_STMT(BPF_ALU | BPF_ADD | BPF_K, 24), | |
6271 | /* add index, was start of 802.11 header */ | |
6272 | BPF_STMT(BPF_ALU | BPF_ADD | BPF_X, 0), | |
6273 | /* move to index, now start of LL header */ | |
6274 | BPF_STMT(BPF_MISC | BPF_TAX, 0), | |
6275 | ||
6276 | /* | |
6277 | * Accept empty data frames, we use those for | |
6278 | * polling activity. | |
6279 | */ | |
6280 | BPF_STMT(BPF_LD | BPF_W | BPF_LEN, 0), | |
6281 | BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_X, 0, PASS, 0), | |
6282 | ||
6283 | /* | |
6284 | * Accept EAPOL frames | |
6285 | */ | |
6286 | BPF_STMT(BPF_LD | BPF_W | BPF_IND, 0), | |
6287 | BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 0xAAAA0300, 0, FAIL), | |
6288 | BPF_STMT(BPF_LD | BPF_W | BPF_IND, 4), | |
6289 | BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 0x0000888E, PASS, FAIL), | |
6290 | ||
6291 | /* keep these last two statements or change the code below */ | |
6292 | /* return 0 == "DROP" */ | |
6293 | BPF_STMT(BPF_RET | BPF_K, 0), | |
6294 | /* return ~0 == "keep all" */ | |
6295 | BPF_STMT(BPF_RET | BPF_K, ~0), | |
6296 | }; | |
6297 | ||
6298 | static struct sock_fprog msock_filter = { | |
6299 | .len = sizeof(msock_filter_insns)/sizeof(msock_filter_insns[0]), | |
6300 | .filter = msock_filter_insns, | |
6301 | }; | |
6302 | ||
6303 | ||
6304 | static int add_monitor_filter(int s) | |
6305 | { | |
6306 | int idx; | |
6307 | ||
6308 | /* rewrite all PASS/FAIL jump offsets */ | |
6309 | for (idx = 0; idx < msock_filter.len; idx++) { | |
6310 | struct sock_filter *insn = &msock_filter_insns[idx]; | |
6311 | ||
6312 | if (BPF_CLASS(insn->code) == BPF_JMP) { | |
6313 | if (insn->code == (BPF_JMP|BPF_JA)) { | |
6314 | if (insn->k == PASS) | |
6315 | insn->k = msock_filter.len - idx - 2; | |
6316 | else if (insn->k == FAIL) | |
6317 | insn->k = msock_filter.len - idx - 3; | |
6318 | } | |
6319 | ||
6320 | if (insn->jt == PASS) | |
6321 | insn->jt = msock_filter.len - idx - 2; | |
6322 | else if (insn->jt == FAIL) | |
6323 | insn->jt = msock_filter.len - idx - 3; | |
6324 | ||
6325 | if (insn->jf == PASS) | |
6326 | insn->jf = msock_filter.len - idx - 2; | |
6327 | else if (insn->jf == FAIL) | |
6328 | insn->jf = msock_filter.len - idx - 3; | |
6329 | } | |
6330 | } | |
6331 | ||
6332 | if (setsockopt(s, SOL_SOCKET, SO_ATTACH_FILTER, | |
6333 | &msock_filter, sizeof(msock_filter))) { | |
6334 | perror("SO_ATTACH_FILTER"); | |
6335 | return -1; | |
6336 | } | |
6337 | ||
6338 | return 0; | |
6339 | } | |
6340 | ||
6341 | ||
460456f8 JM |
6342 | static void nl80211_remove_monitor_interface( |
6343 | struct wpa_driver_nl80211_data *drv) | |
6344 | { | |
3fd1cefb JB |
6345 | drv->monitor_refcount--; |
6346 | if (drv->monitor_refcount > 0) | |
6347 | return; | |
6348 | ||
460456f8 JM |
6349 | if (drv->monitor_ifidx >= 0) { |
6350 | nl80211_remove_iface(drv, drv->monitor_ifidx); | |
6351 | drv->monitor_ifidx = -1; | |
6352 | } | |
504e905c JM |
6353 | if (drv->monitor_sock >= 0) { |
6354 | eloop_unregister_read_sock(drv->monitor_sock); | |
6355 | close(drv->monitor_sock); | |
6356 | drv->monitor_sock = -1; | |
6357 | } | |
460456f8 JM |
6358 | } |
6359 | ||
6360 | ||
0915d02c JM |
6361 | static int |
6362 | nl80211_create_monitor_interface(struct wpa_driver_nl80211_data *drv) | |
6363 | { | |
6364 | char buf[IFNAMSIZ]; | |
6365 | struct sockaddr_ll ll; | |
6366 | int optval; | |
6367 | socklen_t optlen; | |
0915d02c | 6368 | |
3fd1cefb JB |
6369 | if (drv->monitor_ifidx >= 0) { |
6370 | drv->monitor_refcount++; | |
6371 | return 0; | |
6372 | } | |
6373 | ||
6758b167 JJ |
6374 | if (os_strncmp(drv->first_bss.ifname, "p2p-", 4) == 0) { |
6375 | /* | |
6376 | * P2P interface name is of the format p2p-%s-%d. For monitor | |
6377 | * interface name corresponding to P2P GO, replace "p2p-" with | |
6378 | * "mon-" to retain the same interface name length and to | |
6379 | * indicate that it is a monitor interface. | |
6380 | */ | |
6381 | snprintf(buf, IFNAMSIZ, "mon-%s", drv->first_bss.ifname + 4); | |
6382 | } else { | |
6383 | /* Non-P2P interface with AP functionality. */ | |
6384 | snprintf(buf, IFNAMSIZ, "mon.%s", drv->first_bss.ifname); | |
6385 | } | |
6386 | ||
0915d02c JM |
6387 | buf[IFNAMSIZ - 1] = '\0'; |
6388 | ||
6389 | drv->monitor_ifidx = | |
fbbfcbac FF |
6390 | nl80211_create_iface(drv, buf, NL80211_IFTYPE_MONITOR, NULL, |
6391 | 0); | |
0915d02c | 6392 | |
866af8b6 | 6393 | if (drv->monitor_ifidx == -EOPNOTSUPP) { |
61cbe2ff JB |
6394 | /* |
6395 | * This is backward compatibility for a few versions of | |
6396 | * the kernel only that didn't advertise the right | |
6397 | * attributes for the only driver that then supported | |
6398 | * AP mode w/o monitor -- ath6kl. | |
6399 | */ | |
866af8b6 JM |
6400 | wpa_printf(MSG_DEBUG, "nl80211: Driver does not support " |
6401 | "monitor interface type - try to run without it"); | |
61cbe2ff | 6402 | drv->device_ap_sme = 1; |
866af8b6 JM |
6403 | } |
6404 | ||
0915d02c JM |
6405 | if (drv->monitor_ifidx < 0) |
6406 | return -1; | |
6407 | ||
c81eff1a | 6408 | if (linux_set_iface_flags(drv->global->ioctl_sock, buf, 1)) |
0915d02c | 6409 | goto error; |
0915d02c JM |
6410 | |
6411 | memset(&ll, 0, sizeof(ll)); | |
6412 | ll.sll_family = AF_PACKET; | |
6413 | ll.sll_ifindex = drv->monitor_ifidx; | |
6414 | drv->monitor_sock = socket(PF_PACKET, SOCK_RAW, htons(ETH_P_ALL)); | |
6415 | if (drv->monitor_sock < 0) { | |
6416 | perror("socket[PF_PACKET,SOCK_RAW]"); | |
6417 | goto error; | |
6418 | } | |
6419 | ||
6420 | if (add_monitor_filter(drv->monitor_sock)) { | |
6421 | wpa_printf(MSG_INFO, "Failed to set socket filter for monitor " | |
6422 | "interface; do filtering in user space"); | |
6423 | /* This works, but will cost in performance. */ | |
6424 | } | |
6425 | ||
2135f224 | 6426 | if (bind(drv->monitor_sock, (struct sockaddr *) &ll, sizeof(ll)) < 0) { |
0915d02c JM |
6427 | perror("monitor socket bind"); |
6428 | goto error; | |
6429 | } | |
6430 | ||
6431 | optlen = sizeof(optval); | |
6432 | optval = 20; | |
6433 | if (setsockopt | |
6434 | (drv->monitor_sock, SOL_SOCKET, SO_PRIORITY, &optval, optlen)) { | |
6435 | perror("Failed to set socket priority"); | |
6436 | goto error; | |
6437 | } | |
6438 | ||
6439 | if (eloop_register_read_sock(drv->monitor_sock, handle_monitor_read, | |
6440 | drv, NULL)) { | |
6441 | printf("Could not register monitor read socket\n"); | |
6442 | goto error; | |
6443 | } | |
6444 | ||
6445 | return 0; | |
6446 | error: | |
460456f8 | 6447 | nl80211_remove_monitor_interface(drv); |
0915d02c JM |
6448 | return -1; |
6449 | } | |
6450 | ||
db149ac9 | 6451 | |
3fd1cefb JB |
6452 | static int nl80211_setup_ap(struct i802_bss *bss) |
6453 | { | |
6454 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
6455 | ||
36488c05 JM |
6456 | wpa_printf(MSG_DEBUG, "nl80211: Setup AP - device_ap_sme=%d " |
6457 | "use_monitor=%d", drv->device_ap_sme, drv->use_monitor); | |
6458 | ||
a11241fa JB |
6459 | /* |
6460 | * Disable Probe Request reporting unless we need it in this way for | |
6461 | * devices that include the AP SME, in the other case (unless using | |
6462 | * monitor iface) we'll get it through the nl_mgmt socket instead. | |
6463 | */ | |
6464 | if (!drv->device_ap_sme) | |
6465 | wpa_driver_nl80211_probe_req_report(bss, 0); | |
6466 | ||
6467 | if (!drv->device_ap_sme && !drv->use_monitor) | |
6468 | if (nl80211_mgmt_subscribe_ap(bss)) | |
6469 | return -1; | |
6470 | ||
a6cc0602 JM |
6471 | if (drv->device_ap_sme && !drv->use_monitor) |
6472 | if (nl80211_mgmt_subscribe_ap_dev_sme(bss)) | |
6473 | return -1; | |
6474 | ||
a11241fa | 6475 | if (!drv->device_ap_sme && drv->use_monitor && |
3fd1cefb JB |
6476 | nl80211_create_monitor_interface(drv) && |
6477 | !drv->device_ap_sme) | |
6478 | return -1; | |
6479 | ||
6480 | if (drv->device_ap_sme && | |
6481 | wpa_driver_nl80211_probe_req_report(bss, 1) < 0) { | |
6482 | wpa_printf(MSG_DEBUG, "nl80211: Failed to enable " | |
6483 | "Probe Request frame reporting in AP mode"); | |
6484 | /* Try to survive without this */ | |
6485 | } | |
6486 | ||
6487 | return 0; | |
6488 | } | |
6489 | ||
6490 | ||
6491 | static void nl80211_teardown_ap(struct i802_bss *bss) | |
6492 | { | |
6493 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
6494 | ||
a6cc0602 | 6495 | if (drv->device_ap_sme) { |
3fd1cefb | 6496 | wpa_driver_nl80211_probe_req_report(bss, 0); |
a6cc0602 JM |
6497 | if (!drv->use_monitor) |
6498 | nl80211_mgmt_unsubscribe(bss, "AP teardown (dev SME)"); | |
6499 | } else if (drv->use_monitor) | |
3fd1cefb | 6500 | nl80211_remove_monitor_interface(drv); |
a11241fa | 6501 | else |
36488c05 | 6502 | nl80211_mgmt_unsubscribe(bss, "AP teardown"); |
a11241fa | 6503 | |
3fd1cefb JB |
6504 | bss->beacon_set = 0; |
6505 | } | |
6506 | ||
6507 | ||
f10bfc9a JM |
6508 | static int nl80211_send_eapol_data(struct i802_bss *bss, |
6509 | const u8 *addr, const u8 *data, | |
d12dab4c | 6510 | size_t data_len) |
f10bfc9a | 6511 | { |
d12dab4c JB |
6512 | struct sockaddr_ll ll; |
6513 | int ret; | |
6514 | ||
6515 | if (bss->drv->eapol_tx_sock < 0) { | |
6516 | wpa_printf(MSG_DEBUG, "nl80211: No socket to send EAPOL"); | |
f10bfc9a JM |
6517 | return -1; |
6518 | } | |
6519 | ||
d12dab4c JB |
6520 | os_memset(&ll, 0, sizeof(ll)); |
6521 | ll.sll_family = AF_PACKET; | |
6522 | ll.sll_ifindex = bss->ifindex; | |
6523 | ll.sll_protocol = htons(ETH_P_PAE); | |
6524 | ll.sll_halen = ETH_ALEN; | |
6525 | os_memcpy(ll.sll_addr, addr, ETH_ALEN); | |
6526 | ret = sendto(bss->drv->eapol_tx_sock, data, data_len, 0, | |
6527 | (struct sockaddr *) &ll, sizeof(ll)); | |
6528 | if (ret < 0) | |
6529 | wpa_printf(MSG_ERROR, "nl80211: EAPOL TX: %s", | |
6530 | strerror(errno)); | |
6531 | ||
6532 | return ret; | |
f10bfc9a | 6533 | } |
5fb1a232 | 6534 | |
f10bfc9a | 6535 | |
db149ac9 JM |
6536 | static const u8 rfc1042_header[6] = { 0xaa, 0xaa, 0x03, 0x00, 0x00, 0x00 }; |
6537 | ||
6538 | static int wpa_driver_nl80211_hapd_send_eapol( | |
6539 | void *priv, const u8 *addr, const u8 *data, | |
4378fc14 | 6540 | size_t data_len, int encrypt, const u8 *own_addr, u32 flags) |
db149ac9 | 6541 | { |
a2e40bb6 FF |
6542 | struct i802_bss *bss = priv; |
6543 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
db149ac9 JM |
6544 | struct ieee80211_hdr *hdr; |
6545 | size_t len; | |
6546 | u8 *pos; | |
6547 | int res; | |
4378fc14 | 6548 | int qos = flags & WPA_STA_WMM; |
db149ac9 | 6549 | |
a11241fa | 6550 | if (drv->device_ap_sme || !drv->use_monitor) |
d12dab4c | 6551 | return nl80211_send_eapol_data(bss, addr, data, data_len); |
f10bfc9a | 6552 | |
db149ac9 JM |
6553 | len = sizeof(*hdr) + (qos ? 2 : 0) + sizeof(rfc1042_header) + 2 + |
6554 | data_len; | |
6555 | hdr = os_zalloc(len); | |
6556 | if (hdr == NULL) { | |
6557 | printf("malloc() failed for i802_send_data(len=%lu)\n", | |
6558 | (unsigned long) len); | |
6559 | return -1; | |
6560 | } | |
6561 | ||
6562 | hdr->frame_control = | |
6563 | IEEE80211_FC(WLAN_FC_TYPE_DATA, WLAN_FC_STYPE_DATA); | |
6564 | hdr->frame_control |= host_to_le16(WLAN_FC_FROMDS); | |
6565 | if (encrypt) | |
6566 | hdr->frame_control |= host_to_le16(WLAN_FC_ISWEP); | |
db149ac9 JM |
6567 | if (qos) { |
6568 | hdr->frame_control |= | |
6569 | host_to_le16(WLAN_FC_STYPE_QOS_DATA << 4); | |
6570 | } | |
db149ac9 JM |
6571 | |
6572 | memcpy(hdr->IEEE80211_DA_FROMDS, addr, ETH_ALEN); | |
6573 | memcpy(hdr->IEEE80211_BSSID_FROMDS, own_addr, ETH_ALEN); | |
6574 | memcpy(hdr->IEEE80211_SA_FROMDS, own_addr, ETH_ALEN); | |
6575 | pos = (u8 *) (hdr + 1); | |
6576 | ||
db149ac9 | 6577 | if (qos) { |
92d521d8 FF |
6578 | /* Set highest priority in QoS header */ |
6579 | pos[0] = 7; | |
db149ac9 JM |
6580 | pos[1] = 0; |
6581 | pos += 2; | |
6582 | } | |
db149ac9 JM |
6583 | |
6584 | memcpy(pos, rfc1042_header, sizeof(rfc1042_header)); | |
6585 | pos += sizeof(rfc1042_header); | |
6586 | WPA_PUT_BE16(pos, ETH_P_PAE); | |
6587 | pos += 2; | |
6588 | memcpy(pos, data, data_len); | |
6589 | ||
55231068 JM |
6590 | res = wpa_driver_nl80211_send_frame(bss, (u8 *) hdr, len, encrypt, 0, |
6591 | 0, 0, 0, 0); | |
db149ac9 JM |
6592 | if (res < 0) { |
6593 | wpa_printf(MSG_ERROR, "i802_send_eapol - packet len: %lu - " | |
6594 | "failed: %d (%s)", | |
6595 | (unsigned long) len, errno, strerror(errno)); | |
6596 | } | |
7bf12757 | 6597 | os_free(hdr); |
db149ac9 JM |
6598 | |
6599 | return res; | |
6600 | } | |
6601 | ||
a8d6ffa4 | 6602 | |
3234cba4 JM |
6603 | static int wpa_driver_nl80211_sta_set_flags(void *priv, const u8 *addr, |
6604 | int total_flags, | |
4c32757d | 6605 | int flags_or, int flags_and) |
a8d6ffa4 | 6606 | { |
a2e40bb6 FF |
6607 | struct i802_bss *bss = priv; |
6608 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
a8d6ffa4 | 6609 | struct nl_msg *msg, *flags = NULL; |
7e76ee9c | 6610 | struct nl80211_sta_flag_update upd; |
a8d6ffa4 JM |
6611 | |
6612 | msg = nlmsg_alloc(); | |
6613 | if (!msg) | |
6614 | return -ENOMEM; | |
6615 | ||
6616 | flags = nlmsg_alloc(); | |
6617 | if (!flags) { | |
6618 | nlmsg_free(msg); | |
6619 | return -ENOMEM; | |
6620 | } | |
6621 | ||
9fb04070 | 6622 | nl80211_cmd(drv, msg, 0, NL80211_CMD_SET_STATION); |
a8d6ffa4 JM |
6623 | |
6624 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, | |
3234cba4 | 6625 | if_nametoindex(bss->ifname)); |
a8d6ffa4 JM |
6626 | NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, addr); |
6627 | ||
7e76ee9c JM |
6628 | /* |
6629 | * Backwards compatibility version using NL80211_ATTR_STA_FLAGS. This | |
6630 | * can be removed eventually. | |
6631 | */ | |
0de39516 | 6632 | if (total_flags & WPA_STA_AUTHORIZED) |
a8d6ffa4 JM |
6633 | NLA_PUT_FLAG(flags, NL80211_STA_FLAG_AUTHORIZED); |
6634 | ||
0de39516 | 6635 | if (total_flags & WPA_STA_WMM) |
a8d6ffa4 JM |
6636 | NLA_PUT_FLAG(flags, NL80211_STA_FLAG_WME); |
6637 | ||
0de39516 | 6638 | if (total_flags & WPA_STA_SHORT_PREAMBLE) |
a8d6ffa4 JM |
6639 | NLA_PUT_FLAG(flags, NL80211_STA_FLAG_SHORT_PREAMBLE); |
6640 | ||
0de39516 | 6641 | if (total_flags & WPA_STA_MFP) |
a8d6ffa4 JM |
6642 | NLA_PUT_FLAG(flags, NL80211_STA_FLAG_MFP); |
6643 | ||
45b722f1 AN |
6644 | if (total_flags & WPA_STA_TDLS_PEER) |
6645 | NLA_PUT_FLAG(flags, NL80211_STA_FLAG_TDLS_PEER); | |
6646 | ||
a8d6ffa4 JM |
6647 | if (nla_put_nested(msg, NL80211_ATTR_STA_FLAGS, flags)) |
6648 | goto nla_put_failure; | |
6649 | ||
7e76ee9c JM |
6650 | os_memset(&upd, 0, sizeof(upd)); |
6651 | upd.mask = sta_flags_nl80211(flags_or | ~flags_and); | |
6652 | upd.set = sta_flags_nl80211(flags_or); | |
6653 | NLA_PUT(msg, NL80211_ATTR_STA_FLAGS2, sizeof(upd), &upd); | |
6654 | ||
a8d6ffa4 JM |
6655 | nlmsg_free(flags); |
6656 | ||
6657 | return send_and_recv_msgs(drv, msg, NULL, NULL); | |
6658 | nla_put_failure: | |
5883168a | 6659 | nlmsg_free(msg); |
a8d6ffa4 JM |
6660 | nlmsg_free(flags); |
6661 | return -ENOBUFS; | |
6662 | } | |
6663 | ||
0915d02c | 6664 | |
1581b38b JM |
6665 | static int wpa_driver_nl80211_ap(struct wpa_driver_nl80211_data *drv, |
6666 | struct wpa_driver_associate_params *params) | |
6667 | { | |
708bc8e0 | 6668 | enum nl80211_iftype nlmode, old_mode; |
89b800d7 JB |
6669 | struct hostapd_freq_params freq = { |
6670 | .freq = params->freq, | |
6671 | }; | |
b1f625e0 EP |
6672 | |
6673 | if (params->p2p) { | |
046b26a2 JM |
6674 | wpa_printf(MSG_DEBUG, "nl80211: Setup AP operations for P2P " |
6675 | "group (GO)"); | |
b1f625e0 EP |
6676 | nlmode = NL80211_IFTYPE_P2P_GO; |
6677 | } else | |
6678 | nlmode = NL80211_IFTYPE_AP; | |
6679 | ||
708bc8e0 JM |
6680 | old_mode = drv->nlmode; |
6681 | if (wpa_driver_nl80211_set_mode(&drv->first_bss, nlmode)) { | |
6682 | nl80211_remove_monitor_interface(drv); | |
6683 | return -1; | |
6684 | } | |
6685 | ||
89b800d7 | 6686 | if (wpa_driver_nl80211_set_freq(&drv->first_bss, &freq)) { |
708bc8e0 JM |
6687 | if (old_mode != nlmode) |
6688 | wpa_driver_nl80211_set_mode(&drv->first_bss, old_mode); | |
460456f8 | 6689 | nl80211_remove_monitor_interface(drv); |
1581b38b | 6690 | return -1; |
0915d02c | 6691 | } |
1581b38b | 6692 | |
1581b38b JM |
6693 | return 0; |
6694 | } | |
1581b38b JM |
6695 | |
6696 | ||
5cc4d64b JM |
6697 | static int nl80211_leave_ibss(struct wpa_driver_nl80211_data *drv) |
6698 | { | |
6699 | struct nl_msg *msg; | |
6700 | int ret = -1; | |
6701 | ||
6702 | msg = nlmsg_alloc(); | |
6703 | if (!msg) | |
6704 | return -1; | |
6705 | ||
9fb04070 | 6706 | nl80211_cmd(drv, msg, 0, NL80211_CMD_LEAVE_IBSS); |
5cc4d64b JM |
6707 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, drv->ifindex); |
6708 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); | |
6709 | msg = NULL; | |
6710 | if (ret) { | |
6711 | wpa_printf(MSG_DEBUG, "nl80211: Leave IBSS failed: ret=%d " | |
6712 | "(%s)", ret, strerror(-ret)); | |
6713 | goto nla_put_failure; | |
6714 | } | |
6715 | ||
6716 | ret = 0; | |
6717 | wpa_printf(MSG_DEBUG, "nl80211: Leave IBSS request sent successfully"); | |
6718 | ||
6719 | nla_put_failure: | |
6720 | nlmsg_free(msg); | |
6721 | return ret; | |
6722 | } | |
6723 | ||
6724 | ||
6725 | static int wpa_driver_nl80211_ibss(struct wpa_driver_nl80211_data *drv, | |
6726 | struct wpa_driver_associate_params *params) | |
6727 | { | |
6728 | struct nl_msg *msg; | |
6729 | int ret = -1; | |
6730 | int count = 0; | |
6731 | ||
6732 | wpa_printf(MSG_DEBUG, "nl80211: Join IBSS (ifindex=%d)", drv->ifindex); | |
6733 | ||
b1f625e0 EP |
6734 | if (wpa_driver_nl80211_set_mode(&drv->first_bss, |
6735 | NL80211_IFTYPE_ADHOC)) { | |
5cc4d64b JM |
6736 | wpa_printf(MSG_INFO, "nl80211: Failed to set interface into " |
6737 | "IBSS mode"); | |
6738 | return -1; | |
6739 | } | |
6740 | ||
6741 | retry: | |
6742 | msg = nlmsg_alloc(); | |
6743 | if (!msg) | |
6744 | return -1; | |
6745 | ||
9fb04070 | 6746 | nl80211_cmd(drv, msg, 0, NL80211_CMD_JOIN_IBSS); |
5cc4d64b JM |
6747 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, drv->ifindex); |
6748 | ||
6749 | if (params->ssid == NULL || params->ssid_len > sizeof(drv->ssid)) | |
6750 | goto nla_put_failure; | |
6751 | ||
6752 | wpa_hexdump_ascii(MSG_DEBUG, " * SSID", | |
6753 | params->ssid, params->ssid_len); | |
6754 | NLA_PUT(msg, NL80211_ATTR_SSID, params->ssid_len, | |
6755 | params->ssid); | |
6756 | os_memcpy(drv->ssid, params->ssid, params->ssid_len); | |
6757 | drv->ssid_len = params->ssid_len; | |
6758 | ||
6759 | wpa_printf(MSG_DEBUG, " * freq=%d", params->freq); | |
6760 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_FREQ, params->freq); | |
6761 | ||
6762 | ret = nl80211_set_conn_keys(params, msg); | |
6763 | if (ret) | |
6764 | goto nla_put_failure; | |
6765 | ||
913e3cf7 NC |
6766 | if (params->bssid && params->fixed_bssid) { |
6767 | wpa_printf(MSG_DEBUG, " * BSSID=" MACSTR, | |
6768 | MAC2STR(params->bssid)); | |
6769 | NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, params->bssid); | |
6770 | } | |
6771 | ||
e640888c AQ |
6772 | if (params->key_mgmt_suite == KEY_MGMT_802_1X || |
6773 | params->key_mgmt_suite == KEY_MGMT_PSK || | |
6774 | params->key_mgmt_suite == KEY_MGMT_802_1X_SHA256 || | |
6775 | params->key_mgmt_suite == KEY_MGMT_PSK_SHA256) { | |
6776 | wpa_printf(MSG_DEBUG, " * control port"); | |
6777 | NLA_PUT_FLAG(msg, NL80211_ATTR_CONTROL_PORT); | |
6778 | } | |
6779 | ||
a95795ad JM |
6780 | if (params->wpa_ie) { |
6781 | wpa_hexdump(MSG_DEBUG, | |
6782 | " * Extra IEs for Beacon/Probe Response frames", | |
6783 | params->wpa_ie, params->wpa_ie_len); | |
6784 | NLA_PUT(msg, NL80211_ATTR_IE, params->wpa_ie_len, | |
6785 | params->wpa_ie); | |
6786 | } | |
6787 | ||
5cc4d64b JM |
6788 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
6789 | msg = NULL; | |
6790 | if (ret) { | |
6791 | wpa_printf(MSG_DEBUG, "nl80211: Join IBSS failed: ret=%d (%s)", | |
6792 | ret, strerror(-ret)); | |
6793 | count++; | |
6794 | if (ret == -EALREADY && count == 1) { | |
6795 | wpa_printf(MSG_DEBUG, "nl80211: Retry IBSS join after " | |
6796 | "forced leave"); | |
6797 | nl80211_leave_ibss(drv); | |
6798 | nlmsg_free(msg); | |
6799 | goto retry; | |
6800 | } | |
6801 | ||
6802 | goto nla_put_failure; | |
6803 | } | |
6804 | ret = 0; | |
6805 | wpa_printf(MSG_DEBUG, "nl80211: Join IBSS request sent successfully"); | |
6806 | ||
6807 | nla_put_failure: | |
6808 | nlmsg_free(msg); | |
6809 | return ret; | |
6810 | } | |
6811 | ||
6812 | ||
a8c5b43a | 6813 | static int wpa_driver_nl80211_try_connect( |
cfaab580 ZY |
6814 | struct wpa_driver_nl80211_data *drv, |
6815 | struct wpa_driver_associate_params *params) | |
6816 | { | |
6817 | struct nl_msg *msg; | |
6818 | enum nl80211_auth_type type; | |
6819 | int ret = 0; | |
3f360238 | 6820 | int algs; |
cfaab580 ZY |
6821 | |
6822 | msg = nlmsg_alloc(); | |
6823 | if (!msg) | |
6824 | return -1; | |
6825 | ||
6826 | wpa_printf(MSG_DEBUG, "nl80211: Connect (ifindex=%d)", drv->ifindex); | |
9fb04070 | 6827 | nl80211_cmd(drv, msg, 0, NL80211_CMD_CONNECT); |
cfaab580 ZY |
6828 | |
6829 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, drv->ifindex); | |
6830 | if (params->bssid) { | |
6831 | wpa_printf(MSG_DEBUG, " * bssid=" MACSTR, | |
6832 | MAC2STR(params->bssid)); | |
6833 | NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, params->bssid); | |
6834 | } | |
6835 | if (params->freq) { | |
6836 | wpa_printf(MSG_DEBUG, " * freq=%d", params->freq); | |
6837 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_FREQ, params->freq); | |
6838 | } | |
1f6c0ab8 BS |
6839 | if (params->bg_scan_period >= 0) { |
6840 | wpa_printf(MSG_DEBUG, " * bg scan period=%d", | |
6841 | params->bg_scan_period); | |
6842 | NLA_PUT_U16(msg, NL80211_ATTR_BG_SCAN_PERIOD, | |
6843 | params->bg_scan_period); | |
6844 | } | |
cfaab580 ZY |
6845 | if (params->ssid) { |
6846 | wpa_hexdump_ascii(MSG_DEBUG, " * SSID", | |
6847 | params->ssid, params->ssid_len); | |
6848 | NLA_PUT(msg, NL80211_ATTR_SSID, params->ssid_len, | |
6849 | params->ssid); | |
6850 | if (params->ssid_len > sizeof(drv->ssid)) | |
6851 | goto nla_put_failure; | |
6852 | os_memcpy(drv->ssid, params->ssid, params->ssid_len); | |
6853 | drv->ssid_len = params->ssid_len; | |
6854 | } | |
6855 | wpa_hexdump(MSG_DEBUG, " * IEs", params->wpa_ie, params->wpa_ie_len); | |
6856 | if (params->wpa_ie) | |
6857 | NLA_PUT(msg, NL80211_ATTR_IE, params->wpa_ie_len, | |
6858 | params->wpa_ie); | |
6859 | ||
3f360238 JM |
6860 | algs = 0; |
6861 | if (params->auth_alg & WPA_AUTH_ALG_OPEN) | |
6862 | algs++; | |
6863 | if (params->auth_alg & WPA_AUTH_ALG_SHARED) | |
6864 | algs++; | |
6865 | if (params->auth_alg & WPA_AUTH_ALG_LEAP) | |
6866 | algs++; | |
6867 | if (algs > 1) { | |
6868 | wpa_printf(MSG_DEBUG, " * Leave out Auth Type for automatic " | |
6869 | "selection"); | |
6870 | goto skip_auth_type; | |
6871 | } | |
6872 | ||
abd9fafa | 6873 | if (params->auth_alg & WPA_AUTH_ALG_OPEN) |
cfaab580 | 6874 | type = NL80211_AUTHTYPE_OPEN_SYSTEM; |
abd9fafa | 6875 | else if (params->auth_alg & WPA_AUTH_ALG_SHARED) |
cfaab580 | 6876 | type = NL80211_AUTHTYPE_SHARED_KEY; |
abd9fafa | 6877 | else if (params->auth_alg & WPA_AUTH_ALG_LEAP) |
cfaab580 | 6878 | type = NL80211_AUTHTYPE_NETWORK_EAP; |
abd9fafa | 6879 | else if (params->auth_alg & WPA_AUTH_ALG_FT) |
cfaab580 ZY |
6880 | type = NL80211_AUTHTYPE_FT; |
6881 | else | |
6882 | goto nla_put_failure; | |
6883 | ||
6884 | wpa_printf(MSG_DEBUG, " * Auth Type %d", type); | |
6885 | NLA_PUT_U32(msg, NL80211_ATTR_AUTH_TYPE, type); | |
6886 | ||
3f360238 | 6887 | skip_auth_type: |
64fa840a JM |
6888 | if (params->wpa_proto) { |
6889 | enum nl80211_wpa_versions ver = 0; | |
cfaab580 | 6890 | |
64fa840a JM |
6891 | if (params->wpa_proto & WPA_PROTO_WPA) |
6892 | ver |= NL80211_WPA_VERSION_1; | |
6893 | if (params->wpa_proto & WPA_PROTO_RSN) | |
6894 | ver |= NL80211_WPA_VERSION_2; | |
cfaab580 | 6895 | |
64fa840a | 6896 | wpa_printf(MSG_DEBUG, " * WPA Versions 0x%x", ver); |
cfaab580 ZY |
6897 | NLA_PUT_U32(msg, NL80211_ATTR_WPA_VERSIONS, ver); |
6898 | } | |
6899 | ||
6900 | if (params->pairwise_suite != CIPHER_NONE) { | |
c1bb3e0a | 6901 | int cipher; |
cfaab580 ZY |
6902 | |
6903 | switch (params->pairwise_suite) { | |
369c8d7b JM |
6904 | case CIPHER_SMS4: |
6905 | cipher = WLAN_CIPHER_SUITE_SMS4; | |
6906 | break; | |
cfaab580 ZY |
6907 | case CIPHER_WEP40: |
6908 | cipher = WLAN_CIPHER_SUITE_WEP40; | |
6909 | break; | |
6910 | case CIPHER_WEP104: | |
6911 | cipher = WLAN_CIPHER_SUITE_WEP104; | |
6912 | break; | |
6913 | case CIPHER_CCMP: | |
6914 | cipher = WLAN_CIPHER_SUITE_CCMP; | |
6915 | break; | |
eb7719ff JM |
6916 | case CIPHER_GCMP: |
6917 | cipher = WLAN_CIPHER_SUITE_GCMP; | |
6918 | break; | |
cfaab580 ZY |
6919 | case CIPHER_TKIP: |
6920 | default: | |
6921 | cipher = WLAN_CIPHER_SUITE_TKIP; | |
6922 | break; | |
6923 | } | |
6924 | NLA_PUT_U32(msg, NL80211_ATTR_CIPHER_SUITES_PAIRWISE, cipher); | |
6925 | } | |
6926 | ||
6927 | if (params->group_suite != CIPHER_NONE) { | |
c1bb3e0a | 6928 | int cipher; |
cfaab580 ZY |
6929 | |
6930 | switch (params->group_suite) { | |
369c8d7b JM |
6931 | case CIPHER_SMS4: |
6932 | cipher = WLAN_CIPHER_SUITE_SMS4; | |
6933 | break; | |
cfaab580 ZY |
6934 | case CIPHER_WEP40: |
6935 | cipher = WLAN_CIPHER_SUITE_WEP40; | |
6936 | break; | |
6937 | case CIPHER_WEP104: | |
6938 | cipher = WLAN_CIPHER_SUITE_WEP104; | |
6939 | break; | |
6940 | case CIPHER_CCMP: | |
6941 | cipher = WLAN_CIPHER_SUITE_CCMP; | |
6942 | break; | |
eb7719ff JM |
6943 | case CIPHER_GCMP: |
6944 | cipher = WLAN_CIPHER_SUITE_GCMP; | |
6945 | break; | |
cfaab580 ZY |
6946 | case CIPHER_TKIP: |
6947 | default: | |
6948 | cipher = WLAN_CIPHER_SUITE_TKIP; | |
6949 | break; | |
6950 | } | |
6951 | NLA_PUT_U32(msg, NL80211_ATTR_CIPHER_SUITE_GROUP, cipher); | |
6952 | } | |
6953 | ||
6954 | if (params->key_mgmt_suite == KEY_MGMT_802_1X || | |
369c8d7b JM |
6955 | params->key_mgmt_suite == KEY_MGMT_PSK || |
6956 | params->key_mgmt_suite == KEY_MGMT_CCKM) { | |
cfaab580 ZY |
6957 | int mgmt = WLAN_AKM_SUITE_PSK; |
6958 | ||
6959 | switch (params->key_mgmt_suite) { | |
369c8d7b JM |
6960 | case KEY_MGMT_CCKM: |
6961 | mgmt = WLAN_AKM_SUITE_CCKM; | |
6962 | break; | |
cfaab580 ZY |
6963 | case KEY_MGMT_802_1X: |
6964 | mgmt = WLAN_AKM_SUITE_8021X; | |
6965 | break; | |
6966 | case KEY_MGMT_PSK: | |
6967 | default: | |
6968 | mgmt = WLAN_AKM_SUITE_PSK; | |
6969 | break; | |
6970 | } | |
6971 | NLA_PUT_U32(msg, NL80211_ATTR_AKM_SUITES, mgmt); | |
6972 | } | |
6973 | ||
8b706a99 JM |
6974 | #ifdef CONFIG_IEEE80211W |
6975 | if (params->mgmt_frame_protection == MGMT_FRAME_PROTECTION_REQUIRED) | |
6976 | NLA_PUT_U32(msg, NL80211_ATTR_USE_MFP, NL80211_MFP_REQUIRED); | |
6977 | #endif /* CONFIG_IEEE80211W */ | |
6978 | ||
80e8a5ee BG |
6979 | if (params->disable_ht) |
6980 | NLA_PUT_FLAG(msg, NL80211_ATTR_DISABLE_HT); | |
6981 | ||
6982 | if (params->htcaps && params->htcaps_mask) { | |
6983 | int sz = sizeof(struct ieee80211_ht_capabilities); | |
6984 | NLA_PUT(msg, NL80211_ATTR_HT_CAPABILITY, sz, params->htcaps); | |
6985 | NLA_PUT(msg, NL80211_ATTR_HT_CAPABILITY_MASK, sz, | |
6986 | params->htcaps_mask); | |
6987 | } | |
6988 | ||
cfaab580 ZY |
6989 | ret = nl80211_set_conn_keys(params, msg); |
6990 | if (ret) | |
6991 | goto nla_put_failure; | |
6992 | ||
6993 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); | |
6994 | msg = NULL; | |
6995 | if (ret) { | |
6996 | wpa_printf(MSG_DEBUG, "nl80211: MLME connect failed: ret=%d " | |
6997 | "(%s)", ret, strerror(-ret)); | |
6998 | goto nla_put_failure; | |
6999 | } | |
7000 | ret = 0; | |
7001 | wpa_printf(MSG_DEBUG, "nl80211: Connect request send successfully"); | |
7002 | ||
7003 | nla_put_failure: | |
7004 | nlmsg_free(msg); | |
7005 | return ret; | |
7006 | ||
7007 | } | |
7008 | ||
7009 | ||
a8c5b43a CW |
7010 | static int wpa_driver_nl80211_connect( |
7011 | struct wpa_driver_nl80211_data *drv, | |
7012 | struct wpa_driver_associate_params *params) | |
7013 | { | |
7014 | int ret = wpa_driver_nl80211_try_connect(drv, params); | |
7015 | if (ret == -EALREADY) { | |
7016 | /* | |
7017 | * cfg80211 does not currently accept new connections if | |
7018 | * we are already connected. As a workaround, force | |
7019 | * disconnection and try again. | |
7020 | */ | |
7021 | wpa_printf(MSG_DEBUG, "nl80211: Explicitly " | |
7022 | "disconnecting before reassociation " | |
7023 | "attempt"); | |
7024 | if (wpa_driver_nl80211_disconnect( | |
7025 | drv, WLAN_REASON_PREV_AUTH_NOT_VALID)) | |
7026 | return -1; | |
7027 | /* Ignore the next local disconnect message. */ | |
7028 | drv->ignore_next_local_disconnect = 1; | |
7029 | ret = wpa_driver_nl80211_try_connect(drv, params); | |
7030 | } | |
7031 | return ret; | |
7032 | } | |
7033 | ||
7034 | ||
c2a04078 JM |
7035 | static int wpa_driver_nl80211_associate( |
7036 | void *priv, struct wpa_driver_associate_params *params) | |
7037 | { | |
a2e40bb6 FF |
7038 | struct i802_bss *bss = priv; |
7039 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
c2a04078 JM |
7040 | int ret = -1; |
7041 | struct nl_msg *msg; | |
7042 | ||
5cc4d64b | 7043 | if (params->mode == IEEE80211_MODE_AP) |
1581b38b | 7044 | return wpa_driver_nl80211_ap(drv, params); |
1581b38b | 7045 | |
5cc4d64b JM |
7046 | if (params->mode == IEEE80211_MODE_IBSS) |
7047 | return wpa_driver_nl80211_ibss(drv, params); | |
7048 | ||
4a867032 | 7049 | if (!(drv->capa.flags & WPA_DRIVER_FLAGS_SME)) { |
b1f625e0 EP |
7050 | enum nl80211_iftype nlmode = params->p2p ? |
7051 | NL80211_IFTYPE_P2P_CLIENT : NL80211_IFTYPE_STATION; | |
7052 | ||
7053 | if (wpa_driver_nl80211_set_mode(priv, nlmode) < 0) | |
4a867032 | 7054 | return -1; |
cfaab580 | 7055 | return wpa_driver_nl80211_connect(drv, params); |
4a867032 | 7056 | } |
cfaab580 | 7057 | |
c2a04078 JM |
7058 | drv->associated = 0; |
7059 | ||
7060 | msg = nlmsg_alloc(); | |
7061 | if (!msg) | |
7062 | return -1; | |
7063 | ||
7064 | wpa_printf(MSG_DEBUG, "nl80211: Associate (ifindex=%d)", | |
7065 | drv->ifindex); | |
9fb04070 | 7066 | nl80211_cmd(drv, msg, 0, NL80211_CMD_ASSOCIATE); |
c2a04078 JM |
7067 | |
7068 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, drv->ifindex); | |
7069 | if (params->bssid) { | |
7070 | wpa_printf(MSG_DEBUG, " * bssid=" MACSTR, | |
7071 | MAC2STR(params->bssid)); | |
7072 | NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, params->bssid); | |
7073 | } | |
7074 | if (params->freq) { | |
7075 | wpa_printf(MSG_DEBUG, " * freq=%d", params->freq); | |
7076 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_FREQ, params->freq); | |
4832ecd7 JM |
7077 | drv->assoc_freq = params->freq; |
7078 | } else | |
7079 | drv->assoc_freq = 0; | |
1f6c0ab8 BS |
7080 | if (params->bg_scan_period >= 0) { |
7081 | wpa_printf(MSG_DEBUG, " * bg scan period=%d", | |
7082 | params->bg_scan_period); | |
7083 | NLA_PUT_U16(msg, NL80211_ATTR_BG_SCAN_PERIOD, | |
7084 | params->bg_scan_period); | |
7085 | } | |
c2a04078 JM |
7086 | if (params->ssid) { |
7087 | wpa_hexdump_ascii(MSG_DEBUG, " * SSID", | |
7088 | params->ssid, params->ssid_len); | |
7089 | NLA_PUT(msg, NL80211_ATTR_SSID, params->ssid_len, | |
7090 | params->ssid); | |
fd05d64e JM |
7091 | if (params->ssid_len > sizeof(drv->ssid)) |
7092 | goto nla_put_failure; | |
7093 | os_memcpy(drv->ssid, params->ssid, params->ssid_len); | |
7094 | drv->ssid_len = params->ssid_len; | |
c2a04078 JM |
7095 | } |
7096 | wpa_hexdump(MSG_DEBUG, " * IEs", params->wpa_ie, params->wpa_ie_len); | |
7097 | if (params->wpa_ie) | |
7098 | NLA_PUT(msg, NL80211_ATTR_IE, params->wpa_ie_len, | |
7099 | params->wpa_ie); | |
7100 | ||
aca01605 JM |
7101 | if (params->pairwise_suite != CIPHER_NONE) { |
7102 | int cipher; | |
7103 | ||
7104 | switch (params->pairwise_suite) { | |
7105 | case CIPHER_WEP40: | |
7106 | cipher = WLAN_CIPHER_SUITE_WEP40; | |
7107 | break; | |
7108 | case CIPHER_WEP104: | |
7109 | cipher = WLAN_CIPHER_SUITE_WEP104; | |
7110 | break; | |
7111 | case CIPHER_CCMP: | |
7112 | cipher = WLAN_CIPHER_SUITE_CCMP; | |
7113 | break; | |
eb7719ff JM |
7114 | case CIPHER_GCMP: |
7115 | cipher = WLAN_CIPHER_SUITE_GCMP; | |
7116 | break; | |
aca01605 JM |
7117 | case CIPHER_TKIP: |
7118 | default: | |
7119 | cipher = WLAN_CIPHER_SUITE_TKIP; | |
7120 | break; | |
7121 | } | |
79c3124c | 7122 | wpa_printf(MSG_DEBUG, " * pairwise=0x%x", cipher); |
aca01605 JM |
7123 | NLA_PUT_U32(msg, NL80211_ATTR_CIPHER_SUITES_PAIRWISE, cipher); |
7124 | } | |
7125 | ||
7126 | if (params->group_suite != CIPHER_NONE) { | |
7127 | int cipher; | |
7128 | ||
7129 | switch (params->group_suite) { | |
7130 | case CIPHER_WEP40: | |
7131 | cipher = WLAN_CIPHER_SUITE_WEP40; | |
7132 | break; | |
7133 | case CIPHER_WEP104: | |
7134 | cipher = WLAN_CIPHER_SUITE_WEP104; | |
7135 | break; | |
7136 | case CIPHER_CCMP: | |
7137 | cipher = WLAN_CIPHER_SUITE_CCMP; | |
7138 | break; | |
eb7719ff JM |
7139 | case CIPHER_GCMP: |
7140 | cipher = WLAN_CIPHER_SUITE_GCMP; | |
7141 | break; | |
aca01605 JM |
7142 | case CIPHER_TKIP: |
7143 | default: | |
7144 | cipher = WLAN_CIPHER_SUITE_TKIP; | |
7145 | break; | |
7146 | } | |
79c3124c | 7147 | wpa_printf(MSG_DEBUG, " * group=0x%x", cipher); |
aca01605 JM |
7148 | NLA_PUT_U32(msg, NL80211_ATTR_CIPHER_SUITE_GROUP, cipher); |
7149 | } | |
7150 | ||
e572fa33 JM |
7151 | #ifdef CONFIG_IEEE80211W |
7152 | if (params->mgmt_frame_protection == MGMT_FRAME_PROTECTION_REQUIRED) | |
7153 | NLA_PUT_U32(msg, NL80211_ATTR_USE_MFP, NL80211_MFP_REQUIRED); | |
7154 | #endif /* CONFIG_IEEE80211W */ | |
7155 | ||
01652550 JM |
7156 | NLA_PUT_FLAG(msg, NL80211_ATTR_CONTROL_PORT); |
7157 | ||
62fa124c JM |
7158 | if (params->prev_bssid) { |
7159 | wpa_printf(MSG_DEBUG, " * prev_bssid=" MACSTR, | |
7160 | MAC2STR(params->prev_bssid)); | |
7161 | NLA_PUT(msg, NL80211_ATTR_PREV_BSSID, ETH_ALEN, | |
7162 | params->prev_bssid); | |
7163 | } | |
7164 | ||
80e8a5ee BG |
7165 | if (params->disable_ht) |
7166 | NLA_PUT_FLAG(msg, NL80211_ATTR_DISABLE_HT); | |
7167 | ||
7168 | if (params->htcaps && params->htcaps_mask) { | |
7169 | int sz = sizeof(struct ieee80211_ht_capabilities); | |
7170 | NLA_PUT(msg, NL80211_ATTR_HT_CAPABILITY, sz, params->htcaps); | |
7171 | NLA_PUT(msg, NL80211_ATTR_HT_CAPABILITY_MASK, sz, | |
7172 | params->htcaps_mask); | |
7173 | } | |
7174 | ||
046b26a2 JM |
7175 | if (params->p2p) |
7176 | wpa_printf(MSG_DEBUG, " * P2P group"); | |
7177 | ||
c2a04078 JM |
7178 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
7179 | msg = NULL; | |
7180 | if (ret) { | |
3b7ea880 BG |
7181 | wpa_dbg(drv->ctx, MSG_DEBUG, |
7182 | "nl80211: MLME command failed (assoc): ret=%d (%s)", | |
7183 | ret, strerror(-ret)); | |
8856462d | 7184 | nl80211_dump_scan(drv); |
c2a04078 JM |
7185 | goto nla_put_failure; |
7186 | } | |
7187 | ret = 0; | |
7188 | wpa_printf(MSG_DEBUG, "nl80211: Association request send " | |
7189 | "successfully"); | |
7190 | ||
7191 | nla_put_failure: | |
7192 | nlmsg_free(msg); | |
7193 | return ret; | |
7194 | } | |
3f5285e8 JM |
7195 | |
7196 | ||
ad1e68e6 | 7197 | static int nl80211_set_mode(struct wpa_driver_nl80211_data *drv, |
a1922f93 | 7198 | int ifindex, enum nl80211_iftype mode) |
3f5285e8 | 7199 | { |
3f5285e8 | 7200 | struct nl_msg *msg; |
ad1e68e6 JM |
7201 | int ret = -ENOBUFS; |
7202 | ||
a1922f93 JM |
7203 | wpa_printf(MSG_DEBUG, "nl80211: Set mode ifindex %d iftype %d (%s)", |
7204 | ifindex, mode, nl80211_iftype_str(mode)); | |
7205 | ||
ad1e68e6 JM |
7206 | msg = nlmsg_alloc(); |
7207 | if (!msg) | |
7208 | return -ENOMEM; | |
7209 | ||
9fb04070 | 7210 | nl80211_cmd(drv, msg, 0, NL80211_CMD_SET_INTERFACE); |
ad1e68e6 JM |
7211 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, ifindex); |
7212 | NLA_PUT_U32(msg, NL80211_ATTR_IFTYPE, mode); | |
7213 | ||
7214 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); | |
5883168a | 7215 | msg = NULL; |
ad1e68e6 JM |
7216 | if (!ret) |
7217 | return 0; | |
7218 | nla_put_failure: | |
5883168a | 7219 | nlmsg_free(msg); |
ad1e68e6 JM |
7220 | wpa_printf(MSG_DEBUG, "nl80211: Failed to set interface %d to mode %d:" |
7221 | " %d (%s)", ifindex, mode, ret, strerror(-ret)); | |
7222 | return ret; | |
7223 | } | |
7224 | ||
7225 | ||
b1f625e0 EP |
7226 | static int wpa_driver_nl80211_set_mode(struct i802_bss *bss, |
7227 | enum nl80211_iftype nlmode) | |
ad1e68e6 | 7228 | { |
a2e40bb6 | 7229 | struct wpa_driver_nl80211_data *drv = bss->drv; |
ad1e68e6 | 7230 | int ret = -1; |
26af9dca | 7231 | int i; |
86957e62 | 7232 | int was_ap = is_ap_interface(drv->nlmode); |
671a5039 | 7233 | int res; |
1581b38b | 7234 | |
671a5039 JM |
7235 | res = nl80211_set_mode(drv, drv->ifindex, nlmode); |
7236 | if (res == 0) { | |
ad1e68e6 | 7237 | drv->nlmode = nlmode; |
460456f8 JM |
7238 | ret = 0; |
7239 | goto done; | |
ad1e68e6 | 7240 | } |
3f5285e8 | 7241 | |
671a5039 JM |
7242 | if (res == -ENODEV) |
7243 | return -1; | |
7244 | ||
460456f8 | 7245 | if (nlmode == drv->nlmode) { |
c6e8e8e4 JM |
7246 | wpa_printf(MSG_DEBUG, "nl80211: Interface already in " |
7247 | "requested mode - ignore error"); | |
460456f8 JM |
7248 | ret = 0; |
7249 | goto done; /* Already in the requested mode */ | |
7250 | } | |
3f5285e8 | 7251 | |
3f5285e8 JM |
7252 | /* mac80211 doesn't allow mode changes while the device is up, so |
7253 | * take the device down, try to set the mode again, and bring the | |
7254 | * device back up. | |
7255 | */ | |
26af9dca JM |
7256 | wpa_printf(MSG_DEBUG, "nl80211: Try mode change after setting " |
7257 | "interface down"); | |
7258 | for (i = 0; i < 10; i++) { | |
c81eff1a BG |
7259 | res = linux_set_iface_flags(drv->global->ioctl_sock, |
7260 | bss->ifname, 0); | |
6e8183d7 JM |
7261 | if (res == -EACCES || res == -ENODEV) |
7262 | break; | |
7263 | if (res == 0) { | |
26af9dca JM |
7264 | /* Try to set the mode again while the interface is |
7265 | * down */ | |
7266 | ret = nl80211_set_mode(drv, drv->ifindex, nlmode); | |
6e8183d7 JM |
7267 | if (ret == -EACCES) |
7268 | break; | |
c81eff1a | 7269 | res = linux_set_iface_flags(drv->global->ioctl_sock, |
6e8183d7 JM |
7270 | bss->ifname, 1); |
7271 | if (res && !ret) | |
26af9dca | 7272 | ret = -1; |
6e8183d7 | 7273 | else if (ret != -EBUSY) |
26af9dca JM |
7274 | break; |
7275 | } else | |
7276 | wpa_printf(MSG_DEBUG, "nl80211: Failed to set " | |
7277 | "interface down"); | |
7278 | os_sleep(0, 100000); | |
3f5285e8 JM |
7279 | } |
7280 | ||
c6e8e8e4 JM |
7281 | if (!ret) { |
7282 | wpa_printf(MSG_DEBUG, "nl80211: Mode change succeeded while " | |
7283 | "interface is down"); | |
ad1e68e6 | 7284 | drv->nlmode = nlmode; |
7d9c3698 | 7285 | drv->ignore_if_down_event = 1; |
c6e8e8e4 | 7286 | } |
ad1e68e6 | 7287 | |
460456f8 | 7288 | done: |
3fd1cefb JB |
7289 | if (ret) { |
7290 | wpa_printf(MSG_DEBUG, "nl80211: Interface mode change to %d " | |
7291 | "from %d failed", nlmode, drv->nlmode); | |
7292 | return ret; | |
7293 | } | |
7294 | ||
edb9bfba RM |
7295 | if (is_p2p_interface(nlmode)) |
7296 | nl80211_disable_11b_rates(drv, drv->ifindex, 1); | |
1d0c6fb1 JM |
7297 | else if (drv->disabled_11b_rates) |
7298 | nl80211_disable_11b_rates(drv, drv->ifindex, 0); | |
edb9bfba | 7299 | |
3fd1cefb | 7300 | if (is_ap_interface(nlmode)) { |
36488c05 | 7301 | nl80211_mgmt_unsubscribe(bss, "start AP"); |
460456f8 | 7302 | /* Setup additional AP mode functionality if needed */ |
3fd1cefb | 7303 | if (nl80211_setup_ap(bss)) |
460456f8 | 7304 | return -1; |
3fd1cefb | 7305 | } else if (was_ap) { |
460456f8 | 7306 | /* Remove additional AP mode functionality */ |
3fd1cefb | 7307 | nl80211_teardown_ap(bss); |
a11241fa | 7308 | } else { |
36488c05 | 7309 | nl80211_mgmt_unsubscribe(bss, "mode change"); |
460456f8 | 7310 | } |
460456f8 | 7311 | |
873d0fcf | 7312 | if (!bss->in_deinit && !is_ap_interface(nlmode) && |
a11241fa JB |
7313 | nl80211_mgmt_subscribe_non_ap(bss) < 0) |
7314 | wpa_printf(MSG_DEBUG, "nl80211: Failed to register Action " | |
7315 | "frame processing - ignore for now"); | |
08359050 | 7316 | |
3fd1cefb | 7317 | return 0; |
3f5285e8 JM |
7318 | } |
7319 | ||
7320 | ||
3f5285e8 JM |
7321 | static int wpa_driver_nl80211_get_capa(void *priv, |
7322 | struct wpa_driver_capa *capa) | |
7323 | { | |
a2e40bb6 FF |
7324 | struct i802_bss *bss = priv; |
7325 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
3f5285e8 JM |
7326 | if (!drv->has_capability) |
7327 | return -1; | |
7328 | os_memcpy(capa, &drv->capa, sizeof(*capa)); | |
7329 | return 0; | |
7330 | } | |
7331 | ||
7332 | ||
7333 | static int wpa_driver_nl80211_set_operstate(void *priv, int state) | |
7334 | { | |
a2e40bb6 FF |
7335 | struct i802_bss *bss = priv; |
7336 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
3f5285e8 JM |
7337 | |
7338 | wpa_printf(MSG_DEBUG, "%s: operstate %d->%d (%s)", | |
7339 | __func__, drv->operstate, state, state ? "UP" : "DORMANT"); | |
7340 | drv->operstate = state; | |
36d84860 | 7341 | return netlink_send_oper_ifla(drv->global->netlink, drv->ifindex, -1, |
e2d02c29 | 7342 | state ? IF_OPER_UP : IF_OPER_DORMANT); |
3f5285e8 JM |
7343 | } |
7344 | ||
01652550 JM |
7345 | |
7346 | static int wpa_driver_nl80211_set_supp_port(void *priv, int authorized) | |
7347 | { | |
a2e40bb6 FF |
7348 | struct i802_bss *bss = priv; |
7349 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
01652550 JM |
7350 | struct nl_msg *msg; |
7351 | struct nl80211_sta_flag_update upd; | |
7352 | ||
7353 | msg = nlmsg_alloc(); | |
7354 | if (!msg) | |
7355 | return -ENOMEM; | |
7356 | ||
9fb04070 | 7357 | nl80211_cmd(drv, msg, 0, NL80211_CMD_SET_STATION); |
01652550 JM |
7358 | |
7359 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, | |
a2e40bb6 | 7360 | if_nametoindex(bss->ifname)); |
01652550 JM |
7361 | NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, drv->bssid); |
7362 | ||
7363 | os_memset(&upd, 0, sizeof(upd)); | |
7364 | upd.mask = BIT(NL80211_STA_FLAG_AUTHORIZED); | |
7365 | if (authorized) | |
7366 | upd.set = BIT(NL80211_STA_FLAG_AUTHORIZED); | |
7367 | NLA_PUT(msg, NL80211_ATTR_STA_FLAGS2, sizeof(upd), &upd); | |
7368 | ||
7369 | return send_and_recv_msgs(drv, msg, NULL, NULL); | |
7370 | nla_put_failure: | |
5883168a | 7371 | nlmsg_free(msg); |
01652550 JM |
7372 | return -ENOBUFS; |
7373 | } | |
7374 | ||
3f5285e8 | 7375 | |
f07ead6a JM |
7376 | /* Set kernel driver on given frequency (MHz) */ |
7377 | static int i802_set_freq(void *priv, struct hostapd_freq_params *freq) | |
c5121837 | 7378 | { |
f07ead6a | 7379 | struct i802_bss *bss = priv; |
89b800d7 | 7380 | return wpa_driver_nl80211_set_freq(bss, freq); |
c5121837 JM |
7381 | } |
7382 | ||
f7b3920c JM |
7383 | |
7384 | #if defined(HOSTAPD) || defined(CONFIG_AP) | |
c5121837 | 7385 | |
c5121837 JM |
7386 | static inline int min_int(int a, int b) |
7387 | { | |
7388 | if (a < b) | |
7389 | return a; | |
7390 | return b; | |
7391 | } | |
7392 | ||
7393 | ||
7394 | static int get_key_handler(struct nl_msg *msg, void *arg) | |
7395 | { | |
7396 | struct nlattr *tb[NL80211_ATTR_MAX + 1]; | |
7397 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); | |
7398 | ||
7399 | nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), | |
7400 | genlmsg_attrlen(gnlh, 0), NULL); | |
7401 | ||
7402 | /* | |
7403 | * TODO: validate the key index and mac address! | |
7404 | * Otherwise, there's a race condition as soon as | |
7405 | * the kernel starts sending key notifications. | |
7406 | */ | |
7407 | ||
7408 | if (tb[NL80211_ATTR_KEY_SEQ]) | |
7409 | memcpy(arg, nla_data(tb[NL80211_ATTR_KEY_SEQ]), | |
7410 | min_int(nla_len(tb[NL80211_ATTR_KEY_SEQ]), 6)); | |
7411 | return NL_SKIP; | |
7412 | } | |
7413 | ||
7414 | ||
7415 | static int i802_get_seqnum(const char *iface, void *priv, const u8 *addr, | |
7416 | int idx, u8 *seq) | |
7417 | { | |
a2e40bb6 FF |
7418 | struct i802_bss *bss = priv; |
7419 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
c5121837 JM |
7420 | struct nl_msg *msg; |
7421 | ||
7422 | msg = nlmsg_alloc(); | |
7423 | if (!msg) | |
7424 | return -ENOMEM; | |
7425 | ||
9fb04070 | 7426 | nl80211_cmd(drv, msg, 0, NL80211_CMD_GET_KEY); |
c5121837 JM |
7427 | |
7428 | if (addr) | |
7429 | NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, addr); | |
7430 | NLA_PUT_U8(msg, NL80211_ATTR_KEY_IDX, idx); | |
7431 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, if_nametoindex(iface)); | |
7432 | ||
7433 | memset(seq, 0, 6); | |
7434 | ||
7435 | return send_and_recv_msgs(drv, msg, get_key_handler, seq); | |
7436 | nla_put_failure: | |
9e088e74 | 7437 | nlmsg_free(msg); |
c5121837 JM |
7438 | return -ENOBUFS; |
7439 | } | |
7440 | ||
7441 | ||
c5121837 JM |
7442 | static int i802_set_rts(void *priv, int rts) |
7443 | { | |
a2e40bb6 FF |
7444 | struct i802_bss *bss = priv; |
7445 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
ad649451 JM |
7446 | struct nl_msg *msg; |
7447 | int ret = -ENOBUFS; | |
7448 | u32 val; | |
c5121837 | 7449 | |
ad649451 JM |
7450 | msg = nlmsg_alloc(); |
7451 | if (!msg) | |
7452 | return -ENOMEM; | |
c5121837 | 7453 | |
ad649451 JM |
7454 | if (rts >= 2347) |
7455 | val = (u32) -1; | |
7456 | else | |
7457 | val = rts; | |
c5121837 | 7458 | |
9fb04070 | 7459 | nl80211_cmd(drv, msg, 0, NL80211_CMD_SET_WIPHY); |
ad649451 JM |
7460 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, drv->ifindex); |
7461 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_RTS_THRESHOLD, val); | |
7462 | ||
7463 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); | |
5883168a | 7464 | msg = NULL; |
ad649451 JM |
7465 | if (!ret) |
7466 | return 0; | |
7467 | nla_put_failure: | |
5883168a | 7468 | nlmsg_free(msg); |
ad649451 JM |
7469 | wpa_printf(MSG_DEBUG, "nl80211: Failed to set RTS threshold %d: " |
7470 | "%d (%s)", rts, ret, strerror(-ret)); | |
7471 | return ret; | |
c5121837 JM |
7472 | } |
7473 | ||
7474 | ||
7475 | static int i802_set_frag(void *priv, int frag) | |
7476 | { | |
a2e40bb6 FF |
7477 | struct i802_bss *bss = priv; |
7478 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
ad649451 JM |
7479 | struct nl_msg *msg; |
7480 | int ret = -ENOBUFS; | |
7481 | u32 val; | |
c5121837 | 7482 | |
ad649451 JM |
7483 | msg = nlmsg_alloc(); |
7484 | if (!msg) | |
7485 | return -ENOMEM; | |
c5121837 | 7486 | |
ad649451 JM |
7487 | if (frag >= 2346) |
7488 | val = (u32) -1; | |
7489 | else | |
7490 | val = frag; | |
c5121837 | 7491 | |
9fb04070 | 7492 | nl80211_cmd(drv, msg, 0, NL80211_CMD_SET_WIPHY); |
ad649451 JM |
7493 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, drv->ifindex); |
7494 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_FRAG_THRESHOLD, val); | |
7495 | ||
7496 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); | |
5883168a | 7497 | msg = NULL; |
ad649451 JM |
7498 | if (!ret) |
7499 | return 0; | |
7500 | nla_put_failure: | |
5883168a | 7501 | nlmsg_free(msg); |
ad649451 JM |
7502 | wpa_printf(MSG_DEBUG, "nl80211: Failed to set fragmentation threshold " |
7503 | "%d: %d (%s)", frag, ret, strerror(-ret)); | |
7504 | return ret; | |
c5121837 JM |
7505 | } |
7506 | ||
7507 | ||
c5121837 JM |
7508 | static int i802_flush(void *priv) |
7509 | { | |
a2e40bb6 FF |
7510 | struct i802_bss *bss = priv; |
7511 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
c5121837 | 7512 | struct nl_msg *msg; |
82554b10 | 7513 | int res; |
c5121837 JM |
7514 | |
7515 | msg = nlmsg_alloc(); | |
7516 | if (!msg) | |
7517 | return -1; | |
7518 | ||
9fb04070 | 7519 | nl80211_cmd(drv, msg, 0, NL80211_CMD_DEL_STATION); |
c5121837 JM |
7520 | |
7521 | /* | |
7522 | * XXX: FIX! this needs to flush all VLANs too | |
7523 | */ | |
7524 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, | |
a2e40bb6 | 7525 | if_nametoindex(bss->ifname)); |
c5121837 | 7526 | |
82554b10 JM |
7527 | res = send_and_recv_msgs(drv, msg, NULL, NULL); |
7528 | if (res) { | |
7529 | wpa_printf(MSG_DEBUG, "nl80211: Station flush failed: ret=%d " | |
7530 | "(%s)", res, strerror(-res)); | |
7531 | } | |
7532 | return res; | |
c5121837 | 7533 | nla_put_failure: |
9e088e74 | 7534 | nlmsg_free(msg); |
c5121837 JM |
7535 | return -ENOBUFS; |
7536 | } | |
7537 | ||
d732463c JM |
7538 | #endif /* HOSTAPD || CONFIG_AP */ |
7539 | ||
c5121837 JM |
7540 | |
7541 | static int get_sta_handler(struct nl_msg *msg, void *arg) | |
7542 | { | |
7543 | struct nlattr *tb[NL80211_ATTR_MAX + 1]; | |
7544 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); | |
7545 | struct hostap_sta_driver_data *data = arg; | |
7546 | struct nlattr *stats[NL80211_STA_INFO_MAX + 1]; | |
7547 | static struct nla_policy stats_policy[NL80211_STA_INFO_MAX + 1] = { | |
7548 | [NL80211_STA_INFO_INACTIVE_TIME] = { .type = NLA_U32 }, | |
7549 | [NL80211_STA_INFO_RX_BYTES] = { .type = NLA_U32 }, | |
7550 | [NL80211_STA_INFO_TX_BYTES] = { .type = NLA_U32 }, | |
7551 | [NL80211_STA_INFO_RX_PACKETS] = { .type = NLA_U32 }, | |
7552 | [NL80211_STA_INFO_TX_PACKETS] = { .type = NLA_U32 }, | |
dc7785f8 | 7553 | [NL80211_STA_INFO_TX_FAILED] = { .type = NLA_U32 }, |
c5121837 JM |
7554 | }; |
7555 | ||
7556 | nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), | |
7557 | genlmsg_attrlen(gnlh, 0), NULL); | |
7558 | ||
7559 | /* | |
7560 | * TODO: validate the interface and mac address! | |
7561 | * Otherwise, there's a race condition as soon as | |
7562 | * the kernel starts sending station notifications. | |
7563 | */ | |
7564 | ||
7565 | if (!tb[NL80211_ATTR_STA_INFO]) { | |
7566 | wpa_printf(MSG_DEBUG, "sta stats missing!"); | |
7567 | return NL_SKIP; | |
7568 | } | |
7569 | if (nla_parse_nested(stats, NL80211_STA_INFO_MAX, | |
7570 | tb[NL80211_ATTR_STA_INFO], | |
7571 | stats_policy)) { | |
7572 | wpa_printf(MSG_DEBUG, "failed to parse nested attributes!"); | |
7573 | return NL_SKIP; | |
7574 | } | |
7575 | ||
7576 | if (stats[NL80211_STA_INFO_INACTIVE_TIME]) | |
7577 | data->inactive_msec = | |
7578 | nla_get_u32(stats[NL80211_STA_INFO_INACTIVE_TIME]); | |
7579 | if (stats[NL80211_STA_INFO_RX_BYTES]) | |
7580 | data->rx_bytes = nla_get_u32(stats[NL80211_STA_INFO_RX_BYTES]); | |
7581 | if (stats[NL80211_STA_INFO_TX_BYTES]) | |
7582 | data->tx_bytes = nla_get_u32(stats[NL80211_STA_INFO_TX_BYTES]); | |
7583 | if (stats[NL80211_STA_INFO_RX_PACKETS]) | |
7584 | data->rx_packets = | |
7585 | nla_get_u32(stats[NL80211_STA_INFO_RX_PACKETS]); | |
7586 | if (stats[NL80211_STA_INFO_TX_PACKETS]) | |
7587 | data->tx_packets = | |
7588 | nla_get_u32(stats[NL80211_STA_INFO_TX_PACKETS]); | |
dc7785f8 YZ |
7589 | if (stats[NL80211_STA_INFO_TX_FAILED]) |
7590 | data->tx_retry_failed = | |
7591 | nla_get_u32(stats[NL80211_STA_INFO_TX_FAILED]); | |
c5121837 JM |
7592 | |
7593 | return NL_SKIP; | |
7594 | } | |
7595 | ||
9ebce9c5 JM |
7596 | static int i802_read_sta_data(struct i802_bss *bss, |
7597 | struct hostap_sta_driver_data *data, | |
c5121837 JM |
7598 | const u8 *addr) |
7599 | { | |
a2e40bb6 | 7600 | struct wpa_driver_nl80211_data *drv = bss->drv; |
c5121837 JM |
7601 | struct nl_msg *msg; |
7602 | ||
7603 | os_memset(data, 0, sizeof(*data)); | |
7604 | msg = nlmsg_alloc(); | |
7605 | if (!msg) | |
7606 | return -ENOMEM; | |
7607 | ||
9fb04070 | 7608 | nl80211_cmd(drv, msg, 0, NL80211_CMD_GET_STATION); |
c5121837 JM |
7609 | |
7610 | NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, addr); | |
a2e40bb6 | 7611 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, if_nametoindex(bss->ifname)); |
c5121837 JM |
7612 | |
7613 | return send_and_recv_msgs(drv, msg, get_sta_handler, data); | |
7614 | nla_put_failure: | |
9e088e74 | 7615 | nlmsg_free(msg); |
c5121837 JM |
7616 | return -ENOBUFS; |
7617 | } | |
7618 | ||
7619 | ||
d732463c JM |
7620 | #if defined(HOSTAPD) || defined(CONFIG_AP) |
7621 | ||
c5121837 JM |
7622 | static int i802_set_tx_queue_params(void *priv, int queue, int aifs, |
7623 | int cw_min, int cw_max, int burst_time) | |
7624 | { | |
a2e40bb6 FF |
7625 | struct i802_bss *bss = priv; |
7626 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
c5121837 JM |
7627 | struct nl_msg *msg; |
7628 | struct nlattr *txq, *params; | |
7629 | ||
7630 | msg = nlmsg_alloc(); | |
7631 | if (!msg) | |
7632 | return -1; | |
7633 | ||
9fb04070 | 7634 | nl80211_cmd(drv, msg, 0, NL80211_CMD_SET_WIPHY); |
c5121837 | 7635 | |
a2e40bb6 | 7636 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, if_nametoindex(bss->ifname)); |
c5121837 JM |
7637 | |
7638 | txq = nla_nest_start(msg, NL80211_ATTR_WIPHY_TXQ_PARAMS); | |
7639 | if (!txq) | |
7640 | goto nla_put_failure; | |
7641 | ||
7642 | /* We are only sending parameters for a single TXQ at a time */ | |
7643 | params = nla_nest_start(msg, 1); | |
7644 | if (!params) | |
7645 | goto nla_put_failure; | |
7646 | ||
7e3c1781 JM |
7647 | switch (queue) { |
7648 | case 0: | |
7649 | NLA_PUT_U8(msg, NL80211_TXQ_ATTR_QUEUE, NL80211_TXQ_Q_VO); | |
7650 | break; | |
7651 | case 1: | |
7652 | NLA_PUT_U8(msg, NL80211_TXQ_ATTR_QUEUE, NL80211_TXQ_Q_VI); | |
7653 | break; | |
7654 | case 2: | |
7655 | NLA_PUT_U8(msg, NL80211_TXQ_ATTR_QUEUE, NL80211_TXQ_Q_BE); | |
7656 | break; | |
7657 | case 3: | |
7658 | NLA_PUT_U8(msg, NL80211_TXQ_ATTR_QUEUE, NL80211_TXQ_Q_BK); | |
7659 | break; | |
7660 | } | |
c5121837 JM |
7661 | /* Burst time is configured in units of 0.1 msec and TXOP parameter in |
7662 | * 32 usec, so need to convert the value here. */ | |
7663 | NLA_PUT_U16(msg, NL80211_TXQ_ATTR_TXOP, (burst_time * 100 + 16) / 32); | |
7664 | NLA_PUT_U16(msg, NL80211_TXQ_ATTR_CWMIN, cw_min); | |
7665 | NLA_PUT_U16(msg, NL80211_TXQ_ATTR_CWMAX, cw_max); | |
7666 | NLA_PUT_U8(msg, NL80211_TXQ_ATTR_AIFS, aifs); | |
7667 | ||
7668 | nla_nest_end(msg, params); | |
7669 | ||
7670 | nla_nest_end(msg, txq); | |
7671 | ||
7672 | if (send_and_recv_msgs(drv, msg, NULL, NULL) == 0) | |
7673 | return 0; | |
9e088e74 | 7674 | msg = NULL; |
c5121837 | 7675 | nla_put_failure: |
9e088e74 | 7676 | nlmsg_free(msg); |
c5121837 JM |
7677 | return -1; |
7678 | } | |
7679 | ||
7680 | ||
9ebce9c5 | 7681 | static int i802_set_sta_vlan(struct i802_bss *bss, const u8 *addr, |
c5121837 JM |
7682 | const char *ifname, int vlan_id) |
7683 | { | |
a2e40bb6 | 7684 | struct wpa_driver_nl80211_data *drv = bss->drv; |
c5121837 | 7685 | struct nl_msg *msg; |
cd1d72c1 | 7686 | int ret = -ENOBUFS; |
c5121837 JM |
7687 | |
7688 | msg = nlmsg_alloc(); | |
7689 | if (!msg) | |
7690 | return -ENOMEM; | |
7691 | ||
9fb04070 | 7692 | nl80211_cmd(drv, msg, 0, NL80211_CMD_SET_STATION); |
c5121837 JM |
7693 | |
7694 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, | |
a2e40bb6 | 7695 | if_nametoindex(bss->ifname)); |
c5121837 | 7696 | NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, addr); |
1c766b09 | 7697 | NLA_PUT_U32(msg, NL80211_ATTR_STA_VLAN, |
c5121837 JM |
7698 | if_nametoindex(ifname)); |
7699 | ||
cd1d72c1 | 7700 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
9e088e74 | 7701 | msg = NULL; |
cd1d72c1 JM |
7702 | if (ret < 0) { |
7703 | wpa_printf(MSG_ERROR, "nl80211: NL80211_ATTR_STA_VLAN (addr=" | |
7704 | MACSTR " ifname=%s vlan_id=%d) failed: %d (%s)", | |
7705 | MAC2STR(addr), ifname, vlan_id, ret, | |
7706 | strerror(-ret)); | |
7707 | } | |
c5121837 | 7708 | nla_put_failure: |
9e088e74 | 7709 | nlmsg_free(msg); |
cd1d72c1 | 7710 | return ret; |
c5121837 JM |
7711 | } |
7712 | ||
fbbfcbac | 7713 | |
c5121837 JM |
7714 | static int i802_get_inact_sec(void *priv, const u8 *addr) |
7715 | { | |
7716 | struct hostap_sta_driver_data data; | |
7717 | int ret; | |
7718 | ||
7719 | data.inactive_msec = (unsigned long) -1; | |
7720 | ret = i802_read_sta_data(priv, &data, addr); | |
7721 | if (ret || data.inactive_msec == (unsigned long) -1) | |
7722 | return -1; | |
7723 | return data.inactive_msec / 1000; | |
7724 | } | |
7725 | ||
7726 | ||
7727 | static int i802_sta_clear_stats(void *priv, const u8 *addr) | |
7728 | { | |
7729 | #if 0 | |
7730 | /* TODO */ | |
7731 | #endif | |
7732 | return 0; | |
7733 | } | |
7734 | ||
7735 | ||
731723a5 JM |
7736 | static int i802_sta_deauth(void *priv, const u8 *own_addr, const u8 *addr, |
7737 | int reason) | |
c5121837 | 7738 | { |
a2e40bb6 | 7739 | struct i802_bss *bss = priv; |
e1bd4e19 | 7740 | struct wpa_driver_nl80211_data *drv = bss->drv; |
c5121837 JM |
7741 | struct ieee80211_mgmt mgmt; |
7742 | ||
e1bd4e19 AT |
7743 | if (drv->device_ap_sme) |
7744 | return wpa_driver_nl80211_sta_remove(bss, addr); | |
7745 | ||
c5121837 JM |
7746 | memset(&mgmt, 0, sizeof(mgmt)); |
7747 | mgmt.frame_control = IEEE80211_FC(WLAN_FC_TYPE_MGMT, | |
7748 | WLAN_FC_STYPE_DEAUTH); | |
7749 | memcpy(mgmt.da, addr, ETH_ALEN); | |
731723a5 JM |
7750 | memcpy(mgmt.sa, own_addr, ETH_ALEN); |
7751 | memcpy(mgmt.bssid, own_addr, ETH_ALEN); | |
c5121837 | 7752 | mgmt.u.deauth.reason_code = host_to_le16(reason); |
a2e40bb6 | 7753 | return wpa_driver_nl80211_send_mlme(bss, (u8 *) &mgmt, |
9f324b61 | 7754 | IEEE80211_HDRLEN + |
9ebce9c5 JM |
7755 | sizeof(mgmt.u.deauth), 0, 0, 0, 0, |
7756 | 0); | |
c5121837 JM |
7757 | } |
7758 | ||
7759 | ||
731723a5 JM |
7760 | static int i802_sta_disassoc(void *priv, const u8 *own_addr, const u8 *addr, |
7761 | int reason) | |
c5121837 | 7762 | { |
a2e40bb6 | 7763 | struct i802_bss *bss = priv; |
e1bd4e19 | 7764 | struct wpa_driver_nl80211_data *drv = bss->drv; |
c5121837 JM |
7765 | struct ieee80211_mgmt mgmt; |
7766 | ||
e1bd4e19 AT |
7767 | if (drv->device_ap_sme) |
7768 | return wpa_driver_nl80211_sta_remove(bss, addr); | |
7769 | ||
c5121837 JM |
7770 | memset(&mgmt, 0, sizeof(mgmt)); |
7771 | mgmt.frame_control = IEEE80211_FC(WLAN_FC_TYPE_MGMT, | |
7772 | WLAN_FC_STYPE_DISASSOC); | |
7773 | memcpy(mgmt.da, addr, ETH_ALEN); | |
731723a5 JM |
7774 | memcpy(mgmt.sa, own_addr, ETH_ALEN); |
7775 | memcpy(mgmt.bssid, own_addr, ETH_ALEN); | |
c5121837 | 7776 | mgmt.u.disassoc.reason_code = host_to_le16(reason); |
a2e40bb6 | 7777 | return wpa_driver_nl80211_send_mlme(bss, (u8 *) &mgmt, |
9f324b61 | 7778 | IEEE80211_HDRLEN + |
9ebce9c5 JM |
7779 | sizeof(mgmt.u.disassoc), 0, 0, 0, 0, |
7780 | 0); | |
c5121837 JM |
7781 | } |
7782 | ||
ee7ab173 JB |
7783 | #endif /* HOSTAPD || CONFIG_AP */ |
7784 | ||
7785 | #ifdef HOSTAPD | |
c5121837 | 7786 | |
f07ead6a JM |
7787 | static void add_ifidx(struct wpa_driver_nl80211_data *drv, int ifidx) |
7788 | { | |
7789 | int i; | |
7790 | int *old; | |
7791 | ||
7792 | wpa_printf(MSG_DEBUG, "nl80211: Add own interface ifindex %d", | |
7793 | ifidx); | |
7794 | for (i = 0; i < drv->num_if_indices; i++) { | |
7795 | if (drv->if_indices[i] == 0) { | |
7796 | drv->if_indices[i] = ifidx; | |
7797 | return; | |
7798 | } | |
7799 | } | |
7800 | ||
7801 | if (drv->if_indices != drv->default_if_indices) | |
7802 | old = drv->if_indices; | |
7803 | else | |
7804 | old = NULL; | |
7805 | ||
067ffa26 JM |
7806 | drv->if_indices = os_realloc_array(old, drv->num_if_indices + 1, |
7807 | sizeof(int)); | |
f07ead6a JM |
7808 | if (!drv->if_indices) { |
7809 | if (!old) | |
7810 | drv->if_indices = drv->default_if_indices; | |
7811 | else | |
7812 | drv->if_indices = old; | |
7813 | wpa_printf(MSG_ERROR, "Failed to reallocate memory for " | |
7814 | "interfaces"); | |
7815 | wpa_printf(MSG_ERROR, "Ignoring EAPOL on interface %d", ifidx); | |
7816 | return; | |
7817 | } else if (!old) | |
7818 | os_memcpy(drv->if_indices, drv->default_if_indices, | |
7819 | sizeof(drv->default_if_indices)); | |
7820 | drv->if_indices[drv->num_if_indices] = ifidx; | |
7821 | drv->num_if_indices++; | |
7822 | } | |
7823 | ||
7824 | ||
7825 | static void del_ifidx(struct wpa_driver_nl80211_data *drv, int ifidx) | |
7826 | { | |
7827 | int i; | |
7828 | ||
7829 | for (i = 0; i < drv->num_if_indices; i++) { | |
7830 | if (drv->if_indices[i] == ifidx) { | |
7831 | drv->if_indices[i] = 0; | |
7832 | break; | |
7833 | } | |
7834 | } | |
7835 | } | |
7836 | ||
7837 | ||
7838 | static int have_ifidx(struct wpa_driver_nl80211_data *drv, int ifidx) | |
7839 | { | |
7840 | int i; | |
7841 | ||
7842 | for (i = 0; i < drv->num_if_indices; i++) | |
7843 | if (drv->if_indices[i] == ifidx) | |
7844 | return 1; | |
7845 | ||
7846 | return 0; | |
7847 | } | |
7848 | ||
7849 | ||
7850 | static int i802_set_wds_sta(void *priv, const u8 *addr, int aid, int val, | |
7851 | const char *bridge_ifname) | |
7852 | { | |
7853 | struct i802_bss *bss = priv; | |
7854 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
7855 | char name[IFNAMSIZ + 1]; | |
7856 | ||
7857 | os_snprintf(name, sizeof(name), "%s.sta%d", bss->ifname, aid); | |
7858 | wpa_printf(MSG_DEBUG, "nl80211: Set WDS STA addr=" MACSTR | |
7859 | " aid=%d val=%d name=%s", MAC2STR(addr), aid, val, name); | |
7860 | if (val) { | |
7861 | if (!if_nametoindex(name)) { | |
7862 | if (nl80211_create_iface(drv, name, | |
7863 | NL80211_IFTYPE_AP_VLAN, | |
7864 | NULL, 1) < 0) | |
7865 | return -1; | |
7866 | if (bridge_ifname && | |
c81eff1a BG |
7867 | linux_br_add_if(drv->global->ioctl_sock, |
7868 | bridge_ifname, name) < 0) | |
f07ead6a JM |
7869 | return -1; |
7870 | } | |
75227f3a JM |
7871 | if (linux_set_iface_flags(drv->global->ioctl_sock, name, 1)) { |
7872 | wpa_printf(MSG_ERROR, "nl80211: Failed to set WDS STA " | |
7873 | "interface %s up", name); | |
7874 | } | |
f07ead6a JM |
7875 | return i802_set_sta_vlan(priv, addr, name, 0); |
7876 | } else { | |
c34e618d FF |
7877 | if (bridge_ifname) |
7878 | linux_br_del_if(drv->global->ioctl_sock, bridge_ifname, | |
7879 | name); | |
7880 | ||
f07ead6a JM |
7881 | i802_set_sta_vlan(priv, addr, bss->ifname, 0); |
7882 | return wpa_driver_nl80211_if_remove(priv, WPA_IF_AP_VLAN, | |
7883 | name); | |
7884 | } | |
7885 | } | |
7886 | ||
7887 | ||
7888 | static void handle_eapol(int sock, void *eloop_ctx, void *sock_ctx) | |
7889 | { | |
7890 | struct wpa_driver_nl80211_data *drv = eloop_ctx; | |
7891 | struct sockaddr_ll lladdr; | |
7892 | unsigned char buf[3000]; | |
7893 | int len; | |
7894 | socklen_t fromlen = sizeof(lladdr); | |
7895 | ||
7896 | len = recvfrom(sock, buf, sizeof(buf), 0, | |
7897 | (struct sockaddr *)&lladdr, &fromlen); | |
7898 | if (len < 0) { | |
7899 | perror("recv"); | |
7900 | return; | |
7901 | } | |
7902 | ||
7903 | if (have_ifidx(drv, lladdr.sll_ifindex)) | |
7904 | drv_event_eapol_rx(drv->ctx, lladdr.sll_addr, buf, len); | |
7905 | } | |
7906 | ||
7907 | ||
94627f6c | 7908 | static int i802_check_bridge(struct wpa_driver_nl80211_data *drv, |
e17a2477 | 7909 | struct i802_bss *bss, |
94627f6c JM |
7910 | const char *brname, const char *ifname) |
7911 | { | |
7912 | int ifindex; | |
7913 | char in_br[IFNAMSIZ]; | |
7914 | ||
e17a2477 | 7915 | os_strlcpy(bss->brname, brname, IFNAMSIZ); |
94627f6c JM |
7916 | ifindex = if_nametoindex(brname); |
7917 | if (ifindex == 0) { | |
7918 | /* | |
7919 | * Bridge was configured, but the bridge device does | |
7920 | * not exist. Try to add it now. | |
7921 | */ | |
c81eff1a | 7922 | if (linux_br_add(drv->global->ioctl_sock, brname) < 0) { |
94627f6c JM |
7923 | wpa_printf(MSG_ERROR, "nl80211: Failed to add the " |
7924 | "bridge interface %s: %s", | |
7925 | brname, strerror(errno)); | |
7926 | return -1; | |
7927 | } | |
e17a2477 | 7928 | bss->added_bridge = 1; |
94627f6c JM |
7929 | add_ifidx(drv, if_nametoindex(brname)); |
7930 | } | |
7931 | ||
7932 | if (linux_br_get(in_br, ifname) == 0) { | |
7933 | if (os_strcmp(in_br, brname) == 0) | |
7934 | return 0; /* already in the bridge */ | |
7935 | ||
7936 | wpa_printf(MSG_DEBUG, "nl80211: Removing interface %s from " | |
7937 | "bridge %s", ifname, in_br); | |
c81eff1a BG |
7938 | if (linux_br_del_if(drv->global->ioctl_sock, in_br, ifname) < |
7939 | 0) { | |
94627f6c JM |
7940 | wpa_printf(MSG_ERROR, "nl80211: Failed to " |
7941 | "remove interface %s from bridge " | |
7942 | "%s: %s", | |
7943 | ifname, brname, strerror(errno)); | |
7944 | return -1; | |
7945 | } | |
7946 | } | |
7947 | ||
7948 | wpa_printf(MSG_DEBUG, "nl80211: Adding interface %s into bridge %s", | |
7949 | ifname, brname); | |
c81eff1a | 7950 | if (linux_br_add_if(drv->global->ioctl_sock, brname, ifname) < 0) { |
94627f6c JM |
7951 | wpa_printf(MSG_ERROR, "nl80211: Failed to add interface %s " |
7952 | "into bridge %s: %s", | |
7953 | ifname, brname, strerror(errno)); | |
7954 | return -1; | |
7955 | } | |
e17a2477 | 7956 | bss->added_if_into_bridge = 1; |
94627f6c JM |
7957 | |
7958 | return 0; | |
7959 | } | |
7960 | ||
7961 | ||
92f475b4 JM |
7962 | static void *i802_init(struct hostapd_data *hapd, |
7963 | struct wpa_init_params *params) | |
c5121837 JM |
7964 | { |
7965 | struct wpa_driver_nl80211_data *drv; | |
a2e40bb6 | 7966 | struct i802_bss *bss; |
c5121837 | 7967 | size_t i; |
94627f6c JM |
7968 | char brname[IFNAMSIZ]; |
7969 | int ifindex, br_ifindex; | |
7970 | int br_added = 0; | |
c5121837 | 7971 | |
4b24282a JM |
7972 | bss = wpa_driver_nl80211_init(hapd, params->ifname, |
7973 | params->global_priv); | |
a2e40bb6 | 7974 | if (bss == NULL) |
c5121837 | 7975 | return NULL; |
c5121837 | 7976 | |
a2e40bb6 | 7977 | drv = bss->drv; |
0382097e | 7978 | drv->nlmode = NL80211_IFTYPE_AP; |
7635bfb0 JB |
7979 | drv->eapol_sock = -1; |
7980 | ||
94627f6c JM |
7981 | if (linux_br_get(brname, params->ifname) == 0) { |
7982 | wpa_printf(MSG_DEBUG, "nl80211: Interface %s is in bridge %s", | |
7983 | params->ifname, brname); | |
7984 | br_ifindex = if_nametoindex(brname); | |
7985 | } else { | |
7986 | brname[0] = '\0'; | |
7987 | br_ifindex = 0; | |
7988 | } | |
7989 | ||
c5121837 JM |
7990 | drv->num_if_indices = sizeof(drv->default_if_indices) / sizeof(int); |
7991 | drv->if_indices = drv->default_if_indices; | |
92f475b4 | 7992 | for (i = 0; i < params->num_bridge; i++) { |
94627f6c JM |
7993 | if (params->bridge[i]) { |
7994 | ifindex = if_nametoindex(params->bridge[i]); | |
7995 | if (ifindex) | |
7996 | add_ifidx(drv, ifindex); | |
7997 | if (ifindex == br_ifindex) | |
7998 | br_added = 1; | |
7999 | } | |
c5121837 | 8000 | } |
94627f6c JM |
8001 | if (!br_added && br_ifindex && |
8002 | (params->num_bridge == 0 || !params->bridge[0])) | |
8003 | add_ifidx(drv, br_ifindex); | |
c5121837 | 8004 | |
ad1e68e6 JM |
8005 | /* start listening for EAPOL on the default AP interface */ |
8006 | add_ifidx(drv, drv->ifindex); | |
8007 | ||
c81eff1a | 8008 | if (linux_set_iface_flags(drv->global->ioctl_sock, bss->ifname, 0)) |
6980c191 | 8009 | goto failed; |
ad1e68e6 | 8010 | |
6980c191 | 8011 | if (params->bssid) { |
c81eff1a | 8012 | if (linux_set_ifhwaddr(drv->global->ioctl_sock, bss->ifname, |
2ac9688e | 8013 | params->bssid)) |
460456f8 JM |
8014 | goto failed; |
8015 | } | |
ad1e68e6 | 8016 | |
b1f625e0 | 8017 | if (wpa_driver_nl80211_set_mode(bss, drv->nlmode)) { |
ad1e68e6 | 8018 | wpa_printf(MSG_ERROR, "nl80211: Failed to set interface %s " |
a2e40bb6 | 8019 | "into AP mode", bss->ifname); |
bbaf0837 | 8020 | goto failed; |
ad1e68e6 JM |
8021 | } |
8022 | ||
94627f6c | 8023 | if (params->num_bridge && params->bridge[0] && |
e17a2477 | 8024 | i802_check_bridge(drv, bss, params->bridge[0], params->ifname) < 0) |
94627f6c JM |
8025 | goto failed; |
8026 | ||
c81eff1a | 8027 | if (linux_set_iface_flags(drv->global->ioctl_sock, bss->ifname, 1)) |
bbaf0837 | 8028 | goto failed; |
ad1e68e6 JM |
8029 | |
8030 | drv->eapol_sock = socket(PF_PACKET, SOCK_DGRAM, htons(ETH_P_PAE)); | |
8031 | if (drv->eapol_sock < 0) { | |
8032 | perror("socket(PF_PACKET, SOCK_DGRAM, ETH_P_PAE)"); | |
bbaf0837 | 8033 | goto failed; |
ad1e68e6 JM |
8034 | } |
8035 | ||
8036 | if (eloop_register_read_sock(drv->eapol_sock, handle_eapol, drv, NULL)) | |
8037 | { | |
8038 | printf("Could not register read socket for eapol\n"); | |
c5121837 | 8039 | goto failed; |
ad1e68e6 JM |
8040 | } |
8041 | ||
c81eff1a BG |
8042 | if (linux_get_ifhwaddr(drv->global->ioctl_sock, bss->ifname, |
8043 | params->own_addr)) | |
bbaf0837 | 8044 | goto failed; |
c5121837 | 8045 | |
341eebee JB |
8046 | memcpy(bss->addr, params->own_addr, ETH_ALEN); |
8047 | ||
a2e40bb6 | 8048 | return bss; |
c5121837 JM |
8049 | |
8050 | failed: | |
7635bfb0 | 8051 | wpa_driver_nl80211_deinit(bss); |
bbaf0837 JM |
8052 | return NULL; |
8053 | } | |
c5121837 | 8054 | |
c5121837 | 8055 | |
bbaf0837 JM |
8056 | static void i802_deinit(void *priv) |
8057 | { | |
9ebce9c5 JM |
8058 | struct i802_bss *bss = priv; |
8059 | wpa_driver_nl80211_deinit(bss); | |
c5121837 JM |
8060 | } |
8061 | ||
8062 | #endif /* HOSTAPD */ | |
8063 | ||
8064 | ||
22a7c9d7 JM |
8065 | static enum nl80211_iftype wpa_driver_nl80211_if_type( |
8066 | enum wpa_driver_if_type type) | |
8067 | { | |
8068 | switch (type) { | |
8069 | case WPA_IF_STATION: | |
9f51b113 | 8070 | return NL80211_IFTYPE_STATION; |
75bde05d JM |
8071 | case WPA_IF_P2P_CLIENT: |
8072 | case WPA_IF_P2P_GROUP: | |
9f51b113 | 8073 | return NL80211_IFTYPE_P2P_CLIENT; |
22a7c9d7 JM |
8074 | case WPA_IF_AP_VLAN: |
8075 | return NL80211_IFTYPE_AP_VLAN; | |
8076 | case WPA_IF_AP_BSS: | |
8077 | return NL80211_IFTYPE_AP; | |
9f51b113 JB |
8078 | case WPA_IF_P2P_GO: |
8079 | return NL80211_IFTYPE_P2P_GO; | |
22a7c9d7 JM |
8080 | } |
8081 | return -1; | |
8082 | } | |
8083 | ||
8084 | ||
482856c8 JM |
8085 | #ifdef CONFIG_P2P |
8086 | ||
f2ed8023 JM |
8087 | static int nl80211_addr_in_use(struct nl80211_global *global, const u8 *addr) |
8088 | { | |
8089 | struct wpa_driver_nl80211_data *drv; | |
8090 | dl_list_for_each(drv, &global->interfaces, | |
8091 | struct wpa_driver_nl80211_data, list) { | |
341eebee | 8092 | if (os_memcmp(addr, drv->first_bss.addr, ETH_ALEN) == 0) |
f2ed8023 JM |
8093 | return 1; |
8094 | } | |
8095 | return 0; | |
8096 | } | |
8097 | ||
8098 | ||
8099 | static int nl80211_p2p_interface_addr(struct wpa_driver_nl80211_data *drv, | |
8100 | u8 *new_addr) | |
8101 | { | |
8102 | unsigned int idx; | |
8103 | ||
8104 | if (!drv->global) | |
8105 | return -1; | |
8106 | ||
341eebee | 8107 | os_memcpy(new_addr, drv->first_bss.addr, ETH_ALEN); |
f2ed8023 | 8108 | for (idx = 0; idx < 64; idx++) { |
341eebee | 8109 | new_addr[0] = drv->first_bss.addr[0] | 0x02; |
f2ed8023 JM |
8110 | new_addr[0] ^= idx << 2; |
8111 | if (!nl80211_addr_in_use(drv->global, new_addr)) | |
8112 | break; | |
8113 | } | |
8114 | if (idx == 64) | |
8115 | return -1; | |
8116 | ||
8117 | wpa_printf(MSG_DEBUG, "nl80211: Assigned new P2P Interface Address " | |
8118 | MACSTR, MAC2STR(new_addr)); | |
8119 | ||
8120 | return 0; | |
8121 | } | |
8122 | ||
482856c8 JM |
8123 | #endif /* CONFIG_P2P */ |
8124 | ||
f2ed8023 | 8125 | |
7ab68865 | 8126 | static int wpa_driver_nl80211_if_add(void *priv, enum wpa_driver_if_type type, |
8043e725 | 8127 | const char *ifname, const u8 *addr, |
f3585c8a | 8128 | void *bss_ctx, void **drv_priv, |
e17a2477 JM |
8129 | char *force_ifname, u8 *if_addr, |
8130 | const char *bridge) | |
22a7c9d7 | 8131 | { |
a2e40bb6 FF |
8132 | struct i802_bss *bss = priv; |
8133 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
22a7c9d7 JM |
8134 | int ifidx; |
8135 | #ifdef HOSTAPD | |
a2e40bb6 | 8136 | struct i802_bss *new_bss = NULL; |
22a7c9d7 JM |
8137 | |
8138 | if (type == WPA_IF_AP_BSS) { | |
a2e40bb6 FF |
8139 | new_bss = os_zalloc(sizeof(*new_bss)); |
8140 | if (new_bss == NULL) | |
22a7c9d7 JM |
8141 | return -1; |
8142 | } | |
8143 | #endif /* HOSTAPD */ | |
8144 | ||
f3585c8a JM |
8145 | if (addr) |
8146 | os_memcpy(if_addr, addr, ETH_ALEN); | |
22a7c9d7 | 8147 | ifidx = nl80211_create_iface(drv, ifname, |
fbbfcbac FF |
8148 | wpa_driver_nl80211_if_type(type), addr, |
8149 | 0); | |
22a7c9d7 JM |
8150 | if (ifidx < 0) { |
8151 | #ifdef HOSTAPD | |
a2e40bb6 | 8152 | os_free(new_bss); |
22a7c9d7 JM |
8153 | #endif /* HOSTAPD */ |
8154 | return -1; | |
8155 | } | |
8156 | ||
f3585c8a | 8157 | if (!addr && |
c81eff1a BG |
8158 | linux_get_ifhwaddr(drv->global->ioctl_sock, bss->ifname, |
8159 | if_addr) < 0) { | |
c55f774d | 8160 | nl80211_remove_iface(drv, ifidx); |
f3585c8a | 8161 | return -1; |
c55f774d JM |
8162 | } |
8163 | ||
8164 | #ifdef CONFIG_P2P | |
8165 | if (!addr && | |
8166 | (type == WPA_IF_P2P_CLIENT || type == WPA_IF_P2P_GROUP || | |
8167 | type == WPA_IF_P2P_GO)) { | |
8168 | /* Enforce unique P2P Interface Address */ | |
8169 | u8 new_addr[ETH_ALEN], own_addr[ETH_ALEN]; | |
8170 | ||
c81eff1a BG |
8171 | if (linux_get_ifhwaddr(drv->global->ioctl_sock, bss->ifname, |
8172 | own_addr) < 0 || | |
8173 | linux_get_ifhwaddr(drv->global->ioctl_sock, ifname, | |
8174 | new_addr) < 0) { | |
c55f774d JM |
8175 | nl80211_remove_iface(drv, ifidx); |
8176 | return -1; | |
8177 | } | |
8178 | if (os_memcmp(own_addr, new_addr, ETH_ALEN) == 0) { | |
8179 | wpa_printf(MSG_DEBUG, "nl80211: Allocate new address " | |
8180 | "for P2P group interface"); | |
f2ed8023 | 8181 | if (nl80211_p2p_interface_addr(drv, new_addr) < 0) { |
c55f774d JM |
8182 | nl80211_remove_iface(drv, ifidx); |
8183 | return -1; | |
8184 | } | |
c81eff1a | 8185 | if (linux_set_ifhwaddr(drv->global->ioctl_sock, ifname, |
c55f774d JM |
8186 | new_addr) < 0) { |
8187 | nl80211_remove_iface(drv, ifidx); | |
8188 | return -1; | |
8189 | } | |
c55f774d | 8190 | } |
f67eeb5c | 8191 | os_memcpy(if_addr, new_addr, ETH_ALEN); |
c55f774d JM |
8192 | } |
8193 | #endif /* CONFIG_P2P */ | |
f3585c8a | 8194 | |
22a7c9d7 | 8195 | #ifdef HOSTAPD |
e17a2477 JM |
8196 | if (bridge && |
8197 | i802_check_bridge(drv, new_bss, bridge, ifname) < 0) { | |
8198 | wpa_printf(MSG_ERROR, "nl80211: Failed to add the new " | |
8199 | "interface %s to a bridge %s", ifname, bridge); | |
8200 | nl80211_remove_iface(drv, ifidx); | |
8201 | os_free(new_bss); | |
8202 | return -1; | |
8203 | } | |
8204 | ||
22a7c9d7 | 8205 | if (type == WPA_IF_AP_BSS) { |
c81eff1a BG |
8206 | if (linux_set_iface_flags(drv->global->ioctl_sock, ifname, 1)) |
8207 | { | |
34f2f814 | 8208 | nl80211_remove_iface(drv, ifidx); |
07179987 | 8209 | os_free(new_bss); |
22a7c9d7 JM |
8210 | return -1; |
8211 | } | |
a2e40bb6 | 8212 | os_strlcpy(new_bss->ifname, ifname, IFNAMSIZ); |
341eebee | 8213 | os_memcpy(new_bss->addr, if_addr, ETH_ALEN); |
a2e40bb6 FF |
8214 | new_bss->ifindex = ifidx; |
8215 | new_bss->drv = drv; | |
8216 | new_bss->next = drv->first_bss.next; | |
a7a6af4c | 8217 | new_bss->freq = drv->first_bss.freq; |
a5e1eb20 | 8218 | new_bss->ctx = bss_ctx; |
a2e40bb6 FF |
8219 | drv->first_bss.next = new_bss; |
8220 | if (drv_priv) | |
8221 | *drv_priv = new_bss; | |
cc7a48d1 | 8222 | nl80211_init_bss(new_bss); |
3dd1d890 YAP |
8223 | |
8224 | /* Subscribe management frames for this WPA_IF_AP_BSS */ | |
8225 | if (nl80211_setup_ap(new_bss)) | |
8226 | return -1; | |
22a7c9d7 JM |
8227 | } |
8228 | #endif /* HOSTAPD */ | |
8229 | ||
ff6a158b JM |
8230 | if (drv->global) |
8231 | drv->global->if_add_ifindex = ifidx; | |
8232 | ||
22a7c9d7 JM |
8233 | return 0; |
8234 | } | |
8235 | ||
8236 | ||
9ebce9c5 | 8237 | static int wpa_driver_nl80211_if_remove(struct i802_bss *bss, |
22a7c9d7 JM |
8238 | enum wpa_driver_if_type type, |
8239 | const char *ifname) | |
8240 | { | |
a2e40bb6 | 8241 | struct wpa_driver_nl80211_data *drv = bss->drv; |
22a7c9d7 JM |
8242 | int ifindex = if_nametoindex(ifname); |
8243 | ||
e748062b JM |
8244 | wpa_printf(MSG_DEBUG, "nl80211: %s(type=%d ifname=%s) ifindex=%d", |
8245 | __func__, type, ifname, ifindex); | |
8246 | if (ifindex <= 0) | |
8247 | return -1; | |
e17a2477 | 8248 | |
c34e618d FF |
8249 | nl80211_remove_iface(drv, ifindex); |
8250 | ||
e17a2477 | 8251 | #ifdef HOSTAPD |
c34e618d FF |
8252 | if (type != WPA_IF_AP_BSS) |
8253 | return 0; | |
8254 | ||
e17a2477 | 8255 | if (bss->added_if_into_bridge) { |
c81eff1a BG |
8256 | if (linux_br_del_if(drv->global->ioctl_sock, bss->brname, |
8257 | bss->ifname) < 0) | |
e17a2477 JM |
8258 | wpa_printf(MSG_INFO, "nl80211: Failed to remove " |
8259 | "interface %s from bridge %s: %s", | |
8260 | bss->ifname, bss->brname, strerror(errno)); | |
8261 | } | |
8262 | if (bss->added_bridge) { | |
c81eff1a | 8263 | if (linux_br_del(drv->global->ioctl_sock, bss->brname) < 0) |
e17a2477 JM |
8264 | wpa_printf(MSG_INFO, "nl80211: Failed to remove " |
8265 | "bridge %s: %s", | |
8266 | bss->brname, strerror(errno)); | |
8267 | } | |
a2e40bb6 FF |
8268 | |
8269 | if (bss != &drv->first_bss) { | |
8546ea19 | 8270 | struct i802_bss *tbss; |
a2e40bb6 | 8271 | |
8546ea19 JM |
8272 | for (tbss = &drv->first_bss; tbss; tbss = tbss->next) { |
8273 | if (tbss->next == bss) { | |
8274 | tbss->next = bss->next; | |
3dd1d890 YAP |
8275 | /* Unsubscribe management frames */ |
8276 | nl80211_teardown_ap(bss); | |
cc7a48d1 | 8277 | nl80211_destroy_bss(bss); |
8546ea19 JM |
8278 | os_free(bss); |
8279 | bss = NULL; | |
8280 | break; | |
8281 | } | |
22a7c9d7 | 8282 | } |
8546ea19 JM |
8283 | if (bss) |
8284 | wpa_printf(MSG_INFO, "nl80211: %s - could not find " | |
8285 | "BSS %p in the list", __func__, bss); | |
22a7c9d7 JM |
8286 | } |
8287 | #endif /* HOSTAPD */ | |
8288 | ||
8289 | return 0; | |
8290 | } | |
8291 | ||
8292 | ||
55777702 JM |
8293 | static int cookie_handler(struct nl_msg *msg, void *arg) |
8294 | { | |
8295 | struct nlattr *tb[NL80211_ATTR_MAX + 1]; | |
8296 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); | |
8297 | u64 *cookie = arg; | |
8298 | nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), | |
8299 | genlmsg_attrlen(gnlh, 0), NULL); | |
8300 | if (tb[NL80211_ATTR_COOKIE]) | |
8301 | *cookie = nla_get_u64(tb[NL80211_ATTR_COOKIE]); | |
8302 | return NL_SKIP; | |
8303 | } | |
8304 | ||
8305 | ||
88df0ef7 | 8306 | static int nl80211_send_frame_cmd(struct i802_bss *bss, |
5dfca53f JB |
8307 | unsigned int freq, unsigned int wait, |
8308 | const u8 *buf, size_t buf_len, | |
88df0ef7 JB |
8309 | u64 *cookie_out, int no_cck, int no_ack, |
8310 | int offchanok) | |
9884f9cc | 8311 | { |
88df0ef7 | 8312 | struct wpa_driver_nl80211_data *drv = bss->drv; |
9884f9cc JB |
8313 | struct nl_msg *msg; |
8314 | u64 cookie; | |
8315 | int ret = -1; | |
8316 | ||
8317 | msg = nlmsg_alloc(); | |
8318 | if (!msg) | |
8319 | return -1; | |
8320 | ||
2e3e4566 JM |
8321 | wpa_printf(MSG_DEBUG, "nl80211: CMD_FRAME freq=%u wait=%u no_cck=%d " |
8322 | "no_ack=%d offchanok=%d", | |
8323 | freq, wait, no_cck, no_ack, offchanok); | |
9fb04070 | 8324 | nl80211_cmd(drv, msg, 0, NL80211_CMD_FRAME); |
9884f9cc | 8325 | |
88df0ef7 | 8326 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, bss->ifindex); |
9884f9cc | 8327 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_FREQ, freq); |
9db931ed JM |
8328 | if (wait) |
8329 | NLA_PUT_U32(msg, NL80211_ATTR_DURATION, wait); | |
b9fd8ce8 | 8330 | if (offchanok && (drv->capa.flags & WPA_DRIVER_FLAGS_OFFCHANNEL_TX)) |
88df0ef7 | 8331 | NLA_PUT_FLAG(msg, NL80211_ATTR_OFFCHANNEL_TX_OK); |
b106173a JM |
8332 | if (no_cck) |
8333 | NLA_PUT_FLAG(msg, NL80211_ATTR_TX_NO_CCK_RATE); | |
ddc53271 JM |
8334 | if (no_ack) |
8335 | NLA_PUT_FLAG(msg, NL80211_ATTR_DONT_WAIT_FOR_ACK); | |
970fa12e | 8336 | |
9884f9cc JB |
8337 | NLA_PUT(msg, NL80211_ATTR_FRAME, buf_len, buf); |
8338 | ||
8339 | cookie = 0; | |
8340 | ret = send_and_recv_msgs(drv, msg, cookie_handler, &cookie); | |
8341 | msg = NULL; | |
8342 | if (ret) { | |
8343 | wpa_printf(MSG_DEBUG, "nl80211: Frame command failed: ret=%d " | |
a05225c8 JM |
8344 | "(%s) (freq=%u wait=%u)", ret, strerror(-ret), |
8345 | freq, wait); | |
9884f9cc JB |
8346 | goto nla_put_failure; |
8347 | } | |
ddc53271 JM |
8348 | wpa_printf(MSG_DEBUG, "nl80211: Frame TX command accepted%s; " |
8349 | "cookie 0x%llx", no_ack ? " (no ACK)" : "", | |
8350 | (long long unsigned int) cookie); | |
9884f9cc JB |
8351 | |
8352 | if (cookie_out) | |
ddc53271 | 8353 | *cookie_out = no_ack ? (u64) -1 : cookie; |
9884f9cc JB |
8354 | |
8355 | nla_put_failure: | |
8356 | nlmsg_free(msg); | |
8357 | return ret; | |
8358 | } | |
8359 | ||
8360 | ||
9ebce9c5 JM |
8361 | static int wpa_driver_nl80211_send_action(struct i802_bss *bss, |
8362 | unsigned int freq, | |
190b9062 | 8363 | unsigned int wait_time, |
58f6fbe0 JM |
8364 | const u8 *dst, const u8 *src, |
8365 | const u8 *bssid, | |
b106173a JM |
8366 | const u8 *data, size_t data_len, |
8367 | int no_cck) | |
58f6fbe0 | 8368 | { |
a2e40bb6 | 8369 | struct wpa_driver_nl80211_data *drv = bss->drv; |
58f6fbe0 | 8370 | int ret = -1; |
58f6fbe0 JM |
8371 | u8 *buf; |
8372 | struct ieee80211_hdr *hdr; | |
58f6fbe0 | 8373 | |
5dfca53f | 8374 | wpa_printf(MSG_DEBUG, "nl80211: Send Action frame (ifindex=%d, " |
55231068 JM |
8375 | "freq=%u MHz wait=%d ms no_cck=%d)", |
8376 | drv->ifindex, freq, wait_time, no_cck); | |
58f6fbe0 JM |
8377 | |
8378 | buf = os_zalloc(24 + data_len); | |
8379 | if (buf == NULL) | |
8380 | return ret; | |
8381 | os_memcpy(buf + 24, data, data_len); | |
8382 | hdr = (struct ieee80211_hdr *) buf; | |
8383 | hdr->frame_control = | |
8384 | IEEE80211_FC(WLAN_FC_TYPE_MGMT, WLAN_FC_STYPE_ACTION); | |
8385 | os_memcpy(hdr->addr1, dst, ETH_ALEN); | |
8386 | os_memcpy(hdr->addr2, src, ETH_ALEN); | |
8387 | os_memcpy(hdr->addr3, bssid, ETH_ALEN); | |
8388 | ||
b1f625e0 | 8389 | if (is_ap_interface(drv->nlmode)) |
9ebce9c5 JM |
8390 | ret = wpa_driver_nl80211_send_mlme(bss, buf, 24 + data_len, |
8391 | 0, freq, no_cck, 1, | |
8392 | wait_time); | |
9884f9cc | 8393 | else |
88df0ef7 | 8394 | ret = nl80211_send_frame_cmd(bss, freq, wait_time, buf, |
5dfca53f | 8395 | 24 + data_len, |
b106173a | 8396 | &drv->send_action_cookie, |
88df0ef7 | 8397 | no_cck, 0, 1); |
58f6fbe0 | 8398 | |
f8bf1421 | 8399 | os_free(buf); |
58f6fbe0 JM |
8400 | return ret; |
8401 | } | |
8402 | ||
8403 | ||
5dfca53f JB |
8404 | static void wpa_driver_nl80211_send_action_cancel_wait(void *priv) |
8405 | { | |
8406 | struct i802_bss *bss = priv; | |
8407 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
8408 | struct nl_msg *msg; | |
8409 | int ret; | |
8410 | ||
8411 | msg = nlmsg_alloc(); | |
8412 | if (!msg) | |
8413 | return; | |
8414 | ||
9fb04070 | 8415 | nl80211_cmd(drv, msg, 0, NL80211_CMD_FRAME_WAIT_CANCEL); |
5dfca53f JB |
8416 | |
8417 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, drv->ifindex); | |
8418 | NLA_PUT_U64(msg, NL80211_ATTR_COOKIE, drv->send_action_cookie); | |
8419 | ||
8420 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); | |
8421 | msg = NULL; | |
8422 | if (ret) | |
8423 | wpa_printf(MSG_DEBUG, "nl80211: wait cancel failed: ret=%d " | |
8424 | "(%s)", ret, strerror(-ret)); | |
8425 | ||
8426 | nla_put_failure: | |
8427 | nlmsg_free(msg); | |
8428 | } | |
8429 | ||
8430 | ||
55777702 JM |
8431 | static int wpa_driver_nl80211_remain_on_channel(void *priv, unsigned int freq, |
8432 | unsigned int duration) | |
8433 | { | |
a2e40bb6 FF |
8434 | struct i802_bss *bss = priv; |
8435 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
55777702 JM |
8436 | struct nl_msg *msg; |
8437 | int ret; | |
8438 | u64 cookie; | |
8439 | ||
8440 | msg = nlmsg_alloc(); | |
8441 | if (!msg) | |
8442 | return -1; | |
8443 | ||
9fb04070 | 8444 | nl80211_cmd(drv, msg, 0, NL80211_CMD_REMAIN_ON_CHANNEL); |
55777702 JM |
8445 | |
8446 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, drv->ifindex); | |
8447 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_FREQ, freq); | |
8448 | NLA_PUT_U32(msg, NL80211_ATTR_DURATION, duration); | |
8449 | ||
8450 | cookie = 0; | |
8451 | ret = send_and_recv_msgs(drv, msg, cookie_handler, &cookie); | |
5883168a | 8452 | msg = NULL; |
55777702 JM |
8453 | if (ret == 0) { |
8454 | wpa_printf(MSG_DEBUG, "nl80211: Remain-on-channel cookie " | |
8455 | "0x%llx for freq=%u MHz duration=%u", | |
8456 | (long long unsigned int) cookie, freq, duration); | |
8457 | drv->remain_on_chan_cookie = cookie; | |
531f0331 | 8458 | drv->pending_remain_on_chan = 1; |
55777702 JM |
8459 | return 0; |
8460 | } | |
8461 | wpa_printf(MSG_DEBUG, "nl80211: Failed to request remain-on-channel " | |
15ed5535 JM |
8462 | "(freq=%d duration=%u): %d (%s)", |
8463 | freq, duration, ret, strerror(-ret)); | |
55777702 | 8464 | nla_put_failure: |
5883168a | 8465 | nlmsg_free(msg); |
55777702 JM |
8466 | return -1; |
8467 | } | |
8468 | ||
8469 | ||
8470 | static int wpa_driver_nl80211_cancel_remain_on_channel(void *priv) | |
8471 | { | |
a2e40bb6 FF |
8472 | struct i802_bss *bss = priv; |
8473 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
55777702 JM |
8474 | struct nl_msg *msg; |
8475 | int ret; | |
8476 | ||
8477 | if (!drv->pending_remain_on_chan) { | |
8478 | wpa_printf(MSG_DEBUG, "nl80211: No pending remain-on-channel " | |
8479 | "to cancel"); | |
8480 | return -1; | |
8481 | } | |
8482 | ||
8483 | wpa_printf(MSG_DEBUG, "nl80211: Cancel remain-on-channel with cookie " | |
8484 | "0x%llx", | |
8485 | (long long unsigned int) drv->remain_on_chan_cookie); | |
8486 | ||
8487 | msg = nlmsg_alloc(); | |
8488 | if (!msg) | |
8489 | return -1; | |
8490 | ||
9fb04070 | 8491 | nl80211_cmd(drv, msg, 0, NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL); |
55777702 JM |
8492 | |
8493 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, drv->ifindex); | |
8494 | NLA_PUT_U64(msg, NL80211_ATTR_COOKIE, drv->remain_on_chan_cookie); | |
8495 | ||
8496 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); | |
5883168a | 8497 | msg = NULL; |
55777702 JM |
8498 | if (ret == 0) |
8499 | return 0; | |
8500 | wpa_printf(MSG_DEBUG, "nl80211: Failed to cancel remain-on-channel: " | |
8501 | "%d (%s)", ret, strerror(-ret)); | |
8502 | nla_put_failure: | |
5883168a | 8503 | nlmsg_free(msg); |
55777702 JM |
8504 | return -1; |
8505 | } | |
8506 | ||
8507 | ||
9ebce9c5 | 8508 | static int wpa_driver_nl80211_probe_req_report(struct i802_bss *bss, int report) |
504e905c | 8509 | { |
a2e40bb6 | 8510 | struct wpa_driver_nl80211_data *drv = bss->drv; |
504e905c | 8511 | |
5582a5d1 | 8512 | if (!report) { |
0d891981 JM |
8513 | if (bss->nl_preq && drv->device_ap_sme && |
8514 | is_ap_interface(drv->nlmode)) { | |
8515 | /* | |
8516 | * Do not disable Probe Request reporting that was | |
8517 | * enabled in nl80211_setup_ap(). | |
8518 | */ | |
8519 | wpa_printf(MSG_DEBUG, "nl80211: Skip disabling of " | |
8520 | "Probe Request reporting nl_preq=%p while " | |
8521 | "in AP mode", bss->nl_preq); | |
8522 | } else if (bss->nl_preq) { | |
36488c05 JM |
8523 | wpa_printf(MSG_DEBUG, "nl80211: Disable Probe Request " |
8524 | "reporting nl_preq=%p", bss->nl_preq); | |
5582a5d1 | 8525 | eloop_unregister_read_sock( |
481234cf | 8526 | nl_socket_get_fd(bss->nl_preq)); |
221a59c9 | 8527 | nl_destroy_handles(&bss->nl_preq); |
5582a5d1 JB |
8528 | } |
8529 | return 0; | |
8530 | } | |
8531 | ||
481234cf | 8532 | if (bss->nl_preq) { |
5582a5d1 | 8533 | wpa_printf(MSG_DEBUG, "nl80211: Probe Request reporting " |
36488c05 | 8534 | "already on! nl_preq=%p", bss->nl_preq); |
5582a5d1 JB |
8535 | return 0; |
8536 | } | |
8537 | ||
481234cf JM |
8538 | bss->nl_preq = nl_create_handle(drv->global->nl_cb, "preq"); |
8539 | if (bss->nl_preq == NULL) | |
5582a5d1 | 8540 | return -1; |
36488c05 JM |
8541 | wpa_printf(MSG_DEBUG, "nl80211: Enable Probe Request " |
8542 | "reporting nl_preq=%p", bss->nl_preq); | |
5582a5d1 | 8543 | |
481234cf | 8544 | if (nl80211_register_frame(bss, bss->nl_preq, |
5582a5d1 JB |
8545 | (WLAN_FC_TYPE_MGMT << 2) | |
8546 | (WLAN_FC_STYPE_PROBE_REQ << 4), | |
a92dfde8 JB |
8547 | NULL, 0) < 0) |
8548 | goto out_err; | |
5582a5d1 | 8549 | |
481234cf | 8550 | eloop_register_read_sock(nl_socket_get_fd(bss->nl_preq), |
a11241fa | 8551 | wpa_driver_nl80211_event_receive, bss->nl_cb, |
481234cf | 8552 | bss->nl_preq); |
5582a5d1 | 8553 | |
504e905c | 8554 | return 0; |
5582a5d1 | 8555 | |
a92dfde8 | 8556 | out_err: |
221a59c9 | 8557 | nl_destroy_handles(&bss->nl_preq); |
5582a5d1 | 8558 | return -1; |
504e905c JM |
8559 | } |
8560 | ||
8561 | ||
4e5cb1a3 JM |
8562 | static int nl80211_disable_11b_rates(struct wpa_driver_nl80211_data *drv, |
8563 | int ifindex, int disabled) | |
8564 | { | |
8565 | struct nl_msg *msg; | |
8566 | struct nlattr *bands, *band; | |
8567 | int ret; | |
8568 | ||
8569 | msg = nlmsg_alloc(); | |
8570 | if (!msg) | |
8571 | return -1; | |
8572 | ||
9fb04070 | 8573 | nl80211_cmd(drv, msg, 0, NL80211_CMD_SET_TX_BITRATE_MASK); |
4e5cb1a3 JM |
8574 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, ifindex); |
8575 | ||
8576 | bands = nla_nest_start(msg, NL80211_ATTR_TX_RATES); | |
8577 | if (!bands) | |
8578 | goto nla_put_failure; | |
8579 | ||
8580 | /* | |
8581 | * Disable 2 GHz rates 1, 2, 5.5, 11 Mbps by masking out everything | |
8582 | * else apart from 6, 9, 12, 18, 24, 36, 48, 54 Mbps from non-MCS | |
8583 | * rates. All 5 GHz rates are left enabled. | |
8584 | */ | |
8585 | band = nla_nest_start(msg, NL80211_BAND_2GHZ); | |
8586 | if (!band) | |
8587 | goto nla_put_failure; | |
1dea5882 JM |
8588 | if (disabled) { |
8589 | NLA_PUT(msg, NL80211_TXRATE_LEGACY, 8, | |
8590 | "\x0c\x12\x18\x24\x30\x48\x60\x6c"); | |
8591 | } | |
4e5cb1a3 JM |
8592 | nla_nest_end(msg, band); |
8593 | ||
8594 | nla_nest_end(msg, bands); | |
8595 | ||
8596 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); | |
8597 | msg = NULL; | |
8598 | if (ret) { | |
8599 | wpa_printf(MSG_DEBUG, "nl80211: Set TX rates failed: ret=%d " | |
8600 | "(%s)", ret, strerror(-ret)); | |
1d0c6fb1 JM |
8601 | } else |
8602 | drv->disabled_11b_rates = disabled; | |
4e5cb1a3 JM |
8603 | |
8604 | return ret; | |
8605 | ||
8606 | nla_put_failure: | |
8607 | nlmsg_free(msg); | |
8608 | return -1; | |
8609 | } | |
8610 | ||
8611 | ||
af473088 JM |
8612 | static int wpa_driver_nl80211_deinit_ap(void *priv) |
8613 | { | |
a2e40bb6 FF |
8614 | struct i802_bss *bss = priv; |
8615 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
b1f625e0 | 8616 | if (!is_ap_interface(drv->nlmode)) |
af473088 JM |
8617 | return -1; |
8618 | wpa_driver_nl80211_del_beacon(drv); | |
b1f625e0 | 8619 | return wpa_driver_nl80211_set_mode(priv, NL80211_IFTYPE_STATION); |
af473088 JM |
8620 | } |
8621 | ||
8622 | ||
3c29244e EP |
8623 | static int wpa_driver_nl80211_deinit_p2p_cli(void *priv) |
8624 | { | |
8625 | struct i802_bss *bss = priv; | |
8626 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
8627 | if (drv->nlmode != NL80211_IFTYPE_P2P_CLIENT) | |
8628 | return -1; | |
8629 | return wpa_driver_nl80211_set_mode(priv, NL80211_IFTYPE_STATION); | |
8630 | } | |
8631 | ||
8632 | ||
207ef3fb JM |
8633 | static void wpa_driver_nl80211_resume(void *priv) |
8634 | { | |
a2e40bb6 FF |
8635 | struct i802_bss *bss = priv; |
8636 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
c81eff1a | 8637 | if (linux_set_iface_flags(drv->global->ioctl_sock, bss->ifname, 1)) { |
207ef3fb JM |
8638 | wpa_printf(MSG_DEBUG, "nl80211: Failed to set interface up on " |
8639 | "resume event"); | |
8640 | } | |
8641 | } | |
8642 | ||
8643 | ||
7b90c16a JM |
8644 | static int nl80211_send_ft_action(void *priv, u8 action, const u8 *target_ap, |
8645 | const u8 *ies, size_t ies_len) | |
8646 | { | |
8647 | struct i802_bss *bss = priv; | |
8648 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
8649 | int ret; | |
8650 | u8 *data, *pos; | |
8651 | size_t data_len; | |
341eebee | 8652 | const u8 *own_addr = bss->addr; |
7b90c16a JM |
8653 | |
8654 | if (action != 1) { | |
8655 | wpa_printf(MSG_ERROR, "nl80211: Unsupported send_ft_action " | |
8656 | "action %d", action); | |
8657 | return -1; | |
8658 | } | |
8659 | ||
8660 | /* | |
8661 | * Action frame payload: | |
8662 | * Category[1] = 6 (Fast BSS Transition) | |
8663 | * Action[1] = 1 (Fast BSS Transition Request) | |
8664 | * STA Address | |
8665 | * Target AP Address | |
8666 | * FT IEs | |
8667 | */ | |
8668 | ||
73fc617d JM |
8669 | data_len = 2 + 2 * ETH_ALEN + ies_len; |
8670 | data = os_malloc(data_len); | |
7b90c16a JM |
8671 | if (data == NULL) |
8672 | return -1; | |
8673 | pos = data; | |
8674 | *pos++ = 0x06; /* FT Action category */ | |
8675 | *pos++ = action; | |
8676 | os_memcpy(pos, own_addr, ETH_ALEN); | |
8677 | pos += ETH_ALEN; | |
8678 | os_memcpy(pos, target_ap, ETH_ALEN); | |
8679 | pos += ETH_ALEN; | |
8680 | os_memcpy(pos, ies, ies_len); | |
8681 | ||
190b9062 JB |
8682 | ret = wpa_driver_nl80211_send_action(bss, drv->assoc_freq, 0, |
8683 | drv->bssid, own_addr, drv->bssid, | |
b106173a | 8684 | data, data_len, 0); |
7b90c16a JM |
8685 | os_free(data); |
8686 | ||
8687 | return ret; | |
8688 | } | |
8689 | ||
8690 | ||
b625473c JM |
8691 | static int nl80211_signal_monitor(void *priv, int threshold, int hysteresis) |
8692 | { | |
8693 | struct i802_bss *bss = priv; | |
8694 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
8695 | struct nl_msg *msg, *cqm = NULL; | |
f0494d0f | 8696 | int ret = -1; |
b625473c JM |
8697 | |
8698 | wpa_printf(MSG_DEBUG, "nl80211: Signal monitor threshold=%d " | |
8699 | "hysteresis=%d", threshold, hysteresis); | |
8700 | ||
8701 | msg = nlmsg_alloc(); | |
8702 | if (!msg) | |
8703 | return -1; | |
8704 | ||
9fb04070 | 8705 | nl80211_cmd(drv, msg, 0, NL80211_CMD_SET_CQM); |
b625473c JM |
8706 | |
8707 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, bss->ifindex); | |
8708 | ||
8709 | cqm = nlmsg_alloc(); | |
8710 | if (cqm == NULL) | |
21270bb4 | 8711 | goto nla_put_failure; |
b625473c JM |
8712 | |
8713 | NLA_PUT_U32(cqm, NL80211_ATTR_CQM_RSSI_THOLD, threshold); | |
8714 | NLA_PUT_U32(cqm, NL80211_ATTR_CQM_RSSI_HYST, hysteresis); | |
f0494d0f JM |
8715 | if (nla_put_nested(msg, NL80211_ATTR_CQM, cqm) < 0) |
8716 | goto nla_put_failure; | |
21270bb4 | 8717 | |
f0494d0f | 8718 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
b625473c JM |
8719 | msg = NULL; |
8720 | ||
8721 | nla_put_failure: | |
5883168a | 8722 | nlmsg_free(cqm); |
b625473c | 8723 | nlmsg_free(msg); |
f0494d0f | 8724 | return ret; |
b625473c JM |
8725 | } |
8726 | ||
8727 | ||
1c5c7273 PS |
8728 | static int nl80211_signal_poll(void *priv, struct wpa_signal_info *si) |
8729 | { | |
8730 | struct i802_bss *bss = priv; | |
8731 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
8732 | int res; | |
8733 | ||
8734 | os_memset(si, 0, sizeof(*si)); | |
8735 | res = nl80211_get_link_signal(drv, si); | |
8736 | if (res != 0) | |
8737 | return res; | |
8738 | ||
8739 | return nl80211_get_link_noise(drv, si); | |
8740 | } | |
8741 | ||
8742 | ||
57ebba59 JJ |
8743 | static int wpa_driver_nl80211_shared_freq(void *priv) |
8744 | { | |
8745 | struct i802_bss *bss = priv; | |
8746 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
8747 | struct wpa_driver_nl80211_data *driver; | |
8748 | int freq = 0; | |
8749 | ||
8750 | /* | |
8751 | * If the same PHY is in connected state with some other interface, | |
8752 | * then retrieve the assoc freq. | |
8753 | */ | |
8754 | wpa_printf(MSG_DEBUG, "nl80211: Get shared freq for PHY %s", | |
8755 | drv->phyname); | |
8756 | ||
8757 | dl_list_for_each(driver, &drv->global->interfaces, | |
8758 | struct wpa_driver_nl80211_data, list) { | |
8759 | if (drv == driver || | |
8760 | os_strcmp(drv->phyname, driver->phyname) != 0 || | |
8761 | !driver->associated) | |
8762 | continue; | |
8763 | ||
8764 | wpa_printf(MSG_DEBUG, "nl80211: Found a match for PHY %s - %s " | |
8765 | MACSTR, | |
8766 | driver->phyname, driver->first_bss.ifname, | |
341eebee | 8767 | MAC2STR(driver->first_bss.addr)); |
d3bd0f05 JJ |
8768 | if (is_ap_interface(driver->nlmode)) |
8769 | freq = driver->first_bss.freq; | |
8770 | else | |
8771 | freq = nl80211_get_assoc_freq(driver); | |
57ebba59 JJ |
8772 | wpa_printf(MSG_DEBUG, "nl80211: Shared freq for PHY %s: %d", |
8773 | drv->phyname, freq); | |
8774 | } | |
8775 | ||
8776 | if (!freq) | |
8777 | wpa_printf(MSG_DEBUG, "nl80211: No shared interface for " | |
8778 | "PHY (%s) in associated state", drv->phyname); | |
8779 | ||
8780 | return freq; | |
8781 | } | |
8782 | ||
8783 | ||
b91ab76e JM |
8784 | static int nl80211_send_frame(void *priv, const u8 *data, size_t data_len, |
8785 | int encrypt) | |
8786 | { | |
8787 | struct i802_bss *bss = priv; | |
55231068 JM |
8788 | return wpa_driver_nl80211_send_frame(bss, data, data_len, encrypt, 0, |
8789 | 0, 0, 0, 0); | |
b91ab76e JM |
8790 | } |
8791 | ||
8792 | ||
c55f774d JM |
8793 | static int nl80211_set_param(void *priv, const char *param) |
8794 | { | |
c55f774d JM |
8795 | wpa_printf(MSG_DEBUG, "nl80211: driver param='%s'", param); |
8796 | if (param == NULL) | |
8797 | return 0; | |
8798 | ||
8799 | #ifdef CONFIG_P2P | |
8800 | if (os_strstr(param, "use_p2p_group_interface=1")) { | |
482856c8 JM |
8801 | struct i802_bss *bss = priv; |
8802 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
8803 | ||
c55f774d JM |
8804 | wpa_printf(MSG_DEBUG, "nl80211: Use separate P2P group " |
8805 | "interface"); | |
8806 | drv->capa.flags |= WPA_DRIVER_FLAGS_P2P_CONCURRENT; | |
8807 | drv->capa.flags |= WPA_DRIVER_FLAGS_P2P_MGMT_AND_NON_P2P; | |
8808 | } | |
8809 | #endif /* CONFIG_P2P */ | |
8810 | ||
8811 | return 0; | |
8812 | } | |
8813 | ||
8814 | ||
f2ed8023 JM |
8815 | static void * nl80211_global_init(void) |
8816 | { | |
8817 | struct nl80211_global *global; | |
36d84860 BG |
8818 | struct netlink_config *cfg; |
8819 | ||
f2ed8023 JM |
8820 | global = os_zalloc(sizeof(*global)); |
8821 | if (global == NULL) | |
8822 | return NULL; | |
c81eff1a | 8823 | global->ioctl_sock = -1; |
f2ed8023 | 8824 | dl_list_init(&global->interfaces); |
ff6a158b | 8825 | global->if_add_ifindex = -1; |
36d84860 BG |
8826 | |
8827 | cfg = os_zalloc(sizeof(*cfg)); | |
8828 | if (cfg == NULL) | |
8829 | goto err; | |
8830 | ||
8831 | cfg->ctx = global; | |
8832 | cfg->newlink_cb = wpa_driver_nl80211_event_rtm_newlink; | |
8833 | cfg->dellink_cb = wpa_driver_nl80211_event_rtm_dellink; | |
8834 | global->netlink = netlink_init(cfg); | |
8835 | if (global->netlink == NULL) { | |
8836 | os_free(cfg); | |
8837 | goto err; | |
8838 | } | |
8839 | ||
2a7b66f5 BG |
8840 | if (wpa_driver_nl80211_init_nl_global(global) < 0) |
8841 | goto err; | |
8842 | ||
c81eff1a BG |
8843 | global->ioctl_sock = socket(PF_INET, SOCK_DGRAM, 0); |
8844 | if (global->ioctl_sock < 0) { | |
8845 | perror("socket(PF_INET,SOCK_DGRAM)"); | |
8846 | goto err; | |
8847 | } | |
8848 | ||
f2ed8023 | 8849 | return global; |
36d84860 BG |
8850 | |
8851 | err: | |
8852 | nl80211_global_deinit(global); | |
8853 | return NULL; | |
f2ed8023 JM |
8854 | } |
8855 | ||
8856 | ||
8857 | static void nl80211_global_deinit(void *priv) | |
8858 | { | |
8859 | struct nl80211_global *global = priv; | |
8860 | if (global == NULL) | |
8861 | return; | |
8862 | if (!dl_list_empty(&global->interfaces)) { | |
8863 | wpa_printf(MSG_ERROR, "nl80211: %u interface(s) remain at " | |
8864 | "nl80211_global_deinit", | |
8865 | dl_list_len(&global->interfaces)); | |
8866 | } | |
36d84860 BG |
8867 | |
8868 | if (global->netlink) | |
8869 | netlink_deinit(global->netlink); | |
8870 | ||
276e2d67 BG |
8871 | nl_destroy_handles(&global->nl); |
8872 | ||
481234cf | 8873 | if (global->nl_event) { |
d6c9aab8 | 8874 | eloop_unregister_read_sock( |
481234cf | 8875 | nl_socket_get_fd(global->nl_event)); |
d6c9aab8 JB |
8876 | nl_destroy_handles(&global->nl_event); |
8877 | } | |
8878 | ||
8879 | nl_cb_put(global->nl_cb); | |
2a7b66f5 | 8880 | |
c81eff1a BG |
8881 | if (global->ioctl_sock >= 0) |
8882 | close(global->ioctl_sock); | |
8883 | ||
f2ed8023 JM |
8884 | os_free(global); |
8885 | } | |
8886 | ||
8887 | ||
6859f1cb BG |
8888 | static const char * nl80211_get_radio_name(void *priv) |
8889 | { | |
8890 | struct i802_bss *bss = priv; | |
8891 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
8892 | return drv->phyname; | |
8893 | } | |
8894 | ||
8895 | ||
a6efc65d JM |
8896 | static int nl80211_pmkid(struct i802_bss *bss, int cmd, const u8 *bssid, |
8897 | const u8 *pmkid) | |
8898 | { | |
8899 | struct nl_msg *msg; | |
8900 | ||
8901 | msg = nlmsg_alloc(); | |
8902 | if (!msg) | |
8903 | return -ENOMEM; | |
8904 | ||
9fb04070 | 8905 | nl80211_cmd(bss->drv, msg, 0, cmd); |
a6efc65d JM |
8906 | |
8907 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, if_nametoindex(bss->ifname)); | |
8908 | if (pmkid) | |
8909 | NLA_PUT(msg, NL80211_ATTR_PMKID, 16, pmkid); | |
8910 | if (bssid) | |
8911 | NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid); | |
8912 | ||
8913 | return send_and_recv_msgs(bss->drv, msg, NULL, NULL); | |
8914 | nla_put_failure: | |
9e088e74 | 8915 | nlmsg_free(msg); |
a6efc65d JM |
8916 | return -ENOBUFS; |
8917 | } | |
8918 | ||
8919 | ||
8920 | static int nl80211_add_pmkid(void *priv, const u8 *bssid, const u8 *pmkid) | |
8921 | { | |
8922 | struct i802_bss *bss = priv; | |
8923 | wpa_printf(MSG_DEBUG, "nl80211: Add PMKID for " MACSTR, MAC2STR(bssid)); | |
8924 | return nl80211_pmkid(bss, NL80211_CMD_SET_PMKSA, bssid, pmkid); | |
8925 | } | |
8926 | ||
8927 | ||
8928 | static int nl80211_remove_pmkid(void *priv, const u8 *bssid, const u8 *pmkid) | |
8929 | { | |
8930 | struct i802_bss *bss = priv; | |
8931 | wpa_printf(MSG_DEBUG, "nl80211: Delete PMKID for " MACSTR, | |
8932 | MAC2STR(bssid)); | |
8933 | return nl80211_pmkid(bss, NL80211_CMD_DEL_PMKSA, bssid, pmkid); | |
8934 | } | |
8935 | ||
8936 | ||
8937 | static int nl80211_flush_pmkid(void *priv) | |
8938 | { | |
8939 | struct i802_bss *bss = priv; | |
8940 | wpa_printf(MSG_DEBUG, "nl80211: Flush PMKIDs"); | |
8941 | return nl80211_pmkid(bss, NL80211_CMD_FLUSH_PMKSA, NULL, NULL); | |
8942 | } | |
8943 | ||
8944 | ||
b14a210c JB |
8945 | static void nl80211_set_rekey_info(void *priv, const u8 *kek, const u8 *kck, |
8946 | const u8 *replay_ctr) | |
8947 | { | |
8948 | struct i802_bss *bss = priv; | |
8949 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
8950 | struct nlattr *replay_nested; | |
8951 | struct nl_msg *msg; | |
8952 | ||
8953 | msg = nlmsg_alloc(); | |
8954 | if (!msg) | |
8955 | return; | |
8956 | ||
9fb04070 | 8957 | nl80211_cmd(drv, msg, 0, NL80211_CMD_SET_REKEY_OFFLOAD); |
b14a210c JB |
8958 | |
8959 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, bss->ifindex); | |
8960 | ||
8961 | replay_nested = nla_nest_start(msg, NL80211_ATTR_REKEY_DATA); | |
8962 | if (!replay_nested) | |
8963 | goto nla_put_failure; | |
8964 | ||
8965 | NLA_PUT(msg, NL80211_REKEY_DATA_KEK, NL80211_KEK_LEN, kek); | |
8966 | NLA_PUT(msg, NL80211_REKEY_DATA_KCK, NL80211_KCK_LEN, kck); | |
8967 | NLA_PUT(msg, NL80211_REKEY_DATA_REPLAY_CTR, NL80211_REPLAY_CTR_LEN, | |
8968 | replay_ctr); | |
8969 | ||
8970 | nla_nest_end(msg, replay_nested); | |
8971 | ||
8972 | send_and_recv_msgs(drv, msg, NULL, NULL); | |
8973 | return; | |
8974 | nla_put_failure: | |
8975 | nlmsg_free(msg); | |
8976 | } | |
8977 | ||
8978 | ||
39718852 JB |
8979 | static void nl80211_send_null_frame(struct i802_bss *bss, const u8 *own_addr, |
8980 | const u8 *addr, int qos) | |
bcf24348 | 8981 | { |
39718852 JB |
8982 | /* send data frame to poll STA and check whether |
8983 | * this frame is ACKed */ | |
bcf24348 JB |
8984 | struct { |
8985 | struct ieee80211_hdr hdr; | |
8986 | u16 qos_ctl; | |
8987 | } STRUCT_PACKED nulldata; | |
8988 | size_t size; | |
8989 | ||
8990 | /* Send data frame to poll STA and check whether this frame is ACKed */ | |
8991 | ||
8992 | os_memset(&nulldata, 0, sizeof(nulldata)); | |
8993 | ||
8994 | if (qos) { | |
8995 | nulldata.hdr.frame_control = | |
8996 | IEEE80211_FC(WLAN_FC_TYPE_DATA, | |
8997 | WLAN_FC_STYPE_QOS_NULL); | |
8998 | size = sizeof(nulldata); | |
8999 | } else { | |
9000 | nulldata.hdr.frame_control = | |
9001 | IEEE80211_FC(WLAN_FC_TYPE_DATA, | |
9002 | WLAN_FC_STYPE_NULLFUNC); | |
9003 | size = sizeof(struct ieee80211_hdr); | |
9004 | } | |
9005 | ||
9006 | nulldata.hdr.frame_control |= host_to_le16(WLAN_FC_FROMDS); | |
9007 | os_memcpy(nulldata.hdr.IEEE80211_DA_FROMDS, addr, ETH_ALEN); | |
9008 | os_memcpy(nulldata.hdr.IEEE80211_BSSID_FROMDS, own_addr, ETH_ALEN); | |
9009 | os_memcpy(nulldata.hdr.IEEE80211_SA_FROMDS, own_addr, ETH_ALEN); | |
9010 | ||
9ebce9c5 JM |
9011 | if (wpa_driver_nl80211_send_mlme(bss, (u8 *) &nulldata, size, 0, 0, 0, |
9012 | 0, 0) < 0) | |
bcf24348 JB |
9013 | wpa_printf(MSG_DEBUG, "nl80211_send_null_frame: Failed to " |
9014 | "send poll frame"); | |
9015 | } | |
9016 | ||
39718852 JB |
9017 | static void nl80211_poll_client(void *priv, const u8 *own_addr, const u8 *addr, |
9018 | int qos) | |
9019 | { | |
9020 | struct i802_bss *bss = priv; | |
9021 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
9022 | struct nl_msg *msg; | |
9023 | ||
9024 | if (!drv->poll_command_supported) { | |
9025 | nl80211_send_null_frame(bss, own_addr, addr, qos); | |
9026 | return; | |
9027 | } | |
9028 | ||
9029 | msg = nlmsg_alloc(); | |
9030 | if (!msg) | |
9031 | return; | |
9032 | ||
9033 | nl80211_cmd(drv, msg, 0, NL80211_CMD_PROBE_CLIENT); | |
9034 | ||
9035 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, bss->ifindex); | |
9036 | NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, addr); | |
9037 | ||
9038 | send_and_recv_msgs(drv, msg, NULL, NULL); | |
9039 | return; | |
9040 | nla_put_failure: | |
9041 | nlmsg_free(msg); | |
9042 | } | |
9043 | ||
bcf24348 | 9044 | |
29f338af JM |
9045 | static int nl80211_set_power_save(struct i802_bss *bss, int enabled) |
9046 | { | |
9047 | struct nl_msg *msg; | |
9048 | ||
9049 | msg = nlmsg_alloc(); | |
9050 | if (!msg) | |
9051 | return -ENOMEM; | |
9052 | ||
9053 | nl80211_cmd(bss->drv, msg, 0, NL80211_CMD_SET_POWER_SAVE); | |
9054 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, bss->ifindex); | |
9055 | NLA_PUT_U32(msg, NL80211_ATTR_PS_STATE, | |
9056 | enabled ? NL80211_PS_ENABLED : NL80211_PS_DISABLED); | |
9057 | return send_and_recv_msgs(bss->drv, msg, NULL, NULL); | |
9058 | nla_put_failure: | |
9059 | nlmsg_free(msg); | |
9060 | return -ENOBUFS; | |
9061 | } | |
9062 | ||
9063 | ||
9064 | static int nl80211_set_p2p_powersave(void *priv, int legacy_ps, int opp_ps, | |
9065 | int ctwindow) | |
9066 | { | |
9067 | struct i802_bss *bss = priv; | |
9068 | ||
9069 | wpa_printf(MSG_DEBUG, "nl80211: set_p2p_powersave (legacy_ps=%d " | |
9070 | "opp_ps=%d ctwindow=%d)", legacy_ps, opp_ps, ctwindow); | |
9071 | ||
9072 | if (opp_ps != -1 || ctwindow != -1) | |
9073 | return -1; /* Not yet supported */ | |
9074 | ||
9075 | if (legacy_ps == -1) | |
9076 | return 0; | |
9077 | if (legacy_ps != 0 && legacy_ps != 1) | |
9078 | return -1; /* Not yet supported */ | |
9079 | ||
9080 | return nl80211_set_power_save(bss, legacy_ps); | |
9081 | } | |
9082 | ||
9083 | ||
03ea1786 AN |
9084 | #ifdef CONFIG_TDLS |
9085 | ||
9086 | static int nl80211_send_tdls_mgmt(void *priv, const u8 *dst, u8 action_code, | |
9087 | u8 dialog_token, u16 status_code, | |
9088 | const u8 *buf, size_t len) | |
9089 | { | |
9090 | struct i802_bss *bss = priv; | |
9091 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
9092 | struct nl_msg *msg; | |
9093 | ||
9094 | if (!(drv->capa.flags & WPA_DRIVER_FLAGS_TDLS_SUPPORT)) | |
9095 | return -EOPNOTSUPP; | |
9096 | ||
9097 | if (!dst) | |
9098 | return -EINVAL; | |
9099 | ||
9100 | msg = nlmsg_alloc(); | |
9101 | if (!msg) | |
9102 | return -ENOMEM; | |
9103 | ||
9104 | nl80211_cmd(drv, msg, 0, NL80211_CMD_TDLS_MGMT); | |
9105 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, drv->ifindex); | |
9106 | NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, dst); | |
9107 | NLA_PUT_U8(msg, NL80211_ATTR_TDLS_ACTION, action_code); | |
9108 | NLA_PUT_U8(msg, NL80211_ATTR_TDLS_DIALOG_TOKEN, dialog_token); | |
9109 | NLA_PUT_U16(msg, NL80211_ATTR_STATUS_CODE, status_code); | |
9110 | NLA_PUT(msg, NL80211_ATTR_IE, len, buf); | |
9111 | ||
9112 | return send_and_recv_msgs(drv, msg, NULL, NULL); | |
9113 | ||
9114 | nla_put_failure: | |
9115 | nlmsg_free(msg); | |
9116 | return -ENOBUFS; | |
9117 | } | |
9118 | ||
9119 | ||
9120 | static int nl80211_tdls_oper(void *priv, enum tdls_oper oper, const u8 *peer) | |
9121 | { | |
9122 | struct i802_bss *bss = priv; | |
9123 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
9124 | struct nl_msg *msg; | |
9125 | enum nl80211_tdls_operation nl80211_oper; | |
9126 | ||
9127 | if (!(drv->capa.flags & WPA_DRIVER_FLAGS_TDLS_SUPPORT)) | |
9128 | return -EOPNOTSUPP; | |
9129 | ||
9130 | switch (oper) { | |
9131 | case TDLS_DISCOVERY_REQ: | |
9132 | nl80211_oper = NL80211_TDLS_DISCOVERY_REQ; | |
9133 | break; | |
9134 | case TDLS_SETUP: | |
9135 | nl80211_oper = NL80211_TDLS_SETUP; | |
9136 | break; | |
9137 | case TDLS_TEARDOWN: | |
9138 | nl80211_oper = NL80211_TDLS_TEARDOWN; | |
9139 | break; | |
9140 | case TDLS_ENABLE_LINK: | |
9141 | nl80211_oper = NL80211_TDLS_ENABLE_LINK; | |
9142 | break; | |
9143 | case TDLS_DISABLE_LINK: | |
9144 | nl80211_oper = NL80211_TDLS_DISABLE_LINK; | |
9145 | break; | |
9146 | case TDLS_ENABLE: | |
9147 | return 0; | |
9148 | case TDLS_DISABLE: | |
9149 | return 0; | |
9150 | default: | |
9151 | return -EINVAL; | |
9152 | } | |
9153 | ||
9154 | msg = nlmsg_alloc(); | |
9155 | if (!msg) | |
9156 | return -ENOMEM; | |
9157 | ||
9158 | nl80211_cmd(drv, msg, 0, NL80211_CMD_TDLS_OPER); | |
9159 | NLA_PUT_U8(msg, NL80211_ATTR_TDLS_OPERATION, nl80211_oper); | |
9160 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, drv->ifindex); | |
9161 | NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, peer); | |
9162 | ||
9163 | return send_and_recv_msgs(drv, msg, NULL, NULL); | |
9164 | ||
9165 | nla_put_failure: | |
9166 | nlmsg_free(msg); | |
9167 | return -ENOBUFS; | |
9168 | } | |
9169 | ||
9170 | #endif /* CONFIG TDLS */ | |
9171 | ||
9172 | ||
216eede8 DS |
9173 | #ifdef ANDROID |
9174 | ||
9175 | typedef struct android_wifi_priv_cmd { | |
9176 | char *buf; | |
9177 | int used_len; | |
9178 | int total_len; | |
9179 | } android_wifi_priv_cmd; | |
9180 | ||
9181 | static int drv_errors = 0; | |
9182 | ||
9183 | static void wpa_driver_send_hang_msg(struct wpa_driver_nl80211_data *drv) | |
9184 | { | |
9185 | drv_errors++; | |
9186 | if (drv_errors > DRV_NUMBER_SEQUENTIAL_ERRORS) { | |
9187 | drv_errors = 0; | |
9188 | wpa_msg(drv->ctx, MSG_INFO, WPA_EVENT_DRIVER_STATE "HANGED"); | |
9189 | } | |
9190 | } | |
9191 | ||
9192 | ||
9193 | static int android_priv_cmd(struct i802_bss *bss, const char *cmd) | |
9194 | { | |
9195 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
9196 | struct ifreq ifr; | |
9197 | android_wifi_priv_cmd priv_cmd; | |
9198 | char buf[MAX_DRV_CMD_SIZE]; | |
9199 | int ret; | |
9200 | ||
9201 | os_memset(&ifr, 0, sizeof(ifr)); | |
9202 | os_memset(&priv_cmd, 0, sizeof(priv_cmd)); | |
9203 | os_strlcpy(ifr.ifr_name, bss->ifname, IFNAMSIZ); | |
9204 | ||
9205 | os_memset(buf, 0, sizeof(buf)); | |
9206 | os_strlcpy(buf, cmd, sizeof(buf)); | |
9207 | ||
9208 | priv_cmd.buf = buf; | |
9209 | priv_cmd.used_len = sizeof(buf); | |
9210 | priv_cmd.total_len = sizeof(buf); | |
9211 | ifr.ifr_data = &priv_cmd; | |
9212 | ||
9213 | ret = ioctl(drv->global->ioctl_sock, SIOCDEVPRIVATE + 1, &ifr); | |
9214 | if (ret < 0) { | |
9215 | wpa_printf(MSG_ERROR, "%s: failed to issue private commands", | |
9216 | __func__); | |
9217 | wpa_driver_send_hang_msg(drv); | |
9218 | return ret; | |
9219 | } | |
9220 | ||
9221 | drv_errors = 0; | |
9222 | return 0; | |
9223 | } | |
9224 | ||
9225 | ||
9226 | static int android_pno_start(struct i802_bss *bss, | |
9227 | struct wpa_driver_scan_params *params) | |
9228 | { | |
9229 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
9230 | struct ifreq ifr; | |
9231 | android_wifi_priv_cmd priv_cmd; | |
9232 | int ret = 0, i = 0, bp; | |
9233 | char buf[WEXT_PNO_MAX_COMMAND_SIZE]; | |
9234 | ||
9235 | bp = WEXT_PNOSETUP_HEADER_SIZE; | |
9236 | os_memcpy(buf, WEXT_PNOSETUP_HEADER, bp); | |
9237 | buf[bp++] = WEXT_PNO_TLV_PREFIX; | |
9238 | buf[bp++] = WEXT_PNO_TLV_VERSION; | |
9239 | buf[bp++] = WEXT_PNO_TLV_SUBVERSION; | |
9240 | buf[bp++] = WEXT_PNO_TLV_RESERVED; | |
9241 | ||
9242 | while (i < WEXT_PNO_AMOUNT && (size_t) i < params->num_ssids) { | |
9243 | /* Check that there is enough space needed for 1 more SSID, the | |
9244 | * other sections and null termination */ | |
9245 | if ((bp + WEXT_PNO_SSID_HEADER_SIZE + MAX_SSID_LEN + | |
9246 | WEXT_PNO_NONSSID_SECTIONS_SIZE + 1) >= (int) sizeof(buf)) | |
9247 | break; | |
9248 | wpa_hexdump_ascii(MSG_DEBUG, "For PNO Scan", | |
a97bde0a JM |
9249 | params->ssids[i].ssid, |
9250 | params->ssids[i].ssid_len); | |
216eede8 DS |
9251 | buf[bp++] = WEXT_PNO_SSID_SECTION; |
9252 | buf[bp++] = params->ssids[i].ssid_len; | |
9253 | os_memcpy(&buf[bp], params->ssids[i].ssid, | |
9254 | params->ssids[i].ssid_len); | |
9255 | bp += params->ssids[i].ssid_len; | |
9256 | i++; | |
9257 | } | |
9258 | ||
9259 | buf[bp++] = WEXT_PNO_SCAN_INTERVAL_SECTION; | |
9260 | os_snprintf(&buf[bp], WEXT_PNO_SCAN_INTERVAL_LENGTH + 1, "%x", | |
9261 | WEXT_PNO_SCAN_INTERVAL); | |
9262 | bp += WEXT_PNO_SCAN_INTERVAL_LENGTH; | |
9263 | ||
9264 | buf[bp++] = WEXT_PNO_REPEAT_SECTION; | |
9265 | os_snprintf(&buf[bp], WEXT_PNO_REPEAT_LENGTH + 1, "%x", | |
9266 | WEXT_PNO_REPEAT); | |
9267 | bp += WEXT_PNO_REPEAT_LENGTH; | |
9268 | ||
9269 | buf[bp++] = WEXT_PNO_MAX_REPEAT_SECTION; | |
9270 | os_snprintf(&buf[bp], WEXT_PNO_MAX_REPEAT_LENGTH + 1, "%x", | |
9271 | WEXT_PNO_MAX_REPEAT); | |
9272 | bp += WEXT_PNO_MAX_REPEAT_LENGTH + 1; | |
9273 | ||
9274 | memset(&ifr, 0, sizeof(ifr)); | |
9275 | memset(&priv_cmd, 0, sizeof(priv_cmd)); | |
9276 | os_strncpy(ifr.ifr_name, bss->ifname, IFNAMSIZ); | |
9277 | ||
9278 | priv_cmd.buf = buf; | |
9279 | priv_cmd.used_len = bp; | |
9280 | priv_cmd.total_len = bp; | |
9281 | ifr.ifr_data = &priv_cmd; | |
9282 | ||
9283 | ret = ioctl(drv->global->ioctl_sock, SIOCDEVPRIVATE + 1, &ifr); | |
9284 | ||
9285 | if (ret < 0) { | |
9286 | wpa_printf(MSG_ERROR, "ioctl[SIOCSIWPRIV] (pnosetup): %d", | |
9287 | ret); | |
9288 | wpa_driver_send_hang_msg(drv); | |
9289 | return ret; | |
9290 | } | |
9291 | ||
9292 | drv_errors = 0; | |
9293 | ||
9294 | return android_priv_cmd(bss, "PNOFORCE 1"); | |
9295 | } | |
9296 | ||
9297 | ||
9298 | static int android_pno_stop(struct i802_bss *bss) | |
9299 | { | |
9300 | return android_priv_cmd(bss, "PNOFORCE 0"); | |
9301 | } | |
9302 | ||
9303 | #endif /* ANDROID */ | |
9304 | ||
9305 | ||
9ebce9c5 JM |
9306 | static int driver_nl80211_set_key(const char *ifname, void *priv, |
9307 | enum wpa_alg alg, const u8 *addr, | |
9308 | int key_idx, int set_tx, | |
9309 | const u8 *seq, size_t seq_len, | |
9310 | const u8 *key, size_t key_len) | |
9311 | { | |
9312 | struct i802_bss *bss = priv; | |
9313 | return wpa_driver_nl80211_set_key(ifname, bss, alg, addr, key_idx, | |
9314 | set_tx, seq, seq_len, key, key_len); | |
9315 | } | |
9316 | ||
9317 | ||
9318 | static int driver_nl80211_scan2(void *priv, | |
9319 | struct wpa_driver_scan_params *params) | |
9320 | { | |
9321 | struct i802_bss *bss = priv; | |
9322 | return wpa_driver_nl80211_scan(bss, params); | |
9323 | } | |
9324 | ||
9325 | ||
9326 | static int driver_nl80211_deauthenticate(void *priv, const u8 *addr, | |
9327 | int reason_code) | |
9328 | { | |
9329 | struct i802_bss *bss = priv; | |
9330 | return wpa_driver_nl80211_deauthenticate(bss, addr, reason_code); | |
9331 | } | |
9332 | ||
9333 | ||
9334 | static int driver_nl80211_authenticate(void *priv, | |
9335 | struct wpa_driver_auth_params *params) | |
9336 | { | |
9337 | struct i802_bss *bss = priv; | |
9338 | return wpa_driver_nl80211_authenticate(bss, params); | |
9339 | } | |
9340 | ||
9341 | ||
9342 | static void driver_nl80211_deinit(void *priv) | |
9343 | { | |
9344 | struct i802_bss *bss = priv; | |
9345 | wpa_driver_nl80211_deinit(bss); | |
9346 | } | |
9347 | ||
9348 | ||
9349 | static int driver_nl80211_if_remove(void *priv, enum wpa_driver_if_type type, | |
9350 | const char *ifname) | |
9351 | { | |
9352 | struct i802_bss *bss = priv; | |
9353 | return wpa_driver_nl80211_if_remove(bss, type, ifname); | |
9354 | } | |
9355 | ||
9356 | ||
9357 | static int driver_nl80211_send_mlme(void *priv, const u8 *data, | |
9358 | size_t data_len, int noack) | |
9359 | { | |
9360 | struct i802_bss *bss = priv; | |
9361 | return wpa_driver_nl80211_send_mlme(bss, data, data_len, noack, | |
9362 | 0, 0, 0, 0); | |
9363 | } | |
9364 | ||
9365 | ||
9366 | static int driver_nl80211_sta_remove(void *priv, const u8 *addr) | |
9367 | { | |
9368 | struct i802_bss *bss = priv; | |
9369 | return wpa_driver_nl80211_sta_remove(bss, addr); | |
9370 | } | |
9371 | ||
9372 | ||
9373 | #if defined(HOSTAPD) || defined(CONFIG_AP) | |
9374 | static int driver_nl80211_set_sta_vlan(void *priv, const u8 *addr, | |
9375 | const char *ifname, int vlan_id) | |
9376 | { | |
9377 | struct i802_bss *bss = priv; | |
9378 | return i802_set_sta_vlan(bss, addr, ifname, vlan_id); | |
9379 | } | |
9380 | #endif /* HOSTAPD || CONFIG_AP */ | |
9381 | ||
9382 | ||
9383 | static int driver_nl80211_read_sta_data(void *priv, | |
9384 | struct hostap_sta_driver_data *data, | |
9385 | const u8 *addr) | |
9386 | { | |
9387 | struct i802_bss *bss = priv; | |
9388 | return i802_read_sta_data(bss, data, addr); | |
9389 | } | |
9390 | ||
9391 | ||
9392 | static int driver_nl80211_send_action(void *priv, unsigned int freq, | |
9393 | unsigned int wait_time, | |
9394 | const u8 *dst, const u8 *src, | |
9395 | const u8 *bssid, | |
9396 | const u8 *data, size_t data_len, | |
9397 | int no_cck) | |
9398 | { | |
9399 | struct i802_bss *bss = priv; | |
9400 | return wpa_driver_nl80211_send_action(bss, freq, wait_time, dst, src, | |
9401 | bssid, data, data_len, no_cck); | |
9402 | } | |
9403 | ||
9404 | ||
9405 | static int driver_nl80211_probe_req_report(void *priv, int report) | |
9406 | { | |
9407 | struct i802_bss *bss = priv; | |
9408 | return wpa_driver_nl80211_probe_req_report(bss, report); | |
9409 | } | |
9410 | ||
9411 | ||
3f5285e8 JM |
9412 | const struct wpa_driver_ops wpa_driver_nl80211_ops = { |
9413 | .name = "nl80211", | |
9414 | .desc = "Linux nl80211/cfg80211", | |
9415 | .get_bssid = wpa_driver_nl80211_get_bssid, | |
9416 | .get_ssid = wpa_driver_nl80211_get_ssid, | |
9ebce9c5 JM |
9417 | .set_key = driver_nl80211_set_key, |
9418 | .scan2 = driver_nl80211_scan2, | |
d21c63b9 LC |
9419 | .sched_scan = wpa_driver_nl80211_sched_scan, |
9420 | .stop_sched_scan = wpa_driver_nl80211_stop_sched_scan, | |
3f5285e8 | 9421 | .get_scan_results2 = wpa_driver_nl80211_get_scan_results, |
9ebce9c5 JM |
9422 | .deauthenticate = driver_nl80211_deauthenticate, |
9423 | .authenticate = driver_nl80211_authenticate, | |
3f5285e8 | 9424 | .associate = wpa_driver_nl80211_associate, |
f2ed8023 JM |
9425 | .global_init = nl80211_global_init, |
9426 | .global_deinit = nl80211_global_deinit, | |
9427 | .init2 = wpa_driver_nl80211_init, | |
9ebce9c5 | 9428 | .deinit = driver_nl80211_deinit, |
3f5285e8 JM |
9429 | .get_capa = wpa_driver_nl80211_get_capa, |
9430 | .set_operstate = wpa_driver_nl80211_set_operstate, | |
01652550 | 9431 | .set_supp_port = wpa_driver_nl80211_set_supp_port, |
6d158490 | 9432 | .set_country = wpa_driver_nl80211_set_country, |
19c3b566 | 9433 | .set_ap = wpa_driver_nl80211_set_ap, |
22a7c9d7 | 9434 | .if_add = wpa_driver_nl80211_if_add, |
9ebce9c5 JM |
9435 | .if_remove = driver_nl80211_if_remove, |
9436 | .send_mlme = driver_nl80211_send_mlme, | |
c3965310 | 9437 | .get_hw_feature_data = wpa_driver_nl80211_get_hw_feature_data, |
0f4e8b4f | 9438 | .sta_add = wpa_driver_nl80211_sta_add, |
9ebce9c5 | 9439 | .sta_remove = driver_nl80211_sta_remove, |
db149ac9 | 9440 | .hapd_send_eapol = wpa_driver_nl80211_hapd_send_eapol, |
a8d6ffa4 | 9441 | .sta_set_flags = wpa_driver_nl80211_sta_set_flags, |
c5121837 JM |
9442 | #ifdef HOSTAPD |
9443 | .hapd_init = i802_init, | |
c5121837 | 9444 | .hapd_deinit = i802_deinit, |
f7b3920c JM |
9445 | .set_wds_sta = i802_set_wds_sta, |
9446 | #endif /* HOSTAPD */ | |
9447 | #if defined(HOSTAPD) || defined(CONFIG_AP) | |
c5121837 JM |
9448 | .get_seqnum = i802_get_seqnum, |
9449 | .flush = i802_flush, | |
c5121837 JM |
9450 | .get_inact_sec = i802_get_inact_sec, |
9451 | .sta_clear_stats = i802_sta_clear_stats, | |
c5121837 JM |
9452 | .set_rts = i802_set_rts, |
9453 | .set_frag = i802_set_frag, | |
c5121837 | 9454 | .set_tx_queue_params = i802_set_tx_queue_params, |
9ebce9c5 | 9455 | .set_sta_vlan = driver_nl80211_set_sta_vlan, |
ee7ab173 JB |
9456 | .sta_deauth = i802_sta_deauth, |
9457 | .sta_disassoc = i802_sta_disassoc, | |
9458 | #endif /* HOSTAPD || CONFIG_AP */ | |
9ebce9c5 | 9459 | .read_sta_data = driver_nl80211_read_sta_data, |
e3802622 | 9460 | .set_freq = i802_set_freq, |
9ebce9c5 | 9461 | .send_action = driver_nl80211_send_action, |
5dfca53f | 9462 | .send_action_cancel_wait = wpa_driver_nl80211_send_action_cancel_wait, |
55777702 JM |
9463 | .remain_on_channel = wpa_driver_nl80211_remain_on_channel, |
9464 | .cancel_remain_on_channel = | |
9465 | wpa_driver_nl80211_cancel_remain_on_channel, | |
9ebce9c5 | 9466 | .probe_req_report = driver_nl80211_probe_req_report, |
af473088 | 9467 | .deinit_ap = wpa_driver_nl80211_deinit_ap, |
3c29244e | 9468 | .deinit_p2p_cli = wpa_driver_nl80211_deinit_p2p_cli, |
207ef3fb | 9469 | .resume = wpa_driver_nl80211_resume, |
7b90c16a | 9470 | .send_ft_action = nl80211_send_ft_action, |
b625473c | 9471 | .signal_monitor = nl80211_signal_monitor, |
1c5c7273 | 9472 | .signal_poll = nl80211_signal_poll, |
b91ab76e | 9473 | .send_frame = nl80211_send_frame, |
57ebba59 | 9474 | .shared_freq = wpa_driver_nl80211_shared_freq, |
c55f774d | 9475 | .set_param = nl80211_set_param, |
6859f1cb | 9476 | .get_radio_name = nl80211_get_radio_name, |
a6efc65d JM |
9477 | .add_pmkid = nl80211_add_pmkid, |
9478 | .remove_pmkid = nl80211_remove_pmkid, | |
9479 | .flush_pmkid = nl80211_flush_pmkid, | |
b14a210c | 9480 | .set_rekey_info = nl80211_set_rekey_info, |
bcf24348 | 9481 | .poll_client = nl80211_poll_client, |
29f338af | 9482 | .set_p2p_powersave = nl80211_set_p2p_powersave, |
03ea1786 AN |
9483 | #ifdef CONFIG_TDLS |
9484 | .send_tdls_mgmt = nl80211_send_tdls_mgmt, | |
9485 | .tdls_oper = nl80211_tdls_oper, | |
9486 | #endif /* CONFIG_TDLS */ | |
3f5285e8 | 9487 | }; |