]>
Commit | Line | Data |
---|---|---|
3f5285e8 | 1 | /* |
c5121837 | 2 | * Driver interaction with Linux nl80211/cfg80211 |
90a545cc | 3 | * Copyright (c) 2002-2014, Jouni Malinen <j@w1.fi> |
072ad14c JM |
4 | * Copyright (c) 2003-2004, Instant802 Networks, Inc. |
5 | * Copyright (c) 2005-2006, Devicescape Software, Inc. | |
6 | * Copyright (c) 2007, Johannes Berg <johannes@sipsolutions.net> | |
58f6fbe0 | 7 | * Copyright (c) 2009-2010, Atheros Communications |
3f5285e8 | 8 | * |
0f3d578e JM |
9 | * This software may be distributed under the terms of the BSD license. |
10 | * See README for more details. | |
3f5285e8 JM |
11 | */ |
12 | ||
13 | #include "includes.h" | |
6859f1cb | 14 | #include <sys/types.h> |
73d2294f | 15 | #include <fcntl.h> |
37b7d082 | 16 | #include <net/if.h> |
3f5285e8 | 17 | #include <netlink/genl/genl.h> |
3f5285e8 | 18 | #include <netlink/genl/ctrl.h> |
97ed9a06 KP |
19 | #ifdef CONFIG_LIBNL3_ROUTE |
20 | #include <netlink/route/neighbour.h> | |
21 | #endif /* CONFIG_LIBNL3_ROUTE */ | |
8602b0f2 | 22 | #include <linux/rtnetlink.h> |
1b648c7e | 23 | #include <netpacket/packet.h> |
32ab4855 | 24 | #include <linux/errqueue.h> |
625f587b | 25 | |
3f5285e8 | 26 | #include "common.h" |
1b648c7e | 27 | #include "eloop.h" |
1682c623 | 28 | #include "common/qca-vendor.h" |
a26582cb | 29 | #include "common/qca-vendor-attr.h" |
1b648c7e | 30 | #include "common/ieee802_11_defs.h" |
9b90955e | 31 | #include "common/ieee802_11_common.h" |
f10bfc9a | 32 | #include "l2_packet/l2_packet.h" |
e2d02c29 | 33 | #include "netlink.h" |
1474e6e9 | 34 | #include "linux_defines.h" |
34f2f814 | 35 | #include "linux_ioctl.h" |
e2d02c29 JM |
36 | #include "radiotap.h" |
37 | #include "radiotap_iter.h" | |
8401a6b0 | 38 | #include "rfkill.h" |
1474e6e9 | 39 | #include "driver_nl80211.h" |
32ab4855 | 40 | |
1474e6e9 JM |
41 | |
42 | #ifndef CONFIG_LIBNL20 | |
a65a9aed JB |
43 | /* |
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 | */ | |
50 | static uint32_t port_bitmap[32] = { 0 }; | |
51 | ||
52 | static 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 | ||
73 | static 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 | } | |
c5121837 JM |
82 | #endif /* CONFIG_LIBNL20 */ |
83 | ||
c5121837 | 84 | |
1c6edec6 JM |
85 | #ifdef ANDROID |
86 | /* system/core/libnl_2 does not include nl_socket_set_nonblocking() */ | |
1c6edec6 JM |
87 | #undef nl_socket_set_nonblocking |
88 | #define nl_socket_set_nonblocking(h) android_nl_socket_set_nonblocking(h) | |
70a96c81 JM |
89 | |
90 | #define genl_ctrl_resolve android_genl_ctrl_resolve | |
1c6edec6 JM |
91 | #endif /* ANDROID */ |
92 | ||
93 | ||
481234cf | 94 | static struct nl_handle * nl_create_handle(struct nl_cb *cb, const char *dbg) |
a92dfde8 | 95 | { |
481234cf | 96 | struct nl_handle *handle; |
a92dfde8 | 97 | |
481234cf JM |
98 | handle = nl80211_handle_alloc(cb); |
99 | if (handle == NULL) { | |
a92dfde8 JB |
100 | wpa_printf(MSG_ERROR, "nl80211: Failed to allocate netlink " |
101 | "callbacks (%s)", dbg); | |
481234cf | 102 | return NULL; |
a92dfde8 JB |
103 | } |
104 | ||
481234cf | 105 | if (genl_connect(handle)) { |
a92dfde8 JB |
106 | wpa_printf(MSG_ERROR, "nl80211: Failed to connect to generic " |
107 | "netlink (%s)", dbg); | |
481234cf JM |
108 | nl80211_handle_destroy(handle); |
109 | return NULL; | |
a92dfde8 JB |
110 | } |
111 | ||
481234cf | 112 | return handle; |
a92dfde8 JB |
113 | } |
114 | ||
115 | ||
481234cf | 116 | static void nl_destroy_handles(struct nl_handle **handle) |
a92dfde8 | 117 | { |
481234cf | 118 | if (*handle == NULL) |
a92dfde8 | 119 | return; |
481234cf JM |
120 | nl80211_handle_destroy(*handle); |
121 | *handle = NULL; | |
a92dfde8 JB |
122 | } |
123 | ||
124 | ||
10b85921 JB |
125 | #if __WORDSIZE == 64 |
126 | #define ELOOP_SOCKET_INVALID (intptr_t) 0x8888888888888889ULL | |
127 | #else | |
128 | #define ELOOP_SOCKET_INVALID (intptr_t) 0x88888889ULL | |
129 | #endif | |
130 | ||
5f65e9f7 JB |
131 | static void nl80211_register_eloop_read(struct nl_handle **handle, |
132 | eloop_sock_handler handler, | |
133 | void *eloop_data) | |
134 | { | |
10b85921 | 135 | nl_socket_set_nonblocking(*handle); |
5f65e9f7 JB |
136 | eloop_register_read_sock(nl_socket_get_fd(*handle), handler, |
137 | eloop_data, *handle); | |
10b85921 | 138 | *handle = (void *) (((intptr_t) *handle) ^ ELOOP_SOCKET_INVALID); |
5f65e9f7 JB |
139 | } |
140 | ||
141 | ||
142 | static void nl80211_destroy_eloop_handle(struct nl_handle **handle) | |
143 | { | |
10b85921 | 144 | *handle = (void *) (((intptr_t) *handle) ^ ELOOP_SOCKET_INVALID); |
5f65e9f7 JB |
145 | eloop_unregister_read_sock(nl_socket_get_fd(*handle)); |
146 | nl_destroy_handles(handle); | |
147 | } | |
148 | ||
149 | ||
36d84860 BG |
150 | static void nl80211_global_deinit(void *priv); |
151 | ||
9ebce9c5 | 152 | static void wpa_driver_nl80211_deinit(struct i802_bss *bss); |
4ec68377 JD |
153 | static int wpa_driver_nl80211_set_mode_ibss(struct i802_bss *bss, |
154 | struct hostapd_freq_params *freq); | |
3c5d34e3 | 155 | |
362f781e | 156 | static int |
0d547d5f | 157 | wpa_driver_nl80211_finish_drv_init(struct wpa_driver_nl80211_data *drv, |
0ecff8d7 JM |
158 | const u8 *set_addr, int first, |
159 | const char *driver_params); | |
88df0ef7 | 160 | static int nl80211_send_frame_cmd(struct i802_bss *bss, |
5dfca53f | 161 | unsigned int freq, unsigned int wait, |
b106173a | 162 | const u8 *buf, size_t buf_len, u64 *cookie, |
88df0ef7 | 163 | int no_cck, int no_ack, int offchanok); |
9ebce9c5 JM |
164 | static int wpa_driver_nl80211_probe_req_report(struct i802_bss *bss, |
165 | int report); | |
0915d02c | 166 | |
2135f224 JM |
167 | static void add_ifidx(struct wpa_driver_nl80211_data *drv, int ifidx); |
168 | static void del_ifidx(struct wpa_driver_nl80211_data *drv, int ifidx); | |
97cfcf64 | 169 | static int have_ifidx(struct wpa_driver_nl80211_data *drv, int ifidx); |
072ad14c | 170 | |
e87ef751 PX |
171 | static int nl80211_set_channel(struct i802_bss *bss, |
172 | struct hostapd_freq_params *freq, int set_chan); | |
4e5cb1a3 JM |
173 | static int nl80211_disable_11b_rates(struct wpa_driver_nl80211_data *drv, |
174 | int ifindex, int disabled); | |
504e905c | 175 | |
666e508c JM |
176 | static int nl80211_leave_ibss(struct wpa_driver_nl80211_data *drv, |
177 | int reset_mode); | |
21bdbe38 | 178 | |
bf83eab5 | 179 | static int i802_set_iface_flags(struct i802_bss *bss, int up); |
0ecff8d7 | 180 | static int nl80211_set_param(void *priv, const char *param); |
bf83eab5 | 181 | |
3f5285e8 | 182 | |
8d1fdde7 | 183 | /* Converts nl80211_chan_width to a common format */ |
f3407c66 | 184 | enum chan_width convert2width(int width) |
8d1fdde7 JD |
185 | { |
186 | switch (width) { | |
187 | case NL80211_CHAN_WIDTH_20_NOHT: | |
188 | return CHAN_WIDTH_20_NOHT; | |
189 | case NL80211_CHAN_WIDTH_20: | |
190 | return CHAN_WIDTH_20; | |
191 | case NL80211_CHAN_WIDTH_40: | |
192 | return CHAN_WIDTH_40; | |
193 | case NL80211_CHAN_WIDTH_80: | |
194 | return CHAN_WIDTH_80; | |
195 | case NL80211_CHAN_WIDTH_80P80: | |
196 | return CHAN_WIDTH_80P80; | |
197 | case NL80211_CHAN_WIDTH_160: | |
198 | return CHAN_WIDTH_160; | |
199 | } | |
200 | return CHAN_WIDTH_UNKNOWN; | |
201 | } | |
202 | ||
203 | ||
f3407c66 | 204 | int is_ap_interface(enum nl80211_iftype nlmode) |
b1f625e0 | 205 | { |
0e80ea2c JM |
206 | return nlmode == NL80211_IFTYPE_AP || |
207 | nlmode == NL80211_IFTYPE_P2P_GO; | |
b1f625e0 EP |
208 | } |
209 | ||
210 | ||
477af8f8 | 211 | int is_sta_interface(enum nl80211_iftype nlmode) |
b1f625e0 | 212 | { |
0e80ea2c JM |
213 | return nlmode == NL80211_IFTYPE_STATION || |
214 | nlmode == NL80211_IFTYPE_P2P_CLIENT; | |
b1f625e0 EP |
215 | } |
216 | ||
217 | ||
6a71413e | 218 | static int is_p2p_net_interface(enum nl80211_iftype nlmode) |
b3af99d2 | 219 | { |
0e80ea2c JM |
220 | return nlmode == NL80211_IFTYPE_P2P_CLIENT || |
221 | nlmode == NL80211_IFTYPE_P2P_GO; | |
b3af99d2 JM |
222 | } |
223 | ||
224 | ||
f3407c66 JM |
225 | struct i802_bss * get_bss_ifindex(struct wpa_driver_nl80211_data *drv, |
226 | int ifindex) | |
5dfbd725 JM |
227 | { |
228 | struct i802_bss *bss; | |
229 | ||
230 | for (bss = drv->first_bss; bss; bss = bss->next) { | |
231 | if (bss->ifindex == ifindex) | |
232 | return bss; | |
233 | } | |
234 | ||
235 | return NULL; | |
236 | } | |
237 | ||
238 | ||
afb0550a BC |
239 | static int is_mesh_interface(enum nl80211_iftype nlmode) |
240 | { | |
241 | return nlmode == NL80211_IFTYPE_MESH_POINT; | |
242 | } | |
243 | ||
244 | ||
f3407c66 | 245 | void nl80211_mark_disconnected(struct wpa_driver_nl80211_data *drv) |
add9b7a4 JM |
246 | { |
247 | if (drv->associated) | |
248 | os_memcpy(drv->prev_bssid, drv->bssid, ETH_ALEN); | |
249 | drv->associated = 0; | |
250 | os_memset(drv->bssid, 0, ETH_ALEN); | |
251 | } | |
252 | ||
253 | ||
6241fcb1 JM |
254 | /* nl80211 code */ |
255 | static int ack_handler(struct nl_msg *msg, void *arg) | |
256 | { | |
257 | int *err = arg; | |
258 | *err = 0; | |
259 | return NL_STOP; | |
260 | } | |
261 | ||
262 | static int finish_handler(struct nl_msg *msg, void *arg) | |
263 | { | |
8e8df255 JM |
264 | int *ret = arg; |
265 | *ret = 0; | |
6241fcb1 JM |
266 | return NL_SKIP; |
267 | } | |
268 | ||
269 | static int error_handler(struct sockaddr_nl *nla, struct nlmsgerr *err, | |
270 | void *arg) | |
271 | { | |
272 | int *ret = arg; | |
273 | *ret = err->error; | |
274 | return NL_SKIP; | |
275 | } | |
276 | ||
5b7b85f6 JM |
277 | |
278 | static int no_seq_check(struct nl_msg *msg, void *arg) | |
279 | { | |
280 | return NL_OK; | |
281 | } | |
282 | ||
283 | ||
bbd89bfc JM |
284 | static void nl80211_nlmsg_clear(struct nl_msg *msg) |
285 | { | |
286 | /* | |
287 | * Clear nlmsg data, e.g., to make sure key material is not left in | |
288 | * heap memory for unnecessarily long time. | |
289 | */ | |
290 | if (msg) { | |
291 | struct nlmsghdr *hdr = nlmsg_hdr(msg); | |
292 | void *data = nlmsg_data(hdr); | |
d58ade21 JM |
293 | /* |
294 | * This would use nlmsg_datalen() or the older nlmsg_len() if | |
295 | * only libnl were to maintain a stable API.. Neither will work | |
296 | * with all released versions, so just calculate the length | |
297 | * here. | |
298 | */ | |
299 | int len = hdr->nlmsg_len - NLMSG_HDRLEN; | |
bbd89bfc JM |
300 | |
301 | os_memset(data, 0, len); | |
302 | } | |
303 | } | |
304 | ||
305 | ||
d6c9aab8 | 306 | static int send_and_recv(struct nl80211_global *global, |
58f6fbe0 JM |
307 | struct nl_handle *nl_handle, struct nl_msg *msg, |
308 | int (*valid_handler)(struct nl_msg *, void *), | |
309 | void *valid_data) | |
6241fcb1 JM |
310 | { |
311 | struct nl_cb *cb; | |
312 | int err = -ENOMEM; | |
313 | ||
9725b784 JM |
314 | if (!msg) |
315 | return -ENOMEM; | |
316 | ||
d6c9aab8 | 317 | cb = nl_cb_clone(global->nl_cb); |
6241fcb1 JM |
318 | if (!cb) |
319 | goto out; | |
320 | ||
58f6fbe0 | 321 | err = nl_send_auto_complete(nl_handle, msg); |
6241fcb1 JM |
322 | if (err < 0) |
323 | goto out; | |
324 | ||
325 | err = 1; | |
326 | ||
327 | nl_cb_err(cb, NL_CB_CUSTOM, error_handler, &err); | |
8e8df255 | 328 | nl_cb_set(cb, NL_CB_FINISH, NL_CB_CUSTOM, finish_handler, &err); |
6241fcb1 JM |
329 | nl_cb_set(cb, NL_CB_ACK, NL_CB_CUSTOM, ack_handler, &err); |
330 | ||
331 | if (valid_handler) | |
332 | nl_cb_set(cb, NL_CB_VALID, NL_CB_CUSTOM, | |
333 | valid_handler, valid_data); | |
334 | ||
34068ac3 JM |
335 | while (err > 0) { |
336 | int res = nl_recvmsgs(nl_handle, cb); | |
d3d04831 | 337 | if (res < 0) { |
34068ac3 JM |
338 | wpa_printf(MSG_INFO, |
339 | "nl80211: %s->nl_recvmsgs failed: %d", | |
340 | __func__, res); | |
341 | } | |
342 | } | |
6241fcb1 JM |
343 | out: |
344 | nl_cb_put(cb); | |
bbd89bfc JM |
345 | if (!valid_handler && valid_data == (void *) -1) |
346 | nl80211_nlmsg_clear(msg); | |
6241fcb1 JM |
347 | nlmsg_free(msg); |
348 | return err; | |
349 | } | |
350 | ||
351 | ||
f3407c66 JM |
352 | int send_and_recv_msgs(struct wpa_driver_nl80211_data *drv, |
353 | struct nl_msg *msg, | |
354 | int (*valid_handler)(struct nl_msg *, void *), | |
355 | void *valid_data) | |
58f6fbe0 | 356 | { |
481234cf | 357 | return send_and_recv(drv->global, drv->global->nl, msg, |
d6c9aab8 | 358 | valid_handler, valid_data); |
58f6fbe0 JM |
359 | } |
360 | ||
361 | ||
97865538 JM |
362 | struct family_data { |
363 | const char *group; | |
364 | int id; | |
365 | }; | |
366 | ||
367 | ||
368 | static int family_handler(struct nl_msg *msg, void *arg) | |
369 | { | |
370 | struct family_data *res = arg; | |
371 | struct nlattr *tb[CTRL_ATTR_MAX + 1]; | |
372 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); | |
373 | struct nlattr *mcgrp; | |
374 | int i; | |
375 | ||
376 | nla_parse(tb, CTRL_ATTR_MAX, genlmsg_attrdata(gnlh, 0), | |
377 | genlmsg_attrlen(gnlh, 0), NULL); | |
378 | if (!tb[CTRL_ATTR_MCAST_GROUPS]) | |
379 | return NL_SKIP; | |
380 | ||
381 | nla_for_each_nested(mcgrp, tb[CTRL_ATTR_MCAST_GROUPS], i) { | |
382 | struct nlattr *tb2[CTRL_ATTR_MCAST_GRP_MAX + 1]; | |
383 | nla_parse(tb2, CTRL_ATTR_MCAST_GRP_MAX, nla_data(mcgrp), | |
384 | nla_len(mcgrp), NULL); | |
385 | if (!tb2[CTRL_ATTR_MCAST_GRP_NAME] || | |
386 | !tb2[CTRL_ATTR_MCAST_GRP_ID] || | |
387 | os_strncmp(nla_data(tb2[CTRL_ATTR_MCAST_GRP_NAME]), | |
388 | res->group, | |
389 | nla_len(tb2[CTRL_ATTR_MCAST_GRP_NAME])) != 0) | |
390 | continue; | |
391 | res->id = nla_get_u32(tb2[CTRL_ATTR_MCAST_GRP_ID]); | |
392 | break; | |
393 | }; | |
394 | ||
395 | return NL_SKIP; | |
396 | } | |
397 | ||
398 | ||
d6c9aab8 | 399 | static int nl_get_multicast_id(struct nl80211_global *global, |
97865538 JM |
400 | const char *family, const char *group) |
401 | { | |
402 | struct nl_msg *msg; | |
a862e4a3 | 403 | int ret; |
97865538 JM |
404 | struct family_data res = { group, -ENOENT }; |
405 | ||
406 | msg = nlmsg_alloc(); | |
407 | if (!msg) | |
408 | return -ENOMEM; | |
a862e4a3 JM |
409 | if (!genlmsg_put(msg, 0, 0, genl_ctrl_resolve(global->nl, "nlctrl"), |
410 | 0, 0, CTRL_CMD_GETFAMILY, 0) || | |
411 | nla_put_string(msg, CTRL_ATTR_FAMILY_NAME, family)) { | |
412 | nlmsg_free(msg); | |
413 | return -1; | |
414 | } | |
97865538 | 415 | |
1033315f | 416 | ret = send_and_recv(global, global->nl, msg, family_handler, &res); |
97865538 JM |
417 | if (ret == 0) |
418 | ret = res.id; | |
97865538 JM |
419 | return ret; |
420 | } | |
421 | ||
422 | ||
f3407c66 JM |
423 | void * nl80211_cmd(struct wpa_driver_nl80211_data *drv, |
424 | struct nl_msg *msg, int flags, uint8_t cmd) | |
9fb04070 | 425 | { |
335d42b1 | 426 | return genlmsg_put(msg, 0, 0, drv->global->nl80211_id, |
276e2d67 | 427 | 0, flags, cmd, 0); |
9fb04070 JM |
428 | } |
429 | ||
430 | ||
350acc35 JM |
431 | static int nl80211_set_iface_id(struct nl_msg *msg, struct i802_bss *bss) |
432 | { | |
433 | if (bss->wdev_id_set) | |
434 | return nla_put_u64(msg, NL80211_ATTR_WDEV, bss->wdev_id); | |
435 | return nla_put_u32(msg, NL80211_ATTR_IFINDEX, bss->ifindex); | |
436 | } | |
437 | ||
438 | ||
07c7757c JM |
439 | struct nl_msg * nl80211_cmd_msg(struct i802_bss *bss, int flags, uint8_t cmd) |
440 | { | |
441 | struct nl_msg *msg; | |
442 | ||
443 | msg = nlmsg_alloc(); | |
444 | if (!msg) | |
445 | return NULL; | |
446 | ||
447 | if (!nl80211_cmd(bss->drv, msg, flags, cmd) || | |
448 | nl80211_set_iface_id(msg, bss) < 0) { | |
449 | nlmsg_free(msg); | |
450 | return NULL; | |
451 | } | |
452 | ||
453 | return msg; | |
454 | } | |
455 | ||
456 | ||
457 | static struct nl_msg * | |
458 | nl80211_ifindex_msg(struct wpa_driver_nl80211_data *drv, int ifindex, | |
459 | int flags, uint8_t cmd) | |
460 | { | |
461 | struct nl_msg *msg; | |
462 | ||
463 | msg = nlmsg_alloc(); | |
464 | if (!msg) | |
465 | return NULL; | |
466 | ||
467 | if (!nl80211_cmd(drv, msg, flags, cmd) || | |
468 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex)) { | |
469 | nlmsg_free(msg); | |
470 | return NULL; | |
471 | } | |
472 | ||
473 | return msg; | |
474 | } | |
475 | ||
476 | ||
477 | struct nl_msg * nl80211_drv_msg(struct wpa_driver_nl80211_data *drv, int flags, | |
478 | uint8_t cmd) | |
479 | { | |
480 | return nl80211_ifindex_msg(drv, drv->ifindex, flags, cmd); | |
481 | } | |
482 | ||
483 | ||
484 | struct nl_msg * nl80211_bss_msg(struct i802_bss *bss, int flags, uint8_t cmd) | |
485 | { | |
486 | return nl80211_ifindex_msg(bss->drv, bss->ifindex, flags, cmd); | |
487 | } | |
488 | ||
489 | ||
e32ad281 JB |
490 | struct wiphy_idx_data { |
491 | int wiphy_idx; | |
01517c8b | 492 | enum nl80211_iftype nlmode; |
597b94f5 | 493 | u8 *macaddr; |
e32ad281 JB |
494 | }; |
495 | ||
496 | ||
497 | static int netdev_info_handler(struct nl_msg *msg, void *arg) | |
498 | { | |
499 | struct nlattr *tb[NL80211_ATTR_MAX + 1]; | |
500 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); | |
501 | struct wiphy_idx_data *info = arg; | |
502 | ||
503 | nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), | |
504 | genlmsg_attrlen(gnlh, 0), NULL); | |
505 | ||
506 | if (tb[NL80211_ATTR_WIPHY]) | |
507 | info->wiphy_idx = nla_get_u32(tb[NL80211_ATTR_WIPHY]); | |
508 | ||
01517c8b JB |
509 | if (tb[NL80211_ATTR_IFTYPE]) |
510 | info->nlmode = nla_get_u32(tb[NL80211_ATTR_IFTYPE]); | |
511 | ||
597b94f5 AS |
512 | if (tb[NL80211_ATTR_MAC] && info->macaddr) |
513 | os_memcpy(info->macaddr, nla_data(tb[NL80211_ATTR_MAC]), | |
514 | ETH_ALEN); | |
515 | ||
e32ad281 JB |
516 | return NL_SKIP; |
517 | } | |
518 | ||
519 | ||
f3407c66 | 520 | int nl80211_get_wiphy_index(struct i802_bss *bss) |
e32ad281 JB |
521 | { |
522 | struct nl_msg *msg; | |
523 | struct wiphy_idx_data data = { | |
524 | .wiphy_idx = -1, | |
597b94f5 | 525 | .macaddr = NULL, |
e32ad281 JB |
526 | }; |
527 | ||
56f77852 | 528 | if (!(msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_GET_INTERFACE))) |
a862e4a3 | 529 | return -1; |
e32ad281 JB |
530 | |
531 | if (send_and_recv_msgs(bss->drv, msg, netdev_info_handler, &data) == 0) | |
532 | return data.wiphy_idx; | |
e32ad281 JB |
533 | return -1; |
534 | } | |
535 | ||
536 | ||
01517c8b JB |
537 | static enum nl80211_iftype nl80211_get_ifmode(struct i802_bss *bss) |
538 | { | |
539 | struct nl_msg *msg; | |
540 | struct wiphy_idx_data data = { | |
597b94f5 AS |
541 | .nlmode = NL80211_IFTYPE_UNSPECIFIED, |
542 | .macaddr = NULL, | |
01517c8b JB |
543 | }; |
544 | ||
56f77852 | 545 | if (!(msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_GET_INTERFACE))) |
a862e4a3 | 546 | return NL80211_IFTYPE_UNSPECIFIED; |
01517c8b JB |
547 | |
548 | if (send_and_recv_msgs(bss->drv, msg, netdev_info_handler, &data) == 0) | |
549 | return data.nlmode; | |
01517c8b JB |
550 | return NL80211_IFTYPE_UNSPECIFIED; |
551 | } | |
01517c8b JB |
552 | |
553 | ||
597b94f5 AS |
554 | static int nl80211_get_macaddr(struct i802_bss *bss) |
555 | { | |
556 | struct nl_msg *msg; | |
557 | struct wiphy_idx_data data = { | |
558 | .macaddr = bss->addr, | |
559 | }; | |
560 | ||
56f77852 | 561 | if (!(msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_GET_INTERFACE))) |
a862e4a3 | 562 | return -1; |
597b94f5 | 563 | |
597b94f5 | 564 | return send_and_recv_msgs(bss->drv, msg, netdev_info_handler, &data); |
597b94f5 | 565 | } |
597b94f5 AS |
566 | |
567 | ||
e32ad281 JB |
568 | static int nl80211_register_beacons(struct wpa_driver_nl80211_data *drv, |
569 | struct nl80211_wiphy_data *w) | |
570 | { | |
571 | struct nl_msg *msg; | |
a862e4a3 | 572 | int ret; |
e32ad281 JB |
573 | |
574 | msg = nlmsg_alloc(); | |
575 | if (!msg) | |
576 | return -1; | |
577 | ||
a862e4a3 JM |
578 | if (!nl80211_cmd(drv, msg, 0, NL80211_CMD_REGISTER_BEACONS) || |
579 | nla_put_u32(msg, NL80211_ATTR_WIPHY, w->wiphy_idx)) { | |
580 | nlmsg_free(msg); | |
581 | return -1; | |
582 | } | |
e32ad281 | 583 | |
481234cf | 584 | ret = send_and_recv(drv->global, w->nl_beacons, msg, NULL, NULL); |
e32ad281 JB |
585 | if (ret) { |
586 | wpa_printf(MSG_DEBUG, "nl80211: Register beacons command " | |
587 | "failed: ret=%d (%s)", | |
588 | ret, strerror(-ret)); | |
e32ad281 | 589 | } |
e32ad281 JB |
590 | return ret; |
591 | } | |
592 | ||
593 | ||
594 | static void nl80211_recv_beacons(int sock, void *eloop_ctx, void *handle) | |
595 | { | |
596 | struct nl80211_wiphy_data *w = eloop_ctx; | |
34068ac3 | 597 | int res; |
e32ad281 | 598 | |
ee9fc67a | 599 | wpa_printf(MSG_EXCESSIVE, "nl80211: Beacon event message available"); |
e32ad281 | 600 | |
34068ac3 | 601 | res = nl_recvmsgs(handle, w->nl_cb); |
d3d04831 | 602 | if (res < 0) { |
34068ac3 JM |
603 | wpa_printf(MSG_INFO, "nl80211: %s->nl_recvmsgs failed: %d", |
604 | __func__, res); | |
605 | } | |
e32ad281 JB |
606 | } |
607 | ||
608 | ||
609 | static int process_beacon_event(struct nl_msg *msg, void *arg) | |
610 | { | |
611 | struct nl80211_wiphy_data *w = arg; | |
612 | struct wpa_driver_nl80211_data *drv; | |
613 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); | |
614 | struct nlattr *tb[NL80211_ATTR_MAX + 1]; | |
615 | union wpa_event_data event; | |
616 | ||
617 | nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), | |
618 | genlmsg_attrlen(gnlh, 0), NULL); | |
619 | ||
620 | if (gnlh->cmd != NL80211_CMD_FRAME) { | |
621 | wpa_printf(MSG_DEBUG, "nl80211: Unexpected beacon event? (%d)", | |
622 | gnlh->cmd); | |
623 | return NL_SKIP; | |
624 | } | |
625 | ||
626 | if (!tb[NL80211_ATTR_FRAME]) | |
627 | return NL_SKIP; | |
628 | ||
629 | dl_list_for_each(drv, &w->drvs, struct wpa_driver_nl80211_data, | |
630 | wiphy_list) { | |
631 | os_memset(&event, 0, sizeof(event)); | |
632 | event.rx_mgmt.frame = nla_data(tb[NL80211_ATTR_FRAME]); | |
633 | event.rx_mgmt.frame_len = nla_len(tb[NL80211_ATTR_FRAME]); | |
634 | wpa_supplicant_event(drv->ctx, EVENT_RX_MGMT, &event); | |
635 | } | |
636 | ||
637 | return NL_SKIP; | |
638 | } | |
639 | ||
640 | ||
641 | static struct nl80211_wiphy_data * | |
642 | nl80211_get_wiphy_data_ap(struct i802_bss *bss) | |
643 | { | |
644 | static DEFINE_DL_LIST(nl80211_wiphys); | |
645 | struct nl80211_wiphy_data *w; | |
646 | int wiphy_idx, found = 0; | |
647 | struct i802_bss *tmp_bss; | |
648 | ||
649 | if (bss->wiphy_data != NULL) | |
650 | return bss->wiphy_data; | |
651 | ||
652 | wiphy_idx = nl80211_get_wiphy_index(bss); | |
653 | ||
654 | dl_list_for_each(w, &nl80211_wiphys, struct nl80211_wiphy_data, list) { | |
655 | if (w->wiphy_idx == wiphy_idx) | |
656 | goto add; | |
657 | } | |
658 | ||
659 | /* alloc new one */ | |
660 | w = os_zalloc(sizeof(*w)); | |
661 | if (w == NULL) | |
662 | return NULL; | |
663 | w->wiphy_idx = wiphy_idx; | |
664 | dl_list_init(&w->bsss); | |
665 | dl_list_init(&w->drvs); | |
666 | ||
667 | w->nl_cb = nl_cb_alloc(NL_CB_DEFAULT); | |
668 | if (!w->nl_cb) { | |
669 | os_free(w); | |
670 | return NULL; | |
671 | } | |
672 | nl_cb_set(w->nl_cb, NL_CB_SEQ_CHECK, NL_CB_CUSTOM, no_seq_check, NULL); | |
673 | nl_cb_set(w->nl_cb, NL_CB_VALID, NL_CB_CUSTOM, process_beacon_event, | |
674 | w); | |
675 | ||
481234cf JM |
676 | w->nl_beacons = nl_create_handle(bss->drv->global->nl_cb, |
677 | "wiphy beacons"); | |
678 | if (w->nl_beacons == NULL) { | |
e32ad281 JB |
679 | os_free(w); |
680 | return NULL; | |
681 | } | |
682 | ||
683 | if (nl80211_register_beacons(bss->drv, w)) { | |
684 | nl_destroy_handles(&w->nl_beacons); | |
685 | os_free(w); | |
686 | return NULL; | |
687 | } | |
688 | ||
5f65e9f7 | 689 | nl80211_register_eloop_read(&w->nl_beacons, nl80211_recv_beacons, w); |
e32ad281 JB |
690 | |
691 | dl_list_add(&nl80211_wiphys, &w->list); | |
692 | ||
693 | add: | |
694 | /* drv entry for this bss already there? */ | |
695 | dl_list_for_each(tmp_bss, &w->bsss, struct i802_bss, wiphy_list) { | |
696 | if (tmp_bss->drv == bss->drv) { | |
697 | found = 1; | |
698 | break; | |
699 | } | |
700 | } | |
701 | /* if not add it */ | |
702 | if (!found) | |
703 | dl_list_add(&w->drvs, &bss->drv->wiphy_list); | |
704 | ||
705 | dl_list_add(&w->bsss, &bss->wiphy_list); | |
706 | bss->wiphy_data = w; | |
707 | return w; | |
708 | } | |
709 | ||
710 | ||
711 | static void nl80211_put_wiphy_data_ap(struct i802_bss *bss) | |
712 | { | |
713 | struct nl80211_wiphy_data *w = bss->wiphy_data; | |
714 | struct i802_bss *tmp_bss; | |
715 | int found = 0; | |
716 | ||
717 | if (w == NULL) | |
718 | return; | |
719 | bss->wiphy_data = NULL; | |
720 | dl_list_del(&bss->wiphy_list); | |
721 | ||
722 | /* still any for this drv present? */ | |
723 | dl_list_for_each(tmp_bss, &w->bsss, struct i802_bss, wiphy_list) { | |
724 | if (tmp_bss->drv == bss->drv) { | |
725 | found = 1; | |
726 | break; | |
727 | } | |
728 | } | |
729 | /* if not remove it */ | |
730 | if (!found) | |
731 | dl_list_del(&bss->drv->wiphy_list); | |
732 | ||
733 | if (!dl_list_empty(&w->bsss)) | |
734 | return; | |
735 | ||
5f65e9f7 | 736 | nl80211_destroy_eloop_handle(&w->nl_beacons); |
e32ad281 JB |
737 | |
738 | nl_cb_put(w->nl_cb); | |
e32ad281 JB |
739 | dl_list_del(&w->list); |
740 | os_free(w); | |
741 | } | |
742 | ||
743 | ||
3f5285e8 JM |
744 | static int wpa_driver_nl80211_get_bssid(void *priv, u8 *bssid) |
745 | { | |
a2e40bb6 FF |
746 | struct i802_bss *bss = priv; |
747 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
c2a04078 JM |
748 | if (!drv->associated) |
749 | return -1; | |
750 | os_memcpy(bssid, drv->bssid, ETH_ALEN); | |
751 | return 0; | |
3f5285e8 JM |
752 | } |
753 | ||
754 | ||
3f5285e8 JM |
755 | static int wpa_driver_nl80211_get_ssid(void *priv, u8 *ssid) |
756 | { | |
a2e40bb6 FF |
757 | struct i802_bss *bss = priv; |
758 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
fd05d64e JM |
759 | if (!drv->associated) |
760 | return -1; | |
761 | os_memcpy(ssid, drv->ssid, drv->ssid_len); | |
762 | return drv->ssid_len; | |
3f5285e8 JM |
763 | } |
764 | ||
765 | ||
90a545cc | 766 | static void wpa_driver_nl80211_event_newlink( |
40e76396 | 767 | struct wpa_driver_nl80211_data *drv, const char *ifname) |
3f5285e8 JM |
768 | { |
769 | union wpa_event_data event; | |
770 | ||
90a545cc JM |
771 | if (os_strcmp(drv->first_bss->ifname, ifname) == 0) { |
772 | if (if_nametoindex(drv->first_bss->ifname) == 0) { | |
773 | wpa_printf(MSG_DEBUG, "nl80211: Interface %s does not exist - ignore RTM_NEWLINK", | |
774 | drv->first_bss->ifname); | |
775 | return; | |
776 | } | |
777 | if (!drv->if_removed) | |
778 | return; | |
779 | wpa_printf(MSG_DEBUG, "nl80211: Mark if_removed=0 for %s based on RTM_NEWLINK event", | |
780 | drv->first_bss->ifname); | |
781 | drv->if_removed = 0; | |
782 | } | |
783 | ||
3f5285e8 | 784 | os_memset(&event, 0, sizeof(event)); |
90a545cc JM |
785 | os_strlcpy(event.interface_status.ifname, ifname, |
786 | sizeof(event.interface_status.ifname)); | |
787 | event.interface_status.ievent = EVENT_INTERFACE_ADDED; | |
788 | wpa_supplicant_event(drv->ctx, EVENT_INTERFACE_STATUS, &event); | |
789 | } | |
790 | ||
791 | ||
792 | static void wpa_driver_nl80211_event_dellink( | |
40e76396 | 793 | struct wpa_driver_nl80211_data *drv, const char *ifname) |
90a545cc JM |
794 | { |
795 | union wpa_event_data event; | |
796 | ||
797 | if (os_strcmp(drv->first_bss->ifname, ifname) == 0) { | |
798 | if (drv->if_removed) { | |
799 | wpa_printf(MSG_DEBUG, "nl80211: if_removed already set - ignore RTM_DELLINK event for %s", | |
800 | ifname); | |
801 | return; | |
d1f4942b | 802 | } |
90a545cc JM |
803 | wpa_printf(MSG_DEBUG, "RTM_DELLINK: Interface '%s' removed - mark if_removed=1", |
804 | ifname); | |
805 | drv->if_removed = 1; | |
806 | } else { | |
807 | wpa_printf(MSG_DEBUG, "RTM_DELLINK: Interface '%s' removed", | |
808 | ifname); | |
7524cfb1 JM |
809 | } |
810 | ||
90a545cc JM |
811 | os_memset(&event, 0, sizeof(event)); |
812 | os_strlcpy(event.interface_status.ifname, ifname, | |
813 | sizeof(event.interface_status.ifname)); | |
814 | event.interface_status.ievent = EVENT_INTERFACE_REMOVED; | |
08063178 | 815 | wpa_supplicant_event(drv->ctx, EVENT_INTERFACE_STATUS, &event); |
3f5285e8 JM |
816 | } |
817 | ||
818 | ||
7524cfb1 | 819 | static int wpa_driver_nl80211_own_ifname(struct wpa_driver_nl80211_data *drv, |
62d680c3 | 820 | u8 *buf, size_t len) |
7524cfb1 | 821 | { |
62d680c3 | 822 | int attrlen, rta_len; |
7524cfb1 JM |
823 | struct rtattr *attr; |
824 | ||
62d680c3 JM |
825 | attrlen = len; |
826 | attr = (struct rtattr *) buf; | |
7524cfb1 JM |
827 | |
828 | rta_len = RTA_ALIGN(sizeof(struct rtattr)); | |
829 | while (RTA_OK(attr, attrlen)) { | |
830 | if (attr->rta_type == IFLA_IFNAME) { | |
834ee56f KP |
831 | if (os_strcmp(((char *) attr) + rta_len, |
832 | drv->first_bss->ifname) == 0) | |
7524cfb1 JM |
833 | return 1; |
834 | else | |
835 | break; | |
836 | } | |
837 | attr = RTA_NEXT(attr, attrlen); | |
838 | } | |
839 | ||
840 | return 0; | |
841 | } | |
842 | ||
843 | ||
844 | static int wpa_driver_nl80211_own_ifindex(struct wpa_driver_nl80211_data *drv, | |
62d680c3 | 845 | int ifindex, u8 *buf, size_t len) |
7524cfb1 JM |
846 | { |
847 | if (drv->ifindex == ifindex) | |
848 | return 1; | |
849 | ||
62d680c3 | 850 | if (drv->if_removed && wpa_driver_nl80211_own_ifname(drv, buf, len)) { |
7524cfb1 JM |
851 | wpa_printf(MSG_DEBUG, "nl80211: Update ifindex for a removed " |
852 | "interface"); | |
0ecff8d7 | 853 | wpa_driver_nl80211_finish_drv_init(drv, NULL, 0, NULL); |
7524cfb1 JM |
854 | return 1; |
855 | } | |
856 | ||
857 | return 0; | |
858 | } | |
859 | ||
860 | ||
36d84860 BG |
861 | static struct wpa_driver_nl80211_data * |
862 | nl80211_find_drv(struct nl80211_global *global, int idx, u8 *buf, size_t len) | |
863 | { | |
864 | struct wpa_driver_nl80211_data *drv; | |
865 | dl_list_for_each(drv, &global->interfaces, | |
866 | struct wpa_driver_nl80211_data, list) { | |
867 | if (wpa_driver_nl80211_own_ifindex(drv, idx, buf, len) || | |
868 | have_ifidx(drv, idx)) | |
869 | return drv; | |
870 | } | |
871 | return NULL; | |
872 | } | |
873 | ||
874 | ||
62d680c3 JM |
875 | static void wpa_driver_nl80211_event_rtm_newlink(void *ctx, |
876 | struct ifinfomsg *ifi, | |
877 | u8 *buf, size_t len) | |
3f5285e8 | 878 | { |
36d84860 BG |
879 | struct nl80211_global *global = ctx; |
880 | struct wpa_driver_nl80211_data *drv; | |
90a545cc | 881 | int attrlen; |
62d680c3 | 882 | struct rtattr *attr; |
97cfcf64 | 883 | u32 brid = 0; |
aef85ba2 | 884 | char namebuf[IFNAMSIZ]; |
90a545cc JM |
885 | char ifname[IFNAMSIZ + 1]; |
886 | char extra[100], *pos, *end; | |
3f5285e8 | 887 | |
36d84860 BG |
888 | drv = nl80211_find_drv(global, ifi->ifi_index, buf, len); |
889 | if (!drv) { | |
90a545cc JM |
890 | wpa_printf(MSG_DEBUG, "nl80211: Ignore RTM_NEWLINK event for foreign ifindex %d", |
891 | ifi->ifi_index); | |
3f5285e8 JM |
892 | return; |
893 | } | |
894 | ||
90a545cc JM |
895 | extra[0] = '\0'; |
896 | pos = extra; | |
897 | end = pos + sizeof(extra); | |
898 | ifname[0] = '\0'; | |
899 | ||
900 | attrlen = len; | |
901 | attr = (struct rtattr *) buf; | |
902 | while (RTA_OK(attr, attrlen)) { | |
903 | switch (attr->rta_type) { | |
904 | case IFLA_IFNAME: | |
905 | if (RTA_PAYLOAD(attr) >= IFNAMSIZ) | |
906 | break; | |
907 | os_memcpy(ifname, RTA_DATA(attr), RTA_PAYLOAD(attr)); | |
908 | ifname[RTA_PAYLOAD(attr)] = '\0'; | |
909 | break; | |
910 | case IFLA_MASTER: | |
911 | brid = nla_get_u32((struct nlattr *) attr); | |
912 | pos += os_snprintf(pos, end - pos, " master=%u", brid); | |
913 | break; | |
914 | case IFLA_WIRELESS: | |
915 | pos += os_snprintf(pos, end - pos, " wext"); | |
916 | break; | |
917 | case IFLA_OPERSTATE: | |
918 | pos += os_snprintf(pos, end - pos, " operstate=%u", | |
919 | nla_get_u32((struct nlattr *) attr)); | |
920 | break; | |
921 | case IFLA_LINKMODE: | |
922 | pos += os_snprintf(pos, end - pos, " linkmode=%u", | |
923 | nla_get_u32((struct nlattr *) attr)); | |
924 | break; | |
925 | } | |
926 | attr = RTA_NEXT(attr, attrlen); | |
927 | } | |
928 | extra[sizeof(extra) - 1] = '\0'; | |
929 | ||
f2e90835 JM |
930 | wpa_printf(MSG_DEBUG, "RTM_NEWLINK: ifi_index=%d ifname=%s%s ifi_family=%d ifi_flags=0x%x (%s%s%s%s)", |
931 | ifi->ifi_index, ifname, extra, ifi->ifi_family, | |
932 | ifi->ifi_flags, | |
3f5285e8 JM |
933 | (ifi->ifi_flags & IFF_UP) ? "[UP]" : "", |
934 | (ifi->ifi_flags & IFF_RUNNING) ? "[RUNNING]" : "", | |
935 | (ifi->ifi_flags & IFF_LOWER_UP) ? "[LOWER_UP]" : "", | |
936 | (ifi->ifi_flags & IFF_DORMANT) ? "[DORMANT]" : ""); | |
a63063b4 JM |
937 | |
938 | if (!drv->if_disabled && !(ifi->ifi_flags & IFF_UP)) { | |
59d24925 JM |
939 | if (if_indextoname(ifi->ifi_index, namebuf) && |
940 | linux_iface_up(drv->global->ioctl_sock, | |
834ee56f | 941 | drv->first_bss->ifname) > 0) { |
59d24925 JM |
942 | wpa_printf(MSG_DEBUG, "nl80211: Ignore interface down " |
943 | "event since interface %s is up", namebuf); | |
7a94120e | 944 | drv->ignore_if_down_event = 0; |
59d24925 JM |
945 | return; |
946 | } | |
a63063b4 | 947 | wpa_printf(MSG_DEBUG, "nl80211: Interface down"); |
7d9c3698 JM |
948 | if (drv->ignore_if_down_event) { |
949 | wpa_printf(MSG_DEBUG, "nl80211: Ignore interface down " | |
950 | "event generated by mode change"); | |
951 | drv->ignore_if_down_event = 0; | |
952 | } else { | |
953 | drv->if_disabled = 1; | |
954 | wpa_supplicant_event(drv->ctx, | |
955 | EVENT_INTERFACE_DISABLED, NULL); | |
819f096f AO |
956 | |
957 | /* | |
958 | * Try to get drv again, since it may be removed as | |
959 | * part of the EVENT_INTERFACE_DISABLED handling for | |
960 | * dynamic interfaces | |
961 | */ | |
962 | drv = nl80211_find_drv(global, ifi->ifi_index, | |
963 | buf, len); | |
964 | if (!drv) | |
965 | return; | |
7d9c3698 | 966 | } |
a63063b4 JM |
967 | } |
968 | ||
969 | if (drv->if_disabled && (ifi->ifi_flags & IFF_UP)) { | |
aef85ba2 JM |
970 | if (if_indextoname(ifi->ifi_index, namebuf) && |
971 | linux_iface_up(drv->global->ioctl_sock, | |
834ee56f | 972 | drv->first_bss->ifname) == 0) { |
aef85ba2 JM |
973 | wpa_printf(MSG_DEBUG, "nl80211: Ignore interface up " |
974 | "event since interface %s is down", | |
975 | namebuf); | |
834ee56f | 976 | } else if (if_nametoindex(drv->first_bss->ifname) == 0) { |
d1f4942b JM |
977 | wpa_printf(MSG_DEBUG, "nl80211: Ignore interface up " |
978 | "event since interface %s does not exist", | |
834ee56f | 979 | drv->first_bss->ifname); |
d1f4942b JM |
980 | } else if (drv->if_removed) { |
981 | wpa_printf(MSG_DEBUG, "nl80211: Ignore interface up " | |
982 | "event since interface %s is marked " | |
834ee56f | 983 | "removed", drv->first_bss->ifname); |
aef85ba2 | 984 | } else { |
3e0272ca DW |
985 | struct i802_bss *bss; |
986 | u8 addr[ETH_ALEN]; | |
987 | ||
988 | /* Re-read MAC address as it may have changed */ | |
989 | bss = get_bss_ifindex(drv, ifi->ifi_index); | |
990 | if (bss && | |
991 | linux_get_ifhwaddr(drv->global->ioctl_sock, | |
992 | bss->ifname, addr) < 0) { | |
993 | wpa_printf(MSG_DEBUG, | |
994 | "nl80211: %s: failed to re-read MAC address", | |
995 | bss->ifname); | |
996 | } else if (bss && | |
997 | os_memcmp(addr, bss->addr, ETH_ALEN) != 0) { | |
998 | wpa_printf(MSG_DEBUG, | |
999 | "nl80211: Own MAC address on ifindex %d (%s) changed from " | |
1000 | MACSTR " to " MACSTR, | |
1001 | ifi->ifi_index, bss->ifname, | |
1002 | MAC2STR(bss->addr), | |
1003 | MAC2STR(addr)); | |
1004 | os_memcpy(bss->addr, addr, ETH_ALEN); | |
1005 | } | |
1006 | ||
aef85ba2 JM |
1007 | wpa_printf(MSG_DEBUG, "nl80211: Interface up"); |
1008 | drv->if_disabled = 0; | |
1009 | wpa_supplicant_event(drv->ctx, EVENT_INTERFACE_ENABLED, | |
1010 | NULL); | |
1011 | } | |
a63063b4 JM |
1012 | } |
1013 | ||
3f5285e8 JM |
1014 | /* |
1015 | * Some drivers send the association event before the operup event--in | |
1016 | * this case, lifting operstate in wpa_driver_nl80211_set_operstate() | |
1017 | * fails. This will hit us when wpa_supplicant does not need to do | |
1018 | * IEEE 802.1X authentication | |
1019 | */ | |
1020 | if (drv->operstate == 1 && | |
1021 | (ifi->ifi_flags & (IFF_LOWER_UP | IFF_DORMANT)) == IFF_LOWER_UP && | |
90a545cc JM |
1022 | !(ifi->ifi_flags & IFF_RUNNING)) { |
1023 | wpa_printf(MSG_DEBUG, "nl80211: Set IF_OPER_UP again based on ifi_flags and expected operstate"); | |
36d84860 | 1024 | netlink_send_oper_ifla(drv->global->netlink, drv->ifindex, |
e2d02c29 | 1025 | -1, IF_OPER_UP); |
3f5285e8 | 1026 | } |
97cfcf64 | 1027 | |
90a545cc JM |
1028 | if (ifname[0]) |
1029 | wpa_driver_nl80211_event_newlink(drv, ifname); | |
1030 | ||
97cfcf64 | 1031 | if (ifi->ifi_family == AF_BRIDGE && brid) { |
392dfd37 JM |
1032 | struct i802_bss *bss; |
1033 | ||
97cfcf64 | 1034 | /* device has been added to bridge */ |
40e76396 JM |
1035 | if (!if_indextoname(brid, namebuf)) { |
1036 | wpa_printf(MSG_DEBUG, | |
1037 | "nl80211: Could not find bridge ifname for ifindex %u", | |
1038 | brid); | |
1039 | return; | |
1040 | } | |
97cfcf64 B |
1041 | wpa_printf(MSG_DEBUG, "nl80211: Add ifindex %u for bridge %s", |
1042 | brid, namebuf); | |
1043 | add_ifidx(drv, brid); | |
392dfd37 JM |
1044 | |
1045 | for (bss = drv->first_bss; bss; bss = bss->next) { | |
1046 | if (os_strcmp(ifname, bss->ifname) == 0) { | |
1047 | os_strlcpy(bss->brname, namebuf, IFNAMSIZ); | |
1048 | break; | |
1049 | } | |
1050 | } | |
97cfcf64 | 1051 | } |
3f5285e8 JM |
1052 | } |
1053 | ||
1054 | ||
62d680c3 JM |
1055 | static void wpa_driver_nl80211_event_rtm_dellink(void *ctx, |
1056 | struct ifinfomsg *ifi, | |
1057 | u8 *buf, size_t len) | |
3f5285e8 | 1058 | { |
36d84860 BG |
1059 | struct nl80211_global *global = ctx; |
1060 | struct wpa_driver_nl80211_data *drv; | |
90a545cc | 1061 | int attrlen; |
62d680c3 | 1062 | struct rtattr *attr; |
97cfcf64 | 1063 | u32 brid = 0; |
90a545cc | 1064 | char ifname[IFNAMSIZ + 1]; |
f2e90835 | 1065 | char extra[100], *pos, *end; |
3f5285e8 | 1066 | |
36d84860 BG |
1067 | drv = nl80211_find_drv(global, ifi->ifi_index, buf, len); |
1068 | if (!drv) { | |
90a545cc JM |
1069 | wpa_printf(MSG_DEBUG, "nl80211: Ignore RTM_DELLINK event for foreign ifindex %d", |
1070 | ifi->ifi_index); | |
36d84860 BG |
1071 | return; |
1072 | } | |
1073 | ||
f2e90835 JM |
1074 | extra[0] = '\0'; |
1075 | pos = extra; | |
1076 | end = pos + sizeof(extra); | |
90a545cc JM |
1077 | ifname[0] = '\0'; |
1078 | ||
62d680c3 JM |
1079 | attrlen = len; |
1080 | attr = (struct rtattr *) buf; | |
3f5285e8 | 1081 | while (RTA_OK(attr, attrlen)) { |
90a545cc JM |
1082 | switch (attr->rta_type) { |
1083 | case IFLA_IFNAME: | |
1084 | if (RTA_PAYLOAD(attr) >= IFNAMSIZ) | |
1085 | break; | |
1086 | os_memcpy(ifname, RTA_DATA(attr), RTA_PAYLOAD(attr)); | |
1087 | ifname[RTA_PAYLOAD(attr)] = '\0'; | |
1088 | break; | |
1089 | case IFLA_MASTER: | |
97cfcf64 | 1090 | brid = nla_get_u32((struct nlattr *) attr); |
f2e90835 JM |
1091 | pos += os_snprintf(pos, end - pos, " master=%u", brid); |
1092 | break; | |
1093 | case IFLA_OPERSTATE: | |
1094 | pos += os_snprintf(pos, end - pos, " operstate=%u", | |
1095 | nla_get_u32((struct nlattr *) attr)); | |
1096 | break; | |
1097 | case IFLA_LINKMODE: | |
1098 | pos += os_snprintf(pos, end - pos, " linkmode=%u", | |
1099 | nla_get_u32((struct nlattr *) attr)); | |
90a545cc JM |
1100 | break; |
1101 | } | |
3f5285e8 JM |
1102 | attr = RTA_NEXT(attr, attrlen); |
1103 | } | |
f2e90835 JM |
1104 | extra[sizeof(extra) - 1] = '\0'; |
1105 | ||
1106 | wpa_printf(MSG_DEBUG, "RTM_DELLINK: ifi_index=%d ifname=%s%s ifi_family=%d ifi_flags=0x%x (%s%s%s%s)", | |
1107 | ifi->ifi_index, ifname, extra, ifi->ifi_family, | |
1108 | ifi->ifi_flags, | |
1109 | (ifi->ifi_flags & IFF_UP) ? "[UP]" : "", | |
1110 | (ifi->ifi_flags & IFF_RUNNING) ? "[RUNNING]" : "", | |
1111 | (ifi->ifi_flags & IFF_LOWER_UP) ? "[LOWER_UP]" : "", | |
1112 | (ifi->ifi_flags & IFF_DORMANT) ? "[DORMANT]" : ""); | |
97cfcf64 | 1113 | |
728ff2f4 | 1114 | if (ifname[0] && (ifi->ifi_family != AF_BRIDGE || !brid)) |
90a545cc JM |
1115 | wpa_driver_nl80211_event_dellink(drv, ifname); |
1116 | ||
97cfcf64 B |
1117 | if (ifi->ifi_family == AF_BRIDGE && brid) { |
1118 | /* device has been removed from bridge */ | |
1119 | char namebuf[IFNAMSIZ]; | |
40e76396 JM |
1120 | |
1121 | if (!if_indextoname(brid, namebuf)) { | |
1122 | wpa_printf(MSG_DEBUG, | |
1123 | "nl80211: Could not find bridge ifname for ifindex %u", | |
1124 | brid); | |
1125 | } else { | |
1126 | wpa_printf(MSG_DEBUG, | |
1127 | "nl80211: Remove ifindex %u for bridge %s", | |
1128 | brid, namebuf); | |
1129 | } | |
97cfcf64 B |
1130 | del_ifidx(drv, brid); |
1131 | } | |
3f5285e8 JM |
1132 | } |
1133 | ||
1134 | ||
f3407c66 | 1135 | unsigned int nl80211_get_assoc_freq(struct wpa_driver_nl80211_data *drv) |
f5a8d422 JM |
1136 | { |
1137 | struct nl_msg *msg; | |
1138 | int ret; | |
1139 | struct nl80211_bss_info_arg arg; | |
1140 | ||
9725b784 | 1141 | msg = nl80211_drv_msg(drv, NLM_F_DUMP, NL80211_CMD_GET_SCAN); |
f5a8d422 | 1142 | os_memset(&arg, 0, sizeof(arg)); |
f5a8d422 JM |
1143 | arg.drv = drv; |
1144 | ret = send_and_recv_msgs(drv, msg, bss_info_handler, &arg); | |
f5a8d422 | 1145 | if (ret == 0) { |
c7caac56 JM |
1146 | unsigned int freq = drv->nlmode == NL80211_IFTYPE_ADHOC ? |
1147 | arg.ibss_freq : arg.assoc_freq; | |
f5a8d422 | 1148 | wpa_printf(MSG_DEBUG, "nl80211: Operating frequency for the " |
c7caac56 JM |
1149 | "associated BSS from scan results: %u MHz", freq); |
1150 | if (freq) | |
1151 | drv->assoc_freq = freq; | |
30158a0d | 1152 | return drv->assoc_freq; |
f5a8d422 JM |
1153 | } |
1154 | wpa_printf(MSG_DEBUG, "nl80211: Scan result fetch failed: ret=%d " | |
1155 | "(%s)", ret, strerror(-ret)); | |
f5a8d422 JM |
1156 | return drv->assoc_freq; |
1157 | } | |
1158 | ||
1159 | ||
60a972a6 JM |
1160 | static int get_link_signal(struct nl_msg *msg, void *arg) |
1161 | { | |
1162 | struct nlattr *tb[NL80211_ATTR_MAX + 1]; | |
1163 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); | |
1164 | struct nlattr *sinfo[NL80211_STA_INFO_MAX + 1]; | |
1165 | static struct nla_policy policy[NL80211_STA_INFO_MAX + 1] = { | |
1166 | [NL80211_STA_INFO_SIGNAL] = { .type = NLA_U8 }, | |
95783298 | 1167 | [NL80211_STA_INFO_SIGNAL_AVG] = { .type = NLA_U8 }, |
60a972a6 | 1168 | }; |
7ee35bf3 PS |
1169 | struct nlattr *rinfo[NL80211_RATE_INFO_MAX + 1]; |
1170 | static struct nla_policy rate_policy[NL80211_RATE_INFO_MAX + 1] = { | |
1171 | [NL80211_RATE_INFO_BITRATE] = { .type = NLA_U16 }, | |
1172 | [NL80211_RATE_INFO_MCS] = { .type = NLA_U8 }, | |
1173 | [NL80211_RATE_INFO_40_MHZ_WIDTH] = { .type = NLA_FLAG }, | |
1174 | [NL80211_RATE_INFO_SHORT_GI] = { .type = NLA_FLAG }, | |
1175 | }; | |
1c5c7273 | 1176 | struct wpa_signal_info *sig_change = arg; |
60a972a6 JM |
1177 | |
1178 | nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), | |
1179 | genlmsg_attrlen(gnlh, 0), NULL); | |
1180 | if (!tb[NL80211_ATTR_STA_INFO] || | |
1181 | nla_parse_nested(sinfo, NL80211_STA_INFO_MAX, | |
1182 | tb[NL80211_ATTR_STA_INFO], policy)) | |
1183 | return NL_SKIP; | |
1184 | if (!sinfo[NL80211_STA_INFO_SIGNAL]) | |
1185 | return NL_SKIP; | |
1186 | ||
7ee35bf3 PS |
1187 | sig_change->current_signal = |
1188 | (s8) nla_get_u8(sinfo[NL80211_STA_INFO_SIGNAL]); | |
1189 | ||
95783298 AO |
1190 | if (sinfo[NL80211_STA_INFO_SIGNAL_AVG]) |
1191 | sig_change->avg_signal = | |
1192 | (s8) nla_get_u8(sinfo[NL80211_STA_INFO_SIGNAL_AVG]); | |
1193 | else | |
1194 | sig_change->avg_signal = 0; | |
1195 | ||
7ee35bf3 PS |
1196 | if (sinfo[NL80211_STA_INFO_TX_BITRATE]) { |
1197 | if (nla_parse_nested(rinfo, NL80211_RATE_INFO_MAX, | |
1198 | sinfo[NL80211_STA_INFO_TX_BITRATE], | |
1199 | rate_policy)) { | |
1200 | sig_change->current_txrate = 0; | |
1201 | } else { | |
1202 | if (rinfo[NL80211_RATE_INFO_BITRATE]) { | |
1203 | sig_change->current_txrate = | |
1204 | nla_get_u16(rinfo[ | |
1205 | NL80211_RATE_INFO_BITRATE]) * 100; | |
1206 | } | |
1207 | } | |
1208 | } | |
1209 | ||
60a972a6 JM |
1210 | return NL_SKIP; |
1211 | } | |
1212 | ||
1213 | ||
f3407c66 JM |
1214 | int nl80211_get_link_signal(struct wpa_driver_nl80211_data *drv, |
1215 | struct wpa_signal_info *sig) | |
60a972a6 JM |
1216 | { |
1217 | struct nl_msg *msg; | |
1218 | ||
7ee35bf3 PS |
1219 | sig->current_signal = -9999; |
1220 | sig->current_txrate = 0; | |
60a972a6 | 1221 | |
9725b784 | 1222 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_GET_STATION)) || |
a862e4a3 JM |
1223 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, drv->bssid)) { |
1224 | nlmsg_free(msg); | |
1225 | return -ENOBUFS; | |
1226 | } | |
60a972a6 JM |
1227 | |
1228 | return send_and_recv_msgs(drv, msg, get_link_signal, sig); | |
60a972a6 JM |
1229 | } |
1230 | ||
1231 | ||
7ee35bf3 PS |
1232 | static int get_link_noise(struct nl_msg *msg, void *arg) |
1233 | { | |
1234 | struct nlattr *tb[NL80211_ATTR_MAX + 1]; | |
1235 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); | |
1236 | struct nlattr *sinfo[NL80211_SURVEY_INFO_MAX + 1]; | |
1237 | static struct nla_policy survey_policy[NL80211_SURVEY_INFO_MAX + 1] = { | |
1238 | [NL80211_SURVEY_INFO_FREQUENCY] = { .type = NLA_U32 }, | |
1239 | [NL80211_SURVEY_INFO_NOISE] = { .type = NLA_U8 }, | |
1240 | }; | |
1c5c7273 | 1241 | struct wpa_signal_info *sig_change = arg; |
7ee35bf3 PS |
1242 | |
1243 | nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), | |
1244 | genlmsg_attrlen(gnlh, 0), NULL); | |
1245 | ||
1246 | if (!tb[NL80211_ATTR_SURVEY_INFO]) { | |
1247 | wpa_printf(MSG_DEBUG, "nl80211: survey data missing!"); | |
1248 | return NL_SKIP; | |
1249 | } | |
1250 | ||
1251 | if (nla_parse_nested(sinfo, NL80211_SURVEY_INFO_MAX, | |
1252 | tb[NL80211_ATTR_SURVEY_INFO], | |
1253 | survey_policy)) { | |
1254 | wpa_printf(MSG_DEBUG, "nl80211: failed to parse nested " | |
1255 | "attributes!"); | |
1256 | return NL_SKIP; | |
1257 | } | |
1258 | ||
1259 | if (!sinfo[NL80211_SURVEY_INFO_FREQUENCY]) | |
1260 | return NL_SKIP; | |
1261 | ||
1262 | if (nla_get_u32(sinfo[NL80211_SURVEY_INFO_FREQUENCY]) != | |
1263 | sig_change->frequency) | |
1264 | return NL_SKIP; | |
1265 | ||
1266 | if (!sinfo[NL80211_SURVEY_INFO_NOISE]) | |
1267 | return NL_SKIP; | |
1268 | ||
1269 | sig_change->current_noise = | |
1270 | (s8) nla_get_u8(sinfo[NL80211_SURVEY_INFO_NOISE]); | |
1271 | ||
1272 | return NL_SKIP; | |
1273 | } | |
1274 | ||
1275 | ||
f3407c66 JM |
1276 | int nl80211_get_link_noise(struct wpa_driver_nl80211_data *drv, |
1277 | struct wpa_signal_info *sig_change) | |
7ee35bf3 PS |
1278 | { |
1279 | struct nl_msg *msg; | |
1280 | ||
1281 | sig_change->current_noise = 9999; | |
1282 | sig_change->frequency = drv->assoc_freq; | |
1283 | ||
9725b784 | 1284 | msg = nl80211_drv_msg(drv, NLM_F_DUMP, NL80211_CMD_GET_SURVEY); |
7ee35bf3 | 1285 | return send_and_recv_msgs(drv, msg, get_link_noise, sig_change); |
7ee35bf3 PS |
1286 | } |
1287 | ||
1288 | ||
97865538 | 1289 | static void wpa_driver_nl80211_event_receive(int sock, void *eloop_ctx, |
5582a5d1 | 1290 | void *handle) |
97865538 | 1291 | { |
a4ae123c | 1292 | struct nl_cb *cb = eloop_ctx; |
34068ac3 | 1293 | int res; |
97865538 | 1294 | |
cc2ada86 | 1295 | wpa_printf(MSG_MSGDUMP, "nl80211: Event message available"); |
97865538 | 1296 | |
34068ac3 | 1297 | res = nl_recvmsgs(handle, cb); |
d3d04831 | 1298 | if (res < 0) { |
34068ac3 JM |
1299 | wpa_printf(MSG_INFO, "nl80211: %s->nl_recvmsgs failed: %d", |
1300 | __func__, res); | |
1301 | } | |
97865538 JM |
1302 | } |
1303 | ||
1304 | ||
6d158490 LR |
1305 | /** |
1306 | * wpa_driver_nl80211_set_country - ask nl80211 to set the regulatory domain | |
1307 | * @priv: driver_nl80211 private data | |
1308 | * @alpha2_arg: country to which to switch to | |
1309 | * Returns: 0 on success, -1 on failure | |
1310 | * | |
1311 | * This asks nl80211 to set the regulatory domain for given | |
1312 | * country ISO / IEC alpha2. | |
1313 | */ | |
1314 | static int wpa_driver_nl80211_set_country(void *priv, const char *alpha2_arg) | |
1315 | { | |
a2e40bb6 FF |
1316 | struct i802_bss *bss = priv; |
1317 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
6d158490 LR |
1318 | char alpha2[3]; |
1319 | struct nl_msg *msg; | |
1320 | ||
1321 | msg = nlmsg_alloc(); | |
1322 | if (!msg) | |
e785c2ba | 1323 | return -ENOMEM; |
6d158490 LR |
1324 | |
1325 | alpha2[0] = alpha2_arg[0]; | |
1326 | alpha2[1] = alpha2_arg[1]; | |
1327 | alpha2[2] = '\0'; | |
1328 | ||
a862e4a3 JM |
1329 | if (!nl80211_cmd(drv, msg, 0, NL80211_CMD_REQ_SET_REG) || |
1330 | nla_put_string(msg, NL80211_ATTR_REG_ALPHA2, alpha2)) { | |
1331 | nlmsg_free(msg); | |
1332 | return -EINVAL; | |
1333 | } | |
6d158490 LR |
1334 | if (send_and_recv_msgs(drv, msg, NULL, NULL)) |
1335 | return -EINVAL; | |
1336 | return 0; | |
6d158490 LR |
1337 | } |
1338 | ||
1339 | ||
f0793bf1 JM |
1340 | static int nl80211_get_country(struct nl_msg *msg, void *arg) |
1341 | { | |
1342 | char *alpha2 = arg; | |
1343 | struct nlattr *tb_msg[NL80211_ATTR_MAX + 1]; | |
1344 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); | |
1345 | ||
1346 | nla_parse(tb_msg, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), | |
1347 | genlmsg_attrlen(gnlh, 0), NULL); | |
1348 | if (!tb_msg[NL80211_ATTR_REG_ALPHA2]) { | |
1349 | wpa_printf(MSG_DEBUG, "nl80211: No country information available"); | |
1350 | return NL_SKIP; | |
1351 | } | |
1352 | os_strlcpy(alpha2, nla_data(tb_msg[NL80211_ATTR_REG_ALPHA2]), 3); | |
1353 | return NL_SKIP; | |
1354 | } | |
1355 | ||
1356 | ||
1357 | static int wpa_driver_nl80211_get_country(void *priv, char *alpha2) | |
1358 | { | |
1359 | struct i802_bss *bss = priv; | |
1360 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
1361 | struct nl_msg *msg; | |
1362 | int ret; | |
1363 | ||
1364 | msg = nlmsg_alloc(); | |
1365 | if (!msg) | |
1366 | return -ENOMEM; | |
1367 | ||
1368 | nl80211_cmd(drv, msg, 0, NL80211_CMD_GET_REG); | |
1369 | alpha2[0] = '\0'; | |
1370 | ret = send_and_recv_msgs(drv, msg, nl80211_get_country, alpha2); | |
1371 | if (!alpha2[0]) | |
1372 | ret = -1; | |
1373 | ||
1374 | return ret; | |
1375 | } | |
1376 | ||
1377 | ||
2a7b66f5 BG |
1378 | static int wpa_driver_nl80211_init_nl_global(struct nl80211_global *global) |
1379 | { | |
d6c9aab8 JB |
1380 | int ret; |
1381 | ||
2a7b66f5 BG |
1382 | global->nl_cb = nl_cb_alloc(NL_CB_DEFAULT); |
1383 | if (global->nl_cb == NULL) { | |
1384 | wpa_printf(MSG_ERROR, "nl80211: Failed to allocate netlink " | |
1385 | "callbacks"); | |
1386 | return -1; | |
1387 | } | |
1388 | ||
481234cf JM |
1389 | global->nl = nl_create_handle(global->nl_cb, "nl"); |
1390 | if (global->nl == NULL) | |
d6c9aab8 | 1391 | goto err; |
276e2d67 | 1392 | |
481234cf | 1393 | global->nl80211_id = genl_ctrl_resolve(global->nl, "nl80211"); |
335d42b1 | 1394 | if (global->nl80211_id < 0) { |
276e2d67 BG |
1395 | wpa_printf(MSG_ERROR, "nl80211: 'nl80211' generic netlink not " |
1396 | "found"); | |
d6c9aab8 | 1397 | goto err; |
276e2d67 BG |
1398 | } |
1399 | ||
481234cf JM |
1400 | global->nl_event = nl_create_handle(global->nl_cb, "event"); |
1401 | if (global->nl_event == NULL) | |
d6c9aab8 | 1402 | goto err; |
9fff9fdc | 1403 | |
d6c9aab8 | 1404 | ret = nl_get_multicast_id(global, "nl80211", "scan"); |
97865538 | 1405 | if (ret >= 0) |
481234cf | 1406 | ret = nl_socket_add_membership(global->nl_event, ret); |
97865538 JM |
1407 | if (ret < 0) { |
1408 | wpa_printf(MSG_ERROR, "nl80211: Could not add multicast " | |
1409 | "membership for scan events: %d (%s)", | |
1410 | ret, strerror(-ret)); | |
d6c9aab8 | 1411 | goto err; |
97865538 | 1412 | } |
c2a04078 | 1413 | |
d6c9aab8 | 1414 | ret = nl_get_multicast_id(global, "nl80211", "mlme"); |
c2a04078 | 1415 | if (ret >= 0) |
481234cf | 1416 | ret = nl_socket_add_membership(global->nl_event, ret); |
c2a04078 JM |
1417 | if (ret < 0) { |
1418 | wpa_printf(MSG_ERROR, "nl80211: Could not add multicast " | |
1419 | "membership for mlme events: %d (%s)", | |
1420 | ret, strerror(-ret)); | |
d6c9aab8 | 1421 | goto err; |
c2a04078 | 1422 | } |
c2a04078 | 1423 | |
d6c9aab8 | 1424 | ret = nl_get_multicast_id(global, "nl80211", "regulatory"); |
33c5deb8 | 1425 | if (ret >= 0) |
481234cf | 1426 | ret = nl_socket_add_membership(global->nl_event, ret); |
33c5deb8 JM |
1427 | if (ret < 0) { |
1428 | wpa_printf(MSG_DEBUG, "nl80211: Could not add multicast " | |
1429 | "membership for regulatory events: %d (%s)", | |
1430 | ret, strerror(-ret)); | |
1431 | /* Continue without regulatory events */ | |
1432 | } | |
1433 | ||
17b79e65 JM |
1434 | ret = nl_get_multicast_id(global, "nl80211", "vendor"); |
1435 | if (ret >= 0) | |
1436 | ret = nl_socket_add_membership(global->nl_event, ret); | |
1437 | if (ret < 0) { | |
1438 | wpa_printf(MSG_DEBUG, "nl80211: Could not add multicast " | |
1439 | "membership for vendor events: %d (%s)", | |
1440 | ret, strerror(-ret)); | |
1441 | /* Continue without vendor events */ | |
1442 | } | |
1443 | ||
d6c9aab8 JB |
1444 | nl_cb_set(global->nl_cb, NL_CB_SEQ_CHECK, NL_CB_CUSTOM, |
1445 | no_seq_check, NULL); | |
1446 | nl_cb_set(global->nl_cb, NL_CB_VALID, NL_CB_CUSTOM, | |
1447 | process_global_event, global); | |
1448 | ||
5f65e9f7 JB |
1449 | nl80211_register_eloop_read(&global->nl_event, |
1450 | wpa_driver_nl80211_event_receive, | |
1451 | global->nl_cb); | |
d6c9aab8 JB |
1452 | |
1453 | return 0; | |
1454 | ||
1455 | err: | |
1456 | nl_destroy_handles(&global->nl_event); | |
1457 | nl_destroy_handles(&global->nl); | |
1458 | nl_cb_put(global->nl_cb); | |
671a5039 | 1459 | global->nl_cb = NULL; |
d6c9aab8 JB |
1460 | return -1; |
1461 | } | |
1462 | ||
1463 | ||
8401a6b0 JM |
1464 | static void wpa_driver_nl80211_rfkill_blocked(void *ctx) |
1465 | { | |
8401a6b0 | 1466 | wpa_printf(MSG_DEBUG, "nl80211: RFKILL blocked"); |
a63063b4 JM |
1467 | /* |
1468 | * This may be for any interface; use ifdown event to disable | |
1469 | * interface. | |
1470 | */ | |
8401a6b0 JM |
1471 | } |
1472 | ||
1473 | ||
1474 | static void wpa_driver_nl80211_rfkill_unblocked(void *ctx) | |
1475 | { | |
1476 | struct wpa_driver_nl80211_data *drv = ctx; | |
1477 | wpa_printf(MSG_DEBUG, "nl80211: RFKILL unblocked"); | |
834ee56f | 1478 | if (i802_set_iface_flags(drv->first_bss, 1)) { |
8401a6b0 JM |
1479 | wpa_printf(MSG_DEBUG, "nl80211: Could not set interface UP " |
1480 | "after rfkill unblock"); | |
1481 | return; | |
1482 | } | |
a63063b4 | 1483 | /* rtnetlink ifup handler will report interface as enabled */ |
8401a6b0 JM |
1484 | } |
1485 | ||
1486 | ||
32ab4855 JB |
1487 | static void wpa_driver_nl80211_handle_eapol_tx_status(int sock, |
1488 | void *eloop_ctx, | |
1489 | void *handle) | |
1490 | { | |
1491 | struct wpa_driver_nl80211_data *drv = eloop_ctx; | |
1492 | u8 data[2048]; | |
1493 | struct msghdr msg; | |
1494 | struct iovec entry; | |
cad0f50e | 1495 | u8 control[512]; |
32ab4855 JB |
1496 | struct cmsghdr *cmsg; |
1497 | int res, found_ee = 0, found_wifi = 0, acked = 0; | |
1498 | union wpa_event_data event; | |
1499 | ||
1500 | memset(&msg, 0, sizeof(msg)); | |
1501 | msg.msg_iov = &entry; | |
1502 | msg.msg_iovlen = 1; | |
1503 | entry.iov_base = data; | |
1504 | entry.iov_len = sizeof(data); | |
1505 | msg.msg_control = &control; | |
1506 | msg.msg_controllen = sizeof(control); | |
1507 | ||
1508 | res = recvmsg(sock, &msg, MSG_ERRQUEUE); | |
1509 | /* if error or not fitting 802.3 header, return */ | |
1510 | if (res < 14) | |
1511 | return; | |
1512 | ||
1513 | for (cmsg = CMSG_FIRSTHDR(&msg); cmsg; cmsg = CMSG_NXTHDR(&msg, cmsg)) | |
1514 | { | |
1515 | if (cmsg->cmsg_level == SOL_SOCKET && | |
1516 | cmsg->cmsg_type == SCM_WIFI_STATUS) { | |
1517 | int *ack; | |
1518 | ||
1519 | found_wifi = 1; | |
1520 | ack = (void *)CMSG_DATA(cmsg); | |
1521 | acked = *ack; | |
1522 | } | |
1523 | ||
1524 | if (cmsg->cmsg_level == SOL_PACKET && | |
1525 | cmsg->cmsg_type == PACKET_TX_TIMESTAMP) { | |
1526 | struct sock_extended_err *err = | |
1527 | (struct sock_extended_err *)CMSG_DATA(cmsg); | |
1528 | ||
1529 | if (err->ee_origin == SO_EE_ORIGIN_TXSTATUS) | |
1530 | found_ee = 1; | |
1531 | } | |
1532 | } | |
1533 | ||
1534 | if (!found_ee || !found_wifi) | |
1535 | return; | |
1536 | ||
1537 | memset(&event, 0, sizeof(event)); | |
1538 | event.eapol_tx_status.dst = data; | |
1539 | event.eapol_tx_status.data = data + 14; | |
1540 | event.eapol_tx_status.data_len = res - 14; | |
1541 | event.eapol_tx_status.ack = acked; | |
1542 | wpa_supplicant_event(drv->ctx, EVENT_EAPOL_TX_STATUS, &event); | |
1543 | } | |
1544 | ||
1545 | ||
cc7a48d1 JB |
1546 | static int nl80211_init_bss(struct i802_bss *bss) |
1547 | { | |
1548 | bss->nl_cb = nl_cb_alloc(NL_CB_DEFAULT); | |
1549 | if (!bss->nl_cb) | |
1550 | return -1; | |
1551 | ||
1552 | nl_cb_set(bss->nl_cb, NL_CB_SEQ_CHECK, NL_CB_CUSTOM, | |
1553 | no_seq_check, NULL); | |
1554 | nl_cb_set(bss->nl_cb, NL_CB_VALID, NL_CB_CUSTOM, | |
1555 | process_bss_event, bss); | |
1556 | ||
1557 | return 0; | |
1558 | } | |
1559 | ||
1560 | ||
1561 | static void nl80211_destroy_bss(struct i802_bss *bss) | |
1562 | { | |
1563 | nl_cb_put(bss->nl_cb); | |
1564 | bss->nl_cb = NULL; | |
1565 | } | |
1566 | ||
1567 | ||
0d547d5f JM |
1568 | static void * wpa_driver_nl80211_drv_init(void *ctx, const char *ifname, |
1569 | void *global_priv, int hostapd, | |
0ecff8d7 JM |
1570 | const u8 *set_addr, |
1571 | const char *driver_params) | |
9fff9fdc | 1572 | { |
9fff9fdc | 1573 | struct wpa_driver_nl80211_data *drv; |
8401a6b0 | 1574 | struct rfkill_config *rcfg; |
a2e40bb6 | 1575 | struct i802_bss *bss; |
9fff9fdc | 1576 | |
a5c696ad JM |
1577 | if (global_priv == NULL) |
1578 | return NULL; | |
9fff9fdc JM |
1579 | drv = os_zalloc(sizeof(*drv)); |
1580 | if (drv == NULL) | |
1581 | return NULL; | |
f2ed8023 | 1582 | drv->global = global_priv; |
9fff9fdc | 1583 | drv->ctx = ctx; |
0d547d5f JM |
1584 | drv->hostapd = !!hostapd; |
1585 | drv->eapol_sock = -1; | |
64ae2447 JM |
1586 | |
1587 | /* | |
1588 | * There is no driver capability flag for this, so assume it is | |
1589 | * supported and disable this on first attempt to use if the driver | |
1590 | * rejects the command due to missing support. | |
1591 | */ | |
1592 | drv->set_rekey_offload = 1; | |
1593 | ||
0d547d5f JM |
1594 | drv->num_if_indices = sizeof(drv->default_if_indices) / sizeof(int); |
1595 | drv->if_indices = drv->default_if_indices; | |
834ee56f KP |
1596 | |
1597 | drv->first_bss = os_zalloc(sizeof(*drv->first_bss)); | |
1598 | if (!drv->first_bss) { | |
1599 | os_free(drv); | |
1600 | return NULL; | |
1601 | } | |
1602 | bss = drv->first_bss; | |
a2e40bb6 | 1603 | bss->drv = drv; |
a5e1eb20 SE |
1604 | bss->ctx = ctx; |
1605 | ||
a2e40bb6 | 1606 | os_strlcpy(bss->ifname, ifname, sizeof(bss->ifname)); |
9fff9fdc JM |
1607 | drv->monitor_ifidx = -1; |
1608 | drv->monitor_sock = -1; | |
d12dab4c | 1609 | drv->eapol_tx_sock = -1; |
b1f625e0 | 1610 | drv->ap_scan_as_station = NL80211_IFTYPE_UNSPECIFIED; |
9fff9fdc | 1611 | |
cc7a48d1 JB |
1612 | if (nl80211_init_bss(bss)) |
1613 | goto failed; | |
1614 | ||
8401a6b0 JM |
1615 | rcfg = os_zalloc(sizeof(*rcfg)); |
1616 | if (rcfg == NULL) | |
1617 | goto failed; | |
1618 | rcfg->ctx = drv; | |
1619 | os_strlcpy(rcfg->ifname, ifname, sizeof(rcfg->ifname)); | |
1620 | rcfg->blocked_cb = wpa_driver_nl80211_rfkill_blocked; | |
1621 | rcfg->unblocked_cb = wpa_driver_nl80211_rfkill_unblocked; | |
1622 | drv->rfkill = rfkill_init(rcfg); | |
52169389 | 1623 | if (drv->rfkill == NULL) { |
8401a6b0 | 1624 | wpa_printf(MSG_DEBUG, "nl80211: RFKILL status not available"); |
52169389 JM |
1625 | os_free(rcfg); |
1626 | } | |
8401a6b0 | 1627 | |
146fa9b3 JM |
1628 | if (linux_iface_up(drv->global->ioctl_sock, ifname) > 0) |
1629 | drv->start_iface_up = 1; | |
1630 | ||
0ecff8d7 | 1631 | if (wpa_driver_nl80211_finish_drv_init(drv, set_addr, 1, driver_params)) |
bbaf0837 | 1632 | goto failed; |
7524cfb1 | 1633 | |
d12dab4c | 1634 | drv->eapol_tx_sock = socket(PF_PACKET, SOCK_DGRAM, 0); |
32ab4855 JB |
1635 | if (drv->eapol_tx_sock < 0) |
1636 | goto failed; | |
1637 | ||
1638 | if (drv->data_tx_status) { | |
1639 | int enabled = 1; | |
1640 | ||
1641 | if (setsockopt(drv->eapol_tx_sock, SOL_SOCKET, SO_WIFI_STATUS, | |
1642 | &enabled, sizeof(enabled)) < 0) { | |
1643 | wpa_printf(MSG_DEBUG, | |
1644 | "nl80211: wifi status sockopt failed\n"); | |
1645 | drv->data_tx_status = 0; | |
a11241fa JB |
1646 | if (!drv->use_monitor) |
1647 | drv->capa.flags &= | |
1648 | ~WPA_DRIVER_FLAGS_EAPOL_TX_STATUS; | |
32ab4855 JB |
1649 | } else { |
1650 | eloop_register_read_sock(drv->eapol_tx_sock, | |
1651 | wpa_driver_nl80211_handle_eapol_tx_status, | |
1652 | drv, NULL); | |
1653 | } | |
1654 | } | |
f10bfc9a | 1655 | |
dac12351 | 1656 | if (drv->global) { |
c4bb8817 | 1657 | dl_list_add(&drv->global->interfaces, &drv->list); |
dac12351 BG |
1658 | drv->in_interface_list = 1; |
1659 | } | |
c4bb8817 | 1660 | |
a2e40bb6 | 1661 | return bss; |
7524cfb1 | 1662 | |
bbaf0837 | 1663 | failed: |
dac12351 | 1664 | wpa_driver_nl80211_deinit(bss); |
7524cfb1 JM |
1665 | return NULL; |
1666 | } | |
1667 | ||
1668 | ||
0d547d5f JM |
1669 | /** |
1670 | * wpa_driver_nl80211_init - Initialize nl80211 driver interface | |
1671 | * @ctx: context to be used when calling wpa_supplicant functions, | |
1672 | * e.g., wpa_supplicant_event() | |
1673 | * @ifname: interface name, e.g., wlan0 | |
1674 | * @global_priv: private driver global data from global_init() | |
1675 | * Returns: Pointer to private data, %NULL on failure | |
1676 | */ | |
1677 | static void * wpa_driver_nl80211_init(void *ctx, const char *ifname, | |
1678 | void *global_priv) | |
1679 | { | |
0ecff8d7 JM |
1680 | return wpa_driver_nl80211_drv_init(ctx, ifname, global_priv, 0, NULL, |
1681 | NULL); | |
0d547d5f JM |
1682 | } |
1683 | ||
1684 | ||
a11241fa | 1685 | static int nl80211_register_frame(struct i802_bss *bss, |
5582a5d1 | 1686 | struct nl_handle *nl_handle, |
bd94971e | 1687 | u16 type, const u8 *match, size_t match_len) |
58f6fbe0 | 1688 | { |
a11241fa | 1689 | struct wpa_driver_nl80211_data *drv = bss->drv; |
58f6fbe0 | 1690 | struct nl_msg *msg; |
a862e4a3 | 1691 | int ret; |
880de885 | 1692 | char buf[30]; |
58f6fbe0 | 1693 | |
880de885 JM |
1694 | buf[0] = '\0'; |
1695 | wpa_snprintf_hex(buf, sizeof(buf), match, match_len); | |
dedfa440 PF |
1696 | wpa_printf(MSG_DEBUG, "nl80211: Register frame type=0x%x (%s) nl_handle=%p match=%s", |
1697 | type, fc2str(type), nl_handle, buf); | |
36488c05 | 1698 | |
56f77852 | 1699 | if (!(msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_REGISTER_ACTION)) || |
a862e4a3 JM |
1700 | nla_put_u16(msg, NL80211_ATTR_FRAME_TYPE, type) || |
1701 | nla_put(msg, NL80211_ATTR_FRAME_MATCH, match_len, match)) { | |
1702 | nlmsg_free(msg); | |
1703 | return -1; | |
1704 | } | |
58f6fbe0 | 1705 | |
d6c9aab8 | 1706 | ret = send_and_recv(drv->global, nl_handle, msg, NULL, NULL); |
58f6fbe0 | 1707 | if (ret) { |
5582a5d1 JB |
1708 | wpa_printf(MSG_DEBUG, "nl80211: Register frame command " |
1709 | "failed (type=%u): ret=%d (%s)", | |
1710 | type, ret, strerror(-ret)); | |
1711 | wpa_hexdump(MSG_DEBUG, "nl80211: Register frame match", | |
58f6fbe0 | 1712 | match, match_len); |
58f6fbe0 | 1713 | } |
58f6fbe0 JM |
1714 | return ret; |
1715 | } | |
1716 | ||
1717 | ||
a11241fa JB |
1718 | static int nl80211_alloc_mgmt_handle(struct i802_bss *bss) |
1719 | { | |
481234cf | 1720 | if (bss->nl_mgmt) { |
a11241fa | 1721 | wpa_printf(MSG_DEBUG, "nl80211: Mgmt reporting " |
36488c05 | 1722 | "already on! (nl_mgmt=%p)", bss->nl_mgmt); |
a11241fa JB |
1723 | return -1; |
1724 | } | |
1725 | ||
ce20a370 | 1726 | bss->nl_mgmt = nl_create_handle(bss->nl_cb, "mgmt"); |
481234cf | 1727 | if (bss->nl_mgmt == NULL) |
a11241fa JB |
1728 | return -1; |
1729 | ||
a11241fa JB |
1730 | return 0; |
1731 | } | |
1732 | ||
1733 | ||
5f65e9f7 JB |
1734 | static void nl80211_mgmt_handle_register_eloop(struct i802_bss *bss) |
1735 | { | |
1736 | nl80211_register_eloop_read(&bss->nl_mgmt, | |
1737 | wpa_driver_nl80211_event_receive, | |
1738 | bss->nl_cb); | |
1739 | } | |
1740 | ||
1741 | ||
a11241fa | 1742 | static int nl80211_register_action_frame(struct i802_bss *bss, |
bd94971e JB |
1743 | const u8 *match, size_t match_len) |
1744 | { | |
1745 | u16 type = (WLAN_FC_TYPE_MGMT << 2) | (WLAN_FC_STYPE_ACTION << 4); | |
481234cf | 1746 | return nl80211_register_frame(bss, bss->nl_mgmt, |
5582a5d1 | 1747 | type, match, match_len); |
bd94971e JB |
1748 | } |
1749 | ||
1750 | ||
a11241fa | 1751 | static int nl80211_mgmt_subscribe_non_ap(struct i802_bss *bss) |
58f6fbe0 | 1752 | { |
a11241fa | 1753 | struct wpa_driver_nl80211_data *drv = bss->drv; |
6f06766e | 1754 | int ret = 0; |
a11241fa JB |
1755 | |
1756 | if (nl80211_alloc_mgmt_handle(bss)) | |
1757 | return -1; | |
36488c05 JM |
1758 | wpa_printf(MSG_DEBUG, "nl80211: Subscribe to mgmt frames with non-AP " |
1759 | "handle %p", bss->nl_mgmt); | |
a11241fa | 1760 | |
e8d1168b JB |
1761 | if (drv->nlmode == NL80211_IFTYPE_ADHOC) { |
1762 | u16 type = (WLAN_FC_TYPE_MGMT << 2) | (WLAN_FC_STYPE_AUTH << 4); | |
1763 | ||
1764 | /* register for any AUTH message */ | |
1765 | nl80211_register_frame(bss, bss->nl_mgmt, type, NULL, 0); | |
1766 | } | |
1767 | ||
56f5af48 JM |
1768 | #ifdef CONFIG_INTERWORKING |
1769 | /* QoS Map Configure */ | |
1770 | if (nl80211_register_action_frame(bss, (u8 *) "\x01\x04", 2) < 0) | |
6f06766e | 1771 | ret = -1; |
56f5af48 | 1772 | #endif /* CONFIG_INTERWORKING */ |
4fe9fa0d | 1773 | #if defined(CONFIG_P2P) || defined(CONFIG_INTERWORKING) |
046b26a2 | 1774 | /* GAS Initial Request */ |
a11241fa | 1775 | if (nl80211_register_action_frame(bss, (u8 *) "\x04\x0a", 2) < 0) |
6f06766e | 1776 | ret = -1; |
046b26a2 | 1777 | /* GAS Initial Response */ |
a11241fa | 1778 | if (nl80211_register_action_frame(bss, (u8 *) "\x04\x0b", 2) < 0) |
6f06766e | 1779 | ret = -1; |
18708aad | 1780 | /* GAS Comeback Request */ |
a11241fa | 1781 | if (nl80211_register_action_frame(bss, (u8 *) "\x04\x0c", 2) < 0) |
6f06766e | 1782 | ret = -1; |
18708aad | 1783 | /* GAS Comeback Response */ |
a11241fa | 1784 | if (nl80211_register_action_frame(bss, (u8 *) "\x04\x0d", 2) < 0) |
6f06766e | 1785 | ret = -1; |
c5a64e2d JM |
1786 | /* Protected GAS Initial Request */ |
1787 | if (nl80211_register_action_frame(bss, (u8 *) "\x09\x0a", 2) < 0) | |
1788 | ret = -1; | |
1789 | /* Protected GAS Initial Response */ | |
1790 | if (nl80211_register_action_frame(bss, (u8 *) "\x09\x0b", 2) < 0) | |
1791 | ret = -1; | |
1792 | /* Protected GAS Comeback Request */ | |
1793 | if (nl80211_register_action_frame(bss, (u8 *) "\x09\x0c", 2) < 0) | |
1794 | ret = -1; | |
1795 | /* Protected GAS Comeback Response */ | |
1796 | if (nl80211_register_action_frame(bss, (u8 *) "\x09\x0d", 2) < 0) | |
1797 | ret = -1; | |
4fe9fa0d JM |
1798 | #endif /* CONFIG_P2P || CONFIG_INTERWORKING */ |
1799 | #ifdef CONFIG_P2P | |
046b26a2 | 1800 | /* P2P Public Action */ |
a11241fa | 1801 | if (nl80211_register_action_frame(bss, |
046b26a2 JM |
1802 | (u8 *) "\x04\x09\x50\x6f\x9a\x09", |
1803 | 6) < 0) | |
6f06766e | 1804 | ret = -1; |
046b26a2 | 1805 | /* P2P Action */ |
a11241fa | 1806 | if (nl80211_register_action_frame(bss, |
046b26a2 JM |
1807 | (u8 *) "\x7f\x50\x6f\x9a\x09", |
1808 | 5) < 0) | |
6f06766e | 1809 | ret = -1; |
046b26a2 | 1810 | #endif /* CONFIG_P2P */ |
7d878ca7 JM |
1811 | #ifdef CONFIG_IEEE80211W |
1812 | /* SA Query Response */ | |
a11241fa | 1813 | if (nl80211_register_action_frame(bss, (u8 *) "\x08\x01", 2) < 0) |
6f06766e | 1814 | ret = -1; |
7d878ca7 | 1815 | #endif /* CONFIG_IEEE80211W */ |
35287637 AN |
1816 | #ifdef CONFIG_TDLS |
1817 | if ((drv->capa.flags & WPA_DRIVER_FLAGS_TDLS_SUPPORT)) { | |
1818 | /* TDLS Discovery Response */ | |
aa543c0c | 1819 | if (nl80211_register_action_frame(bss, (u8 *) "\x04\x0e", 2) < |
35287637 | 1820 | 0) |
6f06766e | 1821 | ret = -1; |
35287637 AN |
1822 | } |
1823 | #endif /* CONFIG_TDLS */ | |
046b26a2 | 1824 | |
7b90c16a | 1825 | /* FT Action frames */ |
a11241fa | 1826 | if (nl80211_register_action_frame(bss, (u8 *) "\x06", 1) < 0) |
6f06766e | 1827 | ret = -1; |
7b90c16a JM |
1828 | else |
1829 | drv->capa.key_mgmt |= WPA_DRIVER_CAPA_KEY_MGMT_FT | | |
1830 | WPA_DRIVER_CAPA_KEY_MGMT_FT_PSK; | |
1831 | ||
71269b37 | 1832 | /* WNM - BSS Transition Management Request */ |
a11241fa | 1833 | if (nl80211_register_action_frame(bss, (u8 *) "\x0a\x07", 2) < 0) |
6f06766e | 1834 | ret = -1; |
bd896433 JM |
1835 | /* WNM-Sleep Mode Response */ |
1836 | if (nl80211_register_action_frame(bss, (u8 *) "\x0a\x11", 2) < 0) | |
6f06766e | 1837 | ret = -1; |
a11241fa | 1838 | |
95a3ea94 JM |
1839 | #ifdef CONFIG_HS20 |
1840 | /* WNM-Notification */ | |
1841 | if (nl80211_register_action_frame(bss, (u8 *) "\x0a\x1a", 2) < 0) | |
3ee18569 | 1842 | ret = -1; |
95a3ea94 JM |
1843 | #endif /* CONFIG_HS20 */ |
1844 | ||
dfa87878 MB |
1845 | /* WMM-AC ADDTS Response */ |
1846 | if (nl80211_register_action_frame(bss, (u8 *) "\x11\x01", 2) < 0) | |
730a0d16 | 1847 | ret = -1; |
dfa87878 MB |
1848 | |
1849 | /* WMM-AC DELTS */ | |
1850 | if (nl80211_register_action_frame(bss, (u8 *) "\x11\x02", 2) < 0) | |
730a0d16 | 1851 | ret = -1; |
dfa87878 | 1852 | |
2526ccd9 AK |
1853 | /* Radio Measurement - Neighbor Report Response */ |
1854 | if (nl80211_register_action_frame(bss, (u8 *) "\x05\x05", 2) < 0) | |
1855 | ret = -1; | |
1856 | ||
7dc03388 AO |
1857 | /* Radio Measurement - Link Measurement Request */ |
1858 | if ((drv->capa.rrm_flags & WPA_DRIVER_FLAGS_TX_POWER_INSERTION) && | |
1859 | (nl80211_register_action_frame(bss, (u8 *) "\x05\x02", 2) < 0)) | |
1860 | ret = -1; | |
1861 | ||
5f65e9f7 JB |
1862 | nl80211_mgmt_handle_register_eloop(bss); |
1863 | ||
6f06766e | 1864 | return ret; |
a11241fa JB |
1865 | } |
1866 | ||
1867 | ||
afb0550a BC |
1868 | static int nl80211_mgmt_subscribe_mesh(struct i802_bss *bss) |
1869 | { | |
1870 | int ret = 0; | |
1871 | ||
1872 | if (nl80211_alloc_mgmt_handle(bss)) | |
1873 | return -1; | |
1874 | ||
1875 | wpa_printf(MSG_DEBUG, | |
1876 | "nl80211: Subscribe to mgmt frames with mesh handle %p", | |
1877 | bss->nl_mgmt); | |
1878 | ||
1879 | /* Auth frames for mesh SAE */ | |
1880 | if (nl80211_register_frame(bss, bss->nl_mgmt, | |
1881 | (WLAN_FC_TYPE_MGMT << 2) | | |
1882 | (WLAN_FC_STYPE_AUTH << 4), | |
1883 | NULL, 0) < 0) | |
1884 | ret = -1; | |
1885 | ||
1886 | /* Mesh peering open */ | |
1887 | if (nl80211_register_action_frame(bss, (u8 *) "\x0f\x01", 2) < 0) | |
1888 | ret = -1; | |
1889 | /* Mesh peering confirm */ | |
1890 | if (nl80211_register_action_frame(bss, (u8 *) "\x0f\x02", 2) < 0) | |
1891 | ret = -1; | |
1892 | /* Mesh peering close */ | |
1893 | if (nl80211_register_action_frame(bss, (u8 *) "\x0f\x03", 2) < 0) | |
1894 | ret = -1; | |
1895 | ||
1896 | nl80211_mgmt_handle_register_eloop(bss); | |
1897 | ||
1898 | return ret; | |
1899 | } | |
1900 | ||
1901 | ||
02bb32c3 JB |
1902 | static int nl80211_register_spurious_class3(struct i802_bss *bss) |
1903 | { | |
02bb32c3 | 1904 | struct nl_msg *msg; |
a862e4a3 | 1905 | int ret; |
02bb32c3 | 1906 | |
13f83980 JM |
1907 | msg = nl80211_bss_msg(bss, 0, NL80211_CMD_UNEXPECTED_FRAME); |
1908 | ret = send_and_recv(bss->drv->global, bss->nl_mgmt, msg, NULL, NULL); | |
02bb32c3 JB |
1909 | if (ret) { |
1910 | wpa_printf(MSG_DEBUG, "nl80211: Register spurious class3 " | |
1911 | "failed: ret=%d (%s)", | |
1912 | ret, strerror(-ret)); | |
02bb32c3 | 1913 | } |
02bb32c3 JB |
1914 | return ret; |
1915 | } | |
1916 | ||
1917 | ||
a11241fa JB |
1918 | static int nl80211_mgmt_subscribe_ap(struct i802_bss *bss) |
1919 | { | |
1920 | static const int stypes[] = { | |
1921 | WLAN_FC_STYPE_AUTH, | |
1922 | WLAN_FC_STYPE_ASSOC_REQ, | |
1923 | WLAN_FC_STYPE_REASSOC_REQ, | |
1924 | WLAN_FC_STYPE_DISASSOC, | |
1925 | WLAN_FC_STYPE_DEAUTH, | |
1926 | WLAN_FC_STYPE_ACTION, | |
1927 | WLAN_FC_STYPE_PROBE_REQ, | |
1928 | /* Beacon doesn't work as mac80211 doesn't currently allow | |
1929 | * it, but it wouldn't really be the right thing anyway as | |
1930 | * it isn't per interface ... maybe just dump the scan | |
1931 | * results periodically for OLBC? | |
1932 | */ | |
0e80ea2c | 1933 | /* WLAN_FC_STYPE_BEACON, */ |
a11241fa JB |
1934 | }; |
1935 | unsigned int i; | |
1936 | ||
1937 | if (nl80211_alloc_mgmt_handle(bss)) | |
71269b37 | 1938 | return -1; |
36488c05 JM |
1939 | wpa_printf(MSG_DEBUG, "nl80211: Subscribe to mgmt frames with AP " |
1940 | "handle %p", bss->nl_mgmt); | |
71269b37 | 1941 | |
e7ecab4a | 1942 | for (i = 0; i < ARRAY_SIZE(stypes); i++) { |
481234cf | 1943 | if (nl80211_register_frame(bss, bss->nl_mgmt, |
a11241fa JB |
1944 | (WLAN_FC_TYPE_MGMT << 2) | |
1945 | (stypes[i] << 4), | |
1946 | NULL, 0) < 0) { | |
1947 | goto out_err; | |
1948 | } | |
1949 | } | |
1950 | ||
02bb32c3 JB |
1951 | if (nl80211_register_spurious_class3(bss)) |
1952 | goto out_err; | |
1953 | ||
e32ad281 JB |
1954 | if (nl80211_get_wiphy_data_ap(bss) == NULL) |
1955 | goto out_err; | |
1956 | ||
5f65e9f7 | 1957 | nl80211_mgmt_handle_register_eloop(bss); |
58f6fbe0 | 1958 | return 0; |
a11241fa JB |
1959 | |
1960 | out_err: | |
a11241fa JB |
1961 | nl_destroy_handles(&bss->nl_mgmt); |
1962 | return -1; | |
1963 | } | |
1964 | ||
1965 | ||
a6cc0602 JM |
1966 | static int nl80211_mgmt_subscribe_ap_dev_sme(struct i802_bss *bss) |
1967 | { | |
1968 | if (nl80211_alloc_mgmt_handle(bss)) | |
1969 | return -1; | |
1970 | wpa_printf(MSG_DEBUG, "nl80211: Subscribe to mgmt frames with AP " | |
1971 | "handle %p (device SME)", bss->nl_mgmt); | |
1972 | ||
1973 | if (nl80211_register_frame(bss, bss->nl_mgmt, | |
1974 | (WLAN_FC_TYPE_MGMT << 2) | | |
1975 | (WLAN_FC_STYPE_ACTION << 4), | |
1976 | NULL, 0) < 0) | |
1977 | goto out_err; | |
1978 | ||
5f65e9f7 | 1979 | nl80211_mgmt_handle_register_eloop(bss); |
a6cc0602 JM |
1980 | return 0; |
1981 | ||
1982 | out_err: | |
a6cc0602 JM |
1983 | nl_destroy_handles(&bss->nl_mgmt); |
1984 | return -1; | |
1985 | } | |
1986 | ||
1987 | ||
36488c05 | 1988 | static void nl80211_mgmt_unsubscribe(struct i802_bss *bss, const char *reason) |
a11241fa | 1989 | { |
481234cf | 1990 | if (bss->nl_mgmt == NULL) |
a11241fa | 1991 | return; |
36488c05 JM |
1992 | wpa_printf(MSG_DEBUG, "nl80211: Unsubscribe mgmt frames handle %p " |
1993 | "(%s)", bss->nl_mgmt, reason); | |
5f65e9f7 | 1994 | nl80211_destroy_eloop_handle(&bss->nl_mgmt); |
e32ad281 JB |
1995 | |
1996 | nl80211_put_wiphy_data_ap(bss); | |
58f6fbe0 JM |
1997 | } |
1998 | ||
1999 | ||
8401a6b0 JM |
2000 | static void wpa_driver_nl80211_send_rfkill(void *eloop_ctx, void *timeout_ctx) |
2001 | { | |
2002 | wpa_supplicant_event(timeout_ctx, EVENT_INTERFACE_DISABLED, NULL); | |
2003 | } | |
2004 | ||
2005 | ||
eb4582f2 AS |
2006 | static void nl80211_del_p2pdev(struct i802_bss *bss) |
2007 | { | |
eb4582f2 AS |
2008 | struct nl_msg *msg; |
2009 | int ret; | |
2010 | ||
a3249fdf JM |
2011 | msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_DEL_INTERFACE); |
2012 | ret = send_and_recv_msgs(bss->drv, msg, NULL, NULL); | |
eb4582f2 AS |
2013 | |
2014 | wpa_printf(MSG_DEBUG, "nl80211: Delete P2P Device %s (0x%llx): %s", | |
2015 | bss->ifname, (long long unsigned int) bss->wdev_id, | |
6cb4f11d | 2016 | strerror(-ret)); |
eb4582f2 AS |
2017 | } |
2018 | ||
2019 | ||
eb4582f2 | 2020 | static int nl80211_set_p2pdev(struct i802_bss *bss, int start) |
f632e483 | 2021 | { |
f632e483 | 2022 | struct nl_msg *msg; |
a862e4a3 | 2023 | int ret; |
f632e483 | 2024 | |
a3249fdf JM |
2025 | msg = nl80211_cmd_msg(bss, 0, start ? NL80211_CMD_START_P2P_DEVICE : |
2026 | NL80211_CMD_STOP_P2P_DEVICE); | |
2027 | ret = send_and_recv_msgs(bss->drv, msg, NULL, NULL); | |
f632e483 | 2028 | |
eb4582f2 AS |
2029 | wpa_printf(MSG_DEBUG, "nl80211: %s P2P Device %s (0x%llx): %s", |
2030 | start ? "Start" : "Stop", | |
2031 | bss->ifname, (long long unsigned int) bss->wdev_id, | |
6cb4f11d | 2032 | strerror(-ret)); |
f632e483 AS |
2033 | return ret; |
2034 | } | |
f632e483 AS |
2035 | |
2036 | ||
91724d6f AS |
2037 | static int i802_set_iface_flags(struct i802_bss *bss, int up) |
2038 | { | |
2039 | enum nl80211_iftype nlmode; | |
2040 | ||
2041 | nlmode = nl80211_get_ifmode(bss); | |
2042 | if (nlmode != NL80211_IFTYPE_P2P_DEVICE) { | |
2043 | return linux_set_iface_flags(bss->drv->global->ioctl_sock, | |
2044 | bss->ifname, up); | |
2045 | } | |
2046 | ||
2047 | /* P2P Device has start/stop which is equivalent */ | |
2048 | return nl80211_set_p2pdev(bss, up); | |
2049 | } | |
2050 | ||
2051 | ||
362f781e | 2052 | static int |
0d547d5f | 2053 | wpa_driver_nl80211_finish_drv_init(struct wpa_driver_nl80211_data *drv, |
0ecff8d7 JM |
2054 | const u8 *set_addr, int first, |
2055 | const char *driver_params) | |
7524cfb1 | 2056 | { |
834ee56f | 2057 | struct i802_bss *bss = drv->first_bss; |
8401a6b0 | 2058 | int send_rfkill_event = 0; |
0d547d5f | 2059 | enum nl80211_iftype nlmode; |
a2e40bb6 FF |
2060 | |
2061 | drv->ifindex = if_nametoindex(bss->ifname); | |
f632e483 AS |
2062 | bss->ifindex = drv->ifindex; |
2063 | bss->wdev_id = drv->global->if_add_wdevid; | |
2064 | bss->wdev_id_set = drv->global->if_add_wdevid_set; | |
2065 | ||
60b13c20 IP |
2066 | bss->if_dynamic = drv->ifindex == drv->global->if_add_ifindex; |
2067 | bss->if_dynamic = bss->if_dynamic || drv->global->if_add_wdevid_set; | |
f632e483 AS |
2068 | drv->global->if_add_wdevid_set = 0; |
2069 | ||
bf144cf6 AP |
2070 | if (!bss->if_dynamic && nl80211_get_ifmode(bss) == NL80211_IFTYPE_AP) |
2071 | bss->static_ap = 1; | |
2072 | ||
f632e483 AS |
2073 | if (wpa_driver_nl80211_capa(drv)) |
2074 | return -1; | |
a87c9d96 | 2075 | |
0ecff8d7 JM |
2076 | if (driver_params && nl80211_set_param(bss, driver_params) < 0) |
2077 | return -1; | |
2078 | ||
5fbcb45d AS |
2079 | wpa_printf(MSG_DEBUG, "nl80211: interface %s in phy %s", |
2080 | bss->ifname, drv->phyname); | |
2081 | ||
0d547d5f JM |
2082 | if (set_addr && |
2083 | (linux_set_iface_flags(drv->global->ioctl_sock, bss->ifname, 0) || | |
2084 | linux_set_ifhwaddr(drv->global->ioctl_sock, bss->ifname, | |
2085 | set_addr))) | |
2086 | return -1; | |
2087 | ||
49b4b205 JM |
2088 | if (first && nl80211_get_ifmode(bss) == NL80211_IFTYPE_AP) |
2089 | drv->start_mode_ap = 1; | |
2090 | ||
bf144cf6 | 2091 | if (drv->hostapd || bss->static_ap) |
0d547d5f JM |
2092 | nlmode = NL80211_IFTYPE_AP; |
2093 | else if (bss->if_dynamic) | |
8e12685c | 2094 | nlmode = nl80211_get_ifmode(bss); |
0d547d5f JM |
2095 | else |
2096 | nlmode = NL80211_IFTYPE_STATION; | |
f632e483 | 2097 | |
8e12685c | 2098 | if (wpa_driver_nl80211_set_mode(bss, nlmode) < 0) { |
0d547d5f | 2099 | wpa_printf(MSG_ERROR, "nl80211: Could not configure driver mode"); |
8e12685c | 2100 | return -1; |
a87c9d96 JM |
2101 | } |
2102 | ||
8c06db70 | 2103 | if (nlmode == NL80211_IFTYPE_P2P_DEVICE) |
597b94f5 | 2104 | nl80211_get_macaddr(bss); |
f632e483 | 2105 | |
8c06db70 MB |
2106 | if (!rfkill_is_blocked(drv->rfkill)) { |
2107 | int ret = i802_set_iface_flags(bss, 1); | |
2108 | if (ret) { | |
8401a6b0 JM |
2109 | wpa_printf(MSG_ERROR, "nl80211: Could not set " |
2110 | "interface '%s' UP", bss->ifname); | |
8c06db70 | 2111 | return ret; |
8401a6b0 | 2112 | } |
8c06db70 MB |
2113 | if (nlmode == NL80211_IFTYPE_P2P_DEVICE) |
2114 | return ret; | |
2115 | } else { | |
2116 | wpa_printf(MSG_DEBUG, "nl80211: Could not yet enable " | |
2117 | "interface '%s' due to rfkill", bss->ifname); | |
2118 | if (nlmode == NL80211_IFTYPE_P2P_DEVICE) | |
2119 | return 0; | |
2120 | drv->if_disabled = 1; | |
2121 | send_rfkill_event = 1; | |
362f781e | 2122 | } |
3f5285e8 | 2123 | |
0d547d5f JM |
2124 | if (!drv->hostapd) |
2125 | netlink_send_oper_ifla(drv->global->netlink, drv->ifindex, | |
2126 | 1, IF_OPER_DORMANT); | |
362f781e | 2127 | |
c81eff1a | 2128 | if (linux_get_ifhwaddr(drv->global->ioctl_sock, bss->ifname, |
341eebee | 2129 | bss->addr)) |
2136f480 | 2130 | return -1; |
fee354c7 | 2131 | os_memcpy(drv->perm_addr, bss->addr, ETH_ALEN); |
f2ed8023 | 2132 | |
8401a6b0 JM |
2133 | if (send_rfkill_event) { |
2134 | eloop_register_timeout(0, 0, wpa_driver_nl80211_send_rfkill, | |
2135 | drv, drv->ctx); | |
2136 | } | |
2137 | ||
362f781e | 2138 | return 0; |
3f5285e8 JM |
2139 | } |
2140 | ||
2141 | ||
8a27af5c JM |
2142 | static int wpa_driver_nl80211_del_beacon(struct wpa_driver_nl80211_data *drv) |
2143 | { | |
2144 | struct nl_msg *msg; | |
2145 | ||
08e55ebb JM |
2146 | wpa_printf(MSG_DEBUG, "nl80211: Remove beacon (ifindex=%d)", |
2147 | drv->ifindex); | |
9725b784 | 2148 | msg = nl80211_drv_msg(drv, 0, NL80211_CMD_DEL_BEACON); |
8a27af5c | 2149 | return send_and_recv_msgs(drv, msg, NULL, NULL); |
8a27af5c | 2150 | } |
8a27af5c JM |
2151 | |
2152 | ||
3f5285e8 | 2153 | /** |
7e5ba1b9 | 2154 | * wpa_driver_nl80211_deinit - Deinitialize nl80211 driver interface |
9ebce9c5 | 2155 | * @bss: Pointer to private nl80211 data from wpa_driver_nl80211_init() |
3f5285e8 JM |
2156 | * |
2157 | * Shut down driver interface and processing of driver events. Free | |
2158 | * private data buffer if one was allocated in wpa_driver_nl80211_init(). | |
2159 | */ | |
9ebce9c5 | 2160 | static void wpa_driver_nl80211_deinit(struct i802_bss *bss) |
3f5285e8 | 2161 | { |
a2e40bb6 | 2162 | struct wpa_driver_nl80211_data *drv = bss->drv; |
3f5285e8 | 2163 | |
3e208481 JM |
2164 | wpa_printf(MSG_INFO, "nl80211: deinit ifname=%s disabled_11b_rates=%d", |
2165 | bss->ifname, drv->disabled_11b_rates); | |
2166 | ||
873d0fcf | 2167 | bss->in_deinit = 1; |
32ab4855 JB |
2168 | if (drv->data_tx_status) |
2169 | eloop_unregister_read_sock(drv->eapol_tx_sock); | |
d12dab4c JB |
2170 | if (drv->eapol_tx_sock >= 0) |
2171 | close(drv->eapol_tx_sock); | |
f10bfc9a | 2172 | |
481234cf | 2173 | if (bss->nl_preq) |
5582a5d1 | 2174 | wpa_driver_nl80211_probe_req_report(bss, 0); |
e17a2477 | 2175 | if (bss->added_if_into_bridge) { |
c81eff1a BG |
2176 | if (linux_br_del_if(drv->global->ioctl_sock, bss->brname, |
2177 | bss->ifname) < 0) | |
94627f6c JM |
2178 | wpa_printf(MSG_INFO, "nl80211: Failed to remove " |
2179 | "interface %s from bridge %s: %s", | |
e17a2477 | 2180 | bss->ifname, bss->brname, strerror(errno)); |
97ed9a06 | 2181 | if (drv->rtnl_sk) |
ca3c6b4d | 2182 | nl80211_handle_destroy(drv->rtnl_sk); |
94627f6c | 2183 | } |
e17a2477 | 2184 | if (bss->added_bridge) { |
f2535da8 JM |
2185 | if (linux_set_iface_flags(drv->global->ioctl_sock, bss->brname, |
2186 | 0) < 0) | |
2187 | wpa_printf(MSG_INFO, | |
2188 | "nl80211: Could not set bridge %s down", | |
2189 | bss->brname); | |
c81eff1a | 2190 | if (linux_br_del(drv->global->ioctl_sock, bss->brname) < 0) |
94627f6c JM |
2191 | wpa_printf(MSG_INFO, "nl80211: Failed to remove " |
2192 | "bridge %s: %s", | |
e17a2477 | 2193 | bss->brname, strerror(errno)); |
94627f6c JM |
2194 | } |
2195 | ||
460456f8 | 2196 | nl80211_remove_monitor_interface(drv); |
8a27af5c | 2197 | |
b1f625e0 | 2198 | if (is_ap_interface(drv->nlmode)) |
8a27af5c | 2199 | wpa_driver_nl80211_del_beacon(drv); |
0915d02c | 2200 | |
bbaf0837 JM |
2201 | if (drv->eapol_sock >= 0) { |
2202 | eloop_unregister_read_sock(drv->eapol_sock); | |
2203 | close(drv->eapol_sock); | |
2204 | } | |
2205 | ||
2206 | if (drv->if_indices != drv->default_if_indices) | |
2207 | os_free(drv->if_indices); | |
3f5285e8 | 2208 | |
b3af99d2 | 2209 | if (drv->disabled_11b_rates) |
4e5cb1a3 JM |
2210 | nl80211_disable_11b_rates(drv, drv->ifindex, 0); |
2211 | ||
36d84860 BG |
2212 | netlink_send_oper_ifla(drv->global->netlink, drv->ifindex, 0, |
2213 | IF_OPER_UP); | |
e390df05 | 2214 | eloop_cancel_timeout(wpa_driver_nl80211_send_rfkill, drv, drv->ctx); |
8401a6b0 | 2215 | rfkill_deinit(drv->rfkill); |
3f5285e8 | 2216 | |
bbaf0837 JM |
2217 | eloop_cancel_timeout(wpa_driver_nl80211_scan_timeout, drv, drv->ctx); |
2218 | ||
146fa9b3 JM |
2219 | if (!drv->start_iface_up) |
2220 | (void) i802_set_iface_flags(bss, 0); | |
fee354c7 JM |
2221 | |
2222 | if (drv->addr_changed) { | |
93da0498 JM |
2223 | if (linux_set_iface_flags(drv->global->ioctl_sock, bss->ifname, |
2224 | 0) < 0) { | |
2225 | wpa_printf(MSG_DEBUG, | |
2226 | "nl80211: Could not set interface down to restore permanent MAC address"); | |
2227 | } | |
fee354c7 JM |
2228 | if (linux_set_ifhwaddr(drv->global->ioctl_sock, bss->ifname, |
2229 | drv->perm_addr) < 0) { | |
2230 | wpa_printf(MSG_DEBUG, | |
2231 | "nl80211: Could not restore permanent MAC address"); | |
2232 | } | |
2233 | } | |
2234 | ||
8e12685c | 2235 | if (drv->nlmode != NL80211_IFTYPE_P2P_DEVICE) { |
49b4b205 JM |
2236 | if (!drv->hostapd || !drv->start_mode_ap) |
2237 | wpa_driver_nl80211_set_mode(bss, | |
2238 | NL80211_IFTYPE_STATION); | |
b378c41f | 2239 | nl80211_mgmt_unsubscribe(bss, "deinit"); |
8e12685c AS |
2240 | } else { |
2241 | nl80211_mgmt_unsubscribe(bss, "deinit"); | |
eb4582f2 | 2242 | nl80211_del_p2pdev(bss); |
8e12685c | 2243 | } |
3f5285e8 | 2244 | |
834ee56f | 2245 | nl80211_destroy_bss(drv->first_bss); |
cc7a48d1 | 2246 | |
3812464c JM |
2247 | os_free(drv->filter_ssids); |
2248 | ||
536fd62d JM |
2249 | os_free(drv->auth_ie); |
2250 | ||
dac12351 | 2251 | if (drv->in_interface_list) |
f2ed8023 JM |
2252 | dl_list_del(&drv->list); |
2253 | ||
8cd6b7bc JB |
2254 | os_free(drv->extended_capa); |
2255 | os_free(drv->extended_capa_mask); | |
834ee56f | 2256 | os_free(drv->first_bss); |
3f5285e8 JM |
2257 | os_free(drv); |
2258 | } | |
2259 | ||
2260 | ||
de4ed4a8 JM |
2261 | static u32 wpa_alg_to_cipher_suite(enum wpa_alg alg, size_t key_len) |
2262 | { | |
2263 | switch (alg) { | |
2264 | case WPA_ALG_WEP: | |
2265 | if (key_len == 5) | |
2266 | return WLAN_CIPHER_SUITE_WEP40; | |
2267 | return WLAN_CIPHER_SUITE_WEP104; | |
2268 | case WPA_ALG_TKIP: | |
2269 | return WLAN_CIPHER_SUITE_TKIP; | |
2270 | case WPA_ALG_CCMP: | |
2271 | return WLAN_CIPHER_SUITE_CCMP; | |
2272 | case WPA_ALG_GCMP: | |
2273 | return WLAN_CIPHER_SUITE_GCMP; | |
2274 | case WPA_ALG_CCMP_256: | |
2275 | return WLAN_CIPHER_SUITE_CCMP_256; | |
2276 | case WPA_ALG_GCMP_256: | |
2277 | return WLAN_CIPHER_SUITE_GCMP_256; | |
2278 | case WPA_ALG_IGTK: | |
2279 | return WLAN_CIPHER_SUITE_AES_CMAC; | |
2280 | case WPA_ALG_BIP_GMAC_128: | |
2281 | return WLAN_CIPHER_SUITE_BIP_GMAC_128; | |
2282 | case WPA_ALG_BIP_GMAC_256: | |
2283 | return WLAN_CIPHER_SUITE_BIP_GMAC_256; | |
2284 | case WPA_ALG_BIP_CMAC_256: | |
2285 | return WLAN_CIPHER_SUITE_BIP_CMAC_256; | |
2286 | case WPA_ALG_SMS4: | |
2287 | return WLAN_CIPHER_SUITE_SMS4; | |
2288 | case WPA_ALG_KRK: | |
2289 | return WLAN_CIPHER_SUITE_KRK; | |
2290 | case WPA_ALG_NONE: | |
2291 | case WPA_ALG_PMK: | |
2292 | wpa_printf(MSG_ERROR, "nl80211: Unexpected encryption algorithm %d", | |
2293 | alg); | |
2294 | return 0; | |
2295 | } | |
2296 | ||
2297 | wpa_printf(MSG_ERROR, "nl80211: Unsupported encryption algorithm %d", | |
2298 | alg); | |
2299 | return 0; | |
2300 | } | |
2301 | ||
2302 | ||
2303 | static u32 wpa_cipher_to_cipher_suite(unsigned int cipher) | |
2304 | { | |
2305 | switch (cipher) { | |
2306 | case WPA_CIPHER_CCMP_256: | |
2307 | return WLAN_CIPHER_SUITE_CCMP_256; | |
2308 | case WPA_CIPHER_GCMP_256: | |
2309 | return WLAN_CIPHER_SUITE_GCMP_256; | |
2310 | case WPA_CIPHER_CCMP: | |
2311 | return WLAN_CIPHER_SUITE_CCMP; | |
2312 | case WPA_CIPHER_GCMP: | |
2313 | return WLAN_CIPHER_SUITE_GCMP; | |
2314 | case WPA_CIPHER_TKIP: | |
2315 | return WLAN_CIPHER_SUITE_TKIP; | |
2316 | case WPA_CIPHER_WEP104: | |
2317 | return WLAN_CIPHER_SUITE_WEP104; | |
2318 | case WPA_CIPHER_WEP40: | |
2319 | return WLAN_CIPHER_SUITE_WEP40; | |
ae6f9272 JM |
2320 | case WPA_CIPHER_GTK_NOT_USED: |
2321 | return WLAN_CIPHER_SUITE_NO_GROUP_ADDR; | |
de4ed4a8 JM |
2322 | } |
2323 | ||
2324 | return 0; | |
2325 | } | |
2326 | ||
2327 | ||
2328 | static int wpa_cipher_to_cipher_suites(unsigned int ciphers, u32 suites[], | |
2329 | int max_suites) | |
2330 | { | |
2331 | int num_suites = 0; | |
2332 | ||
2333 | if (num_suites < max_suites && ciphers & WPA_CIPHER_CCMP_256) | |
2334 | suites[num_suites++] = WLAN_CIPHER_SUITE_CCMP_256; | |
2335 | if (num_suites < max_suites && ciphers & WPA_CIPHER_GCMP_256) | |
2336 | suites[num_suites++] = WLAN_CIPHER_SUITE_GCMP_256; | |
2337 | if (num_suites < max_suites && ciphers & WPA_CIPHER_CCMP) | |
2338 | suites[num_suites++] = WLAN_CIPHER_SUITE_CCMP; | |
2339 | if (num_suites < max_suites && ciphers & WPA_CIPHER_GCMP) | |
2340 | suites[num_suites++] = WLAN_CIPHER_SUITE_GCMP; | |
2341 | if (num_suites < max_suites && ciphers & WPA_CIPHER_TKIP) | |
2342 | suites[num_suites++] = WLAN_CIPHER_SUITE_TKIP; | |
2343 | if (num_suites < max_suites && ciphers & WPA_CIPHER_WEP104) | |
2344 | suites[num_suites++] = WLAN_CIPHER_SUITE_WEP104; | |
2345 | if (num_suites < max_suites && ciphers & WPA_CIPHER_WEP40) | |
2346 | suites[num_suites++] = WLAN_CIPHER_SUITE_WEP40; | |
2347 | ||
2348 | return num_suites; | |
2349 | } | |
2350 | ||
2351 | ||
b41f2684 CL |
2352 | static int issue_key_mgmt_set_key(struct wpa_driver_nl80211_data *drv, |
2353 | const u8 *key, size_t key_len) | |
2354 | { | |
2355 | struct nl_msg *msg; | |
a862e4a3 | 2356 | int ret; |
b41f2684 | 2357 | |
15badebd | 2358 | if (!(drv->capa.flags & WPA_DRIVER_FLAGS_KEY_MGMT_OFFLOAD)) |
b41f2684 CL |
2359 | return 0; |
2360 | ||
9725b784 | 2361 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_VENDOR)) || |
a862e4a3 JM |
2362 | nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) || |
2363 | nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD, | |
2364 | QCA_NL80211_VENDOR_SUBCMD_KEY_MGMT_SET_KEY) || | |
2365 | nla_put(msg, NL80211_ATTR_VENDOR_DATA, key_len, key)) { | |
bbd89bfc | 2366 | nl80211_nlmsg_clear(msg); |
a862e4a3 JM |
2367 | nlmsg_free(msg); |
2368 | return -1; | |
2369 | } | |
bbd89bfc | 2370 | ret = send_and_recv_msgs(drv, msg, NULL, (void *) -1); |
b41f2684 CL |
2371 | if (ret) { |
2372 | wpa_printf(MSG_DEBUG, | |
2373 | "nl80211: Key management set key failed: ret=%d (%s)", | |
2374 | ret, strerror(-ret)); | |
2375 | } | |
2376 | ||
b41f2684 CL |
2377 | return ret; |
2378 | } | |
2379 | ||
2380 | ||
9ebce9c5 | 2381 | static int wpa_driver_nl80211_set_key(const char *ifname, struct i802_bss *bss, |
71934751 JM |
2382 | enum wpa_alg alg, const u8 *addr, |
2383 | int key_idx, int set_tx, | |
642187d6 JM |
2384 | const u8 *seq, size_t seq_len, |
2385 | const u8 *key, size_t key_len) | |
3f5285e8 | 2386 | { |
a2e40bb6 | 2387 | struct wpa_driver_nl80211_data *drv = bss->drv; |
e472e1b4 | 2388 | int ifindex; |
3f5285e8 | 2389 | struct nl_msg *msg; |
1ad1cdc2 | 2390 | int ret; |
dc01de8a | 2391 | int tdls = 0; |
3f5285e8 | 2392 | |
e472e1b4 AS |
2393 | /* Ignore for P2P Device */ |
2394 | if (drv->nlmode == NL80211_IFTYPE_P2P_DEVICE) | |
2395 | return 0; | |
2396 | ||
2397 | ifindex = if_nametoindex(ifname); | |
8393e1a0 | 2398 | wpa_printf(MSG_DEBUG, "%s: ifindex=%d (%s) alg=%d addr=%p key_idx=%d " |
1ad1cdc2 | 2399 | "set_tx=%d seq_len=%lu key_len=%lu", |
8393e1a0 | 2400 | __func__, ifindex, ifname, alg, addr, key_idx, set_tx, |
3f5285e8 | 2401 | (unsigned long) seq_len, (unsigned long) key_len); |
8c66e185 | 2402 | #ifdef CONFIG_TDLS |
dc01de8a | 2403 | if (key_idx == -1) { |
8c66e185 | 2404 | key_idx = 0; |
dc01de8a JM |
2405 | tdls = 1; |
2406 | } | |
8c66e185 | 2407 | #endif /* CONFIG_TDLS */ |
3f5285e8 | 2408 | |
15badebd CL |
2409 | if (alg == WPA_ALG_PMK && |
2410 | (drv->capa.flags & WPA_DRIVER_FLAGS_KEY_MGMT_OFFLOAD)) { | |
b41f2684 CL |
2411 | wpa_printf(MSG_DEBUG, "%s: calling issue_key_mgmt_set_key", |
2412 | __func__); | |
2413 | ret = issue_key_mgmt_set_key(drv, key, key_len); | |
2414 | return ret; | |
2415 | } | |
2416 | ||
3f5285e8 | 2417 | if (alg == WPA_ALG_NONE) { |
95376e1a JM |
2418 | msg = nl80211_ifindex_msg(drv, ifindex, 0, NL80211_CMD_DEL_KEY); |
2419 | if (!msg) | |
2420 | return -ENOBUFS; | |
3f5285e8 | 2421 | } else { |
95376e1a JM |
2422 | msg = nl80211_ifindex_msg(drv, ifindex, 0, NL80211_CMD_NEW_KEY); |
2423 | if (!msg || | |
a862e4a3 JM |
2424 | nla_put(msg, NL80211_ATTR_KEY_DATA, key_len, key) || |
2425 | nla_put_u32(msg, NL80211_ATTR_KEY_CIPHER, | |
2426 | wpa_alg_to_cipher_suite(alg, key_len))) | |
2427 | goto fail; | |
e6ef73f1 | 2428 | wpa_hexdump_key(MSG_DEBUG, "nl80211: KEY_DATA", key, key_len); |
3f5285e8 JM |
2429 | } |
2430 | ||
e6ef73f1 | 2431 | if (seq && seq_len) { |
a862e4a3 JM |
2432 | if (nla_put(msg, NL80211_ATTR_KEY_SEQ, seq_len, seq)) |
2433 | goto fail; | |
e6ef73f1 JM |
2434 | wpa_hexdump(MSG_DEBUG, "nl80211: KEY_SEQ", seq, seq_len); |
2435 | } | |
1ad1cdc2 | 2436 | |
0382097e | 2437 | if (addr && !is_broadcast_ether_addr(addr)) { |
3f5285e8 | 2438 | wpa_printf(MSG_DEBUG, " addr=" MACSTR, MAC2STR(addr)); |
a862e4a3 JM |
2439 | if (nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) |
2440 | goto fail; | |
89c38e32 JM |
2441 | |
2442 | if (alg != WPA_ALG_WEP && key_idx && !set_tx) { | |
2443 | wpa_printf(MSG_DEBUG, " RSN IBSS RX GTK"); | |
a862e4a3 JM |
2444 | if (nla_put_u32(msg, NL80211_ATTR_KEY_TYPE, |
2445 | NL80211_KEYTYPE_GROUP)) | |
2446 | goto fail; | |
89c38e32 | 2447 | } |
60ea8187 | 2448 | } else if (addr && is_broadcast_ether_addr(addr)) { |
8970bae8 JB |
2449 | struct nlattr *types; |
2450 | ||
60ea8187 | 2451 | wpa_printf(MSG_DEBUG, " broadcast key"); |
8970bae8 JB |
2452 | |
2453 | types = nla_nest_start(msg, NL80211_ATTR_KEY_DEFAULT_TYPES); | |
a862e4a3 JM |
2454 | if (!types || |
2455 | nla_put_flag(msg, NL80211_KEY_DEFAULT_TYPE_MULTICAST)) | |
2456 | goto fail; | |
8970bae8 | 2457 | nla_nest_end(msg, types); |
3f5285e8 | 2458 | } |
95376e1a | 2459 | if (nla_put_u8(msg, NL80211_ATTR_KEY_IDX, key_idx)) |
a862e4a3 | 2460 | goto fail; |
3f5285e8 | 2461 | |
bbd89bfc | 2462 | ret = send_and_recv_msgs(drv, msg, NULL, key ? (void *) -1 : NULL); |
15664ad0 | 2463 | if ((ret == -ENOENT || ret == -ENOLINK) && alg == WPA_ALG_NONE) |
1ad1cdc2 JM |
2464 | ret = 0; |
2465 | if (ret) | |
2466 | wpa_printf(MSG_DEBUG, "nl80211: set_key failed; err=%d %s)", | |
2467 | ret, strerror(-ret)); | |
3f5285e8 | 2468 | |
1ad1cdc2 JM |
2469 | /* |
2470 | * If we failed or don't need to set the default TX key (below), | |
2471 | * we're done here. | |
2472 | */ | |
dc01de8a | 2473 | if (ret || !set_tx || alg == WPA_ALG_NONE || tdls) |
1ad1cdc2 | 2474 | return ret; |
b1f625e0 | 2475 | if (is_ap_interface(drv->nlmode) && addr && |
0382097e | 2476 | !is_broadcast_ether_addr(addr)) |
de12717a | 2477 | return ret; |
3f5285e8 | 2478 | |
95376e1a JM |
2479 | msg = nl80211_ifindex_msg(drv, ifindex, 0, NL80211_CMD_SET_KEY); |
2480 | if (!msg || | |
a862e4a3 | 2481 | nla_put_u8(msg, NL80211_ATTR_KEY_IDX, key_idx) || |
a862e4a3 JM |
2482 | nla_put_flag(msg, alg == WPA_ALG_IGTK ? |
2483 | NL80211_ATTR_KEY_DEFAULT_MGMT : | |
2484 | NL80211_ATTR_KEY_DEFAULT)) | |
2485 | goto fail; | |
60ea8187 | 2486 | if (addr && is_broadcast_ether_addr(addr)) { |
8970bae8 JB |
2487 | struct nlattr *types; |
2488 | ||
2489 | types = nla_nest_start(msg, NL80211_ATTR_KEY_DEFAULT_TYPES); | |
a862e4a3 JM |
2490 | if (!types || |
2491 | nla_put_flag(msg, NL80211_KEY_DEFAULT_TYPE_MULTICAST)) | |
2492 | goto fail; | |
8970bae8 | 2493 | nla_nest_end(msg, types); |
60ea8187 | 2494 | } else if (addr) { |
8970bae8 JB |
2495 | struct nlattr *types; |
2496 | ||
2497 | types = nla_nest_start(msg, NL80211_ATTR_KEY_DEFAULT_TYPES); | |
a862e4a3 JM |
2498 | if (!types || |
2499 | nla_put_flag(msg, NL80211_KEY_DEFAULT_TYPE_UNICAST)) | |
2500 | goto fail; | |
8970bae8 | 2501 | nla_nest_end(msg, types); |
60ea8187 | 2502 | } |
3f5285e8 | 2503 | |
1ad1cdc2 JM |
2504 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
2505 | if (ret == -ENOENT) | |
2506 | ret = 0; | |
2507 | if (ret) | |
2508 | wpa_printf(MSG_DEBUG, "nl80211: set_key default failed; " | |
2509 | "err=%d %s)", ret, strerror(-ret)); | |
2510 | return ret; | |
3f5285e8 | 2511 | |
a862e4a3 | 2512 | fail: |
bbd89bfc | 2513 | nl80211_nlmsg_clear(msg); |
5883168a | 2514 | nlmsg_free(msg); |
6241fcb1 | 2515 | return -ENOBUFS; |
3f5285e8 JM |
2516 | } |
2517 | ||
2518 | ||
71934751 | 2519 | static int nl_add_key(struct nl_msg *msg, enum wpa_alg alg, |
0194fedb JB |
2520 | int key_idx, int defkey, |
2521 | const u8 *seq, size_t seq_len, | |
2522 | const u8 *key, size_t key_len) | |
2523 | { | |
2524 | struct nlattr *key_attr = nla_nest_start(msg, NL80211_ATTR_KEY); | |
2525 | if (!key_attr) | |
2526 | return -1; | |
2527 | ||
a862e4a3 JM |
2528 | if (defkey && alg == WPA_ALG_IGTK) { |
2529 | if (nla_put_flag(msg, NL80211_KEY_DEFAULT_MGMT)) | |
2530 | return -1; | |
2531 | } else if (defkey) { | |
2532 | if (nla_put_flag(msg, NL80211_KEY_DEFAULT)) | |
2533 | return -1; | |
2534 | } | |
0194fedb | 2535 | |
a862e4a3 JM |
2536 | if (nla_put_u8(msg, NL80211_KEY_IDX, key_idx) || |
2537 | nla_put_u32(msg, NL80211_KEY_CIPHER, | |
2538 | wpa_alg_to_cipher_suite(alg, key_len)) || | |
2539 | (seq && seq_len && | |
2540 | nla_put(msg, NL80211_KEY_SEQ, seq_len, seq)) || | |
2541 | nla_put(msg, NL80211_KEY_DATA, key_len, key)) | |
2542 | return -1; | |
0194fedb JB |
2543 | |
2544 | nla_nest_end(msg, key_attr); | |
2545 | ||
2546 | return 0; | |
0194fedb JB |
2547 | } |
2548 | ||
c811d5bc | 2549 | |
cfaab580 ZY |
2550 | static int nl80211_set_conn_keys(struct wpa_driver_associate_params *params, |
2551 | struct nl_msg *msg) | |
2552 | { | |
2553 | int i, privacy = 0; | |
2554 | struct nlattr *nl_keys, *nl_key; | |
2555 | ||
2556 | for (i = 0; i < 4; i++) { | |
2557 | if (!params->wep_key[i]) | |
2558 | continue; | |
2559 | privacy = 1; | |
2560 | break; | |
2561 | } | |
ce04af5a JM |
2562 | if (params->wps == WPS_MODE_PRIVACY) |
2563 | privacy = 1; | |
2564 | if (params->pairwise_suite && | |
2565 | params->pairwise_suite != WPA_CIPHER_NONE) | |
2566 | privacy = 1; | |
2567 | ||
cfaab580 ZY |
2568 | if (!privacy) |
2569 | return 0; | |
2570 | ||
a862e4a3 JM |
2571 | if (nla_put_flag(msg, NL80211_ATTR_PRIVACY)) |
2572 | return -ENOBUFS; | |
cfaab580 ZY |
2573 | |
2574 | nl_keys = nla_nest_start(msg, NL80211_ATTR_KEYS); | |
2575 | if (!nl_keys) | |
a862e4a3 | 2576 | return -ENOBUFS; |
cfaab580 ZY |
2577 | |
2578 | for (i = 0; i < 4; i++) { | |
2579 | if (!params->wep_key[i]) | |
2580 | continue; | |
2581 | ||
2582 | nl_key = nla_nest_start(msg, i); | |
a862e4a3 JM |
2583 | if (!nl_key || |
2584 | nla_put(msg, NL80211_KEY_DATA, params->wep_key_len[i], | |
2585 | params->wep_key[i]) || | |
2586 | nla_put_u32(msg, NL80211_KEY_CIPHER, | |
2587 | params->wep_key_len[i] == 5 ? | |
2588 | WLAN_CIPHER_SUITE_WEP40 : | |
2589 | WLAN_CIPHER_SUITE_WEP104) || | |
2590 | nla_put_u8(msg, NL80211_KEY_IDX, i) || | |
2591 | (i == params->wep_tx_keyidx && | |
2592 | nla_put_flag(msg, NL80211_KEY_DEFAULT))) | |
2593 | return -ENOBUFS; | |
cfaab580 ZY |
2594 | |
2595 | nla_nest_end(msg, nl_key); | |
2596 | } | |
2597 | nla_nest_end(msg, nl_keys); | |
2598 | ||
2599 | return 0; | |
cfaab580 ZY |
2600 | } |
2601 | ||
2602 | ||
477af8f8 JM |
2603 | int wpa_driver_nl80211_mlme(struct wpa_driver_nl80211_data *drv, |
2604 | const u8 *addr, int cmd, u16 reason_code, | |
2605 | int local_state_change) | |
c2a04078 | 2606 | { |
a862e4a3 | 2607 | int ret; |
c2a04078 JM |
2608 | struct nl_msg *msg; |
2609 | ||
9725b784 | 2610 | if (!(msg = nl80211_drv_msg(drv, 0, cmd)) || |
a862e4a3 JM |
2611 | nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason_code) || |
2612 | (addr && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) || | |
2613 | (local_state_change && | |
2614 | nla_put_flag(msg, NL80211_ATTR_LOCAL_STATE_CHANGE))) { | |
2615 | nlmsg_free(msg); | |
2616 | return -1; | |
2617 | } | |
c2a04078 JM |
2618 | |
2619 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); | |
c2a04078 | 2620 | if (ret) { |
3b7ea880 BG |
2621 | wpa_dbg(drv->ctx, MSG_DEBUG, |
2622 | "nl80211: MLME command failed: reason=%u ret=%d (%s)", | |
2623 | reason_code, ret, strerror(-ret)); | |
c2a04078 | 2624 | } |
c2a04078 JM |
2625 | return ret; |
2626 | } | |
3f5285e8 JM |
2627 | |
2628 | ||
cfaab580 | 2629 | static int wpa_driver_nl80211_disconnect(struct wpa_driver_nl80211_data *drv, |
817762d9 | 2630 | int reason_code) |
cfaab580 | 2631 | { |
3f53c006 JJ |
2632 | int ret; |
2633 | ||
817762d9 | 2634 | wpa_printf(MSG_DEBUG, "%s(reason_code=%d)", __func__, reason_code); |
add9b7a4 | 2635 | nl80211_mark_disconnected(drv); |
817762d9 | 2636 | /* Disconnect command doesn't need BSSID - it uses cached value */ |
3f53c006 JJ |
2637 | ret = wpa_driver_nl80211_mlme(drv, NULL, NL80211_CMD_DISCONNECT, |
2638 | reason_code, 0); | |
2639 | /* | |
2640 | * For locally generated disconnect, supplicant already generates a | |
2641 | * DEAUTH event, so ignore the event from NL80211. | |
2642 | */ | |
2643 | drv->ignore_next_local_disconnect = ret == 0; | |
2644 | ||
2645 | return ret; | |
cfaab580 ZY |
2646 | } |
2647 | ||
2648 | ||
9ebce9c5 JM |
2649 | static int wpa_driver_nl80211_deauthenticate(struct i802_bss *bss, |
2650 | const u8 *addr, int reason_code) | |
3f5285e8 | 2651 | { |
a2e40bb6 | 2652 | struct wpa_driver_nl80211_data *drv = bss->drv; |
d6a36f39 | 2653 | int ret; |
9392c9be AS |
2654 | |
2655 | if (drv->nlmode == NL80211_IFTYPE_ADHOC) { | |
2656 | nl80211_mark_disconnected(drv); | |
666e508c | 2657 | return nl80211_leave_ibss(drv, 1); |
9392c9be | 2658 | } |
cfaab580 | 2659 | if (!(drv->capa.flags & WPA_DRIVER_FLAGS_SME)) |
817762d9 | 2660 | return wpa_driver_nl80211_disconnect(drv, reason_code); |
2e75a2b3 JM |
2661 | wpa_printf(MSG_DEBUG, "%s(addr=" MACSTR " reason_code=%d)", |
2662 | __func__, MAC2STR(addr), reason_code); | |
add9b7a4 | 2663 | nl80211_mark_disconnected(drv); |
d6a36f39 JM |
2664 | ret = wpa_driver_nl80211_mlme(drv, addr, NL80211_CMD_DEAUTHENTICATE, |
2665 | reason_code, 0); | |
2666 | /* | |
2667 | * For locally generated deauthenticate, supplicant already generates a | |
2668 | * DEAUTH event, so ignore the event from NL80211. | |
2669 | */ | |
2670 | drv->ignore_next_local_deauth = ret == 0; | |
2671 | return ret; | |
3f5285e8 JM |
2672 | } |
2673 | ||
2674 | ||
536fd62d JM |
2675 | static void nl80211_copy_auth_params(struct wpa_driver_nl80211_data *drv, |
2676 | struct wpa_driver_auth_params *params) | |
2677 | { | |
2678 | int i; | |
2679 | ||
2680 | drv->auth_freq = params->freq; | |
2681 | drv->auth_alg = params->auth_alg; | |
2682 | drv->auth_wep_tx_keyidx = params->wep_tx_keyidx; | |
2683 | drv->auth_local_state_change = params->local_state_change; | |
2684 | drv->auth_p2p = params->p2p; | |
2685 | ||
2686 | if (params->bssid) | |
2687 | os_memcpy(drv->auth_bssid_, params->bssid, ETH_ALEN); | |
2688 | else | |
2689 | os_memset(drv->auth_bssid_, 0, ETH_ALEN); | |
2690 | ||
2691 | if (params->ssid) { | |
2692 | os_memcpy(drv->auth_ssid, params->ssid, params->ssid_len); | |
2693 | drv->auth_ssid_len = params->ssid_len; | |
2694 | } else | |
2695 | drv->auth_ssid_len = 0; | |
2696 | ||
2697 | ||
2698 | os_free(drv->auth_ie); | |
2699 | drv->auth_ie = NULL; | |
2700 | drv->auth_ie_len = 0; | |
2701 | if (params->ie) { | |
2702 | drv->auth_ie = os_malloc(params->ie_len); | |
2703 | if (drv->auth_ie) { | |
2704 | os_memcpy(drv->auth_ie, params->ie, params->ie_len); | |
2705 | drv->auth_ie_len = params->ie_len; | |
2706 | } | |
2707 | } | |
2708 | ||
2709 | for (i = 0; i < 4; i++) { | |
2710 | if (params->wep_key[i] && params->wep_key_len[i] && | |
2711 | params->wep_key_len[i] <= 16) { | |
2712 | os_memcpy(drv->auth_wep_key[i], params->wep_key[i], | |
2713 | params->wep_key_len[i]); | |
2714 | drv->auth_wep_key_len[i] = params->wep_key_len[i]; | |
2715 | } else | |
2716 | drv->auth_wep_key_len[i] = 0; | |
2717 | } | |
2718 | } | |
2719 | ||
2720 | ||
4bd71954 JM |
2721 | static void nl80211_unmask_11b_rates(struct i802_bss *bss) |
2722 | { | |
2723 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
2724 | ||
2725 | if (is_p2p_net_interface(drv->nlmode) || !drv->disabled_11b_rates) | |
2726 | return; | |
2727 | ||
2728 | /* | |
2729 | * Looks like we failed to unmask 11b rates previously. This could | |
2730 | * happen, e.g., if the interface was down at the point in time when a | |
2731 | * P2P group was terminated. | |
2732 | */ | |
2733 | wpa_printf(MSG_DEBUG, | |
2734 | "nl80211: Interface %s mode is for non-P2P, but 11b rates were disabled - re-enable them", | |
2735 | bss->ifname); | |
2736 | nl80211_disable_11b_rates(drv, drv->ifindex, 0); | |
2737 | } | |
2738 | ||
2739 | ||
c2a04078 | 2740 | static int wpa_driver_nl80211_authenticate( |
9ebce9c5 | 2741 | struct i802_bss *bss, struct wpa_driver_auth_params *params) |
c2a04078 | 2742 | { |
a2e40bb6 | 2743 | struct wpa_driver_nl80211_data *drv = bss->drv; |
a0b2f99b | 2744 | int ret = -1, i; |
c2a04078 JM |
2745 | struct nl_msg *msg; |
2746 | enum nl80211_auth_type type; | |
2f4f73b1 | 2747 | enum nl80211_iftype nlmode; |
6d6f4bb8 | 2748 | int count = 0; |
536fd62d JM |
2749 | int is_retry; |
2750 | ||
4bd71954 JM |
2751 | nl80211_unmask_11b_rates(bss); |
2752 | ||
536fd62d JM |
2753 | is_retry = drv->retry_auth; |
2754 | drv->retry_auth = 0; | |
e8d70a73 | 2755 | drv->ignore_deauth_event = 0; |
c2a04078 | 2756 | |
add9b7a4 | 2757 | nl80211_mark_disconnected(drv); |
e6b8efeb | 2758 | os_memset(drv->auth_bssid, 0, ETH_ALEN); |
add9b7a4 JM |
2759 | if (params->bssid) |
2760 | os_memcpy(drv->auth_attempt_bssid, params->bssid, ETH_ALEN); | |
2761 | else | |
2762 | os_memset(drv->auth_attempt_bssid, 0, ETH_ALEN); | |
af473088 | 2763 | /* FIX: IBSS mode */ |
2f4f73b1 EP |
2764 | nlmode = params->p2p ? |
2765 | NL80211_IFTYPE_P2P_CLIENT : NL80211_IFTYPE_STATION; | |
2766 | if (drv->nlmode != nlmode && | |
9ebce9c5 | 2767 | wpa_driver_nl80211_set_mode(bss, nlmode) < 0) |
4a867032 JM |
2768 | return -1; |
2769 | ||
6d6f4bb8 | 2770 | retry: |
c2a04078 JM |
2771 | wpa_printf(MSG_DEBUG, "nl80211: Authenticate (ifindex=%d)", |
2772 | drv->ifindex); | |
a0b2f99b | 2773 | |
9725b784 JM |
2774 | msg = nl80211_drv_msg(drv, 0, NL80211_CMD_AUTHENTICATE); |
2775 | if (!msg) | |
2776 | goto fail; | |
0194fedb | 2777 | |
a0b2f99b JM |
2778 | for (i = 0; i < 4; i++) { |
2779 | if (!params->wep_key[i]) | |
2780 | continue; | |
9ebce9c5 | 2781 | wpa_driver_nl80211_set_key(bss->ifname, bss, WPA_ALG_WEP, |
2ea2fcc7 | 2782 | NULL, i, |
a0b2f99b JM |
2783 | i == params->wep_tx_keyidx, NULL, 0, |
2784 | params->wep_key[i], | |
2785 | params->wep_key_len[i]); | |
0194fedb JB |
2786 | if (params->wep_tx_keyidx != i) |
2787 | continue; | |
2788 | if (nl_add_key(msg, WPA_ALG_WEP, i, 1, NULL, 0, | |
9725b784 JM |
2789 | params->wep_key[i], params->wep_key_len[i])) |
2790 | goto fail; | |
a0b2f99b JM |
2791 | } |
2792 | ||
c2a04078 JM |
2793 | if (params->bssid) { |
2794 | wpa_printf(MSG_DEBUG, " * bssid=" MACSTR, | |
2795 | MAC2STR(params->bssid)); | |
a862e4a3 JM |
2796 | if (nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, params->bssid)) |
2797 | goto fail; | |
c2a04078 JM |
2798 | } |
2799 | if (params->freq) { | |
2800 | wpa_printf(MSG_DEBUG, " * freq=%d", params->freq); | |
a862e4a3 JM |
2801 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, params->freq)) |
2802 | goto fail; | |
c2a04078 JM |
2803 | } |
2804 | if (params->ssid) { | |
2805 | wpa_hexdump_ascii(MSG_DEBUG, " * SSID", | |
2806 | params->ssid, params->ssid_len); | |
a862e4a3 JM |
2807 | if (nla_put(msg, NL80211_ATTR_SSID, params->ssid_len, |
2808 | params->ssid)) | |
2809 | goto fail; | |
c2a04078 JM |
2810 | } |
2811 | wpa_hexdump(MSG_DEBUG, " * IEs", params->ie, params->ie_len); | |
a862e4a3 JM |
2812 | if (params->ie && |
2813 | nla_put(msg, NL80211_ATTR_IE, params->ie_len, params->ie)) | |
2814 | goto fail; | |
569fed90 JM |
2815 | if (params->sae_data) { |
2816 | wpa_hexdump(MSG_DEBUG, " * SAE data", params->sae_data, | |
2817 | params->sae_data_len); | |
a862e4a3 JM |
2818 | if (nla_put(msg, NL80211_ATTR_SAE_DATA, params->sae_data_len, |
2819 | params->sae_data)) | |
2820 | goto fail; | |
569fed90 | 2821 | } |
abd9fafa | 2822 | if (params->auth_alg & WPA_AUTH_ALG_OPEN) |
c2a04078 | 2823 | type = NL80211_AUTHTYPE_OPEN_SYSTEM; |
abd9fafa | 2824 | else if (params->auth_alg & WPA_AUTH_ALG_SHARED) |
c2a04078 | 2825 | type = NL80211_AUTHTYPE_SHARED_KEY; |
abd9fafa | 2826 | else if (params->auth_alg & WPA_AUTH_ALG_LEAP) |
c2a04078 | 2827 | type = NL80211_AUTHTYPE_NETWORK_EAP; |
abd9fafa | 2828 | else if (params->auth_alg & WPA_AUTH_ALG_FT) |
c2a04078 | 2829 | type = NL80211_AUTHTYPE_FT; |
569fed90 JM |
2830 | else if (params->auth_alg & WPA_AUTH_ALG_SAE) |
2831 | type = NL80211_AUTHTYPE_SAE; | |
c2a04078 | 2832 | else |
a862e4a3 | 2833 | goto fail; |
c2a04078 | 2834 | wpa_printf(MSG_DEBUG, " * Auth Type %d", type); |
a862e4a3 JM |
2835 | if (nla_put_u32(msg, NL80211_ATTR_AUTH_TYPE, type)) |
2836 | goto fail; | |
77339912 JM |
2837 | if (params->local_state_change) { |
2838 | wpa_printf(MSG_DEBUG, " * Local state change only"); | |
a862e4a3 JM |
2839 | if (nla_put_flag(msg, NL80211_ATTR_LOCAL_STATE_CHANGE)) |
2840 | goto fail; | |
77339912 | 2841 | } |
c2a04078 JM |
2842 | |
2843 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); | |
2844 | msg = NULL; | |
2845 | if (ret) { | |
3b7ea880 BG |
2846 | wpa_dbg(drv->ctx, MSG_DEBUG, |
2847 | "nl80211: MLME command failed (auth): ret=%d (%s)", | |
2848 | ret, strerror(-ret)); | |
6d6f4bb8 | 2849 | count++; |
77339912 JM |
2850 | if (ret == -EALREADY && count == 1 && params->bssid && |
2851 | !params->local_state_change) { | |
6d6f4bb8 JM |
2852 | /* |
2853 | * mac80211 does not currently accept new | |
2854 | * authentication if we are already authenticated. As a | |
2855 | * workaround, force deauthentication and try again. | |
2856 | */ | |
2857 | wpa_printf(MSG_DEBUG, "nl80211: Retry authentication " | |
2858 | "after forced deauthentication"); | |
e8d70a73 | 2859 | drv->ignore_deauth_event = 1; |
6d6f4bb8 | 2860 | wpa_driver_nl80211_deauthenticate( |
5205c4f9 | 2861 | bss, params->bssid, |
6d6f4bb8 JM |
2862 | WLAN_REASON_PREV_AUTH_NOT_VALID); |
2863 | nlmsg_free(msg); | |
2864 | goto retry; | |
2865 | } | |
536fd62d JM |
2866 | |
2867 | if (ret == -ENOENT && params->freq && !is_retry) { | |
2868 | /* | |
2869 | * cfg80211 has likely expired the BSS entry even | |
2870 | * though it was previously available in our internal | |
2871 | * BSS table. To recover quickly, start a single | |
2872 | * channel scan on the specified channel. | |
2873 | */ | |
2874 | struct wpa_driver_scan_params scan; | |
2875 | int freqs[2]; | |
2876 | ||
2877 | os_memset(&scan, 0, sizeof(scan)); | |
2878 | scan.num_ssids = 1; | |
2879 | if (params->ssid) { | |
2880 | scan.ssids[0].ssid = params->ssid; | |
2881 | scan.ssids[0].ssid_len = params->ssid_len; | |
2882 | } | |
2883 | freqs[0] = params->freq; | |
2884 | freqs[1] = 0; | |
2885 | scan.freqs = freqs; | |
2886 | wpa_printf(MSG_DEBUG, "nl80211: Trigger single " | |
2887 | "channel scan to refresh cfg80211 BSS " | |
2888 | "entry"); | |
2889 | ret = wpa_driver_nl80211_scan(bss, &scan); | |
2890 | if (ret == 0) { | |
2891 | nl80211_copy_auth_params(drv, params); | |
2892 | drv->scan_for_auth = 1; | |
2893 | } | |
8c3ba078 JM |
2894 | } else if (is_retry) { |
2895 | /* | |
2896 | * Need to indicate this with an event since the return | |
2897 | * value from the retry is not delivered to core code. | |
2898 | */ | |
2899 | union wpa_event_data event; | |
2900 | wpa_printf(MSG_DEBUG, "nl80211: Authentication retry " | |
2901 | "failed"); | |
2902 | os_memset(&event, 0, sizeof(event)); | |
2903 | os_memcpy(event.timeout_event.addr, drv->auth_bssid_, | |
2904 | ETH_ALEN); | |
2905 | wpa_supplicant_event(drv->ctx, EVENT_AUTH_TIMED_OUT, | |
2906 | &event); | |
536fd62d | 2907 | } |
a862e4a3 JM |
2908 | } else { |
2909 | wpa_printf(MSG_DEBUG, | |
2910 | "nl80211: Authentication request send successfully"); | |
c2a04078 | 2911 | } |
c2a04078 | 2912 | |
a862e4a3 | 2913 | fail: |
c2a04078 JM |
2914 | nlmsg_free(msg); |
2915 | return ret; | |
2916 | } | |
2917 | ||
2918 | ||
f3407c66 | 2919 | int wpa_driver_nl80211_authenticate_retry(struct wpa_driver_nl80211_data *drv) |
536fd62d JM |
2920 | { |
2921 | struct wpa_driver_auth_params params; | |
834ee56f | 2922 | struct i802_bss *bss = drv->first_bss; |
536fd62d JM |
2923 | int i; |
2924 | ||
2925 | wpa_printf(MSG_DEBUG, "nl80211: Try to authenticate again"); | |
2926 | ||
2927 | os_memset(¶ms, 0, sizeof(params)); | |
2928 | params.freq = drv->auth_freq; | |
2929 | params.auth_alg = drv->auth_alg; | |
2930 | params.wep_tx_keyidx = drv->auth_wep_tx_keyidx; | |
2931 | params.local_state_change = drv->auth_local_state_change; | |
2932 | params.p2p = drv->auth_p2p; | |
2933 | ||
2934 | if (!is_zero_ether_addr(drv->auth_bssid_)) | |
2935 | params.bssid = drv->auth_bssid_; | |
2936 | ||
2937 | if (drv->auth_ssid_len) { | |
2938 | params.ssid = drv->auth_ssid; | |
2939 | params.ssid_len = drv->auth_ssid_len; | |
2940 | } | |
2941 | ||
2942 | params.ie = drv->auth_ie; | |
2943 | params.ie_len = drv->auth_ie_len; | |
2944 | ||
2945 | for (i = 0; i < 4; i++) { | |
2946 | if (drv->auth_wep_key_len[i]) { | |
2947 | params.wep_key[i] = drv->auth_wep_key[i]; | |
2948 | params.wep_key_len[i] = drv->auth_wep_key_len[i]; | |
2949 | } | |
2950 | } | |
2951 | ||
2952 | drv->retry_auth = 1; | |
2953 | return wpa_driver_nl80211_authenticate(bss, ¶ms); | |
2954 | } | |
2955 | ||
2956 | ||
a11241fa JB |
2957 | static int wpa_driver_nl80211_send_frame(struct i802_bss *bss, |
2958 | const void *data, size_t len, | |
55231068 JM |
2959 | int encrypt, int noack, |
2960 | unsigned int freq, int no_cck, | |
2961 | int offchanok, unsigned int wait_time) | |
a11241fa JB |
2962 | { |
2963 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
2964 | u64 cookie; | |
41cc50d1 | 2965 | int res; |
a11241fa | 2966 | |
c7caac56 JM |
2967 | if (freq == 0 && drv->nlmode == NL80211_IFTYPE_ADHOC) { |
2968 | freq = nl80211_get_assoc_freq(drv); | |
2969 | wpa_printf(MSG_DEBUG, | |
2970 | "nl80211: send_frame - Use assoc_freq=%u for IBSS", | |
2971 | freq); | |
2972 | } | |
af964484 JM |
2973 | if (freq == 0) { |
2974 | wpa_printf(MSG_DEBUG, "nl80211: send_frame - Use bss->freq=%u", | |
2975 | bss->freq); | |
55231068 | 2976 | freq = bss->freq; |
af964484 | 2977 | } |
55231068 | 2978 | |
739faee2 | 2979 | if (drv->use_monitor) { |
981cf85a | 2980 | wpa_printf(MSG_DEBUG, "nl80211: send_frame(freq=%u bss->freq=%u) -> send_monitor", |
739faee2 | 2981 | freq, bss->freq); |
981cf85a | 2982 | return nl80211_send_monitor(drv, data, len, encrypt, noack); |
739faee2 | 2983 | } |
a11241fa | 2984 | |
739faee2 | 2985 | wpa_printf(MSG_DEBUG, "nl80211: send_frame -> send_frame_cmd"); |
41cc50d1 JM |
2986 | res = nl80211_send_frame_cmd(bss, freq, wait_time, data, len, |
2987 | &cookie, no_cck, noack, offchanok); | |
2988 | if (res == 0 && !noack) { | |
2989 | const struct ieee80211_mgmt *mgmt; | |
2990 | u16 fc; | |
2991 | ||
2992 | mgmt = (const struct ieee80211_mgmt *) data; | |
2993 | fc = le_to_host16(mgmt->frame_control); | |
2994 | if (WLAN_FC_GET_TYPE(fc) == WLAN_FC_TYPE_MGMT && | |
2995 | WLAN_FC_GET_STYPE(fc) == WLAN_FC_STYPE_ACTION) { | |
2996 | wpa_printf(MSG_MSGDUMP, | |
2997 | "nl80211: Update send_action_cookie from 0x%llx to 0x%llx", | |
2998 | (long long unsigned int) | |
2999 | drv->send_action_cookie, | |
3000 | (long long unsigned int) cookie); | |
3001 | drv->send_action_cookie = cookie; | |
3002 | } | |
3003 | } | |
3004 | ||
3005 | return res; | |
a11241fa JB |
3006 | } |
3007 | ||
3008 | ||
9ebce9c5 JM |
3009 | static int wpa_driver_nl80211_send_mlme(struct i802_bss *bss, const u8 *data, |
3010 | size_t data_len, int noack, | |
3011 | unsigned int freq, int no_cck, | |
3012 | int offchanok, | |
3013 | unsigned int wait_time) | |
2c2010ac | 3014 | { |
a2e40bb6 | 3015 | struct wpa_driver_nl80211_data *drv = bss->drv; |
2c2010ac | 3016 | struct ieee80211_mgmt *mgmt; |
7a47d567 | 3017 | int encrypt = 1; |
2c2010ac JM |
3018 | u16 fc; |
3019 | ||
3020 | mgmt = (struct ieee80211_mgmt *) data; | |
3021 | fc = le_to_host16(mgmt->frame_control); | |
f95a4524 PF |
3022 | wpa_printf(MSG_DEBUG, "nl80211: send_mlme - da= " MACSTR |
3023 | " noack=%d freq=%u no_cck=%d offchanok=%d wait_time=%u fc=0x%x (%s) nlmode=%d", | |
3024 | MAC2STR(mgmt->da), noack, freq, no_cck, offchanok, wait_time, | |
3025 | fc, fc2str(fc), drv->nlmode); | |
2c2010ac | 3026 | |
8e12685c AS |
3027 | if ((is_sta_interface(drv->nlmode) || |
3028 | drv->nlmode == NL80211_IFTYPE_P2P_DEVICE) && | |
5582a5d1 JB |
3029 | WLAN_FC_GET_TYPE(fc) == WLAN_FC_TYPE_MGMT && |
3030 | WLAN_FC_GET_STYPE(fc) == WLAN_FC_STYPE_PROBE_RESP) { | |
3031 | /* | |
3032 | * The use of last_mgmt_freq is a bit of a hack, | |
3033 | * but it works due to the single-threaded nature | |
3034 | * of wpa_supplicant. | |
3035 | */ | |
af964484 JM |
3036 | if (freq == 0) { |
3037 | wpa_printf(MSG_DEBUG, "nl80211: Use last_mgmt_freq=%d", | |
3038 | drv->last_mgmt_freq); | |
55231068 | 3039 | freq = drv->last_mgmt_freq; |
af964484 | 3040 | } |
55231068 | 3041 | return nl80211_send_frame_cmd(bss, freq, 0, |
88df0ef7 JB |
3042 | data, data_len, NULL, 1, noack, |
3043 | 1); | |
5582a5d1 JB |
3044 | } |
3045 | ||
61cbe2ff | 3046 | if (drv->device_ap_sme && is_ap_interface(drv->nlmode)) { |
af964484 JM |
3047 | if (freq == 0) { |
3048 | wpa_printf(MSG_DEBUG, "nl80211: Use bss->freq=%d", | |
3049 | bss->freq); | |
55231068 | 3050 | freq = bss->freq; |
af964484 | 3051 | } |
b5671498 JM |
3052 | return nl80211_send_frame_cmd(bss, freq, |
3053 | (int) freq == bss->freq ? 0 : | |
3054 | wait_time, | |
d8d6b32e DG |
3055 | data, data_len, |
3056 | &drv->send_action_cookie, | |
55231068 | 3057 | no_cck, noack, offchanok); |
86957e62 JM |
3058 | } |
3059 | ||
2c2010ac JM |
3060 | if (WLAN_FC_GET_TYPE(fc) == WLAN_FC_TYPE_MGMT && |
3061 | WLAN_FC_GET_STYPE(fc) == WLAN_FC_STYPE_AUTH) { | |
3062 | /* | |
3063 | * Only one of the authentication frame types is encrypted. | |
3064 | * In order for static WEP encryption to work properly (i.e., | |
3065 | * to not encrypt the frame), we need to tell mac80211 about | |
3066 | * the frames that must not be encrypted. | |
3067 | */ | |
3068 | u16 auth_alg = le_to_host16(mgmt->u.auth.auth_alg); | |
3069 | u16 auth_trans = le_to_host16(mgmt->u.auth.auth_transaction); | |
7a47d567 JB |
3070 | if (auth_alg != WLAN_AUTH_SHARED_KEY || auth_trans != 3) |
3071 | encrypt = 0; | |
2c2010ac JM |
3072 | } |
3073 | ||
739faee2 | 3074 | wpa_printf(MSG_DEBUG, "nl80211: send_mlme -> send_frame"); |
a11241fa | 3075 | return wpa_driver_nl80211_send_frame(bss, data, data_len, encrypt, |
55231068 JM |
3076 | noack, freq, no_cck, offchanok, |
3077 | wait_time); | |
3078 | } | |
3079 | ||
3080 | ||
31357268 | 3081 | static int nl80211_set_bss(struct i802_bss *bss, int cts, int preamble, |
e5693c47 JM |
3082 | int slot, int ht_opmode, int ap_isolate, |
3083 | int *basic_rates) | |
31357268 JM |
3084 | { |
3085 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
3086 | struct nl_msg *msg; | |
3087 | ||
13f83980 | 3088 | if (!(msg = nl80211_bss_msg(bss, 0, NL80211_CMD_SET_BSS)) || |
a862e4a3 JM |
3089 | (cts >= 0 && |
3090 | nla_put_u8(msg, NL80211_ATTR_BSS_CTS_PROT, cts)) || | |
3091 | (preamble >= 0 && | |
3092 | nla_put_u8(msg, NL80211_ATTR_BSS_SHORT_PREAMBLE, preamble)) || | |
3093 | (slot >= 0 && | |
3094 | nla_put_u8(msg, NL80211_ATTR_BSS_SHORT_SLOT_TIME, slot)) || | |
3095 | (ht_opmode >= 0 && | |
3096 | nla_put_u16(msg, NL80211_ATTR_BSS_HT_OPMODE, ht_opmode)) || | |
3097 | (ap_isolate >= 0 && | |
3098 | nla_put_u8(msg, NL80211_ATTR_AP_ISOLATE, ap_isolate))) | |
3099 | goto fail; | |
e5693c47 JM |
3100 | |
3101 | if (basic_rates) { | |
3102 | u8 rates[NL80211_MAX_SUPP_RATES]; | |
3103 | u8 rates_len = 0; | |
3104 | int i; | |
3105 | ||
3106 | for (i = 0; i < NL80211_MAX_SUPP_RATES && basic_rates[i] >= 0; | |
3107 | i++) | |
3108 | rates[rates_len++] = basic_rates[i] / 5; | |
3109 | ||
a862e4a3 JM |
3110 | if (nla_put(msg, NL80211_ATTR_BSS_BASIC_RATES, rates_len, |
3111 | rates)) | |
3112 | goto fail; | |
e5693c47 JM |
3113 | } |
3114 | ||
31357268 | 3115 | return send_and_recv_msgs(drv, msg, NULL, NULL); |
a862e4a3 | 3116 | fail: |
5883168a | 3117 | nlmsg_free(msg); |
31357268 JM |
3118 | return -ENOBUFS; |
3119 | } | |
3120 | ||
3121 | ||
3c4ca363 VN |
3122 | static int wpa_driver_nl80211_set_acl(void *priv, |
3123 | struct hostapd_acl_params *params) | |
3124 | { | |
3125 | struct i802_bss *bss = priv; | |
3126 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
3127 | struct nl_msg *msg; | |
3128 | struct nlattr *acl; | |
3129 | unsigned int i; | |
a862e4a3 | 3130 | int ret; |
3c4ca363 VN |
3131 | |
3132 | if (!(drv->capa.max_acl_mac_addrs)) | |
3133 | return -ENOTSUP; | |
3134 | ||
3135 | if (params->num_mac_acl > drv->capa.max_acl_mac_addrs) | |
3136 | return -ENOTSUP; | |
3137 | ||
3c4ca363 VN |
3138 | wpa_printf(MSG_DEBUG, "nl80211: Set %s ACL (num_mac_acl=%u)", |
3139 | params->acl_policy ? "Accept" : "Deny", params->num_mac_acl); | |
3140 | ||
9725b784 | 3141 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_SET_MAC_ACL)) || |
a862e4a3 JM |
3142 | nla_put_u32(msg, NL80211_ATTR_ACL_POLICY, params->acl_policy ? |
3143 | NL80211_ACL_POLICY_DENY_UNLESS_LISTED : | |
3144 | NL80211_ACL_POLICY_ACCEPT_UNLESS_LISTED) || | |
3145 | (acl = nla_nest_start(msg, NL80211_ATTR_MAC_ADDRS)) == NULL) { | |
3146 | nlmsg_free(msg); | |
3147 | return -ENOMEM; | |
3148 | } | |
3c4ca363 | 3149 | |
a862e4a3 JM |
3150 | for (i = 0; i < params->num_mac_acl; i++) { |
3151 | if (nla_put(msg, i + 1, ETH_ALEN, params->mac_acl[i].addr)) { | |
3152 | nlmsg_free(msg); | |
3153 | return -ENOMEM; | |
3154 | } | |
3155 | } | |
3c4ca363 VN |
3156 | |
3157 | nla_nest_end(msg, acl); | |
3158 | ||
3159 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); | |
3c4ca363 VN |
3160 | if (ret) { |
3161 | wpa_printf(MSG_DEBUG, "nl80211: Failed to set MAC ACL: %d (%s)", | |
3162 | ret, strerror(-ret)); | |
3163 | } | |
3164 | ||
3c4ca363 VN |
3165 | return ret; |
3166 | } | |
3167 | ||
3168 | ||
19c3b566 JM |
3169 | static int wpa_driver_nl80211_set_ap(void *priv, |
3170 | struct wpa_driver_ap_params *params) | |
d2440ba0 | 3171 | { |
a2e40bb6 FF |
3172 | struct i802_bss *bss = priv; |
3173 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
d2440ba0 JM |
3174 | struct nl_msg *msg; |
3175 | u8 cmd = NL80211_CMD_NEW_BEACON; | |
3176 | int ret; | |
b4fd6fab | 3177 | int beacon_set; |
b11d1d64 | 3178 | int num_suites; |
da1080d7 | 3179 | int smps_mode; |
de4ed4a8 | 3180 | u32 suites[10], suite; |
b11d1d64 | 3181 | u32 ver; |
b4fd6fab | 3182 | |
b4fd6fab | 3183 | beacon_set = bss->beacon_set; |
d2440ba0 | 3184 | |
d2440ba0 | 3185 | wpa_printf(MSG_DEBUG, "nl80211: Set beacon (beacon_set=%d)", |
b4fd6fab JM |
3186 | beacon_set); |
3187 | if (beacon_set) | |
d2440ba0 JM |
3188 | cmd = NL80211_CMD_SET_BEACON; |
3189 | ||
b92e08fc JM |
3190 | wpa_hexdump(MSG_DEBUG, "nl80211: Beacon head", |
3191 | params->head, params->head_len); | |
b92e08fc JM |
3192 | wpa_hexdump(MSG_DEBUG, "nl80211: Beacon tail", |
3193 | params->tail, params->tail_len); | |
13f83980 | 3194 | wpa_printf(MSG_DEBUG, "nl80211: ifindex=%d", bss->ifindex); |
b92e08fc | 3195 | wpa_printf(MSG_DEBUG, "nl80211: beacon_int=%d", params->beacon_int); |
b92e08fc | 3196 | wpa_printf(MSG_DEBUG, "nl80211: dtim_period=%d", params->dtim_period); |
b92e08fc JM |
3197 | wpa_hexdump_ascii(MSG_DEBUG, "nl80211: ssid", |
3198 | params->ssid, params->ssid_len); | |
13f83980 | 3199 | if (!(msg = nl80211_bss_msg(bss, 0, cmd)) || |
a862e4a3 JM |
3200 | nla_put(msg, NL80211_ATTR_BEACON_HEAD, params->head_len, |
3201 | params->head) || | |
3202 | nla_put(msg, NL80211_ATTR_BEACON_TAIL, params->tail_len, | |
3203 | params->tail) || | |
a862e4a3 JM |
3204 | nla_put_u32(msg, NL80211_ATTR_BEACON_INTERVAL, |
3205 | params->beacon_int) || | |
3206 | nla_put_u32(msg, NL80211_ATTR_DTIM_PERIOD, params->dtim_period) || | |
3207 | nla_put(msg, NL80211_ATTR_SSID, params->ssid_len, params->ssid)) | |
3208 | goto fail; | |
b92e08fc JM |
3209 | if (params->proberesp && params->proberesp_len) { |
3210 | wpa_hexdump(MSG_DEBUG, "nl80211: proberesp (offload)", | |
3211 | params->proberesp, params->proberesp_len); | |
a862e4a3 JM |
3212 | if (nla_put(msg, NL80211_ATTR_PROBE_RESP, params->proberesp_len, |
3213 | params->proberesp)) | |
3214 | goto fail; | |
b92e08fc | 3215 | } |
97a7a0b5 JM |
3216 | switch (params->hide_ssid) { |
3217 | case NO_SSID_HIDING: | |
b92e08fc | 3218 | wpa_printf(MSG_DEBUG, "nl80211: hidden SSID not in use"); |
a862e4a3 JM |
3219 | if (nla_put_u32(msg, NL80211_ATTR_HIDDEN_SSID, |
3220 | NL80211_HIDDEN_SSID_NOT_IN_USE)) | |
3221 | goto fail; | |
97a7a0b5 JM |
3222 | break; |
3223 | case HIDDEN_SSID_ZERO_LEN: | |
b92e08fc | 3224 | wpa_printf(MSG_DEBUG, "nl80211: hidden SSID zero len"); |
a862e4a3 JM |
3225 | if (nla_put_u32(msg, NL80211_ATTR_HIDDEN_SSID, |
3226 | NL80211_HIDDEN_SSID_ZERO_LEN)) | |
3227 | goto fail; | |
97a7a0b5 JM |
3228 | break; |
3229 | case HIDDEN_SSID_ZERO_CONTENTS: | |
b92e08fc | 3230 | wpa_printf(MSG_DEBUG, "nl80211: hidden SSID zero contents"); |
a862e4a3 JM |
3231 | if (nla_put_u32(msg, NL80211_ATTR_HIDDEN_SSID, |
3232 | NL80211_HIDDEN_SSID_ZERO_CONTENTS)) | |
3233 | goto fail; | |
97a7a0b5 JM |
3234 | break; |
3235 | } | |
b92e08fc | 3236 | wpa_printf(MSG_DEBUG, "nl80211: privacy=%d", params->privacy); |
a862e4a3 JM |
3237 | if (params->privacy && |
3238 | nla_put_flag(msg, NL80211_ATTR_PRIVACY)) | |
3239 | goto fail; | |
b92e08fc | 3240 | wpa_printf(MSG_DEBUG, "nl80211: auth_algs=0x%x", params->auth_algs); |
b11d1d64 JM |
3241 | if ((params->auth_algs & (WPA_AUTH_ALG_OPEN | WPA_AUTH_ALG_SHARED)) == |
3242 | (WPA_AUTH_ALG_OPEN | WPA_AUTH_ALG_SHARED)) { | |
3243 | /* Leave out the attribute */ | |
a862e4a3 JM |
3244 | } else if (params->auth_algs & WPA_AUTH_ALG_SHARED) { |
3245 | if (nla_put_u32(msg, NL80211_ATTR_AUTH_TYPE, | |
3246 | NL80211_AUTHTYPE_SHARED_KEY)) | |
3247 | goto fail; | |
3248 | } else { | |
3249 | if (nla_put_u32(msg, NL80211_ATTR_AUTH_TYPE, | |
3250 | NL80211_AUTHTYPE_OPEN_SYSTEM)) | |
3251 | goto fail; | |
3252 | } | |
b11d1d64 | 3253 | |
b92e08fc | 3254 | wpa_printf(MSG_DEBUG, "nl80211: wpa_version=0x%x", params->wpa_version); |
b11d1d64 JM |
3255 | ver = 0; |
3256 | if (params->wpa_version & WPA_PROTO_WPA) | |
3257 | ver |= NL80211_WPA_VERSION_1; | |
3258 | if (params->wpa_version & WPA_PROTO_RSN) | |
3259 | ver |= NL80211_WPA_VERSION_2; | |
a862e4a3 JM |
3260 | if (ver && |
3261 | nla_put_u32(msg, NL80211_ATTR_WPA_VERSIONS, ver)) | |
3262 | goto fail; | |
b11d1d64 | 3263 | |
b92e08fc JM |
3264 | wpa_printf(MSG_DEBUG, "nl80211: key_mgmt_suites=0x%x", |
3265 | params->key_mgmt_suites); | |
b11d1d64 JM |
3266 | num_suites = 0; |
3267 | if (params->key_mgmt_suites & WPA_KEY_MGMT_IEEE8021X) | |
3268 | suites[num_suites++] = WLAN_AKM_SUITE_8021X; | |
3269 | if (params->key_mgmt_suites & WPA_KEY_MGMT_PSK) | |
3270 | suites[num_suites++] = WLAN_AKM_SUITE_PSK; | |
a862e4a3 JM |
3271 | if (num_suites && |
3272 | nla_put(msg, NL80211_ATTR_AKM_SUITES, num_suites * sizeof(u32), | |
3273 | suites)) | |
3274 | goto fail; | |
b11d1d64 | 3275 | |
533fe09b | 3276 | if (params->key_mgmt_suites & WPA_KEY_MGMT_IEEE8021X_NO_WPA && |
a862e4a3 JM |
3277 | params->pairwise_ciphers & (WPA_CIPHER_WEP104 | WPA_CIPHER_WEP40) && |
3278 | nla_put_flag(msg, NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT)) | |
3279 | goto fail; | |
9f12614b | 3280 | |
b92e08fc JM |
3281 | wpa_printf(MSG_DEBUG, "nl80211: pairwise_ciphers=0x%x", |
3282 | params->pairwise_ciphers); | |
de4ed4a8 JM |
3283 | num_suites = wpa_cipher_to_cipher_suites(params->pairwise_ciphers, |
3284 | suites, ARRAY_SIZE(suites)); | |
a862e4a3 JM |
3285 | if (num_suites && |
3286 | nla_put(msg, NL80211_ATTR_CIPHER_SUITES_PAIRWISE, | |
3287 | num_suites * sizeof(u32), suites)) | |
3288 | goto fail; | |
b11d1d64 | 3289 | |
b92e08fc JM |
3290 | wpa_printf(MSG_DEBUG, "nl80211: group_cipher=0x%x", |
3291 | params->group_cipher); | |
de4ed4a8 | 3292 | suite = wpa_cipher_to_cipher_suite(params->group_cipher); |
a862e4a3 JM |
3293 | if (suite && |
3294 | nla_put_u32(msg, NL80211_ATTR_CIPHER_SUITE_GROUP, suite)) | |
3295 | goto fail; | |
d2440ba0 | 3296 | |
da1080d7 EP |
3297 | switch (params->smps_mode) { |
3298 | case HT_CAP_INFO_SMPS_DYNAMIC: | |
3299 | wpa_printf(MSG_DEBUG, "nl80211: SMPS mode - dynamic"); | |
3300 | smps_mode = NL80211_SMPS_DYNAMIC; | |
3301 | break; | |
3302 | case HT_CAP_INFO_SMPS_STATIC: | |
3303 | wpa_printf(MSG_DEBUG, "nl80211: SMPS mode - static"); | |
3304 | smps_mode = NL80211_SMPS_STATIC; | |
3305 | break; | |
3306 | default: | |
3307 | /* invalid - fallback to smps off */ | |
3308 | case HT_CAP_INFO_SMPS_DISABLED: | |
3309 | wpa_printf(MSG_DEBUG, "nl80211: SMPS mode - off"); | |
3310 | smps_mode = NL80211_SMPS_OFF; | |
3311 | break; | |
3312 | } | |
a862e4a3 JM |
3313 | if (nla_put_u32(msg, NL80211_ATTR_SMPS_MODE, smps_mode)) |
3314 | goto fail; | |
da1080d7 | 3315 | |
fb91db56 | 3316 | if (params->beacon_ies) { |
b92e08fc JM |
3317 | wpa_hexdump_buf(MSG_DEBUG, "nl80211: beacon_ies", |
3318 | params->beacon_ies); | |
a862e4a3 JM |
3319 | if (nla_put(msg, NL80211_ATTR_IE, |
3320 | wpabuf_len(params->beacon_ies), | |
3321 | wpabuf_head(params->beacon_ies))) | |
3322 | goto fail; | |
fb91db56 JM |
3323 | } |
3324 | if (params->proberesp_ies) { | |
b92e08fc JM |
3325 | wpa_hexdump_buf(MSG_DEBUG, "nl80211: proberesp_ies", |
3326 | params->proberesp_ies); | |
a862e4a3 JM |
3327 | if (nla_put(msg, NL80211_ATTR_IE_PROBE_RESP, |
3328 | wpabuf_len(params->proberesp_ies), | |
3329 | wpabuf_head(params->proberesp_ies))) | |
3330 | goto fail; | |
fb91db56 JM |
3331 | } |
3332 | if (params->assocresp_ies) { | |
b92e08fc JM |
3333 | wpa_hexdump_buf(MSG_DEBUG, "nl80211: assocresp_ies", |
3334 | params->assocresp_ies); | |
a862e4a3 JM |
3335 | if (nla_put(msg, NL80211_ATTR_IE_ASSOC_RESP, |
3336 | wpabuf_len(params->assocresp_ies), | |
3337 | wpabuf_head(params->assocresp_ies))) | |
3338 | goto fail; | |
fb91db56 JM |
3339 | } |
3340 | ||
a0133ee1 | 3341 | if (drv->capa.flags & WPA_DRIVER_FLAGS_INACTIVITY_TIMER) { |
b92e08fc JM |
3342 | wpa_printf(MSG_DEBUG, "nl80211: ap_max_inactivity=%d", |
3343 | params->ap_max_inactivity); | |
a862e4a3 JM |
3344 | if (nla_put_u16(msg, NL80211_ATTR_INACTIVITY_TIMEOUT, |
3345 | params->ap_max_inactivity)) | |
3346 | goto fail; | |
a0133ee1 VT |
3347 | } |
3348 | ||
d2440ba0 JM |
3349 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
3350 | if (ret) { | |
3351 | wpa_printf(MSG_DEBUG, "nl80211: Beacon set failed: %d (%s)", | |
3352 | ret, strerror(-ret)); | |
b4fd6fab | 3353 | } else { |
b4fd6fab | 3354 | bss->beacon_set = 1; |
31357268 | 3355 | nl80211_set_bss(bss, params->cts_protect, params->preamble, |
d03e8d11 | 3356 | params->short_slot_time, params->ht_opmode, |
e5693c47 | 3357 | params->isolate, params->basic_rates); |
e87ef751 PX |
3358 | if (beacon_set && params->freq && |
3359 | params->freq->bandwidth != bss->bandwidth) { | |
3360 | wpa_printf(MSG_DEBUG, | |
3361 | "nl80211: Update BSS %s bandwidth: %d -> %d", | |
3362 | bss->ifname, bss->bandwidth, | |
3363 | params->freq->bandwidth); | |
3364 | ret = nl80211_set_channel(bss, params->freq, 1); | |
3365 | if (ret) { | |
3366 | wpa_printf(MSG_DEBUG, | |
3367 | "nl80211: Frequency set failed: %d (%s)", | |
3368 | ret, strerror(-ret)); | |
3369 | } else { | |
3370 | wpa_printf(MSG_DEBUG, | |
3371 | "nl80211: Frequency set succeeded for ht2040 coex"); | |
3372 | bss->bandwidth = params->freq->bandwidth; | |
3373 | } | |
3374 | } else if (!beacon_set) { | |
3375 | /* | |
3376 | * cfg80211 updates the driver on frequence change in AP | |
3377 | * mode only at the point when beaconing is started, so | |
3378 | * set the initial value here. | |
3379 | */ | |
3380 | bss->bandwidth = params->freq->bandwidth; | |
3381 | } | |
b4fd6fab | 3382 | } |
d2440ba0 | 3383 | return ret; |
a862e4a3 | 3384 | fail: |
5883168a | 3385 | nlmsg_free(msg); |
d2440ba0 JM |
3386 | return -ENOBUFS; |
3387 | } | |
3388 | ||
3389 | ||
1c4ffa87 | 3390 | static int nl80211_put_freq_params(struct nl_msg *msg, |
72b2605f | 3391 | const struct hostapd_freq_params *freq) |
1581b38b | 3392 | { |
a862e4a3 JM |
3393 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq->freq)) |
3394 | return -ENOBUFS; | |
3395 | ||
89b800d7 | 3396 | if (freq->vht_enabled) { |
a862e4a3 JM |
3397 | enum nl80211_chan_width cw; |
3398 | ||
89b800d7 JB |
3399 | switch (freq->bandwidth) { |
3400 | case 20: | |
a862e4a3 | 3401 | cw = NL80211_CHAN_WIDTH_20; |
89b800d7 JB |
3402 | break; |
3403 | case 40: | |
a862e4a3 | 3404 | cw = NL80211_CHAN_WIDTH_40; |
89b800d7 JB |
3405 | break; |
3406 | case 80: | |
3407 | if (freq->center_freq2) | |
a862e4a3 | 3408 | cw = NL80211_CHAN_WIDTH_80P80; |
89b800d7 | 3409 | else |
a862e4a3 | 3410 | cw = NL80211_CHAN_WIDTH_80; |
89b800d7 JB |
3411 | break; |
3412 | case 160: | |
a862e4a3 | 3413 | cw = NL80211_CHAN_WIDTH_160; |
89b800d7 JB |
3414 | break; |
3415 | default: | |
1c4ffa87 | 3416 | return -EINVAL; |
89b800d7 | 3417 | } |
a862e4a3 JM |
3418 | |
3419 | if (nla_put_u32(msg, NL80211_ATTR_CHANNEL_WIDTH, cw) || | |
3420 | nla_put_u32(msg, NL80211_ATTR_CENTER_FREQ1, | |
3421 | freq->center_freq1) || | |
3422 | (freq->center_freq2 && | |
3423 | nla_put_u32(msg, NL80211_ATTR_CENTER_FREQ2, | |
3424 | freq->center_freq2))) | |
3425 | return -ENOBUFS; | |
89b800d7 | 3426 | } else if (freq->ht_enabled) { |
a862e4a3 JM |
3427 | enum nl80211_channel_type ct; |
3428 | ||
89b800d7 | 3429 | switch (freq->sec_channel_offset) { |
f019981a | 3430 | case -1: |
a862e4a3 | 3431 | ct = NL80211_CHAN_HT40MINUS; |
f019981a JM |
3432 | break; |
3433 | case 1: | |
a862e4a3 | 3434 | ct = NL80211_CHAN_HT40PLUS; |
f019981a JM |
3435 | break; |
3436 | default: | |
a862e4a3 | 3437 | ct = NL80211_CHAN_HT20; |
f019981a JM |
3438 | break; |
3439 | } | |
a862e4a3 JM |
3440 | |
3441 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE, ct)) | |
3442 | return -ENOBUFS; | |
f019981a | 3443 | } |
1c4ffa87 | 3444 | return 0; |
1c4ffa87 AO |
3445 | } |
3446 | ||
3447 | ||
e87ef751 PX |
3448 | static int nl80211_set_channel(struct i802_bss *bss, |
3449 | struct hostapd_freq_params *freq, int set_chan) | |
1c4ffa87 AO |
3450 | { |
3451 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
3452 | struct nl_msg *msg; | |
3453 | int ret; | |
3454 | ||
3455 | wpa_printf(MSG_DEBUG, | |
3456 | "nl80211: Set freq %d (ht_enabled=%d, vht_enabled=%d, bandwidth=%d MHz, cf1=%d MHz, cf2=%d MHz)", | |
3457 | freq->freq, freq->ht_enabled, freq->vht_enabled, | |
3458 | freq->bandwidth, freq->center_freq1, freq->center_freq2); | |
1c4ffa87 | 3459 | |
9725b784 JM |
3460 | msg = nl80211_drv_msg(drv, 0, set_chan ? NL80211_CMD_SET_CHANNEL : |
3461 | NL80211_CMD_SET_WIPHY); | |
3462 | if (!msg || nl80211_put_freq_params(msg, freq) < 0) { | |
a862e4a3 JM |
3463 | nlmsg_free(msg); |
3464 | return -1; | |
3465 | } | |
1581b38b | 3466 | |
d2440ba0 | 3467 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
e4fb2167 | 3468 | if (ret == 0) { |
89b800d7 | 3469 | bss->freq = freq->freq; |
1581b38b | 3470 | return 0; |
e4fb2167 | 3471 | } |
f019981a | 3472 | wpa_printf(MSG_DEBUG, "nl80211: Failed to set channel (freq=%d): " |
89b800d7 | 3473 | "%d (%s)", freq->freq, ret, strerror(-ret)); |
1581b38b JM |
3474 | return -1; |
3475 | } | |
3476 | ||
0f4e8b4f | 3477 | |
95ab6063 AN |
3478 | static u32 sta_flags_nl80211(int flags) |
3479 | { | |
3480 | u32 f = 0; | |
3481 | ||
3482 | if (flags & WPA_STA_AUTHORIZED) | |
3483 | f |= BIT(NL80211_STA_FLAG_AUTHORIZED); | |
3484 | if (flags & WPA_STA_WMM) | |
3485 | f |= BIT(NL80211_STA_FLAG_WME); | |
3486 | if (flags & WPA_STA_SHORT_PREAMBLE) | |
3487 | f |= BIT(NL80211_STA_FLAG_SHORT_PREAMBLE); | |
3488 | if (flags & WPA_STA_MFP) | |
3489 | f |= BIT(NL80211_STA_FLAG_MFP); | |
45b722f1 AN |
3490 | if (flags & WPA_STA_TDLS_PEER) |
3491 | f |= BIT(NL80211_STA_FLAG_TDLS_PEER); | |
7a228b5c BC |
3492 | if (flags & WPA_STA_AUTHENTICATED) |
3493 | f |= BIT(NL80211_STA_FLAG_AUTHENTICATED); | |
95ab6063 AN |
3494 | |
3495 | return f; | |
3496 | } | |
3497 | ||
3498 | ||
7c7e7877 BC |
3499 | #ifdef CONFIG_MESH |
3500 | static u32 sta_plink_state_nl80211(enum mesh_plink_state state) | |
3501 | { | |
3502 | switch (state) { | |
3503 | case PLINK_LISTEN: | |
3504 | return NL80211_PLINK_LISTEN; | |
3505 | case PLINK_OPEN_SENT: | |
3506 | return NL80211_PLINK_OPN_SNT; | |
3507 | case PLINK_OPEN_RCVD: | |
3508 | return NL80211_PLINK_OPN_RCVD; | |
3509 | case PLINK_CNF_RCVD: | |
3510 | return NL80211_PLINK_CNF_RCVD; | |
3511 | case PLINK_ESTAB: | |
3512 | return NL80211_PLINK_ESTAB; | |
3513 | case PLINK_HOLDING: | |
3514 | return NL80211_PLINK_HOLDING; | |
3515 | case PLINK_BLOCKED: | |
3516 | return NL80211_PLINK_BLOCKED; | |
3517 | default: | |
3518 | wpa_printf(MSG_ERROR, "nl80211: Invalid mesh plink state %d", | |
3519 | state); | |
3520 | } | |
3521 | return -1; | |
3522 | } | |
3523 | #endif /* CONFIG_MESH */ | |
3524 | ||
3525 | ||
62847751 | 3526 | static int wpa_driver_nl80211_sta_add(void *priv, |
0f4e8b4f JM |
3527 | struct hostapd_sta_add_params *params) |
3528 | { | |
a2e40bb6 FF |
3529 | struct i802_bss *bss = priv; |
3530 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
8970bae8 | 3531 | struct nl_msg *msg; |
95ab6063 | 3532 | struct nl80211_sta_flag_update upd; |
0f4e8b4f JM |
3533 | int ret = -ENOBUFS; |
3534 | ||
45b722f1 AN |
3535 | if ((params->flags & WPA_STA_TDLS_PEER) && |
3536 | !(drv->capa.flags & WPA_DRIVER_FLAGS_TDLS_SUPPORT)) | |
3537 | return -EOPNOTSUPP; | |
3538 | ||
e4dea253 JM |
3539 | wpa_printf(MSG_DEBUG, "nl80211: %s STA " MACSTR, |
3540 | params->set ? "Set" : "Add", MAC2STR(params->addr)); | |
13f83980 JM |
3541 | msg = nl80211_bss_msg(bss, 0, params->set ? NL80211_CMD_SET_STATION : |
3542 | NL80211_CMD_NEW_STATION); | |
3543 | if (!msg || nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, params->addr)) | |
a862e4a3 | 3544 | goto fail; |
5551bc9c BC |
3545 | |
3546 | if (!params->set || (params->flags & WPA_STA_TDLS_PEER)) { | |
5551bc9c BC |
3547 | wpa_hexdump(MSG_DEBUG, " * supported rates", |
3548 | params->supp_rates, params->supp_rates_len); | |
a862e4a3 JM |
3549 | wpa_printf(MSG_DEBUG, " * capability=0x%x", |
3550 | params->capability); | |
3551 | if (nla_put(msg, NL80211_ATTR_STA_SUPPORTED_RATES, | |
3552 | params->supp_rates_len, params->supp_rates) || | |
3553 | nla_put_u16(msg, NL80211_ATTR_STA_CAPABILITY, | |
3554 | params->capability)) | |
3555 | goto fail; | |
e503861f JM |
3556 | |
3557 | if (params->ht_capabilities) { | |
3558 | wpa_hexdump(MSG_DEBUG, " * ht_capabilities", | |
3559 | (u8 *) params->ht_capabilities, | |
3560 | sizeof(*params->ht_capabilities)); | |
a862e4a3 JM |
3561 | if (nla_put(msg, NL80211_ATTR_HT_CAPABILITY, |
3562 | sizeof(*params->ht_capabilities), | |
3563 | params->ht_capabilities)) | |
3564 | goto fail; | |
e503861f JM |
3565 | } |
3566 | ||
3567 | if (params->vht_capabilities) { | |
3568 | wpa_hexdump(MSG_DEBUG, " * vht_capabilities", | |
3569 | (u8 *) params->vht_capabilities, | |
3570 | sizeof(*params->vht_capabilities)); | |
a862e4a3 JM |
3571 | if (nla_put(msg, NL80211_ATTR_VHT_CAPABILITY, |
3572 | sizeof(*params->vht_capabilities), | |
3573 | params->vht_capabilities)) | |
3574 | goto fail; | |
e503861f JM |
3575 | } |
3576 | ||
e503861f JM |
3577 | if (params->ext_capab) { |
3578 | wpa_hexdump(MSG_DEBUG, " * ext_capab", | |
3579 | params->ext_capab, params->ext_capab_len); | |
a862e4a3 JM |
3580 | if (nla_put(msg, NL80211_ATTR_STA_EXT_CAPABILITY, |
3581 | params->ext_capab_len, params->ext_capab)) | |
3582 | goto fail; | |
e503861f | 3583 | } |
5551bc9c | 3584 | } |
45b722f1 | 3585 | if (!params->set) { |
f11b72c3 JM |
3586 | if (params->aid) { |
3587 | wpa_printf(MSG_DEBUG, " * aid=%u", params->aid); | |
a862e4a3 JM |
3588 | if (nla_put_u16(msg, NL80211_ATTR_STA_AID, params->aid)) |
3589 | goto fail; | |
f11b72c3 JM |
3590 | } else { |
3591 | /* | |
3592 | * cfg80211 validates that AID is non-zero, so we have | |
3593 | * to make this a non-zero value for the TDLS case where | |
3594 | * a dummy STA entry is used for now. | |
3595 | */ | |
3596 | wpa_printf(MSG_DEBUG, " * aid=1 (TDLS workaround)"); | |
a862e4a3 JM |
3597 | if (nla_put_u16(msg, NL80211_ATTR_STA_AID, 1)) |
3598 | goto fail; | |
f11b72c3 | 3599 | } |
e4dea253 JM |
3600 | wpa_printf(MSG_DEBUG, " * listen_interval=%u", |
3601 | params->listen_interval); | |
a862e4a3 JM |
3602 | if (nla_put_u16(msg, NL80211_ATTR_STA_LISTEN_INTERVAL, |
3603 | params->listen_interval)) | |
3604 | goto fail; | |
e112764e JM |
3605 | } else if (params->aid && (params->flags & WPA_STA_TDLS_PEER)) { |
3606 | wpa_printf(MSG_DEBUG, " * peer_aid=%u", params->aid); | |
a862e4a3 JM |
3607 | if (nla_put_u16(msg, NL80211_ATTR_PEER_AID, params->aid)) |
3608 | goto fail; | |
45b722f1 | 3609 | } |
05a8d422 | 3610 | |
8a458116 MK |
3611 | if (params->vht_opmode_enabled) { |
3612 | wpa_printf(MSG_DEBUG, " * opmode=%u", params->vht_opmode); | |
a862e4a3 JM |
3613 | if (nla_put_u8(msg, NL80211_ATTR_OPMODE_NOTIF, |
3614 | params->vht_opmode)) | |
3615 | goto fail; | |
8a458116 MK |
3616 | } |
3617 | ||
efc64886 SD |
3618 | if (params->supp_channels) { |
3619 | wpa_hexdump(MSG_DEBUG, " * supported channels", | |
3620 | params->supp_channels, params->supp_channels_len); | |
a862e4a3 JM |
3621 | if (nla_put(msg, NL80211_ATTR_STA_SUPPORTED_CHANNELS, |
3622 | params->supp_channels_len, params->supp_channels)) | |
3623 | goto fail; | |
efc64886 SD |
3624 | } |
3625 | ||
3626 | if (params->supp_oper_classes) { | |
3627 | wpa_hexdump(MSG_DEBUG, " * supported operating classes", | |
3628 | params->supp_oper_classes, | |
3629 | params->supp_oper_classes_len); | |
a862e4a3 JM |
3630 | if (nla_put(msg, NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES, |
3631 | params->supp_oper_classes_len, | |
3632 | params->supp_oper_classes)) | |
3633 | goto fail; | |
efc64886 SD |
3634 | } |
3635 | ||
95ab6063 | 3636 | os_memset(&upd, 0, sizeof(upd)); |
7e31703e BC |
3637 | upd.set = sta_flags_nl80211(params->flags); |
3638 | upd.mask = upd.set | sta_flags_nl80211(params->flags_mask); | |
e4dea253 JM |
3639 | wpa_printf(MSG_DEBUG, " * flags set=0x%x mask=0x%x", |
3640 | upd.set, upd.mask); | |
a862e4a3 JM |
3641 | if (nla_put(msg, NL80211_ATTR_STA_FLAGS2, sizeof(upd), &upd)) |
3642 | goto fail; | |
95ab6063 | 3643 | |
7c7e7877 | 3644 | #ifdef CONFIG_MESH |
a862e4a3 JM |
3645 | if (params->plink_state && |
3646 | nla_put_u8(msg, NL80211_ATTR_STA_PLINK_STATE, | |
3647 | sta_plink_state_nl80211(params->plink_state))) | |
3648 | goto fail; | |
7c7e7877 BC |
3649 | #endif /* CONFIG_MESH */ |
3650 | ||
774bfa62 | 3651 | if (params->flags & WPA_STA_WMM) { |
8970bae8 JB |
3652 | struct nlattr *wme = nla_nest_start(msg, NL80211_ATTR_STA_WME); |
3653 | ||
e4dea253 | 3654 | wpa_printf(MSG_DEBUG, " * qosinfo=0x%x", params->qosinfo); |
a862e4a3 JM |
3655 | if (!wme || |
3656 | nla_put_u8(msg, NL80211_STA_WME_UAPSD_QUEUES, | |
3657 | params->qosinfo & WMM_QOSINFO_STA_AC_MASK) || | |
3658 | nla_put_u8(msg, NL80211_STA_WME_MAX_SP, | |
3659 | (params->qosinfo >> WMM_QOSINFO_STA_SP_SHIFT) & | |
3660 | WMM_QOSINFO_STA_SP_MASK)) | |
3661 | goto fail; | |
8970bae8 | 3662 | nla_nest_end(msg, wme); |
774bfa62 EP |
3663 | } |
3664 | ||
0f4e8b4f | 3665 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
5883168a | 3666 | msg = NULL; |
0f4e8b4f | 3667 | if (ret) |
45b722f1 AN |
3668 | wpa_printf(MSG_DEBUG, "nl80211: NL80211_CMD_%s_STATION " |
3669 | "result: %d (%s)", params->set ? "SET" : "NEW", ret, | |
3670 | strerror(-ret)); | |
0f4e8b4f JM |
3671 | if (ret == -EEXIST) |
3672 | ret = 0; | |
a862e4a3 | 3673 | fail: |
5883168a | 3674 | nlmsg_free(msg); |
0f4e8b4f JM |
3675 | return ret; |
3676 | } | |
3677 | ||
3678 | ||
97ed9a06 KP |
3679 | static void rtnl_neigh_delete_fdb_entry(struct i802_bss *bss, const u8 *addr) |
3680 | { | |
3681 | #ifdef CONFIG_LIBNL3_ROUTE | |
3682 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
3683 | struct rtnl_neigh *rn; | |
3684 | struct nl_addr *nl_addr; | |
3685 | int err; | |
3686 | ||
3687 | rn = rtnl_neigh_alloc(); | |
3688 | if (!rn) | |
3689 | return; | |
3690 | ||
3691 | rtnl_neigh_set_family(rn, AF_BRIDGE); | |
3692 | rtnl_neigh_set_ifindex(rn, bss->ifindex); | |
3693 | nl_addr = nl_addr_build(AF_BRIDGE, (void *) addr, ETH_ALEN); | |
3694 | if (!nl_addr) { | |
3695 | rtnl_neigh_put(rn); | |
3696 | return; | |
3697 | } | |
3698 | rtnl_neigh_set_lladdr(rn, nl_addr); | |
3699 | ||
3700 | err = rtnl_neigh_delete(drv->rtnl_sk, rn, 0); | |
3701 | if (err < 0) { | |
3702 | wpa_printf(MSG_DEBUG, "nl80211: bridge FDB entry delete for " | |
3703 | MACSTR " ifindex=%d failed: %s", MAC2STR(addr), | |
3704 | bss->ifindex, nl_geterror(err)); | |
3705 | } else { | |
3706 | wpa_printf(MSG_DEBUG, "nl80211: deleted bridge FDB entry for " | |
3707 | MACSTR, MAC2STR(addr)); | |
3708 | } | |
3709 | ||
3710 | nl_addr_put(nl_addr); | |
3711 | rtnl_neigh_put(rn); | |
3712 | #endif /* CONFIG_LIBNL3_ROUTE */ | |
3713 | } | |
3714 | ||
3715 | ||
59d7148a JM |
3716 | static int wpa_driver_nl80211_sta_remove(struct i802_bss *bss, const u8 *addr, |
3717 | int deauth, u16 reason_code) | |
0f4e8b4f | 3718 | { |
a2e40bb6 | 3719 | struct wpa_driver_nl80211_data *drv = bss->drv; |
0f4e8b4f JM |
3720 | struct nl_msg *msg; |
3721 | int ret; | |
3722 | ||
13f83980 | 3723 | if (!(msg = nl80211_bss_msg(bss, 0, NL80211_CMD_DEL_STATION)) || |
a862e4a3 JM |
3724 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) || |
3725 | (deauth == 0 && | |
3726 | nla_put_u8(msg, NL80211_ATTR_MGMT_SUBTYPE, | |
3727 | WLAN_FC_STYPE_DISASSOC)) || | |
3728 | (deauth == 1 && | |
3729 | nla_put_u8(msg, NL80211_ATTR_MGMT_SUBTYPE, | |
3730 | WLAN_FC_STYPE_DEAUTH)) || | |
3731 | (reason_code && | |
3732 | nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason_code))) { | |
3733 | nlmsg_free(msg); | |
3734 | return -ENOBUFS; | |
3735 | } | |
0f4e8b4f JM |
3736 | |
3737 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); | |
83e7bb0e JM |
3738 | wpa_printf(MSG_DEBUG, "nl80211: sta_remove -> DEL_STATION %s " MACSTR |
3739 | " --> %d (%s)", | |
3740 | bss->ifname, MAC2STR(addr), ret, strerror(-ret)); | |
97ed9a06 KP |
3741 | |
3742 | if (drv->rtnl_sk) | |
3743 | rtnl_neigh_delete_fdb_entry(bss, addr); | |
3744 | ||
0f4e8b4f JM |
3745 | if (ret == -ENOENT) |
3746 | return 0; | |
3747 | return ret; | |
0f4e8b4f JM |
3748 | } |
3749 | ||
1581b38b | 3750 | |
f3407c66 | 3751 | void nl80211_remove_iface(struct wpa_driver_nl80211_data *drv, int ifidx) |
0915d02c JM |
3752 | { |
3753 | struct nl_msg *msg; | |
de884303 | 3754 | struct wpa_driver_nl80211_data *drv2; |
0915d02c | 3755 | |
c6e8e8e4 JM |
3756 | wpa_printf(MSG_DEBUG, "nl80211: Remove interface ifindex=%d", ifidx); |
3757 | ||
2135f224 | 3758 | /* stop listening for EAPOL on this interface */ |
de884303 JM |
3759 | dl_list_for_each(drv2, &drv->global->interfaces, |
3760 | struct wpa_driver_nl80211_data, list) | |
3761 | del_ifidx(drv2, ifidx); | |
2135f224 | 3762 | |
95376e1a | 3763 | msg = nl80211_ifindex_msg(drv, ifidx, 0, NL80211_CMD_DEL_INTERFACE); |
0915d02c JM |
3764 | if (send_and_recv_msgs(drv, msg, NULL, NULL) == 0) |
3765 | return; | |
e748062b | 3766 | wpa_printf(MSG_ERROR, "Failed to remove interface (ifidx=%d)", ifidx); |
0915d02c JM |
3767 | } |
3768 | ||
3769 | ||
a1922f93 JM |
3770 | static const char * nl80211_iftype_str(enum nl80211_iftype mode) |
3771 | { | |
3772 | switch (mode) { | |
3773 | case NL80211_IFTYPE_ADHOC: | |
3774 | return "ADHOC"; | |
3775 | case NL80211_IFTYPE_STATION: | |
3776 | return "STATION"; | |
3777 | case NL80211_IFTYPE_AP: | |
3778 | return "AP"; | |
1045ec36 JM |
3779 | case NL80211_IFTYPE_AP_VLAN: |
3780 | return "AP_VLAN"; | |
3781 | case NL80211_IFTYPE_WDS: | |
3782 | return "WDS"; | |
a1922f93 JM |
3783 | case NL80211_IFTYPE_MONITOR: |
3784 | return "MONITOR"; | |
1045ec36 JM |
3785 | case NL80211_IFTYPE_MESH_POINT: |
3786 | return "MESH_POINT"; | |
a1922f93 JM |
3787 | case NL80211_IFTYPE_P2P_CLIENT: |
3788 | return "P2P_CLIENT"; | |
3789 | case NL80211_IFTYPE_P2P_GO: | |
3790 | return "P2P_GO"; | |
7aad838c NS |
3791 | case NL80211_IFTYPE_P2P_DEVICE: |
3792 | return "P2P_DEVICE"; | |
a1922f93 JM |
3793 | default: |
3794 | return "unknown"; | |
3795 | } | |
3796 | } | |
3797 | ||
3798 | ||
a35187e7 KH |
3799 | static int nl80211_create_iface_once(struct wpa_driver_nl80211_data *drv, |
3800 | const char *ifname, | |
3801 | enum nl80211_iftype iftype, | |
d6dcfcda DS |
3802 | const u8 *addr, int wds, |
3803 | int (*handler)(struct nl_msg *, void *), | |
3804 | void *arg) | |
0915d02c | 3805 | { |
8970bae8 | 3806 | struct nl_msg *msg; |
0915d02c JM |
3807 | int ifidx; |
3808 | int ret = -ENOBUFS; | |
3809 | ||
a1922f93 JM |
3810 | wpa_printf(MSG_DEBUG, "nl80211: Create interface iftype %d (%s)", |
3811 | iftype, nl80211_iftype_str(iftype)); | |
3812 | ||
56f77852 JM |
3813 | msg = nl80211_cmd_msg(drv->first_bss, 0, NL80211_CMD_NEW_INTERFACE); |
3814 | if (!msg || | |
a862e4a3 JM |
3815 | nla_put_string(msg, NL80211_ATTR_IFNAME, ifname) || |
3816 | nla_put_u32(msg, NL80211_ATTR_IFTYPE, iftype)) | |
3817 | goto fail; | |
0915d02c JM |
3818 | |
3819 | if (iftype == NL80211_IFTYPE_MONITOR) { | |
8970bae8 | 3820 | struct nlattr *flags; |
0915d02c | 3821 | |
8970bae8 | 3822 | flags = nla_nest_start(msg, NL80211_ATTR_MNTR_FLAGS); |
a862e4a3 JM |
3823 | if (!flags || |
3824 | nla_put_flag(msg, NL80211_MNTR_FLAG_COOK_FRAMES)) | |
3825 | goto fail; | |
0915d02c | 3826 | |
8970bae8 | 3827 | nla_nest_end(msg, flags); |
fbbfcbac | 3828 | } else if (wds) { |
a862e4a3 JM |
3829 | if (nla_put_u8(msg, NL80211_ATTR_4ADDR, wds)) |
3830 | goto fail; | |
0915d02c JM |
3831 | } |
3832 | ||
52f5877a IP |
3833 | /* |
3834 | * Tell cfg80211 that the interface belongs to the socket that created | |
3835 | * it, and the interface should be deleted when the socket is closed. | |
3836 | */ | |
a862e4a3 JM |
3837 | if (nla_put_flag(msg, NL80211_ATTR_IFACE_SOCKET_OWNER)) |
3838 | goto fail; | |
52f5877a | 3839 | |
d6dcfcda | 3840 | ret = send_and_recv_msgs(drv, msg, handler, arg); |
5883168a | 3841 | msg = NULL; |
0915d02c | 3842 | if (ret) { |
a862e4a3 | 3843 | fail: |
5883168a | 3844 | nlmsg_free(msg); |
a35187e7 KH |
3845 | wpa_printf(MSG_ERROR, "Failed to create interface %s: %d (%s)", |
3846 | ifname, ret, strerror(-ret)); | |
0915d02c JM |
3847 | return ret; |
3848 | } | |
3849 | ||
f632e483 | 3850 | if (iftype == NL80211_IFTYPE_P2P_DEVICE) |
6bae92e0 | 3851 | return 0; |
6bae92e0 | 3852 | |
0915d02c | 3853 | ifidx = if_nametoindex(ifname); |
c6e8e8e4 JM |
3854 | wpa_printf(MSG_DEBUG, "nl80211: New interface %s created: ifindex=%d", |
3855 | ifname, ifidx); | |
0915d02c JM |
3856 | |
3857 | if (ifidx <= 0) | |
3858 | return -1; | |
3859 | ||
147848ec JM |
3860 | /* |
3861 | * Some virtual interfaces need to process EAPOL packets and events on | |
3862 | * the parent interface. This is used mainly with hostapd. | |
3863 | */ | |
3864 | if (drv->hostapd || | |
3865 | iftype == NL80211_IFTYPE_AP_VLAN || | |
3866 | iftype == NL80211_IFTYPE_WDS || | |
3867 | iftype == NL80211_IFTYPE_MONITOR) { | |
3868 | /* start listening for EAPOL on this interface */ | |
3869 | add_ifidx(drv, ifidx); | |
3870 | } | |
2135f224 | 3871 | |
7bfc47c3 | 3872 | if (addr && iftype != NL80211_IFTYPE_MONITOR && |
c81eff1a | 3873 | linux_set_ifhwaddr(drv->global->ioctl_sock, ifname, addr)) { |
41d931ee JM |
3874 | nl80211_remove_iface(drv, ifidx); |
3875 | return -1; | |
2135f224 | 3876 | } |
2135f224 | 3877 | |
0915d02c JM |
3878 | return ifidx; |
3879 | } | |
22a7c9d7 JM |
3880 | |
3881 | ||
f3407c66 JM |
3882 | int nl80211_create_iface(struct wpa_driver_nl80211_data *drv, |
3883 | const char *ifname, enum nl80211_iftype iftype, | |
3884 | const u8 *addr, int wds, | |
3885 | int (*handler)(struct nl_msg *, void *), | |
3886 | void *arg, int use_existing) | |
a35187e7 KH |
3887 | { |
3888 | int ret; | |
3889 | ||
d6dcfcda DS |
3890 | ret = nl80211_create_iface_once(drv, ifname, iftype, addr, wds, handler, |
3891 | arg); | |
a35187e7 | 3892 | |
ffbf1eaa | 3893 | /* if error occurred and interface exists already */ |
a35187e7 | 3894 | if (ret == -ENFILE && if_nametoindex(ifname)) { |
2aec4f3c JM |
3895 | if (use_existing) { |
3896 | wpa_printf(MSG_DEBUG, "nl80211: Continue using existing interface %s", | |
3897 | ifname); | |
6997f8ba JM |
3898 | if (addr && iftype != NL80211_IFTYPE_MONITOR && |
3899 | linux_set_ifhwaddr(drv->global->ioctl_sock, ifname, | |
3900 | addr) < 0 && | |
3901 | (linux_set_iface_flags(drv->global->ioctl_sock, | |
3902 | ifname, 0) < 0 || | |
3903 | linux_set_ifhwaddr(drv->global->ioctl_sock, ifname, | |
3904 | addr) < 0 || | |
3905 | linux_set_iface_flags(drv->global->ioctl_sock, | |
3906 | ifname, 1) < 0)) | |
3907 | return -1; | |
2aec4f3c JM |
3908 | return -ENFILE; |
3909 | } | |
a35187e7 KH |
3910 | wpa_printf(MSG_INFO, "Try to remove and re-create %s", ifname); |
3911 | ||
3912 | /* Try to remove the interface that was already there. */ | |
3913 | nl80211_remove_iface(drv, if_nametoindex(ifname)); | |
3914 | ||
3915 | /* Try to create the interface again */ | |
fbbfcbac | 3916 | ret = nl80211_create_iface_once(drv, ifname, iftype, addr, |
d6dcfcda | 3917 | wds, handler, arg); |
a35187e7 KH |
3918 | } |
3919 | ||
3e208481 JM |
3920 | if (ret >= 0 && is_p2p_net_interface(iftype)) { |
3921 | wpa_printf(MSG_DEBUG, | |
3922 | "nl80211: Interface %s created for P2P - disable 11b rates", | |
3923 | ifname); | |
4e5cb1a3 | 3924 | nl80211_disable_11b_rates(drv, ret, 1); |
3e208481 | 3925 | } |
4e5cb1a3 | 3926 | |
a35187e7 KH |
3927 | return ret; |
3928 | } | |
0915d02c | 3929 | |
2135f224 | 3930 | |
3fd1cefb JB |
3931 | static int nl80211_setup_ap(struct i802_bss *bss) |
3932 | { | |
3933 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
3934 | ||
748c0ac0 JM |
3935 | wpa_printf(MSG_DEBUG, "nl80211: Setup AP(%s) - device_ap_sme=%d use_monitor=%d", |
3936 | bss->ifname, drv->device_ap_sme, drv->use_monitor); | |
36488c05 | 3937 | |
a11241fa JB |
3938 | /* |
3939 | * Disable Probe Request reporting unless we need it in this way for | |
3940 | * devices that include the AP SME, in the other case (unless using | |
3941 | * monitor iface) we'll get it through the nl_mgmt socket instead. | |
3942 | */ | |
3943 | if (!drv->device_ap_sme) | |
3944 | wpa_driver_nl80211_probe_req_report(bss, 0); | |
3945 | ||
3946 | if (!drv->device_ap_sme && !drv->use_monitor) | |
3947 | if (nl80211_mgmt_subscribe_ap(bss)) | |
3948 | return -1; | |
3949 | ||
a6cc0602 JM |
3950 | if (drv->device_ap_sme && !drv->use_monitor) |
3951 | if (nl80211_mgmt_subscribe_ap_dev_sme(bss)) | |
3952 | return -1; | |
3953 | ||
a11241fa | 3954 | if (!drv->device_ap_sme && drv->use_monitor && |
3fd1cefb JB |
3955 | nl80211_create_monitor_interface(drv) && |
3956 | !drv->device_ap_sme) | |
3957 | return -1; | |
3958 | ||
3959 | if (drv->device_ap_sme && | |
3960 | wpa_driver_nl80211_probe_req_report(bss, 1) < 0) { | |
3961 | wpa_printf(MSG_DEBUG, "nl80211: Failed to enable " | |
3962 | "Probe Request frame reporting in AP mode"); | |
3963 | /* Try to survive without this */ | |
3964 | } | |
3965 | ||
3966 | return 0; | |
3967 | } | |
3968 | ||
3969 | ||
3970 | static void nl80211_teardown_ap(struct i802_bss *bss) | |
3971 | { | |
3972 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
3973 | ||
748c0ac0 JM |
3974 | wpa_printf(MSG_DEBUG, "nl80211: Teardown AP(%s) - device_ap_sme=%d use_monitor=%d", |
3975 | bss->ifname, drv->device_ap_sme, drv->use_monitor); | |
a6cc0602 | 3976 | if (drv->device_ap_sme) { |
3fd1cefb | 3977 | wpa_driver_nl80211_probe_req_report(bss, 0); |
a6cc0602 JM |
3978 | if (!drv->use_monitor) |
3979 | nl80211_mgmt_unsubscribe(bss, "AP teardown (dev SME)"); | |
3980 | } else if (drv->use_monitor) | |
3fd1cefb | 3981 | nl80211_remove_monitor_interface(drv); |
a11241fa | 3982 | else |
36488c05 | 3983 | nl80211_mgmt_unsubscribe(bss, "AP teardown"); |
a11241fa | 3984 | |
3fd1cefb JB |
3985 | bss->beacon_set = 0; |
3986 | } | |
3987 | ||
3988 | ||
f10bfc9a JM |
3989 | static int nl80211_send_eapol_data(struct i802_bss *bss, |
3990 | const u8 *addr, const u8 *data, | |
d12dab4c | 3991 | size_t data_len) |
f10bfc9a | 3992 | { |
d12dab4c JB |
3993 | struct sockaddr_ll ll; |
3994 | int ret; | |
3995 | ||
3996 | if (bss->drv->eapol_tx_sock < 0) { | |
3997 | wpa_printf(MSG_DEBUG, "nl80211: No socket to send EAPOL"); | |
f10bfc9a JM |
3998 | return -1; |
3999 | } | |
4000 | ||
d12dab4c JB |
4001 | os_memset(&ll, 0, sizeof(ll)); |
4002 | ll.sll_family = AF_PACKET; | |
4003 | ll.sll_ifindex = bss->ifindex; | |
4004 | ll.sll_protocol = htons(ETH_P_PAE); | |
4005 | ll.sll_halen = ETH_ALEN; | |
4006 | os_memcpy(ll.sll_addr, addr, ETH_ALEN); | |
4007 | ret = sendto(bss->drv->eapol_tx_sock, data, data_len, 0, | |
4008 | (struct sockaddr *) &ll, sizeof(ll)); | |
4009 | if (ret < 0) | |
4010 | wpa_printf(MSG_ERROR, "nl80211: EAPOL TX: %s", | |
4011 | strerror(errno)); | |
4012 | ||
4013 | return ret; | |
f10bfc9a | 4014 | } |
5fb1a232 | 4015 | |
f10bfc9a | 4016 | |
db149ac9 JM |
4017 | static const u8 rfc1042_header[6] = { 0xaa, 0xaa, 0x03, 0x00, 0x00, 0x00 }; |
4018 | ||
4019 | static int wpa_driver_nl80211_hapd_send_eapol( | |
4020 | void *priv, const u8 *addr, const u8 *data, | |
4378fc14 | 4021 | size_t data_len, int encrypt, const u8 *own_addr, u32 flags) |
db149ac9 | 4022 | { |
a2e40bb6 FF |
4023 | struct i802_bss *bss = priv; |
4024 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
db149ac9 JM |
4025 | struct ieee80211_hdr *hdr; |
4026 | size_t len; | |
4027 | u8 *pos; | |
4028 | int res; | |
4378fc14 | 4029 | int qos = flags & WPA_STA_WMM; |
db149ac9 | 4030 | |
a11241fa | 4031 | if (drv->device_ap_sme || !drv->use_monitor) |
d12dab4c | 4032 | return nl80211_send_eapol_data(bss, addr, data, data_len); |
f10bfc9a | 4033 | |
db149ac9 JM |
4034 | len = sizeof(*hdr) + (qos ? 2 : 0) + sizeof(rfc1042_header) + 2 + |
4035 | data_len; | |
4036 | hdr = os_zalloc(len); | |
4037 | if (hdr == NULL) { | |
7ac3616d JM |
4038 | wpa_printf(MSG_INFO, "nl80211: Failed to allocate EAPOL buffer(len=%lu)", |
4039 | (unsigned long) len); | |
db149ac9 JM |
4040 | return -1; |
4041 | } | |
4042 | ||
4043 | hdr->frame_control = | |
4044 | IEEE80211_FC(WLAN_FC_TYPE_DATA, WLAN_FC_STYPE_DATA); | |
4045 | hdr->frame_control |= host_to_le16(WLAN_FC_FROMDS); | |
4046 | if (encrypt) | |
4047 | hdr->frame_control |= host_to_le16(WLAN_FC_ISWEP); | |
db149ac9 JM |
4048 | if (qos) { |
4049 | hdr->frame_control |= | |
4050 | host_to_le16(WLAN_FC_STYPE_QOS_DATA << 4); | |
4051 | } | |
db149ac9 JM |
4052 | |
4053 | memcpy(hdr->IEEE80211_DA_FROMDS, addr, ETH_ALEN); | |
4054 | memcpy(hdr->IEEE80211_BSSID_FROMDS, own_addr, ETH_ALEN); | |
4055 | memcpy(hdr->IEEE80211_SA_FROMDS, own_addr, ETH_ALEN); | |
4056 | pos = (u8 *) (hdr + 1); | |
4057 | ||
db149ac9 | 4058 | if (qos) { |
92d521d8 FF |
4059 | /* Set highest priority in QoS header */ |
4060 | pos[0] = 7; | |
db149ac9 JM |
4061 | pos[1] = 0; |
4062 | pos += 2; | |
4063 | } | |
db149ac9 JM |
4064 | |
4065 | memcpy(pos, rfc1042_header, sizeof(rfc1042_header)); | |
4066 | pos += sizeof(rfc1042_header); | |
4067 | WPA_PUT_BE16(pos, ETH_P_PAE); | |
4068 | pos += 2; | |
4069 | memcpy(pos, data, data_len); | |
4070 | ||
55231068 JM |
4071 | res = wpa_driver_nl80211_send_frame(bss, (u8 *) hdr, len, encrypt, 0, |
4072 | 0, 0, 0, 0); | |
db149ac9 JM |
4073 | if (res < 0) { |
4074 | wpa_printf(MSG_ERROR, "i802_send_eapol - packet len: %lu - " | |
4075 | "failed: %d (%s)", | |
4076 | (unsigned long) len, errno, strerror(errno)); | |
4077 | } | |
7bf12757 | 4078 | os_free(hdr); |
db149ac9 JM |
4079 | |
4080 | return res; | |
4081 | } | |
4082 | ||
a8d6ffa4 | 4083 | |
3234cba4 JM |
4084 | static int wpa_driver_nl80211_sta_set_flags(void *priv, const u8 *addr, |
4085 | int total_flags, | |
4c32757d | 4086 | int flags_or, int flags_and) |
a8d6ffa4 | 4087 | { |
a2e40bb6 | 4088 | struct i802_bss *bss = priv; |
8970bae8 JB |
4089 | struct nl_msg *msg; |
4090 | struct nlattr *flags; | |
7e76ee9c | 4091 | struct nl80211_sta_flag_update upd; |
a8d6ffa4 | 4092 | |
0cd9846c JM |
4093 | wpa_printf(MSG_DEBUG, "nl80211: Set STA flags - ifname=%s addr=" MACSTR |
4094 | " total_flags=0x%x flags_or=0x%x flags_and=0x%x authorized=%d", | |
4095 | bss->ifname, MAC2STR(addr), total_flags, flags_or, flags_and, | |
4096 | !!(total_flags & WPA_STA_AUTHORIZED)); | |
4097 | ||
13f83980 | 4098 | if (!(msg = nl80211_bss_msg(bss, 0, NL80211_CMD_SET_STATION)) || |
a862e4a3 JM |
4099 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) |
4100 | goto fail; | |
a8d6ffa4 | 4101 | |
7e76ee9c JM |
4102 | /* |
4103 | * Backwards compatibility version using NL80211_ATTR_STA_FLAGS. This | |
4104 | * can be removed eventually. | |
4105 | */ | |
8970bae8 | 4106 | flags = nla_nest_start(msg, NL80211_ATTR_STA_FLAGS); |
a862e4a3 JM |
4107 | if (!flags || |
4108 | ((total_flags & WPA_STA_AUTHORIZED) && | |
4109 | nla_put_flag(msg, NL80211_STA_FLAG_AUTHORIZED)) || | |
4110 | ((total_flags & WPA_STA_WMM) && | |
4111 | nla_put_flag(msg, NL80211_STA_FLAG_WME)) || | |
4112 | ((total_flags & WPA_STA_SHORT_PREAMBLE) && | |
4113 | nla_put_flag(msg, NL80211_STA_FLAG_SHORT_PREAMBLE)) || | |
4114 | ((total_flags & WPA_STA_MFP) && | |
4115 | nla_put_flag(msg, NL80211_STA_FLAG_MFP)) || | |
4116 | ((total_flags & WPA_STA_TDLS_PEER) && | |
4117 | nla_put_flag(msg, NL80211_STA_FLAG_TDLS_PEER))) | |
4118 | goto fail; | |
45b722f1 | 4119 | |
8970bae8 | 4120 | nla_nest_end(msg, flags); |
a8d6ffa4 | 4121 | |
7e76ee9c JM |
4122 | os_memset(&upd, 0, sizeof(upd)); |
4123 | upd.mask = sta_flags_nl80211(flags_or | ~flags_and); | |
4124 | upd.set = sta_flags_nl80211(flags_or); | |
a862e4a3 JM |
4125 | if (nla_put(msg, NL80211_ATTR_STA_FLAGS2, sizeof(upd), &upd)) |
4126 | goto fail; | |
7e76ee9c | 4127 | |
13f83980 | 4128 | return send_and_recv_msgs(bss->drv, msg, NULL, NULL); |
a862e4a3 | 4129 | fail: |
5883168a | 4130 | nlmsg_free(msg); |
a8d6ffa4 JM |
4131 | return -ENOBUFS; |
4132 | } | |
4133 | ||
0915d02c | 4134 | |
1581b38b JM |
4135 | static int wpa_driver_nl80211_ap(struct wpa_driver_nl80211_data *drv, |
4136 | struct wpa_driver_associate_params *params) | |
4137 | { | |
708bc8e0 | 4138 | enum nl80211_iftype nlmode, old_mode; |
b1f625e0 EP |
4139 | |
4140 | if (params->p2p) { | |
046b26a2 JM |
4141 | wpa_printf(MSG_DEBUG, "nl80211: Setup AP operations for P2P " |
4142 | "group (GO)"); | |
b1f625e0 EP |
4143 | nlmode = NL80211_IFTYPE_P2P_GO; |
4144 | } else | |
4145 | nlmode = NL80211_IFTYPE_AP; | |
4146 | ||
708bc8e0 | 4147 | old_mode = drv->nlmode; |
834ee56f | 4148 | if (wpa_driver_nl80211_set_mode(drv->first_bss, nlmode)) { |
708bc8e0 JM |
4149 | nl80211_remove_monitor_interface(drv); |
4150 | return -1; | |
4151 | } | |
4152 | ||
4ec68377 | 4153 | if (nl80211_set_channel(drv->first_bss, ¶ms->freq, 0)) { |
708bc8e0 | 4154 | if (old_mode != nlmode) |
834ee56f | 4155 | wpa_driver_nl80211_set_mode(drv->first_bss, old_mode); |
460456f8 | 4156 | nl80211_remove_monitor_interface(drv); |
1581b38b | 4157 | return -1; |
0915d02c | 4158 | } |
1581b38b | 4159 | |
1581b38b JM |
4160 | return 0; |
4161 | } | |
1581b38b JM |
4162 | |
4163 | ||
666e508c JM |
4164 | static int nl80211_leave_ibss(struct wpa_driver_nl80211_data *drv, |
4165 | int reset_mode) | |
5cc4d64b JM |
4166 | { |
4167 | struct nl_msg *msg; | |
9725b784 | 4168 | int ret; |
a862e4a3 | 4169 | |
9725b784 | 4170 | msg = nl80211_drv_msg(drv, 0, NL80211_CMD_LEAVE_IBSS); |
5cc4d64b | 4171 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
5cc4d64b JM |
4172 | if (ret) { |
4173 | wpa_printf(MSG_DEBUG, "nl80211: Leave IBSS failed: ret=%d " | |
4174 | "(%s)", ret, strerror(-ret)); | |
9725b784 JM |
4175 | } else { |
4176 | wpa_printf(MSG_DEBUG, | |
4177 | "nl80211: Leave IBSS request sent successfully"); | |
5cc4d64b JM |
4178 | } |
4179 | ||
666e508c JM |
4180 | if (reset_mode && |
4181 | wpa_driver_nl80211_set_mode(drv->first_bss, | |
5d4c78fb JM |
4182 | NL80211_IFTYPE_STATION)) { |
4183 | wpa_printf(MSG_INFO, "nl80211: Failed to set interface into " | |
4184 | "station mode"); | |
4185 | } | |
4186 | ||
5cc4d64b JM |
4187 | return ret; |
4188 | } | |
4189 | ||
4190 | ||
4191 | static int wpa_driver_nl80211_ibss(struct wpa_driver_nl80211_data *drv, | |
4192 | struct wpa_driver_associate_params *params) | |
4193 | { | |
4194 | struct nl_msg *msg; | |
4195 | int ret = -1; | |
4196 | int count = 0; | |
4197 | ||
4198 | wpa_printf(MSG_DEBUG, "nl80211: Join IBSS (ifindex=%d)", drv->ifindex); | |
4199 | ||
4ec68377 | 4200 | if (wpa_driver_nl80211_set_mode_ibss(drv->first_bss, ¶ms->freq)) { |
5cc4d64b JM |
4201 | wpa_printf(MSG_INFO, "nl80211: Failed to set interface into " |
4202 | "IBSS mode"); | |
4203 | return -1; | |
4204 | } | |
4205 | ||
4206 | retry: | |
9725b784 | 4207 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_JOIN_IBSS)) || |
a862e4a3 JM |
4208 | params->ssid == NULL || params->ssid_len > sizeof(drv->ssid)) |
4209 | goto fail; | |
5cc4d64b JM |
4210 | |
4211 | wpa_hexdump_ascii(MSG_DEBUG, " * SSID", | |
4212 | params->ssid, params->ssid_len); | |
a862e4a3 JM |
4213 | if (nla_put(msg, NL80211_ATTR_SSID, params->ssid_len, params->ssid)) |
4214 | goto fail; | |
5cc4d64b JM |
4215 | os_memcpy(drv->ssid, params->ssid, params->ssid_len); |
4216 | drv->ssid_len = params->ssid_len; | |
4217 | ||
4ec68377 JD |
4218 | wpa_printf(MSG_DEBUG, " * freq=%d", params->freq.freq); |
4219 | wpa_printf(MSG_DEBUG, " * ht_enabled=%d", params->freq.ht_enabled); | |
4220 | wpa_printf(MSG_DEBUG, " * sec_channel_offset=%d", | |
4221 | params->freq.sec_channel_offset); | |
4222 | wpa_printf(MSG_DEBUG, " * vht_enabled=%d", params->freq.vht_enabled); | |
4223 | wpa_printf(MSG_DEBUG, " * center_freq1=%d", params->freq.center_freq1); | |
4224 | wpa_printf(MSG_DEBUG, " * center_freq2=%d", params->freq.center_freq2); | |
4225 | wpa_printf(MSG_DEBUG, " * bandwidth=%d", params->freq.bandwidth); | |
4226 | if (nl80211_put_freq_params(msg, ¶ms->freq) < 0) | |
a862e4a3 | 4227 | goto fail; |
5cc4d64b | 4228 | |
8f05577d JM |
4229 | if (params->beacon_int > 0) { |
4230 | wpa_printf(MSG_DEBUG, " * beacon_int=%d", params->beacon_int); | |
a862e4a3 JM |
4231 | if (nla_put_u32(msg, NL80211_ATTR_BEACON_INTERVAL, |
4232 | params->beacon_int)) | |
4233 | goto fail; | |
8f05577d JM |
4234 | } |
4235 | ||
5cc4d64b JM |
4236 | ret = nl80211_set_conn_keys(params, msg); |
4237 | if (ret) | |
a862e4a3 | 4238 | goto fail; |
5cc4d64b | 4239 | |
913e3cf7 NC |
4240 | if (params->bssid && params->fixed_bssid) { |
4241 | wpa_printf(MSG_DEBUG, " * BSSID=" MACSTR, | |
4242 | MAC2STR(params->bssid)); | |
a862e4a3 JM |
4243 | if (nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, params->bssid)) |
4244 | goto fail; | |
913e3cf7 NC |
4245 | } |
4246 | ||
4848a38d JM |
4247 | if (params->key_mgmt_suite == WPA_KEY_MGMT_IEEE8021X || |
4248 | params->key_mgmt_suite == WPA_KEY_MGMT_PSK || | |
4249 | params->key_mgmt_suite == WPA_KEY_MGMT_IEEE8021X_SHA256 || | |
4250 | params->key_mgmt_suite == WPA_KEY_MGMT_PSK_SHA256) { | |
e640888c | 4251 | wpa_printf(MSG_DEBUG, " * control port"); |
a862e4a3 JM |
4252 | if (nla_put_flag(msg, NL80211_ATTR_CONTROL_PORT)) |
4253 | goto fail; | |
e640888c AQ |
4254 | } |
4255 | ||
a95795ad JM |
4256 | if (params->wpa_ie) { |
4257 | wpa_hexdump(MSG_DEBUG, | |
4258 | " * Extra IEs for Beacon/Probe Response frames", | |
4259 | params->wpa_ie, params->wpa_ie_len); | |
a862e4a3 JM |
4260 | if (nla_put(msg, NL80211_ATTR_IE, params->wpa_ie_len, |
4261 | params->wpa_ie)) | |
4262 | goto fail; | |
a95795ad JM |
4263 | } |
4264 | ||
5cc4d64b JM |
4265 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
4266 | msg = NULL; | |
4267 | if (ret) { | |
4268 | wpa_printf(MSG_DEBUG, "nl80211: Join IBSS failed: ret=%d (%s)", | |
4269 | ret, strerror(-ret)); | |
4270 | count++; | |
4271 | if (ret == -EALREADY && count == 1) { | |
4272 | wpa_printf(MSG_DEBUG, "nl80211: Retry IBSS join after " | |
4273 | "forced leave"); | |
666e508c | 4274 | nl80211_leave_ibss(drv, 0); |
5cc4d64b JM |
4275 | nlmsg_free(msg); |
4276 | goto retry; | |
4277 | } | |
a862e4a3 JM |
4278 | } else { |
4279 | wpa_printf(MSG_DEBUG, | |
4280 | "nl80211: Join IBSS request sent successfully"); | |
5cc4d64b | 4281 | } |
5cc4d64b | 4282 | |
a862e4a3 | 4283 | fail: |
5cc4d64b JM |
4284 | nlmsg_free(msg); |
4285 | return ret; | |
4286 | } | |
4287 | ||
4288 | ||
a0bdd191 JM |
4289 | static int nl80211_connect_common(struct wpa_driver_nl80211_data *drv, |
4290 | struct wpa_driver_associate_params *params, | |
4291 | struct nl_msg *msg) | |
cfaab580 | 4292 | { |
cfaab580 ZY |
4293 | if (params->bssid) { |
4294 | wpa_printf(MSG_DEBUG, " * bssid=" MACSTR, | |
4295 | MAC2STR(params->bssid)); | |
a862e4a3 JM |
4296 | if (nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, params->bssid)) |
4297 | return -1; | |
cfaab580 | 4298 | } |
a0bdd191 | 4299 | |
7ac7fd43 DS |
4300 | if (params->bssid_hint) { |
4301 | wpa_printf(MSG_DEBUG, " * bssid_hint=" MACSTR, | |
4302 | MAC2STR(params->bssid_hint)); | |
a862e4a3 JM |
4303 | if (nla_put(msg, NL80211_ATTR_MAC_HINT, ETH_ALEN, |
4304 | params->bssid_hint)) | |
4305 | return -1; | |
7ac7fd43 DS |
4306 | } |
4307 | ||
4ec68377 JD |
4308 | if (params->freq.freq) { |
4309 | wpa_printf(MSG_DEBUG, " * freq=%d", params->freq.freq); | |
a862e4a3 JM |
4310 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, |
4311 | params->freq.freq)) | |
4312 | return -1; | |
4ec68377 | 4313 | drv->assoc_freq = params->freq.freq; |
30158a0d SD |
4314 | } else |
4315 | drv->assoc_freq = 0; | |
a0bdd191 | 4316 | |
7ac7fd43 DS |
4317 | if (params->freq_hint) { |
4318 | wpa_printf(MSG_DEBUG, " * freq_hint=%d", params->freq_hint); | |
a862e4a3 JM |
4319 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ_HINT, |
4320 | params->freq_hint)) | |
4321 | return -1; | |
7ac7fd43 DS |
4322 | } |
4323 | ||
1f6c0ab8 BS |
4324 | if (params->bg_scan_period >= 0) { |
4325 | wpa_printf(MSG_DEBUG, " * bg scan period=%d", | |
4326 | params->bg_scan_period); | |
a862e4a3 JM |
4327 | if (nla_put_u16(msg, NL80211_ATTR_BG_SCAN_PERIOD, |
4328 | params->bg_scan_period)) | |
4329 | return -1; | |
1f6c0ab8 | 4330 | } |
a0bdd191 | 4331 | |
cfaab580 ZY |
4332 | if (params->ssid) { |
4333 | wpa_hexdump_ascii(MSG_DEBUG, " * SSID", | |
4334 | params->ssid, params->ssid_len); | |
a862e4a3 JM |
4335 | if (nla_put(msg, NL80211_ATTR_SSID, params->ssid_len, |
4336 | params->ssid)) | |
4337 | return -1; | |
cfaab580 | 4338 | if (params->ssid_len > sizeof(drv->ssid)) |
a862e4a3 | 4339 | return -1; |
cfaab580 ZY |
4340 | os_memcpy(drv->ssid, params->ssid, params->ssid_len); |
4341 | drv->ssid_len = params->ssid_len; | |
4342 | } | |
a0bdd191 | 4343 | |
cfaab580 | 4344 | wpa_hexdump(MSG_DEBUG, " * IEs", params->wpa_ie, params->wpa_ie_len); |
a862e4a3 JM |
4345 | if (params->wpa_ie && |
4346 | nla_put(msg, NL80211_ATTR_IE, params->wpa_ie_len, params->wpa_ie)) | |
4347 | return -1; | |
cfaab580 | 4348 | |
64fa840a JM |
4349 | if (params->wpa_proto) { |
4350 | enum nl80211_wpa_versions ver = 0; | |
cfaab580 | 4351 | |
64fa840a JM |
4352 | if (params->wpa_proto & WPA_PROTO_WPA) |
4353 | ver |= NL80211_WPA_VERSION_1; | |
4354 | if (params->wpa_proto & WPA_PROTO_RSN) | |
4355 | ver |= NL80211_WPA_VERSION_2; | |
cfaab580 | 4356 | |
64fa840a | 4357 | wpa_printf(MSG_DEBUG, " * WPA Versions 0x%x", ver); |
a862e4a3 JM |
4358 | if (nla_put_u32(msg, NL80211_ATTR_WPA_VERSIONS, ver)) |
4359 | return -1; | |
cfaab580 ZY |
4360 | } |
4361 | ||
4848a38d | 4362 | if (params->pairwise_suite != WPA_CIPHER_NONE) { |
a0bdd191 JM |
4363 | u32 cipher = wpa_cipher_to_cipher_suite(params->pairwise_suite); |
4364 | wpa_printf(MSG_DEBUG, " * pairwise=0x%x", cipher); | |
a862e4a3 JM |
4365 | if (nla_put_u32(msg, NL80211_ATTR_CIPHER_SUITES_PAIRWISE, |
4366 | cipher)) | |
4367 | return -1; | |
cfaab580 ZY |
4368 | } |
4369 | ||
ae6f9272 JM |
4370 | if (params->group_suite == WPA_CIPHER_GTK_NOT_USED && |
4371 | !(drv->capa.enc & WPA_DRIVER_CAPA_ENC_GTK_NOT_USED)) { | |
4372 | /* | |
4373 | * This is likely to work even though many drivers do not | |
4374 | * advertise support for operations without GTK. | |
4375 | */ | |
4376 | wpa_printf(MSG_DEBUG, " * skip group cipher configuration for GTK_NOT_USED due to missing driver support advertisement"); | |
4377 | } else if (params->group_suite != WPA_CIPHER_NONE) { | |
a0bdd191 JM |
4378 | u32 cipher = wpa_cipher_to_cipher_suite(params->group_suite); |
4379 | wpa_printf(MSG_DEBUG, " * group=0x%x", cipher); | |
a862e4a3 JM |
4380 | if (nla_put_u32(msg, NL80211_ATTR_CIPHER_SUITE_GROUP, cipher)) |
4381 | return -1; | |
cfaab580 ZY |
4382 | } |
4383 | ||
4848a38d JM |
4384 | if (params->key_mgmt_suite == WPA_KEY_MGMT_IEEE8021X || |
4385 | params->key_mgmt_suite == WPA_KEY_MGMT_PSK || | |
4386 | params->key_mgmt_suite == WPA_KEY_MGMT_FT_IEEE8021X || | |
4387 | params->key_mgmt_suite == WPA_KEY_MGMT_FT_PSK || | |
163f801e | 4388 | params->key_mgmt_suite == WPA_KEY_MGMT_CCKM || |
8802326f JJ |
4389 | params->key_mgmt_suite == WPA_KEY_MGMT_OSEN || |
4390 | params->key_mgmt_suite == WPA_KEY_MGMT_IEEE8021X_SHA256 || | |
666497c8 JM |
4391 | params->key_mgmt_suite == WPA_KEY_MGMT_PSK_SHA256 || |
4392 | params->key_mgmt_suite == WPA_KEY_MGMT_IEEE8021X_SUITE_B) { | |
cfaab580 ZY |
4393 | int mgmt = WLAN_AKM_SUITE_PSK; |
4394 | ||
4395 | switch (params->key_mgmt_suite) { | |
4848a38d | 4396 | case WPA_KEY_MGMT_CCKM: |
369c8d7b JM |
4397 | mgmt = WLAN_AKM_SUITE_CCKM; |
4398 | break; | |
4848a38d | 4399 | case WPA_KEY_MGMT_IEEE8021X: |
cfaab580 ZY |
4400 | mgmt = WLAN_AKM_SUITE_8021X; |
4401 | break; | |
4848a38d | 4402 | case WPA_KEY_MGMT_FT_IEEE8021X: |
6a1ce395 DG |
4403 | mgmt = WLAN_AKM_SUITE_FT_8021X; |
4404 | break; | |
4848a38d | 4405 | case WPA_KEY_MGMT_FT_PSK: |
6a1ce395 DG |
4406 | mgmt = WLAN_AKM_SUITE_FT_PSK; |
4407 | break; | |
8802326f JJ |
4408 | case WPA_KEY_MGMT_IEEE8021X_SHA256: |
4409 | mgmt = WLAN_AKM_SUITE_8021X_SHA256; | |
4410 | break; | |
4411 | case WPA_KEY_MGMT_PSK_SHA256: | |
4412 | mgmt = WLAN_AKM_SUITE_PSK_SHA256; | |
4413 | break; | |
163f801e JM |
4414 | case WPA_KEY_MGMT_OSEN: |
4415 | mgmt = WLAN_AKM_SUITE_OSEN; | |
4416 | break; | |
666497c8 JM |
4417 | case WPA_KEY_MGMT_IEEE8021X_SUITE_B: |
4418 | mgmt = WLAN_AKM_SUITE_8021X_SUITE_B; | |
4419 | break; | |
4848a38d | 4420 | case WPA_KEY_MGMT_PSK: |
cfaab580 ZY |
4421 | default: |
4422 | mgmt = WLAN_AKM_SUITE_PSK; | |
4423 | break; | |
4424 | } | |
163f801e | 4425 | wpa_printf(MSG_DEBUG, " * akm=0x%x", mgmt); |
a862e4a3 JM |
4426 | if (nla_put_u32(msg, NL80211_ATTR_AKM_SUITES, mgmt)) |
4427 | return -1; | |
cfaab580 ZY |
4428 | } |
4429 | ||
a862e4a3 JM |
4430 | if (nla_put_flag(msg, NL80211_ATTR_CONTROL_PORT)) |
4431 | return -1; | |
a0bdd191 | 4432 | |
a862e4a3 JM |
4433 | if (params->mgmt_frame_protection == MGMT_FRAME_PROTECTION_REQUIRED && |
4434 | nla_put_u32(msg, NL80211_ATTR_USE_MFP, NL80211_MFP_REQUIRED)) | |
4435 | return -1; | |
a565084f | 4436 | |
58162adf AK |
4437 | if (params->rrm_used) { |
4438 | u32 drv_rrm_flags = drv->capa.rrm_flags; | |
4439 | if (!(drv_rrm_flags & | |
4440 | WPA_DRIVER_FLAGS_DS_PARAM_SET_IE_IN_PROBES) || | |
a862e4a3 JM |
4441 | !(drv_rrm_flags & WPA_DRIVER_FLAGS_QUIET) || |
4442 | nla_put_flag(msg, NL80211_ATTR_USE_RRM)) | |
4443 | return -1; | |
58162adf AK |
4444 | } |
4445 | ||
a862e4a3 JM |
4446 | if (params->disable_ht && nla_put_flag(msg, NL80211_ATTR_DISABLE_HT)) |
4447 | return -1; | |
80e8a5ee BG |
4448 | |
4449 | if (params->htcaps && params->htcaps_mask) { | |
4450 | int sz = sizeof(struct ieee80211_ht_capabilities); | |
6d99bd80 | 4451 | wpa_hexdump(MSG_DEBUG, " * htcaps", params->htcaps, sz); |
6d99bd80 JM |
4452 | wpa_hexdump(MSG_DEBUG, " * htcaps_mask", |
4453 | params->htcaps_mask, sz); | |
a862e4a3 JM |
4454 | if (nla_put(msg, NL80211_ATTR_HT_CAPABILITY, sz, |
4455 | params->htcaps) || | |
4456 | nla_put(msg, NL80211_ATTR_HT_CAPABILITY_MASK, sz, | |
4457 | params->htcaps_mask)) | |
4458 | return -1; | |
80e8a5ee BG |
4459 | } |
4460 | ||
e9ee8dc3 JB |
4461 | #ifdef CONFIG_VHT_OVERRIDES |
4462 | if (params->disable_vht) { | |
4463 | wpa_printf(MSG_DEBUG, " * VHT disabled"); | |
a862e4a3 JM |
4464 | if (nla_put_flag(msg, NL80211_ATTR_DISABLE_VHT)) |
4465 | return -1; | |
e9ee8dc3 JB |
4466 | } |
4467 | ||
4468 | if (params->vhtcaps && params->vhtcaps_mask) { | |
4469 | int sz = sizeof(struct ieee80211_vht_capabilities); | |
6d99bd80 | 4470 | wpa_hexdump(MSG_DEBUG, " * vhtcaps", params->vhtcaps, sz); |
6d99bd80 JM |
4471 | wpa_hexdump(MSG_DEBUG, " * vhtcaps_mask", |
4472 | params->vhtcaps_mask, sz); | |
a862e4a3 JM |
4473 | if (nla_put(msg, NL80211_ATTR_VHT_CAPABILITY, sz, |
4474 | params->vhtcaps) || | |
4475 | nla_put(msg, NL80211_ATTR_VHT_CAPABILITY_MASK, sz, | |
4476 | params->vhtcaps_mask)) | |
4477 | return -1; | |
e9ee8dc3 JB |
4478 | } |
4479 | #endif /* CONFIG_VHT_OVERRIDES */ | |
4480 | ||
a0bdd191 JM |
4481 | if (params->p2p) |
4482 | wpa_printf(MSG_DEBUG, " * P2P group"); | |
4483 | ||
4484 | return 0; | |
a0bdd191 JM |
4485 | } |
4486 | ||
4487 | ||
4488 | static int wpa_driver_nl80211_try_connect( | |
4489 | struct wpa_driver_nl80211_data *drv, | |
4490 | struct wpa_driver_associate_params *params) | |
4491 | { | |
4492 | struct nl_msg *msg; | |
4493 | enum nl80211_auth_type type; | |
4494 | int ret; | |
4495 | int algs; | |
4496 | ||
b41f2684 CL |
4497 | if (params->req_key_mgmt_offload && params->psk && |
4498 | (params->key_mgmt_suite == WPA_KEY_MGMT_PSK || | |
4499 | params->key_mgmt_suite == WPA_KEY_MGMT_PSK_SHA256 || | |
4500 | params->key_mgmt_suite == WPA_KEY_MGMT_FT_PSK)) { | |
4501 | wpa_printf(MSG_DEBUG, "nl80211: Key management set PSK"); | |
4502 | ret = issue_key_mgmt_set_key(drv, params->psk, 32); | |
4503 | if (ret) | |
4504 | return ret; | |
4505 | } | |
4506 | ||
9725b784 JM |
4507 | wpa_printf(MSG_DEBUG, "nl80211: Connect (ifindex=%d)", drv->ifindex); |
4508 | msg = nl80211_drv_msg(drv, 0, NL80211_CMD_CONNECT); | |
a0bdd191 JM |
4509 | if (!msg) |
4510 | return -1; | |
4511 | ||
a0bdd191 JM |
4512 | ret = nl80211_connect_common(drv, params, msg); |
4513 | if (ret) | |
a862e4a3 | 4514 | goto fail; |
a0bdd191 JM |
4515 | |
4516 | algs = 0; | |
4517 | if (params->auth_alg & WPA_AUTH_ALG_OPEN) | |
4518 | algs++; | |
4519 | if (params->auth_alg & WPA_AUTH_ALG_SHARED) | |
4520 | algs++; | |
4521 | if (params->auth_alg & WPA_AUTH_ALG_LEAP) | |
4522 | algs++; | |
4523 | if (algs > 1) { | |
4524 | wpa_printf(MSG_DEBUG, " * Leave out Auth Type for automatic " | |
4525 | "selection"); | |
4526 | goto skip_auth_type; | |
4527 | } | |
4528 | ||
4529 | if (params->auth_alg & WPA_AUTH_ALG_OPEN) | |
4530 | type = NL80211_AUTHTYPE_OPEN_SYSTEM; | |
4531 | else if (params->auth_alg & WPA_AUTH_ALG_SHARED) | |
4532 | type = NL80211_AUTHTYPE_SHARED_KEY; | |
4533 | else if (params->auth_alg & WPA_AUTH_ALG_LEAP) | |
4534 | type = NL80211_AUTHTYPE_NETWORK_EAP; | |
4535 | else if (params->auth_alg & WPA_AUTH_ALG_FT) | |
4536 | type = NL80211_AUTHTYPE_FT; | |
4537 | else | |
a862e4a3 | 4538 | goto fail; |
a0bdd191 JM |
4539 | |
4540 | wpa_printf(MSG_DEBUG, " * Auth Type %d", type); | |
a862e4a3 JM |
4541 | if (nla_put_u32(msg, NL80211_ATTR_AUTH_TYPE, type)) |
4542 | goto fail; | |
a0bdd191 JM |
4543 | |
4544 | skip_auth_type: | |
cfaab580 ZY |
4545 | ret = nl80211_set_conn_keys(params, msg); |
4546 | if (ret) | |
a862e4a3 | 4547 | goto fail; |
cfaab580 ZY |
4548 | |
4549 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); | |
4550 | msg = NULL; | |
4551 | if (ret) { | |
4552 | wpa_printf(MSG_DEBUG, "nl80211: MLME connect failed: ret=%d " | |
4553 | "(%s)", ret, strerror(-ret)); | |
a862e4a3 JM |
4554 | } else { |
4555 | wpa_printf(MSG_DEBUG, | |
4556 | "nl80211: Connect request send successfully"); | |
cfaab580 | 4557 | } |
cfaab580 | 4558 | |
a862e4a3 | 4559 | fail: |
cfaab580 ZY |
4560 | nlmsg_free(msg); |
4561 | return ret; | |
4562 | ||
4563 | } | |
4564 | ||
4565 | ||
a8c5b43a CW |
4566 | static int wpa_driver_nl80211_connect( |
4567 | struct wpa_driver_nl80211_data *drv, | |
4568 | struct wpa_driver_associate_params *params) | |
4569 | { | |
0d4e3d1d JJ |
4570 | int ret; |
4571 | ||
4572 | /* Store the connection attempted bssid for future use */ | |
4573 | if (params->bssid) | |
4574 | os_memcpy(drv->auth_attempt_bssid, params->bssid, ETH_ALEN); | |
4575 | else | |
4576 | os_memset(drv->auth_attempt_bssid, 0, ETH_ALEN); | |
4577 | ||
4578 | ret = wpa_driver_nl80211_try_connect(drv, params); | |
a8c5b43a CW |
4579 | if (ret == -EALREADY) { |
4580 | /* | |
4581 | * cfg80211 does not currently accept new connections if | |
4582 | * we are already connected. As a workaround, force | |
4583 | * disconnection and try again. | |
4584 | */ | |
4585 | wpa_printf(MSG_DEBUG, "nl80211: Explicitly " | |
4586 | "disconnecting before reassociation " | |
4587 | "attempt"); | |
4588 | if (wpa_driver_nl80211_disconnect( | |
4589 | drv, WLAN_REASON_PREV_AUTH_NOT_VALID)) | |
4590 | return -1; | |
a8c5b43a CW |
4591 | ret = wpa_driver_nl80211_try_connect(drv, params); |
4592 | } | |
4593 | return ret; | |
4594 | } | |
4595 | ||
4596 | ||
c2a04078 JM |
4597 | static int wpa_driver_nl80211_associate( |
4598 | void *priv, struct wpa_driver_associate_params *params) | |
4599 | { | |
a2e40bb6 FF |
4600 | struct i802_bss *bss = priv; |
4601 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
a862e4a3 | 4602 | int ret = -1; |
c2a04078 JM |
4603 | struct nl_msg *msg; |
4604 | ||
4bd71954 JM |
4605 | nl80211_unmask_11b_rates(bss); |
4606 | ||
5cc4d64b | 4607 | if (params->mode == IEEE80211_MODE_AP) |
1581b38b | 4608 | return wpa_driver_nl80211_ap(drv, params); |
1581b38b | 4609 | |
5cc4d64b JM |
4610 | if (params->mode == IEEE80211_MODE_IBSS) |
4611 | return wpa_driver_nl80211_ibss(drv, params); | |
4612 | ||
4a867032 | 4613 | if (!(drv->capa.flags & WPA_DRIVER_FLAGS_SME)) { |
b1f625e0 EP |
4614 | enum nl80211_iftype nlmode = params->p2p ? |
4615 | NL80211_IFTYPE_P2P_CLIENT : NL80211_IFTYPE_STATION; | |
4616 | ||
4617 | if (wpa_driver_nl80211_set_mode(priv, nlmode) < 0) | |
4a867032 | 4618 | return -1; |
cfaab580 | 4619 | return wpa_driver_nl80211_connect(drv, params); |
4a867032 | 4620 | } |
cfaab580 | 4621 | |
add9b7a4 | 4622 | nl80211_mark_disconnected(drv); |
c2a04078 | 4623 | |
c2a04078 JM |
4624 | wpa_printf(MSG_DEBUG, "nl80211: Associate (ifindex=%d)", |
4625 | drv->ifindex); | |
9725b784 JM |
4626 | msg = nl80211_drv_msg(drv, 0, NL80211_CMD_ASSOCIATE); |
4627 | if (!msg) | |
4628 | return -1; | |
c2a04078 | 4629 | |
a0bdd191 JM |
4630 | ret = nl80211_connect_common(drv, params, msg); |
4631 | if (ret) | |
a862e4a3 | 4632 | goto fail; |
01652550 | 4633 | |
62fa124c JM |
4634 | if (params->prev_bssid) { |
4635 | wpa_printf(MSG_DEBUG, " * prev_bssid=" MACSTR, | |
4636 | MAC2STR(params->prev_bssid)); | |
a862e4a3 JM |
4637 | if (nla_put(msg, NL80211_ATTR_PREV_BSSID, ETH_ALEN, |
4638 | params->prev_bssid)) | |
4639 | goto fail; | |
62fa124c JM |
4640 | } |
4641 | ||
c2a04078 JM |
4642 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
4643 | msg = NULL; | |
4644 | if (ret) { | |
3b7ea880 BG |
4645 | wpa_dbg(drv->ctx, MSG_DEBUG, |
4646 | "nl80211: MLME command failed (assoc): ret=%d (%s)", | |
4647 | ret, strerror(-ret)); | |
8856462d | 4648 | nl80211_dump_scan(drv); |
a862e4a3 JM |
4649 | } else { |
4650 | wpa_printf(MSG_DEBUG, | |
4651 | "nl80211: Association request send successfully"); | |
c2a04078 | 4652 | } |
c2a04078 | 4653 | |
a862e4a3 | 4654 | fail: |
c2a04078 JM |
4655 | nlmsg_free(msg); |
4656 | return ret; | |
4657 | } | |
3f5285e8 JM |
4658 | |
4659 | ||
ad1e68e6 | 4660 | static int nl80211_set_mode(struct wpa_driver_nl80211_data *drv, |
a1922f93 | 4661 | int ifindex, enum nl80211_iftype mode) |
3f5285e8 | 4662 | { |
3f5285e8 | 4663 | struct nl_msg *msg; |
ad1e68e6 JM |
4664 | int ret = -ENOBUFS; |
4665 | ||
a1922f93 JM |
4666 | wpa_printf(MSG_DEBUG, "nl80211: Set mode ifindex %d iftype %d (%s)", |
4667 | ifindex, mode, nl80211_iftype_str(mode)); | |
4668 | ||
56f77852 JM |
4669 | msg = nl80211_cmd_msg(drv->first_bss, 0, NL80211_CMD_SET_INTERFACE); |
4670 | if (!msg || nla_put_u32(msg, NL80211_ATTR_IFTYPE, mode)) | |
a862e4a3 | 4671 | goto fail; |
ad1e68e6 JM |
4672 | |
4673 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); | |
5883168a | 4674 | msg = NULL; |
ad1e68e6 JM |
4675 | if (!ret) |
4676 | return 0; | |
a862e4a3 | 4677 | fail: |
5883168a | 4678 | nlmsg_free(msg); |
ad1e68e6 JM |
4679 | wpa_printf(MSG_DEBUG, "nl80211: Failed to set interface %d to mode %d:" |
4680 | " %d (%s)", ifindex, mode, ret, strerror(-ret)); | |
4681 | return ret; | |
4682 | } | |
4683 | ||
4684 | ||
3c5d34e3 CW |
4685 | static int wpa_driver_nl80211_set_mode_impl( |
4686 | struct i802_bss *bss, | |
4687 | enum nl80211_iftype nlmode, | |
4688 | struct hostapd_freq_params *desired_freq_params) | |
ad1e68e6 | 4689 | { |
a2e40bb6 | 4690 | struct wpa_driver_nl80211_data *drv = bss->drv; |
ad1e68e6 | 4691 | int ret = -1; |
26af9dca | 4692 | int i; |
86957e62 | 4693 | int was_ap = is_ap_interface(drv->nlmode); |
671a5039 | 4694 | int res; |
ebffdbc4 | 4695 | int mode_switch_res; |
1581b38b | 4696 | |
ebffdbc4 CW |
4697 | mode_switch_res = nl80211_set_mode(drv, drv->ifindex, nlmode); |
4698 | if (mode_switch_res && nlmode == nl80211_get_ifmode(bss)) | |
4699 | mode_switch_res = 0; | |
8e12685c | 4700 | |
ebffdbc4 | 4701 | if (mode_switch_res == 0) { |
ad1e68e6 | 4702 | drv->nlmode = nlmode; |
460456f8 JM |
4703 | ret = 0; |
4704 | goto done; | |
ad1e68e6 | 4705 | } |
3f5285e8 | 4706 | |
ebffdbc4 | 4707 | if (mode_switch_res == -ENODEV) |
671a5039 JM |
4708 | return -1; |
4709 | ||
460456f8 | 4710 | if (nlmode == drv->nlmode) { |
c6e8e8e4 JM |
4711 | wpa_printf(MSG_DEBUG, "nl80211: Interface already in " |
4712 | "requested mode - ignore error"); | |
460456f8 JM |
4713 | ret = 0; |
4714 | goto done; /* Already in the requested mode */ | |
4715 | } | |
3f5285e8 | 4716 | |
3f5285e8 JM |
4717 | /* mac80211 doesn't allow mode changes while the device is up, so |
4718 | * take the device down, try to set the mode again, and bring the | |
4719 | * device back up. | |
4720 | */ | |
26af9dca JM |
4721 | wpa_printf(MSG_DEBUG, "nl80211: Try mode change after setting " |
4722 | "interface down"); | |
4723 | for (i = 0; i < 10; i++) { | |
91724d6f | 4724 | res = i802_set_iface_flags(bss, 0); |
6e8183d7 JM |
4725 | if (res == -EACCES || res == -ENODEV) |
4726 | break; | |
ebffdbc4 | 4727 | if (res != 0) { |
26af9dca JM |
4728 | wpa_printf(MSG_DEBUG, "nl80211: Failed to set " |
4729 | "interface down"); | |
ebffdbc4 CW |
4730 | os_sleep(0, 100000); |
4731 | continue; | |
4732 | } | |
3c5d34e3 CW |
4733 | |
4734 | /* | |
4735 | * Setting the mode will fail for some drivers if the phy is | |
4736 | * on a frequency that the mode is disallowed in. | |
4737 | */ | |
4738 | if (desired_freq_params) { | |
bdf5ccb2 | 4739 | res = nl80211_set_channel(bss, desired_freq_params, 0); |
3c5d34e3 CW |
4740 | if (res) { |
4741 | wpa_printf(MSG_DEBUG, | |
4742 | "nl80211: Failed to set frequency on interface"); | |
4743 | } | |
4744 | } | |
4745 | ||
ebffdbc4 CW |
4746 | /* Try to set the mode again while the interface is down */ |
4747 | mode_switch_res = nl80211_set_mode(drv, drv->ifindex, nlmode); | |
4748 | if (mode_switch_res == -EBUSY) { | |
4749 | wpa_printf(MSG_DEBUG, | |
4750 | "nl80211: Delaying mode set while interface going down"); | |
4751 | os_sleep(0, 100000); | |
4752 | continue; | |
4753 | } | |
4754 | ret = mode_switch_res; | |
4755 | break; | |
3f5285e8 JM |
4756 | } |
4757 | ||
c6e8e8e4 JM |
4758 | if (!ret) { |
4759 | wpa_printf(MSG_DEBUG, "nl80211: Mode change succeeded while " | |
4760 | "interface is down"); | |
ad1e68e6 | 4761 | drv->nlmode = nlmode; |
7d9c3698 | 4762 | drv->ignore_if_down_event = 1; |
c6e8e8e4 | 4763 | } |
ad1e68e6 | 4764 | |
ebffdbc4 CW |
4765 | /* Bring the interface back up */ |
4766 | res = linux_set_iface_flags(drv->global->ioctl_sock, bss->ifname, 1); | |
4767 | if (res != 0) { | |
4768 | wpa_printf(MSG_DEBUG, | |
4769 | "nl80211: Failed to set interface up after switching mode"); | |
4770 | ret = -1; | |
4771 | } | |
4772 | ||
460456f8 | 4773 | done: |
3fd1cefb JB |
4774 | if (ret) { |
4775 | wpa_printf(MSG_DEBUG, "nl80211: Interface mode change to %d " | |
4776 | "from %d failed", nlmode, drv->nlmode); | |
4777 | return ret; | |
4778 | } | |
4779 | ||
3e208481 JM |
4780 | if (is_p2p_net_interface(nlmode)) { |
4781 | wpa_printf(MSG_DEBUG, | |
4782 | "nl80211: Interface %s mode change to P2P - disable 11b rates", | |
4783 | bss->ifname); | |
edb9bfba | 4784 | nl80211_disable_11b_rates(drv, drv->ifindex, 1); |
3e208481 JM |
4785 | } else if (drv->disabled_11b_rates) { |
4786 | wpa_printf(MSG_DEBUG, | |
4787 | "nl80211: Interface %s mode changed to non-P2P - re-enable 11b rates", | |
4788 | bss->ifname); | |
1d0c6fb1 | 4789 | nl80211_disable_11b_rates(drv, drv->ifindex, 0); |
3e208481 | 4790 | } |
edb9bfba | 4791 | |
3fd1cefb | 4792 | if (is_ap_interface(nlmode)) { |
36488c05 | 4793 | nl80211_mgmt_unsubscribe(bss, "start AP"); |
460456f8 | 4794 | /* Setup additional AP mode functionality if needed */ |
3fd1cefb | 4795 | if (nl80211_setup_ap(bss)) |
460456f8 | 4796 | return -1; |
3fd1cefb | 4797 | } else if (was_ap) { |
460456f8 | 4798 | /* Remove additional AP mode functionality */ |
3fd1cefb | 4799 | nl80211_teardown_ap(bss); |
a11241fa | 4800 | } else { |
36488c05 | 4801 | nl80211_mgmt_unsubscribe(bss, "mode change"); |
460456f8 | 4802 | } |
460456f8 | 4803 | |
afb0550a BC |
4804 | if (is_mesh_interface(nlmode) && |
4805 | nl80211_mgmt_subscribe_mesh(bss)) | |
4806 | return -1; | |
4807 | ||
873d0fcf | 4808 | if (!bss->in_deinit && !is_ap_interface(nlmode) && |
afb0550a | 4809 | !is_mesh_interface(nlmode) && |
a11241fa JB |
4810 | nl80211_mgmt_subscribe_non_ap(bss) < 0) |
4811 | wpa_printf(MSG_DEBUG, "nl80211: Failed to register Action " | |
4812 | "frame processing - ignore for now"); | |
08359050 | 4813 | |
3fd1cefb | 4814 | return 0; |
3f5285e8 JM |
4815 | } |
4816 | ||
4817 | ||
f3407c66 JM |
4818 | int wpa_driver_nl80211_set_mode(struct i802_bss *bss, |
4819 | enum nl80211_iftype nlmode) | |
3c5d34e3 CW |
4820 | { |
4821 | return wpa_driver_nl80211_set_mode_impl(bss, nlmode, NULL); | |
4822 | } | |
4823 | ||
4824 | ||
4ec68377 JD |
4825 | static int wpa_driver_nl80211_set_mode_ibss(struct i802_bss *bss, |
4826 | struct hostapd_freq_params *freq) | |
3c5d34e3 | 4827 | { |
3c5d34e3 | 4828 | return wpa_driver_nl80211_set_mode_impl(bss, NL80211_IFTYPE_ADHOC, |
4ec68377 | 4829 | freq); |
3c5d34e3 | 4830 | } |
65d645ce AS |
4831 | |
4832 | ||
3f5285e8 JM |
4833 | static int wpa_driver_nl80211_get_capa(void *priv, |
4834 | struct wpa_driver_capa *capa) | |
4835 | { | |
a2e40bb6 FF |
4836 | struct i802_bss *bss = priv; |
4837 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
65d645ce | 4838 | |
3f5285e8 JM |
4839 | if (!drv->has_capability) |
4840 | return -1; | |
4841 | os_memcpy(capa, &drv->capa, sizeof(*capa)); | |
8cd6b7bc JB |
4842 | if (drv->extended_capa && drv->extended_capa_mask) { |
4843 | capa->extended_capa = drv->extended_capa; | |
4844 | capa->extended_capa_mask = drv->extended_capa_mask; | |
4845 | capa->extended_capa_len = drv->extended_capa_len; | |
4846 | } | |
851b0c55 | 4847 | |
906bc4c7 | 4848 | return 0; |
3f5285e8 JM |
4849 | } |
4850 | ||
4851 | ||
4852 | static int wpa_driver_nl80211_set_operstate(void *priv, int state) | |
4853 | { | |
a2e40bb6 FF |
4854 | struct i802_bss *bss = priv; |
4855 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
3f5285e8 | 4856 | |
90a545cc JM |
4857 | wpa_printf(MSG_DEBUG, "nl80211: Set %s operstate %d->%d (%s)", |
4858 | bss->ifname, drv->operstate, state, | |
4859 | state ? "UP" : "DORMANT"); | |
3f5285e8 | 4860 | drv->operstate = state; |
36d84860 | 4861 | return netlink_send_oper_ifla(drv->global->netlink, drv->ifindex, -1, |
e2d02c29 | 4862 | state ? IF_OPER_UP : IF_OPER_DORMANT); |
3f5285e8 JM |
4863 | } |
4864 | ||
01652550 JM |
4865 | |
4866 | static int wpa_driver_nl80211_set_supp_port(void *priv, int authorized) | |
4867 | { | |
a2e40bb6 FF |
4868 | struct i802_bss *bss = priv; |
4869 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
01652550 JM |
4870 | struct nl_msg *msg; |
4871 | struct nl80211_sta_flag_update upd; | |
a862e4a3 | 4872 | int ret; |
2eef5177 JM |
4873 | |
4874 | if (!drv->associated && is_zero_ether_addr(drv->bssid) && !authorized) { | |
4875 | wpa_printf(MSG_DEBUG, "nl80211: Skip set_supp_port(unauthorized) while not associated"); | |
4876 | return 0; | |
4877 | } | |
01652550 | 4878 | |
1ba51ec0 JM |
4879 | wpa_printf(MSG_DEBUG, "nl80211: Set supplicant port %sauthorized for " |
4880 | MACSTR, authorized ? "" : "un", MAC2STR(drv->bssid)); | |
4881 | ||
01652550 JM |
4882 | os_memset(&upd, 0, sizeof(upd)); |
4883 | upd.mask = BIT(NL80211_STA_FLAG_AUTHORIZED); | |
4884 | if (authorized) | |
4885 | upd.set = BIT(NL80211_STA_FLAG_AUTHORIZED); | |
a862e4a3 | 4886 | |
13f83980 | 4887 | if (!(msg = nl80211_bss_msg(bss, 0, NL80211_CMD_SET_STATION)) || |
a862e4a3 JM |
4888 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, drv->bssid) || |
4889 | nla_put(msg, NL80211_ATTR_STA_FLAGS2, sizeof(upd), &upd)) { | |
4890 | nlmsg_free(msg); | |
4891 | return -ENOBUFS; | |
4892 | } | |
01652550 | 4893 | |
2eef5177 | 4894 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
2eef5177 JM |
4895 | if (!ret) |
4896 | return 0; | |
2eef5177 JM |
4897 | wpa_printf(MSG_DEBUG, "nl80211: Failed to set STA flag: %d (%s)", |
4898 | ret, strerror(-ret)); | |
4899 | return ret; | |
01652550 JM |
4900 | } |
4901 | ||
3f5285e8 | 4902 | |
f07ead6a JM |
4903 | /* Set kernel driver on given frequency (MHz) */ |
4904 | static int i802_set_freq(void *priv, struct hostapd_freq_params *freq) | |
c5121837 | 4905 | { |
f07ead6a | 4906 | struct i802_bss *bss = priv; |
13a524a3 | 4907 | return nl80211_set_channel(bss, freq, 0); |
c5121837 JM |
4908 | } |
4909 | ||
f7b3920c | 4910 | |
c5121837 JM |
4911 | static inline int min_int(int a, int b) |
4912 | { | |
4913 | if (a < b) | |
4914 | return a; | |
4915 | return b; | |
4916 | } | |
4917 | ||
4918 | ||
4919 | static int get_key_handler(struct nl_msg *msg, void *arg) | |
4920 | { | |
4921 | struct nlattr *tb[NL80211_ATTR_MAX + 1]; | |
4922 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); | |
4923 | ||
4924 | nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), | |
4925 | genlmsg_attrlen(gnlh, 0), NULL); | |
4926 | ||
4927 | /* | |
4928 | * TODO: validate the key index and mac address! | |
4929 | * Otherwise, there's a race condition as soon as | |
4930 | * the kernel starts sending key notifications. | |
4931 | */ | |
4932 | ||
4933 | if (tb[NL80211_ATTR_KEY_SEQ]) | |
4934 | memcpy(arg, nla_data(tb[NL80211_ATTR_KEY_SEQ]), | |
4935 | min_int(nla_len(tb[NL80211_ATTR_KEY_SEQ]), 6)); | |
4936 | return NL_SKIP; | |
4937 | } | |
4938 | ||
4939 | ||
4940 | static int i802_get_seqnum(const char *iface, void *priv, const u8 *addr, | |
4941 | int idx, u8 *seq) | |
4942 | { | |
a2e40bb6 FF |
4943 | struct i802_bss *bss = priv; |
4944 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
c5121837 JM |
4945 | struct nl_msg *msg; |
4946 | ||
95376e1a JM |
4947 | msg = nl80211_ifindex_msg(drv, if_nametoindex(iface), 0, |
4948 | NL80211_CMD_GET_KEY); | |
4949 | if (!msg || | |
a862e4a3 | 4950 | (addr && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) || |
95376e1a | 4951 | nla_put_u8(msg, NL80211_ATTR_KEY_IDX, idx)) { |
a862e4a3 JM |
4952 | nlmsg_free(msg); |
4953 | return -ENOBUFS; | |
4954 | } | |
c5121837 JM |
4955 | |
4956 | memset(seq, 0, 6); | |
4957 | ||
4958 | return send_and_recv_msgs(drv, msg, get_key_handler, seq); | |
c5121837 JM |
4959 | } |
4960 | ||
4961 | ||
c5121837 JM |
4962 | static int i802_set_rts(void *priv, int rts) |
4963 | { | |
a2e40bb6 FF |
4964 | struct i802_bss *bss = priv; |
4965 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
ad649451 | 4966 | struct nl_msg *msg; |
a862e4a3 | 4967 | int ret; |
ad649451 | 4968 | u32 val; |
c5121837 | 4969 | |
ad649451 JM |
4970 | if (rts >= 2347) |
4971 | val = (u32) -1; | |
4972 | else | |
4973 | val = rts; | |
c5121837 | 4974 | |
9725b784 | 4975 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_SET_WIPHY)) || |
a862e4a3 JM |
4976 | nla_put_u32(msg, NL80211_ATTR_WIPHY_RTS_THRESHOLD, val)) { |
4977 | nlmsg_free(msg); | |
4978 | return -ENOBUFS; | |
4979 | } | |
ad649451 JM |
4980 | |
4981 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); | |
4982 | if (!ret) | |
4983 | return 0; | |
ad649451 JM |
4984 | wpa_printf(MSG_DEBUG, "nl80211: Failed to set RTS threshold %d: " |
4985 | "%d (%s)", rts, ret, strerror(-ret)); | |
4986 | return ret; | |
c5121837 JM |
4987 | } |
4988 | ||
4989 | ||
4990 | static int i802_set_frag(void *priv, int frag) | |
4991 | { | |
a2e40bb6 FF |
4992 | struct i802_bss *bss = priv; |
4993 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
ad649451 | 4994 | struct nl_msg *msg; |
a862e4a3 | 4995 | int ret; |
ad649451 | 4996 | u32 val; |
c5121837 | 4997 | |
ad649451 JM |
4998 | if (frag >= 2346) |
4999 | val = (u32) -1; | |
5000 | else | |
5001 | val = frag; | |
c5121837 | 5002 | |
9725b784 | 5003 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_SET_WIPHY)) || |
a862e4a3 JM |
5004 | nla_put_u32(msg, NL80211_ATTR_WIPHY_FRAG_THRESHOLD, val)) { |
5005 | nlmsg_free(msg); | |
5006 | return -ENOBUFS; | |
5007 | } | |
ad649451 JM |
5008 | |
5009 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); | |
5010 | if (!ret) | |
5011 | return 0; | |
ad649451 JM |
5012 | wpa_printf(MSG_DEBUG, "nl80211: Failed to set fragmentation threshold " |
5013 | "%d: %d (%s)", frag, ret, strerror(-ret)); | |
5014 | return ret; | |
c5121837 JM |
5015 | } |
5016 | ||
5017 | ||
c5121837 JM |
5018 | static int i802_flush(void *priv) |
5019 | { | |
a2e40bb6 | 5020 | struct i802_bss *bss = priv; |
c5121837 | 5021 | struct nl_msg *msg; |
82554b10 | 5022 | int res; |
c5121837 | 5023 | |
83e7bb0e JM |
5024 | wpa_printf(MSG_DEBUG, "nl80211: flush -> DEL_STATION %s (all)", |
5025 | bss->ifname); | |
c5121837 JM |
5026 | |
5027 | /* | |
5028 | * XXX: FIX! this needs to flush all VLANs too | |
5029 | */ | |
13f83980 JM |
5030 | msg = nl80211_bss_msg(bss, 0, NL80211_CMD_DEL_STATION); |
5031 | res = send_and_recv_msgs(bss->drv, msg, NULL, NULL); | |
82554b10 JM |
5032 | if (res) { |
5033 | wpa_printf(MSG_DEBUG, "nl80211: Station flush failed: ret=%d " | |
5034 | "(%s)", res, strerror(-res)); | |
5035 | } | |
5036 | return res; | |
c5121837 JM |
5037 | } |
5038 | ||
5039 | ||
5040 | static int get_sta_handler(struct nl_msg *msg, void *arg) | |
5041 | { | |
5042 | struct nlattr *tb[NL80211_ATTR_MAX + 1]; | |
5043 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); | |
5044 | struct hostap_sta_driver_data *data = arg; | |
5045 | struct nlattr *stats[NL80211_STA_INFO_MAX + 1]; | |
5046 | static struct nla_policy stats_policy[NL80211_STA_INFO_MAX + 1] = { | |
5047 | [NL80211_STA_INFO_INACTIVE_TIME] = { .type = NLA_U32 }, | |
5048 | [NL80211_STA_INFO_RX_BYTES] = { .type = NLA_U32 }, | |
5049 | [NL80211_STA_INFO_TX_BYTES] = { .type = NLA_U32 }, | |
5050 | [NL80211_STA_INFO_RX_PACKETS] = { .type = NLA_U32 }, | |
5051 | [NL80211_STA_INFO_TX_PACKETS] = { .type = NLA_U32 }, | |
dc7785f8 | 5052 | [NL80211_STA_INFO_TX_FAILED] = { .type = NLA_U32 }, |
c5121837 JM |
5053 | }; |
5054 | ||
5055 | nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), | |
5056 | genlmsg_attrlen(gnlh, 0), NULL); | |
5057 | ||
5058 | /* | |
5059 | * TODO: validate the interface and mac address! | |
5060 | * Otherwise, there's a race condition as soon as | |
5061 | * the kernel starts sending station notifications. | |
5062 | */ | |
5063 | ||
5064 | if (!tb[NL80211_ATTR_STA_INFO]) { | |
5065 | wpa_printf(MSG_DEBUG, "sta stats missing!"); | |
5066 | return NL_SKIP; | |
5067 | } | |
5068 | if (nla_parse_nested(stats, NL80211_STA_INFO_MAX, | |
5069 | tb[NL80211_ATTR_STA_INFO], | |
5070 | stats_policy)) { | |
5071 | wpa_printf(MSG_DEBUG, "failed to parse nested attributes!"); | |
5072 | return NL_SKIP; | |
5073 | } | |
5074 | ||
5075 | if (stats[NL80211_STA_INFO_INACTIVE_TIME]) | |
5076 | data->inactive_msec = | |
5077 | nla_get_u32(stats[NL80211_STA_INFO_INACTIVE_TIME]); | |
5078 | if (stats[NL80211_STA_INFO_RX_BYTES]) | |
5079 | data->rx_bytes = nla_get_u32(stats[NL80211_STA_INFO_RX_BYTES]); | |
5080 | if (stats[NL80211_STA_INFO_TX_BYTES]) | |
5081 | data->tx_bytes = nla_get_u32(stats[NL80211_STA_INFO_TX_BYTES]); | |
5082 | if (stats[NL80211_STA_INFO_RX_PACKETS]) | |
5083 | data->rx_packets = | |
5084 | nla_get_u32(stats[NL80211_STA_INFO_RX_PACKETS]); | |
5085 | if (stats[NL80211_STA_INFO_TX_PACKETS]) | |
5086 | data->tx_packets = | |
5087 | nla_get_u32(stats[NL80211_STA_INFO_TX_PACKETS]); | |
dc7785f8 YZ |
5088 | if (stats[NL80211_STA_INFO_TX_FAILED]) |
5089 | data->tx_retry_failed = | |
5090 | nla_get_u32(stats[NL80211_STA_INFO_TX_FAILED]); | |
c5121837 JM |
5091 | |
5092 | return NL_SKIP; | |
5093 | } | |
5094 | ||
9ebce9c5 JM |
5095 | static int i802_read_sta_data(struct i802_bss *bss, |
5096 | struct hostap_sta_driver_data *data, | |
c5121837 JM |
5097 | const u8 *addr) |
5098 | { | |
c5121837 JM |
5099 | struct nl_msg *msg; |
5100 | ||
5101 | os_memset(data, 0, sizeof(*data)); | |
c5121837 | 5102 | |
13f83980 JM |
5103 | if (!(msg = nl80211_bss_msg(bss, 0, NL80211_CMD_GET_STATION)) || |
5104 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) { | |
a862e4a3 JM |
5105 | nlmsg_free(msg); |
5106 | return -ENOBUFS; | |
5107 | } | |
c5121837 | 5108 | |
13f83980 | 5109 | return send_and_recv_msgs(bss->drv, msg, get_sta_handler, data); |
c5121837 JM |
5110 | } |
5111 | ||
5112 | ||
c5121837 JM |
5113 | static int i802_set_tx_queue_params(void *priv, int queue, int aifs, |
5114 | int cw_min, int cw_max, int burst_time) | |
5115 | { | |
a2e40bb6 FF |
5116 | struct i802_bss *bss = priv; |
5117 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
c5121837 JM |
5118 | struct nl_msg *msg; |
5119 | struct nlattr *txq, *params; | |
5120 | ||
13f83980 | 5121 | msg = nl80211_bss_msg(bss, 0, NL80211_CMD_SET_WIPHY); |
c5121837 JM |
5122 | if (!msg) |
5123 | return -1; | |
5124 | ||
c5121837 JM |
5125 | txq = nla_nest_start(msg, NL80211_ATTR_WIPHY_TXQ_PARAMS); |
5126 | if (!txq) | |
a862e4a3 | 5127 | goto fail; |
c5121837 JM |
5128 | |
5129 | /* We are only sending parameters for a single TXQ at a time */ | |
5130 | params = nla_nest_start(msg, 1); | |
5131 | if (!params) | |
a862e4a3 | 5132 | goto fail; |
c5121837 | 5133 | |
7e3c1781 JM |
5134 | switch (queue) { |
5135 | case 0: | |
a862e4a3 JM |
5136 | if (nla_put_u8(msg, NL80211_TXQ_ATTR_QUEUE, NL80211_TXQ_Q_VO)) |
5137 | goto fail; | |
7e3c1781 JM |
5138 | break; |
5139 | case 1: | |
a862e4a3 JM |
5140 | if (nla_put_u8(msg, NL80211_TXQ_ATTR_QUEUE, NL80211_TXQ_Q_VI)) |
5141 | goto fail; | |
7e3c1781 JM |
5142 | break; |
5143 | case 2: | |
a862e4a3 JM |
5144 | if (nla_put_u8(msg, NL80211_TXQ_ATTR_QUEUE, NL80211_TXQ_Q_BE)) |
5145 | goto fail; | |
7e3c1781 JM |
5146 | break; |
5147 | case 3: | |
a862e4a3 JM |
5148 | if (nla_put_u8(msg, NL80211_TXQ_ATTR_QUEUE, NL80211_TXQ_Q_BK)) |
5149 | goto fail; | |
7e3c1781 JM |
5150 | break; |
5151 | } | |
c5121837 JM |
5152 | /* Burst time is configured in units of 0.1 msec and TXOP parameter in |
5153 | * 32 usec, so need to convert the value here. */ | |
a862e4a3 JM |
5154 | if (nla_put_u16(msg, NL80211_TXQ_ATTR_TXOP, |
5155 | (burst_time * 100 + 16) / 32) || | |
5156 | nla_put_u16(msg, NL80211_TXQ_ATTR_CWMIN, cw_min) || | |
5157 | nla_put_u16(msg, NL80211_TXQ_ATTR_CWMAX, cw_max) || | |
5158 | nla_put_u8(msg, NL80211_TXQ_ATTR_AIFS, aifs)) | |
5159 | goto fail; | |
c5121837 JM |
5160 | |
5161 | nla_nest_end(msg, params); | |
5162 | ||
5163 | nla_nest_end(msg, txq); | |
5164 | ||
5165 | if (send_and_recv_msgs(drv, msg, NULL, NULL) == 0) | |
5166 | return 0; | |
9e088e74 | 5167 | msg = NULL; |
a862e4a3 | 5168 | fail: |
9e088e74 | 5169 | nlmsg_free(msg); |
c5121837 JM |
5170 | return -1; |
5171 | } | |
5172 | ||
5173 | ||
9ebce9c5 | 5174 | static int i802_set_sta_vlan(struct i802_bss *bss, const u8 *addr, |
c5121837 JM |
5175 | const char *ifname, int vlan_id) |
5176 | { | |
a2e40bb6 | 5177 | struct wpa_driver_nl80211_data *drv = bss->drv; |
c5121837 | 5178 | struct nl_msg *msg; |
a862e4a3 | 5179 | int ret; |
c5121837 | 5180 | |
bbc706a3 JM |
5181 | wpa_printf(MSG_DEBUG, "nl80211: %s[%d]: set_sta_vlan(" MACSTR |
5182 | ", ifname=%s[%d], vlan_id=%d)", | |
5183 | bss->ifname, if_nametoindex(bss->ifname), | |
5184 | MAC2STR(addr), ifname, if_nametoindex(ifname), vlan_id); | |
13f83980 | 5185 | if (!(msg = nl80211_bss_msg(bss, 0, NL80211_CMD_SET_STATION)) || |
a862e4a3 JM |
5186 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) || |
5187 | nla_put_u32(msg, NL80211_ATTR_STA_VLAN, if_nametoindex(ifname))) { | |
5188 | nlmsg_free(msg); | |
5189 | return -ENOBUFS; | |
5190 | } | |
c5121837 | 5191 | |
cd1d72c1 JM |
5192 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
5193 | if (ret < 0) { | |
5194 | wpa_printf(MSG_ERROR, "nl80211: NL80211_ATTR_STA_VLAN (addr=" | |
5195 | MACSTR " ifname=%s vlan_id=%d) failed: %d (%s)", | |
5196 | MAC2STR(addr), ifname, vlan_id, ret, | |
5197 | strerror(-ret)); | |
5198 | } | |
cd1d72c1 | 5199 | return ret; |
c5121837 JM |
5200 | } |
5201 | ||
fbbfcbac | 5202 | |
c5121837 JM |
5203 | static int i802_get_inact_sec(void *priv, const u8 *addr) |
5204 | { | |
5205 | struct hostap_sta_driver_data data; | |
5206 | int ret; | |
5207 | ||
5208 | data.inactive_msec = (unsigned long) -1; | |
5209 | ret = i802_read_sta_data(priv, &data, addr); | |
5210 | if (ret || data.inactive_msec == (unsigned long) -1) | |
5211 | return -1; | |
5212 | return data.inactive_msec / 1000; | |
5213 | } | |
5214 | ||
5215 | ||
5216 | static int i802_sta_clear_stats(void *priv, const u8 *addr) | |
5217 | { | |
5218 | #if 0 | |
5219 | /* TODO */ | |
5220 | #endif | |
5221 | return 0; | |
5222 | } | |
5223 | ||
5224 | ||
731723a5 JM |
5225 | static int i802_sta_deauth(void *priv, const u8 *own_addr, const u8 *addr, |
5226 | int reason) | |
c5121837 | 5227 | { |
a2e40bb6 | 5228 | struct i802_bss *bss = priv; |
e1bd4e19 | 5229 | struct wpa_driver_nl80211_data *drv = bss->drv; |
c5121837 JM |
5230 | struct ieee80211_mgmt mgmt; |
5231 | ||
0d391b03 BC |
5232 | if (is_mesh_interface(drv->nlmode)) |
5233 | return -1; | |
5234 | ||
e1bd4e19 | 5235 | if (drv->device_ap_sme) |
59d7148a | 5236 | return wpa_driver_nl80211_sta_remove(bss, addr, 1, reason); |
e1bd4e19 | 5237 | |
c5121837 JM |
5238 | memset(&mgmt, 0, sizeof(mgmt)); |
5239 | mgmt.frame_control = IEEE80211_FC(WLAN_FC_TYPE_MGMT, | |
5240 | WLAN_FC_STYPE_DEAUTH); | |
5241 | memcpy(mgmt.da, addr, ETH_ALEN); | |
731723a5 JM |
5242 | memcpy(mgmt.sa, own_addr, ETH_ALEN); |
5243 | memcpy(mgmt.bssid, own_addr, ETH_ALEN); | |
c5121837 | 5244 | mgmt.u.deauth.reason_code = host_to_le16(reason); |
a2e40bb6 | 5245 | return wpa_driver_nl80211_send_mlme(bss, (u8 *) &mgmt, |
9f324b61 | 5246 | IEEE80211_HDRLEN + |
9ebce9c5 JM |
5247 | sizeof(mgmt.u.deauth), 0, 0, 0, 0, |
5248 | 0); | |
c5121837 JM |
5249 | } |
5250 | ||
5251 | ||
731723a5 JM |
5252 | static int i802_sta_disassoc(void *priv, const u8 *own_addr, const u8 *addr, |
5253 | int reason) | |
c5121837 | 5254 | { |
a2e40bb6 | 5255 | struct i802_bss *bss = priv; |
e1bd4e19 | 5256 | struct wpa_driver_nl80211_data *drv = bss->drv; |
c5121837 JM |
5257 | struct ieee80211_mgmt mgmt; |
5258 | ||
0d391b03 BC |
5259 | if (is_mesh_interface(drv->nlmode)) |
5260 | return -1; | |
5261 | ||
e1bd4e19 | 5262 | if (drv->device_ap_sme) |
59d7148a | 5263 | return wpa_driver_nl80211_sta_remove(bss, addr, 0, reason); |
e1bd4e19 | 5264 | |
c5121837 JM |
5265 | memset(&mgmt, 0, sizeof(mgmt)); |
5266 | mgmt.frame_control = IEEE80211_FC(WLAN_FC_TYPE_MGMT, | |
5267 | WLAN_FC_STYPE_DISASSOC); | |
5268 | memcpy(mgmt.da, addr, ETH_ALEN); | |
731723a5 JM |
5269 | memcpy(mgmt.sa, own_addr, ETH_ALEN); |
5270 | memcpy(mgmt.bssid, own_addr, ETH_ALEN); | |
c5121837 | 5271 | mgmt.u.disassoc.reason_code = host_to_le16(reason); |
a2e40bb6 | 5272 | return wpa_driver_nl80211_send_mlme(bss, (u8 *) &mgmt, |
9f324b61 | 5273 | IEEE80211_HDRLEN + |
9ebce9c5 JM |
5274 | sizeof(mgmt.u.disassoc), 0, 0, 0, 0, |
5275 | 0); | |
c5121837 JM |
5276 | } |
5277 | ||
5278 | ||
9b4d9c8b JM |
5279 | static void dump_ifidx(struct wpa_driver_nl80211_data *drv) |
5280 | { | |
5281 | char buf[200], *pos, *end; | |
5282 | int i, res; | |
5283 | ||
5284 | pos = buf; | |
5285 | end = pos + sizeof(buf); | |
5286 | ||
5287 | for (i = 0; i < drv->num_if_indices; i++) { | |
5288 | if (!drv->if_indices[i]) | |
5289 | continue; | |
5290 | res = os_snprintf(pos, end - pos, " %d", drv->if_indices[i]); | |
d85e1fc8 | 5291 | if (os_snprintf_error(end - pos, res)) |
9b4d9c8b JM |
5292 | break; |
5293 | pos += res; | |
5294 | } | |
5295 | *pos = '\0'; | |
5296 | ||
5297 | wpa_printf(MSG_DEBUG, "nl80211: if_indices[%d]:%s", | |
5298 | drv->num_if_indices, buf); | |
5299 | } | |
5300 | ||
5301 | ||
f07ead6a JM |
5302 | static void add_ifidx(struct wpa_driver_nl80211_data *drv, int ifidx) |
5303 | { | |
5304 | int i; | |
5305 | int *old; | |
5306 | ||
5307 | wpa_printf(MSG_DEBUG, "nl80211: Add own interface ifindex %d", | |
5308 | ifidx); | |
b36935be MB |
5309 | if (have_ifidx(drv, ifidx)) { |
5310 | wpa_printf(MSG_DEBUG, "nl80211: ifindex %d already in the list", | |
5311 | ifidx); | |
5312 | return; | |
5313 | } | |
f07ead6a JM |
5314 | for (i = 0; i < drv->num_if_indices; i++) { |
5315 | if (drv->if_indices[i] == 0) { | |
5316 | drv->if_indices[i] = ifidx; | |
9b4d9c8b | 5317 | dump_ifidx(drv); |
f07ead6a JM |
5318 | return; |
5319 | } | |
5320 | } | |
5321 | ||
5322 | if (drv->if_indices != drv->default_if_indices) | |
5323 | old = drv->if_indices; | |
5324 | else | |
5325 | old = NULL; | |
5326 | ||
067ffa26 JM |
5327 | drv->if_indices = os_realloc_array(old, drv->num_if_indices + 1, |
5328 | sizeof(int)); | |
f07ead6a JM |
5329 | if (!drv->if_indices) { |
5330 | if (!old) | |
5331 | drv->if_indices = drv->default_if_indices; | |
5332 | else | |
5333 | drv->if_indices = old; | |
5334 | wpa_printf(MSG_ERROR, "Failed to reallocate memory for " | |
5335 | "interfaces"); | |
5336 | wpa_printf(MSG_ERROR, "Ignoring EAPOL on interface %d", ifidx); | |
5337 | return; | |
5338 | } else if (!old) | |
5339 | os_memcpy(drv->if_indices, drv->default_if_indices, | |
5340 | sizeof(drv->default_if_indices)); | |
5341 | drv->if_indices[drv->num_if_indices] = ifidx; | |
5342 | drv->num_if_indices++; | |
9b4d9c8b | 5343 | dump_ifidx(drv); |
f07ead6a JM |
5344 | } |
5345 | ||
5346 | ||
5347 | static void del_ifidx(struct wpa_driver_nl80211_data *drv, int ifidx) | |
5348 | { | |
5349 | int i; | |
5350 | ||
5351 | for (i = 0; i < drv->num_if_indices; i++) { | |
5352 | if (drv->if_indices[i] == ifidx) { | |
5353 | drv->if_indices[i] = 0; | |
5354 | break; | |
5355 | } | |
5356 | } | |
9b4d9c8b | 5357 | dump_ifidx(drv); |
f07ead6a JM |
5358 | } |
5359 | ||
5360 | ||
5361 | static int have_ifidx(struct wpa_driver_nl80211_data *drv, int ifidx) | |
5362 | { | |
5363 | int i; | |
5364 | ||
5365 | for (i = 0; i < drv->num_if_indices; i++) | |
5366 | if (drv->if_indices[i] == ifidx) | |
5367 | return 1; | |
5368 | ||
5369 | return 0; | |
5370 | } | |
5371 | ||
5372 | ||
5373 | static int i802_set_wds_sta(void *priv, const u8 *addr, int aid, int val, | |
0e80ea2c | 5374 | const char *bridge_ifname, char *ifname_wds) |
f07ead6a JM |
5375 | { |
5376 | struct i802_bss *bss = priv; | |
5377 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
5378 | char name[IFNAMSIZ + 1]; | |
5379 | ||
5380 | os_snprintf(name, sizeof(name), "%s.sta%d", bss->ifname, aid); | |
69dd2967 SM |
5381 | if (ifname_wds) |
5382 | os_strlcpy(ifname_wds, name, IFNAMSIZ + 1); | |
5383 | ||
f07ead6a JM |
5384 | wpa_printf(MSG_DEBUG, "nl80211: Set WDS STA addr=" MACSTR |
5385 | " aid=%d val=%d name=%s", MAC2STR(addr), aid, val, name); | |
5386 | if (val) { | |
5387 | if (!if_nametoindex(name)) { | |
5388 | if (nl80211_create_iface(drv, name, | |
5389 | NL80211_IFTYPE_AP_VLAN, | |
2aec4f3c JM |
5390 | bss->addr, 1, NULL, NULL, 0) < |
5391 | 0) | |
f07ead6a JM |
5392 | return -1; |
5393 | if (bridge_ifname && | |
c81eff1a BG |
5394 | linux_br_add_if(drv->global->ioctl_sock, |
5395 | bridge_ifname, name) < 0) | |
f07ead6a JM |
5396 | return -1; |
5397 | } | |
75227f3a JM |
5398 | if (linux_set_iface_flags(drv->global->ioctl_sock, name, 1)) { |
5399 | wpa_printf(MSG_ERROR, "nl80211: Failed to set WDS STA " | |
5400 | "interface %s up", name); | |
5401 | } | |
f07ead6a JM |
5402 | return i802_set_sta_vlan(priv, addr, name, 0); |
5403 | } else { | |
c34e618d FF |
5404 | if (bridge_ifname) |
5405 | linux_br_del_if(drv->global->ioctl_sock, bridge_ifname, | |
5406 | name); | |
5407 | ||
f07ead6a | 5408 | i802_set_sta_vlan(priv, addr, bss->ifname, 0); |
d0595b25 FF |
5409 | nl80211_remove_iface(drv, if_nametoindex(name)); |
5410 | return 0; | |
f07ead6a JM |
5411 | } |
5412 | } | |
5413 | ||
5414 | ||
5415 | static void handle_eapol(int sock, void *eloop_ctx, void *sock_ctx) | |
5416 | { | |
5417 | struct wpa_driver_nl80211_data *drv = eloop_ctx; | |
5418 | struct sockaddr_ll lladdr; | |
5419 | unsigned char buf[3000]; | |
5420 | int len; | |
5421 | socklen_t fromlen = sizeof(lladdr); | |
5422 | ||
5423 | len = recvfrom(sock, buf, sizeof(buf), 0, | |
5424 | (struct sockaddr *)&lladdr, &fromlen); | |
5425 | if (len < 0) { | |
7ac3616d JM |
5426 | wpa_printf(MSG_ERROR, "nl80211: EAPOL recv failed: %s", |
5427 | strerror(errno)); | |
f07ead6a JM |
5428 | return; |
5429 | } | |
5430 | ||
5431 | if (have_ifidx(drv, lladdr.sll_ifindex)) | |
5432 | drv_event_eapol_rx(drv->ctx, lladdr.sll_addr, buf, len); | |
5433 | } | |
5434 | ||
5435 | ||
94627f6c | 5436 | static int i802_check_bridge(struct wpa_driver_nl80211_data *drv, |
e17a2477 | 5437 | struct i802_bss *bss, |
94627f6c JM |
5438 | const char *brname, const char *ifname) |
5439 | { | |
6c6678e7 | 5440 | int br_ifindex; |
94627f6c JM |
5441 | char in_br[IFNAMSIZ]; |
5442 | ||
e17a2477 | 5443 | os_strlcpy(bss->brname, brname, IFNAMSIZ); |
6c6678e7 | 5444 | br_ifindex = if_nametoindex(brname); |
6c6678e7 | 5445 | if (br_ifindex == 0) { |
94627f6c JM |
5446 | /* |
5447 | * Bridge was configured, but the bridge device does | |
5448 | * not exist. Try to add it now. | |
5449 | */ | |
c81eff1a | 5450 | if (linux_br_add(drv->global->ioctl_sock, brname) < 0) { |
94627f6c JM |
5451 | wpa_printf(MSG_ERROR, "nl80211: Failed to add the " |
5452 | "bridge interface %s: %s", | |
5453 | brname, strerror(errno)); | |
5454 | return -1; | |
5455 | } | |
e17a2477 | 5456 | bss->added_bridge = 1; |
8997613c JM |
5457 | br_ifindex = if_nametoindex(brname); |
5458 | add_ifidx(drv, br_ifindex); | |
94627f6c | 5459 | } |
8997613c | 5460 | bss->br_ifindex = br_ifindex; |
94627f6c JM |
5461 | |
5462 | if (linux_br_get(in_br, ifname) == 0) { | |
5463 | if (os_strcmp(in_br, brname) == 0) | |
5464 | return 0; /* already in the bridge */ | |
5465 | ||
5466 | wpa_printf(MSG_DEBUG, "nl80211: Removing interface %s from " | |
5467 | "bridge %s", ifname, in_br); | |
c81eff1a BG |
5468 | if (linux_br_del_if(drv->global->ioctl_sock, in_br, ifname) < |
5469 | 0) { | |
94627f6c JM |
5470 | wpa_printf(MSG_ERROR, "nl80211: Failed to " |
5471 | "remove interface %s from bridge " | |
5472 | "%s: %s", | |
5473 | ifname, brname, strerror(errno)); | |
5474 | return -1; | |
5475 | } | |
5476 | } | |
5477 | ||
5478 | wpa_printf(MSG_DEBUG, "nl80211: Adding interface %s into bridge %s", | |
5479 | ifname, brname); | |
c81eff1a | 5480 | if (linux_br_add_if(drv->global->ioctl_sock, brname, ifname) < 0) { |
94627f6c JM |
5481 | wpa_printf(MSG_ERROR, "nl80211: Failed to add interface %s " |
5482 | "into bridge %s: %s", | |
5483 | ifname, brname, strerror(errno)); | |
5484 | return -1; | |
5485 | } | |
e17a2477 | 5486 | bss->added_if_into_bridge = 1; |
94627f6c JM |
5487 | |
5488 | return 0; | |
5489 | } | |
5490 | ||
5491 | ||
92f475b4 JM |
5492 | static void *i802_init(struct hostapd_data *hapd, |
5493 | struct wpa_init_params *params) | |
c5121837 JM |
5494 | { |
5495 | struct wpa_driver_nl80211_data *drv; | |
a2e40bb6 | 5496 | struct i802_bss *bss; |
c5121837 | 5497 | size_t i; |
94627f6c JM |
5498 | char brname[IFNAMSIZ]; |
5499 | int ifindex, br_ifindex; | |
5500 | int br_added = 0; | |
c5121837 | 5501 | |
0d547d5f JM |
5502 | bss = wpa_driver_nl80211_drv_init(hapd, params->ifname, |
5503 | params->global_priv, 1, | |
0ecff8d7 | 5504 | params->bssid, params->driver_params); |
a2e40bb6 | 5505 | if (bss == NULL) |
c5121837 | 5506 | return NULL; |
c5121837 | 5507 | |
a2e40bb6 | 5508 | drv = bss->drv; |
7635bfb0 | 5509 | |
94627f6c JM |
5510 | if (linux_br_get(brname, params->ifname) == 0) { |
5511 | wpa_printf(MSG_DEBUG, "nl80211: Interface %s is in bridge %s", | |
5512 | params->ifname, brname); | |
5513 | br_ifindex = if_nametoindex(brname); | |
392dfd37 | 5514 | os_strlcpy(bss->brname, brname, IFNAMSIZ); |
94627f6c JM |
5515 | } else { |
5516 | brname[0] = '\0'; | |
5517 | br_ifindex = 0; | |
5518 | } | |
6c6678e7 | 5519 | bss->br_ifindex = br_ifindex; |
94627f6c | 5520 | |
92f475b4 | 5521 | for (i = 0; i < params->num_bridge; i++) { |
94627f6c JM |
5522 | if (params->bridge[i]) { |
5523 | ifindex = if_nametoindex(params->bridge[i]); | |
5524 | if (ifindex) | |
5525 | add_ifidx(drv, ifindex); | |
5526 | if (ifindex == br_ifindex) | |
5527 | br_added = 1; | |
5528 | } | |
c5121837 | 5529 | } |
c5121837 | 5530 | |
ad1e68e6 JM |
5531 | /* start listening for EAPOL on the default AP interface */ |
5532 | add_ifidx(drv, drv->ifindex); | |
5533 | ||
5ef8e39f JM |
5534 | if (params->num_bridge && params->bridge[0]) { |
5535 | if (i802_check_bridge(drv, bss, params->bridge[0], | |
5536 | params->ifname) < 0) | |
5537 | goto failed; | |
5538 | if (os_strcmp(params->bridge[0], brname) != 0) | |
5539 | br_added = 1; | |
5540 | } | |
5541 | ||
5542 | if (!br_added && br_ifindex && | |
5543 | (params->num_bridge == 0 || !params->bridge[0])) | |
5544 | add_ifidx(drv, br_ifindex); | |
94627f6c | 5545 | |
97ed9a06 KP |
5546 | #ifdef CONFIG_LIBNL3_ROUTE |
5547 | if (bss->added_if_into_bridge) { | |
5548 | drv->rtnl_sk = nl_socket_alloc(); | |
5549 | if (drv->rtnl_sk == NULL) { | |
5550 | wpa_printf(MSG_ERROR, "nl80211: Failed to allocate nl_sock"); | |
5551 | goto failed; | |
5552 | } | |
5553 | ||
5554 | if (nl_connect(drv->rtnl_sk, NETLINK_ROUTE)) { | |
5555 | wpa_printf(MSG_ERROR, "nl80211: Failed to connect nl_sock to NETLINK_ROUTE: %s", | |
5556 | strerror(errno)); | |
5557 | goto failed; | |
5558 | } | |
5559 | } | |
5560 | #endif /* CONFIG_LIBNL3_ROUTE */ | |
5561 | ||
ad1e68e6 JM |
5562 | drv->eapol_sock = socket(PF_PACKET, SOCK_DGRAM, htons(ETH_P_PAE)); |
5563 | if (drv->eapol_sock < 0) { | |
7ac3616d JM |
5564 | wpa_printf(MSG_ERROR, "nl80211: socket(PF_PACKET, SOCK_DGRAM, ETH_P_PAE) failed: %s", |
5565 | strerror(errno)); | |
bbaf0837 | 5566 | goto failed; |
ad1e68e6 JM |
5567 | } |
5568 | ||
5569 | if (eloop_register_read_sock(drv->eapol_sock, handle_eapol, drv, NULL)) | |
5570 | { | |
7ac3616d | 5571 | wpa_printf(MSG_INFO, "nl80211: Could not register read socket for eapol"); |
c5121837 | 5572 | goto failed; |
ad1e68e6 JM |
5573 | } |
5574 | ||
c81eff1a BG |
5575 | if (linux_get_ifhwaddr(drv->global->ioctl_sock, bss->ifname, |
5576 | params->own_addr)) | |
bbaf0837 | 5577 | goto failed; |
fee354c7 | 5578 | os_memcpy(drv->perm_addr, params->own_addr, ETH_ALEN); |
c5121837 | 5579 | |
341eebee JB |
5580 | memcpy(bss->addr, params->own_addr, ETH_ALEN); |
5581 | ||
a2e40bb6 | 5582 | return bss; |
c5121837 JM |
5583 | |
5584 | failed: | |
7635bfb0 | 5585 | wpa_driver_nl80211_deinit(bss); |
bbaf0837 JM |
5586 | return NULL; |
5587 | } | |
c5121837 | 5588 | |
c5121837 | 5589 | |
bbaf0837 JM |
5590 | static void i802_deinit(void *priv) |
5591 | { | |
9ebce9c5 JM |
5592 | struct i802_bss *bss = priv; |
5593 | wpa_driver_nl80211_deinit(bss); | |
c5121837 JM |
5594 | } |
5595 | ||
c5121837 | 5596 | |
22a7c9d7 JM |
5597 | static enum nl80211_iftype wpa_driver_nl80211_if_type( |
5598 | enum wpa_driver_if_type type) | |
5599 | { | |
5600 | switch (type) { | |
5601 | case WPA_IF_STATION: | |
9f51b113 | 5602 | return NL80211_IFTYPE_STATION; |
75bde05d JM |
5603 | case WPA_IF_P2P_CLIENT: |
5604 | case WPA_IF_P2P_GROUP: | |
9f51b113 | 5605 | return NL80211_IFTYPE_P2P_CLIENT; |
22a7c9d7 JM |
5606 | case WPA_IF_AP_VLAN: |
5607 | return NL80211_IFTYPE_AP_VLAN; | |
5608 | case WPA_IF_AP_BSS: | |
5609 | return NL80211_IFTYPE_AP; | |
9f51b113 JB |
5610 | case WPA_IF_P2P_GO: |
5611 | return NL80211_IFTYPE_P2P_GO; | |
7aad838c NS |
5612 | case WPA_IF_P2P_DEVICE: |
5613 | return NL80211_IFTYPE_P2P_DEVICE; | |
5b78493f MH |
5614 | case WPA_IF_MESH: |
5615 | return NL80211_IFTYPE_MESH_POINT; | |
22a7c9d7 JM |
5616 | } |
5617 | return -1; | |
5618 | } | |
5619 | ||
5620 | ||
5b78493f | 5621 | #if defined(CONFIG_P2P) || defined(CONFIG_MESH) |
482856c8 | 5622 | |
f2ed8023 JM |
5623 | static int nl80211_addr_in_use(struct nl80211_global *global, const u8 *addr) |
5624 | { | |
5625 | struct wpa_driver_nl80211_data *drv; | |
5626 | dl_list_for_each(drv, &global->interfaces, | |
5627 | struct wpa_driver_nl80211_data, list) { | |
834ee56f | 5628 | if (os_memcmp(addr, drv->first_bss->addr, ETH_ALEN) == 0) |
f2ed8023 JM |
5629 | return 1; |
5630 | } | |
5631 | return 0; | |
5632 | } | |
5633 | ||
5634 | ||
5b78493f | 5635 | static int nl80211_vif_addr(struct wpa_driver_nl80211_data *drv, u8 *new_addr) |
f2ed8023 JM |
5636 | { |
5637 | unsigned int idx; | |
5638 | ||
5639 | if (!drv->global) | |
5640 | return -1; | |
5641 | ||
834ee56f | 5642 | os_memcpy(new_addr, drv->first_bss->addr, ETH_ALEN); |
f2ed8023 | 5643 | for (idx = 0; idx < 64; idx++) { |
834ee56f | 5644 | new_addr[0] = drv->first_bss->addr[0] | 0x02; |
f2ed8023 JM |
5645 | new_addr[0] ^= idx << 2; |
5646 | if (!nl80211_addr_in_use(drv->global, new_addr)) | |
5647 | break; | |
5648 | } | |
5649 | if (idx == 64) | |
5650 | return -1; | |
5651 | ||
5b78493f | 5652 | wpa_printf(MSG_DEBUG, "nl80211: Assigned new virtual interface address " |
f2ed8023 JM |
5653 | MACSTR, MAC2STR(new_addr)); |
5654 | ||
5655 | return 0; | |
5656 | } | |
5657 | ||
5b78493f | 5658 | #endif /* CONFIG_P2P || CONFIG_MESH */ |
482856c8 | 5659 | |
f2ed8023 | 5660 | |
f632e483 AS |
5661 | struct wdev_info { |
5662 | u64 wdev_id; | |
5663 | int wdev_id_set; | |
5664 | u8 macaddr[ETH_ALEN]; | |
5665 | }; | |
5666 | ||
5667 | static int nl80211_wdev_handler(struct nl_msg *msg, void *arg) | |
e472e1b4 AS |
5668 | { |
5669 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); | |
5670 | struct nlattr *tb[NL80211_ATTR_MAX + 1]; | |
f632e483 | 5671 | struct wdev_info *wi = arg; |
e472e1b4 AS |
5672 | |
5673 | nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), | |
5674 | genlmsg_attrlen(gnlh, 0), NULL); | |
5675 | if (tb[NL80211_ATTR_WDEV]) { | |
f632e483 AS |
5676 | wi->wdev_id = nla_get_u64(tb[NL80211_ATTR_WDEV]); |
5677 | wi->wdev_id_set = 1; | |
e472e1b4 AS |
5678 | } |
5679 | ||
5680 | if (tb[NL80211_ATTR_MAC]) | |
f632e483 | 5681 | os_memcpy(wi->macaddr, nla_data(tb[NL80211_ATTR_MAC]), |
e472e1b4 AS |
5682 | ETH_ALEN); |
5683 | ||
5684 | return NL_SKIP; | |
5685 | } | |
5686 | ||
5687 | ||
7ab68865 | 5688 | static int wpa_driver_nl80211_if_add(void *priv, enum wpa_driver_if_type type, |
8043e725 | 5689 | const char *ifname, const u8 *addr, |
f3585c8a | 5690 | void *bss_ctx, void **drv_priv, |
e17a2477 | 5691 | char *force_ifname, u8 *if_addr, |
2aec4f3c | 5692 | const char *bridge, int use_existing) |
22a7c9d7 | 5693 | { |
e472e1b4 | 5694 | enum nl80211_iftype nlmode; |
a2e40bb6 FF |
5695 | struct i802_bss *bss = priv; |
5696 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
22a7c9d7 | 5697 | int ifidx; |
2aec4f3c | 5698 | int added = 1; |
22a7c9d7 | 5699 | |
f3585c8a JM |
5700 | if (addr) |
5701 | os_memcpy(if_addr, addr, ETH_ALEN); | |
e472e1b4 AS |
5702 | nlmode = wpa_driver_nl80211_if_type(type); |
5703 | if (nlmode == NL80211_IFTYPE_P2P_DEVICE) { | |
f632e483 AS |
5704 | struct wdev_info p2pdev_info; |
5705 | ||
5706 | os_memset(&p2pdev_info, 0, sizeof(p2pdev_info)); | |
e472e1b4 | 5707 | ifidx = nl80211_create_iface(drv, ifname, nlmode, addr, |
f632e483 | 5708 | 0, nl80211_wdev_handler, |
2aec4f3c | 5709 | &p2pdev_info, use_existing); |
f632e483 | 5710 | if (!p2pdev_info.wdev_id_set || ifidx != 0) { |
e472e1b4 AS |
5711 | wpa_printf(MSG_ERROR, "nl80211: Failed to create a P2P Device interface %s", |
5712 | ifname); | |
e472e1b4 AS |
5713 | return -1; |
5714 | } | |
f632e483 AS |
5715 | |
5716 | drv->global->if_add_wdevid = p2pdev_info.wdev_id; | |
5717 | drv->global->if_add_wdevid_set = p2pdev_info.wdev_id_set; | |
5718 | if (!is_zero_ether_addr(p2pdev_info.macaddr)) | |
5719 | os_memcpy(if_addr, p2pdev_info.macaddr, ETH_ALEN); | |
5720 | wpa_printf(MSG_DEBUG, "nl80211: New P2P Device interface %s (0x%llx) created", | |
5721 | ifname, | |
5722 | (long long unsigned int) p2pdev_info.wdev_id); | |
e472e1b4 AS |
5723 | } else { |
5724 | ifidx = nl80211_create_iface(drv, ifname, nlmode, addr, | |
2aec4f3c JM |
5725 | 0, NULL, NULL, use_existing); |
5726 | if (use_existing && ifidx == -ENFILE) { | |
5727 | added = 0; | |
5728 | ifidx = if_nametoindex(ifname); | |
5729 | } else if (ifidx < 0) { | |
e472e1b4 AS |
5730 | return -1; |
5731 | } | |
22a7c9d7 JM |
5732 | } |
5733 | ||
ab7a1add AS |
5734 | if (!addr) { |
5735 | if (drv->nlmode == NL80211_IFTYPE_P2P_DEVICE) | |
5736 | os_memcpy(if_addr, bss->addr, ETH_ALEN); | |
5737 | else if (linux_get_ifhwaddr(drv->global->ioctl_sock, | |
5738 | bss->ifname, if_addr) < 0) { | |
2aec4f3c JM |
5739 | if (added) |
5740 | nl80211_remove_iface(drv, ifidx); | |
ab7a1add AS |
5741 | return -1; |
5742 | } | |
c55f774d JM |
5743 | } |
5744 | ||
5b78493f | 5745 | #if defined(CONFIG_P2P) || defined(CONFIG_MESH) |
c55f774d JM |
5746 | if (!addr && |
5747 | (type == WPA_IF_P2P_CLIENT || type == WPA_IF_P2P_GROUP || | |
5b78493f | 5748 | type == WPA_IF_P2P_GO || type == WPA_IF_MESH)) { |
c55f774d | 5749 | /* Enforce unique P2P Interface Address */ |
ab7a1add | 5750 | u8 new_addr[ETH_ALEN]; |
c55f774d | 5751 | |
ab7a1add | 5752 | if (linux_get_ifhwaddr(drv->global->ioctl_sock, ifname, |
c81eff1a | 5753 | new_addr) < 0) { |
ea39367c MK |
5754 | if (added) |
5755 | nl80211_remove_iface(drv, ifidx); | |
c55f774d JM |
5756 | return -1; |
5757 | } | |
f608081c | 5758 | if (nl80211_addr_in_use(drv->global, new_addr)) { |
c55f774d | 5759 | wpa_printf(MSG_DEBUG, "nl80211: Allocate new address " |
5b78493f MH |
5760 | "for %s interface", type == WPA_IF_MESH ? |
5761 | "mesh" : "P2P group"); | |
5762 | if (nl80211_vif_addr(drv, new_addr) < 0) { | |
ea39367c MK |
5763 | if (added) |
5764 | nl80211_remove_iface(drv, ifidx); | |
c55f774d JM |
5765 | return -1; |
5766 | } | |
c81eff1a | 5767 | if (linux_set_ifhwaddr(drv->global->ioctl_sock, ifname, |
c55f774d | 5768 | new_addr) < 0) { |
ea39367c MK |
5769 | if (added) |
5770 | nl80211_remove_iface(drv, ifidx); | |
c55f774d JM |
5771 | return -1; |
5772 | } | |
c55f774d | 5773 | } |
f67eeb5c | 5774 | os_memcpy(if_addr, new_addr, ETH_ALEN); |
c55f774d | 5775 | } |
5b78493f | 5776 | #endif /* CONFIG_P2P || CONFIG_MESH */ |
f3585c8a | 5777 | |
22a7c9d7 | 5778 | if (type == WPA_IF_AP_BSS) { |
f5eb9da3 JM |
5779 | struct i802_bss *new_bss = os_zalloc(sizeof(*new_bss)); |
5780 | if (new_bss == NULL) { | |
2aec4f3c JM |
5781 | if (added) |
5782 | nl80211_remove_iface(drv, ifidx); | |
f5eb9da3 JM |
5783 | return -1; |
5784 | } | |
5785 | ||
5786 | if (bridge && | |
5787 | i802_check_bridge(drv, new_bss, bridge, ifname) < 0) { | |
5788 | wpa_printf(MSG_ERROR, "nl80211: Failed to add the new " | |
5789 | "interface %s to a bridge %s", | |
5790 | ifname, bridge); | |
2aec4f3c JM |
5791 | if (added) |
5792 | nl80211_remove_iface(drv, ifidx); | |
f5eb9da3 JM |
5793 | os_free(new_bss); |
5794 | return -1; | |
5795 | } | |
5796 | ||
c81eff1a BG |
5797 | if (linux_set_iface_flags(drv->global->ioctl_sock, ifname, 1)) |
5798 | { | |
ea39367c MK |
5799 | if (added) |
5800 | nl80211_remove_iface(drv, ifidx); | |
07179987 | 5801 | os_free(new_bss); |
22a7c9d7 JM |
5802 | return -1; |
5803 | } | |
a2e40bb6 | 5804 | os_strlcpy(new_bss->ifname, ifname, IFNAMSIZ); |
341eebee | 5805 | os_memcpy(new_bss->addr, if_addr, ETH_ALEN); |
a2e40bb6 FF |
5806 | new_bss->ifindex = ifidx; |
5807 | new_bss->drv = drv; | |
834ee56f KP |
5808 | new_bss->next = drv->first_bss->next; |
5809 | new_bss->freq = drv->first_bss->freq; | |
a5e1eb20 | 5810 | new_bss->ctx = bss_ctx; |
2aec4f3c | 5811 | new_bss->added_if = added; |
834ee56f | 5812 | drv->first_bss->next = new_bss; |
a2e40bb6 FF |
5813 | if (drv_priv) |
5814 | *drv_priv = new_bss; | |
cc7a48d1 | 5815 | nl80211_init_bss(new_bss); |
3dd1d890 YAP |
5816 | |
5817 | /* Subscribe management frames for this WPA_IF_AP_BSS */ | |
5818 | if (nl80211_setup_ap(new_bss)) | |
5819 | return -1; | |
22a7c9d7 | 5820 | } |
22a7c9d7 | 5821 | |
ff6a158b JM |
5822 | if (drv->global) |
5823 | drv->global->if_add_ifindex = ifidx; | |
5824 | ||
d1bb7aed JJ |
5825 | /* |
5826 | * Some virtual interfaces need to process EAPOL packets and events on | |
5827 | * the parent interface. This is used mainly with hostapd. | |
5828 | */ | |
5829 | if (ifidx > 0 && | |
5830 | (drv->hostapd || | |
5831 | nlmode == NL80211_IFTYPE_AP_VLAN || | |
5832 | nlmode == NL80211_IFTYPE_WDS || | |
5833 | nlmode == NL80211_IFTYPE_MONITOR)) | |
b36935be MB |
5834 | add_ifidx(drv, ifidx); |
5835 | ||
22a7c9d7 JM |
5836 | return 0; |
5837 | } | |
5838 | ||
5839 | ||
9ebce9c5 | 5840 | static int wpa_driver_nl80211_if_remove(struct i802_bss *bss, |
22a7c9d7 JM |
5841 | enum wpa_driver_if_type type, |
5842 | const char *ifname) | |
5843 | { | |
a2e40bb6 | 5844 | struct wpa_driver_nl80211_data *drv = bss->drv; |
22a7c9d7 JM |
5845 | int ifindex = if_nametoindex(ifname); |
5846 | ||
2aec4f3c JM |
5847 | wpa_printf(MSG_DEBUG, "nl80211: %s(type=%d ifname=%s) ifindex=%d added_if=%d", |
5848 | __func__, type, ifname, ifindex, bss->added_if); | |
158b090c | 5849 | if (ifindex > 0 && (bss->added_if || bss->ifindex != ifindex)) |
2b72df63 | 5850 | nl80211_remove_iface(drv, ifindex); |
de884303 JM |
5851 | else if (ifindex > 0 && !bss->added_if) { |
5852 | struct wpa_driver_nl80211_data *drv2; | |
5853 | dl_list_for_each(drv2, &drv->global->interfaces, | |
5854 | struct wpa_driver_nl80211_data, list) | |
5855 | del_ifidx(drv2, ifindex); | |
5856 | } | |
c34e618d | 5857 | |
c34e618d FF |
5858 | if (type != WPA_IF_AP_BSS) |
5859 | return 0; | |
5860 | ||
e17a2477 | 5861 | if (bss->added_if_into_bridge) { |
c81eff1a BG |
5862 | if (linux_br_del_if(drv->global->ioctl_sock, bss->brname, |
5863 | bss->ifname) < 0) | |
e17a2477 JM |
5864 | wpa_printf(MSG_INFO, "nl80211: Failed to remove " |
5865 | "interface %s from bridge %s: %s", | |
5866 | bss->ifname, bss->brname, strerror(errno)); | |
5867 | } | |
5868 | if (bss->added_bridge) { | |
c81eff1a | 5869 | if (linux_br_del(drv->global->ioctl_sock, bss->brname) < 0) |
e17a2477 JM |
5870 | wpa_printf(MSG_INFO, "nl80211: Failed to remove " |
5871 | "bridge %s: %s", | |
5872 | bss->brname, strerror(errno)); | |
5873 | } | |
a2e40bb6 | 5874 | |
834ee56f | 5875 | if (bss != drv->first_bss) { |
8546ea19 | 5876 | struct i802_bss *tbss; |
a2e40bb6 | 5877 | |
2aec4f3c | 5878 | wpa_printf(MSG_DEBUG, "nl80211: Not the first BSS - remove it"); |
834ee56f | 5879 | for (tbss = drv->first_bss; tbss; tbss = tbss->next) { |
8546ea19 JM |
5880 | if (tbss->next == bss) { |
5881 | tbss->next = bss->next; | |
3dd1d890 YAP |
5882 | /* Unsubscribe management frames */ |
5883 | nl80211_teardown_ap(bss); | |
cc7a48d1 | 5884 | nl80211_destroy_bss(bss); |
5c9da160 MB |
5885 | if (!bss->added_if) |
5886 | i802_set_iface_flags(bss, 0); | |
8546ea19 JM |
5887 | os_free(bss); |
5888 | bss = NULL; | |
5889 | break; | |
5890 | } | |
22a7c9d7 | 5891 | } |
8546ea19 JM |
5892 | if (bss) |
5893 | wpa_printf(MSG_INFO, "nl80211: %s - could not find " | |
5894 | "BSS %p in the list", __func__, bss); | |
390e489c | 5895 | } else { |
2aec4f3c | 5896 | wpa_printf(MSG_DEBUG, "nl80211: First BSS - reassign context"); |
390e489c | 5897 | nl80211_teardown_ap(bss); |
2aec4f3c JM |
5898 | if (!bss->added_if && !drv->first_bss->next) |
5899 | wpa_driver_nl80211_del_beacon(drv); | |
390e489c | 5900 | nl80211_destroy_bss(bss); |
2aec4f3c JM |
5901 | if (!bss->added_if) |
5902 | i802_set_iface_flags(bss, 0); | |
390e489c KP |
5903 | if (drv->first_bss->next) { |
5904 | drv->first_bss = drv->first_bss->next; | |
5905 | drv->ctx = drv->first_bss->ctx; | |
5906 | os_free(bss); | |
5907 | } else { | |
5908 | wpa_printf(MSG_DEBUG, "nl80211: No second BSS to reassign context to"); | |
5909 | } | |
22a7c9d7 | 5910 | } |
22a7c9d7 JM |
5911 | |
5912 | return 0; | |
5913 | } | |
5914 | ||
5915 | ||
55777702 JM |
5916 | static int cookie_handler(struct nl_msg *msg, void *arg) |
5917 | { | |
5918 | struct nlattr *tb[NL80211_ATTR_MAX + 1]; | |
5919 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); | |
5920 | u64 *cookie = arg; | |
5921 | nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), | |
5922 | genlmsg_attrlen(gnlh, 0), NULL); | |
5923 | if (tb[NL80211_ATTR_COOKIE]) | |
5924 | *cookie = nla_get_u64(tb[NL80211_ATTR_COOKIE]); | |
5925 | return NL_SKIP; | |
5926 | } | |
5927 | ||
5928 | ||
88df0ef7 | 5929 | static int nl80211_send_frame_cmd(struct i802_bss *bss, |
5dfca53f JB |
5930 | unsigned int freq, unsigned int wait, |
5931 | const u8 *buf, size_t buf_len, | |
88df0ef7 JB |
5932 | u64 *cookie_out, int no_cck, int no_ack, |
5933 | int offchanok) | |
9884f9cc | 5934 | { |
88df0ef7 | 5935 | struct wpa_driver_nl80211_data *drv = bss->drv; |
9884f9cc JB |
5936 | struct nl_msg *msg; |
5937 | u64 cookie; | |
5938 | int ret = -1; | |
5939 | ||
cc2ada86 | 5940 | wpa_printf(MSG_MSGDUMP, "nl80211: CMD_FRAME freq=%u wait=%u no_cck=%d " |
2e3e4566 JM |
5941 | "no_ack=%d offchanok=%d", |
5942 | freq, wait, no_cck, no_ack, offchanok); | |
c91f796f | 5943 | wpa_hexdump(MSG_MSGDUMP, "CMD_FRAME", buf, buf_len); |
9884f9cc | 5944 | |
56f77852 | 5945 | if (!(msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_FRAME)) || |
a862e4a3 JM |
5946 | (freq && nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq)) || |
5947 | (wait && nla_put_u32(msg, NL80211_ATTR_DURATION, wait)) || | |
5948 | (offchanok && ((drv->capa.flags & WPA_DRIVER_FLAGS_OFFCHANNEL_TX) || | |
5949 | drv->test_use_roc_tx) && | |
5950 | nla_put_flag(msg, NL80211_ATTR_OFFCHANNEL_TX_OK)) || | |
5951 | (no_cck && nla_put_flag(msg, NL80211_ATTR_TX_NO_CCK_RATE)) || | |
5952 | (no_ack && nla_put_flag(msg, NL80211_ATTR_DONT_WAIT_FOR_ACK)) || | |
5953 | nla_put(msg, NL80211_ATTR_FRAME, buf_len, buf)) | |
5954 | goto fail; | |
9884f9cc JB |
5955 | |
5956 | cookie = 0; | |
5957 | ret = send_and_recv_msgs(drv, msg, cookie_handler, &cookie); | |
5958 | msg = NULL; | |
5959 | if (ret) { | |
5960 | wpa_printf(MSG_DEBUG, "nl80211: Frame command failed: ret=%d " | |
a05225c8 JM |
5961 | "(%s) (freq=%u wait=%u)", ret, strerror(-ret), |
5962 | freq, wait); | |
a862e4a3 JM |
5963 | } else { |
5964 | wpa_printf(MSG_MSGDUMP, "nl80211: Frame TX command accepted%s; " | |
5965 | "cookie 0x%llx", no_ack ? " (no ACK)" : "", | |
5966 | (long long unsigned int) cookie); | |
9884f9cc | 5967 | |
a862e4a3 JM |
5968 | if (cookie_out) |
5969 | *cookie_out = no_ack ? (u64) -1 : cookie; | |
5970 | } | |
9884f9cc | 5971 | |
a862e4a3 | 5972 | fail: |
9884f9cc JB |
5973 | nlmsg_free(msg); |
5974 | return ret; | |
5975 | } | |
5976 | ||
5977 | ||
9ebce9c5 JM |
5978 | static int wpa_driver_nl80211_send_action(struct i802_bss *bss, |
5979 | unsigned int freq, | |
190b9062 | 5980 | unsigned int wait_time, |
58f6fbe0 JM |
5981 | const u8 *dst, const u8 *src, |
5982 | const u8 *bssid, | |
b106173a JM |
5983 | const u8 *data, size_t data_len, |
5984 | int no_cck) | |
58f6fbe0 | 5985 | { |
a2e40bb6 | 5986 | struct wpa_driver_nl80211_data *drv = bss->drv; |
58f6fbe0 | 5987 | int ret = -1; |
58f6fbe0 JM |
5988 | u8 *buf; |
5989 | struct ieee80211_hdr *hdr; | |
58f6fbe0 | 5990 | |
5dfca53f | 5991 | wpa_printf(MSG_DEBUG, "nl80211: Send Action frame (ifindex=%d, " |
55231068 JM |
5992 | "freq=%u MHz wait=%d ms no_cck=%d)", |
5993 | drv->ifindex, freq, wait_time, no_cck); | |
58f6fbe0 JM |
5994 | |
5995 | buf = os_zalloc(24 + data_len); | |
5996 | if (buf == NULL) | |
5997 | return ret; | |
5998 | os_memcpy(buf + 24, data, data_len); | |
5999 | hdr = (struct ieee80211_hdr *) buf; | |
6000 | hdr->frame_control = | |
6001 | IEEE80211_FC(WLAN_FC_TYPE_MGMT, WLAN_FC_STYPE_ACTION); | |
6002 | os_memcpy(hdr->addr1, dst, ETH_ALEN); | |
6003 | os_memcpy(hdr->addr2, src, ETH_ALEN); | |
6004 | os_memcpy(hdr->addr3, bssid, ETH_ALEN); | |
6005 | ||
f78f2785 JM |
6006 | if (is_ap_interface(drv->nlmode) && |
6007 | (!(drv->capa.flags & WPA_DRIVER_FLAGS_OFFCHANNEL_TX) || | |
6008 | (int) freq == bss->freq || drv->device_ap_sme || | |
6009 | !drv->use_monitor)) | |
9ebce9c5 JM |
6010 | ret = wpa_driver_nl80211_send_mlme(bss, buf, 24 + data_len, |
6011 | 0, freq, no_cck, 1, | |
6012 | wait_time); | |
9884f9cc | 6013 | else |
88df0ef7 | 6014 | ret = nl80211_send_frame_cmd(bss, freq, wait_time, buf, |
5dfca53f | 6015 | 24 + data_len, |
b106173a | 6016 | &drv->send_action_cookie, |
88df0ef7 | 6017 | no_cck, 0, 1); |
58f6fbe0 | 6018 | |
f8bf1421 | 6019 | os_free(buf); |
58f6fbe0 JM |
6020 | return ret; |
6021 | } | |
6022 | ||
6023 | ||
5dfca53f JB |
6024 | static void wpa_driver_nl80211_send_action_cancel_wait(void *priv) |
6025 | { | |
6026 | struct i802_bss *bss = priv; | |
6027 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
6028 | struct nl_msg *msg; | |
6029 | int ret; | |
6030 | ||
316a9e4d JM |
6031 | wpa_printf(MSG_DEBUG, "nl80211: Cancel TX frame wait: cookie=0x%llx", |
6032 | (long long unsigned int) drv->send_action_cookie); | |
56f77852 | 6033 | if (!(msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_FRAME_WAIT_CANCEL)) || |
a862e4a3 JM |
6034 | nla_put_u64(msg, NL80211_ATTR_COOKIE, drv->send_action_cookie)) { |
6035 | nlmsg_free(msg); | |
6036 | return; | |
6037 | } | |
5dfca53f JB |
6038 | |
6039 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); | |
5dfca53f JB |
6040 | if (ret) |
6041 | wpa_printf(MSG_DEBUG, "nl80211: wait cancel failed: ret=%d " | |
6042 | "(%s)", ret, strerror(-ret)); | |
5dfca53f JB |
6043 | } |
6044 | ||
6045 | ||
55777702 JM |
6046 | static int wpa_driver_nl80211_remain_on_channel(void *priv, unsigned int freq, |
6047 | unsigned int duration) | |
6048 | { | |
a2e40bb6 FF |
6049 | struct i802_bss *bss = priv; |
6050 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
55777702 JM |
6051 | struct nl_msg *msg; |
6052 | int ret; | |
6053 | u64 cookie; | |
6054 | ||
56f77852 | 6055 | if (!(msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_REMAIN_ON_CHANNEL)) || |
a862e4a3 JM |
6056 | nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq) || |
6057 | nla_put_u32(msg, NL80211_ATTR_DURATION, duration)) { | |
6058 | nlmsg_free(msg); | |
6059 | return -1; | |
6060 | } | |
55777702 JM |
6061 | |
6062 | cookie = 0; | |
6063 | ret = send_and_recv_msgs(drv, msg, cookie_handler, &cookie); | |
6064 | if (ret == 0) { | |
6065 | wpa_printf(MSG_DEBUG, "nl80211: Remain-on-channel cookie " | |
6066 | "0x%llx for freq=%u MHz duration=%u", | |
6067 | (long long unsigned int) cookie, freq, duration); | |
6068 | drv->remain_on_chan_cookie = cookie; | |
531f0331 | 6069 | drv->pending_remain_on_chan = 1; |
55777702 JM |
6070 | return 0; |
6071 | } | |
6072 | wpa_printf(MSG_DEBUG, "nl80211: Failed to request remain-on-channel " | |
15ed5535 JM |
6073 | "(freq=%d duration=%u): %d (%s)", |
6074 | freq, duration, ret, strerror(-ret)); | |
55777702 JM |
6075 | return -1; |
6076 | } | |
6077 | ||
6078 | ||
6079 | static int wpa_driver_nl80211_cancel_remain_on_channel(void *priv) | |
6080 | { | |
a2e40bb6 FF |
6081 | struct i802_bss *bss = priv; |
6082 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
55777702 JM |
6083 | struct nl_msg *msg; |
6084 | int ret; | |
6085 | ||
6086 | if (!drv->pending_remain_on_chan) { | |
6087 | wpa_printf(MSG_DEBUG, "nl80211: No pending remain-on-channel " | |
6088 | "to cancel"); | |
6089 | return -1; | |
6090 | } | |
6091 | ||
6092 | wpa_printf(MSG_DEBUG, "nl80211: Cancel remain-on-channel with cookie " | |
6093 | "0x%llx", | |
6094 | (long long unsigned int) drv->remain_on_chan_cookie); | |
6095 | ||
56f77852 JM |
6096 | msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL); |
6097 | if (!msg || | |
a862e4a3 JM |
6098 | nla_put_u64(msg, NL80211_ATTR_COOKIE, drv->remain_on_chan_cookie)) { |
6099 | nlmsg_free(msg); | |
6100 | return -1; | |
6101 | } | |
55777702 JM |
6102 | |
6103 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); | |
6104 | if (ret == 0) | |
6105 | return 0; | |
6106 | wpa_printf(MSG_DEBUG, "nl80211: Failed to cancel remain-on-channel: " | |
6107 | "%d (%s)", ret, strerror(-ret)); | |
55777702 JM |
6108 | return -1; |
6109 | } | |
6110 | ||
6111 | ||
9ebce9c5 | 6112 | static int wpa_driver_nl80211_probe_req_report(struct i802_bss *bss, int report) |
504e905c | 6113 | { |
a2e40bb6 | 6114 | struct wpa_driver_nl80211_data *drv = bss->drv; |
504e905c | 6115 | |
5582a5d1 | 6116 | if (!report) { |
0d891981 | 6117 | if (bss->nl_preq && drv->device_ap_sme && |
b8d87ed2 AP |
6118 | is_ap_interface(drv->nlmode) && !bss->in_deinit && |
6119 | !bss->static_ap) { | |
0d891981 JM |
6120 | /* |
6121 | * Do not disable Probe Request reporting that was | |
6122 | * enabled in nl80211_setup_ap(). | |
6123 | */ | |
6124 | wpa_printf(MSG_DEBUG, "nl80211: Skip disabling of " | |
6125 | "Probe Request reporting nl_preq=%p while " | |
6126 | "in AP mode", bss->nl_preq); | |
6127 | } else if (bss->nl_preq) { | |
36488c05 JM |
6128 | wpa_printf(MSG_DEBUG, "nl80211: Disable Probe Request " |
6129 | "reporting nl_preq=%p", bss->nl_preq); | |
5f65e9f7 | 6130 | nl80211_destroy_eloop_handle(&bss->nl_preq); |
5582a5d1 JB |
6131 | } |
6132 | return 0; | |
6133 | } | |
6134 | ||
481234cf | 6135 | if (bss->nl_preq) { |
5582a5d1 | 6136 | wpa_printf(MSG_DEBUG, "nl80211: Probe Request reporting " |
36488c05 | 6137 | "already on! nl_preq=%p", bss->nl_preq); |
5582a5d1 JB |
6138 | return 0; |
6139 | } | |
6140 | ||
481234cf JM |
6141 | bss->nl_preq = nl_create_handle(drv->global->nl_cb, "preq"); |
6142 | if (bss->nl_preq == NULL) | |
5582a5d1 | 6143 | return -1; |
36488c05 JM |
6144 | wpa_printf(MSG_DEBUG, "nl80211: Enable Probe Request " |
6145 | "reporting nl_preq=%p", bss->nl_preq); | |
5582a5d1 | 6146 | |
481234cf | 6147 | if (nl80211_register_frame(bss, bss->nl_preq, |
5582a5d1 JB |
6148 | (WLAN_FC_TYPE_MGMT << 2) | |
6149 | (WLAN_FC_STYPE_PROBE_REQ << 4), | |
a92dfde8 JB |
6150 | NULL, 0) < 0) |
6151 | goto out_err; | |
5582a5d1 | 6152 | |
5f65e9f7 JB |
6153 | nl80211_register_eloop_read(&bss->nl_preq, |
6154 | wpa_driver_nl80211_event_receive, | |
6155 | bss->nl_cb); | |
5582a5d1 | 6156 | |
504e905c | 6157 | return 0; |
5582a5d1 | 6158 | |
a92dfde8 | 6159 | out_err: |
221a59c9 | 6160 | nl_destroy_handles(&bss->nl_preq); |
5582a5d1 | 6161 | return -1; |
504e905c JM |
6162 | } |
6163 | ||
6164 | ||
4e5cb1a3 JM |
6165 | static int nl80211_disable_11b_rates(struct wpa_driver_nl80211_data *drv, |
6166 | int ifindex, int disabled) | |
6167 | { | |
6168 | struct nl_msg *msg; | |
6169 | struct nlattr *bands, *band; | |
6170 | int ret; | |
6171 | ||
3e208481 JM |
6172 | wpa_printf(MSG_DEBUG, |
6173 | "nl80211: NL80211_CMD_SET_TX_BITRATE_MASK (ifindex=%d %s)", | |
6174 | ifindex, disabled ? "NL80211_TXRATE_LEGACY=OFDM-only" : | |
6175 | "no NL80211_TXRATE_LEGACY constraint"); | |
6176 | ||
95376e1a JM |
6177 | msg = nl80211_ifindex_msg(drv, ifindex, 0, |
6178 | NL80211_CMD_SET_TX_BITRATE_MASK); | |
4e5cb1a3 JM |
6179 | if (!msg) |
6180 | return -1; | |
6181 | ||
4e5cb1a3 JM |
6182 | bands = nla_nest_start(msg, NL80211_ATTR_TX_RATES); |
6183 | if (!bands) | |
a862e4a3 | 6184 | goto fail; |
4e5cb1a3 JM |
6185 | |
6186 | /* | |
6187 | * Disable 2 GHz rates 1, 2, 5.5, 11 Mbps by masking out everything | |
6188 | * else apart from 6, 9, 12, 18, 24, 36, 48, 54 Mbps from non-MCS | |
6189 | * rates. All 5 GHz rates are left enabled. | |
6190 | */ | |
6191 | band = nla_nest_start(msg, NL80211_BAND_2GHZ); | |
a862e4a3 JM |
6192 | if (!band || |
6193 | (disabled && nla_put(msg, NL80211_TXRATE_LEGACY, 8, | |
6194 | "\x0c\x12\x18\x24\x30\x48\x60\x6c"))) | |
6195 | goto fail; | |
4e5cb1a3 JM |
6196 | nla_nest_end(msg, band); |
6197 | ||
6198 | nla_nest_end(msg, bands); | |
6199 | ||
6200 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); | |
4e5cb1a3 JM |
6201 | if (ret) { |
6202 | wpa_printf(MSG_DEBUG, "nl80211: Set TX rates failed: ret=%d " | |
6203 | "(%s)", ret, strerror(-ret)); | |
1d0c6fb1 JM |
6204 | } else |
6205 | drv->disabled_11b_rates = disabled; | |
4e5cb1a3 JM |
6206 | |
6207 | return ret; | |
6208 | ||
a862e4a3 | 6209 | fail: |
4e5cb1a3 JM |
6210 | nlmsg_free(msg); |
6211 | return -1; | |
6212 | } | |
6213 | ||
6214 | ||
af473088 JM |
6215 | static int wpa_driver_nl80211_deinit_ap(void *priv) |
6216 | { | |
a2e40bb6 FF |
6217 | struct i802_bss *bss = priv; |
6218 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
b1f625e0 | 6219 | if (!is_ap_interface(drv->nlmode)) |
af473088 JM |
6220 | return -1; |
6221 | wpa_driver_nl80211_del_beacon(drv); | |
9bc5cfa3 | 6222 | bss->beacon_set = 0; |
60b13c20 IP |
6223 | |
6224 | /* | |
6225 | * If the P2P GO interface was dynamically added, then it is | |
6226 | * possible that the interface change to station is not possible. | |
6227 | */ | |
6228 | if (drv->nlmode == NL80211_IFTYPE_P2P_GO && bss->if_dynamic) | |
6229 | return 0; | |
6230 | ||
b1f625e0 | 6231 | return wpa_driver_nl80211_set_mode(priv, NL80211_IFTYPE_STATION); |
af473088 JM |
6232 | } |
6233 | ||
6234 | ||
695c7038 SW |
6235 | static int wpa_driver_nl80211_stop_ap(void *priv) |
6236 | { | |
6237 | struct i802_bss *bss = priv; | |
6238 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
6239 | if (!is_ap_interface(drv->nlmode)) | |
6240 | return -1; | |
6241 | wpa_driver_nl80211_del_beacon(drv); | |
6242 | bss->beacon_set = 0; | |
6243 | return 0; | |
6244 | } | |
6245 | ||
6246 | ||
3c29244e EP |
6247 | static int wpa_driver_nl80211_deinit_p2p_cli(void *priv) |
6248 | { | |
6249 | struct i802_bss *bss = priv; | |
6250 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
6251 | if (drv->nlmode != NL80211_IFTYPE_P2P_CLIENT) | |
6252 | return -1; | |
60b13c20 IP |
6253 | |
6254 | /* | |
6255 | * If the P2P Client interface was dynamically added, then it is | |
6256 | * possible that the interface change to station is not possible. | |
6257 | */ | |
6258 | if (bss->if_dynamic) | |
6259 | return 0; | |
6260 | ||
3c29244e EP |
6261 | return wpa_driver_nl80211_set_mode(priv, NL80211_IFTYPE_STATION); |
6262 | } | |
6263 | ||
6264 | ||
207ef3fb JM |
6265 | static void wpa_driver_nl80211_resume(void *priv) |
6266 | { | |
a2e40bb6 | 6267 | struct i802_bss *bss = priv; |
91724d6f AS |
6268 | |
6269 | if (i802_set_iface_flags(bss, 1)) | |
6270 | wpa_printf(MSG_DEBUG, "nl80211: Failed to set interface up on resume event"); | |
207ef3fb JM |
6271 | } |
6272 | ||
6273 | ||
b625473c JM |
6274 | static int nl80211_signal_monitor(void *priv, int threshold, int hysteresis) |
6275 | { | |
6276 | struct i802_bss *bss = priv; | |
6277 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
8970bae8 JB |
6278 | struct nl_msg *msg; |
6279 | struct nlattr *cqm; | |
b625473c JM |
6280 | |
6281 | wpa_printf(MSG_DEBUG, "nl80211: Signal monitor threshold=%d " | |
6282 | "hysteresis=%d", threshold, hysteresis); | |
6283 | ||
13f83980 | 6284 | if (!(msg = nl80211_bss_msg(bss, 0, NL80211_CMD_SET_CQM)) || |
a862e4a3 JM |
6285 | !(cqm = nla_nest_start(msg, NL80211_ATTR_CQM)) || |
6286 | nla_put_u32(msg, NL80211_ATTR_CQM_RSSI_THOLD, threshold) || | |
6287 | nla_put_u32(msg, NL80211_ATTR_CQM_RSSI_HYST, hysteresis)) { | |
6288 | nlmsg_free(msg); | |
6289 | return -1; | |
6290 | } | |
8970bae8 | 6291 | nla_nest_end(msg, cqm); |
21270bb4 | 6292 | |
a862e4a3 | 6293 | return send_and_recv_msgs(drv, msg, NULL, NULL); |
b625473c JM |
6294 | } |
6295 | ||
6296 | ||
2cc8d8f4 AO |
6297 | static int get_channel_width(struct nl_msg *msg, void *arg) |
6298 | { | |
6299 | struct nlattr *tb[NL80211_ATTR_MAX + 1]; | |
6300 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); | |
6301 | struct wpa_signal_info *sig_change = arg; | |
6302 | ||
6303 | nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), | |
6304 | genlmsg_attrlen(gnlh, 0), NULL); | |
6305 | ||
6306 | sig_change->center_frq1 = -1; | |
6307 | sig_change->center_frq2 = -1; | |
6308 | sig_change->chanwidth = CHAN_WIDTH_UNKNOWN; | |
6309 | ||
6310 | if (tb[NL80211_ATTR_CHANNEL_WIDTH]) { | |
6311 | sig_change->chanwidth = convert2width( | |
6312 | nla_get_u32(tb[NL80211_ATTR_CHANNEL_WIDTH])); | |
6313 | if (tb[NL80211_ATTR_CENTER_FREQ1]) | |
6314 | sig_change->center_frq1 = | |
6315 | nla_get_u32(tb[NL80211_ATTR_CENTER_FREQ1]); | |
6316 | if (tb[NL80211_ATTR_CENTER_FREQ2]) | |
6317 | sig_change->center_frq2 = | |
6318 | nla_get_u32(tb[NL80211_ATTR_CENTER_FREQ2]); | |
6319 | } | |
6320 | ||
6321 | return NL_SKIP; | |
6322 | } | |
6323 | ||
6324 | ||
6325 | static int nl80211_get_channel_width(struct wpa_driver_nl80211_data *drv, | |
6326 | struct wpa_signal_info *sig) | |
6327 | { | |
6328 | struct nl_msg *msg; | |
6329 | ||
9725b784 | 6330 | msg = nl80211_drv_msg(drv, 0, NL80211_CMD_GET_INTERFACE); |
2cc8d8f4 | 6331 | return send_and_recv_msgs(drv, msg, get_channel_width, sig); |
2cc8d8f4 AO |
6332 | } |
6333 | ||
6334 | ||
1c5c7273 PS |
6335 | static int nl80211_signal_poll(void *priv, struct wpa_signal_info *si) |
6336 | { | |
6337 | struct i802_bss *bss = priv; | |
6338 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
6339 | int res; | |
6340 | ||
6341 | os_memset(si, 0, sizeof(*si)); | |
6342 | res = nl80211_get_link_signal(drv, si); | |
6343 | if (res != 0) | |
6344 | return res; | |
6345 | ||
2cc8d8f4 AO |
6346 | res = nl80211_get_channel_width(drv, si); |
6347 | if (res != 0) | |
6348 | return res; | |
6349 | ||
1c5c7273 PS |
6350 | return nl80211_get_link_noise(drv, si); |
6351 | } | |
6352 | ||
6353 | ||
57ebba59 JJ |
6354 | static int wpa_driver_nl80211_shared_freq(void *priv) |
6355 | { | |
6356 | struct i802_bss *bss = priv; | |
6357 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
6358 | struct wpa_driver_nl80211_data *driver; | |
6359 | int freq = 0; | |
6360 | ||
6361 | /* | |
6362 | * If the same PHY is in connected state with some other interface, | |
6363 | * then retrieve the assoc freq. | |
6364 | */ | |
6365 | wpa_printf(MSG_DEBUG, "nl80211: Get shared freq for PHY %s", | |
6366 | drv->phyname); | |
6367 | ||
6368 | dl_list_for_each(driver, &drv->global->interfaces, | |
6369 | struct wpa_driver_nl80211_data, list) { | |
6370 | if (drv == driver || | |
6371 | os_strcmp(drv->phyname, driver->phyname) != 0 || | |
6372 | !driver->associated) | |
6373 | continue; | |
6374 | ||
6375 | wpa_printf(MSG_DEBUG, "nl80211: Found a match for PHY %s - %s " | |
6376 | MACSTR, | |
834ee56f KP |
6377 | driver->phyname, driver->first_bss->ifname, |
6378 | MAC2STR(driver->first_bss->addr)); | |
d3bd0f05 | 6379 | if (is_ap_interface(driver->nlmode)) |
834ee56f | 6380 | freq = driver->first_bss->freq; |
d3bd0f05 JJ |
6381 | else |
6382 | freq = nl80211_get_assoc_freq(driver); | |
57ebba59 JJ |
6383 | wpa_printf(MSG_DEBUG, "nl80211: Shared freq for PHY %s: %d", |
6384 | drv->phyname, freq); | |
6385 | } | |
6386 | ||
6387 | if (!freq) | |
6388 | wpa_printf(MSG_DEBUG, "nl80211: No shared interface for " | |
6389 | "PHY (%s) in associated state", drv->phyname); | |
6390 | ||
6391 | return freq; | |
6392 | } | |
6393 | ||
6394 | ||
b91ab76e JM |
6395 | static int nl80211_send_frame(void *priv, const u8 *data, size_t data_len, |
6396 | int encrypt) | |
6397 | { | |
6398 | struct i802_bss *bss = priv; | |
55231068 JM |
6399 | return wpa_driver_nl80211_send_frame(bss, data, data_len, encrypt, 0, |
6400 | 0, 0, 0, 0); | |
b91ab76e JM |
6401 | } |
6402 | ||
6403 | ||
c55f774d JM |
6404 | static int nl80211_set_param(void *priv, const char *param) |
6405 | { | |
c55f774d JM |
6406 | wpa_printf(MSG_DEBUG, "nl80211: driver param='%s'", param); |
6407 | if (param == NULL) | |
6408 | return 0; | |
6409 | ||
6410 | #ifdef CONFIG_P2P | |
6411 | if (os_strstr(param, "use_p2p_group_interface=1")) { | |
482856c8 JM |
6412 | struct i802_bss *bss = priv; |
6413 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
6414 | ||
c55f774d JM |
6415 | wpa_printf(MSG_DEBUG, "nl80211: Use separate P2P group " |
6416 | "interface"); | |
6417 | drv->capa.flags |= WPA_DRIVER_FLAGS_P2P_CONCURRENT; | |
6418 | drv->capa.flags |= WPA_DRIVER_FLAGS_P2P_MGMT_AND_NON_P2P; | |
6419 | } | |
6420 | #endif /* CONFIG_P2P */ | |
6421 | ||
327b01d3 JM |
6422 | if (os_strstr(param, "use_monitor=1")) { |
6423 | struct i802_bss *bss = priv; | |
6424 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
6425 | drv->use_monitor = 1; | |
6426 | } | |
6427 | ||
6428 | if (os_strstr(param, "force_connect_cmd=1")) { | |
6429 | struct i802_bss *bss = priv; | |
6430 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
6431 | drv->capa.flags &= ~WPA_DRIVER_FLAGS_SME; | |
b497a212 | 6432 | drv->force_connect_cmd = 1; |
327b01d3 JM |
6433 | } |
6434 | ||
64abb725 JM |
6435 | if (os_strstr(param, "no_offchannel_tx=1")) { |
6436 | struct i802_bss *bss = priv; | |
6437 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
6438 | drv->capa.flags &= ~WPA_DRIVER_FLAGS_OFFCHANNEL_TX; | |
6439 | drv->test_use_roc_tx = 1; | |
6440 | } | |
6441 | ||
c55f774d JM |
6442 | return 0; |
6443 | } | |
6444 | ||
6445 | ||
f2ed8023 JM |
6446 | static void * nl80211_global_init(void) |
6447 | { | |
6448 | struct nl80211_global *global; | |
36d84860 BG |
6449 | struct netlink_config *cfg; |
6450 | ||
f2ed8023 JM |
6451 | global = os_zalloc(sizeof(*global)); |
6452 | if (global == NULL) | |
6453 | return NULL; | |
c81eff1a | 6454 | global->ioctl_sock = -1; |
f2ed8023 | 6455 | dl_list_init(&global->interfaces); |
ff6a158b | 6456 | global->if_add_ifindex = -1; |
36d84860 BG |
6457 | |
6458 | cfg = os_zalloc(sizeof(*cfg)); | |
6459 | if (cfg == NULL) | |
6460 | goto err; | |
6461 | ||
6462 | cfg->ctx = global; | |
6463 | cfg->newlink_cb = wpa_driver_nl80211_event_rtm_newlink; | |
6464 | cfg->dellink_cb = wpa_driver_nl80211_event_rtm_dellink; | |
6465 | global->netlink = netlink_init(cfg); | |
6466 | if (global->netlink == NULL) { | |
6467 | os_free(cfg); | |
6468 | goto err; | |
6469 | } | |
6470 | ||
2a7b66f5 BG |
6471 | if (wpa_driver_nl80211_init_nl_global(global) < 0) |
6472 | goto err; | |
6473 | ||
c81eff1a BG |
6474 | global->ioctl_sock = socket(PF_INET, SOCK_DGRAM, 0); |
6475 | if (global->ioctl_sock < 0) { | |
7ac3616d JM |
6476 | wpa_printf(MSG_ERROR, "nl80211: socket(PF_INET,SOCK_DGRAM) failed: %s", |
6477 | strerror(errno)); | |
c81eff1a BG |
6478 | goto err; |
6479 | } | |
6480 | ||
f2ed8023 | 6481 | return global; |
36d84860 BG |
6482 | |
6483 | err: | |
6484 | nl80211_global_deinit(global); | |
6485 | return NULL; | |
f2ed8023 JM |
6486 | } |
6487 | ||
6488 | ||
6489 | static void nl80211_global_deinit(void *priv) | |
6490 | { | |
6491 | struct nl80211_global *global = priv; | |
6492 | if (global == NULL) | |
6493 | return; | |
6494 | if (!dl_list_empty(&global->interfaces)) { | |
6495 | wpa_printf(MSG_ERROR, "nl80211: %u interface(s) remain at " | |
6496 | "nl80211_global_deinit", | |
6497 | dl_list_len(&global->interfaces)); | |
6498 | } | |
36d84860 BG |
6499 | |
6500 | if (global->netlink) | |
6501 | netlink_deinit(global->netlink); | |
6502 | ||
276e2d67 BG |
6503 | nl_destroy_handles(&global->nl); |
6504 | ||
5f65e9f7 JB |
6505 | if (global->nl_event) |
6506 | nl80211_destroy_eloop_handle(&global->nl_event); | |
d6c9aab8 JB |
6507 | |
6508 | nl_cb_put(global->nl_cb); | |
2a7b66f5 | 6509 | |
c81eff1a BG |
6510 | if (global->ioctl_sock >= 0) |
6511 | close(global->ioctl_sock); | |
6512 | ||
f2ed8023 JM |
6513 | os_free(global); |
6514 | } | |
6515 | ||
6516 | ||
6859f1cb BG |
6517 | static const char * nl80211_get_radio_name(void *priv) |
6518 | { | |
6519 | struct i802_bss *bss = priv; | |
6520 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
6521 | return drv->phyname; | |
6522 | } | |
6523 | ||
6524 | ||
a6efc65d JM |
6525 | static int nl80211_pmkid(struct i802_bss *bss, int cmd, const u8 *bssid, |
6526 | const u8 *pmkid) | |
6527 | { | |
6528 | struct nl_msg *msg; | |
6529 | ||
13f83980 | 6530 | if (!(msg = nl80211_bss_msg(bss, 0, cmd)) || |
a862e4a3 JM |
6531 | (pmkid && nla_put(msg, NL80211_ATTR_PMKID, 16, pmkid)) || |
6532 | (bssid && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid))) { | |
6533 | nlmsg_free(msg); | |
6534 | return -ENOBUFS; | |
6535 | } | |
a6efc65d JM |
6536 | |
6537 | return send_and_recv_msgs(bss->drv, msg, NULL, NULL); | |
a6efc65d JM |
6538 | } |
6539 | ||
6540 | ||
6541 | static int nl80211_add_pmkid(void *priv, const u8 *bssid, const u8 *pmkid) | |
6542 | { | |
6543 | struct i802_bss *bss = priv; | |
6544 | wpa_printf(MSG_DEBUG, "nl80211: Add PMKID for " MACSTR, MAC2STR(bssid)); | |
6545 | return nl80211_pmkid(bss, NL80211_CMD_SET_PMKSA, bssid, pmkid); | |
6546 | } | |
6547 | ||
6548 | ||
6549 | static int nl80211_remove_pmkid(void *priv, const u8 *bssid, const u8 *pmkid) | |
6550 | { | |
6551 | struct i802_bss *bss = priv; | |
6552 | wpa_printf(MSG_DEBUG, "nl80211: Delete PMKID for " MACSTR, | |
6553 | MAC2STR(bssid)); | |
6554 | return nl80211_pmkid(bss, NL80211_CMD_DEL_PMKSA, bssid, pmkid); | |
6555 | } | |
6556 | ||
6557 | ||
6558 | static int nl80211_flush_pmkid(void *priv) | |
6559 | { | |
6560 | struct i802_bss *bss = priv; | |
6561 | wpa_printf(MSG_DEBUG, "nl80211: Flush PMKIDs"); | |
6562 | return nl80211_pmkid(bss, NL80211_CMD_FLUSH_PMKSA, NULL, NULL); | |
6563 | } | |
6564 | ||
6565 | ||
0185007c MK |
6566 | static void clean_survey_results(struct survey_results *survey_results) |
6567 | { | |
6568 | struct freq_survey *survey, *tmp; | |
6569 | ||
6570 | if (dl_list_empty(&survey_results->survey_list)) | |
6571 | return; | |
6572 | ||
6573 | dl_list_for_each_safe(survey, tmp, &survey_results->survey_list, | |
6574 | struct freq_survey, list) { | |
6575 | dl_list_del(&survey->list); | |
6576 | os_free(survey); | |
6577 | } | |
6578 | } | |
6579 | ||
6580 | ||
6581 | static void add_survey(struct nlattr **sinfo, u32 ifidx, | |
6582 | struct dl_list *survey_list) | |
6583 | { | |
6584 | struct freq_survey *survey; | |
6585 | ||
6586 | survey = os_zalloc(sizeof(struct freq_survey)); | |
6587 | if (!survey) | |
6588 | return; | |
6589 | ||
6590 | survey->ifidx = ifidx; | |
6591 | survey->freq = nla_get_u32(sinfo[NL80211_SURVEY_INFO_FREQUENCY]); | |
6592 | survey->filled = 0; | |
6593 | ||
6594 | if (sinfo[NL80211_SURVEY_INFO_NOISE]) { | |
6595 | survey->nf = (int8_t) | |
6596 | nla_get_u8(sinfo[NL80211_SURVEY_INFO_NOISE]); | |
6597 | survey->filled |= SURVEY_HAS_NF; | |
6598 | } | |
6599 | ||
6600 | if (sinfo[NL80211_SURVEY_INFO_CHANNEL_TIME]) { | |
6601 | survey->channel_time = | |
6602 | nla_get_u64(sinfo[NL80211_SURVEY_INFO_CHANNEL_TIME]); | |
6603 | survey->filled |= SURVEY_HAS_CHAN_TIME; | |
6604 | } | |
6605 | ||
6606 | if (sinfo[NL80211_SURVEY_INFO_CHANNEL_TIME_BUSY]) { | |
6607 | survey->channel_time_busy = | |
6608 | nla_get_u64(sinfo[NL80211_SURVEY_INFO_CHANNEL_TIME_BUSY]); | |
6609 | survey->filled |= SURVEY_HAS_CHAN_TIME_BUSY; | |
6610 | } | |
6611 | ||
6612 | if (sinfo[NL80211_SURVEY_INFO_CHANNEL_TIME_RX]) { | |
6613 | survey->channel_time_rx = | |
6614 | nla_get_u64(sinfo[NL80211_SURVEY_INFO_CHANNEL_TIME_RX]); | |
6615 | survey->filled |= SURVEY_HAS_CHAN_TIME_RX; | |
6616 | } | |
6617 | ||
6618 | if (sinfo[NL80211_SURVEY_INFO_CHANNEL_TIME_TX]) { | |
6619 | survey->channel_time_tx = | |
6620 | nla_get_u64(sinfo[NL80211_SURVEY_INFO_CHANNEL_TIME_TX]); | |
6621 | survey->filled |= SURVEY_HAS_CHAN_TIME_TX; | |
6622 | } | |
6623 | ||
6624 | 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)", | |
6625 | survey->freq, | |
6626 | survey->nf, | |
6627 | (unsigned long int) survey->channel_time, | |
6628 | (unsigned long int) survey->channel_time_busy, | |
6629 | (unsigned long int) survey->channel_time_tx, | |
6630 | (unsigned long int) survey->channel_time_rx, | |
6631 | survey->filled); | |
6632 | ||
6633 | dl_list_add_tail(survey_list, &survey->list); | |
6634 | } | |
6635 | ||
6636 | ||
6637 | static int check_survey_ok(struct nlattr **sinfo, u32 surveyed_freq, | |
6638 | unsigned int freq_filter) | |
6639 | { | |
6640 | if (!freq_filter) | |
6641 | return 1; | |
6642 | ||
6643 | return freq_filter == surveyed_freq; | |
6644 | } | |
6645 | ||
6646 | ||
6647 | static int survey_handler(struct nl_msg *msg, void *arg) | |
6648 | { | |
6649 | struct nlattr *tb[NL80211_ATTR_MAX + 1]; | |
6650 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); | |
6651 | struct nlattr *sinfo[NL80211_SURVEY_INFO_MAX + 1]; | |
6652 | struct survey_results *survey_results; | |
6653 | u32 surveyed_freq = 0; | |
6654 | u32 ifidx; | |
6655 | ||
6656 | static struct nla_policy survey_policy[NL80211_SURVEY_INFO_MAX + 1] = { | |
6657 | [NL80211_SURVEY_INFO_FREQUENCY] = { .type = NLA_U32 }, | |
6658 | [NL80211_SURVEY_INFO_NOISE] = { .type = NLA_U8 }, | |
6659 | }; | |
6660 | ||
6661 | survey_results = (struct survey_results *) arg; | |
6662 | ||
6663 | nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), | |
6664 | genlmsg_attrlen(gnlh, 0), NULL); | |
6665 | ||
e28f39b7 SJ |
6666 | if (!tb[NL80211_ATTR_IFINDEX]) |
6667 | return NL_SKIP; | |
6668 | ||
0185007c MK |
6669 | ifidx = nla_get_u32(tb[NL80211_ATTR_IFINDEX]); |
6670 | ||
6671 | if (!tb[NL80211_ATTR_SURVEY_INFO]) | |
6672 | return NL_SKIP; | |
6673 | ||
6674 | if (nla_parse_nested(sinfo, NL80211_SURVEY_INFO_MAX, | |
6675 | tb[NL80211_ATTR_SURVEY_INFO], | |
6676 | survey_policy)) | |
6677 | return NL_SKIP; | |
6678 | ||
6679 | if (!sinfo[NL80211_SURVEY_INFO_FREQUENCY]) { | |
6680 | wpa_printf(MSG_ERROR, "nl80211: Invalid survey data"); | |
6681 | return NL_SKIP; | |
6682 | } | |
6683 | ||
6684 | surveyed_freq = nla_get_u32(sinfo[NL80211_SURVEY_INFO_FREQUENCY]); | |
6685 | ||
6686 | if (!check_survey_ok(sinfo, surveyed_freq, | |
6687 | survey_results->freq_filter)) | |
6688 | return NL_SKIP; | |
6689 | ||
6690 | if (survey_results->freq_filter && | |
6691 | survey_results->freq_filter != surveyed_freq) { | |
6692 | wpa_printf(MSG_EXCESSIVE, "nl80211: Ignoring survey data for freq %d MHz", | |
6693 | surveyed_freq); | |
6694 | return NL_SKIP; | |
6695 | } | |
6696 | ||
6697 | add_survey(sinfo, ifidx, &survey_results->survey_list); | |
6698 | ||
6699 | return NL_SKIP; | |
6700 | } | |
6701 | ||
6702 | ||
6703 | static int wpa_driver_nl80211_get_survey(void *priv, unsigned int freq) | |
6704 | { | |
6705 | struct i802_bss *bss = priv; | |
6706 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
6707 | struct nl_msg *msg; | |
9725b784 | 6708 | int err; |
0185007c MK |
6709 | union wpa_event_data data; |
6710 | struct survey_results *survey_results; | |
6711 | ||
6712 | os_memset(&data, 0, sizeof(data)); | |
6713 | survey_results = &data.survey_results; | |
6714 | ||
6715 | dl_list_init(&survey_results->survey_list); | |
6716 | ||
9725b784 | 6717 | msg = nl80211_drv_msg(drv, NLM_F_DUMP, NL80211_CMD_GET_SURVEY); |
0185007c | 6718 | if (!msg) |
a862e4a3 | 6719 | return -ENOBUFS; |
0185007c | 6720 | |
0185007c MK |
6721 | if (freq) |
6722 | data.survey_results.freq_filter = freq; | |
6723 | ||
6724 | do { | |
6725 | wpa_printf(MSG_DEBUG, "nl80211: Fetch survey data"); | |
6726 | err = send_and_recv_msgs(drv, msg, survey_handler, | |
6727 | survey_results); | |
6728 | } while (err > 0); | |
6729 | ||
a862e4a3 | 6730 | if (err) |
0185007c | 6731 | wpa_printf(MSG_ERROR, "nl80211: Failed to process survey data"); |
a862e4a3 JM |
6732 | else |
6733 | wpa_supplicant_event(drv->ctx, EVENT_SURVEY, &data); | |
0185007c | 6734 | |
0185007c | 6735 | clean_survey_results(survey_results); |
0185007c MK |
6736 | return err; |
6737 | } | |
6738 | ||
6739 | ||
b14a210c JB |
6740 | static void nl80211_set_rekey_info(void *priv, const u8 *kek, const u8 *kck, |
6741 | const u8 *replay_ctr) | |
6742 | { | |
6743 | struct i802_bss *bss = priv; | |
6744 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
6745 | struct nlattr *replay_nested; | |
6746 | struct nl_msg *msg; | |
64ae2447 | 6747 | int ret; |
b14a210c | 6748 | |
64ae2447 JM |
6749 | if (!drv->set_rekey_offload) |
6750 | return; | |
6751 | ||
6752 | wpa_printf(MSG_DEBUG, "nl80211: Set rekey offload"); | |
13f83980 | 6753 | if (!(msg = nl80211_bss_msg(bss, 0, NL80211_CMD_SET_REKEY_OFFLOAD)) || |
a862e4a3 JM |
6754 | !(replay_nested = nla_nest_start(msg, NL80211_ATTR_REKEY_DATA)) || |
6755 | nla_put(msg, NL80211_REKEY_DATA_KEK, NL80211_KEK_LEN, kek) || | |
6756 | nla_put(msg, NL80211_REKEY_DATA_KCK, NL80211_KCK_LEN, kck) || | |
6757 | nla_put(msg, NL80211_REKEY_DATA_REPLAY_CTR, NL80211_REPLAY_CTR_LEN, | |
6758 | replay_ctr)) { | |
bbd89bfc | 6759 | nl80211_nlmsg_clear(msg); |
a862e4a3 JM |
6760 | nlmsg_free(msg); |
6761 | return; | |
6762 | } | |
b14a210c JB |
6763 | |
6764 | nla_nest_end(msg, replay_nested); | |
6765 | ||
64ae2447 JM |
6766 | ret = send_and_recv_msgs(drv, msg, NULL, (void *) -1); |
6767 | if (ret == -EOPNOTSUPP) { | |
6768 | wpa_printf(MSG_DEBUG, | |
6769 | "nl80211: Driver does not support rekey offload"); | |
6770 | drv->set_rekey_offload = 0; | |
6771 | } | |
b14a210c JB |
6772 | } |
6773 | ||
6774 | ||
39718852 JB |
6775 | static void nl80211_send_null_frame(struct i802_bss *bss, const u8 *own_addr, |
6776 | const u8 *addr, int qos) | |
bcf24348 | 6777 | { |
39718852 JB |
6778 | /* send data frame to poll STA and check whether |
6779 | * this frame is ACKed */ | |
bcf24348 JB |
6780 | struct { |
6781 | struct ieee80211_hdr hdr; | |
6782 | u16 qos_ctl; | |
6783 | } STRUCT_PACKED nulldata; | |
6784 | size_t size; | |
6785 | ||
6786 | /* Send data frame to poll STA and check whether this frame is ACKed */ | |
6787 | ||
6788 | os_memset(&nulldata, 0, sizeof(nulldata)); | |
6789 | ||
6790 | if (qos) { | |
6791 | nulldata.hdr.frame_control = | |
6792 | IEEE80211_FC(WLAN_FC_TYPE_DATA, | |
6793 | WLAN_FC_STYPE_QOS_NULL); | |
6794 | size = sizeof(nulldata); | |
6795 | } else { | |
6796 | nulldata.hdr.frame_control = | |
6797 | IEEE80211_FC(WLAN_FC_TYPE_DATA, | |
6798 | WLAN_FC_STYPE_NULLFUNC); | |
6799 | size = sizeof(struct ieee80211_hdr); | |
6800 | } | |
6801 | ||
6802 | nulldata.hdr.frame_control |= host_to_le16(WLAN_FC_FROMDS); | |
6803 | os_memcpy(nulldata.hdr.IEEE80211_DA_FROMDS, addr, ETH_ALEN); | |
6804 | os_memcpy(nulldata.hdr.IEEE80211_BSSID_FROMDS, own_addr, ETH_ALEN); | |
6805 | os_memcpy(nulldata.hdr.IEEE80211_SA_FROMDS, own_addr, ETH_ALEN); | |
6806 | ||
9ebce9c5 JM |
6807 | if (wpa_driver_nl80211_send_mlme(bss, (u8 *) &nulldata, size, 0, 0, 0, |
6808 | 0, 0) < 0) | |
bcf24348 JB |
6809 | wpa_printf(MSG_DEBUG, "nl80211_send_null_frame: Failed to " |
6810 | "send poll frame"); | |
6811 | } | |
6812 | ||
39718852 JB |
6813 | static void nl80211_poll_client(void *priv, const u8 *own_addr, const u8 *addr, |
6814 | int qos) | |
6815 | { | |
6816 | struct i802_bss *bss = priv; | |
6817 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
6818 | struct nl_msg *msg; | |
6819 | ||
6820 | if (!drv->poll_command_supported) { | |
6821 | nl80211_send_null_frame(bss, own_addr, addr, qos); | |
6822 | return; | |
6823 | } | |
6824 | ||
13f83980 | 6825 | if (!(msg = nl80211_bss_msg(bss, 0, NL80211_CMD_PROBE_CLIENT)) || |
a862e4a3 JM |
6826 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) { |
6827 | nlmsg_free(msg); | |
6828 | return; | |
6829 | } | |
39718852 JB |
6830 | |
6831 | send_and_recv_msgs(drv, msg, NULL, NULL); | |
39718852 JB |
6832 | } |
6833 | ||
bcf24348 | 6834 | |
29f338af JM |
6835 | static int nl80211_set_power_save(struct i802_bss *bss, int enabled) |
6836 | { | |
6837 | struct nl_msg *msg; | |
6838 | ||
13f83980 | 6839 | if (!(msg = nl80211_bss_msg(bss, 0, NL80211_CMD_SET_POWER_SAVE)) || |
a862e4a3 JM |
6840 | nla_put_u32(msg, NL80211_ATTR_PS_STATE, |
6841 | enabled ? NL80211_PS_ENABLED : NL80211_PS_DISABLED)) { | |
6842 | nlmsg_free(msg); | |
6843 | return -ENOBUFS; | |
6844 | } | |
29f338af | 6845 | return send_and_recv_msgs(bss->drv, msg, NULL, NULL); |
29f338af JM |
6846 | } |
6847 | ||
6848 | ||
6849 | static int nl80211_set_p2p_powersave(void *priv, int legacy_ps, int opp_ps, | |
6850 | int ctwindow) | |
6851 | { | |
6852 | struct i802_bss *bss = priv; | |
6853 | ||
6854 | wpa_printf(MSG_DEBUG, "nl80211: set_p2p_powersave (legacy_ps=%d " | |
6855 | "opp_ps=%d ctwindow=%d)", legacy_ps, opp_ps, ctwindow); | |
6856 | ||
0de38036 JM |
6857 | if (opp_ps != -1 || ctwindow != -1) { |
6858 | #ifdef ANDROID_P2P | |
6859 | wpa_driver_set_p2p_ps(priv, legacy_ps, opp_ps, ctwindow); | |
6860 | #else /* ANDROID_P2P */ | |
29f338af | 6861 | return -1; /* Not yet supported */ |
0de38036 JM |
6862 | #endif /* ANDROID_P2P */ |
6863 | } | |
29f338af JM |
6864 | |
6865 | if (legacy_ps == -1) | |
6866 | return 0; | |
6867 | if (legacy_ps != 0 && legacy_ps != 1) | |
6868 | return -1; /* Not yet supported */ | |
6869 | ||
6870 | return nl80211_set_power_save(bss, legacy_ps); | |
6871 | } | |
6872 | ||
6873 | ||
04e8003c JD |
6874 | static int nl80211_start_radar_detection(void *priv, |
6875 | struct hostapd_freq_params *freq) | |
f90e9c1c SW |
6876 | { |
6877 | struct i802_bss *bss = priv; | |
6878 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
6879 | struct nl_msg *msg; | |
6880 | int ret; | |
6881 | ||
04e8003c JD |
6882 | 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)", |
6883 | freq->freq, freq->ht_enabled, freq->vht_enabled, | |
6884 | freq->bandwidth, freq->center_freq1, freq->center_freq2); | |
6885 | ||
f90e9c1c SW |
6886 | if (!(drv->capa.flags & WPA_DRIVER_FLAGS_RADAR)) { |
6887 | wpa_printf(MSG_DEBUG, "nl80211: Driver does not support radar " | |
6888 | "detection"); | |
6889 | return -1; | |
6890 | } | |
6891 | ||
9725b784 | 6892 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_RADAR_DETECT)) || |
a862e4a3 JM |
6893 | nl80211_put_freq_params(msg, freq) < 0) { |
6894 | nlmsg_free(msg); | |
6895 | return -1; | |
6896 | } | |
f90e9c1c SW |
6897 | |
6898 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); | |
6899 | if (ret == 0) | |
6900 | return 0; | |
6901 | wpa_printf(MSG_DEBUG, "nl80211: Failed to start radar detection: " | |
6902 | "%d (%s)", ret, strerror(-ret)); | |
f90e9c1c SW |
6903 | return -1; |
6904 | } | |
6905 | ||
03ea1786 AN |
6906 | #ifdef CONFIG_TDLS |
6907 | ||
6908 | static int nl80211_send_tdls_mgmt(void *priv, const u8 *dst, u8 action_code, | |
6909 | u8 dialog_token, u16 status_code, | |
984dadc2 AN |
6910 | u32 peer_capab, int initiator, const u8 *buf, |
6911 | size_t len) | |
03ea1786 AN |
6912 | { |
6913 | struct i802_bss *bss = priv; | |
6914 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
6915 | struct nl_msg *msg; | |
6916 | ||
6917 | if (!(drv->capa.flags & WPA_DRIVER_FLAGS_TDLS_SUPPORT)) | |
6918 | return -EOPNOTSUPP; | |
6919 | ||
6920 | if (!dst) | |
6921 | return -EINVAL; | |
6922 | ||
9725b784 | 6923 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_TDLS_MGMT)) || |
a862e4a3 JM |
6924 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, dst) || |
6925 | nla_put_u8(msg, NL80211_ATTR_TDLS_ACTION, action_code) || | |
6926 | nla_put_u8(msg, NL80211_ATTR_TDLS_DIALOG_TOKEN, dialog_token) || | |
6927 | nla_put_u16(msg, NL80211_ATTR_STATUS_CODE, status_code)) | |
6928 | goto fail; | |
96ecea5e SD |
6929 | if (peer_capab) { |
6930 | /* | |
6931 | * The internal enum tdls_peer_capability definition is | |
6932 | * currently identical with the nl80211 enum | |
6933 | * nl80211_tdls_peer_capability, so no conversion is needed | |
6934 | * here. | |
6935 | */ | |
a862e4a3 JM |
6936 | if (nla_put_u32(msg, NL80211_ATTR_TDLS_PEER_CAPABILITY, |
6937 | peer_capab)) | |
6938 | goto fail; | |
96ecea5e | 6939 | } |
a862e4a3 JM |
6940 | if ((initiator && |
6941 | nla_put_flag(msg, NL80211_ATTR_TDLS_INITIATOR)) || | |
6942 | nla_put(msg, NL80211_ATTR_IE, len, buf)) | |
6943 | goto fail; | |
03ea1786 AN |
6944 | |
6945 | return send_and_recv_msgs(drv, msg, NULL, NULL); | |
6946 | ||
a862e4a3 | 6947 | fail: |
03ea1786 AN |
6948 | nlmsg_free(msg); |
6949 | return -ENOBUFS; | |
6950 | } | |
6951 | ||
6952 | ||
6953 | static int nl80211_tdls_oper(void *priv, enum tdls_oper oper, const u8 *peer) | |
6954 | { | |
6955 | struct i802_bss *bss = priv; | |
6956 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
6957 | struct nl_msg *msg; | |
6958 | enum nl80211_tdls_operation nl80211_oper; | |
6959 | ||
6960 | if (!(drv->capa.flags & WPA_DRIVER_FLAGS_TDLS_SUPPORT)) | |
6961 | return -EOPNOTSUPP; | |
6962 | ||
6963 | switch (oper) { | |
6964 | case TDLS_DISCOVERY_REQ: | |
6965 | nl80211_oper = NL80211_TDLS_DISCOVERY_REQ; | |
6966 | break; | |
6967 | case TDLS_SETUP: | |
6968 | nl80211_oper = NL80211_TDLS_SETUP; | |
6969 | break; | |
6970 | case TDLS_TEARDOWN: | |
6971 | nl80211_oper = NL80211_TDLS_TEARDOWN; | |
6972 | break; | |
6973 | case TDLS_ENABLE_LINK: | |
6974 | nl80211_oper = NL80211_TDLS_ENABLE_LINK; | |
6975 | break; | |
6976 | case TDLS_DISABLE_LINK: | |
6977 | nl80211_oper = NL80211_TDLS_DISABLE_LINK; | |
6978 | break; | |
6979 | case TDLS_ENABLE: | |
6980 | return 0; | |
6981 | case TDLS_DISABLE: | |
6982 | return 0; | |
6983 | default: | |
6984 | return -EINVAL; | |
6985 | } | |
6986 | ||
9725b784 | 6987 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_TDLS_OPER)) || |
a862e4a3 | 6988 | nla_put_u8(msg, NL80211_ATTR_TDLS_OPERATION, nl80211_oper) || |
a862e4a3 JM |
6989 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer)) { |
6990 | nlmsg_free(msg); | |
6991 | return -ENOBUFS; | |
6992 | } | |
03ea1786 AN |
6993 | |
6994 | return send_and_recv_msgs(drv, msg, NULL, NULL); | |
03ea1786 AN |
6995 | } |
6996 | ||
72b2605f AN |
6997 | |
6998 | static int | |
6999 | nl80211_tdls_enable_channel_switch(void *priv, const u8 *addr, u8 oper_class, | |
7000 | const struct hostapd_freq_params *params) | |
7001 | { | |
7002 | struct i802_bss *bss = priv; | |
7003 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
7004 | struct nl_msg *msg; | |
7005 | int ret = -ENOBUFS; | |
7006 | ||
7007 | if (!(drv->capa.flags & WPA_DRIVER_FLAGS_TDLS_SUPPORT) || | |
7008 | !(drv->capa.flags & WPA_DRIVER_FLAGS_TDLS_CHANNEL_SWITCH)) | |
7009 | return -EOPNOTSUPP; | |
7010 | ||
7011 | wpa_printf(MSG_DEBUG, "nl80211: Enable TDLS channel switch " MACSTR | |
7012 | " oper_class=%u freq=%u", | |
7013 | MAC2STR(addr), oper_class, params->freq); | |
7014 | msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_TDLS_CHANNEL_SWITCH); | |
7015 | if (!msg || | |
7016 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) || | |
7017 | nla_put_u8(msg, NL80211_ATTR_OPER_CLASS, oper_class) || | |
7018 | (ret = nl80211_put_freq_params(msg, params))) { | |
7019 | nlmsg_free(msg); | |
7020 | wpa_printf(MSG_DEBUG, "nl80211: Could not build TDLS chan switch"); | |
7021 | return ret; | |
7022 | } | |
7023 | ||
7024 | return send_and_recv_msgs(drv, msg, NULL, NULL); | |
7025 | } | |
7026 | ||
7027 | ||
7028 | static int | |
7029 | nl80211_tdls_disable_channel_switch(void *priv, const u8 *addr) | |
7030 | { | |
7031 | struct i802_bss *bss = priv; | |
7032 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
7033 | struct nl_msg *msg; | |
7034 | ||
7035 | if (!(drv->capa.flags & WPA_DRIVER_FLAGS_TDLS_SUPPORT) || | |
7036 | !(drv->capa.flags & WPA_DRIVER_FLAGS_TDLS_CHANNEL_SWITCH)) | |
7037 | return -EOPNOTSUPP; | |
7038 | ||
7039 | wpa_printf(MSG_DEBUG, "nl80211: Disable TDLS channel switch " MACSTR, | |
7040 | MAC2STR(addr)); | |
7041 | msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_TDLS_CANCEL_CHANNEL_SWITCH); | |
7042 | if (!msg || | |
7043 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) { | |
7044 | nlmsg_free(msg); | |
7045 | wpa_printf(MSG_DEBUG, | |
7046 | "nl80211: Could not build TDLS cancel chan switch"); | |
7047 | return -ENOBUFS; | |
7048 | } | |
7049 | ||
7050 | return send_and_recv_msgs(drv, msg, NULL, NULL); | |
7051 | } | |
7052 | ||
03ea1786 AN |
7053 | #endif /* CONFIG TDLS */ |
7054 | ||
7055 | ||
9ebce9c5 JM |
7056 | static int driver_nl80211_set_key(const char *ifname, void *priv, |
7057 | enum wpa_alg alg, const u8 *addr, | |
7058 | int key_idx, int set_tx, | |
7059 | const u8 *seq, size_t seq_len, | |
7060 | const u8 *key, size_t key_len) | |
7061 | { | |
7062 | struct i802_bss *bss = priv; | |
7063 | return wpa_driver_nl80211_set_key(ifname, bss, alg, addr, key_idx, | |
7064 | set_tx, seq, seq_len, key, key_len); | |
7065 | } | |
7066 | ||
7067 | ||
7068 | static int driver_nl80211_scan2(void *priv, | |
7069 | struct wpa_driver_scan_params *params) | |
7070 | { | |
7071 | struct i802_bss *bss = priv; | |
7072 | return wpa_driver_nl80211_scan(bss, params); | |
7073 | } | |
7074 | ||
7075 | ||
7076 | static int driver_nl80211_deauthenticate(void *priv, const u8 *addr, | |
7077 | int reason_code) | |
7078 | { | |
7079 | struct i802_bss *bss = priv; | |
7080 | return wpa_driver_nl80211_deauthenticate(bss, addr, reason_code); | |
7081 | } | |
7082 | ||
7083 | ||
7084 | static int driver_nl80211_authenticate(void *priv, | |
7085 | struct wpa_driver_auth_params *params) | |
7086 | { | |
7087 | struct i802_bss *bss = priv; | |
7088 | return wpa_driver_nl80211_authenticate(bss, params); | |
7089 | } | |
7090 | ||
7091 | ||
7092 | static void driver_nl80211_deinit(void *priv) | |
7093 | { | |
7094 | struct i802_bss *bss = priv; | |
7095 | wpa_driver_nl80211_deinit(bss); | |
7096 | } | |
7097 | ||
7098 | ||
7099 | static int driver_nl80211_if_remove(void *priv, enum wpa_driver_if_type type, | |
7100 | const char *ifname) | |
7101 | { | |
7102 | struct i802_bss *bss = priv; | |
7103 | return wpa_driver_nl80211_if_remove(bss, type, ifname); | |
7104 | } | |
7105 | ||
7106 | ||
7107 | static int driver_nl80211_send_mlme(void *priv, const u8 *data, | |
7108 | size_t data_len, int noack) | |
7109 | { | |
7110 | struct i802_bss *bss = priv; | |
7111 | return wpa_driver_nl80211_send_mlme(bss, data, data_len, noack, | |
7112 | 0, 0, 0, 0); | |
7113 | } | |
7114 | ||
7115 | ||
7116 | static int driver_nl80211_sta_remove(void *priv, const u8 *addr) | |
7117 | { | |
7118 | struct i802_bss *bss = priv; | |
59d7148a | 7119 | return wpa_driver_nl80211_sta_remove(bss, addr, -1, 0); |
9ebce9c5 JM |
7120 | } |
7121 | ||
7122 | ||
9ebce9c5 JM |
7123 | static int driver_nl80211_set_sta_vlan(void *priv, const u8 *addr, |
7124 | const char *ifname, int vlan_id) | |
7125 | { | |
7126 | struct i802_bss *bss = priv; | |
7127 | return i802_set_sta_vlan(bss, addr, ifname, vlan_id); | |
7128 | } | |
9ebce9c5 JM |
7129 | |
7130 | ||
7131 | static int driver_nl80211_read_sta_data(void *priv, | |
7132 | struct hostap_sta_driver_data *data, | |
7133 | const u8 *addr) | |
7134 | { | |
7135 | struct i802_bss *bss = priv; | |
7136 | return i802_read_sta_data(bss, data, addr); | |
7137 | } | |
7138 | ||
7139 | ||
7140 | static int driver_nl80211_send_action(void *priv, unsigned int freq, | |
7141 | unsigned int wait_time, | |
7142 | const u8 *dst, const u8 *src, | |
7143 | const u8 *bssid, | |
7144 | const u8 *data, size_t data_len, | |
7145 | int no_cck) | |
7146 | { | |
7147 | struct i802_bss *bss = priv; | |
7148 | return wpa_driver_nl80211_send_action(bss, freq, wait_time, dst, src, | |
7149 | bssid, data, data_len, no_cck); | |
7150 | } | |
7151 | ||
7152 | ||
7153 | static int driver_nl80211_probe_req_report(void *priv, int report) | |
7154 | { | |
7155 | struct i802_bss *bss = priv; | |
7156 | return wpa_driver_nl80211_probe_req_report(bss, report); | |
7157 | } | |
7158 | ||
7159 | ||
6a1ce395 DG |
7160 | static int wpa_driver_nl80211_update_ft_ies(void *priv, const u8 *md, |
7161 | const u8 *ies, size_t ies_len) | |
7162 | { | |
7163 | int ret; | |
7164 | struct nl_msg *msg; | |
7165 | struct i802_bss *bss = priv; | |
7166 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
7167 | u16 mdid = WPA_GET_LE16(md); | |
7168 | ||
6a1ce395 | 7169 | wpa_printf(MSG_DEBUG, "nl80211: Updating FT IEs"); |
9725b784 | 7170 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_UPDATE_FT_IES)) || |
a862e4a3 JM |
7171 | nla_put(msg, NL80211_ATTR_IE, ies_len, ies) || |
7172 | nla_put_u16(msg, NL80211_ATTR_MDID, mdid)) { | |
7173 | nlmsg_free(msg); | |
7174 | return -ENOBUFS; | |
7175 | } | |
6a1ce395 DG |
7176 | |
7177 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); | |
7178 | if (ret) { | |
7179 | wpa_printf(MSG_DEBUG, "nl80211: update_ft_ies failed " | |
7180 | "err=%d (%s)", ret, strerror(-ret)); | |
7181 | } | |
7182 | ||
7183 | return ret; | |
6a1ce395 DG |
7184 | } |
7185 | ||
7186 | ||
597b94f5 AS |
7187 | const u8 * wpa_driver_nl80211_get_macaddr(void *priv) |
7188 | { | |
7189 | struct i802_bss *bss = priv; | |
7190 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
7191 | ||
7192 | if (drv->nlmode != NL80211_IFTYPE_P2P_DEVICE) | |
7193 | return NULL; | |
7194 | ||
7195 | return bss->addr; | |
7196 | } | |
7197 | ||
7198 | ||
a771c07d JM |
7199 | static const char * scan_state_str(enum scan_states scan_state) |
7200 | { | |
7201 | switch (scan_state) { | |
7202 | case NO_SCAN: | |
7203 | return "NO_SCAN"; | |
7204 | case SCAN_REQUESTED: | |
7205 | return "SCAN_REQUESTED"; | |
7206 | case SCAN_STARTED: | |
7207 | return "SCAN_STARTED"; | |
7208 | case SCAN_COMPLETED: | |
7209 | return "SCAN_COMPLETED"; | |
7210 | case SCAN_ABORTED: | |
7211 | return "SCAN_ABORTED"; | |
7212 | case SCHED_SCAN_STARTED: | |
7213 | return "SCHED_SCAN_STARTED"; | |
7214 | case SCHED_SCAN_STOPPED: | |
7215 | return "SCHED_SCAN_STOPPED"; | |
7216 | case SCHED_SCAN_RESULTS: | |
7217 | return "SCHED_SCAN_RESULTS"; | |
7218 | } | |
7219 | ||
7220 | return "??"; | |
7221 | } | |
7222 | ||
7223 | ||
7224 | static int wpa_driver_nl80211_status(void *priv, char *buf, size_t buflen) | |
7225 | { | |
7226 | struct i802_bss *bss = priv; | |
7227 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
7228 | int res; | |
7229 | char *pos, *end; | |
7230 | ||
7231 | pos = buf; | |
7232 | end = buf + buflen; | |
7233 | ||
7234 | res = os_snprintf(pos, end - pos, | |
7235 | "ifindex=%d\n" | |
7236 | "ifname=%s\n" | |
7237 | "brname=%s\n" | |
7238 | "addr=" MACSTR "\n" | |
7239 | "freq=%d\n" | |
7240 | "%s%s%s%s%s", | |
7241 | bss->ifindex, | |
7242 | bss->ifname, | |
7243 | bss->brname, | |
7244 | MAC2STR(bss->addr), | |
7245 | bss->freq, | |
7246 | bss->beacon_set ? "beacon_set=1\n" : "", | |
7247 | bss->added_if_into_bridge ? | |
7248 | "added_if_into_bridge=1\n" : "", | |
7249 | bss->added_bridge ? "added_bridge=1\n" : "", | |
7250 | bss->in_deinit ? "in_deinit=1\n" : "", | |
7251 | bss->if_dynamic ? "if_dynamic=1\n" : ""); | |
d85e1fc8 | 7252 | if (os_snprintf_error(end - pos, res)) |
a771c07d JM |
7253 | return pos - buf; |
7254 | pos += res; | |
7255 | ||
7256 | if (bss->wdev_id_set) { | |
7257 | res = os_snprintf(pos, end - pos, "wdev_id=%llu\n", | |
7258 | (unsigned long long) bss->wdev_id); | |
d85e1fc8 | 7259 | if (os_snprintf_error(end - pos, res)) |
a771c07d JM |
7260 | return pos - buf; |
7261 | pos += res; | |
7262 | } | |
7263 | ||
7264 | res = os_snprintf(pos, end - pos, | |
7265 | "phyname=%s\n" | |
fee354c7 | 7266 | "perm_addr=" MACSTR "\n" |
a771c07d JM |
7267 | "drv_ifindex=%d\n" |
7268 | "operstate=%d\n" | |
7269 | "scan_state=%s\n" | |
7270 | "auth_bssid=" MACSTR "\n" | |
7271 | "auth_attempt_bssid=" MACSTR "\n" | |
7272 | "bssid=" MACSTR "\n" | |
7273 | "prev_bssid=" MACSTR "\n" | |
7274 | "associated=%d\n" | |
7275 | "assoc_freq=%u\n" | |
7276 | "monitor_sock=%d\n" | |
7277 | "monitor_ifidx=%d\n" | |
7278 | "monitor_refcount=%d\n" | |
7279 | "last_mgmt_freq=%u\n" | |
7280 | "eapol_tx_sock=%d\n" | |
97752f79 | 7281 | "%s%s%s%s%s%s%s%s%s%s%s%s%s", |
a771c07d | 7282 | drv->phyname, |
fee354c7 | 7283 | MAC2STR(drv->perm_addr), |
a771c07d JM |
7284 | drv->ifindex, |
7285 | drv->operstate, | |
7286 | scan_state_str(drv->scan_state), | |
7287 | MAC2STR(drv->auth_bssid), | |
7288 | MAC2STR(drv->auth_attempt_bssid), | |
7289 | MAC2STR(drv->bssid), | |
7290 | MAC2STR(drv->prev_bssid), | |
7291 | drv->associated, | |
7292 | drv->assoc_freq, | |
7293 | drv->monitor_sock, | |
7294 | drv->monitor_ifidx, | |
7295 | drv->monitor_refcount, | |
7296 | drv->last_mgmt_freq, | |
7297 | drv->eapol_tx_sock, | |
7298 | drv->ignore_if_down_event ? | |
7299 | "ignore_if_down_event=1\n" : "", | |
7300 | drv->scan_complete_events ? | |
7301 | "scan_complete_events=1\n" : "", | |
7302 | drv->disabled_11b_rates ? | |
7303 | "disabled_11b_rates=1\n" : "", | |
7304 | drv->pending_remain_on_chan ? | |
7305 | "pending_remain_on_chan=1\n" : "", | |
7306 | drv->in_interface_list ? "in_interface_list=1\n" : "", | |
7307 | drv->device_ap_sme ? "device_ap_sme=1\n" : "", | |
7308 | drv->poll_command_supported ? | |
7309 | "poll_command_supported=1\n" : "", | |
7310 | drv->data_tx_status ? "data_tx_status=1\n" : "", | |
7311 | drv->scan_for_auth ? "scan_for_auth=1\n" : "", | |
7312 | drv->retry_auth ? "retry_auth=1\n" : "", | |
7313 | drv->use_monitor ? "use_monitor=1\n" : "", | |
7314 | drv->ignore_next_local_disconnect ? | |
7315 | "ignore_next_local_disconnect=1\n" : "", | |
d6a36f39 | 7316 | drv->ignore_next_local_deauth ? |
97752f79 | 7317 | "ignore_next_local_deauth=1\n" : ""); |
d85e1fc8 | 7318 | if (os_snprintf_error(end - pos, res)) |
a771c07d JM |
7319 | return pos - buf; |
7320 | pos += res; | |
7321 | ||
7322 | if (drv->has_capability) { | |
7323 | res = os_snprintf(pos, end - pos, | |
7324 | "capa.key_mgmt=0x%x\n" | |
7325 | "capa.enc=0x%x\n" | |
7326 | "capa.auth=0x%x\n" | |
24bd4e0b | 7327 | "capa.flags=0x%llx\n" |
a0a34d53 | 7328 | "capa.rrm_flags=0x%x\n" |
a771c07d JM |
7329 | "capa.max_scan_ssids=%d\n" |
7330 | "capa.max_sched_scan_ssids=%d\n" | |
7331 | "capa.sched_scan_supported=%d\n" | |
7332 | "capa.max_match_sets=%d\n" | |
7333 | "capa.max_remain_on_chan=%u\n" | |
7334 | "capa.max_stations=%u\n" | |
7335 | "capa.probe_resp_offloads=0x%x\n" | |
7336 | "capa.max_acl_mac_addrs=%u\n" | |
86056fea IP |
7337 | "capa.num_multichan_concurrent=%u\n" |
7338 | "capa.mac_addr_rand_sched_scan_supported=%d\n" | |
7339 | "capa.mac_addr_rand_scan_supported=%d\n", | |
a771c07d JM |
7340 | drv->capa.key_mgmt, |
7341 | drv->capa.enc, | |
7342 | drv->capa.auth, | |
24bd4e0b | 7343 | (unsigned long long) drv->capa.flags, |
a0a34d53 | 7344 | drv->capa.rrm_flags, |
a771c07d JM |
7345 | drv->capa.max_scan_ssids, |
7346 | drv->capa.max_sched_scan_ssids, | |
7347 | drv->capa.sched_scan_supported, | |
7348 | drv->capa.max_match_sets, | |
7349 | drv->capa.max_remain_on_chan, | |
7350 | drv->capa.max_stations, | |
7351 | drv->capa.probe_resp_offloads, | |
7352 | drv->capa.max_acl_mac_addrs, | |
86056fea IP |
7353 | drv->capa.num_multichan_concurrent, |
7354 | drv->capa.mac_addr_rand_sched_scan_supported, | |
7355 | drv->capa.mac_addr_rand_scan_supported); | |
d85e1fc8 | 7356 | if (os_snprintf_error(end - pos, res)) |
a771c07d JM |
7357 | return pos - buf; |
7358 | pos += res; | |
7359 | } | |
7360 | ||
7361 | return pos - buf; | |
7362 | } | |
7363 | ||
7364 | ||
1c4ffa87 AO |
7365 | static int set_beacon_data(struct nl_msg *msg, struct beacon_data *settings) |
7366 | { | |
a862e4a3 JM |
7367 | if ((settings->head && |
7368 | nla_put(msg, NL80211_ATTR_BEACON_HEAD, | |
7369 | settings->head_len, settings->head)) || | |
7370 | (settings->tail && | |
7371 | nla_put(msg, NL80211_ATTR_BEACON_TAIL, | |
7372 | settings->tail_len, settings->tail)) || | |
7373 | (settings->beacon_ies && | |
7374 | nla_put(msg, NL80211_ATTR_IE, | |
7375 | settings->beacon_ies_len, settings->beacon_ies)) || | |
7376 | (settings->proberesp_ies && | |
7377 | nla_put(msg, NL80211_ATTR_IE_PROBE_RESP, | |
7378 | settings->proberesp_ies_len, settings->proberesp_ies)) || | |
7379 | (settings->assocresp_ies && | |
7380 | nla_put(msg, NL80211_ATTR_IE_ASSOC_RESP, | |
7381 | settings->assocresp_ies_len, settings->assocresp_ies)) || | |
7382 | (settings->probe_resp && | |
7383 | nla_put(msg, NL80211_ATTR_PROBE_RESP, | |
7384 | settings->probe_resp_len, settings->probe_resp))) | |
7385 | return -ENOBUFS; | |
1c4ffa87 AO |
7386 | |
7387 | return 0; | |
1c4ffa87 AO |
7388 | } |
7389 | ||
7390 | ||
7391 | static int nl80211_switch_channel(void *priv, struct csa_settings *settings) | |
7392 | { | |
7393 | struct nl_msg *msg; | |
7394 | struct i802_bss *bss = priv; | |
7395 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
7396 | struct nlattr *beacon_csa; | |
7397 | int ret = -ENOBUFS; | |
7398 | ||
8d1fdde7 | 7399 | wpa_printf(MSG_DEBUG, "nl80211: Channel switch request (cs_count=%u block_tx=%u freq=%d width=%d cf1=%d cf2=%d)", |
1c4ffa87 | 7400 | settings->cs_count, settings->block_tx, |
8d1fdde7 JD |
7401 | settings->freq_params.freq, settings->freq_params.bandwidth, |
7402 | settings->freq_params.center_freq1, | |
7403 | settings->freq_params.center_freq2); | |
1c4ffa87 | 7404 | |
991aa9c7 | 7405 | if (!(drv->capa.flags & WPA_DRIVER_FLAGS_AP_CSA)) { |
1c4ffa87 AO |
7406 | wpa_printf(MSG_DEBUG, "nl80211: Driver does not support channel switch command"); |
7407 | return -EOPNOTSUPP; | |
7408 | } | |
7409 | ||
7410 | if ((drv->nlmode != NL80211_IFTYPE_AP) && | |
7411 | (drv->nlmode != NL80211_IFTYPE_P2P_GO)) | |
7412 | return -EOPNOTSUPP; | |
7413 | ||
7414 | /* check settings validity */ | |
7415 | if (!settings->beacon_csa.tail || | |
7416 | ((settings->beacon_csa.tail_len <= | |
7417 | settings->counter_offset_beacon) || | |
7418 | (settings->beacon_csa.tail[settings->counter_offset_beacon] != | |
7419 | settings->cs_count))) | |
7420 | return -EINVAL; | |
7421 | ||
7422 | if (settings->beacon_csa.probe_resp && | |
7423 | ((settings->beacon_csa.probe_resp_len <= | |
7424 | settings->counter_offset_presp) || | |
7425 | (settings->beacon_csa.probe_resp[settings->counter_offset_presp] != | |
7426 | settings->cs_count))) | |
7427 | return -EINVAL; | |
7428 | ||
13f83980 | 7429 | if (!(msg = nl80211_bss_msg(bss, 0, NL80211_CMD_CHANNEL_SWITCH)) || |
a862e4a3 JM |
7430 | nla_put_u32(msg, NL80211_ATTR_CH_SWITCH_COUNT, |
7431 | settings->cs_count) || | |
7432 | (ret = nl80211_put_freq_params(msg, &settings->freq_params)) || | |
7433 | (settings->block_tx && | |
7434 | nla_put_flag(msg, NL80211_ATTR_CH_SWITCH_BLOCK_TX))) | |
1c4ffa87 AO |
7435 | goto error; |
7436 | ||
1c4ffa87 AO |
7437 | /* beacon_after params */ |
7438 | ret = set_beacon_data(msg, &settings->beacon_after); | |
7439 | if (ret) | |
7440 | goto error; | |
7441 | ||
7442 | /* beacon_csa params */ | |
7443 | beacon_csa = nla_nest_start(msg, NL80211_ATTR_CSA_IES); | |
7444 | if (!beacon_csa) | |
a862e4a3 | 7445 | goto fail; |
1c4ffa87 AO |
7446 | |
7447 | ret = set_beacon_data(msg, &settings->beacon_csa); | |
7448 | if (ret) | |
7449 | goto error; | |
7450 | ||
a862e4a3 JM |
7451 | if (nla_put_u16(msg, NL80211_ATTR_CSA_C_OFF_BEACON, |
7452 | settings->counter_offset_beacon) || | |
7453 | (settings->beacon_csa.probe_resp && | |
7454 | nla_put_u16(msg, NL80211_ATTR_CSA_C_OFF_PRESP, | |
7455 | settings->counter_offset_presp))) | |
7456 | goto fail; | |
1c4ffa87 AO |
7457 | |
7458 | nla_nest_end(msg, beacon_csa); | |
7459 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); | |
7460 | if (ret) { | |
7461 | wpa_printf(MSG_DEBUG, "nl80211: switch_channel failed err=%d (%s)", | |
7462 | ret, strerror(-ret)); | |
7463 | } | |
7464 | return ret; | |
7465 | ||
a862e4a3 | 7466 | fail: |
1c4ffa87 AO |
7467 | ret = -ENOBUFS; |
7468 | error: | |
7469 | nlmsg_free(msg); | |
7470 | wpa_printf(MSG_DEBUG, "nl80211: Could not build channel switch request"); | |
7471 | return ret; | |
7472 | } | |
7473 | ||
7474 | ||
dfa87878 MB |
7475 | static int nl80211_add_ts(void *priv, u8 tsid, const u8 *addr, |
7476 | u8 user_priority, u16 admitted_time) | |
7477 | { | |
7478 | struct i802_bss *bss = priv; | |
7479 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
7480 | struct nl_msg *msg; | |
7481 | int ret; | |
7482 | ||
7483 | wpa_printf(MSG_DEBUG, | |
7484 | "nl80211: add_ts request: tsid=%u admitted_time=%u up=%d", | |
7485 | tsid, admitted_time, user_priority); | |
7486 | ||
7487 | if (!is_sta_interface(drv->nlmode)) | |
7488 | return -ENOTSUP; | |
7489 | ||
56f77852 JM |
7490 | msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_ADD_TX_TS); |
7491 | if (!msg || | |
a862e4a3 JM |
7492 | nla_put_u8(msg, NL80211_ATTR_TSID, tsid) || |
7493 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) || | |
7494 | nla_put_u8(msg, NL80211_ATTR_USER_PRIO, user_priority) || | |
7495 | nla_put_u16(msg, NL80211_ATTR_ADMITTED_TIME, admitted_time)) { | |
7496 | nlmsg_free(msg); | |
7497 | return -ENOBUFS; | |
7498 | } | |
dfa87878 MB |
7499 | |
7500 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); | |
7501 | if (ret) | |
7502 | wpa_printf(MSG_DEBUG, "nl80211: add_ts failed err=%d (%s)", | |
7503 | ret, strerror(-ret)); | |
7504 | return ret; | |
dfa87878 MB |
7505 | } |
7506 | ||
7507 | ||
7508 | static int nl80211_del_ts(void *priv, u8 tsid, const u8 *addr) | |
7509 | { | |
7510 | struct i802_bss *bss = priv; | |
7511 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
7512 | struct nl_msg *msg; | |
7513 | int ret; | |
7514 | ||
7515 | wpa_printf(MSG_DEBUG, "nl80211: del_ts request: tsid=%u", tsid); | |
7516 | ||
7517 | if (!is_sta_interface(drv->nlmode)) | |
7518 | return -ENOTSUP; | |
7519 | ||
56f77852 | 7520 | if (!(msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_DEL_TX_TS)) || |
a862e4a3 JM |
7521 | nla_put_u8(msg, NL80211_ATTR_TSID, tsid) || |
7522 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) { | |
7523 | nlmsg_free(msg); | |
7524 | return -ENOBUFS; | |
7525 | } | |
dfa87878 MB |
7526 | |
7527 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); | |
7528 | if (ret) | |
7529 | wpa_printf(MSG_DEBUG, "nl80211: del_ts failed err=%d (%s)", | |
7530 | ret, strerror(-ret)); | |
7531 | return ret; | |
dfa87878 MB |
7532 | } |
7533 | ||
7534 | ||
6b9f7af6 JM |
7535 | #ifdef CONFIG_TESTING_OPTIONS |
7536 | static int cmd_reply_handler(struct nl_msg *msg, void *arg) | |
7537 | { | |
7538 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); | |
7539 | struct wpabuf *buf = arg; | |
7540 | ||
7541 | if (!buf) | |
7542 | return NL_SKIP; | |
7543 | ||
7544 | if ((size_t) genlmsg_attrlen(gnlh, 0) > wpabuf_tailroom(buf)) { | |
7545 | wpa_printf(MSG_INFO, "nl80211: insufficient buffer space for reply"); | |
7546 | return NL_SKIP; | |
7547 | } | |
7548 | ||
7549 | wpabuf_put_data(buf, genlmsg_attrdata(gnlh, 0), | |
7550 | genlmsg_attrlen(gnlh, 0)); | |
7551 | ||
7552 | return NL_SKIP; | |
7553 | } | |
7554 | #endif /* CONFIG_TESTING_OPTIONS */ | |
7555 | ||
7556 | ||
adef8948 BL |
7557 | static int vendor_reply_handler(struct nl_msg *msg, void *arg) |
7558 | { | |
7559 | struct nlattr *tb[NL80211_ATTR_MAX + 1]; | |
7560 | struct nlattr *nl_vendor_reply, *nl; | |
7561 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); | |
7562 | struct wpabuf *buf = arg; | |
7563 | int rem; | |
7564 | ||
7565 | if (!buf) | |
7566 | return NL_SKIP; | |
7567 | ||
7568 | nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), | |
7569 | genlmsg_attrlen(gnlh, 0), NULL); | |
7570 | nl_vendor_reply = tb[NL80211_ATTR_VENDOR_DATA]; | |
7571 | ||
7572 | if (!nl_vendor_reply) | |
7573 | return NL_SKIP; | |
7574 | ||
7575 | if ((size_t) nla_len(nl_vendor_reply) > wpabuf_tailroom(buf)) { | |
7576 | wpa_printf(MSG_INFO, "nl80211: Vendor command: insufficient buffer space for reply"); | |
7577 | return NL_SKIP; | |
7578 | } | |
7579 | ||
7580 | nla_for_each_nested(nl, nl_vendor_reply, rem) { | |
7581 | wpabuf_put_data(buf, nla_data(nl), nla_len(nl)); | |
7582 | } | |
7583 | ||
7584 | return NL_SKIP; | |
7585 | } | |
7586 | ||
7587 | ||
7588 | static int nl80211_vendor_cmd(void *priv, unsigned int vendor_id, | |
7589 | unsigned int subcmd, const u8 *data, | |
7590 | size_t data_len, struct wpabuf *buf) | |
7591 | { | |
7592 | struct i802_bss *bss = priv; | |
7593 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
7594 | struct nl_msg *msg; | |
7595 | int ret; | |
7596 | ||
6b9f7af6 JM |
7597 | #ifdef CONFIG_TESTING_OPTIONS |
7598 | if (vendor_id == 0xffffffff) { | |
56f77852 JM |
7599 | msg = nlmsg_alloc(); |
7600 | if (!msg) | |
7601 | return -ENOMEM; | |
7602 | ||
6b9f7af6 JM |
7603 | nl80211_cmd(drv, msg, 0, subcmd); |
7604 | if (nlmsg_append(msg, (void *) data, data_len, NLMSG_ALIGNTO) < | |
7605 | 0) | |
a862e4a3 | 7606 | goto fail; |
6b9f7af6 JM |
7607 | ret = send_and_recv_msgs(drv, msg, cmd_reply_handler, buf); |
7608 | if (ret) | |
7609 | wpa_printf(MSG_DEBUG, "nl80211: command failed err=%d", | |
7610 | ret); | |
7611 | return ret; | |
7612 | } | |
7613 | #endif /* CONFIG_TESTING_OPTIONS */ | |
7614 | ||
56f77852 | 7615 | if (!(msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_VENDOR)) || |
a862e4a3 JM |
7616 | nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, vendor_id) || |
7617 | nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD, subcmd) || | |
7618 | (data && | |
7619 | nla_put(msg, NL80211_ATTR_VENDOR_DATA, data_len, data))) | |
7620 | goto fail; | |
adef8948 BL |
7621 | |
7622 | ret = send_and_recv_msgs(drv, msg, vendor_reply_handler, buf); | |
7623 | if (ret) | |
7624 | wpa_printf(MSG_DEBUG, "nl80211: vendor command failed err=%d", | |
7625 | ret); | |
7626 | return ret; | |
7627 | ||
a862e4a3 | 7628 | fail: |
adef8948 BL |
7629 | nlmsg_free(msg); |
7630 | return -ENOBUFS; | |
7631 | } | |
7632 | ||
7633 | ||
049105b4 KP |
7634 | static int nl80211_set_qos_map(void *priv, const u8 *qos_map_set, |
7635 | u8 qos_map_set_len) | |
7636 | { | |
7637 | struct i802_bss *bss = priv; | |
7638 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
7639 | struct nl_msg *msg; | |
7640 | int ret; | |
7641 | ||
049105b4 KP |
7642 | wpa_hexdump(MSG_DEBUG, "nl80211: Setting QoS Map", |
7643 | qos_map_set, qos_map_set_len); | |
7644 | ||
9725b784 | 7645 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_SET_QOS_MAP)) || |
a862e4a3 JM |
7646 | nla_put(msg, NL80211_ATTR_QOS_MAP, qos_map_set_len, qos_map_set)) { |
7647 | nlmsg_free(msg); | |
7648 | return -ENOBUFS; | |
7649 | } | |
049105b4 KP |
7650 | |
7651 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); | |
7652 | if (ret) | |
7653 | wpa_printf(MSG_DEBUG, "nl80211: Setting QoS Map failed"); | |
7654 | ||
7655 | return ret; | |
049105b4 KP |
7656 | } |
7657 | ||
7658 | ||
e4fa8b12 EP |
7659 | static int nl80211_set_wowlan(void *priv, |
7660 | const struct wowlan_triggers *triggers) | |
7661 | { | |
7662 | struct i802_bss *bss = priv; | |
7663 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
7664 | struct nl_msg *msg; | |
7665 | struct nlattr *wowlan_triggers; | |
7666 | int ret; | |
7667 | ||
e4fa8b12 EP |
7668 | wpa_printf(MSG_DEBUG, "nl80211: Setting wowlan"); |
7669 | ||
9725b784 | 7670 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_SET_WOWLAN)) || |
a862e4a3 JM |
7671 | !(wowlan_triggers = nla_nest_start(msg, |
7672 | NL80211_ATTR_WOWLAN_TRIGGERS)) || | |
7673 | (triggers->any && | |
7674 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_ANY)) || | |
7675 | (triggers->disconnect && | |
7676 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) || | |
7677 | (triggers->magic_pkt && | |
7678 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) || | |
7679 | (triggers->gtk_rekey_failure && | |
7680 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) || | |
7681 | (triggers->eap_identity_req && | |
7682 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) || | |
7683 | (triggers->four_way_handshake && | |
7684 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) || | |
7685 | (triggers->rfkill_release && | |
7686 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE))) { | |
7687 | nlmsg_free(msg); | |
7688 | return -ENOBUFS; | |
7689 | } | |
e4fa8b12 EP |
7690 | |
7691 | nla_nest_end(msg, wowlan_triggers); | |
7692 | ||
7693 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); | |
7694 | if (ret) | |
7695 | wpa_printf(MSG_DEBUG, "nl80211: Setting wowlan failed"); | |
7696 | ||
7697 | return ret; | |
e4fa8b12 EP |
7698 | } |
7699 | ||
7700 | ||
0800f9ee JM |
7701 | static int nl80211_roaming(void *priv, int allowed, const u8 *bssid) |
7702 | { | |
7703 | struct i802_bss *bss = priv; | |
7704 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
7705 | struct nl_msg *msg; | |
7706 | struct nlattr *params; | |
7707 | ||
7708 | wpa_printf(MSG_DEBUG, "nl80211: Roaming policy: allowed=%d", allowed); | |
7709 | ||
7710 | if (!drv->roaming_vendor_cmd_avail) { | |
7711 | wpa_printf(MSG_DEBUG, | |
7712 | "nl80211: Ignore roaming policy change since driver does not provide command for setting it"); | |
7713 | return -1; | |
7714 | } | |
7715 | ||
9725b784 | 7716 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_VENDOR)) || |
a862e4a3 JM |
7717 | nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) || |
7718 | nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD, | |
7719 | QCA_NL80211_VENDOR_SUBCMD_ROAMING) || | |
7720 | !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) || | |
7721 | nla_put_u32(msg, QCA_WLAN_VENDOR_ATTR_ROAMING_POLICY, | |
7722 | allowed ? QCA_ROAMING_ALLOWED_WITHIN_ESS : | |
7723 | QCA_ROAMING_NOT_ALLOWED) || | |
7724 | (bssid && | |
7725 | nla_put(msg, QCA_WLAN_VENDOR_ATTR_MAC_ADDR, ETH_ALEN, bssid))) { | |
7726 | nlmsg_free(msg); | |
7727 | return -1; | |
7728 | } | |
0800f9ee JM |
7729 | nla_nest_end(msg, params); |
7730 | ||
7731 | return send_and_recv_msgs(drv, msg, NULL, NULL); | |
0800f9ee JM |
7732 | } |
7733 | ||
7734 | ||
fee354c7 JM |
7735 | static int nl80211_set_mac_addr(void *priv, const u8 *addr) |
7736 | { | |
7737 | struct i802_bss *bss = priv; | |
7738 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
7739 | int new_addr = addr != NULL; | |
7740 | ||
7741 | if (!addr) | |
7742 | addr = drv->perm_addr; | |
7743 | ||
7744 | if (linux_set_iface_flags(drv->global->ioctl_sock, bss->ifname, 0) < 0) | |
7745 | return -1; | |
7746 | ||
7747 | if (linux_set_ifhwaddr(drv->global->ioctl_sock, bss->ifname, addr) < 0) | |
7748 | { | |
7749 | wpa_printf(MSG_DEBUG, | |
7750 | "nl80211: failed to set_mac_addr for %s to " MACSTR, | |
7751 | bss->ifname, MAC2STR(addr)); | |
7752 | if (linux_set_iface_flags(drv->global->ioctl_sock, bss->ifname, | |
7753 | 1) < 0) { | |
7754 | wpa_printf(MSG_DEBUG, | |
7755 | "nl80211: Could not restore interface UP after failed set_mac_addr"); | |
7756 | } | |
7757 | return -1; | |
7758 | } | |
7759 | ||
7760 | wpa_printf(MSG_DEBUG, "nl80211: set_mac_addr for %s to " MACSTR, | |
7761 | bss->ifname, MAC2STR(addr)); | |
7762 | drv->addr_changed = new_addr; | |
7763 | os_memcpy(bss->addr, addr, ETH_ALEN); | |
7764 | ||
7765 | if (linux_set_iface_flags(drv->global->ioctl_sock, bss->ifname, 1) < 0) | |
7766 | { | |
7767 | wpa_printf(MSG_DEBUG, | |
7768 | "nl80211: Could not restore interface UP after set_mac_addr"); | |
7769 | } | |
7770 | ||
7771 | return 0; | |
7772 | } | |
7773 | ||
7774 | ||
6c1664f6 BC |
7775 | #ifdef CONFIG_MESH |
7776 | ||
7777 | static int wpa_driver_nl80211_init_mesh(void *priv) | |
7778 | { | |
7779 | if (wpa_driver_nl80211_set_mode(priv, NL80211_IFTYPE_MESH_POINT)) { | |
7780 | wpa_printf(MSG_INFO, | |
7781 | "nl80211: Failed to set interface into mesh mode"); | |
7782 | return -1; | |
7783 | } | |
7784 | return 0; | |
7785 | } | |
7786 | ||
7787 | ||
7788 | static int | |
7789 | wpa_driver_nl80211_join_mesh(void *priv, | |
7790 | struct wpa_driver_mesh_join_params *params) | |
7791 | { | |
7792 | struct i802_bss *bss = priv; | |
7793 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
7794 | struct nl_msg *msg; | |
7795 | struct nlattr *container; | |
7796 | int ret = 0; | |
7797 | ||
6c1664f6 | 7798 | wpa_printf(MSG_DEBUG, "nl80211: mesh join (ifindex=%d)", drv->ifindex); |
9725b784 JM |
7799 | msg = nl80211_drv_msg(drv, 0, NL80211_CMD_JOIN_MESH); |
7800 | if (!msg) | |
a862e4a3 | 7801 | goto fail; |
6c1664f6 BC |
7802 | if (params->freq) { |
7803 | wpa_printf(MSG_DEBUG, " * freq=%d", params->freq); | |
a862e4a3 JM |
7804 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, params->freq)) |
7805 | goto fail; | |
6c1664f6 BC |
7806 | } |
7807 | ||
5cfb672d JM |
7808 | if (params->ht_mode) { |
7809 | unsigned int ht_value; | |
7810 | char *ht_mode = ""; | |
7811 | ||
7812 | switch (params->ht_mode) { | |
7813 | default: | |
7814 | case CHAN_NO_HT: | |
7815 | ht_value = NL80211_CHAN_NO_HT; | |
7816 | ht_mode = "NOHT"; | |
7817 | break; | |
7818 | case CHAN_HT20: | |
7819 | ht_value = NL80211_CHAN_HT20; | |
7820 | ht_mode = "HT20"; | |
7821 | break; | |
7822 | case CHAN_HT40PLUS: | |
7823 | ht_value = NL80211_CHAN_HT40PLUS; | |
7824 | ht_mode = "HT40+"; | |
7825 | break; | |
7826 | case CHAN_HT40MINUS: | |
7827 | ht_value = NL80211_CHAN_HT40MINUS; | |
7828 | ht_mode = "HT40-"; | |
7829 | break; | |
7830 | } | |
7831 | wpa_printf(MSG_DEBUG, " * ht_mode=%s", ht_mode); | |
a862e4a3 JM |
7832 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE, ht_value)) |
7833 | goto fail; | |
5cfb672d JM |
7834 | } |
7835 | ||
6c1664f6 BC |
7836 | if (params->basic_rates) { |
7837 | u8 rates[NL80211_MAX_SUPP_RATES]; | |
7838 | u8 rates_len = 0; | |
7839 | int i; | |
7840 | ||
7841 | for (i = 0; i < NL80211_MAX_SUPP_RATES; i++) { | |
7842 | if (params->basic_rates[i] < 0) | |
7843 | break; | |
7844 | rates[rates_len++] = params->basic_rates[i] / 5; | |
7845 | } | |
7846 | ||
a862e4a3 JM |
7847 | if (nla_put(msg, NL80211_ATTR_BSS_BASIC_RATES, rates_len, |
7848 | rates)) | |
7849 | goto fail; | |
6c1664f6 BC |
7850 | } |
7851 | ||
7852 | if (params->meshid) { | |
7853 | wpa_hexdump_ascii(MSG_DEBUG, " * SSID", | |
7854 | params->meshid, params->meshid_len); | |
a862e4a3 JM |
7855 | if (nla_put(msg, NL80211_ATTR_MESH_ID, params->meshid_len, |
7856 | params->meshid)) | |
7857 | goto fail; | |
6c1664f6 BC |
7858 | } |
7859 | ||
9c58c5f7 MH |
7860 | if (params->beacon_int > 0) { |
7861 | wpa_printf(MSG_DEBUG, " * beacon_int=%d", params->beacon_int); | |
7862 | if (nla_put_u32(msg, NL80211_ATTR_BEACON_INTERVAL, | |
7863 | params->beacon_int)) | |
7864 | goto fail; | |
7865 | } | |
7866 | ||
6c1664f6 BC |
7867 | wpa_printf(MSG_DEBUG, " * flags=%08X", params->flags); |
7868 | ||
7869 | container = nla_nest_start(msg, NL80211_ATTR_MESH_SETUP); | |
7870 | if (!container) | |
a862e4a3 | 7871 | goto fail; |
6c1664f6 BC |
7872 | |
7873 | if (params->ies) { | |
7874 | wpa_hexdump(MSG_DEBUG, " * IEs", params->ies, params->ie_len); | |
a862e4a3 JM |
7875 | if (nla_put(msg, NL80211_MESH_SETUP_IE, params->ie_len, |
7876 | params->ies)) | |
7877 | goto fail; | |
6c1664f6 BC |
7878 | } |
7879 | /* WPA_DRIVER_MESH_FLAG_OPEN_AUTH is treated as default by nl80211 */ | |
7880 | if (params->flags & WPA_DRIVER_MESH_FLAG_SAE_AUTH) { | |
a862e4a3 JM |
7881 | if (nla_put_u8(msg, NL80211_MESH_SETUP_AUTH_PROTOCOL, 0x1) || |
7882 | nla_put_flag(msg, NL80211_MESH_SETUP_USERSPACE_AUTH)) | |
7883 | goto fail; | |
6c1664f6 | 7884 | } |
a862e4a3 JM |
7885 | if ((params->flags & WPA_DRIVER_MESH_FLAG_AMPE) && |
7886 | nla_put_flag(msg, NL80211_MESH_SETUP_USERSPACE_AMPE)) | |
7887 | goto fail; | |
7888 | if ((params->flags & WPA_DRIVER_MESH_FLAG_USER_MPM) && | |
7889 | nla_put_flag(msg, NL80211_MESH_SETUP_USERSPACE_MPM)) | |
7890 | goto fail; | |
6c1664f6 BC |
7891 | nla_nest_end(msg, container); |
7892 | ||
7893 | container = nla_nest_start(msg, NL80211_ATTR_MESH_CONFIG); | |
7894 | if (!container) | |
a862e4a3 | 7895 | goto fail; |
6c1664f6 | 7896 | |
a862e4a3 JM |
7897 | if (!(params->conf.flags & WPA_DRIVER_MESH_CONF_FLAG_AUTO_PLINKS) && |
7898 | nla_put_u32(msg, NL80211_MESHCONF_AUTO_OPEN_PLINKS, 0)) | |
7899 | goto fail; | |
4b409368 MH |
7900 | if ((params->conf.flags & WPA_DRIVER_MESH_FLAG_DRIVER_MPM) && |
7901 | nla_put_u16(msg, NL80211_MESHCONF_MAX_PEER_LINKS, | |
7902 | params->max_peer_links)) | |
7903 | goto fail; | |
6c1664f6 BC |
7904 | nla_nest_end(msg, container); |
7905 | ||
7906 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); | |
7907 | msg = NULL; | |
7908 | if (ret) { | |
7909 | wpa_printf(MSG_DEBUG, "nl80211: mesh join failed: ret=%d (%s)", | |
7910 | ret, strerror(-ret)); | |
a862e4a3 | 7911 | goto fail; |
6c1664f6 BC |
7912 | } |
7913 | ret = 0; | |
7914 | bss->freq = params->freq; | |
7915 | wpa_printf(MSG_DEBUG, "nl80211: mesh join request send successfully"); | |
7916 | ||
a862e4a3 | 7917 | fail: |
6c1664f6 BC |
7918 | nlmsg_free(msg); |
7919 | return ret; | |
7920 | } | |
7921 | ||
7922 | ||
7923 | static int wpa_driver_nl80211_leave_mesh(void *priv) | |
7924 | { | |
7925 | struct i802_bss *bss = priv; | |
7926 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
7927 | struct nl_msg *msg; | |
9725b784 | 7928 | int ret; |
6c1664f6 BC |
7929 | |
7930 | wpa_printf(MSG_DEBUG, "nl80211: mesh leave (ifindex=%d)", drv->ifindex); | |
9725b784 | 7931 | msg = nl80211_drv_msg(drv, 0, NL80211_CMD_LEAVE_MESH); |
6c1664f6 | 7932 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
6c1664f6 BC |
7933 | if (ret) { |
7934 | wpa_printf(MSG_DEBUG, "nl80211: mesh leave failed: ret=%d (%s)", | |
7935 | ret, strerror(-ret)); | |
a862e4a3 JM |
7936 | } else { |
7937 | wpa_printf(MSG_DEBUG, | |
7938 | "nl80211: mesh leave request send successfully"); | |
6c1664f6 | 7939 | } |
6c1664f6 | 7940 | |
f33c82d2 JM |
7941 | if (wpa_driver_nl80211_set_mode(drv->first_bss, |
7942 | NL80211_IFTYPE_STATION)) { | |
7943 | wpa_printf(MSG_INFO, | |
7944 | "nl80211: Failed to set interface into station mode"); | |
7945 | } | |
6c1664f6 BC |
7946 | return ret; |
7947 | } | |
7948 | ||
7949 | #endif /* CONFIG_MESH */ | |
7950 | ||
7951 | ||
ed4ddb6d KP |
7952 | static int wpa_driver_br_add_ip_neigh(void *priv, u8 version, |
7953 | const u8 *ipaddr, int prefixlen, | |
7954 | const u8 *addr) | |
71103bed KP |
7955 | { |
7956 | #ifdef CONFIG_LIBNL3_ROUTE | |
7957 | struct i802_bss *bss = priv; | |
7958 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
7959 | struct rtnl_neigh *rn; | |
7960 | struct nl_addr *nl_ipaddr = NULL; | |
7961 | struct nl_addr *nl_lladdr = NULL; | |
ed4ddb6d | 7962 | int family, addrsize; |
71103bed KP |
7963 | int res; |
7964 | ||
ed4ddb6d | 7965 | if (!ipaddr || prefixlen == 0 || !addr) |
71103bed KP |
7966 | return -EINVAL; |
7967 | ||
7968 | if (bss->br_ifindex == 0) { | |
7969 | wpa_printf(MSG_DEBUG, | |
7970 | "nl80211: bridge must be set before adding an ip neigh to it"); | |
7971 | return -1; | |
7972 | } | |
7973 | ||
7974 | if (!drv->rtnl_sk) { | |
7975 | wpa_printf(MSG_DEBUG, | |
7976 | "nl80211: nl_sock for NETLINK_ROUTE is not initialized"); | |
7977 | return -1; | |
7978 | } | |
7979 | ||
ed4ddb6d KP |
7980 | if (version == 4) { |
7981 | family = AF_INET; | |
7982 | addrsize = 4; | |
7983 | } else if (version == 6) { | |
7984 | family = AF_INET6; | |
7985 | addrsize = 16; | |
7986 | } else { | |
7987 | return -EINVAL; | |
7988 | } | |
7989 | ||
71103bed KP |
7990 | rn = rtnl_neigh_alloc(); |
7991 | if (rn == NULL) | |
7992 | return -ENOMEM; | |
7993 | ||
7994 | /* set the destination ip address for neigh */ | |
ed4ddb6d | 7995 | nl_ipaddr = nl_addr_build(family, (void *) ipaddr, addrsize); |
71103bed KP |
7996 | if (nl_ipaddr == NULL) { |
7997 | wpa_printf(MSG_DEBUG, "nl80211: nl_ipaddr build failed"); | |
7998 | res = -ENOMEM; | |
7999 | goto errout; | |
8000 | } | |
8001 | nl_addr_set_prefixlen(nl_ipaddr, prefixlen); | |
8002 | res = rtnl_neigh_set_dst(rn, nl_ipaddr); | |
8003 | if (res) { | |
8004 | wpa_printf(MSG_DEBUG, | |
8005 | "nl80211: neigh set destination addr failed"); | |
8006 | goto errout; | |
8007 | } | |
8008 | ||
8009 | /* set the corresponding lladdr for neigh */ | |
8010 | nl_lladdr = nl_addr_build(AF_BRIDGE, (u8 *) addr, ETH_ALEN); | |
8011 | if (nl_lladdr == NULL) { | |
8012 | wpa_printf(MSG_DEBUG, "nl80211: neigh set lladdr failed"); | |
8013 | res = -ENOMEM; | |
8014 | goto errout; | |
8015 | } | |
8016 | rtnl_neigh_set_lladdr(rn, nl_lladdr); | |
8017 | ||
8018 | rtnl_neigh_set_ifindex(rn, bss->br_ifindex); | |
8019 | rtnl_neigh_set_state(rn, NUD_PERMANENT); | |
8020 | ||
8021 | res = rtnl_neigh_add(drv->rtnl_sk, rn, NLM_F_CREATE); | |
8022 | if (res) { | |
8023 | wpa_printf(MSG_DEBUG, | |
8024 | "nl80211: Adding bridge ip neigh failed: %s", | |
8025 | strerror(errno)); | |
8026 | } | |
8027 | errout: | |
8028 | if (nl_lladdr) | |
8029 | nl_addr_put(nl_lladdr); | |
8030 | if (nl_ipaddr) | |
8031 | nl_addr_put(nl_ipaddr); | |
8032 | if (rn) | |
8033 | rtnl_neigh_put(rn); | |
8034 | return res; | |
8035 | #else /* CONFIG_LIBNL3_ROUTE */ | |
8036 | return -1; | |
8037 | #endif /* CONFIG_LIBNL3_ROUTE */ | |
8038 | } | |
8039 | ||
8040 | ||
ed4ddb6d KP |
8041 | static int wpa_driver_br_delete_ip_neigh(void *priv, u8 version, |
8042 | const u8 *ipaddr) | |
71103bed KP |
8043 | { |
8044 | #ifdef CONFIG_LIBNL3_ROUTE | |
8045 | struct i802_bss *bss = priv; | |
8046 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
8047 | struct rtnl_neigh *rn; | |
8048 | struct nl_addr *nl_ipaddr; | |
ed4ddb6d | 8049 | int family, addrsize; |
71103bed KP |
8050 | int res; |
8051 | ||
ed4ddb6d | 8052 | if (!ipaddr) |
71103bed KP |
8053 | return -EINVAL; |
8054 | ||
ed4ddb6d KP |
8055 | if (version == 4) { |
8056 | family = AF_INET; | |
8057 | addrsize = 4; | |
8058 | } else if (version == 6) { | |
8059 | family = AF_INET6; | |
8060 | addrsize = 16; | |
8061 | } else { | |
8062 | return -EINVAL; | |
8063 | } | |
8064 | ||
71103bed KP |
8065 | if (bss->br_ifindex == 0) { |
8066 | wpa_printf(MSG_DEBUG, | |
8067 | "nl80211: bridge must be set to delete an ip neigh"); | |
8068 | return -1; | |
8069 | } | |
8070 | ||
8071 | if (!drv->rtnl_sk) { | |
8072 | wpa_printf(MSG_DEBUG, | |
8073 | "nl80211: nl_sock for NETLINK_ROUTE is not initialized"); | |
8074 | return -1; | |
8075 | } | |
8076 | ||
8077 | rn = rtnl_neigh_alloc(); | |
8078 | if (rn == NULL) | |
8079 | return -ENOMEM; | |
8080 | ||
8081 | /* set the destination ip address for neigh */ | |
ed4ddb6d | 8082 | nl_ipaddr = nl_addr_build(family, (void *) ipaddr, addrsize); |
71103bed KP |
8083 | if (nl_ipaddr == NULL) { |
8084 | wpa_printf(MSG_DEBUG, "nl80211: nl_ipaddr build failed"); | |
8085 | res = -ENOMEM; | |
8086 | goto errout; | |
8087 | } | |
8088 | res = rtnl_neigh_set_dst(rn, nl_ipaddr); | |
8089 | if (res) { | |
8090 | wpa_printf(MSG_DEBUG, | |
8091 | "nl80211: neigh set destination addr failed"); | |
8092 | goto errout; | |
8093 | } | |
8094 | ||
8095 | rtnl_neigh_set_ifindex(rn, bss->br_ifindex); | |
8096 | ||
8097 | res = rtnl_neigh_delete(drv->rtnl_sk, rn, 0); | |
8098 | if (res) { | |
8099 | wpa_printf(MSG_DEBUG, | |
8100 | "nl80211: Deleting bridge ip neigh failed: %s", | |
8101 | strerror(errno)); | |
8102 | } | |
8103 | errout: | |
8104 | if (nl_ipaddr) | |
8105 | nl_addr_put(nl_ipaddr); | |
8106 | if (rn) | |
8107 | rtnl_neigh_put(rn); | |
8108 | return res; | |
8109 | #else /* CONFIG_LIBNL3_ROUTE */ | |
8110 | return -1; | |
8111 | #endif /* CONFIG_LIBNL3_ROUTE */ | |
8112 | } | |
8113 | ||
8114 | ||
73d2294f KP |
8115 | static int linux_write_system_file(const char *path, unsigned int val) |
8116 | { | |
8117 | char buf[50]; | |
8118 | int fd, len; | |
8119 | ||
8120 | len = os_snprintf(buf, sizeof(buf), "%u\n", val); | |
a9aaacbb | 8121 | if (os_snprintf_error(sizeof(buf), len)) |
73d2294f KP |
8122 | return -1; |
8123 | ||
8124 | fd = open(path, O_WRONLY); | |
8125 | if (fd < 0) | |
8126 | return -1; | |
8127 | ||
8128 | if (write(fd, buf, len) < 0) { | |
8129 | wpa_printf(MSG_DEBUG, | |
8130 | "nl80211: Failed to write Linux system file: %s with the value of %d", | |
8131 | path, val); | |
8132 | close(fd); | |
8133 | return -1; | |
8134 | } | |
8135 | close(fd); | |
8136 | ||
8137 | return 0; | |
8138 | } | |
8139 | ||
8140 | ||
8141 | static const char * drv_br_port_attr_str(enum drv_br_port_attr attr) | |
8142 | { | |
8143 | switch (attr) { | |
8144 | case DRV_BR_PORT_ATTR_PROXYARP: | |
8145 | return "proxyarp"; | |
8146 | case DRV_BR_PORT_ATTR_HAIRPIN_MODE: | |
8147 | return "hairpin_mode"; | |
8148 | } | |
8149 | ||
8150 | return NULL; | |
8151 | } | |
8152 | ||
8153 | ||
8154 | static int wpa_driver_br_port_set_attr(void *priv, enum drv_br_port_attr attr, | |
8155 | unsigned int val) | |
8156 | { | |
8157 | struct i802_bss *bss = priv; | |
8158 | char path[128]; | |
8159 | const char *attr_txt; | |
8160 | ||
8161 | attr_txt = drv_br_port_attr_str(attr); | |
8162 | if (attr_txt == NULL) | |
8163 | return -EINVAL; | |
8164 | ||
8165 | os_snprintf(path, sizeof(path), "/sys/class/net/%s/brport/%s", | |
8166 | bss->ifname, attr_txt); | |
8167 | ||
8168 | if (linux_write_system_file(path, val)) | |
8169 | return -1; | |
8170 | ||
8171 | return 0; | |
8172 | } | |
8173 | ||
8174 | ||
7565752d KP |
8175 | static const char * drv_br_net_param_str(enum drv_br_net_param param) |
8176 | { | |
8177 | switch (param) { | |
8178 | case DRV_BR_NET_PARAM_GARP_ACCEPT: | |
8179 | return "arp_accept"; | |
8180 | } | |
8181 | ||
8182 | return NULL; | |
8183 | } | |
8184 | ||
8185 | ||
8186 | static int wpa_driver_br_set_net_param(void *priv, enum drv_br_net_param param, | |
8187 | unsigned int val) | |
8188 | { | |
8189 | struct i802_bss *bss = priv; | |
8190 | char path[128]; | |
8191 | const char *param_txt; | |
8192 | int ip_version = 4; | |
8193 | ||
8194 | param_txt = drv_br_net_param_str(param); | |
8195 | if (param_txt == NULL) | |
8196 | return -EINVAL; | |
8197 | ||
8198 | switch (param) { | |
8199 | case DRV_BR_NET_PARAM_GARP_ACCEPT: | |
8200 | ip_version = 4; | |
8201 | break; | |
8202 | default: | |
8203 | return -EINVAL; | |
8204 | } | |
8205 | ||
8206 | os_snprintf(path, sizeof(path), "/proc/sys/net/ipv%d/conf/%s/%s", | |
8207 | ip_version, bss->brname, param_txt); | |
8208 | ||
8209 | if (linux_write_system_file(path, val)) | |
8210 | return -1; | |
8211 | ||
8212 | return 0; | |
8213 | } | |
8214 | ||
8215 | ||
16689c7c PX |
8216 | static int hw_mode_to_qca_acs(enum hostapd_hw_mode hw_mode) |
8217 | { | |
8218 | switch (hw_mode) { | |
8219 | case HOSTAPD_MODE_IEEE80211B: | |
8220 | return QCA_ACS_MODE_IEEE80211B; | |
8221 | case HOSTAPD_MODE_IEEE80211G: | |
8222 | return QCA_ACS_MODE_IEEE80211G; | |
8223 | case HOSTAPD_MODE_IEEE80211A: | |
8224 | return QCA_ACS_MODE_IEEE80211A; | |
8225 | case HOSTAPD_MODE_IEEE80211AD: | |
8226 | return QCA_ACS_MODE_IEEE80211AD; | |
8227 | default: | |
8228 | return -1; | |
8229 | } | |
8230 | } | |
8231 | ||
8232 | ||
8233 | static int wpa_driver_do_acs(void *priv, struct drv_acs_params *params) | |
8234 | { | |
8235 | struct i802_bss *bss = priv; | |
8236 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
8237 | struct nl_msg *msg; | |
8238 | struct nlattr *data; | |
a862e4a3 | 8239 | int ret; |
16689c7c PX |
8240 | int mode; |
8241 | ||
8242 | mode = hw_mode_to_qca_acs(params->hw_mode); | |
8243 | if (mode < 0) | |
8244 | return -1; | |
8245 | ||
9725b784 | 8246 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_VENDOR)) || |
a862e4a3 JM |
8247 | nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) || |
8248 | nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD, | |
8249 | QCA_NL80211_VENDOR_SUBCMD_DO_ACS) || | |
8250 | !(data = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) || | |
8251 | nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_ACS_HW_MODE, mode) || | |
8252 | (params->ht_enabled && | |
8253 | nla_put_flag(msg, QCA_WLAN_VENDOR_ATTR_ACS_HT_ENABLED)) || | |
8254 | (params->ht40_enabled && | |
8255 | nla_put_flag(msg, QCA_WLAN_VENDOR_ATTR_ACS_HT40_ENABLED))) { | |
8256 | nlmsg_free(msg); | |
8257 | return -ENOBUFS; | |
8258 | } | |
16689c7c PX |
8259 | nla_nest_end(msg, data); |
8260 | ||
8261 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); | |
16689c7c PX |
8262 | if (ret) { |
8263 | wpa_printf(MSG_DEBUG, | |
8264 | "nl80211: Failed to invoke driver ACS function: %s", | |
8265 | strerror(errno)); | |
8266 | } | |
16689c7c PX |
8267 | return ret; |
8268 | } | |
8269 | ||
8270 | ||
3f5285e8 JM |
8271 | const struct wpa_driver_ops wpa_driver_nl80211_ops = { |
8272 | .name = "nl80211", | |
8273 | .desc = "Linux nl80211/cfg80211", | |
8274 | .get_bssid = wpa_driver_nl80211_get_bssid, | |
8275 | .get_ssid = wpa_driver_nl80211_get_ssid, | |
9ebce9c5 JM |
8276 | .set_key = driver_nl80211_set_key, |
8277 | .scan2 = driver_nl80211_scan2, | |
d21c63b9 LC |
8278 | .sched_scan = wpa_driver_nl80211_sched_scan, |
8279 | .stop_sched_scan = wpa_driver_nl80211_stop_sched_scan, | |
3f5285e8 | 8280 | .get_scan_results2 = wpa_driver_nl80211_get_scan_results, |
9ebce9c5 JM |
8281 | .deauthenticate = driver_nl80211_deauthenticate, |
8282 | .authenticate = driver_nl80211_authenticate, | |
3f5285e8 | 8283 | .associate = wpa_driver_nl80211_associate, |
f2ed8023 JM |
8284 | .global_init = nl80211_global_init, |
8285 | .global_deinit = nl80211_global_deinit, | |
8286 | .init2 = wpa_driver_nl80211_init, | |
9ebce9c5 | 8287 | .deinit = driver_nl80211_deinit, |
3f5285e8 JM |
8288 | .get_capa = wpa_driver_nl80211_get_capa, |
8289 | .set_operstate = wpa_driver_nl80211_set_operstate, | |
01652550 | 8290 | .set_supp_port = wpa_driver_nl80211_set_supp_port, |
6d158490 | 8291 | .set_country = wpa_driver_nl80211_set_country, |
f0793bf1 | 8292 | .get_country = wpa_driver_nl80211_get_country, |
19c3b566 | 8293 | .set_ap = wpa_driver_nl80211_set_ap, |
3c4ca363 | 8294 | .set_acl = wpa_driver_nl80211_set_acl, |
22a7c9d7 | 8295 | .if_add = wpa_driver_nl80211_if_add, |
9ebce9c5 JM |
8296 | .if_remove = driver_nl80211_if_remove, |
8297 | .send_mlme = driver_nl80211_send_mlme, | |
0fafeb54 | 8298 | .get_hw_feature_data = nl80211_get_hw_feature_data, |
0f4e8b4f | 8299 | .sta_add = wpa_driver_nl80211_sta_add, |
9ebce9c5 | 8300 | .sta_remove = driver_nl80211_sta_remove, |
db149ac9 | 8301 | .hapd_send_eapol = wpa_driver_nl80211_hapd_send_eapol, |
a8d6ffa4 | 8302 | .sta_set_flags = wpa_driver_nl80211_sta_set_flags, |
c5121837 | 8303 | .hapd_init = i802_init, |
c5121837 | 8304 | .hapd_deinit = i802_deinit, |
f7b3920c | 8305 | .set_wds_sta = i802_set_wds_sta, |
c5121837 JM |
8306 | .get_seqnum = i802_get_seqnum, |
8307 | .flush = i802_flush, | |
c5121837 JM |
8308 | .get_inact_sec = i802_get_inact_sec, |
8309 | .sta_clear_stats = i802_sta_clear_stats, | |
c5121837 JM |
8310 | .set_rts = i802_set_rts, |
8311 | .set_frag = i802_set_frag, | |
c5121837 | 8312 | .set_tx_queue_params = i802_set_tx_queue_params, |
9ebce9c5 | 8313 | .set_sta_vlan = driver_nl80211_set_sta_vlan, |
ee7ab173 JB |
8314 | .sta_deauth = i802_sta_deauth, |
8315 | .sta_disassoc = i802_sta_disassoc, | |
9ebce9c5 | 8316 | .read_sta_data = driver_nl80211_read_sta_data, |
e3802622 | 8317 | .set_freq = i802_set_freq, |
9ebce9c5 | 8318 | .send_action = driver_nl80211_send_action, |
5dfca53f | 8319 | .send_action_cancel_wait = wpa_driver_nl80211_send_action_cancel_wait, |
55777702 JM |
8320 | .remain_on_channel = wpa_driver_nl80211_remain_on_channel, |
8321 | .cancel_remain_on_channel = | |
8322 | wpa_driver_nl80211_cancel_remain_on_channel, | |
9ebce9c5 | 8323 | .probe_req_report = driver_nl80211_probe_req_report, |
af473088 | 8324 | .deinit_ap = wpa_driver_nl80211_deinit_ap, |
3c29244e | 8325 | .deinit_p2p_cli = wpa_driver_nl80211_deinit_p2p_cli, |
207ef3fb | 8326 | .resume = wpa_driver_nl80211_resume, |
b625473c | 8327 | .signal_monitor = nl80211_signal_monitor, |
1c5c7273 | 8328 | .signal_poll = nl80211_signal_poll, |
b91ab76e | 8329 | .send_frame = nl80211_send_frame, |
57ebba59 | 8330 | .shared_freq = wpa_driver_nl80211_shared_freq, |
c55f774d | 8331 | .set_param = nl80211_set_param, |
6859f1cb | 8332 | .get_radio_name = nl80211_get_radio_name, |
a6efc65d JM |
8333 | .add_pmkid = nl80211_add_pmkid, |
8334 | .remove_pmkid = nl80211_remove_pmkid, | |
8335 | .flush_pmkid = nl80211_flush_pmkid, | |
b14a210c | 8336 | .set_rekey_info = nl80211_set_rekey_info, |
bcf24348 | 8337 | .poll_client = nl80211_poll_client, |
29f338af | 8338 | .set_p2p_powersave = nl80211_set_p2p_powersave, |
f90e9c1c | 8339 | .start_dfs_cac = nl80211_start_radar_detection, |
695c7038 | 8340 | .stop_ap = wpa_driver_nl80211_stop_ap, |
03ea1786 AN |
8341 | #ifdef CONFIG_TDLS |
8342 | .send_tdls_mgmt = nl80211_send_tdls_mgmt, | |
8343 | .tdls_oper = nl80211_tdls_oper, | |
72b2605f AN |
8344 | .tdls_enable_channel_switch = nl80211_tdls_enable_channel_switch, |
8345 | .tdls_disable_channel_switch = nl80211_tdls_disable_channel_switch, | |
03ea1786 | 8346 | #endif /* CONFIG_TDLS */ |
6a1ce395 | 8347 | .update_ft_ies = wpa_driver_nl80211_update_ft_ies, |
597b94f5 | 8348 | .get_mac_addr = wpa_driver_nl80211_get_macaddr, |
0185007c | 8349 | .get_survey = wpa_driver_nl80211_get_survey, |
a771c07d | 8350 | .status = wpa_driver_nl80211_status, |
1c4ffa87 | 8351 | .switch_channel = nl80211_switch_channel, |
0de38036 JM |
8352 | #ifdef ANDROID_P2P |
8353 | .set_noa = wpa_driver_set_p2p_noa, | |
8354 | .get_noa = wpa_driver_get_p2p_noa, | |
8355 | .set_ap_wps_ie = wpa_driver_set_ap_wps_p2p_ie, | |
8356 | #endif /* ANDROID_P2P */ | |
5e2c3490 JM |
8357 | #ifdef ANDROID |
8358 | .driver_cmd = wpa_driver_nl80211_driver_cmd, | |
8359 | #endif /* ANDROID */ | |
adef8948 | 8360 | .vendor_cmd = nl80211_vendor_cmd, |
049105b4 | 8361 | .set_qos_map = nl80211_set_qos_map, |
e4fa8b12 | 8362 | .set_wowlan = nl80211_set_wowlan, |
0800f9ee | 8363 | .roaming = nl80211_roaming, |
fee354c7 | 8364 | .set_mac_addr = nl80211_set_mac_addr, |
6c1664f6 BC |
8365 | #ifdef CONFIG_MESH |
8366 | .init_mesh = wpa_driver_nl80211_init_mesh, | |
8367 | .join_mesh = wpa_driver_nl80211_join_mesh, | |
8368 | .leave_mesh = wpa_driver_nl80211_leave_mesh, | |
8369 | #endif /* CONFIG_MESH */ | |
71103bed KP |
8370 | .br_add_ip_neigh = wpa_driver_br_add_ip_neigh, |
8371 | .br_delete_ip_neigh = wpa_driver_br_delete_ip_neigh, | |
73d2294f | 8372 | .br_port_set_attr = wpa_driver_br_port_set_attr, |
7565752d | 8373 | .br_set_net_param = wpa_driver_br_set_net_param, |
dfa87878 MB |
8374 | .add_tx_ts = nl80211_add_ts, |
8375 | .del_tx_ts = nl80211_del_ts, | |
16689c7c | 8376 | .do_acs = wpa_driver_do_acs, |
3f5285e8 | 8377 | }; |