blob: be0e7c5d901a026042df78d50085cf881558ba4a [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 Shmidtf73259c2015-03-17 11:00:54 -07001190 [NL80211_STA_INFO_BEACON_SIGNAL_AVG] = { .type = NLA_U8 },
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001191 };
1192 struct nlattr *rinfo[NL80211_RATE_INFO_MAX + 1];
1193 static struct nla_policy rate_policy[NL80211_RATE_INFO_MAX + 1] = {
1194 [NL80211_RATE_INFO_BITRATE] = { .type = NLA_U16 },
1195 [NL80211_RATE_INFO_MCS] = { .type = NLA_U8 },
1196 [NL80211_RATE_INFO_40_MHZ_WIDTH] = { .type = NLA_FLAG },
1197 [NL80211_RATE_INFO_SHORT_GI] = { .type = NLA_FLAG },
1198 };
1199 struct wpa_signal_info *sig_change = arg;
1200
1201 nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0),
1202 genlmsg_attrlen(gnlh, 0), NULL);
1203 if (!tb[NL80211_ATTR_STA_INFO] ||
1204 nla_parse_nested(sinfo, NL80211_STA_INFO_MAX,
1205 tb[NL80211_ATTR_STA_INFO], policy))
1206 return NL_SKIP;
1207 if (!sinfo[NL80211_STA_INFO_SIGNAL])
1208 return NL_SKIP;
1209
1210 sig_change->current_signal =
1211 (s8) nla_get_u8(sinfo[NL80211_STA_INFO_SIGNAL]);
1212
Dmitry Shmidt34af3062013-07-11 10:46:32 -07001213 if (sinfo[NL80211_STA_INFO_SIGNAL_AVG])
1214 sig_change->avg_signal =
1215 (s8) nla_get_u8(sinfo[NL80211_STA_INFO_SIGNAL_AVG]);
1216 else
1217 sig_change->avg_signal = 0;
1218
Dmitry Shmidtf73259c2015-03-17 11:00:54 -07001219 if (sinfo[NL80211_STA_INFO_BEACON_SIGNAL_AVG])
1220 sig_change->avg_beacon_signal =
1221 (s8)
1222 nla_get_u8(sinfo[NL80211_STA_INFO_BEACON_SIGNAL_AVG]);
1223 else
1224 sig_change->avg_beacon_signal = 0;
1225
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001226 if (sinfo[NL80211_STA_INFO_TX_BITRATE]) {
1227 if (nla_parse_nested(rinfo, NL80211_RATE_INFO_MAX,
1228 sinfo[NL80211_STA_INFO_TX_BITRATE],
1229 rate_policy)) {
1230 sig_change->current_txrate = 0;
1231 } else {
1232 if (rinfo[NL80211_RATE_INFO_BITRATE]) {
1233 sig_change->current_txrate =
1234 nla_get_u16(rinfo[
1235 NL80211_RATE_INFO_BITRATE]) * 100;
1236 }
1237 }
1238 }
1239
1240 return NL_SKIP;
1241}
1242
1243
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001244int nl80211_get_link_signal(struct wpa_driver_nl80211_data *drv,
1245 struct wpa_signal_info *sig)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001246{
1247 struct nl_msg *msg;
1248
1249 sig->current_signal = -9999;
1250 sig->current_txrate = 0;
1251
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001252 if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_GET_STATION)) ||
1253 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, drv->bssid)) {
1254 nlmsg_free(msg);
1255 return -ENOBUFS;
1256 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001257
1258 return send_and_recv_msgs(drv, msg, get_link_signal, sig);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001259}
1260
1261
1262static int get_link_noise(struct nl_msg *msg, void *arg)
1263{
1264 struct nlattr *tb[NL80211_ATTR_MAX + 1];
1265 struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg));
1266 struct nlattr *sinfo[NL80211_SURVEY_INFO_MAX + 1];
1267 static struct nla_policy survey_policy[NL80211_SURVEY_INFO_MAX + 1] = {
1268 [NL80211_SURVEY_INFO_FREQUENCY] = { .type = NLA_U32 },
1269 [NL80211_SURVEY_INFO_NOISE] = { .type = NLA_U8 },
1270 };
1271 struct wpa_signal_info *sig_change = arg;
1272
1273 nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0),
1274 genlmsg_attrlen(gnlh, 0), NULL);
1275
1276 if (!tb[NL80211_ATTR_SURVEY_INFO]) {
1277 wpa_printf(MSG_DEBUG, "nl80211: survey data missing!");
1278 return NL_SKIP;
1279 }
1280
1281 if (nla_parse_nested(sinfo, NL80211_SURVEY_INFO_MAX,
1282 tb[NL80211_ATTR_SURVEY_INFO],
1283 survey_policy)) {
1284 wpa_printf(MSG_DEBUG, "nl80211: failed to parse nested "
1285 "attributes!");
1286 return NL_SKIP;
1287 }
1288
1289 if (!sinfo[NL80211_SURVEY_INFO_FREQUENCY])
1290 return NL_SKIP;
1291
1292 if (nla_get_u32(sinfo[NL80211_SURVEY_INFO_FREQUENCY]) !=
1293 sig_change->frequency)
1294 return NL_SKIP;
1295
1296 if (!sinfo[NL80211_SURVEY_INFO_NOISE])
1297 return NL_SKIP;
1298
1299 sig_change->current_noise =
1300 (s8) nla_get_u8(sinfo[NL80211_SURVEY_INFO_NOISE]);
1301
1302 return NL_SKIP;
1303}
1304
1305
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001306int nl80211_get_link_noise(struct wpa_driver_nl80211_data *drv,
1307 struct wpa_signal_info *sig_change)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001308{
1309 struct nl_msg *msg;
1310
1311 sig_change->current_noise = 9999;
1312 sig_change->frequency = drv->assoc_freq;
1313
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001314 msg = nl80211_drv_msg(drv, NLM_F_DUMP, NL80211_CMD_GET_SURVEY);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001315 return send_and_recv_msgs(drv, msg, get_link_noise, sig_change);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001316}
1317
1318
1319static void wpa_driver_nl80211_event_receive(int sock, void *eloop_ctx,
1320 void *handle)
1321{
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001322 struct nl_cb *cb = eloop_ctx;
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -07001323 int res;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001324
Dmitry Shmidt8da800a2013-04-24 12:57:01 -07001325 wpa_printf(MSG_MSGDUMP, "nl80211: Event message available");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001326
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -07001327 res = nl_recvmsgs(handle, cb);
Dmitry Shmidt71757432014-06-02 13:50:35 -07001328 if (res < 0) {
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -07001329 wpa_printf(MSG_INFO, "nl80211: %s->nl_recvmsgs failed: %d",
1330 __func__, res);
1331 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001332}
1333
1334
1335/**
1336 * wpa_driver_nl80211_set_country - ask nl80211 to set the regulatory domain
1337 * @priv: driver_nl80211 private data
1338 * @alpha2_arg: country to which to switch to
1339 * Returns: 0 on success, -1 on failure
1340 *
1341 * This asks nl80211 to set the regulatory domain for given
1342 * country ISO / IEC alpha2.
1343 */
1344static int wpa_driver_nl80211_set_country(void *priv, const char *alpha2_arg)
1345{
1346 struct i802_bss *bss = priv;
1347 struct wpa_driver_nl80211_data *drv = bss->drv;
1348 char alpha2[3];
1349 struct nl_msg *msg;
1350
1351 msg = nlmsg_alloc();
1352 if (!msg)
1353 return -ENOMEM;
1354
1355 alpha2[0] = alpha2_arg[0];
1356 alpha2[1] = alpha2_arg[1];
1357 alpha2[2] = '\0';
1358
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001359 if (!nl80211_cmd(drv, msg, 0, NL80211_CMD_REQ_SET_REG) ||
1360 nla_put_string(msg, NL80211_ATTR_REG_ALPHA2, alpha2)) {
1361 nlmsg_free(msg);
1362 return -EINVAL;
1363 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001364 if (send_and_recv_msgs(drv, msg, NULL, NULL))
1365 return -EINVAL;
1366 return 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001367}
1368
1369
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001370static int nl80211_get_country(struct nl_msg *msg, void *arg)
1371{
1372 char *alpha2 = arg;
1373 struct nlattr *tb_msg[NL80211_ATTR_MAX + 1];
1374 struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg));
1375
1376 nla_parse(tb_msg, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0),
1377 genlmsg_attrlen(gnlh, 0), NULL);
1378 if (!tb_msg[NL80211_ATTR_REG_ALPHA2]) {
1379 wpa_printf(MSG_DEBUG, "nl80211: No country information available");
1380 return NL_SKIP;
1381 }
1382 os_strlcpy(alpha2, nla_data(tb_msg[NL80211_ATTR_REG_ALPHA2]), 3);
1383 return NL_SKIP;
1384}
1385
1386
1387static int wpa_driver_nl80211_get_country(void *priv, char *alpha2)
1388{
1389 struct i802_bss *bss = priv;
1390 struct wpa_driver_nl80211_data *drv = bss->drv;
1391 struct nl_msg *msg;
1392 int ret;
1393
1394 msg = nlmsg_alloc();
1395 if (!msg)
1396 return -ENOMEM;
1397
1398 nl80211_cmd(drv, msg, 0, NL80211_CMD_GET_REG);
1399 alpha2[0] = '\0';
1400 ret = send_and_recv_msgs(drv, msg, nl80211_get_country, alpha2);
1401 if (!alpha2[0])
1402 ret = -1;
1403
1404 return ret;
1405}
1406
1407
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001408static int wpa_driver_nl80211_init_nl_global(struct nl80211_global *global)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001409{
1410 int ret;
1411
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001412 global->nl_cb = nl_cb_alloc(NL_CB_DEFAULT);
1413 if (global->nl_cb == NULL) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001414 wpa_printf(MSG_ERROR, "nl80211: Failed to allocate netlink "
1415 "callbacks");
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001416 return -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001417 }
1418
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001419 global->nl = nl_create_handle(global->nl_cb, "nl");
1420 if (global->nl == NULL)
1421 goto err;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001422
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001423 global->nl80211_id = genl_ctrl_resolve(global->nl, "nl80211");
1424 if (global->nl80211_id < 0) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001425 wpa_printf(MSG_ERROR, "nl80211: 'nl80211' generic netlink not "
1426 "found");
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001427 goto err;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001428 }
1429
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001430 global->nl_event = nl_create_handle(global->nl_cb, "event");
1431 if (global->nl_event == NULL)
1432 goto err;
1433
1434 ret = nl_get_multicast_id(global, "nl80211", "scan");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001435 if (ret >= 0)
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001436 ret = nl_socket_add_membership(global->nl_event, ret);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001437 if (ret < 0) {
1438 wpa_printf(MSG_ERROR, "nl80211: Could not add multicast "
1439 "membership for scan events: %d (%s)",
1440 ret, strerror(-ret));
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001441 goto err;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001442 }
1443
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001444 ret = nl_get_multicast_id(global, "nl80211", "mlme");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001445 if (ret >= 0)
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001446 ret = nl_socket_add_membership(global->nl_event, ret);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001447 if (ret < 0) {
1448 wpa_printf(MSG_ERROR, "nl80211: Could not add multicast "
1449 "membership for mlme events: %d (%s)",
1450 ret, strerror(-ret));
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001451 goto err;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001452 }
1453
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001454 ret = nl_get_multicast_id(global, "nl80211", "regulatory");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001455 if (ret >= 0)
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001456 ret = nl_socket_add_membership(global->nl_event, ret);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001457 if (ret < 0) {
1458 wpa_printf(MSG_DEBUG, "nl80211: Could not add multicast "
1459 "membership for regulatory events: %d (%s)",
1460 ret, strerror(-ret));
1461 /* Continue without regulatory events */
1462 }
1463
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001464 ret = nl_get_multicast_id(global, "nl80211", "vendor");
1465 if (ret >= 0)
1466 ret = nl_socket_add_membership(global->nl_event, ret);
1467 if (ret < 0) {
1468 wpa_printf(MSG_DEBUG, "nl80211: Could not add multicast "
1469 "membership for vendor events: %d (%s)",
1470 ret, strerror(-ret));
1471 /* Continue without vendor events */
1472 }
1473
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001474 nl_cb_set(global->nl_cb, NL_CB_SEQ_CHECK, NL_CB_CUSTOM,
1475 no_seq_check, NULL);
1476 nl_cb_set(global->nl_cb, NL_CB_VALID, NL_CB_CUSTOM,
1477 process_global_event, global);
1478
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -07001479 nl80211_register_eloop_read(&global->nl_event,
1480 wpa_driver_nl80211_event_receive,
1481 global->nl_cb);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001482
1483 return 0;
1484
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001485err:
1486 nl_destroy_handles(&global->nl_event);
1487 nl_destroy_handles(&global->nl);
1488 nl_cb_put(global->nl_cb);
1489 global->nl_cb = NULL;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001490 return -1;
1491}
1492
1493
Dmitry Shmidt7f656022015-02-25 14:36:37 -08001494static void nl80211_check_global(struct nl80211_global *global)
1495{
1496 struct nl_handle *handle;
1497 const char *groups[] = { "scan", "mlme", "regulatory", "vendor", NULL };
1498 int ret;
1499 unsigned int i;
1500
1501 /*
1502 * Try to re-add memberships to handle case of cfg80211 getting reloaded
1503 * and all registration having been cleared.
1504 */
1505 handle = (void *) (((intptr_t) global->nl_event) ^
1506 ELOOP_SOCKET_INVALID);
1507
1508 for (i = 0; groups[i]; i++) {
1509 ret = nl_get_multicast_id(global, "nl80211", groups[i]);
1510 if (ret >= 0)
1511 ret = nl_socket_add_membership(handle, ret);
1512 if (ret < 0) {
1513 wpa_printf(MSG_INFO,
1514 "nl80211: Could not re-add multicast membership for %s events: %d (%s)",
1515 groups[i], ret, strerror(-ret));
1516 }
1517 }
1518}
1519
1520
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001521static void wpa_driver_nl80211_rfkill_blocked(void *ctx)
1522{
1523 wpa_printf(MSG_DEBUG, "nl80211: RFKILL blocked");
1524 /*
1525 * This may be for any interface; use ifdown event to disable
1526 * interface.
1527 */
1528}
1529
1530
1531static void wpa_driver_nl80211_rfkill_unblocked(void *ctx)
1532{
1533 struct wpa_driver_nl80211_data *drv = ctx;
1534 wpa_printf(MSG_DEBUG, "nl80211: RFKILL unblocked");
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001535 if (i802_set_iface_flags(drv->first_bss, 1)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001536 wpa_printf(MSG_DEBUG, "nl80211: Could not set interface UP "
1537 "after rfkill unblock");
1538 return;
1539 }
1540 /* rtnetlink ifup handler will report interface as enabled */
1541}
1542
1543
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001544static void wpa_driver_nl80211_handle_eapol_tx_status(int sock,
1545 void *eloop_ctx,
1546 void *handle)
1547{
1548 struct wpa_driver_nl80211_data *drv = eloop_ctx;
1549 u8 data[2048];
1550 struct msghdr msg;
1551 struct iovec entry;
Dmitry Shmidt04949592012-07-19 12:16:46 -07001552 u8 control[512];
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001553 struct cmsghdr *cmsg;
1554 int res, found_ee = 0, found_wifi = 0, acked = 0;
1555 union wpa_event_data event;
1556
1557 memset(&msg, 0, sizeof(msg));
1558 msg.msg_iov = &entry;
1559 msg.msg_iovlen = 1;
1560 entry.iov_base = data;
1561 entry.iov_len = sizeof(data);
1562 msg.msg_control = &control;
1563 msg.msg_controllen = sizeof(control);
1564
1565 res = recvmsg(sock, &msg, MSG_ERRQUEUE);
1566 /* if error or not fitting 802.3 header, return */
1567 if (res < 14)
1568 return;
1569
1570 for (cmsg = CMSG_FIRSTHDR(&msg); cmsg; cmsg = CMSG_NXTHDR(&msg, cmsg))
1571 {
1572 if (cmsg->cmsg_level == SOL_SOCKET &&
1573 cmsg->cmsg_type == SCM_WIFI_STATUS) {
1574 int *ack;
1575
1576 found_wifi = 1;
1577 ack = (void *)CMSG_DATA(cmsg);
1578 acked = *ack;
1579 }
1580
1581 if (cmsg->cmsg_level == SOL_PACKET &&
1582 cmsg->cmsg_type == PACKET_TX_TIMESTAMP) {
1583 struct sock_extended_err *err =
1584 (struct sock_extended_err *)CMSG_DATA(cmsg);
1585
1586 if (err->ee_origin == SO_EE_ORIGIN_TXSTATUS)
1587 found_ee = 1;
1588 }
1589 }
1590
1591 if (!found_ee || !found_wifi)
1592 return;
1593
1594 memset(&event, 0, sizeof(event));
1595 event.eapol_tx_status.dst = data;
1596 event.eapol_tx_status.data = data + 14;
1597 event.eapol_tx_status.data_len = res - 14;
1598 event.eapol_tx_status.ack = acked;
1599 wpa_supplicant_event(drv->ctx, EVENT_EAPOL_TX_STATUS, &event);
1600}
1601
1602
1603static int nl80211_init_bss(struct i802_bss *bss)
1604{
1605 bss->nl_cb = nl_cb_alloc(NL_CB_DEFAULT);
1606 if (!bss->nl_cb)
1607 return -1;
1608
1609 nl_cb_set(bss->nl_cb, NL_CB_SEQ_CHECK, NL_CB_CUSTOM,
1610 no_seq_check, NULL);
1611 nl_cb_set(bss->nl_cb, NL_CB_VALID, NL_CB_CUSTOM,
1612 process_bss_event, bss);
1613
1614 return 0;
1615}
1616
1617
1618static void nl80211_destroy_bss(struct i802_bss *bss)
1619{
1620 nl_cb_put(bss->nl_cb);
1621 bss->nl_cb = NULL;
1622}
1623
1624
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08001625static void * wpa_driver_nl80211_drv_init(void *ctx, const char *ifname,
1626 void *global_priv, int hostapd,
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001627 const u8 *set_addr,
1628 const char *driver_params)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001629{
1630 struct wpa_driver_nl80211_data *drv;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001631 struct rfkill_config *rcfg;
1632 struct i802_bss *bss;
1633
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001634 if (global_priv == NULL)
1635 return NULL;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001636 drv = os_zalloc(sizeof(*drv));
1637 if (drv == NULL)
1638 return NULL;
1639 drv->global = global_priv;
1640 drv->ctx = ctx;
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08001641 drv->hostapd = !!hostapd;
1642 drv->eapol_sock = -1;
Dmitry Shmidtff787d52015-01-12 13:01:47 -08001643
1644 /*
1645 * There is no driver capability flag for this, so assume it is
1646 * supported and disable this on first attempt to use if the driver
1647 * rejects the command due to missing support.
1648 */
1649 drv->set_rekey_offload = 1;
1650
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08001651 drv->num_if_indices = sizeof(drv->default_if_indices) / sizeof(int);
1652 drv->if_indices = drv->default_if_indices;
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001653
1654 drv->first_bss = os_zalloc(sizeof(*drv->first_bss));
1655 if (!drv->first_bss) {
1656 os_free(drv);
1657 return NULL;
1658 }
1659 bss = drv->first_bss;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001660 bss->drv = drv;
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08001661 bss->ctx = ctx;
1662
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001663 os_strlcpy(bss->ifname, ifname, sizeof(bss->ifname));
1664 drv->monitor_ifidx = -1;
1665 drv->monitor_sock = -1;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001666 drv->eapol_tx_sock = -1;
1667 drv->ap_scan_as_station = NL80211_IFTYPE_UNSPECIFIED;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001668
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001669 if (nl80211_init_bss(bss))
1670 goto failed;
1671
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001672 rcfg = os_zalloc(sizeof(*rcfg));
1673 if (rcfg == NULL)
1674 goto failed;
1675 rcfg->ctx = drv;
1676 os_strlcpy(rcfg->ifname, ifname, sizeof(rcfg->ifname));
1677 rcfg->blocked_cb = wpa_driver_nl80211_rfkill_blocked;
1678 rcfg->unblocked_cb = wpa_driver_nl80211_rfkill_unblocked;
1679 drv->rfkill = rfkill_init(rcfg);
1680 if (drv->rfkill == NULL) {
1681 wpa_printf(MSG_DEBUG, "nl80211: RFKILL status not available");
1682 os_free(rcfg);
1683 }
1684
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08001685 if (linux_iface_up(drv->global->ioctl_sock, ifname) > 0)
1686 drv->start_iface_up = 1;
1687
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001688 if (wpa_driver_nl80211_finish_drv_init(drv, set_addr, 1, driver_params))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001689 goto failed;
1690
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001691 drv->eapol_tx_sock = socket(PF_PACKET, SOCK_DGRAM, 0);
1692 if (drv->eapol_tx_sock < 0)
1693 goto failed;
1694
1695 if (drv->data_tx_status) {
1696 int enabled = 1;
1697
1698 if (setsockopt(drv->eapol_tx_sock, SOL_SOCKET, SO_WIFI_STATUS,
1699 &enabled, sizeof(enabled)) < 0) {
1700 wpa_printf(MSG_DEBUG,
1701 "nl80211: wifi status sockopt failed\n");
1702 drv->data_tx_status = 0;
1703 if (!drv->use_monitor)
1704 drv->capa.flags &=
1705 ~WPA_DRIVER_FLAGS_EAPOL_TX_STATUS;
1706 } else {
1707 eloop_register_read_sock(drv->eapol_tx_sock,
1708 wpa_driver_nl80211_handle_eapol_tx_status,
1709 drv, NULL);
1710 }
1711 }
1712
1713 if (drv->global) {
Dmitry Shmidt7f656022015-02-25 14:36:37 -08001714 nl80211_check_global(drv->global);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001715 dl_list_add(&drv->global->interfaces, &drv->list);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001716 drv->in_interface_list = 1;
1717 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001718
1719 return bss;
1720
1721failed:
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001722 wpa_driver_nl80211_deinit(bss);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001723 return NULL;
1724}
1725
1726
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08001727/**
1728 * wpa_driver_nl80211_init - Initialize nl80211 driver interface
1729 * @ctx: context to be used when calling wpa_supplicant functions,
1730 * e.g., wpa_supplicant_event()
1731 * @ifname: interface name, e.g., wlan0
1732 * @global_priv: private driver global data from global_init()
1733 * Returns: Pointer to private data, %NULL on failure
1734 */
1735static void * wpa_driver_nl80211_init(void *ctx, const char *ifname,
1736 void *global_priv)
1737{
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001738 return wpa_driver_nl80211_drv_init(ctx, ifname, global_priv, 0, NULL,
1739 NULL);
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08001740}
1741
1742
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001743static int nl80211_register_frame(struct i802_bss *bss,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001744 struct nl_handle *nl_handle,
1745 u16 type, const u8 *match, size_t match_len)
1746{
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001747 struct wpa_driver_nl80211_data *drv = bss->drv;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001748 struct nl_msg *msg;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001749 int ret;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001750 char buf[30];
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001751
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001752 buf[0] = '\0';
1753 wpa_snprintf_hex(buf, sizeof(buf), match, match_len);
Dmitry Shmidt2271d3f2014-06-23 12:16:31 -07001754 wpa_printf(MSG_DEBUG, "nl80211: Register frame type=0x%x (%s) nl_handle=%p match=%s",
1755 type, fc2str(type), nl_handle, buf);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001756
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001757 if (!(msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_REGISTER_ACTION)) ||
1758 nla_put_u16(msg, NL80211_ATTR_FRAME_TYPE, type) ||
1759 nla_put(msg, NL80211_ATTR_FRAME_MATCH, match_len, match)) {
1760 nlmsg_free(msg);
1761 return -1;
1762 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001763
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001764 ret = send_and_recv(drv->global, nl_handle, msg, NULL, NULL);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001765 if (ret) {
1766 wpa_printf(MSG_DEBUG, "nl80211: Register frame command "
1767 "failed (type=%u): ret=%d (%s)",
1768 type, ret, strerror(-ret));
1769 wpa_hexdump(MSG_DEBUG, "nl80211: Register frame match",
1770 match, match_len);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001771 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001772 return ret;
1773}
1774
1775
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001776static int nl80211_alloc_mgmt_handle(struct i802_bss *bss)
1777{
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001778 if (bss->nl_mgmt) {
1779 wpa_printf(MSG_DEBUG, "nl80211: Mgmt reporting "
1780 "already on! (nl_mgmt=%p)", bss->nl_mgmt);
1781 return -1;
1782 }
1783
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001784 bss->nl_mgmt = nl_create_handle(bss->nl_cb, "mgmt");
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001785 if (bss->nl_mgmt == NULL)
1786 return -1;
1787
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001788 return 0;
1789}
1790
1791
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -07001792static void nl80211_mgmt_handle_register_eloop(struct i802_bss *bss)
1793{
1794 nl80211_register_eloop_read(&bss->nl_mgmt,
1795 wpa_driver_nl80211_event_receive,
1796 bss->nl_cb);
1797}
1798
1799
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001800static int nl80211_register_action_frame(struct i802_bss *bss,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001801 const u8 *match, size_t match_len)
1802{
1803 u16 type = (WLAN_FC_TYPE_MGMT << 2) | (WLAN_FC_STYPE_ACTION << 4);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001804 return nl80211_register_frame(bss, bss->nl_mgmt,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001805 type, match, match_len);
1806}
1807
1808
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001809static int nl80211_mgmt_subscribe_non_ap(struct i802_bss *bss)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001810{
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001811 struct wpa_driver_nl80211_data *drv = bss->drv;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001812 int ret = 0;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001813
1814 if (nl80211_alloc_mgmt_handle(bss))
1815 return -1;
1816 wpa_printf(MSG_DEBUG, "nl80211: Subscribe to mgmt frames with non-AP "
1817 "handle %p", bss->nl_mgmt);
1818
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -07001819 if (drv->nlmode == NL80211_IFTYPE_ADHOC) {
1820 u16 type = (WLAN_FC_TYPE_MGMT << 2) | (WLAN_FC_STYPE_AUTH << 4);
1821
1822 /* register for any AUTH message */
1823 nl80211_register_frame(bss, bss->nl_mgmt, type, NULL, 0);
1824 }
1825
Dmitry Shmidt051af732013-10-22 13:52:46 -07001826#ifdef CONFIG_INTERWORKING
1827 /* QoS Map Configure */
1828 if (nl80211_register_action_frame(bss, (u8 *) "\x01\x04", 2) < 0)
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001829 ret = -1;
Dmitry Shmidt051af732013-10-22 13:52:46 -07001830#endif /* CONFIG_INTERWORKING */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001831#if defined(CONFIG_P2P) || defined(CONFIG_INTERWORKING)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001832 /* GAS Initial Request */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001833 if (nl80211_register_action_frame(bss, (u8 *) "\x04\x0a", 2) < 0)
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001834 ret = -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001835 /* GAS Initial Response */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001836 if (nl80211_register_action_frame(bss, (u8 *) "\x04\x0b", 2) < 0)
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001837 ret = -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001838 /* GAS Comeback Request */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001839 if (nl80211_register_action_frame(bss, (u8 *) "\x04\x0c", 2) < 0)
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001840 ret = -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001841 /* GAS Comeback Response */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001842 if (nl80211_register_action_frame(bss, (u8 *) "\x04\x0d", 2) < 0)
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001843 ret = -1;
Dmitry Shmidt18463232014-01-24 12:29:41 -08001844 /* Protected GAS Initial Request */
1845 if (nl80211_register_action_frame(bss, (u8 *) "\x09\x0a", 2) < 0)
1846 ret = -1;
1847 /* Protected GAS Initial Response */
1848 if (nl80211_register_action_frame(bss, (u8 *) "\x09\x0b", 2) < 0)
1849 ret = -1;
1850 /* Protected GAS Comeback Request */
1851 if (nl80211_register_action_frame(bss, (u8 *) "\x09\x0c", 2) < 0)
1852 ret = -1;
1853 /* Protected GAS Comeback Response */
1854 if (nl80211_register_action_frame(bss, (u8 *) "\x09\x0d", 2) < 0)
1855 ret = -1;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001856#endif /* CONFIG_P2P || CONFIG_INTERWORKING */
1857#ifdef CONFIG_P2P
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001858 /* P2P Public Action */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001859 if (nl80211_register_action_frame(bss,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001860 (u8 *) "\x04\x09\x50\x6f\x9a\x09",
1861 6) < 0)
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001862 ret = -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001863 /* P2P Action */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001864 if (nl80211_register_action_frame(bss,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001865 (u8 *) "\x7f\x50\x6f\x9a\x09",
1866 5) < 0)
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001867 ret = -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001868#endif /* CONFIG_P2P */
1869#ifdef CONFIG_IEEE80211W
1870 /* SA Query Response */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001871 if (nl80211_register_action_frame(bss, (u8 *) "\x08\x01", 2) < 0)
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001872 ret = -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001873#endif /* CONFIG_IEEE80211W */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001874#ifdef CONFIG_TDLS
1875 if ((drv->capa.flags & WPA_DRIVER_FLAGS_TDLS_SUPPORT)) {
1876 /* TDLS Discovery Response */
1877 if (nl80211_register_action_frame(bss, (u8 *) "\x04\x0e", 2) <
1878 0)
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001879 ret = -1;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001880 }
1881#endif /* CONFIG_TDLS */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001882
1883 /* FT Action frames */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001884 if (nl80211_register_action_frame(bss, (u8 *) "\x06", 1) < 0)
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001885 ret = -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001886 else
1887 drv->capa.key_mgmt |= WPA_DRIVER_CAPA_KEY_MGMT_FT |
1888 WPA_DRIVER_CAPA_KEY_MGMT_FT_PSK;
1889
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001890 /* WNM - BSS Transition Management Request */
1891 if (nl80211_register_action_frame(bss, (u8 *) "\x0a\x07", 2) < 0)
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001892 ret = -1;
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08001893 /* WNM-Sleep Mode Response */
1894 if (nl80211_register_action_frame(bss, (u8 *) "\x0a\x11", 2) < 0)
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001895 ret = -1;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001896
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08001897#ifdef CONFIG_HS20
1898 /* WNM-Notification */
1899 if (nl80211_register_action_frame(bss, (u8 *) "\x0a\x1a", 2) < 0)
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07001900 ret = -1;
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08001901#endif /* CONFIG_HS20 */
1902
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001903 /* WMM-AC ADDTS Response */
1904 if (nl80211_register_action_frame(bss, (u8 *) "\x11\x01", 2) < 0)
1905 ret = -1;
1906
1907 /* WMM-AC DELTS */
1908 if (nl80211_register_action_frame(bss, (u8 *) "\x11\x02", 2) < 0)
1909 ret = -1;
1910
1911 /* Radio Measurement - Neighbor Report Response */
1912 if (nl80211_register_action_frame(bss, (u8 *) "\x05\x05", 2) < 0)
1913 ret = -1;
1914
1915 /* Radio Measurement - Link Measurement Request */
1916 if ((drv->capa.rrm_flags & WPA_DRIVER_FLAGS_TX_POWER_INSERTION) &&
1917 (nl80211_register_action_frame(bss, (u8 *) "\x05\x02", 2) < 0))
1918 ret = -1;
1919
1920 nl80211_mgmt_handle_register_eloop(bss);
1921
1922 return ret;
1923}
1924
1925
1926static int nl80211_mgmt_subscribe_mesh(struct i802_bss *bss)
1927{
1928 int ret = 0;
1929
1930 if (nl80211_alloc_mgmt_handle(bss))
1931 return -1;
1932
1933 wpa_printf(MSG_DEBUG,
1934 "nl80211: Subscribe to mgmt frames with mesh handle %p",
1935 bss->nl_mgmt);
1936
1937 /* Auth frames for mesh SAE */
1938 if (nl80211_register_frame(bss, bss->nl_mgmt,
1939 (WLAN_FC_TYPE_MGMT << 2) |
1940 (WLAN_FC_STYPE_AUTH << 4),
1941 NULL, 0) < 0)
1942 ret = -1;
1943
1944 /* Mesh peering open */
1945 if (nl80211_register_action_frame(bss, (u8 *) "\x0f\x01", 2) < 0)
1946 ret = -1;
1947 /* Mesh peering confirm */
1948 if (nl80211_register_action_frame(bss, (u8 *) "\x0f\x02", 2) < 0)
1949 ret = -1;
1950 /* Mesh peering close */
1951 if (nl80211_register_action_frame(bss, (u8 *) "\x0f\x03", 2) < 0)
1952 ret = -1;
1953
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -07001954 nl80211_mgmt_handle_register_eloop(bss);
1955
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001956 return ret;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001957}
1958
1959
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001960static int nl80211_register_spurious_class3(struct i802_bss *bss)
1961{
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001962 struct nl_msg *msg;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001963 int ret;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001964
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001965 msg = nl80211_bss_msg(bss, 0, NL80211_CMD_UNEXPECTED_FRAME);
1966 ret = send_and_recv(bss->drv->global, bss->nl_mgmt, msg, NULL, NULL);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001967 if (ret) {
1968 wpa_printf(MSG_DEBUG, "nl80211: Register spurious class3 "
1969 "failed: ret=%d (%s)",
1970 ret, strerror(-ret));
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001971 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001972 return ret;
1973}
1974
1975
1976static int nl80211_mgmt_subscribe_ap(struct i802_bss *bss)
1977{
1978 static const int stypes[] = {
1979 WLAN_FC_STYPE_AUTH,
1980 WLAN_FC_STYPE_ASSOC_REQ,
1981 WLAN_FC_STYPE_REASSOC_REQ,
1982 WLAN_FC_STYPE_DISASSOC,
1983 WLAN_FC_STYPE_DEAUTH,
1984 WLAN_FC_STYPE_ACTION,
1985 WLAN_FC_STYPE_PROBE_REQ,
1986/* Beacon doesn't work as mac80211 doesn't currently allow
1987 * it, but it wouldn't really be the right thing anyway as
1988 * it isn't per interface ... maybe just dump the scan
1989 * results periodically for OLBC?
1990 */
Dmitry Shmidt7832adb2014-04-29 10:53:02 -07001991 /* WLAN_FC_STYPE_BEACON, */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001992 };
1993 unsigned int i;
1994
1995 if (nl80211_alloc_mgmt_handle(bss))
1996 return -1;
1997 wpa_printf(MSG_DEBUG, "nl80211: Subscribe to mgmt frames with AP "
1998 "handle %p", bss->nl_mgmt);
1999
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -07002000 for (i = 0; i < ARRAY_SIZE(stypes); i++) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002001 if (nl80211_register_frame(bss, bss->nl_mgmt,
2002 (WLAN_FC_TYPE_MGMT << 2) |
2003 (stypes[i] << 4),
2004 NULL, 0) < 0) {
2005 goto out_err;
2006 }
2007 }
2008
2009 if (nl80211_register_spurious_class3(bss))
2010 goto out_err;
2011
2012 if (nl80211_get_wiphy_data_ap(bss) == NULL)
2013 goto out_err;
2014
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -07002015 nl80211_mgmt_handle_register_eloop(bss);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002016 return 0;
2017
2018out_err:
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002019 nl_destroy_handles(&bss->nl_mgmt);
2020 return -1;
2021}
2022
2023
2024static int nl80211_mgmt_subscribe_ap_dev_sme(struct i802_bss *bss)
2025{
2026 if (nl80211_alloc_mgmt_handle(bss))
2027 return -1;
2028 wpa_printf(MSG_DEBUG, "nl80211: Subscribe to mgmt frames with AP "
2029 "handle %p (device SME)", bss->nl_mgmt);
2030
2031 if (nl80211_register_frame(bss, bss->nl_mgmt,
2032 (WLAN_FC_TYPE_MGMT << 2) |
2033 (WLAN_FC_STYPE_ACTION << 4),
2034 NULL, 0) < 0)
2035 goto out_err;
2036
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -07002037 nl80211_mgmt_handle_register_eloop(bss);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002038 return 0;
2039
2040out_err:
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002041 nl_destroy_handles(&bss->nl_mgmt);
2042 return -1;
2043}
2044
2045
2046static void nl80211_mgmt_unsubscribe(struct i802_bss *bss, const char *reason)
2047{
2048 if (bss->nl_mgmt == NULL)
2049 return;
2050 wpa_printf(MSG_DEBUG, "nl80211: Unsubscribe mgmt frames handle %p "
2051 "(%s)", bss->nl_mgmt, reason);
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -07002052 nl80211_destroy_eloop_handle(&bss->nl_mgmt);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002053
2054 nl80211_put_wiphy_data_ap(bss);
2055}
2056
2057
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002058static void wpa_driver_nl80211_send_rfkill(void *eloop_ctx, void *timeout_ctx)
2059{
2060 wpa_supplicant_event(timeout_ctx, EVENT_INTERFACE_DISABLED, NULL);
2061}
2062
2063
Dmitry Shmidt34af3062013-07-11 10:46:32 -07002064static void nl80211_del_p2pdev(struct i802_bss *bss)
2065{
Dmitry Shmidt34af3062013-07-11 10:46:32 -07002066 struct nl_msg *msg;
2067 int ret;
2068
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002069 msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_DEL_INTERFACE);
2070 ret = send_and_recv_msgs(bss->drv, msg, NULL, NULL);
Dmitry Shmidt34af3062013-07-11 10:46:32 -07002071
2072 wpa_printf(MSG_DEBUG, "nl80211: Delete P2P Device %s (0x%llx): %s",
2073 bss->ifname, (long long unsigned int) bss->wdev_id,
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -07002074 strerror(-ret));
Dmitry Shmidt34af3062013-07-11 10:46:32 -07002075}
2076
2077
2078static int nl80211_set_p2pdev(struct i802_bss *bss, int start)
2079{
Dmitry Shmidt34af3062013-07-11 10:46:32 -07002080 struct nl_msg *msg;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002081 int ret;
Dmitry Shmidt34af3062013-07-11 10:46:32 -07002082
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002083 msg = nl80211_cmd_msg(bss, 0, start ? NL80211_CMD_START_P2P_DEVICE :
2084 NL80211_CMD_STOP_P2P_DEVICE);
2085 ret = send_and_recv_msgs(bss->drv, msg, NULL, NULL);
Dmitry Shmidt34af3062013-07-11 10:46:32 -07002086
2087 wpa_printf(MSG_DEBUG, "nl80211: %s P2P Device %s (0x%llx): %s",
2088 start ? "Start" : "Stop",
2089 bss->ifname, (long long unsigned int) bss->wdev_id,
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -07002090 strerror(-ret));
Dmitry Shmidt34af3062013-07-11 10:46:32 -07002091 return ret;
2092}
2093
2094
2095static int i802_set_iface_flags(struct i802_bss *bss, int up)
2096{
2097 enum nl80211_iftype nlmode;
2098
2099 nlmode = nl80211_get_ifmode(bss);
2100 if (nlmode != NL80211_IFTYPE_P2P_DEVICE) {
2101 return linux_set_iface_flags(bss->drv->global->ioctl_sock,
2102 bss->ifname, up);
2103 }
2104
2105 /* P2P Device has start/stop which is equivalent */
2106 return nl80211_set_p2pdev(bss, up);
2107}
2108
2109
Dmitry Shmidt7f656022015-02-25 14:36:37 -08002110#ifdef CONFIG_TESTING_OPTIONS
2111static int qca_vendor_test_cmd_handler(struct nl_msg *msg, void *arg)
2112{
2113 /* struct wpa_driver_nl80211_data *drv = arg; */
2114 struct nlattr *tb[NL80211_ATTR_MAX + 1];
2115 struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg));
2116
2117
2118 wpa_printf(MSG_DEBUG,
2119 "nl80211: QCA vendor test command response received");
2120
2121 nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0),
2122 genlmsg_attrlen(gnlh, 0), NULL);
2123 if (!tb[NL80211_ATTR_VENDOR_DATA]) {
2124 wpa_printf(MSG_DEBUG, "nl80211: No vendor data attribute");
2125 return NL_SKIP;
2126 }
2127
2128 wpa_hexdump(MSG_DEBUG,
2129 "nl80211: Received QCA vendor test command response",
2130 nla_data(tb[NL80211_ATTR_VENDOR_DATA]),
2131 nla_len(tb[NL80211_ATTR_VENDOR_DATA]));
2132
2133 return NL_SKIP;
2134}
2135#endif /* CONFIG_TESTING_OPTIONS */
2136
2137
2138static void qca_vendor_test(struct wpa_driver_nl80211_data *drv)
2139{
2140#ifdef CONFIG_TESTING_OPTIONS
2141 struct nl_msg *msg;
2142 struct nlattr *params;
2143 int ret;
2144
2145 if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_VENDOR)) ||
2146 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
2147 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
2148 QCA_NL80211_VENDOR_SUBCMD_TEST) ||
2149 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
2150 nla_put_u32(msg, QCA_WLAN_VENDOR_ATTR_TEST, 123)) {
2151 nlmsg_free(msg);
2152 return;
2153 }
2154 nla_nest_end(msg, params);
2155
2156 ret = send_and_recv_msgs(drv, msg, qca_vendor_test_cmd_handler, drv);
2157 wpa_printf(MSG_DEBUG,
2158 "nl80211: QCA vendor test command returned %d (%s)",
2159 ret, strerror(-ret));
2160#endif /* CONFIG_TESTING_OPTIONS */
2161}
2162
2163
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002164static int
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08002165wpa_driver_nl80211_finish_drv_init(struct wpa_driver_nl80211_data *drv,
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002166 const u8 *set_addr, int first,
2167 const char *driver_params)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002168{
Dmitry Shmidtcce06662013-11-04 18:44:24 -08002169 struct i802_bss *bss = drv->first_bss;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002170 int send_rfkill_event = 0;
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08002171 enum nl80211_iftype nlmode;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002172
2173 drv->ifindex = if_nametoindex(bss->ifname);
Dmitry Shmidt34af3062013-07-11 10:46:32 -07002174 bss->ifindex = drv->ifindex;
2175 bss->wdev_id = drv->global->if_add_wdevid;
2176 bss->wdev_id_set = drv->global->if_add_wdevid_set;
2177
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -07002178 bss->if_dynamic = drv->ifindex == drv->global->if_add_ifindex;
2179 bss->if_dynamic = bss->if_dynamic || drv->global->if_add_wdevid_set;
Dmitry Shmidt34af3062013-07-11 10:46:32 -07002180 drv->global->if_add_wdevid_set = 0;
2181
Dmitry Shmidt03658832014-08-13 11:03:49 -07002182 if (!bss->if_dynamic && nl80211_get_ifmode(bss) == NL80211_IFTYPE_AP)
2183 bss->static_ap = 1;
2184
Dmitry Shmidt34af3062013-07-11 10:46:32 -07002185 if (wpa_driver_nl80211_capa(drv))
2186 return -1;
2187
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002188 if (driver_params && nl80211_set_param(bss, driver_params) < 0)
2189 return -1;
2190
Dmitry Shmidt34af3062013-07-11 10:46:32 -07002191 wpa_printf(MSG_DEBUG, "nl80211: interface %s in phy %s",
2192 bss->ifname, drv->phyname);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002193
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08002194 if (set_addr &&
2195 (linux_set_iface_flags(drv->global->ioctl_sock, bss->ifname, 0) ||
2196 linux_set_ifhwaddr(drv->global->ioctl_sock, bss->ifname,
2197 set_addr)))
2198 return -1;
Dmitry Shmidt34af3062013-07-11 10:46:32 -07002199
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08002200 if (first && nl80211_get_ifmode(bss) == NL80211_IFTYPE_AP)
2201 drv->start_mode_ap = 1;
2202
Dmitry Shmidt03658832014-08-13 11:03:49 -07002203 if (drv->hostapd || bss->static_ap)
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08002204 nlmode = NL80211_IFTYPE_AP;
2205 else if (bss->if_dynamic)
2206 nlmode = nl80211_get_ifmode(bss);
2207 else
2208 nlmode = NL80211_IFTYPE_STATION;
2209
Dmitry Shmidt34af3062013-07-11 10:46:32 -07002210 if (wpa_driver_nl80211_set_mode(bss, nlmode) < 0) {
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08002211 wpa_printf(MSG_ERROR, "nl80211: Could not configure driver mode");
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002212 return -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002213 }
Dmitry Shmidt34af3062013-07-11 10:46:32 -07002214
Dmitry Shmidt98660862014-03-11 17:26:21 -07002215 if (nlmode == NL80211_IFTYPE_P2P_DEVICE)
Dmitry Shmidt34af3062013-07-11 10:46:32 -07002216 nl80211_get_macaddr(bss);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002217
Dmitry Shmidt98660862014-03-11 17:26:21 -07002218 if (!rfkill_is_blocked(drv->rfkill)) {
2219 int ret = i802_set_iface_flags(bss, 1);
2220 if (ret) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002221 wpa_printf(MSG_ERROR, "nl80211: Could not set "
2222 "interface '%s' UP", bss->ifname);
Dmitry Shmidt98660862014-03-11 17:26:21 -07002223 return ret;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002224 }
Dmitry Shmidt98660862014-03-11 17:26:21 -07002225 if (nlmode == NL80211_IFTYPE_P2P_DEVICE)
2226 return ret;
2227 } else {
2228 wpa_printf(MSG_DEBUG, "nl80211: Could not yet enable "
2229 "interface '%s' due to rfkill", bss->ifname);
2230 if (nlmode == NL80211_IFTYPE_P2P_DEVICE)
2231 return 0;
2232 drv->if_disabled = 1;
2233 send_rfkill_event = 1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002234 }
2235
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08002236 if (!drv->hostapd)
2237 netlink_send_oper_ifla(drv->global->netlink, drv->ifindex,
2238 1, IF_OPER_DORMANT);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002239
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002240 if (linux_get_ifhwaddr(drv->global->ioctl_sock, bss->ifname,
2241 bss->addr))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002242 return -1;
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07002243 os_memcpy(drv->perm_addr, bss->addr, ETH_ALEN);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002244
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002245 if (send_rfkill_event) {
2246 eloop_register_timeout(0, 0, wpa_driver_nl80211_send_rfkill,
2247 drv, drv->ctx);
2248 }
2249
Dmitry Shmidt7f656022015-02-25 14:36:37 -08002250 if (drv->vendor_cmd_test_avail)
2251 qca_vendor_test(drv);
2252
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002253 return 0;
2254}
2255
2256
2257static int wpa_driver_nl80211_del_beacon(struct wpa_driver_nl80211_data *drv)
2258{
2259 struct nl_msg *msg;
2260
Dmitry Shmidtcce06662013-11-04 18:44:24 -08002261 wpa_printf(MSG_DEBUG, "nl80211: Remove beacon (ifindex=%d)",
2262 drv->ifindex);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002263 msg = nl80211_drv_msg(drv, 0, NL80211_CMD_DEL_BEACON);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002264 return send_and_recv_msgs(drv, msg, NULL, NULL);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002265}
2266
2267
2268/**
2269 * wpa_driver_nl80211_deinit - Deinitialize nl80211 driver interface
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08002270 * @bss: Pointer to private nl80211 data from wpa_driver_nl80211_init()
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002271 *
2272 * Shut down driver interface and processing of driver events. Free
2273 * private data buffer if one was allocated in wpa_driver_nl80211_init().
2274 */
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08002275static void wpa_driver_nl80211_deinit(struct i802_bss *bss)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002276{
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002277 struct wpa_driver_nl80211_data *drv = bss->drv;
2278
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002279 wpa_printf(MSG_INFO, "nl80211: deinit ifname=%s disabled_11b_rates=%d",
2280 bss->ifname, drv->disabled_11b_rates);
2281
Dmitry Shmidt04949592012-07-19 12:16:46 -07002282 bss->in_deinit = 1;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002283 if (drv->data_tx_status)
2284 eloop_unregister_read_sock(drv->eapol_tx_sock);
2285 if (drv->eapol_tx_sock >= 0)
2286 close(drv->eapol_tx_sock);
2287
2288 if (bss->nl_preq)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002289 wpa_driver_nl80211_probe_req_report(bss, 0);
2290 if (bss->added_if_into_bridge) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002291 if (linux_br_del_if(drv->global->ioctl_sock, bss->brname,
2292 bss->ifname) < 0)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002293 wpa_printf(MSG_INFO, "nl80211: Failed to remove "
2294 "interface %s from bridge %s: %s",
2295 bss->ifname, bss->brname, strerror(errno));
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07002296 if (drv->rtnl_sk)
Dmitry Shmidt9ead16e2014-10-07 13:15:23 -07002297 nl80211_handle_destroy(drv->rtnl_sk);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002298 }
2299 if (bss->added_bridge) {
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002300 if (linux_set_iface_flags(drv->global->ioctl_sock, bss->brname,
2301 0) < 0)
2302 wpa_printf(MSG_INFO,
2303 "nl80211: Could not set bridge %s down",
2304 bss->brname);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002305 if (linux_br_del(drv->global->ioctl_sock, bss->brname) < 0)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002306 wpa_printf(MSG_INFO, "nl80211: Failed to remove "
2307 "bridge %s: %s",
2308 bss->brname, strerror(errno));
2309 }
2310
2311 nl80211_remove_monitor_interface(drv);
2312
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002313 if (is_ap_interface(drv->nlmode))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002314 wpa_driver_nl80211_del_beacon(drv);
2315
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002316 if (drv->eapol_sock >= 0) {
2317 eloop_unregister_read_sock(drv->eapol_sock);
2318 close(drv->eapol_sock);
2319 }
2320
2321 if (drv->if_indices != drv->default_if_indices)
2322 os_free(drv->if_indices);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002323
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002324 if (drv->disabled_11b_rates)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002325 nl80211_disable_11b_rates(drv, drv->ifindex, 0);
2326
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002327 netlink_send_oper_ifla(drv->global->netlink, drv->ifindex, 0,
2328 IF_OPER_UP);
Dmitry Shmidtb58836e2014-04-29 14:35:56 -07002329 eloop_cancel_timeout(wpa_driver_nl80211_send_rfkill, drv, drv->ctx);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002330 rfkill_deinit(drv->rfkill);
2331
2332 eloop_cancel_timeout(wpa_driver_nl80211_scan_timeout, drv, drv->ctx);
2333
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08002334 if (!drv->start_iface_up)
2335 (void) i802_set_iface_flags(bss, 0);
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07002336
2337 if (drv->addr_changed) {
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002338 if (linux_set_iface_flags(drv->global->ioctl_sock, bss->ifname,
2339 0) < 0) {
2340 wpa_printf(MSG_DEBUG,
2341 "nl80211: Could not set interface down to restore permanent MAC address");
2342 }
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07002343 if (linux_set_ifhwaddr(drv->global->ioctl_sock, bss->ifname,
2344 drv->perm_addr) < 0) {
2345 wpa_printf(MSG_DEBUG,
2346 "nl80211: Could not restore permanent MAC address");
2347 }
2348 }
2349
Dmitry Shmidt34af3062013-07-11 10:46:32 -07002350 if (drv->nlmode != NL80211_IFTYPE_P2P_DEVICE) {
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08002351 if (!drv->hostapd || !drv->start_mode_ap)
2352 wpa_driver_nl80211_set_mode(bss,
2353 NL80211_IFTYPE_STATION);
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -07002354 nl80211_mgmt_unsubscribe(bss, "deinit");
Dmitry Shmidt34af3062013-07-11 10:46:32 -07002355 } else {
2356 nl80211_mgmt_unsubscribe(bss, "deinit");
2357 nl80211_del_p2pdev(bss);
2358 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002359
Dmitry Shmidtcce06662013-11-04 18:44:24 -08002360 nl80211_destroy_bss(drv->first_bss);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002361
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002362 os_free(drv->filter_ssids);
2363
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002364 os_free(drv->auth_ie);
2365
2366 if (drv->in_interface_list)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002367 dl_list_del(&drv->list);
2368
Dmitry Shmidt444d5672013-04-01 13:08:44 -07002369 os_free(drv->extended_capa);
2370 os_free(drv->extended_capa_mask);
Dmitry Shmidtcce06662013-11-04 18:44:24 -08002371 os_free(drv->first_bss);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002372 os_free(drv);
2373}
2374
2375
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002376static u32 wpa_alg_to_cipher_suite(enum wpa_alg alg, size_t key_len)
2377{
2378 switch (alg) {
2379 case WPA_ALG_WEP:
2380 if (key_len == 5)
2381 return WLAN_CIPHER_SUITE_WEP40;
2382 return WLAN_CIPHER_SUITE_WEP104;
2383 case WPA_ALG_TKIP:
2384 return WLAN_CIPHER_SUITE_TKIP;
2385 case WPA_ALG_CCMP:
2386 return WLAN_CIPHER_SUITE_CCMP;
2387 case WPA_ALG_GCMP:
2388 return WLAN_CIPHER_SUITE_GCMP;
2389 case WPA_ALG_CCMP_256:
2390 return WLAN_CIPHER_SUITE_CCMP_256;
2391 case WPA_ALG_GCMP_256:
2392 return WLAN_CIPHER_SUITE_GCMP_256;
2393 case WPA_ALG_IGTK:
2394 return WLAN_CIPHER_SUITE_AES_CMAC;
2395 case WPA_ALG_BIP_GMAC_128:
2396 return WLAN_CIPHER_SUITE_BIP_GMAC_128;
2397 case WPA_ALG_BIP_GMAC_256:
2398 return WLAN_CIPHER_SUITE_BIP_GMAC_256;
2399 case WPA_ALG_BIP_CMAC_256:
2400 return WLAN_CIPHER_SUITE_BIP_CMAC_256;
2401 case WPA_ALG_SMS4:
2402 return WLAN_CIPHER_SUITE_SMS4;
2403 case WPA_ALG_KRK:
2404 return WLAN_CIPHER_SUITE_KRK;
2405 case WPA_ALG_NONE:
2406 case WPA_ALG_PMK:
2407 wpa_printf(MSG_ERROR, "nl80211: Unexpected encryption algorithm %d",
2408 alg);
2409 return 0;
2410 }
2411
2412 wpa_printf(MSG_ERROR, "nl80211: Unsupported encryption algorithm %d",
2413 alg);
2414 return 0;
2415}
2416
2417
2418static u32 wpa_cipher_to_cipher_suite(unsigned int cipher)
2419{
2420 switch (cipher) {
2421 case WPA_CIPHER_CCMP_256:
2422 return WLAN_CIPHER_SUITE_CCMP_256;
2423 case WPA_CIPHER_GCMP_256:
2424 return WLAN_CIPHER_SUITE_GCMP_256;
2425 case WPA_CIPHER_CCMP:
2426 return WLAN_CIPHER_SUITE_CCMP;
2427 case WPA_CIPHER_GCMP:
2428 return WLAN_CIPHER_SUITE_GCMP;
2429 case WPA_CIPHER_TKIP:
2430 return WLAN_CIPHER_SUITE_TKIP;
2431 case WPA_CIPHER_WEP104:
2432 return WLAN_CIPHER_SUITE_WEP104;
2433 case WPA_CIPHER_WEP40:
2434 return WLAN_CIPHER_SUITE_WEP40;
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08002435 case WPA_CIPHER_GTK_NOT_USED:
2436 return WLAN_CIPHER_SUITE_NO_GROUP_ADDR;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002437 }
2438
2439 return 0;
2440}
2441
2442
2443static int wpa_cipher_to_cipher_suites(unsigned int ciphers, u32 suites[],
2444 int max_suites)
2445{
2446 int num_suites = 0;
2447
2448 if (num_suites < max_suites && ciphers & WPA_CIPHER_CCMP_256)
2449 suites[num_suites++] = WLAN_CIPHER_SUITE_CCMP_256;
2450 if (num_suites < max_suites && ciphers & WPA_CIPHER_GCMP_256)
2451 suites[num_suites++] = WLAN_CIPHER_SUITE_GCMP_256;
2452 if (num_suites < max_suites && ciphers & WPA_CIPHER_CCMP)
2453 suites[num_suites++] = WLAN_CIPHER_SUITE_CCMP;
2454 if (num_suites < max_suites && ciphers & WPA_CIPHER_GCMP)
2455 suites[num_suites++] = WLAN_CIPHER_SUITE_GCMP;
2456 if (num_suites < max_suites && ciphers & WPA_CIPHER_TKIP)
2457 suites[num_suites++] = WLAN_CIPHER_SUITE_TKIP;
2458 if (num_suites < max_suites && ciphers & WPA_CIPHER_WEP104)
2459 suites[num_suites++] = WLAN_CIPHER_SUITE_WEP104;
2460 if (num_suites < max_suites && ciphers & WPA_CIPHER_WEP40)
2461 suites[num_suites++] = WLAN_CIPHER_SUITE_WEP40;
2462
2463 return num_suites;
2464}
2465
2466
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002467static int issue_key_mgmt_set_key(struct wpa_driver_nl80211_data *drv,
2468 const u8 *key, size_t key_len)
2469{
2470 struct nl_msg *msg;
2471 int ret;
2472
2473 if (!(drv->capa.flags & WPA_DRIVER_FLAGS_KEY_MGMT_OFFLOAD))
2474 return 0;
2475
2476 if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_VENDOR)) ||
2477 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
2478 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
2479 QCA_NL80211_VENDOR_SUBCMD_KEY_MGMT_SET_KEY) ||
2480 nla_put(msg, NL80211_ATTR_VENDOR_DATA, key_len, key)) {
2481 nl80211_nlmsg_clear(msg);
2482 nlmsg_free(msg);
2483 return -1;
2484 }
2485 ret = send_and_recv_msgs(drv, msg, NULL, (void *) -1);
2486 if (ret) {
2487 wpa_printf(MSG_DEBUG,
2488 "nl80211: Key management set key failed: ret=%d (%s)",
2489 ret, strerror(-ret));
2490 }
2491
2492 return ret;
2493}
2494
2495
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08002496static int wpa_driver_nl80211_set_key(const char *ifname, struct i802_bss *bss,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002497 enum wpa_alg alg, const u8 *addr,
2498 int key_idx, int set_tx,
2499 const u8 *seq, size_t seq_len,
2500 const u8 *key, size_t key_len)
2501{
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002502 struct wpa_driver_nl80211_data *drv = bss->drv;
Dmitry Shmidt34af3062013-07-11 10:46:32 -07002503 int ifindex;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002504 struct nl_msg *msg;
2505 int ret;
Dmitry Shmidtd5c075b2013-08-05 14:36:10 -07002506 int tdls = 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002507
Dmitry Shmidt34af3062013-07-11 10:46:32 -07002508 /* Ignore for P2P Device */
2509 if (drv->nlmode == NL80211_IFTYPE_P2P_DEVICE)
2510 return 0;
2511
2512 ifindex = if_nametoindex(ifname);
2513 wpa_printf(MSG_DEBUG, "%s: ifindex=%d (%s) alg=%d addr=%p key_idx=%d "
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002514 "set_tx=%d seq_len=%lu key_len=%lu",
Dmitry Shmidt34af3062013-07-11 10:46:32 -07002515 __func__, ifindex, ifname, alg, addr, key_idx, set_tx,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002516 (unsigned long) seq_len, (unsigned long) key_len);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002517#ifdef CONFIG_TDLS
Dmitry Shmidtd5c075b2013-08-05 14:36:10 -07002518 if (key_idx == -1) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002519 key_idx = 0;
Dmitry Shmidtd5c075b2013-08-05 14:36:10 -07002520 tdls = 1;
2521 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002522#endif /* CONFIG_TDLS */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002523
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002524 if (alg == WPA_ALG_PMK &&
2525 (drv->capa.flags & WPA_DRIVER_FLAGS_KEY_MGMT_OFFLOAD)) {
2526 wpa_printf(MSG_DEBUG, "%s: calling issue_key_mgmt_set_key",
2527 __func__);
2528 ret = issue_key_mgmt_set_key(drv, key, key_len);
2529 return ret;
2530 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002531
2532 if (alg == WPA_ALG_NONE) {
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002533 msg = nl80211_ifindex_msg(drv, ifindex, 0, NL80211_CMD_DEL_KEY);
2534 if (!msg)
2535 return -ENOBUFS;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002536 } else {
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002537 msg = nl80211_ifindex_msg(drv, ifindex, 0, NL80211_CMD_NEW_KEY);
2538 if (!msg ||
2539 nla_put(msg, NL80211_ATTR_KEY_DATA, key_len, key) ||
2540 nla_put_u32(msg, NL80211_ATTR_KEY_CIPHER,
2541 wpa_alg_to_cipher_suite(alg, key_len)))
2542 goto fail;
Dmitry Shmidt98660862014-03-11 17:26:21 -07002543 wpa_hexdump_key(MSG_DEBUG, "nl80211: KEY_DATA", key, key_len);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002544 }
2545
Dmitry Shmidt98660862014-03-11 17:26:21 -07002546 if (seq && seq_len) {
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002547 if (nla_put(msg, NL80211_ATTR_KEY_SEQ, seq_len, seq))
2548 goto fail;
Dmitry Shmidt98660862014-03-11 17:26:21 -07002549 wpa_hexdump(MSG_DEBUG, "nl80211: KEY_SEQ", seq, seq_len);
2550 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002551
2552 if (addr && !is_broadcast_ether_addr(addr)) {
2553 wpa_printf(MSG_DEBUG, " addr=" MACSTR, MAC2STR(addr));
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002554 if (nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr))
2555 goto fail;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002556
2557 if (alg != WPA_ALG_WEP && key_idx && !set_tx) {
2558 wpa_printf(MSG_DEBUG, " RSN IBSS RX GTK");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002559 if (nla_put_u32(msg, NL80211_ATTR_KEY_TYPE,
2560 NL80211_KEYTYPE_GROUP))
2561 goto fail;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002562 }
2563 } else if (addr && is_broadcast_ether_addr(addr)) {
Dmitry Shmidt8da800a2013-04-24 12:57:01 -07002564 struct nlattr *types;
2565
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002566 wpa_printf(MSG_DEBUG, " broadcast key");
Dmitry Shmidt8da800a2013-04-24 12:57:01 -07002567
2568 types = nla_nest_start(msg, NL80211_ATTR_KEY_DEFAULT_TYPES);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002569 if (!types ||
2570 nla_put_flag(msg, NL80211_KEY_DEFAULT_TYPE_MULTICAST))
2571 goto fail;
Dmitry Shmidt8da800a2013-04-24 12:57:01 -07002572 nla_nest_end(msg, types);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002573 }
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002574 if (nla_put_u8(msg, NL80211_ATTR_KEY_IDX, key_idx))
2575 goto fail;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002576
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002577 ret = send_and_recv_msgs(drv, msg, NULL, key ? (void *) -1 : NULL);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002578 if ((ret == -ENOENT || ret == -ENOLINK) && alg == WPA_ALG_NONE)
2579 ret = 0;
2580 if (ret)
2581 wpa_printf(MSG_DEBUG, "nl80211: set_key failed; err=%d %s)",
2582 ret, strerror(-ret));
2583
2584 /*
2585 * If we failed or don't need to set the default TX key (below),
2586 * we're done here.
2587 */
Dmitry Shmidtd5c075b2013-08-05 14:36:10 -07002588 if (ret || !set_tx || alg == WPA_ALG_NONE || tdls)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002589 return ret;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002590 if (is_ap_interface(drv->nlmode) && addr &&
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002591 !is_broadcast_ether_addr(addr))
2592 return ret;
2593
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002594 msg = nl80211_ifindex_msg(drv, ifindex, 0, NL80211_CMD_SET_KEY);
2595 if (!msg ||
2596 nla_put_u8(msg, NL80211_ATTR_KEY_IDX, key_idx) ||
Dmitry Shmidt807291d2015-01-27 13:40:23 -08002597 nla_put_flag(msg, (alg == WPA_ALG_IGTK ||
2598 alg == WPA_ALG_BIP_GMAC_128 ||
2599 alg == WPA_ALG_BIP_GMAC_256 ||
2600 alg == WPA_ALG_BIP_CMAC_256) ?
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002601 NL80211_ATTR_KEY_DEFAULT_MGMT :
2602 NL80211_ATTR_KEY_DEFAULT))
2603 goto fail;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002604 if (addr && is_broadcast_ether_addr(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_MULTICAST))
2610 goto fail;
Dmitry Shmidt8da800a2013-04-24 12:57:01 -07002611 nla_nest_end(msg, types);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002612 } else if (addr) {
Dmitry Shmidt8da800a2013-04-24 12:57:01 -07002613 struct nlattr *types;
2614
2615 types = nla_nest_start(msg, NL80211_ATTR_KEY_DEFAULT_TYPES);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002616 if (!types ||
2617 nla_put_flag(msg, NL80211_KEY_DEFAULT_TYPE_UNICAST))
2618 goto fail;
Dmitry Shmidt8da800a2013-04-24 12:57:01 -07002619 nla_nest_end(msg, types);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002620 }
2621
2622 ret = send_and_recv_msgs(drv, msg, NULL, NULL);
2623 if (ret == -ENOENT)
2624 ret = 0;
2625 if (ret)
2626 wpa_printf(MSG_DEBUG, "nl80211: set_key default failed; "
2627 "err=%d %s)", ret, strerror(-ret));
2628 return ret;
2629
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002630fail:
2631 nl80211_nlmsg_clear(msg);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002632 nlmsg_free(msg);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002633 return -ENOBUFS;
2634}
2635
2636
2637static int nl_add_key(struct nl_msg *msg, enum wpa_alg alg,
2638 int key_idx, int defkey,
2639 const u8 *seq, size_t seq_len,
2640 const u8 *key, size_t key_len)
2641{
2642 struct nlattr *key_attr = nla_nest_start(msg, NL80211_ATTR_KEY);
2643 if (!key_attr)
2644 return -1;
2645
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002646 if (defkey && alg == WPA_ALG_IGTK) {
2647 if (nla_put_flag(msg, NL80211_KEY_DEFAULT_MGMT))
2648 return -1;
2649 } else if (defkey) {
2650 if (nla_put_flag(msg, NL80211_KEY_DEFAULT))
2651 return -1;
2652 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002653
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002654 if (nla_put_u8(msg, NL80211_KEY_IDX, key_idx) ||
2655 nla_put_u32(msg, NL80211_KEY_CIPHER,
2656 wpa_alg_to_cipher_suite(alg, key_len)) ||
2657 (seq && seq_len &&
2658 nla_put(msg, NL80211_KEY_SEQ, seq_len, seq)) ||
2659 nla_put(msg, NL80211_KEY_DATA, key_len, key))
2660 return -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002661
2662 nla_nest_end(msg, key_attr);
2663
2664 return 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002665}
2666
2667
2668static int nl80211_set_conn_keys(struct wpa_driver_associate_params *params,
2669 struct nl_msg *msg)
2670{
2671 int i, privacy = 0;
2672 struct nlattr *nl_keys, *nl_key;
2673
2674 for (i = 0; i < 4; i++) {
2675 if (!params->wep_key[i])
2676 continue;
2677 privacy = 1;
2678 break;
2679 }
2680 if (params->wps == WPS_MODE_PRIVACY)
2681 privacy = 1;
2682 if (params->pairwise_suite &&
2683 params->pairwise_suite != WPA_CIPHER_NONE)
2684 privacy = 1;
2685
2686 if (!privacy)
2687 return 0;
2688
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002689 if (nla_put_flag(msg, NL80211_ATTR_PRIVACY))
2690 return -ENOBUFS;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002691
2692 nl_keys = nla_nest_start(msg, NL80211_ATTR_KEYS);
2693 if (!nl_keys)
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002694 return -ENOBUFS;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002695
2696 for (i = 0; i < 4; i++) {
2697 if (!params->wep_key[i])
2698 continue;
2699
2700 nl_key = nla_nest_start(msg, i);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002701 if (!nl_key ||
2702 nla_put(msg, NL80211_KEY_DATA, params->wep_key_len[i],
2703 params->wep_key[i]) ||
2704 nla_put_u32(msg, NL80211_KEY_CIPHER,
2705 params->wep_key_len[i] == 5 ?
2706 WLAN_CIPHER_SUITE_WEP40 :
2707 WLAN_CIPHER_SUITE_WEP104) ||
2708 nla_put_u8(msg, NL80211_KEY_IDX, i) ||
2709 (i == params->wep_tx_keyidx &&
2710 nla_put_flag(msg, NL80211_KEY_DEFAULT)))
2711 return -ENOBUFS;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002712
2713 nla_nest_end(msg, nl_key);
2714 }
2715 nla_nest_end(msg, nl_keys);
2716
2717 return 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002718}
2719
2720
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002721int wpa_driver_nl80211_mlme(struct wpa_driver_nl80211_data *drv,
2722 const u8 *addr, int cmd, u16 reason_code,
2723 int local_state_change)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002724{
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002725 int ret;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002726 struct nl_msg *msg;
2727
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002728 if (!(msg = nl80211_drv_msg(drv, 0, cmd)) ||
2729 nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason_code) ||
2730 (addr && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) ||
2731 (local_state_change &&
2732 nla_put_flag(msg, NL80211_ATTR_LOCAL_STATE_CHANGE))) {
2733 nlmsg_free(msg);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002734 return -1;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002735 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002736
2737 ret = send_and_recv_msgs(drv, msg, NULL, NULL);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002738 if (ret) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002739 wpa_dbg(drv->ctx, MSG_DEBUG,
2740 "nl80211: MLME command failed: reason=%u ret=%d (%s)",
2741 reason_code, ret, strerror(-ret));
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002742 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002743 return ret;
2744}
2745
2746
2747static int wpa_driver_nl80211_disconnect(struct wpa_driver_nl80211_data *drv,
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08002748 int reason_code)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002749{
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07002750 int ret;
2751
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08002752 wpa_printf(MSG_DEBUG, "%s(reason_code=%d)", __func__, reason_code);
Dmitry Shmidt8bae4132013-06-06 11:25:10 -07002753 nl80211_mark_disconnected(drv);
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08002754 /* Disconnect command doesn't need BSSID - it uses cached value */
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07002755 ret = wpa_driver_nl80211_mlme(drv, NULL, NL80211_CMD_DISCONNECT,
2756 reason_code, 0);
2757 /*
2758 * For locally generated disconnect, supplicant already generates a
2759 * DEAUTH event, so ignore the event from NL80211.
2760 */
2761 drv->ignore_next_local_disconnect = ret == 0;
2762
2763 return ret;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002764}
2765
2766
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08002767static int wpa_driver_nl80211_deauthenticate(struct i802_bss *bss,
2768 const u8 *addr, int reason_code)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002769{
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002770 struct wpa_driver_nl80211_data *drv = bss->drv;
Dmitry Shmidt7dba0e52014-04-14 10:49:15 -07002771 int ret;
Dmitry Shmidt413dde72014-04-11 10:23:22 -07002772
2773 if (drv->nlmode == NL80211_IFTYPE_ADHOC) {
2774 nl80211_mark_disconnected(drv);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002775 return nl80211_leave_ibss(drv, 1);
Dmitry Shmidt413dde72014-04-11 10:23:22 -07002776 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002777 if (!(drv->capa.flags & WPA_DRIVER_FLAGS_SME))
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08002778 return wpa_driver_nl80211_disconnect(drv, reason_code);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002779 wpa_printf(MSG_DEBUG, "%s(addr=" MACSTR " reason_code=%d)",
2780 __func__, MAC2STR(addr), reason_code);
Dmitry Shmidt8bae4132013-06-06 11:25:10 -07002781 nl80211_mark_disconnected(drv);
Dmitry Shmidt7dba0e52014-04-14 10:49:15 -07002782 ret = wpa_driver_nl80211_mlme(drv, addr, NL80211_CMD_DEAUTHENTICATE,
2783 reason_code, 0);
2784 /*
2785 * For locally generated deauthenticate, supplicant already generates a
2786 * DEAUTH event, so ignore the event from NL80211.
2787 */
2788 drv->ignore_next_local_deauth = ret == 0;
2789 return ret;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002790}
2791
2792
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002793static void nl80211_copy_auth_params(struct wpa_driver_nl80211_data *drv,
2794 struct wpa_driver_auth_params *params)
2795{
2796 int i;
2797
2798 drv->auth_freq = params->freq;
2799 drv->auth_alg = params->auth_alg;
2800 drv->auth_wep_tx_keyidx = params->wep_tx_keyidx;
2801 drv->auth_local_state_change = params->local_state_change;
2802 drv->auth_p2p = params->p2p;
2803
2804 if (params->bssid)
2805 os_memcpy(drv->auth_bssid_, params->bssid, ETH_ALEN);
2806 else
2807 os_memset(drv->auth_bssid_, 0, ETH_ALEN);
2808
2809 if (params->ssid) {
2810 os_memcpy(drv->auth_ssid, params->ssid, params->ssid_len);
2811 drv->auth_ssid_len = params->ssid_len;
2812 } else
2813 drv->auth_ssid_len = 0;
2814
2815
2816 os_free(drv->auth_ie);
2817 drv->auth_ie = NULL;
2818 drv->auth_ie_len = 0;
2819 if (params->ie) {
2820 drv->auth_ie = os_malloc(params->ie_len);
2821 if (drv->auth_ie) {
2822 os_memcpy(drv->auth_ie, params->ie, params->ie_len);
2823 drv->auth_ie_len = params->ie_len;
2824 }
2825 }
2826
2827 for (i = 0; i < 4; i++) {
2828 if (params->wep_key[i] && params->wep_key_len[i] &&
2829 params->wep_key_len[i] <= 16) {
2830 os_memcpy(drv->auth_wep_key[i], params->wep_key[i],
2831 params->wep_key_len[i]);
2832 drv->auth_wep_key_len[i] = params->wep_key_len[i];
2833 } else
2834 drv->auth_wep_key_len[i] = 0;
2835 }
2836}
2837
2838
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002839static void nl80211_unmask_11b_rates(struct i802_bss *bss)
2840{
2841 struct wpa_driver_nl80211_data *drv = bss->drv;
2842
2843 if (is_p2p_net_interface(drv->nlmode) || !drv->disabled_11b_rates)
2844 return;
2845
2846 /*
2847 * Looks like we failed to unmask 11b rates previously. This could
2848 * happen, e.g., if the interface was down at the point in time when a
2849 * P2P group was terminated.
2850 */
2851 wpa_printf(MSG_DEBUG,
2852 "nl80211: Interface %s mode is for non-P2P, but 11b rates were disabled - re-enable them",
2853 bss->ifname);
2854 nl80211_disable_11b_rates(drv, drv->ifindex, 0);
2855}
2856
2857
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002858static int wpa_driver_nl80211_authenticate(
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08002859 struct i802_bss *bss, struct wpa_driver_auth_params *params)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002860{
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002861 struct wpa_driver_nl80211_data *drv = bss->drv;
2862 int ret = -1, i;
2863 struct nl_msg *msg;
2864 enum nl80211_auth_type type;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002865 enum nl80211_iftype nlmode;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002866 int count = 0;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002867 int is_retry;
2868
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002869 nl80211_unmask_11b_rates(bss);
2870
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002871 is_retry = drv->retry_auth;
2872 drv->retry_auth = 0;
Dmitry Shmidt98660862014-03-11 17:26:21 -07002873 drv->ignore_deauth_event = 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002874
Dmitry Shmidt8bae4132013-06-06 11:25:10 -07002875 nl80211_mark_disconnected(drv);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002876 os_memset(drv->auth_bssid, 0, ETH_ALEN);
Dmitry Shmidt8bae4132013-06-06 11:25:10 -07002877 if (params->bssid)
2878 os_memcpy(drv->auth_attempt_bssid, params->bssid, ETH_ALEN);
2879 else
2880 os_memset(drv->auth_attempt_bssid, 0, ETH_ALEN);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002881 /* FIX: IBSS mode */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002882 nlmode = params->p2p ?
2883 NL80211_IFTYPE_P2P_CLIENT : NL80211_IFTYPE_STATION;
2884 if (drv->nlmode != nlmode &&
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08002885 wpa_driver_nl80211_set_mode(bss, nlmode) < 0)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002886 return -1;
2887
2888retry:
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002889 wpa_printf(MSG_DEBUG, "nl80211: Authenticate (ifindex=%d)",
2890 drv->ifindex);
2891
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002892 msg = nl80211_drv_msg(drv, 0, NL80211_CMD_AUTHENTICATE);
2893 if (!msg)
2894 goto fail;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002895
2896 for (i = 0; i < 4; i++) {
2897 if (!params->wep_key[i])
2898 continue;
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08002899 wpa_driver_nl80211_set_key(bss->ifname, bss, WPA_ALG_WEP,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002900 NULL, i,
2901 i == params->wep_tx_keyidx, NULL, 0,
2902 params->wep_key[i],
2903 params->wep_key_len[i]);
2904 if (params->wep_tx_keyidx != i)
2905 continue;
2906 if (nl_add_key(msg, WPA_ALG_WEP, i, 1, NULL, 0,
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002907 params->wep_key[i], params->wep_key_len[i]))
2908 goto fail;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002909 }
2910
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002911 if (params->bssid) {
2912 wpa_printf(MSG_DEBUG, " * bssid=" MACSTR,
2913 MAC2STR(params->bssid));
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002914 if (nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, params->bssid))
2915 goto fail;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002916 }
2917 if (params->freq) {
2918 wpa_printf(MSG_DEBUG, " * freq=%d", params->freq);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002919 if (nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, params->freq))
2920 goto fail;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002921 }
2922 if (params->ssid) {
2923 wpa_hexdump_ascii(MSG_DEBUG, " * SSID",
2924 params->ssid, params->ssid_len);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002925 if (nla_put(msg, NL80211_ATTR_SSID, params->ssid_len,
2926 params->ssid))
2927 goto fail;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002928 }
2929 wpa_hexdump(MSG_DEBUG, " * IEs", params->ie, params->ie_len);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002930 if (params->ie &&
2931 nla_put(msg, NL80211_ATTR_IE, params->ie_len, params->ie))
2932 goto fail;
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08002933 if (params->sae_data) {
2934 wpa_hexdump(MSG_DEBUG, " * SAE data", params->sae_data,
2935 params->sae_data_len);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002936 if (nla_put(msg, NL80211_ATTR_SAE_DATA, params->sae_data_len,
2937 params->sae_data))
2938 goto fail;
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08002939 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002940 if (params->auth_alg & WPA_AUTH_ALG_OPEN)
2941 type = NL80211_AUTHTYPE_OPEN_SYSTEM;
2942 else if (params->auth_alg & WPA_AUTH_ALG_SHARED)
2943 type = NL80211_AUTHTYPE_SHARED_KEY;
2944 else if (params->auth_alg & WPA_AUTH_ALG_LEAP)
2945 type = NL80211_AUTHTYPE_NETWORK_EAP;
2946 else if (params->auth_alg & WPA_AUTH_ALG_FT)
2947 type = NL80211_AUTHTYPE_FT;
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08002948 else if (params->auth_alg & WPA_AUTH_ALG_SAE)
2949 type = NL80211_AUTHTYPE_SAE;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002950 else
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002951 goto fail;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002952 wpa_printf(MSG_DEBUG, " * Auth Type %d", type);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002953 if (nla_put_u32(msg, NL80211_ATTR_AUTH_TYPE, type))
2954 goto fail;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002955 if (params->local_state_change) {
2956 wpa_printf(MSG_DEBUG, " * Local state change only");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002957 if (nla_put_flag(msg, NL80211_ATTR_LOCAL_STATE_CHANGE))
2958 goto fail;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002959 }
2960
2961 ret = send_and_recv_msgs(drv, msg, NULL, NULL);
2962 msg = NULL;
2963 if (ret) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002964 wpa_dbg(drv->ctx, MSG_DEBUG,
2965 "nl80211: MLME command failed (auth): ret=%d (%s)",
2966 ret, strerror(-ret));
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002967 count++;
2968 if (ret == -EALREADY && count == 1 && params->bssid &&
2969 !params->local_state_change) {
2970 /*
2971 * mac80211 does not currently accept new
2972 * authentication if we are already authenticated. As a
2973 * workaround, force deauthentication and try again.
2974 */
2975 wpa_printf(MSG_DEBUG, "nl80211: Retry authentication "
2976 "after forced deauthentication");
Dmitry Shmidt98660862014-03-11 17:26:21 -07002977 drv->ignore_deauth_event = 1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002978 wpa_driver_nl80211_deauthenticate(
2979 bss, params->bssid,
2980 WLAN_REASON_PREV_AUTH_NOT_VALID);
2981 nlmsg_free(msg);
2982 goto retry;
2983 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002984
2985 if (ret == -ENOENT && params->freq && !is_retry) {
2986 /*
2987 * cfg80211 has likely expired the BSS entry even
2988 * though it was previously available in our internal
2989 * BSS table. To recover quickly, start a single
2990 * channel scan on the specified channel.
2991 */
2992 struct wpa_driver_scan_params scan;
2993 int freqs[2];
2994
2995 os_memset(&scan, 0, sizeof(scan));
2996 scan.num_ssids = 1;
2997 if (params->ssid) {
2998 scan.ssids[0].ssid = params->ssid;
2999 scan.ssids[0].ssid_len = params->ssid_len;
3000 }
3001 freqs[0] = params->freq;
3002 freqs[1] = 0;
3003 scan.freqs = freqs;
3004 wpa_printf(MSG_DEBUG, "nl80211: Trigger single "
3005 "channel scan to refresh cfg80211 BSS "
3006 "entry");
3007 ret = wpa_driver_nl80211_scan(bss, &scan);
3008 if (ret == 0) {
3009 nl80211_copy_auth_params(drv, params);
3010 drv->scan_for_auth = 1;
3011 }
3012 } else if (is_retry) {
3013 /*
3014 * Need to indicate this with an event since the return
3015 * value from the retry is not delivered to core code.
3016 */
3017 union wpa_event_data event;
3018 wpa_printf(MSG_DEBUG, "nl80211: Authentication retry "
3019 "failed");
3020 os_memset(&event, 0, sizeof(event));
3021 os_memcpy(event.timeout_event.addr, drv->auth_bssid_,
3022 ETH_ALEN);
3023 wpa_supplicant_event(drv->ctx, EVENT_AUTH_TIMED_OUT,
3024 &event);
3025 }
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003026 } else {
3027 wpa_printf(MSG_DEBUG,
3028 "nl80211: Authentication request send successfully");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003029 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003030
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003031fail:
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003032 nlmsg_free(msg);
3033 return ret;
3034}
3035
3036
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003037int wpa_driver_nl80211_authenticate_retry(struct wpa_driver_nl80211_data *drv)
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003038{
3039 struct wpa_driver_auth_params params;
Dmitry Shmidtcce06662013-11-04 18:44:24 -08003040 struct i802_bss *bss = drv->first_bss;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003041 int i;
3042
3043 wpa_printf(MSG_DEBUG, "nl80211: Try to authenticate again");
3044
3045 os_memset(&params, 0, sizeof(params));
3046 params.freq = drv->auth_freq;
3047 params.auth_alg = drv->auth_alg;
3048 params.wep_tx_keyidx = drv->auth_wep_tx_keyidx;
3049 params.local_state_change = drv->auth_local_state_change;
3050 params.p2p = drv->auth_p2p;
3051
3052 if (!is_zero_ether_addr(drv->auth_bssid_))
3053 params.bssid = drv->auth_bssid_;
3054
3055 if (drv->auth_ssid_len) {
3056 params.ssid = drv->auth_ssid;
3057 params.ssid_len = drv->auth_ssid_len;
3058 }
3059
3060 params.ie = drv->auth_ie;
3061 params.ie_len = drv->auth_ie_len;
3062
3063 for (i = 0; i < 4; i++) {
3064 if (drv->auth_wep_key_len[i]) {
3065 params.wep_key[i] = drv->auth_wep_key[i];
3066 params.wep_key_len[i] = drv->auth_wep_key_len[i];
3067 }
3068 }
3069
3070 drv->retry_auth = 1;
3071 return wpa_driver_nl80211_authenticate(bss, &params);
3072}
3073
3074
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003075static int wpa_driver_nl80211_send_frame(struct i802_bss *bss,
3076 const void *data, size_t len,
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08003077 int encrypt, int noack,
3078 unsigned int freq, int no_cck,
3079 int offchanok, unsigned int wait_time)
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003080{
3081 struct wpa_driver_nl80211_data *drv = bss->drv;
3082 u64 cookie;
Dmitry Shmidt051af732013-10-22 13:52:46 -07003083 int res;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003084
Dmitry Shmidt6dc03bd2014-05-16 10:40:13 -07003085 if (freq == 0 && drv->nlmode == NL80211_IFTYPE_ADHOC) {
3086 freq = nl80211_get_assoc_freq(drv);
3087 wpa_printf(MSG_DEBUG,
3088 "nl80211: send_frame - Use assoc_freq=%u for IBSS",
3089 freq);
3090 }
Dmitry Shmidt56052862013-10-04 10:23:25 -07003091 if (freq == 0) {
3092 wpa_printf(MSG_DEBUG, "nl80211: send_frame - Use bss->freq=%u",
3093 bss->freq);
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08003094 freq = bss->freq;
Dmitry Shmidt56052862013-10-04 10:23:25 -07003095 }
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08003096
Dmitry Shmidt56052862013-10-04 10:23:25 -07003097 if (drv->use_monitor) {
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003098 wpa_printf(MSG_DEBUG, "nl80211: send_frame(freq=%u bss->freq=%u) -> send_monitor",
Dmitry Shmidt56052862013-10-04 10:23:25 -07003099 freq, bss->freq);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003100 return nl80211_send_monitor(drv, data, len, encrypt, noack);
Dmitry Shmidt56052862013-10-04 10:23:25 -07003101 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003102
Dmitry Shmidt56052862013-10-04 10:23:25 -07003103 wpa_printf(MSG_DEBUG, "nl80211: send_frame -> send_frame_cmd");
Dmitry Shmidt051af732013-10-22 13:52:46 -07003104 res = nl80211_send_frame_cmd(bss, freq, wait_time, data, len,
3105 &cookie, no_cck, noack, offchanok);
3106 if (res == 0 && !noack) {
3107 const struct ieee80211_mgmt *mgmt;
3108 u16 fc;
3109
3110 mgmt = (const struct ieee80211_mgmt *) data;
3111 fc = le_to_host16(mgmt->frame_control);
3112 if (WLAN_FC_GET_TYPE(fc) == WLAN_FC_TYPE_MGMT &&
3113 WLAN_FC_GET_STYPE(fc) == WLAN_FC_STYPE_ACTION) {
3114 wpa_printf(MSG_MSGDUMP,
3115 "nl80211: Update send_action_cookie from 0x%llx to 0x%llx",
3116 (long long unsigned int)
3117 drv->send_action_cookie,
3118 (long long unsigned int) cookie);
3119 drv->send_action_cookie = cookie;
3120 }
3121 }
3122
3123 return res;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003124}
3125
3126
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08003127static int wpa_driver_nl80211_send_mlme(struct i802_bss *bss, const u8 *data,
3128 size_t data_len, int noack,
3129 unsigned int freq, int no_cck,
3130 int offchanok,
3131 unsigned int wait_time)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003132{
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003133 struct wpa_driver_nl80211_data *drv = bss->drv;
3134 struct ieee80211_mgmt *mgmt;
3135 int encrypt = 1;
3136 u16 fc;
3137
3138 mgmt = (struct ieee80211_mgmt *) data;
3139 fc = le_to_host16(mgmt->frame_control);
Dmitry Shmidt2271d3f2014-06-23 12:16:31 -07003140 wpa_printf(MSG_DEBUG, "nl80211: send_mlme - da= " MACSTR
3141 " noack=%d freq=%u no_cck=%d offchanok=%d wait_time=%u fc=0x%x (%s) nlmode=%d",
3142 MAC2STR(mgmt->da), noack, freq, no_cck, offchanok, wait_time,
3143 fc, fc2str(fc), drv->nlmode);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003144
Dmitry Shmidt34af3062013-07-11 10:46:32 -07003145 if ((is_sta_interface(drv->nlmode) ||
3146 drv->nlmode == NL80211_IFTYPE_P2P_DEVICE) &&
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003147 WLAN_FC_GET_TYPE(fc) == WLAN_FC_TYPE_MGMT &&
3148 WLAN_FC_GET_STYPE(fc) == WLAN_FC_STYPE_PROBE_RESP) {
3149 /*
3150 * The use of last_mgmt_freq is a bit of a hack,
3151 * but it works due to the single-threaded nature
3152 * of wpa_supplicant.
3153 */
Dmitry Shmidt56052862013-10-04 10:23:25 -07003154 if (freq == 0) {
3155 wpa_printf(MSG_DEBUG, "nl80211: Use last_mgmt_freq=%d",
3156 drv->last_mgmt_freq);
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08003157 freq = drv->last_mgmt_freq;
Dmitry Shmidt56052862013-10-04 10:23:25 -07003158 }
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08003159 return nl80211_send_frame_cmd(bss, freq, 0,
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003160 data, data_len, NULL, 1, noack,
3161 1);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003162 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003163
3164 if (drv->device_ap_sme && is_ap_interface(drv->nlmode)) {
Dmitry Shmidt56052862013-10-04 10:23:25 -07003165 if (freq == 0) {
3166 wpa_printf(MSG_DEBUG, "nl80211: Use bss->freq=%d",
3167 bss->freq);
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08003168 freq = bss->freq;
Dmitry Shmidt56052862013-10-04 10:23:25 -07003169 }
Dmitry Shmidt04949592012-07-19 12:16:46 -07003170 return nl80211_send_frame_cmd(bss, freq,
3171 (int) freq == bss->freq ? 0 :
3172 wait_time,
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08003173 data, data_len,
3174 &drv->send_action_cookie,
3175 no_cck, noack, offchanok);
Dmitry Shmidt6e933c12011-09-27 12:29:26 -07003176 }
Dmitry Shmidtb638fe72012-03-20 12:51:25 -07003177
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003178 if (WLAN_FC_GET_TYPE(fc) == WLAN_FC_TYPE_MGMT &&
3179 WLAN_FC_GET_STYPE(fc) == WLAN_FC_STYPE_AUTH) {
3180 /*
3181 * Only one of the authentication frame types is encrypted.
3182 * In order for static WEP encryption to work properly (i.e.,
3183 * to not encrypt the frame), we need to tell mac80211 about
3184 * the frames that must not be encrypted.
3185 */
3186 u16 auth_alg = le_to_host16(mgmt->u.auth.auth_alg);
3187 u16 auth_trans = le_to_host16(mgmt->u.auth.auth_transaction);
3188 if (auth_alg != WLAN_AUTH_SHARED_KEY || auth_trans != 3)
3189 encrypt = 0;
3190 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003191
Dmitry Shmidt56052862013-10-04 10:23:25 -07003192 wpa_printf(MSG_DEBUG, "nl80211: send_mlme -> send_frame");
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003193 return wpa_driver_nl80211_send_frame(bss, data, data_len, encrypt,
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08003194 noack, freq, no_cck, offchanok,
3195 wait_time);
3196}
3197
3198
Dmitry Shmidtff787d52015-01-12 13:01:47 -08003199static int nl80211_put_basic_rates(struct nl_msg *msg, const int *basic_rates)
3200{
3201 u8 rates[NL80211_MAX_SUPP_RATES];
3202 u8 rates_len = 0;
3203 int i;
3204
3205 if (!basic_rates)
3206 return 0;
3207
3208 for (i = 0; i < NL80211_MAX_SUPP_RATES && basic_rates[i] >= 0; i++)
3209 rates[rates_len++] = basic_rates[i] / 5;
3210
3211 return nla_put(msg, NL80211_ATTR_BSS_BASIC_RATES, rates_len, rates);
3212}
3213
3214
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003215static int nl80211_set_bss(struct i802_bss *bss, int cts, int preamble,
3216 int slot, int ht_opmode, int ap_isolate,
Dmitry Shmidtff787d52015-01-12 13:01:47 -08003217 const int *basic_rates)
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003218{
3219 struct wpa_driver_nl80211_data *drv = bss->drv;
3220 struct nl_msg *msg;
3221
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003222 if (!(msg = nl80211_bss_msg(bss, 0, NL80211_CMD_SET_BSS)) ||
3223 (cts >= 0 &&
3224 nla_put_u8(msg, NL80211_ATTR_BSS_CTS_PROT, cts)) ||
3225 (preamble >= 0 &&
3226 nla_put_u8(msg, NL80211_ATTR_BSS_SHORT_PREAMBLE, preamble)) ||
3227 (slot >= 0 &&
3228 nla_put_u8(msg, NL80211_ATTR_BSS_SHORT_SLOT_TIME, slot)) ||
3229 (ht_opmode >= 0 &&
3230 nla_put_u16(msg, NL80211_ATTR_BSS_HT_OPMODE, ht_opmode)) ||
3231 (ap_isolate >= 0 &&
Dmitry Shmidtff787d52015-01-12 13:01:47 -08003232 nla_put_u8(msg, NL80211_ATTR_AP_ISOLATE, ap_isolate)) ||
3233 nl80211_put_basic_rates(msg, basic_rates)) {
3234 nlmsg_free(msg);
3235 return -ENOBUFS;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003236 }
3237
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003238 return send_and_recv_msgs(drv, msg, NULL, NULL);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003239}
3240
3241
Dmitry Shmidt8bae4132013-06-06 11:25:10 -07003242static int wpa_driver_nl80211_set_acl(void *priv,
3243 struct hostapd_acl_params *params)
3244{
3245 struct i802_bss *bss = priv;
3246 struct wpa_driver_nl80211_data *drv = bss->drv;
3247 struct nl_msg *msg;
3248 struct nlattr *acl;
3249 unsigned int i;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003250 int ret;
Dmitry Shmidt8bae4132013-06-06 11:25:10 -07003251
3252 if (!(drv->capa.max_acl_mac_addrs))
3253 return -ENOTSUP;
3254
3255 if (params->num_mac_acl > drv->capa.max_acl_mac_addrs)
3256 return -ENOTSUP;
3257
Dmitry Shmidt8bae4132013-06-06 11:25:10 -07003258 wpa_printf(MSG_DEBUG, "nl80211: Set %s ACL (num_mac_acl=%u)",
3259 params->acl_policy ? "Accept" : "Deny", params->num_mac_acl);
3260
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003261 if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_SET_MAC_ACL)) ||
3262 nla_put_u32(msg, NL80211_ATTR_ACL_POLICY, params->acl_policy ?
3263 NL80211_ACL_POLICY_DENY_UNLESS_LISTED :
3264 NL80211_ACL_POLICY_ACCEPT_UNLESS_LISTED) ||
3265 (acl = nla_nest_start(msg, NL80211_ATTR_MAC_ADDRS)) == NULL) {
3266 nlmsg_free(msg);
3267 return -ENOMEM;
3268 }
Dmitry Shmidt8bae4132013-06-06 11:25:10 -07003269
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003270 for (i = 0; i < params->num_mac_acl; i++) {
3271 if (nla_put(msg, i + 1, ETH_ALEN, params->mac_acl[i].addr)) {
3272 nlmsg_free(msg);
3273 return -ENOMEM;
3274 }
3275 }
Dmitry Shmidt8bae4132013-06-06 11:25:10 -07003276
3277 nla_nest_end(msg, acl);
3278
3279 ret = send_and_recv_msgs(drv, msg, NULL, NULL);
Dmitry Shmidt8bae4132013-06-06 11:25:10 -07003280 if (ret) {
3281 wpa_printf(MSG_DEBUG, "nl80211: Failed to set MAC ACL: %d (%s)",
3282 ret, strerror(-ret));
3283 }
3284
Dmitry Shmidt8bae4132013-06-06 11:25:10 -07003285 return ret;
3286}
3287
3288
Dmitry Shmidtff787d52015-01-12 13:01:47 -08003289static int nl80211_put_beacon_int(struct nl_msg *msg, int beacon_int)
3290{
3291 if (beacon_int > 0) {
3292 wpa_printf(MSG_DEBUG, " * beacon_int=%d", beacon_int);
3293 return nla_put_u32(msg, NL80211_ATTR_BEACON_INTERVAL,
3294 beacon_int);
3295 }
3296
3297 return 0;
3298}
3299
3300
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003301static int wpa_driver_nl80211_set_ap(void *priv,
3302 struct wpa_driver_ap_params *params)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003303{
3304 struct i802_bss *bss = priv;
3305 struct wpa_driver_nl80211_data *drv = bss->drv;
3306 struct nl_msg *msg;
3307 u8 cmd = NL80211_CMD_NEW_BEACON;
3308 int ret;
3309 int beacon_set;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003310 int num_suites;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003311 int smps_mode;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08003312 u32 suites[10], suite;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003313 u32 ver;
3314
Dmitry Shmidt7f656022015-02-25 14:36:37 -08003315 beacon_set = params->reenable ? 0 : bss->beacon_set;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003316
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003317 wpa_printf(MSG_DEBUG, "nl80211: Set beacon (beacon_set=%d)",
3318 beacon_set);
3319 if (beacon_set)
3320 cmd = NL80211_CMD_SET_BEACON;
3321
Dmitry Shmidt0ccb66e2013-03-29 16:41:28 -07003322 wpa_hexdump(MSG_DEBUG, "nl80211: Beacon head",
3323 params->head, params->head_len);
Dmitry Shmidt0ccb66e2013-03-29 16:41:28 -07003324 wpa_hexdump(MSG_DEBUG, "nl80211: Beacon tail",
3325 params->tail, params->tail_len);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003326 wpa_printf(MSG_DEBUG, "nl80211: ifindex=%d", bss->ifindex);
Dmitry Shmidt0ccb66e2013-03-29 16:41:28 -07003327 wpa_printf(MSG_DEBUG, "nl80211: beacon_int=%d", params->beacon_int);
Dmitry Shmidt0ccb66e2013-03-29 16:41:28 -07003328 wpa_printf(MSG_DEBUG, "nl80211: dtim_period=%d", params->dtim_period);
Dmitry Shmidt0ccb66e2013-03-29 16:41:28 -07003329 wpa_hexdump_ascii(MSG_DEBUG, "nl80211: ssid",
3330 params->ssid, params->ssid_len);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003331 if (!(msg = nl80211_bss_msg(bss, 0, cmd)) ||
3332 nla_put(msg, NL80211_ATTR_BEACON_HEAD, params->head_len,
3333 params->head) ||
3334 nla_put(msg, NL80211_ATTR_BEACON_TAIL, params->tail_len,
3335 params->tail) ||
Dmitry Shmidtff787d52015-01-12 13:01:47 -08003336 nl80211_put_beacon_int(msg, params->beacon_int) ||
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003337 nla_put_u32(msg, NL80211_ATTR_DTIM_PERIOD, params->dtim_period) ||
3338 nla_put(msg, NL80211_ATTR_SSID, params->ssid_len, params->ssid))
3339 goto fail;
Dmitry Shmidt0ccb66e2013-03-29 16:41:28 -07003340 if (params->proberesp && params->proberesp_len) {
3341 wpa_hexdump(MSG_DEBUG, "nl80211: proberesp (offload)",
3342 params->proberesp, params->proberesp_len);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003343 if (nla_put(msg, NL80211_ATTR_PROBE_RESP, params->proberesp_len,
3344 params->proberesp))
3345 goto fail;
Dmitry Shmidt0ccb66e2013-03-29 16:41:28 -07003346 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003347 switch (params->hide_ssid) {
3348 case NO_SSID_HIDING:
Dmitry Shmidt0ccb66e2013-03-29 16:41:28 -07003349 wpa_printf(MSG_DEBUG, "nl80211: hidden SSID not in use");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003350 if (nla_put_u32(msg, NL80211_ATTR_HIDDEN_SSID,
3351 NL80211_HIDDEN_SSID_NOT_IN_USE))
3352 goto fail;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003353 break;
3354 case HIDDEN_SSID_ZERO_LEN:
Dmitry Shmidt0ccb66e2013-03-29 16:41:28 -07003355 wpa_printf(MSG_DEBUG, "nl80211: hidden SSID zero len");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003356 if (nla_put_u32(msg, NL80211_ATTR_HIDDEN_SSID,
3357 NL80211_HIDDEN_SSID_ZERO_LEN))
3358 goto fail;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003359 break;
3360 case HIDDEN_SSID_ZERO_CONTENTS:
Dmitry Shmidt0ccb66e2013-03-29 16:41:28 -07003361 wpa_printf(MSG_DEBUG, "nl80211: hidden SSID zero contents");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003362 if (nla_put_u32(msg, NL80211_ATTR_HIDDEN_SSID,
3363 NL80211_HIDDEN_SSID_ZERO_CONTENTS))
3364 goto fail;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003365 break;
3366 }
Dmitry Shmidt0ccb66e2013-03-29 16:41:28 -07003367 wpa_printf(MSG_DEBUG, "nl80211: privacy=%d", params->privacy);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003368 if (params->privacy &&
3369 nla_put_flag(msg, NL80211_ATTR_PRIVACY))
3370 goto fail;
Dmitry Shmidt0ccb66e2013-03-29 16:41:28 -07003371 wpa_printf(MSG_DEBUG, "nl80211: auth_algs=0x%x", params->auth_algs);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003372 if ((params->auth_algs & (WPA_AUTH_ALG_OPEN | WPA_AUTH_ALG_SHARED)) ==
3373 (WPA_AUTH_ALG_OPEN | WPA_AUTH_ALG_SHARED)) {
3374 /* Leave out the attribute */
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003375 } else if (params->auth_algs & WPA_AUTH_ALG_SHARED) {
3376 if (nla_put_u32(msg, NL80211_ATTR_AUTH_TYPE,
3377 NL80211_AUTHTYPE_SHARED_KEY))
3378 goto fail;
3379 } else {
3380 if (nla_put_u32(msg, NL80211_ATTR_AUTH_TYPE,
3381 NL80211_AUTHTYPE_OPEN_SYSTEM))
3382 goto fail;
3383 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003384
Dmitry Shmidt0ccb66e2013-03-29 16:41:28 -07003385 wpa_printf(MSG_DEBUG, "nl80211: wpa_version=0x%x", params->wpa_version);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003386 ver = 0;
3387 if (params->wpa_version & WPA_PROTO_WPA)
3388 ver |= NL80211_WPA_VERSION_1;
3389 if (params->wpa_version & WPA_PROTO_RSN)
3390 ver |= NL80211_WPA_VERSION_2;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003391 if (ver &&
3392 nla_put_u32(msg, NL80211_ATTR_WPA_VERSIONS, ver))
3393 goto fail;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003394
Dmitry Shmidt0ccb66e2013-03-29 16:41:28 -07003395 wpa_printf(MSG_DEBUG, "nl80211: key_mgmt_suites=0x%x",
3396 params->key_mgmt_suites);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003397 num_suites = 0;
3398 if (params->key_mgmt_suites & WPA_KEY_MGMT_IEEE8021X)
3399 suites[num_suites++] = WLAN_AKM_SUITE_8021X;
3400 if (params->key_mgmt_suites & WPA_KEY_MGMT_PSK)
3401 suites[num_suites++] = WLAN_AKM_SUITE_PSK;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003402 if (num_suites &&
3403 nla_put(msg, NL80211_ATTR_AKM_SUITES, num_suites * sizeof(u32),
3404 suites))
3405 goto fail;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003406
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003407 if (params->key_mgmt_suites & WPA_KEY_MGMT_IEEE8021X_NO_WPA &&
3408 params->pairwise_ciphers & (WPA_CIPHER_WEP104 | WPA_CIPHER_WEP40) &&
3409 nla_put_flag(msg, NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT))
3410 goto fail;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003411
Dmitry Shmidt0ccb66e2013-03-29 16:41:28 -07003412 wpa_printf(MSG_DEBUG, "nl80211: pairwise_ciphers=0x%x",
3413 params->pairwise_ciphers);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08003414 num_suites = wpa_cipher_to_cipher_suites(params->pairwise_ciphers,
3415 suites, ARRAY_SIZE(suites));
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003416 if (num_suites &&
3417 nla_put(msg, NL80211_ATTR_CIPHER_SUITES_PAIRWISE,
3418 num_suites * sizeof(u32), suites))
3419 goto fail;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003420
Dmitry Shmidt0ccb66e2013-03-29 16:41:28 -07003421 wpa_printf(MSG_DEBUG, "nl80211: group_cipher=0x%x",
3422 params->group_cipher);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08003423 suite = wpa_cipher_to_cipher_suite(params->group_cipher);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003424 if (suite &&
3425 nla_put_u32(msg, NL80211_ATTR_CIPHER_SUITE_GROUP, suite))
3426 goto fail;
3427
3428 switch (params->smps_mode) {
3429 case HT_CAP_INFO_SMPS_DYNAMIC:
3430 wpa_printf(MSG_DEBUG, "nl80211: SMPS mode - dynamic");
3431 smps_mode = NL80211_SMPS_DYNAMIC;
3432 break;
3433 case HT_CAP_INFO_SMPS_STATIC:
3434 wpa_printf(MSG_DEBUG, "nl80211: SMPS mode - static");
3435 smps_mode = NL80211_SMPS_STATIC;
3436 break;
3437 default:
3438 /* invalid - fallback to smps off */
3439 case HT_CAP_INFO_SMPS_DISABLED:
3440 wpa_printf(MSG_DEBUG, "nl80211: SMPS mode - off");
3441 smps_mode = NL80211_SMPS_OFF;
3442 break;
3443 }
3444 if (nla_put_u32(msg, NL80211_ATTR_SMPS_MODE, smps_mode))
3445 goto fail;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003446
3447 if (params->beacon_ies) {
Dmitry Shmidt0ccb66e2013-03-29 16:41:28 -07003448 wpa_hexdump_buf(MSG_DEBUG, "nl80211: beacon_ies",
3449 params->beacon_ies);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003450 if (nla_put(msg, NL80211_ATTR_IE,
3451 wpabuf_len(params->beacon_ies),
3452 wpabuf_head(params->beacon_ies)))
3453 goto fail;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003454 }
3455 if (params->proberesp_ies) {
Dmitry Shmidt0ccb66e2013-03-29 16:41:28 -07003456 wpa_hexdump_buf(MSG_DEBUG, "nl80211: proberesp_ies",
3457 params->proberesp_ies);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003458 if (nla_put(msg, NL80211_ATTR_IE_PROBE_RESP,
3459 wpabuf_len(params->proberesp_ies),
3460 wpabuf_head(params->proberesp_ies)))
3461 goto fail;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003462 }
3463 if (params->assocresp_ies) {
Dmitry Shmidt0ccb66e2013-03-29 16:41:28 -07003464 wpa_hexdump_buf(MSG_DEBUG, "nl80211: assocresp_ies",
3465 params->assocresp_ies);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003466 if (nla_put(msg, NL80211_ATTR_IE_ASSOC_RESP,
3467 wpabuf_len(params->assocresp_ies),
3468 wpabuf_head(params->assocresp_ies)))
3469 goto fail;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003470 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003471
Dmitry Shmidt04949592012-07-19 12:16:46 -07003472 if (drv->capa.flags & WPA_DRIVER_FLAGS_INACTIVITY_TIMER) {
Dmitry Shmidt0ccb66e2013-03-29 16:41:28 -07003473 wpa_printf(MSG_DEBUG, "nl80211: ap_max_inactivity=%d",
3474 params->ap_max_inactivity);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003475 if (nla_put_u16(msg, NL80211_ATTR_INACTIVITY_TIMEOUT,
3476 params->ap_max_inactivity))
3477 goto fail;
Dmitry Shmidt04949592012-07-19 12:16:46 -07003478 }
3479
Dmitry Shmidt7f656022015-02-25 14:36:37 -08003480#ifdef CONFIG_P2P
3481 if (params->p2p_go_ctwindow > 0) {
3482 if (drv->p2p_go_ctwindow_supported) {
3483 wpa_printf(MSG_DEBUG, "nl80211: P2P GO ctwindow=%d",
3484 params->p2p_go_ctwindow);
3485 if (nla_put_u8(msg, NL80211_ATTR_P2P_CTWINDOW,
3486 params->p2p_go_ctwindow))
3487 goto fail;
3488 } else {
3489 wpa_printf(MSG_INFO,
3490 "nl80211: Driver does not support CTWindow configuration - ignore this parameter");
3491 }
3492 }
3493#endif /* CONFIG_P2P */
3494
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003495 ret = send_and_recv_msgs(drv, msg, NULL, NULL);
3496 if (ret) {
3497 wpa_printf(MSG_DEBUG, "nl80211: Beacon set failed: %d (%s)",
3498 ret, strerror(-ret));
3499 } else {
3500 bss->beacon_set = 1;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003501 nl80211_set_bss(bss, params->cts_protect, params->preamble,
3502 params->short_slot_time, params->ht_opmode,
3503 params->isolate, params->basic_rates);
Dmitry Shmidt7832adb2014-04-29 10:53:02 -07003504 if (beacon_set && params->freq &&
3505 params->freq->bandwidth != bss->bandwidth) {
3506 wpa_printf(MSG_DEBUG,
3507 "nl80211: Update BSS %s bandwidth: %d -> %d",
3508 bss->ifname, bss->bandwidth,
3509 params->freq->bandwidth);
3510 ret = nl80211_set_channel(bss, params->freq, 1);
3511 if (ret) {
3512 wpa_printf(MSG_DEBUG,
3513 "nl80211: Frequency set failed: %d (%s)",
3514 ret, strerror(-ret));
3515 } else {
3516 wpa_printf(MSG_DEBUG,
3517 "nl80211: Frequency set succeeded for ht2040 coex");
3518 bss->bandwidth = params->freq->bandwidth;
3519 }
3520 } else if (!beacon_set) {
3521 /*
3522 * cfg80211 updates the driver on frequence change in AP
3523 * mode only at the point when beaconing is started, so
3524 * set the initial value here.
3525 */
3526 bss->bandwidth = params->freq->bandwidth;
3527 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003528 }
3529 return ret;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003530fail:
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003531 nlmsg_free(msg);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003532 return -ENOBUFS;
3533}
3534
3535
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08003536static int nl80211_put_freq_params(struct nl_msg *msg,
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003537 const struct hostapd_freq_params *freq)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003538{
Dmitry Shmidtff787d52015-01-12 13:01:47 -08003539 wpa_printf(MSG_DEBUG, " * freq=%d", freq->freq);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003540 if (nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq->freq))
3541 return -ENOBUFS;
3542
Dmitry Shmidtff787d52015-01-12 13:01:47 -08003543 wpa_printf(MSG_DEBUG, " * vht_enabled=%d", freq->vht_enabled);
3544 wpa_printf(MSG_DEBUG, " * ht_enabled=%d", freq->ht_enabled);
3545
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08003546 if (freq->vht_enabled) {
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003547 enum nl80211_chan_width cw;
3548
Dmitry Shmidtff787d52015-01-12 13:01:47 -08003549 wpa_printf(MSG_DEBUG, " * bandwidth=%d", freq->bandwidth);
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08003550 switch (freq->bandwidth) {
3551 case 20:
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003552 cw = NL80211_CHAN_WIDTH_20;
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08003553 break;
3554 case 40:
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003555 cw = NL80211_CHAN_WIDTH_40;
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08003556 break;
3557 case 80:
3558 if (freq->center_freq2)
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003559 cw = NL80211_CHAN_WIDTH_80P80;
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08003560 else
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003561 cw = NL80211_CHAN_WIDTH_80;
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08003562 break;
3563 case 160:
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003564 cw = NL80211_CHAN_WIDTH_160;
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08003565 break;
3566 default:
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08003567 return -EINVAL;
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08003568 }
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003569
Dmitry Shmidtff787d52015-01-12 13:01:47 -08003570 wpa_printf(MSG_DEBUG, " * channel_width=%d", cw);
3571 wpa_printf(MSG_DEBUG, " * center_freq1=%d",
3572 freq->center_freq1);
3573 wpa_printf(MSG_DEBUG, " * center_freq2=%d",
3574 freq->center_freq2);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003575 if (nla_put_u32(msg, NL80211_ATTR_CHANNEL_WIDTH, cw) ||
3576 nla_put_u32(msg, NL80211_ATTR_CENTER_FREQ1,
3577 freq->center_freq1) ||
3578 (freq->center_freq2 &&
3579 nla_put_u32(msg, NL80211_ATTR_CENTER_FREQ2,
3580 freq->center_freq2)))
3581 return -ENOBUFS;
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08003582 } else if (freq->ht_enabled) {
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003583 enum nl80211_channel_type ct;
3584
Dmitry Shmidtff787d52015-01-12 13:01:47 -08003585 wpa_printf(MSG_DEBUG, " * sec_channel_offset=%d",
3586 freq->sec_channel_offset);
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08003587 switch (freq->sec_channel_offset) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003588 case -1:
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003589 ct = NL80211_CHAN_HT40MINUS;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003590 break;
3591 case 1:
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003592 ct = NL80211_CHAN_HT40PLUS;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003593 break;
3594 default:
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003595 ct = NL80211_CHAN_HT20;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003596 break;
3597 }
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003598
Dmitry Shmidtff787d52015-01-12 13:01:47 -08003599 wpa_printf(MSG_DEBUG, " * channel_type=%d", ct);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003600 if (nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE, ct))
3601 return -ENOBUFS;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003602 }
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08003603 return 0;
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08003604}
3605
3606
Dmitry Shmidt7832adb2014-04-29 10:53:02 -07003607static int nl80211_set_channel(struct i802_bss *bss,
3608 struct hostapd_freq_params *freq, int set_chan)
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08003609{
3610 struct wpa_driver_nl80211_data *drv = bss->drv;
3611 struct nl_msg *msg;
3612 int ret;
3613
3614 wpa_printf(MSG_DEBUG,
3615 "nl80211: Set freq %d (ht_enabled=%d, vht_enabled=%d, bandwidth=%d MHz, cf1=%d MHz, cf2=%d MHz)",
3616 freq->freq, freq->ht_enabled, freq->vht_enabled,
3617 freq->bandwidth, freq->center_freq1, freq->center_freq2);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003618
3619 msg = nl80211_drv_msg(drv, 0, set_chan ? NL80211_CMD_SET_CHANNEL :
3620 NL80211_CMD_SET_WIPHY);
3621 if (!msg || nl80211_put_freq_params(msg, freq) < 0) {
3622 nlmsg_free(msg);
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08003623 return -1;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003624 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003625
3626 ret = send_and_recv_msgs(drv, msg, NULL, NULL);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003627 if (ret == 0) {
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08003628 bss->freq = freq->freq;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003629 return 0;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003630 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003631 wpa_printf(MSG_DEBUG, "nl80211: Failed to set channel (freq=%d): "
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08003632 "%d (%s)", freq->freq, ret, strerror(-ret));
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003633 return -1;
3634}
3635
3636
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003637static u32 sta_flags_nl80211(int flags)
3638{
3639 u32 f = 0;
3640
3641 if (flags & WPA_STA_AUTHORIZED)
3642 f |= BIT(NL80211_STA_FLAG_AUTHORIZED);
3643 if (flags & WPA_STA_WMM)
3644 f |= BIT(NL80211_STA_FLAG_WME);
3645 if (flags & WPA_STA_SHORT_PREAMBLE)
3646 f |= BIT(NL80211_STA_FLAG_SHORT_PREAMBLE);
3647 if (flags & WPA_STA_MFP)
3648 f |= BIT(NL80211_STA_FLAG_MFP);
3649 if (flags & WPA_STA_TDLS_PEER)
3650 f |= BIT(NL80211_STA_FLAG_TDLS_PEER);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003651 if (flags & WPA_STA_AUTHENTICATED)
3652 f |= BIT(NL80211_STA_FLAG_AUTHENTICATED);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003653
3654 return f;
3655}
3656
3657
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003658#ifdef CONFIG_MESH
3659static u32 sta_plink_state_nl80211(enum mesh_plink_state state)
3660{
3661 switch (state) {
3662 case PLINK_LISTEN:
3663 return NL80211_PLINK_LISTEN;
3664 case PLINK_OPEN_SENT:
3665 return NL80211_PLINK_OPN_SNT;
3666 case PLINK_OPEN_RCVD:
3667 return NL80211_PLINK_OPN_RCVD;
3668 case PLINK_CNF_RCVD:
3669 return NL80211_PLINK_CNF_RCVD;
3670 case PLINK_ESTAB:
3671 return NL80211_PLINK_ESTAB;
3672 case PLINK_HOLDING:
3673 return NL80211_PLINK_HOLDING;
3674 case PLINK_BLOCKED:
3675 return NL80211_PLINK_BLOCKED;
3676 default:
3677 wpa_printf(MSG_ERROR, "nl80211: Invalid mesh plink state %d",
3678 state);
3679 }
3680 return -1;
3681}
3682#endif /* CONFIG_MESH */
3683
3684
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003685static int wpa_driver_nl80211_sta_add(void *priv,
3686 struct hostapd_sta_add_params *params)
3687{
3688 struct i802_bss *bss = priv;
3689 struct wpa_driver_nl80211_data *drv = bss->drv;
Dmitry Shmidt8da800a2013-04-24 12:57:01 -07003690 struct nl_msg *msg;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003691 struct nl80211_sta_flag_update upd;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003692 int ret = -ENOBUFS;
3693
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003694 if ((params->flags & WPA_STA_TDLS_PEER) &&
3695 !(drv->capa.flags & WPA_DRIVER_FLAGS_TDLS_SUPPORT))
3696 return -EOPNOTSUPP;
3697
Dmitry Shmidtf8623282013-02-20 14:34:59 -08003698 wpa_printf(MSG_DEBUG, "nl80211: %s STA " MACSTR,
3699 params->set ? "Set" : "Add", MAC2STR(params->addr));
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003700 msg = nl80211_bss_msg(bss, 0, params->set ? NL80211_CMD_SET_STATION :
3701 NL80211_CMD_NEW_STATION);
3702 if (!msg || nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, params->addr))
3703 goto fail;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003704
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003705 if (!params->set || (params->flags & WPA_STA_TDLS_PEER)) {
3706 wpa_hexdump(MSG_DEBUG, " * supported rates",
3707 params->supp_rates, params->supp_rates_len);
3708 wpa_printf(MSG_DEBUG, " * capability=0x%x",
3709 params->capability);
3710 if (nla_put(msg, NL80211_ATTR_STA_SUPPORTED_RATES,
3711 params->supp_rates_len, params->supp_rates) ||
3712 nla_put_u16(msg, NL80211_ATTR_STA_CAPABILITY,
3713 params->capability))
3714 goto fail;
3715
3716 if (params->ht_capabilities) {
3717 wpa_hexdump(MSG_DEBUG, " * ht_capabilities",
3718 (u8 *) params->ht_capabilities,
3719 sizeof(*params->ht_capabilities));
3720 if (nla_put(msg, NL80211_ATTR_HT_CAPABILITY,
3721 sizeof(*params->ht_capabilities),
3722 params->ht_capabilities))
3723 goto fail;
3724 }
3725
3726 if (params->vht_capabilities) {
3727 wpa_hexdump(MSG_DEBUG, " * vht_capabilities",
3728 (u8 *) params->vht_capabilities,
3729 sizeof(*params->vht_capabilities));
3730 if (nla_put(msg, NL80211_ATTR_VHT_CAPABILITY,
3731 sizeof(*params->vht_capabilities),
3732 params->vht_capabilities))
3733 goto fail;
3734 }
3735
3736 if (params->ext_capab) {
3737 wpa_hexdump(MSG_DEBUG, " * ext_capab",
3738 params->ext_capab, params->ext_capab_len);
3739 if (nla_put(msg, NL80211_ATTR_STA_EXT_CAPABILITY,
3740 params->ext_capab_len, params->ext_capab))
3741 goto fail;
3742 }
3743 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003744 if (!params->set) {
Dmitry Shmidt51b6ea82013-05-08 10:42:09 -07003745 if (params->aid) {
3746 wpa_printf(MSG_DEBUG, " * aid=%u", params->aid);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003747 if (nla_put_u16(msg, NL80211_ATTR_STA_AID, params->aid))
3748 goto fail;
Dmitry Shmidt51b6ea82013-05-08 10:42:09 -07003749 } else {
3750 /*
3751 * cfg80211 validates that AID is non-zero, so we have
3752 * to make this a non-zero value for the TDLS case where
3753 * a dummy STA entry is used for now.
3754 */
3755 wpa_printf(MSG_DEBUG, " * aid=1 (TDLS workaround)");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003756 if (nla_put_u16(msg, NL80211_ATTR_STA_AID, 1))
3757 goto fail;
Dmitry Shmidt51b6ea82013-05-08 10:42:09 -07003758 }
Dmitry Shmidtf8623282013-02-20 14:34:59 -08003759 wpa_printf(MSG_DEBUG, " * listen_interval=%u",
3760 params->listen_interval);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003761 if (nla_put_u16(msg, NL80211_ATTR_STA_LISTEN_INTERVAL,
3762 params->listen_interval))
3763 goto fail;
Dmitry Shmidt8bae4132013-06-06 11:25:10 -07003764 } else if (params->aid && (params->flags & WPA_STA_TDLS_PEER)) {
3765 wpa_printf(MSG_DEBUG, " * peer_aid=%u", params->aid);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003766 if (nla_put_u16(msg, NL80211_ATTR_PEER_AID, params->aid))
3767 goto fail;
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08003768 }
3769
Dmitry Shmidtbd14a572014-02-18 10:33:49 -08003770 if (params->vht_opmode_enabled) {
3771 wpa_printf(MSG_DEBUG, " * opmode=%u", params->vht_opmode);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003772 if (nla_put_u8(msg, NL80211_ATTR_OPMODE_NOTIF,
3773 params->vht_opmode))
3774 goto fail;
Dmitry Shmidtf8623282013-02-20 14:34:59 -08003775 }
3776
Dmitry Shmidt344abd32014-01-14 13:17:00 -08003777 if (params->supp_channels) {
3778 wpa_hexdump(MSG_DEBUG, " * supported channels",
3779 params->supp_channels, params->supp_channels_len);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003780 if (nla_put(msg, NL80211_ATTR_STA_SUPPORTED_CHANNELS,
3781 params->supp_channels_len, params->supp_channels))
3782 goto fail;
Dmitry Shmidt344abd32014-01-14 13:17:00 -08003783 }
3784
3785 if (params->supp_oper_classes) {
3786 wpa_hexdump(MSG_DEBUG, " * supported operating classes",
3787 params->supp_oper_classes,
3788 params->supp_oper_classes_len);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003789 if (nla_put(msg, NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES,
3790 params->supp_oper_classes_len,
3791 params->supp_oper_classes))
3792 goto fail;
Dmitry Shmidt344abd32014-01-14 13:17:00 -08003793 }
3794
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003795 os_memset(&upd, 0, sizeof(upd));
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003796 upd.set = sta_flags_nl80211(params->flags);
3797 upd.mask = upd.set | sta_flags_nl80211(params->flags_mask);
Dmitry Shmidtf8623282013-02-20 14:34:59 -08003798 wpa_printf(MSG_DEBUG, " * flags set=0x%x mask=0x%x",
3799 upd.set, upd.mask);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003800 if (nla_put(msg, NL80211_ATTR_STA_FLAGS2, sizeof(upd), &upd))
3801 goto fail;
3802
3803#ifdef CONFIG_MESH
3804 if (params->plink_state &&
3805 nla_put_u8(msg, NL80211_ATTR_STA_PLINK_STATE,
3806 sta_plink_state_nl80211(params->plink_state)))
3807 goto fail;
3808#endif /* CONFIG_MESH */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003809
3810 if (params->flags & WPA_STA_WMM) {
Dmitry Shmidt8da800a2013-04-24 12:57:01 -07003811 struct nlattr *wme = nla_nest_start(msg, NL80211_ATTR_STA_WME);
3812
Dmitry Shmidtf8623282013-02-20 14:34:59 -08003813 wpa_printf(MSG_DEBUG, " * qosinfo=0x%x", params->qosinfo);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003814 if (!wme ||
3815 nla_put_u8(msg, NL80211_STA_WME_UAPSD_QUEUES,
3816 params->qosinfo & WMM_QOSINFO_STA_AC_MASK) ||
3817 nla_put_u8(msg, NL80211_STA_WME_MAX_SP,
3818 (params->qosinfo >> WMM_QOSINFO_STA_SP_SHIFT) &
3819 WMM_QOSINFO_STA_SP_MASK))
3820 goto fail;
Dmitry Shmidt8da800a2013-04-24 12:57:01 -07003821 nla_nest_end(msg, wme);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003822 }
3823
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003824 ret = send_and_recv_msgs(drv, msg, NULL, NULL);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003825 msg = NULL;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003826 if (ret)
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003827 wpa_printf(MSG_DEBUG, "nl80211: NL80211_CMD_%s_STATION "
3828 "result: %d (%s)", params->set ? "SET" : "NEW", ret,
3829 strerror(-ret));
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003830 if (ret == -EEXIST)
3831 ret = 0;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003832fail:
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003833 nlmsg_free(msg);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003834 return ret;
3835}
3836
3837
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07003838static void rtnl_neigh_delete_fdb_entry(struct i802_bss *bss, const u8 *addr)
3839{
3840#ifdef CONFIG_LIBNL3_ROUTE
3841 struct wpa_driver_nl80211_data *drv = bss->drv;
3842 struct rtnl_neigh *rn;
3843 struct nl_addr *nl_addr;
3844 int err;
3845
3846 rn = rtnl_neigh_alloc();
3847 if (!rn)
3848 return;
3849
3850 rtnl_neigh_set_family(rn, AF_BRIDGE);
3851 rtnl_neigh_set_ifindex(rn, bss->ifindex);
3852 nl_addr = nl_addr_build(AF_BRIDGE, (void *) addr, ETH_ALEN);
3853 if (!nl_addr) {
3854 rtnl_neigh_put(rn);
3855 return;
3856 }
3857 rtnl_neigh_set_lladdr(rn, nl_addr);
3858
3859 err = rtnl_neigh_delete(drv->rtnl_sk, rn, 0);
3860 if (err < 0) {
3861 wpa_printf(MSG_DEBUG, "nl80211: bridge FDB entry delete for "
3862 MACSTR " ifindex=%d failed: %s", MAC2STR(addr),
3863 bss->ifindex, nl_geterror(err));
3864 } else {
3865 wpa_printf(MSG_DEBUG, "nl80211: deleted bridge FDB entry for "
3866 MACSTR, MAC2STR(addr));
3867 }
3868
3869 nl_addr_put(nl_addr);
3870 rtnl_neigh_put(rn);
3871#endif /* CONFIG_LIBNL3_ROUTE */
3872}
3873
3874
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003875static int wpa_driver_nl80211_sta_remove(struct i802_bss *bss, const u8 *addr,
3876 int deauth, u16 reason_code)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003877{
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003878 struct wpa_driver_nl80211_data *drv = bss->drv;
3879 struct nl_msg *msg;
3880 int ret;
3881
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003882 if (!(msg = nl80211_bss_msg(bss, 0, NL80211_CMD_DEL_STATION)) ||
3883 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) ||
3884 (deauth == 0 &&
3885 nla_put_u8(msg, NL80211_ATTR_MGMT_SUBTYPE,
3886 WLAN_FC_STYPE_DISASSOC)) ||
3887 (deauth == 1 &&
3888 nla_put_u8(msg, NL80211_ATTR_MGMT_SUBTYPE,
3889 WLAN_FC_STYPE_DEAUTH)) ||
3890 (reason_code &&
3891 nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason_code))) {
3892 nlmsg_free(msg);
3893 return -ENOBUFS;
3894 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003895
3896 ret = send_and_recv_msgs(drv, msg, NULL, NULL);
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -07003897 wpa_printf(MSG_DEBUG, "nl80211: sta_remove -> DEL_STATION %s " MACSTR
3898 " --> %d (%s)",
3899 bss->ifname, MAC2STR(addr), ret, strerror(-ret));
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07003900
3901 if (drv->rtnl_sk)
3902 rtnl_neigh_delete_fdb_entry(bss, addr);
3903
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003904 if (ret == -ENOENT)
3905 return 0;
3906 return ret;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003907}
3908
3909
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003910void nl80211_remove_iface(struct wpa_driver_nl80211_data *drv, int ifidx)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003911{
3912 struct nl_msg *msg;
Dmitry Shmidt76cd2cc2014-05-27 12:56:04 -07003913 struct wpa_driver_nl80211_data *drv2;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003914
3915 wpa_printf(MSG_DEBUG, "nl80211: Remove interface ifindex=%d", ifidx);
3916
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003917 /* stop listening for EAPOL on this interface */
Dmitry Shmidt76cd2cc2014-05-27 12:56:04 -07003918 dl_list_for_each(drv2, &drv->global->interfaces,
3919 struct wpa_driver_nl80211_data, list)
3920 del_ifidx(drv2, ifidx);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003921
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003922 msg = nl80211_ifindex_msg(drv, ifidx, 0, NL80211_CMD_DEL_INTERFACE);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003923 if (send_and_recv_msgs(drv, msg, NULL, NULL) == 0)
3924 return;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003925 wpa_printf(MSG_ERROR, "Failed to remove interface (ifidx=%d)", ifidx);
3926}
3927
3928
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003929static const char * nl80211_iftype_str(enum nl80211_iftype mode)
3930{
3931 switch (mode) {
3932 case NL80211_IFTYPE_ADHOC:
3933 return "ADHOC";
3934 case NL80211_IFTYPE_STATION:
3935 return "STATION";
3936 case NL80211_IFTYPE_AP:
3937 return "AP";
Dmitry Shmidtf7e0a992013-05-23 11:03:10 -07003938 case NL80211_IFTYPE_AP_VLAN:
3939 return "AP_VLAN";
3940 case NL80211_IFTYPE_WDS:
3941 return "WDS";
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003942 case NL80211_IFTYPE_MONITOR:
3943 return "MONITOR";
Dmitry Shmidtf7e0a992013-05-23 11:03:10 -07003944 case NL80211_IFTYPE_MESH_POINT:
3945 return "MESH_POINT";
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003946 case NL80211_IFTYPE_P2P_CLIENT:
3947 return "P2P_CLIENT";
3948 case NL80211_IFTYPE_P2P_GO:
3949 return "P2P_GO";
Dmitry Shmidt34af3062013-07-11 10:46:32 -07003950 case NL80211_IFTYPE_P2P_DEVICE:
3951 return "P2P_DEVICE";
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003952 default:
3953 return "unknown";
3954 }
3955}
3956
3957
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003958static int nl80211_create_iface_once(struct wpa_driver_nl80211_data *drv,
3959 const char *ifname,
3960 enum nl80211_iftype iftype,
Dmitry Shmidt34af3062013-07-11 10:46:32 -07003961 const u8 *addr, int wds,
3962 int (*handler)(struct nl_msg *, void *),
3963 void *arg)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003964{
Dmitry Shmidt8da800a2013-04-24 12:57:01 -07003965 struct nl_msg *msg;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003966 int ifidx;
3967 int ret = -ENOBUFS;
3968
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003969 wpa_printf(MSG_DEBUG, "nl80211: Create interface iftype %d (%s)",
3970 iftype, nl80211_iftype_str(iftype));
3971
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003972 msg = nl80211_cmd_msg(drv->first_bss, 0, NL80211_CMD_NEW_INTERFACE);
3973 if (!msg ||
3974 nla_put_string(msg, NL80211_ATTR_IFNAME, ifname) ||
3975 nla_put_u32(msg, NL80211_ATTR_IFTYPE, iftype))
3976 goto fail;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003977
3978 if (iftype == NL80211_IFTYPE_MONITOR) {
Dmitry Shmidt8da800a2013-04-24 12:57:01 -07003979 struct nlattr *flags;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003980
Dmitry Shmidt8da800a2013-04-24 12:57:01 -07003981 flags = nla_nest_start(msg, NL80211_ATTR_MNTR_FLAGS);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003982 if (!flags ||
3983 nla_put_flag(msg, NL80211_MNTR_FLAG_COOK_FRAMES))
3984 goto fail;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003985
Dmitry Shmidt8da800a2013-04-24 12:57:01 -07003986 nla_nest_end(msg, flags);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003987 } else if (wds) {
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003988 if (nla_put_u8(msg, NL80211_ATTR_4ADDR, wds))
3989 goto fail;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003990 }
3991
Dmitry Shmidtb58836e2014-04-29 14:35:56 -07003992 /*
3993 * Tell cfg80211 that the interface belongs to the socket that created
3994 * it, and the interface should be deleted when the socket is closed.
3995 */
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003996 if (nla_put_flag(msg, NL80211_ATTR_IFACE_SOCKET_OWNER))
3997 goto fail;
Dmitry Shmidtb58836e2014-04-29 14:35:56 -07003998
Dmitry Shmidt34af3062013-07-11 10:46:32 -07003999 ret = send_and_recv_msgs(drv, msg, handler, arg);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004000 msg = NULL;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004001 if (ret) {
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004002 fail:
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004003 nlmsg_free(msg);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004004 wpa_printf(MSG_ERROR, "Failed to create interface %s: %d (%s)",
4005 ifname, ret, strerror(-ret));
4006 return ret;
4007 }
4008
Dmitry Shmidt34af3062013-07-11 10:46:32 -07004009 if (iftype == NL80211_IFTYPE_P2P_DEVICE)
4010 return 0;
4011
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004012 ifidx = if_nametoindex(ifname);
4013 wpa_printf(MSG_DEBUG, "nl80211: New interface %s created: ifindex=%d",
4014 ifname, ifidx);
4015
4016 if (ifidx <= 0)
4017 return -1;
4018
Dmitry Shmidt76cd2cc2014-05-27 12:56:04 -07004019 /*
4020 * Some virtual interfaces need to process EAPOL packets and events on
4021 * the parent interface. This is used mainly with hostapd.
4022 */
4023 if (drv->hostapd ||
4024 iftype == NL80211_IFTYPE_AP_VLAN ||
4025 iftype == NL80211_IFTYPE_WDS ||
4026 iftype == NL80211_IFTYPE_MONITOR) {
4027 /* start listening for EAPOL on this interface */
4028 add_ifidx(drv, ifidx);
4029 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004030
4031 if (addr && iftype != NL80211_IFTYPE_MONITOR &&
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004032 linux_set_ifhwaddr(drv->global->ioctl_sock, ifname, addr)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004033 nl80211_remove_iface(drv, ifidx);
4034 return -1;
4035 }
4036
4037 return ifidx;
4038}
4039
4040
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004041int nl80211_create_iface(struct wpa_driver_nl80211_data *drv,
4042 const char *ifname, enum nl80211_iftype iftype,
4043 const u8 *addr, int wds,
4044 int (*handler)(struct nl_msg *, void *),
4045 void *arg, int use_existing)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004046{
4047 int ret;
4048
Dmitry Shmidt34af3062013-07-11 10:46:32 -07004049 ret = nl80211_create_iface_once(drv, ifname, iftype, addr, wds, handler,
4050 arg);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004051
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004052 /* if error occurred and interface exists already */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004053 if (ret == -ENFILE && if_nametoindex(ifname)) {
Dmitry Shmidtcce06662013-11-04 18:44:24 -08004054 if (use_existing) {
4055 wpa_printf(MSG_DEBUG, "nl80211: Continue using existing interface %s",
4056 ifname);
Dmitry Shmidtdf5a7e42014-04-02 12:59:59 -07004057 if (addr && iftype != NL80211_IFTYPE_MONITOR &&
4058 linux_set_ifhwaddr(drv->global->ioctl_sock, ifname,
4059 addr) < 0 &&
4060 (linux_set_iface_flags(drv->global->ioctl_sock,
4061 ifname, 0) < 0 ||
4062 linux_set_ifhwaddr(drv->global->ioctl_sock, ifname,
4063 addr) < 0 ||
4064 linux_set_iface_flags(drv->global->ioctl_sock,
4065 ifname, 1) < 0))
4066 return -1;
Dmitry Shmidtcce06662013-11-04 18:44:24 -08004067 return -ENFILE;
4068 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004069 wpa_printf(MSG_INFO, "Try to remove and re-create %s", ifname);
4070
4071 /* Try to remove the interface that was already there. */
4072 nl80211_remove_iface(drv, if_nametoindex(ifname));
4073
4074 /* Try to create the interface again */
4075 ret = nl80211_create_iface_once(drv, ifname, iftype, addr,
Dmitry Shmidt34af3062013-07-11 10:46:32 -07004076 wds, handler, arg);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004077 }
4078
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004079 if (ret >= 0 && is_p2p_net_interface(iftype)) {
4080 wpa_printf(MSG_DEBUG,
4081 "nl80211: Interface %s created for P2P - disable 11b rates",
4082 ifname);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004083 nl80211_disable_11b_rates(drv, ret, 1);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004084 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004085
4086 return ret;
4087}
4088
4089
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004090static int nl80211_setup_ap(struct i802_bss *bss)
4091{
4092 struct wpa_driver_nl80211_data *drv = bss->drv;
4093
Dmitry Shmidtcce06662013-11-04 18:44:24 -08004094 wpa_printf(MSG_DEBUG, "nl80211: Setup AP(%s) - device_ap_sme=%d use_monitor=%d",
4095 bss->ifname, drv->device_ap_sme, drv->use_monitor);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004096
4097 /*
4098 * Disable Probe Request reporting unless we need it in this way for
4099 * devices that include the AP SME, in the other case (unless using
4100 * monitor iface) we'll get it through the nl_mgmt socket instead.
4101 */
4102 if (!drv->device_ap_sme)
4103 wpa_driver_nl80211_probe_req_report(bss, 0);
4104
4105 if (!drv->device_ap_sme && !drv->use_monitor)
4106 if (nl80211_mgmt_subscribe_ap(bss))
4107 return -1;
4108
4109 if (drv->device_ap_sme && !drv->use_monitor)
4110 if (nl80211_mgmt_subscribe_ap_dev_sme(bss))
4111 return -1;
4112
4113 if (!drv->device_ap_sme && drv->use_monitor &&
4114 nl80211_create_monitor_interface(drv) &&
4115 !drv->device_ap_sme)
Dmitry Shmidt04949592012-07-19 12:16:46 -07004116 return -1;
4117
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004118 if (drv->device_ap_sme &&
4119 wpa_driver_nl80211_probe_req_report(bss, 1) < 0) {
4120 wpa_printf(MSG_DEBUG, "nl80211: Failed to enable "
4121 "Probe Request frame reporting in AP mode");
4122 /* Try to survive without this */
4123 }
4124
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004125 return 0;
4126}
4127
4128
4129static void nl80211_teardown_ap(struct i802_bss *bss)
4130{
4131 struct wpa_driver_nl80211_data *drv = bss->drv;
4132
Dmitry Shmidtcce06662013-11-04 18:44:24 -08004133 wpa_printf(MSG_DEBUG, "nl80211: Teardown AP(%s) - device_ap_sme=%d use_monitor=%d",
4134 bss->ifname, drv->device_ap_sme, drv->use_monitor);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004135 if (drv->device_ap_sme) {
4136 wpa_driver_nl80211_probe_req_report(bss, 0);
4137 if (!drv->use_monitor)
4138 nl80211_mgmt_unsubscribe(bss, "AP teardown (dev SME)");
4139 } else if (drv->use_monitor)
4140 nl80211_remove_monitor_interface(drv);
4141 else
4142 nl80211_mgmt_unsubscribe(bss, "AP teardown");
4143
4144 bss->beacon_set = 0;
4145}
4146
4147
4148static int nl80211_send_eapol_data(struct i802_bss *bss,
4149 const u8 *addr, const u8 *data,
4150 size_t data_len)
4151{
4152 struct sockaddr_ll ll;
4153 int ret;
4154
4155 if (bss->drv->eapol_tx_sock < 0) {
4156 wpa_printf(MSG_DEBUG, "nl80211: No socket to send EAPOL");
4157 return -1;
4158 }
4159
4160 os_memset(&ll, 0, sizeof(ll));
4161 ll.sll_family = AF_PACKET;
4162 ll.sll_ifindex = bss->ifindex;
4163 ll.sll_protocol = htons(ETH_P_PAE);
4164 ll.sll_halen = ETH_ALEN;
4165 os_memcpy(ll.sll_addr, addr, ETH_ALEN);
4166 ret = sendto(bss->drv->eapol_tx_sock, data, data_len, 0,
4167 (struct sockaddr *) &ll, sizeof(ll));
4168 if (ret < 0)
4169 wpa_printf(MSG_ERROR, "nl80211: EAPOL TX: %s",
4170 strerror(errno));
4171
4172 return ret;
4173}
4174
4175
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004176static const u8 rfc1042_header[6] = { 0xaa, 0xaa, 0x03, 0x00, 0x00, 0x00 };
4177
4178static int wpa_driver_nl80211_hapd_send_eapol(
4179 void *priv, const u8 *addr, const u8 *data,
4180 size_t data_len, int encrypt, const u8 *own_addr, u32 flags)
4181{
4182 struct i802_bss *bss = priv;
4183 struct wpa_driver_nl80211_data *drv = bss->drv;
4184 struct ieee80211_hdr *hdr;
4185 size_t len;
4186 u8 *pos;
4187 int res;
4188 int qos = flags & WPA_STA_WMM;
Dmitry Shmidt641185e2013-11-06 15:17:13 -08004189
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004190 if (drv->device_ap_sme || !drv->use_monitor)
4191 return nl80211_send_eapol_data(bss, addr, data, data_len);
4192
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004193 len = sizeof(*hdr) + (qos ? 2 : 0) + sizeof(rfc1042_header) + 2 +
4194 data_len;
4195 hdr = os_zalloc(len);
4196 if (hdr == NULL) {
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -07004197 wpa_printf(MSG_INFO, "nl80211: Failed to allocate EAPOL buffer(len=%lu)",
4198 (unsigned long) len);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004199 return -1;
4200 }
4201
4202 hdr->frame_control =
4203 IEEE80211_FC(WLAN_FC_TYPE_DATA, WLAN_FC_STYPE_DATA);
4204 hdr->frame_control |= host_to_le16(WLAN_FC_FROMDS);
4205 if (encrypt)
4206 hdr->frame_control |= host_to_le16(WLAN_FC_ISWEP);
4207 if (qos) {
4208 hdr->frame_control |=
4209 host_to_le16(WLAN_FC_STYPE_QOS_DATA << 4);
4210 }
4211
4212 memcpy(hdr->IEEE80211_DA_FROMDS, addr, ETH_ALEN);
4213 memcpy(hdr->IEEE80211_BSSID_FROMDS, own_addr, ETH_ALEN);
4214 memcpy(hdr->IEEE80211_SA_FROMDS, own_addr, ETH_ALEN);
4215 pos = (u8 *) (hdr + 1);
4216
4217 if (qos) {
Dmitry Shmidtaa532512012-09-24 10:35:31 -07004218 /* Set highest priority in QoS header */
4219 pos[0] = 7;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004220 pos[1] = 0;
4221 pos += 2;
4222 }
4223
4224 memcpy(pos, rfc1042_header, sizeof(rfc1042_header));
4225 pos += sizeof(rfc1042_header);
4226 WPA_PUT_BE16(pos, ETH_P_PAE);
4227 pos += 2;
4228 memcpy(pos, data, data_len);
4229
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08004230 res = wpa_driver_nl80211_send_frame(bss, (u8 *) hdr, len, encrypt, 0,
4231 0, 0, 0, 0);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004232 if (res < 0) {
4233 wpa_printf(MSG_ERROR, "i802_send_eapol - packet len: %lu - "
4234 "failed: %d (%s)",
4235 (unsigned long) len, errno, strerror(errno));
4236 }
4237 os_free(hdr);
4238
4239 return res;
4240}
4241
4242
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004243static int wpa_driver_nl80211_sta_set_flags(void *priv, const u8 *addr,
4244 int total_flags,
4245 int flags_or, int flags_and)
4246{
4247 struct i802_bss *bss = priv;
Dmitry Shmidt8da800a2013-04-24 12:57:01 -07004248 struct nl_msg *msg;
4249 struct nlattr *flags;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004250 struct nl80211_sta_flag_update upd;
4251
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07004252 wpa_printf(MSG_DEBUG, "nl80211: Set STA flags - ifname=%s addr=" MACSTR
4253 " total_flags=0x%x flags_or=0x%x flags_and=0x%x authorized=%d",
4254 bss->ifname, MAC2STR(addr), total_flags, flags_or, flags_and,
4255 !!(total_flags & WPA_STA_AUTHORIZED));
4256
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004257 if (!(msg = nl80211_bss_msg(bss, 0, NL80211_CMD_SET_STATION)) ||
4258 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr))
4259 goto fail;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004260
4261 /*
4262 * Backwards compatibility version using NL80211_ATTR_STA_FLAGS. This
4263 * can be removed eventually.
4264 */
Dmitry Shmidt8da800a2013-04-24 12:57:01 -07004265 flags = nla_nest_start(msg, NL80211_ATTR_STA_FLAGS);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004266 if (!flags ||
4267 ((total_flags & WPA_STA_AUTHORIZED) &&
4268 nla_put_flag(msg, NL80211_STA_FLAG_AUTHORIZED)) ||
4269 ((total_flags & WPA_STA_WMM) &&
4270 nla_put_flag(msg, NL80211_STA_FLAG_WME)) ||
4271 ((total_flags & WPA_STA_SHORT_PREAMBLE) &&
4272 nla_put_flag(msg, NL80211_STA_FLAG_SHORT_PREAMBLE)) ||
4273 ((total_flags & WPA_STA_MFP) &&
4274 nla_put_flag(msg, NL80211_STA_FLAG_MFP)) ||
4275 ((total_flags & WPA_STA_TDLS_PEER) &&
4276 nla_put_flag(msg, NL80211_STA_FLAG_TDLS_PEER)))
4277 goto fail;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004278
Dmitry Shmidt8da800a2013-04-24 12:57:01 -07004279 nla_nest_end(msg, flags);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004280
4281 os_memset(&upd, 0, sizeof(upd));
4282 upd.mask = sta_flags_nl80211(flags_or | ~flags_and);
4283 upd.set = sta_flags_nl80211(flags_or);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004284 if (nla_put(msg, NL80211_ATTR_STA_FLAGS2, sizeof(upd), &upd))
4285 goto fail;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004286
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004287 return send_and_recv_msgs(bss->drv, msg, NULL, NULL);
4288fail:
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004289 nlmsg_free(msg);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004290 return -ENOBUFS;
4291}
4292
4293
4294static int wpa_driver_nl80211_ap(struct wpa_driver_nl80211_data *drv,
4295 struct wpa_driver_associate_params *params)
4296{
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08004297 enum nl80211_iftype nlmode, old_mode;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004298
4299 if (params->p2p) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004300 wpa_printf(MSG_DEBUG, "nl80211: Setup AP operations for P2P "
4301 "group (GO)");
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004302 nlmode = NL80211_IFTYPE_P2P_GO;
4303 } else
4304 nlmode = NL80211_IFTYPE_AP;
4305
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08004306 old_mode = drv->nlmode;
Dmitry Shmidtcce06662013-11-04 18:44:24 -08004307 if (wpa_driver_nl80211_set_mode(drv->first_bss, nlmode)) {
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08004308 nl80211_remove_monitor_interface(drv);
4309 return -1;
4310 }
4311
Dmitry Shmidt203eadb2015-03-05 14:16:04 -08004312 if (params->freq.freq &&
4313 nl80211_set_channel(drv->first_bss, &params->freq, 0)) {
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08004314 if (old_mode != nlmode)
Dmitry Shmidtcce06662013-11-04 18:44:24 -08004315 wpa_driver_nl80211_set_mode(drv->first_bss, old_mode);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004316 nl80211_remove_monitor_interface(drv);
4317 return -1;
4318 }
4319
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004320 return 0;
4321}
4322
4323
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004324static int nl80211_leave_ibss(struct wpa_driver_nl80211_data *drv,
4325 int reset_mode)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004326{
4327 struct nl_msg *msg;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004328 int ret;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004329
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004330 msg = nl80211_drv_msg(drv, 0, NL80211_CMD_LEAVE_IBSS);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004331 ret = send_and_recv_msgs(drv, msg, NULL, NULL);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004332 if (ret) {
4333 wpa_printf(MSG_DEBUG, "nl80211: Leave IBSS failed: ret=%d "
4334 "(%s)", ret, strerror(-ret));
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004335 } else {
4336 wpa_printf(MSG_DEBUG,
4337 "nl80211: Leave IBSS request sent successfully");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004338 }
4339
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004340 if (reset_mode &&
4341 wpa_driver_nl80211_set_mode(drv->first_bss,
Dmitry Shmidt56052862013-10-04 10:23:25 -07004342 NL80211_IFTYPE_STATION)) {
4343 wpa_printf(MSG_INFO, "nl80211: Failed to set interface into "
4344 "station mode");
4345 }
4346
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004347 return ret;
4348}
4349
4350
Dmitry Shmidt2f74e362015-01-21 13:19:05 -08004351static int nl80211_ht_vht_overrides(struct nl_msg *msg,
4352 struct wpa_driver_associate_params *params)
4353{
4354 if (params->disable_ht && nla_put_flag(msg, NL80211_ATTR_DISABLE_HT))
4355 return -1;
4356
4357 if (params->htcaps && params->htcaps_mask) {
4358 int sz = sizeof(struct ieee80211_ht_capabilities);
4359 wpa_hexdump(MSG_DEBUG, " * htcaps", params->htcaps, sz);
4360 wpa_hexdump(MSG_DEBUG, " * htcaps_mask",
4361 params->htcaps_mask, sz);
4362 if (nla_put(msg, NL80211_ATTR_HT_CAPABILITY, sz,
4363 params->htcaps) ||
4364 nla_put(msg, NL80211_ATTR_HT_CAPABILITY_MASK, sz,
4365 params->htcaps_mask))
4366 return -1;
4367 }
4368
4369#ifdef CONFIG_VHT_OVERRIDES
4370 if (params->disable_vht) {
4371 wpa_printf(MSG_DEBUG, " * VHT disabled");
4372 if (nla_put_flag(msg, NL80211_ATTR_DISABLE_VHT))
4373 return -1;
4374 }
4375
4376 if (params->vhtcaps && params->vhtcaps_mask) {
4377 int sz = sizeof(struct ieee80211_vht_capabilities);
4378 wpa_hexdump(MSG_DEBUG, " * vhtcaps", params->vhtcaps, sz);
4379 wpa_hexdump(MSG_DEBUG, " * vhtcaps_mask",
4380 params->vhtcaps_mask, sz);
4381 if (nla_put(msg, NL80211_ATTR_VHT_CAPABILITY, sz,
4382 params->vhtcaps) ||
4383 nla_put(msg, NL80211_ATTR_VHT_CAPABILITY_MASK, sz,
4384 params->vhtcaps_mask))
4385 return -1;
4386 }
4387#endif /* CONFIG_VHT_OVERRIDES */
4388
4389 return 0;
4390}
4391
4392
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004393static int wpa_driver_nl80211_ibss(struct wpa_driver_nl80211_data *drv,
4394 struct wpa_driver_associate_params *params)
4395{
4396 struct nl_msg *msg;
4397 int ret = -1;
4398 int count = 0;
4399
4400 wpa_printf(MSG_DEBUG, "nl80211: Join IBSS (ifindex=%d)", drv->ifindex);
4401
Dmitry Shmidt9ead16e2014-10-07 13:15:23 -07004402 if (wpa_driver_nl80211_set_mode_ibss(drv->first_bss, &params->freq)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004403 wpa_printf(MSG_INFO, "nl80211: Failed to set interface into "
4404 "IBSS mode");
4405 return -1;
4406 }
4407
4408retry:
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004409 if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_JOIN_IBSS)) ||
4410 params->ssid == NULL || params->ssid_len > sizeof(drv->ssid))
4411 goto fail;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004412
4413 wpa_hexdump_ascii(MSG_DEBUG, " * SSID",
4414 params->ssid, params->ssid_len);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004415 if (nla_put(msg, NL80211_ATTR_SSID, params->ssid_len, params->ssid))
4416 goto fail;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004417 os_memcpy(drv->ssid, params->ssid, params->ssid_len);
4418 drv->ssid_len = params->ssid_len;
4419
Dmitry Shmidtff787d52015-01-12 13:01:47 -08004420 if (nl80211_put_freq_params(msg, &params->freq) < 0 ||
4421 nl80211_put_beacon_int(msg, params->beacon_int))
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004422 goto fail;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004423
4424 ret = nl80211_set_conn_keys(params, msg);
4425 if (ret)
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004426 goto fail;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004427
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08004428 if (params->bssid && params->fixed_bssid) {
4429 wpa_printf(MSG_DEBUG, " * BSSID=" MACSTR,
4430 MAC2STR(params->bssid));
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004431 if (nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, params->bssid))
4432 goto fail;
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08004433 }
4434
Dmitry Shmidt7f656022015-02-25 14:36:37 -08004435 if (params->fixed_freq) {
4436 wpa_printf(MSG_DEBUG, " * fixed_freq");
4437 if (nla_put_flag(msg, NL80211_ATTR_FREQ_FIXED))
4438 goto fail;
4439 }
4440
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004441 if (params->key_mgmt_suite == WPA_KEY_MGMT_IEEE8021X ||
4442 params->key_mgmt_suite == WPA_KEY_MGMT_PSK ||
4443 params->key_mgmt_suite == WPA_KEY_MGMT_IEEE8021X_SHA256 ||
4444 params->key_mgmt_suite == WPA_KEY_MGMT_PSK_SHA256) {
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08004445 wpa_printf(MSG_DEBUG, " * control port");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004446 if (nla_put_flag(msg, NL80211_ATTR_CONTROL_PORT))
4447 goto fail;
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08004448 }
4449
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004450 if (params->wpa_ie) {
4451 wpa_hexdump(MSG_DEBUG,
4452 " * Extra IEs for Beacon/Probe Response frames",
4453 params->wpa_ie, params->wpa_ie_len);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004454 if (nla_put(msg, NL80211_ATTR_IE, params->wpa_ie_len,
4455 params->wpa_ie))
4456 goto fail;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004457 }
4458
Dmitry Shmidt2f74e362015-01-21 13:19:05 -08004459 if (nl80211_ht_vht_overrides(msg, params) < 0)
4460 return -1;
4461
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004462 ret = send_and_recv_msgs(drv, msg, NULL, NULL);
4463 msg = NULL;
4464 if (ret) {
4465 wpa_printf(MSG_DEBUG, "nl80211: Join IBSS failed: ret=%d (%s)",
4466 ret, strerror(-ret));
4467 count++;
4468 if (ret == -EALREADY && count == 1) {
4469 wpa_printf(MSG_DEBUG, "nl80211: Retry IBSS join after "
4470 "forced leave");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004471 nl80211_leave_ibss(drv, 0);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004472 nlmsg_free(msg);
4473 goto retry;
4474 }
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004475 } else {
4476 wpa_printf(MSG_DEBUG,
4477 "nl80211: Join IBSS request sent successfully");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004478 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004479
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004480fail:
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004481 nlmsg_free(msg);
4482 return ret;
4483}
4484
4485
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004486static int nl80211_connect_common(struct wpa_driver_nl80211_data *drv,
4487 struct wpa_driver_associate_params *params,
4488 struct nl_msg *msg)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004489{
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004490 if (params->bssid) {
4491 wpa_printf(MSG_DEBUG, " * bssid=" MACSTR,
4492 MAC2STR(params->bssid));
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004493 if (nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, params->bssid))
4494 return -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004495 }
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004496
Dmitry Shmidt96be6222014-02-13 10:16:51 -08004497 if (params->bssid_hint) {
4498 wpa_printf(MSG_DEBUG, " * bssid_hint=" MACSTR,
4499 MAC2STR(params->bssid_hint));
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004500 if (nla_put(msg, NL80211_ATTR_MAC_HINT, ETH_ALEN,
4501 params->bssid_hint))
4502 return -1;
Dmitry Shmidt96be6222014-02-13 10:16:51 -08004503 }
4504
Dmitry Shmidt9ead16e2014-10-07 13:15:23 -07004505 if (params->freq.freq) {
4506 wpa_printf(MSG_DEBUG, " * freq=%d", params->freq.freq);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004507 if (nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ,
4508 params->freq.freq))
4509 return -1;
Dmitry Shmidt9ead16e2014-10-07 13:15:23 -07004510 drv->assoc_freq = params->freq.freq;
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -07004511 } else
4512 drv->assoc_freq = 0;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004513
Dmitry Shmidt96be6222014-02-13 10:16:51 -08004514 if (params->freq_hint) {
4515 wpa_printf(MSG_DEBUG, " * freq_hint=%d", params->freq_hint);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004516 if (nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ_HINT,
4517 params->freq_hint))
4518 return -1;
Dmitry Shmidt96be6222014-02-13 10:16:51 -08004519 }
4520
Dmitry Shmidt04949592012-07-19 12:16:46 -07004521 if (params->bg_scan_period >= 0) {
4522 wpa_printf(MSG_DEBUG, " * bg scan period=%d",
4523 params->bg_scan_period);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004524 if (nla_put_u16(msg, NL80211_ATTR_BG_SCAN_PERIOD,
4525 params->bg_scan_period))
4526 return -1;
Dmitry Shmidt04949592012-07-19 12:16:46 -07004527 }
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004528
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004529 if (params->ssid) {
4530 wpa_hexdump_ascii(MSG_DEBUG, " * SSID",
4531 params->ssid, params->ssid_len);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004532 if (nla_put(msg, NL80211_ATTR_SSID, params->ssid_len,
4533 params->ssid))
4534 return -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004535 if (params->ssid_len > sizeof(drv->ssid))
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004536 return -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004537 os_memcpy(drv->ssid, params->ssid, params->ssid_len);
4538 drv->ssid_len = params->ssid_len;
4539 }
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004540
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004541 wpa_hexdump(MSG_DEBUG, " * IEs", params->wpa_ie, params->wpa_ie_len);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004542 if (params->wpa_ie &&
4543 nla_put(msg, NL80211_ATTR_IE, params->wpa_ie_len, params->wpa_ie))
4544 return -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004545
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004546 if (params->wpa_proto) {
4547 enum nl80211_wpa_versions ver = 0;
4548
4549 if (params->wpa_proto & WPA_PROTO_WPA)
4550 ver |= NL80211_WPA_VERSION_1;
4551 if (params->wpa_proto & WPA_PROTO_RSN)
4552 ver |= NL80211_WPA_VERSION_2;
4553
4554 wpa_printf(MSG_DEBUG, " * WPA Versions 0x%x", ver);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004555 if (nla_put_u32(msg, NL80211_ATTR_WPA_VERSIONS, ver))
4556 return -1;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004557 }
4558
4559 if (params->pairwise_suite != WPA_CIPHER_NONE) {
4560 u32 cipher = wpa_cipher_to_cipher_suite(params->pairwise_suite);
4561 wpa_printf(MSG_DEBUG, " * pairwise=0x%x", cipher);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004562 if (nla_put_u32(msg, NL80211_ATTR_CIPHER_SUITES_PAIRWISE,
4563 cipher))
4564 return -1;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004565 }
4566
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08004567 if (params->group_suite == WPA_CIPHER_GTK_NOT_USED &&
4568 !(drv->capa.enc & WPA_DRIVER_CAPA_ENC_GTK_NOT_USED)) {
4569 /*
4570 * This is likely to work even though many drivers do not
4571 * advertise support for operations without GTK.
4572 */
4573 wpa_printf(MSG_DEBUG, " * skip group cipher configuration for GTK_NOT_USED due to missing driver support advertisement");
4574 } else if (params->group_suite != WPA_CIPHER_NONE) {
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004575 u32 cipher = wpa_cipher_to_cipher_suite(params->group_suite);
4576 wpa_printf(MSG_DEBUG, " * group=0x%x", cipher);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004577 if (nla_put_u32(msg, NL80211_ATTR_CIPHER_SUITE_GROUP, cipher))
4578 return -1;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004579 }
4580
4581 if (params->key_mgmt_suite == WPA_KEY_MGMT_IEEE8021X ||
4582 params->key_mgmt_suite == WPA_KEY_MGMT_PSK ||
4583 params->key_mgmt_suite == WPA_KEY_MGMT_FT_IEEE8021X ||
4584 params->key_mgmt_suite == WPA_KEY_MGMT_FT_PSK ||
Dmitry Shmidt15907092014-03-25 10:42:57 -07004585 params->key_mgmt_suite == WPA_KEY_MGMT_CCKM ||
Dmitry Shmidt3c57b3f2014-05-22 15:13:07 -07004586 params->key_mgmt_suite == WPA_KEY_MGMT_OSEN ||
4587 params->key_mgmt_suite == WPA_KEY_MGMT_IEEE8021X_SHA256 ||
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004588 params->key_mgmt_suite == WPA_KEY_MGMT_PSK_SHA256 ||
Dmitry Shmidt807291d2015-01-27 13:40:23 -08004589 params->key_mgmt_suite == WPA_KEY_MGMT_IEEE8021X_SUITE_B ||
4590 params->key_mgmt_suite == WPA_KEY_MGMT_IEEE8021X_SUITE_B_192) {
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004591 int mgmt = WLAN_AKM_SUITE_PSK;
4592
4593 switch (params->key_mgmt_suite) {
4594 case WPA_KEY_MGMT_CCKM:
4595 mgmt = WLAN_AKM_SUITE_CCKM;
4596 break;
4597 case WPA_KEY_MGMT_IEEE8021X:
4598 mgmt = WLAN_AKM_SUITE_8021X;
4599 break;
4600 case WPA_KEY_MGMT_FT_IEEE8021X:
4601 mgmt = WLAN_AKM_SUITE_FT_8021X;
4602 break;
4603 case WPA_KEY_MGMT_FT_PSK:
4604 mgmt = WLAN_AKM_SUITE_FT_PSK;
4605 break;
Dmitry Shmidt3c57b3f2014-05-22 15:13:07 -07004606 case WPA_KEY_MGMT_IEEE8021X_SHA256:
4607 mgmt = WLAN_AKM_SUITE_8021X_SHA256;
4608 break;
4609 case WPA_KEY_MGMT_PSK_SHA256:
4610 mgmt = WLAN_AKM_SUITE_PSK_SHA256;
4611 break;
Dmitry Shmidt15907092014-03-25 10:42:57 -07004612 case WPA_KEY_MGMT_OSEN:
4613 mgmt = WLAN_AKM_SUITE_OSEN;
4614 break;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004615 case WPA_KEY_MGMT_IEEE8021X_SUITE_B:
4616 mgmt = WLAN_AKM_SUITE_8021X_SUITE_B;
4617 break;
Dmitry Shmidt807291d2015-01-27 13:40:23 -08004618 case WPA_KEY_MGMT_IEEE8021X_SUITE_B_192:
4619 mgmt = WLAN_AKM_SUITE_8021X_SUITE_B_192;
4620 break;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004621 case WPA_KEY_MGMT_PSK:
4622 default:
4623 mgmt = WLAN_AKM_SUITE_PSK;
4624 break;
4625 }
Dmitry Shmidt15907092014-03-25 10:42:57 -07004626 wpa_printf(MSG_DEBUG, " * akm=0x%x", mgmt);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004627 if (nla_put_u32(msg, NL80211_ATTR_AKM_SUITES, mgmt))
4628 return -1;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004629 }
4630
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004631 if (nla_put_flag(msg, NL80211_ATTR_CONTROL_PORT))
4632 return -1;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004633
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004634 if (params->mgmt_frame_protection == MGMT_FRAME_PROTECTION_REQUIRED &&
4635 nla_put_u32(msg, NL80211_ATTR_USE_MFP, NL80211_MFP_REQUIRED))
4636 return -1;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004637
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004638 if (params->rrm_used) {
4639 u32 drv_rrm_flags = drv->capa.rrm_flags;
4640 if (!(drv_rrm_flags &
4641 WPA_DRIVER_FLAGS_DS_PARAM_SET_IE_IN_PROBES) ||
4642 !(drv_rrm_flags & WPA_DRIVER_FLAGS_QUIET) ||
4643 nla_put_flag(msg, NL80211_ATTR_USE_RRM))
4644 return -1;
4645 }
4646
Dmitry Shmidt2f74e362015-01-21 13:19:05 -08004647 if (nl80211_ht_vht_overrides(msg, params) < 0)
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004648 return -1;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004649
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004650 if (params->p2p)
4651 wpa_printf(MSG_DEBUG, " * P2P group");
4652
4653 return 0;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004654}
4655
4656
4657static int wpa_driver_nl80211_try_connect(
4658 struct wpa_driver_nl80211_data *drv,
4659 struct wpa_driver_associate_params *params)
4660{
4661 struct nl_msg *msg;
4662 enum nl80211_auth_type type;
4663 int ret;
4664 int algs;
4665
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004666 if (params->req_key_mgmt_offload && params->psk &&
4667 (params->key_mgmt_suite == WPA_KEY_MGMT_PSK ||
4668 params->key_mgmt_suite == WPA_KEY_MGMT_PSK_SHA256 ||
4669 params->key_mgmt_suite == WPA_KEY_MGMT_FT_PSK)) {
4670 wpa_printf(MSG_DEBUG, "nl80211: Key management set PSK");
4671 ret = issue_key_mgmt_set_key(drv, params->psk, 32);
4672 if (ret)
4673 return ret;
4674 }
4675
4676 wpa_printf(MSG_DEBUG, "nl80211: Connect (ifindex=%d)", drv->ifindex);
4677 msg = nl80211_drv_msg(drv, 0, NL80211_CMD_CONNECT);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004678 if (!msg)
4679 return -1;
4680
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004681 ret = nl80211_connect_common(drv, params, msg);
4682 if (ret)
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004683 goto fail;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004684
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004685 algs = 0;
4686 if (params->auth_alg & WPA_AUTH_ALG_OPEN)
4687 algs++;
4688 if (params->auth_alg & WPA_AUTH_ALG_SHARED)
4689 algs++;
4690 if (params->auth_alg & WPA_AUTH_ALG_LEAP)
4691 algs++;
4692 if (algs > 1) {
4693 wpa_printf(MSG_DEBUG, " * Leave out Auth Type for automatic "
4694 "selection");
4695 goto skip_auth_type;
4696 }
4697
4698 if (params->auth_alg & WPA_AUTH_ALG_OPEN)
4699 type = NL80211_AUTHTYPE_OPEN_SYSTEM;
4700 else if (params->auth_alg & WPA_AUTH_ALG_SHARED)
4701 type = NL80211_AUTHTYPE_SHARED_KEY;
4702 else if (params->auth_alg & WPA_AUTH_ALG_LEAP)
4703 type = NL80211_AUTHTYPE_NETWORK_EAP;
4704 else if (params->auth_alg & WPA_AUTH_ALG_FT)
4705 type = NL80211_AUTHTYPE_FT;
4706 else
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004707 goto fail;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004708
4709 wpa_printf(MSG_DEBUG, " * Auth Type %d", type);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004710 if (nla_put_u32(msg, NL80211_ATTR_AUTH_TYPE, type))
4711 goto fail;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004712
4713skip_auth_type:
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004714 ret = nl80211_set_conn_keys(params, msg);
4715 if (ret)
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004716 goto fail;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004717
4718 ret = send_and_recv_msgs(drv, msg, NULL, NULL);
4719 msg = NULL;
4720 if (ret) {
4721 wpa_printf(MSG_DEBUG, "nl80211: MLME connect failed: ret=%d "
4722 "(%s)", ret, strerror(-ret));
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004723 } else {
4724 wpa_printf(MSG_DEBUG,
4725 "nl80211: Connect request send successfully");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004726 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004727
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004728fail:
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004729 nlmsg_free(msg);
4730 return ret;
4731
4732}
4733
4734
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08004735static int wpa_driver_nl80211_connect(
4736 struct wpa_driver_nl80211_data *drv,
4737 struct wpa_driver_associate_params *params)
4738{
Jithu Jancea7c60b42014-12-03 18:54:40 +05304739 int ret;
4740
4741 /* Store the connection attempted bssid for future use */
4742 if (params->bssid)
4743 os_memcpy(drv->auth_attempt_bssid, params->bssid, ETH_ALEN);
4744 else
4745 os_memset(drv->auth_attempt_bssid, 0, ETH_ALEN);
4746
4747 ret = wpa_driver_nl80211_try_connect(drv, params);
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08004748 if (ret == -EALREADY) {
4749 /*
4750 * cfg80211 does not currently accept new connections if
4751 * we are already connected. As a workaround, force
4752 * disconnection and try again.
4753 */
4754 wpa_printf(MSG_DEBUG, "nl80211: Explicitly "
4755 "disconnecting before reassociation "
4756 "attempt");
4757 if (wpa_driver_nl80211_disconnect(
4758 drv, WLAN_REASON_PREV_AUTH_NOT_VALID))
4759 return -1;
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08004760 ret = wpa_driver_nl80211_try_connect(drv, params);
4761 }
4762 return ret;
4763}
4764
4765
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004766static int wpa_driver_nl80211_associate(
4767 void *priv, struct wpa_driver_associate_params *params)
4768{
4769 struct i802_bss *bss = priv;
4770 struct wpa_driver_nl80211_data *drv = bss->drv;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004771 int ret = -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004772 struct nl_msg *msg;
4773
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004774 nl80211_unmask_11b_rates(bss);
4775
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004776 if (params->mode == IEEE80211_MODE_AP)
4777 return wpa_driver_nl80211_ap(drv, params);
4778
4779 if (params->mode == IEEE80211_MODE_IBSS)
4780 return wpa_driver_nl80211_ibss(drv, params);
4781
4782 if (!(drv->capa.flags & WPA_DRIVER_FLAGS_SME)) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004783 enum nl80211_iftype nlmode = params->p2p ?
4784 NL80211_IFTYPE_P2P_CLIENT : NL80211_IFTYPE_STATION;
4785
4786 if (wpa_driver_nl80211_set_mode(priv, nlmode) < 0)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004787 return -1;
4788 return wpa_driver_nl80211_connect(drv, params);
4789 }
4790
Dmitry Shmidt8bae4132013-06-06 11:25:10 -07004791 nl80211_mark_disconnected(drv);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004792
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004793 wpa_printf(MSG_DEBUG, "nl80211: Associate (ifindex=%d)",
4794 drv->ifindex);
4795 msg = nl80211_drv_msg(drv, 0, NL80211_CMD_ASSOCIATE);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004796 if (!msg)
4797 return -1;
4798
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004799 ret = nl80211_connect_common(drv, params, msg);
4800 if (ret)
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004801 goto fail;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004802
4803 if (params->prev_bssid) {
4804 wpa_printf(MSG_DEBUG, " * prev_bssid=" MACSTR,
4805 MAC2STR(params->prev_bssid));
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004806 if (nla_put(msg, NL80211_ATTR_PREV_BSSID, ETH_ALEN,
4807 params->prev_bssid))
4808 goto fail;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004809 }
4810
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004811 ret = send_and_recv_msgs(drv, msg, NULL, NULL);
4812 msg = NULL;
4813 if (ret) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004814 wpa_dbg(drv->ctx, MSG_DEBUG,
4815 "nl80211: MLME command failed (assoc): ret=%d (%s)",
4816 ret, strerror(-ret));
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004817 nl80211_dump_scan(drv);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004818 } else {
4819 wpa_printf(MSG_DEBUG,
4820 "nl80211: Association request send successfully");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004821 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004822
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004823fail:
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004824 nlmsg_free(msg);
4825 return ret;
4826}
4827
4828
4829static int nl80211_set_mode(struct wpa_driver_nl80211_data *drv,
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004830 int ifindex, enum nl80211_iftype mode)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004831{
4832 struct nl_msg *msg;
4833 int ret = -ENOBUFS;
4834
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004835 wpa_printf(MSG_DEBUG, "nl80211: Set mode ifindex %d iftype %d (%s)",
4836 ifindex, mode, nl80211_iftype_str(mode));
4837
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004838 msg = nl80211_cmd_msg(drv->first_bss, 0, NL80211_CMD_SET_INTERFACE);
4839 if (!msg || nla_put_u32(msg, NL80211_ATTR_IFTYPE, mode))
4840 goto fail;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004841
4842 ret = send_and_recv_msgs(drv, msg, NULL, NULL);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004843 msg = NULL;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004844 if (!ret)
4845 return 0;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004846fail:
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004847 nlmsg_free(msg);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004848 wpa_printf(MSG_DEBUG, "nl80211: Failed to set interface %d to mode %d:"
4849 " %d (%s)", ifindex, mode, ret, strerror(-ret));
4850 return ret;
4851}
4852
4853
Dmitry Shmidtd30ac602014-06-30 09:54:22 -07004854static int wpa_driver_nl80211_set_mode_impl(
4855 struct i802_bss *bss,
4856 enum nl80211_iftype nlmode,
4857 struct hostapd_freq_params *desired_freq_params)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004858{
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004859 struct wpa_driver_nl80211_data *drv = bss->drv;
4860 int ret = -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004861 int i;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004862 int was_ap = is_ap_interface(drv->nlmode);
4863 int res;
Dmitry Shmidtd30ac602014-06-30 09:54:22 -07004864 int mode_switch_res;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004865
Dmitry Shmidtd30ac602014-06-30 09:54:22 -07004866 mode_switch_res = nl80211_set_mode(drv, drv->ifindex, nlmode);
4867 if (mode_switch_res && nlmode == nl80211_get_ifmode(bss))
4868 mode_switch_res = 0;
Dmitry Shmidt34af3062013-07-11 10:46:32 -07004869
Dmitry Shmidtd30ac602014-06-30 09:54:22 -07004870 if (mode_switch_res == 0) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004871 drv->nlmode = nlmode;
4872 ret = 0;
4873 goto done;
4874 }
4875
Dmitry Shmidtd30ac602014-06-30 09:54:22 -07004876 if (mode_switch_res == -ENODEV)
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004877 return -1;
4878
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004879 if (nlmode == drv->nlmode) {
4880 wpa_printf(MSG_DEBUG, "nl80211: Interface already in "
4881 "requested mode - ignore error");
4882 ret = 0;
4883 goto done; /* Already in the requested mode */
4884 }
4885
4886 /* mac80211 doesn't allow mode changes while the device is up, so
4887 * take the device down, try to set the mode again, and bring the
4888 * device back up.
4889 */
4890 wpa_printf(MSG_DEBUG, "nl80211: Try mode change after setting "
4891 "interface down");
4892 for (i = 0; i < 10; i++) {
Dmitry Shmidt34af3062013-07-11 10:46:32 -07004893 res = i802_set_iface_flags(bss, 0);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004894 if (res == -EACCES || res == -ENODEV)
4895 break;
Dmitry Shmidtd30ac602014-06-30 09:54:22 -07004896 if (res != 0) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004897 wpa_printf(MSG_DEBUG, "nl80211: Failed to set "
4898 "interface down");
Dmitry Shmidtd30ac602014-06-30 09:54:22 -07004899 os_sleep(0, 100000);
4900 continue;
4901 }
4902
4903 /*
4904 * Setting the mode will fail for some drivers if the phy is
4905 * on a frequency that the mode is disallowed in.
4906 */
4907 if (desired_freq_params) {
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004908 res = nl80211_set_channel(bss, desired_freq_params, 0);
Dmitry Shmidtd30ac602014-06-30 09:54:22 -07004909 if (res) {
4910 wpa_printf(MSG_DEBUG,
4911 "nl80211: Failed to set frequency on interface");
4912 }
4913 }
4914
4915 /* Try to set the mode again while the interface is down */
4916 mode_switch_res = nl80211_set_mode(drv, drv->ifindex, nlmode);
4917 if (mode_switch_res == -EBUSY) {
4918 wpa_printf(MSG_DEBUG,
4919 "nl80211: Delaying mode set while interface going down");
4920 os_sleep(0, 100000);
4921 continue;
4922 }
4923 ret = mode_switch_res;
4924 break;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004925 }
4926
4927 if (!ret) {
4928 wpa_printf(MSG_DEBUG, "nl80211: Mode change succeeded while "
4929 "interface is down");
4930 drv->nlmode = nlmode;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004931 drv->ignore_if_down_event = 1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004932 }
4933
Dmitry Shmidtd30ac602014-06-30 09:54:22 -07004934 /* Bring the interface back up */
4935 res = linux_set_iface_flags(drv->global->ioctl_sock, bss->ifname, 1);
4936 if (res != 0) {
4937 wpa_printf(MSG_DEBUG,
4938 "nl80211: Failed to set interface up after switching mode");
4939 ret = -1;
4940 }
4941
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004942done:
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004943 if (ret) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004944 wpa_printf(MSG_DEBUG, "nl80211: Interface mode change to %d "
4945 "from %d failed", nlmode, drv->nlmode);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004946 return ret;
4947 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004948
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004949 if (is_p2p_net_interface(nlmode)) {
4950 wpa_printf(MSG_DEBUG,
4951 "nl80211: Interface %s mode change to P2P - disable 11b rates",
4952 bss->ifname);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07004953 nl80211_disable_11b_rates(drv, drv->ifindex, 1);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004954 } else if (drv->disabled_11b_rates) {
4955 wpa_printf(MSG_DEBUG,
4956 "nl80211: Interface %s mode changed to non-P2P - re-enable 11b rates",
4957 bss->ifname);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07004958 nl80211_disable_11b_rates(drv, drv->ifindex, 0);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004959 }
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07004960
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004961 if (is_ap_interface(nlmode)) {
4962 nl80211_mgmt_unsubscribe(bss, "start AP");
4963 /* Setup additional AP mode functionality if needed */
4964 if (nl80211_setup_ap(bss))
4965 return -1;
4966 } else if (was_ap) {
4967 /* Remove additional AP mode functionality */
4968 nl80211_teardown_ap(bss);
4969 } else {
4970 nl80211_mgmt_unsubscribe(bss, "mode change");
4971 }
4972
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004973 if (is_mesh_interface(nlmode) &&
4974 nl80211_mgmt_subscribe_mesh(bss))
4975 return -1;
4976
Dmitry Shmidt04949592012-07-19 12:16:46 -07004977 if (!bss->in_deinit && !is_ap_interface(nlmode) &&
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004978 !is_mesh_interface(nlmode) &&
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004979 nl80211_mgmt_subscribe_non_ap(bss) < 0)
4980 wpa_printf(MSG_DEBUG, "nl80211: Failed to register Action "
4981 "frame processing - ignore for now");
4982
4983 return 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004984}
4985
4986
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004987int wpa_driver_nl80211_set_mode(struct i802_bss *bss,
4988 enum nl80211_iftype nlmode)
Dmitry Shmidtd30ac602014-06-30 09:54:22 -07004989{
4990 return wpa_driver_nl80211_set_mode_impl(bss, nlmode, NULL);
4991}
4992
4993
Dmitry Shmidt9ead16e2014-10-07 13:15:23 -07004994static int wpa_driver_nl80211_set_mode_ibss(struct i802_bss *bss,
4995 struct hostapd_freq_params *freq)
Dmitry Shmidtd30ac602014-06-30 09:54:22 -07004996{
Dmitry Shmidtd30ac602014-06-30 09:54:22 -07004997 return wpa_driver_nl80211_set_mode_impl(bss, NL80211_IFTYPE_ADHOC,
Dmitry Shmidt9ead16e2014-10-07 13:15:23 -07004998 freq);
Dmitry Shmidtd30ac602014-06-30 09:54:22 -07004999}
5000
5001
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005002static int wpa_driver_nl80211_get_capa(void *priv,
5003 struct wpa_driver_capa *capa)
5004{
5005 struct i802_bss *bss = priv;
5006 struct wpa_driver_nl80211_data *drv = bss->drv;
Dmitry Shmidtd11f0192014-03-24 12:09:47 -07005007
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005008 if (!drv->has_capability)
5009 return -1;
5010 os_memcpy(capa, &drv->capa, sizeof(*capa));
Dmitry Shmidt444d5672013-04-01 13:08:44 -07005011 if (drv->extended_capa && drv->extended_capa_mask) {
5012 capa->extended_capa = drv->extended_capa;
5013 capa->extended_capa_mask = drv->extended_capa_mask;
5014 capa->extended_capa_len = drv->extended_capa_len;
5015 }
Dmitry Shmidt34af3062013-07-11 10:46:32 -07005016
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005017 return 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005018}
5019
5020
5021static int wpa_driver_nl80211_set_operstate(void *priv, int state)
5022{
5023 struct i802_bss *bss = priv;
5024 struct wpa_driver_nl80211_data *drv = bss->drv;
5025
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08005026 wpa_printf(MSG_DEBUG, "nl80211: Set %s operstate %d->%d (%s)",
5027 bss->ifname, drv->operstate, state,
5028 state ? "UP" : "DORMANT");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005029 drv->operstate = state;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005030 return netlink_send_oper_ifla(drv->global->netlink, drv->ifindex, -1,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005031 state ? IF_OPER_UP : IF_OPER_DORMANT);
5032}
5033
5034
5035static int wpa_driver_nl80211_set_supp_port(void *priv, int authorized)
5036{
5037 struct i802_bss *bss = priv;
5038 struct wpa_driver_nl80211_data *drv = bss->drv;
5039 struct nl_msg *msg;
5040 struct nl80211_sta_flag_update upd;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005041 int ret;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08005042
5043 if (!drv->associated && is_zero_ether_addr(drv->bssid) && !authorized) {
5044 wpa_printf(MSG_DEBUG, "nl80211: Skip set_supp_port(unauthorized) while not associated");
5045 return 0;
5046 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005047
Dmitry Shmidt8bae4132013-06-06 11:25:10 -07005048 wpa_printf(MSG_DEBUG, "nl80211: Set supplicant port %sauthorized for "
5049 MACSTR, authorized ? "" : "un", MAC2STR(drv->bssid));
5050
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005051 os_memset(&upd, 0, sizeof(upd));
5052 upd.mask = BIT(NL80211_STA_FLAG_AUTHORIZED);
5053 if (authorized)
5054 upd.set = BIT(NL80211_STA_FLAG_AUTHORIZED);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005055
5056 if (!(msg = nl80211_bss_msg(bss, 0, NL80211_CMD_SET_STATION)) ||
5057 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, drv->bssid) ||
5058 nla_put(msg, NL80211_ATTR_STA_FLAGS2, sizeof(upd), &upd)) {
5059 nlmsg_free(msg);
5060 return -ENOBUFS;
5061 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005062
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08005063 ret = send_and_recv_msgs(drv, msg, NULL, NULL);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08005064 if (!ret)
5065 return 0;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08005066 wpa_printf(MSG_DEBUG, "nl80211: Failed to set STA flag: %d (%s)",
5067 ret, strerror(-ret));
5068 return ret;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005069}
5070
5071
Jouni Malinen75ecf522011-06-27 15:19:46 -07005072/* Set kernel driver on given frequency (MHz) */
5073static int i802_set_freq(void *priv, struct hostapd_freq_params *freq)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005074{
Jouni Malinen75ecf522011-06-27 15:19:46 -07005075 struct i802_bss *bss = priv;
Dmitry Shmidt7832adb2014-04-29 10:53:02 -07005076 return nl80211_set_channel(bss, freq, 0);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005077}
5078
5079
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005080static inline int min_int(int a, int b)
5081{
5082 if (a < b)
5083 return a;
5084 return b;
5085}
5086
5087
5088static int get_key_handler(struct nl_msg *msg, void *arg)
5089{
5090 struct nlattr *tb[NL80211_ATTR_MAX + 1];
5091 struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg));
5092
5093 nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0),
5094 genlmsg_attrlen(gnlh, 0), NULL);
5095
5096 /*
5097 * TODO: validate the key index and mac address!
5098 * Otherwise, there's a race condition as soon as
5099 * the kernel starts sending key notifications.
5100 */
5101
5102 if (tb[NL80211_ATTR_KEY_SEQ])
5103 memcpy(arg, nla_data(tb[NL80211_ATTR_KEY_SEQ]),
5104 min_int(nla_len(tb[NL80211_ATTR_KEY_SEQ]), 6));
5105 return NL_SKIP;
5106}
5107
5108
5109static int i802_get_seqnum(const char *iface, void *priv, const u8 *addr,
5110 int idx, u8 *seq)
5111{
5112 struct i802_bss *bss = priv;
5113 struct wpa_driver_nl80211_data *drv = bss->drv;
5114 struct nl_msg *msg;
5115
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005116 msg = nl80211_ifindex_msg(drv, if_nametoindex(iface), 0,
5117 NL80211_CMD_GET_KEY);
5118 if (!msg ||
5119 (addr && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) ||
5120 nla_put_u8(msg, NL80211_ATTR_KEY_IDX, idx)) {
5121 nlmsg_free(msg);
5122 return -ENOBUFS;
5123 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005124
5125 memset(seq, 0, 6);
5126
5127 return send_and_recv_msgs(drv, msg, get_key_handler, seq);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005128}
5129
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005130
5131static int i802_set_rts(void *priv, int rts)
5132{
5133 struct i802_bss *bss = priv;
5134 struct wpa_driver_nl80211_data *drv = bss->drv;
5135 struct nl_msg *msg;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005136 int ret;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005137 u32 val;
5138
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005139 if (rts >= 2347)
5140 val = (u32) -1;
5141 else
5142 val = rts;
5143
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005144 if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_SET_WIPHY)) ||
5145 nla_put_u32(msg, NL80211_ATTR_WIPHY_RTS_THRESHOLD, val)) {
5146 nlmsg_free(msg);
5147 return -ENOBUFS;
5148 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005149
5150 ret = send_and_recv_msgs(drv, msg, NULL, NULL);
5151 if (!ret)
5152 return 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005153 wpa_printf(MSG_DEBUG, "nl80211: Failed to set RTS threshold %d: "
5154 "%d (%s)", rts, ret, strerror(-ret));
5155 return ret;
5156}
5157
5158
5159static int i802_set_frag(void *priv, int frag)
5160{
5161 struct i802_bss *bss = priv;
5162 struct wpa_driver_nl80211_data *drv = bss->drv;
5163 struct nl_msg *msg;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005164 int ret;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005165 u32 val;
5166
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005167 if (frag >= 2346)
5168 val = (u32) -1;
5169 else
5170 val = frag;
5171
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005172 if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_SET_WIPHY)) ||
5173 nla_put_u32(msg, NL80211_ATTR_WIPHY_FRAG_THRESHOLD, val)) {
5174 nlmsg_free(msg);
5175 return -ENOBUFS;
5176 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005177
5178 ret = send_and_recv_msgs(drv, msg, NULL, NULL);
5179 if (!ret)
5180 return 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005181 wpa_printf(MSG_DEBUG, "nl80211: Failed to set fragmentation threshold "
5182 "%d: %d (%s)", frag, ret, strerror(-ret));
5183 return ret;
5184}
5185
5186
5187static int i802_flush(void *priv)
5188{
5189 struct i802_bss *bss = priv;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005190 struct nl_msg *msg;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005191 int res;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005192
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -07005193 wpa_printf(MSG_DEBUG, "nl80211: flush -> DEL_STATION %s (all)",
5194 bss->ifname);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005195
5196 /*
5197 * XXX: FIX! this needs to flush all VLANs too
5198 */
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005199 msg = nl80211_bss_msg(bss, 0, NL80211_CMD_DEL_STATION);
5200 res = send_and_recv_msgs(bss->drv, msg, NULL, NULL);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005201 if (res) {
5202 wpa_printf(MSG_DEBUG, "nl80211: Station flush failed: ret=%d "
5203 "(%s)", res, strerror(-res));
5204 }
5205 return res;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005206}
5207
5208
5209static int get_sta_handler(struct nl_msg *msg, void *arg)
5210{
5211 struct nlattr *tb[NL80211_ATTR_MAX + 1];
5212 struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg));
5213 struct hostap_sta_driver_data *data = arg;
5214 struct nlattr *stats[NL80211_STA_INFO_MAX + 1];
5215 static struct nla_policy stats_policy[NL80211_STA_INFO_MAX + 1] = {
5216 [NL80211_STA_INFO_INACTIVE_TIME] = { .type = NLA_U32 },
5217 [NL80211_STA_INFO_RX_BYTES] = { .type = NLA_U32 },
5218 [NL80211_STA_INFO_TX_BYTES] = { .type = NLA_U32 },
5219 [NL80211_STA_INFO_RX_PACKETS] = { .type = NLA_U32 },
5220 [NL80211_STA_INFO_TX_PACKETS] = { .type = NLA_U32 },
Jouni Malinen1e6c57f2012-09-05 17:07:03 +03005221 [NL80211_STA_INFO_TX_FAILED] = { .type = NLA_U32 },
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005222 };
5223
5224 nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0),
5225 genlmsg_attrlen(gnlh, 0), NULL);
5226
5227 /*
5228 * TODO: validate the interface and mac address!
5229 * Otherwise, there's a race condition as soon as
5230 * the kernel starts sending station notifications.
5231 */
5232
5233 if (!tb[NL80211_ATTR_STA_INFO]) {
5234 wpa_printf(MSG_DEBUG, "sta stats missing!");
5235 return NL_SKIP;
5236 }
5237 if (nla_parse_nested(stats, NL80211_STA_INFO_MAX,
5238 tb[NL80211_ATTR_STA_INFO],
5239 stats_policy)) {
5240 wpa_printf(MSG_DEBUG, "failed to parse nested attributes!");
5241 return NL_SKIP;
5242 }
5243
5244 if (stats[NL80211_STA_INFO_INACTIVE_TIME])
5245 data->inactive_msec =
5246 nla_get_u32(stats[NL80211_STA_INFO_INACTIVE_TIME]);
5247 if (stats[NL80211_STA_INFO_RX_BYTES])
5248 data->rx_bytes = nla_get_u32(stats[NL80211_STA_INFO_RX_BYTES]);
5249 if (stats[NL80211_STA_INFO_TX_BYTES])
5250 data->tx_bytes = nla_get_u32(stats[NL80211_STA_INFO_TX_BYTES]);
5251 if (stats[NL80211_STA_INFO_RX_PACKETS])
5252 data->rx_packets =
5253 nla_get_u32(stats[NL80211_STA_INFO_RX_PACKETS]);
5254 if (stats[NL80211_STA_INFO_TX_PACKETS])
5255 data->tx_packets =
5256 nla_get_u32(stats[NL80211_STA_INFO_TX_PACKETS]);
Jouni Malinen1e6c57f2012-09-05 17:07:03 +03005257 if (stats[NL80211_STA_INFO_TX_FAILED])
5258 data->tx_retry_failed =
5259 nla_get_u32(stats[NL80211_STA_INFO_TX_FAILED]);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005260
5261 return NL_SKIP;
5262}
5263
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08005264static int i802_read_sta_data(struct i802_bss *bss,
5265 struct hostap_sta_driver_data *data,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005266 const u8 *addr)
5267{
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005268 struct nl_msg *msg;
5269
5270 os_memset(data, 0, sizeof(*data));
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005271
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005272 if (!(msg = nl80211_bss_msg(bss, 0, NL80211_CMD_GET_STATION)) ||
5273 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) {
5274 nlmsg_free(msg);
5275 return -ENOBUFS;
5276 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005277
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005278 return send_and_recv_msgs(bss->drv, msg, get_sta_handler, data);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005279}
5280
5281
5282static int i802_set_tx_queue_params(void *priv, int queue, int aifs,
5283 int cw_min, int cw_max, int burst_time)
5284{
5285 struct i802_bss *bss = priv;
5286 struct wpa_driver_nl80211_data *drv = bss->drv;
5287 struct nl_msg *msg;
5288 struct nlattr *txq, *params;
5289
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005290 msg = nl80211_bss_msg(bss, 0, NL80211_CMD_SET_WIPHY);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005291 if (!msg)
5292 return -1;
5293
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005294 txq = nla_nest_start(msg, NL80211_ATTR_WIPHY_TXQ_PARAMS);
5295 if (!txq)
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005296 goto fail;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005297
5298 /* We are only sending parameters for a single TXQ at a time */
5299 params = nla_nest_start(msg, 1);
5300 if (!params)
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005301 goto fail;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005302
5303 switch (queue) {
5304 case 0:
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005305 if (nla_put_u8(msg, NL80211_TXQ_ATTR_QUEUE, NL80211_TXQ_Q_VO))
5306 goto fail;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005307 break;
5308 case 1:
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005309 if (nla_put_u8(msg, NL80211_TXQ_ATTR_QUEUE, NL80211_TXQ_Q_VI))
5310 goto fail;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005311 break;
5312 case 2:
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005313 if (nla_put_u8(msg, NL80211_TXQ_ATTR_QUEUE, NL80211_TXQ_Q_BE))
5314 goto fail;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005315 break;
5316 case 3:
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005317 if (nla_put_u8(msg, NL80211_TXQ_ATTR_QUEUE, NL80211_TXQ_Q_BK))
5318 goto fail;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005319 break;
5320 }
5321 /* Burst time is configured in units of 0.1 msec and TXOP parameter in
5322 * 32 usec, so need to convert the value here. */
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005323 if (nla_put_u16(msg, NL80211_TXQ_ATTR_TXOP,
5324 (burst_time * 100 + 16) / 32) ||
5325 nla_put_u16(msg, NL80211_TXQ_ATTR_CWMIN, cw_min) ||
5326 nla_put_u16(msg, NL80211_TXQ_ATTR_CWMAX, cw_max) ||
5327 nla_put_u8(msg, NL80211_TXQ_ATTR_AIFS, aifs))
5328 goto fail;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005329
5330 nla_nest_end(msg, params);
5331
5332 nla_nest_end(msg, txq);
5333
5334 if (send_and_recv_msgs(drv, msg, NULL, NULL) == 0)
5335 return 0;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005336 msg = NULL;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005337fail:
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005338 nlmsg_free(msg);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005339 return -1;
5340}
5341
5342
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08005343static int i802_set_sta_vlan(struct i802_bss *bss, const u8 *addr,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005344 const char *ifname, int vlan_id)
5345{
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005346 struct wpa_driver_nl80211_data *drv = bss->drv;
5347 struct nl_msg *msg;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005348 int ret;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005349
Dmitry Shmidtcce06662013-11-04 18:44:24 -08005350 wpa_printf(MSG_DEBUG, "nl80211: %s[%d]: set_sta_vlan(" MACSTR
5351 ", ifname=%s[%d], vlan_id=%d)",
5352 bss->ifname, if_nametoindex(bss->ifname),
5353 MAC2STR(addr), ifname, if_nametoindex(ifname), vlan_id);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005354 if (!(msg = nl80211_bss_msg(bss, 0, NL80211_CMD_SET_STATION)) ||
5355 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) ||
5356 nla_put_u32(msg, NL80211_ATTR_STA_VLAN, if_nametoindex(ifname))) {
5357 nlmsg_free(msg);
5358 return -ENOBUFS;
5359 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005360
5361 ret = send_and_recv_msgs(drv, msg, NULL, NULL);
5362 if (ret < 0) {
5363 wpa_printf(MSG_ERROR, "nl80211: NL80211_ATTR_STA_VLAN (addr="
5364 MACSTR " ifname=%s vlan_id=%d) failed: %d (%s)",
5365 MAC2STR(addr), ifname, vlan_id, ret,
5366 strerror(-ret));
5367 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005368 return ret;
5369}
5370
5371
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005372static int i802_get_inact_sec(void *priv, const u8 *addr)
5373{
5374 struct hostap_sta_driver_data data;
5375 int ret;
5376
5377 data.inactive_msec = (unsigned long) -1;
5378 ret = i802_read_sta_data(priv, &data, addr);
Dmitry Shmidt2f74e362015-01-21 13:19:05 -08005379 if (ret == -ENOENT)
5380 return -ENOENT;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005381 if (ret || data.inactive_msec == (unsigned long) -1)
5382 return -1;
5383 return data.inactive_msec / 1000;
5384}
5385
5386
5387static int i802_sta_clear_stats(void *priv, const u8 *addr)
5388{
5389#if 0
5390 /* TODO */
5391#endif
5392 return 0;
5393}
5394
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005395
5396static int i802_sta_deauth(void *priv, const u8 *own_addr, const u8 *addr,
5397 int reason)
5398{
5399 struct i802_bss *bss = priv;
Dmitry Shmidt04949592012-07-19 12:16:46 -07005400 struct wpa_driver_nl80211_data *drv = bss->drv;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005401 struct ieee80211_mgmt mgmt;
5402
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005403 if (is_mesh_interface(drv->nlmode))
5404 return -1;
5405
Dmitry Shmidt04949592012-07-19 12:16:46 -07005406 if (drv->device_ap_sme)
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005407 return wpa_driver_nl80211_sta_remove(bss, addr, 1, reason);
Dmitry Shmidt04949592012-07-19 12:16:46 -07005408
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005409 memset(&mgmt, 0, sizeof(mgmt));
5410 mgmt.frame_control = IEEE80211_FC(WLAN_FC_TYPE_MGMT,
5411 WLAN_FC_STYPE_DEAUTH);
5412 memcpy(mgmt.da, addr, ETH_ALEN);
5413 memcpy(mgmt.sa, own_addr, ETH_ALEN);
5414 memcpy(mgmt.bssid, own_addr, ETH_ALEN);
5415 mgmt.u.deauth.reason_code = host_to_le16(reason);
5416 return wpa_driver_nl80211_send_mlme(bss, (u8 *) &mgmt,
5417 IEEE80211_HDRLEN +
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08005418 sizeof(mgmt.u.deauth), 0, 0, 0, 0,
5419 0);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005420}
5421
5422
5423static int i802_sta_disassoc(void *priv, const u8 *own_addr, const u8 *addr,
5424 int reason)
5425{
5426 struct i802_bss *bss = priv;
Dmitry Shmidt04949592012-07-19 12:16:46 -07005427 struct wpa_driver_nl80211_data *drv = bss->drv;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005428 struct ieee80211_mgmt mgmt;
5429
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005430 if (is_mesh_interface(drv->nlmode))
5431 return -1;
5432
Dmitry Shmidt04949592012-07-19 12:16:46 -07005433 if (drv->device_ap_sme)
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005434 return wpa_driver_nl80211_sta_remove(bss, addr, 0, reason);
Dmitry Shmidt04949592012-07-19 12:16:46 -07005435
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005436 memset(&mgmt, 0, sizeof(mgmt));
5437 mgmt.frame_control = IEEE80211_FC(WLAN_FC_TYPE_MGMT,
5438 WLAN_FC_STYPE_DISASSOC);
5439 memcpy(mgmt.da, addr, ETH_ALEN);
5440 memcpy(mgmt.sa, own_addr, ETH_ALEN);
5441 memcpy(mgmt.bssid, own_addr, ETH_ALEN);
5442 mgmt.u.disassoc.reason_code = host_to_le16(reason);
5443 return wpa_driver_nl80211_send_mlme(bss, (u8 *) &mgmt,
5444 IEEE80211_HDRLEN +
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08005445 sizeof(mgmt.u.disassoc), 0, 0, 0, 0,
5446 0);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005447}
5448
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005449
Dmitry Shmidtdf5a7e42014-04-02 12:59:59 -07005450static void dump_ifidx(struct wpa_driver_nl80211_data *drv)
5451{
5452 char buf[200], *pos, *end;
5453 int i, res;
5454
5455 pos = buf;
5456 end = pos + sizeof(buf);
5457
5458 for (i = 0; i < drv->num_if_indices; i++) {
5459 if (!drv->if_indices[i])
5460 continue;
5461 res = os_snprintf(pos, end - pos, " %d", drv->if_indices[i]);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005462 if (os_snprintf_error(end - pos, res))
Dmitry Shmidtdf5a7e42014-04-02 12:59:59 -07005463 break;
5464 pos += res;
5465 }
5466 *pos = '\0';
5467
5468 wpa_printf(MSG_DEBUG, "nl80211: if_indices[%d]:%s",
5469 drv->num_if_indices, buf);
5470}
5471
5472
Jouni Malinen75ecf522011-06-27 15:19:46 -07005473static void add_ifidx(struct wpa_driver_nl80211_data *drv, int ifidx)
5474{
5475 int i;
5476 int *old;
5477
5478 wpa_printf(MSG_DEBUG, "nl80211: Add own interface ifindex %d",
5479 ifidx);
Dmitry Shmidtdf5a7e42014-04-02 12:59:59 -07005480 if (have_ifidx(drv, ifidx)) {
5481 wpa_printf(MSG_DEBUG, "nl80211: ifindex %d already in the list",
5482 ifidx);
5483 return;
5484 }
Jouni Malinen75ecf522011-06-27 15:19:46 -07005485 for (i = 0; i < drv->num_if_indices; i++) {
5486 if (drv->if_indices[i] == 0) {
5487 drv->if_indices[i] = ifidx;
Dmitry Shmidtdf5a7e42014-04-02 12:59:59 -07005488 dump_ifidx(drv);
Jouni Malinen75ecf522011-06-27 15:19:46 -07005489 return;
5490 }
5491 }
5492
5493 if (drv->if_indices != drv->default_if_indices)
5494 old = drv->if_indices;
5495 else
5496 old = NULL;
5497
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07005498 drv->if_indices = os_realloc_array(old, drv->num_if_indices + 1,
5499 sizeof(int));
Jouni Malinen75ecf522011-06-27 15:19:46 -07005500 if (!drv->if_indices) {
5501 if (!old)
5502 drv->if_indices = drv->default_if_indices;
5503 else
5504 drv->if_indices = old;
5505 wpa_printf(MSG_ERROR, "Failed to reallocate memory for "
5506 "interfaces");
5507 wpa_printf(MSG_ERROR, "Ignoring EAPOL on interface %d", ifidx);
5508 return;
5509 } else if (!old)
5510 os_memcpy(drv->if_indices, drv->default_if_indices,
5511 sizeof(drv->default_if_indices));
5512 drv->if_indices[drv->num_if_indices] = ifidx;
5513 drv->num_if_indices++;
Dmitry Shmidtdf5a7e42014-04-02 12:59:59 -07005514 dump_ifidx(drv);
Jouni Malinen75ecf522011-06-27 15:19:46 -07005515}
5516
5517
5518static void del_ifidx(struct wpa_driver_nl80211_data *drv, int ifidx)
5519{
5520 int i;
5521
5522 for (i = 0; i < drv->num_if_indices; i++) {
5523 if (drv->if_indices[i] == ifidx) {
5524 drv->if_indices[i] = 0;
5525 break;
5526 }
5527 }
Dmitry Shmidtdf5a7e42014-04-02 12:59:59 -07005528 dump_ifidx(drv);
Jouni Malinen75ecf522011-06-27 15:19:46 -07005529}
5530
5531
5532static int have_ifidx(struct wpa_driver_nl80211_data *drv, int ifidx)
5533{
5534 int i;
5535
5536 for (i = 0; i < drv->num_if_indices; i++)
5537 if (drv->if_indices[i] == ifidx)
5538 return 1;
5539
5540 return 0;
5541}
5542
5543
5544static int i802_set_wds_sta(void *priv, const u8 *addr, int aid, int val,
Dmitry Shmidt7832adb2014-04-29 10:53:02 -07005545 const char *bridge_ifname, char *ifname_wds)
Jouni Malinen75ecf522011-06-27 15:19:46 -07005546{
5547 struct i802_bss *bss = priv;
5548 struct wpa_driver_nl80211_data *drv = bss->drv;
5549 char name[IFNAMSIZ + 1];
5550
5551 os_snprintf(name, sizeof(name), "%s.sta%d", bss->ifname, aid);
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07005552 if (ifname_wds)
5553 os_strlcpy(ifname_wds, name, IFNAMSIZ + 1);
5554
Jouni Malinen75ecf522011-06-27 15:19:46 -07005555 wpa_printf(MSG_DEBUG, "nl80211: Set WDS STA addr=" MACSTR
5556 " aid=%d val=%d name=%s", MAC2STR(addr), aid, val, name);
5557 if (val) {
5558 if (!if_nametoindex(name)) {
5559 if (nl80211_create_iface(drv, name,
5560 NL80211_IFTYPE_AP_VLAN,
Dmitry Shmidtcce06662013-11-04 18:44:24 -08005561 bss->addr, 1, NULL, NULL, 0) <
5562 0)
Jouni Malinen75ecf522011-06-27 15:19:46 -07005563 return -1;
5564 if (bridge_ifname &&
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005565 linux_br_add_if(drv->global->ioctl_sock,
5566 bridge_ifname, name) < 0)
Jouni Malinen75ecf522011-06-27 15:19:46 -07005567 return -1;
5568 }
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07005569 if (linux_set_iface_flags(drv->global->ioctl_sock, name, 1)) {
5570 wpa_printf(MSG_ERROR, "nl80211: Failed to set WDS STA "
5571 "interface %s up", name);
5572 }
Jouni Malinen75ecf522011-06-27 15:19:46 -07005573 return i802_set_sta_vlan(priv, addr, name, 0);
5574 } else {
Dmitry Shmidtaa532512012-09-24 10:35:31 -07005575 if (bridge_ifname)
5576 linux_br_del_if(drv->global->ioctl_sock, bridge_ifname,
5577 name);
5578
Jouni Malinen75ecf522011-06-27 15:19:46 -07005579 i802_set_sta_vlan(priv, addr, bss->ifname, 0);
Dmitry Shmidta38abf92014-03-06 13:38:44 -08005580 nl80211_remove_iface(drv, if_nametoindex(name));
5581 return 0;
Jouni Malinen75ecf522011-06-27 15:19:46 -07005582 }
5583}
5584
5585
5586static void handle_eapol(int sock, void *eloop_ctx, void *sock_ctx)
5587{
5588 struct wpa_driver_nl80211_data *drv = eloop_ctx;
5589 struct sockaddr_ll lladdr;
5590 unsigned char buf[3000];
5591 int len;
5592 socklen_t fromlen = sizeof(lladdr);
5593
5594 len = recvfrom(sock, buf, sizeof(buf), 0,
5595 (struct sockaddr *)&lladdr, &fromlen);
5596 if (len < 0) {
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -07005597 wpa_printf(MSG_ERROR, "nl80211: EAPOL recv failed: %s",
5598 strerror(errno));
Jouni Malinen75ecf522011-06-27 15:19:46 -07005599 return;
5600 }
5601
5602 if (have_ifidx(drv, lladdr.sll_ifindex))
5603 drv_event_eapol_rx(drv->ctx, lladdr.sll_addr, buf, len);
5604}
5605
5606
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005607static int i802_check_bridge(struct wpa_driver_nl80211_data *drv,
5608 struct i802_bss *bss,
5609 const char *brname, const char *ifname)
5610{
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005611 int br_ifindex;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005612 char in_br[IFNAMSIZ];
5613
5614 os_strlcpy(bss->brname, brname, IFNAMSIZ);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005615 br_ifindex = if_nametoindex(brname);
5616 if (br_ifindex == 0) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005617 /*
5618 * Bridge was configured, but the bridge device does
5619 * not exist. Try to add it now.
5620 */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005621 if (linux_br_add(drv->global->ioctl_sock, brname) < 0) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005622 wpa_printf(MSG_ERROR, "nl80211: Failed to add the "
5623 "bridge interface %s: %s",
5624 brname, strerror(errno));
5625 return -1;
5626 }
5627 bss->added_bridge = 1;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005628 br_ifindex = if_nametoindex(brname);
5629 add_ifidx(drv, br_ifindex);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005630 }
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005631 bss->br_ifindex = br_ifindex;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005632
5633 if (linux_br_get(in_br, ifname) == 0) {
5634 if (os_strcmp(in_br, brname) == 0)
5635 return 0; /* already in the bridge */
5636
5637 wpa_printf(MSG_DEBUG, "nl80211: Removing interface %s from "
5638 "bridge %s", ifname, in_br);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005639 if (linux_br_del_if(drv->global->ioctl_sock, in_br, ifname) <
5640 0) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005641 wpa_printf(MSG_ERROR, "nl80211: Failed to "
5642 "remove interface %s from bridge "
5643 "%s: %s",
5644 ifname, brname, strerror(errno));
5645 return -1;
5646 }
5647 }
5648
5649 wpa_printf(MSG_DEBUG, "nl80211: Adding interface %s into bridge %s",
5650 ifname, brname);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005651 if (linux_br_add_if(drv->global->ioctl_sock, brname, ifname) < 0) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005652 wpa_printf(MSG_ERROR, "nl80211: Failed to add interface %s "
5653 "into bridge %s: %s",
5654 ifname, brname, strerror(errno));
5655 return -1;
5656 }
5657 bss->added_if_into_bridge = 1;
5658
5659 return 0;
5660}
5661
5662
5663static void *i802_init(struct hostapd_data *hapd,
5664 struct wpa_init_params *params)
5665{
5666 struct wpa_driver_nl80211_data *drv;
5667 struct i802_bss *bss;
5668 size_t i;
5669 char brname[IFNAMSIZ];
5670 int ifindex, br_ifindex;
5671 int br_added = 0;
5672
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08005673 bss = wpa_driver_nl80211_drv_init(hapd, params->ifname,
5674 params->global_priv, 1,
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005675 params->bssid, params->driver_params);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005676 if (bss == NULL)
5677 return NULL;
5678
5679 drv = bss->drv;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005680
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005681 if (linux_br_get(brname, params->ifname) == 0) {
5682 wpa_printf(MSG_DEBUG, "nl80211: Interface %s is in bridge %s",
5683 params->ifname, brname);
5684 br_ifindex = if_nametoindex(brname);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005685 os_strlcpy(bss->brname, brname, IFNAMSIZ);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005686 } else {
5687 brname[0] = '\0';
5688 br_ifindex = 0;
5689 }
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005690 bss->br_ifindex = br_ifindex;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005691
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005692 for (i = 0; i < params->num_bridge; i++) {
5693 if (params->bridge[i]) {
5694 ifindex = if_nametoindex(params->bridge[i]);
5695 if (ifindex)
5696 add_ifidx(drv, ifindex);
5697 if (ifindex == br_ifindex)
5698 br_added = 1;
5699 }
5700 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005701
5702 /* start listening for EAPOL on the default AP interface */
5703 add_ifidx(drv, drv->ifindex);
5704
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005705 if (params->num_bridge && params->bridge[0]) {
5706 if (i802_check_bridge(drv, bss, params->bridge[0],
5707 params->ifname) < 0)
5708 goto failed;
5709 if (os_strcmp(params->bridge[0], brname) != 0)
5710 br_added = 1;
5711 }
5712
5713 if (!br_added && br_ifindex &&
5714 (params->num_bridge == 0 || !params->bridge[0]))
5715 add_ifidx(drv, br_ifindex);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005716
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07005717#ifdef CONFIG_LIBNL3_ROUTE
5718 if (bss->added_if_into_bridge) {
5719 drv->rtnl_sk = nl_socket_alloc();
5720 if (drv->rtnl_sk == NULL) {
5721 wpa_printf(MSG_ERROR, "nl80211: Failed to allocate nl_sock");
5722 goto failed;
5723 }
5724
5725 if (nl_connect(drv->rtnl_sk, NETLINK_ROUTE)) {
5726 wpa_printf(MSG_ERROR, "nl80211: Failed to connect nl_sock to NETLINK_ROUTE: %s",
5727 strerror(errno));
5728 goto failed;
5729 }
5730 }
5731#endif /* CONFIG_LIBNL3_ROUTE */
5732
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005733 drv->eapol_sock = socket(PF_PACKET, SOCK_DGRAM, htons(ETH_P_PAE));
5734 if (drv->eapol_sock < 0) {
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -07005735 wpa_printf(MSG_ERROR, "nl80211: socket(PF_PACKET, SOCK_DGRAM, ETH_P_PAE) failed: %s",
5736 strerror(errno));
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005737 goto failed;
5738 }
5739
5740 if (eloop_register_read_sock(drv->eapol_sock, handle_eapol, drv, NULL))
5741 {
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -07005742 wpa_printf(MSG_INFO, "nl80211: Could not register read socket for eapol");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005743 goto failed;
5744 }
5745
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005746 if (linux_get_ifhwaddr(drv->global->ioctl_sock, bss->ifname,
5747 params->own_addr))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005748 goto failed;
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07005749 os_memcpy(drv->perm_addr, params->own_addr, ETH_ALEN);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005750
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005751 memcpy(bss->addr, params->own_addr, ETH_ALEN);
5752
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005753 return bss;
5754
5755failed:
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005756 wpa_driver_nl80211_deinit(bss);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005757 return NULL;
5758}
5759
5760
5761static void i802_deinit(void *priv)
5762{
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08005763 struct i802_bss *bss = priv;
5764 wpa_driver_nl80211_deinit(bss);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005765}
5766
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005767
5768static enum nl80211_iftype wpa_driver_nl80211_if_type(
5769 enum wpa_driver_if_type type)
5770{
5771 switch (type) {
5772 case WPA_IF_STATION:
5773 return NL80211_IFTYPE_STATION;
5774 case WPA_IF_P2P_CLIENT:
5775 case WPA_IF_P2P_GROUP:
5776 return NL80211_IFTYPE_P2P_CLIENT;
5777 case WPA_IF_AP_VLAN:
5778 return NL80211_IFTYPE_AP_VLAN;
5779 case WPA_IF_AP_BSS:
5780 return NL80211_IFTYPE_AP;
5781 case WPA_IF_P2P_GO:
5782 return NL80211_IFTYPE_P2P_GO;
Dmitry Shmidt34af3062013-07-11 10:46:32 -07005783 case WPA_IF_P2P_DEVICE:
5784 return NL80211_IFTYPE_P2P_DEVICE;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005785 case WPA_IF_MESH:
5786 return NL80211_IFTYPE_MESH_POINT;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005787 }
5788 return -1;
5789}
5790
5791
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005792#if defined(CONFIG_P2P) || defined(CONFIG_MESH)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005793
5794static int nl80211_addr_in_use(struct nl80211_global *global, const u8 *addr)
5795{
5796 struct wpa_driver_nl80211_data *drv;
5797 dl_list_for_each(drv, &global->interfaces,
5798 struct wpa_driver_nl80211_data, list) {
Dmitry Shmidtcce06662013-11-04 18:44:24 -08005799 if (os_memcmp(addr, drv->first_bss->addr, ETH_ALEN) == 0)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005800 return 1;
5801 }
5802 return 0;
5803}
5804
5805
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005806static int nl80211_vif_addr(struct wpa_driver_nl80211_data *drv, u8 *new_addr)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005807{
5808 unsigned int idx;
5809
5810 if (!drv->global)
5811 return -1;
5812
Dmitry Shmidtcce06662013-11-04 18:44:24 -08005813 os_memcpy(new_addr, drv->first_bss->addr, ETH_ALEN);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005814 for (idx = 0; idx < 64; idx++) {
Dmitry Shmidtcce06662013-11-04 18:44:24 -08005815 new_addr[0] = drv->first_bss->addr[0] | 0x02;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005816 new_addr[0] ^= idx << 2;
5817 if (!nl80211_addr_in_use(drv->global, new_addr))
5818 break;
5819 }
5820 if (idx == 64)
5821 return -1;
5822
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005823 wpa_printf(MSG_DEBUG, "nl80211: Assigned new virtual interface address "
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005824 MACSTR, MAC2STR(new_addr));
5825
5826 return 0;
5827}
5828
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005829#endif /* CONFIG_P2P || CONFIG_MESH */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005830
5831
Dmitry Shmidt34af3062013-07-11 10:46:32 -07005832struct wdev_info {
5833 u64 wdev_id;
5834 int wdev_id_set;
5835 u8 macaddr[ETH_ALEN];
5836};
5837
5838static int nl80211_wdev_handler(struct nl_msg *msg, void *arg)
5839{
5840 struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg));
5841 struct nlattr *tb[NL80211_ATTR_MAX + 1];
5842 struct wdev_info *wi = arg;
5843
5844 nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0),
5845 genlmsg_attrlen(gnlh, 0), NULL);
5846 if (tb[NL80211_ATTR_WDEV]) {
5847 wi->wdev_id = nla_get_u64(tb[NL80211_ATTR_WDEV]);
5848 wi->wdev_id_set = 1;
5849 }
5850
5851 if (tb[NL80211_ATTR_MAC])
5852 os_memcpy(wi->macaddr, nla_data(tb[NL80211_ATTR_MAC]),
5853 ETH_ALEN);
5854
5855 return NL_SKIP;
5856}
5857
5858
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005859static int wpa_driver_nl80211_if_add(void *priv, enum wpa_driver_if_type type,
5860 const char *ifname, const u8 *addr,
5861 void *bss_ctx, void **drv_priv,
5862 char *force_ifname, u8 *if_addr,
Dmitry Shmidtcce06662013-11-04 18:44:24 -08005863 const char *bridge, int use_existing)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005864{
Dmitry Shmidt34af3062013-07-11 10:46:32 -07005865 enum nl80211_iftype nlmode;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005866 struct i802_bss *bss = priv;
5867 struct wpa_driver_nl80211_data *drv = bss->drv;
5868 int ifidx;
Dmitry Shmidtcce06662013-11-04 18:44:24 -08005869 int added = 1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005870
5871 if (addr)
5872 os_memcpy(if_addr, addr, ETH_ALEN);
Dmitry Shmidt34af3062013-07-11 10:46:32 -07005873 nlmode = wpa_driver_nl80211_if_type(type);
5874 if (nlmode == NL80211_IFTYPE_P2P_DEVICE) {
5875 struct wdev_info p2pdev_info;
5876
5877 os_memset(&p2pdev_info, 0, sizeof(p2pdev_info));
5878 ifidx = nl80211_create_iface(drv, ifname, nlmode, addr,
5879 0, nl80211_wdev_handler,
Dmitry Shmidtcce06662013-11-04 18:44:24 -08005880 &p2pdev_info, use_existing);
Dmitry Shmidt34af3062013-07-11 10:46:32 -07005881 if (!p2pdev_info.wdev_id_set || ifidx != 0) {
5882 wpa_printf(MSG_ERROR, "nl80211: Failed to create a P2P Device interface %s",
5883 ifname);
5884 return -1;
5885 }
5886
5887 drv->global->if_add_wdevid = p2pdev_info.wdev_id;
5888 drv->global->if_add_wdevid_set = p2pdev_info.wdev_id_set;
5889 if (!is_zero_ether_addr(p2pdev_info.macaddr))
5890 os_memcpy(if_addr, p2pdev_info.macaddr, ETH_ALEN);
5891 wpa_printf(MSG_DEBUG, "nl80211: New P2P Device interface %s (0x%llx) created",
5892 ifname,
5893 (long long unsigned int) p2pdev_info.wdev_id);
5894 } else {
5895 ifidx = nl80211_create_iface(drv, ifname, nlmode, addr,
Dmitry Shmidtcce06662013-11-04 18:44:24 -08005896 0, NULL, NULL, use_existing);
5897 if (use_existing && ifidx == -ENFILE) {
5898 added = 0;
5899 ifidx = if_nametoindex(ifname);
5900 } else if (ifidx < 0) {
Dmitry Shmidt34af3062013-07-11 10:46:32 -07005901 return -1;
5902 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005903 }
5904
Dmitry Shmidt34af3062013-07-11 10:46:32 -07005905 if (!addr) {
5906 if (drv->nlmode == NL80211_IFTYPE_P2P_DEVICE)
5907 os_memcpy(if_addr, bss->addr, ETH_ALEN);
5908 else if (linux_get_ifhwaddr(drv->global->ioctl_sock,
5909 bss->ifname, if_addr) < 0) {
Dmitry Shmidtcce06662013-11-04 18:44:24 -08005910 if (added)
5911 nl80211_remove_iface(drv, ifidx);
Dmitry Shmidt34af3062013-07-11 10:46:32 -07005912 return -1;
5913 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005914 }
5915
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005916#if defined(CONFIG_P2P) || defined(CONFIG_MESH)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005917 if (!addr &&
5918 (type == WPA_IF_P2P_CLIENT || type == WPA_IF_P2P_GROUP ||
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005919 type == WPA_IF_P2P_GO || type == WPA_IF_MESH)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005920 /* Enforce unique P2P Interface Address */
Dmitry Shmidt34af3062013-07-11 10:46:32 -07005921 u8 new_addr[ETH_ALEN];
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005922
Dmitry Shmidt34af3062013-07-11 10:46:32 -07005923 if (linux_get_ifhwaddr(drv->global->ioctl_sock, ifname,
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005924 new_addr) < 0) {
Dmitry Shmidt71757432014-06-02 13:50:35 -07005925 if (added)
5926 nl80211_remove_iface(drv, ifidx);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005927 return -1;
5928 }
Dmitry Shmidt34af3062013-07-11 10:46:32 -07005929 if (nl80211_addr_in_use(drv->global, new_addr)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005930 wpa_printf(MSG_DEBUG, "nl80211: Allocate new address "
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005931 "for %s interface", type == WPA_IF_MESH ?
5932 "mesh" : "P2P group");
5933 if (nl80211_vif_addr(drv, new_addr) < 0) {
Dmitry Shmidt71757432014-06-02 13:50:35 -07005934 if (added)
5935 nl80211_remove_iface(drv, ifidx);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005936 return -1;
5937 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005938 if (linux_set_ifhwaddr(drv->global->ioctl_sock, ifname,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005939 new_addr) < 0) {
Dmitry Shmidt71757432014-06-02 13:50:35 -07005940 if (added)
5941 nl80211_remove_iface(drv, ifidx);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005942 return -1;
5943 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005944 }
Dmitry Shmidt6e933c12011-09-27 12:29:26 -07005945 os_memcpy(if_addr, new_addr, ETH_ALEN);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005946 }
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005947#endif /* CONFIG_P2P || CONFIG_MESH */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005948
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005949 if (type == WPA_IF_AP_BSS) {
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -07005950 struct i802_bss *new_bss = os_zalloc(sizeof(*new_bss));
5951 if (new_bss == NULL) {
Dmitry Shmidtcce06662013-11-04 18:44:24 -08005952 if (added)
5953 nl80211_remove_iface(drv, ifidx);
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -07005954 return -1;
5955 }
5956
5957 if (bridge &&
5958 i802_check_bridge(drv, new_bss, bridge, ifname) < 0) {
5959 wpa_printf(MSG_ERROR, "nl80211: Failed to add the new "
5960 "interface %s to a bridge %s",
5961 ifname, bridge);
Dmitry Shmidtcce06662013-11-04 18:44:24 -08005962 if (added)
5963 nl80211_remove_iface(drv, ifidx);
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -07005964 os_free(new_bss);
5965 return -1;
5966 }
5967
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005968 if (linux_set_iface_flags(drv->global->ioctl_sock, ifname, 1))
5969 {
Dmitry Shmidt71757432014-06-02 13:50:35 -07005970 if (added)
5971 nl80211_remove_iface(drv, ifidx);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005972 os_free(new_bss);
5973 return -1;
5974 }
5975 os_strlcpy(new_bss->ifname, ifname, IFNAMSIZ);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005976 os_memcpy(new_bss->addr, if_addr, ETH_ALEN);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005977 new_bss->ifindex = ifidx;
5978 new_bss->drv = drv;
Dmitry Shmidtcce06662013-11-04 18:44:24 -08005979 new_bss->next = drv->first_bss->next;
5980 new_bss->freq = drv->first_bss->freq;
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08005981 new_bss->ctx = bss_ctx;
Dmitry Shmidtcce06662013-11-04 18:44:24 -08005982 new_bss->added_if = added;
5983 drv->first_bss->next = new_bss;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005984 if (drv_priv)
5985 *drv_priv = new_bss;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005986 nl80211_init_bss(new_bss);
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08005987
5988 /* Subscribe management frames for this WPA_IF_AP_BSS */
5989 if (nl80211_setup_ap(new_bss))
5990 return -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005991 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005992
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005993 if (drv->global)
5994 drv->global->if_add_ifindex = ifidx;
5995
Dmitry Shmidt43cb5782014-06-16 16:23:22 -07005996 /*
5997 * Some virtual interfaces need to process EAPOL packets and events on
5998 * the parent interface. This is used mainly with hostapd.
5999 */
6000 if (ifidx > 0 &&
6001 (drv->hostapd ||
6002 nlmode == NL80211_IFTYPE_AP_VLAN ||
6003 nlmode == NL80211_IFTYPE_WDS ||
6004 nlmode == NL80211_IFTYPE_MONITOR))
Dmitry Shmidtdf5a7e42014-04-02 12:59:59 -07006005 add_ifidx(drv, ifidx);
6006
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006007 return 0;
6008}
6009
6010
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08006011static int wpa_driver_nl80211_if_remove(struct i802_bss *bss,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006012 enum wpa_driver_if_type type,
6013 const char *ifname)
6014{
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006015 struct wpa_driver_nl80211_data *drv = bss->drv;
6016 int ifindex = if_nametoindex(ifname);
6017
Dmitry Shmidtcce06662013-11-04 18:44:24 -08006018 wpa_printf(MSG_DEBUG, "nl80211: %s(type=%d ifname=%s) ifindex=%d added_if=%d",
6019 __func__, type, ifname, ifindex, bss->added_if);
Dmitry Shmidt01904cf2013-12-05 11:08:35 -08006020 if (ifindex > 0 && (bss->added_if || bss->ifindex != ifindex))
Dmitry Shmidt051af732013-10-22 13:52:46 -07006021 nl80211_remove_iface(drv, ifindex);
Dmitry Shmidt76cd2cc2014-05-27 12:56:04 -07006022 else if (ifindex > 0 && !bss->added_if) {
6023 struct wpa_driver_nl80211_data *drv2;
6024 dl_list_for_each(drv2, &drv->global->interfaces,
6025 struct wpa_driver_nl80211_data, list)
6026 del_ifidx(drv2, ifindex);
6027 }
Dmitry Shmidtaa532512012-09-24 10:35:31 -07006028
Dmitry Shmidtaa532512012-09-24 10:35:31 -07006029 if (type != WPA_IF_AP_BSS)
6030 return 0;
6031
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006032 if (bss->added_if_into_bridge) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006033 if (linux_br_del_if(drv->global->ioctl_sock, bss->brname,
6034 bss->ifname) < 0)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006035 wpa_printf(MSG_INFO, "nl80211: Failed to remove "
6036 "interface %s from bridge %s: %s",
6037 bss->ifname, bss->brname, strerror(errno));
6038 }
6039 if (bss->added_bridge) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006040 if (linux_br_del(drv->global->ioctl_sock, bss->brname) < 0)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006041 wpa_printf(MSG_INFO, "nl80211: Failed to remove "
6042 "bridge %s: %s",
6043 bss->brname, strerror(errno));
6044 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006045
Dmitry Shmidtcce06662013-11-04 18:44:24 -08006046 if (bss != drv->first_bss) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006047 struct i802_bss *tbss;
6048
Dmitry Shmidtcce06662013-11-04 18:44:24 -08006049 wpa_printf(MSG_DEBUG, "nl80211: Not the first BSS - remove it");
6050 for (tbss = drv->first_bss; tbss; tbss = tbss->next) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006051 if (tbss->next == bss) {
6052 tbss->next = bss->next;
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08006053 /* Unsubscribe management frames */
6054 nl80211_teardown_ap(bss);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006055 nl80211_destroy_bss(bss);
Dmitry Shmidtdf5a7e42014-04-02 12:59:59 -07006056 if (!bss->added_if)
6057 i802_set_iface_flags(bss, 0);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006058 os_free(bss);
6059 bss = NULL;
6060 break;
6061 }
6062 }
6063 if (bss)
6064 wpa_printf(MSG_INFO, "nl80211: %s - could not find "
6065 "BSS %p in the list", __func__, bss);
Dmitry Shmidtcce06662013-11-04 18:44:24 -08006066 } else {
6067 wpa_printf(MSG_DEBUG, "nl80211: First BSS - reassign context");
6068 nl80211_teardown_ap(bss);
6069 if (!bss->added_if && !drv->first_bss->next)
6070 wpa_driver_nl80211_del_beacon(drv);
6071 nl80211_destroy_bss(bss);
6072 if (!bss->added_if)
6073 i802_set_iface_flags(bss, 0);
6074 if (drv->first_bss->next) {
6075 drv->first_bss = drv->first_bss->next;
6076 drv->ctx = drv->first_bss->ctx;
6077 os_free(bss);
6078 } else {
6079 wpa_printf(MSG_DEBUG, "nl80211: No second BSS to reassign context to");
6080 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006081 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006082
6083 return 0;
6084}
6085
6086
6087static int cookie_handler(struct nl_msg *msg, void *arg)
6088{
6089 struct nlattr *tb[NL80211_ATTR_MAX + 1];
6090 struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg));
6091 u64 *cookie = arg;
6092 nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0),
6093 genlmsg_attrlen(gnlh, 0), NULL);
6094 if (tb[NL80211_ATTR_COOKIE])
6095 *cookie = nla_get_u64(tb[NL80211_ATTR_COOKIE]);
6096 return NL_SKIP;
6097}
6098
6099
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006100static int nl80211_send_frame_cmd(struct i802_bss *bss,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006101 unsigned int freq, unsigned int wait,
6102 const u8 *buf, size_t buf_len,
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006103 u64 *cookie_out, int no_cck, int no_ack,
6104 int offchanok)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006105{
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006106 struct wpa_driver_nl80211_data *drv = bss->drv;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006107 struct nl_msg *msg;
6108 u64 cookie;
6109 int ret = -1;
6110
Dmitry Shmidt8da800a2013-04-24 12:57:01 -07006111 wpa_printf(MSG_MSGDUMP, "nl80211: CMD_FRAME freq=%u wait=%u no_cck=%d "
Dmitry Shmidt04949592012-07-19 12:16:46 -07006112 "no_ack=%d offchanok=%d",
6113 freq, wait, no_cck, no_ack, offchanok);
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07006114 wpa_hexdump(MSG_MSGDUMP, "CMD_FRAME", buf, buf_len);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006115
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08006116 if (!(msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_FRAME)) ||
6117 (freq && nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq)) ||
6118 (wait && nla_put_u32(msg, NL80211_ATTR_DURATION, wait)) ||
6119 (offchanok && ((drv->capa.flags & WPA_DRIVER_FLAGS_OFFCHANNEL_TX) ||
6120 drv->test_use_roc_tx) &&
6121 nla_put_flag(msg, NL80211_ATTR_OFFCHANNEL_TX_OK)) ||
6122 (no_cck && nla_put_flag(msg, NL80211_ATTR_TX_NO_CCK_RATE)) ||
6123 (no_ack && nla_put_flag(msg, NL80211_ATTR_DONT_WAIT_FOR_ACK)) ||
6124 nla_put(msg, NL80211_ATTR_FRAME, buf_len, buf))
6125 goto fail;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006126
6127 cookie = 0;
6128 ret = send_and_recv_msgs(drv, msg, cookie_handler, &cookie);
6129 msg = NULL;
6130 if (ret) {
6131 wpa_printf(MSG_DEBUG, "nl80211: Frame command failed: ret=%d "
Dmitry Shmidt6e933c12011-09-27 12:29:26 -07006132 "(%s) (freq=%u wait=%u)", ret, strerror(-ret),
6133 freq, wait);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08006134 } else {
6135 wpa_printf(MSG_MSGDUMP, "nl80211: Frame TX command accepted%s; "
6136 "cookie 0x%llx", no_ack ? " (no ACK)" : "",
6137 (long long unsigned int) cookie);
6138
6139 if (cookie_out)
6140 *cookie_out = no_ack ? (u64) -1 : cookie;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006141 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006142
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08006143fail:
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006144 nlmsg_free(msg);
6145 return ret;
6146}
6147
6148
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08006149static int wpa_driver_nl80211_send_action(struct i802_bss *bss,
6150 unsigned int freq,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006151 unsigned int wait_time,
6152 const u8 *dst, const u8 *src,
6153 const u8 *bssid,
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006154 const u8 *data, size_t data_len,
6155 int no_cck)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006156{
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006157 struct wpa_driver_nl80211_data *drv = bss->drv;
6158 int ret = -1;
6159 u8 *buf;
6160 struct ieee80211_hdr *hdr;
6161
6162 wpa_printf(MSG_DEBUG, "nl80211: Send Action frame (ifindex=%d, "
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08006163 "freq=%u MHz wait=%d ms no_cck=%d)",
6164 drv->ifindex, freq, wait_time, no_cck);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006165
6166 buf = os_zalloc(24 + data_len);
6167 if (buf == NULL)
6168 return ret;
6169 os_memcpy(buf + 24, data, data_len);
6170 hdr = (struct ieee80211_hdr *) buf;
6171 hdr->frame_control =
6172 IEEE80211_FC(WLAN_FC_TYPE_MGMT, WLAN_FC_STYPE_ACTION);
6173 os_memcpy(hdr->addr1, dst, ETH_ALEN);
6174 os_memcpy(hdr->addr2, src, ETH_ALEN);
6175 os_memcpy(hdr->addr3, bssid, ETH_ALEN);
6176
Dmitry Shmidt56052862013-10-04 10:23:25 -07006177 if (is_ap_interface(drv->nlmode) &&
6178 (!(drv->capa.flags & WPA_DRIVER_FLAGS_OFFCHANNEL_TX) ||
6179 (int) freq == bss->freq || drv->device_ap_sme ||
6180 !drv->use_monitor))
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08006181 ret = wpa_driver_nl80211_send_mlme(bss, buf, 24 + data_len,
6182 0, freq, no_cck, 1,
6183 wait_time);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006184 else
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006185 ret = nl80211_send_frame_cmd(bss, freq, wait_time, buf,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006186 24 + data_len,
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006187 &drv->send_action_cookie,
6188 no_cck, 0, 1);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006189
6190 os_free(buf);
6191 return ret;
6192}
6193
6194
6195static void wpa_driver_nl80211_send_action_cancel_wait(void *priv)
6196{
6197 struct i802_bss *bss = priv;
6198 struct wpa_driver_nl80211_data *drv = bss->drv;
6199 struct nl_msg *msg;
6200 int ret;
6201
Dmitry Shmidt2f3b8de2013-03-01 09:32:50 -08006202 wpa_printf(MSG_DEBUG, "nl80211: Cancel TX frame wait: cookie=0x%llx",
6203 (long long unsigned int) drv->send_action_cookie);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08006204 if (!(msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_FRAME_WAIT_CANCEL)) ||
6205 nla_put_u64(msg, NL80211_ATTR_COOKIE, drv->send_action_cookie)) {
6206 nlmsg_free(msg);
6207 return;
6208 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006209
6210 ret = send_and_recv_msgs(drv, msg, NULL, NULL);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006211 if (ret)
6212 wpa_printf(MSG_DEBUG, "nl80211: wait cancel failed: ret=%d "
6213 "(%s)", ret, strerror(-ret));
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006214}
6215
6216
6217static int wpa_driver_nl80211_remain_on_channel(void *priv, unsigned int freq,
6218 unsigned int duration)
6219{
6220 struct i802_bss *bss = priv;
6221 struct wpa_driver_nl80211_data *drv = bss->drv;
6222 struct nl_msg *msg;
6223 int ret;
6224 u64 cookie;
6225
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08006226 if (!(msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_REMAIN_ON_CHANNEL)) ||
6227 nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq) ||
6228 nla_put_u32(msg, NL80211_ATTR_DURATION, duration)) {
6229 nlmsg_free(msg);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006230 return -1;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08006231 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006232
6233 cookie = 0;
6234 ret = send_and_recv_msgs(drv, msg, cookie_handler, &cookie);
6235 if (ret == 0) {
6236 wpa_printf(MSG_DEBUG, "nl80211: Remain-on-channel cookie "
6237 "0x%llx for freq=%u MHz duration=%u",
6238 (long long unsigned int) cookie, freq, duration);
6239 drv->remain_on_chan_cookie = cookie;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006240 drv->pending_remain_on_chan = 1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006241 return 0;
6242 }
6243 wpa_printf(MSG_DEBUG, "nl80211: Failed to request remain-on-channel "
6244 "(freq=%d duration=%u): %d (%s)",
6245 freq, duration, ret, strerror(-ret));
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006246 return -1;
6247}
6248
6249
6250static int wpa_driver_nl80211_cancel_remain_on_channel(void *priv)
6251{
6252 struct i802_bss *bss = priv;
6253 struct wpa_driver_nl80211_data *drv = bss->drv;
6254 struct nl_msg *msg;
6255 int ret;
6256
6257 if (!drv->pending_remain_on_chan) {
6258 wpa_printf(MSG_DEBUG, "nl80211: No pending remain-on-channel "
6259 "to cancel");
6260 return -1;
6261 }
6262
6263 wpa_printf(MSG_DEBUG, "nl80211: Cancel remain-on-channel with cookie "
6264 "0x%llx",
6265 (long long unsigned int) drv->remain_on_chan_cookie);
6266
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08006267 msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL);
6268 if (!msg ||
6269 nla_put_u64(msg, NL80211_ATTR_COOKIE, drv->remain_on_chan_cookie)) {
6270 nlmsg_free(msg);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006271 return -1;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08006272 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006273
6274 ret = send_and_recv_msgs(drv, msg, NULL, NULL);
6275 if (ret == 0)
6276 return 0;
6277 wpa_printf(MSG_DEBUG, "nl80211: Failed to cancel remain-on-channel: "
6278 "%d (%s)", ret, strerror(-ret));
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006279 return -1;
6280}
6281
6282
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08006283static int wpa_driver_nl80211_probe_req_report(struct i802_bss *bss, int report)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006284{
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006285 struct wpa_driver_nl80211_data *drv = bss->drv;
Dmitry Shmidt6e933c12011-09-27 12:29:26 -07006286
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006287 if (!report) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006288 if (bss->nl_preq && drv->device_ap_sme &&
Dmitry Shmidt03658832014-08-13 11:03:49 -07006289 is_ap_interface(drv->nlmode) && !bss->in_deinit &&
6290 !bss->static_ap) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006291 /*
6292 * Do not disable Probe Request reporting that was
6293 * enabled in nl80211_setup_ap().
6294 */
6295 wpa_printf(MSG_DEBUG, "nl80211: Skip disabling of "
6296 "Probe Request reporting nl_preq=%p while "
6297 "in AP mode", bss->nl_preq);
6298 } else if (bss->nl_preq) {
6299 wpa_printf(MSG_DEBUG, "nl80211: Disable Probe Request "
6300 "reporting nl_preq=%p", bss->nl_preq);
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -07006301 nl80211_destroy_eloop_handle(&bss->nl_preq);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006302 }
6303 return 0;
6304 }
6305
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006306 if (bss->nl_preq) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006307 wpa_printf(MSG_DEBUG, "nl80211: Probe Request reporting "
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006308 "already on! nl_preq=%p", bss->nl_preq);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006309 return 0;
6310 }
6311
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006312 bss->nl_preq = nl_create_handle(drv->global->nl_cb, "preq");
6313 if (bss->nl_preq == NULL)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006314 return -1;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006315 wpa_printf(MSG_DEBUG, "nl80211: Enable Probe Request "
6316 "reporting nl_preq=%p", bss->nl_preq);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006317
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006318 if (nl80211_register_frame(bss, bss->nl_preq,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006319 (WLAN_FC_TYPE_MGMT << 2) |
6320 (WLAN_FC_STYPE_PROBE_REQ << 4),
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006321 NULL, 0) < 0)
6322 goto out_err;
Dmitry Shmidt497c1d52011-07-21 15:19:46 -07006323
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -07006324 nl80211_register_eloop_read(&bss->nl_preq,
6325 wpa_driver_nl80211_event_receive,
6326 bss->nl_cb);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006327
6328 return 0;
6329
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006330 out_err:
6331 nl_destroy_handles(&bss->nl_preq);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006332 return -1;
6333}
6334
6335
6336static int nl80211_disable_11b_rates(struct wpa_driver_nl80211_data *drv,
6337 int ifindex, int disabled)
6338{
6339 struct nl_msg *msg;
6340 struct nlattr *bands, *band;
6341 int ret;
6342
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08006343 wpa_printf(MSG_DEBUG,
6344 "nl80211: NL80211_CMD_SET_TX_BITRATE_MASK (ifindex=%d %s)",
6345 ifindex, disabled ? "NL80211_TXRATE_LEGACY=OFDM-only" :
6346 "no NL80211_TXRATE_LEGACY constraint");
6347
6348 msg = nl80211_ifindex_msg(drv, ifindex, 0,
6349 NL80211_CMD_SET_TX_BITRATE_MASK);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006350 if (!msg)
6351 return -1;
6352
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006353 bands = nla_nest_start(msg, NL80211_ATTR_TX_RATES);
6354 if (!bands)
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08006355 goto fail;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006356
6357 /*
6358 * Disable 2 GHz rates 1, 2, 5.5, 11 Mbps by masking out everything
6359 * else apart from 6, 9, 12, 18, 24, 36, 48, 54 Mbps from non-MCS
6360 * rates. All 5 GHz rates are left enabled.
6361 */
6362 band = nla_nest_start(msg, NL80211_BAND_2GHZ);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08006363 if (!band ||
6364 (disabled && nla_put(msg, NL80211_TXRATE_LEGACY, 8,
6365 "\x0c\x12\x18\x24\x30\x48\x60\x6c")))
6366 goto fail;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006367 nla_nest_end(msg, band);
6368
6369 nla_nest_end(msg, bands);
6370
6371 ret = send_and_recv_msgs(drv, msg, NULL, NULL);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006372 if (ret) {
6373 wpa_printf(MSG_DEBUG, "nl80211: Set TX rates failed: ret=%d "
6374 "(%s)", ret, strerror(-ret));
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07006375 } else
6376 drv->disabled_11b_rates = disabled;
6377
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006378 return ret;
6379
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08006380fail:
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006381 nlmsg_free(msg);
6382 return -1;
6383}
6384
6385
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006386static int wpa_driver_nl80211_deinit_ap(void *priv)
6387{
6388 struct i802_bss *bss = priv;
6389 struct wpa_driver_nl80211_data *drv = bss->drv;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006390 if (!is_ap_interface(drv->nlmode))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006391 return -1;
6392 wpa_driver_nl80211_del_beacon(drv);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08006393 bss->beacon_set = 0;
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -07006394
6395 /*
6396 * If the P2P GO interface was dynamically added, then it is
6397 * possible that the interface change to station is not possible.
6398 */
6399 if (drv->nlmode == NL80211_IFTYPE_P2P_GO && bss->if_dynamic)
6400 return 0;
6401
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006402 return wpa_driver_nl80211_set_mode(priv, NL80211_IFTYPE_STATION);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006403}
6404
6405
Dmitry Shmidtea69e842013-05-13 14:52:28 -07006406static int wpa_driver_nl80211_stop_ap(void *priv)
6407{
6408 struct i802_bss *bss = priv;
6409 struct wpa_driver_nl80211_data *drv = bss->drv;
6410 if (!is_ap_interface(drv->nlmode))
6411 return -1;
6412 wpa_driver_nl80211_del_beacon(drv);
6413 bss->beacon_set = 0;
6414 return 0;
6415}
6416
6417
Dmitry Shmidt04949592012-07-19 12:16:46 -07006418static int wpa_driver_nl80211_deinit_p2p_cli(void *priv)
6419{
6420 struct i802_bss *bss = priv;
6421 struct wpa_driver_nl80211_data *drv = bss->drv;
6422 if (drv->nlmode != NL80211_IFTYPE_P2P_CLIENT)
6423 return -1;
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -07006424
6425 /*
6426 * If the P2P Client interface was dynamically added, then it is
6427 * possible that the interface change to station is not possible.
6428 */
6429 if (bss->if_dynamic)
6430 return 0;
6431
Dmitry Shmidt04949592012-07-19 12:16:46 -07006432 return wpa_driver_nl80211_set_mode(priv, NL80211_IFTYPE_STATION);
6433}
6434
6435
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006436static void wpa_driver_nl80211_resume(void *priv)
6437{
6438 struct i802_bss *bss = priv;
Dmitry Shmidt34af3062013-07-11 10:46:32 -07006439
6440 if (i802_set_iface_flags(bss, 1))
6441 wpa_printf(MSG_DEBUG, "nl80211: Failed to set interface up on resume event");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006442}
6443
6444
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006445static int nl80211_signal_monitor(void *priv, int threshold, int hysteresis)
6446{
6447 struct i802_bss *bss = priv;
6448 struct wpa_driver_nl80211_data *drv = bss->drv;
Dmitry Shmidt8da800a2013-04-24 12:57:01 -07006449 struct nl_msg *msg;
6450 struct nlattr *cqm;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006451
6452 wpa_printf(MSG_DEBUG, "nl80211: Signal monitor threshold=%d "
6453 "hysteresis=%d", threshold, hysteresis);
6454
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08006455 if (!(msg = nl80211_bss_msg(bss, 0, NL80211_CMD_SET_CQM)) ||
6456 !(cqm = nla_nest_start(msg, NL80211_ATTR_CQM)) ||
6457 nla_put_u32(msg, NL80211_ATTR_CQM_RSSI_THOLD, threshold) ||
6458 nla_put_u32(msg, NL80211_ATTR_CQM_RSSI_HYST, hysteresis)) {
6459 nlmsg_free(msg);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006460 return -1;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08006461 }
Dmitry Shmidt8da800a2013-04-24 12:57:01 -07006462 nla_nest_end(msg, cqm);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006463
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08006464 return send_and_recv_msgs(drv, msg, NULL, NULL);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006465}
6466
6467
Dmitry Shmidt34af3062013-07-11 10:46:32 -07006468static int get_channel_width(struct nl_msg *msg, void *arg)
6469{
6470 struct nlattr *tb[NL80211_ATTR_MAX + 1];
6471 struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg));
6472 struct wpa_signal_info *sig_change = arg;
6473
6474 nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0),
6475 genlmsg_attrlen(gnlh, 0), NULL);
6476
6477 sig_change->center_frq1 = -1;
6478 sig_change->center_frq2 = -1;
6479 sig_change->chanwidth = CHAN_WIDTH_UNKNOWN;
6480
6481 if (tb[NL80211_ATTR_CHANNEL_WIDTH]) {
6482 sig_change->chanwidth = convert2width(
6483 nla_get_u32(tb[NL80211_ATTR_CHANNEL_WIDTH]));
6484 if (tb[NL80211_ATTR_CENTER_FREQ1])
6485 sig_change->center_frq1 =
6486 nla_get_u32(tb[NL80211_ATTR_CENTER_FREQ1]);
6487 if (tb[NL80211_ATTR_CENTER_FREQ2])
6488 sig_change->center_frq2 =
6489 nla_get_u32(tb[NL80211_ATTR_CENTER_FREQ2]);
6490 }
6491
6492 return NL_SKIP;
6493}
6494
6495
6496static int nl80211_get_channel_width(struct wpa_driver_nl80211_data *drv,
6497 struct wpa_signal_info *sig)
6498{
6499 struct nl_msg *msg;
6500
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08006501 msg = nl80211_drv_msg(drv, 0, NL80211_CMD_GET_INTERFACE);
Dmitry Shmidt34af3062013-07-11 10:46:32 -07006502 return send_and_recv_msgs(drv, msg, get_channel_width, sig);
Dmitry Shmidt34af3062013-07-11 10:46:32 -07006503}
6504
6505
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006506static int nl80211_signal_poll(void *priv, struct wpa_signal_info *si)
6507{
6508 struct i802_bss *bss = priv;
6509 struct wpa_driver_nl80211_data *drv = bss->drv;
6510 int res;
6511
6512 os_memset(si, 0, sizeof(*si));
6513 res = nl80211_get_link_signal(drv, si);
6514 if (res != 0)
6515 return res;
6516
Dmitry Shmidt34af3062013-07-11 10:46:32 -07006517 res = nl80211_get_channel_width(drv, si);
6518 if (res != 0)
6519 return res;
6520
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006521 return nl80211_get_link_noise(drv, si);
6522}
6523
6524
6525static int nl80211_send_frame(void *priv, const u8 *data, size_t data_len,
6526 int encrypt)
6527{
6528 struct i802_bss *bss = priv;
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08006529 return wpa_driver_nl80211_send_frame(bss, data, data_len, encrypt, 0,
6530 0, 0, 0, 0);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006531}
6532
6533
6534static int nl80211_set_param(void *priv, const char *param)
6535{
6536 wpa_printf(MSG_DEBUG, "nl80211: driver param='%s'", param);
6537 if (param == NULL)
6538 return 0;
6539
6540#ifdef CONFIG_P2P
6541 if (os_strstr(param, "use_p2p_group_interface=1")) {
6542 struct i802_bss *bss = priv;
6543 struct wpa_driver_nl80211_data *drv = bss->drv;
6544
6545 wpa_printf(MSG_DEBUG, "nl80211: Use separate P2P group "
6546 "interface");
6547 drv->capa.flags |= WPA_DRIVER_FLAGS_P2P_CONCURRENT;
6548 drv->capa.flags |= WPA_DRIVER_FLAGS_P2P_MGMT_AND_NON_P2P;
6549 }
6550#endif /* CONFIG_P2P */
6551
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08006552 if (os_strstr(param, "use_monitor=1")) {
6553 struct i802_bss *bss = priv;
6554 struct wpa_driver_nl80211_data *drv = bss->drv;
6555 drv->use_monitor = 1;
6556 }
6557
6558 if (os_strstr(param, "force_connect_cmd=1")) {
6559 struct i802_bss *bss = priv;
6560 struct wpa_driver_nl80211_data *drv = bss->drv;
6561 drv->capa.flags &= ~WPA_DRIVER_FLAGS_SME;
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07006562 drv->force_connect_cmd = 1;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08006563 }
6564
Dmitry Shmidt7d5c8f22014-03-03 13:53:28 -08006565 if (os_strstr(param, "no_offchannel_tx=1")) {
6566 struct i802_bss *bss = priv;
6567 struct wpa_driver_nl80211_data *drv = bss->drv;
6568 drv->capa.flags &= ~WPA_DRIVER_FLAGS_OFFCHANNEL_TX;
6569 drv->test_use_roc_tx = 1;
6570 }
6571
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006572 return 0;
6573}
6574
6575
6576static void * nl80211_global_init(void)
6577{
6578 struct nl80211_global *global;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006579 struct netlink_config *cfg;
6580
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006581 global = os_zalloc(sizeof(*global));
6582 if (global == NULL)
6583 return NULL;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006584 global->ioctl_sock = -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006585 dl_list_init(&global->interfaces);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006586 global->if_add_ifindex = -1;
6587
6588 cfg = os_zalloc(sizeof(*cfg));
6589 if (cfg == NULL)
6590 goto err;
6591
6592 cfg->ctx = global;
6593 cfg->newlink_cb = wpa_driver_nl80211_event_rtm_newlink;
6594 cfg->dellink_cb = wpa_driver_nl80211_event_rtm_dellink;
6595 global->netlink = netlink_init(cfg);
6596 if (global->netlink == NULL) {
6597 os_free(cfg);
6598 goto err;
6599 }
6600
6601 if (wpa_driver_nl80211_init_nl_global(global) < 0)
6602 goto err;
6603
6604 global->ioctl_sock = socket(PF_INET, SOCK_DGRAM, 0);
6605 if (global->ioctl_sock < 0) {
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -07006606 wpa_printf(MSG_ERROR, "nl80211: socket(PF_INET,SOCK_DGRAM) failed: %s",
6607 strerror(errno));
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006608 goto err;
6609 }
6610
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006611 return global;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006612
6613err:
6614 nl80211_global_deinit(global);
6615 return NULL;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006616}
6617
6618
6619static void nl80211_global_deinit(void *priv)
6620{
6621 struct nl80211_global *global = priv;
6622 if (global == NULL)
6623 return;
6624 if (!dl_list_empty(&global->interfaces)) {
6625 wpa_printf(MSG_ERROR, "nl80211: %u interface(s) remain at "
6626 "nl80211_global_deinit",
6627 dl_list_len(&global->interfaces));
6628 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006629
6630 if (global->netlink)
6631 netlink_deinit(global->netlink);
6632
6633 nl_destroy_handles(&global->nl);
6634
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -07006635 if (global->nl_event)
6636 nl80211_destroy_eloop_handle(&global->nl_event);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006637
6638 nl_cb_put(global->nl_cb);
6639
6640 if (global->ioctl_sock >= 0)
6641 close(global->ioctl_sock);
6642
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006643 os_free(global);
6644}
6645
6646
6647static const char * nl80211_get_radio_name(void *priv)
6648{
6649 struct i802_bss *bss = priv;
6650 struct wpa_driver_nl80211_data *drv = bss->drv;
6651 return drv->phyname;
6652}
6653
6654
Jouni Malinen75ecf522011-06-27 15:19:46 -07006655static int nl80211_pmkid(struct i802_bss *bss, int cmd, const u8 *bssid,
6656 const u8 *pmkid)
6657{
6658 struct nl_msg *msg;
6659
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08006660 if (!(msg = nl80211_bss_msg(bss, 0, cmd)) ||
6661 (pmkid && nla_put(msg, NL80211_ATTR_PMKID, 16, pmkid)) ||
6662 (bssid && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid))) {
6663 nlmsg_free(msg);
6664 return -ENOBUFS;
6665 }
Jouni Malinen75ecf522011-06-27 15:19:46 -07006666
6667 return send_and_recv_msgs(bss->drv, msg, NULL, NULL);
Jouni Malinen75ecf522011-06-27 15:19:46 -07006668}
6669
6670
6671static int nl80211_add_pmkid(void *priv, const u8 *bssid, const u8 *pmkid)
6672{
6673 struct i802_bss *bss = priv;
6674 wpa_printf(MSG_DEBUG, "nl80211: Add PMKID for " MACSTR, MAC2STR(bssid));
6675 return nl80211_pmkid(bss, NL80211_CMD_SET_PMKSA, bssid, pmkid);
6676}
6677
6678
6679static int nl80211_remove_pmkid(void *priv, const u8 *bssid, const u8 *pmkid)
6680{
6681 struct i802_bss *bss = priv;
6682 wpa_printf(MSG_DEBUG, "nl80211: Delete PMKID for " MACSTR,
6683 MAC2STR(bssid));
6684 return nl80211_pmkid(bss, NL80211_CMD_DEL_PMKSA, bssid, pmkid);
6685}
6686
6687
6688static int nl80211_flush_pmkid(void *priv)
6689{
6690 struct i802_bss *bss = priv;
6691 wpa_printf(MSG_DEBUG, "nl80211: Flush PMKIDs");
6692 return nl80211_pmkid(bss, NL80211_CMD_FLUSH_PMKSA, NULL, NULL);
6693}
6694
6695
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -07006696static void clean_survey_results(struct survey_results *survey_results)
6697{
6698 struct freq_survey *survey, *tmp;
6699
6700 if (dl_list_empty(&survey_results->survey_list))
6701 return;
6702
6703 dl_list_for_each_safe(survey, tmp, &survey_results->survey_list,
6704 struct freq_survey, list) {
6705 dl_list_del(&survey->list);
6706 os_free(survey);
6707 }
6708}
6709
6710
6711static void add_survey(struct nlattr **sinfo, u32 ifidx,
6712 struct dl_list *survey_list)
6713{
6714 struct freq_survey *survey;
6715
6716 survey = os_zalloc(sizeof(struct freq_survey));
6717 if (!survey)
6718 return;
6719
6720 survey->ifidx = ifidx;
6721 survey->freq = nla_get_u32(sinfo[NL80211_SURVEY_INFO_FREQUENCY]);
6722 survey->filled = 0;
6723
6724 if (sinfo[NL80211_SURVEY_INFO_NOISE]) {
6725 survey->nf = (int8_t)
6726 nla_get_u8(sinfo[NL80211_SURVEY_INFO_NOISE]);
6727 survey->filled |= SURVEY_HAS_NF;
6728 }
6729
6730 if (sinfo[NL80211_SURVEY_INFO_CHANNEL_TIME]) {
6731 survey->channel_time =
6732 nla_get_u64(sinfo[NL80211_SURVEY_INFO_CHANNEL_TIME]);
6733 survey->filled |= SURVEY_HAS_CHAN_TIME;
6734 }
6735
6736 if (sinfo[NL80211_SURVEY_INFO_CHANNEL_TIME_BUSY]) {
6737 survey->channel_time_busy =
6738 nla_get_u64(sinfo[NL80211_SURVEY_INFO_CHANNEL_TIME_BUSY]);
6739 survey->filled |= SURVEY_HAS_CHAN_TIME_BUSY;
6740 }
6741
6742 if (sinfo[NL80211_SURVEY_INFO_CHANNEL_TIME_RX]) {
6743 survey->channel_time_rx =
6744 nla_get_u64(sinfo[NL80211_SURVEY_INFO_CHANNEL_TIME_RX]);
6745 survey->filled |= SURVEY_HAS_CHAN_TIME_RX;
6746 }
6747
6748 if (sinfo[NL80211_SURVEY_INFO_CHANNEL_TIME_TX]) {
6749 survey->channel_time_tx =
6750 nla_get_u64(sinfo[NL80211_SURVEY_INFO_CHANNEL_TIME_TX]);
6751 survey->filled |= SURVEY_HAS_CHAN_TIME_TX;
6752 }
6753
6754 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)",
6755 survey->freq,
6756 survey->nf,
6757 (unsigned long int) survey->channel_time,
6758 (unsigned long int) survey->channel_time_busy,
6759 (unsigned long int) survey->channel_time_tx,
6760 (unsigned long int) survey->channel_time_rx,
6761 survey->filled);
6762
6763 dl_list_add_tail(survey_list, &survey->list);
6764}
6765
6766
6767static int check_survey_ok(struct nlattr **sinfo, u32 surveyed_freq,
6768 unsigned int freq_filter)
6769{
6770 if (!freq_filter)
6771 return 1;
6772
6773 return freq_filter == surveyed_freq;
6774}
6775
6776
6777static int survey_handler(struct nl_msg *msg, void *arg)
6778{
6779 struct nlattr *tb[NL80211_ATTR_MAX + 1];
6780 struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg));
6781 struct nlattr *sinfo[NL80211_SURVEY_INFO_MAX + 1];
6782 struct survey_results *survey_results;
6783 u32 surveyed_freq = 0;
6784 u32 ifidx;
6785
6786 static struct nla_policy survey_policy[NL80211_SURVEY_INFO_MAX + 1] = {
6787 [NL80211_SURVEY_INFO_FREQUENCY] = { .type = NLA_U32 },
6788 [NL80211_SURVEY_INFO_NOISE] = { .type = NLA_U8 },
6789 };
6790
6791 survey_results = (struct survey_results *) arg;
6792
6793 nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0),
6794 genlmsg_attrlen(gnlh, 0), NULL);
6795
Dmitry Shmidt97672262014-02-03 13:02:54 -08006796 if (!tb[NL80211_ATTR_IFINDEX])
6797 return NL_SKIP;
6798
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -07006799 ifidx = nla_get_u32(tb[NL80211_ATTR_IFINDEX]);
6800
6801 if (!tb[NL80211_ATTR_SURVEY_INFO])
6802 return NL_SKIP;
6803
6804 if (nla_parse_nested(sinfo, NL80211_SURVEY_INFO_MAX,
6805 tb[NL80211_ATTR_SURVEY_INFO],
6806 survey_policy))
6807 return NL_SKIP;
6808
6809 if (!sinfo[NL80211_SURVEY_INFO_FREQUENCY]) {
6810 wpa_printf(MSG_ERROR, "nl80211: Invalid survey data");
6811 return NL_SKIP;
6812 }
6813
6814 surveyed_freq = nla_get_u32(sinfo[NL80211_SURVEY_INFO_FREQUENCY]);
6815
6816 if (!check_survey_ok(sinfo, surveyed_freq,
6817 survey_results->freq_filter))
6818 return NL_SKIP;
6819
6820 if (survey_results->freq_filter &&
6821 survey_results->freq_filter != surveyed_freq) {
6822 wpa_printf(MSG_EXCESSIVE, "nl80211: Ignoring survey data for freq %d MHz",
6823 surveyed_freq);
6824 return NL_SKIP;
6825 }
6826
6827 add_survey(sinfo, ifidx, &survey_results->survey_list);
6828
6829 return NL_SKIP;
6830}
6831
6832
6833static int wpa_driver_nl80211_get_survey(void *priv, unsigned int freq)
6834{
6835 struct i802_bss *bss = priv;
6836 struct wpa_driver_nl80211_data *drv = bss->drv;
6837 struct nl_msg *msg;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08006838 int err;
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -07006839 union wpa_event_data data;
6840 struct survey_results *survey_results;
6841
6842 os_memset(&data, 0, sizeof(data));
6843 survey_results = &data.survey_results;
6844
6845 dl_list_init(&survey_results->survey_list);
6846
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08006847 msg = nl80211_drv_msg(drv, NLM_F_DUMP, NL80211_CMD_GET_SURVEY);
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -07006848 if (!msg)
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08006849 return -ENOBUFS;
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -07006850
6851 if (freq)
6852 data.survey_results.freq_filter = freq;
6853
6854 do {
6855 wpa_printf(MSG_DEBUG, "nl80211: Fetch survey data");
6856 err = send_and_recv_msgs(drv, msg, survey_handler,
6857 survey_results);
6858 } while (err > 0);
6859
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08006860 if (err)
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -07006861 wpa_printf(MSG_ERROR, "nl80211: Failed to process survey data");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08006862 else
6863 wpa_supplicant_event(drv->ctx, EVENT_SURVEY, &data);
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -07006864
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -07006865 clean_survey_results(survey_results);
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -07006866 return err;
6867}
6868
6869
Dmitry Shmidt807291d2015-01-27 13:40:23 -08006870static void nl80211_set_rekey_info(void *priv, const u8 *kek, size_t kek_len,
6871 const u8 *kck, size_t kck_len,
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006872 const u8 *replay_ctr)
6873{
6874 struct i802_bss *bss = priv;
6875 struct wpa_driver_nl80211_data *drv = bss->drv;
6876 struct nlattr *replay_nested;
6877 struct nl_msg *msg;
Dmitry Shmidtff787d52015-01-12 13:01:47 -08006878 int ret;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006879
Dmitry Shmidtff787d52015-01-12 13:01:47 -08006880 if (!drv->set_rekey_offload)
6881 return;
6882
6883 wpa_printf(MSG_DEBUG, "nl80211: Set rekey offload");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08006884 if (!(msg = nl80211_bss_msg(bss, 0, NL80211_CMD_SET_REKEY_OFFLOAD)) ||
6885 !(replay_nested = nla_nest_start(msg, NL80211_ATTR_REKEY_DATA)) ||
Dmitry Shmidt807291d2015-01-27 13:40:23 -08006886 nla_put(msg, NL80211_REKEY_DATA_KEK, kek_len, kek) ||
6887 nla_put(msg, NL80211_REKEY_DATA_KCK, kck_len, kck) ||
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08006888 nla_put(msg, NL80211_REKEY_DATA_REPLAY_CTR, NL80211_REPLAY_CTR_LEN,
6889 replay_ctr)) {
6890 nl80211_nlmsg_clear(msg);
6891 nlmsg_free(msg);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006892 return;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08006893 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006894
6895 nla_nest_end(msg, replay_nested);
6896
Dmitry Shmidtff787d52015-01-12 13:01:47 -08006897 ret = send_and_recv_msgs(drv, msg, NULL, (void *) -1);
6898 if (ret == -EOPNOTSUPP) {
6899 wpa_printf(MSG_DEBUG,
6900 "nl80211: Driver does not support rekey offload");
6901 drv->set_rekey_offload = 0;
6902 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006903}
6904
6905
6906static void nl80211_send_null_frame(struct i802_bss *bss, const u8 *own_addr,
6907 const u8 *addr, int qos)
6908{
6909 /* send data frame to poll STA and check whether
6910 * this frame is ACKed */
6911 struct {
6912 struct ieee80211_hdr hdr;
6913 u16 qos_ctl;
6914 } STRUCT_PACKED nulldata;
6915 size_t size;
6916
6917 /* Send data frame to poll STA and check whether this frame is ACKed */
6918
6919 os_memset(&nulldata, 0, sizeof(nulldata));
6920
6921 if (qos) {
6922 nulldata.hdr.frame_control =
6923 IEEE80211_FC(WLAN_FC_TYPE_DATA,
6924 WLAN_FC_STYPE_QOS_NULL);
6925 size = sizeof(nulldata);
6926 } else {
6927 nulldata.hdr.frame_control =
6928 IEEE80211_FC(WLAN_FC_TYPE_DATA,
6929 WLAN_FC_STYPE_NULLFUNC);
6930 size = sizeof(struct ieee80211_hdr);
6931 }
6932
6933 nulldata.hdr.frame_control |= host_to_le16(WLAN_FC_FROMDS);
6934 os_memcpy(nulldata.hdr.IEEE80211_DA_FROMDS, addr, ETH_ALEN);
6935 os_memcpy(nulldata.hdr.IEEE80211_BSSID_FROMDS, own_addr, ETH_ALEN);
6936 os_memcpy(nulldata.hdr.IEEE80211_SA_FROMDS, own_addr, ETH_ALEN);
6937
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08006938 if (wpa_driver_nl80211_send_mlme(bss, (u8 *) &nulldata, size, 0, 0, 0,
6939 0, 0) < 0)
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006940 wpa_printf(MSG_DEBUG, "nl80211_send_null_frame: Failed to "
6941 "send poll frame");
6942}
6943
6944static void nl80211_poll_client(void *priv, const u8 *own_addr, const u8 *addr,
6945 int qos)
6946{
6947 struct i802_bss *bss = priv;
6948 struct wpa_driver_nl80211_data *drv = bss->drv;
6949 struct nl_msg *msg;
Dmitry Shmidt7f656022015-02-25 14:36:37 -08006950 int ret;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006951
6952 if (!drv->poll_command_supported) {
6953 nl80211_send_null_frame(bss, own_addr, addr, qos);
6954 return;
6955 }
6956
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08006957 if (!(msg = nl80211_bss_msg(bss, 0, NL80211_CMD_PROBE_CLIENT)) ||
6958 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) {
6959 nlmsg_free(msg);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006960 return;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08006961 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006962
Dmitry Shmidt7f656022015-02-25 14:36:37 -08006963 ret = send_and_recv_msgs(drv, msg, NULL, NULL);
6964 if (ret < 0) {
6965 wpa_printf(MSG_DEBUG, "nl80211: Client probe request for "
6966 MACSTR " failed: ret=%d (%s)",
6967 MAC2STR(addr), ret, strerror(-ret));
6968 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006969}
6970
6971
6972static int nl80211_set_power_save(struct i802_bss *bss, int enabled)
6973{
6974 struct nl_msg *msg;
6975
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08006976 if (!(msg = nl80211_bss_msg(bss, 0, NL80211_CMD_SET_POWER_SAVE)) ||
6977 nla_put_u32(msg, NL80211_ATTR_PS_STATE,
6978 enabled ? NL80211_PS_ENABLED : NL80211_PS_DISABLED)) {
6979 nlmsg_free(msg);
6980 return -ENOBUFS;
6981 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006982 return send_and_recv_msgs(bss->drv, msg, NULL, NULL);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006983}
6984
6985
6986static int nl80211_set_p2p_powersave(void *priv, int legacy_ps, int opp_ps,
6987 int ctwindow)
6988{
6989 struct i802_bss *bss = priv;
6990
6991 wpa_printf(MSG_DEBUG, "nl80211: set_p2p_powersave (legacy_ps=%d "
6992 "opp_ps=%d ctwindow=%d)", legacy_ps, opp_ps, ctwindow);
6993
Dmitry Shmidt292b0c32013-11-22 12:54:42 -08006994 if (opp_ps != -1 || ctwindow != -1) {
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08006995#ifdef ANDROID_P2P
6996 wpa_driver_set_p2p_ps(priv, legacy_ps, opp_ps, ctwindow);
Dmitry Shmidt292b0c32013-11-22 12:54:42 -08006997#else /* ANDROID_P2P */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006998 return -1; /* Not yet supported */
Dmitry Shmidt292b0c32013-11-22 12:54:42 -08006999#endif /* ANDROID_P2P */
7000 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08007001
7002 if (legacy_ps == -1)
7003 return 0;
7004 if (legacy_ps != 0 && legacy_ps != 1)
7005 return -1; /* Not yet supported */
7006
7007 return nl80211_set_power_save(bss, legacy_ps);
7008}
7009
7010
Dmitry Shmidt051af732013-10-22 13:52:46 -07007011static int nl80211_start_radar_detection(void *priv,
7012 struct hostapd_freq_params *freq)
Dmitry Shmidtea69e842013-05-13 14:52:28 -07007013{
7014 struct i802_bss *bss = priv;
7015 struct wpa_driver_nl80211_data *drv = bss->drv;
7016 struct nl_msg *msg;
7017 int ret;
7018
Dmitry Shmidt051af732013-10-22 13:52:46 -07007019 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)",
7020 freq->freq, freq->ht_enabled, freq->vht_enabled,
7021 freq->bandwidth, freq->center_freq1, freq->center_freq2);
7022
Dmitry Shmidtea69e842013-05-13 14:52:28 -07007023 if (!(drv->capa.flags & WPA_DRIVER_FLAGS_RADAR)) {
7024 wpa_printf(MSG_DEBUG, "nl80211: Driver does not support radar "
7025 "detection");
7026 return -1;
7027 }
7028
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08007029 if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_RADAR_DETECT)) ||
7030 nl80211_put_freq_params(msg, freq) < 0) {
7031 nlmsg_free(msg);
Dmitry Shmidtea69e842013-05-13 14:52:28 -07007032 return -1;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08007033 }
Dmitry Shmidtea69e842013-05-13 14:52:28 -07007034
7035 ret = send_and_recv_msgs(drv, msg, NULL, NULL);
7036 if (ret == 0)
7037 return 0;
7038 wpa_printf(MSG_DEBUG, "nl80211: Failed to start radar detection: "
7039 "%d (%s)", ret, strerror(-ret));
Dmitry Shmidtea69e842013-05-13 14:52:28 -07007040 return -1;
7041}
7042
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08007043#ifdef CONFIG_TDLS
7044
7045static int nl80211_send_tdls_mgmt(void *priv, const u8 *dst, u8 action_code,
7046 u8 dialog_token, u16 status_code,
Dmitry Shmidt9ead16e2014-10-07 13:15:23 -07007047 u32 peer_capab, int initiator, const u8 *buf,
7048 size_t len)
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08007049{
7050 struct i802_bss *bss = priv;
7051 struct wpa_driver_nl80211_data *drv = bss->drv;
7052 struct nl_msg *msg;
7053
7054 if (!(drv->capa.flags & WPA_DRIVER_FLAGS_TDLS_SUPPORT))
7055 return -EOPNOTSUPP;
7056
7057 if (!dst)
7058 return -EINVAL;
7059
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08007060 if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_TDLS_MGMT)) ||
7061 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, dst) ||
7062 nla_put_u8(msg, NL80211_ATTR_TDLS_ACTION, action_code) ||
7063 nla_put_u8(msg, NL80211_ATTR_TDLS_DIALOG_TOKEN, dialog_token) ||
7064 nla_put_u16(msg, NL80211_ATTR_STATUS_CODE, status_code))
7065 goto fail;
Dmitry Shmidtdf5a7e42014-04-02 12:59:59 -07007066 if (peer_capab) {
7067 /*
7068 * The internal enum tdls_peer_capability definition is
7069 * currently identical with the nl80211 enum
7070 * nl80211_tdls_peer_capability, so no conversion is needed
7071 * here.
7072 */
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08007073 if (nla_put_u32(msg, NL80211_ATTR_TDLS_PEER_CAPABILITY,
7074 peer_capab))
7075 goto fail;
Dmitry Shmidtdf5a7e42014-04-02 12:59:59 -07007076 }
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08007077 if ((initiator &&
7078 nla_put_flag(msg, NL80211_ATTR_TDLS_INITIATOR)) ||
7079 nla_put(msg, NL80211_ATTR_IE, len, buf))
7080 goto fail;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08007081
7082 return send_and_recv_msgs(drv, msg, NULL, NULL);
7083
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08007084fail:
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08007085 nlmsg_free(msg);
7086 return -ENOBUFS;
7087}
7088
7089
7090static int nl80211_tdls_oper(void *priv, enum tdls_oper oper, const u8 *peer)
7091{
7092 struct i802_bss *bss = priv;
7093 struct wpa_driver_nl80211_data *drv = bss->drv;
7094 struct nl_msg *msg;
7095 enum nl80211_tdls_operation nl80211_oper;
7096
7097 if (!(drv->capa.flags & WPA_DRIVER_FLAGS_TDLS_SUPPORT))
7098 return -EOPNOTSUPP;
7099
7100 switch (oper) {
7101 case TDLS_DISCOVERY_REQ:
7102 nl80211_oper = NL80211_TDLS_DISCOVERY_REQ;
7103 break;
7104 case TDLS_SETUP:
7105 nl80211_oper = NL80211_TDLS_SETUP;
7106 break;
7107 case TDLS_TEARDOWN:
7108 nl80211_oper = NL80211_TDLS_TEARDOWN;
7109 break;
7110 case TDLS_ENABLE_LINK:
7111 nl80211_oper = NL80211_TDLS_ENABLE_LINK;
7112 break;
7113 case TDLS_DISABLE_LINK:
7114 nl80211_oper = NL80211_TDLS_DISABLE_LINK;
7115 break;
7116 case TDLS_ENABLE:
7117 return 0;
7118 case TDLS_DISABLE:
7119 return 0;
7120 default:
7121 return -EINVAL;
7122 }
7123
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08007124 if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_TDLS_OPER)) ||
7125 nla_put_u8(msg, NL80211_ATTR_TDLS_OPERATION, nl80211_oper) ||
7126 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer)) {
7127 nlmsg_free(msg);
7128 return -ENOBUFS;
7129 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08007130
7131 return send_and_recv_msgs(drv, msg, NULL, NULL);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08007132}
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08007133
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08007134
7135static int
7136nl80211_tdls_enable_channel_switch(void *priv, const u8 *addr, u8 oper_class,
7137 const struct hostapd_freq_params *params)
7138{
7139 struct i802_bss *bss = priv;
7140 struct wpa_driver_nl80211_data *drv = bss->drv;
7141 struct nl_msg *msg;
7142 int ret = -ENOBUFS;
7143
7144 if (!(drv->capa.flags & WPA_DRIVER_FLAGS_TDLS_SUPPORT) ||
7145 !(drv->capa.flags & WPA_DRIVER_FLAGS_TDLS_CHANNEL_SWITCH))
7146 return -EOPNOTSUPP;
7147
7148 wpa_printf(MSG_DEBUG, "nl80211: Enable TDLS channel switch " MACSTR
7149 " oper_class=%u freq=%u",
7150 MAC2STR(addr), oper_class, params->freq);
7151 msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_TDLS_CHANNEL_SWITCH);
7152 if (!msg ||
7153 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) ||
7154 nla_put_u8(msg, NL80211_ATTR_OPER_CLASS, oper_class) ||
7155 (ret = nl80211_put_freq_params(msg, params))) {
7156 nlmsg_free(msg);
7157 wpa_printf(MSG_DEBUG, "nl80211: Could not build TDLS chan switch");
7158 return ret;
7159 }
7160
7161 return send_and_recv_msgs(drv, msg, NULL, NULL);
7162}
7163
7164
7165static int
7166nl80211_tdls_disable_channel_switch(void *priv, const u8 *addr)
7167{
7168 struct i802_bss *bss = priv;
7169 struct wpa_driver_nl80211_data *drv = bss->drv;
7170 struct nl_msg *msg;
7171
7172 if (!(drv->capa.flags & WPA_DRIVER_FLAGS_TDLS_SUPPORT) ||
7173 !(drv->capa.flags & WPA_DRIVER_FLAGS_TDLS_CHANNEL_SWITCH))
7174 return -EOPNOTSUPP;
7175
7176 wpa_printf(MSG_DEBUG, "nl80211: Disable TDLS channel switch " MACSTR,
7177 MAC2STR(addr));
7178 msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_TDLS_CANCEL_CHANNEL_SWITCH);
7179 if (!msg ||
7180 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) {
7181 nlmsg_free(msg);
7182 wpa_printf(MSG_DEBUG,
7183 "nl80211: Could not build TDLS cancel chan switch");
7184 return -ENOBUFS;
7185 }
7186
7187 return send_and_recv_msgs(drv, msg, NULL, NULL);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08007188}
7189
7190#endif /* CONFIG TDLS */
7191
7192
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08007193static int driver_nl80211_set_key(const char *ifname, void *priv,
7194 enum wpa_alg alg, const u8 *addr,
7195 int key_idx, int set_tx,
7196 const u8 *seq, size_t seq_len,
7197 const u8 *key, size_t key_len)
7198{
7199 struct i802_bss *bss = priv;
7200 return wpa_driver_nl80211_set_key(ifname, bss, alg, addr, key_idx,
7201 set_tx, seq, seq_len, key, key_len);
7202}
7203
7204
7205static int driver_nl80211_scan2(void *priv,
7206 struct wpa_driver_scan_params *params)
7207{
7208 struct i802_bss *bss = priv;
7209 return wpa_driver_nl80211_scan(bss, params);
7210}
7211
7212
7213static int driver_nl80211_deauthenticate(void *priv, const u8 *addr,
7214 int reason_code)
7215{
7216 struct i802_bss *bss = priv;
7217 return wpa_driver_nl80211_deauthenticate(bss, addr, reason_code);
7218}
7219
7220
7221static int driver_nl80211_authenticate(void *priv,
7222 struct wpa_driver_auth_params *params)
7223{
7224 struct i802_bss *bss = priv;
7225 return wpa_driver_nl80211_authenticate(bss, params);
7226}
7227
7228
7229static void driver_nl80211_deinit(void *priv)
7230{
7231 struct i802_bss *bss = priv;
7232 wpa_driver_nl80211_deinit(bss);
7233}
7234
7235
7236static int driver_nl80211_if_remove(void *priv, enum wpa_driver_if_type type,
7237 const char *ifname)
7238{
7239 struct i802_bss *bss = priv;
7240 return wpa_driver_nl80211_if_remove(bss, type, ifname);
7241}
7242
7243
7244static int driver_nl80211_send_mlme(void *priv, const u8 *data,
7245 size_t data_len, int noack)
7246{
7247 struct i802_bss *bss = priv;
7248 return wpa_driver_nl80211_send_mlme(bss, data, data_len, noack,
7249 0, 0, 0, 0);
7250}
7251
7252
7253static int driver_nl80211_sta_remove(void *priv, const u8 *addr)
7254{
7255 struct i802_bss *bss = priv;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08007256 return wpa_driver_nl80211_sta_remove(bss, addr, -1, 0);
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08007257}
7258
7259
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08007260static int driver_nl80211_set_sta_vlan(void *priv, const u8 *addr,
7261 const char *ifname, int vlan_id)
7262{
7263 struct i802_bss *bss = priv;
7264 return i802_set_sta_vlan(bss, addr, ifname, vlan_id);
7265}
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08007266
7267
7268static int driver_nl80211_read_sta_data(void *priv,
7269 struct hostap_sta_driver_data *data,
7270 const u8 *addr)
7271{
7272 struct i802_bss *bss = priv;
7273 return i802_read_sta_data(bss, data, addr);
7274}
7275
7276
7277static int driver_nl80211_send_action(void *priv, unsigned int freq,
7278 unsigned int wait_time,
7279 const u8 *dst, const u8 *src,
7280 const u8 *bssid,
7281 const u8 *data, size_t data_len,
7282 int no_cck)
7283{
7284 struct i802_bss *bss = priv;
7285 return wpa_driver_nl80211_send_action(bss, freq, wait_time, dst, src,
7286 bssid, data, data_len, no_cck);
7287}
7288
7289
7290static int driver_nl80211_probe_req_report(void *priv, int report)
7291{
7292 struct i802_bss *bss = priv;
7293 return wpa_driver_nl80211_probe_req_report(bss, report);
7294}
7295
7296
Dmitry Shmidt700a1372013-03-15 14:14:44 -07007297static int wpa_driver_nl80211_update_ft_ies(void *priv, const u8 *md,
7298 const u8 *ies, size_t ies_len)
7299{
7300 int ret;
7301 struct nl_msg *msg;
7302 struct i802_bss *bss = priv;
7303 struct wpa_driver_nl80211_data *drv = bss->drv;
7304 u16 mdid = WPA_GET_LE16(md);
7305
Dmitry Shmidt700a1372013-03-15 14:14:44 -07007306 wpa_printf(MSG_DEBUG, "nl80211: Updating FT IEs");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08007307 if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_UPDATE_FT_IES)) ||
7308 nla_put(msg, NL80211_ATTR_IE, ies_len, ies) ||
7309 nla_put_u16(msg, NL80211_ATTR_MDID, mdid)) {
7310 nlmsg_free(msg);
7311 return -ENOBUFS;
7312 }
Dmitry Shmidt700a1372013-03-15 14:14:44 -07007313
7314 ret = send_and_recv_msgs(drv, msg, NULL, NULL);
7315 if (ret) {
7316 wpa_printf(MSG_DEBUG, "nl80211: update_ft_ies failed "
7317 "err=%d (%s)", ret, strerror(-ret));
7318 }
7319
7320 return ret;
Dmitry Shmidt700a1372013-03-15 14:14:44 -07007321}
7322
7323
Dmitry Shmidt34af3062013-07-11 10:46:32 -07007324const u8 * wpa_driver_nl80211_get_macaddr(void *priv)
7325{
7326 struct i802_bss *bss = priv;
7327 struct wpa_driver_nl80211_data *drv = bss->drv;
7328
7329 if (drv->nlmode != NL80211_IFTYPE_P2P_DEVICE)
7330 return NULL;
7331
7332 return bss->addr;
7333}
7334
7335
Dmitry Shmidt56052862013-10-04 10:23:25 -07007336static const char * scan_state_str(enum scan_states scan_state)
7337{
7338 switch (scan_state) {
7339 case NO_SCAN:
7340 return "NO_SCAN";
7341 case SCAN_REQUESTED:
7342 return "SCAN_REQUESTED";
7343 case SCAN_STARTED:
7344 return "SCAN_STARTED";
7345 case SCAN_COMPLETED:
7346 return "SCAN_COMPLETED";
7347 case SCAN_ABORTED:
7348 return "SCAN_ABORTED";
7349 case SCHED_SCAN_STARTED:
7350 return "SCHED_SCAN_STARTED";
7351 case SCHED_SCAN_STOPPED:
7352 return "SCHED_SCAN_STOPPED";
7353 case SCHED_SCAN_RESULTS:
7354 return "SCHED_SCAN_RESULTS";
7355 }
7356
7357 return "??";
7358}
7359
7360
7361static int wpa_driver_nl80211_status(void *priv, char *buf, size_t buflen)
7362{
7363 struct i802_bss *bss = priv;
7364 struct wpa_driver_nl80211_data *drv = bss->drv;
7365 int res;
7366 char *pos, *end;
7367
7368 pos = buf;
7369 end = buf + buflen;
7370
7371 res = os_snprintf(pos, end - pos,
7372 "ifindex=%d\n"
7373 "ifname=%s\n"
7374 "brname=%s\n"
7375 "addr=" MACSTR "\n"
7376 "freq=%d\n"
7377 "%s%s%s%s%s",
7378 bss->ifindex,
7379 bss->ifname,
7380 bss->brname,
7381 MAC2STR(bss->addr),
7382 bss->freq,
7383 bss->beacon_set ? "beacon_set=1\n" : "",
7384 bss->added_if_into_bridge ?
7385 "added_if_into_bridge=1\n" : "",
7386 bss->added_bridge ? "added_bridge=1\n" : "",
7387 bss->in_deinit ? "in_deinit=1\n" : "",
7388 bss->if_dynamic ? "if_dynamic=1\n" : "");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08007389 if (os_snprintf_error(end - pos, res))
Dmitry Shmidt56052862013-10-04 10:23:25 -07007390 return pos - buf;
7391 pos += res;
7392
7393 if (bss->wdev_id_set) {
7394 res = os_snprintf(pos, end - pos, "wdev_id=%llu\n",
7395 (unsigned long long) bss->wdev_id);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08007396 if (os_snprintf_error(end - pos, res))
Dmitry Shmidt56052862013-10-04 10:23:25 -07007397 return pos - buf;
7398 pos += res;
7399 }
7400
7401 res = os_snprintf(pos, end - pos,
7402 "phyname=%s\n"
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07007403 "perm_addr=" MACSTR "\n"
Dmitry Shmidt56052862013-10-04 10:23:25 -07007404 "drv_ifindex=%d\n"
7405 "operstate=%d\n"
7406 "scan_state=%s\n"
7407 "auth_bssid=" MACSTR "\n"
7408 "auth_attempt_bssid=" MACSTR "\n"
7409 "bssid=" MACSTR "\n"
7410 "prev_bssid=" MACSTR "\n"
7411 "associated=%d\n"
7412 "assoc_freq=%u\n"
7413 "monitor_sock=%d\n"
7414 "monitor_ifidx=%d\n"
7415 "monitor_refcount=%d\n"
7416 "last_mgmt_freq=%u\n"
7417 "eapol_tx_sock=%d\n"
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08007418 "%s%s%s%s%s%s%s%s%s%s%s%s%s",
Dmitry Shmidt56052862013-10-04 10:23:25 -07007419 drv->phyname,
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07007420 MAC2STR(drv->perm_addr),
Dmitry Shmidt56052862013-10-04 10:23:25 -07007421 drv->ifindex,
7422 drv->operstate,
7423 scan_state_str(drv->scan_state),
7424 MAC2STR(drv->auth_bssid),
7425 MAC2STR(drv->auth_attempt_bssid),
7426 MAC2STR(drv->bssid),
7427 MAC2STR(drv->prev_bssid),
7428 drv->associated,
7429 drv->assoc_freq,
7430 drv->monitor_sock,
7431 drv->monitor_ifidx,
7432 drv->monitor_refcount,
7433 drv->last_mgmt_freq,
7434 drv->eapol_tx_sock,
7435 drv->ignore_if_down_event ?
7436 "ignore_if_down_event=1\n" : "",
7437 drv->scan_complete_events ?
7438 "scan_complete_events=1\n" : "",
7439 drv->disabled_11b_rates ?
7440 "disabled_11b_rates=1\n" : "",
7441 drv->pending_remain_on_chan ?
7442 "pending_remain_on_chan=1\n" : "",
7443 drv->in_interface_list ? "in_interface_list=1\n" : "",
7444 drv->device_ap_sme ? "device_ap_sme=1\n" : "",
7445 drv->poll_command_supported ?
7446 "poll_command_supported=1\n" : "",
7447 drv->data_tx_status ? "data_tx_status=1\n" : "",
7448 drv->scan_for_auth ? "scan_for_auth=1\n" : "",
7449 drv->retry_auth ? "retry_auth=1\n" : "",
7450 drv->use_monitor ? "use_monitor=1\n" : "",
7451 drv->ignore_next_local_disconnect ?
7452 "ignore_next_local_disconnect=1\n" : "",
Dmitry Shmidt7dba0e52014-04-14 10:49:15 -07007453 drv->ignore_next_local_deauth ?
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08007454 "ignore_next_local_deauth=1\n" : "");
7455 if (os_snprintf_error(end - pos, res))
Dmitry Shmidt56052862013-10-04 10:23:25 -07007456 return pos - buf;
7457 pos += res;
7458
7459 if (drv->has_capability) {
7460 res = os_snprintf(pos, end - pos,
7461 "capa.key_mgmt=0x%x\n"
7462 "capa.enc=0x%x\n"
7463 "capa.auth=0x%x\n"
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08007464 "capa.flags=0x%llx\n"
7465 "capa.rrm_flags=0x%x\n"
Dmitry Shmidt56052862013-10-04 10:23:25 -07007466 "capa.max_scan_ssids=%d\n"
7467 "capa.max_sched_scan_ssids=%d\n"
7468 "capa.sched_scan_supported=%d\n"
7469 "capa.max_match_sets=%d\n"
7470 "capa.max_remain_on_chan=%u\n"
7471 "capa.max_stations=%u\n"
7472 "capa.probe_resp_offloads=0x%x\n"
7473 "capa.max_acl_mac_addrs=%u\n"
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08007474 "capa.num_multichan_concurrent=%u\n"
7475 "capa.mac_addr_rand_sched_scan_supported=%d\n"
7476 "capa.mac_addr_rand_scan_supported=%d\n",
Dmitry Shmidt56052862013-10-04 10:23:25 -07007477 drv->capa.key_mgmt,
7478 drv->capa.enc,
7479 drv->capa.auth,
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08007480 (unsigned long long) drv->capa.flags,
7481 drv->capa.rrm_flags,
Dmitry Shmidt56052862013-10-04 10:23:25 -07007482 drv->capa.max_scan_ssids,
7483 drv->capa.max_sched_scan_ssids,
7484 drv->capa.sched_scan_supported,
7485 drv->capa.max_match_sets,
7486 drv->capa.max_remain_on_chan,
7487 drv->capa.max_stations,
7488 drv->capa.probe_resp_offloads,
7489 drv->capa.max_acl_mac_addrs,
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08007490 drv->capa.num_multichan_concurrent,
7491 drv->capa.mac_addr_rand_sched_scan_supported,
7492 drv->capa.mac_addr_rand_scan_supported);
7493 if (os_snprintf_error(end - pos, res))
Dmitry Shmidt56052862013-10-04 10:23:25 -07007494 return pos - buf;
7495 pos += res;
7496 }
7497
7498 return pos - buf;
7499}
7500
7501
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08007502static int set_beacon_data(struct nl_msg *msg, struct beacon_data *settings)
7503{
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08007504 if ((settings->head &&
7505 nla_put(msg, NL80211_ATTR_BEACON_HEAD,
7506 settings->head_len, settings->head)) ||
7507 (settings->tail &&
7508 nla_put(msg, NL80211_ATTR_BEACON_TAIL,
7509 settings->tail_len, settings->tail)) ||
7510 (settings->beacon_ies &&
7511 nla_put(msg, NL80211_ATTR_IE,
7512 settings->beacon_ies_len, settings->beacon_ies)) ||
7513 (settings->proberesp_ies &&
7514 nla_put(msg, NL80211_ATTR_IE_PROBE_RESP,
7515 settings->proberesp_ies_len, settings->proberesp_ies)) ||
7516 (settings->assocresp_ies &&
7517 nla_put(msg, NL80211_ATTR_IE_ASSOC_RESP,
7518 settings->assocresp_ies_len, settings->assocresp_ies)) ||
7519 (settings->probe_resp &&
7520 nla_put(msg, NL80211_ATTR_PROBE_RESP,
7521 settings->probe_resp_len, settings->probe_resp)))
7522 return -ENOBUFS;
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08007523
7524 return 0;
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08007525}
7526
7527
7528static int nl80211_switch_channel(void *priv, struct csa_settings *settings)
7529{
7530 struct nl_msg *msg;
7531 struct i802_bss *bss = priv;
7532 struct wpa_driver_nl80211_data *drv = bss->drv;
7533 struct nlattr *beacon_csa;
7534 int ret = -ENOBUFS;
7535
Dmitry Shmidt04f534e2013-12-09 15:50:16 -08007536 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 -08007537 settings->cs_count, settings->block_tx,
Dmitry Shmidt04f534e2013-12-09 15:50:16 -08007538 settings->freq_params.freq, settings->freq_params.bandwidth,
7539 settings->freq_params.center_freq1,
7540 settings->freq_params.center_freq2);
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08007541
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08007542 if (!(drv->capa.flags & WPA_DRIVER_FLAGS_AP_CSA)) {
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08007543 wpa_printf(MSG_DEBUG, "nl80211: Driver does not support channel switch command");
7544 return -EOPNOTSUPP;
7545 }
7546
7547 if ((drv->nlmode != NL80211_IFTYPE_AP) &&
7548 (drv->nlmode != NL80211_IFTYPE_P2P_GO))
7549 return -EOPNOTSUPP;
7550
7551 /* check settings validity */
7552 if (!settings->beacon_csa.tail ||
7553 ((settings->beacon_csa.tail_len <=
7554 settings->counter_offset_beacon) ||
7555 (settings->beacon_csa.tail[settings->counter_offset_beacon] !=
7556 settings->cs_count)))
7557 return -EINVAL;
7558
7559 if (settings->beacon_csa.probe_resp &&
7560 ((settings->beacon_csa.probe_resp_len <=
7561 settings->counter_offset_presp) ||
7562 (settings->beacon_csa.probe_resp[settings->counter_offset_presp] !=
7563 settings->cs_count)))
7564 return -EINVAL;
7565
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08007566 if (!(msg = nl80211_bss_msg(bss, 0, NL80211_CMD_CHANNEL_SWITCH)) ||
7567 nla_put_u32(msg, NL80211_ATTR_CH_SWITCH_COUNT,
7568 settings->cs_count) ||
7569 (ret = nl80211_put_freq_params(msg, &settings->freq_params)) ||
7570 (settings->block_tx &&
7571 nla_put_flag(msg, NL80211_ATTR_CH_SWITCH_BLOCK_TX)))
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08007572 goto error;
7573
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08007574 /* beacon_after params */
7575 ret = set_beacon_data(msg, &settings->beacon_after);
7576 if (ret)
7577 goto error;
7578
7579 /* beacon_csa params */
7580 beacon_csa = nla_nest_start(msg, NL80211_ATTR_CSA_IES);
7581 if (!beacon_csa)
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08007582 goto fail;
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08007583
7584 ret = set_beacon_data(msg, &settings->beacon_csa);
7585 if (ret)
7586 goto error;
7587
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08007588 if (nla_put_u16(msg, NL80211_ATTR_CSA_C_OFF_BEACON,
7589 settings->counter_offset_beacon) ||
7590 (settings->beacon_csa.probe_resp &&
7591 nla_put_u16(msg, NL80211_ATTR_CSA_C_OFF_PRESP,
7592 settings->counter_offset_presp)))
7593 goto fail;
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08007594
7595 nla_nest_end(msg, beacon_csa);
7596 ret = send_and_recv_msgs(drv, msg, NULL, NULL);
7597 if (ret) {
7598 wpa_printf(MSG_DEBUG, "nl80211: switch_channel failed err=%d (%s)",
7599 ret, strerror(-ret));
7600 }
7601 return ret;
7602
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08007603fail:
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08007604 ret = -ENOBUFS;
7605error:
7606 nlmsg_free(msg);
7607 wpa_printf(MSG_DEBUG, "nl80211: Could not build channel switch request");
7608 return ret;
7609}
7610
7611
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08007612static int nl80211_add_ts(void *priv, u8 tsid, const u8 *addr,
7613 u8 user_priority, u16 admitted_time)
7614{
7615 struct i802_bss *bss = priv;
7616 struct wpa_driver_nl80211_data *drv = bss->drv;
7617 struct nl_msg *msg;
7618 int ret;
7619
7620 wpa_printf(MSG_DEBUG,
7621 "nl80211: add_ts request: tsid=%u admitted_time=%u up=%d",
7622 tsid, admitted_time, user_priority);
7623
7624 if (!is_sta_interface(drv->nlmode))
7625 return -ENOTSUP;
7626
7627 msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_ADD_TX_TS);
7628 if (!msg ||
7629 nla_put_u8(msg, NL80211_ATTR_TSID, tsid) ||
7630 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) ||
7631 nla_put_u8(msg, NL80211_ATTR_USER_PRIO, user_priority) ||
7632 nla_put_u16(msg, NL80211_ATTR_ADMITTED_TIME, admitted_time)) {
7633 nlmsg_free(msg);
7634 return -ENOBUFS;
7635 }
7636
7637 ret = send_and_recv_msgs(drv, msg, NULL, NULL);
7638 if (ret)
7639 wpa_printf(MSG_DEBUG, "nl80211: add_ts failed err=%d (%s)",
7640 ret, strerror(-ret));
7641 return ret;
7642}
7643
7644
7645static int nl80211_del_ts(void *priv, u8 tsid, const u8 *addr)
7646{
7647 struct i802_bss *bss = priv;
7648 struct wpa_driver_nl80211_data *drv = bss->drv;
7649 struct nl_msg *msg;
7650 int ret;
7651
7652 wpa_printf(MSG_DEBUG, "nl80211: del_ts request: tsid=%u", tsid);
7653
7654 if (!is_sta_interface(drv->nlmode))
7655 return -ENOTSUP;
7656
7657 if (!(msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_DEL_TX_TS)) ||
7658 nla_put_u8(msg, NL80211_ATTR_TSID, tsid) ||
7659 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) {
7660 nlmsg_free(msg);
7661 return -ENOBUFS;
7662 }
7663
7664 ret = send_and_recv_msgs(drv, msg, NULL, NULL);
7665 if (ret)
7666 wpa_printf(MSG_DEBUG, "nl80211: del_ts failed err=%d (%s)",
7667 ret, strerror(-ret));
7668 return ret;
7669}
7670
7671
Dmitry Shmidta38abf92014-03-06 13:38:44 -08007672#ifdef CONFIG_TESTING_OPTIONS
7673static int cmd_reply_handler(struct nl_msg *msg, void *arg)
7674{
7675 struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg));
7676 struct wpabuf *buf = arg;
7677
7678 if (!buf)
7679 return NL_SKIP;
7680
7681 if ((size_t) genlmsg_attrlen(gnlh, 0) > wpabuf_tailroom(buf)) {
7682 wpa_printf(MSG_INFO, "nl80211: insufficient buffer space for reply");
7683 return NL_SKIP;
7684 }
7685
7686 wpabuf_put_data(buf, genlmsg_attrdata(gnlh, 0),
7687 genlmsg_attrlen(gnlh, 0));
7688
7689 return NL_SKIP;
7690}
7691#endif /* CONFIG_TESTING_OPTIONS */
7692
7693
7694static int vendor_reply_handler(struct nl_msg *msg, void *arg)
7695{
7696 struct nlattr *tb[NL80211_ATTR_MAX + 1];
7697 struct nlattr *nl_vendor_reply, *nl;
7698 struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg));
7699 struct wpabuf *buf = arg;
7700 int rem;
7701
7702 if (!buf)
7703 return NL_SKIP;
7704
7705 nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0),
7706 genlmsg_attrlen(gnlh, 0), NULL);
7707 nl_vendor_reply = tb[NL80211_ATTR_VENDOR_DATA];
7708
7709 if (!nl_vendor_reply)
7710 return NL_SKIP;
7711
7712 if ((size_t) nla_len(nl_vendor_reply) > wpabuf_tailroom(buf)) {
7713 wpa_printf(MSG_INFO, "nl80211: Vendor command: insufficient buffer space for reply");
7714 return NL_SKIP;
7715 }
7716
7717 nla_for_each_nested(nl, nl_vendor_reply, rem) {
7718 wpabuf_put_data(buf, nla_data(nl), nla_len(nl));
7719 }
7720
7721 return NL_SKIP;
7722}
7723
7724
7725static int nl80211_vendor_cmd(void *priv, unsigned int vendor_id,
7726 unsigned int subcmd, const u8 *data,
7727 size_t data_len, struct wpabuf *buf)
7728{
7729 struct i802_bss *bss = priv;
7730 struct wpa_driver_nl80211_data *drv = bss->drv;
7731 struct nl_msg *msg;
7732 int ret;
7733
Dmitry Shmidta38abf92014-03-06 13:38:44 -08007734#ifdef CONFIG_TESTING_OPTIONS
7735 if (vendor_id == 0xffffffff) {
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08007736 msg = nlmsg_alloc();
7737 if (!msg)
7738 return -ENOMEM;
7739
Dmitry Shmidta38abf92014-03-06 13:38:44 -08007740 nl80211_cmd(drv, msg, 0, subcmd);
7741 if (nlmsg_append(msg, (void *) data, data_len, NLMSG_ALIGNTO) <
7742 0)
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08007743 goto fail;
Dmitry Shmidta38abf92014-03-06 13:38:44 -08007744 ret = send_and_recv_msgs(drv, msg, cmd_reply_handler, buf);
7745 if (ret)
7746 wpa_printf(MSG_DEBUG, "nl80211: command failed err=%d",
7747 ret);
7748 return ret;
7749 }
7750#endif /* CONFIG_TESTING_OPTIONS */
7751
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08007752 if (!(msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_VENDOR)) ||
7753 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, vendor_id) ||
7754 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD, subcmd) ||
7755 (data &&
7756 nla_put(msg, NL80211_ATTR_VENDOR_DATA, data_len, data)))
7757 goto fail;
Dmitry Shmidta38abf92014-03-06 13:38:44 -08007758
7759 ret = send_and_recv_msgs(drv, msg, vendor_reply_handler, buf);
7760 if (ret)
7761 wpa_printf(MSG_DEBUG, "nl80211: vendor command failed err=%d",
7762 ret);
7763 return ret;
7764
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08007765fail:
Dmitry Shmidta38abf92014-03-06 13:38:44 -08007766 nlmsg_free(msg);
7767 return -ENOBUFS;
7768}
7769
7770
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08007771static int nl80211_set_qos_map(void *priv, const u8 *qos_map_set,
7772 u8 qos_map_set_len)
7773{
7774 struct i802_bss *bss = priv;
7775 struct wpa_driver_nl80211_data *drv = bss->drv;
7776 struct nl_msg *msg;
7777 int ret;
7778
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08007779 wpa_hexdump(MSG_DEBUG, "nl80211: Setting QoS Map",
7780 qos_map_set, qos_map_set_len);
7781
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08007782 if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_SET_QOS_MAP)) ||
7783 nla_put(msg, NL80211_ATTR_QOS_MAP, qos_map_set_len, qos_map_set)) {
7784 nlmsg_free(msg);
7785 return -ENOBUFS;
7786 }
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08007787
7788 ret = send_and_recv_msgs(drv, msg, NULL, NULL);
7789 if (ret)
7790 wpa_printf(MSG_DEBUG, "nl80211: Setting QoS Map failed");
7791
7792 return ret;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08007793}
7794
7795
Dmitry Shmidtb58836e2014-04-29 14:35:56 -07007796static int nl80211_set_wowlan(void *priv,
7797 const struct wowlan_triggers *triggers)
7798{
7799 struct i802_bss *bss = priv;
7800 struct wpa_driver_nl80211_data *drv = bss->drv;
7801 struct nl_msg *msg;
7802 struct nlattr *wowlan_triggers;
7803 int ret;
7804
Dmitry Shmidtb58836e2014-04-29 14:35:56 -07007805 wpa_printf(MSG_DEBUG, "nl80211: Setting wowlan");
7806
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08007807 if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_SET_WOWLAN)) ||
7808 !(wowlan_triggers = nla_nest_start(msg,
7809 NL80211_ATTR_WOWLAN_TRIGGERS)) ||
7810 (triggers->any &&
7811 nla_put_flag(msg, NL80211_WOWLAN_TRIG_ANY)) ||
7812 (triggers->disconnect &&
7813 nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) ||
7814 (triggers->magic_pkt &&
7815 nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) ||
7816 (triggers->gtk_rekey_failure &&
7817 nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) ||
7818 (triggers->eap_identity_req &&
7819 nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) ||
7820 (triggers->four_way_handshake &&
7821 nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) ||
7822 (triggers->rfkill_release &&
7823 nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE))) {
7824 nlmsg_free(msg);
7825 return -ENOBUFS;
7826 }
Dmitry Shmidtb58836e2014-04-29 14:35:56 -07007827
7828 nla_nest_end(msg, wowlan_triggers);
7829
7830 ret = send_and_recv_msgs(drv, msg, NULL, NULL);
7831 if (ret)
7832 wpa_printf(MSG_DEBUG, "nl80211: Setting wowlan failed");
7833
7834 return ret;
Dmitry Shmidtb58836e2014-04-29 14:35:56 -07007835}
7836
7837
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07007838static int nl80211_roaming(void *priv, int allowed, const u8 *bssid)
7839{
7840 struct i802_bss *bss = priv;
7841 struct wpa_driver_nl80211_data *drv = bss->drv;
7842 struct nl_msg *msg;
7843 struct nlattr *params;
7844
7845 wpa_printf(MSG_DEBUG, "nl80211: Roaming policy: allowed=%d", allowed);
7846
7847 if (!drv->roaming_vendor_cmd_avail) {
7848 wpa_printf(MSG_DEBUG,
7849 "nl80211: Ignore roaming policy change since driver does not provide command for setting it");
7850 return -1;
7851 }
7852
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08007853 if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_VENDOR)) ||
7854 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
7855 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
7856 QCA_NL80211_VENDOR_SUBCMD_ROAMING) ||
7857 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
7858 nla_put_u32(msg, QCA_WLAN_VENDOR_ATTR_ROAMING_POLICY,
7859 allowed ? QCA_ROAMING_ALLOWED_WITHIN_ESS :
7860 QCA_ROAMING_NOT_ALLOWED) ||
7861 (bssid &&
7862 nla_put(msg, QCA_WLAN_VENDOR_ATTR_MAC_ADDR, ETH_ALEN, bssid))) {
7863 nlmsg_free(msg);
7864 return -1;
7865 }
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07007866 nla_nest_end(msg, params);
7867
7868 return send_and_recv_msgs(drv, msg, NULL, NULL);
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07007869}
7870
7871
7872static int nl80211_set_mac_addr(void *priv, const u8 *addr)
7873{
7874 struct i802_bss *bss = priv;
7875 struct wpa_driver_nl80211_data *drv = bss->drv;
7876 int new_addr = addr != NULL;
7877
7878 if (!addr)
7879 addr = drv->perm_addr;
7880
7881 if (linux_set_iface_flags(drv->global->ioctl_sock, bss->ifname, 0) < 0)
7882 return -1;
7883
7884 if (linux_set_ifhwaddr(drv->global->ioctl_sock, bss->ifname, addr) < 0)
7885 {
7886 wpa_printf(MSG_DEBUG,
7887 "nl80211: failed to set_mac_addr for %s to " MACSTR,
7888 bss->ifname, MAC2STR(addr));
7889 if (linux_set_iface_flags(drv->global->ioctl_sock, bss->ifname,
7890 1) < 0) {
7891 wpa_printf(MSG_DEBUG,
7892 "nl80211: Could not restore interface UP after failed set_mac_addr");
7893 }
7894 return -1;
7895 }
7896
7897 wpa_printf(MSG_DEBUG, "nl80211: set_mac_addr for %s to " MACSTR,
7898 bss->ifname, MAC2STR(addr));
7899 drv->addr_changed = new_addr;
7900 os_memcpy(bss->addr, addr, ETH_ALEN);
7901
7902 if (linux_set_iface_flags(drv->global->ioctl_sock, bss->ifname, 1) < 0)
7903 {
7904 wpa_printf(MSG_DEBUG,
7905 "nl80211: Could not restore interface UP after set_mac_addr");
7906 }
7907
7908 return 0;
7909}
7910
7911
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08007912#ifdef CONFIG_MESH
7913
7914static int wpa_driver_nl80211_init_mesh(void *priv)
7915{
7916 if (wpa_driver_nl80211_set_mode(priv, NL80211_IFTYPE_MESH_POINT)) {
7917 wpa_printf(MSG_INFO,
7918 "nl80211: Failed to set interface into mesh mode");
7919 return -1;
7920 }
7921 return 0;
7922}
7923
7924
Dmitry Shmidtff787d52015-01-12 13:01:47 -08007925static int nl80211_put_mesh_id(struct nl_msg *msg, const u8 *mesh_id,
7926 size_t mesh_id_len)
7927{
7928 if (mesh_id) {
7929 wpa_hexdump_ascii(MSG_DEBUG, " * Mesh ID (SSID)",
7930 mesh_id, mesh_id_len);
7931 return nla_put(msg, NL80211_ATTR_MESH_ID, mesh_id_len, mesh_id);
7932 }
7933
7934 return 0;
7935}
7936
7937
Dmitry Shmidt7f656022015-02-25 14:36:37 -08007938static int nl80211_join_mesh(struct i802_bss *bss,
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08007939 struct wpa_driver_mesh_join_params *params)
7940{
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08007941 struct wpa_driver_nl80211_data *drv = bss->drv;
7942 struct nl_msg *msg;
7943 struct nlattr *container;
Dmitry Shmidt2f74e362015-01-21 13:19:05 -08007944 int ret = -1;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08007945
7946 wpa_printf(MSG_DEBUG, "nl80211: mesh join (ifindex=%d)", drv->ifindex);
7947 msg = nl80211_drv_msg(drv, 0, NL80211_CMD_JOIN_MESH);
Dmitry Shmidtff787d52015-01-12 13:01:47 -08007948 if (!msg ||
7949 nl80211_put_freq_params(msg, &params->freq) ||
7950 nl80211_put_basic_rates(msg, params->basic_rates) ||
7951 nl80211_put_mesh_id(msg, params->meshid, params->meshid_len) ||
7952 nl80211_put_beacon_int(msg, params->beacon_int))
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08007953 goto fail;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08007954
7955 wpa_printf(MSG_DEBUG, " * flags=%08X", params->flags);
7956
7957 container = nla_nest_start(msg, NL80211_ATTR_MESH_SETUP);
7958 if (!container)
7959 goto fail;
7960
7961 if (params->ies) {
7962 wpa_hexdump(MSG_DEBUG, " * IEs", params->ies, params->ie_len);
7963 if (nla_put(msg, NL80211_MESH_SETUP_IE, params->ie_len,
7964 params->ies))
7965 goto fail;
7966 }
7967 /* WPA_DRIVER_MESH_FLAG_OPEN_AUTH is treated as default by nl80211 */
7968 if (params->flags & WPA_DRIVER_MESH_FLAG_SAE_AUTH) {
7969 if (nla_put_u8(msg, NL80211_MESH_SETUP_AUTH_PROTOCOL, 0x1) ||
7970 nla_put_flag(msg, NL80211_MESH_SETUP_USERSPACE_AUTH))
7971 goto fail;
7972 }
7973 if ((params->flags & WPA_DRIVER_MESH_FLAG_AMPE) &&
7974 nla_put_flag(msg, NL80211_MESH_SETUP_USERSPACE_AMPE))
7975 goto fail;
7976 if ((params->flags & WPA_DRIVER_MESH_FLAG_USER_MPM) &&
7977 nla_put_flag(msg, NL80211_MESH_SETUP_USERSPACE_MPM))
7978 goto fail;
7979 nla_nest_end(msg, container);
7980
7981 container = nla_nest_start(msg, NL80211_ATTR_MESH_CONFIG);
7982 if (!container)
7983 goto fail;
7984
7985 if (!(params->conf.flags & WPA_DRIVER_MESH_CONF_FLAG_AUTO_PLINKS) &&
7986 nla_put_u32(msg, NL80211_MESHCONF_AUTO_OPEN_PLINKS, 0))
7987 goto fail;
7988 if ((params->conf.flags & WPA_DRIVER_MESH_FLAG_DRIVER_MPM) &&
7989 nla_put_u16(msg, NL80211_MESHCONF_MAX_PEER_LINKS,
7990 params->max_peer_links))
7991 goto fail;
Dmitry Shmidt2f74e362015-01-21 13:19:05 -08007992
7993 /*
7994 * Set NL80211_MESHCONF_PLINK_TIMEOUT even if user mpm is used because
7995 * the timer could disconnect stations even in that case.
Dmitry Shmidt2f74e362015-01-21 13:19:05 -08007996 */
Dmitry Shmidt7f656022015-02-25 14:36:37 -08007997 if (nla_put_u32(msg, NL80211_MESHCONF_PLINK_TIMEOUT,
7998 params->conf.peer_link_timeout)) {
Dmitry Shmidt2f74e362015-01-21 13:19:05 -08007999 wpa_printf(MSG_ERROR, "nl80211: Failed to set PLINK_TIMEOUT");
8000 goto fail;
8001 }
8002
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08008003 nla_nest_end(msg, container);
8004
8005 ret = send_and_recv_msgs(drv, msg, NULL, NULL);
8006 msg = NULL;
8007 if (ret) {
8008 wpa_printf(MSG_DEBUG, "nl80211: mesh join failed: ret=%d (%s)",
8009 ret, strerror(-ret));
8010 goto fail;
8011 }
8012 ret = 0;
Dmitry Shmidtff787d52015-01-12 13:01:47 -08008013 bss->freq = params->freq.freq;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08008014 wpa_printf(MSG_DEBUG, "nl80211: mesh join request send successfully");
8015
8016fail:
8017 nlmsg_free(msg);
8018 return ret;
8019}
8020
8021
Dmitry Shmidt7f656022015-02-25 14:36:37 -08008022static int
8023wpa_driver_nl80211_join_mesh(void *priv,
8024 struct wpa_driver_mesh_join_params *params)
8025{
8026 struct i802_bss *bss = priv;
8027 int ret, timeout;
8028
8029 timeout = params->conf.peer_link_timeout;
8030
8031 /* Disable kernel inactivity timer */
8032 if (params->flags & WPA_DRIVER_MESH_FLAG_USER_MPM)
8033 params->conf.peer_link_timeout = 0;
8034
8035 ret = nl80211_join_mesh(bss, params);
8036 if (ret == -EINVAL && params->conf.peer_link_timeout == 0) {
8037 wpa_printf(MSG_DEBUG,
8038 "nl80211: Mesh join retry for peer_link_timeout");
8039 /*
8040 * Old kernel does not support setting
8041 * NL80211_MESHCONF_PLINK_TIMEOUT to zero, so set 60 seconds
8042 * into future from peer_link_timeout.
8043 */
8044 params->conf.peer_link_timeout = timeout + 60;
8045 ret = nl80211_join_mesh(priv, params);
8046 }
8047
8048 params->conf.peer_link_timeout = timeout;
8049 return ret;
8050}
8051
8052
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08008053static int wpa_driver_nl80211_leave_mesh(void *priv)
8054{
8055 struct i802_bss *bss = priv;
8056 struct wpa_driver_nl80211_data *drv = bss->drv;
8057 struct nl_msg *msg;
8058 int ret;
8059
8060 wpa_printf(MSG_DEBUG, "nl80211: mesh leave (ifindex=%d)", drv->ifindex);
8061 msg = nl80211_drv_msg(drv, 0, NL80211_CMD_LEAVE_MESH);
8062 ret = send_and_recv_msgs(drv, msg, NULL, NULL);
8063 if (ret) {
8064 wpa_printf(MSG_DEBUG, "nl80211: mesh leave failed: ret=%d (%s)",
8065 ret, strerror(-ret));
8066 } else {
8067 wpa_printf(MSG_DEBUG,
8068 "nl80211: mesh leave request send successfully");
8069 }
8070
8071 if (wpa_driver_nl80211_set_mode(drv->first_bss,
8072 NL80211_IFTYPE_STATION)) {
8073 wpa_printf(MSG_INFO,
8074 "nl80211: Failed to set interface into station mode");
8075 }
8076 return ret;
8077}
8078
8079#endif /* CONFIG_MESH */
8080
8081
8082static int wpa_driver_br_add_ip_neigh(void *priv, u8 version,
8083 const u8 *ipaddr, int prefixlen,
8084 const u8 *addr)
8085{
8086#ifdef CONFIG_LIBNL3_ROUTE
8087 struct i802_bss *bss = priv;
8088 struct wpa_driver_nl80211_data *drv = bss->drv;
8089 struct rtnl_neigh *rn;
8090 struct nl_addr *nl_ipaddr = NULL;
8091 struct nl_addr *nl_lladdr = NULL;
8092 int family, addrsize;
8093 int res;
8094
8095 if (!ipaddr || prefixlen == 0 || !addr)
8096 return -EINVAL;
8097
8098 if (bss->br_ifindex == 0) {
8099 wpa_printf(MSG_DEBUG,
8100 "nl80211: bridge must be set before adding an ip neigh to it");
8101 return -1;
8102 }
8103
8104 if (!drv->rtnl_sk) {
8105 wpa_printf(MSG_DEBUG,
8106 "nl80211: nl_sock for NETLINK_ROUTE is not initialized");
8107 return -1;
8108 }
8109
8110 if (version == 4) {
8111 family = AF_INET;
8112 addrsize = 4;
8113 } else if (version == 6) {
8114 family = AF_INET6;
8115 addrsize = 16;
8116 } else {
8117 return -EINVAL;
8118 }
8119
8120 rn = rtnl_neigh_alloc();
8121 if (rn == NULL)
8122 return -ENOMEM;
8123
8124 /* set the destination ip address for neigh */
8125 nl_ipaddr = nl_addr_build(family, (void *) ipaddr, addrsize);
8126 if (nl_ipaddr == NULL) {
8127 wpa_printf(MSG_DEBUG, "nl80211: nl_ipaddr build failed");
8128 res = -ENOMEM;
8129 goto errout;
8130 }
8131 nl_addr_set_prefixlen(nl_ipaddr, prefixlen);
8132 res = rtnl_neigh_set_dst(rn, nl_ipaddr);
8133 if (res) {
8134 wpa_printf(MSG_DEBUG,
8135 "nl80211: neigh set destination addr failed");
8136 goto errout;
8137 }
8138
8139 /* set the corresponding lladdr for neigh */
8140 nl_lladdr = nl_addr_build(AF_BRIDGE, (u8 *) addr, ETH_ALEN);
8141 if (nl_lladdr == NULL) {
8142 wpa_printf(MSG_DEBUG, "nl80211: neigh set lladdr failed");
8143 res = -ENOMEM;
8144 goto errout;
8145 }
8146 rtnl_neigh_set_lladdr(rn, nl_lladdr);
8147
8148 rtnl_neigh_set_ifindex(rn, bss->br_ifindex);
8149 rtnl_neigh_set_state(rn, NUD_PERMANENT);
8150
8151 res = rtnl_neigh_add(drv->rtnl_sk, rn, NLM_F_CREATE);
8152 if (res) {
8153 wpa_printf(MSG_DEBUG,
8154 "nl80211: Adding bridge ip neigh failed: %s",
8155 strerror(errno));
8156 }
8157errout:
8158 if (nl_lladdr)
8159 nl_addr_put(nl_lladdr);
8160 if (nl_ipaddr)
8161 nl_addr_put(nl_ipaddr);
8162 if (rn)
8163 rtnl_neigh_put(rn);
8164 return res;
8165#else /* CONFIG_LIBNL3_ROUTE */
8166 return -1;
8167#endif /* CONFIG_LIBNL3_ROUTE */
8168}
8169
8170
8171static int wpa_driver_br_delete_ip_neigh(void *priv, u8 version,
8172 const u8 *ipaddr)
8173{
8174#ifdef CONFIG_LIBNL3_ROUTE
8175 struct i802_bss *bss = priv;
8176 struct wpa_driver_nl80211_data *drv = bss->drv;
8177 struct rtnl_neigh *rn;
8178 struct nl_addr *nl_ipaddr;
8179 int family, addrsize;
8180 int res;
8181
8182 if (!ipaddr)
8183 return -EINVAL;
8184
8185 if (version == 4) {
8186 family = AF_INET;
8187 addrsize = 4;
8188 } else if (version == 6) {
8189 family = AF_INET6;
8190 addrsize = 16;
8191 } else {
8192 return -EINVAL;
8193 }
8194
8195 if (bss->br_ifindex == 0) {
8196 wpa_printf(MSG_DEBUG,
8197 "nl80211: bridge must be set to delete an ip neigh");
8198 return -1;
8199 }
8200
8201 if (!drv->rtnl_sk) {
8202 wpa_printf(MSG_DEBUG,
8203 "nl80211: nl_sock for NETLINK_ROUTE is not initialized");
8204 return -1;
8205 }
8206
8207 rn = rtnl_neigh_alloc();
8208 if (rn == NULL)
8209 return -ENOMEM;
8210
8211 /* set the destination ip address for neigh */
8212 nl_ipaddr = nl_addr_build(family, (void *) ipaddr, addrsize);
8213 if (nl_ipaddr == NULL) {
8214 wpa_printf(MSG_DEBUG, "nl80211: nl_ipaddr build failed");
8215 res = -ENOMEM;
8216 goto errout;
8217 }
8218 res = rtnl_neigh_set_dst(rn, nl_ipaddr);
8219 if (res) {
8220 wpa_printf(MSG_DEBUG,
8221 "nl80211: neigh set destination addr failed");
8222 goto errout;
8223 }
8224
8225 rtnl_neigh_set_ifindex(rn, bss->br_ifindex);
8226
8227 res = rtnl_neigh_delete(drv->rtnl_sk, rn, 0);
8228 if (res) {
8229 wpa_printf(MSG_DEBUG,
8230 "nl80211: Deleting bridge ip neigh failed: %s",
8231 strerror(errno));
8232 }
8233errout:
8234 if (nl_ipaddr)
8235 nl_addr_put(nl_ipaddr);
8236 if (rn)
8237 rtnl_neigh_put(rn);
8238 return res;
8239#else /* CONFIG_LIBNL3_ROUTE */
8240 return -1;
8241#endif /* CONFIG_LIBNL3_ROUTE */
8242}
8243
8244
8245static int linux_write_system_file(const char *path, unsigned int val)
8246{
8247 char buf[50];
8248 int fd, len;
8249
8250 len = os_snprintf(buf, sizeof(buf), "%u\n", val);
8251 if (os_snprintf_error(sizeof(buf), len))
8252 return -1;
8253
8254 fd = open(path, O_WRONLY);
8255 if (fd < 0)
8256 return -1;
8257
8258 if (write(fd, buf, len) < 0) {
8259 wpa_printf(MSG_DEBUG,
8260 "nl80211: Failed to write Linux system file: %s with the value of %d",
8261 path, val);
8262 close(fd);
8263 return -1;
8264 }
8265 close(fd);
8266
8267 return 0;
8268}
8269
8270
8271static const char * drv_br_port_attr_str(enum drv_br_port_attr attr)
8272{
8273 switch (attr) {
8274 case DRV_BR_PORT_ATTR_PROXYARP:
Dmitry Shmidt4dd28dc2015-03-10 11:21:43 -07008275 return "proxyarp_wifi";
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08008276 case DRV_BR_PORT_ATTR_HAIRPIN_MODE:
8277 return "hairpin_mode";
8278 }
8279
8280 return NULL;
8281}
8282
8283
8284static int wpa_driver_br_port_set_attr(void *priv, enum drv_br_port_attr attr,
8285 unsigned int val)
8286{
8287 struct i802_bss *bss = priv;
8288 char path[128];
8289 const char *attr_txt;
8290
8291 attr_txt = drv_br_port_attr_str(attr);
8292 if (attr_txt == NULL)
8293 return -EINVAL;
8294
8295 os_snprintf(path, sizeof(path), "/sys/class/net/%s/brport/%s",
8296 bss->ifname, attr_txt);
8297
8298 if (linux_write_system_file(path, val))
8299 return -1;
8300
8301 return 0;
8302}
8303
8304
8305static const char * drv_br_net_param_str(enum drv_br_net_param param)
8306{
8307 switch (param) {
8308 case DRV_BR_NET_PARAM_GARP_ACCEPT:
8309 return "arp_accept";
Dmitry Shmidt83474442015-04-15 13:47:09 -07008310 default:
8311 return NULL;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08008312 }
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08008313}
8314
8315
8316static int wpa_driver_br_set_net_param(void *priv, enum drv_br_net_param param,
8317 unsigned int val)
8318{
8319 struct i802_bss *bss = priv;
8320 char path[128];
8321 const char *param_txt;
8322 int ip_version = 4;
8323
Dmitry Shmidt83474442015-04-15 13:47:09 -07008324 if (param == DRV_BR_MULTICAST_SNOOPING) {
8325 os_snprintf(path, sizeof(path),
8326 "/sys/devices/virtual/net/%s/bridge/multicast_snooping",
8327 bss->brname);
8328 goto set_val;
8329 }
8330
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08008331 param_txt = drv_br_net_param_str(param);
8332 if (param_txt == NULL)
8333 return -EINVAL;
8334
8335 switch (param) {
8336 case DRV_BR_NET_PARAM_GARP_ACCEPT:
8337 ip_version = 4;
8338 break;
8339 default:
8340 return -EINVAL;
8341 }
8342
8343 os_snprintf(path, sizeof(path), "/proc/sys/net/ipv%d/conf/%s/%s",
8344 ip_version, bss->brname, param_txt);
8345
Dmitry Shmidt83474442015-04-15 13:47:09 -07008346set_val:
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08008347 if (linux_write_system_file(path, val))
8348 return -1;
8349
8350 return 0;
8351}
8352
8353
8354static int hw_mode_to_qca_acs(enum hostapd_hw_mode hw_mode)
8355{
8356 switch (hw_mode) {
8357 case HOSTAPD_MODE_IEEE80211B:
8358 return QCA_ACS_MODE_IEEE80211B;
8359 case HOSTAPD_MODE_IEEE80211G:
8360 return QCA_ACS_MODE_IEEE80211G;
8361 case HOSTAPD_MODE_IEEE80211A:
8362 return QCA_ACS_MODE_IEEE80211A;
8363 case HOSTAPD_MODE_IEEE80211AD:
8364 return QCA_ACS_MODE_IEEE80211AD;
8365 default:
8366 return -1;
8367 }
8368}
8369
8370
8371static int wpa_driver_do_acs(void *priv, struct drv_acs_params *params)
8372{
8373 struct i802_bss *bss = priv;
8374 struct wpa_driver_nl80211_data *drv = bss->drv;
8375 struct nl_msg *msg;
8376 struct nlattr *data;
8377 int ret;
8378 int mode;
8379
8380 mode = hw_mode_to_qca_acs(params->hw_mode);
8381 if (mode < 0)
8382 return -1;
8383
8384 if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_VENDOR)) ||
8385 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
8386 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
8387 QCA_NL80211_VENDOR_SUBCMD_DO_ACS) ||
8388 !(data = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
8389 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_ACS_HW_MODE, mode) ||
8390 (params->ht_enabled &&
8391 nla_put_flag(msg, QCA_WLAN_VENDOR_ATTR_ACS_HT_ENABLED)) ||
8392 (params->ht40_enabled &&
Dmitry Shmidtdda10c22015-03-24 16:05:01 -07008393 nla_put_flag(msg, QCA_WLAN_VENDOR_ATTR_ACS_HT40_ENABLED)) ||
8394 (params->vht_enabled &&
8395 nla_put_flag(msg, QCA_WLAN_VENDOR_ATTR_ACS_VHT_ENABLED)) ||
8396 nla_put_u16(msg, QCA_WLAN_VENDOR_ATTR_ACS_CHWIDTH,
8397 params->ch_width) ||
8398 (params->ch_list_len &&
8399 nla_put(msg, QCA_WLAN_VENDOR_ATTR_ACS_CH_LIST, params->ch_list_len,
8400 params->ch_list))) {
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08008401 nlmsg_free(msg);
8402 return -ENOBUFS;
8403 }
8404 nla_nest_end(msg, data);
8405
Dmitry Shmidtdda10c22015-03-24 16:05:01 -07008406 wpa_printf(MSG_DEBUG,
8407 "nl80211: ACS Params: HW_MODE: %d HT: %d HT40: %d VHT: %d BW: %d CH_LIST_LEN: %u",
8408 params->hw_mode, params->ht_enabled, params->ht40_enabled,
8409 params->vht_enabled, params->ch_width, params->ch_list_len);
8410
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08008411 ret = send_and_recv_msgs(drv, msg, NULL, NULL);
8412 if (ret) {
8413 wpa_printf(MSG_DEBUG,
8414 "nl80211: Failed to invoke driver ACS function: %s",
8415 strerror(errno));
8416 }
8417 return ret;
8418}
8419
8420
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07008421const struct wpa_driver_ops wpa_driver_nl80211_ops = {
8422 .name = "nl80211",
8423 .desc = "Linux nl80211/cfg80211",
8424 .get_bssid = wpa_driver_nl80211_get_bssid,
8425 .get_ssid = wpa_driver_nl80211_get_ssid,
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08008426 .set_key = driver_nl80211_set_key,
8427 .scan2 = driver_nl80211_scan2,
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08008428 .sched_scan = wpa_driver_nl80211_sched_scan,
8429 .stop_sched_scan = wpa_driver_nl80211_stop_sched_scan,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07008430 .get_scan_results2 = wpa_driver_nl80211_get_scan_results,
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08008431 .deauthenticate = driver_nl80211_deauthenticate,
8432 .authenticate = driver_nl80211_authenticate,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07008433 .associate = wpa_driver_nl80211_associate,
8434 .global_init = nl80211_global_init,
8435 .global_deinit = nl80211_global_deinit,
8436 .init2 = wpa_driver_nl80211_init,
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08008437 .deinit = driver_nl80211_deinit,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07008438 .get_capa = wpa_driver_nl80211_get_capa,
8439 .set_operstate = wpa_driver_nl80211_set_operstate,
8440 .set_supp_port = wpa_driver_nl80211_set_supp_port,
8441 .set_country = wpa_driver_nl80211_set_country,
Dmitry Shmidtcce06662013-11-04 18:44:24 -08008442 .get_country = wpa_driver_nl80211_get_country,
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08008443 .set_ap = wpa_driver_nl80211_set_ap,
Dmitry Shmidt8bae4132013-06-06 11:25:10 -07008444 .set_acl = wpa_driver_nl80211_set_acl,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07008445 .if_add = wpa_driver_nl80211_if_add,
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08008446 .if_remove = driver_nl80211_if_remove,
8447 .send_mlme = driver_nl80211_send_mlme,
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08008448 .get_hw_feature_data = nl80211_get_hw_feature_data,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07008449 .sta_add = wpa_driver_nl80211_sta_add,
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08008450 .sta_remove = driver_nl80211_sta_remove,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07008451 .hapd_send_eapol = wpa_driver_nl80211_hapd_send_eapol,
8452 .sta_set_flags = wpa_driver_nl80211_sta_set_flags,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07008453 .hapd_init = i802_init,
8454 .hapd_deinit = i802_deinit,
Jouni Malinen75ecf522011-06-27 15:19:46 -07008455 .set_wds_sta = i802_set_wds_sta,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07008456 .get_seqnum = i802_get_seqnum,
8457 .flush = i802_flush,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07008458 .get_inact_sec = i802_get_inact_sec,
8459 .sta_clear_stats = i802_sta_clear_stats,
8460 .set_rts = i802_set_rts,
8461 .set_frag = i802_set_frag,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07008462 .set_tx_queue_params = i802_set_tx_queue_params,
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08008463 .set_sta_vlan = driver_nl80211_set_sta_vlan,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07008464 .sta_deauth = i802_sta_deauth,
8465 .sta_disassoc = i802_sta_disassoc,
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08008466 .read_sta_data = driver_nl80211_read_sta_data,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07008467 .set_freq = i802_set_freq,
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08008468 .send_action = driver_nl80211_send_action,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07008469 .send_action_cancel_wait = wpa_driver_nl80211_send_action_cancel_wait,
8470 .remain_on_channel = wpa_driver_nl80211_remain_on_channel,
8471 .cancel_remain_on_channel =
8472 wpa_driver_nl80211_cancel_remain_on_channel,
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08008473 .probe_req_report = driver_nl80211_probe_req_report,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07008474 .deinit_ap = wpa_driver_nl80211_deinit_ap,
Dmitry Shmidt04949592012-07-19 12:16:46 -07008475 .deinit_p2p_cli = wpa_driver_nl80211_deinit_p2p_cli,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07008476 .resume = wpa_driver_nl80211_resume,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07008477 .signal_monitor = nl80211_signal_monitor,
8478 .signal_poll = nl80211_signal_poll,
8479 .send_frame = nl80211_send_frame,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07008480 .set_param = nl80211_set_param,
8481 .get_radio_name = nl80211_get_radio_name,
Jouni Malinen75ecf522011-06-27 15:19:46 -07008482 .add_pmkid = nl80211_add_pmkid,
8483 .remove_pmkid = nl80211_remove_pmkid,
8484 .flush_pmkid = nl80211_flush_pmkid,
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08008485 .set_rekey_info = nl80211_set_rekey_info,
8486 .poll_client = nl80211_poll_client,
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08008487 .set_p2p_powersave = nl80211_set_p2p_powersave,
Dmitry Shmidtea69e842013-05-13 14:52:28 -07008488 .start_dfs_cac = nl80211_start_radar_detection,
8489 .stop_ap = wpa_driver_nl80211_stop_ap,
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08008490#ifdef CONFIG_TDLS
8491 .send_tdls_mgmt = nl80211_send_tdls_mgmt,
8492 .tdls_oper = nl80211_tdls_oper,
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08008493 .tdls_enable_channel_switch = nl80211_tdls_enable_channel_switch,
8494 .tdls_disable_channel_switch = nl80211_tdls_disable_channel_switch,
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08008495#endif /* CONFIG_TDLS */
Dmitry Shmidt700a1372013-03-15 14:14:44 -07008496 .update_ft_ies = wpa_driver_nl80211_update_ft_ies,
Dmitry Shmidt34af3062013-07-11 10:46:32 -07008497 .get_mac_addr = wpa_driver_nl80211_get_macaddr,
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -07008498 .get_survey = wpa_driver_nl80211_get_survey,
Dmitry Shmidt56052862013-10-04 10:23:25 -07008499 .status = wpa_driver_nl80211_status,
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08008500 .switch_channel = nl80211_switch_channel,
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08008501#ifdef ANDROID_P2P
Dmitry Shmidt6e933c12011-09-27 12:29:26 -07008502 .set_noa = wpa_driver_set_p2p_noa,
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08008503 .get_noa = wpa_driver_get_p2p_noa,
Dmitry Shmidt6e933c12011-09-27 12:29:26 -07008504 .set_ap_wps_ie = wpa_driver_set_ap_wps_p2p_ie,
Dmitry Shmidt292b0c32013-11-22 12:54:42 -08008505#endif /* ANDROID_P2P */
Dmitry Shmidt738a26e2011-07-07 14:22:14 -07008506#ifdef ANDROID
8507 .driver_cmd = wpa_driver_nl80211_driver_cmd,
Dmitry Shmidt292b0c32013-11-22 12:54:42 -08008508#endif /* ANDROID */
Dmitry Shmidta38abf92014-03-06 13:38:44 -08008509 .vendor_cmd = nl80211_vendor_cmd,
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08008510 .set_qos_map = nl80211_set_qos_map,
Dmitry Shmidtb58836e2014-04-29 14:35:56 -07008511 .set_wowlan = nl80211_set_wowlan,
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07008512 .roaming = nl80211_roaming,
8513 .set_mac_addr = nl80211_set_mac_addr,
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08008514#ifdef CONFIG_MESH
8515 .init_mesh = wpa_driver_nl80211_init_mesh,
8516 .join_mesh = wpa_driver_nl80211_join_mesh,
8517 .leave_mesh = wpa_driver_nl80211_leave_mesh,
8518#endif /* CONFIG_MESH */
8519 .br_add_ip_neigh = wpa_driver_br_add_ip_neigh,
8520 .br_delete_ip_neigh = wpa_driver_br_delete_ip_neigh,
8521 .br_port_set_attr = wpa_driver_br_port_set_attr,
8522 .br_set_net_param = wpa_driver_br_set_net_param,
8523 .add_tx_ts = nl80211_add_ts,
8524 .del_tx_ts = nl80211_del_ts,
8525 .do_acs = wpa_driver_do_acs,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07008526};