blob: 2a2ef6f186279d60f0da899e4d34263fd2ac3736 [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
90#define genl_ctrl_resolve android_genl_ctrl_resolve
Dmitry Shmidt54605472013-11-08 11:10:19 -080091#endif /* ANDROID */
92
93
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -080094static struct nl_handle * nl_create_handle(struct nl_cb *cb, const char *dbg)
95{
96 struct nl_handle *handle;
97
98 handle = nl80211_handle_alloc(cb);
99 if (handle == NULL) {
100 wpa_printf(MSG_ERROR, "nl80211: Failed to allocate netlink "
101 "callbacks (%s)", dbg);
102 return NULL;
103 }
104
105 if (genl_connect(handle)) {
106 wpa_printf(MSG_ERROR, "nl80211: Failed to connect to generic "
107 "netlink (%s)", dbg);
108 nl80211_handle_destroy(handle);
109 return NULL;
110 }
111
112 return handle;
113}
114
115
116static void nl_destroy_handles(struct nl_handle **handle)
117{
118 if (*handle == NULL)
119 return;
120 nl80211_handle_destroy(*handle);
121 *handle = NULL;
122}
123
124
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -0700125#if __WORDSIZE == 64
126#define ELOOP_SOCKET_INVALID (intptr_t) 0x8888888888888889ULL
127#else
128#define ELOOP_SOCKET_INVALID (intptr_t) 0x88888889ULL
129#endif
130
131static void nl80211_register_eloop_read(struct nl_handle **handle,
132 eloop_sock_handler handler,
133 void *eloop_data)
134{
Dmitry Shmidt807291d2015-01-27 13:40:23 -0800135#ifdef CONFIG_LIBNL20
136 /*
137 * libnl uses a pretty small buffer (32 kB that gets converted to 64 kB)
138 * by default. It is possible to hit that limit in some cases where
139 * operations are blocked, e.g., with a burst of Deauthentication frames
140 * to hostapd and STA entry deletion. Try to increase the buffer to make
141 * this less likely to occur.
142 */
143 if (nl_socket_set_buffer_size(*handle, 262144, 0) < 0) {
144 wpa_printf(MSG_DEBUG,
145 "nl80211: Could not set nl_socket RX buffer size: %s",
146 strerror(errno));
147 /* continue anyway with the default (smaller) buffer */
148 }
149#endif /* CONFIG_LIBNL20 */
150
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -0700151 nl_socket_set_nonblocking(*handle);
152 eloop_register_read_sock(nl_socket_get_fd(*handle), handler,
153 eloop_data, *handle);
154 *handle = (void *) (((intptr_t) *handle) ^ ELOOP_SOCKET_INVALID);
155}
156
157
158static void nl80211_destroy_eloop_handle(struct nl_handle **handle)
159{
160 *handle = (void *) (((intptr_t) *handle) ^ ELOOP_SOCKET_INVALID);
161 eloop_unregister_read_sock(nl_socket_get_fd(*handle));
162 nl_destroy_handles(handle);
163}
164
165
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800166static void nl80211_global_deinit(void *priv);
Dmitry Shmidt7f656022015-02-25 14:36:37 -0800167static void nl80211_check_global(struct nl80211_global *global);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800168
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -0800169static void wpa_driver_nl80211_deinit(struct i802_bss *bss);
Dmitry Shmidt9ead16e2014-10-07 13:15:23 -0700170static int wpa_driver_nl80211_set_mode_ibss(struct i802_bss *bss,
171 struct hostapd_freq_params *freq);
Dmitry Shmidtd30ac602014-06-30 09:54:22 -0700172
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700173static int
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -0800174wpa_driver_nl80211_finish_drv_init(struct wpa_driver_nl80211_data *drv,
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800175 const u8 *set_addr, int first,
176 const char *driver_params);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800177static int nl80211_send_frame_cmd(struct i802_bss *bss,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700178 unsigned int freq, unsigned int wait,
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800179 const u8 *buf, size_t buf_len, u64 *cookie,
180 int no_cck, int no_ack, int offchanok);
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 Shmidt8d520ff2011-05-09 14:06:53 -0700184static void add_ifidx(struct wpa_driver_nl80211_data *drv, int ifidx);
185static void del_ifidx(struct wpa_driver_nl80211_data *drv, int ifidx);
186static int have_ifidx(struct wpa_driver_nl80211_data *drv, int ifidx);
Dmitry Shmidt738a26e2011-07-07 14:22:14 -0700187
Dmitry Shmidt7832adb2014-04-29 10:53:02 -0700188static int nl80211_set_channel(struct i802_bss *bss,
189 struct hostapd_freq_params *freq, int set_chan);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700190static int nl80211_disable_11b_rates(struct wpa_driver_nl80211_data *drv,
191 int ifindex, int disabled);
192
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800193static int nl80211_leave_ibss(struct wpa_driver_nl80211_data *drv,
194 int reset_mode);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800195
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -0700196static int i802_set_iface_flags(struct i802_bss *bss, int up);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800197static int nl80211_set_param(void *priv, const char *param);
Dmitry Shmidt34af3062013-07-11 10:46:32 -0700198
199
Dmitry Shmidt04f534e2013-12-09 15:50:16 -0800200/* Converts nl80211_chan_width to a common format */
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800201enum chan_width convert2width(int width)
Dmitry Shmidt04f534e2013-12-09 15:50:16 -0800202{
203 switch (width) {
204 case NL80211_CHAN_WIDTH_20_NOHT:
205 return CHAN_WIDTH_20_NOHT;
206 case NL80211_CHAN_WIDTH_20:
207 return CHAN_WIDTH_20;
208 case NL80211_CHAN_WIDTH_40:
209 return CHAN_WIDTH_40;
210 case NL80211_CHAN_WIDTH_80:
211 return CHAN_WIDTH_80;
212 case NL80211_CHAN_WIDTH_80P80:
213 return CHAN_WIDTH_80P80;
214 case NL80211_CHAN_WIDTH_160:
215 return CHAN_WIDTH_160;
216 }
217 return CHAN_WIDTH_UNKNOWN;
218}
219
220
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800221int is_ap_interface(enum nl80211_iftype nlmode)
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800222{
Dmitry Shmidt7832adb2014-04-29 10:53:02 -0700223 return nlmode == NL80211_IFTYPE_AP ||
224 nlmode == NL80211_IFTYPE_P2P_GO;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800225}
226
227
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800228int is_sta_interface(enum nl80211_iftype nlmode)
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800229{
Dmitry Shmidt7832adb2014-04-29 10:53:02 -0700230 return nlmode == NL80211_IFTYPE_STATION ||
231 nlmode == NL80211_IFTYPE_P2P_CLIENT;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800232}
233
234
Dmitry Shmidt34af3062013-07-11 10:46:32 -0700235static int is_p2p_net_interface(enum nl80211_iftype nlmode)
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800236{
Dmitry Shmidt7832adb2014-04-29 10:53:02 -0700237 return nlmode == NL80211_IFTYPE_P2P_CLIENT ||
238 nlmode == NL80211_IFTYPE_P2P_GO;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800239}
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700240
241
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800242struct i802_bss * get_bss_ifindex(struct wpa_driver_nl80211_data *drv,
243 int ifindex)
Dmitry Shmidt9ead16e2014-10-07 13:15:23 -0700244{
245 struct i802_bss *bss;
246
247 for (bss = drv->first_bss; bss; bss = bss->next) {
248 if (bss->ifindex == ifindex)
249 return bss;
250 }
251
252 return NULL;
253}
254
255
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800256static int is_mesh_interface(enum nl80211_iftype nlmode)
257{
258 return nlmode == NL80211_IFTYPE_MESH_POINT;
259}
260
261
262void nl80211_mark_disconnected(struct wpa_driver_nl80211_data *drv)
Dmitry Shmidt8bae4132013-06-06 11:25:10 -0700263{
264 if (drv->associated)
265 os_memcpy(drv->prev_bssid, drv->bssid, ETH_ALEN);
266 drv->associated = 0;
267 os_memset(drv->bssid, 0, ETH_ALEN);
268}
269
270
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700271/* nl80211 code */
272static int ack_handler(struct nl_msg *msg, void *arg)
273{
274 int *err = arg;
275 *err = 0;
276 return NL_STOP;
277}
278
279static int finish_handler(struct nl_msg *msg, void *arg)
280{
281 int *ret = arg;
282 *ret = 0;
283 return NL_SKIP;
284}
285
286static int error_handler(struct sockaddr_nl *nla, struct nlmsgerr *err,
287 void *arg)
288{
289 int *ret = arg;
290 *ret = err->error;
291 return NL_SKIP;
292}
293
294
295static int no_seq_check(struct nl_msg *msg, void *arg)
296{
297 return NL_OK;
298}
299
300
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800301static void nl80211_nlmsg_clear(struct nl_msg *msg)
302{
303 /*
304 * Clear nlmsg data, e.g., to make sure key material is not left in
305 * heap memory for unnecessarily long time.
306 */
307 if (msg) {
308 struct nlmsghdr *hdr = nlmsg_hdr(msg);
309 void *data = nlmsg_data(hdr);
310 /*
311 * This would use nlmsg_datalen() or the older nlmsg_len() if
312 * only libnl were to maintain a stable API.. Neither will work
313 * with all released versions, so just calculate the length
314 * here.
315 */
316 int len = hdr->nlmsg_len - NLMSG_HDRLEN;
317
318 os_memset(data, 0, len);
319 }
320}
321
322
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800323static int send_and_recv(struct nl80211_global *global,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700324 struct nl_handle *nl_handle, struct nl_msg *msg,
325 int (*valid_handler)(struct nl_msg *, void *),
326 void *valid_data)
327{
328 struct nl_cb *cb;
329 int err = -ENOMEM;
330
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800331 if (!msg)
332 return -ENOMEM;
333
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800334 cb = nl_cb_clone(global->nl_cb);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700335 if (!cb)
336 goto out;
337
338 err = nl_send_auto_complete(nl_handle, msg);
339 if (err < 0)
340 goto out;
341
342 err = 1;
343
344 nl_cb_err(cb, NL_CB_CUSTOM, error_handler, &err);
345 nl_cb_set(cb, NL_CB_FINISH, NL_CB_CUSTOM, finish_handler, &err);
346 nl_cb_set(cb, NL_CB_ACK, NL_CB_CUSTOM, ack_handler, &err);
347
348 if (valid_handler)
349 nl_cb_set(cb, NL_CB_VALID, NL_CB_CUSTOM,
350 valid_handler, valid_data);
351
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -0700352 while (err > 0) {
353 int res = nl_recvmsgs(nl_handle, cb);
Dmitry Shmidt71757432014-06-02 13:50:35 -0700354 if (res < 0) {
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -0700355 wpa_printf(MSG_INFO,
356 "nl80211: %s->nl_recvmsgs failed: %d",
357 __func__, res);
358 }
359 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700360 out:
361 nl_cb_put(cb);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800362 if (!valid_handler && valid_data == (void *) -1)
363 nl80211_nlmsg_clear(msg);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700364 nlmsg_free(msg);
365 return err;
366}
367
368
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800369int send_and_recv_msgs(struct wpa_driver_nl80211_data *drv,
370 struct nl_msg *msg,
371 int (*valid_handler)(struct nl_msg *, void *),
372 void *valid_data)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700373{
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800374 return send_and_recv(drv->global, drv->global->nl, msg,
375 valid_handler, valid_data);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700376}
377
378
379struct family_data {
380 const char *group;
381 int id;
382};
383
384
385static int family_handler(struct nl_msg *msg, void *arg)
386{
387 struct family_data *res = arg;
388 struct nlattr *tb[CTRL_ATTR_MAX + 1];
389 struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg));
390 struct nlattr *mcgrp;
391 int i;
392
393 nla_parse(tb, CTRL_ATTR_MAX, genlmsg_attrdata(gnlh, 0),
394 genlmsg_attrlen(gnlh, 0), NULL);
395 if (!tb[CTRL_ATTR_MCAST_GROUPS])
396 return NL_SKIP;
397
398 nla_for_each_nested(mcgrp, tb[CTRL_ATTR_MCAST_GROUPS], i) {
399 struct nlattr *tb2[CTRL_ATTR_MCAST_GRP_MAX + 1];
400 nla_parse(tb2, CTRL_ATTR_MCAST_GRP_MAX, nla_data(mcgrp),
401 nla_len(mcgrp), NULL);
402 if (!tb2[CTRL_ATTR_MCAST_GRP_NAME] ||
403 !tb2[CTRL_ATTR_MCAST_GRP_ID] ||
404 os_strncmp(nla_data(tb2[CTRL_ATTR_MCAST_GRP_NAME]),
405 res->group,
406 nla_len(tb2[CTRL_ATTR_MCAST_GRP_NAME])) != 0)
407 continue;
408 res->id = nla_get_u32(tb2[CTRL_ATTR_MCAST_GRP_ID]);
409 break;
410 };
411
412 return NL_SKIP;
413}
414
415
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800416static int nl_get_multicast_id(struct nl80211_global *global,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700417 const char *family, const char *group)
418{
419 struct nl_msg *msg;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800420 int ret;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700421 struct family_data res = { group, -ENOENT };
422
423 msg = nlmsg_alloc();
424 if (!msg)
425 return -ENOMEM;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800426 if (!genlmsg_put(msg, 0, 0, genl_ctrl_resolve(global->nl, "nlctrl"),
427 0, 0, CTRL_CMD_GETFAMILY, 0) ||
428 nla_put_string(msg, CTRL_ATTR_FAMILY_NAME, family)) {
429 nlmsg_free(msg);
430 return -1;
431 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700432
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800433 ret = send_and_recv(global, global->nl, msg, family_handler, &res);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700434 if (ret == 0)
435 ret = res.id;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700436 return ret;
437}
438
439
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800440void * nl80211_cmd(struct wpa_driver_nl80211_data *drv,
441 struct nl_msg *msg, int flags, uint8_t cmd)
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800442{
443 return genlmsg_put(msg, 0, 0, drv->global->nl80211_id,
444 0, flags, cmd, 0);
445}
446
447
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800448static int nl80211_set_iface_id(struct nl_msg *msg, struct i802_bss *bss)
449{
450 if (bss->wdev_id_set)
451 return nla_put_u64(msg, NL80211_ATTR_WDEV, bss->wdev_id);
452 return nla_put_u32(msg, NL80211_ATTR_IFINDEX, bss->ifindex);
453}
454
455
456struct nl_msg * nl80211_cmd_msg(struct i802_bss *bss, int flags, uint8_t cmd)
457{
458 struct nl_msg *msg;
459
460 msg = nlmsg_alloc();
461 if (!msg)
462 return NULL;
463
464 if (!nl80211_cmd(bss->drv, msg, flags, cmd) ||
465 nl80211_set_iface_id(msg, bss) < 0) {
466 nlmsg_free(msg);
467 return NULL;
468 }
469
470 return msg;
471}
472
473
474static struct nl_msg *
475nl80211_ifindex_msg(struct wpa_driver_nl80211_data *drv, int ifindex,
476 int flags, uint8_t cmd)
477{
478 struct nl_msg *msg;
479
480 msg = nlmsg_alloc();
481 if (!msg)
482 return NULL;
483
484 if (!nl80211_cmd(drv, msg, flags, cmd) ||
485 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex)) {
486 nlmsg_free(msg);
487 return NULL;
488 }
489
490 return msg;
491}
492
493
494struct nl_msg * nl80211_drv_msg(struct wpa_driver_nl80211_data *drv, int flags,
495 uint8_t cmd)
496{
497 return nl80211_ifindex_msg(drv, drv->ifindex, flags, cmd);
498}
499
500
501struct nl_msg * nl80211_bss_msg(struct i802_bss *bss, int flags, uint8_t cmd)
502{
503 return nl80211_ifindex_msg(bss->drv, bss->ifindex, flags, cmd);
504}
505
506
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800507struct wiphy_idx_data {
508 int wiphy_idx;
Dmitry Shmidt34af3062013-07-11 10:46:32 -0700509 enum nl80211_iftype nlmode;
510 u8 *macaddr;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800511};
512
513
514static int netdev_info_handler(struct nl_msg *msg, void *arg)
515{
516 struct nlattr *tb[NL80211_ATTR_MAX + 1];
517 struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg));
518 struct wiphy_idx_data *info = arg;
519
520 nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0),
521 genlmsg_attrlen(gnlh, 0), NULL);
522
523 if (tb[NL80211_ATTR_WIPHY])
524 info->wiphy_idx = nla_get_u32(tb[NL80211_ATTR_WIPHY]);
525
Dmitry Shmidt34af3062013-07-11 10:46:32 -0700526 if (tb[NL80211_ATTR_IFTYPE])
527 info->nlmode = nla_get_u32(tb[NL80211_ATTR_IFTYPE]);
528
529 if (tb[NL80211_ATTR_MAC] && info->macaddr)
530 os_memcpy(info->macaddr, nla_data(tb[NL80211_ATTR_MAC]),
531 ETH_ALEN);
532
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800533 return NL_SKIP;
534}
535
536
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800537int nl80211_get_wiphy_index(struct i802_bss *bss)
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800538{
539 struct nl_msg *msg;
540 struct wiphy_idx_data data = {
541 .wiphy_idx = -1,
Dmitry Shmidt34af3062013-07-11 10:46:32 -0700542 .macaddr = NULL,
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800543 };
544
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800545 if (!(msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_GET_INTERFACE)))
546 return -1;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800547
548 if (send_and_recv_msgs(bss->drv, msg, netdev_info_handler, &data) == 0)
549 return data.wiphy_idx;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800550 return -1;
551}
552
553
Dmitry Shmidt34af3062013-07-11 10:46:32 -0700554static enum nl80211_iftype nl80211_get_ifmode(struct i802_bss *bss)
555{
556 struct nl_msg *msg;
557 struct wiphy_idx_data data = {
558 .nlmode = NL80211_IFTYPE_UNSPECIFIED,
559 .macaddr = NULL,
560 };
561
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800562 if (!(msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_GET_INTERFACE)))
563 return NL80211_IFTYPE_UNSPECIFIED;
Dmitry Shmidt34af3062013-07-11 10:46:32 -0700564
565 if (send_and_recv_msgs(bss->drv, msg, netdev_info_handler, &data) == 0)
566 return data.nlmode;
Dmitry Shmidt34af3062013-07-11 10:46:32 -0700567 return NL80211_IFTYPE_UNSPECIFIED;
568}
569
570
Dmitry Shmidt34af3062013-07-11 10:46:32 -0700571static int nl80211_get_macaddr(struct i802_bss *bss)
572{
573 struct nl_msg *msg;
574 struct wiphy_idx_data data = {
575 .macaddr = bss->addr,
576 };
577
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800578 if (!(msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_GET_INTERFACE)))
579 return -1;
Dmitry Shmidt34af3062013-07-11 10:46:32 -0700580
581 return send_and_recv_msgs(bss->drv, msg, netdev_info_handler, &data);
Dmitry Shmidt34af3062013-07-11 10:46:32 -0700582}
Dmitry Shmidt34af3062013-07-11 10:46:32 -0700583
584
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800585static int nl80211_register_beacons(struct wpa_driver_nl80211_data *drv,
586 struct nl80211_wiphy_data *w)
587{
588 struct nl_msg *msg;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800589 int ret;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800590
591 msg = nlmsg_alloc();
592 if (!msg)
593 return -1;
594
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800595 if (!nl80211_cmd(drv, msg, 0, NL80211_CMD_REGISTER_BEACONS) ||
596 nla_put_u32(msg, NL80211_ATTR_WIPHY, w->wiphy_idx)) {
597 nlmsg_free(msg);
598 return -1;
599 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800600
601 ret = send_and_recv(drv->global, w->nl_beacons, msg, NULL, NULL);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800602 if (ret) {
603 wpa_printf(MSG_DEBUG, "nl80211: Register beacons command "
604 "failed: ret=%d (%s)",
605 ret, strerror(-ret));
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800606 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800607 return ret;
608}
609
610
611static void nl80211_recv_beacons(int sock, void *eloop_ctx, void *handle)
612{
613 struct nl80211_wiphy_data *w = eloop_ctx;
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -0700614 int res;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800615
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -0800616 wpa_printf(MSG_EXCESSIVE, "nl80211: Beacon event message available");
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800617
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -0700618 res = nl_recvmsgs(handle, w->nl_cb);
Dmitry Shmidt71757432014-06-02 13:50:35 -0700619 if (res < 0) {
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -0700620 wpa_printf(MSG_INFO, "nl80211: %s->nl_recvmsgs failed: %d",
621 __func__, res);
622 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800623}
624
625
626static int process_beacon_event(struct nl_msg *msg, void *arg)
627{
628 struct nl80211_wiphy_data *w = arg;
629 struct wpa_driver_nl80211_data *drv;
630 struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg));
631 struct nlattr *tb[NL80211_ATTR_MAX + 1];
632 union wpa_event_data event;
633
634 nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0),
635 genlmsg_attrlen(gnlh, 0), NULL);
636
637 if (gnlh->cmd != NL80211_CMD_FRAME) {
638 wpa_printf(MSG_DEBUG, "nl80211: Unexpected beacon event? (%d)",
639 gnlh->cmd);
640 return NL_SKIP;
641 }
642
643 if (!tb[NL80211_ATTR_FRAME])
644 return NL_SKIP;
645
646 dl_list_for_each(drv, &w->drvs, struct wpa_driver_nl80211_data,
647 wiphy_list) {
648 os_memset(&event, 0, sizeof(event));
649 event.rx_mgmt.frame = nla_data(tb[NL80211_ATTR_FRAME]);
650 event.rx_mgmt.frame_len = nla_len(tb[NL80211_ATTR_FRAME]);
651 wpa_supplicant_event(drv->ctx, EVENT_RX_MGMT, &event);
652 }
653
654 return NL_SKIP;
655}
656
657
658static struct nl80211_wiphy_data *
659nl80211_get_wiphy_data_ap(struct i802_bss *bss)
660{
661 static DEFINE_DL_LIST(nl80211_wiphys);
662 struct nl80211_wiphy_data *w;
663 int wiphy_idx, found = 0;
664 struct i802_bss *tmp_bss;
665
666 if (bss->wiphy_data != NULL)
667 return bss->wiphy_data;
668
669 wiphy_idx = nl80211_get_wiphy_index(bss);
670
671 dl_list_for_each(w, &nl80211_wiphys, struct nl80211_wiphy_data, list) {
672 if (w->wiphy_idx == wiphy_idx)
673 goto add;
674 }
675
676 /* alloc new one */
677 w = os_zalloc(sizeof(*w));
678 if (w == NULL)
679 return NULL;
680 w->wiphy_idx = wiphy_idx;
681 dl_list_init(&w->bsss);
682 dl_list_init(&w->drvs);
683
684 w->nl_cb = nl_cb_alloc(NL_CB_DEFAULT);
685 if (!w->nl_cb) {
686 os_free(w);
687 return NULL;
688 }
689 nl_cb_set(w->nl_cb, NL_CB_SEQ_CHECK, NL_CB_CUSTOM, no_seq_check, NULL);
690 nl_cb_set(w->nl_cb, NL_CB_VALID, NL_CB_CUSTOM, process_beacon_event,
691 w);
692
693 w->nl_beacons = nl_create_handle(bss->drv->global->nl_cb,
694 "wiphy beacons");
695 if (w->nl_beacons == NULL) {
696 os_free(w);
697 return NULL;
698 }
699
700 if (nl80211_register_beacons(bss->drv, w)) {
701 nl_destroy_handles(&w->nl_beacons);
702 os_free(w);
703 return NULL;
704 }
705
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -0700706 nl80211_register_eloop_read(&w->nl_beacons, nl80211_recv_beacons, w);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800707
708 dl_list_add(&nl80211_wiphys, &w->list);
709
710add:
711 /* drv entry for this bss already there? */
712 dl_list_for_each(tmp_bss, &w->bsss, struct i802_bss, wiphy_list) {
713 if (tmp_bss->drv == bss->drv) {
714 found = 1;
715 break;
716 }
717 }
718 /* if not add it */
719 if (!found)
720 dl_list_add(&w->drvs, &bss->drv->wiphy_list);
721
722 dl_list_add(&w->bsss, &bss->wiphy_list);
723 bss->wiphy_data = w;
724 return w;
725}
726
727
728static void nl80211_put_wiphy_data_ap(struct i802_bss *bss)
729{
730 struct nl80211_wiphy_data *w = bss->wiphy_data;
731 struct i802_bss *tmp_bss;
732 int found = 0;
733
734 if (w == NULL)
735 return;
736 bss->wiphy_data = NULL;
737 dl_list_del(&bss->wiphy_list);
738
739 /* still any for this drv present? */
740 dl_list_for_each(tmp_bss, &w->bsss, struct i802_bss, wiphy_list) {
741 if (tmp_bss->drv == bss->drv) {
742 found = 1;
743 break;
744 }
745 }
746 /* if not remove it */
747 if (!found)
748 dl_list_del(&bss->drv->wiphy_list);
749
750 if (!dl_list_empty(&w->bsss))
751 return;
752
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -0700753 nl80211_destroy_eloop_handle(&w->nl_beacons);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800754
755 nl_cb_put(w->nl_cb);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800756 dl_list_del(&w->list);
757 os_free(w);
758}
759
760
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700761static int wpa_driver_nl80211_get_bssid(void *priv, u8 *bssid)
762{
763 struct i802_bss *bss = priv;
764 struct wpa_driver_nl80211_data *drv = bss->drv;
765 if (!drv->associated)
766 return -1;
767 os_memcpy(bssid, drv->bssid, ETH_ALEN);
768 return 0;
769}
770
771
772static int wpa_driver_nl80211_get_ssid(void *priv, u8 *ssid)
773{
774 struct i802_bss *bss = priv;
775 struct wpa_driver_nl80211_data *drv = bss->drv;
776 if (!drv->associated)
777 return -1;
778 os_memcpy(ssid, drv->ssid, drv->ssid_len);
779 return drv->ssid_len;
780}
781
782
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800783static void wpa_driver_nl80211_event_newlink(
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800784 struct wpa_driver_nl80211_data *drv, const char *ifname)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700785{
786 union wpa_event_data event;
787
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800788 if (os_strcmp(drv->first_bss->ifname, ifname) == 0) {
789 if (if_nametoindex(drv->first_bss->ifname) == 0) {
790 wpa_printf(MSG_DEBUG, "nl80211: Interface %s does not exist - ignore RTM_NEWLINK",
791 drv->first_bss->ifname);
792 return;
Dmitry Shmidt04949592012-07-19 12:16:46 -0700793 }
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800794 if (!drv->if_removed)
795 return;
796 wpa_printf(MSG_DEBUG, "nl80211: Mark if_removed=0 for %s based on RTM_NEWLINK event",
797 drv->first_bss->ifname);
798 drv->if_removed = 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700799 }
800
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800801 os_memset(&event, 0, sizeof(event));
802 os_strlcpy(event.interface_status.ifname, ifname,
803 sizeof(event.interface_status.ifname));
804 event.interface_status.ievent = EVENT_INTERFACE_ADDED;
805 wpa_supplicant_event(drv->ctx, EVENT_INTERFACE_STATUS, &event);
806}
807
808
809static void wpa_driver_nl80211_event_dellink(
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800810 struct wpa_driver_nl80211_data *drv, const char *ifname)
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800811{
812 union wpa_event_data event;
813
814 if (os_strcmp(drv->first_bss->ifname, ifname) == 0) {
815 if (drv->if_removed) {
816 wpa_printf(MSG_DEBUG, "nl80211: if_removed already set - ignore RTM_DELLINK event for %s",
817 ifname);
818 return;
819 }
820 wpa_printf(MSG_DEBUG, "RTM_DELLINK: Interface '%s' removed - mark if_removed=1",
821 ifname);
822 drv->if_removed = 1;
823 } else {
824 wpa_printf(MSG_DEBUG, "RTM_DELLINK: Interface '%s' removed",
825 ifname);
826 }
827
828 os_memset(&event, 0, sizeof(event));
829 os_strlcpy(event.interface_status.ifname, ifname,
830 sizeof(event.interface_status.ifname));
831 event.interface_status.ievent = EVENT_INTERFACE_REMOVED;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700832 wpa_supplicant_event(drv->ctx, EVENT_INTERFACE_STATUS, &event);
833}
834
835
836static int wpa_driver_nl80211_own_ifname(struct wpa_driver_nl80211_data *drv,
837 u8 *buf, size_t len)
838{
839 int attrlen, rta_len;
840 struct rtattr *attr;
841
842 attrlen = len;
843 attr = (struct rtattr *) buf;
844
845 rta_len = RTA_ALIGN(sizeof(struct rtattr));
846 while (RTA_OK(attr, attrlen)) {
847 if (attr->rta_type == IFLA_IFNAME) {
Dmitry Shmidtcce06662013-11-04 18:44:24 -0800848 if (os_strcmp(((char *) attr) + rta_len,
849 drv->first_bss->ifname) == 0)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700850 return 1;
851 else
852 break;
853 }
854 attr = RTA_NEXT(attr, attrlen);
855 }
856
857 return 0;
858}
859
860
861static int wpa_driver_nl80211_own_ifindex(struct wpa_driver_nl80211_data *drv,
862 int ifindex, u8 *buf, size_t len)
863{
864 if (drv->ifindex == ifindex)
865 return 1;
866
867 if (drv->if_removed && wpa_driver_nl80211_own_ifname(drv, buf, len)) {
Dmitry Shmidt7f656022015-02-25 14:36:37 -0800868 nl80211_check_global(drv->global);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700869 wpa_printf(MSG_DEBUG, "nl80211: Update ifindex for a removed "
870 "interface");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800871 wpa_driver_nl80211_finish_drv_init(drv, NULL, 0, NULL);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700872 return 1;
873 }
874
875 return 0;
876}
877
878
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800879static struct wpa_driver_nl80211_data *
880nl80211_find_drv(struct nl80211_global *global, int idx, u8 *buf, size_t len)
881{
882 struct wpa_driver_nl80211_data *drv;
883 dl_list_for_each(drv, &global->interfaces,
884 struct wpa_driver_nl80211_data, list) {
885 if (wpa_driver_nl80211_own_ifindex(drv, idx, buf, len) ||
886 have_ifidx(drv, idx))
887 return drv;
888 }
889 return NULL;
890}
891
892
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700893static void wpa_driver_nl80211_event_rtm_newlink(void *ctx,
894 struct ifinfomsg *ifi,
895 u8 *buf, size_t len)
896{
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800897 struct nl80211_global *global = ctx;
898 struct wpa_driver_nl80211_data *drv;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800899 int attrlen;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700900 struct rtattr *attr;
901 u32 brid = 0;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800902 char namebuf[IFNAMSIZ];
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800903 char ifname[IFNAMSIZ + 1];
904 char extra[100], *pos, *end;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700905
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800906 drv = nl80211_find_drv(global, ifi->ifi_index, buf, len);
907 if (!drv) {
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800908 wpa_printf(MSG_DEBUG, "nl80211: Ignore RTM_NEWLINK event for foreign ifindex %d",
909 ifi->ifi_index);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700910 return;
911 }
912
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800913 extra[0] = '\0';
914 pos = extra;
915 end = pos + sizeof(extra);
916 ifname[0] = '\0';
917
918 attrlen = len;
919 attr = (struct rtattr *) buf;
920 while (RTA_OK(attr, attrlen)) {
921 switch (attr->rta_type) {
922 case IFLA_IFNAME:
923 if (RTA_PAYLOAD(attr) >= IFNAMSIZ)
924 break;
925 os_memcpy(ifname, RTA_DATA(attr), RTA_PAYLOAD(attr));
926 ifname[RTA_PAYLOAD(attr)] = '\0';
927 break;
928 case IFLA_MASTER:
929 brid = nla_get_u32((struct nlattr *) attr);
930 pos += os_snprintf(pos, end - pos, " master=%u", brid);
931 break;
932 case IFLA_WIRELESS:
933 pos += os_snprintf(pos, end - pos, " wext");
934 break;
935 case IFLA_OPERSTATE:
936 pos += os_snprintf(pos, end - pos, " operstate=%u",
937 nla_get_u32((struct nlattr *) attr));
938 break;
939 case IFLA_LINKMODE:
940 pos += os_snprintf(pos, end - pos, " linkmode=%u",
941 nla_get_u32((struct nlattr *) attr));
942 break;
943 }
944 attr = RTA_NEXT(attr, attrlen);
945 }
946 extra[sizeof(extra) - 1] = '\0';
947
Dmitry Shmidt661b4f72014-09-29 14:58:27 -0700948 wpa_printf(MSG_DEBUG, "RTM_NEWLINK: ifi_index=%d ifname=%s%s ifi_family=%d ifi_flags=0x%x (%s%s%s%s)",
949 ifi->ifi_index, ifname, extra, ifi->ifi_family,
950 ifi->ifi_flags,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700951 (ifi->ifi_flags & IFF_UP) ? "[UP]" : "",
952 (ifi->ifi_flags & IFF_RUNNING) ? "[RUNNING]" : "",
953 (ifi->ifi_flags & IFF_LOWER_UP) ? "[LOWER_UP]" : "",
954 (ifi->ifi_flags & IFF_DORMANT) ? "[DORMANT]" : "");
955
956 if (!drv->if_disabled && !(ifi->ifi_flags & IFF_UP)) {
Dmitry Shmidt7f656022015-02-25 14:36:37 -0800957 namebuf[0] = '\0';
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800958 if (if_indextoname(ifi->ifi_index, namebuf) &&
Dmitry Shmidt7f656022015-02-25 14:36:37 -0800959 linux_iface_up(drv->global->ioctl_sock, namebuf) > 0) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800960 wpa_printf(MSG_DEBUG, "nl80211: Ignore interface down "
961 "event since interface %s is up", namebuf);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800962 drv->ignore_if_down_event = 0;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800963 return;
964 }
Dmitry Shmidt7f656022015-02-25 14:36:37 -0800965 wpa_printf(MSG_DEBUG, "nl80211: Interface down (%s/%s)",
966 namebuf, ifname);
967 if (os_strcmp(drv->first_bss->ifname, ifname) != 0) {
968 wpa_printf(MSG_DEBUG,
969 "nl80211: Not the main interface (%s) - do not indicate interface down",
970 drv->first_bss->ifname);
971 } else if (drv->ignore_if_down_event) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800972 wpa_printf(MSG_DEBUG, "nl80211: Ignore interface down "
973 "event generated by mode change");
974 drv->ignore_if_down_event = 0;
975 } else {
976 drv->if_disabled = 1;
977 wpa_supplicant_event(drv->ctx,
978 EVENT_INTERFACE_DISABLED, NULL);
Dmitry Shmidta38abf92014-03-06 13:38:44 -0800979
980 /*
981 * Try to get drv again, since it may be removed as
982 * part of the EVENT_INTERFACE_DISABLED handling for
983 * dynamic interfaces
984 */
985 drv = nl80211_find_drv(global, ifi->ifi_index,
986 buf, len);
987 if (!drv)
988 return;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800989 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700990 }
991
992 if (drv->if_disabled && (ifi->ifi_flags & IFF_UP)) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800993 if (if_indextoname(ifi->ifi_index, namebuf) &&
Dmitry Shmidt7f656022015-02-25 14:36:37 -0800994 linux_iface_up(drv->global->ioctl_sock, namebuf) == 0) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800995 wpa_printf(MSG_DEBUG, "nl80211: Ignore interface up "
996 "event since interface %s is down",
997 namebuf);
Dmitry Shmidtcce06662013-11-04 18:44:24 -0800998 } else if (if_nametoindex(drv->first_bss->ifname) == 0) {
Dmitry Shmidt04949592012-07-19 12:16:46 -0700999 wpa_printf(MSG_DEBUG, "nl80211: Ignore interface up "
1000 "event since interface %s does not exist",
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001001 drv->first_bss->ifname);
Dmitry Shmidt04949592012-07-19 12:16:46 -07001002 } else if (drv->if_removed) {
1003 wpa_printf(MSG_DEBUG, "nl80211: Ignore interface up "
1004 "event since interface %s is marked "
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001005 "removed", drv->first_bss->ifname);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001006 } else {
Dmitry Shmidt9ead16e2014-10-07 13:15:23 -07001007 struct i802_bss *bss;
1008 u8 addr[ETH_ALEN];
1009
1010 /* Re-read MAC address as it may have changed */
1011 bss = get_bss_ifindex(drv, ifi->ifi_index);
1012 if (bss &&
1013 linux_get_ifhwaddr(drv->global->ioctl_sock,
1014 bss->ifname, addr) < 0) {
1015 wpa_printf(MSG_DEBUG,
1016 "nl80211: %s: failed to re-read MAC address",
1017 bss->ifname);
1018 } else if (bss &&
1019 os_memcmp(addr, bss->addr, ETH_ALEN) != 0) {
1020 wpa_printf(MSG_DEBUG,
1021 "nl80211: Own MAC address on ifindex %d (%s) changed from "
1022 MACSTR " to " MACSTR,
1023 ifi->ifi_index, bss->ifname,
1024 MAC2STR(bss->addr),
1025 MAC2STR(addr));
1026 os_memcpy(bss->addr, addr, ETH_ALEN);
1027 }
1028
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001029 wpa_printf(MSG_DEBUG, "nl80211: Interface up");
1030 drv->if_disabled = 0;
1031 wpa_supplicant_event(drv->ctx, EVENT_INTERFACE_ENABLED,
1032 NULL);
1033 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001034 }
1035
1036 /*
1037 * Some drivers send the association event before the operup event--in
1038 * this case, lifting operstate in wpa_driver_nl80211_set_operstate()
1039 * fails. This will hit us when wpa_supplicant does not need to do
1040 * IEEE 802.1X authentication
1041 */
1042 if (drv->operstate == 1 &&
1043 (ifi->ifi_flags & (IFF_LOWER_UP | IFF_DORMANT)) == IFF_LOWER_UP &&
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001044 !(ifi->ifi_flags & IFF_RUNNING)) {
1045 wpa_printf(MSG_DEBUG, "nl80211: Set IF_OPER_UP again based on ifi_flags and expected operstate");
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001046 netlink_send_oper_ifla(drv->global->netlink, drv->ifindex,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001047 -1, IF_OPER_UP);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001048 }
1049
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001050 if (ifname[0])
1051 wpa_driver_nl80211_event_newlink(drv, ifname);
1052
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001053 if (ifi->ifi_family == AF_BRIDGE && brid) {
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001054 struct i802_bss *bss;
1055
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001056 /* device has been added to bridge */
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001057 if (!if_indextoname(brid, namebuf)) {
1058 wpa_printf(MSG_DEBUG,
1059 "nl80211: Could not find bridge ifname for ifindex %u",
1060 brid);
1061 return;
1062 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001063 wpa_printf(MSG_DEBUG, "nl80211: Add ifindex %u for bridge %s",
1064 brid, namebuf);
1065 add_ifidx(drv, brid);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001066
1067 for (bss = drv->first_bss; bss; bss = bss->next) {
1068 if (os_strcmp(ifname, bss->ifname) == 0) {
1069 os_strlcpy(bss->brname, namebuf, IFNAMSIZ);
1070 break;
1071 }
1072 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001073 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001074}
1075
1076
1077static void wpa_driver_nl80211_event_rtm_dellink(void *ctx,
1078 struct ifinfomsg *ifi,
1079 u8 *buf, size_t len)
1080{
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001081 struct nl80211_global *global = ctx;
1082 struct wpa_driver_nl80211_data *drv;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001083 int attrlen;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001084 struct rtattr *attr;
1085 u32 brid = 0;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001086 char ifname[IFNAMSIZ + 1];
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07001087 char extra[100], *pos, *end;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001088
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001089 drv = nl80211_find_drv(global, ifi->ifi_index, buf, len);
1090 if (!drv) {
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001091 wpa_printf(MSG_DEBUG, "nl80211: Ignore RTM_DELLINK event for foreign ifindex %d",
1092 ifi->ifi_index);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001093 return;
1094 }
1095
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07001096 extra[0] = '\0';
1097 pos = extra;
1098 end = pos + sizeof(extra);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001099 ifname[0] = '\0';
1100
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001101 attrlen = len;
1102 attr = (struct rtattr *) buf;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001103 while (RTA_OK(attr, attrlen)) {
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001104 switch (attr->rta_type) {
1105 case IFLA_IFNAME:
1106 if (RTA_PAYLOAD(attr) >= IFNAMSIZ)
1107 break;
1108 os_memcpy(ifname, RTA_DATA(attr), RTA_PAYLOAD(attr));
1109 ifname[RTA_PAYLOAD(attr)] = '\0';
1110 break;
1111 case IFLA_MASTER:
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001112 brid = nla_get_u32((struct nlattr *) attr);
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07001113 pos += os_snprintf(pos, end - pos, " master=%u", brid);
1114 break;
1115 case IFLA_OPERSTATE:
1116 pos += os_snprintf(pos, end - pos, " operstate=%u",
1117 nla_get_u32((struct nlattr *) attr));
1118 break;
1119 case IFLA_LINKMODE:
1120 pos += os_snprintf(pos, end - pos, " linkmode=%u",
1121 nla_get_u32((struct nlattr *) attr));
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001122 break;
1123 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001124 attr = RTA_NEXT(attr, attrlen);
1125 }
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07001126 extra[sizeof(extra) - 1] = '\0';
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001127
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07001128 wpa_printf(MSG_DEBUG, "RTM_DELLINK: ifi_index=%d ifname=%s%s ifi_family=%d ifi_flags=0x%x (%s%s%s%s)",
1129 ifi->ifi_index, ifname, extra, ifi->ifi_family,
1130 ifi->ifi_flags,
1131 (ifi->ifi_flags & IFF_UP) ? "[UP]" : "",
1132 (ifi->ifi_flags & IFF_RUNNING) ? "[RUNNING]" : "",
1133 (ifi->ifi_flags & IFF_LOWER_UP) ? "[LOWER_UP]" : "",
1134 (ifi->ifi_flags & IFF_DORMANT) ? "[DORMANT]" : "");
1135
1136 if (ifname[0] && (ifi->ifi_family != AF_BRIDGE || !brid))
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001137 wpa_driver_nl80211_event_dellink(drv, ifname);
1138
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001139 if (ifi->ifi_family == AF_BRIDGE && brid) {
1140 /* device has been removed from bridge */
1141 char namebuf[IFNAMSIZ];
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001142
1143 if (!if_indextoname(brid, namebuf)) {
1144 wpa_printf(MSG_DEBUG,
1145 "nl80211: Could not find bridge ifname for ifindex %u",
1146 brid);
1147 } else {
1148 wpa_printf(MSG_DEBUG,
1149 "nl80211: Remove ifindex %u for bridge %s",
1150 brid, namebuf);
1151 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001152 del_ifidx(drv, brid);
1153 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001154}
1155
1156
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001157unsigned int nl80211_get_assoc_freq(struct wpa_driver_nl80211_data *drv)
Jouni Malinen87fd2792011-05-16 18:35:42 +03001158{
1159 struct nl_msg *msg;
1160 int ret;
1161 struct nl80211_bss_info_arg arg;
1162
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001163 msg = nl80211_drv_msg(drv, NLM_F_DUMP, NL80211_CMD_GET_SCAN);
Jouni Malinen87fd2792011-05-16 18:35:42 +03001164 os_memset(&arg, 0, sizeof(arg));
Jouni Malinen87fd2792011-05-16 18:35:42 +03001165 arg.drv = drv;
1166 ret = send_and_recv_msgs(drv, msg, bss_info_handler, &arg);
Jouni Malinen87fd2792011-05-16 18:35:42 +03001167 if (ret == 0) {
Dmitry Shmidt6dc03bd2014-05-16 10:40:13 -07001168 unsigned int freq = drv->nlmode == NL80211_IFTYPE_ADHOC ?
1169 arg.ibss_freq : arg.assoc_freq;
Jouni Malinen87fd2792011-05-16 18:35:42 +03001170 wpa_printf(MSG_DEBUG, "nl80211: Operating frequency for the "
Dmitry Shmidt6dc03bd2014-05-16 10:40:13 -07001171 "associated BSS from scan results: %u MHz", freq);
1172 if (freq)
1173 drv->assoc_freq = freq;
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -07001174 return drv->assoc_freq;
Jouni Malinen87fd2792011-05-16 18:35:42 +03001175 }
1176 wpa_printf(MSG_DEBUG, "nl80211: Scan result fetch failed: ret=%d "
1177 "(%s)", ret, strerror(-ret));
Jouni Malinen87fd2792011-05-16 18:35:42 +03001178 return drv->assoc_freq;
1179}
1180
1181
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001182static int get_link_signal(struct nl_msg *msg, void *arg)
1183{
1184 struct nlattr *tb[NL80211_ATTR_MAX + 1];
1185 struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg));
1186 struct nlattr *sinfo[NL80211_STA_INFO_MAX + 1];
1187 static struct nla_policy policy[NL80211_STA_INFO_MAX + 1] = {
1188 [NL80211_STA_INFO_SIGNAL] = { .type = NLA_U8 },
Dmitry Shmidt34af3062013-07-11 10:46:32 -07001189 [NL80211_STA_INFO_SIGNAL_AVG] = { .type = NLA_U8 },
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001190 };
1191 struct nlattr *rinfo[NL80211_RATE_INFO_MAX + 1];
1192 static struct nla_policy rate_policy[NL80211_RATE_INFO_MAX + 1] = {
1193 [NL80211_RATE_INFO_BITRATE] = { .type = NLA_U16 },
1194 [NL80211_RATE_INFO_MCS] = { .type = NLA_U8 },
1195 [NL80211_RATE_INFO_40_MHZ_WIDTH] = { .type = NLA_FLAG },
1196 [NL80211_RATE_INFO_SHORT_GI] = { .type = NLA_FLAG },
1197 };
1198 struct wpa_signal_info *sig_change = arg;
1199
1200 nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0),
1201 genlmsg_attrlen(gnlh, 0), NULL);
1202 if (!tb[NL80211_ATTR_STA_INFO] ||
1203 nla_parse_nested(sinfo, NL80211_STA_INFO_MAX,
1204 tb[NL80211_ATTR_STA_INFO], policy))
1205 return NL_SKIP;
1206 if (!sinfo[NL80211_STA_INFO_SIGNAL])
1207 return NL_SKIP;
1208
1209 sig_change->current_signal =
1210 (s8) nla_get_u8(sinfo[NL80211_STA_INFO_SIGNAL]);
1211
Dmitry Shmidt34af3062013-07-11 10:46:32 -07001212 if (sinfo[NL80211_STA_INFO_SIGNAL_AVG])
1213 sig_change->avg_signal =
1214 (s8) nla_get_u8(sinfo[NL80211_STA_INFO_SIGNAL_AVG]);
1215 else
1216 sig_change->avg_signal = 0;
1217
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001218 if (sinfo[NL80211_STA_INFO_TX_BITRATE]) {
1219 if (nla_parse_nested(rinfo, NL80211_RATE_INFO_MAX,
1220 sinfo[NL80211_STA_INFO_TX_BITRATE],
1221 rate_policy)) {
1222 sig_change->current_txrate = 0;
1223 } else {
1224 if (rinfo[NL80211_RATE_INFO_BITRATE]) {
1225 sig_change->current_txrate =
1226 nla_get_u16(rinfo[
1227 NL80211_RATE_INFO_BITRATE]) * 100;
1228 }
1229 }
1230 }
1231
1232 return NL_SKIP;
1233}
1234
1235
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001236int nl80211_get_link_signal(struct wpa_driver_nl80211_data *drv,
1237 struct wpa_signal_info *sig)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001238{
1239 struct nl_msg *msg;
1240
1241 sig->current_signal = -9999;
1242 sig->current_txrate = 0;
1243
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001244 if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_GET_STATION)) ||
1245 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, drv->bssid)) {
1246 nlmsg_free(msg);
1247 return -ENOBUFS;
1248 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001249
1250 return send_and_recv_msgs(drv, msg, get_link_signal, sig);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001251}
1252
1253
1254static int get_link_noise(struct nl_msg *msg, void *arg)
1255{
1256 struct nlattr *tb[NL80211_ATTR_MAX + 1];
1257 struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg));
1258 struct nlattr *sinfo[NL80211_SURVEY_INFO_MAX + 1];
1259 static struct nla_policy survey_policy[NL80211_SURVEY_INFO_MAX + 1] = {
1260 [NL80211_SURVEY_INFO_FREQUENCY] = { .type = NLA_U32 },
1261 [NL80211_SURVEY_INFO_NOISE] = { .type = NLA_U8 },
1262 };
1263 struct wpa_signal_info *sig_change = arg;
1264
1265 nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0),
1266 genlmsg_attrlen(gnlh, 0), NULL);
1267
1268 if (!tb[NL80211_ATTR_SURVEY_INFO]) {
1269 wpa_printf(MSG_DEBUG, "nl80211: survey data missing!");
1270 return NL_SKIP;
1271 }
1272
1273 if (nla_parse_nested(sinfo, NL80211_SURVEY_INFO_MAX,
1274 tb[NL80211_ATTR_SURVEY_INFO],
1275 survey_policy)) {
1276 wpa_printf(MSG_DEBUG, "nl80211: failed to parse nested "
1277 "attributes!");
1278 return NL_SKIP;
1279 }
1280
1281 if (!sinfo[NL80211_SURVEY_INFO_FREQUENCY])
1282 return NL_SKIP;
1283
1284 if (nla_get_u32(sinfo[NL80211_SURVEY_INFO_FREQUENCY]) !=
1285 sig_change->frequency)
1286 return NL_SKIP;
1287
1288 if (!sinfo[NL80211_SURVEY_INFO_NOISE])
1289 return NL_SKIP;
1290
1291 sig_change->current_noise =
1292 (s8) nla_get_u8(sinfo[NL80211_SURVEY_INFO_NOISE]);
1293
1294 return NL_SKIP;
1295}
1296
1297
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001298int nl80211_get_link_noise(struct wpa_driver_nl80211_data *drv,
1299 struct wpa_signal_info *sig_change)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001300{
1301 struct nl_msg *msg;
1302
1303 sig_change->current_noise = 9999;
1304 sig_change->frequency = drv->assoc_freq;
1305
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001306 msg = nl80211_drv_msg(drv, NLM_F_DUMP, NL80211_CMD_GET_SURVEY);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001307 return send_and_recv_msgs(drv, msg, get_link_noise, sig_change);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001308}
1309
1310
1311static void wpa_driver_nl80211_event_receive(int sock, void *eloop_ctx,
1312 void *handle)
1313{
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001314 struct nl_cb *cb = eloop_ctx;
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -07001315 int res;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001316
Dmitry Shmidt8da800a2013-04-24 12:57:01 -07001317 wpa_printf(MSG_MSGDUMP, "nl80211: Event message available");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001318
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -07001319 res = nl_recvmsgs(handle, cb);
Dmitry Shmidt71757432014-06-02 13:50:35 -07001320 if (res < 0) {
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -07001321 wpa_printf(MSG_INFO, "nl80211: %s->nl_recvmsgs failed: %d",
1322 __func__, res);
1323 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001324}
1325
1326
1327/**
1328 * wpa_driver_nl80211_set_country - ask nl80211 to set the regulatory domain
1329 * @priv: driver_nl80211 private data
1330 * @alpha2_arg: country to which to switch to
1331 * Returns: 0 on success, -1 on failure
1332 *
1333 * This asks nl80211 to set the regulatory domain for given
1334 * country ISO / IEC alpha2.
1335 */
1336static int wpa_driver_nl80211_set_country(void *priv, const char *alpha2_arg)
1337{
1338 struct i802_bss *bss = priv;
1339 struct wpa_driver_nl80211_data *drv = bss->drv;
1340 char alpha2[3];
1341 struct nl_msg *msg;
1342
1343 msg = nlmsg_alloc();
1344 if (!msg)
1345 return -ENOMEM;
1346
1347 alpha2[0] = alpha2_arg[0];
1348 alpha2[1] = alpha2_arg[1];
1349 alpha2[2] = '\0';
1350
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001351 if (!nl80211_cmd(drv, msg, 0, NL80211_CMD_REQ_SET_REG) ||
1352 nla_put_string(msg, NL80211_ATTR_REG_ALPHA2, alpha2)) {
1353 nlmsg_free(msg);
1354 return -EINVAL;
1355 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001356 if (send_and_recv_msgs(drv, msg, NULL, NULL))
1357 return -EINVAL;
1358 return 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001359}
1360
1361
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001362static int nl80211_get_country(struct nl_msg *msg, void *arg)
1363{
1364 char *alpha2 = arg;
1365 struct nlattr *tb_msg[NL80211_ATTR_MAX + 1];
1366 struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg));
1367
1368 nla_parse(tb_msg, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0),
1369 genlmsg_attrlen(gnlh, 0), NULL);
1370 if (!tb_msg[NL80211_ATTR_REG_ALPHA2]) {
1371 wpa_printf(MSG_DEBUG, "nl80211: No country information available");
1372 return NL_SKIP;
1373 }
1374 os_strlcpy(alpha2, nla_data(tb_msg[NL80211_ATTR_REG_ALPHA2]), 3);
1375 return NL_SKIP;
1376}
1377
1378
1379static int wpa_driver_nl80211_get_country(void *priv, char *alpha2)
1380{
1381 struct i802_bss *bss = priv;
1382 struct wpa_driver_nl80211_data *drv = bss->drv;
1383 struct nl_msg *msg;
1384 int ret;
1385
1386 msg = nlmsg_alloc();
1387 if (!msg)
1388 return -ENOMEM;
1389
1390 nl80211_cmd(drv, msg, 0, NL80211_CMD_GET_REG);
1391 alpha2[0] = '\0';
1392 ret = send_and_recv_msgs(drv, msg, nl80211_get_country, alpha2);
1393 if (!alpha2[0])
1394 ret = -1;
1395
1396 return ret;
1397}
1398
1399
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001400static int wpa_driver_nl80211_init_nl_global(struct nl80211_global *global)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001401{
1402 int ret;
1403
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001404 global->nl_cb = nl_cb_alloc(NL_CB_DEFAULT);
1405 if (global->nl_cb == NULL) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001406 wpa_printf(MSG_ERROR, "nl80211: Failed to allocate netlink "
1407 "callbacks");
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001408 return -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001409 }
1410
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001411 global->nl = nl_create_handle(global->nl_cb, "nl");
1412 if (global->nl == NULL)
1413 goto err;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001414
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001415 global->nl80211_id = genl_ctrl_resolve(global->nl, "nl80211");
1416 if (global->nl80211_id < 0) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001417 wpa_printf(MSG_ERROR, "nl80211: 'nl80211' generic netlink not "
1418 "found");
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001419 goto err;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001420 }
1421
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001422 global->nl_event = nl_create_handle(global->nl_cb, "event");
1423 if (global->nl_event == NULL)
1424 goto err;
1425
1426 ret = nl_get_multicast_id(global, "nl80211", "scan");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001427 if (ret >= 0)
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001428 ret = nl_socket_add_membership(global->nl_event, ret);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001429 if (ret < 0) {
1430 wpa_printf(MSG_ERROR, "nl80211: Could not add multicast "
1431 "membership for scan events: %d (%s)",
1432 ret, strerror(-ret));
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001433 goto err;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001434 }
1435
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001436 ret = nl_get_multicast_id(global, "nl80211", "mlme");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001437 if (ret >= 0)
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001438 ret = nl_socket_add_membership(global->nl_event, ret);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001439 if (ret < 0) {
1440 wpa_printf(MSG_ERROR, "nl80211: Could not add multicast "
1441 "membership for mlme events: %d (%s)",
1442 ret, strerror(-ret));
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001443 goto err;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001444 }
1445
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001446 ret = nl_get_multicast_id(global, "nl80211", "regulatory");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001447 if (ret >= 0)
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001448 ret = nl_socket_add_membership(global->nl_event, ret);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001449 if (ret < 0) {
1450 wpa_printf(MSG_DEBUG, "nl80211: Could not add multicast "
1451 "membership for regulatory events: %d (%s)",
1452 ret, strerror(-ret));
1453 /* Continue without regulatory events */
1454 }
1455
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001456 ret = nl_get_multicast_id(global, "nl80211", "vendor");
1457 if (ret >= 0)
1458 ret = nl_socket_add_membership(global->nl_event, ret);
1459 if (ret < 0) {
1460 wpa_printf(MSG_DEBUG, "nl80211: Could not add multicast "
1461 "membership for vendor events: %d (%s)",
1462 ret, strerror(-ret));
1463 /* Continue without vendor events */
1464 }
1465
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001466 nl_cb_set(global->nl_cb, NL_CB_SEQ_CHECK, NL_CB_CUSTOM,
1467 no_seq_check, NULL);
1468 nl_cb_set(global->nl_cb, NL_CB_VALID, NL_CB_CUSTOM,
1469 process_global_event, global);
1470
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -07001471 nl80211_register_eloop_read(&global->nl_event,
1472 wpa_driver_nl80211_event_receive,
1473 global->nl_cb);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001474
1475 return 0;
1476
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001477err:
1478 nl_destroy_handles(&global->nl_event);
1479 nl_destroy_handles(&global->nl);
1480 nl_cb_put(global->nl_cb);
1481 global->nl_cb = NULL;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001482 return -1;
1483}
1484
1485
Dmitry Shmidt7f656022015-02-25 14:36:37 -08001486static void nl80211_check_global(struct nl80211_global *global)
1487{
1488 struct nl_handle *handle;
1489 const char *groups[] = { "scan", "mlme", "regulatory", "vendor", NULL };
1490 int ret;
1491 unsigned int i;
1492
1493 /*
1494 * Try to re-add memberships to handle case of cfg80211 getting reloaded
1495 * and all registration having been cleared.
1496 */
1497 handle = (void *) (((intptr_t) global->nl_event) ^
1498 ELOOP_SOCKET_INVALID);
1499
1500 for (i = 0; groups[i]; i++) {
1501 ret = nl_get_multicast_id(global, "nl80211", groups[i]);
1502 if (ret >= 0)
1503 ret = nl_socket_add_membership(handle, ret);
1504 if (ret < 0) {
1505 wpa_printf(MSG_INFO,
1506 "nl80211: Could not re-add multicast membership for %s events: %d (%s)",
1507 groups[i], ret, strerror(-ret));
1508 }
1509 }
1510}
1511
1512
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001513static void wpa_driver_nl80211_rfkill_blocked(void *ctx)
1514{
1515 wpa_printf(MSG_DEBUG, "nl80211: RFKILL blocked");
1516 /*
1517 * This may be for any interface; use ifdown event to disable
1518 * interface.
1519 */
1520}
1521
1522
1523static void wpa_driver_nl80211_rfkill_unblocked(void *ctx)
1524{
1525 struct wpa_driver_nl80211_data *drv = ctx;
1526 wpa_printf(MSG_DEBUG, "nl80211: RFKILL unblocked");
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001527 if (i802_set_iface_flags(drv->first_bss, 1)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001528 wpa_printf(MSG_DEBUG, "nl80211: Could not set interface UP "
1529 "after rfkill unblock");
1530 return;
1531 }
1532 /* rtnetlink ifup handler will report interface as enabled */
1533}
1534
1535
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001536static void wpa_driver_nl80211_handle_eapol_tx_status(int sock,
1537 void *eloop_ctx,
1538 void *handle)
1539{
1540 struct wpa_driver_nl80211_data *drv = eloop_ctx;
1541 u8 data[2048];
1542 struct msghdr msg;
1543 struct iovec entry;
Dmitry Shmidt04949592012-07-19 12:16:46 -07001544 u8 control[512];
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001545 struct cmsghdr *cmsg;
1546 int res, found_ee = 0, found_wifi = 0, acked = 0;
1547 union wpa_event_data event;
1548
1549 memset(&msg, 0, sizeof(msg));
1550 msg.msg_iov = &entry;
1551 msg.msg_iovlen = 1;
1552 entry.iov_base = data;
1553 entry.iov_len = sizeof(data);
1554 msg.msg_control = &control;
1555 msg.msg_controllen = sizeof(control);
1556
1557 res = recvmsg(sock, &msg, MSG_ERRQUEUE);
1558 /* if error or not fitting 802.3 header, return */
1559 if (res < 14)
1560 return;
1561
1562 for (cmsg = CMSG_FIRSTHDR(&msg); cmsg; cmsg = CMSG_NXTHDR(&msg, cmsg))
1563 {
1564 if (cmsg->cmsg_level == SOL_SOCKET &&
1565 cmsg->cmsg_type == SCM_WIFI_STATUS) {
1566 int *ack;
1567
1568 found_wifi = 1;
1569 ack = (void *)CMSG_DATA(cmsg);
1570 acked = *ack;
1571 }
1572
1573 if (cmsg->cmsg_level == SOL_PACKET &&
1574 cmsg->cmsg_type == PACKET_TX_TIMESTAMP) {
1575 struct sock_extended_err *err =
1576 (struct sock_extended_err *)CMSG_DATA(cmsg);
1577
1578 if (err->ee_origin == SO_EE_ORIGIN_TXSTATUS)
1579 found_ee = 1;
1580 }
1581 }
1582
1583 if (!found_ee || !found_wifi)
1584 return;
1585
1586 memset(&event, 0, sizeof(event));
1587 event.eapol_tx_status.dst = data;
1588 event.eapol_tx_status.data = data + 14;
1589 event.eapol_tx_status.data_len = res - 14;
1590 event.eapol_tx_status.ack = acked;
1591 wpa_supplicant_event(drv->ctx, EVENT_EAPOL_TX_STATUS, &event);
1592}
1593
1594
1595static int nl80211_init_bss(struct i802_bss *bss)
1596{
1597 bss->nl_cb = nl_cb_alloc(NL_CB_DEFAULT);
1598 if (!bss->nl_cb)
1599 return -1;
1600
1601 nl_cb_set(bss->nl_cb, NL_CB_SEQ_CHECK, NL_CB_CUSTOM,
1602 no_seq_check, NULL);
1603 nl_cb_set(bss->nl_cb, NL_CB_VALID, NL_CB_CUSTOM,
1604 process_bss_event, bss);
1605
1606 return 0;
1607}
1608
1609
1610static void nl80211_destroy_bss(struct i802_bss *bss)
1611{
1612 nl_cb_put(bss->nl_cb);
1613 bss->nl_cb = NULL;
1614}
1615
1616
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08001617static void * wpa_driver_nl80211_drv_init(void *ctx, const char *ifname,
1618 void *global_priv, int hostapd,
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001619 const u8 *set_addr,
1620 const char *driver_params)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001621{
1622 struct wpa_driver_nl80211_data *drv;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001623 struct rfkill_config *rcfg;
1624 struct i802_bss *bss;
1625
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001626 if (global_priv == NULL)
1627 return NULL;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001628 drv = os_zalloc(sizeof(*drv));
1629 if (drv == NULL)
1630 return NULL;
1631 drv->global = global_priv;
1632 drv->ctx = ctx;
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08001633 drv->hostapd = !!hostapd;
1634 drv->eapol_sock = -1;
Dmitry Shmidtff787d52015-01-12 13:01:47 -08001635
1636 /*
1637 * There is no driver capability flag for this, so assume it is
1638 * supported and disable this on first attempt to use if the driver
1639 * rejects the command due to missing support.
1640 */
1641 drv->set_rekey_offload = 1;
1642
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08001643 drv->num_if_indices = sizeof(drv->default_if_indices) / sizeof(int);
1644 drv->if_indices = drv->default_if_indices;
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001645
1646 drv->first_bss = os_zalloc(sizeof(*drv->first_bss));
1647 if (!drv->first_bss) {
1648 os_free(drv);
1649 return NULL;
1650 }
1651 bss = drv->first_bss;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001652 bss->drv = drv;
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08001653 bss->ctx = ctx;
1654
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001655 os_strlcpy(bss->ifname, ifname, sizeof(bss->ifname));
1656 drv->monitor_ifidx = -1;
1657 drv->monitor_sock = -1;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001658 drv->eapol_tx_sock = -1;
1659 drv->ap_scan_as_station = NL80211_IFTYPE_UNSPECIFIED;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001660
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001661 if (nl80211_init_bss(bss))
1662 goto failed;
1663
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001664 rcfg = os_zalloc(sizeof(*rcfg));
1665 if (rcfg == NULL)
1666 goto failed;
1667 rcfg->ctx = drv;
1668 os_strlcpy(rcfg->ifname, ifname, sizeof(rcfg->ifname));
1669 rcfg->blocked_cb = wpa_driver_nl80211_rfkill_blocked;
1670 rcfg->unblocked_cb = wpa_driver_nl80211_rfkill_unblocked;
1671 drv->rfkill = rfkill_init(rcfg);
1672 if (drv->rfkill == NULL) {
1673 wpa_printf(MSG_DEBUG, "nl80211: RFKILL status not available");
1674 os_free(rcfg);
1675 }
1676
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08001677 if (linux_iface_up(drv->global->ioctl_sock, ifname) > 0)
1678 drv->start_iface_up = 1;
1679
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001680 if (wpa_driver_nl80211_finish_drv_init(drv, set_addr, 1, driver_params))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001681 goto failed;
1682
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001683 drv->eapol_tx_sock = socket(PF_PACKET, SOCK_DGRAM, 0);
1684 if (drv->eapol_tx_sock < 0)
1685 goto failed;
1686
1687 if (drv->data_tx_status) {
1688 int enabled = 1;
1689
1690 if (setsockopt(drv->eapol_tx_sock, SOL_SOCKET, SO_WIFI_STATUS,
1691 &enabled, sizeof(enabled)) < 0) {
1692 wpa_printf(MSG_DEBUG,
1693 "nl80211: wifi status sockopt failed\n");
1694 drv->data_tx_status = 0;
1695 if (!drv->use_monitor)
1696 drv->capa.flags &=
1697 ~WPA_DRIVER_FLAGS_EAPOL_TX_STATUS;
1698 } else {
1699 eloop_register_read_sock(drv->eapol_tx_sock,
1700 wpa_driver_nl80211_handle_eapol_tx_status,
1701 drv, NULL);
1702 }
1703 }
1704
1705 if (drv->global) {
Dmitry Shmidt7f656022015-02-25 14:36:37 -08001706 nl80211_check_global(drv->global);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001707 dl_list_add(&drv->global->interfaces, &drv->list);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001708 drv->in_interface_list = 1;
1709 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001710
1711 return bss;
1712
1713failed:
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001714 wpa_driver_nl80211_deinit(bss);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001715 return NULL;
1716}
1717
1718
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08001719/**
1720 * wpa_driver_nl80211_init - Initialize nl80211 driver interface
1721 * @ctx: context to be used when calling wpa_supplicant functions,
1722 * e.g., wpa_supplicant_event()
1723 * @ifname: interface name, e.g., wlan0
1724 * @global_priv: private driver global data from global_init()
1725 * Returns: Pointer to private data, %NULL on failure
1726 */
1727static void * wpa_driver_nl80211_init(void *ctx, const char *ifname,
1728 void *global_priv)
1729{
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001730 return wpa_driver_nl80211_drv_init(ctx, ifname, global_priv, 0, NULL,
1731 NULL);
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08001732}
1733
1734
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001735static int nl80211_register_frame(struct i802_bss *bss,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001736 struct nl_handle *nl_handle,
1737 u16 type, const u8 *match, size_t match_len)
1738{
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001739 struct wpa_driver_nl80211_data *drv = bss->drv;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001740 struct nl_msg *msg;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001741 int ret;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001742 char buf[30];
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001743
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001744 buf[0] = '\0';
1745 wpa_snprintf_hex(buf, sizeof(buf), match, match_len);
Dmitry Shmidt2271d3f2014-06-23 12:16:31 -07001746 wpa_printf(MSG_DEBUG, "nl80211: Register frame type=0x%x (%s) nl_handle=%p match=%s",
1747 type, fc2str(type), nl_handle, buf);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001748
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001749 if (!(msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_REGISTER_ACTION)) ||
1750 nla_put_u16(msg, NL80211_ATTR_FRAME_TYPE, type) ||
1751 nla_put(msg, NL80211_ATTR_FRAME_MATCH, match_len, match)) {
1752 nlmsg_free(msg);
1753 return -1;
1754 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001755
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001756 ret = send_and_recv(drv->global, nl_handle, msg, NULL, NULL);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001757 if (ret) {
1758 wpa_printf(MSG_DEBUG, "nl80211: Register frame command "
1759 "failed (type=%u): ret=%d (%s)",
1760 type, ret, strerror(-ret));
1761 wpa_hexdump(MSG_DEBUG, "nl80211: Register frame match",
1762 match, match_len);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001763 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001764 return ret;
1765}
1766
1767
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001768static int nl80211_alloc_mgmt_handle(struct i802_bss *bss)
1769{
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001770 if (bss->nl_mgmt) {
1771 wpa_printf(MSG_DEBUG, "nl80211: Mgmt reporting "
1772 "already on! (nl_mgmt=%p)", bss->nl_mgmt);
1773 return -1;
1774 }
1775
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001776 bss->nl_mgmt = nl_create_handle(bss->nl_cb, "mgmt");
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001777 if (bss->nl_mgmt == NULL)
1778 return -1;
1779
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001780 return 0;
1781}
1782
1783
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -07001784static void nl80211_mgmt_handle_register_eloop(struct i802_bss *bss)
1785{
1786 nl80211_register_eloop_read(&bss->nl_mgmt,
1787 wpa_driver_nl80211_event_receive,
1788 bss->nl_cb);
1789}
1790
1791
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001792static int nl80211_register_action_frame(struct i802_bss *bss,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001793 const u8 *match, size_t match_len)
1794{
1795 u16 type = (WLAN_FC_TYPE_MGMT << 2) | (WLAN_FC_STYPE_ACTION << 4);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001796 return nl80211_register_frame(bss, bss->nl_mgmt,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001797 type, match, match_len);
1798}
1799
1800
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001801static int nl80211_mgmt_subscribe_non_ap(struct i802_bss *bss)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001802{
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001803 struct wpa_driver_nl80211_data *drv = bss->drv;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001804 int ret = 0;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001805
1806 if (nl80211_alloc_mgmt_handle(bss))
1807 return -1;
1808 wpa_printf(MSG_DEBUG, "nl80211: Subscribe to mgmt frames with non-AP "
1809 "handle %p", bss->nl_mgmt);
1810
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -07001811 if (drv->nlmode == NL80211_IFTYPE_ADHOC) {
1812 u16 type = (WLAN_FC_TYPE_MGMT << 2) | (WLAN_FC_STYPE_AUTH << 4);
1813
1814 /* register for any AUTH message */
1815 nl80211_register_frame(bss, bss->nl_mgmt, type, NULL, 0);
1816 }
1817
Dmitry Shmidt051af732013-10-22 13:52:46 -07001818#ifdef CONFIG_INTERWORKING
1819 /* QoS Map Configure */
1820 if (nl80211_register_action_frame(bss, (u8 *) "\x01\x04", 2) < 0)
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001821 ret = -1;
Dmitry Shmidt051af732013-10-22 13:52:46 -07001822#endif /* CONFIG_INTERWORKING */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001823#if defined(CONFIG_P2P) || defined(CONFIG_INTERWORKING)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001824 /* GAS Initial Request */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001825 if (nl80211_register_action_frame(bss, (u8 *) "\x04\x0a", 2) < 0)
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001826 ret = -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001827 /* GAS Initial Response */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001828 if (nl80211_register_action_frame(bss, (u8 *) "\x04\x0b", 2) < 0)
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001829 ret = -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001830 /* GAS Comeback Request */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001831 if (nl80211_register_action_frame(bss, (u8 *) "\x04\x0c", 2) < 0)
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001832 ret = -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001833 /* GAS Comeback Response */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001834 if (nl80211_register_action_frame(bss, (u8 *) "\x04\x0d", 2) < 0)
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001835 ret = -1;
Dmitry Shmidt18463232014-01-24 12:29:41 -08001836 /* Protected GAS Initial Request */
1837 if (nl80211_register_action_frame(bss, (u8 *) "\x09\x0a", 2) < 0)
1838 ret = -1;
1839 /* Protected GAS Initial Response */
1840 if (nl80211_register_action_frame(bss, (u8 *) "\x09\x0b", 2) < 0)
1841 ret = -1;
1842 /* Protected GAS Comeback Request */
1843 if (nl80211_register_action_frame(bss, (u8 *) "\x09\x0c", 2) < 0)
1844 ret = -1;
1845 /* Protected GAS Comeback Response */
1846 if (nl80211_register_action_frame(bss, (u8 *) "\x09\x0d", 2) < 0)
1847 ret = -1;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001848#endif /* CONFIG_P2P || CONFIG_INTERWORKING */
1849#ifdef CONFIG_P2P
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001850 /* P2P Public Action */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001851 if (nl80211_register_action_frame(bss,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001852 (u8 *) "\x04\x09\x50\x6f\x9a\x09",
1853 6) < 0)
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001854 ret = -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001855 /* P2P Action */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001856 if (nl80211_register_action_frame(bss,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001857 (u8 *) "\x7f\x50\x6f\x9a\x09",
1858 5) < 0)
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001859 ret = -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001860#endif /* CONFIG_P2P */
1861#ifdef CONFIG_IEEE80211W
1862 /* SA Query Response */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001863 if (nl80211_register_action_frame(bss, (u8 *) "\x08\x01", 2) < 0)
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001864 ret = -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001865#endif /* CONFIG_IEEE80211W */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001866#ifdef CONFIG_TDLS
1867 if ((drv->capa.flags & WPA_DRIVER_FLAGS_TDLS_SUPPORT)) {
1868 /* TDLS Discovery Response */
1869 if (nl80211_register_action_frame(bss, (u8 *) "\x04\x0e", 2) <
1870 0)
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001871 ret = -1;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001872 }
1873#endif /* CONFIG_TDLS */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001874
1875 /* FT Action frames */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001876 if (nl80211_register_action_frame(bss, (u8 *) "\x06", 1) < 0)
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001877 ret = -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001878 else
1879 drv->capa.key_mgmt |= WPA_DRIVER_CAPA_KEY_MGMT_FT |
1880 WPA_DRIVER_CAPA_KEY_MGMT_FT_PSK;
1881
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001882 /* WNM - BSS Transition Management Request */
1883 if (nl80211_register_action_frame(bss, (u8 *) "\x0a\x07", 2) < 0)
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001884 ret = -1;
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08001885 /* WNM-Sleep Mode Response */
1886 if (nl80211_register_action_frame(bss, (u8 *) "\x0a\x11", 2) < 0)
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001887 ret = -1;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001888
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08001889#ifdef CONFIG_HS20
1890 /* WNM-Notification */
1891 if (nl80211_register_action_frame(bss, (u8 *) "\x0a\x1a", 2) < 0)
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07001892 ret = -1;
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08001893#endif /* CONFIG_HS20 */
1894
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001895 /* WMM-AC ADDTS Response */
1896 if (nl80211_register_action_frame(bss, (u8 *) "\x11\x01", 2) < 0)
1897 ret = -1;
1898
1899 /* WMM-AC DELTS */
1900 if (nl80211_register_action_frame(bss, (u8 *) "\x11\x02", 2) < 0)
1901 ret = -1;
1902
1903 /* Radio Measurement - Neighbor Report Response */
1904 if (nl80211_register_action_frame(bss, (u8 *) "\x05\x05", 2) < 0)
1905 ret = -1;
1906
1907 /* Radio Measurement - Link Measurement Request */
1908 if ((drv->capa.rrm_flags & WPA_DRIVER_FLAGS_TX_POWER_INSERTION) &&
1909 (nl80211_register_action_frame(bss, (u8 *) "\x05\x02", 2) < 0))
1910 ret = -1;
1911
1912 nl80211_mgmt_handle_register_eloop(bss);
1913
1914 return ret;
1915}
1916
1917
1918static int nl80211_mgmt_subscribe_mesh(struct i802_bss *bss)
1919{
1920 int ret = 0;
1921
1922 if (nl80211_alloc_mgmt_handle(bss))
1923 return -1;
1924
1925 wpa_printf(MSG_DEBUG,
1926 "nl80211: Subscribe to mgmt frames with mesh handle %p",
1927 bss->nl_mgmt);
1928
1929 /* Auth frames for mesh SAE */
1930 if (nl80211_register_frame(bss, bss->nl_mgmt,
1931 (WLAN_FC_TYPE_MGMT << 2) |
1932 (WLAN_FC_STYPE_AUTH << 4),
1933 NULL, 0) < 0)
1934 ret = -1;
1935
1936 /* Mesh peering open */
1937 if (nl80211_register_action_frame(bss, (u8 *) "\x0f\x01", 2) < 0)
1938 ret = -1;
1939 /* Mesh peering confirm */
1940 if (nl80211_register_action_frame(bss, (u8 *) "\x0f\x02", 2) < 0)
1941 ret = -1;
1942 /* Mesh peering close */
1943 if (nl80211_register_action_frame(bss, (u8 *) "\x0f\x03", 2) < 0)
1944 ret = -1;
1945
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -07001946 nl80211_mgmt_handle_register_eloop(bss);
1947
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001948 return ret;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001949}
1950
1951
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001952static int nl80211_register_spurious_class3(struct i802_bss *bss)
1953{
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001954 struct nl_msg *msg;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001955 int ret;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001956
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001957 msg = nl80211_bss_msg(bss, 0, NL80211_CMD_UNEXPECTED_FRAME);
1958 ret = send_and_recv(bss->drv->global, bss->nl_mgmt, msg, NULL, NULL);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001959 if (ret) {
1960 wpa_printf(MSG_DEBUG, "nl80211: Register spurious class3 "
1961 "failed: ret=%d (%s)",
1962 ret, strerror(-ret));
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001963 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001964 return ret;
1965}
1966
1967
1968static int nl80211_mgmt_subscribe_ap(struct i802_bss *bss)
1969{
1970 static const int stypes[] = {
1971 WLAN_FC_STYPE_AUTH,
1972 WLAN_FC_STYPE_ASSOC_REQ,
1973 WLAN_FC_STYPE_REASSOC_REQ,
1974 WLAN_FC_STYPE_DISASSOC,
1975 WLAN_FC_STYPE_DEAUTH,
1976 WLAN_FC_STYPE_ACTION,
1977 WLAN_FC_STYPE_PROBE_REQ,
1978/* Beacon doesn't work as mac80211 doesn't currently allow
1979 * it, but it wouldn't really be the right thing anyway as
1980 * it isn't per interface ... maybe just dump the scan
1981 * results periodically for OLBC?
1982 */
Dmitry Shmidt7832adb2014-04-29 10:53:02 -07001983 /* WLAN_FC_STYPE_BEACON, */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001984 };
1985 unsigned int i;
1986
1987 if (nl80211_alloc_mgmt_handle(bss))
1988 return -1;
1989 wpa_printf(MSG_DEBUG, "nl80211: Subscribe to mgmt frames with AP "
1990 "handle %p", bss->nl_mgmt);
1991
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -07001992 for (i = 0; i < ARRAY_SIZE(stypes); i++) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001993 if (nl80211_register_frame(bss, bss->nl_mgmt,
1994 (WLAN_FC_TYPE_MGMT << 2) |
1995 (stypes[i] << 4),
1996 NULL, 0) < 0) {
1997 goto out_err;
1998 }
1999 }
2000
2001 if (nl80211_register_spurious_class3(bss))
2002 goto out_err;
2003
2004 if (nl80211_get_wiphy_data_ap(bss) == NULL)
2005 goto out_err;
2006
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -07002007 nl80211_mgmt_handle_register_eloop(bss);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002008 return 0;
2009
2010out_err:
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002011 nl_destroy_handles(&bss->nl_mgmt);
2012 return -1;
2013}
2014
2015
2016static int nl80211_mgmt_subscribe_ap_dev_sme(struct i802_bss *bss)
2017{
2018 if (nl80211_alloc_mgmt_handle(bss))
2019 return -1;
2020 wpa_printf(MSG_DEBUG, "nl80211: Subscribe to mgmt frames with AP "
2021 "handle %p (device SME)", bss->nl_mgmt);
2022
2023 if (nl80211_register_frame(bss, bss->nl_mgmt,
2024 (WLAN_FC_TYPE_MGMT << 2) |
2025 (WLAN_FC_STYPE_ACTION << 4),
2026 NULL, 0) < 0)
2027 goto out_err;
2028
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -07002029 nl80211_mgmt_handle_register_eloop(bss);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002030 return 0;
2031
2032out_err:
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002033 nl_destroy_handles(&bss->nl_mgmt);
2034 return -1;
2035}
2036
2037
2038static void nl80211_mgmt_unsubscribe(struct i802_bss *bss, const char *reason)
2039{
2040 if (bss->nl_mgmt == NULL)
2041 return;
2042 wpa_printf(MSG_DEBUG, "nl80211: Unsubscribe mgmt frames handle %p "
2043 "(%s)", bss->nl_mgmt, reason);
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -07002044 nl80211_destroy_eloop_handle(&bss->nl_mgmt);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002045
2046 nl80211_put_wiphy_data_ap(bss);
2047}
2048
2049
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002050static void wpa_driver_nl80211_send_rfkill(void *eloop_ctx, void *timeout_ctx)
2051{
2052 wpa_supplicant_event(timeout_ctx, EVENT_INTERFACE_DISABLED, NULL);
2053}
2054
2055
Dmitry Shmidt34af3062013-07-11 10:46:32 -07002056static void nl80211_del_p2pdev(struct i802_bss *bss)
2057{
Dmitry Shmidt34af3062013-07-11 10:46:32 -07002058 struct nl_msg *msg;
2059 int ret;
2060
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002061 msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_DEL_INTERFACE);
2062 ret = send_and_recv_msgs(bss->drv, msg, NULL, NULL);
Dmitry Shmidt34af3062013-07-11 10:46:32 -07002063
2064 wpa_printf(MSG_DEBUG, "nl80211: Delete P2P Device %s (0x%llx): %s",
2065 bss->ifname, (long long unsigned int) bss->wdev_id,
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -07002066 strerror(-ret));
Dmitry Shmidt34af3062013-07-11 10:46:32 -07002067}
2068
2069
2070static int nl80211_set_p2pdev(struct i802_bss *bss, int start)
2071{
Dmitry Shmidt34af3062013-07-11 10:46:32 -07002072 struct nl_msg *msg;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002073 int ret;
Dmitry Shmidt34af3062013-07-11 10:46:32 -07002074
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002075 msg = nl80211_cmd_msg(bss, 0, start ? NL80211_CMD_START_P2P_DEVICE :
2076 NL80211_CMD_STOP_P2P_DEVICE);
2077 ret = send_and_recv_msgs(bss->drv, msg, NULL, NULL);
Dmitry Shmidt34af3062013-07-11 10:46:32 -07002078
2079 wpa_printf(MSG_DEBUG, "nl80211: %s P2P Device %s (0x%llx): %s",
2080 start ? "Start" : "Stop",
2081 bss->ifname, (long long unsigned int) bss->wdev_id,
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -07002082 strerror(-ret));
Dmitry Shmidt34af3062013-07-11 10:46:32 -07002083 return ret;
2084}
2085
2086
2087static int i802_set_iface_flags(struct i802_bss *bss, int up)
2088{
2089 enum nl80211_iftype nlmode;
2090
2091 nlmode = nl80211_get_ifmode(bss);
2092 if (nlmode != NL80211_IFTYPE_P2P_DEVICE) {
2093 return linux_set_iface_flags(bss->drv->global->ioctl_sock,
2094 bss->ifname, up);
2095 }
2096
2097 /* P2P Device has start/stop which is equivalent */
2098 return nl80211_set_p2pdev(bss, up);
2099}
2100
2101
Dmitry Shmidt7f656022015-02-25 14:36:37 -08002102#ifdef CONFIG_TESTING_OPTIONS
2103static int qca_vendor_test_cmd_handler(struct nl_msg *msg, void *arg)
2104{
2105 /* struct wpa_driver_nl80211_data *drv = arg; */
2106 struct nlattr *tb[NL80211_ATTR_MAX + 1];
2107 struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg));
2108
2109
2110 wpa_printf(MSG_DEBUG,
2111 "nl80211: QCA vendor test command response received");
2112
2113 nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0),
2114 genlmsg_attrlen(gnlh, 0), NULL);
2115 if (!tb[NL80211_ATTR_VENDOR_DATA]) {
2116 wpa_printf(MSG_DEBUG, "nl80211: No vendor data attribute");
2117 return NL_SKIP;
2118 }
2119
2120 wpa_hexdump(MSG_DEBUG,
2121 "nl80211: Received QCA vendor test command response",
2122 nla_data(tb[NL80211_ATTR_VENDOR_DATA]),
2123 nla_len(tb[NL80211_ATTR_VENDOR_DATA]));
2124
2125 return NL_SKIP;
2126}
2127#endif /* CONFIG_TESTING_OPTIONS */
2128
2129
2130static void qca_vendor_test(struct wpa_driver_nl80211_data *drv)
2131{
2132#ifdef CONFIG_TESTING_OPTIONS
2133 struct nl_msg *msg;
2134 struct nlattr *params;
2135 int ret;
2136
2137 if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_VENDOR)) ||
2138 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
2139 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
2140 QCA_NL80211_VENDOR_SUBCMD_TEST) ||
2141 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
2142 nla_put_u32(msg, QCA_WLAN_VENDOR_ATTR_TEST, 123)) {
2143 nlmsg_free(msg);
2144 return;
2145 }
2146 nla_nest_end(msg, params);
2147
2148 ret = send_and_recv_msgs(drv, msg, qca_vendor_test_cmd_handler, drv);
2149 wpa_printf(MSG_DEBUG,
2150 "nl80211: QCA vendor test command returned %d (%s)",
2151 ret, strerror(-ret));
2152#endif /* CONFIG_TESTING_OPTIONS */
2153}
2154
2155
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002156static int
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08002157wpa_driver_nl80211_finish_drv_init(struct wpa_driver_nl80211_data *drv,
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002158 const u8 *set_addr, int first,
2159 const char *driver_params)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002160{
Dmitry Shmidtcce06662013-11-04 18:44:24 -08002161 struct i802_bss *bss = drv->first_bss;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002162 int send_rfkill_event = 0;
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08002163 enum nl80211_iftype nlmode;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002164
2165 drv->ifindex = if_nametoindex(bss->ifname);
Dmitry Shmidt34af3062013-07-11 10:46:32 -07002166 bss->ifindex = drv->ifindex;
2167 bss->wdev_id = drv->global->if_add_wdevid;
2168 bss->wdev_id_set = drv->global->if_add_wdevid_set;
2169
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -07002170 bss->if_dynamic = drv->ifindex == drv->global->if_add_ifindex;
2171 bss->if_dynamic = bss->if_dynamic || drv->global->if_add_wdevid_set;
Dmitry Shmidt34af3062013-07-11 10:46:32 -07002172 drv->global->if_add_wdevid_set = 0;
2173
Dmitry Shmidt03658832014-08-13 11:03:49 -07002174 if (!bss->if_dynamic && nl80211_get_ifmode(bss) == NL80211_IFTYPE_AP)
2175 bss->static_ap = 1;
2176
Dmitry Shmidt34af3062013-07-11 10:46:32 -07002177 if (wpa_driver_nl80211_capa(drv))
2178 return -1;
2179
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002180 if (driver_params && nl80211_set_param(bss, driver_params) < 0)
2181 return -1;
2182
Dmitry Shmidt34af3062013-07-11 10:46:32 -07002183 wpa_printf(MSG_DEBUG, "nl80211: interface %s in phy %s",
2184 bss->ifname, drv->phyname);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002185
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08002186 if (set_addr &&
2187 (linux_set_iface_flags(drv->global->ioctl_sock, bss->ifname, 0) ||
2188 linux_set_ifhwaddr(drv->global->ioctl_sock, bss->ifname,
2189 set_addr)))
2190 return -1;
Dmitry Shmidt34af3062013-07-11 10:46:32 -07002191
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08002192 if (first && nl80211_get_ifmode(bss) == NL80211_IFTYPE_AP)
2193 drv->start_mode_ap = 1;
2194
Dmitry Shmidt03658832014-08-13 11:03:49 -07002195 if (drv->hostapd || bss->static_ap)
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08002196 nlmode = NL80211_IFTYPE_AP;
2197 else if (bss->if_dynamic)
2198 nlmode = nl80211_get_ifmode(bss);
2199 else
2200 nlmode = NL80211_IFTYPE_STATION;
2201
Dmitry Shmidt34af3062013-07-11 10:46:32 -07002202 if (wpa_driver_nl80211_set_mode(bss, nlmode) < 0) {
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08002203 wpa_printf(MSG_ERROR, "nl80211: Could not configure driver mode");
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002204 return -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002205 }
Dmitry Shmidt34af3062013-07-11 10:46:32 -07002206
Dmitry Shmidt98660862014-03-11 17:26:21 -07002207 if (nlmode == NL80211_IFTYPE_P2P_DEVICE)
Dmitry Shmidt34af3062013-07-11 10:46:32 -07002208 nl80211_get_macaddr(bss);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002209
Dmitry Shmidt98660862014-03-11 17:26:21 -07002210 if (!rfkill_is_blocked(drv->rfkill)) {
2211 int ret = i802_set_iface_flags(bss, 1);
2212 if (ret) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002213 wpa_printf(MSG_ERROR, "nl80211: Could not set "
2214 "interface '%s' UP", bss->ifname);
Dmitry Shmidt98660862014-03-11 17:26:21 -07002215 return ret;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002216 }
Dmitry Shmidt98660862014-03-11 17:26:21 -07002217 if (nlmode == NL80211_IFTYPE_P2P_DEVICE)
2218 return ret;
2219 } else {
2220 wpa_printf(MSG_DEBUG, "nl80211: Could not yet enable "
2221 "interface '%s' due to rfkill", bss->ifname);
2222 if (nlmode == NL80211_IFTYPE_P2P_DEVICE)
2223 return 0;
2224 drv->if_disabled = 1;
2225 send_rfkill_event = 1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002226 }
2227
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08002228 if (!drv->hostapd)
2229 netlink_send_oper_ifla(drv->global->netlink, drv->ifindex,
2230 1, IF_OPER_DORMANT);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002231
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002232 if (linux_get_ifhwaddr(drv->global->ioctl_sock, bss->ifname,
2233 bss->addr))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002234 return -1;
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07002235 os_memcpy(drv->perm_addr, bss->addr, ETH_ALEN);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002236
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002237 if (send_rfkill_event) {
2238 eloop_register_timeout(0, 0, wpa_driver_nl80211_send_rfkill,
2239 drv, drv->ctx);
2240 }
2241
Dmitry Shmidt7f656022015-02-25 14:36:37 -08002242 if (drv->vendor_cmd_test_avail)
2243 qca_vendor_test(drv);
2244
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002245 return 0;
2246}
2247
2248
2249static int wpa_driver_nl80211_del_beacon(struct wpa_driver_nl80211_data *drv)
2250{
2251 struct nl_msg *msg;
2252
Dmitry Shmidtcce06662013-11-04 18:44:24 -08002253 wpa_printf(MSG_DEBUG, "nl80211: Remove beacon (ifindex=%d)",
2254 drv->ifindex);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002255 msg = nl80211_drv_msg(drv, 0, NL80211_CMD_DEL_BEACON);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002256 return send_and_recv_msgs(drv, msg, NULL, NULL);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002257}
2258
2259
2260/**
2261 * wpa_driver_nl80211_deinit - Deinitialize nl80211 driver interface
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08002262 * @bss: Pointer to private nl80211 data from wpa_driver_nl80211_init()
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002263 *
2264 * Shut down driver interface and processing of driver events. Free
2265 * private data buffer if one was allocated in wpa_driver_nl80211_init().
2266 */
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08002267static void wpa_driver_nl80211_deinit(struct i802_bss *bss)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002268{
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002269 struct wpa_driver_nl80211_data *drv = bss->drv;
2270
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002271 wpa_printf(MSG_INFO, "nl80211: deinit ifname=%s disabled_11b_rates=%d",
2272 bss->ifname, drv->disabled_11b_rates);
2273
Dmitry Shmidt04949592012-07-19 12:16:46 -07002274 bss->in_deinit = 1;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002275 if (drv->data_tx_status)
2276 eloop_unregister_read_sock(drv->eapol_tx_sock);
2277 if (drv->eapol_tx_sock >= 0)
2278 close(drv->eapol_tx_sock);
2279
2280 if (bss->nl_preq)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002281 wpa_driver_nl80211_probe_req_report(bss, 0);
2282 if (bss->added_if_into_bridge) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002283 if (linux_br_del_if(drv->global->ioctl_sock, bss->brname,
2284 bss->ifname) < 0)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002285 wpa_printf(MSG_INFO, "nl80211: Failed to remove "
2286 "interface %s from bridge %s: %s",
2287 bss->ifname, bss->brname, strerror(errno));
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07002288 if (drv->rtnl_sk)
Dmitry Shmidt9ead16e2014-10-07 13:15:23 -07002289 nl80211_handle_destroy(drv->rtnl_sk);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002290 }
2291 if (bss->added_bridge) {
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002292 if (linux_set_iface_flags(drv->global->ioctl_sock, bss->brname,
2293 0) < 0)
2294 wpa_printf(MSG_INFO,
2295 "nl80211: Could not set bridge %s down",
2296 bss->brname);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002297 if (linux_br_del(drv->global->ioctl_sock, bss->brname) < 0)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002298 wpa_printf(MSG_INFO, "nl80211: Failed to remove "
2299 "bridge %s: %s",
2300 bss->brname, strerror(errno));
2301 }
2302
2303 nl80211_remove_monitor_interface(drv);
2304
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002305 if (is_ap_interface(drv->nlmode))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002306 wpa_driver_nl80211_del_beacon(drv);
2307
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002308 if (drv->eapol_sock >= 0) {
2309 eloop_unregister_read_sock(drv->eapol_sock);
2310 close(drv->eapol_sock);
2311 }
2312
2313 if (drv->if_indices != drv->default_if_indices)
2314 os_free(drv->if_indices);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002315
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002316 if (drv->disabled_11b_rates)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002317 nl80211_disable_11b_rates(drv, drv->ifindex, 0);
2318
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002319 netlink_send_oper_ifla(drv->global->netlink, drv->ifindex, 0,
2320 IF_OPER_UP);
Dmitry Shmidtb58836e2014-04-29 14:35:56 -07002321 eloop_cancel_timeout(wpa_driver_nl80211_send_rfkill, drv, drv->ctx);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002322 rfkill_deinit(drv->rfkill);
2323
2324 eloop_cancel_timeout(wpa_driver_nl80211_scan_timeout, drv, drv->ctx);
2325
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08002326 if (!drv->start_iface_up)
2327 (void) i802_set_iface_flags(bss, 0);
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07002328
2329 if (drv->addr_changed) {
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002330 if (linux_set_iface_flags(drv->global->ioctl_sock, bss->ifname,
2331 0) < 0) {
2332 wpa_printf(MSG_DEBUG,
2333 "nl80211: Could not set interface down to restore permanent MAC address");
2334 }
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07002335 if (linux_set_ifhwaddr(drv->global->ioctl_sock, bss->ifname,
2336 drv->perm_addr) < 0) {
2337 wpa_printf(MSG_DEBUG,
2338 "nl80211: Could not restore permanent MAC address");
2339 }
2340 }
2341
Dmitry Shmidt34af3062013-07-11 10:46:32 -07002342 if (drv->nlmode != NL80211_IFTYPE_P2P_DEVICE) {
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08002343 if (!drv->hostapd || !drv->start_mode_ap)
2344 wpa_driver_nl80211_set_mode(bss,
2345 NL80211_IFTYPE_STATION);
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -07002346 nl80211_mgmt_unsubscribe(bss, "deinit");
Dmitry Shmidt34af3062013-07-11 10:46:32 -07002347 } else {
2348 nl80211_mgmt_unsubscribe(bss, "deinit");
2349 nl80211_del_p2pdev(bss);
2350 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002351
Dmitry Shmidtcce06662013-11-04 18:44:24 -08002352 nl80211_destroy_bss(drv->first_bss);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002353
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002354 os_free(drv->filter_ssids);
2355
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002356 os_free(drv->auth_ie);
2357
2358 if (drv->in_interface_list)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002359 dl_list_del(&drv->list);
2360
Dmitry Shmidt444d5672013-04-01 13:08:44 -07002361 os_free(drv->extended_capa);
2362 os_free(drv->extended_capa_mask);
Dmitry Shmidtcce06662013-11-04 18:44:24 -08002363 os_free(drv->first_bss);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002364 os_free(drv);
2365}
2366
2367
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002368static u32 wpa_alg_to_cipher_suite(enum wpa_alg alg, size_t key_len)
2369{
2370 switch (alg) {
2371 case WPA_ALG_WEP:
2372 if (key_len == 5)
2373 return WLAN_CIPHER_SUITE_WEP40;
2374 return WLAN_CIPHER_SUITE_WEP104;
2375 case WPA_ALG_TKIP:
2376 return WLAN_CIPHER_SUITE_TKIP;
2377 case WPA_ALG_CCMP:
2378 return WLAN_CIPHER_SUITE_CCMP;
2379 case WPA_ALG_GCMP:
2380 return WLAN_CIPHER_SUITE_GCMP;
2381 case WPA_ALG_CCMP_256:
2382 return WLAN_CIPHER_SUITE_CCMP_256;
2383 case WPA_ALG_GCMP_256:
2384 return WLAN_CIPHER_SUITE_GCMP_256;
2385 case WPA_ALG_IGTK:
2386 return WLAN_CIPHER_SUITE_AES_CMAC;
2387 case WPA_ALG_BIP_GMAC_128:
2388 return WLAN_CIPHER_SUITE_BIP_GMAC_128;
2389 case WPA_ALG_BIP_GMAC_256:
2390 return WLAN_CIPHER_SUITE_BIP_GMAC_256;
2391 case WPA_ALG_BIP_CMAC_256:
2392 return WLAN_CIPHER_SUITE_BIP_CMAC_256;
2393 case WPA_ALG_SMS4:
2394 return WLAN_CIPHER_SUITE_SMS4;
2395 case WPA_ALG_KRK:
2396 return WLAN_CIPHER_SUITE_KRK;
2397 case WPA_ALG_NONE:
2398 case WPA_ALG_PMK:
2399 wpa_printf(MSG_ERROR, "nl80211: Unexpected encryption algorithm %d",
2400 alg);
2401 return 0;
2402 }
2403
2404 wpa_printf(MSG_ERROR, "nl80211: Unsupported encryption algorithm %d",
2405 alg);
2406 return 0;
2407}
2408
2409
2410static u32 wpa_cipher_to_cipher_suite(unsigned int cipher)
2411{
2412 switch (cipher) {
2413 case WPA_CIPHER_CCMP_256:
2414 return WLAN_CIPHER_SUITE_CCMP_256;
2415 case WPA_CIPHER_GCMP_256:
2416 return WLAN_CIPHER_SUITE_GCMP_256;
2417 case WPA_CIPHER_CCMP:
2418 return WLAN_CIPHER_SUITE_CCMP;
2419 case WPA_CIPHER_GCMP:
2420 return WLAN_CIPHER_SUITE_GCMP;
2421 case WPA_CIPHER_TKIP:
2422 return WLAN_CIPHER_SUITE_TKIP;
2423 case WPA_CIPHER_WEP104:
2424 return WLAN_CIPHER_SUITE_WEP104;
2425 case WPA_CIPHER_WEP40:
2426 return WLAN_CIPHER_SUITE_WEP40;
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08002427 case WPA_CIPHER_GTK_NOT_USED:
2428 return WLAN_CIPHER_SUITE_NO_GROUP_ADDR;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002429 }
2430
2431 return 0;
2432}
2433
2434
2435static int wpa_cipher_to_cipher_suites(unsigned int ciphers, u32 suites[],
2436 int max_suites)
2437{
2438 int num_suites = 0;
2439
2440 if (num_suites < max_suites && ciphers & WPA_CIPHER_CCMP_256)
2441 suites[num_suites++] = WLAN_CIPHER_SUITE_CCMP_256;
2442 if (num_suites < max_suites && ciphers & WPA_CIPHER_GCMP_256)
2443 suites[num_suites++] = WLAN_CIPHER_SUITE_GCMP_256;
2444 if (num_suites < max_suites && ciphers & WPA_CIPHER_CCMP)
2445 suites[num_suites++] = WLAN_CIPHER_SUITE_CCMP;
2446 if (num_suites < max_suites && ciphers & WPA_CIPHER_GCMP)
2447 suites[num_suites++] = WLAN_CIPHER_SUITE_GCMP;
2448 if (num_suites < max_suites && ciphers & WPA_CIPHER_TKIP)
2449 suites[num_suites++] = WLAN_CIPHER_SUITE_TKIP;
2450 if (num_suites < max_suites && ciphers & WPA_CIPHER_WEP104)
2451 suites[num_suites++] = WLAN_CIPHER_SUITE_WEP104;
2452 if (num_suites < max_suites && ciphers & WPA_CIPHER_WEP40)
2453 suites[num_suites++] = WLAN_CIPHER_SUITE_WEP40;
2454
2455 return num_suites;
2456}
2457
2458
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002459static int issue_key_mgmt_set_key(struct wpa_driver_nl80211_data *drv,
2460 const u8 *key, size_t key_len)
2461{
2462 struct nl_msg *msg;
2463 int ret;
2464
2465 if (!(drv->capa.flags & WPA_DRIVER_FLAGS_KEY_MGMT_OFFLOAD))
2466 return 0;
2467
2468 if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_VENDOR)) ||
2469 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
2470 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
2471 QCA_NL80211_VENDOR_SUBCMD_KEY_MGMT_SET_KEY) ||
2472 nla_put(msg, NL80211_ATTR_VENDOR_DATA, key_len, key)) {
2473 nl80211_nlmsg_clear(msg);
2474 nlmsg_free(msg);
2475 return -1;
2476 }
2477 ret = send_and_recv_msgs(drv, msg, NULL, (void *) -1);
2478 if (ret) {
2479 wpa_printf(MSG_DEBUG,
2480 "nl80211: Key management set key failed: ret=%d (%s)",
2481 ret, strerror(-ret));
2482 }
2483
2484 return ret;
2485}
2486
2487
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08002488static int wpa_driver_nl80211_set_key(const char *ifname, struct i802_bss *bss,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002489 enum wpa_alg alg, const u8 *addr,
2490 int key_idx, int set_tx,
2491 const u8 *seq, size_t seq_len,
2492 const u8 *key, size_t key_len)
2493{
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002494 struct wpa_driver_nl80211_data *drv = bss->drv;
Dmitry Shmidt34af3062013-07-11 10:46:32 -07002495 int ifindex;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002496 struct nl_msg *msg;
2497 int ret;
Dmitry Shmidtd5c075b2013-08-05 14:36:10 -07002498 int tdls = 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002499
Dmitry Shmidt34af3062013-07-11 10:46:32 -07002500 /* Ignore for P2P Device */
2501 if (drv->nlmode == NL80211_IFTYPE_P2P_DEVICE)
2502 return 0;
2503
2504 ifindex = if_nametoindex(ifname);
2505 wpa_printf(MSG_DEBUG, "%s: ifindex=%d (%s) alg=%d addr=%p key_idx=%d "
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002506 "set_tx=%d seq_len=%lu key_len=%lu",
Dmitry Shmidt34af3062013-07-11 10:46:32 -07002507 __func__, ifindex, ifname, alg, addr, key_idx, set_tx,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002508 (unsigned long) seq_len, (unsigned long) key_len);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002509#ifdef CONFIG_TDLS
Dmitry Shmidtd5c075b2013-08-05 14:36:10 -07002510 if (key_idx == -1) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002511 key_idx = 0;
Dmitry Shmidtd5c075b2013-08-05 14:36:10 -07002512 tdls = 1;
2513 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002514#endif /* CONFIG_TDLS */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002515
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002516 if (alg == WPA_ALG_PMK &&
2517 (drv->capa.flags & WPA_DRIVER_FLAGS_KEY_MGMT_OFFLOAD)) {
2518 wpa_printf(MSG_DEBUG, "%s: calling issue_key_mgmt_set_key",
2519 __func__);
2520 ret = issue_key_mgmt_set_key(drv, key, key_len);
2521 return ret;
2522 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002523
2524 if (alg == WPA_ALG_NONE) {
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002525 msg = nl80211_ifindex_msg(drv, ifindex, 0, NL80211_CMD_DEL_KEY);
2526 if (!msg)
2527 return -ENOBUFS;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002528 } else {
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002529 msg = nl80211_ifindex_msg(drv, ifindex, 0, NL80211_CMD_NEW_KEY);
2530 if (!msg ||
2531 nla_put(msg, NL80211_ATTR_KEY_DATA, key_len, key) ||
2532 nla_put_u32(msg, NL80211_ATTR_KEY_CIPHER,
2533 wpa_alg_to_cipher_suite(alg, key_len)))
2534 goto fail;
Dmitry Shmidt98660862014-03-11 17:26:21 -07002535 wpa_hexdump_key(MSG_DEBUG, "nl80211: KEY_DATA", key, key_len);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002536 }
2537
Dmitry Shmidt98660862014-03-11 17:26:21 -07002538 if (seq && seq_len) {
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002539 if (nla_put(msg, NL80211_ATTR_KEY_SEQ, seq_len, seq))
2540 goto fail;
Dmitry Shmidt98660862014-03-11 17:26:21 -07002541 wpa_hexdump(MSG_DEBUG, "nl80211: KEY_SEQ", seq, seq_len);
2542 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002543
2544 if (addr && !is_broadcast_ether_addr(addr)) {
2545 wpa_printf(MSG_DEBUG, " addr=" MACSTR, MAC2STR(addr));
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002546 if (nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr))
2547 goto fail;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002548
2549 if (alg != WPA_ALG_WEP && key_idx && !set_tx) {
2550 wpa_printf(MSG_DEBUG, " RSN IBSS RX GTK");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002551 if (nla_put_u32(msg, NL80211_ATTR_KEY_TYPE,
2552 NL80211_KEYTYPE_GROUP))
2553 goto fail;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002554 }
2555 } else if (addr && is_broadcast_ether_addr(addr)) {
Dmitry Shmidt8da800a2013-04-24 12:57:01 -07002556 struct nlattr *types;
2557
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002558 wpa_printf(MSG_DEBUG, " broadcast key");
Dmitry Shmidt8da800a2013-04-24 12:57:01 -07002559
2560 types = nla_nest_start(msg, NL80211_ATTR_KEY_DEFAULT_TYPES);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002561 if (!types ||
2562 nla_put_flag(msg, NL80211_KEY_DEFAULT_TYPE_MULTICAST))
2563 goto fail;
Dmitry Shmidt8da800a2013-04-24 12:57:01 -07002564 nla_nest_end(msg, types);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002565 }
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002566 if (nla_put_u8(msg, NL80211_ATTR_KEY_IDX, key_idx))
2567 goto fail;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002568
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002569 ret = send_and_recv_msgs(drv, msg, NULL, key ? (void *) -1 : NULL);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002570 if ((ret == -ENOENT || ret == -ENOLINK) && alg == WPA_ALG_NONE)
2571 ret = 0;
2572 if (ret)
2573 wpa_printf(MSG_DEBUG, "nl80211: set_key failed; err=%d %s)",
2574 ret, strerror(-ret));
2575
2576 /*
2577 * If we failed or don't need to set the default TX key (below),
2578 * we're done here.
2579 */
Dmitry Shmidtd5c075b2013-08-05 14:36:10 -07002580 if (ret || !set_tx || alg == WPA_ALG_NONE || tdls)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002581 return ret;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002582 if (is_ap_interface(drv->nlmode) && addr &&
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002583 !is_broadcast_ether_addr(addr))
2584 return ret;
2585
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002586 msg = nl80211_ifindex_msg(drv, ifindex, 0, NL80211_CMD_SET_KEY);
2587 if (!msg ||
2588 nla_put_u8(msg, NL80211_ATTR_KEY_IDX, key_idx) ||
Dmitry Shmidt807291d2015-01-27 13:40:23 -08002589 nla_put_flag(msg, (alg == WPA_ALG_IGTK ||
2590 alg == WPA_ALG_BIP_GMAC_128 ||
2591 alg == WPA_ALG_BIP_GMAC_256 ||
2592 alg == WPA_ALG_BIP_CMAC_256) ?
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002593 NL80211_ATTR_KEY_DEFAULT_MGMT :
2594 NL80211_ATTR_KEY_DEFAULT))
2595 goto fail;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002596 if (addr && is_broadcast_ether_addr(addr)) {
Dmitry Shmidt8da800a2013-04-24 12:57:01 -07002597 struct nlattr *types;
2598
2599 types = nla_nest_start(msg, NL80211_ATTR_KEY_DEFAULT_TYPES);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002600 if (!types ||
2601 nla_put_flag(msg, NL80211_KEY_DEFAULT_TYPE_MULTICAST))
2602 goto fail;
Dmitry Shmidt8da800a2013-04-24 12:57:01 -07002603 nla_nest_end(msg, types);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002604 } else if (addr) {
Dmitry Shmidt8da800a2013-04-24 12:57:01 -07002605 struct nlattr *types;
2606
2607 types = nla_nest_start(msg, NL80211_ATTR_KEY_DEFAULT_TYPES);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002608 if (!types ||
2609 nla_put_flag(msg, NL80211_KEY_DEFAULT_TYPE_UNICAST))
2610 goto fail;
Dmitry Shmidt8da800a2013-04-24 12:57:01 -07002611 nla_nest_end(msg, types);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002612 }
2613
2614 ret = send_and_recv_msgs(drv, msg, NULL, NULL);
2615 if (ret == -ENOENT)
2616 ret = 0;
2617 if (ret)
2618 wpa_printf(MSG_DEBUG, "nl80211: set_key default failed; "
2619 "err=%d %s)", ret, strerror(-ret));
2620 return ret;
2621
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002622fail:
2623 nl80211_nlmsg_clear(msg);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002624 nlmsg_free(msg);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002625 return -ENOBUFS;
2626}
2627
2628
2629static int nl_add_key(struct nl_msg *msg, enum wpa_alg alg,
2630 int key_idx, int defkey,
2631 const u8 *seq, size_t seq_len,
2632 const u8 *key, size_t key_len)
2633{
2634 struct nlattr *key_attr = nla_nest_start(msg, NL80211_ATTR_KEY);
2635 if (!key_attr)
2636 return -1;
2637
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002638 if (defkey && alg == WPA_ALG_IGTK) {
2639 if (nla_put_flag(msg, NL80211_KEY_DEFAULT_MGMT))
2640 return -1;
2641 } else if (defkey) {
2642 if (nla_put_flag(msg, NL80211_KEY_DEFAULT))
2643 return -1;
2644 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002645
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002646 if (nla_put_u8(msg, NL80211_KEY_IDX, key_idx) ||
2647 nla_put_u32(msg, NL80211_KEY_CIPHER,
2648 wpa_alg_to_cipher_suite(alg, key_len)) ||
2649 (seq && seq_len &&
2650 nla_put(msg, NL80211_KEY_SEQ, seq_len, seq)) ||
2651 nla_put(msg, NL80211_KEY_DATA, key_len, key))
2652 return -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002653
2654 nla_nest_end(msg, key_attr);
2655
2656 return 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002657}
2658
2659
2660static int nl80211_set_conn_keys(struct wpa_driver_associate_params *params,
2661 struct nl_msg *msg)
2662{
2663 int i, privacy = 0;
2664 struct nlattr *nl_keys, *nl_key;
2665
2666 for (i = 0; i < 4; i++) {
2667 if (!params->wep_key[i])
2668 continue;
2669 privacy = 1;
2670 break;
2671 }
2672 if (params->wps == WPS_MODE_PRIVACY)
2673 privacy = 1;
2674 if (params->pairwise_suite &&
2675 params->pairwise_suite != WPA_CIPHER_NONE)
2676 privacy = 1;
2677
2678 if (!privacy)
2679 return 0;
2680
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002681 if (nla_put_flag(msg, NL80211_ATTR_PRIVACY))
2682 return -ENOBUFS;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002683
2684 nl_keys = nla_nest_start(msg, NL80211_ATTR_KEYS);
2685 if (!nl_keys)
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002686 return -ENOBUFS;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002687
2688 for (i = 0; i < 4; i++) {
2689 if (!params->wep_key[i])
2690 continue;
2691
2692 nl_key = nla_nest_start(msg, i);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002693 if (!nl_key ||
2694 nla_put(msg, NL80211_KEY_DATA, params->wep_key_len[i],
2695 params->wep_key[i]) ||
2696 nla_put_u32(msg, NL80211_KEY_CIPHER,
2697 params->wep_key_len[i] == 5 ?
2698 WLAN_CIPHER_SUITE_WEP40 :
2699 WLAN_CIPHER_SUITE_WEP104) ||
2700 nla_put_u8(msg, NL80211_KEY_IDX, i) ||
2701 (i == params->wep_tx_keyidx &&
2702 nla_put_flag(msg, NL80211_KEY_DEFAULT)))
2703 return -ENOBUFS;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002704
2705 nla_nest_end(msg, nl_key);
2706 }
2707 nla_nest_end(msg, nl_keys);
2708
2709 return 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002710}
2711
2712
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002713int wpa_driver_nl80211_mlme(struct wpa_driver_nl80211_data *drv,
2714 const u8 *addr, int cmd, u16 reason_code,
2715 int local_state_change)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002716{
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002717 int ret;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002718 struct nl_msg *msg;
2719
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002720 if (!(msg = nl80211_drv_msg(drv, 0, cmd)) ||
2721 nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason_code) ||
2722 (addr && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) ||
2723 (local_state_change &&
2724 nla_put_flag(msg, NL80211_ATTR_LOCAL_STATE_CHANGE))) {
2725 nlmsg_free(msg);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002726 return -1;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002727 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002728
2729 ret = send_and_recv_msgs(drv, msg, NULL, NULL);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002730 if (ret) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002731 wpa_dbg(drv->ctx, MSG_DEBUG,
2732 "nl80211: MLME command failed: reason=%u ret=%d (%s)",
2733 reason_code, ret, strerror(-ret));
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002734 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002735 return ret;
2736}
2737
2738
2739static int wpa_driver_nl80211_disconnect(struct wpa_driver_nl80211_data *drv,
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08002740 int reason_code)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002741{
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07002742 int ret;
2743
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08002744 wpa_printf(MSG_DEBUG, "%s(reason_code=%d)", __func__, reason_code);
Dmitry Shmidt8bae4132013-06-06 11:25:10 -07002745 nl80211_mark_disconnected(drv);
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08002746 /* Disconnect command doesn't need BSSID - it uses cached value */
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07002747 ret = wpa_driver_nl80211_mlme(drv, NULL, NL80211_CMD_DISCONNECT,
2748 reason_code, 0);
2749 /*
2750 * For locally generated disconnect, supplicant already generates a
2751 * DEAUTH event, so ignore the event from NL80211.
2752 */
2753 drv->ignore_next_local_disconnect = ret == 0;
2754
2755 return ret;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002756}
2757
2758
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08002759static int wpa_driver_nl80211_deauthenticate(struct i802_bss *bss,
2760 const u8 *addr, int reason_code)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002761{
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002762 struct wpa_driver_nl80211_data *drv = bss->drv;
Dmitry Shmidt7dba0e52014-04-14 10:49:15 -07002763 int ret;
Dmitry Shmidt413dde72014-04-11 10:23:22 -07002764
2765 if (drv->nlmode == NL80211_IFTYPE_ADHOC) {
2766 nl80211_mark_disconnected(drv);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002767 return nl80211_leave_ibss(drv, 1);
Dmitry Shmidt413dde72014-04-11 10:23:22 -07002768 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002769 if (!(drv->capa.flags & WPA_DRIVER_FLAGS_SME))
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08002770 return wpa_driver_nl80211_disconnect(drv, reason_code);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002771 wpa_printf(MSG_DEBUG, "%s(addr=" MACSTR " reason_code=%d)",
2772 __func__, MAC2STR(addr), reason_code);
Dmitry Shmidt8bae4132013-06-06 11:25:10 -07002773 nl80211_mark_disconnected(drv);
Dmitry Shmidt7dba0e52014-04-14 10:49:15 -07002774 ret = wpa_driver_nl80211_mlme(drv, addr, NL80211_CMD_DEAUTHENTICATE,
2775 reason_code, 0);
2776 /*
2777 * For locally generated deauthenticate, supplicant already generates a
2778 * DEAUTH event, so ignore the event from NL80211.
2779 */
2780 drv->ignore_next_local_deauth = ret == 0;
2781 return ret;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002782}
2783
2784
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002785static void nl80211_copy_auth_params(struct wpa_driver_nl80211_data *drv,
2786 struct wpa_driver_auth_params *params)
2787{
2788 int i;
2789
2790 drv->auth_freq = params->freq;
2791 drv->auth_alg = params->auth_alg;
2792 drv->auth_wep_tx_keyidx = params->wep_tx_keyidx;
2793 drv->auth_local_state_change = params->local_state_change;
2794 drv->auth_p2p = params->p2p;
2795
2796 if (params->bssid)
2797 os_memcpy(drv->auth_bssid_, params->bssid, ETH_ALEN);
2798 else
2799 os_memset(drv->auth_bssid_, 0, ETH_ALEN);
2800
2801 if (params->ssid) {
2802 os_memcpy(drv->auth_ssid, params->ssid, params->ssid_len);
2803 drv->auth_ssid_len = params->ssid_len;
2804 } else
2805 drv->auth_ssid_len = 0;
2806
2807
2808 os_free(drv->auth_ie);
2809 drv->auth_ie = NULL;
2810 drv->auth_ie_len = 0;
2811 if (params->ie) {
2812 drv->auth_ie = os_malloc(params->ie_len);
2813 if (drv->auth_ie) {
2814 os_memcpy(drv->auth_ie, params->ie, params->ie_len);
2815 drv->auth_ie_len = params->ie_len;
2816 }
2817 }
2818
2819 for (i = 0; i < 4; i++) {
2820 if (params->wep_key[i] && params->wep_key_len[i] &&
2821 params->wep_key_len[i] <= 16) {
2822 os_memcpy(drv->auth_wep_key[i], params->wep_key[i],
2823 params->wep_key_len[i]);
2824 drv->auth_wep_key_len[i] = params->wep_key_len[i];
2825 } else
2826 drv->auth_wep_key_len[i] = 0;
2827 }
2828}
2829
2830
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002831static void nl80211_unmask_11b_rates(struct i802_bss *bss)
2832{
2833 struct wpa_driver_nl80211_data *drv = bss->drv;
2834
2835 if (is_p2p_net_interface(drv->nlmode) || !drv->disabled_11b_rates)
2836 return;
2837
2838 /*
2839 * Looks like we failed to unmask 11b rates previously. This could
2840 * happen, e.g., if the interface was down at the point in time when a
2841 * P2P group was terminated.
2842 */
2843 wpa_printf(MSG_DEBUG,
2844 "nl80211: Interface %s mode is for non-P2P, but 11b rates were disabled - re-enable them",
2845 bss->ifname);
2846 nl80211_disable_11b_rates(drv, drv->ifindex, 0);
2847}
2848
2849
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002850static int wpa_driver_nl80211_authenticate(
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08002851 struct i802_bss *bss, struct wpa_driver_auth_params *params)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002852{
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002853 struct wpa_driver_nl80211_data *drv = bss->drv;
2854 int ret = -1, i;
2855 struct nl_msg *msg;
2856 enum nl80211_auth_type type;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002857 enum nl80211_iftype nlmode;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002858 int count = 0;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002859 int is_retry;
2860
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002861 nl80211_unmask_11b_rates(bss);
2862
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002863 is_retry = drv->retry_auth;
2864 drv->retry_auth = 0;
Dmitry Shmidt98660862014-03-11 17:26:21 -07002865 drv->ignore_deauth_event = 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002866
Dmitry Shmidt8bae4132013-06-06 11:25:10 -07002867 nl80211_mark_disconnected(drv);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002868 os_memset(drv->auth_bssid, 0, ETH_ALEN);
Dmitry Shmidt8bae4132013-06-06 11:25:10 -07002869 if (params->bssid)
2870 os_memcpy(drv->auth_attempt_bssid, params->bssid, ETH_ALEN);
2871 else
2872 os_memset(drv->auth_attempt_bssid, 0, ETH_ALEN);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002873 /* FIX: IBSS mode */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002874 nlmode = params->p2p ?
2875 NL80211_IFTYPE_P2P_CLIENT : NL80211_IFTYPE_STATION;
2876 if (drv->nlmode != nlmode &&
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08002877 wpa_driver_nl80211_set_mode(bss, nlmode) < 0)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002878 return -1;
2879
2880retry:
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002881 wpa_printf(MSG_DEBUG, "nl80211: Authenticate (ifindex=%d)",
2882 drv->ifindex);
2883
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002884 msg = nl80211_drv_msg(drv, 0, NL80211_CMD_AUTHENTICATE);
2885 if (!msg)
2886 goto fail;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002887
2888 for (i = 0; i < 4; i++) {
2889 if (!params->wep_key[i])
2890 continue;
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08002891 wpa_driver_nl80211_set_key(bss->ifname, bss, WPA_ALG_WEP,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002892 NULL, i,
2893 i == params->wep_tx_keyidx, NULL, 0,
2894 params->wep_key[i],
2895 params->wep_key_len[i]);
2896 if (params->wep_tx_keyidx != i)
2897 continue;
2898 if (nl_add_key(msg, WPA_ALG_WEP, i, 1, NULL, 0,
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002899 params->wep_key[i], params->wep_key_len[i]))
2900 goto fail;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002901 }
2902
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002903 if (params->bssid) {
2904 wpa_printf(MSG_DEBUG, " * bssid=" MACSTR,
2905 MAC2STR(params->bssid));
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002906 if (nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, params->bssid))
2907 goto fail;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002908 }
2909 if (params->freq) {
2910 wpa_printf(MSG_DEBUG, " * freq=%d", params->freq);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002911 if (nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, params->freq))
2912 goto fail;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002913 }
2914 if (params->ssid) {
2915 wpa_hexdump_ascii(MSG_DEBUG, " * SSID",
2916 params->ssid, params->ssid_len);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002917 if (nla_put(msg, NL80211_ATTR_SSID, params->ssid_len,
2918 params->ssid))
2919 goto fail;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002920 }
2921 wpa_hexdump(MSG_DEBUG, " * IEs", params->ie, params->ie_len);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002922 if (params->ie &&
2923 nla_put(msg, NL80211_ATTR_IE, params->ie_len, params->ie))
2924 goto fail;
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08002925 if (params->sae_data) {
2926 wpa_hexdump(MSG_DEBUG, " * SAE data", params->sae_data,
2927 params->sae_data_len);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002928 if (nla_put(msg, NL80211_ATTR_SAE_DATA, params->sae_data_len,
2929 params->sae_data))
2930 goto fail;
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08002931 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002932 if (params->auth_alg & WPA_AUTH_ALG_OPEN)
2933 type = NL80211_AUTHTYPE_OPEN_SYSTEM;
2934 else if (params->auth_alg & WPA_AUTH_ALG_SHARED)
2935 type = NL80211_AUTHTYPE_SHARED_KEY;
2936 else if (params->auth_alg & WPA_AUTH_ALG_LEAP)
2937 type = NL80211_AUTHTYPE_NETWORK_EAP;
2938 else if (params->auth_alg & WPA_AUTH_ALG_FT)
2939 type = NL80211_AUTHTYPE_FT;
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08002940 else if (params->auth_alg & WPA_AUTH_ALG_SAE)
2941 type = NL80211_AUTHTYPE_SAE;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002942 else
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002943 goto fail;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002944 wpa_printf(MSG_DEBUG, " * Auth Type %d", type);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002945 if (nla_put_u32(msg, NL80211_ATTR_AUTH_TYPE, type))
2946 goto fail;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002947 if (params->local_state_change) {
2948 wpa_printf(MSG_DEBUG, " * Local state change only");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002949 if (nla_put_flag(msg, NL80211_ATTR_LOCAL_STATE_CHANGE))
2950 goto fail;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002951 }
2952
2953 ret = send_and_recv_msgs(drv, msg, NULL, NULL);
2954 msg = NULL;
2955 if (ret) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002956 wpa_dbg(drv->ctx, MSG_DEBUG,
2957 "nl80211: MLME command failed (auth): ret=%d (%s)",
2958 ret, strerror(-ret));
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002959 count++;
2960 if (ret == -EALREADY && count == 1 && params->bssid &&
2961 !params->local_state_change) {
2962 /*
2963 * mac80211 does not currently accept new
2964 * authentication if we are already authenticated. As a
2965 * workaround, force deauthentication and try again.
2966 */
2967 wpa_printf(MSG_DEBUG, "nl80211: Retry authentication "
2968 "after forced deauthentication");
Dmitry Shmidt98660862014-03-11 17:26:21 -07002969 drv->ignore_deauth_event = 1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002970 wpa_driver_nl80211_deauthenticate(
2971 bss, params->bssid,
2972 WLAN_REASON_PREV_AUTH_NOT_VALID);
2973 nlmsg_free(msg);
2974 goto retry;
2975 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002976
2977 if (ret == -ENOENT && params->freq && !is_retry) {
2978 /*
2979 * cfg80211 has likely expired the BSS entry even
2980 * though it was previously available in our internal
2981 * BSS table. To recover quickly, start a single
2982 * channel scan on the specified channel.
2983 */
2984 struct wpa_driver_scan_params scan;
2985 int freqs[2];
2986
2987 os_memset(&scan, 0, sizeof(scan));
2988 scan.num_ssids = 1;
2989 if (params->ssid) {
2990 scan.ssids[0].ssid = params->ssid;
2991 scan.ssids[0].ssid_len = params->ssid_len;
2992 }
2993 freqs[0] = params->freq;
2994 freqs[1] = 0;
2995 scan.freqs = freqs;
2996 wpa_printf(MSG_DEBUG, "nl80211: Trigger single "
2997 "channel scan to refresh cfg80211 BSS "
2998 "entry");
2999 ret = wpa_driver_nl80211_scan(bss, &scan);
3000 if (ret == 0) {
3001 nl80211_copy_auth_params(drv, params);
3002 drv->scan_for_auth = 1;
3003 }
3004 } else if (is_retry) {
3005 /*
3006 * Need to indicate this with an event since the return
3007 * value from the retry is not delivered to core code.
3008 */
3009 union wpa_event_data event;
3010 wpa_printf(MSG_DEBUG, "nl80211: Authentication retry "
3011 "failed");
3012 os_memset(&event, 0, sizeof(event));
3013 os_memcpy(event.timeout_event.addr, drv->auth_bssid_,
3014 ETH_ALEN);
3015 wpa_supplicant_event(drv->ctx, EVENT_AUTH_TIMED_OUT,
3016 &event);
3017 }
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003018 } else {
3019 wpa_printf(MSG_DEBUG,
3020 "nl80211: Authentication request send successfully");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003021 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003022
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003023fail:
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003024 nlmsg_free(msg);
3025 return ret;
3026}
3027
3028
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003029int wpa_driver_nl80211_authenticate_retry(struct wpa_driver_nl80211_data *drv)
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003030{
3031 struct wpa_driver_auth_params params;
Dmitry Shmidtcce06662013-11-04 18:44:24 -08003032 struct i802_bss *bss = drv->first_bss;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003033 int i;
3034
3035 wpa_printf(MSG_DEBUG, "nl80211: Try to authenticate again");
3036
3037 os_memset(&params, 0, sizeof(params));
3038 params.freq = drv->auth_freq;
3039 params.auth_alg = drv->auth_alg;
3040 params.wep_tx_keyidx = drv->auth_wep_tx_keyidx;
3041 params.local_state_change = drv->auth_local_state_change;
3042 params.p2p = drv->auth_p2p;
3043
3044 if (!is_zero_ether_addr(drv->auth_bssid_))
3045 params.bssid = drv->auth_bssid_;
3046
3047 if (drv->auth_ssid_len) {
3048 params.ssid = drv->auth_ssid;
3049 params.ssid_len = drv->auth_ssid_len;
3050 }
3051
3052 params.ie = drv->auth_ie;
3053 params.ie_len = drv->auth_ie_len;
3054
3055 for (i = 0; i < 4; i++) {
3056 if (drv->auth_wep_key_len[i]) {
3057 params.wep_key[i] = drv->auth_wep_key[i];
3058 params.wep_key_len[i] = drv->auth_wep_key_len[i];
3059 }
3060 }
3061
3062 drv->retry_auth = 1;
3063 return wpa_driver_nl80211_authenticate(bss, &params);
3064}
3065
3066
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003067static int wpa_driver_nl80211_send_frame(struct i802_bss *bss,
3068 const void *data, size_t len,
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08003069 int encrypt, int noack,
3070 unsigned int freq, int no_cck,
3071 int offchanok, unsigned int wait_time)
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003072{
3073 struct wpa_driver_nl80211_data *drv = bss->drv;
3074 u64 cookie;
Dmitry Shmidt051af732013-10-22 13:52:46 -07003075 int res;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003076
Dmitry Shmidt6dc03bd2014-05-16 10:40:13 -07003077 if (freq == 0 && drv->nlmode == NL80211_IFTYPE_ADHOC) {
3078 freq = nl80211_get_assoc_freq(drv);
3079 wpa_printf(MSG_DEBUG,
3080 "nl80211: send_frame - Use assoc_freq=%u for IBSS",
3081 freq);
3082 }
Dmitry Shmidt56052862013-10-04 10:23:25 -07003083 if (freq == 0) {
3084 wpa_printf(MSG_DEBUG, "nl80211: send_frame - Use bss->freq=%u",
3085 bss->freq);
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08003086 freq = bss->freq;
Dmitry Shmidt56052862013-10-04 10:23:25 -07003087 }
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08003088
Dmitry Shmidt56052862013-10-04 10:23:25 -07003089 if (drv->use_monitor) {
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003090 wpa_printf(MSG_DEBUG, "nl80211: send_frame(freq=%u bss->freq=%u) -> send_monitor",
Dmitry Shmidt56052862013-10-04 10:23:25 -07003091 freq, bss->freq);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003092 return nl80211_send_monitor(drv, data, len, encrypt, noack);
Dmitry Shmidt56052862013-10-04 10:23:25 -07003093 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003094
Dmitry Shmidt56052862013-10-04 10:23:25 -07003095 wpa_printf(MSG_DEBUG, "nl80211: send_frame -> send_frame_cmd");
Dmitry Shmidt051af732013-10-22 13:52:46 -07003096 res = nl80211_send_frame_cmd(bss, freq, wait_time, data, len,
3097 &cookie, no_cck, noack, offchanok);
3098 if (res == 0 && !noack) {
3099 const struct ieee80211_mgmt *mgmt;
3100 u16 fc;
3101
3102 mgmt = (const struct ieee80211_mgmt *) data;
3103 fc = le_to_host16(mgmt->frame_control);
3104 if (WLAN_FC_GET_TYPE(fc) == WLAN_FC_TYPE_MGMT &&
3105 WLAN_FC_GET_STYPE(fc) == WLAN_FC_STYPE_ACTION) {
3106 wpa_printf(MSG_MSGDUMP,
3107 "nl80211: Update send_action_cookie from 0x%llx to 0x%llx",
3108 (long long unsigned int)
3109 drv->send_action_cookie,
3110 (long long unsigned int) cookie);
3111 drv->send_action_cookie = cookie;
3112 }
3113 }
3114
3115 return res;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003116}
3117
3118
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08003119static int wpa_driver_nl80211_send_mlme(struct i802_bss *bss, const u8 *data,
3120 size_t data_len, int noack,
3121 unsigned int freq, int no_cck,
3122 int offchanok,
3123 unsigned int wait_time)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003124{
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003125 struct wpa_driver_nl80211_data *drv = bss->drv;
3126 struct ieee80211_mgmt *mgmt;
3127 int encrypt = 1;
3128 u16 fc;
3129
3130 mgmt = (struct ieee80211_mgmt *) data;
3131 fc = le_to_host16(mgmt->frame_control);
Dmitry Shmidt2271d3f2014-06-23 12:16:31 -07003132 wpa_printf(MSG_DEBUG, "nl80211: send_mlme - da= " MACSTR
3133 " noack=%d freq=%u no_cck=%d offchanok=%d wait_time=%u fc=0x%x (%s) nlmode=%d",
3134 MAC2STR(mgmt->da), noack, freq, no_cck, offchanok, wait_time,
3135 fc, fc2str(fc), drv->nlmode);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003136
Dmitry Shmidt34af3062013-07-11 10:46:32 -07003137 if ((is_sta_interface(drv->nlmode) ||
3138 drv->nlmode == NL80211_IFTYPE_P2P_DEVICE) &&
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003139 WLAN_FC_GET_TYPE(fc) == WLAN_FC_TYPE_MGMT &&
3140 WLAN_FC_GET_STYPE(fc) == WLAN_FC_STYPE_PROBE_RESP) {
3141 /*
3142 * The use of last_mgmt_freq is a bit of a hack,
3143 * but it works due to the single-threaded nature
3144 * of wpa_supplicant.
3145 */
Dmitry Shmidt56052862013-10-04 10:23:25 -07003146 if (freq == 0) {
3147 wpa_printf(MSG_DEBUG, "nl80211: Use last_mgmt_freq=%d",
3148 drv->last_mgmt_freq);
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08003149 freq = drv->last_mgmt_freq;
Dmitry Shmidt56052862013-10-04 10:23:25 -07003150 }
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08003151 return nl80211_send_frame_cmd(bss, freq, 0,
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003152 data, data_len, NULL, 1, noack,
3153 1);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003154 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003155
3156 if (drv->device_ap_sme && is_ap_interface(drv->nlmode)) {
Dmitry Shmidt56052862013-10-04 10:23:25 -07003157 if (freq == 0) {
3158 wpa_printf(MSG_DEBUG, "nl80211: Use bss->freq=%d",
3159 bss->freq);
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08003160 freq = bss->freq;
Dmitry Shmidt56052862013-10-04 10:23:25 -07003161 }
Dmitry Shmidt04949592012-07-19 12:16:46 -07003162 return nl80211_send_frame_cmd(bss, freq,
3163 (int) freq == bss->freq ? 0 :
3164 wait_time,
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08003165 data, data_len,
3166 &drv->send_action_cookie,
3167 no_cck, noack, offchanok);
Dmitry Shmidt6e933c12011-09-27 12:29:26 -07003168 }
Dmitry Shmidtb638fe72012-03-20 12:51:25 -07003169
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003170 if (WLAN_FC_GET_TYPE(fc) == WLAN_FC_TYPE_MGMT &&
3171 WLAN_FC_GET_STYPE(fc) == WLAN_FC_STYPE_AUTH) {
3172 /*
3173 * Only one of the authentication frame types is encrypted.
3174 * In order for static WEP encryption to work properly (i.e.,
3175 * to not encrypt the frame), we need to tell mac80211 about
3176 * the frames that must not be encrypted.
3177 */
3178 u16 auth_alg = le_to_host16(mgmt->u.auth.auth_alg);
3179 u16 auth_trans = le_to_host16(mgmt->u.auth.auth_transaction);
3180 if (auth_alg != WLAN_AUTH_SHARED_KEY || auth_trans != 3)
3181 encrypt = 0;
3182 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003183
Dmitry Shmidt56052862013-10-04 10:23:25 -07003184 wpa_printf(MSG_DEBUG, "nl80211: send_mlme -> send_frame");
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003185 return wpa_driver_nl80211_send_frame(bss, data, data_len, encrypt,
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08003186 noack, freq, no_cck, offchanok,
3187 wait_time);
3188}
3189
3190
Dmitry Shmidtff787d52015-01-12 13:01:47 -08003191static int nl80211_put_basic_rates(struct nl_msg *msg, const int *basic_rates)
3192{
3193 u8 rates[NL80211_MAX_SUPP_RATES];
3194 u8 rates_len = 0;
3195 int i;
3196
3197 if (!basic_rates)
3198 return 0;
3199
3200 for (i = 0; i < NL80211_MAX_SUPP_RATES && basic_rates[i] >= 0; i++)
3201 rates[rates_len++] = basic_rates[i] / 5;
3202
3203 return nla_put(msg, NL80211_ATTR_BSS_BASIC_RATES, rates_len, rates);
3204}
3205
3206
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003207static int nl80211_set_bss(struct i802_bss *bss, int cts, int preamble,
3208 int slot, int ht_opmode, int ap_isolate,
Dmitry Shmidtff787d52015-01-12 13:01:47 -08003209 const int *basic_rates)
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003210{
3211 struct wpa_driver_nl80211_data *drv = bss->drv;
3212 struct nl_msg *msg;
3213
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003214 if (!(msg = nl80211_bss_msg(bss, 0, NL80211_CMD_SET_BSS)) ||
3215 (cts >= 0 &&
3216 nla_put_u8(msg, NL80211_ATTR_BSS_CTS_PROT, cts)) ||
3217 (preamble >= 0 &&
3218 nla_put_u8(msg, NL80211_ATTR_BSS_SHORT_PREAMBLE, preamble)) ||
3219 (slot >= 0 &&
3220 nla_put_u8(msg, NL80211_ATTR_BSS_SHORT_SLOT_TIME, slot)) ||
3221 (ht_opmode >= 0 &&
3222 nla_put_u16(msg, NL80211_ATTR_BSS_HT_OPMODE, ht_opmode)) ||
3223 (ap_isolate >= 0 &&
Dmitry Shmidtff787d52015-01-12 13:01:47 -08003224 nla_put_u8(msg, NL80211_ATTR_AP_ISOLATE, ap_isolate)) ||
3225 nl80211_put_basic_rates(msg, basic_rates)) {
3226 nlmsg_free(msg);
3227 return -ENOBUFS;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003228 }
3229
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003230 return send_and_recv_msgs(drv, msg, NULL, NULL);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003231}
3232
3233
Dmitry Shmidt8bae4132013-06-06 11:25:10 -07003234static int wpa_driver_nl80211_set_acl(void *priv,
3235 struct hostapd_acl_params *params)
3236{
3237 struct i802_bss *bss = priv;
3238 struct wpa_driver_nl80211_data *drv = bss->drv;
3239 struct nl_msg *msg;
3240 struct nlattr *acl;
3241 unsigned int i;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003242 int ret;
Dmitry Shmidt8bae4132013-06-06 11:25:10 -07003243
3244 if (!(drv->capa.max_acl_mac_addrs))
3245 return -ENOTSUP;
3246
3247 if (params->num_mac_acl > drv->capa.max_acl_mac_addrs)
3248 return -ENOTSUP;
3249
Dmitry Shmidt8bae4132013-06-06 11:25:10 -07003250 wpa_printf(MSG_DEBUG, "nl80211: Set %s ACL (num_mac_acl=%u)",
3251 params->acl_policy ? "Accept" : "Deny", params->num_mac_acl);
3252
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003253 if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_SET_MAC_ACL)) ||
3254 nla_put_u32(msg, NL80211_ATTR_ACL_POLICY, params->acl_policy ?
3255 NL80211_ACL_POLICY_DENY_UNLESS_LISTED :
3256 NL80211_ACL_POLICY_ACCEPT_UNLESS_LISTED) ||
3257 (acl = nla_nest_start(msg, NL80211_ATTR_MAC_ADDRS)) == NULL) {
3258 nlmsg_free(msg);
3259 return -ENOMEM;
3260 }
Dmitry Shmidt8bae4132013-06-06 11:25:10 -07003261
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003262 for (i = 0; i < params->num_mac_acl; i++) {
3263 if (nla_put(msg, i + 1, ETH_ALEN, params->mac_acl[i].addr)) {
3264 nlmsg_free(msg);
3265 return -ENOMEM;
3266 }
3267 }
Dmitry Shmidt8bae4132013-06-06 11:25:10 -07003268
3269 nla_nest_end(msg, acl);
3270
3271 ret = send_and_recv_msgs(drv, msg, NULL, NULL);
Dmitry Shmidt8bae4132013-06-06 11:25:10 -07003272 if (ret) {
3273 wpa_printf(MSG_DEBUG, "nl80211: Failed to set MAC ACL: %d (%s)",
3274 ret, strerror(-ret));
3275 }
3276
Dmitry Shmidt8bae4132013-06-06 11:25:10 -07003277 return ret;
3278}
3279
3280
Dmitry Shmidtff787d52015-01-12 13:01:47 -08003281static int nl80211_put_beacon_int(struct nl_msg *msg, int beacon_int)
3282{
3283 if (beacon_int > 0) {
3284 wpa_printf(MSG_DEBUG, " * beacon_int=%d", beacon_int);
3285 return nla_put_u32(msg, NL80211_ATTR_BEACON_INTERVAL,
3286 beacon_int);
3287 }
3288
3289 return 0;
3290}
3291
3292
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003293static int wpa_driver_nl80211_set_ap(void *priv,
3294 struct wpa_driver_ap_params *params)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003295{
3296 struct i802_bss *bss = priv;
3297 struct wpa_driver_nl80211_data *drv = bss->drv;
3298 struct nl_msg *msg;
3299 u8 cmd = NL80211_CMD_NEW_BEACON;
3300 int ret;
3301 int beacon_set;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003302 int num_suites;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003303 int smps_mode;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08003304 u32 suites[10], suite;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003305 u32 ver;
3306
Dmitry Shmidt7f656022015-02-25 14:36:37 -08003307 beacon_set = params->reenable ? 0 : bss->beacon_set;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003308
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003309 wpa_printf(MSG_DEBUG, "nl80211: Set beacon (beacon_set=%d)",
3310 beacon_set);
3311 if (beacon_set)
3312 cmd = NL80211_CMD_SET_BEACON;
3313
Dmitry Shmidt0ccb66e2013-03-29 16:41:28 -07003314 wpa_hexdump(MSG_DEBUG, "nl80211: Beacon head",
3315 params->head, params->head_len);
Dmitry Shmidt0ccb66e2013-03-29 16:41:28 -07003316 wpa_hexdump(MSG_DEBUG, "nl80211: Beacon tail",
3317 params->tail, params->tail_len);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003318 wpa_printf(MSG_DEBUG, "nl80211: ifindex=%d", bss->ifindex);
Dmitry Shmidt0ccb66e2013-03-29 16:41:28 -07003319 wpa_printf(MSG_DEBUG, "nl80211: beacon_int=%d", params->beacon_int);
Dmitry Shmidt0ccb66e2013-03-29 16:41:28 -07003320 wpa_printf(MSG_DEBUG, "nl80211: dtim_period=%d", params->dtim_period);
Dmitry Shmidt0ccb66e2013-03-29 16:41:28 -07003321 wpa_hexdump_ascii(MSG_DEBUG, "nl80211: ssid",
3322 params->ssid, params->ssid_len);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003323 if (!(msg = nl80211_bss_msg(bss, 0, cmd)) ||
3324 nla_put(msg, NL80211_ATTR_BEACON_HEAD, params->head_len,
3325 params->head) ||
3326 nla_put(msg, NL80211_ATTR_BEACON_TAIL, params->tail_len,
3327 params->tail) ||
Dmitry Shmidtff787d52015-01-12 13:01:47 -08003328 nl80211_put_beacon_int(msg, params->beacon_int) ||
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003329 nla_put_u32(msg, NL80211_ATTR_DTIM_PERIOD, params->dtim_period) ||
3330 nla_put(msg, NL80211_ATTR_SSID, params->ssid_len, params->ssid))
3331 goto fail;
Dmitry Shmidt0ccb66e2013-03-29 16:41:28 -07003332 if (params->proberesp && params->proberesp_len) {
3333 wpa_hexdump(MSG_DEBUG, "nl80211: proberesp (offload)",
3334 params->proberesp, params->proberesp_len);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003335 if (nla_put(msg, NL80211_ATTR_PROBE_RESP, params->proberesp_len,
3336 params->proberesp))
3337 goto fail;
Dmitry Shmidt0ccb66e2013-03-29 16:41:28 -07003338 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003339 switch (params->hide_ssid) {
3340 case NO_SSID_HIDING:
Dmitry Shmidt0ccb66e2013-03-29 16:41:28 -07003341 wpa_printf(MSG_DEBUG, "nl80211: hidden SSID not in use");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003342 if (nla_put_u32(msg, NL80211_ATTR_HIDDEN_SSID,
3343 NL80211_HIDDEN_SSID_NOT_IN_USE))
3344 goto fail;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003345 break;
3346 case HIDDEN_SSID_ZERO_LEN:
Dmitry Shmidt0ccb66e2013-03-29 16:41:28 -07003347 wpa_printf(MSG_DEBUG, "nl80211: hidden SSID zero len");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003348 if (nla_put_u32(msg, NL80211_ATTR_HIDDEN_SSID,
3349 NL80211_HIDDEN_SSID_ZERO_LEN))
3350 goto fail;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003351 break;
3352 case HIDDEN_SSID_ZERO_CONTENTS:
Dmitry Shmidt0ccb66e2013-03-29 16:41:28 -07003353 wpa_printf(MSG_DEBUG, "nl80211: hidden SSID zero contents");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003354 if (nla_put_u32(msg, NL80211_ATTR_HIDDEN_SSID,
3355 NL80211_HIDDEN_SSID_ZERO_CONTENTS))
3356 goto fail;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003357 break;
3358 }
Dmitry Shmidt0ccb66e2013-03-29 16:41:28 -07003359 wpa_printf(MSG_DEBUG, "nl80211: privacy=%d", params->privacy);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003360 if (params->privacy &&
3361 nla_put_flag(msg, NL80211_ATTR_PRIVACY))
3362 goto fail;
Dmitry Shmidt0ccb66e2013-03-29 16:41:28 -07003363 wpa_printf(MSG_DEBUG, "nl80211: auth_algs=0x%x", params->auth_algs);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003364 if ((params->auth_algs & (WPA_AUTH_ALG_OPEN | WPA_AUTH_ALG_SHARED)) ==
3365 (WPA_AUTH_ALG_OPEN | WPA_AUTH_ALG_SHARED)) {
3366 /* Leave out the attribute */
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003367 } else if (params->auth_algs & WPA_AUTH_ALG_SHARED) {
3368 if (nla_put_u32(msg, NL80211_ATTR_AUTH_TYPE,
3369 NL80211_AUTHTYPE_SHARED_KEY))
3370 goto fail;
3371 } else {
3372 if (nla_put_u32(msg, NL80211_ATTR_AUTH_TYPE,
3373 NL80211_AUTHTYPE_OPEN_SYSTEM))
3374 goto fail;
3375 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003376
Dmitry Shmidt0ccb66e2013-03-29 16:41:28 -07003377 wpa_printf(MSG_DEBUG, "nl80211: wpa_version=0x%x", params->wpa_version);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003378 ver = 0;
3379 if (params->wpa_version & WPA_PROTO_WPA)
3380 ver |= NL80211_WPA_VERSION_1;
3381 if (params->wpa_version & WPA_PROTO_RSN)
3382 ver |= NL80211_WPA_VERSION_2;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003383 if (ver &&
3384 nla_put_u32(msg, NL80211_ATTR_WPA_VERSIONS, ver))
3385 goto fail;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003386
Dmitry Shmidt0ccb66e2013-03-29 16:41:28 -07003387 wpa_printf(MSG_DEBUG, "nl80211: key_mgmt_suites=0x%x",
3388 params->key_mgmt_suites);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003389 num_suites = 0;
3390 if (params->key_mgmt_suites & WPA_KEY_MGMT_IEEE8021X)
3391 suites[num_suites++] = WLAN_AKM_SUITE_8021X;
3392 if (params->key_mgmt_suites & WPA_KEY_MGMT_PSK)
3393 suites[num_suites++] = WLAN_AKM_SUITE_PSK;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003394 if (num_suites &&
3395 nla_put(msg, NL80211_ATTR_AKM_SUITES, num_suites * sizeof(u32),
3396 suites))
3397 goto fail;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003398
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003399 if (params->key_mgmt_suites & WPA_KEY_MGMT_IEEE8021X_NO_WPA &&
3400 params->pairwise_ciphers & (WPA_CIPHER_WEP104 | WPA_CIPHER_WEP40) &&
3401 nla_put_flag(msg, NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT))
3402 goto fail;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003403
Dmitry Shmidt0ccb66e2013-03-29 16:41:28 -07003404 wpa_printf(MSG_DEBUG, "nl80211: pairwise_ciphers=0x%x",
3405 params->pairwise_ciphers);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08003406 num_suites = wpa_cipher_to_cipher_suites(params->pairwise_ciphers,
3407 suites, ARRAY_SIZE(suites));
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003408 if (num_suites &&
3409 nla_put(msg, NL80211_ATTR_CIPHER_SUITES_PAIRWISE,
3410 num_suites * sizeof(u32), suites))
3411 goto fail;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003412
Dmitry Shmidt0ccb66e2013-03-29 16:41:28 -07003413 wpa_printf(MSG_DEBUG, "nl80211: group_cipher=0x%x",
3414 params->group_cipher);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08003415 suite = wpa_cipher_to_cipher_suite(params->group_cipher);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003416 if (suite &&
3417 nla_put_u32(msg, NL80211_ATTR_CIPHER_SUITE_GROUP, suite))
3418 goto fail;
3419
3420 switch (params->smps_mode) {
3421 case HT_CAP_INFO_SMPS_DYNAMIC:
3422 wpa_printf(MSG_DEBUG, "nl80211: SMPS mode - dynamic");
3423 smps_mode = NL80211_SMPS_DYNAMIC;
3424 break;
3425 case HT_CAP_INFO_SMPS_STATIC:
3426 wpa_printf(MSG_DEBUG, "nl80211: SMPS mode - static");
3427 smps_mode = NL80211_SMPS_STATIC;
3428 break;
3429 default:
3430 /* invalid - fallback to smps off */
3431 case HT_CAP_INFO_SMPS_DISABLED:
3432 wpa_printf(MSG_DEBUG, "nl80211: SMPS mode - off");
3433 smps_mode = NL80211_SMPS_OFF;
3434 break;
3435 }
3436 if (nla_put_u32(msg, NL80211_ATTR_SMPS_MODE, smps_mode))
3437 goto fail;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003438
3439 if (params->beacon_ies) {
Dmitry Shmidt0ccb66e2013-03-29 16:41:28 -07003440 wpa_hexdump_buf(MSG_DEBUG, "nl80211: beacon_ies",
3441 params->beacon_ies);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003442 if (nla_put(msg, NL80211_ATTR_IE,
3443 wpabuf_len(params->beacon_ies),
3444 wpabuf_head(params->beacon_ies)))
3445 goto fail;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003446 }
3447 if (params->proberesp_ies) {
Dmitry Shmidt0ccb66e2013-03-29 16:41:28 -07003448 wpa_hexdump_buf(MSG_DEBUG, "nl80211: proberesp_ies",
3449 params->proberesp_ies);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003450 if (nla_put(msg, NL80211_ATTR_IE_PROBE_RESP,
3451 wpabuf_len(params->proberesp_ies),
3452 wpabuf_head(params->proberesp_ies)))
3453 goto fail;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003454 }
3455 if (params->assocresp_ies) {
Dmitry Shmidt0ccb66e2013-03-29 16:41:28 -07003456 wpa_hexdump_buf(MSG_DEBUG, "nl80211: assocresp_ies",
3457 params->assocresp_ies);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003458 if (nla_put(msg, NL80211_ATTR_IE_ASSOC_RESP,
3459 wpabuf_len(params->assocresp_ies),
3460 wpabuf_head(params->assocresp_ies)))
3461 goto fail;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003462 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003463
Dmitry Shmidt04949592012-07-19 12:16:46 -07003464 if (drv->capa.flags & WPA_DRIVER_FLAGS_INACTIVITY_TIMER) {
Dmitry Shmidt0ccb66e2013-03-29 16:41:28 -07003465 wpa_printf(MSG_DEBUG, "nl80211: ap_max_inactivity=%d",
3466 params->ap_max_inactivity);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003467 if (nla_put_u16(msg, NL80211_ATTR_INACTIVITY_TIMEOUT,
3468 params->ap_max_inactivity))
3469 goto fail;
Dmitry Shmidt04949592012-07-19 12:16:46 -07003470 }
3471
Dmitry Shmidt7f656022015-02-25 14:36:37 -08003472#ifdef CONFIG_P2P
3473 if (params->p2p_go_ctwindow > 0) {
3474 if (drv->p2p_go_ctwindow_supported) {
3475 wpa_printf(MSG_DEBUG, "nl80211: P2P GO ctwindow=%d",
3476 params->p2p_go_ctwindow);
3477 if (nla_put_u8(msg, NL80211_ATTR_P2P_CTWINDOW,
3478 params->p2p_go_ctwindow))
3479 goto fail;
3480 } else {
3481 wpa_printf(MSG_INFO,
3482 "nl80211: Driver does not support CTWindow configuration - ignore this parameter");
3483 }
3484 }
3485#endif /* CONFIG_P2P */
3486
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003487 ret = send_and_recv_msgs(drv, msg, NULL, NULL);
3488 if (ret) {
3489 wpa_printf(MSG_DEBUG, "nl80211: Beacon set failed: %d (%s)",
3490 ret, strerror(-ret));
3491 } else {
3492 bss->beacon_set = 1;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003493 nl80211_set_bss(bss, params->cts_protect, params->preamble,
3494 params->short_slot_time, params->ht_opmode,
3495 params->isolate, params->basic_rates);
Dmitry Shmidt7832adb2014-04-29 10:53:02 -07003496 if (beacon_set && params->freq &&
3497 params->freq->bandwidth != bss->bandwidth) {
3498 wpa_printf(MSG_DEBUG,
3499 "nl80211: Update BSS %s bandwidth: %d -> %d",
3500 bss->ifname, bss->bandwidth,
3501 params->freq->bandwidth);
3502 ret = nl80211_set_channel(bss, params->freq, 1);
3503 if (ret) {
3504 wpa_printf(MSG_DEBUG,
3505 "nl80211: Frequency set failed: %d (%s)",
3506 ret, strerror(-ret));
3507 } else {
3508 wpa_printf(MSG_DEBUG,
3509 "nl80211: Frequency set succeeded for ht2040 coex");
3510 bss->bandwidth = params->freq->bandwidth;
3511 }
3512 } else if (!beacon_set) {
3513 /*
3514 * cfg80211 updates the driver on frequence change in AP
3515 * mode only at the point when beaconing is started, so
3516 * set the initial value here.
3517 */
3518 bss->bandwidth = params->freq->bandwidth;
3519 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003520 }
3521 return ret;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003522fail:
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003523 nlmsg_free(msg);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003524 return -ENOBUFS;
3525}
3526
3527
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08003528static int nl80211_put_freq_params(struct nl_msg *msg,
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003529 const struct hostapd_freq_params *freq)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003530{
Dmitry Shmidtff787d52015-01-12 13:01:47 -08003531 wpa_printf(MSG_DEBUG, " * freq=%d", freq->freq);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003532 if (nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq->freq))
3533 return -ENOBUFS;
3534
Dmitry Shmidtff787d52015-01-12 13:01:47 -08003535 wpa_printf(MSG_DEBUG, " * vht_enabled=%d", freq->vht_enabled);
3536 wpa_printf(MSG_DEBUG, " * ht_enabled=%d", freq->ht_enabled);
3537
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08003538 if (freq->vht_enabled) {
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003539 enum nl80211_chan_width cw;
3540
Dmitry Shmidtff787d52015-01-12 13:01:47 -08003541 wpa_printf(MSG_DEBUG, " * bandwidth=%d", freq->bandwidth);
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08003542 switch (freq->bandwidth) {
3543 case 20:
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003544 cw = NL80211_CHAN_WIDTH_20;
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08003545 break;
3546 case 40:
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003547 cw = NL80211_CHAN_WIDTH_40;
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08003548 break;
3549 case 80:
3550 if (freq->center_freq2)
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003551 cw = NL80211_CHAN_WIDTH_80P80;
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08003552 else
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003553 cw = NL80211_CHAN_WIDTH_80;
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08003554 break;
3555 case 160:
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003556 cw = NL80211_CHAN_WIDTH_160;
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08003557 break;
3558 default:
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08003559 return -EINVAL;
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08003560 }
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003561
Dmitry Shmidtff787d52015-01-12 13:01:47 -08003562 wpa_printf(MSG_DEBUG, " * channel_width=%d", cw);
3563 wpa_printf(MSG_DEBUG, " * center_freq1=%d",
3564 freq->center_freq1);
3565 wpa_printf(MSG_DEBUG, " * center_freq2=%d",
3566 freq->center_freq2);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003567 if (nla_put_u32(msg, NL80211_ATTR_CHANNEL_WIDTH, cw) ||
3568 nla_put_u32(msg, NL80211_ATTR_CENTER_FREQ1,
3569 freq->center_freq1) ||
3570 (freq->center_freq2 &&
3571 nla_put_u32(msg, NL80211_ATTR_CENTER_FREQ2,
3572 freq->center_freq2)))
3573 return -ENOBUFS;
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08003574 } else if (freq->ht_enabled) {
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003575 enum nl80211_channel_type ct;
3576
Dmitry Shmidtff787d52015-01-12 13:01:47 -08003577 wpa_printf(MSG_DEBUG, " * sec_channel_offset=%d",
3578 freq->sec_channel_offset);
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08003579 switch (freq->sec_channel_offset) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003580 case -1:
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003581 ct = NL80211_CHAN_HT40MINUS;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003582 break;
3583 case 1:
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003584 ct = NL80211_CHAN_HT40PLUS;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003585 break;
3586 default:
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003587 ct = NL80211_CHAN_HT20;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003588 break;
3589 }
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003590
Dmitry Shmidtff787d52015-01-12 13:01:47 -08003591 wpa_printf(MSG_DEBUG, " * channel_type=%d", ct);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003592 if (nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE, ct))
3593 return -ENOBUFS;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003594 }
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08003595 return 0;
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08003596}
3597
3598
Dmitry Shmidt7832adb2014-04-29 10:53:02 -07003599static int nl80211_set_channel(struct i802_bss *bss,
3600 struct hostapd_freq_params *freq, int set_chan)
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08003601{
3602 struct wpa_driver_nl80211_data *drv = bss->drv;
3603 struct nl_msg *msg;
3604 int ret;
3605
3606 wpa_printf(MSG_DEBUG,
3607 "nl80211: Set freq %d (ht_enabled=%d, vht_enabled=%d, bandwidth=%d MHz, cf1=%d MHz, cf2=%d MHz)",
3608 freq->freq, freq->ht_enabled, freq->vht_enabled,
3609 freq->bandwidth, freq->center_freq1, freq->center_freq2);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003610
3611 msg = nl80211_drv_msg(drv, 0, set_chan ? NL80211_CMD_SET_CHANNEL :
3612 NL80211_CMD_SET_WIPHY);
3613 if (!msg || nl80211_put_freq_params(msg, freq) < 0) {
3614 nlmsg_free(msg);
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08003615 return -1;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003616 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003617
3618 ret = send_and_recv_msgs(drv, msg, NULL, NULL);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003619 if (ret == 0) {
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08003620 bss->freq = freq->freq;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003621 return 0;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003622 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003623 wpa_printf(MSG_DEBUG, "nl80211: Failed to set channel (freq=%d): "
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08003624 "%d (%s)", freq->freq, ret, strerror(-ret));
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003625 return -1;
3626}
3627
3628
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003629static u32 sta_flags_nl80211(int flags)
3630{
3631 u32 f = 0;
3632
3633 if (flags & WPA_STA_AUTHORIZED)
3634 f |= BIT(NL80211_STA_FLAG_AUTHORIZED);
3635 if (flags & WPA_STA_WMM)
3636 f |= BIT(NL80211_STA_FLAG_WME);
3637 if (flags & WPA_STA_SHORT_PREAMBLE)
3638 f |= BIT(NL80211_STA_FLAG_SHORT_PREAMBLE);
3639 if (flags & WPA_STA_MFP)
3640 f |= BIT(NL80211_STA_FLAG_MFP);
3641 if (flags & WPA_STA_TDLS_PEER)
3642 f |= BIT(NL80211_STA_FLAG_TDLS_PEER);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003643 if (flags & WPA_STA_AUTHENTICATED)
3644 f |= BIT(NL80211_STA_FLAG_AUTHENTICATED);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003645
3646 return f;
3647}
3648
3649
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003650#ifdef CONFIG_MESH
3651static u32 sta_plink_state_nl80211(enum mesh_plink_state state)
3652{
3653 switch (state) {
3654 case PLINK_LISTEN:
3655 return NL80211_PLINK_LISTEN;
3656 case PLINK_OPEN_SENT:
3657 return NL80211_PLINK_OPN_SNT;
3658 case PLINK_OPEN_RCVD:
3659 return NL80211_PLINK_OPN_RCVD;
3660 case PLINK_CNF_RCVD:
3661 return NL80211_PLINK_CNF_RCVD;
3662 case PLINK_ESTAB:
3663 return NL80211_PLINK_ESTAB;
3664 case PLINK_HOLDING:
3665 return NL80211_PLINK_HOLDING;
3666 case PLINK_BLOCKED:
3667 return NL80211_PLINK_BLOCKED;
3668 default:
3669 wpa_printf(MSG_ERROR, "nl80211: Invalid mesh plink state %d",
3670 state);
3671 }
3672 return -1;
3673}
3674#endif /* CONFIG_MESH */
3675
3676
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003677static int wpa_driver_nl80211_sta_add(void *priv,
3678 struct hostapd_sta_add_params *params)
3679{
3680 struct i802_bss *bss = priv;
3681 struct wpa_driver_nl80211_data *drv = bss->drv;
Dmitry Shmidt8da800a2013-04-24 12:57:01 -07003682 struct nl_msg *msg;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003683 struct nl80211_sta_flag_update upd;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003684 int ret = -ENOBUFS;
3685
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003686 if ((params->flags & WPA_STA_TDLS_PEER) &&
3687 !(drv->capa.flags & WPA_DRIVER_FLAGS_TDLS_SUPPORT))
3688 return -EOPNOTSUPP;
3689
Dmitry Shmidtf8623282013-02-20 14:34:59 -08003690 wpa_printf(MSG_DEBUG, "nl80211: %s STA " MACSTR,
3691 params->set ? "Set" : "Add", MAC2STR(params->addr));
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003692 msg = nl80211_bss_msg(bss, 0, params->set ? NL80211_CMD_SET_STATION :
3693 NL80211_CMD_NEW_STATION);
3694 if (!msg || nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, params->addr))
3695 goto fail;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003696
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003697 if (!params->set || (params->flags & WPA_STA_TDLS_PEER)) {
3698 wpa_hexdump(MSG_DEBUG, " * supported rates",
3699 params->supp_rates, params->supp_rates_len);
3700 wpa_printf(MSG_DEBUG, " * capability=0x%x",
3701 params->capability);
3702 if (nla_put(msg, NL80211_ATTR_STA_SUPPORTED_RATES,
3703 params->supp_rates_len, params->supp_rates) ||
3704 nla_put_u16(msg, NL80211_ATTR_STA_CAPABILITY,
3705 params->capability))
3706 goto fail;
3707
3708 if (params->ht_capabilities) {
3709 wpa_hexdump(MSG_DEBUG, " * ht_capabilities",
3710 (u8 *) params->ht_capabilities,
3711 sizeof(*params->ht_capabilities));
3712 if (nla_put(msg, NL80211_ATTR_HT_CAPABILITY,
3713 sizeof(*params->ht_capabilities),
3714 params->ht_capabilities))
3715 goto fail;
3716 }
3717
3718 if (params->vht_capabilities) {
3719 wpa_hexdump(MSG_DEBUG, " * vht_capabilities",
3720 (u8 *) params->vht_capabilities,
3721 sizeof(*params->vht_capabilities));
3722 if (nla_put(msg, NL80211_ATTR_VHT_CAPABILITY,
3723 sizeof(*params->vht_capabilities),
3724 params->vht_capabilities))
3725 goto fail;
3726 }
3727
3728 if (params->ext_capab) {
3729 wpa_hexdump(MSG_DEBUG, " * ext_capab",
3730 params->ext_capab, params->ext_capab_len);
3731 if (nla_put(msg, NL80211_ATTR_STA_EXT_CAPABILITY,
3732 params->ext_capab_len, params->ext_capab))
3733 goto fail;
3734 }
3735 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003736 if (!params->set) {
Dmitry Shmidt51b6ea82013-05-08 10:42:09 -07003737 if (params->aid) {
3738 wpa_printf(MSG_DEBUG, " * aid=%u", params->aid);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003739 if (nla_put_u16(msg, NL80211_ATTR_STA_AID, params->aid))
3740 goto fail;
Dmitry Shmidt51b6ea82013-05-08 10:42:09 -07003741 } else {
3742 /*
3743 * cfg80211 validates that AID is non-zero, so we have
3744 * to make this a non-zero value for the TDLS case where
3745 * a dummy STA entry is used for now.
3746 */
3747 wpa_printf(MSG_DEBUG, " * aid=1 (TDLS workaround)");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003748 if (nla_put_u16(msg, NL80211_ATTR_STA_AID, 1))
3749 goto fail;
Dmitry Shmidt51b6ea82013-05-08 10:42:09 -07003750 }
Dmitry Shmidtf8623282013-02-20 14:34:59 -08003751 wpa_printf(MSG_DEBUG, " * listen_interval=%u",
3752 params->listen_interval);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003753 if (nla_put_u16(msg, NL80211_ATTR_STA_LISTEN_INTERVAL,
3754 params->listen_interval))
3755 goto fail;
Dmitry Shmidt8bae4132013-06-06 11:25:10 -07003756 } else if (params->aid && (params->flags & WPA_STA_TDLS_PEER)) {
3757 wpa_printf(MSG_DEBUG, " * peer_aid=%u", params->aid);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003758 if (nla_put_u16(msg, NL80211_ATTR_PEER_AID, params->aid))
3759 goto fail;
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08003760 }
3761
Dmitry Shmidtbd14a572014-02-18 10:33:49 -08003762 if (params->vht_opmode_enabled) {
3763 wpa_printf(MSG_DEBUG, " * opmode=%u", params->vht_opmode);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003764 if (nla_put_u8(msg, NL80211_ATTR_OPMODE_NOTIF,
3765 params->vht_opmode))
3766 goto fail;
Dmitry Shmidtf8623282013-02-20 14:34:59 -08003767 }
3768
Dmitry Shmidt344abd32014-01-14 13:17:00 -08003769 if (params->supp_channels) {
3770 wpa_hexdump(MSG_DEBUG, " * supported channels",
3771 params->supp_channels, params->supp_channels_len);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003772 if (nla_put(msg, NL80211_ATTR_STA_SUPPORTED_CHANNELS,
3773 params->supp_channels_len, params->supp_channels))
3774 goto fail;
Dmitry Shmidt344abd32014-01-14 13:17:00 -08003775 }
3776
3777 if (params->supp_oper_classes) {
3778 wpa_hexdump(MSG_DEBUG, " * supported operating classes",
3779 params->supp_oper_classes,
3780 params->supp_oper_classes_len);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003781 if (nla_put(msg, NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES,
3782 params->supp_oper_classes_len,
3783 params->supp_oper_classes))
3784 goto fail;
Dmitry Shmidt344abd32014-01-14 13:17:00 -08003785 }
3786
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003787 os_memset(&upd, 0, sizeof(upd));
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003788 upd.set = sta_flags_nl80211(params->flags);
3789 upd.mask = upd.set | sta_flags_nl80211(params->flags_mask);
Dmitry Shmidtf8623282013-02-20 14:34:59 -08003790 wpa_printf(MSG_DEBUG, " * flags set=0x%x mask=0x%x",
3791 upd.set, upd.mask);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003792 if (nla_put(msg, NL80211_ATTR_STA_FLAGS2, sizeof(upd), &upd))
3793 goto fail;
3794
3795#ifdef CONFIG_MESH
3796 if (params->plink_state &&
3797 nla_put_u8(msg, NL80211_ATTR_STA_PLINK_STATE,
3798 sta_plink_state_nl80211(params->plink_state)))
3799 goto fail;
3800#endif /* CONFIG_MESH */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003801
3802 if (params->flags & WPA_STA_WMM) {
Dmitry Shmidt8da800a2013-04-24 12:57:01 -07003803 struct nlattr *wme = nla_nest_start(msg, NL80211_ATTR_STA_WME);
3804
Dmitry Shmidtf8623282013-02-20 14:34:59 -08003805 wpa_printf(MSG_DEBUG, " * qosinfo=0x%x", params->qosinfo);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003806 if (!wme ||
3807 nla_put_u8(msg, NL80211_STA_WME_UAPSD_QUEUES,
3808 params->qosinfo & WMM_QOSINFO_STA_AC_MASK) ||
3809 nla_put_u8(msg, NL80211_STA_WME_MAX_SP,
3810 (params->qosinfo >> WMM_QOSINFO_STA_SP_SHIFT) &
3811 WMM_QOSINFO_STA_SP_MASK))
3812 goto fail;
Dmitry Shmidt8da800a2013-04-24 12:57:01 -07003813 nla_nest_end(msg, wme);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003814 }
3815
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003816 ret = send_and_recv_msgs(drv, msg, NULL, NULL);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003817 msg = NULL;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003818 if (ret)
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003819 wpa_printf(MSG_DEBUG, "nl80211: NL80211_CMD_%s_STATION "
3820 "result: %d (%s)", params->set ? "SET" : "NEW", ret,
3821 strerror(-ret));
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003822 if (ret == -EEXIST)
3823 ret = 0;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003824fail:
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003825 nlmsg_free(msg);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003826 return ret;
3827}
3828
3829
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07003830static void rtnl_neigh_delete_fdb_entry(struct i802_bss *bss, const u8 *addr)
3831{
3832#ifdef CONFIG_LIBNL3_ROUTE
3833 struct wpa_driver_nl80211_data *drv = bss->drv;
3834 struct rtnl_neigh *rn;
3835 struct nl_addr *nl_addr;
3836 int err;
3837
3838 rn = rtnl_neigh_alloc();
3839 if (!rn)
3840 return;
3841
3842 rtnl_neigh_set_family(rn, AF_BRIDGE);
3843 rtnl_neigh_set_ifindex(rn, bss->ifindex);
3844 nl_addr = nl_addr_build(AF_BRIDGE, (void *) addr, ETH_ALEN);
3845 if (!nl_addr) {
3846 rtnl_neigh_put(rn);
3847 return;
3848 }
3849 rtnl_neigh_set_lladdr(rn, nl_addr);
3850
3851 err = rtnl_neigh_delete(drv->rtnl_sk, rn, 0);
3852 if (err < 0) {
3853 wpa_printf(MSG_DEBUG, "nl80211: bridge FDB entry delete for "
3854 MACSTR " ifindex=%d failed: %s", MAC2STR(addr),
3855 bss->ifindex, nl_geterror(err));
3856 } else {
3857 wpa_printf(MSG_DEBUG, "nl80211: deleted bridge FDB entry for "
3858 MACSTR, MAC2STR(addr));
3859 }
3860
3861 nl_addr_put(nl_addr);
3862 rtnl_neigh_put(rn);
3863#endif /* CONFIG_LIBNL3_ROUTE */
3864}
3865
3866
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003867static int wpa_driver_nl80211_sta_remove(struct i802_bss *bss, const u8 *addr,
3868 int deauth, u16 reason_code)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003869{
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003870 struct wpa_driver_nl80211_data *drv = bss->drv;
3871 struct nl_msg *msg;
3872 int ret;
3873
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003874 if (!(msg = nl80211_bss_msg(bss, 0, NL80211_CMD_DEL_STATION)) ||
3875 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) ||
3876 (deauth == 0 &&
3877 nla_put_u8(msg, NL80211_ATTR_MGMT_SUBTYPE,
3878 WLAN_FC_STYPE_DISASSOC)) ||
3879 (deauth == 1 &&
3880 nla_put_u8(msg, NL80211_ATTR_MGMT_SUBTYPE,
3881 WLAN_FC_STYPE_DEAUTH)) ||
3882 (reason_code &&
3883 nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason_code))) {
3884 nlmsg_free(msg);
3885 return -ENOBUFS;
3886 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003887
3888 ret = send_and_recv_msgs(drv, msg, NULL, NULL);
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -07003889 wpa_printf(MSG_DEBUG, "nl80211: sta_remove -> DEL_STATION %s " MACSTR
3890 " --> %d (%s)",
3891 bss->ifname, MAC2STR(addr), ret, strerror(-ret));
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07003892
3893 if (drv->rtnl_sk)
3894 rtnl_neigh_delete_fdb_entry(bss, addr);
3895
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003896 if (ret == -ENOENT)
3897 return 0;
3898 return ret;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003899}
3900
3901
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003902void nl80211_remove_iface(struct wpa_driver_nl80211_data *drv, int ifidx)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003903{
3904 struct nl_msg *msg;
Dmitry Shmidt76cd2cc2014-05-27 12:56:04 -07003905 struct wpa_driver_nl80211_data *drv2;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003906
3907 wpa_printf(MSG_DEBUG, "nl80211: Remove interface ifindex=%d", ifidx);
3908
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003909 /* stop listening for EAPOL on this interface */
Dmitry Shmidt76cd2cc2014-05-27 12:56:04 -07003910 dl_list_for_each(drv2, &drv->global->interfaces,
3911 struct wpa_driver_nl80211_data, list)
3912 del_ifidx(drv2, ifidx);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003913
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003914 msg = nl80211_ifindex_msg(drv, ifidx, 0, NL80211_CMD_DEL_INTERFACE);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003915 if (send_and_recv_msgs(drv, msg, NULL, NULL) == 0)
3916 return;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003917 wpa_printf(MSG_ERROR, "Failed to remove interface (ifidx=%d)", ifidx);
3918}
3919
3920
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003921static const char * nl80211_iftype_str(enum nl80211_iftype mode)
3922{
3923 switch (mode) {
3924 case NL80211_IFTYPE_ADHOC:
3925 return "ADHOC";
3926 case NL80211_IFTYPE_STATION:
3927 return "STATION";
3928 case NL80211_IFTYPE_AP:
3929 return "AP";
Dmitry Shmidtf7e0a992013-05-23 11:03:10 -07003930 case NL80211_IFTYPE_AP_VLAN:
3931 return "AP_VLAN";
3932 case NL80211_IFTYPE_WDS:
3933 return "WDS";
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003934 case NL80211_IFTYPE_MONITOR:
3935 return "MONITOR";
Dmitry Shmidtf7e0a992013-05-23 11:03:10 -07003936 case NL80211_IFTYPE_MESH_POINT:
3937 return "MESH_POINT";
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003938 case NL80211_IFTYPE_P2P_CLIENT:
3939 return "P2P_CLIENT";
3940 case NL80211_IFTYPE_P2P_GO:
3941 return "P2P_GO";
Dmitry Shmidt34af3062013-07-11 10:46:32 -07003942 case NL80211_IFTYPE_P2P_DEVICE:
3943 return "P2P_DEVICE";
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003944 default:
3945 return "unknown";
3946 }
3947}
3948
3949
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003950static int nl80211_create_iface_once(struct wpa_driver_nl80211_data *drv,
3951 const char *ifname,
3952 enum nl80211_iftype iftype,
Dmitry Shmidt34af3062013-07-11 10:46:32 -07003953 const u8 *addr, int wds,
3954 int (*handler)(struct nl_msg *, void *),
3955 void *arg)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003956{
Dmitry Shmidt8da800a2013-04-24 12:57:01 -07003957 struct nl_msg *msg;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003958 int ifidx;
3959 int ret = -ENOBUFS;
3960
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003961 wpa_printf(MSG_DEBUG, "nl80211: Create interface iftype %d (%s)",
3962 iftype, nl80211_iftype_str(iftype));
3963
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003964 msg = nl80211_cmd_msg(drv->first_bss, 0, NL80211_CMD_NEW_INTERFACE);
3965 if (!msg ||
3966 nla_put_string(msg, NL80211_ATTR_IFNAME, ifname) ||
3967 nla_put_u32(msg, NL80211_ATTR_IFTYPE, iftype))
3968 goto fail;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003969
3970 if (iftype == NL80211_IFTYPE_MONITOR) {
Dmitry Shmidt8da800a2013-04-24 12:57:01 -07003971 struct nlattr *flags;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003972
Dmitry Shmidt8da800a2013-04-24 12:57:01 -07003973 flags = nla_nest_start(msg, NL80211_ATTR_MNTR_FLAGS);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003974 if (!flags ||
3975 nla_put_flag(msg, NL80211_MNTR_FLAG_COOK_FRAMES))
3976 goto fail;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003977
Dmitry Shmidt8da800a2013-04-24 12:57:01 -07003978 nla_nest_end(msg, flags);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003979 } else if (wds) {
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003980 if (nla_put_u8(msg, NL80211_ATTR_4ADDR, wds))
3981 goto fail;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003982 }
3983
Dmitry Shmidtb58836e2014-04-29 14:35:56 -07003984 /*
3985 * Tell cfg80211 that the interface belongs to the socket that created
3986 * it, and the interface should be deleted when the socket is closed.
3987 */
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003988 if (nla_put_flag(msg, NL80211_ATTR_IFACE_SOCKET_OWNER))
3989 goto fail;
Dmitry Shmidtb58836e2014-04-29 14:35:56 -07003990
Dmitry Shmidt34af3062013-07-11 10:46:32 -07003991 ret = send_and_recv_msgs(drv, msg, handler, arg);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003992 msg = NULL;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003993 if (ret) {
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003994 fail:
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003995 nlmsg_free(msg);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003996 wpa_printf(MSG_ERROR, "Failed to create interface %s: %d (%s)",
3997 ifname, ret, strerror(-ret));
3998 return ret;
3999 }
4000
Dmitry Shmidt34af3062013-07-11 10:46:32 -07004001 if (iftype == NL80211_IFTYPE_P2P_DEVICE)
4002 return 0;
4003
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004004 ifidx = if_nametoindex(ifname);
4005 wpa_printf(MSG_DEBUG, "nl80211: New interface %s created: ifindex=%d",
4006 ifname, ifidx);
4007
4008 if (ifidx <= 0)
4009 return -1;
4010
Dmitry Shmidt76cd2cc2014-05-27 12:56:04 -07004011 /*
4012 * Some virtual interfaces need to process EAPOL packets and events on
4013 * the parent interface. This is used mainly with hostapd.
4014 */
4015 if (drv->hostapd ||
4016 iftype == NL80211_IFTYPE_AP_VLAN ||
4017 iftype == NL80211_IFTYPE_WDS ||
4018 iftype == NL80211_IFTYPE_MONITOR) {
4019 /* start listening for EAPOL on this interface */
4020 add_ifidx(drv, ifidx);
4021 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004022
4023 if (addr && iftype != NL80211_IFTYPE_MONITOR &&
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004024 linux_set_ifhwaddr(drv->global->ioctl_sock, ifname, addr)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004025 nl80211_remove_iface(drv, ifidx);
4026 return -1;
4027 }
4028
4029 return ifidx;
4030}
4031
4032
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004033int nl80211_create_iface(struct wpa_driver_nl80211_data *drv,
4034 const char *ifname, enum nl80211_iftype iftype,
4035 const u8 *addr, int wds,
4036 int (*handler)(struct nl_msg *, void *),
4037 void *arg, int use_existing)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004038{
4039 int ret;
4040
Dmitry Shmidt34af3062013-07-11 10:46:32 -07004041 ret = nl80211_create_iface_once(drv, ifname, iftype, addr, wds, handler,
4042 arg);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004043
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004044 /* if error occurred and interface exists already */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004045 if (ret == -ENFILE && if_nametoindex(ifname)) {
Dmitry Shmidtcce06662013-11-04 18:44:24 -08004046 if (use_existing) {
4047 wpa_printf(MSG_DEBUG, "nl80211: Continue using existing interface %s",
4048 ifname);
Dmitry Shmidtdf5a7e42014-04-02 12:59:59 -07004049 if (addr && iftype != NL80211_IFTYPE_MONITOR &&
4050 linux_set_ifhwaddr(drv->global->ioctl_sock, ifname,
4051 addr) < 0 &&
4052 (linux_set_iface_flags(drv->global->ioctl_sock,
4053 ifname, 0) < 0 ||
4054 linux_set_ifhwaddr(drv->global->ioctl_sock, ifname,
4055 addr) < 0 ||
4056 linux_set_iface_flags(drv->global->ioctl_sock,
4057 ifname, 1) < 0))
4058 return -1;
Dmitry Shmidtcce06662013-11-04 18:44:24 -08004059 return -ENFILE;
4060 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004061 wpa_printf(MSG_INFO, "Try to remove and re-create %s", ifname);
4062
4063 /* Try to remove the interface that was already there. */
4064 nl80211_remove_iface(drv, if_nametoindex(ifname));
4065
4066 /* Try to create the interface again */
4067 ret = nl80211_create_iface_once(drv, ifname, iftype, addr,
Dmitry Shmidt34af3062013-07-11 10:46:32 -07004068 wds, handler, arg);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004069 }
4070
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004071 if (ret >= 0 && is_p2p_net_interface(iftype)) {
4072 wpa_printf(MSG_DEBUG,
4073 "nl80211: Interface %s created for P2P - disable 11b rates",
4074 ifname);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004075 nl80211_disable_11b_rates(drv, ret, 1);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004076 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004077
4078 return ret;
4079}
4080
4081
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004082static int nl80211_setup_ap(struct i802_bss *bss)
4083{
4084 struct wpa_driver_nl80211_data *drv = bss->drv;
4085
Dmitry Shmidtcce06662013-11-04 18:44:24 -08004086 wpa_printf(MSG_DEBUG, "nl80211: Setup AP(%s) - device_ap_sme=%d use_monitor=%d",
4087 bss->ifname, drv->device_ap_sme, drv->use_monitor);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004088
4089 /*
4090 * Disable Probe Request reporting unless we need it in this way for
4091 * devices that include the AP SME, in the other case (unless using
4092 * monitor iface) we'll get it through the nl_mgmt socket instead.
4093 */
4094 if (!drv->device_ap_sme)
4095 wpa_driver_nl80211_probe_req_report(bss, 0);
4096
4097 if (!drv->device_ap_sme && !drv->use_monitor)
4098 if (nl80211_mgmt_subscribe_ap(bss))
4099 return -1;
4100
4101 if (drv->device_ap_sme && !drv->use_monitor)
4102 if (nl80211_mgmt_subscribe_ap_dev_sme(bss))
4103 return -1;
4104
4105 if (!drv->device_ap_sme && drv->use_monitor &&
4106 nl80211_create_monitor_interface(drv) &&
4107 !drv->device_ap_sme)
Dmitry Shmidt04949592012-07-19 12:16:46 -07004108 return -1;
4109
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004110 if (drv->device_ap_sme &&
4111 wpa_driver_nl80211_probe_req_report(bss, 1) < 0) {
4112 wpa_printf(MSG_DEBUG, "nl80211: Failed to enable "
4113 "Probe Request frame reporting in AP mode");
4114 /* Try to survive without this */
4115 }
4116
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004117 return 0;
4118}
4119
4120
4121static void nl80211_teardown_ap(struct i802_bss *bss)
4122{
4123 struct wpa_driver_nl80211_data *drv = bss->drv;
4124
Dmitry Shmidtcce06662013-11-04 18:44:24 -08004125 wpa_printf(MSG_DEBUG, "nl80211: Teardown AP(%s) - device_ap_sme=%d use_monitor=%d",
4126 bss->ifname, drv->device_ap_sme, drv->use_monitor);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004127 if (drv->device_ap_sme) {
4128 wpa_driver_nl80211_probe_req_report(bss, 0);
4129 if (!drv->use_monitor)
4130 nl80211_mgmt_unsubscribe(bss, "AP teardown (dev SME)");
4131 } else if (drv->use_monitor)
4132 nl80211_remove_monitor_interface(drv);
4133 else
4134 nl80211_mgmt_unsubscribe(bss, "AP teardown");
4135
4136 bss->beacon_set = 0;
4137}
4138
4139
4140static int nl80211_send_eapol_data(struct i802_bss *bss,
4141 const u8 *addr, const u8 *data,
4142 size_t data_len)
4143{
4144 struct sockaddr_ll ll;
4145 int ret;
4146
4147 if (bss->drv->eapol_tx_sock < 0) {
4148 wpa_printf(MSG_DEBUG, "nl80211: No socket to send EAPOL");
4149 return -1;
4150 }
4151
4152 os_memset(&ll, 0, sizeof(ll));
4153 ll.sll_family = AF_PACKET;
4154 ll.sll_ifindex = bss->ifindex;
4155 ll.sll_protocol = htons(ETH_P_PAE);
4156 ll.sll_halen = ETH_ALEN;
4157 os_memcpy(ll.sll_addr, addr, ETH_ALEN);
4158 ret = sendto(bss->drv->eapol_tx_sock, data, data_len, 0,
4159 (struct sockaddr *) &ll, sizeof(ll));
4160 if (ret < 0)
4161 wpa_printf(MSG_ERROR, "nl80211: EAPOL TX: %s",
4162 strerror(errno));
4163
4164 return ret;
4165}
4166
4167
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004168static const u8 rfc1042_header[6] = { 0xaa, 0xaa, 0x03, 0x00, 0x00, 0x00 };
4169
4170static int wpa_driver_nl80211_hapd_send_eapol(
4171 void *priv, const u8 *addr, const u8 *data,
4172 size_t data_len, int encrypt, const u8 *own_addr, u32 flags)
4173{
4174 struct i802_bss *bss = priv;
4175 struct wpa_driver_nl80211_data *drv = bss->drv;
4176 struct ieee80211_hdr *hdr;
4177 size_t len;
4178 u8 *pos;
4179 int res;
4180 int qos = flags & WPA_STA_WMM;
Dmitry Shmidt641185e2013-11-06 15:17:13 -08004181
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004182 if (drv->device_ap_sme || !drv->use_monitor)
4183 return nl80211_send_eapol_data(bss, addr, data, data_len);
4184
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004185 len = sizeof(*hdr) + (qos ? 2 : 0) + sizeof(rfc1042_header) + 2 +
4186 data_len;
4187 hdr = os_zalloc(len);
4188 if (hdr == NULL) {
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -07004189 wpa_printf(MSG_INFO, "nl80211: Failed to allocate EAPOL buffer(len=%lu)",
4190 (unsigned long) len);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004191 return -1;
4192 }
4193
4194 hdr->frame_control =
4195 IEEE80211_FC(WLAN_FC_TYPE_DATA, WLAN_FC_STYPE_DATA);
4196 hdr->frame_control |= host_to_le16(WLAN_FC_FROMDS);
4197 if (encrypt)
4198 hdr->frame_control |= host_to_le16(WLAN_FC_ISWEP);
4199 if (qos) {
4200 hdr->frame_control |=
4201 host_to_le16(WLAN_FC_STYPE_QOS_DATA << 4);
4202 }
4203
4204 memcpy(hdr->IEEE80211_DA_FROMDS, addr, ETH_ALEN);
4205 memcpy(hdr->IEEE80211_BSSID_FROMDS, own_addr, ETH_ALEN);
4206 memcpy(hdr->IEEE80211_SA_FROMDS, own_addr, ETH_ALEN);
4207 pos = (u8 *) (hdr + 1);
4208
4209 if (qos) {
Dmitry Shmidtaa532512012-09-24 10:35:31 -07004210 /* Set highest priority in QoS header */
4211 pos[0] = 7;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004212 pos[1] = 0;
4213 pos += 2;
4214 }
4215
4216 memcpy(pos, rfc1042_header, sizeof(rfc1042_header));
4217 pos += sizeof(rfc1042_header);
4218 WPA_PUT_BE16(pos, ETH_P_PAE);
4219 pos += 2;
4220 memcpy(pos, data, data_len);
4221
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08004222 res = wpa_driver_nl80211_send_frame(bss, (u8 *) hdr, len, encrypt, 0,
4223 0, 0, 0, 0);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004224 if (res < 0) {
4225 wpa_printf(MSG_ERROR, "i802_send_eapol - packet len: %lu - "
4226 "failed: %d (%s)",
4227 (unsigned long) len, errno, strerror(errno));
4228 }
4229 os_free(hdr);
4230
4231 return res;
4232}
4233
4234
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004235static int wpa_driver_nl80211_sta_set_flags(void *priv, const u8 *addr,
4236 int total_flags,
4237 int flags_or, int flags_and)
4238{
4239 struct i802_bss *bss = priv;
Dmitry Shmidt8da800a2013-04-24 12:57:01 -07004240 struct nl_msg *msg;
4241 struct nlattr *flags;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004242 struct nl80211_sta_flag_update upd;
4243
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07004244 wpa_printf(MSG_DEBUG, "nl80211: Set STA flags - ifname=%s addr=" MACSTR
4245 " total_flags=0x%x flags_or=0x%x flags_and=0x%x authorized=%d",
4246 bss->ifname, MAC2STR(addr), total_flags, flags_or, flags_and,
4247 !!(total_flags & WPA_STA_AUTHORIZED));
4248
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004249 if (!(msg = nl80211_bss_msg(bss, 0, NL80211_CMD_SET_STATION)) ||
4250 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr))
4251 goto fail;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004252
4253 /*
4254 * Backwards compatibility version using NL80211_ATTR_STA_FLAGS. This
4255 * can be removed eventually.
4256 */
Dmitry Shmidt8da800a2013-04-24 12:57:01 -07004257 flags = nla_nest_start(msg, NL80211_ATTR_STA_FLAGS);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004258 if (!flags ||
4259 ((total_flags & WPA_STA_AUTHORIZED) &&
4260 nla_put_flag(msg, NL80211_STA_FLAG_AUTHORIZED)) ||
4261 ((total_flags & WPA_STA_WMM) &&
4262 nla_put_flag(msg, NL80211_STA_FLAG_WME)) ||
4263 ((total_flags & WPA_STA_SHORT_PREAMBLE) &&
4264 nla_put_flag(msg, NL80211_STA_FLAG_SHORT_PREAMBLE)) ||
4265 ((total_flags & WPA_STA_MFP) &&
4266 nla_put_flag(msg, NL80211_STA_FLAG_MFP)) ||
4267 ((total_flags & WPA_STA_TDLS_PEER) &&
4268 nla_put_flag(msg, NL80211_STA_FLAG_TDLS_PEER)))
4269 goto fail;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004270
Dmitry Shmidt8da800a2013-04-24 12:57:01 -07004271 nla_nest_end(msg, flags);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004272
4273 os_memset(&upd, 0, sizeof(upd));
4274 upd.mask = sta_flags_nl80211(flags_or | ~flags_and);
4275 upd.set = sta_flags_nl80211(flags_or);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004276 if (nla_put(msg, NL80211_ATTR_STA_FLAGS2, sizeof(upd), &upd))
4277 goto fail;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004278
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004279 return send_and_recv_msgs(bss->drv, msg, NULL, NULL);
4280fail:
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004281 nlmsg_free(msg);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004282 return -ENOBUFS;
4283}
4284
4285
4286static int wpa_driver_nl80211_ap(struct wpa_driver_nl80211_data *drv,
4287 struct wpa_driver_associate_params *params)
4288{
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08004289 enum nl80211_iftype nlmode, old_mode;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004290
4291 if (params->p2p) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004292 wpa_printf(MSG_DEBUG, "nl80211: Setup AP operations for P2P "
4293 "group (GO)");
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004294 nlmode = NL80211_IFTYPE_P2P_GO;
4295 } else
4296 nlmode = NL80211_IFTYPE_AP;
4297
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08004298 old_mode = drv->nlmode;
Dmitry Shmidtcce06662013-11-04 18:44:24 -08004299 if (wpa_driver_nl80211_set_mode(drv->first_bss, nlmode)) {
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08004300 nl80211_remove_monitor_interface(drv);
4301 return -1;
4302 }
4303
Dmitry Shmidt203eadb2015-03-05 14:16:04 -08004304 if (params->freq.freq &&
4305 nl80211_set_channel(drv->first_bss, &params->freq, 0)) {
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08004306 if (old_mode != nlmode)
Dmitry Shmidtcce06662013-11-04 18:44:24 -08004307 wpa_driver_nl80211_set_mode(drv->first_bss, old_mode);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004308 nl80211_remove_monitor_interface(drv);
4309 return -1;
4310 }
4311
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004312 return 0;
4313}
4314
4315
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004316static int nl80211_leave_ibss(struct wpa_driver_nl80211_data *drv,
4317 int reset_mode)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004318{
4319 struct nl_msg *msg;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004320 int ret;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004321
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004322 msg = nl80211_drv_msg(drv, 0, NL80211_CMD_LEAVE_IBSS);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004323 ret = send_and_recv_msgs(drv, msg, NULL, NULL);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004324 if (ret) {
4325 wpa_printf(MSG_DEBUG, "nl80211: Leave IBSS failed: ret=%d "
4326 "(%s)", ret, strerror(-ret));
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004327 } else {
4328 wpa_printf(MSG_DEBUG,
4329 "nl80211: Leave IBSS request sent successfully");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004330 }
4331
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004332 if (reset_mode &&
4333 wpa_driver_nl80211_set_mode(drv->first_bss,
Dmitry Shmidt56052862013-10-04 10:23:25 -07004334 NL80211_IFTYPE_STATION)) {
4335 wpa_printf(MSG_INFO, "nl80211: Failed to set interface into "
4336 "station mode");
4337 }
4338
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004339 return ret;
4340}
4341
4342
Dmitry Shmidt2f74e362015-01-21 13:19:05 -08004343static int nl80211_ht_vht_overrides(struct nl_msg *msg,
4344 struct wpa_driver_associate_params *params)
4345{
4346 if (params->disable_ht && nla_put_flag(msg, NL80211_ATTR_DISABLE_HT))
4347 return -1;
4348
4349 if (params->htcaps && params->htcaps_mask) {
4350 int sz = sizeof(struct ieee80211_ht_capabilities);
4351 wpa_hexdump(MSG_DEBUG, " * htcaps", params->htcaps, sz);
4352 wpa_hexdump(MSG_DEBUG, " * htcaps_mask",
4353 params->htcaps_mask, sz);
4354 if (nla_put(msg, NL80211_ATTR_HT_CAPABILITY, sz,
4355 params->htcaps) ||
4356 nla_put(msg, NL80211_ATTR_HT_CAPABILITY_MASK, sz,
4357 params->htcaps_mask))
4358 return -1;
4359 }
4360
4361#ifdef CONFIG_VHT_OVERRIDES
4362 if (params->disable_vht) {
4363 wpa_printf(MSG_DEBUG, " * VHT disabled");
4364 if (nla_put_flag(msg, NL80211_ATTR_DISABLE_VHT))
4365 return -1;
4366 }
4367
4368 if (params->vhtcaps && params->vhtcaps_mask) {
4369 int sz = sizeof(struct ieee80211_vht_capabilities);
4370 wpa_hexdump(MSG_DEBUG, " * vhtcaps", params->vhtcaps, sz);
4371 wpa_hexdump(MSG_DEBUG, " * vhtcaps_mask",
4372 params->vhtcaps_mask, sz);
4373 if (nla_put(msg, NL80211_ATTR_VHT_CAPABILITY, sz,
4374 params->vhtcaps) ||
4375 nla_put(msg, NL80211_ATTR_VHT_CAPABILITY_MASK, sz,
4376 params->vhtcaps_mask))
4377 return -1;
4378 }
4379#endif /* CONFIG_VHT_OVERRIDES */
4380
4381 return 0;
4382}
4383
4384
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004385static int wpa_driver_nl80211_ibss(struct wpa_driver_nl80211_data *drv,
4386 struct wpa_driver_associate_params *params)
4387{
4388 struct nl_msg *msg;
4389 int ret = -1;
4390 int count = 0;
4391
4392 wpa_printf(MSG_DEBUG, "nl80211: Join IBSS (ifindex=%d)", drv->ifindex);
4393
Dmitry Shmidt9ead16e2014-10-07 13:15:23 -07004394 if (wpa_driver_nl80211_set_mode_ibss(drv->first_bss, &params->freq)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004395 wpa_printf(MSG_INFO, "nl80211: Failed to set interface into "
4396 "IBSS mode");
4397 return -1;
4398 }
4399
4400retry:
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004401 if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_JOIN_IBSS)) ||
4402 params->ssid == NULL || params->ssid_len > sizeof(drv->ssid))
4403 goto fail;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004404
4405 wpa_hexdump_ascii(MSG_DEBUG, " * SSID",
4406 params->ssid, params->ssid_len);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004407 if (nla_put(msg, NL80211_ATTR_SSID, params->ssid_len, params->ssid))
4408 goto fail;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004409 os_memcpy(drv->ssid, params->ssid, params->ssid_len);
4410 drv->ssid_len = params->ssid_len;
4411
Dmitry Shmidtff787d52015-01-12 13:01:47 -08004412 if (nl80211_put_freq_params(msg, &params->freq) < 0 ||
4413 nl80211_put_beacon_int(msg, params->beacon_int))
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004414 goto fail;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004415
4416 ret = nl80211_set_conn_keys(params, msg);
4417 if (ret)
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004418 goto fail;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004419
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08004420 if (params->bssid && params->fixed_bssid) {
4421 wpa_printf(MSG_DEBUG, " * BSSID=" MACSTR,
4422 MAC2STR(params->bssid));
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004423 if (nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, params->bssid))
4424 goto fail;
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08004425 }
4426
Dmitry Shmidt7f656022015-02-25 14:36:37 -08004427 if (params->fixed_freq) {
4428 wpa_printf(MSG_DEBUG, " * fixed_freq");
4429 if (nla_put_flag(msg, NL80211_ATTR_FREQ_FIXED))
4430 goto fail;
4431 }
4432
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004433 if (params->key_mgmt_suite == WPA_KEY_MGMT_IEEE8021X ||
4434 params->key_mgmt_suite == WPA_KEY_MGMT_PSK ||
4435 params->key_mgmt_suite == WPA_KEY_MGMT_IEEE8021X_SHA256 ||
4436 params->key_mgmt_suite == WPA_KEY_MGMT_PSK_SHA256) {
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08004437 wpa_printf(MSG_DEBUG, " * control port");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004438 if (nla_put_flag(msg, NL80211_ATTR_CONTROL_PORT))
4439 goto fail;
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08004440 }
4441
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004442 if (params->wpa_ie) {
4443 wpa_hexdump(MSG_DEBUG,
4444 " * Extra IEs for Beacon/Probe Response frames",
4445 params->wpa_ie, params->wpa_ie_len);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004446 if (nla_put(msg, NL80211_ATTR_IE, params->wpa_ie_len,
4447 params->wpa_ie))
4448 goto fail;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004449 }
4450
Dmitry Shmidt2f74e362015-01-21 13:19:05 -08004451 if (nl80211_ht_vht_overrides(msg, params) < 0)
4452 return -1;
4453
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004454 ret = send_and_recv_msgs(drv, msg, NULL, NULL);
4455 msg = NULL;
4456 if (ret) {
4457 wpa_printf(MSG_DEBUG, "nl80211: Join IBSS failed: ret=%d (%s)",
4458 ret, strerror(-ret));
4459 count++;
4460 if (ret == -EALREADY && count == 1) {
4461 wpa_printf(MSG_DEBUG, "nl80211: Retry IBSS join after "
4462 "forced leave");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004463 nl80211_leave_ibss(drv, 0);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004464 nlmsg_free(msg);
4465 goto retry;
4466 }
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004467 } else {
4468 wpa_printf(MSG_DEBUG,
4469 "nl80211: Join IBSS request sent successfully");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004470 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004471
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004472fail:
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004473 nlmsg_free(msg);
4474 return ret;
4475}
4476
4477
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004478static int nl80211_connect_common(struct wpa_driver_nl80211_data *drv,
4479 struct wpa_driver_associate_params *params,
4480 struct nl_msg *msg)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004481{
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004482 if (params->bssid) {
4483 wpa_printf(MSG_DEBUG, " * bssid=" MACSTR,
4484 MAC2STR(params->bssid));
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004485 if (nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, params->bssid))
4486 return -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004487 }
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004488
Dmitry Shmidt96be6222014-02-13 10:16:51 -08004489 if (params->bssid_hint) {
4490 wpa_printf(MSG_DEBUG, " * bssid_hint=" MACSTR,
4491 MAC2STR(params->bssid_hint));
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004492 if (nla_put(msg, NL80211_ATTR_MAC_HINT, ETH_ALEN,
4493 params->bssid_hint))
4494 return -1;
Dmitry Shmidt96be6222014-02-13 10:16:51 -08004495 }
4496
Dmitry Shmidt9ead16e2014-10-07 13:15:23 -07004497 if (params->freq.freq) {
4498 wpa_printf(MSG_DEBUG, " * freq=%d", params->freq.freq);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004499 if (nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ,
4500 params->freq.freq))
4501 return -1;
Dmitry Shmidt9ead16e2014-10-07 13:15:23 -07004502 drv->assoc_freq = params->freq.freq;
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -07004503 } else
4504 drv->assoc_freq = 0;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004505
Dmitry Shmidt96be6222014-02-13 10:16:51 -08004506 if (params->freq_hint) {
4507 wpa_printf(MSG_DEBUG, " * freq_hint=%d", params->freq_hint);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004508 if (nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ_HINT,
4509 params->freq_hint))
4510 return -1;
Dmitry Shmidt96be6222014-02-13 10:16:51 -08004511 }
4512
Dmitry Shmidt04949592012-07-19 12:16:46 -07004513 if (params->bg_scan_period >= 0) {
4514 wpa_printf(MSG_DEBUG, " * bg scan period=%d",
4515 params->bg_scan_period);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004516 if (nla_put_u16(msg, NL80211_ATTR_BG_SCAN_PERIOD,
4517 params->bg_scan_period))
4518 return -1;
Dmitry Shmidt04949592012-07-19 12:16:46 -07004519 }
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004520
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004521 if (params->ssid) {
4522 wpa_hexdump_ascii(MSG_DEBUG, " * SSID",
4523 params->ssid, params->ssid_len);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004524 if (nla_put(msg, NL80211_ATTR_SSID, params->ssid_len,
4525 params->ssid))
4526 return -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004527 if (params->ssid_len > sizeof(drv->ssid))
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004528 return -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004529 os_memcpy(drv->ssid, params->ssid, params->ssid_len);
4530 drv->ssid_len = params->ssid_len;
4531 }
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004532
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004533 wpa_hexdump(MSG_DEBUG, " * IEs", params->wpa_ie, params->wpa_ie_len);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004534 if (params->wpa_ie &&
4535 nla_put(msg, NL80211_ATTR_IE, params->wpa_ie_len, params->wpa_ie))
4536 return -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004537
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004538 if (params->wpa_proto) {
4539 enum nl80211_wpa_versions ver = 0;
4540
4541 if (params->wpa_proto & WPA_PROTO_WPA)
4542 ver |= NL80211_WPA_VERSION_1;
4543 if (params->wpa_proto & WPA_PROTO_RSN)
4544 ver |= NL80211_WPA_VERSION_2;
4545
4546 wpa_printf(MSG_DEBUG, " * WPA Versions 0x%x", ver);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004547 if (nla_put_u32(msg, NL80211_ATTR_WPA_VERSIONS, ver))
4548 return -1;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004549 }
4550
4551 if (params->pairwise_suite != WPA_CIPHER_NONE) {
4552 u32 cipher = wpa_cipher_to_cipher_suite(params->pairwise_suite);
4553 wpa_printf(MSG_DEBUG, " * pairwise=0x%x", cipher);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004554 if (nla_put_u32(msg, NL80211_ATTR_CIPHER_SUITES_PAIRWISE,
4555 cipher))
4556 return -1;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004557 }
4558
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08004559 if (params->group_suite == WPA_CIPHER_GTK_NOT_USED &&
4560 !(drv->capa.enc & WPA_DRIVER_CAPA_ENC_GTK_NOT_USED)) {
4561 /*
4562 * This is likely to work even though many drivers do not
4563 * advertise support for operations without GTK.
4564 */
4565 wpa_printf(MSG_DEBUG, " * skip group cipher configuration for GTK_NOT_USED due to missing driver support advertisement");
4566 } else if (params->group_suite != WPA_CIPHER_NONE) {
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004567 u32 cipher = wpa_cipher_to_cipher_suite(params->group_suite);
4568 wpa_printf(MSG_DEBUG, " * group=0x%x", cipher);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004569 if (nla_put_u32(msg, NL80211_ATTR_CIPHER_SUITE_GROUP, cipher))
4570 return -1;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004571 }
4572
4573 if (params->key_mgmt_suite == WPA_KEY_MGMT_IEEE8021X ||
4574 params->key_mgmt_suite == WPA_KEY_MGMT_PSK ||
4575 params->key_mgmt_suite == WPA_KEY_MGMT_FT_IEEE8021X ||
4576 params->key_mgmt_suite == WPA_KEY_MGMT_FT_PSK ||
Dmitry Shmidt15907092014-03-25 10:42:57 -07004577 params->key_mgmt_suite == WPA_KEY_MGMT_CCKM ||
Dmitry Shmidt3c57b3f2014-05-22 15:13:07 -07004578 params->key_mgmt_suite == WPA_KEY_MGMT_OSEN ||
4579 params->key_mgmt_suite == WPA_KEY_MGMT_IEEE8021X_SHA256 ||
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004580 params->key_mgmt_suite == WPA_KEY_MGMT_PSK_SHA256 ||
Dmitry Shmidt807291d2015-01-27 13:40:23 -08004581 params->key_mgmt_suite == WPA_KEY_MGMT_IEEE8021X_SUITE_B ||
4582 params->key_mgmt_suite == WPA_KEY_MGMT_IEEE8021X_SUITE_B_192) {
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004583 int mgmt = WLAN_AKM_SUITE_PSK;
4584
4585 switch (params->key_mgmt_suite) {
4586 case WPA_KEY_MGMT_CCKM:
4587 mgmt = WLAN_AKM_SUITE_CCKM;
4588 break;
4589 case WPA_KEY_MGMT_IEEE8021X:
4590 mgmt = WLAN_AKM_SUITE_8021X;
4591 break;
4592 case WPA_KEY_MGMT_FT_IEEE8021X:
4593 mgmt = WLAN_AKM_SUITE_FT_8021X;
4594 break;
4595 case WPA_KEY_MGMT_FT_PSK:
4596 mgmt = WLAN_AKM_SUITE_FT_PSK;
4597 break;
Dmitry Shmidt3c57b3f2014-05-22 15:13:07 -07004598 case WPA_KEY_MGMT_IEEE8021X_SHA256:
4599 mgmt = WLAN_AKM_SUITE_8021X_SHA256;
4600 break;
4601 case WPA_KEY_MGMT_PSK_SHA256:
4602 mgmt = WLAN_AKM_SUITE_PSK_SHA256;
4603 break;
Dmitry Shmidt15907092014-03-25 10:42:57 -07004604 case WPA_KEY_MGMT_OSEN:
4605 mgmt = WLAN_AKM_SUITE_OSEN;
4606 break;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004607 case WPA_KEY_MGMT_IEEE8021X_SUITE_B:
4608 mgmt = WLAN_AKM_SUITE_8021X_SUITE_B;
4609 break;
Dmitry Shmidt807291d2015-01-27 13:40:23 -08004610 case WPA_KEY_MGMT_IEEE8021X_SUITE_B_192:
4611 mgmt = WLAN_AKM_SUITE_8021X_SUITE_B_192;
4612 break;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004613 case WPA_KEY_MGMT_PSK:
4614 default:
4615 mgmt = WLAN_AKM_SUITE_PSK;
4616 break;
4617 }
Dmitry Shmidt15907092014-03-25 10:42:57 -07004618 wpa_printf(MSG_DEBUG, " * akm=0x%x", mgmt);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004619 if (nla_put_u32(msg, NL80211_ATTR_AKM_SUITES, mgmt))
4620 return -1;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004621 }
4622
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004623 if (nla_put_flag(msg, NL80211_ATTR_CONTROL_PORT))
4624 return -1;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004625
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004626 if (params->mgmt_frame_protection == MGMT_FRAME_PROTECTION_REQUIRED &&
4627 nla_put_u32(msg, NL80211_ATTR_USE_MFP, NL80211_MFP_REQUIRED))
4628 return -1;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004629
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004630 if (params->rrm_used) {
4631 u32 drv_rrm_flags = drv->capa.rrm_flags;
4632 if (!(drv_rrm_flags &
4633 WPA_DRIVER_FLAGS_DS_PARAM_SET_IE_IN_PROBES) ||
4634 !(drv_rrm_flags & WPA_DRIVER_FLAGS_QUIET) ||
4635 nla_put_flag(msg, NL80211_ATTR_USE_RRM))
4636 return -1;
4637 }
4638
Dmitry Shmidt2f74e362015-01-21 13:19:05 -08004639 if (nl80211_ht_vht_overrides(msg, params) < 0)
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004640 return -1;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004641
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004642 if (params->p2p)
4643 wpa_printf(MSG_DEBUG, " * P2P group");
4644
4645 return 0;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004646}
4647
4648
4649static int wpa_driver_nl80211_try_connect(
4650 struct wpa_driver_nl80211_data *drv,
4651 struct wpa_driver_associate_params *params)
4652{
4653 struct nl_msg *msg;
4654 enum nl80211_auth_type type;
4655 int ret;
4656 int algs;
4657
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004658 if (params->req_key_mgmt_offload && params->psk &&
4659 (params->key_mgmt_suite == WPA_KEY_MGMT_PSK ||
4660 params->key_mgmt_suite == WPA_KEY_MGMT_PSK_SHA256 ||
4661 params->key_mgmt_suite == WPA_KEY_MGMT_FT_PSK)) {
4662 wpa_printf(MSG_DEBUG, "nl80211: Key management set PSK");
4663 ret = issue_key_mgmt_set_key(drv, params->psk, 32);
4664 if (ret)
4665 return ret;
4666 }
4667
4668 wpa_printf(MSG_DEBUG, "nl80211: Connect (ifindex=%d)", drv->ifindex);
4669 msg = nl80211_drv_msg(drv, 0, NL80211_CMD_CONNECT);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004670 if (!msg)
4671 return -1;
4672
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004673 ret = nl80211_connect_common(drv, params, msg);
4674 if (ret)
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004675 goto fail;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004676
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004677 algs = 0;
4678 if (params->auth_alg & WPA_AUTH_ALG_OPEN)
4679 algs++;
4680 if (params->auth_alg & WPA_AUTH_ALG_SHARED)
4681 algs++;
4682 if (params->auth_alg & WPA_AUTH_ALG_LEAP)
4683 algs++;
4684 if (algs > 1) {
4685 wpa_printf(MSG_DEBUG, " * Leave out Auth Type for automatic "
4686 "selection");
4687 goto skip_auth_type;
4688 }
4689
4690 if (params->auth_alg & WPA_AUTH_ALG_OPEN)
4691 type = NL80211_AUTHTYPE_OPEN_SYSTEM;
4692 else if (params->auth_alg & WPA_AUTH_ALG_SHARED)
4693 type = NL80211_AUTHTYPE_SHARED_KEY;
4694 else if (params->auth_alg & WPA_AUTH_ALG_LEAP)
4695 type = NL80211_AUTHTYPE_NETWORK_EAP;
4696 else if (params->auth_alg & WPA_AUTH_ALG_FT)
4697 type = NL80211_AUTHTYPE_FT;
4698 else
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004699 goto fail;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004700
4701 wpa_printf(MSG_DEBUG, " * Auth Type %d", type);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004702 if (nla_put_u32(msg, NL80211_ATTR_AUTH_TYPE, type))
4703 goto fail;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004704
4705skip_auth_type:
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004706 ret = nl80211_set_conn_keys(params, msg);
4707 if (ret)
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004708 goto fail;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004709
4710 ret = send_and_recv_msgs(drv, msg, NULL, NULL);
4711 msg = NULL;
4712 if (ret) {
4713 wpa_printf(MSG_DEBUG, "nl80211: MLME connect failed: ret=%d "
4714 "(%s)", ret, strerror(-ret));
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004715 } else {
4716 wpa_printf(MSG_DEBUG,
4717 "nl80211: Connect request send successfully");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004718 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004719
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004720fail:
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004721 nlmsg_free(msg);
4722 return ret;
4723
4724}
4725
4726
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08004727static int wpa_driver_nl80211_connect(
4728 struct wpa_driver_nl80211_data *drv,
4729 struct wpa_driver_associate_params *params)
4730{
Jithu Jancea7c60b42014-12-03 18:54:40 +05304731 int ret;
4732
4733 /* Store the connection attempted bssid for future use */
4734 if (params->bssid)
4735 os_memcpy(drv->auth_attempt_bssid, params->bssid, ETH_ALEN);
4736 else
4737 os_memset(drv->auth_attempt_bssid, 0, ETH_ALEN);
4738
4739 ret = wpa_driver_nl80211_try_connect(drv, params);
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08004740 if (ret == -EALREADY) {
4741 /*
4742 * cfg80211 does not currently accept new connections if
4743 * we are already connected. As a workaround, force
4744 * disconnection and try again.
4745 */
4746 wpa_printf(MSG_DEBUG, "nl80211: Explicitly "
4747 "disconnecting before reassociation "
4748 "attempt");
4749 if (wpa_driver_nl80211_disconnect(
4750 drv, WLAN_REASON_PREV_AUTH_NOT_VALID))
4751 return -1;
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08004752 ret = wpa_driver_nl80211_try_connect(drv, params);
4753 }
4754 return ret;
4755}
4756
4757
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004758static int wpa_driver_nl80211_associate(
4759 void *priv, struct wpa_driver_associate_params *params)
4760{
4761 struct i802_bss *bss = priv;
4762 struct wpa_driver_nl80211_data *drv = bss->drv;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004763 int ret = -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004764 struct nl_msg *msg;
4765
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004766 nl80211_unmask_11b_rates(bss);
4767
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004768 if (params->mode == IEEE80211_MODE_AP)
4769 return wpa_driver_nl80211_ap(drv, params);
4770
4771 if (params->mode == IEEE80211_MODE_IBSS)
4772 return wpa_driver_nl80211_ibss(drv, params);
4773
4774 if (!(drv->capa.flags & WPA_DRIVER_FLAGS_SME)) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004775 enum nl80211_iftype nlmode = params->p2p ?
4776 NL80211_IFTYPE_P2P_CLIENT : NL80211_IFTYPE_STATION;
4777
4778 if (wpa_driver_nl80211_set_mode(priv, nlmode) < 0)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004779 return -1;
4780 return wpa_driver_nl80211_connect(drv, params);
4781 }
4782
Dmitry Shmidt8bae4132013-06-06 11:25:10 -07004783 nl80211_mark_disconnected(drv);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004784
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004785 wpa_printf(MSG_DEBUG, "nl80211: Associate (ifindex=%d)",
4786 drv->ifindex);
4787 msg = nl80211_drv_msg(drv, 0, NL80211_CMD_ASSOCIATE);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004788 if (!msg)
4789 return -1;
4790
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004791 ret = nl80211_connect_common(drv, params, msg);
4792 if (ret)
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004793 goto fail;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004794
4795 if (params->prev_bssid) {
4796 wpa_printf(MSG_DEBUG, " * prev_bssid=" MACSTR,
4797 MAC2STR(params->prev_bssid));
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004798 if (nla_put(msg, NL80211_ATTR_PREV_BSSID, ETH_ALEN,
4799 params->prev_bssid))
4800 goto fail;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004801 }
4802
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004803 ret = send_and_recv_msgs(drv, msg, NULL, NULL);
4804 msg = NULL;
4805 if (ret) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004806 wpa_dbg(drv->ctx, MSG_DEBUG,
4807 "nl80211: MLME command failed (assoc): ret=%d (%s)",
4808 ret, strerror(-ret));
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004809 nl80211_dump_scan(drv);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004810 } else {
4811 wpa_printf(MSG_DEBUG,
4812 "nl80211: Association request send successfully");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004813 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004814
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004815fail:
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004816 nlmsg_free(msg);
4817 return ret;
4818}
4819
4820
4821static int nl80211_set_mode(struct wpa_driver_nl80211_data *drv,
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004822 int ifindex, enum nl80211_iftype mode)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004823{
4824 struct nl_msg *msg;
4825 int ret = -ENOBUFS;
4826
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004827 wpa_printf(MSG_DEBUG, "nl80211: Set mode ifindex %d iftype %d (%s)",
4828 ifindex, mode, nl80211_iftype_str(mode));
4829
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004830 msg = nl80211_cmd_msg(drv->first_bss, 0, NL80211_CMD_SET_INTERFACE);
4831 if (!msg || nla_put_u32(msg, NL80211_ATTR_IFTYPE, mode))
4832 goto fail;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004833
4834 ret = send_and_recv_msgs(drv, msg, NULL, NULL);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004835 msg = NULL;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004836 if (!ret)
4837 return 0;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004838fail:
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004839 nlmsg_free(msg);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004840 wpa_printf(MSG_DEBUG, "nl80211: Failed to set interface %d to mode %d:"
4841 " %d (%s)", ifindex, mode, ret, strerror(-ret));
4842 return ret;
4843}
4844
4845
Dmitry Shmidtd30ac602014-06-30 09:54:22 -07004846static int wpa_driver_nl80211_set_mode_impl(
4847 struct i802_bss *bss,
4848 enum nl80211_iftype nlmode,
4849 struct hostapd_freq_params *desired_freq_params)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004850{
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004851 struct wpa_driver_nl80211_data *drv = bss->drv;
4852 int ret = -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004853 int i;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004854 int was_ap = is_ap_interface(drv->nlmode);
4855 int res;
Dmitry Shmidtd30ac602014-06-30 09:54:22 -07004856 int mode_switch_res;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004857
Dmitry Shmidtd30ac602014-06-30 09:54:22 -07004858 mode_switch_res = nl80211_set_mode(drv, drv->ifindex, nlmode);
4859 if (mode_switch_res && nlmode == nl80211_get_ifmode(bss))
4860 mode_switch_res = 0;
Dmitry Shmidt34af3062013-07-11 10:46:32 -07004861
Dmitry Shmidtd30ac602014-06-30 09:54:22 -07004862 if (mode_switch_res == 0) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004863 drv->nlmode = nlmode;
4864 ret = 0;
4865 goto done;
4866 }
4867
Dmitry Shmidtd30ac602014-06-30 09:54:22 -07004868 if (mode_switch_res == -ENODEV)
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004869 return -1;
4870
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004871 if (nlmode == drv->nlmode) {
4872 wpa_printf(MSG_DEBUG, "nl80211: Interface already in "
4873 "requested mode - ignore error");
4874 ret = 0;
4875 goto done; /* Already in the requested mode */
4876 }
4877
4878 /* mac80211 doesn't allow mode changes while the device is up, so
4879 * take the device down, try to set the mode again, and bring the
4880 * device back up.
4881 */
4882 wpa_printf(MSG_DEBUG, "nl80211: Try mode change after setting "
4883 "interface down");
4884 for (i = 0; i < 10; i++) {
Dmitry Shmidt34af3062013-07-11 10:46:32 -07004885 res = i802_set_iface_flags(bss, 0);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004886 if (res == -EACCES || res == -ENODEV)
4887 break;
Dmitry Shmidtd30ac602014-06-30 09:54:22 -07004888 if (res != 0) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004889 wpa_printf(MSG_DEBUG, "nl80211: Failed to set "
4890 "interface down");
Dmitry Shmidtd30ac602014-06-30 09:54:22 -07004891 os_sleep(0, 100000);
4892 continue;
4893 }
4894
4895 /*
4896 * Setting the mode will fail for some drivers if the phy is
4897 * on a frequency that the mode is disallowed in.
4898 */
4899 if (desired_freq_params) {
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004900 res = nl80211_set_channel(bss, desired_freq_params, 0);
Dmitry Shmidtd30ac602014-06-30 09:54:22 -07004901 if (res) {
4902 wpa_printf(MSG_DEBUG,
4903 "nl80211: Failed to set frequency on interface");
4904 }
4905 }
4906
4907 /* Try to set the mode again while the interface is down */
4908 mode_switch_res = nl80211_set_mode(drv, drv->ifindex, nlmode);
4909 if (mode_switch_res == -EBUSY) {
4910 wpa_printf(MSG_DEBUG,
4911 "nl80211: Delaying mode set while interface going down");
4912 os_sleep(0, 100000);
4913 continue;
4914 }
4915 ret = mode_switch_res;
4916 break;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004917 }
4918
4919 if (!ret) {
4920 wpa_printf(MSG_DEBUG, "nl80211: Mode change succeeded while "
4921 "interface is down");
4922 drv->nlmode = nlmode;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004923 drv->ignore_if_down_event = 1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004924 }
4925
Dmitry Shmidtd30ac602014-06-30 09:54:22 -07004926 /* Bring the interface back up */
4927 res = linux_set_iface_flags(drv->global->ioctl_sock, bss->ifname, 1);
4928 if (res != 0) {
4929 wpa_printf(MSG_DEBUG,
4930 "nl80211: Failed to set interface up after switching mode");
4931 ret = -1;
4932 }
4933
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004934done:
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004935 if (ret) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004936 wpa_printf(MSG_DEBUG, "nl80211: Interface mode change to %d "
4937 "from %d failed", nlmode, drv->nlmode);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004938 return ret;
4939 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004940
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004941 if (is_p2p_net_interface(nlmode)) {
4942 wpa_printf(MSG_DEBUG,
4943 "nl80211: Interface %s mode change to P2P - disable 11b rates",
4944 bss->ifname);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07004945 nl80211_disable_11b_rates(drv, drv->ifindex, 1);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004946 } else if (drv->disabled_11b_rates) {
4947 wpa_printf(MSG_DEBUG,
4948 "nl80211: Interface %s mode changed to non-P2P - re-enable 11b rates",
4949 bss->ifname);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07004950 nl80211_disable_11b_rates(drv, drv->ifindex, 0);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004951 }
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07004952
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004953 if (is_ap_interface(nlmode)) {
4954 nl80211_mgmt_unsubscribe(bss, "start AP");
4955 /* Setup additional AP mode functionality if needed */
4956 if (nl80211_setup_ap(bss))
4957 return -1;
4958 } else if (was_ap) {
4959 /* Remove additional AP mode functionality */
4960 nl80211_teardown_ap(bss);
4961 } else {
4962 nl80211_mgmt_unsubscribe(bss, "mode change");
4963 }
4964
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004965 if (is_mesh_interface(nlmode) &&
4966 nl80211_mgmt_subscribe_mesh(bss))
4967 return -1;
4968
Dmitry Shmidt04949592012-07-19 12:16:46 -07004969 if (!bss->in_deinit && !is_ap_interface(nlmode) &&
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004970 !is_mesh_interface(nlmode) &&
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004971 nl80211_mgmt_subscribe_non_ap(bss) < 0)
4972 wpa_printf(MSG_DEBUG, "nl80211: Failed to register Action "
4973 "frame processing - ignore for now");
4974
4975 return 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004976}
4977
4978
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004979int wpa_driver_nl80211_set_mode(struct i802_bss *bss,
4980 enum nl80211_iftype nlmode)
Dmitry Shmidtd30ac602014-06-30 09:54:22 -07004981{
4982 return wpa_driver_nl80211_set_mode_impl(bss, nlmode, NULL);
4983}
4984
4985
Dmitry Shmidt9ead16e2014-10-07 13:15:23 -07004986static int wpa_driver_nl80211_set_mode_ibss(struct i802_bss *bss,
4987 struct hostapd_freq_params *freq)
Dmitry Shmidtd30ac602014-06-30 09:54:22 -07004988{
Dmitry Shmidtd30ac602014-06-30 09:54:22 -07004989 return wpa_driver_nl80211_set_mode_impl(bss, NL80211_IFTYPE_ADHOC,
Dmitry Shmidt9ead16e2014-10-07 13:15:23 -07004990 freq);
Dmitry Shmidtd30ac602014-06-30 09:54:22 -07004991}
4992
4993
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004994static int wpa_driver_nl80211_get_capa(void *priv,
4995 struct wpa_driver_capa *capa)
4996{
4997 struct i802_bss *bss = priv;
4998 struct wpa_driver_nl80211_data *drv = bss->drv;
Dmitry Shmidtd11f0192014-03-24 12:09:47 -07004999
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005000 if (!drv->has_capability)
5001 return -1;
5002 os_memcpy(capa, &drv->capa, sizeof(*capa));
Dmitry Shmidt444d5672013-04-01 13:08:44 -07005003 if (drv->extended_capa && drv->extended_capa_mask) {
5004 capa->extended_capa = drv->extended_capa;
5005 capa->extended_capa_mask = drv->extended_capa_mask;
5006 capa->extended_capa_len = drv->extended_capa_len;
5007 }
Dmitry Shmidt34af3062013-07-11 10:46:32 -07005008
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005009 return 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005010}
5011
5012
5013static int wpa_driver_nl80211_set_operstate(void *priv, int state)
5014{
5015 struct i802_bss *bss = priv;
5016 struct wpa_driver_nl80211_data *drv = bss->drv;
5017
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08005018 wpa_printf(MSG_DEBUG, "nl80211: Set %s operstate %d->%d (%s)",
5019 bss->ifname, drv->operstate, state,
5020 state ? "UP" : "DORMANT");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005021 drv->operstate = state;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005022 return netlink_send_oper_ifla(drv->global->netlink, drv->ifindex, -1,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005023 state ? IF_OPER_UP : IF_OPER_DORMANT);
5024}
5025
5026
5027static int wpa_driver_nl80211_set_supp_port(void *priv, int authorized)
5028{
5029 struct i802_bss *bss = priv;
5030 struct wpa_driver_nl80211_data *drv = bss->drv;
5031 struct nl_msg *msg;
5032 struct nl80211_sta_flag_update upd;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005033 int ret;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08005034
5035 if (!drv->associated && is_zero_ether_addr(drv->bssid) && !authorized) {
5036 wpa_printf(MSG_DEBUG, "nl80211: Skip set_supp_port(unauthorized) while not associated");
5037 return 0;
5038 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005039
Dmitry Shmidt8bae4132013-06-06 11:25:10 -07005040 wpa_printf(MSG_DEBUG, "nl80211: Set supplicant port %sauthorized for "
5041 MACSTR, authorized ? "" : "un", MAC2STR(drv->bssid));
5042
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005043 os_memset(&upd, 0, sizeof(upd));
5044 upd.mask = BIT(NL80211_STA_FLAG_AUTHORIZED);
5045 if (authorized)
5046 upd.set = BIT(NL80211_STA_FLAG_AUTHORIZED);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005047
5048 if (!(msg = nl80211_bss_msg(bss, 0, NL80211_CMD_SET_STATION)) ||
5049 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, drv->bssid) ||
5050 nla_put(msg, NL80211_ATTR_STA_FLAGS2, sizeof(upd), &upd)) {
5051 nlmsg_free(msg);
5052 return -ENOBUFS;
5053 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005054
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08005055 ret = send_and_recv_msgs(drv, msg, NULL, NULL);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08005056 if (!ret)
5057 return 0;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08005058 wpa_printf(MSG_DEBUG, "nl80211: Failed to set STA flag: %d (%s)",
5059 ret, strerror(-ret));
5060 return ret;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005061}
5062
5063
Jouni Malinen75ecf522011-06-27 15:19:46 -07005064/* Set kernel driver on given frequency (MHz) */
5065static int i802_set_freq(void *priv, struct hostapd_freq_params *freq)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005066{
Jouni Malinen75ecf522011-06-27 15:19:46 -07005067 struct i802_bss *bss = priv;
Dmitry Shmidt7832adb2014-04-29 10:53:02 -07005068 return nl80211_set_channel(bss, freq, 0);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005069}
5070
5071
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005072static inline int min_int(int a, int b)
5073{
5074 if (a < b)
5075 return a;
5076 return b;
5077}
5078
5079
5080static int get_key_handler(struct nl_msg *msg, void *arg)
5081{
5082 struct nlattr *tb[NL80211_ATTR_MAX + 1];
5083 struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg));
5084
5085 nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0),
5086 genlmsg_attrlen(gnlh, 0), NULL);
5087
5088 /*
5089 * TODO: validate the key index and mac address!
5090 * Otherwise, there's a race condition as soon as
5091 * the kernel starts sending key notifications.
5092 */
5093
5094 if (tb[NL80211_ATTR_KEY_SEQ])
5095 memcpy(arg, nla_data(tb[NL80211_ATTR_KEY_SEQ]),
5096 min_int(nla_len(tb[NL80211_ATTR_KEY_SEQ]), 6));
5097 return NL_SKIP;
5098}
5099
5100
5101static int i802_get_seqnum(const char *iface, void *priv, const u8 *addr,
5102 int idx, u8 *seq)
5103{
5104 struct i802_bss *bss = priv;
5105 struct wpa_driver_nl80211_data *drv = bss->drv;
5106 struct nl_msg *msg;
5107
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005108 msg = nl80211_ifindex_msg(drv, if_nametoindex(iface), 0,
5109 NL80211_CMD_GET_KEY);
5110 if (!msg ||
5111 (addr && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) ||
5112 nla_put_u8(msg, NL80211_ATTR_KEY_IDX, idx)) {
5113 nlmsg_free(msg);
5114 return -ENOBUFS;
5115 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005116
5117 memset(seq, 0, 6);
5118
5119 return send_and_recv_msgs(drv, msg, get_key_handler, seq);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005120}
5121
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005122
5123static int i802_set_rts(void *priv, int rts)
5124{
5125 struct i802_bss *bss = priv;
5126 struct wpa_driver_nl80211_data *drv = bss->drv;
5127 struct nl_msg *msg;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005128 int ret;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005129 u32 val;
5130
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005131 if (rts >= 2347)
5132 val = (u32) -1;
5133 else
5134 val = rts;
5135
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005136 if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_SET_WIPHY)) ||
5137 nla_put_u32(msg, NL80211_ATTR_WIPHY_RTS_THRESHOLD, val)) {
5138 nlmsg_free(msg);
5139 return -ENOBUFS;
5140 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005141
5142 ret = send_and_recv_msgs(drv, msg, NULL, NULL);
5143 if (!ret)
5144 return 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005145 wpa_printf(MSG_DEBUG, "nl80211: Failed to set RTS threshold %d: "
5146 "%d (%s)", rts, ret, strerror(-ret));
5147 return ret;
5148}
5149
5150
5151static int i802_set_frag(void *priv, int frag)
5152{
5153 struct i802_bss *bss = priv;
5154 struct wpa_driver_nl80211_data *drv = bss->drv;
5155 struct nl_msg *msg;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005156 int ret;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005157 u32 val;
5158
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005159 if (frag >= 2346)
5160 val = (u32) -1;
5161 else
5162 val = frag;
5163
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005164 if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_SET_WIPHY)) ||
5165 nla_put_u32(msg, NL80211_ATTR_WIPHY_FRAG_THRESHOLD, val)) {
5166 nlmsg_free(msg);
5167 return -ENOBUFS;
5168 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005169
5170 ret = send_and_recv_msgs(drv, msg, NULL, NULL);
5171 if (!ret)
5172 return 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005173 wpa_printf(MSG_DEBUG, "nl80211: Failed to set fragmentation threshold "
5174 "%d: %d (%s)", frag, ret, strerror(-ret));
5175 return ret;
5176}
5177
5178
5179static int i802_flush(void *priv)
5180{
5181 struct i802_bss *bss = priv;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005182 struct nl_msg *msg;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005183 int res;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005184
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -07005185 wpa_printf(MSG_DEBUG, "nl80211: flush -> DEL_STATION %s (all)",
5186 bss->ifname);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005187
5188 /*
5189 * XXX: FIX! this needs to flush all VLANs too
5190 */
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005191 msg = nl80211_bss_msg(bss, 0, NL80211_CMD_DEL_STATION);
5192 res = send_and_recv_msgs(bss->drv, msg, NULL, NULL);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005193 if (res) {
5194 wpa_printf(MSG_DEBUG, "nl80211: Station flush failed: ret=%d "
5195 "(%s)", res, strerror(-res));
5196 }
5197 return res;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005198}
5199
5200
5201static int get_sta_handler(struct nl_msg *msg, void *arg)
5202{
5203 struct nlattr *tb[NL80211_ATTR_MAX + 1];
5204 struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg));
5205 struct hostap_sta_driver_data *data = arg;
5206 struct nlattr *stats[NL80211_STA_INFO_MAX + 1];
5207 static struct nla_policy stats_policy[NL80211_STA_INFO_MAX + 1] = {
5208 [NL80211_STA_INFO_INACTIVE_TIME] = { .type = NLA_U32 },
5209 [NL80211_STA_INFO_RX_BYTES] = { .type = NLA_U32 },
5210 [NL80211_STA_INFO_TX_BYTES] = { .type = NLA_U32 },
5211 [NL80211_STA_INFO_RX_PACKETS] = { .type = NLA_U32 },
5212 [NL80211_STA_INFO_TX_PACKETS] = { .type = NLA_U32 },
Jouni Malinen1e6c57f2012-09-05 17:07:03 +03005213 [NL80211_STA_INFO_TX_FAILED] = { .type = NLA_U32 },
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005214 };
5215
5216 nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0),
5217 genlmsg_attrlen(gnlh, 0), NULL);
5218
5219 /*
5220 * TODO: validate the interface and mac address!
5221 * Otherwise, there's a race condition as soon as
5222 * the kernel starts sending station notifications.
5223 */
5224
5225 if (!tb[NL80211_ATTR_STA_INFO]) {
5226 wpa_printf(MSG_DEBUG, "sta stats missing!");
5227 return NL_SKIP;
5228 }
5229 if (nla_parse_nested(stats, NL80211_STA_INFO_MAX,
5230 tb[NL80211_ATTR_STA_INFO],
5231 stats_policy)) {
5232 wpa_printf(MSG_DEBUG, "failed to parse nested attributes!");
5233 return NL_SKIP;
5234 }
5235
5236 if (stats[NL80211_STA_INFO_INACTIVE_TIME])
5237 data->inactive_msec =
5238 nla_get_u32(stats[NL80211_STA_INFO_INACTIVE_TIME]);
5239 if (stats[NL80211_STA_INFO_RX_BYTES])
5240 data->rx_bytes = nla_get_u32(stats[NL80211_STA_INFO_RX_BYTES]);
5241 if (stats[NL80211_STA_INFO_TX_BYTES])
5242 data->tx_bytes = nla_get_u32(stats[NL80211_STA_INFO_TX_BYTES]);
5243 if (stats[NL80211_STA_INFO_RX_PACKETS])
5244 data->rx_packets =
5245 nla_get_u32(stats[NL80211_STA_INFO_RX_PACKETS]);
5246 if (stats[NL80211_STA_INFO_TX_PACKETS])
5247 data->tx_packets =
5248 nla_get_u32(stats[NL80211_STA_INFO_TX_PACKETS]);
Jouni Malinen1e6c57f2012-09-05 17:07:03 +03005249 if (stats[NL80211_STA_INFO_TX_FAILED])
5250 data->tx_retry_failed =
5251 nla_get_u32(stats[NL80211_STA_INFO_TX_FAILED]);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005252
5253 return NL_SKIP;
5254}
5255
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08005256static int i802_read_sta_data(struct i802_bss *bss,
5257 struct hostap_sta_driver_data *data,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005258 const u8 *addr)
5259{
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005260 struct nl_msg *msg;
5261
5262 os_memset(data, 0, sizeof(*data));
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005263
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005264 if (!(msg = nl80211_bss_msg(bss, 0, NL80211_CMD_GET_STATION)) ||
5265 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) {
5266 nlmsg_free(msg);
5267 return -ENOBUFS;
5268 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005269
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005270 return send_and_recv_msgs(bss->drv, msg, get_sta_handler, data);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005271}
5272
5273
5274static int i802_set_tx_queue_params(void *priv, int queue, int aifs,
5275 int cw_min, int cw_max, int burst_time)
5276{
5277 struct i802_bss *bss = priv;
5278 struct wpa_driver_nl80211_data *drv = bss->drv;
5279 struct nl_msg *msg;
5280 struct nlattr *txq, *params;
5281
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005282 msg = nl80211_bss_msg(bss, 0, NL80211_CMD_SET_WIPHY);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005283 if (!msg)
5284 return -1;
5285
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005286 txq = nla_nest_start(msg, NL80211_ATTR_WIPHY_TXQ_PARAMS);
5287 if (!txq)
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005288 goto fail;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005289
5290 /* We are only sending parameters for a single TXQ at a time */
5291 params = nla_nest_start(msg, 1);
5292 if (!params)
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005293 goto fail;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005294
5295 switch (queue) {
5296 case 0:
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005297 if (nla_put_u8(msg, NL80211_TXQ_ATTR_QUEUE, NL80211_TXQ_Q_VO))
5298 goto fail;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005299 break;
5300 case 1:
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005301 if (nla_put_u8(msg, NL80211_TXQ_ATTR_QUEUE, NL80211_TXQ_Q_VI))
5302 goto fail;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005303 break;
5304 case 2:
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005305 if (nla_put_u8(msg, NL80211_TXQ_ATTR_QUEUE, NL80211_TXQ_Q_BE))
5306 goto fail;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005307 break;
5308 case 3:
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005309 if (nla_put_u8(msg, NL80211_TXQ_ATTR_QUEUE, NL80211_TXQ_Q_BK))
5310 goto fail;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005311 break;
5312 }
5313 /* Burst time is configured in units of 0.1 msec and TXOP parameter in
5314 * 32 usec, so need to convert the value here. */
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005315 if (nla_put_u16(msg, NL80211_TXQ_ATTR_TXOP,
5316 (burst_time * 100 + 16) / 32) ||
5317 nla_put_u16(msg, NL80211_TXQ_ATTR_CWMIN, cw_min) ||
5318 nla_put_u16(msg, NL80211_TXQ_ATTR_CWMAX, cw_max) ||
5319 nla_put_u8(msg, NL80211_TXQ_ATTR_AIFS, aifs))
5320 goto fail;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005321
5322 nla_nest_end(msg, params);
5323
5324 nla_nest_end(msg, txq);
5325
5326 if (send_and_recv_msgs(drv, msg, NULL, NULL) == 0)
5327 return 0;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005328 msg = NULL;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005329fail:
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005330 nlmsg_free(msg);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005331 return -1;
5332}
5333
5334
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08005335static int i802_set_sta_vlan(struct i802_bss *bss, const u8 *addr,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005336 const char *ifname, int vlan_id)
5337{
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005338 struct wpa_driver_nl80211_data *drv = bss->drv;
5339 struct nl_msg *msg;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005340 int ret;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005341
Dmitry Shmidtcce06662013-11-04 18:44:24 -08005342 wpa_printf(MSG_DEBUG, "nl80211: %s[%d]: set_sta_vlan(" MACSTR
5343 ", ifname=%s[%d], vlan_id=%d)",
5344 bss->ifname, if_nametoindex(bss->ifname),
5345 MAC2STR(addr), ifname, if_nametoindex(ifname), vlan_id);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005346 if (!(msg = nl80211_bss_msg(bss, 0, NL80211_CMD_SET_STATION)) ||
5347 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) ||
5348 nla_put_u32(msg, NL80211_ATTR_STA_VLAN, if_nametoindex(ifname))) {
5349 nlmsg_free(msg);
5350 return -ENOBUFS;
5351 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005352
5353 ret = send_and_recv_msgs(drv, msg, NULL, NULL);
5354 if (ret < 0) {
5355 wpa_printf(MSG_ERROR, "nl80211: NL80211_ATTR_STA_VLAN (addr="
5356 MACSTR " ifname=%s vlan_id=%d) failed: %d (%s)",
5357 MAC2STR(addr), ifname, vlan_id, ret,
5358 strerror(-ret));
5359 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005360 return ret;
5361}
5362
5363
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005364static int i802_get_inact_sec(void *priv, const u8 *addr)
5365{
5366 struct hostap_sta_driver_data data;
5367 int ret;
5368
5369 data.inactive_msec = (unsigned long) -1;
5370 ret = i802_read_sta_data(priv, &data, addr);
Dmitry Shmidt2f74e362015-01-21 13:19:05 -08005371 if (ret == -ENOENT)
5372 return -ENOENT;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005373 if (ret || data.inactive_msec == (unsigned long) -1)
5374 return -1;
5375 return data.inactive_msec / 1000;
5376}
5377
5378
5379static int i802_sta_clear_stats(void *priv, const u8 *addr)
5380{
5381#if 0
5382 /* TODO */
5383#endif
5384 return 0;
5385}
5386
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005387
5388static int i802_sta_deauth(void *priv, const u8 *own_addr, const u8 *addr,
5389 int reason)
5390{
5391 struct i802_bss *bss = priv;
Dmitry Shmidt04949592012-07-19 12:16:46 -07005392 struct wpa_driver_nl80211_data *drv = bss->drv;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005393 struct ieee80211_mgmt mgmt;
5394
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005395 if (is_mesh_interface(drv->nlmode))
5396 return -1;
5397
Dmitry Shmidt04949592012-07-19 12:16:46 -07005398 if (drv->device_ap_sme)
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005399 return wpa_driver_nl80211_sta_remove(bss, addr, 1, reason);
Dmitry Shmidt04949592012-07-19 12:16:46 -07005400
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005401 memset(&mgmt, 0, sizeof(mgmt));
5402 mgmt.frame_control = IEEE80211_FC(WLAN_FC_TYPE_MGMT,
5403 WLAN_FC_STYPE_DEAUTH);
5404 memcpy(mgmt.da, addr, ETH_ALEN);
5405 memcpy(mgmt.sa, own_addr, ETH_ALEN);
5406 memcpy(mgmt.bssid, own_addr, ETH_ALEN);
5407 mgmt.u.deauth.reason_code = host_to_le16(reason);
5408 return wpa_driver_nl80211_send_mlme(bss, (u8 *) &mgmt,
5409 IEEE80211_HDRLEN +
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08005410 sizeof(mgmt.u.deauth), 0, 0, 0, 0,
5411 0);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005412}
5413
5414
5415static int i802_sta_disassoc(void *priv, const u8 *own_addr, const u8 *addr,
5416 int reason)
5417{
5418 struct i802_bss *bss = priv;
Dmitry Shmidt04949592012-07-19 12:16:46 -07005419 struct wpa_driver_nl80211_data *drv = bss->drv;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005420 struct ieee80211_mgmt mgmt;
5421
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005422 if (is_mesh_interface(drv->nlmode))
5423 return -1;
5424
Dmitry Shmidt04949592012-07-19 12:16:46 -07005425 if (drv->device_ap_sme)
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005426 return wpa_driver_nl80211_sta_remove(bss, addr, 0, reason);
Dmitry Shmidt04949592012-07-19 12:16:46 -07005427
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005428 memset(&mgmt, 0, sizeof(mgmt));
5429 mgmt.frame_control = IEEE80211_FC(WLAN_FC_TYPE_MGMT,
5430 WLAN_FC_STYPE_DISASSOC);
5431 memcpy(mgmt.da, addr, ETH_ALEN);
5432 memcpy(mgmt.sa, own_addr, ETH_ALEN);
5433 memcpy(mgmt.bssid, own_addr, ETH_ALEN);
5434 mgmt.u.disassoc.reason_code = host_to_le16(reason);
5435 return wpa_driver_nl80211_send_mlme(bss, (u8 *) &mgmt,
5436 IEEE80211_HDRLEN +
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08005437 sizeof(mgmt.u.disassoc), 0, 0, 0, 0,
5438 0);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005439}
5440
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005441
Dmitry Shmidtdf5a7e42014-04-02 12:59:59 -07005442static void dump_ifidx(struct wpa_driver_nl80211_data *drv)
5443{
5444 char buf[200], *pos, *end;
5445 int i, res;
5446
5447 pos = buf;
5448 end = pos + sizeof(buf);
5449
5450 for (i = 0; i < drv->num_if_indices; i++) {
5451 if (!drv->if_indices[i])
5452 continue;
5453 res = os_snprintf(pos, end - pos, " %d", drv->if_indices[i]);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005454 if (os_snprintf_error(end - pos, res))
Dmitry Shmidtdf5a7e42014-04-02 12:59:59 -07005455 break;
5456 pos += res;
5457 }
5458 *pos = '\0';
5459
5460 wpa_printf(MSG_DEBUG, "nl80211: if_indices[%d]:%s",
5461 drv->num_if_indices, buf);
5462}
5463
5464
Jouni Malinen75ecf522011-06-27 15:19:46 -07005465static void add_ifidx(struct wpa_driver_nl80211_data *drv, int ifidx)
5466{
5467 int i;
5468 int *old;
5469
5470 wpa_printf(MSG_DEBUG, "nl80211: Add own interface ifindex %d",
5471 ifidx);
Dmitry Shmidtdf5a7e42014-04-02 12:59:59 -07005472 if (have_ifidx(drv, ifidx)) {
5473 wpa_printf(MSG_DEBUG, "nl80211: ifindex %d already in the list",
5474 ifidx);
5475 return;
5476 }
Jouni Malinen75ecf522011-06-27 15:19:46 -07005477 for (i = 0; i < drv->num_if_indices; i++) {
5478 if (drv->if_indices[i] == 0) {
5479 drv->if_indices[i] = ifidx;
Dmitry Shmidtdf5a7e42014-04-02 12:59:59 -07005480 dump_ifidx(drv);
Jouni Malinen75ecf522011-06-27 15:19:46 -07005481 return;
5482 }
5483 }
5484
5485 if (drv->if_indices != drv->default_if_indices)
5486 old = drv->if_indices;
5487 else
5488 old = NULL;
5489
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07005490 drv->if_indices = os_realloc_array(old, drv->num_if_indices + 1,
5491 sizeof(int));
Jouni Malinen75ecf522011-06-27 15:19:46 -07005492 if (!drv->if_indices) {
5493 if (!old)
5494 drv->if_indices = drv->default_if_indices;
5495 else
5496 drv->if_indices = old;
5497 wpa_printf(MSG_ERROR, "Failed to reallocate memory for "
5498 "interfaces");
5499 wpa_printf(MSG_ERROR, "Ignoring EAPOL on interface %d", ifidx);
5500 return;
5501 } else if (!old)
5502 os_memcpy(drv->if_indices, drv->default_if_indices,
5503 sizeof(drv->default_if_indices));
5504 drv->if_indices[drv->num_if_indices] = ifidx;
5505 drv->num_if_indices++;
Dmitry Shmidtdf5a7e42014-04-02 12:59:59 -07005506 dump_ifidx(drv);
Jouni Malinen75ecf522011-06-27 15:19:46 -07005507}
5508
5509
5510static void del_ifidx(struct wpa_driver_nl80211_data *drv, int ifidx)
5511{
5512 int i;
5513
5514 for (i = 0; i < drv->num_if_indices; i++) {
5515 if (drv->if_indices[i] == ifidx) {
5516 drv->if_indices[i] = 0;
5517 break;
5518 }
5519 }
Dmitry Shmidtdf5a7e42014-04-02 12:59:59 -07005520 dump_ifidx(drv);
Jouni Malinen75ecf522011-06-27 15:19:46 -07005521}
5522
5523
5524static int have_ifidx(struct wpa_driver_nl80211_data *drv, int ifidx)
5525{
5526 int i;
5527
5528 for (i = 0; i < drv->num_if_indices; i++)
5529 if (drv->if_indices[i] == ifidx)
5530 return 1;
5531
5532 return 0;
5533}
5534
5535
5536static int i802_set_wds_sta(void *priv, const u8 *addr, int aid, int val,
Dmitry Shmidt7832adb2014-04-29 10:53:02 -07005537 const char *bridge_ifname, char *ifname_wds)
Jouni Malinen75ecf522011-06-27 15:19:46 -07005538{
5539 struct i802_bss *bss = priv;
5540 struct wpa_driver_nl80211_data *drv = bss->drv;
5541 char name[IFNAMSIZ + 1];
5542
5543 os_snprintf(name, sizeof(name), "%s.sta%d", bss->ifname, aid);
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07005544 if (ifname_wds)
5545 os_strlcpy(ifname_wds, name, IFNAMSIZ + 1);
5546
Jouni Malinen75ecf522011-06-27 15:19:46 -07005547 wpa_printf(MSG_DEBUG, "nl80211: Set WDS STA addr=" MACSTR
5548 " aid=%d val=%d name=%s", MAC2STR(addr), aid, val, name);
5549 if (val) {
5550 if (!if_nametoindex(name)) {
5551 if (nl80211_create_iface(drv, name,
5552 NL80211_IFTYPE_AP_VLAN,
Dmitry Shmidtcce06662013-11-04 18:44:24 -08005553 bss->addr, 1, NULL, NULL, 0) <
5554 0)
Jouni Malinen75ecf522011-06-27 15:19:46 -07005555 return -1;
5556 if (bridge_ifname &&
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005557 linux_br_add_if(drv->global->ioctl_sock,
5558 bridge_ifname, name) < 0)
Jouni Malinen75ecf522011-06-27 15:19:46 -07005559 return -1;
5560 }
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07005561 if (linux_set_iface_flags(drv->global->ioctl_sock, name, 1)) {
5562 wpa_printf(MSG_ERROR, "nl80211: Failed to set WDS STA "
5563 "interface %s up", name);
5564 }
Jouni Malinen75ecf522011-06-27 15:19:46 -07005565 return i802_set_sta_vlan(priv, addr, name, 0);
5566 } else {
Dmitry Shmidtaa532512012-09-24 10:35:31 -07005567 if (bridge_ifname)
5568 linux_br_del_if(drv->global->ioctl_sock, bridge_ifname,
5569 name);
5570
Jouni Malinen75ecf522011-06-27 15:19:46 -07005571 i802_set_sta_vlan(priv, addr, bss->ifname, 0);
Dmitry Shmidta38abf92014-03-06 13:38:44 -08005572 nl80211_remove_iface(drv, if_nametoindex(name));
5573 return 0;
Jouni Malinen75ecf522011-06-27 15:19:46 -07005574 }
5575}
5576
5577
5578static void handle_eapol(int sock, void *eloop_ctx, void *sock_ctx)
5579{
5580 struct wpa_driver_nl80211_data *drv = eloop_ctx;
5581 struct sockaddr_ll lladdr;
5582 unsigned char buf[3000];
5583 int len;
5584 socklen_t fromlen = sizeof(lladdr);
5585
5586 len = recvfrom(sock, buf, sizeof(buf), 0,
5587 (struct sockaddr *)&lladdr, &fromlen);
5588 if (len < 0) {
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -07005589 wpa_printf(MSG_ERROR, "nl80211: EAPOL recv failed: %s",
5590 strerror(errno));
Jouni Malinen75ecf522011-06-27 15:19:46 -07005591 return;
5592 }
5593
5594 if (have_ifidx(drv, lladdr.sll_ifindex))
5595 drv_event_eapol_rx(drv->ctx, lladdr.sll_addr, buf, len);
5596}
5597
5598
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005599static int i802_check_bridge(struct wpa_driver_nl80211_data *drv,
5600 struct i802_bss *bss,
5601 const char *brname, const char *ifname)
5602{
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005603 int br_ifindex;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005604 char in_br[IFNAMSIZ];
5605
5606 os_strlcpy(bss->brname, brname, IFNAMSIZ);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005607 br_ifindex = if_nametoindex(brname);
5608 if (br_ifindex == 0) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005609 /*
5610 * Bridge was configured, but the bridge device does
5611 * not exist. Try to add it now.
5612 */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005613 if (linux_br_add(drv->global->ioctl_sock, brname) < 0) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005614 wpa_printf(MSG_ERROR, "nl80211: Failed to add the "
5615 "bridge interface %s: %s",
5616 brname, strerror(errno));
5617 return -1;
5618 }
5619 bss->added_bridge = 1;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005620 br_ifindex = if_nametoindex(brname);
5621 add_ifidx(drv, br_ifindex);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005622 }
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005623 bss->br_ifindex = br_ifindex;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005624
5625 if (linux_br_get(in_br, ifname) == 0) {
5626 if (os_strcmp(in_br, brname) == 0)
5627 return 0; /* already in the bridge */
5628
5629 wpa_printf(MSG_DEBUG, "nl80211: Removing interface %s from "
5630 "bridge %s", ifname, in_br);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005631 if (linux_br_del_if(drv->global->ioctl_sock, in_br, ifname) <
5632 0) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005633 wpa_printf(MSG_ERROR, "nl80211: Failed to "
5634 "remove interface %s from bridge "
5635 "%s: %s",
5636 ifname, brname, strerror(errno));
5637 return -1;
5638 }
5639 }
5640
5641 wpa_printf(MSG_DEBUG, "nl80211: Adding interface %s into bridge %s",
5642 ifname, brname);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005643 if (linux_br_add_if(drv->global->ioctl_sock, brname, ifname) < 0) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005644 wpa_printf(MSG_ERROR, "nl80211: Failed to add interface %s "
5645 "into bridge %s: %s",
5646 ifname, brname, strerror(errno));
5647 return -1;
5648 }
5649 bss->added_if_into_bridge = 1;
5650
5651 return 0;
5652}
5653
5654
5655static void *i802_init(struct hostapd_data *hapd,
5656 struct wpa_init_params *params)
5657{
5658 struct wpa_driver_nl80211_data *drv;
5659 struct i802_bss *bss;
5660 size_t i;
5661 char brname[IFNAMSIZ];
5662 int ifindex, br_ifindex;
5663 int br_added = 0;
5664
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08005665 bss = wpa_driver_nl80211_drv_init(hapd, params->ifname,
5666 params->global_priv, 1,
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005667 params->bssid, params->driver_params);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005668 if (bss == NULL)
5669 return NULL;
5670
5671 drv = bss->drv;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005672
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005673 if (linux_br_get(brname, params->ifname) == 0) {
5674 wpa_printf(MSG_DEBUG, "nl80211: Interface %s is in bridge %s",
5675 params->ifname, brname);
5676 br_ifindex = if_nametoindex(brname);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005677 os_strlcpy(bss->brname, brname, IFNAMSIZ);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005678 } else {
5679 brname[0] = '\0';
5680 br_ifindex = 0;
5681 }
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005682 bss->br_ifindex = br_ifindex;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005683
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005684 for (i = 0; i < params->num_bridge; i++) {
5685 if (params->bridge[i]) {
5686 ifindex = if_nametoindex(params->bridge[i]);
5687 if (ifindex)
5688 add_ifidx(drv, ifindex);
5689 if (ifindex == br_ifindex)
5690 br_added = 1;
5691 }
5692 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005693
5694 /* start listening for EAPOL on the default AP interface */
5695 add_ifidx(drv, drv->ifindex);
5696
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005697 if (params->num_bridge && params->bridge[0]) {
5698 if (i802_check_bridge(drv, bss, params->bridge[0],
5699 params->ifname) < 0)
5700 goto failed;
5701 if (os_strcmp(params->bridge[0], brname) != 0)
5702 br_added = 1;
5703 }
5704
5705 if (!br_added && br_ifindex &&
5706 (params->num_bridge == 0 || !params->bridge[0]))
5707 add_ifidx(drv, br_ifindex);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005708
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07005709#ifdef CONFIG_LIBNL3_ROUTE
5710 if (bss->added_if_into_bridge) {
5711 drv->rtnl_sk = nl_socket_alloc();
5712 if (drv->rtnl_sk == NULL) {
5713 wpa_printf(MSG_ERROR, "nl80211: Failed to allocate nl_sock");
5714 goto failed;
5715 }
5716
5717 if (nl_connect(drv->rtnl_sk, NETLINK_ROUTE)) {
5718 wpa_printf(MSG_ERROR, "nl80211: Failed to connect nl_sock to NETLINK_ROUTE: %s",
5719 strerror(errno));
5720 goto failed;
5721 }
5722 }
5723#endif /* CONFIG_LIBNL3_ROUTE */
5724
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005725 drv->eapol_sock = socket(PF_PACKET, SOCK_DGRAM, htons(ETH_P_PAE));
5726 if (drv->eapol_sock < 0) {
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -07005727 wpa_printf(MSG_ERROR, "nl80211: socket(PF_PACKET, SOCK_DGRAM, ETH_P_PAE) failed: %s",
5728 strerror(errno));
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005729 goto failed;
5730 }
5731
5732 if (eloop_register_read_sock(drv->eapol_sock, handle_eapol, drv, NULL))
5733 {
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -07005734 wpa_printf(MSG_INFO, "nl80211: Could not register read socket for eapol");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005735 goto failed;
5736 }
5737
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005738 if (linux_get_ifhwaddr(drv->global->ioctl_sock, bss->ifname,
5739 params->own_addr))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005740 goto failed;
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07005741 os_memcpy(drv->perm_addr, params->own_addr, ETH_ALEN);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005742
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005743 memcpy(bss->addr, params->own_addr, ETH_ALEN);
5744
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005745 return bss;
5746
5747failed:
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005748 wpa_driver_nl80211_deinit(bss);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005749 return NULL;
5750}
5751
5752
5753static void i802_deinit(void *priv)
5754{
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08005755 struct i802_bss *bss = priv;
5756 wpa_driver_nl80211_deinit(bss);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005757}
5758
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005759
5760static enum nl80211_iftype wpa_driver_nl80211_if_type(
5761 enum wpa_driver_if_type type)
5762{
5763 switch (type) {
5764 case WPA_IF_STATION:
5765 return NL80211_IFTYPE_STATION;
5766 case WPA_IF_P2P_CLIENT:
5767 case WPA_IF_P2P_GROUP:
5768 return NL80211_IFTYPE_P2P_CLIENT;
5769 case WPA_IF_AP_VLAN:
5770 return NL80211_IFTYPE_AP_VLAN;
5771 case WPA_IF_AP_BSS:
5772 return NL80211_IFTYPE_AP;
5773 case WPA_IF_P2P_GO:
5774 return NL80211_IFTYPE_P2P_GO;
Dmitry Shmidt34af3062013-07-11 10:46:32 -07005775 case WPA_IF_P2P_DEVICE:
5776 return NL80211_IFTYPE_P2P_DEVICE;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005777 case WPA_IF_MESH:
5778 return NL80211_IFTYPE_MESH_POINT;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005779 }
5780 return -1;
5781}
5782
5783
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005784#if defined(CONFIG_P2P) || defined(CONFIG_MESH)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005785
5786static int nl80211_addr_in_use(struct nl80211_global *global, const u8 *addr)
5787{
5788 struct wpa_driver_nl80211_data *drv;
5789 dl_list_for_each(drv, &global->interfaces,
5790 struct wpa_driver_nl80211_data, list) {
Dmitry Shmidtcce06662013-11-04 18:44:24 -08005791 if (os_memcmp(addr, drv->first_bss->addr, ETH_ALEN) == 0)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005792 return 1;
5793 }
5794 return 0;
5795}
5796
5797
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005798static int nl80211_vif_addr(struct wpa_driver_nl80211_data *drv, u8 *new_addr)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005799{
5800 unsigned int idx;
5801
5802 if (!drv->global)
5803 return -1;
5804
Dmitry Shmidtcce06662013-11-04 18:44:24 -08005805 os_memcpy(new_addr, drv->first_bss->addr, ETH_ALEN);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005806 for (idx = 0; idx < 64; idx++) {
Dmitry Shmidtcce06662013-11-04 18:44:24 -08005807 new_addr[0] = drv->first_bss->addr[0] | 0x02;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005808 new_addr[0] ^= idx << 2;
5809 if (!nl80211_addr_in_use(drv->global, new_addr))
5810 break;
5811 }
5812 if (idx == 64)
5813 return -1;
5814
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005815 wpa_printf(MSG_DEBUG, "nl80211: Assigned new virtual interface address "
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005816 MACSTR, MAC2STR(new_addr));
5817
5818 return 0;
5819}
5820
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005821#endif /* CONFIG_P2P || CONFIG_MESH */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005822
5823
Dmitry Shmidt34af3062013-07-11 10:46:32 -07005824struct wdev_info {
5825 u64 wdev_id;
5826 int wdev_id_set;
5827 u8 macaddr[ETH_ALEN];
5828};
5829
5830static int nl80211_wdev_handler(struct nl_msg *msg, void *arg)
5831{
5832 struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg));
5833 struct nlattr *tb[NL80211_ATTR_MAX + 1];
5834 struct wdev_info *wi = arg;
5835
5836 nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0),
5837 genlmsg_attrlen(gnlh, 0), NULL);
5838 if (tb[NL80211_ATTR_WDEV]) {
5839 wi->wdev_id = nla_get_u64(tb[NL80211_ATTR_WDEV]);
5840 wi->wdev_id_set = 1;
5841 }
5842
5843 if (tb[NL80211_ATTR_MAC])
5844 os_memcpy(wi->macaddr, nla_data(tb[NL80211_ATTR_MAC]),
5845 ETH_ALEN);
5846
5847 return NL_SKIP;
5848}
5849
5850
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005851static int wpa_driver_nl80211_if_add(void *priv, enum wpa_driver_if_type type,
5852 const char *ifname, const u8 *addr,
5853 void *bss_ctx, void **drv_priv,
5854 char *force_ifname, u8 *if_addr,
Dmitry Shmidtcce06662013-11-04 18:44:24 -08005855 const char *bridge, int use_existing)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005856{
Dmitry Shmidt34af3062013-07-11 10:46:32 -07005857 enum nl80211_iftype nlmode;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005858 struct i802_bss *bss = priv;
5859 struct wpa_driver_nl80211_data *drv = bss->drv;
5860 int ifidx;
Dmitry Shmidtcce06662013-11-04 18:44:24 -08005861 int added = 1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005862
5863 if (addr)
5864 os_memcpy(if_addr, addr, ETH_ALEN);
Dmitry Shmidt34af3062013-07-11 10:46:32 -07005865 nlmode = wpa_driver_nl80211_if_type(type);
5866 if (nlmode == NL80211_IFTYPE_P2P_DEVICE) {
5867 struct wdev_info p2pdev_info;
5868
5869 os_memset(&p2pdev_info, 0, sizeof(p2pdev_info));
5870 ifidx = nl80211_create_iface(drv, ifname, nlmode, addr,
5871 0, nl80211_wdev_handler,
Dmitry Shmidtcce06662013-11-04 18:44:24 -08005872 &p2pdev_info, use_existing);
Dmitry Shmidt34af3062013-07-11 10:46:32 -07005873 if (!p2pdev_info.wdev_id_set || ifidx != 0) {
5874 wpa_printf(MSG_ERROR, "nl80211: Failed to create a P2P Device interface %s",
5875 ifname);
5876 return -1;
5877 }
5878
5879 drv->global->if_add_wdevid = p2pdev_info.wdev_id;
5880 drv->global->if_add_wdevid_set = p2pdev_info.wdev_id_set;
5881 if (!is_zero_ether_addr(p2pdev_info.macaddr))
5882 os_memcpy(if_addr, p2pdev_info.macaddr, ETH_ALEN);
5883 wpa_printf(MSG_DEBUG, "nl80211: New P2P Device interface %s (0x%llx) created",
5884 ifname,
5885 (long long unsigned int) p2pdev_info.wdev_id);
5886 } else {
5887 ifidx = nl80211_create_iface(drv, ifname, nlmode, addr,
Dmitry Shmidtcce06662013-11-04 18:44:24 -08005888 0, NULL, NULL, use_existing);
5889 if (use_existing && ifidx == -ENFILE) {
5890 added = 0;
5891 ifidx = if_nametoindex(ifname);
5892 } else if (ifidx < 0) {
Dmitry Shmidt34af3062013-07-11 10:46:32 -07005893 return -1;
5894 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005895 }
5896
Dmitry Shmidt34af3062013-07-11 10:46:32 -07005897 if (!addr) {
5898 if (drv->nlmode == NL80211_IFTYPE_P2P_DEVICE)
5899 os_memcpy(if_addr, bss->addr, ETH_ALEN);
5900 else if (linux_get_ifhwaddr(drv->global->ioctl_sock,
5901 bss->ifname, if_addr) < 0) {
Dmitry Shmidtcce06662013-11-04 18:44:24 -08005902 if (added)
5903 nl80211_remove_iface(drv, ifidx);
Dmitry Shmidt34af3062013-07-11 10:46:32 -07005904 return -1;
5905 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005906 }
5907
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005908#if defined(CONFIG_P2P) || defined(CONFIG_MESH)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005909 if (!addr &&
5910 (type == WPA_IF_P2P_CLIENT || type == WPA_IF_P2P_GROUP ||
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005911 type == WPA_IF_P2P_GO || type == WPA_IF_MESH)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005912 /* Enforce unique P2P Interface Address */
Dmitry Shmidt34af3062013-07-11 10:46:32 -07005913 u8 new_addr[ETH_ALEN];
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005914
Dmitry Shmidt34af3062013-07-11 10:46:32 -07005915 if (linux_get_ifhwaddr(drv->global->ioctl_sock, ifname,
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005916 new_addr) < 0) {
Dmitry Shmidt71757432014-06-02 13:50:35 -07005917 if (added)
5918 nl80211_remove_iface(drv, ifidx);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005919 return -1;
5920 }
Dmitry Shmidt34af3062013-07-11 10:46:32 -07005921 if (nl80211_addr_in_use(drv->global, new_addr)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005922 wpa_printf(MSG_DEBUG, "nl80211: Allocate new address "
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005923 "for %s interface", type == WPA_IF_MESH ?
5924 "mesh" : "P2P group");
5925 if (nl80211_vif_addr(drv, new_addr) < 0) {
Dmitry Shmidt71757432014-06-02 13:50:35 -07005926 if (added)
5927 nl80211_remove_iface(drv, ifidx);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005928 return -1;
5929 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005930 if (linux_set_ifhwaddr(drv->global->ioctl_sock, ifname,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005931 new_addr) < 0) {
Dmitry Shmidt71757432014-06-02 13:50:35 -07005932 if (added)
5933 nl80211_remove_iface(drv, ifidx);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005934 return -1;
5935 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005936 }
Dmitry Shmidt6e933c12011-09-27 12:29:26 -07005937 os_memcpy(if_addr, new_addr, ETH_ALEN);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005938 }
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005939#endif /* CONFIG_P2P || CONFIG_MESH */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005940
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005941 if (type == WPA_IF_AP_BSS) {
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -07005942 struct i802_bss *new_bss = os_zalloc(sizeof(*new_bss));
5943 if (new_bss == NULL) {
Dmitry Shmidtcce06662013-11-04 18:44:24 -08005944 if (added)
5945 nl80211_remove_iface(drv, ifidx);
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -07005946 return -1;
5947 }
5948
5949 if (bridge &&
5950 i802_check_bridge(drv, new_bss, bridge, ifname) < 0) {
5951 wpa_printf(MSG_ERROR, "nl80211: Failed to add the new "
5952 "interface %s to a bridge %s",
5953 ifname, bridge);
Dmitry Shmidtcce06662013-11-04 18:44:24 -08005954 if (added)
5955 nl80211_remove_iface(drv, ifidx);
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -07005956 os_free(new_bss);
5957 return -1;
5958 }
5959
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005960 if (linux_set_iface_flags(drv->global->ioctl_sock, ifname, 1))
5961 {
Dmitry Shmidt71757432014-06-02 13:50:35 -07005962 if (added)
5963 nl80211_remove_iface(drv, ifidx);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005964 os_free(new_bss);
5965 return -1;
5966 }
5967 os_strlcpy(new_bss->ifname, ifname, IFNAMSIZ);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005968 os_memcpy(new_bss->addr, if_addr, ETH_ALEN);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005969 new_bss->ifindex = ifidx;
5970 new_bss->drv = drv;
Dmitry Shmidtcce06662013-11-04 18:44:24 -08005971 new_bss->next = drv->first_bss->next;
5972 new_bss->freq = drv->first_bss->freq;
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08005973 new_bss->ctx = bss_ctx;
Dmitry Shmidtcce06662013-11-04 18:44:24 -08005974 new_bss->added_if = added;
5975 drv->first_bss->next = new_bss;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005976 if (drv_priv)
5977 *drv_priv = new_bss;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005978 nl80211_init_bss(new_bss);
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08005979
5980 /* Subscribe management frames for this WPA_IF_AP_BSS */
5981 if (nl80211_setup_ap(new_bss))
5982 return -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005983 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005984
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005985 if (drv->global)
5986 drv->global->if_add_ifindex = ifidx;
5987
Dmitry Shmidt43cb5782014-06-16 16:23:22 -07005988 /*
5989 * Some virtual interfaces need to process EAPOL packets and events on
5990 * the parent interface. This is used mainly with hostapd.
5991 */
5992 if (ifidx > 0 &&
5993 (drv->hostapd ||
5994 nlmode == NL80211_IFTYPE_AP_VLAN ||
5995 nlmode == NL80211_IFTYPE_WDS ||
5996 nlmode == NL80211_IFTYPE_MONITOR))
Dmitry Shmidtdf5a7e42014-04-02 12:59:59 -07005997 add_ifidx(drv, ifidx);
5998
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005999 return 0;
6000}
6001
6002
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08006003static int wpa_driver_nl80211_if_remove(struct i802_bss *bss,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006004 enum wpa_driver_if_type type,
6005 const char *ifname)
6006{
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006007 struct wpa_driver_nl80211_data *drv = bss->drv;
6008 int ifindex = if_nametoindex(ifname);
6009
Dmitry Shmidtcce06662013-11-04 18:44:24 -08006010 wpa_printf(MSG_DEBUG, "nl80211: %s(type=%d ifname=%s) ifindex=%d added_if=%d",
6011 __func__, type, ifname, ifindex, bss->added_if);
Dmitry Shmidt01904cf2013-12-05 11:08:35 -08006012 if (ifindex > 0 && (bss->added_if || bss->ifindex != ifindex))
Dmitry Shmidt051af732013-10-22 13:52:46 -07006013 nl80211_remove_iface(drv, ifindex);
Dmitry Shmidt76cd2cc2014-05-27 12:56:04 -07006014 else if (ifindex > 0 && !bss->added_if) {
6015 struct wpa_driver_nl80211_data *drv2;
6016 dl_list_for_each(drv2, &drv->global->interfaces,
6017 struct wpa_driver_nl80211_data, list)
6018 del_ifidx(drv2, ifindex);
6019 }
Dmitry Shmidtaa532512012-09-24 10:35:31 -07006020
Dmitry Shmidtaa532512012-09-24 10:35:31 -07006021 if (type != WPA_IF_AP_BSS)
6022 return 0;
6023
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006024 if (bss->added_if_into_bridge) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006025 if (linux_br_del_if(drv->global->ioctl_sock, bss->brname,
6026 bss->ifname) < 0)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006027 wpa_printf(MSG_INFO, "nl80211: Failed to remove "
6028 "interface %s from bridge %s: %s",
6029 bss->ifname, bss->brname, strerror(errno));
6030 }
6031 if (bss->added_bridge) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006032 if (linux_br_del(drv->global->ioctl_sock, bss->brname) < 0)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006033 wpa_printf(MSG_INFO, "nl80211: Failed to remove "
6034 "bridge %s: %s",
6035 bss->brname, strerror(errno));
6036 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006037
Dmitry Shmidtcce06662013-11-04 18:44:24 -08006038 if (bss != drv->first_bss) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006039 struct i802_bss *tbss;
6040
Dmitry Shmidtcce06662013-11-04 18:44:24 -08006041 wpa_printf(MSG_DEBUG, "nl80211: Not the first BSS - remove it");
6042 for (tbss = drv->first_bss; tbss; tbss = tbss->next) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006043 if (tbss->next == bss) {
6044 tbss->next = bss->next;
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08006045 /* Unsubscribe management frames */
6046 nl80211_teardown_ap(bss);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006047 nl80211_destroy_bss(bss);
Dmitry Shmidtdf5a7e42014-04-02 12:59:59 -07006048 if (!bss->added_if)
6049 i802_set_iface_flags(bss, 0);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006050 os_free(bss);
6051 bss = NULL;
6052 break;
6053 }
6054 }
6055 if (bss)
6056 wpa_printf(MSG_INFO, "nl80211: %s - could not find "
6057 "BSS %p in the list", __func__, bss);
Dmitry Shmidtcce06662013-11-04 18:44:24 -08006058 } else {
6059 wpa_printf(MSG_DEBUG, "nl80211: First BSS - reassign context");
6060 nl80211_teardown_ap(bss);
6061 if (!bss->added_if && !drv->first_bss->next)
6062 wpa_driver_nl80211_del_beacon(drv);
6063 nl80211_destroy_bss(bss);
6064 if (!bss->added_if)
6065 i802_set_iface_flags(bss, 0);
6066 if (drv->first_bss->next) {
6067 drv->first_bss = drv->first_bss->next;
6068 drv->ctx = drv->first_bss->ctx;
6069 os_free(bss);
6070 } else {
6071 wpa_printf(MSG_DEBUG, "nl80211: No second BSS to reassign context to");
6072 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006073 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006074
6075 return 0;
6076}
6077
6078
6079static int cookie_handler(struct nl_msg *msg, void *arg)
6080{
6081 struct nlattr *tb[NL80211_ATTR_MAX + 1];
6082 struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg));
6083 u64 *cookie = arg;
6084 nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0),
6085 genlmsg_attrlen(gnlh, 0), NULL);
6086 if (tb[NL80211_ATTR_COOKIE])
6087 *cookie = nla_get_u64(tb[NL80211_ATTR_COOKIE]);
6088 return NL_SKIP;
6089}
6090
6091
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006092static int nl80211_send_frame_cmd(struct i802_bss *bss,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006093 unsigned int freq, unsigned int wait,
6094 const u8 *buf, size_t buf_len,
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006095 u64 *cookie_out, int no_cck, int no_ack,
6096 int offchanok)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006097{
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006098 struct wpa_driver_nl80211_data *drv = bss->drv;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006099 struct nl_msg *msg;
6100 u64 cookie;
6101 int ret = -1;
6102
Dmitry Shmidt8da800a2013-04-24 12:57:01 -07006103 wpa_printf(MSG_MSGDUMP, "nl80211: CMD_FRAME freq=%u wait=%u no_cck=%d "
Dmitry Shmidt04949592012-07-19 12:16:46 -07006104 "no_ack=%d offchanok=%d",
6105 freq, wait, no_cck, no_ack, offchanok);
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07006106 wpa_hexdump(MSG_MSGDUMP, "CMD_FRAME", buf, buf_len);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006107
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08006108 if (!(msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_FRAME)) ||
6109 (freq && nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq)) ||
6110 (wait && nla_put_u32(msg, NL80211_ATTR_DURATION, wait)) ||
6111 (offchanok && ((drv->capa.flags & WPA_DRIVER_FLAGS_OFFCHANNEL_TX) ||
6112 drv->test_use_roc_tx) &&
6113 nla_put_flag(msg, NL80211_ATTR_OFFCHANNEL_TX_OK)) ||
6114 (no_cck && nla_put_flag(msg, NL80211_ATTR_TX_NO_CCK_RATE)) ||
6115 (no_ack && nla_put_flag(msg, NL80211_ATTR_DONT_WAIT_FOR_ACK)) ||
6116 nla_put(msg, NL80211_ATTR_FRAME, buf_len, buf))
6117 goto fail;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006118
6119 cookie = 0;
6120 ret = send_and_recv_msgs(drv, msg, cookie_handler, &cookie);
6121 msg = NULL;
6122 if (ret) {
6123 wpa_printf(MSG_DEBUG, "nl80211: Frame command failed: ret=%d "
Dmitry Shmidt6e933c12011-09-27 12:29:26 -07006124 "(%s) (freq=%u wait=%u)", ret, strerror(-ret),
6125 freq, wait);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08006126 } else {
6127 wpa_printf(MSG_MSGDUMP, "nl80211: Frame TX command accepted%s; "
6128 "cookie 0x%llx", no_ack ? " (no ACK)" : "",
6129 (long long unsigned int) cookie);
6130
6131 if (cookie_out)
6132 *cookie_out = no_ack ? (u64) -1 : cookie;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006133 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006134
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08006135fail:
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006136 nlmsg_free(msg);
6137 return ret;
6138}
6139
6140
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08006141static int wpa_driver_nl80211_send_action(struct i802_bss *bss,
6142 unsigned int freq,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006143 unsigned int wait_time,
6144 const u8 *dst, const u8 *src,
6145 const u8 *bssid,
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006146 const u8 *data, size_t data_len,
6147 int no_cck)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006148{
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006149 struct wpa_driver_nl80211_data *drv = bss->drv;
6150 int ret = -1;
6151 u8 *buf;
6152 struct ieee80211_hdr *hdr;
6153
6154 wpa_printf(MSG_DEBUG, "nl80211: Send Action frame (ifindex=%d, "
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08006155 "freq=%u MHz wait=%d ms no_cck=%d)",
6156 drv->ifindex, freq, wait_time, no_cck);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006157
6158 buf = os_zalloc(24 + data_len);
6159 if (buf == NULL)
6160 return ret;
6161 os_memcpy(buf + 24, data, data_len);
6162 hdr = (struct ieee80211_hdr *) buf;
6163 hdr->frame_control =
6164 IEEE80211_FC(WLAN_FC_TYPE_MGMT, WLAN_FC_STYPE_ACTION);
6165 os_memcpy(hdr->addr1, dst, ETH_ALEN);
6166 os_memcpy(hdr->addr2, src, ETH_ALEN);
6167 os_memcpy(hdr->addr3, bssid, ETH_ALEN);
6168
Dmitry Shmidt56052862013-10-04 10:23:25 -07006169 if (is_ap_interface(drv->nlmode) &&
6170 (!(drv->capa.flags & WPA_DRIVER_FLAGS_OFFCHANNEL_TX) ||
6171 (int) freq == bss->freq || drv->device_ap_sme ||
6172 !drv->use_monitor))
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08006173 ret = wpa_driver_nl80211_send_mlme(bss, buf, 24 + data_len,
6174 0, freq, no_cck, 1,
6175 wait_time);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006176 else
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006177 ret = nl80211_send_frame_cmd(bss, freq, wait_time, buf,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006178 24 + data_len,
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006179 &drv->send_action_cookie,
6180 no_cck, 0, 1);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006181
6182 os_free(buf);
6183 return ret;
6184}
6185
6186
6187static void wpa_driver_nl80211_send_action_cancel_wait(void *priv)
6188{
6189 struct i802_bss *bss = priv;
6190 struct wpa_driver_nl80211_data *drv = bss->drv;
6191 struct nl_msg *msg;
6192 int ret;
6193
Dmitry Shmidt2f3b8de2013-03-01 09:32:50 -08006194 wpa_printf(MSG_DEBUG, "nl80211: Cancel TX frame wait: cookie=0x%llx",
6195 (long long unsigned int) drv->send_action_cookie);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08006196 if (!(msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_FRAME_WAIT_CANCEL)) ||
6197 nla_put_u64(msg, NL80211_ATTR_COOKIE, drv->send_action_cookie)) {
6198 nlmsg_free(msg);
6199 return;
6200 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006201
6202 ret = send_and_recv_msgs(drv, msg, NULL, NULL);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006203 if (ret)
6204 wpa_printf(MSG_DEBUG, "nl80211: wait cancel failed: ret=%d "
6205 "(%s)", ret, strerror(-ret));
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006206}
6207
6208
6209static int wpa_driver_nl80211_remain_on_channel(void *priv, unsigned int freq,
6210 unsigned int duration)
6211{
6212 struct i802_bss *bss = priv;
6213 struct wpa_driver_nl80211_data *drv = bss->drv;
6214 struct nl_msg *msg;
6215 int ret;
6216 u64 cookie;
6217
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08006218 if (!(msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_REMAIN_ON_CHANNEL)) ||
6219 nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq) ||
6220 nla_put_u32(msg, NL80211_ATTR_DURATION, duration)) {
6221 nlmsg_free(msg);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006222 return -1;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08006223 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006224
6225 cookie = 0;
6226 ret = send_and_recv_msgs(drv, msg, cookie_handler, &cookie);
6227 if (ret == 0) {
6228 wpa_printf(MSG_DEBUG, "nl80211: Remain-on-channel cookie "
6229 "0x%llx for freq=%u MHz duration=%u",
6230 (long long unsigned int) cookie, freq, duration);
6231 drv->remain_on_chan_cookie = cookie;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006232 drv->pending_remain_on_chan = 1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006233 return 0;
6234 }
6235 wpa_printf(MSG_DEBUG, "nl80211: Failed to request remain-on-channel "
6236 "(freq=%d duration=%u): %d (%s)",
6237 freq, duration, ret, strerror(-ret));
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006238 return -1;
6239}
6240
6241
6242static int wpa_driver_nl80211_cancel_remain_on_channel(void *priv)
6243{
6244 struct i802_bss *bss = priv;
6245 struct wpa_driver_nl80211_data *drv = bss->drv;
6246 struct nl_msg *msg;
6247 int ret;
6248
6249 if (!drv->pending_remain_on_chan) {
6250 wpa_printf(MSG_DEBUG, "nl80211: No pending remain-on-channel "
6251 "to cancel");
6252 return -1;
6253 }
6254
6255 wpa_printf(MSG_DEBUG, "nl80211: Cancel remain-on-channel with cookie "
6256 "0x%llx",
6257 (long long unsigned int) drv->remain_on_chan_cookie);
6258
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08006259 msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL);
6260 if (!msg ||
6261 nla_put_u64(msg, NL80211_ATTR_COOKIE, drv->remain_on_chan_cookie)) {
6262 nlmsg_free(msg);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006263 return -1;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08006264 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006265
6266 ret = send_and_recv_msgs(drv, msg, NULL, NULL);
6267 if (ret == 0)
6268 return 0;
6269 wpa_printf(MSG_DEBUG, "nl80211: Failed to cancel remain-on-channel: "
6270 "%d (%s)", ret, strerror(-ret));
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006271 return -1;
6272}
6273
6274
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08006275static int wpa_driver_nl80211_probe_req_report(struct i802_bss *bss, int report)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006276{
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006277 struct wpa_driver_nl80211_data *drv = bss->drv;
Dmitry Shmidt6e933c12011-09-27 12:29:26 -07006278
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006279 if (!report) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006280 if (bss->nl_preq && drv->device_ap_sme &&
Dmitry Shmidt03658832014-08-13 11:03:49 -07006281 is_ap_interface(drv->nlmode) && !bss->in_deinit &&
6282 !bss->static_ap) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006283 /*
6284 * Do not disable Probe Request reporting that was
6285 * enabled in nl80211_setup_ap().
6286 */
6287 wpa_printf(MSG_DEBUG, "nl80211: Skip disabling of "
6288 "Probe Request reporting nl_preq=%p while "
6289 "in AP mode", bss->nl_preq);
6290 } else if (bss->nl_preq) {
6291 wpa_printf(MSG_DEBUG, "nl80211: Disable Probe Request "
6292 "reporting nl_preq=%p", bss->nl_preq);
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -07006293 nl80211_destroy_eloop_handle(&bss->nl_preq);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006294 }
6295 return 0;
6296 }
6297
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006298 if (bss->nl_preq) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006299 wpa_printf(MSG_DEBUG, "nl80211: Probe Request reporting "
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006300 "already on! nl_preq=%p", bss->nl_preq);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006301 return 0;
6302 }
6303
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006304 bss->nl_preq = nl_create_handle(drv->global->nl_cb, "preq");
6305 if (bss->nl_preq == NULL)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006306 return -1;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006307 wpa_printf(MSG_DEBUG, "nl80211: Enable Probe Request "
6308 "reporting nl_preq=%p", bss->nl_preq);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006309
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006310 if (nl80211_register_frame(bss, bss->nl_preq,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006311 (WLAN_FC_TYPE_MGMT << 2) |
6312 (WLAN_FC_STYPE_PROBE_REQ << 4),
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006313 NULL, 0) < 0)
6314 goto out_err;
Dmitry Shmidt497c1d52011-07-21 15:19:46 -07006315
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -07006316 nl80211_register_eloop_read(&bss->nl_preq,
6317 wpa_driver_nl80211_event_receive,
6318 bss->nl_cb);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006319
6320 return 0;
6321
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006322 out_err:
6323 nl_destroy_handles(&bss->nl_preq);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006324 return -1;
6325}
6326
6327
6328static int nl80211_disable_11b_rates(struct wpa_driver_nl80211_data *drv,
6329 int ifindex, int disabled)
6330{
6331 struct nl_msg *msg;
6332 struct nlattr *bands, *band;
6333 int ret;
6334
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08006335 wpa_printf(MSG_DEBUG,
6336 "nl80211: NL80211_CMD_SET_TX_BITRATE_MASK (ifindex=%d %s)",
6337 ifindex, disabled ? "NL80211_TXRATE_LEGACY=OFDM-only" :
6338 "no NL80211_TXRATE_LEGACY constraint");
6339
6340 msg = nl80211_ifindex_msg(drv, ifindex, 0,
6341 NL80211_CMD_SET_TX_BITRATE_MASK);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006342 if (!msg)
6343 return -1;
6344
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006345 bands = nla_nest_start(msg, NL80211_ATTR_TX_RATES);
6346 if (!bands)
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08006347 goto fail;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006348
6349 /*
6350 * Disable 2 GHz rates 1, 2, 5.5, 11 Mbps by masking out everything
6351 * else apart from 6, 9, 12, 18, 24, 36, 48, 54 Mbps from non-MCS
6352 * rates. All 5 GHz rates are left enabled.
6353 */
6354 band = nla_nest_start(msg, NL80211_BAND_2GHZ);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08006355 if (!band ||
6356 (disabled && nla_put(msg, NL80211_TXRATE_LEGACY, 8,
6357 "\x0c\x12\x18\x24\x30\x48\x60\x6c")))
6358 goto fail;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006359 nla_nest_end(msg, band);
6360
6361 nla_nest_end(msg, bands);
6362
6363 ret = send_and_recv_msgs(drv, msg, NULL, NULL);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006364 if (ret) {
6365 wpa_printf(MSG_DEBUG, "nl80211: Set TX rates failed: ret=%d "
6366 "(%s)", ret, strerror(-ret));
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07006367 } else
6368 drv->disabled_11b_rates = disabled;
6369
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006370 return ret;
6371
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08006372fail:
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006373 nlmsg_free(msg);
6374 return -1;
6375}
6376
6377
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006378static int wpa_driver_nl80211_deinit_ap(void *priv)
6379{
6380 struct i802_bss *bss = priv;
6381 struct wpa_driver_nl80211_data *drv = bss->drv;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006382 if (!is_ap_interface(drv->nlmode))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006383 return -1;
6384 wpa_driver_nl80211_del_beacon(drv);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08006385 bss->beacon_set = 0;
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -07006386
6387 /*
6388 * If the P2P GO interface was dynamically added, then it is
6389 * possible that the interface change to station is not possible.
6390 */
6391 if (drv->nlmode == NL80211_IFTYPE_P2P_GO && bss->if_dynamic)
6392 return 0;
6393
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006394 return wpa_driver_nl80211_set_mode(priv, NL80211_IFTYPE_STATION);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006395}
6396
6397
Dmitry Shmidtea69e842013-05-13 14:52:28 -07006398static int wpa_driver_nl80211_stop_ap(void *priv)
6399{
6400 struct i802_bss *bss = priv;
6401 struct wpa_driver_nl80211_data *drv = bss->drv;
6402 if (!is_ap_interface(drv->nlmode))
6403 return -1;
6404 wpa_driver_nl80211_del_beacon(drv);
6405 bss->beacon_set = 0;
6406 return 0;
6407}
6408
6409
Dmitry Shmidt04949592012-07-19 12:16:46 -07006410static int wpa_driver_nl80211_deinit_p2p_cli(void *priv)
6411{
6412 struct i802_bss *bss = priv;
6413 struct wpa_driver_nl80211_data *drv = bss->drv;
6414 if (drv->nlmode != NL80211_IFTYPE_P2P_CLIENT)
6415 return -1;
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -07006416
6417 /*
6418 * If the P2P Client interface was dynamically added, then it is
6419 * possible that the interface change to station is not possible.
6420 */
6421 if (bss->if_dynamic)
6422 return 0;
6423
Dmitry Shmidt04949592012-07-19 12:16:46 -07006424 return wpa_driver_nl80211_set_mode(priv, NL80211_IFTYPE_STATION);
6425}
6426
6427
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006428static void wpa_driver_nl80211_resume(void *priv)
6429{
6430 struct i802_bss *bss = priv;
Dmitry Shmidt34af3062013-07-11 10:46:32 -07006431
6432 if (i802_set_iface_flags(bss, 1))
6433 wpa_printf(MSG_DEBUG, "nl80211: Failed to set interface up on resume event");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006434}
6435
6436
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006437static int nl80211_signal_monitor(void *priv, int threshold, int hysteresis)
6438{
6439 struct i802_bss *bss = priv;
6440 struct wpa_driver_nl80211_data *drv = bss->drv;
Dmitry Shmidt8da800a2013-04-24 12:57:01 -07006441 struct nl_msg *msg;
6442 struct nlattr *cqm;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006443
6444 wpa_printf(MSG_DEBUG, "nl80211: Signal monitor threshold=%d "
6445 "hysteresis=%d", threshold, hysteresis);
6446
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08006447 if (!(msg = nl80211_bss_msg(bss, 0, NL80211_CMD_SET_CQM)) ||
6448 !(cqm = nla_nest_start(msg, NL80211_ATTR_CQM)) ||
6449 nla_put_u32(msg, NL80211_ATTR_CQM_RSSI_THOLD, threshold) ||
6450 nla_put_u32(msg, NL80211_ATTR_CQM_RSSI_HYST, hysteresis)) {
6451 nlmsg_free(msg);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006452 return -1;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08006453 }
Dmitry Shmidt8da800a2013-04-24 12:57:01 -07006454 nla_nest_end(msg, cqm);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006455
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08006456 return send_and_recv_msgs(drv, msg, NULL, NULL);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006457}
6458
6459
Dmitry Shmidt34af3062013-07-11 10:46:32 -07006460static int get_channel_width(struct nl_msg *msg, void *arg)
6461{
6462 struct nlattr *tb[NL80211_ATTR_MAX + 1];
6463 struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg));
6464 struct wpa_signal_info *sig_change = arg;
6465
6466 nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0),
6467 genlmsg_attrlen(gnlh, 0), NULL);
6468
6469 sig_change->center_frq1 = -1;
6470 sig_change->center_frq2 = -1;
6471 sig_change->chanwidth = CHAN_WIDTH_UNKNOWN;
6472
6473 if (tb[NL80211_ATTR_CHANNEL_WIDTH]) {
6474 sig_change->chanwidth = convert2width(
6475 nla_get_u32(tb[NL80211_ATTR_CHANNEL_WIDTH]));
6476 if (tb[NL80211_ATTR_CENTER_FREQ1])
6477 sig_change->center_frq1 =
6478 nla_get_u32(tb[NL80211_ATTR_CENTER_FREQ1]);
6479 if (tb[NL80211_ATTR_CENTER_FREQ2])
6480 sig_change->center_frq2 =
6481 nla_get_u32(tb[NL80211_ATTR_CENTER_FREQ2]);
6482 }
6483
6484 return NL_SKIP;
6485}
6486
6487
6488static int nl80211_get_channel_width(struct wpa_driver_nl80211_data *drv,
6489 struct wpa_signal_info *sig)
6490{
6491 struct nl_msg *msg;
6492
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08006493 msg = nl80211_drv_msg(drv, 0, NL80211_CMD_GET_INTERFACE);
Dmitry Shmidt34af3062013-07-11 10:46:32 -07006494 return send_and_recv_msgs(drv, msg, get_channel_width, sig);
Dmitry Shmidt34af3062013-07-11 10:46:32 -07006495}
6496
6497
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006498static int nl80211_signal_poll(void *priv, struct wpa_signal_info *si)
6499{
6500 struct i802_bss *bss = priv;
6501 struct wpa_driver_nl80211_data *drv = bss->drv;
6502 int res;
6503
6504 os_memset(si, 0, sizeof(*si));
6505 res = nl80211_get_link_signal(drv, si);
6506 if (res != 0)
6507 return res;
6508
Dmitry Shmidt34af3062013-07-11 10:46:32 -07006509 res = nl80211_get_channel_width(drv, si);
6510 if (res != 0)
6511 return res;
6512
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006513 return nl80211_get_link_noise(drv, si);
6514}
6515
6516
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006517static int wpa_driver_nl80211_shared_freq(void *priv)
6518{
6519 struct i802_bss *bss = priv;
6520 struct wpa_driver_nl80211_data *drv = bss->drv;
6521 struct wpa_driver_nl80211_data *driver;
6522 int freq = 0;
6523
6524 /*
6525 * If the same PHY is in connected state with some other interface,
6526 * then retrieve the assoc freq.
6527 */
6528 wpa_printf(MSG_DEBUG, "nl80211: Get shared freq for PHY %s",
6529 drv->phyname);
6530
6531 dl_list_for_each(driver, &drv->global->interfaces,
6532 struct wpa_driver_nl80211_data, list) {
6533 if (drv == driver ||
6534 os_strcmp(drv->phyname, driver->phyname) != 0 ||
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006535 !driver->associated)
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006536 continue;
6537
6538 wpa_printf(MSG_DEBUG, "nl80211: Found a match for PHY %s - %s "
6539 MACSTR,
Dmitry Shmidtcce06662013-11-04 18:44:24 -08006540 driver->phyname, driver->first_bss->ifname,
6541 MAC2STR(driver->first_bss->addr));
Dmitry Shmidt04949592012-07-19 12:16:46 -07006542 if (is_ap_interface(driver->nlmode))
Dmitry Shmidtcce06662013-11-04 18:44:24 -08006543 freq = driver->first_bss->freq;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006544 else
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006545 freq = nl80211_get_assoc_freq(driver);
6546 wpa_printf(MSG_DEBUG, "nl80211: Shared freq for PHY %s: %d",
6547 drv->phyname, freq);
6548 }
6549
6550 if (!freq)
6551 wpa_printf(MSG_DEBUG, "nl80211: No shared interface for "
6552 "PHY (%s) in associated state", drv->phyname);
6553
6554 return freq;
6555}
6556
6557
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006558static int nl80211_send_frame(void *priv, const u8 *data, size_t data_len,
6559 int encrypt)
6560{
6561 struct i802_bss *bss = priv;
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08006562 return wpa_driver_nl80211_send_frame(bss, data, data_len, encrypt, 0,
6563 0, 0, 0, 0);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006564}
6565
6566
6567static int nl80211_set_param(void *priv, const char *param)
6568{
6569 wpa_printf(MSG_DEBUG, "nl80211: driver param='%s'", param);
6570 if (param == NULL)
6571 return 0;
6572
6573#ifdef CONFIG_P2P
6574 if (os_strstr(param, "use_p2p_group_interface=1")) {
6575 struct i802_bss *bss = priv;
6576 struct wpa_driver_nl80211_data *drv = bss->drv;
6577
6578 wpa_printf(MSG_DEBUG, "nl80211: Use separate P2P group "
6579 "interface");
6580 drv->capa.flags |= WPA_DRIVER_FLAGS_P2P_CONCURRENT;
6581 drv->capa.flags |= WPA_DRIVER_FLAGS_P2P_MGMT_AND_NON_P2P;
6582 }
6583#endif /* CONFIG_P2P */
6584
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08006585 if (os_strstr(param, "use_monitor=1")) {
6586 struct i802_bss *bss = priv;
6587 struct wpa_driver_nl80211_data *drv = bss->drv;
6588 drv->use_monitor = 1;
6589 }
6590
6591 if (os_strstr(param, "force_connect_cmd=1")) {
6592 struct i802_bss *bss = priv;
6593 struct wpa_driver_nl80211_data *drv = bss->drv;
6594 drv->capa.flags &= ~WPA_DRIVER_FLAGS_SME;
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07006595 drv->force_connect_cmd = 1;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08006596 }
6597
Dmitry Shmidt7d5c8f22014-03-03 13:53:28 -08006598 if (os_strstr(param, "no_offchannel_tx=1")) {
6599 struct i802_bss *bss = priv;
6600 struct wpa_driver_nl80211_data *drv = bss->drv;
6601 drv->capa.flags &= ~WPA_DRIVER_FLAGS_OFFCHANNEL_TX;
6602 drv->test_use_roc_tx = 1;
6603 }
6604
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006605 return 0;
6606}
6607
6608
6609static void * nl80211_global_init(void)
6610{
6611 struct nl80211_global *global;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006612 struct netlink_config *cfg;
6613
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006614 global = os_zalloc(sizeof(*global));
6615 if (global == NULL)
6616 return NULL;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006617 global->ioctl_sock = -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006618 dl_list_init(&global->interfaces);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006619 global->if_add_ifindex = -1;
6620
6621 cfg = os_zalloc(sizeof(*cfg));
6622 if (cfg == NULL)
6623 goto err;
6624
6625 cfg->ctx = global;
6626 cfg->newlink_cb = wpa_driver_nl80211_event_rtm_newlink;
6627 cfg->dellink_cb = wpa_driver_nl80211_event_rtm_dellink;
6628 global->netlink = netlink_init(cfg);
6629 if (global->netlink == NULL) {
6630 os_free(cfg);
6631 goto err;
6632 }
6633
6634 if (wpa_driver_nl80211_init_nl_global(global) < 0)
6635 goto err;
6636
6637 global->ioctl_sock = socket(PF_INET, SOCK_DGRAM, 0);
6638 if (global->ioctl_sock < 0) {
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -07006639 wpa_printf(MSG_ERROR, "nl80211: socket(PF_INET,SOCK_DGRAM) failed: %s",
6640 strerror(errno));
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006641 goto err;
6642 }
6643
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006644 return global;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006645
6646err:
6647 nl80211_global_deinit(global);
6648 return NULL;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006649}
6650
6651
6652static void nl80211_global_deinit(void *priv)
6653{
6654 struct nl80211_global *global = priv;
6655 if (global == NULL)
6656 return;
6657 if (!dl_list_empty(&global->interfaces)) {
6658 wpa_printf(MSG_ERROR, "nl80211: %u interface(s) remain at "
6659 "nl80211_global_deinit",
6660 dl_list_len(&global->interfaces));
6661 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006662
6663 if (global->netlink)
6664 netlink_deinit(global->netlink);
6665
6666 nl_destroy_handles(&global->nl);
6667
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -07006668 if (global->nl_event)
6669 nl80211_destroy_eloop_handle(&global->nl_event);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006670
6671 nl_cb_put(global->nl_cb);
6672
6673 if (global->ioctl_sock >= 0)
6674 close(global->ioctl_sock);
6675
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006676 os_free(global);
6677}
6678
6679
6680static const char * nl80211_get_radio_name(void *priv)
6681{
6682 struct i802_bss *bss = priv;
6683 struct wpa_driver_nl80211_data *drv = bss->drv;
6684 return drv->phyname;
6685}
6686
6687
Jouni Malinen75ecf522011-06-27 15:19:46 -07006688static int nl80211_pmkid(struct i802_bss *bss, int cmd, const u8 *bssid,
6689 const u8 *pmkid)
6690{
6691 struct nl_msg *msg;
6692
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08006693 if (!(msg = nl80211_bss_msg(bss, 0, cmd)) ||
6694 (pmkid && nla_put(msg, NL80211_ATTR_PMKID, 16, pmkid)) ||
6695 (bssid && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid))) {
6696 nlmsg_free(msg);
6697 return -ENOBUFS;
6698 }
Jouni Malinen75ecf522011-06-27 15:19:46 -07006699
6700 return send_and_recv_msgs(bss->drv, msg, NULL, NULL);
Jouni Malinen75ecf522011-06-27 15:19:46 -07006701}
6702
6703
6704static int nl80211_add_pmkid(void *priv, const u8 *bssid, const u8 *pmkid)
6705{
6706 struct i802_bss *bss = priv;
6707 wpa_printf(MSG_DEBUG, "nl80211: Add PMKID for " MACSTR, MAC2STR(bssid));
6708 return nl80211_pmkid(bss, NL80211_CMD_SET_PMKSA, bssid, pmkid);
6709}
6710
6711
6712static int nl80211_remove_pmkid(void *priv, const u8 *bssid, const u8 *pmkid)
6713{
6714 struct i802_bss *bss = priv;
6715 wpa_printf(MSG_DEBUG, "nl80211: Delete PMKID for " MACSTR,
6716 MAC2STR(bssid));
6717 return nl80211_pmkid(bss, NL80211_CMD_DEL_PMKSA, bssid, pmkid);
6718}
6719
6720
6721static int nl80211_flush_pmkid(void *priv)
6722{
6723 struct i802_bss *bss = priv;
6724 wpa_printf(MSG_DEBUG, "nl80211: Flush PMKIDs");
6725 return nl80211_pmkid(bss, NL80211_CMD_FLUSH_PMKSA, NULL, NULL);
6726}
6727
6728
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -07006729static void clean_survey_results(struct survey_results *survey_results)
6730{
6731 struct freq_survey *survey, *tmp;
6732
6733 if (dl_list_empty(&survey_results->survey_list))
6734 return;
6735
6736 dl_list_for_each_safe(survey, tmp, &survey_results->survey_list,
6737 struct freq_survey, list) {
6738 dl_list_del(&survey->list);
6739 os_free(survey);
6740 }
6741}
6742
6743
6744static void add_survey(struct nlattr **sinfo, u32 ifidx,
6745 struct dl_list *survey_list)
6746{
6747 struct freq_survey *survey;
6748
6749 survey = os_zalloc(sizeof(struct freq_survey));
6750 if (!survey)
6751 return;
6752
6753 survey->ifidx = ifidx;
6754 survey->freq = nla_get_u32(sinfo[NL80211_SURVEY_INFO_FREQUENCY]);
6755 survey->filled = 0;
6756
6757 if (sinfo[NL80211_SURVEY_INFO_NOISE]) {
6758 survey->nf = (int8_t)
6759 nla_get_u8(sinfo[NL80211_SURVEY_INFO_NOISE]);
6760 survey->filled |= SURVEY_HAS_NF;
6761 }
6762
6763 if (sinfo[NL80211_SURVEY_INFO_CHANNEL_TIME]) {
6764 survey->channel_time =
6765 nla_get_u64(sinfo[NL80211_SURVEY_INFO_CHANNEL_TIME]);
6766 survey->filled |= SURVEY_HAS_CHAN_TIME;
6767 }
6768
6769 if (sinfo[NL80211_SURVEY_INFO_CHANNEL_TIME_BUSY]) {
6770 survey->channel_time_busy =
6771 nla_get_u64(sinfo[NL80211_SURVEY_INFO_CHANNEL_TIME_BUSY]);
6772 survey->filled |= SURVEY_HAS_CHAN_TIME_BUSY;
6773 }
6774
6775 if (sinfo[NL80211_SURVEY_INFO_CHANNEL_TIME_RX]) {
6776 survey->channel_time_rx =
6777 nla_get_u64(sinfo[NL80211_SURVEY_INFO_CHANNEL_TIME_RX]);
6778 survey->filled |= SURVEY_HAS_CHAN_TIME_RX;
6779 }
6780
6781 if (sinfo[NL80211_SURVEY_INFO_CHANNEL_TIME_TX]) {
6782 survey->channel_time_tx =
6783 nla_get_u64(sinfo[NL80211_SURVEY_INFO_CHANNEL_TIME_TX]);
6784 survey->filled |= SURVEY_HAS_CHAN_TIME_TX;
6785 }
6786
6787 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)",
6788 survey->freq,
6789 survey->nf,
6790 (unsigned long int) survey->channel_time,
6791 (unsigned long int) survey->channel_time_busy,
6792 (unsigned long int) survey->channel_time_tx,
6793 (unsigned long int) survey->channel_time_rx,
6794 survey->filled);
6795
6796 dl_list_add_tail(survey_list, &survey->list);
6797}
6798
6799
6800static int check_survey_ok(struct nlattr **sinfo, u32 surveyed_freq,
6801 unsigned int freq_filter)
6802{
6803 if (!freq_filter)
6804 return 1;
6805
6806 return freq_filter == surveyed_freq;
6807}
6808
6809
6810static int survey_handler(struct nl_msg *msg, void *arg)
6811{
6812 struct nlattr *tb[NL80211_ATTR_MAX + 1];
6813 struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg));
6814 struct nlattr *sinfo[NL80211_SURVEY_INFO_MAX + 1];
6815 struct survey_results *survey_results;
6816 u32 surveyed_freq = 0;
6817 u32 ifidx;
6818
6819 static struct nla_policy survey_policy[NL80211_SURVEY_INFO_MAX + 1] = {
6820 [NL80211_SURVEY_INFO_FREQUENCY] = { .type = NLA_U32 },
6821 [NL80211_SURVEY_INFO_NOISE] = { .type = NLA_U8 },
6822 };
6823
6824 survey_results = (struct survey_results *) arg;
6825
6826 nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0),
6827 genlmsg_attrlen(gnlh, 0), NULL);
6828
Dmitry Shmidt97672262014-02-03 13:02:54 -08006829 if (!tb[NL80211_ATTR_IFINDEX])
6830 return NL_SKIP;
6831
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -07006832 ifidx = nla_get_u32(tb[NL80211_ATTR_IFINDEX]);
6833
6834 if (!tb[NL80211_ATTR_SURVEY_INFO])
6835 return NL_SKIP;
6836
6837 if (nla_parse_nested(sinfo, NL80211_SURVEY_INFO_MAX,
6838 tb[NL80211_ATTR_SURVEY_INFO],
6839 survey_policy))
6840 return NL_SKIP;
6841
6842 if (!sinfo[NL80211_SURVEY_INFO_FREQUENCY]) {
6843 wpa_printf(MSG_ERROR, "nl80211: Invalid survey data");
6844 return NL_SKIP;
6845 }
6846
6847 surveyed_freq = nla_get_u32(sinfo[NL80211_SURVEY_INFO_FREQUENCY]);
6848
6849 if (!check_survey_ok(sinfo, surveyed_freq,
6850 survey_results->freq_filter))
6851 return NL_SKIP;
6852
6853 if (survey_results->freq_filter &&
6854 survey_results->freq_filter != surveyed_freq) {
6855 wpa_printf(MSG_EXCESSIVE, "nl80211: Ignoring survey data for freq %d MHz",
6856 surveyed_freq);
6857 return NL_SKIP;
6858 }
6859
6860 add_survey(sinfo, ifidx, &survey_results->survey_list);
6861
6862 return NL_SKIP;
6863}
6864
6865
6866static int wpa_driver_nl80211_get_survey(void *priv, unsigned int freq)
6867{
6868 struct i802_bss *bss = priv;
6869 struct wpa_driver_nl80211_data *drv = bss->drv;
6870 struct nl_msg *msg;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08006871 int err;
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -07006872 union wpa_event_data data;
6873 struct survey_results *survey_results;
6874
6875 os_memset(&data, 0, sizeof(data));
6876 survey_results = &data.survey_results;
6877
6878 dl_list_init(&survey_results->survey_list);
6879
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08006880 msg = nl80211_drv_msg(drv, NLM_F_DUMP, NL80211_CMD_GET_SURVEY);
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -07006881 if (!msg)
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08006882 return -ENOBUFS;
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -07006883
6884 if (freq)
6885 data.survey_results.freq_filter = freq;
6886
6887 do {
6888 wpa_printf(MSG_DEBUG, "nl80211: Fetch survey data");
6889 err = send_and_recv_msgs(drv, msg, survey_handler,
6890 survey_results);
6891 } while (err > 0);
6892
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08006893 if (err)
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -07006894 wpa_printf(MSG_ERROR, "nl80211: Failed to process survey data");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08006895 else
6896 wpa_supplicant_event(drv->ctx, EVENT_SURVEY, &data);
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -07006897
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -07006898 clean_survey_results(survey_results);
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -07006899 return err;
6900}
6901
6902
Dmitry Shmidt807291d2015-01-27 13:40:23 -08006903static void nl80211_set_rekey_info(void *priv, const u8 *kek, size_t kek_len,
6904 const u8 *kck, size_t kck_len,
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006905 const u8 *replay_ctr)
6906{
6907 struct i802_bss *bss = priv;
6908 struct wpa_driver_nl80211_data *drv = bss->drv;
6909 struct nlattr *replay_nested;
6910 struct nl_msg *msg;
Dmitry Shmidtff787d52015-01-12 13:01:47 -08006911 int ret;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006912
Dmitry Shmidtff787d52015-01-12 13:01:47 -08006913 if (!drv->set_rekey_offload)
6914 return;
6915
6916 wpa_printf(MSG_DEBUG, "nl80211: Set rekey offload");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08006917 if (!(msg = nl80211_bss_msg(bss, 0, NL80211_CMD_SET_REKEY_OFFLOAD)) ||
6918 !(replay_nested = nla_nest_start(msg, NL80211_ATTR_REKEY_DATA)) ||
Dmitry Shmidt807291d2015-01-27 13:40:23 -08006919 nla_put(msg, NL80211_REKEY_DATA_KEK, kek_len, kek) ||
6920 nla_put(msg, NL80211_REKEY_DATA_KCK, kck_len, kck) ||
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08006921 nla_put(msg, NL80211_REKEY_DATA_REPLAY_CTR, NL80211_REPLAY_CTR_LEN,
6922 replay_ctr)) {
6923 nl80211_nlmsg_clear(msg);
6924 nlmsg_free(msg);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006925 return;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08006926 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006927
6928 nla_nest_end(msg, replay_nested);
6929
Dmitry Shmidtff787d52015-01-12 13:01:47 -08006930 ret = send_and_recv_msgs(drv, msg, NULL, (void *) -1);
6931 if (ret == -EOPNOTSUPP) {
6932 wpa_printf(MSG_DEBUG,
6933 "nl80211: Driver does not support rekey offload");
6934 drv->set_rekey_offload = 0;
6935 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006936}
6937
6938
6939static void nl80211_send_null_frame(struct i802_bss *bss, const u8 *own_addr,
6940 const u8 *addr, int qos)
6941{
6942 /* send data frame to poll STA and check whether
6943 * this frame is ACKed */
6944 struct {
6945 struct ieee80211_hdr hdr;
6946 u16 qos_ctl;
6947 } STRUCT_PACKED nulldata;
6948 size_t size;
6949
6950 /* Send data frame to poll STA and check whether this frame is ACKed */
6951
6952 os_memset(&nulldata, 0, sizeof(nulldata));
6953
6954 if (qos) {
6955 nulldata.hdr.frame_control =
6956 IEEE80211_FC(WLAN_FC_TYPE_DATA,
6957 WLAN_FC_STYPE_QOS_NULL);
6958 size = sizeof(nulldata);
6959 } else {
6960 nulldata.hdr.frame_control =
6961 IEEE80211_FC(WLAN_FC_TYPE_DATA,
6962 WLAN_FC_STYPE_NULLFUNC);
6963 size = sizeof(struct ieee80211_hdr);
6964 }
6965
6966 nulldata.hdr.frame_control |= host_to_le16(WLAN_FC_FROMDS);
6967 os_memcpy(nulldata.hdr.IEEE80211_DA_FROMDS, addr, ETH_ALEN);
6968 os_memcpy(nulldata.hdr.IEEE80211_BSSID_FROMDS, own_addr, ETH_ALEN);
6969 os_memcpy(nulldata.hdr.IEEE80211_SA_FROMDS, own_addr, ETH_ALEN);
6970
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08006971 if (wpa_driver_nl80211_send_mlme(bss, (u8 *) &nulldata, size, 0, 0, 0,
6972 0, 0) < 0)
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006973 wpa_printf(MSG_DEBUG, "nl80211_send_null_frame: Failed to "
6974 "send poll frame");
6975}
6976
6977static void nl80211_poll_client(void *priv, const u8 *own_addr, const u8 *addr,
6978 int qos)
6979{
6980 struct i802_bss *bss = priv;
6981 struct wpa_driver_nl80211_data *drv = bss->drv;
6982 struct nl_msg *msg;
Dmitry Shmidt7f656022015-02-25 14:36:37 -08006983 int ret;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006984
6985 if (!drv->poll_command_supported) {
6986 nl80211_send_null_frame(bss, own_addr, addr, qos);
6987 return;
6988 }
6989
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08006990 if (!(msg = nl80211_bss_msg(bss, 0, NL80211_CMD_PROBE_CLIENT)) ||
6991 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) {
6992 nlmsg_free(msg);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006993 return;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08006994 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006995
Dmitry Shmidt7f656022015-02-25 14:36:37 -08006996 ret = send_and_recv_msgs(drv, msg, NULL, NULL);
6997 if (ret < 0) {
6998 wpa_printf(MSG_DEBUG, "nl80211: Client probe request for "
6999 MACSTR " failed: ret=%d (%s)",
7000 MAC2STR(addr), ret, strerror(-ret));
7001 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08007002}
7003
7004
7005static int nl80211_set_power_save(struct i802_bss *bss, int enabled)
7006{
7007 struct nl_msg *msg;
7008
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08007009 if (!(msg = nl80211_bss_msg(bss, 0, NL80211_CMD_SET_POWER_SAVE)) ||
7010 nla_put_u32(msg, NL80211_ATTR_PS_STATE,
7011 enabled ? NL80211_PS_ENABLED : NL80211_PS_DISABLED)) {
7012 nlmsg_free(msg);
7013 return -ENOBUFS;
7014 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08007015 return send_and_recv_msgs(bss->drv, msg, NULL, NULL);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08007016}
7017
7018
7019static int nl80211_set_p2p_powersave(void *priv, int legacy_ps, int opp_ps,
7020 int ctwindow)
7021{
7022 struct i802_bss *bss = priv;
7023
7024 wpa_printf(MSG_DEBUG, "nl80211: set_p2p_powersave (legacy_ps=%d "
7025 "opp_ps=%d ctwindow=%d)", legacy_ps, opp_ps, ctwindow);
7026
Dmitry Shmidt292b0c32013-11-22 12:54:42 -08007027 if (opp_ps != -1 || ctwindow != -1) {
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08007028#ifdef ANDROID_P2P
7029 wpa_driver_set_p2p_ps(priv, legacy_ps, opp_ps, ctwindow);
Dmitry Shmidt292b0c32013-11-22 12:54:42 -08007030#else /* ANDROID_P2P */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08007031 return -1; /* Not yet supported */
Dmitry Shmidt292b0c32013-11-22 12:54:42 -08007032#endif /* ANDROID_P2P */
7033 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08007034
7035 if (legacy_ps == -1)
7036 return 0;
7037 if (legacy_ps != 0 && legacy_ps != 1)
7038 return -1; /* Not yet supported */
7039
7040 return nl80211_set_power_save(bss, legacy_ps);
7041}
7042
7043
Dmitry Shmidt051af732013-10-22 13:52:46 -07007044static int nl80211_start_radar_detection(void *priv,
7045 struct hostapd_freq_params *freq)
Dmitry Shmidtea69e842013-05-13 14:52:28 -07007046{
7047 struct i802_bss *bss = priv;
7048 struct wpa_driver_nl80211_data *drv = bss->drv;
7049 struct nl_msg *msg;
7050 int ret;
7051
Dmitry Shmidt051af732013-10-22 13:52:46 -07007052 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)",
7053 freq->freq, freq->ht_enabled, freq->vht_enabled,
7054 freq->bandwidth, freq->center_freq1, freq->center_freq2);
7055
Dmitry Shmidtea69e842013-05-13 14:52:28 -07007056 if (!(drv->capa.flags & WPA_DRIVER_FLAGS_RADAR)) {
7057 wpa_printf(MSG_DEBUG, "nl80211: Driver does not support radar "
7058 "detection");
7059 return -1;
7060 }
7061
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08007062 if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_RADAR_DETECT)) ||
7063 nl80211_put_freq_params(msg, freq) < 0) {
7064 nlmsg_free(msg);
Dmitry Shmidtea69e842013-05-13 14:52:28 -07007065 return -1;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08007066 }
Dmitry Shmidtea69e842013-05-13 14:52:28 -07007067
7068 ret = send_and_recv_msgs(drv, msg, NULL, NULL);
7069 if (ret == 0)
7070 return 0;
7071 wpa_printf(MSG_DEBUG, "nl80211: Failed to start radar detection: "
7072 "%d (%s)", ret, strerror(-ret));
Dmitry Shmidtea69e842013-05-13 14:52:28 -07007073 return -1;
7074}
7075
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08007076#ifdef CONFIG_TDLS
7077
7078static int nl80211_send_tdls_mgmt(void *priv, const u8 *dst, u8 action_code,
7079 u8 dialog_token, u16 status_code,
Dmitry Shmidt9ead16e2014-10-07 13:15:23 -07007080 u32 peer_capab, int initiator, const u8 *buf,
7081 size_t len)
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08007082{
7083 struct i802_bss *bss = priv;
7084 struct wpa_driver_nl80211_data *drv = bss->drv;
7085 struct nl_msg *msg;
7086
7087 if (!(drv->capa.flags & WPA_DRIVER_FLAGS_TDLS_SUPPORT))
7088 return -EOPNOTSUPP;
7089
7090 if (!dst)
7091 return -EINVAL;
7092
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08007093 if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_TDLS_MGMT)) ||
7094 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, dst) ||
7095 nla_put_u8(msg, NL80211_ATTR_TDLS_ACTION, action_code) ||
7096 nla_put_u8(msg, NL80211_ATTR_TDLS_DIALOG_TOKEN, dialog_token) ||
7097 nla_put_u16(msg, NL80211_ATTR_STATUS_CODE, status_code))
7098 goto fail;
Dmitry Shmidtdf5a7e42014-04-02 12:59:59 -07007099 if (peer_capab) {
7100 /*
7101 * The internal enum tdls_peer_capability definition is
7102 * currently identical with the nl80211 enum
7103 * nl80211_tdls_peer_capability, so no conversion is needed
7104 * here.
7105 */
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08007106 if (nla_put_u32(msg, NL80211_ATTR_TDLS_PEER_CAPABILITY,
7107 peer_capab))
7108 goto fail;
Dmitry Shmidtdf5a7e42014-04-02 12:59:59 -07007109 }
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08007110 if ((initiator &&
7111 nla_put_flag(msg, NL80211_ATTR_TDLS_INITIATOR)) ||
7112 nla_put(msg, NL80211_ATTR_IE, len, buf))
7113 goto fail;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08007114
7115 return send_and_recv_msgs(drv, msg, NULL, NULL);
7116
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08007117fail:
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08007118 nlmsg_free(msg);
7119 return -ENOBUFS;
7120}
7121
7122
7123static int nl80211_tdls_oper(void *priv, enum tdls_oper oper, const u8 *peer)
7124{
7125 struct i802_bss *bss = priv;
7126 struct wpa_driver_nl80211_data *drv = bss->drv;
7127 struct nl_msg *msg;
7128 enum nl80211_tdls_operation nl80211_oper;
7129
7130 if (!(drv->capa.flags & WPA_DRIVER_FLAGS_TDLS_SUPPORT))
7131 return -EOPNOTSUPP;
7132
7133 switch (oper) {
7134 case TDLS_DISCOVERY_REQ:
7135 nl80211_oper = NL80211_TDLS_DISCOVERY_REQ;
7136 break;
7137 case TDLS_SETUP:
7138 nl80211_oper = NL80211_TDLS_SETUP;
7139 break;
7140 case TDLS_TEARDOWN:
7141 nl80211_oper = NL80211_TDLS_TEARDOWN;
7142 break;
7143 case TDLS_ENABLE_LINK:
7144 nl80211_oper = NL80211_TDLS_ENABLE_LINK;
7145 break;
7146 case TDLS_DISABLE_LINK:
7147 nl80211_oper = NL80211_TDLS_DISABLE_LINK;
7148 break;
7149 case TDLS_ENABLE:
7150 return 0;
7151 case TDLS_DISABLE:
7152 return 0;
7153 default:
7154 return -EINVAL;
7155 }
7156
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08007157 if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_TDLS_OPER)) ||
7158 nla_put_u8(msg, NL80211_ATTR_TDLS_OPERATION, nl80211_oper) ||
7159 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer)) {
7160 nlmsg_free(msg);
7161 return -ENOBUFS;
7162 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08007163
7164 return send_and_recv_msgs(drv, msg, NULL, NULL);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08007165}
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08007166
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08007167
7168static int
7169nl80211_tdls_enable_channel_switch(void *priv, const u8 *addr, u8 oper_class,
7170 const struct hostapd_freq_params *params)
7171{
7172 struct i802_bss *bss = priv;
7173 struct wpa_driver_nl80211_data *drv = bss->drv;
7174 struct nl_msg *msg;
7175 int ret = -ENOBUFS;
7176
7177 if (!(drv->capa.flags & WPA_DRIVER_FLAGS_TDLS_SUPPORT) ||
7178 !(drv->capa.flags & WPA_DRIVER_FLAGS_TDLS_CHANNEL_SWITCH))
7179 return -EOPNOTSUPP;
7180
7181 wpa_printf(MSG_DEBUG, "nl80211: Enable TDLS channel switch " MACSTR
7182 " oper_class=%u freq=%u",
7183 MAC2STR(addr), oper_class, params->freq);
7184 msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_TDLS_CHANNEL_SWITCH);
7185 if (!msg ||
7186 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) ||
7187 nla_put_u8(msg, NL80211_ATTR_OPER_CLASS, oper_class) ||
7188 (ret = nl80211_put_freq_params(msg, params))) {
7189 nlmsg_free(msg);
7190 wpa_printf(MSG_DEBUG, "nl80211: Could not build TDLS chan switch");
7191 return ret;
7192 }
7193
7194 return send_and_recv_msgs(drv, msg, NULL, NULL);
7195}
7196
7197
7198static int
7199nl80211_tdls_disable_channel_switch(void *priv, const u8 *addr)
7200{
7201 struct i802_bss *bss = priv;
7202 struct wpa_driver_nl80211_data *drv = bss->drv;
7203 struct nl_msg *msg;
7204
7205 if (!(drv->capa.flags & WPA_DRIVER_FLAGS_TDLS_SUPPORT) ||
7206 !(drv->capa.flags & WPA_DRIVER_FLAGS_TDLS_CHANNEL_SWITCH))
7207 return -EOPNOTSUPP;
7208
7209 wpa_printf(MSG_DEBUG, "nl80211: Disable TDLS channel switch " MACSTR,
7210 MAC2STR(addr));
7211 msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_TDLS_CANCEL_CHANNEL_SWITCH);
7212 if (!msg ||
7213 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) {
7214 nlmsg_free(msg);
7215 wpa_printf(MSG_DEBUG,
7216 "nl80211: Could not build TDLS cancel chan switch");
7217 return -ENOBUFS;
7218 }
7219
7220 return send_and_recv_msgs(drv, msg, NULL, NULL);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08007221}
7222
7223#endif /* CONFIG TDLS */
7224
7225
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08007226static int driver_nl80211_set_key(const char *ifname, void *priv,
7227 enum wpa_alg alg, const u8 *addr,
7228 int key_idx, int set_tx,
7229 const u8 *seq, size_t seq_len,
7230 const u8 *key, size_t key_len)
7231{
7232 struct i802_bss *bss = priv;
7233 return wpa_driver_nl80211_set_key(ifname, bss, alg, addr, key_idx,
7234 set_tx, seq, seq_len, key, key_len);
7235}
7236
7237
7238static int driver_nl80211_scan2(void *priv,
7239 struct wpa_driver_scan_params *params)
7240{
7241 struct i802_bss *bss = priv;
7242 return wpa_driver_nl80211_scan(bss, params);
7243}
7244
7245
7246static int driver_nl80211_deauthenticate(void *priv, const u8 *addr,
7247 int reason_code)
7248{
7249 struct i802_bss *bss = priv;
7250 return wpa_driver_nl80211_deauthenticate(bss, addr, reason_code);
7251}
7252
7253
7254static int driver_nl80211_authenticate(void *priv,
7255 struct wpa_driver_auth_params *params)
7256{
7257 struct i802_bss *bss = priv;
7258 return wpa_driver_nl80211_authenticate(bss, params);
7259}
7260
7261
7262static void driver_nl80211_deinit(void *priv)
7263{
7264 struct i802_bss *bss = priv;
7265 wpa_driver_nl80211_deinit(bss);
7266}
7267
7268
7269static int driver_nl80211_if_remove(void *priv, enum wpa_driver_if_type type,
7270 const char *ifname)
7271{
7272 struct i802_bss *bss = priv;
7273 return wpa_driver_nl80211_if_remove(bss, type, ifname);
7274}
7275
7276
7277static int driver_nl80211_send_mlme(void *priv, const u8 *data,
7278 size_t data_len, int noack)
7279{
7280 struct i802_bss *bss = priv;
7281 return wpa_driver_nl80211_send_mlme(bss, data, data_len, noack,
7282 0, 0, 0, 0);
7283}
7284
7285
7286static int driver_nl80211_sta_remove(void *priv, const u8 *addr)
7287{
7288 struct i802_bss *bss = priv;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08007289 return wpa_driver_nl80211_sta_remove(bss, addr, -1, 0);
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08007290}
7291
7292
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08007293static int driver_nl80211_set_sta_vlan(void *priv, const u8 *addr,
7294 const char *ifname, int vlan_id)
7295{
7296 struct i802_bss *bss = priv;
7297 return i802_set_sta_vlan(bss, addr, ifname, vlan_id);
7298}
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08007299
7300
7301static int driver_nl80211_read_sta_data(void *priv,
7302 struct hostap_sta_driver_data *data,
7303 const u8 *addr)
7304{
7305 struct i802_bss *bss = priv;
7306 return i802_read_sta_data(bss, data, addr);
7307}
7308
7309
7310static int driver_nl80211_send_action(void *priv, unsigned int freq,
7311 unsigned int wait_time,
7312 const u8 *dst, const u8 *src,
7313 const u8 *bssid,
7314 const u8 *data, size_t data_len,
7315 int no_cck)
7316{
7317 struct i802_bss *bss = priv;
7318 return wpa_driver_nl80211_send_action(bss, freq, wait_time, dst, src,
7319 bssid, data, data_len, no_cck);
7320}
7321
7322
7323static int driver_nl80211_probe_req_report(void *priv, int report)
7324{
7325 struct i802_bss *bss = priv;
7326 return wpa_driver_nl80211_probe_req_report(bss, report);
7327}
7328
7329
Dmitry Shmidt700a1372013-03-15 14:14:44 -07007330static int wpa_driver_nl80211_update_ft_ies(void *priv, const u8 *md,
7331 const u8 *ies, size_t ies_len)
7332{
7333 int ret;
7334 struct nl_msg *msg;
7335 struct i802_bss *bss = priv;
7336 struct wpa_driver_nl80211_data *drv = bss->drv;
7337 u16 mdid = WPA_GET_LE16(md);
7338
Dmitry Shmidt700a1372013-03-15 14:14:44 -07007339 wpa_printf(MSG_DEBUG, "nl80211: Updating FT IEs");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08007340 if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_UPDATE_FT_IES)) ||
7341 nla_put(msg, NL80211_ATTR_IE, ies_len, ies) ||
7342 nla_put_u16(msg, NL80211_ATTR_MDID, mdid)) {
7343 nlmsg_free(msg);
7344 return -ENOBUFS;
7345 }
Dmitry Shmidt700a1372013-03-15 14:14:44 -07007346
7347 ret = send_and_recv_msgs(drv, msg, NULL, NULL);
7348 if (ret) {
7349 wpa_printf(MSG_DEBUG, "nl80211: update_ft_ies failed "
7350 "err=%d (%s)", ret, strerror(-ret));
7351 }
7352
7353 return ret;
Dmitry Shmidt700a1372013-03-15 14:14:44 -07007354}
7355
7356
Dmitry Shmidt34af3062013-07-11 10:46:32 -07007357const u8 * wpa_driver_nl80211_get_macaddr(void *priv)
7358{
7359 struct i802_bss *bss = priv;
7360 struct wpa_driver_nl80211_data *drv = bss->drv;
7361
7362 if (drv->nlmode != NL80211_IFTYPE_P2P_DEVICE)
7363 return NULL;
7364
7365 return bss->addr;
7366}
7367
7368
Dmitry Shmidt56052862013-10-04 10:23:25 -07007369static const char * scan_state_str(enum scan_states scan_state)
7370{
7371 switch (scan_state) {
7372 case NO_SCAN:
7373 return "NO_SCAN";
7374 case SCAN_REQUESTED:
7375 return "SCAN_REQUESTED";
7376 case SCAN_STARTED:
7377 return "SCAN_STARTED";
7378 case SCAN_COMPLETED:
7379 return "SCAN_COMPLETED";
7380 case SCAN_ABORTED:
7381 return "SCAN_ABORTED";
7382 case SCHED_SCAN_STARTED:
7383 return "SCHED_SCAN_STARTED";
7384 case SCHED_SCAN_STOPPED:
7385 return "SCHED_SCAN_STOPPED";
7386 case SCHED_SCAN_RESULTS:
7387 return "SCHED_SCAN_RESULTS";
7388 }
7389
7390 return "??";
7391}
7392
7393
7394static int wpa_driver_nl80211_status(void *priv, char *buf, size_t buflen)
7395{
7396 struct i802_bss *bss = priv;
7397 struct wpa_driver_nl80211_data *drv = bss->drv;
7398 int res;
7399 char *pos, *end;
7400
7401 pos = buf;
7402 end = buf + buflen;
7403
7404 res = os_snprintf(pos, end - pos,
7405 "ifindex=%d\n"
7406 "ifname=%s\n"
7407 "brname=%s\n"
7408 "addr=" MACSTR "\n"
7409 "freq=%d\n"
7410 "%s%s%s%s%s",
7411 bss->ifindex,
7412 bss->ifname,
7413 bss->brname,
7414 MAC2STR(bss->addr),
7415 bss->freq,
7416 bss->beacon_set ? "beacon_set=1\n" : "",
7417 bss->added_if_into_bridge ?
7418 "added_if_into_bridge=1\n" : "",
7419 bss->added_bridge ? "added_bridge=1\n" : "",
7420 bss->in_deinit ? "in_deinit=1\n" : "",
7421 bss->if_dynamic ? "if_dynamic=1\n" : "");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08007422 if (os_snprintf_error(end - pos, res))
Dmitry Shmidt56052862013-10-04 10:23:25 -07007423 return pos - buf;
7424 pos += res;
7425
7426 if (bss->wdev_id_set) {
7427 res = os_snprintf(pos, end - pos, "wdev_id=%llu\n",
7428 (unsigned long long) bss->wdev_id);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08007429 if (os_snprintf_error(end - pos, res))
Dmitry Shmidt56052862013-10-04 10:23:25 -07007430 return pos - buf;
7431 pos += res;
7432 }
7433
7434 res = os_snprintf(pos, end - pos,
7435 "phyname=%s\n"
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07007436 "perm_addr=" MACSTR "\n"
Dmitry Shmidt56052862013-10-04 10:23:25 -07007437 "drv_ifindex=%d\n"
7438 "operstate=%d\n"
7439 "scan_state=%s\n"
7440 "auth_bssid=" MACSTR "\n"
7441 "auth_attempt_bssid=" MACSTR "\n"
7442 "bssid=" MACSTR "\n"
7443 "prev_bssid=" MACSTR "\n"
7444 "associated=%d\n"
7445 "assoc_freq=%u\n"
7446 "monitor_sock=%d\n"
7447 "monitor_ifidx=%d\n"
7448 "monitor_refcount=%d\n"
7449 "last_mgmt_freq=%u\n"
7450 "eapol_tx_sock=%d\n"
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08007451 "%s%s%s%s%s%s%s%s%s%s%s%s%s",
Dmitry Shmidt56052862013-10-04 10:23:25 -07007452 drv->phyname,
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07007453 MAC2STR(drv->perm_addr),
Dmitry Shmidt56052862013-10-04 10:23:25 -07007454 drv->ifindex,
7455 drv->operstate,
7456 scan_state_str(drv->scan_state),
7457 MAC2STR(drv->auth_bssid),
7458 MAC2STR(drv->auth_attempt_bssid),
7459 MAC2STR(drv->bssid),
7460 MAC2STR(drv->prev_bssid),
7461 drv->associated,
7462 drv->assoc_freq,
7463 drv->monitor_sock,
7464 drv->monitor_ifidx,
7465 drv->monitor_refcount,
7466 drv->last_mgmt_freq,
7467 drv->eapol_tx_sock,
7468 drv->ignore_if_down_event ?
7469 "ignore_if_down_event=1\n" : "",
7470 drv->scan_complete_events ?
7471 "scan_complete_events=1\n" : "",
7472 drv->disabled_11b_rates ?
7473 "disabled_11b_rates=1\n" : "",
7474 drv->pending_remain_on_chan ?
7475 "pending_remain_on_chan=1\n" : "",
7476 drv->in_interface_list ? "in_interface_list=1\n" : "",
7477 drv->device_ap_sme ? "device_ap_sme=1\n" : "",
7478 drv->poll_command_supported ?
7479 "poll_command_supported=1\n" : "",
7480 drv->data_tx_status ? "data_tx_status=1\n" : "",
7481 drv->scan_for_auth ? "scan_for_auth=1\n" : "",
7482 drv->retry_auth ? "retry_auth=1\n" : "",
7483 drv->use_monitor ? "use_monitor=1\n" : "",
7484 drv->ignore_next_local_disconnect ?
7485 "ignore_next_local_disconnect=1\n" : "",
Dmitry Shmidt7dba0e52014-04-14 10:49:15 -07007486 drv->ignore_next_local_deauth ?
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08007487 "ignore_next_local_deauth=1\n" : "");
7488 if (os_snprintf_error(end - pos, res))
Dmitry Shmidt56052862013-10-04 10:23:25 -07007489 return pos - buf;
7490 pos += res;
7491
7492 if (drv->has_capability) {
7493 res = os_snprintf(pos, end - pos,
7494 "capa.key_mgmt=0x%x\n"
7495 "capa.enc=0x%x\n"
7496 "capa.auth=0x%x\n"
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08007497 "capa.flags=0x%llx\n"
7498 "capa.rrm_flags=0x%x\n"
Dmitry Shmidt56052862013-10-04 10:23:25 -07007499 "capa.max_scan_ssids=%d\n"
7500 "capa.max_sched_scan_ssids=%d\n"
7501 "capa.sched_scan_supported=%d\n"
7502 "capa.max_match_sets=%d\n"
7503 "capa.max_remain_on_chan=%u\n"
7504 "capa.max_stations=%u\n"
7505 "capa.probe_resp_offloads=0x%x\n"
7506 "capa.max_acl_mac_addrs=%u\n"
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08007507 "capa.num_multichan_concurrent=%u\n"
7508 "capa.mac_addr_rand_sched_scan_supported=%d\n"
7509 "capa.mac_addr_rand_scan_supported=%d\n",
Dmitry Shmidt56052862013-10-04 10:23:25 -07007510 drv->capa.key_mgmt,
7511 drv->capa.enc,
7512 drv->capa.auth,
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08007513 (unsigned long long) drv->capa.flags,
7514 drv->capa.rrm_flags,
Dmitry Shmidt56052862013-10-04 10:23:25 -07007515 drv->capa.max_scan_ssids,
7516 drv->capa.max_sched_scan_ssids,
7517 drv->capa.sched_scan_supported,
7518 drv->capa.max_match_sets,
7519 drv->capa.max_remain_on_chan,
7520 drv->capa.max_stations,
7521 drv->capa.probe_resp_offloads,
7522 drv->capa.max_acl_mac_addrs,
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08007523 drv->capa.num_multichan_concurrent,
7524 drv->capa.mac_addr_rand_sched_scan_supported,
7525 drv->capa.mac_addr_rand_scan_supported);
7526 if (os_snprintf_error(end - pos, res))
Dmitry Shmidt56052862013-10-04 10:23:25 -07007527 return pos - buf;
7528 pos += res;
7529 }
7530
7531 return pos - buf;
7532}
7533
7534
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08007535static int set_beacon_data(struct nl_msg *msg, struct beacon_data *settings)
7536{
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08007537 if ((settings->head &&
7538 nla_put(msg, NL80211_ATTR_BEACON_HEAD,
7539 settings->head_len, settings->head)) ||
7540 (settings->tail &&
7541 nla_put(msg, NL80211_ATTR_BEACON_TAIL,
7542 settings->tail_len, settings->tail)) ||
7543 (settings->beacon_ies &&
7544 nla_put(msg, NL80211_ATTR_IE,
7545 settings->beacon_ies_len, settings->beacon_ies)) ||
7546 (settings->proberesp_ies &&
7547 nla_put(msg, NL80211_ATTR_IE_PROBE_RESP,
7548 settings->proberesp_ies_len, settings->proberesp_ies)) ||
7549 (settings->assocresp_ies &&
7550 nla_put(msg, NL80211_ATTR_IE_ASSOC_RESP,
7551 settings->assocresp_ies_len, settings->assocresp_ies)) ||
7552 (settings->probe_resp &&
7553 nla_put(msg, NL80211_ATTR_PROBE_RESP,
7554 settings->probe_resp_len, settings->probe_resp)))
7555 return -ENOBUFS;
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08007556
7557 return 0;
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08007558}
7559
7560
7561static int nl80211_switch_channel(void *priv, struct csa_settings *settings)
7562{
7563 struct nl_msg *msg;
7564 struct i802_bss *bss = priv;
7565 struct wpa_driver_nl80211_data *drv = bss->drv;
7566 struct nlattr *beacon_csa;
7567 int ret = -ENOBUFS;
7568
Dmitry Shmidt04f534e2013-12-09 15:50:16 -08007569 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 -08007570 settings->cs_count, settings->block_tx,
Dmitry Shmidt04f534e2013-12-09 15:50:16 -08007571 settings->freq_params.freq, settings->freq_params.bandwidth,
7572 settings->freq_params.center_freq1,
7573 settings->freq_params.center_freq2);
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08007574
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08007575 if (!(drv->capa.flags & WPA_DRIVER_FLAGS_AP_CSA)) {
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08007576 wpa_printf(MSG_DEBUG, "nl80211: Driver does not support channel switch command");
7577 return -EOPNOTSUPP;
7578 }
7579
7580 if ((drv->nlmode != NL80211_IFTYPE_AP) &&
7581 (drv->nlmode != NL80211_IFTYPE_P2P_GO))
7582 return -EOPNOTSUPP;
7583
7584 /* check settings validity */
7585 if (!settings->beacon_csa.tail ||
7586 ((settings->beacon_csa.tail_len <=
7587 settings->counter_offset_beacon) ||
7588 (settings->beacon_csa.tail[settings->counter_offset_beacon] !=
7589 settings->cs_count)))
7590 return -EINVAL;
7591
7592 if (settings->beacon_csa.probe_resp &&
7593 ((settings->beacon_csa.probe_resp_len <=
7594 settings->counter_offset_presp) ||
7595 (settings->beacon_csa.probe_resp[settings->counter_offset_presp] !=
7596 settings->cs_count)))
7597 return -EINVAL;
7598
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08007599 if (!(msg = nl80211_bss_msg(bss, 0, NL80211_CMD_CHANNEL_SWITCH)) ||
7600 nla_put_u32(msg, NL80211_ATTR_CH_SWITCH_COUNT,
7601 settings->cs_count) ||
7602 (ret = nl80211_put_freq_params(msg, &settings->freq_params)) ||
7603 (settings->block_tx &&
7604 nla_put_flag(msg, NL80211_ATTR_CH_SWITCH_BLOCK_TX)))
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08007605 goto error;
7606
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08007607 /* beacon_after params */
7608 ret = set_beacon_data(msg, &settings->beacon_after);
7609 if (ret)
7610 goto error;
7611
7612 /* beacon_csa params */
7613 beacon_csa = nla_nest_start(msg, NL80211_ATTR_CSA_IES);
7614 if (!beacon_csa)
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08007615 goto fail;
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08007616
7617 ret = set_beacon_data(msg, &settings->beacon_csa);
7618 if (ret)
7619 goto error;
7620
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08007621 if (nla_put_u16(msg, NL80211_ATTR_CSA_C_OFF_BEACON,
7622 settings->counter_offset_beacon) ||
7623 (settings->beacon_csa.probe_resp &&
7624 nla_put_u16(msg, NL80211_ATTR_CSA_C_OFF_PRESP,
7625 settings->counter_offset_presp)))
7626 goto fail;
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08007627
7628 nla_nest_end(msg, beacon_csa);
7629 ret = send_and_recv_msgs(drv, msg, NULL, NULL);
7630 if (ret) {
7631 wpa_printf(MSG_DEBUG, "nl80211: switch_channel failed err=%d (%s)",
7632 ret, strerror(-ret));
7633 }
7634 return ret;
7635
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08007636fail:
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08007637 ret = -ENOBUFS;
7638error:
7639 nlmsg_free(msg);
7640 wpa_printf(MSG_DEBUG, "nl80211: Could not build channel switch request");
7641 return ret;
7642}
7643
7644
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08007645static int nl80211_add_ts(void *priv, u8 tsid, const u8 *addr,
7646 u8 user_priority, u16 admitted_time)
7647{
7648 struct i802_bss *bss = priv;
7649 struct wpa_driver_nl80211_data *drv = bss->drv;
7650 struct nl_msg *msg;
7651 int ret;
7652
7653 wpa_printf(MSG_DEBUG,
7654 "nl80211: add_ts request: tsid=%u admitted_time=%u up=%d",
7655 tsid, admitted_time, user_priority);
7656
7657 if (!is_sta_interface(drv->nlmode))
7658 return -ENOTSUP;
7659
7660 msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_ADD_TX_TS);
7661 if (!msg ||
7662 nla_put_u8(msg, NL80211_ATTR_TSID, tsid) ||
7663 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) ||
7664 nla_put_u8(msg, NL80211_ATTR_USER_PRIO, user_priority) ||
7665 nla_put_u16(msg, NL80211_ATTR_ADMITTED_TIME, admitted_time)) {
7666 nlmsg_free(msg);
7667 return -ENOBUFS;
7668 }
7669
7670 ret = send_and_recv_msgs(drv, msg, NULL, NULL);
7671 if (ret)
7672 wpa_printf(MSG_DEBUG, "nl80211: add_ts failed err=%d (%s)",
7673 ret, strerror(-ret));
7674 return ret;
7675}
7676
7677
7678static int nl80211_del_ts(void *priv, u8 tsid, const u8 *addr)
7679{
7680 struct i802_bss *bss = priv;
7681 struct wpa_driver_nl80211_data *drv = bss->drv;
7682 struct nl_msg *msg;
7683 int ret;
7684
7685 wpa_printf(MSG_DEBUG, "nl80211: del_ts request: tsid=%u", tsid);
7686
7687 if (!is_sta_interface(drv->nlmode))
7688 return -ENOTSUP;
7689
7690 if (!(msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_DEL_TX_TS)) ||
7691 nla_put_u8(msg, NL80211_ATTR_TSID, tsid) ||
7692 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) {
7693 nlmsg_free(msg);
7694 return -ENOBUFS;
7695 }
7696
7697 ret = send_and_recv_msgs(drv, msg, NULL, NULL);
7698 if (ret)
7699 wpa_printf(MSG_DEBUG, "nl80211: del_ts failed err=%d (%s)",
7700 ret, strerror(-ret));
7701 return ret;
7702}
7703
7704
Dmitry Shmidta38abf92014-03-06 13:38:44 -08007705#ifdef CONFIG_TESTING_OPTIONS
7706static int cmd_reply_handler(struct nl_msg *msg, void *arg)
7707{
7708 struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg));
7709 struct wpabuf *buf = arg;
7710
7711 if (!buf)
7712 return NL_SKIP;
7713
7714 if ((size_t) genlmsg_attrlen(gnlh, 0) > wpabuf_tailroom(buf)) {
7715 wpa_printf(MSG_INFO, "nl80211: insufficient buffer space for reply");
7716 return NL_SKIP;
7717 }
7718
7719 wpabuf_put_data(buf, genlmsg_attrdata(gnlh, 0),
7720 genlmsg_attrlen(gnlh, 0));
7721
7722 return NL_SKIP;
7723}
7724#endif /* CONFIG_TESTING_OPTIONS */
7725
7726
7727static int vendor_reply_handler(struct nl_msg *msg, void *arg)
7728{
7729 struct nlattr *tb[NL80211_ATTR_MAX + 1];
7730 struct nlattr *nl_vendor_reply, *nl;
7731 struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg));
7732 struct wpabuf *buf = arg;
7733 int rem;
7734
7735 if (!buf)
7736 return NL_SKIP;
7737
7738 nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0),
7739 genlmsg_attrlen(gnlh, 0), NULL);
7740 nl_vendor_reply = tb[NL80211_ATTR_VENDOR_DATA];
7741
7742 if (!nl_vendor_reply)
7743 return NL_SKIP;
7744
7745 if ((size_t) nla_len(nl_vendor_reply) > wpabuf_tailroom(buf)) {
7746 wpa_printf(MSG_INFO, "nl80211: Vendor command: insufficient buffer space for reply");
7747 return NL_SKIP;
7748 }
7749
7750 nla_for_each_nested(nl, nl_vendor_reply, rem) {
7751 wpabuf_put_data(buf, nla_data(nl), nla_len(nl));
7752 }
7753
7754 return NL_SKIP;
7755}
7756
7757
7758static int nl80211_vendor_cmd(void *priv, unsigned int vendor_id,
7759 unsigned int subcmd, const u8 *data,
7760 size_t data_len, struct wpabuf *buf)
7761{
7762 struct i802_bss *bss = priv;
7763 struct wpa_driver_nl80211_data *drv = bss->drv;
7764 struct nl_msg *msg;
7765 int ret;
7766
Dmitry Shmidta38abf92014-03-06 13:38:44 -08007767#ifdef CONFIG_TESTING_OPTIONS
7768 if (vendor_id == 0xffffffff) {
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08007769 msg = nlmsg_alloc();
7770 if (!msg)
7771 return -ENOMEM;
7772
Dmitry Shmidta38abf92014-03-06 13:38:44 -08007773 nl80211_cmd(drv, msg, 0, subcmd);
7774 if (nlmsg_append(msg, (void *) data, data_len, NLMSG_ALIGNTO) <
7775 0)
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08007776 goto fail;
Dmitry Shmidta38abf92014-03-06 13:38:44 -08007777 ret = send_and_recv_msgs(drv, msg, cmd_reply_handler, buf);
7778 if (ret)
7779 wpa_printf(MSG_DEBUG, "nl80211: command failed err=%d",
7780 ret);
7781 return ret;
7782 }
7783#endif /* CONFIG_TESTING_OPTIONS */
7784
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08007785 if (!(msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_VENDOR)) ||
7786 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, vendor_id) ||
7787 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD, subcmd) ||
7788 (data &&
7789 nla_put(msg, NL80211_ATTR_VENDOR_DATA, data_len, data)))
7790 goto fail;
Dmitry Shmidta38abf92014-03-06 13:38:44 -08007791
7792 ret = send_and_recv_msgs(drv, msg, vendor_reply_handler, buf);
7793 if (ret)
7794 wpa_printf(MSG_DEBUG, "nl80211: vendor command failed err=%d",
7795 ret);
7796 return ret;
7797
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08007798fail:
Dmitry Shmidta38abf92014-03-06 13:38:44 -08007799 nlmsg_free(msg);
7800 return -ENOBUFS;
7801}
7802
7803
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08007804static int nl80211_set_qos_map(void *priv, const u8 *qos_map_set,
7805 u8 qos_map_set_len)
7806{
7807 struct i802_bss *bss = priv;
7808 struct wpa_driver_nl80211_data *drv = bss->drv;
7809 struct nl_msg *msg;
7810 int ret;
7811
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08007812 wpa_hexdump(MSG_DEBUG, "nl80211: Setting QoS Map",
7813 qos_map_set, qos_map_set_len);
7814
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08007815 if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_SET_QOS_MAP)) ||
7816 nla_put(msg, NL80211_ATTR_QOS_MAP, qos_map_set_len, qos_map_set)) {
7817 nlmsg_free(msg);
7818 return -ENOBUFS;
7819 }
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08007820
7821 ret = send_and_recv_msgs(drv, msg, NULL, NULL);
7822 if (ret)
7823 wpa_printf(MSG_DEBUG, "nl80211: Setting QoS Map failed");
7824
7825 return ret;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08007826}
7827
7828
Dmitry Shmidtb58836e2014-04-29 14:35:56 -07007829static int nl80211_set_wowlan(void *priv,
7830 const struct wowlan_triggers *triggers)
7831{
7832 struct i802_bss *bss = priv;
7833 struct wpa_driver_nl80211_data *drv = bss->drv;
7834 struct nl_msg *msg;
7835 struct nlattr *wowlan_triggers;
7836 int ret;
7837
Dmitry Shmidtb58836e2014-04-29 14:35:56 -07007838 wpa_printf(MSG_DEBUG, "nl80211: Setting wowlan");
7839
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08007840 if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_SET_WOWLAN)) ||
7841 !(wowlan_triggers = nla_nest_start(msg,
7842 NL80211_ATTR_WOWLAN_TRIGGERS)) ||
7843 (triggers->any &&
7844 nla_put_flag(msg, NL80211_WOWLAN_TRIG_ANY)) ||
7845 (triggers->disconnect &&
7846 nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) ||
7847 (triggers->magic_pkt &&
7848 nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) ||
7849 (triggers->gtk_rekey_failure &&
7850 nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) ||
7851 (triggers->eap_identity_req &&
7852 nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) ||
7853 (triggers->four_way_handshake &&
7854 nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) ||
7855 (triggers->rfkill_release &&
7856 nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE))) {
7857 nlmsg_free(msg);
7858 return -ENOBUFS;
7859 }
Dmitry Shmidtb58836e2014-04-29 14:35:56 -07007860
7861 nla_nest_end(msg, wowlan_triggers);
7862
7863 ret = send_and_recv_msgs(drv, msg, NULL, NULL);
7864 if (ret)
7865 wpa_printf(MSG_DEBUG, "nl80211: Setting wowlan failed");
7866
7867 return ret;
Dmitry Shmidtb58836e2014-04-29 14:35:56 -07007868}
7869
7870
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07007871static int nl80211_roaming(void *priv, int allowed, const u8 *bssid)
7872{
7873 struct i802_bss *bss = priv;
7874 struct wpa_driver_nl80211_data *drv = bss->drv;
7875 struct nl_msg *msg;
7876 struct nlattr *params;
7877
7878 wpa_printf(MSG_DEBUG, "nl80211: Roaming policy: allowed=%d", allowed);
7879
7880 if (!drv->roaming_vendor_cmd_avail) {
7881 wpa_printf(MSG_DEBUG,
7882 "nl80211: Ignore roaming policy change since driver does not provide command for setting it");
7883 return -1;
7884 }
7885
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08007886 if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_VENDOR)) ||
7887 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
7888 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
7889 QCA_NL80211_VENDOR_SUBCMD_ROAMING) ||
7890 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
7891 nla_put_u32(msg, QCA_WLAN_VENDOR_ATTR_ROAMING_POLICY,
7892 allowed ? QCA_ROAMING_ALLOWED_WITHIN_ESS :
7893 QCA_ROAMING_NOT_ALLOWED) ||
7894 (bssid &&
7895 nla_put(msg, QCA_WLAN_VENDOR_ATTR_MAC_ADDR, ETH_ALEN, bssid))) {
7896 nlmsg_free(msg);
7897 return -1;
7898 }
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07007899 nla_nest_end(msg, params);
7900
7901 return send_and_recv_msgs(drv, msg, NULL, NULL);
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07007902}
7903
7904
7905static int nl80211_set_mac_addr(void *priv, const u8 *addr)
7906{
7907 struct i802_bss *bss = priv;
7908 struct wpa_driver_nl80211_data *drv = bss->drv;
7909 int new_addr = addr != NULL;
7910
7911 if (!addr)
7912 addr = drv->perm_addr;
7913
7914 if (linux_set_iface_flags(drv->global->ioctl_sock, bss->ifname, 0) < 0)
7915 return -1;
7916
7917 if (linux_set_ifhwaddr(drv->global->ioctl_sock, bss->ifname, addr) < 0)
7918 {
7919 wpa_printf(MSG_DEBUG,
7920 "nl80211: failed to set_mac_addr for %s to " MACSTR,
7921 bss->ifname, MAC2STR(addr));
7922 if (linux_set_iface_flags(drv->global->ioctl_sock, bss->ifname,
7923 1) < 0) {
7924 wpa_printf(MSG_DEBUG,
7925 "nl80211: Could not restore interface UP after failed set_mac_addr");
7926 }
7927 return -1;
7928 }
7929
7930 wpa_printf(MSG_DEBUG, "nl80211: set_mac_addr for %s to " MACSTR,
7931 bss->ifname, MAC2STR(addr));
7932 drv->addr_changed = new_addr;
7933 os_memcpy(bss->addr, addr, ETH_ALEN);
7934
7935 if (linux_set_iface_flags(drv->global->ioctl_sock, bss->ifname, 1) < 0)
7936 {
7937 wpa_printf(MSG_DEBUG,
7938 "nl80211: Could not restore interface UP after set_mac_addr");
7939 }
7940
7941 return 0;
7942}
7943
7944
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08007945#ifdef CONFIG_MESH
7946
7947static int wpa_driver_nl80211_init_mesh(void *priv)
7948{
7949 if (wpa_driver_nl80211_set_mode(priv, NL80211_IFTYPE_MESH_POINT)) {
7950 wpa_printf(MSG_INFO,
7951 "nl80211: Failed to set interface into mesh mode");
7952 return -1;
7953 }
7954 return 0;
7955}
7956
7957
Dmitry Shmidtff787d52015-01-12 13:01:47 -08007958static int nl80211_put_mesh_id(struct nl_msg *msg, const u8 *mesh_id,
7959 size_t mesh_id_len)
7960{
7961 if (mesh_id) {
7962 wpa_hexdump_ascii(MSG_DEBUG, " * Mesh ID (SSID)",
7963 mesh_id, mesh_id_len);
7964 return nla_put(msg, NL80211_ATTR_MESH_ID, mesh_id_len, mesh_id);
7965 }
7966
7967 return 0;
7968}
7969
7970
Dmitry Shmidt7f656022015-02-25 14:36:37 -08007971static int nl80211_join_mesh(struct i802_bss *bss,
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08007972 struct wpa_driver_mesh_join_params *params)
7973{
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08007974 struct wpa_driver_nl80211_data *drv = bss->drv;
7975 struct nl_msg *msg;
7976 struct nlattr *container;
Dmitry Shmidt2f74e362015-01-21 13:19:05 -08007977 int ret = -1;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08007978
7979 wpa_printf(MSG_DEBUG, "nl80211: mesh join (ifindex=%d)", drv->ifindex);
7980 msg = nl80211_drv_msg(drv, 0, NL80211_CMD_JOIN_MESH);
Dmitry Shmidtff787d52015-01-12 13:01:47 -08007981 if (!msg ||
7982 nl80211_put_freq_params(msg, &params->freq) ||
7983 nl80211_put_basic_rates(msg, params->basic_rates) ||
7984 nl80211_put_mesh_id(msg, params->meshid, params->meshid_len) ||
7985 nl80211_put_beacon_int(msg, params->beacon_int))
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08007986 goto fail;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08007987
7988 wpa_printf(MSG_DEBUG, " * flags=%08X", params->flags);
7989
7990 container = nla_nest_start(msg, NL80211_ATTR_MESH_SETUP);
7991 if (!container)
7992 goto fail;
7993
7994 if (params->ies) {
7995 wpa_hexdump(MSG_DEBUG, " * IEs", params->ies, params->ie_len);
7996 if (nla_put(msg, NL80211_MESH_SETUP_IE, params->ie_len,
7997 params->ies))
7998 goto fail;
7999 }
8000 /* WPA_DRIVER_MESH_FLAG_OPEN_AUTH is treated as default by nl80211 */
8001 if (params->flags & WPA_DRIVER_MESH_FLAG_SAE_AUTH) {
8002 if (nla_put_u8(msg, NL80211_MESH_SETUP_AUTH_PROTOCOL, 0x1) ||
8003 nla_put_flag(msg, NL80211_MESH_SETUP_USERSPACE_AUTH))
8004 goto fail;
8005 }
8006 if ((params->flags & WPA_DRIVER_MESH_FLAG_AMPE) &&
8007 nla_put_flag(msg, NL80211_MESH_SETUP_USERSPACE_AMPE))
8008 goto fail;
8009 if ((params->flags & WPA_DRIVER_MESH_FLAG_USER_MPM) &&
8010 nla_put_flag(msg, NL80211_MESH_SETUP_USERSPACE_MPM))
8011 goto fail;
8012 nla_nest_end(msg, container);
8013
8014 container = nla_nest_start(msg, NL80211_ATTR_MESH_CONFIG);
8015 if (!container)
8016 goto fail;
8017
8018 if (!(params->conf.flags & WPA_DRIVER_MESH_CONF_FLAG_AUTO_PLINKS) &&
8019 nla_put_u32(msg, NL80211_MESHCONF_AUTO_OPEN_PLINKS, 0))
8020 goto fail;
8021 if ((params->conf.flags & WPA_DRIVER_MESH_FLAG_DRIVER_MPM) &&
8022 nla_put_u16(msg, NL80211_MESHCONF_MAX_PEER_LINKS,
8023 params->max_peer_links))
8024 goto fail;
Dmitry Shmidt2f74e362015-01-21 13:19:05 -08008025
8026 /*
8027 * Set NL80211_MESHCONF_PLINK_TIMEOUT even if user mpm is used because
8028 * the timer could disconnect stations even in that case.
Dmitry Shmidt2f74e362015-01-21 13:19:05 -08008029 */
Dmitry Shmidt7f656022015-02-25 14:36:37 -08008030 if (nla_put_u32(msg, NL80211_MESHCONF_PLINK_TIMEOUT,
8031 params->conf.peer_link_timeout)) {
Dmitry Shmidt2f74e362015-01-21 13:19:05 -08008032 wpa_printf(MSG_ERROR, "nl80211: Failed to set PLINK_TIMEOUT");
8033 goto fail;
8034 }
8035
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08008036 nla_nest_end(msg, container);
8037
8038 ret = send_and_recv_msgs(drv, msg, NULL, NULL);
8039 msg = NULL;
8040 if (ret) {
8041 wpa_printf(MSG_DEBUG, "nl80211: mesh join failed: ret=%d (%s)",
8042 ret, strerror(-ret));
8043 goto fail;
8044 }
8045 ret = 0;
Dmitry Shmidtff787d52015-01-12 13:01:47 -08008046 bss->freq = params->freq.freq;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08008047 wpa_printf(MSG_DEBUG, "nl80211: mesh join request send successfully");
8048
8049fail:
8050 nlmsg_free(msg);
8051 return ret;
8052}
8053
8054
Dmitry Shmidt7f656022015-02-25 14:36:37 -08008055static int
8056wpa_driver_nl80211_join_mesh(void *priv,
8057 struct wpa_driver_mesh_join_params *params)
8058{
8059 struct i802_bss *bss = priv;
8060 int ret, timeout;
8061
8062 timeout = params->conf.peer_link_timeout;
8063
8064 /* Disable kernel inactivity timer */
8065 if (params->flags & WPA_DRIVER_MESH_FLAG_USER_MPM)
8066 params->conf.peer_link_timeout = 0;
8067
8068 ret = nl80211_join_mesh(bss, params);
8069 if (ret == -EINVAL && params->conf.peer_link_timeout == 0) {
8070 wpa_printf(MSG_DEBUG,
8071 "nl80211: Mesh join retry for peer_link_timeout");
8072 /*
8073 * Old kernel does not support setting
8074 * NL80211_MESHCONF_PLINK_TIMEOUT to zero, so set 60 seconds
8075 * into future from peer_link_timeout.
8076 */
8077 params->conf.peer_link_timeout = timeout + 60;
8078 ret = nl80211_join_mesh(priv, params);
8079 }
8080
8081 params->conf.peer_link_timeout = timeout;
8082 return ret;
8083}
8084
8085
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08008086static int wpa_driver_nl80211_leave_mesh(void *priv)
8087{
8088 struct i802_bss *bss = priv;
8089 struct wpa_driver_nl80211_data *drv = bss->drv;
8090 struct nl_msg *msg;
8091 int ret;
8092
8093 wpa_printf(MSG_DEBUG, "nl80211: mesh leave (ifindex=%d)", drv->ifindex);
8094 msg = nl80211_drv_msg(drv, 0, NL80211_CMD_LEAVE_MESH);
8095 ret = send_and_recv_msgs(drv, msg, NULL, NULL);
8096 if (ret) {
8097 wpa_printf(MSG_DEBUG, "nl80211: mesh leave failed: ret=%d (%s)",
8098 ret, strerror(-ret));
8099 } else {
8100 wpa_printf(MSG_DEBUG,
8101 "nl80211: mesh leave request send successfully");
8102 }
8103
8104 if (wpa_driver_nl80211_set_mode(drv->first_bss,
8105 NL80211_IFTYPE_STATION)) {
8106 wpa_printf(MSG_INFO,
8107 "nl80211: Failed to set interface into station mode");
8108 }
8109 return ret;
8110}
8111
8112#endif /* CONFIG_MESH */
8113
8114
8115static int wpa_driver_br_add_ip_neigh(void *priv, u8 version,
8116 const u8 *ipaddr, int prefixlen,
8117 const u8 *addr)
8118{
8119#ifdef CONFIG_LIBNL3_ROUTE
8120 struct i802_bss *bss = priv;
8121 struct wpa_driver_nl80211_data *drv = bss->drv;
8122 struct rtnl_neigh *rn;
8123 struct nl_addr *nl_ipaddr = NULL;
8124 struct nl_addr *nl_lladdr = NULL;
8125 int family, addrsize;
8126 int res;
8127
8128 if (!ipaddr || prefixlen == 0 || !addr)
8129 return -EINVAL;
8130
8131 if (bss->br_ifindex == 0) {
8132 wpa_printf(MSG_DEBUG,
8133 "nl80211: bridge must be set before adding an ip neigh to it");
8134 return -1;
8135 }
8136
8137 if (!drv->rtnl_sk) {
8138 wpa_printf(MSG_DEBUG,
8139 "nl80211: nl_sock for NETLINK_ROUTE is not initialized");
8140 return -1;
8141 }
8142
8143 if (version == 4) {
8144 family = AF_INET;
8145 addrsize = 4;
8146 } else if (version == 6) {
8147 family = AF_INET6;
8148 addrsize = 16;
8149 } else {
8150 return -EINVAL;
8151 }
8152
8153 rn = rtnl_neigh_alloc();
8154 if (rn == NULL)
8155 return -ENOMEM;
8156
8157 /* set the destination ip address for neigh */
8158 nl_ipaddr = nl_addr_build(family, (void *) ipaddr, addrsize);
8159 if (nl_ipaddr == NULL) {
8160 wpa_printf(MSG_DEBUG, "nl80211: nl_ipaddr build failed");
8161 res = -ENOMEM;
8162 goto errout;
8163 }
8164 nl_addr_set_prefixlen(nl_ipaddr, prefixlen);
8165 res = rtnl_neigh_set_dst(rn, nl_ipaddr);
8166 if (res) {
8167 wpa_printf(MSG_DEBUG,
8168 "nl80211: neigh set destination addr failed");
8169 goto errout;
8170 }
8171
8172 /* set the corresponding lladdr for neigh */
8173 nl_lladdr = nl_addr_build(AF_BRIDGE, (u8 *) addr, ETH_ALEN);
8174 if (nl_lladdr == NULL) {
8175 wpa_printf(MSG_DEBUG, "nl80211: neigh set lladdr failed");
8176 res = -ENOMEM;
8177 goto errout;
8178 }
8179 rtnl_neigh_set_lladdr(rn, nl_lladdr);
8180
8181 rtnl_neigh_set_ifindex(rn, bss->br_ifindex);
8182 rtnl_neigh_set_state(rn, NUD_PERMANENT);
8183
8184 res = rtnl_neigh_add(drv->rtnl_sk, rn, NLM_F_CREATE);
8185 if (res) {
8186 wpa_printf(MSG_DEBUG,
8187 "nl80211: Adding bridge ip neigh failed: %s",
8188 strerror(errno));
8189 }
8190errout:
8191 if (nl_lladdr)
8192 nl_addr_put(nl_lladdr);
8193 if (nl_ipaddr)
8194 nl_addr_put(nl_ipaddr);
8195 if (rn)
8196 rtnl_neigh_put(rn);
8197 return res;
8198#else /* CONFIG_LIBNL3_ROUTE */
8199 return -1;
8200#endif /* CONFIG_LIBNL3_ROUTE */
8201}
8202
8203
8204static int wpa_driver_br_delete_ip_neigh(void *priv, u8 version,
8205 const u8 *ipaddr)
8206{
8207#ifdef CONFIG_LIBNL3_ROUTE
8208 struct i802_bss *bss = priv;
8209 struct wpa_driver_nl80211_data *drv = bss->drv;
8210 struct rtnl_neigh *rn;
8211 struct nl_addr *nl_ipaddr;
8212 int family, addrsize;
8213 int res;
8214
8215 if (!ipaddr)
8216 return -EINVAL;
8217
8218 if (version == 4) {
8219 family = AF_INET;
8220 addrsize = 4;
8221 } else if (version == 6) {
8222 family = AF_INET6;
8223 addrsize = 16;
8224 } else {
8225 return -EINVAL;
8226 }
8227
8228 if (bss->br_ifindex == 0) {
8229 wpa_printf(MSG_DEBUG,
8230 "nl80211: bridge must be set to delete an ip neigh");
8231 return -1;
8232 }
8233
8234 if (!drv->rtnl_sk) {
8235 wpa_printf(MSG_DEBUG,
8236 "nl80211: nl_sock for NETLINK_ROUTE is not initialized");
8237 return -1;
8238 }
8239
8240 rn = rtnl_neigh_alloc();
8241 if (rn == NULL)
8242 return -ENOMEM;
8243
8244 /* set the destination ip address for neigh */
8245 nl_ipaddr = nl_addr_build(family, (void *) ipaddr, addrsize);
8246 if (nl_ipaddr == NULL) {
8247 wpa_printf(MSG_DEBUG, "nl80211: nl_ipaddr build failed");
8248 res = -ENOMEM;
8249 goto errout;
8250 }
8251 res = rtnl_neigh_set_dst(rn, nl_ipaddr);
8252 if (res) {
8253 wpa_printf(MSG_DEBUG,
8254 "nl80211: neigh set destination addr failed");
8255 goto errout;
8256 }
8257
8258 rtnl_neigh_set_ifindex(rn, bss->br_ifindex);
8259
8260 res = rtnl_neigh_delete(drv->rtnl_sk, rn, 0);
8261 if (res) {
8262 wpa_printf(MSG_DEBUG,
8263 "nl80211: Deleting bridge ip neigh failed: %s",
8264 strerror(errno));
8265 }
8266errout:
8267 if (nl_ipaddr)
8268 nl_addr_put(nl_ipaddr);
8269 if (rn)
8270 rtnl_neigh_put(rn);
8271 return res;
8272#else /* CONFIG_LIBNL3_ROUTE */
8273 return -1;
8274#endif /* CONFIG_LIBNL3_ROUTE */
8275}
8276
8277
8278static int linux_write_system_file(const char *path, unsigned int val)
8279{
8280 char buf[50];
8281 int fd, len;
8282
8283 len = os_snprintf(buf, sizeof(buf), "%u\n", val);
8284 if (os_snprintf_error(sizeof(buf), len))
8285 return -1;
8286
8287 fd = open(path, O_WRONLY);
8288 if (fd < 0)
8289 return -1;
8290
8291 if (write(fd, buf, len) < 0) {
8292 wpa_printf(MSG_DEBUG,
8293 "nl80211: Failed to write Linux system file: %s with the value of %d",
8294 path, val);
8295 close(fd);
8296 return -1;
8297 }
8298 close(fd);
8299
8300 return 0;
8301}
8302
8303
8304static const char * drv_br_port_attr_str(enum drv_br_port_attr attr)
8305{
8306 switch (attr) {
8307 case DRV_BR_PORT_ATTR_PROXYARP:
8308 return "proxyarp";
8309 case DRV_BR_PORT_ATTR_HAIRPIN_MODE:
8310 return "hairpin_mode";
8311 }
8312
8313 return NULL;
8314}
8315
8316
8317static int wpa_driver_br_port_set_attr(void *priv, enum drv_br_port_attr attr,
8318 unsigned int val)
8319{
8320 struct i802_bss *bss = priv;
8321 char path[128];
8322 const char *attr_txt;
8323
8324 attr_txt = drv_br_port_attr_str(attr);
8325 if (attr_txt == NULL)
8326 return -EINVAL;
8327
8328 os_snprintf(path, sizeof(path), "/sys/class/net/%s/brport/%s",
8329 bss->ifname, attr_txt);
8330
8331 if (linux_write_system_file(path, val))
8332 return -1;
8333
8334 return 0;
8335}
8336
8337
8338static const char * drv_br_net_param_str(enum drv_br_net_param param)
8339{
8340 switch (param) {
8341 case DRV_BR_NET_PARAM_GARP_ACCEPT:
8342 return "arp_accept";
8343 }
8344
8345 return NULL;
8346}
8347
8348
8349static int wpa_driver_br_set_net_param(void *priv, enum drv_br_net_param param,
8350 unsigned int val)
8351{
8352 struct i802_bss *bss = priv;
8353 char path[128];
8354 const char *param_txt;
8355 int ip_version = 4;
8356
8357 param_txt = drv_br_net_param_str(param);
8358 if (param_txt == NULL)
8359 return -EINVAL;
8360
8361 switch (param) {
8362 case DRV_BR_NET_PARAM_GARP_ACCEPT:
8363 ip_version = 4;
8364 break;
8365 default:
8366 return -EINVAL;
8367 }
8368
8369 os_snprintf(path, sizeof(path), "/proc/sys/net/ipv%d/conf/%s/%s",
8370 ip_version, bss->brname, param_txt);
8371
8372 if (linux_write_system_file(path, val))
8373 return -1;
8374
8375 return 0;
8376}
8377
8378
8379static int hw_mode_to_qca_acs(enum hostapd_hw_mode hw_mode)
8380{
8381 switch (hw_mode) {
8382 case HOSTAPD_MODE_IEEE80211B:
8383 return QCA_ACS_MODE_IEEE80211B;
8384 case HOSTAPD_MODE_IEEE80211G:
8385 return QCA_ACS_MODE_IEEE80211G;
8386 case HOSTAPD_MODE_IEEE80211A:
8387 return QCA_ACS_MODE_IEEE80211A;
8388 case HOSTAPD_MODE_IEEE80211AD:
8389 return QCA_ACS_MODE_IEEE80211AD;
8390 default:
8391 return -1;
8392 }
8393}
8394
8395
8396static int wpa_driver_do_acs(void *priv, struct drv_acs_params *params)
8397{
8398 struct i802_bss *bss = priv;
8399 struct wpa_driver_nl80211_data *drv = bss->drv;
8400 struct nl_msg *msg;
8401 struct nlattr *data;
8402 int ret;
8403 int mode;
8404
8405 mode = hw_mode_to_qca_acs(params->hw_mode);
8406 if (mode < 0)
8407 return -1;
8408
8409 if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_VENDOR)) ||
8410 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
8411 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
8412 QCA_NL80211_VENDOR_SUBCMD_DO_ACS) ||
8413 !(data = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
8414 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_ACS_HW_MODE, mode) ||
8415 (params->ht_enabled &&
8416 nla_put_flag(msg, QCA_WLAN_VENDOR_ATTR_ACS_HT_ENABLED)) ||
8417 (params->ht40_enabled &&
8418 nla_put_flag(msg, QCA_WLAN_VENDOR_ATTR_ACS_HT40_ENABLED))) {
8419 nlmsg_free(msg);
8420 return -ENOBUFS;
8421 }
8422 nla_nest_end(msg, data);
8423
8424 ret = send_and_recv_msgs(drv, msg, NULL, NULL);
8425 if (ret) {
8426 wpa_printf(MSG_DEBUG,
8427 "nl80211: Failed to invoke driver ACS function: %s",
8428 strerror(errno));
8429 }
8430 return ret;
8431}
8432
8433
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07008434const struct wpa_driver_ops wpa_driver_nl80211_ops = {
8435 .name = "nl80211",
8436 .desc = "Linux nl80211/cfg80211",
8437 .get_bssid = wpa_driver_nl80211_get_bssid,
8438 .get_ssid = wpa_driver_nl80211_get_ssid,
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08008439 .set_key = driver_nl80211_set_key,
8440 .scan2 = driver_nl80211_scan2,
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08008441 .sched_scan = wpa_driver_nl80211_sched_scan,
8442 .stop_sched_scan = wpa_driver_nl80211_stop_sched_scan,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07008443 .get_scan_results2 = wpa_driver_nl80211_get_scan_results,
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08008444 .deauthenticate = driver_nl80211_deauthenticate,
8445 .authenticate = driver_nl80211_authenticate,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07008446 .associate = wpa_driver_nl80211_associate,
8447 .global_init = nl80211_global_init,
8448 .global_deinit = nl80211_global_deinit,
8449 .init2 = wpa_driver_nl80211_init,
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08008450 .deinit = driver_nl80211_deinit,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07008451 .get_capa = wpa_driver_nl80211_get_capa,
8452 .set_operstate = wpa_driver_nl80211_set_operstate,
8453 .set_supp_port = wpa_driver_nl80211_set_supp_port,
8454 .set_country = wpa_driver_nl80211_set_country,
Dmitry Shmidtcce06662013-11-04 18:44:24 -08008455 .get_country = wpa_driver_nl80211_get_country,
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08008456 .set_ap = wpa_driver_nl80211_set_ap,
Dmitry Shmidt8bae4132013-06-06 11:25:10 -07008457 .set_acl = wpa_driver_nl80211_set_acl,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07008458 .if_add = wpa_driver_nl80211_if_add,
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08008459 .if_remove = driver_nl80211_if_remove,
8460 .send_mlme = driver_nl80211_send_mlme,
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08008461 .get_hw_feature_data = nl80211_get_hw_feature_data,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07008462 .sta_add = wpa_driver_nl80211_sta_add,
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08008463 .sta_remove = driver_nl80211_sta_remove,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07008464 .hapd_send_eapol = wpa_driver_nl80211_hapd_send_eapol,
8465 .sta_set_flags = wpa_driver_nl80211_sta_set_flags,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07008466 .hapd_init = i802_init,
8467 .hapd_deinit = i802_deinit,
Jouni Malinen75ecf522011-06-27 15:19:46 -07008468 .set_wds_sta = i802_set_wds_sta,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07008469 .get_seqnum = i802_get_seqnum,
8470 .flush = i802_flush,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07008471 .get_inact_sec = i802_get_inact_sec,
8472 .sta_clear_stats = i802_sta_clear_stats,
8473 .set_rts = i802_set_rts,
8474 .set_frag = i802_set_frag,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07008475 .set_tx_queue_params = i802_set_tx_queue_params,
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08008476 .set_sta_vlan = driver_nl80211_set_sta_vlan,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07008477 .sta_deauth = i802_sta_deauth,
8478 .sta_disassoc = i802_sta_disassoc,
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08008479 .read_sta_data = driver_nl80211_read_sta_data,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07008480 .set_freq = i802_set_freq,
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08008481 .send_action = driver_nl80211_send_action,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07008482 .send_action_cancel_wait = wpa_driver_nl80211_send_action_cancel_wait,
8483 .remain_on_channel = wpa_driver_nl80211_remain_on_channel,
8484 .cancel_remain_on_channel =
8485 wpa_driver_nl80211_cancel_remain_on_channel,
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08008486 .probe_req_report = driver_nl80211_probe_req_report,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07008487 .deinit_ap = wpa_driver_nl80211_deinit_ap,
Dmitry Shmidt04949592012-07-19 12:16:46 -07008488 .deinit_p2p_cli = wpa_driver_nl80211_deinit_p2p_cli,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07008489 .resume = wpa_driver_nl80211_resume,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07008490 .signal_monitor = nl80211_signal_monitor,
8491 .signal_poll = nl80211_signal_poll,
8492 .send_frame = nl80211_send_frame,
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08008493 .shared_freq = wpa_driver_nl80211_shared_freq,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07008494 .set_param = nl80211_set_param,
8495 .get_radio_name = nl80211_get_radio_name,
Jouni Malinen75ecf522011-06-27 15:19:46 -07008496 .add_pmkid = nl80211_add_pmkid,
8497 .remove_pmkid = nl80211_remove_pmkid,
8498 .flush_pmkid = nl80211_flush_pmkid,
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08008499 .set_rekey_info = nl80211_set_rekey_info,
8500 .poll_client = nl80211_poll_client,
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08008501 .set_p2p_powersave = nl80211_set_p2p_powersave,
Dmitry Shmidtea69e842013-05-13 14:52:28 -07008502 .start_dfs_cac = nl80211_start_radar_detection,
8503 .stop_ap = wpa_driver_nl80211_stop_ap,
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08008504#ifdef CONFIG_TDLS
8505 .send_tdls_mgmt = nl80211_send_tdls_mgmt,
8506 .tdls_oper = nl80211_tdls_oper,
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08008507 .tdls_enable_channel_switch = nl80211_tdls_enable_channel_switch,
8508 .tdls_disable_channel_switch = nl80211_tdls_disable_channel_switch,
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08008509#endif /* CONFIG_TDLS */
Dmitry Shmidt700a1372013-03-15 14:14:44 -07008510 .update_ft_ies = wpa_driver_nl80211_update_ft_ies,
Dmitry Shmidt34af3062013-07-11 10:46:32 -07008511 .get_mac_addr = wpa_driver_nl80211_get_macaddr,
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -07008512 .get_survey = wpa_driver_nl80211_get_survey,
Dmitry Shmidt56052862013-10-04 10:23:25 -07008513 .status = wpa_driver_nl80211_status,
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08008514 .switch_channel = nl80211_switch_channel,
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08008515#ifdef ANDROID_P2P
Dmitry Shmidt6e933c12011-09-27 12:29:26 -07008516 .set_noa = wpa_driver_set_p2p_noa,
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08008517 .get_noa = wpa_driver_get_p2p_noa,
Dmitry Shmidt6e933c12011-09-27 12:29:26 -07008518 .set_ap_wps_ie = wpa_driver_set_ap_wps_p2p_ie,
Dmitry Shmidt292b0c32013-11-22 12:54:42 -08008519#endif /* ANDROID_P2P */
Dmitry Shmidt738a26e2011-07-07 14:22:14 -07008520#ifdef ANDROID
8521 .driver_cmd = wpa_driver_nl80211_driver_cmd,
Dmitry Shmidt292b0c32013-11-22 12:54:42 -08008522#endif /* ANDROID */
Dmitry Shmidta38abf92014-03-06 13:38:44 -08008523 .vendor_cmd = nl80211_vendor_cmd,
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08008524 .set_qos_map = nl80211_set_qos_map,
Dmitry Shmidtb58836e2014-04-29 14:35:56 -07008525 .set_wowlan = nl80211_set_wowlan,
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07008526 .roaming = nl80211_roaming,
8527 .set_mac_addr = nl80211_set_mac_addr,
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08008528#ifdef CONFIG_MESH
8529 .init_mesh = wpa_driver_nl80211_init_mesh,
8530 .join_mesh = wpa_driver_nl80211_join_mesh,
8531 .leave_mesh = wpa_driver_nl80211_leave_mesh,
8532#endif /* CONFIG_MESH */
8533 .br_add_ip_neigh = wpa_driver_br_add_ip_neigh,
8534 .br_delete_ip_neigh = wpa_driver_br_delete_ip_neigh,
8535 .br_port_set_attr = wpa_driver_br_port_set_attr,
8536 .br_set_net_param = wpa_driver_br_set_net_param,
8537 .add_tx_ts = nl80211_add_ts,
8538 .del_tx_ts = nl80211_del_ts,
8539 .do_acs = wpa_driver_do_acs,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07008540};