blob: 798e69476717d43e7121ffacf522df0302e7f01a [file] [log] [blame]
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001/*
2 * Driver interaction with Linux nl80211/cfg80211
Dmitry Shmidt807291d2015-01-27 13:40:23 -08003 * Copyright (c) 2002-2015, Jouni Malinen <j@w1.fi>
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004 * 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 *
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08009 * This software may be distributed under the terms of the BSD license.
10 * See README for more details.
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070011 */
12
13#include "includes.h"
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070014#include <sys/types.h>
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070015#include <fcntl.h>
16#include <net/if.h>
17#include <netlink/genl/genl.h>
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070018#include <netlink/genl/ctrl.h>
Dmitry Shmidt661b4f72014-09-29 14:58:27 -070019#ifdef CONFIG_LIBNL3_ROUTE
20#include <netlink/route/neighbour.h>
21#endif /* CONFIG_LIBNL3_ROUTE */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070022#include <linux/rtnetlink.h>
23#include <netpacket/packet.h>
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -080024#include <linux/errqueue.h>
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070025
26#include "common.h"
27#include "eloop.h"
Dmitry Shmidtcf32e602014-01-28 10:57:39 -080028#include "common/qca-vendor.h"
Dmitry Shmidt7832adb2014-04-29 10:53:02 -070029#include "common/qca-vendor-attr.h"
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070030#include "common/ieee802_11_defs.h"
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -080031#include "common/ieee802_11_common.h"
32#include "l2_packet/l2_packet.h"
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070033#include "netlink.h"
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080034#include "linux_defines.h"
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070035#include "linux_ioctl.h"
36#include "radiotap.h"
37#include "radiotap_iter.h"
38#include "rfkill.h"
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080039#include "driver_nl80211.h"
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -080040
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -080041
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080042#ifndef CONFIG_LIBNL20
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070043/*
44 * libnl 1.1 has a bug, it tries to allocate socket numbers densely
45 * but when you free a socket again it will mess up its bitmap and
46 * and use the wrong number the next time it needs a socket ID.
47 * Therefore, we wrap the handle alloc/destroy and add our own pid
48 * accounting.
49 */
50static uint32_t port_bitmap[32] = { 0 };
51
52static struct nl_handle *nl80211_handle_alloc(void *cb)
53{
54 struct nl_handle *handle;
55 uint32_t pid = getpid() & 0x3FFFFF;
56 int i;
57
58 handle = nl_handle_alloc_cb(cb);
59
60 for (i = 0; i < 1024; i++) {
61 if (port_bitmap[i / 32] & (1 << (i % 32)))
62 continue;
63 port_bitmap[i / 32] |= 1 << (i % 32);
64 pid += i << 22;
65 break;
66 }
67
68 nl_socket_set_local_port(handle, pid);
69
70 return handle;
71}
72
73static void nl80211_handle_destroy(struct nl_handle *handle)
74{
75 uint32_t port = nl_socket_get_local_port(handle);
76
77 port >>= 22;
78 port_bitmap[port / 32] &= ~(1 << (port % 32));
79
80 nl_handle_destroy(handle);
81}
82#endif /* CONFIG_LIBNL20 */
83
84
Dmitry Shmidt54605472013-11-08 11:10:19 -080085#ifdef ANDROID
86/* system/core/libnl_2 does not include nl_socket_set_nonblocking() */
Dmitry Shmidt54605472013-11-08 11:10:19 -080087#undef nl_socket_set_nonblocking
88#define nl_socket_set_nonblocking(h) android_nl_socket_set_nonblocking(h)
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080089
Dmitry Shmidt54605472013-11-08 11:10:19 -080090#endif /* ANDROID */
91
92
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -080093static struct nl_handle * nl_create_handle(struct nl_cb *cb, const char *dbg)
94{
95 struct nl_handle *handle;
96
97 handle = nl80211_handle_alloc(cb);
98 if (handle == NULL) {
99 wpa_printf(MSG_ERROR, "nl80211: Failed to allocate netlink "
100 "callbacks (%s)", dbg);
101 return NULL;
102 }
103
104 if (genl_connect(handle)) {
105 wpa_printf(MSG_ERROR, "nl80211: Failed to connect to generic "
106 "netlink (%s)", dbg);
107 nl80211_handle_destroy(handle);
108 return NULL;
109 }
110
111 return handle;
112}
113
114
115static void nl_destroy_handles(struct nl_handle **handle)
116{
117 if (*handle == NULL)
118 return;
119 nl80211_handle_destroy(*handle);
120 *handle = NULL;
121}
122
123
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -0700124#if __WORDSIZE == 64
125#define ELOOP_SOCKET_INVALID (intptr_t) 0x8888888888888889ULL
126#else
127#define ELOOP_SOCKET_INVALID (intptr_t) 0x88888889ULL
128#endif
129
130static void nl80211_register_eloop_read(struct nl_handle **handle,
131 eloop_sock_handler handler,
132 void *eloop_data)
133{
Dmitry Shmidt807291d2015-01-27 13:40:23 -0800134#ifdef CONFIG_LIBNL20
135 /*
136 * libnl uses a pretty small buffer (32 kB that gets converted to 64 kB)
137 * by default. It is possible to hit that limit in some cases where
138 * operations are blocked, e.g., with a burst of Deauthentication frames
139 * to hostapd and STA entry deletion. Try to increase the buffer to make
140 * this less likely to occur.
141 */
142 if (nl_socket_set_buffer_size(*handle, 262144, 0) < 0) {
143 wpa_printf(MSG_DEBUG,
144 "nl80211: Could not set nl_socket RX buffer size: %s",
145 strerror(errno));
146 /* continue anyway with the default (smaller) buffer */
147 }
148#endif /* CONFIG_LIBNL20 */
149
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -0700150 nl_socket_set_nonblocking(*handle);
151 eloop_register_read_sock(nl_socket_get_fd(*handle), handler,
152 eloop_data, *handle);
153 *handle = (void *) (((intptr_t) *handle) ^ ELOOP_SOCKET_INVALID);
154}
155
156
157static void nl80211_destroy_eloop_handle(struct nl_handle **handle)
158{
159 *handle = (void *) (((intptr_t) *handle) ^ ELOOP_SOCKET_INVALID);
160 eloop_unregister_read_sock(nl_socket_get_fd(*handle));
161 nl_destroy_handles(handle);
162}
163
164
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800165static void nl80211_global_deinit(void *priv);
Dmitry Shmidt7f656022015-02-25 14:36:37 -0800166static void nl80211_check_global(struct nl80211_global *global);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800167
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -0800168static void wpa_driver_nl80211_deinit(struct i802_bss *bss);
Dmitry Shmidt9ead16e2014-10-07 13:15:23 -0700169static int wpa_driver_nl80211_set_mode_ibss(struct i802_bss *bss,
170 struct hostapd_freq_params *freq);
Dmitry Shmidtd30ac602014-06-30 09:54:22 -0700171
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700172static int
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -0800173wpa_driver_nl80211_finish_drv_init(struct wpa_driver_nl80211_data *drv,
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800174 const u8 *set_addr, int first,
175 const char *driver_params);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800176static int nl80211_send_frame_cmd(struct i802_bss *bss,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700177 unsigned int freq, unsigned int wait,
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800178 const u8 *buf, size_t buf_len, u64 *cookie,
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800179 int no_cck, int no_ack, int offchanok,
180 const u16 *csa_offs, size_t csa_offs_len);
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -0800181static int wpa_driver_nl80211_probe_req_report(struct i802_bss *bss,
182 int report);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700183
Dmitry Shmidt9c175262016-03-03 10:20:07 -0800184#define IFIDX_ANY -1
185
186static void add_ifidx(struct wpa_driver_nl80211_data *drv, int ifidx,
187 int ifidx_reason);
188static void del_ifidx(struct wpa_driver_nl80211_data *drv, int ifidx,
189 int ifidx_reason);
190static int have_ifidx(struct wpa_driver_nl80211_data *drv, int ifidx,
191 int ifidx_reason);
Dmitry Shmidt738a26e2011-07-07 14:22:14 -0700192
Dmitry Shmidt7832adb2014-04-29 10:53:02 -0700193static int nl80211_set_channel(struct i802_bss *bss,
194 struct hostapd_freq_params *freq, int set_chan);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700195static int nl80211_disable_11b_rates(struct wpa_driver_nl80211_data *drv,
196 int ifindex, int disabled);
197
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800198static int nl80211_leave_ibss(struct wpa_driver_nl80211_data *drv,
199 int reset_mode);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800200
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -0700201static int i802_set_iface_flags(struct i802_bss *bss, int up);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800202static int nl80211_set_param(void *priv, const char *param);
Dmitry Shmidt34af3062013-07-11 10:46:32 -0700203
204
Dmitry Shmidt04f534e2013-12-09 15:50:16 -0800205/* Converts nl80211_chan_width to a common format */
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800206enum chan_width convert2width(int width)
Dmitry Shmidt04f534e2013-12-09 15:50:16 -0800207{
208 switch (width) {
209 case NL80211_CHAN_WIDTH_20_NOHT:
210 return CHAN_WIDTH_20_NOHT;
211 case NL80211_CHAN_WIDTH_20:
212 return CHAN_WIDTH_20;
213 case NL80211_CHAN_WIDTH_40:
214 return CHAN_WIDTH_40;
215 case NL80211_CHAN_WIDTH_80:
216 return CHAN_WIDTH_80;
217 case NL80211_CHAN_WIDTH_80P80:
218 return CHAN_WIDTH_80P80;
219 case NL80211_CHAN_WIDTH_160:
220 return CHAN_WIDTH_160;
221 }
222 return CHAN_WIDTH_UNKNOWN;
223}
224
225
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800226int is_ap_interface(enum nl80211_iftype nlmode)
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800227{
Dmitry Shmidt7832adb2014-04-29 10:53:02 -0700228 return nlmode == NL80211_IFTYPE_AP ||
229 nlmode == NL80211_IFTYPE_P2P_GO;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800230}
231
232
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800233int is_sta_interface(enum nl80211_iftype nlmode)
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800234{
Dmitry Shmidt7832adb2014-04-29 10:53:02 -0700235 return nlmode == NL80211_IFTYPE_STATION ||
236 nlmode == NL80211_IFTYPE_P2P_CLIENT;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800237}
238
239
Dmitry Shmidt34af3062013-07-11 10:46:32 -0700240static int is_p2p_net_interface(enum nl80211_iftype nlmode)
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800241{
Dmitry Shmidt7832adb2014-04-29 10:53:02 -0700242 return nlmode == NL80211_IFTYPE_P2P_CLIENT ||
243 nlmode == NL80211_IFTYPE_P2P_GO;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800244}
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700245
246
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800247struct i802_bss * get_bss_ifindex(struct wpa_driver_nl80211_data *drv,
248 int ifindex)
Dmitry Shmidt9ead16e2014-10-07 13:15:23 -0700249{
250 struct i802_bss *bss;
251
252 for (bss = drv->first_bss; bss; bss = bss->next) {
253 if (bss->ifindex == ifindex)
254 return bss;
255 }
256
257 return NULL;
258}
259
260
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800261static int is_mesh_interface(enum nl80211_iftype nlmode)
262{
263 return nlmode == NL80211_IFTYPE_MESH_POINT;
264}
265
266
267void nl80211_mark_disconnected(struct wpa_driver_nl80211_data *drv)
Dmitry Shmidt8bae4132013-06-06 11:25:10 -0700268{
269 if (drv->associated)
270 os_memcpy(drv->prev_bssid, drv->bssid, ETH_ALEN);
271 drv->associated = 0;
272 os_memset(drv->bssid, 0, ETH_ALEN);
273}
274
275
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700276/* nl80211 code */
277static int ack_handler(struct nl_msg *msg, void *arg)
278{
279 int *err = arg;
280 *err = 0;
281 return NL_STOP;
282}
283
284static int finish_handler(struct nl_msg *msg, void *arg)
285{
286 int *ret = arg;
287 *ret = 0;
288 return NL_SKIP;
289}
290
291static int error_handler(struct sockaddr_nl *nla, struct nlmsgerr *err,
292 void *arg)
293{
294 int *ret = arg;
295 *ret = err->error;
296 return NL_SKIP;
297}
298
299
300static int no_seq_check(struct nl_msg *msg, void *arg)
301{
302 return NL_OK;
303}
304
305
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800306static void nl80211_nlmsg_clear(struct nl_msg *msg)
307{
308 /*
309 * Clear nlmsg data, e.g., to make sure key material is not left in
310 * heap memory for unnecessarily long time.
311 */
312 if (msg) {
313 struct nlmsghdr *hdr = nlmsg_hdr(msg);
314 void *data = nlmsg_data(hdr);
315 /*
316 * This would use nlmsg_datalen() or the older nlmsg_len() if
317 * only libnl were to maintain a stable API.. Neither will work
318 * with all released versions, so just calculate the length
319 * here.
320 */
321 int len = hdr->nlmsg_len - NLMSG_HDRLEN;
322
323 os_memset(data, 0, len);
324 }
325}
326
327
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800328static int send_and_recv(struct nl80211_global *global,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700329 struct nl_handle *nl_handle, struct nl_msg *msg,
330 int (*valid_handler)(struct nl_msg *, void *),
331 void *valid_data)
332{
333 struct nl_cb *cb;
334 int err = -ENOMEM;
335
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800336 if (!msg)
337 return -ENOMEM;
338
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800339 cb = nl_cb_clone(global->nl_cb);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700340 if (!cb)
341 goto out;
342
343 err = nl_send_auto_complete(nl_handle, msg);
344 if (err < 0)
345 goto out;
346
347 err = 1;
348
349 nl_cb_err(cb, NL_CB_CUSTOM, error_handler, &err);
350 nl_cb_set(cb, NL_CB_FINISH, NL_CB_CUSTOM, finish_handler, &err);
351 nl_cb_set(cb, NL_CB_ACK, NL_CB_CUSTOM, ack_handler, &err);
352
353 if (valid_handler)
354 nl_cb_set(cb, NL_CB_VALID, NL_CB_CUSTOM,
355 valid_handler, valid_data);
356
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -0700357 while (err > 0) {
358 int res = nl_recvmsgs(nl_handle, cb);
Dmitry Shmidt71757432014-06-02 13:50:35 -0700359 if (res < 0) {
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -0700360 wpa_printf(MSG_INFO,
361 "nl80211: %s->nl_recvmsgs failed: %d",
362 __func__, res);
363 }
364 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700365 out:
366 nl_cb_put(cb);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800367 if (!valid_handler && valid_data == (void *) -1)
368 nl80211_nlmsg_clear(msg);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700369 nlmsg_free(msg);
370 return err;
371}
372
373
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800374int send_and_recv_msgs(struct wpa_driver_nl80211_data *drv,
375 struct nl_msg *msg,
376 int (*valid_handler)(struct nl_msg *, void *),
377 void *valid_data)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700378{
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800379 return send_and_recv(drv->global, drv->global->nl, msg,
380 valid_handler, valid_data);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700381}
382
383
384struct family_data {
385 const char *group;
386 int id;
387};
388
389
390static int family_handler(struct nl_msg *msg, void *arg)
391{
392 struct family_data *res = arg;
393 struct nlattr *tb[CTRL_ATTR_MAX + 1];
394 struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg));
395 struct nlattr *mcgrp;
396 int i;
397
398 nla_parse(tb, CTRL_ATTR_MAX, genlmsg_attrdata(gnlh, 0),
399 genlmsg_attrlen(gnlh, 0), NULL);
400 if (!tb[CTRL_ATTR_MCAST_GROUPS])
401 return NL_SKIP;
402
403 nla_for_each_nested(mcgrp, tb[CTRL_ATTR_MCAST_GROUPS], i) {
404 struct nlattr *tb2[CTRL_ATTR_MCAST_GRP_MAX + 1];
405 nla_parse(tb2, CTRL_ATTR_MCAST_GRP_MAX, nla_data(mcgrp),
406 nla_len(mcgrp), NULL);
407 if (!tb2[CTRL_ATTR_MCAST_GRP_NAME] ||
408 !tb2[CTRL_ATTR_MCAST_GRP_ID] ||
409 os_strncmp(nla_data(tb2[CTRL_ATTR_MCAST_GRP_NAME]),
410 res->group,
411 nla_len(tb2[CTRL_ATTR_MCAST_GRP_NAME])) != 0)
412 continue;
413 res->id = nla_get_u32(tb2[CTRL_ATTR_MCAST_GRP_ID]);
414 break;
415 };
416
417 return NL_SKIP;
418}
419
420
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800421static int nl_get_multicast_id(struct nl80211_global *global,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700422 const char *family, const char *group)
423{
424 struct nl_msg *msg;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800425 int ret;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700426 struct family_data res = { group, -ENOENT };
427
428 msg = nlmsg_alloc();
429 if (!msg)
430 return -ENOMEM;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800431 if (!genlmsg_put(msg, 0, 0, genl_ctrl_resolve(global->nl, "nlctrl"),
432 0, 0, CTRL_CMD_GETFAMILY, 0) ||
433 nla_put_string(msg, CTRL_ATTR_FAMILY_NAME, family)) {
434 nlmsg_free(msg);
435 return -1;
436 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700437
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800438 ret = send_and_recv(global, global->nl, msg, family_handler, &res);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700439 if (ret == 0)
440 ret = res.id;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700441 return ret;
442}
443
444
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800445void * nl80211_cmd(struct wpa_driver_nl80211_data *drv,
446 struct nl_msg *msg, int flags, uint8_t cmd)
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800447{
448 return genlmsg_put(msg, 0, 0, drv->global->nl80211_id,
449 0, flags, cmd, 0);
450}
451
452
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800453static int nl80211_set_iface_id(struct nl_msg *msg, struct i802_bss *bss)
454{
455 if (bss->wdev_id_set)
456 return nla_put_u64(msg, NL80211_ATTR_WDEV, bss->wdev_id);
457 return nla_put_u32(msg, NL80211_ATTR_IFINDEX, bss->ifindex);
458}
459
460
461struct nl_msg * nl80211_cmd_msg(struct i802_bss *bss, int flags, uint8_t cmd)
462{
463 struct nl_msg *msg;
464
465 msg = nlmsg_alloc();
466 if (!msg)
467 return NULL;
468
469 if (!nl80211_cmd(bss->drv, msg, flags, cmd) ||
470 nl80211_set_iface_id(msg, bss) < 0) {
471 nlmsg_free(msg);
472 return NULL;
473 }
474
475 return msg;
476}
477
478
479static struct nl_msg *
480nl80211_ifindex_msg(struct wpa_driver_nl80211_data *drv, int ifindex,
481 int flags, uint8_t cmd)
482{
483 struct nl_msg *msg;
484
485 msg = nlmsg_alloc();
486 if (!msg)
487 return NULL;
488
489 if (!nl80211_cmd(drv, msg, flags, cmd) ||
490 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex)) {
491 nlmsg_free(msg);
492 return NULL;
493 }
494
495 return msg;
496}
497
498
499struct nl_msg * nl80211_drv_msg(struct wpa_driver_nl80211_data *drv, int flags,
500 uint8_t cmd)
501{
502 return nl80211_ifindex_msg(drv, drv->ifindex, flags, cmd);
503}
504
505
506struct nl_msg * nl80211_bss_msg(struct i802_bss *bss, int flags, uint8_t cmd)
507{
508 return nl80211_ifindex_msg(bss->drv, bss->ifindex, flags, cmd);
509}
510
511
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800512struct wiphy_idx_data {
513 int wiphy_idx;
Dmitry Shmidt34af3062013-07-11 10:46:32 -0700514 enum nl80211_iftype nlmode;
515 u8 *macaddr;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800516};
517
518
519static int netdev_info_handler(struct nl_msg *msg, void *arg)
520{
521 struct nlattr *tb[NL80211_ATTR_MAX + 1];
522 struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg));
523 struct wiphy_idx_data *info = arg;
524
525 nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0),
526 genlmsg_attrlen(gnlh, 0), NULL);
527
528 if (tb[NL80211_ATTR_WIPHY])
529 info->wiphy_idx = nla_get_u32(tb[NL80211_ATTR_WIPHY]);
530
Dmitry Shmidt34af3062013-07-11 10:46:32 -0700531 if (tb[NL80211_ATTR_IFTYPE])
532 info->nlmode = nla_get_u32(tb[NL80211_ATTR_IFTYPE]);
533
534 if (tb[NL80211_ATTR_MAC] && info->macaddr)
535 os_memcpy(info->macaddr, nla_data(tb[NL80211_ATTR_MAC]),
536 ETH_ALEN);
537
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800538 return NL_SKIP;
539}
540
541
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800542int nl80211_get_wiphy_index(struct i802_bss *bss)
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800543{
544 struct nl_msg *msg;
545 struct wiphy_idx_data data = {
546 .wiphy_idx = -1,
Dmitry Shmidt34af3062013-07-11 10:46:32 -0700547 .macaddr = NULL,
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800548 };
549
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800550 if (!(msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_GET_INTERFACE)))
551 return -1;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800552
553 if (send_and_recv_msgs(bss->drv, msg, netdev_info_handler, &data) == 0)
554 return data.wiphy_idx;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800555 return -1;
556}
557
558
Dmitry Shmidt34af3062013-07-11 10:46:32 -0700559static enum nl80211_iftype nl80211_get_ifmode(struct i802_bss *bss)
560{
561 struct nl_msg *msg;
562 struct wiphy_idx_data data = {
563 .nlmode = NL80211_IFTYPE_UNSPECIFIED,
564 .macaddr = NULL,
565 };
566
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800567 if (!(msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_GET_INTERFACE)))
568 return NL80211_IFTYPE_UNSPECIFIED;
Dmitry Shmidt34af3062013-07-11 10:46:32 -0700569
570 if (send_and_recv_msgs(bss->drv, msg, netdev_info_handler, &data) == 0)
571 return data.nlmode;
Dmitry Shmidt34af3062013-07-11 10:46:32 -0700572 return NL80211_IFTYPE_UNSPECIFIED;
573}
574
575
Dmitry Shmidt34af3062013-07-11 10:46:32 -0700576static int nl80211_get_macaddr(struct i802_bss *bss)
577{
578 struct nl_msg *msg;
579 struct wiphy_idx_data data = {
580 .macaddr = bss->addr,
581 };
582
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800583 if (!(msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_GET_INTERFACE)))
584 return -1;
Dmitry Shmidt34af3062013-07-11 10:46:32 -0700585
586 return send_and_recv_msgs(bss->drv, msg, netdev_info_handler, &data);
Dmitry Shmidt34af3062013-07-11 10:46:32 -0700587}
Dmitry Shmidt34af3062013-07-11 10:46:32 -0700588
589
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800590static int nl80211_register_beacons(struct wpa_driver_nl80211_data *drv,
591 struct nl80211_wiphy_data *w)
592{
593 struct nl_msg *msg;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800594 int ret;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800595
596 msg = nlmsg_alloc();
597 if (!msg)
598 return -1;
599
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800600 if (!nl80211_cmd(drv, msg, 0, NL80211_CMD_REGISTER_BEACONS) ||
601 nla_put_u32(msg, NL80211_ATTR_WIPHY, w->wiphy_idx)) {
602 nlmsg_free(msg);
603 return -1;
604 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800605
606 ret = send_and_recv(drv->global, w->nl_beacons, msg, NULL, NULL);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800607 if (ret) {
608 wpa_printf(MSG_DEBUG, "nl80211: Register beacons command "
609 "failed: ret=%d (%s)",
610 ret, strerror(-ret));
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800611 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800612 return ret;
613}
614
615
616static void nl80211_recv_beacons(int sock, void *eloop_ctx, void *handle)
617{
618 struct nl80211_wiphy_data *w = eloop_ctx;
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -0700619 int res;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800620
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -0800621 wpa_printf(MSG_EXCESSIVE, "nl80211: Beacon event message available");
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800622
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -0700623 res = nl_recvmsgs(handle, w->nl_cb);
Dmitry Shmidt71757432014-06-02 13:50:35 -0700624 if (res < 0) {
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -0700625 wpa_printf(MSG_INFO, "nl80211: %s->nl_recvmsgs failed: %d",
626 __func__, res);
627 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800628}
629
630
631static int process_beacon_event(struct nl_msg *msg, void *arg)
632{
633 struct nl80211_wiphy_data *w = arg;
634 struct wpa_driver_nl80211_data *drv;
635 struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg));
636 struct nlattr *tb[NL80211_ATTR_MAX + 1];
637 union wpa_event_data event;
638
639 nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0),
640 genlmsg_attrlen(gnlh, 0), NULL);
641
642 if (gnlh->cmd != NL80211_CMD_FRAME) {
643 wpa_printf(MSG_DEBUG, "nl80211: Unexpected beacon event? (%d)",
644 gnlh->cmd);
645 return NL_SKIP;
646 }
647
648 if (!tb[NL80211_ATTR_FRAME])
649 return NL_SKIP;
650
651 dl_list_for_each(drv, &w->drvs, struct wpa_driver_nl80211_data,
652 wiphy_list) {
653 os_memset(&event, 0, sizeof(event));
654 event.rx_mgmt.frame = nla_data(tb[NL80211_ATTR_FRAME]);
655 event.rx_mgmt.frame_len = nla_len(tb[NL80211_ATTR_FRAME]);
656 wpa_supplicant_event(drv->ctx, EVENT_RX_MGMT, &event);
657 }
658
659 return NL_SKIP;
660}
661
662
663static struct nl80211_wiphy_data *
664nl80211_get_wiphy_data_ap(struct i802_bss *bss)
665{
666 static DEFINE_DL_LIST(nl80211_wiphys);
667 struct nl80211_wiphy_data *w;
668 int wiphy_idx, found = 0;
669 struct i802_bss *tmp_bss;
670
671 if (bss->wiphy_data != NULL)
672 return bss->wiphy_data;
673
674 wiphy_idx = nl80211_get_wiphy_index(bss);
675
676 dl_list_for_each(w, &nl80211_wiphys, struct nl80211_wiphy_data, list) {
677 if (w->wiphy_idx == wiphy_idx)
678 goto add;
679 }
680
681 /* alloc new one */
682 w = os_zalloc(sizeof(*w));
683 if (w == NULL)
684 return NULL;
685 w->wiphy_idx = wiphy_idx;
686 dl_list_init(&w->bsss);
687 dl_list_init(&w->drvs);
688
689 w->nl_cb = nl_cb_alloc(NL_CB_DEFAULT);
690 if (!w->nl_cb) {
691 os_free(w);
692 return NULL;
693 }
694 nl_cb_set(w->nl_cb, NL_CB_SEQ_CHECK, NL_CB_CUSTOM, no_seq_check, NULL);
695 nl_cb_set(w->nl_cb, NL_CB_VALID, NL_CB_CUSTOM, process_beacon_event,
696 w);
697
698 w->nl_beacons = nl_create_handle(bss->drv->global->nl_cb,
699 "wiphy beacons");
700 if (w->nl_beacons == NULL) {
701 os_free(w);
702 return NULL;
703 }
704
705 if (nl80211_register_beacons(bss->drv, w)) {
706 nl_destroy_handles(&w->nl_beacons);
707 os_free(w);
708 return NULL;
709 }
710
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -0700711 nl80211_register_eloop_read(&w->nl_beacons, nl80211_recv_beacons, w);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800712
713 dl_list_add(&nl80211_wiphys, &w->list);
714
715add:
716 /* drv entry for this bss already there? */
717 dl_list_for_each(tmp_bss, &w->bsss, struct i802_bss, wiphy_list) {
718 if (tmp_bss->drv == bss->drv) {
719 found = 1;
720 break;
721 }
722 }
723 /* if not add it */
724 if (!found)
725 dl_list_add(&w->drvs, &bss->drv->wiphy_list);
726
727 dl_list_add(&w->bsss, &bss->wiphy_list);
728 bss->wiphy_data = w;
729 return w;
730}
731
732
733static void nl80211_put_wiphy_data_ap(struct i802_bss *bss)
734{
735 struct nl80211_wiphy_data *w = bss->wiphy_data;
736 struct i802_bss *tmp_bss;
737 int found = 0;
738
739 if (w == NULL)
740 return;
741 bss->wiphy_data = NULL;
742 dl_list_del(&bss->wiphy_list);
743
744 /* still any for this drv present? */
745 dl_list_for_each(tmp_bss, &w->bsss, struct i802_bss, wiphy_list) {
746 if (tmp_bss->drv == bss->drv) {
747 found = 1;
748 break;
749 }
750 }
751 /* if not remove it */
752 if (!found)
753 dl_list_del(&bss->drv->wiphy_list);
754
755 if (!dl_list_empty(&w->bsss))
756 return;
757
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -0700758 nl80211_destroy_eloop_handle(&w->nl_beacons);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800759
760 nl_cb_put(w->nl_cb);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800761 dl_list_del(&w->list);
762 os_free(w);
763}
764
765
Dmitry Shmidte4663042016-04-04 10:07:49 -0700766static unsigned int nl80211_get_ifindex(void *priv)
767{
768 struct i802_bss *bss = priv;
769 struct wpa_driver_nl80211_data *drv = bss->drv;
770
771 return drv->ifindex;
772}
773
774
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700775static int wpa_driver_nl80211_get_bssid(void *priv, u8 *bssid)
776{
777 struct i802_bss *bss = priv;
778 struct wpa_driver_nl80211_data *drv = bss->drv;
779 if (!drv->associated)
780 return -1;
781 os_memcpy(bssid, drv->bssid, ETH_ALEN);
782 return 0;
783}
784
785
786static int wpa_driver_nl80211_get_ssid(void *priv, u8 *ssid)
787{
788 struct i802_bss *bss = priv;
789 struct wpa_driver_nl80211_data *drv = bss->drv;
790 if (!drv->associated)
791 return -1;
792 os_memcpy(ssid, drv->ssid, drv->ssid_len);
793 return drv->ssid_len;
794}
795
796
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800797static void wpa_driver_nl80211_event_newlink(
Dmitry Shmidte4663042016-04-04 10:07:49 -0700798 struct nl80211_global *global, struct wpa_driver_nl80211_data *drv,
799 int ifindex, const char *ifname)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700800{
801 union wpa_event_data event;
802
Dmitry Shmidte4663042016-04-04 10:07:49 -0700803 if (drv && os_strcmp(drv->first_bss->ifname, ifname) == 0) {
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800804 if (if_nametoindex(drv->first_bss->ifname) == 0) {
805 wpa_printf(MSG_DEBUG, "nl80211: Interface %s does not exist - ignore RTM_NEWLINK",
806 drv->first_bss->ifname);
807 return;
Dmitry Shmidt04949592012-07-19 12:16:46 -0700808 }
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800809 if (!drv->if_removed)
810 return;
811 wpa_printf(MSG_DEBUG, "nl80211: Mark if_removed=0 for %s based on RTM_NEWLINK event",
812 drv->first_bss->ifname);
813 drv->if_removed = 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700814 }
815
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800816 os_memset(&event, 0, sizeof(event));
Dmitry Shmidte4663042016-04-04 10:07:49 -0700817 event.interface_status.ifindex = ifindex;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800818 os_strlcpy(event.interface_status.ifname, ifname,
819 sizeof(event.interface_status.ifname));
820 event.interface_status.ievent = EVENT_INTERFACE_ADDED;
Dmitry Shmidte4663042016-04-04 10:07:49 -0700821 if (drv)
822 wpa_supplicant_event(drv->ctx, EVENT_INTERFACE_STATUS, &event);
823 else
824 wpa_supplicant_event_global(global->ctx, EVENT_INTERFACE_STATUS,
825 &event);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800826}
827
828
829static void wpa_driver_nl80211_event_dellink(
Dmitry Shmidte4663042016-04-04 10:07:49 -0700830 struct nl80211_global *global, struct wpa_driver_nl80211_data *drv,
831 int ifindex, const char *ifname)
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800832{
833 union wpa_event_data event;
834
Dmitry Shmidte4663042016-04-04 10:07:49 -0700835 if (drv && os_strcmp(drv->first_bss->ifname, ifname) == 0) {
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800836 if (drv->if_removed) {
837 wpa_printf(MSG_DEBUG, "nl80211: if_removed already set - ignore RTM_DELLINK event for %s",
838 ifname);
839 return;
840 }
841 wpa_printf(MSG_DEBUG, "RTM_DELLINK: Interface '%s' removed - mark if_removed=1",
842 ifname);
843 drv->if_removed = 1;
844 } else {
845 wpa_printf(MSG_DEBUG, "RTM_DELLINK: Interface '%s' removed",
846 ifname);
847 }
848
849 os_memset(&event, 0, sizeof(event));
Dmitry Shmidte4663042016-04-04 10:07:49 -0700850 event.interface_status.ifindex = ifindex;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800851 os_strlcpy(event.interface_status.ifname, ifname,
852 sizeof(event.interface_status.ifname));
853 event.interface_status.ievent = EVENT_INTERFACE_REMOVED;
Dmitry Shmidte4663042016-04-04 10:07:49 -0700854 if (drv)
855 wpa_supplicant_event(drv->ctx, EVENT_INTERFACE_STATUS, &event);
856 else
857 wpa_supplicant_event_global(global->ctx, EVENT_INTERFACE_STATUS,
858 &event);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700859}
860
861
862static int wpa_driver_nl80211_own_ifname(struct wpa_driver_nl80211_data *drv,
863 u8 *buf, size_t len)
864{
865 int attrlen, rta_len;
866 struct rtattr *attr;
867
868 attrlen = len;
869 attr = (struct rtattr *) buf;
870
871 rta_len = RTA_ALIGN(sizeof(struct rtattr));
872 while (RTA_OK(attr, attrlen)) {
873 if (attr->rta_type == IFLA_IFNAME) {
Dmitry Shmidtcce06662013-11-04 18:44:24 -0800874 if (os_strcmp(((char *) attr) + rta_len,
875 drv->first_bss->ifname) == 0)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700876 return 1;
877 else
878 break;
879 }
880 attr = RTA_NEXT(attr, attrlen);
881 }
882
883 return 0;
884}
885
886
887static int wpa_driver_nl80211_own_ifindex(struct wpa_driver_nl80211_data *drv,
888 int ifindex, u8 *buf, size_t len)
889{
890 if (drv->ifindex == ifindex)
891 return 1;
892
893 if (drv->if_removed && wpa_driver_nl80211_own_ifname(drv, buf, len)) {
Dmitry Shmidt7f656022015-02-25 14:36:37 -0800894 nl80211_check_global(drv->global);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700895 wpa_printf(MSG_DEBUG, "nl80211: Update ifindex for a removed "
896 "interface");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800897 wpa_driver_nl80211_finish_drv_init(drv, NULL, 0, NULL);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700898 return 1;
899 }
900
901 return 0;
902}
903
904
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800905static struct wpa_driver_nl80211_data *
906nl80211_find_drv(struct nl80211_global *global, int idx, u8 *buf, size_t len)
907{
908 struct wpa_driver_nl80211_data *drv;
909 dl_list_for_each(drv, &global->interfaces,
910 struct wpa_driver_nl80211_data, list) {
911 if (wpa_driver_nl80211_own_ifindex(drv, idx, buf, len) ||
Dmitry Shmidt9c175262016-03-03 10:20:07 -0800912 have_ifidx(drv, idx, IFIDX_ANY))
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800913 return drv;
914 }
915 return NULL;
916}
917
918
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700919static void wpa_driver_nl80211_event_rtm_newlink(void *ctx,
920 struct ifinfomsg *ifi,
921 u8 *buf, size_t len)
922{
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800923 struct nl80211_global *global = ctx;
924 struct wpa_driver_nl80211_data *drv;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800925 int attrlen;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700926 struct rtattr *attr;
927 u32 brid = 0;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800928 char namebuf[IFNAMSIZ];
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800929 char ifname[IFNAMSIZ + 1];
930 char extra[100], *pos, *end;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700931
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800932 extra[0] = '\0';
933 pos = extra;
934 end = pos + sizeof(extra);
935 ifname[0] = '\0';
936
937 attrlen = len;
938 attr = (struct rtattr *) buf;
939 while (RTA_OK(attr, attrlen)) {
940 switch (attr->rta_type) {
941 case IFLA_IFNAME:
942 if (RTA_PAYLOAD(attr) >= IFNAMSIZ)
943 break;
944 os_memcpy(ifname, RTA_DATA(attr), RTA_PAYLOAD(attr));
945 ifname[RTA_PAYLOAD(attr)] = '\0';
946 break;
947 case IFLA_MASTER:
948 brid = nla_get_u32((struct nlattr *) attr);
949 pos += os_snprintf(pos, end - pos, " master=%u", brid);
950 break;
951 case IFLA_WIRELESS:
952 pos += os_snprintf(pos, end - pos, " wext");
953 break;
954 case IFLA_OPERSTATE:
955 pos += os_snprintf(pos, end - pos, " operstate=%u",
956 nla_get_u32((struct nlattr *) attr));
957 break;
958 case IFLA_LINKMODE:
959 pos += os_snprintf(pos, end - pos, " linkmode=%u",
960 nla_get_u32((struct nlattr *) attr));
961 break;
962 }
963 attr = RTA_NEXT(attr, attrlen);
964 }
965 extra[sizeof(extra) - 1] = '\0';
966
Dmitry Shmidt661b4f72014-09-29 14:58:27 -0700967 wpa_printf(MSG_DEBUG, "RTM_NEWLINK: ifi_index=%d ifname=%s%s ifi_family=%d ifi_flags=0x%x (%s%s%s%s)",
968 ifi->ifi_index, ifname, extra, ifi->ifi_family,
969 ifi->ifi_flags,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700970 (ifi->ifi_flags & IFF_UP) ? "[UP]" : "",
971 (ifi->ifi_flags & IFF_RUNNING) ? "[RUNNING]" : "",
972 (ifi->ifi_flags & IFF_LOWER_UP) ? "[LOWER_UP]" : "",
973 (ifi->ifi_flags & IFF_DORMANT) ? "[DORMANT]" : "");
974
Dmitry Shmidte4663042016-04-04 10:07:49 -0700975 drv = nl80211_find_drv(global, ifi->ifi_index, buf, len);
976 if (!drv)
977 goto event_newlink;
978
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700979 if (!drv->if_disabled && !(ifi->ifi_flags & IFF_UP)) {
Dmitry Shmidt7f656022015-02-25 14:36:37 -0800980 namebuf[0] = '\0';
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800981 if (if_indextoname(ifi->ifi_index, namebuf) &&
Dmitry Shmidt7f656022015-02-25 14:36:37 -0800982 linux_iface_up(drv->global->ioctl_sock, namebuf) > 0) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800983 wpa_printf(MSG_DEBUG, "nl80211: Ignore interface down "
984 "event since interface %s is up", namebuf);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800985 drv->ignore_if_down_event = 0;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800986 return;
987 }
Dmitry Shmidt7f656022015-02-25 14:36:37 -0800988 wpa_printf(MSG_DEBUG, "nl80211: Interface down (%s/%s)",
989 namebuf, ifname);
990 if (os_strcmp(drv->first_bss->ifname, ifname) != 0) {
991 wpa_printf(MSG_DEBUG,
992 "nl80211: Not the main interface (%s) - do not indicate interface down",
993 drv->first_bss->ifname);
994 } else if (drv->ignore_if_down_event) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800995 wpa_printf(MSG_DEBUG, "nl80211: Ignore interface down "
996 "event generated by mode change");
997 drv->ignore_if_down_event = 0;
998 } else {
999 drv->if_disabled = 1;
1000 wpa_supplicant_event(drv->ctx,
1001 EVENT_INTERFACE_DISABLED, NULL);
Dmitry Shmidta38abf92014-03-06 13:38:44 -08001002
1003 /*
1004 * Try to get drv again, since it may be removed as
1005 * part of the EVENT_INTERFACE_DISABLED handling for
1006 * dynamic interfaces
1007 */
1008 drv = nl80211_find_drv(global, ifi->ifi_index,
1009 buf, len);
1010 if (!drv)
1011 return;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001012 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001013 }
1014
1015 if (drv->if_disabled && (ifi->ifi_flags & IFF_UP)) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001016 if (if_indextoname(ifi->ifi_index, namebuf) &&
Dmitry Shmidt7f656022015-02-25 14:36:37 -08001017 linux_iface_up(drv->global->ioctl_sock, namebuf) == 0) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001018 wpa_printf(MSG_DEBUG, "nl80211: Ignore interface up "
1019 "event since interface %s is down",
1020 namebuf);
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001021 } else if (if_nametoindex(drv->first_bss->ifname) == 0) {
Dmitry Shmidt04949592012-07-19 12:16:46 -07001022 wpa_printf(MSG_DEBUG, "nl80211: Ignore interface up "
1023 "event since interface %s does not exist",
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001024 drv->first_bss->ifname);
Dmitry Shmidt04949592012-07-19 12:16:46 -07001025 } else if (drv->if_removed) {
1026 wpa_printf(MSG_DEBUG, "nl80211: Ignore interface up "
1027 "event since interface %s is marked "
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001028 "removed", drv->first_bss->ifname);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001029 } else {
Dmitry Shmidt9ead16e2014-10-07 13:15:23 -07001030 struct i802_bss *bss;
1031 u8 addr[ETH_ALEN];
1032
1033 /* Re-read MAC address as it may have changed */
1034 bss = get_bss_ifindex(drv, ifi->ifi_index);
1035 if (bss &&
1036 linux_get_ifhwaddr(drv->global->ioctl_sock,
1037 bss->ifname, addr) < 0) {
1038 wpa_printf(MSG_DEBUG,
1039 "nl80211: %s: failed to re-read MAC address",
1040 bss->ifname);
1041 } else if (bss &&
1042 os_memcmp(addr, bss->addr, ETH_ALEN) != 0) {
1043 wpa_printf(MSG_DEBUG,
1044 "nl80211: Own MAC address on ifindex %d (%s) changed from "
1045 MACSTR " to " MACSTR,
1046 ifi->ifi_index, bss->ifname,
1047 MAC2STR(bss->addr),
1048 MAC2STR(addr));
1049 os_memcpy(bss->addr, addr, ETH_ALEN);
1050 }
1051
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001052 wpa_printf(MSG_DEBUG, "nl80211: Interface up");
1053 drv->if_disabled = 0;
1054 wpa_supplicant_event(drv->ctx, EVENT_INTERFACE_ENABLED,
1055 NULL);
1056 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001057 }
1058
1059 /*
1060 * Some drivers send the association event before the operup event--in
1061 * this case, lifting operstate in wpa_driver_nl80211_set_operstate()
1062 * fails. This will hit us when wpa_supplicant does not need to do
1063 * IEEE 802.1X authentication
1064 */
1065 if (drv->operstate == 1 &&
1066 (ifi->ifi_flags & (IFF_LOWER_UP | IFF_DORMANT)) == IFF_LOWER_UP &&
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001067 !(ifi->ifi_flags & IFF_RUNNING)) {
1068 wpa_printf(MSG_DEBUG, "nl80211: Set IF_OPER_UP again based on ifi_flags and expected operstate");
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001069 netlink_send_oper_ifla(drv->global->netlink, drv->ifindex,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001070 -1, IF_OPER_UP);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001071 }
1072
Dmitry Shmidte4663042016-04-04 10:07:49 -07001073event_newlink:
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001074 if (ifname[0])
Dmitry Shmidte4663042016-04-04 10:07:49 -07001075 wpa_driver_nl80211_event_newlink(global, drv, ifi->ifi_index,
1076 ifname);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001077
Dmitry Shmidte4663042016-04-04 10:07:49 -07001078 if (ifi->ifi_family == AF_BRIDGE && brid && drv) {
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001079 struct i802_bss *bss;
1080
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001081 /* device has been added to bridge */
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001082 if (!if_indextoname(brid, namebuf)) {
1083 wpa_printf(MSG_DEBUG,
1084 "nl80211: Could not find bridge ifname for ifindex %u",
1085 brid);
1086 return;
1087 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001088 wpa_printf(MSG_DEBUG, "nl80211: Add ifindex %u for bridge %s",
1089 brid, namebuf);
Dmitry Shmidt9c175262016-03-03 10:20:07 -08001090 add_ifidx(drv, brid, ifi->ifi_index);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001091
1092 for (bss = drv->first_bss; bss; bss = bss->next) {
1093 if (os_strcmp(ifname, bss->ifname) == 0) {
1094 os_strlcpy(bss->brname, namebuf, IFNAMSIZ);
1095 break;
1096 }
1097 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001098 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001099}
1100
1101
1102static void wpa_driver_nl80211_event_rtm_dellink(void *ctx,
1103 struct ifinfomsg *ifi,
1104 u8 *buf, size_t len)
1105{
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001106 struct nl80211_global *global = ctx;
1107 struct wpa_driver_nl80211_data *drv;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001108 int attrlen;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001109 struct rtattr *attr;
1110 u32 brid = 0;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001111 char ifname[IFNAMSIZ + 1];
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07001112 char extra[100], *pos, *end;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001113
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07001114 extra[0] = '\0';
1115 pos = extra;
1116 end = pos + sizeof(extra);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001117 ifname[0] = '\0';
1118
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001119 attrlen = len;
1120 attr = (struct rtattr *) buf;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001121 while (RTA_OK(attr, attrlen)) {
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001122 switch (attr->rta_type) {
1123 case IFLA_IFNAME:
1124 if (RTA_PAYLOAD(attr) >= IFNAMSIZ)
1125 break;
1126 os_memcpy(ifname, RTA_DATA(attr), RTA_PAYLOAD(attr));
1127 ifname[RTA_PAYLOAD(attr)] = '\0';
1128 break;
1129 case IFLA_MASTER:
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001130 brid = nla_get_u32((struct nlattr *) attr);
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07001131 pos += os_snprintf(pos, end - pos, " master=%u", brid);
1132 break;
1133 case IFLA_OPERSTATE:
1134 pos += os_snprintf(pos, end - pos, " operstate=%u",
1135 nla_get_u32((struct nlattr *) attr));
1136 break;
1137 case IFLA_LINKMODE:
1138 pos += os_snprintf(pos, end - pos, " linkmode=%u",
1139 nla_get_u32((struct nlattr *) attr));
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001140 break;
1141 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001142 attr = RTA_NEXT(attr, attrlen);
1143 }
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07001144 extra[sizeof(extra) - 1] = '\0';
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001145
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07001146 wpa_printf(MSG_DEBUG, "RTM_DELLINK: ifi_index=%d ifname=%s%s ifi_family=%d ifi_flags=0x%x (%s%s%s%s)",
1147 ifi->ifi_index, ifname, extra, ifi->ifi_family,
1148 ifi->ifi_flags,
1149 (ifi->ifi_flags & IFF_UP) ? "[UP]" : "",
1150 (ifi->ifi_flags & IFF_RUNNING) ? "[RUNNING]" : "",
1151 (ifi->ifi_flags & IFF_LOWER_UP) ? "[LOWER_UP]" : "",
1152 (ifi->ifi_flags & IFF_DORMANT) ? "[DORMANT]" : "");
1153
Dmitry Shmidte4663042016-04-04 10:07:49 -07001154 drv = nl80211_find_drv(global, ifi->ifi_index, buf, len);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001155
Dmitry Shmidte4663042016-04-04 10:07:49 -07001156 if (ifi->ifi_family == AF_BRIDGE && brid && drv) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001157 /* device has been removed from bridge */
1158 char namebuf[IFNAMSIZ];
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001159
1160 if (!if_indextoname(brid, namebuf)) {
1161 wpa_printf(MSG_DEBUG,
1162 "nl80211: Could not find bridge ifname for ifindex %u",
1163 brid);
1164 } else {
1165 wpa_printf(MSG_DEBUG,
1166 "nl80211: Remove ifindex %u for bridge %s",
1167 brid, namebuf);
1168 }
Dmitry Shmidt9c175262016-03-03 10:20:07 -08001169 del_ifidx(drv, brid, ifi->ifi_index);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001170 }
Dmitry Shmidte4663042016-04-04 10:07:49 -07001171
1172 if (ifi->ifi_family != AF_BRIDGE || !brid)
1173 wpa_driver_nl80211_event_dellink(global, drv, ifi->ifi_index,
1174 ifname);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001175}
1176
1177
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001178unsigned int nl80211_get_assoc_freq(struct wpa_driver_nl80211_data *drv)
Jouni Malinen87fd2792011-05-16 18:35:42 +03001179{
1180 struct nl_msg *msg;
1181 int ret;
1182 struct nl80211_bss_info_arg arg;
1183
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001184 msg = nl80211_drv_msg(drv, NLM_F_DUMP, NL80211_CMD_GET_SCAN);
Jouni Malinen87fd2792011-05-16 18:35:42 +03001185 os_memset(&arg, 0, sizeof(arg));
Jouni Malinen87fd2792011-05-16 18:35:42 +03001186 arg.drv = drv;
1187 ret = send_and_recv_msgs(drv, msg, bss_info_handler, &arg);
Jouni Malinen87fd2792011-05-16 18:35:42 +03001188 if (ret == 0) {
Dmitry Shmidt6dc03bd2014-05-16 10:40:13 -07001189 unsigned int freq = drv->nlmode == NL80211_IFTYPE_ADHOC ?
1190 arg.ibss_freq : arg.assoc_freq;
Jouni Malinen87fd2792011-05-16 18:35:42 +03001191 wpa_printf(MSG_DEBUG, "nl80211: Operating frequency for the "
Dmitry Shmidt6dc03bd2014-05-16 10:40:13 -07001192 "associated BSS from scan results: %u MHz", freq);
1193 if (freq)
1194 drv->assoc_freq = freq;
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -07001195 return drv->assoc_freq;
Jouni Malinen87fd2792011-05-16 18:35:42 +03001196 }
1197 wpa_printf(MSG_DEBUG, "nl80211: Scan result fetch failed: ret=%d "
1198 "(%s)", ret, strerror(-ret));
Jouni Malinen87fd2792011-05-16 18:35:42 +03001199 return drv->assoc_freq;
1200}
1201
1202
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001203static int get_link_signal(struct nl_msg *msg, void *arg)
1204{
1205 struct nlattr *tb[NL80211_ATTR_MAX + 1];
1206 struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg));
1207 struct nlattr *sinfo[NL80211_STA_INFO_MAX + 1];
1208 static struct nla_policy policy[NL80211_STA_INFO_MAX + 1] = {
1209 [NL80211_STA_INFO_SIGNAL] = { .type = NLA_U8 },
Dmitry Shmidt34af3062013-07-11 10:46:32 -07001210 [NL80211_STA_INFO_SIGNAL_AVG] = { .type = NLA_U8 },
Dmitry Shmidtf73259c2015-03-17 11:00:54 -07001211 [NL80211_STA_INFO_BEACON_SIGNAL_AVG] = { .type = NLA_U8 },
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001212 };
1213 struct nlattr *rinfo[NL80211_RATE_INFO_MAX + 1];
1214 static struct nla_policy rate_policy[NL80211_RATE_INFO_MAX + 1] = {
1215 [NL80211_RATE_INFO_BITRATE] = { .type = NLA_U16 },
1216 [NL80211_RATE_INFO_MCS] = { .type = NLA_U8 },
1217 [NL80211_RATE_INFO_40_MHZ_WIDTH] = { .type = NLA_FLAG },
1218 [NL80211_RATE_INFO_SHORT_GI] = { .type = NLA_FLAG },
1219 };
1220 struct wpa_signal_info *sig_change = arg;
1221
1222 nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0),
1223 genlmsg_attrlen(gnlh, 0), NULL);
1224 if (!tb[NL80211_ATTR_STA_INFO] ||
1225 nla_parse_nested(sinfo, NL80211_STA_INFO_MAX,
1226 tb[NL80211_ATTR_STA_INFO], policy))
1227 return NL_SKIP;
1228 if (!sinfo[NL80211_STA_INFO_SIGNAL])
1229 return NL_SKIP;
1230
1231 sig_change->current_signal =
1232 (s8) nla_get_u8(sinfo[NL80211_STA_INFO_SIGNAL]);
1233
Dmitry Shmidt34af3062013-07-11 10:46:32 -07001234 if (sinfo[NL80211_STA_INFO_SIGNAL_AVG])
1235 sig_change->avg_signal =
1236 (s8) nla_get_u8(sinfo[NL80211_STA_INFO_SIGNAL_AVG]);
1237 else
1238 sig_change->avg_signal = 0;
1239
Dmitry Shmidtf73259c2015-03-17 11:00:54 -07001240 if (sinfo[NL80211_STA_INFO_BEACON_SIGNAL_AVG])
1241 sig_change->avg_beacon_signal =
1242 (s8)
1243 nla_get_u8(sinfo[NL80211_STA_INFO_BEACON_SIGNAL_AVG]);
1244 else
1245 sig_change->avg_beacon_signal = 0;
1246
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001247 if (sinfo[NL80211_STA_INFO_TX_BITRATE]) {
1248 if (nla_parse_nested(rinfo, NL80211_RATE_INFO_MAX,
1249 sinfo[NL80211_STA_INFO_TX_BITRATE],
1250 rate_policy)) {
1251 sig_change->current_txrate = 0;
1252 } else {
1253 if (rinfo[NL80211_RATE_INFO_BITRATE]) {
1254 sig_change->current_txrate =
1255 nla_get_u16(rinfo[
1256 NL80211_RATE_INFO_BITRATE]) * 100;
1257 }
1258 }
1259 }
1260
1261 return NL_SKIP;
1262}
1263
1264
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001265int nl80211_get_link_signal(struct wpa_driver_nl80211_data *drv,
1266 struct wpa_signal_info *sig)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001267{
1268 struct nl_msg *msg;
1269
1270 sig->current_signal = -9999;
1271 sig->current_txrate = 0;
1272
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001273 if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_GET_STATION)) ||
1274 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, drv->bssid)) {
1275 nlmsg_free(msg);
1276 return -ENOBUFS;
1277 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001278
1279 return send_and_recv_msgs(drv, msg, get_link_signal, sig);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001280}
1281
1282
1283static int get_link_noise(struct nl_msg *msg, void *arg)
1284{
1285 struct nlattr *tb[NL80211_ATTR_MAX + 1];
1286 struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg));
1287 struct nlattr *sinfo[NL80211_SURVEY_INFO_MAX + 1];
1288 static struct nla_policy survey_policy[NL80211_SURVEY_INFO_MAX + 1] = {
1289 [NL80211_SURVEY_INFO_FREQUENCY] = { .type = NLA_U32 },
1290 [NL80211_SURVEY_INFO_NOISE] = { .type = NLA_U8 },
1291 };
1292 struct wpa_signal_info *sig_change = arg;
1293
1294 nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0),
1295 genlmsg_attrlen(gnlh, 0), NULL);
1296
1297 if (!tb[NL80211_ATTR_SURVEY_INFO]) {
1298 wpa_printf(MSG_DEBUG, "nl80211: survey data missing!");
1299 return NL_SKIP;
1300 }
1301
1302 if (nla_parse_nested(sinfo, NL80211_SURVEY_INFO_MAX,
1303 tb[NL80211_ATTR_SURVEY_INFO],
1304 survey_policy)) {
1305 wpa_printf(MSG_DEBUG, "nl80211: failed to parse nested "
1306 "attributes!");
1307 return NL_SKIP;
1308 }
1309
1310 if (!sinfo[NL80211_SURVEY_INFO_FREQUENCY])
1311 return NL_SKIP;
1312
1313 if (nla_get_u32(sinfo[NL80211_SURVEY_INFO_FREQUENCY]) !=
1314 sig_change->frequency)
1315 return NL_SKIP;
1316
1317 if (!sinfo[NL80211_SURVEY_INFO_NOISE])
1318 return NL_SKIP;
1319
1320 sig_change->current_noise =
1321 (s8) nla_get_u8(sinfo[NL80211_SURVEY_INFO_NOISE]);
1322
1323 return NL_SKIP;
1324}
1325
1326
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001327int nl80211_get_link_noise(struct wpa_driver_nl80211_data *drv,
1328 struct wpa_signal_info *sig_change)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001329{
1330 struct nl_msg *msg;
1331
1332 sig_change->current_noise = 9999;
1333 sig_change->frequency = drv->assoc_freq;
1334
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001335 msg = nl80211_drv_msg(drv, NLM_F_DUMP, NL80211_CMD_GET_SURVEY);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001336 return send_and_recv_msgs(drv, msg, get_link_noise, sig_change);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001337}
1338
1339
1340static void wpa_driver_nl80211_event_receive(int sock, void *eloop_ctx,
1341 void *handle)
1342{
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001343 struct nl_cb *cb = eloop_ctx;
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -07001344 int res;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001345
Dmitry Shmidt8da800a2013-04-24 12:57:01 -07001346 wpa_printf(MSG_MSGDUMP, "nl80211: Event message available");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001347
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -07001348 res = nl_recvmsgs(handle, cb);
Dmitry Shmidt71757432014-06-02 13:50:35 -07001349 if (res < 0) {
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -07001350 wpa_printf(MSG_INFO, "nl80211: %s->nl_recvmsgs failed: %d",
1351 __func__, res);
1352 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001353}
1354
1355
1356/**
1357 * wpa_driver_nl80211_set_country - ask nl80211 to set the regulatory domain
1358 * @priv: driver_nl80211 private data
1359 * @alpha2_arg: country to which to switch to
1360 * Returns: 0 on success, -1 on failure
1361 *
1362 * This asks nl80211 to set the regulatory domain for given
1363 * country ISO / IEC alpha2.
1364 */
1365static int wpa_driver_nl80211_set_country(void *priv, const char *alpha2_arg)
1366{
1367 struct i802_bss *bss = priv;
1368 struct wpa_driver_nl80211_data *drv = bss->drv;
1369 char alpha2[3];
1370 struct nl_msg *msg;
1371
1372 msg = nlmsg_alloc();
1373 if (!msg)
1374 return -ENOMEM;
1375
1376 alpha2[0] = alpha2_arg[0];
1377 alpha2[1] = alpha2_arg[1];
1378 alpha2[2] = '\0';
1379
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001380 if (!nl80211_cmd(drv, msg, 0, NL80211_CMD_REQ_SET_REG) ||
1381 nla_put_string(msg, NL80211_ATTR_REG_ALPHA2, alpha2)) {
1382 nlmsg_free(msg);
1383 return -EINVAL;
1384 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001385 if (send_and_recv_msgs(drv, msg, NULL, NULL))
1386 return -EINVAL;
1387 return 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001388}
1389
1390
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001391static int nl80211_get_country(struct nl_msg *msg, void *arg)
1392{
1393 char *alpha2 = arg;
1394 struct nlattr *tb_msg[NL80211_ATTR_MAX + 1];
1395 struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg));
1396
1397 nla_parse(tb_msg, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0),
1398 genlmsg_attrlen(gnlh, 0), NULL);
1399 if (!tb_msg[NL80211_ATTR_REG_ALPHA2]) {
1400 wpa_printf(MSG_DEBUG, "nl80211: No country information available");
1401 return NL_SKIP;
1402 }
1403 os_strlcpy(alpha2, nla_data(tb_msg[NL80211_ATTR_REG_ALPHA2]), 3);
1404 return NL_SKIP;
1405}
1406
1407
1408static int wpa_driver_nl80211_get_country(void *priv, char *alpha2)
1409{
1410 struct i802_bss *bss = priv;
1411 struct wpa_driver_nl80211_data *drv = bss->drv;
1412 struct nl_msg *msg;
1413 int ret;
1414
1415 msg = nlmsg_alloc();
1416 if (!msg)
1417 return -ENOMEM;
1418
1419 nl80211_cmd(drv, msg, 0, NL80211_CMD_GET_REG);
1420 alpha2[0] = '\0';
1421 ret = send_and_recv_msgs(drv, msg, nl80211_get_country, alpha2);
1422 if (!alpha2[0])
1423 ret = -1;
1424
1425 return ret;
1426}
1427
1428
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001429static int wpa_driver_nl80211_init_nl_global(struct nl80211_global *global)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001430{
1431 int ret;
1432
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001433 global->nl_cb = nl_cb_alloc(NL_CB_DEFAULT);
1434 if (global->nl_cb == NULL) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001435 wpa_printf(MSG_ERROR, "nl80211: Failed to allocate netlink "
1436 "callbacks");
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001437 return -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001438 }
1439
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001440 global->nl = nl_create_handle(global->nl_cb, "nl");
1441 if (global->nl == NULL)
1442 goto err;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001443
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001444 global->nl80211_id = genl_ctrl_resolve(global->nl, "nl80211");
1445 if (global->nl80211_id < 0) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001446 wpa_printf(MSG_ERROR, "nl80211: 'nl80211' generic netlink not "
1447 "found");
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001448 goto err;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001449 }
1450
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001451 global->nl_event = nl_create_handle(global->nl_cb, "event");
1452 if (global->nl_event == NULL)
1453 goto err;
1454
1455 ret = nl_get_multicast_id(global, "nl80211", "scan");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001456 if (ret >= 0)
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001457 ret = nl_socket_add_membership(global->nl_event, ret);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001458 if (ret < 0) {
1459 wpa_printf(MSG_ERROR, "nl80211: Could not add multicast "
1460 "membership for scan events: %d (%s)",
1461 ret, strerror(-ret));
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001462 goto err;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001463 }
1464
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001465 ret = nl_get_multicast_id(global, "nl80211", "mlme");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001466 if (ret >= 0)
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001467 ret = nl_socket_add_membership(global->nl_event, ret);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001468 if (ret < 0) {
1469 wpa_printf(MSG_ERROR, "nl80211: Could not add multicast "
1470 "membership for mlme events: %d (%s)",
1471 ret, strerror(-ret));
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001472 goto err;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001473 }
1474
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001475 ret = nl_get_multicast_id(global, "nl80211", "regulatory");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001476 if (ret >= 0)
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001477 ret = nl_socket_add_membership(global->nl_event, ret);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001478 if (ret < 0) {
1479 wpa_printf(MSG_DEBUG, "nl80211: Could not add multicast "
1480 "membership for regulatory events: %d (%s)",
1481 ret, strerror(-ret));
1482 /* Continue without regulatory events */
1483 }
1484
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001485 ret = nl_get_multicast_id(global, "nl80211", "vendor");
1486 if (ret >= 0)
1487 ret = nl_socket_add_membership(global->nl_event, ret);
1488 if (ret < 0) {
1489 wpa_printf(MSG_DEBUG, "nl80211: Could not add multicast "
1490 "membership for vendor events: %d (%s)",
1491 ret, strerror(-ret));
1492 /* Continue without vendor events */
1493 }
1494
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001495 nl_cb_set(global->nl_cb, NL_CB_SEQ_CHECK, NL_CB_CUSTOM,
1496 no_seq_check, NULL);
1497 nl_cb_set(global->nl_cb, NL_CB_VALID, NL_CB_CUSTOM,
1498 process_global_event, global);
1499
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -07001500 nl80211_register_eloop_read(&global->nl_event,
1501 wpa_driver_nl80211_event_receive,
1502 global->nl_cb);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001503
1504 return 0;
1505
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001506err:
1507 nl_destroy_handles(&global->nl_event);
1508 nl_destroy_handles(&global->nl);
1509 nl_cb_put(global->nl_cb);
1510 global->nl_cb = NULL;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001511 return -1;
1512}
1513
1514
Dmitry Shmidt7f656022015-02-25 14:36:37 -08001515static void nl80211_check_global(struct nl80211_global *global)
1516{
1517 struct nl_handle *handle;
1518 const char *groups[] = { "scan", "mlme", "regulatory", "vendor", NULL };
1519 int ret;
1520 unsigned int i;
1521
1522 /*
1523 * Try to re-add memberships to handle case of cfg80211 getting reloaded
1524 * and all registration having been cleared.
1525 */
1526 handle = (void *) (((intptr_t) global->nl_event) ^
1527 ELOOP_SOCKET_INVALID);
1528
1529 for (i = 0; groups[i]; i++) {
1530 ret = nl_get_multicast_id(global, "nl80211", groups[i]);
1531 if (ret >= 0)
1532 ret = nl_socket_add_membership(handle, ret);
1533 if (ret < 0) {
1534 wpa_printf(MSG_INFO,
1535 "nl80211: Could not re-add multicast membership for %s events: %d (%s)",
1536 groups[i], ret, strerror(-ret));
1537 }
1538 }
1539}
1540
1541
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001542static void wpa_driver_nl80211_rfkill_blocked(void *ctx)
1543{
Dmitry Shmidt7d56b752015-12-22 10:59:44 -08001544 struct wpa_driver_nl80211_data *drv = ctx;
1545
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001546 wpa_printf(MSG_DEBUG, "nl80211: RFKILL blocked");
Dmitry Shmidt7d56b752015-12-22 10:59:44 -08001547
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001548 /*
Dmitry Shmidt7d56b752015-12-22 10:59:44 -08001549 * rtnetlink ifdown handler will report interfaces other than the P2P
1550 * Device interface as disabled.
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001551 */
Dmitry Shmidt7d56b752015-12-22 10:59:44 -08001552 if (drv->nlmode == NL80211_IFTYPE_P2P_DEVICE)
1553 wpa_supplicant_event(drv->ctx, EVENT_INTERFACE_DISABLED, NULL);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001554}
1555
1556
1557static void wpa_driver_nl80211_rfkill_unblocked(void *ctx)
1558{
1559 struct wpa_driver_nl80211_data *drv = ctx;
1560 wpa_printf(MSG_DEBUG, "nl80211: RFKILL unblocked");
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001561 if (i802_set_iface_flags(drv->first_bss, 1)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001562 wpa_printf(MSG_DEBUG, "nl80211: Could not set interface UP "
1563 "after rfkill unblock");
1564 return;
1565 }
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001566
1567 if (is_p2p_net_interface(drv->nlmode))
1568 nl80211_disable_11b_rates(drv, drv->ifindex, 1);
1569
Dmitry Shmidt7d56b752015-12-22 10:59:44 -08001570 /*
1571 * rtnetlink ifup handler will report interfaces other than the P2P
1572 * Device interface as enabled.
1573 */
1574 if (drv->nlmode == NL80211_IFTYPE_P2P_DEVICE)
1575 wpa_supplicant_event(drv->ctx, EVENT_INTERFACE_ENABLED, NULL);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001576}
1577
1578
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001579static void wpa_driver_nl80211_handle_eapol_tx_status(int sock,
1580 void *eloop_ctx,
1581 void *handle)
1582{
1583 struct wpa_driver_nl80211_data *drv = eloop_ctx;
1584 u8 data[2048];
1585 struct msghdr msg;
1586 struct iovec entry;
Dmitry Shmidt04949592012-07-19 12:16:46 -07001587 u8 control[512];
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001588 struct cmsghdr *cmsg;
1589 int res, found_ee = 0, found_wifi = 0, acked = 0;
1590 union wpa_event_data event;
1591
1592 memset(&msg, 0, sizeof(msg));
1593 msg.msg_iov = &entry;
1594 msg.msg_iovlen = 1;
1595 entry.iov_base = data;
1596 entry.iov_len = sizeof(data);
1597 msg.msg_control = &control;
1598 msg.msg_controllen = sizeof(control);
1599
1600 res = recvmsg(sock, &msg, MSG_ERRQUEUE);
1601 /* if error or not fitting 802.3 header, return */
1602 if (res < 14)
1603 return;
1604
1605 for (cmsg = CMSG_FIRSTHDR(&msg); cmsg; cmsg = CMSG_NXTHDR(&msg, cmsg))
1606 {
1607 if (cmsg->cmsg_level == SOL_SOCKET &&
1608 cmsg->cmsg_type == SCM_WIFI_STATUS) {
1609 int *ack;
1610
1611 found_wifi = 1;
1612 ack = (void *)CMSG_DATA(cmsg);
1613 acked = *ack;
1614 }
1615
1616 if (cmsg->cmsg_level == SOL_PACKET &&
1617 cmsg->cmsg_type == PACKET_TX_TIMESTAMP) {
1618 struct sock_extended_err *err =
1619 (struct sock_extended_err *)CMSG_DATA(cmsg);
1620
1621 if (err->ee_origin == SO_EE_ORIGIN_TXSTATUS)
1622 found_ee = 1;
1623 }
1624 }
1625
1626 if (!found_ee || !found_wifi)
1627 return;
1628
1629 memset(&event, 0, sizeof(event));
1630 event.eapol_tx_status.dst = data;
1631 event.eapol_tx_status.data = data + 14;
1632 event.eapol_tx_status.data_len = res - 14;
1633 event.eapol_tx_status.ack = acked;
1634 wpa_supplicant_event(drv->ctx, EVENT_EAPOL_TX_STATUS, &event);
1635}
1636
1637
1638static int nl80211_init_bss(struct i802_bss *bss)
1639{
1640 bss->nl_cb = nl_cb_alloc(NL_CB_DEFAULT);
1641 if (!bss->nl_cb)
1642 return -1;
1643
1644 nl_cb_set(bss->nl_cb, NL_CB_SEQ_CHECK, NL_CB_CUSTOM,
1645 no_seq_check, NULL);
1646 nl_cb_set(bss->nl_cb, NL_CB_VALID, NL_CB_CUSTOM,
1647 process_bss_event, bss);
1648
1649 return 0;
1650}
1651
1652
1653static void nl80211_destroy_bss(struct i802_bss *bss)
1654{
1655 nl_cb_put(bss->nl_cb);
1656 bss->nl_cb = NULL;
1657}
1658
1659
Dmitry Shmidt7d56b752015-12-22 10:59:44 -08001660static void
1661wpa_driver_nl80211_drv_init_rfkill(struct wpa_driver_nl80211_data *drv)
1662{
1663 struct rfkill_config *rcfg;
1664
1665 if (drv->rfkill)
1666 return;
1667
1668 rcfg = os_zalloc(sizeof(*rcfg));
1669 if (!rcfg)
1670 return;
1671
1672 rcfg->ctx = drv;
1673
1674 /* rfkill uses netdev sysfs for initialization. However, P2P Device is
1675 * not associated with a netdev, so use the name of some other interface
1676 * sharing the same wiphy as the P2P Device interface.
1677 *
1678 * Note: This is valid, as a P2P Device interface is always dynamically
1679 * created and is created only once another wpa_s interface was added.
1680 */
1681 if (drv->nlmode == NL80211_IFTYPE_P2P_DEVICE) {
1682 struct nl80211_global *global = drv->global;
1683 struct wpa_driver_nl80211_data *tmp1;
1684
1685 dl_list_for_each(tmp1, &global->interfaces,
1686 struct wpa_driver_nl80211_data, list) {
1687 if (drv == tmp1 || drv->wiphy_idx != tmp1->wiphy_idx ||
1688 !tmp1->rfkill)
1689 continue;
1690
1691 wpa_printf(MSG_DEBUG,
1692 "nl80211: Use (%s) to initialize P2P Device rfkill",
1693 tmp1->first_bss->ifname);
1694 os_strlcpy(rcfg->ifname, tmp1->first_bss->ifname,
1695 sizeof(rcfg->ifname));
1696 break;
1697 }
1698 } else {
1699 os_strlcpy(rcfg->ifname, drv->first_bss->ifname,
1700 sizeof(rcfg->ifname));
1701 }
1702
1703 rcfg->blocked_cb = wpa_driver_nl80211_rfkill_blocked;
1704 rcfg->unblocked_cb = wpa_driver_nl80211_rfkill_unblocked;
1705 drv->rfkill = rfkill_init(rcfg);
1706 if (!drv->rfkill) {
1707 wpa_printf(MSG_DEBUG, "nl80211: RFKILL status not available");
1708 os_free(rcfg);
1709 }
1710}
1711
1712
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08001713static void * wpa_driver_nl80211_drv_init(void *ctx, const char *ifname,
1714 void *global_priv, int hostapd,
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001715 const u8 *set_addr,
1716 const char *driver_params)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001717{
1718 struct wpa_driver_nl80211_data *drv;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001719 struct i802_bss *bss;
1720
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001721 if (global_priv == NULL)
1722 return NULL;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001723 drv = os_zalloc(sizeof(*drv));
1724 if (drv == NULL)
1725 return NULL;
1726 drv->global = global_priv;
1727 drv->ctx = ctx;
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08001728 drv->hostapd = !!hostapd;
1729 drv->eapol_sock = -1;
Dmitry Shmidtff787d52015-01-12 13:01:47 -08001730
1731 /*
1732 * There is no driver capability flag for this, so assume it is
1733 * supported and disable this on first attempt to use if the driver
1734 * rejects the command due to missing support.
1735 */
1736 drv->set_rekey_offload = 1;
1737
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08001738 drv->num_if_indices = sizeof(drv->default_if_indices) / sizeof(int);
1739 drv->if_indices = drv->default_if_indices;
Dmitry Shmidt9c175262016-03-03 10:20:07 -08001740 drv->if_indices_reason = drv->default_if_indices_reason;
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001741
1742 drv->first_bss = os_zalloc(sizeof(*drv->first_bss));
1743 if (!drv->first_bss) {
1744 os_free(drv);
1745 return NULL;
1746 }
1747 bss = drv->first_bss;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001748 bss->drv = drv;
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08001749 bss->ctx = ctx;
1750
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001751 os_strlcpy(bss->ifname, ifname, sizeof(bss->ifname));
1752 drv->monitor_ifidx = -1;
1753 drv->monitor_sock = -1;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001754 drv->eapol_tx_sock = -1;
1755 drv->ap_scan_as_station = NL80211_IFTYPE_UNSPECIFIED;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001756
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001757 if (nl80211_init_bss(bss))
1758 goto failed;
1759
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001760 if (wpa_driver_nl80211_finish_drv_init(drv, set_addr, 1, driver_params))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001761 goto failed;
1762
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001763 drv->eapol_tx_sock = socket(PF_PACKET, SOCK_DGRAM, 0);
1764 if (drv->eapol_tx_sock < 0)
1765 goto failed;
1766
1767 if (drv->data_tx_status) {
1768 int enabled = 1;
1769
1770 if (setsockopt(drv->eapol_tx_sock, SOL_SOCKET, SO_WIFI_STATUS,
1771 &enabled, sizeof(enabled)) < 0) {
1772 wpa_printf(MSG_DEBUG,
1773 "nl80211: wifi status sockopt failed\n");
1774 drv->data_tx_status = 0;
1775 if (!drv->use_monitor)
1776 drv->capa.flags &=
1777 ~WPA_DRIVER_FLAGS_EAPOL_TX_STATUS;
1778 } else {
1779 eloop_register_read_sock(drv->eapol_tx_sock,
1780 wpa_driver_nl80211_handle_eapol_tx_status,
1781 drv, NULL);
1782 }
1783 }
1784
1785 if (drv->global) {
Dmitry Shmidt7f656022015-02-25 14:36:37 -08001786 nl80211_check_global(drv->global);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001787 dl_list_add(&drv->global->interfaces, &drv->list);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001788 drv->in_interface_list = 1;
1789 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001790
1791 return bss;
1792
1793failed:
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001794 wpa_driver_nl80211_deinit(bss);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001795 return NULL;
1796}
1797
1798
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08001799/**
1800 * wpa_driver_nl80211_init - Initialize nl80211 driver interface
1801 * @ctx: context to be used when calling wpa_supplicant functions,
1802 * e.g., wpa_supplicant_event()
1803 * @ifname: interface name, e.g., wlan0
1804 * @global_priv: private driver global data from global_init()
1805 * Returns: Pointer to private data, %NULL on failure
1806 */
1807static void * wpa_driver_nl80211_init(void *ctx, const char *ifname,
1808 void *global_priv)
1809{
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001810 return wpa_driver_nl80211_drv_init(ctx, ifname, global_priv, 0, NULL,
1811 NULL);
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08001812}
1813
1814
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001815static int nl80211_register_frame(struct i802_bss *bss,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001816 struct nl_handle *nl_handle,
1817 u16 type, const u8 *match, size_t match_len)
1818{
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001819 struct wpa_driver_nl80211_data *drv = bss->drv;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001820 struct nl_msg *msg;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001821 int ret;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001822 char buf[30];
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001823
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001824 buf[0] = '\0';
1825 wpa_snprintf_hex(buf, sizeof(buf), match, match_len);
Dmitry Shmidt2271d3f2014-06-23 12:16:31 -07001826 wpa_printf(MSG_DEBUG, "nl80211: Register frame type=0x%x (%s) nl_handle=%p match=%s",
1827 type, fc2str(type), nl_handle, buf);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001828
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001829 if (!(msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_REGISTER_ACTION)) ||
1830 nla_put_u16(msg, NL80211_ATTR_FRAME_TYPE, type) ||
1831 nla_put(msg, NL80211_ATTR_FRAME_MATCH, match_len, match)) {
1832 nlmsg_free(msg);
1833 return -1;
1834 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001835
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001836 ret = send_and_recv(drv->global, nl_handle, msg, NULL, NULL);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001837 if (ret) {
1838 wpa_printf(MSG_DEBUG, "nl80211: Register frame command "
1839 "failed (type=%u): ret=%d (%s)",
1840 type, ret, strerror(-ret));
1841 wpa_hexdump(MSG_DEBUG, "nl80211: Register frame match",
1842 match, match_len);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001843 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001844 return ret;
1845}
1846
1847
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001848static int nl80211_alloc_mgmt_handle(struct i802_bss *bss)
1849{
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001850 if (bss->nl_mgmt) {
1851 wpa_printf(MSG_DEBUG, "nl80211: Mgmt reporting "
1852 "already on! (nl_mgmt=%p)", bss->nl_mgmt);
1853 return -1;
1854 }
1855
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001856 bss->nl_mgmt = nl_create_handle(bss->nl_cb, "mgmt");
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001857 if (bss->nl_mgmt == NULL)
1858 return -1;
1859
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001860 return 0;
1861}
1862
1863
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -07001864static void nl80211_mgmt_handle_register_eloop(struct i802_bss *bss)
1865{
1866 nl80211_register_eloop_read(&bss->nl_mgmt,
1867 wpa_driver_nl80211_event_receive,
1868 bss->nl_cb);
1869}
1870
1871
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001872static int nl80211_register_action_frame(struct i802_bss *bss,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001873 const u8 *match, size_t match_len)
1874{
1875 u16 type = (WLAN_FC_TYPE_MGMT << 2) | (WLAN_FC_STYPE_ACTION << 4);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001876 return nl80211_register_frame(bss, bss->nl_mgmt,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001877 type, match, match_len);
1878}
1879
1880
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001881static int nl80211_mgmt_subscribe_non_ap(struct i802_bss *bss)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001882{
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001883 struct wpa_driver_nl80211_data *drv = bss->drv;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001884 int ret = 0;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001885
1886 if (nl80211_alloc_mgmt_handle(bss))
1887 return -1;
1888 wpa_printf(MSG_DEBUG, "nl80211: Subscribe to mgmt frames with non-AP "
1889 "handle %p", bss->nl_mgmt);
1890
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -07001891 if (drv->nlmode == NL80211_IFTYPE_ADHOC) {
1892 u16 type = (WLAN_FC_TYPE_MGMT << 2) | (WLAN_FC_STYPE_AUTH << 4);
1893
1894 /* register for any AUTH message */
1895 nl80211_register_frame(bss, bss->nl_mgmt, type, NULL, 0);
1896 }
1897
Dmitry Shmidt051af732013-10-22 13:52:46 -07001898#ifdef CONFIG_INTERWORKING
1899 /* QoS Map Configure */
1900 if (nl80211_register_action_frame(bss, (u8 *) "\x01\x04", 2) < 0)
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001901 ret = -1;
Dmitry Shmidt051af732013-10-22 13:52:46 -07001902#endif /* CONFIG_INTERWORKING */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001903#if defined(CONFIG_P2P) || defined(CONFIG_INTERWORKING)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001904 /* GAS Initial Request */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001905 if (nl80211_register_action_frame(bss, (u8 *) "\x04\x0a", 2) < 0)
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001906 ret = -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001907 /* GAS Initial Response */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001908 if (nl80211_register_action_frame(bss, (u8 *) "\x04\x0b", 2) < 0)
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001909 ret = -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001910 /* GAS Comeback Request */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001911 if (nl80211_register_action_frame(bss, (u8 *) "\x04\x0c", 2) < 0)
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001912 ret = -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001913 /* GAS Comeback Response */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001914 if (nl80211_register_action_frame(bss, (u8 *) "\x04\x0d", 2) < 0)
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001915 ret = -1;
Dmitry Shmidt18463232014-01-24 12:29:41 -08001916 /* Protected GAS Initial Request */
1917 if (nl80211_register_action_frame(bss, (u8 *) "\x09\x0a", 2) < 0)
1918 ret = -1;
1919 /* Protected GAS Initial Response */
1920 if (nl80211_register_action_frame(bss, (u8 *) "\x09\x0b", 2) < 0)
1921 ret = -1;
1922 /* Protected GAS Comeback Request */
1923 if (nl80211_register_action_frame(bss, (u8 *) "\x09\x0c", 2) < 0)
1924 ret = -1;
1925 /* Protected GAS Comeback Response */
1926 if (nl80211_register_action_frame(bss, (u8 *) "\x09\x0d", 2) < 0)
1927 ret = -1;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001928#endif /* CONFIG_P2P || CONFIG_INTERWORKING */
1929#ifdef CONFIG_P2P
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001930 /* P2P Public Action */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001931 if (nl80211_register_action_frame(bss,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001932 (u8 *) "\x04\x09\x50\x6f\x9a\x09",
1933 6) < 0)
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001934 ret = -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001935 /* P2P Action */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001936 if (nl80211_register_action_frame(bss,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001937 (u8 *) "\x7f\x50\x6f\x9a\x09",
1938 5) < 0)
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001939 ret = -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001940#endif /* CONFIG_P2P */
1941#ifdef CONFIG_IEEE80211W
1942 /* SA Query Response */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001943 if (nl80211_register_action_frame(bss, (u8 *) "\x08\x01", 2) < 0)
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001944 ret = -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001945#endif /* CONFIG_IEEE80211W */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001946#ifdef CONFIG_TDLS
1947 if ((drv->capa.flags & WPA_DRIVER_FLAGS_TDLS_SUPPORT)) {
1948 /* TDLS Discovery Response */
1949 if (nl80211_register_action_frame(bss, (u8 *) "\x04\x0e", 2) <
1950 0)
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001951 ret = -1;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001952 }
1953#endif /* CONFIG_TDLS */
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001954#ifdef CONFIG_FST
1955 /* FST Action frames */
1956 if (nl80211_register_action_frame(bss, (u8 *) "\x12", 1) < 0)
1957 ret = -1;
1958#endif /* CONFIG_FST */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001959
1960 /* FT Action frames */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001961 if (nl80211_register_action_frame(bss, (u8 *) "\x06", 1) < 0)
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001962 ret = -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001963 else
1964 drv->capa.key_mgmt |= WPA_DRIVER_CAPA_KEY_MGMT_FT |
1965 WPA_DRIVER_CAPA_KEY_MGMT_FT_PSK;
1966
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001967 /* WNM - BSS Transition Management Request */
1968 if (nl80211_register_action_frame(bss, (u8 *) "\x0a\x07", 2) < 0)
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001969 ret = -1;
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08001970 /* WNM-Sleep Mode Response */
1971 if (nl80211_register_action_frame(bss, (u8 *) "\x0a\x11", 2) < 0)
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001972 ret = -1;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001973
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08001974#ifdef CONFIG_HS20
1975 /* WNM-Notification */
1976 if (nl80211_register_action_frame(bss, (u8 *) "\x0a\x1a", 2) < 0)
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07001977 ret = -1;
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08001978#endif /* CONFIG_HS20 */
1979
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001980 /* WMM-AC ADDTS Response */
1981 if (nl80211_register_action_frame(bss, (u8 *) "\x11\x01", 2) < 0)
1982 ret = -1;
1983
1984 /* WMM-AC DELTS */
1985 if (nl80211_register_action_frame(bss, (u8 *) "\x11\x02", 2) < 0)
1986 ret = -1;
1987
1988 /* Radio Measurement - Neighbor Report Response */
1989 if (nl80211_register_action_frame(bss, (u8 *) "\x05\x05", 2) < 0)
1990 ret = -1;
1991
1992 /* Radio Measurement - Link Measurement Request */
1993 if ((drv->capa.rrm_flags & WPA_DRIVER_FLAGS_TX_POWER_INSERTION) &&
1994 (nl80211_register_action_frame(bss, (u8 *) "\x05\x02", 2) < 0))
1995 ret = -1;
1996
1997 nl80211_mgmt_handle_register_eloop(bss);
1998
1999 return ret;
2000}
2001
2002
2003static int nl80211_mgmt_subscribe_mesh(struct i802_bss *bss)
2004{
2005 int ret = 0;
2006
2007 if (nl80211_alloc_mgmt_handle(bss))
2008 return -1;
2009
2010 wpa_printf(MSG_DEBUG,
2011 "nl80211: Subscribe to mgmt frames with mesh handle %p",
2012 bss->nl_mgmt);
2013
2014 /* Auth frames for mesh SAE */
2015 if (nl80211_register_frame(bss, bss->nl_mgmt,
2016 (WLAN_FC_TYPE_MGMT << 2) |
2017 (WLAN_FC_STYPE_AUTH << 4),
2018 NULL, 0) < 0)
2019 ret = -1;
2020
2021 /* Mesh peering open */
2022 if (nl80211_register_action_frame(bss, (u8 *) "\x0f\x01", 2) < 0)
2023 ret = -1;
2024 /* Mesh peering confirm */
2025 if (nl80211_register_action_frame(bss, (u8 *) "\x0f\x02", 2) < 0)
2026 ret = -1;
2027 /* Mesh peering close */
2028 if (nl80211_register_action_frame(bss, (u8 *) "\x0f\x03", 2) < 0)
2029 ret = -1;
2030
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -07002031 nl80211_mgmt_handle_register_eloop(bss);
2032
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002033 return ret;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002034}
2035
2036
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002037static int nl80211_register_spurious_class3(struct i802_bss *bss)
2038{
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002039 struct nl_msg *msg;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002040 int ret;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002041
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002042 msg = nl80211_bss_msg(bss, 0, NL80211_CMD_UNEXPECTED_FRAME);
2043 ret = send_and_recv(bss->drv->global, bss->nl_mgmt, msg, NULL, NULL);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002044 if (ret) {
2045 wpa_printf(MSG_DEBUG, "nl80211: Register spurious class3 "
2046 "failed: ret=%d (%s)",
2047 ret, strerror(-ret));
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002048 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002049 return ret;
2050}
2051
2052
2053static int nl80211_mgmt_subscribe_ap(struct i802_bss *bss)
2054{
2055 static const int stypes[] = {
2056 WLAN_FC_STYPE_AUTH,
2057 WLAN_FC_STYPE_ASSOC_REQ,
2058 WLAN_FC_STYPE_REASSOC_REQ,
2059 WLAN_FC_STYPE_DISASSOC,
2060 WLAN_FC_STYPE_DEAUTH,
2061 WLAN_FC_STYPE_ACTION,
2062 WLAN_FC_STYPE_PROBE_REQ,
2063/* Beacon doesn't work as mac80211 doesn't currently allow
2064 * it, but it wouldn't really be the right thing anyway as
2065 * it isn't per interface ... maybe just dump the scan
2066 * results periodically for OLBC?
2067 */
Dmitry Shmidt7832adb2014-04-29 10:53:02 -07002068 /* WLAN_FC_STYPE_BEACON, */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002069 };
2070 unsigned int i;
2071
2072 if (nl80211_alloc_mgmt_handle(bss))
2073 return -1;
2074 wpa_printf(MSG_DEBUG, "nl80211: Subscribe to mgmt frames with AP "
2075 "handle %p", bss->nl_mgmt);
2076
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -07002077 for (i = 0; i < ARRAY_SIZE(stypes); i++) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002078 if (nl80211_register_frame(bss, bss->nl_mgmt,
2079 (WLAN_FC_TYPE_MGMT << 2) |
2080 (stypes[i] << 4),
2081 NULL, 0) < 0) {
2082 goto out_err;
2083 }
2084 }
2085
2086 if (nl80211_register_spurious_class3(bss))
2087 goto out_err;
2088
2089 if (nl80211_get_wiphy_data_ap(bss) == NULL)
2090 goto out_err;
2091
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -07002092 nl80211_mgmt_handle_register_eloop(bss);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002093 return 0;
2094
2095out_err:
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002096 nl_destroy_handles(&bss->nl_mgmt);
2097 return -1;
2098}
2099
2100
2101static int nl80211_mgmt_subscribe_ap_dev_sme(struct i802_bss *bss)
2102{
2103 if (nl80211_alloc_mgmt_handle(bss))
2104 return -1;
2105 wpa_printf(MSG_DEBUG, "nl80211: Subscribe to mgmt frames with AP "
2106 "handle %p (device SME)", bss->nl_mgmt);
2107
2108 if (nl80211_register_frame(bss, bss->nl_mgmt,
2109 (WLAN_FC_TYPE_MGMT << 2) |
2110 (WLAN_FC_STYPE_ACTION << 4),
2111 NULL, 0) < 0)
2112 goto out_err;
2113
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -07002114 nl80211_mgmt_handle_register_eloop(bss);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002115 return 0;
2116
2117out_err:
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002118 nl_destroy_handles(&bss->nl_mgmt);
2119 return -1;
2120}
2121
2122
2123static void nl80211_mgmt_unsubscribe(struct i802_bss *bss, const char *reason)
2124{
2125 if (bss->nl_mgmt == NULL)
2126 return;
2127 wpa_printf(MSG_DEBUG, "nl80211: Unsubscribe mgmt frames handle %p "
2128 "(%s)", bss->nl_mgmt, reason);
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -07002129 nl80211_destroy_eloop_handle(&bss->nl_mgmt);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002130
2131 nl80211_put_wiphy_data_ap(bss);
2132}
2133
2134
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002135static void wpa_driver_nl80211_send_rfkill(void *eloop_ctx, void *timeout_ctx)
2136{
2137 wpa_supplicant_event(timeout_ctx, EVENT_INTERFACE_DISABLED, NULL);
2138}
2139
2140
Dmitry Shmidt34af3062013-07-11 10:46:32 -07002141static void nl80211_del_p2pdev(struct i802_bss *bss)
2142{
Dmitry Shmidt34af3062013-07-11 10:46:32 -07002143 struct nl_msg *msg;
2144 int ret;
2145
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002146 msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_DEL_INTERFACE);
2147 ret = send_and_recv_msgs(bss->drv, msg, NULL, NULL);
Dmitry Shmidt34af3062013-07-11 10:46:32 -07002148
2149 wpa_printf(MSG_DEBUG, "nl80211: Delete P2P Device %s (0x%llx): %s",
2150 bss->ifname, (long long unsigned int) bss->wdev_id,
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -07002151 strerror(-ret));
Dmitry Shmidt34af3062013-07-11 10:46:32 -07002152}
2153
2154
2155static int nl80211_set_p2pdev(struct i802_bss *bss, int start)
2156{
Dmitry Shmidt34af3062013-07-11 10:46:32 -07002157 struct nl_msg *msg;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002158 int ret;
Dmitry Shmidt34af3062013-07-11 10:46:32 -07002159
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002160 msg = nl80211_cmd_msg(bss, 0, start ? NL80211_CMD_START_P2P_DEVICE :
2161 NL80211_CMD_STOP_P2P_DEVICE);
2162 ret = send_and_recv_msgs(bss->drv, msg, NULL, NULL);
Dmitry Shmidt34af3062013-07-11 10:46:32 -07002163
2164 wpa_printf(MSG_DEBUG, "nl80211: %s P2P Device %s (0x%llx): %s",
2165 start ? "Start" : "Stop",
2166 bss->ifname, (long long unsigned int) bss->wdev_id,
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -07002167 strerror(-ret));
Dmitry Shmidt34af3062013-07-11 10:46:32 -07002168 return ret;
2169}
2170
2171
2172static int i802_set_iface_flags(struct i802_bss *bss, int up)
2173{
2174 enum nl80211_iftype nlmode;
2175
2176 nlmode = nl80211_get_ifmode(bss);
2177 if (nlmode != NL80211_IFTYPE_P2P_DEVICE) {
2178 return linux_set_iface_flags(bss->drv->global->ioctl_sock,
2179 bss->ifname, up);
2180 }
2181
2182 /* P2P Device has start/stop which is equivalent */
2183 return nl80211_set_p2pdev(bss, up);
2184}
2185
2186
Dmitry Shmidt7f656022015-02-25 14:36:37 -08002187#ifdef CONFIG_TESTING_OPTIONS
2188static int qca_vendor_test_cmd_handler(struct nl_msg *msg, void *arg)
2189{
2190 /* struct wpa_driver_nl80211_data *drv = arg; */
2191 struct nlattr *tb[NL80211_ATTR_MAX + 1];
2192 struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg));
2193
2194
2195 wpa_printf(MSG_DEBUG,
2196 "nl80211: QCA vendor test command response received");
2197
2198 nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0),
2199 genlmsg_attrlen(gnlh, 0), NULL);
2200 if (!tb[NL80211_ATTR_VENDOR_DATA]) {
2201 wpa_printf(MSG_DEBUG, "nl80211: No vendor data attribute");
2202 return NL_SKIP;
2203 }
2204
2205 wpa_hexdump(MSG_DEBUG,
2206 "nl80211: Received QCA vendor test command response",
2207 nla_data(tb[NL80211_ATTR_VENDOR_DATA]),
2208 nla_len(tb[NL80211_ATTR_VENDOR_DATA]));
2209
2210 return NL_SKIP;
2211}
2212#endif /* CONFIG_TESTING_OPTIONS */
2213
2214
2215static void qca_vendor_test(struct wpa_driver_nl80211_data *drv)
2216{
2217#ifdef CONFIG_TESTING_OPTIONS
2218 struct nl_msg *msg;
2219 struct nlattr *params;
2220 int ret;
2221
2222 if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_VENDOR)) ||
2223 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
2224 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
2225 QCA_NL80211_VENDOR_SUBCMD_TEST) ||
2226 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
2227 nla_put_u32(msg, QCA_WLAN_VENDOR_ATTR_TEST, 123)) {
2228 nlmsg_free(msg);
2229 return;
2230 }
2231 nla_nest_end(msg, params);
2232
2233 ret = send_and_recv_msgs(drv, msg, qca_vendor_test_cmd_handler, drv);
2234 wpa_printf(MSG_DEBUG,
2235 "nl80211: QCA vendor test command returned %d (%s)",
2236 ret, strerror(-ret));
2237#endif /* CONFIG_TESTING_OPTIONS */
2238}
2239
2240
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002241static int
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08002242wpa_driver_nl80211_finish_drv_init(struct wpa_driver_nl80211_data *drv,
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002243 const u8 *set_addr, int first,
2244 const char *driver_params)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002245{
Dmitry Shmidtcce06662013-11-04 18:44:24 -08002246 struct i802_bss *bss = drv->first_bss;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002247 int send_rfkill_event = 0;
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08002248 enum nl80211_iftype nlmode;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002249
2250 drv->ifindex = if_nametoindex(bss->ifname);
Dmitry Shmidt34af3062013-07-11 10:46:32 -07002251 bss->ifindex = drv->ifindex;
2252 bss->wdev_id = drv->global->if_add_wdevid;
2253 bss->wdev_id_set = drv->global->if_add_wdevid_set;
2254
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -07002255 bss->if_dynamic = drv->ifindex == drv->global->if_add_ifindex;
2256 bss->if_dynamic = bss->if_dynamic || drv->global->if_add_wdevid_set;
Dmitry Shmidt34af3062013-07-11 10:46:32 -07002257 drv->global->if_add_wdevid_set = 0;
2258
Dmitry Shmidt03658832014-08-13 11:03:49 -07002259 if (!bss->if_dynamic && nl80211_get_ifmode(bss) == NL80211_IFTYPE_AP)
2260 bss->static_ap = 1;
2261
Dmitry Shmidt014a3ff2015-12-28 13:27:49 -08002262 if (first &&
2263 nl80211_get_ifmode(bss) != NL80211_IFTYPE_P2P_DEVICE &&
2264 linux_iface_up(drv->global->ioctl_sock, bss->ifname) > 0)
2265 drv->start_iface_up = 1;
2266
Dmitry Shmidt34af3062013-07-11 10:46:32 -07002267 if (wpa_driver_nl80211_capa(drv))
2268 return -1;
2269
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002270 if (driver_params && nl80211_set_param(bss, driver_params) < 0)
2271 return -1;
2272
Dmitry Shmidt34af3062013-07-11 10:46:32 -07002273 wpa_printf(MSG_DEBUG, "nl80211: interface %s in phy %s",
2274 bss->ifname, drv->phyname);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002275
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08002276 if (set_addr &&
2277 (linux_set_iface_flags(drv->global->ioctl_sock, bss->ifname, 0) ||
2278 linux_set_ifhwaddr(drv->global->ioctl_sock, bss->ifname,
2279 set_addr)))
2280 return -1;
Dmitry Shmidt34af3062013-07-11 10:46:32 -07002281
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08002282 if (first && nl80211_get_ifmode(bss) == NL80211_IFTYPE_AP)
2283 drv->start_mode_ap = 1;
2284
Dmitry Shmidt03658832014-08-13 11:03:49 -07002285 if (drv->hostapd || bss->static_ap)
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08002286 nlmode = NL80211_IFTYPE_AP;
2287 else if (bss->if_dynamic)
2288 nlmode = nl80211_get_ifmode(bss);
2289 else
2290 nlmode = NL80211_IFTYPE_STATION;
2291
Dmitry Shmidt34af3062013-07-11 10:46:32 -07002292 if (wpa_driver_nl80211_set_mode(bss, nlmode) < 0) {
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08002293 wpa_printf(MSG_ERROR, "nl80211: Could not configure driver mode");
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002294 return -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002295 }
Dmitry Shmidt34af3062013-07-11 10:46:32 -07002296
Dmitry Shmidt98660862014-03-11 17:26:21 -07002297 if (nlmode == NL80211_IFTYPE_P2P_DEVICE)
Dmitry Shmidt34af3062013-07-11 10:46:32 -07002298 nl80211_get_macaddr(bss);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002299
Dmitry Shmidt7d56b752015-12-22 10:59:44 -08002300 wpa_driver_nl80211_drv_init_rfkill(drv);
2301
Dmitry Shmidt98660862014-03-11 17:26:21 -07002302 if (!rfkill_is_blocked(drv->rfkill)) {
2303 int ret = i802_set_iface_flags(bss, 1);
2304 if (ret) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002305 wpa_printf(MSG_ERROR, "nl80211: Could not set "
2306 "interface '%s' UP", bss->ifname);
Dmitry Shmidt98660862014-03-11 17:26:21 -07002307 return ret;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002308 }
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08002309
2310 if (is_p2p_net_interface(nlmode))
2311 nl80211_disable_11b_rates(bss->drv,
2312 bss->drv->ifindex, 1);
2313
Dmitry Shmidt98660862014-03-11 17:26:21 -07002314 if (nlmode == NL80211_IFTYPE_P2P_DEVICE)
2315 return ret;
2316 } else {
2317 wpa_printf(MSG_DEBUG, "nl80211: Could not yet enable "
2318 "interface '%s' due to rfkill", bss->ifname);
Dmitry Shmidt7d56b752015-12-22 10:59:44 -08002319 if (nlmode != NL80211_IFTYPE_P2P_DEVICE)
2320 drv->if_disabled = 1;
2321
Dmitry Shmidt98660862014-03-11 17:26:21 -07002322 send_rfkill_event = 1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002323 }
2324
Dmitry Shmidt7d56b752015-12-22 10:59:44 -08002325 if (!drv->hostapd && nlmode != NL80211_IFTYPE_P2P_DEVICE)
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08002326 netlink_send_oper_ifla(drv->global->netlink, drv->ifindex,
2327 1, IF_OPER_DORMANT);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002328
Dmitry Shmidt7d56b752015-12-22 10:59:44 -08002329 if (nlmode != NL80211_IFTYPE_P2P_DEVICE) {
2330 if (linux_get_ifhwaddr(drv->global->ioctl_sock, bss->ifname,
2331 bss->addr))
2332 return -1;
2333 os_memcpy(drv->perm_addr, bss->addr, ETH_ALEN);
2334 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002335
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002336 if (send_rfkill_event) {
2337 eloop_register_timeout(0, 0, wpa_driver_nl80211_send_rfkill,
2338 drv, drv->ctx);
2339 }
2340
Dmitry Shmidt7f656022015-02-25 14:36:37 -08002341 if (drv->vendor_cmd_test_avail)
2342 qca_vendor_test(drv);
2343
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002344 return 0;
2345}
2346
2347
2348static int wpa_driver_nl80211_del_beacon(struct wpa_driver_nl80211_data *drv)
2349{
2350 struct nl_msg *msg;
2351
Dmitry Shmidtcce06662013-11-04 18:44:24 -08002352 wpa_printf(MSG_DEBUG, "nl80211: Remove beacon (ifindex=%d)",
2353 drv->ifindex);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002354 msg = nl80211_drv_msg(drv, 0, NL80211_CMD_DEL_BEACON);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002355 return send_and_recv_msgs(drv, msg, NULL, NULL);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002356}
2357
2358
2359/**
2360 * wpa_driver_nl80211_deinit - Deinitialize nl80211 driver interface
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08002361 * @bss: Pointer to private nl80211 data from wpa_driver_nl80211_init()
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002362 *
2363 * Shut down driver interface and processing of driver events. Free
2364 * private data buffer if one was allocated in wpa_driver_nl80211_init().
2365 */
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08002366static void wpa_driver_nl80211_deinit(struct i802_bss *bss)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002367{
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002368 struct wpa_driver_nl80211_data *drv = bss->drv;
2369
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002370 wpa_printf(MSG_INFO, "nl80211: deinit ifname=%s disabled_11b_rates=%d",
2371 bss->ifname, drv->disabled_11b_rates);
2372
Dmitry Shmidt04949592012-07-19 12:16:46 -07002373 bss->in_deinit = 1;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002374 if (drv->data_tx_status)
2375 eloop_unregister_read_sock(drv->eapol_tx_sock);
2376 if (drv->eapol_tx_sock >= 0)
2377 close(drv->eapol_tx_sock);
2378
2379 if (bss->nl_preq)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002380 wpa_driver_nl80211_probe_req_report(bss, 0);
2381 if (bss->added_if_into_bridge) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002382 if (linux_br_del_if(drv->global->ioctl_sock, bss->brname,
2383 bss->ifname) < 0)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002384 wpa_printf(MSG_INFO, "nl80211: Failed to remove "
2385 "interface %s from bridge %s: %s",
2386 bss->ifname, bss->brname, strerror(errno));
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07002387 if (drv->rtnl_sk)
Dmitry Shmidt9ead16e2014-10-07 13:15:23 -07002388 nl80211_handle_destroy(drv->rtnl_sk);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002389 }
2390 if (bss->added_bridge) {
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002391 if (linux_set_iface_flags(drv->global->ioctl_sock, bss->brname,
2392 0) < 0)
2393 wpa_printf(MSG_INFO,
2394 "nl80211: Could not set bridge %s down",
2395 bss->brname);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002396 if (linux_br_del(drv->global->ioctl_sock, bss->brname) < 0)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002397 wpa_printf(MSG_INFO, "nl80211: Failed to remove "
2398 "bridge %s: %s",
2399 bss->brname, strerror(errno));
2400 }
2401
2402 nl80211_remove_monitor_interface(drv);
2403
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002404 if (is_ap_interface(drv->nlmode))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002405 wpa_driver_nl80211_del_beacon(drv);
2406
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002407 if (drv->eapol_sock >= 0) {
2408 eloop_unregister_read_sock(drv->eapol_sock);
2409 close(drv->eapol_sock);
2410 }
2411
2412 if (drv->if_indices != drv->default_if_indices)
2413 os_free(drv->if_indices);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002414
Dmitry Shmidt9c175262016-03-03 10:20:07 -08002415 if (drv->if_indices_reason != drv->default_if_indices_reason)
2416 os_free(drv->if_indices_reason);
2417
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002418 if (drv->disabled_11b_rates)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002419 nl80211_disable_11b_rates(drv, drv->ifindex, 0);
2420
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002421 netlink_send_oper_ifla(drv->global->netlink, drv->ifindex, 0,
2422 IF_OPER_UP);
Dmitry Shmidtb58836e2014-04-29 14:35:56 -07002423 eloop_cancel_timeout(wpa_driver_nl80211_send_rfkill, drv, drv->ctx);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002424 rfkill_deinit(drv->rfkill);
2425
2426 eloop_cancel_timeout(wpa_driver_nl80211_scan_timeout, drv, drv->ctx);
2427
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08002428 if (!drv->start_iface_up)
2429 (void) i802_set_iface_flags(bss, 0);
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07002430
2431 if (drv->addr_changed) {
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002432 if (linux_set_iface_flags(drv->global->ioctl_sock, bss->ifname,
2433 0) < 0) {
2434 wpa_printf(MSG_DEBUG,
2435 "nl80211: Could not set interface down to restore permanent MAC address");
2436 }
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07002437 if (linux_set_ifhwaddr(drv->global->ioctl_sock, bss->ifname,
2438 drv->perm_addr) < 0) {
2439 wpa_printf(MSG_DEBUG,
2440 "nl80211: Could not restore permanent MAC address");
2441 }
2442 }
2443
Dmitry Shmidt34af3062013-07-11 10:46:32 -07002444 if (drv->nlmode != NL80211_IFTYPE_P2P_DEVICE) {
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08002445 if (!drv->hostapd || !drv->start_mode_ap)
2446 wpa_driver_nl80211_set_mode(bss,
2447 NL80211_IFTYPE_STATION);
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -07002448 nl80211_mgmt_unsubscribe(bss, "deinit");
Dmitry Shmidt34af3062013-07-11 10:46:32 -07002449 } else {
2450 nl80211_mgmt_unsubscribe(bss, "deinit");
2451 nl80211_del_p2pdev(bss);
2452 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002453
Dmitry Shmidtcce06662013-11-04 18:44:24 -08002454 nl80211_destroy_bss(drv->first_bss);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002455
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002456 os_free(drv->filter_ssids);
2457
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002458 os_free(drv->auth_ie);
2459
2460 if (drv->in_interface_list)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002461 dl_list_del(&drv->list);
2462
Dmitry Shmidt444d5672013-04-01 13:08:44 -07002463 os_free(drv->extended_capa);
2464 os_free(drv->extended_capa_mask);
Dmitry Shmidtcce06662013-11-04 18:44:24 -08002465 os_free(drv->first_bss);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002466 os_free(drv);
2467}
2468
2469
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002470static u32 wpa_alg_to_cipher_suite(enum wpa_alg alg, size_t key_len)
2471{
2472 switch (alg) {
2473 case WPA_ALG_WEP:
2474 if (key_len == 5)
2475 return WLAN_CIPHER_SUITE_WEP40;
2476 return WLAN_CIPHER_SUITE_WEP104;
2477 case WPA_ALG_TKIP:
2478 return WLAN_CIPHER_SUITE_TKIP;
2479 case WPA_ALG_CCMP:
2480 return WLAN_CIPHER_SUITE_CCMP;
2481 case WPA_ALG_GCMP:
2482 return WLAN_CIPHER_SUITE_GCMP;
2483 case WPA_ALG_CCMP_256:
2484 return WLAN_CIPHER_SUITE_CCMP_256;
2485 case WPA_ALG_GCMP_256:
2486 return WLAN_CIPHER_SUITE_GCMP_256;
2487 case WPA_ALG_IGTK:
2488 return WLAN_CIPHER_SUITE_AES_CMAC;
2489 case WPA_ALG_BIP_GMAC_128:
2490 return WLAN_CIPHER_SUITE_BIP_GMAC_128;
2491 case WPA_ALG_BIP_GMAC_256:
2492 return WLAN_CIPHER_SUITE_BIP_GMAC_256;
2493 case WPA_ALG_BIP_CMAC_256:
2494 return WLAN_CIPHER_SUITE_BIP_CMAC_256;
2495 case WPA_ALG_SMS4:
2496 return WLAN_CIPHER_SUITE_SMS4;
2497 case WPA_ALG_KRK:
2498 return WLAN_CIPHER_SUITE_KRK;
2499 case WPA_ALG_NONE:
2500 case WPA_ALG_PMK:
2501 wpa_printf(MSG_ERROR, "nl80211: Unexpected encryption algorithm %d",
2502 alg);
2503 return 0;
2504 }
2505
2506 wpa_printf(MSG_ERROR, "nl80211: Unsupported encryption algorithm %d",
2507 alg);
2508 return 0;
2509}
2510
2511
2512static u32 wpa_cipher_to_cipher_suite(unsigned int cipher)
2513{
2514 switch (cipher) {
2515 case WPA_CIPHER_CCMP_256:
2516 return WLAN_CIPHER_SUITE_CCMP_256;
2517 case WPA_CIPHER_GCMP_256:
2518 return WLAN_CIPHER_SUITE_GCMP_256;
2519 case WPA_CIPHER_CCMP:
2520 return WLAN_CIPHER_SUITE_CCMP;
2521 case WPA_CIPHER_GCMP:
2522 return WLAN_CIPHER_SUITE_GCMP;
2523 case WPA_CIPHER_TKIP:
2524 return WLAN_CIPHER_SUITE_TKIP;
2525 case WPA_CIPHER_WEP104:
2526 return WLAN_CIPHER_SUITE_WEP104;
2527 case WPA_CIPHER_WEP40:
2528 return WLAN_CIPHER_SUITE_WEP40;
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08002529 case WPA_CIPHER_GTK_NOT_USED:
2530 return WLAN_CIPHER_SUITE_NO_GROUP_ADDR;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002531 }
2532
2533 return 0;
2534}
2535
2536
2537static int wpa_cipher_to_cipher_suites(unsigned int ciphers, u32 suites[],
2538 int max_suites)
2539{
2540 int num_suites = 0;
2541
2542 if (num_suites < max_suites && ciphers & WPA_CIPHER_CCMP_256)
2543 suites[num_suites++] = WLAN_CIPHER_SUITE_CCMP_256;
2544 if (num_suites < max_suites && ciphers & WPA_CIPHER_GCMP_256)
2545 suites[num_suites++] = WLAN_CIPHER_SUITE_GCMP_256;
2546 if (num_suites < max_suites && ciphers & WPA_CIPHER_CCMP)
2547 suites[num_suites++] = WLAN_CIPHER_SUITE_CCMP;
2548 if (num_suites < max_suites && ciphers & WPA_CIPHER_GCMP)
2549 suites[num_suites++] = WLAN_CIPHER_SUITE_GCMP;
2550 if (num_suites < max_suites && ciphers & WPA_CIPHER_TKIP)
2551 suites[num_suites++] = WLAN_CIPHER_SUITE_TKIP;
2552 if (num_suites < max_suites && ciphers & WPA_CIPHER_WEP104)
2553 suites[num_suites++] = WLAN_CIPHER_SUITE_WEP104;
2554 if (num_suites < max_suites && ciphers & WPA_CIPHER_WEP40)
2555 suites[num_suites++] = WLAN_CIPHER_SUITE_WEP40;
2556
2557 return num_suites;
2558}
2559
2560
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08002561#ifdef CONFIG_DRIVER_NL80211_QCA
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002562static int issue_key_mgmt_set_key(struct wpa_driver_nl80211_data *drv,
2563 const u8 *key, size_t key_len)
2564{
2565 struct nl_msg *msg;
2566 int ret;
2567
2568 if (!(drv->capa.flags & WPA_DRIVER_FLAGS_KEY_MGMT_OFFLOAD))
2569 return 0;
2570
2571 if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_VENDOR)) ||
2572 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
2573 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
2574 QCA_NL80211_VENDOR_SUBCMD_KEY_MGMT_SET_KEY) ||
2575 nla_put(msg, NL80211_ATTR_VENDOR_DATA, key_len, key)) {
2576 nl80211_nlmsg_clear(msg);
2577 nlmsg_free(msg);
2578 return -1;
2579 }
2580 ret = send_and_recv_msgs(drv, msg, NULL, (void *) -1);
2581 if (ret) {
2582 wpa_printf(MSG_DEBUG,
2583 "nl80211: Key management set key failed: ret=%d (%s)",
2584 ret, strerror(-ret));
2585 }
2586
2587 return ret;
2588}
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08002589#endif /* CONFIG_DRIVER_NL80211_QCA */
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002590
2591
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08002592static int wpa_driver_nl80211_set_key(const char *ifname, struct i802_bss *bss,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002593 enum wpa_alg alg, const u8 *addr,
2594 int key_idx, int set_tx,
2595 const u8 *seq, size_t seq_len,
2596 const u8 *key, size_t key_len)
2597{
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002598 struct wpa_driver_nl80211_data *drv = bss->drv;
Dmitry Shmidt34af3062013-07-11 10:46:32 -07002599 int ifindex;
Dmitry Shmidt1d755d02015-04-28 10:34:29 -07002600 struct nl_msg *msg = NULL;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002601 int ret;
Dmitry Shmidtd5c075b2013-08-05 14:36:10 -07002602 int tdls = 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002603
Dmitry Shmidt34af3062013-07-11 10:46:32 -07002604 /* Ignore for P2P Device */
2605 if (drv->nlmode == NL80211_IFTYPE_P2P_DEVICE)
2606 return 0;
2607
2608 ifindex = if_nametoindex(ifname);
2609 wpa_printf(MSG_DEBUG, "%s: ifindex=%d (%s) alg=%d addr=%p key_idx=%d "
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002610 "set_tx=%d seq_len=%lu key_len=%lu",
Dmitry Shmidt34af3062013-07-11 10:46:32 -07002611 __func__, ifindex, ifname, alg, addr, key_idx, set_tx,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002612 (unsigned long) seq_len, (unsigned long) key_len);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002613#ifdef CONFIG_TDLS
Dmitry Shmidtd5c075b2013-08-05 14:36:10 -07002614 if (key_idx == -1) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002615 key_idx = 0;
Dmitry Shmidtd5c075b2013-08-05 14:36:10 -07002616 tdls = 1;
2617 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002618#endif /* CONFIG_TDLS */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002619
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08002620#ifdef CONFIG_DRIVER_NL80211_QCA
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002621 if (alg == WPA_ALG_PMK &&
2622 (drv->capa.flags & WPA_DRIVER_FLAGS_KEY_MGMT_OFFLOAD)) {
2623 wpa_printf(MSG_DEBUG, "%s: calling issue_key_mgmt_set_key",
2624 __func__);
2625 ret = issue_key_mgmt_set_key(drv, key, key_len);
2626 return ret;
2627 }
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08002628#endif /* CONFIG_DRIVER_NL80211_QCA */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002629
2630 if (alg == WPA_ALG_NONE) {
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002631 msg = nl80211_ifindex_msg(drv, ifindex, 0, NL80211_CMD_DEL_KEY);
2632 if (!msg)
2633 return -ENOBUFS;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002634 } else {
Dmitry Shmidt1d755d02015-04-28 10:34:29 -07002635 u32 suite;
2636
2637 suite = wpa_alg_to_cipher_suite(alg, key_len);
2638 if (!suite)
2639 goto fail;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002640 msg = nl80211_ifindex_msg(drv, ifindex, 0, NL80211_CMD_NEW_KEY);
2641 if (!msg ||
2642 nla_put(msg, NL80211_ATTR_KEY_DATA, key_len, key) ||
Dmitry Shmidt1d755d02015-04-28 10:34:29 -07002643 nla_put_u32(msg, NL80211_ATTR_KEY_CIPHER, suite))
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002644 goto fail;
Dmitry Shmidt98660862014-03-11 17:26:21 -07002645 wpa_hexdump_key(MSG_DEBUG, "nl80211: KEY_DATA", key, key_len);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002646 }
2647
Dmitry Shmidt98660862014-03-11 17:26:21 -07002648 if (seq && seq_len) {
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002649 if (nla_put(msg, NL80211_ATTR_KEY_SEQ, seq_len, seq))
2650 goto fail;
Dmitry Shmidt98660862014-03-11 17:26:21 -07002651 wpa_hexdump(MSG_DEBUG, "nl80211: KEY_SEQ", seq, seq_len);
2652 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002653
2654 if (addr && !is_broadcast_ether_addr(addr)) {
2655 wpa_printf(MSG_DEBUG, " addr=" MACSTR, MAC2STR(addr));
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002656 if (nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr))
2657 goto fail;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002658
2659 if (alg != WPA_ALG_WEP && key_idx && !set_tx) {
2660 wpa_printf(MSG_DEBUG, " RSN IBSS RX GTK");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002661 if (nla_put_u32(msg, NL80211_ATTR_KEY_TYPE,
2662 NL80211_KEYTYPE_GROUP))
2663 goto fail;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002664 }
2665 } else if (addr && is_broadcast_ether_addr(addr)) {
Dmitry Shmidt8da800a2013-04-24 12:57:01 -07002666 struct nlattr *types;
2667
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002668 wpa_printf(MSG_DEBUG, " broadcast key");
Dmitry Shmidt8da800a2013-04-24 12:57:01 -07002669
2670 types = nla_nest_start(msg, NL80211_ATTR_KEY_DEFAULT_TYPES);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002671 if (!types ||
2672 nla_put_flag(msg, NL80211_KEY_DEFAULT_TYPE_MULTICAST))
2673 goto fail;
Dmitry Shmidt8da800a2013-04-24 12:57:01 -07002674 nla_nest_end(msg, types);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002675 }
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002676 if (nla_put_u8(msg, NL80211_ATTR_KEY_IDX, key_idx))
2677 goto fail;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002678
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002679 ret = send_and_recv_msgs(drv, msg, NULL, key ? (void *) -1 : NULL);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002680 if ((ret == -ENOENT || ret == -ENOLINK) && alg == WPA_ALG_NONE)
2681 ret = 0;
2682 if (ret)
2683 wpa_printf(MSG_DEBUG, "nl80211: set_key failed; err=%d %s)",
2684 ret, strerror(-ret));
2685
2686 /*
2687 * If we failed or don't need to set the default TX key (below),
2688 * we're done here.
2689 */
Dmitry Shmidtd5c075b2013-08-05 14:36:10 -07002690 if (ret || !set_tx || alg == WPA_ALG_NONE || tdls)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002691 return ret;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002692 if (is_ap_interface(drv->nlmode) && addr &&
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002693 !is_broadcast_ether_addr(addr))
2694 return ret;
2695
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002696 msg = nl80211_ifindex_msg(drv, ifindex, 0, NL80211_CMD_SET_KEY);
2697 if (!msg ||
2698 nla_put_u8(msg, NL80211_ATTR_KEY_IDX, key_idx) ||
Dmitry Shmidt807291d2015-01-27 13:40:23 -08002699 nla_put_flag(msg, (alg == WPA_ALG_IGTK ||
2700 alg == WPA_ALG_BIP_GMAC_128 ||
2701 alg == WPA_ALG_BIP_GMAC_256 ||
2702 alg == WPA_ALG_BIP_CMAC_256) ?
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002703 NL80211_ATTR_KEY_DEFAULT_MGMT :
2704 NL80211_ATTR_KEY_DEFAULT))
2705 goto fail;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002706 if (addr && is_broadcast_ether_addr(addr)) {
Dmitry Shmidt8da800a2013-04-24 12:57:01 -07002707 struct nlattr *types;
2708
2709 types = nla_nest_start(msg, NL80211_ATTR_KEY_DEFAULT_TYPES);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002710 if (!types ||
2711 nla_put_flag(msg, NL80211_KEY_DEFAULT_TYPE_MULTICAST))
2712 goto fail;
Dmitry Shmidt8da800a2013-04-24 12:57:01 -07002713 nla_nest_end(msg, types);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002714 } else if (addr) {
Dmitry Shmidt8da800a2013-04-24 12:57:01 -07002715 struct nlattr *types;
2716
2717 types = nla_nest_start(msg, NL80211_ATTR_KEY_DEFAULT_TYPES);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002718 if (!types ||
2719 nla_put_flag(msg, NL80211_KEY_DEFAULT_TYPE_UNICAST))
2720 goto fail;
Dmitry Shmidt8da800a2013-04-24 12:57:01 -07002721 nla_nest_end(msg, types);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002722 }
2723
2724 ret = send_and_recv_msgs(drv, msg, NULL, NULL);
2725 if (ret == -ENOENT)
2726 ret = 0;
2727 if (ret)
2728 wpa_printf(MSG_DEBUG, "nl80211: set_key default failed; "
2729 "err=%d %s)", ret, strerror(-ret));
2730 return ret;
2731
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002732fail:
2733 nl80211_nlmsg_clear(msg);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002734 nlmsg_free(msg);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002735 return -ENOBUFS;
2736}
2737
2738
2739static int nl_add_key(struct nl_msg *msg, enum wpa_alg alg,
2740 int key_idx, int defkey,
2741 const u8 *seq, size_t seq_len,
2742 const u8 *key, size_t key_len)
2743{
2744 struct nlattr *key_attr = nla_nest_start(msg, NL80211_ATTR_KEY);
Dmitry Shmidt1d755d02015-04-28 10:34:29 -07002745 u32 suite;
2746
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002747 if (!key_attr)
2748 return -1;
2749
Dmitry Shmidt1d755d02015-04-28 10:34:29 -07002750 suite = wpa_alg_to_cipher_suite(alg, key_len);
2751 if (!suite)
2752 return -1;
2753
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002754 if (defkey && alg == WPA_ALG_IGTK) {
2755 if (nla_put_flag(msg, NL80211_KEY_DEFAULT_MGMT))
2756 return -1;
2757 } else if (defkey) {
2758 if (nla_put_flag(msg, NL80211_KEY_DEFAULT))
2759 return -1;
2760 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002761
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002762 if (nla_put_u8(msg, NL80211_KEY_IDX, key_idx) ||
Dmitry Shmidt1d755d02015-04-28 10:34:29 -07002763 nla_put_u32(msg, NL80211_KEY_CIPHER, suite) ||
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002764 (seq && seq_len &&
2765 nla_put(msg, NL80211_KEY_SEQ, seq_len, seq)) ||
2766 nla_put(msg, NL80211_KEY_DATA, key_len, key))
2767 return -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002768
2769 nla_nest_end(msg, key_attr);
2770
2771 return 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002772}
2773
2774
2775static int nl80211_set_conn_keys(struct wpa_driver_associate_params *params,
2776 struct nl_msg *msg)
2777{
2778 int i, privacy = 0;
2779 struct nlattr *nl_keys, *nl_key;
2780
2781 for (i = 0; i < 4; i++) {
2782 if (!params->wep_key[i])
2783 continue;
2784 privacy = 1;
2785 break;
2786 }
2787 if (params->wps == WPS_MODE_PRIVACY)
2788 privacy = 1;
2789 if (params->pairwise_suite &&
2790 params->pairwise_suite != WPA_CIPHER_NONE)
2791 privacy = 1;
2792
2793 if (!privacy)
2794 return 0;
2795
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002796 if (nla_put_flag(msg, NL80211_ATTR_PRIVACY))
2797 return -ENOBUFS;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002798
2799 nl_keys = nla_nest_start(msg, NL80211_ATTR_KEYS);
2800 if (!nl_keys)
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002801 return -ENOBUFS;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002802
2803 for (i = 0; i < 4; i++) {
2804 if (!params->wep_key[i])
2805 continue;
2806
2807 nl_key = nla_nest_start(msg, i);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002808 if (!nl_key ||
2809 nla_put(msg, NL80211_KEY_DATA, params->wep_key_len[i],
2810 params->wep_key[i]) ||
2811 nla_put_u32(msg, NL80211_KEY_CIPHER,
2812 params->wep_key_len[i] == 5 ?
2813 WLAN_CIPHER_SUITE_WEP40 :
2814 WLAN_CIPHER_SUITE_WEP104) ||
2815 nla_put_u8(msg, NL80211_KEY_IDX, i) ||
2816 (i == params->wep_tx_keyidx &&
2817 nla_put_flag(msg, NL80211_KEY_DEFAULT)))
2818 return -ENOBUFS;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002819
2820 nla_nest_end(msg, nl_key);
2821 }
2822 nla_nest_end(msg, nl_keys);
2823
2824 return 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002825}
2826
2827
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002828int wpa_driver_nl80211_mlme(struct wpa_driver_nl80211_data *drv,
2829 const u8 *addr, int cmd, u16 reason_code,
2830 int local_state_change)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002831{
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002832 int ret;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002833 struct nl_msg *msg;
2834
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002835 if (!(msg = nl80211_drv_msg(drv, 0, cmd)) ||
2836 nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason_code) ||
2837 (addr && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) ||
2838 (local_state_change &&
2839 nla_put_flag(msg, NL80211_ATTR_LOCAL_STATE_CHANGE))) {
2840 nlmsg_free(msg);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002841 return -1;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002842 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002843
2844 ret = send_and_recv_msgs(drv, msg, NULL, NULL);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002845 if (ret) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002846 wpa_dbg(drv->ctx, MSG_DEBUG,
2847 "nl80211: MLME command failed: reason=%u ret=%d (%s)",
2848 reason_code, ret, strerror(-ret));
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002849 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002850 return ret;
2851}
2852
2853
2854static int wpa_driver_nl80211_disconnect(struct wpa_driver_nl80211_data *drv,
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08002855 int reason_code)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002856{
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07002857 int ret;
2858
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08002859 wpa_printf(MSG_DEBUG, "%s(reason_code=%d)", __func__, reason_code);
Dmitry Shmidt8bae4132013-06-06 11:25:10 -07002860 nl80211_mark_disconnected(drv);
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08002861 /* Disconnect command doesn't need BSSID - it uses cached value */
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07002862 ret = wpa_driver_nl80211_mlme(drv, NULL, NL80211_CMD_DISCONNECT,
2863 reason_code, 0);
2864 /*
2865 * For locally generated disconnect, supplicant already generates a
2866 * DEAUTH event, so ignore the event from NL80211.
2867 */
2868 drv->ignore_next_local_disconnect = ret == 0;
2869
2870 return ret;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002871}
2872
2873
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08002874static int wpa_driver_nl80211_deauthenticate(struct i802_bss *bss,
2875 const u8 *addr, int reason_code)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002876{
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002877 struct wpa_driver_nl80211_data *drv = bss->drv;
Dmitry Shmidt7dba0e52014-04-14 10:49:15 -07002878 int ret;
Dmitry Shmidt413dde72014-04-11 10:23:22 -07002879
2880 if (drv->nlmode == NL80211_IFTYPE_ADHOC) {
2881 nl80211_mark_disconnected(drv);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002882 return nl80211_leave_ibss(drv, 1);
Dmitry Shmidt413dde72014-04-11 10:23:22 -07002883 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002884 if (!(drv->capa.flags & WPA_DRIVER_FLAGS_SME))
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08002885 return wpa_driver_nl80211_disconnect(drv, reason_code);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002886 wpa_printf(MSG_DEBUG, "%s(addr=" MACSTR " reason_code=%d)",
2887 __func__, MAC2STR(addr), reason_code);
Dmitry Shmidt8bae4132013-06-06 11:25:10 -07002888 nl80211_mark_disconnected(drv);
Dmitry Shmidt7dba0e52014-04-14 10:49:15 -07002889 ret = wpa_driver_nl80211_mlme(drv, addr, NL80211_CMD_DEAUTHENTICATE,
2890 reason_code, 0);
2891 /*
2892 * For locally generated deauthenticate, supplicant already generates a
2893 * DEAUTH event, so ignore the event from NL80211.
2894 */
2895 drv->ignore_next_local_deauth = ret == 0;
2896 return ret;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002897}
2898
2899
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002900static void nl80211_copy_auth_params(struct wpa_driver_nl80211_data *drv,
2901 struct wpa_driver_auth_params *params)
2902{
2903 int i;
2904
2905 drv->auth_freq = params->freq;
2906 drv->auth_alg = params->auth_alg;
2907 drv->auth_wep_tx_keyidx = params->wep_tx_keyidx;
2908 drv->auth_local_state_change = params->local_state_change;
2909 drv->auth_p2p = params->p2p;
2910
2911 if (params->bssid)
2912 os_memcpy(drv->auth_bssid_, params->bssid, ETH_ALEN);
2913 else
2914 os_memset(drv->auth_bssid_, 0, ETH_ALEN);
2915
2916 if (params->ssid) {
2917 os_memcpy(drv->auth_ssid, params->ssid, params->ssid_len);
2918 drv->auth_ssid_len = params->ssid_len;
2919 } else
2920 drv->auth_ssid_len = 0;
2921
2922
2923 os_free(drv->auth_ie);
2924 drv->auth_ie = NULL;
2925 drv->auth_ie_len = 0;
2926 if (params->ie) {
2927 drv->auth_ie = os_malloc(params->ie_len);
2928 if (drv->auth_ie) {
2929 os_memcpy(drv->auth_ie, params->ie, params->ie_len);
2930 drv->auth_ie_len = params->ie_len;
2931 }
2932 }
2933
2934 for (i = 0; i < 4; i++) {
2935 if (params->wep_key[i] && params->wep_key_len[i] &&
2936 params->wep_key_len[i] <= 16) {
2937 os_memcpy(drv->auth_wep_key[i], params->wep_key[i],
2938 params->wep_key_len[i]);
2939 drv->auth_wep_key_len[i] = params->wep_key_len[i];
2940 } else
2941 drv->auth_wep_key_len[i] = 0;
2942 }
2943}
2944
2945
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002946static void nl80211_unmask_11b_rates(struct i802_bss *bss)
2947{
2948 struct wpa_driver_nl80211_data *drv = bss->drv;
2949
2950 if (is_p2p_net_interface(drv->nlmode) || !drv->disabled_11b_rates)
2951 return;
2952
2953 /*
2954 * Looks like we failed to unmask 11b rates previously. This could
2955 * happen, e.g., if the interface was down at the point in time when a
2956 * P2P group was terminated.
2957 */
2958 wpa_printf(MSG_DEBUG,
2959 "nl80211: Interface %s mode is for non-P2P, but 11b rates were disabled - re-enable them",
2960 bss->ifname);
2961 nl80211_disable_11b_rates(drv, drv->ifindex, 0);
2962}
2963
2964
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002965static int wpa_driver_nl80211_authenticate(
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08002966 struct i802_bss *bss, struct wpa_driver_auth_params *params)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002967{
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002968 struct wpa_driver_nl80211_data *drv = bss->drv;
2969 int ret = -1, i;
2970 struct nl_msg *msg;
2971 enum nl80211_auth_type type;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002972 enum nl80211_iftype nlmode;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002973 int count = 0;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002974 int is_retry;
2975
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002976 nl80211_unmask_11b_rates(bss);
2977
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002978 is_retry = drv->retry_auth;
2979 drv->retry_auth = 0;
Dmitry Shmidt98660862014-03-11 17:26:21 -07002980 drv->ignore_deauth_event = 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002981
Dmitry Shmidt8bae4132013-06-06 11:25:10 -07002982 nl80211_mark_disconnected(drv);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002983 os_memset(drv->auth_bssid, 0, ETH_ALEN);
Dmitry Shmidt8bae4132013-06-06 11:25:10 -07002984 if (params->bssid)
2985 os_memcpy(drv->auth_attempt_bssid, params->bssid, ETH_ALEN);
2986 else
2987 os_memset(drv->auth_attempt_bssid, 0, ETH_ALEN);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002988 /* FIX: IBSS mode */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002989 nlmode = params->p2p ?
2990 NL80211_IFTYPE_P2P_CLIENT : NL80211_IFTYPE_STATION;
2991 if (drv->nlmode != nlmode &&
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08002992 wpa_driver_nl80211_set_mode(bss, nlmode) < 0)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002993 return -1;
2994
2995retry:
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002996 wpa_printf(MSG_DEBUG, "nl80211: Authenticate (ifindex=%d)",
2997 drv->ifindex);
2998
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002999 msg = nl80211_drv_msg(drv, 0, NL80211_CMD_AUTHENTICATE);
3000 if (!msg)
3001 goto fail;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003002
3003 for (i = 0; i < 4; i++) {
3004 if (!params->wep_key[i])
3005 continue;
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08003006 wpa_driver_nl80211_set_key(bss->ifname, bss, WPA_ALG_WEP,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003007 NULL, i,
3008 i == params->wep_tx_keyidx, NULL, 0,
3009 params->wep_key[i],
3010 params->wep_key_len[i]);
3011 if (params->wep_tx_keyidx != i)
3012 continue;
3013 if (nl_add_key(msg, WPA_ALG_WEP, i, 1, NULL, 0,
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003014 params->wep_key[i], params->wep_key_len[i]))
3015 goto fail;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003016 }
3017
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003018 if (params->bssid) {
3019 wpa_printf(MSG_DEBUG, " * bssid=" MACSTR,
3020 MAC2STR(params->bssid));
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003021 if (nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, params->bssid))
3022 goto fail;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003023 }
3024 if (params->freq) {
3025 wpa_printf(MSG_DEBUG, " * freq=%d", params->freq);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003026 if (nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, params->freq))
3027 goto fail;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003028 }
3029 if (params->ssid) {
3030 wpa_hexdump_ascii(MSG_DEBUG, " * SSID",
3031 params->ssid, params->ssid_len);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003032 if (nla_put(msg, NL80211_ATTR_SSID, params->ssid_len,
3033 params->ssid))
3034 goto fail;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003035 }
3036 wpa_hexdump(MSG_DEBUG, " * IEs", params->ie, params->ie_len);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003037 if (params->ie &&
3038 nla_put(msg, NL80211_ATTR_IE, params->ie_len, params->ie))
3039 goto fail;
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08003040 if (params->sae_data) {
3041 wpa_hexdump(MSG_DEBUG, " * SAE data", params->sae_data,
3042 params->sae_data_len);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003043 if (nla_put(msg, NL80211_ATTR_SAE_DATA, params->sae_data_len,
3044 params->sae_data))
3045 goto fail;
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08003046 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003047 if (params->auth_alg & WPA_AUTH_ALG_OPEN)
3048 type = NL80211_AUTHTYPE_OPEN_SYSTEM;
3049 else if (params->auth_alg & WPA_AUTH_ALG_SHARED)
3050 type = NL80211_AUTHTYPE_SHARED_KEY;
3051 else if (params->auth_alg & WPA_AUTH_ALG_LEAP)
3052 type = NL80211_AUTHTYPE_NETWORK_EAP;
3053 else if (params->auth_alg & WPA_AUTH_ALG_FT)
3054 type = NL80211_AUTHTYPE_FT;
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08003055 else if (params->auth_alg & WPA_AUTH_ALG_SAE)
3056 type = NL80211_AUTHTYPE_SAE;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003057 else
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003058 goto fail;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003059 wpa_printf(MSG_DEBUG, " * Auth Type %d", type);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003060 if (nla_put_u32(msg, NL80211_ATTR_AUTH_TYPE, type))
3061 goto fail;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003062 if (params->local_state_change) {
3063 wpa_printf(MSG_DEBUG, " * Local state change only");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003064 if (nla_put_flag(msg, NL80211_ATTR_LOCAL_STATE_CHANGE))
3065 goto fail;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003066 }
3067
3068 ret = send_and_recv_msgs(drv, msg, NULL, NULL);
3069 msg = NULL;
3070 if (ret) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003071 wpa_dbg(drv->ctx, MSG_DEBUG,
3072 "nl80211: MLME command failed (auth): ret=%d (%s)",
3073 ret, strerror(-ret));
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003074 count++;
3075 if (ret == -EALREADY && count == 1 && params->bssid &&
3076 !params->local_state_change) {
3077 /*
3078 * mac80211 does not currently accept new
3079 * authentication if we are already authenticated. As a
3080 * workaround, force deauthentication and try again.
3081 */
3082 wpa_printf(MSG_DEBUG, "nl80211: Retry authentication "
3083 "after forced deauthentication");
Dmitry Shmidt98660862014-03-11 17:26:21 -07003084 drv->ignore_deauth_event = 1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003085 wpa_driver_nl80211_deauthenticate(
3086 bss, params->bssid,
3087 WLAN_REASON_PREV_AUTH_NOT_VALID);
3088 nlmsg_free(msg);
3089 goto retry;
3090 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003091
3092 if (ret == -ENOENT && params->freq && !is_retry) {
3093 /*
3094 * cfg80211 has likely expired the BSS entry even
3095 * though it was previously available in our internal
3096 * BSS table. To recover quickly, start a single
3097 * channel scan on the specified channel.
3098 */
3099 struct wpa_driver_scan_params scan;
3100 int freqs[2];
3101
3102 os_memset(&scan, 0, sizeof(scan));
3103 scan.num_ssids = 1;
3104 if (params->ssid) {
3105 scan.ssids[0].ssid = params->ssid;
3106 scan.ssids[0].ssid_len = params->ssid_len;
3107 }
3108 freqs[0] = params->freq;
3109 freqs[1] = 0;
3110 scan.freqs = freqs;
3111 wpa_printf(MSG_DEBUG, "nl80211: Trigger single "
3112 "channel scan to refresh cfg80211 BSS "
3113 "entry");
3114 ret = wpa_driver_nl80211_scan(bss, &scan);
3115 if (ret == 0) {
3116 nl80211_copy_auth_params(drv, params);
3117 drv->scan_for_auth = 1;
3118 }
3119 } else if (is_retry) {
3120 /*
3121 * Need to indicate this with an event since the return
3122 * value from the retry is not delivered to core code.
3123 */
3124 union wpa_event_data event;
3125 wpa_printf(MSG_DEBUG, "nl80211: Authentication retry "
3126 "failed");
3127 os_memset(&event, 0, sizeof(event));
3128 os_memcpy(event.timeout_event.addr, drv->auth_bssid_,
3129 ETH_ALEN);
3130 wpa_supplicant_event(drv->ctx, EVENT_AUTH_TIMED_OUT,
3131 &event);
3132 }
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003133 } else {
3134 wpa_printf(MSG_DEBUG,
3135 "nl80211: Authentication request send successfully");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003136 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003137
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003138fail:
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003139 nlmsg_free(msg);
3140 return ret;
3141}
3142
3143
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003144int wpa_driver_nl80211_authenticate_retry(struct wpa_driver_nl80211_data *drv)
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003145{
3146 struct wpa_driver_auth_params params;
Dmitry Shmidtcce06662013-11-04 18:44:24 -08003147 struct i802_bss *bss = drv->first_bss;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003148 int i;
3149
3150 wpa_printf(MSG_DEBUG, "nl80211: Try to authenticate again");
3151
3152 os_memset(&params, 0, sizeof(params));
3153 params.freq = drv->auth_freq;
3154 params.auth_alg = drv->auth_alg;
3155 params.wep_tx_keyidx = drv->auth_wep_tx_keyidx;
3156 params.local_state_change = drv->auth_local_state_change;
3157 params.p2p = drv->auth_p2p;
3158
3159 if (!is_zero_ether_addr(drv->auth_bssid_))
3160 params.bssid = drv->auth_bssid_;
3161
3162 if (drv->auth_ssid_len) {
3163 params.ssid = drv->auth_ssid;
3164 params.ssid_len = drv->auth_ssid_len;
3165 }
3166
3167 params.ie = drv->auth_ie;
3168 params.ie_len = drv->auth_ie_len;
3169
3170 for (i = 0; i < 4; i++) {
3171 if (drv->auth_wep_key_len[i]) {
3172 params.wep_key[i] = drv->auth_wep_key[i];
3173 params.wep_key_len[i] = drv->auth_wep_key_len[i];
3174 }
3175 }
3176
3177 drv->retry_auth = 1;
3178 return wpa_driver_nl80211_authenticate(bss, &params);
3179}
3180
3181
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003182static int wpa_driver_nl80211_send_frame(struct i802_bss *bss,
3183 const void *data, size_t len,
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08003184 int encrypt, int noack,
3185 unsigned int freq, int no_cck,
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08003186 int offchanok, unsigned int wait_time,
3187 const u16 *csa_offs,
3188 size_t csa_offs_len)
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003189{
3190 struct wpa_driver_nl80211_data *drv = bss->drv;
3191 u64 cookie;
Dmitry Shmidt051af732013-10-22 13:52:46 -07003192 int res;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003193
Dmitry Shmidt6dc03bd2014-05-16 10:40:13 -07003194 if (freq == 0 && drv->nlmode == NL80211_IFTYPE_ADHOC) {
3195 freq = nl80211_get_assoc_freq(drv);
3196 wpa_printf(MSG_DEBUG,
3197 "nl80211: send_frame - Use assoc_freq=%u for IBSS",
3198 freq);
3199 }
Dmitry Shmidt56052862013-10-04 10:23:25 -07003200 if (freq == 0) {
3201 wpa_printf(MSG_DEBUG, "nl80211: send_frame - Use bss->freq=%u",
3202 bss->freq);
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08003203 freq = bss->freq;
Dmitry Shmidt56052862013-10-04 10:23:25 -07003204 }
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08003205
Dmitry Shmidt56052862013-10-04 10:23:25 -07003206 if (drv->use_monitor) {
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003207 wpa_printf(MSG_DEBUG, "nl80211: send_frame(freq=%u bss->freq=%u) -> send_monitor",
Dmitry Shmidt56052862013-10-04 10:23:25 -07003208 freq, bss->freq);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003209 return nl80211_send_monitor(drv, data, len, encrypt, noack);
Dmitry Shmidt56052862013-10-04 10:23:25 -07003210 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003211
Dmitry Shmidt56052862013-10-04 10:23:25 -07003212 wpa_printf(MSG_DEBUG, "nl80211: send_frame -> send_frame_cmd");
Dmitry Shmidt051af732013-10-22 13:52:46 -07003213 res = nl80211_send_frame_cmd(bss, freq, wait_time, data, len,
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08003214 &cookie, no_cck, noack, offchanok,
3215 csa_offs, csa_offs_len);
Dmitry Shmidt051af732013-10-22 13:52:46 -07003216 if (res == 0 && !noack) {
3217 const struct ieee80211_mgmt *mgmt;
3218 u16 fc;
3219
3220 mgmt = (const struct ieee80211_mgmt *) data;
3221 fc = le_to_host16(mgmt->frame_control);
3222 if (WLAN_FC_GET_TYPE(fc) == WLAN_FC_TYPE_MGMT &&
3223 WLAN_FC_GET_STYPE(fc) == WLAN_FC_STYPE_ACTION) {
3224 wpa_printf(MSG_MSGDUMP,
3225 "nl80211: Update send_action_cookie from 0x%llx to 0x%llx",
3226 (long long unsigned int)
3227 drv->send_action_cookie,
3228 (long long unsigned int) cookie);
3229 drv->send_action_cookie = cookie;
3230 }
3231 }
3232
3233 return res;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003234}
3235
3236
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08003237static int wpa_driver_nl80211_send_mlme(struct i802_bss *bss, const u8 *data,
3238 size_t data_len, int noack,
3239 unsigned int freq, int no_cck,
3240 int offchanok,
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08003241 unsigned int wait_time,
3242 const u16 *csa_offs,
3243 size_t csa_offs_len)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003244{
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003245 struct wpa_driver_nl80211_data *drv = bss->drv;
3246 struct ieee80211_mgmt *mgmt;
3247 int encrypt = 1;
3248 u16 fc;
3249
3250 mgmt = (struct ieee80211_mgmt *) data;
3251 fc = le_to_host16(mgmt->frame_control);
Dmitry Shmidt2271d3f2014-06-23 12:16:31 -07003252 wpa_printf(MSG_DEBUG, "nl80211: send_mlme - da= " MACSTR
3253 " noack=%d freq=%u no_cck=%d offchanok=%d wait_time=%u fc=0x%x (%s) nlmode=%d",
3254 MAC2STR(mgmt->da), noack, freq, no_cck, offchanok, wait_time,
3255 fc, fc2str(fc), drv->nlmode);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003256
Dmitry Shmidt34af3062013-07-11 10:46:32 -07003257 if ((is_sta_interface(drv->nlmode) ||
3258 drv->nlmode == NL80211_IFTYPE_P2P_DEVICE) &&
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003259 WLAN_FC_GET_TYPE(fc) == WLAN_FC_TYPE_MGMT &&
3260 WLAN_FC_GET_STYPE(fc) == WLAN_FC_STYPE_PROBE_RESP) {
3261 /*
3262 * The use of last_mgmt_freq is a bit of a hack,
3263 * but it works due to the single-threaded nature
3264 * of wpa_supplicant.
3265 */
Dmitry Shmidt56052862013-10-04 10:23:25 -07003266 if (freq == 0) {
3267 wpa_printf(MSG_DEBUG, "nl80211: Use last_mgmt_freq=%d",
3268 drv->last_mgmt_freq);
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08003269 freq = drv->last_mgmt_freq;
Dmitry Shmidt56052862013-10-04 10:23:25 -07003270 }
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08003271 return nl80211_send_frame_cmd(bss, freq, 0,
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003272 data, data_len, NULL, 1, noack,
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08003273 1, csa_offs, csa_offs_len);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003274 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003275
3276 if (drv->device_ap_sme && is_ap_interface(drv->nlmode)) {
Dmitry Shmidt56052862013-10-04 10:23:25 -07003277 if (freq == 0) {
3278 wpa_printf(MSG_DEBUG, "nl80211: Use bss->freq=%d",
3279 bss->freq);
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08003280 freq = bss->freq;
Dmitry Shmidt56052862013-10-04 10:23:25 -07003281 }
Dmitry Shmidt04949592012-07-19 12:16:46 -07003282 return nl80211_send_frame_cmd(bss, freq,
3283 (int) freq == bss->freq ? 0 :
3284 wait_time,
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08003285 data, data_len,
3286 &drv->send_action_cookie,
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08003287 no_cck, noack, offchanok,
3288 csa_offs, csa_offs_len);
Dmitry Shmidt6e933c12011-09-27 12:29:26 -07003289 }
Dmitry Shmidtb638fe72012-03-20 12:51:25 -07003290
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003291 if (WLAN_FC_GET_TYPE(fc) == WLAN_FC_TYPE_MGMT &&
3292 WLAN_FC_GET_STYPE(fc) == WLAN_FC_STYPE_AUTH) {
3293 /*
3294 * Only one of the authentication frame types is encrypted.
3295 * In order for static WEP encryption to work properly (i.e.,
3296 * to not encrypt the frame), we need to tell mac80211 about
3297 * the frames that must not be encrypted.
3298 */
3299 u16 auth_alg = le_to_host16(mgmt->u.auth.auth_alg);
3300 u16 auth_trans = le_to_host16(mgmt->u.auth.auth_transaction);
3301 if (auth_alg != WLAN_AUTH_SHARED_KEY || auth_trans != 3)
3302 encrypt = 0;
3303 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003304
Dmitry Shmidt56052862013-10-04 10:23:25 -07003305 wpa_printf(MSG_DEBUG, "nl80211: send_mlme -> send_frame");
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003306 return wpa_driver_nl80211_send_frame(bss, data, data_len, encrypt,
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08003307 noack, freq, no_cck, offchanok,
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08003308 wait_time, csa_offs,
3309 csa_offs_len);
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08003310}
3311
3312
Dmitry Shmidtff787d52015-01-12 13:01:47 -08003313static int nl80211_put_basic_rates(struct nl_msg *msg, const int *basic_rates)
3314{
3315 u8 rates[NL80211_MAX_SUPP_RATES];
3316 u8 rates_len = 0;
3317 int i;
3318
3319 if (!basic_rates)
3320 return 0;
3321
3322 for (i = 0; i < NL80211_MAX_SUPP_RATES && basic_rates[i] >= 0; i++)
3323 rates[rates_len++] = basic_rates[i] / 5;
3324
3325 return nla_put(msg, NL80211_ATTR_BSS_BASIC_RATES, rates_len, rates);
3326}
3327
3328
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003329static int nl80211_set_bss(struct i802_bss *bss, int cts, int preamble,
3330 int slot, int ht_opmode, int ap_isolate,
Dmitry Shmidtff787d52015-01-12 13:01:47 -08003331 const int *basic_rates)
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003332{
3333 struct wpa_driver_nl80211_data *drv = bss->drv;
3334 struct nl_msg *msg;
3335
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003336 if (!(msg = nl80211_bss_msg(bss, 0, NL80211_CMD_SET_BSS)) ||
3337 (cts >= 0 &&
3338 nla_put_u8(msg, NL80211_ATTR_BSS_CTS_PROT, cts)) ||
3339 (preamble >= 0 &&
3340 nla_put_u8(msg, NL80211_ATTR_BSS_SHORT_PREAMBLE, preamble)) ||
3341 (slot >= 0 &&
3342 nla_put_u8(msg, NL80211_ATTR_BSS_SHORT_SLOT_TIME, slot)) ||
3343 (ht_opmode >= 0 &&
3344 nla_put_u16(msg, NL80211_ATTR_BSS_HT_OPMODE, ht_opmode)) ||
3345 (ap_isolate >= 0 &&
Dmitry Shmidtff787d52015-01-12 13:01:47 -08003346 nla_put_u8(msg, NL80211_ATTR_AP_ISOLATE, ap_isolate)) ||
3347 nl80211_put_basic_rates(msg, basic_rates)) {
3348 nlmsg_free(msg);
3349 return -ENOBUFS;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003350 }
3351
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003352 return send_and_recv_msgs(drv, msg, NULL, NULL);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003353}
3354
3355
Dmitry Shmidt8bae4132013-06-06 11:25:10 -07003356static int wpa_driver_nl80211_set_acl(void *priv,
3357 struct hostapd_acl_params *params)
3358{
3359 struct i802_bss *bss = priv;
3360 struct wpa_driver_nl80211_data *drv = bss->drv;
3361 struct nl_msg *msg;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08003362 struct nl_msg *acl;
Dmitry Shmidt8bae4132013-06-06 11:25:10 -07003363 unsigned int i;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003364 int ret;
Dmitry Shmidt8bae4132013-06-06 11:25:10 -07003365
3366 if (!(drv->capa.max_acl_mac_addrs))
3367 return -ENOTSUP;
3368
3369 if (params->num_mac_acl > drv->capa.max_acl_mac_addrs)
3370 return -ENOTSUP;
3371
Dmitry Shmidt8bae4132013-06-06 11:25:10 -07003372 wpa_printf(MSG_DEBUG, "nl80211: Set %s ACL (num_mac_acl=%u)",
3373 params->acl_policy ? "Accept" : "Deny", params->num_mac_acl);
3374
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08003375 acl = nlmsg_alloc();
3376 if (!acl)
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003377 return -ENOMEM;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003378 for (i = 0; i < params->num_mac_acl; i++) {
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08003379 if (nla_put(acl, i + 1, ETH_ALEN, params->mac_acl[i].addr)) {
3380 nlmsg_free(acl);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003381 return -ENOMEM;
3382 }
3383 }
Dmitry Shmidt8bae4132013-06-06 11:25:10 -07003384
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08003385 if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_SET_MAC_ACL)) ||
3386 nla_put_u32(msg, NL80211_ATTR_ACL_POLICY, params->acl_policy ?
3387 NL80211_ACL_POLICY_DENY_UNLESS_LISTED :
3388 NL80211_ACL_POLICY_ACCEPT_UNLESS_LISTED) ||
3389 nla_put_nested(msg, NL80211_ATTR_MAC_ADDRS, acl)) {
3390 nlmsg_free(msg);
3391 nlmsg_free(acl);
3392 return -ENOMEM;
3393 }
3394 nlmsg_free(acl);
Dmitry Shmidt8bae4132013-06-06 11:25:10 -07003395
3396 ret = send_and_recv_msgs(drv, msg, NULL, NULL);
Dmitry Shmidt8bae4132013-06-06 11:25:10 -07003397 if (ret) {
3398 wpa_printf(MSG_DEBUG, "nl80211: Failed to set MAC ACL: %d (%s)",
3399 ret, strerror(-ret));
3400 }
3401
Dmitry Shmidt8bae4132013-06-06 11:25:10 -07003402 return ret;
3403}
3404
3405
Dmitry Shmidtff787d52015-01-12 13:01:47 -08003406static int nl80211_put_beacon_int(struct nl_msg *msg, int beacon_int)
3407{
3408 if (beacon_int > 0) {
3409 wpa_printf(MSG_DEBUG, " * beacon_int=%d", beacon_int);
3410 return nla_put_u32(msg, NL80211_ATTR_BEACON_INTERVAL,
3411 beacon_int);
3412 }
3413
3414 return 0;
3415}
3416
3417
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003418static int wpa_driver_nl80211_set_ap(void *priv,
3419 struct wpa_driver_ap_params *params)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003420{
3421 struct i802_bss *bss = priv;
3422 struct wpa_driver_nl80211_data *drv = bss->drv;
3423 struct nl_msg *msg;
3424 u8 cmd = NL80211_CMD_NEW_BEACON;
3425 int ret;
3426 int beacon_set;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003427 int num_suites;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003428 int smps_mode;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08003429 u32 suites[10], suite;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003430 u32 ver;
3431
Dmitry Shmidt7f656022015-02-25 14:36:37 -08003432 beacon_set = params->reenable ? 0 : bss->beacon_set;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003433
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003434 wpa_printf(MSG_DEBUG, "nl80211: Set beacon (beacon_set=%d)",
3435 beacon_set);
3436 if (beacon_set)
3437 cmd = NL80211_CMD_SET_BEACON;
3438
Dmitry Shmidt0ccb66e2013-03-29 16:41:28 -07003439 wpa_hexdump(MSG_DEBUG, "nl80211: Beacon head",
3440 params->head, params->head_len);
Dmitry Shmidt0ccb66e2013-03-29 16:41:28 -07003441 wpa_hexdump(MSG_DEBUG, "nl80211: Beacon tail",
3442 params->tail, params->tail_len);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003443 wpa_printf(MSG_DEBUG, "nl80211: ifindex=%d", bss->ifindex);
Dmitry Shmidt0ccb66e2013-03-29 16:41:28 -07003444 wpa_printf(MSG_DEBUG, "nl80211: beacon_int=%d", params->beacon_int);
Dmitry Shmidt0ccb66e2013-03-29 16:41:28 -07003445 wpa_printf(MSG_DEBUG, "nl80211: dtim_period=%d", params->dtim_period);
Dmitry Shmidt0ccb66e2013-03-29 16:41:28 -07003446 wpa_hexdump_ascii(MSG_DEBUG, "nl80211: ssid",
3447 params->ssid, params->ssid_len);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003448 if (!(msg = nl80211_bss_msg(bss, 0, cmd)) ||
3449 nla_put(msg, NL80211_ATTR_BEACON_HEAD, params->head_len,
3450 params->head) ||
3451 nla_put(msg, NL80211_ATTR_BEACON_TAIL, params->tail_len,
3452 params->tail) ||
Dmitry Shmidtff787d52015-01-12 13:01:47 -08003453 nl80211_put_beacon_int(msg, params->beacon_int) ||
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003454 nla_put_u32(msg, NL80211_ATTR_DTIM_PERIOD, params->dtim_period) ||
3455 nla_put(msg, NL80211_ATTR_SSID, params->ssid_len, params->ssid))
3456 goto fail;
Dmitry Shmidt0ccb66e2013-03-29 16:41:28 -07003457 if (params->proberesp && params->proberesp_len) {
3458 wpa_hexdump(MSG_DEBUG, "nl80211: proberesp (offload)",
3459 params->proberesp, params->proberesp_len);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003460 if (nla_put(msg, NL80211_ATTR_PROBE_RESP, params->proberesp_len,
3461 params->proberesp))
3462 goto fail;
Dmitry Shmidt0ccb66e2013-03-29 16:41:28 -07003463 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003464 switch (params->hide_ssid) {
3465 case NO_SSID_HIDING:
Dmitry Shmidt0ccb66e2013-03-29 16:41:28 -07003466 wpa_printf(MSG_DEBUG, "nl80211: hidden SSID not in use");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003467 if (nla_put_u32(msg, NL80211_ATTR_HIDDEN_SSID,
3468 NL80211_HIDDEN_SSID_NOT_IN_USE))
3469 goto fail;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003470 break;
3471 case HIDDEN_SSID_ZERO_LEN:
Dmitry Shmidt0ccb66e2013-03-29 16:41:28 -07003472 wpa_printf(MSG_DEBUG, "nl80211: hidden SSID zero len");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003473 if (nla_put_u32(msg, NL80211_ATTR_HIDDEN_SSID,
3474 NL80211_HIDDEN_SSID_ZERO_LEN))
3475 goto fail;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003476 break;
3477 case HIDDEN_SSID_ZERO_CONTENTS:
Dmitry Shmidt0ccb66e2013-03-29 16:41:28 -07003478 wpa_printf(MSG_DEBUG, "nl80211: hidden SSID zero contents");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003479 if (nla_put_u32(msg, NL80211_ATTR_HIDDEN_SSID,
3480 NL80211_HIDDEN_SSID_ZERO_CONTENTS))
3481 goto fail;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003482 break;
3483 }
Dmitry Shmidt0ccb66e2013-03-29 16:41:28 -07003484 wpa_printf(MSG_DEBUG, "nl80211: privacy=%d", params->privacy);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003485 if (params->privacy &&
3486 nla_put_flag(msg, NL80211_ATTR_PRIVACY))
3487 goto fail;
Dmitry Shmidt0ccb66e2013-03-29 16:41:28 -07003488 wpa_printf(MSG_DEBUG, "nl80211: auth_algs=0x%x", params->auth_algs);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003489 if ((params->auth_algs & (WPA_AUTH_ALG_OPEN | WPA_AUTH_ALG_SHARED)) ==
3490 (WPA_AUTH_ALG_OPEN | WPA_AUTH_ALG_SHARED)) {
3491 /* Leave out the attribute */
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003492 } else if (params->auth_algs & WPA_AUTH_ALG_SHARED) {
3493 if (nla_put_u32(msg, NL80211_ATTR_AUTH_TYPE,
3494 NL80211_AUTHTYPE_SHARED_KEY))
3495 goto fail;
3496 } else {
3497 if (nla_put_u32(msg, NL80211_ATTR_AUTH_TYPE,
3498 NL80211_AUTHTYPE_OPEN_SYSTEM))
3499 goto fail;
3500 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003501
Dmitry Shmidt0ccb66e2013-03-29 16:41:28 -07003502 wpa_printf(MSG_DEBUG, "nl80211: wpa_version=0x%x", params->wpa_version);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003503 ver = 0;
3504 if (params->wpa_version & WPA_PROTO_WPA)
3505 ver |= NL80211_WPA_VERSION_1;
3506 if (params->wpa_version & WPA_PROTO_RSN)
3507 ver |= NL80211_WPA_VERSION_2;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003508 if (ver &&
3509 nla_put_u32(msg, NL80211_ATTR_WPA_VERSIONS, ver))
3510 goto fail;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003511
Dmitry Shmidt0ccb66e2013-03-29 16:41:28 -07003512 wpa_printf(MSG_DEBUG, "nl80211: key_mgmt_suites=0x%x",
3513 params->key_mgmt_suites);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003514 num_suites = 0;
3515 if (params->key_mgmt_suites & WPA_KEY_MGMT_IEEE8021X)
3516 suites[num_suites++] = WLAN_AKM_SUITE_8021X;
3517 if (params->key_mgmt_suites & WPA_KEY_MGMT_PSK)
3518 suites[num_suites++] = WLAN_AKM_SUITE_PSK;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003519 if (num_suites &&
3520 nla_put(msg, NL80211_ATTR_AKM_SUITES, num_suites * sizeof(u32),
3521 suites))
3522 goto fail;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003523
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003524 if (params->key_mgmt_suites & WPA_KEY_MGMT_IEEE8021X_NO_WPA &&
3525 params->pairwise_ciphers & (WPA_CIPHER_WEP104 | WPA_CIPHER_WEP40) &&
3526 nla_put_flag(msg, NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT))
3527 goto fail;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003528
Dmitry Shmidt0ccb66e2013-03-29 16:41:28 -07003529 wpa_printf(MSG_DEBUG, "nl80211: pairwise_ciphers=0x%x",
3530 params->pairwise_ciphers);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08003531 num_suites = wpa_cipher_to_cipher_suites(params->pairwise_ciphers,
3532 suites, ARRAY_SIZE(suites));
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003533 if (num_suites &&
3534 nla_put(msg, NL80211_ATTR_CIPHER_SUITES_PAIRWISE,
3535 num_suites * sizeof(u32), suites))
3536 goto fail;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003537
Dmitry Shmidt0ccb66e2013-03-29 16:41:28 -07003538 wpa_printf(MSG_DEBUG, "nl80211: group_cipher=0x%x",
3539 params->group_cipher);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08003540 suite = wpa_cipher_to_cipher_suite(params->group_cipher);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003541 if (suite &&
3542 nla_put_u32(msg, NL80211_ATTR_CIPHER_SUITE_GROUP, suite))
3543 goto fail;
3544
Dmitry Shmidte4663042016-04-04 10:07:49 -07003545 if (params->ht_opmode != -1) {
3546 switch (params->smps_mode) {
3547 case HT_CAP_INFO_SMPS_DYNAMIC:
3548 wpa_printf(MSG_DEBUG, "nl80211: SMPS mode - dynamic");
3549 smps_mode = NL80211_SMPS_DYNAMIC;
3550 break;
3551 case HT_CAP_INFO_SMPS_STATIC:
3552 wpa_printf(MSG_DEBUG, "nl80211: SMPS mode - static");
3553 smps_mode = NL80211_SMPS_STATIC;
3554 break;
3555 default:
3556 /* invalid - fallback to smps off */
3557 case HT_CAP_INFO_SMPS_DISABLED:
3558 wpa_printf(MSG_DEBUG, "nl80211: SMPS mode - off");
3559 smps_mode = NL80211_SMPS_OFF;
3560 break;
3561 }
3562 if (nla_put_u32(msg, NL80211_ATTR_SMPS_MODE, smps_mode))
3563 goto fail;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003564 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003565
3566 if (params->beacon_ies) {
Dmitry Shmidt0ccb66e2013-03-29 16:41:28 -07003567 wpa_hexdump_buf(MSG_DEBUG, "nl80211: beacon_ies",
3568 params->beacon_ies);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003569 if (nla_put(msg, NL80211_ATTR_IE,
3570 wpabuf_len(params->beacon_ies),
3571 wpabuf_head(params->beacon_ies)))
3572 goto fail;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003573 }
3574 if (params->proberesp_ies) {
Dmitry Shmidt0ccb66e2013-03-29 16:41:28 -07003575 wpa_hexdump_buf(MSG_DEBUG, "nl80211: proberesp_ies",
3576 params->proberesp_ies);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003577 if (nla_put(msg, NL80211_ATTR_IE_PROBE_RESP,
3578 wpabuf_len(params->proberesp_ies),
3579 wpabuf_head(params->proberesp_ies)))
3580 goto fail;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003581 }
3582 if (params->assocresp_ies) {
Dmitry Shmidt0ccb66e2013-03-29 16:41:28 -07003583 wpa_hexdump_buf(MSG_DEBUG, "nl80211: assocresp_ies",
3584 params->assocresp_ies);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003585 if (nla_put(msg, NL80211_ATTR_IE_ASSOC_RESP,
3586 wpabuf_len(params->assocresp_ies),
3587 wpabuf_head(params->assocresp_ies)))
3588 goto fail;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003589 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003590
Dmitry Shmidt04949592012-07-19 12:16:46 -07003591 if (drv->capa.flags & WPA_DRIVER_FLAGS_INACTIVITY_TIMER) {
Dmitry Shmidt0ccb66e2013-03-29 16:41:28 -07003592 wpa_printf(MSG_DEBUG, "nl80211: ap_max_inactivity=%d",
3593 params->ap_max_inactivity);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003594 if (nla_put_u16(msg, NL80211_ATTR_INACTIVITY_TIMEOUT,
3595 params->ap_max_inactivity))
3596 goto fail;
Dmitry Shmidt04949592012-07-19 12:16:46 -07003597 }
3598
Dmitry Shmidt7f656022015-02-25 14:36:37 -08003599#ifdef CONFIG_P2P
3600 if (params->p2p_go_ctwindow > 0) {
3601 if (drv->p2p_go_ctwindow_supported) {
3602 wpa_printf(MSG_DEBUG, "nl80211: P2P GO ctwindow=%d",
3603 params->p2p_go_ctwindow);
3604 if (nla_put_u8(msg, NL80211_ATTR_P2P_CTWINDOW,
3605 params->p2p_go_ctwindow))
3606 goto fail;
3607 } else {
3608 wpa_printf(MSG_INFO,
3609 "nl80211: Driver does not support CTWindow configuration - ignore this parameter");
3610 }
3611 }
3612#endif /* CONFIG_P2P */
3613
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08003614 if (params->pbss) {
3615 wpa_printf(MSG_DEBUG, "nl80211: PBSS");
3616 if (nla_put_flag(msg, NL80211_ATTR_PBSS))
3617 goto fail;
3618 }
3619
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003620 ret = send_and_recv_msgs(drv, msg, NULL, NULL);
3621 if (ret) {
3622 wpa_printf(MSG_DEBUG, "nl80211: Beacon set failed: %d (%s)",
3623 ret, strerror(-ret));
3624 } else {
3625 bss->beacon_set = 1;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003626 nl80211_set_bss(bss, params->cts_protect, params->preamble,
3627 params->short_slot_time, params->ht_opmode,
3628 params->isolate, params->basic_rates);
Dmitry Shmidt7832adb2014-04-29 10:53:02 -07003629 if (beacon_set && params->freq &&
3630 params->freq->bandwidth != bss->bandwidth) {
3631 wpa_printf(MSG_DEBUG,
3632 "nl80211: Update BSS %s bandwidth: %d -> %d",
3633 bss->ifname, bss->bandwidth,
3634 params->freq->bandwidth);
3635 ret = nl80211_set_channel(bss, params->freq, 1);
3636 if (ret) {
3637 wpa_printf(MSG_DEBUG,
3638 "nl80211: Frequency set failed: %d (%s)",
3639 ret, strerror(-ret));
3640 } else {
3641 wpa_printf(MSG_DEBUG,
3642 "nl80211: Frequency set succeeded for ht2040 coex");
3643 bss->bandwidth = params->freq->bandwidth;
3644 }
3645 } else if (!beacon_set) {
3646 /*
3647 * cfg80211 updates the driver on frequence change in AP
3648 * mode only at the point when beaconing is started, so
3649 * set the initial value here.
3650 */
3651 bss->bandwidth = params->freq->bandwidth;
3652 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003653 }
3654 return ret;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003655fail:
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003656 nlmsg_free(msg);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003657 return -ENOBUFS;
3658}
3659
3660
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08003661static int nl80211_put_freq_params(struct nl_msg *msg,
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003662 const struct hostapd_freq_params *freq)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003663{
Dmitry Shmidtff787d52015-01-12 13:01:47 -08003664 wpa_printf(MSG_DEBUG, " * freq=%d", freq->freq);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003665 if (nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq->freq))
3666 return -ENOBUFS;
3667
Dmitry Shmidtff787d52015-01-12 13:01:47 -08003668 wpa_printf(MSG_DEBUG, " * vht_enabled=%d", freq->vht_enabled);
3669 wpa_printf(MSG_DEBUG, " * ht_enabled=%d", freq->ht_enabled);
3670
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08003671 if (freq->vht_enabled) {
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003672 enum nl80211_chan_width cw;
3673
Dmitry Shmidtff787d52015-01-12 13:01:47 -08003674 wpa_printf(MSG_DEBUG, " * bandwidth=%d", freq->bandwidth);
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08003675 switch (freq->bandwidth) {
3676 case 20:
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003677 cw = NL80211_CHAN_WIDTH_20;
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08003678 break;
3679 case 40:
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003680 cw = NL80211_CHAN_WIDTH_40;
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08003681 break;
3682 case 80:
3683 if (freq->center_freq2)
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003684 cw = NL80211_CHAN_WIDTH_80P80;
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08003685 else
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003686 cw = NL80211_CHAN_WIDTH_80;
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08003687 break;
3688 case 160:
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003689 cw = NL80211_CHAN_WIDTH_160;
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08003690 break;
3691 default:
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08003692 return -EINVAL;
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08003693 }
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003694
Dmitry Shmidtff787d52015-01-12 13:01:47 -08003695 wpa_printf(MSG_DEBUG, " * channel_width=%d", cw);
3696 wpa_printf(MSG_DEBUG, " * center_freq1=%d",
3697 freq->center_freq1);
3698 wpa_printf(MSG_DEBUG, " * center_freq2=%d",
3699 freq->center_freq2);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003700 if (nla_put_u32(msg, NL80211_ATTR_CHANNEL_WIDTH, cw) ||
3701 nla_put_u32(msg, NL80211_ATTR_CENTER_FREQ1,
3702 freq->center_freq1) ||
3703 (freq->center_freq2 &&
3704 nla_put_u32(msg, NL80211_ATTR_CENTER_FREQ2,
3705 freq->center_freq2)))
3706 return -ENOBUFS;
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08003707 } else if (freq->ht_enabled) {
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003708 enum nl80211_channel_type ct;
3709
Dmitry Shmidtff787d52015-01-12 13:01:47 -08003710 wpa_printf(MSG_DEBUG, " * sec_channel_offset=%d",
3711 freq->sec_channel_offset);
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08003712 switch (freq->sec_channel_offset) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003713 case -1:
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003714 ct = NL80211_CHAN_HT40MINUS;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003715 break;
3716 case 1:
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003717 ct = NL80211_CHAN_HT40PLUS;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003718 break;
3719 default:
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003720 ct = NL80211_CHAN_HT20;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003721 break;
3722 }
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003723
Dmitry Shmidtff787d52015-01-12 13:01:47 -08003724 wpa_printf(MSG_DEBUG, " * channel_type=%d", ct);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003725 if (nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE, ct))
3726 return -ENOBUFS;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003727 }
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08003728 return 0;
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08003729}
3730
3731
Dmitry Shmidt7832adb2014-04-29 10:53:02 -07003732static int nl80211_set_channel(struct i802_bss *bss,
3733 struct hostapd_freq_params *freq, int set_chan)
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08003734{
3735 struct wpa_driver_nl80211_data *drv = bss->drv;
3736 struct nl_msg *msg;
3737 int ret;
3738
3739 wpa_printf(MSG_DEBUG,
3740 "nl80211: Set freq %d (ht_enabled=%d, vht_enabled=%d, bandwidth=%d MHz, cf1=%d MHz, cf2=%d MHz)",
3741 freq->freq, freq->ht_enabled, freq->vht_enabled,
3742 freq->bandwidth, freq->center_freq1, freq->center_freq2);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003743
3744 msg = nl80211_drv_msg(drv, 0, set_chan ? NL80211_CMD_SET_CHANNEL :
3745 NL80211_CMD_SET_WIPHY);
3746 if (!msg || nl80211_put_freq_params(msg, freq) < 0) {
3747 nlmsg_free(msg);
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08003748 return -1;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003749 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003750
3751 ret = send_and_recv_msgs(drv, msg, NULL, NULL);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003752 if (ret == 0) {
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08003753 bss->freq = freq->freq;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003754 return 0;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003755 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003756 wpa_printf(MSG_DEBUG, "nl80211: Failed to set channel (freq=%d): "
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08003757 "%d (%s)", freq->freq, ret, strerror(-ret));
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003758 return -1;
3759}
3760
3761
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003762static u32 sta_flags_nl80211(int flags)
3763{
3764 u32 f = 0;
3765
3766 if (flags & WPA_STA_AUTHORIZED)
3767 f |= BIT(NL80211_STA_FLAG_AUTHORIZED);
3768 if (flags & WPA_STA_WMM)
3769 f |= BIT(NL80211_STA_FLAG_WME);
3770 if (flags & WPA_STA_SHORT_PREAMBLE)
3771 f |= BIT(NL80211_STA_FLAG_SHORT_PREAMBLE);
3772 if (flags & WPA_STA_MFP)
3773 f |= BIT(NL80211_STA_FLAG_MFP);
3774 if (flags & WPA_STA_TDLS_PEER)
3775 f |= BIT(NL80211_STA_FLAG_TDLS_PEER);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003776 if (flags & WPA_STA_AUTHENTICATED)
3777 f |= BIT(NL80211_STA_FLAG_AUTHENTICATED);
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08003778 if (flags & WPA_STA_ASSOCIATED)
3779 f |= BIT(NL80211_STA_FLAG_ASSOCIATED);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003780
3781 return f;
3782}
3783
3784
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003785#ifdef CONFIG_MESH
3786static u32 sta_plink_state_nl80211(enum mesh_plink_state state)
3787{
3788 switch (state) {
3789 case PLINK_LISTEN:
3790 return NL80211_PLINK_LISTEN;
3791 case PLINK_OPEN_SENT:
3792 return NL80211_PLINK_OPN_SNT;
3793 case PLINK_OPEN_RCVD:
3794 return NL80211_PLINK_OPN_RCVD;
3795 case PLINK_CNF_RCVD:
3796 return NL80211_PLINK_CNF_RCVD;
3797 case PLINK_ESTAB:
3798 return NL80211_PLINK_ESTAB;
3799 case PLINK_HOLDING:
3800 return NL80211_PLINK_HOLDING;
3801 case PLINK_BLOCKED:
3802 return NL80211_PLINK_BLOCKED;
3803 default:
3804 wpa_printf(MSG_ERROR, "nl80211: Invalid mesh plink state %d",
3805 state);
3806 }
3807 return -1;
3808}
3809#endif /* CONFIG_MESH */
3810
3811
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003812static int wpa_driver_nl80211_sta_add(void *priv,
3813 struct hostapd_sta_add_params *params)
3814{
3815 struct i802_bss *bss = priv;
3816 struct wpa_driver_nl80211_data *drv = bss->drv;
Dmitry Shmidt8da800a2013-04-24 12:57:01 -07003817 struct nl_msg *msg;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003818 struct nl80211_sta_flag_update upd;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003819 int ret = -ENOBUFS;
3820
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003821 if ((params->flags & WPA_STA_TDLS_PEER) &&
3822 !(drv->capa.flags & WPA_DRIVER_FLAGS_TDLS_SUPPORT))
3823 return -EOPNOTSUPP;
3824
Dmitry Shmidtf8623282013-02-20 14:34:59 -08003825 wpa_printf(MSG_DEBUG, "nl80211: %s STA " MACSTR,
3826 params->set ? "Set" : "Add", MAC2STR(params->addr));
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003827 msg = nl80211_bss_msg(bss, 0, params->set ? NL80211_CMD_SET_STATION :
3828 NL80211_CMD_NEW_STATION);
3829 if (!msg || nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, params->addr))
3830 goto fail;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003831
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08003832 /*
3833 * Set the below properties only in one of the following cases:
3834 * 1. New station is added, already associated.
3835 * 2. Set WPA_STA_TDLS_PEER station.
3836 * 3. Set an already added unassociated station, if driver supports
3837 * full AP client state. (Set these properties after station became
3838 * associated will be rejected by the driver).
3839 */
3840 if (!params->set || (params->flags & WPA_STA_TDLS_PEER) ||
3841 (params->set && FULL_AP_CLIENT_STATE_SUPP(drv->capa.flags) &&
3842 (params->flags & WPA_STA_ASSOCIATED))) {
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003843 wpa_hexdump(MSG_DEBUG, " * supported rates",
3844 params->supp_rates, params->supp_rates_len);
3845 wpa_printf(MSG_DEBUG, " * capability=0x%x",
3846 params->capability);
3847 if (nla_put(msg, NL80211_ATTR_STA_SUPPORTED_RATES,
3848 params->supp_rates_len, params->supp_rates) ||
3849 nla_put_u16(msg, NL80211_ATTR_STA_CAPABILITY,
3850 params->capability))
3851 goto fail;
3852
3853 if (params->ht_capabilities) {
3854 wpa_hexdump(MSG_DEBUG, " * ht_capabilities",
3855 (u8 *) params->ht_capabilities,
3856 sizeof(*params->ht_capabilities));
3857 if (nla_put(msg, NL80211_ATTR_HT_CAPABILITY,
3858 sizeof(*params->ht_capabilities),
3859 params->ht_capabilities))
3860 goto fail;
3861 }
3862
3863 if (params->vht_capabilities) {
3864 wpa_hexdump(MSG_DEBUG, " * vht_capabilities",
3865 (u8 *) params->vht_capabilities,
3866 sizeof(*params->vht_capabilities));
3867 if (nla_put(msg, NL80211_ATTR_VHT_CAPABILITY,
3868 sizeof(*params->vht_capabilities),
3869 params->vht_capabilities))
3870 goto fail;
3871 }
3872
3873 if (params->ext_capab) {
3874 wpa_hexdump(MSG_DEBUG, " * ext_capab",
3875 params->ext_capab, params->ext_capab_len);
3876 if (nla_put(msg, NL80211_ATTR_STA_EXT_CAPABILITY,
3877 params->ext_capab_len, params->ext_capab))
3878 goto fail;
3879 }
3880 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003881 if (!params->set) {
Dmitry Shmidt51b6ea82013-05-08 10:42:09 -07003882 if (params->aid) {
3883 wpa_printf(MSG_DEBUG, " * aid=%u", params->aid);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003884 if (nla_put_u16(msg, NL80211_ATTR_STA_AID, params->aid))
3885 goto fail;
Dmitry Shmidt51b6ea82013-05-08 10:42:09 -07003886 } else {
3887 /*
3888 * cfg80211 validates that AID is non-zero, so we have
3889 * to make this a non-zero value for the TDLS case where
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08003890 * a dummy STA entry is used for now and for a station
3891 * that is still not associated.
Dmitry Shmidt51b6ea82013-05-08 10:42:09 -07003892 */
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08003893 wpa_printf(MSG_DEBUG, " * aid=1 (%s workaround)",
3894 (params->flags & WPA_STA_TDLS_PEER) ?
3895 "TDLS" : "UNASSOC_STA");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003896 if (nla_put_u16(msg, NL80211_ATTR_STA_AID, 1))
3897 goto fail;
Dmitry Shmidt51b6ea82013-05-08 10:42:09 -07003898 }
Dmitry Shmidtf8623282013-02-20 14:34:59 -08003899 wpa_printf(MSG_DEBUG, " * listen_interval=%u",
3900 params->listen_interval);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003901 if (nla_put_u16(msg, NL80211_ATTR_STA_LISTEN_INTERVAL,
3902 params->listen_interval))
3903 goto fail;
Dmitry Shmidt8bae4132013-06-06 11:25:10 -07003904 } else if (params->aid && (params->flags & WPA_STA_TDLS_PEER)) {
3905 wpa_printf(MSG_DEBUG, " * peer_aid=%u", params->aid);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003906 if (nla_put_u16(msg, NL80211_ATTR_PEER_AID, params->aid))
3907 goto fail;
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08003908 } else if (FULL_AP_CLIENT_STATE_SUPP(drv->capa.flags) &&
3909 (params->flags & WPA_STA_ASSOCIATED)) {
3910 wpa_printf(MSG_DEBUG, " * aid=%u", params->aid);
3911 wpa_printf(MSG_DEBUG, " * listen_interval=%u",
3912 params->listen_interval);
3913 if (nla_put_u16(msg, NL80211_ATTR_STA_AID, params->aid) ||
3914 nla_put_u16(msg, NL80211_ATTR_STA_LISTEN_INTERVAL,
3915 params->listen_interval))
3916 goto fail;
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08003917 }
3918
Dmitry Shmidtbd14a572014-02-18 10:33:49 -08003919 if (params->vht_opmode_enabled) {
3920 wpa_printf(MSG_DEBUG, " * opmode=%u", params->vht_opmode);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003921 if (nla_put_u8(msg, NL80211_ATTR_OPMODE_NOTIF,
3922 params->vht_opmode))
3923 goto fail;
Dmitry Shmidtf8623282013-02-20 14:34:59 -08003924 }
3925
Dmitry Shmidt344abd32014-01-14 13:17:00 -08003926 if (params->supp_channels) {
3927 wpa_hexdump(MSG_DEBUG, " * supported channels",
3928 params->supp_channels, params->supp_channels_len);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003929 if (nla_put(msg, NL80211_ATTR_STA_SUPPORTED_CHANNELS,
3930 params->supp_channels_len, params->supp_channels))
3931 goto fail;
Dmitry Shmidt344abd32014-01-14 13:17:00 -08003932 }
3933
3934 if (params->supp_oper_classes) {
3935 wpa_hexdump(MSG_DEBUG, " * supported operating classes",
3936 params->supp_oper_classes,
3937 params->supp_oper_classes_len);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003938 if (nla_put(msg, NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES,
3939 params->supp_oper_classes_len,
3940 params->supp_oper_classes))
3941 goto fail;
Dmitry Shmidt344abd32014-01-14 13:17:00 -08003942 }
3943
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003944 os_memset(&upd, 0, sizeof(upd));
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003945 upd.set = sta_flags_nl80211(params->flags);
3946 upd.mask = upd.set | sta_flags_nl80211(params->flags_mask);
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08003947
3948 /*
3949 * If the driver doesn't support full AP client state, ignore ASSOC/AUTH
3950 * flags, as nl80211 driver moves a new station, by default, into
3951 * associated state.
3952 *
3953 * On the other hand, if the driver supports that feature and the
3954 * station is added in unauthenticated state, set the
3955 * authenticated/associated bits in the mask to prevent moving this
3956 * station to associated state before it is actually associated.
3957 *
3958 * This is irrelevant for mesh mode where the station is added to the
3959 * driver as authenticated already, and ASSOCIATED isn't part of the
3960 * nl80211 API.
3961 */
3962 if (!is_mesh_interface(drv->nlmode)) {
3963 if (!FULL_AP_CLIENT_STATE_SUPP(drv->capa.flags)) {
3964 wpa_printf(MSG_DEBUG,
3965 "nl80211: Ignore ASSOC/AUTH flags since driver doesn't support full AP client state");
3966 upd.mask &= ~(BIT(NL80211_STA_FLAG_ASSOCIATED) |
3967 BIT(NL80211_STA_FLAG_AUTHENTICATED));
3968 } else if (!params->set &&
3969 !(params->flags & WPA_STA_TDLS_PEER)) {
3970 if (!(params->flags & WPA_STA_AUTHENTICATED))
3971 upd.mask |= BIT(NL80211_STA_FLAG_AUTHENTICATED);
3972 if (!(params->flags & WPA_STA_ASSOCIATED))
3973 upd.mask |= BIT(NL80211_STA_FLAG_ASSOCIATED);
3974 }
3975 }
3976
Dmitry Shmidtf8623282013-02-20 14:34:59 -08003977 wpa_printf(MSG_DEBUG, " * flags set=0x%x mask=0x%x",
3978 upd.set, upd.mask);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003979 if (nla_put(msg, NL80211_ATTR_STA_FLAGS2, sizeof(upd), &upd))
3980 goto fail;
3981
3982#ifdef CONFIG_MESH
3983 if (params->plink_state &&
3984 nla_put_u8(msg, NL80211_ATTR_STA_PLINK_STATE,
3985 sta_plink_state_nl80211(params->plink_state)))
3986 goto fail;
3987#endif /* CONFIG_MESH */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003988
3989 if (params->flags & WPA_STA_WMM) {
Dmitry Shmidt8da800a2013-04-24 12:57:01 -07003990 struct nlattr *wme = nla_nest_start(msg, NL80211_ATTR_STA_WME);
3991
Dmitry Shmidtf8623282013-02-20 14:34:59 -08003992 wpa_printf(MSG_DEBUG, " * qosinfo=0x%x", params->qosinfo);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003993 if (!wme ||
3994 nla_put_u8(msg, NL80211_STA_WME_UAPSD_QUEUES,
3995 params->qosinfo & WMM_QOSINFO_STA_AC_MASK) ||
3996 nla_put_u8(msg, NL80211_STA_WME_MAX_SP,
3997 (params->qosinfo >> WMM_QOSINFO_STA_SP_SHIFT) &
3998 WMM_QOSINFO_STA_SP_MASK))
3999 goto fail;
Dmitry Shmidt8da800a2013-04-24 12:57:01 -07004000 nla_nest_end(msg, wme);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004001 }
4002
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004003 ret = send_and_recv_msgs(drv, msg, NULL, NULL);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004004 msg = NULL;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004005 if (ret)
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004006 wpa_printf(MSG_DEBUG, "nl80211: NL80211_CMD_%s_STATION "
4007 "result: %d (%s)", params->set ? "SET" : "NEW", ret,
4008 strerror(-ret));
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004009 if (ret == -EEXIST)
4010 ret = 0;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004011fail:
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004012 nlmsg_free(msg);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004013 return ret;
4014}
4015
4016
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07004017static void rtnl_neigh_delete_fdb_entry(struct i802_bss *bss, const u8 *addr)
4018{
4019#ifdef CONFIG_LIBNL3_ROUTE
4020 struct wpa_driver_nl80211_data *drv = bss->drv;
4021 struct rtnl_neigh *rn;
4022 struct nl_addr *nl_addr;
4023 int err;
4024
4025 rn = rtnl_neigh_alloc();
4026 if (!rn)
4027 return;
4028
4029 rtnl_neigh_set_family(rn, AF_BRIDGE);
4030 rtnl_neigh_set_ifindex(rn, bss->ifindex);
4031 nl_addr = nl_addr_build(AF_BRIDGE, (void *) addr, ETH_ALEN);
4032 if (!nl_addr) {
4033 rtnl_neigh_put(rn);
4034 return;
4035 }
4036 rtnl_neigh_set_lladdr(rn, nl_addr);
4037
4038 err = rtnl_neigh_delete(drv->rtnl_sk, rn, 0);
4039 if (err < 0) {
4040 wpa_printf(MSG_DEBUG, "nl80211: bridge FDB entry delete for "
4041 MACSTR " ifindex=%d failed: %s", MAC2STR(addr),
4042 bss->ifindex, nl_geterror(err));
4043 } else {
4044 wpa_printf(MSG_DEBUG, "nl80211: deleted bridge FDB entry for "
4045 MACSTR, MAC2STR(addr));
4046 }
4047
4048 nl_addr_put(nl_addr);
4049 rtnl_neigh_put(rn);
4050#endif /* CONFIG_LIBNL3_ROUTE */
4051}
4052
4053
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004054static int wpa_driver_nl80211_sta_remove(struct i802_bss *bss, const u8 *addr,
4055 int deauth, u16 reason_code)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004056{
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004057 struct wpa_driver_nl80211_data *drv = bss->drv;
4058 struct nl_msg *msg;
4059 int ret;
4060
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004061 if (!(msg = nl80211_bss_msg(bss, 0, NL80211_CMD_DEL_STATION)) ||
4062 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) ||
4063 (deauth == 0 &&
4064 nla_put_u8(msg, NL80211_ATTR_MGMT_SUBTYPE,
4065 WLAN_FC_STYPE_DISASSOC)) ||
4066 (deauth == 1 &&
4067 nla_put_u8(msg, NL80211_ATTR_MGMT_SUBTYPE,
4068 WLAN_FC_STYPE_DEAUTH)) ||
4069 (reason_code &&
4070 nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason_code))) {
4071 nlmsg_free(msg);
4072 return -ENOBUFS;
4073 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004074
4075 ret = send_and_recv_msgs(drv, msg, NULL, NULL);
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -07004076 wpa_printf(MSG_DEBUG, "nl80211: sta_remove -> DEL_STATION %s " MACSTR
4077 " --> %d (%s)",
4078 bss->ifname, MAC2STR(addr), ret, strerror(-ret));
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07004079
4080 if (drv->rtnl_sk)
4081 rtnl_neigh_delete_fdb_entry(bss, addr);
4082
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004083 if (ret == -ENOENT)
4084 return 0;
4085 return ret;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004086}
4087
4088
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004089void nl80211_remove_iface(struct wpa_driver_nl80211_data *drv, int ifidx)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004090{
4091 struct nl_msg *msg;
Dmitry Shmidt76cd2cc2014-05-27 12:56:04 -07004092 struct wpa_driver_nl80211_data *drv2;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004093
4094 wpa_printf(MSG_DEBUG, "nl80211: Remove interface ifindex=%d", ifidx);
4095
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004096 /* stop listening for EAPOL on this interface */
Dmitry Shmidt76cd2cc2014-05-27 12:56:04 -07004097 dl_list_for_each(drv2, &drv->global->interfaces,
4098 struct wpa_driver_nl80211_data, list)
Dmitry Shmidt9c175262016-03-03 10:20:07 -08004099 {
4100 del_ifidx(drv2, ifidx, IFIDX_ANY);
4101 /* Remove all bridges learned for this iface */
4102 del_ifidx(drv2, IFIDX_ANY, ifidx);
4103 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004104
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004105 msg = nl80211_ifindex_msg(drv, ifidx, 0, NL80211_CMD_DEL_INTERFACE);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004106 if (send_and_recv_msgs(drv, msg, NULL, NULL) == 0)
4107 return;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004108 wpa_printf(MSG_ERROR, "Failed to remove interface (ifidx=%d)", ifidx);
4109}
4110
4111
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004112static const char * nl80211_iftype_str(enum nl80211_iftype mode)
4113{
4114 switch (mode) {
4115 case NL80211_IFTYPE_ADHOC:
4116 return "ADHOC";
4117 case NL80211_IFTYPE_STATION:
4118 return "STATION";
4119 case NL80211_IFTYPE_AP:
4120 return "AP";
Dmitry Shmidtf7e0a992013-05-23 11:03:10 -07004121 case NL80211_IFTYPE_AP_VLAN:
4122 return "AP_VLAN";
4123 case NL80211_IFTYPE_WDS:
4124 return "WDS";
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004125 case NL80211_IFTYPE_MONITOR:
4126 return "MONITOR";
Dmitry Shmidtf7e0a992013-05-23 11:03:10 -07004127 case NL80211_IFTYPE_MESH_POINT:
4128 return "MESH_POINT";
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004129 case NL80211_IFTYPE_P2P_CLIENT:
4130 return "P2P_CLIENT";
4131 case NL80211_IFTYPE_P2P_GO:
4132 return "P2P_GO";
Dmitry Shmidt34af3062013-07-11 10:46:32 -07004133 case NL80211_IFTYPE_P2P_DEVICE:
4134 return "P2P_DEVICE";
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004135 default:
4136 return "unknown";
4137 }
4138}
4139
4140
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004141static int nl80211_create_iface_once(struct wpa_driver_nl80211_data *drv,
4142 const char *ifname,
4143 enum nl80211_iftype iftype,
Dmitry Shmidt34af3062013-07-11 10:46:32 -07004144 const u8 *addr, int wds,
4145 int (*handler)(struct nl_msg *, void *),
4146 void *arg)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004147{
Dmitry Shmidt8da800a2013-04-24 12:57:01 -07004148 struct nl_msg *msg;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004149 int ifidx;
4150 int ret = -ENOBUFS;
4151
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004152 wpa_printf(MSG_DEBUG, "nl80211: Create interface iftype %d (%s)",
4153 iftype, nl80211_iftype_str(iftype));
4154
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004155 msg = nl80211_cmd_msg(drv->first_bss, 0, NL80211_CMD_NEW_INTERFACE);
4156 if (!msg ||
4157 nla_put_string(msg, NL80211_ATTR_IFNAME, ifname) ||
4158 nla_put_u32(msg, NL80211_ATTR_IFTYPE, iftype))
4159 goto fail;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004160
4161 if (iftype == NL80211_IFTYPE_MONITOR) {
Dmitry Shmidt8da800a2013-04-24 12:57:01 -07004162 struct nlattr *flags;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004163
Dmitry Shmidt8da800a2013-04-24 12:57:01 -07004164 flags = nla_nest_start(msg, NL80211_ATTR_MNTR_FLAGS);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004165 if (!flags ||
4166 nla_put_flag(msg, NL80211_MNTR_FLAG_COOK_FRAMES))
4167 goto fail;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004168
Dmitry Shmidt8da800a2013-04-24 12:57:01 -07004169 nla_nest_end(msg, flags);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004170 } else if (wds) {
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004171 if (nla_put_u8(msg, NL80211_ATTR_4ADDR, wds))
4172 goto fail;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004173 }
4174
Dmitry Shmidtb58836e2014-04-29 14:35:56 -07004175 /*
4176 * Tell cfg80211 that the interface belongs to the socket that created
4177 * it, and the interface should be deleted when the socket is closed.
4178 */
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004179 if (nla_put_flag(msg, NL80211_ATTR_IFACE_SOCKET_OWNER))
4180 goto fail;
Dmitry Shmidtb58836e2014-04-29 14:35:56 -07004181
Dmitry Shmidt34af3062013-07-11 10:46:32 -07004182 ret = send_and_recv_msgs(drv, msg, handler, arg);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004183 msg = NULL;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004184 if (ret) {
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004185 fail:
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004186 nlmsg_free(msg);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004187 wpa_printf(MSG_ERROR, "Failed to create interface %s: %d (%s)",
4188 ifname, ret, strerror(-ret));
4189 return ret;
4190 }
4191
Dmitry Shmidt34af3062013-07-11 10:46:32 -07004192 if (iftype == NL80211_IFTYPE_P2P_DEVICE)
4193 return 0;
4194
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004195 ifidx = if_nametoindex(ifname);
4196 wpa_printf(MSG_DEBUG, "nl80211: New interface %s created: ifindex=%d",
4197 ifname, ifidx);
4198
4199 if (ifidx <= 0)
4200 return -1;
4201
Dmitry Shmidt76cd2cc2014-05-27 12:56:04 -07004202 /*
4203 * Some virtual interfaces need to process EAPOL packets and events on
4204 * the parent interface. This is used mainly with hostapd.
4205 */
4206 if (drv->hostapd ||
4207 iftype == NL80211_IFTYPE_AP_VLAN ||
4208 iftype == NL80211_IFTYPE_WDS ||
4209 iftype == NL80211_IFTYPE_MONITOR) {
4210 /* start listening for EAPOL on this interface */
Dmitry Shmidt9c175262016-03-03 10:20:07 -08004211 add_ifidx(drv, ifidx, IFIDX_ANY);
Dmitry Shmidt76cd2cc2014-05-27 12:56:04 -07004212 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004213
4214 if (addr && iftype != NL80211_IFTYPE_MONITOR &&
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004215 linux_set_ifhwaddr(drv->global->ioctl_sock, ifname, addr)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004216 nl80211_remove_iface(drv, ifidx);
4217 return -1;
4218 }
4219
4220 return ifidx;
4221}
4222
4223
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004224int nl80211_create_iface(struct wpa_driver_nl80211_data *drv,
4225 const char *ifname, enum nl80211_iftype iftype,
4226 const u8 *addr, int wds,
4227 int (*handler)(struct nl_msg *, void *),
4228 void *arg, int use_existing)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004229{
4230 int ret;
4231
Dmitry Shmidt34af3062013-07-11 10:46:32 -07004232 ret = nl80211_create_iface_once(drv, ifname, iftype, addr, wds, handler,
4233 arg);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004234
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004235 /* if error occurred and interface exists already */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004236 if (ret == -ENFILE && if_nametoindex(ifname)) {
Dmitry Shmidtcce06662013-11-04 18:44:24 -08004237 if (use_existing) {
4238 wpa_printf(MSG_DEBUG, "nl80211: Continue using existing interface %s",
4239 ifname);
Dmitry Shmidtdf5a7e42014-04-02 12:59:59 -07004240 if (addr && iftype != NL80211_IFTYPE_MONITOR &&
4241 linux_set_ifhwaddr(drv->global->ioctl_sock, ifname,
4242 addr) < 0 &&
4243 (linux_set_iface_flags(drv->global->ioctl_sock,
4244 ifname, 0) < 0 ||
4245 linux_set_ifhwaddr(drv->global->ioctl_sock, ifname,
4246 addr) < 0 ||
4247 linux_set_iface_flags(drv->global->ioctl_sock,
4248 ifname, 1) < 0))
4249 return -1;
Dmitry Shmidtcce06662013-11-04 18:44:24 -08004250 return -ENFILE;
4251 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004252 wpa_printf(MSG_INFO, "Try to remove and re-create %s", ifname);
4253
4254 /* Try to remove the interface that was already there. */
4255 nl80211_remove_iface(drv, if_nametoindex(ifname));
4256
4257 /* Try to create the interface again */
4258 ret = nl80211_create_iface_once(drv, ifname, iftype, addr,
Dmitry Shmidt34af3062013-07-11 10:46:32 -07004259 wds, handler, arg);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004260 }
4261
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004262 if (ret >= 0 && is_p2p_net_interface(iftype)) {
4263 wpa_printf(MSG_DEBUG,
4264 "nl80211: Interface %s created for P2P - disable 11b rates",
4265 ifname);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004266 nl80211_disable_11b_rates(drv, ret, 1);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004267 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004268
4269 return ret;
4270}
4271
4272
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004273static int nl80211_setup_ap(struct i802_bss *bss)
4274{
4275 struct wpa_driver_nl80211_data *drv = bss->drv;
4276
Dmitry Shmidtcce06662013-11-04 18:44:24 -08004277 wpa_printf(MSG_DEBUG, "nl80211: Setup AP(%s) - device_ap_sme=%d use_monitor=%d",
4278 bss->ifname, drv->device_ap_sme, drv->use_monitor);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004279
4280 /*
4281 * Disable Probe Request reporting unless we need it in this way for
4282 * devices that include the AP SME, in the other case (unless using
4283 * monitor iface) we'll get it through the nl_mgmt socket instead.
4284 */
4285 if (!drv->device_ap_sme)
4286 wpa_driver_nl80211_probe_req_report(bss, 0);
4287
4288 if (!drv->device_ap_sme && !drv->use_monitor)
4289 if (nl80211_mgmt_subscribe_ap(bss))
4290 return -1;
4291
4292 if (drv->device_ap_sme && !drv->use_monitor)
4293 if (nl80211_mgmt_subscribe_ap_dev_sme(bss))
4294 return -1;
4295
4296 if (!drv->device_ap_sme && drv->use_monitor &&
4297 nl80211_create_monitor_interface(drv) &&
4298 !drv->device_ap_sme)
Dmitry Shmidt04949592012-07-19 12:16:46 -07004299 return -1;
4300
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004301 if (drv->device_ap_sme &&
4302 wpa_driver_nl80211_probe_req_report(bss, 1) < 0) {
4303 wpa_printf(MSG_DEBUG, "nl80211: Failed to enable "
4304 "Probe Request frame reporting in AP mode");
4305 /* Try to survive without this */
4306 }
4307
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004308 return 0;
4309}
4310
4311
4312static void nl80211_teardown_ap(struct i802_bss *bss)
4313{
4314 struct wpa_driver_nl80211_data *drv = bss->drv;
4315
Dmitry Shmidtcce06662013-11-04 18:44:24 -08004316 wpa_printf(MSG_DEBUG, "nl80211: Teardown AP(%s) - device_ap_sme=%d use_monitor=%d",
4317 bss->ifname, drv->device_ap_sme, drv->use_monitor);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004318 if (drv->device_ap_sme) {
4319 wpa_driver_nl80211_probe_req_report(bss, 0);
4320 if (!drv->use_monitor)
4321 nl80211_mgmt_unsubscribe(bss, "AP teardown (dev SME)");
4322 } else if (drv->use_monitor)
4323 nl80211_remove_monitor_interface(drv);
4324 else
4325 nl80211_mgmt_unsubscribe(bss, "AP teardown");
4326
4327 bss->beacon_set = 0;
4328}
4329
4330
4331static int nl80211_send_eapol_data(struct i802_bss *bss,
4332 const u8 *addr, const u8 *data,
4333 size_t data_len)
4334{
4335 struct sockaddr_ll ll;
4336 int ret;
4337
4338 if (bss->drv->eapol_tx_sock < 0) {
4339 wpa_printf(MSG_DEBUG, "nl80211: No socket to send EAPOL");
4340 return -1;
4341 }
4342
4343 os_memset(&ll, 0, sizeof(ll));
4344 ll.sll_family = AF_PACKET;
4345 ll.sll_ifindex = bss->ifindex;
4346 ll.sll_protocol = htons(ETH_P_PAE);
4347 ll.sll_halen = ETH_ALEN;
4348 os_memcpy(ll.sll_addr, addr, ETH_ALEN);
4349 ret = sendto(bss->drv->eapol_tx_sock, data, data_len, 0,
4350 (struct sockaddr *) &ll, sizeof(ll));
4351 if (ret < 0)
4352 wpa_printf(MSG_ERROR, "nl80211: EAPOL TX: %s",
4353 strerror(errno));
4354
4355 return ret;
4356}
4357
4358
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004359static const u8 rfc1042_header[6] = { 0xaa, 0xaa, 0x03, 0x00, 0x00, 0x00 };
4360
4361static int wpa_driver_nl80211_hapd_send_eapol(
4362 void *priv, const u8 *addr, const u8 *data,
4363 size_t data_len, int encrypt, const u8 *own_addr, u32 flags)
4364{
4365 struct i802_bss *bss = priv;
4366 struct wpa_driver_nl80211_data *drv = bss->drv;
4367 struct ieee80211_hdr *hdr;
4368 size_t len;
4369 u8 *pos;
4370 int res;
4371 int qos = flags & WPA_STA_WMM;
Dmitry Shmidt641185e2013-11-06 15:17:13 -08004372
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004373 if (drv->device_ap_sme || !drv->use_monitor)
4374 return nl80211_send_eapol_data(bss, addr, data, data_len);
4375
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004376 len = sizeof(*hdr) + (qos ? 2 : 0) + sizeof(rfc1042_header) + 2 +
4377 data_len;
4378 hdr = os_zalloc(len);
4379 if (hdr == NULL) {
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -07004380 wpa_printf(MSG_INFO, "nl80211: Failed to allocate EAPOL buffer(len=%lu)",
4381 (unsigned long) len);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004382 return -1;
4383 }
4384
4385 hdr->frame_control =
4386 IEEE80211_FC(WLAN_FC_TYPE_DATA, WLAN_FC_STYPE_DATA);
4387 hdr->frame_control |= host_to_le16(WLAN_FC_FROMDS);
4388 if (encrypt)
4389 hdr->frame_control |= host_to_le16(WLAN_FC_ISWEP);
4390 if (qos) {
4391 hdr->frame_control |=
4392 host_to_le16(WLAN_FC_STYPE_QOS_DATA << 4);
4393 }
4394
4395 memcpy(hdr->IEEE80211_DA_FROMDS, addr, ETH_ALEN);
4396 memcpy(hdr->IEEE80211_BSSID_FROMDS, own_addr, ETH_ALEN);
4397 memcpy(hdr->IEEE80211_SA_FROMDS, own_addr, ETH_ALEN);
4398 pos = (u8 *) (hdr + 1);
4399
4400 if (qos) {
Dmitry Shmidtaa532512012-09-24 10:35:31 -07004401 /* Set highest priority in QoS header */
4402 pos[0] = 7;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004403 pos[1] = 0;
4404 pos += 2;
4405 }
4406
4407 memcpy(pos, rfc1042_header, sizeof(rfc1042_header));
4408 pos += sizeof(rfc1042_header);
4409 WPA_PUT_BE16(pos, ETH_P_PAE);
4410 pos += 2;
4411 memcpy(pos, data, data_len);
4412
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08004413 res = wpa_driver_nl80211_send_frame(bss, (u8 *) hdr, len, encrypt, 0,
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08004414 0, 0, 0, 0, NULL, 0);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004415 if (res < 0) {
4416 wpa_printf(MSG_ERROR, "i802_send_eapol - packet len: %lu - "
4417 "failed: %d (%s)",
4418 (unsigned long) len, errno, strerror(errno));
4419 }
4420 os_free(hdr);
4421
4422 return res;
4423}
4424
4425
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004426static int wpa_driver_nl80211_sta_set_flags(void *priv, const u8 *addr,
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08004427 unsigned int total_flags,
4428 unsigned int flags_or,
4429 unsigned int flags_and)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004430{
4431 struct i802_bss *bss = priv;
Dmitry Shmidt8da800a2013-04-24 12:57:01 -07004432 struct nl_msg *msg;
4433 struct nlattr *flags;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004434 struct nl80211_sta_flag_update upd;
4435
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07004436 wpa_printf(MSG_DEBUG, "nl80211: Set STA flags - ifname=%s addr=" MACSTR
4437 " total_flags=0x%x flags_or=0x%x flags_and=0x%x authorized=%d",
4438 bss->ifname, MAC2STR(addr), total_flags, flags_or, flags_and,
4439 !!(total_flags & WPA_STA_AUTHORIZED));
4440
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004441 if (!(msg = nl80211_bss_msg(bss, 0, NL80211_CMD_SET_STATION)) ||
4442 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr))
4443 goto fail;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004444
4445 /*
4446 * Backwards compatibility version using NL80211_ATTR_STA_FLAGS. This
4447 * can be removed eventually.
4448 */
Dmitry Shmidt8da800a2013-04-24 12:57:01 -07004449 flags = nla_nest_start(msg, NL80211_ATTR_STA_FLAGS);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004450 if (!flags ||
4451 ((total_flags & WPA_STA_AUTHORIZED) &&
4452 nla_put_flag(msg, NL80211_STA_FLAG_AUTHORIZED)) ||
4453 ((total_flags & WPA_STA_WMM) &&
4454 nla_put_flag(msg, NL80211_STA_FLAG_WME)) ||
4455 ((total_flags & WPA_STA_SHORT_PREAMBLE) &&
4456 nla_put_flag(msg, NL80211_STA_FLAG_SHORT_PREAMBLE)) ||
4457 ((total_flags & WPA_STA_MFP) &&
4458 nla_put_flag(msg, NL80211_STA_FLAG_MFP)) ||
4459 ((total_flags & WPA_STA_TDLS_PEER) &&
4460 nla_put_flag(msg, NL80211_STA_FLAG_TDLS_PEER)))
4461 goto fail;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004462
Dmitry Shmidt8da800a2013-04-24 12:57:01 -07004463 nla_nest_end(msg, flags);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004464
4465 os_memset(&upd, 0, sizeof(upd));
4466 upd.mask = sta_flags_nl80211(flags_or | ~flags_and);
4467 upd.set = sta_flags_nl80211(flags_or);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004468 if (nla_put(msg, NL80211_ATTR_STA_FLAGS2, sizeof(upd), &upd))
4469 goto fail;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004470
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004471 return send_and_recv_msgs(bss->drv, msg, NULL, NULL);
4472fail:
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004473 nlmsg_free(msg);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004474 return -ENOBUFS;
4475}
4476
4477
4478static int wpa_driver_nl80211_ap(struct wpa_driver_nl80211_data *drv,
4479 struct wpa_driver_associate_params *params)
4480{
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08004481 enum nl80211_iftype nlmode, old_mode;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004482
4483 if (params->p2p) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004484 wpa_printf(MSG_DEBUG, "nl80211: Setup AP operations for P2P "
4485 "group (GO)");
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004486 nlmode = NL80211_IFTYPE_P2P_GO;
4487 } else
4488 nlmode = NL80211_IFTYPE_AP;
4489
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08004490 old_mode = drv->nlmode;
Dmitry Shmidtcce06662013-11-04 18:44:24 -08004491 if (wpa_driver_nl80211_set_mode(drv->first_bss, nlmode)) {
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08004492 nl80211_remove_monitor_interface(drv);
4493 return -1;
4494 }
4495
Dmitry Shmidt203eadb2015-03-05 14:16:04 -08004496 if (params->freq.freq &&
4497 nl80211_set_channel(drv->first_bss, &params->freq, 0)) {
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08004498 if (old_mode != nlmode)
Dmitry Shmidtcce06662013-11-04 18:44:24 -08004499 wpa_driver_nl80211_set_mode(drv->first_bss, old_mode);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004500 nl80211_remove_monitor_interface(drv);
4501 return -1;
4502 }
4503
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004504 return 0;
4505}
4506
4507
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004508static int nl80211_leave_ibss(struct wpa_driver_nl80211_data *drv,
4509 int reset_mode)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004510{
4511 struct nl_msg *msg;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004512 int ret;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004513
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004514 msg = nl80211_drv_msg(drv, 0, NL80211_CMD_LEAVE_IBSS);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004515 ret = send_and_recv_msgs(drv, msg, NULL, NULL);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004516 if (ret) {
4517 wpa_printf(MSG_DEBUG, "nl80211: Leave IBSS failed: ret=%d "
4518 "(%s)", ret, strerror(-ret));
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004519 } else {
4520 wpa_printf(MSG_DEBUG,
4521 "nl80211: Leave IBSS request sent successfully");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004522 }
4523
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004524 if (reset_mode &&
4525 wpa_driver_nl80211_set_mode(drv->first_bss,
Dmitry Shmidt56052862013-10-04 10:23:25 -07004526 NL80211_IFTYPE_STATION)) {
4527 wpa_printf(MSG_INFO, "nl80211: Failed to set interface into "
4528 "station mode");
4529 }
4530
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004531 return ret;
4532}
4533
4534
Dmitry Shmidt2f74e362015-01-21 13:19:05 -08004535static int nl80211_ht_vht_overrides(struct nl_msg *msg,
4536 struct wpa_driver_associate_params *params)
4537{
4538 if (params->disable_ht && nla_put_flag(msg, NL80211_ATTR_DISABLE_HT))
4539 return -1;
4540
4541 if (params->htcaps && params->htcaps_mask) {
4542 int sz = sizeof(struct ieee80211_ht_capabilities);
4543 wpa_hexdump(MSG_DEBUG, " * htcaps", params->htcaps, sz);
4544 wpa_hexdump(MSG_DEBUG, " * htcaps_mask",
4545 params->htcaps_mask, sz);
4546 if (nla_put(msg, NL80211_ATTR_HT_CAPABILITY, sz,
4547 params->htcaps) ||
4548 nla_put(msg, NL80211_ATTR_HT_CAPABILITY_MASK, sz,
4549 params->htcaps_mask))
4550 return -1;
4551 }
4552
4553#ifdef CONFIG_VHT_OVERRIDES
4554 if (params->disable_vht) {
4555 wpa_printf(MSG_DEBUG, " * VHT disabled");
4556 if (nla_put_flag(msg, NL80211_ATTR_DISABLE_VHT))
4557 return -1;
4558 }
4559
4560 if (params->vhtcaps && params->vhtcaps_mask) {
4561 int sz = sizeof(struct ieee80211_vht_capabilities);
4562 wpa_hexdump(MSG_DEBUG, " * vhtcaps", params->vhtcaps, sz);
4563 wpa_hexdump(MSG_DEBUG, " * vhtcaps_mask",
4564 params->vhtcaps_mask, sz);
4565 if (nla_put(msg, NL80211_ATTR_VHT_CAPABILITY, sz,
4566 params->vhtcaps) ||
4567 nla_put(msg, NL80211_ATTR_VHT_CAPABILITY_MASK, sz,
4568 params->vhtcaps_mask))
4569 return -1;
4570 }
4571#endif /* CONFIG_VHT_OVERRIDES */
4572
4573 return 0;
4574}
4575
4576
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004577static int wpa_driver_nl80211_ibss(struct wpa_driver_nl80211_data *drv,
4578 struct wpa_driver_associate_params *params)
4579{
4580 struct nl_msg *msg;
4581 int ret = -1;
4582 int count = 0;
4583
4584 wpa_printf(MSG_DEBUG, "nl80211: Join IBSS (ifindex=%d)", drv->ifindex);
4585
Dmitry Shmidt9ead16e2014-10-07 13:15:23 -07004586 if (wpa_driver_nl80211_set_mode_ibss(drv->first_bss, &params->freq)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004587 wpa_printf(MSG_INFO, "nl80211: Failed to set interface into "
4588 "IBSS mode");
4589 return -1;
4590 }
4591
4592retry:
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004593 if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_JOIN_IBSS)) ||
4594 params->ssid == NULL || params->ssid_len > sizeof(drv->ssid))
4595 goto fail;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004596
4597 wpa_hexdump_ascii(MSG_DEBUG, " * SSID",
4598 params->ssid, params->ssid_len);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004599 if (nla_put(msg, NL80211_ATTR_SSID, params->ssid_len, params->ssid))
4600 goto fail;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004601 os_memcpy(drv->ssid, params->ssid, params->ssid_len);
4602 drv->ssid_len = params->ssid_len;
4603
Dmitry Shmidtff787d52015-01-12 13:01:47 -08004604 if (nl80211_put_freq_params(msg, &params->freq) < 0 ||
4605 nl80211_put_beacon_int(msg, params->beacon_int))
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004606 goto fail;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004607
4608 ret = nl80211_set_conn_keys(params, msg);
4609 if (ret)
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004610 goto fail;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004611
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08004612 if (params->bssid && params->fixed_bssid) {
4613 wpa_printf(MSG_DEBUG, " * BSSID=" MACSTR,
4614 MAC2STR(params->bssid));
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004615 if (nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, params->bssid))
4616 goto fail;
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08004617 }
4618
Dmitry Shmidt7f656022015-02-25 14:36:37 -08004619 if (params->fixed_freq) {
4620 wpa_printf(MSG_DEBUG, " * fixed_freq");
4621 if (nla_put_flag(msg, NL80211_ATTR_FREQ_FIXED))
4622 goto fail;
4623 }
4624
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004625 if (params->key_mgmt_suite == WPA_KEY_MGMT_IEEE8021X ||
4626 params->key_mgmt_suite == WPA_KEY_MGMT_PSK ||
4627 params->key_mgmt_suite == WPA_KEY_MGMT_IEEE8021X_SHA256 ||
4628 params->key_mgmt_suite == WPA_KEY_MGMT_PSK_SHA256) {
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08004629 wpa_printf(MSG_DEBUG, " * control port");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004630 if (nla_put_flag(msg, NL80211_ATTR_CONTROL_PORT))
4631 goto fail;
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08004632 }
4633
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004634 if (params->wpa_ie) {
4635 wpa_hexdump(MSG_DEBUG,
4636 " * Extra IEs for Beacon/Probe Response frames",
4637 params->wpa_ie, params->wpa_ie_len);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004638 if (nla_put(msg, NL80211_ATTR_IE, params->wpa_ie_len,
4639 params->wpa_ie))
4640 goto fail;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004641 }
4642
Dmitry Shmidt1d6bf422016-01-19 15:51:35 -08004643 ret = nl80211_ht_vht_overrides(msg, params);
4644 if (ret < 0)
4645 goto fail;
Dmitry Shmidt2f74e362015-01-21 13:19:05 -08004646
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004647 ret = send_and_recv_msgs(drv, msg, NULL, NULL);
4648 msg = NULL;
4649 if (ret) {
4650 wpa_printf(MSG_DEBUG, "nl80211: Join IBSS failed: ret=%d (%s)",
4651 ret, strerror(-ret));
4652 count++;
4653 if (ret == -EALREADY && count == 1) {
4654 wpa_printf(MSG_DEBUG, "nl80211: Retry IBSS join after "
4655 "forced leave");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004656 nl80211_leave_ibss(drv, 0);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004657 nlmsg_free(msg);
4658 goto retry;
4659 }
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004660 } else {
4661 wpa_printf(MSG_DEBUG,
4662 "nl80211: Join IBSS request sent successfully");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004663 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004664
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004665fail:
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004666 nlmsg_free(msg);
4667 return ret;
4668}
4669
4670
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004671static int nl80211_connect_common(struct wpa_driver_nl80211_data *drv,
4672 struct wpa_driver_associate_params *params,
4673 struct nl_msg *msg)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004674{
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004675 if (params->bssid) {
4676 wpa_printf(MSG_DEBUG, " * bssid=" MACSTR,
4677 MAC2STR(params->bssid));
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004678 if (nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, params->bssid))
4679 return -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004680 }
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004681
Dmitry Shmidt96be6222014-02-13 10:16:51 -08004682 if (params->bssid_hint) {
4683 wpa_printf(MSG_DEBUG, " * bssid_hint=" MACSTR,
4684 MAC2STR(params->bssid_hint));
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004685 if (nla_put(msg, NL80211_ATTR_MAC_HINT, ETH_ALEN,
4686 params->bssid_hint))
4687 return -1;
Dmitry Shmidt96be6222014-02-13 10:16:51 -08004688 }
4689
Dmitry Shmidt9ead16e2014-10-07 13:15:23 -07004690 if (params->freq.freq) {
4691 wpa_printf(MSG_DEBUG, " * freq=%d", params->freq.freq);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004692 if (nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ,
4693 params->freq.freq))
4694 return -1;
Dmitry Shmidt9ead16e2014-10-07 13:15:23 -07004695 drv->assoc_freq = params->freq.freq;
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -07004696 } else
4697 drv->assoc_freq = 0;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004698
Dmitry Shmidt96be6222014-02-13 10:16:51 -08004699 if (params->freq_hint) {
4700 wpa_printf(MSG_DEBUG, " * freq_hint=%d", params->freq_hint);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004701 if (nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ_HINT,
4702 params->freq_hint))
4703 return -1;
Dmitry Shmidt96be6222014-02-13 10:16:51 -08004704 }
4705
Dmitry Shmidt04949592012-07-19 12:16:46 -07004706 if (params->bg_scan_period >= 0) {
4707 wpa_printf(MSG_DEBUG, " * bg scan period=%d",
4708 params->bg_scan_period);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004709 if (nla_put_u16(msg, NL80211_ATTR_BG_SCAN_PERIOD,
4710 params->bg_scan_period))
4711 return -1;
Dmitry Shmidt04949592012-07-19 12:16:46 -07004712 }
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004713
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004714 if (params->ssid) {
4715 wpa_hexdump_ascii(MSG_DEBUG, " * SSID",
4716 params->ssid, params->ssid_len);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004717 if (nla_put(msg, NL80211_ATTR_SSID, params->ssid_len,
4718 params->ssid))
4719 return -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004720 if (params->ssid_len > sizeof(drv->ssid))
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004721 return -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004722 os_memcpy(drv->ssid, params->ssid, params->ssid_len);
4723 drv->ssid_len = params->ssid_len;
4724 }
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004725
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004726 wpa_hexdump(MSG_DEBUG, " * IEs", params->wpa_ie, params->wpa_ie_len);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004727 if (params->wpa_ie &&
4728 nla_put(msg, NL80211_ATTR_IE, params->wpa_ie_len, params->wpa_ie))
4729 return -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004730
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004731 if (params->wpa_proto) {
4732 enum nl80211_wpa_versions ver = 0;
4733
4734 if (params->wpa_proto & WPA_PROTO_WPA)
4735 ver |= NL80211_WPA_VERSION_1;
4736 if (params->wpa_proto & WPA_PROTO_RSN)
4737 ver |= NL80211_WPA_VERSION_2;
4738
4739 wpa_printf(MSG_DEBUG, " * WPA Versions 0x%x", ver);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004740 if (nla_put_u32(msg, NL80211_ATTR_WPA_VERSIONS, ver))
4741 return -1;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004742 }
4743
4744 if (params->pairwise_suite != WPA_CIPHER_NONE) {
4745 u32 cipher = wpa_cipher_to_cipher_suite(params->pairwise_suite);
4746 wpa_printf(MSG_DEBUG, " * pairwise=0x%x", cipher);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004747 if (nla_put_u32(msg, NL80211_ATTR_CIPHER_SUITES_PAIRWISE,
4748 cipher))
4749 return -1;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004750 }
4751
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08004752 if (params->group_suite == WPA_CIPHER_GTK_NOT_USED &&
4753 !(drv->capa.enc & WPA_DRIVER_CAPA_ENC_GTK_NOT_USED)) {
4754 /*
4755 * This is likely to work even though many drivers do not
4756 * advertise support for operations without GTK.
4757 */
4758 wpa_printf(MSG_DEBUG, " * skip group cipher configuration for GTK_NOT_USED due to missing driver support advertisement");
4759 } else if (params->group_suite != WPA_CIPHER_NONE) {
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004760 u32 cipher = wpa_cipher_to_cipher_suite(params->group_suite);
4761 wpa_printf(MSG_DEBUG, " * group=0x%x", cipher);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004762 if (nla_put_u32(msg, NL80211_ATTR_CIPHER_SUITE_GROUP, cipher))
4763 return -1;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004764 }
4765
4766 if (params->key_mgmt_suite == WPA_KEY_MGMT_IEEE8021X ||
4767 params->key_mgmt_suite == WPA_KEY_MGMT_PSK ||
4768 params->key_mgmt_suite == WPA_KEY_MGMT_FT_IEEE8021X ||
4769 params->key_mgmt_suite == WPA_KEY_MGMT_FT_PSK ||
Dmitry Shmidt15907092014-03-25 10:42:57 -07004770 params->key_mgmt_suite == WPA_KEY_MGMT_CCKM ||
Dmitry Shmidt3c57b3f2014-05-22 15:13:07 -07004771 params->key_mgmt_suite == WPA_KEY_MGMT_OSEN ||
4772 params->key_mgmt_suite == WPA_KEY_MGMT_IEEE8021X_SHA256 ||
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004773 params->key_mgmt_suite == WPA_KEY_MGMT_PSK_SHA256 ||
Dmitry Shmidt807291d2015-01-27 13:40:23 -08004774 params->key_mgmt_suite == WPA_KEY_MGMT_IEEE8021X_SUITE_B ||
4775 params->key_mgmt_suite == WPA_KEY_MGMT_IEEE8021X_SUITE_B_192) {
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004776 int mgmt = WLAN_AKM_SUITE_PSK;
4777
4778 switch (params->key_mgmt_suite) {
4779 case WPA_KEY_MGMT_CCKM:
4780 mgmt = WLAN_AKM_SUITE_CCKM;
4781 break;
4782 case WPA_KEY_MGMT_IEEE8021X:
4783 mgmt = WLAN_AKM_SUITE_8021X;
4784 break;
4785 case WPA_KEY_MGMT_FT_IEEE8021X:
4786 mgmt = WLAN_AKM_SUITE_FT_8021X;
4787 break;
4788 case WPA_KEY_MGMT_FT_PSK:
4789 mgmt = WLAN_AKM_SUITE_FT_PSK;
4790 break;
Dmitry Shmidt3c57b3f2014-05-22 15:13:07 -07004791 case WPA_KEY_MGMT_IEEE8021X_SHA256:
4792 mgmt = WLAN_AKM_SUITE_8021X_SHA256;
4793 break;
4794 case WPA_KEY_MGMT_PSK_SHA256:
4795 mgmt = WLAN_AKM_SUITE_PSK_SHA256;
4796 break;
Dmitry Shmidt15907092014-03-25 10:42:57 -07004797 case WPA_KEY_MGMT_OSEN:
4798 mgmt = WLAN_AKM_SUITE_OSEN;
4799 break;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004800 case WPA_KEY_MGMT_IEEE8021X_SUITE_B:
4801 mgmt = WLAN_AKM_SUITE_8021X_SUITE_B;
4802 break;
Dmitry Shmidt807291d2015-01-27 13:40:23 -08004803 case WPA_KEY_MGMT_IEEE8021X_SUITE_B_192:
4804 mgmt = WLAN_AKM_SUITE_8021X_SUITE_B_192;
4805 break;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004806 case WPA_KEY_MGMT_PSK:
4807 default:
4808 mgmt = WLAN_AKM_SUITE_PSK;
4809 break;
4810 }
Dmitry Shmidt15907092014-03-25 10:42:57 -07004811 wpa_printf(MSG_DEBUG, " * akm=0x%x", mgmt);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004812 if (nla_put_u32(msg, NL80211_ATTR_AKM_SUITES, mgmt))
4813 return -1;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004814 }
4815
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004816 if (nla_put_flag(msg, NL80211_ATTR_CONTROL_PORT))
4817 return -1;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004818
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004819 if (params->mgmt_frame_protection == MGMT_FRAME_PROTECTION_REQUIRED &&
4820 nla_put_u32(msg, NL80211_ATTR_USE_MFP, NL80211_MFP_REQUIRED))
4821 return -1;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004822
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004823 if (params->rrm_used) {
4824 u32 drv_rrm_flags = drv->capa.rrm_flags;
4825 if (!(drv_rrm_flags &
4826 WPA_DRIVER_FLAGS_DS_PARAM_SET_IE_IN_PROBES) ||
4827 !(drv_rrm_flags & WPA_DRIVER_FLAGS_QUIET) ||
4828 nla_put_flag(msg, NL80211_ATTR_USE_RRM))
4829 return -1;
4830 }
4831
Dmitry Shmidt2f74e362015-01-21 13:19:05 -08004832 if (nl80211_ht_vht_overrides(msg, params) < 0)
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004833 return -1;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004834
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004835 if (params->p2p)
4836 wpa_printf(MSG_DEBUG, " * P2P group");
4837
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08004838 if (params->pbss) {
4839 wpa_printf(MSG_DEBUG, " * PBSS");
4840 if (nla_put_flag(msg, NL80211_ATTR_PBSS))
4841 return -1;
4842 }
4843
Dmitry Shmidte4663042016-04-04 10:07:49 -07004844 drv->connect_reassoc = 0;
4845 if (params->prev_bssid) {
4846 wpa_printf(MSG_DEBUG, " * prev_bssid=" MACSTR,
4847 MAC2STR(params->prev_bssid));
4848 if (nla_put(msg, NL80211_ATTR_PREV_BSSID, ETH_ALEN,
4849 params->prev_bssid))
4850 return -1;
4851 drv->connect_reassoc = 1;
4852 }
4853
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004854 return 0;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004855}
4856
4857
4858static int wpa_driver_nl80211_try_connect(
4859 struct wpa_driver_nl80211_data *drv,
4860 struct wpa_driver_associate_params *params)
4861{
4862 struct nl_msg *msg;
4863 enum nl80211_auth_type type;
4864 int ret;
4865 int algs;
4866
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08004867#ifdef CONFIG_DRIVER_NL80211_QCA
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004868 if (params->req_key_mgmt_offload && params->psk &&
4869 (params->key_mgmt_suite == WPA_KEY_MGMT_PSK ||
4870 params->key_mgmt_suite == WPA_KEY_MGMT_PSK_SHA256 ||
4871 params->key_mgmt_suite == WPA_KEY_MGMT_FT_PSK)) {
4872 wpa_printf(MSG_DEBUG, "nl80211: Key management set PSK");
4873 ret = issue_key_mgmt_set_key(drv, params->psk, 32);
4874 if (ret)
4875 return ret;
4876 }
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08004877#endif /* CONFIG_DRIVER_NL80211_QCA */
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004878
4879 wpa_printf(MSG_DEBUG, "nl80211: Connect (ifindex=%d)", drv->ifindex);
4880 msg = nl80211_drv_msg(drv, 0, NL80211_CMD_CONNECT);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004881 if (!msg)
4882 return -1;
4883
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004884 ret = nl80211_connect_common(drv, params, msg);
4885 if (ret)
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004886 goto fail;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004887
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004888 algs = 0;
4889 if (params->auth_alg & WPA_AUTH_ALG_OPEN)
4890 algs++;
4891 if (params->auth_alg & WPA_AUTH_ALG_SHARED)
4892 algs++;
4893 if (params->auth_alg & WPA_AUTH_ALG_LEAP)
4894 algs++;
4895 if (algs > 1) {
4896 wpa_printf(MSG_DEBUG, " * Leave out Auth Type for automatic "
4897 "selection");
4898 goto skip_auth_type;
4899 }
4900
4901 if (params->auth_alg & WPA_AUTH_ALG_OPEN)
4902 type = NL80211_AUTHTYPE_OPEN_SYSTEM;
4903 else if (params->auth_alg & WPA_AUTH_ALG_SHARED)
4904 type = NL80211_AUTHTYPE_SHARED_KEY;
4905 else if (params->auth_alg & WPA_AUTH_ALG_LEAP)
4906 type = NL80211_AUTHTYPE_NETWORK_EAP;
4907 else if (params->auth_alg & WPA_AUTH_ALG_FT)
4908 type = NL80211_AUTHTYPE_FT;
4909 else
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004910 goto fail;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004911
4912 wpa_printf(MSG_DEBUG, " * Auth Type %d", type);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004913 if (nla_put_u32(msg, NL80211_ATTR_AUTH_TYPE, type))
4914 goto fail;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004915
4916skip_auth_type:
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004917 ret = nl80211_set_conn_keys(params, msg);
4918 if (ret)
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004919 goto fail;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004920
4921 ret = send_and_recv_msgs(drv, msg, NULL, NULL);
4922 msg = NULL;
4923 if (ret) {
4924 wpa_printf(MSG_DEBUG, "nl80211: MLME connect failed: ret=%d "
4925 "(%s)", ret, strerror(-ret));
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004926 } else {
4927 wpa_printf(MSG_DEBUG,
4928 "nl80211: Connect request send successfully");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004929 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004930
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004931fail:
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004932 nlmsg_free(msg);
4933 return ret;
4934
4935}
4936
4937
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08004938static int wpa_driver_nl80211_connect(
4939 struct wpa_driver_nl80211_data *drv,
4940 struct wpa_driver_associate_params *params)
4941{
Jithu Jancea7c60b42014-12-03 18:54:40 +05304942 int ret;
4943
4944 /* Store the connection attempted bssid for future use */
4945 if (params->bssid)
4946 os_memcpy(drv->auth_attempt_bssid, params->bssid, ETH_ALEN);
4947 else
4948 os_memset(drv->auth_attempt_bssid, 0, ETH_ALEN);
4949
4950 ret = wpa_driver_nl80211_try_connect(drv, params);
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08004951 if (ret == -EALREADY) {
4952 /*
4953 * cfg80211 does not currently accept new connections if
4954 * we are already connected. As a workaround, force
4955 * disconnection and try again.
4956 */
4957 wpa_printf(MSG_DEBUG, "nl80211: Explicitly "
4958 "disconnecting before reassociation "
4959 "attempt");
4960 if (wpa_driver_nl80211_disconnect(
4961 drv, WLAN_REASON_PREV_AUTH_NOT_VALID))
4962 return -1;
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08004963 ret = wpa_driver_nl80211_try_connect(drv, params);
4964 }
4965 return ret;
4966}
4967
4968
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004969static int wpa_driver_nl80211_associate(
4970 void *priv, struct wpa_driver_associate_params *params)
4971{
4972 struct i802_bss *bss = priv;
4973 struct wpa_driver_nl80211_data *drv = bss->drv;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004974 int ret = -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004975 struct nl_msg *msg;
4976
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004977 nl80211_unmask_11b_rates(bss);
4978
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004979 if (params->mode == IEEE80211_MODE_AP)
4980 return wpa_driver_nl80211_ap(drv, params);
4981
4982 if (params->mode == IEEE80211_MODE_IBSS)
4983 return wpa_driver_nl80211_ibss(drv, params);
4984
4985 if (!(drv->capa.flags & WPA_DRIVER_FLAGS_SME)) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004986 enum nl80211_iftype nlmode = params->p2p ?
4987 NL80211_IFTYPE_P2P_CLIENT : NL80211_IFTYPE_STATION;
4988
4989 if (wpa_driver_nl80211_set_mode(priv, nlmode) < 0)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004990 return -1;
4991 return wpa_driver_nl80211_connect(drv, params);
4992 }
4993
Dmitry Shmidt8bae4132013-06-06 11:25:10 -07004994 nl80211_mark_disconnected(drv);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004995
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004996 wpa_printf(MSG_DEBUG, "nl80211: Associate (ifindex=%d)",
4997 drv->ifindex);
4998 msg = nl80211_drv_msg(drv, 0, NL80211_CMD_ASSOCIATE);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004999 if (!msg)
5000 return -1;
5001
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08005002 ret = nl80211_connect_common(drv, params, msg);
5003 if (ret)
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005004 goto fail;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005005
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005006 ret = send_and_recv_msgs(drv, msg, NULL, NULL);
5007 msg = NULL;
5008 if (ret) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005009 wpa_dbg(drv->ctx, MSG_DEBUG,
5010 "nl80211: MLME command failed (assoc): ret=%d (%s)",
5011 ret, strerror(-ret));
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005012 nl80211_dump_scan(drv);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005013 } else {
5014 wpa_printf(MSG_DEBUG,
5015 "nl80211: Association request send successfully");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005016 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005017
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005018fail:
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005019 nlmsg_free(msg);
5020 return ret;
5021}
5022
5023
5024static int nl80211_set_mode(struct wpa_driver_nl80211_data *drv,
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005025 int ifindex, enum nl80211_iftype mode)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005026{
5027 struct nl_msg *msg;
5028 int ret = -ENOBUFS;
5029
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005030 wpa_printf(MSG_DEBUG, "nl80211: Set mode ifindex %d iftype %d (%s)",
5031 ifindex, mode, nl80211_iftype_str(mode));
5032
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005033 msg = nl80211_cmd_msg(drv->first_bss, 0, NL80211_CMD_SET_INTERFACE);
5034 if (!msg || nla_put_u32(msg, NL80211_ATTR_IFTYPE, mode))
5035 goto fail;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005036
5037 ret = send_and_recv_msgs(drv, msg, NULL, NULL);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005038 msg = NULL;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005039 if (!ret)
5040 return 0;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005041fail:
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005042 nlmsg_free(msg);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005043 wpa_printf(MSG_DEBUG, "nl80211: Failed to set interface %d to mode %d:"
5044 " %d (%s)", ifindex, mode, ret, strerror(-ret));
5045 return ret;
5046}
5047
5048
Dmitry Shmidtd30ac602014-06-30 09:54:22 -07005049static int wpa_driver_nl80211_set_mode_impl(
5050 struct i802_bss *bss,
5051 enum nl80211_iftype nlmode,
5052 struct hostapd_freq_params *desired_freq_params)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005053{
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005054 struct wpa_driver_nl80211_data *drv = bss->drv;
5055 int ret = -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005056 int i;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005057 int was_ap = is_ap_interface(drv->nlmode);
5058 int res;
Dmitry Shmidtd30ac602014-06-30 09:54:22 -07005059 int mode_switch_res;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005060
Dmitry Shmidtd30ac602014-06-30 09:54:22 -07005061 mode_switch_res = nl80211_set_mode(drv, drv->ifindex, nlmode);
5062 if (mode_switch_res && nlmode == nl80211_get_ifmode(bss))
5063 mode_switch_res = 0;
Dmitry Shmidt34af3062013-07-11 10:46:32 -07005064
Dmitry Shmidtd30ac602014-06-30 09:54:22 -07005065 if (mode_switch_res == 0) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005066 drv->nlmode = nlmode;
5067 ret = 0;
5068 goto done;
5069 }
5070
Dmitry Shmidtd30ac602014-06-30 09:54:22 -07005071 if (mode_switch_res == -ENODEV)
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005072 return -1;
5073
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005074 if (nlmode == drv->nlmode) {
5075 wpa_printf(MSG_DEBUG, "nl80211: Interface already in "
5076 "requested mode - ignore error");
5077 ret = 0;
5078 goto done; /* Already in the requested mode */
5079 }
5080
5081 /* mac80211 doesn't allow mode changes while the device is up, so
5082 * take the device down, try to set the mode again, and bring the
5083 * device back up.
5084 */
5085 wpa_printf(MSG_DEBUG, "nl80211: Try mode change after setting "
5086 "interface down");
5087 for (i = 0; i < 10; i++) {
Dmitry Shmidt34af3062013-07-11 10:46:32 -07005088 res = i802_set_iface_flags(bss, 0);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005089 if (res == -EACCES || res == -ENODEV)
5090 break;
Dmitry Shmidtd30ac602014-06-30 09:54:22 -07005091 if (res != 0) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005092 wpa_printf(MSG_DEBUG, "nl80211: Failed to set "
5093 "interface down");
Dmitry Shmidtd30ac602014-06-30 09:54:22 -07005094 os_sleep(0, 100000);
5095 continue;
5096 }
5097
5098 /*
5099 * Setting the mode will fail for some drivers if the phy is
5100 * on a frequency that the mode is disallowed in.
5101 */
5102 if (desired_freq_params) {
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005103 res = nl80211_set_channel(bss, desired_freq_params, 0);
Dmitry Shmidtd30ac602014-06-30 09:54:22 -07005104 if (res) {
5105 wpa_printf(MSG_DEBUG,
5106 "nl80211: Failed to set frequency on interface");
5107 }
5108 }
5109
5110 /* Try to set the mode again while the interface is down */
5111 mode_switch_res = nl80211_set_mode(drv, drv->ifindex, nlmode);
5112 if (mode_switch_res == -EBUSY) {
5113 wpa_printf(MSG_DEBUG,
5114 "nl80211: Delaying mode set while interface going down");
5115 os_sleep(0, 100000);
5116 continue;
5117 }
5118 ret = mode_switch_res;
5119 break;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005120 }
5121
5122 if (!ret) {
5123 wpa_printf(MSG_DEBUG, "nl80211: Mode change succeeded while "
5124 "interface is down");
5125 drv->nlmode = nlmode;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005126 drv->ignore_if_down_event = 1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005127 }
5128
Dmitry Shmidtd30ac602014-06-30 09:54:22 -07005129 /* Bring the interface back up */
5130 res = linux_set_iface_flags(drv->global->ioctl_sock, bss->ifname, 1);
5131 if (res != 0) {
5132 wpa_printf(MSG_DEBUG,
5133 "nl80211: Failed to set interface up after switching mode");
5134 ret = -1;
5135 }
5136
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005137done:
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005138 if (ret) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005139 wpa_printf(MSG_DEBUG, "nl80211: Interface mode change to %d "
5140 "from %d failed", nlmode, drv->nlmode);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005141 return ret;
5142 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005143
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005144 if (is_p2p_net_interface(nlmode)) {
5145 wpa_printf(MSG_DEBUG,
5146 "nl80211: Interface %s mode change to P2P - disable 11b rates",
5147 bss->ifname);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07005148 nl80211_disable_11b_rates(drv, drv->ifindex, 1);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005149 } else if (drv->disabled_11b_rates) {
5150 wpa_printf(MSG_DEBUG,
5151 "nl80211: Interface %s mode changed to non-P2P - re-enable 11b rates",
5152 bss->ifname);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07005153 nl80211_disable_11b_rates(drv, drv->ifindex, 0);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005154 }
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07005155
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005156 if (is_ap_interface(nlmode)) {
5157 nl80211_mgmt_unsubscribe(bss, "start AP");
5158 /* Setup additional AP mode functionality if needed */
5159 if (nl80211_setup_ap(bss))
5160 return -1;
5161 } else if (was_ap) {
5162 /* Remove additional AP mode functionality */
5163 nl80211_teardown_ap(bss);
5164 } else {
5165 nl80211_mgmt_unsubscribe(bss, "mode change");
5166 }
5167
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005168 if (is_mesh_interface(nlmode) &&
5169 nl80211_mgmt_subscribe_mesh(bss))
5170 return -1;
5171
Dmitry Shmidt04949592012-07-19 12:16:46 -07005172 if (!bss->in_deinit && !is_ap_interface(nlmode) &&
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005173 !is_mesh_interface(nlmode) &&
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005174 nl80211_mgmt_subscribe_non_ap(bss) < 0)
5175 wpa_printf(MSG_DEBUG, "nl80211: Failed to register Action "
5176 "frame processing - ignore for now");
5177
5178 return 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005179}
5180
5181
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005182int wpa_driver_nl80211_set_mode(struct i802_bss *bss,
5183 enum nl80211_iftype nlmode)
Dmitry Shmidtd30ac602014-06-30 09:54:22 -07005184{
5185 return wpa_driver_nl80211_set_mode_impl(bss, nlmode, NULL);
5186}
5187
5188
Dmitry Shmidt9ead16e2014-10-07 13:15:23 -07005189static int wpa_driver_nl80211_set_mode_ibss(struct i802_bss *bss,
5190 struct hostapd_freq_params *freq)
Dmitry Shmidtd30ac602014-06-30 09:54:22 -07005191{
Dmitry Shmidtd30ac602014-06-30 09:54:22 -07005192 return wpa_driver_nl80211_set_mode_impl(bss, NL80211_IFTYPE_ADHOC,
Dmitry Shmidt9ead16e2014-10-07 13:15:23 -07005193 freq);
Dmitry Shmidtd30ac602014-06-30 09:54:22 -07005194}
5195
5196
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005197static int wpa_driver_nl80211_get_capa(void *priv,
5198 struct wpa_driver_capa *capa)
5199{
5200 struct i802_bss *bss = priv;
5201 struct wpa_driver_nl80211_data *drv = bss->drv;
Dmitry Shmidtd11f0192014-03-24 12:09:47 -07005202
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005203 if (!drv->has_capability)
5204 return -1;
5205 os_memcpy(capa, &drv->capa, sizeof(*capa));
Dmitry Shmidt444d5672013-04-01 13:08:44 -07005206 if (drv->extended_capa && drv->extended_capa_mask) {
5207 capa->extended_capa = drv->extended_capa;
5208 capa->extended_capa_mask = drv->extended_capa_mask;
5209 capa->extended_capa_len = drv->extended_capa_len;
5210 }
Dmitry Shmidt34af3062013-07-11 10:46:32 -07005211
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005212 return 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005213}
5214
5215
5216static int wpa_driver_nl80211_set_operstate(void *priv, int state)
5217{
5218 struct i802_bss *bss = priv;
5219 struct wpa_driver_nl80211_data *drv = bss->drv;
5220
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08005221 wpa_printf(MSG_DEBUG, "nl80211: Set %s operstate %d->%d (%s)",
5222 bss->ifname, drv->operstate, state,
5223 state ? "UP" : "DORMANT");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005224 drv->operstate = state;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005225 return netlink_send_oper_ifla(drv->global->netlink, drv->ifindex, -1,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005226 state ? IF_OPER_UP : IF_OPER_DORMANT);
5227}
5228
5229
5230static int wpa_driver_nl80211_set_supp_port(void *priv, int authorized)
5231{
5232 struct i802_bss *bss = priv;
5233 struct wpa_driver_nl80211_data *drv = bss->drv;
5234 struct nl_msg *msg;
5235 struct nl80211_sta_flag_update upd;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005236 int ret;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08005237
5238 if (!drv->associated && is_zero_ether_addr(drv->bssid) && !authorized) {
5239 wpa_printf(MSG_DEBUG, "nl80211: Skip set_supp_port(unauthorized) while not associated");
5240 return 0;
5241 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005242
Dmitry Shmidt8bae4132013-06-06 11:25:10 -07005243 wpa_printf(MSG_DEBUG, "nl80211: Set supplicant port %sauthorized for "
5244 MACSTR, authorized ? "" : "un", MAC2STR(drv->bssid));
5245
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005246 os_memset(&upd, 0, sizeof(upd));
5247 upd.mask = BIT(NL80211_STA_FLAG_AUTHORIZED);
5248 if (authorized)
5249 upd.set = BIT(NL80211_STA_FLAG_AUTHORIZED);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005250
5251 if (!(msg = nl80211_bss_msg(bss, 0, NL80211_CMD_SET_STATION)) ||
5252 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, drv->bssid) ||
5253 nla_put(msg, NL80211_ATTR_STA_FLAGS2, sizeof(upd), &upd)) {
5254 nlmsg_free(msg);
5255 return -ENOBUFS;
5256 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005257
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08005258 ret = send_and_recv_msgs(drv, msg, NULL, NULL);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08005259 if (!ret)
5260 return 0;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08005261 wpa_printf(MSG_DEBUG, "nl80211: Failed to set STA flag: %d (%s)",
5262 ret, strerror(-ret));
5263 return ret;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005264}
5265
5266
Jouni Malinen75ecf522011-06-27 15:19:46 -07005267/* Set kernel driver on given frequency (MHz) */
5268static int i802_set_freq(void *priv, struct hostapd_freq_params *freq)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005269{
Jouni Malinen75ecf522011-06-27 15:19:46 -07005270 struct i802_bss *bss = priv;
Dmitry Shmidt7832adb2014-04-29 10:53:02 -07005271 return nl80211_set_channel(bss, freq, 0);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005272}
5273
5274
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005275static inline int min_int(int a, int b)
5276{
5277 if (a < b)
5278 return a;
5279 return b;
5280}
5281
5282
5283static int get_key_handler(struct nl_msg *msg, void *arg)
5284{
5285 struct nlattr *tb[NL80211_ATTR_MAX + 1];
5286 struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg));
5287
5288 nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0),
5289 genlmsg_attrlen(gnlh, 0), NULL);
5290
5291 /*
5292 * TODO: validate the key index and mac address!
5293 * Otherwise, there's a race condition as soon as
5294 * the kernel starts sending key notifications.
5295 */
5296
5297 if (tb[NL80211_ATTR_KEY_SEQ])
5298 memcpy(arg, nla_data(tb[NL80211_ATTR_KEY_SEQ]),
5299 min_int(nla_len(tb[NL80211_ATTR_KEY_SEQ]), 6));
5300 return NL_SKIP;
5301}
5302
5303
5304static int i802_get_seqnum(const char *iface, void *priv, const u8 *addr,
5305 int idx, u8 *seq)
5306{
5307 struct i802_bss *bss = priv;
5308 struct wpa_driver_nl80211_data *drv = bss->drv;
5309 struct nl_msg *msg;
5310
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005311 msg = nl80211_ifindex_msg(drv, if_nametoindex(iface), 0,
5312 NL80211_CMD_GET_KEY);
5313 if (!msg ||
5314 (addr && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) ||
5315 nla_put_u8(msg, NL80211_ATTR_KEY_IDX, idx)) {
5316 nlmsg_free(msg);
5317 return -ENOBUFS;
5318 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005319
5320 memset(seq, 0, 6);
5321
5322 return send_and_recv_msgs(drv, msg, get_key_handler, seq);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005323}
5324
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005325
5326static int i802_set_rts(void *priv, int rts)
5327{
5328 struct i802_bss *bss = priv;
5329 struct wpa_driver_nl80211_data *drv = bss->drv;
5330 struct nl_msg *msg;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005331 int ret;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005332 u32 val;
5333
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005334 if (rts >= 2347)
5335 val = (u32) -1;
5336 else
5337 val = rts;
5338
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005339 if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_SET_WIPHY)) ||
5340 nla_put_u32(msg, NL80211_ATTR_WIPHY_RTS_THRESHOLD, val)) {
5341 nlmsg_free(msg);
5342 return -ENOBUFS;
5343 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005344
5345 ret = send_and_recv_msgs(drv, msg, NULL, NULL);
5346 if (!ret)
5347 return 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005348 wpa_printf(MSG_DEBUG, "nl80211: Failed to set RTS threshold %d: "
5349 "%d (%s)", rts, ret, strerror(-ret));
5350 return ret;
5351}
5352
5353
5354static int i802_set_frag(void *priv, int frag)
5355{
5356 struct i802_bss *bss = priv;
5357 struct wpa_driver_nl80211_data *drv = bss->drv;
5358 struct nl_msg *msg;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005359 int ret;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005360 u32 val;
5361
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005362 if (frag >= 2346)
5363 val = (u32) -1;
5364 else
5365 val = frag;
5366
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005367 if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_SET_WIPHY)) ||
5368 nla_put_u32(msg, NL80211_ATTR_WIPHY_FRAG_THRESHOLD, val)) {
5369 nlmsg_free(msg);
5370 return -ENOBUFS;
5371 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005372
5373 ret = send_and_recv_msgs(drv, msg, NULL, NULL);
5374 if (!ret)
5375 return 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005376 wpa_printf(MSG_DEBUG, "nl80211: Failed to set fragmentation threshold "
5377 "%d: %d (%s)", frag, ret, strerror(-ret));
5378 return ret;
5379}
5380
5381
5382static int i802_flush(void *priv)
5383{
5384 struct i802_bss *bss = priv;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005385 struct nl_msg *msg;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005386 int res;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005387
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -07005388 wpa_printf(MSG_DEBUG, "nl80211: flush -> DEL_STATION %s (all)",
5389 bss->ifname);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005390
5391 /*
5392 * XXX: FIX! this needs to flush all VLANs too
5393 */
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005394 msg = nl80211_bss_msg(bss, 0, NL80211_CMD_DEL_STATION);
5395 res = send_and_recv_msgs(bss->drv, msg, NULL, NULL);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005396 if (res) {
5397 wpa_printf(MSG_DEBUG, "nl80211: Station flush failed: ret=%d "
5398 "(%s)", res, strerror(-res));
5399 }
5400 return res;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005401}
5402
5403
5404static int get_sta_handler(struct nl_msg *msg, void *arg)
5405{
5406 struct nlattr *tb[NL80211_ATTR_MAX + 1];
5407 struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg));
5408 struct hostap_sta_driver_data *data = arg;
5409 struct nlattr *stats[NL80211_STA_INFO_MAX + 1];
5410 static struct nla_policy stats_policy[NL80211_STA_INFO_MAX + 1] = {
5411 [NL80211_STA_INFO_INACTIVE_TIME] = { .type = NLA_U32 },
5412 [NL80211_STA_INFO_RX_BYTES] = { .type = NLA_U32 },
5413 [NL80211_STA_INFO_TX_BYTES] = { .type = NLA_U32 },
5414 [NL80211_STA_INFO_RX_PACKETS] = { .type = NLA_U32 },
5415 [NL80211_STA_INFO_TX_PACKETS] = { .type = NLA_U32 },
Jouni Malinen1e6c57f2012-09-05 17:07:03 +03005416 [NL80211_STA_INFO_TX_FAILED] = { .type = NLA_U32 },
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08005417 [NL80211_STA_INFO_RX_BYTES64] = { .type = NLA_U64 },
5418 [NL80211_STA_INFO_TX_BYTES64] = { .type = NLA_U64 },
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005419 };
5420
5421 nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0),
5422 genlmsg_attrlen(gnlh, 0), NULL);
5423
5424 /*
5425 * TODO: validate the interface and mac address!
5426 * Otherwise, there's a race condition as soon as
5427 * the kernel starts sending station notifications.
5428 */
5429
5430 if (!tb[NL80211_ATTR_STA_INFO]) {
5431 wpa_printf(MSG_DEBUG, "sta stats missing!");
5432 return NL_SKIP;
5433 }
5434 if (nla_parse_nested(stats, NL80211_STA_INFO_MAX,
5435 tb[NL80211_ATTR_STA_INFO],
5436 stats_policy)) {
5437 wpa_printf(MSG_DEBUG, "failed to parse nested attributes!");
5438 return NL_SKIP;
5439 }
5440
5441 if (stats[NL80211_STA_INFO_INACTIVE_TIME])
5442 data->inactive_msec =
5443 nla_get_u32(stats[NL80211_STA_INFO_INACTIVE_TIME]);
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08005444 /* For backwards compatibility, fetch the 32-bit counters first. */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005445 if (stats[NL80211_STA_INFO_RX_BYTES])
5446 data->rx_bytes = nla_get_u32(stats[NL80211_STA_INFO_RX_BYTES]);
5447 if (stats[NL80211_STA_INFO_TX_BYTES])
5448 data->tx_bytes = nla_get_u32(stats[NL80211_STA_INFO_TX_BYTES]);
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08005449 if (stats[NL80211_STA_INFO_RX_BYTES64] &&
5450 stats[NL80211_STA_INFO_TX_BYTES64]) {
5451 /*
5452 * The driver supports 64-bit counters, so use them to override
5453 * the 32-bit values.
5454 */
5455 data->rx_bytes =
5456 nla_get_u64(stats[NL80211_STA_INFO_RX_BYTES64]);
5457 data->tx_bytes =
5458 nla_get_u64(stats[NL80211_STA_INFO_TX_BYTES64]);
5459 data->bytes_64bit = 1;
5460 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005461 if (stats[NL80211_STA_INFO_RX_PACKETS])
5462 data->rx_packets =
5463 nla_get_u32(stats[NL80211_STA_INFO_RX_PACKETS]);
5464 if (stats[NL80211_STA_INFO_TX_PACKETS])
5465 data->tx_packets =
5466 nla_get_u32(stats[NL80211_STA_INFO_TX_PACKETS]);
Jouni Malinen1e6c57f2012-09-05 17:07:03 +03005467 if (stats[NL80211_STA_INFO_TX_FAILED])
5468 data->tx_retry_failed =
5469 nla_get_u32(stats[NL80211_STA_INFO_TX_FAILED]);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005470
5471 return NL_SKIP;
5472}
5473
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08005474static int i802_read_sta_data(struct i802_bss *bss,
5475 struct hostap_sta_driver_data *data,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005476 const u8 *addr)
5477{
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005478 struct nl_msg *msg;
5479
5480 os_memset(data, 0, sizeof(*data));
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005481
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005482 if (!(msg = nl80211_bss_msg(bss, 0, NL80211_CMD_GET_STATION)) ||
5483 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) {
5484 nlmsg_free(msg);
5485 return -ENOBUFS;
5486 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005487
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005488 return send_and_recv_msgs(bss->drv, msg, get_sta_handler, data);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005489}
5490
5491
5492static int i802_set_tx_queue_params(void *priv, int queue, int aifs,
5493 int cw_min, int cw_max, int burst_time)
5494{
5495 struct i802_bss *bss = priv;
5496 struct wpa_driver_nl80211_data *drv = bss->drv;
5497 struct nl_msg *msg;
5498 struct nlattr *txq, *params;
5499
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005500 msg = nl80211_bss_msg(bss, 0, NL80211_CMD_SET_WIPHY);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005501 if (!msg)
5502 return -1;
5503
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005504 txq = nla_nest_start(msg, NL80211_ATTR_WIPHY_TXQ_PARAMS);
5505 if (!txq)
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005506 goto fail;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005507
5508 /* We are only sending parameters for a single TXQ at a time */
5509 params = nla_nest_start(msg, 1);
5510 if (!params)
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005511 goto fail;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005512
5513 switch (queue) {
5514 case 0:
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005515 if (nla_put_u8(msg, NL80211_TXQ_ATTR_QUEUE, NL80211_TXQ_Q_VO))
5516 goto fail;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005517 break;
5518 case 1:
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005519 if (nla_put_u8(msg, NL80211_TXQ_ATTR_QUEUE, NL80211_TXQ_Q_VI))
5520 goto fail;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005521 break;
5522 case 2:
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005523 if (nla_put_u8(msg, NL80211_TXQ_ATTR_QUEUE, NL80211_TXQ_Q_BE))
5524 goto fail;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005525 break;
5526 case 3:
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005527 if (nla_put_u8(msg, NL80211_TXQ_ATTR_QUEUE, NL80211_TXQ_Q_BK))
5528 goto fail;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005529 break;
5530 }
5531 /* Burst time is configured in units of 0.1 msec and TXOP parameter in
5532 * 32 usec, so need to convert the value here. */
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005533 if (nla_put_u16(msg, NL80211_TXQ_ATTR_TXOP,
5534 (burst_time * 100 + 16) / 32) ||
5535 nla_put_u16(msg, NL80211_TXQ_ATTR_CWMIN, cw_min) ||
5536 nla_put_u16(msg, NL80211_TXQ_ATTR_CWMAX, cw_max) ||
5537 nla_put_u8(msg, NL80211_TXQ_ATTR_AIFS, aifs))
5538 goto fail;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005539
5540 nla_nest_end(msg, params);
5541
5542 nla_nest_end(msg, txq);
5543
5544 if (send_and_recv_msgs(drv, msg, NULL, NULL) == 0)
5545 return 0;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005546 msg = NULL;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005547fail:
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005548 nlmsg_free(msg);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005549 return -1;
5550}
5551
5552
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08005553static int i802_set_sta_vlan(struct i802_bss *bss, const u8 *addr,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005554 const char *ifname, int vlan_id)
5555{
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005556 struct wpa_driver_nl80211_data *drv = bss->drv;
5557 struct nl_msg *msg;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005558 int ret;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005559
Dmitry Shmidtcce06662013-11-04 18:44:24 -08005560 wpa_printf(MSG_DEBUG, "nl80211: %s[%d]: set_sta_vlan(" MACSTR
5561 ", ifname=%s[%d], vlan_id=%d)",
5562 bss->ifname, if_nametoindex(bss->ifname),
5563 MAC2STR(addr), ifname, if_nametoindex(ifname), vlan_id);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005564 if (!(msg = nl80211_bss_msg(bss, 0, NL80211_CMD_SET_STATION)) ||
5565 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) ||
5566 nla_put_u32(msg, NL80211_ATTR_STA_VLAN, if_nametoindex(ifname))) {
5567 nlmsg_free(msg);
5568 return -ENOBUFS;
5569 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005570
5571 ret = send_and_recv_msgs(drv, msg, NULL, NULL);
5572 if (ret < 0) {
5573 wpa_printf(MSG_ERROR, "nl80211: NL80211_ATTR_STA_VLAN (addr="
5574 MACSTR " ifname=%s vlan_id=%d) failed: %d (%s)",
5575 MAC2STR(addr), ifname, vlan_id, ret,
5576 strerror(-ret));
5577 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005578 return ret;
5579}
5580
5581
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005582static int i802_get_inact_sec(void *priv, const u8 *addr)
5583{
5584 struct hostap_sta_driver_data data;
5585 int ret;
5586
5587 data.inactive_msec = (unsigned long) -1;
5588 ret = i802_read_sta_data(priv, &data, addr);
Dmitry Shmidt2f74e362015-01-21 13:19:05 -08005589 if (ret == -ENOENT)
5590 return -ENOENT;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005591 if (ret || data.inactive_msec == (unsigned long) -1)
5592 return -1;
5593 return data.inactive_msec / 1000;
5594}
5595
5596
5597static int i802_sta_clear_stats(void *priv, const u8 *addr)
5598{
5599#if 0
5600 /* TODO */
5601#endif
5602 return 0;
5603}
5604
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005605
5606static int i802_sta_deauth(void *priv, const u8 *own_addr, const u8 *addr,
5607 int reason)
5608{
5609 struct i802_bss *bss = priv;
Dmitry Shmidt04949592012-07-19 12:16:46 -07005610 struct wpa_driver_nl80211_data *drv = bss->drv;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005611 struct ieee80211_mgmt mgmt;
5612
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005613 if (is_mesh_interface(drv->nlmode))
5614 return -1;
5615
Dmitry Shmidt04949592012-07-19 12:16:46 -07005616 if (drv->device_ap_sme)
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005617 return wpa_driver_nl80211_sta_remove(bss, addr, 1, reason);
Dmitry Shmidt04949592012-07-19 12:16:46 -07005618
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005619 memset(&mgmt, 0, sizeof(mgmt));
5620 mgmt.frame_control = IEEE80211_FC(WLAN_FC_TYPE_MGMT,
5621 WLAN_FC_STYPE_DEAUTH);
5622 memcpy(mgmt.da, addr, ETH_ALEN);
5623 memcpy(mgmt.sa, own_addr, ETH_ALEN);
5624 memcpy(mgmt.bssid, own_addr, ETH_ALEN);
5625 mgmt.u.deauth.reason_code = host_to_le16(reason);
5626 return wpa_driver_nl80211_send_mlme(bss, (u8 *) &mgmt,
5627 IEEE80211_HDRLEN +
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08005628 sizeof(mgmt.u.deauth), 0, 0, 0, 0,
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08005629 0, NULL, 0);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005630}
5631
5632
5633static int i802_sta_disassoc(void *priv, const u8 *own_addr, const u8 *addr,
5634 int reason)
5635{
5636 struct i802_bss *bss = priv;
Dmitry Shmidt04949592012-07-19 12:16:46 -07005637 struct wpa_driver_nl80211_data *drv = bss->drv;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005638 struct ieee80211_mgmt mgmt;
5639
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005640 if (is_mesh_interface(drv->nlmode))
5641 return -1;
5642
Dmitry Shmidt04949592012-07-19 12:16:46 -07005643 if (drv->device_ap_sme)
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005644 return wpa_driver_nl80211_sta_remove(bss, addr, 0, reason);
Dmitry Shmidt04949592012-07-19 12:16:46 -07005645
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005646 memset(&mgmt, 0, sizeof(mgmt));
5647 mgmt.frame_control = IEEE80211_FC(WLAN_FC_TYPE_MGMT,
5648 WLAN_FC_STYPE_DISASSOC);
5649 memcpy(mgmt.da, addr, ETH_ALEN);
5650 memcpy(mgmt.sa, own_addr, ETH_ALEN);
5651 memcpy(mgmt.bssid, own_addr, ETH_ALEN);
5652 mgmt.u.disassoc.reason_code = host_to_le16(reason);
5653 return wpa_driver_nl80211_send_mlme(bss, (u8 *) &mgmt,
5654 IEEE80211_HDRLEN +
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08005655 sizeof(mgmt.u.disassoc), 0, 0, 0, 0,
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08005656 0, NULL, 0);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005657}
5658
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005659
Dmitry Shmidtdf5a7e42014-04-02 12:59:59 -07005660static void dump_ifidx(struct wpa_driver_nl80211_data *drv)
5661{
5662 char buf[200], *pos, *end;
5663 int i, res;
5664
5665 pos = buf;
5666 end = pos + sizeof(buf);
5667
5668 for (i = 0; i < drv->num_if_indices; i++) {
5669 if (!drv->if_indices[i])
5670 continue;
Dmitry Shmidt9c175262016-03-03 10:20:07 -08005671 res = os_snprintf(pos, end - pos, " %d(%d)",
5672 drv->if_indices[i],
5673 drv->if_indices_reason[i]);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005674 if (os_snprintf_error(end - pos, res))
Dmitry Shmidtdf5a7e42014-04-02 12:59:59 -07005675 break;
5676 pos += res;
5677 }
5678 *pos = '\0';
5679
5680 wpa_printf(MSG_DEBUG, "nl80211: if_indices[%d]:%s",
5681 drv->num_if_indices, buf);
5682}
5683
5684
Dmitry Shmidt9c175262016-03-03 10:20:07 -08005685static void add_ifidx(struct wpa_driver_nl80211_data *drv, int ifidx,
5686 int ifidx_reason)
Jouni Malinen75ecf522011-06-27 15:19:46 -07005687{
5688 int i;
Dmitry Shmidt9c175262016-03-03 10:20:07 -08005689 int *old, *old_reason;
Jouni Malinen75ecf522011-06-27 15:19:46 -07005690
Dmitry Shmidt9c175262016-03-03 10:20:07 -08005691 wpa_printf(MSG_DEBUG,
5692 "nl80211: Add own interface ifindex %d (ifidx_reason %d)",
5693 ifidx, ifidx_reason);
5694 if (have_ifidx(drv, ifidx, ifidx_reason)) {
Dmitry Shmidtdf5a7e42014-04-02 12:59:59 -07005695 wpa_printf(MSG_DEBUG, "nl80211: ifindex %d already in the list",
5696 ifidx);
5697 return;
5698 }
Jouni Malinen75ecf522011-06-27 15:19:46 -07005699 for (i = 0; i < drv->num_if_indices; i++) {
5700 if (drv->if_indices[i] == 0) {
5701 drv->if_indices[i] = ifidx;
Dmitry Shmidt9c175262016-03-03 10:20:07 -08005702 drv->if_indices_reason[i] = ifidx_reason;
Dmitry Shmidtdf5a7e42014-04-02 12:59:59 -07005703 dump_ifidx(drv);
Jouni Malinen75ecf522011-06-27 15:19:46 -07005704 return;
5705 }
5706 }
5707
5708 if (drv->if_indices != drv->default_if_indices)
5709 old = drv->if_indices;
5710 else
5711 old = NULL;
5712
Dmitry Shmidt9c175262016-03-03 10:20:07 -08005713 if (drv->if_indices_reason != drv->default_if_indices_reason)
5714 old_reason = drv->if_indices_reason;
5715 else
5716 old_reason = NULL;
5717
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07005718 drv->if_indices = os_realloc_array(old, drv->num_if_indices + 1,
5719 sizeof(int));
Dmitry Shmidt9c175262016-03-03 10:20:07 -08005720 drv->if_indices_reason = os_realloc_array(old_reason,
5721 drv->num_if_indices + 1,
5722 sizeof(int));
Jouni Malinen75ecf522011-06-27 15:19:46 -07005723 if (!drv->if_indices) {
5724 if (!old)
5725 drv->if_indices = drv->default_if_indices;
5726 else
5727 drv->if_indices = old;
Dmitry Shmidt9c175262016-03-03 10:20:07 -08005728 }
5729 if (!drv->if_indices_reason) {
5730 if (!old_reason)
5731 drv->if_indices_reason = drv->default_if_indices_reason;
5732 else
Dmitry Shmidte4663042016-04-04 10:07:49 -07005733 drv->if_indices_reason = old_reason;
Dmitry Shmidt9c175262016-03-03 10:20:07 -08005734 }
5735 if (!drv->if_indices || !drv->if_indices_reason) {
Jouni Malinen75ecf522011-06-27 15:19:46 -07005736 wpa_printf(MSG_ERROR, "Failed to reallocate memory for "
5737 "interfaces");
5738 wpa_printf(MSG_ERROR, "Ignoring EAPOL on interface %d", ifidx);
5739 return;
Dmitry Shmidt9c175262016-03-03 10:20:07 -08005740 }
5741 if (!old)
Jouni Malinen75ecf522011-06-27 15:19:46 -07005742 os_memcpy(drv->if_indices, drv->default_if_indices,
5743 sizeof(drv->default_if_indices));
Dmitry Shmidt9c175262016-03-03 10:20:07 -08005744 if (!old_reason)
5745 os_memcpy(drv->if_indices_reason,
5746 drv->default_if_indices_reason,
5747 sizeof(drv->default_if_indices_reason));
Jouni Malinen75ecf522011-06-27 15:19:46 -07005748 drv->if_indices[drv->num_if_indices] = ifidx;
Dmitry Shmidt9c175262016-03-03 10:20:07 -08005749 drv->if_indices_reason[drv->num_if_indices] = ifidx_reason;
Jouni Malinen75ecf522011-06-27 15:19:46 -07005750 drv->num_if_indices++;
Dmitry Shmidtdf5a7e42014-04-02 12:59:59 -07005751 dump_ifidx(drv);
Jouni Malinen75ecf522011-06-27 15:19:46 -07005752}
5753
5754
Dmitry Shmidt9c175262016-03-03 10:20:07 -08005755static void del_ifidx(struct wpa_driver_nl80211_data *drv, int ifidx,
5756 int ifidx_reason)
Jouni Malinen75ecf522011-06-27 15:19:46 -07005757{
5758 int i;
5759
5760 for (i = 0; i < drv->num_if_indices; i++) {
Dmitry Shmidt9c175262016-03-03 10:20:07 -08005761 if ((drv->if_indices[i] == ifidx || ifidx == IFIDX_ANY) &&
5762 (drv->if_indices_reason[i] == ifidx_reason ||
5763 ifidx_reason == IFIDX_ANY)) {
Jouni Malinen75ecf522011-06-27 15:19:46 -07005764 drv->if_indices[i] = 0;
5765 break;
5766 }
5767 }
Dmitry Shmidtdf5a7e42014-04-02 12:59:59 -07005768 dump_ifidx(drv);
Jouni Malinen75ecf522011-06-27 15:19:46 -07005769}
5770
5771
Dmitry Shmidt9c175262016-03-03 10:20:07 -08005772static int have_ifidx(struct wpa_driver_nl80211_data *drv, int ifidx,
5773 int ifidx_reason)
Jouni Malinen75ecf522011-06-27 15:19:46 -07005774{
5775 int i;
5776
5777 for (i = 0; i < drv->num_if_indices; i++)
Dmitry Shmidt9c175262016-03-03 10:20:07 -08005778 if (drv->if_indices[i] == ifidx &&
5779 (drv->if_indices_reason[i] == ifidx_reason ||
5780 ifidx_reason == IFIDX_ANY))
Jouni Malinen75ecf522011-06-27 15:19:46 -07005781 return 1;
5782
5783 return 0;
5784}
5785
5786
5787static int i802_set_wds_sta(void *priv, const u8 *addr, int aid, int val,
Dmitry Shmidt7832adb2014-04-29 10:53:02 -07005788 const char *bridge_ifname, char *ifname_wds)
Jouni Malinen75ecf522011-06-27 15:19:46 -07005789{
5790 struct i802_bss *bss = priv;
5791 struct wpa_driver_nl80211_data *drv = bss->drv;
5792 char name[IFNAMSIZ + 1];
5793
5794 os_snprintf(name, sizeof(name), "%s.sta%d", bss->ifname, aid);
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07005795 if (ifname_wds)
5796 os_strlcpy(ifname_wds, name, IFNAMSIZ + 1);
5797
Jouni Malinen75ecf522011-06-27 15:19:46 -07005798 wpa_printf(MSG_DEBUG, "nl80211: Set WDS STA addr=" MACSTR
5799 " aid=%d val=%d name=%s", MAC2STR(addr), aid, val, name);
5800 if (val) {
5801 if (!if_nametoindex(name)) {
5802 if (nl80211_create_iface(drv, name,
5803 NL80211_IFTYPE_AP_VLAN,
Dmitry Shmidtcce06662013-11-04 18:44:24 -08005804 bss->addr, 1, NULL, NULL, 0) <
5805 0)
Jouni Malinen75ecf522011-06-27 15:19:46 -07005806 return -1;
5807 if (bridge_ifname &&
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005808 linux_br_add_if(drv->global->ioctl_sock,
5809 bridge_ifname, name) < 0)
Jouni Malinen75ecf522011-06-27 15:19:46 -07005810 return -1;
5811 }
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07005812 if (linux_set_iface_flags(drv->global->ioctl_sock, name, 1)) {
5813 wpa_printf(MSG_ERROR, "nl80211: Failed to set WDS STA "
5814 "interface %s up", name);
5815 }
Jouni Malinen75ecf522011-06-27 15:19:46 -07005816 return i802_set_sta_vlan(priv, addr, name, 0);
5817 } else {
Dmitry Shmidtaa532512012-09-24 10:35:31 -07005818 if (bridge_ifname)
5819 linux_br_del_if(drv->global->ioctl_sock, bridge_ifname,
5820 name);
5821
Jouni Malinen75ecf522011-06-27 15:19:46 -07005822 i802_set_sta_vlan(priv, addr, bss->ifname, 0);
Dmitry Shmidta38abf92014-03-06 13:38:44 -08005823 nl80211_remove_iface(drv, if_nametoindex(name));
5824 return 0;
Jouni Malinen75ecf522011-06-27 15:19:46 -07005825 }
5826}
5827
5828
5829static void handle_eapol(int sock, void *eloop_ctx, void *sock_ctx)
5830{
5831 struct wpa_driver_nl80211_data *drv = eloop_ctx;
5832 struct sockaddr_ll lladdr;
5833 unsigned char buf[3000];
5834 int len;
5835 socklen_t fromlen = sizeof(lladdr);
5836
5837 len = recvfrom(sock, buf, sizeof(buf), 0,
5838 (struct sockaddr *)&lladdr, &fromlen);
5839 if (len < 0) {
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -07005840 wpa_printf(MSG_ERROR, "nl80211: EAPOL recv failed: %s",
5841 strerror(errno));
Jouni Malinen75ecf522011-06-27 15:19:46 -07005842 return;
5843 }
5844
Dmitry Shmidt9c175262016-03-03 10:20:07 -08005845 if (have_ifidx(drv, lladdr.sll_ifindex, IFIDX_ANY))
Jouni Malinen75ecf522011-06-27 15:19:46 -07005846 drv_event_eapol_rx(drv->ctx, lladdr.sll_addr, buf, len);
5847}
5848
5849
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005850static int i802_check_bridge(struct wpa_driver_nl80211_data *drv,
5851 struct i802_bss *bss,
5852 const char *brname, const char *ifname)
5853{
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005854 int br_ifindex;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005855 char in_br[IFNAMSIZ];
5856
5857 os_strlcpy(bss->brname, brname, IFNAMSIZ);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005858 br_ifindex = if_nametoindex(brname);
5859 if (br_ifindex == 0) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005860 /*
5861 * Bridge was configured, but the bridge device does
5862 * not exist. Try to add it now.
5863 */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005864 if (linux_br_add(drv->global->ioctl_sock, brname) < 0) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005865 wpa_printf(MSG_ERROR, "nl80211: Failed to add the "
5866 "bridge interface %s: %s",
5867 brname, strerror(errno));
5868 return -1;
5869 }
5870 bss->added_bridge = 1;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005871 br_ifindex = if_nametoindex(brname);
Dmitry Shmidt9c175262016-03-03 10:20:07 -08005872 add_ifidx(drv, br_ifindex, drv->ifindex);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005873 }
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005874 bss->br_ifindex = br_ifindex;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005875
5876 if (linux_br_get(in_br, ifname) == 0) {
5877 if (os_strcmp(in_br, brname) == 0)
5878 return 0; /* already in the bridge */
5879
5880 wpa_printf(MSG_DEBUG, "nl80211: Removing interface %s from "
5881 "bridge %s", ifname, in_br);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005882 if (linux_br_del_if(drv->global->ioctl_sock, in_br, ifname) <
5883 0) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005884 wpa_printf(MSG_ERROR, "nl80211: Failed to "
5885 "remove interface %s from bridge "
5886 "%s: %s",
5887 ifname, brname, strerror(errno));
5888 return -1;
5889 }
5890 }
5891
5892 wpa_printf(MSG_DEBUG, "nl80211: Adding interface %s into bridge %s",
5893 ifname, brname);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005894 if (linux_br_add_if(drv->global->ioctl_sock, brname, ifname) < 0) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005895 wpa_printf(MSG_ERROR, "nl80211: Failed to add interface %s "
5896 "into bridge %s: %s",
5897 ifname, brname, strerror(errno));
5898 return -1;
5899 }
5900 bss->added_if_into_bridge = 1;
5901
5902 return 0;
5903}
5904
5905
5906static void *i802_init(struct hostapd_data *hapd,
5907 struct wpa_init_params *params)
5908{
5909 struct wpa_driver_nl80211_data *drv;
5910 struct i802_bss *bss;
5911 size_t i;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08005912 char master_ifname[IFNAMSIZ];
5913 int ifindex, br_ifindex = 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005914 int br_added = 0;
5915
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08005916 bss = wpa_driver_nl80211_drv_init(hapd, params->ifname,
5917 params->global_priv, 1,
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005918 params->bssid, params->driver_params);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005919 if (bss == NULL)
5920 return NULL;
5921
5922 drv = bss->drv;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005923
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08005924 if (linux_br_get(master_ifname, params->ifname) == 0) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005925 wpa_printf(MSG_DEBUG, "nl80211: Interface %s is in bridge %s",
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08005926 params->ifname, master_ifname);
5927 br_ifindex = if_nametoindex(master_ifname);
5928 os_strlcpy(bss->brname, master_ifname, IFNAMSIZ);
5929 } else if ((params->num_bridge == 0 || !params->bridge[0]) &&
5930 linux_master_get(master_ifname, params->ifname) == 0) {
5931 wpa_printf(MSG_DEBUG, "nl80211: Interface %s is in master %s",
5932 params->ifname, master_ifname);
5933 /* start listening for EAPOL on the master interface */
Dmitry Shmidt9c175262016-03-03 10:20:07 -08005934 add_ifidx(drv, if_nametoindex(master_ifname), drv->ifindex);
Dmitry Shmidt31a29cc2016-03-09 15:58:17 -08005935
5936 /* check if master itself is under bridge */
5937 if (linux_br_get(master_ifname, master_ifname) == 0) {
5938 wpa_printf(MSG_DEBUG, "nl80211: which is in bridge %s",
5939 master_ifname);
5940 br_ifindex = if_nametoindex(master_ifname);
5941 os_strlcpy(bss->brname, master_ifname, IFNAMSIZ);
5942 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005943 } else {
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08005944 master_ifname[0] = '\0';
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005945 }
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08005946
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005947 bss->br_ifindex = br_ifindex;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005948
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005949 for (i = 0; i < params->num_bridge; i++) {
5950 if (params->bridge[i]) {
5951 ifindex = if_nametoindex(params->bridge[i]);
5952 if (ifindex)
Dmitry Shmidt9c175262016-03-03 10:20:07 -08005953 add_ifidx(drv, ifindex, drv->ifindex);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005954 if (ifindex == br_ifindex)
5955 br_added = 1;
5956 }
5957 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005958
5959 /* start listening for EAPOL on the default AP interface */
Dmitry Shmidt9c175262016-03-03 10:20:07 -08005960 add_ifidx(drv, drv->ifindex, IFIDX_ANY);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005961
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005962 if (params->num_bridge && params->bridge[0]) {
5963 if (i802_check_bridge(drv, bss, params->bridge[0],
5964 params->ifname) < 0)
5965 goto failed;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08005966 if (os_strcmp(params->bridge[0], master_ifname) != 0)
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005967 br_added = 1;
5968 }
5969
5970 if (!br_added && br_ifindex &&
5971 (params->num_bridge == 0 || !params->bridge[0]))
Dmitry Shmidt9c175262016-03-03 10:20:07 -08005972 add_ifidx(drv, br_ifindex, drv->ifindex);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005973
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07005974#ifdef CONFIG_LIBNL3_ROUTE
5975 if (bss->added_if_into_bridge) {
5976 drv->rtnl_sk = nl_socket_alloc();
5977 if (drv->rtnl_sk == NULL) {
5978 wpa_printf(MSG_ERROR, "nl80211: Failed to allocate nl_sock");
5979 goto failed;
5980 }
5981
5982 if (nl_connect(drv->rtnl_sk, NETLINK_ROUTE)) {
5983 wpa_printf(MSG_ERROR, "nl80211: Failed to connect nl_sock to NETLINK_ROUTE: %s",
5984 strerror(errno));
5985 goto failed;
5986 }
5987 }
5988#endif /* CONFIG_LIBNL3_ROUTE */
5989
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005990 drv->eapol_sock = socket(PF_PACKET, SOCK_DGRAM, htons(ETH_P_PAE));
5991 if (drv->eapol_sock < 0) {
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -07005992 wpa_printf(MSG_ERROR, "nl80211: socket(PF_PACKET, SOCK_DGRAM, ETH_P_PAE) failed: %s",
5993 strerror(errno));
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005994 goto failed;
5995 }
5996
5997 if (eloop_register_read_sock(drv->eapol_sock, handle_eapol, drv, NULL))
5998 {
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -07005999 wpa_printf(MSG_INFO, "nl80211: Could not register read socket for eapol");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006000 goto failed;
6001 }
6002
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006003 if (linux_get_ifhwaddr(drv->global->ioctl_sock, bss->ifname,
6004 params->own_addr))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006005 goto failed;
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07006006 os_memcpy(drv->perm_addr, params->own_addr, ETH_ALEN);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006007
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006008 memcpy(bss->addr, params->own_addr, ETH_ALEN);
6009
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006010 return bss;
6011
6012failed:
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006013 wpa_driver_nl80211_deinit(bss);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006014 return NULL;
6015}
6016
6017
6018static void i802_deinit(void *priv)
6019{
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08006020 struct i802_bss *bss = priv;
6021 wpa_driver_nl80211_deinit(bss);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006022}
6023
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006024
6025static enum nl80211_iftype wpa_driver_nl80211_if_type(
6026 enum wpa_driver_if_type type)
6027{
6028 switch (type) {
6029 case WPA_IF_STATION:
6030 return NL80211_IFTYPE_STATION;
6031 case WPA_IF_P2P_CLIENT:
6032 case WPA_IF_P2P_GROUP:
6033 return NL80211_IFTYPE_P2P_CLIENT;
6034 case WPA_IF_AP_VLAN:
6035 return NL80211_IFTYPE_AP_VLAN;
6036 case WPA_IF_AP_BSS:
6037 return NL80211_IFTYPE_AP;
6038 case WPA_IF_P2P_GO:
6039 return NL80211_IFTYPE_P2P_GO;
Dmitry Shmidt34af3062013-07-11 10:46:32 -07006040 case WPA_IF_P2P_DEVICE:
6041 return NL80211_IFTYPE_P2P_DEVICE;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08006042 case WPA_IF_MESH:
6043 return NL80211_IFTYPE_MESH_POINT;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08006044 default:
6045 return -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006046 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006047}
6048
6049
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006050static int nl80211_addr_in_use(struct nl80211_global *global, const u8 *addr)
6051{
6052 struct wpa_driver_nl80211_data *drv;
6053 dl_list_for_each(drv, &global->interfaces,
6054 struct wpa_driver_nl80211_data, list) {
Dmitry Shmidtcce06662013-11-04 18:44:24 -08006055 if (os_memcmp(addr, drv->first_bss->addr, ETH_ALEN) == 0)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006056 return 1;
6057 }
6058 return 0;
6059}
6060
6061
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08006062static int nl80211_vif_addr(struct wpa_driver_nl80211_data *drv, u8 *new_addr)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006063{
6064 unsigned int idx;
6065
6066 if (!drv->global)
6067 return -1;
6068
Dmitry Shmidtcce06662013-11-04 18:44:24 -08006069 os_memcpy(new_addr, drv->first_bss->addr, ETH_ALEN);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006070 for (idx = 0; idx < 64; idx++) {
Dmitry Shmidtcce06662013-11-04 18:44:24 -08006071 new_addr[0] = drv->first_bss->addr[0] | 0x02;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006072 new_addr[0] ^= idx << 2;
6073 if (!nl80211_addr_in_use(drv->global, new_addr))
6074 break;
6075 }
6076 if (idx == 64)
6077 return -1;
6078
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08006079 wpa_printf(MSG_DEBUG, "nl80211: Assigned new virtual interface address "
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006080 MACSTR, MAC2STR(new_addr));
6081
6082 return 0;
6083}
6084
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006085
Dmitry Shmidt34af3062013-07-11 10:46:32 -07006086struct wdev_info {
6087 u64 wdev_id;
6088 int wdev_id_set;
6089 u8 macaddr[ETH_ALEN];
6090};
6091
6092static int nl80211_wdev_handler(struct nl_msg *msg, void *arg)
6093{
6094 struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg));
6095 struct nlattr *tb[NL80211_ATTR_MAX + 1];
6096 struct wdev_info *wi = arg;
6097
6098 nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0),
6099 genlmsg_attrlen(gnlh, 0), NULL);
6100 if (tb[NL80211_ATTR_WDEV]) {
6101 wi->wdev_id = nla_get_u64(tb[NL80211_ATTR_WDEV]);
6102 wi->wdev_id_set = 1;
6103 }
6104
6105 if (tb[NL80211_ATTR_MAC])
6106 os_memcpy(wi->macaddr, nla_data(tb[NL80211_ATTR_MAC]),
6107 ETH_ALEN);
6108
6109 return NL_SKIP;
6110}
6111
6112
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006113static int wpa_driver_nl80211_if_add(void *priv, enum wpa_driver_if_type type,
6114 const char *ifname, const u8 *addr,
6115 void *bss_ctx, void **drv_priv,
6116 char *force_ifname, u8 *if_addr,
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08006117 const char *bridge, int use_existing,
6118 int setup_ap)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006119{
Dmitry Shmidt34af3062013-07-11 10:46:32 -07006120 enum nl80211_iftype nlmode;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006121 struct i802_bss *bss = priv;
6122 struct wpa_driver_nl80211_data *drv = bss->drv;
6123 int ifidx;
Dmitry Shmidtcce06662013-11-04 18:44:24 -08006124 int added = 1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006125
6126 if (addr)
6127 os_memcpy(if_addr, addr, ETH_ALEN);
Dmitry Shmidt34af3062013-07-11 10:46:32 -07006128 nlmode = wpa_driver_nl80211_if_type(type);
6129 if (nlmode == NL80211_IFTYPE_P2P_DEVICE) {
6130 struct wdev_info p2pdev_info;
6131
6132 os_memset(&p2pdev_info, 0, sizeof(p2pdev_info));
6133 ifidx = nl80211_create_iface(drv, ifname, nlmode, addr,
6134 0, nl80211_wdev_handler,
Dmitry Shmidtcce06662013-11-04 18:44:24 -08006135 &p2pdev_info, use_existing);
Dmitry Shmidt34af3062013-07-11 10:46:32 -07006136 if (!p2pdev_info.wdev_id_set || ifidx != 0) {
6137 wpa_printf(MSG_ERROR, "nl80211: Failed to create a P2P Device interface %s",
6138 ifname);
6139 return -1;
6140 }
6141
6142 drv->global->if_add_wdevid = p2pdev_info.wdev_id;
6143 drv->global->if_add_wdevid_set = p2pdev_info.wdev_id_set;
6144 if (!is_zero_ether_addr(p2pdev_info.macaddr))
6145 os_memcpy(if_addr, p2pdev_info.macaddr, ETH_ALEN);
6146 wpa_printf(MSG_DEBUG, "nl80211: New P2P Device interface %s (0x%llx) created",
6147 ifname,
6148 (long long unsigned int) p2pdev_info.wdev_id);
6149 } else {
6150 ifidx = nl80211_create_iface(drv, ifname, nlmode, addr,
Dmitry Shmidtcce06662013-11-04 18:44:24 -08006151 0, NULL, NULL, use_existing);
6152 if (use_existing && ifidx == -ENFILE) {
6153 added = 0;
6154 ifidx = if_nametoindex(ifname);
6155 } else if (ifidx < 0) {
Dmitry Shmidt34af3062013-07-11 10:46:32 -07006156 return -1;
6157 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006158 }
6159
Dmitry Shmidt34af3062013-07-11 10:46:32 -07006160 if (!addr) {
Dmitry Shmidt1d755d02015-04-28 10:34:29 -07006161 if (nlmode == NL80211_IFTYPE_P2P_DEVICE)
Dmitry Shmidt34af3062013-07-11 10:46:32 -07006162 os_memcpy(if_addr, bss->addr, ETH_ALEN);
6163 else if (linux_get_ifhwaddr(drv->global->ioctl_sock,
Dmitry Shmidt1d755d02015-04-28 10:34:29 -07006164 ifname, if_addr) < 0) {
Dmitry Shmidtcce06662013-11-04 18:44:24 -08006165 if (added)
6166 nl80211_remove_iface(drv, ifidx);
Dmitry Shmidt34af3062013-07-11 10:46:32 -07006167 return -1;
6168 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006169 }
6170
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006171 if (!addr &&
6172 (type == WPA_IF_P2P_CLIENT || type == WPA_IF_P2P_GROUP ||
Dmitry Shmidt1d755d02015-04-28 10:34:29 -07006173 type == WPA_IF_P2P_GO || type == WPA_IF_MESH ||
6174 type == WPA_IF_STATION)) {
6175 /* Enforce unique address */
Dmitry Shmidt34af3062013-07-11 10:46:32 -07006176 u8 new_addr[ETH_ALEN];
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006177
Dmitry Shmidt34af3062013-07-11 10:46:32 -07006178 if (linux_get_ifhwaddr(drv->global->ioctl_sock, ifname,
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006179 new_addr) < 0) {
Dmitry Shmidt71757432014-06-02 13:50:35 -07006180 if (added)
6181 nl80211_remove_iface(drv, ifidx);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006182 return -1;
6183 }
Dmitry Shmidt34af3062013-07-11 10:46:32 -07006184 if (nl80211_addr_in_use(drv->global, new_addr)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006185 wpa_printf(MSG_DEBUG, "nl80211: Allocate new address "
Dmitry Shmidt1d755d02015-04-28 10:34:29 -07006186 "for interface %s type %d", ifname, type);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08006187 if (nl80211_vif_addr(drv, new_addr) < 0) {
Dmitry Shmidt71757432014-06-02 13:50:35 -07006188 if (added)
6189 nl80211_remove_iface(drv, ifidx);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006190 return -1;
6191 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006192 if (linux_set_ifhwaddr(drv->global->ioctl_sock, ifname,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006193 new_addr) < 0) {
Dmitry Shmidt71757432014-06-02 13:50:35 -07006194 if (added)
6195 nl80211_remove_iface(drv, ifidx);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006196 return -1;
6197 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006198 }
Dmitry Shmidt6e933c12011-09-27 12:29:26 -07006199 os_memcpy(if_addr, new_addr, ETH_ALEN);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006200 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006201
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08006202 if (type == WPA_IF_AP_BSS && setup_ap) {
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -07006203 struct i802_bss *new_bss = os_zalloc(sizeof(*new_bss));
6204 if (new_bss == NULL) {
Dmitry Shmidtcce06662013-11-04 18:44:24 -08006205 if (added)
6206 nl80211_remove_iface(drv, ifidx);
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -07006207 return -1;
6208 }
6209
6210 if (bridge &&
6211 i802_check_bridge(drv, new_bss, bridge, ifname) < 0) {
6212 wpa_printf(MSG_ERROR, "nl80211: Failed to add the new "
6213 "interface %s to a bridge %s",
6214 ifname, bridge);
Dmitry Shmidtcce06662013-11-04 18:44:24 -08006215 if (added)
6216 nl80211_remove_iface(drv, ifidx);
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -07006217 os_free(new_bss);
6218 return -1;
6219 }
6220
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006221 if (linux_set_iface_flags(drv->global->ioctl_sock, ifname, 1))
6222 {
Dmitry Shmidt71757432014-06-02 13:50:35 -07006223 if (added)
6224 nl80211_remove_iface(drv, ifidx);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006225 os_free(new_bss);
6226 return -1;
6227 }
6228 os_strlcpy(new_bss->ifname, ifname, IFNAMSIZ);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006229 os_memcpy(new_bss->addr, if_addr, ETH_ALEN);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006230 new_bss->ifindex = ifidx;
6231 new_bss->drv = drv;
Dmitry Shmidtcce06662013-11-04 18:44:24 -08006232 new_bss->next = drv->first_bss->next;
6233 new_bss->freq = drv->first_bss->freq;
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08006234 new_bss->ctx = bss_ctx;
Dmitry Shmidtcce06662013-11-04 18:44:24 -08006235 new_bss->added_if = added;
6236 drv->first_bss->next = new_bss;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006237 if (drv_priv)
6238 *drv_priv = new_bss;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006239 nl80211_init_bss(new_bss);
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08006240
6241 /* Subscribe management frames for this WPA_IF_AP_BSS */
6242 if (nl80211_setup_ap(new_bss))
6243 return -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006244 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006245
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006246 if (drv->global)
6247 drv->global->if_add_ifindex = ifidx;
6248
Dmitry Shmidt43cb5782014-06-16 16:23:22 -07006249 /*
6250 * Some virtual interfaces need to process EAPOL packets and events on
6251 * the parent interface. This is used mainly with hostapd.
6252 */
6253 if (ifidx > 0 &&
6254 (drv->hostapd ||
6255 nlmode == NL80211_IFTYPE_AP_VLAN ||
6256 nlmode == NL80211_IFTYPE_WDS ||
6257 nlmode == NL80211_IFTYPE_MONITOR))
Dmitry Shmidt9c175262016-03-03 10:20:07 -08006258 add_ifidx(drv, ifidx, IFIDX_ANY);
Dmitry Shmidtdf5a7e42014-04-02 12:59:59 -07006259
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006260 return 0;
6261}
6262
6263
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08006264static int wpa_driver_nl80211_if_remove(struct i802_bss *bss,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006265 enum wpa_driver_if_type type,
6266 const char *ifname)
6267{
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006268 struct wpa_driver_nl80211_data *drv = bss->drv;
6269 int ifindex = if_nametoindex(ifname);
6270
Dmitry Shmidtcce06662013-11-04 18:44:24 -08006271 wpa_printf(MSG_DEBUG, "nl80211: %s(type=%d ifname=%s) ifindex=%d added_if=%d",
6272 __func__, type, ifname, ifindex, bss->added_if);
Dmitry Shmidt01904cf2013-12-05 11:08:35 -08006273 if (ifindex > 0 && (bss->added_if || bss->ifindex != ifindex))
Dmitry Shmidt051af732013-10-22 13:52:46 -07006274 nl80211_remove_iface(drv, ifindex);
Dmitry Shmidt76cd2cc2014-05-27 12:56:04 -07006275 else if (ifindex > 0 && !bss->added_if) {
6276 struct wpa_driver_nl80211_data *drv2;
6277 dl_list_for_each(drv2, &drv->global->interfaces,
Dmitry Shmidt9c175262016-03-03 10:20:07 -08006278 struct wpa_driver_nl80211_data, list) {
6279 del_ifidx(drv2, ifindex, IFIDX_ANY);
6280 del_ifidx(drv2, IFIDX_ANY, ifindex);
6281 }
Dmitry Shmidt76cd2cc2014-05-27 12:56:04 -07006282 }
Dmitry Shmidtaa532512012-09-24 10:35:31 -07006283
Dmitry Shmidtaa532512012-09-24 10:35:31 -07006284 if (type != WPA_IF_AP_BSS)
6285 return 0;
6286
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006287 if (bss->added_if_into_bridge) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006288 if (linux_br_del_if(drv->global->ioctl_sock, bss->brname,
6289 bss->ifname) < 0)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006290 wpa_printf(MSG_INFO, "nl80211: Failed to remove "
6291 "interface %s from bridge %s: %s",
6292 bss->ifname, bss->brname, strerror(errno));
6293 }
6294 if (bss->added_bridge) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006295 if (linux_br_del(drv->global->ioctl_sock, bss->brname) < 0)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006296 wpa_printf(MSG_INFO, "nl80211: Failed to remove "
6297 "bridge %s: %s",
6298 bss->brname, strerror(errno));
6299 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006300
Dmitry Shmidtcce06662013-11-04 18:44:24 -08006301 if (bss != drv->first_bss) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006302 struct i802_bss *tbss;
6303
Dmitry Shmidtcce06662013-11-04 18:44:24 -08006304 wpa_printf(MSG_DEBUG, "nl80211: Not the first BSS - remove it");
6305 for (tbss = drv->first_bss; tbss; tbss = tbss->next) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006306 if (tbss->next == bss) {
6307 tbss->next = bss->next;
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08006308 /* Unsubscribe management frames */
6309 nl80211_teardown_ap(bss);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006310 nl80211_destroy_bss(bss);
Dmitry Shmidtdf5a7e42014-04-02 12:59:59 -07006311 if (!bss->added_if)
6312 i802_set_iface_flags(bss, 0);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006313 os_free(bss);
6314 bss = NULL;
6315 break;
6316 }
6317 }
6318 if (bss)
6319 wpa_printf(MSG_INFO, "nl80211: %s - could not find "
6320 "BSS %p in the list", __func__, bss);
Dmitry Shmidtcce06662013-11-04 18:44:24 -08006321 } else {
6322 wpa_printf(MSG_DEBUG, "nl80211: First BSS - reassign context");
6323 nl80211_teardown_ap(bss);
6324 if (!bss->added_if && !drv->first_bss->next)
6325 wpa_driver_nl80211_del_beacon(drv);
6326 nl80211_destroy_bss(bss);
6327 if (!bss->added_if)
6328 i802_set_iface_flags(bss, 0);
6329 if (drv->first_bss->next) {
6330 drv->first_bss = drv->first_bss->next;
6331 drv->ctx = drv->first_bss->ctx;
6332 os_free(bss);
6333 } else {
6334 wpa_printf(MSG_DEBUG, "nl80211: No second BSS to reassign context to");
6335 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006336 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006337
6338 return 0;
6339}
6340
6341
6342static int cookie_handler(struct nl_msg *msg, void *arg)
6343{
6344 struct nlattr *tb[NL80211_ATTR_MAX + 1];
6345 struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg));
6346 u64 *cookie = arg;
6347 nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0),
6348 genlmsg_attrlen(gnlh, 0), NULL);
6349 if (tb[NL80211_ATTR_COOKIE])
6350 *cookie = nla_get_u64(tb[NL80211_ATTR_COOKIE]);
6351 return NL_SKIP;
6352}
6353
6354
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006355static int nl80211_send_frame_cmd(struct i802_bss *bss,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006356 unsigned int freq, unsigned int wait,
6357 const u8 *buf, size_t buf_len,
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006358 u64 *cookie_out, int no_cck, int no_ack,
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08006359 int offchanok, const u16 *csa_offs,
6360 size_t csa_offs_len)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006361{
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006362 struct wpa_driver_nl80211_data *drv = bss->drv;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006363 struct nl_msg *msg;
6364 u64 cookie;
6365 int ret = -1;
6366
Dmitry Shmidt8da800a2013-04-24 12:57:01 -07006367 wpa_printf(MSG_MSGDUMP, "nl80211: CMD_FRAME freq=%u wait=%u no_cck=%d "
Dmitry Shmidt04949592012-07-19 12:16:46 -07006368 "no_ack=%d offchanok=%d",
6369 freq, wait, no_cck, no_ack, offchanok);
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07006370 wpa_hexdump(MSG_MSGDUMP, "CMD_FRAME", buf, buf_len);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006371
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08006372 if (!(msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_FRAME)) ||
6373 (freq && nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq)) ||
6374 (wait && nla_put_u32(msg, NL80211_ATTR_DURATION, wait)) ||
6375 (offchanok && ((drv->capa.flags & WPA_DRIVER_FLAGS_OFFCHANNEL_TX) ||
6376 drv->test_use_roc_tx) &&
6377 nla_put_flag(msg, NL80211_ATTR_OFFCHANNEL_TX_OK)) ||
6378 (no_cck && nla_put_flag(msg, NL80211_ATTR_TX_NO_CCK_RATE)) ||
6379 (no_ack && nla_put_flag(msg, NL80211_ATTR_DONT_WAIT_FOR_ACK)) ||
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08006380 (csa_offs && nla_put(msg, NL80211_ATTR_CSA_C_OFFSETS_TX,
6381 csa_offs_len * sizeof(u16), csa_offs)) ||
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08006382 nla_put(msg, NL80211_ATTR_FRAME, buf_len, buf))
6383 goto fail;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006384
6385 cookie = 0;
6386 ret = send_and_recv_msgs(drv, msg, cookie_handler, &cookie);
6387 msg = NULL;
6388 if (ret) {
6389 wpa_printf(MSG_DEBUG, "nl80211: Frame command failed: ret=%d "
Dmitry Shmidt6e933c12011-09-27 12:29:26 -07006390 "(%s) (freq=%u wait=%u)", ret, strerror(-ret),
6391 freq, wait);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08006392 } else {
6393 wpa_printf(MSG_MSGDUMP, "nl80211: Frame TX command accepted%s; "
6394 "cookie 0x%llx", no_ack ? " (no ACK)" : "",
6395 (long long unsigned int) cookie);
6396
6397 if (cookie_out)
6398 *cookie_out = no_ack ? (u64) -1 : cookie;
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08006399
6400 if (drv->num_send_action_cookies == MAX_SEND_ACTION_COOKIES) {
6401 wpa_printf(MSG_DEBUG,
6402 "nl80211: Drop oldest pending send action cookie 0x%llx",
6403 (long long unsigned int)
6404 drv->send_action_cookies[0]);
6405 os_memmove(&drv->send_action_cookies[0],
6406 &drv->send_action_cookies[1],
6407 (MAX_SEND_ACTION_COOKIES - 1) *
6408 sizeof(u64));
6409 drv->num_send_action_cookies--;
6410 }
6411 drv->send_action_cookies[drv->num_send_action_cookies] = cookie;
6412 drv->num_send_action_cookies++;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006413 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006414
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08006415fail:
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006416 nlmsg_free(msg);
6417 return ret;
6418}
6419
6420
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08006421static int wpa_driver_nl80211_send_action(struct i802_bss *bss,
6422 unsigned int freq,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006423 unsigned int wait_time,
6424 const u8 *dst, const u8 *src,
6425 const u8 *bssid,
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006426 const u8 *data, size_t data_len,
6427 int no_cck)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006428{
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006429 struct wpa_driver_nl80211_data *drv = bss->drv;
6430 int ret = -1;
6431 u8 *buf;
6432 struct ieee80211_hdr *hdr;
6433
6434 wpa_printf(MSG_DEBUG, "nl80211: Send Action frame (ifindex=%d, "
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08006435 "freq=%u MHz wait=%d ms no_cck=%d)",
6436 drv->ifindex, freq, wait_time, no_cck);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006437
6438 buf = os_zalloc(24 + data_len);
6439 if (buf == NULL)
6440 return ret;
6441 os_memcpy(buf + 24, data, data_len);
6442 hdr = (struct ieee80211_hdr *) buf;
6443 hdr->frame_control =
6444 IEEE80211_FC(WLAN_FC_TYPE_MGMT, WLAN_FC_STYPE_ACTION);
6445 os_memcpy(hdr->addr1, dst, ETH_ALEN);
6446 os_memcpy(hdr->addr2, src, ETH_ALEN);
6447 os_memcpy(hdr->addr3, bssid, ETH_ALEN);
6448
Dmitry Shmidt56052862013-10-04 10:23:25 -07006449 if (is_ap_interface(drv->nlmode) &&
6450 (!(drv->capa.flags & WPA_DRIVER_FLAGS_OFFCHANNEL_TX) ||
6451 (int) freq == bss->freq || drv->device_ap_sme ||
6452 !drv->use_monitor))
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08006453 ret = wpa_driver_nl80211_send_mlme(bss, buf, 24 + data_len,
6454 0, freq, no_cck, 1,
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08006455 wait_time, NULL, 0);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006456 else
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006457 ret = nl80211_send_frame_cmd(bss, freq, wait_time, buf,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006458 24 + data_len,
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006459 &drv->send_action_cookie,
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08006460 no_cck, 0, 1, NULL, 0);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006461
6462 os_free(buf);
6463 return ret;
6464}
6465
6466
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08006467static void nl80211_frame_wait_cancel(struct i802_bss *bss, u64 cookie)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006468{
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006469 struct wpa_driver_nl80211_data *drv = bss->drv;
6470 struct nl_msg *msg;
6471 int ret;
6472
Dmitry Shmidt2f3b8de2013-03-01 09:32:50 -08006473 wpa_printf(MSG_DEBUG, "nl80211: Cancel TX frame wait: cookie=0x%llx",
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08006474 (long long unsigned int) cookie);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08006475 if (!(msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_FRAME_WAIT_CANCEL)) ||
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08006476 nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie)) {
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08006477 nlmsg_free(msg);
6478 return;
6479 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006480
6481 ret = send_and_recv_msgs(drv, msg, NULL, NULL);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006482 if (ret)
6483 wpa_printf(MSG_DEBUG, "nl80211: wait cancel failed: ret=%d "
6484 "(%s)", ret, strerror(-ret));
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006485}
6486
6487
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08006488static void wpa_driver_nl80211_send_action_cancel_wait(void *priv)
6489{
6490 struct i802_bss *bss = priv;
6491 struct wpa_driver_nl80211_data *drv = bss->drv;
6492 unsigned int i;
6493 u64 cookie;
6494
6495 /* Cancel the last pending TX cookie */
6496 nl80211_frame_wait_cancel(bss, drv->send_action_cookie);
6497
6498 /*
6499 * Cancel the other pending TX cookies, if any. This is needed since
6500 * the driver may keep a list of all pending offchannel TX operations
6501 * and free up the radio only once they have expired or cancelled.
6502 */
6503 for (i = drv->num_send_action_cookies; i > 0; i--) {
6504 cookie = drv->send_action_cookies[i - 1];
6505 if (cookie != drv->send_action_cookie)
6506 nl80211_frame_wait_cancel(bss, cookie);
6507 }
6508 drv->num_send_action_cookies = 0;
6509}
6510
6511
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006512static int wpa_driver_nl80211_remain_on_channel(void *priv, unsigned int freq,
6513 unsigned int duration)
6514{
6515 struct i802_bss *bss = priv;
6516 struct wpa_driver_nl80211_data *drv = bss->drv;
6517 struct nl_msg *msg;
6518 int ret;
6519 u64 cookie;
6520
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08006521 if (!(msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_REMAIN_ON_CHANNEL)) ||
6522 nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq) ||
6523 nla_put_u32(msg, NL80211_ATTR_DURATION, duration)) {
6524 nlmsg_free(msg);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006525 return -1;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08006526 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006527
6528 cookie = 0;
6529 ret = send_and_recv_msgs(drv, msg, cookie_handler, &cookie);
6530 if (ret == 0) {
6531 wpa_printf(MSG_DEBUG, "nl80211: Remain-on-channel cookie "
6532 "0x%llx for freq=%u MHz duration=%u",
6533 (long long unsigned int) cookie, freq, duration);
6534 drv->remain_on_chan_cookie = cookie;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006535 drv->pending_remain_on_chan = 1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006536 return 0;
6537 }
6538 wpa_printf(MSG_DEBUG, "nl80211: Failed to request remain-on-channel "
6539 "(freq=%d duration=%u): %d (%s)",
6540 freq, duration, ret, strerror(-ret));
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006541 return -1;
6542}
6543
6544
6545static int wpa_driver_nl80211_cancel_remain_on_channel(void *priv)
6546{
6547 struct i802_bss *bss = priv;
6548 struct wpa_driver_nl80211_data *drv = bss->drv;
6549 struct nl_msg *msg;
6550 int ret;
6551
6552 if (!drv->pending_remain_on_chan) {
6553 wpa_printf(MSG_DEBUG, "nl80211: No pending remain-on-channel "
6554 "to cancel");
6555 return -1;
6556 }
6557
6558 wpa_printf(MSG_DEBUG, "nl80211: Cancel remain-on-channel with cookie "
6559 "0x%llx",
6560 (long long unsigned int) drv->remain_on_chan_cookie);
6561
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08006562 msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL);
6563 if (!msg ||
6564 nla_put_u64(msg, NL80211_ATTR_COOKIE, drv->remain_on_chan_cookie)) {
6565 nlmsg_free(msg);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006566 return -1;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08006567 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006568
6569 ret = send_and_recv_msgs(drv, msg, NULL, NULL);
6570 if (ret == 0)
6571 return 0;
6572 wpa_printf(MSG_DEBUG, "nl80211: Failed to cancel remain-on-channel: "
6573 "%d (%s)", ret, strerror(-ret));
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006574 return -1;
6575}
6576
6577
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08006578static int wpa_driver_nl80211_probe_req_report(struct i802_bss *bss, int report)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006579{
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006580 struct wpa_driver_nl80211_data *drv = bss->drv;
Dmitry Shmidt6e933c12011-09-27 12:29:26 -07006581
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006582 if (!report) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006583 if (bss->nl_preq && drv->device_ap_sme &&
Dmitry Shmidt03658832014-08-13 11:03:49 -07006584 is_ap_interface(drv->nlmode) && !bss->in_deinit &&
6585 !bss->static_ap) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006586 /*
6587 * Do not disable Probe Request reporting that was
6588 * enabled in nl80211_setup_ap().
6589 */
6590 wpa_printf(MSG_DEBUG, "nl80211: Skip disabling of "
6591 "Probe Request reporting nl_preq=%p while "
6592 "in AP mode", bss->nl_preq);
6593 } else if (bss->nl_preq) {
6594 wpa_printf(MSG_DEBUG, "nl80211: Disable Probe Request "
6595 "reporting nl_preq=%p", bss->nl_preq);
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -07006596 nl80211_destroy_eloop_handle(&bss->nl_preq);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006597 }
6598 return 0;
6599 }
6600
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006601 if (bss->nl_preq) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006602 wpa_printf(MSG_DEBUG, "nl80211: Probe Request reporting "
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006603 "already on! nl_preq=%p", bss->nl_preq);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006604 return 0;
6605 }
6606
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006607 bss->nl_preq = nl_create_handle(drv->global->nl_cb, "preq");
6608 if (bss->nl_preq == NULL)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006609 return -1;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006610 wpa_printf(MSG_DEBUG, "nl80211: Enable Probe Request "
6611 "reporting nl_preq=%p", bss->nl_preq);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006612
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006613 if (nl80211_register_frame(bss, bss->nl_preq,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006614 (WLAN_FC_TYPE_MGMT << 2) |
6615 (WLAN_FC_STYPE_PROBE_REQ << 4),
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006616 NULL, 0) < 0)
6617 goto out_err;
Dmitry Shmidt497c1d52011-07-21 15:19:46 -07006618
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -07006619 nl80211_register_eloop_read(&bss->nl_preq,
6620 wpa_driver_nl80211_event_receive,
6621 bss->nl_cb);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006622
6623 return 0;
6624
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006625 out_err:
6626 nl_destroy_handles(&bss->nl_preq);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006627 return -1;
6628}
6629
6630
6631static int nl80211_disable_11b_rates(struct wpa_driver_nl80211_data *drv,
6632 int ifindex, int disabled)
6633{
6634 struct nl_msg *msg;
6635 struct nlattr *bands, *band;
6636 int ret;
6637
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08006638 wpa_printf(MSG_DEBUG,
6639 "nl80211: NL80211_CMD_SET_TX_BITRATE_MASK (ifindex=%d %s)",
6640 ifindex, disabled ? "NL80211_TXRATE_LEGACY=OFDM-only" :
6641 "no NL80211_TXRATE_LEGACY constraint");
6642
6643 msg = nl80211_ifindex_msg(drv, ifindex, 0,
6644 NL80211_CMD_SET_TX_BITRATE_MASK);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006645 if (!msg)
6646 return -1;
6647
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006648 bands = nla_nest_start(msg, NL80211_ATTR_TX_RATES);
6649 if (!bands)
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08006650 goto fail;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006651
6652 /*
6653 * Disable 2 GHz rates 1, 2, 5.5, 11 Mbps by masking out everything
6654 * else apart from 6, 9, 12, 18, 24, 36, 48, 54 Mbps from non-MCS
6655 * rates. All 5 GHz rates are left enabled.
6656 */
6657 band = nla_nest_start(msg, NL80211_BAND_2GHZ);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08006658 if (!band ||
6659 (disabled && nla_put(msg, NL80211_TXRATE_LEGACY, 8,
6660 "\x0c\x12\x18\x24\x30\x48\x60\x6c")))
6661 goto fail;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006662 nla_nest_end(msg, band);
6663
6664 nla_nest_end(msg, bands);
6665
6666 ret = send_and_recv_msgs(drv, msg, NULL, NULL);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006667 if (ret) {
6668 wpa_printf(MSG_DEBUG, "nl80211: Set TX rates failed: ret=%d "
6669 "(%s)", ret, strerror(-ret));
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07006670 } else
6671 drv->disabled_11b_rates = disabled;
6672
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006673 return ret;
6674
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08006675fail:
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006676 nlmsg_free(msg);
6677 return -1;
6678}
6679
6680
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006681static int wpa_driver_nl80211_deinit_ap(void *priv)
6682{
6683 struct i802_bss *bss = priv;
6684 struct wpa_driver_nl80211_data *drv = bss->drv;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006685 if (!is_ap_interface(drv->nlmode))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006686 return -1;
6687 wpa_driver_nl80211_del_beacon(drv);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08006688 bss->beacon_set = 0;
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -07006689
6690 /*
6691 * If the P2P GO interface was dynamically added, then it is
6692 * possible that the interface change to station is not possible.
6693 */
6694 if (drv->nlmode == NL80211_IFTYPE_P2P_GO && bss->if_dynamic)
6695 return 0;
6696
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006697 return wpa_driver_nl80211_set_mode(priv, NL80211_IFTYPE_STATION);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006698}
6699
6700
Dmitry Shmidtea69e842013-05-13 14:52:28 -07006701static int wpa_driver_nl80211_stop_ap(void *priv)
6702{
6703 struct i802_bss *bss = priv;
6704 struct wpa_driver_nl80211_data *drv = bss->drv;
6705 if (!is_ap_interface(drv->nlmode))
6706 return -1;
6707 wpa_driver_nl80211_del_beacon(drv);
6708 bss->beacon_set = 0;
6709 return 0;
6710}
6711
6712
Dmitry Shmidt04949592012-07-19 12:16:46 -07006713static int wpa_driver_nl80211_deinit_p2p_cli(void *priv)
6714{
6715 struct i802_bss *bss = priv;
6716 struct wpa_driver_nl80211_data *drv = bss->drv;
6717 if (drv->nlmode != NL80211_IFTYPE_P2P_CLIENT)
6718 return -1;
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -07006719
6720 /*
6721 * If the P2P Client interface was dynamically added, then it is
6722 * possible that the interface change to station is not possible.
6723 */
6724 if (bss->if_dynamic)
6725 return 0;
6726
Dmitry Shmidt04949592012-07-19 12:16:46 -07006727 return wpa_driver_nl80211_set_mode(priv, NL80211_IFTYPE_STATION);
6728}
6729
6730
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006731static void wpa_driver_nl80211_resume(void *priv)
6732{
6733 struct i802_bss *bss = priv;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08006734 enum nl80211_iftype nlmode = nl80211_get_ifmode(bss);
Dmitry Shmidt34af3062013-07-11 10:46:32 -07006735
6736 if (i802_set_iface_flags(bss, 1))
6737 wpa_printf(MSG_DEBUG, "nl80211: Failed to set interface up on resume event");
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08006738
6739 if (is_p2p_net_interface(nlmode))
6740 nl80211_disable_11b_rates(bss->drv, bss->drv->ifindex, 1);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006741}
6742
6743
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006744static int nl80211_signal_monitor(void *priv, int threshold, int hysteresis)
6745{
6746 struct i802_bss *bss = priv;
6747 struct wpa_driver_nl80211_data *drv = bss->drv;
Dmitry Shmidt8da800a2013-04-24 12:57:01 -07006748 struct nl_msg *msg;
6749 struct nlattr *cqm;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006750
6751 wpa_printf(MSG_DEBUG, "nl80211: Signal monitor threshold=%d "
6752 "hysteresis=%d", threshold, hysteresis);
6753
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08006754 if (!(msg = nl80211_bss_msg(bss, 0, NL80211_CMD_SET_CQM)) ||
6755 !(cqm = nla_nest_start(msg, NL80211_ATTR_CQM)) ||
6756 nla_put_u32(msg, NL80211_ATTR_CQM_RSSI_THOLD, threshold) ||
6757 nla_put_u32(msg, NL80211_ATTR_CQM_RSSI_HYST, hysteresis)) {
6758 nlmsg_free(msg);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006759 return -1;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08006760 }
Dmitry Shmidt8da800a2013-04-24 12:57:01 -07006761 nla_nest_end(msg, cqm);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006762
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08006763 return send_and_recv_msgs(drv, msg, NULL, NULL);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006764}
6765
6766
Dmitry Shmidt34af3062013-07-11 10:46:32 -07006767static int get_channel_width(struct nl_msg *msg, void *arg)
6768{
6769 struct nlattr *tb[NL80211_ATTR_MAX + 1];
6770 struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg));
6771 struct wpa_signal_info *sig_change = arg;
6772
6773 nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0),
6774 genlmsg_attrlen(gnlh, 0), NULL);
6775
6776 sig_change->center_frq1 = -1;
6777 sig_change->center_frq2 = -1;
6778 sig_change->chanwidth = CHAN_WIDTH_UNKNOWN;
6779
6780 if (tb[NL80211_ATTR_CHANNEL_WIDTH]) {
6781 sig_change->chanwidth = convert2width(
6782 nla_get_u32(tb[NL80211_ATTR_CHANNEL_WIDTH]));
6783 if (tb[NL80211_ATTR_CENTER_FREQ1])
6784 sig_change->center_frq1 =
6785 nla_get_u32(tb[NL80211_ATTR_CENTER_FREQ1]);
6786 if (tb[NL80211_ATTR_CENTER_FREQ2])
6787 sig_change->center_frq2 =
6788 nla_get_u32(tb[NL80211_ATTR_CENTER_FREQ2]);
6789 }
6790
6791 return NL_SKIP;
6792}
6793
6794
6795static int nl80211_get_channel_width(struct wpa_driver_nl80211_data *drv,
6796 struct wpa_signal_info *sig)
6797{
6798 struct nl_msg *msg;
6799
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08006800 msg = nl80211_drv_msg(drv, 0, NL80211_CMD_GET_INTERFACE);
Dmitry Shmidt34af3062013-07-11 10:46:32 -07006801 return send_and_recv_msgs(drv, msg, get_channel_width, sig);
Dmitry Shmidt34af3062013-07-11 10:46:32 -07006802}
6803
6804
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006805static int nl80211_signal_poll(void *priv, struct wpa_signal_info *si)
6806{
6807 struct i802_bss *bss = priv;
6808 struct wpa_driver_nl80211_data *drv = bss->drv;
6809 int res;
6810
6811 os_memset(si, 0, sizeof(*si));
6812 res = nl80211_get_link_signal(drv, si);
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08006813 if (res) {
6814 if (drv->nlmode != NL80211_IFTYPE_ADHOC &&
6815 drv->nlmode != NL80211_IFTYPE_MESH_POINT)
6816 return res;
6817 si->current_signal = 0;
6818 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006819
Dmitry Shmidt34af3062013-07-11 10:46:32 -07006820 res = nl80211_get_channel_width(drv, si);
6821 if (res != 0)
6822 return res;
6823
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006824 return nl80211_get_link_noise(drv, si);
6825}
6826
6827
6828static int nl80211_send_frame(void *priv, const u8 *data, size_t data_len,
6829 int encrypt)
6830{
6831 struct i802_bss *bss = priv;
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08006832 return wpa_driver_nl80211_send_frame(bss, data, data_len, encrypt, 0,
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08006833 0, 0, 0, 0, NULL, 0);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006834}
6835
6836
6837static int nl80211_set_param(void *priv, const char *param)
6838{
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006839 if (param == NULL)
6840 return 0;
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08006841 wpa_printf(MSG_DEBUG, "nl80211: driver param='%s'", param);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006842
6843#ifdef CONFIG_P2P
6844 if (os_strstr(param, "use_p2p_group_interface=1")) {
6845 struct i802_bss *bss = priv;
6846 struct wpa_driver_nl80211_data *drv = bss->drv;
6847
6848 wpa_printf(MSG_DEBUG, "nl80211: Use separate P2P group "
6849 "interface");
6850 drv->capa.flags |= WPA_DRIVER_FLAGS_P2P_CONCURRENT;
6851 drv->capa.flags |= WPA_DRIVER_FLAGS_P2P_MGMT_AND_NON_P2P;
6852 }
6853#endif /* CONFIG_P2P */
6854
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08006855 if (os_strstr(param, "use_monitor=1")) {
6856 struct i802_bss *bss = priv;
6857 struct wpa_driver_nl80211_data *drv = bss->drv;
6858 drv->use_monitor = 1;
6859 }
6860
6861 if (os_strstr(param, "force_connect_cmd=1")) {
6862 struct i802_bss *bss = priv;
6863 struct wpa_driver_nl80211_data *drv = bss->drv;
6864 drv->capa.flags &= ~WPA_DRIVER_FLAGS_SME;
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07006865 drv->force_connect_cmd = 1;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08006866 }
6867
Dmitry Shmidt7d5c8f22014-03-03 13:53:28 -08006868 if (os_strstr(param, "no_offchannel_tx=1")) {
6869 struct i802_bss *bss = priv;
6870 struct wpa_driver_nl80211_data *drv = bss->drv;
6871 drv->capa.flags &= ~WPA_DRIVER_FLAGS_OFFCHANNEL_TX;
6872 drv->test_use_roc_tx = 1;
6873 }
6874
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006875 return 0;
6876}
6877
6878
Dmitry Shmidte4663042016-04-04 10:07:49 -07006879static void * nl80211_global_init(void *ctx)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006880{
6881 struct nl80211_global *global;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006882 struct netlink_config *cfg;
6883
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006884 global = os_zalloc(sizeof(*global));
6885 if (global == NULL)
6886 return NULL;
Dmitry Shmidte4663042016-04-04 10:07:49 -07006887 global->ctx = ctx;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006888 global->ioctl_sock = -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006889 dl_list_init(&global->interfaces);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006890 global->if_add_ifindex = -1;
6891
6892 cfg = os_zalloc(sizeof(*cfg));
6893 if (cfg == NULL)
6894 goto err;
6895
6896 cfg->ctx = global;
6897 cfg->newlink_cb = wpa_driver_nl80211_event_rtm_newlink;
6898 cfg->dellink_cb = wpa_driver_nl80211_event_rtm_dellink;
6899 global->netlink = netlink_init(cfg);
6900 if (global->netlink == NULL) {
6901 os_free(cfg);
6902 goto err;
6903 }
6904
6905 if (wpa_driver_nl80211_init_nl_global(global) < 0)
6906 goto err;
6907
6908 global->ioctl_sock = socket(PF_INET, SOCK_DGRAM, 0);
6909 if (global->ioctl_sock < 0) {
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -07006910 wpa_printf(MSG_ERROR, "nl80211: socket(PF_INET,SOCK_DGRAM) failed: %s",
6911 strerror(errno));
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006912 goto err;
6913 }
6914
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006915 return global;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006916
6917err:
6918 nl80211_global_deinit(global);
6919 return NULL;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006920}
6921
6922
6923static void nl80211_global_deinit(void *priv)
6924{
6925 struct nl80211_global *global = priv;
6926 if (global == NULL)
6927 return;
6928 if (!dl_list_empty(&global->interfaces)) {
6929 wpa_printf(MSG_ERROR, "nl80211: %u interface(s) remain at "
6930 "nl80211_global_deinit",
6931 dl_list_len(&global->interfaces));
6932 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006933
6934 if (global->netlink)
6935 netlink_deinit(global->netlink);
6936
6937 nl_destroy_handles(&global->nl);
6938
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -07006939 if (global->nl_event)
6940 nl80211_destroy_eloop_handle(&global->nl_event);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006941
6942 nl_cb_put(global->nl_cb);
6943
6944 if (global->ioctl_sock >= 0)
6945 close(global->ioctl_sock);
6946
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006947 os_free(global);
6948}
6949
6950
6951static const char * nl80211_get_radio_name(void *priv)
6952{
6953 struct i802_bss *bss = priv;
6954 struct wpa_driver_nl80211_data *drv = bss->drv;
6955 return drv->phyname;
6956}
6957
6958
Jouni Malinen75ecf522011-06-27 15:19:46 -07006959static int nl80211_pmkid(struct i802_bss *bss, int cmd, const u8 *bssid,
6960 const u8 *pmkid)
6961{
6962 struct nl_msg *msg;
6963
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08006964 if (!(msg = nl80211_bss_msg(bss, 0, cmd)) ||
6965 (pmkid && nla_put(msg, NL80211_ATTR_PMKID, 16, pmkid)) ||
6966 (bssid && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid))) {
6967 nlmsg_free(msg);
6968 return -ENOBUFS;
6969 }
Jouni Malinen75ecf522011-06-27 15:19:46 -07006970
6971 return send_and_recv_msgs(bss->drv, msg, NULL, NULL);
Jouni Malinen75ecf522011-06-27 15:19:46 -07006972}
6973
6974
6975static int nl80211_add_pmkid(void *priv, const u8 *bssid, const u8 *pmkid)
6976{
6977 struct i802_bss *bss = priv;
6978 wpa_printf(MSG_DEBUG, "nl80211: Add PMKID for " MACSTR, MAC2STR(bssid));
6979 return nl80211_pmkid(bss, NL80211_CMD_SET_PMKSA, bssid, pmkid);
6980}
6981
6982
6983static int nl80211_remove_pmkid(void *priv, const u8 *bssid, const u8 *pmkid)
6984{
6985 struct i802_bss *bss = priv;
6986 wpa_printf(MSG_DEBUG, "nl80211: Delete PMKID for " MACSTR,
6987 MAC2STR(bssid));
6988 return nl80211_pmkid(bss, NL80211_CMD_DEL_PMKSA, bssid, pmkid);
6989}
6990
6991
6992static int nl80211_flush_pmkid(void *priv)
6993{
6994 struct i802_bss *bss = priv;
6995 wpa_printf(MSG_DEBUG, "nl80211: Flush PMKIDs");
6996 return nl80211_pmkid(bss, NL80211_CMD_FLUSH_PMKSA, NULL, NULL);
6997}
6998
6999
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -07007000static void clean_survey_results(struct survey_results *survey_results)
7001{
7002 struct freq_survey *survey, *tmp;
7003
7004 if (dl_list_empty(&survey_results->survey_list))
7005 return;
7006
7007 dl_list_for_each_safe(survey, tmp, &survey_results->survey_list,
7008 struct freq_survey, list) {
7009 dl_list_del(&survey->list);
7010 os_free(survey);
7011 }
7012}
7013
7014
7015static void add_survey(struct nlattr **sinfo, u32 ifidx,
7016 struct dl_list *survey_list)
7017{
7018 struct freq_survey *survey;
7019
7020 survey = os_zalloc(sizeof(struct freq_survey));
7021 if (!survey)
7022 return;
7023
7024 survey->ifidx = ifidx;
7025 survey->freq = nla_get_u32(sinfo[NL80211_SURVEY_INFO_FREQUENCY]);
7026 survey->filled = 0;
7027
7028 if (sinfo[NL80211_SURVEY_INFO_NOISE]) {
7029 survey->nf = (int8_t)
7030 nla_get_u8(sinfo[NL80211_SURVEY_INFO_NOISE]);
7031 survey->filled |= SURVEY_HAS_NF;
7032 }
7033
7034 if (sinfo[NL80211_SURVEY_INFO_CHANNEL_TIME]) {
7035 survey->channel_time =
7036 nla_get_u64(sinfo[NL80211_SURVEY_INFO_CHANNEL_TIME]);
7037 survey->filled |= SURVEY_HAS_CHAN_TIME;
7038 }
7039
7040 if (sinfo[NL80211_SURVEY_INFO_CHANNEL_TIME_BUSY]) {
7041 survey->channel_time_busy =
7042 nla_get_u64(sinfo[NL80211_SURVEY_INFO_CHANNEL_TIME_BUSY]);
7043 survey->filled |= SURVEY_HAS_CHAN_TIME_BUSY;
7044 }
7045
7046 if (sinfo[NL80211_SURVEY_INFO_CHANNEL_TIME_RX]) {
7047 survey->channel_time_rx =
7048 nla_get_u64(sinfo[NL80211_SURVEY_INFO_CHANNEL_TIME_RX]);
7049 survey->filled |= SURVEY_HAS_CHAN_TIME_RX;
7050 }
7051
7052 if (sinfo[NL80211_SURVEY_INFO_CHANNEL_TIME_TX]) {
7053 survey->channel_time_tx =
7054 nla_get_u64(sinfo[NL80211_SURVEY_INFO_CHANNEL_TIME_TX]);
7055 survey->filled |= SURVEY_HAS_CHAN_TIME_TX;
7056 }
7057
7058 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)",
7059 survey->freq,
7060 survey->nf,
7061 (unsigned long int) survey->channel_time,
7062 (unsigned long int) survey->channel_time_busy,
7063 (unsigned long int) survey->channel_time_tx,
7064 (unsigned long int) survey->channel_time_rx,
7065 survey->filled);
7066
7067 dl_list_add_tail(survey_list, &survey->list);
7068}
7069
7070
7071static int check_survey_ok(struct nlattr **sinfo, u32 surveyed_freq,
7072 unsigned int freq_filter)
7073{
7074 if (!freq_filter)
7075 return 1;
7076
7077 return freq_filter == surveyed_freq;
7078}
7079
7080
7081static int survey_handler(struct nl_msg *msg, void *arg)
7082{
7083 struct nlattr *tb[NL80211_ATTR_MAX + 1];
7084 struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg));
7085 struct nlattr *sinfo[NL80211_SURVEY_INFO_MAX + 1];
7086 struct survey_results *survey_results;
7087 u32 surveyed_freq = 0;
7088 u32 ifidx;
7089
7090 static struct nla_policy survey_policy[NL80211_SURVEY_INFO_MAX + 1] = {
7091 [NL80211_SURVEY_INFO_FREQUENCY] = { .type = NLA_U32 },
7092 [NL80211_SURVEY_INFO_NOISE] = { .type = NLA_U8 },
7093 };
7094
7095 survey_results = (struct survey_results *) arg;
7096
7097 nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0),
7098 genlmsg_attrlen(gnlh, 0), NULL);
7099
Dmitry Shmidt97672262014-02-03 13:02:54 -08007100 if (!tb[NL80211_ATTR_IFINDEX])
7101 return NL_SKIP;
7102
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -07007103 ifidx = nla_get_u32(tb[NL80211_ATTR_IFINDEX]);
7104
7105 if (!tb[NL80211_ATTR_SURVEY_INFO])
7106 return NL_SKIP;
7107
7108 if (nla_parse_nested(sinfo, NL80211_SURVEY_INFO_MAX,
7109 tb[NL80211_ATTR_SURVEY_INFO],
7110 survey_policy))
7111 return NL_SKIP;
7112
7113 if (!sinfo[NL80211_SURVEY_INFO_FREQUENCY]) {
7114 wpa_printf(MSG_ERROR, "nl80211: Invalid survey data");
7115 return NL_SKIP;
7116 }
7117
7118 surveyed_freq = nla_get_u32(sinfo[NL80211_SURVEY_INFO_FREQUENCY]);
7119
7120 if (!check_survey_ok(sinfo, surveyed_freq,
7121 survey_results->freq_filter))
7122 return NL_SKIP;
7123
7124 if (survey_results->freq_filter &&
7125 survey_results->freq_filter != surveyed_freq) {
7126 wpa_printf(MSG_EXCESSIVE, "nl80211: Ignoring survey data for freq %d MHz",
7127 surveyed_freq);
7128 return NL_SKIP;
7129 }
7130
7131 add_survey(sinfo, ifidx, &survey_results->survey_list);
7132
7133 return NL_SKIP;
7134}
7135
7136
7137static int wpa_driver_nl80211_get_survey(void *priv, unsigned int freq)
7138{
7139 struct i802_bss *bss = priv;
7140 struct wpa_driver_nl80211_data *drv = bss->drv;
7141 struct nl_msg *msg;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08007142 int err;
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -07007143 union wpa_event_data data;
7144 struct survey_results *survey_results;
7145
7146 os_memset(&data, 0, sizeof(data));
7147 survey_results = &data.survey_results;
7148
7149 dl_list_init(&survey_results->survey_list);
7150
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08007151 msg = nl80211_drv_msg(drv, NLM_F_DUMP, NL80211_CMD_GET_SURVEY);
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -07007152 if (!msg)
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08007153 return -ENOBUFS;
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -07007154
7155 if (freq)
7156 data.survey_results.freq_filter = freq;
7157
7158 do {
7159 wpa_printf(MSG_DEBUG, "nl80211: Fetch survey data");
7160 err = send_and_recv_msgs(drv, msg, survey_handler,
7161 survey_results);
7162 } while (err > 0);
7163
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08007164 if (err)
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -07007165 wpa_printf(MSG_ERROR, "nl80211: Failed to process survey data");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08007166 else
7167 wpa_supplicant_event(drv->ctx, EVENT_SURVEY, &data);
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -07007168
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -07007169 clean_survey_results(survey_results);
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -07007170 return err;
7171}
7172
7173
Dmitry Shmidt807291d2015-01-27 13:40:23 -08007174static void nl80211_set_rekey_info(void *priv, const u8 *kek, size_t kek_len,
7175 const u8 *kck, size_t kck_len,
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08007176 const u8 *replay_ctr)
7177{
7178 struct i802_bss *bss = priv;
7179 struct wpa_driver_nl80211_data *drv = bss->drv;
7180 struct nlattr *replay_nested;
7181 struct nl_msg *msg;
Dmitry Shmidtff787d52015-01-12 13:01:47 -08007182 int ret;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08007183
Dmitry Shmidtff787d52015-01-12 13:01:47 -08007184 if (!drv->set_rekey_offload)
7185 return;
7186
7187 wpa_printf(MSG_DEBUG, "nl80211: Set rekey offload");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08007188 if (!(msg = nl80211_bss_msg(bss, 0, NL80211_CMD_SET_REKEY_OFFLOAD)) ||
7189 !(replay_nested = nla_nest_start(msg, NL80211_ATTR_REKEY_DATA)) ||
Dmitry Shmidt807291d2015-01-27 13:40:23 -08007190 nla_put(msg, NL80211_REKEY_DATA_KEK, kek_len, kek) ||
7191 nla_put(msg, NL80211_REKEY_DATA_KCK, kck_len, kck) ||
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08007192 nla_put(msg, NL80211_REKEY_DATA_REPLAY_CTR, NL80211_REPLAY_CTR_LEN,
7193 replay_ctr)) {
7194 nl80211_nlmsg_clear(msg);
7195 nlmsg_free(msg);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08007196 return;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08007197 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08007198
7199 nla_nest_end(msg, replay_nested);
7200
Dmitry Shmidtff787d52015-01-12 13:01:47 -08007201 ret = send_and_recv_msgs(drv, msg, NULL, (void *) -1);
7202 if (ret == -EOPNOTSUPP) {
7203 wpa_printf(MSG_DEBUG,
7204 "nl80211: Driver does not support rekey offload");
7205 drv->set_rekey_offload = 0;
7206 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08007207}
7208
7209
7210static void nl80211_send_null_frame(struct i802_bss *bss, const u8 *own_addr,
7211 const u8 *addr, int qos)
7212{
7213 /* send data frame to poll STA and check whether
7214 * this frame is ACKed */
7215 struct {
7216 struct ieee80211_hdr hdr;
7217 u16 qos_ctl;
7218 } STRUCT_PACKED nulldata;
7219 size_t size;
7220
7221 /* Send data frame to poll STA and check whether this frame is ACKed */
7222
7223 os_memset(&nulldata, 0, sizeof(nulldata));
7224
7225 if (qos) {
7226 nulldata.hdr.frame_control =
7227 IEEE80211_FC(WLAN_FC_TYPE_DATA,
7228 WLAN_FC_STYPE_QOS_NULL);
7229 size = sizeof(nulldata);
7230 } else {
7231 nulldata.hdr.frame_control =
7232 IEEE80211_FC(WLAN_FC_TYPE_DATA,
7233 WLAN_FC_STYPE_NULLFUNC);
7234 size = sizeof(struct ieee80211_hdr);
7235 }
7236
7237 nulldata.hdr.frame_control |= host_to_le16(WLAN_FC_FROMDS);
7238 os_memcpy(nulldata.hdr.IEEE80211_DA_FROMDS, addr, ETH_ALEN);
7239 os_memcpy(nulldata.hdr.IEEE80211_BSSID_FROMDS, own_addr, ETH_ALEN);
7240 os_memcpy(nulldata.hdr.IEEE80211_SA_FROMDS, own_addr, ETH_ALEN);
7241
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08007242 if (wpa_driver_nl80211_send_mlme(bss, (u8 *) &nulldata, size, 0, 0, 0,
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08007243 0, 0, NULL, 0) < 0)
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08007244 wpa_printf(MSG_DEBUG, "nl80211_send_null_frame: Failed to "
7245 "send poll frame");
7246}
7247
7248static void nl80211_poll_client(void *priv, const u8 *own_addr, const u8 *addr,
7249 int qos)
7250{
7251 struct i802_bss *bss = priv;
7252 struct wpa_driver_nl80211_data *drv = bss->drv;
7253 struct nl_msg *msg;
Dmitry Shmidt7f656022015-02-25 14:36:37 -08007254 int ret;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08007255
7256 if (!drv->poll_command_supported) {
7257 nl80211_send_null_frame(bss, own_addr, addr, qos);
7258 return;
7259 }
7260
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08007261 if (!(msg = nl80211_bss_msg(bss, 0, NL80211_CMD_PROBE_CLIENT)) ||
7262 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) {
7263 nlmsg_free(msg);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08007264 return;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08007265 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08007266
Dmitry Shmidt7f656022015-02-25 14:36:37 -08007267 ret = send_and_recv_msgs(drv, msg, NULL, NULL);
7268 if (ret < 0) {
7269 wpa_printf(MSG_DEBUG, "nl80211: Client probe request for "
7270 MACSTR " failed: ret=%d (%s)",
7271 MAC2STR(addr), ret, strerror(-ret));
7272 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08007273}
7274
7275
7276static int nl80211_set_power_save(struct i802_bss *bss, int enabled)
7277{
7278 struct nl_msg *msg;
7279
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08007280 if (!(msg = nl80211_bss_msg(bss, 0, NL80211_CMD_SET_POWER_SAVE)) ||
7281 nla_put_u32(msg, NL80211_ATTR_PS_STATE,
7282 enabled ? NL80211_PS_ENABLED : NL80211_PS_DISABLED)) {
7283 nlmsg_free(msg);
7284 return -ENOBUFS;
7285 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08007286 return send_and_recv_msgs(bss->drv, msg, NULL, NULL);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08007287}
7288
7289
7290static int nl80211_set_p2p_powersave(void *priv, int legacy_ps, int opp_ps,
7291 int ctwindow)
7292{
7293 struct i802_bss *bss = priv;
7294
7295 wpa_printf(MSG_DEBUG, "nl80211: set_p2p_powersave (legacy_ps=%d "
7296 "opp_ps=%d ctwindow=%d)", legacy_ps, opp_ps, ctwindow);
7297
Dmitry Shmidt292b0c32013-11-22 12:54:42 -08007298 if (opp_ps != -1 || ctwindow != -1) {
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08007299#ifdef ANDROID_P2P
7300 wpa_driver_set_p2p_ps(priv, legacy_ps, opp_ps, ctwindow);
Dmitry Shmidt292b0c32013-11-22 12:54:42 -08007301#else /* ANDROID_P2P */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08007302 return -1; /* Not yet supported */
Dmitry Shmidt292b0c32013-11-22 12:54:42 -08007303#endif /* ANDROID_P2P */
7304 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08007305
7306 if (legacy_ps == -1)
7307 return 0;
7308 if (legacy_ps != 0 && legacy_ps != 1)
7309 return -1; /* Not yet supported */
7310
7311 return nl80211_set_power_save(bss, legacy_ps);
7312}
7313
7314
Dmitry Shmidt051af732013-10-22 13:52:46 -07007315static int nl80211_start_radar_detection(void *priv,
7316 struct hostapd_freq_params *freq)
Dmitry Shmidtea69e842013-05-13 14:52:28 -07007317{
7318 struct i802_bss *bss = priv;
7319 struct wpa_driver_nl80211_data *drv = bss->drv;
7320 struct nl_msg *msg;
7321 int ret;
7322
Dmitry Shmidt051af732013-10-22 13:52:46 -07007323 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)",
7324 freq->freq, freq->ht_enabled, freq->vht_enabled,
7325 freq->bandwidth, freq->center_freq1, freq->center_freq2);
7326
Dmitry Shmidtea69e842013-05-13 14:52:28 -07007327 if (!(drv->capa.flags & WPA_DRIVER_FLAGS_RADAR)) {
7328 wpa_printf(MSG_DEBUG, "nl80211: Driver does not support radar "
7329 "detection");
7330 return -1;
7331 }
7332
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08007333 if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_RADAR_DETECT)) ||
7334 nl80211_put_freq_params(msg, freq) < 0) {
7335 nlmsg_free(msg);
Dmitry Shmidtea69e842013-05-13 14:52:28 -07007336 return -1;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08007337 }
Dmitry Shmidtea69e842013-05-13 14:52:28 -07007338
7339 ret = send_and_recv_msgs(drv, msg, NULL, NULL);
7340 if (ret == 0)
7341 return 0;
7342 wpa_printf(MSG_DEBUG, "nl80211: Failed to start radar detection: "
7343 "%d (%s)", ret, strerror(-ret));
Dmitry Shmidtea69e842013-05-13 14:52:28 -07007344 return -1;
7345}
7346
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08007347#ifdef CONFIG_TDLS
7348
7349static int nl80211_send_tdls_mgmt(void *priv, const u8 *dst, u8 action_code,
7350 u8 dialog_token, u16 status_code,
Dmitry Shmidt9ead16e2014-10-07 13:15:23 -07007351 u32 peer_capab, int initiator, const u8 *buf,
7352 size_t len)
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08007353{
7354 struct i802_bss *bss = priv;
7355 struct wpa_driver_nl80211_data *drv = bss->drv;
7356 struct nl_msg *msg;
7357
7358 if (!(drv->capa.flags & WPA_DRIVER_FLAGS_TDLS_SUPPORT))
7359 return -EOPNOTSUPP;
7360
7361 if (!dst)
7362 return -EINVAL;
7363
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08007364 if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_TDLS_MGMT)) ||
7365 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, dst) ||
7366 nla_put_u8(msg, NL80211_ATTR_TDLS_ACTION, action_code) ||
7367 nla_put_u8(msg, NL80211_ATTR_TDLS_DIALOG_TOKEN, dialog_token) ||
7368 nla_put_u16(msg, NL80211_ATTR_STATUS_CODE, status_code))
7369 goto fail;
Dmitry Shmidtdf5a7e42014-04-02 12:59:59 -07007370 if (peer_capab) {
7371 /*
7372 * The internal enum tdls_peer_capability definition is
7373 * currently identical with the nl80211 enum
7374 * nl80211_tdls_peer_capability, so no conversion is needed
7375 * here.
7376 */
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08007377 if (nla_put_u32(msg, NL80211_ATTR_TDLS_PEER_CAPABILITY,
7378 peer_capab))
7379 goto fail;
Dmitry Shmidtdf5a7e42014-04-02 12:59:59 -07007380 }
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08007381 if ((initiator &&
7382 nla_put_flag(msg, NL80211_ATTR_TDLS_INITIATOR)) ||
7383 nla_put(msg, NL80211_ATTR_IE, len, buf))
7384 goto fail;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08007385
7386 return send_and_recv_msgs(drv, msg, NULL, NULL);
7387
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08007388fail:
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08007389 nlmsg_free(msg);
7390 return -ENOBUFS;
7391}
7392
7393
7394static int nl80211_tdls_oper(void *priv, enum tdls_oper oper, const u8 *peer)
7395{
7396 struct i802_bss *bss = priv;
7397 struct wpa_driver_nl80211_data *drv = bss->drv;
7398 struct nl_msg *msg;
7399 enum nl80211_tdls_operation nl80211_oper;
7400
7401 if (!(drv->capa.flags & WPA_DRIVER_FLAGS_TDLS_SUPPORT))
7402 return -EOPNOTSUPP;
7403
7404 switch (oper) {
7405 case TDLS_DISCOVERY_REQ:
7406 nl80211_oper = NL80211_TDLS_DISCOVERY_REQ;
7407 break;
7408 case TDLS_SETUP:
7409 nl80211_oper = NL80211_TDLS_SETUP;
7410 break;
7411 case TDLS_TEARDOWN:
7412 nl80211_oper = NL80211_TDLS_TEARDOWN;
7413 break;
7414 case TDLS_ENABLE_LINK:
7415 nl80211_oper = NL80211_TDLS_ENABLE_LINK;
7416 break;
7417 case TDLS_DISABLE_LINK:
7418 nl80211_oper = NL80211_TDLS_DISABLE_LINK;
7419 break;
7420 case TDLS_ENABLE:
7421 return 0;
7422 case TDLS_DISABLE:
7423 return 0;
7424 default:
7425 return -EINVAL;
7426 }
7427
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08007428 if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_TDLS_OPER)) ||
7429 nla_put_u8(msg, NL80211_ATTR_TDLS_OPERATION, nl80211_oper) ||
7430 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer)) {
7431 nlmsg_free(msg);
7432 return -ENOBUFS;
7433 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08007434
7435 return send_and_recv_msgs(drv, msg, NULL, NULL);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08007436}
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08007437
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08007438
7439static int
7440nl80211_tdls_enable_channel_switch(void *priv, const u8 *addr, u8 oper_class,
7441 const struct hostapd_freq_params *params)
7442{
7443 struct i802_bss *bss = priv;
7444 struct wpa_driver_nl80211_data *drv = bss->drv;
7445 struct nl_msg *msg;
7446 int ret = -ENOBUFS;
7447
7448 if (!(drv->capa.flags & WPA_DRIVER_FLAGS_TDLS_SUPPORT) ||
7449 !(drv->capa.flags & WPA_DRIVER_FLAGS_TDLS_CHANNEL_SWITCH))
7450 return -EOPNOTSUPP;
7451
7452 wpa_printf(MSG_DEBUG, "nl80211: Enable TDLS channel switch " MACSTR
7453 " oper_class=%u freq=%u",
7454 MAC2STR(addr), oper_class, params->freq);
7455 msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_TDLS_CHANNEL_SWITCH);
7456 if (!msg ||
7457 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) ||
7458 nla_put_u8(msg, NL80211_ATTR_OPER_CLASS, oper_class) ||
7459 (ret = nl80211_put_freq_params(msg, params))) {
7460 nlmsg_free(msg);
7461 wpa_printf(MSG_DEBUG, "nl80211: Could not build TDLS chan switch");
7462 return ret;
7463 }
7464
7465 return send_and_recv_msgs(drv, msg, NULL, NULL);
7466}
7467
7468
7469static int
7470nl80211_tdls_disable_channel_switch(void *priv, const u8 *addr)
7471{
7472 struct i802_bss *bss = priv;
7473 struct wpa_driver_nl80211_data *drv = bss->drv;
7474 struct nl_msg *msg;
7475
7476 if (!(drv->capa.flags & WPA_DRIVER_FLAGS_TDLS_SUPPORT) ||
7477 !(drv->capa.flags & WPA_DRIVER_FLAGS_TDLS_CHANNEL_SWITCH))
7478 return -EOPNOTSUPP;
7479
7480 wpa_printf(MSG_DEBUG, "nl80211: Disable TDLS channel switch " MACSTR,
7481 MAC2STR(addr));
7482 msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_TDLS_CANCEL_CHANNEL_SWITCH);
7483 if (!msg ||
7484 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) {
7485 nlmsg_free(msg);
7486 wpa_printf(MSG_DEBUG,
7487 "nl80211: Could not build TDLS cancel chan switch");
7488 return -ENOBUFS;
7489 }
7490
7491 return send_and_recv_msgs(drv, msg, NULL, NULL);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08007492}
7493
7494#endif /* CONFIG TDLS */
7495
7496
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08007497static int driver_nl80211_set_key(const char *ifname, void *priv,
7498 enum wpa_alg alg, const u8 *addr,
7499 int key_idx, int set_tx,
7500 const u8 *seq, size_t seq_len,
7501 const u8 *key, size_t key_len)
7502{
7503 struct i802_bss *bss = priv;
7504 return wpa_driver_nl80211_set_key(ifname, bss, alg, addr, key_idx,
7505 set_tx, seq, seq_len, key, key_len);
7506}
7507
7508
7509static int driver_nl80211_scan2(void *priv,
7510 struct wpa_driver_scan_params *params)
7511{
7512 struct i802_bss *bss = priv;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08007513#ifdef CONFIG_DRIVER_NL80211_QCA
7514 struct wpa_driver_nl80211_data *drv = bss->drv;
7515
7516 /*
7517 * Do a vendor specific scan if possible. If only_new_results is
7518 * set, do a normal scan since a kernel (cfg80211) BSS cache flush
7519 * cannot be achieved through a vendor scan. The below condition may
7520 * need to be modified if new scan flags are added in the future whose
7521 * functionality can only be achieved through a normal scan.
7522 */
7523 if (drv->scan_vendor_cmd_avail && !params->only_new_results)
7524 return wpa_driver_nl80211_vendor_scan(bss, params);
7525#endif /* CONFIG_DRIVER_NL80211_QCA */
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08007526 return wpa_driver_nl80211_scan(bss, params);
7527}
7528
7529
7530static int driver_nl80211_deauthenticate(void *priv, const u8 *addr,
7531 int reason_code)
7532{
7533 struct i802_bss *bss = priv;
7534 return wpa_driver_nl80211_deauthenticate(bss, addr, reason_code);
7535}
7536
7537
7538static int driver_nl80211_authenticate(void *priv,
7539 struct wpa_driver_auth_params *params)
7540{
7541 struct i802_bss *bss = priv;
7542 return wpa_driver_nl80211_authenticate(bss, params);
7543}
7544
7545
7546static void driver_nl80211_deinit(void *priv)
7547{
7548 struct i802_bss *bss = priv;
7549 wpa_driver_nl80211_deinit(bss);
7550}
7551
7552
7553static int driver_nl80211_if_remove(void *priv, enum wpa_driver_if_type type,
7554 const char *ifname)
7555{
7556 struct i802_bss *bss = priv;
7557 return wpa_driver_nl80211_if_remove(bss, type, ifname);
7558}
7559
7560
7561static int driver_nl80211_send_mlme(void *priv, const u8 *data,
Dmitry Shmidta3dc3092015-06-23 11:21:28 -07007562 size_t data_len, int noack,
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08007563 unsigned int freq,
7564 const u16 *csa_offs, size_t csa_offs_len)
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08007565{
7566 struct i802_bss *bss = priv;
7567 return wpa_driver_nl80211_send_mlme(bss, data, data_len, noack,
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08007568 freq, 0, 0, 0, csa_offs,
7569 csa_offs_len);
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08007570}
7571
7572
7573static int driver_nl80211_sta_remove(void *priv, const u8 *addr)
7574{
7575 struct i802_bss *bss = priv;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08007576 return wpa_driver_nl80211_sta_remove(bss, addr, -1, 0);
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08007577}
7578
7579
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08007580static int driver_nl80211_set_sta_vlan(void *priv, const u8 *addr,
7581 const char *ifname, int vlan_id)
7582{
7583 struct i802_bss *bss = priv;
7584 return i802_set_sta_vlan(bss, addr, ifname, vlan_id);
7585}
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08007586
7587
7588static int driver_nl80211_read_sta_data(void *priv,
7589 struct hostap_sta_driver_data *data,
7590 const u8 *addr)
7591{
7592 struct i802_bss *bss = priv;
7593 return i802_read_sta_data(bss, data, addr);
7594}
7595
7596
7597static int driver_nl80211_send_action(void *priv, unsigned int freq,
7598 unsigned int wait_time,
7599 const u8 *dst, const u8 *src,
7600 const u8 *bssid,
7601 const u8 *data, size_t data_len,
7602 int no_cck)
7603{
7604 struct i802_bss *bss = priv;
7605 return wpa_driver_nl80211_send_action(bss, freq, wait_time, dst, src,
7606 bssid, data, data_len, no_cck);
7607}
7608
7609
7610static int driver_nl80211_probe_req_report(void *priv, int report)
7611{
7612 struct i802_bss *bss = priv;
7613 return wpa_driver_nl80211_probe_req_report(bss, report);
7614}
7615
7616
Dmitry Shmidt700a1372013-03-15 14:14:44 -07007617static int wpa_driver_nl80211_update_ft_ies(void *priv, const u8 *md,
7618 const u8 *ies, size_t ies_len)
7619{
7620 int ret;
7621 struct nl_msg *msg;
7622 struct i802_bss *bss = priv;
7623 struct wpa_driver_nl80211_data *drv = bss->drv;
7624 u16 mdid = WPA_GET_LE16(md);
7625
Dmitry Shmidt700a1372013-03-15 14:14:44 -07007626 wpa_printf(MSG_DEBUG, "nl80211: Updating FT IEs");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08007627 if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_UPDATE_FT_IES)) ||
7628 nla_put(msg, NL80211_ATTR_IE, ies_len, ies) ||
7629 nla_put_u16(msg, NL80211_ATTR_MDID, mdid)) {
7630 nlmsg_free(msg);
7631 return -ENOBUFS;
7632 }
Dmitry Shmidt700a1372013-03-15 14:14:44 -07007633
7634 ret = send_and_recv_msgs(drv, msg, NULL, NULL);
7635 if (ret) {
7636 wpa_printf(MSG_DEBUG, "nl80211: update_ft_ies failed "
7637 "err=%d (%s)", ret, strerror(-ret));
7638 }
7639
7640 return ret;
Dmitry Shmidt700a1372013-03-15 14:14:44 -07007641}
7642
7643
Dmitry Shmidt34af3062013-07-11 10:46:32 -07007644const u8 * wpa_driver_nl80211_get_macaddr(void *priv)
7645{
7646 struct i802_bss *bss = priv;
7647 struct wpa_driver_nl80211_data *drv = bss->drv;
7648
7649 if (drv->nlmode != NL80211_IFTYPE_P2P_DEVICE)
7650 return NULL;
7651
7652 return bss->addr;
7653}
7654
7655
Dmitry Shmidt56052862013-10-04 10:23:25 -07007656static const char * scan_state_str(enum scan_states scan_state)
7657{
7658 switch (scan_state) {
7659 case NO_SCAN:
7660 return "NO_SCAN";
7661 case SCAN_REQUESTED:
7662 return "SCAN_REQUESTED";
7663 case SCAN_STARTED:
7664 return "SCAN_STARTED";
7665 case SCAN_COMPLETED:
7666 return "SCAN_COMPLETED";
7667 case SCAN_ABORTED:
7668 return "SCAN_ABORTED";
7669 case SCHED_SCAN_STARTED:
7670 return "SCHED_SCAN_STARTED";
7671 case SCHED_SCAN_STOPPED:
7672 return "SCHED_SCAN_STOPPED";
7673 case SCHED_SCAN_RESULTS:
7674 return "SCHED_SCAN_RESULTS";
7675 }
7676
7677 return "??";
7678}
7679
7680
7681static int wpa_driver_nl80211_status(void *priv, char *buf, size_t buflen)
7682{
7683 struct i802_bss *bss = priv;
7684 struct wpa_driver_nl80211_data *drv = bss->drv;
7685 int res;
7686 char *pos, *end;
7687
7688 pos = buf;
7689 end = buf + buflen;
7690
7691 res = os_snprintf(pos, end - pos,
7692 "ifindex=%d\n"
7693 "ifname=%s\n"
7694 "brname=%s\n"
7695 "addr=" MACSTR "\n"
7696 "freq=%d\n"
7697 "%s%s%s%s%s",
7698 bss->ifindex,
7699 bss->ifname,
7700 bss->brname,
7701 MAC2STR(bss->addr),
7702 bss->freq,
7703 bss->beacon_set ? "beacon_set=1\n" : "",
7704 bss->added_if_into_bridge ?
7705 "added_if_into_bridge=1\n" : "",
7706 bss->added_bridge ? "added_bridge=1\n" : "",
7707 bss->in_deinit ? "in_deinit=1\n" : "",
7708 bss->if_dynamic ? "if_dynamic=1\n" : "");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08007709 if (os_snprintf_error(end - pos, res))
Dmitry Shmidt56052862013-10-04 10:23:25 -07007710 return pos - buf;
7711 pos += res;
7712
7713 if (bss->wdev_id_set) {
7714 res = os_snprintf(pos, end - pos, "wdev_id=%llu\n",
7715 (unsigned long long) bss->wdev_id);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08007716 if (os_snprintf_error(end - pos, res))
Dmitry Shmidt56052862013-10-04 10:23:25 -07007717 return pos - buf;
7718 pos += res;
7719 }
7720
7721 res = os_snprintf(pos, end - pos,
7722 "phyname=%s\n"
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07007723 "perm_addr=" MACSTR "\n"
Dmitry Shmidt56052862013-10-04 10:23:25 -07007724 "drv_ifindex=%d\n"
7725 "operstate=%d\n"
7726 "scan_state=%s\n"
7727 "auth_bssid=" MACSTR "\n"
7728 "auth_attempt_bssid=" MACSTR "\n"
7729 "bssid=" MACSTR "\n"
7730 "prev_bssid=" MACSTR "\n"
7731 "associated=%d\n"
7732 "assoc_freq=%u\n"
7733 "monitor_sock=%d\n"
7734 "monitor_ifidx=%d\n"
7735 "monitor_refcount=%d\n"
7736 "last_mgmt_freq=%u\n"
7737 "eapol_tx_sock=%d\n"
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08007738 "%s%s%s%s%s%s%s%s%s%s%s%s%s",
Dmitry Shmidt56052862013-10-04 10:23:25 -07007739 drv->phyname,
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07007740 MAC2STR(drv->perm_addr),
Dmitry Shmidt56052862013-10-04 10:23:25 -07007741 drv->ifindex,
7742 drv->operstate,
7743 scan_state_str(drv->scan_state),
7744 MAC2STR(drv->auth_bssid),
7745 MAC2STR(drv->auth_attempt_bssid),
7746 MAC2STR(drv->bssid),
7747 MAC2STR(drv->prev_bssid),
7748 drv->associated,
7749 drv->assoc_freq,
7750 drv->monitor_sock,
7751 drv->monitor_ifidx,
7752 drv->monitor_refcount,
7753 drv->last_mgmt_freq,
7754 drv->eapol_tx_sock,
7755 drv->ignore_if_down_event ?
7756 "ignore_if_down_event=1\n" : "",
7757 drv->scan_complete_events ?
7758 "scan_complete_events=1\n" : "",
7759 drv->disabled_11b_rates ?
7760 "disabled_11b_rates=1\n" : "",
7761 drv->pending_remain_on_chan ?
7762 "pending_remain_on_chan=1\n" : "",
7763 drv->in_interface_list ? "in_interface_list=1\n" : "",
7764 drv->device_ap_sme ? "device_ap_sme=1\n" : "",
7765 drv->poll_command_supported ?
7766 "poll_command_supported=1\n" : "",
7767 drv->data_tx_status ? "data_tx_status=1\n" : "",
7768 drv->scan_for_auth ? "scan_for_auth=1\n" : "",
7769 drv->retry_auth ? "retry_auth=1\n" : "",
7770 drv->use_monitor ? "use_monitor=1\n" : "",
7771 drv->ignore_next_local_disconnect ?
7772 "ignore_next_local_disconnect=1\n" : "",
Dmitry Shmidt7dba0e52014-04-14 10:49:15 -07007773 drv->ignore_next_local_deauth ?
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08007774 "ignore_next_local_deauth=1\n" : "");
7775 if (os_snprintf_error(end - pos, res))
Dmitry Shmidt56052862013-10-04 10:23:25 -07007776 return pos - buf;
7777 pos += res;
7778
7779 if (drv->has_capability) {
7780 res = os_snprintf(pos, end - pos,
7781 "capa.key_mgmt=0x%x\n"
7782 "capa.enc=0x%x\n"
7783 "capa.auth=0x%x\n"
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08007784 "capa.flags=0x%llx\n"
7785 "capa.rrm_flags=0x%x\n"
Dmitry Shmidt56052862013-10-04 10:23:25 -07007786 "capa.max_scan_ssids=%d\n"
7787 "capa.max_sched_scan_ssids=%d\n"
7788 "capa.sched_scan_supported=%d\n"
7789 "capa.max_match_sets=%d\n"
7790 "capa.max_remain_on_chan=%u\n"
7791 "capa.max_stations=%u\n"
7792 "capa.probe_resp_offloads=0x%x\n"
7793 "capa.max_acl_mac_addrs=%u\n"
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08007794 "capa.num_multichan_concurrent=%u\n"
7795 "capa.mac_addr_rand_sched_scan_supported=%d\n"
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08007796 "capa.mac_addr_rand_scan_supported=%d\n"
7797 "capa.conc_capab=%u\n"
7798 "capa.max_conc_chan_2_4=%u\n"
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08007799 "capa.max_conc_chan_5_0=%u\n"
7800 "capa.max_sched_scan_plans=%u\n"
7801 "capa.max_sched_scan_plan_interval=%u\n"
7802 "capa.max_sched_scan_plan_iterations=%u\n",
Dmitry Shmidt56052862013-10-04 10:23:25 -07007803 drv->capa.key_mgmt,
7804 drv->capa.enc,
7805 drv->capa.auth,
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08007806 (unsigned long long) drv->capa.flags,
7807 drv->capa.rrm_flags,
Dmitry Shmidt56052862013-10-04 10:23:25 -07007808 drv->capa.max_scan_ssids,
7809 drv->capa.max_sched_scan_ssids,
7810 drv->capa.sched_scan_supported,
7811 drv->capa.max_match_sets,
7812 drv->capa.max_remain_on_chan,
7813 drv->capa.max_stations,
7814 drv->capa.probe_resp_offloads,
7815 drv->capa.max_acl_mac_addrs,
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08007816 drv->capa.num_multichan_concurrent,
7817 drv->capa.mac_addr_rand_sched_scan_supported,
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08007818 drv->capa.mac_addr_rand_scan_supported,
7819 drv->capa.conc_capab,
7820 drv->capa.max_conc_chan_2_4,
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08007821 drv->capa.max_conc_chan_5_0,
7822 drv->capa.max_sched_scan_plans,
7823 drv->capa.max_sched_scan_plan_interval,
7824 drv->capa.max_sched_scan_plan_iterations);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08007825 if (os_snprintf_error(end - pos, res))
Dmitry Shmidt56052862013-10-04 10:23:25 -07007826 return pos - buf;
7827 pos += res;
7828 }
7829
7830 return pos - buf;
7831}
7832
7833
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08007834static int set_beacon_data(struct nl_msg *msg, struct beacon_data *settings)
7835{
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08007836 if ((settings->head &&
7837 nla_put(msg, NL80211_ATTR_BEACON_HEAD,
7838 settings->head_len, settings->head)) ||
7839 (settings->tail &&
7840 nla_put(msg, NL80211_ATTR_BEACON_TAIL,
7841 settings->tail_len, settings->tail)) ||
7842 (settings->beacon_ies &&
7843 nla_put(msg, NL80211_ATTR_IE,
7844 settings->beacon_ies_len, settings->beacon_ies)) ||
7845 (settings->proberesp_ies &&
7846 nla_put(msg, NL80211_ATTR_IE_PROBE_RESP,
7847 settings->proberesp_ies_len, settings->proberesp_ies)) ||
7848 (settings->assocresp_ies &&
7849 nla_put(msg, NL80211_ATTR_IE_ASSOC_RESP,
7850 settings->assocresp_ies_len, settings->assocresp_ies)) ||
7851 (settings->probe_resp &&
7852 nla_put(msg, NL80211_ATTR_PROBE_RESP,
7853 settings->probe_resp_len, settings->probe_resp)))
7854 return -ENOBUFS;
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08007855
7856 return 0;
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08007857}
7858
7859
7860static int nl80211_switch_channel(void *priv, struct csa_settings *settings)
7861{
7862 struct nl_msg *msg;
7863 struct i802_bss *bss = priv;
7864 struct wpa_driver_nl80211_data *drv = bss->drv;
7865 struct nlattr *beacon_csa;
7866 int ret = -ENOBUFS;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08007867 int csa_off_len = 0;
7868 int i;
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08007869
Dmitry Shmidt04f534e2013-12-09 15:50:16 -08007870 wpa_printf(MSG_DEBUG, "nl80211: Channel switch request (cs_count=%u block_tx=%u freq=%d width=%d cf1=%d cf2=%d)",
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08007871 settings->cs_count, settings->block_tx,
Dmitry Shmidt04f534e2013-12-09 15:50:16 -08007872 settings->freq_params.freq, settings->freq_params.bandwidth,
7873 settings->freq_params.center_freq1,
7874 settings->freq_params.center_freq2);
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08007875
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08007876 if (!(drv->capa.flags & WPA_DRIVER_FLAGS_AP_CSA)) {
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08007877 wpa_printf(MSG_DEBUG, "nl80211: Driver does not support channel switch command");
7878 return -EOPNOTSUPP;
7879 }
7880
7881 if ((drv->nlmode != NL80211_IFTYPE_AP) &&
7882 (drv->nlmode != NL80211_IFTYPE_P2P_GO))
7883 return -EOPNOTSUPP;
7884
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08007885 /*
7886 * Remove empty counters, assuming Probe Response and Beacon frame
7887 * counters match. This implementation assumes that there are only two
7888 * counters.
7889 */
7890 if (settings->counter_offset_beacon[0] &&
7891 !settings->counter_offset_beacon[1]) {
7892 csa_off_len = 1;
7893 } else if (settings->counter_offset_beacon[1] &&
7894 !settings->counter_offset_beacon[0]) {
7895 csa_off_len = 1;
7896 settings->counter_offset_beacon[0] =
7897 settings->counter_offset_beacon[1];
7898 settings->counter_offset_presp[0] =
7899 settings->counter_offset_presp[1];
7900 } else if (settings->counter_offset_beacon[1] &&
7901 settings->counter_offset_beacon[0]) {
7902 csa_off_len = 2;
7903 } else {
7904 wpa_printf(MSG_ERROR, "nl80211: No CSA counters provided");
7905 return -EINVAL;
7906 }
7907
7908 /* Check CSA counters validity */
7909 if (drv->capa.max_csa_counters &&
7910 csa_off_len > drv->capa.max_csa_counters) {
7911 wpa_printf(MSG_ERROR,
7912 "nl80211: Too many CSA counters provided");
7913 return -EINVAL;
7914 }
7915
7916 if (!settings->beacon_csa.tail)
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08007917 return -EINVAL;
7918
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08007919 for (i = 0; i < csa_off_len; i++) {
7920 u16 csa_c_off_bcn = settings->counter_offset_beacon[i];
7921 u16 csa_c_off_presp = settings->counter_offset_presp[i];
7922
7923 if ((settings->beacon_csa.tail_len <= csa_c_off_bcn) ||
7924 (settings->beacon_csa.tail[csa_c_off_bcn] !=
7925 settings->cs_count))
7926 return -EINVAL;
7927
7928 if (settings->beacon_csa.probe_resp &&
7929 ((settings->beacon_csa.probe_resp_len <=
7930 csa_c_off_presp) ||
7931 (settings->beacon_csa.probe_resp[csa_c_off_presp] !=
7932 settings->cs_count)))
7933 return -EINVAL;
7934 }
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08007935
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08007936 if (!(msg = nl80211_bss_msg(bss, 0, NL80211_CMD_CHANNEL_SWITCH)) ||
7937 nla_put_u32(msg, NL80211_ATTR_CH_SWITCH_COUNT,
7938 settings->cs_count) ||
7939 (ret = nl80211_put_freq_params(msg, &settings->freq_params)) ||
7940 (settings->block_tx &&
7941 nla_put_flag(msg, NL80211_ATTR_CH_SWITCH_BLOCK_TX)))
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08007942 goto error;
7943
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08007944 /* beacon_after params */
7945 ret = set_beacon_data(msg, &settings->beacon_after);
7946 if (ret)
7947 goto error;
7948
7949 /* beacon_csa params */
7950 beacon_csa = nla_nest_start(msg, NL80211_ATTR_CSA_IES);
7951 if (!beacon_csa)
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08007952 goto fail;
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08007953
7954 ret = set_beacon_data(msg, &settings->beacon_csa);
7955 if (ret)
7956 goto error;
7957
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08007958 if (nla_put(msg, NL80211_ATTR_CSA_C_OFF_BEACON,
7959 csa_off_len * sizeof(u16),
7960 settings->counter_offset_beacon) ||
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08007961 (settings->beacon_csa.probe_resp &&
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08007962 nla_put(msg, NL80211_ATTR_CSA_C_OFF_PRESP,
7963 csa_off_len * sizeof(u16),
7964 settings->counter_offset_presp)))
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08007965 goto fail;
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08007966
7967 nla_nest_end(msg, beacon_csa);
7968 ret = send_and_recv_msgs(drv, msg, NULL, NULL);
7969 if (ret) {
7970 wpa_printf(MSG_DEBUG, "nl80211: switch_channel failed err=%d (%s)",
7971 ret, strerror(-ret));
7972 }
7973 return ret;
7974
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08007975fail:
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08007976 ret = -ENOBUFS;
7977error:
7978 nlmsg_free(msg);
7979 wpa_printf(MSG_DEBUG, "nl80211: Could not build channel switch request");
7980 return ret;
7981}
7982
7983
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08007984static int nl80211_add_ts(void *priv, u8 tsid, const u8 *addr,
7985 u8 user_priority, u16 admitted_time)
7986{
7987 struct i802_bss *bss = priv;
7988 struct wpa_driver_nl80211_data *drv = bss->drv;
7989 struct nl_msg *msg;
7990 int ret;
7991
7992 wpa_printf(MSG_DEBUG,
7993 "nl80211: add_ts request: tsid=%u admitted_time=%u up=%d",
7994 tsid, admitted_time, user_priority);
7995
7996 if (!is_sta_interface(drv->nlmode))
7997 return -ENOTSUP;
7998
7999 msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_ADD_TX_TS);
8000 if (!msg ||
8001 nla_put_u8(msg, NL80211_ATTR_TSID, tsid) ||
8002 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) ||
8003 nla_put_u8(msg, NL80211_ATTR_USER_PRIO, user_priority) ||
8004 nla_put_u16(msg, NL80211_ATTR_ADMITTED_TIME, admitted_time)) {
8005 nlmsg_free(msg);
8006 return -ENOBUFS;
8007 }
8008
8009 ret = send_and_recv_msgs(drv, msg, NULL, NULL);
8010 if (ret)
8011 wpa_printf(MSG_DEBUG, "nl80211: add_ts failed err=%d (%s)",
8012 ret, strerror(-ret));
8013 return ret;
8014}
8015
8016
8017static int nl80211_del_ts(void *priv, u8 tsid, const u8 *addr)
8018{
8019 struct i802_bss *bss = priv;
8020 struct wpa_driver_nl80211_data *drv = bss->drv;
8021 struct nl_msg *msg;
8022 int ret;
8023
8024 wpa_printf(MSG_DEBUG, "nl80211: del_ts request: tsid=%u", tsid);
8025
8026 if (!is_sta_interface(drv->nlmode))
8027 return -ENOTSUP;
8028
8029 if (!(msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_DEL_TX_TS)) ||
8030 nla_put_u8(msg, NL80211_ATTR_TSID, tsid) ||
8031 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) {
8032 nlmsg_free(msg);
8033 return -ENOBUFS;
8034 }
8035
8036 ret = send_and_recv_msgs(drv, msg, NULL, NULL);
8037 if (ret)
8038 wpa_printf(MSG_DEBUG, "nl80211: del_ts failed err=%d (%s)",
8039 ret, strerror(-ret));
8040 return ret;
8041}
8042
8043
Dmitry Shmidta38abf92014-03-06 13:38:44 -08008044#ifdef CONFIG_TESTING_OPTIONS
8045static int cmd_reply_handler(struct nl_msg *msg, void *arg)
8046{
8047 struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg));
8048 struct wpabuf *buf = arg;
8049
8050 if (!buf)
8051 return NL_SKIP;
8052
8053 if ((size_t) genlmsg_attrlen(gnlh, 0) > wpabuf_tailroom(buf)) {
8054 wpa_printf(MSG_INFO, "nl80211: insufficient buffer space for reply");
8055 return NL_SKIP;
8056 }
8057
8058 wpabuf_put_data(buf, genlmsg_attrdata(gnlh, 0),
8059 genlmsg_attrlen(gnlh, 0));
8060
8061 return NL_SKIP;
8062}
8063#endif /* CONFIG_TESTING_OPTIONS */
8064
8065
8066static int vendor_reply_handler(struct nl_msg *msg, void *arg)
8067{
8068 struct nlattr *tb[NL80211_ATTR_MAX + 1];
8069 struct nlattr *nl_vendor_reply, *nl;
8070 struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg));
8071 struct wpabuf *buf = arg;
8072 int rem;
8073
8074 if (!buf)
8075 return NL_SKIP;
8076
8077 nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0),
8078 genlmsg_attrlen(gnlh, 0), NULL);
8079 nl_vendor_reply = tb[NL80211_ATTR_VENDOR_DATA];
8080
8081 if (!nl_vendor_reply)
8082 return NL_SKIP;
8083
8084 if ((size_t) nla_len(nl_vendor_reply) > wpabuf_tailroom(buf)) {
8085 wpa_printf(MSG_INFO, "nl80211: Vendor command: insufficient buffer space for reply");
8086 return NL_SKIP;
8087 }
8088
8089 nla_for_each_nested(nl, nl_vendor_reply, rem) {
8090 wpabuf_put_data(buf, nla_data(nl), nla_len(nl));
8091 }
8092
8093 return NL_SKIP;
8094}
8095
8096
8097static int nl80211_vendor_cmd(void *priv, unsigned int vendor_id,
8098 unsigned int subcmd, const u8 *data,
8099 size_t data_len, struct wpabuf *buf)
8100{
8101 struct i802_bss *bss = priv;
8102 struct wpa_driver_nl80211_data *drv = bss->drv;
8103 struct nl_msg *msg;
8104 int ret;
8105
Dmitry Shmidta38abf92014-03-06 13:38:44 -08008106#ifdef CONFIG_TESTING_OPTIONS
8107 if (vendor_id == 0xffffffff) {
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08008108 msg = nlmsg_alloc();
8109 if (!msg)
8110 return -ENOMEM;
8111
Dmitry Shmidta38abf92014-03-06 13:38:44 -08008112 nl80211_cmd(drv, msg, 0, subcmd);
8113 if (nlmsg_append(msg, (void *) data, data_len, NLMSG_ALIGNTO) <
8114 0)
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08008115 goto fail;
Dmitry Shmidta38abf92014-03-06 13:38:44 -08008116 ret = send_and_recv_msgs(drv, msg, cmd_reply_handler, buf);
8117 if (ret)
8118 wpa_printf(MSG_DEBUG, "nl80211: command failed err=%d",
8119 ret);
8120 return ret;
8121 }
8122#endif /* CONFIG_TESTING_OPTIONS */
8123
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08008124 if (!(msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_VENDOR)) ||
8125 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, vendor_id) ||
8126 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD, subcmd) ||
8127 (data &&
8128 nla_put(msg, NL80211_ATTR_VENDOR_DATA, data_len, data)))
8129 goto fail;
Dmitry Shmidta38abf92014-03-06 13:38:44 -08008130
8131 ret = send_and_recv_msgs(drv, msg, vendor_reply_handler, buf);
8132 if (ret)
8133 wpa_printf(MSG_DEBUG, "nl80211: vendor command failed err=%d",
8134 ret);
8135 return ret;
8136
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08008137fail:
Dmitry Shmidta38abf92014-03-06 13:38:44 -08008138 nlmsg_free(msg);
8139 return -ENOBUFS;
8140}
8141
8142
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08008143static int nl80211_set_qos_map(void *priv, const u8 *qos_map_set,
8144 u8 qos_map_set_len)
8145{
8146 struct i802_bss *bss = priv;
8147 struct wpa_driver_nl80211_data *drv = bss->drv;
8148 struct nl_msg *msg;
8149 int ret;
8150
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08008151 wpa_hexdump(MSG_DEBUG, "nl80211: Setting QoS Map",
8152 qos_map_set, qos_map_set_len);
8153
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08008154 if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_SET_QOS_MAP)) ||
8155 nla_put(msg, NL80211_ATTR_QOS_MAP, qos_map_set_len, qos_map_set)) {
8156 nlmsg_free(msg);
8157 return -ENOBUFS;
8158 }
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08008159
8160 ret = send_and_recv_msgs(drv, msg, NULL, NULL);
8161 if (ret)
8162 wpa_printf(MSG_DEBUG, "nl80211: Setting QoS Map failed");
8163
8164 return ret;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08008165}
8166
8167
Dmitry Shmidtb58836e2014-04-29 14:35:56 -07008168static int nl80211_set_wowlan(void *priv,
8169 const struct wowlan_triggers *triggers)
8170{
8171 struct i802_bss *bss = priv;
8172 struct wpa_driver_nl80211_data *drv = bss->drv;
8173 struct nl_msg *msg;
8174 struct nlattr *wowlan_triggers;
8175 int ret;
8176
Dmitry Shmidtb58836e2014-04-29 14:35:56 -07008177 wpa_printf(MSG_DEBUG, "nl80211: Setting wowlan");
8178
Dmitry Shmidta3dc3092015-06-23 11:21:28 -07008179 if (!(msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_SET_WOWLAN)) ||
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08008180 !(wowlan_triggers = nla_nest_start(msg,
8181 NL80211_ATTR_WOWLAN_TRIGGERS)) ||
8182 (triggers->any &&
8183 nla_put_flag(msg, NL80211_WOWLAN_TRIG_ANY)) ||
8184 (triggers->disconnect &&
8185 nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) ||
8186 (triggers->magic_pkt &&
8187 nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) ||
8188 (triggers->gtk_rekey_failure &&
8189 nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) ||
8190 (triggers->eap_identity_req &&
8191 nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) ||
8192 (triggers->four_way_handshake &&
8193 nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) ||
8194 (triggers->rfkill_release &&
8195 nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE))) {
8196 nlmsg_free(msg);
8197 return -ENOBUFS;
8198 }
Dmitry Shmidtb58836e2014-04-29 14:35:56 -07008199
8200 nla_nest_end(msg, wowlan_triggers);
8201
8202 ret = send_and_recv_msgs(drv, msg, NULL, NULL);
8203 if (ret)
8204 wpa_printf(MSG_DEBUG, "nl80211: Setting wowlan failed");
8205
8206 return ret;
Dmitry Shmidtb58836e2014-04-29 14:35:56 -07008207}
8208
8209
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08008210#ifdef CONFIG_DRIVER_NL80211_QCA
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07008211static int nl80211_roaming(void *priv, int allowed, const u8 *bssid)
8212{
8213 struct i802_bss *bss = priv;
8214 struct wpa_driver_nl80211_data *drv = bss->drv;
8215 struct nl_msg *msg;
8216 struct nlattr *params;
8217
8218 wpa_printf(MSG_DEBUG, "nl80211: Roaming policy: allowed=%d", allowed);
8219
8220 if (!drv->roaming_vendor_cmd_avail) {
8221 wpa_printf(MSG_DEBUG,
8222 "nl80211: Ignore roaming policy change since driver does not provide command for setting it");
8223 return -1;
8224 }
8225
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08008226 if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_VENDOR)) ||
8227 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
8228 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
8229 QCA_NL80211_VENDOR_SUBCMD_ROAMING) ||
8230 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
8231 nla_put_u32(msg, QCA_WLAN_VENDOR_ATTR_ROAMING_POLICY,
8232 allowed ? QCA_ROAMING_ALLOWED_WITHIN_ESS :
8233 QCA_ROAMING_NOT_ALLOWED) ||
8234 (bssid &&
8235 nla_put(msg, QCA_WLAN_VENDOR_ATTR_MAC_ADDR, ETH_ALEN, bssid))) {
8236 nlmsg_free(msg);
8237 return -1;
8238 }
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07008239 nla_nest_end(msg, params);
8240
8241 return send_and_recv_msgs(drv, msg, NULL, NULL);
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07008242}
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08008243#endif /* CONFIG_DRIVER_NL80211_QCA */
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07008244
8245
8246static int nl80211_set_mac_addr(void *priv, const u8 *addr)
8247{
8248 struct i802_bss *bss = priv;
8249 struct wpa_driver_nl80211_data *drv = bss->drv;
8250 int new_addr = addr != NULL;
8251
8252 if (!addr)
8253 addr = drv->perm_addr;
8254
8255 if (linux_set_iface_flags(drv->global->ioctl_sock, bss->ifname, 0) < 0)
8256 return -1;
8257
8258 if (linux_set_ifhwaddr(drv->global->ioctl_sock, bss->ifname, addr) < 0)
8259 {
8260 wpa_printf(MSG_DEBUG,
8261 "nl80211: failed to set_mac_addr for %s to " MACSTR,
8262 bss->ifname, MAC2STR(addr));
8263 if (linux_set_iface_flags(drv->global->ioctl_sock, bss->ifname,
8264 1) < 0) {
8265 wpa_printf(MSG_DEBUG,
8266 "nl80211: Could not restore interface UP after failed set_mac_addr");
8267 }
8268 return -1;
8269 }
8270
8271 wpa_printf(MSG_DEBUG, "nl80211: set_mac_addr for %s to " MACSTR,
8272 bss->ifname, MAC2STR(addr));
8273 drv->addr_changed = new_addr;
8274 os_memcpy(bss->addr, addr, ETH_ALEN);
8275
8276 if (linux_set_iface_flags(drv->global->ioctl_sock, bss->ifname, 1) < 0)
8277 {
8278 wpa_printf(MSG_DEBUG,
8279 "nl80211: Could not restore interface UP after set_mac_addr");
8280 }
8281
8282 return 0;
8283}
8284
8285
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08008286#ifdef CONFIG_MESH
8287
8288static int wpa_driver_nl80211_init_mesh(void *priv)
8289{
8290 if (wpa_driver_nl80211_set_mode(priv, NL80211_IFTYPE_MESH_POINT)) {
8291 wpa_printf(MSG_INFO,
8292 "nl80211: Failed to set interface into mesh mode");
8293 return -1;
8294 }
8295 return 0;
8296}
8297
8298
Dmitry Shmidtff787d52015-01-12 13:01:47 -08008299static int nl80211_put_mesh_id(struct nl_msg *msg, const u8 *mesh_id,
8300 size_t mesh_id_len)
8301{
8302 if (mesh_id) {
8303 wpa_hexdump_ascii(MSG_DEBUG, " * Mesh ID (SSID)",
8304 mesh_id, mesh_id_len);
8305 return nla_put(msg, NL80211_ATTR_MESH_ID, mesh_id_len, mesh_id);
8306 }
8307
8308 return 0;
8309}
8310
8311
Dmitry Shmidt7f656022015-02-25 14:36:37 -08008312static int nl80211_join_mesh(struct i802_bss *bss,
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08008313 struct wpa_driver_mesh_join_params *params)
8314{
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08008315 struct wpa_driver_nl80211_data *drv = bss->drv;
8316 struct nl_msg *msg;
8317 struct nlattr *container;
Dmitry Shmidt2f74e362015-01-21 13:19:05 -08008318 int ret = -1;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08008319
8320 wpa_printf(MSG_DEBUG, "nl80211: mesh join (ifindex=%d)", drv->ifindex);
8321 msg = nl80211_drv_msg(drv, 0, NL80211_CMD_JOIN_MESH);
Dmitry Shmidtff787d52015-01-12 13:01:47 -08008322 if (!msg ||
8323 nl80211_put_freq_params(msg, &params->freq) ||
8324 nl80211_put_basic_rates(msg, params->basic_rates) ||
8325 nl80211_put_mesh_id(msg, params->meshid, params->meshid_len) ||
8326 nl80211_put_beacon_int(msg, params->beacon_int))
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08008327 goto fail;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08008328
8329 wpa_printf(MSG_DEBUG, " * flags=%08X", params->flags);
8330
8331 container = nla_nest_start(msg, NL80211_ATTR_MESH_SETUP);
8332 if (!container)
8333 goto fail;
8334
8335 if (params->ies) {
8336 wpa_hexdump(MSG_DEBUG, " * IEs", params->ies, params->ie_len);
8337 if (nla_put(msg, NL80211_MESH_SETUP_IE, params->ie_len,
8338 params->ies))
8339 goto fail;
8340 }
8341 /* WPA_DRIVER_MESH_FLAG_OPEN_AUTH is treated as default by nl80211 */
8342 if (params->flags & WPA_DRIVER_MESH_FLAG_SAE_AUTH) {
8343 if (nla_put_u8(msg, NL80211_MESH_SETUP_AUTH_PROTOCOL, 0x1) ||
8344 nla_put_flag(msg, NL80211_MESH_SETUP_USERSPACE_AUTH))
8345 goto fail;
8346 }
8347 if ((params->flags & WPA_DRIVER_MESH_FLAG_AMPE) &&
8348 nla_put_flag(msg, NL80211_MESH_SETUP_USERSPACE_AMPE))
8349 goto fail;
8350 if ((params->flags & WPA_DRIVER_MESH_FLAG_USER_MPM) &&
8351 nla_put_flag(msg, NL80211_MESH_SETUP_USERSPACE_MPM))
8352 goto fail;
8353 nla_nest_end(msg, container);
8354
8355 container = nla_nest_start(msg, NL80211_ATTR_MESH_CONFIG);
8356 if (!container)
8357 goto fail;
8358
8359 if (!(params->conf.flags & WPA_DRIVER_MESH_CONF_FLAG_AUTO_PLINKS) &&
8360 nla_put_u32(msg, NL80211_MESHCONF_AUTO_OPEN_PLINKS, 0))
8361 goto fail;
8362 if ((params->conf.flags & WPA_DRIVER_MESH_FLAG_DRIVER_MPM) &&
8363 nla_put_u16(msg, NL80211_MESHCONF_MAX_PEER_LINKS,
8364 params->max_peer_links))
8365 goto fail;
Dmitry Shmidt2f74e362015-01-21 13:19:05 -08008366
8367 /*
8368 * Set NL80211_MESHCONF_PLINK_TIMEOUT even if user mpm is used because
8369 * the timer could disconnect stations even in that case.
Dmitry Shmidt2f74e362015-01-21 13:19:05 -08008370 */
Dmitry Shmidt7f656022015-02-25 14:36:37 -08008371 if (nla_put_u32(msg, NL80211_MESHCONF_PLINK_TIMEOUT,
8372 params->conf.peer_link_timeout)) {
Dmitry Shmidt2f74e362015-01-21 13:19:05 -08008373 wpa_printf(MSG_ERROR, "nl80211: Failed to set PLINK_TIMEOUT");
8374 goto fail;
8375 }
8376
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08008377 nla_nest_end(msg, container);
8378
8379 ret = send_and_recv_msgs(drv, msg, NULL, NULL);
8380 msg = NULL;
8381 if (ret) {
8382 wpa_printf(MSG_DEBUG, "nl80211: mesh join failed: ret=%d (%s)",
8383 ret, strerror(-ret));
8384 goto fail;
8385 }
8386 ret = 0;
Dmitry Shmidtff787d52015-01-12 13:01:47 -08008387 bss->freq = params->freq.freq;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08008388 wpa_printf(MSG_DEBUG, "nl80211: mesh join request send successfully");
8389
8390fail:
8391 nlmsg_free(msg);
8392 return ret;
8393}
8394
8395
Dmitry Shmidt7f656022015-02-25 14:36:37 -08008396static int
8397wpa_driver_nl80211_join_mesh(void *priv,
8398 struct wpa_driver_mesh_join_params *params)
8399{
8400 struct i802_bss *bss = priv;
8401 int ret, timeout;
8402
8403 timeout = params->conf.peer_link_timeout;
8404
8405 /* Disable kernel inactivity timer */
8406 if (params->flags & WPA_DRIVER_MESH_FLAG_USER_MPM)
8407 params->conf.peer_link_timeout = 0;
8408
8409 ret = nl80211_join_mesh(bss, params);
8410 if (ret == -EINVAL && params->conf.peer_link_timeout == 0) {
8411 wpa_printf(MSG_DEBUG,
8412 "nl80211: Mesh join retry for peer_link_timeout");
8413 /*
8414 * Old kernel does not support setting
8415 * NL80211_MESHCONF_PLINK_TIMEOUT to zero, so set 60 seconds
8416 * into future from peer_link_timeout.
8417 */
8418 params->conf.peer_link_timeout = timeout + 60;
8419 ret = nl80211_join_mesh(priv, params);
8420 }
8421
8422 params->conf.peer_link_timeout = timeout;
8423 return ret;
8424}
8425
8426
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08008427static int wpa_driver_nl80211_leave_mesh(void *priv)
8428{
8429 struct i802_bss *bss = priv;
8430 struct wpa_driver_nl80211_data *drv = bss->drv;
8431 struct nl_msg *msg;
8432 int ret;
8433
8434 wpa_printf(MSG_DEBUG, "nl80211: mesh leave (ifindex=%d)", drv->ifindex);
8435 msg = nl80211_drv_msg(drv, 0, NL80211_CMD_LEAVE_MESH);
8436 ret = send_and_recv_msgs(drv, msg, NULL, NULL);
8437 if (ret) {
8438 wpa_printf(MSG_DEBUG, "nl80211: mesh leave failed: ret=%d (%s)",
8439 ret, strerror(-ret));
8440 } else {
8441 wpa_printf(MSG_DEBUG,
8442 "nl80211: mesh leave request send successfully");
8443 }
8444
8445 if (wpa_driver_nl80211_set_mode(drv->first_bss,
8446 NL80211_IFTYPE_STATION)) {
8447 wpa_printf(MSG_INFO,
8448 "nl80211: Failed to set interface into station mode");
8449 }
8450 return ret;
8451}
8452
8453#endif /* CONFIG_MESH */
8454
8455
8456static int wpa_driver_br_add_ip_neigh(void *priv, u8 version,
8457 const u8 *ipaddr, int prefixlen,
8458 const u8 *addr)
8459{
8460#ifdef CONFIG_LIBNL3_ROUTE
8461 struct i802_bss *bss = priv;
8462 struct wpa_driver_nl80211_data *drv = bss->drv;
8463 struct rtnl_neigh *rn;
8464 struct nl_addr *nl_ipaddr = NULL;
8465 struct nl_addr *nl_lladdr = NULL;
8466 int family, addrsize;
8467 int res;
8468
8469 if (!ipaddr || prefixlen == 0 || !addr)
8470 return -EINVAL;
8471
8472 if (bss->br_ifindex == 0) {
8473 wpa_printf(MSG_DEBUG,
8474 "nl80211: bridge must be set before adding an ip neigh to it");
8475 return -1;
8476 }
8477
8478 if (!drv->rtnl_sk) {
8479 wpa_printf(MSG_DEBUG,
8480 "nl80211: nl_sock for NETLINK_ROUTE is not initialized");
8481 return -1;
8482 }
8483
8484 if (version == 4) {
8485 family = AF_INET;
8486 addrsize = 4;
8487 } else if (version == 6) {
8488 family = AF_INET6;
8489 addrsize = 16;
8490 } else {
8491 return -EINVAL;
8492 }
8493
8494 rn = rtnl_neigh_alloc();
8495 if (rn == NULL)
8496 return -ENOMEM;
8497
8498 /* set the destination ip address for neigh */
8499 nl_ipaddr = nl_addr_build(family, (void *) ipaddr, addrsize);
8500 if (nl_ipaddr == NULL) {
8501 wpa_printf(MSG_DEBUG, "nl80211: nl_ipaddr build failed");
8502 res = -ENOMEM;
8503 goto errout;
8504 }
8505 nl_addr_set_prefixlen(nl_ipaddr, prefixlen);
8506 res = rtnl_neigh_set_dst(rn, nl_ipaddr);
8507 if (res) {
8508 wpa_printf(MSG_DEBUG,
8509 "nl80211: neigh set destination addr failed");
8510 goto errout;
8511 }
8512
8513 /* set the corresponding lladdr for neigh */
8514 nl_lladdr = nl_addr_build(AF_BRIDGE, (u8 *) addr, ETH_ALEN);
8515 if (nl_lladdr == NULL) {
8516 wpa_printf(MSG_DEBUG, "nl80211: neigh set lladdr failed");
8517 res = -ENOMEM;
8518 goto errout;
8519 }
8520 rtnl_neigh_set_lladdr(rn, nl_lladdr);
8521
8522 rtnl_neigh_set_ifindex(rn, bss->br_ifindex);
8523 rtnl_neigh_set_state(rn, NUD_PERMANENT);
8524
8525 res = rtnl_neigh_add(drv->rtnl_sk, rn, NLM_F_CREATE);
8526 if (res) {
8527 wpa_printf(MSG_DEBUG,
8528 "nl80211: Adding bridge ip neigh failed: %s",
8529 strerror(errno));
8530 }
8531errout:
8532 if (nl_lladdr)
8533 nl_addr_put(nl_lladdr);
8534 if (nl_ipaddr)
8535 nl_addr_put(nl_ipaddr);
8536 if (rn)
8537 rtnl_neigh_put(rn);
8538 return res;
8539#else /* CONFIG_LIBNL3_ROUTE */
8540 return -1;
8541#endif /* CONFIG_LIBNL3_ROUTE */
8542}
8543
8544
8545static int wpa_driver_br_delete_ip_neigh(void *priv, u8 version,
8546 const u8 *ipaddr)
8547{
8548#ifdef CONFIG_LIBNL3_ROUTE
8549 struct i802_bss *bss = priv;
8550 struct wpa_driver_nl80211_data *drv = bss->drv;
8551 struct rtnl_neigh *rn;
8552 struct nl_addr *nl_ipaddr;
8553 int family, addrsize;
8554 int res;
8555
8556 if (!ipaddr)
8557 return -EINVAL;
8558
8559 if (version == 4) {
8560 family = AF_INET;
8561 addrsize = 4;
8562 } else if (version == 6) {
8563 family = AF_INET6;
8564 addrsize = 16;
8565 } else {
8566 return -EINVAL;
8567 }
8568
8569 if (bss->br_ifindex == 0) {
8570 wpa_printf(MSG_DEBUG,
8571 "nl80211: bridge must be set to delete an ip neigh");
8572 return -1;
8573 }
8574
8575 if (!drv->rtnl_sk) {
8576 wpa_printf(MSG_DEBUG,
8577 "nl80211: nl_sock for NETLINK_ROUTE is not initialized");
8578 return -1;
8579 }
8580
8581 rn = rtnl_neigh_alloc();
8582 if (rn == NULL)
8583 return -ENOMEM;
8584
8585 /* set the destination ip address for neigh */
8586 nl_ipaddr = nl_addr_build(family, (void *) ipaddr, addrsize);
8587 if (nl_ipaddr == NULL) {
8588 wpa_printf(MSG_DEBUG, "nl80211: nl_ipaddr build failed");
8589 res = -ENOMEM;
8590 goto errout;
8591 }
8592 res = rtnl_neigh_set_dst(rn, nl_ipaddr);
8593 if (res) {
8594 wpa_printf(MSG_DEBUG,
8595 "nl80211: neigh set destination addr failed");
8596 goto errout;
8597 }
8598
8599 rtnl_neigh_set_ifindex(rn, bss->br_ifindex);
8600
8601 res = rtnl_neigh_delete(drv->rtnl_sk, rn, 0);
8602 if (res) {
8603 wpa_printf(MSG_DEBUG,
8604 "nl80211: Deleting bridge ip neigh failed: %s",
8605 strerror(errno));
8606 }
8607errout:
8608 if (nl_ipaddr)
8609 nl_addr_put(nl_ipaddr);
8610 if (rn)
8611 rtnl_neigh_put(rn);
8612 return res;
8613#else /* CONFIG_LIBNL3_ROUTE */
8614 return -1;
8615#endif /* CONFIG_LIBNL3_ROUTE */
8616}
8617
8618
8619static int linux_write_system_file(const char *path, unsigned int val)
8620{
8621 char buf[50];
8622 int fd, len;
8623
8624 len = os_snprintf(buf, sizeof(buf), "%u\n", val);
8625 if (os_snprintf_error(sizeof(buf), len))
8626 return -1;
8627
8628 fd = open(path, O_WRONLY);
8629 if (fd < 0)
8630 return -1;
8631
8632 if (write(fd, buf, len) < 0) {
8633 wpa_printf(MSG_DEBUG,
8634 "nl80211: Failed to write Linux system file: %s with the value of %d",
8635 path, val);
8636 close(fd);
8637 return -1;
8638 }
8639 close(fd);
8640
8641 return 0;
8642}
8643
8644
8645static const char * drv_br_port_attr_str(enum drv_br_port_attr attr)
8646{
8647 switch (attr) {
8648 case DRV_BR_PORT_ATTR_PROXYARP:
Dmitry Shmidt4dd28dc2015-03-10 11:21:43 -07008649 return "proxyarp_wifi";
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08008650 case DRV_BR_PORT_ATTR_HAIRPIN_MODE:
8651 return "hairpin_mode";
8652 }
8653
8654 return NULL;
8655}
8656
8657
8658static int wpa_driver_br_port_set_attr(void *priv, enum drv_br_port_attr attr,
8659 unsigned int val)
8660{
8661 struct i802_bss *bss = priv;
8662 char path[128];
8663 const char *attr_txt;
8664
8665 attr_txt = drv_br_port_attr_str(attr);
8666 if (attr_txt == NULL)
8667 return -EINVAL;
8668
8669 os_snprintf(path, sizeof(path), "/sys/class/net/%s/brport/%s",
8670 bss->ifname, attr_txt);
8671
8672 if (linux_write_system_file(path, val))
8673 return -1;
8674
8675 return 0;
8676}
8677
8678
8679static const char * drv_br_net_param_str(enum drv_br_net_param param)
8680{
8681 switch (param) {
8682 case DRV_BR_NET_PARAM_GARP_ACCEPT:
8683 return "arp_accept";
Dmitry Shmidt83474442015-04-15 13:47:09 -07008684 default:
8685 return NULL;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08008686 }
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08008687}
8688
8689
8690static int wpa_driver_br_set_net_param(void *priv, enum drv_br_net_param param,
8691 unsigned int val)
8692{
8693 struct i802_bss *bss = priv;
8694 char path[128];
8695 const char *param_txt;
8696 int ip_version = 4;
8697
Dmitry Shmidt83474442015-04-15 13:47:09 -07008698 if (param == DRV_BR_MULTICAST_SNOOPING) {
8699 os_snprintf(path, sizeof(path),
8700 "/sys/devices/virtual/net/%s/bridge/multicast_snooping",
8701 bss->brname);
8702 goto set_val;
8703 }
8704
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08008705 param_txt = drv_br_net_param_str(param);
8706 if (param_txt == NULL)
8707 return -EINVAL;
8708
8709 switch (param) {
8710 case DRV_BR_NET_PARAM_GARP_ACCEPT:
8711 ip_version = 4;
8712 break;
8713 default:
8714 return -EINVAL;
8715 }
8716
8717 os_snprintf(path, sizeof(path), "/proc/sys/net/ipv%d/conf/%s/%s",
8718 ip_version, bss->brname, param_txt);
8719
Dmitry Shmidt83474442015-04-15 13:47:09 -07008720set_val:
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08008721 if (linux_write_system_file(path, val))
8722 return -1;
8723
8724 return 0;
8725}
8726
8727
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08008728#ifdef CONFIG_DRIVER_NL80211_QCA
8729
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08008730static int hw_mode_to_qca_acs(enum hostapd_hw_mode hw_mode)
8731{
8732 switch (hw_mode) {
8733 case HOSTAPD_MODE_IEEE80211B:
8734 return QCA_ACS_MODE_IEEE80211B;
8735 case HOSTAPD_MODE_IEEE80211G:
8736 return QCA_ACS_MODE_IEEE80211G;
8737 case HOSTAPD_MODE_IEEE80211A:
8738 return QCA_ACS_MODE_IEEE80211A;
8739 case HOSTAPD_MODE_IEEE80211AD:
8740 return QCA_ACS_MODE_IEEE80211AD;
Dmitry Shmidtb1e52102015-05-29 12:36:29 -07008741 case HOSTAPD_MODE_IEEE80211ANY:
8742 return QCA_ACS_MODE_IEEE80211ANY;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08008743 default:
8744 return -1;
8745 }
8746}
8747
8748
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08008749static int add_acs_freq_list(struct nl_msg *msg, const int *freq_list)
8750{
8751 int i, len, ret;
8752 u32 *freqs;
8753
8754 if (!freq_list)
8755 return 0;
8756 len = int_array_len(freq_list);
8757 freqs = os_malloc(sizeof(u32) * len);
8758 if (!freqs)
8759 return -1;
8760 for (i = 0; i < len; i++)
8761 freqs[i] = freq_list[i];
8762 ret = nla_put(msg, QCA_WLAN_VENDOR_ATTR_ACS_FREQ_LIST,
8763 sizeof(u32) * len, freqs);
8764 os_free(freqs);
8765 return ret;
8766}
8767
8768
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08008769static int wpa_driver_do_acs(void *priv, struct drv_acs_params *params)
8770{
8771 struct i802_bss *bss = priv;
8772 struct wpa_driver_nl80211_data *drv = bss->drv;
8773 struct nl_msg *msg;
8774 struct nlattr *data;
8775 int ret;
8776 int mode;
8777
8778 mode = hw_mode_to_qca_acs(params->hw_mode);
8779 if (mode < 0)
8780 return -1;
8781
8782 if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_VENDOR)) ||
8783 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
8784 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
8785 QCA_NL80211_VENDOR_SUBCMD_DO_ACS) ||
8786 !(data = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
8787 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_ACS_HW_MODE, mode) ||
8788 (params->ht_enabled &&
8789 nla_put_flag(msg, QCA_WLAN_VENDOR_ATTR_ACS_HT_ENABLED)) ||
8790 (params->ht40_enabled &&
Dmitry Shmidtdda10c22015-03-24 16:05:01 -07008791 nla_put_flag(msg, QCA_WLAN_VENDOR_ATTR_ACS_HT40_ENABLED)) ||
8792 (params->vht_enabled &&
8793 nla_put_flag(msg, QCA_WLAN_VENDOR_ATTR_ACS_VHT_ENABLED)) ||
8794 nla_put_u16(msg, QCA_WLAN_VENDOR_ATTR_ACS_CHWIDTH,
8795 params->ch_width) ||
8796 (params->ch_list_len &&
8797 nla_put(msg, QCA_WLAN_VENDOR_ATTR_ACS_CH_LIST, params->ch_list_len,
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08008798 params->ch_list)) ||
8799 add_acs_freq_list(msg, params->freq_list)) {
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08008800 nlmsg_free(msg);
8801 return -ENOBUFS;
8802 }
8803 nla_nest_end(msg, data);
8804
Dmitry Shmidtdda10c22015-03-24 16:05:01 -07008805 wpa_printf(MSG_DEBUG,
8806 "nl80211: ACS Params: HW_MODE: %d HT: %d HT40: %d VHT: %d BW: %d CH_LIST_LEN: %u",
8807 params->hw_mode, params->ht_enabled, params->ht40_enabled,
8808 params->vht_enabled, params->ch_width, params->ch_list_len);
8809
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08008810 ret = send_and_recv_msgs(drv, msg, NULL, NULL);
8811 if (ret) {
8812 wpa_printf(MSG_DEBUG,
8813 "nl80211: Failed to invoke driver ACS function: %s",
8814 strerror(errno));
8815 }
8816 return ret;
8817}
8818
8819
Ravi Joshie6ccb162015-07-16 17:45:41 -07008820static int nl80211_set_band(void *priv, enum set_band band)
8821{
8822 struct i802_bss *bss = priv;
8823 struct wpa_driver_nl80211_data *drv = bss->drv;
8824 struct nl_msg *msg;
8825 struct nlattr *data;
8826 int ret;
8827 enum qca_set_band qca_band;
8828
8829 if (!drv->setband_vendor_cmd_avail)
8830 return -1;
8831
8832 switch (band) {
8833 case WPA_SETBAND_AUTO:
8834 qca_band = QCA_SETBAND_AUTO;
8835 break;
8836 case WPA_SETBAND_5G:
8837 qca_band = QCA_SETBAND_5G;
8838 break;
8839 case WPA_SETBAND_2G:
8840 qca_band = QCA_SETBAND_2G;
8841 break;
8842 default:
8843 return -1;
8844 }
8845
8846 if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_VENDOR)) ||
8847 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
8848 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
8849 QCA_NL80211_VENDOR_SUBCMD_SETBAND) ||
8850 !(data = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
8851 nla_put_u32(msg, QCA_WLAN_VENDOR_ATTR_SETBAND_VALUE, qca_band)) {
8852 nlmsg_free(msg);
8853 return -ENOBUFS;
8854 }
8855 nla_nest_end(msg, data);
8856
8857 ret = send_and_recv_msgs(drv, msg, NULL, NULL);
8858 if (ret) {
8859 wpa_printf(MSG_DEBUG,
8860 "nl80211: Driver setband function failed: %s",
8861 strerror(errno));
8862 }
8863 return ret;
8864}
8865
8866
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08008867struct nl80211_pcl {
8868 unsigned int num;
8869 unsigned int *freq_list;
8870};
8871
8872static int preferred_freq_info_handler(struct nl_msg *msg, void *arg)
8873{
8874 struct nlattr *tb[NL80211_ATTR_MAX + 1];
8875 struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg));
8876 struct nl80211_pcl *param = arg;
8877 struct nlattr *nl_vend, *attr;
8878 enum qca_iface_type iface_type;
8879 struct nlattr *tb_vendor[QCA_WLAN_VENDOR_ATTR_MAX + 1];
8880 unsigned int num, max_num;
8881 u32 *freqs;
8882
8883 nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0),
8884 genlmsg_attrlen(gnlh, 0), NULL);
8885
8886 nl_vend = tb[NL80211_ATTR_VENDOR_DATA];
8887 if (!nl_vend)
8888 return NL_SKIP;
8889
8890 nla_parse(tb_vendor, QCA_WLAN_VENDOR_ATTR_MAX,
8891 nla_data(nl_vend), nla_len(nl_vend), NULL);
8892
8893 attr = tb_vendor[
8894 QCA_WLAN_VENDOR_ATTR_GET_PREFERRED_FREQ_LIST_IFACE_TYPE];
8895 if (!attr) {
8896 wpa_printf(MSG_ERROR, "nl80211: iface_type couldn't be found");
8897 param->num = 0;
8898 return NL_SKIP;
8899 }
8900
8901 iface_type = (enum qca_iface_type) nla_get_u32(attr);
8902 wpa_printf(MSG_DEBUG, "nl80211: Driver returned iface_type=%d",
8903 iface_type);
8904
8905 attr = tb_vendor[QCA_WLAN_VENDOR_ATTR_GET_PREFERRED_FREQ_LIST];
8906 if (!attr) {
8907 wpa_printf(MSG_ERROR,
8908 "nl80211: preferred_freq_list couldn't be found");
8909 param->num = 0;
8910 return NL_SKIP;
8911 }
8912
8913 /*
8914 * param->num has the maximum number of entries for which there
8915 * is room in the freq_list provided by the caller.
8916 */
8917 freqs = nla_data(attr);
8918 max_num = nla_len(attr) / sizeof(u32);
8919 if (max_num > param->num)
8920 max_num = param->num;
8921 for (num = 0; num < max_num; num++)
8922 param->freq_list[num] = freqs[num];
8923 param->num = num;
8924
8925 return NL_SKIP;
8926}
8927
8928
8929static int nl80211_get_pref_freq_list(void *priv,
8930 enum wpa_driver_if_type if_type,
8931 unsigned int *num,
8932 unsigned int *freq_list)
8933{
8934 struct i802_bss *bss = priv;
8935 struct wpa_driver_nl80211_data *drv = bss->drv;
8936 struct nl_msg *msg;
8937 int ret;
8938 unsigned int i;
8939 struct nlattr *params;
8940 struct nl80211_pcl param;
8941 enum qca_iface_type iface_type;
8942
8943 if (!drv->get_pref_freq_list)
8944 return -1;
8945
8946 switch (if_type) {
8947 case WPA_IF_STATION:
8948 iface_type = QCA_IFACE_TYPE_STA;
8949 break;
8950 case WPA_IF_AP_BSS:
8951 iface_type = QCA_IFACE_TYPE_AP;
8952 break;
8953 case WPA_IF_P2P_GO:
8954 iface_type = QCA_IFACE_TYPE_P2P_GO;
8955 break;
8956 case WPA_IF_P2P_CLIENT:
8957 iface_type = QCA_IFACE_TYPE_P2P_CLIENT;
8958 break;
8959 case WPA_IF_IBSS:
8960 iface_type = QCA_IFACE_TYPE_IBSS;
8961 break;
8962 case WPA_IF_TDLS:
8963 iface_type = QCA_IFACE_TYPE_TDLS;
8964 break;
8965 default:
8966 return -1;
8967 }
8968
8969 param.num = *num;
8970 param.freq_list = freq_list;
8971
8972 if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_VENDOR)) ||
8973 nla_put_u32(msg, NL80211_ATTR_IFINDEX, drv->ifindex) ||
8974 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
8975 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
8976 QCA_NL80211_VENDOR_SUBCMD_GET_PREFERRED_FREQ_LIST) ||
8977 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
8978 nla_put_u32(msg,
8979 QCA_WLAN_VENDOR_ATTR_GET_PREFERRED_FREQ_LIST_IFACE_TYPE,
8980 iface_type)) {
8981 wpa_printf(MSG_ERROR,
8982 "%s: err in adding vendor_cmd and vendor_data",
8983 __func__);
8984 nlmsg_free(msg);
8985 return -1;
8986 }
8987 nla_nest_end(msg, params);
8988
8989 os_memset(freq_list, 0, *num * sizeof(freq_list[0]));
8990 ret = send_and_recv_msgs(drv, msg, preferred_freq_info_handler, &param);
8991 if (ret) {
8992 wpa_printf(MSG_ERROR,
8993 "%s: err in send_and_recv_msgs", __func__);
8994 return ret;
8995 }
8996
8997 *num = param.num;
8998
8999 for (i = 0; i < *num; i++) {
9000 wpa_printf(MSG_DEBUG, "nl80211: preferred_channel_list[%d]=%d",
9001 i, freq_list[i]);
9002 }
9003
9004 return 0;
9005}
9006
9007
9008static int nl80211_set_prob_oper_freq(void *priv, unsigned int freq)
9009{
9010 struct i802_bss *bss = priv;
9011 struct wpa_driver_nl80211_data *drv = bss->drv;
9012 struct nl_msg *msg;
9013 int ret;
9014 struct nlattr *params;
9015
9016 if (!drv->set_prob_oper_freq)
9017 return -1;
9018
9019 wpa_printf(MSG_DEBUG,
9020 "nl80211: Set P2P probable operating freq %u for ifindex %d",
9021 freq, bss->ifindex);
9022
9023 if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_VENDOR)) ||
9024 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
9025 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
9026 QCA_NL80211_VENDOR_SUBCMD_SET_PROBABLE_OPER_CHANNEL) ||
9027 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
9028 nla_put_u32(msg,
9029 QCA_WLAN_VENDOR_ATTR_PROBABLE_OPER_CHANNEL_IFACE_TYPE,
9030 QCA_IFACE_TYPE_P2P_CLIENT) ||
9031 nla_put_u32(msg,
9032 QCA_WLAN_VENDOR_ATTR_PROBABLE_OPER_CHANNEL_FREQ,
9033 freq)) {
9034 wpa_printf(MSG_ERROR,
9035 "%s: err in adding vendor_cmd and vendor_data",
9036 __func__);
9037 nlmsg_free(msg);
9038 return -1;
9039 }
9040 nla_nest_end(msg, params);
9041
9042 ret = send_and_recv_msgs(drv, msg, NULL, NULL);
9043 msg = NULL;
9044 if (ret) {
9045 wpa_printf(MSG_ERROR, "%s: err in send_and_recv_msgs",
9046 __func__);
9047 return ret;
9048 }
9049 nlmsg_free(msg);
9050 return 0;
9051}
9052
9053#endif /* CONFIG_DRIVER_NL80211_QCA */
9054
9055
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07009056const struct wpa_driver_ops wpa_driver_nl80211_ops = {
9057 .name = "nl80211",
9058 .desc = "Linux nl80211/cfg80211",
9059 .get_bssid = wpa_driver_nl80211_get_bssid,
9060 .get_ssid = wpa_driver_nl80211_get_ssid,
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08009061 .set_key = driver_nl80211_set_key,
9062 .scan2 = driver_nl80211_scan2,
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08009063 .sched_scan = wpa_driver_nl80211_sched_scan,
9064 .stop_sched_scan = wpa_driver_nl80211_stop_sched_scan,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07009065 .get_scan_results2 = wpa_driver_nl80211_get_scan_results,
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08009066 .abort_scan = wpa_driver_nl80211_abort_scan,
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08009067 .deauthenticate = driver_nl80211_deauthenticate,
9068 .authenticate = driver_nl80211_authenticate,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07009069 .associate = wpa_driver_nl80211_associate,
9070 .global_init = nl80211_global_init,
9071 .global_deinit = nl80211_global_deinit,
9072 .init2 = wpa_driver_nl80211_init,
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08009073 .deinit = driver_nl80211_deinit,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07009074 .get_capa = wpa_driver_nl80211_get_capa,
9075 .set_operstate = wpa_driver_nl80211_set_operstate,
9076 .set_supp_port = wpa_driver_nl80211_set_supp_port,
9077 .set_country = wpa_driver_nl80211_set_country,
Dmitry Shmidtcce06662013-11-04 18:44:24 -08009078 .get_country = wpa_driver_nl80211_get_country,
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08009079 .set_ap = wpa_driver_nl80211_set_ap,
Dmitry Shmidt8bae4132013-06-06 11:25:10 -07009080 .set_acl = wpa_driver_nl80211_set_acl,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07009081 .if_add = wpa_driver_nl80211_if_add,
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08009082 .if_remove = driver_nl80211_if_remove,
9083 .send_mlme = driver_nl80211_send_mlme,
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08009084 .get_hw_feature_data = nl80211_get_hw_feature_data,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07009085 .sta_add = wpa_driver_nl80211_sta_add,
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08009086 .sta_remove = driver_nl80211_sta_remove,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07009087 .hapd_send_eapol = wpa_driver_nl80211_hapd_send_eapol,
9088 .sta_set_flags = wpa_driver_nl80211_sta_set_flags,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07009089 .hapd_init = i802_init,
9090 .hapd_deinit = i802_deinit,
Jouni Malinen75ecf522011-06-27 15:19:46 -07009091 .set_wds_sta = i802_set_wds_sta,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07009092 .get_seqnum = i802_get_seqnum,
9093 .flush = i802_flush,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07009094 .get_inact_sec = i802_get_inact_sec,
9095 .sta_clear_stats = i802_sta_clear_stats,
9096 .set_rts = i802_set_rts,
9097 .set_frag = i802_set_frag,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07009098 .set_tx_queue_params = i802_set_tx_queue_params,
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08009099 .set_sta_vlan = driver_nl80211_set_sta_vlan,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07009100 .sta_deauth = i802_sta_deauth,
9101 .sta_disassoc = i802_sta_disassoc,
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08009102 .read_sta_data = driver_nl80211_read_sta_data,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07009103 .set_freq = i802_set_freq,
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08009104 .send_action = driver_nl80211_send_action,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07009105 .send_action_cancel_wait = wpa_driver_nl80211_send_action_cancel_wait,
9106 .remain_on_channel = wpa_driver_nl80211_remain_on_channel,
9107 .cancel_remain_on_channel =
9108 wpa_driver_nl80211_cancel_remain_on_channel,
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08009109 .probe_req_report = driver_nl80211_probe_req_report,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07009110 .deinit_ap = wpa_driver_nl80211_deinit_ap,
Dmitry Shmidt04949592012-07-19 12:16:46 -07009111 .deinit_p2p_cli = wpa_driver_nl80211_deinit_p2p_cli,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07009112 .resume = wpa_driver_nl80211_resume,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07009113 .signal_monitor = nl80211_signal_monitor,
9114 .signal_poll = nl80211_signal_poll,
9115 .send_frame = nl80211_send_frame,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07009116 .set_param = nl80211_set_param,
9117 .get_radio_name = nl80211_get_radio_name,
Jouni Malinen75ecf522011-06-27 15:19:46 -07009118 .add_pmkid = nl80211_add_pmkid,
9119 .remove_pmkid = nl80211_remove_pmkid,
9120 .flush_pmkid = nl80211_flush_pmkid,
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08009121 .set_rekey_info = nl80211_set_rekey_info,
9122 .poll_client = nl80211_poll_client,
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08009123 .set_p2p_powersave = nl80211_set_p2p_powersave,
Dmitry Shmidtea69e842013-05-13 14:52:28 -07009124 .start_dfs_cac = nl80211_start_radar_detection,
9125 .stop_ap = wpa_driver_nl80211_stop_ap,
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08009126#ifdef CONFIG_TDLS
9127 .send_tdls_mgmt = nl80211_send_tdls_mgmt,
9128 .tdls_oper = nl80211_tdls_oper,
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08009129 .tdls_enable_channel_switch = nl80211_tdls_enable_channel_switch,
9130 .tdls_disable_channel_switch = nl80211_tdls_disable_channel_switch,
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08009131#endif /* CONFIG_TDLS */
Dmitry Shmidt700a1372013-03-15 14:14:44 -07009132 .update_ft_ies = wpa_driver_nl80211_update_ft_ies,
Dmitry Shmidt34af3062013-07-11 10:46:32 -07009133 .get_mac_addr = wpa_driver_nl80211_get_macaddr,
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -07009134 .get_survey = wpa_driver_nl80211_get_survey,
Dmitry Shmidt56052862013-10-04 10:23:25 -07009135 .status = wpa_driver_nl80211_status,
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08009136 .switch_channel = nl80211_switch_channel,
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08009137#ifdef ANDROID_P2P
Dmitry Shmidt6e933c12011-09-27 12:29:26 -07009138 .set_noa = wpa_driver_set_p2p_noa,
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08009139 .get_noa = wpa_driver_get_p2p_noa,
Dmitry Shmidt6e933c12011-09-27 12:29:26 -07009140 .set_ap_wps_ie = wpa_driver_set_ap_wps_p2p_ie,
Dmitry Shmidt292b0c32013-11-22 12:54:42 -08009141#endif /* ANDROID_P2P */
Dmitry Shmidt738a26e2011-07-07 14:22:14 -07009142#ifdef ANDROID
Dmitry Shmidt41712582015-06-29 11:02:15 -07009143#ifndef ANDROID_LIB_STUB
Dmitry Shmidt738a26e2011-07-07 14:22:14 -07009144 .driver_cmd = wpa_driver_nl80211_driver_cmd,
Dmitry Shmidt41712582015-06-29 11:02:15 -07009145#endif /* !ANDROID_LIB_STUB */
Dmitry Shmidt292b0c32013-11-22 12:54:42 -08009146#endif /* ANDROID */
Dmitry Shmidta38abf92014-03-06 13:38:44 -08009147 .vendor_cmd = nl80211_vendor_cmd,
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08009148 .set_qos_map = nl80211_set_qos_map,
Dmitry Shmidtb58836e2014-04-29 14:35:56 -07009149 .set_wowlan = nl80211_set_wowlan,
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08009150#ifdef CONFIG_DRIVER_NL80211_QCA
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07009151 .roaming = nl80211_roaming,
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08009152#endif /* CONFIG_DRIVER_NL80211_QCA */
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07009153 .set_mac_addr = nl80211_set_mac_addr,
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08009154#ifdef CONFIG_MESH
9155 .init_mesh = wpa_driver_nl80211_init_mesh,
9156 .join_mesh = wpa_driver_nl80211_join_mesh,
9157 .leave_mesh = wpa_driver_nl80211_leave_mesh,
9158#endif /* CONFIG_MESH */
9159 .br_add_ip_neigh = wpa_driver_br_add_ip_neigh,
9160 .br_delete_ip_neigh = wpa_driver_br_delete_ip_neigh,
9161 .br_port_set_attr = wpa_driver_br_port_set_attr,
9162 .br_set_net_param = wpa_driver_br_set_net_param,
9163 .add_tx_ts = nl80211_add_ts,
9164 .del_tx_ts = nl80211_del_ts,
Dmitry Shmidte4663042016-04-04 10:07:49 -07009165 .get_ifindex = nl80211_get_ifindex,
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08009166#ifdef CONFIG_DRIVER_NL80211_QCA
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08009167 .do_acs = wpa_driver_do_acs,
Ravi Joshie6ccb162015-07-16 17:45:41 -07009168 .set_band = nl80211_set_band,
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08009169 .get_pref_freq_list = nl80211_get_pref_freq_list,
9170 .set_prob_oper_freq = nl80211_set_prob_oper_freq,
9171#endif /* CONFIG_DRIVER_NL80211_QCA */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07009172};