blob: 26e4984d6320a1e05f56b06bfe494175b3a78f56 [file] [log] [blame]
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001/*
2 * Driver interaction with Linux nl80211/cfg80211
Dmitry Shmidt807291d2015-01-27 13:40:23 -08003 * Copyright (c) 2002-2015, Jouni Malinen <j@w1.fi>
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004 * Copyright (c) 2003-2004, Instant802 Networks, Inc.
5 * Copyright (c) 2005-2006, Devicescape Software, Inc.
6 * Copyright (c) 2007, Johannes Berg <johannes@sipsolutions.net>
7 * Copyright (c) 2009-2010, Atheros Communications
8 *
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08009 * This software may be distributed under the terms of the BSD license.
10 * See README for more details.
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070011 */
12
13#include "includes.h"
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070014#include <sys/types.h>
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070015#include <fcntl.h>
16#include <net/if.h>
17#include <netlink/genl/genl.h>
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070018#include <netlink/genl/ctrl.h>
Dmitry Shmidt661b4f72014-09-29 14:58:27 -070019#ifdef CONFIG_LIBNL3_ROUTE
20#include <netlink/route/neighbour.h>
21#endif /* CONFIG_LIBNL3_ROUTE */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070022#include <linux/rtnetlink.h>
23#include <netpacket/packet.h>
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -080024#include <linux/errqueue.h>
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070025
26#include "common.h"
27#include "eloop.h"
Dmitry Shmidtcf32e602014-01-28 10:57:39 -080028#include "common/qca-vendor.h"
Dmitry Shmidt7832adb2014-04-29 10:53:02 -070029#include "common/qca-vendor-attr.h"
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070030#include "common/ieee802_11_defs.h"
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -080031#include "common/ieee802_11_common.h"
32#include "l2_packet/l2_packet.h"
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070033#include "netlink.h"
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080034#include "linux_defines.h"
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070035#include "linux_ioctl.h"
36#include "radiotap.h"
37#include "radiotap_iter.h"
38#include "rfkill.h"
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080039#include "driver_nl80211.h"
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -080040
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -080041
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080042#ifndef CONFIG_LIBNL20
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070043/*
44 * libnl 1.1 has a bug, it tries to allocate socket numbers densely
45 * but when you free a socket again it will mess up its bitmap and
46 * and use the wrong number the next time it needs a socket ID.
47 * Therefore, we wrap the handle alloc/destroy and add our own pid
48 * accounting.
49 */
50static uint32_t port_bitmap[32] = { 0 };
51
52static struct nl_handle *nl80211_handle_alloc(void *cb)
53{
54 struct nl_handle *handle;
55 uint32_t pid = getpid() & 0x3FFFFF;
56 int i;
57
58 handle = nl_handle_alloc_cb(cb);
59
60 for (i = 0; i < 1024; i++) {
61 if (port_bitmap[i / 32] & (1 << (i % 32)))
62 continue;
63 port_bitmap[i / 32] |= 1 << (i % 32);
64 pid += i << 22;
65 break;
66 }
67
68 nl_socket_set_local_port(handle, pid);
69
70 return handle;
71}
72
73static void nl80211_handle_destroy(struct nl_handle *handle)
74{
75 uint32_t port = nl_socket_get_local_port(handle);
76
77 port >>= 22;
78 port_bitmap[port / 32] &= ~(1 << (port % 32));
79
80 nl_handle_destroy(handle);
81}
82#endif /* CONFIG_LIBNL20 */
83
84
Dmitry Shmidt54605472013-11-08 11:10:19 -080085#ifdef ANDROID
86/* system/core/libnl_2 does not include nl_socket_set_nonblocking() */
Dmitry Shmidt54605472013-11-08 11:10:19 -080087#undef nl_socket_set_nonblocking
88#define nl_socket_set_nonblocking(h) android_nl_socket_set_nonblocking(h)
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080089
90#define genl_ctrl_resolve android_genl_ctrl_resolve
Dmitry Shmidt54605472013-11-08 11:10:19 -080091#endif /* ANDROID */
92
93
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -080094static struct nl_handle * nl_create_handle(struct nl_cb *cb, const char *dbg)
95{
96 struct nl_handle *handle;
97
98 handle = nl80211_handle_alloc(cb);
99 if (handle == NULL) {
100 wpa_printf(MSG_ERROR, "nl80211: Failed to allocate netlink "
101 "callbacks (%s)", dbg);
102 return NULL;
103 }
104
105 if (genl_connect(handle)) {
106 wpa_printf(MSG_ERROR, "nl80211: Failed to connect to generic "
107 "netlink (%s)", dbg);
108 nl80211_handle_destroy(handle);
109 return NULL;
110 }
111
112 return handle;
113}
114
115
116static void nl_destroy_handles(struct nl_handle **handle)
117{
118 if (*handle == NULL)
119 return;
120 nl80211_handle_destroy(*handle);
121 *handle = NULL;
122}
123
124
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -0700125#if __WORDSIZE == 64
126#define ELOOP_SOCKET_INVALID (intptr_t) 0x8888888888888889ULL
127#else
128#define ELOOP_SOCKET_INVALID (intptr_t) 0x88888889ULL
129#endif
130
131static void nl80211_register_eloop_read(struct nl_handle **handle,
132 eloop_sock_handler handler,
133 void *eloop_data)
134{
Dmitry Shmidt807291d2015-01-27 13:40:23 -0800135#ifdef CONFIG_LIBNL20
136 /*
137 * libnl uses a pretty small buffer (32 kB that gets converted to 64 kB)
138 * by default. It is possible to hit that limit in some cases where
139 * operations are blocked, e.g., with a burst of Deauthentication frames
140 * to hostapd and STA entry deletion. Try to increase the buffer to make
141 * this less likely to occur.
142 */
143 if (nl_socket_set_buffer_size(*handle, 262144, 0) < 0) {
144 wpa_printf(MSG_DEBUG,
145 "nl80211: Could not set nl_socket RX buffer size: %s",
146 strerror(errno));
147 /* continue anyway with the default (smaller) buffer */
148 }
149#endif /* CONFIG_LIBNL20 */
150
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -0700151 nl_socket_set_nonblocking(*handle);
152 eloop_register_read_sock(nl_socket_get_fd(*handle), handler,
153 eloop_data, *handle);
154 *handle = (void *) (((intptr_t) *handle) ^ ELOOP_SOCKET_INVALID);
155}
156
157
158static void nl80211_destroy_eloop_handle(struct nl_handle **handle)
159{
160 *handle = (void *) (((intptr_t) *handle) ^ ELOOP_SOCKET_INVALID);
161 eloop_unregister_read_sock(nl_socket_get_fd(*handle));
162 nl_destroy_handles(handle);
163}
164
165
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800166static void nl80211_global_deinit(void *priv);
Dmitry Shmidt7f656022015-02-25 14:36:37 -0800167static void nl80211_check_global(struct nl80211_global *global);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800168
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -0800169static void wpa_driver_nl80211_deinit(struct i802_bss *bss);
Dmitry Shmidt9ead16e2014-10-07 13:15:23 -0700170static int wpa_driver_nl80211_set_mode_ibss(struct i802_bss *bss,
171 struct hostapd_freq_params *freq);
Dmitry Shmidtd30ac602014-06-30 09:54:22 -0700172
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700173static int
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -0800174wpa_driver_nl80211_finish_drv_init(struct wpa_driver_nl80211_data *drv,
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800175 const u8 *set_addr, int first,
176 const char *driver_params);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800177static int nl80211_send_frame_cmd(struct i802_bss *bss,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700178 unsigned int freq, unsigned int wait,
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800179 const u8 *buf, size_t buf_len, u64 *cookie,
180 int no_cck, int no_ack, int offchanok);
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -0800181static int wpa_driver_nl80211_probe_req_report(struct i802_bss *bss,
182 int report);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700183
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700184static void add_ifidx(struct wpa_driver_nl80211_data *drv, int ifidx);
185static void del_ifidx(struct wpa_driver_nl80211_data *drv, int ifidx);
186static int have_ifidx(struct wpa_driver_nl80211_data *drv, int ifidx);
Dmitry Shmidt738a26e2011-07-07 14:22:14 -0700187
Dmitry Shmidt7832adb2014-04-29 10:53:02 -0700188static int nl80211_set_channel(struct i802_bss *bss,
189 struct hostapd_freq_params *freq, int set_chan);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700190static int nl80211_disable_11b_rates(struct wpa_driver_nl80211_data *drv,
191 int ifindex, int disabled);
192
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800193static int nl80211_leave_ibss(struct wpa_driver_nl80211_data *drv,
194 int reset_mode);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800195
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -0700196static int i802_set_iface_flags(struct i802_bss *bss, int up);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800197static int nl80211_set_param(void *priv, const char *param);
Dmitry Shmidt34af3062013-07-11 10:46:32 -0700198
199
Dmitry Shmidt04f534e2013-12-09 15:50:16 -0800200/* Converts nl80211_chan_width to a common format */
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800201enum chan_width convert2width(int width)
Dmitry Shmidt04f534e2013-12-09 15:50:16 -0800202{
203 switch (width) {
204 case NL80211_CHAN_WIDTH_20_NOHT:
205 return CHAN_WIDTH_20_NOHT;
206 case NL80211_CHAN_WIDTH_20:
207 return CHAN_WIDTH_20;
208 case NL80211_CHAN_WIDTH_40:
209 return CHAN_WIDTH_40;
210 case NL80211_CHAN_WIDTH_80:
211 return CHAN_WIDTH_80;
212 case NL80211_CHAN_WIDTH_80P80:
213 return CHAN_WIDTH_80P80;
214 case NL80211_CHAN_WIDTH_160:
215 return CHAN_WIDTH_160;
216 }
217 return CHAN_WIDTH_UNKNOWN;
218}
219
220
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800221int is_ap_interface(enum nl80211_iftype nlmode)
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800222{
Dmitry Shmidt7832adb2014-04-29 10:53:02 -0700223 return nlmode == NL80211_IFTYPE_AP ||
224 nlmode == NL80211_IFTYPE_P2P_GO;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800225}
226
227
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800228int is_sta_interface(enum nl80211_iftype nlmode)
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800229{
Dmitry Shmidt7832adb2014-04-29 10:53:02 -0700230 return nlmode == NL80211_IFTYPE_STATION ||
231 nlmode == NL80211_IFTYPE_P2P_CLIENT;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800232}
233
234
Dmitry Shmidt34af3062013-07-11 10:46:32 -0700235static int is_p2p_net_interface(enum nl80211_iftype nlmode)
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800236{
Dmitry Shmidt7832adb2014-04-29 10:53:02 -0700237 return nlmode == NL80211_IFTYPE_P2P_CLIENT ||
238 nlmode == NL80211_IFTYPE_P2P_GO;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800239}
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700240
241
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800242struct i802_bss * get_bss_ifindex(struct wpa_driver_nl80211_data *drv,
243 int ifindex)
Dmitry Shmidt9ead16e2014-10-07 13:15:23 -0700244{
245 struct i802_bss *bss;
246
247 for (bss = drv->first_bss; bss; bss = bss->next) {
248 if (bss->ifindex == ifindex)
249 return bss;
250 }
251
252 return NULL;
253}
254
255
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800256static int is_mesh_interface(enum nl80211_iftype nlmode)
257{
258 return nlmode == NL80211_IFTYPE_MESH_POINT;
259}
260
261
262void nl80211_mark_disconnected(struct wpa_driver_nl80211_data *drv)
Dmitry Shmidt8bae4132013-06-06 11:25:10 -0700263{
264 if (drv->associated)
265 os_memcpy(drv->prev_bssid, drv->bssid, ETH_ALEN);
266 drv->associated = 0;
267 os_memset(drv->bssid, 0, ETH_ALEN);
268}
269
270
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700271/* nl80211 code */
272static int ack_handler(struct nl_msg *msg, void *arg)
273{
274 int *err = arg;
275 *err = 0;
276 return NL_STOP;
277}
278
279static int finish_handler(struct nl_msg *msg, void *arg)
280{
281 int *ret = arg;
282 *ret = 0;
283 return NL_SKIP;
284}
285
286static int error_handler(struct sockaddr_nl *nla, struct nlmsgerr *err,
287 void *arg)
288{
289 int *ret = arg;
290 *ret = err->error;
291 return NL_SKIP;
292}
293
294
295static int no_seq_check(struct nl_msg *msg, void *arg)
296{
297 return NL_OK;
298}
299
300
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800301static void nl80211_nlmsg_clear(struct nl_msg *msg)
302{
303 /*
304 * Clear nlmsg data, e.g., to make sure key material is not left in
305 * heap memory for unnecessarily long time.
306 */
307 if (msg) {
308 struct nlmsghdr *hdr = nlmsg_hdr(msg);
309 void *data = nlmsg_data(hdr);
310 /*
311 * This would use nlmsg_datalen() or the older nlmsg_len() if
312 * only libnl were to maintain a stable API.. Neither will work
313 * with all released versions, so just calculate the length
314 * here.
315 */
316 int len = hdr->nlmsg_len - NLMSG_HDRLEN;
317
318 os_memset(data, 0, len);
319 }
320}
321
322
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800323static int send_and_recv(struct nl80211_global *global,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700324 struct nl_handle *nl_handle, struct nl_msg *msg,
325 int (*valid_handler)(struct nl_msg *, void *),
326 void *valid_data)
327{
328 struct nl_cb *cb;
329 int err = -ENOMEM;
330
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800331 if (!msg)
332 return -ENOMEM;
333
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800334 cb = nl_cb_clone(global->nl_cb);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700335 if (!cb)
336 goto out;
337
338 err = nl_send_auto_complete(nl_handle, msg);
339 if (err < 0)
340 goto out;
341
342 err = 1;
343
344 nl_cb_err(cb, NL_CB_CUSTOM, error_handler, &err);
345 nl_cb_set(cb, NL_CB_FINISH, NL_CB_CUSTOM, finish_handler, &err);
346 nl_cb_set(cb, NL_CB_ACK, NL_CB_CUSTOM, ack_handler, &err);
347
348 if (valid_handler)
349 nl_cb_set(cb, NL_CB_VALID, NL_CB_CUSTOM,
350 valid_handler, valid_data);
351
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -0700352 while (err > 0) {
353 int res = nl_recvmsgs(nl_handle, cb);
Dmitry Shmidt71757432014-06-02 13:50:35 -0700354 if (res < 0) {
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -0700355 wpa_printf(MSG_INFO,
356 "nl80211: %s->nl_recvmsgs failed: %d",
357 __func__, res);
358 }
359 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700360 out:
361 nl_cb_put(cb);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800362 if (!valid_handler && valid_data == (void *) -1)
363 nl80211_nlmsg_clear(msg);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700364 nlmsg_free(msg);
365 return err;
366}
367
368
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800369int send_and_recv_msgs(struct wpa_driver_nl80211_data *drv,
370 struct nl_msg *msg,
371 int (*valid_handler)(struct nl_msg *, void *),
372 void *valid_data)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700373{
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800374 return send_and_recv(drv->global, drv->global->nl, msg,
375 valid_handler, valid_data);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700376}
377
378
379struct family_data {
380 const char *group;
381 int id;
382};
383
384
385static int family_handler(struct nl_msg *msg, void *arg)
386{
387 struct family_data *res = arg;
388 struct nlattr *tb[CTRL_ATTR_MAX + 1];
389 struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg));
390 struct nlattr *mcgrp;
391 int i;
392
393 nla_parse(tb, CTRL_ATTR_MAX, genlmsg_attrdata(gnlh, 0),
394 genlmsg_attrlen(gnlh, 0), NULL);
395 if (!tb[CTRL_ATTR_MCAST_GROUPS])
396 return NL_SKIP;
397
398 nla_for_each_nested(mcgrp, tb[CTRL_ATTR_MCAST_GROUPS], i) {
399 struct nlattr *tb2[CTRL_ATTR_MCAST_GRP_MAX + 1];
400 nla_parse(tb2, CTRL_ATTR_MCAST_GRP_MAX, nla_data(mcgrp),
401 nla_len(mcgrp), NULL);
402 if (!tb2[CTRL_ATTR_MCAST_GRP_NAME] ||
403 !tb2[CTRL_ATTR_MCAST_GRP_ID] ||
404 os_strncmp(nla_data(tb2[CTRL_ATTR_MCAST_GRP_NAME]),
405 res->group,
406 nla_len(tb2[CTRL_ATTR_MCAST_GRP_NAME])) != 0)
407 continue;
408 res->id = nla_get_u32(tb2[CTRL_ATTR_MCAST_GRP_ID]);
409 break;
410 };
411
412 return NL_SKIP;
413}
414
415
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800416static int nl_get_multicast_id(struct nl80211_global *global,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700417 const char *family, const char *group)
418{
419 struct nl_msg *msg;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800420 int ret;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700421 struct family_data res = { group, -ENOENT };
422
423 msg = nlmsg_alloc();
424 if (!msg)
425 return -ENOMEM;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800426 if (!genlmsg_put(msg, 0, 0, genl_ctrl_resolve(global->nl, "nlctrl"),
427 0, 0, CTRL_CMD_GETFAMILY, 0) ||
428 nla_put_string(msg, CTRL_ATTR_FAMILY_NAME, family)) {
429 nlmsg_free(msg);
430 return -1;
431 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700432
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800433 ret = send_and_recv(global, global->nl, msg, family_handler, &res);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700434 if (ret == 0)
435 ret = res.id;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700436 return ret;
437}
438
439
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800440void * nl80211_cmd(struct wpa_driver_nl80211_data *drv,
441 struct nl_msg *msg, int flags, uint8_t cmd)
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800442{
443 return genlmsg_put(msg, 0, 0, drv->global->nl80211_id,
444 0, flags, cmd, 0);
445}
446
447
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800448static int nl80211_set_iface_id(struct nl_msg *msg, struct i802_bss *bss)
449{
450 if (bss->wdev_id_set)
451 return nla_put_u64(msg, NL80211_ATTR_WDEV, bss->wdev_id);
452 return nla_put_u32(msg, NL80211_ATTR_IFINDEX, bss->ifindex);
453}
454
455
456struct nl_msg * nl80211_cmd_msg(struct i802_bss *bss, int flags, uint8_t cmd)
457{
458 struct nl_msg *msg;
459
460 msg = nlmsg_alloc();
461 if (!msg)
462 return NULL;
463
464 if (!nl80211_cmd(bss->drv, msg, flags, cmd) ||
465 nl80211_set_iface_id(msg, bss) < 0) {
466 nlmsg_free(msg);
467 return NULL;
468 }
469
470 return msg;
471}
472
473
474static struct nl_msg *
475nl80211_ifindex_msg(struct wpa_driver_nl80211_data *drv, int ifindex,
476 int flags, uint8_t cmd)
477{
478 struct nl_msg *msg;
479
480 msg = nlmsg_alloc();
481 if (!msg)
482 return NULL;
483
484 if (!nl80211_cmd(drv, msg, flags, cmd) ||
485 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex)) {
486 nlmsg_free(msg);
487 return NULL;
488 }
489
490 return msg;
491}
492
493
494struct nl_msg * nl80211_drv_msg(struct wpa_driver_nl80211_data *drv, int flags,
495 uint8_t cmd)
496{
497 return nl80211_ifindex_msg(drv, drv->ifindex, flags, cmd);
498}
499
500
501struct nl_msg * nl80211_bss_msg(struct i802_bss *bss, int flags, uint8_t cmd)
502{
503 return nl80211_ifindex_msg(bss->drv, bss->ifindex, flags, cmd);
504}
505
506
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800507struct wiphy_idx_data {
508 int wiphy_idx;
Dmitry Shmidt34af3062013-07-11 10:46:32 -0700509 enum nl80211_iftype nlmode;
510 u8 *macaddr;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800511};
512
513
514static int netdev_info_handler(struct nl_msg *msg, void *arg)
515{
516 struct nlattr *tb[NL80211_ATTR_MAX + 1];
517 struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg));
518 struct wiphy_idx_data *info = arg;
519
520 nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0),
521 genlmsg_attrlen(gnlh, 0), NULL);
522
523 if (tb[NL80211_ATTR_WIPHY])
524 info->wiphy_idx = nla_get_u32(tb[NL80211_ATTR_WIPHY]);
525
Dmitry Shmidt34af3062013-07-11 10:46:32 -0700526 if (tb[NL80211_ATTR_IFTYPE])
527 info->nlmode = nla_get_u32(tb[NL80211_ATTR_IFTYPE]);
528
529 if (tb[NL80211_ATTR_MAC] && info->macaddr)
530 os_memcpy(info->macaddr, nla_data(tb[NL80211_ATTR_MAC]),
531 ETH_ALEN);
532
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800533 return NL_SKIP;
534}
535
536
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800537int nl80211_get_wiphy_index(struct i802_bss *bss)
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800538{
539 struct nl_msg *msg;
540 struct wiphy_idx_data data = {
541 .wiphy_idx = -1,
Dmitry Shmidt34af3062013-07-11 10:46:32 -0700542 .macaddr = NULL,
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800543 };
544
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800545 if (!(msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_GET_INTERFACE)))
546 return -1;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800547
548 if (send_and_recv_msgs(bss->drv, msg, netdev_info_handler, &data) == 0)
549 return data.wiphy_idx;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800550 return -1;
551}
552
553
Dmitry Shmidt34af3062013-07-11 10:46:32 -0700554static enum nl80211_iftype nl80211_get_ifmode(struct i802_bss *bss)
555{
556 struct nl_msg *msg;
557 struct wiphy_idx_data data = {
558 .nlmode = NL80211_IFTYPE_UNSPECIFIED,
559 .macaddr = NULL,
560 };
561
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800562 if (!(msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_GET_INTERFACE)))
563 return NL80211_IFTYPE_UNSPECIFIED;
Dmitry Shmidt34af3062013-07-11 10:46:32 -0700564
565 if (send_and_recv_msgs(bss->drv, msg, netdev_info_handler, &data) == 0)
566 return data.nlmode;
Dmitry Shmidt34af3062013-07-11 10:46:32 -0700567 return NL80211_IFTYPE_UNSPECIFIED;
568}
569
570
Dmitry Shmidt34af3062013-07-11 10:46:32 -0700571static int nl80211_get_macaddr(struct i802_bss *bss)
572{
573 struct nl_msg *msg;
574 struct wiphy_idx_data data = {
575 .macaddr = bss->addr,
576 };
577
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800578 if (!(msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_GET_INTERFACE)))
579 return -1;
Dmitry Shmidt34af3062013-07-11 10:46:32 -0700580
581 return send_and_recv_msgs(bss->drv, msg, netdev_info_handler, &data);
Dmitry Shmidt34af3062013-07-11 10:46:32 -0700582}
Dmitry Shmidt34af3062013-07-11 10:46:32 -0700583
584
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800585static int nl80211_register_beacons(struct wpa_driver_nl80211_data *drv,
586 struct nl80211_wiphy_data *w)
587{
588 struct nl_msg *msg;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800589 int ret;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800590
591 msg = nlmsg_alloc();
592 if (!msg)
593 return -1;
594
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800595 if (!nl80211_cmd(drv, msg, 0, NL80211_CMD_REGISTER_BEACONS) ||
596 nla_put_u32(msg, NL80211_ATTR_WIPHY, w->wiphy_idx)) {
597 nlmsg_free(msg);
598 return -1;
599 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800600
601 ret = send_and_recv(drv->global, w->nl_beacons, msg, NULL, NULL);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800602 if (ret) {
603 wpa_printf(MSG_DEBUG, "nl80211: Register beacons command "
604 "failed: ret=%d (%s)",
605 ret, strerror(-ret));
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800606 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800607 return ret;
608}
609
610
611static void nl80211_recv_beacons(int sock, void *eloop_ctx, void *handle)
612{
613 struct nl80211_wiphy_data *w = eloop_ctx;
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -0700614 int res;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800615
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -0800616 wpa_printf(MSG_EXCESSIVE, "nl80211: Beacon event message available");
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800617
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -0700618 res = nl_recvmsgs(handle, w->nl_cb);
Dmitry Shmidt71757432014-06-02 13:50:35 -0700619 if (res < 0) {
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -0700620 wpa_printf(MSG_INFO, "nl80211: %s->nl_recvmsgs failed: %d",
621 __func__, res);
622 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800623}
624
625
626static int process_beacon_event(struct nl_msg *msg, void *arg)
627{
628 struct nl80211_wiphy_data *w = arg;
629 struct wpa_driver_nl80211_data *drv;
630 struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg));
631 struct nlattr *tb[NL80211_ATTR_MAX + 1];
632 union wpa_event_data event;
633
634 nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0),
635 genlmsg_attrlen(gnlh, 0), NULL);
636
637 if (gnlh->cmd != NL80211_CMD_FRAME) {
638 wpa_printf(MSG_DEBUG, "nl80211: Unexpected beacon event? (%d)",
639 gnlh->cmd);
640 return NL_SKIP;
641 }
642
643 if (!tb[NL80211_ATTR_FRAME])
644 return NL_SKIP;
645
646 dl_list_for_each(drv, &w->drvs, struct wpa_driver_nl80211_data,
647 wiphy_list) {
648 os_memset(&event, 0, sizeof(event));
649 event.rx_mgmt.frame = nla_data(tb[NL80211_ATTR_FRAME]);
650 event.rx_mgmt.frame_len = nla_len(tb[NL80211_ATTR_FRAME]);
651 wpa_supplicant_event(drv->ctx, EVENT_RX_MGMT, &event);
652 }
653
654 return NL_SKIP;
655}
656
657
658static struct nl80211_wiphy_data *
659nl80211_get_wiphy_data_ap(struct i802_bss *bss)
660{
661 static DEFINE_DL_LIST(nl80211_wiphys);
662 struct nl80211_wiphy_data *w;
663 int wiphy_idx, found = 0;
664 struct i802_bss *tmp_bss;
665
666 if (bss->wiphy_data != NULL)
667 return bss->wiphy_data;
668
669 wiphy_idx = nl80211_get_wiphy_index(bss);
670
671 dl_list_for_each(w, &nl80211_wiphys, struct nl80211_wiphy_data, list) {
672 if (w->wiphy_idx == wiphy_idx)
673 goto add;
674 }
675
676 /* alloc new one */
677 w = os_zalloc(sizeof(*w));
678 if (w == NULL)
679 return NULL;
680 w->wiphy_idx = wiphy_idx;
681 dl_list_init(&w->bsss);
682 dl_list_init(&w->drvs);
683
684 w->nl_cb = nl_cb_alloc(NL_CB_DEFAULT);
685 if (!w->nl_cb) {
686 os_free(w);
687 return NULL;
688 }
689 nl_cb_set(w->nl_cb, NL_CB_SEQ_CHECK, NL_CB_CUSTOM, no_seq_check, NULL);
690 nl_cb_set(w->nl_cb, NL_CB_VALID, NL_CB_CUSTOM, process_beacon_event,
691 w);
692
693 w->nl_beacons = nl_create_handle(bss->drv->global->nl_cb,
694 "wiphy beacons");
695 if (w->nl_beacons == NULL) {
696 os_free(w);
697 return NULL;
698 }
699
700 if (nl80211_register_beacons(bss->drv, w)) {
701 nl_destroy_handles(&w->nl_beacons);
702 os_free(w);
703 return NULL;
704 }
705
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -0700706 nl80211_register_eloop_read(&w->nl_beacons, nl80211_recv_beacons, w);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800707
708 dl_list_add(&nl80211_wiphys, &w->list);
709
710add:
711 /* drv entry for this bss already there? */
712 dl_list_for_each(tmp_bss, &w->bsss, struct i802_bss, wiphy_list) {
713 if (tmp_bss->drv == bss->drv) {
714 found = 1;
715 break;
716 }
717 }
718 /* if not add it */
719 if (!found)
720 dl_list_add(&w->drvs, &bss->drv->wiphy_list);
721
722 dl_list_add(&w->bsss, &bss->wiphy_list);
723 bss->wiphy_data = w;
724 return w;
725}
726
727
728static void nl80211_put_wiphy_data_ap(struct i802_bss *bss)
729{
730 struct nl80211_wiphy_data *w = bss->wiphy_data;
731 struct i802_bss *tmp_bss;
732 int found = 0;
733
734 if (w == NULL)
735 return;
736 bss->wiphy_data = NULL;
737 dl_list_del(&bss->wiphy_list);
738
739 /* still any for this drv present? */
740 dl_list_for_each(tmp_bss, &w->bsss, struct i802_bss, wiphy_list) {
741 if (tmp_bss->drv == bss->drv) {
742 found = 1;
743 break;
744 }
745 }
746 /* if not remove it */
747 if (!found)
748 dl_list_del(&bss->drv->wiphy_list);
749
750 if (!dl_list_empty(&w->bsss))
751 return;
752
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -0700753 nl80211_destroy_eloop_handle(&w->nl_beacons);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800754
755 nl_cb_put(w->nl_cb);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800756 dl_list_del(&w->list);
757 os_free(w);
758}
759
760
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700761static int wpa_driver_nl80211_get_bssid(void *priv, u8 *bssid)
762{
763 struct i802_bss *bss = priv;
764 struct wpa_driver_nl80211_data *drv = bss->drv;
765 if (!drv->associated)
766 return -1;
767 os_memcpy(bssid, drv->bssid, ETH_ALEN);
768 return 0;
769}
770
771
772static int wpa_driver_nl80211_get_ssid(void *priv, u8 *ssid)
773{
774 struct i802_bss *bss = priv;
775 struct wpa_driver_nl80211_data *drv = bss->drv;
776 if (!drv->associated)
777 return -1;
778 os_memcpy(ssid, drv->ssid, drv->ssid_len);
779 return drv->ssid_len;
780}
781
782
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800783static void wpa_driver_nl80211_event_newlink(
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800784 struct wpa_driver_nl80211_data *drv, const char *ifname)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700785{
786 union wpa_event_data event;
787
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800788 if (os_strcmp(drv->first_bss->ifname, ifname) == 0) {
789 if (if_nametoindex(drv->first_bss->ifname) == 0) {
790 wpa_printf(MSG_DEBUG, "nl80211: Interface %s does not exist - ignore RTM_NEWLINK",
791 drv->first_bss->ifname);
792 return;
Dmitry Shmidt04949592012-07-19 12:16:46 -0700793 }
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800794 if (!drv->if_removed)
795 return;
796 wpa_printf(MSG_DEBUG, "nl80211: Mark if_removed=0 for %s based on RTM_NEWLINK event",
797 drv->first_bss->ifname);
798 drv->if_removed = 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700799 }
800
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800801 os_memset(&event, 0, sizeof(event));
802 os_strlcpy(event.interface_status.ifname, ifname,
803 sizeof(event.interface_status.ifname));
804 event.interface_status.ievent = EVENT_INTERFACE_ADDED;
805 wpa_supplicant_event(drv->ctx, EVENT_INTERFACE_STATUS, &event);
806}
807
808
809static void wpa_driver_nl80211_event_dellink(
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800810 struct wpa_driver_nl80211_data *drv, const char *ifname)
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800811{
812 union wpa_event_data event;
813
814 if (os_strcmp(drv->first_bss->ifname, ifname) == 0) {
815 if (drv->if_removed) {
816 wpa_printf(MSG_DEBUG, "nl80211: if_removed already set - ignore RTM_DELLINK event for %s",
817 ifname);
818 return;
819 }
820 wpa_printf(MSG_DEBUG, "RTM_DELLINK: Interface '%s' removed - mark if_removed=1",
821 ifname);
822 drv->if_removed = 1;
823 } else {
824 wpa_printf(MSG_DEBUG, "RTM_DELLINK: Interface '%s' removed",
825 ifname);
826 }
827
828 os_memset(&event, 0, sizeof(event));
829 os_strlcpy(event.interface_status.ifname, ifname,
830 sizeof(event.interface_status.ifname));
831 event.interface_status.ievent = EVENT_INTERFACE_REMOVED;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700832 wpa_supplicant_event(drv->ctx, EVENT_INTERFACE_STATUS, &event);
833}
834
835
836static int wpa_driver_nl80211_own_ifname(struct wpa_driver_nl80211_data *drv,
837 u8 *buf, size_t len)
838{
839 int attrlen, rta_len;
840 struct rtattr *attr;
841
842 attrlen = len;
843 attr = (struct rtattr *) buf;
844
845 rta_len = RTA_ALIGN(sizeof(struct rtattr));
846 while (RTA_OK(attr, attrlen)) {
847 if (attr->rta_type == IFLA_IFNAME) {
Dmitry Shmidtcce06662013-11-04 18:44:24 -0800848 if (os_strcmp(((char *) attr) + rta_len,
849 drv->first_bss->ifname) == 0)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700850 return 1;
851 else
852 break;
853 }
854 attr = RTA_NEXT(attr, attrlen);
855 }
856
857 return 0;
858}
859
860
861static int wpa_driver_nl80211_own_ifindex(struct wpa_driver_nl80211_data *drv,
862 int ifindex, u8 *buf, size_t len)
863{
864 if (drv->ifindex == ifindex)
865 return 1;
866
867 if (drv->if_removed && wpa_driver_nl80211_own_ifname(drv, buf, len)) {
Dmitry Shmidt7f656022015-02-25 14:36:37 -0800868 nl80211_check_global(drv->global);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700869 wpa_printf(MSG_DEBUG, "nl80211: Update ifindex for a removed "
870 "interface");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800871 wpa_driver_nl80211_finish_drv_init(drv, NULL, 0, NULL);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700872 return 1;
873 }
874
875 return 0;
876}
877
878
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800879static struct wpa_driver_nl80211_data *
880nl80211_find_drv(struct nl80211_global *global, int idx, u8 *buf, size_t len)
881{
882 struct wpa_driver_nl80211_data *drv;
883 dl_list_for_each(drv, &global->interfaces,
884 struct wpa_driver_nl80211_data, list) {
885 if (wpa_driver_nl80211_own_ifindex(drv, idx, buf, len) ||
886 have_ifidx(drv, idx))
887 return drv;
888 }
889 return NULL;
890}
891
892
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700893static void wpa_driver_nl80211_event_rtm_newlink(void *ctx,
894 struct ifinfomsg *ifi,
895 u8 *buf, size_t len)
896{
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800897 struct nl80211_global *global = ctx;
898 struct wpa_driver_nl80211_data *drv;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800899 int attrlen;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700900 struct rtattr *attr;
901 u32 brid = 0;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800902 char namebuf[IFNAMSIZ];
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800903 char ifname[IFNAMSIZ + 1];
904 char extra[100], *pos, *end;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700905
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800906 drv = nl80211_find_drv(global, ifi->ifi_index, buf, len);
907 if (!drv) {
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800908 wpa_printf(MSG_DEBUG, "nl80211: Ignore RTM_NEWLINK event for foreign ifindex %d",
909 ifi->ifi_index);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700910 return;
911 }
912
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800913 extra[0] = '\0';
914 pos = extra;
915 end = pos + sizeof(extra);
916 ifname[0] = '\0';
917
918 attrlen = len;
919 attr = (struct rtattr *) buf;
920 while (RTA_OK(attr, attrlen)) {
921 switch (attr->rta_type) {
922 case IFLA_IFNAME:
923 if (RTA_PAYLOAD(attr) >= IFNAMSIZ)
924 break;
925 os_memcpy(ifname, RTA_DATA(attr), RTA_PAYLOAD(attr));
926 ifname[RTA_PAYLOAD(attr)] = '\0';
927 break;
928 case IFLA_MASTER:
929 brid = nla_get_u32((struct nlattr *) attr);
930 pos += os_snprintf(pos, end - pos, " master=%u", brid);
931 break;
932 case IFLA_WIRELESS:
933 pos += os_snprintf(pos, end - pos, " wext");
934 break;
935 case IFLA_OPERSTATE:
936 pos += os_snprintf(pos, end - pos, " operstate=%u",
937 nla_get_u32((struct nlattr *) attr));
938 break;
939 case IFLA_LINKMODE:
940 pos += os_snprintf(pos, end - pos, " linkmode=%u",
941 nla_get_u32((struct nlattr *) attr));
942 break;
943 }
944 attr = RTA_NEXT(attr, attrlen);
945 }
946 extra[sizeof(extra) - 1] = '\0';
947
Dmitry Shmidt661b4f72014-09-29 14:58:27 -0700948 wpa_printf(MSG_DEBUG, "RTM_NEWLINK: ifi_index=%d ifname=%s%s ifi_family=%d ifi_flags=0x%x (%s%s%s%s)",
949 ifi->ifi_index, ifname, extra, ifi->ifi_family,
950 ifi->ifi_flags,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700951 (ifi->ifi_flags & IFF_UP) ? "[UP]" : "",
952 (ifi->ifi_flags & IFF_RUNNING) ? "[RUNNING]" : "",
953 (ifi->ifi_flags & IFF_LOWER_UP) ? "[LOWER_UP]" : "",
954 (ifi->ifi_flags & IFF_DORMANT) ? "[DORMANT]" : "");
955
956 if (!drv->if_disabled && !(ifi->ifi_flags & IFF_UP)) {
Dmitry Shmidt7f656022015-02-25 14:36:37 -0800957 namebuf[0] = '\0';
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800958 if (if_indextoname(ifi->ifi_index, namebuf) &&
Dmitry Shmidt7f656022015-02-25 14:36:37 -0800959 linux_iface_up(drv->global->ioctl_sock, namebuf) > 0) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800960 wpa_printf(MSG_DEBUG, "nl80211: Ignore interface down "
961 "event since interface %s is up", namebuf);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800962 drv->ignore_if_down_event = 0;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800963 return;
964 }
Dmitry Shmidt7f656022015-02-25 14:36:37 -0800965 wpa_printf(MSG_DEBUG, "nl80211: Interface down (%s/%s)",
966 namebuf, ifname);
967 if (os_strcmp(drv->first_bss->ifname, ifname) != 0) {
968 wpa_printf(MSG_DEBUG,
969 "nl80211: Not the main interface (%s) - do not indicate interface down",
970 drv->first_bss->ifname);
971 } else if (drv->ignore_if_down_event) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800972 wpa_printf(MSG_DEBUG, "nl80211: Ignore interface down "
973 "event generated by mode change");
974 drv->ignore_if_down_event = 0;
975 } else {
976 drv->if_disabled = 1;
977 wpa_supplicant_event(drv->ctx,
978 EVENT_INTERFACE_DISABLED, NULL);
Dmitry Shmidta38abf92014-03-06 13:38:44 -0800979
980 /*
981 * Try to get drv again, since it may be removed as
982 * part of the EVENT_INTERFACE_DISABLED handling for
983 * dynamic interfaces
984 */
985 drv = nl80211_find_drv(global, ifi->ifi_index,
986 buf, len);
987 if (!drv)
988 return;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800989 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700990 }
991
992 if (drv->if_disabled && (ifi->ifi_flags & IFF_UP)) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800993 if (if_indextoname(ifi->ifi_index, namebuf) &&
Dmitry Shmidt7f656022015-02-25 14:36:37 -0800994 linux_iface_up(drv->global->ioctl_sock, namebuf) == 0) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800995 wpa_printf(MSG_DEBUG, "nl80211: Ignore interface up "
996 "event since interface %s is down",
997 namebuf);
Dmitry Shmidtcce06662013-11-04 18:44:24 -0800998 } else if (if_nametoindex(drv->first_bss->ifname) == 0) {
Dmitry Shmidt04949592012-07-19 12:16:46 -0700999 wpa_printf(MSG_DEBUG, "nl80211: Ignore interface up "
1000 "event since interface %s does not exist",
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001001 drv->first_bss->ifname);
Dmitry Shmidt04949592012-07-19 12:16:46 -07001002 } else if (drv->if_removed) {
1003 wpa_printf(MSG_DEBUG, "nl80211: Ignore interface up "
1004 "event since interface %s is marked "
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001005 "removed", drv->first_bss->ifname);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001006 } else {
Dmitry Shmidt9ead16e2014-10-07 13:15:23 -07001007 struct i802_bss *bss;
1008 u8 addr[ETH_ALEN];
1009
1010 /* Re-read MAC address as it may have changed */
1011 bss = get_bss_ifindex(drv, ifi->ifi_index);
1012 if (bss &&
1013 linux_get_ifhwaddr(drv->global->ioctl_sock,
1014 bss->ifname, addr) < 0) {
1015 wpa_printf(MSG_DEBUG,
1016 "nl80211: %s: failed to re-read MAC address",
1017 bss->ifname);
1018 } else if (bss &&
1019 os_memcmp(addr, bss->addr, ETH_ALEN) != 0) {
1020 wpa_printf(MSG_DEBUG,
1021 "nl80211: Own MAC address on ifindex %d (%s) changed from "
1022 MACSTR " to " MACSTR,
1023 ifi->ifi_index, bss->ifname,
1024 MAC2STR(bss->addr),
1025 MAC2STR(addr));
1026 os_memcpy(bss->addr, addr, ETH_ALEN);
1027 }
1028
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001029 wpa_printf(MSG_DEBUG, "nl80211: Interface up");
1030 drv->if_disabled = 0;
1031 wpa_supplicant_event(drv->ctx, EVENT_INTERFACE_ENABLED,
1032 NULL);
1033 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001034 }
1035
1036 /*
1037 * Some drivers send the association event before the operup event--in
1038 * this case, lifting operstate in wpa_driver_nl80211_set_operstate()
1039 * fails. This will hit us when wpa_supplicant does not need to do
1040 * IEEE 802.1X authentication
1041 */
1042 if (drv->operstate == 1 &&
1043 (ifi->ifi_flags & (IFF_LOWER_UP | IFF_DORMANT)) == IFF_LOWER_UP &&
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001044 !(ifi->ifi_flags & IFF_RUNNING)) {
1045 wpa_printf(MSG_DEBUG, "nl80211: Set IF_OPER_UP again based on ifi_flags and expected operstate");
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001046 netlink_send_oper_ifla(drv->global->netlink, drv->ifindex,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001047 -1, IF_OPER_UP);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001048 }
1049
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001050 if (ifname[0])
1051 wpa_driver_nl80211_event_newlink(drv, ifname);
1052
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001053 if (ifi->ifi_family == AF_BRIDGE && brid) {
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001054 struct i802_bss *bss;
1055
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001056 /* device has been added to bridge */
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001057 if (!if_indextoname(brid, namebuf)) {
1058 wpa_printf(MSG_DEBUG,
1059 "nl80211: Could not find bridge ifname for ifindex %u",
1060 brid);
1061 return;
1062 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001063 wpa_printf(MSG_DEBUG, "nl80211: Add ifindex %u for bridge %s",
1064 brid, namebuf);
1065 add_ifidx(drv, brid);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001066
1067 for (bss = drv->first_bss; bss; bss = bss->next) {
1068 if (os_strcmp(ifname, bss->ifname) == 0) {
1069 os_strlcpy(bss->brname, namebuf, IFNAMSIZ);
1070 break;
1071 }
1072 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001073 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001074}
1075
1076
1077static void wpa_driver_nl80211_event_rtm_dellink(void *ctx,
1078 struct ifinfomsg *ifi,
1079 u8 *buf, size_t len)
1080{
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001081 struct nl80211_global *global = ctx;
1082 struct wpa_driver_nl80211_data *drv;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001083 int attrlen;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001084 struct rtattr *attr;
1085 u32 brid = 0;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001086 char ifname[IFNAMSIZ + 1];
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07001087 char extra[100], *pos, *end;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001088
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001089 drv = nl80211_find_drv(global, ifi->ifi_index, buf, len);
1090 if (!drv) {
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001091 wpa_printf(MSG_DEBUG, "nl80211: Ignore RTM_DELLINK event for foreign ifindex %d",
1092 ifi->ifi_index);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001093 return;
1094 }
1095
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07001096 extra[0] = '\0';
1097 pos = extra;
1098 end = pos + sizeof(extra);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001099 ifname[0] = '\0';
1100
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001101 attrlen = len;
1102 attr = (struct rtattr *) buf;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001103 while (RTA_OK(attr, attrlen)) {
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001104 switch (attr->rta_type) {
1105 case IFLA_IFNAME:
1106 if (RTA_PAYLOAD(attr) >= IFNAMSIZ)
1107 break;
1108 os_memcpy(ifname, RTA_DATA(attr), RTA_PAYLOAD(attr));
1109 ifname[RTA_PAYLOAD(attr)] = '\0';
1110 break;
1111 case IFLA_MASTER:
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001112 brid = nla_get_u32((struct nlattr *) attr);
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07001113 pos += os_snprintf(pos, end - pos, " master=%u", brid);
1114 break;
1115 case IFLA_OPERSTATE:
1116 pos += os_snprintf(pos, end - pos, " operstate=%u",
1117 nla_get_u32((struct nlattr *) attr));
1118 break;
1119 case IFLA_LINKMODE:
1120 pos += os_snprintf(pos, end - pos, " linkmode=%u",
1121 nla_get_u32((struct nlattr *) attr));
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001122 break;
1123 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001124 attr = RTA_NEXT(attr, attrlen);
1125 }
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07001126 extra[sizeof(extra) - 1] = '\0';
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001127
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07001128 wpa_printf(MSG_DEBUG, "RTM_DELLINK: ifi_index=%d ifname=%s%s ifi_family=%d ifi_flags=0x%x (%s%s%s%s)",
1129 ifi->ifi_index, ifname, extra, ifi->ifi_family,
1130 ifi->ifi_flags,
1131 (ifi->ifi_flags & IFF_UP) ? "[UP]" : "",
1132 (ifi->ifi_flags & IFF_RUNNING) ? "[RUNNING]" : "",
1133 (ifi->ifi_flags & IFF_LOWER_UP) ? "[LOWER_UP]" : "",
1134 (ifi->ifi_flags & IFF_DORMANT) ? "[DORMANT]" : "");
1135
1136 if (ifname[0] && (ifi->ifi_family != AF_BRIDGE || !brid))
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001137 wpa_driver_nl80211_event_dellink(drv, ifname);
1138
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001139 if (ifi->ifi_family == AF_BRIDGE && brid) {
1140 /* device has been removed from bridge */
1141 char namebuf[IFNAMSIZ];
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001142
1143 if (!if_indextoname(brid, namebuf)) {
1144 wpa_printf(MSG_DEBUG,
1145 "nl80211: Could not find bridge ifname for ifindex %u",
1146 brid);
1147 } else {
1148 wpa_printf(MSG_DEBUG,
1149 "nl80211: Remove ifindex %u for bridge %s",
1150 brid, namebuf);
1151 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001152 del_ifidx(drv, brid);
1153 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001154}
1155
1156
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001157unsigned int nl80211_get_assoc_freq(struct wpa_driver_nl80211_data *drv)
Jouni Malinen87fd2792011-05-16 18:35:42 +03001158{
1159 struct nl_msg *msg;
1160 int ret;
1161 struct nl80211_bss_info_arg arg;
1162
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001163 msg = nl80211_drv_msg(drv, NLM_F_DUMP, NL80211_CMD_GET_SCAN);
Jouni Malinen87fd2792011-05-16 18:35:42 +03001164 os_memset(&arg, 0, sizeof(arg));
Jouni Malinen87fd2792011-05-16 18:35:42 +03001165 arg.drv = drv;
1166 ret = send_and_recv_msgs(drv, msg, bss_info_handler, &arg);
Jouni Malinen87fd2792011-05-16 18:35:42 +03001167 if (ret == 0) {
Dmitry Shmidt6dc03bd2014-05-16 10:40:13 -07001168 unsigned int freq = drv->nlmode == NL80211_IFTYPE_ADHOC ?
1169 arg.ibss_freq : arg.assoc_freq;
Jouni Malinen87fd2792011-05-16 18:35:42 +03001170 wpa_printf(MSG_DEBUG, "nl80211: Operating frequency for the "
Dmitry Shmidt6dc03bd2014-05-16 10:40:13 -07001171 "associated BSS from scan results: %u MHz", freq);
1172 if (freq)
1173 drv->assoc_freq = freq;
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -07001174 return drv->assoc_freq;
Jouni Malinen87fd2792011-05-16 18:35:42 +03001175 }
1176 wpa_printf(MSG_DEBUG, "nl80211: Scan result fetch failed: ret=%d "
1177 "(%s)", ret, strerror(-ret));
Jouni Malinen87fd2792011-05-16 18:35:42 +03001178 return drv->assoc_freq;
1179}
1180
1181
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001182static int get_link_signal(struct nl_msg *msg, void *arg)
1183{
1184 struct nlattr *tb[NL80211_ATTR_MAX + 1];
1185 struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg));
1186 struct nlattr *sinfo[NL80211_STA_INFO_MAX + 1];
1187 static struct nla_policy policy[NL80211_STA_INFO_MAX + 1] = {
1188 [NL80211_STA_INFO_SIGNAL] = { .type = NLA_U8 },
Dmitry Shmidt34af3062013-07-11 10:46:32 -07001189 [NL80211_STA_INFO_SIGNAL_AVG] = { .type = NLA_U8 },
Dmitry Shmidtf73259c2015-03-17 11:00:54 -07001190 [NL80211_STA_INFO_BEACON_SIGNAL_AVG] = { .type = NLA_U8 },
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001191 };
1192 struct nlattr *rinfo[NL80211_RATE_INFO_MAX + 1];
1193 static struct nla_policy rate_policy[NL80211_RATE_INFO_MAX + 1] = {
1194 [NL80211_RATE_INFO_BITRATE] = { .type = NLA_U16 },
1195 [NL80211_RATE_INFO_MCS] = { .type = NLA_U8 },
1196 [NL80211_RATE_INFO_40_MHZ_WIDTH] = { .type = NLA_FLAG },
1197 [NL80211_RATE_INFO_SHORT_GI] = { .type = NLA_FLAG },
1198 };
1199 struct wpa_signal_info *sig_change = arg;
1200
1201 nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0),
1202 genlmsg_attrlen(gnlh, 0), NULL);
1203 if (!tb[NL80211_ATTR_STA_INFO] ||
1204 nla_parse_nested(sinfo, NL80211_STA_INFO_MAX,
1205 tb[NL80211_ATTR_STA_INFO], policy))
1206 return NL_SKIP;
1207 if (!sinfo[NL80211_STA_INFO_SIGNAL])
1208 return NL_SKIP;
1209
1210 sig_change->current_signal =
1211 (s8) nla_get_u8(sinfo[NL80211_STA_INFO_SIGNAL]);
1212
Dmitry Shmidt34af3062013-07-11 10:46:32 -07001213 if (sinfo[NL80211_STA_INFO_SIGNAL_AVG])
1214 sig_change->avg_signal =
1215 (s8) nla_get_u8(sinfo[NL80211_STA_INFO_SIGNAL_AVG]);
1216 else
1217 sig_change->avg_signal = 0;
1218
Dmitry Shmidtf73259c2015-03-17 11:00:54 -07001219 if (sinfo[NL80211_STA_INFO_BEACON_SIGNAL_AVG])
1220 sig_change->avg_beacon_signal =
1221 (s8)
1222 nla_get_u8(sinfo[NL80211_STA_INFO_BEACON_SIGNAL_AVG]);
1223 else
1224 sig_change->avg_beacon_signal = 0;
1225
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001226 if (sinfo[NL80211_STA_INFO_TX_BITRATE]) {
1227 if (nla_parse_nested(rinfo, NL80211_RATE_INFO_MAX,
1228 sinfo[NL80211_STA_INFO_TX_BITRATE],
1229 rate_policy)) {
1230 sig_change->current_txrate = 0;
1231 } else {
1232 if (rinfo[NL80211_RATE_INFO_BITRATE]) {
1233 sig_change->current_txrate =
1234 nla_get_u16(rinfo[
1235 NL80211_RATE_INFO_BITRATE]) * 100;
1236 }
1237 }
1238 }
1239
1240 return NL_SKIP;
1241}
1242
1243
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001244int nl80211_get_link_signal(struct wpa_driver_nl80211_data *drv,
1245 struct wpa_signal_info *sig)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001246{
1247 struct nl_msg *msg;
1248
1249 sig->current_signal = -9999;
1250 sig->current_txrate = 0;
1251
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001252 if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_GET_STATION)) ||
1253 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, drv->bssid)) {
1254 nlmsg_free(msg);
1255 return -ENOBUFS;
1256 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001257
1258 return send_and_recv_msgs(drv, msg, get_link_signal, sig);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001259}
1260
1261
1262static int get_link_noise(struct nl_msg *msg, void *arg)
1263{
1264 struct nlattr *tb[NL80211_ATTR_MAX + 1];
1265 struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg));
1266 struct nlattr *sinfo[NL80211_SURVEY_INFO_MAX + 1];
1267 static struct nla_policy survey_policy[NL80211_SURVEY_INFO_MAX + 1] = {
1268 [NL80211_SURVEY_INFO_FREQUENCY] = { .type = NLA_U32 },
1269 [NL80211_SURVEY_INFO_NOISE] = { .type = NLA_U8 },
1270 };
1271 struct wpa_signal_info *sig_change = arg;
1272
1273 nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0),
1274 genlmsg_attrlen(gnlh, 0), NULL);
1275
1276 if (!tb[NL80211_ATTR_SURVEY_INFO]) {
1277 wpa_printf(MSG_DEBUG, "nl80211: survey data missing!");
1278 return NL_SKIP;
1279 }
1280
1281 if (nla_parse_nested(sinfo, NL80211_SURVEY_INFO_MAX,
1282 tb[NL80211_ATTR_SURVEY_INFO],
1283 survey_policy)) {
1284 wpa_printf(MSG_DEBUG, "nl80211: failed to parse nested "
1285 "attributes!");
1286 return NL_SKIP;
1287 }
1288
1289 if (!sinfo[NL80211_SURVEY_INFO_FREQUENCY])
1290 return NL_SKIP;
1291
1292 if (nla_get_u32(sinfo[NL80211_SURVEY_INFO_FREQUENCY]) !=
1293 sig_change->frequency)
1294 return NL_SKIP;
1295
1296 if (!sinfo[NL80211_SURVEY_INFO_NOISE])
1297 return NL_SKIP;
1298
1299 sig_change->current_noise =
1300 (s8) nla_get_u8(sinfo[NL80211_SURVEY_INFO_NOISE]);
1301
1302 return NL_SKIP;
1303}
1304
1305
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001306int nl80211_get_link_noise(struct wpa_driver_nl80211_data *drv,
1307 struct wpa_signal_info *sig_change)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001308{
1309 struct nl_msg *msg;
1310
1311 sig_change->current_noise = 9999;
1312 sig_change->frequency = drv->assoc_freq;
1313
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001314 msg = nl80211_drv_msg(drv, NLM_F_DUMP, NL80211_CMD_GET_SURVEY);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001315 return send_and_recv_msgs(drv, msg, get_link_noise, sig_change);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001316}
1317
1318
1319static void wpa_driver_nl80211_event_receive(int sock, void *eloop_ctx,
1320 void *handle)
1321{
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001322 struct nl_cb *cb = eloop_ctx;
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -07001323 int res;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001324
Dmitry Shmidt8da800a2013-04-24 12:57:01 -07001325 wpa_printf(MSG_MSGDUMP, "nl80211: Event message available");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001326
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -07001327 res = nl_recvmsgs(handle, cb);
Dmitry Shmidt71757432014-06-02 13:50:35 -07001328 if (res < 0) {
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -07001329 wpa_printf(MSG_INFO, "nl80211: %s->nl_recvmsgs failed: %d",
1330 __func__, res);
1331 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001332}
1333
1334
1335/**
1336 * wpa_driver_nl80211_set_country - ask nl80211 to set the regulatory domain
1337 * @priv: driver_nl80211 private data
1338 * @alpha2_arg: country to which to switch to
1339 * Returns: 0 on success, -1 on failure
1340 *
1341 * This asks nl80211 to set the regulatory domain for given
1342 * country ISO / IEC alpha2.
1343 */
1344static int wpa_driver_nl80211_set_country(void *priv, const char *alpha2_arg)
1345{
1346 struct i802_bss *bss = priv;
1347 struct wpa_driver_nl80211_data *drv = bss->drv;
1348 char alpha2[3];
1349 struct nl_msg *msg;
1350
1351 msg = nlmsg_alloc();
1352 if (!msg)
1353 return -ENOMEM;
1354
1355 alpha2[0] = alpha2_arg[0];
1356 alpha2[1] = alpha2_arg[1];
1357 alpha2[2] = '\0';
1358
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001359 if (!nl80211_cmd(drv, msg, 0, NL80211_CMD_REQ_SET_REG) ||
1360 nla_put_string(msg, NL80211_ATTR_REG_ALPHA2, alpha2)) {
1361 nlmsg_free(msg);
1362 return -EINVAL;
1363 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001364 if (send_and_recv_msgs(drv, msg, NULL, NULL))
1365 return -EINVAL;
1366 return 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001367}
1368
1369
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001370static int nl80211_get_country(struct nl_msg *msg, void *arg)
1371{
1372 char *alpha2 = arg;
1373 struct nlattr *tb_msg[NL80211_ATTR_MAX + 1];
1374 struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg));
1375
1376 nla_parse(tb_msg, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0),
1377 genlmsg_attrlen(gnlh, 0), NULL);
1378 if (!tb_msg[NL80211_ATTR_REG_ALPHA2]) {
1379 wpa_printf(MSG_DEBUG, "nl80211: No country information available");
1380 return NL_SKIP;
1381 }
1382 os_strlcpy(alpha2, nla_data(tb_msg[NL80211_ATTR_REG_ALPHA2]), 3);
1383 return NL_SKIP;
1384}
1385
1386
1387static int wpa_driver_nl80211_get_country(void *priv, char *alpha2)
1388{
1389 struct i802_bss *bss = priv;
1390 struct wpa_driver_nl80211_data *drv = bss->drv;
1391 struct nl_msg *msg;
1392 int ret;
1393
1394 msg = nlmsg_alloc();
1395 if (!msg)
1396 return -ENOMEM;
1397
1398 nl80211_cmd(drv, msg, 0, NL80211_CMD_GET_REG);
1399 alpha2[0] = '\0';
1400 ret = send_and_recv_msgs(drv, msg, nl80211_get_country, alpha2);
1401 if (!alpha2[0])
1402 ret = -1;
1403
1404 return ret;
1405}
1406
1407
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001408static int wpa_driver_nl80211_init_nl_global(struct nl80211_global *global)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001409{
1410 int ret;
1411
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001412 global->nl_cb = nl_cb_alloc(NL_CB_DEFAULT);
1413 if (global->nl_cb == NULL) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001414 wpa_printf(MSG_ERROR, "nl80211: Failed to allocate netlink "
1415 "callbacks");
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001416 return -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001417 }
1418
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001419 global->nl = nl_create_handle(global->nl_cb, "nl");
1420 if (global->nl == NULL)
1421 goto err;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001422
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001423 global->nl80211_id = genl_ctrl_resolve(global->nl, "nl80211");
1424 if (global->nl80211_id < 0) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001425 wpa_printf(MSG_ERROR, "nl80211: 'nl80211' generic netlink not "
1426 "found");
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001427 goto err;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001428 }
1429
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001430 global->nl_event = nl_create_handle(global->nl_cb, "event");
1431 if (global->nl_event == NULL)
1432 goto err;
1433
1434 ret = nl_get_multicast_id(global, "nl80211", "scan");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001435 if (ret >= 0)
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001436 ret = nl_socket_add_membership(global->nl_event, ret);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001437 if (ret < 0) {
1438 wpa_printf(MSG_ERROR, "nl80211: Could not add multicast "
1439 "membership for scan events: %d (%s)",
1440 ret, strerror(-ret));
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001441 goto err;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001442 }
1443
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001444 ret = nl_get_multicast_id(global, "nl80211", "mlme");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001445 if (ret >= 0)
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001446 ret = nl_socket_add_membership(global->nl_event, ret);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001447 if (ret < 0) {
1448 wpa_printf(MSG_ERROR, "nl80211: Could not add multicast "
1449 "membership for mlme events: %d (%s)",
1450 ret, strerror(-ret));
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001451 goto err;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001452 }
1453
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001454 ret = nl_get_multicast_id(global, "nl80211", "regulatory");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001455 if (ret >= 0)
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001456 ret = nl_socket_add_membership(global->nl_event, ret);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001457 if (ret < 0) {
1458 wpa_printf(MSG_DEBUG, "nl80211: Could not add multicast "
1459 "membership for regulatory events: %d (%s)",
1460 ret, strerror(-ret));
1461 /* Continue without regulatory events */
1462 }
1463
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001464 ret = nl_get_multicast_id(global, "nl80211", "vendor");
1465 if (ret >= 0)
1466 ret = nl_socket_add_membership(global->nl_event, ret);
1467 if (ret < 0) {
1468 wpa_printf(MSG_DEBUG, "nl80211: Could not add multicast "
1469 "membership for vendor events: %d (%s)",
1470 ret, strerror(-ret));
1471 /* Continue without vendor events */
1472 }
1473
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001474 nl_cb_set(global->nl_cb, NL_CB_SEQ_CHECK, NL_CB_CUSTOM,
1475 no_seq_check, NULL);
1476 nl_cb_set(global->nl_cb, NL_CB_VALID, NL_CB_CUSTOM,
1477 process_global_event, global);
1478
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -07001479 nl80211_register_eloop_read(&global->nl_event,
1480 wpa_driver_nl80211_event_receive,
1481 global->nl_cb);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001482
1483 return 0;
1484
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001485err:
1486 nl_destroy_handles(&global->nl_event);
1487 nl_destroy_handles(&global->nl);
1488 nl_cb_put(global->nl_cb);
1489 global->nl_cb = NULL;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001490 return -1;
1491}
1492
1493
Dmitry Shmidt7f656022015-02-25 14:36:37 -08001494static void nl80211_check_global(struct nl80211_global *global)
1495{
1496 struct nl_handle *handle;
1497 const char *groups[] = { "scan", "mlme", "regulatory", "vendor", NULL };
1498 int ret;
1499 unsigned int i;
1500
1501 /*
1502 * Try to re-add memberships to handle case of cfg80211 getting reloaded
1503 * and all registration having been cleared.
1504 */
1505 handle = (void *) (((intptr_t) global->nl_event) ^
1506 ELOOP_SOCKET_INVALID);
1507
1508 for (i = 0; groups[i]; i++) {
1509 ret = nl_get_multicast_id(global, "nl80211", groups[i]);
1510 if (ret >= 0)
1511 ret = nl_socket_add_membership(handle, ret);
1512 if (ret < 0) {
1513 wpa_printf(MSG_INFO,
1514 "nl80211: Could not re-add multicast membership for %s events: %d (%s)",
1515 groups[i], ret, strerror(-ret));
1516 }
1517 }
1518}
1519
1520
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001521static void wpa_driver_nl80211_rfkill_blocked(void *ctx)
1522{
1523 wpa_printf(MSG_DEBUG, "nl80211: RFKILL blocked");
1524 /*
1525 * This may be for any interface; use ifdown event to disable
1526 * interface.
1527 */
1528}
1529
1530
1531static void wpa_driver_nl80211_rfkill_unblocked(void *ctx)
1532{
1533 struct wpa_driver_nl80211_data *drv = ctx;
1534 wpa_printf(MSG_DEBUG, "nl80211: RFKILL unblocked");
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001535 if (i802_set_iface_flags(drv->first_bss, 1)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001536 wpa_printf(MSG_DEBUG, "nl80211: Could not set interface UP "
1537 "after rfkill unblock");
1538 return;
1539 }
1540 /* rtnetlink ifup handler will report interface as enabled */
1541}
1542
1543
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001544static void wpa_driver_nl80211_handle_eapol_tx_status(int sock,
1545 void *eloop_ctx,
1546 void *handle)
1547{
1548 struct wpa_driver_nl80211_data *drv = eloop_ctx;
1549 u8 data[2048];
1550 struct msghdr msg;
1551 struct iovec entry;
Dmitry Shmidt04949592012-07-19 12:16:46 -07001552 u8 control[512];
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001553 struct cmsghdr *cmsg;
1554 int res, found_ee = 0, found_wifi = 0, acked = 0;
1555 union wpa_event_data event;
1556
1557 memset(&msg, 0, sizeof(msg));
1558 msg.msg_iov = &entry;
1559 msg.msg_iovlen = 1;
1560 entry.iov_base = data;
1561 entry.iov_len = sizeof(data);
1562 msg.msg_control = &control;
1563 msg.msg_controllen = sizeof(control);
1564
1565 res = recvmsg(sock, &msg, MSG_ERRQUEUE);
1566 /* if error or not fitting 802.3 header, return */
1567 if (res < 14)
1568 return;
1569
1570 for (cmsg = CMSG_FIRSTHDR(&msg); cmsg; cmsg = CMSG_NXTHDR(&msg, cmsg))
1571 {
1572 if (cmsg->cmsg_level == SOL_SOCKET &&
1573 cmsg->cmsg_type == SCM_WIFI_STATUS) {
1574 int *ack;
1575
1576 found_wifi = 1;
1577 ack = (void *)CMSG_DATA(cmsg);
1578 acked = *ack;
1579 }
1580
1581 if (cmsg->cmsg_level == SOL_PACKET &&
1582 cmsg->cmsg_type == PACKET_TX_TIMESTAMP) {
1583 struct sock_extended_err *err =
1584 (struct sock_extended_err *)CMSG_DATA(cmsg);
1585
1586 if (err->ee_origin == SO_EE_ORIGIN_TXSTATUS)
1587 found_ee = 1;
1588 }
1589 }
1590
1591 if (!found_ee || !found_wifi)
1592 return;
1593
1594 memset(&event, 0, sizeof(event));
1595 event.eapol_tx_status.dst = data;
1596 event.eapol_tx_status.data = data + 14;
1597 event.eapol_tx_status.data_len = res - 14;
1598 event.eapol_tx_status.ack = acked;
1599 wpa_supplicant_event(drv->ctx, EVENT_EAPOL_TX_STATUS, &event);
1600}
1601
1602
1603static int nl80211_init_bss(struct i802_bss *bss)
1604{
1605 bss->nl_cb = nl_cb_alloc(NL_CB_DEFAULT);
1606 if (!bss->nl_cb)
1607 return -1;
1608
1609 nl_cb_set(bss->nl_cb, NL_CB_SEQ_CHECK, NL_CB_CUSTOM,
1610 no_seq_check, NULL);
1611 nl_cb_set(bss->nl_cb, NL_CB_VALID, NL_CB_CUSTOM,
1612 process_bss_event, bss);
1613
1614 return 0;
1615}
1616
1617
1618static void nl80211_destroy_bss(struct i802_bss *bss)
1619{
1620 nl_cb_put(bss->nl_cb);
1621 bss->nl_cb = NULL;
1622}
1623
1624
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08001625static void * wpa_driver_nl80211_drv_init(void *ctx, const char *ifname,
1626 void *global_priv, int hostapd,
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001627 const u8 *set_addr,
1628 const char *driver_params)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001629{
1630 struct wpa_driver_nl80211_data *drv;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001631 struct rfkill_config *rcfg;
1632 struct i802_bss *bss;
1633
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001634 if (global_priv == NULL)
1635 return NULL;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001636 drv = os_zalloc(sizeof(*drv));
1637 if (drv == NULL)
1638 return NULL;
1639 drv->global = global_priv;
1640 drv->ctx = ctx;
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08001641 drv->hostapd = !!hostapd;
1642 drv->eapol_sock = -1;
Dmitry Shmidtff787d52015-01-12 13:01:47 -08001643
1644 /*
1645 * There is no driver capability flag for this, so assume it is
1646 * supported and disable this on first attempt to use if the driver
1647 * rejects the command due to missing support.
1648 */
1649 drv->set_rekey_offload = 1;
1650
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08001651 drv->num_if_indices = sizeof(drv->default_if_indices) / sizeof(int);
1652 drv->if_indices = drv->default_if_indices;
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001653
1654 drv->first_bss = os_zalloc(sizeof(*drv->first_bss));
1655 if (!drv->first_bss) {
1656 os_free(drv);
1657 return NULL;
1658 }
1659 bss = drv->first_bss;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001660 bss->drv = drv;
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08001661 bss->ctx = ctx;
1662
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001663 os_strlcpy(bss->ifname, ifname, sizeof(bss->ifname));
1664 drv->monitor_ifidx = -1;
1665 drv->monitor_sock = -1;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001666 drv->eapol_tx_sock = -1;
1667 drv->ap_scan_as_station = NL80211_IFTYPE_UNSPECIFIED;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001668
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001669 if (nl80211_init_bss(bss))
1670 goto failed;
1671
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001672 rcfg = os_zalloc(sizeof(*rcfg));
1673 if (rcfg == NULL)
1674 goto failed;
1675 rcfg->ctx = drv;
1676 os_strlcpy(rcfg->ifname, ifname, sizeof(rcfg->ifname));
1677 rcfg->blocked_cb = wpa_driver_nl80211_rfkill_blocked;
1678 rcfg->unblocked_cb = wpa_driver_nl80211_rfkill_unblocked;
1679 drv->rfkill = rfkill_init(rcfg);
1680 if (drv->rfkill == NULL) {
1681 wpa_printf(MSG_DEBUG, "nl80211: RFKILL status not available");
1682 os_free(rcfg);
1683 }
1684
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08001685 if (linux_iface_up(drv->global->ioctl_sock, ifname) > 0)
1686 drv->start_iface_up = 1;
1687
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001688 if (wpa_driver_nl80211_finish_drv_init(drv, set_addr, 1, driver_params))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001689 goto failed;
1690
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001691 drv->eapol_tx_sock = socket(PF_PACKET, SOCK_DGRAM, 0);
1692 if (drv->eapol_tx_sock < 0)
1693 goto failed;
1694
1695 if (drv->data_tx_status) {
1696 int enabled = 1;
1697
1698 if (setsockopt(drv->eapol_tx_sock, SOL_SOCKET, SO_WIFI_STATUS,
1699 &enabled, sizeof(enabled)) < 0) {
1700 wpa_printf(MSG_DEBUG,
1701 "nl80211: wifi status sockopt failed\n");
1702 drv->data_tx_status = 0;
1703 if (!drv->use_monitor)
1704 drv->capa.flags &=
1705 ~WPA_DRIVER_FLAGS_EAPOL_TX_STATUS;
1706 } else {
1707 eloop_register_read_sock(drv->eapol_tx_sock,
1708 wpa_driver_nl80211_handle_eapol_tx_status,
1709 drv, NULL);
1710 }
1711 }
1712
1713 if (drv->global) {
Dmitry Shmidt7f656022015-02-25 14:36:37 -08001714 nl80211_check_global(drv->global);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001715 dl_list_add(&drv->global->interfaces, &drv->list);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001716 drv->in_interface_list = 1;
1717 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001718
1719 return bss;
1720
1721failed:
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001722 wpa_driver_nl80211_deinit(bss);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001723 return NULL;
1724}
1725
1726
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08001727/**
1728 * wpa_driver_nl80211_init - Initialize nl80211 driver interface
1729 * @ctx: context to be used when calling wpa_supplicant functions,
1730 * e.g., wpa_supplicant_event()
1731 * @ifname: interface name, e.g., wlan0
1732 * @global_priv: private driver global data from global_init()
1733 * Returns: Pointer to private data, %NULL on failure
1734 */
1735static void * wpa_driver_nl80211_init(void *ctx, const char *ifname,
1736 void *global_priv)
1737{
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001738 return wpa_driver_nl80211_drv_init(ctx, ifname, global_priv, 0, NULL,
1739 NULL);
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08001740}
1741
1742
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001743static int nl80211_register_frame(struct i802_bss *bss,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001744 struct nl_handle *nl_handle,
1745 u16 type, const u8 *match, size_t match_len)
1746{
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001747 struct wpa_driver_nl80211_data *drv = bss->drv;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001748 struct nl_msg *msg;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001749 int ret;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001750 char buf[30];
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001751
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001752 buf[0] = '\0';
1753 wpa_snprintf_hex(buf, sizeof(buf), match, match_len);
Dmitry Shmidt2271d3f2014-06-23 12:16:31 -07001754 wpa_printf(MSG_DEBUG, "nl80211: Register frame type=0x%x (%s) nl_handle=%p match=%s",
1755 type, fc2str(type), nl_handle, buf);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001756
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001757 if (!(msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_REGISTER_ACTION)) ||
1758 nla_put_u16(msg, NL80211_ATTR_FRAME_TYPE, type) ||
1759 nla_put(msg, NL80211_ATTR_FRAME_MATCH, match_len, match)) {
1760 nlmsg_free(msg);
1761 return -1;
1762 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001763
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001764 ret = send_and_recv(drv->global, nl_handle, msg, NULL, NULL);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001765 if (ret) {
1766 wpa_printf(MSG_DEBUG, "nl80211: Register frame command "
1767 "failed (type=%u): ret=%d (%s)",
1768 type, ret, strerror(-ret));
1769 wpa_hexdump(MSG_DEBUG, "nl80211: Register frame match",
1770 match, match_len);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001771 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001772 return ret;
1773}
1774
1775
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001776static int nl80211_alloc_mgmt_handle(struct i802_bss *bss)
1777{
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001778 if (bss->nl_mgmt) {
1779 wpa_printf(MSG_DEBUG, "nl80211: Mgmt reporting "
1780 "already on! (nl_mgmt=%p)", bss->nl_mgmt);
1781 return -1;
1782 }
1783
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001784 bss->nl_mgmt = nl_create_handle(bss->nl_cb, "mgmt");
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001785 if (bss->nl_mgmt == NULL)
1786 return -1;
1787
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001788 return 0;
1789}
1790
1791
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -07001792static void nl80211_mgmt_handle_register_eloop(struct i802_bss *bss)
1793{
1794 nl80211_register_eloop_read(&bss->nl_mgmt,
1795 wpa_driver_nl80211_event_receive,
1796 bss->nl_cb);
1797}
1798
1799
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001800static int nl80211_register_action_frame(struct i802_bss *bss,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001801 const u8 *match, size_t match_len)
1802{
1803 u16 type = (WLAN_FC_TYPE_MGMT << 2) | (WLAN_FC_STYPE_ACTION << 4);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001804 return nl80211_register_frame(bss, bss->nl_mgmt,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001805 type, match, match_len);
1806}
1807
1808
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001809static int nl80211_mgmt_subscribe_non_ap(struct i802_bss *bss)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001810{
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001811 struct wpa_driver_nl80211_data *drv = bss->drv;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001812 int ret = 0;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001813
1814 if (nl80211_alloc_mgmt_handle(bss))
1815 return -1;
1816 wpa_printf(MSG_DEBUG, "nl80211: Subscribe to mgmt frames with non-AP "
1817 "handle %p", bss->nl_mgmt);
1818
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -07001819 if (drv->nlmode == NL80211_IFTYPE_ADHOC) {
1820 u16 type = (WLAN_FC_TYPE_MGMT << 2) | (WLAN_FC_STYPE_AUTH << 4);
1821
1822 /* register for any AUTH message */
1823 nl80211_register_frame(bss, bss->nl_mgmt, type, NULL, 0);
1824 }
1825
Dmitry Shmidt051af732013-10-22 13:52:46 -07001826#ifdef CONFIG_INTERWORKING
1827 /* QoS Map Configure */
1828 if (nl80211_register_action_frame(bss, (u8 *) "\x01\x04", 2) < 0)
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001829 ret = -1;
Dmitry Shmidt051af732013-10-22 13:52:46 -07001830#endif /* CONFIG_INTERWORKING */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001831#if defined(CONFIG_P2P) || defined(CONFIG_INTERWORKING)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001832 /* GAS Initial Request */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001833 if (nl80211_register_action_frame(bss, (u8 *) "\x04\x0a", 2) < 0)
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001834 ret = -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001835 /* GAS Initial Response */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001836 if (nl80211_register_action_frame(bss, (u8 *) "\x04\x0b", 2) < 0)
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001837 ret = -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001838 /* GAS Comeback Request */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001839 if (nl80211_register_action_frame(bss, (u8 *) "\x04\x0c", 2) < 0)
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001840 ret = -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001841 /* GAS Comeback Response */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001842 if (nl80211_register_action_frame(bss, (u8 *) "\x04\x0d", 2) < 0)
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001843 ret = -1;
Dmitry Shmidt18463232014-01-24 12:29:41 -08001844 /* Protected GAS Initial Request */
1845 if (nl80211_register_action_frame(bss, (u8 *) "\x09\x0a", 2) < 0)
1846 ret = -1;
1847 /* Protected GAS Initial Response */
1848 if (nl80211_register_action_frame(bss, (u8 *) "\x09\x0b", 2) < 0)
1849 ret = -1;
1850 /* Protected GAS Comeback Request */
1851 if (nl80211_register_action_frame(bss, (u8 *) "\x09\x0c", 2) < 0)
1852 ret = -1;
1853 /* Protected GAS Comeback Response */
1854 if (nl80211_register_action_frame(bss, (u8 *) "\x09\x0d", 2) < 0)
1855 ret = -1;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001856#endif /* CONFIG_P2P || CONFIG_INTERWORKING */
1857#ifdef CONFIG_P2P
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001858 /* P2P Public Action */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001859 if (nl80211_register_action_frame(bss,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001860 (u8 *) "\x04\x09\x50\x6f\x9a\x09",
1861 6) < 0)
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001862 ret = -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001863 /* P2P Action */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001864 if (nl80211_register_action_frame(bss,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001865 (u8 *) "\x7f\x50\x6f\x9a\x09",
1866 5) < 0)
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001867 ret = -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001868#endif /* CONFIG_P2P */
1869#ifdef CONFIG_IEEE80211W
1870 /* SA Query Response */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001871 if (nl80211_register_action_frame(bss, (u8 *) "\x08\x01", 2) < 0)
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001872 ret = -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001873#endif /* CONFIG_IEEE80211W */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001874#ifdef CONFIG_TDLS
1875 if ((drv->capa.flags & WPA_DRIVER_FLAGS_TDLS_SUPPORT)) {
1876 /* TDLS Discovery Response */
1877 if (nl80211_register_action_frame(bss, (u8 *) "\x04\x0e", 2) <
1878 0)
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001879 ret = -1;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001880 }
1881#endif /* CONFIG_TDLS */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001882
1883 /* FT Action frames */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001884 if (nl80211_register_action_frame(bss, (u8 *) "\x06", 1) < 0)
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001885 ret = -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001886 else
1887 drv->capa.key_mgmt |= WPA_DRIVER_CAPA_KEY_MGMT_FT |
1888 WPA_DRIVER_CAPA_KEY_MGMT_FT_PSK;
1889
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001890 /* WNM - BSS Transition Management Request */
1891 if (nl80211_register_action_frame(bss, (u8 *) "\x0a\x07", 2) < 0)
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001892 ret = -1;
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08001893 /* WNM-Sleep Mode Response */
1894 if (nl80211_register_action_frame(bss, (u8 *) "\x0a\x11", 2) < 0)
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001895 ret = -1;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001896
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08001897#ifdef CONFIG_HS20
1898 /* WNM-Notification */
1899 if (nl80211_register_action_frame(bss, (u8 *) "\x0a\x1a", 2) < 0)
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07001900 ret = -1;
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08001901#endif /* CONFIG_HS20 */
1902
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001903 /* WMM-AC ADDTS Response */
1904 if (nl80211_register_action_frame(bss, (u8 *) "\x11\x01", 2) < 0)
1905 ret = -1;
1906
1907 /* WMM-AC DELTS */
1908 if (nl80211_register_action_frame(bss, (u8 *) "\x11\x02", 2) < 0)
1909 ret = -1;
1910
1911 /* Radio Measurement - Neighbor Report Response */
1912 if (nl80211_register_action_frame(bss, (u8 *) "\x05\x05", 2) < 0)
1913 ret = -1;
1914
1915 /* Radio Measurement - Link Measurement Request */
1916 if ((drv->capa.rrm_flags & WPA_DRIVER_FLAGS_TX_POWER_INSERTION) &&
1917 (nl80211_register_action_frame(bss, (u8 *) "\x05\x02", 2) < 0))
1918 ret = -1;
1919
1920 nl80211_mgmt_handle_register_eloop(bss);
1921
1922 return ret;
1923}
1924
1925
1926static int nl80211_mgmt_subscribe_mesh(struct i802_bss *bss)
1927{
1928 int ret = 0;
1929
1930 if (nl80211_alloc_mgmt_handle(bss))
1931 return -1;
1932
1933 wpa_printf(MSG_DEBUG,
1934 "nl80211: Subscribe to mgmt frames with mesh handle %p",
1935 bss->nl_mgmt);
1936
1937 /* Auth frames for mesh SAE */
1938 if (nl80211_register_frame(bss, bss->nl_mgmt,
1939 (WLAN_FC_TYPE_MGMT << 2) |
1940 (WLAN_FC_STYPE_AUTH << 4),
1941 NULL, 0) < 0)
1942 ret = -1;
1943
1944 /* Mesh peering open */
1945 if (nl80211_register_action_frame(bss, (u8 *) "\x0f\x01", 2) < 0)
1946 ret = -1;
1947 /* Mesh peering confirm */
1948 if (nl80211_register_action_frame(bss, (u8 *) "\x0f\x02", 2) < 0)
1949 ret = -1;
1950 /* Mesh peering close */
1951 if (nl80211_register_action_frame(bss, (u8 *) "\x0f\x03", 2) < 0)
1952 ret = -1;
1953
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -07001954 nl80211_mgmt_handle_register_eloop(bss);
1955
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001956 return ret;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001957}
1958
1959
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001960static int nl80211_register_spurious_class3(struct i802_bss *bss)
1961{
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001962 struct nl_msg *msg;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001963 int ret;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001964
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001965 msg = nl80211_bss_msg(bss, 0, NL80211_CMD_UNEXPECTED_FRAME);
1966 ret = send_and_recv(bss->drv->global, bss->nl_mgmt, msg, NULL, NULL);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001967 if (ret) {
1968 wpa_printf(MSG_DEBUG, "nl80211: Register spurious class3 "
1969 "failed: ret=%d (%s)",
1970 ret, strerror(-ret));
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001971 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001972 return ret;
1973}
1974
1975
1976static int nl80211_mgmt_subscribe_ap(struct i802_bss *bss)
1977{
1978 static const int stypes[] = {
1979 WLAN_FC_STYPE_AUTH,
1980 WLAN_FC_STYPE_ASSOC_REQ,
1981 WLAN_FC_STYPE_REASSOC_REQ,
1982 WLAN_FC_STYPE_DISASSOC,
1983 WLAN_FC_STYPE_DEAUTH,
1984 WLAN_FC_STYPE_ACTION,
1985 WLAN_FC_STYPE_PROBE_REQ,
1986/* Beacon doesn't work as mac80211 doesn't currently allow
1987 * it, but it wouldn't really be the right thing anyway as
1988 * it isn't per interface ... maybe just dump the scan
1989 * results periodically for OLBC?
1990 */
Dmitry Shmidt7832adb2014-04-29 10:53:02 -07001991 /* WLAN_FC_STYPE_BEACON, */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001992 };
1993 unsigned int i;
1994
1995 if (nl80211_alloc_mgmt_handle(bss))
1996 return -1;
1997 wpa_printf(MSG_DEBUG, "nl80211: Subscribe to mgmt frames with AP "
1998 "handle %p", bss->nl_mgmt);
1999
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -07002000 for (i = 0; i < ARRAY_SIZE(stypes); i++) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002001 if (nl80211_register_frame(bss, bss->nl_mgmt,
2002 (WLAN_FC_TYPE_MGMT << 2) |
2003 (stypes[i] << 4),
2004 NULL, 0) < 0) {
2005 goto out_err;
2006 }
2007 }
2008
2009 if (nl80211_register_spurious_class3(bss))
2010 goto out_err;
2011
2012 if (nl80211_get_wiphy_data_ap(bss) == NULL)
2013 goto out_err;
2014
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -07002015 nl80211_mgmt_handle_register_eloop(bss);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002016 return 0;
2017
2018out_err:
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002019 nl_destroy_handles(&bss->nl_mgmt);
2020 return -1;
2021}
2022
2023
2024static int nl80211_mgmt_subscribe_ap_dev_sme(struct i802_bss *bss)
2025{
2026 if (nl80211_alloc_mgmt_handle(bss))
2027 return -1;
2028 wpa_printf(MSG_DEBUG, "nl80211: Subscribe to mgmt frames with AP "
2029 "handle %p (device SME)", bss->nl_mgmt);
2030
2031 if (nl80211_register_frame(bss, bss->nl_mgmt,
2032 (WLAN_FC_TYPE_MGMT << 2) |
2033 (WLAN_FC_STYPE_ACTION << 4),
2034 NULL, 0) < 0)
2035 goto out_err;
2036
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -07002037 nl80211_mgmt_handle_register_eloop(bss);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002038 return 0;
2039
2040out_err:
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002041 nl_destroy_handles(&bss->nl_mgmt);
2042 return -1;
2043}
2044
2045
2046static void nl80211_mgmt_unsubscribe(struct i802_bss *bss, const char *reason)
2047{
2048 if (bss->nl_mgmt == NULL)
2049 return;
2050 wpa_printf(MSG_DEBUG, "nl80211: Unsubscribe mgmt frames handle %p "
2051 "(%s)", bss->nl_mgmt, reason);
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -07002052 nl80211_destroy_eloop_handle(&bss->nl_mgmt);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002053
2054 nl80211_put_wiphy_data_ap(bss);
2055}
2056
2057
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002058static void wpa_driver_nl80211_send_rfkill(void *eloop_ctx, void *timeout_ctx)
2059{
2060 wpa_supplicant_event(timeout_ctx, EVENT_INTERFACE_DISABLED, NULL);
2061}
2062
2063
Dmitry Shmidt34af3062013-07-11 10:46:32 -07002064static void nl80211_del_p2pdev(struct i802_bss *bss)
2065{
Dmitry Shmidt34af3062013-07-11 10:46:32 -07002066 struct nl_msg *msg;
2067 int ret;
2068
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002069 msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_DEL_INTERFACE);
2070 ret = send_and_recv_msgs(bss->drv, msg, NULL, NULL);
Dmitry Shmidt34af3062013-07-11 10:46:32 -07002071
2072 wpa_printf(MSG_DEBUG, "nl80211: Delete P2P Device %s (0x%llx): %s",
2073 bss->ifname, (long long unsigned int) bss->wdev_id,
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -07002074 strerror(-ret));
Dmitry Shmidt34af3062013-07-11 10:46:32 -07002075}
2076
2077
2078static int nl80211_set_p2pdev(struct i802_bss *bss, int start)
2079{
Dmitry Shmidt34af3062013-07-11 10:46:32 -07002080 struct nl_msg *msg;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002081 int ret;
Dmitry Shmidt34af3062013-07-11 10:46:32 -07002082
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002083 msg = nl80211_cmd_msg(bss, 0, start ? NL80211_CMD_START_P2P_DEVICE :
2084 NL80211_CMD_STOP_P2P_DEVICE);
2085 ret = send_and_recv_msgs(bss->drv, msg, NULL, NULL);
Dmitry Shmidt34af3062013-07-11 10:46:32 -07002086
2087 wpa_printf(MSG_DEBUG, "nl80211: %s P2P Device %s (0x%llx): %s",
2088 start ? "Start" : "Stop",
2089 bss->ifname, (long long unsigned int) bss->wdev_id,
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -07002090 strerror(-ret));
Dmitry Shmidt34af3062013-07-11 10:46:32 -07002091 return ret;
2092}
2093
2094
2095static int i802_set_iface_flags(struct i802_bss *bss, int up)
2096{
2097 enum nl80211_iftype nlmode;
2098
2099 nlmode = nl80211_get_ifmode(bss);
2100 if (nlmode != NL80211_IFTYPE_P2P_DEVICE) {
2101 return linux_set_iface_flags(bss->drv->global->ioctl_sock,
2102 bss->ifname, up);
2103 }
2104
2105 /* P2P Device has start/stop which is equivalent */
2106 return nl80211_set_p2pdev(bss, up);
2107}
2108
2109
Dmitry Shmidt7f656022015-02-25 14:36:37 -08002110#ifdef CONFIG_TESTING_OPTIONS
2111static int qca_vendor_test_cmd_handler(struct nl_msg *msg, void *arg)
2112{
2113 /* struct wpa_driver_nl80211_data *drv = arg; */
2114 struct nlattr *tb[NL80211_ATTR_MAX + 1];
2115 struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg));
2116
2117
2118 wpa_printf(MSG_DEBUG,
2119 "nl80211: QCA vendor test command response received");
2120
2121 nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0),
2122 genlmsg_attrlen(gnlh, 0), NULL);
2123 if (!tb[NL80211_ATTR_VENDOR_DATA]) {
2124 wpa_printf(MSG_DEBUG, "nl80211: No vendor data attribute");
2125 return NL_SKIP;
2126 }
2127
2128 wpa_hexdump(MSG_DEBUG,
2129 "nl80211: Received QCA vendor test command response",
2130 nla_data(tb[NL80211_ATTR_VENDOR_DATA]),
2131 nla_len(tb[NL80211_ATTR_VENDOR_DATA]));
2132
2133 return NL_SKIP;
2134}
2135#endif /* CONFIG_TESTING_OPTIONS */
2136
2137
2138static void qca_vendor_test(struct wpa_driver_nl80211_data *drv)
2139{
2140#ifdef CONFIG_TESTING_OPTIONS
2141 struct nl_msg *msg;
2142 struct nlattr *params;
2143 int ret;
2144
2145 if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_VENDOR)) ||
2146 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
2147 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
2148 QCA_NL80211_VENDOR_SUBCMD_TEST) ||
2149 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
2150 nla_put_u32(msg, QCA_WLAN_VENDOR_ATTR_TEST, 123)) {
2151 nlmsg_free(msg);
2152 return;
2153 }
2154 nla_nest_end(msg, params);
2155
2156 ret = send_and_recv_msgs(drv, msg, qca_vendor_test_cmd_handler, drv);
2157 wpa_printf(MSG_DEBUG,
2158 "nl80211: QCA vendor test command returned %d (%s)",
2159 ret, strerror(-ret));
2160#endif /* CONFIG_TESTING_OPTIONS */
2161}
2162
2163
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002164static int
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08002165wpa_driver_nl80211_finish_drv_init(struct wpa_driver_nl80211_data *drv,
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002166 const u8 *set_addr, int first,
2167 const char *driver_params)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002168{
Dmitry Shmidtcce06662013-11-04 18:44:24 -08002169 struct i802_bss *bss = drv->first_bss;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002170 int send_rfkill_event = 0;
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08002171 enum nl80211_iftype nlmode;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002172
2173 drv->ifindex = if_nametoindex(bss->ifname);
Dmitry Shmidt34af3062013-07-11 10:46:32 -07002174 bss->ifindex = drv->ifindex;
2175 bss->wdev_id = drv->global->if_add_wdevid;
2176 bss->wdev_id_set = drv->global->if_add_wdevid_set;
2177
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -07002178 bss->if_dynamic = drv->ifindex == drv->global->if_add_ifindex;
2179 bss->if_dynamic = bss->if_dynamic || drv->global->if_add_wdevid_set;
Dmitry Shmidt34af3062013-07-11 10:46:32 -07002180 drv->global->if_add_wdevid_set = 0;
2181
Dmitry Shmidt03658832014-08-13 11:03:49 -07002182 if (!bss->if_dynamic && nl80211_get_ifmode(bss) == NL80211_IFTYPE_AP)
2183 bss->static_ap = 1;
2184
Dmitry Shmidt34af3062013-07-11 10:46:32 -07002185 if (wpa_driver_nl80211_capa(drv))
2186 return -1;
2187
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002188 if (driver_params && nl80211_set_param(bss, driver_params) < 0)
2189 return -1;
2190
Dmitry Shmidt34af3062013-07-11 10:46:32 -07002191 wpa_printf(MSG_DEBUG, "nl80211: interface %s in phy %s",
2192 bss->ifname, drv->phyname);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002193
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08002194 if (set_addr &&
2195 (linux_set_iface_flags(drv->global->ioctl_sock, bss->ifname, 0) ||
2196 linux_set_ifhwaddr(drv->global->ioctl_sock, bss->ifname,
2197 set_addr)))
2198 return -1;
Dmitry Shmidt34af3062013-07-11 10:46:32 -07002199
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08002200 if (first && nl80211_get_ifmode(bss) == NL80211_IFTYPE_AP)
2201 drv->start_mode_ap = 1;
2202
Dmitry Shmidt03658832014-08-13 11:03:49 -07002203 if (drv->hostapd || bss->static_ap)
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08002204 nlmode = NL80211_IFTYPE_AP;
2205 else if (bss->if_dynamic)
2206 nlmode = nl80211_get_ifmode(bss);
2207 else
2208 nlmode = NL80211_IFTYPE_STATION;
2209
Dmitry Shmidt34af3062013-07-11 10:46:32 -07002210 if (wpa_driver_nl80211_set_mode(bss, nlmode) < 0) {
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08002211 wpa_printf(MSG_ERROR, "nl80211: Could not configure driver mode");
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002212 return -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002213 }
Dmitry Shmidt34af3062013-07-11 10:46:32 -07002214
Dmitry Shmidt98660862014-03-11 17:26:21 -07002215 if (nlmode == NL80211_IFTYPE_P2P_DEVICE)
Dmitry Shmidt34af3062013-07-11 10:46:32 -07002216 nl80211_get_macaddr(bss);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002217
Dmitry Shmidt98660862014-03-11 17:26:21 -07002218 if (!rfkill_is_blocked(drv->rfkill)) {
2219 int ret = i802_set_iface_flags(bss, 1);
2220 if (ret) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002221 wpa_printf(MSG_ERROR, "nl80211: Could not set "
2222 "interface '%s' UP", bss->ifname);
Dmitry Shmidt98660862014-03-11 17:26:21 -07002223 return ret;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002224 }
Dmitry Shmidt98660862014-03-11 17:26:21 -07002225 if (nlmode == NL80211_IFTYPE_P2P_DEVICE)
2226 return ret;
2227 } else {
2228 wpa_printf(MSG_DEBUG, "nl80211: Could not yet enable "
2229 "interface '%s' due to rfkill", bss->ifname);
2230 if (nlmode == NL80211_IFTYPE_P2P_DEVICE)
2231 return 0;
2232 drv->if_disabled = 1;
2233 send_rfkill_event = 1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002234 }
2235
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08002236 if (!drv->hostapd)
2237 netlink_send_oper_ifla(drv->global->netlink, drv->ifindex,
2238 1, IF_OPER_DORMANT);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002239
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002240 if (linux_get_ifhwaddr(drv->global->ioctl_sock, bss->ifname,
2241 bss->addr))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002242 return -1;
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07002243 os_memcpy(drv->perm_addr, bss->addr, ETH_ALEN);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002244
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002245 if (send_rfkill_event) {
2246 eloop_register_timeout(0, 0, wpa_driver_nl80211_send_rfkill,
2247 drv, drv->ctx);
2248 }
2249
Dmitry Shmidt7f656022015-02-25 14:36:37 -08002250 if (drv->vendor_cmd_test_avail)
2251 qca_vendor_test(drv);
2252
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002253 return 0;
2254}
2255
2256
2257static int wpa_driver_nl80211_del_beacon(struct wpa_driver_nl80211_data *drv)
2258{
2259 struct nl_msg *msg;
2260
Dmitry Shmidtcce06662013-11-04 18:44:24 -08002261 wpa_printf(MSG_DEBUG, "nl80211: Remove beacon (ifindex=%d)",
2262 drv->ifindex);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002263 msg = nl80211_drv_msg(drv, 0, NL80211_CMD_DEL_BEACON);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002264 return send_and_recv_msgs(drv, msg, NULL, NULL);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002265}
2266
2267
2268/**
2269 * wpa_driver_nl80211_deinit - Deinitialize nl80211 driver interface
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08002270 * @bss: Pointer to private nl80211 data from wpa_driver_nl80211_init()
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002271 *
2272 * Shut down driver interface and processing of driver events. Free
2273 * private data buffer if one was allocated in wpa_driver_nl80211_init().
2274 */
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08002275static void wpa_driver_nl80211_deinit(struct i802_bss *bss)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002276{
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002277 struct wpa_driver_nl80211_data *drv = bss->drv;
2278
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002279 wpa_printf(MSG_INFO, "nl80211: deinit ifname=%s disabled_11b_rates=%d",
2280 bss->ifname, drv->disabled_11b_rates);
2281
Dmitry Shmidt04949592012-07-19 12:16:46 -07002282 bss->in_deinit = 1;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002283 if (drv->data_tx_status)
2284 eloop_unregister_read_sock(drv->eapol_tx_sock);
2285 if (drv->eapol_tx_sock >= 0)
2286 close(drv->eapol_tx_sock);
2287
2288 if (bss->nl_preq)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002289 wpa_driver_nl80211_probe_req_report(bss, 0);
2290 if (bss->added_if_into_bridge) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002291 if (linux_br_del_if(drv->global->ioctl_sock, bss->brname,
2292 bss->ifname) < 0)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002293 wpa_printf(MSG_INFO, "nl80211: Failed to remove "
2294 "interface %s from bridge %s: %s",
2295 bss->ifname, bss->brname, strerror(errno));
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07002296 if (drv->rtnl_sk)
Dmitry Shmidt9ead16e2014-10-07 13:15:23 -07002297 nl80211_handle_destroy(drv->rtnl_sk);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002298 }
2299 if (bss->added_bridge) {
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002300 if (linux_set_iface_flags(drv->global->ioctl_sock, bss->brname,
2301 0) < 0)
2302 wpa_printf(MSG_INFO,
2303 "nl80211: Could not set bridge %s down",
2304 bss->brname);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002305 if (linux_br_del(drv->global->ioctl_sock, bss->brname) < 0)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002306 wpa_printf(MSG_INFO, "nl80211: Failed to remove "
2307 "bridge %s: %s",
2308 bss->brname, strerror(errno));
2309 }
2310
2311 nl80211_remove_monitor_interface(drv);
2312
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002313 if (is_ap_interface(drv->nlmode))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002314 wpa_driver_nl80211_del_beacon(drv);
2315
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002316 if (drv->eapol_sock >= 0) {
2317 eloop_unregister_read_sock(drv->eapol_sock);
2318 close(drv->eapol_sock);
2319 }
2320
2321 if (drv->if_indices != drv->default_if_indices)
2322 os_free(drv->if_indices);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002323
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002324 if (drv->disabled_11b_rates)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002325 nl80211_disable_11b_rates(drv, drv->ifindex, 0);
2326
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002327 netlink_send_oper_ifla(drv->global->netlink, drv->ifindex, 0,
2328 IF_OPER_UP);
Dmitry Shmidtb58836e2014-04-29 14:35:56 -07002329 eloop_cancel_timeout(wpa_driver_nl80211_send_rfkill, drv, drv->ctx);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002330 rfkill_deinit(drv->rfkill);
2331
2332 eloop_cancel_timeout(wpa_driver_nl80211_scan_timeout, drv, drv->ctx);
2333
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08002334 if (!drv->start_iface_up)
2335 (void) i802_set_iface_flags(bss, 0);
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07002336
2337 if (drv->addr_changed) {
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002338 if (linux_set_iface_flags(drv->global->ioctl_sock, bss->ifname,
2339 0) < 0) {
2340 wpa_printf(MSG_DEBUG,
2341 "nl80211: Could not set interface down to restore permanent MAC address");
2342 }
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07002343 if (linux_set_ifhwaddr(drv->global->ioctl_sock, bss->ifname,
2344 drv->perm_addr) < 0) {
2345 wpa_printf(MSG_DEBUG,
2346 "nl80211: Could not restore permanent MAC address");
2347 }
2348 }
2349
Dmitry Shmidt34af3062013-07-11 10:46:32 -07002350 if (drv->nlmode != NL80211_IFTYPE_P2P_DEVICE) {
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08002351 if (!drv->hostapd || !drv->start_mode_ap)
2352 wpa_driver_nl80211_set_mode(bss,
2353 NL80211_IFTYPE_STATION);
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -07002354 nl80211_mgmt_unsubscribe(bss, "deinit");
Dmitry Shmidt34af3062013-07-11 10:46:32 -07002355 } else {
2356 nl80211_mgmt_unsubscribe(bss, "deinit");
2357 nl80211_del_p2pdev(bss);
2358 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002359
Dmitry Shmidtcce06662013-11-04 18:44:24 -08002360 nl80211_destroy_bss(drv->first_bss);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002361
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002362 os_free(drv->filter_ssids);
2363
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002364 os_free(drv->auth_ie);
2365
2366 if (drv->in_interface_list)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002367 dl_list_del(&drv->list);
2368
Dmitry Shmidt444d5672013-04-01 13:08:44 -07002369 os_free(drv->extended_capa);
2370 os_free(drv->extended_capa_mask);
Dmitry Shmidtcce06662013-11-04 18:44:24 -08002371 os_free(drv->first_bss);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002372 os_free(drv);
2373}
2374
2375
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002376static u32 wpa_alg_to_cipher_suite(enum wpa_alg alg, size_t key_len)
2377{
2378 switch (alg) {
2379 case WPA_ALG_WEP:
2380 if (key_len == 5)
2381 return WLAN_CIPHER_SUITE_WEP40;
2382 return WLAN_CIPHER_SUITE_WEP104;
2383 case WPA_ALG_TKIP:
2384 return WLAN_CIPHER_SUITE_TKIP;
2385 case WPA_ALG_CCMP:
2386 return WLAN_CIPHER_SUITE_CCMP;
2387 case WPA_ALG_GCMP:
2388 return WLAN_CIPHER_SUITE_GCMP;
2389 case WPA_ALG_CCMP_256:
2390 return WLAN_CIPHER_SUITE_CCMP_256;
2391 case WPA_ALG_GCMP_256:
2392 return WLAN_CIPHER_SUITE_GCMP_256;
2393 case WPA_ALG_IGTK:
2394 return WLAN_CIPHER_SUITE_AES_CMAC;
2395 case WPA_ALG_BIP_GMAC_128:
2396 return WLAN_CIPHER_SUITE_BIP_GMAC_128;
2397 case WPA_ALG_BIP_GMAC_256:
2398 return WLAN_CIPHER_SUITE_BIP_GMAC_256;
2399 case WPA_ALG_BIP_CMAC_256:
2400 return WLAN_CIPHER_SUITE_BIP_CMAC_256;
2401 case WPA_ALG_SMS4:
2402 return WLAN_CIPHER_SUITE_SMS4;
2403 case WPA_ALG_KRK:
2404 return WLAN_CIPHER_SUITE_KRK;
2405 case WPA_ALG_NONE:
2406 case WPA_ALG_PMK:
2407 wpa_printf(MSG_ERROR, "nl80211: Unexpected encryption algorithm %d",
2408 alg);
2409 return 0;
2410 }
2411
2412 wpa_printf(MSG_ERROR, "nl80211: Unsupported encryption algorithm %d",
2413 alg);
2414 return 0;
2415}
2416
2417
2418static u32 wpa_cipher_to_cipher_suite(unsigned int cipher)
2419{
2420 switch (cipher) {
2421 case WPA_CIPHER_CCMP_256:
2422 return WLAN_CIPHER_SUITE_CCMP_256;
2423 case WPA_CIPHER_GCMP_256:
2424 return WLAN_CIPHER_SUITE_GCMP_256;
2425 case WPA_CIPHER_CCMP:
2426 return WLAN_CIPHER_SUITE_CCMP;
2427 case WPA_CIPHER_GCMP:
2428 return WLAN_CIPHER_SUITE_GCMP;
2429 case WPA_CIPHER_TKIP:
2430 return WLAN_CIPHER_SUITE_TKIP;
2431 case WPA_CIPHER_WEP104:
2432 return WLAN_CIPHER_SUITE_WEP104;
2433 case WPA_CIPHER_WEP40:
2434 return WLAN_CIPHER_SUITE_WEP40;
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08002435 case WPA_CIPHER_GTK_NOT_USED:
2436 return WLAN_CIPHER_SUITE_NO_GROUP_ADDR;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002437 }
2438
2439 return 0;
2440}
2441
2442
2443static int wpa_cipher_to_cipher_suites(unsigned int ciphers, u32 suites[],
2444 int max_suites)
2445{
2446 int num_suites = 0;
2447
2448 if (num_suites < max_suites && ciphers & WPA_CIPHER_CCMP_256)
2449 suites[num_suites++] = WLAN_CIPHER_SUITE_CCMP_256;
2450 if (num_suites < max_suites && ciphers & WPA_CIPHER_GCMP_256)
2451 suites[num_suites++] = WLAN_CIPHER_SUITE_GCMP_256;
2452 if (num_suites < max_suites && ciphers & WPA_CIPHER_CCMP)
2453 suites[num_suites++] = WLAN_CIPHER_SUITE_CCMP;
2454 if (num_suites < max_suites && ciphers & WPA_CIPHER_GCMP)
2455 suites[num_suites++] = WLAN_CIPHER_SUITE_GCMP;
2456 if (num_suites < max_suites && ciphers & WPA_CIPHER_TKIP)
2457 suites[num_suites++] = WLAN_CIPHER_SUITE_TKIP;
2458 if (num_suites < max_suites && ciphers & WPA_CIPHER_WEP104)
2459 suites[num_suites++] = WLAN_CIPHER_SUITE_WEP104;
2460 if (num_suites < max_suites && ciphers & WPA_CIPHER_WEP40)
2461 suites[num_suites++] = WLAN_CIPHER_SUITE_WEP40;
2462
2463 return num_suites;
2464}
2465
2466
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002467static int issue_key_mgmt_set_key(struct wpa_driver_nl80211_data *drv,
2468 const u8 *key, size_t key_len)
2469{
2470 struct nl_msg *msg;
2471 int ret;
2472
2473 if (!(drv->capa.flags & WPA_DRIVER_FLAGS_KEY_MGMT_OFFLOAD))
2474 return 0;
2475
2476 if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_VENDOR)) ||
2477 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
2478 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
2479 QCA_NL80211_VENDOR_SUBCMD_KEY_MGMT_SET_KEY) ||
2480 nla_put(msg, NL80211_ATTR_VENDOR_DATA, key_len, key)) {
2481 nl80211_nlmsg_clear(msg);
2482 nlmsg_free(msg);
2483 return -1;
2484 }
2485 ret = send_and_recv_msgs(drv, msg, NULL, (void *) -1);
2486 if (ret) {
2487 wpa_printf(MSG_DEBUG,
2488 "nl80211: Key management set key failed: ret=%d (%s)",
2489 ret, strerror(-ret));
2490 }
2491
2492 return ret;
2493}
2494
2495
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08002496static int wpa_driver_nl80211_set_key(const char *ifname, struct i802_bss *bss,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002497 enum wpa_alg alg, const u8 *addr,
2498 int key_idx, int set_tx,
2499 const u8 *seq, size_t seq_len,
2500 const u8 *key, size_t key_len)
2501{
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002502 struct wpa_driver_nl80211_data *drv = bss->drv;
Dmitry Shmidt34af3062013-07-11 10:46:32 -07002503 int ifindex;
Dmitry Shmidt1d755d02015-04-28 10:34:29 -07002504 struct nl_msg *msg = NULL;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002505 int ret;
Dmitry Shmidtd5c075b2013-08-05 14:36:10 -07002506 int tdls = 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002507
Dmitry Shmidt34af3062013-07-11 10:46:32 -07002508 /* Ignore for P2P Device */
2509 if (drv->nlmode == NL80211_IFTYPE_P2P_DEVICE)
2510 return 0;
2511
2512 ifindex = if_nametoindex(ifname);
2513 wpa_printf(MSG_DEBUG, "%s: ifindex=%d (%s) alg=%d addr=%p key_idx=%d "
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002514 "set_tx=%d seq_len=%lu key_len=%lu",
Dmitry Shmidt34af3062013-07-11 10:46:32 -07002515 __func__, ifindex, ifname, alg, addr, key_idx, set_tx,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002516 (unsigned long) seq_len, (unsigned long) key_len);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002517#ifdef CONFIG_TDLS
Dmitry Shmidtd5c075b2013-08-05 14:36:10 -07002518 if (key_idx == -1) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002519 key_idx = 0;
Dmitry Shmidtd5c075b2013-08-05 14:36:10 -07002520 tdls = 1;
2521 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002522#endif /* CONFIG_TDLS */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002523
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002524 if (alg == WPA_ALG_PMK &&
2525 (drv->capa.flags & WPA_DRIVER_FLAGS_KEY_MGMT_OFFLOAD)) {
2526 wpa_printf(MSG_DEBUG, "%s: calling issue_key_mgmt_set_key",
2527 __func__);
2528 ret = issue_key_mgmt_set_key(drv, key, key_len);
2529 return ret;
2530 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002531
2532 if (alg == WPA_ALG_NONE) {
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002533 msg = nl80211_ifindex_msg(drv, ifindex, 0, NL80211_CMD_DEL_KEY);
2534 if (!msg)
2535 return -ENOBUFS;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002536 } else {
Dmitry Shmidt1d755d02015-04-28 10:34:29 -07002537 u32 suite;
2538
2539 suite = wpa_alg_to_cipher_suite(alg, key_len);
2540 if (!suite)
2541 goto fail;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002542 msg = nl80211_ifindex_msg(drv, ifindex, 0, NL80211_CMD_NEW_KEY);
2543 if (!msg ||
2544 nla_put(msg, NL80211_ATTR_KEY_DATA, key_len, key) ||
Dmitry Shmidt1d755d02015-04-28 10:34:29 -07002545 nla_put_u32(msg, NL80211_ATTR_KEY_CIPHER, suite))
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002546 goto fail;
Dmitry Shmidt98660862014-03-11 17:26:21 -07002547 wpa_hexdump_key(MSG_DEBUG, "nl80211: KEY_DATA", key, key_len);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002548 }
2549
Dmitry Shmidt98660862014-03-11 17:26:21 -07002550 if (seq && seq_len) {
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002551 if (nla_put(msg, NL80211_ATTR_KEY_SEQ, seq_len, seq))
2552 goto fail;
Dmitry Shmidt98660862014-03-11 17:26:21 -07002553 wpa_hexdump(MSG_DEBUG, "nl80211: KEY_SEQ", seq, seq_len);
2554 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002555
2556 if (addr && !is_broadcast_ether_addr(addr)) {
2557 wpa_printf(MSG_DEBUG, " addr=" MACSTR, MAC2STR(addr));
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002558 if (nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr))
2559 goto fail;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002560
2561 if (alg != WPA_ALG_WEP && key_idx && !set_tx) {
2562 wpa_printf(MSG_DEBUG, " RSN IBSS RX GTK");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002563 if (nla_put_u32(msg, NL80211_ATTR_KEY_TYPE,
2564 NL80211_KEYTYPE_GROUP))
2565 goto fail;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002566 }
2567 } else if (addr && is_broadcast_ether_addr(addr)) {
Dmitry Shmidt8da800a2013-04-24 12:57:01 -07002568 struct nlattr *types;
2569
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002570 wpa_printf(MSG_DEBUG, " broadcast key");
Dmitry Shmidt8da800a2013-04-24 12:57:01 -07002571
2572 types = nla_nest_start(msg, NL80211_ATTR_KEY_DEFAULT_TYPES);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002573 if (!types ||
2574 nla_put_flag(msg, NL80211_KEY_DEFAULT_TYPE_MULTICAST))
2575 goto fail;
Dmitry Shmidt8da800a2013-04-24 12:57:01 -07002576 nla_nest_end(msg, types);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002577 }
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002578 if (nla_put_u8(msg, NL80211_ATTR_KEY_IDX, key_idx))
2579 goto fail;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002580
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002581 ret = send_and_recv_msgs(drv, msg, NULL, key ? (void *) -1 : NULL);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002582 if ((ret == -ENOENT || ret == -ENOLINK) && alg == WPA_ALG_NONE)
2583 ret = 0;
2584 if (ret)
2585 wpa_printf(MSG_DEBUG, "nl80211: set_key failed; err=%d %s)",
2586 ret, strerror(-ret));
2587
2588 /*
2589 * If we failed or don't need to set the default TX key (below),
2590 * we're done here.
2591 */
Dmitry Shmidtd5c075b2013-08-05 14:36:10 -07002592 if (ret || !set_tx || alg == WPA_ALG_NONE || tdls)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002593 return ret;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002594 if (is_ap_interface(drv->nlmode) && addr &&
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002595 !is_broadcast_ether_addr(addr))
2596 return ret;
2597
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002598 msg = nl80211_ifindex_msg(drv, ifindex, 0, NL80211_CMD_SET_KEY);
2599 if (!msg ||
2600 nla_put_u8(msg, NL80211_ATTR_KEY_IDX, key_idx) ||
Dmitry Shmidt807291d2015-01-27 13:40:23 -08002601 nla_put_flag(msg, (alg == WPA_ALG_IGTK ||
2602 alg == WPA_ALG_BIP_GMAC_128 ||
2603 alg == WPA_ALG_BIP_GMAC_256 ||
2604 alg == WPA_ALG_BIP_CMAC_256) ?
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002605 NL80211_ATTR_KEY_DEFAULT_MGMT :
2606 NL80211_ATTR_KEY_DEFAULT))
2607 goto fail;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002608 if (addr && is_broadcast_ether_addr(addr)) {
Dmitry Shmidt8da800a2013-04-24 12:57:01 -07002609 struct nlattr *types;
2610
2611 types = nla_nest_start(msg, NL80211_ATTR_KEY_DEFAULT_TYPES);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002612 if (!types ||
2613 nla_put_flag(msg, NL80211_KEY_DEFAULT_TYPE_MULTICAST))
2614 goto fail;
Dmitry Shmidt8da800a2013-04-24 12:57:01 -07002615 nla_nest_end(msg, types);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002616 } else if (addr) {
Dmitry Shmidt8da800a2013-04-24 12:57:01 -07002617 struct nlattr *types;
2618
2619 types = nla_nest_start(msg, NL80211_ATTR_KEY_DEFAULT_TYPES);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002620 if (!types ||
2621 nla_put_flag(msg, NL80211_KEY_DEFAULT_TYPE_UNICAST))
2622 goto fail;
Dmitry Shmidt8da800a2013-04-24 12:57:01 -07002623 nla_nest_end(msg, types);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002624 }
2625
2626 ret = send_and_recv_msgs(drv, msg, NULL, NULL);
2627 if (ret == -ENOENT)
2628 ret = 0;
2629 if (ret)
2630 wpa_printf(MSG_DEBUG, "nl80211: set_key default failed; "
2631 "err=%d %s)", ret, strerror(-ret));
2632 return ret;
2633
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002634fail:
2635 nl80211_nlmsg_clear(msg);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002636 nlmsg_free(msg);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002637 return -ENOBUFS;
2638}
2639
2640
2641static int nl_add_key(struct nl_msg *msg, enum wpa_alg alg,
2642 int key_idx, int defkey,
2643 const u8 *seq, size_t seq_len,
2644 const u8 *key, size_t key_len)
2645{
2646 struct nlattr *key_attr = nla_nest_start(msg, NL80211_ATTR_KEY);
Dmitry Shmidt1d755d02015-04-28 10:34:29 -07002647 u32 suite;
2648
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002649 if (!key_attr)
2650 return -1;
2651
Dmitry Shmidt1d755d02015-04-28 10:34:29 -07002652 suite = wpa_alg_to_cipher_suite(alg, key_len);
2653 if (!suite)
2654 return -1;
2655
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002656 if (defkey && alg == WPA_ALG_IGTK) {
2657 if (nla_put_flag(msg, NL80211_KEY_DEFAULT_MGMT))
2658 return -1;
2659 } else if (defkey) {
2660 if (nla_put_flag(msg, NL80211_KEY_DEFAULT))
2661 return -1;
2662 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002663
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002664 if (nla_put_u8(msg, NL80211_KEY_IDX, key_idx) ||
Dmitry Shmidt1d755d02015-04-28 10:34:29 -07002665 nla_put_u32(msg, NL80211_KEY_CIPHER, suite) ||
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002666 (seq && seq_len &&
2667 nla_put(msg, NL80211_KEY_SEQ, seq_len, seq)) ||
2668 nla_put(msg, NL80211_KEY_DATA, key_len, key))
2669 return -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002670
2671 nla_nest_end(msg, key_attr);
2672
2673 return 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002674}
2675
2676
2677static int nl80211_set_conn_keys(struct wpa_driver_associate_params *params,
2678 struct nl_msg *msg)
2679{
2680 int i, privacy = 0;
2681 struct nlattr *nl_keys, *nl_key;
2682
2683 for (i = 0; i < 4; i++) {
2684 if (!params->wep_key[i])
2685 continue;
2686 privacy = 1;
2687 break;
2688 }
2689 if (params->wps == WPS_MODE_PRIVACY)
2690 privacy = 1;
2691 if (params->pairwise_suite &&
2692 params->pairwise_suite != WPA_CIPHER_NONE)
2693 privacy = 1;
2694
2695 if (!privacy)
2696 return 0;
2697
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002698 if (nla_put_flag(msg, NL80211_ATTR_PRIVACY))
2699 return -ENOBUFS;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002700
2701 nl_keys = nla_nest_start(msg, NL80211_ATTR_KEYS);
2702 if (!nl_keys)
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002703 return -ENOBUFS;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002704
2705 for (i = 0; i < 4; i++) {
2706 if (!params->wep_key[i])
2707 continue;
2708
2709 nl_key = nla_nest_start(msg, i);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002710 if (!nl_key ||
2711 nla_put(msg, NL80211_KEY_DATA, params->wep_key_len[i],
2712 params->wep_key[i]) ||
2713 nla_put_u32(msg, NL80211_KEY_CIPHER,
2714 params->wep_key_len[i] == 5 ?
2715 WLAN_CIPHER_SUITE_WEP40 :
2716 WLAN_CIPHER_SUITE_WEP104) ||
2717 nla_put_u8(msg, NL80211_KEY_IDX, i) ||
2718 (i == params->wep_tx_keyidx &&
2719 nla_put_flag(msg, NL80211_KEY_DEFAULT)))
2720 return -ENOBUFS;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002721
2722 nla_nest_end(msg, nl_key);
2723 }
2724 nla_nest_end(msg, nl_keys);
2725
2726 return 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002727}
2728
2729
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002730int wpa_driver_nl80211_mlme(struct wpa_driver_nl80211_data *drv,
2731 const u8 *addr, int cmd, u16 reason_code,
2732 int local_state_change)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002733{
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002734 int ret;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002735 struct nl_msg *msg;
2736
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002737 if (!(msg = nl80211_drv_msg(drv, 0, cmd)) ||
2738 nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason_code) ||
2739 (addr && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) ||
2740 (local_state_change &&
2741 nla_put_flag(msg, NL80211_ATTR_LOCAL_STATE_CHANGE))) {
2742 nlmsg_free(msg);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002743 return -1;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002744 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002745
2746 ret = send_and_recv_msgs(drv, msg, NULL, NULL);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002747 if (ret) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002748 wpa_dbg(drv->ctx, MSG_DEBUG,
2749 "nl80211: MLME command failed: reason=%u ret=%d (%s)",
2750 reason_code, ret, strerror(-ret));
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002751 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002752 return ret;
2753}
2754
2755
2756static int wpa_driver_nl80211_disconnect(struct wpa_driver_nl80211_data *drv,
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08002757 int reason_code)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002758{
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07002759 int ret;
2760
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08002761 wpa_printf(MSG_DEBUG, "%s(reason_code=%d)", __func__, reason_code);
Dmitry Shmidt8bae4132013-06-06 11:25:10 -07002762 nl80211_mark_disconnected(drv);
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08002763 /* Disconnect command doesn't need BSSID - it uses cached value */
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07002764 ret = wpa_driver_nl80211_mlme(drv, NULL, NL80211_CMD_DISCONNECT,
2765 reason_code, 0);
2766 /*
2767 * For locally generated disconnect, supplicant already generates a
2768 * DEAUTH event, so ignore the event from NL80211.
2769 */
2770 drv->ignore_next_local_disconnect = ret == 0;
2771
2772 return ret;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002773}
2774
2775
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08002776static int wpa_driver_nl80211_deauthenticate(struct i802_bss *bss,
2777 const u8 *addr, int reason_code)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002778{
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002779 struct wpa_driver_nl80211_data *drv = bss->drv;
Dmitry Shmidt7dba0e52014-04-14 10:49:15 -07002780 int ret;
Dmitry Shmidt413dde72014-04-11 10:23:22 -07002781
2782 if (drv->nlmode == NL80211_IFTYPE_ADHOC) {
2783 nl80211_mark_disconnected(drv);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002784 return nl80211_leave_ibss(drv, 1);
Dmitry Shmidt413dde72014-04-11 10:23:22 -07002785 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002786 if (!(drv->capa.flags & WPA_DRIVER_FLAGS_SME))
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08002787 return wpa_driver_nl80211_disconnect(drv, reason_code);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002788 wpa_printf(MSG_DEBUG, "%s(addr=" MACSTR " reason_code=%d)",
2789 __func__, MAC2STR(addr), reason_code);
Dmitry Shmidt8bae4132013-06-06 11:25:10 -07002790 nl80211_mark_disconnected(drv);
Dmitry Shmidt7dba0e52014-04-14 10:49:15 -07002791 ret = wpa_driver_nl80211_mlme(drv, addr, NL80211_CMD_DEAUTHENTICATE,
2792 reason_code, 0);
2793 /*
2794 * For locally generated deauthenticate, supplicant already generates a
2795 * DEAUTH event, so ignore the event from NL80211.
2796 */
2797 drv->ignore_next_local_deauth = ret == 0;
2798 return ret;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002799}
2800
2801
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002802static void nl80211_copy_auth_params(struct wpa_driver_nl80211_data *drv,
2803 struct wpa_driver_auth_params *params)
2804{
2805 int i;
2806
2807 drv->auth_freq = params->freq;
2808 drv->auth_alg = params->auth_alg;
2809 drv->auth_wep_tx_keyidx = params->wep_tx_keyidx;
2810 drv->auth_local_state_change = params->local_state_change;
2811 drv->auth_p2p = params->p2p;
2812
2813 if (params->bssid)
2814 os_memcpy(drv->auth_bssid_, params->bssid, ETH_ALEN);
2815 else
2816 os_memset(drv->auth_bssid_, 0, ETH_ALEN);
2817
2818 if (params->ssid) {
2819 os_memcpy(drv->auth_ssid, params->ssid, params->ssid_len);
2820 drv->auth_ssid_len = params->ssid_len;
2821 } else
2822 drv->auth_ssid_len = 0;
2823
2824
2825 os_free(drv->auth_ie);
2826 drv->auth_ie = NULL;
2827 drv->auth_ie_len = 0;
2828 if (params->ie) {
2829 drv->auth_ie = os_malloc(params->ie_len);
2830 if (drv->auth_ie) {
2831 os_memcpy(drv->auth_ie, params->ie, params->ie_len);
2832 drv->auth_ie_len = params->ie_len;
2833 }
2834 }
2835
2836 for (i = 0; i < 4; i++) {
2837 if (params->wep_key[i] && params->wep_key_len[i] &&
2838 params->wep_key_len[i] <= 16) {
2839 os_memcpy(drv->auth_wep_key[i], params->wep_key[i],
2840 params->wep_key_len[i]);
2841 drv->auth_wep_key_len[i] = params->wep_key_len[i];
2842 } else
2843 drv->auth_wep_key_len[i] = 0;
2844 }
2845}
2846
2847
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002848static void nl80211_unmask_11b_rates(struct i802_bss *bss)
2849{
2850 struct wpa_driver_nl80211_data *drv = bss->drv;
2851
2852 if (is_p2p_net_interface(drv->nlmode) || !drv->disabled_11b_rates)
2853 return;
2854
2855 /*
2856 * Looks like we failed to unmask 11b rates previously. This could
2857 * happen, e.g., if the interface was down at the point in time when a
2858 * P2P group was terminated.
2859 */
2860 wpa_printf(MSG_DEBUG,
2861 "nl80211: Interface %s mode is for non-P2P, but 11b rates were disabled - re-enable them",
2862 bss->ifname);
2863 nl80211_disable_11b_rates(drv, drv->ifindex, 0);
2864}
2865
2866
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002867static int wpa_driver_nl80211_authenticate(
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08002868 struct i802_bss *bss, struct wpa_driver_auth_params *params)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002869{
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002870 struct wpa_driver_nl80211_data *drv = bss->drv;
2871 int ret = -1, i;
2872 struct nl_msg *msg;
2873 enum nl80211_auth_type type;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002874 enum nl80211_iftype nlmode;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002875 int count = 0;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002876 int is_retry;
2877
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002878 nl80211_unmask_11b_rates(bss);
2879
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002880 is_retry = drv->retry_auth;
2881 drv->retry_auth = 0;
Dmitry Shmidt98660862014-03-11 17:26:21 -07002882 drv->ignore_deauth_event = 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002883
Dmitry Shmidt8bae4132013-06-06 11:25:10 -07002884 nl80211_mark_disconnected(drv);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002885 os_memset(drv->auth_bssid, 0, ETH_ALEN);
Dmitry Shmidt8bae4132013-06-06 11:25:10 -07002886 if (params->bssid)
2887 os_memcpy(drv->auth_attempt_bssid, params->bssid, ETH_ALEN);
2888 else
2889 os_memset(drv->auth_attempt_bssid, 0, ETH_ALEN);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002890 /* FIX: IBSS mode */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002891 nlmode = params->p2p ?
2892 NL80211_IFTYPE_P2P_CLIENT : NL80211_IFTYPE_STATION;
2893 if (drv->nlmode != nlmode &&
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08002894 wpa_driver_nl80211_set_mode(bss, nlmode) < 0)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002895 return -1;
2896
2897retry:
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002898 wpa_printf(MSG_DEBUG, "nl80211: Authenticate (ifindex=%d)",
2899 drv->ifindex);
2900
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002901 msg = nl80211_drv_msg(drv, 0, NL80211_CMD_AUTHENTICATE);
2902 if (!msg)
2903 goto fail;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002904
2905 for (i = 0; i < 4; i++) {
2906 if (!params->wep_key[i])
2907 continue;
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08002908 wpa_driver_nl80211_set_key(bss->ifname, bss, WPA_ALG_WEP,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002909 NULL, i,
2910 i == params->wep_tx_keyidx, NULL, 0,
2911 params->wep_key[i],
2912 params->wep_key_len[i]);
2913 if (params->wep_tx_keyidx != i)
2914 continue;
2915 if (nl_add_key(msg, WPA_ALG_WEP, i, 1, NULL, 0,
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002916 params->wep_key[i], params->wep_key_len[i]))
2917 goto fail;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002918 }
2919
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002920 if (params->bssid) {
2921 wpa_printf(MSG_DEBUG, " * bssid=" MACSTR,
2922 MAC2STR(params->bssid));
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002923 if (nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, params->bssid))
2924 goto fail;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002925 }
2926 if (params->freq) {
2927 wpa_printf(MSG_DEBUG, " * freq=%d", params->freq);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002928 if (nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, params->freq))
2929 goto fail;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002930 }
2931 if (params->ssid) {
2932 wpa_hexdump_ascii(MSG_DEBUG, " * SSID",
2933 params->ssid, params->ssid_len);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002934 if (nla_put(msg, NL80211_ATTR_SSID, params->ssid_len,
2935 params->ssid))
2936 goto fail;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002937 }
2938 wpa_hexdump(MSG_DEBUG, " * IEs", params->ie, params->ie_len);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002939 if (params->ie &&
2940 nla_put(msg, NL80211_ATTR_IE, params->ie_len, params->ie))
2941 goto fail;
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08002942 if (params->sae_data) {
2943 wpa_hexdump(MSG_DEBUG, " * SAE data", params->sae_data,
2944 params->sae_data_len);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002945 if (nla_put(msg, NL80211_ATTR_SAE_DATA, params->sae_data_len,
2946 params->sae_data))
2947 goto fail;
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08002948 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002949 if (params->auth_alg & WPA_AUTH_ALG_OPEN)
2950 type = NL80211_AUTHTYPE_OPEN_SYSTEM;
2951 else if (params->auth_alg & WPA_AUTH_ALG_SHARED)
2952 type = NL80211_AUTHTYPE_SHARED_KEY;
2953 else if (params->auth_alg & WPA_AUTH_ALG_LEAP)
2954 type = NL80211_AUTHTYPE_NETWORK_EAP;
2955 else if (params->auth_alg & WPA_AUTH_ALG_FT)
2956 type = NL80211_AUTHTYPE_FT;
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08002957 else if (params->auth_alg & WPA_AUTH_ALG_SAE)
2958 type = NL80211_AUTHTYPE_SAE;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002959 else
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002960 goto fail;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002961 wpa_printf(MSG_DEBUG, " * Auth Type %d", type);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002962 if (nla_put_u32(msg, NL80211_ATTR_AUTH_TYPE, type))
2963 goto fail;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002964 if (params->local_state_change) {
2965 wpa_printf(MSG_DEBUG, " * Local state change only");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002966 if (nla_put_flag(msg, NL80211_ATTR_LOCAL_STATE_CHANGE))
2967 goto fail;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002968 }
2969
2970 ret = send_and_recv_msgs(drv, msg, NULL, NULL);
2971 msg = NULL;
2972 if (ret) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002973 wpa_dbg(drv->ctx, MSG_DEBUG,
2974 "nl80211: MLME command failed (auth): ret=%d (%s)",
2975 ret, strerror(-ret));
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002976 count++;
2977 if (ret == -EALREADY && count == 1 && params->bssid &&
2978 !params->local_state_change) {
2979 /*
2980 * mac80211 does not currently accept new
2981 * authentication if we are already authenticated. As a
2982 * workaround, force deauthentication and try again.
2983 */
2984 wpa_printf(MSG_DEBUG, "nl80211: Retry authentication "
2985 "after forced deauthentication");
Dmitry Shmidt98660862014-03-11 17:26:21 -07002986 drv->ignore_deauth_event = 1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002987 wpa_driver_nl80211_deauthenticate(
2988 bss, params->bssid,
2989 WLAN_REASON_PREV_AUTH_NOT_VALID);
2990 nlmsg_free(msg);
2991 goto retry;
2992 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002993
2994 if (ret == -ENOENT && params->freq && !is_retry) {
2995 /*
2996 * cfg80211 has likely expired the BSS entry even
2997 * though it was previously available in our internal
2998 * BSS table. To recover quickly, start a single
2999 * channel scan on the specified channel.
3000 */
3001 struct wpa_driver_scan_params scan;
3002 int freqs[2];
3003
3004 os_memset(&scan, 0, sizeof(scan));
3005 scan.num_ssids = 1;
3006 if (params->ssid) {
3007 scan.ssids[0].ssid = params->ssid;
3008 scan.ssids[0].ssid_len = params->ssid_len;
3009 }
3010 freqs[0] = params->freq;
3011 freqs[1] = 0;
3012 scan.freqs = freqs;
3013 wpa_printf(MSG_DEBUG, "nl80211: Trigger single "
3014 "channel scan to refresh cfg80211 BSS "
3015 "entry");
3016 ret = wpa_driver_nl80211_scan(bss, &scan);
3017 if (ret == 0) {
3018 nl80211_copy_auth_params(drv, params);
3019 drv->scan_for_auth = 1;
3020 }
3021 } else if (is_retry) {
3022 /*
3023 * Need to indicate this with an event since the return
3024 * value from the retry is not delivered to core code.
3025 */
3026 union wpa_event_data event;
3027 wpa_printf(MSG_DEBUG, "nl80211: Authentication retry "
3028 "failed");
3029 os_memset(&event, 0, sizeof(event));
3030 os_memcpy(event.timeout_event.addr, drv->auth_bssid_,
3031 ETH_ALEN);
3032 wpa_supplicant_event(drv->ctx, EVENT_AUTH_TIMED_OUT,
3033 &event);
3034 }
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003035 } else {
3036 wpa_printf(MSG_DEBUG,
3037 "nl80211: Authentication request send successfully");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003038 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003039
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003040fail:
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003041 nlmsg_free(msg);
3042 return ret;
3043}
3044
3045
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003046int wpa_driver_nl80211_authenticate_retry(struct wpa_driver_nl80211_data *drv)
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003047{
3048 struct wpa_driver_auth_params params;
Dmitry Shmidtcce06662013-11-04 18:44:24 -08003049 struct i802_bss *bss = drv->first_bss;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003050 int i;
3051
3052 wpa_printf(MSG_DEBUG, "nl80211: Try to authenticate again");
3053
3054 os_memset(&params, 0, sizeof(params));
3055 params.freq = drv->auth_freq;
3056 params.auth_alg = drv->auth_alg;
3057 params.wep_tx_keyidx = drv->auth_wep_tx_keyidx;
3058 params.local_state_change = drv->auth_local_state_change;
3059 params.p2p = drv->auth_p2p;
3060
3061 if (!is_zero_ether_addr(drv->auth_bssid_))
3062 params.bssid = drv->auth_bssid_;
3063
3064 if (drv->auth_ssid_len) {
3065 params.ssid = drv->auth_ssid;
3066 params.ssid_len = drv->auth_ssid_len;
3067 }
3068
3069 params.ie = drv->auth_ie;
3070 params.ie_len = drv->auth_ie_len;
3071
3072 for (i = 0; i < 4; i++) {
3073 if (drv->auth_wep_key_len[i]) {
3074 params.wep_key[i] = drv->auth_wep_key[i];
3075 params.wep_key_len[i] = drv->auth_wep_key_len[i];
3076 }
3077 }
3078
3079 drv->retry_auth = 1;
3080 return wpa_driver_nl80211_authenticate(bss, &params);
3081}
3082
3083
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003084static int wpa_driver_nl80211_send_frame(struct i802_bss *bss,
3085 const void *data, size_t len,
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08003086 int encrypt, int noack,
3087 unsigned int freq, int no_cck,
3088 int offchanok, unsigned int wait_time)
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003089{
3090 struct wpa_driver_nl80211_data *drv = bss->drv;
3091 u64 cookie;
Dmitry Shmidt051af732013-10-22 13:52:46 -07003092 int res;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003093
Dmitry Shmidt6dc03bd2014-05-16 10:40:13 -07003094 if (freq == 0 && drv->nlmode == NL80211_IFTYPE_ADHOC) {
3095 freq = nl80211_get_assoc_freq(drv);
3096 wpa_printf(MSG_DEBUG,
3097 "nl80211: send_frame - Use assoc_freq=%u for IBSS",
3098 freq);
3099 }
Dmitry Shmidt56052862013-10-04 10:23:25 -07003100 if (freq == 0) {
3101 wpa_printf(MSG_DEBUG, "nl80211: send_frame - Use bss->freq=%u",
3102 bss->freq);
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08003103 freq = bss->freq;
Dmitry Shmidt56052862013-10-04 10:23:25 -07003104 }
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08003105
Dmitry Shmidt56052862013-10-04 10:23:25 -07003106 if (drv->use_monitor) {
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003107 wpa_printf(MSG_DEBUG, "nl80211: send_frame(freq=%u bss->freq=%u) -> send_monitor",
Dmitry Shmidt56052862013-10-04 10:23:25 -07003108 freq, bss->freq);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003109 return nl80211_send_monitor(drv, data, len, encrypt, noack);
Dmitry Shmidt56052862013-10-04 10:23:25 -07003110 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003111
Dmitry Shmidt56052862013-10-04 10:23:25 -07003112 wpa_printf(MSG_DEBUG, "nl80211: send_frame -> send_frame_cmd");
Dmitry Shmidt051af732013-10-22 13:52:46 -07003113 res = nl80211_send_frame_cmd(bss, freq, wait_time, data, len,
3114 &cookie, no_cck, noack, offchanok);
3115 if (res == 0 && !noack) {
3116 const struct ieee80211_mgmt *mgmt;
3117 u16 fc;
3118
3119 mgmt = (const struct ieee80211_mgmt *) data;
3120 fc = le_to_host16(mgmt->frame_control);
3121 if (WLAN_FC_GET_TYPE(fc) == WLAN_FC_TYPE_MGMT &&
3122 WLAN_FC_GET_STYPE(fc) == WLAN_FC_STYPE_ACTION) {
3123 wpa_printf(MSG_MSGDUMP,
3124 "nl80211: Update send_action_cookie from 0x%llx to 0x%llx",
3125 (long long unsigned int)
3126 drv->send_action_cookie,
3127 (long long unsigned int) cookie);
3128 drv->send_action_cookie = cookie;
3129 }
3130 }
3131
3132 return res;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003133}
3134
3135
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08003136static int wpa_driver_nl80211_send_mlme(struct i802_bss *bss, const u8 *data,
3137 size_t data_len, int noack,
3138 unsigned int freq, int no_cck,
3139 int offchanok,
3140 unsigned int wait_time)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003141{
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003142 struct wpa_driver_nl80211_data *drv = bss->drv;
3143 struct ieee80211_mgmt *mgmt;
3144 int encrypt = 1;
3145 u16 fc;
3146
3147 mgmt = (struct ieee80211_mgmt *) data;
3148 fc = le_to_host16(mgmt->frame_control);
Dmitry Shmidt2271d3f2014-06-23 12:16:31 -07003149 wpa_printf(MSG_DEBUG, "nl80211: send_mlme - da= " MACSTR
3150 " noack=%d freq=%u no_cck=%d offchanok=%d wait_time=%u fc=0x%x (%s) nlmode=%d",
3151 MAC2STR(mgmt->da), noack, freq, no_cck, offchanok, wait_time,
3152 fc, fc2str(fc), drv->nlmode);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003153
Dmitry Shmidt34af3062013-07-11 10:46:32 -07003154 if ((is_sta_interface(drv->nlmode) ||
3155 drv->nlmode == NL80211_IFTYPE_P2P_DEVICE) &&
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003156 WLAN_FC_GET_TYPE(fc) == WLAN_FC_TYPE_MGMT &&
3157 WLAN_FC_GET_STYPE(fc) == WLAN_FC_STYPE_PROBE_RESP) {
3158 /*
3159 * The use of last_mgmt_freq is a bit of a hack,
3160 * but it works due to the single-threaded nature
3161 * of wpa_supplicant.
3162 */
Dmitry Shmidt56052862013-10-04 10:23:25 -07003163 if (freq == 0) {
3164 wpa_printf(MSG_DEBUG, "nl80211: Use last_mgmt_freq=%d",
3165 drv->last_mgmt_freq);
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08003166 freq = drv->last_mgmt_freq;
Dmitry Shmidt56052862013-10-04 10:23:25 -07003167 }
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08003168 return nl80211_send_frame_cmd(bss, freq, 0,
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003169 data, data_len, NULL, 1, noack,
3170 1);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003171 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003172
3173 if (drv->device_ap_sme && is_ap_interface(drv->nlmode)) {
Dmitry Shmidt56052862013-10-04 10:23:25 -07003174 if (freq == 0) {
3175 wpa_printf(MSG_DEBUG, "nl80211: Use bss->freq=%d",
3176 bss->freq);
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08003177 freq = bss->freq;
Dmitry Shmidt56052862013-10-04 10:23:25 -07003178 }
Dmitry Shmidt04949592012-07-19 12:16:46 -07003179 return nl80211_send_frame_cmd(bss, freq,
3180 (int) freq == bss->freq ? 0 :
3181 wait_time,
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08003182 data, data_len,
3183 &drv->send_action_cookie,
3184 no_cck, noack, offchanok);
Dmitry Shmidt6e933c12011-09-27 12:29:26 -07003185 }
Dmitry Shmidtb638fe72012-03-20 12:51:25 -07003186
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003187 if (WLAN_FC_GET_TYPE(fc) == WLAN_FC_TYPE_MGMT &&
3188 WLAN_FC_GET_STYPE(fc) == WLAN_FC_STYPE_AUTH) {
3189 /*
3190 * Only one of the authentication frame types is encrypted.
3191 * In order for static WEP encryption to work properly (i.e.,
3192 * to not encrypt the frame), we need to tell mac80211 about
3193 * the frames that must not be encrypted.
3194 */
3195 u16 auth_alg = le_to_host16(mgmt->u.auth.auth_alg);
3196 u16 auth_trans = le_to_host16(mgmt->u.auth.auth_transaction);
3197 if (auth_alg != WLAN_AUTH_SHARED_KEY || auth_trans != 3)
3198 encrypt = 0;
3199 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003200
Dmitry Shmidt56052862013-10-04 10:23:25 -07003201 wpa_printf(MSG_DEBUG, "nl80211: send_mlme -> send_frame");
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003202 return wpa_driver_nl80211_send_frame(bss, data, data_len, encrypt,
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08003203 noack, freq, no_cck, offchanok,
3204 wait_time);
3205}
3206
3207
Dmitry Shmidtff787d52015-01-12 13:01:47 -08003208static int nl80211_put_basic_rates(struct nl_msg *msg, const int *basic_rates)
3209{
3210 u8 rates[NL80211_MAX_SUPP_RATES];
3211 u8 rates_len = 0;
3212 int i;
3213
3214 if (!basic_rates)
3215 return 0;
3216
3217 for (i = 0; i < NL80211_MAX_SUPP_RATES && basic_rates[i] >= 0; i++)
3218 rates[rates_len++] = basic_rates[i] / 5;
3219
3220 return nla_put(msg, NL80211_ATTR_BSS_BASIC_RATES, rates_len, rates);
3221}
3222
3223
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003224static int nl80211_set_bss(struct i802_bss *bss, int cts, int preamble,
3225 int slot, int ht_opmode, int ap_isolate,
Dmitry Shmidtff787d52015-01-12 13:01:47 -08003226 const int *basic_rates)
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003227{
3228 struct wpa_driver_nl80211_data *drv = bss->drv;
3229 struct nl_msg *msg;
3230
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003231 if (!(msg = nl80211_bss_msg(bss, 0, NL80211_CMD_SET_BSS)) ||
3232 (cts >= 0 &&
3233 nla_put_u8(msg, NL80211_ATTR_BSS_CTS_PROT, cts)) ||
3234 (preamble >= 0 &&
3235 nla_put_u8(msg, NL80211_ATTR_BSS_SHORT_PREAMBLE, preamble)) ||
3236 (slot >= 0 &&
3237 nla_put_u8(msg, NL80211_ATTR_BSS_SHORT_SLOT_TIME, slot)) ||
3238 (ht_opmode >= 0 &&
3239 nla_put_u16(msg, NL80211_ATTR_BSS_HT_OPMODE, ht_opmode)) ||
3240 (ap_isolate >= 0 &&
Dmitry Shmidtff787d52015-01-12 13:01:47 -08003241 nla_put_u8(msg, NL80211_ATTR_AP_ISOLATE, ap_isolate)) ||
3242 nl80211_put_basic_rates(msg, basic_rates)) {
3243 nlmsg_free(msg);
3244 return -ENOBUFS;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003245 }
3246
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003247 return send_and_recv_msgs(drv, msg, NULL, NULL);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003248}
3249
3250
Dmitry Shmidt8bae4132013-06-06 11:25:10 -07003251static int wpa_driver_nl80211_set_acl(void *priv,
3252 struct hostapd_acl_params *params)
3253{
3254 struct i802_bss *bss = priv;
3255 struct wpa_driver_nl80211_data *drv = bss->drv;
3256 struct nl_msg *msg;
3257 struct nlattr *acl;
3258 unsigned int i;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003259 int ret;
Dmitry Shmidt8bae4132013-06-06 11:25:10 -07003260
3261 if (!(drv->capa.max_acl_mac_addrs))
3262 return -ENOTSUP;
3263
3264 if (params->num_mac_acl > drv->capa.max_acl_mac_addrs)
3265 return -ENOTSUP;
3266
Dmitry Shmidt8bae4132013-06-06 11:25:10 -07003267 wpa_printf(MSG_DEBUG, "nl80211: Set %s ACL (num_mac_acl=%u)",
3268 params->acl_policy ? "Accept" : "Deny", params->num_mac_acl);
3269
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003270 if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_SET_MAC_ACL)) ||
3271 nla_put_u32(msg, NL80211_ATTR_ACL_POLICY, params->acl_policy ?
3272 NL80211_ACL_POLICY_DENY_UNLESS_LISTED :
3273 NL80211_ACL_POLICY_ACCEPT_UNLESS_LISTED) ||
3274 (acl = nla_nest_start(msg, NL80211_ATTR_MAC_ADDRS)) == NULL) {
3275 nlmsg_free(msg);
3276 return -ENOMEM;
3277 }
Dmitry Shmidt8bae4132013-06-06 11:25:10 -07003278
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003279 for (i = 0; i < params->num_mac_acl; i++) {
3280 if (nla_put(msg, i + 1, ETH_ALEN, params->mac_acl[i].addr)) {
3281 nlmsg_free(msg);
3282 return -ENOMEM;
3283 }
3284 }
Dmitry Shmidt8bae4132013-06-06 11:25:10 -07003285
3286 nla_nest_end(msg, acl);
3287
3288 ret = send_and_recv_msgs(drv, msg, NULL, NULL);
Dmitry Shmidt8bae4132013-06-06 11:25:10 -07003289 if (ret) {
3290 wpa_printf(MSG_DEBUG, "nl80211: Failed to set MAC ACL: %d (%s)",
3291 ret, strerror(-ret));
3292 }
3293
Dmitry Shmidt8bae4132013-06-06 11:25:10 -07003294 return ret;
3295}
3296
3297
Dmitry Shmidtff787d52015-01-12 13:01:47 -08003298static int nl80211_put_beacon_int(struct nl_msg *msg, int beacon_int)
3299{
3300 if (beacon_int > 0) {
3301 wpa_printf(MSG_DEBUG, " * beacon_int=%d", beacon_int);
3302 return nla_put_u32(msg, NL80211_ATTR_BEACON_INTERVAL,
3303 beacon_int);
3304 }
3305
3306 return 0;
3307}
3308
3309
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003310static int wpa_driver_nl80211_set_ap(void *priv,
3311 struct wpa_driver_ap_params *params)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003312{
3313 struct i802_bss *bss = priv;
3314 struct wpa_driver_nl80211_data *drv = bss->drv;
3315 struct nl_msg *msg;
3316 u8 cmd = NL80211_CMD_NEW_BEACON;
3317 int ret;
3318 int beacon_set;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003319 int num_suites;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003320 int smps_mode;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08003321 u32 suites[10], suite;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003322 u32 ver;
3323
Dmitry Shmidt7f656022015-02-25 14:36:37 -08003324 beacon_set = params->reenable ? 0 : bss->beacon_set;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003325
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003326 wpa_printf(MSG_DEBUG, "nl80211: Set beacon (beacon_set=%d)",
3327 beacon_set);
3328 if (beacon_set)
3329 cmd = NL80211_CMD_SET_BEACON;
3330
Dmitry Shmidt0ccb66e2013-03-29 16:41:28 -07003331 wpa_hexdump(MSG_DEBUG, "nl80211: Beacon head",
3332 params->head, params->head_len);
Dmitry Shmidt0ccb66e2013-03-29 16:41:28 -07003333 wpa_hexdump(MSG_DEBUG, "nl80211: Beacon tail",
3334 params->tail, params->tail_len);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003335 wpa_printf(MSG_DEBUG, "nl80211: ifindex=%d", bss->ifindex);
Dmitry Shmidt0ccb66e2013-03-29 16:41:28 -07003336 wpa_printf(MSG_DEBUG, "nl80211: beacon_int=%d", params->beacon_int);
Dmitry Shmidt0ccb66e2013-03-29 16:41:28 -07003337 wpa_printf(MSG_DEBUG, "nl80211: dtim_period=%d", params->dtim_period);
Dmitry Shmidt0ccb66e2013-03-29 16:41:28 -07003338 wpa_hexdump_ascii(MSG_DEBUG, "nl80211: ssid",
3339 params->ssid, params->ssid_len);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003340 if (!(msg = nl80211_bss_msg(bss, 0, cmd)) ||
3341 nla_put(msg, NL80211_ATTR_BEACON_HEAD, params->head_len,
3342 params->head) ||
3343 nla_put(msg, NL80211_ATTR_BEACON_TAIL, params->tail_len,
3344 params->tail) ||
Dmitry Shmidtff787d52015-01-12 13:01:47 -08003345 nl80211_put_beacon_int(msg, params->beacon_int) ||
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003346 nla_put_u32(msg, NL80211_ATTR_DTIM_PERIOD, params->dtim_period) ||
3347 nla_put(msg, NL80211_ATTR_SSID, params->ssid_len, params->ssid))
3348 goto fail;
Dmitry Shmidt0ccb66e2013-03-29 16:41:28 -07003349 if (params->proberesp && params->proberesp_len) {
3350 wpa_hexdump(MSG_DEBUG, "nl80211: proberesp (offload)",
3351 params->proberesp, params->proberesp_len);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003352 if (nla_put(msg, NL80211_ATTR_PROBE_RESP, params->proberesp_len,
3353 params->proberesp))
3354 goto fail;
Dmitry Shmidt0ccb66e2013-03-29 16:41:28 -07003355 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003356 switch (params->hide_ssid) {
3357 case NO_SSID_HIDING:
Dmitry Shmidt0ccb66e2013-03-29 16:41:28 -07003358 wpa_printf(MSG_DEBUG, "nl80211: hidden SSID not in use");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003359 if (nla_put_u32(msg, NL80211_ATTR_HIDDEN_SSID,
3360 NL80211_HIDDEN_SSID_NOT_IN_USE))
3361 goto fail;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003362 break;
3363 case HIDDEN_SSID_ZERO_LEN:
Dmitry Shmidt0ccb66e2013-03-29 16:41:28 -07003364 wpa_printf(MSG_DEBUG, "nl80211: hidden SSID zero len");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003365 if (nla_put_u32(msg, NL80211_ATTR_HIDDEN_SSID,
3366 NL80211_HIDDEN_SSID_ZERO_LEN))
3367 goto fail;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003368 break;
3369 case HIDDEN_SSID_ZERO_CONTENTS:
Dmitry Shmidt0ccb66e2013-03-29 16:41:28 -07003370 wpa_printf(MSG_DEBUG, "nl80211: hidden SSID zero contents");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003371 if (nla_put_u32(msg, NL80211_ATTR_HIDDEN_SSID,
3372 NL80211_HIDDEN_SSID_ZERO_CONTENTS))
3373 goto fail;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003374 break;
3375 }
Dmitry Shmidt0ccb66e2013-03-29 16:41:28 -07003376 wpa_printf(MSG_DEBUG, "nl80211: privacy=%d", params->privacy);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003377 if (params->privacy &&
3378 nla_put_flag(msg, NL80211_ATTR_PRIVACY))
3379 goto fail;
Dmitry Shmidt0ccb66e2013-03-29 16:41:28 -07003380 wpa_printf(MSG_DEBUG, "nl80211: auth_algs=0x%x", params->auth_algs);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003381 if ((params->auth_algs & (WPA_AUTH_ALG_OPEN | WPA_AUTH_ALG_SHARED)) ==
3382 (WPA_AUTH_ALG_OPEN | WPA_AUTH_ALG_SHARED)) {
3383 /* Leave out the attribute */
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003384 } else if (params->auth_algs & WPA_AUTH_ALG_SHARED) {
3385 if (nla_put_u32(msg, NL80211_ATTR_AUTH_TYPE,
3386 NL80211_AUTHTYPE_SHARED_KEY))
3387 goto fail;
3388 } else {
3389 if (nla_put_u32(msg, NL80211_ATTR_AUTH_TYPE,
3390 NL80211_AUTHTYPE_OPEN_SYSTEM))
3391 goto fail;
3392 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003393
Dmitry Shmidt0ccb66e2013-03-29 16:41:28 -07003394 wpa_printf(MSG_DEBUG, "nl80211: wpa_version=0x%x", params->wpa_version);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003395 ver = 0;
3396 if (params->wpa_version & WPA_PROTO_WPA)
3397 ver |= NL80211_WPA_VERSION_1;
3398 if (params->wpa_version & WPA_PROTO_RSN)
3399 ver |= NL80211_WPA_VERSION_2;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003400 if (ver &&
3401 nla_put_u32(msg, NL80211_ATTR_WPA_VERSIONS, ver))
3402 goto fail;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003403
Dmitry Shmidt0ccb66e2013-03-29 16:41:28 -07003404 wpa_printf(MSG_DEBUG, "nl80211: key_mgmt_suites=0x%x",
3405 params->key_mgmt_suites);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003406 num_suites = 0;
3407 if (params->key_mgmt_suites & WPA_KEY_MGMT_IEEE8021X)
3408 suites[num_suites++] = WLAN_AKM_SUITE_8021X;
3409 if (params->key_mgmt_suites & WPA_KEY_MGMT_PSK)
3410 suites[num_suites++] = WLAN_AKM_SUITE_PSK;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003411 if (num_suites &&
3412 nla_put(msg, NL80211_ATTR_AKM_SUITES, num_suites * sizeof(u32),
3413 suites))
3414 goto fail;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003415
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003416 if (params->key_mgmt_suites & WPA_KEY_MGMT_IEEE8021X_NO_WPA &&
3417 params->pairwise_ciphers & (WPA_CIPHER_WEP104 | WPA_CIPHER_WEP40) &&
3418 nla_put_flag(msg, NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT))
3419 goto fail;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003420
Dmitry Shmidt0ccb66e2013-03-29 16:41:28 -07003421 wpa_printf(MSG_DEBUG, "nl80211: pairwise_ciphers=0x%x",
3422 params->pairwise_ciphers);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08003423 num_suites = wpa_cipher_to_cipher_suites(params->pairwise_ciphers,
3424 suites, ARRAY_SIZE(suites));
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003425 if (num_suites &&
3426 nla_put(msg, NL80211_ATTR_CIPHER_SUITES_PAIRWISE,
3427 num_suites * sizeof(u32), suites))
3428 goto fail;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003429
Dmitry Shmidt0ccb66e2013-03-29 16:41:28 -07003430 wpa_printf(MSG_DEBUG, "nl80211: group_cipher=0x%x",
3431 params->group_cipher);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08003432 suite = wpa_cipher_to_cipher_suite(params->group_cipher);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003433 if (suite &&
3434 nla_put_u32(msg, NL80211_ATTR_CIPHER_SUITE_GROUP, suite))
3435 goto fail;
3436
3437 switch (params->smps_mode) {
3438 case HT_CAP_INFO_SMPS_DYNAMIC:
3439 wpa_printf(MSG_DEBUG, "nl80211: SMPS mode - dynamic");
3440 smps_mode = NL80211_SMPS_DYNAMIC;
3441 break;
3442 case HT_CAP_INFO_SMPS_STATIC:
3443 wpa_printf(MSG_DEBUG, "nl80211: SMPS mode - static");
3444 smps_mode = NL80211_SMPS_STATIC;
3445 break;
3446 default:
3447 /* invalid - fallback to smps off */
3448 case HT_CAP_INFO_SMPS_DISABLED:
3449 wpa_printf(MSG_DEBUG, "nl80211: SMPS mode - off");
3450 smps_mode = NL80211_SMPS_OFF;
3451 break;
3452 }
3453 if (nla_put_u32(msg, NL80211_ATTR_SMPS_MODE, smps_mode))
3454 goto fail;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003455
3456 if (params->beacon_ies) {
Dmitry Shmidt0ccb66e2013-03-29 16:41:28 -07003457 wpa_hexdump_buf(MSG_DEBUG, "nl80211: beacon_ies",
3458 params->beacon_ies);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003459 if (nla_put(msg, NL80211_ATTR_IE,
3460 wpabuf_len(params->beacon_ies),
3461 wpabuf_head(params->beacon_ies)))
3462 goto fail;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003463 }
3464 if (params->proberesp_ies) {
Dmitry Shmidt0ccb66e2013-03-29 16:41:28 -07003465 wpa_hexdump_buf(MSG_DEBUG, "nl80211: proberesp_ies",
3466 params->proberesp_ies);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003467 if (nla_put(msg, NL80211_ATTR_IE_PROBE_RESP,
3468 wpabuf_len(params->proberesp_ies),
3469 wpabuf_head(params->proberesp_ies)))
3470 goto fail;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003471 }
3472 if (params->assocresp_ies) {
Dmitry Shmidt0ccb66e2013-03-29 16:41:28 -07003473 wpa_hexdump_buf(MSG_DEBUG, "nl80211: assocresp_ies",
3474 params->assocresp_ies);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003475 if (nla_put(msg, NL80211_ATTR_IE_ASSOC_RESP,
3476 wpabuf_len(params->assocresp_ies),
3477 wpabuf_head(params->assocresp_ies)))
3478 goto fail;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003479 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003480
Dmitry Shmidt04949592012-07-19 12:16:46 -07003481 if (drv->capa.flags & WPA_DRIVER_FLAGS_INACTIVITY_TIMER) {
Dmitry Shmidt0ccb66e2013-03-29 16:41:28 -07003482 wpa_printf(MSG_DEBUG, "nl80211: ap_max_inactivity=%d",
3483 params->ap_max_inactivity);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003484 if (nla_put_u16(msg, NL80211_ATTR_INACTIVITY_TIMEOUT,
3485 params->ap_max_inactivity))
3486 goto fail;
Dmitry Shmidt04949592012-07-19 12:16:46 -07003487 }
3488
Dmitry Shmidt7f656022015-02-25 14:36:37 -08003489#ifdef CONFIG_P2P
3490 if (params->p2p_go_ctwindow > 0) {
3491 if (drv->p2p_go_ctwindow_supported) {
3492 wpa_printf(MSG_DEBUG, "nl80211: P2P GO ctwindow=%d",
3493 params->p2p_go_ctwindow);
3494 if (nla_put_u8(msg, NL80211_ATTR_P2P_CTWINDOW,
3495 params->p2p_go_ctwindow))
3496 goto fail;
3497 } else {
3498 wpa_printf(MSG_INFO,
3499 "nl80211: Driver does not support CTWindow configuration - ignore this parameter");
3500 }
3501 }
3502#endif /* CONFIG_P2P */
3503
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003504 ret = send_and_recv_msgs(drv, msg, NULL, NULL);
3505 if (ret) {
3506 wpa_printf(MSG_DEBUG, "nl80211: Beacon set failed: %d (%s)",
3507 ret, strerror(-ret));
3508 } else {
3509 bss->beacon_set = 1;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003510 nl80211_set_bss(bss, params->cts_protect, params->preamble,
3511 params->short_slot_time, params->ht_opmode,
3512 params->isolate, params->basic_rates);
Dmitry Shmidt7832adb2014-04-29 10:53:02 -07003513 if (beacon_set && params->freq &&
3514 params->freq->bandwidth != bss->bandwidth) {
3515 wpa_printf(MSG_DEBUG,
3516 "nl80211: Update BSS %s bandwidth: %d -> %d",
3517 bss->ifname, bss->bandwidth,
3518 params->freq->bandwidth);
3519 ret = nl80211_set_channel(bss, params->freq, 1);
3520 if (ret) {
3521 wpa_printf(MSG_DEBUG,
3522 "nl80211: Frequency set failed: %d (%s)",
3523 ret, strerror(-ret));
3524 } else {
3525 wpa_printf(MSG_DEBUG,
3526 "nl80211: Frequency set succeeded for ht2040 coex");
3527 bss->bandwidth = params->freq->bandwidth;
3528 }
3529 } else if (!beacon_set) {
3530 /*
3531 * cfg80211 updates the driver on frequence change in AP
3532 * mode only at the point when beaconing is started, so
3533 * set the initial value here.
3534 */
3535 bss->bandwidth = params->freq->bandwidth;
3536 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003537 }
3538 return ret;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003539fail:
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003540 nlmsg_free(msg);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003541 return -ENOBUFS;
3542}
3543
3544
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08003545static int nl80211_put_freq_params(struct nl_msg *msg,
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003546 const struct hostapd_freq_params *freq)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003547{
Dmitry Shmidtff787d52015-01-12 13:01:47 -08003548 wpa_printf(MSG_DEBUG, " * freq=%d", freq->freq);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003549 if (nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq->freq))
3550 return -ENOBUFS;
3551
Dmitry Shmidtff787d52015-01-12 13:01:47 -08003552 wpa_printf(MSG_DEBUG, " * vht_enabled=%d", freq->vht_enabled);
3553 wpa_printf(MSG_DEBUG, " * ht_enabled=%d", freq->ht_enabled);
3554
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08003555 if (freq->vht_enabled) {
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003556 enum nl80211_chan_width cw;
3557
Dmitry Shmidtff787d52015-01-12 13:01:47 -08003558 wpa_printf(MSG_DEBUG, " * bandwidth=%d", freq->bandwidth);
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08003559 switch (freq->bandwidth) {
3560 case 20:
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003561 cw = NL80211_CHAN_WIDTH_20;
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08003562 break;
3563 case 40:
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003564 cw = NL80211_CHAN_WIDTH_40;
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08003565 break;
3566 case 80:
3567 if (freq->center_freq2)
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003568 cw = NL80211_CHAN_WIDTH_80P80;
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08003569 else
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003570 cw = NL80211_CHAN_WIDTH_80;
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08003571 break;
3572 case 160:
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003573 cw = NL80211_CHAN_WIDTH_160;
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08003574 break;
3575 default:
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08003576 return -EINVAL;
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08003577 }
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003578
Dmitry Shmidtff787d52015-01-12 13:01:47 -08003579 wpa_printf(MSG_DEBUG, " * channel_width=%d", cw);
3580 wpa_printf(MSG_DEBUG, " * center_freq1=%d",
3581 freq->center_freq1);
3582 wpa_printf(MSG_DEBUG, " * center_freq2=%d",
3583 freq->center_freq2);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003584 if (nla_put_u32(msg, NL80211_ATTR_CHANNEL_WIDTH, cw) ||
3585 nla_put_u32(msg, NL80211_ATTR_CENTER_FREQ1,
3586 freq->center_freq1) ||
3587 (freq->center_freq2 &&
3588 nla_put_u32(msg, NL80211_ATTR_CENTER_FREQ2,
3589 freq->center_freq2)))
3590 return -ENOBUFS;
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08003591 } else if (freq->ht_enabled) {
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003592 enum nl80211_channel_type ct;
3593
Dmitry Shmidtff787d52015-01-12 13:01:47 -08003594 wpa_printf(MSG_DEBUG, " * sec_channel_offset=%d",
3595 freq->sec_channel_offset);
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08003596 switch (freq->sec_channel_offset) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003597 case -1:
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003598 ct = NL80211_CHAN_HT40MINUS;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003599 break;
3600 case 1:
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003601 ct = NL80211_CHAN_HT40PLUS;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003602 break;
3603 default:
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003604 ct = NL80211_CHAN_HT20;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003605 break;
3606 }
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003607
Dmitry Shmidtff787d52015-01-12 13:01:47 -08003608 wpa_printf(MSG_DEBUG, " * channel_type=%d", ct);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003609 if (nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE, ct))
3610 return -ENOBUFS;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003611 }
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08003612 return 0;
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08003613}
3614
3615
Dmitry Shmidt7832adb2014-04-29 10:53:02 -07003616static int nl80211_set_channel(struct i802_bss *bss,
3617 struct hostapd_freq_params *freq, int set_chan)
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08003618{
3619 struct wpa_driver_nl80211_data *drv = bss->drv;
3620 struct nl_msg *msg;
3621 int ret;
3622
3623 wpa_printf(MSG_DEBUG,
3624 "nl80211: Set freq %d (ht_enabled=%d, vht_enabled=%d, bandwidth=%d MHz, cf1=%d MHz, cf2=%d MHz)",
3625 freq->freq, freq->ht_enabled, freq->vht_enabled,
3626 freq->bandwidth, freq->center_freq1, freq->center_freq2);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003627
3628 msg = nl80211_drv_msg(drv, 0, set_chan ? NL80211_CMD_SET_CHANNEL :
3629 NL80211_CMD_SET_WIPHY);
3630 if (!msg || nl80211_put_freq_params(msg, freq) < 0) {
3631 nlmsg_free(msg);
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08003632 return -1;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003633 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003634
3635 ret = send_and_recv_msgs(drv, msg, NULL, NULL);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003636 if (ret == 0) {
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08003637 bss->freq = freq->freq;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003638 return 0;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003639 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003640 wpa_printf(MSG_DEBUG, "nl80211: Failed to set channel (freq=%d): "
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08003641 "%d (%s)", freq->freq, ret, strerror(-ret));
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003642 return -1;
3643}
3644
3645
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003646static u32 sta_flags_nl80211(int flags)
3647{
3648 u32 f = 0;
3649
3650 if (flags & WPA_STA_AUTHORIZED)
3651 f |= BIT(NL80211_STA_FLAG_AUTHORIZED);
3652 if (flags & WPA_STA_WMM)
3653 f |= BIT(NL80211_STA_FLAG_WME);
3654 if (flags & WPA_STA_SHORT_PREAMBLE)
3655 f |= BIT(NL80211_STA_FLAG_SHORT_PREAMBLE);
3656 if (flags & WPA_STA_MFP)
3657 f |= BIT(NL80211_STA_FLAG_MFP);
3658 if (flags & WPA_STA_TDLS_PEER)
3659 f |= BIT(NL80211_STA_FLAG_TDLS_PEER);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003660 if (flags & WPA_STA_AUTHENTICATED)
3661 f |= BIT(NL80211_STA_FLAG_AUTHENTICATED);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003662
3663 return f;
3664}
3665
3666
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003667#ifdef CONFIG_MESH
3668static u32 sta_plink_state_nl80211(enum mesh_plink_state state)
3669{
3670 switch (state) {
3671 case PLINK_LISTEN:
3672 return NL80211_PLINK_LISTEN;
3673 case PLINK_OPEN_SENT:
3674 return NL80211_PLINK_OPN_SNT;
3675 case PLINK_OPEN_RCVD:
3676 return NL80211_PLINK_OPN_RCVD;
3677 case PLINK_CNF_RCVD:
3678 return NL80211_PLINK_CNF_RCVD;
3679 case PLINK_ESTAB:
3680 return NL80211_PLINK_ESTAB;
3681 case PLINK_HOLDING:
3682 return NL80211_PLINK_HOLDING;
3683 case PLINK_BLOCKED:
3684 return NL80211_PLINK_BLOCKED;
3685 default:
3686 wpa_printf(MSG_ERROR, "nl80211: Invalid mesh plink state %d",
3687 state);
3688 }
3689 return -1;
3690}
3691#endif /* CONFIG_MESH */
3692
3693
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003694static int wpa_driver_nl80211_sta_add(void *priv,
3695 struct hostapd_sta_add_params *params)
3696{
3697 struct i802_bss *bss = priv;
3698 struct wpa_driver_nl80211_data *drv = bss->drv;
Dmitry Shmidt8da800a2013-04-24 12:57:01 -07003699 struct nl_msg *msg;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003700 struct nl80211_sta_flag_update upd;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003701 int ret = -ENOBUFS;
3702
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003703 if ((params->flags & WPA_STA_TDLS_PEER) &&
3704 !(drv->capa.flags & WPA_DRIVER_FLAGS_TDLS_SUPPORT))
3705 return -EOPNOTSUPP;
3706
Dmitry Shmidtf8623282013-02-20 14:34:59 -08003707 wpa_printf(MSG_DEBUG, "nl80211: %s STA " MACSTR,
3708 params->set ? "Set" : "Add", MAC2STR(params->addr));
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003709 msg = nl80211_bss_msg(bss, 0, params->set ? NL80211_CMD_SET_STATION :
3710 NL80211_CMD_NEW_STATION);
3711 if (!msg || nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, params->addr))
3712 goto fail;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003713
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003714 if (!params->set || (params->flags & WPA_STA_TDLS_PEER)) {
3715 wpa_hexdump(MSG_DEBUG, " * supported rates",
3716 params->supp_rates, params->supp_rates_len);
3717 wpa_printf(MSG_DEBUG, " * capability=0x%x",
3718 params->capability);
3719 if (nla_put(msg, NL80211_ATTR_STA_SUPPORTED_RATES,
3720 params->supp_rates_len, params->supp_rates) ||
3721 nla_put_u16(msg, NL80211_ATTR_STA_CAPABILITY,
3722 params->capability))
3723 goto fail;
3724
3725 if (params->ht_capabilities) {
3726 wpa_hexdump(MSG_DEBUG, " * ht_capabilities",
3727 (u8 *) params->ht_capabilities,
3728 sizeof(*params->ht_capabilities));
3729 if (nla_put(msg, NL80211_ATTR_HT_CAPABILITY,
3730 sizeof(*params->ht_capabilities),
3731 params->ht_capabilities))
3732 goto fail;
3733 }
3734
3735 if (params->vht_capabilities) {
3736 wpa_hexdump(MSG_DEBUG, " * vht_capabilities",
3737 (u8 *) params->vht_capabilities,
3738 sizeof(*params->vht_capabilities));
3739 if (nla_put(msg, NL80211_ATTR_VHT_CAPABILITY,
3740 sizeof(*params->vht_capabilities),
3741 params->vht_capabilities))
3742 goto fail;
3743 }
3744
3745 if (params->ext_capab) {
3746 wpa_hexdump(MSG_DEBUG, " * ext_capab",
3747 params->ext_capab, params->ext_capab_len);
3748 if (nla_put(msg, NL80211_ATTR_STA_EXT_CAPABILITY,
3749 params->ext_capab_len, params->ext_capab))
3750 goto fail;
3751 }
3752 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003753 if (!params->set) {
Dmitry Shmidt51b6ea82013-05-08 10:42:09 -07003754 if (params->aid) {
3755 wpa_printf(MSG_DEBUG, " * aid=%u", params->aid);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003756 if (nla_put_u16(msg, NL80211_ATTR_STA_AID, params->aid))
3757 goto fail;
Dmitry Shmidt51b6ea82013-05-08 10:42:09 -07003758 } else {
3759 /*
3760 * cfg80211 validates that AID is non-zero, so we have
3761 * to make this a non-zero value for the TDLS case where
3762 * a dummy STA entry is used for now.
3763 */
3764 wpa_printf(MSG_DEBUG, " * aid=1 (TDLS workaround)");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003765 if (nla_put_u16(msg, NL80211_ATTR_STA_AID, 1))
3766 goto fail;
Dmitry Shmidt51b6ea82013-05-08 10:42:09 -07003767 }
Dmitry Shmidtf8623282013-02-20 14:34:59 -08003768 wpa_printf(MSG_DEBUG, " * listen_interval=%u",
3769 params->listen_interval);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003770 if (nla_put_u16(msg, NL80211_ATTR_STA_LISTEN_INTERVAL,
3771 params->listen_interval))
3772 goto fail;
Dmitry Shmidt8bae4132013-06-06 11:25:10 -07003773 } else if (params->aid && (params->flags & WPA_STA_TDLS_PEER)) {
3774 wpa_printf(MSG_DEBUG, " * peer_aid=%u", params->aid);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003775 if (nla_put_u16(msg, NL80211_ATTR_PEER_AID, params->aid))
3776 goto fail;
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08003777 }
3778
Dmitry Shmidtbd14a572014-02-18 10:33:49 -08003779 if (params->vht_opmode_enabled) {
3780 wpa_printf(MSG_DEBUG, " * opmode=%u", params->vht_opmode);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003781 if (nla_put_u8(msg, NL80211_ATTR_OPMODE_NOTIF,
3782 params->vht_opmode))
3783 goto fail;
Dmitry Shmidtf8623282013-02-20 14:34:59 -08003784 }
3785
Dmitry Shmidt344abd32014-01-14 13:17:00 -08003786 if (params->supp_channels) {
3787 wpa_hexdump(MSG_DEBUG, " * supported channels",
3788 params->supp_channels, params->supp_channels_len);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003789 if (nla_put(msg, NL80211_ATTR_STA_SUPPORTED_CHANNELS,
3790 params->supp_channels_len, params->supp_channels))
3791 goto fail;
Dmitry Shmidt344abd32014-01-14 13:17:00 -08003792 }
3793
3794 if (params->supp_oper_classes) {
3795 wpa_hexdump(MSG_DEBUG, " * supported operating classes",
3796 params->supp_oper_classes,
3797 params->supp_oper_classes_len);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003798 if (nla_put(msg, NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES,
3799 params->supp_oper_classes_len,
3800 params->supp_oper_classes))
3801 goto fail;
Dmitry Shmidt344abd32014-01-14 13:17:00 -08003802 }
3803
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003804 os_memset(&upd, 0, sizeof(upd));
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003805 upd.set = sta_flags_nl80211(params->flags);
3806 upd.mask = upd.set | sta_flags_nl80211(params->flags_mask);
Dmitry Shmidtf8623282013-02-20 14:34:59 -08003807 wpa_printf(MSG_DEBUG, " * flags set=0x%x mask=0x%x",
3808 upd.set, upd.mask);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003809 if (nla_put(msg, NL80211_ATTR_STA_FLAGS2, sizeof(upd), &upd))
3810 goto fail;
3811
3812#ifdef CONFIG_MESH
3813 if (params->plink_state &&
3814 nla_put_u8(msg, NL80211_ATTR_STA_PLINK_STATE,
3815 sta_plink_state_nl80211(params->plink_state)))
3816 goto fail;
3817#endif /* CONFIG_MESH */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003818
3819 if (params->flags & WPA_STA_WMM) {
Dmitry Shmidt8da800a2013-04-24 12:57:01 -07003820 struct nlattr *wme = nla_nest_start(msg, NL80211_ATTR_STA_WME);
3821
Dmitry Shmidtf8623282013-02-20 14:34:59 -08003822 wpa_printf(MSG_DEBUG, " * qosinfo=0x%x", params->qosinfo);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003823 if (!wme ||
3824 nla_put_u8(msg, NL80211_STA_WME_UAPSD_QUEUES,
3825 params->qosinfo & WMM_QOSINFO_STA_AC_MASK) ||
3826 nla_put_u8(msg, NL80211_STA_WME_MAX_SP,
3827 (params->qosinfo >> WMM_QOSINFO_STA_SP_SHIFT) &
3828 WMM_QOSINFO_STA_SP_MASK))
3829 goto fail;
Dmitry Shmidt8da800a2013-04-24 12:57:01 -07003830 nla_nest_end(msg, wme);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003831 }
3832
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003833 ret = send_and_recv_msgs(drv, msg, NULL, NULL);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003834 msg = NULL;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003835 if (ret)
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003836 wpa_printf(MSG_DEBUG, "nl80211: NL80211_CMD_%s_STATION "
3837 "result: %d (%s)", params->set ? "SET" : "NEW", ret,
3838 strerror(-ret));
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003839 if (ret == -EEXIST)
3840 ret = 0;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003841fail:
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003842 nlmsg_free(msg);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003843 return ret;
3844}
3845
3846
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07003847static void rtnl_neigh_delete_fdb_entry(struct i802_bss *bss, const u8 *addr)
3848{
3849#ifdef CONFIG_LIBNL3_ROUTE
3850 struct wpa_driver_nl80211_data *drv = bss->drv;
3851 struct rtnl_neigh *rn;
3852 struct nl_addr *nl_addr;
3853 int err;
3854
3855 rn = rtnl_neigh_alloc();
3856 if (!rn)
3857 return;
3858
3859 rtnl_neigh_set_family(rn, AF_BRIDGE);
3860 rtnl_neigh_set_ifindex(rn, bss->ifindex);
3861 nl_addr = nl_addr_build(AF_BRIDGE, (void *) addr, ETH_ALEN);
3862 if (!nl_addr) {
3863 rtnl_neigh_put(rn);
3864 return;
3865 }
3866 rtnl_neigh_set_lladdr(rn, nl_addr);
3867
3868 err = rtnl_neigh_delete(drv->rtnl_sk, rn, 0);
3869 if (err < 0) {
3870 wpa_printf(MSG_DEBUG, "nl80211: bridge FDB entry delete for "
3871 MACSTR " ifindex=%d failed: %s", MAC2STR(addr),
3872 bss->ifindex, nl_geterror(err));
3873 } else {
3874 wpa_printf(MSG_DEBUG, "nl80211: deleted bridge FDB entry for "
3875 MACSTR, MAC2STR(addr));
3876 }
3877
3878 nl_addr_put(nl_addr);
3879 rtnl_neigh_put(rn);
3880#endif /* CONFIG_LIBNL3_ROUTE */
3881}
3882
3883
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003884static int wpa_driver_nl80211_sta_remove(struct i802_bss *bss, const u8 *addr,
3885 int deauth, u16 reason_code)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003886{
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003887 struct wpa_driver_nl80211_data *drv = bss->drv;
3888 struct nl_msg *msg;
3889 int ret;
3890
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003891 if (!(msg = nl80211_bss_msg(bss, 0, NL80211_CMD_DEL_STATION)) ||
3892 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) ||
3893 (deauth == 0 &&
3894 nla_put_u8(msg, NL80211_ATTR_MGMT_SUBTYPE,
3895 WLAN_FC_STYPE_DISASSOC)) ||
3896 (deauth == 1 &&
3897 nla_put_u8(msg, NL80211_ATTR_MGMT_SUBTYPE,
3898 WLAN_FC_STYPE_DEAUTH)) ||
3899 (reason_code &&
3900 nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason_code))) {
3901 nlmsg_free(msg);
3902 return -ENOBUFS;
3903 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003904
3905 ret = send_and_recv_msgs(drv, msg, NULL, NULL);
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -07003906 wpa_printf(MSG_DEBUG, "nl80211: sta_remove -> DEL_STATION %s " MACSTR
3907 " --> %d (%s)",
3908 bss->ifname, MAC2STR(addr), ret, strerror(-ret));
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07003909
3910 if (drv->rtnl_sk)
3911 rtnl_neigh_delete_fdb_entry(bss, addr);
3912
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003913 if (ret == -ENOENT)
3914 return 0;
3915 return ret;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003916}
3917
3918
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003919void nl80211_remove_iface(struct wpa_driver_nl80211_data *drv, int ifidx)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003920{
3921 struct nl_msg *msg;
Dmitry Shmidt76cd2cc2014-05-27 12:56:04 -07003922 struct wpa_driver_nl80211_data *drv2;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003923
3924 wpa_printf(MSG_DEBUG, "nl80211: Remove interface ifindex=%d", ifidx);
3925
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003926 /* stop listening for EAPOL on this interface */
Dmitry Shmidt76cd2cc2014-05-27 12:56:04 -07003927 dl_list_for_each(drv2, &drv->global->interfaces,
3928 struct wpa_driver_nl80211_data, list)
3929 del_ifidx(drv2, ifidx);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003930
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003931 msg = nl80211_ifindex_msg(drv, ifidx, 0, NL80211_CMD_DEL_INTERFACE);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003932 if (send_and_recv_msgs(drv, msg, NULL, NULL) == 0)
3933 return;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003934 wpa_printf(MSG_ERROR, "Failed to remove interface (ifidx=%d)", ifidx);
3935}
3936
3937
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003938static const char * nl80211_iftype_str(enum nl80211_iftype mode)
3939{
3940 switch (mode) {
3941 case NL80211_IFTYPE_ADHOC:
3942 return "ADHOC";
3943 case NL80211_IFTYPE_STATION:
3944 return "STATION";
3945 case NL80211_IFTYPE_AP:
3946 return "AP";
Dmitry Shmidtf7e0a992013-05-23 11:03:10 -07003947 case NL80211_IFTYPE_AP_VLAN:
3948 return "AP_VLAN";
3949 case NL80211_IFTYPE_WDS:
3950 return "WDS";
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003951 case NL80211_IFTYPE_MONITOR:
3952 return "MONITOR";
Dmitry Shmidtf7e0a992013-05-23 11:03:10 -07003953 case NL80211_IFTYPE_MESH_POINT:
3954 return "MESH_POINT";
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003955 case NL80211_IFTYPE_P2P_CLIENT:
3956 return "P2P_CLIENT";
3957 case NL80211_IFTYPE_P2P_GO:
3958 return "P2P_GO";
Dmitry Shmidt34af3062013-07-11 10:46:32 -07003959 case NL80211_IFTYPE_P2P_DEVICE:
3960 return "P2P_DEVICE";
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003961 default:
3962 return "unknown";
3963 }
3964}
3965
3966
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003967static int nl80211_create_iface_once(struct wpa_driver_nl80211_data *drv,
3968 const char *ifname,
3969 enum nl80211_iftype iftype,
Dmitry Shmidt34af3062013-07-11 10:46:32 -07003970 const u8 *addr, int wds,
3971 int (*handler)(struct nl_msg *, void *),
3972 void *arg)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003973{
Dmitry Shmidt8da800a2013-04-24 12:57:01 -07003974 struct nl_msg *msg;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003975 int ifidx;
3976 int ret = -ENOBUFS;
3977
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08003978 wpa_printf(MSG_DEBUG, "nl80211: Create interface iftype %d (%s)",
3979 iftype, nl80211_iftype_str(iftype));
3980
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003981 msg = nl80211_cmd_msg(drv->first_bss, 0, NL80211_CMD_NEW_INTERFACE);
3982 if (!msg ||
3983 nla_put_string(msg, NL80211_ATTR_IFNAME, ifname) ||
3984 nla_put_u32(msg, NL80211_ATTR_IFTYPE, iftype))
3985 goto fail;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003986
3987 if (iftype == NL80211_IFTYPE_MONITOR) {
Dmitry Shmidt8da800a2013-04-24 12:57:01 -07003988 struct nlattr *flags;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003989
Dmitry Shmidt8da800a2013-04-24 12:57:01 -07003990 flags = nla_nest_start(msg, NL80211_ATTR_MNTR_FLAGS);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003991 if (!flags ||
3992 nla_put_flag(msg, NL80211_MNTR_FLAG_COOK_FRAMES))
3993 goto fail;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003994
Dmitry Shmidt8da800a2013-04-24 12:57:01 -07003995 nla_nest_end(msg, flags);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003996 } else if (wds) {
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003997 if (nla_put_u8(msg, NL80211_ATTR_4ADDR, wds))
3998 goto fail;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07003999 }
4000
Dmitry Shmidtb58836e2014-04-29 14:35:56 -07004001 /*
4002 * Tell cfg80211 that the interface belongs to the socket that created
4003 * it, and the interface should be deleted when the socket is closed.
4004 */
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004005 if (nla_put_flag(msg, NL80211_ATTR_IFACE_SOCKET_OWNER))
4006 goto fail;
Dmitry Shmidtb58836e2014-04-29 14:35:56 -07004007
Dmitry Shmidt34af3062013-07-11 10:46:32 -07004008 ret = send_and_recv_msgs(drv, msg, handler, arg);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004009 msg = NULL;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004010 if (ret) {
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004011 fail:
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004012 nlmsg_free(msg);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004013 wpa_printf(MSG_ERROR, "Failed to create interface %s: %d (%s)",
4014 ifname, ret, strerror(-ret));
4015 return ret;
4016 }
4017
Dmitry Shmidt34af3062013-07-11 10:46:32 -07004018 if (iftype == NL80211_IFTYPE_P2P_DEVICE)
4019 return 0;
4020
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004021 ifidx = if_nametoindex(ifname);
4022 wpa_printf(MSG_DEBUG, "nl80211: New interface %s created: ifindex=%d",
4023 ifname, ifidx);
4024
4025 if (ifidx <= 0)
4026 return -1;
4027
Dmitry Shmidt76cd2cc2014-05-27 12:56:04 -07004028 /*
4029 * Some virtual interfaces need to process EAPOL packets and events on
4030 * the parent interface. This is used mainly with hostapd.
4031 */
4032 if (drv->hostapd ||
4033 iftype == NL80211_IFTYPE_AP_VLAN ||
4034 iftype == NL80211_IFTYPE_WDS ||
4035 iftype == NL80211_IFTYPE_MONITOR) {
4036 /* start listening for EAPOL on this interface */
4037 add_ifidx(drv, ifidx);
4038 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004039
4040 if (addr && iftype != NL80211_IFTYPE_MONITOR &&
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004041 linux_set_ifhwaddr(drv->global->ioctl_sock, ifname, addr)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004042 nl80211_remove_iface(drv, ifidx);
4043 return -1;
4044 }
4045
4046 return ifidx;
4047}
4048
4049
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004050int nl80211_create_iface(struct wpa_driver_nl80211_data *drv,
4051 const char *ifname, enum nl80211_iftype iftype,
4052 const u8 *addr, int wds,
4053 int (*handler)(struct nl_msg *, void *),
4054 void *arg, int use_existing)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004055{
4056 int ret;
4057
Dmitry Shmidt34af3062013-07-11 10:46:32 -07004058 ret = nl80211_create_iface_once(drv, ifname, iftype, addr, wds, handler,
4059 arg);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004060
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004061 /* if error occurred and interface exists already */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004062 if (ret == -ENFILE && if_nametoindex(ifname)) {
Dmitry Shmidtcce06662013-11-04 18:44:24 -08004063 if (use_existing) {
4064 wpa_printf(MSG_DEBUG, "nl80211: Continue using existing interface %s",
4065 ifname);
Dmitry Shmidtdf5a7e42014-04-02 12:59:59 -07004066 if (addr && iftype != NL80211_IFTYPE_MONITOR &&
4067 linux_set_ifhwaddr(drv->global->ioctl_sock, ifname,
4068 addr) < 0 &&
4069 (linux_set_iface_flags(drv->global->ioctl_sock,
4070 ifname, 0) < 0 ||
4071 linux_set_ifhwaddr(drv->global->ioctl_sock, ifname,
4072 addr) < 0 ||
4073 linux_set_iface_flags(drv->global->ioctl_sock,
4074 ifname, 1) < 0))
4075 return -1;
Dmitry Shmidtcce06662013-11-04 18:44:24 -08004076 return -ENFILE;
4077 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004078 wpa_printf(MSG_INFO, "Try to remove and re-create %s", ifname);
4079
4080 /* Try to remove the interface that was already there. */
4081 nl80211_remove_iface(drv, if_nametoindex(ifname));
4082
4083 /* Try to create the interface again */
4084 ret = nl80211_create_iface_once(drv, ifname, iftype, addr,
Dmitry Shmidt34af3062013-07-11 10:46:32 -07004085 wds, handler, arg);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004086 }
4087
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004088 if (ret >= 0 && is_p2p_net_interface(iftype)) {
4089 wpa_printf(MSG_DEBUG,
4090 "nl80211: Interface %s created for P2P - disable 11b rates",
4091 ifname);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004092 nl80211_disable_11b_rates(drv, ret, 1);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004093 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004094
4095 return ret;
4096}
4097
4098
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004099static int nl80211_setup_ap(struct i802_bss *bss)
4100{
4101 struct wpa_driver_nl80211_data *drv = bss->drv;
4102
Dmitry Shmidtcce06662013-11-04 18:44:24 -08004103 wpa_printf(MSG_DEBUG, "nl80211: Setup AP(%s) - device_ap_sme=%d use_monitor=%d",
4104 bss->ifname, drv->device_ap_sme, drv->use_monitor);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004105
4106 /*
4107 * Disable Probe Request reporting unless we need it in this way for
4108 * devices that include the AP SME, in the other case (unless using
4109 * monitor iface) we'll get it through the nl_mgmt socket instead.
4110 */
4111 if (!drv->device_ap_sme)
4112 wpa_driver_nl80211_probe_req_report(bss, 0);
4113
4114 if (!drv->device_ap_sme && !drv->use_monitor)
4115 if (nl80211_mgmt_subscribe_ap(bss))
4116 return -1;
4117
4118 if (drv->device_ap_sme && !drv->use_monitor)
4119 if (nl80211_mgmt_subscribe_ap_dev_sme(bss))
4120 return -1;
4121
4122 if (!drv->device_ap_sme && drv->use_monitor &&
4123 nl80211_create_monitor_interface(drv) &&
4124 !drv->device_ap_sme)
Dmitry Shmidt04949592012-07-19 12:16:46 -07004125 return -1;
4126
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004127 if (drv->device_ap_sme &&
4128 wpa_driver_nl80211_probe_req_report(bss, 1) < 0) {
4129 wpa_printf(MSG_DEBUG, "nl80211: Failed to enable "
4130 "Probe Request frame reporting in AP mode");
4131 /* Try to survive without this */
4132 }
4133
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004134 return 0;
4135}
4136
4137
4138static void nl80211_teardown_ap(struct i802_bss *bss)
4139{
4140 struct wpa_driver_nl80211_data *drv = bss->drv;
4141
Dmitry Shmidtcce06662013-11-04 18:44:24 -08004142 wpa_printf(MSG_DEBUG, "nl80211: Teardown AP(%s) - device_ap_sme=%d use_monitor=%d",
4143 bss->ifname, drv->device_ap_sme, drv->use_monitor);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004144 if (drv->device_ap_sme) {
4145 wpa_driver_nl80211_probe_req_report(bss, 0);
4146 if (!drv->use_monitor)
4147 nl80211_mgmt_unsubscribe(bss, "AP teardown (dev SME)");
4148 } else if (drv->use_monitor)
4149 nl80211_remove_monitor_interface(drv);
4150 else
4151 nl80211_mgmt_unsubscribe(bss, "AP teardown");
4152
4153 bss->beacon_set = 0;
4154}
4155
4156
4157static int nl80211_send_eapol_data(struct i802_bss *bss,
4158 const u8 *addr, const u8 *data,
4159 size_t data_len)
4160{
4161 struct sockaddr_ll ll;
4162 int ret;
4163
4164 if (bss->drv->eapol_tx_sock < 0) {
4165 wpa_printf(MSG_DEBUG, "nl80211: No socket to send EAPOL");
4166 return -1;
4167 }
4168
4169 os_memset(&ll, 0, sizeof(ll));
4170 ll.sll_family = AF_PACKET;
4171 ll.sll_ifindex = bss->ifindex;
4172 ll.sll_protocol = htons(ETH_P_PAE);
4173 ll.sll_halen = ETH_ALEN;
4174 os_memcpy(ll.sll_addr, addr, ETH_ALEN);
4175 ret = sendto(bss->drv->eapol_tx_sock, data, data_len, 0,
4176 (struct sockaddr *) &ll, sizeof(ll));
4177 if (ret < 0)
4178 wpa_printf(MSG_ERROR, "nl80211: EAPOL TX: %s",
4179 strerror(errno));
4180
4181 return ret;
4182}
4183
4184
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004185static const u8 rfc1042_header[6] = { 0xaa, 0xaa, 0x03, 0x00, 0x00, 0x00 };
4186
4187static int wpa_driver_nl80211_hapd_send_eapol(
4188 void *priv, const u8 *addr, const u8 *data,
4189 size_t data_len, int encrypt, const u8 *own_addr, u32 flags)
4190{
4191 struct i802_bss *bss = priv;
4192 struct wpa_driver_nl80211_data *drv = bss->drv;
4193 struct ieee80211_hdr *hdr;
4194 size_t len;
4195 u8 *pos;
4196 int res;
4197 int qos = flags & WPA_STA_WMM;
Dmitry Shmidt641185e2013-11-06 15:17:13 -08004198
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004199 if (drv->device_ap_sme || !drv->use_monitor)
4200 return nl80211_send_eapol_data(bss, addr, data, data_len);
4201
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004202 len = sizeof(*hdr) + (qos ? 2 : 0) + sizeof(rfc1042_header) + 2 +
4203 data_len;
4204 hdr = os_zalloc(len);
4205 if (hdr == NULL) {
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -07004206 wpa_printf(MSG_INFO, "nl80211: Failed to allocate EAPOL buffer(len=%lu)",
4207 (unsigned long) len);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004208 return -1;
4209 }
4210
4211 hdr->frame_control =
4212 IEEE80211_FC(WLAN_FC_TYPE_DATA, WLAN_FC_STYPE_DATA);
4213 hdr->frame_control |= host_to_le16(WLAN_FC_FROMDS);
4214 if (encrypt)
4215 hdr->frame_control |= host_to_le16(WLAN_FC_ISWEP);
4216 if (qos) {
4217 hdr->frame_control |=
4218 host_to_le16(WLAN_FC_STYPE_QOS_DATA << 4);
4219 }
4220
4221 memcpy(hdr->IEEE80211_DA_FROMDS, addr, ETH_ALEN);
4222 memcpy(hdr->IEEE80211_BSSID_FROMDS, own_addr, ETH_ALEN);
4223 memcpy(hdr->IEEE80211_SA_FROMDS, own_addr, ETH_ALEN);
4224 pos = (u8 *) (hdr + 1);
4225
4226 if (qos) {
Dmitry Shmidtaa532512012-09-24 10:35:31 -07004227 /* Set highest priority in QoS header */
4228 pos[0] = 7;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004229 pos[1] = 0;
4230 pos += 2;
4231 }
4232
4233 memcpy(pos, rfc1042_header, sizeof(rfc1042_header));
4234 pos += sizeof(rfc1042_header);
4235 WPA_PUT_BE16(pos, ETH_P_PAE);
4236 pos += 2;
4237 memcpy(pos, data, data_len);
4238
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08004239 res = wpa_driver_nl80211_send_frame(bss, (u8 *) hdr, len, encrypt, 0,
4240 0, 0, 0, 0);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004241 if (res < 0) {
4242 wpa_printf(MSG_ERROR, "i802_send_eapol - packet len: %lu - "
4243 "failed: %d (%s)",
4244 (unsigned long) len, errno, strerror(errno));
4245 }
4246 os_free(hdr);
4247
4248 return res;
4249}
4250
4251
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004252static int wpa_driver_nl80211_sta_set_flags(void *priv, const u8 *addr,
4253 int total_flags,
4254 int flags_or, int flags_and)
4255{
4256 struct i802_bss *bss = priv;
Dmitry Shmidt8da800a2013-04-24 12:57:01 -07004257 struct nl_msg *msg;
4258 struct nlattr *flags;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004259 struct nl80211_sta_flag_update upd;
4260
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07004261 wpa_printf(MSG_DEBUG, "nl80211: Set STA flags - ifname=%s addr=" MACSTR
4262 " total_flags=0x%x flags_or=0x%x flags_and=0x%x authorized=%d",
4263 bss->ifname, MAC2STR(addr), total_flags, flags_or, flags_and,
4264 !!(total_flags & WPA_STA_AUTHORIZED));
4265
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004266 if (!(msg = nl80211_bss_msg(bss, 0, NL80211_CMD_SET_STATION)) ||
4267 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr))
4268 goto fail;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004269
4270 /*
4271 * Backwards compatibility version using NL80211_ATTR_STA_FLAGS. This
4272 * can be removed eventually.
4273 */
Dmitry Shmidt8da800a2013-04-24 12:57:01 -07004274 flags = nla_nest_start(msg, NL80211_ATTR_STA_FLAGS);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004275 if (!flags ||
4276 ((total_flags & WPA_STA_AUTHORIZED) &&
4277 nla_put_flag(msg, NL80211_STA_FLAG_AUTHORIZED)) ||
4278 ((total_flags & WPA_STA_WMM) &&
4279 nla_put_flag(msg, NL80211_STA_FLAG_WME)) ||
4280 ((total_flags & WPA_STA_SHORT_PREAMBLE) &&
4281 nla_put_flag(msg, NL80211_STA_FLAG_SHORT_PREAMBLE)) ||
4282 ((total_flags & WPA_STA_MFP) &&
4283 nla_put_flag(msg, NL80211_STA_FLAG_MFP)) ||
4284 ((total_flags & WPA_STA_TDLS_PEER) &&
4285 nla_put_flag(msg, NL80211_STA_FLAG_TDLS_PEER)))
4286 goto fail;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004287
Dmitry Shmidt8da800a2013-04-24 12:57:01 -07004288 nla_nest_end(msg, flags);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004289
4290 os_memset(&upd, 0, sizeof(upd));
4291 upd.mask = sta_flags_nl80211(flags_or | ~flags_and);
4292 upd.set = sta_flags_nl80211(flags_or);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004293 if (nla_put(msg, NL80211_ATTR_STA_FLAGS2, sizeof(upd), &upd))
4294 goto fail;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004295
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004296 return send_and_recv_msgs(bss->drv, msg, NULL, NULL);
4297fail:
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004298 nlmsg_free(msg);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004299 return -ENOBUFS;
4300}
4301
4302
4303static int wpa_driver_nl80211_ap(struct wpa_driver_nl80211_data *drv,
4304 struct wpa_driver_associate_params *params)
4305{
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08004306 enum nl80211_iftype nlmode, old_mode;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004307
4308 if (params->p2p) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004309 wpa_printf(MSG_DEBUG, "nl80211: Setup AP operations for P2P "
4310 "group (GO)");
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004311 nlmode = NL80211_IFTYPE_P2P_GO;
4312 } else
4313 nlmode = NL80211_IFTYPE_AP;
4314
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08004315 old_mode = drv->nlmode;
Dmitry Shmidtcce06662013-11-04 18:44:24 -08004316 if (wpa_driver_nl80211_set_mode(drv->first_bss, nlmode)) {
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08004317 nl80211_remove_monitor_interface(drv);
4318 return -1;
4319 }
4320
Dmitry Shmidt203eadb2015-03-05 14:16:04 -08004321 if (params->freq.freq &&
4322 nl80211_set_channel(drv->first_bss, &params->freq, 0)) {
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08004323 if (old_mode != nlmode)
Dmitry Shmidtcce06662013-11-04 18:44:24 -08004324 wpa_driver_nl80211_set_mode(drv->first_bss, old_mode);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004325 nl80211_remove_monitor_interface(drv);
4326 return -1;
4327 }
4328
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004329 return 0;
4330}
4331
4332
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004333static int nl80211_leave_ibss(struct wpa_driver_nl80211_data *drv,
4334 int reset_mode)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004335{
4336 struct nl_msg *msg;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004337 int ret;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004338
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004339 msg = nl80211_drv_msg(drv, 0, NL80211_CMD_LEAVE_IBSS);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004340 ret = send_and_recv_msgs(drv, msg, NULL, NULL);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004341 if (ret) {
4342 wpa_printf(MSG_DEBUG, "nl80211: Leave IBSS failed: ret=%d "
4343 "(%s)", ret, strerror(-ret));
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004344 } else {
4345 wpa_printf(MSG_DEBUG,
4346 "nl80211: Leave IBSS request sent successfully");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004347 }
4348
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004349 if (reset_mode &&
4350 wpa_driver_nl80211_set_mode(drv->first_bss,
Dmitry Shmidt56052862013-10-04 10:23:25 -07004351 NL80211_IFTYPE_STATION)) {
4352 wpa_printf(MSG_INFO, "nl80211: Failed to set interface into "
4353 "station mode");
4354 }
4355
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004356 return ret;
4357}
4358
4359
Dmitry Shmidt2f74e362015-01-21 13:19:05 -08004360static int nl80211_ht_vht_overrides(struct nl_msg *msg,
4361 struct wpa_driver_associate_params *params)
4362{
4363 if (params->disable_ht && nla_put_flag(msg, NL80211_ATTR_DISABLE_HT))
4364 return -1;
4365
4366 if (params->htcaps && params->htcaps_mask) {
4367 int sz = sizeof(struct ieee80211_ht_capabilities);
4368 wpa_hexdump(MSG_DEBUG, " * htcaps", params->htcaps, sz);
4369 wpa_hexdump(MSG_DEBUG, " * htcaps_mask",
4370 params->htcaps_mask, sz);
4371 if (nla_put(msg, NL80211_ATTR_HT_CAPABILITY, sz,
4372 params->htcaps) ||
4373 nla_put(msg, NL80211_ATTR_HT_CAPABILITY_MASK, sz,
4374 params->htcaps_mask))
4375 return -1;
4376 }
4377
4378#ifdef CONFIG_VHT_OVERRIDES
4379 if (params->disable_vht) {
4380 wpa_printf(MSG_DEBUG, " * VHT disabled");
4381 if (nla_put_flag(msg, NL80211_ATTR_DISABLE_VHT))
4382 return -1;
4383 }
4384
4385 if (params->vhtcaps && params->vhtcaps_mask) {
4386 int sz = sizeof(struct ieee80211_vht_capabilities);
4387 wpa_hexdump(MSG_DEBUG, " * vhtcaps", params->vhtcaps, sz);
4388 wpa_hexdump(MSG_DEBUG, " * vhtcaps_mask",
4389 params->vhtcaps_mask, sz);
4390 if (nla_put(msg, NL80211_ATTR_VHT_CAPABILITY, sz,
4391 params->vhtcaps) ||
4392 nla_put(msg, NL80211_ATTR_VHT_CAPABILITY_MASK, sz,
4393 params->vhtcaps_mask))
4394 return -1;
4395 }
4396#endif /* CONFIG_VHT_OVERRIDES */
4397
4398 return 0;
4399}
4400
4401
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004402static int wpa_driver_nl80211_ibss(struct wpa_driver_nl80211_data *drv,
4403 struct wpa_driver_associate_params *params)
4404{
4405 struct nl_msg *msg;
4406 int ret = -1;
4407 int count = 0;
4408
4409 wpa_printf(MSG_DEBUG, "nl80211: Join IBSS (ifindex=%d)", drv->ifindex);
4410
Dmitry Shmidt9ead16e2014-10-07 13:15:23 -07004411 if (wpa_driver_nl80211_set_mode_ibss(drv->first_bss, &params->freq)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004412 wpa_printf(MSG_INFO, "nl80211: Failed to set interface into "
4413 "IBSS mode");
4414 return -1;
4415 }
4416
4417retry:
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004418 if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_JOIN_IBSS)) ||
4419 params->ssid == NULL || params->ssid_len > sizeof(drv->ssid))
4420 goto fail;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004421
4422 wpa_hexdump_ascii(MSG_DEBUG, " * SSID",
4423 params->ssid, params->ssid_len);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004424 if (nla_put(msg, NL80211_ATTR_SSID, params->ssid_len, params->ssid))
4425 goto fail;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004426 os_memcpy(drv->ssid, params->ssid, params->ssid_len);
4427 drv->ssid_len = params->ssid_len;
4428
Dmitry Shmidtff787d52015-01-12 13:01:47 -08004429 if (nl80211_put_freq_params(msg, &params->freq) < 0 ||
4430 nl80211_put_beacon_int(msg, params->beacon_int))
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004431 goto fail;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004432
4433 ret = nl80211_set_conn_keys(params, msg);
4434 if (ret)
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004435 goto fail;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004436
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08004437 if (params->bssid && params->fixed_bssid) {
4438 wpa_printf(MSG_DEBUG, " * BSSID=" MACSTR,
4439 MAC2STR(params->bssid));
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004440 if (nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, params->bssid))
4441 goto fail;
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08004442 }
4443
Dmitry Shmidt7f656022015-02-25 14:36:37 -08004444 if (params->fixed_freq) {
4445 wpa_printf(MSG_DEBUG, " * fixed_freq");
4446 if (nla_put_flag(msg, NL80211_ATTR_FREQ_FIXED))
4447 goto fail;
4448 }
4449
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004450 if (params->key_mgmt_suite == WPA_KEY_MGMT_IEEE8021X ||
4451 params->key_mgmt_suite == WPA_KEY_MGMT_PSK ||
4452 params->key_mgmt_suite == WPA_KEY_MGMT_IEEE8021X_SHA256 ||
4453 params->key_mgmt_suite == WPA_KEY_MGMT_PSK_SHA256) {
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08004454 wpa_printf(MSG_DEBUG, " * control port");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004455 if (nla_put_flag(msg, NL80211_ATTR_CONTROL_PORT))
4456 goto fail;
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08004457 }
4458
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004459 if (params->wpa_ie) {
4460 wpa_hexdump(MSG_DEBUG,
4461 " * Extra IEs for Beacon/Probe Response frames",
4462 params->wpa_ie, params->wpa_ie_len);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004463 if (nla_put(msg, NL80211_ATTR_IE, params->wpa_ie_len,
4464 params->wpa_ie))
4465 goto fail;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004466 }
4467
Dmitry Shmidt2f74e362015-01-21 13:19:05 -08004468 if (nl80211_ht_vht_overrides(msg, params) < 0)
4469 return -1;
4470
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004471 ret = send_and_recv_msgs(drv, msg, NULL, NULL);
4472 msg = NULL;
4473 if (ret) {
4474 wpa_printf(MSG_DEBUG, "nl80211: Join IBSS failed: ret=%d (%s)",
4475 ret, strerror(-ret));
4476 count++;
4477 if (ret == -EALREADY && count == 1) {
4478 wpa_printf(MSG_DEBUG, "nl80211: Retry IBSS join after "
4479 "forced leave");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004480 nl80211_leave_ibss(drv, 0);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004481 nlmsg_free(msg);
4482 goto retry;
4483 }
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004484 } else {
4485 wpa_printf(MSG_DEBUG,
4486 "nl80211: Join IBSS request sent successfully");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004487 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004488
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004489fail:
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004490 nlmsg_free(msg);
4491 return ret;
4492}
4493
4494
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004495static int nl80211_connect_common(struct wpa_driver_nl80211_data *drv,
4496 struct wpa_driver_associate_params *params,
4497 struct nl_msg *msg)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004498{
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004499 if (params->bssid) {
4500 wpa_printf(MSG_DEBUG, " * bssid=" MACSTR,
4501 MAC2STR(params->bssid));
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004502 if (nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, params->bssid))
4503 return -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004504 }
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004505
Dmitry Shmidt96be6222014-02-13 10:16:51 -08004506 if (params->bssid_hint) {
4507 wpa_printf(MSG_DEBUG, " * bssid_hint=" MACSTR,
4508 MAC2STR(params->bssid_hint));
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004509 if (nla_put(msg, NL80211_ATTR_MAC_HINT, ETH_ALEN,
4510 params->bssid_hint))
4511 return -1;
Dmitry Shmidt96be6222014-02-13 10:16:51 -08004512 }
4513
Dmitry Shmidt9ead16e2014-10-07 13:15:23 -07004514 if (params->freq.freq) {
4515 wpa_printf(MSG_DEBUG, " * freq=%d", params->freq.freq);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004516 if (nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ,
4517 params->freq.freq))
4518 return -1;
Dmitry Shmidt9ead16e2014-10-07 13:15:23 -07004519 drv->assoc_freq = params->freq.freq;
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -07004520 } else
4521 drv->assoc_freq = 0;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004522
Dmitry Shmidt96be6222014-02-13 10:16:51 -08004523 if (params->freq_hint) {
4524 wpa_printf(MSG_DEBUG, " * freq_hint=%d", params->freq_hint);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004525 if (nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ_HINT,
4526 params->freq_hint))
4527 return -1;
Dmitry Shmidt96be6222014-02-13 10:16:51 -08004528 }
4529
Dmitry Shmidt04949592012-07-19 12:16:46 -07004530 if (params->bg_scan_period >= 0) {
4531 wpa_printf(MSG_DEBUG, " * bg scan period=%d",
4532 params->bg_scan_period);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004533 if (nla_put_u16(msg, NL80211_ATTR_BG_SCAN_PERIOD,
4534 params->bg_scan_period))
4535 return -1;
Dmitry Shmidt04949592012-07-19 12:16:46 -07004536 }
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004537
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004538 if (params->ssid) {
4539 wpa_hexdump_ascii(MSG_DEBUG, " * SSID",
4540 params->ssid, params->ssid_len);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004541 if (nla_put(msg, NL80211_ATTR_SSID, params->ssid_len,
4542 params->ssid))
4543 return -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004544 if (params->ssid_len > sizeof(drv->ssid))
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004545 return -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004546 os_memcpy(drv->ssid, params->ssid, params->ssid_len);
4547 drv->ssid_len = params->ssid_len;
4548 }
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004549
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004550 wpa_hexdump(MSG_DEBUG, " * IEs", params->wpa_ie, params->wpa_ie_len);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004551 if (params->wpa_ie &&
4552 nla_put(msg, NL80211_ATTR_IE, params->wpa_ie_len, params->wpa_ie))
4553 return -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004554
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004555 if (params->wpa_proto) {
4556 enum nl80211_wpa_versions ver = 0;
4557
4558 if (params->wpa_proto & WPA_PROTO_WPA)
4559 ver |= NL80211_WPA_VERSION_1;
4560 if (params->wpa_proto & WPA_PROTO_RSN)
4561 ver |= NL80211_WPA_VERSION_2;
4562
4563 wpa_printf(MSG_DEBUG, " * WPA Versions 0x%x", ver);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004564 if (nla_put_u32(msg, NL80211_ATTR_WPA_VERSIONS, ver))
4565 return -1;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004566 }
4567
4568 if (params->pairwise_suite != WPA_CIPHER_NONE) {
4569 u32 cipher = wpa_cipher_to_cipher_suite(params->pairwise_suite);
4570 wpa_printf(MSG_DEBUG, " * pairwise=0x%x", cipher);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004571 if (nla_put_u32(msg, NL80211_ATTR_CIPHER_SUITES_PAIRWISE,
4572 cipher))
4573 return -1;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004574 }
4575
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08004576 if (params->group_suite == WPA_CIPHER_GTK_NOT_USED &&
4577 !(drv->capa.enc & WPA_DRIVER_CAPA_ENC_GTK_NOT_USED)) {
4578 /*
4579 * This is likely to work even though many drivers do not
4580 * advertise support for operations without GTK.
4581 */
4582 wpa_printf(MSG_DEBUG, " * skip group cipher configuration for GTK_NOT_USED due to missing driver support advertisement");
4583 } else if (params->group_suite != WPA_CIPHER_NONE) {
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004584 u32 cipher = wpa_cipher_to_cipher_suite(params->group_suite);
4585 wpa_printf(MSG_DEBUG, " * group=0x%x", cipher);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004586 if (nla_put_u32(msg, NL80211_ATTR_CIPHER_SUITE_GROUP, cipher))
4587 return -1;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004588 }
4589
4590 if (params->key_mgmt_suite == WPA_KEY_MGMT_IEEE8021X ||
4591 params->key_mgmt_suite == WPA_KEY_MGMT_PSK ||
4592 params->key_mgmt_suite == WPA_KEY_MGMT_FT_IEEE8021X ||
4593 params->key_mgmt_suite == WPA_KEY_MGMT_FT_PSK ||
Dmitry Shmidt15907092014-03-25 10:42:57 -07004594 params->key_mgmt_suite == WPA_KEY_MGMT_CCKM ||
Dmitry Shmidt3c57b3f2014-05-22 15:13:07 -07004595 params->key_mgmt_suite == WPA_KEY_MGMT_OSEN ||
4596 params->key_mgmt_suite == WPA_KEY_MGMT_IEEE8021X_SHA256 ||
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004597 params->key_mgmt_suite == WPA_KEY_MGMT_PSK_SHA256 ||
Dmitry Shmidt807291d2015-01-27 13:40:23 -08004598 params->key_mgmt_suite == WPA_KEY_MGMT_IEEE8021X_SUITE_B ||
4599 params->key_mgmt_suite == WPA_KEY_MGMT_IEEE8021X_SUITE_B_192) {
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004600 int mgmt = WLAN_AKM_SUITE_PSK;
4601
4602 switch (params->key_mgmt_suite) {
4603 case WPA_KEY_MGMT_CCKM:
4604 mgmt = WLAN_AKM_SUITE_CCKM;
4605 break;
4606 case WPA_KEY_MGMT_IEEE8021X:
4607 mgmt = WLAN_AKM_SUITE_8021X;
4608 break;
4609 case WPA_KEY_MGMT_FT_IEEE8021X:
4610 mgmt = WLAN_AKM_SUITE_FT_8021X;
4611 break;
4612 case WPA_KEY_MGMT_FT_PSK:
4613 mgmt = WLAN_AKM_SUITE_FT_PSK;
4614 break;
Dmitry Shmidt3c57b3f2014-05-22 15:13:07 -07004615 case WPA_KEY_MGMT_IEEE8021X_SHA256:
4616 mgmt = WLAN_AKM_SUITE_8021X_SHA256;
4617 break;
4618 case WPA_KEY_MGMT_PSK_SHA256:
4619 mgmt = WLAN_AKM_SUITE_PSK_SHA256;
4620 break;
Dmitry Shmidt15907092014-03-25 10:42:57 -07004621 case WPA_KEY_MGMT_OSEN:
4622 mgmt = WLAN_AKM_SUITE_OSEN;
4623 break;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004624 case WPA_KEY_MGMT_IEEE8021X_SUITE_B:
4625 mgmt = WLAN_AKM_SUITE_8021X_SUITE_B;
4626 break;
Dmitry Shmidt807291d2015-01-27 13:40:23 -08004627 case WPA_KEY_MGMT_IEEE8021X_SUITE_B_192:
4628 mgmt = WLAN_AKM_SUITE_8021X_SUITE_B_192;
4629 break;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004630 case WPA_KEY_MGMT_PSK:
4631 default:
4632 mgmt = WLAN_AKM_SUITE_PSK;
4633 break;
4634 }
Dmitry Shmidt15907092014-03-25 10:42:57 -07004635 wpa_printf(MSG_DEBUG, " * akm=0x%x", mgmt);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004636 if (nla_put_u32(msg, NL80211_ATTR_AKM_SUITES, mgmt))
4637 return -1;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004638 }
4639
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004640 if (nla_put_flag(msg, NL80211_ATTR_CONTROL_PORT))
4641 return -1;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004642
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004643 if (params->mgmt_frame_protection == MGMT_FRAME_PROTECTION_REQUIRED &&
4644 nla_put_u32(msg, NL80211_ATTR_USE_MFP, NL80211_MFP_REQUIRED))
4645 return -1;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004646
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004647 if (params->rrm_used) {
4648 u32 drv_rrm_flags = drv->capa.rrm_flags;
4649 if (!(drv_rrm_flags &
4650 WPA_DRIVER_FLAGS_DS_PARAM_SET_IE_IN_PROBES) ||
4651 !(drv_rrm_flags & WPA_DRIVER_FLAGS_QUIET) ||
4652 nla_put_flag(msg, NL80211_ATTR_USE_RRM))
4653 return -1;
4654 }
4655
Dmitry Shmidt2f74e362015-01-21 13:19:05 -08004656 if (nl80211_ht_vht_overrides(msg, params) < 0)
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004657 return -1;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004658
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004659 if (params->p2p)
4660 wpa_printf(MSG_DEBUG, " * P2P group");
4661
4662 return 0;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004663}
4664
4665
4666static int wpa_driver_nl80211_try_connect(
4667 struct wpa_driver_nl80211_data *drv,
4668 struct wpa_driver_associate_params *params)
4669{
4670 struct nl_msg *msg;
4671 enum nl80211_auth_type type;
4672 int ret;
4673 int algs;
4674
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004675 if (params->req_key_mgmt_offload && params->psk &&
4676 (params->key_mgmt_suite == WPA_KEY_MGMT_PSK ||
4677 params->key_mgmt_suite == WPA_KEY_MGMT_PSK_SHA256 ||
4678 params->key_mgmt_suite == WPA_KEY_MGMT_FT_PSK)) {
4679 wpa_printf(MSG_DEBUG, "nl80211: Key management set PSK");
4680 ret = issue_key_mgmt_set_key(drv, params->psk, 32);
4681 if (ret)
4682 return ret;
4683 }
4684
4685 wpa_printf(MSG_DEBUG, "nl80211: Connect (ifindex=%d)", drv->ifindex);
4686 msg = nl80211_drv_msg(drv, 0, NL80211_CMD_CONNECT);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004687 if (!msg)
4688 return -1;
4689
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004690 ret = nl80211_connect_common(drv, params, msg);
4691 if (ret)
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004692 goto fail;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004693
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004694 algs = 0;
4695 if (params->auth_alg & WPA_AUTH_ALG_OPEN)
4696 algs++;
4697 if (params->auth_alg & WPA_AUTH_ALG_SHARED)
4698 algs++;
4699 if (params->auth_alg & WPA_AUTH_ALG_LEAP)
4700 algs++;
4701 if (algs > 1) {
4702 wpa_printf(MSG_DEBUG, " * Leave out Auth Type for automatic "
4703 "selection");
4704 goto skip_auth_type;
4705 }
4706
4707 if (params->auth_alg & WPA_AUTH_ALG_OPEN)
4708 type = NL80211_AUTHTYPE_OPEN_SYSTEM;
4709 else if (params->auth_alg & WPA_AUTH_ALG_SHARED)
4710 type = NL80211_AUTHTYPE_SHARED_KEY;
4711 else if (params->auth_alg & WPA_AUTH_ALG_LEAP)
4712 type = NL80211_AUTHTYPE_NETWORK_EAP;
4713 else if (params->auth_alg & WPA_AUTH_ALG_FT)
4714 type = NL80211_AUTHTYPE_FT;
4715 else
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004716 goto fail;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004717
4718 wpa_printf(MSG_DEBUG, " * Auth Type %d", type);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004719 if (nla_put_u32(msg, NL80211_ATTR_AUTH_TYPE, type))
4720 goto fail;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004721
4722skip_auth_type:
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004723 ret = nl80211_set_conn_keys(params, msg);
4724 if (ret)
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004725 goto fail;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004726
4727 ret = send_and_recv_msgs(drv, msg, NULL, NULL);
4728 msg = NULL;
4729 if (ret) {
4730 wpa_printf(MSG_DEBUG, "nl80211: MLME connect failed: ret=%d "
4731 "(%s)", ret, strerror(-ret));
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004732 } else {
4733 wpa_printf(MSG_DEBUG,
4734 "nl80211: Connect request send successfully");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004735 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004736
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004737fail:
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004738 nlmsg_free(msg);
4739 return ret;
4740
4741}
4742
4743
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08004744static int wpa_driver_nl80211_connect(
4745 struct wpa_driver_nl80211_data *drv,
4746 struct wpa_driver_associate_params *params)
4747{
Jithu Jancea7c60b42014-12-03 18:54:40 +05304748 int ret;
4749
4750 /* Store the connection attempted bssid for future use */
4751 if (params->bssid)
4752 os_memcpy(drv->auth_attempt_bssid, params->bssid, ETH_ALEN);
4753 else
4754 os_memset(drv->auth_attempt_bssid, 0, ETH_ALEN);
4755
4756 ret = wpa_driver_nl80211_try_connect(drv, params);
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08004757 if (ret == -EALREADY) {
4758 /*
4759 * cfg80211 does not currently accept new connections if
4760 * we are already connected. As a workaround, force
4761 * disconnection and try again.
4762 */
4763 wpa_printf(MSG_DEBUG, "nl80211: Explicitly "
4764 "disconnecting before reassociation "
4765 "attempt");
4766 if (wpa_driver_nl80211_disconnect(
4767 drv, WLAN_REASON_PREV_AUTH_NOT_VALID))
4768 return -1;
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08004769 ret = wpa_driver_nl80211_try_connect(drv, params);
4770 }
4771 return ret;
4772}
4773
4774
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004775static int wpa_driver_nl80211_associate(
4776 void *priv, struct wpa_driver_associate_params *params)
4777{
4778 struct i802_bss *bss = priv;
4779 struct wpa_driver_nl80211_data *drv = bss->drv;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004780 int ret = -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004781 struct nl_msg *msg;
4782
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004783 nl80211_unmask_11b_rates(bss);
4784
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004785 if (params->mode == IEEE80211_MODE_AP)
4786 return wpa_driver_nl80211_ap(drv, params);
4787
4788 if (params->mode == IEEE80211_MODE_IBSS)
4789 return wpa_driver_nl80211_ibss(drv, params);
4790
4791 if (!(drv->capa.flags & WPA_DRIVER_FLAGS_SME)) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004792 enum nl80211_iftype nlmode = params->p2p ?
4793 NL80211_IFTYPE_P2P_CLIENT : NL80211_IFTYPE_STATION;
4794
4795 if (wpa_driver_nl80211_set_mode(priv, nlmode) < 0)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004796 return -1;
4797 return wpa_driver_nl80211_connect(drv, params);
4798 }
4799
Dmitry Shmidt8bae4132013-06-06 11:25:10 -07004800 nl80211_mark_disconnected(drv);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004801
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004802 wpa_printf(MSG_DEBUG, "nl80211: Associate (ifindex=%d)",
4803 drv->ifindex);
4804 msg = nl80211_drv_msg(drv, 0, NL80211_CMD_ASSOCIATE);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004805 if (!msg)
4806 return -1;
4807
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08004808 ret = nl80211_connect_common(drv, params, msg);
4809 if (ret)
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004810 goto fail;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004811
4812 if (params->prev_bssid) {
4813 wpa_printf(MSG_DEBUG, " * prev_bssid=" MACSTR,
4814 MAC2STR(params->prev_bssid));
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004815 if (nla_put(msg, NL80211_ATTR_PREV_BSSID, ETH_ALEN,
4816 params->prev_bssid))
4817 goto fail;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004818 }
4819
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004820 ret = send_and_recv_msgs(drv, msg, NULL, NULL);
4821 msg = NULL;
4822 if (ret) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004823 wpa_dbg(drv->ctx, MSG_DEBUG,
4824 "nl80211: MLME command failed (assoc): ret=%d (%s)",
4825 ret, strerror(-ret));
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004826 nl80211_dump_scan(drv);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004827 } else {
4828 wpa_printf(MSG_DEBUG,
4829 "nl80211: Association request send successfully");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004830 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004831
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004832fail:
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004833 nlmsg_free(msg);
4834 return ret;
4835}
4836
4837
4838static int nl80211_set_mode(struct wpa_driver_nl80211_data *drv,
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004839 int ifindex, enum nl80211_iftype mode)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004840{
4841 struct nl_msg *msg;
4842 int ret = -ENOBUFS;
4843
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004844 wpa_printf(MSG_DEBUG, "nl80211: Set mode ifindex %d iftype %d (%s)",
4845 ifindex, mode, nl80211_iftype_str(mode));
4846
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004847 msg = nl80211_cmd_msg(drv->first_bss, 0, NL80211_CMD_SET_INTERFACE);
4848 if (!msg || nla_put_u32(msg, NL80211_ATTR_IFTYPE, mode))
4849 goto fail;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004850
4851 ret = send_and_recv_msgs(drv, msg, NULL, NULL);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004852 msg = NULL;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004853 if (!ret)
4854 return 0;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004855fail:
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004856 nlmsg_free(msg);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004857 wpa_printf(MSG_DEBUG, "nl80211: Failed to set interface %d to mode %d:"
4858 " %d (%s)", ifindex, mode, ret, strerror(-ret));
4859 return ret;
4860}
4861
4862
Dmitry Shmidtd30ac602014-06-30 09:54:22 -07004863static int wpa_driver_nl80211_set_mode_impl(
4864 struct i802_bss *bss,
4865 enum nl80211_iftype nlmode,
4866 struct hostapd_freq_params *desired_freq_params)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004867{
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004868 struct wpa_driver_nl80211_data *drv = bss->drv;
4869 int ret = -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004870 int i;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004871 int was_ap = is_ap_interface(drv->nlmode);
4872 int res;
Dmitry Shmidtd30ac602014-06-30 09:54:22 -07004873 int mode_switch_res;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004874
Dmitry Shmidtd30ac602014-06-30 09:54:22 -07004875 mode_switch_res = nl80211_set_mode(drv, drv->ifindex, nlmode);
4876 if (mode_switch_res && nlmode == nl80211_get_ifmode(bss))
4877 mode_switch_res = 0;
Dmitry Shmidt34af3062013-07-11 10:46:32 -07004878
Dmitry Shmidtd30ac602014-06-30 09:54:22 -07004879 if (mode_switch_res == 0) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004880 drv->nlmode = nlmode;
4881 ret = 0;
4882 goto done;
4883 }
4884
Dmitry Shmidtd30ac602014-06-30 09:54:22 -07004885 if (mode_switch_res == -ENODEV)
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004886 return -1;
4887
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004888 if (nlmode == drv->nlmode) {
4889 wpa_printf(MSG_DEBUG, "nl80211: Interface already in "
4890 "requested mode - ignore error");
4891 ret = 0;
4892 goto done; /* Already in the requested mode */
4893 }
4894
4895 /* mac80211 doesn't allow mode changes while the device is up, so
4896 * take the device down, try to set the mode again, and bring the
4897 * device back up.
4898 */
4899 wpa_printf(MSG_DEBUG, "nl80211: Try mode change after setting "
4900 "interface down");
4901 for (i = 0; i < 10; i++) {
Dmitry Shmidt34af3062013-07-11 10:46:32 -07004902 res = i802_set_iface_flags(bss, 0);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004903 if (res == -EACCES || res == -ENODEV)
4904 break;
Dmitry Shmidtd30ac602014-06-30 09:54:22 -07004905 if (res != 0) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004906 wpa_printf(MSG_DEBUG, "nl80211: Failed to set "
4907 "interface down");
Dmitry Shmidtd30ac602014-06-30 09:54:22 -07004908 os_sleep(0, 100000);
4909 continue;
4910 }
4911
4912 /*
4913 * Setting the mode will fail for some drivers if the phy is
4914 * on a frequency that the mode is disallowed in.
4915 */
4916 if (desired_freq_params) {
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004917 res = nl80211_set_channel(bss, desired_freq_params, 0);
Dmitry Shmidtd30ac602014-06-30 09:54:22 -07004918 if (res) {
4919 wpa_printf(MSG_DEBUG,
4920 "nl80211: Failed to set frequency on interface");
4921 }
4922 }
4923
4924 /* Try to set the mode again while the interface is down */
4925 mode_switch_res = nl80211_set_mode(drv, drv->ifindex, nlmode);
4926 if (mode_switch_res == -EBUSY) {
4927 wpa_printf(MSG_DEBUG,
4928 "nl80211: Delaying mode set while interface going down");
4929 os_sleep(0, 100000);
4930 continue;
4931 }
4932 ret = mode_switch_res;
4933 break;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004934 }
4935
4936 if (!ret) {
4937 wpa_printf(MSG_DEBUG, "nl80211: Mode change succeeded while "
4938 "interface is down");
4939 drv->nlmode = nlmode;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004940 drv->ignore_if_down_event = 1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004941 }
4942
Dmitry Shmidtd30ac602014-06-30 09:54:22 -07004943 /* Bring the interface back up */
4944 res = linux_set_iface_flags(drv->global->ioctl_sock, bss->ifname, 1);
4945 if (res != 0) {
4946 wpa_printf(MSG_DEBUG,
4947 "nl80211: Failed to set interface up after switching mode");
4948 ret = -1;
4949 }
4950
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004951done:
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004952 if (ret) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004953 wpa_printf(MSG_DEBUG, "nl80211: Interface mode change to %d "
4954 "from %d failed", nlmode, drv->nlmode);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004955 return ret;
4956 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004957
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004958 if (is_p2p_net_interface(nlmode)) {
4959 wpa_printf(MSG_DEBUG,
4960 "nl80211: Interface %s mode change to P2P - disable 11b rates",
4961 bss->ifname);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07004962 nl80211_disable_11b_rates(drv, drv->ifindex, 1);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004963 } else if (drv->disabled_11b_rates) {
4964 wpa_printf(MSG_DEBUG,
4965 "nl80211: Interface %s mode changed to non-P2P - re-enable 11b rates",
4966 bss->ifname);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07004967 nl80211_disable_11b_rates(drv, drv->ifindex, 0);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004968 }
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07004969
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004970 if (is_ap_interface(nlmode)) {
4971 nl80211_mgmt_unsubscribe(bss, "start AP");
4972 /* Setup additional AP mode functionality if needed */
4973 if (nl80211_setup_ap(bss))
4974 return -1;
4975 } else if (was_ap) {
4976 /* Remove additional AP mode functionality */
4977 nl80211_teardown_ap(bss);
4978 } else {
4979 nl80211_mgmt_unsubscribe(bss, "mode change");
4980 }
4981
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004982 if (is_mesh_interface(nlmode) &&
4983 nl80211_mgmt_subscribe_mesh(bss))
4984 return -1;
4985
Dmitry Shmidt04949592012-07-19 12:16:46 -07004986 if (!bss->in_deinit && !is_ap_interface(nlmode) &&
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004987 !is_mesh_interface(nlmode) &&
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08004988 nl80211_mgmt_subscribe_non_ap(bss) < 0)
4989 wpa_printf(MSG_DEBUG, "nl80211: Failed to register Action "
4990 "frame processing - ignore for now");
4991
4992 return 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004993}
4994
4995
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08004996int wpa_driver_nl80211_set_mode(struct i802_bss *bss,
4997 enum nl80211_iftype nlmode)
Dmitry Shmidtd30ac602014-06-30 09:54:22 -07004998{
4999 return wpa_driver_nl80211_set_mode_impl(bss, nlmode, NULL);
5000}
5001
5002
Dmitry Shmidt9ead16e2014-10-07 13:15:23 -07005003static int wpa_driver_nl80211_set_mode_ibss(struct i802_bss *bss,
5004 struct hostapd_freq_params *freq)
Dmitry Shmidtd30ac602014-06-30 09:54:22 -07005005{
Dmitry Shmidtd30ac602014-06-30 09:54:22 -07005006 return wpa_driver_nl80211_set_mode_impl(bss, NL80211_IFTYPE_ADHOC,
Dmitry Shmidt9ead16e2014-10-07 13:15:23 -07005007 freq);
Dmitry Shmidtd30ac602014-06-30 09:54:22 -07005008}
5009
5010
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005011static int wpa_driver_nl80211_get_capa(void *priv,
5012 struct wpa_driver_capa *capa)
5013{
5014 struct i802_bss *bss = priv;
5015 struct wpa_driver_nl80211_data *drv = bss->drv;
Dmitry Shmidtd11f0192014-03-24 12:09:47 -07005016
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005017 if (!drv->has_capability)
5018 return -1;
5019 os_memcpy(capa, &drv->capa, sizeof(*capa));
Dmitry Shmidt444d5672013-04-01 13:08:44 -07005020 if (drv->extended_capa && drv->extended_capa_mask) {
5021 capa->extended_capa = drv->extended_capa;
5022 capa->extended_capa_mask = drv->extended_capa_mask;
5023 capa->extended_capa_len = drv->extended_capa_len;
5024 }
Dmitry Shmidt34af3062013-07-11 10:46:32 -07005025
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005026 return 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005027}
5028
5029
5030static int wpa_driver_nl80211_set_operstate(void *priv, int state)
5031{
5032 struct i802_bss *bss = priv;
5033 struct wpa_driver_nl80211_data *drv = bss->drv;
5034
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08005035 wpa_printf(MSG_DEBUG, "nl80211: Set %s operstate %d->%d (%s)",
5036 bss->ifname, drv->operstate, state,
5037 state ? "UP" : "DORMANT");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005038 drv->operstate = state;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005039 return netlink_send_oper_ifla(drv->global->netlink, drv->ifindex, -1,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005040 state ? IF_OPER_UP : IF_OPER_DORMANT);
5041}
5042
5043
5044static int wpa_driver_nl80211_set_supp_port(void *priv, int authorized)
5045{
5046 struct i802_bss *bss = priv;
5047 struct wpa_driver_nl80211_data *drv = bss->drv;
5048 struct nl_msg *msg;
5049 struct nl80211_sta_flag_update upd;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005050 int ret;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08005051
5052 if (!drv->associated && is_zero_ether_addr(drv->bssid) && !authorized) {
5053 wpa_printf(MSG_DEBUG, "nl80211: Skip set_supp_port(unauthorized) while not associated");
5054 return 0;
5055 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005056
Dmitry Shmidt8bae4132013-06-06 11:25:10 -07005057 wpa_printf(MSG_DEBUG, "nl80211: Set supplicant port %sauthorized for "
5058 MACSTR, authorized ? "" : "un", MAC2STR(drv->bssid));
5059
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005060 os_memset(&upd, 0, sizeof(upd));
5061 upd.mask = BIT(NL80211_STA_FLAG_AUTHORIZED);
5062 if (authorized)
5063 upd.set = BIT(NL80211_STA_FLAG_AUTHORIZED);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005064
5065 if (!(msg = nl80211_bss_msg(bss, 0, NL80211_CMD_SET_STATION)) ||
5066 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, drv->bssid) ||
5067 nla_put(msg, NL80211_ATTR_STA_FLAGS2, sizeof(upd), &upd)) {
5068 nlmsg_free(msg);
5069 return -ENOBUFS;
5070 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005071
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08005072 ret = send_and_recv_msgs(drv, msg, NULL, NULL);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08005073 if (!ret)
5074 return 0;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08005075 wpa_printf(MSG_DEBUG, "nl80211: Failed to set STA flag: %d (%s)",
5076 ret, strerror(-ret));
5077 return ret;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005078}
5079
5080
Jouni Malinen75ecf522011-06-27 15:19:46 -07005081/* Set kernel driver on given frequency (MHz) */
5082static int i802_set_freq(void *priv, struct hostapd_freq_params *freq)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005083{
Jouni Malinen75ecf522011-06-27 15:19:46 -07005084 struct i802_bss *bss = priv;
Dmitry Shmidt7832adb2014-04-29 10:53:02 -07005085 return nl80211_set_channel(bss, freq, 0);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005086}
5087
5088
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005089static inline int min_int(int a, int b)
5090{
5091 if (a < b)
5092 return a;
5093 return b;
5094}
5095
5096
5097static int get_key_handler(struct nl_msg *msg, void *arg)
5098{
5099 struct nlattr *tb[NL80211_ATTR_MAX + 1];
5100 struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg));
5101
5102 nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0),
5103 genlmsg_attrlen(gnlh, 0), NULL);
5104
5105 /*
5106 * TODO: validate the key index and mac address!
5107 * Otherwise, there's a race condition as soon as
5108 * the kernel starts sending key notifications.
5109 */
5110
5111 if (tb[NL80211_ATTR_KEY_SEQ])
5112 memcpy(arg, nla_data(tb[NL80211_ATTR_KEY_SEQ]),
5113 min_int(nla_len(tb[NL80211_ATTR_KEY_SEQ]), 6));
5114 return NL_SKIP;
5115}
5116
5117
5118static int i802_get_seqnum(const char *iface, void *priv, const u8 *addr,
5119 int idx, u8 *seq)
5120{
5121 struct i802_bss *bss = priv;
5122 struct wpa_driver_nl80211_data *drv = bss->drv;
5123 struct nl_msg *msg;
5124
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005125 msg = nl80211_ifindex_msg(drv, if_nametoindex(iface), 0,
5126 NL80211_CMD_GET_KEY);
5127 if (!msg ||
5128 (addr && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) ||
5129 nla_put_u8(msg, NL80211_ATTR_KEY_IDX, idx)) {
5130 nlmsg_free(msg);
5131 return -ENOBUFS;
5132 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005133
5134 memset(seq, 0, 6);
5135
5136 return send_and_recv_msgs(drv, msg, get_key_handler, seq);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005137}
5138
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005139
5140static int i802_set_rts(void *priv, int rts)
5141{
5142 struct i802_bss *bss = priv;
5143 struct wpa_driver_nl80211_data *drv = bss->drv;
5144 struct nl_msg *msg;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005145 int ret;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005146 u32 val;
5147
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005148 if (rts >= 2347)
5149 val = (u32) -1;
5150 else
5151 val = rts;
5152
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005153 if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_SET_WIPHY)) ||
5154 nla_put_u32(msg, NL80211_ATTR_WIPHY_RTS_THRESHOLD, val)) {
5155 nlmsg_free(msg);
5156 return -ENOBUFS;
5157 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005158
5159 ret = send_and_recv_msgs(drv, msg, NULL, NULL);
5160 if (!ret)
5161 return 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005162 wpa_printf(MSG_DEBUG, "nl80211: Failed to set RTS threshold %d: "
5163 "%d (%s)", rts, ret, strerror(-ret));
5164 return ret;
5165}
5166
5167
5168static int i802_set_frag(void *priv, int frag)
5169{
5170 struct i802_bss *bss = priv;
5171 struct wpa_driver_nl80211_data *drv = bss->drv;
5172 struct nl_msg *msg;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005173 int ret;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005174 u32 val;
5175
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005176 if (frag >= 2346)
5177 val = (u32) -1;
5178 else
5179 val = frag;
5180
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005181 if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_SET_WIPHY)) ||
5182 nla_put_u32(msg, NL80211_ATTR_WIPHY_FRAG_THRESHOLD, val)) {
5183 nlmsg_free(msg);
5184 return -ENOBUFS;
5185 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005186
5187 ret = send_and_recv_msgs(drv, msg, NULL, NULL);
5188 if (!ret)
5189 return 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005190 wpa_printf(MSG_DEBUG, "nl80211: Failed to set fragmentation threshold "
5191 "%d: %d (%s)", frag, ret, strerror(-ret));
5192 return ret;
5193}
5194
5195
5196static int i802_flush(void *priv)
5197{
5198 struct i802_bss *bss = priv;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005199 struct nl_msg *msg;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005200 int res;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005201
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -07005202 wpa_printf(MSG_DEBUG, "nl80211: flush -> DEL_STATION %s (all)",
5203 bss->ifname);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005204
5205 /*
5206 * XXX: FIX! this needs to flush all VLANs too
5207 */
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005208 msg = nl80211_bss_msg(bss, 0, NL80211_CMD_DEL_STATION);
5209 res = send_and_recv_msgs(bss->drv, msg, NULL, NULL);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005210 if (res) {
5211 wpa_printf(MSG_DEBUG, "nl80211: Station flush failed: ret=%d "
5212 "(%s)", res, strerror(-res));
5213 }
5214 return res;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005215}
5216
5217
5218static int get_sta_handler(struct nl_msg *msg, void *arg)
5219{
5220 struct nlattr *tb[NL80211_ATTR_MAX + 1];
5221 struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg));
5222 struct hostap_sta_driver_data *data = arg;
5223 struct nlattr *stats[NL80211_STA_INFO_MAX + 1];
5224 static struct nla_policy stats_policy[NL80211_STA_INFO_MAX + 1] = {
5225 [NL80211_STA_INFO_INACTIVE_TIME] = { .type = NLA_U32 },
5226 [NL80211_STA_INFO_RX_BYTES] = { .type = NLA_U32 },
5227 [NL80211_STA_INFO_TX_BYTES] = { .type = NLA_U32 },
5228 [NL80211_STA_INFO_RX_PACKETS] = { .type = NLA_U32 },
5229 [NL80211_STA_INFO_TX_PACKETS] = { .type = NLA_U32 },
Jouni Malinen1e6c57f2012-09-05 17:07:03 +03005230 [NL80211_STA_INFO_TX_FAILED] = { .type = NLA_U32 },
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005231 };
5232
5233 nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0),
5234 genlmsg_attrlen(gnlh, 0), NULL);
5235
5236 /*
5237 * TODO: validate the interface and mac address!
5238 * Otherwise, there's a race condition as soon as
5239 * the kernel starts sending station notifications.
5240 */
5241
5242 if (!tb[NL80211_ATTR_STA_INFO]) {
5243 wpa_printf(MSG_DEBUG, "sta stats missing!");
5244 return NL_SKIP;
5245 }
5246 if (nla_parse_nested(stats, NL80211_STA_INFO_MAX,
5247 tb[NL80211_ATTR_STA_INFO],
5248 stats_policy)) {
5249 wpa_printf(MSG_DEBUG, "failed to parse nested attributes!");
5250 return NL_SKIP;
5251 }
5252
5253 if (stats[NL80211_STA_INFO_INACTIVE_TIME])
5254 data->inactive_msec =
5255 nla_get_u32(stats[NL80211_STA_INFO_INACTIVE_TIME]);
5256 if (stats[NL80211_STA_INFO_RX_BYTES])
5257 data->rx_bytes = nla_get_u32(stats[NL80211_STA_INFO_RX_BYTES]);
5258 if (stats[NL80211_STA_INFO_TX_BYTES])
5259 data->tx_bytes = nla_get_u32(stats[NL80211_STA_INFO_TX_BYTES]);
5260 if (stats[NL80211_STA_INFO_RX_PACKETS])
5261 data->rx_packets =
5262 nla_get_u32(stats[NL80211_STA_INFO_RX_PACKETS]);
5263 if (stats[NL80211_STA_INFO_TX_PACKETS])
5264 data->tx_packets =
5265 nla_get_u32(stats[NL80211_STA_INFO_TX_PACKETS]);
Jouni Malinen1e6c57f2012-09-05 17:07:03 +03005266 if (stats[NL80211_STA_INFO_TX_FAILED])
5267 data->tx_retry_failed =
5268 nla_get_u32(stats[NL80211_STA_INFO_TX_FAILED]);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005269
5270 return NL_SKIP;
5271}
5272
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08005273static int i802_read_sta_data(struct i802_bss *bss,
5274 struct hostap_sta_driver_data *data,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005275 const u8 *addr)
5276{
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005277 struct nl_msg *msg;
5278
5279 os_memset(data, 0, sizeof(*data));
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005280
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005281 if (!(msg = nl80211_bss_msg(bss, 0, NL80211_CMD_GET_STATION)) ||
5282 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) {
5283 nlmsg_free(msg);
5284 return -ENOBUFS;
5285 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005286
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005287 return send_and_recv_msgs(bss->drv, msg, get_sta_handler, data);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005288}
5289
5290
5291static int i802_set_tx_queue_params(void *priv, int queue, int aifs,
5292 int cw_min, int cw_max, int burst_time)
5293{
5294 struct i802_bss *bss = priv;
5295 struct wpa_driver_nl80211_data *drv = bss->drv;
5296 struct nl_msg *msg;
5297 struct nlattr *txq, *params;
5298
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005299 msg = nl80211_bss_msg(bss, 0, NL80211_CMD_SET_WIPHY);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005300 if (!msg)
5301 return -1;
5302
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005303 txq = nla_nest_start(msg, NL80211_ATTR_WIPHY_TXQ_PARAMS);
5304 if (!txq)
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005305 goto fail;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005306
5307 /* We are only sending parameters for a single TXQ at a time */
5308 params = nla_nest_start(msg, 1);
5309 if (!params)
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005310 goto fail;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005311
5312 switch (queue) {
5313 case 0:
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005314 if (nla_put_u8(msg, NL80211_TXQ_ATTR_QUEUE, NL80211_TXQ_Q_VO))
5315 goto fail;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005316 break;
5317 case 1:
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005318 if (nla_put_u8(msg, NL80211_TXQ_ATTR_QUEUE, NL80211_TXQ_Q_VI))
5319 goto fail;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005320 break;
5321 case 2:
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005322 if (nla_put_u8(msg, NL80211_TXQ_ATTR_QUEUE, NL80211_TXQ_Q_BE))
5323 goto fail;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005324 break;
5325 case 3:
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005326 if (nla_put_u8(msg, NL80211_TXQ_ATTR_QUEUE, NL80211_TXQ_Q_BK))
5327 goto fail;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005328 break;
5329 }
5330 /* Burst time is configured in units of 0.1 msec and TXOP parameter in
5331 * 32 usec, so need to convert the value here. */
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005332 if (nla_put_u16(msg, NL80211_TXQ_ATTR_TXOP,
5333 (burst_time * 100 + 16) / 32) ||
5334 nla_put_u16(msg, NL80211_TXQ_ATTR_CWMIN, cw_min) ||
5335 nla_put_u16(msg, NL80211_TXQ_ATTR_CWMAX, cw_max) ||
5336 nla_put_u8(msg, NL80211_TXQ_ATTR_AIFS, aifs))
5337 goto fail;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005338
5339 nla_nest_end(msg, params);
5340
5341 nla_nest_end(msg, txq);
5342
5343 if (send_and_recv_msgs(drv, msg, NULL, NULL) == 0)
5344 return 0;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005345 msg = NULL;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005346fail:
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005347 nlmsg_free(msg);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005348 return -1;
5349}
5350
5351
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08005352static int i802_set_sta_vlan(struct i802_bss *bss, const u8 *addr,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005353 const char *ifname, int vlan_id)
5354{
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005355 struct wpa_driver_nl80211_data *drv = bss->drv;
5356 struct nl_msg *msg;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005357 int ret;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005358
Dmitry Shmidtcce06662013-11-04 18:44:24 -08005359 wpa_printf(MSG_DEBUG, "nl80211: %s[%d]: set_sta_vlan(" MACSTR
5360 ", ifname=%s[%d], vlan_id=%d)",
5361 bss->ifname, if_nametoindex(bss->ifname),
5362 MAC2STR(addr), ifname, if_nametoindex(ifname), vlan_id);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005363 if (!(msg = nl80211_bss_msg(bss, 0, NL80211_CMD_SET_STATION)) ||
5364 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) ||
5365 nla_put_u32(msg, NL80211_ATTR_STA_VLAN, if_nametoindex(ifname))) {
5366 nlmsg_free(msg);
5367 return -ENOBUFS;
5368 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005369
5370 ret = send_and_recv_msgs(drv, msg, NULL, NULL);
5371 if (ret < 0) {
5372 wpa_printf(MSG_ERROR, "nl80211: NL80211_ATTR_STA_VLAN (addr="
5373 MACSTR " ifname=%s vlan_id=%d) failed: %d (%s)",
5374 MAC2STR(addr), ifname, vlan_id, ret,
5375 strerror(-ret));
5376 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005377 return ret;
5378}
5379
5380
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005381static int i802_get_inact_sec(void *priv, const u8 *addr)
5382{
5383 struct hostap_sta_driver_data data;
5384 int ret;
5385
5386 data.inactive_msec = (unsigned long) -1;
5387 ret = i802_read_sta_data(priv, &data, addr);
Dmitry Shmidt2f74e362015-01-21 13:19:05 -08005388 if (ret == -ENOENT)
5389 return -ENOENT;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005390 if (ret || data.inactive_msec == (unsigned long) -1)
5391 return -1;
5392 return data.inactive_msec / 1000;
5393}
5394
5395
5396static int i802_sta_clear_stats(void *priv, const u8 *addr)
5397{
5398#if 0
5399 /* TODO */
5400#endif
5401 return 0;
5402}
5403
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005404
5405static int i802_sta_deauth(void *priv, const u8 *own_addr, const u8 *addr,
5406 int reason)
5407{
5408 struct i802_bss *bss = priv;
Dmitry Shmidt04949592012-07-19 12:16:46 -07005409 struct wpa_driver_nl80211_data *drv = bss->drv;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005410 struct ieee80211_mgmt mgmt;
5411
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005412 if (is_mesh_interface(drv->nlmode))
5413 return -1;
5414
Dmitry Shmidt04949592012-07-19 12:16:46 -07005415 if (drv->device_ap_sme)
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005416 return wpa_driver_nl80211_sta_remove(bss, addr, 1, reason);
Dmitry Shmidt04949592012-07-19 12:16:46 -07005417
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005418 memset(&mgmt, 0, sizeof(mgmt));
5419 mgmt.frame_control = IEEE80211_FC(WLAN_FC_TYPE_MGMT,
5420 WLAN_FC_STYPE_DEAUTH);
5421 memcpy(mgmt.da, addr, ETH_ALEN);
5422 memcpy(mgmt.sa, own_addr, ETH_ALEN);
5423 memcpy(mgmt.bssid, own_addr, ETH_ALEN);
5424 mgmt.u.deauth.reason_code = host_to_le16(reason);
5425 return wpa_driver_nl80211_send_mlme(bss, (u8 *) &mgmt,
5426 IEEE80211_HDRLEN +
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08005427 sizeof(mgmt.u.deauth), 0, 0, 0, 0,
5428 0);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005429}
5430
5431
5432static int i802_sta_disassoc(void *priv, const u8 *own_addr, const u8 *addr,
5433 int reason)
5434{
5435 struct i802_bss *bss = priv;
Dmitry Shmidt04949592012-07-19 12:16:46 -07005436 struct wpa_driver_nl80211_data *drv = bss->drv;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005437 struct ieee80211_mgmt mgmt;
5438
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005439 if (is_mesh_interface(drv->nlmode))
5440 return -1;
5441
Dmitry Shmidt04949592012-07-19 12:16:46 -07005442 if (drv->device_ap_sme)
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005443 return wpa_driver_nl80211_sta_remove(bss, addr, 0, reason);
Dmitry Shmidt04949592012-07-19 12:16:46 -07005444
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005445 memset(&mgmt, 0, sizeof(mgmt));
5446 mgmt.frame_control = IEEE80211_FC(WLAN_FC_TYPE_MGMT,
5447 WLAN_FC_STYPE_DISASSOC);
5448 memcpy(mgmt.da, addr, ETH_ALEN);
5449 memcpy(mgmt.sa, own_addr, ETH_ALEN);
5450 memcpy(mgmt.bssid, own_addr, ETH_ALEN);
5451 mgmt.u.disassoc.reason_code = host_to_le16(reason);
5452 return wpa_driver_nl80211_send_mlme(bss, (u8 *) &mgmt,
5453 IEEE80211_HDRLEN +
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08005454 sizeof(mgmt.u.disassoc), 0, 0, 0, 0,
5455 0);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005456}
5457
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005458
Dmitry Shmidtdf5a7e42014-04-02 12:59:59 -07005459static void dump_ifidx(struct wpa_driver_nl80211_data *drv)
5460{
5461 char buf[200], *pos, *end;
5462 int i, res;
5463
5464 pos = buf;
5465 end = pos + sizeof(buf);
5466
5467 for (i = 0; i < drv->num_if_indices; i++) {
5468 if (!drv->if_indices[i])
5469 continue;
5470 res = os_snprintf(pos, end - pos, " %d", drv->if_indices[i]);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005471 if (os_snprintf_error(end - pos, res))
Dmitry Shmidtdf5a7e42014-04-02 12:59:59 -07005472 break;
5473 pos += res;
5474 }
5475 *pos = '\0';
5476
5477 wpa_printf(MSG_DEBUG, "nl80211: if_indices[%d]:%s",
5478 drv->num_if_indices, buf);
5479}
5480
5481
Jouni Malinen75ecf522011-06-27 15:19:46 -07005482static void add_ifidx(struct wpa_driver_nl80211_data *drv, int ifidx)
5483{
5484 int i;
5485 int *old;
5486
5487 wpa_printf(MSG_DEBUG, "nl80211: Add own interface ifindex %d",
5488 ifidx);
Dmitry Shmidtdf5a7e42014-04-02 12:59:59 -07005489 if (have_ifidx(drv, ifidx)) {
5490 wpa_printf(MSG_DEBUG, "nl80211: ifindex %d already in the list",
5491 ifidx);
5492 return;
5493 }
Jouni Malinen75ecf522011-06-27 15:19:46 -07005494 for (i = 0; i < drv->num_if_indices; i++) {
5495 if (drv->if_indices[i] == 0) {
5496 drv->if_indices[i] = ifidx;
Dmitry Shmidtdf5a7e42014-04-02 12:59:59 -07005497 dump_ifidx(drv);
Jouni Malinen75ecf522011-06-27 15:19:46 -07005498 return;
5499 }
5500 }
5501
5502 if (drv->if_indices != drv->default_if_indices)
5503 old = drv->if_indices;
5504 else
5505 old = NULL;
5506
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07005507 drv->if_indices = os_realloc_array(old, drv->num_if_indices + 1,
5508 sizeof(int));
Jouni Malinen75ecf522011-06-27 15:19:46 -07005509 if (!drv->if_indices) {
5510 if (!old)
5511 drv->if_indices = drv->default_if_indices;
5512 else
5513 drv->if_indices = old;
5514 wpa_printf(MSG_ERROR, "Failed to reallocate memory for "
5515 "interfaces");
5516 wpa_printf(MSG_ERROR, "Ignoring EAPOL on interface %d", ifidx);
5517 return;
5518 } else if (!old)
5519 os_memcpy(drv->if_indices, drv->default_if_indices,
5520 sizeof(drv->default_if_indices));
5521 drv->if_indices[drv->num_if_indices] = ifidx;
5522 drv->num_if_indices++;
Dmitry Shmidtdf5a7e42014-04-02 12:59:59 -07005523 dump_ifidx(drv);
Jouni Malinen75ecf522011-06-27 15:19:46 -07005524}
5525
5526
5527static void del_ifidx(struct wpa_driver_nl80211_data *drv, int ifidx)
5528{
5529 int i;
5530
5531 for (i = 0; i < drv->num_if_indices; i++) {
5532 if (drv->if_indices[i] == ifidx) {
5533 drv->if_indices[i] = 0;
5534 break;
5535 }
5536 }
Dmitry Shmidtdf5a7e42014-04-02 12:59:59 -07005537 dump_ifidx(drv);
Jouni Malinen75ecf522011-06-27 15:19:46 -07005538}
5539
5540
5541static int have_ifidx(struct wpa_driver_nl80211_data *drv, int ifidx)
5542{
5543 int i;
5544
5545 for (i = 0; i < drv->num_if_indices; i++)
5546 if (drv->if_indices[i] == ifidx)
5547 return 1;
5548
5549 return 0;
5550}
5551
5552
5553static int i802_set_wds_sta(void *priv, const u8 *addr, int aid, int val,
Dmitry Shmidt7832adb2014-04-29 10:53:02 -07005554 const char *bridge_ifname, char *ifname_wds)
Jouni Malinen75ecf522011-06-27 15:19:46 -07005555{
5556 struct i802_bss *bss = priv;
5557 struct wpa_driver_nl80211_data *drv = bss->drv;
5558 char name[IFNAMSIZ + 1];
5559
5560 os_snprintf(name, sizeof(name), "%s.sta%d", bss->ifname, aid);
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07005561 if (ifname_wds)
5562 os_strlcpy(ifname_wds, name, IFNAMSIZ + 1);
5563
Jouni Malinen75ecf522011-06-27 15:19:46 -07005564 wpa_printf(MSG_DEBUG, "nl80211: Set WDS STA addr=" MACSTR
5565 " aid=%d val=%d name=%s", MAC2STR(addr), aid, val, name);
5566 if (val) {
5567 if (!if_nametoindex(name)) {
5568 if (nl80211_create_iface(drv, name,
5569 NL80211_IFTYPE_AP_VLAN,
Dmitry Shmidtcce06662013-11-04 18:44:24 -08005570 bss->addr, 1, NULL, NULL, 0) <
5571 0)
Jouni Malinen75ecf522011-06-27 15:19:46 -07005572 return -1;
5573 if (bridge_ifname &&
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005574 linux_br_add_if(drv->global->ioctl_sock,
5575 bridge_ifname, name) < 0)
Jouni Malinen75ecf522011-06-27 15:19:46 -07005576 return -1;
5577 }
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07005578 if (linux_set_iface_flags(drv->global->ioctl_sock, name, 1)) {
5579 wpa_printf(MSG_ERROR, "nl80211: Failed to set WDS STA "
5580 "interface %s up", name);
5581 }
Jouni Malinen75ecf522011-06-27 15:19:46 -07005582 return i802_set_sta_vlan(priv, addr, name, 0);
5583 } else {
Dmitry Shmidtaa532512012-09-24 10:35:31 -07005584 if (bridge_ifname)
5585 linux_br_del_if(drv->global->ioctl_sock, bridge_ifname,
5586 name);
5587
Jouni Malinen75ecf522011-06-27 15:19:46 -07005588 i802_set_sta_vlan(priv, addr, bss->ifname, 0);
Dmitry Shmidta38abf92014-03-06 13:38:44 -08005589 nl80211_remove_iface(drv, if_nametoindex(name));
5590 return 0;
Jouni Malinen75ecf522011-06-27 15:19:46 -07005591 }
5592}
5593
5594
5595static void handle_eapol(int sock, void *eloop_ctx, void *sock_ctx)
5596{
5597 struct wpa_driver_nl80211_data *drv = eloop_ctx;
5598 struct sockaddr_ll lladdr;
5599 unsigned char buf[3000];
5600 int len;
5601 socklen_t fromlen = sizeof(lladdr);
5602
5603 len = recvfrom(sock, buf, sizeof(buf), 0,
5604 (struct sockaddr *)&lladdr, &fromlen);
5605 if (len < 0) {
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -07005606 wpa_printf(MSG_ERROR, "nl80211: EAPOL recv failed: %s",
5607 strerror(errno));
Jouni Malinen75ecf522011-06-27 15:19:46 -07005608 return;
5609 }
5610
5611 if (have_ifidx(drv, lladdr.sll_ifindex))
5612 drv_event_eapol_rx(drv->ctx, lladdr.sll_addr, buf, len);
5613}
5614
5615
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005616static int i802_check_bridge(struct wpa_driver_nl80211_data *drv,
5617 struct i802_bss *bss,
5618 const char *brname, const char *ifname)
5619{
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005620 int br_ifindex;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005621 char in_br[IFNAMSIZ];
5622
5623 os_strlcpy(bss->brname, brname, IFNAMSIZ);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005624 br_ifindex = if_nametoindex(brname);
5625 if (br_ifindex == 0) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005626 /*
5627 * Bridge was configured, but the bridge device does
5628 * not exist. Try to add it now.
5629 */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005630 if (linux_br_add(drv->global->ioctl_sock, brname) < 0) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005631 wpa_printf(MSG_ERROR, "nl80211: Failed to add the "
5632 "bridge interface %s: %s",
5633 brname, strerror(errno));
5634 return -1;
5635 }
5636 bss->added_bridge = 1;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005637 br_ifindex = if_nametoindex(brname);
5638 add_ifidx(drv, br_ifindex);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005639 }
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005640 bss->br_ifindex = br_ifindex;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005641
5642 if (linux_br_get(in_br, ifname) == 0) {
5643 if (os_strcmp(in_br, brname) == 0)
5644 return 0; /* already in the bridge */
5645
5646 wpa_printf(MSG_DEBUG, "nl80211: Removing interface %s from "
5647 "bridge %s", ifname, in_br);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005648 if (linux_br_del_if(drv->global->ioctl_sock, in_br, ifname) <
5649 0) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005650 wpa_printf(MSG_ERROR, "nl80211: Failed to "
5651 "remove interface %s from bridge "
5652 "%s: %s",
5653 ifname, brname, strerror(errno));
5654 return -1;
5655 }
5656 }
5657
5658 wpa_printf(MSG_DEBUG, "nl80211: Adding interface %s into bridge %s",
5659 ifname, brname);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005660 if (linux_br_add_if(drv->global->ioctl_sock, brname, ifname) < 0) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005661 wpa_printf(MSG_ERROR, "nl80211: Failed to add interface %s "
5662 "into bridge %s: %s",
5663 ifname, brname, strerror(errno));
5664 return -1;
5665 }
5666 bss->added_if_into_bridge = 1;
5667
5668 return 0;
5669}
5670
5671
5672static void *i802_init(struct hostapd_data *hapd,
5673 struct wpa_init_params *params)
5674{
5675 struct wpa_driver_nl80211_data *drv;
5676 struct i802_bss *bss;
5677 size_t i;
5678 char brname[IFNAMSIZ];
5679 int ifindex, br_ifindex;
5680 int br_added = 0;
5681
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08005682 bss = wpa_driver_nl80211_drv_init(hapd, params->ifname,
5683 params->global_priv, 1,
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005684 params->bssid, params->driver_params);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005685 if (bss == NULL)
5686 return NULL;
5687
5688 drv = bss->drv;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005689
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005690 if (linux_br_get(brname, params->ifname) == 0) {
5691 wpa_printf(MSG_DEBUG, "nl80211: Interface %s is in bridge %s",
5692 params->ifname, brname);
5693 br_ifindex = if_nametoindex(brname);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005694 os_strlcpy(bss->brname, brname, IFNAMSIZ);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005695 } else {
5696 brname[0] = '\0';
5697 br_ifindex = 0;
5698 }
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005699 bss->br_ifindex = br_ifindex;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005700
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005701 for (i = 0; i < params->num_bridge; i++) {
5702 if (params->bridge[i]) {
5703 ifindex = if_nametoindex(params->bridge[i]);
5704 if (ifindex)
5705 add_ifidx(drv, ifindex);
5706 if (ifindex == br_ifindex)
5707 br_added = 1;
5708 }
5709 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005710
5711 /* start listening for EAPOL on the default AP interface */
5712 add_ifidx(drv, drv->ifindex);
5713
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005714 if (params->num_bridge && params->bridge[0]) {
5715 if (i802_check_bridge(drv, bss, params->bridge[0],
5716 params->ifname) < 0)
5717 goto failed;
5718 if (os_strcmp(params->bridge[0], brname) != 0)
5719 br_added = 1;
5720 }
5721
5722 if (!br_added && br_ifindex &&
5723 (params->num_bridge == 0 || !params->bridge[0]))
5724 add_ifidx(drv, br_ifindex);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005725
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07005726#ifdef CONFIG_LIBNL3_ROUTE
5727 if (bss->added_if_into_bridge) {
5728 drv->rtnl_sk = nl_socket_alloc();
5729 if (drv->rtnl_sk == NULL) {
5730 wpa_printf(MSG_ERROR, "nl80211: Failed to allocate nl_sock");
5731 goto failed;
5732 }
5733
5734 if (nl_connect(drv->rtnl_sk, NETLINK_ROUTE)) {
5735 wpa_printf(MSG_ERROR, "nl80211: Failed to connect nl_sock to NETLINK_ROUTE: %s",
5736 strerror(errno));
5737 goto failed;
5738 }
5739 }
5740#endif /* CONFIG_LIBNL3_ROUTE */
5741
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005742 drv->eapol_sock = socket(PF_PACKET, SOCK_DGRAM, htons(ETH_P_PAE));
5743 if (drv->eapol_sock < 0) {
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -07005744 wpa_printf(MSG_ERROR, "nl80211: socket(PF_PACKET, SOCK_DGRAM, ETH_P_PAE) failed: %s",
5745 strerror(errno));
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005746 goto failed;
5747 }
5748
5749 if (eloop_register_read_sock(drv->eapol_sock, handle_eapol, drv, NULL))
5750 {
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -07005751 wpa_printf(MSG_INFO, "nl80211: Could not register read socket for eapol");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005752 goto failed;
5753 }
5754
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005755 if (linux_get_ifhwaddr(drv->global->ioctl_sock, bss->ifname,
5756 params->own_addr))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005757 goto failed;
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07005758 os_memcpy(drv->perm_addr, params->own_addr, ETH_ALEN);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005759
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005760 memcpy(bss->addr, params->own_addr, ETH_ALEN);
5761
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005762 return bss;
5763
5764failed:
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005765 wpa_driver_nl80211_deinit(bss);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005766 return NULL;
5767}
5768
5769
5770static void i802_deinit(void *priv)
5771{
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08005772 struct i802_bss *bss = priv;
5773 wpa_driver_nl80211_deinit(bss);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005774}
5775
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005776
5777static enum nl80211_iftype wpa_driver_nl80211_if_type(
5778 enum wpa_driver_if_type type)
5779{
5780 switch (type) {
5781 case WPA_IF_STATION:
5782 return NL80211_IFTYPE_STATION;
5783 case WPA_IF_P2P_CLIENT:
5784 case WPA_IF_P2P_GROUP:
5785 return NL80211_IFTYPE_P2P_CLIENT;
5786 case WPA_IF_AP_VLAN:
5787 return NL80211_IFTYPE_AP_VLAN;
5788 case WPA_IF_AP_BSS:
5789 return NL80211_IFTYPE_AP;
5790 case WPA_IF_P2P_GO:
5791 return NL80211_IFTYPE_P2P_GO;
Dmitry Shmidt34af3062013-07-11 10:46:32 -07005792 case WPA_IF_P2P_DEVICE:
5793 return NL80211_IFTYPE_P2P_DEVICE;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005794 case WPA_IF_MESH:
5795 return NL80211_IFTYPE_MESH_POINT;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005796 }
5797 return -1;
5798}
5799
5800
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005801static int nl80211_addr_in_use(struct nl80211_global *global, const u8 *addr)
5802{
5803 struct wpa_driver_nl80211_data *drv;
5804 dl_list_for_each(drv, &global->interfaces,
5805 struct wpa_driver_nl80211_data, list) {
Dmitry Shmidtcce06662013-11-04 18:44:24 -08005806 if (os_memcmp(addr, drv->first_bss->addr, ETH_ALEN) == 0)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005807 return 1;
5808 }
5809 return 0;
5810}
5811
5812
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005813static int nl80211_vif_addr(struct wpa_driver_nl80211_data *drv, u8 *new_addr)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005814{
5815 unsigned int idx;
5816
5817 if (!drv->global)
5818 return -1;
5819
Dmitry Shmidtcce06662013-11-04 18:44:24 -08005820 os_memcpy(new_addr, drv->first_bss->addr, ETH_ALEN);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005821 for (idx = 0; idx < 64; idx++) {
Dmitry Shmidtcce06662013-11-04 18:44:24 -08005822 new_addr[0] = drv->first_bss->addr[0] | 0x02;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005823 new_addr[0] ^= idx << 2;
5824 if (!nl80211_addr_in_use(drv->global, new_addr))
5825 break;
5826 }
5827 if (idx == 64)
5828 return -1;
5829
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005830 wpa_printf(MSG_DEBUG, "nl80211: Assigned new virtual interface address "
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005831 MACSTR, MAC2STR(new_addr));
5832
5833 return 0;
5834}
5835
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005836
Dmitry Shmidt34af3062013-07-11 10:46:32 -07005837struct wdev_info {
5838 u64 wdev_id;
5839 int wdev_id_set;
5840 u8 macaddr[ETH_ALEN];
5841};
5842
5843static int nl80211_wdev_handler(struct nl_msg *msg, void *arg)
5844{
5845 struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg));
5846 struct nlattr *tb[NL80211_ATTR_MAX + 1];
5847 struct wdev_info *wi = arg;
5848
5849 nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0),
5850 genlmsg_attrlen(gnlh, 0), NULL);
5851 if (tb[NL80211_ATTR_WDEV]) {
5852 wi->wdev_id = nla_get_u64(tb[NL80211_ATTR_WDEV]);
5853 wi->wdev_id_set = 1;
5854 }
5855
5856 if (tb[NL80211_ATTR_MAC])
5857 os_memcpy(wi->macaddr, nla_data(tb[NL80211_ATTR_MAC]),
5858 ETH_ALEN);
5859
5860 return NL_SKIP;
5861}
5862
5863
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005864static int wpa_driver_nl80211_if_add(void *priv, enum wpa_driver_if_type type,
5865 const char *ifname, const u8 *addr,
5866 void *bss_ctx, void **drv_priv,
5867 char *force_ifname, u8 *if_addr,
Dmitry Shmidtcce06662013-11-04 18:44:24 -08005868 const char *bridge, int use_existing)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005869{
Dmitry Shmidt34af3062013-07-11 10:46:32 -07005870 enum nl80211_iftype nlmode;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005871 struct i802_bss *bss = priv;
5872 struct wpa_driver_nl80211_data *drv = bss->drv;
5873 int ifidx;
Dmitry Shmidtcce06662013-11-04 18:44:24 -08005874 int added = 1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005875
5876 if (addr)
5877 os_memcpy(if_addr, addr, ETH_ALEN);
Dmitry Shmidt34af3062013-07-11 10:46:32 -07005878 nlmode = wpa_driver_nl80211_if_type(type);
5879 if (nlmode == NL80211_IFTYPE_P2P_DEVICE) {
5880 struct wdev_info p2pdev_info;
5881
5882 os_memset(&p2pdev_info, 0, sizeof(p2pdev_info));
5883 ifidx = nl80211_create_iface(drv, ifname, nlmode, addr,
5884 0, nl80211_wdev_handler,
Dmitry Shmidtcce06662013-11-04 18:44:24 -08005885 &p2pdev_info, use_existing);
Dmitry Shmidt34af3062013-07-11 10:46:32 -07005886 if (!p2pdev_info.wdev_id_set || ifidx != 0) {
5887 wpa_printf(MSG_ERROR, "nl80211: Failed to create a P2P Device interface %s",
5888 ifname);
5889 return -1;
5890 }
5891
5892 drv->global->if_add_wdevid = p2pdev_info.wdev_id;
5893 drv->global->if_add_wdevid_set = p2pdev_info.wdev_id_set;
5894 if (!is_zero_ether_addr(p2pdev_info.macaddr))
5895 os_memcpy(if_addr, p2pdev_info.macaddr, ETH_ALEN);
5896 wpa_printf(MSG_DEBUG, "nl80211: New P2P Device interface %s (0x%llx) created",
5897 ifname,
5898 (long long unsigned int) p2pdev_info.wdev_id);
5899 } else {
5900 ifidx = nl80211_create_iface(drv, ifname, nlmode, addr,
Dmitry Shmidtcce06662013-11-04 18:44:24 -08005901 0, NULL, NULL, use_existing);
5902 if (use_existing && ifidx == -ENFILE) {
5903 added = 0;
5904 ifidx = if_nametoindex(ifname);
5905 } else if (ifidx < 0) {
Dmitry Shmidt34af3062013-07-11 10:46:32 -07005906 return -1;
5907 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005908 }
5909
Dmitry Shmidt34af3062013-07-11 10:46:32 -07005910 if (!addr) {
Dmitry Shmidt1d755d02015-04-28 10:34:29 -07005911 if (nlmode == NL80211_IFTYPE_P2P_DEVICE)
Dmitry Shmidt34af3062013-07-11 10:46:32 -07005912 os_memcpy(if_addr, bss->addr, ETH_ALEN);
5913 else if (linux_get_ifhwaddr(drv->global->ioctl_sock,
Dmitry Shmidt1d755d02015-04-28 10:34:29 -07005914 ifname, if_addr) < 0) {
Dmitry Shmidtcce06662013-11-04 18:44:24 -08005915 if (added)
5916 nl80211_remove_iface(drv, ifidx);
Dmitry Shmidt34af3062013-07-11 10:46:32 -07005917 return -1;
5918 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005919 }
5920
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005921 if (!addr &&
5922 (type == WPA_IF_P2P_CLIENT || type == WPA_IF_P2P_GROUP ||
Dmitry Shmidt1d755d02015-04-28 10:34:29 -07005923 type == WPA_IF_P2P_GO || type == WPA_IF_MESH ||
5924 type == WPA_IF_STATION)) {
5925 /* Enforce unique address */
Dmitry Shmidt34af3062013-07-11 10:46:32 -07005926 u8 new_addr[ETH_ALEN];
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005927
Dmitry Shmidt34af3062013-07-11 10:46:32 -07005928 if (linux_get_ifhwaddr(drv->global->ioctl_sock, ifname,
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005929 new_addr) < 0) {
Dmitry Shmidt71757432014-06-02 13:50:35 -07005930 if (added)
5931 nl80211_remove_iface(drv, ifidx);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005932 return -1;
5933 }
Dmitry Shmidt34af3062013-07-11 10:46:32 -07005934 if (nl80211_addr_in_use(drv->global, new_addr)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005935 wpa_printf(MSG_DEBUG, "nl80211: Allocate new address "
Dmitry Shmidt1d755d02015-04-28 10:34:29 -07005936 "for interface %s type %d", ifname, type);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08005937 if (nl80211_vif_addr(drv, new_addr) < 0) {
Dmitry Shmidt71757432014-06-02 13:50:35 -07005938 if (added)
5939 nl80211_remove_iface(drv, ifidx);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005940 return -1;
5941 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005942 if (linux_set_ifhwaddr(drv->global->ioctl_sock, ifname,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005943 new_addr) < 0) {
Dmitry Shmidt71757432014-06-02 13:50:35 -07005944 if (added)
5945 nl80211_remove_iface(drv, ifidx);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005946 return -1;
5947 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005948 }
Dmitry Shmidt6e933c12011-09-27 12:29:26 -07005949 os_memcpy(if_addr, new_addr, ETH_ALEN);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005950 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005951
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005952 if (type == WPA_IF_AP_BSS) {
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -07005953 struct i802_bss *new_bss = os_zalloc(sizeof(*new_bss));
5954 if (new_bss == NULL) {
Dmitry Shmidtcce06662013-11-04 18:44:24 -08005955 if (added)
5956 nl80211_remove_iface(drv, ifidx);
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -07005957 return -1;
5958 }
5959
5960 if (bridge &&
5961 i802_check_bridge(drv, new_bss, bridge, ifname) < 0) {
5962 wpa_printf(MSG_ERROR, "nl80211: Failed to add the new "
5963 "interface %s to a bridge %s",
5964 ifname, bridge);
Dmitry Shmidtcce06662013-11-04 18:44:24 -08005965 if (added)
5966 nl80211_remove_iface(drv, ifidx);
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -07005967 os_free(new_bss);
5968 return -1;
5969 }
5970
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005971 if (linux_set_iface_flags(drv->global->ioctl_sock, ifname, 1))
5972 {
Dmitry Shmidt71757432014-06-02 13:50:35 -07005973 if (added)
5974 nl80211_remove_iface(drv, ifidx);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005975 os_free(new_bss);
5976 return -1;
5977 }
5978 os_strlcpy(new_bss->ifname, ifname, IFNAMSIZ);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005979 os_memcpy(new_bss->addr, if_addr, ETH_ALEN);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005980 new_bss->ifindex = ifidx;
5981 new_bss->drv = drv;
Dmitry Shmidtcce06662013-11-04 18:44:24 -08005982 new_bss->next = drv->first_bss->next;
5983 new_bss->freq = drv->first_bss->freq;
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08005984 new_bss->ctx = bss_ctx;
Dmitry Shmidtcce06662013-11-04 18:44:24 -08005985 new_bss->added_if = added;
5986 drv->first_bss->next = new_bss;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005987 if (drv_priv)
5988 *drv_priv = new_bss;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005989 nl80211_init_bss(new_bss);
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08005990
5991 /* Subscribe management frames for this WPA_IF_AP_BSS */
5992 if (nl80211_setup_ap(new_bss))
5993 return -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005994 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07005995
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08005996 if (drv->global)
5997 drv->global->if_add_ifindex = ifidx;
5998
Dmitry Shmidt43cb5782014-06-16 16:23:22 -07005999 /*
6000 * Some virtual interfaces need to process EAPOL packets and events on
6001 * the parent interface. This is used mainly with hostapd.
6002 */
6003 if (ifidx > 0 &&
6004 (drv->hostapd ||
6005 nlmode == NL80211_IFTYPE_AP_VLAN ||
6006 nlmode == NL80211_IFTYPE_WDS ||
6007 nlmode == NL80211_IFTYPE_MONITOR))
Dmitry Shmidtdf5a7e42014-04-02 12:59:59 -07006008 add_ifidx(drv, ifidx);
6009
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006010 return 0;
6011}
6012
6013
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08006014static int wpa_driver_nl80211_if_remove(struct i802_bss *bss,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006015 enum wpa_driver_if_type type,
6016 const char *ifname)
6017{
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006018 struct wpa_driver_nl80211_data *drv = bss->drv;
6019 int ifindex = if_nametoindex(ifname);
6020
Dmitry Shmidtcce06662013-11-04 18:44:24 -08006021 wpa_printf(MSG_DEBUG, "nl80211: %s(type=%d ifname=%s) ifindex=%d added_if=%d",
6022 __func__, type, ifname, ifindex, bss->added_if);
Dmitry Shmidt01904cf2013-12-05 11:08:35 -08006023 if (ifindex > 0 && (bss->added_if || bss->ifindex != ifindex))
Dmitry Shmidt051af732013-10-22 13:52:46 -07006024 nl80211_remove_iface(drv, ifindex);
Dmitry Shmidt76cd2cc2014-05-27 12:56:04 -07006025 else if (ifindex > 0 && !bss->added_if) {
6026 struct wpa_driver_nl80211_data *drv2;
6027 dl_list_for_each(drv2, &drv->global->interfaces,
6028 struct wpa_driver_nl80211_data, list)
6029 del_ifidx(drv2, ifindex);
6030 }
Dmitry Shmidtaa532512012-09-24 10:35:31 -07006031
Dmitry Shmidtaa532512012-09-24 10:35:31 -07006032 if (type != WPA_IF_AP_BSS)
6033 return 0;
6034
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006035 if (bss->added_if_into_bridge) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006036 if (linux_br_del_if(drv->global->ioctl_sock, bss->brname,
6037 bss->ifname) < 0)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006038 wpa_printf(MSG_INFO, "nl80211: Failed to remove "
6039 "interface %s from bridge %s: %s",
6040 bss->ifname, bss->brname, strerror(errno));
6041 }
6042 if (bss->added_bridge) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006043 if (linux_br_del(drv->global->ioctl_sock, bss->brname) < 0)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006044 wpa_printf(MSG_INFO, "nl80211: Failed to remove "
6045 "bridge %s: %s",
6046 bss->brname, strerror(errno));
6047 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006048
Dmitry Shmidtcce06662013-11-04 18:44:24 -08006049 if (bss != drv->first_bss) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006050 struct i802_bss *tbss;
6051
Dmitry Shmidtcce06662013-11-04 18:44:24 -08006052 wpa_printf(MSG_DEBUG, "nl80211: Not the first BSS - remove it");
6053 for (tbss = drv->first_bss; tbss; tbss = tbss->next) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006054 if (tbss->next == bss) {
6055 tbss->next = bss->next;
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08006056 /* Unsubscribe management frames */
6057 nl80211_teardown_ap(bss);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006058 nl80211_destroy_bss(bss);
Dmitry Shmidtdf5a7e42014-04-02 12:59:59 -07006059 if (!bss->added_if)
6060 i802_set_iface_flags(bss, 0);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006061 os_free(bss);
6062 bss = NULL;
6063 break;
6064 }
6065 }
6066 if (bss)
6067 wpa_printf(MSG_INFO, "nl80211: %s - could not find "
6068 "BSS %p in the list", __func__, bss);
Dmitry Shmidtcce06662013-11-04 18:44:24 -08006069 } else {
6070 wpa_printf(MSG_DEBUG, "nl80211: First BSS - reassign context");
6071 nl80211_teardown_ap(bss);
6072 if (!bss->added_if && !drv->first_bss->next)
6073 wpa_driver_nl80211_del_beacon(drv);
6074 nl80211_destroy_bss(bss);
6075 if (!bss->added_if)
6076 i802_set_iface_flags(bss, 0);
6077 if (drv->first_bss->next) {
6078 drv->first_bss = drv->first_bss->next;
6079 drv->ctx = drv->first_bss->ctx;
6080 os_free(bss);
6081 } else {
6082 wpa_printf(MSG_DEBUG, "nl80211: No second BSS to reassign context to");
6083 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006084 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006085
6086 return 0;
6087}
6088
6089
6090static int cookie_handler(struct nl_msg *msg, void *arg)
6091{
6092 struct nlattr *tb[NL80211_ATTR_MAX + 1];
6093 struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg));
6094 u64 *cookie = arg;
6095 nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0),
6096 genlmsg_attrlen(gnlh, 0), NULL);
6097 if (tb[NL80211_ATTR_COOKIE])
6098 *cookie = nla_get_u64(tb[NL80211_ATTR_COOKIE]);
6099 return NL_SKIP;
6100}
6101
6102
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006103static int nl80211_send_frame_cmd(struct i802_bss *bss,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006104 unsigned int freq, unsigned int wait,
6105 const u8 *buf, size_t buf_len,
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006106 u64 *cookie_out, int no_cck, int no_ack,
6107 int offchanok)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006108{
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006109 struct wpa_driver_nl80211_data *drv = bss->drv;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006110 struct nl_msg *msg;
6111 u64 cookie;
6112 int ret = -1;
6113
Dmitry Shmidt8da800a2013-04-24 12:57:01 -07006114 wpa_printf(MSG_MSGDUMP, "nl80211: CMD_FRAME freq=%u wait=%u no_cck=%d "
Dmitry Shmidt04949592012-07-19 12:16:46 -07006115 "no_ack=%d offchanok=%d",
6116 freq, wait, no_cck, no_ack, offchanok);
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07006117 wpa_hexdump(MSG_MSGDUMP, "CMD_FRAME", buf, buf_len);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006118
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08006119 if (!(msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_FRAME)) ||
6120 (freq && nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq)) ||
6121 (wait && nla_put_u32(msg, NL80211_ATTR_DURATION, wait)) ||
6122 (offchanok && ((drv->capa.flags & WPA_DRIVER_FLAGS_OFFCHANNEL_TX) ||
6123 drv->test_use_roc_tx) &&
6124 nla_put_flag(msg, NL80211_ATTR_OFFCHANNEL_TX_OK)) ||
6125 (no_cck && nla_put_flag(msg, NL80211_ATTR_TX_NO_CCK_RATE)) ||
6126 (no_ack && nla_put_flag(msg, NL80211_ATTR_DONT_WAIT_FOR_ACK)) ||
6127 nla_put(msg, NL80211_ATTR_FRAME, buf_len, buf))
6128 goto fail;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006129
6130 cookie = 0;
6131 ret = send_and_recv_msgs(drv, msg, cookie_handler, &cookie);
6132 msg = NULL;
6133 if (ret) {
6134 wpa_printf(MSG_DEBUG, "nl80211: Frame command failed: ret=%d "
Dmitry Shmidt6e933c12011-09-27 12:29:26 -07006135 "(%s) (freq=%u wait=%u)", ret, strerror(-ret),
6136 freq, wait);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08006137 } else {
6138 wpa_printf(MSG_MSGDUMP, "nl80211: Frame TX command accepted%s; "
6139 "cookie 0x%llx", no_ack ? " (no ACK)" : "",
6140 (long long unsigned int) cookie);
6141
6142 if (cookie_out)
6143 *cookie_out = no_ack ? (u64) -1 : cookie;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006144 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006145
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08006146fail:
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006147 nlmsg_free(msg);
6148 return ret;
6149}
6150
6151
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08006152static int wpa_driver_nl80211_send_action(struct i802_bss *bss,
6153 unsigned int freq,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006154 unsigned int wait_time,
6155 const u8 *dst, const u8 *src,
6156 const u8 *bssid,
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006157 const u8 *data, size_t data_len,
6158 int no_cck)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006159{
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006160 struct wpa_driver_nl80211_data *drv = bss->drv;
6161 int ret = -1;
6162 u8 *buf;
6163 struct ieee80211_hdr *hdr;
6164
6165 wpa_printf(MSG_DEBUG, "nl80211: Send Action frame (ifindex=%d, "
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08006166 "freq=%u MHz wait=%d ms no_cck=%d)",
6167 drv->ifindex, freq, wait_time, no_cck);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006168
6169 buf = os_zalloc(24 + data_len);
6170 if (buf == NULL)
6171 return ret;
6172 os_memcpy(buf + 24, data, data_len);
6173 hdr = (struct ieee80211_hdr *) buf;
6174 hdr->frame_control =
6175 IEEE80211_FC(WLAN_FC_TYPE_MGMT, WLAN_FC_STYPE_ACTION);
6176 os_memcpy(hdr->addr1, dst, ETH_ALEN);
6177 os_memcpy(hdr->addr2, src, ETH_ALEN);
6178 os_memcpy(hdr->addr3, bssid, ETH_ALEN);
6179
Dmitry Shmidt56052862013-10-04 10:23:25 -07006180 if (is_ap_interface(drv->nlmode) &&
6181 (!(drv->capa.flags & WPA_DRIVER_FLAGS_OFFCHANNEL_TX) ||
6182 (int) freq == bss->freq || drv->device_ap_sme ||
6183 !drv->use_monitor))
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08006184 ret = wpa_driver_nl80211_send_mlme(bss, buf, 24 + data_len,
6185 0, freq, no_cck, 1,
6186 wait_time);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006187 else
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006188 ret = nl80211_send_frame_cmd(bss, freq, wait_time, buf,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006189 24 + data_len,
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006190 &drv->send_action_cookie,
6191 no_cck, 0, 1);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006192
6193 os_free(buf);
6194 return ret;
6195}
6196
6197
6198static void wpa_driver_nl80211_send_action_cancel_wait(void *priv)
6199{
6200 struct i802_bss *bss = priv;
6201 struct wpa_driver_nl80211_data *drv = bss->drv;
6202 struct nl_msg *msg;
6203 int ret;
6204
Dmitry Shmidt2f3b8de2013-03-01 09:32:50 -08006205 wpa_printf(MSG_DEBUG, "nl80211: Cancel TX frame wait: cookie=0x%llx",
6206 (long long unsigned int) drv->send_action_cookie);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08006207 if (!(msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_FRAME_WAIT_CANCEL)) ||
6208 nla_put_u64(msg, NL80211_ATTR_COOKIE, drv->send_action_cookie)) {
6209 nlmsg_free(msg);
6210 return;
6211 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006212
6213 ret = send_and_recv_msgs(drv, msg, NULL, NULL);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006214 if (ret)
6215 wpa_printf(MSG_DEBUG, "nl80211: wait cancel failed: ret=%d "
6216 "(%s)", ret, strerror(-ret));
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006217}
6218
6219
6220static int wpa_driver_nl80211_remain_on_channel(void *priv, unsigned int freq,
6221 unsigned int duration)
6222{
6223 struct i802_bss *bss = priv;
6224 struct wpa_driver_nl80211_data *drv = bss->drv;
6225 struct nl_msg *msg;
6226 int ret;
6227 u64 cookie;
6228
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08006229 if (!(msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_REMAIN_ON_CHANNEL)) ||
6230 nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq) ||
6231 nla_put_u32(msg, NL80211_ATTR_DURATION, duration)) {
6232 nlmsg_free(msg);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006233 return -1;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08006234 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006235
6236 cookie = 0;
6237 ret = send_and_recv_msgs(drv, msg, cookie_handler, &cookie);
6238 if (ret == 0) {
6239 wpa_printf(MSG_DEBUG, "nl80211: Remain-on-channel cookie "
6240 "0x%llx for freq=%u MHz duration=%u",
6241 (long long unsigned int) cookie, freq, duration);
6242 drv->remain_on_chan_cookie = cookie;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006243 drv->pending_remain_on_chan = 1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006244 return 0;
6245 }
6246 wpa_printf(MSG_DEBUG, "nl80211: Failed to request remain-on-channel "
6247 "(freq=%d duration=%u): %d (%s)",
6248 freq, duration, ret, strerror(-ret));
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006249 return -1;
6250}
6251
6252
6253static int wpa_driver_nl80211_cancel_remain_on_channel(void *priv)
6254{
6255 struct i802_bss *bss = priv;
6256 struct wpa_driver_nl80211_data *drv = bss->drv;
6257 struct nl_msg *msg;
6258 int ret;
6259
6260 if (!drv->pending_remain_on_chan) {
6261 wpa_printf(MSG_DEBUG, "nl80211: No pending remain-on-channel "
6262 "to cancel");
6263 return -1;
6264 }
6265
6266 wpa_printf(MSG_DEBUG, "nl80211: Cancel remain-on-channel with cookie "
6267 "0x%llx",
6268 (long long unsigned int) drv->remain_on_chan_cookie);
6269
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08006270 msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL);
6271 if (!msg ||
6272 nla_put_u64(msg, NL80211_ATTR_COOKIE, drv->remain_on_chan_cookie)) {
6273 nlmsg_free(msg);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006274 return -1;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08006275 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006276
6277 ret = send_and_recv_msgs(drv, msg, NULL, NULL);
6278 if (ret == 0)
6279 return 0;
6280 wpa_printf(MSG_DEBUG, "nl80211: Failed to cancel remain-on-channel: "
6281 "%d (%s)", ret, strerror(-ret));
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006282 return -1;
6283}
6284
6285
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08006286static int wpa_driver_nl80211_probe_req_report(struct i802_bss *bss, int report)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006287{
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006288 struct wpa_driver_nl80211_data *drv = bss->drv;
Dmitry Shmidt6e933c12011-09-27 12:29:26 -07006289
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006290 if (!report) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006291 if (bss->nl_preq && drv->device_ap_sme &&
Dmitry Shmidt03658832014-08-13 11:03:49 -07006292 is_ap_interface(drv->nlmode) && !bss->in_deinit &&
6293 !bss->static_ap) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006294 /*
6295 * Do not disable Probe Request reporting that was
6296 * enabled in nl80211_setup_ap().
6297 */
6298 wpa_printf(MSG_DEBUG, "nl80211: Skip disabling of "
6299 "Probe Request reporting nl_preq=%p while "
6300 "in AP mode", bss->nl_preq);
6301 } else if (bss->nl_preq) {
6302 wpa_printf(MSG_DEBUG, "nl80211: Disable Probe Request "
6303 "reporting nl_preq=%p", bss->nl_preq);
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -07006304 nl80211_destroy_eloop_handle(&bss->nl_preq);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006305 }
6306 return 0;
6307 }
6308
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006309 if (bss->nl_preq) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006310 wpa_printf(MSG_DEBUG, "nl80211: Probe Request reporting "
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006311 "already on! nl_preq=%p", bss->nl_preq);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006312 return 0;
6313 }
6314
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006315 bss->nl_preq = nl_create_handle(drv->global->nl_cb, "preq");
6316 if (bss->nl_preq == NULL)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006317 return -1;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006318 wpa_printf(MSG_DEBUG, "nl80211: Enable Probe Request "
6319 "reporting nl_preq=%p", bss->nl_preq);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006320
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006321 if (nl80211_register_frame(bss, bss->nl_preq,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006322 (WLAN_FC_TYPE_MGMT << 2) |
6323 (WLAN_FC_STYPE_PROBE_REQ << 4),
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006324 NULL, 0) < 0)
6325 goto out_err;
Dmitry Shmidt497c1d52011-07-21 15:19:46 -07006326
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -07006327 nl80211_register_eloop_read(&bss->nl_preq,
6328 wpa_driver_nl80211_event_receive,
6329 bss->nl_cb);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006330
6331 return 0;
6332
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006333 out_err:
6334 nl_destroy_handles(&bss->nl_preq);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006335 return -1;
6336}
6337
6338
6339static int nl80211_disable_11b_rates(struct wpa_driver_nl80211_data *drv,
6340 int ifindex, int disabled)
6341{
6342 struct nl_msg *msg;
6343 struct nlattr *bands, *band;
6344 int ret;
6345
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08006346 wpa_printf(MSG_DEBUG,
6347 "nl80211: NL80211_CMD_SET_TX_BITRATE_MASK (ifindex=%d %s)",
6348 ifindex, disabled ? "NL80211_TXRATE_LEGACY=OFDM-only" :
6349 "no NL80211_TXRATE_LEGACY constraint");
6350
6351 msg = nl80211_ifindex_msg(drv, ifindex, 0,
6352 NL80211_CMD_SET_TX_BITRATE_MASK);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006353 if (!msg)
6354 return -1;
6355
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006356 bands = nla_nest_start(msg, NL80211_ATTR_TX_RATES);
6357 if (!bands)
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08006358 goto fail;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006359
6360 /*
6361 * Disable 2 GHz rates 1, 2, 5.5, 11 Mbps by masking out everything
6362 * else apart from 6, 9, 12, 18, 24, 36, 48, 54 Mbps from non-MCS
6363 * rates. All 5 GHz rates are left enabled.
6364 */
6365 band = nla_nest_start(msg, NL80211_BAND_2GHZ);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08006366 if (!band ||
6367 (disabled && nla_put(msg, NL80211_TXRATE_LEGACY, 8,
6368 "\x0c\x12\x18\x24\x30\x48\x60\x6c")))
6369 goto fail;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006370 nla_nest_end(msg, band);
6371
6372 nla_nest_end(msg, bands);
6373
6374 ret = send_and_recv_msgs(drv, msg, NULL, NULL);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006375 if (ret) {
6376 wpa_printf(MSG_DEBUG, "nl80211: Set TX rates failed: ret=%d "
6377 "(%s)", ret, strerror(-ret));
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07006378 } else
6379 drv->disabled_11b_rates = disabled;
6380
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006381 return ret;
6382
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08006383fail:
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006384 nlmsg_free(msg);
6385 return -1;
6386}
6387
6388
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006389static int wpa_driver_nl80211_deinit_ap(void *priv)
6390{
6391 struct i802_bss *bss = priv;
6392 struct wpa_driver_nl80211_data *drv = bss->drv;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006393 if (!is_ap_interface(drv->nlmode))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006394 return -1;
6395 wpa_driver_nl80211_del_beacon(drv);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08006396 bss->beacon_set = 0;
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -07006397
6398 /*
6399 * If the P2P GO interface was dynamically added, then it is
6400 * possible that the interface change to station is not possible.
6401 */
6402 if (drv->nlmode == NL80211_IFTYPE_P2P_GO && bss->if_dynamic)
6403 return 0;
6404
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006405 return wpa_driver_nl80211_set_mode(priv, NL80211_IFTYPE_STATION);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006406}
6407
6408
Dmitry Shmidtea69e842013-05-13 14:52:28 -07006409static int wpa_driver_nl80211_stop_ap(void *priv)
6410{
6411 struct i802_bss *bss = priv;
6412 struct wpa_driver_nl80211_data *drv = bss->drv;
6413 if (!is_ap_interface(drv->nlmode))
6414 return -1;
6415 wpa_driver_nl80211_del_beacon(drv);
6416 bss->beacon_set = 0;
6417 return 0;
6418}
6419
6420
Dmitry Shmidt04949592012-07-19 12:16:46 -07006421static int wpa_driver_nl80211_deinit_p2p_cli(void *priv)
6422{
6423 struct i802_bss *bss = priv;
6424 struct wpa_driver_nl80211_data *drv = bss->drv;
6425 if (drv->nlmode != NL80211_IFTYPE_P2P_CLIENT)
6426 return -1;
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -07006427
6428 /*
6429 * If the P2P Client interface was dynamically added, then it is
6430 * possible that the interface change to station is not possible.
6431 */
6432 if (bss->if_dynamic)
6433 return 0;
6434
Dmitry Shmidt04949592012-07-19 12:16:46 -07006435 return wpa_driver_nl80211_set_mode(priv, NL80211_IFTYPE_STATION);
6436}
6437
6438
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006439static void wpa_driver_nl80211_resume(void *priv)
6440{
6441 struct i802_bss *bss = priv;
Dmitry Shmidt34af3062013-07-11 10:46:32 -07006442
6443 if (i802_set_iface_flags(bss, 1))
6444 wpa_printf(MSG_DEBUG, "nl80211: Failed to set interface up on resume event");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006445}
6446
6447
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006448static int nl80211_signal_monitor(void *priv, int threshold, int hysteresis)
6449{
6450 struct i802_bss *bss = priv;
6451 struct wpa_driver_nl80211_data *drv = bss->drv;
Dmitry Shmidt8da800a2013-04-24 12:57:01 -07006452 struct nl_msg *msg;
6453 struct nlattr *cqm;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006454
6455 wpa_printf(MSG_DEBUG, "nl80211: Signal monitor threshold=%d "
6456 "hysteresis=%d", threshold, hysteresis);
6457
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08006458 if (!(msg = nl80211_bss_msg(bss, 0, NL80211_CMD_SET_CQM)) ||
6459 !(cqm = nla_nest_start(msg, NL80211_ATTR_CQM)) ||
6460 nla_put_u32(msg, NL80211_ATTR_CQM_RSSI_THOLD, threshold) ||
6461 nla_put_u32(msg, NL80211_ATTR_CQM_RSSI_HYST, hysteresis)) {
6462 nlmsg_free(msg);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006463 return -1;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08006464 }
Dmitry Shmidt8da800a2013-04-24 12:57:01 -07006465 nla_nest_end(msg, cqm);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006466
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08006467 return send_and_recv_msgs(drv, msg, NULL, NULL);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006468}
6469
6470
Dmitry Shmidt34af3062013-07-11 10:46:32 -07006471static int get_channel_width(struct nl_msg *msg, void *arg)
6472{
6473 struct nlattr *tb[NL80211_ATTR_MAX + 1];
6474 struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg));
6475 struct wpa_signal_info *sig_change = arg;
6476
6477 nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0),
6478 genlmsg_attrlen(gnlh, 0), NULL);
6479
6480 sig_change->center_frq1 = -1;
6481 sig_change->center_frq2 = -1;
6482 sig_change->chanwidth = CHAN_WIDTH_UNKNOWN;
6483
6484 if (tb[NL80211_ATTR_CHANNEL_WIDTH]) {
6485 sig_change->chanwidth = convert2width(
6486 nla_get_u32(tb[NL80211_ATTR_CHANNEL_WIDTH]));
6487 if (tb[NL80211_ATTR_CENTER_FREQ1])
6488 sig_change->center_frq1 =
6489 nla_get_u32(tb[NL80211_ATTR_CENTER_FREQ1]);
6490 if (tb[NL80211_ATTR_CENTER_FREQ2])
6491 sig_change->center_frq2 =
6492 nla_get_u32(tb[NL80211_ATTR_CENTER_FREQ2]);
6493 }
6494
6495 return NL_SKIP;
6496}
6497
6498
6499static int nl80211_get_channel_width(struct wpa_driver_nl80211_data *drv,
6500 struct wpa_signal_info *sig)
6501{
6502 struct nl_msg *msg;
6503
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08006504 msg = nl80211_drv_msg(drv, 0, NL80211_CMD_GET_INTERFACE);
Dmitry Shmidt34af3062013-07-11 10:46:32 -07006505 return send_and_recv_msgs(drv, msg, get_channel_width, sig);
Dmitry Shmidt34af3062013-07-11 10:46:32 -07006506}
6507
6508
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006509static int nl80211_signal_poll(void *priv, struct wpa_signal_info *si)
6510{
6511 struct i802_bss *bss = priv;
6512 struct wpa_driver_nl80211_data *drv = bss->drv;
6513 int res;
6514
6515 os_memset(si, 0, sizeof(*si));
6516 res = nl80211_get_link_signal(drv, si);
6517 if (res != 0)
6518 return res;
6519
Dmitry Shmidt34af3062013-07-11 10:46:32 -07006520 res = nl80211_get_channel_width(drv, si);
6521 if (res != 0)
6522 return res;
6523
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006524 return nl80211_get_link_noise(drv, si);
6525}
6526
6527
6528static int nl80211_send_frame(void *priv, const u8 *data, size_t data_len,
6529 int encrypt)
6530{
6531 struct i802_bss *bss = priv;
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08006532 return wpa_driver_nl80211_send_frame(bss, data, data_len, encrypt, 0,
6533 0, 0, 0, 0);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006534}
6535
6536
6537static int nl80211_set_param(void *priv, const char *param)
6538{
6539 wpa_printf(MSG_DEBUG, "nl80211: driver param='%s'", param);
6540 if (param == NULL)
6541 return 0;
6542
6543#ifdef CONFIG_P2P
6544 if (os_strstr(param, "use_p2p_group_interface=1")) {
6545 struct i802_bss *bss = priv;
6546 struct wpa_driver_nl80211_data *drv = bss->drv;
6547
6548 wpa_printf(MSG_DEBUG, "nl80211: Use separate P2P group "
6549 "interface");
6550 drv->capa.flags |= WPA_DRIVER_FLAGS_P2P_CONCURRENT;
6551 drv->capa.flags |= WPA_DRIVER_FLAGS_P2P_MGMT_AND_NON_P2P;
6552 }
6553#endif /* CONFIG_P2P */
6554
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08006555 if (os_strstr(param, "use_monitor=1")) {
6556 struct i802_bss *bss = priv;
6557 struct wpa_driver_nl80211_data *drv = bss->drv;
6558 drv->use_monitor = 1;
6559 }
6560
6561 if (os_strstr(param, "force_connect_cmd=1")) {
6562 struct i802_bss *bss = priv;
6563 struct wpa_driver_nl80211_data *drv = bss->drv;
6564 drv->capa.flags &= ~WPA_DRIVER_FLAGS_SME;
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07006565 drv->force_connect_cmd = 1;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08006566 }
6567
Dmitry Shmidt7d5c8f22014-03-03 13:53:28 -08006568 if (os_strstr(param, "no_offchannel_tx=1")) {
6569 struct i802_bss *bss = priv;
6570 struct wpa_driver_nl80211_data *drv = bss->drv;
6571 drv->capa.flags &= ~WPA_DRIVER_FLAGS_OFFCHANNEL_TX;
6572 drv->test_use_roc_tx = 1;
6573 }
6574
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006575 return 0;
6576}
6577
6578
6579static void * nl80211_global_init(void)
6580{
6581 struct nl80211_global *global;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006582 struct netlink_config *cfg;
6583
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006584 global = os_zalloc(sizeof(*global));
6585 if (global == NULL)
6586 return NULL;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006587 global->ioctl_sock = -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006588 dl_list_init(&global->interfaces);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006589 global->if_add_ifindex = -1;
6590
6591 cfg = os_zalloc(sizeof(*cfg));
6592 if (cfg == NULL)
6593 goto err;
6594
6595 cfg->ctx = global;
6596 cfg->newlink_cb = wpa_driver_nl80211_event_rtm_newlink;
6597 cfg->dellink_cb = wpa_driver_nl80211_event_rtm_dellink;
6598 global->netlink = netlink_init(cfg);
6599 if (global->netlink == NULL) {
6600 os_free(cfg);
6601 goto err;
6602 }
6603
6604 if (wpa_driver_nl80211_init_nl_global(global) < 0)
6605 goto err;
6606
6607 global->ioctl_sock = socket(PF_INET, SOCK_DGRAM, 0);
6608 if (global->ioctl_sock < 0) {
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -07006609 wpa_printf(MSG_ERROR, "nl80211: socket(PF_INET,SOCK_DGRAM) failed: %s",
6610 strerror(errno));
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006611 goto err;
6612 }
6613
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006614 return global;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006615
6616err:
6617 nl80211_global_deinit(global);
6618 return NULL;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006619}
6620
6621
6622static void nl80211_global_deinit(void *priv)
6623{
6624 struct nl80211_global *global = priv;
6625 if (global == NULL)
6626 return;
6627 if (!dl_list_empty(&global->interfaces)) {
6628 wpa_printf(MSG_ERROR, "nl80211: %u interface(s) remain at "
6629 "nl80211_global_deinit",
6630 dl_list_len(&global->interfaces));
6631 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006632
6633 if (global->netlink)
6634 netlink_deinit(global->netlink);
6635
6636 nl_destroy_handles(&global->nl);
6637
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -07006638 if (global->nl_event)
6639 nl80211_destroy_eloop_handle(&global->nl_event);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006640
6641 nl_cb_put(global->nl_cb);
6642
6643 if (global->ioctl_sock >= 0)
6644 close(global->ioctl_sock);
6645
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07006646 os_free(global);
6647}
6648
6649
6650static const char * nl80211_get_radio_name(void *priv)
6651{
6652 struct i802_bss *bss = priv;
6653 struct wpa_driver_nl80211_data *drv = bss->drv;
6654 return drv->phyname;
6655}
6656
6657
Jouni Malinen75ecf522011-06-27 15:19:46 -07006658static int nl80211_pmkid(struct i802_bss *bss, int cmd, const u8 *bssid,
6659 const u8 *pmkid)
6660{
6661 struct nl_msg *msg;
6662
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08006663 if (!(msg = nl80211_bss_msg(bss, 0, cmd)) ||
6664 (pmkid && nla_put(msg, NL80211_ATTR_PMKID, 16, pmkid)) ||
6665 (bssid && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid))) {
6666 nlmsg_free(msg);
6667 return -ENOBUFS;
6668 }
Jouni Malinen75ecf522011-06-27 15:19:46 -07006669
6670 return send_and_recv_msgs(bss->drv, msg, NULL, NULL);
Jouni Malinen75ecf522011-06-27 15:19:46 -07006671}
6672
6673
6674static int nl80211_add_pmkid(void *priv, const u8 *bssid, const u8 *pmkid)
6675{
6676 struct i802_bss *bss = priv;
6677 wpa_printf(MSG_DEBUG, "nl80211: Add PMKID for " MACSTR, MAC2STR(bssid));
6678 return nl80211_pmkid(bss, NL80211_CMD_SET_PMKSA, bssid, pmkid);
6679}
6680
6681
6682static int nl80211_remove_pmkid(void *priv, const u8 *bssid, const u8 *pmkid)
6683{
6684 struct i802_bss *bss = priv;
6685 wpa_printf(MSG_DEBUG, "nl80211: Delete PMKID for " MACSTR,
6686 MAC2STR(bssid));
6687 return nl80211_pmkid(bss, NL80211_CMD_DEL_PMKSA, bssid, pmkid);
6688}
6689
6690
6691static int nl80211_flush_pmkid(void *priv)
6692{
6693 struct i802_bss *bss = priv;
6694 wpa_printf(MSG_DEBUG, "nl80211: Flush PMKIDs");
6695 return nl80211_pmkid(bss, NL80211_CMD_FLUSH_PMKSA, NULL, NULL);
6696}
6697
6698
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -07006699static void clean_survey_results(struct survey_results *survey_results)
6700{
6701 struct freq_survey *survey, *tmp;
6702
6703 if (dl_list_empty(&survey_results->survey_list))
6704 return;
6705
6706 dl_list_for_each_safe(survey, tmp, &survey_results->survey_list,
6707 struct freq_survey, list) {
6708 dl_list_del(&survey->list);
6709 os_free(survey);
6710 }
6711}
6712
6713
6714static void add_survey(struct nlattr **sinfo, u32 ifidx,
6715 struct dl_list *survey_list)
6716{
6717 struct freq_survey *survey;
6718
6719 survey = os_zalloc(sizeof(struct freq_survey));
6720 if (!survey)
6721 return;
6722
6723 survey->ifidx = ifidx;
6724 survey->freq = nla_get_u32(sinfo[NL80211_SURVEY_INFO_FREQUENCY]);
6725 survey->filled = 0;
6726
6727 if (sinfo[NL80211_SURVEY_INFO_NOISE]) {
6728 survey->nf = (int8_t)
6729 nla_get_u8(sinfo[NL80211_SURVEY_INFO_NOISE]);
6730 survey->filled |= SURVEY_HAS_NF;
6731 }
6732
6733 if (sinfo[NL80211_SURVEY_INFO_CHANNEL_TIME]) {
6734 survey->channel_time =
6735 nla_get_u64(sinfo[NL80211_SURVEY_INFO_CHANNEL_TIME]);
6736 survey->filled |= SURVEY_HAS_CHAN_TIME;
6737 }
6738
6739 if (sinfo[NL80211_SURVEY_INFO_CHANNEL_TIME_BUSY]) {
6740 survey->channel_time_busy =
6741 nla_get_u64(sinfo[NL80211_SURVEY_INFO_CHANNEL_TIME_BUSY]);
6742 survey->filled |= SURVEY_HAS_CHAN_TIME_BUSY;
6743 }
6744
6745 if (sinfo[NL80211_SURVEY_INFO_CHANNEL_TIME_RX]) {
6746 survey->channel_time_rx =
6747 nla_get_u64(sinfo[NL80211_SURVEY_INFO_CHANNEL_TIME_RX]);
6748 survey->filled |= SURVEY_HAS_CHAN_TIME_RX;
6749 }
6750
6751 if (sinfo[NL80211_SURVEY_INFO_CHANNEL_TIME_TX]) {
6752 survey->channel_time_tx =
6753 nla_get_u64(sinfo[NL80211_SURVEY_INFO_CHANNEL_TIME_TX]);
6754 survey->filled |= SURVEY_HAS_CHAN_TIME_TX;
6755 }
6756
6757 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)",
6758 survey->freq,
6759 survey->nf,
6760 (unsigned long int) survey->channel_time,
6761 (unsigned long int) survey->channel_time_busy,
6762 (unsigned long int) survey->channel_time_tx,
6763 (unsigned long int) survey->channel_time_rx,
6764 survey->filled);
6765
6766 dl_list_add_tail(survey_list, &survey->list);
6767}
6768
6769
6770static int check_survey_ok(struct nlattr **sinfo, u32 surveyed_freq,
6771 unsigned int freq_filter)
6772{
6773 if (!freq_filter)
6774 return 1;
6775
6776 return freq_filter == surveyed_freq;
6777}
6778
6779
6780static int survey_handler(struct nl_msg *msg, void *arg)
6781{
6782 struct nlattr *tb[NL80211_ATTR_MAX + 1];
6783 struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg));
6784 struct nlattr *sinfo[NL80211_SURVEY_INFO_MAX + 1];
6785 struct survey_results *survey_results;
6786 u32 surveyed_freq = 0;
6787 u32 ifidx;
6788
6789 static struct nla_policy survey_policy[NL80211_SURVEY_INFO_MAX + 1] = {
6790 [NL80211_SURVEY_INFO_FREQUENCY] = { .type = NLA_U32 },
6791 [NL80211_SURVEY_INFO_NOISE] = { .type = NLA_U8 },
6792 };
6793
6794 survey_results = (struct survey_results *) arg;
6795
6796 nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0),
6797 genlmsg_attrlen(gnlh, 0), NULL);
6798
Dmitry Shmidt97672262014-02-03 13:02:54 -08006799 if (!tb[NL80211_ATTR_IFINDEX])
6800 return NL_SKIP;
6801
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -07006802 ifidx = nla_get_u32(tb[NL80211_ATTR_IFINDEX]);
6803
6804 if (!tb[NL80211_ATTR_SURVEY_INFO])
6805 return NL_SKIP;
6806
6807 if (nla_parse_nested(sinfo, NL80211_SURVEY_INFO_MAX,
6808 tb[NL80211_ATTR_SURVEY_INFO],
6809 survey_policy))
6810 return NL_SKIP;
6811
6812 if (!sinfo[NL80211_SURVEY_INFO_FREQUENCY]) {
6813 wpa_printf(MSG_ERROR, "nl80211: Invalid survey data");
6814 return NL_SKIP;
6815 }
6816
6817 surveyed_freq = nla_get_u32(sinfo[NL80211_SURVEY_INFO_FREQUENCY]);
6818
6819 if (!check_survey_ok(sinfo, surveyed_freq,
6820 survey_results->freq_filter))
6821 return NL_SKIP;
6822
6823 if (survey_results->freq_filter &&
6824 survey_results->freq_filter != surveyed_freq) {
6825 wpa_printf(MSG_EXCESSIVE, "nl80211: Ignoring survey data for freq %d MHz",
6826 surveyed_freq);
6827 return NL_SKIP;
6828 }
6829
6830 add_survey(sinfo, ifidx, &survey_results->survey_list);
6831
6832 return NL_SKIP;
6833}
6834
6835
6836static int wpa_driver_nl80211_get_survey(void *priv, unsigned int freq)
6837{
6838 struct i802_bss *bss = priv;
6839 struct wpa_driver_nl80211_data *drv = bss->drv;
6840 struct nl_msg *msg;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08006841 int err;
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -07006842 union wpa_event_data data;
6843 struct survey_results *survey_results;
6844
6845 os_memset(&data, 0, sizeof(data));
6846 survey_results = &data.survey_results;
6847
6848 dl_list_init(&survey_results->survey_list);
6849
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08006850 msg = nl80211_drv_msg(drv, NLM_F_DUMP, NL80211_CMD_GET_SURVEY);
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -07006851 if (!msg)
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08006852 return -ENOBUFS;
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -07006853
6854 if (freq)
6855 data.survey_results.freq_filter = freq;
6856
6857 do {
6858 wpa_printf(MSG_DEBUG, "nl80211: Fetch survey data");
6859 err = send_and_recv_msgs(drv, msg, survey_handler,
6860 survey_results);
6861 } while (err > 0);
6862
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08006863 if (err)
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -07006864 wpa_printf(MSG_ERROR, "nl80211: Failed to process survey data");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08006865 else
6866 wpa_supplicant_event(drv->ctx, EVENT_SURVEY, &data);
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -07006867
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -07006868 clean_survey_results(survey_results);
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -07006869 return err;
6870}
6871
6872
Dmitry Shmidt807291d2015-01-27 13:40:23 -08006873static void nl80211_set_rekey_info(void *priv, const u8 *kek, size_t kek_len,
6874 const u8 *kck, size_t kck_len,
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006875 const u8 *replay_ctr)
6876{
6877 struct i802_bss *bss = priv;
6878 struct wpa_driver_nl80211_data *drv = bss->drv;
6879 struct nlattr *replay_nested;
6880 struct nl_msg *msg;
Dmitry Shmidtff787d52015-01-12 13:01:47 -08006881 int ret;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006882
Dmitry Shmidtff787d52015-01-12 13:01:47 -08006883 if (!drv->set_rekey_offload)
6884 return;
6885
6886 wpa_printf(MSG_DEBUG, "nl80211: Set rekey offload");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08006887 if (!(msg = nl80211_bss_msg(bss, 0, NL80211_CMD_SET_REKEY_OFFLOAD)) ||
6888 !(replay_nested = nla_nest_start(msg, NL80211_ATTR_REKEY_DATA)) ||
Dmitry Shmidt807291d2015-01-27 13:40:23 -08006889 nla_put(msg, NL80211_REKEY_DATA_KEK, kek_len, kek) ||
6890 nla_put(msg, NL80211_REKEY_DATA_KCK, kck_len, kck) ||
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08006891 nla_put(msg, NL80211_REKEY_DATA_REPLAY_CTR, NL80211_REPLAY_CTR_LEN,
6892 replay_ctr)) {
6893 nl80211_nlmsg_clear(msg);
6894 nlmsg_free(msg);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006895 return;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08006896 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006897
6898 nla_nest_end(msg, replay_nested);
6899
Dmitry Shmidtff787d52015-01-12 13:01:47 -08006900 ret = send_and_recv_msgs(drv, msg, NULL, (void *) -1);
6901 if (ret == -EOPNOTSUPP) {
6902 wpa_printf(MSG_DEBUG,
6903 "nl80211: Driver does not support rekey offload");
6904 drv->set_rekey_offload = 0;
6905 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006906}
6907
6908
6909static void nl80211_send_null_frame(struct i802_bss *bss, const u8 *own_addr,
6910 const u8 *addr, int qos)
6911{
6912 /* send data frame to poll STA and check whether
6913 * this frame is ACKed */
6914 struct {
6915 struct ieee80211_hdr hdr;
6916 u16 qos_ctl;
6917 } STRUCT_PACKED nulldata;
6918 size_t size;
6919
6920 /* Send data frame to poll STA and check whether this frame is ACKed */
6921
6922 os_memset(&nulldata, 0, sizeof(nulldata));
6923
6924 if (qos) {
6925 nulldata.hdr.frame_control =
6926 IEEE80211_FC(WLAN_FC_TYPE_DATA,
6927 WLAN_FC_STYPE_QOS_NULL);
6928 size = sizeof(nulldata);
6929 } else {
6930 nulldata.hdr.frame_control =
6931 IEEE80211_FC(WLAN_FC_TYPE_DATA,
6932 WLAN_FC_STYPE_NULLFUNC);
6933 size = sizeof(struct ieee80211_hdr);
6934 }
6935
6936 nulldata.hdr.frame_control |= host_to_le16(WLAN_FC_FROMDS);
6937 os_memcpy(nulldata.hdr.IEEE80211_DA_FROMDS, addr, ETH_ALEN);
6938 os_memcpy(nulldata.hdr.IEEE80211_BSSID_FROMDS, own_addr, ETH_ALEN);
6939 os_memcpy(nulldata.hdr.IEEE80211_SA_FROMDS, own_addr, ETH_ALEN);
6940
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08006941 if (wpa_driver_nl80211_send_mlme(bss, (u8 *) &nulldata, size, 0, 0, 0,
6942 0, 0) < 0)
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006943 wpa_printf(MSG_DEBUG, "nl80211_send_null_frame: Failed to "
6944 "send poll frame");
6945}
6946
6947static void nl80211_poll_client(void *priv, const u8 *own_addr, const u8 *addr,
6948 int qos)
6949{
6950 struct i802_bss *bss = priv;
6951 struct wpa_driver_nl80211_data *drv = bss->drv;
6952 struct nl_msg *msg;
Dmitry Shmidt7f656022015-02-25 14:36:37 -08006953 int ret;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006954
6955 if (!drv->poll_command_supported) {
6956 nl80211_send_null_frame(bss, own_addr, addr, qos);
6957 return;
6958 }
6959
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08006960 if (!(msg = nl80211_bss_msg(bss, 0, NL80211_CMD_PROBE_CLIENT)) ||
6961 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) {
6962 nlmsg_free(msg);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006963 return;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08006964 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006965
Dmitry Shmidt7f656022015-02-25 14:36:37 -08006966 ret = send_and_recv_msgs(drv, msg, NULL, NULL);
6967 if (ret < 0) {
6968 wpa_printf(MSG_DEBUG, "nl80211: Client probe request for "
6969 MACSTR " failed: ret=%d (%s)",
6970 MAC2STR(addr), ret, strerror(-ret));
6971 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006972}
6973
6974
6975static int nl80211_set_power_save(struct i802_bss *bss, int enabled)
6976{
6977 struct nl_msg *msg;
6978
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08006979 if (!(msg = nl80211_bss_msg(bss, 0, NL80211_CMD_SET_POWER_SAVE)) ||
6980 nla_put_u32(msg, NL80211_ATTR_PS_STATE,
6981 enabled ? NL80211_PS_ENABLED : NL80211_PS_DISABLED)) {
6982 nlmsg_free(msg);
6983 return -ENOBUFS;
6984 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006985 return send_and_recv_msgs(bss->drv, msg, NULL, NULL);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08006986}
6987
6988
6989static int nl80211_set_p2p_powersave(void *priv, int legacy_ps, int opp_ps,
6990 int ctwindow)
6991{
6992 struct i802_bss *bss = priv;
6993
6994 wpa_printf(MSG_DEBUG, "nl80211: set_p2p_powersave (legacy_ps=%d "
6995 "opp_ps=%d ctwindow=%d)", legacy_ps, opp_ps, ctwindow);
6996
Dmitry Shmidt292b0c32013-11-22 12:54:42 -08006997 if (opp_ps != -1 || ctwindow != -1) {
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08006998#ifdef ANDROID_P2P
6999 wpa_driver_set_p2p_ps(priv, legacy_ps, opp_ps, ctwindow);
Dmitry Shmidt292b0c32013-11-22 12:54:42 -08007000#else /* ANDROID_P2P */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08007001 return -1; /* Not yet supported */
Dmitry Shmidt292b0c32013-11-22 12:54:42 -08007002#endif /* ANDROID_P2P */
7003 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08007004
7005 if (legacy_ps == -1)
7006 return 0;
7007 if (legacy_ps != 0 && legacy_ps != 1)
7008 return -1; /* Not yet supported */
7009
7010 return nl80211_set_power_save(bss, legacy_ps);
7011}
7012
7013
Dmitry Shmidt051af732013-10-22 13:52:46 -07007014static int nl80211_start_radar_detection(void *priv,
7015 struct hostapd_freq_params *freq)
Dmitry Shmidtea69e842013-05-13 14:52:28 -07007016{
7017 struct i802_bss *bss = priv;
7018 struct wpa_driver_nl80211_data *drv = bss->drv;
7019 struct nl_msg *msg;
7020 int ret;
7021
Dmitry Shmidt051af732013-10-22 13:52:46 -07007022 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)",
7023 freq->freq, freq->ht_enabled, freq->vht_enabled,
7024 freq->bandwidth, freq->center_freq1, freq->center_freq2);
7025
Dmitry Shmidtea69e842013-05-13 14:52:28 -07007026 if (!(drv->capa.flags & WPA_DRIVER_FLAGS_RADAR)) {
7027 wpa_printf(MSG_DEBUG, "nl80211: Driver does not support radar "
7028 "detection");
7029 return -1;
7030 }
7031
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08007032 if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_RADAR_DETECT)) ||
7033 nl80211_put_freq_params(msg, freq) < 0) {
7034 nlmsg_free(msg);
Dmitry Shmidtea69e842013-05-13 14:52:28 -07007035 return -1;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08007036 }
Dmitry Shmidtea69e842013-05-13 14:52:28 -07007037
7038 ret = send_and_recv_msgs(drv, msg, NULL, NULL);
7039 if (ret == 0)
7040 return 0;
7041 wpa_printf(MSG_DEBUG, "nl80211: Failed to start radar detection: "
7042 "%d (%s)", ret, strerror(-ret));
Dmitry Shmidtea69e842013-05-13 14:52:28 -07007043 return -1;
7044}
7045
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08007046#ifdef CONFIG_TDLS
7047
7048static int nl80211_send_tdls_mgmt(void *priv, const u8 *dst, u8 action_code,
7049 u8 dialog_token, u16 status_code,
Dmitry Shmidt9ead16e2014-10-07 13:15:23 -07007050 u32 peer_capab, int initiator, const u8 *buf,
7051 size_t len)
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08007052{
7053 struct i802_bss *bss = priv;
7054 struct wpa_driver_nl80211_data *drv = bss->drv;
7055 struct nl_msg *msg;
7056
7057 if (!(drv->capa.flags & WPA_DRIVER_FLAGS_TDLS_SUPPORT))
7058 return -EOPNOTSUPP;
7059
7060 if (!dst)
7061 return -EINVAL;
7062
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08007063 if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_TDLS_MGMT)) ||
7064 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, dst) ||
7065 nla_put_u8(msg, NL80211_ATTR_TDLS_ACTION, action_code) ||
7066 nla_put_u8(msg, NL80211_ATTR_TDLS_DIALOG_TOKEN, dialog_token) ||
7067 nla_put_u16(msg, NL80211_ATTR_STATUS_CODE, status_code))
7068 goto fail;
Dmitry Shmidtdf5a7e42014-04-02 12:59:59 -07007069 if (peer_capab) {
7070 /*
7071 * The internal enum tdls_peer_capability definition is
7072 * currently identical with the nl80211 enum
7073 * nl80211_tdls_peer_capability, so no conversion is needed
7074 * here.
7075 */
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08007076 if (nla_put_u32(msg, NL80211_ATTR_TDLS_PEER_CAPABILITY,
7077 peer_capab))
7078 goto fail;
Dmitry Shmidtdf5a7e42014-04-02 12:59:59 -07007079 }
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08007080 if ((initiator &&
7081 nla_put_flag(msg, NL80211_ATTR_TDLS_INITIATOR)) ||
7082 nla_put(msg, NL80211_ATTR_IE, len, buf))
7083 goto fail;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08007084
7085 return send_and_recv_msgs(drv, msg, NULL, NULL);
7086
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08007087fail:
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08007088 nlmsg_free(msg);
7089 return -ENOBUFS;
7090}
7091
7092
7093static int nl80211_tdls_oper(void *priv, enum tdls_oper oper, const u8 *peer)
7094{
7095 struct i802_bss *bss = priv;
7096 struct wpa_driver_nl80211_data *drv = bss->drv;
7097 struct nl_msg *msg;
7098 enum nl80211_tdls_operation nl80211_oper;
7099
7100 if (!(drv->capa.flags & WPA_DRIVER_FLAGS_TDLS_SUPPORT))
7101 return -EOPNOTSUPP;
7102
7103 switch (oper) {
7104 case TDLS_DISCOVERY_REQ:
7105 nl80211_oper = NL80211_TDLS_DISCOVERY_REQ;
7106 break;
7107 case TDLS_SETUP:
7108 nl80211_oper = NL80211_TDLS_SETUP;
7109 break;
7110 case TDLS_TEARDOWN:
7111 nl80211_oper = NL80211_TDLS_TEARDOWN;
7112 break;
7113 case TDLS_ENABLE_LINK:
7114 nl80211_oper = NL80211_TDLS_ENABLE_LINK;
7115 break;
7116 case TDLS_DISABLE_LINK:
7117 nl80211_oper = NL80211_TDLS_DISABLE_LINK;
7118 break;
7119 case TDLS_ENABLE:
7120 return 0;
7121 case TDLS_DISABLE:
7122 return 0;
7123 default:
7124 return -EINVAL;
7125 }
7126
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08007127 if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_TDLS_OPER)) ||
7128 nla_put_u8(msg, NL80211_ATTR_TDLS_OPERATION, nl80211_oper) ||
7129 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer)) {
7130 nlmsg_free(msg);
7131 return -ENOBUFS;
7132 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08007133
7134 return send_and_recv_msgs(drv, msg, NULL, NULL);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08007135}
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08007136
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08007137
7138static int
7139nl80211_tdls_enable_channel_switch(void *priv, const u8 *addr, u8 oper_class,
7140 const struct hostapd_freq_params *params)
7141{
7142 struct i802_bss *bss = priv;
7143 struct wpa_driver_nl80211_data *drv = bss->drv;
7144 struct nl_msg *msg;
7145 int ret = -ENOBUFS;
7146
7147 if (!(drv->capa.flags & WPA_DRIVER_FLAGS_TDLS_SUPPORT) ||
7148 !(drv->capa.flags & WPA_DRIVER_FLAGS_TDLS_CHANNEL_SWITCH))
7149 return -EOPNOTSUPP;
7150
7151 wpa_printf(MSG_DEBUG, "nl80211: Enable TDLS channel switch " MACSTR
7152 " oper_class=%u freq=%u",
7153 MAC2STR(addr), oper_class, params->freq);
7154 msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_TDLS_CHANNEL_SWITCH);
7155 if (!msg ||
7156 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) ||
7157 nla_put_u8(msg, NL80211_ATTR_OPER_CLASS, oper_class) ||
7158 (ret = nl80211_put_freq_params(msg, params))) {
7159 nlmsg_free(msg);
7160 wpa_printf(MSG_DEBUG, "nl80211: Could not build TDLS chan switch");
7161 return ret;
7162 }
7163
7164 return send_and_recv_msgs(drv, msg, NULL, NULL);
7165}
7166
7167
7168static int
7169nl80211_tdls_disable_channel_switch(void *priv, const u8 *addr)
7170{
7171 struct i802_bss *bss = priv;
7172 struct wpa_driver_nl80211_data *drv = bss->drv;
7173 struct nl_msg *msg;
7174
7175 if (!(drv->capa.flags & WPA_DRIVER_FLAGS_TDLS_SUPPORT) ||
7176 !(drv->capa.flags & WPA_DRIVER_FLAGS_TDLS_CHANNEL_SWITCH))
7177 return -EOPNOTSUPP;
7178
7179 wpa_printf(MSG_DEBUG, "nl80211: Disable TDLS channel switch " MACSTR,
7180 MAC2STR(addr));
7181 msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_TDLS_CANCEL_CHANNEL_SWITCH);
7182 if (!msg ||
7183 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) {
7184 nlmsg_free(msg);
7185 wpa_printf(MSG_DEBUG,
7186 "nl80211: Could not build TDLS cancel chan switch");
7187 return -ENOBUFS;
7188 }
7189
7190 return send_and_recv_msgs(drv, msg, NULL, NULL);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08007191}
7192
7193#endif /* CONFIG TDLS */
7194
7195
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08007196static int driver_nl80211_set_key(const char *ifname, void *priv,
7197 enum wpa_alg alg, const u8 *addr,
7198 int key_idx, int set_tx,
7199 const u8 *seq, size_t seq_len,
7200 const u8 *key, size_t key_len)
7201{
7202 struct i802_bss *bss = priv;
7203 return wpa_driver_nl80211_set_key(ifname, bss, alg, addr, key_idx,
7204 set_tx, seq, seq_len, key, key_len);
7205}
7206
7207
7208static int driver_nl80211_scan2(void *priv,
7209 struct wpa_driver_scan_params *params)
7210{
7211 struct i802_bss *bss = priv;
7212 return wpa_driver_nl80211_scan(bss, params);
7213}
7214
7215
7216static int driver_nl80211_deauthenticate(void *priv, const u8 *addr,
7217 int reason_code)
7218{
7219 struct i802_bss *bss = priv;
7220 return wpa_driver_nl80211_deauthenticate(bss, addr, reason_code);
7221}
7222
7223
7224static int driver_nl80211_authenticate(void *priv,
7225 struct wpa_driver_auth_params *params)
7226{
7227 struct i802_bss *bss = priv;
7228 return wpa_driver_nl80211_authenticate(bss, params);
7229}
7230
7231
7232static void driver_nl80211_deinit(void *priv)
7233{
7234 struct i802_bss *bss = priv;
7235 wpa_driver_nl80211_deinit(bss);
7236}
7237
7238
7239static int driver_nl80211_if_remove(void *priv, enum wpa_driver_if_type type,
7240 const char *ifname)
7241{
7242 struct i802_bss *bss = priv;
7243 return wpa_driver_nl80211_if_remove(bss, type, ifname);
7244}
7245
7246
7247static int driver_nl80211_send_mlme(void *priv, const u8 *data,
7248 size_t data_len, int noack)
7249{
7250 struct i802_bss *bss = priv;
7251 return wpa_driver_nl80211_send_mlme(bss, data, data_len, noack,
7252 0, 0, 0, 0);
7253}
7254
7255
7256static int driver_nl80211_sta_remove(void *priv, const u8 *addr)
7257{
7258 struct i802_bss *bss = priv;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08007259 return wpa_driver_nl80211_sta_remove(bss, addr, -1, 0);
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08007260}
7261
7262
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08007263static int driver_nl80211_set_sta_vlan(void *priv, const u8 *addr,
7264 const char *ifname, int vlan_id)
7265{
7266 struct i802_bss *bss = priv;
7267 return i802_set_sta_vlan(bss, addr, ifname, vlan_id);
7268}
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08007269
7270
7271static int driver_nl80211_read_sta_data(void *priv,
7272 struct hostap_sta_driver_data *data,
7273 const u8 *addr)
7274{
7275 struct i802_bss *bss = priv;
7276 return i802_read_sta_data(bss, data, addr);
7277}
7278
7279
7280static int driver_nl80211_send_action(void *priv, unsigned int freq,
7281 unsigned int wait_time,
7282 const u8 *dst, const u8 *src,
7283 const u8 *bssid,
7284 const u8 *data, size_t data_len,
7285 int no_cck)
7286{
7287 struct i802_bss *bss = priv;
7288 return wpa_driver_nl80211_send_action(bss, freq, wait_time, dst, src,
7289 bssid, data, data_len, no_cck);
7290}
7291
7292
7293static int driver_nl80211_probe_req_report(void *priv, int report)
7294{
7295 struct i802_bss *bss = priv;
7296 return wpa_driver_nl80211_probe_req_report(bss, report);
7297}
7298
7299
Dmitry Shmidt700a1372013-03-15 14:14:44 -07007300static int wpa_driver_nl80211_update_ft_ies(void *priv, const u8 *md,
7301 const u8 *ies, size_t ies_len)
7302{
7303 int ret;
7304 struct nl_msg *msg;
7305 struct i802_bss *bss = priv;
7306 struct wpa_driver_nl80211_data *drv = bss->drv;
7307 u16 mdid = WPA_GET_LE16(md);
7308
Dmitry Shmidt700a1372013-03-15 14:14:44 -07007309 wpa_printf(MSG_DEBUG, "nl80211: Updating FT IEs");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08007310 if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_UPDATE_FT_IES)) ||
7311 nla_put(msg, NL80211_ATTR_IE, ies_len, ies) ||
7312 nla_put_u16(msg, NL80211_ATTR_MDID, mdid)) {
7313 nlmsg_free(msg);
7314 return -ENOBUFS;
7315 }
Dmitry Shmidt700a1372013-03-15 14:14:44 -07007316
7317 ret = send_and_recv_msgs(drv, msg, NULL, NULL);
7318 if (ret) {
7319 wpa_printf(MSG_DEBUG, "nl80211: update_ft_ies failed "
7320 "err=%d (%s)", ret, strerror(-ret));
7321 }
7322
7323 return ret;
Dmitry Shmidt700a1372013-03-15 14:14:44 -07007324}
7325
7326
Dmitry Shmidt34af3062013-07-11 10:46:32 -07007327const u8 * wpa_driver_nl80211_get_macaddr(void *priv)
7328{
7329 struct i802_bss *bss = priv;
7330 struct wpa_driver_nl80211_data *drv = bss->drv;
7331
7332 if (drv->nlmode != NL80211_IFTYPE_P2P_DEVICE)
7333 return NULL;
7334
7335 return bss->addr;
7336}
7337
7338
Dmitry Shmidt56052862013-10-04 10:23:25 -07007339static const char * scan_state_str(enum scan_states scan_state)
7340{
7341 switch (scan_state) {
7342 case NO_SCAN:
7343 return "NO_SCAN";
7344 case SCAN_REQUESTED:
7345 return "SCAN_REQUESTED";
7346 case SCAN_STARTED:
7347 return "SCAN_STARTED";
7348 case SCAN_COMPLETED:
7349 return "SCAN_COMPLETED";
7350 case SCAN_ABORTED:
7351 return "SCAN_ABORTED";
7352 case SCHED_SCAN_STARTED:
7353 return "SCHED_SCAN_STARTED";
7354 case SCHED_SCAN_STOPPED:
7355 return "SCHED_SCAN_STOPPED";
7356 case SCHED_SCAN_RESULTS:
7357 return "SCHED_SCAN_RESULTS";
7358 }
7359
7360 return "??";
7361}
7362
7363
7364static int wpa_driver_nl80211_status(void *priv, char *buf, size_t buflen)
7365{
7366 struct i802_bss *bss = priv;
7367 struct wpa_driver_nl80211_data *drv = bss->drv;
7368 int res;
7369 char *pos, *end;
7370
7371 pos = buf;
7372 end = buf + buflen;
7373
7374 res = os_snprintf(pos, end - pos,
7375 "ifindex=%d\n"
7376 "ifname=%s\n"
7377 "brname=%s\n"
7378 "addr=" MACSTR "\n"
7379 "freq=%d\n"
7380 "%s%s%s%s%s",
7381 bss->ifindex,
7382 bss->ifname,
7383 bss->brname,
7384 MAC2STR(bss->addr),
7385 bss->freq,
7386 bss->beacon_set ? "beacon_set=1\n" : "",
7387 bss->added_if_into_bridge ?
7388 "added_if_into_bridge=1\n" : "",
7389 bss->added_bridge ? "added_bridge=1\n" : "",
7390 bss->in_deinit ? "in_deinit=1\n" : "",
7391 bss->if_dynamic ? "if_dynamic=1\n" : "");
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08007392 if (os_snprintf_error(end - pos, res))
Dmitry Shmidt56052862013-10-04 10:23:25 -07007393 return pos - buf;
7394 pos += res;
7395
7396 if (bss->wdev_id_set) {
7397 res = os_snprintf(pos, end - pos, "wdev_id=%llu\n",
7398 (unsigned long long) bss->wdev_id);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08007399 if (os_snprintf_error(end - pos, res))
Dmitry Shmidt56052862013-10-04 10:23:25 -07007400 return pos - buf;
7401 pos += res;
7402 }
7403
7404 res = os_snprintf(pos, end - pos,
7405 "phyname=%s\n"
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07007406 "perm_addr=" MACSTR "\n"
Dmitry Shmidt56052862013-10-04 10:23:25 -07007407 "drv_ifindex=%d\n"
7408 "operstate=%d\n"
7409 "scan_state=%s\n"
7410 "auth_bssid=" MACSTR "\n"
7411 "auth_attempt_bssid=" MACSTR "\n"
7412 "bssid=" MACSTR "\n"
7413 "prev_bssid=" MACSTR "\n"
7414 "associated=%d\n"
7415 "assoc_freq=%u\n"
7416 "monitor_sock=%d\n"
7417 "monitor_ifidx=%d\n"
7418 "monitor_refcount=%d\n"
7419 "last_mgmt_freq=%u\n"
7420 "eapol_tx_sock=%d\n"
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08007421 "%s%s%s%s%s%s%s%s%s%s%s%s%s",
Dmitry Shmidt56052862013-10-04 10:23:25 -07007422 drv->phyname,
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07007423 MAC2STR(drv->perm_addr),
Dmitry Shmidt56052862013-10-04 10:23:25 -07007424 drv->ifindex,
7425 drv->operstate,
7426 scan_state_str(drv->scan_state),
7427 MAC2STR(drv->auth_bssid),
7428 MAC2STR(drv->auth_attempt_bssid),
7429 MAC2STR(drv->bssid),
7430 MAC2STR(drv->prev_bssid),
7431 drv->associated,
7432 drv->assoc_freq,
7433 drv->monitor_sock,
7434 drv->monitor_ifidx,
7435 drv->monitor_refcount,
7436 drv->last_mgmt_freq,
7437 drv->eapol_tx_sock,
7438 drv->ignore_if_down_event ?
7439 "ignore_if_down_event=1\n" : "",
7440 drv->scan_complete_events ?
7441 "scan_complete_events=1\n" : "",
7442 drv->disabled_11b_rates ?
7443 "disabled_11b_rates=1\n" : "",
7444 drv->pending_remain_on_chan ?
7445 "pending_remain_on_chan=1\n" : "",
7446 drv->in_interface_list ? "in_interface_list=1\n" : "",
7447 drv->device_ap_sme ? "device_ap_sme=1\n" : "",
7448 drv->poll_command_supported ?
7449 "poll_command_supported=1\n" : "",
7450 drv->data_tx_status ? "data_tx_status=1\n" : "",
7451 drv->scan_for_auth ? "scan_for_auth=1\n" : "",
7452 drv->retry_auth ? "retry_auth=1\n" : "",
7453 drv->use_monitor ? "use_monitor=1\n" : "",
7454 drv->ignore_next_local_disconnect ?
7455 "ignore_next_local_disconnect=1\n" : "",
Dmitry Shmidt7dba0e52014-04-14 10:49:15 -07007456 drv->ignore_next_local_deauth ?
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08007457 "ignore_next_local_deauth=1\n" : "");
7458 if (os_snprintf_error(end - pos, res))
Dmitry Shmidt56052862013-10-04 10:23:25 -07007459 return pos - buf;
7460 pos += res;
7461
7462 if (drv->has_capability) {
7463 res = os_snprintf(pos, end - pos,
7464 "capa.key_mgmt=0x%x\n"
7465 "capa.enc=0x%x\n"
7466 "capa.auth=0x%x\n"
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08007467 "capa.flags=0x%llx\n"
7468 "capa.rrm_flags=0x%x\n"
Dmitry Shmidt56052862013-10-04 10:23:25 -07007469 "capa.max_scan_ssids=%d\n"
7470 "capa.max_sched_scan_ssids=%d\n"
7471 "capa.sched_scan_supported=%d\n"
7472 "capa.max_match_sets=%d\n"
7473 "capa.max_remain_on_chan=%u\n"
7474 "capa.max_stations=%u\n"
7475 "capa.probe_resp_offloads=0x%x\n"
7476 "capa.max_acl_mac_addrs=%u\n"
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08007477 "capa.num_multichan_concurrent=%u\n"
7478 "capa.mac_addr_rand_sched_scan_supported=%d\n"
7479 "capa.mac_addr_rand_scan_supported=%d\n",
Dmitry Shmidt56052862013-10-04 10:23:25 -07007480 drv->capa.key_mgmt,
7481 drv->capa.enc,
7482 drv->capa.auth,
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08007483 (unsigned long long) drv->capa.flags,
7484 drv->capa.rrm_flags,
Dmitry Shmidt56052862013-10-04 10:23:25 -07007485 drv->capa.max_scan_ssids,
7486 drv->capa.max_sched_scan_ssids,
7487 drv->capa.sched_scan_supported,
7488 drv->capa.max_match_sets,
7489 drv->capa.max_remain_on_chan,
7490 drv->capa.max_stations,
7491 drv->capa.probe_resp_offloads,
7492 drv->capa.max_acl_mac_addrs,
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08007493 drv->capa.num_multichan_concurrent,
7494 drv->capa.mac_addr_rand_sched_scan_supported,
7495 drv->capa.mac_addr_rand_scan_supported);
7496 if (os_snprintf_error(end - pos, res))
Dmitry Shmidt56052862013-10-04 10:23:25 -07007497 return pos - buf;
7498 pos += res;
7499 }
7500
7501 return pos - buf;
7502}
7503
7504
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08007505static int set_beacon_data(struct nl_msg *msg, struct beacon_data *settings)
7506{
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08007507 if ((settings->head &&
7508 nla_put(msg, NL80211_ATTR_BEACON_HEAD,
7509 settings->head_len, settings->head)) ||
7510 (settings->tail &&
7511 nla_put(msg, NL80211_ATTR_BEACON_TAIL,
7512 settings->tail_len, settings->tail)) ||
7513 (settings->beacon_ies &&
7514 nla_put(msg, NL80211_ATTR_IE,
7515 settings->beacon_ies_len, settings->beacon_ies)) ||
7516 (settings->proberesp_ies &&
7517 nla_put(msg, NL80211_ATTR_IE_PROBE_RESP,
7518 settings->proberesp_ies_len, settings->proberesp_ies)) ||
7519 (settings->assocresp_ies &&
7520 nla_put(msg, NL80211_ATTR_IE_ASSOC_RESP,
7521 settings->assocresp_ies_len, settings->assocresp_ies)) ||
7522 (settings->probe_resp &&
7523 nla_put(msg, NL80211_ATTR_PROBE_RESP,
7524 settings->probe_resp_len, settings->probe_resp)))
7525 return -ENOBUFS;
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08007526
7527 return 0;
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08007528}
7529
7530
7531static int nl80211_switch_channel(void *priv, struct csa_settings *settings)
7532{
7533 struct nl_msg *msg;
7534 struct i802_bss *bss = priv;
7535 struct wpa_driver_nl80211_data *drv = bss->drv;
7536 struct nlattr *beacon_csa;
7537 int ret = -ENOBUFS;
7538
Dmitry Shmidt04f534e2013-12-09 15:50:16 -08007539 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 -08007540 settings->cs_count, settings->block_tx,
Dmitry Shmidt04f534e2013-12-09 15:50:16 -08007541 settings->freq_params.freq, settings->freq_params.bandwidth,
7542 settings->freq_params.center_freq1,
7543 settings->freq_params.center_freq2);
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08007544
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08007545 if (!(drv->capa.flags & WPA_DRIVER_FLAGS_AP_CSA)) {
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08007546 wpa_printf(MSG_DEBUG, "nl80211: Driver does not support channel switch command");
7547 return -EOPNOTSUPP;
7548 }
7549
7550 if ((drv->nlmode != NL80211_IFTYPE_AP) &&
7551 (drv->nlmode != NL80211_IFTYPE_P2P_GO))
7552 return -EOPNOTSUPP;
7553
7554 /* check settings validity */
7555 if (!settings->beacon_csa.tail ||
7556 ((settings->beacon_csa.tail_len <=
7557 settings->counter_offset_beacon) ||
7558 (settings->beacon_csa.tail[settings->counter_offset_beacon] !=
7559 settings->cs_count)))
7560 return -EINVAL;
7561
7562 if (settings->beacon_csa.probe_resp &&
7563 ((settings->beacon_csa.probe_resp_len <=
7564 settings->counter_offset_presp) ||
7565 (settings->beacon_csa.probe_resp[settings->counter_offset_presp] !=
7566 settings->cs_count)))
7567 return -EINVAL;
7568
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08007569 if (!(msg = nl80211_bss_msg(bss, 0, NL80211_CMD_CHANNEL_SWITCH)) ||
7570 nla_put_u32(msg, NL80211_ATTR_CH_SWITCH_COUNT,
7571 settings->cs_count) ||
7572 (ret = nl80211_put_freq_params(msg, &settings->freq_params)) ||
7573 (settings->block_tx &&
7574 nla_put_flag(msg, NL80211_ATTR_CH_SWITCH_BLOCK_TX)))
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08007575 goto error;
7576
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08007577 /* beacon_after params */
7578 ret = set_beacon_data(msg, &settings->beacon_after);
7579 if (ret)
7580 goto error;
7581
7582 /* beacon_csa params */
7583 beacon_csa = nla_nest_start(msg, NL80211_ATTR_CSA_IES);
7584 if (!beacon_csa)
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08007585 goto fail;
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08007586
7587 ret = set_beacon_data(msg, &settings->beacon_csa);
7588 if (ret)
7589 goto error;
7590
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08007591 if (nla_put_u16(msg, NL80211_ATTR_CSA_C_OFF_BEACON,
7592 settings->counter_offset_beacon) ||
7593 (settings->beacon_csa.probe_resp &&
7594 nla_put_u16(msg, NL80211_ATTR_CSA_C_OFF_PRESP,
7595 settings->counter_offset_presp)))
7596 goto fail;
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08007597
7598 nla_nest_end(msg, beacon_csa);
7599 ret = send_and_recv_msgs(drv, msg, NULL, NULL);
7600 if (ret) {
7601 wpa_printf(MSG_DEBUG, "nl80211: switch_channel failed err=%d (%s)",
7602 ret, strerror(-ret));
7603 }
7604 return ret;
7605
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08007606fail:
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08007607 ret = -ENOBUFS;
7608error:
7609 nlmsg_free(msg);
7610 wpa_printf(MSG_DEBUG, "nl80211: Could not build channel switch request");
7611 return ret;
7612}
7613
7614
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08007615static int nl80211_add_ts(void *priv, u8 tsid, const u8 *addr,
7616 u8 user_priority, u16 admitted_time)
7617{
7618 struct i802_bss *bss = priv;
7619 struct wpa_driver_nl80211_data *drv = bss->drv;
7620 struct nl_msg *msg;
7621 int ret;
7622
7623 wpa_printf(MSG_DEBUG,
7624 "nl80211: add_ts request: tsid=%u admitted_time=%u up=%d",
7625 tsid, admitted_time, user_priority);
7626
7627 if (!is_sta_interface(drv->nlmode))
7628 return -ENOTSUP;
7629
7630 msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_ADD_TX_TS);
7631 if (!msg ||
7632 nla_put_u8(msg, NL80211_ATTR_TSID, tsid) ||
7633 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) ||
7634 nla_put_u8(msg, NL80211_ATTR_USER_PRIO, user_priority) ||
7635 nla_put_u16(msg, NL80211_ATTR_ADMITTED_TIME, admitted_time)) {
7636 nlmsg_free(msg);
7637 return -ENOBUFS;
7638 }
7639
7640 ret = send_and_recv_msgs(drv, msg, NULL, NULL);
7641 if (ret)
7642 wpa_printf(MSG_DEBUG, "nl80211: add_ts failed err=%d (%s)",
7643 ret, strerror(-ret));
7644 return ret;
7645}
7646
7647
7648static int nl80211_del_ts(void *priv, u8 tsid, const u8 *addr)
7649{
7650 struct i802_bss *bss = priv;
7651 struct wpa_driver_nl80211_data *drv = bss->drv;
7652 struct nl_msg *msg;
7653 int ret;
7654
7655 wpa_printf(MSG_DEBUG, "nl80211: del_ts request: tsid=%u", tsid);
7656
7657 if (!is_sta_interface(drv->nlmode))
7658 return -ENOTSUP;
7659
7660 if (!(msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_DEL_TX_TS)) ||
7661 nla_put_u8(msg, NL80211_ATTR_TSID, tsid) ||
7662 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) {
7663 nlmsg_free(msg);
7664 return -ENOBUFS;
7665 }
7666
7667 ret = send_and_recv_msgs(drv, msg, NULL, NULL);
7668 if (ret)
7669 wpa_printf(MSG_DEBUG, "nl80211: del_ts failed err=%d (%s)",
7670 ret, strerror(-ret));
7671 return ret;
7672}
7673
7674
Dmitry Shmidta38abf92014-03-06 13:38:44 -08007675#ifdef CONFIG_TESTING_OPTIONS
7676static int cmd_reply_handler(struct nl_msg *msg, void *arg)
7677{
7678 struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg));
7679 struct wpabuf *buf = arg;
7680
7681 if (!buf)
7682 return NL_SKIP;
7683
7684 if ((size_t) genlmsg_attrlen(gnlh, 0) > wpabuf_tailroom(buf)) {
7685 wpa_printf(MSG_INFO, "nl80211: insufficient buffer space for reply");
7686 return NL_SKIP;
7687 }
7688
7689 wpabuf_put_data(buf, genlmsg_attrdata(gnlh, 0),
7690 genlmsg_attrlen(gnlh, 0));
7691
7692 return NL_SKIP;
7693}
7694#endif /* CONFIG_TESTING_OPTIONS */
7695
7696
7697static int vendor_reply_handler(struct nl_msg *msg, void *arg)
7698{
7699 struct nlattr *tb[NL80211_ATTR_MAX + 1];
7700 struct nlattr *nl_vendor_reply, *nl;
7701 struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg));
7702 struct wpabuf *buf = arg;
7703 int rem;
7704
7705 if (!buf)
7706 return NL_SKIP;
7707
7708 nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0),
7709 genlmsg_attrlen(gnlh, 0), NULL);
7710 nl_vendor_reply = tb[NL80211_ATTR_VENDOR_DATA];
7711
7712 if (!nl_vendor_reply)
7713 return NL_SKIP;
7714
7715 if ((size_t) nla_len(nl_vendor_reply) > wpabuf_tailroom(buf)) {
7716 wpa_printf(MSG_INFO, "nl80211: Vendor command: insufficient buffer space for reply");
7717 return NL_SKIP;
7718 }
7719
7720 nla_for_each_nested(nl, nl_vendor_reply, rem) {
7721 wpabuf_put_data(buf, nla_data(nl), nla_len(nl));
7722 }
7723
7724 return NL_SKIP;
7725}
7726
7727
7728static int nl80211_vendor_cmd(void *priv, unsigned int vendor_id,
7729 unsigned int subcmd, const u8 *data,
7730 size_t data_len, struct wpabuf *buf)
7731{
7732 struct i802_bss *bss = priv;
7733 struct wpa_driver_nl80211_data *drv = bss->drv;
7734 struct nl_msg *msg;
7735 int ret;
7736
Dmitry Shmidta38abf92014-03-06 13:38:44 -08007737#ifdef CONFIG_TESTING_OPTIONS
7738 if (vendor_id == 0xffffffff) {
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08007739 msg = nlmsg_alloc();
7740 if (!msg)
7741 return -ENOMEM;
7742
Dmitry Shmidta38abf92014-03-06 13:38:44 -08007743 nl80211_cmd(drv, msg, 0, subcmd);
7744 if (nlmsg_append(msg, (void *) data, data_len, NLMSG_ALIGNTO) <
7745 0)
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08007746 goto fail;
Dmitry Shmidta38abf92014-03-06 13:38:44 -08007747 ret = send_and_recv_msgs(drv, msg, cmd_reply_handler, buf);
7748 if (ret)
7749 wpa_printf(MSG_DEBUG, "nl80211: command failed err=%d",
7750 ret);
7751 return ret;
7752 }
7753#endif /* CONFIG_TESTING_OPTIONS */
7754
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08007755 if (!(msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_VENDOR)) ||
7756 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, vendor_id) ||
7757 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD, subcmd) ||
7758 (data &&
7759 nla_put(msg, NL80211_ATTR_VENDOR_DATA, data_len, data)))
7760 goto fail;
Dmitry Shmidta38abf92014-03-06 13:38:44 -08007761
7762 ret = send_and_recv_msgs(drv, msg, vendor_reply_handler, buf);
7763 if (ret)
7764 wpa_printf(MSG_DEBUG, "nl80211: vendor command failed err=%d",
7765 ret);
7766 return ret;
7767
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08007768fail:
Dmitry Shmidta38abf92014-03-06 13:38:44 -08007769 nlmsg_free(msg);
7770 return -ENOBUFS;
7771}
7772
7773
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08007774static int nl80211_set_qos_map(void *priv, const u8 *qos_map_set,
7775 u8 qos_map_set_len)
7776{
7777 struct i802_bss *bss = priv;
7778 struct wpa_driver_nl80211_data *drv = bss->drv;
7779 struct nl_msg *msg;
7780 int ret;
7781
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08007782 wpa_hexdump(MSG_DEBUG, "nl80211: Setting QoS Map",
7783 qos_map_set, qos_map_set_len);
7784
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08007785 if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_SET_QOS_MAP)) ||
7786 nla_put(msg, NL80211_ATTR_QOS_MAP, qos_map_set_len, qos_map_set)) {
7787 nlmsg_free(msg);
7788 return -ENOBUFS;
7789 }
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08007790
7791 ret = send_and_recv_msgs(drv, msg, NULL, NULL);
7792 if (ret)
7793 wpa_printf(MSG_DEBUG, "nl80211: Setting QoS Map failed");
7794
7795 return ret;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08007796}
7797
7798
Dmitry Shmidtb58836e2014-04-29 14:35:56 -07007799static int nl80211_set_wowlan(void *priv,
7800 const struct wowlan_triggers *triggers)
7801{
7802 struct i802_bss *bss = priv;
7803 struct wpa_driver_nl80211_data *drv = bss->drv;
7804 struct nl_msg *msg;
7805 struct nlattr *wowlan_triggers;
7806 int ret;
7807
Dmitry Shmidtb58836e2014-04-29 14:35:56 -07007808 wpa_printf(MSG_DEBUG, "nl80211: Setting wowlan");
7809
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08007810 if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_SET_WOWLAN)) ||
7811 !(wowlan_triggers = nla_nest_start(msg,
7812 NL80211_ATTR_WOWLAN_TRIGGERS)) ||
7813 (triggers->any &&
7814 nla_put_flag(msg, NL80211_WOWLAN_TRIG_ANY)) ||
7815 (triggers->disconnect &&
7816 nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) ||
7817 (triggers->magic_pkt &&
7818 nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) ||
7819 (triggers->gtk_rekey_failure &&
7820 nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) ||
7821 (triggers->eap_identity_req &&
7822 nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) ||
7823 (triggers->four_way_handshake &&
7824 nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) ||
7825 (triggers->rfkill_release &&
7826 nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE))) {
7827 nlmsg_free(msg);
7828 return -ENOBUFS;
7829 }
Dmitry Shmidtb58836e2014-04-29 14:35:56 -07007830
7831 nla_nest_end(msg, wowlan_triggers);
7832
7833 ret = send_and_recv_msgs(drv, msg, NULL, NULL);
7834 if (ret)
7835 wpa_printf(MSG_DEBUG, "nl80211: Setting wowlan failed");
7836
7837 return ret;
Dmitry Shmidtb58836e2014-04-29 14:35:56 -07007838}
7839
7840
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07007841static int nl80211_roaming(void *priv, int allowed, const u8 *bssid)
7842{
7843 struct i802_bss *bss = priv;
7844 struct wpa_driver_nl80211_data *drv = bss->drv;
7845 struct nl_msg *msg;
7846 struct nlattr *params;
7847
7848 wpa_printf(MSG_DEBUG, "nl80211: Roaming policy: allowed=%d", allowed);
7849
7850 if (!drv->roaming_vendor_cmd_avail) {
7851 wpa_printf(MSG_DEBUG,
7852 "nl80211: Ignore roaming policy change since driver does not provide command for setting it");
7853 return -1;
7854 }
7855
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08007856 if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_VENDOR)) ||
7857 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
7858 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
7859 QCA_NL80211_VENDOR_SUBCMD_ROAMING) ||
7860 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
7861 nla_put_u32(msg, QCA_WLAN_VENDOR_ATTR_ROAMING_POLICY,
7862 allowed ? QCA_ROAMING_ALLOWED_WITHIN_ESS :
7863 QCA_ROAMING_NOT_ALLOWED) ||
7864 (bssid &&
7865 nla_put(msg, QCA_WLAN_VENDOR_ATTR_MAC_ADDR, ETH_ALEN, bssid))) {
7866 nlmsg_free(msg);
7867 return -1;
7868 }
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07007869 nla_nest_end(msg, params);
7870
7871 return send_and_recv_msgs(drv, msg, NULL, NULL);
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07007872}
7873
7874
7875static int nl80211_set_mac_addr(void *priv, const u8 *addr)
7876{
7877 struct i802_bss *bss = priv;
7878 struct wpa_driver_nl80211_data *drv = bss->drv;
7879 int new_addr = addr != NULL;
7880
7881 if (!addr)
7882 addr = drv->perm_addr;
7883
7884 if (linux_set_iface_flags(drv->global->ioctl_sock, bss->ifname, 0) < 0)
7885 return -1;
7886
7887 if (linux_set_ifhwaddr(drv->global->ioctl_sock, bss->ifname, addr) < 0)
7888 {
7889 wpa_printf(MSG_DEBUG,
7890 "nl80211: failed to set_mac_addr for %s to " MACSTR,
7891 bss->ifname, MAC2STR(addr));
7892 if (linux_set_iface_flags(drv->global->ioctl_sock, bss->ifname,
7893 1) < 0) {
7894 wpa_printf(MSG_DEBUG,
7895 "nl80211: Could not restore interface UP after failed set_mac_addr");
7896 }
7897 return -1;
7898 }
7899
7900 wpa_printf(MSG_DEBUG, "nl80211: set_mac_addr for %s to " MACSTR,
7901 bss->ifname, MAC2STR(addr));
7902 drv->addr_changed = new_addr;
7903 os_memcpy(bss->addr, addr, ETH_ALEN);
7904
7905 if (linux_set_iface_flags(drv->global->ioctl_sock, bss->ifname, 1) < 0)
7906 {
7907 wpa_printf(MSG_DEBUG,
7908 "nl80211: Could not restore interface UP after set_mac_addr");
7909 }
7910
7911 return 0;
7912}
7913
7914
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08007915#ifdef CONFIG_MESH
7916
7917static int wpa_driver_nl80211_init_mesh(void *priv)
7918{
7919 if (wpa_driver_nl80211_set_mode(priv, NL80211_IFTYPE_MESH_POINT)) {
7920 wpa_printf(MSG_INFO,
7921 "nl80211: Failed to set interface into mesh mode");
7922 return -1;
7923 }
7924 return 0;
7925}
7926
7927
Dmitry Shmidtff787d52015-01-12 13:01:47 -08007928static int nl80211_put_mesh_id(struct nl_msg *msg, const u8 *mesh_id,
7929 size_t mesh_id_len)
7930{
7931 if (mesh_id) {
7932 wpa_hexdump_ascii(MSG_DEBUG, " * Mesh ID (SSID)",
7933 mesh_id, mesh_id_len);
7934 return nla_put(msg, NL80211_ATTR_MESH_ID, mesh_id_len, mesh_id);
7935 }
7936
7937 return 0;
7938}
7939
7940
Dmitry Shmidt7f656022015-02-25 14:36:37 -08007941static int nl80211_join_mesh(struct i802_bss *bss,
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08007942 struct wpa_driver_mesh_join_params *params)
7943{
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08007944 struct wpa_driver_nl80211_data *drv = bss->drv;
7945 struct nl_msg *msg;
7946 struct nlattr *container;
Dmitry Shmidt2f74e362015-01-21 13:19:05 -08007947 int ret = -1;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08007948
7949 wpa_printf(MSG_DEBUG, "nl80211: mesh join (ifindex=%d)", drv->ifindex);
7950 msg = nl80211_drv_msg(drv, 0, NL80211_CMD_JOIN_MESH);
Dmitry Shmidtff787d52015-01-12 13:01:47 -08007951 if (!msg ||
7952 nl80211_put_freq_params(msg, &params->freq) ||
7953 nl80211_put_basic_rates(msg, params->basic_rates) ||
7954 nl80211_put_mesh_id(msg, params->meshid, params->meshid_len) ||
7955 nl80211_put_beacon_int(msg, params->beacon_int))
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08007956 goto fail;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08007957
7958 wpa_printf(MSG_DEBUG, " * flags=%08X", params->flags);
7959
7960 container = nla_nest_start(msg, NL80211_ATTR_MESH_SETUP);
7961 if (!container)
7962 goto fail;
7963
7964 if (params->ies) {
7965 wpa_hexdump(MSG_DEBUG, " * IEs", params->ies, params->ie_len);
7966 if (nla_put(msg, NL80211_MESH_SETUP_IE, params->ie_len,
7967 params->ies))
7968 goto fail;
7969 }
7970 /* WPA_DRIVER_MESH_FLAG_OPEN_AUTH is treated as default by nl80211 */
7971 if (params->flags & WPA_DRIVER_MESH_FLAG_SAE_AUTH) {
7972 if (nla_put_u8(msg, NL80211_MESH_SETUP_AUTH_PROTOCOL, 0x1) ||
7973 nla_put_flag(msg, NL80211_MESH_SETUP_USERSPACE_AUTH))
7974 goto fail;
7975 }
7976 if ((params->flags & WPA_DRIVER_MESH_FLAG_AMPE) &&
7977 nla_put_flag(msg, NL80211_MESH_SETUP_USERSPACE_AMPE))
7978 goto fail;
7979 if ((params->flags & WPA_DRIVER_MESH_FLAG_USER_MPM) &&
7980 nla_put_flag(msg, NL80211_MESH_SETUP_USERSPACE_MPM))
7981 goto fail;
7982 nla_nest_end(msg, container);
7983
7984 container = nla_nest_start(msg, NL80211_ATTR_MESH_CONFIG);
7985 if (!container)
7986 goto fail;
7987
7988 if (!(params->conf.flags & WPA_DRIVER_MESH_CONF_FLAG_AUTO_PLINKS) &&
7989 nla_put_u32(msg, NL80211_MESHCONF_AUTO_OPEN_PLINKS, 0))
7990 goto fail;
7991 if ((params->conf.flags & WPA_DRIVER_MESH_FLAG_DRIVER_MPM) &&
7992 nla_put_u16(msg, NL80211_MESHCONF_MAX_PEER_LINKS,
7993 params->max_peer_links))
7994 goto fail;
Dmitry Shmidt2f74e362015-01-21 13:19:05 -08007995
7996 /*
7997 * Set NL80211_MESHCONF_PLINK_TIMEOUT even if user mpm is used because
7998 * the timer could disconnect stations even in that case.
Dmitry Shmidt2f74e362015-01-21 13:19:05 -08007999 */
Dmitry Shmidt7f656022015-02-25 14:36:37 -08008000 if (nla_put_u32(msg, NL80211_MESHCONF_PLINK_TIMEOUT,
8001 params->conf.peer_link_timeout)) {
Dmitry Shmidt2f74e362015-01-21 13:19:05 -08008002 wpa_printf(MSG_ERROR, "nl80211: Failed to set PLINK_TIMEOUT");
8003 goto fail;
8004 }
8005
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08008006 nla_nest_end(msg, container);
8007
8008 ret = send_and_recv_msgs(drv, msg, NULL, NULL);
8009 msg = NULL;
8010 if (ret) {
8011 wpa_printf(MSG_DEBUG, "nl80211: mesh join failed: ret=%d (%s)",
8012 ret, strerror(-ret));
8013 goto fail;
8014 }
8015 ret = 0;
Dmitry Shmidtff787d52015-01-12 13:01:47 -08008016 bss->freq = params->freq.freq;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08008017 wpa_printf(MSG_DEBUG, "nl80211: mesh join request send successfully");
8018
8019fail:
8020 nlmsg_free(msg);
8021 return ret;
8022}
8023
8024
Dmitry Shmidt7f656022015-02-25 14:36:37 -08008025static int
8026wpa_driver_nl80211_join_mesh(void *priv,
8027 struct wpa_driver_mesh_join_params *params)
8028{
8029 struct i802_bss *bss = priv;
8030 int ret, timeout;
8031
8032 timeout = params->conf.peer_link_timeout;
8033
8034 /* Disable kernel inactivity timer */
8035 if (params->flags & WPA_DRIVER_MESH_FLAG_USER_MPM)
8036 params->conf.peer_link_timeout = 0;
8037
8038 ret = nl80211_join_mesh(bss, params);
8039 if (ret == -EINVAL && params->conf.peer_link_timeout == 0) {
8040 wpa_printf(MSG_DEBUG,
8041 "nl80211: Mesh join retry for peer_link_timeout");
8042 /*
8043 * Old kernel does not support setting
8044 * NL80211_MESHCONF_PLINK_TIMEOUT to zero, so set 60 seconds
8045 * into future from peer_link_timeout.
8046 */
8047 params->conf.peer_link_timeout = timeout + 60;
8048 ret = nl80211_join_mesh(priv, params);
8049 }
8050
8051 params->conf.peer_link_timeout = timeout;
8052 return ret;
8053}
8054
8055
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08008056static int wpa_driver_nl80211_leave_mesh(void *priv)
8057{
8058 struct i802_bss *bss = priv;
8059 struct wpa_driver_nl80211_data *drv = bss->drv;
8060 struct nl_msg *msg;
8061 int ret;
8062
8063 wpa_printf(MSG_DEBUG, "nl80211: mesh leave (ifindex=%d)", drv->ifindex);
8064 msg = nl80211_drv_msg(drv, 0, NL80211_CMD_LEAVE_MESH);
8065 ret = send_and_recv_msgs(drv, msg, NULL, NULL);
8066 if (ret) {
8067 wpa_printf(MSG_DEBUG, "nl80211: mesh leave failed: ret=%d (%s)",
8068 ret, strerror(-ret));
8069 } else {
8070 wpa_printf(MSG_DEBUG,
8071 "nl80211: mesh leave request send successfully");
8072 }
8073
8074 if (wpa_driver_nl80211_set_mode(drv->first_bss,
8075 NL80211_IFTYPE_STATION)) {
8076 wpa_printf(MSG_INFO,
8077 "nl80211: Failed to set interface into station mode");
8078 }
8079 return ret;
8080}
8081
8082#endif /* CONFIG_MESH */
8083
8084
8085static int wpa_driver_br_add_ip_neigh(void *priv, u8 version,
8086 const u8 *ipaddr, int prefixlen,
8087 const u8 *addr)
8088{
8089#ifdef CONFIG_LIBNL3_ROUTE
8090 struct i802_bss *bss = priv;
8091 struct wpa_driver_nl80211_data *drv = bss->drv;
8092 struct rtnl_neigh *rn;
8093 struct nl_addr *nl_ipaddr = NULL;
8094 struct nl_addr *nl_lladdr = NULL;
8095 int family, addrsize;
8096 int res;
8097
8098 if (!ipaddr || prefixlen == 0 || !addr)
8099 return -EINVAL;
8100
8101 if (bss->br_ifindex == 0) {
8102 wpa_printf(MSG_DEBUG,
8103 "nl80211: bridge must be set before adding an ip neigh to it");
8104 return -1;
8105 }
8106
8107 if (!drv->rtnl_sk) {
8108 wpa_printf(MSG_DEBUG,
8109 "nl80211: nl_sock for NETLINK_ROUTE is not initialized");
8110 return -1;
8111 }
8112
8113 if (version == 4) {
8114 family = AF_INET;
8115 addrsize = 4;
8116 } else if (version == 6) {
8117 family = AF_INET6;
8118 addrsize = 16;
8119 } else {
8120 return -EINVAL;
8121 }
8122
8123 rn = rtnl_neigh_alloc();
8124 if (rn == NULL)
8125 return -ENOMEM;
8126
8127 /* set the destination ip address for neigh */
8128 nl_ipaddr = nl_addr_build(family, (void *) ipaddr, addrsize);
8129 if (nl_ipaddr == NULL) {
8130 wpa_printf(MSG_DEBUG, "nl80211: nl_ipaddr build failed");
8131 res = -ENOMEM;
8132 goto errout;
8133 }
8134 nl_addr_set_prefixlen(nl_ipaddr, prefixlen);
8135 res = rtnl_neigh_set_dst(rn, nl_ipaddr);
8136 if (res) {
8137 wpa_printf(MSG_DEBUG,
8138 "nl80211: neigh set destination addr failed");
8139 goto errout;
8140 }
8141
8142 /* set the corresponding lladdr for neigh */
8143 nl_lladdr = nl_addr_build(AF_BRIDGE, (u8 *) addr, ETH_ALEN);
8144 if (nl_lladdr == NULL) {
8145 wpa_printf(MSG_DEBUG, "nl80211: neigh set lladdr failed");
8146 res = -ENOMEM;
8147 goto errout;
8148 }
8149 rtnl_neigh_set_lladdr(rn, nl_lladdr);
8150
8151 rtnl_neigh_set_ifindex(rn, bss->br_ifindex);
8152 rtnl_neigh_set_state(rn, NUD_PERMANENT);
8153
8154 res = rtnl_neigh_add(drv->rtnl_sk, rn, NLM_F_CREATE);
8155 if (res) {
8156 wpa_printf(MSG_DEBUG,
8157 "nl80211: Adding bridge ip neigh failed: %s",
8158 strerror(errno));
8159 }
8160errout:
8161 if (nl_lladdr)
8162 nl_addr_put(nl_lladdr);
8163 if (nl_ipaddr)
8164 nl_addr_put(nl_ipaddr);
8165 if (rn)
8166 rtnl_neigh_put(rn);
8167 return res;
8168#else /* CONFIG_LIBNL3_ROUTE */
8169 return -1;
8170#endif /* CONFIG_LIBNL3_ROUTE */
8171}
8172
8173
8174static int wpa_driver_br_delete_ip_neigh(void *priv, u8 version,
8175 const u8 *ipaddr)
8176{
8177#ifdef CONFIG_LIBNL3_ROUTE
8178 struct i802_bss *bss = priv;
8179 struct wpa_driver_nl80211_data *drv = bss->drv;
8180 struct rtnl_neigh *rn;
8181 struct nl_addr *nl_ipaddr;
8182 int family, addrsize;
8183 int res;
8184
8185 if (!ipaddr)
8186 return -EINVAL;
8187
8188 if (version == 4) {
8189 family = AF_INET;
8190 addrsize = 4;
8191 } else if (version == 6) {
8192 family = AF_INET6;
8193 addrsize = 16;
8194 } else {
8195 return -EINVAL;
8196 }
8197
8198 if (bss->br_ifindex == 0) {
8199 wpa_printf(MSG_DEBUG,
8200 "nl80211: bridge must be set to delete an ip neigh");
8201 return -1;
8202 }
8203
8204 if (!drv->rtnl_sk) {
8205 wpa_printf(MSG_DEBUG,
8206 "nl80211: nl_sock for NETLINK_ROUTE is not initialized");
8207 return -1;
8208 }
8209
8210 rn = rtnl_neigh_alloc();
8211 if (rn == NULL)
8212 return -ENOMEM;
8213
8214 /* set the destination ip address for neigh */
8215 nl_ipaddr = nl_addr_build(family, (void *) ipaddr, addrsize);
8216 if (nl_ipaddr == NULL) {
8217 wpa_printf(MSG_DEBUG, "nl80211: nl_ipaddr build failed");
8218 res = -ENOMEM;
8219 goto errout;
8220 }
8221 res = rtnl_neigh_set_dst(rn, nl_ipaddr);
8222 if (res) {
8223 wpa_printf(MSG_DEBUG,
8224 "nl80211: neigh set destination addr failed");
8225 goto errout;
8226 }
8227
8228 rtnl_neigh_set_ifindex(rn, bss->br_ifindex);
8229
8230 res = rtnl_neigh_delete(drv->rtnl_sk, rn, 0);
8231 if (res) {
8232 wpa_printf(MSG_DEBUG,
8233 "nl80211: Deleting bridge ip neigh failed: %s",
8234 strerror(errno));
8235 }
8236errout:
8237 if (nl_ipaddr)
8238 nl_addr_put(nl_ipaddr);
8239 if (rn)
8240 rtnl_neigh_put(rn);
8241 return res;
8242#else /* CONFIG_LIBNL3_ROUTE */
8243 return -1;
8244#endif /* CONFIG_LIBNL3_ROUTE */
8245}
8246
8247
8248static int linux_write_system_file(const char *path, unsigned int val)
8249{
8250 char buf[50];
8251 int fd, len;
8252
8253 len = os_snprintf(buf, sizeof(buf), "%u\n", val);
8254 if (os_snprintf_error(sizeof(buf), len))
8255 return -1;
8256
8257 fd = open(path, O_WRONLY);
8258 if (fd < 0)
8259 return -1;
8260
8261 if (write(fd, buf, len) < 0) {
8262 wpa_printf(MSG_DEBUG,
8263 "nl80211: Failed to write Linux system file: %s with the value of %d",
8264 path, val);
8265 close(fd);
8266 return -1;
8267 }
8268 close(fd);
8269
8270 return 0;
8271}
8272
8273
8274static const char * drv_br_port_attr_str(enum drv_br_port_attr attr)
8275{
8276 switch (attr) {
8277 case DRV_BR_PORT_ATTR_PROXYARP:
Dmitry Shmidt4dd28dc2015-03-10 11:21:43 -07008278 return "proxyarp_wifi";
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08008279 case DRV_BR_PORT_ATTR_HAIRPIN_MODE:
8280 return "hairpin_mode";
8281 }
8282
8283 return NULL;
8284}
8285
8286
8287static int wpa_driver_br_port_set_attr(void *priv, enum drv_br_port_attr attr,
8288 unsigned int val)
8289{
8290 struct i802_bss *bss = priv;
8291 char path[128];
8292 const char *attr_txt;
8293
8294 attr_txt = drv_br_port_attr_str(attr);
8295 if (attr_txt == NULL)
8296 return -EINVAL;
8297
8298 os_snprintf(path, sizeof(path), "/sys/class/net/%s/brport/%s",
8299 bss->ifname, attr_txt);
8300
8301 if (linux_write_system_file(path, val))
8302 return -1;
8303
8304 return 0;
8305}
8306
8307
8308static const char * drv_br_net_param_str(enum drv_br_net_param param)
8309{
8310 switch (param) {
8311 case DRV_BR_NET_PARAM_GARP_ACCEPT:
8312 return "arp_accept";
Dmitry Shmidt83474442015-04-15 13:47:09 -07008313 default:
8314 return NULL;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08008315 }
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08008316}
8317
8318
8319static int wpa_driver_br_set_net_param(void *priv, enum drv_br_net_param param,
8320 unsigned int val)
8321{
8322 struct i802_bss *bss = priv;
8323 char path[128];
8324 const char *param_txt;
8325 int ip_version = 4;
8326
Dmitry Shmidt83474442015-04-15 13:47:09 -07008327 if (param == DRV_BR_MULTICAST_SNOOPING) {
8328 os_snprintf(path, sizeof(path),
8329 "/sys/devices/virtual/net/%s/bridge/multicast_snooping",
8330 bss->brname);
8331 goto set_val;
8332 }
8333
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08008334 param_txt = drv_br_net_param_str(param);
8335 if (param_txt == NULL)
8336 return -EINVAL;
8337
8338 switch (param) {
8339 case DRV_BR_NET_PARAM_GARP_ACCEPT:
8340 ip_version = 4;
8341 break;
8342 default:
8343 return -EINVAL;
8344 }
8345
8346 os_snprintf(path, sizeof(path), "/proc/sys/net/ipv%d/conf/%s/%s",
8347 ip_version, bss->brname, param_txt);
8348
Dmitry Shmidt83474442015-04-15 13:47:09 -07008349set_val:
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08008350 if (linux_write_system_file(path, val))
8351 return -1;
8352
8353 return 0;
8354}
8355
8356
8357static int hw_mode_to_qca_acs(enum hostapd_hw_mode hw_mode)
8358{
8359 switch (hw_mode) {
8360 case HOSTAPD_MODE_IEEE80211B:
8361 return QCA_ACS_MODE_IEEE80211B;
8362 case HOSTAPD_MODE_IEEE80211G:
8363 return QCA_ACS_MODE_IEEE80211G;
8364 case HOSTAPD_MODE_IEEE80211A:
8365 return QCA_ACS_MODE_IEEE80211A;
8366 case HOSTAPD_MODE_IEEE80211AD:
8367 return QCA_ACS_MODE_IEEE80211AD;
8368 default:
8369 return -1;
8370 }
8371}
8372
8373
8374static int wpa_driver_do_acs(void *priv, struct drv_acs_params *params)
8375{
8376 struct i802_bss *bss = priv;
8377 struct wpa_driver_nl80211_data *drv = bss->drv;
8378 struct nl_msg *msg;
8379 struct nlattr *data;
8380 int ret;
8381 int mode;
8382
8383 mode = hw_mode_to_qca_acs(params->hw_mode);
8384 if (mode < 0)
8385 return -1;
8386
8387 if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_VENDOR)) ||
8388 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
8389 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
8390 QCA_NL80211_VENDOR_SUBCMD_DO_ACS) ||
8391 !(data = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
8392 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_ACS_HW_MODE, mode) ||
8393 (params->ht_enabled &&
8394 nla_put_flag(msg, QCA_WLAN_VENDOR_ATTR_ACS_HT_ENABLED)) ||
8395 (params->ht40_enabled &&
Dmitry Shmidtdda10c22015-03-24 16:05:01 -07008396 nla_put_flag(msg, QCA_WLAN_VENDOR_ATTR_ACS_HT40_ENABLED)) ||
8397 (params->vht_enabled &&
8398 nla_put_flag(msg, QCA_WLAN_VENDOR_ATTR_ACS_VHT_ENABLED)) ||
8399 nla_put_u16(msg, QCA_WLAN_VENDOR_ATTR_ACS_CHWIDTH,
8400 params->ch_width) ||
8401 (params->ch_list_len &&
8402 nla_put(msg, QCA_WLAN_VENDOR_ATTR_ACS_CH_LIST, params->ch_list_len,
8403 params->ch_list))) {
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08008404 nlmsg_free(msg);
8405 return -ENOBUFS;
8406 }
8407 nla_nest_end(msg, data);
8408
Dmitry Shmidtdda10c22015-03-24 16:05:01 -07008409 wpa_printf(MSG_DEBUG,
8410 "nl80211: ACS Params: HW_MODE: %d HT: %d HT40: %d VHT: %d BW: %d CH_LIST_LEN: %u",
8411 params->hw_mode, params->ht_enabled, params->ht40_enabled,
8412 params->vht_enabled, params->ch_width, params->ch_list_len);
8413
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08008414 ret = send_and_recv_msgs(drv, msg, NULL, NULL);
8415 if (ret) {
8416 wpa_printf(MSG_DEBUG,
8417 "nl80211: Failed to invoke driver ACS function: %s",
8418 strerror(errno));
8419 }
8420 return ret;
8421}
8422
8423
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07008424const struct wpa_driver_ops wpa_driver_nl80211_ops = {
8425 .name = "nl80211",
8426 .desc = "Linux nl80211/cfg80211",
8427 .get_bssid = wpa_driver_nl80211_get_bssid,
8428 .get_ssid = wpa_driver_nl80211_get_ssid,
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08008429 .set_key = driver_nl80211_set_key,
8430 .scan2 = driver_nl80211_scan2,
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08008431 .sched_scan = wpa_driver_nl80211_sched_scan,
8432 .stop_sched_scan = wpa_driver_nl80211_stop_sched_scan,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07008433 .get_scan_results2 = wpa_driver_nl80211_get_scan_results,
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08008434 .deauthenticate = driver_nl80211_deauthenticate,
8435 .authenticate = driver_nl80211_authenticate,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07008436 .associate = wpa_driver_nl80211_associate,
8437 .global_init = nl80211_global_init,
8438 .global_deinit = nl80211_global_deinit,
8439 .init2 = wpa_driver_nl80211_init,
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08008440 .deinit = driver_nl80211_deinit,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07008441 .get_capa = wpa_driver_nl80211_get_capa,
8442 .set_operstate = wpa_driver_nl80211_set_operstate,
8443 .set_supp_port = wpa_driver_nl80211_set_supp_port,
8444 .set_country = wpa_driver_nl80211_set_country,
Dmitry Shmidtcce06662013-11-04 18:44:24 -08008445 .get_country = wpa_driver_nl80211_get_country,
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08008446 .set_ap = wpa_driver_nl80211_set_ap,
Dmitry Shmidt8bae4132013-06-06 11:25:10 -07008447 .set_acl = wpa_driver_nl80211_set_acl,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07008448 .if_add = wpa_driver_nl80211_if_add,
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08008449 .if_remove = driver_nl80211_if_remove,
8450 .send_mlme = driver_nl80211_send_mlme,
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08008451 .get_hw_feature_data = nl80211_get_hw_feature_data,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07008452 .sta_add = wpa_driver_nl80211_sta_add,
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08008453 .sta_remove = driver_nl80211_sta_remove,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07008454 .hapd_send_eapol = wpa_driver_nl80211_hapd_send_eapol,
8455 .sta_set_flags = wpa_driver_nl80211_sta_set_flags,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07008456 .hapd_init = i802_init,
8457 .hapd_deinit = i802_deinit,
Jouni Malinen75ecf522011-06-27 15:19:46 -07008458 .set_wds_sta = i802_set_wds_sta,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07008459 .get_seqnum = i802_get_seqnum,
8460 .flush = i802_flush,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07008461 .get_inact_sec = i802_get_inact_sec,
8462 .sta_clear_stats = i802_sta_clear_stats,
8463 .set_rts = i802_set_rts,
8464 .set_frag = i802_set_frag,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07008465 .set_tx_queue_params = i802_set_tx_queue_params,
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08008466 .set_sta_vlan = driver_nl80211_set_sta_vlan,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07008467 .sta_deauth = i802_sta_deauth,
8468 .sta_disassoc = i802_sta_disassoc,
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08008469 .read_sta_data = driver_nl80211_read_sta_data,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07008470 .set_freq = i802_set_freq,
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08008471 .send_action = driver_nl80211_send_action,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07008472 .send_action_cancel_wait = wpa_driver_nl80211_send_action_cancel_wait,
8473 .remain_on_channel = wpa_driver_nl80211_remain_on_channel,
8474 .cancel_remain_on_channel =
8475 wpa_driver_nl80211_cancel_remain_on_channel,
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08008476 .probe_req_report = driver_nl80211_probe_req_report,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07008477 .deinit_ap = wpa_driver_nl80211_deinit_ap,
Dmitry Shmidt04949592012-07-19 12:16:46 -07008478 .deinit_p2p_cli = wpa_driver_nl80211_deinit_p2p_cli,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07008479 .resume = wpa_driver_nl80211_resume,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07008480 .signal_monitor = nl80211_signal_monitor,
8481 .signal_poll = nl80211_signal_poll,
8482 .send_frame = nl80211_send_frame,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07008483 .set_param = nl80211_set_param,
8484 .get_radio_name = nl80211_get_radio_name,
Jouni Malinen75ecf522011-06-27 15:19:46 -07008485 .add_pmkid = nl80211_add_pmkid,
8486 .remove_pmkid = nl80211_remove_pmkid,
8487 .flush_pmkid = nl80211_flush_pmkid,
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08008488 .set_rekey_info = nl80211_set_rekey_info,
8489 .poll_client = nl80211_poll_client,
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08008490 .set_p2p_powersave = nl80211_set_p2p_powersave,
Dmitry Shmidtea69e842013-05-13 14:52:28 -07008491 .start_dfs_cac = nl80211_start_radar_detection,
8492 .stop_ap = wpa_driver_nl80211_stop_ap,
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08008493#ifdef CONFIG_TDLS
8494 .send_tdls_mgmt = nl80211_send_tdls_mgmt,
8495 .tdls_oper = nl80211_tdls_oper,
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08008496 .tdls_enable_channel_switch = nl80211_tdls_enable_channel_switch,
8497 .tdls_disable_channel_switch = nl80211_tdls_disable_channel_switch,
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08008498#endif /* CONFIG_TDLS */
Dmitry Shmidt700a1372013-03-15 14:14:44 -07008499 .update_ft_ies = wpa_driver_nl80211_update_ft_ies,
Dmitry Shmidt34af3062013-07-11 10:46:32 -07008500 .get_mac_addr = wpa_driver_nl80211_get_macaddr,
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -07008501 .get_survey = wpa_driver_nl80211_get_survey,
Dmitry Shmidt56052862013-10-04 10:23:25 -07008502 .status = wpa_driver_nl80211_status,
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08008503 .switch_channel = nl80211_switch_channel,
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08008504#ifdef ANDROID_P2P
Dmitry Shmidt6e933c12011-09-27 12:29:26 -07008505 .set_noa = wpa_driver_set_p2p_noa,
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08008506 .get_noa = wpa_driver_get_p2p_noa,
Dmitry Shmidt6e933c12011-09-27 12:29:26 -07008507 .set_ap_wps_ie = wpa_driver_set_ap_wps_p2p_ie,
Dmitry Shmidt292b0c32013-11-22 12:54:42 -08008508#endif /* ANDROID_P2P */
Dmitry Shmidt738a26e2011-07-07 14:22:14 -07008509#ifdef ANDROID
8510 .driver_cmd = wpa_driver_nl80211_driver_cmd,
Dmitry Shmidt292b0c32013-11-22 12:54:42 -08008511#endif /* ANDROID */
Dmitry Shmidta38abf92014-03-06 13:38:44 -08008512 .vendor_cmd = nl80211_vendor_cmd,
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08008513 .set_qos_map = nl80211_set_qos_map,
Dmitry Shmidtb58836e2014-04-29 14:35:56 -07008514 .set_wowlan = nl80211_set_wowlan,
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07008515 .roaming = nl80211_roaming,
8516 .set_mac_addr = nl80211_set_mac_addr,
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08008517#ifdef CONFIG_MESH
8518 .init_mesh = wpa_driver_nl80211_init_mesh,
8519 .join_mesh = wpa_driver_nl80211_join_mesh,
8520 .leave_mesh = wpa_driver_nl80211_leave_mesh,
8521#endif /* CONFIG_MESH */
8522 .br_add_ip_neigh = wpa_driver_br_add_ip_neigh,
8523 .br_delete_ip_neigh = wpa_driver_br_delete_ip_neigh,
8524 .br_port_set_attr = wpa_driver_br_port_set_attr,
8525 .br_set_net_param = wpa_driver_br_set_net_param,
8526 .add_tx_ts = nl80211_add_ts,
8527 .del_tx_ts = nl80211_del_ts,
8528 .do_acs = wpa_driver_do_acs,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07008529};