blob: 2dce242a3170ff34a08a4e68e460f50f0c86a832 [file] [log] [blame]
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001/*
2 * Driver interaction with Linux nl80211/cfg80211
Dmitry Shmidt807291d2015-01-27 13:40:23 -08003 * Copyright (c) 2002-2015, Jouni Malinen <j@w1.fi>
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004 * Copyright (c) 2003-2004, Instant802 Networks, Inc.
5 * Copyright (c) 2005-2006, Devicescape Software, Inc.
6 * Copyright (c) 2007, Johannes Berg <johannes@sipsolutions.net>
7 * Copyright (c) 2009-2010, Atheros Communications
8 *
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08009 * This software may be distributed under the terms of the BSD license.
10 * See README for more details.
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070011 */
12
13#include "includes.h"
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070014#include <sys/types.h>
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070015#include <fcntl.h>
16#include <net/if.h>
17#include <netlink/genl/genl.h>
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070018#include <netlink/genl/ctrl.h>
Dmitry Shmidt661b4f72014-09-29 14:58:27 -070019#ifdef CONFIG_LIBNL3_ROUTE
20#include <netlink/route/neighbour.h>
21#endif /* CONFIG_LIBNL3_ROUTE */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070022#include <linux/rtnetlink.h>
23#include <netpacket/packet.h>
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -080024#include <linux/errqueue.h>
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070025
26#include "common.h"
27#include "eloop.h"
Dmitry Shmidtcf32e602014-01-28 10:57:39 -080028#include "common/qca-vendor.h"
Dmitry Shmidt7832adb2014-04-29 10:53:02 -070029#include "common/qca-vendor-attr.h"
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070030#include "common/ieee802_11_defs.h"
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -080031#include "common/ieee802_11_common.h"
32#include "l2_packet/l2_packet.h"
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070033#include "netlink.h"
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080034#include "linux_defines.h"
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070035#include "linux_ioctl.h"
36#include "radiotap.h"
37#include "radiotap_iter.h"
38#include "rfkill.h"
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080039#include "driver_nl80211.h"
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -080040
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -080041
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080042#ifndef CONFIG_LIBNL20
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070043/*
44 * libnl 1.1 has a bug, it tries to allocate socket numbers densely
45 * but when you free a socket again it will mess up its bitmap and
46 * and use the wrong number the next time it needs a socket ID.
47 * Therefore, we wrap the handle alloc/destroy and add our own pid
48 * accounting.
49 */
50static uint32_t port_bitmap[32] = { 0 };
51
52static struct nl_handle *nl80211_handle_alloc(void *cb)
53{
54 struct nl_handle *handle;
55 uint32_t pid = getpid() & 0x3FFFFF;
56 int i;
57
58 handle = nl_handle_alloc_cb(cb);
59
60 for (i = 0; i < 1024; i++) {
61 if (port_bitmap[i / 32] & (1 << (i % 32)))
62 continue;
63 port_bitmap[i / 32] |= 1 << (i % 32);
64 pid += i << 22;
65 break;
66 }
67
68 nl_socket_set_local_port(handle, pid);
69
70 return handle;
71}
72
73static void nl80211_handle_destroy(struct nl_handle *handle)
74{
75 uint32_t port = nl_socket_get_local_port(handle);
76
77 port >>= 22;
78 port_bitmap[port / 32] &= ~(1 << (port % 32));
79
80 nl_handle_destroy(handle);
81}
82#endif /* CONFIG_LIBNL20 */
83
84
Dmitry Shmidt54605472013-11-08 11:10:19 -080085#ifdef ANDROID
86/* system/core/libnl_2 does not include nl_socket_set_nonblocking() */
Dmitry Shmidt54605472013-11-08 11:10:19 -080087#undef nl_socket_set_nonblocking
88#define nl_socket_set_nonblocking(h) android_nl_socket_set_nonblocking(h)
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080089
90#define genl_ctrl_resolve android_genl_ctrl_resolve
Dmitry Shmidt54605472013-11-08 11:10:19 -080091#endif /* ANDROID */
92
93
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -080094static struct nl_handle * nl_create_handle(struct nl_cb *cb, const char *dbg)
95{
96 struct nl_handle *handle;
97
98 handle = nl80211_handle_alloc(cb);
99 if (handle == NULL) {
100 wpa_printf(MSG_ERROR, "nl80211: Failed to allocate netlink "
101 "callbacks (%s)", dbg);
102 return NULL;
103 }
104
105 if (genl_connect(handle)) {
106 wpa_printf(MSG_ERROR, "nl80211: Failed to connect to generic "
107 "netlink (%s)", dbg);
108 nl80211_handle_destroy(handle);
109 return NULL;
110 }
111
112 return handle;
113}
114
115
116static void nl_destroy_handles(struct nl_handle **handle)
117{
118 if (*handle == NULL)
119 return;
120 nl80211_handle_destroy(*handle);
121 *handle = NULL;
122}
123
124
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -0700125#if __WORDSIZE == 64
126#define ELOOP_SOCKET_INVALID (intptr_t) 0x8888888888888889ULL
127#else
128#define ELOOP_SOCKET_INVALID (intptr_t) 0x88888889ULL
129#endif
130
131static void nl80211_register_eloop_read(struct nl_handle **handle,
132 eloop_sock_handler handler,
133 void *eloop_data)
134{
Dmitry Shmidt807291d2015-01-27 13:40:23 -0800135#ifdef CONFIG_LIBNL20
136 /*
137 * libnl uses a pretty small buffer (32 kB that gets converted to 64 kB)
138 * by default. It is possible to hit that limit in some cases where
139 * operations are blocked, e.g., with a burst of Deauthentication frames
140 * to hostapd and STA entry deletion. Try to increase the buffer to make
141 * this less likely to occur.
142 */
143 if (nl_socket_set_buffer_size(*handle, 262144, 0) < 0) {
144 wpa_printf(MSG_DEBUG,
145 "nl80211: Could not set nl_socket RX buffer size: %s",
146 strerror(errno));
147 /* continue anyway with the default (smaller) buffer */
148 }
149#endif /* CONFIG_LIBNL20 */
150
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -0700151 nl_socket_set_nonblocking(*handle);
152 eloop_register_read_sock(nl_socket_get_fd(*handle), handler,
153 eloop_data, *handle);
154 *handle = (void *) (((intptr_t) *handle) ^ ELOOP_SOCKET_INVALID);
155}
156
157
158static void nl80211_destroy_eloop_handle(struct nl_handle **handle)
159{
160 *handle = (void *) (((intptr_t) *handle) ^ ELOOP_SOCKET_INVALID);
161 eloop_unregister_read_sock(nl_socket_get_fd(*handle));
162 nl_destroy_handles(handle);
163}
164
165
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800166static void nl80211_global_deinit(void *priv);
Dmitry Shmidt7f656022015-02-25 14:36:37 -0800167static void nl80211_check_global(struct nl80211_global *global);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800168
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -0800169static void wpa_driver_nl80211_deinit(struct i802_bss *bss);
Dmitry Shmidt9ead16e2014-10-07 13:15:23 -0700170static int wpa_driver_nl80211_set_mode_ibss(struct i802_bss *bss,
171 struct hostapd_freq_params *freq);
Dmitry Shmidtd30ac602014-06-30 09:54:22 -0700172
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700173static int
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -0800174wpa_driver_nl80211_finish_drv_init(struct wpa_driver_nl80211_data *drv,
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800175 const u8 *set_addr, int first,
176 const char *driver_params);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800177static int nl80211_send_frame_cmd(struct i802_bss *bss,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700178 unsigned int freq, unsigned int wait,
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800179 const u8 *buf, size_t buf_len, u64 *cookie,
180 int no_cck, int no_ack, int offchanok);
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -0800181static int wpa_driver_nl80211_probe_req_report(struct i802_bss *bss,
182 int report);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700183
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700184static void add_ifidx(struct wpa_driver_nl80211_data *drv, int ifidx);
185static void del_ifidx(struct wpa_driver_nl80211_data *drv, int ifidx);
186static int have_ifidx(struct wpa_driver_nl80211_data *drv, int ifidx);
Dmitry Shmidt738a26e2011-07-07 14:22:14 -0700187
Dmitry Shmidt7832adb2014-04-29 10:53:02 -0700188static int nl80211_set_channel(struct i802_bss *bss,
189 struct hostapd_freq_params *freq, int set_chan);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700190static int nl80211_disable_11b_rates(struct wpa_driver_nl80211_data *drv,
191 int ifindex, int disabled);
192
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800193static int nl80211_leave_ibss(struct wpa_driver_nl80211_data *drv,
194 int reset_mode);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800195
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -0700196static int i802_set_iface_flags(struct i802_bss *bss, int up);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800197static int nl80211_set_param(void *priv, const char *param);
Dmitry Shmidt34af3062013-07-11 10:46:32 -0700198
199
Dmitry Shmidt04f534e2013-12-09 15:50:16 -0800200/* Converts nl80211_chan_width to a common format */
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800201enum chan_width convert2width(int width)
Dmitry Shmidt04f534e2013-12-09 15:50:16 -0800202{
203 switch (width) {
204 case NL80211_CHAN_WIDTH_20_NOHT:
205 return CHAN_WIDTH_20_NOHT;
206 case NL80211_CHAN_WIDTH_20:
207 return CHAN_WIDTH_20;
208 case NL80211_CHAN_WIDTH_40:
209 return CHAN_WIDTH_40;
210 case NL80211_CHAN_WIDTH_80:
211 return CHAN_WIDTH_80;
212 case NL80211_CHAN_WIDTH_80P80:
213 return CHAN_WIDTH_80P80;
214 case NL80211_CHAN_WIDTH_160:
215 return CHAN_WIDTH_160;
216 }
217 return CHAN_WIDTH_UNKNOWN;
218}
219
220
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800221int is_ap_interface(enum nl80211_iftype nlmode)
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800222{
Dmitry Shmidt7832adb2014-04-29 10:53:02 -0700223 return nlmode == NL80211_IFTYPE_AP ||
224 nlmode == NL80211_IFTYPE_P2P_GO;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800225}
226
227
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800228int is_sta_interface(enum nl80211_iftype nlmode)
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800229{
Dmitry Shmidt7832adb2014-04-29 10:53:02 -0700230 return nlmode == NL80211_IFTYPE_STATION ||
231 nlmode == NL80211_IFTYPE_P2P_CLIENT;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800232}
233
234
Dmitry Shmidt34af3062013-07-11 10:46:32 -0700235static int is_p2p_net_interface(enum nl80211_iftype nlmode)
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800236{
Dmitry Shmidt7832adb2014-04-29 10:53:02 -0700237 return nlmode == NL80211_IFTYPE_P2P_CLIENT ||
238 nlmode == NL80211_IFTYPE_P2P_GO;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800239}
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700240
241
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800242struct i802_bss * get_bss_ifindex(struct wpa_driver_nl80211_data *drv,
243 int ifindex)
Dmitry Shmidt9ead16e2014-10-07 13:15:23 -0700244{
245 struct i802_bss *bss;
246
247 for (bss = drv->first_bss; bss; bss = bss->next) {
248 if (bss->ifindex == ifindex)
249 return bss;
250 }
251
252 return NULL;
253}
254
255
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800256static int is_mesh_interface(enum nl80211_iftype nlmode)
257{
258 return nlmode == NL80211_IFTYPE_MESH_POINT;
259}
260
261
262void nl80211_mark_disconnected(struct wpa_driver_nl80211_data *drv)
Dmitry Shmidt8bae4132013-06-06 11:25:10 -0700263{
264 if (drv->associated)
265 os_memcpy(drv->prev_bssid, drv->bssid, ETH_ALEN);
266 drv->associated = 0;
267 os_memset(drv->bssid, 0, ETH_ALEN);
268}
269
270
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700271/* nl80211 code */
272static int ack_handler(struct nl_msg *msg, void *arg)
273{
274 int *err = arg;
275 *err = 0;
276 return NL_STOP;
277}
278
279static int finish_handler(struct nl_msg *msg, void *arg)
280{
281 int *ret = arg;
282 *ret = 0;
283 return NL_SKIP;
284}
285
286static int error_handler(struct sockaddr_nl *nla, struct nlmsgerr *err,
287 void *arg)
288{
289 int *ret = arg;
290 *ret = err->error;
291 return NL_SKIP;
292}
293
294
295static int no_seq_check(struct nl_msg *msg, void *arg)
296{
297 return NL_OK;
298}
299
300
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800301static void nl80211_nlmsg_clear(struct nl_msg *msg)
302{
303 /*
304 * Clear nlmsg data, e.g., to make sure key material is not left in
305 * heap memory for unnecessarily long time.
306 */
307 if (msg) {
308 struct nlmsghdr *hdr = nlmsg_hdr(msg);
309 void *data = nlmsg_data(hdr);
310 /*
311 * This would use nlmsg_datalen() or the older nlmsg_len() if
312 * only libnl were to maintain a stable API.. Neither will work
313 * with all released versions, so just calculate the length
314 * here.
315 */
316 int len = hdr->nlmsg_len - NLMSG_HDRLEN;
317
318 os_memset(data, 0, len);
319 }
320}
321
322
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800323static int send_and_recv(struct nl80211_global *global,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700324 struct nl_handle *nl_handle, struct nl_msg *msg,
325 int (*valid_handler)(struct nl_msg *, void *),
326 void *valid_data)
327{
328 struct nl_cb *cb;
329 int err = -ENOMEM;
330
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800331 if (!msg)
332 return -ENOMEM;
333
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800334 cb = nl_cb_clone(global->nl_cb);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700335 if (!cb)
336 goto out;
337
338 err = nl_send_auto_complete(nl_handle, msg);
339 if (err < 0)
340 goto out;
341
342 err = 1;
343
344 nl_cb_err(cb, NL_CB_CUSTOM, error_handler, &err);
345 nl_cb_set(cb, NL_CB_FINISH, NL_CB_CUSTOM, finish_handler, &err);
346 nl_cb_set(cb, NL_CB_ACK, NL_CB_CUSTOM, ack_handler, &err);
347
348 if (valid_handler)
349 nl_cb_set(cb, NL_CB_VALID, NL_CB_CUSTOM,
350 valid_handler, valid_data);
351
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -0700352 while (err > 0) {
353 int res = nl_recvmsgs(nl_handle, cb);
Dmitry Shmidt71757432014-06-02 13:50:35 -0700354 if (res < 0) {
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -0700355 wpa_printf(MSG_INFO,
356 "nl80211: %s->nl_recvmsgs failed: %d",
357 __func__, res);
358 }
359 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700360 out:
361 nl_cb_put(cb);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800362 if (!valid_handler && valid_data == (void *) -1)
363 nl80211_nlmsg_clear(msg);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700364 nlmsg_free(msg);
365 return err;
366}
367
368
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800369int send_and_recv_msgs(struct wpa_driver_nl80211_data *drv,
370 struct nl_msg *msg,
371 int (*valid_handler)(struct nl_msg *, void *),
372 void *valid_data)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700373{
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800374 return send_and_recv(drv->global, drv->global->nl, msg,
375 valid_handler, valid_data);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700376}
377
378
379struct family_data {
380 const char *group;
381 int id;
382};
383
384
385static int family_handler(struct nl_msg *msg, void *arg)
386{
387 struct family_data *res = arg;
388 struct nlattr *tb[CTRL_ATTR_MAX + 1];
389 struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg));
390 struct nlattr *mcgrp;
391 int i;
392
393 nla_parse(tb, CTRL_ATTR_MAX, genlmsg_attrdata(gnlh, 0),
394 genlmsg_attrlen(gnlh, 0), NULL);
395 if (!tb[CTRL_ATTR_MCAST_GROUPS])
396 return NL_SKIP;
397
398 nla_for_each_nested(mcgrp, tb[CTRL_ATTR_MCAST_GROUPS], i) {
399 struct nlattr *tb2[CTRL_ATTR_MCAST_GRP_MAX + 1];
400 nla_parse(tb2, CTRL_ATTR_MCAST_GRP_MAX, nla_data(mcgrp),
401 nla_len(mcgrp), NULL);
402 if (!tb2[CTRL_ATTR_MCAST_GRP_NAME] ||
403 !tb2[CTRL_ATTR_MCAST_GRP_ID] ||
404 os_strncmp(nla_data(tb2[CTRL_ATTR_MCAST_GRP_NAME]),
405 res->group,
406 nla_len(tb2[CTRL_ATTR_MCAST_GRP_NAME])) != 0)
407 continue;
408 res->id = nla_get_u32(tb2[CTRL_ATTR_MCAST_GRP_ID]);
409 break;
410 };
411
412 return NL_SKIP;
413}
414
415
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800416static int nl_get_multicast_id(struct nl80211_global *global,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700417 const char *family, const char *group)
418{
419 struct nl_msg *msg;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800420 int ret;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700421 struct family_data res = { group, -ENOENT };
422
423 msg = nlmsg_alloc();
424 if (!msg)
425 return -ENOMEM;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800426 if (!genlmsg_put(msg, 0, 0, genl_ctrl_resolve(global->nl, "nlctrl"),
427 0, 0, CTRL_CMD_GETFAMILY, 0) ||
428 nla_put_string(msg, CTRL_ATTR_FAMILY_NAME, family)) {
429 nlmsg_free(msg);
430 return -1;
431 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700432
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800433 ret = send_and_recv(global, global->nl, msg, family_handler, &res);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700434 if (ret == 0)
435 ret = res.id;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700436 return ret;
437}
438
439
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800440void * nl80211_cmd(struct wpa_driver_nl80211_data *drv,
441 struct nl_msg *msg, int flags, uint8_t cmd)
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800442{
443 return genlmsg_put(msg, 0, 0, drv->global->nl80211_id,
444 0, flags, cmd, 0);
445}
446
447
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800448static int nl80211_set_iface_id(struct nl_msg *msg, struct i802_bss *bss)
449{
450 if (bss->wdev_id_set)
451 return nla_put_u64(msg, NL80211_ATTR_WDEV, bss->wdev_id);
452 return nla_put_u32(msg, NL80211_ATTR_IFINDEX, bss->ifindex);
453}
454
455
456struct nl_msg * nl80211_cmd_msg(struct i802_bss *bss, int flags, uint8_t cmd)
457{
458 struct nl_msg *msg;
459
460 msg = nlmsg_alloc();
461 if (!msg)
462 return NULL;
463
464 if (!nl80211_cmd(bss->drv, msg, flags, cmd) ||
465 nl80211_set_iface_id(msg, bss) < 0) {
466 nlmsg_free(msg);
467 return NULL;
468 }
469
470 return msg;
471}
472
473
474static struct nl_msg *
475nl80211_ifindex_msg(struct wpa_driver_nl80211_data *drv, int ifindex,
476 int flags, uint8_t cmd)
477{
478 struct nl_msg *msg;
479
480 msg = nlmsg_alloc();
481 if (!msg)
482 return NULL;
483
484 if (!nl80211_cmd(drv, msg, flags, cmd) ||
485 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex)) {
486 nlmsg_free(msg);
487 return NULL;
488 }
489
490 return msg;
491}
492
493
494struct nl_msg * nl80211_drv_msg(struct wpa_driver_nl80211_data *drv, int flags,
495 uint8_t cmd)
496{
497 return nl80211_ifindex_msg(drv, drv->ifindex, flags, cmd);
498}
499
500
501struct nl_msg * nl80211_bss_msg(struct i802_bss *bss, int flags, uint8_t cmd)
502{
503 return nl80211_ifindex_msg(bss->drv, bss->ifindex, flags, cmd);
504}
505
506
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800507struct wiphy_idx_data {
508 int wiphy_idx;
Dmitry Shmidt34af3062013-07-11 10:46:32 -0700509 enum nl80211_iftype nlmode;
510 u8 *macaddr;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800511};
512
513
514static int netdev_info_handler(struct nl_msg *msg, void *arg)
515{
516 struct nlattr *tb[NL80211_ATTR_MAX + 1];
517 struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg));
518 struct wiphy_idx_data *info = arg;
519
520 nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0),
521 genlmsg_attrlen(gnlh, 0), NULL);
522
523 if (tb[NL80211_ATTR_WIPHY])
524 info->wiphy_idx = nla_get_u32(tb[NL80211_ATTR_WIPHY]);
525
Dmitry Shmidt34af3062013-07-11 10:46:32 -0700526 if (tb[NL80211_ATTR_IFTYPE])
527 info->nlmode = nla_get_u32(tb[NL80211_ATTR_IFTYPE]);
528
529 if (tb[NL80211_ATTR_MAC] && info->macaddr)
530 os_memcpy(info->macaddr, nla_data(tb[NL80211_ATTR_MAC]),
531 ETH_ALEN);
532
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800533 return NL_SKIP;
534}
535
536
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800537int nl80211_get_wiphy_index(struct i802_bss *bss)
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800538{
539 struct nl_msg *msg;
540 struct wiphy_idx_data data = {
541 .wiphy_idx = -1,
Dmitry Shmidt34af3062013-07-11 10:46:32 -0700542 .macaddr = NULL,
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800543 };
544
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800545 if (!(msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_GET_INTERFACE)))
546 return -1;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800547
548 if (send_and_recv_msgs(bss->drv, msg, netdev_info_handler, &data) == 0)
549 return data.wiphy_idx;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800550 return -1;
551}
552
553
Dmitry Shmidt34af3062013-07-11 10:46:32 -0700554static enum nl80211_iftype nl80211_get_ifmode(struct i802_bss *bss)
555{
556 struct nl_msg *msg;
557 struct wiphy_idx_data data = {
558 .nlmode = NL80211_IFTYPE_UNSPECIFIED,
559 .macaddr = NULL,
560 };
561
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800562 if (!(msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_GET_INTERFACE)))
563 return NL80211_IFTYPE_UNSPECIFIED;
Dmitry Shmidt34af3062013-07-11 10:46:32 -0700564
565 if (send_and_recv_msgs(bss->drv, msg, netdev_info_handler, &data) == 0)
566 return data.nlmode;
Dmitry Shmidt34af3062013-07-11 10:46:32 -0700567 return NL80211_IFTYPE_UNSPECIFIED;
568}
569
570
Dmitry Shmidt34af3062013-07-11 10:46:32 -0700571static int nl80211_get_macaddr(struct i802_bss *bss)
572{
573 struct nl_msg *msg;
574 struct wiphy_idx_data data = {
575 .macaddr = bss->addr,
576 };
577
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800578 if (!(msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_GET_INTERFACE)))
579 return -1;
Dmitry Shmidt34af3062013-07-11 10:46:32 -0700580
581 return send_and_recv_msgs(bss->drv, msg, netdev_info_handler, &data);
Dmitry Shmidt34af3062013-07-11 10:46:32 -0700582}
Dmitry Shmidt34af3062013-07-11 10:46:32 -0700583
584
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800585static int nl80211_register_beacons(struct wpa_driver_nl80211_data *drv,
586 struct nl80211_wiphy_data *w)
587{
588 struct nl_msg *msg;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800589 int ret;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800590
591 msg = nlmsg_alloc();
592 if (!msg)
593 return -1;
594
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800595 if (!nl80211_cmd(drv, msg, 0, NL80211_CMD_REGISTER_BEACONS) ||
596 nla_put_u32(msg, NL80211_ATTR_WIPHY, w->wiphy_idx)) {
597 nlmsg_free(msg);
598 return -1;
599 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800600
601 ret = send_and_recv(drv->global, w->nl_beacons, msg, NULL, NULL);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800602 if (ret) {
603 wpa_printf(MSG_DEBUG, "nl80211: Register beacons command "
604 "failed: ret=%d (%s)",
605 ret, strerror(-ret));
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800606 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800607 return ret;
608}
609
610
611static void nl80211_recv_beacons(int sock, void *eloop_ctx, void *handle)
612{
613 struct nl80211_wiphy_data *w = eloop_ctx;
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -0700614 int res;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800615
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -0800616 wpa_printf(MSG_EXCESSIVE, "nl80211: Beacon event message available");
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800617
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -0700618 res = nl_recvmsgs(handle, w->nl_cb);
Dmitry Shmidt71757432014-06-02 13:50:35 -0700619 if (res < 0) {
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -0700620 wpa_printf(MSG_INFO, "nl80211: %s->nl_recvmsgs failed: %d",
621 __func__, res);
622 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800623}
624
625
626static int process_beacon_event(struct nl_msg *msg, void *arg)
627{
628 struct nl80211_wiphy_data *w = arg;
629 struct wpa_driver_nl80211_data *drv;
630 struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg));
631 struct nlattr *tb[NL80211_ATTR_MAX + 1];
632 union wpa_event_data event;
633
634 nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0),
635 genlmsg_attrlen(gnlh, 0), NULL);
636
637 if (gnlh->cmd != NL80211_CMD_FRAME) {
638 wpa_printf(MSG_DEBUG, "nl80211: Unexpected beacon event? (%d)",
639 gnlh->cmd);
640 return NL_SKIP;
641 }
642
643 if (!tb[NL80211_ATTR_FRAME])
644 return NL_SKIP;
645
646 dl_list_for_each(drv, &w->drvs, struct wpa_driver_nl80211_data,
647 wiphy_list) {
648 os_memset(&event, 0, sizeof(event));
649 event.rx_mgmt.frame = nla_data(tb[NL80211_ATTR_FRAME]);
650 event.rx_mgmt.frame_len = nla_len(tb[NL80211_ATTR_FRAME]);
651 wpa_supplicant_event(drv->ctx, EVENT_RX_MGMT, &event);
652 }
653
654 return NL_SKIP;
655}
656
657
658static struct nl80211_wiphy_data *
659nl80211_get_wiphy_data_ap(struct i802_bss *bss)
660{
661 static DEFINE_DL_LIST(nl80211_wiphys);
662 struct nl80211_wiphy_data *w;
663 int wiphy_idx, found = 0;
664 struct i802_bss *tmp_bss;
665
666 if (bss->wiphy_data != NULL)
667 return bss->wiphy_data;
668
669 wiphy_idx = nl80211_get_wiphy_index(bss);
670
671 dl_list_for_each(w, &nl80211_wiphys, struct nl80211_wiphy_data, list) {
672 if (w->wiphy_idx == wiphy_idx)
673 goto add;
674 }
675
676 /* alloc new one */
677 w = os_zalloc(sizeof(*w));
678 if (w == NULL)
679 return NULL;
680 w->wiphy_idx = wiphy_idx;
681 dl_list_init(&w->bsss);
682 dl_list_init(&w->drvs);
683
684 w->nl_cb = nl_cb_alloc(NL_CB_DEFAULT);
685 if (!w->nl_cb) {
686 os_free(w);
687 return NULL;
688 }
689 nl_cb_set(w->nl_cb, NL_CB_SEQ_CHECK, NL_CB_CUSTOM, no_seq_check, NULL);
690 nl_cb_set(w->nl_cb, NL_CB_VALID, NL_CB_CUSTOM, process_beacon_event,
691 w);
692
693 w->nl_beacons = nl_create_handle(bss->drv->global->nl_cb,
694 "wiphy beacons");
695 if (w->nl_beacons == NULL) {
696 os_free(w);
697 return NULL;
698 }
699
700 if (nl80211_register_beacons(bss->drv, w)) {
701 nl_destroy_handles(&w->nl_beacons);
702 os_free(w);
703 return NULL;
704 }
705
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -0700706 nl80211_register_eloop_read(&w->nl_beacons, nl80211_recv_beacons, w);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800707
708 dl_list_add(&nl80211_wiphys, &w->list);
709
710add:
711 /* drv entry for this bss already there? */
712 dl_list_for_each(tmp_bss, &w->bsss, struct i802_bss, wiphy_list) {
713 if (tmp_bss->drv == bss->drv) {
714 found = 1;
715 break;
716 }
717 }
718 /* if not add it */
719 if (!found)
720 dl_list_add(&w->drvs, &bss->drv->wiphy_list);
721
722 dl_list_add(&w->bsss, &bss->wiphy_list);
723 bss->wiphy_data = w;
724 return w;
725}
726
727
728static void nl80211_put_wiphy_data_ap(struct i802_bss *bss)
729{
730 struct nl80211_wiphy_data *w = bss->wiphy_data;
731 struct i802_bss *tmp_bss;
732 int found = 0;
733
734 if (w == NULL)
735 return;
736 bss->wiphy_data = NULL;
737 dl_list_del(&bss->wiphy_list);
738
739 /* still any for this drv present? */
740 dl_list_for_each(tmp_bss, &w->bsss, struct i802_bss, wiphy_list) {
741 if (tmp_bss->drv == bss->drv) {
742 found = 1;
743 break;
744 }
745 }
746 /* if not remove it */
747 if (!found)
748 dl_list_del(&bss->drv->wiphy_list);
749
750 if (!dl_list_empty(&w->bsss))
751 return;
752
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -0700753 nl80211_destroy_eloop_handle(&w->nl_beacons);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800754
755 nl_cb_put(w->nl_cb);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800756 dl_list_del(&w->list);
757 os_free(w);
758}
759
760
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700761static int wpa_driver_nl80211_get_bssid(void *priv, u8 *bssid)
762{
763 struct i802_bss *bss = priv;
764 struct wpa_driver_nl80211_data *drv = bss->drv;
765 if (!drv->associated)
766 return -1;
767 os_memcpy(bssid, drv->bssid, ETH_ALEN);
768 return 0;
769}
770
771
772static int wpa_driver_nl80211_get_ssid(void *priv, u8 *ssid)
773{
774 struct i802_bss *bss = priv;
775 struct wpa_driver_nl80211_data *drv = bss->drv;
776 if (!drv->associated)
777 return -1;
778 os_memcpy(ssid, drv->ssid, drv->ssid_len);
779 return drv->ssid_len;
780}
781
782
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800783static void wpa_driver_nl80211_event_newlink(
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800784 struct wpa_driver_nl80211_data *drv, const char *ifname)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700785{
786 union wpa_event_data event;
787
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800788 if (os_strcmp(drv->first_bss->ifname, ifname) == 0) {
789 if (if_nametoindex(drv->first_bss->ifname) == 0) {
790 wpa_printf(MSG_DEBUG, "nl80211: Interface %s does not exist - ignore RTM_NEWLINK",
791 drv->first_bss->ifname);
792 return;
Dmitry Shmidt04949592012-07-19 12:16:46 -0700793 }
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800794 if (!drv->if_removed)
795 return;
796 wpa_printf(MSG_DEBUG, "nl80211: Mark if_removed=0 for %s based on RTM_NEWLINK event",
797 drv->first_bss->ifname);
798 drv->if_removed = 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700799 }
800
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800801 os_memset(&event, 0, sizeof(event));
802 os_strlcpy(event.interface_status.ifname, ifname,
803 sizeof(event.interface_status.ifname));
804 event.interface_status.ievent = EVENT_INTERFACE_ADDED;
805 wpa_supplicant_event(drv->ctx, EVENT_INTERFACE_STATUS, &event);
806}
807
808
809static void wpa_driver_nl80211_event_dellink(
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800810 struct wpa_driver_nl80211_data *drv, const char *ifname)
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800811{
812 union wpa_event_data event;
813
814 if (os_strcmp(drv->first_bss->ifname, ifname) == 0) {
815 if (drv->if_removed) {
816 wpa_printf(MSG_DEBUG, "nl80211: if_removed already set - ignore RTM_DELLINK event for %s",
817 ifname);
818 return;
819 }
820 wpa_printf(MSG_DEBUG, "RTM_DELLINK: Interface '%s' removed - mark if_removed=1",
821 ifname);
822 drv->if_removed = 1;
823 } else {
824 wpa_printf(MSG_DEBUG, "RTM_DELLINK: Interface '%s' removed",
825 ifname);
826 }
827
828 os_memset(&event, 0, sizeof(event));
829 os_strlcpy(event.interface_status.ifname, ifname,
830 sizeof(event.interface_status.ifname));
831 event.interface_status.ievent = EVENT_INTERFACE_REMOVED;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700832 wpa_supplicant_event(drv->ctx, EVENT_INTERFACE_STATUS, &event);
833}
834
835
836static int wpa_driver_nl80211_own_ifname(struct wpa_driver_nl80211_data *drv,
837 u8 *buf, size_t len)
838{
839 int attrlen, rta_len;
840 struct rtattr *attr;
841
842 attrlen = len;
843 attr = (struct rtattr *) buf;
844
845 rta_len = RTA_ALIGN(sizeof(struct rtattr));
846 while (RTA_OK(attr, attrlen)) {
847 if (attr->rta_type == IFLA_IFNAME) {
Dmitry Shmidtcce06662013-11-04 18:44:24 -0800848 if (os_strcmp(((char *) attr) + rta_len,
849 drv->first_bss->ifname) == 0)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700850 return 1;
851 else
852 break;
853 }
854 attr = RTA_NEXT(attr, attrlen);
855 }
856
857 return 0;
858}
859
860
861static int wpa_driver_nl80211_own_ifindex(struct wpa_driver_nl80211_data *drv,
862 int ifindex, u8 *buf, size_t len)
863{
864 if (drv->ifindex == ifindex)
865 return 1;
866
867 if (drv->if_removed && wpa_driver_nl80211_own_ifname(drv, buf, len)) {
Dmitry Shmidt7f656022015-02-25 14:36:37 -0800868 nl80211_check_global(drv->global);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700869 wpa_printf(MSG_DEBUG, "nl80211: Update ifindex for a removed "
870 "interface");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800871 wpa_driver_nl80211_finish_drv_init(drv, NULL, 0, NULL);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700872 return 1;
873 }
874
875 return 0;
876}
877
878
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800879static struct wpa_driver_nl80211_data *
880nl80211_find_drv(struct nl80211_global *global, int idx, u8 *buf, size_t len)
881{
882 struct wpa_driver_nl80211_data *drv;
883 dl_list_for_each(drv, &global->interfaces,
884 struct wpa_driver_nl80211_data, list) {
885 if (wpa_driver_nl80211_own_ifindex(drv, idx, buf, len) ||
886 have_ifidx(drv, idx))
887 return drv;
888 }
889 return NULL;
890}
891
892
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700893static void wpa_driver_nl80211_event_rtm_newlink(void *ctx,
894 struct ifinfomsg *ifi,
895 u8 *buf, size_t len)
896{
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800897 struct nl80211_global *global = ctx;
898 struct wpa_driver_nl80211_data *drv;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800899 int attrlen;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700900 struct rtattr *attr;
901 u32 brid = 0;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800902 char namebuf[IFNAMSIZ];
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800903 char ifname[IFNAMSIZ + 1];
904 char extra[100], *pos, *end;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700905
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800906 drv = nl80211_find_drv(global, ifi->ifi_index, buf, len);
907 if (!drv) {
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800908 wpa_printf(MSG_DEBUG, "nl80211: Ignore RTM_NEWLINK event for foreign ifindex %d",
909 ifi->ifi_index);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700910 return;
911 }
912
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800913 extra[0] = '\0';
914 pos = extra;
915 end = pos + sizeof(extra);
916 ifname[0] = '\0';
917
918 attrlen = len;
919 attr = (struct rtattr *) buf;
920 while (RTA_OK(attr, attrlen)) {
921 switch (attr->rta_type) {
922 case IFLA_IFNAME:
923 if (RTA_PAYLOAD(attr) >= IFNAMSIZ)
924 break;
925 os_memcpy(ifname, RTA_DATA(attr), RTA_PAYLOAD(attr));
926 ifname[RTA_PAYLOAD(attr)] = '\0';
927 break;
928 case IFLA_MASTER:
929 brid = nla_get_u32((struct nlattr *) attr);
930 pos += os_snprintf(pos, end - pos, " master=%u", brid);
931 break;
932 case IFLA_WIRELESS:
933 pos += os_snprintf(pos, end - pos, " wext");
934 break;
935 case IFLA_OPERSTATE:
936 pos += os_snprintf(pos, end - pos, " operstate=%u",
937 nla_get_u32((struct nlattr *) attr));
938 break;
939 case IFLA_LINKMODE:
940 pos += os_snprintf(pos, end - pos, " linkmode=%u",
941 nla_get_u32((struct nlattr *) attr));
942 break;
943 }
944 attr = RTA_NEXT(attr, attrlen);
945 }
946 extra[sizeof(extra) - 1] = '\0';
947
Dmitry Shmidt661b4f72014-09-29 14:58:27 -0700948 wpa_printf(MSG_DEBUG, "RTM_NEWLINK: ifi_index=%d ifname=%s%s ifi_family=%d ifi_flags=0x%x (%s%s%s%s)",
949 ifi->ifi_index, ifname, extra, ifi->ifi_family,
950 ifi->ifi_flags,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700951 (ifi->ifi_flags & IFF_UP) ? "[UP]" : "",
952 (ifi->ifi_flags & IFF_RUNNING) ? "[RUNNING]" : "",
953 (ifi->ifi_flags & IFF_LOWER_UP) ? "[LOWER_UP]" : "",
954 (ifi->ifi_flags & IFF_DORMANT) ? "[DORMANT]" : "");
955
956 if (!drv->if_disabled && !(ifi->ifi_flags & IFF_UP)) {
Dmitry Shmidt7f656022015-02-25 14:36:37 -0800957 namebuf[0] = '\0';
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800958 if (if_indextoname(ifi->ifi_index, namebuf) &&
Dmitry Shmidt7f656022015-02-25 14:36:37 -0800959 linux_iface_up(drv->global->ioctl_sock, namebuf) > 0) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800960 wpa_printf(MSG_DEBUG, "nl80211: Ignore interface down "
961 "event since interface %s is up", namebuf);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800962 drv->ignore_if_down_event = 0;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800963 return;
964 }
Dmitry Shmidt7f656022015-02-25 14:36:37 -0800965 wpa_printf(MSG_DEBUG, "nl80211: Interface down (%s/%s)",
966 namebuf, ifname);
967 if (os_strcmp(drv->first_bss->ifname, ifname) != 0) {
968 wpa_printf(MSG_DEBUG,
969 "nl80211: Not the main interface (%s) - do not indicate interface down",
970 drv->first_bss->ifname);
971 } else if (drv->ignore_if_down_event) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800972 wpa_printf(MSG_DEBUG, "nl80211: Ignore interface down "
973 "event generated by mode change");
974 drv->ignore_if_down_event = 0;
975 } else {
976 drv->if_disabled = 1;
977 wpa_supplicant_event(drv->ctx,
978 EVENT_INTERFACE_DISABLED, NULL);
Dmitry Shmidta38abf92014-03-06 13:38:44 -0800979
980 /*
981 * Try to get drv again, since it may be removed as
982 * part of the EVENT_INTERFACE_DISABLED handling for
983 * dynamic interfaces
984 */
985 drv = nl80211_find_drv(global, ifi->ifi_index,
986 buf, len);
987 if (!drv)
988 return;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800989 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700990 }
991
992 if (drv->if_disabled && (ifi->ifi_flags & IFF_UP)) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800993 if (if_indextoname(ifi->ifi_index, namebuf) &&
Dmitry Shmidt7f656022015-02-25 14:36:37 -0800994 linux_iface_up(drv->global->ioctl_sock, namebuf) == 0) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800995 wpa_printf(MSG_DEBUG, "nl80211: Ignore interface up "
996 "event since interface %s is down",
997 namebuf);
Dmitry Shmidtcce06662013-11-04 18:44:24 -0800998 } else if (if_nametoindex(drv->first_bss->ifname) == 0) {
Dmitry Shmidt04949592012-07-19 12:16:46 -0700999 wpa_printf(MSG_DEBUG, "nl80211: Ignore interface up "
1000 "event since interface %s does not exist",
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001001 drv->first_bss->ifname);
Dmitry Shmidt04949592012-07-19 12:16:46 -07001002 } else if (drv->if_removed) {
1003 wpa_printf(MSG_DEBUG, "nl80211: Ignore interface up "
1004 "event since interface %s is marked "
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001005 "removed", drv->first_bss->ifname);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001006 } else {
Dmitry Shmidt9ead16e2014-10-07 13:15:23 -07001007 struct i802_bss *bss;
1008 u8 addr[ETH_ALEN];
1009
1010 /* Re-read MAC address as it may have changed */
1011 bss = get_bss_ifindex(drv, ifi->ifi_index);
1012 if (bss &&
1013 linux_get_ifhwaddr(drv->global->ioctl_sock,
1014 bss->ifname, addr) < 0) {
1015 wpa_printf(MSG_DEBUG,
1016 "nl80211: %s: failed to re-read MAC address",
1017 bss->ifname);
1018 } else if (bss &&
1019 os_memcmp(addr, bss->addr, ETH_ALEN) != 0) {
1020 wpa_printf(MSG_DEBUG,
1021 "nl80211: Own MAC address on ifindex %d (%s) changed from "
1022 MACSTR " to " MACSTR,
1023 ifi->ifi_index, bss->ifname,
1024 MAC2STR(bss->addr),
1025 MAC2STR(addr));
1026 os_memcpy(bss->addr, addr, ETH_ALEN);
1027 }
1028
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001029 wpa_printf(MSG_DEBUG, "nl80211: Interface up");
1030 drv->if_disabled = 0;
1031 wpa_supplicant_event(drv->ctx, EVENT_INTERFACE_ENABLED,
1032 NULL);
1033 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001034 }
1035
1036 /*
1037 * Some drivers send the association event before the operup event--in
1038 * this case, lifting operstate in wpa_driver_nl80211_set_operstate()
1039 * fails. This will hit us when wpa_supplicant does not need to do
1040 * IEEE 802.1X authentication
1041 */
1042 if (drv->operstate == 1 &&
1043 (ifi->ifi_flags & (IFF_LOWER_UP | IFF_DORMANT)) == IFF_LOWER_UP &&
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001044 !(ifi->ifi_flags & IFF_RUNNING)) {
1045 wpa_printf(MSG_DEBUG, "nl80211: Set IF_OPER_UP again based on ifi_flags and expected operstate");
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001046 netlink_send_oper_ifla(drv->global->netlink, drv->ifindex,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001047 -1, IF_OPER_UP);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001048 }
1049
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001050 if (ifname[0])
1051 wpa_driver_nl80211_event_newlink(drv, ifname);
1052
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001053 if (ifi->ifi_family == AF_BRIDGE && brid) {
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001054 struct i802_bss *bss;
1055
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001056 /* device has been added to bridge */
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001057 if (!if_indextoname(brid, namebuf)) {
1058 wpa_printf(MSG_DEBUG,
1059 "nl80211: Could not find bridge ifname for ifindex %u",
1060 brid);
1061 return;
1062 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001063 wpa_printf(MSG_DEBUG, "nl80211: Add ifindex %u for bridge %s",
1064 brid, namebuf);
1065 add_ifidx(drv, brid);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001066
1067 for (bss = drv->first_bss; bss; bss = bss->next) {
1068 if (os_strcmp(ifname, bss->ifname) == 0) {
1069 os_strlcpy(bss->brname, namebuf, IFNAMSIZ);
1070 break;
1071 }
1072 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001073 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001074}
1075
1076
1077static void wpa_driver_nl80211_event_rtm_dellink(void *ctx,
1078 struct ifinfomsg *ifi,
1079 u8 *buf, size_t len)
1080{
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001081 struct nl80211_global *global = ctx;
1082 struct wpa_driver_nl80211_data *drv;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001083 int attrlen;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001084 struct rtattr *attr;
1085 u32 brid = 0;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001086 char ifname[IFNAMSIZ + 1];
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07001087 char extra[100], *pos, *end;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001088
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001089 drv = nl80211_find_drv(global, ifi->ifi_index, buf, len);
1090 if (!drv) {
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001091 wpa_printf(MSG_DEBUG, "nl80211: Ignore RTM_DELLINK event for foreign ifindex %d",
1092 ifi->ifi_index);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001093 return;
1094 }
1095
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07001096 extra[0] = '\0';
1097 pos = extra;
1098 end = pos + sizeof(extra);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001099 ifname[0] = '\0';
1100
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001101 attrlen = len;
1102 attr = (struct rtattr *) buf;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001103 while (RTA_OK(attr, attrlen)) {
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001104 switch (attr->rta_type) {
1105 case IFLA_IFNAME:
1106 if (RTA_PAYLOAD(attr) >= IFNAMSIZ)
1107 break;
1108 os_memcpy(ifname, RTA_DATA(attr), RTA_PAYLOAD(attr));
1109 ifname[RTA_PAYLOAD(attr)] = '\0';
1110 break;
1111 case IFLA_MASTER:
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001112 brid = nla_get_u32((struct nlattr *) attr);
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07001113 pos += os_snprintf(pos, end - pos, " master=%u", brid);
1114 break;
1115 case IFLA_OPERSTATE:
1116 pos += os_snprintf(pos, end - pos, " operstate=%u",
1117 nla_get_u32((struct nlattr *) attr));
1118 break;
1119 case IFLA_LINKMODE:
1120 pos += os_snprintf(pos, end - pos, " linkmode=%u",
1121 nla_get_u32((struct nlattr *) attr));
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001122 break;
1123 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001124 attr = RTA_NEXT(attr, attrlen);
1125 }
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07001126 extra[sizeof(extra) - 1] = '\0';
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001127
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07001128 wpa_printf(MSG_DEBUG, "RTM_DELLINK: ifi_index=%d ifname=%s%s ifi_family=%d ifi_flags=0x%x (%s%s%s%s)",
1129 ifi->ifi_index, ifname, extra, ifi->ifi_family,
1130 ifi->ifi_flags,
1131 (ifi->ifi_flags & IFF_UP) ? "[UP]" : "",
1132 (ifi->ifi_flags & IFF_RUNNING) ? "[RUNNING]" : "",
1133 (ifi->ifi_flags & IFF_LOWER_UP) ? "[LOWER_UP]" : "",
1134 (ifi->ifi_flags & IFF_DORMANT) ? "[DORMANT]" : "");
1135
1136 if (ifname[0] && (ifi->ifi_family != AF_BRIDGE || !brid))
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001137 wpa_driver_nl80211_event_dellink(drv, ifname);
1138
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001139 if (ifi->ifi_family == AF_BRIDGE && brid) {
1140 /* device has been removed from bridge */
1141 char namebuf[IFNAMSIZ];
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001142
1143 if (!if_indextoname(brid, namebuf)) {
1144 wpa_printf(MSG_DEBUG,
1145 "nl80211: Could not find bridge ifname for ifindex %u",
1146 brid);
1147 } else {
1148 wpa_printf(MSG_DEBUG,
1149 "nl80211: Remove ifindex %u for bridge %s",
1150 brid, namebuf);
1151 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001152 del_ifidx(drv, brid);
1153 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001154}
1155
1156
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001157unsigned int nl80211_get_assoc_freq(struct wpa_driver_nl80211_data *drv)
Jouni Malinen87fd2792011-05-16 18:35:42 +03001158{
1159 struct nl_msg *msg;
1160 int ret;
1161 struct nl80211_bss_info_arg arg;
1162
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001163 msg = nl80211_drv_msg(drv, NLM_F_DUMP, NL80211_CMD_GET_SCAN);
Jouni Malinen87fd2792011-05-16 18:35:42 +03001164 os_memset(&arg, 0, sizeof(arg));
Jouni Malinen87fd2792011-05-16 18:35:42 +03001165 arg.drv = drv;
1166 ret = send_and_recv_msgs(drv, msg, bss_info_handler, &arg);
Jouni Malinen87fd2792011-05-16 18:35:42 +03001167 if (ret == 0) {
Dmitry Shmidt6dc03bd2014-05-16 10:40:13 -07001168 unsigned int freq = drv->nlmode == NL80211_IFTYPE_ADHOC ?
1169 arg.ibss_freq : arg.assoc_freq;
Jouni Malinen87fd2792011-05-16 18:35:42 +03001170 wpa_printf(MSG_DEBUG, "nl80211: Operating frequency for the "
Dmitry Shmidt6dc03bd2014-05-16 10:40:13 -07001171 "associated BSS from scan results: %u MHz", freq);
1172 if (freq)
1173 drv->assoc_freq = freq;
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -07001174 return drv->assoc_freq;
Jouni Malinen87fd2792011-05-16 18:35:42 +03001175 }
1176 wpa_printf(MSG_DEBUG, "nl80211: Scan result fetch failed: ret=%d "
1177 "(%s)", ret, strerror(-ret));
Jouni Malinen87fd2792011-05-16 18:35:42 +03001178 return drv->assoc_freq;
1179}
1180
1181
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001182static int get_link_signal(struct nl_msg *msg, void *arg)
1183{
1184 struct nlattr *tb[NL80211_ATTR_MAX + 1];
1185 struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg));
1186 struct nlattr *sinfo[NL80211_STA_INFO_MAX + 1];
1187 static struct nla_policy policy[NL80211_STA_INFO_MAX + 1] = {
1188 [NL80211_STA_INFO_SIGNAL] = { .type = NLA_U8 },
Dmitry Shmidt34af3062013-07-11 10:46:32 -07001189 [NL80211_STA_INFO_SIGNAL_AVG] = { .type = NLA_U8 },
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001190 };
1191 struct nlattr *rinfo[NL80211_RATE_INFO_MAX + 1];
1192 static struct nla_policy rate_policy[NL80211_RATE_INFO_MAX + 1] = {
1193 [NL80211_RATE_INFO_BITRATE] = { .type = NLA_U16 },
1194 [NL80211_RATE_INFO_MCS] = { .type = NLA_U8 },
1195 [NL80211_RATE_INFO_40_MHZ_WIDTH] = { .type = NLA_FLAG },
1196 [NL80211_RATE_INFO_SHORT_GI] = { .type = NLA_FLAG },
1197 };
1198 struct wpa_signal_info *sig_change = arg;
1199
1200 nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0),
1201 genlmsg_attrlen(gnlh, 0), NULL);
1202 if (!tb[NL80211_ATTR_STA_INFO] ||
1203 nla_parse_nested(sinfo, NL80211_STA_INFO_MAX,
1204 tb[NL80211_ATTR_STA_INFO], policy))
1205 return NL_SKIP;
1206 if (!sinfo[NL80211_STA_INFO_SIGNAL])
1207 return NL_SKIP;
1208
1209 sig_change->current_signal =
1210 (s8) nla_get_u8(sinfo[NL80211_STA_INFO_SIGNAL]);
1211
Dmitry Shmidt34af3062013-07-11 10:46:32 -07001212 if (sinfo[NL80211_STA_INFO_SIGNAL_AVG])
1213 sig_change->avg_signal =
1214 (s8) nla_get_u8(sinfo[NL80211_STA_INFO_SIGNAL_AVG]);
1215 else
1216 sig_change->avg_signal = 0;
1217
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001218 if (sinfo[NL80211_STA_INFO_TX_BITRATE]) {
1219 if (nla_parse_nested(rinfo, NL80211_RATE_INFO_MAX,
1220 sinfo[NL80211_STA_INFO_TX_BITRATE],
1221 rate_policy)) {
1222 sig_change->current_txrate = 0;
1223 } else {
1224 if (rinfo[NL80211_RATE_INFO_BITRATE]) {
1225 sig_change->current_txrate =
1226 nla_get_u16(rinfo[
1227 NL80211_RATE_INFO_BITRATE]) * 100;
1228 }
1229 }
1230 }
1231
1232 return NL_SKIP;
1233}
1234
1235
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001236int nl80211_get_link_signal(struct wpa_driver_nl80211_data *drv,
1237 struct wpa_signal_info *sig)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001238{
1239 struct nl_msg *msg;
1240
1241 sig->current_signal = -9999;
1242 sig->current_txrate = 0;
1243
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001244 if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_GET_STATION)) ||
1245 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, drv->bssid)) {
1246 nlmsg_free(msg);
1247 return -ENOBUFS;
1248 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001249
1250 return send_and_recv_msgs(drv, msg, get_link_signal, sig);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001251}
1252
1253
1254static int get_link_noise(struct nl_msg *msg, void *arg)
1255{
1256 struct nlattr *tb[NL80211_ATTR_MAX + 1];
1257 struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg));
1258 struct nlattr *sinfo[NL80211_SURVEY_INFO_MAX + 1];
1259 static struct nla_policy survey_policy[NL80211_SURVEY_INFO_MAX + 1] = {
1260 [NL80211_SURVEY_INFO_FREQUENCY] = { .type = NLA_U32 },
1261 [NL80211_SURVEY_INFO_NOISE] = { .type = NLA_U8 },
1262 };
1263 struct wpa_signal_info *sig_change = arg;
1264
1265 nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0),
1266 genlmsg_attrlen(gnlh, 0), NULL);
1267
1268 if (!tb[NL80211_ATTR_SURVEY_INFO]) {
1269 wpa_printf(MSG_DEBUG, "nl80211: survey data missing!");
1270 return NL_SKIP;
1271 }
1272
1273 if (nla_parse_nested(sinfo, NL80211_SURVEY_INFO_MAX,
1274 tb[NL80211_ATTR_SURVEY_INFO],
1275 survey_policy)) {
1276 wpa_printf(MSG_DEBUG, "nl80211: failed to parse nested "
1277 "attributes!");
1278 return NL_SKIP;
1279 }
1280
1281 if (!sinfo[NL80211_SURVEY_INFO_FREQUENCY])
1282 return NL_SKIP;
1283
1284 if (nla_get_u32(sinfo[NL80211_SURVEY_INFO_FREQUENCY]) !=
1285 sig_change->frequency)
1286 return NL_SKIP;
1287
1288 if (!sinfo[NL80211_SURVEY_INFO_NOISE])
1289 return NL_SKIP;
1290
1291 sig_change->current_noise =
1292 (s8) nla_get_u8(sinfo[NL80211_SURVEY_INFO_NOISE]);
1293
1294 return NL_SKIP;
1295}
1296
1297
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001298int nl80211_get_link_noise(struct wpa_driver_nl80211_data *drv,
1299 struct wpa_signal_info *sig_change)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001300{
1301 struct nl_msg *msg;
1302
1303 sig_change->current_noise = 9999;
1304 sig_change->frequency = drv->assoc_freq;
1305
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001306 msg = nl80211_drv_msg(drv, NLM_F_DUMP, NL80211_CMD_GET_SURVEY);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001307 return send_and_recv_msgs(drv, msg, get_link_noise, sig_change);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001308}
1309
1310
1311static void wpa_driver_nl80211_event_receive(int sock, void *eloop_ctx,
1312 void *handle)
1313{
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001314 struct nl_cb *cb = eloop_ctx;
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -07001315 int res;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001316
Dmitry Shmidt8da800a2013-04-24 12:57:01 -07001317 wpa_printf(MSG_MSGDUMP, "nl80211: Event message available");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001318
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -07001319 res = nl_recvmsgs(handle, cb);
Dmitry Shmidt71757432014-06-02 13:50:35 -07001320 if (res < 0) {
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -07001321 wpa_printf(MSG_INFO, "nl80211: %s->nl_recvmsgs failed: %d",
1322 __func__, res);
1323 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001324}
1325
1326
1327/**
1328 * wpa_driver_nl80211_set_country - ask nl80211 to set the regulatory domain
1329 * @priv: driver_nl80211 private data
1330 * @alpha2_arg: country to which to switch to
1331 * Returns: 0 on success, -1 on failure
1332 *
1333 * This asks nl80211 to set the regulatory domain for given
1334 * country ISO / IEC alpha2.
1335 */
1336static int wpa_driver_nl80211_set_country(void *priv, const char *alpha2_arg)
1337{
1338 struct i802_bss *bss = priv;
1339 struct wpa_driver_nl80211_data *drv = bss->drv;
1340 char alpha2[3];
1341 struct nl_msg *msg;
1342
1343 msg = nlmsg_alloc();
1344 if (!msg)
1345 return -ENOMEM;
1346
1347 alpha2[0] = alpha2_arg[0];
1348 alpha2[1] = alpha2_arg[1];
1349 alpha2[2] = '\0';
1350
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001351 if (!nl80211_cmd(drv, msg, 0, NL80211_CMD_REQ_SET_REG) ||
1352 nla_put_string(msg, NL80211_ATTR_REG_ALPHA2, alpha2)) {
1353 nlmsg_free(msg);
1354 return -EINVAL;
1355 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001356 if (send_and_recv_msgs(drv, msg, NULL, NULL))
1357 return -EINVAL;
1358 return 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001359}
1360
1361
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001362static int nl80211_get_country(struct nl_msg *msg, void *arg)
1363{
1364 char *alpha2 = arg;
1365 struct nlattr *tb_msg[NL80211_ATTR_MAX + 1];
1366 struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg));
1367
1368 nla_parse(tb_msg, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0),
1369 genlmsg_attrlen(gnlh, 0), NULL);
1370 if (!tb_msg[NL80211_ATTR_REG_ALPHA2]) {
1371 wpa_printf(MSG_DEBUG, "nl80211: No country information available");
1372 return NL_SKIP;
1373 }
1374 os_strlcpy(alpha2, nla_data(tb_msg[NL80211_ATTR_REG_ALPHA2]), 3);
1375 return NL_SKIP;
1376}
1377
1378
1379static int wpa_driver_nl80211_get_country(void *priv, char *alpha2)
1380{
1381 struct i802_bss *bss = priv;
1382 struct wpa_driver_nl80211_data *drv = bss->drv;
1383 struct nl_msg *msg;
1384 int ret;
1385
1386 msg = nlmsg_alloc();
1387 if (!msg)
1388 return -ENOMEM;
1389
1390 nl80211_cmd(drv, msg, 0, NL80211_CMD_GET_REG);
1391 alpha2[0] = '\0';
1392 ret = send_and_recv_msgs(drv, msg, nl80211_get_country, alpha2);
1393 if (!alpha2[0])
1394 ret = -1;
1395
1396 return ret;
1397}
1398
1399
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001400static int wpa_driver_nl80211_init_nl_global(struct nl80211_global *global)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001401{
1402 int ret;
1403
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001404 global->nl_cb = nl_cb_alloc(NL_CB_DEFAULT);
1405 if (global->nl_cb == NULL) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001406 wpa_printf(MSG_ERROR, "nl80211: Failed to allocate netlink "
1407 "callbacks");
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001408 return -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001409 }
1410
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001411 global->nl = nl_create_handle(global->nl_cb, "nl");
1412 if (global->nl == NULL)
1413 goto err;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001414
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001415 global->nl80211_id = genl_ctrl_resolve(global->nl, "nl80211");
1416 if (global->nl80211_id < 0) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001417 wpa_printf(MSG_ERROR, "nl80211: 'nl80211' generic netlink not "
1418 "found");
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001419 goto err;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001420 }
1421
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001422 global->nl_event = nl_create_handle(global->nl_cb, "event");
1423 if (global->nl_event == NULL)
1424 goto err;
1425
1426 ret = nl_get_multicast_id(global, "nl80211", "scan");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001427 if (ret >= 0)
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001428 ret = nl_socket_add_membership(global->nl_event, ret);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001429 if (ret < 0) {
1430 wpa_printf(MSG_ERROR, "nl80211: Could not add multicast "
1431 "membership for scan events: %d (%s)",
1432 ret, strerror(-ret));
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001433 goto err;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001434 }
1435
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001436 ret = nl_get_multicast_id(global, "nl80211", "mlme");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001437 if (ret >= 0)
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001438 ret = nl_socket_add_membership(global->nl_event, ret);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001439 if (ret < 0) {
1440 wpa_printf(MSG_ERROR, "nl80211: Could not add multicast "
1441 "membership for mlme events: %d (%s)",
1442 ret, strerror(-ret));
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001443 goto err;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001444 }
1445
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001446 ret = nl_get_multicast_id(global, "nl80211", "regulatory");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001447 if (ret >= 0)
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001448 ret = nl_socket_add_membership(global->nl_event, ret);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001449 if (ret < 0) {
1450 wpa_printf(MSG_DEBUG, "nl80211: Could not add multicast "
1451 "membership for regulatory events: %d (%s)",
1452 ret, strerror(-ret));
1453 /* Continue without regulatory events */
1454 }
1455
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001456 ret = nl_get_multicast_id(global, "nl80211", "vendor");
1457 if (ret >= 0)
1458 ret = nl_socket_add_membership(global->nl_event, ret);
1459 if (ret < 0) {
1460 wpa_printf(MSG_DEBUG, "nl80211: Could not add multicast "
1461 "membership for vendor events: %d (%s)",
1462 ret, strerror(-ret));
1463 /* Continue without vendor events */
1464 }
1465
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001466 nl_cb_set(global->nl_cb, NL_CB_SEQ_CHECK, NL_CB_CUSTOM,
1467 no_seq_check, NULL);
1468 nl_cb_set(global->nl_cb, NL_CB_VALID, NL_CB_CUSTOM,
1469 process_global_event, global);
1470
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -07001471 nl80211_register_eloop_read(&global->nl_event,
1472 wpa_driver_nl80211_event_receive,
1473 global->nl_cb);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001474
1475 return 0;
1476
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001477err:
1478 nl_destroy_handles(&global->nl_event);
1479 nl_destroy_handles(&global->nl);
1480 nl_cb_put(global->nl_cb);
1481 global->nl_cb = NULL;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001482 return -1;
1483}
1484
1485
Dmitry Shmidt7f656022015-02-25 14:36:37 -08001486static void nl80211_check_global(struct nl80211_global *global)
1487{
1488 struct nl_handle *handle;
1489 const char *groups[] = { "scan", "mlme", "regulatory", "vendor", NULL };
1490 int ret;
1491 unsigned int i;
1492
1493 /*
1494 * Try to re-add memberships to handle case of cfg80211 getting reloaded
1495 * and all registration having been cleared.
1496 */
1497 handle = (void *) (((intptr_t) global->nl_event) ^
1498 ELOOP_SOCKET_INVALID);
1499
1500 for (i = 0; groups[i]; i++) {
1501 ret = nl_get_multicast_id(global, "nl80211", groups[i]);
1502 if (ret >= 0)
1503 ret = nl_socket_add_membership(handle, ret);
1504 if (ret < 0) {
1505 wpa_printf(MSG_INFO,
1506 "nl80211: Could not re-add multicast membership for %s events: %d (%s)",
1507 groups[i], ret, strerror(-ret));
1508 }
1509 }
1510}
1511
1512
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001513static void wpa_driver_nl80211_rfkill_blocked(void *ctx)
1514{
1515 wpa_printf(MSG_DEBUG, "nl80211: RFKILL blocked");
1516 /*
1517 * This may be for any interface; use ifdown event to disable
1518 * interface.
1519 */
1520}
1521
1522
1523static void wpa_driver_nl80211_rfkill_unblocked(void *ctx)
1524{
1525 struct wpa_driver_nl80211_data *drv = ctx;
1526 wpa_printf(MSG_DEBUG, "nl80211: RFKILL unblocked");
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001527 if (i802_set_iface_flags(drv->first_bss, 1)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001528 wpa_printf(MSG_DEBUG, "nl80211: Could not set interface UP "
1529 "after rfkill unblock");
1530 return;
1531 }
1532 /* rtnetlink ifup handler will report interface as enabled */
1533}
1534
1535
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001536static void wpa_driver_nl80211_handle_eapol_tx_status(int sock,
1537 void *eloop_ctx,
1538 void *handle)
1539{
1540 struct wpa_driver_nl80211_data *drv = eloop_ctx;
1541 u8 data[2048];
1542 struct msghdr msg;
1543 struct iovec entry;
Dmitry Shmidt04949592012-07-19 12:16:46 -07001544 u8 control[512];
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001545 struct cmsghdr *cmsg;
1546 int res, found_ee = 0, found_wifi = 0, acked = 0;
1547 union wpa_event_data event;
1548
1549 memset(&msg, 0, sizeof(msg));
1550 msg.msg_iov = &entry;
1551 msg.msg_iovlen = 1;
1552 entry.iov_base = data;
1553 entry.iov_len = sizeof(data);
1554 msg.msg_control = &control;
1555 msg.msg_controllen = sizeof(control);
1556
1557 res = recvmsg(sock, &msg, MSG_ERRQUEUE);
1558 /* if error or not fitting 802.3 header, return */
1559 if (res < 14)
1560 return;
1561
1562 for (cmsg = CMSG_FIRSTHDR(&msg); cmsg; cmsg = CMSG_NXTHDR(&msg, cmsg))
1563 {
1564 if (cmsg->cmsg_level == SOL_SOCKET &&
1565 cmsg->cmsg_type == SCM_WIFI_STATUS) {
1566 int *ack;
1567
1568 found_wifi = 1;
1569 ack = (void *)CMSG_DATA(cmsg);
1570 acked = *ack;
1571 }
1572
1573 if (cmsg->cmsg_level == SOL_PACKET &&
1574 cmsg->cmsg_type == PACKET_TX_TIMESTAMP) {
1575 struct sock_extended_err *err =
1576 (struct sock_extended_err *)CMSG_DATA(cmsg);
1577
1578 if (err->ee_origin == SO_EE_ORIGIN_TXSTATUS)
1579 found_ee = 1;
1580 }
1581 }
1582
1583 if (!found_ee || !found_wifi)
1584 return;
1585
1586 memset(&event, 0, sizeof(event));
1587 event.eapol_tx_status.dst = data;
1588 event.eapol_tx_status.data = data + 14;
1589 event.eapol_tx_status.data_len = res - 14;
1590 event.eapol_tx_status.ack = acked;
1591 wpa_supplicant_event(drv->ctx, EVENT_EAPOL_TX_STATUS, &event);
1592}
1593
1594
1595static int nl80211_init_bss(struct i802_bss *bss)
1596{
1597 bss->nl_cb = nl_cb_alloc(NL_CB_DEFAULT);
1598 if (!bss->nl_cb)
1599 return -1;
1600
1601 nl_cb_set(bss->nl_cb, NL_CB_SEQ_CHECK, NL_CB_CUSTOM,
1602 no_seq_check, NULL);
1603 nl_cb_set(bss->nl_cb, NL_CB_VALID, NL_CB_CUSTOM,
1604 process_bss_event, bss);
1605
1606 return 0;
1607}
1608
1609
1610static void nl80211_destroy_bss(struct i802_bss *bss)
1611{
1612 nl_cb_put(bss->nl_cb);
1613 bss->nl_cb = NULL;
1614}
1615
1616
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08001617static void * wpa_driver_nl80211_drv_init(void *ctx, const char *ifname,
1618 void *global_priv, int hostapd,
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001619 const u8 *set_addr,
1620 const char *driver_params)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001621{
1622 struct wpa_driver_nl80211_data *drv;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001623 struct rfkill_config *rcfg;
1624 struct i802_bss *bss;
1625
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001626 if (global_priv == NULL)
1627 return NULL;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001628 drv = os_zalloc(sizeof(*drv));
1629 if (drv == NULL)
1630 return NULL;
1631 drv->global = global_priv;
1632 drv->ctx = ctx;
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08001633 drv->hostapd = !!hostapd;
1634 drv->eapol_sock = -1;
Dmitry Shmidtff787d52015-01-12 13:01:47 -08001635
1636 /*
1637 * There is no driver capability flag for this, so assume it is
1638 * supported and disable this on first attempt to use if the driver
1639 * rejects the command due to missing support.
1640 */
1641 drv->set_rekey_offload = 1;
1642
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08001643 drv->num_if_indices = sizeof(drv->default_if_indices) / sizeof(int);
1644 drv->if_indices = drv->default_if_indices;
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001645
1646 drv->first_bss = os_zalloc(sizeof(*drv->first_bss));
1647 if (!drv->first_bss) {
1648 os_free(drv);
1649 return NULL;
1650 }
1651 bss = drv->first_bss;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001652 bss->drv = drv;
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08001653 bss->ctx = ctx;
1654
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001655 os_strlcpy(bss->ifname, ifname, sizeof(bss->ifname));
1656 drv->monitor_ifidx = -1;
1657 drv->monitor_sock = -1;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001658 drv->eapol_tx_sock = -1;
1659 drv->ap_scan_as_station = NL80211_IFTYPE_UNSPECIFIED;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001660
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001661 if (nl80211_init_bss(bss))
1662 goto failed;
1663
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001664 rcfg = os_zalloc(sizeof(*rcfg));
1665 if (rcfg == NULL)
1666 goto failed;
1667 rcfg->ctx = drv;
1668 os_strlcpy(rcfg->ifname, ifname, sizeof(rcfg->ifname));
1669 rcfg->blocked_cb = wpa_driver_nl80211_rfkill_blocked;
1670 rcfg->unblocked_cb = wpa_driver_nl80211_rfkill_unblocked;
1671 drv->rfkill = rfkill_init(rcfg);
1672 if (drv->rfkill == NULL) {
1673 wpa_printf(MSG_DEBUG, "nl80211: RFKILL status not available");
1674 os_free(rcfg);
1675 }
1676
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08001677 if (linux_iface_up(drv->global->ioctl_sock, ifname) > 0)
1678 drv->start_iface_up = 1;
1679
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001680 if (wpa_driver_nl80211_finish_drv_init(drv, set_addr, 1, driver_params))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001681 goto failed;
1682
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001683 drv->eapol_tx_sock = socket(PF_PACKET, SOCK_DGRAM, 0);
1684 if (drv->eapol_tx_sock < 0)
1685 goto failed;
1686
1687 if (drv->data_tx_status) {
1688 int enabled = 1;
1689
1690 if (setsockopt(drv->eapol_tx_sock, SOL_SOCKET, SO_WIFI_STATUS,
1691 &enabled, sizeof(enabled)) < 0) {
1692 wpa_printf(MSG_DEBUG,
1693 "nl80211: wifi status sockopt failed\n");
1694 drv->data_tx_status = 0;
1695 if (!drv->use_monitor)
1696 drv->capa.flags &=
1697 ~WPA_DRIVER_FLAGS_EAPOL_TX_STATUS;
1698 } else {
1699 eloop_register_read_sock(drv->eapol_tx_sock,
1700 wpa_driver_nl80211_handle_eapol_tx_status,
1701 drv, NULL);
1702 }
1703 }
1704
1705 if (drv->global) {
Dmitry Shmidt7f656022015-02-25 14:36:37 -08001706 nl80211_check_global(drv->global);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001707 dl_list_add(&drv->global->interfaces, &drv->list);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001708 drv->in_interface_list = 1;
1709 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001710
1711 return bss;
1712
1713failed:
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001714 wpa_driver_nl80211_deinit(bss);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001715 return NULL;
1716}
1717
1718
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08001719/**
1720 * wpa_driver_nl80211_init - Initialize nl80211 driver interface
1721 * @ctx: context to be used when calling wpa_supplicant functions,
1722 * e.g., wpa_supplicant_event()
1723 * @ifname: interface name, e.g., wlan0
1724 * @global_priv: private driver global data from global_init()
1725 * Returns: Pointer to private data, %NULL on failure
1726 */
1727static void * wpa_driver_nl80211_init(void *ctx, const char *ifname,
1728 void *global_priv)
1729{
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001730 return wpa_driver_nl80211_drv_init(ctx, ifname, global_priv, 0, NULL,
1731 NULL);
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08001732}
1733
1734
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001735static int nl80211_register_frame(struct i802_bss *bss,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001736 struct nl_handle *nl_handle,
1737 u16 type, const u8 *match, size_t match_len)
1738{
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001739 struct wpa_driver_nl80211_data *drv = bss->drv;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001740 struct nl_msg *msg;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001741 int ret;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001742 char buf[30];
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001743
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001744 buf[0] = '\0';
1745 wpa_snprintf_hex(buf, sizeof(buf), match, match_len);
Dmitry Shmidt2271d3f2014-06-23 12:16:31 -07001746 wpa_printf(MSG_DEBUG, "nl80211: Register frame type=0x%x (%s) nl_handle=%p match=%s",
1747 type, fc2str(type), nl_handle, buf);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001748
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001749 if (!(msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_REGISTER_ACTION)) ||
1750 nla_put_u16(msg, NL80211_ATTR_FRAME_TYPE, type) ||
1751 nla_put(msg, NL80211_ATTR_FRAME_MATCH, match_len, match)) {
1752 nlmsg_free(msg);
1753 return -1;
1754 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001755
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001756 ret = send_and_recv(drv->global, nl_handle, msg, NULL, NULL);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001757 if (ret) {
1758 wpa_printf(MSG_DEBUG, "nl80211: Register frame command "
1759 "failed (type=%u): ret=%d (%s)",
1760 type, ret, strerror(-ret));
1761 wpa_hexdump(MSG_DEBUG, "nl80211: Register frame match",
1762 match, match_len);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001763 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001764 return ret;
1765}
1766
1767
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001768static int nl80211_alloc_mgmt_handle(struct i802_bss *bss)
1769{
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001770 if (bss->nl_mgmt) {
1771 wpa_printf(MSG_DEBUG, "nl80211: Mgmt reporting "
1772 "already on! (nl_mgmt=%p)", bss->nl_mgmt);
1773 return -1;
1774 }
1775
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001776 bss->nl_mgmt = nl_create_handle(bss->nl_cb, "mgmt");
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001777 if (bss->nl_mgmt == NULL)
1778 return -1;
1779
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001780 return 0;
1781}
1782
1783
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -07001784static void nl80211_mgmt_handle_register_eloop(struct i802_bss *bss)
1785{
1786 nl80211_register_eloop_read(&bss->nl_mgmt,
1787 wpa_driver_nl80211_event_receive,
1788 bss->nl_cb);
1789}
1790
1791
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001792static int nl80211_register_action_frame(struct i802_bss *bss,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001793 const u8 *match, size_t match_len)
1794{
1795 u16 type = (WLAN_FC_TYPE_MGMT << 2) | (WLAN_FC_STYPE_ACTION << 4);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001796 return nl80211_register_frame(bss, bss->nl_mgmt,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001797 type, match, match_len);
1798}
1799
1800
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001801static int nl80211_mgmt_subscribe_non_ap(struct i802_bss *bss)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001802{
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001803 struct wpa_driver_nl80211_data *drv = bss->drv;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001804 int ret = 0;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001805
1806 if (nl80211_alloc_mgmt_handle(bss))
1807 return -1;
1808 wpa_printf(MSG_DEBUG, "nl80211: Subscribe to mgmt frames with non-AP "
1809 "handle %p", bss->nl_mgmt);
1810
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -07001811 if (drv->nlmode == NL80211_IFTYPE_ADHOC) {
1812 u16 type = (WLAN_FC_TYPE_MGMT << 2) | (WLAN_FC_STYPE_AUTH << 4);
1813
1814 /* register for any AUTH message */
1815 nl80211_register_frame(bss, bss->nl_mgmt, type, NULL, 0);
1816 }
1817
Dmitry Shmidt051af732013-10-22 13:52:46 -07001818#ifdef CONFIG_INTERWORKING
1819 /* QoS Map Configure */
1820 if (nl80211_register_action_frame(bss, (u8 *) "\x01\x04", 2) < 0)
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001821 ret = -1;
Dmitry Shmidt051af732013-10-22 13:52:46 -07001822#endif /* CONFIG_INTERWORKING */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001823#if defined(CONFIG_P2P) || defined(CONFIG_INTERWORKING)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001824 /* GAS Initial Request */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001825 if (nl80211_register_action_frame(bss, (u8 *) "\x04\x0a", 2) < 0)
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001826 ret = -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001827 /* GAS Initial Response */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001828 if (nl80211_register_action_frame(bss, (u8 *) "\x04\x0b", 2) < 0)
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001829 ret = -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001830 /* GAS Comeback Request */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001831 if (nl80211_register_action_frame(bss, (u8 *) "\x04\x0c", 2) < 0)
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001832 ret = -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001833 /* GAS Comeback Response */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001834 if (nl80211_register_action_frame(bss, (u8 *) "\x04\x0d", 2) < 0)
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001835 ret = -1;
Dmitry Shmidt18463232014-01-24 12:29:41 -08001836 /* Protected GAS Initial Request */
1837 if (nl80211_register_action_frame(bss, (u8 *) "\x09\x0a", 2) < 0)
1838 ret = -1;
1839 /* Protected GAS Initial Response */
1840 if (nl80211_register_action_frame(bss, (u8 *) "\x09\x0b", 2) < 0)
1841 ret = -1;
1842 /* Protected GAS Comeback Request */
1843 if (nl80211_register_action_frame(bss, (u8 *) "\x09\x0c", 2) < 0)
1844 ret = -1;
1845 /* Protected GAS Comeback Response */
1846 if (nl80211_register_action_frame(bss, (u8 *) "\x09\x0d", 2) < 0)
1847 ret = -1;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001848#endif /* CONFIG_P2P || CONFIG_INTERWORKING */
1849#ifdef CONFIG_P2P
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001850 /* P2P Public Action */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001851 if (nl80211_register_action_frame(bss,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001852 (u8 *) "\x04\x09\x50\x6f\x9a\x09",
1853 6) < 0)
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001854 ret = -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001855 /* P2P Action */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001856 if (nl80211_register_action_frame(bss,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001857 (u8 *) "\x7f\x50\x6f\x9a\x09",
1858 5) < 0)
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001859 ret = -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001860#endif /* CONFIG_P2P */
1861#ifdef CONFIG_IEEE80211W
1862 /* SA Query Response */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001863 if (nl80211_register_action_frame(bss, (u8 *) "\x08\x01", 2) < 0)
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001864 ret = -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001865#endif /* CONFIG_IEEE80211W */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001866#ifdef CONFIG_TDLS
1867 if ((drv->capa.flags & WPA_DRIVER_FLAGS_TDLS_SUPPORT)) {
1868 /* TDLS Discovery Response */
1869 if (nl80211_register_action_frame(bss, (u8 *) "\x04\x0e", 2) <
1870 0)
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001871 ret = -1;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001872 }
1873#endif /* CONFIG_TDLS */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001874
1875 /* FT Action frames */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001876 if (nl80211_register_action_frame(bss, (u8 *) "\x06", 1) < 0)
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001877 ret = -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001878 else
1879 drv->capa.key_mgmt |= WPA_DRIVER_CAPA_KEY_MGMT_FT |
1880 WPA_DRIVER_CAPA_KEY_MGMT_FT_PSK;
1881
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001882 /* WNM - BSS Transition Management Request */
1883 if (nl80211_register_action_frame(bss, (u8 *) "\x0a\x07", 2) < 0)
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001884 ret = -1;
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08001885 /* WNM-Sleep Mode Response */
1886 if (nl80211_register_action_frame(bss, (u8 *) "\x0a\x11", 2) < 0)
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001887 ret = -1;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001888
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08001889#ifdef CONFIG_HS20
1890 /* WNM-Notification */
1891 if (nl80211_register_action_frame(bss, (u8 *) "\x0a\x1a", 2) < 0)
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07001892 ret = -1;
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08001893#endif /* CONFIG_HS20 */
1894
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001895 /* WMM-AC ADDTS Response */
1896 if (nl80211_register_action_frame(bss, (u8 *) "\x11\x01", 2) < 0)
1897 ret = -1;
1898
1899 /* WMM-AC DELTS */
1900 if (nl80211_register_action_frame(bss, (u8 *) "\x11\x02", 2) < 0)
1901 ret = -1;
1902
1903 /* Radio Measurement - Neighbor Report Response */
1904 if (nl80211_register_action_frame(bss, (u8 *) "\x05\x05", 2) < 0)
1905 ret = -1;
1906
1907 /* Radio Measurement - Link Measurement Request */
1908 if ((drv->capa.rrm_flags & WPA_DRIVER_FLAGS_TX_POWER_INSERTION) &&
1909 (nl80211_register_action_frame(bss, (u8 *) "\x05\x02", 2) < 0))
1910 ret = -1;
1911
1912 nl80211_mgmt_handle_register_eloop(bss);
1913
1914 return ret;
1915}
1916
1917
1918static int nl80211_mgmt_subscribe_mesh(struct i802_bss *bss)
1919{
1920 int ret = 0;
1921
1922 if (nl80211_alloc_mgmt_handle(bss))
1923 return -1;
1924
1925 wpa_printf(MSG_DEBUG,
1926 "nl80211: Subscribe to mgmt frames with mesh handle %p",
1927 bss->nl_mgmt);
1928
1929 /* Auth frames for mesh SAE */
1930 if (nl80211_register_frame(bss, bss->nl_mgmt,
1931 (WLAN_FC_TYPE_MGMT << 2) |
1932 (WLAN_FC_STYPE_AUTH << 4),
1933 NULL, 0) < 0)
1934 ret = -1;
1935
1936 /* Mesh peering open */
1937 if (nl80211_register_action_frame(bss, (u8 *) "\x0f\x01", 2) < 0)
1938 ret = -1;
1939 /* Mesh peering confirm */
1940 if (nl80211_register_action_frame(bss, (u8 *) "\x0f\x02", 2) < 0)
1941 ret = -1;
1942 /* Mesh peering close */
1943 if (nl80211_register_action_frame(bss, (u8 *) "\x0f\x03", 2) < 0)
1944 ret = -1;
1945
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -07001946 nl80211_mgmt_handle_register_eloop(bss);
1947
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001948 return ret;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001949}
1950
1951
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001952static int nl80211_register_spurious_class3(struct i802_bss *bss)
1953{
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001954 struct nl_msg *msg;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001955 int ret;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001956
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001957 msg = nl80211_bss_msg(bss, 0, NL80211_CMD_UNEXPECTED_FRAME);
1958 ret = send_and_recv(bss->drv->global, bss->nl_mgmt, msg, NULL, NULL);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001959 if (ret) {
1960 wpa_printf(MSG_DEBUG, "nl80211: Register spurious class3 "
1961 "failed: ret=%d (%s)",
1962 ret, strerror(-ret));
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001963 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001964 return ret;
1965}
1966
1967
1968static int nl80211_mgmt_subscribe_ap(struct i802_bss *bss)
1969{
1970 static const int stypes[] = {
1971 WLAN_FC_STYPE_AUTH,
1972 WLAN_FC_STYPE_ASSOC_REQ,
1973 WLAN_FC_STYPE_REASSOC_REQ,
1974 WLAN_FC_STYPE_DISASSOC,
1975 WLAN_FC_STYPE_DEAUTH,
1976 WLAN_FC_STYPE_ACTION,
1977 WLAN_FC_STYPE_PROBE_REQ,
1978/* Beacon doesn't work as mac80211 doesn't currently allow
1979 * it, but it wouldn't really be the right thing anyway as
1980 * it isn't per interface ... maybe just dump the scan
1981 * results periodically for OLBC?
1982 */
Dmitry Shmidt7832adb2014-04-29 10:53:02 -07001983 /* WLAN_FC_STYPE_BEACON, */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001984 };
1985 unsigned int i;
1986
1987 if (nl80211_alloc_mgmt_handle(bss))
1988 return -1;
1989 wpa_printf(MSG_DEBUG, "nl80211: Subscribe to mgmt frames with AP "
1990 "handle %p", bss->nl_mgmt);
1991
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -07001992 for (i = 0; i < ARRAY_SIZE(stypes); i++) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001993 if (nl80211_register_frame(bss, bss->nl_mgmt,
1994 (WLAN_FC_TYPE_MGMT << 2) |
1995 (stypes[i] << 4),
1996 NULL, 0) < 0) {
1997 goto out_err;
1998 }
1999 }
2000
2001 if (nl80211_register_spurious_class3(bss))
2002 goto out_err;
2003
2004 if (nl80211_get_wiphy_data_ap(bss) == NULL)
2005 goto out_err;
2006
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -07002007 nl80211_mgmt_handle_register_eloop(bss);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002008 return 0;
2009
2010out_err:
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002011 nl_destroy_handles(&bss->nl_mgmt);
2012 return -1;
2013}
2014
2015
2016static int nl80211_mgmt_subscribe_ap_dev_sme(struct i802_bss *bss)
2017{
2018 if (nl80211_alloc_mgmt_handle(bss))
2019 return -1;
2020 wpa_printf(MSG_DEBUG, "nl80211: Subscribe to mgmt frames with AP "
2021 "handle %p (device SME)", bss->nl_mgmt);
2022
2023 if (nl80211_register_frame(bss, bss->nl_mgmt,
2024 (WLAN_FC_TYPE_MGMT << 2) |
2025 (WLAN_FC_STYPE_ACTION << 4),
2026 NULL, 0) < 0)
2027 goto out_err;
2028
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -07002029 nl80211_mgmt_handle_register_eloop(bss);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002030 return 0;
2031
2032out_err:
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002033 nl_destroy_handles(&bss->nl_mgmt);
2034 return -1;
2035}
2036
2037
2038static void nl80211_mgmt_unsubscribe(struct i802_bss *bss, const char *reason)
2039{
2040 if (bss->nl_mgmt == NULL)
2041 return;
2042 wpa_printf(MSG_DEBUG, "nl80211: Unsubscribe mgmt frames handle %p "
2043 "(%s)", bss->nl_mgmt, reason);
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -07002044 nl80211_destroy_eloop_handle(&bss->nl_mgmt);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002045
2046 nl80211_put_wiphy_data_ap(bss);
2047}
2048
2049
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002050static void wpa_driver_nl80211_send_rfkill(void *eloop_ctx, void *timeout_ctx)
2051{
2052 wpa_supplicant_event(timeout_ctx, EVENT_INTERFACE_DISABLED, NULL);
2053}
2054
2055
Dmitry Shmidt34af3062013-07-11 10:46:32 -07002056static void nl80211_del_p2pdev(struct i802_bss *bss)
2057{
Dmitry Shmidt34af3062013-07-11 10:46:32 -07002058 struct nl_msg *msg;
2059 int ret;
2060
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002061 msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_DEL_INTERFACE);
2062 ret = send_and_recv_msgs(bss->drv, msg, NULL, NULL);
Dmitry Shmidt34af3062013-07-11 10:46:32 -07002063
2064 wpa_printf(MSG_DEBUG, "nl80211: Delete P2P Device %s (0x%llx): %s",
2065 bss->ifname, (long long unsigned int) bss->wdev_id,
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -07002066 strerror(-ret));
Dmitry Shmidt34af3062013-07-11 10:46:32 -07002067}
2068
2069
2070static int nl80211_set_p2pdev(struct i802_bss *bss, int start)
2071{
Dmitry Shmidt34af3062013-07-11 10:46:32 -07002072 struct nl_msg *msg;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002073 int ret;
Dmitry Shmidt34af3062013-07-11 10:46:32 -07002074
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002075 msg = nl80211_cmd_msg(bss, 0, start ? NL80211_CMD_START_P2P_DEVICE :
2076 NL80211_CMD_STOP_P2P_DEVICE);
2077 ret = send_and_recv_msgs(bss->drv, msg, NULL, NULL);
Dmitry Shmidt34af3062013-07-11 10:46:32 -07002078
2079 wpa_printf(MSG_DEBUG, "nl80211: %s P2P Device %s (0x%llx): %s",
2080 start ? "Start" : "Stop",
2081 bss->ifname, (long long unsigned int) bss->wdev_id,
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -07002082 strerror(-ret));
Dmitry Shmidt34af3062013-07-11 10:46:32 -07002083 return ret;
2084}
2085
2086
2087static int i802_set_iface_flags(struct i802_bss *bss, int up)
2088{
2089 enum nl80211_iftype nlmode;
2090
2091 nlmode = nl80211_get_ifmode(bss);
2092 if (nlmode != NL80211_IFTYPE_P2P_DEVICE) {
2093 return linux_set_iface_flags(bss->drv->global->ioctl_sock,
2094 bss->ifname, up);
2095 }
2096
2097 /* P2P Device has start/stop which is equivalent */
2098 return nl80211_set_p2pdev(bss, up);
2099}
2100
2101
Dmitry Shmidt7f656022015-02-25 14:36:37 -08002102#ifdef CONFIG_TESTING_OPTIONS
2103static int qca_vendor_test_cmd_handler(struct nl_msg *msg, void *arg)
2104{
2105 /* struct wpa_driver_nl80211_data *drv = arg; */
2106 struct nlattr *tb[NL80211_ATTR_MAX + 1];
2107 struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg));
2108
2109
2110 wpa_printf(MSG_DEBUG,
2111 "nl80211: QCA vendor test command response received");
2112
2113 nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0),
2114 genlmsg_attrlen(gnlh, 0), NULL);
2115 if (!tb[NL80211_ATTR_VENDOR_DATA]) {
2116 wpa_printf(MSG_DEBUG, "nl80211: No vendor data attribute");
2117 return NL_SKIP;
2118 }
2119
2120 wpa_hexdump(MSG_DEBUG,
2121 "nl80211: Received QCA vendor test command response",
2122 nla_data(tb[NL80211_ATTR_VENDOR_DATA]),
2123 nla_len(tb[NL80211_ATTR_VENDOR_DATA]));
2124
2125 return NL_SKIP;
2126}
2127#endif /* CONFIG_TESTING_OPTIONS */
2128
2129
2130static void qca_vendor_test(struct wpa_driver_nl80211_data *drv)
2131{
2132#ifdef CONFIG_TESTING_OPTIONS
2133 struct nl_msg *msg;
2134 struct nlattr *params;
2135 int ret;
2136
2137 if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_VENDOR)) ||
2138 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
2139 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
2140 QCA_NL80211_VENDOR_SUBCMD_TEST) ||
2141 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
2142 nla_put_u32(msg, QCA_WLAN_VENDOR_ATTR_TEST, 123)) {
2143 nlmsg_free(msg);
2144 return;
2145 }
2146 nla_nest_end(msg, params);
2147
2148 ret = send_and_recv_msgs(drv, msg, qca_vendor_test_cmd_handler, drv);
2149 wpa_printf(MSG_DEBUG,
2150 "nl80211: QCA vendor test command returned %d (%s)",
2151 ret, strerror(-ret));
2152#endif /* CONFIG_TESTING_OPTIONS */
2153}
2154
2155
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002156static int
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08002157wpa_driver_nl80211_finish_drv_init(struct wpa_driver_nl80211_data *drv,
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002158 const u8 *set_addr, int first,
2159 const char *driver_params)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002160{
Dmitry Shmidtcce06662013-11-04 18:44:24 -08002161 struct i802_bss *bss = drv->first_bss;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002162 int send_rfkill_event = 0;
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08002163 enum nl80211_iftype nlmode;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002164
2165 drv->ifindex = if_nametoindex(bss->ifname);
Dmitry Shmidt34af3062013-07-11 10:46:32 -07002166 bss->ifindex = drv->ifindex;
2167 bss->wdev_id = drv->global->if_add_wdevid;
2168 bss->wdev_id_set = drv->global->if_add_wdevid_set;
2169
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -07002170 bss->if_dynamic = drv->ifindex == drv->global->if_add_ifindex;
2171 bss->if_dynamic = bss->if_dynamic || drv->global->if_add_wdevid_set;
Dmitry Shmidt34af3062013-07-11 10:46:32 -07002172 drv->global->if_add_wdevid_set = 0;
2173
Dmitry Shmidt03658832014-08-13 11:03:49 -07002174 if (!bss->if_dynamic && nl80211_get_ifmode(bss) == NL80211_IFTYPE_AP)
2175 bss->static_ap = 1;
2176
Dmitry Shmidt34af3062013-07-11 10:46:32 -07002177 if (wpa_driver_nl80211_capa(drv))
2178 return -1;
2179
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002180 if (driver_params && nl80211_set_param(bss, driver_params) < 0)
2181 return -1;
2182
Dmitry Shmidt34af3062013-07-11 10:46:32 -07002183 wpa_printf(MSG_DEBUG, "nl80211: interface %s in phy %s",
2184 bss->ifname, drv->phyname);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002185
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08002186 if (set_addr &&
2187 (linux_set_iface_flags(drv->global->ioctl_sock, bss->ifname, 0) ||
2188 linux_set_ifhwaddr(drv->global->ioctl_sock, bss->ifname,
2189 set_addr)))
2190 return -1;
Dmitry Shmidt34af3062013-07-11 10:46:32 -07002191
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08002192 if (first && nl80211_get_ifmode(bss) == NL80211_IFTYPE_AP)
2193 drv->start_mode_ap = 1;
2194
Dmitry Shmidt03658832014-08-13 11:03:49 -07002195 if (drv->hostapd || bss->static_ap)
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08002196 nlmode = NL80211_IFTYPE_AP;
2197 else if (bss->if_dynamic)
2198 nlmode = nl80211_get_ifmode(bss);
2199 else
2200 nlmode = NL80211_IFTYPE_STATION;
2201
Dmitry Shmidt34af3062013-07-11 10:46:32 -07002202 if (wpa_driver_nl80211_set_mode(bss, nlmode) < 0) {
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08002203 wpa_printf(MSG_ERROR, "nl80211: Could not configure driver mode");
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002204 return -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002205 }
Dmitry Shmidt34af3062013-07-11 10:46:32 -07002206
Dmitry Shmidt98660862014-03-11 17:26:21 -07002207 if (nlmode == NL80211_IFTYPE_P2P_DEVICE)
Dmitry Shmidt34af3062013-07-11 10:46:32 -07002208 nl80211_get_macaddr(bss);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002209
Dmitry Shmidt98660862014-03-11 17:26:21 -07002210 if (!rfkill_is_blocked(drv->rfkill)) {
2211 int ret = i802_set_iface_flags(bss, 1);
2212 if (ret) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002213 wpa_printf(MSG_ERROR, "nl80211: Could not set "
2214 "interface '%s' UP", bss->ifname);
Dmitry Shmidt98660862014-03-11 17:26:21 -07002215 return ret;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002216 }
Dmitry Shmidt98660862014-03-11 17:26:21 -07002217 if (nlmode == NL80211_IFTYPE_P2P_DEVICE)
2218 return ret;
2219 } else {
2220 wpa_printf(MSG_DEBUG, "nl80211: Could not yet enable "
2221 "interface '%s' due to rfkill", bss->ifname);
2222 if (nlmode == NL80211_IFTYPE_P2P_DEVICE)
2223 return 0;
2224 drv->if_disabled = 1;
2225 send_rfkill_event = 1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002226 }
2227
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08002228 if (!drv->hostapd)
2229 netlink_send_oper_ifla(drv->global->netlink, drv->ifindex,
2230 1, IF_OPER_DORMANT);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002231
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002232 if (linux_get_ifhwaddr(drv->global->ioctl_sock, bss->ifname,
2233 bss->addr))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002234 return -1;
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07002235 os_memcpy(drv->perm_addr, bss->addr, ETH_ALEN);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002236
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002237 if (send_rfkill_event) {
2238 eloop_register_timeout(0, 0, wpa_driver_nl80211_send_rfkill,
2239 drv, drv->ctx);
2240 }
2241
Dmitry Shmidt7f656022015-02-25 14:36:37 -08002242 if (drv->vendor_cmd_test_avail)
2243 qca_vendor_test(drv);
2244
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002245 return 0;
2246}
2247
2248
2249static int wpa_driver_nl80211_del_beacon(struct wpa_driver_nl80211_data *drv)
2250{
2251 struct nl_msg *msg;
2252
Dmitry Shmidtcce06662013-11-04 18:44:24 -08002253 wpa_printf(MSG_DEBUG, "nl80211: Remove beacon (ifindex=%d)",
2254 drv->ifindex);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002255 msg = nl80211_drv_msg(drv, 0, NL80211_CMD_DEL_BEACON);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002256 return send_and_recv_msgs(drv, msg, NULL, NULL);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002257}
2258
2259
2260/**
2261 * wpa_driver_nl80211_deinit - Deinitialize nl80211 driver interface
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08002262 * @bss: Pointer to private nl80211 data from wpa_driver_nl80211_init()
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002263 *
2264 * Shut down driver interface and processing of driver events. Free
2265 * private data buffer if one was allocated in wpa_driver_nl80211_init().
2266 */
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08002267static void wpa_driver_nl80211_deinit(struct i802_bss *bss)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002268{
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002269 struct wpa_driver_nl80211_data *drv = bss->drv;
2270
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002271 wpa_printf(MSG_INFO, "nl80211: deinit ifname=%s disabled_11b_rates=%d",
2272 bss->ifname, drv->disabled_11b_rates);
2273
Dmitry Shmidt04949592012-07-19 12:16:46 -07002274 bss->in_deinit = 1;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002275 if (drv->data_tx_status)
2276 eloop_unregister_read_sock(drv->eapol_tx_sock);
2277 if (drv->eapol_tx_sock >= 0)
2278 close(drv->eapol_tx_sock);
2279
2280 if (bss->nl_preq)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002281 wpa_driver_nl80211_probe_req_report(bss, 0);
2282 if (bss->added_if_into_bridge) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002283 if (linux_br_del_if(drv->global->ioctl_sock, bss->brname,
2284 bss->ifname) < 0)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002285 wpa_printf(MSG_INFO, "nl80211: Failed to remove "
2286 "interface %s from bridge %s: %s",
2287 bss->ifname, bss->brname, strerror(errno));
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07002288 if (drv->rtnl_sk)
Dmitry Shmidt9ead16e2014-10-07 13:15:23 -07002289 nl80211_handle_destroy(drv->rtnl_sk);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002290 }
2291 if (bss->added_bridge) {
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002292 if (linux_set_iface_flags(drv->global->ioctl_sock, bss->brname,
2293 0) < 0)
2294 wpa_printf(MSG_INFO,
2295 "nl80211: Could not set bridge %s down",
2296 bss->brname);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002297 if (linux_br_del(drv->global->ioctl_sock, bss->brname) < 0)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002298 wpa_printf(MSG_INFO, "nl80211: Failed to remove "
2299 "bridge %s: %s",
2300 bss->brname, strerror(errno));
2301 }
2302
2303 nl80211_remove_monitor_interface(drv);
2304
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002305 if (is_ap_interface(drv->nlmode))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002306 wpa_driver_nl80211_del_beacon(drv);
2307
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002308 if (drv->eapol_sock >= 0) {
2309 eloop_unregister_read_sock(drv->eapol_sock);
2310 close(drv->eapol_sock);
2311 }
2312
2313 if (drv->if_indices != drv->default_if_indices)
2314 os_free(drv->if_indices);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002315
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002316 if (drv->disabled_11b_rates)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002317 nl80211_disable_11b_rates(drv, drv->ifindex, 0);
2318
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002319 netlink_send_oper_ifla(drv->global->netlink, drv->ifindex, 0,
2320 IF_OPER_UP);
Dmitry Shmidtb58836e2014-04-29 14:35:56 -07002321 eloop_cancel_timeout(wpa_driver_nl80211_send_rfkill, drv, drv->ctx);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002322 rfkill_deinit(drv->rfkill);
2323
2324 eloop_cancel_timeout(wpa_driver_nl80211_scan_timeout, drv, drv->ctx);
2325
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08002326 if (!drv->start_iface_up)
2327 (void) i802_set_iface_flags(bss, 0);
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07002328
2329 if (drv->addr_changed) {
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002330 if (linux_set_iface_flags(drv->global->ioctl_sock, bss->ifname,
2331 0) < 0) {
2332 wpa_printf(MSG_DEBUG,
2333 "nl80211: Could not set interface down to restore permanent MAC address");
2334 }
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07002335 if (linux_set_ifhwaddr(drv->global->ioctl_sock, bss->ifname,
2336 drv->perm_addr) < 0) {
2337 wpa_printf(MSG_DEBUG,
2338 "nl80211: Could not restore permanent MAC address");
2339 }
2340 }
2341
Dmitry Shmidt34af3062013-07-11 10:46:32 -07002342 if (drv->nlmode != NL80211_IFTYPE_P2P_DEVICE) {
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08002343 if (!drv->hostapd || !drv->start_mode_ap)
2344 wpa_driver_nl80211_set_mode(bss,
2345 NL80211_IFTYPE_STATION);
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -07002346 nl80211_mgmt_unsubscribe(bss, "deinit");
Dmitry Shmidt34af3062013-07-11 10:46:32 -07002347 } else {
2348 nl80211_mgmt_unsubscribe(bss, "deinit");
2349 nl80211_del_p2pdev(bss);
2350 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002351
Dmitry Shmidtcce06662013-11-04 18:44:24 -08002352 nl80211_destroy_bss(drv->first_bss);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002353
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002354 os_free(drv->filter_ssids);
2355
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002356 os_free(drv->auth_ie);
2357
2358 if (drv->in_interface_list)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002359 dl_list_del(&drv->list);
2360
Dmitry Shmidt444d5672013-04-01 13:08:44 -07002361 os_free(drv->extended_capa);
2362 os_free(drv->extended_capa_mask);
Dmitry Shmidtcce06662013-11-04 18:44:24 -08002363 os_free(drv->first_bss);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002364 os_free(drv);
2365}
2366
2367
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002368static u32 wpa_alg_to_cipher_suite(enum wpa_alg alg, size_t key_len)
2369{
2370 switch (alg) {
2371 case WPA_ALG_WEP:
2372 if (key_len == 5)
2373 return WLAN_CIPHER_SUITE_WEP40;
2374 return WLAN_CIPHER_SUITE_WEP104;
2375 case WPA_ALG_TKIP:
2376 return WLAN_CIPHER_SUITE_TKIP;
2377 case WPA_ALG_CCMP:
2378 return WLAN_CIPHER_SUITE_CCMP;
2379 case WPA_ALG_GCMP:
2380 return WLAN_CIPHER_SUITE_GCMP;
2381 case WPA_ALG_CCMP_256:
2382 return WLAN_CIPHER_SUITE_CCMP_256;
2383 case WPA_ALG_GCMP_256:
2384 return WLAN_CIPHER_SUITE_GCMP_256;
2385 case WPA_ALG_IGTK:
2386 return WLAN_CIPHER_SUITE_AES_CMAC;
2387 case WPA_ALG_BIP_GMAC_128:
2388 return WLAN_CIPHER_SUITE_BIP_GMAC_128;
2389 case WPA_ALG_BIP_GMAC_256:
2390 return WLAN_CIPHER_SUITE_BIP_GMAC_256;
2391 case WPA_ALG_BIP_CMAC_256:
2392 return WLAN_CIPHER_SUITE_BIP_CMAC_256;
2393 case WPA_ALG_SMS4:
2394 return WLAN_CIPHER_SUITE_SMS4;
2395 case WPA_ALG_KRK:
2396 return WLAN_CIPHER_SUITE_KRK;
2397 case WPA_ALG_NONE:
2398 case WPA_ALG_PMK:
2399 wpa_printf(MSG_ERROR, "nl80211: Unexpected encryption algorithm %d",
2400 alg);
2401 return 0;
2402 }
2403
2404 wpa_printf(MSG_ERROR, "nl80211: Unsupported encryption algorithm %d",
2405 alg);
2406 return 0;
2407}
2408
2409
2410static u32 wpa_cipher_to_cipher_suite(unsigned int cipher)
2411{
2412 switch (cipher) {
2413 case WPA_CIPHER_CCMP_256:
2414 return WLAN_CIPHER_SUITE_CCMP_256;
2415 case WPA_CIPHER_GCMP_256:
2416 return WLAN_CIPHER_SUITE_GCMP_256;
2417 case WPA_CIPHER_CCMP:
2418 return WLAN_CIPHER_SUITE_CCMP;
2419 case WPA_CIPHER_GCMP:
2420 return WLAN_CIPHER_SUITE_GCMP;
2421 case WPA_CIPHER_TKIP:
2422 return WLAN_CIPHER_SUITE_TKIP;
2423 case WPA_CIPHER_WEP104:
2424 return WLAN_CIPHER_SUITE_WEP104;
2425 case WPA_CIPHER_WEP40:
2426 return WLAN_CIPHER_SUITE_WEP40;
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08002427 case WPA_CIPHER_GTK_NOT_USED:
2428 return WLAN_CIPHER_SUITE_NO_GROUP_ADDR;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002429 }
2430
2431 return 0;
2432}
2433
2434
2435static int wpa_cipher_to_cipher_suites(unsigned int ciphers, u32 suites[],
2436 int max_suites)
2437{
2438 int num_suites = 0;
2439
2440 if (num_suites < max_suites && ciphers & WPA_CIPHER_CCMP_256)
2441 suites[num_suites++] = WLAN_CIPHER_SUITE_CCMP_256;
2442 if (num_suites < max_suites && ciphers & WPA_CIPHER_GCMP_256)
2443 suites[num_suites++] = WLAN_CIPHER_SUITE_GCMP_256;
2444 if (num_suites < max_suites && ciphers & WPA_CIPHER_CCMP)
2445 suites[num_suites++] = WLAN_CIPHER_SUITE_CCMP;
2446 if (num_suites < max_suites && ciphers & WPA_CIPHER_GCMP)
2447 suites[num_suites++] = WLAN_CIPHER_SUITE_GCMP;
2448 if (num_suites < max_suites && ciphers & WPA_CIPHER_TKIP)
2449 suites[num_suites++] = WLAN_CIPHER_SUITE_TKIP;
2450 if (num_suites < max_suites && ciphers & WPA_CIPHER_WEP104)
2451 suites[num_suites++] = WLAN_CIPHER_SUITE_WEP104;
2452 if (num_suites < max_suites && ciphers & WPA_CIPHER_WEP40)
2453 suites[num_suites++] = WLAN_CIPHER_SUITE_WEP40;
2454
2455 return num_suites;
2456}
2457
2458
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002459static int issue_key_mgmt_set_key(struct wpa_driver_nl80211_data *drv,
2460 const u8 *key, size_t key_len)
2461{
2462 struct nl_msg *msg;
2463 int ret;
2464
2465 if (!(drv->capa.flags & WPA_DRIVER_FLAGS_KEY_MGMT_OFFLOAD))
2466 return 0;
2467
2468 if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_VENDOR)) ||
2469 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
2470 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
2471 QCA_NL80211_VENDOR_SUBCMD_KEY_MGMT_SET_KEY) ||
2472 nla_put(msg, NL80211_ATTR_VENDOR_DATA, key_len, key)) {
2473 nl80211_nlmsg_clear(msg);
2474 nlmsg_free(msg);
2475 return -1;
2476 }
2477 ret = send_and_recv_msgs(drv, msg, NULL, (void *) -1);
2478 if (ret) {
2479 wpa_printf(MSG_DEBUG,
2480 "nl80211: Key management set key failed: ret=%d (%s)",
2481 ret, strerror(-ret));
2482 }
2483
2484 return ret;
2485}
2486
2487
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08002488static int wpa_driver_nl80211_set_key(const char *ifname, struct i802_bss *bss,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002489 enum wpa_alg alg, const u8 *addr,
2490 int key_idx, int set_tx,
2491 const u8 *seq, size_t seq_len,
2492 const u8 *key, size_t key_len)
2493{
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002494 struct wpa_driver_nl80211_data *drv = bss->drv;
Dmitry Shmidt34af3062013-07-11 10:46:32 -07002495 int ifindex;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002496 struct nl_msg *msg;
2497 int ret;
Dmitry Shmidtd5c075b2013-08-05 14:36:10 -07002498 int tdls = 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002499
Dmitry Shmidt34af3062013-07-11 10:46:32 -07002500 /* Ignore for P2P Device */
2501 if (drv->nlmode == NL80211_IFTYPE_P2P_DEVICE)
2502 return 0;
2503
2504 ifindex = if_nametoindex(ifname);
2505 wpa_printf(MSG_DEBUG, "%s: ifindex=%d (%s) alg=%d addr=%p key_idx=%d "
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002506 "set_tx=%d seq_len=%lu key_len=%lu",
Dmitry Shmidt34af3062013-07-11 10:46:32 -07002507 __func__, ifindex, ifname, alg, addr, key_idx, set_tx,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002508 (unsigned long) seq_len, (unsigned long) key_len);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002509#ifdef CONFIG_TDLS
Dmitry Shmidtd5c075b2013-08-05 14:36:10 -07002510 if (key_idx == -1) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002511 key_idx = 0;
Dmitry Shmidtd5c075b2013-08-05 14:36:10 -07002512 tdls = 1;
2513 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002514#endif /* CONFIG_TDLS */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002515
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002516 if (alg == WPA_ALG_PMK &&
2517 (drv->capa.flags & WPA_DRIVER_FLAGS_KEY_MGMT_OFFLOAD)) {
2518 wpa_printf(MSG_DEBUG, "%s: calling issue_key_mgmt_set_key",
2519 __func__);
2520 ret = issue_key_mgmt_set_key(drv, key, key_len);
2521 return ret;
2522 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002523
2524 if (alg == WPA_ALG_NONE) {
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002525 msg = nl80211_ifindex_msg(drv, ifindex, 0, NL80211_CMD_DEL_KEY);
2526 if (!msg)
2527 return -ENOBUFS;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002528 } else {
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002529 msg = nl80211_ifindex_msg(drv, ifindex, 0, NL80211_CMD_NEW_KEY);
2530 if (!msg ||
2531 nla_put(msg, NL80211_ATTR_KEY_DATA, key_len, key) ||
2532 nla_put_u32(msg, NL80211_ATTR_KEY_CIPHER,
2533 wpa_alg_to_cipher_suite(alg, key_len)))
2534 goto fail;
Dmitry Shmidt98660862014-03-11 17:26:21 -07002535 wpa_hexdump_key(MSG_DEBUG, "nl80211: KEY_DATA", key, key_len);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002536 }
2537
Dmitry Shmidt98660862014-03-11 17:26:21 -07002538 if (seq && seq_len) {
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002539 if (nla_put(msg, NL80211_ATTR_KEY_SEQ, seq_len, seq))
2540 goto fail;
Dmitry Shmidt98660862014-03-11 17:26:21 -07002541 wpa_hexdump(MSG_DEBUG, "nl80211: KEY_SEQ", seq, seq_len);
2542 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002543
2544 if (addr && !is_broadcast_ether_addr(addr)) {
2545 wpa_printf(MSG_DEBUG, " addr=" MACSTR, MAC2STR(addr));
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002546 if (nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr))
2547 goto fail;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002548
2549 if (alg != WPA_ALG_WEP && key_idx && !set_tx) {
2550 wpa_printf(MSG_DEBUG, " RSN IBSS RX GTK");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002551 if (nla_put_u32(msg, NL80211_ATTR_KEY_TYPE,
2552 NL80211_KEYTYPE_GROUP))
2553 goto fail;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002554 }
2555 } else if (addr && is_broadcast_ether_addr(addr)) {
Dmitry Shmidt8da800a2013-04-24 12:57:01 -07002556 struct nlattr *types;
2557
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002558 wpa_printf(MSG_DEBUG, " broadcast key");
Dmitry Shmidt8da800a2013-04-24 12:57:01 -07002559
2560 types = nla_nest_start(msg, NL80211_ATTR_KEY_DEFAULT_TYPES);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002561 if (!types ||
2562 nla_put_flag(msg, NL80211_KEY_DEFAULT_TYPE_MULTICAST))
2563 goto fail;
Dmitry Shmidt8da800a2013-04-24 12:57:01 -07002564 nla_nest_end(msg, types);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002565 }
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002566 if (nla_put_u8(msg, NL80211_ATTR_KEY_IDX, key_idx))
2567 goto fail;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002568
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002569 ret = send_and_recv_msgs(drv, msg, NULL, key ? (void *) -1 : NULL);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002570 if ((ret == -ENOENT || ret == -ENOLINK) && alg == WPA_ALG_NONE)
2571 ret = 0;
2572 if (ret)
2573 wpa_printf(MSG_DEBUG, "nl80211: set_key failed; err=%d %s)",
2574 ret, strerror(-ret));
2575
2576 /*
2577 * If we failed or don't need to set the default TX key (below),
2578 * we're done here.
2579 */
Dmitry Shmidtd5c075b2013-08-05 14:36:10 -07002580 if (ret || !set_tx || alg == WPA_ALG_NONE || tdls)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002581 return ret;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002582 if (is_ap_interface(drv->nlmode) && addr &&
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002583 !is_broadcast_ether_addr(addr))
2584 return ret;
2585
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002586 msg = nl80211_ifindex_msg(drv, ifindex, 0, NL80211_CMD_SET_KEY);
2587 if (!msg ||
2588 nla_put_u8(msg, NL80211_ATTR_KEY_IDX, key_idx) ||
Dmitry Shmidt807291d2015-01-27 13:40:23 -08002589 nla_put_flag(msg, (alg == WPA_ALG_IGTK ||
2590 alg == WPA_ALG_BIP_GMAC_128 ||
2591 alg == WPA_ALG_BIP_GMAC_256 ||
2592 alg == WPA_ALG_BIP_CMAC_256) ?
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002593 NL80211_ATTR_KEY_DEFAULT_MGMT :
2594 NL80211_ATTR_KEY_DEFAULT))
2595 goto fail;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002596 if (addr && is_broadcast_ether_addr(addr)) {
Dmitry Shmidt8da800a2013-04-24 12:57:01 -07002597 struct nlattr *types;
2598
2599 types = nla_nest_start(msg, NL80211_ATTR_KEY_DEFAULT_TYPES);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002600 if (!types ||
2601 nla_put_flag(msg, NL80211_KEY_DEFAULT_TYPE_MULTICAST))
2602 goto fail;
Dmitry Shmidt8da800a2013-04-24 12:57:01 -07002603 nla_nest_end(msg, types);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002604 } else if (addr) {
Dmitry Shmidt8da800a2013-04-24 12:57:01 -07002605 struct nlattr *types;
2606
2607 types = nla_nest_start(msg, NL80211_ATTR_KEY_DEFAULT_TYPES);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002608 if (!types ||
2609 nla_put_flag(msg, NL80211_KEY_DEFAULT_TYPE_UNICAST))
2610 goto fail;
Dmitry Shmidt8da800a2013-04-24 12:57:01 -07002611 nla_nest_end(msg, types);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002612 }
2613
2614 ret = send_and_recv_msgs(drv, msg, NULL, NULL);
2615 if (ret == -ENOENT)
2616 ret = 0;
2617 if (ret)
2618 wpa_printf(MSG_DEBUG, "nl80211: set_key default failed; "
2619 "err=%d %s)", ret, strerror(-ret));
2620 return ret;
2621
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002622fail:
2623 nl80211_nlmsg_clear(msg);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002624 nlmsg_free(msg);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002625 return -ENOBUFS;
2626}
2627
2628
2629static int nl_add_key(struct nl_msg *msg, enum wpa_alg alg,
2630 int key_idx, int defkey,
2631 const u8 *seq, size_t seq_len,
2632 const u8 *key, size_t key_len)
2633{
2634 struct nlattr *key_attr = nla_nest_start(msg, NL80211_ATTR_KEY);
2635 if (!key_attr)
2636 return -1;
2637
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002638 if (defkey && alg == WPA_ALG_IGTK) {
2639 if (nla_put_flag(msg, NL80211_KEY_DEFAULT_MGMT))
2640 return -1;
2641 } else if (defkey) {
2642 if (nla_put_flag(msg, NL80211_KEY_DEFAULT))
2643 return -1;
2644 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002645
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002646 if (nla_put_u8(msg, NL80211_KEY_IDX, key_idx) ||
2647 nla_put_u32(msg, NL80211_KEY_CIPHER,
2648 wpa_alg_to_cipher_suite(alg, key_len)) ||
2649 (seq && seq_len &&
2650 nla_put(msg, NL80211_KEY_SEQ, seq_len, seq)) ||
2651 nla_put(msg, NL80211_KEY_DATA, key_len, key))
2652 return -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002653
2654 nla_nest_end(msg, key_attr);
2655
2656 return 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002657}
2658
2659
2660static int nl80211_set_conn_keys(struct wpa_driver_associate_params *params,
2661 struct nl_msg *msg)
2662{
2663 int i, privacy = 0;
2664 struct nlattr *nl_keys, *nl_key;
2665
2666 for (i = 0; i < 4; i++) {
2667 if (!params->wep_key[i])
2668 continue;
2669 privacy = 1;
2670 break;
2671 }
2672 if (params->wps == WPS_MODE_PRIVACY)
2673 privacy = 1;
2674 if (params->pairwise_suite &&
2675 params->pairwise_suite != WPA_CIPHER_NONE)
2676 privacy = 1;
2677
2678 if (!privacy)
2679 return 0;
2680
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002681 if (nla_put_flag(msg, NL80211_ATTR_PRIVACY))
2682 return -ENOBUFS;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002683
2684 nl_keys = nla_nest_start(msg, NL80211_ATTR_KEYS);
2685 if (!nl_keys)
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002686 return -ENOBUFS;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002687
2688 for (i = 0; i < 4; i++) {
2689 if (!params->wep_key[i])
2690 continue;
2691
2692 nl_key = nla_nest_start(msg, i);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002693 if (!nl_key ||
2694 nla_put(msg, NL80211_KEY_DATA, params->wep_key_len[i],
2695 params->wep_key[i]) ||
2696 nla_put_u32(msg, NL80211_KEY_CIPHER,
2697 params->wep_key_len[i] == 5 ?
2698 WLAN_CIPHER_SUITE_WEP40 :
2699 WLAN_CIPHER_SUITE_WEP104) ||
2700 nla_put_u8(msg, NL80211_KEY_IDX, i) ||
2701 (i == params->wep_tx_keyidx &&
2702 nla_put_flag(msg, NL80211_KEY_DEFAULT)))
2703 return -ENOBUFS;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002704
2705 nla_nest_end(msg, nl_key);
2706 }
2707 nla_nest_end(msg, nl_keys);
2708
2709 return 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002710}
2711
2712
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002713int wpa_driver_nl80211_mlme(struct wpa_driver_nl80211_data *drv,
2714 const u8 *addr, int cmd, u16 reason_code,
2715 int local_state_change)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002716{
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002717 int ret;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002718 struct nl_msg *msg;
2719
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002720 if (!(msg = nl80211_drv_msg(drv, 0, cmd)) ||
2721 nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason_code) ||
2722 (addr && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) ||
2723 (local_state_change &&
2724 nla_put_flag(msg, NL80211_ATTR_LOCAL_STATE_CHANGE))) {
2725 nlmsg_free(msg);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002726 return -1;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002727 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002728
2729 ret = send_and_recv_msgs(drv, msg, NULL, NULL);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002730 if (ret) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002731 wpa_dbg(drv->ctx, MSG_DEBUG,
2732 "nl80211: MLME command failed: reason=%u ret=%d (%s)",
2733 reason_code, ret, strerror(-ret));
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002734 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002735 return ret;
2736}
2737
2738
2739static int wpa_driver_nl80211_disconnect(struct wpa_driver_nl80211_data *drv,
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08002740 int reason_code)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002741{
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07002742 int ret;
2743
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08002744 wpa_printf(MSG_DEBUG, "%s(reason_code=%d)", __func__, reason_code);
Dmitry Shmidt8bae4132013-06-06 11:25:10 -07002745 nl80211_mark_disconnected(drv);
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08002746 /* Disconnect command doesn't need BSSID - it uses cached value */
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07002747 ret = wpa_driver_nl80211_mlme(drv, NULL, NL80211_CMD_DISCONNECT,
2748 reason_code, 0);
2749 /*
2750 * For locally generated disconnect, supplicant already generates a
2751 * DEAUTH event, so ignore the event from NL80211.
2752 */
2753 drv->ignore_next_local_disconnect = ret == 0;
2754
2755 return ret;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002756}
2757
2758
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08002759static int wpa_driver_nl80211_deauthenticate(struct i802_bss *bss,
2760 const u8 *addr, int reason_code)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002761{
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002762 struct wpa_driver_nl80211_data *drv = bss->drv;
Dmitry Shmidt7dba0e52014-04-14 10:49:15 -07002763 int ret;
Dmitry Shmidt413dde72014-04-11 10:23:22 -07002764
2765 if (drv->nlmode == NL80211_IFTYPE_ADHOC) {
2766 nl80211_mark_disconnected(drv);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002767 return nl80211_leave_ibss(drv, 1);
Dmitry Shmidt413dde72014-04-11 10:23:22 -07002768 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002769 if (!(drv->capa.flags & WPA_DRIVER_FLAGS_SME))
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08002770 return wpa_driver_nl80211_disconnect(drv, reason_code);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002771 wpa_printf(MSG_DEBUG, "%s(addr=" MACSTR " reason_code=%d)",
2772 __func__, MAC2STR(addr), reason_code);
Dmitry Shmidt8bae4132013-06-06 11:25:10 -07002773 nl80211_mark_disconnected(drv);
Dmitry Shmidt7dba0e52014-04-14 10:49:15 -07002774 ret = wpa_driver_nl80211_mlme(drv, addr, NL80211_CMD_DEAUTHENTICATE,
2775 reason_code, 0);
2776 /*
2777 * For locally generated deauthenticate, supplicant already generates a
2778 * DEAUTH event, so ignore the event from NL80211.
2779 */
2780 drv->ignore_next_local_deauth = ret == 0;
2781 return ret;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002782}
2783
2784
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002785static void nl80211_copy_auth_params(struct wpa_driver_nl80211_data *drv,
2786 struct wpa_driver_auth_params *params)
2787{
2788 int i;
2789
2790 drv->auth_freq = params->freq;
2791 drv->auth_alg = params->auth_alg;
2792 drv->auth_wep_tx_keyidx = params->wep_tx_keyidx;
2793 drv->auth_local_state_change = params->local_state_change;
2794 drv->auth_p2p = params->p2p;
2795
2796 if (params->bssid)
2797 os_memcpy(drv->auth_bssid_, params->bssid, ETH_ALEN);
2798 else
2799 os_memset(drv->auth_bssid_, 0, ETH_ALEN);
2800
2801 if (params->ssid) {
2802 os_memcpy(drv->auth_ssid, params->ssid, params->ssid_len);
2803 drv->auth_ssid_len = params->ssid_len;
2804 } else
2805 drv->auth_ssid_len = 0;
2806
2807
2808 os_free(drv->auth_ie);
2809 drv->auth_ie = NULL;
2810 drv->auth_ie_len = 0;
2811 if (params->ie) {
2812 drv->auth_ie = os_malloc(params->ie_len);
2813 if (drv->auth_ie) {
2814 os_memcpy(drv->auth_ie, params->ie, params->ie_len);
2815 drv->auth_ie_len = params->ie_len;
2816 }
2817 }
2818
2819 for (i = 0; i < 4; i++) {
2820 if (params->wep_key[i] && params->wep_key_len[i] &&
2821 params->wep_key_len[i] <= 16) {
2822 os_memcpy(drv->auth_wep_key[i], params->wep_key[i],
2823 params->wep_key_len[i]);
2824 drv->auth_wep_key_len[i] = params->wep_key_len[i];
2825 } else
2826 drv->auth_wep_key_len[i] = 0;
2827 }
2828}
2829
2830
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002831static void nl80211_unmask_11b_rates(struct i802_bss *bss)
2832{
2833 struct wpa_driver_nl80211_data *drv = bss->drv;
2834
2835 if (is_p2p_net_interface(drv->nlmode) || !drv->disabled_11b_rates)
2836 return;
2837
2838 /*
2839 * Looks like we failed to unmask 11b rates previously. This could
2840 * happen, e.g., if the interface was down at the point in time when a
2841 * P2P group was terminated.
2842 */
2843 wpa_printf(MSG_DEBUG,
2844 "nl80211: Interface %s mode is for non-P2P, but 11b rates were disabled - re-enable them",
2845 bss->ifname);
2846 nl80211_disable_11b_rates(drv, drv->ifindex, 0);
2847}
2848
2849
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002850static int wpa_driver_nl80211_authenticate(
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08002851 struct i802_bss *bss, struct wpa_driver_auth_params *params)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002852{
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002853 struct wpa_driver_nl80211_data *drv = bss->drv;
2854 int ret = -1, i;
2855 struct nl_msg *msg;
2856 enum nl80211_auth_type type;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002857 enum nl80211_iftype nlmode;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002858 int count = 0;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002859 int is_retry;
2860
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002861 nl80211_unmask_11b_rates(bss);
2862
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002863 is_retry = drv->retry_auth;
2864 drv->retry_auth = 0;
Dmitry Shmidt98660862014-03-11 17:26:21 -07002865 drv->ignore_deauth_event = 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002866
Dmitry Shmidt8bae4132013-06-06 11:25:10 -07002867 nl80211_mark_disconnected(drv);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002868 os_memset(drv->auth_bssid, 0, ETH_ALEN);
Dmitry Shmidt8bae4132013-06-06 11:25:10 -07002869 if (params->bssid)
2870 os_memcpy(drv->auth_attempt_bssid, params->bssid, ETH_ALEN);
2871 else
2872 os_memset(drv->auth_attempt_bssid, 0, ETH_ALEN);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002873 /* FIX: IBSS mode */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002874 nlmode = params->p2p ?
2875 NL80211_IFTYPE_P2P_CLIENT : NL80211_IFTYPE_STATION;
2876 if (drv->nlmode != nlmode &&
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08002877 wpa_driver_nl80211_set_mode(bss, nlmode) < 0)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002878 return -1;
2879
2880retry:
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002881 wpa_printf(MSG_DEBUG, "nl80211: Authenticate (ifindex=%d)",
2882 drv->ifindex);
2883
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002884 msg = nl80211_drv_msg(drv, 0, NL80211_CMD_AUTHENTICATE);
2885 if (!msg)
2886 goto fail;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002887
2888 for (i = 0; i < 4; i++) {
2889 if (!params->wep_key[i])
2890 continue;
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08002891 wpa_driver_nl80211_set_key(bss->ifname, bss, WPA_ALG_WEP,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002892 NULL, i,
2893 i == params->wep_tx_keyidx, NULL, 0,
2894 params->wep_key[i],
2895 params->wep_key_len[i]);
2896 if (params->wep_tx_keyidx != i)
2897 continue;
2898 if (nl_add_key(msg, WPA_ALG_WEP, i, 1, NULL, 0,
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002899 params->wep_key[i], params->wep_key_len[i]))
2900 goto fail;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002901 }
2902
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002903 if (params->bssid) {
2904 wpa_printf(MSG_DEBUG, " * bssid=" MACSTR,
2905 MAC2STR(params->bssid));
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002906 if (nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, params->bssid))
2907 goto fail;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002908 }
2909 if (params->freq) {
2910 wpa_printf(MSG_DEBUG, " * freq=%d", params->freq);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002911 if (nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, params->freq))
2912 goto fail;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002913 }
2914 if (params->ssid) {
2915 wpa_hexdump_ascii(MSG_DEBUG, " * SSID",
2916 params->ssid, params->ssid_len);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002917 if (nla_put(msg, NL80211_ATTR_SSID, params->ssid_len,
2918 params->ssid))
2919 goto fail;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002920 }
2921 wpa_hexdump(MSG_DEBUG, " * IEs", params->ie, params->ie_len);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002922 if (params->ie &&
2923 nla_put(msg, NL80211_ATTR_IE, params->ie_len, params->ie))
2924 goto fail;
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08002925 if (params->sae_data) {
2926 wpa_hexdump(MSG_DEBUG, " * SAE data", params->sae_data,
2927 params->sae_data_len);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002928 if (nla_put(msg, NL80211_ATTR_SAE_DATA, params->sae_data_len,
2929 params->sae_data))
2930 goto fail;
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08002931 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002932 if (params->auth_alg & WPA_AUTH_ALG_OPEN)
2933 type = NL80211_AUTHTYPE_OPEN_SYSTEM;
2934 else if (params->auth_alg & WPA_AUTH_ALG_SHARED)
2935 type = NL80211_AUTHTYPE_SHARED_KEY;
2936 else if (params->auth_alg & WPA_AUTH_ALG_LEAP)
2937 type = NL80211_AUTHTYPE_NETWORK_EAP;
2938 else if (params->auth_alg & WPA_AUTH_ALG_FT)
2939 type = NL80211_AUTHTYPE_FT;
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08002940 else if (params->auth_alg & WPA_AUTH_ALG_SAE)
2941 type = NL80211_AUTHTYPE_SAE;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002942 else
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002943 goto fail;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002944 wpa_printf(MSG_DEBUG, " * Auth Type %d", type);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002945 if (nla_put_u32(msg, NL80211_ATTR_AUTH_TYPE, type))
2946 goto fail;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002947 if (params->local_state_change) {
2948 wpa_printf(MSG_DEBUG, " * Local state change only");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002949 if (nla_put_flag(msg, NL80211_ATTR_LOCAL_STATE_CHANGE))
2950 goto fail;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002951 }
2952
2953 ret = send_and_recv_msgs(drv, msg, NULL, NULL);
2954 msg = NULL;
2955 if (ret) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002956 wpa_dbg(drv->ctx, MSG_DEBUG,
2957 "nl80211: MLME command failed (auth): ret=%d (%s)",
2958 ret, strerror(-ret));
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002959 count++;
2960 if (ret == -EALREADY && count == 1 && params->bssid &&
2961 !params->local_state_change) {
2962 /*
2963 * mac80211 does not currently accept new
2964 * authentication if we are already authenticated. As a
2965 * workaround, force deauthentication and try again.
2966 */
2967 wpa_printf(MSG_DEBUG, "nl80211: Retry authentication "
2968 "after forced deauthentication");
Dmitry Shmidt98660862014-03-11 17:26:21 -07002969 drv->ignore_deauth_event = 1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002970 wpa_driver_nl80211_deauthenticate(
2971 bss, params->bssid,
2972 WLAN_REASON_PREV_AUTH_NOT_VALID);
2973 nlmsg_free(msg);
2974 goto retry;
2975 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002976
2977 if (ret == -ENOENT && params->freq && !is_retry) {
2978 /*
2979 * cfg80211 has likely expired the BSS entry even
2980 * though it was previously available in our internal
2981 * BSS table. To recover quickly, start a single
2982 * channel scan on the specified channel.
2983 */
2984 struct wpa_driver_scan_params scan;
2985 int freqs[2];
2986
2987 os_memset(&scan, 0, sizeof(scan));
2988 scan.num_ssids = 1;
2989 if (params->ssid) {
2990 scan.ssids[0].ssid = params->ssid;
2991 scan.ssids[0].ssid_len = params->ssid_len;
2992 }
2993 freqs[0] = params->freq;
2994 freqs[1] = 0;
2995 scan.freqs = freqs;
2996 wpa_printf(MSG_DEBUG, "nl80211: Trigger single "
2997 "channel scan to refresh cfg80211 BSS "
2998 "entry");
2999 ret = wpa_driver_nl80211_scan(bss, &scan);
3000 if (ret == 0) {
3001 nl80211_copy_auth_params(drv, params);
3002 drv->scan_for_auth = 1;
3003 }
3004 } else if (is_retry) {
3005 /*
3006 * Need to indicate this with an event since the return
3007 * value from the retry is not delivered to core code.
3008 */
3009 union wpa_event_data event;
3010 wpa_printf(MSG_DEBUG, "nl80211: Authentication retry "
3011 "failed");
3012 os_memset(&event, 0, sizeof(event));
3013 os_memcpy(event.timeout_event.addr, drv->auth_bssid_,
3014 ETH_ALEN);
3015 wpa_supplicant_event(drv->ctx, EVENT_AUTH_TIMED_OUT,
3016 &event);
3017 }
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003018 } else {
3019 wpa_printf(MSG_DEBUG,
3020 "nl80211: Authentication request send successfully");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003021 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003022
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003023fail:
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003024 nlmsg_free(msg);
3025 return ret;
3026}
3027
3028
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003029int wpa_driver_nl80211_authenticate_retry(struct wpa_driver_nl80211_data *drv)
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003030{
3031 struct wpa_driver_auth_params params;
Dmitry Shmidtcce06662013-11-04 18:44:24 -08003032 struct i802_bss *bss = drv->first_bss;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003033 int i;
3034
3035 wpa_printf(MSG_DEBUG, "nl80211: Try to authenticate again");
3036
3037 os_memset(&params, 0, sizeof(params));
3038 params.freq = drv->auth_freq;
3039 params.auth_alg = drv->auth_alg;
3040 params.wep_tx_keyidx = drv->auth_wep_tx_keyidx;
3041 params.local_state_change = drv->auth_local_state_change;
3042 params.p2p = drv->auth_p2p;
3043
3044 if (!is_zero_ether_addr(drv->auth_bssid_))
3045 params.bssid = drv->auth_bssid_;
3046
3047 if (drv->auth_ssid_len) {
3048 params.ssid = drv->auth_ssid;
3049 params.ssid_len = drv->auth_ssid_len;
3050 }
3051
3052 params.ie = drv->auth_ie;
3053 params.ie_len = drv->auth_ie_len;
3054
3055 for (i = 0; i < 4; i++) {
3056 if (drv->auth_wep_key_len[i]) {
3057 params.wep_key[i] = drv->auth_wep_key[i];
3058 params.wep_key_len[i] = drv->auth_wep_key_len[i];
3059 }
3060 }
3061
3062 drv->retry_auth = 1;
3063 return wpa_driver_nl80211_authenticate(bss, &params);
3064}
3065
3066
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003067static int wpa_driver_nl80211_send_frame(struct i802_bss *bss,
3068 const void *data, size_t len,
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08003069 int encrypt, int noack,
3070 unsigned int freq, int no_cck,
3071 int offchanok, unsigned int wait_time)
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003072{
3073 struct wpa_driver_nl80211_data *drv = bss->drv;
3074 u64 cookie;
Dmitry Shmidt051af732013-10-22 13:52:46 -07003075 int res;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003076
Dmitry Shmidt6dc03bd2014-05-16 10:40:13 -07003077 if (freq == 0 && drv->nlmode == NL80211_IFTYPE_ADHOC) {
3078 freq = nl80211_get_assoc_freq(drv);
3079 wpa_printf(MSG_DEBUG,
3080 "nl80211: send_frame - Use assoc_freq=%u for IBSS",
3081 freq);
3082 }
Dmitry Shmidt56052862013-10-04 10:23:25 -07003083 if (freq == 0) {
3084 wpa_printf(MSG_DEBUG, "nl80211: send_frame - Use bss->freq=%u",
3085 bss->freq);
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08003086 freq = bss->freq;
Dmitry Shmidt56052862013-10-04 10:23:25 -07003087 }
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08003088
Dmitry Shmidt56052862013-10-04 10:23:25 -07003089 if (drv->use_monitor) {
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003090 wpa_printf(MSG_DEBUG, "nl80211: send_frame(freq=%u bss->freq=%u) -> send_monitor",
Dmitry Shmidt56052862013-10-04 10:23:25 -07003091 freq, bss->freq);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003092 return nl80211_send_monitor(drv, data, len, encrypt, noack);
Dmitry Shmidt56052862013-10-04 10:23:25 -07003093 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003094
Dmitry Shmidt56052862013-10-04 10:23:25 -07003095 wpa_printf(MSG_DEBUG, "nl80211: send_frame -> send_frame_cmd");
Dmitry Shmidt051af732013-10-22 13:52:46 -07003096 res = nl80211_send_frame_cmd(bss, freq, wait_time, data, len,
3097 &cookie, no_cck, noack, offchanok);
3098 if (res == 0 && !noack) {
3099 const struct ieee80211_mgmt *mgmt;
3100 u16 fc;
3101
3102 mgmt = (const struct ieee80211_mgmt *) data;
3103 fc = le_to_host16(mgmt->frame_control);
3104 if (WLAN_FC_GET_TYPE(fc) == WLAN_FC_TYPE_MGMT &&
3105 WLAN_FC_GET_STYPE(fc) == WLAN_FC_STYPE_ACTION) {
3106 wpa_printf(MSG_MSGDUMP,
3107 "nl80211: Update send_action_cookie from 0x%llx to 0x%llx",
3108 (long long unsigned int)
3109 drv->send_action_cookie,
3110 (long long unsigned int) cookie);
3111 drv->send_action_cookie = cookie;
3112 }
3113 }
3114
3115 return res;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003116}
3117
3118
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08003119static int wpa_driver_nl80211_send_mlme(struct i802_bss *bss, const u8 *data,
3120 size_t data_len, int noack,
3121 unsigned int freq, int no_cck,
3122 int offchanok,
3123 unsigned int wait_time)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003124{
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003125 struct wpa_driver_nl80211_data *drv = bss->drv;
3126 struct ieee80211_mgmt *mgmt;
3127 int encrypt = 1;
3128 u16 fc;
3129
3130 mgmt = (struct ieee80211_mgmt *) data;
3131 fc = le_to_host16(mgmt->frame_control);
Dmitry Shmidt2271d3f2014-06-23 12:16:31 -07003132 wpa_printf(MSG_DEBUG, "nl80211: send_mlme - da= " MACSTR
3133 " noack=%d freq=%u no_cck=%d offchanok=%d wait_time=%u fc=0x%x (%s) nlmode=%d",
3134 MAC2STR(mgmt->da), noack, freq, no_cck, offchanok, wait_time,
3135 fc, fc2str(fc), drv->nlmode);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003136
Dmitry Shmidt34af3062013-07-11 10:46:32 -07003137 if ((is_sta_interface(drv->nlmode) ||
3138 drv->nlmode == NL80211_IFTYPE_P2P_DEVICE) &&
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003139 WLAN_FC_GET_TYPE(fc) == WLAN_FC_TYPE_MGMT &&
3140 WLAN_FC_GET_STYPE(fc) == WLAN_FC_STYPE_PROBE_RESP) {
3141 /*
3142 * The use of last_mgmt_freq is a bit of a hack,
3143 * but it works due to the single-threaded nature
3144 * of wpa_supplicant.
3145 */
Dmitry Shmidt56052862013-10-04 10:23:25 -07003146 if (freq == 0) {
3147 wpa_printf(MSG_DEBUG, "nl80211: Use last_mgmt_freq=%d",
3148 drv->last_mgmt_freq);
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08003149 freq = drv->last_mgmt_freq;
Dmitry Shmidt56052862013-10-04 10:23:25 -07003150 }
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08003151 return nl80211_send_frame_cmd(bss, freq, 0,
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003152 data, data_len, NULL, 1, noack,
3153 1);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003154 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003155
3156 if (drv->device_ap_sme && is_ap_interface(drv->nlmode)) {
Dmitry Shmidt56052862013-10-04 10:23:25 -07003157 if (freq == 0) {
3158 wpa_printf(MSG_DEBUG, "nl80211: Use bss->freq=%d",
3159 bss->freq);
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08003160 freq = bss->freq;
Dmitry Shmidt56052862013-10-04 10:23:25 -07003161 }
Dmitry Shmidt04949592012-07-19 12:16:46 -07003162 return nl80211_send_frame_cmd(bss, freq,
3163 (int) freq == bss->freq ? 0 :
3164 wait_time,
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08003165 data, data_len,
3166 &drv->send_action_cookie,
3167 no_cck, noack, offchanok);
Dmitry Shmidt6e933c12011-09-27 12:29:26 -07003168 }
Dmitry Shmidtb638fe72012-03-20 12:51:25 -07003169
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003170 if (WLAN_FC_GET_TYPE(fc) == WLAN_FC_TYPE_MGMT &&
3171 WLAN_FC_GET_STYPE(fc) == WLAN_FC_STYPE_AUTH) {
3172 /*
3173 * Only one of the authentication frame types is encrypted.
3174 * In order for static WEP encryption to work properly (i.e.,
3175 * to not encrypt the frame), we need to tell mac80211 about
3176 * the frames that must not be encrypted.
3177 */
3178 u16 auth_alg = le_to_host16(mgmt->u.auth.auth_alg);
3179 u16 auth_trans = le_to_host16(mgmt->u.auth.auth_transaction);
3180 if (auth_alg != WLAN_AUTH_SHARED_KEY || auth_trans != 3)
3181 encrypt = 0;
3182 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003183
Dmitry Shmidt56052862013-10-04 10:23:25 -07003184 wpa_printf(MSG_DEBUG, "nl80211: send_mlme -> send_frame");
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003185 return wpa_driver_nl80211_send_frame(bss, data, data_len, encrypt,
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08003186 noack, freq, no_cck, offchanok,
3187 wait_time);
3188}
3189
3190
Dmitry Shmidtff787d52015-01-12 13:01:47 -08003191static int nl80211_put_basic_rates(struct nl_msg *msg, const int *basic_rates)
3192{
3193 u8 rates[NL80211_MAX_SUPP_RATES];
3194 u8 rates_len = 0;
3195 int i;
3196
3197 if (!basic_rates)
3198 return 0;
3199
3200 for (i = 0; i < NL80211_MAX_SUPP_RATES && basic_rates[i] >= 0; i++)
3201 rates[rates_len++] = basic_rates[i] / 5;
3202
3203 return nla_put(msg, NL80211_ATTR_BSS_BASIC_RATES, rates_len, rates);
3204}
3205
3206
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003207static int nl80211_set_bss(struct i802_bss *bss, int cts, int preamble,
3208 int slot, int ht_opmode, int ap_isolate,
Dmitry Shmidtff787d52015-01-12 13:01:47 -08003209 const int *basic_rates)
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003210{
3211 struct wpa_driver_nl80211_data *drv = bss->drv;
3212 struct nl_msg *msg;
3213
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003214 if (!(msg = nl80211_bss_msg(bss, 0, NL80211_CMD_SET_BSS)) ||
3215 (cts >= 0 &&
3216 nla_put_u8(msg, NL80211_ATTR_BSS_CTS_PROT, cts)) ||
3217 (preamble >= 0 &&
3218 nla_put_u8(msg, NL80211_ATTR_BSS_SHORT_PREAMBLE, preamble)) ||
3219 (slot >= 0 &&
3220 nla_put_u8(msg, NL80211_ATTR_BSS_SHORT_SLOT_TIME, slot)) ||
3221 (ht_opmode >= 0 &&
3222 nla_put_u16(msg, NL80211_ATTR_BSS_HT_OPMODE, ht_opmode)) ||
3223 (ap_isolate >= 0 &&
Dmitry Shmidtff787d52015-01-12 13:01:47 -08003224 nla_put_u8(msg, NL80211_ATTR_AP_ISOLATE, ap_isolate)) ||
3225 nl80211_put_basic_rates(msg, basic_rates)) {
3226 nlmsg_free(msg);
3227 return -ENOBUFS;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003228 }
3229
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003230 return send_and_recv_msgs(drv, msg, NULL, NULL);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003231}
3232
3233
Dmitry Shmidt8bae4132013-06-06 11:25:10 -07003234static int wpa_driver_nl80211_set_acl(void *priv,
3235 struct hostapd_acl_params *params)
3236{
3237 struct i802_bss *bss = priv;
3238 struct wpa_driver_nl80211_data *drv = bss->drv;
3239 struct nl_msg *msg;
3240 struct nlattr *acl;
3241 unsigned int i;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003242 int ret;
Dmitry Shmidt8bae4132013-06-06 11:25:10 -07003243
3244 if (!(drv->capa.max_acl_mac_addrs))
3245 return -ENOTSUP;
3246
3247 if (params->num_mac_acl > drv->capa.max_acl_mac_addrs)
3248 return -ENOTSUP;
3249
Dmitry Shmidt8bae4132013-06-06 11:25:10 -07003250 wpa_printf(MSG_DEBUG, "nl80211: Set %s ACL (num_mac_acl=%u)",
3251 params->acl_policy ? "Accept" : "Deny", params->num_mac_acl);
3252
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003253 if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_SET_MAC_ACL)) ||
3254 nla_put_u32(msg, NL80211_ATTR_ACL_POLICY, params->acl_policy ?
3255 NL80211_ACL_POLICY_DENY_UNLESS_LISTED :
3256 NL80211_ACL_POLICY_ACCEPT_UNLESS_LISTED) ||
3257 (acl = nla_nest_start(msg, NL80211_ATTR_MAC_ADDRS)) == NULL) {
3258 nlmsg_free(msg);
3259 return -ENOMEM;
3260 }
Dmitry Shmidt8bae4132013-06-06 11:25:10 -07003261
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003262 for (i = 0; i < params->num_mac_acl; i++) {
3263 if (nla_put(msg, i + 1, ETH_ALEN, params->mac_acl[i].addr)) {
3264 nlmsg_free(msg);
3265 return -ENOMEM;
3266 }
3267 }
Dmitry Shmidt8bae4132013-06-06 11:25:10 -07003268
3269 nla_nest_end(msg, acl);
3270
3271 ret = send_and_recv_msgs(drv, msg, NULL, NULL);
Dmitry Shmidt8bae4132013-06-06 11:25:10 -07003272 if (ret) {
3273 wpa_printf(MSG_DEBUG, "nl80211: Failed to set MAC ACL: %d (%s)",
3274 ret, strerror(-ret));
3275 }
3276
Dmitry Shmidt8bae4132013-06-06 11:25:10 -07003277 return ret;
3278}
3279
3280
Dmitry Shmidtff787d52015-01-12 13:01:47 -08003281static int nl80211_put_beacon_int(struct nl_msg *msg, int beacon_int)
3282{
3283 if (beacon_int > 0) {
3284 wpa_printf(MSG_DEBUG, " * beacon_int=%d", beacon_int);
3285 return nla_put_u32(msg, NL80211_ATTR_BEACON_INTERVAL,
3286 beacon_int);
3287 }
3288
3289 return 0;
3290}
3291
3292
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003293static int wpa_driver_nl80211_set_ap(void *priv,
3294 struct wpa_driver_ap_params *params)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003295{
3296 struct i802_bss *bss = priv;
3297 struct wpa_driver_nl80211_data *drv = bss->drv;
3298 struct nl_msg *msg;
3299 u8 cmd = NL80211_CMD_NEW_BEACON;
3300 int ret;
3301 int beacon_set;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003302 int num_suites;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003303 int smps_mode;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08003304 u32 suites[10], suite;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003305 u32 ver;
3306
Dmitry Shmidt7f656022015-02-25 14:36:37 -08003307 beacon_set = params->reenable ? 0 : bss->beacon_set;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003308
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003309 wpa_printf(MSG_DEBUG, "nl80211: Set beacon (beacon_set=%d)",
3310 beacon_set);
3311 if (beacon_set)
3312 cmd = NL80211_CMD_SET_BEACON;
3313
Dmitry Shmidt0ccb66e2013-03-29 16:41:28 -07003314 wpa_hexdump(MSG_DEBUG, "nl80211: Beacon head",
3315 params->head, params->head_len);
Dmitry Shmidt0ccb66e2013-03-29 16:41:28 -07003316 wpa_hexdump(MSG_DEBUG, "nl80211: Beacon tail",
3317 params->tail, params->tail_len);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003318 wpa_printf(MSG_DEBUG, "nl80211: ifindex=%d", bss->ifindex);
Dmitry Shmidt0ccb66e2013-03-29 16:41:28 -07003319 wpa_printf(MSG_DEBUG, "nl80211: beacon_int=%d", params->beacon_int);
Dmitry Shmidt0ccb66e2013-03-29 16:41:28 -07003320 wpa_printf(MSG_DEBUG, "nl80211: dtim_period=%d", params->dtim_period);
Dmitry Shmidt0ccb66e2013-03-29 16:41:28 -07003321 wpa_hexdump_ascii(MSG_DEBUG, "nl80211: ssid",
3322 params->ssid, params->ssid_len);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003323 if (!(msg = nl80211_bss_msg(bss, 0, cmd)) ||
3324 nla_put(msg, NL80211_ATTR_BEACON_HEAD, params->head_len,
3325 params->head) ||
3326 nla_put(msg, NL80211_ATTR_BEACON_TAIL, params->tail_len,
3327 params->tail) ||
Dmitry Shmidtff787d52015-01-12 13:01:47 -08003328 nl80211_put_beacon_int(msg, params->beacon_int) ||
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003329 nla_put_u32(msg, NL80211_ATTR_DTIM_PERIOD, params->dtim_period) ||
3330 nla_put(msg, NL80211_ATTR_SSID, params->ssid_len, params->ssid))
3331 goto fail;
Dmitry Shmidt0ccb66e2013-03-29 16:41:28 -07003332 if (params->proberesp && params->proberesp_len) {
3333 wpa_hexdump(MSG_DEBUG, "nl80211: proberesp (offload)",
3334 params->proberesp, params->proberesp_len);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003335 if (nla_put(msg, NL80211_ATTR_PROBE_RESP, params->proberesp_len,
3336 params->proberesp))
3337 goto fail;
Dmitry Shmidt0ccb66e2013-03-29 16:41:28 -07003338 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003339 switch (params->hide_ssid) {
3340 case NO_SSID_HIDING:
Dmitry Shmidt0ccb66e2013-03-29 16:41:28 -07003341 wpa_printf(MSG_DEBUG, "nl80211: hidden SSID not in use");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003342 if (nla_put_u32(msg, NL80211_ATTR_HIDDEN_SSID,
3343 NL80211_HIDDEN_SSID_NOT_IN_USE))
3344 goto fail;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003345 break;
3346 case HIDDEN_SSID_ZERO_LEN:
Dmitry Shmidt0ccb66e2013-03-29 16:41:28 -07003347 wpa_printf(MSG_DEBUG, "nl80211: hidden SSID zero len");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003348 if (nla_put_u32(msg, NL80211_ATTR_HIDDEN_SSID,
3349 NL80211_HIDDEN_SSID_ZERO_LEN))
3350 goto fail;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003351 break;
3352 case HIDDEN_SSID_ZERO_CONTENTS:
Dmitry Shmidt0ccb66e2013-03-29 16:41:28 -07003353 wpa_printf(MSG_DEBUG, "nl80211: hidden SSID zero contents");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003354 if (nla_put_u32(msg, NL80211_ATTR_HIDDEN_SSID,
3355 NL80211_HIDDEN_SSID_ZERO_CONTENTS))
3356 goto fail;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003357 break;
3358 }
Dmitry Shmidt0ccb66e2013-03-29 16:41:28 -07003359 wpa_printf(MSG_DEBUG, "nl80211: privacy=%d", params->privacy);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003360 if (params->privacy &&
3361 nla_put_flag(msg, NL80211_ATTR_PRIVACY))
3362 goto fail;
Dmitry Shmidt0ccb66e2013-03-29 16:41:28 -07003363 wpa_printf(MSG_DEBUG, "nl80211: auth_algs=0x%x", params->auth_algs);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003364 if ((params->auth_algs & (WPA_AUTH_ALG_OPEN | WPA_AUTH_ALG_SHARED)) ==
3365 (WPA_AUTH_ALG_OPEN | WPA_AUTH_ALG_SHARED)) {
3366 /* Leave out the attribute */
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003367 } else if (params->auth_algs & WPA_AUTH_ALG_SHARED) {
3368 if (nla_put_u32(msg, NL80211_ATTR_AUTH_TYPE,
3369 NL80211_AUTHTYPE_SHARED_KEY))
3370 goto fail;
3371 } else {
3372 if (nla_put_u32(msg, NL80211_ATTR_AUTH_TYPE,
3373 NL80211_AUTHTYPE_OPEN_SYSTEM))
3374 goto fail;
3375 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003376
Dmitry Shmidt0ccb66e2013-03-29 16:41:28 -07003377 wpa_printf(MSG_DEBUG, "nl80211: wpa_version=0x%x", params->wpa_version);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003378 ver = 0;
3379 if (params->wpa_version & WPA_PROTO_WPA)
3380 ver |= NL80211_WPA_VERSION_1;
3381 if (params->wpa_version & WPA_PROTO_RSN)
3382 ver |= NL80211_WPA_VERSION_2;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003383 if (ver &&
3384 nla_put_u32(msg, NL80211_ATTR_WPA_VERSIONS, ver))
3385 goto fail;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003386
Dmitry Shmidt0ccb66e2013-03-29 16:41:28 -07003387 wpa_printf(MSG_DEBUG, "nl80211: key_mgmt_suites=0x%x",
3388 params->key_mgmt_suites);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003389 num_suites = 0;
3390 if (params->key_mgmt_suites & WPA_KEY_MGMT_IEEE8021X)
3391 suites[num_suites++] = WLAN_AKM_SUITE_8021X;
3392 if (params->key_mgmt_suites & WPA_KEY_MGMT_PSK)
3393 suites[num_suites++] = WLAN_AKM_SUITE_PSK;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003394 if (num_suites &&
3395 nla_put(msg, NL80211_ATTR_AKM_SUITES, num_suites * sizeof(u32),
3396 suites))
3397 goto fail;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003398
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003399 if (params->key_mgmt_suites & WPA_KEY_MGMT_IEEE8021X_NO_WPA &&
3400 params->pairwise_ciphers & (WPA_CIPHER_WEP104 | WPA_CIPHER_WEP40) &&
3401 nla_put_flag(msg, NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT))
3402 goto fail;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003403
Dmitry Shmidt0ccb66e2013-03-29 16:41:28 -07003404 wpa_printf(MSG_DEBUG, "nl80211: pairwise_ciphers=0x%x",
3405 params->pairwise_ciphers);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08003406 num_suites = wpa_cipher_to_cipher_suites(params->pairwise_ciphers,
3407 suites, ARRAY_SIZE(suites));
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003408 if (num_suites &&
3409 nla_put(msg, NL80211_ATTR_CIPHER_SUITES_PAIRWISE,
3410 num_suites * sizeof(u32), suites))
3411 goto fail;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003412
Dmitry Shmidt0ccb66e2013-03-29 16:41:28 -07003413 wpa_printf(MSG_DEBUG, "nl80211: group_cipher=0x%x",
3414 params->group_cipher);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08003415 suite = wpa_cipher_to_cipher_suite(params->group_cipher);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003416 if (suite &&
3417 nla_put_u32(msg, NL80211_ATTR_CIPHER_SUITE_GROUP, suite))
3418 goto fail;
3419
3420 switch (params->smps_mode) {
3421 case HT_CAP_INFO_SMPS_DYNAMIC:
3422 wpa_printf(MSG_DEBUG, "nl80211: SMPS mode - dynamic");
3423 smps_mode = NL80211_SMPS_DYNAMIC;
3424 break;
3425 case HT_CAP_INFO_SMPS_STATIC:
3426 wpa_printf(MSG_DEBUG, "nl80211: SMPS mode - static");
3427 smps_mode = NL80211_SMPS_STATIC;
3428 break;
3429 default:
3430 /* invalid - fallback to smps off */
3431 case HT_CAP_INFO_SMPS_DISABLED:
3432 wpa_printf(MSG_DEBUG, "nl80211: SMPS mode - off");
3433 smps_mode = NL80211_SMPS_OFF;
3434 break;
3435 }
3436 if (nla_put_u32(msg, NL80211_ATTR_SMPS_MODE, smps_mode))
3437 goto fail;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003438
3439 if (params->beacon_ies) {
Dmitry Shmidt0ccb66e2013-03-29 16:41:28 -07003440 wpa_hexdump_buf(MSG_DEBUG, "nl80211: beacon_ies",
3441 params->beacon_ies);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003442 if (nla_put(msg, NL80211_ATTR_IE,
3443 wpabuf_len(params->beacon_ies),
3444 wpabuf_head(params->beacon_ies)))
3445 goto fail;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003446 }
3447 if (params->proberesp_ies) {
Dmitry Shmidt0ccb66e2013-03-29 16:41:28 -07003448 wpa_hexdump_buf(MSG_DEBUG, "nl80211: proberesp_ies",
3449 params->proberesp_ies);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003450 if (nla_put(msg, NL80211_ATTR_IE_PROBE_RESP,
3451 wpabuf_len(params->proberesp_ies),
3452 wpabuf_head(params->proberesp_ies)))
3453 goto fail;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003454 }
3455 if (params->assocresp_ies) {
Dmitry Shmidt0ccb66e2013-03-29 16:41:28 -07003456 wpa_hexdump_buf(MSG_DEBUG, "nl80211: assocresp_ies",
3457 params->assocresp_ies);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003458 if (nla_put(msg, NL80211_ATTR_IE_ASSOC_RESP,
3459 wpabuf_len(params->assocresp_ies),
3460 wpabuf_head(params->assocresp_ies)))
3461 goto fail;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003462 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003463
Dmitry Shmidt04949592012-07-19 12:16:46 -07003464 if (drv->capa.flags & WPA_DRIVER_FLAGS_INACTIVITY_TIMER) {
Dmitry Shmidt0ccb66e2013-03-29 16:41:28 -07003465 wpa_printf(MSG_DEBUG, "nl80211: ap_max_inactivity=%d",
3466 params->ap_max_inactivity);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003467 if (nla_put_u16(msg, NL80211_ATTR_INACTIVITY_TIMEOUT,
3468 params->ap_max_inactivity))
3469 goto fail;
Dmitry Shmidt04949592012-07-19 12:16:46 -07003470 }
3471
Dmitry Shmidt7f656022015-02-25 14:36:37 -08003472#ifdef CONFIG_P2P
3473 if (params->p2p_go_ctwindow > 0) {
3474 if (drv->p2p_go_ctwindow_supported) {
3475 wpa_printf(MSG_DEBUG, "nl80211: P2P GO ctwindow=%d",
3476 params->p2p_go_ctwindow);
3477 if (nla_put_u8(msg, NL80211_ATTR_P2P_CTWINDOW,
3478 params->p2p_go_ctwindow))
3479 goto fail;
3480 } else {
3481 wpa_printf(MSG_INFO,
3482 "nl80211: Driver does not support CTWindow configuration - ignore this parameter");
3483 }
3484 }
3485#endif /* CONFIG_P2P */
3486
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003487 ret = send_and_recv_msgs(drv, msg, NULL, NULL);
3488 if (ret) {
3489 wpa_printf(MSG_DEBUG, "nl80211: Beacon set failed: %d (%s)",
3490 ret, strerror(-ret));
3491 } else {
3492 bss->beacon_set = 1;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003493 nl80211_set_bss(bss, params->cts_protect, params->preamble,
3494 params->short_slot_time, params->ht_opmode,
3495 params->isolate, params->basic_rates);
Dmitry Shmidt7832adb2014-04-29 10:53:02 -07003496 if (beacon_set && params->freq &&
3497 params->freq->bandwidth != bss->bandwidth) {
3498 wpa_printf(MSG_DEBUG,
3499 "nl80211: Update BSS %s bandwidth: %d -> %d",
3500 bss->ifname, bss->bandwidth,
3501 params->freq->bandwidth);
3502 ret = nl80211_set_channel(bss, params->freq, 1);
3503 if (ret) {
3504 wpa_printf(MSG_DEBUG,
3505 "nl80211: Frequency set failed: %d (%s)",
3506 ret, strerror(-ret));
3507 } else {
3508 wpa_printf(MSG_DEBUG,
3509 "nl80211: Frequency set succeeded for ht2040 coex");
3510 bss->bandwidth = params->freq->bandwidth;
3511 }
3512 } else if (!beacon_set) {
3513 /*
3514 * cfg80211 updates the driver on frequence change in AP
3515 * mode only at the point when beaconing is started, so
3516 * set the initial value here.
3517 */
3518 bss->bandwidth = params->freq->bandwidth;
3519 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003520 }
3521 return ret;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003522fail:
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003523 nlmsg_free(msg);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003524 return -ENOBUFS;
3525}
3526
3527
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08003528static int nl80211_put_freq_params(struct nl_msg *msg,
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003529 const struct hostapd_freq_params *freq)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003530{
Dmitry Shmidtff787d52015-01-12 13:01:47 -08003531 wpa_printf(MSG_DEBUG, " * freq=%d", freq->freq);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003532 if (nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq->freq))
3533 return -ENOBUFS;
3534
Dmitry Shmidtff787d52015-01-12 13:01:47 -08003535 wpa_printf(MSG_DEBUG, " * vht_enabled=%d", freq->vht_enabled);
3536 wpa_printf(MSG_DEBUG, " * ht_enabled=%d", freq->ht_enabled);
3537
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08003538 if (freq->vht_enabled) {
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003539 enum nl80211_chan_width cw;
3540
Dmitry Shmidtff787d52015-01-12 13:01:47 -08003541 wpa_printf(MSG_DEBUG, " * bandwidth=%d", freq->bandwidth);
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08003542 switch (freq->bandwidth) {
3543 case 20:
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003544 cw = NL80211_CHAN_WIDTH_20;
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08003545 break;
3546 case 40:
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003547 cw = NL80211_CHAN_WIDTH_40;
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08003548 break;
3549 case 80:
3550 if (freq->center_freq2)
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003551 cw = NL80211_CHAN_WIDTH_80P80;
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08003552 else
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003553 cw = NL80211_CHAN_WIDTH_80;
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08003554 break;
3555 case 160:
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003556 cw = NL80211_CHAN_WIDTH_160;
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08003557 break;
3558 default:
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08003559 return -EINVAL;
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08003560 }
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003561
Dmitry Shmidtff787d52015-01-12 13:01:47 -08003562 wpa_printf(MSG_DEBUG, " * channel_width=%d", cw);
3563 wpa_printf(MSG_DEBUG, " * center_freq1=%d",
3564 freq->center_freq1);
3565 wpa_printf(MSG_DEBUG, " * center_freq2=%d",
3566 freq->center_freq2);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003567 if (nla_put_u32(msg, NL80211_ATTR_CHANNEL_WIDTH, cw) ||
3568 nla_put_u32(msg, NL80211_ATTR_CENTER_FREQ1,
3569 freq->center_freq1) ||
3570 (freq->center_freq2 &&
3571 nla_put_u32(msg, NL80211_ATTR_CENTER_FREQ2,
3572 freq->center_freq2)))
3573 return -ENOBUFS;
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08003574 } else if (freq->ht_enabled) {
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003575 enum nl80211_channel_type ct;
3576
Dmitry Shmidtff787d52015-01-12 13:01:47 -08003577 wpa_printf(MSG_DEBUG, " * sec_channel_offset=%d",
3578 freq->sec_channel_offset);
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08003579 switch (freq->sec_channel_offset) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003580 case -1:
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003581 ct = NL80211_CHAN_HT40MINUS;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003582 break;
3583 case 1:
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003584 ct = NL80211_CHAN_HT40PLUS;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003585 break;
3586 default:
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003587 ct = NL80211_CHAN_HT20;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003588 break;
3589 }
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003590
Dmitry Shmidtff787d52015-01-12 13:01:47 -08003591 wpa_printf(MSG_DEBUG, " * channel_type=%d", ct);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003592 if (nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE, ct))
3593 return -ENOBUFS;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003594 }
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08003595 return 0;
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08003596}
3597
3598
Dmitry Shmidt7832adb2014-04-29 10:53:02 -07003599static int nl80211_set_channel(struct i802_bss *bss,
3600 struct hostapd_freq_params *freq, int set_chan)
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08003601{
3602 struct wpa_driver_nl80211_data *drv = bss->drv;
3603 struct nl_msg *msg;
3604 int ret;
3605
3606 wpa_printf(MSG_DEBUG,
3607 "nl80211: Set freq %d (ht_enabled=%d, vht_enabled=%d, bandwidth=%d MHz, cf1=%d MHz, cf2=%d MHz)",
3608 freq->freq, freq->ht_enabled, freq->vht_enabled,
3609 freq->bandwidth, freq->center_freq1, freq->center_freq2);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003610
3611 msg = nl80211_drv_msg(drv, 0, set_chan ? NL80211_CMD_SET_CHANNEL :
3612 NL80211_CMD_SET_WIPHY);
3613 if (!msg || nl80211_put_freq_params(msg, freq) < 0) {
3614 nlmsg_free(msg);
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08003615 return -1;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003616 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003617
3618 ret = send_and_recv_msgs(drv, msg, NULL, NULL);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003619 if (ret == 0) {
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08003620 bss->freq = freq->freq;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003621 return 0;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003622 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003623 wpa_printf(MSG_DEBUG, "nl80211: Failed to set channel (freq=%d): "
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08003624 "%d (%s)", freq->freq, ret, strerror(-ret));
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003625 return -1;
3626}
3627
3628
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003629static u32 sta_flags_nl80211(int flags)
3630{
3631 u32 f = 0;
3632
3633 if (flags & WPA_STA_AUTHORIZED)
3634 f |= BIT(NL80211_STA_FLAG_AUTHORIZED);
3635 if (flags & WPA_STA_WMM)
3636 f |= BIT(NL80211_STA_FLAG_WME);
3637 if (flags & WPA_STA_SHORT_PREAMBLE)
3638 f |= BIT(NL80211_STA_FLAG_SHORT_PREAMBLE);
3639 if (flags & WPA_STA_MFP)
3640 f |= BIT(NL80211_STA_FLAG_MFP);
3641 if (flags & WPA_STA_TDLS_PEER)
3642 f |= BIT(NL80211_STA_FLAG_TDLS_PEER);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003643 if (flags & WPA_STA_AUTHENTICATED)
3644 f |= BIT(NL80211_STA_FLAG_AUTHENTICATED);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003645
3646 return f;
3647}
3648
3649
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003650#ifdef CONFIG_MESH
3651static u32 sta_plink_state_nl80211(enum mesh_plink_state state)
3652{
3653 switch (state) {
3654 case PLINK_LISTEN:
3655 return NL80211_PLINK_LISTEN;
3656 case PLINK_OPEN_SENT:
3657 return NL80211_PLINK_OPN_SNT;
3658 case PLINK_OPEN_RCVD:
3659 return NL80211_PLINK_OPN_RCVD;
3660 case PLINK_CNF_RCVD:
3661 return NL80211_PLINK_CNF_RCVD;
3662 case PLINK_ESTAB:
3663 return NL80211_PLINK_ESTAB;
3664 case PLINK_HOLDING:
3665 return NL80211_PLINK_HOLDING;
3666 case PLINK_BLOCKED:
3667 return NL80211_PLINK_BLOCKED;
3668 default:
3669 wpa_printf(MSG_ERROR, "nl80211: Invalid mesh plink state %d",
3670 state);
3671 }
3672 return -1;
3673}
3674#endif /* CONFIG_MESH */
3675
3676
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003677static int wpa_driver_nl80211_sta_add(void *priv,
3678 struct hostapd_sta_add_params *params)
3679{
3680 struct i802_bss *bss = priv;
3681 struct wpa_driver_nl80211_data *drv = bss->drv;
Dmitry Shmidt8da800a2013-04-24 12:57:01 -07003682 struct nl_msg *msg;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003683 struct nl80211_sta_flag_update upd;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003684 int ret = -ENOBUFS;
3685
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003686 if ((params->flags & WPA_STA_TDLS_PEER) &&
3687 !(drv->capa.flags & WPA_DRIVER_FLAGS_TDLS_SUPPORT))
3688 return -EOPNOTSUPP;
3689
Dmitry Shmidtf8623282013-02-20 14:34:59 -08003690 wpa_printf(MSG_DEBUG, "nl80211: %s STA " MACSTR,
3691 params->set ? "Set" : "Add", MAC2STR(params->addr));
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003692 msg = nl80211_bss_msg(bss, 0, params->set ? NL80211_CMD_SET_STATION :
3693 NL80211_CMD_NEW_STATION);
3694 if (!msg || nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, params->addr))
3695 goto fail;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003696
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003697 if (!params->set || (params->flags & WPA_STA_TDLS_PEER)) {
3698 wpa_hexdump(MSG_DEBUG, " * supported rates",
3699 params->supp_rates, params->supp_rates_len);
3700 wpa_printf(MSG_DEBUG, " * capability=0x%x",
3701 params->capability);
3702 if (nla_put(msg, NL80211_ATTR_STA_SUPPORTED_RATES,
3703 params->supp_rates_len, params->supp_rates) ||
3704 nla_put_u16(msg, NL80211_ATTR_STA_CAPABILITY,
3705 params->capability))
3706 goto fail;
3707
3708 if (params->ht_capabilities) {
3709 wpa_hexdump(MSG_DEBUG, " * ht_capabilities",
3710 (u8 *) params->ht_capabilities,
3711 sizeof(*params->ht_capabilities));
3712 if (nla_put(msg, NL80211_ATTR_HT_CAPABILITY,
3713 sizeof(*params->ht_capabilities),
3714 params->ht_capabilities))
3715 goto fail;
3716 }
3717
3718 if (params->vht_capabilities) {
3719 wpa_hexdump(MSG_DEBUG, " * vht_capabilities",
3720 (u8 *) params->vht_capabilities,
3721 sizeof(*params->vht_capabilities));
3722 if (nla_put(msg, NL80211_ATTR_VHT_CAPABILITY,
3723 sizeof(*params->vht_capabilities),
3724 params->vht_capabilities))
3725 goto fail;
3726 }
3727
3728 if (params->ext_capab) {
3729 wpa_hexdump(MSG_DEBUG, " * ext_capab",
3730 params->ext_capab, params->ext_capab_len);
3731 if (nla_put(msg, NL80211_ATTR_STA_EXT_CAPABILITY,
3732 params->ext_capab_len, params->ext_capab))
3733 goto fail;
3734 }
3735 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003736 if (!params->set) {
Dmitry Shmidt51b6ea82013-05-08 10:42:09 -07003737 if (params->aid) {
3738 wpa_printf(MSG_DEBUG, " * aid=%u", params->aid);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003739 if (nla_put_u16(msg, NL80211_ATTR_STA_AID, params->aid))
3740 goto fail;
Dmitry Shmidt51b6ea82013-05-08 10:42:09 -07003741 } else {
3742 /*
3743 * cfg80211 validates that AID is non-zero, so we have
3744 * to make this a non-zero value for the TDLS case where
3745 * a dummy STA entry is used for now.
3746 */
3747 wpa_printf(MSG_DEBUG, " * aid=1 (TDLS workaround)");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003748 if (nla_put_u16(msg, NL80211_ATTR_STA_AID, 1))
3749 goto fail;
Dmitry Shmidt51b6ea82013-05-08 10:42:09 -07003750 }
Dmitry Shmidtf8623282013-02-20 14:34:59 -08003751 wpa_printf(MSG_DEBUG, " * listen_interval=%u",
3752 params->listen_interval);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003753 if (nla_put_u16(msg, NL80211_ATTR_STA_LISTEN_INTERVAL,
3754 params->listen_interval))
3755 goto fail;
Dmitry Shmidt8bae4132013-06-06 11:25:10 -07003756 } else if (params->aid && (params->flags & WPA_STA_TDLS_PEER)) {
3757 wpa_printf(MSG_DEBUG, " * peer_aid=%u", params->aid);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003758 if (nla_put_u16(msg, NL80211_ATTR_PEER_AID, params->aid))
3759 goto fail;
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08003760 }
3761
Dmitry Shmidtbd14a572014-02-18 10:33:49 -08003762 if (params->vht_opmode_enabled) {
3763 wpa_printf(MSG_DEBUG, " * opmode=%u", params->vht_opmode);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003764 if (nla_put_u8(msg, NL80211_ATTR_OPMODE_NOTIF,
3765 params->vht_opmode))
3766 goto fail;
Dmitry Shmidtf8623282013-02-20 14:34:59 -08003767 }
3768
Dmitry Shmidt344abd32014-01-14 13:17:00 -08003769 if (params->supp_channels) {
3770 wpa_hexdump(MSG_DEBUG, " * supported channels",
3771 params->supp_channels, params->supp_channels_len);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003772 if (nla_put(msg, NL80211_ATTR_STA_SUPPORTED_CHANNELS,
3773 params->supp_channels_len, params->supp_channels))
3774 goto fail;
Dmitry Shmidt344abd32014-01-14 13:17:00 -08003775 }
3776
3777 if (params->supp_oper_classes) {
3778 wpa_hexdump(MSG_DEBUG, " * supported operating classes",
3779 params->supp_oper_classes,
3780 params->supp_oper_classes_len);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003781 if (nla_put(msg, NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES,
3782 params->supp_oper_classes_len,
3783 params->supp_oper_classes))
3784 goto fail;
Dmitry Shmidt344abd32014-01-14 13:17:00 -08003785 }
3786
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003787 os_memset(&upd, 0, sizeof(upd));
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003788 upd.set = sta_flags_nl80211(params->flags);
3789 upd.mask = upd.set | sta_flags_nl80211(params->flags_mask);
Dmitry Shmidtf8623282013-02-20 14:34:59 -08003790 wpa_printf(MSG_DEBUG, " * flags set=0x%x mask=0x%x",
3791 upd.set, upd.mask);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003792 if (nla_put(msg, NL80211_ATTR_STA_FLAGS2, sizeof(upd), &upd))
3793 goto fail;
3794
3795#ifdef CONFIG_MESH
3796 if (params->plink_state &&
3797 nla_put_u8(msg, NL80211_ATTR_STA_PLINK_STATE,
3798 sta_plink_state_nl80211(params->plink_state)))
3799 goto fail;
3800#endif /* CONFIG_MESH */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003801
3802 if (params->flags & WPA_STA_WMM) {
Dmitry Shmidt8da800a2013-04-24 12:57:01 -07003803 struct nlattr *wme = nla_nest_start(msg, NL80211_ATTR_STA_WME);
3804
Dmitry Shmidtf8623282013-02-20 14:34:59 -08003805 wpa_printf(MSG_DEBUG, " * qosinfo=0x%x", params->qosinfo);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003806 if (!wme ||
3807 nla_put_u8(msg, NL80211_STA_WME_UAPSD_QUEUES,
3808 params->qosinfo & WMM_QOSINFO_STA_AC_MASK) ||
3809 nla_put_u8(msg, NL80211_STA_WME_MAX_SP,
3810 (params->qosinfo >> WMM_QOSINFO_STA_SP_SHIFT) &
3811 WMM_QOSINFO_STA_SP_MASK))
3812 goto fail;
Dmitry Shmidt8da800a2013-04-24 12:57:01 -07003813 nla_nest_end(msg, wme);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003814 }
3815
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003816 ret = send_and_recv_msgs(drv, msg, NULL, NULL);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003817 msg = NULL;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003818 if (ret)
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003819 wpa_printf(MSG_DEBUG, "nl80211: NL80211_CMD_%s_STATION "
3820 "result: %d (%s)", params->set ? "SET" : "NEW", ret,
3821 strerror(-ret));
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003822 if (ret == -EEXIST)
3823 ret = 0;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003824fail:
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003825 nlmsg_free(msg);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003826 return ret;
3827}
3828
3829
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07003830static void rtnl_neigh_delete_fdb_entry(struct i802_bss *bss, const u8 *addr)
3831{
3832#ifdef CONFIG_LIBNL3_ROUTE
3833 struct wpa_driver_nl80211_data *drv = bss->drv;
3834 struct rtnl_neigh *rn;
3835 struct nl_addr *nl_addr;
3836 int err;
3837
3838 rn = rtnl_neigh_alloc();
3839 if (!rn)
3840 return;
3841
3842 rtnl_neigh_set_family(rn, AF_BRIDGE);
3843 rtnl_neigh_set_ifindex(rn, bss->ifindex);
3844 nl_addr = nl_addr_build(AF_BRIDGE, (void *) addr, ETH_ALEN);
3845 if (!nl_addr) {
3846 rtnl_neigh_put(rn);
3847 return;
3848 }
3849 rtnl_neigh_set_lladdr(rn, nl_addr);
3850
3851 err = rtnl_neigh_delete(drv->rtnl_sk, rn, 0);
3852 if (err < 0) {
3853 wpa_printf(MSG_DEBUG, "nl80211: bridge FDB entry delete for "
3854 MACSTR " ifindex=%d failed: %s", MAC2STR(addr),
3855 bss->ifindex, nl_geterror(err));
3856 } else {
3857 wpa_printf(MSG_DEBUG, "nl80211: deleted bridge FDB entry for "
3858 MACSTR, MAC2STR(addr));
3859 }
3860
3861 nl_addr_put(nl_addr);
3862 rtnl_neigh_put(rn);
3863#endif /* CONFIG_LIBNL3_ROUTE */
3864}
3865
3866
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003867static int wpa_driver_nl80211_sta_remove(struct i802_bss *bss, const u8 *addr,
3868 int deauth, u16 reason_code)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003869{
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003870 struct wpa_driver_nl80211_data *drv = bss->drv;
3871 struct nl_msg *msg;
3872 int ret;
3873
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003874 if (!(msg = nl80211_bss_msg(bss, 0, NL80211_CMD_DEL_STATION)) ||
3875 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) ||
3876 (deauth == 0 &&
3877 nla_put_u8(msg, NL80211_ATTR_MGMT_SUBTYPE,
3878 WLAN_FC_STYPE_DISASSOC)) ||
3879 (deauth == 1 &&
3880 nla_put_u8(msg, NL80211_ATTR_MGMT_SUBTYPE,
3881 WLAN_FC_STYPE_DEAUTH)) ||
3882 (reason_code &&
3883 nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason_code))) {
3884 nlmsg_free(msg);
3885 return -ENOBUFS;
3886 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003887
3888 ret = send_and_recv_msgs(drv, msg, NULL, NULL);
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -07003889 wpa_printf(MSG_DEBUG, "nl80211: sta_remove -> DEL_STATION %s " MACSTR
3890 " --> %d (%s)",
3891 bss->ifname, MAC2STR(addr), ret, strerror(-ret));
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07003892
3893 if (drv->rtnl_sk)
3894 rtnl_neigh_delete_fdb_entry(bss, addr);
3895
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003896 if (ret == -ENOENT)
3897 return 0;
3898 return ret;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003899}
3900
3901
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003902void nl80211_remove_iface(struct wpa_driver_nl80211_data *drv, int ifidx)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003903{
3904 struct nl_msg *msg;
Dmitry Shmidt76cd2cc2014-05-27 12:56:04 -07003905 struct wpa_driver_nl80211_data *drv2;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003906
3907 wpa_printf(MSG_DEBUG, "nl80211: Remove interface ifindex=%d", ifidx);
3908
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003909 /* stop listening for EAPOL on this interface */
Dmitry Shmidt76cd2cc2014-05-27 12:56:04 -07003910 dl_list_for_each(drv2, &drv->global->interfaces,
3911 struct wpa_driver_nl80211_data, list)
3912 del_ifidx(drv2, ifidx);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003913
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003914 msg = nl80211_ifindex_msg(drv, ifidx, 0, NL80211_CMD_DEL_INTERFACE);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003915 if (send_and_recv_msgs(drv, msg, NULL, NULL) == 0)
3916 return;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003917 wpa_printf(MSG_ERROR, "Failed to remove interface (ifidx=%d)", ifidx);
3918}
3919
3920
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003921static const char * nl80211_iftype_str(enum nl80211_iftype mode)
3922{
3923 switch (mode) {
3924 case NL80211_IFTYPE_ADHOC:
3925 return "ADHOC";
3926 case NL80211_IFTYPE_STATION:
3927 return "STATION";
3928 case NL80211_IFTYPE_AP:
3929 return "AP";
Dmitry Shmidtf7e0a992013-05-23 11:03:10 -07003930 case NL80211_IFTYPE_AP_VLAN:
3931 return "AP_VLAN";
3932 case NL80211_IFTYPE_WDS:
3933 return "WDS";
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003934 case NL80211_IFTYPE_MONITOR:
3935 return "MONITOR";
Dmitry Shmidtf7e0a992013-05-23 11:03:10 -07003936 case NL80211_IFTYPE_MESH_POINT:
3937 return "MESH_POINT";
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003938 case NL80211_IFTYPE_P2P_CLIENT:
3939 return "P2P_CLIENT";
3940 case NL80211_IFTYPE_P2P_GO:
3941 return "P2P_GO";
Dmitry Shmidt34af3062013-07-11 10:46:32 -07003942 case NL80211_IFTYPE_P2P_DEVICE:
3943 return "P2P_DEVICE";
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003944 default:
3945 return "unknown";
3946 }
3947}
3948
3949
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003950static int nl80211_create_iface_once(struct wpa_driver_nl80211_data *drv,
3951 const char *ifname,
3952 enum nl80211_iftype iftype,
Dmitry Shmidt34af3062013-07-11 10:46:32 -07003953 const u8 *addr, int wds,
3954 int (*handler)(struct nl_msg *, void *),
3955 void *arg)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003956{
Dmitry Shmidt8da800a2013-04-24 12:57:01 -07003957 struct nl_msg *msg;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003958 int ifidx;
3959 int ret = -ENOBUFS;
3960
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003961 wpa_printf(MSG_DEBUG, "nl80211: Create interface iftype %d (%s)",
3962 iftype, nl80211_iftype_str(iftype));
3963
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003964 msg = nl80211_cmd_msg(drv->first_bss, 0, NL80211_CMD_NEW_INTERFACE);
3965 if (!msg ||
3966 nla_put_string(msg, NL80211_ATTR_IFNAME, ifname) ||
3967 nla_put_u32(msg, NL80211_ATTR_IFTYPE, iftype))
3968 goto fail;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003969
3970 if (iftype == NL80211_IFTYPE_MONITOR) {
Dmitry Shmidt8da800a2013-04-24 12:57:01 -07003971 struct nlattr *flags;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003972
Dmitry Shmidt8da800a2013-04-24 12:57:01 -07003973 flags = nla_nest_start(msg, NL80211_ATTR_MNTR_FLAGS);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003974 if (!flags ||
3975 nla_put_flag(msg, NL80211_MNTR_FLAG_COOK_FRAMES))
3976 goto fail;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003977
Dmitry Shmidt8da800a2013-04-24 12:57:01 -07003978 nla_nest_end(msg, flags);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003979 } else if (wds) {
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003980 if (nla_put_u8(msg, NL80211_ATTR_4ADDR, wds))
3981 goto fail;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003982 }
3983
Dmitry Shmidtb58836e2014-04-29 14:35:56 -07003984 /*
3985 * Tell cfg80211 that the interface belongs to the socket that created
3986 * it, and the interface should be deleted when the socket is closed.
3987 */
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003988 if (nla_put_flag(msg, NL80211_ATTR_IFACE_SOCKET_OWNER))
3989 goto fail;
Dmitry Shmidtb58836e2014-04-29 14:35:56 -07003990
Dmitry Shmidt34af3062013-07-11 10:46:32 -07003991 ret = send_and_recv_msgs(drv, msg, handler, arg);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003992 msg = NULL;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003993 if (ret) {
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003994 fail:
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003995 nlmsg_free(msg);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003996 wpa_printf(MSG_ERROR, "Failed to create interface %s: %d (%s)",
3997 ifname, ret, strerror(-ret));
3998 return ret;
3999 }
4000
Dmitry Shmidt34af3062013-07-11 10:46:32 -07004001 if (iftype == NL80211_IFTYPE_P2P_DEVICE)
4002 return 0;
4003
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004004 ifidx = if_nametoindex(ifname);
4005 wpa_printf(MSG_DEBUG, "nl80211: New interface %s created: ifindex=%d",
4006 ifname, ifidx);
4007
4008 if (ifidx <= 0)
4009 return -1;
4010
Dmitry Shmidt76cd2cc2014-05-27 12:56:04 -07004011 /*
4012 * Some virtual interfaces need to process EAPOL packets and events on
4013 * the parent interface. This is used mainly with hostapd.
4014 */
4015 if (drv->hostapd ||
4016 iftype == NL80211_IFTYPE_AP_VLAN ||
4017 iftype == NL80211_IFTYPE_WDS ||
4018 iftype == NL80211_IFTYPE_MONITOR) {
4019 /* start listening for EAPOL on this interface */
4020 add_ifidx(drv, ifidx);
4021 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004022
4023 if (addr && iftype != NL80211_IFTYPE_MONITOR &&
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004024 linux_set_ifhwaddr(drv->global->ioctl_sock, ifname, addr)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004025 nl80211_remove_iface(drv, ifidx);
4026 return -1;
4027 }
4028
4029 return ifidx;
4030}
4031
4032
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004033int nl80211_create_iface(struct wpa_driver_nl80211_data *drv,
4034 const char *ifname, enum nl80211_iftype iftype,
4035 const u8 *addr, int wds,
4036 int (*handler)(struct nl_msg *, void *),
4037 void *arg, int use_existing)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004038{
4039 int ret;
4040
Dmitry Shmidt34af3062013-07-11 10:46:32 -07004041 ret = nl80211_create_iface_once(drv, ifname, iftype, addr, wds, handler,
4042 arg);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004043
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004044 /* if error occurred and interface exists already */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004045 if (ret == -ENFILE && if_nametoindex(ifname)) {
Dmitry Shmidtcce06662013-11-04 18:44:24 -08004046 if (use_existing) {
4047 wpa_printf(MSG_DEBUG, "nl80211: Continue using existing interface %s",
4048 ifname);
Dmitry Shmidtdf5a7e42014-04-02 12:59:59 -07004049 if (addr && iftype != NL80211_IFTYPE_MONITOR &&
4050 linux_set_ifhwaddr(drv->global->ioctl_sock, ifname,
4051 addr) < 0 &&
4052 (linux_set_iface_flags(drv->global->ioctl_sock,
4053 ifname, 0) < 0 ||
4054 linux_set_ifhwaddr(drv->global->ioctl_sock, ifname,
4055 addr) < 0 ||
4056 linux_set_iface_flags(drv->global->ioctl_sock,
4057 ifname, 1) < 0))
4058 return -1;
Dmitry Shmidtcce06662013-11-04 18:44:24 -08004059 return -ENFILE;
4060 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004061 wpa_printf(MSG_INFO, "Try to remove and re-create %s", ifname);
4062
4063 /* Try to remove the interface that was already there. */
4064 nl80211_remove_iface(drv, if_nametoindex(ifname));
4065
4066 /* Try to create the interface again */
4067 ret = nl80211_create_iface_once(drv, ifname, iftype, addr,
Dmitry Shmidt34af3062013-07-11 10:46:32 -07004068 wds, handler, arg);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004069 }
4070
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004071 if (ret >= 0 && is_p2p_net_interface(iftype)) {
4072 wpa_printf(MSG_DEBUG,
4073 "nl80211: Interface %s created for P2P - disable 11b rates",
4074 ifname);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004075 nl80211_disable_11b_rates(drv, ret, 1);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004076 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004077
4078 return ret;
4079}
4080
4081
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004082static int nl80211_setup_ap(struct i802_bss *bss)
4083{
4084 struct wpa_driver_nl80211_data *drv = bss->drv;
4085
Dmitry Shmidtcce06662013-11-04 18:44:24 -08004086 wpa_printf(MSG_DEBUG, "nl80211: Setup AP(%s) - device_ap_sme=%d use_monitor=%d",
4087 bss->ifname, drv->device_ap_sme, drv->use_monitor);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004088
4089 /*
4090 * Disable Probe Request reporting unless we need it in this way for
4091 * devices that include the AP SME, in the other case (unless using
4092 * monitor iface) we'll get it through the nl_mgmt socket instead.
4093 */
4094 if (!drv->device_ap_sme)
4095 wpa_driver_nl80211_probe_req_report(bss, 0);
4096
4097 if (!drv->device_ap_sme && !drv->use_monitor)
4098 if (nl80211_mgmt_subscribe_ap(bss))
4099 return -1;
4100
4101 if (drv->device_ap_sme && !drv->use_monitor)
4102 if (nl80211_mgmt_subscribe_ap_dev_sme(bss))
4103 return -1;
4104
4105 if (!drv->device_ap_sme && drv->use_monitor &&
4106 nl80211_create_monitor_interface(drv) &&
4107 !drv->device_ap_sme)
Dmitry Shmidt04949592012-07-19 12:16:46 -07004108 return -1;
4109
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004110 if (drv->device_ap_sme &&
4111 wpa_driver_nl80211_probe_req_report(bss, 1) < 0) {
4112 wpa_printf(MSG_DEBUG, "nl80211: Failed to enable "
4113 "Probe Request frame reporting in AP mode");
4114 /* Try to survive without this */
4115 }
4116
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004117 return 0;
4118}
4119
4120
4121static void nl80211_teardown_ap(struct i802_bss *bss)
4122{
4123 struct wpa_driver_nl80211_data *drv = bss->drv;
4124
Dmitry Shmidtcce06662013-11-04 18:44:24 -08004125 wpa_printf(MSG_DEBUG, "nl80211: Teardown AP(%s) - device_ap_sme=%d use_monitor=%d",
4126 bss->ifname, drv->device_ap_sme, drv->use_monitor);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004127 if (drv->device_ap_sme) {
4128 wpa_driver_nl80211_probe_req_report(bss, 0);
4129 if (!drv->use_monitor)
4130 nl80211_mgmt_unsubscribe(bss, "AP teardown (dev SME)");
4131 } else if (drv->use_monitor)
4132 nl80211_remove_monitor_interface(drv);
4133 else
4134 nl80211_mgmt_unsubscribe(bss, "AP teardown");
4135
4136 bss->beacon_set = 0;
4137}
4138
4139
4140static int nl80211_send_eapol_data(struct i802_bss *bss,
4141 const u8 *addr, const u8 *data,
4142 size_t data_len)
4143{
4144 struct sockaddr_ll ll;
4145 int ret;
4146
4147 if (bss->drv->eapol_tx_sock < 0) {
4148 wpa_printf(MSG_DEBUG, "nl80211: No socket to send EAPOL");
4149 return -1;
4150 }
4151
4152 os_memset(&ll, 0, sizeof(ll));
4153 ll.sll_family = AF_PACKET;
4154 ll.sll_ifindex = bss->ifindex;
4155 ll.sll_protocol = htons(ETH_P_PAE);
4156 ll.sll_halen = ETH_ALEN;
4157 os_memcpy(ll.sll_addr, addr, ETH_ALEN);
4158 ret = sendto(bss->drv->eapol_tx_sock, data, data_len, 0,
4159 (struct sockaddr *) &ll, sizeof(ll));
4160 if (ret < 0)
4161 wpa_printf(MSG_ERROR, "nl80211: EAPOL TX: %s",
4162 strerror(errno));
4163
4164 return ret;
4165}
4166
4167
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004168static const u8 rfc1042_header[6] = { 0xaa, 0xaa, 0x03, 0x00, 0x00, 0x00 };
4169
4170static int wpa_driver_nl80211_hapd_send_eapol(
4171 void *priv, const u8 *addr, const u8 *data,
4172 size_t data_len, int encrypt, const u8 *own_addr, u32 flags)
4173{
4174 struct i802_bss *bss = priv;
4175 struct wpa_driver_nl80211_data *drv = bss->drv;
4176 struct ieee80211_hdr *hdr;
4177 size_t len;
4178 u8 *pos;
4179 int res;
4180 int qos = flags & WPA_STA_WMM;
Dmitry Shmidt641185e2013-11-06 15:17:13 -08004181
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004182 if (drv->device_ap_sme || !drv->use_monitor)
4183 return nl80211_send_eapol_data(bss, addr, data, data_len);
4184
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004185 len = sizeof(*hdr) + (qos ? 2 : 0) + sizeof(rfc1042_header) + 2 +
4186 data_len;
4187 hdr = os_zalloc(len);
4188 if (hdr == NULL) {
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -07004189 wpa_printf(MSG_INFO, "nl80211: Failed to allocate EAPOL buffer(len=%lu)",
4190 (unsigned long) len);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004191 return -1;
4192 }
4193
4194 hdr->frame_control =
4195 IEEE80211_FC(WLAN_FC_TYPE_DATA, WLAN_FC_STYPE_DATA);
4196 hdr->frame_control |= host_to_le16(WLAN_FC_FROMDS);
4197 if (encrypt)
4198 hdr->frame_control |= host_to_le16(WLAN_FC_ISWEP);
4199 if (qos) {
4200 hdr->frame_control |=
4201 host_to_le16(WLAN_FC_STYPE_QOS_DATA << 4);
4202 }
4203
4204 memcpy(hdr->IEEE80211_DA_FROMDS, addr, ETH_ALEN);
4205 memcpy(hdr->IEEE80211_BSSID_FROMDS, own_addr, ETH_ALEN);
4206 memcpy(hdr->IEEE80211_SA_FROMDS, own_addr, ETH_ALEN);
4207 pos = (u8 *) (hdr + 1);
4208
4209 if (qos) {
Dmitry Shmidtaa532512012-09-24 10:35:31 -07004210 /* Set highest priority in QoS header */
4211 pos[0] = 7;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004212 pos[1] = 0;
4213 pos += 2;
4214 }
4215
4216 memcpy(pos, rfc1042_header, sizeof(rfc1042_header));
4217 pos += sizeof(rfc1042_header);
4218 WPA_PUT_BE16(pos, ETH_P_PAE);
4219 pos += 2;
4220 memcpy(pos, data, data_len);
4221
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08004222 res = wpa_driver_nl80211_send_frame(bss, (u8 *) hdr, len, encrypt, 0,
4223 0, 0, 0, 0);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004224 if (res < 0) {
4225 wpa_printf(MSG_ERROR, "i802_send_eapol - packet len: %lu - "
4226 "failed: %d (%s)",
4227 (unsigned long) len, errno, strerror(errno));
4228 }
4229 os_free(hdr);
4230
4231 return res;
4232}
4233
4234
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004235static int wpa_driver_nl80211_sta_set_flags(void *priv, const u8 *addr,
4236 int total_flags,
4237 int flags_or, int flags_and)
4238{
4239 struct i802_bss *bss = priv;
Dmitry Shmidt8da800a2013-04-24 12:57:01 -07004240 struct nl_msg *msg;
4241 struct nlattr *flags;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004242 struct nl80211_sta_flag_update upd;
4243
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07004244 wpa_printf(MSG_DEBUG, "nl80211: Set STA flags - ifname=%s addr=" MACSTR
4245 " total_flags=0x%x flags_or=0x%x flags_and=0x%x authorized=%d",
4246 bss->ifname, MAC2STR(addr), total_flags, flags_or, flags_and,
4247 !!(total_flags & WPA_STA_AUTHORIZED));
4248
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004249 if (!(msg = nl80211_bss_msg(bss, 0, NL80211_CMD_SET_STATION)) ||
4250 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr))
4251 goto fail;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004252
4253 /*
4254 * Backwards compatibility version using NL80211_ATTR_STA_FLAGS. This
4255 * can be removed eventually.
4256 */
Dmitry Shmidt8da800a2013-04-24 12:57:01 -07004257 flags = nla_nest_start(msg, NL80211_ATTR_STA_FLAGS);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004258 if (!flags ||
4259 ((total_flags & WPA_STA_AUTHORIZED) &&
4260 nla_put_flag(msg, NL80211_STA_FLAG_AUTHORIZED)) ||
4261 ((total_flags & WPA_STA_WMM) &&
4262 nla_put_flag(msg, NL80211_STA_FLAG_WME)) ||
4263 ((total_flags & WPA_STA_SHORT_PREAMBLE) &&
4264 nla_put_flag(msg, NL80211_STA_FLAG_SHORT_PREAMBLE)) ||
4265 ((total_flags & WPA_STA_MFP) &&
4266 nla_put_flag(msg, NL80211_STA_FLAG_MFP)) ||
4267 ((total_flags & WPA_STA_TDLS_PEER) &&
4268 nla_put_flag(msg, NL80211_STA_FLAG_TDLS_PEER)))
4269 goto fail;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004270
Dmitry Shmidt8da800a2013-04-24 12:57:01 -07004271 nla_nest_end(msg, flags);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004272
4273 os_memset(&upd, 0, sizeof(upd));
4274 upd.mask = sta_flags_nl80211(flags_or | ~flags_and);
4275 upd.set = sta_flags_nl80211(flags_or);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004276 if (nla_put(msg, NL80211_ATTR_STA_FLAGS2, sizeof(upd), &upd))
4277 goto fail;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004278
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004279 return send_and_recv_msgs(bss->drv, msg, NULL, NULL);
4280fail:
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004281 nlmsg_free(msg);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004282 return -ENOBUFS;
4283}
4284
4285
4286static int wpa_driver_nl80211_ap(struct wpa_driver_nl80211_data *drv,
4287 struct wpa_driver_associate_params *params)
4288{
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08004289 enum nl80211_iftype nlmode, old_mode;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004290
4291 if (params->p2p) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004292 wpa_printf(MSG_DEBUG, "nl80211: Setup AP operations for P2P "
4293 "group (GO)");
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004294 nlmode = NL80211_IFTYPE_P2P_GO;
4295 } else
4296 nlmode = NL80211_IFTYPE_AP;
4297
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08004298 old_mode = drv->nlmode;
Dmitry Shmidtcce06662013-11-04 18:44:24 -08004299 if (wpa_driver_nl80211_set_mode(drv->first_bss, nlmode)) {
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08004300 nl80211_remove_monitor_interface(drv);
4301 return -1;
4302 }
4303
Dmitry Shmidt9ead16e2014-10-07 13:15:23 -07004304 if (nl80211_set_channel(drv->first_bss, &params->freq, 0)) {
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08004305 if (old_mode != nlmode)
Dmitry Shmidtcce06662013-11-04 18:44:24 -08004306 wpa_driver_nl80211_set_mode(drv->first_bss, old_mode);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004307 nl80211_remove_monitor_interface(drv);
4308 return -1;
4309 }
4310
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004311 return 0;
4312}
4313
4314
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004315static int nl80211_leave_ibss(struct wpa_driver_nl80211_data *drv,
4316 int reset_mode)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004317{
4318 struct nl_msg *msg;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004319 int ret;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004320
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004321 msg = nl80211_drv_msg(drv, 0, NL80211_CMD_LEAVE_IBSS);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004322 ret = send_and_recv_msgs(drv, msg, NULL, NULL);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004323 if (ret) {
4324 wpa_printf(MSG_DEBUG, "nl80211: Leave IBSS failed: ret=%d "
4325 "(%s)", ret, strerror(-ret));
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004326 } else {
4327 wpa_printf(MSG_DEBUG,
4328 "nl80211: Leave IBSS request sent successfully");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004329 }
4330
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004331 if (reset_mode &&
4332 wpa_driver_nl80211_set_mode(drv->first_bss,
Dmitry Shmidt56052862013-10-04 10:23:25 -07004333 NL80211_IFTYPE_STATION)) {
4334 wpa_printf(MSG_INFO, "nl80211: Failed to set interface into "
4335 "station mode");
4336 }
4337
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004338 return ret;
4339}
4340
4341
Dmitry Shmidt2f74e362015-01-21 13:19:05 -08004342static int nl80211_ht_vht_overrides(struct nl_msg *msg,
4343 struct wpa_driver_associate_params *params)
4344{
4345 if (params->disable_ht && nla_put_flag(msg, NL80211_ATTR_DISABLE_HT))
4346 return -1;
4347
4348 if (params->htcaps && params->htcaps_mask) {
4349 int sz = sizeof(struct ieee80211_ht_capabilities);
4350 wpa_hexdump(MSG_DEBUG, " * htcaps", params->htcaps, sz);
4351 wpa_hexdump(MSG_DEBUG, " * htcaps_mask",
4352 params->htcaps_mask, sz);
4353 if (nla_put(msg, NL80211_ATTR_HT_CAPABILITY, sz,
4354 params->htcaps) ||
4355 nla_put(msg, NL80211_ATTR_HT_CAPABILITY_MASK, sz,
4356 params->htcaps_mask))
4357 return -1;
4358 }
4359
4360#ifdef CONFIG_VHT_OVERRIDES
4361 if (params->disable_vht) {
4362 wpa_printf(MSG_DEBUG, " * VHT disabled");
4363 if (nla_put_flag(msg, NL80211_ATTR_DISABLE_VHT))
4364 return -1;
4365 }
4366
4367 if (params->vhtcaps && params->vhtcaps_mask) {
4368 int sz = sizeof(struct ieee80211_vht_capabilities);
4369 wpa_hexdump(MSG_DEBUG, " * vhtcaps", params->vhtcaps, sz);
4370 wpa_hexdump(MSG_DEBUG, " * vhtcaps_mask",
4371 params->vhtcaps_mask, sz);
4372 if (nla_put(msg, NL80211_ATTR_VHT_CAPABILITY, sz,
4373 params->vhtcaps) ||
4374 nla_put(msg, NL80211_ATTR_VHT_CAPABILITY_MASK, sz,
4375 params->vhtcaps_mask))
4376 return -1;
4377 }
4378#endif /* CONFIG_VHT_OVERRIDES */
4379
4380 return 0;
4381}
4382
4383
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004384static int wpa_driver_nl80211_ibss(struct wpa_driver_nl80211_data *drv,
4385 struct wpa_driver_associate_params *params)
4386{
4387 struct nl_msg *msg;
4388 int ret = -1;
4389 int count = 0;
4390
4391 wpa_printf(MSG_DEBUG, "nl80211: Join IBSS (ifindex=%d)", drv->ifindex);
4392
Dmitry Shmidt9ead16e2014-10-07 13:15:23 -07004393 if (wpa_driver_nl80211_set_mode_ibss(drv->first_bss, &params->freq)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004394 wpa_printf(MSG_INFO, "nl80211: Failed to set interface into "
4395 "IBSS mode");
4396 return -1;
4397 }
4398
4399retry:
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004400 if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_JOIN_IBSS)) ||
4401 params->ssid == NULL || params->ssid_len > sizeof(drv->ssid))
4402 goto fail;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004403
4404 wpa_hexdump_ascii(MSG_DEBUG, " * SSID",
4405 params->ssid, params->ssid_len);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004406 if (nla_put(msg, NL80211_ATTR_SSID, params->ssid_len, params->ssid))
4407 goto fail;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004408 os_memcpy(drv->ssid, params->ssid, params->ssid_len);
4409 drv->ssid_len = params->ssid_len;
4410
Dmitry Shmidtff787d52015-01-12 13:01:47 -08004411 if (nl80211_put_freq_params(msg, &params->freq) < 0 ||
4412 nl80211_put_beacon_int(msg, params->beacon_int))
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004413 goto fail;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004414
4415 ret = nl80211_set_conn_keys(params, msg);
4416 if (ret)
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004417 goto fail;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004418
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08004419 if (params->bssid && params->fixed_bssid) {
4420 wpa_printf(MSG_DEBUG, " * BSSID=" MACSTR,
4421 MAC2STR(params->bssid));
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004422 if (nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, params->bssid))
4423 goto fail;
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08004424 }
4425
Dmitry Shmidt7f656022015-02-25 14:36:37 -08004426 if (params->fixed_freq) {
4427 wpa_printf(MSG_DEBUG, " * fixed_freq");
4428 if (nla_put_flag(msg, NL80211_ATTR_FREQ_FIXED))
4429 goto fail;
4430 }
4431
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004432 if (params->key_mgmt_suite == WPA_KEY_MGMT_IEEE8021X ||
4433 params->key_mgmt_suite == WPA_KEY_MGMT_PSK ||
4434 params->key_mgmt_suite == WPA_KEY_MGMT_IEEE8021X_SHA256 ||
4435 params->key_mgmt_suite == WPA_KEY_MGMT_PSK_SHA256) {
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08004436 wpa_printf(MSG_DEBUG, " * control port");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004437 if (nla_put_flag(msg, NL80211_ATTR_CONTROL_PORT))
4438 goto fail;
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08004439 }
4440
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004441 if (params->wpa_ie) {
4442 wpa_hexdump(MSG_DEBUG,
4443 " * Extra IEs for Beacon/Probe Response frames",
4444 params->wpa_ie, params->wpa_ie_len);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004445 if (nla_put(msg, NL80211_ATTR_IE, params->wpa_ie_len,
4446 params->wpa_ie))
4447 goto fail;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004448 }
4449
Dmitry Shmidt2f74e362015-01-21 13:19:05 -08004450 if (nl80211_ht_vht_overrides(msg, params) < 0)
4451 return -1;
4452
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004453 ret = send_and_recv_msgs(drv, msg, NULL, NULL);
4454 msg = NULL;
4455 if (ret) {
4456 wpa_printf(MSG_DEBUG, "nl80211: Join IBSS failed: ret=%d (%s)",
4457 ret, strerror(-ret));
4458 count++;
4459 if (ret == -EALREADY && count == 1) {
4460 wpa_printf(MSG_DEBUG, "nl80211: Retry IBSS join after "
4461 "forced leave");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004462 nl80211_leave_ibss(drv, 0);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004463 nlmsg_free(msg);
4464 goto retry;
4465 }
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004466 } else {
4467 wpa_printf(MSG_DEBUG,
4468 "nl80211: Join IBSS request sent successfully");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004469 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004470
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004471fail:
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004472 nlmsg_free(msg);
4473 return ret;
4474}
4475
4476
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004477static int nl80211_connect_common(struct wpa_driver_nl80211_data *drv,
4478 struct wpa_driver_associate_params *params,
4479 struct nl_msg *msg)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004480{
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004481 if (params->bssid) {
4482 wpa_printf(MSG_DEBUG, " * bssid=" MACSTR,
4483 MAC2STR(params->bssid));
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004484 if (nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, params->bssid))
4485 return -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004486 }
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004487
Dmitry Shmidt96be6222014-02-13 10:16:51 -08004488 if (params->bssid_hint) {
4489 wpa_printf(MSG_DEBUG, " * bssid_hint=" MACSTR,
4490 MAC2STR(params->bssid_hint));
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004491 if (nla_put(msg, NL80211_ATTR_MAC_HINT, ETH_ALEN,
4492 params->bssid_hint))
4493 return -1;
Dmitry Shmidt96be6222014-02-13 10:16:51 -08004494 }
4495
Dmitry Shmidt9ead16e2014-10-07 13:15:23 -07004496 if (params->freq.freq) {
4497 wpa_printf(MSG_DEBUG, " * freq=%d", params->freq.freq);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004498 if (nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ,
4499 params->freq.freq))
4500 return -1;
Dmitry Shmidt9ead16e2014-10-07 13:15:23 -07004501 drv->assoc_freq = params->freq.freq;
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -07004502 } else
4503 drv->assoc_freq = 0;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004504
Dmitry Shmidt96be6222014-02-13 10:16:51 -08004505 if (params->freq_hint) {
4506 wpa_printf(MSG_DEBUG, " * freq_hint=%d", params->freq_hint);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004507 if (nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ_HINT,
4508 params->freq_hint))
4509 return -1;
Dmitry Shmidt96be6222014-02-13 10:16:51 -08004510 }
4511
Dmitry Shmidt04949592012-07-19 12:16:46 -07004512 if (params->bg_scan_period >= 0) {
4513 wpa_printf(MSG_DEBUG, " * bg scan period=%d",
4514 params->bg_scan_period);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004515 if (nla_put_u16(msg, NL80211_ATTR_BG_SCAN_PERIOD,
4516 params->bg_scan_period))
4517 return -1;
Dmitry Shmidt04949592012-07-19 12:16:46 -07004518 }
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004519
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004520 if (params->ssid) {
4521 wpa_hexdump_ascii(MSG_DEBUG, " * SSID",
4522 params->ssid, params->ssid_len);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004523 if (nla_put(msg, NL80211_ATTR_SSID, params->ssid_len,
4524 params->ssid))
4525 return -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004526 if (params->ssid_len > sizeof(drv->ssid))
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004527 return -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004528 os_memcpy(drv->ssid, params->ssid, params->ssid_len);
4529 drv->ssid_len = params->ssid_len;
4530 }
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004531
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004532 wpa_hexdump(MSG_DEBUG, " * IEs", params->wpa_ie, params->wpa_ie_len);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004533 if (params->wpa_ie &&
4534 nla_put(msg, NL80211_ATTR_IE, params->wpa_ie_len, params->wpa_ie))
4535 return -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004536
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004537 if (params->wpa_proto) {
4538 enum nl80211_wpa_versions ver = 0;
4539
4540 if (params->wpa_proto & WPA_PROTO_WPA)
4541 ver |= NL80211_WPA_VERSION_1;
4542 if (params->wpa_proto & WPA_PROTO_RSN)
4543 ver |= NL80211_WPA_VERSION_2;
4544
4545 wpa_printf(MSG_DEBUG, " * WPA Versions 0x%x", ver);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004546 if (nla_put_u32(msg, NL80211_ATTR_WPA_VERSIONS, ver))
4547 return -1;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004548 }
4549
4550 if (params->pairwise_suite != WPA_CIPHER_NONE) {
4551 u32 cipher = wpa_cipher_to_cipher_suite(params->pairwise_suite);
4552 wpa_printf(MSG_DEBUG, " * pairwise=0x%x", cipher);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004553 if (nla_put_u32(msg, NL80211_ATTR_CIPHER_SUITES_PAIRWISE,
4554 cipher))
4555 return -1;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004556 }
4557
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08004558 if (params->group_suite == WPA_CIPHER_GTK_NOT_USED &&
4559 !(drv->capa.enc & WPA_DRIVER_CAPA_ENC_GTK_NOT_USED)) {
4560 /*
4561 * This is likely to work even though many drivers do not
4562 * advertise support for operations without GTK.
4563 */
4564 wpa_printf(MSG_DEBUG, " * skip group cipher configuration for GTK_NOT_USED due to missing driver support advertisement");
4565 } else if (params->group_suite != WPA_CIPHER_NONE) {
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004566 u32 cipher = wpa_cipher_to_cipher_suite(params->group_suite);
4567 wpa_printf(MSG_DEBUG, " * group=0x%x", cipher);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004568 if (nla_put_u32(msg, NL80211_ATTR_CIPHER_SUITE_GROUP, cipher))
4569 return -1;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004570 }
4571
4572 if (params->key_mgmt_suite == WPA_KEY_MGMT_IEEE8021X ||
4573 params->key_mgmt_suite == WPA_KEY_MGMT_PSK ||
4574 params->key_mgmt_suite == WPA_KEY_MGMT_FT_IEEE8021X ||
4575 params->key_mgmt_suite == WPA_KEY_MGMT_FT_PSK ||
Dmitry Shmidt15907092014-03-25 10:42:57 -07004576 params->key_mgmt_suite == WPA_KEY_MGMT_CCKM ||
Dmitry Shmidt3c57b3f2014-05-22 15:13:07 -07004577 params->key_mgmt_suite == WPA_KEY_MGMT_OSEN ||
4578 params->key_mgmt_suite == WPA_KEY_MGMT_IEEE8021X_SHA256 ||
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004579 params->key_mgmt_suite == WPA_KEY_MGMT_PSK_SHA256 ||
Dmitry Shmidt807291d2015-01-27 13:40:23 -08004580 params->key_mgmt_suite == WPA_KEY_MGMT_IEEE8021X_SUITE_B ||
4581 params->key_mgmt_suite == WPA_KEY_MGMT_IEEE8021X_SUITE_B_192) {
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004582 int mgmt = WLAN_AKM_SUITE_PSK;
4583
4584 switch (params->key_mgmt_suite) {
4585 case WPA_KEY_MGMT_CCKM:
4586 mgmt = WLAN_AKM_SUITE_CCKM;
4587 break;
4588 case WPA_KEY_MGMT_IEEE8021X:
4589 mgmt = WLAN_AKM_SUITE_8021X;
4590 break;
4591 case WPA_KEY_MGMT_FT_IEEE8021X:
4592 mgmt = WLAN_AKM_SUITE_FT_8021X;
4593 break;
4594 case WPA_KEY_MGMT_FT_PSK:
4595 mgmt = WLAN_AKM_SUITE_FT_PSK;
4596 break;
Dmitry Shmidt3c57b3f2014-05-22 15:13:07 -07004597 case WPA_KEY_MGMT_IEEE8021X_SHA256:
4598 mgmt = WLAN_AKM_SUITE_8021X_SHA256;
4599 break;
4600 case WPA_KEY_MGMT_PSK_SHA256:
4601 mgmt = WLAN_AKM_SUITE_PSK_SHA256;
4602 break;
Dmitry Shmidt15907092014-03-25 10:42:57 -07004603 case WPA_KEY_MGMT_OSEN:
4604 mgmt = WLAN_AKM_SUITE_OSEN;
4605 break;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004606 case WPA_KEY_MGMT_IEEE8021X_SUITE_B:
4607 mgmt = WLAN_AKM_SUITE_8021X_SUITE_B;
4608 break;
Dmitry Shmidt807291d2015-01-27 13:40:23 -08004609 case WPA_KEY_MGMT_IEEE8021X_SUITE_B_192:
4610 mgmt = WLAN_AKM_SUITE_8021X_SUITE_B_192;
4611 break;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004612 case WPA_KEY_MGMT_PSK:
4613 default:
4614 mgmt = WLAN_AKM_SUITE_PSK;
4615 break;
4616 }
Dmitry Shmidt15907092014-03-25 10:42:57 -07004617 wpa_printf(MSG_DEBUG, " * akm=0x%x", mgmt);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004618 if (nla_put_u32(msg, NL80211_ATTR_AKM_SUITES, mgmt))
4619 return -1;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004620 }
4621
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004622 if (nla_put_flag(msg, NL80211_ATTR_CONTROL_PORT))
4623 return -1;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004624
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004625 if (params->mgmt_frame_protection == MGMT_FRAME_PROTECTION_REQUIRED &&
4626 nla_put_u32(msg, NL80211_ATTR_USE_MFP, NL80211_MFP_REQUIRED))
4627 return -1;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004628
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004629 if (params->rrm_used) {
4630 u32 drv_rrm_flags = drv->capa.rrm_flags;
4631 if (!(drv_rrm_flags &
4632 WPA_DRIVER_FLAGS_DS_PARAM_SET_IE_IN_PROBES) ||
4633 !(drv_rrm_flags & WPA_DRIVER_FLAGS_QUIET) ||
4634 nla_put_flag(msg, NL80211_ATTR_USE_RRM))
4635 return -1;
4636 }
4637
Dmitry Shmidt2f74e362015-01-21 13:19:05 -08004638 if (nl80211_ht_vht_overrides(msg, params) < 0)
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004639 return -1;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004640
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004641 if (params->p2p)
4642 wpa_printf(MSG_DEBUG, " * P2P group");
4643
4644 return 0;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004645}
4646
4647
4648static int wpa_driver_nl80211_try_connect(
4649 struct wpa_driver_nl80211_data *drv,
4650 struct wpa_driver_associate_params *params)
4651{
4652 struct nl_msg *msg;
4653 enum nl80211_auth_type type;
4654 int ret;
4655 int algs;
4656
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004657 if (params->req_key_mgmt_offload && params->psk &&
4658 (params->key_mgmt_suite == WPA_KEY_MGMT_PSK ||
4659 params->key_mgmt_suite == WPA_KEY_MGMT_PSK_SHA256 ||
4660 params->key_mgmt_suite == WPA_KEY_MGMT_FT_PSK)) {
4661 wpa_printf(MSG_DEBUG, "nl80211: Key management set PSK");
4662 ret = issue_key_mgmt_set_key(drv, params->psk, 32);
4663 if (ret)
4664 return ret;
4665 }
4666
4667 wpa_printf(MSG_DEBUG, "nl80211: Connect (ifindex=%d)", drv->ifindex);
4668 msg = nl80211_drv_msg(drv, 0, NL80211_CMD_CONNECT);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004669 if (!msg)
4670 return -1;
4671
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004672 ret = nl80211_connect_common(drv, params, msg);
4673 if (ret)
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004674 goto fail;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004675
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004676 algs = 0;
4677 if (params->auth_alg & WPA_AUTH_ALG_OPEN)
4678 algs++;
4679 if (params->auth_alg & WPA_AUTH_ALG_SHARED)
4680 algs++;
4681 if (params->auth_alg & WPA_AUTH_ALG_LEAP)
4682 algs++;
4683 if (algs > 1) {
4684 wpa_printf(MSG_DEBUG, " * Leave out Auth Type for automatic "
4685 "selection");
4686 goto skip_auth_type;
4687 }
4688
4689 if (params->auth_alg & WPA_AUTH_ALG_OPEN)
4690 type = NL80211_AUTHTYPE_OPEN_SYSTEM;
4691 else if (params->auth_alg & WPA_AUTH_ALG_SHARED)
4692 type = NL80211_AUTHTYPE_SHARED_KEY;
4693 else if (params->auth_alg & WPA_AUTH_ALG_LEAP)
4694 type = NL80211_AUTHTYPE_NETWORK_EAP;
4695 else if (params->auth_alg & WPA_AUTH_ALG_FT)
4696 type = NL80211_AUTHTYPE_FT;
4697 else
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004698 goto fail;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004699
4700 wpa_printf(MSG_DEBUG, " * Auth Type %d", type);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004701 if (nla_put_u32(msg, NL80211_ATTR_AUTH_TYPE, type))
4702 goto fail;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004703
4704skip_auth_type:
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004705 ret = nl80211_set_conn_keys(params, msg);
4706 if (ret)
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004707 goto fail;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004708
4709 ret = send_and_recv_msgs(drv, msg, NULL, NULL);
4710 msg = NULL;
4711 if (ret) {
4712 wpa_printf(MSG_DEBUG, "nl80211: MLME connect failed: ret=%d "
4713 "(%s)", ret, strerror(-ret));
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004714 } else {
4715 wpa_printf(MSG_DEBUG,
4716 "nl80211: Connect request send successfully");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004717 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004718
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004719fail:
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004720 nlmsg_free(msg);
4721 return ret;
4722
4723}
4724
4725
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08004726static int wpa_driver_nl80211_connect(
4727 struct wpa_driver_nl80211_data *drv,
4728 struct wpa_driver_associate_params *params)
4729{
Jithu Jancea7c60b42014-12-03 18:54:40 +05304730 int ret;
4731
4732 /* Store the connection attempted bssid for future use */
4733 if (params->bssid)
4734 os_memcpy(drv->auth_attempt_bssid, params->bssid, ETH_ALEN);
4735 else
4736 os_memset(drv->auth_attempt_bssid, 0, ETH_ALEN);
4737
4738 ret = wpa_driver_nl80211_try_connect(drv, params);
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08004739 if (ret == -EALREADY) {
4740 /*
4741 * cfg80211 does not currently accept new connections if
4742 * we are already connected. As a workaround, force
4743 * disconnection and try again.
4744 */
4745 wpa_printf(MSG_DEBUG, "nl80211: Explicitly "
4746 "disconnecting before reassociation "
4747 "attempt");
4748 if (wpa_driver_nl80211_disconnect(
4749 drv, WLAN_REASON_PREV_AUTH_NOT_VALID))
4750 return -1;
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08004751 ret = wpa_driver_nl80211_try_connect(drv, params);
4752 }
4753 return ret;
4754}
4755
4756
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004757static int wpa_driver_nl80211_associate(
4758 void *priv, struct wpa_driver_associate_params *params)
4759{
4760 struct i802_bss *bss = priv;
4761 struct wpa_driver_nl80211_data *drv = bss->drv;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004762 int ret = -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004763 struct nl_msg *msg;
4764
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004765 nl80211_unmask_11b_rates(bss);
4766
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004767 if (params->mode == IEEE80211_MODE_AP)
4768 return wpa_driver_nl80211_ap(drv, params);
4769
4770 if (params->mode == IEEE80211_MODE_IBSS)
4771 return wpa_driver_nl80211_ibss(drv, params);
4772
4773 if (!(drv->capa.flags & WPA_DRIVER_FLAGS_SME)) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004774 enum nl80211_iftype nlmode = params->p2p ?
4775 NL80211_IFTYPE_P2P_CLIENT : NL80211_IFTYPE_STATION;
4776
4777 if (wpa_driver_nl80211_set_mode(priv, nlmode) < 0)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004778 return -1;
4779 return wpa_driver_nl80211_connect(drv, params);
4780 }
4781
Dmitry Shmidt8bae4132013-06-06 11:25:10 -07004782 nl80211_mark_disconnected(drv);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004783
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004784 wpa_printf(MSG_DEBUG, "nl80211: Associate (ifindex=%d)",
4785 drv->ifindex);
4786 msg = nl80211_drv_msg(drv, 0, NL80211_CMD_ASSOCIATE);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004787 if (!msg)
4788 return -1;
4789
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004790 ret = nl80211_connect_common(drv, params, msg);
4791 if (ret)
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004792 goto fail;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004793
4794 if (params->prev_bssid) {
4795 wpa_printf(MSG_DEBUG, " * prev_bssid=" MACSTR,
4796 MAC2STR(params->prev_bssid));
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004797 if (nla_put(msg, NL80211_ATTR_PREV_BSSID, ETH_ALEN,
4798 params->prev_bssid))
4799 goto fail;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004800 }
4801
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004802 ret = send_and_recv_msgs(drv, msg, NULL, NULL);
4803 msg = NULL;
4804 if (ret) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004805 wpa_dbg(drv->ctx, MSG_DEBUG,
4806 "nl80211: MLME command failed (assoc): ret=%d (%s)",
4807 ret, strerror(-ret));
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004808 nl80211_dump_scan(drv);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004809 } else {
4810 wpa_printf(MSG_DEBUG,
4811 "nl80211: Association request send successfully");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004812 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004813
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004814fail:
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004815 nlmsg_free(msg);
4816 return ret;
4817}
4818
4819
4820static int nl80211_set_mode(struct wpa_driver_nl80211_data *drv,
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004821 int ifindex, enum nl80211_iftype mode)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004822{
4823 struct nl_msg *msg;
4824 int ret = -ENOBUFS;
4825
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004826 wpa_printf(MSG_DEBUG, "nl80211: Set mode ifindex %d iftype %d (%s)",
4827 ifindex, mode, nl80211_iftype_str(mode));
4828
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004829 msg = nl80211_cmd_msg(drv->first_bss, 0, NL80211_CMD_SET_INTERFACE);
4830 if (!msg || nla_put_u32(msg, NL80211_ATTR_IFTYPE, mode))
4831 goto fail;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004832
4833 ret = send_and_recv_msgs(drv, msg, NULL, NULL);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004834 msg = NULL;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004835 if (!ret)
4836 return 0;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004837fail:
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004838 nlmsg_free(msg);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004839 wpa_printf(MSG_DEBUG, "nl80211: Failed to set interface %d to mode %d:"
4840 " %d (%s)", ifindex, mode, ret, strerror(-ret));
4841 return ret;
4842}
4843
4844
Dmitry Shmidtd30ac602014-06-30 09:54:22 -07004845static int wpa_driver_nl80211_set_mode_impl(
4846 struct i802_bss *bss,
4847 enum nl80211_iftype nlmode,
4848 struct hostapd_freq_params *desired_freq_params)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004849{
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004850 struct wpa_driver_nl80211_data *drv = bss->drv;
4851 int ret = -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004852 int i;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004853 int was_ap = is_ap_interface(drv->nlmode);
4854 int res;
Dmitry Shmidtd30ac602014-06-30 09:54:22 -07004855 int mode_switch_res;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004856
Dmitry Shmidtd30ac602014-06-30 09:54:22 -07004857 mode_switch_res = nl80211_set_mode(drv, drv->ifindex, nlmode);
4858 if (mode_switch_res && nlmode == nl80211_get_ifmode(bss))
4859 mode_switch_res = 0;
Dmitry Shmidt34af3062013-07-11 10:46:32 -07004860
Dmitry Shmidtd30ac602014-06-30 09:54:22 -07004861 if (mode_switch_res == 0) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004862 drv->nlmode = nlmode;
4863 ret = 0;
4864 goto done;
4865 }
4866
Dmitry Shmidtd30ac602014-06-30 09:54:22 -07004867 if (mode_switch_res == -ENODEV)
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004868 return -1;
4869
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004870 if (nlmode == drv->nlmode) {
4871 wpa_printf(MSG_DEBUG, "nl80211: Interface already in "
4872 "requested mode - ignore error");
4873 ret = 0;
4874 goto done; /* Already in the requested mode */
4875 }
4876
4877 /* mac80211 doesn't allow mode changes while the device is up, so
4878 * take the device down, try to set the mode again, and bring the
4879 * device back up.
4880 */
4881 wpa_printf(MSG_DEBUG, "nl80211: Try mode change after setting "
4882 "interface down");
4883 for (i = 0; i < 10; i++) {
Dmitry Shmidt34af3062013-07-11 10:46:32 -07004884 res = i802_set_iface_flags(bss, 0);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004885 if (res == -EACCES || res == -ENODEV)
4886 break;
Dmitry Shmidtd30ac602014-06-30 09:54:22 -07004887 if (res != 0) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004888 wpa_printf(MSG_DEBUG, "nl80211: Failed to set "
4889 "interface down");
Dmitry Shmidtd30ac602014-06-30 09:54:22 -07004890 os_sleep(0, 100000);
4891 continue;
4892 }
4893
4894 /*
4895 * Setting the mode will fail for some drivers if the phy is
4896 * on a frequency that the mode is disallowed in.
4897 */
4898 if (desired_freq_params) {
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004899 res = nl80211_set_channel(bss, desired_freq_params, 0);
Dmitry Shmidtd30ac602014-06-30 09:54:22 -07004900 if (res) {
4901 wpa_printf(MSG_DEBUG,
4902 "nl80211: Failed to set frequency on interface");
4903 }
4904 }
4905
4906 /* Try to set the mode again while the interface is down */
4907 mode_switch_res = nl80211_set_mode(drv, drv->ifindex, nlmode);
4908 if (mode_switch_res == -EBUSY) {
4909 wpa_printf(MSG_DEBUG,
4910 "nl80211: Delaying mode set while interface going down");
4911 os_sleep(0, 100000);
4912 continue;
4913 }
4914 ret = mode_switch_res;
4915 break;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004916 }
4917
4918 if (!ret) {
4919 wpa_printf(MSG_DEBUG, "nl80211: Mode change succeeded while "
4920 "interface is down");
4921 drv->nlmode = nlmode;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004922 drv->ignore_if_down_event = 1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004923 }
4924
Dmitry Shmidtd30ac602014-06-30 09:54:22 -07004925 /* Bring the interface back up */
4926 res = linux_set_iface_flags(drv->global->ioctl_sock, bss->ifname, 1);
4927 if (res != 0) {
4928 wpa_printf(MSG_DEBUG,
4929 "nl80211: Failed to set interface up after switching mode");
4930 ret = -1;
4931 }
4932
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004933done:
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004934 if (ret) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004935 wpa_printf(MSG_DEBUG, "nl80211: Interface mode change to %d "
4936 "from %d failed", nlmode, drv->nlmode);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004937 return ret;
4938 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004939
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004940 if (is_p2p_net_interface(nlmode)) {
4941 wpa_printf(MSG_DEBUG,
4942 "nl80211: Interface %s mode change to P2P - disable 11b rates",
4943 bss->ifname);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07004944 nl80211_disable_11b_rates(drv, drv->ifindex, 1);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004945 } else if (drv->disabled_11b_rates) {
4946 wpa_printf(MSG_DEBUG,
4947 "nl80211: Interface %s mode changed to non-P2P - re-enable 11b rates",
4948 bss->ifname);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07004949 nl80211_disable_11b_rates(drv, drv->ifindex, 0);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004950 }
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07004951
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004952 if (is_ap_interface(nlmode)) {
4953 nl80211_mgmt_unsubscribe(bss, "start AP");
4954 /* Setup additional AP mode functionality if needed */
4955 if (nl80211_setup_ap(bss))
4956 return -1;
4957 } else if (was_ap) {
4958 /* Remove additional AP mode functionality */
4959 nl80211_teardown_ap(bss);
4960 } else {
4961 nl80211_mgmt_unsubscribe(bss, "mode change");
4962 }
4963
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004964 if (is_mesh_interface(nlmode) &&
4965 nl80211_mgmt_subscribe_mesh(bss))
4966 return -1;
4967
Dmitry Shmidt04949592012-07-19 12:16:46 -07004968 if (!bss->in_deinit && !is_ap_interface(nlmode) &&
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004969 !is_mesh_interface(nlmode) &&
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004970 nl80211_mgmt_subscribe_non_ap(bss) < 0)
4971 wpa_printf(MSG_DEBUG, "nl80211: Failed to register Action "
4972 "frame processing - ignore for now");
4973
4974 return 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004975}
4976
4977
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004978int wpa_driver_nl80211_set_mode(struct i802_bss *bss,
4979 enum nl80211_iftype nlmode)
Dmitry Shmidtd30ac602014-06-30 09:54:22 -07004980{
4981 return wpa_driver_nl80211_set_mode_impl(bss, nlmode, NULL);
4982}
4983
4984
Dmitry Shmidt9ead16e2014-10-07 13:15:23 -07004985static int wpa_driver_nl80211_set_mode_ibss(struct i802_bss *bss,
4986 struct hostapd_freq_params *freq)
Dmitry Shmidtd30ac602014-06-30 09:54:22 -07004987{
Dmitry Shmidtd30ac602014-06-30 09:54:22 -07004988 return wpa_driver_nl80211_set_mode_impl(bss, NL80211_IFTYPE_ADHOC,
Dmitry Shmidt9ead16e2014-10-07 13:15:23 -07004989 freq);
Dmitry Shmidtd30ac602014-06-30 09:54:22 -07004990}
4991
4992
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004993static int wpa_driver_nl80211_get_capa(void *priv,
4994 struct wpa_driver_capa *capa)
4995{
4996 struct i802_bss *bss = priv;
4997 struct wpa_driver_nl80211_data *drv = bss->drv;
Dmitry Shmidtd11f0192014-03-24 12:09:47 -07004998
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004999 if (!drv->has_capability)
5000 return -1;
5001 os_memcpy(capa, &drv->capa, sizeof(*capa));
Dmitry Shmidt444d5672013-04-01 13:08:44 -07005002 if (drv->extended_capa && drv->extended_capa_mask) {
5003 capa->extended_capa = drv->extended_capa;
5004 capa->extended_capa_mask = drv->extended_capa_mask;
5005 capa->extended_capa_len = drv->extended_capa_len;
5006 }
Dmitry Shmidt34af3062013-07-11 10:46:32 -07005007
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005008 return 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005009}
5010
5011
5012static int wpa_driver_nl80211_set_operstate(void *priv, int state)
5013{
5014 struct i802_bss *bss = priv;
5015 struct wpa_driver_nl80211_data *drv = bss->drv;
5016
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08005017 wpa_printf(MSG_DEBUG, "nl80211: Set %s operstate %d->%d (%s)",
5018 bss->ifname, drv->operstate, state,
5019 state ? "UP" : "DORMANT");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005020 drv->operstate = state;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005021 return netlink_send_oper_ifla(drv->global->netlink, drv->ifindex, -1,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005022 state ? IF_OPER_UP : IF_OPER_DORMANT);
5023}
5024
5025
5026static int wpa_driver_nl80211_set_supp_port(void *priv, int authorized)
5027{
5028 struct i802_bss *bss = priv;
5029 struct wpa_driver_nl80211_data *drv = bss->drv;
5030 struct nl_msg *msg;
5031 struct nl80211_sta_flag_update upd;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005032 int ret;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08005033
5034 if (!drv->associated && is_zero_ether_addr(drv->bssid) && !authorized) {
5035 wpa_printf(MSG_DEBUG, "nl80211: Skip set_supp_port(unauthorized) while not associated");
5036 return 0;
5037 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005038
Dmitry Shmidt8bae4132013-06-06 11:25:10 -07005039 wpa_printf(MSG_DEBUG, "nl80211: Set supplicant port %sauthorized for "
5040 MACSTR, authorized ? "" : "un", MAC2STR(drv->bssid));
5041
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005042 os_memset(&upd, 0, sizeof(upd));
5043 upd.mask = BIT(NL80211_STA_FLAG_AUTHORIZED);
5044 if (authorized)
5045 upd.set = BIT(NL80211_STA_FLAG_AUTHORIZED);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005046
5047 if (!(msg = nl80211_bss_msg(bss, 0, NL80211_CMD_SET_STATION)) ||
5048 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, drv->bssid) ||
5049 nla_put(msg, NL80211_ATTR_STA_FLAGS2, sizeof(upd), &upd)) {
5050 nlmsg_free(msg);
5051 return -ENOBUFS;
5052 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005053
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08005054 ret = send_and_recv_msgs(drv, msg, NULL, NULL);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08005055 if (!ret)
5056 return 0;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08005057 wpa_printf(MSG_DEBUG, "nl80211: Failed to set STA flag: %d (%s)",
5058 ret, strerror(-ret));
5059 return ret;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005060}
5061
5062
Jouni Malinen75ecf522011-06-27 15:19:46 -07005063/* Set kernel driver on given frequency (MHz) */
5064static int i802_set_freq(void *priv, struct hostapd_freq_params *freq)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005065{
Jouni Malinen75ecf522011-06-27 15:19:46 -07005066 struct i802_bss *bss = priv;
Dmitry Shmidt7832adb2014-04-29 10:53:02 -07005067 return nl80211_set_channel(bss, freq, 0);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005068}
5069
5070
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005071static inline int min_int(int a, int b)
5072{
5073 if (a < b)
5074 return a;
5075 return b;
5076}
5077
5078
5079static int get_key_handler(struct nl_msg *msg, void *arg)
5080{
5081 struct nlattr *tb[NL80211_ATTR_MAX + 1];
5082 struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg));
5083
5084 nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0),
5085 genlmsg_attrlen(gnlh, 0), NULL);
5086
5087 /*
5088 * TODO: validate the key index and mac address!
5089 * Otherwise, there's a race condition as soon as
5090 * the kernel starts sending key notifications.
5091 */
5092
5093 if (tb[NL80211_ATTR_KEY_SEQ])
5094 memcpy(arg, nla_data(tb[NL80211_ATTR_KEY_SEQ]),
5095 min_int(nla_len(tb[NL80211_ATTR_KEY_SEQ]), 6));
5096 return NL_SKIP;
5097}
5098
5099
5100static int i802_get_seqnum(const char *iface, void *priv, const u8 *addr,
5101 int idx, u8 *seq)
5102{
5103 struct i802_bss *bss = priv;
5104 struct wpa_driver_nl80211_data *drv = bss->drv;
5105 struct nl_msg *msg;
5106
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005107 msg = nl80211_ifindex_msg(drv, if_nametoindex(iface), 0,
5108 NL80211_CMD_GET_KEY);
5109 if (!msg ||
5110 (addr && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) ||
5111 nla_put_u8(msg, NL80211_ATTR_KEY_IDX, idx)) {
5112 nlmsg_free(msg);
5113 return -ENOBUFS;
5114 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005115
5116 memset(seq, 0, 6);
5117
5118 return send_and_recv_msgs(drv, msg, get_key_handler, seq);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005119}
5120
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005121
5122static int i802_set_rts(void *priv, int rts)
5123{
5124 struct i802_bss *bss = priv;
5125 struct wpa_driver_nl80211_data *drv = bss->drv;
5126 struct nl_msg *msg;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005127 int ret;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005128 u32 val;
5129
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005130 if (rts >= 2347)
5131 val = (u32) -1;
5132 else
5133 val = rts;
5134
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005135 if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_SET_WIPHY)) ||
5136 nla_put_u32(msg, NL80211_ATTR_WIPHY_RTS_THRESHOLD, val)) {
5137 nlmsg_free(msg);
5138 return -ENOBUFS;
5139 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005140
5141 ret = send_and_recv_msgs(drv, msg, NULL, NULL);
5142 if (!ret)
5143 return 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005144 wpa_printf(MSG_DEBUG, "nl80211: Failed to set RTS threshold %d: "
5145 "%d (%s)", rts, ret, strerror(-ret));
5146 return ret;
5147}
5148
5149
5150static int i802_set_frag(void *priv, int frag)
5151{
5152 struct i802_bss *bss = priv;
5153 struct wpa_driver_nl80211_data *drv = bss->drv;
5154 struct nl_msg *msg;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005155 int ret;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005156 u32 val;
5157
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005158 if (frag >= 2346)
5159 val = (u32) -1;
5160 else
5161 val = frag;
5162
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005163 if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_SET_WIPHY)) ||
5164 nla_put_u32(msg, NL80211_ATTR_WIPHY_FRAG_THRESHOLD, val)) {
5165 nlmsg_free(msg);
5166 return -ENOBUFS;
5167 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005168
5169 ret = send_and_recv_msgs(drv, msg, NULL, NULL);
5170 if (!ret)
5171 return 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005172 wpa_printf(MSG_DEBUG, "nl80211: Failed to set fragmentation threshold "
5173 "%d: %d (%s)", frag, ret, strerror(-ret));
5174 return ret;
5175}
5176
5177
5178static int i802_flush(void *priv)
5179{
5180 struct i802_bss *bss = priv;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005181 struct nl_msg *msg;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005182 int res;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005183
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -07005184 wpa_printf(MSG_DEBUG, "nl80211: flush -> DEL_STATION %s (all)",
5185 bss->ifname);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005186
5187 /*
5188 * XXX: FIX! this needs to flush all VLANs too
5189 */
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005190 msg = nl80211_bss_msg(bss, 0, NL80211_CMD_DEL_STATION);
5191 res = send_and_recv_msgs(bss->drv, msg, NULL, NULL);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005192 if (res) {
5193 wpa_printf(MSG_DEBUG, "nl80211: Station flush failed: ret=%d "
5194 "(%s)", res, strerror(-res));
5195 }
5196 return res;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005197}
5198
5199
5200static int get_sta_handler(struct nl_msg *msg, void *arg)
5201{
5202 struct nlattr *tb[NL80211_ATTR_MAX + 1];
5203 struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg));
5204 struct hostap_sta_driver_data *data = arg;
5205 struct nlattr *stats[NL80211_STA_INFO_MAX + 1];
5206 static struct nla_policy stats_policy[NL80211_STA_INFO_MAX + 1] = {
5207 [NL80211_STA_INFO_INACTIVE_TIME] = { .type = NLA_U32 },
5208 [NL80211_STA_INFO_RX_BYTES] = { .type = NLA_U32 },
5209 [NL80211_STA_INFO_TX_BYTES] = { .type = NLA_U32 },
5210 [NL80211_STA_INFO_RX_PACKETS] = { .type = NLA_U32 },
5211 [NL80211_STA_INFO_TX_PACKETS] = { .type = NLA_U32 },
Jouni Malinen1e6c57f2012-09-05 17:07:03 +03005212 [NL80211_STA_INFO_TX_FAILED] = { .type = NLA_U32 },
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005213 };
5214
5215 nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0),
5216 genlmsg_attrlen(gnlh, 0), NULL);
5217
5218 /*
5219 * TODO: validate the interface and mac address!
5220 * Otherwise, there's a race condition as soon as
5221 * the kernel starts sending station notifications.
5222 */
5223
5224 if (!tb[NL80211_ATTR_STA_INFO]) {
5225 wpa_printf(MSG_DEBUG, "sta stats missing!");
5226 return NL_SKIP;
5227 }
5228 if (nla_parse_nested(stats, NL80211_STA_INFO_MAX,
5229 tb[NL80211_ATTR_STA_INFO],
5230 stats_policy)) {
5231 wpa_printf(MSG_DEBUG, "failed to parse nested attributes!");
5232 return NL_SKIP;
5233 }
5234
5235 if (stats[NL80211_STA_INFO_INACTIVE_TIME])
5236 data->inactive_msec =
5237 nla_get_u32(stats[NL80211_STA_INFO_INACTIVE_TIME]);
5238 if (stats[NL80211_STA_INFO_RX_BYTES])
5239 data->rx_bytes = nla_get_u32(stats[NL80211_STA_INFO_RX_BYTES]);
5240 if (stats[NL80211_STA_INFO_TX_BYTES])
5241 data->tx_bytes = nla_get_u32(stats[NL80211_STA_INFO_TX_BYTES]);
5242 if (stats[NL80211_STA_INFO_RX_PACKETS])
5243 data->rx_packets =
5244 nla_get_u32(stats[NL80211_STA_INFO_RX_PACKETS]);
5245 if (stats[NL80211_STA_INFO_TX_PACKETS])
5246 data->tx_packets =
5247 nla_get_u32(stats[NL80211_STA_INFO_TX_PACKETS]);
Jouni Malinen1e6c57f2012-09-05 17:07:03 +03005248 if (stats[NL80211_STA_INFO_TX_FAILED])
5249 data->tx_retry_failed =
5250 nla_get_u32(stats[NL80211_STA_INFO_TX_FAILED]);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005251
5252 return NL_SKIP;
5253}
5254
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08005255static int i802_read_sta_data(struct i802_bss *bss,
5256 struct hostap_sta_driver_data *data,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005257 const u8 *addr)
5258{
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005259 struct nl_msg *msg;
5260
5261 os_memset(data, 0, sizeof(*data));
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005262
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005263 if (!(msg = nl80211_bss_msg(bss, 0, NL80211_CMD_GET_STATION)) ||
5264 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) {
5265 nlmsg_free(msg);
5266 return -ENOBUFS;
5267 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005268
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005269 return send_and_recv_msgs(bss->drv, msg, get_sta_handler, data);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005270}
5271
5272
5273static int i802_set_tx_queue_params(void *priv, int queue, int aifs,
5274 int cw_min, int cw_max, int burst_time)
5275{
5276 struct i802_bss *bss = priv;
5277 struct wpa_driver_nl80211_data *drv = bss->drv;
5278 struct nl_msg *msg;
5279 struct nlattr *txq, *params;
5280
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005281 msg = nl80211_bss_msg(bss, 0, NL80211_CMD_SET_WIPHY);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005282 if (!msg)
5283 return -1;
5284
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005285 txq = nla_nest_start(msg, NL80211_ATTR_WIPHY_TXQ_PARAMS);
5286 if (!txq)
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005287 goto fail;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005288
5289 /* We are only sending parameters for a single TXQ at a time */
5290 params = nla_nest_start(msg, 1);
5291 if (!params)
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005292 goto fail;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005293
5294 switch (queue) {
5295 case 0:
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005296 if (nla_put_u8(msg, NL80211_TXQ_ATTR_QUEUE, NL80211_TXQ_Q_VO))
5297 goto fail;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005298 break;
5299 case 1:
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005300 if (nla_put_u8(msg, NL80211_TXQ_ATTR_QUEUE, NL80211_TXQ_Q_VI))
5301 goto fail;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005302 break;
5303 case 2:
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005304 if (nla_put_u8(msg, NL80211_TXQ_ATTR_QUEUE, NL80211_TXQ_Q_BE))
5305 goto fail;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005306 break;
5307 case 3:
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005308 if (nla_put_u8(msg, NL80211_TXQ_ATTR_QUEUE, NL80211_TXQ_Q_BK))
5309 goto fail;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005310 break;
5311 }
5312 /* Burst time is configured in units of 0.1 msec and TXOP parameter in
5313 * 32 usec, so need to convert the value here. */
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005314 if (nla_put_u16(msg, NL80211_TXQ_ATTR_TXOP,
5315 (burst_time * 100 + 16) / 32) ||
5316 nla_put_u16(msg, NL80211_TXQ_ATTR_CWMIN, cw_min) ||
5317 nla_put_u16(msg, NL80211_TXQ_ATTR_CWMAX, cw_max) ||
5318 nla_put_u8(msg, NL80211_TXQ_ATTR_AIFS, aifs))
5319 goto fail;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005320
5321 nla_nest_end(msg, params);
5322
5323 nla_nest_end(msg, txq);
5324
5325 if (send_and_recv_msgs(drv, msg, NULL, NULL) == 0)
5326 return 0;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005327 msg = NULL;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005328fail:
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005329 nlmsg_free(msg);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005330 return -1;
5331}
5332
5333
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08005334static int i802_set_sta_vlan(struct i802_bss *bss, const u8 *addr,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005335 const char *ifname, int vlan_id)
5336{
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005337 struct wpa_driver_nl80211_data *drv = bss->drv;
5338 struct nl_msg *msg;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005339 int ret;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005340
Dmitry Shmidtcce06662013-11-04 18:44:24 -08005341 wpa_printf(MSG_DEBUG, "nl80211: %s[%d]: set_sta_vlan(" MACSTR
5342 ", ifname=%s[%d], vlan_id=%d)",
5343 bss->ifname, if_nametoindex(bss->ifname),
5344 MAC2STR(addr), ifname, if_nametoindex(ifname), vlan_id);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005345 if (!(msg = nl80211_bss_msg(bss, 0, NL80211_CMD_SET_STATION)) ||
5346 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) ||
5347 nla_put_u32(msg, NL80211_ATTR_STA_VLAN, if_nametoindex(ifname))) {
5348 nlmsg_free(msg);
5349 return -ENOBUFS;
5350 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005351
5352 ret = send_and_recv_msgs(drv, msg, NULL, NULL);
5353 if (ret < 0) {
5354 wpa_printf(MSG_ERROR, "nl80211: NL80211_ATTR_STA_VLAN (addr="
5355 MACSTR " ifname=%s vlan_id=%d) failed: %d (%s)",
5356 MAC2STR(addr), ifname, vlan_id, ret,
5357 strerror(-ret));
5358 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005359 return ret;
5360}
5361
5362
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005363static int i802_get_inact_sec(void *priv, const u8 *addr)
5364{
5365 struct hostap_sta_driver_data data;
5366 int ret;
5367
5368 data.inactive_msec = (unsigned long) -1;
5369 ret = i802_read_sta_data(priv, &data, addr);
Dmitry Shmidt2f74e362015-01-21 13:19:05 -08005370 if (ret == -ENOENT)
5371 return -ENOENT;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005372 if (ret || data.inactive_msec == (unsigned long) -1)
5373 return -1;
5374 return data.inactive_msec / 1000;
5375}
5376
5377
5378static int i802_sta_clear_stats(void *priv, const u8 *addr)
5379{
5380#if 0
5381 /* TODO */
5382#endif
5383 return 0;
5384}
5385
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005386
5387static int i802_sta_deauth(void *priv, const u8 *own_addr, const u8 *addr,
5388 int reason)
5389{
5390 struct i802_bss *bss = priv;
Dmitry Shmidt04949592012-07-19 12:16:46 -07005391 struct wpa_driver_nl80211_data *drv = bss->drv;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005392 struct ieee80211_mgmt mgmt;
5393
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005394 if (is_mesh_interface(drv->nlmode))
5395 return -1;
5396
Dmitry Shmidt04949592012-07-19 12:16:46 -07005397 if (drv->device_ap_sme)
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005398 return wpa_driver_nl80211_sta_remove(bss, addr, 1, reason);
Dmitry Shmidt04949592012-07-19 12:16:46 -07005399
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005400 memset(&mgmt, 0, sizeof(mgmt));
5401 mgmt.frame_control = IEEE80211_FC(WLAN_FC_TYPE_MGMT,
5402 WLAN_FC_STYPE_DEAUTH);
5403 memcpy(mgmt.da, addr, ETH_ALEN);
5404 memcpy(mgmt.sa, own_addr, ETH_ALEN);
5405 memcpy(mgmt.bssid, own_addr, ETH_ALEN);
5406 mgmt.u.deauth.reason_code = host_to_le16(reason);
5407 return wpa_driver_nl80211_send_mlme(bss, (u8 *) &mgmt,
5408 IEEE80211_HDRLEN +
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08005409 sizeof(mgmt.u.deauth), 0, 0, 0, 0,
5410 0);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005411}
5412
5413
5414static int i802_sta_disassoc(void *priv, const u8 *own_addr, const u8 *addr,
5415 int reason)
5416{
5417 struct i802_bss *bss = priv;
Dmitry Shmidt04949592012-07-19 12:16:46 -07005418 struct wpa_driver_nl80211_data *drv = bss->drv;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005419 struct ieee80211_mgmt mgmt;
5420
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005421 if (is_mesh_interface(drv->nlmode))
5422 return -1;
5423
Dmitry Shmidt04949592012-07-19 12:16:46 -07005424 if (drv->device_ap_sme)
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005425 return wpa_driver_nl80211_sta_remove(bss, addr, 0, reason);
Dmitry Shmidt04949592012-07-19 12:16:46 -07005426
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005427 memset(&mgmt, 0, sizeof(mgmt));
5428 mgmt.frame_control = IEEE80211_FC(WLAN_FC_TYPE_MGMT,
5429 WLAN_FC_STYPE_DISASSOC);
5430 memcpy(mgmt.da, addr, ETH_ALEN);
5431 memcpy(mgmt.sa, own_addr, ETH_ALEN);
5432 memcpy(mgmt.bssid, own_addr, ETH_ALEN);
5433 mgmt.u.disassoc.reason_code = host_to_le16(reason);
5434 return wpa_driver_nl80211_send_mlme(bss, (u8 *) &mgmt,
5435 IEEE80211_HDRLEN +
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08005436 sizeof(mgmt.u.disassoc), 0, 0, 0, 0,
5437 0);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005438}
5439
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005440
Dmitry Shmidtdf5a7e42014-04-02 12:59:59 -07005441static void dump_ifidx(struct wpa_driver_nl80211_data *drv)
5442{
5443 char buf[200], *pos, *end;
5444 int i, res;
5445
5446 pos = buf;
5447 end = pos + sizeof(buf);
5448
5449 for (i = 0; i < drv->num_if_indices; i++) {
5450 if (!drv->if_indices[i])
5451 continue;
5452 res = os_snprintf(pos, end - pos, " %d", drv->if_indices[i]);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005453 if (os_snprintf_error(end - pos, res))
Dmitry Shmidtdf5a7e42014-04-02 12:59:59 -07005454 break;
5455 pos += res;
5456 }
5457 *pos = '\0';
5458
5459 wpa_printf(MSG_DEBUG, "nl80211: if_indices[%d]:%s",
5460 drv->num_if_indices, buf);
5461}
5462
5463
Jouni Malinen75ecf522011-06-27 15:19:46 -07005464static void add_ifidx(struct wpa_driver_nl80211_data *drv, int ifidx)
5465{
5466 int i;
5467 int *old;
5468
5469 wpa_printf(MSG_DEBUG, "nl80211: Add own interface ifindex %d",
5470 ifidx);
Dmitry Shmidtdf5a7e42014-04-02 12:59:59 -07005471 if (have_ifidx(drv, ifidx)) {
5472 wpa_printf(MSG_DEBUG, "nl80211: ifindex %d already in the list",
5473 ifidx);
5474 return;
5475 }
Jouni Malinen75ecf522011-06-27 15:19:46 -07005476 for (i = 0; i < drv->num_if_indices; i++) {
5477 if (drv->if_indices[i] == 0) {
5478 drv->if_indices[i] = ifidx;
Dmitry Shmidtdf5a7e42014-04-02 12:59:59 -07005479 dump_ifidx(drv);
Jouni Malinen75ecf522011-06-27 15:19:46 -07005480 return;
5481 }
5482 }
5483
5484 if (drv->if_indices != drv->default_if_indices)
5485 old = drv->if_indices;
5486 else
5487 old = NULL;
5488
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07005489 drv->if_indices = os_realloc_array(old, drv->num_if_indices + 1,
5490 sizeof(int));
Jouni Malinen75ecf522011-06-27 15:19:46 -07005491 if (!drv->if_indices) {
5492 if (!old)
5493 drv->if_indices = drv->default_if_indices;
5494 else
5495 drv->if_indices = old;
5496 wpa_printf(MSG_ERROR, "Failed to reallocate memory for "
5497 "interfaces");
5498 wpa_printf(MSG_ERROR, "Ignoring EAPOL on interface %d", ifidx);
5499 return;
5500 } else if (!old)
5501 os_memcpy(drv->if_indices, drv->default_if_indices,
5502 sizeof(drv->default_if_indices));
5503 drv->if_indices[drv->num_if_indices] = ifidx;
5504 drv->num_if_indices++;
Dmitry Shmidtdf5a7e42014-04-02 12:59:59 -07005505 dump_ifidx(drv);
Jouni Malinen75ecf522011-06-27 15:19:46 -07005506}
5507
5508
5509static void del_ifidx(struct wpa_driver_nl80211_data *drv, int ifidx)
5510{
5511 int i;
5512
5513 for (i = 0; i < drv->num_if_indices; i++) {
5514 if (drv->if_indices[i] == ifidx) {
5515 drv->if_indices[i] = 0;
5516 break;
5517 }
5518 }
Dmitry Shmidtdf5a7e42014-04-02 12:59:59 -07005519 dump_ifidx(drv);
Jouni Malinen75ecf522011-06-27 15:19:46 -07005520}
5521
5522
5523static int have_ifidx(struct wpa_driver_nl80211_data *drv, int ifidx)
5524{
5525 int i;
5526
5527 for (i = 0; i < drv->num_if_indices; i++)
5528 if (drv->if_indices[i] == ifidx)
5529 return 1;
5530
5531 return 0;
5532}
5533
5534
5535static int i802_set_wds_sta(void *priv, const u8 *addr, int aid, int val,
Dmitry Shmidt7832adb2014-04-29 10:53:02 -07005536 const char *bridge_ifname, char *ifname_wds)
Jouni Malinen75ecf522011-06-27 15:19:46 -07005537{
5538 struct i802_bss *bss = priv;
5539 struct wpa_driver_nl80211_data *drv = bss->drv;
5540 char name[IFNAMSIZ + 1];
5541
5542 os_snprintf(name, sizeof(name), "%s.sta%d", bss->ifname, aid);
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07005543 if (ifname_wds)
5544 os_strlcpy(ifname_wds, name, IFNAMSIZ + 1);
5545
Jouni Malinen75ecf522011-06-27 15:19:46 -07005546 wpa_printf(MSG_DEBUG, "nl80211: Set WDS STA addr=" MACSTR
5547 " aid=%d val=%d name=%s", MAC2STR(addr), aid, val, name);
5548 if (val) {
5549 if (!if_nametoindex(name)) {
5550 if (nl80211_create_iface(drv, name,
5551 NL80211_IFTYPE_AP_VLAN,
Dmitry Shmidtcce06662013-11-04 18:44:24 -08005552 bss->addr, 1, NULL, NULL, 0) <
5553 0)
Jouni Malinen75ecf522011-06-27 15:19:46 -07005554 return -1;
5555 if (bridge_ifname &&
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005556 linux_br_add_if(drv->global->ioctl_sock,
5557 bridge_ifname, name) < 0)
Jouni Malinen75ecf522011-06-27 15:19:46 -07005558 return -1;
5559 }
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07005560 if (linux_set_iface_flags(drv->global->ioctl_sock, name, 1)) {
5561 wpa_printf(MSG_ERROR, "nl80211: Failed to set WDS STA "
5562 "interface %s up", name);
5563 }
Jouni Malinen75ecf522011-06-27 15:19:46 -07005564 return i802_set_sta_vlan(priv, addr, name, 0);
5565 } else {
Dmitry Shmidtaa532512012-09-24 10:35:31 -07005566 if (bridge_ifname)
5567 linux_br_del_if(drv->global->ioctl_sock, bridge_ifname,
5568 name);
5569
Jouni Malinen75ecf522011-06-27 15:19:46 -07005570 i802_set_sta_vlan(priv, addr, bss->ifname, 0);
Dmitry Shmidta38abf92014-03-06 13:38:44 -08005571 nl80211_remove_iface(drv, if_nametoindex(name));
5572 return 0;
Jouni Malinen75ecf522011-06-27 15:19:46 -07005573 }
5574}
5575
5576
5577static void handle_eapol(int sock, void *eloop_ctx, void *sock_ctx)
5578{
5579 struct wpa_driver_nl80211_data *drv = eloop_ctx;
5580 struct sockaddr_ll lladdr;
5581 unsigned char buf[3000];
5582 int len;
5583 socklen_t fromlen = sizeof(lladdr);
5584
5585 len = recvfrom(sock, buf, sizeof(buf), 0,
5586 (struct sockaddr *)&lladdr, &fromlen);
5587 if (len < 0) {
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -07005588 wpa_printf(MSG_ERROR, "nl80211: EAPOL recv failed: %s",
5589 strerror(errno));
Jouni Malinen75ecf522011-06-27 15:19:46 -07005590 return;
5591 }
5592
5593 if (have_ifidx(drv, lladdr.sll_ifindex))
5594 drv_event_eapol_rx(drv->ctx, lladdr.sll_addr, buf, len);
5595}
5596
5597
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005598static int i802_check_bridge(struct wpa_driver_nl80211_data *drv,
5599 struct i802_bss *bss,
5600 const char *brname, const char *ifname)
5601{
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005602 int br_ifindex;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005603 char in_br[IFNAMSIZ];
5604
5605 os_strlcpy(bss->brname, brname, IFNAMSIZ);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005606 br_ifindex = if_nametoindex(brname);
5607 if (br_ifindex == 0) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005608 /*
5609 * Bridge was configured, but the bridge device does
5610 * not exist. Try to add it now.
5611 */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005612 if (linux_br_add(drv->global->ioctl_sock, brname) < 0) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005613 wpa_printf(MSG_ERROR, "nl80211: Failed to add the "
5614 "bridge interface %s: %s",
5615 brname, strerror(errno));
5616 return -1;
5617 }
5618 bss->added_bridge = 1;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005619 br_ifindex = if_nametoindex(brname);
5620 add_ifidx(drv, br_ifindex);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005621 }
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005622 bss->br_ifindex = br_ifindex;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005623
5624 if (linux_br_get(in_br, ifname) == 0) {
5625 if (os_strcmp(in_br, brname) == 0)
5626 return 0; /* already in the bridge */
5627
5628 wpa_printf(MSG_DEBUG, "nl80211: Removing interface %s from "
5629 "bridge %s", ifname, in_br);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005630 if (linux_br_del_if(drv->global->ioctl_sock, in_br, ifname) <
5631 0) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005632 wpa_printf(MSG_ERROR, "nl80211: Failed to "
5633 "remove interface %s from bridge "
5634 "%s: %s",
5635 ifname, brname, strerror(errno));
5636 return -1;
5637 }
5638 }
5639
5640 wpa_printf(MSG_DEBUG, "nl80211: Adding interface %s into bridge %s",
5641 ifname, brname);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005642 if (linux_br_add_if(drv->global->ioctl_sock, brname, ifname) < 0) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005643 wpa_printf(MSG_ERROR, "nl80211: Failed to add interface %s "
5644 "into bridge %s: %s",
5645 ifname, brname, strerror(errno));
5646 return -1;
5647 }
5648 bss->added_if_into_bridge = 1;
5649
5650 return 0;
5651}
5652
5653
5654static void *i802_init(struct hostapd_data *hapd,
5655 struct wpa_init_params *params)
5656{
5657 struct wpa_driver_nl80211_data *drv;
5658 struct i802_bss *bss;
5659 size_t i;
5660 char brname[IFNAMSIZ];
5661 int ifindex, br_ifindex;
5662 int br_added = 0;
5663
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08005664 bss = wpa_driver_nl80211_drv_init(hapd, params->ifname,
5665 params->global_priv, 1,
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005666 params->bssid, params->driver_params);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005667 if (bss == NULL)
5668 return NULL;
5669
5670 drv = bss->drv;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005671
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005672 if (linux_br_get(brname, params->ifname) == 0) {
5673 wpa_printf(MSG_DEBUG, "nl80211: Interface %s is in bridge %s",
5674 params->ifname, brname);
5675 br_ifindex = if_nametoindex(brname);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005676 os_strlcpy(bss->brname, brname, IFNAMSIZ);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005677 } else {
5678 brname[0] = '\0';
5679 br_ifindex = 0;
5680 }
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005681 bss->br_ifindex = br_ifindex;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005682
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005683 for (i = 0; i < params->num_bridge; i++) {
5684 if (params->bridge[i]) {
5685 ifindex = if_nametoindex(params->bridge[i]);
5686 if (ifindex)
5687 add_ifidx(drv, ifindex);
5688 if (ifindex == br_ifindex)
5689 br_added = 1;
5690 }
5691 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005692
5693 /* start listening for EAPOL on the default AP interface */
5694 add_ifidx(drv, drv->ifindex);
5695
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005696 if (params->num_bridge && params->bridge[0]) {
5697 if (i802_check_bridge(drv, bss, params->bridge[0],
5698 params->ifname) < 0)
5699 goto failed;
5700 if (os_strcmp(params->bridge[0], brname) != 0)
5701 br_added = 1;
5702 }
5703
5704 if (!br_added && br_ifindex &&
5705 (params->num_bridge == 0 || !params->bridge[0]))
5706 add_ifidx(drv, br_ifindex);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005707
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07005708#ifdef CONFIG_LIBNL3_ROUTE
5709 if (bss->added_if_into_bridge) {
5710 drv->rtnl_sk = nl_socket_alloc();
5711 if (drv->rtnl_sk == NULL) {
5712 wpa_printf(MSG_ERROR, "nl80211: Failed to allocate nl_sock");
5713 goto failed;
5714 }
5715
5716 if (nl_connect(drv->rtnl_sk, NETLINK_ROUTE)) {
5717 wpa_printf(MSG_ERROR, "nl80211: Failed to connect nl_sock to NETLINK_ROUTE: %s",
5718 strerror(errno));
5719 goto failed;
5720 }
5721 }
5722#endif /* CONFIG_LIBNL3_ROUTE */
5723
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005724 drv->eapol_sock = socket(PF_PACKET, SOCK_DGRAM, htons(ETH_P_PAE));
5725 if (drv->eapol_sock < 0) {
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -07005726 wpa_printf(MSG_ERROR, "nl80211: socket(PF_PACKET, SOCK_DGRAM, ETH_P_PAE) failed: %s",
5727 strerror(errno));
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005728 goto failed;
5729 }
5730
5731 if (eloop_register_read_sock(drv->eapol_sock, handle_eapol, drv, NULL))
5732 {
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -07005733 wpa_printf(MSG_INFO, "nl80211: Could not register read socket for eapol");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005734 goto failed;
5735 }
5736
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005737 if (linux_get_ifhwaddr(drv->global->ioctl_sock, bss->ifname,
5738 params->own_addr))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005739 goto failed;
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07005740 os_memcpy(drv->perm_addr, params->own_addr, ETH_ALEN);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005741
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005742 memcpy(bss->addr, params->own_addr, ETH_ALEN);
5743
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005744 return bss;
5745
5746failed:
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005747 wpa_driver_nl80211_deinit(bss);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005748 return NULL;
5749}
5750
5751
5752static void i802_deinit(void *priv)
5753{
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08005754 struct i802_bss *bss = priv;
5755 wpa_driver_nl80211_deinit(bss);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005756}
5757
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005758
5759static enum nl80211_iftype wpa_driver_nl80211_if_type(
5760 enum wpa_driver_if_type type)
5761{
5762 switch (type) {
5763 case WPA_IF_STATION:
5764 return NL80211_IFTYPE_STATION;
5765 case WPA_IF_P2P_CLIENT:
5766 case WPA_IF_P2P_GROUP:
5767 return NL80211_IFTYPE_P2P_CLIENT;
5768 case WPA_IF_AP_VLAN:
5769 return NL80211_IFTYPE_AP_VLAN;
5770 case WPA_IF_AP_BSS:
5771 return NL80211_IFTYPE_AP;
5772 case WPA_IF_P2P_GO:
5773 return NL80211_IFTYPE_P2P_GO;
Dmitry Shmidt34af3062013-07-11 10:46:32 -07005774 case WPA_IF_P2P_DEVICE:
5775 return NL80211_IFTYPE_P2P_DEVICE;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005776 case WPA_IF_MESH:
5777 return NL80211_IFTYPE_MESH_POINT;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005778 }
5779 return -1;
5780}
5781
5782
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005783#if defined(CONFIG_P2P) || defined(CONFIG_MESH)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005784
5785static int nl80211_addr_in_use(struct nl80211_global *global, const u8 *addr)
5786{
5787 struct wpa_driver_nl80211_data *drv;
5788 dl_list_for_each(drv, &global->interfaces,
5789 struct wpa_driver_nl80211_data, list) {
Dmitry Shmidtcce06662013-11-04 18:44:24 -08005790 if (os_memcmp(addr, drv->first_bss->addr, ETH_ALEN) == 0)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005791 return 1;
5792 }
5793 return 0;
5794}
5795
5796
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005797static int nl80211_vif_addr(struct wpa_driver_nl80211_data *drv, u8 *new_addr)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005798{
5799 unsigned int idx;
5800
5801 if (!drv->global)
5802 return -1;
5803
Dmitry Shmidtcce06662013-11-04 18:44:24 -08005804 os_memcpy(new_addr, drv->first_bss->addr, ETH_ALEN);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005805 for (idx = 0; idx < 64; idx++) {
Dmitry Shmidtcce06662013-11-04 18:44:24 -08005806 new_addr[0] = drv->first_bss->addr[0] | 0x02;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005807 new_addr[0] ^= idx << 2;
5808 if (!nl80211_addr_in_use(drv->global, new_addr))
5809 break;
5810 }
5811 if (idx == 64)
5812 return -1;
5813
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005814 wpa_printf(MSG_DEBUG, "nl80211: Assigned new virtual interface address "
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005815 MACSTR, MAC2STR(new_addr));
5816
5817 return 0;
5818}
5819
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005820#endif /* CONFIG_P2P || CONFIG_MESH */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005821
5822
Dmitry Shmidt34af3062013-07-11 10:46:32 -07005823struct wdev_info {
5824 u64 wdev_id;
5825 int wdev_id_set;
5826 u8 macaddr[ETH_ALEN];
5827};
5828
5829static int nl80211_wdev_handler(struct nl_msg *msg, void *arg)
5830{
5831 struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg));
5832 struct nlattr *tb[NL80211_ATTR_MAX + 1];
5833 struct wdev_info *wi = arg;
5834
5835 nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0),
5836 genlmsg_attrlen(gnlh, 0), NULL);
5837 if (tb[NL80211_ATTR_WDEV]) {
5838 wi->wdev_id = nla_get_u64(tb[NL80211_ATTR_WDEV]);
5839 wi->wdev_id_set = 1;
5840 }
5841
5842 if (tb[NL80211_ATTR_MAC])
5843 os_memcpy(wi->macaddr, nla_data(tb[NL80211_ATTR_MAC]),
5844 ETH_ALEN);
5845
5846 return NL_SKIP;
5847}
5848
5849
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005850static int wpa_driver_nl80211_if_add(void *priv, enum wpa_driver_if_type type,
5851 const char *ifname, const u8 *addr,
5852 void *bss_ctx, void **drv_priv,
5853 char *force_ifname, u8 *if_addr,
Dmitry Shmidtcce06662013-11-04 18:44:24 -08005854 const char *bridge, int use_existing)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005855{
Dmitry Shmidt34af3062013-07-11 10:46:32 -07005856 enum nl80211_iftype nlmode;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005857 struct i802_bss *bss = priv;
5858 struct wpa_driver_nl80211_data *drv = bss->drv;
5859 int ifidx;
Dmitry Shmidtcce06662013-11-04 18:44:24 -08005860 int added = 1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005861
5862 if (addr)
5863 os_memcpy(if_addr, addr, ETH_ALEN);
Dmitry Shmidt34af3062013-07-11 10:46:32 -07005864 nlmode = wpa_driver_nl80211_if_type(type);
5865 if (nlmode == NL80211_IFTYPE_P2P_DEVICE) {
5866 struct wdev_info p2pdev_info;
5867
5868 os_memset(&p2pdev_info, 0, sizeof(p2pdev_info));
5869 ifidx = nl80211_create_iface(drv, ifname, nlmode, addr,
5870 0, nl80211_wdev_handler,
Dmitry Shmidtcce06662013-11-04 18:44:24 -08005871 &p2pdev_info, use_existing);
Dmitry Shmidt34af3062013-07-11 10:46:32 -07005872 if (!p2pdev_info.wdev_id_set || ifidx != 0) {
5873 wpa_printf(MSG_ERROR, "nl80211: Failed to create a P2P Device interface %s",
5874 ifname);
5875 return -1;
5876 }
5877
5878 drv->global->if_add_wdevid = p2pdev_info.wdev_id;
5879 drv->global->if_add_wdevid_set = p2pdev_info.wdev_id_set;
5880 if (!is_zero_ether_addr(p2pdev_info.macaddr))
5881 os_memcpy(if_addr, p2pdev_info.macaddr, ETH_ALEN);
5882 wpa_printf(MSG_DEBUG, "nl80211: New P2P Device interface %s (0x%llx) created",
5883 ifname,
5884 (long long unsigned int) p2pdev_info.wdev_id);
5885 } else {
5886 ifidx = nl80211_create_iface(drv, ifname, nlmode, addr,
Dmitry Shmidtcce06662013-11-04 18:44:24 -08005887 0, NULL, NULL, use_existing);
5888 if (use_existing && ifidx == -ENFILE) {
5889 added = 0;
5890 ifidx = if_nametoindex(ifname);
5891 } else if (ifidx < 0) {
Dmitry Shmidt34af3062013-07-11 10:46:32 -07005892 return -1;
5893 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005894 }
5895
Dmitry Shmidt34af3062013-07-11 10:46:32 -07005896 if (!addr) {
5897 if (drv->nlmode == NL80211_IFTYPE_P2P_DEVICE)
5898 os_memcpy(if_addr, bss->addr, ETH_ALEN);
5899 else if (linux_get_ifhwaddr(drv->global->ioctl_sock,
5900 bss->ifname, if_addr) < 0) {
Dmitry Shmidtcce06662013-11-04 18:44:24 -08005901 if (added)
5902 nl80211_remove_iface(drv, ifidx);
Dmitry Shmidt34af3062013-07-11 10:46:32 -07005903 return -1;
5904 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005905 }
5906
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005907#if defined(CONFIG_P2P) || defined(CONFIG_MESH)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005908 if (!addr &&
5909 (type == WPA_IF_P2P_CLIENT || type == WPA_IF_P2P_GROUP ||
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005910 type == WPA_IF_P2P_GO || type == WPA_IF_MESH)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005911 /* Enforce unique P2P Interface Address */
Dmitry Shmidt34af3062013-07-11 10:46:32 -07005912 u8 new_addr[ETH_ALEN];
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005913
Dmitry Shmidt34af3062013-07-11 10:46:32 -07005914 if (linux_get_ifhwaddr(drv->global->ioctl_sock, ifname,
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005915 new_addr) < 0) {
Dmitry Shmidt71757432014-06-02 13:50:35 -07005916 if (added)
5917 nl80211_remove_iface(drv, ifidx);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005918 return -1;
5919 }
Dmitry Shmidt34af3062013-07-11 10:46:32 -07005920 if (nl80211_addr_in_use(drv->global, new_addr)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005921 wpa_printf(MSG_DEBUG, "nl80211: Allocate new address "
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005922 "for %s interface", type == WPA_IF_MESH ?
5923 "mesh" : "P2P group");
5924 if (nl80211_vif_addr(drv, 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 Shmidt1f69aa52012-01-24 16:10:04 -08005929 if (linux_set_ifhwaddr(drv->global->ioctl_sock, ifname,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005930 new_addr) < 0) {
Dmitry Shmidt71757432014-06-02 13:50:35 -07005931 if (added)
5932 nl80211_remove_iface(drv, ifidx);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005933 return -1;
5934 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005935 }
Dmitry Shmidt6e933c12011-09-27 12:29:26 -07005936 os_memcpy(if_addr, new_addr, ETH_ALEN);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005937 }
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005938#endif /* CONFIG_P2P || CONFIG_MESH */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005939
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005940 if (type == WPA_IF_AP_BSS) {
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -07005941 struct i802_bss *new_bss = os_zalloc(sizeof(*new_bss));
5942 if (new_bss == NULL) {
Dmitry Shmidtcce06662013-11-04 18:44:24 -08005943 if (added)
5944 nl80211_remove_iface(drv, ifidx);
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -07005945 return -1;
5946 }
5947
5948 if (bridge &&
5949 i802_check_bridge(drv, new_bss, bridge, ifname) < 0) {
5950 wpa_printf(MSG_ERROR, "nl80211: Failed to add the new "
5951 "interface %s to a bridge %s",
5952 ifname, bridge);
Dmitry Shmidtcce06662013-11-04 18:44:24 -08005953 if (added)
5954 nl80211_remove_iface(drv, ifidx);
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -07005955 os_free(new_bss);
5956 return -1;
5957 }
5958
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005959 if (linux_set_iface_flags(drv->global->ioctl_sock, ifname, 1))
5960 {
Dmitry Shmidt71757432014-06-02 13:50:35 -07005961 if (added)
5962 nl80211_remove_iface(drv, ifidx);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005963 os_free(new_bss);
5964 return -1;
5965 }
5966 os_strlcpy(new_bss->ifname, ifname, IFNAMSIZ);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005967 os_memcpy(new_bss->addr, if_addr, ETH_ALEN);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005968 new_bss->ifindex = ifidx;
5969 new_bss->drv = drv;
Dmitry Shmidtcce06662013-11-04 18:44:24 -08005970 new_bss->next = drv->first_bss->next;
5971 new_bss->freq = drv->first_bss->freq;
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08005972 new_bss->ctx = bss_ctx;
Dmitry Shmidtcce06662013-11-04 18:44:24 -08005973 new_bss->added_if = added;
5974 drv->first_bss->next = new_bss;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005975 if (drv_priv)
5976 *drv_priv = new_bss;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005977 nl80211_init_bss(new_bss);
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08005978
5979 /* Subscribe management frames for this WPA_IF_AP_BSS */
5980 if (nl80211_setup_ap(new_bss))
5981 return -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005982 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005983
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005984 if (drv->global)
5985 drv->global->if_add_ifindex = ifidx;
5986
Dmitry Shmidt43cb5782014-06-16 16:23:22 -07005987 /*
5988 * Some virtual interfaces need to process EAPOL packets and events on
5989 * the parent interface. This is used mainly with hostapd.
5990 */
5991 if (ifidx > 0 &&
5992 (drv->hostapd ||
5993 nlmode == NL80211_IFTYPE_AP_VLAN ||
5994 nlmode == NL80211_IFTYPE_WDS ||
5995 nlmode == NL80211_IFTYPE_MONITOR))
Dmitry Shmidtdf5a7e42014-04-02 12:59:59 -07005996 add_ifidx(drv, ifidx);
5997
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005998 return 0;
5999}
6000
6001
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08006002static int wpa_driver_nl80211_if_remove(struct i802_bss *bss,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006003 enum wpa_driver_if_type type,
6004 const char *ifname)
6005{
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006006 struct wpa_driver_nl80211_data *drv = bss->drv;
6007 int ifindex = if_nametoindex(ifname);
6008
Dmitry Shmidtcce06662013-11-04 18:44:24 -08006009 wpa_printf(MSG_DEBUG, "nl80211: %s(type=%d ifname=%s) ifindex=%d added_if=%d",
6010 __func__, type, ifname, ifindex, bss->added_if);
Dmitry Shmidt01904cf2013-12-05 11:08:35 -08006011 if (ifindex > 0 && (bss->added_if || bss->ifindex != ifindex))
Dmitry Shmidt051af732013-10-22 13:52:46 -07006012 nl80211_remove_iface(drv, ifindex);
Dmitry Shmidt76cd2cc2014-05-27 12:56:04 -07006013 else if (ifindex > 0 && !bss->added_if) {
6014 struct wpa_driver_nl80211_data *drv2;
6015 dl_list_for_each(drv2, &drv->global->interfaces,
6016 struct wpa_driver_nl80211_data, list)
6017 del_ifidx(drv2, ifindex);
6018 }
Dmitry Shmidtaa532512012-09-24 10:35:31 -07006019
Dmitry Shmidtaa532512012-09-24 10:35:31 -07006020 if (type != WPA_IF_AP_BSS)
6021 return 0;
6022
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006023 if (bss->added_if_into_bridge) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006024 if (linux_br_del_if(drv->global->ioctl_sock, bss->brname,
6025 bss->ifname) < 0)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006026 wpa_printf(MSG_INFO, "nl80211: Failed to remove "
6027 "interface %s from bridge %s: %s",
6028 bss->ifname, bss->brname, strerror(errno));
6029 }
6030 if (bss->added_bridge) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006031 if (linux_br_del(drv->global->ioctl_sock, bss->brname) < 0)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006032 wpa_printf(MSG_INFO, "nl80211: Failed to remove "
6033 "bridge %s: %s",
6034 bss->brname, strerror(errno));
6035 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006036
Dmitry Shmidtcce06662013-11-04 18:44:24 -08006037 if (bss != drv->first_bss) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006038 struct i802_bss *tbss;
6039
Dmitry Shmidtcce06662013-11-04 18:44:24 -08006040 wpa_printf(MSG_DEBUG, "nl80211: Not the first BSS - remove it");
6041 for (tbss = drv->first_bss; tbss; tbss = tbss->next) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006042 if (tbss->next == bss) {
6043 tbss->next = bss->next;
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08006044 /* Unsubscribe management frames */
6045 nl80211_teardown_ap(bss);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006046 nl80211_destroy_bss(bss);
Dmitry Shmidtdf5a7e42014-04-02 12:59:59 -07006047 if (!bss->added_if)
6048 i802_set_iface_flags(bss, 0);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006049 os_free(bss);
6050 bss = NULL;
6051 break;
6052 }
6053 }
6054 if (bss)
6055 wpa_printf(MSG_INFO, "nl80211: %s - could not find "
6056 "BSS %p in the list", __func__, bss);
Dmitry Shmidtcce06662013-11-04 18:44:24 -08006057 } else {
6058 wpa_printf(MSG_DEBUG, "nl80211: First BSS - reassign context");
6059 nl80211_teardown_ap(bss);
6060 if (!bss->added_if && !drv->first_bss->next)
6061 wpa_driver_nl80211_del_beacon(drv);
6062 nl80211_destroy_bss(bss);
6063 if (!bss->added_if)
6064 i802_set_iface_flags(bss, 0);
6065 if (drv->first_bss->next) {
6066 drv->first_bss = drv->first_bss->next;
6067 drv->ctx = drv->first_bss->ctx;
6068 os_free(bss);
6069 } else {
6070 wpa_printf(MSG_DEBUG, "nl80211: No second BSS to reassign context to");
6071 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006072 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006073
6074 return 0;
6075}
6076
6077
6078static int cookie_handler(struct nl_msg *msg, void *arg)
6079{
6080 struct nlattr *tb[NL80211_ATTR_MAX + 1];
6081 struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg));
6082 u64 *cookie = arg;
6083 nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0),
6084 genlmsg_attrlen(gnlh, 0), NULL);
6085 if (tb[NL80211_ATTR_COOKIE])
6086 *cookie = nla_get_u64(tb[NL80211_ATTR_COOKIE]);
6087 return NL_SKIP;
6088}
6089
6090
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006091static int nl80211_send_frame_cmd(struct i802_bss *bss,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006092 unsigned int freq, unsigned int wait,
6093 const u8 *buf, size_t buf_len,
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006094 u64 *cookie_out, int no_cck, int no_ack,
6095 int offchanok)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006096{
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006097 struct wpa_driver_nl80211_data *drv = bss->drv;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006098 struct nl_msg *msg;
6099 u64 cookie;
6100 int ret = -1;
6101
Dmitry Shmidt8da800a2013-04-24 12:57:01 -07006102 wpa_printf(MSG_MSGDUMP, "nl80211: CMD_FRAME freq=%u wait=%u no_cck=%d "
Dmitry Shmidt04949592012-07-19 12:16:46 -07006103 "no_ack=%d offchanok=%d",
6104 freq, wait, no_cck, no_ack, offchanok);
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07006105 wpa_hexdump(MSG_MSGDUMP, "CMD_FRAME", buf, buf_len);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006106
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08006107 if (!(msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_FRAME)) ||
6108 (freq && nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq)) ||
6109 (wait && nla_put_u32(msg, NL80211_ATTR_DURATION, wait)) ||
6110 (offchanok && ((drv->capa.flags & WPA_DRIVER_FLAGS_OFFCHANNEL_TX) ||
6111 drv->test_use_roc_tx) &&
6112 nla_put_flag(msg, NL80211_ATTR_OFFCHANNEL_TX_OK)) ||
6113 (no_cck && nla_put_flag(msg, NL80211_ATTR_TX_NO_CCK_RATE)) ||
6114 (no_ack && nla_put_flag(msg, NL80211_ATTR_DONT_WAIT_FOR_ACK)) ||
6115 nla_put(msg, NL80211_ATTR_FRAME, buf_len, buf))
6116 goto fail;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006117
6118 cookie = 0;
6119 ret = send_and_recv_msgs(drv, msg, cookie_handler, &cookie);
6120 msg = NULL;
6121 if (ret) {
6122 wpa_printf(MSG_DEBUG, "nl80211: Frame command failed: ret=%d "
Dmitry Shmidt6e933c12011-09-27 12:29:26 -07006123 "(%s) (freq=%u wait=%u)", ret, strerror(-ret),
6124 freq, wait);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08006125 } else {
6126 wpa_printf(MSG_MSGDUMP, "nl80211: Frame TX command accepted%s; "
6127 "cookie 0x%llx", no_ack ? " (no ACK)" : "",
6128 (long long unsigned int) cookie);
6129
6130 if (cookie_out)
6131 *cookie_out = no_ack ? (u64) -1 : cookie;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006132 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006133
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08006134fail:
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006135 nlmsg_free(msg);
6136 return ret;
6137}
6138
6139
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08006140static int wpa_driver_nl80211_send_action(struct i802_bss *bss,
6141 unsigned int freq,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006142 unsigned int wait_time,
6143 const u8 *dst, const u8 *src,
6144 const u8 *bssid,
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006145 const u8 *data, size_t data_len,
6146 int no_cck)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006147{
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006148 struct wpa_driver_nl80211_data *drv = bss->drv;
6149 int ret = -1;
6150 u8 *buf;
6151 struct ieee80211_hdr *hdr;
6152
6153 wpa_printf(MSG_DEBUG, "nl80211: Send Action frame (ifindex=%d, "
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08006154 "freq=%u MHz wait=%d ms no_cck=%d)",
6155 drv->ifindex, freq, wait_time, no_cck);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006156
6157 buf = os_zalloc(24 + data_len);
6158 if (buf == NULL)
6159 return ret;
6160 os_memcpy(buf + 24, data, data_len);
6161 hdr = (struct ieee80211_hdr *) buf;
6162 hdr->frame_control =
6163 IEEE80211_FC(WLAN_FC_TYPE_MGMT, WLAN_FC_STYPE_ACTION);
6164 os_memcpy(hdr->addr1, dst, ETH_ALEN);
6165 os_memcpy(hdr->addr2, src, ETH_ALEN);
6166 os_memcpy(hdr->addr3, bssid, ETH_ALEN);
6167
Dmitry Shmidt56052862013-10-04 10:23:25 -07006168 if (is_ap_interface(drv->nlmode) &&
6169 (!(drv->capa.flags & WPA_DRIVER_FLAGS_OFFCHANNEL_TX) ||
6170 (int) freq == bss->freq || drv->device_ap_sme ||
6171 !drv->use_monitor))
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08006172 ret = wpa_driver_nl80211_send_mlme(bss, buf, 24 + data_len,
6173 0, freq, no_cck, 1,
6174 wait_time);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006175 else
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006176 ret = nl80211_send_frame_cmd(bss, freq, wait_time, buf,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006177 24 + data_len,
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006178 &drv->send_action_cookie,
6179 no_cck, 0, 1);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006180
6181 os_free(buf);
6182 return ret;
6183}
6184
6185
6186static void wpa_driver_nl80211_send_action_cancel_wait(void *priv)
6187{
6188 struct i802_bss *bss = priv;
6189 struct wpa_driver_nl80211_data *drv = bss->drv;
6190 struct nl_msg *msg;
6191 int ret;
6192
Dmitry Shmidt2f3b8de2013-03-01 09:32:50 -08006193 wpa_printf(MSG_DEBUG, "nl80211: Cancel TX frame wait: cookie=0x%llx",
6194 (long long unsigned int) drv->send_action_cookie);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08006195 if (!(msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_FRAME_WAIT_CANCEL)) ||
6196 nla_put_u64(msg, NL80211_ATTR_COOKIE, drv->send_action_cookie)) {
6197 nlmsg_free(msg);
6198 return;
6199 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006200
6201 ret = send_and_recv_msgs(drv, msg, NULL, NULL);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006202 if (ret)
6203 wpa_printf(MSG_DEBUG, "nl80211: wait cancel failed: ret=%d "
6204 "(%s)", ret, strerror(-ret));
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006205}
6206
6207
6208static int wpa_driver_nl80211_remain_on_channel(void *priv, unsigned int freq,
6209 unsigned int duration)
6210{
6211 struct i802_bss *bss = priv;
6212 struct wpa_driver_nl80211_data *drv = bss->drv;
6213 struct nl_msg *msg;
6214 int ret;
6215 u64 cookie;
6216
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08006217 if (!(msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_REMAIN_ON_CHANNEL)) ||
6218 nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq) ||
6219 nla_put_u32(msg, NL80211_ATTR_DURATION, duration)) {
6220 nlmsg_free(msg);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006221 return -1;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08006222 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006223
6224 cookie = 0;
6225 ret = send_and_recv_msgs(drv, msg, cookie_handler, &cookie);
6226 if (ret == 0) {
6227 wpa_printf(MSG_DEBUG, "nl80211: Remain-on-channel cookie "
6228 "0x%llx for freq=%u MHz duration=%u",
6229 (long long unsigned int) cookie, freq, duration);
6230 drv->remain_on_chan_cookie = cookie;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006231 drv->pending_remain_on_chan = 1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006232 return 0;
6233 }
6234 wpa_printf(MSG_DEBUG, "nl80211: Failed to request remain-on-channel "
6235 "(freq=%d duration=%u): %d (%s)",
6236 freq, duration, ret, strerror(-ret));
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006237 return -1;
6238}
6239
6240
6241static int wpa_driver_nl80211_cancel_remain_on_channel(void *priv)
6242{
6243 struct i802_bss *bss = priv;
6244 struct wpa_driver_nl80211_data *drv = bss->drv;
6245 struct nl_msg *msg;
6246 int ret;
6247
6248 if (!drv->pending_remain_on_chan) {
6249 wpa_printf(MSG_DEBUG, "nl80211: No pending remain-on-channel "
6250 "to cancel");
6251 return -1;
6252 }
6253
6254 wpa_printf(MSG_DEBUG, "nl80211: Cancel remain-on-channel with cookie "
6255 "0x%llx",
6256 (long long unsigned int) drv->remain_on_chan_cookie);
6257
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08006258 msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL);
6259 if (!msg ||
6260 nla_put_u64(msg, NL80211_ATTR_COOKIE, drv->remain_on_chan_cookie)) {
6261 nlmsg_free(msg);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006262 return -1;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08006263 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006264
6265 ret = send_and_recv_msgs(drv, msg, NULL, NULL);
6266 if (ret == 0)
6267 return 0;
6268 wpa_printf(MSG_DEBUG, "nl80211: Failed to cancel remain-on-channel: "
6269 "%d (%s)", ret, strerror(-ret));
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006270 return -1;
6271}
6272
6273
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08006274static int wpa_driver_nl80211_probe_req_report(struct i802_bss *bss, int report)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006275{
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006276 struct wpa_driver_nl80211_data *drv = bss->drv;
Dmitry Shmidt6e933c12011-09-27 12:29:26 -07006277
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006278 if (!report) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006279 if (bss->nl_preq && drv->device_ap_sme &&
Dmitry Shmidt03658832014-08-13 11:03:49 -07006280 is_ap_interface(drv->nlmode) && !bss->in_deinit &&
6281 !bss->static_ap) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006282 /*
6283 * Do not disable Probe Request reporting that was
6284 * enabled in nl80211_setup_ap().
6285 */
6286 wpa_printf(MSG_DEBUG, "nl80211: Skip disabling of "
6287 "Probe Request reporting nl_preq=%p while "
6288 "in AP mode", bss->nl_preq);
6289 } else if (bss->nl_preq) {
6290 wpa_printf(MSG_DEBUG, "nl80211: Disable Probe Request "
6291 "reporting nl_preq=%p", bss->nl_preq);
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -07006292 nl80211_destroy_eloop_handle(&bss->nl_preq);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006293 }
6294 return 0;
6295 }
6296
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006297 if (bss->nl_preq) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006298 wpa_printf(MSG_DEBUG, "nl80211: Probe Request reporting "
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006299 "already on! nl_preq=%p", bss->nl_preq);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006300 return 0;
6301 }
6302
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006303 bss->nl_preq = nl_create_handle(drv->global->nl_cb, "preq");
6304 if (bss->nl_preq == NULL)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006305 return -1;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006306 wpa_printf(MSG_DEBUG, "nl80211: Enable Probe Request "
6307 "reporting nl_preq=%p", bss->nl_preq);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006308
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006309 if (nl80211_register_frame(bss, bss->nl_preq,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006310 (WLAN_FC_TYPE_MGMT << 2) |
6311 (WLAN_FC_STYPE_PROBE_REQ << 4),
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006312 NULL, 0) < 0)
6313 goto out_err;
Dmitry Shmidt497c1d52011-07-21 15:19:46 -07006314
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -07006315 nl80211_register_eloop_read(&bss->nl_preq,
6316 wpa_driver_nl80211_event_receive,
6317 bss->nl_cb);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006318
6319 return 0;
6320
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006321 out_err:
6322 nl_destroy_handles(&bss->nl_preq);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006323 return -1;
6324}
6325
6326
6327static int nl80211_disable_11b_rates(struct wpa_driver_nl80211_data *drv,
6328 int ifindex, int disabled)
6329{
6330 struct nl_msg *msg;
6331 struct nlattr *bands, *band;
6332 int ret;
6333
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08006334 wpa_printf(MSG_DEBUG,
6335 "nl80211: NL80211_CMD_SET_TX_BITRATE_MASK (ifindex=%d %s)",
6336 ifindex, disabled ? "NL80211_TXRATE_LEGACY=OFDM-only" :
6337 "no NL80211_TXRATE_LEGACY constraint");
6338
6339 msg = nl80211_ifindex_msg(drv, ifindex, 0,
6340 NL80211_CMD_SET_TX_BITRATE_MASK);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006341 if (!msg)
6342 return -1;
6343
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006344 bands = nla_nest_start(msg, NL80211_ATTR_TX_RATES);
6345 if (!bands)
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08006346 goto fail;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006347
6348 /*
6349 * Disable 2 GHz rates 1, 2, 5.5, 11 Mbps by masking out everything
6350 * else apart from 6, 9, 12, 18, 24, 36, 48, 54 Mbps from non-MCS
6351 * rates. All 5 GHz rates are left enabled.
6352 */
6353 band = nla_nest_start(msg, NL80211_BAND_2GHZ);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08006354 if (!band ||
6355 (disabled && nla_put(msg, NL80211_TXRATE_LEGACY, 8,
6356 "\x0c\x12\x18\x24\x30\x48\x60\x6c")))
6357 goto fail;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006358 nla_nest_end(msg, band);
6359
6360 nla_nest_end(msg, bands);
6361
6362 ret = send_and_recv_msgs(drv, msg, NULL, NULL);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006363 if (ret) {
6364 wpa_printf(MSG_DEBUG, "nl80211: Set TX rates failed: ret=%d "
6365 "(%s)", ret, strerror(-ret));
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07006366 } else
6367 drv->disabled_11b_rates = disabled;
6368
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006369 return ret;
6370
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08006371fail:
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006372 nlmsg_free(msg);
6373 return -1;
6374}
6375
6376
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006377static int wpa_driver_nl80211_deinit_ap(void *priv)
6378{
6379 struct i802_bss *bss = priv;
6380 struct wpa_driver_nl80211_data *drv = bss->drv;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006381 if (!is_ap_interface(drv->nlmode))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006382 return -1;
6383 wpa_driver_nl80211_del_beacon(drv);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08006384 bss->beacon_set = 0;
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -07006385
6386 /*
6387 * If the P2P GO interface was dynamically added, then it is
6388 * possible that the interface change to station is not possible.
6389 */
6390 if (drv->nlmode == NL80211_IFTYPE_P2P_GO && bss->if_dynamic)
6391 return 0;
6392
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006393 return wpa_driver_nl80211_set_mode(priv, NL80211_IFTYPE_STATION);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006394}
6395
6396
Dmitry Shmidtea69e842013-05-13 14:52:28 -07006397static int wpa_driver_nl80211_stop_ap(void *priv)
6398{
6399 struct i802_bss *bss = priv;
6400 struct wpa_driver_nl80211_data *drv = bss->drv;
6401 if (!is_ap_interface(drv->nlmode))
6402 return -1;
6403 wpa_driver_nl80211_del_beacon(drv);
6404 bss->beacon_set = 0;
6405 return 0;
6406}
6407
6408
Dmitry Shmidt04949592012-07-19 12:16:46 -07006409static int wpa_driver_nl80211_deinit_p2p_cli(void *priv)
6410{
6411 struct i802_bss *bss = priv;
6412 struct wpa_driver_nl80211_data *drv = bss->drv;
6413 if (drv->nlmode != NL80211_IFTYPE_P2P_CLIENT)
6414 return -1;
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -07006415
6416 /*
6417 * If the P2P Client interface was dynamically added, then it is
6418 * possible that the interface change to station is not possible.
6419 */
6420 if (bss->if_dynamic)
6421 return 0;
6422
Dmitry Shmidt04949592012-07-19 12:16:46 -07006423 return wpa_driver_nl80211_set_mode(priv, NL80211_IFTYPE_STATION);
6424}
6425
6426
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006427static void wpa_driver_nl80211_resume(void *priv)
6428{
6429 struct i802_bss *bss = priv;
Dmitry Shmidt34af3062013-07-11 10:46:32 -07006430
6431 if (i802_set_iface_flags(bss, 1))
6432 wpa_printf(MSG_DEBUG, "nl80211: Failed to set interface up on resume event");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006433}
6434
6435
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006436static int nl80211_signal_monitor(void *priv, int threshold, int hysteresis)
6437{
6438 struct i802_bss *bss = priv;
6439 struct wpa_driver_nl80211_data *drv = bss->drv;
Dmitry Shmidt8da800a2013-04-24 12:57:01 -07006440 struct nl_msg *msg;
6441 struct nlattr *cqm;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006442
6443 wpa_printf(MSG_DEBUG, "nl80211: Signal monitor threshold=%d "
6444 "hysteresis=%d", threshold, hysteresis);
6445
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08006446 if (!(msg = nl80211_bss_msg(bss, 0, NL80211_CMD_SET_CQM)) ||
6447 !(cqm = nla_nest_start(msg, NL80211_ATTR_CQM)) ||
6448 nla_put_u32(msg, NL80211_ATTR_CQM_RSSI_THOLD, threshold) ||
6449 nla_put_u32(msg, NL80211_ATTR_CQM_RSSI_HYST, hysteresis)) {
6450 nlmsg_free(msg);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006451 return -1;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08006452 }
Dmitry Shmidt8da800a2013-04-24 12:57:01 -07006453 nla_nest_end(msg, cqm);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006454
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08006455 return send_and_recv_msgs(drv, msg, NULL, NULL);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006456}
6457
6458
Dmitry Shmidt34af3062013-07-11 10:46:32 -07006459static int get_channel_width(struct nl_msg *msg, void *arg)
6460{
6461 struct nlattr *tb[NL80211_ATTR_MAX + 1];
6462 struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg));
6463 struct wpa_signal_info *sig_change = arg;
6464
6465 nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0),
6466 genlmsg_attrlen(gnlh, 0), NULL);
6467
6468 sig_change->center_frq1 = -1;
6469 sig_change->center_frq2 = -1;
6470 sig_change->chanwidth = CHAN_WIDTH_UNKNOWN;
6471
6472 if (tb[NL80211_ATTR_CHANNEL_WIDTH]) {
6473 sig_change->chanwidth = convert2width(
6474 nla_get_u32(tb[NL80211_ATTR_CHANNEL_WIDTH]));
6475 if (tb[NL80211_ATTR_CENTER_FREQ1])
6476 sig_change->center_frq1 =
6477 nla_get_u32(tb[NL80211_ATTR_CENTER_FREQ1]);
6478 if (tb[NL80211_ATTR_CENTER_FREQ2])
6479 sig_change->center_frq2 =
6480 nla_get_u32(tb[NL80211_ATTR_CENTER_FREQ2]);
6481 }
6482
6483 return NL_SKIP;
6484}
6485
6486
6487static int nl80211_get_channel_width(struct wpa_driver_nl80211_data *drv,
6488 struct wpa_signal_info *sig)
6489{
6490 struct nl_msg *msg;
6491
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08006492 msg = nl80211_drv_msg(drv, 0, NL80211_CMD_GET_INTERFACE);
Dmitry Shmidt34af3062013-07-11 10:46:32 -07006493 return send_and_recv_msgs(drv, msg, get_channel_width, sig);
Dmitry Shmidt34af3062013-07-11 10:46:32 -07006494}
6495
6496
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006497static int nl80211_signal_poll(void *priv, struct wpa_signal_info *si)
6498{
6499 struct i802_bss *bss = priv;
6500 struct wpa_driver_nl80211_data *drv = bss->drv;
6501 int res;
6502
6503 os_memset(si, 0, sizeof(*si));
6504 res = nl80211_get_link_signal(drv, si);
6505 if (res != 0)
6506 return res;
6507
Dmitry Shmidt34af3062013-07-11 10:46:32 -07006508 res = nl80211_get_channel_width(drv, si);
6509 if (res != 0)
6510 return res;
6511
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006512 return nl80211_get_link_noise(drv, si);
6513}
6514
6515
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006516static int wpa_driver_nl80211_shared_freq(void *priv)
6517{
6518 struct i802_bss *bss = priv;
6519 struct wpa_driver_nl80211_data *drv = bss->drv;
6520 struct wpa_driver_nl80211_data *driver;
6521 int freq = 0;
6522
6523 /*
6524 * If the same PHY is in connected state with some other interface,
6525 * then retrieve the assoc freq.
6526 */
6527 wpa_printf(MSG_DEBUG, "nl80211: Get shared freq for PHY %s",
6528 drv->phyname);
6529
6530 dl_list_for_each(driver, &drv->global->interfaces,
6531 struct wpa_driver_nl80211_data, list) {
6532 if (drv == driver ||
6533 os_strcmp(drv->phyname, driver->phyname) != 0 ||
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006534 !driver->associated)
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006535 continue;
6536
6537 wpa_printf(MSG_DEBUG, "nl80211: Found a match for PHY %s - %s "
6538 MACSTR,
Dmitry Shmidtcce06662013-11-04 18:44:24 -08006539 driver->phyname, driver->first_bss->ifname,
6540 MAC2STR(driver->first_bss->addr));
Dmitry Shmidt04949592012-07-19 12:16:46 -07006541 if (is_ap_interface(driver->nlmode))
Dmitry Shmidtcce06662013-11-04 18:44:24 -08006542 freq = driver->first_bss->freq;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006543 else
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006544 freq = nl80211_get_assoc_freq(driver);
6545 wpa_printf(MSG_DEBUG, "nl80211: Shared freq for PHY %s: %d",
6546 drv->phyname, freq);
6547 }
6548
6549 if (!freq)
6550 wpa_printf(MSG_DEBUG, "nl80211: No shared interface for "
6551 "PHY (%s) in associated state", drv->phyname);
6552
6553 return freq;
6554}
6555
6556
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006557static int nl80211_send_frame(void *priv, const u8 *data, size_t data_len,
6558 int encrypt)
6559{
6560 struct i802_bss *bss = priv;
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08006561 return wpa_driver_nl80211_send_frame(bss, data, data_len, encrypt, 0,
6562 0, 0, 0, 0);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006563}
6564
6565
6566static int nl80211_set_param(void *priv, const char *param)
6567{
6568 wpa_printf(MSG_DEBUG, "nl80211: driver param='%s'", param);
6569 if (param == NULL)
6570 return 0;
6571
6572#ifdef CONFIG_P2P
6573 if (os_strstr(param, "use_p2p_group_interface=1")) {
6574 struct i802_bss *bss = priv;
6575 struct wpa_driver_nl80211_data *drv = bss->drv;
6576
6577 wpa_printf(MSG_DEBUG, "nl80211: Use separate P2P group "
6578 "interface");
6579 drv->capa.flags |= WPA_DRIVER_FLAGS_P2P_CONCURRENT;
6580 drv->capa.flags |= WPA_DRIVER_FLAGS_P2P_MGMT_AND_NON_P2P;
6581 }
6582#endif /* CONFIG_P2P */
6583
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08006584 if (os_strstr(param, "use_monitor=1")) {
6585 struct i802_bss *bss = priv;
6586 struct wpa_driver_nl80211_data *drv = bss->drv;
6587 drv->use_monitor = 1;
6588 }
6589
6590 if (os_strstr(param, "force_connect_cmd=1")) {
6591 struct i802_bss *bss = priv;
6592 struct wpa_driver_nl80211_data *drv = bss->drv;
6593 drv->capa.flags &= ~WPA_DRIVER_FLAGS_SME;
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07006594 drv->force_connect_cmd = 1;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08006595 }
6596
Dmitry Shmidt7d5c8f22014-03-03 13:53:28 -08006597 if (os_strstr(param, "no_offchannel_tx=1")) {
6598 struct i802_bss *bss = priv;
6599 struct wpa_driver_nl80211_data *drv = bss->drv;
6600 drv->capa.flags &= ~WPA_DRIVER_FLAGS_OFFCHANNEL_TX;
6601 drv->test_use_roc_tx = 1;
6602 }
6603
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006604 return 0;
6605}
6606
6607
6608static void * nl80211_global_init(void)
6609{
6610 struct nl80211_global *global;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006611 struct netlink_config *cfg;
6612
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006613 global = os_zalloc(sizeof(*global));
6614 if (global == NULL)
6615 return NULL;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006616 global->ioctl_sock = -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006617 dl_list_init(&global->interfaces);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006618 global->if_add_ifindex = -1;
6619
6620 cfg = os_zalloc(sizeof(*cfg));
6621 if (cfg == NULL)
6622 goto err;
6623
6624 cfg->ctx = global;
6625 cfg->newlink_cb = wpa_driver_nl80211_event_rtm_newlink;
6626 cfg->dellink_cb = wpa_driver_nl80211_event_rtm_dellink;
6627 global->netlink = netlink_init(cfg);
6628 if (global->netlink == NULL) {
6629 os_free(cfg);
6630 goto err;
6631 }
6632
6633 if (wpa_driver_nl80211_init_nl_global(global) < 0)
6634 goto err;
6635
6636 global->ioctl_sock = socket(PF_INET, SOCK_DGRAM, 0);
6637 if (global->ioctl_sock < 0) {
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -07006638 wpa_printf(MSG_ERROR, "nl80211: socket(PF_INET,SOCK_DGRAM) failed: %s",
6639 strerror(errno));
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006640 goto err;
6641 }
6642
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006643 return global;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006644
6645err:
6646 nl80211_global_deinit(global);
6647 return NULL;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006648}
6649
6650
6651static void nl80211_global_deinit(void *priv)
6652{
6653 struct nl80211_global *global = priv;
6654 if (global == NULL)
6655 return;
6656 if (!dl_list_empty(&global->interfaces)) {
6657 wpa_printf(MSG_ERROR, "nl80211: %u interface(s) remain at "
6658 "nl80211_global_deinit",
6659 dl_list_len(&global->interfaces));
6660 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006661
6662 if (global->netlink)
6663 netlink_deinit(global->netlink);
6664
6665 nl_destroy_handles(&global->nl);
6666
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -07006667 if (global->nl_event)
6668 nl80211_destroy_eloop_handle(&global->nl_event);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006669
6670 nl_cb_put(global->nl_cb);
6671
6672 if (global->ioctl_sock >= 0)
6673 close(global->ioctl_sock);
6674
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006675 os_free(global);
6676}
6677
6678
6679static const char * nl80211_get_radio_name(void *priv)
6680{
6681 struct i802_bss *bss = priv;
6682 struct wpa_driver_nl80211_data *drv = bss->drv;
6683 return drv->phyname;
6684}
6685
6686
Jouni Malinen75ecf522011-06-27 15:19:46 -07006687static int nl80211_pmkid(struct i802_bss *bss, int cmd, const u8 *bssid,
6688 const u8 *pmkid)
6689{
6690 struct nl_msg *msg;
6691
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08006692 if (!(msg = nl80211_bss_msg(bss, 0, cmd)) ||
6693 (pmkid && nla_put(msg, NL80211_ATTR_PMKID, 16, pmkid)) ||
6694 (bssid && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid))) {
6695 nlmsg_free(msg);
6696 return -ENOBUFS;
6697 }
Jouni Malinen75ecf522011-06-27 15:19:46 -07006698
6699 return send_and_recv_msgs(bss->drv, msg, NULL, NULL);
Jouni Malinen75ecf522011-06-27 15:19:46 -07006700}
6701
6702
6703static int nl80211_add_pmkid(void *priv, const u8 *bssid, const u8 *pmkid)
6704{
6705 struct i802_bss *bss = priv;
6706 wpa_printf(MSG_DEBUG, "nl80211: Add PMKID for " MACSTR, MAC2STR(bssid));
6707 return nl80211_pmkid(bss, NL80211_CMD_SET_PMKSA, bssid, pmkid);
6708}
6709
6710
6711static int nl80211_remove_pmkid(void *priv, const u8 *bssid, const u8 *pmkid)
6712{
6713 struct i802_bss *bss = priv;
6714 wpa_printf(MSG_DEBUG, "nl80211: Delete PMKID for " MACSTR,
6715 MAC2STR(bssid));
6716 return nl80211_pmkid(bss, NL80211_CMD_DEL_PMKSA, bssid, pmkid);
6717}
6718
6719
6720static int nl80211_flush_pmkid(void *priv)
6721{
6722 struct i802_bss *bss = priv;
6723 wpa_printf(MSG_DEBUG, "nl80211: Flush PMKIDs");
6724 return nl80211_pmkid(bss, NL80211_CMD_FLUSH_PMKSA, NULL, NULL);
6725}
6726
6727
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -07006728static void clean_survey_results(struct survey_results *survey_results)
6729{
6730 struct freq_survey *survey, *tmp;
6731
6732 if (dl_list_empty(&survey_results->survey_list))
6733 return;
6734
6735 dl_list_for_each_safe(survey, tmp, &survey_results->survey_list,
6736 struct freq_survey, list) {
6737 dl_list_del(&survey->list);
6738 os_free(survey);
6739 }
6740}
6741
6742
6743static void add_survey(struct nlattr **sinfo, u32 ifidx,
6744 struct dl_list *survey_list)
6745{
6746 struct freq_survey *survey;
6747
6748 survey = os_zalloc(sizeof(struct freq_survey));
6749 if (!survey)
6750 return;
6751
6752 survey->ifidx = ifidx;
6753 survey->freq = nla_get_u32(sinfo[NL80211_SURVEY_INFO_FREQUENCY]);
6754 survey->filled = 0;
6755
6756 if (sinfo[NL80211_SURVEY_INFO_NOISE]) {
6757 survey->nf = (int8_t)
6758 nla_get_u8(sinfo[NL80211_SURVEY_INFO_NOISE]);
6759 survey->filled |= SURVEY_HAS_NF;
6760 }
6761
6762 if (sinfo[NL80211_SURVEY_INFO_CHANNEL_TIME]) {
6763 survey->channel_time =
6764 nla_get_u64(sinfo[NL80211_SURVEY_INFO_CHANNEL_TIME]);
6765 survey->filled |= SURVEY_HAS_CHAN_TIME;
6766 }
6767
6768 if (sinfo[NL80211_SURVEY_INFO_CHANNEL_TIME_BUSY]) {
6769 survey->channel_time_busy =
6770 nla_get_u64(sinfo[NL80211_SURVEY_INFO_CHANNEL_TIME_BUSY]);
6771 survey->filled |= SURVEY_HAS_CHAN_TIME_BUSY;
6772 }
6773
6774 if (sinfo[NL80211_SURVEY_INFO_CHANNEL_TIME_RX]) {
6775 survey->channel_time_rx =
6776 nla_get_u64(sinfo[NL80211_SURVEY_INFO_CHANNEL_TIME_RX]);
6777 survey->filled |= SURVEY_HAS_CHAN_TIME_RX;
6778 }
6779
6780 if (sinfo[NL80211_SURVEY_INFO_CHANNEL_TIME_TX]) {
6781 survey->channel_time_tx =
6782 nla_get_u64(sinfo[NL80211_SURVEY_INFO_CHANNEL_TIME_TX]);
6783 survey->filled |= SURVEY_HAS_CHAN_TIME_TX;
6784 }
6785
6786 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)",
6787 survey->freq,
6788 survey->nf,
6789 (unsigned long int) survey->channel_time,
6790 (unsigned long int) survey->channel_time_busy,
6791 (unsigned long int) survey->channel_time_tx,
6792 (unsigned long int) survey->channel_time_rx,
6793 survey->filled);
6794
6795 dl_list_add_tail(survey_list, &survey->list);
6796}
6797
6798
6799static int check_survey_ok(struct nlattr **sinfo, u32 surveyed_freq,
6800 unsigned int freq_filter)
6801{
6802 if (!freq_filter)
6803 return 1;
6804
6805 return freq_filter == surveyed_freq;
6806}
6807
6808
6809static int survey_handler(struct nl_msg *msg, void *arg)
6810{
6811 struct nlattr *tb[NL80211_ATTR_MAX + 1];
6812 struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg));
6813 struct nlattr *sinfo[NL80211_SURVEY_INFO_MAX + 1];
6814 struct survey_results *survey_results;
6815 u32 surveyed_freq = 0;
6816 u32 ifidx;
6817
6818 static struct nla_policy survey_policy[NL80211_SURVEY_INFO_MAX + 1] = {
6819 [NL80211_SURVEY_INFO_FREQUENCY] = { .type = NLA_U32 },
6820 [NL80211_SURVEY_INFO_NOISE] = { .type = NLA_U8 },
6821 };
6822
6823 survey_results = (struct survey_results *) arg;
6824
6825 nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0),
6826 genlmsg_attrlen(gnlh, 0), NULL);
6827
Dmitry Shmidt97672262014-02-03 13:02:54 -08006828 if (!tb[NL80211_ATTR_IFINDEX])
6829 return NL_SKIP;
6830
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -07006831 ifidx = nla_get_u32(tb[NL80211_ATTR_IFINDEX]);
6832
6833 if (!tb[NL80211_ATTR_SURVEY_INFO])
6834 return NL_SKIP;
6835
6836 if (nla_parse_nested(sinfo, NL80211_SURVEY_INFO_MAX,
6837 tb[NL80211_ATTR_SURVEY_INFO],
6838 survey_policy))
6839 return NL_SKIP;
6840
6841 if (!sinfo[NL80211_SURVEY_INFO_FREQUENCY]) {
6842 wpa_printf(MSG_ERROR, "nl80211: Invalid survey data");
6843 return NL_SKIP;
6844 }
6845
6846 surveyed_freq = nla_get_u32(sinfo[NL80211_SURVEY_INFO_FREQUENCY]);
6847
6848 if (!check_survey_ok(sinfo, surveyed_freq,
6849 survey_results->freq_filter))
6850 return NL_SKIP;
6851
6852 if (survey_results->freq_filter &&
6853 survey_results->freq_filter != surveyed_freq) {
6854 wpa_printf(MSG_EXCESSIVE, "nl80211: Ignoring survey data for freq %d MHz",
6855 surveyed_freq);
6856 return NL_SKIP;
6857 }
6858
6859 add_survey(sinfo, ifidx, &survey_results->survey_list);
6860
6861 return NL_SKIP;
6862}
6863
6864
6865static int wpa_driver_nl80211_get_survey(void *priv, unsigned int freq)
6866{
6867 struct i802_bss *bss = priv;
6868 struct wpa_driver_nl80211_data *drv = bss->drv;
6869 struct nl_msg *msg;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08006870 int err;
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -07006871 union wpa_event_data data;
6872 struct survey_results *survey_results;
6873
6874 os_memset(&data, 0, sizeof(data));
6875 survey_results = &data.survey_results;
6876
6877 dl_list_init(&survey_results->survey_list);
6878
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08006879 msg = nl80211_drv_msg(drv, NLM_F_DUMP, NL80211_CMD_GET_SURVEY);
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -07006880 if (!msg)
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08006881 return -ENOBUFS;
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -07006882
6883 if (freq)
6884 data.survey_results.freq_filter = freq;
6885
6886 do {
6887 wpa_printf(MSG_DEBUG, "nl80211: Fetch survey data");
6888 err = send_and_recv_msgs(drv, msg, survey_handler,
6889 survey_results);
6890 } while (err > 0);
6891
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08006892 if (err)
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -07006893 wpa_printf(MSG_ERROR, "nl80211: Failed to process survey data");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08006894 else
6895 wpa_supplicant_event(drv->ctx, EVENT_SURVEY, &data);
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -07006896
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -07006897 clean_survey_results(survey_results);
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -07006898 return err;
6899}
6900
6901
Dmitry Shmidt807291d2015-01-27 13:40:23 -08006902static void nl80211_set_rekey_info(void *priv, const u8 *kek, size_t kek_len,
6903 const u8 *kck, size_t kck_len,
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006904 const u8 *replay_ctr)
6905{
6906 struct i802_bss *bss = priv;
6907 struct wpa_driver_nl80211_data *drv = bss->drv;
6908 struct nlattr *replay_nested;
6909 struct nl_msg *msg;
Dmitry Shmidtff787d52015-01-12 13:01:47 -08006910 int ret;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006911
Dmitry Shmidtff787d52015-01-12 13:01:47 -08006912 if (!drv->set_rekey_offload)
6913 return;
6914
6915 wpa_printf(MSG_DEBUG, "nl80211: Set rekey offload");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08006916 if (!(msg = nl80211_bss_msg(bss, 0, NL80211_CMD_SET_REKEY_OFFLOAD)) ||
6917 !(replay_nested = nla_nest_start(msg, NL80211_ATTR_REKEY_DATA)) ||
Dmitry Shmidt807291d2015-01-27 13:40:23 -08006918 nla_put(msg, NL80211_REKEY_DATA_KEK, kek_len, kek) ||
6919 nla_put(msg, NL80211_REKEY_DATA_KCK, kck_len, kck) ||
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08006920 nla_put(msg, NL80211_REKEY_DATA_REPLAY_CTR, NL80211_REPLAY_CTR_LEN,
6921 replay_ctr)) {
6922 nl80211_nlmsg_clear(msg);
6923 nlmsg_free(msg);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006924 return;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08006925 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006926
6927 nla_nest_end(msg, replay_nested);
6928
Dmitry Shmidtff787d52015-01-12 13:01:47 -08006929 ret = send_and_recv_msgs(drv, msg, NULL, (void *) -1);
6930 if (ret == -EOPNOTSUPP) {
6931 wpa_printf(MSG_DEBUG,
6932 "nl80211: Driver does not support rekey offload");
6933 drv->set_rekey_offload = 0;
6934 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006935}
6936
6937
6938static void nl80211_send_null_frame(struct i802_bss *bss, const u8 *own_addr,
6939 const u8 *addr, int qos)
6940{
6941 /* send data frame to poll STA and check whether
6942 * this frame is ACKed */
6943 struct {
6944 struct ieee80211_hdr hdr;
6945 u16 qos_ctl;
6946 } STRUCT_PACKED nulldata;
6947 size_t size;
6948
6949 /* Send data frame to poll STA and check whether this frame is ACKed */
6950
6951 os_memset(&nulldata, 0, sizeof(nulldata));
6952
6953 if (qos) {
6954 nulldata.hdr.frame_control =
6955 IEEE80211_FC(WLAN_FC_TYPE_DATA,
6956 WLAN_FC_STYPE_QOS_NULL);
6957 size = sizeof(nulldata);
6958 } else {
6959 nulldata.hdr.frame_control =
6960 IEEE80211_FC(WLAN_FC_TYPE_DATA,
6961 WLAN_FC_STYPE_NULLFUNC);
6962 size = sizeof(struct ieee80211_hdr);
6963 }
6964
6965 nulldata.hdr.frame_control |= host_to_le16(WLAN_FC_FROMDS);
6966 os_memcpy(nulldata.hdr.IEEE80211_DA_FROMDS, addr, ETH_ALEN);
6967 os_memcpy(nulldata.hdr.IEEE80211_BSSID_FROMDS, own_addr, ETH_ALEN);
6968 os_memcpy(nulldata.hdr.IEEE80211_SA_FROMDS, own_addr, ETH_ALEN);
6969
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08006970 if (wpa_driver_nl80211_send_mlme(bss, (u8 *) &nulldata, size, 0, 0, 0,
6971 0, 0) < 0)
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006972 wpa_printf(MSG_DEBUG, "nl80211_send_null_frame: Failed to "
6973 "send poll frame");
6974}
6975
6976static void nl80211_poll_client(void *priv, const u8 *own_addr, const u8 *addr,
6977 int qos)
6978{
6979 struct i802_bss *bss = priv;
6980 struct wpa_driver_nl80211_data *drv = bss->drv;
6981 struct nl_msg *msg;
Dmitry Shmidt7f656022015-02-25 14:36:37 -08006982 int ret;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006983
6984 if (!drv->poll_command_supported) {
6985 nl80211_send_null_frame(bss, own_addr, addr, qos);
6986 return;
6987 }
6988
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08006989 if (!(msg = nl80211_bss_msg(bss, 0, NL80211_CMD_PROBE_CLIENT)) ||
6990 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) {
6991 nlmsg_free(msg);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006992 return;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08006993 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006994
Dmitry Shmidt7f656022015-02-25 14:36:37 -08006995 ret = send_and_recv_msgs(drv, msg, NULL, NULL);
6996 if (ret < 0) {
6997 wpa_printf(MSG_DEBUG, "nl80211: Client probe request for "
6998 MACSTR " failed: ret=%d (%s)",
6999 MAC2STR(addr), ret, strerror(-ret));
7000 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08007001}
7002
7003
7004static int nl80211_set_power_save(struct i802_bss *bss, int enabled)
7005{
7006 struct nl_msg *msg;
7007
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08007008 if (!(msg = nl80211_bss_msg(bss, 0, NL80211_CMD_SET_POWER_SAVE)) ||
7009 nla_put_u32(msg, NL80211_ATTR_PS_STATE,
7010 enabled ? NL80211_PS_ENABLED : NL80211_PS_DISABLED)) {
7011 nlmsg_free(msg);
7012 return -ENOBUFS;
7013 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08007014 return send_and_recv_msgs(bss->drv, msg, NULL, NULL);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08007015}
7016
7017
7018static int nl80211_set_p2p_powersave(void *priv, int legacy_ps, int opp_ps,
7019 int ctwindow)
7020{
7021 struct i802_bss *bss = priv;
7022
7023 wpa_printf(MSG_DEBUG, "nl80211: set_p2p_powersave (legacy_ps=%d "
7024 "opp_ps=%d ctwindow=%d)", legacy_ps, opp_ps, ctwindow);
7025
Dmitry Shmidt292b0c32013-11-22 12:54:42 -08007026 if (opp_ps != -1 || ctwindow != -1) {
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08007027#ifdef ANDROID_P2P
7028 wpa_driver_set_p2p_ps(priv, legacy_ps, opp_ps, ctwindow);
Dmitry Shmidt292b0c32013-11-22 12:54:42 -08007029#else /* ANDROID_P2P */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08007030 return -1; /* Not yet supported */
Dmitry Shmidt292b0c32013-11-22 12:54:42 -08007031#endif /* ANDROID_P2P */
7032 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08007033
7034 if (legacy_ps == -1)
7035 return 0;
7036 if (legacy_ps != 0 && legacy_ps != 1)
7037 return -1; /* Not yet supported */
7038
7039 return nl80211_set_power_save(bss, legacy_ps);
7040}
7041
7042
Dmitry Shmidt051af732013-10-22 13:52:46 -07007043static int nl80211_start_radar_detection(void *priv,
7044 struct hostapd_freq_params *freq)
Dmitry Shmidtea69e842013-05-13 14:52:28 -07007045{
7046 struct i802_bss *bss = priv;
7047 struct wpa_driver_nl80211_data *drv = bss->drv;
7048 struct nl_msg *msg;
7049 int ret;
7050
Dmitry Shmidt051af732013-10-22 13:52:46 -07007051 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)",
7052 freq->freq, freq->ht_enabled, freq->vht_enabled,
7053 freq->bandwidth, freq->center_freq1, freq->center_freq2);
7054
Dmitry Shmidtea69e842013-05-13 14:52:28 -07007055 if (!(drv->capa.flags & WPA_DRIVER_FLAGS_RADAR)) {
7056 wpa_printf(MSG_DEBUG, "nl80211: Driver does not support radar "
7057 "detection");
7058 return -1;
7059 }
7060
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08007061 if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_RADAR_DETECT)) ||
7062 nl80211_put_freq_params(msg, freq) < 0) {
7063 nlmsg_free(msg);
Dmitry Shmidtea69e842013-05-13 14:52:28 -07007064 return -1;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08007065 }
Dmitry Shmidtea69e842013-05-13 14:52:28 -07007066
7067 ret = send_and_recv_msgs(drv, msg, NULL, NULL);
7068 if (ret == 0)
7069 return 0;
7070 wpa_printf(MSG_DEBUG, "nl80211: Failed to start radar detection: "
7071 "%d (%s)", ret, strerror(-ret));
Dmitry Shmidtea69e842013-05-13 14:52:28 -07007072 return -1;
7073}
7074
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08007075#ifdef CONFIG_TDLS
7076
7077static int nl80211_send_tdls_mgmt(void *priv, const u8 *dst, u8 action_code,
7078 u8 dialog_token, u16 status_code,
Dmitry Shmidt9ead16e2014-10-07 13:15:23 -07007079 u32 peer_capab, int initiator, const u8 *buf,
7080 size_t len)
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08007081{
7082 struct i802_bss *bss = priv;
7083 struct wpa_driver_nl80211_data *drv = bss->drv;
7084 struct nl_msg *msg;
7085
7086 if (!(drv->capa.flags & WPA_DRIVER_FLAGS_TDLS_SUPPORT))
7087 return -EOPNOTSUPP;
7088
7089 if (!dst)
7090 return -EINVAL;
7091
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08007092 if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_TDLS_MGMT)) ||
7093 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, dst) ||
7094 nla_put_u8(msg, NL80211_ATTR_TDLS_ACTION, action_code) ||
7095 nla_put_u8(msg, NL80211_ATTR_TDLS_DIALOG_TOKEN, dialog_token) ||
7096 nla_put_u16(msg, NL80211_ATTR_STATUS_CODE, status_code))
7097 goto fail;
Dmitry Shmidtdf5a7e42014-04-02 12:59:59 -07007098 if (peer_capab) {
7099 /*
7100 * The internal enum tdls_peer_capability definition is
7101 * currently identical with the nl80211 enum
7102 * nl80211_tdls_peer_capability, so no conversion is needed
7103 * here.
7104 */
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08007105 if (nla_put_u32(msg, NL80211_ATTR_TDLS_PEER_CAPABILITY,
7106 peer_capab))
7107 goto fail;
Dmitry Shmidtdf5a7e42014-04-02 12:59:59 -07007108 }
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08007109 if ((initiator &&
7110 nla_put_flag(msg, NL80211_ATTR_TDLS_INITIATOR)) ||
7111 nla_put(msg, NL80211_ATTR_IE, len, buf))
7112 goto fail;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08007113
7114 return send_and_recv_msgs(drv, msg, NULL, NULL);
7115
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08007116fail:
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08007117 nlmsg_free(msg);
7118 return -ENOBUFS;
7119}
7120
7121
7122static int nl80211_tdls_oper(void *priv, enum tdls_oper oper, const u8 *peer)
7123{
7124 struct i802_bss *bss = priv;
7125 struct wpa_driver_nl80211_data *drv = bss->drv;
7126 struct nl_msg *msg;
7127 enum nl80211_tdls_operation nl80211_oper;
7128
7129 if (!(drv->capa.flags & WPA_DRIVER_FLAGS_TDLS_SUPPORT))
7130 return -EOPNOTSUPP;
7131
7132 switch (oper) {
7133 case TDLS_DISCOVERY_REQ:
7134 nl80211_oper = NL80211_TDLS_DISCOVERY_REQ;
7135 break;
7136 case TDLS_SETUP:
7137 nl80211_oper = NL80211_TDLS_SETUP;
7138 break;
7139 case TDLS_TEARDOWN:
7140 nl80211_oper = NL80211_TDLS_TEARDOWN;
7141 break;
7142 case TDLS_ENABLE_LINK:
7143 nl80211_oper = NL80211_TDLS_ENABLE_LINK;
7144 break;
7145 case TDLS_DISABLE_LINK:
7146 nl80211_oper = NL80211_TDLS_DISABLE_LINK;
7147 break;
7148 case TDLS_ENABLE:
7149 return 0;
7150 case TDLS_DISABLE:
7151 return 0;
7152 default:
7153 return -EINVAL;
7154 }
7155
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08007156 if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_TDLS_OPER)) ||
7157 nla_put_u8(msg, NL80211_ATTR_TDLS_OPERATION, nl80211_oper) ||
7158 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer)) {
7159 nlmsg_free(msg);
7160 return -ENOBUFS;
7161 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08007162
7163 return send_and_recv_msgs(drv, msg, NULL, NULL);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08007164}
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08007165
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08007166
7167static int
7168nl80211_tdls_enable_channel_switch(void *priv, const u8 *addr, u8 oper_class,
7169 const struct hostapd_freq_params *params)
7170{
7171 struct i802_bss *bss = priv;
7172 struct wpa_driver_nl80211_data *drv = bss->drv;
7173 struct nl_msg *msg;
7174 int ret = -ENOBUFS;
7175
7176 if (!(drv->capa.flags & WPA_DRIVER_FLAGS_TDLS_SUPPORT) ||
7177 !(drv->capa.flags & WPA_DRIVER_FLAGS_TDLS_CHANNEL_SWITCH))
7178 return -EOPNOTSUPP;
7179
7180 wpa_printf(MSG_DEBUG, "nl80211: Enable TDLS channel switch " MACSTR
7181 " oper_class=%u freq=%u",
7182 MAC2STR(addr), oper_class, params->freq);
7183 msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_TDLS_CHANNEL_SWITCH);
7184 if (!msg ||
7185 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) ||
7186 nla_put_u8(msg, NL80211_ATTR_OPER_CLASS, oper_class) ||
7187 (ret = nl80211_put_freq_params(msg, params))) {
7188 nlmsg_free(msg);
7189 wpa_printf(MSG_DEBUG, "nl80211: Could not build TDLS chan switch");
7190 return ret;
7191 }
7192
7193 return send_and_recv_msgs(drv, msg, NULL, NULL);
7194}
7195
7196
7197static int
7198nl80211_tdls_disable_channel_switch(void *priv, const u8 *addr)
7199{
7200 struct i802_bss *bss = priv;
7201 struct wpa_driver_nl80211_data *drv = bss->drv;
7202 struct nl_msg *msg;
7203
7204 if (!(drv->capa.flags & WPA_DRIVER_FLAGS_TDLS_SUPPORT) ||
7205 !(drv->capa.flags & WPA_DRIVER_FLAGS_TDLS_CHANNEL_SWITCH))
7206 return -EOPNOTSUPP;
7207
7208 wpa_printf(MSG_DEBUG, "nl80211: Disable TDLS channel switch " MACSTR,
7209 MAC2STR(addr));
7210 msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_TDLS_CANCEL_CHANNEL_SWITCH);
7211 if (!msg ||
7212 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) {
7213 nlmsg_free(msg);
7214 wpa_printf(MSG_DEBUG,
7215 "nl80211: Could not build TDLS cancel chan switch");
7216 return -ENOBUFS;
7217 }
7218
7219 return send_and_recv_msgs(drv, msg, NULL, NULL);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08007220}
7221
7222#endif /* CONFIG TDLS */
7223
7224
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08007225static int driver_nl80211_set_key(const char *ifname, void *priv,
7226 enum wpa_alg alg, const u8 *addr,
7227 int key_idx, int set_tx,
7228 const u8 *seq, size_t seq_len,
7229 const u8 *key, size_t key_len)
7230{
7231 struct i802_bss *bss = priv;
7232 return wpa_driver_nl80211_set_key(ifname, bss, alg, addr, key_idx,
7233 set_tx, seq, seq_len, key, key_len);
7234}
7235
7236
7237static int driver_nl80211_scan2(void *priv,
7238 struct wpa_driver_scan_params *params)
7239{
7240 struct i802_bss *bss = priv;
7241 return wpa_driver_nl80211_scan(bss, params);
7242}
7243
7244
7245static int driver_nl80211_deauthenticate(void *priv, const u8 *addr,
7246 int reason_code)
7247{
7248 struct i802_bss *bss = priv;
7249 return wpa_driver_nl80211_deauthenticate(bss, addr, reason_code);
7250}
7251
7252
7253static int driver_nl80211_authenticate(void *priv,
7254 struct wpa_driver_auth_params *params)
7255{
7256 struct i802_bss *bss = priv;
7257 return wpa_driver_nl80211_authenticate(bss, params);
7258}
7259
7260
7261static void driver_nl80211_deinit(void *priv)
7262{
7263 struct i802_bss *bss = priv;
7264 wpa_driver_nl80211_deinit(bss);
7265}
7266
7267
7268static int driver_nl80211_if_remove(void *priv, enum wpa_driver_if_type type,
7269 const char *ifname)
7270{
7271 struct i802_bss *bss = priv;
7272 return wpa_driver_nl80211_if_remove(bss, type, ifname);
7273}
7274
7275
7276static int driver_nl80211_send_mlme(void *priv, const u8 *data,
7277 size_t data_len, int noack)
7278{
7279 struct i802_bss *bss = priv;
7280 return wpa_driver_nl80211_send_mlme(bss, data, data_len, noack,
7281 0, 0, 0, 0);
7282}
7283
7284
7285static int driver_nl80211_sta_remove(void *priv, const u8 *addr)
7286{
7287 struct i802_bss *bss = priv;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08007288 return wpa_driver_nl80211_sta_remove(bss, addr, -1, 0);
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08007289}
7290
7291
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08007292static int driver_nl80211_set_sta_vlan(void *priv, const u8 *addr,
7293 const char *ifname, int vlan_id)
7294{
7295 struct i802_bss *bss = priv;
7296 return i802_set_sta_vlan(bss, addr, ifname, vlan_id);
7297}
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08007298
7299
7300static int driver_nl80211_read_sta_data(void *priv,
7301 struct hostap_sta_driver_data *data,
7302 const u8 *addr)
7303{
7304 struct i802_bss *bss = priv;
7305 return i802_read_sta_data(bss, data, addr);
7306}
7307
7308
7309static int driver_nl80211_send_action(void *priv, unsigned int freq,
7310 unsigned int wait_time,
7311 const u8 *dst, const u8 *src,
7312 const u8 *bssid,
7313 const u8 *data, size_t data_len,
7314 int no_cck)
7315{
7316 struct i802_bss *bss = priv;
7317 return wpa_driver_nl80211_send_action(bss, freq, wait_time, dst, src,
7318 bssid, data, data_len, no_cck);
7319}
7320
7321
7322static int driver_nl80211_probe_req_report(void *priv, int report)
7323{
7324 struct i802_bss *bss = priv;
7325 return wpa_driver_nl80211_probe_req_report(bss, report);
7326}
7327
7328
Dmitry Shmidt700a1372013-03-15 14:14:44 -07007329static int wpa_driver_nl80211_update_ft_ies(void *priv, const u8 *md,
7330 const u8 *ies, size_t ies_len)
7331{
7332 int ret;
7333 struct nl_msg *msg;
7334 struct i802_bss *bss = priv;
7335 struct wpa_driver_nl80211_data *drv = bss->drv;
7336 u16 mdid = WPA_GET_LE16(md);
7337
Dmitry Shmidt700a1372013-03-15 14:14:44 -07007338 wpa_printf(MSG_DEBUG, "nl80211: Updating FT IEs");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08007339 if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_UPDATE_FT_IES)) ||
7340 nla_put(msg, NL80211_ATTR_IE, ies_len, ies) ||
7341 nla_put_u16(msg, NL80211_ATTR_MDID, mdid)) {
7342 nlmsg_free(msg);
7343 return -ENOBUFS;
7344 }
Dmitry Shmidt700a1372013-03-15 14:14:44 -07007345
7346 ret = send_and_recv_msgs(drv, msg, NULL, NULL);
7347 if (ret) {
7348 wpa_printf(MSG_DEBUG, "nl80211: update_ft_ies failed "
7349 "err=%d (%s)", ret, strerror(-ret));
7350 }
7351
7352 return ret;
Dmitry Shmidt700a1372013-03-15 14:14:44 -07007353}
7354
7355
Dmitry Shmidt34af3062013-07-11 10:46:32 -07007356const u8 * wpa_driver_nl80211_get_macaddr(void *priv)
7357{
7358 struct i802_bss *bss = priv;
7359 struct wpa_driver_nl80211_data *drv = bss->drv;
7360
7361 if (drv->nlmode != NL80211_IFTYPE_P2P_DEVICE)
7362 return NULL;
7363
7364 return bss->addr;
7365}
7366
7367
Dmitry Shmidt56052862013-10-04 10:23:25 -07007368static const char * scan_state_str(enum scan_states scan_state)
7369{
7370 switch (scan_state) {
7371 case NO_SCAN:
7372 return "NO_SCAN";
7373 case SCAN_REQUESTED:
7374 return "SCAN_REQUESTED";
7375 case SCAN_STARTED:
7376 return "SCAN_STARTED";
7377 case SCAN_COMPLETED:
7378 return "SCAN_COMPLETED";
7379 case SCAN_ABORTED:
7380 return "SCAN_ABORTED";
7381 case SCHED_SCAN_STARTED:
7382 return "SCHED_SCAN_STARTED";
7383 case SCHED_SCAN_STOPPED:
7384 return "SCHED_SCAN_STOPPED";
7385 case SCHED_SCAN_RESULTS:
7386 return "SCHED_SCAN_RESULTS";
7387 }
7388
7389 return "??";
7390}
7391
7392
7393static int wpa_driver_nl80211_status(void *priv, char *buf, size_t buflen)
7394{
7395 struct i802_bss *bss = priv;
7396 struct wpa_driver_nl80211_data *drv = bss->drv;
7397 int res;
7398 char *pos, *end;
7399
7400 pos = buf;
7401 end = buf + buflen;
7402
7403 res = os_snprintf(pos, end - pos,
7404 "ifindex=%d\n"
7405 "ifname=%s\n"
7406 "brname=%s\n"
7407 "addr=" MACSTR "\n"
7408 "freq=%d\n"
7409 "%s%s%s%s%s",
7410 bss->ifindex,
7411 bss->ifname,
7412 bss->brname,
7413 MAC2STR(bss->addr),
7414 bss->freq,
7415 bss->beacon_set ? "beacon_set=1\n" : "",
7416 bss->added_if_into_bridge ?
7417 "added_if_into_bridge=1\n" : "",
7418 bss->added_bridge ? "added_bridge=1\n" : "",
7419 bss->in_deinit ? "in_deinit=1\n" : "",
7420 bss->if_dynamic ? "if_dynamic=1\n" : "");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08007421 if (os_snprintf_error(end - pos, res))
Dmitry Shmidt56052862013-10-04 10:23:25 -07007422 return pos - buf;
7423 pos += res;
7424
7425 if (bss->wdev_id_set) {
7426 res = os_snprintf(pos, end - pos, "wdev_id=%llu\n",
7427 (unsigned long long) bss->wdev_id);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08007428 if (os_snprintf_error(end - pos, res))
Dmitry Shmidt56052862013-10-04 10:23:25 -07007429 return pos - buf;
7430 pos += res;
7431 }
7432
7433 res = os_snprintf(pos, end - pos,
7434 "phyname=%s\n"
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07007435 "perm_addr=" MACSTR "\n"
Dmitry Shmidt56052862013-10-04 10:23:25 -07007436 "drv_ifindex=%d\n"
7437 "operstate=%d\n"
7438 "scan_state=%s\n"
7439 "auth_bssid=" MACSTR "\n"
7440 "auth_attempt_bssid=" MACSTR "\n"
7441 "bssid=" MACSTR "\n"
7442 "prev_bssid=" MACSTR "\n"
7443 "associated=%d\n"
7444 "assoc_freq=%u\n"
7445 "monitor_sock=%d\n"
7446 "monitor_ifidx=%d\n"
7447 "monitor_refcount=%d\n"
7448 "last_mgmt_freq=%u\n"
7449 "eapol_tx_sock=%d\n"
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08007450 "%s%s%s%s%s%s%s%s%s%s%s%s%s",
Dmitry Shmidt56052862013-10-04 10:23:25 -07007451 drv->phyname,
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07007452 MAC2STR(drv->perm_addr),
Dmitry Shmidt56052862013-10-04 10:23:25 -07007453 drv->ifindex,
7454 drv->operstate,
7455 scan_state_str(drv->scan_state),
7456 MAC2STR(drv->auth_bssid),
7457 MAC2STR(drv->auth_attempt_bssid),
7458 MAC2STR(drv->bssid),
7459 MAC2STR(drv->prev_bssid),
7460 drv->associated,
7461 drv->assoc_freq,
7462 drv->monitor_sock,
7463 drv->monitor_ifidx,
7464 drv->monitor_refcount,
7465 drv->last_mgmt_freq,
7466 drv->eapol_tx_sock,
7467 drv->ignore_if_down_event ?
7468 "ignore_if_down_event=1\n" : "",
7469 drv->scan_complete_events ?
7470 "scan_complete_events=1\n" : "",
7471 drv->disabled_11b_rates ?
7472 "disabled_11b_rates=1\n" : "",
7473 drv->pending_remain_on_chan ?
7474 "pending_remain_on_chan=1\n" : "",
7475 drv->in_interface_list ? "in_interface_list=1\n" : "",
7476 drv->device_ap_sme ? "device_ap_sme=1\n" : "",
7477 drv->poll_command_supported ?
7478 "poll_command_supported=1\n" : "",
7479 drv->data_tx_status ? "data_tx_status=1\n" : "",
7480 drv->scan_for_auth ? "scan_for_auth=1\n" : "",
7481 drv->retry_auth ? "retry_auth=1\n" : "",
7482 drv->use_monitor ? "use_monitor=1\n" : "",
7483 drv->ignore_next_local_disconnect ?
7484 "ignore_next_local_disconnect=1\n" : "",
Dmitry Shmidt7dba0e52014-04-14 10:49:15 -07007485 drv->ignore_next_local_deauth ?
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08007486 "ignore_next_local_deauth=1\n" : "");
7487 if (os_snprintf_error(end - pos, res))
Dmitry Shmidt56052862013-10-04 10:23:25 -07007488 return pos - buf;
7489 pos += res;
7490
7491 if (drv->has_capability) {
7492 res = os_snprintf(pos, end - pos,
7493 "capa.key_mgmt=0x%x\n"
7494 "capa.enc=0x%x\n"
7495 "capa.auth=0x%x\n"
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08007496 "capa.flags=0x%llx\n"
7497 "capa.rrm_flags=0x%x\n"
Dmitry Shmidt56052862013-10-04 10:23:25 -07007498 "capa.max_scan_ssids=%d\n"
7499 "capa.max_sched_scan_ssids=%d\n"
7500 "capa.sched_scan_supported=%d\n"
7501 "capa.max_match_sets=%d\n"
7502 "capa.max_remain_on_chan=%u\n"
7503 "capa.max_stations=%u\n"
7504 "capa.probe_resp_offloads=0x%x\n"
7505 "capa.max_acl_mac_addrs=%u\n"
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08007506 "capa.num_multichan_concurrent=%u\n"
7507 "capa.mac_addr_rand_sched_scan_supported=%d\n"
7508 "capa.mac_addr_rand_scan_supported=%d\n",
Dmitry Shmidt56052862013-10-04 10:23:25 -07007509 drv->capa.key_mgmt,
7510 drv->capa.enc,
7511 drv->capa.auth,
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08007512 (unsigned long long) drv->capa.flags,
7513 drv->capa.rrm_flags,
Dmitry Shmidt56052862013-10-04 10:23:25 -07007514 drv->capa.max_scan_ssids,
7515 drv->capa.max_sched_scan_ssids,
7516 drv->capa.sched_scan_supported,
7517 drv->capa.max_match_sets,
7518 drv->capa.max_remain_on_chan,
7519 drv->capa.max_stations,
7520 drv->capa.probe_resp_offloads,
7521 drv->capa.max_acl_mac_addrs,
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08007522 drv->capa.num_multichan_concurrent,
7523 drv->capa.mac_addr_rand_sched_scan_supported,
7524 drv->capa.mac_addr_rand_scan_supported);
7525 if (os_snprintf_error(end - pos, res))
Dmitry Shmidt56052862013-10-04 10:23:25 -07007526 return pos - buf;
7527 pos += res;
7528 }
7529
7530 return pos - buf;
7531}
7532
7533
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08007534static int set_beacon_data(struct nl_msg *msg, struct beacon_data *settings)
7535{
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08007536 if ((settings->head &&
7537 nla_put(msg, NL80211_ATTR_BEACON_HEAD,
7538 settings->head_len, settings->head)) ||
7539 (settings->tail &&
7540 nla_put(msg, NL80211_ATTR_BEACON_TAIL,
7541 settings->tail_len, settings->tail)) ||
7542 (settings->beacon_ies &&
7543 nla_put(msg, NL80211_ATTR_IE,
7544 settings->beacon_ies_len, settings->beacon_ies)) ||
7545 (settings->proberesp_ies &&
7546 nla_put(msg, NL80211_ATTR_IE_PROBE_RESP,
7547 settings->proberesp_ies_len, settings->proberesp_ies)) ||
7548 (settings->assocresp_ies &&
7549 nla_put(msg, NL80211_ATTR_IE_ASSOC_RESP,
7550 settings->assocresp_ies_len, settings->assocresp_ies)) ||
7551 (settings->probe_resp &&
7552 nla_put(msg, NL80211_ATTR_PROBE_RESP,
7553 settings->probe_resp_len, settings->probe_resp)))
7554 return -ENOBUFS;
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08007555
7556 return 0;
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08007557}
7558
7559
7560static int nl80211_switch_channel(void *priv, struct csa_settings *settings)
7561{
7562 struct nl_msg *msg;
7563 struct i802_bss *bss = priv;
7564 struct wpa_driver_nl80211_data *drv = bss->drv;
7565 struct nlattr *beacon_csa;
7566 int ret = -ENOBUFS;
7567
Dmitry Shmidt04f534e2013-12-09 15:50:16 -08007568 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 -08007569 settings->cs_count, settings->block_tx,
Dmitry Shmidt04f534e2013-12-09 15:50:16 -08007570 settings->freq_params.freq, settings->freq_params.bandwidth,
7571 settings->freq_params.center_freq1,
7572 settings->freq_params.center_freq2);
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08007573
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08007574 if (!(drv->capa.flags & WPA_DRIVER_FLAGS_AP_CSA)) {
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08007575 wpa_printf(MSG_DEBUG, "nl80211: Driver does not support channel switch command");
7576 return -EOPNOTSUPP;
7577 }
7578
7579 if ((drv->nlmode != NL80211_IFTYPE_AP) &&
7580 (drv->nlmode != NL80211_IFTYPE_P2P_GO))
7581 return -EOPNOTSUPP;
7582
7583 /* check settings validity */
7584 if (!settings->beacon_csa.tail ||
7585 ((settings->beacon_csa.tail_len <=
7586 settings->counter_offset_beacon) ||
7587 (settings->beacon_csa.tail[settings->counter_offset_beacon] !=
7588 settings->cs_count)))
7589 return -EINVAL;
7590
7591 if (settings->beacon_csa.probe_resp &&
7592 ((settings->beacon_csa.probe_resp_len <=
7593 settings->counter_offset_presp) ||
7594 (settings->beacon_csa.probe_resp[settings->counter_offset_presp] !=
7595 settings->cs_count)))
7596 return -EINVAL;
7597
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08007598 if (!(msg = nl80211_bss_msg(bss, 0, NL80211_CMD_CHANNEL_SWITCH)) ||
7599 nla_put_u32(msg, NL80211_ATTR_CH_SWITCH_COUNT,
7600 settings->cs_count) ||
7601 (ret = nl80211_put_freq_params(msg, &settings->freq_params)) ||
7602 (settings->block_tx &&
7603 nla_put_flag(msg, NL80211_ATTR_CH_SWITCH_BLOCK_TX)))
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08007604 goto error;
7605
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08007606 /* beacon_after params */
7607 ret = set_beacon_data(msg, &settings->beacon_after);
7608 if (ret)
7609 goto error;
7610
7611 /* beacon_csa params */
7612 beacon_csa = nla_nest_start(msg, NL80211_ATTR_CSA_IES);
7613 if (!beacon_csa)
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08007614 goto fail;
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08007615
7616 ret = set_beacon_data(msg, &settings->beacon_csa);
7617 if (ret)
7618 goto error;
7619
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08007620 if (nla_put_u16(msg, NL80211_ATTR_CSA_C_OFF_BEACON,
7621 settings->counter_offset_beacon) ||
7622 (settings->beacon_csa.probe_resp &&
7623 nla_put_u16(msg, NL80211_ATTR_CSA_C_OFF_PRESP,
7624 settings->counter_offset_presp)))
7625 goto fail;
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08007626
7627 nla_nest_end(msg, beacon_csa);
7628 ret = send_and_recv_msgs(drv, msg, NULL, NULL);
7629 if (ret) {
7630 wpa_printf(MSG_DEBUG, "nl80211: switch_channel failed err=%d (%s)",
7631 ret, strerror(-ret));
7632 }
7633 return ret;
7634
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08007635fail:
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08007636 ret = -ENOBUFS;
7637error:
7638 nlmsg_free(msg);
7639 wpa_printf(MSG_DEBUG, "nl80211: Could not build channel switch request");
7640 return ret;
7641}
7642
7643
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08007644static int nl80211_add_ts(void *priv, u8 tsid, const u8 *addr,
7645 u8 user_priority, u16 admitted_time)
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,
7653 "nl80211: add_ts request: tsid=%u admitted_time=%u up=%d",
7654 tsid, admitted_time, user_priority);
7655
7656 if (!is_sta_interface(drv->nlmode))
7657 return -ENOTSUP;
7658
7659 msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_ADD_TX_TS);
7660 if (!msg ||
7661 nla_put_u8(msg, NL80211_ATTR_TSID, tsid) ||
7662 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) ||
7663 nla_put_u8(msg, NL80211_ATTR_USER_PRIO, user_priority) ||
7664 nla_put_u16(msg, NL80211_ATTR_ADMITTED_TIME, admitted_time)) {
7665 nlmsg_free(msg);
7666 return -ENOBUFS;
7667 }
7668
7669 ret = send_and_recv_msgs(drv, msg, NULL, NULL);
7670 if (ret)
7671 wpa_printf(MSG_DEBUG, "nl80211: add_ts failed err=%d (%s)",
7672 ret, strerror(-ret));
7673 return ret;
7674}
7675
7676
7677static int nl80211_del_ts(void *priv, u8 tsid, const u8 *addr)
7678{
7679 struct i802_bss *bss = priv;
7680 struct wpa_driver_nl80211_data *drv = bss->drv;
7681 struct nl_msg *msg;
7682 int ret;
7683
7684 wpa_printf(MSG_DEBUG, "nl80211: del_ts request: tsid=%u", tsid);
7685
7686 if (!is_sta_interface(drv->nlmode))
7687 return -ENOTSUP;
7688
7689 if (!(msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_DEL_TX_TS)) ||
7690 nla_put_u8(msg, NL80211_ATTR_TSID, tsid) ||
7691 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) {
7692 nlmsg_free(msg);
7693 return -ENOBUFS;
7694 }
7695
7696 ret = send_and_recv_msgs(drv, msg, NULL, NULL);
7697 if (ret)
7698 wpa_printf(MSG_DEBUG, "nl80211: del_ts failed err=%d (%s)",
7699 ret, strerror(-ret));
7700 return ret;
7701}
7702
7703
Dmitry Shmidta38abf92014-03-06 13:38:44 -08007704#ifdef CONFIG_TESTING_OPTIONS
7705static int cmd_reply_handler(struct nl_msg *msg, void *arg)
7706{
7707 struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg));
7708 struct wpabuf *buf = arg;
7709
7710 if (!buf)
7711 return NL_SKIP;
7712
7713 if ((size_t) genlmsg_attrlen(gnlh, 0) > wpabuf_tailroom(buf)) {
7714 wpa_printf(MSG_INFO, "nl80211: insufficient buffer space for reply");
7715 return NL_SKIP;
7716 }
7717
7718 wpabuf_put_data(buf, genlmsg_attrdata(gnlh, 0),
7719 genlmsg_attrlen(gnlh, 0));
7720
7721 return NL_SKIP;
7722}
7723#endif /* CONFIG_TESTING_OPTIONS */
7724
7725
7726static int vendor_reply_handler(struct nl_msg *msg, void *arg)
7727{
7728 struct nlattr *tb[NL80211_ATTR_MAX + 1];
7729 struct nlattr *nl_vendor_reply, *nl;
7730 struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg));
7731 struct wpabuf *buf = arg;
7732 int rem;
7733
7734 if (!buf)
7735 return NL_SKIP;
7736
7737 nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0),
7738 genlmsg_attrlen(gnlh, 0), NULL);
7739 nl_vendor_reply = tb[NL80211_ATTR_VENDOR_DATA];
7740
7741 if (!nl_vendor_reply)
7742 return NL_SKIP;
7743
7744 if ((size_t) nla_len(nl_vendor_reply) > wpabuf_tailroom(buf)) {
7745 wpa_printf(MSG_INFO, "nl80211: Vendor command: insufficient buffer space for reply");
7746 return NL_SKIP;
7747 }
7748
7749 nla_for_each_nested(nl, nl_vendor_reply, rem) {
7750 wpabuf_put_data(buf, nla_data(nl), nla_len(nl));
7751 }
7752
7753 return NL_SKIP;
7754}
7755
7756
7757static int nl80211_vendor_cmd(void *priv, unsigned int vendor_id,
7758 unsigned int subcmd, const u8 *data,
7759 size_t data_len, struct wpabuf *buf)
7760{
7761 struct i802_bss *bss = priv;
7762 struct wpa_driver_nl80211_data *drv = bss->drv;
7763 struct nl_msg *msg;
7764 int ret;
7765
Dmitry Shmidta38abf92014-03-06 13:38:44 -08007766#ifdef CONFIG_TESTING_OPTIONS
7767 if (vendor_id == 0xffffffff) {
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08007768 msg = nlmsg_alloc();
7769 if (!msg)
7770 return -ENOMEM;
7771
Dmitry Shmidta38abf92014-03-06 13:38:44 -08007772 nl80211_cmd(drv, msg, 0, subcmd);
7773 if (nlmsg_append(msg, (void *) data, data_len, NLMSG_ALIGNTO) <
7774 0)
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08007775 goto fail;
Dmitry Shmidta38abf92014-03-06 13:38:44 -08007776 ret = send_and_recv_msgs(drv, msg, cmd_reply_handler, buf);
7777 if (ret)
7778 wpa_printf(MSG_DEBUG, "nl80211: command failed err=%d",
7779 ret);
7780 return ret;
7781 }
7782#endif /* CONFIG_TESTING_OPTIONS */
7783
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08007784 if (!(msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_VENDOR)) ||
7785 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, vendor_id) ||
7786 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD, subcmd) ||
7787 (data &&
7788 nla_put(msg, NL80211_ATTR_VENDOR_DATA, data_len, data)))
7789 goto fail;
Dmitry Shmidta38abf92014-03-06 13:38:44 -08007790
7791 ret = send_and_recv_msgs(drv, msg, vendor_reply_handler, buf);
7792 if (ret)
7793 wpa_printf(MSG_DEBUG, "nl80211: vendor command failed err=%d",
7794 ret);
7795 return ret;
7796
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08007797fail:
Dmitry Shmidta38abf92014-03-06 13:38:44 -08007798 nlmsg_free(msg);
7799 return -ENOBUFS;
7800}
7801
7802
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08007803static int nl80211_set_qos_map(void *priv, const u8 *qos_map_set,
7804 u8 qos_map_set_len)
7805{
7806 struct i802_bss *bss = priv;
7807 struct wpa_driver_nl80211_data *drv = bss->drv;
7808 struct nl_msg *msg;
7809 int ret;
7810
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08007811 wpa_hexdump(MSG_DEBUG, "nl80211: Setting QoS Map",
7812 qos_map_set, qos_map_set_len);
7813
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08007814 if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_SET_QOS_MAP)) ||
7815 nla_put(msg, NL80211_ATTR_QOS_MAP, qos_map_set_len, qos_map_set)) {
7816 nlmsg_free(msg);
7817 return -ENOBUFS;
7818 }
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08007819
7820 ret = send_and_recv_msgs(drv, msg, NULL, NULL);
7821 if (ret)
7822 wpa_printf(MSG_DEBUG, "nl80211: Setting QoS Map failed");
7823
7824 return ret;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08007825}
7826
7827
Dmitry Shmidtb58836e2014-04-29 14:35:56 -07007828static int nl80211_set_wowlan(void *priv,
7829 const struct wowlan_triggers *triggers)
7830{
7831 struct i802_bss *bss = priv;
7832 struct wpa_driver_nl80211_data *drv = bss->drv;
7833 struct nl_msg *msg;
7834 struct nlattr *wowlan_triggers;
7835 int ret;
7836
Dmitry Shmidtb58836e2014-04-29 14:35:56 -07007837 wpa_printf(MSG_DEBUG, "nl80211: Setting wowlan");
7838
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08007839 if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_SET_WOWLAN)) ||
7840 !(wowlan_triggers = nla_nest_start(msg,
7841 NL80211_ATTR_WOWLAN_TRIGGERS)) ||
7842 (triggers->any &&
7843 nla_put_flag(msg, NL80211_WOWLAN_TRIG_ANY)) ||
7844 (triggers->disconnect &&
7845 nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) ||
7846 (triggers->magic_pkt &&
7847 nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) ||
7848 (triggers->gtk_rekey_failure &&
7849 nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) ||
7850 (triggers->eap_identity_req &&
7851 nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) ||
7852 (triggers->four_way_handshake &&
7853 nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) ||
7854 (triggers->rfkill_release &&
7855 nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE))) {
7856 nlmsg_free(msg);
7857 return -ENOBUFS;
7858 }
Dmitry Shmidtb58836e2014-04-29 14:35:56 -07007859
7860 nla_nest_end(msg, wowlan_triggers);
7861
7862 ret = send_and_recv_msgs(drv, msg, NULL, NULL);
7863 if (ret)
7864 wpa_printf(MSG_DEBUG, "nl80211: Setting wowlan failed");
7865
7866 return ret;
Dmitry Shmidtb58836e2014-04-29 14:35:56 -07007867}
7868
7869
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07007870static int nl80211_roaming(void *priv, int allowed, const u8 *bssid)
7871{
7872 struct i802_bss *bss = priv;
7873 struct wpa_driver_nl80211_data *drv = bss->drv;
7874 struct nl_msg *msg;
7875 struct nlattr *params;
7876
7877 wpa_printf(MSG_DEBUG, "nl80211: Roaming policy: allowed=%d", allowed);
7878
7879 if (!drv->roaming_vendor_cmd_avail) {
7880 wpa_printf(MSG_DEBUG,
7881 "nl80211: Ignore roaming policy change since driver does not provide command for setting it");
7882 return -1;
7883 }
7884
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08007885 if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_VENDOR)) ||
7886 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
7887 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
7888 QCA_NL80211_VENDOR_SUBCMD_ROAMING) ||
7889 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
7890 nla_put_u32(msg, QCA_WLAN_VENDOR_ATTR_ROAMING_POLICY,
7891 allowed ? QCA_ROAMING_ALLOWED_WITHIN_ESS :
7892 QCA_ROAMING_NOT_ALLOWED) ||
7893 (bssid &&
7894 nla_put(msg, QCA_WLAN_VENDOR_ATTR_MAC_ADDR, ETH_ALEN, bssid))) {
7895 nlmsg_free(msg);
7896 return -1;
7897 }
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07007898 nla_nest_end(msg, params);
7899
7900 return send_and_recv_msgs(drv, msg, NULL, NULL);
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07007901}
7902
7903
7904static int nl80211_set_mac_addr(void *priv, const u8 *addr)
7905{
7906 struct i802_bss *bss = priv;
7907 struct wpa_driver_nl80211_data *drv = bss->drv;
7908 int new_addr = addr != NULL;
7909
7910 if (!addr)
7911 addr = drv->perm_addr;
7912
7913 if (linux_set_iface_flags(drv->global->ioctl_sock, bss->ifname, 0) < 0)
7914 return -1;
7915
7916 if (linux_set_ifhwaddr(drv->global->ioctl_sock, bss->ifname, addr) < 0)
7917 {
7918 wpa_printf(MSG_DEBUG,
7919 "nl80211: failed to set_mac_addr for %s to " MACSTR,
7920 bss->ifname, MAC2STR(addr));
7921 if (linux_set_iface_flags(drv->global->ioctl_sock, bss->ifname,
7922 1) < 0) {
7923 wpa_printf(MSG_DEBUG,
7924 "nl80211: Could not restore interface UP after failed set_mac_addr");
7925 }
7926 return -1;
7927 }
7928
7929 wpa_printf(MSG_DEBUG, "nl80211: set_mac_addr for %s to " MACSTR,
7930 bss->ifname, MAC2STR(addr));
7931 drv->addr_changed = new_addr;
7932 os_memcpy(bss->addr, addr, ETH_ALEN);
7933
7934 if (linux_set_iface_flags(drv->global->ioctl_sock, bss->ifname, 1) < 0)
7935 {
7936 wpa_printf(MSG_DEBUG,
7937 "nl80211: Could not restore interface UP after set_mac_addr");
7938 }
7939
7940 return 0;
7941}
7942
7943
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08007944#ifdef CONFIG_MESH
7945
7946static int wpa_driver_nl80211_init_mesh(void *priv)
7947{
7948 if (wpa_driver_nl80211_set_mode(priv, NL80211_IFTYPE_MESH_POINT)) {
7949 wpa_printf(MSG_INFO,
7950 "nl80211: Failed to set interface into mesh mode");
7951 return -1;
7952 }
7953 return 0;
7954}
7955
7956
Dmitry Shmidtff787d52015-01-12 13:01:47 -08007957static int nl80211_put_mesh_id(struct nl_msg *msg, const u8 *mesh_id,
7958 size_t mesh_id_len)
7959{
7960 if (mesh_id) {
7961 wpa_hexdump_ascii(MSG_DEBUG, " * Mesh ID (SSID)",
7962 mesh_id, mesh_id_len);
7963 return nla_put(msg, NL80211_ATTR_MESH_ID, mesh_id_len, mesh_id);
7964 }
7965
7966 return 0;
7967}
7968
7969
Dmitry Shmidt7f656022015-02-25 14:36:37 -08007970static int nl80211_join_mesh(struct i802_bss *bss,
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08007971 struct wpa_driver_mesh_join_params *params)
7972{
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08007973 struct wpa_driver_nl80211_data *drv = bss->drv;
7974 struct nl_msg *msg;
7975 struct nlattr *container;
Dmitry Shmidt2f74e362015-01-21 13:19:05 -08007976 int ret = -1;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08007977
7978 wpa_printf(MSG_DEBUG, "nl80211: mesh join (ifindex=%d)", drv->ifindex);
7979 msg = nl80211_drv_msg(drv, 0, NL80211_CMD_JOIN_MESH);
Dmitry Shmidtff787d52015-01-12 13:01:47 -08007980 if (!msg ||
7981 nl80211_put_freq_params(msg, &params->freq) ||
7982 nl80211_put_basic_rates(msg, params->basic_rates) ||
7983 nl80211_put_mesh_id(msg, params->meshid, params->meshid_len) ||
7984 nl80211_put_beacon_int(msg, params->beacon_int))
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08007985 goto fail;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08007986
7987 wpa_printf(MSG_DEBUG, " * flags=%08X", params->flags);
7988
7989 container = nla_nest_start(msg, NL80211_ATTR_MESH_SETUP);
7990 if (!container)
7991 goto fail;
7992
7993 if (params->ies) {
7994 wpa_hexdump(MSG_DEBUG, " * IEs", params->ies, params->ie_len);
7995 if (nla_put(msg, NL80211_MESH_SETUP_IE, params->ie_len,
7996 params->ies))
7997 goto fail;
7998 }
7999 /* WPA_DRIVER_MESH_FLAG_OPEN_AUTH is treated as default by nl80211 */
8000 if (params->flags & WPA_DRIVER_MESH_FLAG_SAE_AUTH) {
8001 if (nla_put_u8(msg, NL80211_MESH_SETUP_AUTH_PROTOCOL, 0x1) ||
8002 nla_put_flag(msg, NL80211_MESH_SETUP_USERSPACE_AUTH))
8003 goto fail;
8004 }
8005 if ((params->flags & WPA_DRIVER_MESH_FLAG_AMPE) &&
8006 nla_put_flag(msg, NL80211_MESH_SETUP_USERSPACE_AMPE))
8007 goto fail;
8008 if ((params->flags & WPA_DRIVER_MESH_FLAG_USER_MPM) &&
8009 nla_put_flag(msg, NL80211_MESH_SETUP_USERSPACE_MPM))
8010 goto fail;
8011 nla_nest_end(msg, container);
8012
8013 container = nla_nest_start(msg, NL80211_ATTR_MESH_CONFIG);
8014 if (!container)
8015 goto fail;
8016
8017 if (!(params->conf.flags & WPA_DRIVER_MESH_CONF_FLAG_AUTO_PLINKS) &&
8018 nla_put_u32(msg, NL80211_MESHCONF_AUTO_OPEN_PLINKS, 0))
8019 goto fail;
8020 if ((params->conf.flags & WPA_DRIVER_MESH_FLAG_DRIVER_MPM) &&
8021 nla_put_u16(msg, NL80211_MESHCONF_MAX_PEER_LINKS,
8022 params->max_peer_links))
8023 goto fail;
Dmitry Shmidt2f74e362015-01-21 13:19:05 -08008024
8025 /*
8026 * Set NL80211_MESHCONF_PLINK_TIMEOUT even if user mpm is used because
8027 * the timer could disconnect stations even in that case.
Dmitry Shmidt2f74e362015-01-21 13:19:05 -08008028 */
Dmitry Shmidt7f656022015-02-25 14:36:37 -08008029 if (nla_put_u32(msg, NL80211_MESHCONF_PLINK_TIMEOUT,
8030 params->conf.peer_link_timeout)) {
Dmitry Shmidt2f74e362015-01-21 13:19:05 -08008031 wpa_printf(MSG_ERROR, "nl80211: Failed to set PLINK_TIMEOUT");
8032 goto fail;
8033 }
8034
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08008035 nla_nest_end(msg, container);
8036
8037 ret = send_and_recv_msgs(drv, msg, NULL, NULL);
8038 msg = NULL;
8039 if (ret) {
8040 wpa_printf(MSG_DEBUG, "nl80211: mesh join failed: ret=%d (%s)",
8041 ret, strerror(-ret));
8042 goto fail;
8043 }
8044 ret = 0;
Dmitry Shmidtff787d52015-01-12 13:01:47 -08008045 bss->freq = params->freq.freq;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08008046 wpa_printf(MSG_DEBUG, "nl80211: mesh join request send successfully");
8047
8048fail:
8049 nlmsg_free(msg);
8050 return ret;
8051}
8052
8053
Dmitry Shmidt7f656022015-02-25 14:36:37 -08008054static int
8055wpa_driver_nl80211_join_mesh(void *priv,
8056 struct wpa_driver_mesh_join_params *params)
8057{
8058 struct i802_bss *bss = priv;
8059 int ret, timeout;
8060
8061 timeout = params->conf.peer_link_timeout;
8062
8063 /* Disable kernel inactivity timer */
8064 if (params->flags & WPA_DRIVER_MESH_FLAG_USER_MPM)
8065 params->conf.peer_link_timeout = 0;
8066
8067 ret = nl80211_join_mesh(bss, params);
8068 if (ret == -EINVAL && params->conf.peer_link_timeout == 0) {
8069 wpa_printf(MSG_DEBUG,
8070 "nl80211: Mesh join retry for peer_link_timeout");
8071 /*
8072 * Old kernel does not support setting
8073 * NL80211_MESHCONF_PLINK_TIMEOUT to zero, so set 60 seconds
8074 * into future from peer_link_timeout.
8075 */
8076 params->conf.peer_link_timeout = timeout + 60;
8077 ret = nl80211_join_mesh(priv, params);
8078 }
8079
8080 params->conf.peer_link_timeout = timeout;
8081 return ret;
8082}
8083
8084
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08008085static int wpa_driver_nl80211_leave_mesh(void *priv)
8086{
8087 struct i802_bss *bss = priv;
8088 struct wpa_driver_nl80211_data *drv = bss->drv;
8089 struct nl_msg *msg;
8090 int ret;
8091
8092 wpa_printf(MSG_DEBUG, "nl80211: mesh leave (ifindex=%d)", drv->ifindex);
8093 msg = nl80211_drv_msg(drv, 0, NL80211_CMD_LEAVE_MESH);
8094 ret = send_and_recv_msgs(drv, msg, NULL, NULL);
8095 if (ret) {
8096 wpa_printf(MSG_DEBUG, "nl80211: mesh leave failed: ret=%d (%s)",
8097 ret, strerror(-ret));
8098 } else {
8099 wpa_printf(MSG_DEBUG,
8100 "nl80211: mesh leave request send successfully");
8101 }
8102
8103 if (wpa_driver_nl80211_set_mode(drv->first_bss,
8104 NL80211_IFTYPE_STATION)) {
8105 wpa_printf(MSG_INFO,
8106 "nl80211: Failed to set interface into station mode");
8107 }
8108 return ret;
8109}
8110
8111#endif /* CONFIG_MESH */
8112
8113
8114static int wpa_driver_br_add_ip_neigh(void *priv, u8 version,
8115 const u8 *ipaddr, int prefixlen,
8116 const u8 *addr)
8117{
8118#ifdef CONFIG_LIBNL3_ROUTE
8119 struct i802_bss *bss = priv;
8120 struct wpa_driver_nl80211_data *drv = bss->drv;
8121 struct rtnl_neigh *rn;
8122 struct nl_addr *nl_ipaddr = NULL;
8123 struct nl_addr *nl_lladdr = NULL;
8124 int family, addrsize;
8125 int res;
8126
8127 if (!ipaddr || prefixlen == 0 || !addr)
8128 return -EINVAL;
8129
8130 if (bss->br_ifindex == 0) {
8131 wpa_printf(MSG_DEBUG,
8132 "nl80211: bridge must be set before adding an ip neigh to it");
8133 return -1;
8134 }
8135
8136 if (!drv->rtnl_sk) {
8137 wpa_printf(MSG_DEBUG,
8138 "nl80211: nl_sock for NETLINK_ROUTE is not initialized");
8139 return -1;
8140 }
8141
8142 if (version == 4) {
8143 family = AF_INET;
8144 addrsize = 4;
8145 } else if (version == 6) {
8146 family = AF_INET6;
8147 addrsize = 16;
8148 } else {
8149 return -EINVAL;
8150 }
8151
8152 rn = rtnl_neigh_alloc();
8153 if (rn == NULL)
8154 return -ENOMEM;
8155
8156 /* set the destination ip address for neigh */
8157 nl_ipaddr = nl_addr_build(family, (void *) ipaddr, addrsize);
8158 if (nl_ipaddr == NULL) {
8159 wpa_printf(MSG_DEBUG, "nl80211: nl_ipaddr build failed");
8160 res = -ENOMEM;
8161 goto errout;
8162 }
8163 nl_addr_set_prefixlen(nl_ipaddr, prefixlen);
8164 res = rtnl_neigh_set_dst(rn, nl_ipaddr);
8165 if (res) {
8166 wpa_printf(MSG_DEBUG,
8167 "nl80211: neigh set destination addr failed");
8168 goto errout;
8169 }
8170
8171 /* set the corresponding lladdr for neigh */
8172 nl_lladdr = nl_addr_build(AF_BRIDGE, (u8 *) addr, ETH_ALEN);
8173 if (nl_lladdr == NULL) {
8174 wpa_printf(MSG_DEBUG, "nl80211: neigh set lladdr failed");
8175 res = -ENOMEM;
8176 goto errout;
8177 }
8178 rtnl_neigh_set_lladdr(rn, nl_lladdr);
8179
8180 rtnl_neigh_set_ifindex(rn, bss->br_ifindex);
8181 rtnl_neigh_set_state(rn, NUD_PERMANENT);
8182
8183 res = rtnl_neigh_add(drv->rtnl_sk, rn, NLM_F_CREATE);
8184 if (res) {
8185 wpa_printf(MSG_DEBUG,
8186 "nl80211: Adding bridge ip neigh failed: %s",
8187 strerror(errno));
8188 }
8189errout:
8190 if (nl_lladdr)
8191 nl_addr_put(nl_lladdr);
8192 if (nl_ipaddr)
8193 nl_addr_put(nl_ipaddr);
8194 if (rn)
8195 rtnl_neigh_put(rn);
8196 return res;
8197#else /* CONFIG_LIBNL3_ROUTE */
8198 return -1;
8199#endif /* CONFIG_LIBNL3_ROUTE */
8200}
8201
8202
8203static int wpa_driver_br_delete_ip_neigh(void *priv, u8 version,
8204 const u8 *ipaddr)
8205{
8206#ifdef CONFIG_LIBNL3_ROUTE
8207 struct i802_bss *bss = priv;
8208 struct wpa_driver_nl80211_data *drv = bss->drv;
8209 struct rtnl_neigh *rn;
8210 struct nl_addr *nl_ipaddr;
8211 int family, addrsize;
8212 int res;
8213
8214 if (!ipaddr)
8215 return -EINVAL;
8216
8217 if (version == 4) {
8218 family = AF_INET;
8219 addrsize = 4;
8220 } else if (version == 6) {
8221 family = AF_INET6;
8222 addrsize = 16;
8223 } else {
8224 return -EINVAL;
8225 }
8226
8227 if (bss->br_ifindex == 0) {
8228 wpa_printf(MSG_DEBUG,
8229 "nl80211: bridge must be set to delete an ip neigh");
8230 return -1;
8231 }
8232
8233 if (!drv->rtnl_sk) {
8234 wpa_printf(MSG_DEBUG,
8235 "nl80211: nl_sock for NETLINK_ROUTE is not initialized");
8236 return -1;
8237 }
8238
8239 rn = rtnl_neigh_alloc();
8240 if (rn == NULL)
8241 return -ENOMEM;
8242
8243 /* set the destination ip address for neigh */
8244 nl_ipaddr = nl_addr_build(family, (void *) ipaddr, addrsize);
8245 if (nl_ipaddr == NULL) {
8246 wpa_printf(MSG_DEBUG, "nl80211: nl_ipaddr build failed");
8247 res = -ENOMEM;
8248 goto errout;
8249 }
8250 res = rtnl_neigh_set_dst(rn, nl_ipaddr);
8251 if (res) {
8252 wpa_printf(MSG_DEBUG,
8253 "nl80211: neigh set destination addr failed");
8254 goto errout;
8255 }
8256
8257 rtnl_neigh_set_ifindex(rn, bss->br_ifindex);
8258
8259 res = rtnl_neigh_delete(drv->rtnl_sk, rn, 0);
8260 if (res) {
8261 wpa_printf(MSG_DEBUG,
8262 "nl80211: Deleting bridge ip neigh failed: %s",
8263 strerror(errno));
8264 }
8265errout:
8266 if (nl_ipaddr)
8267 nl_addr_put(nl_ipaddr);
8268 if (rn)
8269 rtnl_neigh_put(rn);
8270 return res;
8271#else /* CONFIG_LIBNL3_ROUTE */
8272 return -1;
8273#endif /* CONFIG_LIBNL3_ROUTE */
8274}
8275
8276
8277static int linux_write_system_file(const char *path, unsigned int val)
8278{
8279 char buf[50];
8280 int fd, len;
8281
8282 len = os_snprintf(buf, sizeof(buf), "%u\n", val);
8283 if (os_snprintf_error(sizeof(buf), len))
8284 return -1;
8285
8286 fd = open(path, O_WRONLY);
8287 if (fd < 0)
8288 return -1;
8289
8290 if (write(fd, buf, len) < 0) {
8291 wpa_printf(MSG_DEBUG,
8292 "nl80211: Failed to write Linux system file: %s with the value of %d",
8293 path, val);
8294 close(fd);
8295 return -1;
8296 }
8297 close(fd);
8298
8299 return 0;
8300}
8301
8302
8303static const char * drv_br_port_attr_str(enum drv_br_port_attr attr)
8304{
8305 switch (attr) {
8306 case DRV_BR_PORT_ATTR_PROXYARP:
8307 return "proxyarp";
8308 case DRV_BR_PORT_ATTR_HAIRPIN_MODE:
8309 return "hairpin_mode";
8310 }
8311
8312 return NULL;
8313}
8314
8315
8316static int wpa_driver_br_port_set_attr(void *priv, enum drv_br_port_attr attr,
8317 unsigned int val)
8318{
8319 struct i802_bss *bss = priv;
8320 char path[128];
8321 const char *attr_txt;
8322
8323 attr_txt = drv_br_port_attr_str(attr);
8324 if (attr_txt == NULL)
8325 return -EINVAL;
8326
8327 os_snprintf(path, sizeof(path), "/sys/class/net/%s/brport/%s",
8328 bss->ifname, attr_txt);
8329
8330 if (linux_write_system_file(path, val))
8331 return -1;
8332
8333 return 0;
8334}
8335
8336
8337static const char * drv_br_net_param_str(enum drv_br_net_param param)
8338{
8339 switch (param) {
8340 case DRV_BR_NET_PARAM_GARP_ACCEPT:
8341 return "arp_accept";
8342 }
8343
8344 return NULL;
8345}
8346
8347
8348static int wpa_driver_br_set_net_param(void *priv, enum drv_br_net_param param,
8349 unsigned int val)
8350{
8351 struct i802_bss *bss = priv;
8352 char path[128];
8353 const char *param_txt;
8354 int ip_version = 4;
8355
8356 param_txt = drv_br_net_param_str(param);
8357 if (param_txt == NULL)
8358 return -EINVAL;
8359
8360 switch (param) {
8361 case DRV_BR_NET_PARAM_GARP_ACCEPT:
8362 ip_version = 4;
8363 break;
8364 default:
8365 return -EINVAL;
8366 }
8367
8368 os_snprintf(path, sizeof(path), "/proc/sys/net/ipv%d/conf/%s/%s",
8369 ip_version, bss->brname, param_txt);
8370
8371 if (linux_write_system_file(path, val))
8372 return -1;
8373
8374 return 0;
8375}
8376
8377
8378static int hw_mode_to_qca_acs(enum hostapd_hw_mode hw_mode)
8379{
8380 switch (hw_mode) {
8381 case HOSTAPD_MODE_IEEE80211B:
8382 return QCA_ACS_MODE_IEEE80211B;
8383 case HOSTAPD_MODE_IEEE80211G:
8384 return QCA_ACS_MODE_IEEE80211G;
8385 case HOSTAPD_MODE_IEEE80211A:
8386 return QCA_ACS_MODE_IEEE80211A;
8387 case HOSTAPD_MODE_IEEE80211AD:
8388 return QCA_ACS_MODE_IEEE80211AD;
8389 default:
8390 return -1;
8391 }
8392}
8393
8394
8395static int wpa_driver_do_acs(void *priv, struct drv_acs_params *params)
8396{
8397 struct i802_bss *bss = priv;
8398 struct wpa_driver_nl80211_data *drv = bss->drv;
8399 struct nl_msg *msg;
8400 struct nlattr *data;
8401 int ret;
8402 int mode;
8403
8404 mode = hw_mode_to_qca_acs(params->hw_mode);
8405 if (mode < 0)
8406 return -1;
8407
8408 if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_VENDOR)) ||
8409 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
8410 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
8411 QCA_NL80211_VENDOR_SUBCMD_DO_ACS) ||
8412 !(data = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
8413 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_ACS_HW_MODE, mode) ||
8414 (params->ht_enabled &&
8415 nla_put_flag(msg, QCA_WLAN_VENDOR_ATTR_ACS_HT_ENABLED)) ||
8416 (params->ht40_enabled &&
8417 nla_put_flag(msg, QCA_WLAN_VENDOR_ATTR_ACS_HT40_ENABLED))) {
8418 nlmsg_free(msg);
8419 return -ENOBUFS;
8420 }
8421 nla_nest_end(msg, data);
8422
8423 ret = send_and_recv_msgs(drv, msg, NULL, NULL);
8424 if (ret) {
8425 wpa_printf(MSG_DEBUG,
8426 "nl80211: Failed to invoke driver ACS function: %s",
8427 strerror(errno));
8428 }
8429 return ret;
8430}
8431
8432
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07008433const struct wpa_driver_ops wpa_driver_nl80211_ops = {
8434 .name = "nl80211",
8435 .desc = "Linux nl80211/cfg80211",
8436 .get_bssid = wpa_driver_nl80211_get_bssid,
8437 .get_ssid = wpa_driver_nl80211_get_ssid,
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08008438 .set_key = driver_nl80211_set_key,
8439 .scan2 = driver_nl80211_scan2,
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08008440 .sched_scan = wpa_driver_nl80211_sched_scan,
8441 .stop_sched_scan = wpa_driver_nl80211_stop_sched_scan,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07008442 .get_scan_results2 = wpa_driver_nl80211_get_scan_results,
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08008443 .deauthenticate = driver_nl80211_deauthenticate,
8444 .authenticate = driver_nl80211_authenticate,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07008445 .associate = wpa_driver_nl80211_associate,
8446 .global_init = nl80211_global_init,
8447 .global_deinit = nl80211_global_deinit,
8448 .init2 = wpa_driver_nl80211_init,
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08008449 .deinit = driver_nl80211_deinit,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07008450 .get_capa = wpa_driver_nl80211_get_capa,
8451 .set_operstate = wpa_driver_nl80211_set_operstate,
8452 .set_supp_port = wpa_driver_nl80211_set_supp_port,
8453 .set_country = wpa_driver_nl80211_set_country,
Dmitry Shmidtcce06662013-11-04 18:44:24 -08008454 .get_country = wpa_driver_nl80211_get_country,
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08008455 .set_ap = wpa_driver_nl80211_set_ap,
Dmitry Shmidt8bae4132013-06-06 11:25:10 -07008456 .set_acl = wpa_driver_nl80211_set_acl,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07008457 .if_add = wpa_driver_nl80211_if_add,
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08008458 .if_remove = driver_nl80211_if_remove,
8459 .send_mlme = driver_nl80211_send_mlme,
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08008460 .get_hw_feature_data = nl80211_get_hw_feature_data,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07008461 .sta_add = wpa_driver_nl80211_sta_add,
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08008462 .sta_remove = driver_nl80211_sta_remove,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07008463 .hapd_send_eapol = wpa_driver_nl80211_hapd_send_eapol,
8464 .sta_set_flags = wpa_driver_nl80211_sta_set_flags,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07008465 .hapd_init = i802_init,
8466 .hapd_deinit = i802_deinit,
Jouni Malinen75ecf522011-06-27 15:19:46 -07008467 .set_wds_sta = i802_set_wds_sta,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07008468 .get_seqnum = i802_get_seqnum,
8469 .flush = i802_flush,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07008470 .get_inact_sec = i802_get_inact_sec,
8471 .sta_clear_stats = i802_sta_clear_stats,
8472 .set_rts = i802_set_rts,
8473 .set_frag = i802_set_frag,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07008474 .set_tx_queue_params = i802_set_tx_queue_params,
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08008475 .set_sta_vlan = driver_nl80211_set_sta_vlan,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07008476 .sta_deauth = i802_sta_deauth,
8477 .sta_disassoc = i802_sta_disassoc,
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08008478 .read_sta_data = driver_nl80211_read_sta_data,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07008479 .set_freq = i802_set_freq,
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08008480 .send_action = driver_nl80211_send_action,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07008481 .send_action_cancel_wait = wpa_driver_nl80211_send_action_cancel_wait,
8482 .remain_on_channel = wpa_driver_nl80211_remain_on_channel,
8483 .cancel_remain_on_channel =
8484 wpa_driver_nl80211_cancel_remain_on_channel,
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08008485 .probe_req_report = driver_nl80211_probe_req_report,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07008486 .deinit_ap = wpa_driver_nl80211_deinit_ap,
Dmitry Shmidt04949592012-07-19 12:16:46 -07008487 .deinit_p2p_cli = wpa_driver_nl80211_deinit_p2p_cli,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07008488 .resume = wpa_driver_nl80211_resume,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07008489 .signal_monitor = nl80211_signal_monitor,
8490 .signal_poll = nl80211_signal_poll,
8491 .send_frame = nl80211_send_frame,
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08008492 .shared_freq = wpa_driver_nl80211_shared_freq,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07008493 .set_param = nl80211_set_param,
8494 .get_radio_name = nl80211_get_radio_name,
Jouni Malinen75ecf522011-06-27 15:19:46 -07008495 .add_pmkid = nl80211_add_pmkid,
8496 .remove_pmkid = nl80211_remove_pmkid,
8497 .flush_pmkid = nl80211_flush_pmkid,
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08008498 .set_rekey_info = nl80211_set_rekey_info,
8499 .poll_client = nl80211_poll_client,
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08008500 .set_p2p_powersave = nl80211_set_p2p_powersave,
Dmitry Shmidtea69e842013-05-13 14:52:28 -07008501 .start_dfs_cac = nl80211_start_radar_detection,
8502 .stop_ap = wpa_driver_nl80211_stop_ap,
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08008503#ifdef CONFIG_TDLS
8504 .send_tdls_mgmt = nl80211_send_tdls_mgmt,
8505 .tdls_oper = nl80211_tdls_oper,
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08008506 .tdls_enable_channel_switch = nl80211_tdls_enable_channel_switch,
8507 .tdls_disable_channel_switch = nl80211_tdls_disable_channel_switch,
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08008508#endif /* CONFIG_TDLS */
Dmitry Shmidt700a1372013-03-15 14:14:44 -07008509 .update_ft_ies = wpa_driver_nl80211_update_ft_ies,
Dmitry Shmidt34af3062013-07-11 10:46:32 -07008510 .get_mac_addr = wpa_driver_nl80211_get_macaddr,
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -07008511 .get_survey = wpa_driver_nl80211_get_survey,
Dmitry Shmidt56052862013-10-04 10:23:25 -07008512 .status = wpa_driver_nl80211_status,
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08008513 .switch_channel = nl80211_switch_channel,
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08008514#ifdef ANDROID_P2P
Dmitry Shmidt6e933c12011-09-27 12:29:26 -07008515 .set_noa = wpa_driver_set_p2p_noa,
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08008516 .get_noa = wpa_driver_get_p2p_noa,
Dmitry Shmidt6e933c12011-09-27 12:29:26 -07008517 .set_ap_wps_ie = wpa_driver_set_ap_wps_p2p_ie,
Dmitry Shmidt292b0c32013-11-22 12:54:42 -08008518#endif /* ANDROID_P2P */
Dmitry Shmidt738a26e2011-07-07 14:22:14 -07008519#ifdef ANDROID
8520 .driver_cmd = wpa_driver_nl80211_driver_cmd,
Dmitry Shmidt292b0c32013-11-22 12:54:42 -08008521#endif /* ANDROID */
Dmitry Shmidta38abf92014-03-06 13:38:44 -08008522 .vendor_cmd = nl80211_vendor_cmd,
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08008523 .set_qos_map = nl80211_set_qos_map,
Dmitry Shmidtb58836e2014-04-29 14:35:56 -07008524 .set_wowlan = nl80211_set_wowlan,
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07008525 .roaming = nl80211_roaming,
8526 .set_mac_addr = nl80211_set_mac_addr,
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08008527#ifdef CONFIG_MESH
8528 .init_mesh = wpa_driver_nl80211_init_mesh,
8529 .join_mesh = wpa_driver_nl80211_join_mesh,
8530 .leave_mesh = wpa_driver_nl80211_leave_mesh,
8531#endif /* CONFIG_MESH */
8532 .br_add_ip_neigh = wpa_driver_br_add_ip_neigh,
8533 .br_delete_ip_neigh = wpa_driver_br_delete_ip_neigh,
8534 .br_port_set_attr = wpa_driver_br_port_set_attr,
8535 .br_set_net_param = wpa_driver_br_set_net_param,
8536 .add_tx_ts = nl80211_add_ts,
8537 .del_tx_ts = nl80211_del_ts,
8538 .do_acs = wpa_driver_do_acs,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07008539};