]> git.ipfire.org Git - thirdparty/hostap.git/blob - src/drivers/driver_nl80211.c
Remove unnecessary copying of SSID and BSSID for external_auth
[thirdparty/hostap.git] / src / drivers / driver_nl80211.c
1 /*
2 * Driver interaction with Linux nl80211/cfg80211
3 * Copyright (c) 2002-2015, Jouni Malinen <j@w1.fi>
4 * Copyright (c) 2003-2004, Instant802 Networks, Inc.
5 * Copyright (c) 2005-2006, Devicescape Software, Inc.
6 * Copyright (c) 2007, Johannes Berg <johannes@sipsolutions.net>
7 * Copyright (c) 2009-2010, Atheros Communications
8 *
9 * This software may be distributed under the terms of the BSD license.
10 * See README for more details.
11 */
12
13 #include "includes.h"
14 #include <sys/types.h>
15 #include <fcntl.h>
16 #include <net/if.h>
17 #include <netlink/genl/genl.h>
18 #include <netlink/genl/ctrl.h>
19 #ifdef CONFIG_LIBNL3_ROUTE
20 #include <netlink/route/neighbour.h>
21 #endif /* CONFIG_LIBNL3_ROUTE */
22 #include <linux/rtnetlink.h>
23 #include <netpacket/packet.h>
24 #include <linux/errqueue.h>
25
26 #include "common.h"
27 #include "eloop.h"
28 #include "common/qca-vendor.h"
29 #include "common/qca-vendor-attr.h"
30 #include "common/ieee802_11_defs.h"
31 #include "common/ieee802_11_common.h"
32 #include "common/wpa_common.h"
33 #include "l2_packet/l2_packet.h"
34 #include "netlink.h"
35 #include "linux_defines.h"
36 #include "linux_ioctl.h"
37 #include "radiotap.h"
38 #include "radiotap_iter.h"
39 #include "rfkill.h"
40 #include "driver_nl80211.h"
41
42
43 #ifndef NETLINK_CAP_ACK
44 #define NETLINK_CAP_ACK 10
45 #endif /* NETLINK_CAP_ACK */
46 /* support for extack if compilation headers are too old */
47 #ifndef NETLINK_EXT_ACK
48 #define NETLINK_EXT_ACK 11
49 enum nlmsgerr_attrs {
50 NLMSGERR_ATTR_UNUSED,
51 NLMSGERR_ATTR_MSG,
52 NLMSGERR_ATTR_OFFS,
53 NLMSGERR_ATTR_COOKIE,
54
55 __NLMSGERR_ATTR_MAX,
56 NLMSGERR_ATTR_MAX = __NLMSGERR_ATTR_MAX - 1
57 };
58 #endif
59 #ifndef NLM_F_CAPPED
60 #define NLM_F_CAPPED 0x100
61 #endif
62 #ifndef NLM_F_ACK_TLVS
63 #define NLM_F_ACK_TLVS 0x200
64 #endif
65 #ifndef SOL_NETLINK
66 #define SOL_NETLINK 270
67 #endif
68
69 #ifndef CONFIG_LIBNL20
70 /*
71 * libnl 1.1 has a bug, it tries to allocate socket numbers densely
72 * but when you free a socket again it will mess up its bitmap and
73 * and use the wrong number the next time it needs a socket ID.
74 * Therefore, we wrap the handle alloc/destroy and add our own pid
75 * accounting.
76 */
77 static uint32_t port_bitmap[32] = { 0 };
78
79 static struct nl_handle *nl80211_handle_alloc(void *cb)
80 {
81 struct nl_handle *handle;
82 uint32_t pid = getpid() & 0x3FFFFF;
83 int i;
84
85 handle = nl_handle_alloc_cb(cb);
86
87 for (i = 0; i < 1024; i++) {
88 if (port_bitmap[i / 32] & (1 << (i % 32)))
89 continue;
90 port_bitmap[i / 32] |= 1 << (i % 32);
91 pid += i << 22;
92 break;
93 }
94
95 nl_socket_set_local_port(handle, pid);
96
97 return handle;
98 }
99
100 static void nl80211_handle_destroy(struct nl_handle *handle)
101 {
102 uint32_t port = nl_socket_get_local_port(handle);
103
104 port >>= 22;
105 port_bitmap[port / 32] &= ~(1 << (port % 32));
106
107 nl_handle_destroy(handle);
108 }
109 #endif /* CONFIG_LIBNL20 */
110
111
112 #ifdef ANDROID
113 /* system/core/libnl_2 does not include nl_socket_set_nonblocking() */
114 #undef nl_socket_set_nonblocking
115 #define nl_socket_set_nonblocking(h) android_nl_socket_set_nonblocking(h)
116
117 #endif /* ANDROID */
118
119
120 static struct nl_handle * nl_create_handle(struct nl_cb *cb, const char *dbg)
121 {
122 struct nl_handle *handle;
123
124 handle = nl80211_handle_alloc(cb);
125 if (handle == NULL) {
126 wpa_printf(MSG_ERROR, "nl80211: Failed to allocate netlink "
127 "callbacks (%s)", dbg);
128 return NULL;
129 }
130
131 if (genl_connect(handle)) {
132 wpa_printf(MSG_ERROR, "nl80211: Failed to connect to generic "
133 "netlink (%s)", dbg);
134 nl80211_handle_destroy(handle);
135 return NULL;
136 }
137
138 return handle;
139 }
140
141
142 static void nl_destroy_handles(struct nl_handle **handle)
143 {
144 if (*handle == NULL)
145 return;
146 nl80211_handle_destroy(*handle);
147 *handle = NULL;
148 }
149
150
151 #if __WORDSIZE == 64
152 #define ELOOP_SOCKET_INVALID (intptr_t) 0x8888888888888889ULL
153 #else
154 #define ELOOP_SOCKET_INVALID (intptr_t) 0x88888889ULL
155 #endif
156
157 static void nl80211_register_eloop_read(struct nl_handle **handle,
158 eloop_sock_handler handler,
159 void *eloop_data, int persist)
160 {
161 #ifdef CONFIG_LIBNL20
162 /*
163 * libnl uses a pretty small buffer (32 kB that gets converted to 64 kB)
164 * by default. It is possible to hit that limit in some cases where
165 * operations are blocked, e.g., with a burst of Deauthentication frames
166 * to hostapd and STA entry deletion. Try to increase the buffer to make
167 * this less likely to occur.
168 */
169 if (nl_socket_set_buffer_size(*handle, 262144, 0) < 0) {
170 wpa_printf(MSG_DEBUG,
171 "nl80211: Could not set nl_socket RX buffer size: %s",
172 strerror(errno));
173 /* continue anyway with the default (smaller) buffer */
174 }
175 #endif /* CONFIG_LIBNL20 */
176
177 nl_socket_set_nonblocking(*handle);
178 eloop_register_read_sock(nl_socket_get_fd(*handle), handler,
179 eloop_data, *handle);
180 if (!persist)
181 *handle = (void *) (((intptr_t) *handle) ^
182 ELOOP_SOCKET_INVALID);
183 }
184
185
186 static void nl80211_destroy_eloop_handle(struct nl_handle **handle, int persist)
187 {
188 if (!persist)
189 *handle = (void *) (((intptr_t) *handle) ^
190 ELOOP_SOCKET_INVALID);
191 eloop_unregister_read_sock(nl_socket_get_fd(*handle));
192 nl_destroy_handles(handle);
193 }
194
195
196 static void nl80211_global_deinit(void *priv);
197 static void nl80211_check_global(struct nl80211_global *global);
198
199 static void wpa_driver_nl80211_deinit(struct i802_bss *bss);
200 static int wpa_driver_nl80211_set_mode_ibss(struct i802_bss *bss,
201 struct hostapd_freq_params *freq);
202
203 static int
204 wpa_driver_nl80211_finish_drv_init(struct wpa_driver_nl80211_data *drv,
205 const u8 *set_addr, int first,
206 const char *driver_params);
207 static int nl80211_send_frame_cmd(struct i802_bss *bss,
208 unsigned int freq, unsigned int wait,
209 const u8 *buf, size_t buf_len, u64 *cookie,
210 int no_cck, int no_ack, int offchanok,
211 const u16 *csa_offs, size_t csa_offs_len);
212 static int wpa_driver_nl80211_probe_req_report(struct i802_bss *bss,
213 int report);
214
215 #define IFIDX_ANY -1
216
217 static void add_ifidx(struct wpa_driver_nl80211_data *drv, int ifidx,
218 int ifidx_reason);
219 static void del_ifidx(struct wpa_driver_nl80211_data *drv, int ifidx,
220 int ifidx_reason);
221 static int have_ifidx(struct wpa_driver_nl80211_data *drv, int ifidx,
222 int ifidx_reason);
223
224 static int nl80211_set_channel(struct i802_bss *bss,
225 struct hostapd_freq_params *freq, int set_chan);
226 static int nl80211_disable_11b_rates(struct wpa_driver_nl80211_data *drv,
227 int ifindex, int disabled);
228
229 static int nl80211_leave_ibss(struct wpa_driver_nl80211_data *drv,
230 int reset_mode);
231
232 static int i802_set_iface_flags(struct i802_bss *bss, int up);
233 static int nl80211_set_param(void *priv, const char *param);
234 #ifdef CONFIG_MESH
235 static int nl80211_put_mesh_config(struct nl_msg *msg,
236 struct wpa_driver_mesh_bss_params *params);
237 #endif /* CONFIG_MESH */
238 static int i802_sta_disassoc(void *priv, const u8 *own_addr, const u8 *addr,
239 int reason);
240
241
242 /* Converts nl80211_chan_width to a common format */
243 enum chan_width convert2width(int width)
244 {
245 switch (width) {
246 case NL80211_CHAN_WIDTH_20_NOHT:
247 return CHAN_WIDTH_20_NOHT;
248 case NL80211_CHAN_WIDTH_20:
249 return CHAN_WIDTH_20;
250 case NL80211_CHAN_WIDTH_40:
251 return CHAN_WIDTH_40;
252 case NL80211_CHAN_WIDTH_80:
253 return CHAN_WIDTH_80;
254 case NL80211_CHAN_WIDTH_80P80:
255 return CHAN_WIDTH_80P80;
256 case NL80211_CHAN_WIDTH_160:
257 return CHAN_WIDTH_160;
258 }
259 return CHAN_WIDTH_UNKNOWN;
260 }
261
262
263 int is_ap_interface(enum nl80211_iftype nlmode)
264 {
265 return nlmode == NL80211_IFTYPE_AP ||
266 nlmode == NL80211_IFTYPE_P2P_GO;
267 }
268
269
270 int is_sta_interface(enum nl80211_iftype nlmode)
271 {
272 return nlmode == NL80211_IFTYPE_STATION ||
273 nlmode == NL80211_IFTYPE_P2P_CLIENT;
274 }
275
276
277 static int is_p2p_net_interface(enum nl80211_iftype nlmode)
278 {
279 return nlmode == NL80211_IFTYPE_P2P_CLIENT ||
280 nlmode == NL80211_IFTYPE_P2P_GO;
281 }
282
283
284 struct i802_bss * get_bss_ifindex(struct wpa_driver_nl80211_data *drv,
285 int ifindex)
286 {
287 struct i802_bss *bss;
288
289 for (bss = drv->first_bss; bss; bss = bss->next) {
290 if (bss->ifindex == ifindex)
291 return bss;
292 }
293
294 return NULL;
295 }
296
297
298 static int is_mesh_interface(enum nl80211_iftype nlmode)
299 {
300 return nlmode == NL80211_IFTYPE_MESH_POINT;
301 }
302
303
304 void nl80211_mark_disconnected(struct wpa_driver_nl80211_data *drv)
305 {
306 if (drv->associated)
307 os_memcpy(drv->prev_bssid, drv->bssid, ETH_ALEN);
308 drv->associated = 0;
309 os_memset(drv->bssid, 0, ETH_ALEN);
310 }
311
312
313 /* nl80211 code */
314 static int ack_handler(struct nl_msg *msg, void *arg)
315 {
316 int *err = arg;
317 *err = 0;
318 return NL_STOP;
319 }
320
321 static int finish_handler(struct nl_msg *msg, void *arg)
322 {
323 int *ret = arg;
324 *ret = 0;
325 return NL_SKIP;
326 }
327
328 static int error_handler(struct sockaddr_nl *nla, struct nlmsgerr *err,
329 void *arg)
330 {
331 struct nlmsghdr *nlh = (struct nlmsghdr *) err - 1;
332 int len = nlh->nlmsg_len;
333 struct nlattr *attrs;
334 struct nlattr *tb[NLMSGERR_ATTR_MAX + 1];
335 int *ret = arg;
336 int ack_len = sizeof(*nlh) + sizeof(int) + sizeof(*nlh);
337
338 *ret = err->error;
339
340 if (!(nlh->nlmsg_flags & NLM_F_ACK_TLVS))
341 return NL_SKIP;
342
343 if (!(nlh->nlmsg_flags & NLM_F_CAPPED))
344 ack_len += err->msg.nlmsg_len - sizeof(*nlh);
345
346 if (len <= ack_len)
347 return NL_STOP;
348
349 attrs = (void *) ((unsigned char *) nlh + ack_len);
350 len -= ack_len;
351
352 nla_parse(tb, NLMSGERR_ATTR_MAX, attrs, len, NULL);
353 if (tb[NLMSGERR_ATTR_MSG]) {
354 len = strnlen((char *) nla_data(tb[NLMSGERR_ATTR_MSG]),
355 nla_len(tb[NLMSGERR_ATTR_MSG]));
356 wpa_printf(MSG_ERROR, "nl80211: kernel reports: %*s",
357 len, (char *) nla_data(tb[NLMSGERR_ATTR_MSG]));
358 }
359
360 return NL_SKIP;
361 }
362
363
364 static int no_seq_check(struct nl_msg *msg, void *arg)
365 {
366 return NL_OK;
367 }
368
369
370 static void nl80211_nlmsg_clear(struct nl_msg *msg)
371 {
372 /*
373 * Clear nlmsg data, e.g., to make sure key material is not left in
374 * heap memory for unnecessarily long time.
375 */
376 if (msg) {
377 struct nlmsghdr *hdr = nlmsg_hdr(msg);
378 void *data = nlmsg_data(hdr);
379 /*
380 * This would use nlmsg_datalen() or the older nlmsg_len() if
381 * only libnl were to maintain a stable API.. Neither will work
382 * with all released versions, so just calculate the length
383 * here.
384 */
385 int len = hdr->nlmsg_len - NLMSG_HDRLEN;
386
387 os_memset(data, 0, len);
388 }
389 }
390
391
392 static int send_and_recv(struct nl80211_global *global,
393 struct nl_handle *nl_handle, struct nl_msg *msg,
394 int (*valid_handler)(struct nl_msg *, void *),
395 void *valid_data)
396 {
397 struct nl_cb *cb;
398 int err = -ENOMEM, opt;
399
400 if (!msg)
401 return -ENOMEM;
402
403 cb = nl_cb_clone(global->nl_cb);
404 if (!cb)
405 goto out;
406
407 /* try to set NETLINK_EXT_ACK to 1, ignoring errors */
408 opt = 1;
409 setsockopt(nl_socket_get_fd(nl_handle), SOL_NETLINK,
410 NETLINK_EXT_ACK, &opt, sizeof(opt));
411
412 /* try to set NETLINK_CAP_ACK to 1, ignoring errors */
413 opt = 1;
414 setsockopt(nl_socket_get_fd(nl_handle), SOL_NETLINK,
415 NETLINK_CAP_ACK, &opt, sizeof(opt));
416
417 err = nl_send_auto_complete(nl_handle, msg);
418 if (err < 0)
419 goto out;
420
421 err = 1;
422
423 nl_cb_err(cb, NL_CB_CUSTOM, error_handler, &err);
424 nl_cb_set(cb, NL_CB_FINISH, NL_CB_CUSTOM, finish_handler, &err);
425 nl_cb_set(cb, NL_CB_ACK, NL_CB_CUSTOM, ack_handler, &err);
426
427 if (valid_handler)
428 nl_cb_set(cb, NL_CB_VALID, NL_CB_CUSTOM,
429 valid_handler, valid_data);
430
431 while (err > 0) {
432 int res = nl_recvmsgs(nl_handle, cb);
433 if (res < 0) {
434 wpa_printf(MSG_INFO,
435 "nl80211: %s->nl_recvmsgs failed: %d",
436 __func__, res);
437 }
438 }
439 out:
440 nl_cb_put(cb);
441 if (!valid_handler && valid_data == (void *) -1)
442 nl80211_nlmsg_clear(msg);
443 nlmsg_free(msg);
444 return err;
445 }
446
447
448 int send_and_recv_msgs(struct wpa_driver_nl80211_data *drv,
449 struct nl_msg *msg,
450 int (*valid_handler)(struct nl_msg *, void *),
451 void *valid_data)
452 {
453 return send_and_recv(drv->global, drv->global->nl, msg,
454 valid_handler, valid_data);
455 }
456
457
458 struct family_data {
459 const char *group;
460 int id;
461 };
462
463
464 static int family_handler(struct nl_msg *msg, void *arg)
465 {
466 struct family_data *res = arg;
467 struct nlattr *tb[CTRL_ATTR_MAX + 1];
468 struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg));
469 struct nlattr *mcgrp;
470 int i;
471
472 nla_parse(tb, CTRL_ATTR_MAX, genlmsg_attrdata(gnlh, 0),
473 genlmsg_attrlen(gnlh, 0), NULL);
474 if (!tb[CTRL_ATTR_MCAST_GROUPS])
475 return NL_SKIP;
476
477 nla_for_each_nested(mcgrp, tb[CTRL_ATTR_MCAST_GROUPS], i) {
478 struct nlattr *tb2[CTRL_ATTR_MCAST_GRP_MAX + 1];
479 nla_parse(tb2, CTRL_ATTR_MCAST_GRP_MAX, nla_data(mcgrp),
480 nla_len(mcgrp), NULL);
481 if (!tb2[CTRL_ATTR_MCAST_GRP_NAME] ||
482 !tb2[CTRL_ATTR_MCAST_GRP_ID] ||
483 os_strncmp(nla_data(tb2[CTRL_ATTR_MCAST_GRP_NAME]),
484 res->group,
485 nla_len(tb2[CTRL_ATTR_MCAST_GRP_NAME])) != 0)
486 continue;
487 res->id = nla_get_u32(tb2[CTRL_ATTR_MCAST_GRP_ID]);
488 break;
489 };
490
491 return NL_SKIP;
492 }
493
494
495 static int nl_get_multicast_id(struct nl80211_global *global,
496 const char *family, const char *group)
497 {
498 struct nl_msg *msg;
499 int ret;
500 struct family_data res = { group, -ENOENT };
501
502 msg = nlmsg_alloc();
503 if (!msg)
504 return -ENOMEM;
505 if (!genlmsg_put(msg, 0, 0, genl_ctrl_resolve(global->nl, "nlctrl"),
506 0, 0, CTRL_CMD_GETFAMILY, 0) ||
507 nla_put_string(msg, CTRL_ATTR_FAMILY_NAME, family)) {
508 nlmsg_free(msg);
509 return -1;
510 }
511
512 ret = send_and_recv(global, global->nl, msg, family_handler, &res);
513 if (ret == 0)
514 ret = res.id;
515 return ret;
516 }
517
518
519 void * nl80211_cmd(struct wpa_driver_nl80211_data *drv,
520 struct nl_msg *msg, int flags, uint8_t cmd)
521 {
522 if (TEST_FAIL())
523 return NULL;
524 return genlmsg_put(msg, 0, 0, drv->global->nl80211_id,
525 0, flags, cmd, 0);
526 }
527
528
529 static int nl80211_set_iface_id(struct nl_msg *msg, struct i802_bss *bss)
530 {
531 if (bss->wdev_id_set)
532 return nla_put_u64(msg, NL80211_ATTR_WDEV, bss->wdev_id);
533 return nla_put_u32(msg, NL80211_ATTR_IFINDEX, bss->ifindex);
534 }
535
536
537 struct nl_msg * nl80211_cmd_msg(struct i802_bss *bss, int flags, uint8_t cmd)
538 {
539 struct nl_msg *msg;
540
541 msg = nlmsg_alloc();
542 if (!msg)
543 return NULL;
544
545 if (!nl80211_cmd(bss->drv, msg, flags, cmd) ||
546 nl80211_set_iface_id(msg, bss) < 0) {
547 nlmsg_free(msg);
548 return NULL;
549 }
550
551 return msg;
552 }
553
554
555 static struct nl_msg *
556 nl80211_ifindex_msg(struct wpa_driver_nl80211_data *drv, int ifindex,
557 int flags, uint8_t cmd)
558 {
559 struct nl_msg *msg;
560
561 msg = nlmsg_alloc();
562 if (!msg)
563 return NULL;
564
565 if (!nl80211_cmd(drv, msg, flags, cmd) ||
566 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex)) {
567 nlmsg_free(msg);
568 return NULL;
569 }
570
571 return msg;
572 }
573
574
575 struct nl_msg * nl80211_drv_msg(struct wpa_driver_nl80211_data *drv, int flags,
576 uint8_t cmd)
577 {
578 return nl80211_ifindex_msg(drv, drv->ifindex, flags, cmd);
579 }
580
581
582 struct nl_msg * nl80211_bss_msg(struct i802_bss *bss, int flags, uint8_t cmd)
583 {
584 return nl80211_ifindex_msg(bss->drv, bss->ifindex, flags, cmd);
585 }
586
587
588 struct wiphy_idx_data {
589 int wiphy_idx;
590 enum nl80211_iftype nlmode;
591 u8 *macaddr;
592 };
593
594
595 static int netdev_info_handler(struct nl_msg *msg, void *arg)
596 {
597 struct nlattr *tb[NL80211_ATTR_MAX + 1];
598 struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg));
599 struct wiphy_idx_data *info = arg;
600
601 nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0),
602 genlmsg_attrlen(gnlh, 0), NULL);
603
604 if (tb[NL80211_ATTR_WIPHY])
605 info->wiphy_idx = nla_get_u32(tb[NL80211_ATTR_WIPHY]);
606
607 if (tb[NL80211_ATTR_IFTYPE])
608 info->nlmode = nla_get_u32(tb[NL80211_ATTR_IFTYPE]);
609
610 if (tb[NL80211_ATTR_MAC] && info->macaddr)
611 os_memcpy(info->macaddr, nla_data(tb[NL80211_ATTR_MAC]),
612 ETH_ALEN);
613
614 return NL_SKIP;
615 }
616
617
618 int nl80211_get_wiphy_index(struct i802_bss *bss)
619 {
620 struct nl_msg *msg;
621 struct wiphy_idx_data data = {
622 .wiphy_idx = -1,
623 .macaddr = NULL,
624 };
625
626 if (!(msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_GET_INTERFACE)))
627 return -1;
628
629 if (send_and_recv_msgs(bss->drv, msg, netdev_info_handler, &data) == 0)
630 return data.wiphy_idx;
631 return -1;
632 }
633
634
635 static enum nl80211_iftype nl80211_get_ifmode(struct i802_bss *bss)
636 {
637 struct nl_msg *msg;
638 struct wiphy_idx_data data = {
639 .nlmode = NL80211_IFTYPE_UNSPECIFIED,
640 .macaddr = NULL,
641 };
642
643 if (!(msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_GET_INTERFACE)))
644 return NL80211_IFTYPE_UNSPECIFIED;
645
646 if (send_and_recv_msgs(bss->drv, msg, netdev_info_handler, &data) == 0)
647 return data.nlmode;
648 return NL80211_IFTYPE_UNSPECIFIED;
649 }
650
651
652 static int nl80211_get_macaddr(struct i802_bss *bss)
653 {
654 struct nl_msg *msg;
655 struct wiphy_idx_data data = {
656 .macaddr = bss->addr,
657 };
658
659 if (!(msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_GET_INTERFACE)))
660 return -1;
661
662 return send_and_recv_msgs(bss->drv, msg, netdev_info_handler, &data);
663 }
664
665
666 static int nl80211_register_beacons(struct wpa_driver_nl80211_data *drv,
667 struct nl80211_wiphy_data *w)
668 {
669 struct nl_msg *msg;
670 int ret;
671
672 msg = nlmsg_alloc();
673 if (!msg)
674 return -1;
675
676 if (!nl80211_cmd(drv, msg, 0, NL80211_CMD_REGISTER_BEACONS) ||
677 nla_put_u32(msg, NL80211_ATTR_WIPHY, w->wiphy_idx)) {
678 nlmsg_free(msg);
679 return -1;
680 }
681
682 ret = send_and_recv(drv->global, w->nl_beacons, msg, NULL, NULL);
683 if (ret) {
684 wpa_printf(MSG_DEBUG, "nl80211: Register beacons command "
685 "failed: ret=%d (%s)",
686 ret, strerror(-ret));
687 }
688 return ret;
689 }
690
691
692 static void nl80211_recv_beacons(int sock, void *eloop_ctx, void *handle)
693 {
694 struct nl80211_wiphy_data *w = eloop_ctx;
695 int res;
696
697 wpa_printf(MSG_EXCESSIVE, "nl80211: Beacon event message available");
698
699 res = nl_recvmsgs(handle, w->nl_cb);
700 if (res < 0) {
701 wpa_printf(MSG_INFO, "nl80211: %s->nl_recvmsgs failed: %d",
702 __func__, res);
703 }
704 }
705
706
707 static int process_beacon_event(struct nl_msg *msg, void *arg)
708 {
709 struct nl80211_wiphy_data *w = arg;
710 struct wpa_driver_nl80211_data *drv;
711 struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg));
712 struct nlattr *tb[NL80211_ATTR_MAX + 1];
713 union wpa_event_data event;
714
715 nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0),
716 genlmsg_attrlen(gnlh, 0), NULL);
717
718 if (gnlh->cmd != NL80211_CMD_FRAME) {
719 wpa_printf(MSG_DEBUG, "nl80211: Unexpected beacon event? (%d)",
720 gnlh->cmd);
721 return NL_SKIP;
722 }
723
724 if (!tb[NL80211_ATTR_FRAME])
725 return NL_SKIP;
726
727 dl_list_for_each(drv, &w->drvs, struct wpa_driver_nl80211_data,
728 wiphy_list) {
729 os_memset(&event, 0, sizeof(event));
730 event.rx_mgmt.frame = nla_data(tb[NL80211_ATTR_FRAME]);
731 event.rx_mgmt.frame_len = nla_len(tb[NL80211_ATTR_FRAME]);
732 wpa_supplicant_event(drv->ctx, EVENT_RX_MGMT, &event);
733 }
734
735 return NL_SKIP;
736 }
737
738
739 static struct nl80211_wiphy_data *
740 nl80211_get_wiphy_data_ap(struct i802_bss *bss)
741 {
742 static DEFINE_DL_LIST(nl80211_wiphys);
743 struct nl80211_wiphy_data *w;
744 int wiphy_idx, found = 0;
745 struct i802_bss *tmp_bss;
746 u8 channel;
747
748 if (bss->wiphy_data != NULL)
749 return bss->wiphy_data;
750
751 wiphy_idx = nl80211_get_wiphy_index(bss);
752
753 dl_list_for_each(w, &nl80211_wiphys, struct nl80211_wiphy_data, list) {
754 if (w->wiphy_idx == wiphy_idx)
755 goto add;
756 }
757
758 /* alloc new one */
759 w = os_zalloc(sizeof(*w));
760 if (w == NULL)
761 return NULL;
762 w->wiphy_idx = wiphy_idx;
763 dl_list_init(&w->bsss);
764 dl_list_init(&w->drvs);
765
766 /* Beacon frames not supported in IEEE 802.11ad */
767 if (ieee80211_freq_to_chan(bss->freq, &channel) !=
768 HOSTAPD_MODE_IEEE80211AD) {
769 w->nl_cb = nl_cb_alloc(NL_CB_DEFAULT);
770 if (!w->nl_cb) {
771 os_free(w);
772 return NULL;
773 }
774 nl_cb_set(w->nl_cb, NL_CB_SEQ_CHECK, NL_CB_CUSTOM,
775 no_seq_check, NULL);
776 nl_cb_set(w->nl_cb, NL_CB_VALID, NL_CB_CUSTOM,
777 process_beacon_event, w);
778
779 w->nl_beacons = nl_create_handle(bss->drv->global->nl_cb,
780 "wiphy beacons");
781 if (w->nl_beacons == NULL) {
782 os_free(w);
783 return NULL;
784 }
785
786 if (nl80211_register_beacons(bss->drv, w)) {
787 nl_destroy_handles(&w->nl_beacons);
788 os_free(w);
789 return NULL;
790 }
791
792 nl80211_register_eloop_read(&w->nl_beacons,
793 nl80211_recv_beacons, w, 0);
794 }
795
796 dl_list_add(&nl80211_wiphys, &w->list);
797
798 add:
799 /* drv entry for this bss already there? */
800 dl_list_for_each(tmp_bss, &w->bsss, struct i802_bss, wiphy_list) {
801 if (tmp_bss->drv == bss->drv) {
802 found = 1;
803 break;
804 }
805 }
806 /* if not add it */
807 if (!found)
808 dl_list_add(&w->drvs, &bss->drv->wiphy_list);
809
810 dl_list_add(&w->bsss, &bss->wiphy_list);
811 bss->wiphy_data = w;
812 return w;
813 }
814
815
816 static void nl80211_put_wiphy_data_ap(struct i802_bss *bss)
817 {
818 struct nl80211_wiphy_data *w = bss->wiphy_data;
819 struct i802_bss *tmp_bss;
820 int found = 0;
821
822 if (w == NULL)
823 return;
824 bss->wiphy_data = NULL;
825 dl_list_del(&bss->wiphy_list);
826
827 /* still any for this drv present? */
828 dl_list_for_each(tmp_bss, &w->bsss, struct i802_bss, wiphy_list) {
829 if (tmp_bss->drv == bss->drv) {
830 found = 1;
831 break;
832 }
833 }
834 /* if not remove it */
835 if (!found)
836 dl_list_del(&bss->drv->wiphy_list);
837
838 if (!dl_list_empty(&w->bsss))
839 return;
840
841 if (w->nl_beacons)
842 nl80211_destroy_eloop_handle(&w->nl_beacons, 0);
843
844 nl_cb_put(w->nl_cb);
845 dl_list_del(&w->list);
846 os_free(w);
847 }
848
849
850 static unsigned int nl80211_get_ifindex(void *priv)
851 {
852 struct i802_bss *bss = priv;
853 struct wpa_driver_nl80211_data *drv = bss->drv;
854
855 return drv->ifindex;
856 }
857
858
859 static int wpa_driver_nl80211_get_bssid(void *priv, u8 *bssid)
860 {
861 struct i802_bss *bss = priv;
862 struct wpa_driver_nl80211_data *drv = bss->drv;
863 if (!drv->associated)
864 return -1;
865 os_memcpy(bssid, drv->bssid, ETH_ALEN);
866 return 0;
867 }
868
869
870 static int wpa_driver_nl80211_get_ssid(void *priv, u8 *ssid)
871 {
872 struct i802_bss *bss = priv;
873 struct wpa_driver_nl80211_data *drv = bss->drv;
874 if (!drv->associated)
875 return -1;
876 os_memcpy(ssid, drv->ssid, drv->ssid_len);
877 return drv->ssid_len;
878 }
879
880
881 static void wpa_driver_nl80211_event_newlink(
882 struct nl80211_global *global, struct wpa_driver_nl80211_data *drv,
883 int ifindex, const char *ifname)
884 {
885 union wpa_event_data event;
886
887 if (drv && os_strcmp(drv->first_bss->ifname, ifname) == 0) {
888 if (if_nametoindex(drv->first_bss->ifname) == 0) {
889 wpa_printf(MSG_DEBUG, "nl80211: Interface %s does not exist - ignore RTM_NEWLINK",
890 drv->first_bss->ifname);
891 return;
892 }
893 if (!drv->if_removed)
894 return;
895 wpa_printf(MSG_DEBUG, "nl80211: Mark if_removed=0 for %s based on RTM_NEWLINK event",
896 drv->first_bss->ifname);
897 drv->if_removed = 0;
898 }
899
900 os_memset(&event, 0, sizeof(event));
901 event.interface_status.ifindex = ifindex;
902 os_strlcpy(event.interface_status.ifname, ifname,
903 sizeof(event.interface_status.ifname));
904 event.interface_status.ievent = EVENT_INTERFACE_ADDED;
905 if (drv)
906 wpa_supplicant_event(drv->ctx, EVENT_INTERFACE_STATUS, &event);
907 else
908 wpa_supplicant_event_global(global->ctx, EVENT_INTERFACE_STATUS,
909 &event);
910 }
911
912
913 static void wpa_driver_nl80211_event_dellink(
914 struct nl80211_global *global, struct wpa_driver_nl80211_data *drv,
915 int ifindex, const char *ifname)
916 {
917 union wpa_event_data event;
918
919 if (drv && os_strcmp(drv->first_bss->ifname, ifname) == 0) {
920 if (drv->if_removed) {
921 wpa_printf(MSG_DEBUG, "nl80211: if_removed already set - ignore RTM_DELLINK event for %s",
922 ifname);
923 return;
924 }
925 wpa_printf(MSG_DEBUG, "RTM_DELLINK: Interface '%s' removed - mark if_removed=1",
926 ifname);
927 drv->if_removed = 1;
928 } else {
929 wpa_printf(MSG_DEBUG, "RTM_DELLINK: Interface '%s' removed",
930 ifname);
931 }
932
933 os_memset(&event, 0, sizeof(event));
934 event.interface_status.ifindex = ifindex;
935 os_strlcpy(event.interface_status.ifname, ifname,
936 sizeof(event.interface_status.ifname));
937 event.interface_status.ievent = EVENT_INTERFACE_REMOVED;
938 if (drv)
939 wpa_supplicant_event(drv->ctx, EVENT_INTERFACE_STATUS, &event);
940 else
941 wpa_supplicant_event_global(global->ctx, EVENT_INTERFACE_STATUS,
942 &event);
943 }
944
945
946 static int wpa_driver_nl80211_own_ifname(struct wpa_driver_nl80211_data *drv,
947 u8 *buf, size_t len)
948 {
949 int attrlen, rta_len;
950 struct rtattr *attr;
951
952 attrlen = len;
953 attr = (struct rtattr *) buf;
954
955 rta_len = RTA_ALIGN(sizeof(struct rtattr));
956 while (RTA_OK(attr, attrlen)) {
957 if (attr->rta_type == IFLA_IFNAME) {
958 if (os_strcmp(((char *) attr) + rta_len,
959 drv->first_bss->ifname) == 0)
960 return 1;
961 else
962 break;
963 }
964 attr = RTA_NEXT(attr, attrlen);
965 }
966
967 return 0;
968 }
969
970
971 static int wpa_driver_nl80211_own_ifindex(struct wpa_driver_nl80211_data *drv,
972 int ifindex, u8 *buf, size_t len)
973 {
974 if (drv->ifindex == ifindex)
975 return 1;
976
977 if (drv->if_removed && wpa_driver_nl80211_own_ifname(drv, buf, len)) {
978 nl80211_check_global(drv->global);
979 wpa_printf(MSG_DEBUG, "nl80211: Update ifindex for a removed "
980 "interface");
981 if (wpa_driver_nl80211_finish_drv_init(drv, NULL, 0, NULL) < 0)
982 return -1;
983 return 1;
984 }
985
986 return 0;
987 }
988
989
990 static struct wpa_driver_nl80211_data *
991 nl80211_find_drv(struct nl80211_global *global, int idx, u8 *buf, size_t len,
992 int *init_failed)
993 {
994 struct wpa_driver_nl80211_data *drv;
995 int res;
996
997 if (init_failed)
998 *init_failed = 0;
999 dl_list_for_each(drv, &global->interfaces,
1000 struct wpa_driver_nl80211_data, list) {
1001 res = wpa_driver_nl80211_own_ifindex(drv, idx, buf, len);
1002 if (res < 0) {
1003 wpa_printf(MSG_DEBUG,
1004 "nl80211: Found matching own interface, but failed to complete reinitialization");
1005 if (init_failed)
1006 *init_failed = 1;
1007 return drv;
1008 }
1009 if (res > 0 || have_ifidx(drv, idx, IFIDX_ANY))
1010 return drv;
1011 }
1012 return NULL;
1013 }
1014
1015
1016 static void nl80211_refresh_mac(struct wpa_driver_nl80211_data *drv,
1017 int ifindex, int notify)
1018 {
1019 struct i802_bss *bss;
1020 u8 addr[ETH_ALEN];
1021
1022 bss = get_bss_ifindex(drv, ifindex);
1023 if (bss &&
1024 linux_get_ifhwaddr(drv->global->ioctl_sock,
1025 bss->ifname, addr) < 0) {
1026 wpa_printf(MSG_DEBUG,
1027 "nl80211: %s: failed to re-read MAC address",
1028 bss->ifname);
1029 } else if (bss && os_memcmp(addr, bss->addr, ETH_ALEN) != 0) {
1030 wpa_printf(MSG_DEBUG,
1031 "nl80211: Own MAC address on ifindex %d (%s) changed from "
1032 MACSTR " to " MACSTR,
1033 ifindex, bss->ifname,
1034 MAC2STR(bss->addr), MAC2STR(addr));
1035 os_memcpy(bss->addr, addr, ETH_ALEN);
1036 if (notify)
1037 wpa_supplicant_event(drv->ctx,
1038 EVENT_INTERFACE_MAC_CHANGED, NULL);
1039 }
1040 }
1041
1042
1043 static void wpa_driver_nl80211_event_rtm_newlink(void *ctx,
1044 struct ifinfomsg *ifi,
1045 u8 *buf, size_t len)
1046 {
1047 struct nl80211_global *global = ctx;
1048 struct wpa_driver_nl80211_data *drv;
1049 int attrlen;
1050 struct rtattr *attr;
1051 u32 brid = 0;
1052 char namebuf[IFNAMSIZ];
1053 char ifname[IFNAMSIZ + 1];
1054 char extra[100], *pos, *end;
1055 int init_failed;
1056
1057 extra[0] = '\0';
1058 pos = extra;
1059 end = pos + sizeof(extra);
1060 ifname[0] = '\0';
1061
1062 attrlen = len;
1063 attr = (struct rtattr *) buf;
1064 while (RTA_OK(attr, attrlen)) {
1065 switch (attr->rta_type) {
1066 case IFLA_IFNAME:
1067 if (RTA_PAYLOAD(attr) >= IFNAMSIZ)
1068 break;
1069 os_memcpy(ifname, RTA_DATA(attr), RTA_PAYLOAD(attr));
1070 ifname[RTA_PAYLOAD(attr)] = '\0';
1071 break;
1072 case IFLA_MASTER:
1073 brid = nla_get_u32((struct nlattr *) attr);
1074 pos += os_snprintf(pos, end - pos, " master=%u", brid);
1075 break;
1076 case IFLA_WIRELESS:
1077 pos += os_snprintf(pos, end - pos, " wext");
1078 break;
1079 case IFLA_OPERSTATE:
1080 pos += os_snprintf(pos, end - pos, " operstate=%u",
1081 nla_get_u32((struct nlattr *) attr));
1082 break;
1083 case IFLA_LINKMODE:
1084 pos += os_snprintf(pos, end - pos, " linkmode=%u",
1085 nla_get_u32((struct nlattr *) attr));
1086 break;
1087 }
1088 attr = RTA_NEXT(attr, attrlen);
1089 }
1090 extra[sizeof(extra) - 1] = '\0';
1091
1092 wpa_printf(MSG_DEBUG, "RTM_NEWLINK: ifi_index=%d ifname=%s%s ifi_family=%d ifi_flags=0x%x (%s%s%s%s)",
1093 ifi->ifi_index, ifname, extra, ifi->ifi_family,
1094 ifi->ifi_flags,
1095 (ifi->ifi_flags & IFF_UP) ? "[UP]" : "",
1096 (ifi->ifi_flags & IFF_RUNNING) ? "[RUNNING]" : "",
1097 (ifi->ifi_flags & IFF_LOWER_UP) ? "[LOWER_UP]" : "",
1098 (ifi->ifi_flags & IFF_DORMANT) ? "[DORMANT]" : "");
1099
1100 drv = nl80211_find_drv(global, ifi->ifi_index, buf, len, &init_failed);
1101 if (!drv)
1102 goto event_newlink;
1103 if (init_failed)
1104 return; /* do not update interface state */
1105
1106 if (!drv->if_disabled && !(ifi->ifi_flags & IFF_UP)) {
1107 namebuf[0] = '\0';
1108 if (if_indextoname(ifi->ifi_index, namebuf) &&
1109 linux_iface_up(drv->global->ioctl_sock, namebuf) > 0) {
1110 wpa_printf(MSG_DEBUG, "nl80211: Ignore interface down "
1111 "event since interface %s is up", namebuf);
1112 drv->ignore_if_down_event = 0;
1113 /* Re-read MAC address as it may have changed */
1114 nl80211_refresh_mac(drv, ifi->ifi_index, 1);
1115 return;
1116 }
1117 wpa_printf(MSG_DEBUG, "nl80211: Interface down (%s/%s)",
1118 namebuf, ifname);
1119 if (os_strcmp(drv->first_bss->ifname, ifname) != 0) {
1120 wpa_printf(MSG_DEBUG,
1121 "nl80211: Not the main interface (%s) - do not indicate interface down",
1122 drv->first_bss->ifname);
1123 } else if (drv->ignore_if_down_event) {
1124 wpa_printf(MSG_DEBUG, "nl80211: Ignore interface down "
1125 "event generated by mode change");
1126 drv->ignore_if_down_event = 0;
1127 } else {
1128 drv->if_disabled = 1;
1129 wpa_supplicant_event(drv->ctx,
1130 EVENT_INTERFACE_DISABLED, NULL);
1131
1132 /*
1133 * Try to get drv again, since it may be removed as
1134 * part of the EVENT_INTERFACE_DISABLED handling for
1135 * dynamic interfaces
1136 */
1137 drv = nl80211_find_drv(global, ifi->ifi_index,
1138 buf, len, NULL);
1139 if (!drv)
1140 return;
1141 }
1142 }
1143
1144 if (drv->if_disabled && (ifi->ifi_flags & IFF_UP)) {
1145 namebuf[0] = '\0';
1146 if (if_indextoname(ifi->ifi_index, namebuf) &&
1147 linux_iface_up(drv->global->ioctl_sock, namebuf) == 0) {
1148 wpa_printf(MSG_DEBUG, "nl80211: Ignore interface up "
1149 "event since interface %s is down",
1150 namebuf);
1151 return;
1152 }
1153 wpa_printf(MSG_DEBUG, "nl80211: Interface up (%s/%s)",
1154 namebuf, ifname);
1155 if (os_strcmp(drv->first_bss->ifname, ifname) != 0) {
1156 wpa_printf(MSG_DEBUG,
1157 "nl80211: Not the main interface (%s) - do not indicate interface up",
1158 drv->first_bss->ifname);
1159 } else if (if_nametoindex(drv->first_bss->ifname) == 0) {
1160 wpa_printf(MSG_DEBUG, "nl80211: Ignore interface up "
1161 "event since interface %s does not exist",
1162 drv->first_bss->ifname);
1163 } else if (drv->if_removed) {
1164 wpa_printf(MSG_DEBUG, "nl80211: Ignore interface up "
1165 "event since interface %s is marked "
1166 "removed", drv->first_bss->ifname);
1167 } else {
1168 /* Re-read MAC address as it may have changed */
1169 nl80211_refresh_mac(drv, ifi->ifi_index, 0);
1170
1171 drv->if_disabled = 0;
1172 wpa_supplicant_event(drv->ctx, EVENT_INTERFACE_ENABLED,
1173 NULL);
1174 }
1175 }
1176
1177 /*
1178 * Some drivers send the association event before the operup event--in
1179 * this case, lifting operstate in wpa_driver_nl80211_set_operstate()
1180 * fails. This will hit us when wpa_supplicant does not need to do
1181 * IEEE 802.1X authentication
1182 */
1183 if (drv->operstate == 1 &&
1184 (ifi->ifi_flags & (IFF_LOWER_UP | IFF_DORMANT)) == IFF_LOWER_UP &&
1185 !(ifi->ifi_flags & IFF_RUNNING)) {
1186 wpa_printf(MSG_DEBUG, "nl80211: Set IF_OPER_UP again based on ifi_flags and expected operstate");
1187 netlink_send_oper_ifla(drv->global->netlink, drv->ifindex,
1188 -1, IF_OPER_UP);
1189 }
1190
1191 event_newlink:
1192 if (ifname[0])
1193 wpa_driver_nl80211_event_newlink(global, drv, ifi->ifi_index,
1194 ifname);
1195
1196 if (ifi->ifi_family == AF_BRIDGE && brid && drv) {
1197 struct i802_bss *bss;
1198
1199 /* device has been added to bridge */
1200 if (!if_indextoname(brid, namebuf)) {
1201 wpa_printf(MSG_DEBUG,
1202 "nl80211: Could not find bridge ifname for ifindex %u",
1203 brid);
1204 return;
1205 }
1206 wpa_printf(MSG_DEBUG, "nl80211: Add ifindex %u for bridge %s",
1207 brid, namebuf);
1208 add_ifidx(drv, brid, ifi->ifi_index);
1209
1210 for (bss = drv->first_bss; bss; bss = bss->next) {
1211 if (os_strcmp(ifname, bss->ifname) == 0) {
1212 os_strlcpy(bss->brname, namebuf, IFNAMSIZ);
1213 break;
1214 }
1215 }
1216 }
1217 }
1218
1219
1220 static void wpa_driver_nl80211_event_rtm_dellink(void *ctx,
1221 struct ifinfomsg *ifi,
1222 u8 *buf, size_t len)
1223 {
1224 struct nl80211_global *global = ctx;
1225 struct wpa_driver_nl80211_data *drv;
1226 int attrlen;
1227 struct rtattr *attr;
1228 u32 brid = 0;
1229 char ifname[IFNAMSIZ + 1];
1230 char extra[100], *pos, *end;
1231
1232 extra[0] = '\0';
1233 pos = extra;
1234 end = pos + sizeof(extra);
1235 ifname[0] = '\0';
1236
1237 attrlen = len;
1238 attr = (struct rtattr *) buf;
1239 while (RTA_OK(attr, attrlen)) {
1240 switch (attr->rta_type) {
1241 case IFLA_IFNAME:
1242 if (RTA_PAYLOAD(attr) >= IFNAMSIZ)
1243 break;
1244 os_memcpy(ifname, RTA_DATA(attr), RTA_PAYLOAD(attr));
1245 ifname[RTA_PAYLOAD(attr)] = '\0';
1246 break;
1247 case IFLA_MASTER:
1248 brid = nla_get_u32((struct nlattr *) attr);
1249 pos += os_snprintf(pos, end - pos, " master=%u", brid);
1250 break;
1251 case IFLA_OPERSTATE:
1252 pos += os_snprintf(pos, end - pos, " operstate=%u",
1253 nla_get_u32((struct nlattr *) attr));
1254 break;
1255 case IFLA_LINKMODE:
1256 pos += os_snprintf(pos, end - pos, " linkmode=%u",
1257 nla_get_u32((struct nlattr *) attr));
1258 break;
1259 }
1260 attr = RTA_NEXT(attr, attrlen);
1261 }
1262 extra[sizeof(extra) - 1] = '\0';
1263
1264 wpa_printf(MSG_DEBUG, "RTM_DELLINK: ifi_index=%d ifname=%s%s ifi_family=%d ifi_flags=0x%x (%s%s%s%s)",
1265 ifi->ifi_index, ifname, extra, ifi->ifi_family,
1266 ifi->ifi_flags,
1267 (ifi->ifi_flags & IFF_UP) ? "[UP]" : "",
1268 (ifi->ifi_flags & IFF_RUNNING) ? "[RUNNING]" : "",
1269 (ifi->ifi_flags & IFF_LOWER_UP) ? "[LOWER_UP]" : "",
1270 (ifi->ifi_flags & IFF_DORMANT) ? "[DORMANT]" : "");
1271
1272 drv = nl80211_find_drv(global, ifi->ifi_index, buf, len, NULL);
1273
1274 if (ifi->ifi_family == AF_BRIDGE && brid && drv) {
1275 /* device has been removed from bridge */
1276 char namebuf[IFNAMSIZ];
1277
1278 if (!if_indextoname(brid, namebuf)) {
1279 wpa_printf(MSG_DEBUG,
1280 "nl80211: Could not find bridge ifname for ifindex %u",
1281 brid);
1282 } else {
1283 wpa_printf(MSG_DEBUG,
1284 "nl80211: Remove ifindex %u for bridge %s",
1285 brid, namebuf);
1286 }
1287 del_ifidx(drv, brid, ifi->ifi_index);
1288 }
1289
1290 if (ifi->ifi_family != AF_BRIDGE || !brid)
1291 wpa_driver_nl80211_event_dellink(global, drv, ifi->ifi_index,
1292 ifname);
1293 }
1294
1295
1296 struct nl80211_get_assoc_freq_arg {
1297 struct wpa_driver_nl80211_data *drv;
1298 unsigned int assoc_freq;
1299 unsigned int ibss_freq;
1300 u8 assoc_bssid[ETH_ALEN];
1301 u8 assoc_ssid[SSID_MAX_LEN];
1302 u8 assoc_ssid_len;
1303 };
1304
1305 static int nl80211_get_assoc_freq_handler(struct nl_msg *msg, void *arg)
1306 {
1307 struct nlattr *tb[NL80211_ATTR_MAX + 1];
1308 struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg));
1309 struct nlattr *bss[NL80211_BSS_MAX + 1];
1310 static struct nla_policy bss_policy[NL80211_BSS_MAX + 1] = {
1311 [NL80211_BSS_BSSID] = { .type = NLA_UNSPEC },
1312 [NL80211_BSS_FREQUENCY] = { .type = NLA_U32 },
1313 [NL80211_BSS_INFORMATION_ELEMENTS] = { .type = NLA_UNSPEC },
1314 [NL80211_BSS_STATUS] = { .type = NLA_U32 },
1315 };
1316 struct nl80211_get_assoc_freq_arg *ctx = arg;
1317 enum nl80211_bss_status status;
1318
1319 nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0),
1320 genlmsg_attrlen(gnlh, 0), NULL);
1321 if (!tb[NL80211_ATTR_BSS] ||
1322 nla_parse_nested(bss, NL80211_BSS_MAX, tb[NL80211_ATTR_BSS],
1323 bss_policy) ||
1324 !bss[NL80211_BSS_STATUS])
1325 return NL_SKIP;
1326
1327 status = nla_get_u32(bss[NL80211_BSS_STATUS]);
1328 if (status == NL80211_BSS_STATUS_ASSOCIATED &&
1329 bss[NL80211_BSS_FREQUENCY]) {
1330 ctx->assoc_freq = nla_get_u32(bss[NL80211_BSS_FREQUENCY]);
1331 wpa_printf(MSG_DEBUG, "nl80211: Associated on %u MHz",
1332 ctx->assoc_freq);
1333 }
1334 if (status == NL80211_BSS_STATUS_IBSS_JOINED &&
1335 bss[NL80211_BSS_FREQUENCY]) {
1336 ctx->ibss_freq = nla_get_u32(bss[NL80211_BSS_FREQUENCY]);
1337 wpa_printf(MSG_DEBUG, "nl80211: IBSS-joined on %u MHz",
1338 ctx->ibss_freq);
1339 }
1340 if (status == NL80211_BSS_STATUS_ASSOCIATED &&
1341 bss[NL80211_BSS_BSSID]) {
1342 os_memcpy(ctx->assoc_bssid,
1343 nla_data(bss[NL80211_BSS_BSSID]), ETH_ALEN);
1344 wpa_printf(MSG_DEBUG, "nl80211: Associated with "
1345 MACSTR, MAC2STR(ctx->assoc_bssid));
1346 }
1347
1348 if (status == NL80211_BSS_STATUS_ASSOCIATED &&
1349 bss[NL80211_BSS_INFORMATION_ELEMENTS]) {
1350 const u8 *ie, *ssid;
1351 size_t ie_len;
1352
1353 ie = nla_data(bss[NL80211_BSS_INFORMATION_ELEMENTS]);
1354 ie_len = nla_len(bss[NL80211_BSS_INFORMATION_ELEMENTS]);
1355 ssid = get_ie(ie, ie_len, WLAN_EID_SSID);
1356 if (ssid && ssid[1] > 0 && ssid[1] <= SSID_MAX_LEN) {
1357 ctx->assoc_ssid_len = ssid[1];
1358 os_memcpy(ctx->assoc_ssid, ssid + 2, ssid[1]);
1359 }
1360 }
1361
1362 return NL_SKIP;
1363 }
1364
1365
1366 int nl80211_get_assoc_ssid(struct wpa_driver_nl80211_data *drv, u8 *ssid)
1367 {
1368 struct nl_msg *msg;
1369 int ret;
1370 struct nl80211_get_assoc_freq_arg arg;
1371
1372 msg = nl80211_drv_msg(drv, NLM_F_DUMP, NL80211_CMD_GET_SCAN);
1373 os_memset(&arg, 0, sizeof(arg));
1374 arg.drv = drv;
1375 ret = send_and_recv_msgs(drv, msg, nl80211_get_assoc_freq_handler,
1376 &arg);
1377 if (ret == 0) {
1378 os_memcpy(ssid, arg.assoc_ssid, arg.assoc_ssid_len);
1379 return arg.assoc_ssid_len;
1380 }
1381 wpa_printf(MSG_DEBUG, "nl80211: Scan result fetch failed: ret=%d (%s)",
1382 ret, strerror(-ret));
1383 return ret;
1384 }
1385
1386
1387 unsigned int nl80211_get_assoc_freq(struct wpa_driver_nl80211_data *drv)
1388 {
1389 struct nl_msg *msg;
1390 int ret;
1391 struct nl80211_get_assoc_freq_arg arg;
1392
1393 msg = nl80211_drv_msg(drv, NLM_F_DUMP, NL80211_CMD_GET_SCAN);
1394 os_memset(&arg, 0, sizeof(arg));
1395 arg.drv = drv;
1396 ret = send_and_recv_msgs(drv, msg, nl80211_get_assoc_freq_handler,
1397 &arg);
1398 if (ret == 0) {
1399 unsigned int freq = drv->nlmode == NL80211_IFTYPE_ADHOC ?
1400 arg.ibss_freq : arg.assoc_freq;
1401 wpa_printf(MSG_DEBUG, "nl80211: Operating frequency for the "
1402 "associated BSS from scan results: %u MHz", freq);
1403 if (freq)
1404 drv->assoc_freq = freq;
1405 return drv->assoc_freq;
1406 }
1407 wpa_printf(MSG_DEBUG, "nl80211: Scan result fetch failed: ret=%d "
1408 "(%s)", ret, strerror(-ret));
1409 return drv->assoc_freq;
1410 }
1411
1412
1413 static int get_link_signal(struct nl_msg *msg, void *arg)
1414 {
1415 struct nlattr *tb[NL80211_ATTR_MAX + 1];
1416 struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg));
1417 struct nlattr *sinfo[NL80211_STA_INFO_MAX + 1];
1418 static struct nla_policy policy[NL80211_STA_INFO_MAX + 1] = {
1419 [NL80211_STA_INFO_SIGNAL] = { .type = NLA_U8 },
1420 [NL80211_STA_INFO_SIGNAL_AVG] = { .type = NLA_U8 },
1421 [NL80211_STA_INFO_BEACON_SIGNAL_AVG] = { .type = NLA_U8 },
1422 };
1423 struct nlattr *rinfo[NL80211_RATE_INFO_MAX + 1];
1424 static struct nla_policy rate_policy[NL80211_RATE_INFO_MAX + 1] = {
1425 [NL80211_RATE_INFO_BITRATE] = { .type = NLA_U16 },
1426 [NL80211_RATE_INFO_MCS] = { .type = NLA_U8 },
1427 [NL80211_RATE_INFO_40_MHZ_WIDTH] = { .type = NLA_FLAG },
1428 [NL80211_RATE_INFO_SHORT_GI] = { .type = NLA_FLAG },
1429 };
1430 struct wpa_signal_info *sig_change = arg;
1431
1432 nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0),
1433 genlmsg_attrlen(gnlh, 0), NULL);
1434 if (!tb[NL80211_ATTR_STA_INFO] ||
1435 nla_parse_nested(sinfo, NL80211_STA_INFO_MAX,
1436 tb[NL80211_ATTR_STA_INFO], policy))
1437 return NL_SKIP;
1438 if (!sinfo[NL80211_STA_INFO_SIGNAL])
1439 return NL_SKIP;
1440
1441 sig_change->current_signal =
1442 (s8) nla_get_u8(sinfo[NL80211_STA_INFO_SIGNAL]);
1443
1444 if (sinfo[NL80211_STA_INFO_SIGNAL_AVG])
1445 sig_change->avg_signal =
1446 (s8) nla_get_u8(sinfo[NL80211_STA_INFO_SIGNAL_AVG]);
1447 else
1448 sig_change->avg_signal = 0;
1449
1450 if (sinfo[NL80211_STA_INFO_BEACON_SIGNAL_AVG])
1451 sig_change->avg_beacon_signal =
1452 (s8)
1453 nla_get_u8(sinfo[NL80211_STA_INFO_BEACON_SIGNAL_AVG]);
1454 else
1455 sig_change->avg_beacon_signal = 0;
1456
1457 if (sinfo[NL80211_STA_INFO_TX_BITRATE]) {
1458 if (nla_parse_nested(rinfo, NL80211_RATE_INFO_MAX,
1459 sinfo[NL80211_STA_INFO_TX_BITRATE],
1460 rate_policy)) {
1461 sig_change->current_txrate = 0;
1462 } else {
1463 if (rinfo[NL80211_RATE_INFO_BITRATE]) {
1464 sig_change->current_txrate =
1465 nla_get_u16(rinfo[
1466 NL80211_RATE_INFO_BITRATE]) * 100;
1467 }
1468 }
1469 }
1470
1471 return NL_SKIP;
1472 }
1473
1474
1475 int nl80211_get_link_signal(struct wpa_driver_nl80211_data *drv,
1476 struct wpa_signal_info *sig)
1477 {
1478 struct nl_msg *msg;
1479
1480 sig->current_signal = -WPA_INVALID_NOISE;
1481 sig->current_txrate = 0;
1482
1483 if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_GET_STATION)) ||
1484 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, drv->bssid)) {
1485 nlmsg_free(msg);
1486 return -ENOBUFS;
1487 }
1488
1489 return send_and_recv_msgs(drv, msg, get_link_signal, sig);
1490 }
1491
1492
1493 static int get_link_noise(struct nl_msg *msg, void *arg)
1494 {
1495 struct nlattr *tb[NL80211_ATTR_MAX + 1];
1496 struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg));
1497 struct nlattr *sinfo[NL80211_SURVEY_INFO_MAX + 1];
1498 static struct nla_policy survey_policy[NL80211_SURVEY_INFO_MAX + 1] = {
1499 [NL80211_SURVEY_INFO_FREQUENCY] = { .type = NLA_U32 },
1500 [NL80211_SURVEY_INFO_NOISE] = { .type = NLA_U8 },
1501 };
1502 struct wpa_signal_info *sig_change = arg;
1503
1504 nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0),
1505 genlmsg_attrlen(gnlh, 0), NULL);
1506
1507 if (!tb[NL80211_ATTR_SURVEY_INFO]) {
1508 wpa_printf(MSG_DEBUG, "nl80211: survey data missing!");
1509 return NL_SKIP;
1510 }
1511
1512 if (nla_parse_nested(sinfo, NL80211_SURVEY_INFO_MAX,
1513 tb[NL80211_ATTR_SURVEY_INFO],
1514 survey_policy)) {
1515 wpa_printf(MSG_DEBUG, "nl80211: failed to parse nested "
1516 "attributes!");
1517 return NL_SKIP;
1518 }
1519
1520 if (!sinfo[NL80211_SURVEY_INFO_FREQUENCY])
1521 return NL_SKIP;
1522
1523 if (nla_get_u32(sinfo[NL80211_SURVEY_INFO_FREQUENCY]) !=
1524 sig_change->frequency)
1525 return NL_SKIP;
1526
1527 if (!sinfo[NL80211_SURVEY_INFO_NOISE])
1528 return NL_SKIP;
1529
1530 sig_change->current_noise =
1531 (s8) nla_get_u8(sinfo[NL80211_SURVEY_INFO_NOISE]);
1532
1533 return NL_SKIP;
1534 }
1535
1536
1537 int nl80211_get_link_noise(struct wpa_driver_nl80211_data *drv,
1538 struct wpa_signal_info *sig_change)
1539 {
1540 struct nl_msg *msg;
1541
1542 sig_change->current_noise = WPA_INVALID_NOISE;
1543 sig_change->frequency = drv->assoc_freq;
1544
1545 msg = nl80211_drv_msg(drv, NLM_F_DUMP, NL80211_CMD_GET_SURVEY);
1546 return send_and_recv_msgs(drv, msg, get_link_noise, sig_change);
1547 }
1548
1549
1550 static int get_channel_info(struct nl_msg *msg, void *arg)
1551 {
1552 struct nlattr *tb[NL80211_ATTR_MAX + 1] = { 0 };
1553 struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg));
1554 struct wpa_channel_info *chan_info = arg;
1555
1556 nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0),
1557 genlmsg_attrlen(gnlh, 0), NULL);
1558
1559 os_memset(chan_info, 0, sizeof(struct wpa_channel_info));
1560 chan_info->chanwidth = CHAN_WIDTH_UNKNOWN;
1561
1562 if (tb[NL80211_ATTR_WIPHY_FREQ])
1563 chan_info->frequency =
1564 nla_get_u32(tb[NL80211_ATTR_WIPHY_FREQ]);
1565 if (tb[NL80211_ATTR_CHANNEL_WIDTH])
1566 chan_info->chanwidth = convert2width(
1567 nla_get_u32(tb[NL80211_ATTR_CHANNEL_WIDTH]));
1568 if (tb[NL80211_ATTR_WIPHY_CHANNEL_TYPE]) {
1569 enum nl80211_channel_type ct =
1570 nla_get_u32(tb[NL80211_ATTR_WIPHY_CHANNEL_TYPE]);
1571
1572 switch (ct) {
1573 case NL80211_CHAN_HT40MINUS:
1574 chan_info->sec_channel = -1;
1575 break;
1576 case NL80211_CHAN_HT40PLUS:
1577 chan_info->sec_channel = 1;
1578 break;
1579 default:
1580 chan_info->sec_channel = 0;
1581 break;
1582 }
1583 }
1584 if (tb[NL80211_ATTR_CENTER_FREQ1])
1585 chan_info->center_frq1 =
1586 nla_get_u32(tb[NL80211_ATTR_CENTER_FREQ1]);
1587 if (tb[NL80211_ATTR_CENTER_FREQ2])
1588 chan_info->center_frq2 =
1589 nla_get_u32(tb[NL80211_ATTR_CENTER_FREQ2]);
1590
1591 if (chan_info->center_frq2) {
1592 u8 seg1_idx = 0;
1593
1594 if (ieee80211_freq_to_chan(chan_info->center_frq2, &seg1_idx) !=
1595 NUM_HOSTAPD_MODES)
1596 chan_info->seg1_idx = seg1_idx;
1597 }
1598
1599 return NL_SKIP;
1600 }
1601
1602
1603 static int nl80211_channel_info(void *priv, struct wpa_channel_info *ci)
1604 {
1605 struct i802_bss *bss = priv;
1606 struct wpa_driver_nl80211_data *drv = bss->drv;
1607 struct nl_msg *msg;
1608
1609 msg = nl80211_drv_msg(drv, 0, NL80211_CMD_GET_INTERFACE);
1610 return send_and_recv_msgs(drv, msg, get_channel_info, ci);
1611 }
1612
1613
1614 static void wpa_driver_nl80211_event_receive(int sock, void *eloop_ctx,
1615 void *handle)
1616 {
1617 struct nl_cb *cb = eloop_ctx;
1618 int res;
1619
1620 wpa_printf(MSG_MSGDUMP, "nl80211: Event message available");
1621
1622 res = nl_recvmsgs(handle, cb);
1623 if (res < 0) {
1624 wpa_printf(MSG_INFO, "nl80211: %s->nl_recvmsgs failed: %d",
1625 __func__, res);
1626 }
1627 }
1628
1629
1630 /**
1631 * wpa_driver_nl80211_set_country - ask nl80211 to set the regulatory domain
1632 * @priv: driver_nl80211 private data
1633 * @alpha2_arg: country to which to switch to
1634 * Returns: 0 on success, -1 on failure
1635 *
1636 * This asks nl80211 to set the regulatory domain for given
1637 * country ISO / IEC alpha2.
1638 */
1639 static int wpa_driver_nl80211_set_country(void *priv, const char *alpha2_arg)
1640 {
1641 struct i802_bss *bss = priv;
1642 struct wpa_driver_nl80211_data *drv = bss->drv;
1643 char alpha2[3];
1644 struct nl_msg *msg;
1645
1646 msg = nlmsg_alloc();
1647 if (!msg)
1648 return -ENOMEM;
1649
1650 alpha2[0] = alpha2_arg[0];
1651 alpha2[1] = alpha2_arg[1];
1652 alpha2[2] = '\0';
1653
1654 if (!nl80211_cmd(drv, msg, 0, NL80211_CMD_REQ_SET_REG) ||
1655 nla_put_string(msg, NL80211_ATTR_REG_ALPHA2, alpha2)) {
1656 nlmsg_free(msg);
1657 return -EINVAL;
1658 }
1659 if (send_and_recv_msgs(drv, msg, NULL, NULL))
1660 return -EINVAL;
1661 return 0;
1662 }
1663
1664
1665 static int nl80211_get_country(struct nl_msg *msg, void *arg)
1666 {
1667 char *alpha2 = arg;
1668 struct nlattr *tb_msg[NL80211_ATTR_MAX + 1];
1669 struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg));
1670
1671 nla_parse(tb_msg, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0),
1672 genlmsg_attrlen(gnlh, 0), NULL);
1673 if (!tb_msg[NL80211_ATTR_REG_ALPHA2]) {
1674 wpa_printf(MSG_DEBUG, "nl80211: No country information available");
1675 return NL_SKIP;
1676 }
1677 os_strlcpy(alpha2, nla_data(tb_msg[NL80211_ATTR_REG_ALPHA2]), 3);
1678 return NL_SKIP;
1679 }
1680
1681
1682 static int wpa_driver_nl80211_get_country(void *priv, char *alpha2)
1683 {
1684 struct i802_bss *bss = priv;
1685 struct wpa_driver_nl80211_data *drv = bss->drv;
1686 struct nl_msg *msg;
1687 int ret;
1688
1689 msg = nlmsg_alloc();
1690 if (!msg)
1691 return -ENOMEM;
1692
1693 nl80211_cmd(drv, msg, 0, NL80211_CMD_GET_REG);
1694 alpha2[0] = '\0';
1695 ret = send_and_recv_msgs(drv, msg, nl80211_get_country, alpha2);
1696 if (!alpha2[0])
1697 ret = -1;
1698
1699 return ret;
1700 }
1701
1702
1703 static int wpa_driver_nl80211_init_nl_global(struct nl80211_global *global)
1704 {
1705 int ret;
1706
1707 global->nl_cb = nl_cb_alloc(NL_CB_DEFAULT);
1708 if (global->nl_cb == NULL) {
1709 wpa_printf(MSG_ERROR, "nl80211: Failed to allocate netlink "
1710 "callbacks");
1711 return -1;
1712 }
1713
1714 global->nl = nl_create_handle(global->nl_cb, "nl");
1715 if (global->nl == NULL)
1716 goto err;
1717
1718 global->nl80211_id = genl_ctrl_resolve(global->nl, "nl80211");
1719 if (global->nl80211_id < 0) {
1720 wpa_printf(MSG_ERROR, "nl80211: 'nl80211' generic netlink not "
1721 "found");
1722 goto err;
1723 }
1724
1725 global->nl_event = nl_create_handle(global->nl_cb, "event");
1726 if (global->nl_event == NULL)
1727 goto err;
1728
1729 ret = nl_get_multicast_id(global, "nl80211", "scan");
1730 if (ret >= 0)
1731 ret = nl_socket_add_membership(global->nl_event, ret);
1732 if (ret < 0) {
1733 wpa_printf(MSG_ERROR, "nl80211: Could not add multicast "
1734 "membership for scan events: %d (%s)",
1735 ret, strerror(-ret));
1736 goto err;
1737 }
1738
1739 ret = nl_get_multicast_id(global, "nl80211", "mlme");
1740 if (ret >= 0)
1741 ret = nl_socket_add_membership(global->nl_event, ret);
1742 if (ret < 0) {
1743 wpa_printf(MSG_ERROR, "nl80211: Could not add multicast "
1744 "membership for mlme events: %d (%s)",
1745 ret, strerror(-ret));
1746 goto err;
1747 }
1748
1749 ret = nl_get_multicast_id(global, "nl80211", "regulatory");
1750 if (ret >= 0)
1751 ret = nl_socket_add_membership(global->nl_event, ret);
1752 if (ret < 0) {
1753 wpa_printf(MSG_DEBUG, "nl80211: Could not add multicast "
1754 "membership for regulatory events: %d (%s)",
1755 ret, strerror(-ret));
1756 /* Continue without regulatory events */
1757 }
1758
1759 ret = nl_get_multicast_id(global, "nl80211", "vendor");
1760 if (ret >= 0)
1761 ret = nl_socket_add_membership(global->nl_event, ret);
1762 if (ret < 0) {
1763 wpa_printf(MSG_DEBUG, "nl80211: Could not add multicast "
1764 "membership for vendor events: %d (%s)",
1765 ret, strerror(-ret));
1766 /* Continue without vendor events */
1767 }
1768
1769 nl_cb_set(global->nl_cb, NL_CB_SEQ_CHECK, NL_CB_CUSTOM,
1770 no_seq_check, NULL);
1771 nl_cb_set(global->nl_cb, NL_CB_VALID, NL_CB_CUSTOM,
1772 process_global_event, global);
1773
1774 nl80211_register_eloop_read(&global->nl_event,
1775 wpa_driver_nl80211_event_receive,
1776 global->nl_cb, 0);
1777
1778 return 0;
1779
1780 err:
1781 nl_destroy_handles(&global->nl_event);
1782 nl_destroy_handles(&global->nl);
1783 nl_cb_put(global->nl_cb);
1784 global->nl_cb = NULL;
1785 return -1;
1786 }
1787
1788
1789 static void nl80211_check_global(struct nl80211_global *global)
1790 {
1791 struct nl_handle *handle;
1792 const char *groups[] = { "scan", "mlme", "regulatory", "vendor", NULL };
1793 int ret;
1794 unsigned int i;
1795
1796 /*
1797 * Try to re-add memberships to handle case of cfg80211 getting reloaded
1798 * and all registration having been cleared.
1799 */
1800 handle = (void *) (((intptr_t) global->nl_event) ^
1801 ELOOP_SOCKET_INVALID);
1802
1803 for (i = 0; groups[i]; i++) {
1804 ret = nl_get_multicast_id(global, "nl80211", groups[i]);
1805 if (ret >= 0)
1806 ret = nl_socket_add_membership(handle, ret);
1807 if (ret < 0) {
1808 wpa_printf(MSG_INFO,
1809 "nl80211: Could not re-add multicast membership for %s events: %d (%s)",
1810 groups[i], ret, strerror(-ret));
1811 }
1812 }
1813 }
1814
1815
1816 static void wpa_driver_nl80211_rfkill_blocked(void *ctx)
1817 {
1818 struct wpa_driver_nl80211_data *drv = ctx;
1819
1820 wpa_printf(MSG_DEBUG, "nl80211: RFKILL blocked");
1821
1822 /*
1823 * rtnetlink ifdown handler will report interfaces other than the P2P
1824 * Device interface as disabled.
1825 */
1826 if (drv->nlmode == NL80211_IFTYPE_P2P_DEVICE)
1827 wpa_supplicant_event(drv->ctx, EVENT_INTERFACE_DISABLED, NULL);
1828 }
1829
1830
1831 static void wpa_driver_nl80211_rfkill_unblocked(void *ctx)
1832 {
1833 struct wpa_driver_nl80211_data *drv = ctx;
1834 wpa_printf(MSG_DEBUG, "nl80211: RFKILL unblocked");
1835 if (i802_set_iface_flags(drv->first_bss, 1)) {
1836 wpa_printf(MSG_DEBUG, "nl80211: Could not set interface UP "
1837 "after rfkill unblock");
1838 return;
1839 }
1840
1841 if (is_p2p_net_interface(drv->nlmode))
1842 nl80211_disable_11b_rates(drv, drv->ifindex, 1);
1843
1844 /*
1845 * rtnetlink ifup handler will report interfaces other than the P2P
1846 * Device interface as enabled.
1847 */
1848 if (drv->nlmode == NL80211_IFTYPE_P2P_DEVICE)
1849 wpa_supplicant_event(drv->ctx, EVENT_INTERFACE_ENABLED, NULL);
1850 }
1851
1852
1853 static void wpa_driver_nl80211_handle_eapol_tx_status(int sock,
1854 void *eloop_ctx,
1855 void *handle)
1856 {
1857 struct wpa_driver_nl80211_data *drv = eloop_ctx;
1858 u8 data[2048];
1859 struct msghdr msg;
1860 struct iovec entry;
1861 u8 control[512];
1862 struct cmsghdr *cmsg;
1863 int res, found_ee = 0, found_wifi = 0, acked = 0;
1864 union wpa_event_data event;
1865
1866 memset(&msg, 0, sizeof(msg));
1867 msg.msg_iov = &entry;
1868 msg.msg_iovlen = 1;
1869 entry.iov_base = data;
1870 entry.iov_len = sizeof(data);
1871 msg.msg_control = &control;
1872 msg.msg_controllen = sizeof(control);
1873
1874 res = recvmsg(sock, &msg, MSG_ERRQUEUE);
1875 /* if error or not fitting 802.3 header, return */
1876 if (res < 14)
1877 return;
1878
1879 for (cmsg = CMSG_FIRSTHDR(&msg); cmsg; cmsg = CMSG_NXTHDR(&msg, cmsg))
1880 {
1881 if (cmsg->cmsg_level == SOL_SOCKET &&
1882 cmsg->cmsg_type == SCM_WIFI_STATUS) {
1883 int *ack;
1884
1885 found_wifi = 1;
1886 ack = (void *)CMSG_DATA(cmsg);
1887 acked = *ack;
1888 }
1889
1890 if (cmsg->cmsg_level == SOL_PACKET &&
1891 cmsg->cmsg_type == PACKET_TX_TIMESTAMP) {
1892 struct sock_extended_err *err =
1893 (struct sock_extended_err *)CMSG_DATA(cmsg);
1894
1895 if (err->ee_origin == SO_EE_ORIGIN_TXSTATUS)
1896 found_ee = 1;
1897 }
1898 }
1899
1900 if (!found_ee || !found_wifi)
1901 return;
1902
1903 memset(&event, 0, sizeof(event));
1904 event.eapol_tx_status.dst = data;
1905 event.eapol_tx_status.data = data + 14;
1906 event.eapol_tx_status.data_len = res - 14;
1907 event.eapol_tx_status.ack = acked;
1908 wpa_supplicant_event(drv->ctx, EVENT_EAPOL_TX_STATUS, &event);
1909 }
1910
1911
1912 static int nl80211_init_bss(struct i802_bss *bss)
1913 {
1914 bss->nl_cb = nl_cb_alloc(NL_CB_DEFAULT);
1915 if (!bss->nl_cb)
1916 return -1;
1917
1918 nl_cb_set(bss->nl_cb, NL_CB_SEQ_CHECK, NL_CB_CUSTOM,
1919 no_seq_check, NULL);
1920 nl_cb_set(bss->nl_cb, NL_CB_VALID, NL_CB_CUSTOM,
1921 process_bss_event, bss);
1922
1923 return 0;
1924 }
1925
1926
1927 static void nl80211_destroy_bss(struct i802_bss *bss)
1928 {
1929 nl_cb_put(bss->nl_cb);
1930 bss->nl_cb = NULL;
1931 }
1932
1933
1934 static void
1935 wpa_driver_nl80211_drv_init_rfkill(struct wpa_driver_nl80211_data *drv)
1936 {
1937 struct rfkill_config *rcfg;
1938
1939 if (drv->rfkill)
1940 return;
1941
1942 rcfg = os_zalloc(sizeof(*rcfg));
1943 if (!rcfg)
1944 return;
1945
1946 rcfg->ctx = drv;
1947
1948 /* rfkill uses netdev sysfs for initialization. However, P2P Device is
1949 * not associated with a netdev, so use the name of some other interface
1950 * sharing the same wiphy as the P2P Device interface.
1951 *
1952 * Note: This is valid, as a P2P Device interface is always dynamically
1953 * created and is created only once another wpa_s interface was added.
1954 */
1955 if (drv->nlmode == NL80211_IFTYPE_P2P_DEVICE) {
1956 struct nl80211_global *global = drv->global;
1957 struct wpa_driver_nl80211_data *tmp1;
1958
1959 dl_list_for_each(tmp1, &global->interfaces,
1960 struct wpa_driver_nl80211_data, list) {
1961 if (drv == tmp1 || drv->wiphy_idx != tmp1->wiphy_idx ||
1962 !tmp1->rfkill)
1963 continue;
1964
1965 wpa_printf(MSG_DEBUG,
1966 "nl80211: Use (%s) to initialize P2P Device rfkill",
1967 tmp1->first_bss->ifname);
1968 os_strlcpy(rcfg->ifname, tmp1->first_bss->ifname,
1969 sizeof(rcfg->ifname));
1970 break;
1971 }
1972 } else {
1973 os_strlcpy(rcfg->ifname, drv->first_bss->ifname,
1974 sizeof(rcfg->ifname));
1975 }
1976
1977 rcfg->blocked_cb = wpa_driver_nl80211_rfkill_blocked;
1978 rcfg->unblocked_cb = wpa_driver_nl80211_rfkill_unblocked;
1979 drv->rfkill = rfkill_init(rcfg);
1980 if (!drv->rfkill) {
1981 wpa_printf(MSG_DEBUG, "nl80211: RFKILL status not available");
1982 os_free(rcfg);
1983 }
1984 }
1985
1986
1987 static void * wpa_driver_nl80211_drv_init(void *ctx, const char *ifname,
1988 void *global_priv, int hostapd,
1989 const u8 *set_addr,
1990 const char *driver_params)
1991 {
1992 struct wpa_driver_nl80211_data *drv;
1993 struct i802_bss *bss;
1994
1995 if (global_priv == NULL)
1996 return NULL;
1997 drv = os_zalloc(sizeof(*drv));
1998 if (drv == NULL)
1999 return NULL;
2000 drv->global = global_priv;
2001 drv->ctx = ctx;
2002 drv->hostapd = !!hostapd;
2003 drv->eapol_sock = -1;
2004
2005 /*
2006 * There is no driver capability flag for this, so assume it is
2007 * supported and disable this on first attempt to use if the driver
2008 * rejects the command due to missing support.
2009 */
2010 drv->set_rekey_offload = 1;
2011
2012 drv->num_if_indices = sizeof(drv->default_if_indices) / sizeof(int);
2013 drv->if_indices = drv->default_if_indices;
2014 drv->if_indices_reason = drv->default_if_indices_reason;
2015
2016 drv->first_bss = os_zalloc(sizeof(*drv->first_bss));
2017 if (!drv->first_bss) {
2018 os_free(drv);
2019 return NULL;
2020 }
2021 bss = drv->first_bss;
2022 bss->drv = drv;
2023 bss->ctx = ctx;
2024
2025 os_strlcpy(bss->ifname, ifname, sizeof(bss->ifname));
2026 drv->monitor_ifidx = -1;
2027 drv->monitor_sock = -1;
2028 drv->eapol_tx_sock = -1;
2029 drv->ap_scan_as_station = NL80211_IFTYPE_UNSPECIFIED;
2030
2031 if (nl80211_init_bss(bss))
2032 goto failed;
2033
2034 if (wpa_driver_nl80211_finish_drv_init(drv, set_addr, 1, driver_params))
2035 goto failed;
2036
2037 drv->eapol_tx_sock = socket(PF_PACKET, SOCK_DGRAM, 0);
2038 if (drv->eapol_tx_sock < 0)
2039 goto failed;
2040
2041 if (drv->data_tx_status) {
2042 int enabled = 1;
2043
2044 if (setsockopt(drv->eapol_tx_sock, SOL_SOCKET, SO_WIFI_STATUS,
2045 &enabled, sizeof(enabled)) < 0) {
2046 wpa_printf(MSG_DEBUG,
2047 "nl80211: wifi status sockopt failed\n");
2048 drv->data_tx_status = 0;
2049 if (!drv->use_monitor)
2050 drv->capa.flags &=
2051 ~WPA_DRIVER_FLAGS_EAPOL_TX_STATUS;
2052 } else {
2053 eloop_register_read_sock(drv->eapol_tx_sock,
2054 wpa_driver_nl80211_handle_eapol_tx_status,
2055 drv, NULL);
2056 }
2057 }
2058
2059 if (drv->global) {
2060 nl80211_check_global(drv->global);
2061 dl_list_add(&drv->global->interfaces, &drv->list);
2062 drv->in_interface_list = 1;
2063 }
2064
2065 return bss;
2066
2067 failed:
2068 wpa_driver_nl80211_deinit(bss);
2069 return NULL;
2070 }
2071
2072
2073 /**
2074 * wpa_driver_nl80211_init - Initialize nl80211 driver interface
2075 * @ctx: context to be used when calling wpa_supplicant functions,
2076 * e.g., wpa_supplicant_event()
2077 * @ifname: interface name, e.g., wlan0
2078 * @global_priv: private driver global data from global_init()
2079 * Returns: Pointer to private data, %NULL on failure
2080 */
2081 static void * wpa_driver_nl80211_init(void *ctx, const char *ifname,
2082 void *global_priv)
2083 {
2084 return wpa_driver_nl80211_drv_init(ctx, ifname, global_priv, 0, NULL,
2085 NULL);
2086 }
2087
2088
2089 static int nl80211_register_frame(struct i802_bss *bss,
2090 struct nl_handle *nl_handle,
2091 u16 type, const u8 *match, size_t match_len)
2092 {
2093 struct wpa_driver_nl80211_data *drv = bss->drv;
2094 struct nl_msg *msg;
2095 int ret;
2096 char buf[30];
2097
2098 buf[0] = '\0';
2099 wpa_snprintf_hex(buf, sizeof(buf), match, match_len);
2100 wpa_printf(MSG_DEBUG, "nl80211: Register frame type=0x%x (%s) nl_handle=%p match=%s",
2101 type, fc2str(type), nl_handle, buf);
2102
2103 if (!(msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_REGISTER_ACTION)) ||
2104 nla_put_u16(msg, NL80211_ATTR_FRAME_TYPE, type) ||
2105 nla_put(msg, NL80211_ATTR_FRAME_MATCH, match_len, match)) {
2106 nlmsg_free(msg);
2107 return -1;
2108 }
2109
2110 ret = send_and_recv(drv->global, nl_handle, msg, NULL, NULL);
2111 if (ret) {
2112 wpa_printf(MSG_DEBUG, "nl80211: Register frame command "
2113 "failed (type=%u): ret=%d (%s)",
2114 type, ret, strerror(-ret));
2115 wpa_hexdump(MSG_DEBUG, "nl80211: Register frame match",
2116 match, match_len);
2117 }
2118 return ret;
2119 }
2120
2121
2122 static int nl80211_alloc_mgmt_handle(struct i802_bss *bss)
2123 {
2124 if (bss->nl_mgmt) {
2125 wpa_printf(MSG_DEBUG, "nl80211: Mgmt reporting "
2126 "already on! (nl_mgmt=%p)", bss->nl_mgmt);
2127 return -1;
2128 }
2129
2130 bss->nl_mgmt = nl_create_handle(bss->nl_cb, "mgmt");
2131 if (bss->nl_mgmt == NULL)
2132 return -1;
2133
2134 return 0;
2135 }
2136
2137
2138 static void nl80211_mgmt_handle_register_eloop(struct i802_bss *bss)
2139 {
2140 nl80211_register_eloop_read(&bss->nl_mgmt,
2141 wpa_driver_nl80211_event_receive,
2142 bss->nl_cb, 0);
2143 }
2144
2145
2146 static int nl80211_register_action_frame(struct i802_bss *bss,
2147 const u8 *match, size_t match_len)
2148 {
2149 u16 type = (WLAN_FC_TYPE_MGMT << 2) | (WLAN_FC_STYPE_ACTION << 4);
2150 return nl80211_register_frame(bss, bss->nl_mgmt,
2151 type, match, match_len);
2152 }
2153
2154
2155 static int nl80211_init_connect_handle(struct i802_bss *bss)
2156 {
2157 if (bss->nl_connect) {
2158 wpa_printf(MSG_DEBUG,
2159 "nl80211: Connect handle already created (nl_connect=%p)",
2160 bss->nl_connect);
2161 return -1;
2162 }
2163
2164 bss->nl_connect = nl_create_handle(bss->nl_cb, "connect");
2165 if (!bss->nl_connect)
2166 return -1;
2167 nl80211_register_eloop_read(&bss->nl_connect,
2168 wpa_driver_nl80211_event_receive,
2169 bss->nl_cb, 1);
2170 return 0;
2171 }
2172
2173
2174 static int nl80211_mgmt_subscribe_non_ap(struct i802_bss *bss)
2175 {
2176 struct wpa_driver_nl80211_data *drv = bss->drv;
2177 int ret = 0;
2178
2179 if (nl80211_alloc_mgmt_handle(bss))
2180 return -1;
2181 wpa_printf(MSG_DEBUG, "nl80211: Subscribe to mgmt frames with non-AP "
2182 "handle %p", bss->nl_mgmt);
2183
2184 if (drv->nlmode == NL80211_IFTYPE_ADHOC ||
2185 ((drv->capa.flags & WPA_DRIVER_FLAGS_SAE) &&
2186 !(drv->capa.flags & WPA_DRIVER_FLAGS_SME))) {
2187 u16 type = (WLAN_FC_TYPE_MGMT << 2) | (WLAN_FC_STYPE_AUTH << 4);
2188
2189 /* register for any AUTH message */
2190 nl80211_register_frame(bss, bss->nl_mgmt, type, NULL, 0);
2191 }
2192
2193 #ifdef CONFIG_INTERWORKING
2194 /* QoS Map Configure */
2195 if (nl80211_register_action_frame(bss, (u8 *) "\x01\x04", 2) < 0)
2196 ret = -1;
2197 #endif /* CONFIG_INTERWORKING */
2198 #if defined(CONFIG_P2P) || defined(CONFIG_INTERWORKING) || defined(CONFIG_DPP)
2199 /* GAS Initial Request */
2200 if (nl80211_register_action_frame(bss, (u8 *) "\x04\x0a", 2) < 0)
2201 ret = -1;
2202 /* GAS Initial Response */
2203 if (nl80211_register_action_frame(bss, (u8 *) "\x04\x0b", 2) < 0)
2204 ret = -1;
2205 /* GAS Comeback Request */
2206 if (nl80211_register_action_frame(bss, (u8 *) "\x04\x0c", 2) < 0)
2207 ret = -1;
2208 /* GAS Comeback Response */
2209 if (nl80211_register_action_frame(bss, (u8 *) "\x04\x0d", 2) < 0)
2210 ret = -1;
2211 /* Protected GAS Initial Request */
2212 if (nl80211_register_action_frame(bss, (u8 *) "\x09\x0a", 2) < 0)
2213 ret = -1;
2214 /* Protected GAS Initial Response */
2215 if (nl80211_register_action_frame(bss, (u8 *) "\x09\x0b", 2) < 0)
2216 ret = -1;
2217 /* Protected GAS Comeback Request */
2218 if (nl80211_register_action_frame(bss, (u8 *) "\x09\x0c", 2) < 0)
2219 ret = -1;
2220 /* Protected GAS Comeback Response */
2221 if (nl80211_register_action_frame(bss, (u8 *) "\x09\x0d", 2) < 0)
2222 ret = -1;
2223 #endif /* CONFIG_P2P || CONFIG_INTERWORKING || CONFIG_DPP */
2224 #ifdef CONFIG_P2P
2225 /* P2P Public Action */
2226 if (nl80211_register_action_frame(bss,
2227 (u8 *) "\x04\x09\x50\x6f\x9a\x09",
2228 6) < 0)
2229 ret = -1;
2230 /* P2P Action */
2231 if (nl80211_register_action_frame(bss,
2232 (u8 *) "\x7f\x50\x6f\x9a\x09",
2233 5) < 0)
2234 ret = -1;
2235 #endif /* CONFIG_P2P */
2236 #ifdef CONFIG_DPP
2237 /* DPP Public Action */
2238 if (nl80211_register_action_frame(bss,
2239 (u8 *) "\x04\x09\x50\x6f\x9a\x1a",
2240 6) < 0)
2241 ret = -1;
2242 #endif /* CONFIG_DPP */
2243 #ifdef CONFIG_IEEE80211W
2244 #ifdef CONFIG_OCV
2245 /* SA Query Request */
2246 if (nl80211_register_action_frame(bss, (u8 *) "\x08\x00", 2) < 0)
2247 ret = -1;
2248 #endif /* CONFIG_OCV */
2249 /* SA Query Response */
2250 if (nl80211_register_action_frame(bss, (u8 *) "\x08\x01", 2) < 0)
2251 ret = -1;
2252 #endif /* CONFIG_IEEE80211W */
2253 #ifdef CONFIG_TDLS
2254 if ((drv->capa.flags & WPA_DRIVER_FLAGS_TDLS_SUPPORT)) {
2255 /* TDLS Discovery Response */
2256 if (nl80211_register_action_frame(bss, (u8 *) "\x04\x0e", 2) <
2257 0)
2258 ret = -1;
2259 }
2260 #endif /* CONFIG_TDLS */
2261 #ifdef CONFIG_FST
2262 /* FST Action frames */
2263 if (nl80211_register_action_frame(bss, (u8 *) "\x12", 1) < 0)
2264 ret = -1;
2265 #endif /* CONFIG_FST */
2266
2267 /* FT Action frames */
2268 if (nl80211_register_action_frame(bss, (u8 *) "\x06", 1) < 0)
2269 ret = -1;
2270 else
2271 drv->capa.key_mgmt |= WPA_DRIVER_CAPA_KEY_MGMT_FT |
2272 WPA_DRIVER_CAPA_KEY_MGMT_FT_PSK;
2273
2274 /* WNM - BSS Transition Management Request */
2275 if (nl80211_register_action_frame(bss, (u8 *) "\x0a\x07", 2) < 0)
2276 ret = -1;
2277 /* WNM-Sleep Mode Response */
2278 if (nl80211_register_action_frame(bss, (u8 *) "\x0a\x11", 2) < 0)
2279 ret = -1;
2280 #ifdef CONFIG_WNM
2281 /* WNM - Collocated Interference Request */
2282 if (nl80211_register_action_frame(bss, (u8 *) "\x0a\x0b", 2) < 0)
2283 ret = -1;
2284 #endif /* CONFIG_WNM */
2285
2286 #ifdef CONFIG_HS20
2287 /* WNM-Notification */
2288 if (nl80211_register_action_frame(bss, (u8 *) "\x0a\x1a", 2) < 0)
2289 ret = -1;
2290 #endif /* CONFIG_HS20 */
2291
2292 /* WMM-AC ADDTS Response */
2293 if (nl80211_register_action_frame(bss, (u8 *) "\x11\x01", 2) < 0)
2294 ret = -1;
2295
2296 /* WMM-AC DELTS */
2297 if (nl80211_register_action_frame(bss, (u8 *) "\x11\x02", 2) < 0)
2298 ret = -1;
2299
2300 /* Radio Measurement - Neighbor Report Response */
2301 if (nl80211_register_action_frame(bss, (u8 *) "\x05\x05", 2) < 0)
2302 ret = -1;
2303
2304 /* Radio Measurement - Radio Measurement Request */
2305 if (nl80211_register_action_frame(bss, (u8 *) "\x05\x00", 2) < 0)
2306 ret = -1;
2307
2308 /* Radio Measurement - Link Measurement Request */
2309 if ((drv->capa.rrm_flags & WPA_DRIVER_FLAGS_TX_POWER_INSERTION) &&
2310 (nl80211_register_action_frame(bss, (u8 *) "\x05\x02", 2) < 0))
2311 ret = -1;
2312
2313 nl80211_mgmt_handle_register_eloop(bss);
2314
2315 return ret;
2316 }
2317
2318
2319 static int nl80211_mgmt_subscribe_mesh(struct i802_bss *bss)
2320 {
2321 int ret = 0;
2322
2323 if (nl80211_alloc_mgmt_handle(bss))
2324 return -1;
2325
2326 wpa_printf(MSG_DEBUG,
2327 "nl80211: Subscribe to mgmt frames with mesh handle %p",
2328 bss->nl_mgmt);
2329
2330 /* Auth frames for mesh SAE */
2331 if (nl80211_register_frame(bss, bss->nl_mgmt,
2332 (WLAN_FC_TYPE_MGMT << 2) |
2333 (WLAN_FC_STYPE_AUTH << 4),
2334 NULL, 0) < 0)
2335 ret = -1;
2336
2337 /* Mesh peering open */
2338 if (nl80211_register_action_frame(bss, (u8 *) "\x0f\x01", 2) < 0)
2339 ret = -1;
2340 /* Mesh peering confirm */
2341 if (nl80211_register_action_frame(bss, (u8 *) "\x0f\x02", 2) < 0)
2342 ret = -1;
2343 /* Mesh peering close */
2344 if (nl80211_register_action_frame(bss, (u8 *) "\x0f\x03", 2) < 0)
2345 ret = -1;
2346
2347 nl80211_mgmt_handle_register_eloop(bss);
2348
2349 return ret;
2350 }
2351
2352
2353 static int nl80211_register_spurious_class3(struct i802_bss *bss)
2354 {
2355 struct nl_msg *msg;
2356 int ret;
2357
2358 msg = nl80211_bss_msg(bss, 0, NL80211_CMD_UNEXPECTED_FRAME);
2359 ret = send_and_recv(bss->drv->global, bss->nl_mgmt, msg, NULL, NULL);
2360 if (ret) {
2361 wpa_printf(MSG_DEBUG, "nl80211: Register spurious class3 "
2362 "failed: ret=%d (%s)",
2363 ret, strerror(-ret));
2364 }
2365 return ret;
2366 }
2367
2368
2369 static int nl80211_action_subscribe_ap(struct i802_bss *bss)
2370 {
2371 int ret = 0;
2372
2373 /* Public Action frames */
2374 if (nl80211_register_action_frame(bss, (u8 *) "\x04", 1) < 0)
2375 ret = -1;
2376 /* RRM Measurement Report */
2377 if (nl80211_register_action_frame(bss, (u8 *) "\x05\x01", 2) < 0)
2378 ret = -1;
2379 /* RRM Link Measurement Report */
2380 if (nl80211_register_action_frame(bss, (u8 *) "\x05\x03", 2) < 0)
2381 ret = -1;
2382 /* RRM Neighbor Report Request */
2383 if (nl80211_register_action_frame(bss, (u8 *) "\x05\x04", 2) < 0)
2384 ret = -1;
2385 /* FT Action frames */
2386 if (nl80211_register_action_frame(bss, (u8 *) "\x06", 1) < 0)
2387 ret = -1;
2388 #ifdef CONFIG_IEEE80211W
2389 /* SA Query */
2390 if (nl80211_register_action_frame(bss, (u8 *) "\x08", 1) < 0)
2391 ret = -1;
2392 #endif /* CONFIG_IEEE80211W */
2393 /* Protected Dual of Public Action */
2394 if (nl80211_register_action_frame(bss, (u8 *) "\x09", 1) < 0)
2395 ret = -1;
2396 /* WNM */
2397 if (nl80211_register_action_frame(bss, (u8 *) "\x0a", 1) < 0)
2398 ret = -1;
2399 /* WMM */
2400 if (nl80211_register_action_frame(bss, (u8 *) "\x11", 1) < 0)
2401 ret = -1;
2402 #ifdef CONFIG_FST
2403 /* FST Action frames */
2404 if (nl80211_register_action_frame(bss, (u8 *) "\x12", 1) < 0)
2405 ret = -1;
2406 #endif /* CONFIG_FST */
2407 /* Vendor-specific */
2408 if (nl80211_register_action_frame(bss, (u8 *) "\x7f", 1) < 0)
2409 ret = -1;
2410
2411 return ret;
2412 }
2413
2414
2415 static int nl80211_mgmt_subscribe_ap(struct i802_bss *bss)
2416 {
2417 static const int stypes[] = {
2418 WLAN_FC_STYPE_AUTH,
2419 WLAN_FC_STYPE_ASSOC_REQ,
2420 WLAN_FC_STYPE_REASSOC_REQ,
2421 WLAN_FC_STYPE_DISASSOC,
2422 WLAN_FC_STYPE_DEAUTH,
2423 WLAN_FC_STYPE_PROBE_REQ,
2424 /* Beacon doesn't work as mac80211 doesn't currently allow
2425 * it, but it wouldn't really be the right thing anyway as
2426 * it isn't per interface ... maybe just dump the scan
2427 * results periodically for OLBC?
2428 */
2429 /* WLAN_FC_STYPE_BEACON, */
2430 };
2431 unsigned int i;
2432
2433 if (nl80211_alloc_mgmt_handle(bss))
2434 return -1;
2435 wpa_printf(MSG_DEBUG, "nl80211: Subscribe to mgmt frames with AP "
2436 "handle %p", bss->nl_mgmt);
2437
2438 for (i = 0; i < ARRAY_SIZE(stypes); i++) {
2439 if (nl80211_register_frame(bss, bss->nl_mgmt,
2440 (WLAN_FC_TYPE_MGMT << 2) |
2441 (stypes[i] << 4),
2442 NULL, 0) < 0) {
2443 goto out_err;
2444 }
2445 }
2446
2447 if (nl80211_action_subscribe_ap(bss))
2448 goto out_err;
2449
2450 if (nl80211_register_spurious_class3(bss))
2451 goto out_err;
2452
2453 nl80211_mgmt_handle_register_eloop(bss);
2454 return 0;
2455
2456 out_err:
2457 nl_destroy_handles(&bss->nl_mgmt);
2458 return -1;
2459 }
2460
2461
2462 static int nl80211_mgmt_subscribe_ap_dev_sme(struct i802_bss *bss)
2463 {
2464 if (nl80211_alloc_mgmt_handle(bss))
2465 return -1;
2466 wpa_printf(MSG_DEBUG, "nl80211: Subscribe to mgmt frames with AP "
2467 "handle %p (device SME)", bss->nl_mgmt);
2468
2469 if (nl80211_action_subscribe_ap(bss))
2470 goto out_err;
2471
2472 if (bss->drv->device_ap_sme) {
2473 u16 type = (WLAN_FC_TYPE_MGMT << 2) | (WLAN_FC_STYPE_AUTH << 4);
2474
2475 /* Register for all Authentication frames */
2476 if (nl80211_register_frame(bss, bss->nl_mgmt, type, NULL, 0)
2477 < 0)
2478 wpa_printf(MSG_DEBUG,
2479 "nl80211: Failed to subscribe to handle Authentication frames - SAE offload may not work");
2480 }
2481
2482 nl80211_mgmt_handle_register_eloop(bss);
2483 return 0;
2484
2485 out_err:
2486 nl_destroy_handles(&bss->nl_mgmt);
2487 return -1;
2488 }
2489
2490
2491 static void nl80211_mgmt_unsubscribe(struct i802_bss *bss, const char *reason)
2492 {
2493 if (bss->nl_mgmt == NULL)
2494 return;
2495 wpa_printf(MSG_DEBUG, "nl80211: Unsubscribe mgmt frames handle %p "
2496 "(%s)", bss->nl_mgmt, reason);
2497 nl80211_destroy_eloop_handle(&bss->nl_mgmt, 0);
2498
2499 nl80211_put_wiphy_data_ap(bss);
2500 }
2501
2502
2503 static void wpa_driver_nl80211_send_rfkill(void *eloop_ctx, void *timeout_ctx)
2504 {
2505 wpa_supplicant_event(timeout_ctx, EVENT_INTERFACE_DISABLED, NULL);
2506 }
2507
2508
2509 static void nl80211_del_p2pdev(struct i802_bss *bss)
2510 {
2511 struct nl_msg *msg;
2512 int ret;
2513
2514 msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_DEL_INTERFACE);
2515 ret = send_and_recv_msgs(bss->drv, msg, NULL, NULL);
2516
2517 wpa_printf(MSG_DEBUG, "nl80211: Delete P2P Device %s (0x%llx): %s",
2518 bss->ifname, (long long unsigned int) bss->wdev_id,
2519 strerror(-ret));
2520 }
2521
2522
2523 static int nl80211_set_p2pdev(struct i802_bss *bss, int start)
2524 {
2525 struct nl_msg *msg;
2526 int ret;
2527
2528 msg = nl80211_cmd_msg(bss, 0, start ? NL80211_CMD_START_P2P_DEVICE :
2529 NL80211_CMD_STOP_P2P_DEVICE);
2530 ret = send_and_recv_msgs(bss->drv, msg, NULL, NULL);
2531
2532 wpa_printf(MSG_DEBUG, "nl80211: %s P2P Device %s (0x%llx): %s",
2533 start ? "Start" : "Stop",
2534 bss->ifname, (long long unsigned int) bss->wdev_id,
2535 strerror(-ret));
2536 return ret;
2537 }
2538
2539
2540 static int i802_set_iface_flags(struct i802_bss *bss, int up)
2541 {
2542 enum nl80211_iftype nlmode;
2543
2544 nlmode = nl80211_get_ifmode(bss);
2545 if (nlmode != NL80211_IFTYPE_P2P_DEVICE) {
2546 return linux_set_iface_flags(bss->drv->global->ioctl_sock,
2547 bss->ifname, up);
2548 }
2549
2550 /* P2P Device has start/stop which is equivalent */
2551 return nl80211_set_p2pdev(bss, up);
2552 }
2553
2554
2555 #ifdef CONFIG_TESTING_OPTIONS
2556 static int qca_vendor_test_cmd_handler(struct nl_msg *msg, void *arg)
2557 {
2558 /* struct wpa_driver_nl80211_data *drv = arg; */
2559 struct nlattr *tb[NL80211_ATTR_MAX + 1];
2560 struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg));
2561
2562
2563 wpa_printf(MSG_DEBUG,
2564 "nl80211: QCA vendor test command response received");
2565
2566 nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0),
2567 genlmsg_attrlen(gnlh, 0), NULL);
2568 if (!tb[NL80211_ATTR_VENDOR_DATA]) {
2569 wpa_printf(MSG_DEBUG, "nl80211: No vendor data attribute");
2570 return NL_SKIP;
2571 }
2572
2573 wpa_hexdump(MSG_DEBUG,
2574 "nl80211: Received QCA vendor test command response",
2575 nla_data(tb[NL80211_ATTR_VENDOR_DATA]),
2576 nla_len(tb[NL80211_ATTR_VENDOR_DATA]));
2577
2578 return NL_SKIP;
2579 }
2580 #endif /* CONFIG_TESTING_OPTIONS */
2581
2582
2583 static void qca_vendor_test(struct wpa_driver_nl80211_data *drv)
2584 {
2585 #ifdef CONFIG_TESTING_OPTIONS
2586 struct nl_msg *msg;
2587 struct nlattr *params;
2588 int ret;
2589
2590 if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_VENDOR)) ||
2591 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
2592 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
2593 QCA_NL80211_VENDOR_SUBCMD_TEST) ||
2594 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
2595 nla_put_u32(msg, QCA_WLAN_VENDOR_ATTR_TEST, 123)) {
2596 nlmsg_free(msg);
2597 return;
2598 }
2599 nla_nest_end(msg, params);
2600
2601 ret = send_and_recv_msgs(drv, msg, qca_vendor_test_cmd_handler, drv);
2602 wpa_printf(MSG_DEBUG,
2603 "nl80211: QCA vendor test command returned %d (%s)",
2604 ret, strerror(-ret));
2605 #endif /* CONFIG_TESTING_OPTIONS */
2606 }
2607
2608
2609 static int
2610 wpa_driver_nl80211_finish_drv_init(struct wpa_driver_nl80211_data *drv,
2611 const u8 *set_addr, int first,
2612 const char *driver_params)
2613 {
2614 struct i802_bss *bss = drv->first_bss;
2615 int send_rfkill_event = 0;
2616 enum nl80211_iftype nlmode;
2617
2618 drv->ifindex = if_nametoindex(bss->ifname);
2619 bss->ifindex = drv->ifindex;
2620 bss->wdev_id = drv->global->if_add_wdevid;
2621 bss->wdev_id_set = drv->global->if_add_wdevid_set;
2622
2623 bss->if_dynamic = drv->ifindex == drv->global->if_add_ifindex;
2624 bss->if_dynamic = bss->if_dynamic || drv->global->if_add_wdevid_set;
2625 drv->global->if_add_wdevid_set = 0;
2626
2627 if (!bss->if_dynamic && nl80211_get_ifmode(bss) == NL80211_IFTYPE_AP)
2628 bss->static_ap = 1;
2629
2630 if (first &&
2631 nl80211_get_ifmode(bss) != NL80211_IFTYPE_P2P_DEVICE &&
2632 linux_iface_up(drv->global->ioctl_sock, bss->ifname) > 0)
2633 drv->start_iface_up = 1;
2634
2635 if (wpa_driver_nl80211_capa(drv))
2636 return -1;
2637
2638 if (driver_params && nl80211_set_param(bss, driver_params) < 0)
2639 return -1;
2640
2641 wpa_printf(MSG_DEBUG, "nl80211: interface %s in phy %s",
2642 bss->ifname, drv->phyname);
2643
2644 if (set_addr &&
2645 (linux_set_iface_flags(drv->global->ioctl_sock, bss->ifname, 0) ||
2646 linux_set_ifhwaddr(drv->global->ioctl_sock, bss->ifname,
2647 set_addr)))
2648 return -1;
2649
2650 if (first && nl80211_get_ifmode(bss) == NL80211_IFTYPE_AP)
2651 drv->start_mode_ap = 1;
2652
2653 if (drv->hostapd || bss->static_ap)
2654 nlmode = NL80211_IFTYPE_AP;
2655 else if (bss->if_dynamic ||
2656 nl80211_get_ifmode(bss) == NL80211_IFTYPE_MESH_POINT)
2657 nlmode = nl80211_get_ifmode(bss);
2658 else
2659 nlmode = NL80211_IFTYPE_STATION;
2660
2661 if (wpa_driver_nl80211_set_mode(bss, nlmode) < 0) {
2662 wpa_printf(MSG_ERROR, "nl80211: Could not configure driver mode");
2663 return -1;
2664 }
2665
2666 if (nlmode == NL80211_IFTYPE_P2P_DEVICE)
2667 nl80211_get_macaddr(bss);
2668
2669 wpa_driver_nl80211_drv_init_rfkill(drv);
2670
2671 if (!rfkill_is_blocked(drv->rfkill)) {
2672 int ret = i802_set_iface_flags(bss, 1);
2673 if (ret) {
2674 wpa_printf(MSG_ERROR, "nl80211: Could not set "
2675 "interface '%s' UP", bss->ifname);
2676 return ret;
2677 }
2678
2679 if (is_p2p_net_interface(nlmode))
2680 nl80211_disable_11b_rates(bss->drv,
2681 bss->drv->ifindex, 1);
2682
2683 if (nlmode == NL80211_IFTYPE_P2P_DEVICE)
2684 return ret;
2685 } else {
2686 wpa_printf(MSG_DEBUG, "nl80211: Could not yet enable "
2687 "interface '%s' due to rfkill", bss->ifname);
2688 if (nlmode != NL80211_IFTYPE_P2P_DEVICE)
2689 drv->if_disabled = 1;
2690
2691 send_rfkill_event = 1;
2692 }
2693
2694 if (!drv->hostapd && nlmode != NL80211_IFTYPE_P2P_DEVICE)
2695 netlink_send_oper_ifla(drv->global->netlink, drv->ifindex,
2696 1, IF_OPER_DORMANT);
2697
2698 if (nlmode != NL80211_IFTYPE_P2P_DEVICE) {
2699 if (linux_get_ifhwaddr(drv->global->ioctl_sock, bss->ifname,
2700 bss->addr))
2701 return -1;
2702 os_memcpy(drv->perm_addr, bss->addr, ETH_ALEN);
2703 }
2704
2705 if (send_rfkill_event) {
2706 eloop_register_timeout(0, 0, wpa_driver_nl80211_send_rfkill,
2707 drv, drv->ctx);
2708 }
2709
2710 if (drv->vendor_cmd_test_avail)
2711 qca_vendor_test(drv);
2712
2713 nl80211_init_connect_handle(bss);
2714
2715 return 0;
2716 }
2717
2718
2719 static int wpa_driver_nl80211_del_beacon(struct i802_bss *bss)
2720 {
2721 struct nl_msg *msg;
2722 struct wpa_driver_nl80211_data *drv = bss->drv;
2723
2724 wpa_printf(MSG_DEBUG, "nl80211: Remove beacon (ifindex=%d)",
2725 drv->ifindex);
2726 nl80211_put_wiphy_data_ap(bss);
2727 msg = nl80211_drv_msg(drv, 0, NL80211_CMD_DEL_BEACON);
2728 return send_and_recv_msgs(drv, msg, NULL, NULL);
2729 }
2730
2731
2732 /**
2733 * wpa_driver_nl80211_deinit - Deinitialize nl80211 driver interface
2734 * @bss: Pointer to private nl80211 data from wpa_driver_nl80211_init()
2735 *
2736 * Shut down driver interface and processing of driver events. Free
2737 * private data buffer if one was allocated in wpa_driver_nl80211_init().
2738 */
2739 static void wpa_driver_nl80211_deinit(struct i802_bss *bss)
2740 {
2741 struct wpa_driver_nl80211_data *drv = bss->drv;
2742 unsigned int i;
2743
2744 wpa_printf(MSG_INFO, "nl80211: deinit ifname=%s disabled_11b_rates=%d",
2745 bss->ifname, drv->disabled_11b_rates);
2746
2747 bss->in_deinit = 1;
2748 if (drv->data_tx_status)
2749 eloop_unregister_read_sock(drv->eapol_tx_sock);
2750 if (drv->eapol_tx_sock >= 0)
2751 close(drv->eapol_tx_sock);
2752
2753 if (bss->nl_preq)
2754 wpa_driver_nl80211_probe_req_report(bss, 0);
2755 if (bss->added_if_into_bridge) {
2756 if (linux_br_del_if(drv->global->ioctl_sock, bss->brname,
2757 bss->ifname) < 0)
2758 wpa_printf(MSG_INFO, "nl80211: Failed to remove "
2759 "interface %s from bridge %s: %s",
2760 bss->ifname, bss->brname, strerror(errno));
2761 }
2762
2763 if (drv->rtnl_sk)
2764 nl80211_handle_destroy(drv->rtnl_sk);
2765
2766 if (bss->added_bridge) {
2767 if (linux_set_iface_flags(drv->global->ioctl_sock, bss->brname,
2768 0) < 0)
2769 wpa_printf(MSG_INFO,
2770 "nl80211: Could not set bridge %s down",
2771 bss->brname);
2772 if (linux_br_del(drv->global->ioctl_sock, bss->brname) < 0)
2773 wpa_printf(MSG_INFO, "nl80211: Failed to remove "
2774 "bridge %s: %s",
2775 bss->brname, strerror(errno));
2776 }
2777
2778 nl80211_remove_monitor_interface(drv);
2779
2780 if (is_ap_interface(drv->nlmode))
2781 wpa_driver_nl80211_del_beacon(bss);
2782
2783 if (drv->eapol_sock >= 0) {
2784 eloop_unregister_read_sock(drv->eapol_sock);
2785 close(drv->eapol_sock);
2786 }
2787
2788 if (drv->if_indices != drv->default_if_indices)
2789 os_free(drv->if_indices);
2790
2791 if (drv->if_indices_reason != drv->default_if_indices_reason)
2792 os_free(drv->if_indices_reason);
2793
2794 if (drv->disabled_11b_rates)
2795 nl80211_disable_11b_rates(drv, drv->ifindex, 0);
2796
2797 netlink_send_oper_ifla(drv->global->netlink, drv->ifindex, 0,
2798 IF_OPER_UP);
2799 eloop_cancel_timeout(wpa_driver_nl80211_send_rfkill, drv, drv->ctx);
2800 rfkill_deinit(drv->rfkill);
2801
2802 eloop_cancel_timeout(wpa_driver_nl80211_scan_timeout, drv, drv->ctx);
2803
2804 if (!drv->start_iface_up)
2805 (void) i802_set_iface_flags(bss, 0);
2806
2807 if (drv->addr_changed) {
2808 if (linux_set_iface_flags(drv->global->ioctl_sock, bss->ifname,
2809 0) < 0) {
2810 wpa_printf(MSG_DEBUG,
2811 "nl80211: Could not set interface down to restore permanent MAC address");
2812 }
2813 if (linux_set_ifhwaddr(drv->global->ioctl_sock, bss->ifname,
2814 drv->perm_addr) < 0) {
2815 wpa_printf(MSG_DEBUG,
2816 "nl80211: Could not restore permanent MAC address");
2817 }
2818 }
2819
2820 if (drv->nlmode != NL80211_IFTYPE_P2P_DEVICE) {
2821 if (!drv->hostapd || !drv->start_mode_ap)
2822 wpa_driver_nl80211_set_mode(bss,
2823 NL80211_IFTYPE_STATION);
2824 nl80211_mgmt_unsubscribe(bss, "deinit");
2825 } else {
2826 nl80211_mgmt_unsubscribe(bss, "deinit");
2827 nl80211_del_p2pdev(bss);
2828 }
2829
2830 if (bss->nl_connect)
2831 nl80211_destroy_eloop_handle(&bss->nl_connect, 1);
2832
2833 nl80211_destroy_bss(drv->first_bss);
2834
2835 os_free(drv->filter_ssids);
2836
2837 os_free(drv->auth_ie);
2838
2839 if (drv->in_interface_list)
2840 dl_list_del(&drv->list);
2841
2842 os_free(drv->extended_capa);
2843 os_free(drv->extended_capa_mask);
2844 for (i = 0; i < drv->num_iface_ext_capa; i++) {
2845 os_free(drv->iface_ext_capa[i].ext_capa);
2846 os_free(drv->iface_ext_capa[i].ext_capa_mask);
2847 }
2848 os_free(drv->first_bss);
2849 os_free(drv);
2850 }
2851
2852
2853 static u32 wpa_alg_to_cipher_suite(enum wpa_alg alg, size_t key_len)
2854 {
2855 switch (alg) {
2856 case WPA_ALG_WEP:
2857 if (key_len == 5)
2858 return RSN_CIPHER_SUITE_WEP40;
2859 return RSN_CIPHER_SUITE_WEP104;
2860 case WPA_ALG_TKIP:
2861 return RSN_CIPHER_SUITE_TKIP;
2862 case WPA_ALG_CCMP:
2863 return RSN_CIPHER_SUITE_CCMP;
2864 case WPA_ALG_GCMP:
2865 return RSN_CIPHER_SUITE_GCMP;
2866 case WPA_ALG_CCMP_256:
2867 return RSN_CIPHER_SUITE_CCMP_256;
2868 case WPA_ALG_GCMP_256:
2869 return RSN_CIPHER_SUITE_GCMP_256;
2870 case WPA_ALG_IGTK:
2871 return RSN_CIPHER_SUITE_AES_128_CMAC;
2872 case WPA_ALG_BIP_GMAC_128:
2873 return RSN_CIPHER_SUITE_BIP_GMAC_128;
2874 case WPA_ALG_BIP_GMAC_256:
2875 return RSN_CIPHER_SUITE_BIP_GMAC_256;
2876 case WPA_ALG_BIP_CMAC_256:
2877 return RSN_CIPHER_SUITE_BIP_CMAC_256;
2878 case WPA_ALG_SMS4:
2879 return RSN_CIPHER_SUITE_SMS4;
2880 case WPA_ALG_KRK:
2881 return RSN_CIPHER_SUITE_KRK;
2882 case WPA_ALG_NONE:
2883 case WPA_ALG_PMK:
2884 wpa_printf(MSG_ERROR, "nl80211: Unexpected encryption algorithm %d",
2885 alg);
2886 return 0;
2887 }
2888
2889 wpa_printf(MSG_ERROR, "nl80211: Unsupported encryption algorithm %d",
2890 alg);
2891 return 0;
2892 }
2893
2894
2895 static u32 wpa_cipher_to_cipher_suite(unsigned int cipher)
2896 {
2897 switch (cipher) {
2898 case WPA_CIPHER_CCMP_256:
2899 return RSN_CIPHER_SUITE_CCMP_256;
2900 case WPA_CIPHER_GCMP_256:
2901 return RSN_CIPHER_SUITE_GCMP_256;
2902 case WPA_CIPHER_CCMP:
2903 return RSN_CIPHER_SUITE_CCMP;
2904 case WPA_CIPHER_GCMP:
2905 return RSN_CIPHER_SUITE_GCMP;
2906 case WPA_CIPHER_TKIP:
2907 return RSN_CIPHER_SUITE_TKIP;
2908 case WPA_CIPHER_WEP104:
2909 return RSN_CIPHER_SUITE_WEP104;
2910 case WPA_CIPHER_WEP40:
2911 return RSN_CIPHER_SUITE_WEP40;
2912 case WPA_CIPHER_GTK_NOT_USED:
2913 return RSN_CIPHER_SUITE_NO_GROUP_ADDRESSED;
2914 }
2915
2916 return 0;
2917 }
2918
2919
2920 static int wpa_cipher_to_cipher_suites(unsigned int ciphers, u32 suites[],
2921 int max_suites)
2922 {
2923 int num_suites = 0;
2924
2925 if (num_suites < max_suites && ciphers & WPA_CIPHER_CCMP_256)
2926 suites[num_suites++] = RSN_CIPHER_SUITE_CCMP_256;
2927 if (num_suites < max_suites && ciphers & WPA_CIPHER_GCMP_256)
2928 suites[num_suites++] = RSN_CIPHER_SUITE_GCMP_256;
2929 if (num_suites < max_suites && ciphers & WPA_CIPHER_CCMP)
2930 suites[num_suites++] = RSN_CIPHER_SUITE_CCMP;
2931 if (num_suites < max_suites && ciphers & WPA_CIPHER_GCMP)
2932 suites[num_suites++] = RSN_CIPHER_SUITE_GCMP;
2933 if (num_suites < max_suites && ciphers & WPA_CIPHER_TKIP)
2934 suites[num_suites++] = RSN_CIPHER_SUITE_TKIP;
2935 if (num_suites < max_suites && ciphers & WPA_CIPHER_WEP104)
2936 suites[num_suites++] = RSN_CIPHER_SUITE_WEP104;
2937 if (num_suites < max_suites && ciphers & WPA_CIPHER_WEP40)
2938 suites[num_suites++] = RSN_CIPHER_SUITE_WEP40;
2939
2940 return num_suites;
2941 }
2942
2943
2944 #ifdef CONFIG_DRIVER_NL80211_QCA
2945 static int issue_key_mgmt_set_key(struct wpa_driver_nl80211_data *drv,
2946 const u8 *key, size_t key_len)
2947 {
2948 struct nl_msg *msg;
2949 int ret;
2950
2951 if (!(drv->capa.flags & WPA_DRIVER_FLAGS_KEY_MGMT_OFFLOAD))
2952 return 0;
2953
2954 if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_VENDOR)) ||
2955 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
2956 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
2957 QCA_NL80211_VENDOR_SUBCMD_KEY_MGMT_SET_KEY) ||
2958 nla_put(msg, NL80211_ATTR_VENDOR_DATA, key_len, key)) {
2959 nl80211_nlmsg_clear(msg);
2960 nlmsg_free(msg);
2961 return -1;
2962 }
2963 ret = send_and_recv_msgs(drv, msg, NULL, (void *) -1);
2964 if (ret) {
2965 wpa_printf(MSG_DEBUG,
2966 "nl80211: Key management set key failed: ret=%d (%s)",
2967 ret, strerror(-ret));
2968 }
2969
2970 return ret;
2971 }
2972 #endif /* CONFIG_DRIVER_NL80211_QCA */
2973
2974
2975 static int nl80211_set_pmk(struct wpa_driver_nl80211_data *drv,
2976 const u8 *key, size_t key_len,
2977 const u8 *addr)
2978 {
2979 struct nl_msg *msg = NULL;
2980 int ret;
2981
2982 /*
2983 * If the authenticator address is not set, assume it is
2984 * the current BSSID.
2985 */
2986 if (!addr && drv->associated)
2987 addr = drv->bssid;
2988 else if (!addr)
2989 return -1;
2990
2991 wpa_printf(MSG_DEBUG, "nl80211: Set PMK to the driver for " MACSTR,
2992 MAC2STR(addr));
2993 wpa_hexdump_key(MSG_DEBUG, "nl80211: PMK", key, key_len);
2994 msg = nl80211_drv_msg(drv, 0, NL80211_CMD_SET_PMK);
2995 if (!msg ||
2996 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) ||
2997 nla_put(msg, NL80211_ATTR_PMK, key_len, key)) {
2998 nl80211_nlmsg_clear(msg);
2999 nlmsg_free(msg);
3000 return -ENOBUFS;
3001 }
3002
3003 ret = send_and_recv_msgs(drv, msg, NULL, (void *) -1);
3004 if (ret) {
3005 wpa_printf(MSG_DEBUG, "nl80211: Set PMK failed: ret=%d (%s)",
3006 ret, strerror(-ret));
3007 }
3008
3009 return ret;
3010 }
3011
3012
3013 static int wpa_driver_nl80211_set_key(const char *ifname, struct i802_bss *bss,
3014 enum wpa_alg alg, const u8 *addr,
3015 int key_idx, int set_tx,
3016 const u8 *seq, size_t seq_len,
3017 const u8 *key, size_t key_len)
3018 {
3019 struct wpa_driver_nl80211_data *drv = bss->drv;
3020 int ifindex;
3021 struct nl_msg *msg = NULL;
3022 int ret;
3023 int tdls = 0;
3024
3025 /* Ignore for P2P Device */
3026 if (drv->nlmode == NL80211_IFTYPE_P2P_DEVICE)
3027 return 0;
3028
3029 ifindex = if_nametoindex(ifname);
3030 wpa_printf(MSG_DEBUG, "%s: ifindex=%d (%s) alg=%d addr=%p key_idx=%d "
3031 "set_tx=%d seq_len=%lu key_len=%lu",
3032 __func__, ifindex, ifname, alg, addr, key_idx, set_tx,
3033 (unsigned long) seq_len, (unsigned long) key_len);
3034 #ifdef CONFIG_TDLS
3035 if (key_idx == -1) {
3036 key_idx = 0;
3037 tdls = 1;
3038 }
3039 #endif /* CONFIG_TDLS */
3040
3041 #ifdef CONFIG_DRIVER_NL80211_QCA
3042 if (alg == WPA_ALG_PMK &&
3043 (drv->capa.flags & WPA_DRIVER_FLAGS_KEY_MGMT_OFFLOAD)) {
3044 wpa_printf(MSG_DEBUG, "%s: calling issue_key_mgmt_set_key",
3045 __func__);
3046 ret = issue_key_mgmt_set_key(drv, key, key_len);
3047 return ret;
3048 }
3049 #endif /* CONFIG_DRIVER_NL80211_QCA */
3050
3051 if (alg == WPA_ALG_PMK &&
3052 (drv->capa.flags & WPA_DRIVER_FLAGS_4WAY_HANDSHAKE_8021X))
3053 return nl80211_set_pmk(drv, key, key_len, addr);
3054
3055 if (alg == WPA_ALG_NONE) {
3056 msg = nl80211_ifindex_msg(drv, ifindex, 0, NL80211_CMD_DEL_KEY);
3057 if (!msg)
3058 return -ENOBUFS;
3059 } else {
3060 u32 suite;
3061
3062 suite = wpa_alg_to_cipher_suite(alg, key_len);
3063 if (!suite)
3064 goto fail;
3065 msg = nl80211_ifindex_msg(drv, ifindex, 0, NL80211_CMD_NEW_KEY);
3066 if (!msg ||
3067 nla_put(msg, NL80211_ATTR_KEY_DATA, key_len, key) ||
3068 nla_put_u32(msg, NL80211_ATTR_KEY_CIPHER, suite))
3069 goto fail;
3070 wpa_hexdump_key(MSG_DEBUG, "nl80211: KEY_DATA", key, key_len);
3071 }
3072
3073 if (seq && seq_len) {
3074 if (nla_put(msg, NL80211_ATTR_KEY_SEQ, seq_len, seq))
3075 goto fail;
3076 wpa_hexdump(MSG_DEBUG, "nl80211: KEY_SEQ", seq, seq_len);
3077 }
3078
3079 if (addr && !is_broadcast_ether_addr(addr)) {
3080 wpa_printf(MSG_DEBUG, " addr=" MACSTR, MAC2STR(addr));
3081 if (nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr))
3082 goto fail;
3083
3084 if (alg != WPA_ALG_WEP && key_idx && !set_tx) {
3085 wpa_printf(MSG_DEBUG, " RSN IBSS RX GTK");
3086 if (nla_put_u32(msg, NL80211_ATTR_KEY_TYPE,
3087 NL80211_KEYTYPE_GROUP))
3088 goto fail;
3089 }
3090 } else if (addr && is_broadcast_ether_addr(addr)) {
3091 struct nlattr *types;
3092
3093 wpa_printf(MSG_DEBUG, " broadcast key");
3094
3095 types = nla_nest_start(msg, NL80211_ATTR_KEY_DEFAULT_TYPES);
3096 if (!types ||
3097 nla_put_flag(msg, NL80211_KEY_DEFAULT_TYPE_MULTICAST))
3098 goto fail;
3099 nla_nest_end(msg, types);
3100 }
3101 if (nla_put_u8(msg, NL80211_ATTR_KEY_IDX, key_idx))
3102 goto fail;
3103
3104 ret = send_and_recv_msgs(drv, msg, NULL, key ? (void *) -1 : NULL);
3105 if ((ret == -ENOENT || ret == -ENOLINK) && alg == WPA_ALG_NONE)
3106 ret = 0;
3107 if (ret)
3108 wpa_printf(MSG_DEBUG, "nl80211: set_key failed; err=%d %s)",
3109 ret, strerror(-ret));
3110
3111 /*
3112 * If we failed or don't need to set the default TX key (below),
3113 * we're done here.
3114 */
3115 if (ret || !set_tx || alg == WPA_ALG_NONE || tdls)
3116 return ret;
3117 if (is_ap_interface(drv->nlmode) && addr &&
3118 !is_broadcast_ether_addr(addr))
3119 return ret;
3120
3121 msg = nl80211_ifindex_msg(drv, ifindex, 0, NL80211_CMD_SET_KEY);
3122 if (!msg ||
3123 nla_put_u8(msg, NL80211_ATTR_KEY_IDX, key_idx) ||
3124 nla_put_flag(msg, (alg == WPA_ALG_IGTK ||
3125 alg == WPA_ALG_BIP_GMAC_128 ||
3126 alg == WPA_ALG_BIP_GMAC_256 ||
3127 alg == WPA_ALG_BIP_CMAC_256) ?
3128 NL80211_ATTR_KEY_DEFAULT_MGMT :
3129 NL80211_ATTR_KEY_DEFAULT))
3130 goto fail;
3131 if (addr && is_broadcast_ether_addr(addr)) {
3132 struct nlattr *types;
3133
3134 types = nla_nest_start(msg, NL80211_ATTR_KEY_DEFAULT_TYPES);
3135 if (!types ||
3136 nla_put_flag(msg, NL80211_KEY_DEFAULT_TYPE_MULTICAST))
3137 goto fail;
3138 nla_nest_end(msg, types);
3139 } else if (addr) {
3140 struct nlattr *types;
3141
3142 types = nla_nest_start(msg, NL80211_ATTR_KEY_DEFAULT_TYPES);
3143 if (!types ||
3144 nla_put_flag(msg, NL80211_KEY_DEFAULT_TYPE_UNICAST))
3145 goto fail;
3146 nla_nest_end(msg, types);
3147 }
3148
3149 ret = send_and_recv_msgs(drv, msg, NULL, NULL);
3150 if (ret == -ENOENT)
3151 ret = 0;
3152 if (ret)
3153 wpa_printf(MSG_DEBUG, "nl80211: set_key default failed; "
3154 "err=%d %s)", ret, strerror(-ret));
3155 return ret;
3156
3157 fail:
3158 nl80211_nlmsg_clear(msg);
3159 nlmsg_free(msg);
3160 return -ENOBUFS;
3161 }
3162
3163
3164 static int nl_add_key(struct nl_msg *msg, enum wpa_alg alg,
3165 int key_idx, int defkey,
3166 const u8 *seq, size_t seq_len,
3167 const u8 *key, size_t key_len)
3168 {
3169 struct nlattr *key_attr = nla_nest_start(msg, NL80211_ATTR_KEY);
3170 u32 suite;
3171
3172 if (!key_attr)
3173 return -1;
3174
3175 suite = wpa_alg_to_cipher_suite(alg, key_len);
3176 if (!suite)
3177 return -1;
3178
3179 if (defkey && alg == WPA_ALG_IGTK) {
3180 if (nla_put_flag(msg, NL80211_KEY_DEFAULT_MGMT))
3181 return -1;
3182 } else if (defkey) {
3183 if (nla_put_flag(msg, NL80211_KEY_DEFAULT))
3184 return -1;
3185 }
3186
3187 if (nla_put_u8(msg, NL80211_KEY_IDX, key_idx) ||
3188 nla_put_u32(msg, NL80211_KEY_CIPHER, suite) ||
3189 (seq && seq_len &&
3190 nla_put(msg, NL80211_KEY_SEQ, seq_len, seq)) ||
3191 nla_put(msg, NL80211_KEY_DATA, key_len, key))
3192 return -1;
3193
3194 nla_nest_end(msg, key_attr);
3195
3196 return 0;
3197 }
3198
3199
3200 static int nl80211_set_conn_keys(struct wpa_driver_associate_params *params,
3201 struct nl_msg *msg)
3202 {
3203 int i, privacy = 0;
3204 struct nlattr *nl_keys, *nl_key;
3205
3206 for (i = 0; i < 4; i++) {
3207 if (!params->wep_key[i])
3208 continue;
3209 privacy = 1;
3210 break;
3211 }
3212 if (params->wps == WPS_MODE_PRIVACY)
3213 privacy = 1;
3214 if (params->pairwise_suite &&
3215 params->pairwise_suite != WPA_CIPHER_NONE)
3216 privacy = 1;
3217
3218 if (!privacy)
3219 return 0;
3220
3221 if (nla_put_flag(msg, NL80211_ATTR_PRIVACY))
3222 return -ENOBUFS;
3223
3224 nl_keys = nla_nest_start(msg, NL80211_ATTR_KEYS);
3225 if (!nl_keys)
3226 return -ENOBUFS;
3227
3228 for (i = 0; i < 4; i++) {
3229 if (!params->wep_key[i])
3230 continue;
3231
3232 nl_key = nla_nest_start(msg, i);
3233 if (!nl_key ||
3234 nla_put(msg, NL80211_KEY_DATA, params->wep_key_len[i],
3235 params->wep_key[i]) ||
3236 nla_put_u32(msg, NL80211_KEY_CIPHER,
3237 params->wep_key_len[i] == 5 ?
3238 RSN_CIPHER_SUITE_WEP40 :
3239 RSN_CIPHER_SUITE_WEP104) ||
3240 nla_put_u8(msg, NL80211_KEY_IDX, i) ||
3241 (i == params->wep_tx_keyidx &&
3242 nla_put_flag(msg, NL80211_KEY_DEFAULT)))
3243 return -ENOBUFS;
3244
3245 nla_nest_end(msg, nl_key);
3246 }
3247 nla_nest_end(msg, nl_keys);
3248
3249 return 0;
3250 }
3251
3252
3253 int wpa_driver_nl80211_mlme(struct wpa_driver_nl80211_data *drv,
3254 const u8 *addr, int cmd, u16 reason_code,
3255 int local_state_change,
3256 struct nl_handle *nl_connect)
3257 {
3258 int ret;
3259 struct nl_msg *msg;
3260
3261 if (!(msg = nl80211_drv_msg(drv, 0, cmd)) ||
3262 nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason_code) ||
3263 (addr && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) ||
3264 (local_state_change &&
3265 nla_put_flag(msg, NL80211_ATTR_LOCAL_STATE_CHANGE))) {
3266 nlmsg_free(msg);
3267 return -1;
3268 }
3269
3270 if (nl_connect)
3271 ret = send_and_recv(drv->global, nl_connect, msg, NULL, NULL);
3272 else
3273 ret = send_and_recv_msgs(drv, msg, NULL, NULL);
3274 if (ret) {
3275 wpa_dbg(drv->ctx, MSG_DEBUG,
3276 "nl80211: MLME command failed: reason=%u ret=%d (%s)",
3277 reason_code, ret, strerror(-ret));
3278 }
3279 return ret;
3280 }
3281
3282
3283 static int wpa_driver_nl80211_disconnect(struct wpa_driver_nl80211_data *drv,
3284 int reason_code,
3285 struct nl_handle *nl_connect)
3286 {
3287 int ret;
3288 int drv_associated = drv->associated;
3289
3290 wpa_printf(MSG_DEBUG, "%s(reason_code=%d)", __func__, reason_code);
3291 nl80211_mark_disconnected(drv);
3292 /* Disconnect command doesn't need BSSID - it uses cached value */
3293 ret = wpa_driver_nl80211_mlme(drv, NULL, NL80211_CMD_DISCONNECT,
3294 reason_code, 0, nl_connect);
3295 /*
3296 * For locally generated disconnect, supplicant already generates a
3297 * DEAUTH event, so ignore the event from NL80211.
3298 */
3299 drv->ignore_next_local_disconnect = drv_associated && (ret == 0);
3300
3301 return ret;
3302 }
3303
3304
3305 static int wpa_driver_nl80211_deauthenticate(struct i802_bss *bss,
3306 const u8 *addr, int reason_code)
3307 {
3308 struct wpa_driver_nl80211_data *drv = bss->drv;
3309 int ret;
3310 int drv_associated = drv->associated;
3311
3312 if (drv->nlmode == NL80211_IFTYPE_ADHOC) {
3313 nl80211_mark_disconnected(drv);
3314 return nl80211_leave_ibss(drv, 1);
3315 }
3316 if (!(drv->capa.flags & WPA_DRIVER_FLAGS_SME)) {
3317 struct nl_handle *nl_connect = NULL;
3318
3319 if (bss->use_nl_connect)
3320 nl_connect = bss->nl_connect;
3321 return wpa_driver_nl80211_disconnect(drv, reason_code,
3322 nl_connect);
3323 }
3324 wpa_printf(MSG_DEBUG, "%s(addr=" MACSTR " reason_code=%d)",
3325 __func__, MAC2STR(addr), reason_code);
3326 nl80211_mark_disconnected(drv);
3327 ret = wpa_driver_nl80211_mlme(drv, addr, NL80211_CMD_DEAUTHENTICATE,
3328 reason_code, 0, NULL);
3329 /*
3330 * For locally generated deauthenticate, supplicant already generates a
3331 * DEAUTH event, so ignore the event from NL80211.
3332 */
3333 drv->ignore_next_local_deauth = drv_associated && (ret == 0);
3334
3335 return ret;
3336 }
3337
3338
3339 static void nl80211_copy_auth_params(struct wpa_driver_nl80211_data *drv,
3340 struct wpa_driver_auth_params *params)
3341 {
3342 int i;
3343
3344 drv->auth_freq = params->freq;
3345 drv->auth_alg = params->auth_alg;
3346 drv->auth_wep_tx_keyidx = params->wep_tx_keyidx;
3347 drv->auth_local_state_change = params->local_state_change;
3348 drv->auth_p2p = params->p2p;
3349
3350 if (params->bssid)
3351 os_memcpy(drv->auth_bssid_, params->bssid, ETH_ALEN);
3352 else
3353 os_memset(drv->auth_bssid_, 0, ETH_ALEN);
3354
3355 if (params->ssid) {
3356 os_memcpy(drv->auth_ssid, params->ssid, params->ssid_len);
3357 drv->auth_ssid_len = params->ssid_len;
3358 } else
3359 drv->auth_ssid_len = 0;
3360
3361
3362 os_free(drv->auth_ie);
3363 drv->auth_ie = NULL;
3364 drv->auth_ie_len = 0;
3365 if (params->ie) {
3366 drv->auth_ie = os_malloc(params->ie_len);
3367 if (drv->auth_ie) {
3368 os_memcpy(drv->auth_ie, params->ie, params->ie_len);
3369 drv->auth_ie_len = params->ie_len;
3370 }
3371 }
3372
3373 for (i = 0; i < 4; i++) {
3374 if (params->wep_key[i] && params->wep_key_len[i] &&
3375 params->wep_key_len[i] <= 16) {
3376 os_memcpy(drv->auth_wep_key[i], params->wep_key[i],
3377 params->wep_key_len[i]);
3378 drv->auth_wep_key_len[i] = params->wep_key_len[i];
3379 } else
3380 drv->auth_wep_key_len[i] = 0;
3381 }
3382 }
3383
3384
3385 static void nl80211_unmask_11b_rates(struct i802_bss *bss)
3386 {
3387 struct wpa_driver_nl80211_data *drv = bss->drv;
3388
3389 if (is_p2p_net_interface(drv->nlmode) || !drv->disabled_11b_rates)
3390 return;
3391
3392 /*
3393 * Looks like we failed to unmask 11b rates previously. This could
3394 * happen, e.g., if the interface was down at the point in time when a
3395 * P2P group was terminated.
3396 */
3397 wpa_printf(MSG_DEBUG,
3398 "nl80211: Interface %s mode is for non-P2P, but 11b rates were disabled - re-enable them",
3399 bss->ifname);
3400 nl80211_disable_11b_rates(drv, drv->ifindex, 0);
3401 }
3402
3403
3404 static enum nl80211_auth_type get_nl_auth_type(int wpa_auth_alg)
3405 {
3406 if (wpa_auth_alg & WPA_AUTH_ALG_OPEN)
3407 return NL80211_AUTHTYPE_OPEN_SYSTEM;
3408 if (wpa_auth_alg & WPA_AUTH_ALG_SHARED)
3409 return NL80211_AUTHTYPE_SHARED_KEY;
3410 if (wpa_auth_alg & WPA_AUTH_ALG_LEAP)
3411 return NL80211_AUTHTYPE_NETWORK_EAP;
3412 if (wpa_auth_alg & WPA_AUTH_ALG_FT)
3413 return NL80211_AUTHTYPE_FT;
3414 if (wpa_auth_alg & WPA_AUTH_ALG_SAE)
3415 return NL80211_AUTHTYPE_SAE;
3416 if (wpa_auth_alg & WPA_AUTH_ALG_FILS)
3417 return NL80211_AUTHTYPE_FILS_SK;
3418 if (wpa_auth_alg & WPA_AUTH_ALG_FILS_SK_PFS)
3419 return NL80211_AUTHTYPE_FILS_SK_PFS;
3420
3421 return NL80211_AUTHTYPE_MAX;
3422 }
3423
3424
3425 static int wpa_driver_nl80211_authenticate(
3426 struct i802_bss *bss, struct wpa_driver_auth_params *params)
3427 {
3428 struct wpa_driver_nl80211_data *drv = bss->drv;
3429 int ret = -1, i;
3430 struct nl_msg *msg;
3431 enum nl80211_auth_type type;
3432 enum nl80211_iftype nlmode;
3433 int count = 0;
3434 int is_retry;
3435
3436 nl80211_unmask_11b_rates(bss);
3437
3438 is_retry = drv->retry_auth;
3439 drv->retry_auth = 0;
3440 drv->ignore_deauth_event = 0;
3441
3442 nl80211_mark_disconnected(drv);
3443 os_memset(drv->auth_bssid, 0, ETH_ALEN);
3444 if (params->bssid)
3445 os_memcpy(drv->auth_attempt_bssid, params->bssid, ETH_ALEN);
3446 else
3447 os_memset(drv->auth_attempt_bssid, 0, ETH_ALEN);
3448 /* FIX: IBSS mode */
3449 nlmode = params->p2p ?
3450 NL80211_IFTYPE_P2P_CLIENT : NL80211_IFTYPE_STATION;
3451 if (drv->nlmode != nlmode &&
3452 wpa_driver_nl80211_set_mode(bss, nlmode) < 0)
3453 return -1;
3454
3455 retry:
3456 wpa_printf(MSG_DEBUG, "nl80211: Authenticate (ifindex=%d)",
3457 drv->ifindex);
3458
3459 msg = nl80211_drv_msg(drv, 0, NL80211_CMD_AUTHENTICATE);
3460 if (!msg)
3461 goto fail;
3462
3463 for (i = 0; i < 4; i++) {
3464 if (!params->wep_key[i])
3465 continue;
3466 wpa_driver_nl80211_set_key(bss->ifname, bss, WPA_ALG_WEP,
3467 NULL, i,
3468 i == params->wep_tx_keyidx, NULL, 0,
3469 params->wep_key[i],
3470 params->wep_key_len[i]);
3471 if (params->wep_tx_keyidx != i)
3472 continue;
3473 if (nl_add_key(msg, WPA_ALG_WEP, i, 1, NULL, 0,
3474 params->wep_key[i], params->wep_key_len[i]))
3475 goto fail;
3476 }
3477
3478 if (params->bssid) {
3479 wpa_printf(MSG_DEBUG, " * bssid=" MACSTR,
3480 MAC2STR(params->bssid));
3481 if (nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, params->bssid))
3482 goto fail;
3483 }
3484 if (params->freq) {
3485 wpa_printf(MSG_DEBUG, " * freq=%d", params->freq);
3486 if (nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, params->freq))
3487 goto fail;
3488 }
3489 if (params->ssid) {
3490 wpa_printf(MSG_DEBUG, " * SSID=%s",
3491 wpa_ssid_txt(params->ssid, params->ssid_len));
3492 if (nla_put(msg, NL80211_ATTR_SSID, params->ssid_len,
3493 params->ssid))
3494 goto fail;
3495 }
3496 wpa_hexdump(MSG_DEBUG, " * IEs", params->ie, params->ie_len);
3497 if (params->ie &&
3498 nla_put(msg, NL80211_ATTR_IE, params->ie_len, params->ie))
3499 goto fail;
3500 if (params->auth_data) {
3501 wpa_hexdump(MSG_DEBUG, " * auth_data", params->auth_data,
3502 params->auth_data_len);
3503 if (nla_put(msg, NL80211_ATTR_SAE_DATA, params->auth_data_len,
3504 params->auth_data))
3505 goto fail;
3506 }
3507 type = get_nl_auth_type(params->auth_alg);
3508 wpa_printf(MSG_DEBUG, " * Auth Type %d", type);
3509 if (type == NL80211_AUTHTYPE_MAX ||
3510 nla_put_u32(msg, NL80211_ATTR_AUTH_TYPE, type))
3511 goto fail;
3512 if (params->local_state_change) {
3513 wpa_printf(MSG_DEBUG, " * Local state change only");
3514 if (nla_put_flag(msg, NL80211_ATTR_LOCAL_STATE_CHANGE))
3515 goto fail;
3516 }
3517
3518 ret = send_and_recv_msgs(drv, msg, NULL, NULL);
3519 msg = NULL;
3520 if (ret) {
3521 wpa_dbg(drv->ctx, MSG_DEBUG,
3522 "nl80211: MLME command failed (auth): count=%d ret=%d (%s)",
3523 count, ret, strerror(-ret));
3524 count++;
3525 if ((ret == -EALREADY || ret == -EEXIST) && count == 1 &&
3526 params->bssid && !params->local_state_change) {
3527 /*
3528 * mac80211 does not currently accept new
3529 * authentication if we are already authenticated. As a
3530 * workaround, force deauthentication and try again.
3531 */
3532 wpa_printf(MSG_DEBUG, "nl80211: Retry authentication "
3533 "after forced deauthentication");
3534 drv->ignore_deauth_event = 1;
3535 wpa_driver_nl80211_deauthenticate(
3536 bss, params->bssid,
3537 WLAN_REASON_PREV_AUTH_NOT_VALID);
3538 nlmsg_free(msg);
3539 goto retry;
3540 }
3541
3542 if (ret == -ENOENT && params->freq && !is_retry) {
3543 /*
3544 * cfg80211 has likely expired the BSS entry even
3545 * though it was previously available in our internal
3546 * BSS table. To recover quickly, start a single
3547 * channel scan on the specified channel.
3548 */
3549 struct wpa_driver_scan_params scan;
3550 int freqs[2];
3551
3552 os_memset(&scan, 0, sizeof(scan));
3553 scan.num_ssids = 1;
3554 if (params->ssid) {
3555 scan.ssids[0].ssid = params->ssid;
3556 scan.ssids[0].ssid_len = params->ssid_len;
3557 }
3558 freqs[0] = params->freq;
3559 freqs[1] = 0;
3560 scan.freqs = freqs;
3561 wpa_printf(MSG_DEBUG, "nl80211: Trigger single "
3562 "channel scan to refresh cfg80211 BSS "
3563 "entry");
3564 ret = wpa_driver_nl80211_scan(bss, &scan);
3565 if (ret == 0) {
3566 nl80211_copy_auth_params(drv, params);
3567 drv->scan_for_auth = 1;
3568 }
3569 } else if (is_retry) {
3570 /*
3571 * Need to indicate this with an event since the return
3572 * value from the retry is not delivered to core code.
3573 */
3574 union wpa_event_data event;
3575 wpa_printf(MSG_DEBUG, "nl80211: Authentication retry "
3576 "failed");
3577 os_memset(&event, 0, sizeof(event));
3578 os_memcpy(event.timeout_event.addr, drv->auth_bssid_,
3579 ETH_ALEN);
3580 wpa_supplicant_event(drv->ctx, EVENT_AUTH_TIMED_OUT,
3581 &event);
3582 }
3583 } else {
3584 wpa_printf(MSG_DEBUG,
3585 "nl80211: Authentication request send successfully");
3586 }
3587
3588 fail:
3589 nlmsg_free(msg);
3590 return ret;
3591 }
3592
3593
3594 int wpa_driver_nl80211_authenticate_retry(struct wpa_driver_nl80211_data *drv)
3595 {
3596 struct wpa_driver_auth_params params;
3597 struct i802_bss *bss = drv->first_bss;
3598 int i;
3599
3600 wpa_printf(MSG_DEBUG, "nl80211: Try to authenticate again");
3601
3602 os_memset(&params, 0, sizeof(params));
3603 params.freq = drv->auth_freq;
3604 params.auth_alg = drv->auth_alg;
3605 params.wep_tx_keyidx = drv->auth_wep_tx_keyidx;
3606 params.local_state_change = drv->auth_local_state_change;
3607 params.p2p = drv->auth_p2p;
3608
3609 if (!is_zero_ether_addr(drv->auth_bssid_))
3610 params.bssid = drv->auth_bssid_;
3611
3612 if (drv->auth_ssid_len) {
3613 params.ssid = drv->auth_ssid;
3614 params.ssid_len = drv->auth_ssid_len;
3615 }
3616
3617 params.ie = drv->auth_ie;
3618 params.ie_len = drv->auth_ie_len;
3619
3620 for (i = 0; i < 4; i++) {
3621 if (drv->auth_wep_key_len[i]) {
3622 params.wep_key[i] = drv->auth_wep_key[i];
3623 params.wep_key_len[i] = drv->auth_wep_key_len[i];
3624 }
3625 }
3626
3627 drv->retry_auth = 1;
3628 return wpa_driver_nl80211_authenticate(bss, &params);
3629 }
3630
3631
3632 static int wpa_driver_nl80211_send_frame(struct i802_bss *bss,
3633 const void *data, size_t len,
3634 int encrypt, int noack,
3635 unsigned int freq, int no_cck,
3636 int offchanok, unsigned int wait_time,
3637 const u16 *csa_offs,
3638 size_t csa_offs_len)
3639 {
3640 struct wpa_driver_nl80211_data *drv = bss->drv;
3641 u64 cookie;
3642 int res;
3643
3644 if (freq == 0 && drv->nlmode == NL80211_IFTYPE_ADHOC) {
3645 freq = nl80211_get_assoc_freq(drv);
3646 wpa_printf(MSG_DEBUG,
3647 "nl80211: send_frame - Use assoc_freq=%u for IBSS",
3648 freq);
3649 }
3650 if (freq == 0) {
3651 wpa_printf(MSG_DEBUG, "nl80211: send_frame - Use bss->freq=%u",
3652 bss->freq);
3653 freq = bss->freq;
3654 }
3655
3656 if (drv->use_monitor) {
3657 wpa_printf(MSG_DEBUG, "nl80211: send_frame(freq=%u bss->freq=%u) -> send_monitor",
3658 freq, bss->freq);
3659 return nl80211_send_monitor(drv, data, len, encrypt, noack);
3660 }
3661
3662 wpa_printf(MSG_DEBUG, "nl80211: send_frame -> send_frame_cmd");
3663 res = nl80211_send_frame_cmd(bss, freq, wait_time, data, len,
3664 &cookie, no_cck, noack, offchanok,
3665 csa_offs, csa_offs_len);
3666 if (res == 0 && !noack) {
3667 const struct ieee80211_mgmt *mgmt;
3668 u16 fc;
3669
3670 mgmt = (const struct ieee80211_mgmt *) data;
3671 fc = le_to_host16(mgmt->frame_control);
3672 if (WLAN_FC_GET_TYPE(fc) == WLAN_FC_TYPE_MGMT &&
3673 WLAN_FC_GET_STYPE(fc) == WLAN_FC_STYPE_ACTION) {
3674 wpa_printf(MSG_MSGDUMP,
3675 "nl80211: Update send_action_cookie from 0x%llx to 0x%llx",
3676 (long long unsigned int)
3677 drv->send_action_cookie,
3678 (long long unsigned int) cookie);
3679 drv->send_action_cookie = cookie;
3680 }
3681 }
3682
3683 return res;
3684 }
3685
3686
3687 static int wpa_driver_nl80211_send_mlme(struct i802_bss *bss, const u8 *data,
3688 size_t data_len, int noack,
3689 unsigned int freq, int no_cck,
3690 int offchanok,
3691 unsigned int wait_time,
3692 const u16 *csa_offs,
3693 size_t csa_offs_len)
3694 {
3695 struct wpa_driver_nl80211_data *drv = bss->drv;
3696 struct ieee80211_mgmt *mgmt;
3697 int encrypt = 1;
3698 u16 fc;
3699
3700 mgmt = (struct ieee80211_mgmt *) data;
3701 fc = le_to_host16(mgmt->frame_control);
3702 wpa_printf(MSG_DEBUG, "nl80211: send_mlme - da= " MACSTR
3703 " noack=%d freq=%u no_cck=%d offchanok=%d wait_time=%u fc=0x%x (%s) nlmode=%d",
3704 MAC2STR(mgmt->da), noack, freq, no_cck, offchanok, wait_time,
3705 fc, fc2str(fc), drv->nlmode);
3706
3707 if ((is_sta_interface(drv->nlmode) ||
3708 drv->nlmode == NL80211_IFTYPE_P2P_DEVICE) &&
3709 WLAN_FC_GET_TYPE(fc) == WLAN_FC_TYPE_MGMT &&
3710 WLAN_FC_GET_STYPE(fc) == WLAN_FC_STYPE_PROBE_RESP) {
3711 /*
3712 * The use of last_mgmt_freq is a bit of a hack,
3713 * but it works due to the single-threaded nature
3714 * of wpa_supplicant.
3715 */
3716 if (freq == 0) {
3717 wpa_printf(MSG_DEBUG, "nl80211: Use last_mgmt_freq=%d",
3718 drv->last_mgmt_freq);
3719 freq = drv->last_mgmt_freq;
3720 }
3721 return nl80211_send_frame_cmd(bss, freq, 0,
3722 data, data_len, NULL, 1, noack,
3723 1, csa_offs, csa_offs_len);
3724 }
3725
3726 if (drv->device_ap_sme && is_ap_interface(drv->nlmode)) {
3727 if (freq == 0) {
3728 wpa_printf(MSG_DEBUG, "nl80211: Use bss->freq=%d",
3729 bss->freq);
3730 freq = bss->freq;
3731 }
3732 return nl80211_send_frame_cmd(bss, freq,
3733 (int) freq == bss->freq ? 0 :
3734 wait_time,
3735 data, data_len,
3736 &drv->send_action_cookie,
3737 no_cck, noack, offchanok,
3738 csa_offs, csa_offs_len);
3739 }
3740
3741 if (WLAN_FC_GET_TYPE(fc) == WLAN_FC_TYPE_MGMT &&
3742 WLAN_FC_GET_STYPE(fc) == WLAN_FC_STYPE_AUTH) {
3743 /*
3744 * Only one of the authentication frame types is encrypted.
3745 * In order for static WEP encryption to work properly (i.e.,
3746 * to not encrypt the frame), we need to tell mac80211 about
3747 * the frames that must not be encrypted.
3748 */
3749 u16 auth_alg = le_to_host16(mgmt->u.auth.auth_alg);
3750 u16 auth_trans = le_to_host16(mgmt->u.auth.auth_transaction);
3751 if (auth_alg != WLAN_AUTH_SHARED_KEY || auth_trans != 3)
3752 encrypt = 0;
3753 }
3754
3755 wpa_printf(MSG_DEBUG, "nl80211: send_mlme -> send_frame");
3756 return wpa_driver_nl80211_send_frame(bss, data, data_len, encrypt,
3757 noack, freq, no_cck, offchanok,
3758 wait_time, csa_offs,
3759 csa_offs_len);
3760 }
3761
3762
3763 static int nl80211_put_basic_rates(struct nl_msg *msg, const int *basic_rates)
3764 {
3765 u8 rates[NL80211_MAX_SUPP_RATES];
3766 u8 rates_len = 0;
3767 int i;
3768
3769 if (!basic_rates)
3770 return 0;
3771
3772 for (i = 0; i < NL80211_MAX_SUPP_RATES && basic_rates[i] >= 0; i++)
3773 rates[rates_len++] = basic_rates[i] / 5;
3774
3775 return nla_put(msg, NL80211_ATTR_BSS_BASIC_RATES, rates_len, rates);
3776 }
3777
3778
3779 static int nl80211_set_bss(struct i802_bss *bss, int cts, int preamble,
3780 int slot, int ht_opmode, int ap_isolate,
3781 const int *basic_rates)
3782 {
3783 struct wpa_driver_nl80211_data *drv = bss->drv;
3784 struct nl_msg *msg;
3785
3786 if (!(msg = nl80211_bss_msg(bss, 0, NL80211_CMD_SET_BSS)) ||
3787 (cts >= 0 &&
3788 nla_put_u8(msg, NL80211_ATTR_BSS_CTS_PROT, cts)) ||
3789 (preamble >= 0 &&
3790 nla_put_u8(msg, NL80211_ATTR_BSS_SHORT_PREAMBLE, preamble)) ||
3791 (slot >= 0 &&
3792 nla_put_u8(msg, NL80211_ATTR_BSS_SHORT_SLOT_TIME, slot)) ||
3793 (ht_opmode >= 0 &&
3794 nla_put_u16(msg, NL80211_ATTR_BSS_HT_OPMODE, ht_opmode)) ||
3795 (ap_isolate >= 0 &&
3796 nla_put_u8(msg, NL80211_ATTR_AP_ISOLATE, ap_isolate)) ||
3797 nl80211_put_basic_rates(msg, basic_rates)) {
3798 nlmsg_free(msg);
3799 return -ENOBUFS;
3800 }
3801
3802 return send_and_recv_msgs(drv, msg, NULL, NULL);
3803 }
3804
3805
3806 static int wpa_driver_nl80211_set_acl(void *priv,
3807 struct hostapd_acl_params *params)
3808 {
3809 struct i802_bss *bss = priv;
3810 struct wpa_driver_nl80211_data *drv = bss->drv;
3811 struct nl_msg *msg;
3812 struct nl_msg *acl;
3813 unsigned int i;
3814 int ret;
3815
3816 if (!(drv->capa.max_acl_mac_addrs))
3817 return -ENOTSUP;
3818
3819 if (params->num_mac_acl > drv->capa.max_acl_mac_addrs)
3820 return -ENOTSUP;
3821
3822 wpa_printf(MSG_DEBUG, "nl80211: Set %s ACL (num_mac_acl=%u)",
3823 params->acl_policy ? "Accept" : "Deny", params->num_mac_acl);
3824
3825 acl = nlmsg_alloc();
3826 if (!acl)
3827 return -ENOMEM;
3828 for (i = 0; i < params->num_mac_acl; i++) {
3829 if (nla_put(acl, i + 1, ETH_ALEN, params->mac_acl[i].addr)) {
3830 nlmsg_free(acl);
3831 return -ENOMEM;
3832 }
3833 }
3834
3835 if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_SET_MAC_ACL)) ||
3836 nla_put_u32(msg, NL80211_ATTR_ACL_POLICY, params->acl_policy ?
3837 NL80211_ACL_POLICY_DENY_UNLESS_LISTED :
3838 NL80211_ACL_POLICY_ACCEPT_UNLESS_LISTED) ||
3839 nla_put_nested(msg, NL80211_ATTR_MAC_ADDRS, acl)) {
3840 nlmsg_free(msg);
3841 nlmsg_free(acl);
3842 return -ENOMEM;
3843 }
3844 nlmsg_free(acl);
3845
3846 ret = send_and_recv_msgs(drv, msg, NULL, NULL);
3847 if (ret) {
3848 wpa_printf(MSG_DEBUG, "nl80211: Failed to set MAC ACL: %d (%s)",
3849 ret, strerror(-ret));
3850 }
3851
3852 return ret;
3853 }
3854
3855
3856 static int nl80211_put_beacon_int(struct nl_msg *msg, int beacon_int)
3857 {
3858 if (beacon_int > 0) {
3859 wpa_printf(MSG_DEBUG, " * beacon_int=%d", beacon_int);
3860 return nla_put_u32(msg, NL80211_ATTR_BEACON_INTERVAL,
3861 beacon_int);
3862 }
3863
3864 return 0;
3865 }
3866
3867
3868 static int nl80211_put_dtim_period(struct nl_msg *msg, int dtim_period)
3869 {
3870 if (dtim_period > 0) {
3871 wpa_printf(MSG_DEBUG, " * dtim_period=%d", dtim_period);
3872 return nla_put_u32(msg, NL80211_ATTR_DTIM_PERIOD, dtim_period);
3873 }
3874
3875 return 0;
3876 }
3877
3878
3879 #ifdef CONFIG_MESH
3880 static int nl80211_set_mesh_config(void *priv,
3881 struct wpa_driver_mesh_bss_params *params)
3882 {
3883 struct i802_bss *bss = priv;
3884 struct wpa_driver_nl80211_data *drv = bss->drv;
3885 struct nl_msg *msg;
3886 int ret;
3887
3888 msg = nl80211_drv_msg(drv, 0, NL80211_CMD_SET_MESH_CONFIG);
3889 if (!msg)
3890 return -1;
3891
3892 ret = nl80211_put_mesh_config(msg, params);
3893 if (ret < 0) {
3894 nlmsg_free(msg);
3895 return ret;
3896 }
3897
3898 ret = send_and_recv_msgs(drv, msg, NULL, NULL);
3899 if (ret) {
3900 wpa_printf(MSG_ERROR,
3901 "nl80211: Mesh config set failed: %d (%s)",
3902 ret, strerror(-ret));
3903 return ret;
3904 }
3905 return 0;
3906 }
3907 #endif /* CONFIG_MESH */
3908
3909
3910 static int nl80211_put_beacon_rate(struct nl_msg *msg, const u64 flags,
3911 struct wpa_driver_ap_params *params)
3912 {
3913 struct nlattr *bands, *band;
3914 struct nl80211_txrate_vht vht_rate;
3915
3916 if (!params->freq ||
3917 (params->beacon_rate == 0 &&
3918 params->rate_type == BEACON_RATE_LEGACY))
3919 return 0;
3920
3921 bands = nla_nest_start(msg, NL80211_ATTR_TX_RATES);
3922 if (!bands)
3923 return -1;
3924
3925 switch (params->freq->mode) {
3926 case HOSTAPD_MODE_IEEE80211B:
3927 case HOSTAPD_MODE_IEEE80211G:
3928 band = nla_nest_start(msg, NL80211_BAND_2GHZ);
3929 break;
3930 case HOSTAPD_MODE_IEEE80211A:
3931 band = nla_nest_start(msg, NL80211_BAND_5GHZ);
3932 break;
3933 case HOSTAPD_MODE_IEEE80211AD:
3934 band = nla_nest_start(msg, NL80211_BAND_60GHZ);
3935 break;
3936 default:
3937 return 0;
3938 }
3939
3940 if (!band)
3941 return -1;
3942
3943 os_memset(&vht_rate, 0, sizeof(vht_rate));
3944
3945 switch (params->rate_type) {
3946 case BEACON_RATE_LEGACY:
3947 if (!(flags & WPA_DRIVER_FLAGS_BEACON_RATE_LEGACY)) {
3948 wpa_printf(MSG_INFO,
3949 "nl80211: Driver does not support setting Beacon frame rate (legacy)");
3950 return -1;
3951 }
3952
3953 if (nla_put_u8(msg, NL80211_TXRATE_LEGACY,
3954 (u8) params->beacon_rate / 5) ||
3955 nla_put(msg, NL80211_TXRATE_HT, 0, NULL) ||
3956 (params->freq->vht_enabled &&
3957 nla_put(msg, NL80211_TXRATE_VHT, sizeof(vht_rate),
3958 &vht_rate)))
3959 return -1;
3960
3961 wpa_printf(MSG_DEBUG, " * beacon_rate = legacy:%u (* 100 kbps)",
3962 params->beacon_rate);
3963 break;
3964 case BEACON_RATE_HT:
3965 if (!(flags & WPA_DRIVER_FLAGS_BEACON_RATE_HT)) {
3966 wpa_printf(MSG_INFO,
3967 "nl80211: Driver does not support setting Beacon frame rate (HT)");
3968 return -1;
3969 }
3970 if (nla_put(msg, NL80211_TXRATE_LEGACY, 0, NULL) ||
3971 nla_put_u8(msg, NL80211_TXRATE_HT, params->beacon_rate) ||
3972 (params->freq->vht_enabled &&
3973 nla_put(msg, NL80211_TXRATE_VHT, sizeof(vht_rate),
3974 &vht_rate)))
3975 return -1;
3976 wpa_printf(MSG_DEBUG, " * beacon_rate = HT-MCS %u",
3977 params->beacon_rate);
3978 break;
3979 case BEACON_RATE_VHT:
3980 if (!(flags & WPA_DRIVER_FLAGS_BEACON_RATE_VHT)) {
3981 wpa_printf(MSG_INFO,
3982 "nl80211: Driver does not support setting Beacon frame rate (VHT)");
3983 return -1;
3984 }
3985 vht_rate.mcs[0] = BIT(params->beacon_rate);
3986 if (nla_put(msg, NL80211_TXRATE_LEGACY, 0, NULL))
3987 return -1;
3988 if (nla_put(msg, NL80211_TXRATE_HT, 0, NULL))
3989 return -1;
3990 if (nla_put(msg, NL80211_TXRATE_VHT, sizeof(vht_rate),
3991 &vht_rate))
3992 return -1;
3993 wpa_printf(MSG_DEBUG, " * beacon_rate = VHT-MCS %u",
3994 params->beacon_rate);
3995 break;
3996 }
3997
3998 nla_nest_end(msg, band);
3999 nla_nest_end(msg, bands);
4000
4001 return 0;
4002 }
4003
4004
4005 static int nl80211_set_multicast_to_unicast(struct i802_bss *bss,
4006 int multicast_to_unicast)
4007 {
4008 struct wpa_driver_nl80211_data *drv = bss->drv;
4009 struct nl_msg *msg;
4010 int ret;
4011
4012 msg = nl80211_bss_msg(bss, 0, NL80211_CMD_SET_MULTICAST_TO_UNICAST);
4013 if (!msg ||
4014 (multicast_to_unicast &&
4015 nla_put_flag(msg, NL80211_ATTR_MULTICAST_TO_UNICAST_ENABLED))) {
4016 wpa_printf(MSG_ERROR,
4017 "nl80211: Failed to build NL80211_CMD_SET_MULTICAST_TO_UNICAST msg for %s",
4018 bss->ifname);
4019 nlmsg_free(msg);
4020 return -ENOBUFS;
4021 }
4022
4023 ret = send_and_recv_msgs(drv, msg, NULL, NULL);
4024
4025 switch (ret) {
4026 case 0:
4027 wpa_printf(MSG_DEBUG,
4028 "nl80211: multicast to unicast %s on interface %s",
4029 multicast_to_unicast ? "enabled" : "disabled",
4030 bss->ifname);
4031 break;
4032 case -EOPNOTSUPP:
4033 if (!multicast_to_unicast)
4034 break;
4035 wpa_printf(MSG_INFO,
4036 "nl80211: multicast to unicast not supported on interface %s",
4037 bss->ifname);
4038 break;
4039 default:
4040 wpa_printf(MSG_ERROR,
4041 "nl80211: %s multicast to unicast failed with %d (%s) on interface %s",
4042 multicast_to_unicast ? "enabling" : "disabling",
4043 ret, strerror(-ret), bss->ifname);
4044 break;
4045 }
4046
4047 return ret;
4048 }
4049
4050
4051 static int wpa_driver_nl80211_set_ap(void *priv,
4052 struct wpa_driver_ap_params *params)
4053 {
4054 struct i802_bss *bss = priv;
4055 struct wpa_driver_nl80211_data *drv = bss->drv;
4056 struct nl_msg *msg;
4057 u8 cmd = NL80211_CMD_NEW_BEACON;
4058 int ret = -ENOBUFS;
4059 int beacon_set;
4060 int num_suites;
4061 int smps_mode;
4062 u32 suites[10], suite;
4063 u32 ver;
4064 #ifdef CONFIG_MESH
4065 struct wpa_driver_mesh_bss_params mesh_params;
4066 #endif /* CONFIG_MESH */
4067
4068 beacon_set = params->reenable ? 0 : bss->beacon_set;
4069
4070 wpa_printf(MSG_DEBUG, "nl80211: Set beacon (beacon_set=%d)",
4071 beacon_set);
4072 if (beacon_set)
4073 cmd = NL80211_CMD_SET_BEACON;
4074 else if (!drv->device_ap_sme && !drv->use_monitor &&
4075 !nl80211_get_wiphy_data_ap(bss))
4076 return -ENOBUFS;
4077
4078 wpa_hexdump(MSG_DEBUG, "nl80211: Beacon head",
4079 params->head, params->head_len);
4080 wpa_hexdump(MSG_DEBUG, "nl80211: Beacon tail",
4081 params->tail, params->tail_len);
4082 wpa_printf(MSG_DEBUG, "nl80211: ifindex=%d", bss->ifindex);
4083 wpa_printf(MSG_DEBUG, "nl80211: beacon_int=%d", params->beacon_int);
4084 wpa_printf(MSG_DEBUG, "nl80211: beacon_rate=%u", params->beacon_rate);
4085 wpa_printf(MSG_DEBUG, "nl80211: rate_type=%d", params->rate_type);
4086 wpa_printf(MSG_DEBUG, "nl80211: dtim_period=%d", params->dtim_period);
4087 wpa_printf(MSG_DEBUG, "nl80211: ssid=%s",
4088 wpa_ssid_txt(params->ssid, params->ssid_len));
4089 if (!(msg = nl80211_bss_msg(bss, 0, cmd)) ||
4090 nla_put(msg, NL80211_ATTR_BEACON_HEAD, params->head_len,
4091 params->head) ||
4092 nla_put(msg, NL80211_ATTR_BEACON_TAIL, params->tail_len,
4093 params->tail) ||
4094 nl80211_put_beacon_int(msg, params->beacon_int) ||
4095 nl80211_put_beacon_rate(msg, drv->capa.flags, params) ||
4096 nl80211_put_dtim_period(msg, params->dtim_period) ||
4097 nla_put(msg, NL80211_ATTR_SSID, params->ssid_len, params->ssid))
4098 goto fail;
4099 if (params->proberesp && params->proberesp_len) {
4100 wpa_hexdump(MSG_DEBUG, "nl80211: proberesp (offload)",
4101 params->proberesp, params->proberesp_len);
4102 if (nla_put(msg, NL80211_ATTR_PROBE_RESP, params->proberesp_len,
4103 params->proberesp))
4104 goto fail;
4105 }
4106 switch (params->hide_ssid) {
4107 case NO_SSID_HIDING:
4108 wpa_printf(MSG_DEBUG, "nl80211: hidden SSID not in use");
4109 if (nla_put_u32(msg, NL80211_ATTR_HIDDEN_SSID,
4110 NL80211_HIDDEN_SSID_NOT_IN_USE))
4111 goto fail;
4112 break;
4113 case HIDDEN_SSID_ZERO_LEN:
4114 wpa_printf(MSG_DEBUG, "nl80211: hidden SSID zero len");
4115 if (nla_put_u32(msg, NL80211_ATTR_HIDDEN_SSID,
4116 NL80211_HIDDEN_SSID_ZERO_LEN))
4117 goto fail;
4118 break;
4119 case HIDDEN_SSID_ZERO_CONTENTS:
4120 wpa_printf(MSG_DEBUG, "nl80211: hidden SSID zero contents");
4121 if (nla_put_u32(msg, NL80211_ATTR_HIDDEN_SSID,
4122 NL80211_HIDDEN_SSID_ZERO_CONTENTS))
4123 goto fail;
4124 break;
4125 }
4126 wpa_printf(MSG_DEBUG, "nl80211: privacy=%d", params->privacy);
4127 if (params->privacy &&
4128 nla_put_flag(msg, NL80211_ATTR_PRIVACY))
4129 goto fail;
4130 wpa_printf(MSG_DEBUG, "nl80211: auth_algs=0x%x", params->auth_algs);
4131 if ((params->auth_algs & (WPA_AUTH_ALG_OPEN | WPA_AUTH_ALG_SHARED)) ==
4132 (WPA_AUTH_ALG_OPEN | WPA_AUTH_ALG_SHARED)) {
4133 /* Leave out the attribute */
4134 } else if (params->auth_algs & WPA_AUTH_ALG_SHARED) {
4135 if (nla_put_u32(msg, NL80211_ATTR_AUTH_TYPE,
4136 NL80211_AUTHTYPE_SHARED_KEY))
4137 goto fail;
4138 } else {
4139 if (nla_put_u32(msg, NL80211_ATTR_AUTH_TYPE,
4140 NL80211_AUTHTYPE_OPEN_SYSTEM))
4141 goto fail;
4142 }
4143
4144 wpa_printf(MSG_DEBUG, "nl80211: wpa_version=0x%x", params->wpa_version);
4145 ver = 0;
4146 if (params->wpa_version & WPA_PROTO_WPA)
4147 ver |= NL80211_WPA_VERSION_1;
4148 if (params->wpa_version & WPA_PROTO_RSN)
4149 ver |= NL80211_WPA_VERSION_2;
4150 if (ver &&
4151 nla_put_u32(msg, NL80211_ATTR_WPA_VERSIONS, ver))
4152 goto fail;
4153
4154 wpa_printf(MSG_DEBUG, "nl80211: key_mgmt_suites=0x%x",
4155 params->key_mgmt_suites);
4156 num_suites = 0;
4157 if (params->key_mgmt_suites & WPA_KEY_MGMT_IEEE8021X)
4158 suites[num_suites++] = RSN_AUTH_KEY_MGMT_UNSPEC_802_1X;
4159 if (params->key_mgmt_suites & WPA_KEY_MGMT_PSK)
4160 suites[num_suites++] = RSN_AUTH_KEY_MGMT_PSK_OVER_802_1X;
4161 if (num_suites &&
4162 nla_put(msg, NL80211_ATTR_AKM_SUITES, num_suites * sizeof(u32),
4163 suites))
4164 goto fail;
4165
4166 if (params->key_mgmt_suites & WPA_KEY_MGMT_IEEE8021X_NO_WPA &&
4167 (!params->pairwise_ciphers ||
4168 params->pairwise_ciphers & (WPA_CIPHER_WEP104 | WPA_CIPHER_WEP40)) &&
4169 (nla_put_u16(msg, NL80211_ATTR_CONTROL_PORT_ETHERTYPE, ETH_P_PAE) ||
4170 nla_put_flag(msg, NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT)))
4171 goto fail;
4172
4173 if (drv->device_ap_sme && (params->key_mgmt_suites & WPA_KEY_MGMT_SAE))
4174 nla_put_flag(msg, NL80211_ATTR_EXTERNAL_AUTH_SUPPORT);
4175
4176 wpa_printf(MSG_DEBUG, "nl80211: pairwise_ciphers=0x%x",
4177 params->pairwise_ciphers);
4178 num_suites = wpa_cipher_to_cipher_suites(params->pairwise_ciphers,
4179 suites, ARRAY_SIZE(suites));
4180 if (num_suites &&
4181 nla_put(msg, NL80211_ATTR_CIPHER_SUITES_PAIRWISE,
4182 num_suites * sizeof(u32), suites))
4183 goto fail;
4184
4185 wpa_printf(MSG_DEBUG, "nl80211: group_cipher=0x%x",
4186 params->group_cipher);
4187 suite = wpa_cipher_to_cipher_suite(params->group_cipher);
4188 if (suite &&
4189 nla_put_u32(msg, NL80211_ATTR_CIPHER_SUITE_GROUP, suite))
4190 goto fail;
4191
4192 if (params->ht_opmode != -1) {
4193 switch (params->smps_mode) {
4194 case HT_CAP_INFO_SMPS_DYNAMIC:
4195 wpa_printf(MSG_DEBUG, "nl80211: SMPS mode - dynamic");
4196 smps_mode = NL80211_SMPS_DYNAMIC;
4197 break;
4198 case HT_CAP_INFO_SMPS_STATIC:
4199 wpa_printf(MSG_DEBUG, "nl80211: SMPS mode - static");
4200 smps_mode = NL80211_SMPS_STATIC;
4201 break;
4202 default:
4203 /* invalid - fallback to smps off */
4204 case HT_CAP_INFO_SMPS_DISABLED:
4205 wpa_printf(MSG_DEBUG, "nl80211: SMPS mode - off");
4206 smps_mode = NL80211_SMPS_OFF;
4207 break;
4208 }
4209 if (nla_put_u8(msg, NL80211_ATTR_SMPS_MODE, smps_mode))
4210 goto fail;
4211 }
4212
4213 if (params->beacon_ies) {
4214 wpa_hexdump_buf(MSG_DEBUG, "nl80211: beacon_ies",
4215 params->beacon_ies);
4216 if (nla_put(msg, NL80211_ATTR_IE,
4217 wpabuf_len(params->beacon_ies),
4218 wpabuf_head(params->beacon_ies)))
4219 goto fail;
4220 }
4221 if (params->proberesp_ies) {
4222 wpa_hexdump_buf(MSG_DEBUG, "nl80211: proberesp_ies",
4223 params->proberesp_ies);
4224 if (nla_put(msg, NL80211_ATTR_IE_PROBE_RESP,
4225 wpabuf_len(params->proberesp_ies),
4226 wpabuf_head(params->proberesp_ies)))
4227 goto fail;
4228 }
4229 if (params->assocresp_ies) {
4230 wpa_hexdump_buf(MSG_DEBUG, "nl80211: assocresp_ies",
4231 params->assocresp_ies);
4232 if (nla_put(msg, NL80211_ATTR_IE_ASSOC_RESP,
4233 wpabuf_len(params->assocresp_ies),
4234 wpabuf_head(params->assocresp_ies)))
4235 goto fail;
4236 }
4237
4238 if (drv->capa.flags & WPA_DRIVER_FLAGS_INACTIVITY_TIMER) {
4239 wpa_printf(MSG_DEBUG, "nl80211: ap_max_inactivity=%d",
4240 params->ap_max_inactivity);
4241 if (nla_put_u16(msg, NL80211_ATTR_INACTIVITY_TIMEOUT,
4242 params->ap_max_inactivity))
4243 goto fail;
4244 }
4245
4246 #ifdef CONFIG_P2P
4247 if (params->p2p_go_ctwindow > 0) {
4248 if (drv->p2p_go_ctwindow_supported) {
4249 wpa_printf(MSG_DEBUG, "nl80211: P2P GO ctwindow=%d",
4250 params->p2p_go_ctwindow);
4251 if (nla_put_u8(msg, NL80211_ATTR_P2P_CTWINDOW,
4252 params->p2p_go_ctwindow))
4253 goto fail;
4254 } else {
4255 wpa_printf(MSG_INFO,
4256 "nl80211: Driver does not support CTWindow configuration - ignore this parameter");
4257 }
4258 }
4259 #endif /* CONFIG_P2P */
4260
4261 if (params->pbss) {
4262 wpa_printf(MSG_DEBUG, "nl80211: PBSS");
4263 if (nla_put_flag(msg, NL80211_ATTR_PBSS))
4264 goto fail;
4265 }
4266
4267 if (params->ftm_responder) {
4268 struct nlattr *ftm;
4269
4270 if (!(drv->capa.flags & WPA_DRIVER_FLAGS_FTM_RESPONDER)) {
4271 ret = -ENOTSUP;
4272 goto fail;
4273 }
4274
4275 ftm = nla_nest_start(msg, NL80211_ATTR_FTM_RESPONDER);
4276 if (!ftm ||
4277 nla_put_flag(msg, NL80211_FTM_RESP_ATTR_ENABLED) ||
4278 (params->lci &&
4279 nla_put(msg, NL80211_FTM_RESP_ATTR_LCI,
4280 wpabuf_len(params->lci),
4281 wpabuf_head(params->lci))) ||
4282 (params->civic &&
4283 nla_put(msg, NL80211_FTM_RESP_ATTR_CIVICLOC,
4284 wpabuf_len(params->civic),
4285 wpabuf_head(params->civic))))
4286 goto fail;
4287 nla_nest_end(msg, ftm);
4288 }
4289
4290 ret = send_and_recv_msgs(drv, msg, NULL, NULL);
4291 if (ret) {
4292 wpa_printf(MSG_DEBUG, "nl80211: Beacon set failed: %d (%s)",
4293 ret, strerror(-ret));
4294 } else {
4295 bss->beacon_set = 1;
4296 nl80211_set_bss(bss, params->cts_protect, params->preamble,
4297 params->short_slot_time, params->ht_opmode,
4298 params->isolate, params->basic_rates);
4299 nl80211_set_multicast_to_unicast(bss,
4300 params->multicast_to_unicast);
4301 if (beacon_set && params->freq &&
4302 params->freq->bandwidth != bss->bandwidth) {
4303 wpa_printf(MSG_DEBUG,
4304 "nl80211: Update BSS %s bandwidth: %d -> %d",
4305 bss->ifname, bss->bandwidth,
4306 params->freq->bandwidth);
4307 ret = nl80211_set_channel(bss, params->freq, 1);
4308 if (ret) {
4309 wpa_printf(MSG_DEBUG,
4310 "nl80211: Frequency set failed: %d (%s)",
4311 ret, strerror(-ret));
4312 } else {
4313 wpa_printf(MSG_DEBUG,
4314 "nl80211: Frequency set succeeded for ht2040 coex");
4315 bss->bandwidth = params->freq->bandwidth;
4316 }
4317 } else if (!beacon_set && params->freq) {
4318 /*
4319 * cfg80211 updates the driver on frequence change in AP
4320 * mode only at the point when beaconing is started, so
4321 * set the initial value here.
4322 */
4323 bss->bandwidth = params->freq->bandwidth;
4324 }
4325 }
4326
4327 #ifdef CONFIG_MESH
4328 if (is_mesh_interface(drv->nlmode) && params->ht_opmode != -1) {
4329 os_memset(&mesh_params, 0, sizeof(mesh_params));
4330 mesh_params.flags |= WPA_DRIVER_MESH_CONF_FLAG_HT_OP_MODE;
4331 mesh_params.ht_opmode = params->ht_opmode;
4332 ret = nl80211_set_mesh_config(priv, &mesh_params);
4333 if (ret < 0)
4334 return ret;
4335 }
4336 #endif /* CONFIG_MESH */
4337
4338 return ret;
4339 fail:
4340 nlmsg_free(msg);
4341 return ret;
4342 }
4343
4344
4345 static int nl80211_put_freq_params(struct nl_msg *msg,
4346 const struct hostapd_freq_params *freq)
4347 {
4348 wpa_printf(MSG_DEBUG, " * freq=%d", freq->freq);
4349 if (nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq->freq))
4350 return -ENOBUFS;
4351
4352 wpa_printf(MSG_DEBUG, " * vht_enabled=%d", freq->vht_enabled);
4353 wpa_printf(MSG_DEBUG, " * ht_enabled=%d", freq->ht_enabled);
4354
4355 if (freq->vht_enabled) {
4356 enum nl80211_chan_width cw;
4357
4358 wpa_printf(MSG_DEBUG, " * bandwidth=%d", freq->bandwidth);
4359 switch (freq->bandwidth) {
4360 case 20:
4361 cw = NL80211_CHAN_WIDTH_20;
4362 break;
4363 case 40:
4364 cw = NL80211_CHAN_WIDTH_40;
4365 break;
4366 case 80:
4367 if (freq->center_freq2)
4368 cw = NL80211_CHAN_WIDTH_80P80;
4369 else
4370 cw = NL80211_CHAN_WIDTH_80;
4371 break;
4372 case 160:
4373 cw = NL80211_CHAN_WIDTH_160;
4374 break;
4375 default:
4376 return -EINVAL;
4377 }
4378
4379 wpa_printf(MSG_DEBUG, " * channel_width=%d", cw);
4380 wpa_printf(MSG_DEBUG, " * center_freq1=%d",
4381 freq->center_freq1);
4382 wpa_printf(MSG_DEBUG, " * center_freq2=%d",
4383 freq->center_freq2);
4384 if (nla_put_u32(msg, NL80211_ATTR_CHANNEL_WIDTH, cw) ||
4385 nla_put_u32(msg, NL80211_ATTR_CENTER_FREQ1,
4386 freq->center_freq1) ||
4387 (freq->center_freq2 &&
4388 nla_put_u32(msg, NL80211_ATTR_CENTER_FREQ2,
4389 freq->center_freq2)))
4390 return -ENOBUFS;
4391 } else if (freq->ht_enabled) {
4392 enum nl80211_channel_type ct;
4393
4394 wpa_printf(MSG_DEBUG, " * sec_channel_offset=%d",
4395 freq->sec_channel_offset);
4396 switch (freq->sec_channel_offset) {
4397 case -1:
4398 ct = NL80211_CHAN_HT40MINUS;
4399 break;
4400 case 1:
4401 ct = NL80211_CHAN_HT40PLUS;
4402 break;
4403 default:
4404 ct = NL80211_CHAN_HT20;
4405 break;
4406 }
4407
4408 wpa_printf(MSG_DEBUG, " * channel_type=%d", ct);
4409 if (nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE, ct))
4410 return -ENOBUFS;
4411 } else {
4412 wpa_printf(MSG_DEBUG, " * channel_type=%d",
4413 NL80211_CHAN_NO_HT);
4414 if (nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE,
4415 NL80211_CHAN_NO_HT))
4416 return -ENOBUFS;
4417 }
4418 return 0;
4419 }
4420
4421
4422 static int nl80211_set_channel(struct i802_bss *bss,
4423 struct hostapd_freq_params *freq, int set_chan)
4424 {
4425 struct wpa_driver_nl80211_data *drv = bss->drv;
4426 struct nl_msg *msg;
4427 int ret;
4428
4429 wpa_printf(MSG_DEBUG,
4430 "nl80211: Set freq %d (ht_enabled=%d, vht_enabled=%d, bandwidth=%d MHz, cf1=%d MHz, cf2=%d MHz)",
4431 freq->freq, freq->ht_enabled, freq->vht_enabled,
4432 freq->bandwidth, freq->center_freq1, freq->center_freq2);
4433
4434 msg = nl80211_drv_msg(drv, 0, set_chan ? NL80211_CMD_SET_CHANNEL :
4435 NL80211_CMD_SET_WIPHY);
4436 if (!msg || nl80211_put_freq_params(msg, freq) < 0) {
4437 nlmsg_free(msg);
4438 return -1;
4439 }
4440
4441 ret = send_and_recv_msgs(drv, msg, NULL, NULL);
4442 if (ret == 0) {
4443 bss->freq = freq->freq;
4444 return 0;
4445 }
4446 wpa_printf(MSG_DEBUG, "nl80211: Failed to set channel (freq=%d): "
4447 "%d (%s)", freq->freq, ret, strerror(-ret));
4448 return -1;
4449 }
4450
4451
4452 static u32 sta_flags_nl80211(int flags)
4453 {
4454 u32 f = 0;
4455
4456 if (flags & WPA_STA_AUTHORIZED)
4457 f |= BIT(NL80211_STA_FLAG_AUTHORIZED);
4458 if (flags & WPA_STA_WMM)
4459 f |= BIT(NL80211_STA_FLAG_WME);
4460 if (flags & WPA_STA_SHORT_PREAMBLE)
4461 f |= BIT(NL80211_STA_FLAG_SHORT_PREAMBLE);
4462 if (flags & WPA_STA_MFP)
4463 f |= BIT(NL80211_STA_FLAG_MFP);
4464 if (flags & WPA_STA_TDLS_PEER)
4465 f |= BIT(NL80211_STA_FLAG_TDLS_PEER);
4466 if (flags & WPA_STA_AUTHENTICATED)
4467 f |= BIT(NL80211_STA_FLAG_AUTHENTICATED);
4468 if (flags & WPA_STA_ASSOCIATED)
4469 f |= BIT(NL80211_STA_FLAG_ASSOCIATED);
4470
4471 return f;
4472 }
4473
4474
4475 #ifdef CONFIG_MESH
4476 static u32 sta_plink_state_nl80211(enum mesh_plink_state state)
4477 {
4478 switch (state) {
4479 case PLINK_IDLE:
4480 return NL80211_PLINK_LISTEN;
4481 case PLINK_OPN_SNT:
4482 return NL80211_PLINK_OPN_SNT;
4483 case PLINK_OPN_RCVD:
4484 return NL80211_PLINK_OPN_RCVD;
4485 case PLINK_CNF_RCVD:
4486 return NL80211_PLINK_CNF_RCVD;
4487 case PLINK_ESTAB:
4488 return NL80211_PLINK_ESTAB;
4489 case PLINK_HOLDING:
4490 return NL80211_PLINK_HOLDING;
4491 case PLINK_BLOCKED:
4492 return NL80211_PLINK_BLOCKED;
4493 default:
4494 wpa_printf(MSG_ERROR, "nl80211: Invalid mesh plink state %d",
4495 state);
4496 }
4497 return -1;
4498 }
4499 #endif /* CONFIG_MESH */
4500
4501
4502 static int wpa_driver_nl80211_sta_add(void *priv,
4503 struct hostapd_sta_add_params *params)
4504 {
4505 struct i802_bss *bss = priv;
4506 struct wpa_driver_nl80211_data *drv = bss->drv;
4507 struct nl_msg *msg;
4508 struct nl80211_sta_flag_update upd;
4509 int ret = -ENOBUFS;
4510
4511 if ((params->flags & WPA_STA_TDLS_PEER) &&
4512 !(drv->capa.flags & WPA_DRIVER_FLAGS_TDLS_SUPPORT))
4513 return -EOPNOTSUPP;
4514
4515 wpa_printf(MSG_DEBUG, "nl80211: %s STA " MACSTR,
4516 params->set ? "Set" : "Add", MAC2STR(params->addr));
4517 msg = nl80211_bss_msg(bss, 0, params->set ? NL80211_CMD_SET_STATION :
4518 NL80211_CMD_NEW_STATION);
4519 if (!msg || nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, params->addr))
4520 goto fail;
4521
4522 /*
4523 * Set the below properties only in one of the following cases:
4524 * 1. New station is added, already associated.
4525 * 2. Set WPA_STA_TDLS_PEER station.
4526 * 3. Set an already added unassociated station, if driver supports
4527 * full AP client state. (Set these properties after station became
4528 * associated will be rejected by the driver).
4529 */
4530 if (!params->set || (params->flags & WPA_STA_TDLS_PEER) ||
4531 (params->set && FULL_AP_CLIENT_STATE_SUPP(drv->capa.flags) &&
4532 (params->flags & WPA_STA_ASSOCIATED))) {
4533 wpa_hexdump(MSG_DEBUG, " * supported rates",
4534 params->supp_rates, params->supp_rates_len);
4535 wpa_printf(MSG_DEBUG, " * capability=0x%x",
4536 params->capability);
4537 if (nla_put(msg, NL80211_ATTR_STA_SUPPORTED_RATES,
4538 params->supp_rates_len, params->supp_rates) ||
4539 nla_put_u16(msg, NL80211_ATTR_STA_CAPABILITY,
4540 params->capability))
4541 goto fail;
4542
4543 if (params->ht_capabilities) {
4544 wpa_hexdump(MSG_DEBUG, " * ht_capabilities",
4545 (u8 *) params->ht_capabilities,
4546 sizeof(*params->ht_capabilities));
4547 if (nla_put(msg, NL80211_ATTR_HT_CAPABILITY,
4548 sizeof(*params->ht_capabilities),
4549 params->ht_capabilities))
4550 goto fail;
4551 }
4552
4553 if (params->vht_capabilities) {
4554 wpa_hexdump(MSG_DEBUG, " * vht_capabilities",
4555 (u8 *) params->vht_capabilities,
4556 sizeof(*params->vht_capabilities));
4557 if (nla_put(msg, NL80211_ATTR_VHT_CAPABILITY,
4558 sizeof(*params->vht_capabilities),
4559 params->vht_capabilities))
4560 goto fail;
4561 }
4562
4563 if (params->ext_capab) {
4564 wpa_hexdump(MSG_DEBUG, " * ext_capab",
4565 params->ext_capab, params->ext_capab_len);
4566 if (nla_put(msg, NL80211_ATTR_STA_EXT_CAPABILITY,
4567 params->ext_capab_len, params->ext_capab))
4568 goto fail;
4569 }
4570
4571 if (is_ap_interface(drv->nlmode) &&
4572 nla_put_u8(msg, NL80211_ATTR_STA_SUPPORT_P2P_PS,
4573 params->support_p2p_ps ?
4574 NL80211_P2P_PS_SUPPORTED :
4575 NL80211_P2P_PS_UNSUPPORTED))
4576 goto fail;
4577 }
4578 if (!params->set) {
4579 if (params->aid) {
4580 wpa_printf(MSG_DEBUG, " * aid=%u", params->aid);
4581 if (nla_put_u16(msg, NL80211_ATTR_STA_AID, params->aid))
4582 goto fail;
4583 } else {
4584 /*
4585 * cfg80211 validates that AID is non-zero, so we have
4586 * to make this a non-zero value for the TDLS case where
4587 * a dummy STA entry is used for now and for a station
4588 * that is still not associated.
4589 */
4590 wpa_printf(MSG_DEBUG, " * aid=1 (%s workaround)",
4591 (params->flags & WPA_STA_TDLS_PEER) ?
4592 "TDLS" : "UNASSOC_STA");
4593 if (nla_put_u16(msg, NL80211_ATTR_STA_AID, 1))
4594 goto fail;
4595 }
4596 wpa_printf(MSG_DEBUG, " * listen_interval=%u",
4597 params->listen_interval);
4598 if (nla_put_u16(msg, NL80211_ATTR_STA_LISTEN_INTERVAL,
4599 params->listen_interval))
4600 goto fail;
4601 } else if (params->aid && (params->flags & WPA_STA_TDLS_PEER)) {
4602 wpa_printf(MSG_DEBUG, " * peer_aid=%u", params->aid);
4603 if (nla_put_u16(msg, NL80211_ATTR_PEER_AID, params->aid))
4604 goto fail;
4605 } else if (FULL_AP_CLIENT_STATE_SUPP(drv->capa.flags) &&
4606 (params->flags & WPA_STA_ASSOCIATED)) {
4607 wpa_printf(MSG_DEBUG, " * aid=%u", params->aid);
4608 wpa_printf(MSG_DEBUG, " * listen_interval=%u",
4609 params->listen_interval);
4610 if (nla_put_u16(msg, NL80211_ATTR_STA_AID, params->aid) ||
4611 nla_put_u16(msg, NL80211_ATTR_STA_LISTEN_INTERVAL,
4612 params->listen_interval))
4613 goto fail;
4614 }
4615
4616 if (params->vht_opmode_enabled) {
4617 wpa_printf(MSG_DEBUG, " * opmode=%u", params->vht_opmode);
4618 if (nla_put_u8(msg, NL80211_ATTR_OPMODE_NOTIF,
4619 params->vht_opmode))
4620 goto fail;
4621 }
4622
4623 if (params->supp_channels) {
4624 wpa_hexdump(MSG_DEBUG, " * supported channels",
4625 params->supp_channels, params->supp_channels_len);
4626 if (nla_put(msg, NL80211_ATTR_STA_SUPPORTED_CHANNELS,
4627 params->supp_channels_len, params->supp_channels))
4628 goto fail;
4629 }
4630
4631 if (params->supp_oper_classes) {
4632 wpa_hexdump(MSG_DEBUG, " * supported operating classes",
4633 params->supp_oper_classes,
4634 params->supp_oper_classes_len);
4635 if (nla_put(msg, NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES,
4636 params->supp_oper_classes_len,
4637 params->supp_oper_classes))
4638 goto fail;
4639 }
4640
4641 os_memset(&upd, 0, sizeof(upd));
4642 upd.set = sta_flags_nl80211(params->flags);
4643 upd.mask = upd.set | sta_flags_nl80211(params->flags_mask);
4644
4645 /*
4646 * If the driver doesn't support full AP client state, ignore ASSOC/AUTH
4647 * flags, as nl80211 driver moves a new station, by default, into
4648 * associated state.
4649 *
4650 * On the other hand, if the driver supports that feature and the
4651 * station is added in unauthenticated state, set the
4652 * authenticated/associated bits in the mask to prevent moving this
4653 * station to associated state before it is actually associated.
4654 *
4655 * This is irrelevant for mesh mode where the station is added to the
4656 * driver as authenticated already, and ASSOCIATED isn't part of the
4657 * nl80211 API.
4658 */
4659 if (!is_mesh_interface(drv->nlmode)) {
4660 if (!FULL_AP_CLIENT_STATE_SUPP(drv->capa.flags)) {
4661 wpa_printf(MSG_DEBUG,
4662 "nl80211: Ignore ASSOC/AUTH flags since driver doesn't support full AP client state");
4663 upd.mask &= ~(BIT(NL80211_STA_FLAG_ASSOCIATED) |
4664 BIT(NL80211_STA_FLAG_AUTHENTICATED));
4665 } else if (!params->set &&
4666 !(params->flags & WPA_STA_TDLS_PEER)) {
4667 if (!(params->flags & WPA_STA_AUTHENTICATED))
4668 upd.mask |= BIT(NL80211_STA_FLAG_AUTHENTICATED);
4669 if (!(params->flags & WPA_STA_ASSOCIATED))
4670 upd.mask |= BIT(NL80211_STA_FLAG_ASSOCIATED);
4671 }
4672 #ifdef CONFIG_MESH
4673 } else {
4674 if (params->plink_state == PLINK_ESTAB && params->peer_aid) {
4675 ret = nla_put_u16(msg, NL80211_ATTR_MESH_PEER_AID,
4676 params->peer_aid);
4677 if (ret)
4678 goto fail;
4679 }
4680 #endif /* CONFIG_MESH */
4681 }
4682
4683 wpa_printf(MSG_DEBUG, " * flags set=0x%x mask=0x%x",
4684 upd.set, upd.mask);
4685 if (nla_put(msg, NL80211_ATTR_STA_FLAGS2, sizeof(upd), &upd))
4686 goto fail;
4687
4688 #ifdef CONFIG_MESH
4689 if (params->plink_state &&
4690 nla_put_u8(msg, NL80211_ATTR_STA_PLINK_STATE,
4691 sta_plink_state_nl80211(params->plink_state)))
4692 goto fail;
4693 #endif /* CONFIG_MESH */
4694
4695 if ((!params->set || FULL_AP_CLIENT_STATE_SUPP(drv->capa.flags)) &&
4696 (params->flags & WPA_STA_WMM)) {
4697 struct nlattr *wme = nla_nest_start(msg, NL80211_ATTR_STA_WME);
4698
4699 wpa_printf(MSG_DEBUG, " * qosinfo=0x%x", params->qosinfo);
4700 if (!wme ||
4701 nla_put_u8(msg, NL80211_STA_WME_UAPSD_QUEUES,
4702 params->qosinfo & WMM_QOSINFO_STA_AC_MASK) ||
4703 nla_put_u8(msg, NL80211_STA_WME_MAX_SP,
4704 (params->qosinfo >> WMM_QOSINFO_STA_SP_SHIFT) &
4705 WMM_QOSINFO_STA_SP_MASK))
4706 goto fail;
4707 nla_nest_end(msg, wme);
4708 }
4709
4710 ret = send_and_recv_msgs(drv, msg, NULL, NULL);
4711 msg = NULL;
4712 if (ret)
4713 wpa_printf(MSG_DEBUG, "nl80211: NL80211_CMD_%s_STATION "
4714 "result: %d (%s)", params->set ? "SET" : "NEW", ret,
4715 strerror(-ret));
4716 if (ret == -EEXIST)
4717 ret = 0;
4718 fail:
4719 nlmsg_free(msg);
4720 return ret;
4721 }
4722
4723
4724 static void rtnl_neigh_delete_fdb_entry(struct i802_bss *bss, const u8 *addr)
4725 {
4726 #ifdef CONFIG_LIBNL3_ROUTE
4727 struct wpa_driver_nl80211_data *drv = bss->drv;
4728 struct rtnl_neigh *rn;
4729 struct nl_addr *nl_addr;
4730 int err;
4731
4732 rn = rtnl_neigh_alloc();
4733 if (!rn)
4734 return;
4735
4736 rtnl_neigh_set_family(rn, AF_BRIDGE);
4737 rtnl_neigh_set_ifindex(rn, bss->ifindex);
4738 nl_addr = nl_addr_build(AF_BRIDGE, (void *) addr, ETH_ALEN);
4739 if (!nl_addr) {
4740 rtnl_neigh_put(rn);
4741 return;
4742 }
4743 rtnl_neigh_set_lladdr(rn, nl_addr);
4744
4745 err = rtnl_neigh_delete(drv->rtnl_sk, rn, 0);
4746 if (err < 0) {
4747 wpa_printf(MSG_DEBUG, "nl80211: bridge FDB entry delete for "
4748 MACSTR " ifindex=%d failed: %s", MAC2STR(addr),
4749 bss->ifindex, nl_geterror(err));
4750 } else {
4751 wpa_printf(MSG_DEBUG, "nl80211: deleted bridge FDB entry for "
4752 MACSTR, MAC2STR(addr));
4753 }
4754
4755 nl_addr_put(nl_addr);
4756 rtnl_neigh_put(rn);
4757 #endif /* CONFIG_LIBNL3_ROUTE */
4758 }
4759
4760
4761 static int wpa_driver_nl80211_sta_remove(struct i802_bss *bss, const u8 *addr,
4762 int deauth, u16 reason_code)
4763 {
4764 struct wpa_driver_nl80211_data *drv = bss->drv;
4765 struct nl_msg *msg;
4766 int ret;
4767
4768 if (!(msg = nl80211_bss_msg(bss, 0, NL80211_CMD_DEL_STATION)) ||
4769 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) ||
4770 (deauth == 0 &&
4771 nla_put_u8(msg, NL80211_ATTR_MGMT_SUBTYPE,
4772 WLAN_FC_STYPE_DISASSOC)) ||
4773 (deauth == 1 &&
4774 nla_put_u8(msg, NL80211_ATTR_MGMT_SUBTYPE,
4775 WLAN_FC_STYPE_DEAUTH)) ||
4776 (reason_code &&
4777 nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason_code))) {
4778 nlmsg_free(msg);
4779 return -ENOBUFS;
4780 }
4781
4782 ret = send_and_recv_msgs(drv, msg, NULL, NULL);
4783 wpa_printf(MSG_DEBUG, "nl80211: sta_remove -> DEL_STATION %s " MACSTR
4784 " --> %d (%s)",
4785 bss->ifname, MAC2STR(addr), ret, strerror(-ret));
4786
4787 if (drv->rtnl_sk)
4788 rtnl_neigh_delete_fdb_entry(bss, addr);
4789
4790 if (ret == -ENOENT)
4791 return 0;
4792 return ret;
4793 }
4794
4795
4796 void nl80211_remove_iface(struct wpa_driver_nl80211_data *drv, int ifidx)
4797 {
4798 struct nl_msg *msg;
4799 struct wpa_driver_nl80211_data *drv2;
4800
4801 wpa_printf(MSG_DEBUG, "nl80211: Remove interface ifindex=%d", ifidx);
4802
4803 /* stop listening for EAPOL on this interface */
4804 dl_list_for_each(drv2, &drv->global->interfaces,
4805 struct wpa_driver_nl80211_data, list)
4806 {
4807 del_ifidx(drv2, ifidx, IFIDX_ANY);
4808 /* Remove all bridges learned for this iface */
4809 del_ifidx(drv2, IFIDX_ANY, ifidx);
4810 }
4811
4812 msg = nl80211_ifindex_msg(drv, ifidx, 0, NL80211_CMD_DEL_INTERFACE);
4813 if (send_and_recv_msgs(drv, msg, NULL, NULL) == 0)
4814 return;
4815 wpa_printf(MSG_ERROR, "Failed to remove interface (ifidx=%d)", ifidx);
4816 }
4817
4818
4819 const char * nl80211_iftype_str(enum nl80211_iftype mode)
4820 {
4821 switch (mode) {
4822 case NL80211_IFTYPE_ADHOC:
4823 return "ADHOC";
4824 case NL80211_IFTYPE_STATION:
4825 return "STATION";
4826 case NL80211_IFTYPE_AP:
4827 return "AP";
4828 case NL80211_IFTYPE_AP_VLAN:
4829 return "AP_VLAN";
4830 case NL80211_IFTYPE_WDS:
4831 return "WDS";
4832 case NL80211_IFTYPE_MONITOR:
4833 return "MONITOR";
4834 case NL80211_IFTYPE_MESH_POINT:
4835 return "MESH_POINT";
4836 case NL80211_IFTYPE_P2P_CLIENT:
4837 return "P2P_CLIENT";
4838 case NL80211_IFTYPE_P2P_GO:
4839 return "P2P_GO";
4840 case NL80211_IFTYPE_P2P_DEVICE:
4841 return "P2P_DEVICE";
4842 default:
4843 return "unknown";
4844 }
4845 }
4846
4847
4848 static int nl80211_create_iface_once(struct wpa_driver_nl80211_data *drv,
4849 const char *ifname,
4850 enum nl80211_iftype iftype,
4851 const u8 *addr, int wds,
4852 int (*handler)(struct nl_msg *, void *),
4853 void *arg)
4854 {
4855 struct nl_msg *msg;
4856 int ifidx;
4857 int ret = -ENOBUFS;
4858
4859 wpa_printf(MSG_DEBUG, "nl80211: Create interface iftype %d (%s)",
4860 iftype, nl80211_iftype_str(iftype));
4861
4862 msg = nl80211_cmd_msg(drv->first_bss, 0, NL80211_CMD_NEW_INTERFACE);
4863 if (!msg ||
4864 nla_put_string(msg, NL80211_ATTR_IFNAME, ifname) ||
4865 nla_put_u32(msg, NL80211_ATTR_IFTYPE, iftype))
4866 goto fail;
4867
4868 if (iftype == NL80211_IFTYPE_MONITOR) {
4869 struct nlattr *flags;
4870
4871 flags = nla_nest_start(msg, NL80211_ATTR_MNTR_FLAGS);
4872 if (!flags ||
4873 nla_put_flag(msg, NL80211_MNTR_FLAG_COOK_FRAMES))
4874 goto fail;
4875
4876 nla_nest_end(msg, flags);
4877 } else if (wds) {
4878 if (nla_put_u8(msg, NL80211_ATTR_4ADDR, wds))
4879 goto fail;
4880 }
4881
4882 /*
4883 * Tell cfg80211 that the interface belongs to the socket that created
4884 * it, and the interface should be deleted when the socket is closed.
4885 */
4886 if (nla_put_flag(msg, NL80211_ATTR_IFACE_SOCKET_OWNER))
4887 goto fail;
4888
4889 ret = send_and_recv_msgs(drv, msg, handler, arg);
4890 msg = NULL;
4891 if (ret) {
4892 fail:
4893 nlmsg_free(msg);
4894 wpa_printf(MSG_ERROR, "Failed to create interface %s: %d (%s)",
4895 ifname, ret, strerror(-ret));
4896 return ret;
4897 }
4898
4899 if (iftype == NL80211_IFTYPE_P2P_DEVICE)
4900 return 0;
4901
4902 ifidx = if_nametoindex(ifname);
4903 wpa_printf(MSG_DEBUG, "nl80211: New interface %s created: ifindex=%d",
4904 ifname, ifidx);
4905
4906 if (ifidx <= 0)
4907 return -1;
4908
4909 /*
4910 * Some virtual interfaces need to process EAPOL packets and events on
4911 * the parent interface. This is used mainly with hostapd.
4912 */
4913 if (drv->hostapd ||
4914 iftype == NL80211_IFTYPE_AP_VLAN ||
4915 iftype == NL80211_IFTYPE_WDS ||
4916 iftype == NL80211_IFTYPE_MONITOR) {
4917 /* start listening for EAPOL on this interface */
4918 add_ifidx(drv, ifidx, IFIDX_ANY);
4919 }
4920
4921 if (addr && iftype != NL80211_IFTYPE_MONITOR &&
4922 linux_set_ifhwaddr(drv->global->ioctl_sock, ifname, addr)) {
4923 nl80211_remove_iface(drv, ifidx);
4924 return -1;
4925 }
4926
4927 return ifidx;
4928 }
4929
4930
4931 int nl80211_create_iface(struct wpa_driver_nl80211_data *drv,
4932 const char *ifname, enum nl80211_iftype iftype,
4933 const u8 *addr, int wds,
4934 int (*handler)(struct nl_msg *, void *),
4935 void *arg, int use_existing)
4936 {
4937 int ret;
4938
4939 ret = nl80211_create_iface_once(drv, ifname, iftype, addr, wds, handler,
4940 arg);
4941
4942 /* if error occurred and interface exists already */
4943 if (ret == -ENFILE && if_nametoindex(ifname)) {
4944 if (use_existing) {
4945 wpa_printf(MSG_DEBUG, "nl80211: Continue using existing interface %s",
4946 ifname);
4947 if (addr && iftype != NL80211_IFTYPE_MONITOR &&
4948 linux_set_ifhwaddr(drv->global->ioctl_sock, ifname,
4949 addr) < 0 &&
4950 (linux_set_iface_flags(drv->global->ioctl_sock,
4951 ifname, 0) < 0 ||
4952 linux_set_ifhwaddr(drv->global->ioctl_sock, ifname,
4953 addr) < 0 ||
4954 linux_set_iface_flags(drv->global->ioctl_sock,
4955 ifname, 1) < 0))
4956 return -1;
4957 return -ENFILE;
4958 }
4959 wpa_printf(MSG_INFO, "Try to remove and re-create %s", ifname);
4960
4961 /* Try to remove the interface that was already there. */
4962 nl80211_remove_iface(drv, if_nametoindex(ifname));
4963
4964 /* Try to create the interface again */
4965 ret = nl80211_create_iface_once(drv, ifname, iftype, addr,
4966 wds, handler, arg);
4967 }
4968
4969 if (ret >= 0 && is_p2p_net_interface(iftype)) {
4970 wpa_printf(MSG_DEBUG,
4971 "nl80211: Interface %s created for P2P - disable 11b rates",
4972 ifname);
4973 nl80211_disable_11b_rates(drv, ret, 1);
4974 }
4975
4976 return ret;
4977 }
4978
4979
4980 static int nl80211_setup_ap(struct i802_bss *bss)
4981 {
4982 struct wpa_driver_nl80211_data *drv = bss->drv;
4983
4984 wpa_printf(MSG_DEBUG, "nl80211: Setup AP(%s) - device_ap_sme=%d use_monitor=%d",
4985 bss->ifname, drv->device_ap_sme, drv->use_monitor);
4986
4987 /*
4988 * Disable Probe Request reporting unless we need it in this way for
4989 * devices that include the AP SME, in the other case (unless using
4990 * monitor iface) we'll get it through the nl_mgmt socket instead.
4991 */
4992 if (!drv->device_ap_sme)
4993 wpa_driver_nl80211_probe_req_report(bss, 0);
4994
4995 if (!drv->device_ap_sme && !drv->use_monitor)
4996 if (nl80211_mgmt_subscribe_ap(bss))
4997 return -1;
4998
4999 if (drv->device_ap_sme && !drv->use_monitor)
5000 if (nl80211_mgmt_subscribe_ap_dev_sme(bss))
5001 wpa_printf(MSG_DEBUG,
5002 "nl80211: Failed to subscribe for mgmt frames from SME driver - trying to run without it");
5003
5004 if (!drv->device_ap_sme && drv->use_monitor &&
5005 nl80211_create_monitor_interface(drv) &&
5006 !drv->device_ap_sme)
5007 return -1;
5008
5009 if (drv->device_ap_sme &&
5010 wpa_driver_nl80211_probe_req_report(bss, 1) < 0) {
5011 wpa_printf(MSG_DEBUG, "nl80211: Failed to enable "
5012 "Probe Request frame reporting in AP mode");
5013 /* Try to survive without this */
5014 }
5015
5016 return 0;
5017 }
5018
5019
5020 static void nl80211_teardown_ap(struct i802_bss *bss)
5021 {
5022 struct wpa_driver_nl80211_data *drv = bss->drv;
5023
5024 wpa_printf(MSG_DEBUG, "nl80211: Teardown AP(%s) - device_ap_sme=%d use_monitor=%d",
5025 bss->ifname, drv->device_ap_sme, drv->use_monitor);
5026 if (drv->device_ap_sme) {
5027 wpa_driver_nl80211_probe_req_report(bss, 0);
5028 if (!drv->use_monitor)
5029 nl80211_mgmt_unsubscribe(bss, "AP teardown (dev SME)");
5030 } else if (drv->use_monitor)
5031 nl80211_remove_monitor_interface(drv);
5032 else
5033 nl80211_mgmt_unsubscribe(bss, "AP teardown");
5034
5035 nl80211_put_wiphy_data_ap(bss);
5036 bss->beacon_set = 0;
5037 }
5038
5039
5040 static int nl80211_send_eapol_data(struct i802_bss *bss,
5041 const u8 *addr, const u8 *data,
5042 size_t data_len)
5043 {
5044 struct sockaddr_ll ll;
5045 int ret;
5046
5047 if (bss->drv->eapol_tx_sock < 0) {
5048 wpa_printf(MSG_DEBUG, "nl80211: No socket to send EAPOL");
5049 return -1;
5050 }
5051
5052 os_memset(&ll, 0, sizeof(ll));
5053 ll.sll_family = AF_PACKET;
5054 ll.sll_ifindex = bss->ifindex;
5055 ll.sll_protocol = htons(ETH_P_PAE);
5056 ll.sll_halen = ETH_ALEN;
5057 os_memcpy(ll.sll_addr, addr, ETH_ALEN);
5058 ret = sendto(bss->drv->eapol_tx_sock, data, data_len, 0,
5059 (struct sockaddr *) &ll, sizeof(ll));
5060 if (ret < 0)
5061 wpa_printf(MSG_ERROR, "nl80211: EAPOL TX: %s",
5062 strerror(errno));
5063
5064 return ret;
5065 }
5066
5067
5068 static const u8 rfc1042_header[6] = { 0xaa, 0xaa, 0x03, 0x00, 0x00, 0x00 };
5069
5070 static int wpa_driver_nl80211_hapd_send_eapol(
5071 void *priv, const u8 *addr, const u8 *data,
5072 size_t data_len, int encrypt, const u8 *own_addr, u32 flags)
5073 {
5074 struct i802_bss *bss = priv;
5075 struct wpa_driver_nl80211_data *drv = bss->drv;
5076 struct ieee80211_hdr *hdr;
5077 size_t len;
5078 u8 *pos;
5079 int res;
5080 int qos = flags & WPA_STA_WMM;
5081
5082 if (drv->device_ap_sme || !drv->use_monitor)
5083 return nl80211_send_eapol_data(bss, addr, data, data_len);
5084
5085 len = sizeof(*hdr) + (qos ? 2 : 0) + sizeof(rfc1042_header) + 2 +
5086 data_len;
5087 hdr = os_zalloc(len);
5088 if (hdr == NULL) {
5089 wpa_printf(MSG_INFO, "nl80211: Failed to allocate EAPOL buffer(len=%lu)",
5090 (unsigned long) len);
5091 return -1;
5092 }
5093
5094 hdr->frame_control =
5095 IEEE80211_FC(WLAN_FC_TYPE_DATA, WLAN_FC_STYPE_DATA);
5096 hdr->frame_control |= host_to_le16(WLAN_FC_FROMDS);
5097 if (encrypt)
5098 hdr->frame_control |= host_to_le16(WLAN_FC_ISWEP);
5099 if (qos) {
5100 hdr->frame_control |=
5101 host_to_le16(WLAN_FC_STYPE_QOS_DATA << 4);
5102 }
5103
5104 memcpy(hdr->IEEE80211_DA_FROMDS, addr, ETH_ALEN);
5105 memcpy(hdr->IEEE80211_BSSID_FROMDS, own_addr, ETH_ALEN);
5106 memcpy(hdr->IEEE80211_SA_FROMDS, own_addr, ETH_ALEN);
5107 pos = (u8 *) (hdr + 1);
5108
5109 if (qos) {
5110 /* Set highest priority in QoS header */
5111 pos[0] = 7;
5112 pos[1] = 0;
5113 pos += 2;
5114 }
5115
5116 memcpy(pos, rfc1042_header, sizeof(rfc1042_header));
5117 pos += sizeof(rfc1042_header);
5118 WPA_PUT_BE16(pos, ETH_P_PAE);
5119 pos += 2;
5120 memcpy(pos, data, data_len);
5121
5122 res = wpa_driver_nl80211_send_frame(bss, (u8 *) hdr, len, encrypt, 0,
5123 0, 0, 0, 0, NULL, 0);
5124 if (res < 0) {
5125 wpa_printf(MSG_ERROR, "i802_send_eapol - packet len: %lu - "
5126 "failed: %d (%s)",
5127 (unsigned long) len, errno, strerror(errno));
5128 }
5129 os_free(hdr);
5130
5131 return res;
5132 }
5133
5134
5135 static int wpa_driver_nl80211_sta_set_flags(void *priv, const u8 *addr,
5136 unsigned int total_flags,
5137 unsigned int flags_or,
5138 unsigned int flags_and)
5139 {
5140 struct i802_bss *bss = priv;
5141 struct nl_msg *msg;
5142 struct nlattr *flags;
5143 struct nl80211_sta_flag_update upd;
5144
5145 wpa_printf(MSG_DEBUG, "nl80211: Set STA flags - ifname=%s addr=" MACSTR
5146 " total_flags=0x%x flags_or=0x%x flags_and=0x%x authorized=%d",
5147 bss->ifname, MAC2STR(addr), total_flags, flags_or, flags_and,
5148 !!(total_flags & WPA_STA_AUTHORIZED));
5149
5150 if (!(msg = nl80211_bss_msg(bss, 0, NL80211_CMD_SET_STATION)) ||
5151 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr))
5152 goto fail;
5153
5154 /*
5155 * Backwards compatibility version using NL80211_ATTR_STA_FLAGS. This
5156 * can be removed eventually.
5157 */
5158 flags = nla_nest_start(msg, NL80211_ATTR_STA_FLAGS);
5159 if (!flags ||
5160 ((total_flags & WPA_STA_AUTHORIZED) &&
5161 nla_put_flag(msg, NL80211_STA_FLAG_AUTHORIZED)) ||
5162 ((total_flags & WPA_STA_WMM) &&
5163 nla_put_flag(msg, NL80211_STA_FLAG_WME)) ||
5164 ((total_flags & WPA_STA_SHORT_PREAMBLE) &&
5165 nla_put_flag(msg, NL80211_STA_FLAG_SHORT_PREAMBLE)) ||
5166 ((total_flags & WPA_STA_MFP) &&
5167 nla_put_flag(msg, NL80211_STA_FLAG_MFP)) ||
5168 ((total_flags & WPA_STA_TDLS_PEER) &&
5169 nla_put_flag(msg, NL80211_STA_FLAG_TDLS_PEER)))
5170 goto fail;
5171
5172 nla_nest_end(msg, flags);
5173
5174 os_memset(&upd, 0, sizeof(upd));
5175 upd.mask = sta_flags_nl80211(flags_or | ~flags_and);
5176 upd.set = sta_flags_nl80211(flags_or);
5177 if (nla_put(msg, NL80211_ATTR_STA_FLAGS2, sizeof(upd), &upd))
5178 goto fail;
5179
5180 return send_and_recv_msgs(bss->drv, msg, NULL, NULL);
5181 fail:
5182 nlmsg_free(msg);
5183 return -ENOBUFS;
5184 }
5185
5186
5187 static int wpa_driver_nl80211_ap(struct wpa_driver_nl80211_data *drv,
5188 struct wpa_driver_associate_params *params)
5189 {
5190 enum nl80211_iftype nlmode, old_mode;
5191
5192 if (params->p2p) {
5193 wpa_printf(MSG_DEBUG, "nl80211: Setup AP operations for P2P "
5194 "group (GO)");
5195 nlmode = NL80211_IFTYPE_P2P_GO;
5196 } else
5197 nlmode = NL80211_IFTYPE_AP;
5198
5199 old_mode = drv->nlmode;
5200 if (wpa_driver_nl80211_set_mode(drv->first_bss, nlmode)) {
5201 nl80211_remove_monitor_interface(drv);
5202 return -1;
5203 }
5204
5205 if (params->freq.freq &&
5206 nl80211_set_channel(drv->first_bss, &params->freq, 0)) {
5207 if (old_mode != nlmode)
5208 wpa_driver_nl80211_set_mode(drv->first_bss, old_mode);
5209 nl80211_remove_monitor_interface(drv);
5210 return -1;
5211 }
5212
5213 return 0;
5214 }
5215
5216
5217 static int nl80211_leave_ibss(struct wpa_driver_nl80211_data *drv,
5218 int reset_mode)
5219 {
5220 struct nl_msg *msg;
5221 int ret;
5222
5223 msg = nl80211_drv_msg(drv, 0, NL80211_CMD_LEAVE_IBSS);
5224 ret = send_and_recv_msgs(drv, msg, NULL, NULL);
5225 if (ret) {
5226 wpa_printf(MSG_DEBUG, "nl80211: Leave IBSS failed: ret=%d "
5227 "(%s)", ret, strerror(-ret));
5228 } else {
5229 wpa_printf(MSG_DEBUG,
5230 "nl80211: Leave IBSS request sent successfully");
5231 }
5232
5233 if (reset_mode &&
5234 wpa_driver_nl80211_set_mode(drv->first_bss,
5235 NL80211_IFTYPE_STATION)) {
5236 wpa_printf(MSG_INFO, "nl80211: Failed to set interface into "
5237 "station mode");
5238 }
5239
5240 return ret;
5241 }
5242
5243
5244 static int nl80211_ht_vht_overrides(struct nl_msg *msg,
5245 struct wpa_driver_associate_params *params)
5246 {
5247 if (params->disable_ht && nla_put_flag(msg, NL80211_ATTR_DISABLE_HT))
5248 return -1;
5249
5250 if (params->htcaps && params->htcaps_mask) {
5251 int sz = sizeof(struct ieee80211_ht_capabilities);
5252 wpa_hexdump(MSG_DEBUG, " * htcaps", params->htcaps, sz);
5253 wpa_hexdump(MSG_DEBUG, " * htcaps_mask",
5254 params->htcaps_mask, sz);
5255 if (nla_put(msg, NL80211_ATTR_HT_CAPABILITY, sz,
5256 params->htcaps) ||
5257 nla_put(msg, NL80211_ATTR_HT_CAPABILITY_MASK, sz,
5258 params->htcaps_mask))
5259 return -1;
5260 }
5261
5262 #ifdef CONFIG_VHT_OVERRIDES
5263 if (params->disable_vht) {
5264 wpa_printf(MSG_DEBUG, " * VHT disabled");
5265 if (nla_put_flag(msg, NL80211_ATTR_DISABLE_VHT))
5266 return -1;
5267 }
5268
5269 if (params->vhtcaps && params->vhtcaps_mask) {
5270 int sz = sizeof(struct ieee80211_vht_capabilities);
5271 wpa_hexdump(MSG_DEBUG, " * vhtcaps", params->vhtcaps, sz);
5272 wpa_hexdump(MSG_DEBUG, " * vhtcaps_mask",
5273 params->vhtcaps_mask, sz);
5274 if (nla_put(msg, NL80211_ATTR_VHT_CAPABILITY, sz,
5275 params->vhtcaps) ||
5276 nla_put(msg, NL80211_ATTR_VHT_CAPABILITY_MASK, sz,
5277 params->vhtcaps_mask))
5278 return -1;
5279 }
5280 #endif /* CONFIG_VHT_OVERRIDES */
5281
5282 return 0;
5283 }
5284
5285
5286 static int wpa_driver_nl80211_ibss(struct wpa_driver_nl80211_data *drv,
5287 struct wpa_driver_associate_params *params)
5288 {
5289 struct nl_msg *msg;
5290 int ret = -1;
5291 int count = 0;
5292
5293 wpa_printf(MSG_DEBUG, "nl80211: Join IBSS (ifindex=%d)", drv->ifindex);
5294
5295 if (wpa_driver_nl80211_set_mode_ibss(drv->first_bss, &params->freq)) {
5296 wpa_printf(MSG_INFO, "nl80211: Failed to set interface into "
5297 "IBSS mode");
5298 return -1;
5299 }
5300
5301 retry:
5302 if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_JOIN_IBSS)) ||
5303 params->ssid == NULL || params->ssid_len > sizeof(drv->ssid))
5304 goto fail;
5305
5306 wpa_printf(MSG_DEBUG, " * SSID=%s",
5307 wpa_ssid_txt(params->ssid, params->ssid_len));
5308 if (nla_put(msg, NL80211_ATTR_SSID, params->ssid_len, params->ssid))
5309 goto fail;
5310 os_memcpy(drv->ssid, params->ssid, params->ssid_len);
5311 drv->ssid_len = params->ssid_len;
5312
5313 if (nl80211_put_freq_params(msg, &params->freq) < 0 ||
5314 nl80211_put_beacon_int(msg, params->beacon_int))
5315 goto fail;
5316
5317 ret = nl80211_set_conn_keys(params, msg);
5318 if (ret)
5319 goto fail;
5320
5321 if (params->bssid && params->fixed_bssid) {
5322 wpa_printf(MSG_DEBUG, " * BSSID=" MACSTR,
5323 MAC2STR(params->bssid));
5324 if (nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, params->bssid))
5325 goto fail;
5326 }
5327
5328 if (params->fixed_freq) {
5329 wpa_printf(MSG_DEBUG, " * fixed_freq");
5330 if (nla_put_flag(msg, NL80211_ATTR_FREQ_FIXED))
5331 goto fail;
5332 }
5333
5334 if (params->key_mgmt_suite == WPA_KEY_MGMT_IEEE8021X ||
5335 params->key_mgmt_suite == WPA_KEY_MGMT_PSK ||
5336 params->key_mgmt_suite == WPA_KEY_MGMT_IEEE8021X_SHA256 ||
5337 params->key_mgmt_suite == WPA_KEY_MGMT_PSK_SHA256) {
5338 wpa_printf(MSG_DEBUG, " * control port");
5339 if (nla_put_flag(msg, NL80211_ATTR_CONTROL_PORT))
5340 goto fail;
5341 }
5342
5343 if (params->wpa_ie) {
5344 wpa_hexdump(MSG_DEBUG,
5345 " * Extra IEs for Beacon/Probe Response frames",
5346 params->wpa_ie, params->wpa_ie_len);
5347 if (nla_put(msg, NL80211_ATTR_IE, params->wpa_ie_len,
5348 params->wpa_ie))
5349 goto fail;
5350 }
5351
5352 ret = nl80211_ht_vht_overrides(msg, params);
5353 if (ret < 0)
5354 goto fail;
5355
5356 ret = send_and_recv_msgs(drv, msg, NULL, NULL);
5357 msg = NULL;
5358 if (ret) {
5359 wpa_printf(MSG_DEBUG, "nl80211: Join IBSS failed: ret=%d (%s)",
5360 ret, strerror(-ret));
5361 count++;
5362 if (ret == -EALREADY && count == 1) {
5363 wpa_printf(MSG_DEBUG, "nl80211: Retry IBSS join after "
5364 "forced leave");
5365 nl80211_leave_ibss(drv, 0);
5366 nlmsg_free(msg);
5367 goto retry;
5368 }
5369 } else {
5370 wpa_printf(MSG_DEBUG,
5371 "nl80211: Join IBSS request sent successfully");
5372 }
5373
5374 fail:
5375 nlmsg_free(msg);
5376 return ret;
5377 }
5378
5379
5380 static int nl80211_put_fils_connect_params(struct wpa_driver_nl80211_data *drv,
5381 struct wpa_driver_associate_params *params,
5382 struct nl_msg *msg)
5383 {
5384 if (params->fils_erp_username_len) {
5385 wpa_hexdump_ascii(MSG_DEBUG, " * FILS ERP EMSKname/username",
5386 params->fils_erp_username,
5387 params->fils_erp_username_len);
5388 if (nla_put(msg, NL80211_ATTR_FILS_ERP_USERNAME,
5389 params->fils_erp_username_len,
5390 params->fils_erp_username))
5391 return -1;
5392 }
5393
5394 if (params->fils_erp_realm_len) {
5395 wpa_hexdump_ascii(MSG_DEBUG, " * FILS ERP Realm",
5396 params->fils_erp_realm,
5397 params->fils_erp_realm_len);
5398 if (nla_put(msg, NL80211_ATTR_FILS_ERP_REALM,
5399 params->fils_erp_realm_len, params->fils_erp_realm))
5400 return -1;
5401 }
5402
5403 wpa_printf(MSG_DEBUG, " * FILS ERP next seq %u",
5404 params->fils_erp_next_seq_num);
5405 if (nla_put_u16(msg, NL80211_ATTR_FILS_ERP_NEXT_SEQ_NUM,
5406 params->fils_erp_next_seq_num))
5407 return -1;
5408
5409 if (params->fils_erp_rrk_len) {
5410 wpa_printf(MSG_DEBUG, " * FILS ERP rRK (len=%lu)",
5411 (unsigned long) params->fils_erp_rrk_len);
5412 if (nla_put(msg, NL80211_ATTR_FILS_ERP_RRK,
5413 params->fils_erp_rrk_len, params->fils_erp_rrk))
5414 return -1;
5415 }
5416
5417 return 0;
5418 }
5419
5420
5421 static int nl80211_connect_common(struct wpa_driver_nl80211_data *drv,
5422 struct wpa_driver_associate_params *params,
5423 struct nl_msg *msg)
5424 {
5425 if (nla_put_flag(msg, NL80211_ATTR_IFACE_SOCKET_OWNER))
5426 return -1;
5427
5428 if (params->bssid) {
5429 wpa_printf(MSG_DEBUG, " * bssid=" MACSTR,
5430 MAC2STR(params->bssid));
5431 if (nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, params->bssid))
5432 return -1;
5433 }
5434
5435 if (params->bssid_hint) {
5436 wpa_printf(MSG_DEBUG, " * bssid_hint=" MACSTR,
5437 MAC2STR(params->bssid_hint));
5438 if (nla_put(msg, NL80211_ATTR_MAC_HINT, ETH_ALEN,
5439 params->bssid_hint))
5440 return -1;
5441 }
5442
5443 if (params->freq.freq) {
5444 wpa_printf(MSG_DEBUG, " * freq=%d", params->freq.freq);
5445 if (nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ,
5446 params->freq.freq))
5447 return -1;
5448 drv->assoc_freq = params->freq.freq;
5449 } else
5450 drv->assoc_freq = 0;
5451
5452 if (params->freq_hint) {
5453 wpa_printf(MSG_DEBUG, " * freq_hint=%d", params->freq_hint);
5454 if (nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ_HINT,
5455 params->freq_hint))
5456 return -1;
5457 }
5458
5459 if (params->bg_scan_period >= 0) {
5460 wpa_printf(MSG_DEBUG, " * bg scan period=%d",
5461 params->bg_scan_period);
5462 if (nla_put_u16(msg, NL80211_ATTR_BG_SCAN_PERIOD,
5463 params->bg_scan_period))
5464 return -1;
5465 }
5466
5467 if (params->ssid) {
5468 wpa_printf(MSG_DEBUG, " * SSID=%s",
5469 wpa_ssid_txt(params->ssid, params->ssid_len));
5470 if (nla_put(msg, NL80211_ATTR_SSID, params->ssid_len,
5471 params->ssid))
5472 return -1;
5473 if (params->ssid_len > sizeof(drv->ssid))
5474 return -1;
5475 os_memcpy(drv->ssid, params->ssid, params->ssid_len);
5476 drv->ssid_len = params->ssid_len;
5477 }
5478
5479 wpa_hexdump(MSG_DEBUG, " * IEs", params->wpa_ie, params->wpa_ie_len);
5480 if (params->wpa_ie &&
5481 nla_put(msg, NL80211_ATTR_IE, params->wpa_ie_len, params->wpa_ie))
5482 return -1;
5483
5484 if (params->wpa_proto) {
5485 enum nl80211_wpa_versions ver = 0;
5486
5487 if (params->wpa_proto & WPA_PROTO_WPA)
5488 ver |= NL80211_WPA_VERSION_1;
5489 if (params->wpa_proto & WPA_PROTO_RSN)
5490 ver |= NL80211_WPA_VERSION_2;
5491
5492 wpa_printf(MSG_DEBUG, " * WPA Versions 0x%x", ver);
5493 if (nla_put_u32(msg, NL80211_ATTR_WPA_VERSIONS, ver))
5494 return -1;
5495 }
5496
5497 if (params->pairwise_suite != WPA_CIPHER_NONE) {
5498 u32 cipher = wpa_cipher_to_cipher_suite(params->pairwise_suite);
5499 wpa_printf(MSG_DEBUG, " * pairwise=0x%x", cipher);
5500 if (nla_put_u32(msg, NL80211_ATTR_CIPHER_SUITES_PAIRWISE,
5501 cipher))
5502 return -1;
5503 }
5504
5505 if (params->group_suite == WPA_CIPHER_GTK_NOT_USED &&
5506 !(drv->capa.enc & WPA_DRIVER_CAPA_ENC_GTK_NOT_USED)) {
5507 /*
5508 * This is likely to work even though many drivers do not
5509 * advertise support for operations without GTK.
5510 */
5511 wpa_printf(MSG_DEBUG, " * skip group cipher configuration for GTK_NOT_USED due to missing driver support advertisement");
5512 } else if (params->group_suite != WPA_CIPHER_NONE) {
5513 u32 cipher = wpa_cipher_to_cipher_suite(params->group_suite);
5514 wpa_printf(MSG_DEBUG, " * group=0x%x", cipher);
5515 if (nla_put_u32(msg, NL80211_ATTR_CIPHER_SUITE_GROUP, cipher))
5516 return -1;
5517 }
5518
5519 if (params->key_mgmt_suite == WPA_KEY_MGMT_IEEE8021X ||
5520 params->key_mgmt_suite == WPA_KEY_MGMT_PSK ||
5521 params->key_mgmt_suite == WPA_KEY_MGMT_FT_IEEE8021X ||
5522 params->key_mgmt_suite == WPA_KEY_MGMT_FT_PSK ||
5523 params->key_mgmt_suite == WPA_KEY_MGMT_CCKM ||
5524 params->key_mgmt_suite == WPA_KEY_MGMT_OSEN ||
5525 params->key_mgmt_suite == WPA_KEY_MGMT_IEEE8021X_SHA256 ||
5526 params->key_mgmt_suite == WPA_KEY_MGMT_PSK_SHA256 ||
5527 params->key_mgmt_suite == WPA_KEY_MGMT_SAE ||
5528 params->key_mgmt_suite == WPA_KEY_MGMT_FT_SAE ||
5529 params->key_mgmt_suite == WPA_KEY_MGMT_IEEE8021X_SUITE_B ||
5530 params->key_mgmt_suite == WPA_KEY_MGMT_IEEE8021X_SUITE_B_192 ||
5531 params->key_mgmt_suite == WPA_KEY_MGMT_FT_IEEE8021X_SHA384 ||
5532 params->key_mgmt_suite == WPA_KEY_MGMT_FILS_SHA256 ||
5533 params->key_mgmt_suite == WPA_KEY_MGMT_FILS_SHA384 ||
5534 params->key_mgmt_suite == WPA_KEY_MGMT_FT_FILS_SHA256 ||
5535 params->key_mgmt_suite == WPA_KEY_MGMT_FT_FILS_SHA384 ||
5536 params->key_mgmt_suite == WPA_KEY_MGMT_OWE ||
5537 params->key_mgmt_suite == WPA_KEY_MGMT_DPP) {
5538 int mgmt = RSN_AUTH_KEY_MGMT_PSK_OVER_802_1X;
5539
5540 switch (params->key_mgmt_suite) {
5541 case WPA_KEY_MGMT_CCKM:
5542 mgmt = RSN_AUTH_KEY_MGMT_CCKM;
5543 break;
5544 case WPA_KEY_MGMT_IEEE8021X:
5545 mgmt = RSN_AUTH_KEY_MGMT_UNSPEC_802_1X;
5546 break;
5547 case WPA_KEY_MGMT_FT_IEEE8021X:
5548 mgmt = RSN_AUTH_KEY_MGMT_FT_802_1X;
5549 break;
5550 case WPA_KEY_MGMT_FT_PSK:
5551 mgmt = RSN_AUTH_KEY_MGMT_FT_PSK;
5552 break;
5553 case WPA_KEY_MGMT_IEEE8021X_SHA256:
5554 mgmt = RSN_AUTH_KEY_MGMT_802_1X_SHA256;
5555 break;
5556 case WPA_KEY_MGMT_PSK_SHA256:
5557 mgmt = RSN_AUTH_KEY_MGMT_PSK_SHA256;
5558 break;
5559 case WPA_KEY_MGMT_OSEN:
5560 mgmt = RSN_AUTH_KEY_MGMT_OSEN;
5561 break;
5562 case WPA_KEY_MGMT_SAE:
5563 mgmt = RSN_AUTH_KEY_MGMT_SAE;
5564 break;
5565 case WPA_KEY_MGMT_FT_SAE:
5566 mgmt = RSN_AUTH_KEY_MGMT_FT_SAE;
5567 break;
5568 case WPA_KEY_MGMT_IEEE8021X_SUITE_B:
5569 mgmt = RSN_AUTH_KEY_MGMT_802_1X_SUITE_B;
5570 break;
5571 case WPA_KEY_MGMT_IEEE8021X_SUITE_B_192:
5572 mgmt = RSN_AUTH_KEY_MGMT_802_1X_SUITE_B_192;
5573 break;
5574 case WPA_KEY_MGMT_FT_IEEE8021X_SHA384:
5575 mgmt = RSN_AUTH_KEY_MGMT_FT_802_1X_SHA384;
5576 break;
5577 case WPA_KEY_MGMT_FILS_SHA256:
5578 mgmt = RSN_AUTH_KEY_MGMT_FILS_SHA256;
5579 break;
5580 case WPA_KEY_MGMT_FILS_SHA384:
5581 mgmt = RSN_AUTH_KEY_MGMT_FILS_SHA384;
5582 break;
5583 case WPA_KEY_MGMT_FT_FILS_SHA256:
5584 mgmt = RSN_AUTH_KEY_MGMT_FT_FILS_SHA256;
5585 break;
5586 case WPA_KEY_MGMT_FT_FILS_SHA384:
5587 mgmt = RSN_AUTH_KEY_MGMT_FT_FILS_SHA384;
5588 break;
5589 case WPA_KEY_MGMT_OWE:
5590 mgmt = RSN_AUTH_KEY_MGMT_OWE;
5591 break;
5592 case WPA_KEY_MGMT_DPP:
5593 mgmt = RSN_AUTH_KEY_MGMT_DPP;
5594 break;
5595 case WPA_KEY_MGMT_PSK:
5596 default:
5597 mgmt = RSN_AUTH_KEY_MGMT_PSK_OVER_802_1X;
5598 break;
5599 }
5600 wpa_printf(MSG_DEBUG, " * akm=0x%x", mgmt);
5601 if (nla_put_u32(msg, NL80211_ATTR_AKM_SUITES, mgmt))
5602 return -1;
5603 }
5604
5605 if (params->req_key_mgmt_offload &&
5606 (drv->capa.flags & WPA_DRIVER_FLAGS_4WAY_HANDSHAKE_8021X)) {
5607 wpa_printf(MSG_DEBUG, " * WANT_1X_4WAY_HS");
5608 if (nla_put_flag(msg, NL80211_ATTR_WANT_1X_4WAY_HS))
5609 return -1;
5610 }
5611
5612 /* Add PSK in case of 4-way handshake offload */
5613 if (params->psk &&
5614 (drv->capa.flags & WPA_DRIVER_FLAGS_4WAY_HANDSHAKE_PSK)) {
5615 wpa_hexdump_key(MSG_DEBUG, " * PSK", params->psk, 32);
5616 if (nla_put(msg, NL80211_ATTR_PMK, 32, params->psk))
5617 return -1;
5618 }
5619
5620 if (nla_put_flag(msg, NL80211_ATTR_CONTROL_PORT))
5621 return -1;
5622
5623 if (params->key_mgmt_suite == WPA_KEY_MGMT_IEEE8021X_NO_WPA &&
5624 (params->pairwise_suite == WPA_CIPHER_NONE ||
5625 params->pairwise_suite == WPA_CIPHER_WEP104 ||
5626 params->pairwise_suite == WPA_CIPHER_WEP40) &&
5627 (nla_put_u16(msg, NL80211_ATTR_CONTROL_PORT_ETHERTYPE, ETH_P_PAE) ||
5628 nla_put_flag(msg, NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT)))
5629 return -1;
5630
5631 if (params->rrm_used) {
5632 u32 drv_rrm_flags = drv->capa.rrm_flags;
5633 if ((!((drv_rrm_flags &
5634 WPA_DRIVER_FLAGS_DS_PARAM_SET_IE_IN_PROBES) &&
5635 (drv_rrm_flags & WPA_DRIVER_FLAGS_QUIET)) &&
5636 !(drv_rrm_flags & WPA_DRIVER_FLAGS_SUPPORT_RRM)) ||
5637 nla_put_flag(msg, NL80211_ATTR_USE_RRM))
5638 return -1;
5639 }
5640
5641 if (nl80211_ht_vht_overrides(msg, params) < 0)
5642 return -1;
5643
5644 if (params->p2p)
5645 wpa_printf(MSG_DEBUG, " * P2P group");
5646
5647 if (params->pbss) {
5648 wpa_printf(MSG_DEBUG, " * PBSS");
5649 if (nla_put_flag(msg, NL80211_ATTR_PBSS))
5650 return -1;
5651 }
5652
5653 drv->connect_reassoc = 0;
5654 if (params->prev_bssid) {
5655 wpa_printf(MSG_DEBUG, " * prev_bssid=" MACSTR,
5656 MAC2STR(params->prev_bssid));
5657 if (nla_put(msg, NL80211_ATTR_PREV_BSSID, ETH_ALEN,
5658 params->prev_bssid))
5659 return -1;
5660 drv->connect_reassoc = 1;
5661 }
5662
5663 if ((params->auth_alg & WPA_AUTH_ALG_FILS) &&
5664 nl80211_put_fils_connect_params(drv, params, msg) != 0)
5665 return -1;
5666
5667 if ((params->auth_alg & WPA_AUTH_ALG_SAE) &&
5668 (!(drv->capa.flags & WPA_DRIVER_FLAGS_SME)) &&
5669 nla_put_flag(msg, NL80211_ATTR_EXTERNAL_AUTH_SUPPORT))
5670 return -1;
5671
5672 return 0;
5673 }
5674
5675
5676 static int wpa_driver_nl80211_try_connect(
5677 struct wpa_driver_nl80211_data *drv,
5678 struct wpa_driver_associate_params *params,
5679 struct nl_handle *nl_connect)
5680 {
5681 struct nl_msg *msg;
5682 enum nl80211_auth_type type;
5683 int ret;
5684 int algs;
5685
5686 #ifdef CONFIG_DRIVER_NL80211_QCA
5687 if (params->req_key_mgmt_offload && params->psk &&
5688 (params->key_mgmt_suite == WPA_KEY_MGMT_PSK ||
5689 params->key_mgmt_suite == WPA_KEY_MGMT_PSK_SHA256 ||
5690 params->key_mgmt_suite == WPA_KEY_MGMT_FT_PSK)) {
5691 wpa_printf(MSG_DEBUG, "nl80211: Key management set PSK");
5692 ret = issue_key_mgmt_set_key(drv, params->psk, 32);
5693 if (ret)
5694 return ret;
5695 }
5696 #endif /* CONFIG_DRIVER_NL80211_QCA */
5697
5698 wpa_printf(MSG_DEBUG, "nl80211: Connect (ifindex=%d)", drv->ifindex);
5699 msg = nl80211_drv_msg(drv, 0, NL80211_CMD_CONNECT);
5700 if (!msg)
5701 return -1;
5702
5703 ret = nl80211_connect_common(drv, params, msg);
5704 if (ret)
5705 goto fail;
5706
5707 if (params->mgmt_frame_protection == MGMT_FRAME_PROTECTION_REQUIRED &&
5708 nla_put_u32(msg, NL80211_ATTR_USE_MFP, NL80211_MFP_REQUIRED))
5709 goto fail;
5710
5711 if (params->mgmt_frame_protection == MGMT_FRAME_PROTECTION_OPTIONAL &&
5712 (drv->capa.flags & WPA_DRIVER_FLAGS_MFP_OPTIONAL) &&
5713 nla_put_u32(msg, NL80211_ATTR_USE_MFP, NL80211_MFP_OPTIONAL))
5714 goto fail;
5715
5716 algs = 0;
5717 if (params->auth_alg & WPA_AUTH_ALG_OPEN)
5718 algs++;
5719 if (params->auth_alg & WPA_AUTH_ALG_SHARED)
5720 algs++;
5721 if (params->auth_alg & WPA_AUTH_ALG_LEAP)
5722 algs++;
5723 if (params->auth_alg & WPA_AUTH_ALG_FILS)
5724 algs++;
5725 if (params->auth_alg & WPA_AUTH_ALG_FT)
5726 algs++;
5727 if (algs > 1) {
5728 wpa_printf(MSG_DEBUG, " * Leave out Auth Type for automatic "
5729 "selection");
5730 goto skip_auth_type;
5731 }
5732
5733 type = get_nl_auth_type(params->auth_alg);
5734 wpa_printf(MSG_DEBUG, " * Auth Type %d", type);
5735 if (type == NL80211_AUTHTYPE_MAX ||
5736 nla_put_u32(msg, NL80211_ATTR_AUTH_TYPE, type))
5737 goto fail;
5738
5739 skip_auth_type:
5740 ret = nl80211_set_conn_keys(params, msg);
5741 if (ret)
5742 goto fail;
5743
5744 if (nl_connect)
5745 ret = send_and_recv(drv->global, nl_connect, msg,
5746 NULL, (void *) -1);
5747 else
5748 ret = send_and_recv_msgs(drv, msg, NULL, (void *) -1);
5749
5750 msg = NULL;
5751 if (ret) {
5752 wpa_printf(MSG_DEBUG, "nl80211: MLME connect failed: ret=%d "
5753 "(%s)", ret, strerror(-ret));
5754 } else {
5755 wpa_printf(MSG_DEBUG,
5756 "nl80211: Connect request send successfully");
5757 }
5758
5759 fail:
5760 nl80211_nlmsg_clear(msg);
5761 nlmsg_free(msg);
5762 return ret;
5763
5764 }
5765
5766
5767 static int wpa_driver_nl80211_connect(
5768 struct wpa_driver_nl80211_data *drv,
5769 struct wpa_driver_associate_params *params,
5770 struct nl_handle *nl_connect)
5771 {
5772 int ret;
5773
5774 /* Store the connection attempted bssid for future use */
5775 if (params->bssid)
5776 os_memcpy(drv->auth_attempt_bssid, params->bssid, ETH_ALEN);
5777 else
5778 os_memset(drv->auth_attempt_bssid, 0, ETH_ALEN);
5779
5780 ret = wpa_driver_nl80211_try_connect(drv, params, nl_connect);
5781 if (ret == -EALREADY) {
5782 /*
5783 * cfg80211 does not currently accept new connections if
5784 * we are already connected. As a workaround, force
5785 * disconnection and try again.
5786 */
5787 wpa_printf(MSG_DEBUG, "nl80211: Explicitly "
5788 "disconnecting before reassociation "
5789 "attempt");
5790 if (wpa_driver_nl80211_disconnect(
5791 drv, WLAN_REASON_PREV_AUTH_NOT_VALID, nl_connect))
5792 return -1;
5793 ret = wpa_driver_nl80211_try_connect(drv, params, nl_connect);
5794 }
5795 return ret;
5796 }
5797
5798
5799 static int wpa_driver_nl80211_associate(
5800 void *priv, struct wpa_driver_associate_params *params)
5801 {
5802 struct i802_bss *bss = priv;
5803 struct wpa_driver_nl80211_data *drv = bss->drv;
5804 int ret = -1;
5805 struct nl_msg *msg;
5806
5807 nl80211_unmask_11b_rates(bss);
5808
5809 if (params->mode == IEEE80211_MODE_AP)
5810 return wpa_driver_nl80211_ap(drv, params);
5811
5812 if (params->mode == IEEE80211_MODE_IBSS)
5813 return wpa_driver_nl80211_ibss(drv, params);
5814
5815 if (!(drv->capa.flags & WPA_DRIVER_FLAGS_SME)) {
5816 enum nl80211_iftype nlmode = params->p2p ?
5817 NL80211_IFTYPE_P2P_CLIENT : NL80211_IFTYPE_STATION;
5818 struct nl_handle *nl_connect = NULL;
5819
5820 if (wpa_driver_nl80211_set_mode(priv, nlmode) < 0)
5821 return -1;
5822 if (params->auth_alg & WPA_AUTH_ALG_SAE) {
5823 nl_connect = bss->nl_connect;
5824 bss->use_nl_connect = 1;
5825 } else {
5826 bss->use_nl_connect = 0;
5827 }
5828
5829 return wpa_driver_nl80211_connect(drv, params, nl_connect);
5830 }
5831
5832 nl80211_mark_disconnected(drv);
5833
5834 wpa_printf(MSG_DEBUG, "nl80211: Associate (ifindex=%d)",
5835 drv->ifindex);
5836 msg = nl80211_drv_msg(drv, 0, NL80211_CMD_ASSOCIATE);
5837 if (!msg)
5838 return -1;
5839
5840 ret = nl80211_connect_common(drv, params, msg);
5841 if (ret)
5842 goto fail;
5843
5844 if (params->mgmt_frame_protection == MGMT_FRAME_PROTECTION_REQUIRED &&
5845 nla_put_u32(msg, NL80211_ATTR_USE_MFP, NL80211_MFP_REQUIRED))
5846 goto fail;
5847
5848 if (params->fils_kek) {
5849 wpa_printf(MSG_DEBUG, " * FILS KEK (len=%u)",
5850 (unsigned int) params->fils_kek_len);
5851 if (nla_put(msg, NL80211_ATTR_FILS_KEK, params->fils_kek_len,
5852 params->fils_kek))
5853 goto fail;
5854 }
5855 if (params->fils_nonces) {
5856 wpa_hexdump(MSG_DEBUG, " * FILS nonces (for AAD)",
5857 params->fils_nonces,
5858 params->fils_nonces_len);
5859 if (nla_put(msg, NL80211_ATTR_FILS_NONCES,
5860 params->fils_nonces_len, params->fils_nonces))
5861 goto fail;
5862 }
5863
5864 ret = send_and_recv_msgs(drv, msg, NULL, NULL);
5865 msg = NULL;
5866 if (ret) {
5867 wpa_dbg(drv->ctx, MSG_DEBUG,
5868 "nl80211: MLME command failed (assoc): ret=%d (%s)",
5869 ret, strerror(-ret));
5870 nl80211_dump_scan(drv);
5871 } else {
5872 wpa_printf(MSG_DEBUG,
5873 "nl80211: Association request send successfully");
5874 }
5875
5876 fail:
5877 nlmsg_free(msg);
5878 return ret;
5879 }
5880
5881
5882 static int nl80211_set_mode(struct wpa_driver_nl80211_data *drv,
5883 int ifindex, enum nl80211_iftype mode)
5884 {
5885 struct nl_msg *msg;
5886 int ret = -ENOBUFS;
5887
5888 wpa_printf(MSG_DEBUG, "nl80211: Set mode ifindex %d iftype %d (%s)",
5889 ifindex, mode, nl80211_iftype_str(mode));
5890
5891 msg = nl80211_cmd_msg(drv->first_bss, 0, NL80211_CMD_SET_INTERFACE);
5892 if (!msg || nla_put_u32(msg, NL80211_ATTR_IFTYPE, mode))
5893 goto fail;
5894
5895 ret = send_and_recv_msgs(drv, msg, NULL, NULL);
5896 msg = NULL;
5897 if (!ret)
5898 return 0;
5899 fail:
5900 nlmsg_free(msg);
5901 wpa_printf(MSG_DEBUG, "nl80211: Failed to set interface %d to mode %d:"
5902 " %d (%s)", ifindex, mode, ret, strerror(-ret));
5903 return ret;
5904 }
5905
5906
5907 static int wpa_driver_nl80211_set_mode_impl(
5908 struct i802_bss *bss,
5909 enum nl80211_iftype nlmode,
5910 struct hostapd_freq_params *desired_freq_params)
5911 {
5912 struct wpa_driver_nl80211_data *drv = bss->drv;
5913 int ret = -1;
5914 int i;
5915 int was_ap = is_ap_interface(drv->nlmode);
5916 int res;
5917 int mode_switch_res;
5918
5919 if (TEST_FAIL())
5920 return -1;
5921
5922 mode_switch_res = nl80211_set_mode(drv, drv->ifindex, nlmode);
5923 if (mode_switch_res && nlmode == nl80211_get_ifmode(bss))
5924 mode_switch_res = 0;
5925
5926 if (mode_switch_res == 0) {
5927 drv->nlmode = nlmode;
5928 ret = 0;
5929 goto done;
5930 }
5931
5932 if (mode_switch_res == -ENODEV)
5933 return -1;
5934
5935 if (nlmode == drv->nlmode) {
5936 wpa_printf(MSG_DEBUG, "nl80211: Interface already in "
5937 "requested mode - ignore error");
5938 ret = 0;
5939 goto done; /* Already in the requested mode */
5940 }
5941
5942 /* mac80211 doesn't allow mode changes while the device is up, so
5943 * take the device down, try to set the mode again, and bring the
5944 * device back up.
5945 */
5946 wpa_printf(MSG_DEBUG, "nl80211: Try mode change after setting "
5947 "interface down");
5948 for (i = 0; i < 10; i++) {
5949 res = i802_set_iface_flags(bss, 0);
5950 if (res == -EACCES || res == -ENODEV)
5951 break;
5952 if (res != 0) {
5953 wpa_printf(MSG_DEBUG, "nl80211: Failed to set "
5954 "interface down");
5955 os_sleep(0, 100000);
5956 continue;
5957 }
5958
5959 /*
5960 * Setting the mode will fail for some drivers if the phy is
5961 * on a frequency that the mode is disallowed in.
5962 */
5963 if (desired_freq_params) {
5964 res = nl80211_set_channel(bss, desired_freq_params, 0);
5965 if (res) {
5966 wpa_printf(MSG_DEBUG,
5967 "nl80211: Failed to set frequency on interface");
5968 }
5969 }
5970
5971 /* Try to set the mode again while the interface is down */
5972 mode_switch_res = nl80211_set_mode(drv, drv->ifindex, nlmode);
5973 if (mode_switch_res == -EBUSY) {
5974 wpa_printf(MSG_DEBUG,
5975 "nl80211: Delaying mode set while interface going down");
5976 os_sleep(0, 100000);
5977 continue;
5978 }
5979 ret = mode_switch_res;
5980 break;
5981 }
5982
5983 if (!ret) {
5984 wpa_printf(MSG_DEBUG, "nl80211: Mode change succeeded while "
5985 "interface is down");
5986 drv->nlmode = nlmode;
5987 drv->ignore_if_down_event = 1;
5988 }
5989
5990 /* Bring the interface back up */
5991 res = linux_set_iface_flags(drv->global->ioctl_sock, bss->ifname, 1);
5992 if (res != 0) {
5993 wpa_printf(MSG_DEBUG,
5994 "nl80211: Failed to set interface up after switching mode");
5995 ret = -1;
5996 }
5997
5998 done:
5999 if (ret) {
6000 wpa_printf(MSG_DEBUG, "nl80211: Interface mode change to %d "
6001 "from %d failed", nlmode, drv->nlmode);
6002 return ret;
6003 }
6004
6005 if (is_p2p_net_interface(nlmode)) {
6006 wpa_printf(MSG_DEBUG,
6007 "nl80211: Interface %s mode change to P2P - disable 11b rates",
6008 bss->ifname);
6009 nl80211_disable_11b_rates(drv, drv->ifindex, 1);
6010 } else if (drv->disabled_11b_rates) {
6011 wpa_printf(MSG_DEBUG,
6012 "nl80211: Interface %s mode changed to non-P2P - re-enable 11b rates",
6013 bss->ifname);
6014 nl80211_disable_11b_rates(drv, drv->ifindex, 0);
6015 }
6016
6017 if (is_ap_interface(nlmode)) {
6018 nl80211_mgmt_unsubscribe(bss, "start AP");
6019 /* Setup additional AP mode functionality if needed */
6020 if (nl80211_setup_ap(bss))
6021 return -1;
6022 } else if (was_ap) {
6023 /* Remove additional AP mode functionality */
6024 nl80211_teardown_ap(bss);
6025 } else {
6026 nl80211_mgmt_unsubscribe(bss, "mode change");
6027 }
6028
6029 if (is_mesh_interface(nlmode) &&
6030 nl80211_mgmt_subscribe_mesh(bss))
6031 return -1;
6032
6033 if (!bss->in_deinit && !is_ap_interface(nlmode) &&
6034 !is_mesh_interface(nlmode) &&
6035 nl80211_mgmt_subscribe_non_ap(bss) < 0)
6036 wpa_printf(MSG_DEBUG, "nl80211: Failed to register Action "
6037 "frame processing - ignore for now");
6038
6039 return 0;
6040 }
6041
6042
6043 int wpa_driver_nl80211_set_mode(struct i802_bss *bss,
6044 enum nl80211_iftype nlmode)
6045 {
6046 return wpa_driver_nl80211_set_mode_impl(bss, nlmode, NULL);
6047 }
6048
6049
6050 static int wpa_driver_nl80211_set_mode_ibss(struct i802_bss *bss,
6051 struct hostapd_freq_params *freq)
6052 {
6053 return wpa_driver_nl80211_set_mode_impl(bss, NL80211_IFTYPE_ADHOC,
6054 freq);
6055 }
6056
6057
6058 static int wpa_driver_nl80211_get_capa(void *priv,
6059 struct wpa_driver_capa *capa)
6060 {
6061 struct i802_bss *bss = priv;
6062 struct wpa_driver_nl80211_data *drv = bss->drv;
6063
6064 if (!drv->has_capability)
6065 return -1;
6066 os_memcpy(capa, &drv->capa, sizeof(*capa));
6067 if (drv->extended_capa && drv->extended_capa_mask) {
6068 capa->extended_capa = drv->extended_capa;
6069 capa->extended_capa_mask = drv->extended_capa_mask;
6070 capa->extended_capa_len = drv->extended_capa_len;
6071 }
6072
6073 return 0;
6074 }
6075
6076
6077 static int wpa_driver_nl80211_set_operstate(void *priv, int state)
6078 {
6079 struct i802_bss *bss = priv;
6080 struct wpa_driver_nl80211_data *drv = bss->drv;
6081
6082 wpa_printf(MSG_DEBUG, "nl80211: Set %s operstate %d->%d (%s)",
6083 bss->ifname, drv->operstate, state,
6084 state ? "UP" : "DORMANT");
6085 drv->operstate = state;
6086 return netlink_send_oper_ifla(drv->global->netlink, drv->ifindex, -1,
6087 state ? IF_OPER_UP : IF_OPER_DORMANT);
6088 }
6089
6090
6091 static int wpa_driver_nl80211_set_supp_port(void *priv, int authorized)
6092 {
6093 struct i802_bss *bss = priv;
6094 struct wpa_driver_nl80211_data *drv = bss->drv;
6095 struct nl_msg *msg;
6096 struct nl80211_sta_flag_update upd;
6097 int ret;
6098
6099 if (!drv->associated && is_zero_ether_addr(drv->bssid) && !authorized) {
6100 wpa_printf(MSG_DEBUG, "nl80211: Skip set_supp_port(unauthorized) while not associated");
6101 return 0;
6102 }
6103
6104 wpa_printf(MSG_DEBUG, "nl80211: Set supplicant port %sauthorized for "
6105 MACSTR, authorized ? "" : "un", MAC2STR(drv->bssid));
6106
6107 os_memset(&upd, 0, sizeof(upd));
6108 upd.mask = BIT(NL80211_STA_FLAG_AUTHORIZED);
6109 if (authorized)
6110 upd.set = BIT(NL80211_STA_FLAG_AUTHORIZED);
6111
6112 if (!(msg = nl80211_bss_msg(bss, 0, NL80211_CMD_SET_STATION)) ||
6113 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, drv->bssid) ||
6114 nla_put(msg, NL80211_ATTR_STA_FLAGS2, sizeof(upd), &upd)) {
6115 nlmsg_free(msg);
6116 return -ENOBUFS;
6117 }
6118
6119 ret = send_and_recv_msgs(drv, msg, NULL, NULL);
6120 if (!ret)
6121 return 0;
6122 wpa_printf(MSG_DEBUG, "nl80211: Failed to set STA flag: %d (%s)",
6123 ret, strerror(-ret));
6124 return ret;
6125 }
6126
6127
6128 /* Set kernel driver on given frequency (MHz) */
6129 static int i802_set_freq(void *priv, struct hostapd_freq_params *freq)
6130 {
6131 struct i802_bss *bss = priv;
6132 return nl80211_set_channel(bss, freq, 0);
6133 }
6134
6135
6136 static inline int min_int(int a, int b)
6137 {
6138 if (a < b)
6139 return a;
6140 return b;
6141 }
6142
6143
6144 static int get_key_handler(struct nl_msg *msg, void *arg)
6145 {
6146 struct nlattr *tb[NL80211_ATTR_MAX + 1];
6147 struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg));
6148
6149 nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0),
6150 genlmsg_attrlen(gnlh, 0), NULL);
6151
6152 /*
6153 * TODO: validate the key index and mac address!
6154 * Otherwise, there's a race condition as soon as
6155 * the kernel starts sending key notifications.
6156 */
6157
6158 if (tb[NL80211_ATTR_KEY_SEQ])
6159 memcpy(arg, nla_data(tb[NL80211_ATTR_KEY_SEQ]),
6160 min_int(nla_len(tb[NL80211_ATTR_KEY_SEQ]), 6));
6161 nl80211_nlmsg_clear(msg);
6162 return NL_SKIP;
6163 }
6164
6165
6166 static int i802_get_seqnum(const char *iface, void *priv, const u8 *addr,
6167 int idx, u8 *seq)
6168 {
6169 struct i802_bss *bss = priv;
6170 struct wpa_driver_nl80211_data *drv = bss->drv;
6171 struct nl_msg *msg;
6172
6173 msg = nl80211_ifindex_msg(drv, if_nametoindex(iface), 0,
6174 NL80211_CMD_GET_KEY);
6175 if (!msg ||
6176 (addr && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) ||
6177 nla_put_u8(msg, NL80211_ATTR_KEY_IDX, idx)) {
6178 nlmsg_free(msg);
6179 return -ENOBUFS;
6180 }
6181
6182 memset(seq, 0, 6);
6183
6184 return send_and_recv_msgs(drv, msg, get_key_handler, seq);
6185 }
6186
6187
6188 static int i802_set_rts(void *priv, int rts)
6189 {
6190 struct i802_bss *bss = priv;
6191 struct wpa_driver_nl80211_data *drv = bss->drv;
6192 struct nl_msg *msg;
6193 int ret;
6194 u32 val;
6195
6196 if (rts >= 2347 || rts == -1)
6197 val = (u32) -1;
6198 else
6199 val = rts;
6200
6201 if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_SET_WIPHY)) ||
6202 nla_put_u32(msg, NL80211_ATTR_WIPHY_RTS_THRESHOLD, val)) {
6203 nlmsg_free(msg);
6204 return -ENOBUFS;
6205 }
6206
6207 ret = send_and_recv_msgs(drv, msg, NULL, NULL);
6208 if (!ret)
6209 return 0;
6210 wpa_printf(MSG_DEBUG, "nl80211: Failed to set RTS threshold %d: "
6211 "%d (%s)", rts, ret, strerror(-ret));
6212 return ret;
6213 }
6214
6215
6216 static int i802_set_frag(void *priv, int frag)
6217 {
6218 struct i802_bss *bss = priv;
6219 struct wpa_driver_nl80211_data *drv = bss->drv;
6220 struct nl_msg *msg;
6221 int ret;
6222 u32 val;
6223
6224 if (frag >= 2346 || frag == -1)
6225 val = (u32) -1;
6226 else
6227 val = frag;
6228
6229 if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_SET_WIPHY)) ||
6230 nla_put_u32(msg, NL80211_ATTR_WIPHY_FRAG_THRESHOLD, val)) {
6231 nlmsg_free(msg);
6232 return -ENOBUFS;
6233 }
6234
6235 ret = send_and_recv_msgs(drv, msg, NULL, NULL);
6236 if (!ret)
6237 return 0;
6238 wpa_printf(MSG_DEBUG, "nl80211: Failed to set fragmentation threshold "
6239 "%d: %d (%s)", frag, ret, strerror(-ret));
6240 return ret;
6241 }
6242
6243
6244 static int i802_flush(void *priv)
6245 {
6246 struct i802_bss *bss = priv;
6247 struct nl_msg *msg;
6248 int res;
6249
6250 wpa_printf(MSG_DEBUG, "nl80211: flush -> DEL_STATION %s (all)",
6251 bss->ifname);
6252
6253 /*
6254 * XXX: FIX! this needs to flush all VLANs too
6255 */
6256 msg = nl80211_bss_msg(bss, 0, NL80211_CMD_DEL_STATION);
6257 res = send_and_recv_msgs(bss->drv, msg, NULL, NULL);
6258 if (res) {
6259 wpa_printf(MSG_DEBUG, "nl80211: Station flush failed: ret=%d "
6260 "(%s)", res, strerror(-res));
6261 }
6262 return res;
6263 }
6264
6265
6266 static int get_sta_handler(struct nl_msg *msg, void *arg)
6267 {
6268 struct nlattr *tb[NL80211_ATTR_MAX + 1];
6269 struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg));
6270 struct hostap_sta_driver_data *data = arg;
6271 struct nlattr *stats[NL80211_STA_INFO_MAX + 1];
6272 static struct nla_policy stats_policy[NL80211_STA_INFO_MAX + 1] = {
6273 [NL80211_STA_INFO_INACTIVE_TIME] = { .type = NLA_U32 },
6274 [NL80211_STA_INFO_RX_BYTES] = { .type = NLA_U32 },
6275 [NL80211_STA_INFO_TX_BYTES] = { .type = NLA_U32 },
6276 [NL80211_STA_INFO_RX_PACKETS] = { .type = NLA_U32 },
6277 [NL80211_STA_INFO_TX_PACKETS] = { .type = NLA_U32 },
6278 [NL80211_STA_INFO_TX_FAILED] = { .type = NLA_U32 },
6279 [NL80211_STA_INFO_RX_BYTES64] = { .type = NLA_U64 },
6280 [NL80211_STA_INFO_TX_BYTES64] = { .type = NLA_U64 },
6281 [NL80211_STA_INFO_SIGNAL] = { .type = NLA_U8 },
6282 [NL80211_STA_INFO_ACK_SIGNAL] = { .type = NLA_U8 },
6283 };
6284 struct nlattr *rate[NL80211_RATE_INFO_MAX + 1];
6285 static struct nla_policy rate_policy[NL80211_RATE_INFO_MAX + 1] = {
6286 [NL80211_RATE_INFO_BITRATE] = { .type = NLA_U16 },
6287 [NL80211_RATE_INFO_BITRATE32] = { .type = NLA_U32 },
6288 [NL80211_RATE_INFO_MCS] = { .type = NLA_U8 },
6289 [NL80211_RATE_INFO_VHT_MCS] = { .type = NLA_U8 },
6290 [NL80211_RATE_INFO_SHORT_GI] = { .type = NLA_FLAG },
6291 [NL80211_RATE_INFO_VHT_NSS] = { .type = NLA_U8 },
6292 };
6293
6294 nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0),
6295 genlmsg_attrlen(gnlh, 0), NULL);
6296
6297 /*
6298 * TODO: validate the interface and mac address!
6299 * Otherwise, there's a race condition as soon as
6300 * the kernel starts sending station notifications.
6301 */
6302
6303 if (!tb[NL80211_ATTR_STA_INFO]) {
6304 wpa_printf(MSG_DEBUG, "sta stats missing!");
6305 return NL_SKIP;
6306 }
6307 if (nla_parse_nested(stats, NL80211_STA_INFO_MAX,
6308 tb[NL80211_ATTR_STA_INFO],
6309 stats_policy)) {
6310 wpa_printf(MSG_DEBUG, "failed to parse nested attributes!");
6311 return NL_SKIP;
6312 }
6313
6314 if (stats[NL80211_STA_INFO_INACTIVE_TIME])
6315 data->inactive_msec =
6316 nla_get_u32(stats[NL80211_STA_INFO_INACTIVE_TIME]);
6317 /* For backwards compatibility, fetch the 32-bit counters first. */
6318 if (stats[NL80211_STA_INFO_RX_BYTES])
6319 data->rx_bytes = nla_get_u32(stats[NL80211_STA_INFO_RX_BYTES]);
6320 if (stats[NL80211_STA_INFO_TX_BYTES])
6321 data->tx_bytes = nla_get_u32(stats[NL80211_STA_INFO_TX_BYTES]);
6322 if (stats[NL80211_STA_INFO_RX_BYTES64] &&
6323 stats[NL80211_STA_INFO_TX_BYTES64]) {
6324 /*
6325 * The driver supports 64-bit counters, so use them to override
6326 * the 32-bit values.
6327 */
6328 data->rx_bytes =
6329 nla_get_u64(stats[NL80211_STA_INFO_RX_BYTES64]);
6330 data->tx_bytes =
6331 nla_get_u64(stats[NL80211_STA_INFO_TX_BYTES64]);
6332 data->bytes_64bit = 1;
6333 }
6334 if (stats[NL80211_STA_INFO_RX_PACKETS])
6335 data->rx_packets =
6336 nla_get_u32(stats[NL80211_STA_INFO_RX_PACKETS]);
6337 if (stats[NL80211_STA_INFO_TX_PACKETS])
6338 data->tx_packets =
6339 nla_get_u32(stats[NL80211_STA_INFO_TX_PACKETS]);
6340 if (stats[NL80211_STA_INFO_TX_FAILED])
6341 data->tx_retry_failed =
6342 nla_get_u32(stats[NL80211_STA_INFO_TX_FAILED]);
6343 if (stats[NL80211_STA_INFO_SIGNAL])
6344 data->signal = nla_get_u8(stats[NL80211_STA_INFO_SIGNAL]);
6345 if (stats[NL80211_STA_INFO_ACK_SIGNAL]) {
6346 data->last_ack_rssi =
6347 nla_get_u8(stats[NL80211_STA_INFO_ACK_SIGNAL]);
6348 data->flags |= STA_DRV_DATA_LAST_ACK_RSSI;
6349 }
6350
6351 if (stats[NL80211_STA_INFO_TX_BITRATE] &&
6352 nla_parse_nested(rate, NL80211_RATE_INFO_MAX,
6353 stats[NL80211_STA_INFO_TX_BITRATE],
6354 rate_policy) == 0) {
6355 if (rate[NL80211_RATE_INFO_BITRATE32])
6356 data->current_tx_rate =
6357 nla_get_u32(rate[NL80211_RATE_INFO_BITRATE32]);
6358 else if (rate[NL80211_RATE_INFO_BITRATE])
6359 data->current_tx_rate =
6360 nla_get_u16(rate[NL80211_RATE_INFO_BITRATE]);
6361
6362 if (rate[NL80211_RATE_INFO_MCS]) {
6363 data->tx_mcs = nla_get_u8(rate[NL80211_RATE_INFO_MCS]);
6364 data->flags |= STA_DRV_DATA_TX_MCS;
6365 }
6366 if (rate[NL80211_RATE_INFO_VHT_MCS]) {
6367 data->tx_vhtmcs =
6368 nla_get_u8(rate[NL80211_RATE_INFO_VHT_MCS]);
6369 data->flags |= STA_DRV_DATA_TX_VHT_MCS;
6370 }
6371 if (rate[NL80211_RATE_INFO_SHORT_GI])
6372 data->flags |= STA_DRV_DATA_TX_SHORT_GI;
6373 if (rate[NL80211_RATE_INFO_VHT_NSS]) {
6374 data->tx_vht_nss =
6375 nla_get_u8(rate[NL80211_RATE_INFO_VHT_NSS]);
6376 data->flags |= STA_DRV_DATA_TX_VHT_NSS;
6377 }
6378 }
6379
6380 if (stats[NL80211_STA_INFO_RX_BITRATE] &&
6381 nla_parse_nested(rate, NL80211_RATE_INFO_MAX,
6382 stats[NL80211_STA_INFO_RX_BITRATE],
6383 rate_policy) == 0) {
6384 if (rate[NL80211_RATE_INFO_BITRATE32])
6385 data->current_rx_rate =
6386 nla_get_u32(rate[NL80211_RATE_INFO_BITRATE32]);
6387 else if (rate[NL80211_RATE_INFO_BITRATE])
6388 data->current_rx_rate =
6389 nla_get_u16(rate[NL80211_RATE_INFO_BITRATE]);
6390
6391 if (rate[NL80211_RATE_INFO_MCS]) {
6392 data->rx_mcs =
6393 nla_get_u8(rate[NL80211_RATE_INFO_MCS]);
6394 data->flags |= STA_DRV_DATA_RX_MCS;
6395 }
6396 if (rate[NL80211_RATE_INFO_VHT_MCS]) {
6397 data->rx_vhtmcs =
6398 nla_get_u8(rate[NL80211_RATE_INFO_VHT_MCS]);
6399 data->flags |= STA_DRV_DATA_RX_VHT_MCS;
6400 }
6401 if (rate[NL80211_RATE_INFO_SHORT_GI])
6402 data->flags |= STA_DRV_DATA_RX_SHORT_GI;
6403 if (rate[NL80211_RATE_INFO_VHT_NSS]) {
6404 data->rx_vht_nss =
6405 nla_get_u8(rate[NL80211_RATE_INFO_VHT_NSS]);
6406 data->flags |= STA_DRV_DATA_RX_VHT_NSS;
6407 }
6408 }
6409
6410 return NL_SKIP;
6411 }
6412
6413 static int i802_read_sta_data(struct i802_bss *bss,
6414 struct hostap_sta_driver_data *data,
6415 const u8 *addr)
6416 {
6417 struct nl_msg *msg;
6418
6419 if (!(msg = nl80211_bss_msg(bss, 0, NL80211_CMD_GET_STATION)) ||
6420 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) {
6421 nlmsg_free(msg);
6422 return -ENOBUFS;
6423 }
6424
6425 return send_and_recv_msgs(bss->drv, msg, get_sta_handler, data);
6426 }
6427
6428
6429 static int i802_set_tx_queue_params(void *priv, int queue, int aifs,
6430 int cw_min, int cw_max, int burst_time)
6431 {
6432 struct i802_bss *bss = priv;
6433 struct wpa_driver_nl80211_data *drv = bss->drv;
6434 struct nl_msg *msg;
6435 struct nlattr *txq, *params;
6436 int res;
6437
6438 msg = nl80211_bss_msg(bss, 0, NL80211_CMD_SET_WIPHY);
6439 if (!msg)
6440 return -1;
6441
6442 txq = nla_nest_start(msg, NL80211_ATTR_WIPHY_TXQ_PARAMS);
6443 if (!txq)
6444 goto fail;
6445
6446 /* We are only sending parameters for a single TXQ at a time */
6447 params = nla_nest_start(msg, 1);
6448 if (!params)
6449 goto fail;
6450
6451 switch (queue) {
6452 case 0:
6453 if (nla_put_u8(msg, NL80211_TXQ_ATTR_QUEUE, NL80211_TXQ_Q_VO))
6454 goto fail;
6455 break;
6456 case 1:
6457 if (nla_put_u8(msg, NL80211_TXQ_ATTR_QUEUE, NL80211_TXQ_Q_VI))
6458 goto fail;
6459 break;
6460 case 2:
6461 if (nla_put_u8(msg, NL80211_TXQ_ATTR_QUEUE, NL80211_TXQ_Q_BE))
6462 goto fail;
6463 break;
6464 case 3:
6465 if (nla_put_u8(msg, NL80211_TXQ_ATTR_QUEUE, NL80211_TXQ_Q_BK))
6466 goto fail;
6467 break;
6468 }
6469 /* Burst time is configured in units of 0.1 msec and TXOP parameter in
6470 * 32 usec, so need to convert the value here. */
6471 if (nla_put_u16(msg, NL80211_TXQ_ATTR_TXOP,
6472 (burst_time * 100 + 16) / 32) ||
6473 nla_put_u16(msg, NL80211_TXQ_ATTR_CWMIN, cw_min) ||
6474 nla_put_u16(msg, NL80211_TXQ_ATTR_CWMAX, cw_max) ||
6475 nla_put_u8(msg, NL80211_TXQ_ATTR_AIFS, aifs))
6476 goto fail;
6477
6478 nla_nest_end(msg, params);
6479
6480 nla_nest_end(msg, txq);
6481
6482 res = send_and_recv_msgs(drv, msg, NULL, NULL);
6483 wpa_printf(MSG_DEBUG,
6484 "nl80211: TX queue param set: queue=%d aifs=%d cw_min=%d cw_max=%d burst_time=%d --> res=%d",
6485 queue, aifs, cw_min, cw_max, burst_time, res);
6486 if (res == 0)
6487 return 0;
6488 msg = NULL;
6489 fail:
6490 nlmsg_free(msg);
6491 return -1;
6492 }
6493
6494
6495 static int i802_set_sta_vlan(struct i802_bss *bss, const u8 *addr,
6496 const char *ifname, int vlan_id)
6497 {
6498 struct wpa_driver_nl80211_data *drv = bss->drv;
6499 struct nl_msg *msg;
6500 int ret;
6501
6502 wpa_printf(MSG_DEBUG, "nl80211: %s[%d]: set_sta_vlan(" MACSTR
6503 ", ifname=%s[%d], vlan_id=%d)",
6504 bss->ifname, if_nametoindex(bss->ifname),
6505 MAC2STR(addr), ifname, if_nametoindex(ifname), vlan_id);
6506 if (!(msg = nl80211_bss_msg(bss, 0, NL80211_CMD_SET_STATION)) ||
6507 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) ||
6508 nla_put_u32(msg, NL80211_ATTR_STA_VLAN, if_nametoindex(ifname))) {
6509 nlmsg_free(msg);
6510 return -ENOBUFS;
6511 }
6512
6513 ret = send_and_recv_msgs(drv, msg, NULL, NULL);
6514 if (ret < 0) {
6515 wpa_printf(MSG_ERROR, "nl80211: NL80211_ATTR_STA_VLAN (addr="
6516 MACSTR " ifname=%s vlan_id=%d) failed: %d (%s)",
6517 MAC2STR(addr), ifname, vlan_id, ret,
6518 strerror(-ret));
6519 }
6520 return ret;
6521 }
6522
6523
6524 static int i802_get_inact_sec(void *priv, const u8 *addr)
6525 {
6526 struct hostap_sta_driver_data data;
6527 int ret;
6528
6529 os_memset(&data, 0, sizeof(data));
6530 data.inactive_msec = (unsigned long) -1;
6531 ret = i802_read_sta_data(priv, &data, addr);
6532 if (ret == -ENOENT)
6533 return -ENOENT;
6534 if (ret || data.inactive_msec == (unsigned long) -1)
6535 return -1;
6536 return data.inactive_msec / 1000;
6537 }
6538
6539
6540 static int i802_sta_clear_stats(void *priv, const u8 *addr)
6541 {
6542 #if 0
6543 /* TODO */
6544 #endif
6545 return 0;
6546 }
6547
6548
6549 static int i802_sta_deauth(void *priv, const u8 *own_addr, const u8 *addr,
6550 int reason)
6551 {
6552 struct i802_bss *bss = priv;
6553 struct wpa_driver_nl80211_data *drv = bss->drv;
6554 struct ieee80211_mgmt mgmt;
6555 u8 channel;
6556
6557 if (ieee80211_freq_to_chan(bss->freq, &channel) ==
6558 HOSTAPD_MODE_IEEE80211AD) {
6559 /* Deauthentication is not used in DMG/IEEE 802.11ad;
6560 * disassociate the STA instead. */
6561 return i802_sta_disassoc(priv, own_addr, addr, reason);
6562 }
6563
6564 if (is_mesh_interface(drv->nlmode))
6565 return -1;
6566
6567 if (drv->device_ap_sme)
6568 return wpa_driver_nl80211_sta_remove(bss, addr, 1, reason);
6569
6570 memset(&mgmt, 0, sizeof(mgmt));
6571 mgmt.frame_control = IEEE80211_FC(WLAN_FC_TYPE_MGMT,
6572 WLAN_FC_STYPE_DEAUTH);
6573 memcpy(mgmt.da, addr, ETH_ALEN);
6574 memcpy(mgmt.sa, own_addr, ETH_ALEN);
6575 memcpy(mgmt.bssid, own_addr, ETH_ALEN);
6576 mgmt.u.deauth.reason_code = host_to_le16(reason);
6577 return wpa_driver_nl80211_send_mlme(bss, (u8 *) &mgmt,
6578 IEEE80211_HDRLEN +
6579 sizeof(mgmt.u.deauth), 0, 0, 0, 0,
6580 0, NULL, 0);
6581 }
6582
6583
6584 static int i802_sta_disassoc(void *priv, const u8 *own_addr, const u8 *addr,
6585 int reason)
6586 {
6587 struct i802_bss *bss = priv;
6588 struct wpa_driver_nl80211_data *drv = bss->drv;
6589 struct ieee80211_mgmt mgmt;
6590
6591 if (is_mesh_interface(drv->nlmode))
6592 return -1;
6593
6594 if (drv->device_ap_sme)
6595 return wpa_driver_nl80211_sta_remove(bss, addr, 0, reason);
6596
6597 memset(&mgmt, 0, sizeof(mgmt));
6598 mgmt.frame_control = IEEE80211_FC(WLAN_FC_TYPE_MGMT,
6599 WLAN_FC_STYPE_DISASSOC);
6600 memcpy(mgmt.da, addr, ETH_ALEN);
6601 memcpy(mgmt.sa, own_addr, ETH_ALEN);
6602 memcpy(mgmt.bssid, own_addr, ETH_ALEN);
6603 mgmt.u.disassoc.reason_code = host_to_le16(reason);
6604 return wpa_driver_nl80211_send_mlme(bss, (u8 *) &mgmt,
6605 IEEE80211_HDRLEN +
6606 sizeof(mgmt.u.disassoc), 0, 0, 0, 0,
6607 0, NULL, 0);
6608 }
6609
6610
6611 static void dump_ifidx(struct wpa_driver_nl80211_data *drv)
6612 {
6613 char buf[200], *pos, *end;
6614 int i, res;
6615
6616 pos = buf;
6617 end = pos + sizeof(buf);
6618
6619 for (i = 0; i < drv->num_if_indices; i++) {
6620 if (!drv->if_indices[i])
6621 continue;
6622 res = os_snprintf(pos, end - pos, " %d(%d)",
6623 drv->if_indices[i],
6624 drv->if_indices_reason[i]);
6625 if (os_snprintf_error(end - pos, res))
6626 break;
6627 pos += res;
6628 }
6629 *pos = '\0';
6630
6631 wpa_printf(MSG_DEBUG, "nl80211: if_indices[%d]:%s",
6632 drv->num_if_indices, buf);
6633 }
6634
6635
6636 static void add_ifidx(struct wpa_driver_nl80211_data *drv, int ifidx,
6637 int ifidx_reason)
6638 {
6639 int i;
6640 int *old, *old_reason;
6641
6642 wpa_printf(MSG_DEBUG,
6643 "nl80211: Add own interface ifindex %d (ifidx_reason %d)",
6644 ifidx, ifidx_reason);
6645 if (have_ifidx(drv, ifidx, ifidx_reason)) {
6646 wpa_printf(MSG_DEBUG, "nl80211: ifindex %d already in the list",
6647 ifidx);
6648 return;
6649 }
6650 for (i = 0; i < drv->num_if_indices; i++) {
6651 if (drv->if_indices[i] == 0) {
6652 drv->if_indices[i] = ifidx;
6653 drv->if_indices_reason[i] = ifidx_reason;
6654 dump_ifidx(drv);
6655 return;
6656 }
6657 }
6658
6659 if (drv->if_indices != drv->default_if_indices)
6660 old = drv->if_indices;
6661 else
6662 old = NULL;
6663
6664 if (drv->if_indices_reason != drv->default_if_indices_reason)
6665 old_reason = drv->if_indices_reason;
6666 else
6667 old_reason = NULL;
6668
6669 drv->if_indices = os_realloc_array(old, drv->num_if_indices + 1,
6670 sizeof(int));
6671 drv->if_indices_reason = os_realloc_array(old_reason,
6672 drv->num_if_indices + 1,
6673 sizeof(int));
6674 if (!drv->if_indices) {
6675 if (!old)
6676 drv->if_indices = drv->default_if_indices;
6677 else
6678 drv->if_indices = old;
6679 }
6680 if (!drv->if_indices_reason) {
6681 if (!old_reason)
6682 drv->if_indices_reason = drv->default_if_indices_reason;
6683 else
6684 drv->if_indices_reason = old_reason;
6685 }
6686 if (!drv->if_indices || !drv->if_indices_reason) {
6687 wpa_printf(MSG_ERROR, "Failed to reallocate memory for "
6688 "interfaces");
6689 wpa_printf(MSG_ERROR, "Ignoring EAPOL on interface %d", ifidx);
6690 return;
6691 }
6692 if (!old)
6693 os_memcpy(drv->if_indices, drv->default_if_indices,
6694 sizeof(drv->default_if_indices));
6695 if (!old_reason)
6696 os_memcpy(drv->if_indices_reason,
6697 drv->default_if_indices_reason,
6698 sizeof(drv->default_if_indices_reason));
6699 drv->if_indices[drv->num_if_indices] = ifidx;
6700 drv->if_indices_reason[drv->num_if_indices] = ifidx_reason;
6701 drv->num_if_indices++;
6702 dump_ifidx(drv);
6703 }
6704
6705
6706 static void del_ifidx(struct wpa_driver_nl80211_data *drv, int ifidx,
6707 int ifidx_reason)
6708 {
6709 int i;
6710
6711 for (i = 0; i < drv->num_if_indices; i++) {
6712 if ((drv->if_indices[i] == ifidx || ifidx == IFIDX_ANY) &&
6713 (drv->if_indices_reason[i] == ifidx_reason ||
6714 ifidx_reason == IFIDX_ANY)) {
6715 drv->if_indices[i] = 0;
6716 break;
6717 }
6718 }
6719 dump_ifidx(drv);
6720 }
6721
6722
6723 static int have_ifidx(struct wpa_driver_nl80211_data *drv, int ifidx,
6724 int ifidx_reason)
6725 {
6726 int i;
6727
6728 for (i = 0; i < drv->num_if_indices; i++)
6729 if (drv->if_indices[i] == ifidx &&
6730 (drv->if_indices_reason[i] == ifidx_reason ||
6731 ifidx_reason == IFIDX_ANY))
6732 return 1;
6733
6734 return 0;
6735 }
6736
6737
6738 static int i802_set_wds_sta(void *priv, const u8 *addr, int aid, int val,
6739 const char *bridge_ifname, char *ifname_wds)
6740 {
6741 struct i802_bss *bss = priv;
6742 struct wpa_driver_nl80211_data *drv = bss->drv;
6743 char name[IFNAMSIZ + 1];
6744 union wpa_event_data event;
6745 int ret;
6746
6747 ret = os_snprintf(name, sizeof(name), "%s.sta%d", bss->ifname, aid);
6748 if (ret >= (int) sizeof(name))
6749 wpa_printf(MSG_WARNING,
6750 "nl80211: WDS interface name was truncated");
6751 else if (ret < 0)
6752 return ret;
6753
6754 if (ifname_wds)
6755 os_strlcpy(ifname_wds, name, IFNAMSIZ + 1);
6756
6757 wpa_printf(MSG_DEBUG, "nl80211: Set WDS STA addr=" MACSTR
6758 " aid=%d val=%d name=%s", MAC2STR(addr), aid, val, name);
6759 if (val) {
6760 if (!if_nametoindex(name)) {
6761 if (nl80211_create_iface(drv, name,
6762 NL80211_IFTYPE_AP_VLAN,
6763 bss->addr, 1, NULL, NULL, 0) <
6764 0)
6765 return -1;
6766 if (bridge_ifname &&
6767 linux_br_add_if(drv->global->ioctl_sock,
6768 bridge_ifname, name) < 0)
6769 return -1;
6770
6771 os_memset(&event, 0, sizeof(event));
6772 event.wds_sta_interface.sta_addr = addr;
6773 event.wds_sta_interface.ifname = name;
6774 event.wds_sta_interface.istatus = INTERFACE_ADDED;
6775 wpa_supplicant_event(bss->ctx,
6776 EVENT_WDS_STA_INTERFACE_STATUS,
6777 &event);
6778 }
6779 if (linux_set_iface_flags(drv->global->ioctl_sock, name, 1)) {
6780 wpa_printf(MSG_ERROR, "nl80211: Failed to set WDS STA "
6781 "interface %s up", name);
6782 }
6783 return i802_set_sta_vlan(priv, addr, name, 0);
6784 } else {
6785 if (bridge_ifname &&
6786 linux_br_del_if(drv->global->ioctl_sock, bridge_ifname,
6787 name) < 0)
6788 wpa_printf(MSG_INFO,
6789 "nl80211: Failed to remove interface %s from bridge %s: %s",
6790 name, bridge_ifname, strerror(errno));
6791
6792 i802_set_sta_vlan(priv, addr, bss->ifname, 0);
6793 nl80211_remove_iface(drv, if_nametoindex(name));
6794 os_memset(&event, 0, sizeof(event));
6795 event.wds_sta_interface.sta_addr = addr;
6796 event.wds_sta_interface.ifname = name;
6797 event.wds_sta_interface.istatus = INTERFACE_REMOVED;
6798 wpa_supplicant_event(bss->ctx, EVENT_WDS_STA_INTERFACE_STATUS,
6799 &event);
6800 return 0;
6801 }
6802 }
6803
6804
6805 static void handle_eapol(int sock, void *eloop_ctx, void *sock_ctx)
6806 {
6807 struct wpa_driver_nl80211_data *drv = eloop_ctx;
6808 struct sockaddr_ll lladdr;
6809 unsigned char buf[3000];
6810 int len;
6811 socklen_t fromlen = sizeof(lladdr);
6812
6813 len = recvfrom(sock, buf, sizeof(buf), 0,
6814 (struct sockaddr *)&lladdr, &fromlen);
6815 if (len < 0) {
6816 wpa_printf(MSG_ERROR, "nl80211: EAPOL recv failed: %s",
6817 strerror(errno));
6818 return;
6819 }
6820
6821 if (have_ifidx(drv, lladdr.sll_ifindex, IFIDX_ANY))
6822 drv_event_eapol_rx(drv->ctx, lladdr.sll_addr, buf, len);
6823 }
6824
6825
6826 static int i802_check_bridge(struct wpa_driver_nl80211_data *drv,
6827 struct i802_bss *bss,
6828 const char *brname, const char *ifname)
6829 {
6830 int br_ifindex;
6831 char in_br[IFNAMSIZ];
6832
6833 os_strlcpy(bss->brname, brname, IFNAMSIZ);
6834 br_ifindex = if_nametoindex(brname);
6835 if (br_ifindex == 0) {
6836 /*
6837 * Bridge was configured, but the bridge device does
6838 * not exist. Try to add it now.
6839 */
6840 if (linux_br_add(drv->global->ioctl_sock, brname) < 0) {
6841 wpa_printf(MSG_ERROR, "nl80211: Failed to add the "
6842 "bridge interface %s: %s",
6843 brname, strerror(errno));
6844 return -1;
6845 }
6846 bss->added_bridge = 1;
6847 br_ifindex = if_nametoindex(brname);
6848 add_ifidx(drv, br_ifindex, drv->ifindex);
6849 }
6850 bss->br_ifindex = br_ifindex;
6851
6852 if (linux_br_get(in_br, ifname) == 0) {
6853 if (os_strcmp(in_br, brname) == 0) {
6854 bss->already_in_bridge = 1;
6855 return 0; /* already in the bridge */
6856 }
6857
6858 wpa_printf(MSG_DEBUG, "nl80211: Removing interface %s from "
6859 "bridge %s", ifname, in_br);
6860 if (linux_br_del_if(drv->global->ioctl_sock, in_br, ifname) <
6861 0) {
6862 wpa_printf(MSG_ERROR, "nl80211: Failed to "
6863 "remove interface %s from bridge "
6864 "%s: %s",
6865 ifname, in_br, strerror(errno));
6866 return -1;
6867 }
6868 }
6869
6870 wpa_printf(MSG_DEBUG, "nl80211: Adding interface %s into bridge %s",
6871 ifname, brname);
6872 if (linux_br_add_if(drv->global->ioctl_sock, brname, ifname) < 0) {
6873 wpa_printf(MSG_ERROR, "nl80211: Failed to add interface %s "
6874 "into bridge %s: %s",
6875 ifname, brname, strerror(errno));
6876 return -1;
6877 }
6878 bss->added_if_into_bridge = 1;
6879
6880 return 0;
6881 }
6882
6883
6884 static void *i802_init(struct hostapd_data *hapd,
6885 struct wpa_init_params *params)
6886 {
6887 struct wpa_driver_nl80211_data *drv;
6888 struct i802_bss *bss;
6889 size_t i;
6890 char master_ifname[IFNAMSIZ];
6891 int ifindex, br_ifindex = 0;
6892 int br_added = 0;
6893
6894 bss = wpa_driver_nl80211_drv_init(hapd, params->ifname,
6895 params->global_priv, 1,
6896 params->bssid, params->driver_params);
6897 if (bss == NULL)
6898 return NULL;
6899
6900 drv = bss->drv;
6901
6902 if (linux_br_get(master_ifname, params->ifname) == 0) {
6903 wpa_printf(MSG_DEBUG, "nl80211: Interface %s is in bridge %s",
6904 params->ifname, master_ifname);
6905 br_ifindex = if_nametoindex(master_ifname);
6906 os_strlcpy(bss->brname, master_ifname, IFNAMSIZ);
6907 } else if ((params->num_bridge == 0 || !params->bridge[0]) &&
6908 linux_master_get(master_ifname, params->ifname) == 0) {
6909 wpa_printf(MSG_DEBUG, "nl80211: Interface %s is in master %s",
6910 params->ifname, master_ifname);
6911 /* start listening for EAPOL on the master interface */
6912 add_ifidx(drv, if_nametoindex(master_ifname), drv->ifindex);
6913
6914 /* check if master itself is under bridge */
6915 if (linux_br_get(master_ifname, master_ifname) == 0) {
6916 wpa_printf(MSG_DEBUG, "nl80211: which is in bridge %s",
6917 master_ifname);
6918 br_ifindex = if_nametoindex(master_ifname);
6919 os_strlcpy(bss->brname, master_ifname, IFNAMSIZ);
6920 }
6921 } else {
6922 master_ifname[0] = '\0';
6923 }
6924
6925 bss->br_ifindex = br_ifindex;
6926
6927 for (i = 0; i < params->num_bridge; i++) {
6928 if (params->bridge[i]) {
6929 ifindex = if_nametoindex(params->bridge[i]);
6930 if (ifindex)
6931 add_ifidx(drv, ifindex, drv->ifindex);
6932 if (ifindex == br_ifindex)
6933 br_added = 1;
6934 }
6935 }
6936
6937 /* start listening for EAPOL on the default AP interface */
6938 add_ifidx(drv, drv->ifindex, IFIDX_ANY);
6939
6940 if (params->num_bridge && params->bridge[0]) {
6941 if (i802_check_bridge(drv, bss, params->bridge[0],
6942 params->ifname) < 0)
6943 goto failed;
6944 if (os_strcmp(params->bridge[0], master_ifname) != 0)
6945 br_added = 1;
6946 }
6947
6948 if (!br_added && br_ifindex &&
6949 (params->num_bridge == 0 || !params->bridge[0]))
6950 add_ifidx(drv, br_ifindex, drv->ifindex);
6951
6952 #ifdef CONFIG_LIBNL3_ROUTE
6953 if (bss->added_if_into_bridge || bss->already_in_bridge) {
6954 drv->rtnl_sk = nl_socket_alloc();
6955 if (drv->rtnl_sk == NULL) {
6956 wpa_printf(MSG_ERROR, "nl80211: Failed to allocate nl_sock");
6957 goto failed;
6958 }
6959
6960 if (nl_connect(drv->rtnl_sk, NETLINK_ROUTE)) {
6961 wpa_printf(MSG_ERROR, "nl80211: Failed to connect nl_sock to NETLINK_ROUTE: %s",
6962 strerror(errno));
6963 goto failed;
6964 }
6965 }
6966 #endif /* CONFIG_LIBNL3_ROUTE */
6967
6968 drv->eapol_sock = socket(PF_PACKET, SOCK_DGRAM, htons(ETH_P_PAE));
6969 if (drv->eapol_sock < 0) {
6970 wpa_printf(MSG_ERROR, "nl80211: socket(PF_PACKET, SOCK_DGRAM, ETH_P_PAE) failed: %s",
6971 strerror(errno));
6972 goto failed;
6973 }
6974
6975 if (eloop_register_read_sock(drv->eapol_sock, handle_eapol, drv, NULL))
6976 {
6977 wpa_printf(MSG_INFO, "nl80211: Could not register read socket for eapol");
6978 goto failed;
6979 }
6980
6981 if (linux_get_ifhwaddr(drv->global->ioctl_sock, bss->ifname,
6982 params->own_addr))
6983 goto failed;
6984 os_memcpy(drv->perm_addr, params->own_addr, ETH_ALEN);
6985
6986 memcpy(bss->addr, params->own_addr, ETH_ALEN);
6987
6988 return bss;
6989
6990 failed:
6991 wpa_driver_nl80211_deinit(bss);
6992 return NULL;
6993 }
6994
6995
6996 static void i802_deinit(void *priv)
6997 {
6998 struct i802_bss *bss = priv;
6999 wpa_driver_nl80211_deinit(bss);
7000 }
7001
7002
7003 static enum nl80211_iftype wpa_driver_nl80211_if_type(
7004 enum wpa_driver_if_type type)
7005 {
7006 switch (type) {
7007 case WPA_IF_STATION:
7008 return NL80211_IFTYPE_STATION;
7009 case WPA_IF_P2P_CLIENT:
7010 case WPA_IF_P2P_GROUP:
7011 return NL80211_IFTYPE_P2P_CLIENT;
7012 case WPA_IF_AP_VLAN:
7013 return NL80211_IFTYPE_AP_VLAN;
7014 case WPA_IF_AP_BSS:
7015 return NL80211_IFTYPE_AP;
7016 case WPA_IF_P2P_GO:
7017 return NL80211_IFTYPE_P2P_GO;
7018 case WPA_IF_P2P_DEVICE:
7019 return NL80211_IFTYPE_P2P_DEVICE;
7020 case WPA_IF_MESH:
7021 return NL80211_IFTYPE_MESH_POINT;
7022 default:
7023 return -1;
7024 }
7025 }
7026
7027
7028 static int nl80211_addr_in_use(struct nl80211_global *global, const u8 *addr)
7029 {
7030 struct wpa_driver_nl80211_data *drv;
7031 dl_list_for_each(drv, &global->interfaces,
7032 struct wpa_driver_nl80211_data, list) {
7033 if (os_memcmp(addr, drv->first_bss->addr, ETH_ALEN) == 0)
7034 return 1;
7035 }
7036 return 0;
7037 }
7038
7039
7040 static int nl80211_vif_addr(struct wpa_driver_nl80211_data *drv, u8 *new_addr)
7041 {
7042 unsigned int idx;
7043
7044 if (!drv->global)
7045 return -1;
7046
7047 os_memcpy(new_addr, drv->first_bss->addr, ETH_ALEN);
7048 for (idx = 0; idx < 64; idx++) {
7049 new_addr[0] = drv->first_bss->addr[0] | 0x02;
7050 new_addr[0] ^= idx << 2;
7051 if (!nl80211_addr_in_use(drv->global, new_addr))
7052 break;
7053 }
7054 if (idx == 64)
7055 return -1;
7056
7057 wpa_printf(MSG_DEBUG, "nl80211: Assigned new virtual interface address "
7058 MACSTR, MAC2STR(new_addr));
7059
7060 return 0;
7061 }
7062
7063
7064 struct wdev_info {
7065 u64 wdev_id;
7066 int wdev_id_set;
7067 u8 macaddr[ETH_ALEN];
7068 };
7069
7070 static int nl80211_wdev_handler(struct nl_msg *msg, void *arg)
7071 {
7072 struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg));
7073 struct nlattr *tb[NL80211_ATTR_MAX + 1];
7074 struct wdev_info *wi = arg;
7075
7076 nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0),
7077 genlmsg_attrlen(gnlh, 0), NULL);
7078 if (tb[NL80211_ATTR_WDEV]) {
7079 wi->wdev_id = nla_get_u64(tb[NL80211_ATTR_WDEV]);
7080 wi->wdev_id_set = 1;
7081 }
7082
7083 if (tb[NL80211_ATTR_MAC])
7084 os_memcpy(wi->macaddr, nla_data(tb[NL80211_ATTR_MAC]),
7085 ETH_ALEN);
7086
7087 return NL_SKIP;
7088 }
7089
7090
7091 static int wpa_driver_nl80211_if_add(void *priv, enum wpa_driver_if_type type,
7092 const char *ifname, const u8 *addr,
7093 void *bss_ctx, void **drv_priv,
7094 char *force_ifname, u8 *if_addr,
7095 const char *bridge, int use_existing,
7096 int setup_ap)
7097 {
7098 enum nl80211_iftype nlmode;
7099 struct i802_bss *bss = priv;
7100 struct wpa_driver_nl80211_data *drv = bss->drv;
7101 int ifidx;
7102 int added = 1;
7103
7104 if (addr)
7105 os_memcpy(if_addr, addr, ETH_ALEN);
7106 nlmode = wpa_driver_nl80211_if_type(type);
7107 if (nlmode == NL80211_IFTYPE_P2P_DEVICE) {
7108 struct wdev_info p2pdev_info;
7109
7110 os_memset(&p2pdev_info, 0, sizeof(p2pdev_info));
7111 ifidx = nl80211_create_iface(drv, ifname, nlmode, addr,
7112 0, nl80211_wdev_handler,
7113 &p2pdev_info, use_existing);
7114 if (!p2pdev_info.wdev_id_set || ifidx != 0) {
7115 wpa_printf(MSG_ERROR, "nl80211: Failed to create a P2P Device interface %s",
7116 ifname);
7117 return -1;
7118 }
7119
7120 drv->global->if_add_wdevid = p2pdev_info.wdev_id;
7121 drv->global->if_add_wdevid_set = p2pdev_info.wdev_id_set;
7122 if (!is_zero_ether_addr(p2pdev_info.macaddr))
7123 os_memcpy(if_addr, p2pdev_info.macaddr, ETH_ALEN);
7124 wpa_printf(MSG_DEBUG, "nl80211: New P2P Device interface %s (0x%llx) created",
7125 ifname,
7126 (long long unsigned int) p2pdev_info.wdev_id);
7127 } else {
7128 ifidx = nl80211_create_iface(drv, ifname, nlmode, addr,
7129 0, NULL, NULL, use_existing);
7130 if (use_existing && ifidx == -ENFILE) {
7131 added = 0;
7132 ifidx = if_nametoindex(ifname);
7133 } else if (ifidx < 0) {
7134 return -1;
7135 }
7136 }
7137
7138 if (!addr) {
7139 if (nlmode == NL80211_IFTYPE_P2P_DEVICE)
7140 os_memcpy(if_addr, bss->addr, ETH_ALEN);
7141 else if (linux_get_ifhwaddr(drv->global->ioctl_sock,
7142 ifname, if_addr) < 0) {
7143 if (added)
7144 nl80211_remove_iface(drv, ifidx);
7145 return -1;
7146 }
7147 }
7148
7149 if (!addr &&
7150 (type == WPA_IF_P2P_CLIENT || type == WPA_IF_P2P_GROUP ||
7151 type == WPA_IF_P2P_GO || type == WPA_IF_MESH ||
7152 type == WPA_IF_STATION)) {
7153 /* Enforce unique address */
7154 u8 new_addr[ETH_ALEN];
7155
7156 if (linux_get_ifhwaddr(drv->global->ioctl_sock, ifname,
7157 new_addr) < 0) {
7158 if (added)
7159 nl80211_remove_iface(drv, ifidx);
7160 return -1;
7161 }
7162 if (nl80211_addr_in_use(drv->global, new_addr)) {
7163 wpa_printf(MSG_DEBUG, "nl80211: Allocate new address "
7164 "for interface %s type %d", ifname, type);
7165 if (nl80211_vif_addr(drv, new_addr) < 0) {
7166 if (added)
7167 nl80211_remove_iface(drv, ifidx);
7168 return -1;
7169 }
7170 if (linux_set_ifhwaddr(drv->global->ioctl_sock, ifname,
7171 new_addr) < 0) {
7172 if (added)
7173 nl80211_remove_iface(drv, ifidx);
7174 return -1;
7175 }
7176 }
7177 os_memcpy(if_addr, new_addr, ETH_ALEN);
7178 }
7179
7180 if (type == WPA_IF_AP_BSS && setup_ap) {
7181 struct i802_bss *new_bss = os_zalloc(sizeof(*new_bss));
7182 if (new_bss == NULL) {
7183 if (added)
7184 nl80211_remove_iface(drv, ifidx);
7185 return -1;
7186 }
7187
7188 if (bridge &&
7189 i802_check_bridge(drv, new_bss, bridge, ifname) < 0) {
7190 wpa_printf(MSG_ERROR, "nl80211: Failed to add the new "
7191 "interface %s to a bridge %s",
7192 ifname, bridge);
7193 if (added)
7194 nl80211_remove_iface(drv, ifidx);
7195 os_free(new_bss);
7196 return -1;
7197 }
7198
7199 if (linux_set_iface_flags(drv->global->ioctl_sock, ifname, 1))
7200 {
7201 if (added)
7202 nl80211_remove_iface(drv, ifidx);
7203 os_free(new_bss);
7204 return -1;
7205 }
7206 os_strlcpy(new_bss->ifname, ifname, IFNAMSIZ);
7207 os_memcpy(new_bss->addr, if_addr, ETH_ALEN);
7208 new_bss->ifindex = ifidx;
7209 new_bss->drv = drv;
7210 new_bss->next = drv->first_bss->next;
7211 new_bss->freq = drv->first_bss->freq;
7212 new_bss->ctx = bss_ctx;
7213 new_bss->added_if = added;
7214 drv->first_bss->next = new_bss;
7215 if (drv_priv)
7216 *drv_priv = new_bss;
7217 nl80211_init_bss(new_bss);
7218
7219 /* Subscribe management frames for this WPA_IF_AP_BSS */
7220 if (nl80211_setup_ap(new_bss))
7221 return -1;
7222 }
7223
7224 if (drv->global)
7225 drv->global->if_add_ifindex = ifidx;
7226
7227 /*
7228 * Some virtual interfaces need to process EAPOL packets and events on
7229 * the parent interface. This is used mainly with hostapd.
7230 */
7231 if (ifidx > 0 &&
7232 (drv->hostapd ||
7233 nlmode == NL80211_IFTYPE_AP_VLAN ||
7234 nlmode == NL80211_IFTYPE_WDS ||
7235 nlmode == NL80211_IFTYPE_MONITOR))
7236 add_ifidx(drv, ifidx, IFIDX_ANY);
7237
7238 return 0;
7239 }
7240
7241
7242 static int wpa_driver_nl80211_if_remove(struct i802_bss *bss,
7243 enum wpa_driver_if_type type,
7244 const char *ifname)
7245 {
7246 struct wpa_driver_nl80211_data *drv = bss->drv;
7247 int ifindex = if_nametoindex(ifname);
7248
7249 wpa_printf(MSG_DEBUG, "nl80211: %s(type=%d ifname=%s) ifindex=%d added_if=%d",
7250 __func__, type, ifname, ifindex, bss->added_if);
7251 if (ifindex > 0 && (bss->added_if || bss->ifindex != ifindex))
7252 nl80211_remove_iface(drv, ifindex);
7253 else if (ifindex > 0 && !bss->added_if) {
7254 struct wpa_driver_nl80211_data *drv2;
7255 dl_list_for_each(drv2, &drv->global->interfaces,
7256 struct wpa_driver_nl80211_data, list) {
7257 del_ifidx(drv2, ifindex, IFIDX_ANY);
7258 del_ifidx(drv2, IFIDX_ANY, ifindex);
7259 }
7260 }
7261
7262 if (type != WPA_IF_AP_BSS)
7263 return 0;
7264
7265 if (bss->added_if_into_bridge) {
7266 if (linux_br_del_if(drv->global->ioctl_sock, bss->brname,
7267 bss->ifname) < 0)
7268 wpa_printf(MSG_INFO, "nl80211: Failed to remove "
7269 "interface %s from bridge %s: %s",
7270 bss->ifname, bss->brname, strerror(errno));
7271 }
7272 if (bss->added_bridge) {
7273 if (linux_br_del(drv->global->ioctl_sock, bss->brname) < 0)
7274 wpa_printf(MSG_INFO, "nl80211: Failed to remove "
7275 "bridge %s: %s",
7276 bss->brname, strerror(errno));
7277 }
7278
7279 if (bss != drv->first_bss) {
7280 struct i802_bss *tbss;
7281
7282 wpa_printf(MSG_DEBUG, "nl80211: Not the first BSS - remove it");
7283 for (tbss = drv->first_bss; tbss; tbss = tbss->next) {
7284 if (tbss->next == bss) {
7285 tbss->next = bss->next;
7286 /* Unsubscribe management frames */
7287 nl80211_teardown_ap(bss);
7288 nl80211_destroy_bss(bss);
7289 if (!bss->added_if)
7290 i802_set_iface_flags(bss, 0);
7291 os_free(bss);
7292 bss = NULL;
7293 break;
7294 }
7295 }
7296 if (bss)
7297 wpa_printf(MSG_INFO, "nl80211: %s - could not find "
7298 "BSS %p in the list", __func__, bss);
7299 } else {
7300 wpa_printf(MSG_DEBUG, "nl80211: First BSS - reassign context");
7301 nl80211_teardown_ap(bss);
7302 if (!bss->added_if && !drv->first_bss->next)
7303 wpa_driver_nl80211_del_beacon(bss);
7304 nl80211_destroy_bss(bss);
7305 if (!bss->added_if)
7306 i802_set_iface_flags(bss, 0);
7307 if (drv->first_bss->next) {
7308 drv->first_bss = drv->first_bss->next;
7309 drv->ctx = drv->first_bss->ctx;
7310 os_free(bss);
7311 } else {
7312 wpa_printf(MSG_DEBUG, "nl80211: No second BSS to reassign context to");
7313 }
7314 }
7315
7316 return 0;
7317 }
7318
7319
7320 static int cookie_handler(struct nl_msg *msg, void *arg)
7321 {
7322 struct nlattr *tb[NL80211_ATTR_MAX + 1];
7323 struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg));
7324 u64 *cookie = arg;
7325 nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0),
7326 genlmsg_attrlen(gnlh, 0), NULL);
7327 if (tb[NL80211_ATTR_COOKIE])
7328 *cookie = nla_get_u64(tb[NL80211_ATTR_COOKIE]);
7329 return NL_SKIP;
7330 }
7331
7332
7333 static int nl80211_send_frame_cmd(struct i802_bss *bss,
7334 unsigned int freq, unsigned int wait,
7335 const u8 *buf, size_t buf_len,
7336 u64 *cookie_out, int no_cck, int no_ack,
7337 int offchanok, const u16 *csa_offs,
7338 size_t csa_offs_len)
7339 {
7340 struct wpa_driver_nl80211_data *drv = bss->drv;
7341 struct nl_msg *msg;
7342 u64 cookie;
7343 int ret = -1;
7344
7345 wpa_printf(MSG_MSGDUMP, "nl80211: CMD_FRAME freq=%u wait=%u no_cck=%d "
7346 "no_ack=%d offchanok=%d",
7347 freq, wait, no_cck, no_ack, offchanok);
7348 wpa_hexdump(MSG_MSGDUMP, "CMD_FRAME", buf, buf_len);
7349
7350 if (!(msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_FRAME)) ||
7351 (freq && nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq)) ||
7352 (wait && nla_put_u32(msg, NL80211_ATTR_DURATION, wait)) ||
7353 (offchanok && ((drv->capa.flags & WPA_DRIVER_FLAGS_OFFCHANNEL_TX) ||
7354 drv->test_use_roc_tx) &&
7355 nla_put_flag(msg, NL80211_ATTR_OFFCHANNEL_TX_OK)) ||
7356 (no_cck && nla_put_flag(msg, NL80211_ATTR_TX_NO_CCK_RATE)) ||
7357 (no_ack && nla_put_flag(msg, NL80211_ATTR_DONT_WAIT_FOR_ACK)) ||
7358 (csa_offs && nla_put(msg, NL80211_ATTR_CSA_C_OFFSETS_TX,
7359 csa_offs_len * sizeof(u16), csa_offs)) ||
7360 nla_put(msg, NL80211_ATTR_FRAME, buf_len, buf))
7361 goto fail;
7362
7363 cookie = 0;
7364 ret = send_and_recv_msgs(drv, msg, cookie_handler, &cookie);
7365 msg = NULL;
7366 if (ret) {
7367 wpa_printf(MSG_DEBUG, "nl80211: Frame command failed: ret=%d "
7368 "(%s) (freq=%u wait=%u)", ret, strerror(-ret),
7369 freq, wait);
7370 } else {
7371 wpa_printf(MSG_MSGDUMP, "nl80211: Frame TX command accepted%s; "
7372 "cookie 0x%llx", no_ack ? " (no ACK)" : "",
7373 (long long unsigned int) cookie);
7374
7375 if (cookie_out)
7376 *cookie_out = no_ack ? (u64) -1 : cookie;
7377
7378 if (drv->num_send_action_cookies == MAX_SEND_ACTION_COOKIES) {
7379 wpa_printf(MSG_DEBUG,
7380 "nl80211: Drop oldest pending send action cookie 0x%llx",
7381 (long long unsigned int)
7382 drv->send_action_cookies[0]);
7383 os_memmove(&drv->send_action_cookies[0],
7384 &drv->send_action_cookies[1],
7385 (MAX_SEND_ACTION_COOKIES - 1) *
7386 sizeof(u64));
7387 drv->num_send_action_cookies--;
7388 }
7389 drv->send_action_cookies[drv->num_send_action_cookies] = cookie;
7390 drv->num_send_action_cookies++;
7391 }
7392
7393 fail:
7394 nlmsg_free(msg);
7395 return ret;
7396 }
7397
7398
7399 static int wpa_driver_nl80211_send_action(struct i802_bss *bss,
7400 unsigned int freq,
7401 unsigned int wait_time,
7402 const u8 *dst, const u8 *src,
7403 const u8 *bssid,
7404 const u8 *data, size_t data_len,
7405 int no_cck)
7406 {
7407 struct wpa_driver_nl80211_data *drv = bss->drv;
7408 int ret = -1;
7409 u8 *buf;
7410 struct ieee80211_hdr *hdr;
7411
7412 wpa_printf(MSG_DEBUG, "nl80211: Send Action frame (ifindex=%d, "
7413 "freq=%u MHz wait=%d ms no_cck=%d)",
7414 drv->ifindex, freq, wait_time, no_cck);
7415
7416 buf = os_zalloc(24 + data_len);
7417 if (buf == NULL)
7418 return ret;
7419 os_memcpy(buf + 24, data, data_len);
7420 hdr = (struct ieee80211_hdr *) buf;
7421 hdr->frame_control =
7422 IEEE80211_FC(WLAN_FC_TYPE_MGMT, WLAN_FC_STYPE_ACTION);
7423 os_memcpy(hdr->addr1, dst, ETH_ALEN);
7424 os_memcpy(hdr->addr2, src, ETH_ALEN);
7425 os_memcpy(hdr->addr3, bssid, ETH_ALEN);
7426
7427 if (os_memcmp(bss->addr, src, ETH_ALEN) != 0) {
7428 wpa_printf(MSG_DEBUG, "nl80211: Use random TA " MACSTR,
7429 MAC2STR(src));
7430 os_memcpy(bss->rand_addr, src, ETH_ALEN);
7431 } else {
7432 os_memset(bss->rand_addr, 0, ETH_ALEN);
7433 }
7434
7435 if (is_ap_interface(drv->nlmode) &&
7436 (!(drv->capa.flags & WPA_DRIVER_FLAGS_OFFCHANNEL_TX) ||
7437 (int) freq == bss->freq || drv->device_ap_sme ||
7438 !drv->use_monitor))
7439 ret = wpa_driver_nl80211_send_mlme(bss, buf, 24 + data_len,
7440 0, freq, no_cck, 1,
7441 wait_time, NULL, 0);
7442 else
7443 ret = nl80211_send_frame_cmd(bss, freq, wait_time, buf,
7444 24 + data_len,
7445 &drv->send_action_cookie,
7446 no_cck, 0, 1, NULL, 0);
7447
7448 os_free(buf);
7449 return ret;
7450 }
7451
7452
7453 static void nl80211_frame_wait_cancel(struct i802_bss *bss, u64 cookie)
7454 {
7455 struct wpa_driver_nl80211_data *drv = bss->drv;
7456 struct nl_msg *msg;
7457 int ret;
7458
7459 wpa_printf(MSG_DEBUG, "nl80211: Cancel TX frame wait: cookie=0x%llx",
7460 (long long unsigned int) cookie);
7461 if (!(msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_FRAME_WAIT_CANCEL)) ||
7462 nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie)) {
7463 nlmsg_free(msg);
7464 return;
7465 }
7466
7467 ret = send_and_recv_msgs(drv, msg, NULL, NULL);
7468 if (ret)
7469 wpa_printf(MSG_DEBUG, "nl80211: wait cancel failed: ret=%d "
7470 "(%s)", ret, strerror(-ret));
7471 }
7472
7473
7474 static void wpa_driver_nl80211_send_action_cancel_wait(void *priv)
7475 {
7476 struct i802_bss *bss = priv;
7477 struct wpa_driver_nl80211_data *drv = bss->drv;
7478 unsigned int i;
7479 u64 cookie;
7480
7481 /* Cancel the last pending TX cookie */
7482 nl80211_frame_wait_cancel(bss, drv->send_action_cookie);
7483
7484 /*
7485 * Cancel the other pending TX cookies, if any. This is needed since
7486 * the driver may keep a list of all pending offchannel TX operations
7487 * and free up the radio only once they have expired or cancelled.
7488 */
7489 for (i = drv->num_send_action_cookies; i > 0; i--) {
7490 cookie = drv->send_action_cookies[i - 1];
7491 if (cookie != drv->send_action_cookie)
7492 nl80211_frame_wait_cancel(bss, cookie);
7493 }
7494 drv->num_send_action_cookies = 0;
7495 }
7496
7497
7498 static int wpa_driver_nl80211_remain_on_channel(void *priv, unsigned int freq,
7499 unsigned int duration)
7500 {
7501 struct i802_bss *bss = priv;
7502 struct wpa_driver_nl80211_data *drv = bss->drv;
7503 struct nl_msg *msg;
7504 int ret;
7505 u64 cookie;
7506
7507 if (!(msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_REMAIN_ON_CHANNEL)) ||
7508 nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq) ||
7509 nla_put_u32(msg, NL80211_ATTR_DURATION, duration)) {
7510 nlmsg_free(msg);
7511 return -1;
7512 }
7513
7514 cookie = 0;
7515 ret = send_and_recv_msgs(drv, msg, cookie_handler, &cookie);
7516 if (ret == 0) {
7517 wpa_printf(MSG_DEBUG, "nl80211: Remain-on-channel cookie "
7518 "0x%llx for freq=%u MHz duration=%u",
7519 (long long unsigned int) cookie, freq, duration);
7520 drv->remain_on_chan_cookie = cookie;
7521 drv->pending_remain_on_chan = 1;
7522 return 0;
7523 }
7524 wpa_printf(MSG_DEBUG, "nl80211: Failed to request remain-on-channel "
7525 "(freq=%d duration=%u): %d (%s)",
7526 freq, duration, ret, strerror(-ret));
7527 return -1;
7528 }
7529
7530
7531 static int wpa_driver_nl80211_cancel_remain_on_channel(void *priv)
7532 {
7533 struct i802_bss *bss = priv;
7534 struct wpa_driver_nl80211_data *drv = bss->drv;
7535 struct nl_msg *msg;
7536 int ret;
7537
7538 if (!drv->pending_remain_on_chan) {
7539 wpa_printf(MSG_DEBUG, "nl80211: No pending remain-on-channel "
7540 "to cancel");
7541 return -1;
7542 }
7543
7544 wpa_printf(MSG_DEBUG, "nl80211: Cancel remain-on-channel with cookie "
7545 "0x%llx",
7546 (long long unsigned int) drv->remain_on_chan_cookie);
7547
7548 msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL);
7549 if (!msg ||
7550 nla_put_u64(msg, NL80211_ATTR_COOKIE, drv->remain_on_chan_cookie)) {
7551 nlmsg_free(msg);
7552 return -1;
7553 }
7554
7555 ret = send_and_recv_msgs(drv, msg, NULL, NULL);
7556 if (ret == 0)
7557 return 0;
7558 wpa_printf(MSG_DEBUG, "nl80211: Failed to cancel remain-on-channel: "
7559 "%d (%s)", ret, strerror(-ret));
7560 return -1;
7561 }
7562
7563
7564 static int wpa_driver_nl80211_probe_req_report(struct i802_bss *bss, int report)
7565 {
7566 struct wpa_driver_nl80211_data *drv = bss->drv;
7567
7568 if (!report) {
7569 if (bss->nl_preq && drv->device_ap_sme &&
7570 is_ap_interface(drv->nlmode) && !bss->in_deinit &&
7571 !bss->static_ap) {
7572 /*
7573 * Do not disable Probe Request reporting that was
7574 * enabled in nl80211_setup_ap().
7575 */
7576 wpa_printf(MSG_DEBUG, "nl80211: Skip disabling of "
7577 "Probe Request reporting nl_preq=%p while "
7578 "in AP mode", bss->nl_preq);
7579 } else if (bss->nl_preq) {
7580 wpa_printf(MSG_DEBUG, "nl80211: Disable Probe Request "
7581 "reporting nl_preq=%p", bss->nl_preq);
7582 nl80211_destroy_eloop_handle(&bss->nl_preq, 0);
7583 }
7584 return 0;
7585 }
7586
7587 if (bss->nl_preq) {
7588 wpa_printf(MSG_DEBUG, "nl80211: Probe Request reporting "
7589 "already on! nl_preq=%p", bss->nl_preq);
7590 return 0;
7591 }
7592
7593 bss->nl_preq = nl_create_handle(drv->global->nl_cb, "preq");
7594 if (bss->nl_preq == NULL)
7595 return -1;
7596 wpa_printf(MSG_DEBUG, "nl80211: Enable Probe Request "
7597 "reporting nl_preq=%p", bss->nl_preq);
7598
7599 if (nl80211_register_frame(bss, bss->nl_preq,
7600 (WLAN_FC_TYPE_MGMT << 2) |
7601 (WLAN_FC_STYPE_PROBE_REQ << 4),
7602 NULL, 0) < 0)
7603 goto out_err;
7604
7605 nl80211_register_eloop_read(&bss->nl_preq,
7606 wpa_driver_nl80211_event_receive,
7607 bss->nl_cb, 0);
7608
7609 return 0;
7610
7611 out_err:
7612 nl_destroy_handles(&bss->nl_preq);
7613 return -1;
7614 }
7615
7616
7617 static int nl80211_disable_11b_rates(struct wpa_driver_nl80211_data *drv,
7618 int ifindex, int disabled)
7619 {
7620 struct nl_msg *msg;
7621 struct nlattr *bands, *band;
7622 int ret;
7623
7624 wpa_printf(MSG_DEBUG,
7625 "nl80211: NL80211_CMD_SET_TX_BITRATE_MASK (ifindex=%d %s)",
7626 ifindex, disabled ? "NL80211_TXRATE_LEGACY=OFDM-only" :
7627 "no NL80211_TXRATE_LEGACY constraint");
7628
7629 msg = nl80211_ifindex_msg(drv, ifindex, 0,
7630 NL80211_CMD_SET_TX_BITRATE_MASK);
7631 if (!msg)
7632 return -1;
7633
7634 bands = nla_nest_start(msg, NL80211_ATTR_TX_RATES);
7635 if (!bands)
7636 goto fail;
7637
7638 /*
7639 * Disable 2 GHz rates 1, 2, 5.5, 11 Mbps by masking out everything
7640 * else apart from 6, 9, 12, 18, 24, 36, 48, 54 Mbps from non-MCS
7641 * rates. All 5 GHz rates are left enabled.
7642 */
7643 band = nla_nest_start(msg, NL80211_BAND_2GHZ);
7644 if (!band ||
7645 (disabled && nla_put(msg, NL80211_TXRATE_LEGACY, 8,
7646 "\x0c\x12\x18\x24\x30\x48\x60\x6c")))
7647 goto fail;
7648 nla_nest_end(msg, band);
7649
7650 nla_nest_end(msg, bands);
7651
7652 ret = send_and_recv_msgs(drv, msg, NULL, NULL);
7653 if (ret) {
7654 wpa_printf(MSG_DEBUG, "nl80211: Set TX rates failed: ret=%d "
7655 "(%s)", ret, strerror(-ret));
7656 } else
7657 drv->disabled_11b_rates = disabled;
7658
7659 return ret;
7660
7661 fail:
7662 nlmsg_free(msg);
7663 return -1;
7664 }
7665
7666
7667 static int wpa_driver_nl80211_deinit_ap(void *priv)
7668 {
7669 struct i802_bss *bss = priv;
7670 struct wpa_driver_nl80211_data *drv = bss->drv;
7671 if (!is_ap_interface(drv->nlmode))
7672 return -1;
7673 wpa_driver_nl80211_del_beacon(bss);
7674 bss->beacon_set = 0;
7675
7676 /*
7677 * If the P2P GO interface was dynamically added, then it is
7678 * possible that the interface change to station is not possible.
7679 */
7680 if (drv->nlmode == NL80211_IFTYPE_P2P_GO && bss->if_dynamic)
7681 return 0;
7682
7683 return wpa_driver_nl80211_set_mode(priv, NL80211_IFTYPE_STATION);
7684 }
7685
7686
7687 static int wpa_driver_nl80211_stop_ap(void *priv)
7688 {
7689 struct i802_bss *bss = priv;
7690 struct wpa_driver_nl80211_data *drv = bss->drv;
7691 if (!is_ap_interface(drv->nlmode))
7692 return -1;
7693 wpa_driver_nl80211_del_beacon(bss);
7694 bss->beacon_set = 0;
7695 return 0;
7696 }
7697
7698
7699 static int wpa_driver_nl80211_deinit_p2p_cli(void *priv)
7700 {
7701 struct i802_bss *bss = priv;
7702 struct wpa_driver_nl80211_data *drv = bss->drv;
7703 if (drv->nlmode != NL80211_IFTYPE_P2P_CLIENT)
7704 return -1;
7705
7706 /*
7707 * If the P2P Client interface was dynamically added, then it is
7708 * possible that the interface change to station is not possible.
7709 */
7710 if (bss->if_dynamic)
7711 return 0;
7712
7713 return wpa_driver_nl80211_set_mode(priv, NL80211_IFTYPE_STATION);
7714 }
7715
7716
7717 static void wpa_driver_nl80211_resume(void *priv)
7718 {
7719 struct i802_bss *bss = priv;
7720 enum nl80211_iftype nlmode = nl80211_get_ifmode(bss);
7721
7722 if (i802_set_iface_flags(bss, 1))
7723 wpa_printf(MSG_DEBUG, "nl80211: Failed to set interface up on resume event");
7724
7725 if (is_p2p_net_interface(nlmode))
7726 nl80211_disable_11b_rates(bss->drv, bss->drv->ifindex, 1);
7727 }
7728
7729
7730 static int nl80211_signal_monitor(void *priv, int threshold, int hysteresis)
7731 {
7732 struct i802_bss *bss = priv;
7733 struct wpa_driver_nl80211_data *drv = bss->drv;
7734 struct nl_msg *msg;
7735 struct nlattr *cqm;
7736
7737 wpa_printf(MSG_DEBUG, "nl80211: Signal monitor threshold=%d "
7738 "hysteresis=%d", threshold, hysteresis);
7739
7740 if (!(msg = nl80211_bss_msg(bss, 0, NL80211_CMD_SET_CQM)) ||
7741 !(cqm = nla_nest_start(msg, NL80211_ATTR_CQM)) ||
7742 nla_put_u32(msg, NL80211_ATTR_CQM_RSSI_THOLD, threshold) ||
7743 nla_put_u32(msg, NL80211_ATTR_CQM_RSSI_HYST, hysteresis)) {
7744 nlmsg_free(msg);
7745 return -1;
7746 }
7747 nla_nest_end(msg, cqm);
7748
7749 return send_and_recv_msgs(drv, msg, NULL, NULL);
7750 }
7751
7752
7753 static int get_channel_width(struct nl_msg *msg, void *arg)
7754 {
7755 struct nlattr *tb[NL80211_ATTR_MAX + 1];
7756 struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg));
7757 struct wpa_signal_info *sig_change = arg;
7758
7759 nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0),
7760 genlmsg_attrlen(gnlh, 0), NULL);
7761
7762 sig_change->center_frq1 = -1;
7763 sig_change->center_frq2 = -1;
7764 sig_change->chanwidth = CHAN_WIDTH_UNKNOWN;
7765
7766 if (tb[NL80211_ATTR_CHANNEL_WIDTH]) {
7767 sig_change->chanwidth = convert2width(
7768 nla_get_u32(tb[NL80211_ATTR_CHANNEL_WIDTH]));
7769 if (tb[NL80211_ATTR_CENTER_FREQ1])
7770 sig_change->center_frq1 =
7771 nla_get_u32(tb[NL80211_ATTR_CENTER_FREQ1]);
7772 if (tb[NL80211_ATTR_CENTER_FREQ2])
7773 sig_change->center_frq2 =
7774 nla_get_u32(tb[NL80211_ATTR_CENTER_FREQ2]);
7775 }
7776
7777 return NL_SKIP;
7778 }
7779
7780
7781 static int nl80211_get_channel_width(struct wpa_driver_nl80211_data *drv,
7782 struct wpa_signal_info *sig)
7783 {
7784 struct nl_msg *msg;
7785
7786 msg = nl80211_drv_msg(drv, 0, NL80211_CMD_GET_INTERFACE);
7787 return send_and_recv_msgs(drv, msg, get_channel_width, sig);
7788 }
7789
7790
7791 static int nl80211_signal_poll(void *priv, struct wpa_signal_info *si)
7792 {
7793 struct i802_bss *bss = priv;
7794 struct wpa_driver_nl80211_data *drv = bss->drv;
7795 int res;
7796
7797 os_memset(si, 0, sizeof(*si));
7798 res = nl80211_get_link_signal(drv, si);
7799 if (res) {
7800 if (drv->nlmode != NL80211_IFTYPE_ADHOC &&
7801 drv->nlmode != NL80211_IFTYPE_MESH_POINT)
7802 return res;
7803 si->current_signal = 0;
7804 }
7805
7806 res = nl80211_get_channel_width(drv, si);
7807 if (res != 0)
7808 return res;
7809
7810 return nl80211_get_link_noise(drv, si);
7811 }
7812
7813
7814 static int nl80211_send_frame(void *priv, const u8 *data, size_t data_len,
7815 int encrypt)
7816 {
7817 struct i802_bss *bss = priv;
7818 return wpa_driver_nl80211_send_frame(bss, data, data_len, encrypt, 0,
7819 0, 0, 0, 0, NULL, 0);
7820 }
7821
7822
7823 static int nl80211_set_param(void *priv, const char *param)
7824 {
7825 struct i802_bss *bss = priv;
7826 struct wpa_driver_nl80211_data *drv = bss->drv;
7827
7828 if (param == NULL)
7829 return 0;
7830 wpa_printf(MSG_DEBUG, "nl80211: driver param='%s'", param);
7831
7832 #ifdef CONFIG_P2P
7833 if (os_strstr(param, "use_p2p_group_interface=1")) {
7834 wpa_printf(MSG_DEBUG, "nl80211: Use separate P2P group "
7835 "interface");
7836 drv->capa.flags |= WPA_DRIVER_FLAGS_P2P_CONCURRENT;
7837 drv->capa.flags |= WPA_DRIVER_FLAGS_P2P_MGMT_AND_NON_P2P;
7838 }
7839 #endif /* CONFIG_P2P */
7840
7841 if (os_strstr(param, "use_monitor=1"))
7842 drv->use_monitor = 1;
7843
7844 if (os_strstr(param, "force_connect_cmd=1")) {
7845 drv->capa.flags &= ~WPA_DRIVER_FLAGS_SME;
7846 drv->force_connect_cmd = 1;
7847 }
7848
7849 if (os_strstr(param, "force_bss_selection=1"))
7850 drv->capa.flags |= WPA_DRIVER_FLAGS_BSS_SELECTION;
7851
7852 if (os_strstr(param, "no_offchannel_tx=1")) {
7853 drv->capa.flags &= ~WPA_DRIVER_FLAGS_OFFCHANNEL_TX;
7854 drv->test_use_roc_tx = 1;
7855 }
7856
7857 return 0;
7858 }
7859
7860
7861 static void * nl80211_global_init(void *ctx)
7862 {
7863 struct nl80211_global *global;
7864 struct netlink_config *cfg;
7865
7866 global = os_zalloc(sizeof(*global));
7867 if (global == NULL)
7868 return NULL;
7869 global->ctx = ctx;
7870 global->ioctl_sock = -1;
7871 dl_list_init(&global->interfaces);
7872 global->if_add_ifindex = -1;
7873
7874 cfg = os_zalloc(sizeof(*cfg));
7875 if (cfg == NULL)
7876 goto err;
7877
7878 cfg->ctx = global;
7879 cfg->newlink_cb = wpa_driver_nl80211_event_rtm_newlink;
7880 cfg->dellink_cb = wpa_driver_nl80211_event_rtm_dellink;
7881 global->netlink = netlink_init(cfg);
7882 if (global->netlink == NULL) {
7883 os_free(cfg);
7884 goto err;
7885 }
7886
7887 if (wpa_driver_nl80211_init_nl_global(global) < 0)
7888 goto err;
7889
7890 global->ioctl_sock = socket(PF_INET, SOCK_DGRAM, 0);
7891 if (global->ioctl_sock < 0) {
7892 wpa_printf(MSG_ERROR, "nl80211: socket(PF_INET,SOCK_DGRAM) failed: %s",
7893 strerror(errno));
7894 goto err;
7895 }
7896
7897 return global;
7898
7899 err:
7900 nl80211_global_deinit(global);
7901 return NULL;
7902 }
7903
7904
7905 static void nl80211_global_deinit(void *priv)
7906 {
7907 struct nl80211_global *global = priv;
7908 if (global == NULL)
7909 return;
7910 if (!dl_list_empty(&global->interfaces)) {
7911 wpa_printf(MSG_ERROR, "nl80211: %u interface(s) remain at "
7912 "nl80211_global_deinit",
7913 dl_list_len(&global->interfaces));
7914 }
7915
7916 if (global->netlink)
7917 netlink_deinit(global->netlink);
7918
7919 nl_destroy_handles(&global->nl);
7920
7921 if (global->nl_event)
7922 nl80211_destroy_eloop_handle(&global->nl_event, 0);
7923
7924 nl_cb_put(global->nl_cb);
7925
7926 if (global->ioctl_sock >= 0)
7927 close(global->ioctl_sock);
7928
7929 os_free(global);
7930 }
7931
7932
7933 static const char * nl80211_get_radio_name(void *priv)
7934 {
7935 struct i802_bss *bss = priv;
7936 struct wpa_driver_nl80211_data *drv = bss->drv;
7937 return drv->phyname;
7938 }
7939
7940
7941 static int nl80211_pmkid(struct i802_bss *bss, int cmd,
7942 struct wpa_pmkid_params *params)
7943 {
7944 struct nl_msg *msg;
7945 const size_t PMK_MAX_LEN = 48; /* current cfg80211 limit */
7946
7947 if (!(msg = nl80211_bss_msg(bss, 0, cmd)) ||
7948 (params->pmkid &&
7949 nla_put(msg, NL80211_ATTR_PMKID, 16, params->pmkid)) ||
7950 (params->bssid &&
7951 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, params->bssid)) ||
7952 (params->ssid_len &&
7953 nla_put(msg, NL80211_ATTR_SSID, params->ssid_len, params->ssid)) ||
7954 (params->fils_cache_id &&
7955 nla_put(msg, NL80211_ATTR_FILS_CACHE_ID, 2,
7956 params->fils_cache_id)) ||
7957 (cmd != NL80211_CMD_DEL_PMKSA &&
7958 params->pmk_len && params->pmk_len <= PMK_MAX_LEN &&
7959 nla_put(msg, NL80211_ATTR_PMK, params->pmk_len, params->pmk))) {
7960 nl80211_nlmsg_clear(msg);
7961 nlmsg_free(msg);
7962 return -ENOBUFS;
7963 }
7964
7965 return send_and_recv_msgs(bss->drv, msg, NULL, (void *) -1);
7966 }
7967
7968
7969 static int nl80211_add_pmkid(void *priv, struct wpa_pmkid_params *params)
7970 {
7971 struct i802_bss *bss = priv;
7972 int ret;
7973
7974 if (params->bssid)
7975 wpa_printf(MSG_DEBUG, "nl80211: Add PMKID for " MACSTR,
7976 MAC2STR(params->bssid));
7977 else if (params->fils_cache_id && params->ssid_len) {
7978 wpa_printf(MSG_DEBUG,
7979 "nl80211: Add PMKSA for cache id %02x%02x SSID %s",
7980 params->fils_cache_id[0], params->fils_cache_id[1],
7981 wpa_ssid_txt(params->ssid, params->ssid_len));
7982 }
7983
7984 ret = nl80211_pmkid(bss, NL80211_CMD_SET_PMKSA, params);
7985 if (ret < 0) {
7986 wpa_printf(MSG_DEBUG,
7987 "nl80211: NL80211_CMD_SET_PMKSA failed: %d (%s)",
7988 ret, strerror(-ret));
7989 }
7990
7991 return ret;
7992 }
7993
7994
7995 static int nl80211_remove_pmkid(void *priv, struct wpa_pmkid_params *params)
7996 {
7997 struct i802_bss *bss = priv;
7998 int ret;
7999
8000 if (params->bssid)
8001 wpa_printf(MSG_DEBUG, "nl80211: Delete PMKID for " MACSTR,
8002 MAC2STR(params->bssid));
8003 else if (params->fils_cache_id && params->ssid_len) {
8004 wpa_printf(MSG_DEBUG,
8005 "nl80211: Delete PMKSA for cache id %02x%02x SSID %s",
8006 params->fils_cache_id[0], params->fils_cache_id[1],
8007 wpa_ssid_txt(params->ssid, params->ssid_len));
8008 }
8009
8010 ret = nl80211_pmkid(bss, NL80211_CMD_DEL_PMKSA, params);
8011 if (ret < 0) {
8012 wpa_printf(MSG_DEBUG,
8013 "nl80211: NL80211_CMD_DEL_PMKSA failed: %d (%s)",
8014 ret, strerror(-ret));
8015 }
8016
8017 return ret;
8018 }
8019
8020
8021 static int nl80211_flush_pmkid(void *priv)
8022 {
8023 struct i802_bss *bss = priv;
8024 struct nl_msg *msg;
8025
8026 wpa_printf(MSG_DEBUG, "nl80211: Flush PMKIDs");
8027 msg = nl80211_bss_msg(bss, 0, NL80211_CMD_FLUSH_PMKSA);
8028 if (!msg)
8029 return -ENOBUFS;
8030 return send_and_recv_msgs(bss->drv, msg, NULL, NULL);
8031 }
8032
8033
8034 static void clean_survey_results(struct survey_results *survey_results)
8035 {
8036 struct freq_survey *survey, *tmp;
8037
8038 if (dl_list_empty(&survey_results->survey_list))
8039 return;
8040
8041 dl_list_for_each_safe(survey, tmp, &survey_results->survey_list,
8042 struct freq_survey, list) {
8043 dl_list_del(&survey->list);
8044 os_free(survey);
8045 }
8046 }
8047
8048
8049 static void add_survey(struct nlattr **sinfo, u32 ifidx,
8050 struct dl_list *survey_list)
8051 {
8052 struct freq_survey *survey;
8053
8054 survey = os_zalloc(sizeof(struct freq_survey));
8055 if (!survey)
8056 return;
8057
8058 survey->ifidx = ifidx;
8059 survey->freq = nla_get_u32(sinfo[NL80211_SURVEY_INFO_FREQUENCY]);
8060 survey->filled = 0;
8061
8062 if (sinfo[NL80211_SURVEY_INFO_NOISE]) {
8063 survey->nf = (int8_t)
8064 nla_get_u8(sinfo[NL80211_SURVEY_INFO_NOISE]);
8065 survey->filled |= SURVEY_HAS_NF;
8066 }
8067
8068 if (sinfo[NL80211_SURVEY_INFO_CHANNEL_TIME]) {
8069 survey->channel_time =
8070 nla_get_u64(sinfo[NL80211_SURVEY_INFO_CHANNEL_TIME]);
8071 survey->filled |= SURVEY_HAS_CHAN_TIME;
8072 }
8073
8074 if (sinfo[NL80211_SURVEY_INFO_CHANNEL_TIME_BUSY]) {
8075 survey->channel_time_busy =
8076 nla_get_u64(sinfo[NL80211_SURVEY_INFO_CHANNEL_TIME_BUSY]);
8077 survey->filled |= SURVEY_HAS_CHAN_TIME_BUSY;
8078 }
8079
8080 if (sinfo[NL80211_SURVEY_INFO_CHANNEL_TIME_RX]) {
8081 survey->channel_time_rx =
8082 nla_get_u64(sinfo[NL80211_SURVEY_INFO_CHANNEL_TIME_RX]);
8083 survey->filled |= SURVEY_HAS_CHAN_TIME_RX;
8084 }
8085
8086 if (sinfo[NL80211_SURVEY_INFO_CHANNEL_TIME_TX]) {
8087 survey->channel_time_tx =
8088 nla_get_u64(sinfo[NL80211_SURVEY_INFO_CHANNEL_TIME_TX]);
8089 survey->filled |= SURVEY_HAS_CHAN_TIME_TX;
8090 }
8091
8092 wpa_printf(MSG_DEBUG, "nl80211: Freq survey dump event (freq=%d MHz noise=%d channel_time=%ld busy_time=%ld tx_time=%ld rx_time=%ld filled=%04x)",
8093 survey->freq,
8094 survey->nf,
8095 (unsigned long int) survey->channel_time,
8096 (unsigned long int) survey->channel_time_busy,
8097 (unsigned long int) survey->channel_time_tx,
8098 (unsigned long int) survey->channel_time_rx,
8099 survey->filled);
8100
8101 dl_list_add_tail(survey_list, &survey->list);
8102 }
8103
8104
8105 static int check_survey_ok(struct nlattr **sinfo, u32 surveyed_freq,
8106 unsigned int freq_filter)
8107 {
8108 if (!freq_filter)
8109 return 1;
8110
8111 return freq_filter == surveyed_freq;
8112 }
8113
8114
8115 static int survey_handler(struct nl_msg *msg, void *arg)
8116 {
8117 struct nlattr *tb[NL80211_ATTR_MAX + 1];
8118 struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg));
8119 struct nlattr *sinfo[NL80211_SURVEY_INFO_MAX + 1];
8120 struct survey_results *survey_results;
8121 u32 surveyed_freq = 0;
8122 u32 ifidx;
8123
8124 static struct nla_policy survey_policy[NL80211_SURVEY_INFO_MAX + 1] = {
8125 [NL80211_SURVEY_INFO_FREQUENCY] = { .type = NLA_U32 },
8126 [NL80211_SURVEY_INFO_NOISE] = { .type = NLA_U8 },
8127 };
8128
8129 survey_results = (struct survey_results *) arg;
8130
8131 nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0),
8132 genlmsg_attrlen(gnlh, 0), NULL);
8133
8134 if (!tb[NL80211_ATTR_IFINDEX])
8135 return NL_SKIP;
8136
8137 ifidx = nla_get_u32(tb[NL80211_ATTR_IFINDEX]);
8138
8139 if (!tb[NL80211_ATTR_SURVEY_INFO])
8140 return NL_SKIP;
8141
8142 if (nla_parse_nested(sinfo, NL80211_SURVEY_INFO_MAX,
8143 tb[NL80211_ATTR_SURVEY_INFO],
8144 survey_policy))
8145 return NL_SKIP;
8146
8147 if (!sinfo[NL80211_SURVEY_INFO_FREQUENCY]) {
8148 wpa_printf(MSG_ERROR, "nl80211: Invalid survey data");
8149 return NL_SKIP;
8150 }
8151
8152 surveyed_freq = nla_get_u32(sinfo[NL80211_SURVEY_INFO_FREQUENCY]);
8153
8154 if (!check_survey_ok(sinfo, surveyed_freq,
8155 survey_results->freq_filter))
8156 return NL_SKIP;
8157
8158 if (survey_results->freq_filter &&
8159 survey_results->freq_filter != surveyed_freq) {
8160 wpa_printf(MSG_EXCESSIVE, "nl80211: Ignoring survey data for freq %d MHz",
8161 surveyed_freq);
8162 return NL_SKIP;
8163 }
8164
8165 add_survey(sinfo, ifidx, &survey_results->survey_list);
8166
8167 return NL_SKIP;
8168 }
8169
8170
8171 static int wpa_driver_nl80211_get_survey(void *priv, unsigned int freq)
8172 {
8173 struct i802_bss *bss = priv;
8174 struct wpa_driver_nl80211_data *drv = bss->drv;
8175 struct nl_msg *msg;
8176 int err;
8177 union wpa_event_data data;
8178 struct survey_results *survey_results;
8179
8180 os_memset(&data, 0, sizeof(data));
8181 survey_results = &data.survey_results;
8182
8183 dl_list_init(&survey_results->survey_list);
8184
8185 msg = nl80211_drv_msg(drv, NLM_F_DUMP, NL80211_CMD_GET_SURVEY);
8186 if (!msg)
8187 return -ENOBUFS;
8188
8189 if (freq)
8190 data.survey_results.freq_filter = freq;
8191
8192 do {
8193 wpa_printf(MSG_DEBUG, "nl80211: Fetch survey data");
8194 err = send_and_recv_msgs(drv, msg, survey_handler,
8195 survey_results);
8196 } while (err > 0);
8197
8198 if (err)
8199 wpa_printf(MSG_ERROR, "nl80211: Failed to process survey data");
8200 else
8201 wpa_supplicant_event(drv->ctx, EVENT_SURVEY, &data);
8202
8203 clean_survey_results(survey_results);
8204 return err;
8205 }
8206
8207
8208 static void nl80211_set_rekey_info(void *priv, const u8 *kek, size_t kek_len,
8209 const u8 *kck, size_t kck_len,
8210 const u8 *replay_ctr)
8211 {
8212 struct i802_bss *bss = priv;
8213 struct wpa_driver_nl80211_data *drv = bss->drv;
8214 struct nlattr *replay_nested;
8215 struct nl_msg *msg;
8216 int ret;
8217
8218 if (!drv->set_rekey_offload)
8219 return;
8220
8221 wpa_printf(MSG_DEBUG, "nl80211: Set rekey offload");
8222 if (!(msg = nl80211_bss_msg(bss, 0, NL80211_CMD_SET_REKEY_OFFLOAD)) ||
8223 !(replay_nested = nla_nest_start(msg, NL80211_ATTR_REKEY_DATA)) ||
8224 nla_put(msg, NL80211_REKEY_DATA_KEK, kek_len, kek) ||
8225 (kck_len && nla_put(msg, NL80211_REKEY_DATA_KCK, kck_len, kck)) ||
8226 nla_put(msg, NL80211_REKEY_DATA_REPLAY_CTR, NL80211_REPLAY_CTR_LEN,
8227 replay_ctr)) {
8228 nl80211_nlmsg_clear(msg);
8229 nlmsg_free(msg);
8230 return;
8231 }
8232
8233 nla_nest_end(msg, replay_nested);
8234
8235 ret = send_and_recv_msgs(drv, msg, NULL, (void *) -1);
8236 if (ret == -EOPNOTSUPP) {
8237 wpa_printf(MSG_DEBUG,
8238 "nl80211: Driver does not support rekey offload");
8239 drv->set_rekey_offload = 0;
8240 }
8241 }
8242
8243
8244 static void nl80211_send_null_frame(struct i802_bss *bss, const u8 *own_addr,
8245 const u8 *addr, int qos)
8246 {
8247 /* send data frame to poll STA and check whether
8248 * this frame is ACKed */
8249 struct {
8250 struct ieee80211_hdr hdr;
8251 u16 qos_ctl;
8252 } STRUCT_PACKED nulldata;
8253 size_t size;
8254
8255 /* Send data frame to poll STA and check whether this frame is ACKed */
8256
8257 os_memset(&nulldata, 0, sizeof(nulldata));
8258
8259 if (qos) {
8260 nulldata.hdr.frame_control =
8261 IEEE80211_FC(WLAN_FC_TYPE_DATA,
8262 WLAN_FC_STYPE_QOS_NULL);
8263 size = sizeof(nulldata);
8264 } else {
8265 nulldata.hdr.frame_control =
8266 IEEE80211_FC(WLAN_FC_TYPE_DATA,
8267 WLAN_FC_STYPE_NULLFUNC);
8268 size = sizeof(struct ieee80211_hdr);
8269 }
8270
8271 nulldata.hdr.frame_control |= host_to_le16(WLAN_FC_FROMDS);
8272 os_memcpy(nulldata.hdr.IEEE80211_DA_FROMDS, addr, ETH_ALEN);
8273 os_memcpy(nulldata.hdr.IEEE80211_BSSID_FROMDS, own_addr, ETH_ALEN);
8274 os_memcpy(nulldata.hdr.IEEE80211_SA_FROMDS, own_addr, ETH_ALEN);
8275
8276 if (wpa_driver_nl80211_send_mlme(bss, (u8 *) &nulldata, size, 0, 0, 0,
8277 0, 0, NULL, 0) < 0)
8278 wpa_printf(MSG_DEBUG, "nl80211_send_null_frame: Failed to "
8279 "send poll frame");
8280 }
8281
8282 static void nl80211_poll_client(void *priv, const u8 *own_addr, const u8 *addr,
8283 int qos)
8284 {
8285 struct i802_bss *bss = priv;
8286 struct wpa_driver_nl80211_data *drv = bss->drv;
8287 struct nl_msg *msg;
8288 int ret;
8289
8290 if (!drv->poll_command_supported) {
8291 nl80211_send_null_frame(bss, own_addr, addr, qos);
8292 return;
8293 }
8294
8295 if (!(msg = nl80211_bss_msg(bss, 0, NL80211_CMD_PROBE_CLIENT)) ||
8296 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) {
8297 nlmsg_free(msg);
8298 return;
8299 }
8300
8301 ret = send_and_recv_msgs(drv, msg, NULL, NULL);
8302 if (ret < 0) {
8303 wpa_printf(MSG_DEBUG, "nl80211: Client probe request for "
8304 MACSTR " failed: ret=%d (%s)",
8305 MAC2STR(addr), ret, strerror(-ret));
8306 }
8307 }
8308
8309
8310 static int nl80211_set_power_save(struct i802_bss *bss, int enabled)
8311 {
8312 struct nl_msg *msg;
8313 int ret;
8314
8315 if (!(msg = nl80211_bss_msg(bss, 0, NL80211_CMD_SET_POWER_SAVE)) ||
8316 nla_put_u32(msg, NL80211_ATTR_PS_STATE,
8317 enabled ? NL80211_PS_ENABLED : NL80211_PS_DISABLED)) {
8318 nlmsg_free(msg);
8319 return -ENOBUFS;
8320 }
8321
8322 ret = send_and_recv_msgs(bss->drv, msg, NULL, NULL);
8323 if (ret < 0) {
8324 wpa_printf(MSG_DEBUG,
8325 "nl80211: Setting PS state %s failed: %d (%s)",
8326 enabled ? "enabled" : "disabled",
8327 ret, strerror(-ret));
8328 }
8329 return ret;
8330 }
8331
8332
8333 static int nl80211_set_p2p_powersave(void *priv, int legacy_ps, int opp_ps,
8334 int ctwindow)
8335 {
8336 struct i802_bss *bss = priv;
8337
8338 wpa_printf(MSG_DEBUG, "nl80211: set_p2p_powersave (legacy_ps=%d "
8339 "opp_ps=%d ctwindow=%d)", legacy_ps, opp_ps, ctwindow);
8340
8341 if (opp_ps != -1 || ctwindow != -1) {
8342 #ifdef ANDROID_P2P
8343 wpa_driver_set_p2p_ps(priv, legacy_ps, opp_ps, ctwindow);
8344 #else /* ANDROID_P2P */
8345 return -1; /* Not yet supported */
8346 #endif /* ANDROID_P2P */
8347 }
8348
8349 if (legacy_ps == -1)
8350 return 0;
8351 if (legacy_ps != 0 && legacy_ps != 1)
8352 return -1; /* Not yet supported */
8353
8354 return nl80211_set_power_save(bss, legacy_ps);
8355 }
8356
8357
8358 static int nl80211_start_radar_detection(void *priv,
8359 struct hostapd_freq_params *freq)
8360 {
8361 struct i802_bss *bss = priv;
8362 struct wpa_driver_nl80211_data *drv = bss->drv;
8363 struct nl_msg *msg;
8364 int ret;
8365
8366 wpa_printf(MSG_DEBUG, "nl80211: Start radar detection (CAC) %d MHz (ht_enabled=%d, vht_enabled=%d, bandwidth=%d MHz, cf1=%d MHz, cf2=%d MHz)",
8367 freq->freq, freq->ht_enabled, freq->vht_enabled,
8368 freq->bandwidth, freq->center_freq1, freq->center_freq2);
8369
8370 if (!(drv->capa.flags & WPA_DRIVER_FLAGS_RADAR)) {
8371 wpa_printf(MSG_DEBUG, "nl80211: Driver does not support radar "
8372 "detection");
8373 return -1;
8374 }
8375
8376 if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_RADAR_DETECT)) ||
8377 nl80211_put_freq_params(msg, freq) < 0) {
8378 nlmsg_free(msg);
8379 return -1;
8380 }
8381
8382 ret = send_and_recv_msgs(drv, msg, NULL, NULL);
8383 if (ret == 0)
8384 return 0;
8385 wpa_printf(MSG_DEBUG, "nl80211: Failed to start radar detection: "
8386 "%d (%s)", ret, strerror(-ret));
8387 return -1;
8388 }
8389
8390 #ifdef CONFIG_TDLS
8391
8392 static int nl80211_send_tdls_mgmt(void *priv, const u8 *dst, u8 action_code,
8393 u8 dialog_token, u16 status_code,
8394 u32 peer_capab, int initiator, const u8 *buf,
8395 size_t len)
8396 {
8397 struct i802_bss *bss = priv;
8398 struct wpa_driver_nl80211_data *drv = bss->drv;
8399 struct nl_msg *msg;
8400
8401 if (!(drv->capa.flags & WPA_DRIVER_FLAGS_TDLS_SUPPORT))
8402 return -EOPNOTSUPP;
8403
8404 if (!dst)
8405 return -EINVAL;
8406
8407 if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_TDLS_MGMT)) ||
8408 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, dst) ||
8409 nla_put_u8(msg, NL80211_ATTR_TDLS_ACTION, action_code) ||
8410 nla_put_u8(msg, NL80211_ATTR_TDLS_DIALOG_TOKEN, dialog_token) ||
8411 nla_put_u16(msg, NL80211_ATTR_STATUS_CODE, status_code))
8412 goto fail;
8413 if (peer_capab) {
8414 /*
8415 * The internal enum tdls_peer_capability definition is
8416 * currently identical with the nl80211 enum
8417 * nl80211_tdls_peer_capability, so no conversion is needed
8418 * here.
8419 */
8420 if (nla_put_u32(msg, NL80211_ATTR_TDLS_PEER_CAPABILITY,
8421 peer_capab))
8422 goto fail;
8423 }
8424 if ((initiator &&
8425 nla_put_flag(msg, NL80211_ATTR_TDLS_INITIATOR)) ||
8426 nla_put(msg, NL80211_ATTR_IE, len, buf))
8427 goto fail;
8428
8429 return send_and_recv_msgs(drv, msg, NULL, NULL);
8430
8431 fail:
8432 nlmsg_free(msg);
8433 return -ENOBUFS;
8434 }
8435
8436
8437 static int nl80211_tdls_oper(void *priv, enum tdls_oper oper, const u8 *peer)
8438 {
8439 struct i802_bss *bss = priv;
8440 struct wpa_driver_nl80211_data *drv = bss->drv;
8441 struct nl_msg *msg;
8442 enum nl80211_tdls_operation nl80211_oper;
8443 int res;
8444
8445 if (!(drv->capa.flags & WPA_DRIVER_FLAGS_TDLS_SUPPORT))
8446 return -EOPNOTSUPP;
8447
8448 switch (oper) {
8449 case TDLS_DISCOVERY_REQ:
8450 nl80211_oper = NL80211_TDLS_DISCOVERY_REQ;
8451 break;
8452 case TDLS_SETUP:
8453 nl80211_oper = NL80211_TDLS_SETUP;
8454 break;
8455 case TDLS_TEARDOWN:
8456 nl80211_oper = NL80211_TDLS_TEARDOWN;
8457 break;
8458 case TDLS_ENABLE_LINK:
8459 nl80211_oper = NL80211_TDLS_ENABLE_LINK;
8460 break;
8461 case TDLS_DISABLE_LINK:
8462 nl80211_oper = NL80211_TDLS_DISABLE_LINK;
8463 break;
8464 case TDLS_ENABLE:
8465 return 0;
8466 case TDLS_DISABLE:
8467 return 0;
8468 default:
8469 return -EINVAL;
8470 }
8471
8472 if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_TDLS_OPER)) ||
8473 nla_put_u8(msg, NL80211_ATTR_TDLS_OPERATION, nl80211_oper) ||
8474 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer)) {
8475 nlmsg_free(msg);
8476 return -ENOBUFS;
8477 }
8478
8479 res = send_and_recv_msgs(drv, msg, NULL, NULL);
8480 wpa_printf(MSG_DEBUG, "nl80211: TDLS_OPER: oper=%d mac=" MACSTR
8481 " --> res=%d (%s)", nl80211_oper, MAC2STR(peer), res,
8482 strerror(-res));
8483 return res;
8484 }
8485
8486
8487 static int
8488 nl80211_tdls_enable_channel_switch(void *priv, const u8 *addr, u8 oper_class,
8489 const struct hostapd_freq_params *params)
8490 {
8491 struct i802_bss *bss = priv;
8492 struct wpa_driver_nl80211_data *drv = bss->drv;
8493 struct nl_msg *msg;
8494 int ret = -ENOBUFS;
8495
8496 if (!(drv->capa.flags & WPA_DRIVER_FLAGS_TDLS_SUPPORT) ||
8497 !(drv->capa.flags & WPA_DRIVER_FLAGS_TDLS_CHANNEL_SWITCH))
8498 return -EOPNOTSUPP;
8499
8500 wpa_printf(MSG_DEBUG, "nl80211: Enable TDLS channel switch " MACSTR
8501 " oper_class=%u freq=%u",
8502 MAC2STR(addr), oper_class, params->freq);
8503 msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_TDLS_CHANNEL_SWITCH);
8504 if (!msg ||
8505 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) ||
8506 nla_put_u8(msg, NL80211_ATTR_OPER_CLASS, oper_class) ||
8507 (ret = nl80211_put_freq_params(msg, params))) {
8508 nlmsg_free(msg);
8509 wpa_printf(MSG_DEBUG, "nl80211: Could not build TDLS chan switch");
8510 return ret;
8511 }
8512
8513 return send_and_recv_msgs(drv, msg, NULL, NULL);
8514 }
8515
8516
8517 static int
8518 nl80211_tdls_disable_channel_switch(void *priv, const u8 *addr)
8519 {
8520 struct i802_bss *bss = priv;
8521 struct wpa_driver_nl80211_data *drv = bss->drv;
8522 struct nl_msg *msg;
8523
8524 if (!(drv->capa.flags & WPA_DRIVER_FLAGS_TDLS_SUPPORT) ||
8525 !(drv->capa.flags & WPA_DRIVER_FLAGS_TDLS_CHANNEL_SWITCH))
8526 return -EOPNOTSUPP;
8527
8528 wpa_printf(MSG_DEBUG, "nl80211: Disable TDLS channel switch " MACSTR,
8529 MAC2STR(addr));
8530 msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_TDLS_CANCEL_CHANNEL_SWITCH);
8531 if (!msg ||
8532 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) {
8533 nlmsg_free(msg);
8534 wpa_printf(MSG_DEBUG,
8535 "nl80211: Could not build TDLS cancel chan switch");
8536 return -ENOBUFS;
8537 }
8538
8539 return send_and_recv_msgs(drv, msg, NULL, NULL);
8540 }
8541
8542 #endif /* CONFIG TDLS */
8543
8544
8545 static int driver_nl80211_set_key(const char *ifname, void *priv,
8546 enum wpa_alg alg, const u8 *addr,
8547 int key_idx, int set_tx,
8548 const u8 *seq, size_t seq_len,
8549 const u8 *key, size_t key_len)
8550 {
8551 struct i802_bss *bss = priv;
8552 return wpa_driver_nl80211_set_key(ifname, bss, alg, addr, key_idx,
8553 set_tx, seq, seq_len, key, key_len);
8554 }
8555
8556
8557 static int driver_nl80211_scan2(void *priv,
8558 struct wpa_driver_scan_params *params)
8559 {
8560 struct i802_bss *bss = priv;
8561 #ifdef CONFIG_DRIVER_NL80211_QCA
8562 struct wpa_driver_nl80211_data *drv = bss->drv;
8563
8564 /*
8565 * Do a vendor specific scan if possible. If only_new_results is
8566 * set, do a normal scan since a kernel (cfg80211) BSS cache flush
8567 * cannot be achieved through a vendor scan. The below condition may
8568 * need to be modified if new scan flags are added in the future whose
8569 * functionality can only be achieved through a normal scan.
8570 */
8571 if (drv->scan_vendor_cmd_avail && !params->only_new_results)
8572 return wpa_driver_nl80211_vendor_scan(bss, params);
8573 #endif /* CONFIG_DRIVER_NL80211_QCA */
8574 return wpa_driver_nl80211_scan(bss, params);
8575 }
8576
8577
8578 static int driver_nl80211_deauthenticate(void *priv, const u8 *addr,
8579 int reason_code)
8580 {
8581 struct i802_bss *bss = priv;
8582 return wpa_driver_nl80211_deauthenticate(bss, addr, reason_code);
8583 }
8584
8585
8586 static int driver_nl80211_authenticate(void *priv,
8587 struct wpa_driver_auth_params *params)
8588 {
8589 struct i802_bss *bss = priv;
8590 return wpa_driver_nl80211_authenticate(bss, params);
8591 }
8592
8593
8594 static void driver_nl80211_deinit(void *priv)
8595 {
8596 struct i802_bss *bss = priv;
8597 wpa_driver_nl80211_deinit(bss);
8598 }
8599
8600
8601 static int driver_nl80211_if_remove(void *priv, enum wpa_driver_if_type type,
8602 const char *ifname)
8603 {
8604 struct i802_bss *bss = priv;
8605 return wpa_driver_nl80211_if_remove(bss, type, ifname);
8606 }
8607
8608
8609 static int driver_nl80211_send_mlme(void *priv, const u8 *data,
8610 size_t data_len, int noack,
8611 unsigned int freq,
8612 const u16 *csa_offs, size_t csa_offs_len)
8613 {
8614 struct i802_bss *bss = priv;
8615 return wpa_driver_nl80211_send_mlme(bss, data, data_len, noack,
8616 freq, 0, 0, 0, csa_offs,
8617 csa_offs_len);
8618 }
8619
8620
8621 static int driver_nl80211_sta_remove(void *priv, const u8 *addr)
8622 {
8623 struct i802_bss *bss = priv;
8624 return wpa_driver_nl80211_sta_remove(bss, addr, -1, 0);
8625 }
8626
8627
8628 static int driver_nl80211_set_sta_vlan(void *priv, const u8 *addr,
8629 const char *ifname, int vlan_id)
8630 {
8631 struct i802_bss *bss = priv;
8632 return i802_set_sta_vlan(bss, addr, ifname, vlan_id);
8633 }
8634
8635
8636 static int driver_nl80211_read_sta_data(void *priv,
8637 struct hostap_sta_driver_data *data,
8638 const u8 *addr)
8639 {
8640 struct i802_bss *bss = priv;
8641
8642 os_memset(data, 0, sizeof(*data));
8643 return i802_read_sta_data(bss, data, addr);
8644 }
8645
8646
8647 static int driver_nl80211_send_action(void *priv, unsigned int freq,
8648 unsigned int wait_time,
8649 const u8 *dst, const u8 *src,
8650 const u8 *bssid,
8651 const u8 *data, size_t data_len,
8652 int no_cck)
8653 {
8654 struct i802_bss *bss = priv;
8655 return wpa_driver_nl80211_send_action(bss, freq, wait_time, dst, src,
8656 bssid, data, data_len, no_cck);
8657 }
8658
8659
8660 static int driver_nl80211_probe_req_report(void *priv, int report)
8661 {
8662 struct i802_bss *bss = priv;
8663 return wpa_driver_nl80211_probe_req_report(bss, report);
8664 }
8665
8666
8667 static int wpa_driver_nl80211_update_ft_ies(void *priv, const u8 *md,
8668 const u8 *ies, size_t ies_len)
8669 {
8670 int ret;
8671 struct nl_msg *msg;
8672 struct i802_bss *bss = priv;
8673 struct wpa_driver_nl80211_data *drv = bss->drv;
8674 u16 mdid = WPA_GET_LE16(md);
8675
8676 wpa_printf(MSG_DEBUG, "nl80211: Updating FT IEs");
8677 if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_UPDATE_FT_IES)) ||
8678 nla_put(msg, NL80211_ATTR_IE, ies_len, ies) ||
8679 nla_put_u16(msg, NL80211_ATTR_MDID, mdid)) {
8680 nlmsg_free(msg);
8681 return -ENOBUFS;
8682 }
8683
8684 ret = send_and_recv_msgs(drv, msg, NULL, NULL);
8685 if (ret) {
8686 wpa_printf(MSG_DEBUG, "nl80211: update_ft_ies failed "
8687 "err=%d (%s)", ret, strerror(-ret));
8688 }
8689
8690 return ret;
8691 }
8692
8693
8694 static const u8 * wpa_driver_nl80211_get_macaddr(void *priv)
8695 {
8696 struct i802_bss *bss = priv;
8697 struct wpa_driver_nl80211_data *drv = bss->drv;
8698
8699 if (drv->nlmode != NL80211_IFTYPE_P2P_DEVICE)
8700 return NULL;
8701
8702 return bss->addr;
8703 }
8704
8705
8706 static const char * scan_state_str(enum scan_states scan_state)
8707 {
8708 switch (scan_state) {
8709 case NO_SCAN:
8710 return "NO_SCAN";
8711 case SCAN_REQUESTED:
8712 return "SCAN_REQUESTED";
8713 case SCAN_STARTED:
8714 return "SCAN_STARTED";
8715 case SCAN_COMPLETED:
8716 return "SCAN_COMPLETED";
8717 case SCAN_ABORTED:
8718 return "SCAN_ABORTED";
8719 case SCHED_SCAN_STARTED:
8720 return "SCHED_SCAN_STARTED";
8721 case SCHED_SCAN_STOPPED:
8722 return "SCHED_SCAN_STOPPED";
8723 case SCHED_SCAN_RESULTS:
8724 return "SCHED_SCAN_RESULTS";
8725 }
8726
8727 return "??";
8728 }
8729
8730
8731 static int wpa_driver_nl80211_status(void *priv, char *buf, size_t buflen)
8732 {
8733 struct i802_bss *bss = priv;
8734 struct wpa_driver_nl80211_data *drv = bss->drv;
8735 int res;
8736 char *pos, *end;
8737 struct nl_msg *msg;
8738 char alpha2[3] = { 0, 0, 0 };
8739
8740 pos = buf;
8741 end = buf + buflen;
8742
8743 res = os_snprintf(pos, end - pos,
8744 "ifindex=%d\n"
8745 "ifname=%s\n"
8746 "brname=%s\n"
8747 "addr=" MACSTR "\n"
8748 "freq=%d\n"
8749 "%s%s%s%s%s%s",
8750 bss->ifindex,
8751 bss->ifname,
8752 bss->brname,
8753 MAC2STR(bss->addr),
8754 bss->freq,
8755 bss->beacon_set ? "beacon_set=1\n" : "",
8756 bss->added_if_into_bridge ?
8757 "added_if_into_bridge=1\n" : "",
8758 bss->already_in_bridge ? "already_in_bridge=1\n" : "",
8759 bss->added_bridge ? "added_bridge=1\n" : "",
8760 bss->in_deinit ? "in_deinit=1\n" : "",
8761 bss->if_dynamic ? "if_dynamic=1\n" : "");
8762 if (os_snprintf_error(end - pos, res))
8763 return pos - buf;
8764 pos += res;
8765
8766 if (bss->wdev_id_set) {
8767 res = os_snprintf(pos, end - pos, "wdev_id=%llu\n",
8768 (unsigned long long) bss->wdev_id);
8769 if (os_snprintf_error(end - pos, res))
8770 return pos - buf;
8771 pos += res;
8772 }
8773
8774 res = os_snprintf(pos, end - pos,
8775 "phyname=%s\n"
8776 "perm_addr=" MACSTR "\n"
8777 "drv_ifindex=%d\n"
8778 "operstate=%d\n"
8779 "scan_state=%s\n"
8780 "auth_bssid=" MACSTR "\n"
8781 "auth_attempt_bssid=" MACSTR "\n"
8782 "bssid=" MACSTR "\n"
8783 "prev_bssid=" MACSTR "\n"
8784 "associated=%d\n"
8785 "assoc_freq=%u\n"
8786 "monitor_sock=%d\n"
8787 "monitor_ifidx=%d\n"
8788 "monitor_refcount=%d\n"
8789 "last_mgmt_freq=%u\n"
8790 "eapol_tx_sock=%d\n"
8791 "%s%s%s%s%s%s%s%s%s%s%s%s%s",
8792 drv->phyname,
8793 MAC2STR(drv->perm_addr),
8794 drv->ifindex,
8795 drv->operstate,
8796 scan_state_str(drv->scan_state),
8797 MAC2STR(drv->auth_bssid),
8798 MAC2STR(drv->auth_attempt_bssid),
8799 MAC2STR(drv->bssid),
8800 MAC2STR(drv->prev_bssid),
8801 drv->associated,
8802 drv->assoc_freq,
8803 drv->monitor_sock,
8804 drv->monitor_ifidx,
8805 drv->monitor_refcount,
8806 drv->last_mgmt_freq,
8807 drv->eapol_tx_sock,
8808 drv->ignore_if_down_event ?
8809 "ignore_if_down_event=1\n" : "",
8810 drv->scan_complete_events ?
8811 "scan_complete_events=1\n" : "",
8812 drv->disabled_11b_rates ?
8813 "disabled_11b_rates=1\n" : "",
8814 drv->pending_remain_on_chan ?
8815 "pending_remain_on_chan=1\n" : "",
8816 drv->in_interface_list ? "in_interface_list=1\n" : "",
8817 drv->device_ap_sme ? "device_ap_sme=1\n" : "",
8818 drv->poll_command_supported ?
8819 "poll_command_supported=1\n" : "",
8820 drv->data_tx_status ? "data_tx_status=1\n" : "",
8821 drv->scan_for_auth ? "scan_for_auth=1\n" : "",
8822 drv->retry_auth ? "retry_auth=1\n" : "",
8823 drv->use_monitor ? "use_monitor=1\n" : "",
8824 drv->ignore_next_local_disconnect ?
8825 "ignore_next_local_disconnect=1\n" : "",
8826 drv->ignore_next_local_deauth ?
8827 "ignore_next_local_deauth=1\n" : "");
8828 if (os_snprintf_error(end - pos, res))
8829 return pos - buf;
8830 pos += res;
8831
8832 if (drv->has_capability) {
8833 res = os_snprintf(pos, end - pos,
8834 "capa.key_mgmt=0x%x\n"
8835 "capa.enc=0x%x\n"
8836 "capa.auth=0x%x\n"
8837 "capa.flags=0x%llx\n"
8838 "capa.rrm_flags=0x%x\n"
8839 "capa.max_scan_ssids=%d\n"
8840 "capa.max_sched_scan_ssids=%d\n"
8841 "capa.sched_scan_supported=%d\n"
8842 "capa.max_match_sets=%d\n"
8843 "capa.max_remain_on_chan=%u\n"
8844 "capa.max_stations=%u\n"
8845 "capa.probe_resp_offloads=0x%x\n"
8846 "capa.max_acl_mac_addrs=%u\n"
8847 "capa.num_multichan_concurrent=%u\n"
8848 "capa.mac_addr_rand_sched_scan_supported=%d\n"
8849 "capa.mac_addr_rand_scan_supported=%d\n"
8850 "capa.conc_capab=%u\n"
8851 "capa.max_conc_chan_2_4=%u\n"
8852 "capa.max_conc_chan_5_0=%u\n"
8853 "capa.max_sched_scan_plans=%u\n"
8854 "capa.max_sched_scan_plan_interval=%u\n"
8855 "capa.max_sched_scan_plan_iterations=%u\n",
8856 drv->capa.key_mgmt,
8857 drv->capa.enc,
8858 drv->capa.auth,
8859 (unsigned long long) drv->capa.flags,
8860 drv->capa.rrm_flags,
8861 drv->capa.max_scan_ssids,
8862 drv->capa.max_sched_scan_ssids,
8863 drv->capa.sched_scan_supported,
8864 drv->capa.max_match_sets,
8865 drv->capa.max_remain_on_chan,
8866 drv->capa.max_stations,
8867 drv->capa.probe_resp_offloads,
8868 drv->capa.max_acl_mac_addrs,
8869 drv->capa.num_multichan_concurrent,
8870 drv->capa.mac_addr_rand_sched_scan_supported,
8871 drv->capa.mac_addr_rand_scan_supported,
8872 drv->capa.conc_capab,
8873 drv->capa.max_conc_chan_2_4,
8874 drv->capa.max_conc_chan_5_0,
8875 drv->capa.max_sched_scan_plans,
8876 drv->capa.max_sched_scan_plan_interval,
8877 drv->capa.max_sched_scan_plan_iterations);
8878 if (os_snprintf_error(end - pos, res))
8879 return pos - buf;
8880 pos += res;
8881 }
8882
8883 msg = nlmsg_alloc();
8884 if (msg &&
8885 nl80211_cmd(drv, msg, 0, NL80211_CMD_GET_REG) &&
8886 nla_put_u32(msg, NL80211_ATTR_WIPHY, drv->wiphy_idx) == 0) {
8887 if (send_and_recv_msgs(drv, msg, nl80211_get_country,
8888 alpha2) == 0 &&
8889 alpha2[0]) {
8890 res = os_snprintf(pos, end - pos, "country=%s\n",
8891 alpha2);
8892 if (os_snprintf_error(end - pos, res))
8893 return pos - buf;
8894 pos += res;
8895 }
8896 } else {
8897 nlmsg_free(msg);
8898 }
8899
8900 return pos - buf;
8901 }
8902
8903
8904 static int set_beacon_data(struct nl_msg *msg, struct beacon_data *settings)
8905 {
8906 if ((settings->head &&
8907 nla_put(msg, NL80211_ATTR_BEACON_HEAD,
8908 settings->head_len, settings->head)) ||
8909 (settings->tail &&
8910 nla_put(msg, NL80211_ATTR_BEACON_TAIL,
8911 settings->tail_len, settings->tail)) ||
8912 (settings->beacon_ies &&
8913 nla_put(msg, NL80211_ATTR_IE,
8914 settings->beacon_ies_len, settings->beacon_ies)) ||
8915 (settings->proberesp_ies &&
8916 nla_put(msg, NL80211_ATTR_IE_PROBE_RESP,
8917 settings->proberesp_ies_len, settings->proberesp_ies)) ||
8918 (settings->assocresp_ies &&
8919 nla_put(msg, NL80211_ATTR_IE_ASSOC_RESP,
8920 settings->assocresp_ies_len, settings->assocresp_ies)) ||
8921 (settings->probe_resp &&
8922 nla_put(msg, NL80211_ATTR_PROBE_RESP,
8923 settings->probe_resp_len, settings->probe_resp)))
8924 return -ENOBUFS;
8925
8926 return 0;
8927 }
8928
8929
8930 static int nl80211_switch_channel(void *priv, struct csa_settings *settings)
8931 {
8932 struct nl_msg *msg;
8933 struct i802_bss *bss = priv;
8934 struct wpa_driver_nl80211_data *drv = bss->drv;
8935 struct nlattr *beacon_csa;
8936 int ret = -ENOBUFS;
8937 int csa_off_len = 0;
8938 int i;
8939
8940 wpa_printf(MSG_DEBUG, "nl80211: Channel switch request (cs_count=%u block_tx=%u freq=%d width=%d cf1=%d cf2=%d)",
8941 settings->cs_count, settings->block_tx,
8942 settings->freq_params.freq, settings->freq_params.bandwidth,
8943 settings->freq_params.center_freq1,
8944 settings->freq_params.center_freq2);
8945
8946 if (!(drv->capa.flags & WPA_DRIVER_FLAGS_AP_CSA)) {
8947 wpa_printf(MSG_DEBUG, "nl80211: Driver does not support channel switch command");
8948 return -EOPNOTSUPP;
8949 }
8950
8951 if (drv->nlmode != NL80211_IFTYPE_AP &&
8952 drv->nlmode != NL80211_IFTYPE_P2P_GO &&
8953 drv->nlmode != NL80211_IFTYPE_MESH_POINT)
8954 return -EOPNOTSUPP;
8955
8956 /*
8957 * Remove empty counters, assuming Probe Response and Beacon frame
8958 * counters match. This implementation assumes that there are only two
8959 * counters.
8960 */
8961 if (settings->counter_offset_beacon[0] &&
8962 !settings->counter_offset_beacon[1]) {
8963 csa_off_len = 1;
8964 } else if (settings->counter_offset_beacon[1] &&
8965 !settings->counter_offset_beacon[0]) {
8966 csa_off_len = 1;
8967 settings->counter_offset_beacon[0] =
8968 settings->counter_offset_beacon[1];
8969 settings->counter_offset_presp[0] =
8970 settings->counter_offset_presp[1];
8971 } else if (settings->counter_offset_beacon[1] &&
8972 settings->counter_offset_beacon[0]) {
8973 csa_off_len = 2;
8974 } else {
8975 wpa_printf(MSG_ERROR, "nl80211: No CSA counters provided");
8976 return -EINVAL;
8977 }
8978
8979 /* Check CSA counters validity */
8980 if (drv->capa.max_csa_counters &&
8981 csa_off_len > drv->capa.max_csa_counters) {
8982 wpa_printf(MSG_ERROR,
8983 "nl80211: Too many CSA counters provided");
8984 return -EINVAL;
8985 }
8986
8987 if (!settings->beacon_csa.tail)
8988 return -EINVAL;
8989
8990 for (i = 0; i < csa_off_len; i++) {
8991 u16 csa_c_off_bcn = settings->counter_offset_beacon[i];
8992 u16 csa_c_off_presp = settings->counter_offset_presp[i];
8993
8994 if ((settings->beacon_csa.tail_len <= csa_c_off_bcn) ||
8995 (settings->beacon_csa.tail[csa_c_off_bcn] !=
8996 settings->cs_count))
8997 return -EINVAL;
8998
8999 if (settings->beacon_csa.probe_resp &&
9000 ((settings->beacon_csa.probe_resp_len <=
9001 csa_c_off_presp) ||
9002 (settings->beacon_csa.probe_resp[csa_c_off_presp] !=
9003 settings->cs_count)))
9004 return -EINVAL;
9005 }
9006
9007 if (!(msg = nl80211_bss_msg(bss, 0, NL80211_CMD_CHANNEL_SWITCH)) ||
9008 nla_put_u32(msg, NL80211_ATTR_CH_SWITCH_COUNT,
9009 settings->cs_count) ||
9010 (ret = nl80211_put_freq_params(msg, &settings->freq_params)) ||
9011 (settings->block_tx &&
9012 nla_put_flag(msg, NL80211_ATTR_CH_SWITCH_BLOCK_TX)))
9013 goto error;
9014
9015 /* beacon_after params */
9016 ret = set_beacon_data(msg, &settings->beacon_after);
9017 if (ret)
9018 goto error;
9019
9020 /* beacon_csa params */
9021 beacon_csa = nla_nest_start(msg, NL80211_ATTR_CSA_IES);
9022 if (!beacon_csa)
9023 goto fail;
9024
9025 ret = set_beacon_data(msg, &settings->beacon_csa);
9026 if (ret)
9027 goto error;
9028
9029 if (nla_put(msg, NL80211_ATTR_CSA_C_OFF_BEACON,
9030 csa_off_len * sizeof(u16),
9031 settings->counter_offset_beacon) ||
9032 (settings->beacon_csa.probe_resp &&
9033 nla_put(msg, NL80211_ATTR_CSA_C_OFF_PRESP,
9034 csa_off_len * sizeof(u16),
9035 settings->counter_offset_presp)))
9036 goto fail;
9037
9038 nla_nest_end(msg, beacon_csa);
9039 ret = send_and_recv_msgs(drv, msg, NULL, NULL);
9040 if (ret) {
9041 wpa_printf(MSG_DEBUG, "nl80211: switch_channel failed err=%d (%s)",
9042 ret, strerror(-ret));
9043 }
9044 return ret;
9045
9046 fail:
9047 ret = -ENOBUFS;
9048 error:
9049 nlmsg_free(msg);
9050 wpa_printf(MSG_DEBUG, "nl80211: Could not build channel switch request");
9051 return ret;
9052 }
9053
9054
9055 static int nl80211_add_ts(void *priv, u8 tsid, const u8 *addr,
9056 u8 user_priority, u16 admitted_time)
9057 {
9058 struct i802_bss *bss = priv;
9059 struct wpa_driver_nl80211_data *drv = bss->drv;
9060 struct nl_msg *msg;
9061 int ret;
9062
9063 wpa_printf(MSG_DEBUG,
9064 "nl80211: add_ts request: tsid=%u admitted_time=%u up=%d",
9065 tsid, admitted_time, user_priority);
9066
9067 if (!is_sta_interface(drv->nlmode))
9068 return -ENOTSUP;
9069
9070 msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_ADD_TX_TS);
9071 if (!msg ||
9072 nla_put_u8(msg, NL80211_ATTR_TSID, tsid) ||
9073 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) ||
9074 nla_put_u8(msg, NL80211_ATTR_USER_PRIO, user_priority) ||
9075 nla_put_u16(msg, NL80211_ATTR_ADMITTED_TIME, admitted_time)) {
9076 nlmsg_free(msg);
9077 return -ENOBUFS;
9078 }
9079
9080 ret = send_and_recv_msgs(drv, msg, NULL, NULL);
9081 if (ret)
9082 wpa_printf(MSG_DEBUG, "nl80211: add_ts failed err=%d (%s)",
9083 ret, strerror(-ret));
9084 return ret;
9085 }
9086
9087
9088 static int nl80211_del_ts(void *priv, u8 tsid, const u8 *addr)
9089 {
9090 struct i802_bss *bss = priv;
9091 struct wpa_driver_nl80211_data *drv = bss->drv;
9092 struct nl_msg *msg;
9093 int ret;
9094
9095 wpa_printf(MSG_DEBUG, "nl80211: del_ts request: tsid=%u", tsid);
9096
9097 if (!is_sta_interface(drv->nlmode))
9098 return -ENOTSUP;
9099
9100 if (!(msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_DEL_TX_TS)) ||
9101 nla_put_u8(msg, NL80211_ATTR_TSID, tsid) ||
9102 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) {
9103 nlmsg_free(msg);
9104 return -ENOBUFS;
9105 }
9106
9107 ret = send_and_recv_msgs(drv, msg, NULL, NULL);
9108 if (ret)
9109 wpa_printf(MSG_DEBUG, "nl80211: del_ts failed err=%d (%s)",
9110 ret, strerror(-ret));
9111 return ret;
9112 }
9113
9114
9115 #ifdef CONFIG_TESTING_OPTIONS
9116 static int cmd_reply_handler(struct nl_msg *msg, void *arg)
9117 {
9118 struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg));
9119 struct wpabuf *buf = arg;
9120
9121 if (!buf)
9122 return NL_SKIP;
9123
9124 if ((size_t) genlmsg_attrlen(gnlh, 0) > wpabuf_tailroom(buf)) {
9125 wpa_printf(MSG_INFO, "nl80211: insufficient buffer space for reply");
9126 return NL_SKIP;
9127 }
9128
9129 wpabuf_put_data(buf, genlmsg_attrdata(gnlh, 0),
9130 genlmsg_attrlen(gnlh, 0));
9131
9132 return NL_SKIP;
9133 }
9134 #endif /* CONFIG_TESTING_OPTIONS */
9135
9136
9137 static int vendor_reply_handler(struct nl_msg *msg, void *arg)
9138 {
9139 struct nlattr *tb[NL80211_ATTR_MAX + 1];
9140 struct nlattr *nl_vendor_reply, *nl;
9141 struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg));
9142 struct wpabuf *buf = arg;
9143 int rem;
9144
9145 if (!buf)
9146 return NL_SKIP;
9147
9148 nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0),
9149 genlmsg_attrlen(gnlh, 0), NULL);
9150 nl_vendor_reply = tb[NL80211_ATTR_VENDOR_DATA];
9151
9152 if (!nl_vendor_reply)
9153 return NL_SKIP;
9154
9155 if ((size_t) nla_len(nl_vendor_reply) > wpabuf_tailroom(buf)) {
9156 wpa_printf(MSG_INFO, "nl80211: Vendor command: insufficient buffer space for reply");
9157 return NL_SKIP;
9158 }
9159
9160 nla_for_each_nested(nl, nl_vendor_reply, rem) {
9161 wpabuf_put_data(buf, nla_data(nl), nla_len(nl));
9162 }
9163
9164 return NL_SKIP;
9165 }
9166
9167
9168 static int nl80211_vendor_cmd(void *priv, unsigned int vendor_id,
9169 unsigned int subcmd, const u8 *data,
9170 size_t data_len, struct wpabuf *buf)
9171 {
9172 struct i802_bss *bss = priv;
9173 struct wpa_driver_nl80211_data *drv = bss->drv;
9174 struct nl_msg *msg;
9175 int ret;
9176
9177 #ifdef CONFIG_TESTING_OPTIONS
9178 if (vendor_id == 0xffffffff) {
9179 msg = nlmsg_alloc();
9180 if (!msg)
9181 return -ENOMEM;
9182
9183 nl80211_cmd(drv, msg, 0, subcmd);
9184 if (nlmsg_append(msg, (void *) data, data_len, NLMSG_ALIGNTO) <
9185 0)
9186 goto fail;
9187 ret = send_and_recv_msgs(drv, msg, cmd_reply_handler, buf);
9188 if (ret)
9189 wpa_printf(MSG_DEBUG, "nl80211: command failed err=%d",
9190 ret);
9191 return ret;
9192 }
9193 #endif /* CONFIG_TESTING_OPTIONS */
9194
9195 if (!(msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_VENDOR)) ||
9196 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, vendor_id) ||
9197 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD, subcmd) ||
9198 (data &&
9199 nla_put(msg, NL80211_ATTR_VENDOR_DATA, data_len, data)))
9200 goto fail;
9201
9202 ret = send_and_recv_msgs(drv, msg, vendor_reply_handler, buf);
9203 if (ret)
9204 wpa_printf(MSG_DEBUG, "nl80211: vendor command failed err=%d",
9205 ret);
9206 return ret;
9207
9208 fail:
9209 nlmsg_free(msg);
9210 return -ENOBUFS;
9211 }
9212
9213
9214 static int nl80211_set_qos_map(void *priv, const u8 *qos_map_set,
9215 u8 qos_map_set_len)
9216 {
9217 struct i802_bss *bss = priv;
9218 struct wpa_driver_nl80211_data *drv = bss->drv;
9219 struct nl_msg *msg;
9220 int ret;
9221
9222 wpa_hexdump(MSG_DEBUG, "nl80211: Setting QoS Map",
9223 qos_map_set, qos_map_set_len);
9224
9225 if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_SET_QOS_MAP)) ||
9226 nla_put(msg, NL80211_ATTR_QOS_MAP, qos_map_set_len, qos_map_set)) {
9227 nlmsg_free(msg);
9228 return -ENOBUFS;
9229 }
9230
9231 ret = send_and_recv_msgs(drv, msg, NULL, NULL);
9232 if (ret)
9233 wpa_printf(MSG_DEBUG, "nl80211: Setting QoS Map failed");
9234
9235 return ret;
9236 }
9237
9238
9239 static int nl80211_set_wowlan(void *priv,
9240 const struct wowlan_triggers *triggers)
9241 {
9242 struct i802_bss *bss = priv;
9243 struct wpa_driver_nl80211_data *drv = bss->drv;
9244 struct nl_msg *msg;
9245 struct nlattr *wowlan_triggers;
9246 int ret;
9247
9248 wpa_printf(MSG_DEBUG, "nl80211: Setting wowlan");
9249
9250 if (!(msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_SET_WOWLAN)) ||
9251 !(wowlan_triggers = nla_nest_start(msg,
9252 NL80211_ATTR_WOWLAN_TRIGGERS)) ||
9253 (triggers->any &&
9254 nla_put_flag(msg, NL80211_WOWLAN_TRIG_ANY)) ||
9255 (triggers->disconnect &&
9256 nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) ||
9257 (triggers->magic_pkt &&
9258 nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) ||
9259 (triggers->gtk_rekey_failure &&
9260 nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) ||
9261 (triggers->eap_identity_req &&
9262 nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) ||
9263 (triggers->four_way_handshake &&
9264 nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) ||
9265 (triggers->rfkill_release &&
9266 nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE))) {
9267 nlmsg_free(msg);
9268 return -ENOBUFS;
9269 }
9270
9271 nla_nest_end(msg, wowlan_triggers);
9272
9273 ret = send_and_recv_msgs(drv, msg, NULL, NULL);
9274 if (ret)
9275 wpa_printf(MSG_DEBUG, "nl80211: Setting wowlan failed");
9276
9277 return ret;
9278 }
9279
9280
9281 #ifdef CONFIG_DRIVER_NL80211_QCA
9282 static int nl80211_roaming(void *priv, int allowed, const u8 *bssid)
9283 {
9284 struct i802_bss *bss = priv;
9285 struct wpa_driver_nl80211_data *drv = bss->drv;
9286 struct nl_msg *msg;
9287 struct nlattr *params;
9288
9289 wpa_printf(MSG_DEBUG, "nl80211: Roaming policy: allowed=%d", allowed);
9290
9291 if (!drv->roaming_vendor_cmd_avail) {
9292 wpa_printf(MSG_DEBUG,
9293 "nl80211: Ignore roaming policy change since driver does not provide command for setting it");
9294 return -1;
9295 }
9296
9297 if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_VENDOR)) ||
9298 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
9299 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
9300 QCA_NL80211_VENDOR_SUBCMD_ROAMING) ||
9301 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
9302 nla_put_u32(msg, QCA_WLAN_VENDOR_ATTR_ROAMING_POLICY,
9303 allowed ? QCA_ROAMING_ALLOWED_WITHIN_ESS :
9304 QCA_ROAMING_NOT_ALLOWED) ||
9305 (bssid &&
9306 nla_put(msg, QCA_WLAN_VENDOR_ATTR_MAC_ADDR, ETH_ALEN, bssid))) {
9307 nlmsg_free(msg);
9308 return -1;
9309 }
9310 nla_nest_end(msg, params);
9311
9312 return send_and_recv_msgs(drv, msg, NULL, NULL);
9313 }
9314
9315
9316 static int nl80211_disable_fils(void *priv, int disable)
9317 {
9318 struct i802_bss *bss = priv;
9319 struct wpa_driver_nl80211_data *drv = bss->drv;
9320 struct nl_msg *msg;
9321 struct nlattr *params;
9322
9323 wpa_printf(MSG_DEBUG, "nl80211: Disable FILS=%d", disable);
9324
9325 if (!drv->set_wifi_conf_vendor_cmd_avail)
9326 return -1;
9327
9328 if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_VENDOR)) ||
9329 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
9330 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
9331 QCA_NL80211_VENDOR_SUBCMD_SET_WIFI_CONFIGURATION) ||
9332 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
9333 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_CONFIG_DISABLE_FILS,
9334 disable)) {
9335 nlmsg_free(msg);
9336 return -1;
9337 }
9338 nla_nest_end(msg, params);
9339
9340 return send_and_recv_msgs(drv, msg, NULL, NULL);
9341 }
9342
9343
9344 /* Reserved QCA_WLAN_VENDOR_ATTR_ROAMING_REQ_ID value for wpa_supplicant */
9345 #define WPA_SUPPLICANT_CLIENT_ID 1
9346
9347 static int nl80211_set_bssid_blacklist(void *priv, unsigned int num_bssid,
9348 const u8 *bssid)
9349 {
9350 struct i802_bss *bss = priv;
9351 struct wpa_driver_nl80211_data *drv = bss->drv;
9352 struct nl_msg *msg;
9353 struct nlattr *params, *nlbssids, *attr;
9354 unsigned int i;
9355
9356 wpa_printf(MSG_DEBUG, "nl80211: Set blacklist BSSID (num=%u)",
9357 num_bssid);
9358
9359 if (!drv->roam_vendor_cmd_avail)
9360 return -1;
9361
9362 if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_VENDOR)) ||
9363 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
9364 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
9365 QCA_NL80211_VENDOR_SUBCMD_ROAM) ||
9366 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
9367 nla_put_u32(msg, QCA_WLAN_VENDOR_ATTR_ROAMING_SUBCMD,
9368 QCA_WLAN_VENDOR_ATTR_ROAM_SUBCMD_SET_BLACKLIST_BSSID) ||
9369 nla_put_u32(msg, QCA_WLAN_VENDOR_ATTR_ROAMING_REQ_ID,
9370 WPA_SUPPLICANT_CLIENT_ID) ||
9371 nla_put_u32(msg,
9372 QCA_WLAN_VENDOR_ATTR_ROAMING_PARAM_SET_BSSID_PARAMS_NUM_BSSID,
9373 num_bssid))
9374 goto fail;
9375
9376 nlbssids = nla_nest_start(
9377 msg, QCA_WLAN_VENDOR_ATTR_ROAMING_PARAM_SET_BSSID_PARAMS);
9378 if (!nlbssids)
9379 goto fail;
9380
9381 for (i = 0; i < num_bssid; i++) {
9382 attr = nla_nest_start(msg, i);
9383 if (!attr)
9384 goto fail;
9385 if (nla_put(msg,
9386 QCA_WLAN_VENDOR_ATTR_ROAMING_PARAM_SET_BSSID_PARAMS_BSSID,
9387 ETH_ALEN, &bssid[i * ETH_ALEN]))
9388 goto fail;
9389 wpa_printf(MSG_DEBUG, "nl80211: BSSID[%u]: " MACSTR, i,
9390 MAC2STR(&bssid[i * ETH_ALEN]));
9391 nla_nest_end(msg, attr);
9392 }
9393 nla_nest_end(msg, nlbssids);
9394 nla_nest_end(msg, params);
9395
9396 return send_and_recv_msgs(drv, msg, NULL, NULL);
9397
9398 fail:
9399 nlmsg_free(msg);
9400 return -1;
9401 }
9402
9403 #endif /* CONFIG_DRIVER_NL80211_QCA */
9404
9405
9406 static int nl80211_set_mac_addr(void *priv, const u8 *addr)
9407 {
9408 struct i802_bss *bss = priv;
9409 struct wpa_driver_nl80211_data *drv = bss->drv;
9410 int new_addr = addr != NULL;
9411
9412 if (TEST_FAIL())
9413 return -1;
9414
9415 if (!addr)
9416 addr = drv->perm_addr;
9417
9418 if (linux_set_iface_flags(drv->global->ioctl_sock, bss->ifname, 0) < 0)
9419 return -1;
9420
9421 if (linux_set_ifhwaddr(drv->global->ioctl_sock, bss->ifname, addr) < 0)
9422 {
9423 wpa_printf(MSG_DEBUG,
9424 "nl80211: failed to set_mac_addr for %s to " MACSTR,
9425 bss->ifname, MAC2STR(addr));
9426 if (linux_set_iface_flags(drv->global->ioctl_sock, bss->ifname,
9427 1) < 0) {
9428 wpa_printf(MSG_DEBUG,
9429 "nl80211: Could not restore interface UP after failed set_mac_addr");
9430 }
9431 return -1;
9432 }
9433
9434 wpa_printf(MSG_DEBUG, "nl80211: set_mac_addr for %s to " MACSTR,
9435 bss->ifname, MAC2STR(addr));
9436 drv->addr_changed = new_addr;
9437 os_memcpy(bss->addr, addr, ETH_ALEN);
9438
9439 if (linux_set_iface_flags(drv->global->ioctl_sock, bss->ifname, 1) < 0)
9440 {
9441 wpa_printf(MSG_DEBUG,
9442 "nl80211: Could not restore interface UP after set_mac_addr");
9443 }
9444
9445 return 0;
9446 }
9447
9448
9449 #ifdef CONFIG_MESH
9450
9451 static int wpa_driver_nl80211_init_mesh(void *priv)
9452 {
9453 if (wpa_driver_nl80211_set_mode(priv, NL80211_IFTYPE_MESH_POINT)) {
9454 wpa_printf(MSG_INFO,
9455 "nl80211: Failed to set interface into mesh mode");
9456 return -1;
9457 }
9458 return 0;
9459 }
9460
9461
9462 static int nl80211_put_mesh_id(struct nl_msg *msg, const u8 *mesh_id,
9463 size_t mesh_id_len)
9464 {
9465 if (mesh_id) {
9466 wpa_printf(MSG_DEBUG, " * Mesh ID (SSID)=%s",
9467 wpa_ssid_txt(mesh_id, mesh_id_len));
9468 return nla_put(msg, NL80211_ATTR_MESH_ID, mesh_id_len, mesh_id);
9469 }
9470
9471 return 0;
9472 }
9473
9474
9475 static int nl80211_put_mesh_config(struct nl_msg *msg,
9476 struct wpa_driver_mesh_bss_params *params)
9477 {
9478 struct nlattr *container;
9479
9480 container = nla_nest_start(msg, NL80211_ATTR_MESH_CONFIG);
9481 if (!container)
9482 return -1;
9483
9484 if (((params->flags & WPA_DRIVER_MESH_CONF_FLAG_AUTO_PLINKS) &&
9485 nla_put_u8(msg, NL80211_MESHCONF_AUTO_OPEN_PLINKS,
9486 params->auto_plinks)) ||
9487 ((params->flags & WPA_DRIVER_MESH_CONF_FLAG_MAX_PEER_LINKS) &&
9488 nla_put_u16(msg, NL80211_MESHCONF_MAX_PEER_LINKS,
9489 params->max_peer_links)) ||
9490 ((params->flags & WPA_DRIVER_MESH_CONF_FLAG_RSSI_THRESHOLD) &&
9491 nla_put_u32(msg, NL80211_MESHCONF_RSSI_THRESHOLD,
9492 params->rssi_threshold)))
9493 return -1;
9494
9495 /*
9496 * Set NL80211_MESHCONF_PLINK_TIMEOUT even if user mpm is used because
9497 * the timer could disconnect stations even in that case.
9498 */
9499 if ((params->flags & WPA_DRIVER_MESH_CONF_FLAG_PEER_LINK_TIMEOUT) &&
9500 nla_put_u32(msg, NL80211_MESHCONF_PLINK_TIMEOUT,
9501 params->peer_link_timeout)) {
9502 wpa_printf(MSG_ERROR, "nl80211: Failed to set PLINK_TIMEOUT");
9503 return -1;
9504 }
9505
9506 if ((params->flags & WPA_DRIVER_MESH_CONF_FLAG_HT_OP_MODE) &&
9507 nla_put_u16(msg, NL80211_MESHCONF_HT_OPMODE, params->ht_opmode)) {
9508 wpa_printf(MSG_ERROR, "nl80211: Failed to set HT_OP_MODE");
9509 return -1;
9510 }
9511
9512 nla_nest_end(msg, container);
9513
9514 return 0;
9515 }
9516
9517
9518 static int nl80211_join_mesh(struct i802_bss *bss,
9519 struct wpa_driver_mesh_join_params *params)
9520 {
9521 struct wpa_driver_nl80211_data *drv = bss->drv;
9522 struct nl_msg *msg;
9523 struct nlattr *container;
9524 int ret = -1;
9525
9526 wpa_printf(MSG_DEBUG, "nl80211: mesh join (ifindex=%d)", drv->ifindex);
9527 msg = nl80211_drv_msg(drv, 0, NL80211_CMD_JOIN_MESH);
9528 if (!msg ||
9529 nl80211_put_freq_params(msg, &params->freq) ||
9530 nl80211_put_basic_rates(msg, params->basic_rates) ||
9531 nl80211_put_mesh_id(msg, params->meshid, params->meshid_len) ||
9532 nl80211_put_beacon_int(msg, params->beacon_int) ||
9533 nl80211_put_dtim_period(msg, params->dtim_period))
9534 goto fail;
9535
9536 wpa_printf(MSG_DEBUG, " * flags=%08X", params->flags);
9537
9538 container = nla_nest_start(msg, NL80211_ATTR_MESH_SETUP);
9539 if (!container)
9540 goto fail;
9541
9542 if (params->ies) {
9543 wpa_hexdump(MSG_DEBUG, " * IEs", params->ies, params->ie_len);
9544 if (nla_put(msg, NL80211_MESH_SETUP_IE, params->ie_len,
9545 params->ies))
9546 goto fail;
9547 }
9548 /* WPA_DRIVER_MESH_FLAG_OPEN_AUTH is treated as default by nl80211 */
9549 if (params->flags & WPA_DRIVER_MESH_FLAG_SAE_AUTH) {
9550 if (nla_put_u8(msg, NL80211_MESH_SETUP_AUTH_PROTOCOL, 0x1) ||
9551 nla_put_flag(msg, NL80211_MESH_SETUP_USERSPACE_AUTH))
9552 goto fail;
9553 }
9554 if ((params->flags & WPA_DRIVER_MESH_FLAG_AMPE) &&
9555 nla_put_flag(msg, NL80211_MESH_SETUP_USERSPACE_AMPE))
9556 goto fail;
9557 if ((params->flags & WPA_DRIVER_MESH_FLAG_USER_MPM) &&
9558 nla_put_flag(msg, NL80211_MESH_SETUP_USERSPACE_MPM))
9559 goto fail;
9560 nla_nest_end(msg, container);
9561
9562 params->conf.flags |= WPA_DRIVER_MESH_CONF_FLAG_AUTO_PLINKS;
9563 params->conf.flags |= WPA_DRIVER_MESH_CONF_FLAG_PEER_LINK_TIMEOUT;
9564 params->conf.flags |= WPA_DRIVER_MESH_CONF_FLAG_MAX_PEER_LINKS;
9565 if (nl80211_put_mesh_config(msg, &params->conf) < 0)
9566 goto fail;
9567
9568 ret = send_and_recv_msgs(drv, msg, NULL, NULL);
9569 msg = NULL;
9570 if (ret) {
9571 wpa_printf(MSG_DEBUG, "nl80211: mesh join failed: ret=%d (%s)",
9572 ret, strerror(-ret));
9573 goto fail;
9574 }
9575 ret = 0;
9576 drv->assoc_freq = bss->freq = params->freq.freq;
9577 wpa_printf(MSG_DEBUG, "nl80211: mesh join request send successfully");
9578
9579 fail:
9580 nlmsg_free(msg);
9581 return ret;
9582 }
9583
9584
9585 static int
9586 wpa_driver_nl80211_join_mesh(void *priv,
9587 struct wpa_driver_mesh_join_params *params)
9588 {
9589 struct i802_bss *bss = priv;
9590 int ret, timeout;
9591
9592 timeout = params->conf.peer_link_timeout;
9593
9594 /* Disable kernel inactivity timer */
9595 if (params->flags & WPA_DRIVER_MESH_FLAG_USER_MPM)
9596 params->conf.peer_link_timeout = 0;
9597
9598 ret = nl80211_join_mesh(bss, params);
9599 if (ret == -EINVAL && params->conf.peer_link_timeout == 0) {
9600 wpa_printf(MSG_DEBUG,
9601 "nl80211: Mesh join retry for peer_link_timeout");
9602 /*
9603 * Old kernel does not support setting
9604 * NL80211_MESHCONF_PLINK_TIMEOUT to zero, so set 60 seconds
9605 * into future from peer_link_timeout.
9606 */
9607 params->conf.peer_link_timeout = timeout + 60;
9608 ret = nl80211_join_mesh(priv, params);
9609 }
9610
9611 params->conf.peer_link_timeout = timeout;
9612 return ret;
9613 }
9614
9615
9616 static int wpa_driver_nl80211_leave_mesh(void *priv)
9617 {
9618 struct i802_bss *bss = priv;
9619 struct wpa_driver_nl80211_data *drv = bss->drv;
9620 struct nl_msg *msg;
9621 int ret;
9622
9623 wpa_printf(MSG_DEBUG, "nl80211: mesh leave (ifindex=%d)", drv->ifindex);
9624 msg = nl80211_drv_msg(drv, 0, NL80211_CMD_LEAVE_MESH);
9625 ret = send_and_recv_msgs(drv, msg, NULL, NULL);
9626 if (ret) {
9627 wpa_printf(MSG_DEBUG, "nl80211: mesh leave failed: ret=%d (%s)",
9628 ret, strerror(-ret));
9629 } else {
9630 wpa_printf(MSG_DEBUG,
9631 "nl80211: mesh leave request send successfully");
9632 }
9633
9634 if (wpa_driver_nl80211_set_mode(drv->first_bss,
9635 NL80211_IFTYPE_STATION)) {
9636 wpa_printf(MSG_INFO,
9637 "nl80211: Failed to set interface into station mode");
9638 }
9639 return ret;
9640 }
9641
9642 #endif /* CONFIG_MESH */
9643
9644
9645 static int wpa_driver_br_add_ip_neigh(void *priv, u8 version,
9646 const u8 *ipaddr, int prefixlen,
9647 const u8 *addr)
9648 {
9649 #ifdef CONFIG_LIBNL3_ROUTE
9650 struct i802_bss *bss = priv;
9651 struct wpa_driver_nl80211_data *drv = bss->drv;
9652 struct rtnl_neigh *rn;
9653 struct nl_addr *nl_ipaddr = NULL;
9654 struct nl_addr *nl_lladdr = NULL;
9655 int family, addrsize;
9656 int res;
9657
9658 if (!ipaddr || prefixlen == 0 || !addr)
9659 return -EINVAL;
9660
9661 if (bss->br_ifindex == 0) {
9662 wpa_printf(MSG_DEBUG,
9663 "nl80211: bridge must be set before adding an ip neigh to it");
9664 return -1;
9665 }
9666
9667 if (!drv->rtnl_sk) {
9668 wpa_printf(MSG_DEBUG,
9669 "nl80211: nl_sock for NETLINK_ROUTE is not initialized");
9670 return -1;
9671 }
9672
9673 if (version == 4) {
9674 family = AF_INET;
9675 addrsize = 4;
9676 } else if (version == 6) {
9677 family = AF_INET6;
9678 addrsize = 16;
9679 } else {
9680 return -EINVAL;
9681 }
9682
9683 rn = rtnl_neigh_alloc();
9684 if (rn == NULL)
9685 return -ENOMEM;
9686
9687 /* set the destination ip address for neigh */
9688 nl_ipaddr = nl_addr_build(family, (void *) ipaddr, addrsize);
9689 if (nl_ipaddr == NULL) {
9690 wpa_printf(MSG_DEBUG, "nl80211: nl_ipaddr build failed");
9691 res = -ENOMEM;
9692 goto errout;
9693 }
9694 nl_addr_set_prefixlen(nl_ipaddr, prefixlen);
9695 res = rtnl_neigh_set_dst(rn, nl_ipaddr);
9696 if (res) {
9697 wpa_printf(MSG_DEBUG,
9698 "nl80211: neigh set destination addr failed");
9699 goto errout;
9700 }
9701
9702 /* set the corresponding lladdr for neigh */
9703 nl_lladdr = nl_addr_build(AF_BRIDGE, (u8 *) addr, ETH_ALEN);
9704 if (nl_lladdr == NULL) {
9705 wpa_printf(MSG_DEBUG, "nl80211: neigh set lladdr failed");
9706 res = -ENOMEM;
9707 goto errout;
9708 }
9709 rtnl_neigh_set_lladdr(rn, nl_lladdr);
9710
9711 rtnl_neigh_set_ifindex(rn, bss->br_ifindex);
9712 rtnl_neigh_set_state(rn, NUD_PERMANENT);
9713
9714 res = rtnl_neigh_add(drv->rtnl_sk, rn, NLM_F_CREATE);
9715 if (res) {
9716 wpa_printf(MSG_DEBUG,
9717 "nl80211: Adding bridge ip neigh failed: %s",
9718 strerror(errno));
9719 }
9720 errout:
9721 if (nl_lladdr)
9722 nl_addr_put(nl_lladdr);
9723 if (nl_ipaddr)
9724 nl_addr_put(nl_ipaddr);
9725 if (rn)
9726 rtnl_neigh_put(rn);
9727 return res;
9728 #else /* CONFIG_LIBNL3_ROUTE */
9729 return -1;
9730 #endif /* CONFIG_LIBNL3_ROUTE */
9731 }
9732
9733
9734 static int wpa_driver_br_delete_ip_neigh(void *priv, u8 version,
9735 const u8 *ipaddr)
9736 {
9737 #ifdef CONFIG_LIBNL3_ROUTE
9738 struct i802_bss *bss = priv;
9739 struct wpa_driver_nl80211_data *drv = bss->drv;
9740 struct rtnl_neigh *rn;
9741 struct nl_addr *nl_ipaddr;
9742 int family, addrsize;
9743 int res;
9744
9745 if (!ipaddr)
9746 return -EINVAL;
9747
9748 if (version == 4) {
9749 family = AF_INET;
9750 addrsize = 4;
9751 } else if (version == 6) {
9752 family = AF_INET6;
9753 addrsize = 16;
9754 } else {
9755 return -EINVAL;
9756 }
9757
9758 if (bss->br_ifindex == 0) {
9759 wpa_printf(MSG_DEBUG,
9760 "nl80211: bridge must be set to delete an ip neigh");
9761 return -1;
9762 }
9763
9764 if (!drv->rtnl_sk) {
9765 wpa_printf(MSG_DEBUG,
9766 "nl80211: nl_sock for NETLINK_ROUTE is not initialized");
9767 return -1;
9768 }
9769
9770 rn = rtnl_neigh_alloc();
9771 if (rn == NULL)
9772 return -ENOMEM;
9773
9774 /* set the destination ip address for neigh */
9775 nl_ipaddr = nl_addr_build(family, (void *) ipaddr, addrsize);
9776 if (nl_ipaddr == NULL) {
9777 wpa_printf(MSG_DEBUG, "nl80211: nl_ipaddr build failed");
9778 res = -ENOMEM;
9779 goto errout;
9780 }
9781 res = rtnl_neigh_set_dst(rn, nl_ipaddr);
9782 if (res) {
9783 wpa_printf(MSG_DEBUG,
9784 "nl80211: neigh set destination addr failed");
9785 goto errout;
9786 }
9787
9788 rtnl_neigh_set_ifindex(rn, bss->br_ifindex);
9789
9790 res = rtnl_neigh_delete(drv->rtnl_sk, rn, 0);
9791 if (res) {
9792 wpa_printf(MSG_DEBUG,
9793 "nl80211: Deleting bridge ip neigh failed: %s",
9794 strerror(errno));
9795 }
9796 errout:
9797 if (nl_ipaddr)
9798 nl_addr_put(nl_ipaddr);
9799 if (rn)
9800 rtnl_neigh_put(rn);
9801 return res;
9802 #else /* CONFIG_LIBNL3_ROUTE */
9803 return -1;
9804 #endif /* CONFIG_LIBNL3_ROUTE */
9805 }
9806
9807
9808 static int linux_write_system_file(const char *path, unsigned int val)
9809 {
9810 char buf[50];
9811 int fd, len;
9812
9813 len = os_snprintf(buf, sizeof(buf), "%u\n", val);
9814 if (os_snprintf_error(sizeof(buf), len))
9815 return -1;
9816
9817 fd = open(path, O_WRONLY);
9818 if (fd < 0)
9819 return -1;
9820
9821 if (write(fd, buf, len) < 0) {
9822 wpa_printf(MSG_DEBUG,
9823 "nl80211: Failed to write Linux system file: %s with the value of %d",
9824 path, val);
9825 close(fd);
9826 return -1;
9827 }
9828 close(fd);
9829
9830 return 0;
9831 }
9832
9833
9834 static const char * drv_br_port_attr_str(enum drv_br_port_attr attr)
9835 {
9836 switch (attr) {
9837 case DRV_BR_PORT_ATTR_PROXYARP:
9838 return "proxyarp_wifi";
9839 case DRV_BR_PORT_ATTR_HAIRPIN_MODE:
9840 return "hairpin_mode";
9841 }
9842
9843 return NULL;
9844 }
9845
9846
9847 static int wpa_driver_br_port_set_attr(void *priv, enum drv_br_port_attr attr,
9848 unsigned int val)
9849 {
9850 struct i802_bss *bss = priv;
9851 char path[128];
9852 const char *attr_txt;
9853
9854 attr_txt = drv_br_port_attr_str(attr);
9855 if (attr_txt == NULL)
9856 return -EINVAL;
9857
9858 os_snprintf(path, sizeof(path), "/sys/class/net/%s/brport/%s",
9859 bss->ifname, attr_txt);
9860
9861 if (linux_write_system_file(path, val))
9862 return -1;
9863
9864 return 0;
9865 }
9866
9867
9868 static const char * drv_br_net_param_str(enum drv_br_net_param param)
9869 {
9870 switch (param) {
9871 case DRV_BR_NET_PARAM_GARP_ACCEPT:
9872 return "arp_accept";
9873 default:
9874 return NULL;
9875 }
9876 }
9877
9878
9879 static int wpa_driver_br_set_net_param(void *priv, enum drv_br_net_param param,
9880 unsigned int val)
9881 {
9882 struct i802_bss *bss = priv;
9883 char path[128];
9884 const char *param_txt;
9885 int ip_version = 4;
9886
9887 if (param == DRV_BR_MULTICAST_SNOOPING) {
9888 os_snprintf(path, sizeof(path),
9889 "/sys/devices/virtual/net/%s/bridge/multicast_snooping",
9890 bss->brname);
9891 goto set_val;
9892 }
9893
9894 param_txt = drv_br_net_param_str(param);
9895 if (param_txt == NULL)
9896 return -EINVAL;
9897
9898 switch (param) {
9899 case DRV_BR_NET_PARAM_GARP_ACCEPT:
9900 ip_version = 4;
9901 break;
9902 default:
9903 return -EINVAL;
9904 }
9905
9906 os_snprintf(path, sizeof(path), "/proc/sys/net/ipv%d/conf/%s/%s",
9907 ip_version, bss->brname, param_txt);
9908
9909 set_val:
9910 if (linux_write_system_file(path, val))
9911 return -1;
9912
9913 return 0;
9914 }
9915
9916
9917 #ifdef CONFIG_DRIVER_NL80211_QCA
9918
9919 static int hw_mode_to_qca_acs(enum hostapd_hw_mode hw_mode)
9920 {
9921 switch (hw_mode) {
9922 case HOSTAPD_MODE_IEEE80211B:
9923 return QCA_ACS_MODE_IEEE80211B;
9924 case HOSTAPD_MODE_IEEE80211G:
9925 return QCA_ACS_MODE_IEEE80211G;
9926 case HOSTAPD_MODE_IEEE80211A:
9927 return QCA_ACS_MODE_IEEE80211A;
9928 case HOSTAPD_MODE_IEEE80211AD:
9929 return QCA_ACS_MODE_IEEE80211AD;
9930 case HOSTAPD_MODE_IEEE80211ANY:
9931 return QCA_ACS_MODE_IEEE80211ANY;
9932 default:
9933 return -1;
9934 }
9935 }
9936
9937
9938 static int add_acs_freq_list(struct nl_msg *msg, const int *freq_list)
9939 {
9940 int i, len, ret;
9941 u32 *freqs;
9942
9943 if (!freq_list)
9944 return 0;
9945 len = int_array_len(freq_list);
9946 freqs = os_malloc(sizeof(u32) * len);
9947 if (!freqs)
9948 return -1;
9949 for (i = 0; i < len; i++)
9950 freqs[i] = freq_list[i];
9951 ret = nla_put(msg, QCA_WLAN_VENDOR_ATTR_ACS_FREQ_LIST,
9952 sizeof(u32) * len, freqs);
9953 os_free(freqs);
9954 return ret;
9955 }
9956
9957
9958 static int wpa_driver_do_acs(void *priv, struct drv_acs_params *params)
9959 {
9960 struct i802_bss *bss = priv;
9961 struct wpa_driver_nl80211_data *drv = bss->drv;
9962 struct nl_msg *msg;
9963 struct nlattr *data;
9964 int ret;
9965 int mode;
9966
9967 mode = hw_mode_to_qca_acs(params->hw_mode);
9968 if (mode < 0)
9969 return -1;
9970
9971 if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_VENDOR)) ||
9972 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
9973 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
9974 QCA_NL80211_VENDOR_SUBCMD_DO_ACS) ||
9975 !(data = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
9976 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_ACS_HW_MODE, mode) ||
9977 (params->ht_enabled &&
9978 nla_put_flag(msg, QCA_WLAN_VENDOR_ATTR_ACS_HT_ENABLED)) ||
9979 (params->ht40_enabled &&
9980 nla_put_flag(msg, QCA_WLAN_VENDOR_ATTR_ACS_HT40_ENABLED)) ||
9981 (params->vht_enabled &&
9982 nla_put_flag(msg, QCA_WLAN_VENDOR_ATTR_ACS_VHT_ENABLED)) ||
9983 nla_put_u16(msg, QCA_WLAN_VENDOR_ATTR_ACS_CHWIDTH,
9984 params->ch_width) ||
9985 (params->ch_list_len &&
9986 nla_put(msg, QCA_WLAN_VENDOR_ATTR_ACS_CH_LIST, params->ch_list_len,
9987 params->ch_list)) ||
9988 add_acs_freq_list(msg, params->freq_list)) {
9989 nlmsg_free(msg);
9990 return -ENOBUFS;
9991 }
9992 nla_nest_end(msg, data);
9993
9994 wpa_printf(MSG_DEBUG,
9995 "nl80211: ACS Params: HW_MODE: %d HT: %d HT40: %d VHT: %d BW: %d CH_LIST_LEN: %u",
9996 params->hw_mode, params->ht_enabled, params->ht40_enabled,
9997 params->vht_enabled, params->ch_width, params->ch_list_len);
9998
9999 ret = send_and_recv_msgs(drv, msg, NULL, NULL);
10000 if (ret) {
10001 wpa_printf(MSG_DEBUG,
10002 "nl80211: Failed to invoke driver ACS function: %s",
10003 strerror(errno));
10004 }
10005 return ret;
10006 }
10007
10008
10009 static int nl80211_set_band(void *priv, enum set_band band)
10010 {
10011 struct i802_bss *bss = priv;
10012 struct wpa_driver_nl80211_data *drv = bss->drv;
10013 struct nl_msg *msg;
10014 struct nlattr *data;
10015 int ret;
10016 enum qca_set_band qca_band;
10017
10018 if (!drv->setband_vendor_cmd_avail)
10019 return -1;
10020
10021 switch (band) {
10022 case WPA_SETBAND_AUTO:
10023 qca_band = QCA_SETBAND_AUTO;
10024 break;
10025 case WPA_SETBAND_5G:
10026 qca_band = QCA_SETBAND_5G;
10027 break;
10028 case WPA_SETBAND_2G:
10029 qca_band = QCA_SETBAND_2G;
10030 break;
10031 default:
10032 return -1;
10033 }
10034
10035 if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_VENDOR)) ||
10036 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
10037 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
10038 QCA_NL80211_VENDOR_SUBCMD_SETBAND) ||
10039 !(data = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
10040 nla_put_u32(msg, QCA_WLAN_VENDOR_ATTR_SETBAND_VALUE, qca_band)) {
10041 nlmsg_free(msg);
10042 return -ENOBUFS;
10043 }
10044 nla_nest_end(msg, data);
10045
10046 ret = send_and_recv_msgs(drv, msg, NULL, NULL);
10047 if (ret) {
10048 wpa_printf(MSG_DEBUG,
10049 "nl80211: Driver setband function failed: %s",
10050 strerror(errno));
10051 }
10052 return ret;
10053 }
10054
10055
10056 struct nl80211_pcl {
10057 unsigned int num;
10058 unsigned int *freq_list;
10059 };
10060
10061 static int preferred_freq_info_handler(struct nl_msg *msg, void *arg)
10062 {
10063 struct nlattr *tb[NL80211_ATTR_MAX + 1];
10064 struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg));
10065 struct nl80211_pcl *param = arg;
10066 struct nlattr *nl_vend, *attr;
10067 enum qca_iface_type iface_type;
10068 struct nlattr *tb_vendor[QCA_WLAN_VENDOR_ATTR_MAX + 1];
10069 unsigned int num, max_num;
10070 u32 *freqs;
10071
10072 nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0),
10073 genlmsg_attrlen(gnlh, 0), NULL);
10074
10075 nl_vend = tb[NL80211_ATTR_VENDOR_DATA];
10076 if (!nl_vend)
10077 return NL_SKIP;
10078
10079 nla_parse(tb_vendor, QCA_WLAN_VENDOR_ATTR_MAX,
10080 nla_data(nl_vend), nla_len(nl_vend), NULL);
10081
10082 attr = tb_vendor[
10083 QCA_WLAN_VENDOR_ATTR_GET_PREFERRED_FREQ_LIST_IFACE_TYPE];
10084 if (!attr) {
10085 wpa_printf(MSG_ERROR, "nl80211: iface_type couldn't be found");
10086 param->num = 0;
10087 return NL_SKIP;
10088 }
10089
10090 iface_type = (enum qca_iface_type) nla_get_u32(attr);
10091 wpa_printf(MSG_DEBUG, "nl80211: Driver returned iface_type=%d",
10092 iface_type);
10093
10094 attr = tb_vendor[QCA_WLAN_VENDOR_ATTR_GET_PREFERRED_FREQ_LIST];
10095 if (!attr) {
10096 wpa_printf(MSG_ERROR,
10097 "nl80211: preferred_freq_list couldn't be found");
10098 param->num = 0;
10099 return NL_SKIP;
10100 }
10101
10102 /*
10103 * param->num has the maximum number of entries for which there
10104 * is room in the freq_list provided by the caller.
10105 */
10106 freqs = nla_data(attr);
10107 max_num = nla_len(attr) / sizeof(u32);
10108 if (max_num > param->num)
10109 max_num = param->num;
10110 for (num = 0; num < max_num; num++)
10111 param->freq_list[num] = freqs[num];
10112 param->num = num;
10113
10114 return NL_SKIP;
10115 }
10116
10117
10118 static int nl80211_get_pref_freq_list(void *priv,
10119 enum wpa_driver_if_type if_type,
10120 unsigned int *num,
10121 unsigned int *freq_list)
10122 {
10123 struct i802_bss *bss = priv;
10124 struct wpa_driver_nl80211_data *drv = bss->drv;
10125 struct nl_msg *msg;
10126 int ret;
10127 unsigned int i;
10128 struct nlattr *params;
10129 struct nl80211_pcl param;
10130 enum qca_iface_type iface_type;
10131
10132 if (!drv->get_pref_freq_list)
10133 return -1;
10134
10135 switch (if_type) {
10136 case WPA_IF_STATION:
10137 iface_type = QCA_IFACE_TYPE_STA;
10138 break;
10139 case WPA_IF_AP_BSS:
10140 iface_type = QCA_IFACE_TYPE_AP;
10141 break;
10142 case WPA_IF_P2P_GO:
10143 iface_type = QCA_IFACE_TYPE_P2P_GO;
10144 break;
10145 case WPA_IF_P2P_CLIENT:
10146 iface_type = QCA_IFACE_TYPE_P2P_CLIENT;
10147 break;
10148 case WPA_IF_IBSS:
10149 iface_type = QCA_IFACE_TYPE_IBSS;
10150 break;
10151 case WPA_IF_TDLS:
10152 iface_type = QCA_IFACE_TYPE_TDLS;
10153 break;
10154 default:
10155 return -1;
10156 }
10157
10158 param.num = *num;
10159 param.freq_list = freq_list;
10160
10161 if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_VENDOR)) ||
10162 nla_put_u32(msg, NL80211_ATTR_IFINDEX, drv->ifindex) ||
10163 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
10164 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
10165 QCA_NL80211_VENDOR_SUBCMD_GET_PREFERRED_FREQ_LIST) ||
10166 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
10167 nla_put_u32(msg,
10168 QCA_WLAN_VENDOR_ATTR_GET_PREFERRED_FREQ_LIST_IFACE_TYPE,
10169 iface_type)) {
10170 wpa_printf(MSG_ERROR,
10171 "%s: err in adding vendor_cmd and vendor_data",
10172 __func__);
10173 nlmsg_free(msg);
10174 return -1;
10175 }
10176 nla_nest_end(msg, params);
10177
10178 os_memset(freq_list, 0, *num * sizeof(freq_list[0]));
10179 ret = send_and_recv_msgs(drv, msg, preferred_freq_info_handler, &param);
10180 if (ret) {
10181 wpa_printf(MSG_ERROR,
10182 "%s: err in send_and_recv_msgs", __func__);
10183 return ret;
10184 }
10185
10186 *num = param.num;
10187
10188 for (i = 0; i < *num; i++) {
10189 wpa_printf(MSG_DEBUG, "nl80211: preferred_channel_list[%d]=%d",
10190 i, freq_list[i]);
10191 }
10192
10193 return 0;
10194 }
10195
10196
10197 static int nl80211_set_prob_oper_freq(void *priv, unsigned int freq)
10198 {
10199 struct i802_bss *bss = priv;
10200 struct wpa_driver_nl80211_data *drv = bss->drv;
10201 struct nl_msg *msg;
10202 int ret;
10203 struct nlattr *params;
10204
10205 if (!drv->set_prob_oper_freq)
10206 return -1;
10207
10208 wpa_printf(MSG_DEBUG,
10209 "nl80211: Set P2P probable operating freq %u for ifindex %d",
10210 freq, bss->ifindex);
10211
10212 if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_VENDOR)) ||
10213 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
10214 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
10215 QCA_NL80211_VENDOR_SUBCMD_SET_PROBABLE_OPER_CHANNEL) ||
10216 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
10217 nla_put_u32(msg,
10218 QCA_WLAN_VENDOR_ATTR_PROBABLE_OPER_CHANNEL_IFACE_TYPE,
10219 QCA_IFACE_TYPE_P2P_CLIENT) ||
10220 nla_put_u32(msg,
10221 QCA_WLAN_VENDOR_ATTR_PROBABLE_OPER_CHANNEL_FREQ,
10222 freq)) {
10223 wpa_printf(MSG_ERROR,
10224 "%s: err in adding vendor_cmd and vendor_data",
10225 __func__);
10226 nlmsg_free(msg);
10227 return -1;
10228 }
10229 nla_nest_end(msg, params);
10230
10231 ret = send_and_recv_msgs(drv, msg, NULL, NULL);
10232 msg = NULL;
10233 if (ret) {
10234 wpa_printf(MSG_ERROR, "%s: err in send_and_recv_msgs",
10235 __func__);
10236 return ret;
10237 }
10238 nlmsg_free(msg);
10239 return 0;
10240 }
10241
10242
10243 static int nl80211_p2p_lo_start(void *priv, unsigned int freq,
10244 unsigned int period, unsigned int interval,
10245 unsigned int count, const u8 *device_types,
10246 size_t dev_types_len,
10247 const u8 *ies, size_t ies_len)
10248 {
10249 struct i802_bss *bss = priv;
10250 struct wpa_driver_nl80211_data *drv = bss->drv;
10251 struct nl_msg *msg;
10252 struct nlattr *container;
10253 int ret;
10254
10255 wpa_printf(MSG_DEBUG,
10256 "nl80211: Start P2P Listen offload: freq=%u, period=%u, interval=%u, count=%u",
10257 freq, period, interval, count);
10258
10259 if (!(drv->capa.flags & WPA_DRIVER_FLAGS_P2P_LISTEN_OFFLOAD))
10260 return -1;
10261
10262 if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_VENDOR)) ||
10263 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
10264 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
10265 QCA_NL80211_VENDOR_SUBCMD_P2P_LISTEN_OFFLOAD_START))
10266 goto fail;
10267
10268 container = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA);
10269 if (!container)
10270 goto fail;
10271
10272 if (nla_put_u32(msg, QCA_WLAN_VENDOR_ATTR_P2P_LISTEN_OFFLOAD_CHANNEL,
10273 freq) ||
10274 nla_put_u32(msg, QCA_WLAN_VENDOR_ATTR_P2P_LISTEN_OFFLOAD_PERIOD,
10275 period) ||
10276 nla_put_u32(msg, QCA_WLAN_VENDOR_ATTR_P2P_LISTEN_OFFLOAD_INTERVAL,
10277 interval) ||
10278 nla_put_u32(msg, QCA_WLAN_VENDOR_ATTR_P2P_LISTEN_OFFLOAD_COUNT,
10279 count) ||
10280 nla_put(msg, QCA_WLAN_VENDOR_ATTR_P2P_LISTEN_OFFLOAD_DEVICE_TYPES,
10281 dev_types_len, device_types) ||
10282 nla_put(msg, QCA_WLAN_VENDOR_ATTR_P2P_LISTEN_OFFLOAD_VENDOR_IE,
10283 ies_len, ies))
10284 goto fail;
10285
10286 nla_nest_end(msg, container);
10287 ret = send_and_recv_msgs(drv, msg, NULL, NULL);
10288 msg = NULL;
10289 if (ret) {
10290 wpa_printf(MSG_DEBUG,
10291 "nl80211: Failed to send P2P Listen offload vendor command");
10292 goto fail;
10293 }
10294
10295 return 0;
10296
10297 fail:
10298 nlmsg_free(msg);
10299 return -1;
10300 }
10301
10302
10303 static int nl80211_p2p_lo_stop(void *priv)
10304 {
10305 struct i802_bss *bss = priv;
10306 struct wpa_driver_nl80211_data *drv = bss->drv;
10307 struct nl_msg *msg;
10308
10309 wpa_printf(MSG_DEBUG, "nl80211: Stop P2P Listen offload");
10310
10311 if (!(drv->capa.flags & WPA_DRIVER_FLAGS_P2P_LISTEN_OFFLOAD))
10312 return -1;
10313
10314 if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_VENDOR)) ||
10315 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
10316 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
10317 QCA_NL80211_VENDOR_SUBCMD_P2P_LISTEN_OFFLOAD_STOP)) {
10318 nlmsg_free(msg);
10319 return -1;
10320 }
10321
10322 return send_and_recv_msgs(drv, msg, NULL, NULL);
10323 }
10324
10325
10326 static int nl80211_set_tdls_mode(void *priv, int tdls_external_control)
10327 {
10328 struct i802_bss *bss = priv;
10329 struct wpa_driver_nl80211_data *drv = bss->drv;
10330 struct nl_msg *msg;
10331 struct nlattr *params;
10332 int ret;
10333 u32 tdls_mode;
10334
10335 wpa_printf(MSG_DEBUG,
10336 "nl80211: Set TDKS mode: tdls_external_control=%d",
10337 tdls_external_control);
10338
10339 if (tdls_external_control == 1)
10340 tdls_mode = QCA_WLAN_VENDOR_TDLS_TRIGGER_MODE_IMPLICIT |
10341 QCA_WLAN_VENDOR_TDLS_TRIGGER_MODE_EXTERNAL;
10342 else
10343 tdls_mode = QCA_WLAN_VENDOR_TDLS_TRIGGER_MODE_EXPLICIT;
10344
10345 if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_VENDOR)) ||
10346 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
10347 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
10348 QCA_NL80211_VENDOR_SUBCMD_CONFIGURE_TDLS))
10349 goto fail;
10350
10351 params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA);
10352 if (!params)
10353 goto fail;
10354
10355 if (nla_put_u32(msg, QCA_WLAN_VENDOR_ATTR_TDLS_CONFIG_TRIGGER_MODE,
10356 tdls_mode))
10357 goto fail;
10358
10359 nla_nest_end(msg, params);
10360
10361 ret = send_and_recv_msgs(drv, msg, NULL, NULL);
10362 msg = NULL;
10363 if (ret) {
10364 wpa_printf(MSG_ERROR,
10365 "nl80211: Set TDLS mode failed: ret=%d (%s)",
10366 ret, strerror(-ret));
10367 goto fail;
10368 }
10369 return 0;
10370 fail:
10371 nlmsg_free(msg);
10372 return -1;
10373 }
10374
10375
10376 #ifdef CONFIG_MBO
10377
10378 static enum mbo_transition_reject_reason
10379 nl80211_mbo_reject_reason_mapping(enum qca_wlan_btm_candidate_status status)
10380 {
10381 switch (status) {
10382 case QCA_STATUS_REJECT_EXCESSIVE_FRAME_LOSS_EXPECTED:
10383 return MBO_TRANSITION_REJECT_REASON_FRAME_LOSS;
10384 case QCA_STATUS_REJECT_EXCESSIVE_DELAY_EXPECTED:
10385 return MBO_TRANSITION_REJECT_REASON_DELAY;
10386 case QCA_STATUS_REJECT_INSUFFICIENT_QOS_CAPACITY:
10387 return MBO_TRANSITION_REJECT_REASON_QOS_CAPACITY;
10388 case QCA_STATUS_REJECT_LOW_RSSI:
10389 return MBO_TRANSITION_REJECT_REASON_RSSI;
10390 case QCA_STATUS_REJECT_HIGH_INTERFERENCE:
10391 return MBO_TRANSITION_REJECT_REASON_INTERFERENCE;
10392 case QCA_STATUS_REJECT_UNKNOWN:
10393 default:
10394 return MBO_TRANSITION_REJECT_REASON_UNSPECIFIED;
10395 }
10396 }
10397
10398
10399 static void nl80211_parse_btm_candidate_info(struct candidate_list *candidate,
10400 struct nlattr *tb[], int num)
10401 {
10402 enum qca_wlan_btm_candidate_status status;
10403 char buf[50];
10404
10405 os_memcpy(candidate->bssid,
10406 nla_data(tb[QCA_WLAN_VENDOR_ATTR_BTM_CANDIDATE_INFO_BSSID]),
10407 ETH_ALEN);
10408
10409 status = nla_get_u32(
10410 tb[QCA_WLAN_VENDOR_ATTR_BTM_CANDIDATE_INFO_STATUS]);
10411 candidate->is_accept = status == QCA_STATUS_ACCEPT;
10412 candidate->reject_reason = nl80211_mbo_reject_reason_mapping(status);
10413
10414 if (candidate->is_accept)
10415 os_snprintf(buf, sizeof(buf), "Accepted");
10416 else
10417 os_snprintf(buf, sizeof(buf),
10418 "Rejected, Reject_reason: %d",
10419 candidate->reject_reason);
10420 wpa_printf(MSG_DEBUG, "nl80211: BSSID[%d]: " MACSTR " %s",
10421 num, MAC2STR(candidate->bssid), buf);
10422 }
10423
10424
10425 static int
10426 nl80211_get_bss_transition_status_handler(struct nl_msg *msg, void *arg)
10427 {
10428 struct wpa_bss_candidate_info *info = arg;
10429 struct candidate_list *candidate = info->candidates;
10430 struct nlattr *tb_msg[NL80211_ATTR_MAX + 1];
10431 struct nlattr *tb_vendor[QCA_WLAN_VENDOR_ATTR_MAX + 1];
10432 struct nlattr *tb[QCA_WLAN_VENDOR_ATTR_BTM_CANDIDATE_INFO_MAX + 1];
10433 static struct nla_policy policy[
10434 QCA_WLAN_VENDOR_ATTR_BTM_CANDIDATE_INFO_MAX + 1] = {
10435 [QCA_WLAN_VENDOR_ATTR_BTM_CANDIDATE_INFO_BSSID] = {
10436 .minlen = ETH_ALEN
10437 },
10438 [QCA_WLAN_VENDOR_ATTR_BTM_CANDIDATE_INFO_STATUS] = {
10439 .type = NLA_U32,
10440 },
10441 };
10442 struct nlattr *attr;
10443 int rem;
10444 struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg));
10445 u8 num;
10446
10447 num = info->num; /* number of candidates sent to driver */
10448 info->num = 0;
10449 nla_parse(tb_msg, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0),
10450 genlmsg_attrlen(gnlh, 0), NULL);
10451
10452 if (!tb_msg[NL80211_ATTR_VENDOR_DATA] ||
10453 nla_parse_nested(tb_vendor, QCA_WLAN_VENDOR_ATTR_MAX,
10454 tb_msg[NL80211_ATTR_VENDOR_DATA], NULL) ||
10455 !tb_vendor[QCA_WLAN_VENDOR_ATTR_BTM_CANDIDATE_INFO])
10456 return NL_SKIP;
10457
10458 wpa_printf(MSG_DEBUG,
10459 "nl80211: WNM Candidate list received from driver");
10460 nla_for_each_nested(attr,
10461 tb_vendor[QCA_WLAN_VENDOR_ATTR_BTM_CANDIDATE_INFO],
10462 rem) {
10463 if (info->num >= num ||
10464 nla_parse_nested(
10465 tb, QCA_WLAN_VENDOR_ATTR_BTM_CANDIDATE_INFO_MAX,
10466 attr, policy) ||
10467 !tb[QCA_WLAN_VENDOR_ATTR_BTM_CANDIDATE_INFO_BSSID] ||
10468 !tb[QCA_WLAN_VENDOR_ATTR_BTM_CANDIDATE_INFO_STATUS])
10469 break;
10470
10471 nl80211_parse_btm_candidate_info(candidate, tb, info->num);
10472
10473 candidate++;
10474 info->num++;
10475 }
10476
10477 return NL_SKIP;
10478 }
10479
10480
10481 static struct wpa_bss_candidate_info *
10482 nl80211_get_bss_transition_status(void *priv, struct wpa_bss_trans_info *params)
10483 {
10484 struct i802_bss *bss = priv;
10485 struct wpa_driver_nl80211_data *drv = bss->drv;
10486 struct nl_msg *msg;
10487 struct nlattr *attr, *attr1, *attr2;
10488 struct wpa_bss_candidate_info *info;
10489 u8 i;
10490 int ret;
10491 u8 *pos;
10492
10493 if (!drv->fetch_bss_trans_status)
10494 return NULL;
10495
10496 info = os_zalloc(sizeof(*info));
10497 if (!info)
10498 return NULL;
10499 /* Allocate memory for number of candidates sent to driver */
10500 info->candidates = os_calloc(params->n_candidates,
10501 sizeof(*info->candidates));
10502 if (!info->candidates) {
10503 os_free(info);
10504 return NULL;
10505 }
10506
10507 /* Copy the number of candidates being sent to driver. This is used in
10508 * nl80211_get_bss_transition_status_handler() to limit the number of
10509 * candidates that can be populated in info->candidates and will be
10510 * later overwritten with the actual number of candidates received from
10511 * the driver.
10512 */
10513 info->num = params->n_candidates;
10514
10515 if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_VENDOR)) ||
10516 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
10517 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
10518 QCA_NL80211_VENDOR_SUBCMD_FETCH_BSS_TRANSITION_STATUS))
10519 goto fail;
10520
10521 attr = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA);
10522 if (!attr)
10523 goto fail;
10524
10525 if (nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_BTM_MBO_TRANSITION_REASON,
10526 params->mbo_transition_reason))
10527 goto fail;
10528
10529 attr1 = nla_nest_start(msg, QCA_WLAN_VENDOR_ATTR_BTM_CANDIDATE_INFO);
10530 if (!attr1)
10531 goto fail;
10532
10533 wpa_printf(MSG_DEBUG,
10534 "nl80211: WNM Candidate list info sending to driver: mbo_transition_reason: %d n_candidates: %d",
10535 params->mbo_transition_reason, params->n_candidates);
10536 pos = params->bssid;
10537 for (i = 0; i < params->n_candidates; i++) {
10538 wpa_printf(MSG_DEBUG, "nl80211: BSSID[%d]: " MACSTR, i,
10539 MAC2STR(pos));
10540 attr2 = nla_nest_start(msg, i);
10541 if (!attr2 ||
10542 nla_put(msg, QCA_WLAN_VENDOR_ATTR_BTM_CANDIDATE_INFO_BSSID,
10543 ETH_ALEN, pos))
10544 goto fail;
10545 pos += ETH_ALEN;
10546 nla_nest_end(msg, attr2);
10547 }
10548
10549 nla_nest_end(msg, attr1);
10550 nla_nest_end(msg, attr);
10551
10552 ret = send_and_recv_msgs(drv, msg,
10553 nl80211_get_bss_transition_status_handler,
10554 info);
10555 msg = NULL;
10556 if (ret) {
10557 wpa_printf(MSG_ERROR,
10558 "nl80211: WNM Get BSS transition status failed: ret=%d (%s)",
10559 ret, strerror(-ret));
10560 goto fail;
10561 }
10562 return info;
10563
10564 fail:
10565 nlmsg_free(msg);
10566 os_free(info->candidates);
10567 os_free(info);
10568 return NULL;
10569 }
10570
10571
10572 /**
10573 * nl80211_ignore_assoc_disallow - Configure driver to ignore assoc_disallow
10574 * @priv: Pointer to private driver data from wpa_driver_nl80211_init()
10575 * @ignore_assoc_disallow: 0 to not ignore, 1 to ignore
10576 * Returns: 0 on success, -1 on failure
10577 */
10578 static int nl80211_ignore_assoc_disallow(void *priv, int ignore_disallow)
10579 {
10580 struct i802_bss *bss = priv;
10581 struct wpa_driver_nl80211_data *drv = bss->drv;
10582 struct nl_msg *msg;
10583 struct nlattr *attr;
10584 int ret = -1;
10585
10586 if (!drv->set_wifi_conf_vendor_cmd_avail)
10587 return -1;
10588
10589 if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_VENDOR)) ||
10590 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
10591 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
10592 QCA_NL80211_VENDOR_SUBCMD_SET_WIFI_CONFIGURATION))
10593 goto fail;
10594
10595 attr = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA);
10596 if (!attr)
10597 goto fail;
10598
10599 wpa_printf(MSG_DEBUG, "nl80211: Set ignore_assoc_disallow %d",
10600 ignore_disallow);
10601 if (nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_CONFIG_IGNORE_ASSOC_DISALLOWED,
10602 ignore_disallow))
10603 goto fail;
10604
10605 nla_nest_end(msg, attr);
10606
10607 ret = send_and_recv_msgs(drv, msg, NULL, NULL);
10608 msg = NULL;
10609 if (ret) {
10610 wpa_printf(MSG_ERROR,
10611 "nl80211: Set ignore_assoc_disallow failed: ret=%d (%s)",
10612 ret, strerror(-ret));
10613 goto fail;
10614 }
10615
10616 fail:
10617 nlmsg_free(msg);
10618 return ret;
10619 }
10620
10621 #endif /* CONFIG_MBO */
10622
10623 #endif /* CONFIG_DRIVER_NL80211_QCA */
10624
10625
10626 static int nl80211_write_to_file(const char *name, unsigned int val)
10627 {
10628 int fd, len;
10629 char tmp[128];
10630
10631 fd = open(name, O_RDWR);
10632 if (fd < 0) {
10633 wpa_printf(MSG_ERROR, "nl80211: Failed to open %s: %s",
10634 name, strerror(errno));
10635 return fd;
10636 }
10637
10638 len = os_snprintf(tmp, sizeof(tmp), "%u\n", val);
10639 len = write(fd, tmp, len);
10640 if (len < 0)
10641 wpa_printf(MSG_ERROR, "nl80211: Failed to write to %s: %s",
10642 name, strerror(errno));
10643 close(fd);
10644
10645 return 0;
10646 }
10647
10648
10649 static int nl80211_configure_data_frame_filters(void *priv, u32 filter_flags)
10650 {
10651 struct i802_bss *bss = priv;
10652 char path[128];
10653 int ret;
10654
10655 wpa_printf(MSG_DEBUG, "nl80211: Data frame filter flags=0x%x",
10656 filter_flags);
10657
10658 /* Configure filtering of unicast frame encrypted using GTK */
10659 ret = os_snprintf(path, sizeof(path),
10660 "/proc/sys/net/ipv4/conf/%s/drop_unicast_in_l2_multicast",
10661 bss->ifname);
10662 if (os_snprintf_error(sizeof(path), ret))
10663 return -1;
10664
10665 ret = nl80211_write_to_file(path,
10666 !!(filter_flags &
10667 WPA_DATA_FRAME_FILTER_FLAG_GTK));
10668 if (ret) {
10669 wpa_printf(MSG_ERROR,
10670 "nl80211: Failed to set IPv4 unicast in multicast filter");
10671 return ret;
10672 }
10673
10674 os_snprintf(path, sizeof(path),
10675 "/proc/sys/net/ipv6/conf/%s/drop_unicast_in_l2_multicast",
10676 bss->ifname);
10677 ret = nl80211_write_to_file(path,
10678 !!(filter_flags &
10679 WPA_DATA_FRAME_FILTER_FLAG_GTK));
10680
10681 if (ret) {
10682 wpa_printf(MSG_ERROR,
10683 "nl80211: Failed to set IPv6 unicast in multicast filter");
10684 return ret;
10685 }
10686
10687 /* Configure filtering of unicast frame encrypted using GTK */
10688 os_snprintf(path, sizeof(path),
10689 "/proc/sys/net/ipv4/conf/%s/drop_gratuitous_arp",
10690 bss->ifname);
10691 ret = nl80211_write_to_file(path,
10692 !!(filter_flags &
10693 WPA_DATA_FRAME_FILTER_FLAG_ARP));
10694 if (ret) {
10695 wpa_printf(MSG_ERROR,
10696 "nl80211: Failed set gratuitous ARP filter");
10697 return ret;
10698 }
10699
10700 /* Configure filtering of IPv6 NA frames */
10701 os_snprintf(path, sizeof(path),
10702 "/proc/sys/net/ipv6/conf/%s/drop_unsolicited_na",
10703 bss->ifname);
10704 ret = nl80211_write_to_file(path,
10705 !!(filter_flags &
10706 WPA_DATA_FRAME_FILTER_FLAG_NA));
10707 if (ret) {
10708 wpa_printf(MSG_ERROR,
10709 "nl80211: Failed to set unsolicited NA filter");
10710 return ret;
10711 }
10712
10713 return 0;
10714 }
10715
10716
10717 static int nl80211_get_ext_capab(void *priv, enum wpa_driver_if_type type,
10718 const u8 **ext_capa, const u8 **ext_capa_mask,
10719 unsigned int *ext_capa_len)
10720 {
10721 struct i802_bss *bss = priv;
10722 struct wpa_driver_nl80211_data *drv = bss->drv;
10723 enum nl80211_iftype nlmode;
10724 unsigned int i;
10725
10726 if (!ext_capa || !ext_capa_mask || !ext_capa_len)
10727 return -1;
10728
10729 nlmode = wpa_driver_nl80211_if_type(type);
10730
10731 /* By default, use the per-radio values */
10732 *ext_capa = drv->extended_capa;
10733 *ext_capa_mask = drv->extended_capa_mask;
10734 *ext_capa_len = drv->extended_capa_len;
10735
10736 /* Replace the default value if a per-interface type value exists */
10737 for (i = 0; i < drv->num_iface_ext_capa; i++) {
10738 if (nlmode == drv->iface_ext_capa[i].iftype) {
10739 *ext_capa = drv->iface_ext_capa[i].ext_capa;
10740 *ext_capa_mask = drv->iface_ext_capa[i].ext_capa_mask;
10741 *ext_capa_len = drv->iface_ext_capa[i].ext_capa_len;
10742 break;
10743 }
10744 }
10745
10746 return 0;
10747 }
10748
10749
10750 static int nl80211_update_connection_params(
10751 void *priv, struct wpa_driver_associate_params *params,
10752 enum wpa_drv_update_connect_params_mask mask)
10753 {
10754 struct i802_bss *bss = priv;
10755 struct wpa_driver_nl80211_data *drv = bss->drv;
10756 struct nl_msg *msg;
10757 int ret = -1;
10758 enum nl80211_auth_type type;
10759
10760 msg = nl80211_drv_msg(drv, 0, NL80211_CMD_UPDATE_CONNECT_PARAMS);
10761 if (!msg)
10762 goto fail;
10763
10764 wpa_printf(MSG_DEBUG, "nl80211: Update connection params (ifindex=%d)",
10765 drv->ifindex);
10766
10767 if ((mask & WPA_DRV_UPDATE_ASSOC_IES) && params->wpa_ie) {
10768 if (nla_put(msg, NL80211_ATTR_IE, params->wpa_ie_len,
10769 params->wpa_ie))
10770 goto fail;
10771 wpa_hexdump(MSG_DEBUG, " * IEs", params->wpa_ie,
10772 params->wpa_ie_len);
10773 }
10774
10775 if (mask & WPA_DRV_UPDATE_AUTH_TYPE) {
10776 type = get_nl_auth_type(params->auth_alg);
10777 if (type == NL80211_AUTHTYPE_MAX ||
10778 nla_put_u32(msg, NL80211_ATTR_AUTH_TYPE, type))
10779 goto fail;
10780 wpa_printf(MSG_DEBUG, " * Auth Type %d", type);
10781 }
10782
10783 if ((mask & WPA_DRV_UPDATE_FILS_ERP_INFO) &&
10784 nl80211_put_fils_connect_params(drv, params, msg))
10785 goto fail;
10786
10787 ret = send_and_recv_msgs(drv, msg, NULL, NULL);
10788 msg = NULL;
10789 if (ret)
10790 wpa_dbg(drv->ctx, MSG_DEBUG,
10791 "nl80211: Update connect params command failed: ret=%d (%s)",
10792 ret, strerror(-ret));
10793
10794 fail:
10795 nlmsg_free(msg);
10796 return ret;
10797 }
10798
10799
10800 static int nl80211_send_external_auth_status(void *priv,
10801 struct external_auth *params)
10802 {
10803 struct i802_bss *bss = priv;
10804 struct wpa_driver_nl80211_data *drv = bss->drv;
10805 struct nl_msg *msg = NULL;
10806 int ret = -1;
10807
10808 /* External auth command/status is intended for drivers that implement
10809 * intenral SME but want to offload authentication processing (e.g.,
10810 * SAE) to hostapd/wpa_supplicant. Do nott send the status to drivers
10811 * which do not support AP SME or use wpa_supplicant/hostapd SME.
10812 */
10813 if (!bss->drv->device_ap_sme ||
10814 (drv->capa.flags & WPA_DRIVER_FLAGS_SME))
10815 return -1;
10816
10817 wpa_dbg(drv->ctx, MSG_DEBUG,
10818 "nl80211: External auth status: %u", params->status);
10819
10820 msg = nl80211_drv_msg(drv, 0, NL80211_CMD_EXTERNAL_AUTH);
10821 if (!msg ||
10822 nla_put_u16(msg, NL80211_ATTR_STATUS_CODE, params->status) ||
10823 (params->ssid && params->ssid_len &&
10824 nla_put(msg, NL80211_ATTR_SSID, params->ssid_len, params->ssid)) ||
10825 (params->pmkid &&
10826 nla_put(msg, NL80211_ATTR_PMKID, PMKID_LEN, params->pmkid)) ||
10827 (params->bssid &&
10828 nla_put(msg, NL80211_ATTR_BSSID, ETH_ALEN, params->bssid)))
10829 goto fail;
10830 ret = send_and_recv_msgs(drv, msg, NULL, NULL);
10831 msg = NULL;
10832 if (ret) {
10833 wpa_printf(MSG_DEBUG,
10834 "nl80211: External Auth status update failed: ret=%d (%s)",
10835 ret, strerror(-ret));
10836 goto fail;
10837 }
10838 fail:
10839 nlmsg_free(msg);
10840 return ret;
10841 }
10842
10843
10844 static int nl80211_set_4addr_mode(void *priv, const char *bridge_ifname,
10845 int val)
10846 {
10847 struct i802_bss *bss = priv;
10848 struct wpa_driver_nl80211_data *drv = bss->drv;
10849 struct nl_msg *msg;
10850 int ret = -ENOBUFS;
10851
10852 wpa_printf(MSG_DEBUG, "nl80211: %s 4addr mode (bridge_ifname: %s)",
10853 val ? "Enable" : "Disable", bridge_ifname);
10854
10855 msg = nl80211_cmd_msg(drv->first_bss, 0, NL80211_CMD_SET_INTERFACE);
10856 if (!msg || nla_put_u8(msg, NL80211_ATTR_4ADDR, val))
10857 goto fail;
10858
10859 if (bridge_ifname[0] && bss->added_if_into_bridge && !val) {
10860 if (linux_br_del_if(drv->global->ioctl_sock,
10861 bridge_ifname, bss->ifname)) {
10862 wpa_printf(MSG_ERROR,
10863 "nl80211: Failed to remove interface %s from bridge %s",
10864 bss->ifname, bridge_ifname);
10865 return -1;
10866 }
10867 bss->added_if_into_bridge = 0;
10868 }
10869
10870 ret = send_and_recv_msgs(drv, msg, NULL, NULL);
10871 msg = NULL;
10872 if (!ret) {
10873 if (bridge_ifname[0] && val &&
10874 i802_check_bridge(drv, bss, bridge_ifname, bss->ifname) < 0)
10875 return -1;
10876 return 0;
10877 }
10878
10879 fail:
10880 nlmsg_free(msg);
10881 wpa_printf(MSG_ERROR, "nl80211: Failed to enable/disable 4addr");
10882
10883 return ret;
10884 }
10885
10886
10887 const struct wpa_driver_ops wpa_driver_nl80211_ops = {
10888 .name = "nl80211",
10889 .desc = "Linux nl80211/cfg80211",
10890 .get_bssid = wpa_driver_nl80211_get_bssid,
10891 .get_ssid = wpa_driver_nl80211_get_ssid,
10892 .set_key = driver_nl80211_set_key,
10893 .scan2 = driver_nl80211_scan2,
10894 .sched_scan = wpa_driver_nl80211_sched_scan,
10895 .stop_sched_scan = wpa_driver_nl80211_stop_sched_scan,
10896 .get_scan_results2 = wpa_driver_nl80211_get_scan_results,
10897 .abort_scan = wpa_driver_nl80211_abort_scan,
10898 .deauthenticate = driver_nl80211_deauthenticate,
10899 .authenticate = driver_nl80211_authenticate,
10900 .associate = wpa_driver_nl80211_associate,
10901 .global_init = nl80211_global_init,
10902 .global_deinit = nl80211_global_deinit,
10903 .init2 = wpa_driver_nl80211_init,
10904 .deinit = driver_nl80211_deinit,
10905 .get_capa = wpa_driver_nl80211_get_capa,
10906 .set_operstate = wpa_driver_nl80211_set_operstate,
10907 .set_supp_port = wpa_driver_nl80211_set_supp_port,
10908 .set_country = wpa_driver_nl80211_set_country,
10909 .get_country = wpa_driver_nl80211_get_country,
10910 .set_ap = wpa_driver_nl80211_set_ap,
10911 .set_acl = wpa_driver_nl80211_set_acl,
10912 .if_add = wpa_driver_nl80211_if_add,
10913 .if_remove = driver_nl80211_if_remove,
10914 .send_mlme = driver_nl80211_send_mlme,
10915 .get_hw_feature_data = nl80211_get_hw_feature_data,
10916 .sta_add = wpa_driver_nl80211_sta_add,
10917 .sta_remove = driver_nl80211_sta_remove,
10918 .hapd_send_eapol = wpa_driver_nl80211_hapd_send_eapol,
10919 .sta_set_flags = wpa_driver_nl80211_sta_set_flags,
10920 .hapd_init = i802_init,
10921 .hapd_deinit = i802_deinit,
10922 .set_wds_sta = i802_set_wds_sta,
10923 .get_seqnum = i802_get_seqnum,
10924 .flush = i802_flush,
10925 .get_inact_sec = i802_get_inact_sec,
10926 .sta_clear_stats = i802_sta_clear_stats,
10927 .set_rts = i802_set_rts,
10928 .set_frag = i802_set_frag,
10929 .set_tx_queue_params = i802_set_tx_queue_params,
10930 .set_sta_vlan = driver_nl80211_set_sta_vlan,
10931 .sta_deauth = i802_sta_deauth,
10932 .sta_disassoc = i802_sta_disassoc,
10933 .read_sta_data = driver_nl80211_read_sta_data,
10934 .set_freq = i802_set_freq,
10935 .send_action = driver_nl80211_send_action,
10936 .send_action_cancel_wait = wpa_driver_nl80211_send_action_cancel_wait,
10937 .remain_on_channel = wpa_driver_nl80211_remain_on_channel,
10938 .cancel_remain_on_channel =
10939 wpa_driver_nl80211_cancel_remain_on_channel,
10940 .probe_req_report = driver_nl80211_probe_req_report,
10941 .deinit_ap = wpa_driver_nl80211_deinit_ap,
10942 .deinit_p2p_cli = wpa_driver_nl80211_deinit_p2p_cli,
10943 .resume = wpa_driver_nl80211_resume,
10944 .signal_monitor = nl80211_signal_monitor,
10945 .signal_poll = nl80211_signal_poll,
10946 .channel_info = nl80211_channel_info,
10947 .send_frame = nl80211_send_frame,
10948 .set_param = nl80211_set_param,
10949 .get_radio_name = nl80211_get_radio_name,
10950 .add_pmkid = nl80211_add_pmkid,
10951 .remove_pmkid = nl80211_remove_pmkid,
10952 .flush_pmkid = nl80211_flush_pmkid,
10953 .set_rekey_info = nl80211_set_rekey_info,
10954 .poll_client = nl80211_poll_client,
10955 .set_p2p_powersave = nl80211_set_p2p_powersave,
10956 .start_dfs_cac = nl80211_start_radar_detection,
10957 .stop_ap = wpa_driver_nl80211_stop_ap,
10958 #ifdef CONFIG_TDLS
10959 .send_tdls_mgmt = nl80211_send_tdls_mgmt,
10960 .tdls_oper = nl80211_tdls_oper,
10961 .tdls_enable_channel_switch = nl80211_tdls_enable_channel_switch,
10962 .tdls_disable_channel_switch = nl80211_tdls_disable_channel_switch,
10963 #endif /* CONFIG_TDLS */
10964 .update_ft_ies = wpa_driver_nl80211_update_ft_ies,
10965 .get_mac_addr = wpa_driver_nl80211_get_macaddr,
10966 .get_survey = wpa_driver_nl80211_get_survey,
10967 .status = wpa_driver_nl80211_status,
10968 .switch_channel = nl80211_switch_channel,
10969 #ifdef ANDROID_P2P
10970 .set_noa = wpa_driver_set_p2p_noa,
10971 .get_noa = wpa_driver_get_p2p_noa,
10972 .set_ap_wps_ie = wpa_driver_set_ap_wps_p2p_ie,
10973 #endif /* ANDROID_P2P */
10974 #ifdef ANDROID
10975 #ifndef ANDROID_LIB_STUB
10976 .driver_cmd = wpa_driver_nl80211_driver_cmd,
10977 #endif /* !ANDROID_LIB_STUB */
10978 #endif /* ANDROID */
10979 .vendor_cmd = nl80211_vendor_cmd,
10980 .set_qos_map = nl80211_set_qos_map,
10981 .set_wowlan = nl80211_set_wowlan,
10982 .set_mac_addr = nl80211_set_mac_addr,
10983 #ifdef CONFIG_MESH
10984 .init_mesh = wpa_driver_nl80211_init_mesh,
10985 .join_mesh = wpa_driver_nl80211_join_mesh,
10986 .leave_mesh = wpa_driver_nl80211_leave_mesh,
10987 #endif /* CONFIG_MESH */
10988 .br_add_ip_neigh = wpa_driver_br_add_ip_neigh,
10989 .br_delete_ip_neigh = wpa_driver_br_delete_ip_neigh,
10990 .br_port_set_attr = wpa_driver_br_port_set_attr,
10991 .br_set_net_param = wpa_driver_br_set_net_param,
10992 .add_tx_ts = nl80211_add_ts,
10993 .del_tx_ts = nl80211_del_ts,
10994 .get_ifindex = nl80211_get_ifindex,
10995 #ifdef CONFIG_DRIVER_NL80211_QCA
10996 .roaming = nl80211_roaming,
10997 .disable_fils = nl80211_disable_fils,
10998 .do_acs = wpa_driver_do_acs,
10999 .set_band = nl80211_set_band,
11000 .get_pref_freq_list = nl80211_get_pref_freq_list,
11001 .set_prob_oper_freq = nl80211_set_prob_oper_freq,
11002 .p2p_lo_start = nl80211_p2p_lo_start,
11003 .p2p_lo_stop = nl80211_p2p_lo_stop,
11004 .set_default_scan_ies = nl80211_set_default_scan_ies,
11005 .set_tdls_mode = nl80211_set_tdls_mode,
11006 #ifdef CONFIG_MBO
11007 .get_bss_transition_status = nl80211_get_bss_transition_status,
11008 .ignore_assoc_disallow = nl80211_ignore_assoc_disallow,
11009 #endif /* CONFIG_MBO */
11010 .set_bssid_blacklist = nl80211_set_bssid_blacklist,
11011 #endif /* CONFIG_DRIVER_NL80211_QCA */
11012 .configure_data_frame_filters = nl80211_configure_data_frame_filters,
11013 .get_ext_capab = nl80211_get_ext_capab,
11014 .update_connect_params = nl80211_update_connection_params,
11015 .send_external_auth_status = nl80211_send_external_auth_status,
11016 .set_4addr_mode = nl80211_set_4addr_mode,
11017 };