]>
Commit | Line | Data |
---|---|---|
3f5285e8 | 1 | /* |
c5121837 | 2 | * Driver interaction with Linux nl80211/cfg80211 |
98cd3d1c | 3 | * Copyright (c) 2002-2015, 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" |
3aa24db9 | 32 | #include "common/wpa_common.h" |
f10bfc9a | 33 | #include "l2_packet/l2_packet.h" |
e2d02c29 | 34 | #include "netlink.h" |
1474e6e9 | 35 | #include "linux_defines.h" |
34f2f814 | 36 | #include "linux_ioctl.h" |
e2d02c29 JM |
37 | #include "radiotap.h" |
38 | #include "radiotap_iter.h" | |
8401a6b0 | 39 | #include "rfkill.h" |
1474e6e9 | 40 | #include "driver_nl80211.h" |
32ab4855 | 41 | |
1474e6e9 JM |
42 | |
43 | #ifndef CONFIG_LIBNL20 | |
a65a9aed JB |
44 | /* |
45 | * libnl 1.1 has a bug, it tries to allocate socket numbers densely | |
46 | * but when you free a socket again it will mess up its bitmap and | |
47 | * and use the wrong number the next time it needs a socket ID. | |
48 | * Therefore, we wrap the handle alloc/destroy and add our own pid | |
49 | * accounting. | |
50 | */ | |
51 | static uint32_t port_bitmap[32] = { 0 }; | |
52 | ||
53 | static struct nl_handle *nl80211_handle_alloc(void *cb) | |
54 | { | |
55 | struct nl_handle *handle; | |
56 | uint32_t pid = getpid() & 0x3FFFFF; | |
57 | int i; | |
58 | ||
59 | handle = nl_handle_alloc_cb(cb); | |
60 | ||
61 | for (i = 0; i < 1024; i++) { | |
62 | if (port_bitmap[i / 32] & (1 << (i % 32))) | |
63 | continue; | |
64 | port_bitmap[i / 32] |= 1 << (i % 32); | |
65 | pid += i << 22; | |
66 | break; | |
67 | } | |
68 | ||
69 | nl_socket_set_local_port(handle, pid); | |
70 | ||
71 | return handle; | |
72 | } | |
73 | ||
74 | static void nl80211_handle_destroy(struct nl_handle *handle) | |
75 | { | |
76 | uint32_t port = nl_socket_get_local_port(handle); | |
77 | ||
78 | port >>= 22; | |
79 | port_bitmap[port / 32] &= ~(1 << (port % 32)); | |
80 | ||
81 | nl_handle_destroy(handle); | |
82 | } | |
c5121837 JM |
83 | #endif /* CONFIG_LIBNL20 */ |
84 | ||
c5121837 | 85 | |
1c6edec6 JM |
86 | #ifdef ANDROID |
87 | /* system/core/libnl_2 does not include nl_socket_set_nonblocking() */ | |
1c6edec6 JM |
88 | #undef nl_socket_set_nonblocking |
89 | #define nl_socket_set_nonblocking(h) android_nl_socket_set_nonblocking(h) | |
70a96c81 | 90 | |
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, | |
40a68f33 | 133 | void *eloop_data, int persist) |
5f65e9f7 | 134 | { |
fa38860c | 135 | #ifdef CONFIG_LIBNL20 |
630b3230 JM |
136 | /* |
137 | * libnl uses a pretty small buffer (32 kB that gets converted to 64 kB) | |
138 | * by default. It is possible to hit that limit in some cases where | |
139 | * operations are blocked, e.g., with a burst of Deauthentication frames | |
140 | * to hostapd and STA entry deletion. Try to increase the buffer to make | |
141 | * this less likely to occur. | |
142 | */ | |
143 | if (nl_socket_set_buffer_size(*handle, 262144, 0) < 0) { | |
144 | wpa_printf(MSG_DEBUG, | |
145 | "nl80211: Could not set nl_socket RX buffer size: %s", | |
146 | strerror(errno)); | |
147 | /* continue anyway with the default (smaller) buffer */ | |
148 | } | |
fa38860c | 149 | #endif /* CONFIG_LIBNL20 */ |
630b3230 | 150 | |
10b85921 | 151 | nl_socket_set_nonblocking(*handle); |
5f65e9f7 JB |
152 | eloop_register_read_sock(nl_socket_get_fd(*handle), handler, |
153 | eloop_data, *handle); | |
40a68f33 SD |
154 | if (!persist) |
155 | *handle = (void *) (((intptr_t) *handle) ^ | |
156 | ELOOP_SOCKET_INVALID); | |
5f65e9f7 JB |
157 | } |
158 | ||
159 | ||
40a68f33 | 160 | static void nl80211_destroy_eloop_handle(struct nl_handle **handle, int persist) |
5f65e9f7 | 161 | { |
40a68f33 SD |
162 | if (!persist) |
163 | *handle = (void *) (((intptr_t) *handle) ^ | |
164 | ELOOP_SOCKET_INVALID); | |
5f65e9f7 JB |
165 | eloop_unregister_read_sock(nl_socket_get_fd(*handle)); |
166 | nl_destroy_handles(handle); | |
167 | } | |
168 | ||
169 | ||
36d84860 | 170 | static void nl80211_global_deinit(void *priv); |
f51f54a0 | 171 | static void nl80211_check_global(struct nl80211_global *global); |
36d84860 | 172 | |
9ebce9c5 | 173 | static void wpa_driver_nl80211_deinit(struct i802_bss *bss); |
4ec68377 JD |
174 | static int wpa_driver_nl80211_set_mode_ibss(struct i802_bss *bss, |
175 | struct hostapd_freq_params *freq); | |
3c5d34e3 | 176 | |
362f781e | 177 | static int |
0d547d5f | 178 | wpa_driver_nl80211_finish_drv_init(struct wpa_driver_nl80211_data *drv, |
0ecff8d7 JM |
179 | const u8 *set_addr, int first, |
180 | const char *driver_params); | |
88df0ef7 | 181 | static int nl80211_send_frame_cmd(struct i802_bss *bss, |
5dfca53f | 182 | unsigned int freq, unsigned int wait, |
b106173a | 183 | const u8 *buf, size_t buf_len, u64 *cookie, |
2d3943ce AO |
184 | int no_cck, int no_ack, int offchanok, |
185 | const u16 *csa_offs, size_t csa_offs_len); | |
9ebce9c5 JM |
186 | static int wpa_driver_nl80211_probe_req_report(struct i802_bss *bss, |
187 | int report); | |
0915d02c | 188 | |
732b1d20 MB |
189 | #define IFIDX_ANY -1 |
190 | ||
191 | static void add_ifidx(struct wpa_driver_nl80211_data *drv, int ifidx, | |
192 | int ifidx_reason); | |
193 | static void del_ifidx(struct wpa_driver_nl80211_data *drv, int ifidx, | |
194 | int ifidx_reason); | |
195 | static int have_ifidx(struct wpa_driver_nl80211_data *drv, int ifidx, | |
196 | int ifidx_reason); | |
072ad14c | 197 | |
e87ef751 PX |
198 | static int nl80211_set_channel(struct i802_bss *bss, |
199 | struct hostapd_freq_params *freq, int set_chan); | |
4e5cb1a3 JM |
200 | static int nl80211_disable_11b_rates(struct wpa_driver_nl80211_data *drv, |
201 | int ifindex, int disabled); | |
504e905c | 202 | |
666e508c JM |
203 | static int nl80211_leave_ibss(struct wpa_driver_nl80211_data *drv, |
204 | int reset_mode); | |
21bdbe38 | 205 | |
bf83eab5 | 206 | static int i802_set_iface_flags(struct i802_bss *bss, int up); |
0ecff8d7 | 207 | static int nl80211_set_param(void *priv, const char *param); |
052b8d38 MH |
208 | #ifdef CONFIG_MESH |
209 | static int nl80211_put_mesh_config(struct nl_msg *msg, | |
210 | struct wpa_driver_mesh_bss_params *params); | |
211 | #endif /* CONFIG_MESH */ | |
05e5e615 DL |
212 | static int i802_sta_disassoc(void *priv, const u8 *own_addr, const u8 *addr, |
213 | int reason); | |
bf83eab5 | 214 | |
3f5285e8 | 215 | |
8d1fdde7 | 216 | /* Converts nl80211_chan_width to a common format */ |
f3407c66 | 217 | enum chan_width convert2width(int width) |
8d1fdde7 JD |
218 | { |
219 | switch (width) { | |
220 | case NL80211_CHAN_WIDTH_20_NOHT: | |
221 | return CHAN_WIDTH_20_NOHT; | |
222 | case NL80211_CHAN_WIDTH_20: | |
223 | return CHAN_WIDTH_20; | |
224 | case NL80211_CHAN_WIDTH_40: | |
225 | return CHAN_WIDTH_40; | |
226 | case NL80211_CHAN_WIDTH_80: | |
227 | return CHAN_WIDTH_80; | |
228 | case NL80211_CHAN_WIDTH_80P80: | |
229 | return CHAN_WIDTH_80P80; | |
230 | case NL80211_CHAN_WIDTH_160: | |
231 | return CHAN_WIDTH_160; | |
232 | } | |
233 | return CHAN_WIDTH_UNKNOWN; | |
234 | } | |
235 | ||
236 | ||
f3407c66 | 237 | int is_ap_interface(enum nl80211_iftype nlmode) |
b1f625e0 | 238 | { |
0e80ea2c JM |
239 | return nlmode == NL80211_IFTYPE_AP || |
240 | nlmode == NL80211_IFTYPE_P2P_GO; | |
b1f625e0 EP |
241 | } |
242 | ||
243 | ||
477af8f8 | 244 | int is_sta_interface(enum nl80211_iftype nlmode) |
b1f625e0 | 245 | { |
0e80ea2c JM |
246 | return nlmode == NL80211_IFTYPE_STATION || |
247 | nlmode == NL80211_IFTYPE_P2P_CLIENT; | |
b1f625e0 EP |
248 | } |
249 | ||
250 | ||
6a71413e | 251 | static int is_p2p_net_interface(enum nl80211_iftype nlmode) |
b3af99d2 | 252 | { |
0e80ea2c JM |
253 | return nlmode == NL80211_IFTYPE_P2P_CLIENT || |
254 | nlmode == NL80211_IFTYPE_P2P_GO; | |
b3af99d2 JM |
255 | } |
256 | ||
257 | ||
f3407c66 JM |
258 | struct i802_bss * get_bss_ifindex(struct wpa_driver_nl80211_data *drv, |
259 | int ifindex) | |
5dfbd725 JM |
260 | { |
261 | struct i802_bss *bss; | |
262 | ||
263 | for (bss = drv->first_bss; bss; bss = bss->next) { | |
264 | if (bss->ifindex == ifindex) | |
265 | return bss; | |
266 | } | |
267 | ||
268 | return NULL; | |
269 | } | |
270 | ||
271 | ||
afb0550a BC |
272 | static int is_mesh_interface(enum nl80211_iftype nlmode) |
273 | { | |
274 | return nlmode == NL80211_IFTYPE_MESH_POINT; | |
275 | } | |
276 | ||
277 | ||
f3407c66 | 278 | void nl80211_mark_disconnected(struct wpa_driver_nl80211_data *drv) |
add9b7a4 JM |
279 | { |
280 | if (drv->associated) | |
281 | os_memcpy(drv->prev_bssid, drv->bssid, ETH_ALEN); | |
282 | drv->associated = 0; | |
283 | os_memset(drv->bssid, 0, ETH_ALEN); | |
284 | } | |
285 | ||
286 | ||
6241fcb1 JM |
287 | /* nl80211 code */ |
288 | static int ack_handler(struct nl_msg *msg, void *arg) | |
289 | { | |
290 | int *err = arg; | |
291 | *err = 0; | |
292 | return NL_STOP; | |
293 | } | |
294 | ||
295 | static int finish_handler(struct nl_msg *msg, void *arg) | |
296 | { | |
8e8df255 JM |
297 | int *ret = arg; |
298 | *ret = 0; | |
6241fcb1 JM |
299 | return NL_SKIP; |
300 | } | |
301 | ||
302 | static int error_handler(struct sockaddr_nl *nla, struct nlmsgerr *err, | |
303 | void *arg) | |
304 | { | |
305 | int *ret = arg; | |
306 | *ret = err->error; | |
307 | return NL_SKIP; | |
308 | } | |
309 | ||
5b7b85f6 JM |
310 | |
311 | static int no_seq_check(struct nl_msg *msg, void *arg) | |
312 | { | |
313 | return NL_OK; | |
314 | } | |
315 | ||
316 | ||
bbd89bfc JM |
317 | static void nl80211_nlmsg_clear(struct nl_msg *msg) |
318 | { | |
319 | /* | |
320 | * Clear nlmsg data, e.g., to make sure key material is not left in | |
321 | * heap memory for unnecessarily long time. | |
322 | */ | |
323 | if (msg) { | |
324 | struct nlmsghdr *hdr = nlmsg_hdr(msg); | |
325 | void *data = nlmsg_data(hdr); | |
d58ade21 JM |
326 | /* |
327 | * This would use nlmsg_datalen() or the older nlmsg_len() if | |
328 | * only libnl were to maintain a stable API.. Neither will work | |
329 | * with all released versions, so just calculate the length | |
330 | * here. | |
331 | */ | |
332 | int len = hdr->nlmsg_len - NLMSG_HDRLEN; | |
bbd89bfc JM |
333 | |
334 | os_memset(data, 0, len); | |
335 | } | |
336 | } | |
337 | ||
338 | ||
d6c9aab8 | 339 | static int send_and_recv(struct nl80211_global *global, |
58f6fbe0 JM |
340 | struct nl_handle *nl_handle, struct nl_msg *msg, |
341 | int (*valid_handler)(struct nl_msg *, void *), | |
342 | void *valid_data) | |
6241fcb1 JM |
343 | { |
344 | struct nl_cb *cb; | |
345 | int err = -ENOMEM; | |
346 | ||
9725b784 JM |
347 | if (!msg) |
348 | return -ENOMEM; | |
349 | ||
d6c9aab8 | 350 | cb = nl_cb_clone(global->nl_cb); |
6241fcb1 JM |
351 | if (!cb) |
352 | goto out; | |
353 | ||
58f6fbe0 | 354 | err = nl_send_auto_complete(nl_handle, msg); |
6241fcb1 JM |
355 | if (err < 0) |
356 | goto out; | |
357 | ||
358 | err = 1; | |
359 | ||
360 | nl_cb_err(cb, NL_CB_CUSTOM, error_handler, &err); | |
8e8df255 | 361 | nl_cb_set(cb, NL_CB_FINISH, NL_CB_CUSTOM, finish_handler, &err); |
6241fcb1 JM |
362 | nl_cb_set(cb, NL_CB_ACK, NL_CB_CUSTOM, ack_handler, &err); |
363 | ||
364 | if (valid_handler) | |
365 | nl_cb_set(cb, NL_CB_VALID, NL_CB_CUSTOM, | |
366 | valid_handler, valid_data); | |
367 | ||
34068ac3 JM |
368 | while (err > 0) { |
369 | int res = nl_recvmsgs(nl_handle, cb); | |
d3d04831 | 370 | if (res < 0) { |
34068ac3 JM |
371 | wpa_printf(MSG_INFO, |
372 | "nl80211: %s->nl_recvmsgs failed: %d", | |
373 | __func__, res); | |
374 | } | |
375 | } | |
6241fcb1 JM |
376 | out: |
377 | nl_cb_put(cb); | |
bbd89bfc JM |
378 | if (!valid_handler && valid_data == (void *) -1) |
379 | nl80211_nlmsg_clear(msg); | |
6241fcb1 JM |
380 | nlmsg_free(msg); |
381 | return err; | |
382 | } | |
383 | ||
384 | ||
f3407c66 JM |
385 | int send_and_recv_msgs(struct wpa_driver_nl80211_data *drv, |
386 | struct nl_msg *msg, | |
387 | int (*valid_handler)(struct nl_msg *, void *), | |
388 | void *valid_data) | |
58f6fbe0 | 389 | { |
481234cf | 390 | return send_and_recv(drv->global, drv->global->nl, msg, |
d6c9aab8 | 391 | valid_handler, valid_data); |
58f6fbe0 JM |
392 | } |
393 | ||
394 | ||
97865538 JM |
395 | struct family_data { |
396 | const char *group; | |
397 | int id; | |
398 | }; | |
399 | ||
400 | ||
401 | static int family_handler(struct nl_msg *msg, void *arg) | |
402 | { | |
403 | struct family_data *res = arg; | |
404 | struct nlattr *tb[CTRL_ATTR_MAX + 1]; | |
405 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); | |
406 | struct nlattr *mcgrp; | |
407 | int i; | |
408 | ||
409 | nla_parse(tb, CTRL_ATTR_MAX, genlmsg_attrdata(gnlh, 0), | |
410 | genlmsg_attrlen(gnlh, 0), NULL); | |
411 | if (!tb[CTRL_ATTR_MCAST_GROUPS]) | |
412 | return NL_SKIP; | |
413 | ||
414 | nla_for_each_nested(mcgrp, tb[CTRL_ATTR_MCAST_GROUPS], i) { | |
415 | struct nlattr *tb2[CTRL_ATTR_MCAST_GRP_MAX + 1]; | |
416 | nla_parse(tb2, CTRL_ATTR_MCAST_GRP_MAX, nla_data(mcgrp), | |
417 | nla_len(mcgrp), NULL); | |
418 | if (!tb2[CTRL_ATTR_MCAST_GRP_NAME] || | |
419 | !tb2[CTRL_ATTR_MCAST_GRP_ID] || | |
420 | os_strncmp(nla_data(tb2[CTRL_ATTR_MCAST_GRP_NAME]), | |
421 | res->group, | |
422 | nla_len(tb2[CTRL_ATTR_MCAST_GRP_NAME])) != 0) | |
423 | continue; | |
424 | res->id = nla_get_u32(tb2[CTRL_ATTR_MCAST_GRP_ID]); | |
425 | break; | |
426 | }; | |
427 | ||
428 | return NL_SKIP; | |
429 | } | |
430 | ||
431 | ||
d6c9aab8 | 432 | static int nl_get_multicast_id(struct nl80211_global *global, |
97865538 JM |
433 | const char *family, const char *group) |
434 | { | |
435 | struct nl_msg *msg; | |
a862e4a3 | 436 | int ret; |
97865538 JM |
437 | struct family_data res = { group, -ENOENT }; |
438 | ||
439 | msg = nlmsg_alloc(); | |
440 | if (!msg) | |
441 | return -ENOMEM; | |
a862e4a3 JM |
442 | if (!genlmsg_put(msg, 0, 0, genl_ctrl_resolve(global->nl, "nlctrl"), |
443 | 0, 0, CTRL_CMD_GETFAMILY, 0) || | |
444 | nla_put_string(msg, CTRL_ATTR_FAMILY_NAME, family)) { | |
445 | nlmsg_free(msg); | |
446 | return -1; | |
447 | } | |
97865538 | 448 | |
1033315f | 449 | ret = send_and_recv(global, global->nl, msg, family_handler, &res); |
97865538 JM |
450 | if (ret == 0) |
451 | ret = res.id; | |
97865538 JM |
452 | return ret; |
453 | } | |
454 | ||
455 | ||
f3407c66 JM |
456 | void * nl80211_cmd(struct wpa_driver_nl80211_data *drv, |
457 | struct nl_msg *msg, int flags, uint8_t cmd) | |
9fb04070 | 458 | { |
a5a187b0 JM |
459 | if (TEST_FAIL()) |
460 | return NULL; | |
335d42b1 | 461 | return genlmsg_put(msg, 0, 0, drv->global->nl80211_id, |
276e2d67 | 462 | 0, flags, cmd, 0); |
9fb04070 JM |
463 | } |
464 | ||
465 | ||
350acc35 JM |
466 | static int nl80211_set_iface_id(struct nl_msg *msg, struct i802_bss *bss) |
467 | { | |
468 | if (bss->wdev_id_set) | |
469 | return nla_put_u64(msg, NL80211_ATTR_WDEV, bss->wdev_id); | |
470 | return nla_put_u32(msg, NL80211_ATTR_IFINDEX, bss->ifindex); | |
471 | } | |
472 | ||
473 | ||
07c7757c JM |
474 | struct nl_msg * nl80211_cmd_msg(struct i802_bss *bss, int flags, uint8_t cmd) |
475 | { | |
476 | struct nl_msg *msg; | |
477 | ||
478 | msg = nlmsg_alloc(); | |
479 | if (!msg) | |
480 | return NULL; | |
481 | ||
482 | if (!nl80211_cmd(bss->drv, msg, flags, cmd) || | |
483 | nl80211_set_iface_id(msg, bss) < 0) { | |
484 | nlmsg_free(msg); | |
485 | return NULL; | |
486 | } | |
487 | ||
488 | return msg; | |
489 | } | |
490 | ||
491 | ||
492 | static struct nl_msg * | |
493 | nl80211_ifindex_msg(struct wpa_driver_nl80211_data *drv, int ifindex, | |
494 | int flags, uint8_t cmd) | |
495 | { | |
496 | struct nl_msg *msg; | |
497 | ||
498 | msg = nlmsg_alloc(); | |
499 | if (!msg) | |
500 | return NULL; | |
501 | ||
502 | if (!nl80211_cmd(drv, msg, flags, cmd) || | |
503 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex)) { | |
504 | nlmsg_free(msg); | |
505 | return NULL; | |
506 | } | |
507 | ||
508 | return msg; | |
509 | } | |
510 | ||
511 | ||
512 | struct nl_msg * nl80211_drv_msg(struct wpa_driver_nl80211_data *drv, int flags, | |
513 | uint8_t cmd) | |
514 | { | |
515 | return nl80211_ifindex_msg(drv, drv->ifindex, flags, cmd); | |
516 | } | |
517 | ||
518 | ||
519 | struct nl_msg * nl80211_bss_msg(struct i802_bss *bss, int flags, uint8_t cmd) | |
520 | { | |
521 | return nl80211_ifindex_msg(bss->drv, bss->ifindex, flags, cmd); | |
522 | } | |
523 | ||
524 | ||
e32ad281 JB |
525 | struct wiphy_idx_data { |
526 | int wiphy_idx; | |
01517c8b | 527 | enum nl80211_iftype nlmode; |
597b94f5 | 528 | u8 *macaddr; |
e32ad281 JB |
529 | }; |
530 | ||
531 | ||
532 | static int netdev_info_handler(struct nl_msg *msg, void *arg) | |
533 | { | |
534 | struct nlattr *tb[NL80211_ATTR_MAX + 1]; | |
535 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); | |
536 | struct wiphy_idx_data *info = arg; | |
537 | ||
538 | nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), | |
539 | genlmsg_attrlen(gnlh, 0), NULL); | |
540 | ||
541 | if (tb[NL80211_ATTR_WIPHY]) | |
542 | info->wiphy_idx = nla_get_u32(tb[NL80211_ATTR_WIPHY]); | |
543 | ||
01517c8b JB |
544 | if (tb[NL80211_ATTR_IFTYPE]) |
545 | info->nlmode = nla_get_u32(tb[NL80211_ATTR_IFTYPE]); | |
546 | ||
597b94f5 AS |
547 | if (tb[NL80211_ATTR_MAC] && info->macaddr) |
548 | os_memcpy(info->macaddr, nla_data(tb[NL80211_ATTR_MAC]), | |
549 | ETH_ALEN); | |
550 | ||
e32ad281 JB |
551 | return NL_SKIP; |
552 | } | |
553 | ||
554 | ||
f3407c66 | 555 | int nl80211_get_wiphy_index(struct i802_bss *bss) |
e32ad281 JB |
556 | { |
557 | struct nl_msg *msg; | |
558 | struct wiphy_idx_data data = { | |
559 | .wiphy_idx = -1, | |
597b94f5 | 560 | .macaddr = NULL, |
e32ad281 JB |
561 | }; |
562 | ||
56f77852 | 563 | if (!(msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_GET_INTERFACE))) |
a862e4a3 | 564 | return -1; |
e32ad281 JB |
565 | |
566 | if (send_and_recv_msgs(bss->drv, msg, netdev_info_handler, &data) == 0) | |
567 | return data.wiphy_idx; | |
e32ad281 JB |
568 | return -1; |
569 | } | |
570 | ||
571 | ||
01517c8b JB |
572 | static enum nl80211_iftype nl80211_get_ifmode(struct i802_bss *bss) |
573 | { | |
574 | struct nl_msg *msg; | |
575 | struct wiphy_idx_data data = { | |
597b94f5 AS |
576 | .nlmode = NL80211_IFTYPE_UNSPECIFIED, |
577 | .macaddr = NULL, | |
01517c8b JB |
578 | }; |
579 | ||
56f77852 | 580 | if (!(msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_GET_INTERFACE))) |
a862e4a3 | 581 | return NL80211_IFTYPE_UNSPECIFIED; |
01517c8b JB |
582 | |
583 | if (send_and_recv_msgs(bss->drv, msg, netdev_info_handler, &data) == 0) | |
584 | return data.nlmode; | |
01517c8b JB |
585 | return NL80211_IFTYPE_UNSPECIFIED; |
586 | } | |
01517c8b JB |
587 | |
588 | ||
597b94f5 AS |
589 | static int nl80211_get_macaddr(struct i802_bss *bss) |
590 | { | |
591 | struct nl_msg *msg; | |
592 | struct wiphy_idx_data data = { | |
593 | .macaddr = bss->addr, | |
594 | }; | |
595 | ||
56f77852 | 596 | if (!(msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_GET_INTERFACE))) |
a862e4a3 | 597 | return -1; |
597b94f5 | 598 | |
597b94f5 | 599 | return send_and_recv_msgs(bss->drv, msg, netdev_info_handler, &data); |
597b94f5 | 600 | } |
597b94f5 AS |
601 | |
602 | ||
e32ad281 JB |
603 | static int nl80211_register_beacons(struct wpa_driver_nl80211_data *drv, |
604 | struct nl80211_wiphy_data *w) | |
605 | { | |
606 | struct nl_msg *msg; | |
a862e4a3 | 607 | int ret; |
e32ad281 JB |
608 | |
609 | msg = nlmsg_alloc(); | |
610 | if (!msg) | |
611 | return -1; | |
612 | ||
a862e4a3 JM |
613 | if (!nl80211_cmd(drv, msg, 0, NL80211_CMD_REGISTER_BEACONS) || |
614 | nla_put_u32(msg, NL80211_ATTR_WIPHY, w->wiphy_idx)) { | |
615 | nlmsg_free(msg); | |
616 | return -1; | |
617 | } | |
e32ad281 | 618 | |
481234cf | 619 | ret = send_and_recv(drv->global, w->nl_beacons, msg, NULL, NULL); |
e32ad281 JB |
620 | if (ret) { |
621 | wpa_printf(MSG_DEBUG, "nl80211: Register beacons command " | |
622 | "failed: ret=%d (%s)", | |
623 | ret, strerror(-ret)); | |
e32ad281 | 624 | } |
e32ad281 JB |
625 | return ret; |
626 | } | |
627 | ||
628 | ||
629 | static void nl80211_recv_beacons(int sock, void *eloop_ctx, void *handle) | |
630 | { | |
631 | struct nl80211_wiphy_data *w = eloop_ctx; | |
34068ac3 | 632 | int res; |
e32ad281 | 633 | |
ee9fc67a | 634 | wpa_printf(MSG_EXCESSIVE, "nl80211: Beacon event message available"); |
e32ad281 | 635 | |
34068ac3 | 636 | res = nl_recvmsgs(handle, w->nl_cb); |
d3d04831 | 637 | if (res < 0) { |
34068ac3 JM |
638 | wpa_printf(MSG_INFO, "nl80211: %s->nl_recvmsgs failed: %d", |
639 | __func__, res); | |
640 | } | |
e32ad281 JB |
641 | } |
642 | ||
643 | ||
644 | static int process_beacon_event(struct nl_msg *msg, void *arg) | |
645 | { | |
646 | struct nl80211_wiphy_data *w = arg; | |
647 | struct wpa_driver_nl80211_data *drv; | |
648 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); | |
649 | struct nlattr *tb[NL80211_ATTR_MAX + 1]; | |
650 | union wpa_event_data event; | |
651 | ||
652 | nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), | |
653 | genlmsg_attrlen(gnlh, 0), NULL); | |
654 | ||
655 | if (gnlh->cmd != NL80211_CMD_FRAME) { | |
656 | wpa_printf(MSG_DEBUG, "nl80211: Unexpected beacon event? (%d)", | |
657 | gnlh->cmd); | |
658 | return NL_SKIP; | |
659 | } | |
660 | ||
661 | if (!tb[NL80211_ATTR_FRAME]) | |
662 | return NL_SKIP; | |
663 | ||
664 | dl_list_for_each(drv, &w->drvs, struct wpa_driver_nl80211_data, | |
665 | wiphy_list) { | |
666 | os_memset(&event, 0, sizeof(event)); | |
667 | event.rx_mgmt.frame = nla_data(tb[NL80211_ATTR_FRAME]); | |
668 | event.rx_mgmt.frame_len = nla_len(tb[NL80211_ATTR_FRAME]); | |
669 | wpa_supplicant_event(drv->ctx, EVENT_RX_MGMT, &event); | |
670 | } | |
671 | ||
672 | return NL_SKIP; | |
673 | } | |
674 | ||
675 | ||
676 | static struct nl80211_wiphy_data * | |
677 | nl80211_get_wiphy_data_ap(struct i802_bss *bss) | |
678 | { | |
679 | static DEFINE_DL_LIST(nl80211_wiphys); | |
680 | struct nl80211_wiphy_data *w; | |
681 | int wiphy_idx, found = 0; | |
682 | struct i802_bss *tmp_bss; | |
a70cd0db | 683 | u8 channel; |
e32ad281 JB |
684 | |
685 | if (bss->wiphy_data != NULL) | |
686 | return bss->wiphy_data; | |
687 | ||
688 | wiphy_idx = nl80211_get_wiphy_index(bss); | |
689 | ||
690 | dl_list_for_each(w, &nl80211_wiphys, struct nl80211_wiphy_data, list) { | |
691 | if (w->wiphy_idx == wiphy_idx) | |
692 | goto add; | |
693 | } | |
694 | ||
695 | /* alloc new one */ | |
696 | w = os_zalloc(sizeof(*w)); | |
697 | if (w == NULL) | |
698 | return NULL; | |
699 | w->wiphy_idx = wiphy_idx; | |
700 | dl_list_init(&w->bsss); | |
701 | dl_list_init(&w->drvs); | |
702 | ||
a70cd0db DL |
703 | /* Beacon frames not supported in IEEE 802.11ad */ |
704 | if (ieee80211_freq_to_chan(bss->freq, &channel) != | |
705 | HOSTAPD_MODE_IEEE80211AD) { | |
706 | w->nl_cb = nl_cb_alloc(NL_CB_DEFAULT); | |
707 | if (!w->nl_cb) { | |
708 | os_free(w); | |
709 | return NULL; | |
710 | } | |
711 | nl_cb_set(w->nl_cb, NL_CB_SEQ_CHECK, NL_CB_CUSTOM, | |
712 | no_seq_check, NULL); | |
713 | nl_cb_set(w->nl_cb, NL_CB_VALID, NL_CB_CUSTOM, | |
714 | process_beacon_event, w); | |
715 | ||
716 | w->nl_beacons = nl_create_handle(bss->drv->global->nl_cb, | |
717 | "wiphy beacons"); | |
718 | if (w->nl_beacons == NULL) { | |
719 | os_free(w); | |
720 | return NULL; | |
721 | } | |
e32ad281 | 722 | |
a70cd0db DL |
723 | if (nl80211_register_beacons(bss->drv, w)) { |
724 | nl_destroy_handles(&w->nl_beacons); | |
725 | os_free(w); | |
726 | return NULL; | |
727 | } | |
e32ad281 | 728 | |
a70cd0db | 729 | nl80211_register_eloop_read(&w->nl_beacons, |
40a68f33 | 730 | nl80211_recv_beacons, w, 0); |
e32ad281 JB |
731 | } |
732 | ||
e32ad281 JB |
733 | dl_list_add(&nl80211_wiphys, &w->list); |
734 | ||
735 | add: | |
736 | /* drv entry for this bss already there? */ | |
737 | dl_list_for_each(tmp_bss, &w->bsss, struct i802_bss, wiphy_list) { | |
738 | if (tmp_bss->drv == bss->drv) { | |
739 | found = 1; | |
740 | break; | |
741 | } | |
742 | } | |
743 | /* if not add it */ | |
744 | if (!found) | |
745 | dl_list_add(&w->drvs, &bss->drv->wiphy_list); | |
746 | ||
747 | dl_list_add(&w->bsss, &bss->wiphy_list); | |
748 | bss->wiphy_data = w; | |
749 | return w; | |
750 | } | |
751 | ||
752 | ||
753 | static void nl80211_put_wiphy_data_ap(struct i802_bss *bss) | |
754 | { | |
755 | struct nl80211_wiphy_data *w = bss->wiphy_data; | |
756 | struct i802_bss *tmp_bss; | |
757 | int found = 0; | |
758 | ||
759 | if (w == NULL) | |
760 | return; | |
761 | bss->wiphy_data = NULL; | |
762 | dl_list_del(&bss->wiphy_list); | |
763 | ||
764 | /* still any for this drv present? */ | |
765 | dl_list_for_each(tmp_bss, &w->bsss, struct i802_bss, wiphy_list) { | |
766 | if (tmp_bss->drv == bss->drv) { | |
767 | found = 1; | |
768 | break; | |
769 | } | |
770 | } | |
771 | /* if not remove it */ | |
772 | if (!found) | |
773 | dl_list_del(&bss->drv->wiphy_list); | |
774 | ||
775 | if (!dl_list_empty(&w->bsss)) | |
776 | return; | |
777 | ||
a70cd0db | 778 | if (w->nl_beacons) |
40a68f33 | 779 | nl80211_destroy_eloop_handle(&w->nl_beacons, 0); |
e32ad281 JB |
780 | |
781 | nl_cb_put(w->nl_cb); | |
e32ad281 JB |
782 | dl_list_del(&w->list); |
783 | os_free(w); | |
784 | } | |
785 | ||
786 | ||
45e3fc72 RM |
787 | static unsigned int nl80211_get_ifindex(void *priv) |
788 | { | |
789 | struct i802_bss *bss = priv; | |
790 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
791 | ||
792 | return drv->ifindex; | |
793 | } | |
794 | ||
795 | ||
3f5285e8 JM |
796 | static int wpa_driver_nl80211_get_bssid(void *priv, u8 *bssid) |
797 | { | |
a2e40bb6 FF |
798 | struct i802_bss *bss = priv; |
799 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
c2a04078 JM |
800 | if (!drv->associated) |
801 | return -1; | |
802 | os_memcpy(bssid, drv->bssid, ETH_ALEN); | |
803 | return 0; | |
3f5285e8 JM |
804 | } |
805 | ||
806 | ||
3f5285e8 JM |
807 | static int wpa_driver_nl80211_get_ssid(void *priv, u8 *ssid) |
808 | { | |
a2e40bb6 FF |
809 | struct i802_bss *bss = priv; |
810 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
fd05d64e JM |
811 | if (!drv->associated) |
812 | return -1; | |
813 | os_memcpy(ssid, drv->ssid, drv->ssid_len); | |
814 | return drv->ssid_len; | |
3f5285e8 JM |
815 | } |
816 | ||
817 | ||
90a545cc | 818 | static void wpa_driver_nl80211_event_newlink( |
45e3fc72 RM |
819 | struct nl80211_global *global, struct wpa_driver_nl80211_data *drv, |
820 | int ifindex, const char *ifname) | |
3f5285e8 JM |
821 | { |
822 | union wpa_event_data event; | |
823 | ||
45e3fc72 | 824 | if (drv && os_strcmp(drv->first_bss->ifname, ifname) == 0) { |
90a545cc JM |
825 | if (if_nametoindex(drv->first_bss->ifname) == 0) { |
826 | wpa_printf(MSG_DEBUG, "nl80211: Interface %s does not exist - ignore RTM_NEWLINK", | |
827 | drv->first_bss->ifname); | |
828 | return; | |
829 | } | |
830 | if (!drv->if_removed) | |
831 | return; | |
832 | wpa_printf(MSG_DEBUG, "nl80211: Mark if_removed=0 for %s based on RTM_NEWLINK event", | |
833 | drv->first_bss->ifname); | |
834 | drv->if_removed = 0; | |
835 | } | |
836 | ||
3f5285e8 | 837 | os_memset(&event, 0, sizeof(event)); |
45e3fc72 | 838 | event.interface_status.ifindex = ifindex; |
90a545cc JM |
839 | os_strlcpy(event.interface_status.ifname, ifname, |
840 | sizeof(event.interface_status.ifname)); | |
841 | event.interface_status.ievent = EVENT_INTERFACE_ADDED; | |
45e3fc72 RM |
842 | if (drv) |
843 | wpa_supplicant_event(drv->ctx, EVENT_INTERFACE_STATUS, &event); | |
844 | else | |
845 | wpa_supplicant_event_global(global->ctx, EVENT_INTERFACE_STATUS, | |
846 | &event); | |
90a545cc JM |
847 | } |
848 | ||
849 | ||
850 | static void wpa_driver_nl80211_event_dellink( | |
45e3fc72 RM |
851 | struct nl80211_global *global, struct wpa_driver_nl80211_data *drv, |
852 | int ifindex, const char *ifname) | |
90a545cc JM |
853 | { |
854 | union wpa_event_data event; | |
855 | ||
45e3fc72 | 856 | if (drv && os_strcmp(drv->first_bss->ifname, ifname) == 0) { |
90a545cc JM |
857 | if (drv->if_removed) { |
858 | wpa_printf(MSG_DEBUG, "nl80211: if_removed already set - ignore RTM_DELLINK event for %s", | |
859 | ifname); | |
860 | return; | |
d1f4942b | 861 | } |
90a545cc JM |
862 | wpa_printf(MSG_DEBUG, "RTM_DELLINK: Interface '%s' removed - mark if_removed=1", |
863 | ifname); | |
864 | drv->if_removed = 1; | |
865 | } else { | |
866 | wpa_printf(MSG_DEBUG, "RTM_DELLINK: Interface '%s' removed", | |
867 | ifname); | |
7524cfb1 JM |
868 | } |
869 | ||
90a545cc | 870 | os_memset(&event, 0, sizeof(event)); |
45e3fc72 | 871 | event.interface_status.ifindex = ifindex; |
90a545cc JM |
872 | os_strlcpy(event.interface_status.ifname, ifname, |
873 | sizeof(event.interface_status.ifname)); | |
874 | event.interface_status.ievent = EVENT_INTERFACE_REMOVED; | |
45e3fc72 RM |
875 | if (drv) |
876 | wpa_supplicant_event(drv->ctx, EVENT_INTERFACE_STATUS, &event); | |
877 | else | |
878 | wpa_supplicant_event_global(global->ctx, EVENT_INTERFACE_STATUS, | |
879 | &event); | |
3f5285e8 JM |
880 | } |
881 | ||
882 | ||
7524cfb1 | 883 | static int wpa_driver_nl80211_own_ifname(struct wpa_driver_nl80211_data *drv, |
62d680c3 | 884 | u8 *buf, size_t len) |
7524cfb1 | 885 | { |
62d680c3 | 886 | int attrlen, rta_len; |
7524cfb1 JM |
887 | struct rtattr *attr; |
888 | ||
62d680c3 JM |
889 | attrlen = len; |
890 | attr = (struct rtattr *) buf; | |
7524cfb1 JM |
891 | |
892 | rta_len = RTA_ALIGN(sizeof(struct rtattr)); | |
893 | while (RTA_OK(attr, attrlen)) { | |
894 | if (attr->rta_type == IFLA_IFNAME) { | |
834ee56f KP |
895 | if (os_strcmp(((char *) attr) + rta_len, |
896 | drv->first_bss->ifname) == 0) | |
7524cfb1 JM |
897 | return 1; |
898 | else | |
899 | break; | |
900 | } | |
901 | attr = RTA_NEXT(attr, attrlen); | |
902 | } | |
903 | ||
904 | return 0; | |
905 | } | |
906 | ||
907 | ||
908 | static int wpa_driver_nl80211_own_ifindex(struct wpa_driver_nl80211_data *drv, | |
62d680c3 | 909 | int ifindex, u8 *buf, size_t len) |
7524cfb1 JM |
910 | { |
911 | if (drv->ifindex == ifindex) | |
912 | return 1; | |
913 | ||
62d680c3 | 914 | if (drv->if_removed && wpa_driver_nl80211_own_ifname(drv, buf, len)) { |
f51f54a0 | 915 | nl80211_check_global(drv->global); |
7524cfb1 JM |
916 | wpa_printf(MSG_DEBUG, "nl80211: Update ifindex for a removed " |
917 | "interface"); | |
5e0c20ff JM |
918 | if (wpa_driver_nl80211_finish_drv_init(drv, NULL, 0, NULL) < 0) |
919 | return -1; | |
7524cfb1 JM |
920 | return 1; |
921 | } | |
922 | ||
923 | return 0; | |
924 | } | |
925 | ||
926 | ||
36d84860 | 927 | static struct wpa_driver_nl80211_data * |
5e0c20ff JM |
928 | nl80211_find_drv(struct nl80211_global *global, int idx, u8 *buf, size_t len, |
929 | int *init_failed) | |
36d84860 BG |
930 | { |
931 | struct wpa_driver_nl80211_data *drv; | |
5e0c20ff JM |
932 | int res; |
933 | ||
934 | if (init_failed) | |
935 | *init_failed = 0; | |
36d84860 BG |
936 | dl_list_for_each(drv, &global->interfaces, |
937 | struct wpa_driver_nl80211_data, list) { | |
5e0c20ff JM |
938 | res = wpa_driver_nl80211_own_ifindex(drv, idx, buf, len); |
939 | if (res < 0) { | |
940 | wpa_printf(MSG_DEBUG, | |
941 | "nl80211: Found matching own interface, but failed to complete reinitialization"); | |
942 | if (init_failed) | |
943 | *init_failed = 1; | |
944 | return drv; | |
945 | } | |
946 | if (res > 0 || have_ifidx(drv, idx, IFIDX_ANY)) | |
36d84860 BG |
947 | return drv; |
948 | } | |
949 | return NULL; | |
950 | } | |
951 | ||
952 | ||
290834df BG |
953 | static void nl80211_refresh_mac(struct wpa_driver_nl80211_data *drv, |
954 | int ifindex) | |
955 | { | |
956 | struct i802_bss *bss; | |
957 | u8 addr[ETH_ALEN]; | |
958 | ||
959 | bss = get_bss_ifindex(drv, ifindex); | |
960 | if (bss && | |
961 | linux_get_ifhwaddr(drv->global->ioctl_sock, | |
962 | bss->ifname, addr) < 0) { | |
963 | wpa_printf(MSG_DEBUG, | |
964 | "nl80211: %s: failed to re-read MAC address", | |
965 | bss->ifname); | |
966 | } else if (bss && os_memcmp(addr, bss->addr, ETH_ALEN) != 0) { | |
967 | wpa_printf(MSG_DEBUG, | |
968 | "nl80211: Own MAC address on ifindex %d (%s) changed from " | |
969 | MACSTR " to " MACSTR, | |
970 | ifindex, bss->ifname, | |
971 | MAC2STR(bss->addr), MAC2STR(addr)); | |
972 | os_memcpy(bss->addr, addr, ETH_ALEN); | |
973 | } | |
974 | } | |
975 | ||
976 | ||
62d680c3 JM |
977 | static void wpa_driver_nl80211_event_rtm_newlink(void *ctx, |
978 | struct ifinfomsg *ifi, | |
979 | u8 *buf, size_t len) | |
3f5285e8 | 980 | { |
36d84860 BG |
981 | struct nl80211_global *global = ctx; |
982 | struct wpa_driver_nl80211_data *drv; | |
90a545cc | 983 | int attrlen; |
62d680c3 | 984 | struct rtattr *attr; |
97cfcf64 | 985 | u32 brid = 0; |
aef85ba2 | 986 | char namebuf[IFNAMSIZ]; |
90a545cc JM |
987 | char ifname[IFNAMSIZ + 1]; |
988 | char extra[100], *pos, *end; | |
5e0c20ff | 989 | int init_failed; |
3f5285e8 | 990 | |
90a545cc JM |
991 | extra[0] = '\0'; |
992 | pos = extra; | |
993 | end = pos + sizeof(extra); | |
994 | ifname[0] = '\0'; | |
995 | ||
996 | attrlen = len; | |
997 | attr = (struct rtattr *) buf; | |
998 | while (RTA_OK(attr, attrlen)) { | |
999 | switch (attr->rta_type) { | |
1000 | case IFLA_IFNAME: | |
1001 | if (RTA_PAYLOAD(attr) >= IFNAMSIZ) | |
1002 | break; | |
1003 | os_memcpy(ifname, RTA_DATA(attr), RTA_PAYLOAD(attr)); | |
1004 | ifname[RTA_PAYLOAD(attr)] = '\0'; | |
1005 | break; | |
1006 | case IFLA_MASTER: | |
1007 | brid = nla_get_u32((struct nlattr *) attr); | |
1008 | pos += os_snprintf(pos, end - pos, " master=%u", brid); | |
1009 | break; | |
1010 | case IFLA_WIRELESS: | |
1011 | pos += os_snprintf(pos, end - pos, " wext"); | |
1012 | break; | |
1013 | case IFLA_OPERSTATE: | |
1014 | pos += os_snprintf(pos, end - pos, " operstate=%u", | |
1015 | nla_get_u32((struct nlattr *) attr)); | |
1016 | break; | |
1017 | case IFLA_LINKMODE: | |
1018 | pos += os_snprintf(pos, end - pos, " linkmode=%u", | |
1019 | nla_get_u32((struct nlattr *) attr)); | |
1020 | break; | |
1021 | } | |
1022 | attr = RTA_NEXT(attr, attrlen); | |
1023 | } | |
1024 | extra[sizeof(extra) - 1] = '\0'; | |
1025 | ||
f2e90835 JM |
1026 | wpa_printf(MSG_DEBUG, "RTM_NEWLINK: ifi_index=%d ifname=%s%s ifi_family=%d ifi_flags=0x%x (%s%s%s%s)", |
1027 | ifi->ifi_index, ifname, extra, ifi->ifi_family, | |
1028 | ifi->ifi_flags, | |
3f5285e8 JM |
1029 | (ifi->ifi_flags & IFF_UP) ? "[UP]" : "", |
1030 | (ifi->ifi_flags & IFF_RUNNING) ? "[RUNNING]" : "", | |
1031 | (ifi->ifi_flags & IFF_LOWER_UP) ? "[LOWER_UP]" : "", | |
1032 | (ifi->ifi_flags & IFF_DORMANT) ? "[DORMANT]" : ""); | |
a63063b4 | 1033 | |
5e0c20ff | 1034 | drv = nl80211_find_drv(global, ifi->ifi_index, buf, len, &init_failed); |
45e3fc72 RM |
1035 | if (!drv) |
1036 | goto event_newlink; | |
5e0c20ff JM |
1037 | if (init_failed) |
1038 | return; /* do not update interface state */ | |
45e3fc72 | 1039 | |
a63063b4 | 1040 | if (!drv->if_disabled && !(ifi->ifi_flags & IFF_UP)) { |
106fa1e9 | 1041 | namebuf[0] = '\0'; |
59d24925 | 1042 | if (if_indextoname(ifi->ifi_index, namebuf) && |
106fa1e9 | 1043 | linux_iface_up(drv->global->ioctl_sock, namebuf) > 0) { |
290834df BG |
1044 | /* Re-read MAC address as it may have changed */ |
1045 | nl80211_refresh_mac(drv, ifi->ifi_index); | |
59d24925 JM |
1046 | wpa_printf(MSG_DEBUG, "nl80211: Ignore interface down " |
1047 | "event since interface %s is up", namebuf); | |
7a94120e | 1048 | drv->ignore_if_down_event = 0; |
59d24925 JM |
1049 | return; |
1050 | } | |
106fa1e9 JM |
1051 | wpa_printf(MSG_DEBUG, "nl80211: Interface down (%s/%s)", |
1052 | namebuf, ifname); | |
1053 | if (os_strcmp(drv->first_bss->ifname, ifname) != 0) { | |
1054 | wpa_printf(MSG_DEBUG, | |
1055 | "nl80211: Not the main interface (%s) - do not indicate interface down", | |
1056 | drv->first_bss->ifname); | |
1057 | } else if (drv->ignore_if_down_event) { | |
7d9c3698 JM |
1058 | wpa_printf(MSG_DEBUG, "nl80211: Ignore interface down " |
1059 | "event generated by mode change"); | |
1060 | drv->ignore_if_down_event = 0; | |
1061 | } else { | |
1062 | drv->if_disabled = 1; | |
1063 | wpa_supplicant_event(drv->ctx, | |
1064 | EVENT_INTERFACE_DISABLED, NULL); | |
819f096f AO |
1065 | |
1066 | /* | |
1067 | * Try to get drv again, since it may be removed as | |
1068 | * part of the EVENT_INTERFACE_DISABLED handling for | |
1069 | * dynamic interfaces | |
1070 | */ | |
1071 | drv = nl80211_find_drv(global, ifi->ifi_index, | |
5e0c20ff | 1072 | buf, len, NULL); |
819f096f AO |
1073 | if (!drv) |
1074 | return; | |
7d9c3698 | 1075 | } |
a63063b4 JM |
1076 | } |
1077 | ||
1078 | if (drv->if_disabled && (ifi->ifi_flags & IFF_UP)) { | |
aef85ba2 | 1079 | if (if_indextoname(ifi->ifi_index, namebuf) && |
106fa1e9 | 1080 | linux_iface_up(drv->global->ioctl_sock, namebuf) == 0) { |
aef85ba2 JM |
1081 | wpa_printf(MSG_DEBUG, "nl80211: Ignore interface up " |
1082 | "event since interface %s is down", | |
1083 | namebuf); | |
834ee56f | 1084 | } else if (if_nametoindex(drv->first_bss->ifname) == 0) { |
d1f4942b JM |
1085 | wpa_printf(MSG_DEBUG, "nl80211: Ignore interface up " |
1086 | "event since interface %s does not exist", | |
834ee56f | 1087 | drv->first_bss->ifname); |
d1f4942b JM |
1088 | } else if (drv->if_removed) { |
1089 | wpa_printf(MSG_DEBUG, "nl80211: Ignore interface up " | |
1090 | "event since interface %s is marked " | |
834ee56f | 1091 | "removed", drv->first_bss->ifname); |
aef85ba2 | 1092 | } else { |
3e0272ca | 1093 | /* Re-read MAC address as it may have changed */ |
290834df | 1094 | nl80211_refresh_mac(drv, ifi->ifi_index); |
3e0272ca | 1095 | |
aef85ba2 JM |
1096 | wpa_printf(MSG_DEBUG, "nl80211: Interface up"); |
1097 | drv->if_disabled = 0; | |
1098 | wpa_supplicant_event(drv->ctx, EVENT_INTERFACE_ENABLED, | |
1099 | NULL); | |
1100 | } | |
a63063b4 JM |
1101 | } |
1102 | ||
3f5285e8 JM |
1103 | /* |
1104 | * Some drivers send the association event before the operup event--in | |
1105 | * this case, lifting operstate in wpa_driver_nl80211_set_operstate() | |
1106 | * fails. This will hit us when wpa_supplicant does not need to do | |
1107 | * IEEE 802.1X authentication | |
1108 | */ | |
1109 | if (drv->operstate == 1 && | |
1110 | (ifi->ifi_flags & (IFF_LOWER_UP | IFF_DORMANT)) == IFF_LOWER_UP && | |
90a545cc JM |
1111 | !(ifi->ifi_flags & IFF_RUNNING)) { |
1112 | wpa_printf(MSG_DEBUG, "nl80211: Set IF_OPER_UP again based on ifi_flags and expected operstate"); | |
36d84860 | 1113 | netlink_send_oper_ifla(drv->global->netlink, drv->ifindex, |
e2d02c29 | 1114 | -1, IF_OPER_UP); |
3f5285e8 | 1115 | } |
97cfcf64 | 1116 | |
45e3fc72 | 1117 | event_newlink: |
90a545cc | 1118 | if (ifname[0]) |
45e3fc72 RM |
1119 | wpa_driver_nl80211_event_newlink(global, drv, ifi->ifi_index, |
1120 | ifname); | |
90a545cc | 1121 | |
45e3fc72 | 1122 | if (ifi->ifi_family == AF_BRIDGE && brid && drv) { |
392dfd37 JM |
1123 | struct i802_bss *bss; |
1124 | ||
97cfcf64 | 1125 | /* device has been added to bridge */ |
40e76396 JM |
1126 | if (!if_indextoname(brid, namebuf)) { |
1127 | wpa_printf(MSG_DEBUG, | |
1128 | "nl80211: Could not find bridge ifname for ifindex %u", | |
1129 | brid); | |
1130 | return; | |
1131 | } | |
97cfcf64 B |
1132 | wpa_printf(MSG_DEBUG, "nl80211: Add ifindex %u for bridge %s", |
1133 | brid, namebuf); | |
732b1d20 | 1134 | add_ifidx(drv, brid, ifi->ifi_index); |
392dfd37 JM |
1135 | |
1136 | for (bss = drv->first_bss; bss; bss = bss->next) { | |
1137 | if (os_strcmp(ifname, bss->ifname) == 0) { | |
1138 | os_strlcpy(bss->brname, namebuf, IFNAMSIZ); | |
1139 | break; | |
1140 | } | |
1141 | } | |
97cfcf64 | 1142 | } |
3f5285e8 JM |
1143 | } |
1144 | ||
1145 | ||
62d680c3 JM |
1146 | static void wpa_driver_nl80211_event_rtm_dellink(void *ctx, |
1147 | struct ifinfomsg *ifi, | |
1148 | u8 *buf, size_t len) | |
3f5285e8 | 1149 | { |
36d84860 BG |
1150 | struct nl80211_global *global = ctx; |
1151 | struct wpa_driver_nl80211_data *drv; | |
90a545cc | 1152 | int attrlen; |
62d680c3 | 1153 | struct rtattr *attr; |
97cfcf64 | 1154 | u32 brid = 0; |
90a545cc | 1155 | char ifname[IFNAMSIZ + 1]; |
f2e90835 | 1156 | char extra[100], *pos, *end; |
3f5285e8 | 1157 | |
f2e90835 JM |
1158 | extra[0] = '\0'; |
1159 | pos = extra; | |
1160 | end = pos + sizeof(extra); | |
90a545cc JM |
1161 | ifname[0] = '\0'; |
1162 | ||
62d680c3 JM |
1163 | attrlen = len; |
1164 | attr = (struct rtattr *) buf; | |
3f5285e8 | 1165 | while (RTA_OK(attr, attrlen)) { |
90a545cc JM |
1166 | switch (attr->rta_type) { |
1167 | case IFLA_IFNAME: | |
1168 | if (RTA_PAYLOAD(attr) >= IFNAMSIZ) | |
1169 | break; | |
1170 | os_memcpy(ifname, RTA_DATA(attr), RTA_PAYLOAD(attr)); | |
1171 | ifname[RTA_PAYLOAD(attr)] = '\0'; | |
1172 | break; | |
1173 | case IFLA_MASTER: | |
97cfcf64 | 1174 | brid = nla_get_u32((struct nlattr *) attr); |
f2e90835 JM |
1175 | pos += os_snprintf(pos, end - pos, " master=%u", brid); |
1176 | break; | |
1177 | case IFLA_OPERSTATE: | |
1178 | pos += os_snprintf(pos, end - pos, " operstate=%u", | |
1179 | nla_get_u32((struct nlattr *) attr)); | |
1180 | break; | |
1181 | case IFLA_LINKMODE: | |
1182 | pos += os_snprintf(pos, end - pos, " linkmode=%u", | |
1183 | nla_get_u32((struct nlattr *) attr)); | |
90a545cc JM |
1184 | break; |
1185 | } | |
3f5285e8 JM |
1186 | attr = RTA_NEXT(attr, attrlen); |
1187 | } | |
f2e90835 JM |
1188 | extra[sizeof(extra) - 1] = '\0'; |
1189 | ||
1190 | wpa_printf(MSG_DEBUG, "RTM_DELLINK: ifi_index=%d ifname=%s%s ifi_family=%d ifi_flags=0x%x (%s%s%s%s)", | |
1191 | ifi->ifi_index, ifname, extra, ifi->ifi_family, | |
1192 | ifi->ifi_flags, | |
1193 | (ifi->ifi_flags & IFF_UP) ? "[UP]" : "", | |
1194 | (ifi->ifi_flags & IFF_RUNNING) ? "[RUNNING]" : "", | |
1195 | (ifi->ifi_flags & IFF_LOWER_UP) ? "[LOWER_UP]" : "", | |
1196 | (ifi->ifi_flags & IFF_DORMANT) ? "[DORMANT]" : ""); | |
97cfcf64 | 1197 | |
5e0c20ff | 1198 | drv = nl80211_find_drv(global, ifi->ifi_index, buf, len, NULL); |
90a545cc | 1199 | |
45e3fc72 | 1200 | if (ifi->ifi_family == AF_BRIDGE && brid && drv) { |
97cfcf64 B |
1201 | /* device has been removed from bridge */ |
1202 | char namebuf[IFNAMSIZ]; | |
40e76396 JM |
1203 | |
1204 | if (!if_indextoname(brid, namebuf)) { | |
1205 | wpa_printf(MSG_DEBUG, | |
1206 | "nl80211: Could not find bridge ifname for ifindex %u", | |
1207 | brid); | |
1208 | } else { | |
1209 | wpa_printf(MSG_DEBUG, | |
1210 | "nl80211: Remove ifindex %u for bridge %s", | |
1211 | brid, namebuf); | |
1212 | } | |
732b1d20 | 1213 | del_ifidx(drv, brid, ifi->ifi_index); |
97cfcf64 | 1214 | } |
45e3fc72 RM |
1215 | |
1216 | if (ifi->ifi_family != AF_BRIDGE || !brid) | |
1217 | wpa_driver_nl80211_event_dellink(global, drv, ifi->ifi_index, | |
1218 | ifname); | |
3f5285e8 JM |
1219 | } |
1220 | ||
1221 | ||
a1fce391 JM |
1222 | struct nl80211_get_assoc_freq_arg { |
1223 | struct wpa_driver_nl80211_data *drv; | |
1224 | unsigned int assoc_freq; | |
1225 | unsigned int ibss_freq; | |
1226 | u8 assoc_bssid[ETH_ALEN]; | |
ed0a4ddc NW |
1227 | u8 assoc_ssid[SSID_MAX_LEN]; |
1228 | u8 assoc_ssid_len; | |
a1fce391 JM |
1229 | }; |
1230 | ||
1231 | static int nl80211_get_assoc_freq_handler(struct nl_msg *msg, void *arg) | |
1232 | { | |
1233 | struct nlattr *tb[NL80211_ATTR_MAX + 1]; | |
1234 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); | |
1235 | struct nlattr *bss[NL80211_BSS_MAX + 1]; | |
1236 | static struct nla_policy bss_policy[NL80211_BSS_MAX + 1] = { | |
1237 | [NL80211_BSS_BSSID] = { .type = NLA_UNSPEC }, | |
1238 | [NL80211_BSS_FREQUENCY] = { .type = NLA_U32 }, | |
ed0a4ddc | 1239 | [NL80211_BSS_INFORMATION_ELEMENTS] = { .type = NLA_UNSPEC }, |
a1fce391 JM |
1240 | [NL80211_BSS_STATUS] = { .type = NLA_U32 }, |
1241 | }; | |
1242 | struct nl80211_get_assoc_freq_arg *ctx = arg; | |
1243 | enum nl80211_bss_status status; | |
1244 | ||
1245 | nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), | |
1246 | genlmsg_attrlen(gnlh, 0), NULL); | |
1247 | if (!tb[NL80211_ATTR_BSS] || | |
1248 | nla_parse_nested(bss, NL80211_BSS_MAX, tb[NL80211_ATTR_BSS], | |
1249 | bss_policy) || | |
1250 | !bss[NL80211_BSS_STATUS]) | |
1251 | return NL_SKIP; | |
1252 | ||
1253 | status = nla_get_u32(bss[NL80211_BSS_STATUS]); | |
1254 | if (status == NL80211_BSS_STATUS_ASSOCIATED && | |
1255 | bss[NL80211_BSS_FREQUENCY]) { | |
1256 | ctx->assoc_freq = nla_get_u32(bss[NL80211_BSS_FREQUENCY]); | |
1257 | wpa_printf(MSG_DEBUG, "nl80211: Associated on %u MHz", | |
1258 | ctx->assoc_freq); | |
1259 | } | |
1260 | if (status == NL80211_BSS_STATUS_IBSS_JOINED && | |
1261 | bss[NL80211_BSS_FREQUENCY]) { | |
1262 | ctx->ibss_freq = nla_get_u32(bss[NL80211_BSS_FREQUENCY]); | |
1263 | wpa_printf(MSG_DEBUG, "nl80211: IBSS-joined on %u MHz", | |
1264 | ctx->ibss_freq); | |
1265 | } | |
1266 | if (status == NL80211_BSS_STATUS_ASSOCIATED && | |
1267 | bss[NL80211_BSS_BSSID]) { | |
1268 | os_memcpy(ctx->assoc_bssid, | |
1269 | nla_data(bss[NL80211_BSS_BSSID]), ETH_ALEN); | |
1270 | wpa_printf(MSG_DEBUG, "nl80211: Associated with " | |
1271 | MACSTR, MAC2STR(ctx->assoc_bssid)); | |
1272 | } | |
1273 | ||
ed0a4ddc NW |
1274 | if (status == NL80211_BSS_STATUS_ASSOCIATED && |
1275 | bss[NL80211_BSS_INFORMATION_ELEMENTS]) { | |
1276 | const u8 *ie, *ssid; | |
1277 | size_t ie_len; | |
1278 | ||
1279 | ie = nla_data(bss[NL80211_BSS_INFORMATION_ELEMENTS]); | |
1280 | ie_len = nla_len(bss[NL80211_BSS_INFORMATION_ELEMENTS]); | |
1281 | ssid = get_ie(ie, ie_len, WLAN_EID_SSID); | |
1282 | if (ssid && ssid[1] > 0 && ssid[1] <= SSID_MAX_LEN) { | |
1283 | ctx->assoc_ssid_len = ssid[1]; | |
1284 | os_memcpy(ctx->assoc_ssid, ssid + 2, ssid[1]); | |
1285 | } | |
1286 | } | |
1287 | ||
a1fce391 JM |
1288 | return NL_SKIP; |
1289 | } | |
1290 | ||
1291 | ||
ed0a4ddc NW |
1292 | int nl80211_get_assoc_ssid(struct wpa_driver_nl80211_data *drv, u8 *ssid) |
1293 | { | |
1294 | struct nl_msg *msg; | |
1295 | int ret; | |
1296 | struct nl80211_get_assoc_freq_arg arg; | |
1297 | ||
1298 | msg = nl80211_drv_msg(drv, NLM_F_DUMP, NL80211_CMD_GET_SCAN); | |
1299 | os_memset(&arg, 0, sizeof(arg)); | |
1300 | arg.drv = drv; | |
1301 | ret = send_and_recv_msgs(drv, msg, nl80211_get_assoc_freq_handler, | |
1302 | &arg); | |
1303 | if (ret == 0) { | |
1304 | os_memcpy(ssid, arg.assoc_ssid, arg.assoc_ssid_len); | |
1305 | return arg.assoc_ssid_len; | |
1306 | } | |
1307 | wpa_printf(MSG_DEBUG, "nl80211: Scan result fetch failed: ret=%d (%s)", | |
1308 | ret, strerror(-ret)); | |
1309 | return ret; | |
1310 | } | |
1311 | ||
1312 | ||
f3407c66 | 1313 | unsigned int nl80211_get_assoc_freq(struct wpa_driver_nl80211_data *drv) |
f5a8d422 JM |
1314 | { |
1315 | struct nl_msg *msg; | |
1316 | int ret; | |
a1fce391 | 1317 | struct nl80211_get_assoc_freq_arg arg; |
f5a8d422 | 1318 | |
9725b784 | 1319 | msg = nl80211_drv_msg(drv, NLM_F_DUMP, NL80211_CMD_GET_SCAN); |
f5a8d422 | 1320 | os_memset(&arg, 0, sizeof(arg)); |
f5a8d422 | 1321 | arg.drv = drv; |
a1fce391 JM |
1322 | ret = send_and_recv_msgs(drv, msg, nl80211_get_assoc_freq_handler, |
1323 | &arg); | |
f5a8d422 | 1324 | if (ret == 0) { |
c7caac56 JM |
1325 | unsigned int freq = drv->nlmode == NL80211_IFTYPE_ADHOC ? |
1326 | arg.ibss_freq : arg.assoc_freq; | |
f5a8d422 | 1327 | wpa_printf(MSG_DEBUG, "nl80211: Operating frequency for the " |
c7caac56 JM |
1328 | "associated BSS from scan results: %u MHz", freq); |
1329 | if (freq) | |
1330 | drv->assoc_freq = freq; | |
30158a0d | 1331 | return drv->assoc_freq; |
f5a8d422 JM |
1332 | } |
1333 | wpa_printf(MSG_DEBUG, "nl80211: Scan result fetch failed: ret=%d " | |
1334 | "(%s)", ret, strerror(-ret)); | |
f5a8d422 JM |
1335 | return drv->assoc_freq; |
1336 | } | |
1337 | ||
1338 | ||
60a972a6 JM |
1339 | static int get_link_signal(struct nl_msg *msg, void *arg) |
1340 | { | |
1341 | struct nlattr *tb[NL80211_ATTR_MAX + 1]; | |
1342 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); | |
1343 | struct nlattr *sinfo[NL80211_STA_INFO_MAX + 1]; | |
1344 | static struct nla_policy policy[NL80211_STA_INFO_MAX + 1] = { | |
1345 | [NL80211_STA_INFO_SIGNAL] = { .type = NLA_U8 }, | |
95783298 | 1346 | [NL80211_STA_INFO_SIGNAL_AVG] = { .type = NLA_U8 }, |
74fa78b2 | 1347 | [NL80211_STA_INFO_BEACON_SIGNAL_AVG] = { .type = NLA_U8 }, |
60a972a6 | 1348 | }; |
7ee35bf3 PS |
1349 | struct nlattr *rinfo[NL80211_RATE_INFO_MAX + 1]; |
1350 | static struct nla_policy rate_policy[NL80211_RATE_INFO_MAX + 1] = { | |
1351 | [NL80211_RATE_INFO_BITRATE] = { .type = NLA_U16 }, | |
1352 | [NL80211_RATE_INFO_MCS] = { .type = NLA_U8 }, | |
1353 | [NL80211_RATE_INFO_40_MHZ_WIDTH] = { .type = NLA_FLAG }, | |
1354 | [NL80211_RATE_INFO_SHORT_GI] = { .type = NLA_FLAG }, | |
1355 | }; | |
1c5c7273 | 1356 | struct wpa_signal_info *sig_change = arg; |
60a972a6 JM |
1357 | |
1358 | nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), | |
1359 | genlmsg_attrlen(gnlh, 0), NULL); | |
1360 | if (!tb[NL80211_ATTR_STA_INFO] || | |
1361 | nla_parse_nested(sinfo, NL80211_STA_INFO_MAX, | |
1362 | tb[NL80211_ATTR_STA_INFO], policy)) | |
1363 | return NL_SKIP; | |
1364 | if (!sinfo[NL80211_STA_INFO_SIGNAL]) | |
1365 | return NL_SKIP; | |
1366 | ||
7ee35bf3 PS |
1367 | sig_change->current_signal = |
1368 | (s8) nla_get_u8(sinfo[NL80211_STA_INFO_SIGNAL]); | |
1369 | ||
95783298 AO |
1370 | if (sinfo[NL80211_STA_INFO_SIGNAL_AVG]) |
1371 | sig_change->avg_signal = | |
1372 | (s8) nla_get_u8(sinfo[NL80211_STA_INFO_SIGNAL_AVG]); | |
1373 | else | |
1374 | sig_change->avg_signal = 0; | |
1375 | ||
74fa78b2 JM |
1376 | if (sinfo[NL80211_STA_INFO_BEACON_SIGNAL_AVG]) |
1377 | sig_change->avg_beacon_signal = | |
1378 | (s8) | |
1379 | nla_get_u8(sinfo[NL80211_STA_INFO_BEACON_SIGNAL_AVG]); | |
1380 | else | |
1381 | sig_change->avg_beacon_signal = 0; | |
1382 | ||
7ee35bf3 PS |
1383 | if (sinfo[NL80211_STA_INFO_TX_BITRATE]) { |
1384 | if (nla_parse_nested(rinfo, NL80211_RATE_INFO_MAX, | |
1385 | sinfo[NL80211_STA_INFO_TX_BITRATE], | |
1386 | rate_policy)) { | |
1387 | sig_change->current_txrate = 0; | |
1388 | } else { | |
1389 | if (rinfo[NL80211_RATE_INFO_BITRATE]) { | |
1390 | sig_change->current_txrate = | |
1391 | nla_get_u16(rinfo[ | |
1392 | NL80211_RATE_INFO_BITRATE]) * 100; | |
1393 | } | |
1394 | } | |
1395 | } | |
1396 | ||
60a972a6 JM |
1397 | return NL_SKIP; |
1398 | } | |
1399 | ||
1400 | ||
f3407c66 JM |
1401 | int nl80211_get_link_signal(struct wpa_driver_nl80211_data *drv, |
1402 | struct wpa_signal_info *sig) | |
60a972a6 JM |
1403 | { |
1404 | struct nl_msg *msg; | |
1405 | ||
7ee35bf3 PS |
1406 | sig->current_signal = -9999; |
1407 | sig->current_txrate = 0; | |
60a972a6 | 1408 | |
9725b784 | 1409 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_GET_STATION)) || |
a862e4a3 JM |
1410 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, drv->bssid)) { |
1411 | nlmsg_free(msg); | |
1412 | return -ENOBUFS; | |
1413 | } | |
60a972a6 JM |
1414 | |
1415 | return send_and_recv_msgs(drv, msg, get_link_signal, sig); | |
60a972a6 JM |
1416 | } |
1417 | ||
1418 | ||
7ee35bf3 PS |
1419 | static int get_link_noise(struct nl_msg *msg, void *arg) |
1420 | { | |
1421 | struct nlattr *tb[NL80211_ATTR_MAX + 1]; | |
1422 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); | |
1423 | struct nlattr *sinfo[NL80211_SURVEY_INFO_MAX + 1]; | |
1424 | static struct nla_policy survey_policy[NL80211_SURVEY_INFO_MAX + 1] = { | |
1425 | [NL80211_SURVEY_INFO_FREQUENCY] = { .type = NLA_U32 }, | |
1426 | [NL80211_SURVEY_INFO_NOISE] = { .type = NLA_U8 }, | |
1427 | }; | |
1c5c7273 | 1428 | struct wpa_signal_info *sig_change = arg; |
7ee35bf3 PS |
1429 | |
1430 | nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), | |
1431 | genlmsg_attrlen(gnlh, 0), NULL); | |
1432 | ||
1433 | if (!tb[NL80211_ATTR_SURVEY_INFO]) { | |
1434 | wpa_printf(MSG_DEBUG, "nl80211: survey data missing!"); | |
1435 | return NL_SKIP; | |
1436 | } | |
1437 | ||
1438 | if (nla_parse_nested(sinfo, NL80211_SURVEY_INFO_MAX, | |
1439 | tb[NL80211_ATTR_SURVEY_INFO], | |
1440 | survey_policy)) { | |
1441 | wpa_printf(MSG_DEBUG, "nl80211: failed to parse nested " | |
1442 | "attributes!"); | |
1443 | return NL_SKIP; | |
1444 | } | |
1445 | ||
1446 | if (!sinfo[NL80211_SURVEY_INFO_FREQUENCY]) | |
1447 | return NL_SKIP; | |
1448 | ||
1449 | if (nla_get_u32(sinfo[NL80211_SURVEY_INFO_FREQUENCY]) != | |
1450 | sig_change->frequency) | |
1451 | return NL_SKIP; | |
1452 | ||
1453 | if (!sinfo[NL80211_SURVEY_INFO_NOISE]) | |
1454 | return NL_SKIP; | |
1455 | ||
1456 | sig_change->current_noise = | |
1457 | (s8) nla_get_u8(sinfo[NL80211_SURVEY_INFO_NOISE]); | |
1458 | ||
1459 | return NL_SKIP; | |
1460 | } | |
1461 | ||
1462 | ||
f3407c66 JM |
1463 | int nl80211_get_link_noise(struct wpa_driver_nl80211_data *drv, |
1464 | struct wpa_signal_info *sig_change) | |
7ee35bf3 PS |
1465 | { |
1466 | struct nl_msg *msg; | |
1467 | ||
1468 | sig_change->current_noise = 9999; | |
1469 | sig_change->frequency = drv->assoc_freq; | |
1470 | ||
9725b784 | 1471 | msg = nl80211_drv_msg(drv, NLM_F_DUMP, NL80211_CMD_GET_SURVEY); |
7ee35bf3 | 1472 | return send_and_recv_msgs(drv, msg, get_link_noise, sig_change); |
7ee35bf3 PS |
1473 | } |
1474 | ||
1475 | ||
97865538 | 1476 | static void wpa_driver_nl80211_event_receive(int sock, void *eloop_ctx, |
5582a5d1 | 1477 | void *handle) |
97865538 | 1478 | { |
a4ae123c | 1479 | struct nl_cb *cb = eloop_ctx; |
34068ac3 | 1480 | int res; |
97865538 | 1481 | |
cc2ada86 | 1482 | wpa_printf(MSG_MSGDUMP, "nl80211: Event message available"); |
97865538 | 1483 | |
34068ac3 | 1484 | res = nl_recvmsgs(handle, cb); |
d3d04831 | 1485 | if (res < 0) { |
34068ac3 JM |
1486 | wpa_printf(MSG_INFO, "nl80211: %s->nl_recvmsgs failed: %d", |
1487 | __func__, res); | |
1488 | } | |
97865538 JM |
1489 | } |
1490 | ||
1491 | ||
6d158490 LR |
1492 | /** |
1493 | * wpa_driver_nl80211_set_country - ask nl80211 to set the regulatory domain | |
1494 | * @priv: driver_nl80211 private data | |
1495 | * @alpha2_arg: country to which to switch to | |
1496 | * Returns: 0 on success, -1 on failure | |
1497 | * | |
1498 | * This asks nl80211 to set the regulatory domain for given | |
1499 | * country ISO / IEC alpha2. | |
1500 | */ | |
1501 | static int wpa_driver_nl80211_set_country(void *priv, const char *alpha2_arg) | |
1502 | { | |
a2e40bb6 FF |
1503 | struct i802_bss *bss = priv; |
1504 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
6d158490 LR |
1505 | char alpha2[3]; |
1506 | struct nl_msg *msg; | |
1507 | ||
1508 | msg = nlmsg_alloc(); | |
1509 | if (!msg) | |
e785c2ba | 1510 | return -ENOMEM; |
6d158490 LR |
1511 | |
1512 | alpha2[0] = alpha2_arg[0]; | |
1513 | alpha2[1] = alpha2_arg[1]; | |
1514 | alpha2[2] = '\0'; | |
1515 | ||
a862e4a3 JM |
1516 | if (!nl80211_cmd(drv, msg, 0, NL80211_CMD_REQ_SET_REG) || |
1517 | nla_put_string(msg, NL80211_ATTR_REG_ALPHA2, alpha2)) { | |
1518 | nlmsg_free(msg); | |
1519 | return -EINVAL; | |
1520 | } | |
6d158490 LR |
1521 | if (send_and_recv_msgs(drv, msg, NULL, NULL)) |
1522 | return -EINVAL; | |
1523 | return 0; | |
6d158490 LR |
1524 | } |
1525 | ||
1526 | ||
f0793bf1 JM |
1527 | static int nl80211_get_country(struct nl_msg *msg, void *arg) |
1528 | { | |
1529 | char *alpha2 = arg; | |
1530 | struct nlattr *tb_msg[NL80211_ATTR_MAX + 1]; | |
1531 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); | |
1532 | ||
1533 | nla_parse(tb_msg, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), | |
1534 | genlmsg_attrlen(gnlh, 0), NULL); | |
1535 | if (!tb_msg[NL80211_ATTR_REG_ALPHA2]) { | |
1536 | wpa_printf(MSG_DEBUG, "nl80211: No country information available"); | |
1537 | return NL_SKIP; | |
1538 | } | |
1539 | os_strlcpy(alpha2, nla_data(tb_msg[NL80211_ATTR_REG_ALPHA2]), 3); | |
1540 | return NL_SKIP; | |
1541 | } | |
1542 | ||
1543 | ||
1544 | static int wpa_driver_nl80211_get_country(void *priv, char *alpha2) | |
1545 | { | |
1546 | struct i802_bss *bss = priv; | |
1547 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
1548 | struct nl_msg *msg; | |
1549 | int ret; | |
1550 | ||
1551 | msg = nlmsg_alloc(); | |
1552 | if (!msg) | |
1553 | return -ENOMEM; | |
1554 | ||
1555 | nl80211_cmd(drv, msg, 0, NL80211_CMD_GET_REG); | |
1556 | alpha2[0] = '\0'; | |
1557 | ret = send_and_recv_msgs(drv, msg, nl80211_get_country, alpha2); | |
1558 | if (!alpha2[0]) | |
1559 | ret = -1; | |
1560 | ||
1561 | return ret; | |
1562 | } | |
1563 | ||
1564 | ||
2a7b66f5 BG |
1565 | static int wpa_driver_nl80211_init_nl_global(struct nl80211_global *global) |
1566 | { | |
d6c9aab8 JB |
1567 | int ret; |
1568 | ||
2a7b66f5 BG |
1569 | global->nl_cb = nl_cb_alloc(NL_CB_DEFAULT); |
1570 | if (global->nl_cb == NULL) { | |
1571 | wpa_printf(MSG_ERROR, "nl80211: Failed to allocate netlink " | |
1572 | "callbacks"); | |
1573 | return -1; | |
1574 | } | |
1575 | ||
481234cf JM |
1576 | global->nl = nl_create_handle(global->nl_cb, "nl"); |
1577 | if (global->nl == NULL) | |
d6c9aab8 | 1578 | goto err; |
276e2d67 | 1579 | |
481234cf | 1580 | global->nl80211_id = genl_ctrl_resolve(global->nl, "nl80211"); |
335d42b1 | 1581 | if (global->nl80211_id < 0) { |
276e2d67 BG |
1582 | wpa_printf(MSG_ERROR, "nl80211: 'nl80211' generic netlink not " |
1583 | "found"); | |
d6c9aab8 | 1584 | goto err; |
276e2d67 BG |
1585 | } |
1586 | ||
481234cf JM |
1587 | global->nl_event = nl_create_handle(global->nl_cb, "event"); |
1588 | if (global->nl_event == NULL) | |
d6c9aab8 | 1589 | goto err; |
9fff9fdc | 1590 | |
d6c9aab8 | 1591 | ret = nl_get_multicast_id(global, "nl80211", "scan"); |
97865538 | 1592 | if (ret >= 0) |
481234cf | 1593 | ret = nl_socket_add_membership(global->nl_event, ret); |
97865538 JM |
1594 | if (ret < 0) { |
1595 | wpa_printf(MSG_ERROR, "nl80211: Could not add multicast " | |
1596 | "membership for scan events: %d (%s)", | |
1597 | ret, strerror(-ret)); | |
d6c9aab8 | 1598 | goto err; |
97865538 | 1599 | } |
c2a04078 | 1600 | |
d6c9aab8 | 1601 | ret = nl_get_multicast_id(global, "nl80211", "mlme"); |
c2a04078 | 1602 | if (ret >= 0) |
481234cf | 1603 | ret = nl_socket_add_membership(global->nl_event, ret); |
c2a04078 JM |
1604 | if (ret < 0) { |
1605 | wpa_printf(MSG_ERROR, "nl80211: Could not add multicast " | |
1606 | "membership for mlme events: %d (%s)", | |
1607 | ret, strerror(-ret)); | |
d6c9aab8 | 1608 | goto err; |
c2a04078 | 1609 | } |
c2a04078 | 1610 | |
d6c9aab8 | 1611 | ret = nl_get_multicast_id(global, "nl80211", "regulatory"); |
33c5deb8 | 1612 | if (ret >= 0) |
481234cf | 1613 | ret = nl_socket_add_membership(global->nl_event, ret); |
33c5deb8 JM |
1614 | if (ret < 0) { |
1615 | wpa_printf(MSG_DEBUG, "nl80211: Could not add multicast " | |
1616 | "membership for regulatory events: %d (%s)", | |
1617 | ret, strerror(-ret)); | |
1618 | /* Continue without regulatory events */ | |
1619 | } | |
1620 | ||
17b79e65 JM |
1621 | ret = nl_get_multicast_id(global, "nl80211", "vendor"); |
1622 | if (ret >= 0) | |
1623 | ret = nl_socket_add_membership(global->nl_event, ret); | |
1624 | if (ret < 0) { | |
1625 | wpa_printf(MSG_DEBUG, "nl80211: Could not add multicast " | |
1626 | "membership for vendor events: %d (%s)", | |
1627 | ret, strerror(-ret)); | |
1628 | /* Continue without vendor events */ | |
1629 | } | |
1630 | ||
d6c9aab8 JB |
1631 | nl_cb_set(global->nl_cb, NL_CB_SEQ_CHECK, NL_CB_CUSTOM, |
1632 | no_seq_check, NULL); | |
1633 | nl_cb_set(global->nl_cb, NL_CB_VALID, NL_CB_CUSTOM, | |
1634 | process_global_event, global); | |
1635 | ||
5f65e9f7 JB |
1636 | nl80211_register_eloop_read(&global->nl_event, |
1637 | wpa_driver_nl80211_event_receive, | |
40a68f33 | 1638 | global->nl_cb, 0); |
d6c9aab8 JB |
1639 | |
1640 | return 0; | |
1641 | ||
1642 | err: | |
1643 | nl_destroy_handles(&global->nl_event); | |
1644 | nl_destroy_handles(&global->nl); | |
1645 | nl_cb_put(global->nl_cb); | |
671a5039 | 1646 | global->nl_cb = NULL; |
d6c9aab8 JB |
1647 | return -1; |
1648 | } | |
1649 | ||
1650 | ||
f51f54a0 JM |
1651 | static void nl80211_check_global(struct nl80211_global *global) |
1652 | { | |
1653 | struct nl_handle *handle; | |
1654 | const char *groups[] = { "scan", "mlme", "regulatory", "vendor", NULL }; | |
1655 | int ret; | |
1656 | unsigned int i; | |
1657 | ||
1658 | /* | |
1659 | * Try to re-add memberships to handle case of cfg80211 getting reloaded | |
1660 | * and all registration having been cleared. | |
1661 | */ | |
1662 | handle = (void *) (((intptr_t) global->nl_event) ^ | |
1663 | ELOOP_SOCKET_INVALID); | |
1664 | ||
1665 | for (i = 0; groups[i]; i++) { | |
1666 | ret = nl_get_multicast_id(global, "nl80211", groups[i]); | |
1667 | if (ret >= 0) | |
1668 | ret = nl_socket_add_membership(handle, ret); | |
1669 | if (ret < 0) { | |
1670 | wpa_printf(MSG_INFO, | |
1671 | "nl80211: Could not re-add multicast membership for %s events: %d (%s)", | |
1672 | groups[i], ret, strerror(-ret)); | |
1673 | } | |
1674 | } | |
1675 | } | |
1676 | ||
1677 | ||
8401a6b0 JM |
1678 | static void wpa_driver_nl80211_rfkill_blocked(void *ctx) |
1679 | { | |
6da504a1 IP |
1680 | struct wpa_driver_nl80211_data *drv = ctx; |
1681 | ||
8401a6b0 | 1682 | wpa_printf(MSG_DEBUG, "nl80211: RFKILL blocked"); |
6da504a1 | 1683 | |
a63063b4 | 1684 | /* |
6da504a1 IP |
1685 | * rtnetlink ifdown handler will report interfaces other than the P2P |
1686 | * Device interface as disabled. | |
a63063b4 | 1687 | */ |
6da504a1 IP |
1688 | if (drv->nlmode == NL80211_IFTYPE_P2P_DEVICE) |
1689 | wpa_supplicant_event(drv->ctx, EVENT_INTERFACE_DISABLED, NULL); | |
8401a6b0 JM |
1690 | } |
1691 | ||
1692 | ||
1693 | static void wpa_driver_nl80211_rfkill_unblocked(void *ctx) | |
1694 | { | |
1695 | struct wpa_driver_nl80211_data *drv = ctx; | |
1696 | wpa_printf(MSG_DEBUG, "nl80211: RFKILL unblocked"); | |
834ee56f | 1697 | if (i802_set_iface_flags(drv->first_bss, 1)) { |
8401a6b0 JM |
1698 | wpa_printf(MSG_DEBUG, "nl80211: Could not set interface UP " |
1699 | "after rfkill unblock"); | |
1700 | return; | |
1701 | } | |
e8dc205f AO |
1702 | |
1703 | if (is_p2p_net_interface(drv->nlmode)) | |
1704 | nl80211_disable_11b_rates(drv, drv->ifindex, 1); | |
1705 | ||
6da504a1 IP |
1706 | /* |
1707 | * rtnetlink ifup handler will report interfaces other than the P2P | |
1708 | * Device interface as enabled. | |
1709 | */ | |
1710 | if (drv->nlmode == NL80211_IFTYPE_P2P_DEVICE) | |
1711 | wpa_supplicant_event(drv->ctx, EVENT_INTERFACE_ENABLED, NULL); | |
8401a6b0 JM |
1712 | } |
1713 | ||
1714 | ||
32ab4855 JB |
1715 | static void wpa_driver_nl80211_handle_eapol_tx_status(int sock, |
1716 | void *eloop_ctx, | |
1717 | void *handle) | |
1718 | { | |
1719 | struct wpa_driver_nl80211_data *drv = eloop_ctx; | |
1720 | u8 data[2048]; | |
1721 | struct msghdr msg; | |
1722 | struct iovec entry; | |
cad0f50e | 1723 | u8 control[512]; |
32ab4855 JB |
1724 | struct cmsghdr *cmsg; |
1725 | int res, found_ee = 0, found_wifi = 0, acked = 0; | |
1726 | union wpa_event_data event; | |
1727 | ||
1728 | memset(&msg, 0, sizeof(msg)); | |
1729 | msg.msg_iov = &entry; | |
1730 | msg.msg_iovlen = 1; | |
1731 | entry.iov_base = data; | |
1732 | entry.iov_len = sizeof(data); | |
1733 | msg.msg_control = &control; | |
1734 | msg.msg_controllen = sizeof(control); | |
1735 | ||
1736 | res = recvmsg(sock, &msg, MSG_ERRQUEUE); | |
1737 | /* if error or not fitting 802.3 header, return */ | |
1738 | if (res < 14) | |
1739 | return; | |
1740 | ||
1741 | for (cmsg = CMSG_FIRSTHDR(&msg); cmsg; cmsg = CMSG_NXTHDR(&msg, cmsg)) | |
1742 | { | |
1743 | if (cmsg->cmsg_level == SOL_SOCKET && | |
1744 | cmsg->cmsg_type == SCM_WIFI_STATUS) { | |
1745 | int *ack; | |
1746 | ||
1747 | found_wifi = 1; | |
1748 | ack = (void *)CMSG_DATA(cmsg); | |
1749 | acked = *ack; | |
1750 | } | |
1751 | ||
1752 | if (cmsg->cmsg_level == SOL_PACKET && | |
1753 | cmsg->cmsg_type == PACKET_TX_TIMESTAMP) { | |
1754 | struct sock_extended_err *err = | |
1755 | (struct sock_extended_err *)CMSG_DATA(cmsg); | |
1756 | ||
1757 | if (err->ee_origin == SO_EE_ORIGIN_TXSTATUS) | |
1758 | found_ee = 1; | |
1759 | } | |
1760 | } | |
1761 | ||
1762 | if (!found_ee || !found_wifi) | |
1763 | return; | |
1764 | ||
1765 | memset(&event, 0, sizeof(event)); | |
1766 | event.eapol_tx_status.dst = data; | |
1767 | event.eapol_tx_status.data = data + 14; | |
1768 | event.eapol_tx_status.data_len = res - 14; | |
1769 | event.eapol_tx_status.ack = acked; | |
1770 | wpa_supplicant_event(drv->ctx, EVENT_EAPOL_TX_STATUS, &event); | |
1771 | } | |
1772 | ||
1773 | ||
cc7a48d1 JB |
1774 | static int nl80211_init_bss(struct i802_bss *bss) |
1775 | { | |
1776 | bss->nl_cb = nl_cb_alloc(NL_CB_DEFAULT); | |
1777 | if (!bss->nl_cb) | |
1778 | return -1; | |
1779 | ||
1780 | nl_cb_set(bss->nl_cb, NL_CB_SEQ_CHECK, NL_CB_CUSTOM, | |
1781 | no_seq_check, NULL); | |
1782 | nl_cb_set(bss->nl_cb, NL_CB_VALID, NL_CB_CUSTOM, | |
1783 | process_bss_event, bss); | |
1784 | ||
1785 | return 0; | |
1786 | } | |
1787 | ||
1788 | ||
1789 | static void nl80211_destroy_bss(struct i802_bss *bss) | |
1790 | { | |
1791 | nl_cb_put(bss->nl_cb); | |
1792 | bss->nl_cb = NULL; | |
1793 | } | |
1794 | ||
1795 | ||
0e92fb8f JB |
1796 | static void |
1797 | wpa_driver_nl80211_drv_init_rfkill(struct wpa_driver_nl80211_data *drv) | |
1798 | { | |
1799 | struct rfkill_config *rcfg; | |
1800 | ||
1801 | if (drv->rfkill) | |
1802 | return; | |
1803 | ||
1804 | rcfg = os_zalloc(sizeof(*rcfg)); | |
1805 | if (!rcfg) | |
1806 | return; | |
1807 | ||
1808 | rcfg->ctx = drv; | |
1809 | ||
1810 | /* rfkill uses netdev sysfs for initialization. However, P2P Device is | |
1811 | * not associated with a netdev, so use the name of some other interface | |
1812 | * sharing the same wiphy as the P2P Device interface. | |
1813 | * | |
1814 | * Note: This is valid, as a P2P Device interface is always dynamically | |
1815 | * created and is created only once another wpa_s interface was added. | |
1816 | */ | |
1817 | if (drv->nlmode == NL80211_IFTYPE_P2P_DEVICE) { | |
1818 | struct nl80211_global *global = drv->global; | |
1819 | struct wpa_driver_nl80211_data *tmp1; | |
1820 | ||
1821 | dl_list_for_each(tmp1, &global->interfaces, | |
1822 | struct wpa_driver_nl80211_data, list) { | |
1823 | if (drv == tmp1 || drv->wiphy_idx != tmp1->wiphy_idx || | |
1824 | !tmp1->rfkill) | |
1825 | continue; | |
1826 | ||
1827 | wpa_printf(MSG_DEBUG, | |
1828 | "nl80211: Use (%s) to initialize P2P Device rfkill", | |
1829 | tmp1->first_bss->ifname); | |
1830 | os_strlcpy(rcfg->ifname, tmp1->first_bss->ifname, | |
1831 | sizeof(rcfg->ifname)); | |
1832 | break; | |
1833 | } | |
1834 | } else { | |
1835 | os_strlcpy(rcfg->ifname, drv->first_bss->ifname, | |
1836 | sizeof(rcfg->ifname)); | |
1837 | } | |
1838 | ||
1839 | rcfg->blocked_cb = wpa_driver_nl80211_rfkill_blocked; | |
1840 | rcfg->unblocked_cb = wpa_driver_nl80211_rfkill_unblocked; | |
1841 | drv->rfkill = rfkill_init(rcfg); | |
1842 | if (!drv->rfkill) { | |
1843 | wpa_printf(MSG_DEBUG, "nl80211: RFKILL status not available"); | |
1844 | os_free(rcfg); | |
1845 | } | |
1846 | } | |
1847 | ||
1848 | ||
0d547d5f JM |
1849 | static void * wpa_driver_nl80211_drv_init(void *ctx, const char *ifname, |
1850 | void *global_priv, int hostapd, | |
0ecff8d7 JM |
1851 | const u8 *set_addr, |
1852 | const char *driver_params) | |
9fff9fdc | 1853 | { |
9fff9fdc | 1854 | struct wpa_driver_nl80211_data *drv; |
a2e40bb6 | 1855 | struct i802_bss *bss; |
9fff9fdc | 1856 | |
a5c696ad JM |
1857 | if (global_priv == NULL) |
1858 | return NULL; | |
9fff9fdc JM |
1859 | drv = os_zalloc(sizeof(*drv)); |
1860 | if (drv == NULL) | |
1861 | return NULL; | |
f2ed8023 | 1862 | drv->global = global_priv; |
9fff9fdc | 1863 | drv->ctx = ctx; |
0d547d5f JM |
1864 | drv->hostapd = !!hostapd; |
1865 | drv->eapol_sock = -1; | |
64ae2447 JM |
1866 | |
1867 | /* | |
1868 | * There is no driver capability flag for this, so assume it is | |
1869 | * supported and disable this on first attempt to use if the driver | |
1870 | * rejects the command due to missing support. | |
1871 | */ | |
1872 | drv->set_rekey_offload = 1; | |
1873 | ||
0d547d5f JM |
1874 | drv->num_if_indices = sizeof(drv->default_if_indices) / sizeof(int); |
1875 | drv->if_indices = drv->default_if_indices; | |
732b1d20 | 1876 | drv->if_indices_reason = drv->default_if_indices_reason; |
834ee56f KP |
1877 | |
1878 | drv->first_bss = os_zalloc(sizeof(*drv->first_bss)); | |
1879 | if (!drv->first_bss) { | |
1880 | os_free(drv); | |
1881 | return NULL; | |
1882 | } | |
1883 | bss = drv->first_bss; | |
a2e40bb6 | 1884 | bss->drv = drv; |
a5e1eb20 SE |
1885 | bss->ctx = ctx; |
1886 | ||
a2e40bb6 | 1887 | os_strlcpy(bss->ifname, ifname, sizeof(bss->ifname)); |
9fff9fdc JM |
1888 | drv->monitor_ifidx = -1; |
1889 | drv->monitor_sock = -1; | |
d12dab4c | 1890 | drv->eapol_tx_sock = -1; |
b1f625e0 | 1891 | drv->ap_scan_as_station = NL80211_IFTYPE_UNSPECIFIED; |
9fff9fdc | 1892 | |
cc7a48d1 JB |
1893 | if (nl80211_init_bss(bss)) |
1894 | goto failed; | |
1895 | ||
0ecff8d7 | 1896 | if (wpa_driver_nl80211_finish_drv_init(drv, set_addr, 1, driver_params)) |
bbaf0837 | 1897 | goto failed; |
7524cfb1 | 1898 | |
d12dab4c | 1899 | drv->eapol_tx_sock = socket(PF_PACKET, SOCK_DGRAM, 0); |
32ab4855 JB |
1900 | if (drv->eapol_tx_sock < 0) |
1901 | goto failed; | |
1902 | ||
1903 | if (drv->data_tx_status) { | |
1904 | int enabled = 1; | |
1905 | ||
1906 | if (setsockopt(drv->eapol_tx_sock, SOL_SOCKET, SO_WIFI_STATUS, | |
1907 | &enabled, sizeof(enabled)) < 0) { | |
1908 | wpa_printf(MSG_DEBUG, | |
1909 | "nl80211: wifi status sockopt failed\n"); | |
1910 | drv->data_tx_status = 0; | |
a11241fa JB |
1911 | if (!drv->use_monitor) |
1912 | drv->capa.flags &= | |
1913 | ~WPA_DRIVER_FLAGS_EAPOL_TX_STATUS; | |
32ab4855 JB |
1914 | } else { |
1915 | eloop_register_read_sock(drv->eapol_tx_sock, | |
1916 | wpa_driver_nl80211_handle_eapol_tx_status, | |
1917 | drv, NULL); | |
1918 | } | |
1919 | } | |
f10bfc9a | 1920 | |
dac12351 | 1921 | if (drv->global) { |
f51f54a0 | 1922 | nl80211_check_global(drv->global); |
c4bb8817 | 1923 | dl_list_add(&drv->global->interfaces, &drv->list); |
dac12351 BG |
1924 | drv->in_interface_list = 1; |
1925 | } | |
c4bb8817 | 1926 | |
a2e40bb6 | 1927 | return bss; |
7524cfb1 | 1928 | |
bbaf0837 | 1929 | failed: |
dac12351 | 1930 | wpa_driver_nl80211_deinit(bss); |
7524cfb1 JM |
1931 | return NULL; |
1932 | } | |
1933 | ||
1934 | ||
0d547d5f JM |
1935 | /** |
1936 | * wpa_driver_nl80211_init - Initialize nl80211 driver interface | |
1937 | * @ctx: context to be used when calling wpa_supplicant functions, | |
1938 | * e.g., wpa_supplicant_event() | |
1939 | * @ifname: interface name, e.g., wlan0 | |
1940 | * @global_priv: private driver global data from global_init() | |
1941 | * Returns: Pointer to private data, %NULL on failure | |
1942 | */ | |
1943 | static void * wpa_driver_nl80211_init(void *ctx, const char *ifname, | |
1944 | void *global_priv) | |
1945 | { | |
0ecff8d7 JM |
1946 | return wpa_driver_nl80211_drv_init(ctx, ifname, global_priv, 0, NULL, |
1947 | NULL); | |
0d547d5f JM |
1948 | } |
1949 | ||
1950 | ||
a11241fa | 1951 | static int nl80211_register_frame(struct i802_bss *bss, |
5582a5d1 | 1952 | struct nl_handle *nl_handle, |
bd94971e | 1953 | u16 type, const u8 *match, size_t match_len) |
58f6fbe0 | 1954 | { |
a11241fa | 1955 | struct wpa_driver_nl80211_data *drv = bss->drv; |
58f6fbe0 | 1956 | struct nl_msg *msg; |
a862e4a3 | 1957 | int ret; |
880de885 | 1958 | char buf[30]; |
58f6fbe0 | 1959 | |
880de885 JM |
1960 | buf[0] = '\0'; |
1961 | wpa_snprintf_hex(buf, sizeof(buf), match, match_len); | |
dedfa440 PF |
1962 | wpa_printf(MSG_DEBUG, "nl80211: Register frame type=0x%x (%s) nl_handle=%p match=%s", |
1963 | type, fc2str(type), nl_handle, buf); | |
36488c05 | 1964 | |
56f77852 | 1965 | if (!(msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_REGISTER_ACTION)) || |
a862e4a3 JM |
1966 | nla_put_u16(msg, NL80211_ATTR_FRAME_TYPE, type) || |
1967 | nla_put(msg, NL80211_ATTR_FRAME_MATCH, match_len, match)) { | |
1968 | nlmsg_free(msg); | |
1969 | return -1; | |
1970 | } | |
58f6fbe0 | 1971 | |
d6c9aab8 | 1972 | ret = send_and_recv(drv->global, nl_handle, msg, NULL, NULL); |
58f6fbe0 | 1973 | if (ret) { |
5582a5d1 JB |
1974 | wpa_printf(MSG_DEBUG, "nl80211: Register frame command " |
1975 | "failed (type=%u): ret=%d (%s)", | |
1976 | type, ret, strerror(-ret)); | |
1977 | wpa_hexdump(MSG_DEBUG, "nl80211: Register frame match", | |
58f6fbe0 | 1978 | match, match_len); |
58f6fbe0 | 1979 | } |
58f6fbe0 JM |
1980 | return ret; |
1981 | } | |
1982 | ||
1983 | ||
a11241fa JB |
1984 | static int nl80211_alloc_mgmt_handle(struct i802_bss *bss) |
1985 | { | |
481234cf | 1986 | if (bss->nl_mgmt) { |
a11241fa | 1987 | wpa_printf(MSG_DEBUG, "nl80211: Mgmt reporting " |
36488c05 | 1988 | "already on! (nl_mgmt=%p)", bss->nl_mgmt); |
a11241fa JB |
1989 | return -1; |
1990 | } | |
1991 | ||
ce20a370 | 1992 | bss->nl_mgmt = nl_create_handle(bss->nl_cb, "mgmt"); |
481234cf | 1993 | if (bss->nl_mgmt == NULL) |
a11241fa JB |
1994 | return -1; |
1995 | ||
a11241fa JB |
1996 | return 0; |
1997 | } | |
1998 | ||
1999 | ||
5f65e9f7 JB |
2000 | static void nl80211_mgmt_handle_register_eloop(struct i802_bss *bss) |
2001 | { | |
2002 | nl80211_register_eloop_read(&bss->nl_mgmt, | |
2003 | wpa_driver_nl80211_event_receive, | |
40a68f33 | 2004 | bss->nl_cb, 0); |
5f65e9f7 JB |
2005 | } |
2006 | ||
2007 | ||
a11241fa | 2008 | static int nl80211_register_action_frame(struct i802_bss *bss, |
bd94971e JB |
2009 | const u8 *match, size_t match_len) |
2010 | { | |
2011 | u16 type = (WLAN_FC_TYPE_MGMT << 2) | (WLAN_FC_STYPE_ACTION << 4); | |
481234cf | 2012 | return nl80211_register_frame(bss, bss->nl_mgmt, |
5582a5d1 | 2013 | type, match, match_len); |
bd94971e JB |
2014 | } |
2015 | ||
2016 | ||
40a68f33 SD |
2017 | static int nl80211_init_connect_handle(struct i802_bss *bss) |
2018 | { | |
2019 | if (bss->nl_connect) { | |
2020 | wpa_printf(MSG_DEBUG, | |
2021 | "nl80211: Connect handle already created (nl_connect=%p)", | |
2022 | bss->nl_connect); | |
2023 | return -1; | |
2024 | } | |
2025 | ||
2026 | bss->nl_connect = nl_create_handle(bss->nl_cb, "connect"); | |
2027 | if (!bss->nl_connect) | |
2028 | return -1; | |
2029 | nl80211_register_eloop_read(&bss->nl_connect, | |
2030 | wpa_driver_nl80211_event_receive, | |
2031 | bss->nl_cb, 1); | |
2032 | return 0; | |
2033 | } | |
2034 | ||
2035 | ||
a11241fa | 2036 | static int nl80211_mgmt_subscribe_non_ap(struct i802_bss *bss) |
58f6fbe0 | 2037 | { |
a11241fa | 2038 | struct wpa_driver_nl80211_data *drv = bss->drv; |
6f06766e | 2039 | int ret = 0; |
a11241fa JB |
2040 | |
2041 | if (nl80211_alloc_mgmt_handle(bss)) | |
2042 | return -1; | |
36488c05 JM |
2043 | wpa_printf(MSG_DEBUG, "nl80211: Subscribe to mgmt frames with non-AP " |
2044 | "handle %p", bss->nl_mgmt); | |
a11241fa | 2045 | |
ba71cb82 SD |
2046 | if (drv->nlmode == NL80211_IFTYPE_ADHOC || |
2047 | ((drv->capa.flags & WPA_DRIVER_FLAGS_SAE) && | |
2048 | !(drv->capa.flags & WPA_DRIVER_FLAGS_SME))) { | |
e8d1168b JB |
2049 | u16 type = (WLAN_FC_TYPE_MGMT << 2) | (WLAN_FC_STYPE_AUTH << 4); |
2050 | ||
2051 | /* register for any AUTH message */ | |
2052 | nl80211_register_frame(bss, bss->nl_mgmt, type, NULL, 0); | |
2053 | } | |
2054 | ||
56f5af48 JM |
2055 | #ifdef CONFIG_INTERWORKING |
2056 | /* QoS Map Configure */ | |
2057 | if (nl80211_register_action_frame(bss, (u8 *) "\x01\x04", 2) < 0) | |
6f06766e | 2058 | ret = -1; |
56f5af48 | 2059 | #endif /* CONFIG_INTERWORKING */ |
00b02149 | 2060 | #if defined(CONFIG_P2P) || defined(CONFIG_INTERWORKING) || defined(CONFIG_DPP) |
046b26a2 | 2061 | /* GAS Initial Request */ |
a11241fa | 2062 | if (nl80211_register_action_frame(bss, (u8 *) "\x04\x0a", 2) < 0) |
6f06766e | 2063 | ret = -1; |
046b26a2 | 2064 | /* GAS Initial Response */ |
a11241fa | 2065 | if (nl80211_register_action_frame(bss, (u8 *) "\x04\x0b", 2) < 0) |
6f06766e | 2066 | ret = -1; |
18708aad | 2067 | /* GAS Comeback Request */ |
a11241fa | 2068 | if (nl80211_register_action_frame(bss, (u8 *) "\x04\x0c", 2) < 0) |
6f06766e | 2069 | ret = -1; |
18708aad | 2070 | /* GAS Comeback Response */ |
a11241fa | 2071 | if (nl80211_register_action_frame(bss, (u8 *) "\x04\x0d", 2) < 0) |
6f06766e | 2072 | ret = -1; |
c5a64e2d JM |
2073 | /* Protected GAS Initial Request */ |
2074 | if (nl80211_register_action_frame(bss, (u8 *) "\x09\x0a", 2) < 0) | |
2075 | ret = -1; | |
2076 | /* Protected GAS Initial Response */ | |
2077 | if (nl80211_register_action_frame(bss, (u8 *) "\x09\x0b", 2) < 0) | |
2078 | ret = -1; | |
2079 | /* Protected GAS Comeback Request */ | |
2080 | if (nl80211_register_action_frame(bss, (u8 *) "\x09\x0c", 2) < 0) | |
2081 | ret = -1; | |
2082 | /* Protected GAS Comeback Response */ | |
2083 | if (nl80211_register_action_frame(bss, (u8 *) "\x09\x0d", 2) < 0) | |
2084 | ret = -1; | |
00b02149 | 2085 | #endif /* CONFIG_P2P || CONFIG_INTERWORKING || CONFIG_DPP */ |
4fe9fa0d | 2086 | #ifdef CONFIG_P2P |
046b26a2 | 2087 | /* P2P Public Action */ |
a11241fa | 2088 | if (nl80211_register_action_frame(bss, |
046b26a2 JM |
2089 | (u8 *) "\x04\x09\x50\x6f\x9a\x09", |
2090 | 6) < 0) | |
6f06766e | 2091 | ret = -1; |
046b26a2 | 2092 | /* P2P Action */ |
a11241fa | 2093 | if (nl80211_register_action_frame(bss, |
046b26a2 JM |
2094 | (u8 *) "\x7f\x50\x6f\x9a\x09", |
2095 | 5) < 0) | |
6f06766e | 2096 | ret = -1; |
046b26a2 | 2097 | #endif /* CONFIG_P2P */ |
00b02149 JM |
2098 | #ifdef CONFIG_DPP |
2099 | /* DPP Public Action */ | |
2100 | if (nl80211_register_action_frame(bss, | |
2101 | (u8 *) "\x04\x09\x50\x6f\x9a\x1a", | |
2102 | 6) < 0) | |
2103 | ret = -1; | |
2104 | #endif /* CONFIG_DPP */ | |
7d878ca7 JM |
2105 | #ifdef CONFIG_IEEE80211W |
2106 | /* SA Query Response */ | |
a11241fa | 2107 | if (nl80211_register_action_frame(bss, (u8 *) "\x08\x01", 2) < 0) |
6f06766e | 2108 | ret = -1; |
7d878ca7 | 2109 | #endif /* CONFIG_IEEE80211W */ |
35287637 AN |
2110 | #ifdef CONFIG_TDLS |
2111 | if ((drv->capa.flags & WPA_DRIVER_FLAGS_TDLS_SUPPORT)) { | |
2112 | /* TDLS Discovery Response */ | |
aa543c0c | 2113 | if (nl80211_register_action_frame(bss, (u8 *) "\x04\x0e", 2) < |
35287637 | 2114 | 0) |
6f06766e | 2115 | ret = -1; |
35287637 AN |
2116 | } |
2117 | #endif /* CONFIG_TDLS */ | |
46ab9b8c AN |
2118 | #ifdef CONFIG_FST |
2119 | /* FST Action frames */ | |
2120 | if (nl80211_register_action_frame(bss, (u8 *) "\x12", 1) < 0) | |
2121 | ret = -1; | |
2122 | #endif /* CONFIG_FST */ | |
046b26a2 | 2123 | |
7b90c16a | 2124 | /* FT Action frames */ |
a11241fa | 2125 | if (nl80211_register_action_frame(bss, (u8 *) "\x06", 1) < 0) |
6f06766e | 2126 | ret = -1; |
7b90c16a JM |
2127 | else |
2128 | drv->capa.key_mgmt |= WPA_DRIVER_CAPA_KEY_MGMT_FT | | |
2129 | WPA_DRIVER_CAPA_KEY_MGMT_FT_PSK; | |
2130 | ||
71269b37 | 2131 | /* WNM - BSS Transition Management Request */ |
a11241fa | 2132 | if (nl80211_register_action_frame(bss, (u8 *) "\x0a\x07", 2) < 0) |
6f06766e | 2133 | ret = -1; |
bd896433 JM |
2134 | /* WNM-Sleep Mode Response */ |
2135 | if (nl80211_register_action_frame(bss, (u8 *) "\x0a\x11", 2) < 0) | |
6f06766e | 2136 | ret = -1; |
a11241fa | 2137 | |
95a3ea94 JM |
2138 | #ifdef CONFIG_HS20 |
2139 | /* WNM-Notification */ | |
2140 | if (nl80211_register_action_frame(bss, (u8 *) "\x0a\x1a", 2) < 0) | |
3ee18569 | 2141 | ret = -1; |
95a3ea94 JM |
2142 | #endif /* CONFIG_HS20 */ |
2143 | ||
dfa87878 MB |
2144 | /* WMM-AC ADDTS Response */ |
2145 | if (nl80211_register_action_frame(bss, (u8 *) "\x11\x01", 2) < 0) | |
730a0d16 | 2146 | ret = -1; |
dfa87878 MB |
2147 | |
2148 | /* WMM-AC DELTS */ | |
2149 | if (nl80211_register_action_frame(bss, (u8 *) "\x11\x02", 2) < 0) | |
730a0d16 | 2150 | ret = -1; |
dfa87878 | 2151 | |
2526ccd9 AK |
2152 | /* Radio Measurement - Neighbor Report Response */ |
2153 | if (nl80211_register_action_frame(bss, (u8 *) "\x05\x05", 2) < 0) | |
2154 | ret = -1; | |
2155 | ||
864b9522 DS |
2156 | /* Radio Measurement - Radio Measurement Request */ |
2157 | if (nl80211_register_action_frame(bss, (u8 *) "\x05\x00", 2) < 0) | |
2158 | ret = -1; | |
2159 | ||
7dc03388 AO |
2160 | /* Radio Measurement - Link Measurement Request */ |
2161 | if ((drv->capa.rrm_flags & WPA_DRIVER_FLAGS_TX_POWER_INSERTION) && | |
2162 | (nl80211_register_action_frame(bss, (u8 *) "\x05\x02", 2) < 0)) | |
2163 | ret = -1; | |
2164 | ||
5f65e9f7 JB |
2165 | nl80211_mgmt_handle_register_eloop(bss); |
2166 | ||
6f06766e | 2167 | return ret; |
a11241fa JB |
2168 | } |
2169 | ||
2170 | ||
afb0550a BC |
2171 | static int nl80211_mgmt_subscribe_mesh(struct i802_bss *bss) |
2172 | { | |
2173 | int ret = 0; | |
2174 | ||
2175 | if (nl80211_alloc_mgmt_handle(bss)) | |
2176 | return -1; | |
2177 | ||
2178 | wpa_printf(MSG_DEBUG, | |
2179 | "nl80211: Subscribe to mgmt frames with mesh handle %p", | |
2180 | bss->nl_mgmt); | |
2181 | ||
2182 | /* Auth frames for mesh SAE */ | |
2183 | if (nl80211_register_frame(bss, bss->nl_mgmt, | |
2184 | (WLAN_FC_TYPE_MGMT << 2) | | |
2185 | (WLAN_FC_STYPE_AUTH << 4), | |
2186 | NULL, 0) < 0) | |
2187 | ret = -1; | |
2188 | ||
2189 | /* Mesh peering open */ | |
2190 | if (nl80211_register_action_frame(bss, (u8 *) "\x0f\x01", 2) < 0) | |
2191 | ret = -1; | |
2192 | /* Mesh peering confirm */ | |
2193 | if (nl80211_register_action_frame(bss, (u8 *) "\x0f\x02", 2) < 0) | |
2194 | ret = -1; | |
2195 | /* Mesh peering close */ | |
2196 | if (nl80211_register_action_frame(bss, (u8 *) "\x0f\x03", 2) < 0) | |
2197 | ret = -1; | |
2198 | ||
2199 | nl80211_mgmt_handle_register_eloop(bss); | |
2200 | ||
2201 | return ret; | |
2202 | } | |
2203 | ||
2204 | ||
02bb32c3 JB |
2205 | static int nl80211_register_spurious_class3(struct i802_bss *bss) |
2206 | { | |
02bb32c3 | 2207 | struct nl_msg *msg; |
a862e4a3 | 2208 | int ret; |
02bb32c3 | 2209 | |
13f83980 JM |
2210 | msg = nl80211_bss_msg(bss, 0, NL80211_CMD_UNEXPECTED_FRAME); |
2211 | ret = send_and_recv(bss->drv->global, bss->nl_mgmt, msg, NULL, NULL); | |
02bb32c3 JB |
2212 | if (ret) { |
2213 | wpa_printf(MSG_DEBUG, "nl80211: Register spurious class3 " | |
2214 | "failed: ret=%d (%s)", | |
2215 | ret, strerror(-ret)); | |
02bb32c3 | 2216 | } |
02bb32c3 JB |
2217 | return ret; |
2218 | } | |
2219 | ||
2220 | ||
4d916ed6 KV |
2221 | static int nl80211_action_subscribe_ap(struct i802_bss *bss) |
2222 | { | |
2223 | int ret = 0; | |
2224 | ||
2225 | /* Public Action frames */ | |
2226 | if (nl80211_register_action_frame(bss, (u8 *) "\x04", 1) < 0) | |
2227 | ret = -1; | |
2228 | /* RRM Measurement Report */ | |
2229 | if (nl80211_register_action_frame(bss, (u8 *) "\x05\x01", 2) < 0) | |
2230 | ret = -1; | |
e4ec6bbf JM |
2231 | /* RRM Link Measurement Report */ |
2232 | if (nl80211_register_action_frame(bss, (u8 *) "\x05\x03", 2) < 0) | |
2233 | ret = -1; | |
4d916ed6 KV |
2234 | /* RRM Neighbor Report Request */ |
2235 | if (nl80211_register_action_frame(bss, (u8 *) "\x05\x04", 2) < 0) | |
2236 | ret = -1; | |
2237 | /* FT Action frames */ | |
2238 | if (nl80211_register_action_frame(bss, (u8 *) "\x06", 1) < 0) | |
2239 | ret = -1; | |
2240 | #ifdef CONFIG_IEEE80211W | |
2241 | /* SA Query */ | |
2242 | if (nl80211_register_action_frame(bss, (u8 *) "\x08", 1) < 0) | |
2243 | ret = -1; | |
2244 | #endif /* CONFIG_IEEE80211W */ | |
2245 | /* Protected Dual of Public Action */ | |
2246 | if (nl80211_register_action_frame(bss, (u8 *) "\x09", 1) < 0) | |
2247 | ret = -1; | |
2248 | /* WNM */ | |
2249 | if (nl80211_register_action_frame(bss, (u8 *) "\x0a", 1) < 0) | |
2250 | ret = -1; | |
2251 | /* WMM */ | |
2252 | if (nl80211_register_action_frame(bss, (u8 *) "\x11", 1) < 0) | |
2253 | ret = -1; | |
2254 | #ifdef CONFIG_FST | |
2255 | /* FST Action frames */ | |
2256 | if (nl80211_register_action_frame(bss, (u8 *) "\x12", 1) < 0) | |
2257 | ret = -1; | |
2258 | #endif /* CONFIG_FST */ | |
2259 | /* Vendor-specific */ | |
2260 | if (nl80211_register_action_frame(bss, (u8 *) "\x7f", 1) < 0) | |
2261 | ret = -1; | |
2262 | ||
2263 | return ret; | |
2264 | } | |
2265 | ||
2266 | ||
a11241fa JB |
2267 | static int nl80211_mgmt_subscribe_ap(struct i802_bss *bss) |
2268 | { | |
2269 | static const int stypes[] = { | |
2270 | WLAN_FC_STYPE_AUTH, | |
2271 | WLAN_FC_STYPE_ASSOC_REQ, | |
2272 | WLAN_FC_STYPE_REASSOC_REQ, | |
2273 | WLAN_FC_STYPE_DISASSOC, | |
2274 | WLAN_FC_STYPE_DEAUTH, | |
a11241fa JB |
2275 | WLAN_FC_STYPE_PROBE_REQ, |
2276 | /* Beacon doesn't work as mac80211 doesn't currently allow | |
2277 | * it, but it wouldn't really be the right thing anyway as | |
2278 | * it isn't per interface ... maybe just dump the scan | |
2279 | * results periodically for OLBC? | |
2280 | */ | |
0e80ea2c | 2281 | /* WLAN_FC_STYPE_BEACON, */ |
a11241fa JB |
2282 | }; |
2283 | unsigned int i; | |
2284 | ||
2285 | if (nl80211_alloc_mgmt_handle(bss)) | |
71269b37 | 2286 | return -1; |
36488c05 JM |
2287 | wpa_printf(MSG_DEBUG, "nl80211: Subscribe to mgmt frames with AP " |
2288 | "handle %p", bss->nl_mgmt); | |
71269b37 | 2289 | |
e7ecab4a | 2290 | for (i = 0; i < ARRAY_SIZE(stypes); i++) { |
481234cf | 2291 | if (nl80211_register_frame(bss, bss->nl_mgmt, |
a11241fa JB |
2292 | (WLAN_FC_TYPE_MGMT << 2) | |
2293 | (stypes[i] << 4), | |
2294 | NULL, 0) < 0) { | |
2295 | goto out_err; | |
2296 | } | |
2297 | } | |
2298 | ||
4d916ed6 KV |
2299 | if (nl80211_action_subscribe_ap(bss)) |
2300 | goto out_err; | |
2301 | ||
02bb32c3 JB |
2302 | if (nl80211_register_spurious_class3(bss)) |
2303 | goto out_err; | |
2304 | ||
5f65e9f7 | 2305 | nl80211_mgmt_handle_register_eloop(bss); |
58f6fbe0 | 2306 | return 0; |
a11241fa JB |
2307 | |
2308 | out_err: | |
a11241fa JB |
2309 | nl_destroy_handles(&bss->nl_mgmt); |
2310 | return -1; | |
2311 | } | |
2312 | ||
2313 | ||
a6cc0602 JM |
2314 | static int nl80211_mgmt_subscribe_ap_dev_sme(struct i802_bss *bss) |
2315 | { | |
2316 | if (nl80211_alloc_mgmt_handle(bss)) | |
2317 | return -1; | |
2318 | wpa_printf(MSG_DEBUG, "nl80211: Subscribe to mgmt frames with AP " | |
2319 | "handle %p (device SME)", bss->nl_mgmt); | |
2320 | ||
4d916ed6 | 2321 | if (nl80211_action_subscribe_ap(bss)) |
a6cc0602 JM |
2322 | goto out_err; |
2323 | ||
5f65e9f7 | 2324 | nl80211_mgmt_handle_register_eloop(bss); |
a6cc0602 JM |
2325 | return 0; |
2326 | ||
2327 | out_err: | |
a6cc0602 JM |
2328 | nl_destroy_handles(&bss->nl_mgmt); |
2329 | return -1; | |
2330 | } | |
2331 | ||
2332 | ||
36488c05 | 2333 | static void nl80211_mgmt_unsubscribe(struct i802_bss *bss, const char *reason) |
a11241fa | 2334 | { |
481234cf | 2335 | if (bss->nl_mgmt == NULL) |
a11241fa | 2336 | return; |
36488c05 JM |
2337 | wpa_printf(MSG_DEBUG, "nl80211: Unsubscribe mgmt frames handle %p " |
2338 | "(%s)", bss->nl_mgmt, reason); | |
40a68f33 | 2339 | nl80211_destroy_eloop_handle(&bss->nl_mgmt, 0); |
7813b7c3 MH |
2340 | |
2341 | nl80211_put_wiphy_data_ap(bss); | |
58f6fbe0 JM |
2342 | } |
2343 | ||
2344 | ||
8401a6b0 JM |
2345 | static void wpa_driver_nl80211_send_rfkill(void *eloop_ctx, void *timeout_ctx) |
2346 | { | |
2347 | wpa_supplicant_event(timeout_ctx, EVENT_INTERFACE_DISABLED, NULL); | |
2348 | } | |
2349 | ||
2350 | ||
eb4582f2 AS |
2351 | static void nl80211_del_p2pdev(struct i802_bss *bss) |
2352 | { | |
eb4582f2 AS |
2353 | struct nl_msg *msg; |
2354 | int ret; | |
2355 | ||
a3249fdf JM |
2356 | msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_DEL_INTERFACE); |
2357 | ret = send_and_recv_msgs(bss->drv, msg, NULL, NULL); | |
eb4582f2 AS |
2358 | |
2359 | wpa_printf(MSG_DEBUG, "nl80211: Delete P2P Device %s (0x%llx): %s", | |
2360 | bss->ifname, (long long unsigned int) bss->wdev_id, | |
6cb4f11d | 2361 | strerror(-ret)); |
eb4582f2 AS |
2362 | } |
2363 | ||
2364 | ||
eb4582f2 | 2365 | static int nl80211_set_p2pdev(struct i802_bss *bss, int start) |
f632e483 | 2366 | { |
f632e483 | 2367 | struct nl_msg *msg; |
a862e4a3 | 2368 | int ret; |
f632e483 | 2369 | |
a3249fdf JM |
2370 | msg = nl80211_cmd_msg(bss, 0, start ? NL80211_CMD_START_P2P_DEVICE : |
2371 | NL80211_CMD_STOP_P2P_DEVICE); | |
2372 | ret = send_and_recv_msgs(bss->drv, msg, NULL, NULL); | |
f632e483 | 2373 | |
eb4582f2 AS |
2374 | wpa_printf(MSG_DEBUG, "nl80211: %s P2P Device %s (0x%llx): %s", |
2375 | start ? "Start" : "Stop", | |
2376 | bss->ifname, (long long unsigned int) bss->wdev_id, | |
6cb4f11d | 2377 | strerror(-ret)); |
f632e483 AS |
2378 | return ret; |
2379 | } | |
f632e483 AS |
2380 | |
2381 | ||
91724d6f AS |
2382 | static int i802_set_iface_flags(struct i802_bss *bss, int up) |
2383 | { | |
2384 | enum nl80211_iftype nlmode; | |
2385 | ||
2386 | nlmode = nl80211_get_ifmode(bss); | |
2387 | if (nlmode != NL80211_IFTYPE_P2P_DEVICE) { | |
2388 | return linux_set_iface_flags(bss->drv->global->ioctl_sock, | |
2389 | bss->ifname, up); | |
2390 | } | |
2391 | ||
2392 | /* P2P Device has start/stop which is equivalent */ | |
2393 | return nl80211_set_p2pdev(bss, up); | |
2394 | } | |
2395 | ||
2396 | ||
1db718b3 JM |
2397 | #ifdef CONFIG_TESTING_OPTIONS |
2398 | static int qca_vendor_test_cmd_handler(struct nl_msg *msg, void *arg) | |
2399 | { | |
2400 | /* struct wpa_driver_nl80211_data *drv = arg; */ | |
2401 | struct nlattr *tb[NL80211_ATTR_MAX + 1]; | |
2402 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); | |
2403 | ||
2404 | ||
2405 | wpa_printf(MSG_DEBUG, | |
2406 | "nl80211: QCA vendor test command response received"); | |
2407 | ||
2408 | nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), | |
2409 | genlmsg_attrlen(gnlh, 0), NULL); | |
2410 | if (!tb[NL80211_ATTR_VENDOR_DATA]) { | |
2411 | wpa_printf(MSG_DEBUG, "nl80211: No vendor data attribute"); | |
2412 | return NL_SKIP; | |
2413 | } | |
2414 | ||
2415 | wpa_hexdump(MSG_DEBUG, | |
2416 | "nl80211: Received QCA vendor test command response", | |
2417 | nla_data(tb[NL80211_ATTR_VENDOR_DATA]), | |
2418 | nla_len(tb[NL80211_ATTR_VENDOR_DATA])); | |
2419 | ||
2420 | return NL_SKIP; | |
2421 | } | |
2422 | #endif /* CONFIG_TESTING_OPTIONS */ | |
2423 | ||
2424 | ||
2425 | static void qca_vendor_test(struct wpa_driver_nl80211_data *drv) | |
2426 | { | |
2427 | #ifdef CONFIG_TESTING_OPTIONS | |
2428 | struct nl_msg *msg; | |
2429 | struct nlattr *params; | |
2430 | int ret; | |
2431 | ||
2432 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_VENDOR)) || | |
2433 | nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) || | |
2434 | nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD, | |
2435 | QCA_NL80211_VENDOR_SUBCMD_TEST) || | |
2436 | !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) || | |
2437 | nla_put_u32(msg, QCA_WLAN_VENDOR_ATTR_TEST, 123)) { | |
2438 | nlmsg_free(msg); | |
2439 | return; | |
2440 | } | |
2441 | nla_nest_end(msg, params); | |
2442 | ||
2443 | ret = send_and_recv_msgs(drv, msg, qca_vendor_test_cmd_handler, drv); | |
2444 | wpa_printf(MSG_DEBUG, | |
2445 | "nl80211: QCA vendor test command returned %d (%s)", | |
2446 | ret, strerror(-ret)); | |
2447 | #endif /* CONFIG_TESTING_OPTIONS */ | |
2448 | } | |
2449 | ||
2450 | ||
362f781e | 2451 | static int |
0d547d5f | 2452 | wpa_driver_nl80211_finish_drv_init(struct wpa_driver_nl80211_data *drv, |
0ecff8d7 JM |
2453 | const u8 *set_addr, int first, |
2454 | const char *driver_params) | |
7524cfb1 | 2455 | { |
834ee56f | 2456 | struct i802_bss *bss = drv->first_bss; |
8401a6b0 | 2457 | int send_rfkill_event = 0; |
0d547d5f | 2458 | enum nl80211_iftype nlmode; |
a2e40bb6 FF |
2459 | |
2460 | drv->ifindex = if_nametoindex(bss->ifname); | |
f632e483 AS |
2461 | bss->ifindex = drv->ifindex; |
2462 | bss->wdev_id = drv->global->if_add_wdevid; | |
2463 | bss->wdev_id_set = drv->global->if_add_wdevid_set; | |
2464 | ||
60b13c20 IP |
2465 | bss->if_dynamic = drv->ifindex == drv->global->if_add_ifindex; |
2466 | bss->if_dynamic = bss->if_dynamic || drv->global->if_add_wdevid_set; | |
f632e483 AS |
2467 | drv->global->if_add_wdevid_set = 0; |
2468 | ||
bf144cf6 AP |
2469 | if (!bss->if_dynamic && nl80211_get_ifmode(bss) == NL80211_IFTYPE_AP) |
2470 | bss->static_ap = 1; | |
2471 | ||
ef3866ab IP |
2472 | if (first && |
2473 | nl80211_get_ifmode(bss) != NL80211_IFTYPE_P2P_DEVICE && | |
2474 | linux_iface_up(drv->global->ioctl_sock, bss->ifname) > 0) | |
2475 | drv->start_iface_up = 1; | |
2476 | ||
f632e483 AS |
2477 | if (wpa_driver_nl80211_capa(drv)) |
2478 | return -1; | |
a87c9d96 | 2479 | |
0ecff8d7 JM |
2480 | if (driver_params && nl80211_set_param(bss, driver_params) < 0) |
2481 | return -1; | |
2482 | ||
5fbcb45d AS |
2483 | wpa_printf(MSG_DEBUG, "nl80211: interface %s in phy %s", |
2484 | bss->ifname, drv->phyname); | |
2485 | ||
0d547d5f JM |
2486 | if (set_addr && |
2487 | (linux_set_iface_flags(drv->global->ioctl_sock, bss->ifname, 0) || | |
2488 | linux_set_ifhwaddr(drv->global->ioctl_sock, bss->ifname, | |
2489 | set_addr))) | |
2490 | return -1; | |
2491 | ||
49b4b205 JM |
2492 | if (first && nl80211_get_ifmode(bss) == NL80211_IFTYPE_AP) |
2493 | drv->start_mode_ap = 1; | |
2494 | ||
bf144cf6 | 2495 | if (drv->hostapd || bss->static_ap) |
0d547d5f | 2496 | nlmode = NL80211_IFTYPE_AP; |
4fe726e2 FF |
2497 | else if (bss->if_dynamic || |
2498 | nl80211_get_ifmode(bss) == NL80211_IFTYPE_MESH_POINT) | |
8e12685c | 2499 | nlmode = nl80211_get_ifmode(bss); |
0d547d5f JM |
2500 | else |
2501 | nlmode = NL80211_IFTYPE_STATION; | |
f632e483 | 2502 | |
8e12685c | 2503 | if (wpa_driver_nl80211_set_mode(bss, nlmode) < 0) { |
0d547d5f | 2504 | wpa_printf(MSG_ERROR, "nl80211: Could not configure driver mode"); |
8e12685c | 2505 | return -1; |
a87c9d96 JM |
2506 | } |
2507 | ||
8c06db70 | 2508 | if (nlmode == NL80211_IFTYPE_P2P_DEVICE) |
597b94f5 | 2509 | nl80211_get_macaddr(bss); |
f632e483 | 2510 | |
0e92fb8f JB |
2511 | wpa_driver_nl80211_drv_init_rfkill(drv); |
2512 | ||
8c06db70 MB |
2513 | if (!rfkill_is_blocked(drv->rfkill)) { |
2514 | int ret = i802_set_iface_flags(bss, 1); | |
2515 | if (ret) { | |
8401a6b0 JM |
2516 | wpa_printf(MSG_ERROR, "nl80211: Could not set " |
2517 | "interface '%s' UP", bss->ifname); | |
8c06db70 | 2518 | return ret; |
8401a6b0 | 2519 | } |
e8dc205f AO |
2520 | |
2521 | if (is_p2p_net_interface(nlmode)) | |
2522 | nl80211_disable_11b_rates(bss->drv, | |
2523 | bss->drv->ifindex, 1); | |
2524 | ||
8c06db70 MB |
2525 | if (nlmode == NL80211_IFTYPE_P2P_DEVICE) |
2526 | return ret; | |
2527 | } else { | |
2528 | wpa_printf(MSG_DEBUG, "nl80211: Could not yet enable " | |
2529 | "interface '%s' due to rfkill", bss->ifname); | |
6da504a1 IP |
2530 | if (nlmode != NL80211_IFTYPE_P2P_DEVICE) |
2531 | drv->if_disabled = 1; | |
2532 | ||
8c06db70 | 2533 | send_rfkill_event = 1; |
362f781e | 2534 | } |
3f5285e8 | 2535 | |
6da504a1 | 2536 | if (!drv->hostapd && nlmode != NL80211_IFTYPE_P2P_DEVICE) |
0d547d5f JM |
2537 | netlink_send_oper_ifla(drv->global->netlink, drv->ifindex, |
2538 | 1, IF_OPER_DORMANT); | |
362f781e | 2539 | |
6da504a1 IP |
2540 | if (nlmode != NL80211_IFTYPE_P2P_DEVICE) { |
2541 | if (linux_get_ifhwaddr(drv->global->ioctl_sock, bss->ifname, | |
2542 | bss->addr)) | |
2543 | return -1; | |
2544 | os_memcpy(drv->perm_addr, bss->addr, ETH_ALEN); | |
2545 | } | |
f2ed8023 | 2546 | |
8401a6b0 JM |
2547 | if (send_rfkill_event) { |
2548 | eloop_register_timeout(0, 0, wpa_driver_nl80211_send_rfkill, | |
2549 | drv, drv->ctx); | |
2550 | } | |
2551 | ||
1db718b3 JM |
2552 | if (drv->vendor_cmd_test_avail) |
2553 | qca_vendor_test(drv); | |
2554 | ||
40a68f33 SD |
2555 | nl80211_init_connect_handle(bss); |
2556 | ||
362f781e | 2557 | return 0; |
3f5285e8 JM |
2558 | } |
2559 | ||
2560 | ||
a70cd0db | 2561 | static int wpa_driver_nl80211_del_beacon(struct i802_bss *bss) |
8a27af5c JM |
2562 | { |
2563 | struct nl_msg *msg; | |
a70cd0db | 2564 | struct wpa_driver_nl80211_data *drv = bss->drv; |
8a27af5c | 2565 | |
08e55ebb JM |
2566 | wpa_printf(MSG_DEBUG, "nl80211: Remove beacon (ifindex=%d)", |
2567 | drv->ifindex); | |
a70cd0db | 2568 | nl80211_put_wiphy_data_ap(bss); |
9725b784 | 2569 | msg = nl80211_drv_msg(drv, 0, NL80211_CMD_DEL_BEACON); |
8a27af5c | 2570 | return send_and_recv_msgs(drv, msg, NULL, NULL); |
8a27af5c | 2571 | } |
8a27af5c JM |
2572 | |
2573 | ||
3f5285e8 | 2574 | /** |
7e5ba1b9 | 2575 | * wpa_driver_nl80211_deinit - Deinitialize nl80211 driver interface |
9ebce9c5 | 2576 | * @bss: Pointer to private nl80211 data from wpa_driver_nl80211_init() |
3f5285e8 JM |
2577 | * |
2578 | * Shut down driver interface and processing of driver events. Free | |
2579 | * private data buffer if one was allocated in wpa_driver_nl80211_init(). | |
2580 | */ | |
9ebce9c5 | 2581 | static void wpa_driver_nl80211_deinit(struct i802_bss *bss) |
3f5285e8 | 2582 | { |
a2e40bb6 | 2583 | struct wpa_driver_nl80211_data *drv = bss->drv; |
cc9a2575 | 2584 | unsigned int i; |
3f5285e8 | 2585 | |
3e208481 JM |
2586 | wpa_printf(MSG_INFO, "nl80211: deinit ifname=%s disabled_11b_rates=%d", |
2587 | bss->ifname, drv->disabled_11b_rates); | |
2588 | ||
873d0fcf | 2589 | bss->in_deinit = 1; |
32ab4855 JB |
2590 | if (drv->data_tx_status) |
2591 | eloop_unregister_read_sock(drv->eapol_tx_sock); | |
d12dab4c JB |
2592 | if (drv->eapol_tx_sock >= 0) |
2593 | close(drv->eapol_tx_sock); | |
f10bfc9a | 2594 | |
481234cf | 2595 | if (bss->nl_preq) |
5582a5d1 | 2596 | wpa_driver_nl80211_probe_req_report(bss, 0); |
e17a2477 | 2597 | if (bss->added_if_into_bridge) { |
c81eff1a BG |
2598 | if (linux_br_del_if(drv->global->ioctl_sock, bss->brname, |
2599 | bss->ifname) < 0) | |
94627f6c JM |
2600 | wpa_printf(MSG_INFO, "nl80211: Failed to remove " |
2601 | "interface %s from bridge %s: %s", | |
e17a2477 | 2602 | bss->ifname, bss->brname, strerror(errno)); |
97ed9a06 | 2603 | if (drv->rtnl_sk) |
ca3c6b4d | 2604 | nl80211_handle_destroy(drv->rtnl_sk); |
94627f6c | 2605 | } |
e17a2477 | 2606 | if (bss->added_bridge) { |
f2535da8 JM |
2607 | if (linux_set_iface_flags(drv->global->ioctl_sock, bss->brname, |
2608 | 0) < 0) | |
2609 | wpa_printf(MSG_INFO, | |
2610 | "nl80211: Could not set bridge %s down", | |
2611 | bss->brname); | |
c81eff1a | 2612 | if (linux_br_del(drv->global->ioctl_sock, bss->brname) < 0) |
94627f6c JM |
2613 | wpa_printf(MSG_INFO, "nl80211: Failed to remove " |
2614 | "bridge %s: %s", | |
e17a2477 | 2615 | bss->brname, strerror(errno)); |
94627f6c JM |
2616 | } |
2617 | ||
460456f8 | 2618 | nl80211_remove_monitor_interface(drv); |
8a27af5c | 2619 | |
b1f625e0 | 2620 | if (is_ap_interface(drv->nlmode)) |
a70cd0db | 2621 | wpa_driver_nl80211_del_beacon(bss); |
0915d02c | 2622 | |
bbaf0837 JM |
2623 | if (drv->eapol_sock >= 0) { |
2624 | eloop_unregister_read_sock(drv->eapol_sock); | |
2625 | close(drv->eapol_sock); | |
2626 | } | |
2627 | ||
2628 | if (drv->if_indices != drv->default_if_indices) | |
2629 | os_free(drv->if_indices); | |
3f5285e8 | 2630 | |
732b1d20 MB |
2631 | if (drv->if_indices_reason != drv->default_if_indices_reason) |
2632 | os_free(drv->if_indices_reason); | |
2633 | ||
b3af99d2 | 2634 | if (drv->disabled_11b_rates) |
4e5cb1a3 JM |
2635 | nl80211_disable_11b_rates(drv, drv->ifindex, 0); |
2636 | ||
36d84860 BG |
2637 | netlink_send_oper_ifla(drv->global->netlink, drv->ifindex, 0, |
2638 | IF_OPER_UP); | |
e390df05 | 2639 | eloop_cancel_timeout(wpa_driver_nl80211_send_rfkill, drv, drv->ctx); |
8401a6b0 | 2640 | rfkill_deinit(drv->rfkill); |
3f5285e8 | 2641 | |
bbaf0837 JM |
2642 | eloop_cancel_timeout(wpa_driver_nl80211_scan_timeout, drv, drv->ctx); |
2643 | ||
146fa9b3 JM |
2644 | if (!drv->start_iface_up) |
2645 | (void) i802_set_iface_flags(bss, 0); | |
fee354c7 JM |
2646 | |
2647 | if (drv->addr_changed) { | |
93da0498 JM |
2648 | if (linux_set_iface_flags(drv->global->ioctl_sock, bss->ifname, |
2649 | 0) < 0) { | |
2650 | wpa_printf(MSG_DEBUG, | |
2651 | "nl80211: Could not set interface down to restore permanent MAC address"); | |
2652 | } | |
fee354c7 JM |
2653 | if (linux_set_ifhwaddr(drv->global->ioctl_sock, bss->ifname, |
2654 | drv->perm_addr) < 0) { | |
2655 | wpa_printf(MSG_DEBUG, | |
2656 | "nl80211: Could not restore permanent MAC address"); | |
2657 | } | |
2658 | } | |
2659 | ||
8e12685c | 2660 | if (drv->nlmode != NL80211_IFTYPE_P2P_DEVICE) { |
49b4b205 JM |
2661 | if (!drv->hostapd || !drv->start_mode_ap) |
2662 | wpa_driver_nl80211_set_mode(bss, | |
2663 | NL80211_IFTYPE_STATION); | |
b378c41f | 2664 | nl80211_mgmt_unsubscribe(bss, "deinit"); |
8e12685c AS |
2665 | } else { |
2666 | nl80211_mgmt_unsubscribe(bss, "deinit"); | |
eb4582f2 | 2667 | nl80211_del_p2pdev(bss); |
8e12685c | 2668 | } |
3f5285e8 | 2669 | |
40a68f33 SD |
2670 | if (bss->nl_connect) |
2671 | nl80211_destroy_eloop_handle(&bss->nl_connect, 1); | |
2672 | ||
834ee56f | 2673 | nl80211_destroy_bss(drv->first_bss); |
cc7a48d1 | 2674 | |
3812464c JM |
2675 | os_free(drv->filter_ssids); |
2676 | ||
536fd62d JM |
2677 | os_free(drv->auth_ie); |
2678 | ||
dac12351 | 2679 | if (drv->in_interface_list) |
f2ed8023 JM |
2680 | dl_list_del(&drv->list); |
2681 | ||
8cd6b7bc JB |
2682 | os_free(drv->extended_capa); |
2683 | os_free(drv->extended_capa_mask); | |
cc9a2575 KV |
2684 | for (i = 0; i < drv->num_iface_ext_capa; i++) { |
2685 | os_free(drv->iface_ext_capa[i].ext_capa); | |
2686 | os_free(drv->iface_ext_capa[i].ext_capa_mask); | |
2687 | } | |
834ee56f | 2688 | os_free(drv->first_bss); |
3f5285e8 JM |
2689 | os_free(drv); |
2690 | } | |
2691 | ||
2692 | ||
de4ed4a8 JM |
2693 | static u32 wpa_alg_to_cipher_suite(enum wpa_alg alg, size_t key_len) |
2694 | { | |
2695 | switch (alg) { | |
2696 | case WPA_ALG_WEP: | |
2697 | if (key_len == 5) | |
a042e39a JM |
2698 | return RSN_CIPHER_SUITE_WEP40; |
2699 | return RSN_CIPHER_SUITE_WEP104; | |
de4ed4a8 | 2700 | case WPA_ALG_TKIP: |
a042e39a | 2701 | return RSN_CIPHER_SUITE_TKIP; |
de4ed4a8 | 2702 | case WPA_ALG_CCMP: |
a042e39a | 2703 | return RSN_CIPHER_SUITE_CCMP; |
de4ed4a8 | 2704 | case WPA_ALG_GCMP: |
a042e39a | 2705 | return RSN_CIPHER_SUITE_GCMP; |
de4ed4a8 | 2706 | case WPA_ALG_CCMP_256: |
a042e39a | 2707 | return RSN_CIPHER_SUITE_CCMP_256; |
de4ed4a8 | 2708 | case WPA_ALG_GCMP_256: |
a042e39a | 2709 | return RSN_CIPHER_SUITE_GCMP_256; |
de4ed4a8 | 2710 | case WPA_ALG_IGTK: |
a042e39a | 2711 | return RSN_CIPHER_SUITE_AES_128_CMAC; |
de4ed4a8 | 2712 | case WPA_ALG_BIP_GMAC_128: |
a042e39a | 2713 | return RSN_CIPHER_SUITE_BIP_GMAC_128; |
de4ed4a8 | 2714 | case WPA_ALG_BIP_GMAC_256: |
a042e39a | 2715 | return RSN_CIPHER_SUITE_BIP_GMAC_256; |
de4ed4a8 | 2716 | case WPA_ALG_BIP_CMAC_256: |
a042e39a | 2717 | return RSN_CIPHER_SUITE_BIP_CMAC_256; |
de4ed4a8 | 2718 | case WPA_ALG_SMS4: |
a042e39a | 2719 | return RSN_CIPHER_SUITE_SMS4; |
de4ed4a8 | 2720 | case WPA_ALG_KRK: |
a042e39a | 2721 | return RSN_CIPHER_SUITE_KRK; |
de4ed4a8 JM |
2722 | case WPA_ALG_NONE: |
2723 | case WPA_ALG_PMK: | |
2724 | wpa_printf(MSG_ERROR, "nl80211: Unexpected encryption algorithm %d", | |
2725 | alg); | |
2726 | return 0; | |
2727 | } | |
2728 | ||
2729 | wpa_printf(MSG_ERROR, "nl80211: Unsupported encryption algorithm %d", | |
2730 | alg); | |
2731 | return 0; | |
2732 | } | |
2733 | ||
2734 | ||
2735 | static u32 wpa_cipher_to_cipher_suite(unsigned int cipher) | |
2736 | { | |
2737 | switch (cipher) { | |
2738 | case WPA_CIPHER_CCMP_256: | |
a042e39a | 2739 | return RSN_CIPHER_SUITE_CCMP_256; |
de4ed4a8 | 2740 | case WPA_CIPHER_GCMP_256: |
a042e39a | 2741 | return RSN_CIPHER_SUITE_GCMP_256; |
de4ed4a8 | 2742 | case WPA_CIPHER_CCMP: |
a042e39a | 2743 | return RSN_CIPHER_SUITE_CCMP; |
de4ed4a8 | 2744 | case WPA_CIPHER_GCMP: |
a042e39a | 2745 | return RSN_CIPHER_SUITE_GCMP; |
de4ed4a8 | 2746 | case WPA_CIPHER_TKIP: |
a042e39a | 2747 | return RSN_CIPHER_SUITE_TKIP; |
de4ed4a8 | 2748 | case WPA_CIPHER_WEP104: |
a042e39a | 2749 | return RSN_CIPHER_SUITE_WEP104; |
de4ed4a8 | 2750 | case WPA_CIPHER_WEP40: |
a042e39a | 2751 | return RSN_CIPHER_SUITE_WEP40; |
ae6f9272 | 2752 | case WPA_CIPHER_GTK_NOT_USED: |
a042e39a | 2753 | return RSN_CIPHER_SUITE_NO_GROUP_ADDRESSED; |
de4ed4a8 JM |
2754 | } |
2755 | ||
2756 | return 0; | |
2757 | } | |
2758 | ||
2759 | ||
2760 | static int wpa_cipher_to_cipher_suites(unsigned int ciphers, u32 suites[], | |
2761 | int max_suites) | |
2762 | { | |
2763 | int num_suites = 0; | |
2764 | ||
2765 | if (num_suites < max_suites && ciphers & WPA_CIPHER_CCMP_256) | |
a042e39a | 2766 | suites[num_suites++] = RSN_CIPHER_SUITE_CCMP_256; |
de4ed4a8 | 2767 | if (num_suites < max_suites && ciphers & WPA_CIPHER_GCMP_256) |
a042e39a | 2768 | suites[num_suites++] = RSN_CIPHER_SUITE_GCMP_256; |
de4ed4a8 | 2769 | if (num_suites < max_suites && ciphers & WPA_CIPHER_CCMP) |
a042e39a | 2770 | suites[num_suites++] = RSN_CIPHER_SUITE_CCMP; |
de4ed4a8 | 2771 | if (num_suites < max_suites && ciphers & WPA_CIPHER_GCMP) |
a042e39a | 2772 | suites[num_suites++] = RSN_CIPHER_SUITE_GCMP; |
de4ed4a8 | 2773 | if (num_suites < max_suites && ciphers & WPA_CIPHER_TKIP) |
a042e39a | 2774 | suites[num_suites++] = RSN_CIPHER_SUITE_TKIP; |
de4ed4a8 | 2775 | if (num_suites < max_suites && ciphers & WPA_CIPHER_WEP104) |
a042e39a | 2776 | suites[num_suites++] = RSN_CIPHER_SUITE_WEP104; |
de4ed4a8 | 2777 | if (num_suites < max_suites && ciphers & WPA_CIPHER_WEP40) |
a042e39a | 2778 | suites[num_suites++] = RSN_CIPHER_SUITE_WEP40; |
de4ed4a8 JM |
2779 | |
2780 | return num_suites; | |
2781 | } | |
2782 | ||
2783 | ||
b658547d | 2784 | #ifdef CONFIG_DRIVER_NL80211_QCA |
b41f2684 CL |
2785 | static int issue_key_mgmt_set_key(struct wpa_driver_nl80211_data *drv, |
2786 | const u8 *key, size_t key_len) | |
2787 | { | |
2788 | struct nl_msg *msg; | |
a862e4a3 | 2789 | int ret; |
b41f2684 | 2790 | |
15badebd | 2791 | if (!(drv->capa.flags & WPA_DRIVER_FLAGS_KEY_MGMT_OFFLOAD)) |
b41f2684 CL |
2792 | return 0; |
2793 | ||
9725b784 | 2794 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_VENDOR)) || |
a862e4a3 JM |
2795 | nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) || |
2796 | nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD, | |
2797 | QCA_NL80211_VENDOR_SUBCMD_KEY_MGMT_SET_KEY) || | |
2798 | nla_put(msg, NL80211_ATTR_VENDOR_DATA, key_len, key)) { | |
bbd89bfc | 2799 | nl80211_nlmsg_clear(msg); |
a862e4a3 JM |
2800 | nlmsg_free(msg); |
2801 | return -1; | |
2802 | } | |
bbd89bfc | 2803 | ret = send_and_recv_msgs(drv, msg, NULL, (void *) -1); |
b41f2684 CL |
2804 | if (ret) { |
2805 | wpa_printf(MSG_DEBUG, | |
2806 | "nl80211: Key management set key failed: ret=%d (%s)", | |
2807 | ret, strerror(-ret)); | |
2808 | } | |
2809 | ||
b41f2684 CL |
2810 | return ret; |
2811 | } | |
b658547d | 2812 | #endif /* CONFIG_DRIVER_NL80211_QCA */ |
b41f2684 CL |
2813 | |
2814 | ||
9ebce9c5 | 2815 | static int wpa_driver_nl80211_set_key(const char *ifname, struct i802_bss *bss, |
71934751 JM |
2816 | enum wpa_alg alg, const u8 *addr, |
2817 | int key_idx, int set_tx, | |
642187d6 JM |
2818 | const u8 *seq, size_t seq_len, |
2819 | const u8 *key, size_t key_len) | |
3f5285e8 | 2820 | { |
a2e40bb6 | 2821 | struct wpa_driver_nl80211_data *drv = bss->drv; |
e472e1b4 | 2822 | int ifindex; |
34651767 | 2823 | struct nl_msg *msg = NULL; |
1ad1cdc2 | 2824 | int ret; |
dc01de8a | 2825 | int tdls = 0; |
3f5285e8 | 2826 | |
e472e1b4 AS |
2827 | /* Ignore for P2P Device */ |
2828 | if (drv->nlmode == NL80211_IFTYPE_P2P_DEVICE) | |
2829 | return 0; | |
2830 | ||
2831 | ifindex = if_nametoindex(ifname); | |
8393e1a0 | 2832 | wpa_printf(MSG_DEBUG, "%s: ifindex=%d (%s) alg=%d addr=%p key_idx=%d " |
1ad1cdc2 | 2833 | "set_tx=%d seq_len=%lu key_len=%lu", |
8393e1a0 | 2834 | __func__, ifindex, ifname, alg, addr, key_idx, set_tx, |
3f5285e8 | 2835 | (unsigned long) seq_len, (unsigned long) key_len); |
8c66e185 | 2836 | #ifdef CONFIG_TDLS |
dc01de8a | 2837 | if (key_idx == -1) { |
8c66e185 | 2838 | key_idx = 0; |
dc01de8a JM |
2839 | tdls = 1; |
2840 | } | |
8c66e185 | 2841 | #endif /* CONFIG_TDLS */ |
3f5285e8 | 2842 | |
b658547d | 2843 | #ifdef CONFIG_DRIVER_NL80211_QCA |
15badebd CL |
2844 | if (alg == WPA_ALG_PMK && |
2845 | (drv->capa.flags & WPA_DRIVER_FLAGS_KEY_MGMT_OFFLOAD)) { | |
b41f2684 CL |
2846 | wpa_printf(MSG_DEBUG, "%s: calling issue_key_mgmt_set_key", |
2847 | __func__); | |
2848 | ret = issue_key_mgmt_set_key(drv, key, key_len); | |
2849 | return ret; | |
2850 | } | |
b658547d | 2851 | #endif /* CONFIG_DRIVER_NL80211_QCA */ |
b41f2684 | 2852 | |
3f5285e8 | 2853 | if (alg == WPA_ALG_NONE) { |
95376e1a JM |
2854 | msg = nl80211_ifindex_msg(drv, ifindex, 0, NL80211_CMD_DEL_KEY); |
2855 | if (!msg) | |
2856 | return -ENOBUFS; | |
3f5285e8 | 2857 | } else { |
34651767 JM |
2858 | u32 suite; |
2859 | ||
2860 | suite = wpa_alg_to_cipher_suite(alg, key_len); | |
2861 | if (!suite) | |
2862 | goto fail; | |
95376e1a JM |
2863 | msg = nl80211_ifindex_msg(drv, ifindex, 0, NL80211_CMD_NEW_KEY); |
2864 | if (!msg || | |
a862e4a3 | 2865 | nla_put(msg, NL80211_ATTR_KEY_DATA, key_len, key) || |
34651767 | 2866 | nla_put_u32(msg, NL80211_ATTR_KEY_CIPHER, suite)) |
a862e4a3 | 2867 | goto fail; |
e6ef73f1 | 2868 | wpa_hexdump_key(MSG_DEBUG, "nl80211: KEY_DATA", key, key_len); |
3f5285e8 JM |
2869 | } |
2870 | ||
e6ef73f1 | 2871 | if (seq && seq_len) { |
a862e4a3 JM |
2872 | if (nla_put(msg, NL80211_ATTR_KEY_SEQ, seq_len, seq)) |
2873 | goto fail; | |
e6ef73f1 JM |
2874 | wpa_hexdump(MSG_DEBUG, "nl80211: KEY_SEQ", seq, seq_len); |
2875 | } | |
1ad1cdc2 | 2876 | |
0382097e | 2877 | if (addr && !is_broadcast_ether_addr(addr)) { |
3f5285e8 | 2878 | wpa_printf(MSG_DEBUG, " addr=" MACSTR, MAC2STR(addr)); |
a862e4a3 JM |
2879 | if (nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) |
2880 | goto fail; | |
89c38e32 JM |
2881 | |
2882 | if (alg != WPA_ALG_WEP && key_idx && !set_tx) { | |
2883 | wpa_printf(MSG_DEBUG, " RSN IBSS RX GTK"); | |
a862e4a3 JM |
2884 | if (nla_put_u32(msg, NL80211_ATTR_KEY_TYPE, |
2885 | NL80211_KEYTYPE_GROUP)) | |
2886 | goto fail; | |
89c38e32 | 2887 | } |
60ea8187 | 2888 | } else if (addr && is_broadcast_ether_addr(addr)) { |
8970bae8 JB |
2889 | struct nlattr *types; |
2890 | ||
60ea8187 | 2891 | wpa_printf(MSG_DEBUG, " broadcast key"); |
8970bae8 JB |
2892 | |
2893 | types = nla_nest_start(msg, NL80211_ATTR_KEY_DEFAULT_TYPES); | |
a862e4a3 JM |
2894 | if (!types || |
2895 | nla_put_flag(msg, NL80211_KEY_DEFAULT_TYPE_MULTICAST)) | |
2896 | goto fail; | |
8970bae8 | 2897 | nla_nest_end(msg, types); |
3f5285e8 | 2898 | } |
95376e1a | 2899 | if (nla_put_u8(msg, NL80211_ATTR_KEY_IDX, key_idx)) |
a862e4a3 | 2900 | goto fail; |
3f5285e8 | 2901 | |
bbd89bfc | 2902 | ret = send_and_recv_msgs(drv, msg, NULL, key ? (void *) -1 : NULL); |
15664ad0 | 2903 | if ((ret == -ENOENT || ret == -ENOLINK) && alg == WPA_ALG_NONE) |
1ad1cdc2 JM |
2904 | ret = 0; |
2905 | if (ret) | |
2906 | wpa_printf(MSG_DEBUG, "nl80211: set_key failed; err=%d %s)", | |
2907 | ret, strerror(-ret)); | |
3f5285e8 | 2908 | |
1ad1cdc2 JM |
2909 | /* |
2910 | * If we failed or don't need to set the default TX key (below), | |
2911 | * we're done here. | |
2912 | */ | |
dc01de8a | 2913 | if (ret || !set_tx || alg == WPA_ALG_NONE || tdls) |
1ad1cdc2 | 2914 | return ret; |
b1f625e0 | 2915 | if (is_ap_interface(drv->nlmode) && addr && |
0382097e | 2916 | !is_broadcast_ether_addr(addr)) |
de12717a | 2917 | return ret; |
3f5285e8 | 2918 | |
95376e1a JM |
2919 | msg = nl80211_ifindex_msg(drv, ifindex, 0, NL80211_CMD_SET_KEY); |
2920 | if (!msg || | |
a862e4a3 | 2921 | nla_put_u8(msg, NL80211_ATTR_KEY_IDX, key_idx) || |
86f9b1c7 JM |
2922 | nla_put_flag(msg, (alg == WPA_ALG_IGTK || |
2923 | alg == WPA_ALG_BIP_GMAC_128 || | |
2924 | alg == WPA_ALG_BIP_GMAC_256 || | |
2925 | alg == WPA_ALG_BIP_CMAC_256) ? | |
a862e4a3 JM |
2926 | NL80211_ATTR_KEY_DEFAULT_MGMT : |
2927 | NL80211_ATTR_KEY_DEFAULT)) | |
2928 | goto fail; | |
60ea8187 | 2929 | if (addr && is_broadcast_ether_addr(addr)) { |
8970bae8 JB |
2930 | struct nlattr *types; |
2931 | ||
2932 | types = nla_nest_start(msg, NL80211_ATTR_KEY_DEFAULT_TYPES); | |
a862e4a3 JM |
2933 | if (!types || |
2934 | nla_put_flag(msg, NL80211_KEY_DEFAULT_TYPE_MULTICAST)) | |
2935 | goto fail; | |
8970bae8 | 2936 | nla_nest_end(msg, types); |
60ea8187 | 2937 | } else if (addr) { |
8970bae8 JB |
2938 | struct nlattr *types; |
2939 | ||
2940 | types = nla_nest_start(msg, NL80211_ATTR_KEY_DEFAULT_TYPES); | |
a862e4a3 JM |
2941 | if (!types || |
2942 | nla_put_flag(msg, NL80211_KEY_DEFAULT_TYPE_UNICAST)) | |
2943 | goto fail; | |
8970bae8 | 2944 | nla_nest_end(msg, types); |
60ea8187 | 2945 | } |
3f5285e8 | 2946 | |
1ad1cdc2 JM |
2947 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
2948 | if (ret == -ENOENT) | |
2949 | ret = 0; | |
2950 | if (ret) | |
2951 | wpa_printf(MSG_DEBUG, "nl80211: set_key default failed; " | |
2952 | "err=%d %s)", ret, strerror(-ret)); | |
2953 | return ret; | |
3f5285e8 | 2954 | |
a862e4a3 | 2955 | fail: |
bbd89bfc | 2956 | nl80211_nlmsg_clear(msg); |
5883168a | 2957 | nlmsg_free(msg); |
6241fcb1 | 2958 | return -ENOBUFS; |
3f5285e8 JM |
2959 | } |
2960 | ||
2961 | ||
71934751 | 2962 | static int nl_add_key(struct nl_msg *msg, enum wpa_alg alg, |
0194fedb JB |
2963 | int key_idx, int defkey, |
2964 | const u8 *seq, size_t seq_len, | |
2965 | const u8 *key, size_t key_len) | |
2966 | { | |
2967 | struct nlattr *key_attr = nla_nest_start(msg, NL80211_ATTR_KEY); | |
34651767 JM |
2968 | u32 suite; |
2969 | ||
0194fedb JB |
2970 | if (!key_attr) |
2971 | return -1; | |
2972 | ||
34651767 JM |
2973 | suite = wpa_alg_to_cipher_suite(alg, key_len); |
2974 | if (!suite) | |
2975 | return -1; | |
2976 | ||
a862e4a3 JM |
2977 | if (defkey && alg == WPA_ALG_IGTK) { |
2978 | if (nla_put_flag(msg, NL80211_KEY_DEFAULT_MGMT)) | |
2979 | return -1; | |
2980 | } else if (defkey) { | |
2981 | if (nla_put_flag(msg, NL80211_KEY_DEFAULT)) | |
2982 | return -1; | |
2983 | } | |
0194fedb | 2984 | |
a862e4a3 | 2985 | if (nla_put_u8(msg, NL80211_KEY_IDX, key_idx) || |
34651767 | 2986 | nla_put_u32(msg, NL80211_KEY_CIPHER, suite) || |
a862e4a3 JM |
2987 | (seq && seq_len && |
2988 | nla_put(msg, NL80211_KEY_SEQ, seq_len, seq)) || | |
2989 | nla_put(msg, NL80211_KEY_DATA, key_len, key)) | |
2990 | return -1; | |
0194fedb JB |
2991 | |
2992 | nla_nest_end(msg, key_attr); | |
2993 | ||
2994 | return 0; | |
0194fedb JB |
2995 | } |
2996 | ||
c811d5bc | 2997 | |
cfaab580 ZY |
2998 | static int nl80211_set_conn_keys(struct wpa_driver_associate_params *params, |
2999 | struct nl_msg *msg) | |
3000 | { | |
3001 | int i, privacy = 0; | |
3002 | struct nlattr *nl_keys, *nl_key; | |
3003 | ||
3004 | for (i = 0; i < 4; i++) { | |
3005 | if (!params->wep_key[i]) | |
3006 | continue; | |
3007 | privacy = 1; | |
3008 | break; | |
3009 | } | |
ce04af5a JM |
3010 | if (params->wps == WPS_MODE_PRIVACY) |
3011 | privacy = 1; | |
3012 | if (params->pairwise_suite && | |
3013 | params->pairwise_suite != WPA_CIPHER_NONE) | |
3014 | privacy = 1; | |
3015 | ||
cfaab580 ZY |
3016 | if (!privacy) |
3017 | return 0; | |
3018 | ||
a862e4a3 JM |
3019 | if (nla_put_flag(msg, NL80211_ATTR_PRIVACY)) |
3020 | return -ENOBUFS; | |
cfaab580 ZY |
3021 | |
3022 | nl_keys = nla_nest_start(msg, NL80211_ATTR_KEYS); | |
3023 | if (!nl_keys) | |
a862e4a3 | 3024 | return -ENOBUFS; |
cfaab580 ZY |
3025 | |
3026 | for (i = 0; i < 4; i++) { | |
3027 | if (!params->wep_key[i]) | |
3028 | continue; | |
3029 | ||
3030 | nl_key = nla_nest_start(msg, i); | |
a862e4a3 JM |
3031 | if (!nl_key || |
3032 | nla_put(msg, NL80211_KEY_DATA, params->wep_key_len[i], | |
3033 | params->wep_key[i]) || | |
3034 | nla_put_u32(msg, NL80211_KEY_CIPHER, | |
3035 | params->wep_key_len[i] == 5 ? | |
a042e39a JM |
3036 | RSN_CIPHER_SUITE_WEP40 : |
3037 | RSN_CIPHER_SUITE_WEP104) || | |
a862e4a3 JM |
3038 | nla_put_u8(msg, NL80211_KEY_IDX, i) || |
3039 | (i == params->wep_tx_keyidx && | |
3040 | nla_put_flag(msg, NL80211_KEY_DEFAULT))) | |
3041 | return -ENOBUFS; | |
cfaab580 ZY |
3042 | |
3043 | nla_nest_end(msg, nl_key); | |
3044 | } | |
3045 | nla_nest_end(msg, nl_keys); | |
3046 | ||
3047 | return 0; | |
cfaab580 ZY |
3048 | } |
3049 | ||
3050 | ||
477af8f8 JM |
3051 | int wpa_driver_nl80211_mlme(struct wpa_driver_nl80211_data *drv, |
3052 | const u8 *addr, int cmd, u16 reason_code, | |
3053 | int local_state_change) | |
c2a04078 | 3054 | { |
a862e4a3 | 3055 | int ret; |
c2a04078 JM |
3056 | struct nl_msg *msg; |
3057 | ||
9725b784 | 3058 | if (!(msg = nl80211_drv_msg(drv, 0, cmd)) || |
a862e4a3 JM |
3059 | nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason_code) || |
3060 | (addr && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) || | |
3061 | (local_state_change && | |
3062 | nla_put_flag(msg, NL80211_ATTR_LOCAL_STATE_CHANGE))) { | |
3063 | nlmsg_free(msg); | |
3064 | return -1; | |
3065 | } | |
c2a04078 JM |
3066 | |
3067 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); | |
c2a04078 | 3068 | if (ret) { |
3b7ea880 BG |
3069 | wpa_dbg(drv->ctx, MSG_DEBUG, |
3070 | "nl80211: MLME command failed: reason=%u ret=%d (%s)", | |
3071 | reason_code, ret, strerror(-ret)); | |
c2a04078 | 3072 | } |
c2a04078 JM |
3073 | return ret; |
3074 | } | |
3f5285e8 JM |
3075 | |
3076 | ||
cfaab580 | 3077 | static int wpa_driver_nl80211_disconnect(struct wpa_driver_nl80211_data *drv, |
817762d9 | 3078 | int reason_code) |
cfaab580 | 3079 | { |
3f53c006 JJ |
3080 | int ret; |
3081 | ||
817762d9 | 3082 | wpa_printf(MSG_DEBUG, "%s(reason_code=%d)", __func__, reason_code); |
add9b7a4 | 3083 | nl80211_mark_disconnected(drv); |
817762d9 | 3084 | /* Disconnect command doesn't need BSSID - it uses cached value */ |
3f53c006 JJ |
3085 | ret = wpa_driver_nl80211_mlme(drv, NULL, NL80211_CMD_DISCONNECT, |
3086 | reason_code, 0); | |
3087 | /* | |
3088 | * For locally generated disconnect, supplicant already generates a | |
3089 | * DEAUTH event, so ignore the event from NL80211. | |
3090 | */ | |
3091 | drv->ignore_next_local_disconnect = ret == 0; | |
3092 | ||
3093 | return ret; | |
cfaab580 ZY |
3094 | } |
3095 | ||
3096 | ||
9ebce9c5 JM |
3097 | static int wpa_driver_nl80211_deauthenticate(struct i802_bss *bss, |
3098 | const u8 *addr, int reason_code) | |
3f5285e8 | 3099 | { |
a2e40bb6 | 3100 | struct wpa_driver_nl80211_data *drv = bss->drv; |
d6a36f39 | 3101 | int ret; |
9392c9be AS |
3102 | |
3103 | if (drv->nlmode == NL80211_IFTYPE_ADHOC) { | |
3104 | nl80211_mark_disconnected(drv); | |
666e508c | 3105 | return nl80211_leave_ibss(drv, 1); |
9392c9be | 3106 | } |
cfaab580 | 3107 | if (!(drv->capa.flags & WPA_DRIVER_FLAGS_SME)) |
817762d9 | 3108 | return wpa_driver_nl80211_disconnect(drv, reason_code); |
2e75a2b3 JM |
3109 | wpa_printf(MSG_DEBUG, "%s(addr=" MACSTR " reason_code=%d)", |
3110 | __func__, MAC2STR(addr), reason_code); | |
add9b7a4 | 3111 | nl80211_mark_disconnected(drv); |
d6a36f39 JM |
3112 | ret = wpa_driver_nl80211_mlme(drv, addr, NL80211_CMD_DEAUTHENTICATE, |
3113 | reason_code, 0); | |
3114 | /* | |
3115 | * For locally generated deauthenticate, supplicant already generates a | |
3116 | * DEAUTH event, so ignore the event from NL80211. | |
3117 | */ | |
3118 | drv->ignore_next_local_deauth = ret == 0; | |
3119 | return ret; | |
3f5285e8 JM |
3120 | } |
3121 | ||
3122 | ||
536fd62d JM |
3123 | static void nl80211_copy_auth_params(struct wpa_driver_nl80211_data *drv, |
3124 | struct wpa_driver_auth_params *params) | |
3125 | { | |
3126 | int i; | |
3127 | ||
3128 | drv->auth_freq = params->freq; | |
3129 | drv->auth_alg = params->auth_alg; | |
3130 | drv->auth_wep_tx_keyidx = params->wep_tx_keyidx; | |
3131 | drv->auth_local_state_change = params->local_state_change; | |
3132 | drv->auth_p2p = params->p2p; | |
3133 | ||
3134 | if (params->bssid) | |
3135 | os_memcpy(drv->auth_bssid_, params->bssid, ETH_ALEN); | |
3136 | else | |
3137 | os_memset(drv->auth_bssid_, 0, ETH_ALEN); | |
3138 | ||
3139 | if (params->ssid) { | |
3140 | os_memcpy(drv->auth_ssid, params->ssid, params->ssid_len); | |
3141 | drv->auth_ssid_len = params->ssid_len; | |
3142 | } else | |
3143 | drv->auth_ssid_len = 0; | |
3144 | ||
3145 | ||
3146 | os_free(drv->auth_ie); | |
3147 | drv->auth_ie = NULL; | |
3148 | drv->auth_ie_len = 0; | |
3149 | if (params->ie) { | |
3150 | drv->auth_ie = os_malloc(params->ie_len); | |
3151 | if (drv->auth_ie) { | |
3152 | os_memcpy(drv->auth_ie, params->ie, params->ie_len); | |
3153 | drv->auth_ie_len = params->ie_len; | |
3154 | } | |
3155 | } | |
3156 | ||
3157 | for (i = 0; i < 4; i++) { | |
3158 | if (params->wep_key[i] && params->wep_key_len[i] && | |
3159 | params->wep_key_len[i] <= 16) { | |
3160 | os_memcpy(drv->auth_wep_key[i], params->wep_key[i], | |
3161 | params->wep_key_len[i]); | |
3162 | drv->auth_wep_key_len[i] = params->wep_key_len[i]; | |
3163 | } else | |
3164 | drv->auth_wep_key_len[i] = 0; | |
3165 | } | |
3166 | } | |
3167 | ||
3168 | ||
4bd71954 JM |
3169 | static void nl80211_unmask_11b_rates(struct i802_bss *bss) |
3170 | { | |
3171 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
3172 | ||
3173 | if (is_p2p_net_interface(drv->nlmode) || !drv->disabled_11b_rates) | |
3174 | return; | |
3175 | ||
3176 | /* | |
3177 | * Looks like we failed to unmask 11b rates previously. This could | |
3178 | * happen, e.g., if the interface was down at the point in time when a | |
3179 | * P2P group was terminated. | |
3180 | */ | |
3181 | wpa_printf(MSG_DEBUG, | |
3182 | "nl80211: Interface %s mode is for non-P2P, but 11b rates were disabled - re-enable them", | |
3183 | bss->ifname); | |
3184 | nl80211_disable_11b_rates(drv, drv->ifindex, 0); | |
3185 | } | |
3186 | ||
3187 | ||
3c67e977 VK |
3188 | static enum nl80211_auth_type get_nl_auth_type(int wpa_auth_alg) |
3189 | { | |
3190 | if (wpa_auth_alg & WPA_AUTH_ALG_OPEN) | |
3191 | return NL80211_AUTHTYPE_OPEN_SYSTEM; | |
3192 | if (wpa_auth_alg & WPA_AUTH_ALG_SHARED) | |
3193 | return NL80211_AUTHTYPE_SHARED_KEY; | |
3194 | if (wpa_auth_alg & WPA_AUTH_ALG_LEAP) | |
3195 | return NL80211_AUTHTYPE_NETWORK_EAP; | |
3196 | if (wpa_auth_alg & WPA_AUTH_ALG_FT) | |
3197 | return NL80211_AUTHTYPE_FT; | |
3198 | if (wpa_auth_alg & WPA_AUTH_ALG_SAE) | |
3199 | return NL80211_AUTHTYPE_SAE; | |
3200 | if (wpa_auth_alg & WPA_AUTH_ALG_FILS) | |
3201 | return NL80211_AUTHTYPE_FILS_SK; | |
3202 | if (wpa_auth_alg & WPA_AUTH_ALG_FILS_SK_PFS) | |
3203 | return NL80211_AUTHTYPE_FILS_SK_PFS; | |
3204 | ||
3205 | return NL80211_AUTHTYPE_MAX; | |
3206 | } | |
3207 | ||
3208 | ||
c2a04078 | 3209 | static int wpa_driver_nl80211_authenticate( |
9ebce9c5 | 3210 | struct i802_bss *bss, struct wpa_driver_auth_params *params) |
c2a04078 | 3211 | { |
a2e40bb6 | 3212 | struct wpa_driver_nl80211_data *drv = bss->drv; |
a0b2f99b | 3213 | int ret = -1, i; |
c2a04078 JM |
3214 | struct nl_msg *msg; |
3215 | enum nl80211_auth_type type; | |
2f4f73b1 | 3216 | enum nl80211_iftype nlmode; |
6d6f4bb8 | 3217 | int count = 0; |
536fd62d JM |
3218 | int is_retry; |
3219 | ||
4bd71954 JM |
3220 | nl80211_unmask_11b_rates(bss); |
3221 | ||
536fd62d JM |
3222 | is_retry = drv->retry_auth; |
3223 | drv->retry_auth = 0; | |
e8d70a73 | 3224 | drv->ignore_deauth_event = 0; |
c2a04078 | 3225 | |
add9b7a4 | 3226 | nl80211_mark_disconnected(drv); |
e6b8efeb | 3227 | os_memset(drv->auth_bssid, 0, ETH_ALEN); |
add9b7a4 JM |
3228 | if (params->bssid) |
3229 | os_memcpy(drv->auth_attempt_bssid, params->bssid, ETH_ALEN); | |
3230 | else | |
3231 | os_memset(drv->auth_attempt_bssid, 0, ETH_ALEN); | |
af473088 | 3232 | /* FIX: IBSS mode */ |
2f4f73b1 EP |
3233 | nlmode = params->p2p ? |
3234 | NL80211_IFTYPE_P2P_CLIENT : NL80211_IFTYPE_STATION; | |
3235 | if (drv->nlmode != nlmode && | |
9ebce9c5 | 3236 | wpa_driver_nl80211_set_mode(bss, nlmode) < 0) |
4a867032 JM |
3237 | return -1; |
3238 | ||
6d6f4bb8 | 3239 | retry: |
c2a04078 JM |
3240 | wpa_printf(MSG_DEBUG, "nl80211: Authenticate (ifindex=%d)", |
3241 | drv->ifindex); | |
a0b2f99b | 3242 | |
9725b784 JM |
3243 | msg = nl80211_drv_msg(drv, 0, NL80211_CMD_AUTHENTICATE); |
3244 | if (!msg) | |
3245 | goto fail; | |
0194fedb | 3246 | |
a0b2f99b JM |
3247 | for (i = 0; i < 4; i++) { |
3248 | if (!params->wep_key[i]) | |
3249 | continue; | |
9ebce9c5 | 3250 | wpa_driver_nl80211_set_key(bss->ifname, bss, WPA_ALG_WEP, |
2ea2fcc7 | 3251 | NULL, i, |
a0b2f99b JM |
3252 | i == params->wep_tx_keyidx, NULL, 0, |
3253 | params->wep_key[i], | |
3254 | params->wep_key_len[i]); | |
0194fedb JB |
3255 | if (params->wep_tx_keyidx != i) |
3256 | continue; | |
3257 | if (nl_add_key(msg, WPA_ALG_WEP, i, 1, NULL, 0, | |
9725b784 JM |
3258 | params->wep_key[i], params->wep_key_len[i])) |
3259 | goto fail; | |
a0b2f99b JM |
3260 | } |
3261 | ||
c2a04078 JM |
3262 | if (params->bssid) { |
3263 | wpa_printf(MSG_DEBUG, " * bssid=" MACSTR, | |
3264 | MAC2STR(params->bssid)); | |
a862e4a3 JM |
3265 | if (nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, params->bssid)) |
3266 | goto fail; | |
c2a04078 JM |
3267 | } |
3268 | if (params->freq) { | |
3269 | wpa_printf(MSG_DEBUG, " * freq=%d", params->freq); | |
a862e4a3 JM |
3270 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, params->freq)) |
3271 | goto fail; | |
c2a04078 JM |
3272 | } |
3273 | if (params->ssid) { | |
3274 | wpa_hexdump_ascii(MSG_DEBUG, " * SSID", | |
3275 | params->ssid, params->ssid_len); | |
a862e4a3 JM |
3276 | if (nla_put(msg, NL80211_ATTR_SSID, params->ssid_len, |
3277 | params->ssid)) | |
3278 | goto fail; | |
c2a04078 JM |
3279 | } |
3280 | wpa_hexdump(MSG_DEBUG, " * IEs", params->ie, params->ie_len); | |
a862e4a3 JM |
3281 | if (params->ie && |
3282 | nla_put(msg, NL80211_ATTR_IE, params->ie_len, params->ie)) | |
3283 | goto fail; | |
ce16c489 JM |
3284 | if (params->auth_data) { |
3285 | wpa_hexdump(MSG_DEBUG, " * auth_data", params->auth_data, | |
3286 | params->auth_data_len); | |
3287 | if (nla_put(msg, NL80211_ATTR_SAE_DATA, params->auth_data_len, | |
3288 | params->auth_data)) | |
a862e4a3 | 3289 | goto fail; |
569fed90 | 3290 | } |
3c67e977 | 3291 | type = get_nl_auth_type(params->auth_alg); |
c2a04078 | 3292 | wpa_printf(MSG_DEBUG, " * Auth Type %d", type); |
3c67e977 VK |
3293 | if (type == NL80211_AUTHTYPE_MAX || |
3294 | nla_put_u32(msg, NL80211_ATTR_AUTH_TYPE, type)) | |
a862e4a3 | 3295 | goto fail; |
77339912 JM |
3296 | if (params->local_state_change) { |
3297 | wpa_printf(MSG_DEBUG, " * Local state change only"); | |
a862e4a3 JM |
3298 | if (nla_put_flag(msg, NL80211_ATTR_LOCAL_STATE_CHANGE)) |
3299 | goto fail; | |
77339912 | 3300 | } |
c2a04078 JM |
3301 | |
3302 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); | |
3303 | msg = NULL; | |
3304 | if (ret) { | |
3b7ea880 BG |
3305 | wpa_dbg(drv->ctx, MSG_DEBUG, |
3306 | "nl80211: MLME command failed (auth): ret=%d (%s)", | |
3307 | ret, strerror(-ret)); | |
6d6f4bb8 | 3308 | count++; |
77339912 JM |
3309 | if (ret == -EALREADY && count == 1 && params->bssid && |
3310 | !params->local_state_change) { | |
6d6f4bb8 JM |
3311 | /* |
3312 | * mac80211 does not currently accept new | |
3313 | * authentication if we are already authenticated. As a | |
3314 | * workaround, force deauthentication and try again. | |
3315 | */ | |
3316 | wpa_printf(MSG_DEBUG, "nl80211: Retry authentication " | |
3317 | "after forced deauthentication"); | |
e8d70a73 | 3318 | drv->ignore_deauth_event = 1; |
6d6f4bb8 | 3319 | wpa_driver_nl80211_deauthenticate( |
5205c4f9 | 3320 | bss, params->bssid, |
6d6f4bb8 JM |
3321 | WLAN_REASON_PREV_AUTH_NOT_VALID); |
3322 | nlmsg_free(msg); | |
3323 | goto retry; | |
3324 | } | |
536fd62d JM |
3325 | |
3326 | if (ret == -ENOENT && params->freq && !is_retry) { | |
3327 | /* | |
3328 | * cfg80211 has likely expired the BSS entry even | |
3329 | * though it was previously available in our internal | |
3330 | * BSS table. To recover quickly, start a single | |
3331 | * channel scan on the specified channel. | |
3332 | */ | |
3333 | struct wpa_driver_scan_params scan; | |
3334 | int freqs[2]; | |
3335 | ||
3336 | os_memset(&scan, 0, sizeof(scan)); | |
3337 | scan.num_ssids = 1; | |
3338 | if (params->ssid) { | |
3339 | scan.ssids[0].ssid = params->ssid; | |
3340 | scan.ssids[0].ssid_len = params->ssid_len; | |
3341 | } | |
3342 | freqs[0] = params->freq; | |
3343 | freqs[1] = 0; | |
3344 | scan.freqs = freqs; | |
3345 | wpa_printf(MSG_DEBUG, "nl80211: Trigger single " | |
3346 | "channel scan to refresh cfg80211 BSS " | |
3347 | "entry"); | |
3348 | ret = wpa_driver_nl80211_scan(bss, &scan); | |
3349 | if (ret == 0) { | |
3350 | nl80211_copy_auth_params(drv, params); | |
3351 | drv->scan_for_auth = 1; | |
3352 | } | |
8c3ba078 JM |
3353 | } else if (is_retry) { |
3354 | /* | |
3355 | * Need to indicate this with an event since the return | |
3356 | * value from the retry is not delivered to core code. | |
3357 | */ | |
3358 | union wpa_event_data event; | |
3359 | wpa_printf(MSG_DEBUG, "nl80211: Authentication retry " | |
3360 | "failed"); | |
3361 | os_memset(&event, 0, sizeof(event)); | |
3362 | os_memcpy(event.timeout_event.addr, drv->auth_bssid_, | |
3363 | ETH_ALEN); | |
3364 | wpa_supplicant_event(drv->ctx, EVENT_AUTH_TIMED_OUT, | |
3365 | &event); | |
536fd62d | 3366 | } |
a862e4a3 JM |
3367 | } else { |
3368 | wpa_printf(MSG_DEBUG, | |
3369 | "nl80211: Authentication request send successfully"); | |
c2a04078 | 3370 | } |
c2a04078 | 3371 | |
a862e4a3 | 3372 | fail: |
c2a04078 JM |
3373 | nlmsg_free(msg); |
3374 | return ret; | |
3375 | } | |
3376 | ||
3377 | ||
f3407c66 | 3378 | int wpa_driver_nl80211_authenticate_retry(struct wpa_driver_nl80211_data *drv) |
536fd62d JM |
3379 | { |
3380 | struct wpa_driver_auth_params params; | |
834ee56f | 3381 | struct i802_bss *bss = drv->first_bss; |
536fd62d JM |
3382 | int i; |
3383 | ||
3384 | wpa_printf(MSG_DEBUG, "nl80211: Try to authenticate again"); | |
3385 | ||
3386 | os_memset(¶ms, 0, sizeof(params)); | |
3387 | params.freq = drv->auth_freq; | |
3388 | params.auth_alg = drv->auth_alg; | |
3389 | params.wep_tx_keyidx = drv->auth_wep_tx_keyidx; | |
3390 | params.local_state_change = drv->auth_local_state_change; | |
3391 | params.p2p = drv->auth_p2p; | |
3392 | ||
3393 | if (!is_zero_ether_addr(drv->auth_bssid_)) | |
3394 | params.bssid = drv->auth_bssid_; | |
3395 | ||
3396 | if (drv->auth_ssid_len) { | |
3397 | params.ssid = drv->auth_ssid; | |
3398 | params.ssid_len = drv->auth_ssid_len; | |
3399 | } | |
3400 | ||
3401 | params.ie = drv->auth_ie; | |
3402 | params.ie_len = drv->auth_ie_len; | |
3403 | ||
3404 | for (i = 0; i < 4; i++) { | |
3405 | if (drv->auth_wep_key_len[i]) { | |
3406 | params.wep_key[i] = drv->auth_wep_key[i]; | |
3407 | params.wep_key_len[i] = drv->auth_wep_key_len[i]; | |
3408 | } | |
3409 | } | |
3410 | ||
3411 | drv->retry_auth = 1; | |
3412 | return wpa_driver_nl80211_authenticate(bss, ¶ms); | |
3413 | } | |
3414 | ||
3415 | ||
a11241fa JB |
3416 | static int wpa_driver_nl80211_send_frame(struct i802_bss *bss, |
3417 | const void *data, size_t len, | |
55231068 JM |
3418 | int encrypt, int noack, |
3419 | unsigned int freq, int no_cck, | |
2d3943ce AO |
3420 | int offchanok, unsigned int wait_time, |
3421 | const u16 *csa_offs, | |
3422 | size_t csa_offs_len) | |
a11241fa JB |
3423 | { |
3424 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
3425 | u64 cookie; | |
41cc50d1 | 3426 | int res; |
a11241fa | 3427 | |
c7caac56 JM |
3428 | if (freq == 0 && drv->nlmode == NL80211_IFTYPE_ADHOC) { |
3429 | freq = nl80211_get_assoc_freq(drv); | |
3430 | wpa_printf(MSG_DEBUG, | |
3431 | "nl80211: send_frame - Use assoc_freq=%u for IBSS", | |
3432 | freq); | |
3433 | } | |
af964484 JM |
3434 | if (freq == 0) { |
3435 | wpa_printf(MSG_DEBUG, "nl80211: send_frame - Use bss->freq=%u", | |
3436 | bss->freq); | |
55231068 | 3437 | freq = bss->freq; |
af964484 | 3438 | } |
55231068 | 3439 | |
739faee2 | 3440 | if (drv->use_monitor) { |
981cf85a | 3441 | wpa_printf(MSG_DEBUG, "nl80211: send_frame(freq=%u bss->freq=%u) -> send_monitor", |
739faee2 | 3442 | freq, bss->freq); |
981cf85a | 3443 | return nl80211_send_monitor(drv, data, len, encrypt, noack); |
739faee2 | 3444 | } |
a11241fa | 3445 | |
739faee2 | 3446 | wpa_printf(MSG_DEBUG, "nl80211: send_frame -> send_frame_cmd"); |
41cc50d1 | 3447 | res = nl80211_send_frame_cmd(bss, freq, wait_time, data, len, |
2d3943ce AO |
3448 | &cookie, no_cck, noack, offchanok, |
3449 | csa_offs, csa_offs_len); | |
41cc50d1 JM |
3450 | if (res == 0 && !noack) { |
3451 | const struct ieee80211_mgmt *mgmt; | |
3452 | u16 fc; | |
3453 | ||
3454 | mgmt = (const struct ieee80211_mgmt *) data; | |
3455 | fc = le_to_host16(mgmt->frame_control); | |
3456 | if (WLAN_FC_GET_TYPE(fc) == WLAN_FC_TYPE_MGMT && | |
3457 | WLAN_FC_GET_STYPE(fc) == WLAN_FC_STYPE_ACTION) { | |
3458 | wpa_printf(MSG_MSGDUMP, | |
3459 | "nl80211: Update send_action_cookie from 0x%llx to 0x%llx", | |
3460 | (long long unsigned int) | |
3461 | drv->send_action_cookie, | |
3462 | (long long unsigned int) cookie); | |
3463 | drv->send_action_cookie = cookie; | |
3464 | } | |
3465 | } | |
3466 | ||
3467 | return res; | |
a11241fa JB |
3468 | } |
3469 | ||
3470 | ||
9ebce9c5 JM |
3471 | static int wpa_driver_nl80211_send_mlme(struct i802_bss *bss, const u8 *data, |
3472 | size_t data_len, int noack, | |
3473 | unsigned int freq, int no_cck, | |
3474 | int offchanok, | |
2d3943ce AO |
3475 | unsigned int wait_time, |
3476 | const u16 *csa_offs, | |
3477 | size_t csa_offs_len) | |
2c2010ac | 3478 | { |
a2e40bb6 | 3479 | struct wpa_driver_nl80211_data *drv = bss->drv; |
2c2010ac | 3480 | struct ieee80211_mgmt *mgmt; |
7a47d567 | 3481 | int encrypt = 1; |
2c2010ac JM |
3482 | u16 fc; |
3483 | ||
3484 | mgmt = (struct ieee80211_mgmt *) data; | |
3485 | fc = le_to_host16(mgmt->frame_control); | |
f95a4524 PF |
3486 | wpa_printf(MSG_DEBUG, "nl80211: send_mlme - da= " MACSTR |
3487 | " noack=%d freq=%u no_cck=%d offchanok=%d wait_time=%u fc=0x%x (%s) nlmode=%d", | |
3488 | MAC2STR(mgmt->da), noack, freq, no_cck, offchanok, wait_time, | |
3489 | fc, fc2str(fc), drv->nlmode); | |
2c2010ac | 3490 | |
8e12685c AS |
3491 | if ((is_sta_interface(drv->nlmode) || |
3492 | drv->nlmode == NL80211_IFTYPE_P2P_DEVICE) && | |
5582a5d1 JB |
3493 | WLAN_FC_GET_TYPE(fc) == WLAN_FC_TYPE_MGMT && |
3494 | WLAN_FC_GET_STYPE(fc) == WLAN_FC_STYPE_PROBE_RESP) { | |
3495 | /* | |
3496 | * The use of last_mgmt_freq is a bit of a hack, | |
3497 | * but it works due to the single-threaded nature | |
3498 | * of wpa_supplicant. | |
3499 | */ | |
af964484 JM |
3500 | if (freq == 0) { |
3501 | wpa_printf(MSG_DEBUG, "nl80211: Use last_mgmt_freq=%d", | |
3502 | drv->last_mgmt_freq); | |
55231068 | 3503 | freq = drv->last_mgmt_freq; |
af964484 | 3504 | } |
55231068 | 3505 | return nl80211_send_frame_cmd(bss, freq, 0, |
88df0ef7 | 3506 | data, data_len, NULL, 1, noack, |
2d3943ce | 3507 | 1, csa_offs, csa_offs_len); |
5582a5d1 JB |
3508 | } |
3509 | ||
61cbe2ff | 3510 | if (drv->device_ap_sme && is_ap_interface(drv->nlmode)) { |
af964484 JM |
3511 | if (freq == 0) { |
3512 | wpa_printf(MSG_DEBUG, "nl80211: Use bss->freq=%d", | |
3513 | bss->freq); | |
55231068 | 3514 | freq = bss->freq; |
af964484 | 3515 | } |
b5671498 JM |
3516 | return nl80211_send_frame_cmd(bss, freq, |
3517 | (int) freq == bss->freq ? 0 : | |
3518 | wait_time, | |
d8d6b32e DG |
3519 | data, data_len, |
3520 | &drv->send_action_cookie, | |
2d3943ce AO |
3521 | no_cck, noack, offchanok, |
3522 | csa_offs, csa_offs_len); | |
86957e62 JM |
3523 | } |
3524 | ||
2c2010ac JM |
3525 | if (WLAN_FC_GET_TYPE(fc) == WLAN_FC_TYPE_MGMT && |
3526 | WLAN_FC_GET_STYPE(fc) == WLAN_FC_STYPE_AUTH) { | |
3527 | /* | |
3528 | * Only one of the authentication frame types is encrypted. | |
3529 | * In order for static WEP encryption to work properly (i.e., | |
3530 | * to not encrypt the frame), we need to tell mac80211 about | |
3531 | * the frames that must not be encrypted. | |
3532 | */ | |
3533 | u16 auth_alg = le_to_host16(mgmt->u.auth.auth_alg); | |
3534 | u16 auth_trans = le_to_host16(mgmt->u.auth.auth_transaction); | |
7a47d567 JB |
3535 | if (auth_alg != WLAN_AUTH_SHARED_KEY || auth_trans != 3) |
3536 | encrypt = 0; | |
2c2010ac JM |
3537 | } |
3538 | ||
739faee2 | 3539 | wpa_printf(MSG_DEBUG, "nl80211: send_mlme -> send_frame"); |
a11241fa | 3540 | return wpa_driver_nl80211_send_frame(bss, data, data_len, encrypt, |
55231068 | 3541 | noack, freq, no_cck, offchanok, |
2d3943ce AO |
3542 | wait_time, csa_offs, |
3543 | csa_offs_len); | |
55231068 JM |
3544 | } |
3545 | ||
3546 | ||
cae87abd JM |
3547 | static int nl80211_put_basic_rates(struct nl_msg *msg, const int *basic_rates) |
3548 | { | |
3549 | u8 rates[NL80211_MAX_SUPP_RATES]; | |
3550 | u8 rates_len = 0; | |
3551 | int i; | |
3552 | ||
3553 | if (!basic_rates) | |
3554 | return 0; | |
3555 | ||
3556 | for (i = 0; i < NL80211_MAX_SUPP_RATES && basic_rates[i] >= 0; i++) | |
3557 | rates[rates_len++] = basic_rates[i] / 5; | |
3558 | ||
3559 | return nla_put(msg, NL80211_ATTR_BSS_BASIC_RATES, rates_len, rates); | |
3560 | } | |
3561 | ||
3562 | ||
31357268 | 3563 | static int nl80211_set_bss(struct i802_bss *bss, int cts, int preamble, |
e5693c47 | 3564 | int slot, int ht_opmode, int ap_isolate, |
cae87abd | 3565 | const int *basic_rates) |
31357268 JM |
3566 | { |
3567 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
3568 | struct nl_msg *msg; | |
3569 | ||
13f83980 | 3570 | if (!(msg = nl80211_bss_msg(bss, 0, NL80211_CMD_SET_BSS)) || |
a862e4a3 JM |
3571 | (cts >= 0 && |
3572 | nla_put_u8(msg, NL80211_ATTR_BSS_CTS_PROT, cts)) || | |
3573 | (preamble >= 0 && | |
3574 | nla_put_u8(msg, NL80211_ATTR_BSS_SHORT_PREAMBLE, preamble)) || | |
3575 | (slot >= 0 && | |
3576 | nla_put_u8(msg, NL80211_ATTR_BSS_SHORT_SLOT_TIME, slot)) || | |
3577 | (ht_opmode >= 0 && | |
3578 | nla_put_u16(msg, NL80211_ATTR_BSS_HT_OPMODE, ht_opmode)) || | |
3579 | (ap_isolate >= 0 && | |
cae87abd JM |
3580 | nla_put_u8(msg, NL80211_ATTR_AP_ISOLATE, ap_isolate)) || |
3581 | nl80211_put_basic_rates(msg, basic_rates)) { | |
3582 | nlmsg_free(msg); | |
3583 | return -ENOBUFS; | |
e5693c47 JM |
3584 | } |
3585 | ||
31357268 | 3586 | return send_and_recv_msgs(drv, msg, NULL, NULL); |
31357268 JM |
3587 | } |
3588 | ||
3589 | ||
3c4ca363 VN |
3590 | static int wpa_driver_nl80211_set_acl(void *priv, |
3591 | struct hostapd_acl_params *params) | |
3592 | { | |
3593 | struct i802_bss *bss = priv; | |
3594 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
3595 | struct nl_msg *msg; | |
f429ec44 | 3596 | struct nl_msg *acl; |
3c4ca363 | 3597 | unsigned int i; |
a862e4a3 | 3598 | int ret; |
3c4ca363 VN |
3599 | |
3600 | if (!(drv->capa.max_acl_mac_addrs)) | |
3601 | return -ENOTSUP; | |
3602 | ||
3603 | if (params->num_mac_acl > drv->capa.max_acl_mac_addrs) | |
3604 | return -ENOTSUP; | |
3605 | ||
3c4ca363 VN |
3606 | wpa_printf(MSG_DEBUG, "nl80211: Set %s ACL (num_mac_acl=%u)", |
3607 | params->acl_policy ? "Accept" : "Deny", params->num_mac_acl); | |
3608 | ||
f429ec44 JM |
3609 | acl = nlmsg_alloc(); |
3610 | if (!acl) | |
3611 | return -ENOMEM; | |
3612 | for (i = 0; i < params->num_mac_acl; i++) { | |
3613 | if (nla_put(acl, i + 1, ETH_ALEN, params->mac_acl[i].addr)) { | |
3614 | nlmsg_free(acl); | |
3615 | return -ENOMEM; | |
3616 | } | |
3617 | } | |
3618 | ||
9725b784 | 3619 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_SET_MAC_ACL)) || |
a862e4a3 JM |
3620 | nla_put_u32(msg, NL80211_ATTR_ACL_POLICY, params->acl_policy ? |
3621 | NL80211_ACL_POLICY_DENY_UNLESS_LISTED : | |
3622 | NL80211_ACL_POLICY_ACCEPT_UNLESS_LISTED) || | |
f429ec44 | 3623 | nla_put_nested(msg, NL80211_ATTR_MAC_ADDRS, acl)) { |
a862e4a3 | 3624 | nlmsg_free(msg); |
f429ec44 | 3625 | nlmsg_free(acl); |
a862e4a3 JM |
3626 | return -ENOMEM; |
3627 | } | |
f429ec44 | 3628 | nlmsg_free(acl); |
3c4ca363 VN |
3629 | |
3630 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); | |
3c4ca363 VN |
3631 | if (ret) { |
3632 | wpa_printf(MSG_DEBUG, "nl80211: Failed to set MAC ACL: %d (%s)", | |
3633 | ret, strerror(-ret)); | |
3634 | } | |
3635 | ||
3c4ca363 VN |
3636 | return ret; |
3637 | } | |
3638 | ||
3639 | ||
85e1fad8 JM |
3640 | static int nl80211_put_beacon_int(struct nl_msg *msg, int beacon_int) |
3641 | { | |
3642 | if (beacon_int > 0) { | |
3643 | wpa_printf(MSG_DEBUG, " * beacon_int=%d", beacon_int); | |
3644 | return nla_put_u32(msg, NL80211_ATTR_BEACON_INTERVAL, | |
3645 | beacon_int); | |
3646 | } | |
3647 | ||
3648 | return 0; | |
3649 | } | |
3650 | ||
3651 | ||
4ac2ea57 MH |
3652 | static int nl80211_put_dtim_period(struct nl_msg *msg, int dtim_period) |
3653 | { | |
3654 | if (dtim_period > 0) { | |
3655 | wpa_printf(MSG_DEBUG, " * dtim_period=%d", dtim_period); | |
3656 | return nla_put_u32(msg, NL80211_ATTR_DTIM_PERIOD, dtim_period); | |
3657 | } | |
3658 | ||
3659 | return 0; | |
3660 | } | |
3661 | ||
3662 | ||
052b8d38 MH |
3663 | #ifdef CONFIG_MESH |
3664 | static int nl80211_set_mesh_config(void *priv, | |
3665 | struct wpa_driver_mesh_bss_params *params) | |
3666 | { | |
3667 | struct i802_bss *bss = priv; | |
3668 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
3669 | struct nl_msg *msg; | |
3670 | int ret; | |
3671 | ||
3672 | msg = nl80211_drv_msg(drv, 0, NL80211_CMD_SET_MESH_CONFIG); | |
3673 | if (!msg) | |
3674 | return -1; | |
3675 | ||
3676 | ret = nl80211_put_mesh_config(msg, params); | |
3677 | if (ret < 0) { | |
3678 | nlmsg_free(msg); | |
3679 | return ret; | |
3680 | } | |
3681 | ||
3682 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); | |
3683 | if (ret) { | |
3684 | wpa_printf(MSG_ERROR, | |
3685 | "nl80211: Mesh config set failed: %d (%s)", | |
3686 | ret, strerror(-ret)); | |
3687 | return ret; | |
3688 | } | |
3689 | return 0; | |
3690 | } | |
3691 | #endif /* CONFIG_MESH */ | |
3692 | ||
3693 | ||
d4f3003c PK |
3694 | static int nl80211_put_beacon_rate(struct nl_msg *msg, const u64 flags, |
3695 | struct wpa_driver_ap_params *params) | |
3696 | { | |
3697 | struct nlattr *bands, *band; | |
3698 | struct nl80211_txrate_vht vht_rate; | |
3699 | ||
3700 | if (!params->freq || | |
3701 | (params->beacon_rate == 0 && | |
3702 | params->rate_type == BEACON_RATE_LEGACY)) | |
3703 | return 0; | |
3704 | ||
3705 | bands = nla_nest_start(msg, NL80211_ATTR_TX_RATES); | |
3706 | if (!bands) | |
3707 | return -1; | |
3708 | ||
3709 | switch (params->freq->mode) { | |
3710 | case HOSTAPD_MODE_IEEE80211B: | |
3711 | case HOSTAPD_MODE_IEEE80211G: | |
3712 | band = nla_nest_start(msg, NL80211_BAND_2GHZ); | |
3713 | break; | |
3714 | case HOSTAPD_MODE_IEEE80211A: | |
3715 | band = nla_nest_start(msg, NL80211_BAND_5GHZ); | |
3716 | break; | |
3717 | case HOSTAPD_MODE_IEEE80211AD: | |
3718 | band = nla_nest_start(msg, NL80211_BAND_60GHZ); | |
3719 | break; | |
3720 | default: | |
3721 | return 0; | |
3722 | } | |
3723 | ||
3724 | if (!band) | |
3725 | return -1; | |
3726 | ||
3727 | os_memset(&vht_rate, 0, sizeof(vht_rate)); | |
3728 | ||
3729 | switch (params->rate_type) { | |
3730 | case BEACON_RATE_LEGACY: | |
3731 | if (!(flags & WPA_DRIVER_FLAGS_BEACON_RATE_LEGACY)) { | |
3732 | wpa_printf(MSG_INFO, | |
3733 | "nl80211: Driver does not support setting Beacon frame rate (legacy)"); | |
3734 | return -1; | |
3735 | } | |
3736 | ||
3737 | if (nla_put_u8(msg, NL80211_TXRATE_LEGACY, | |
3738 | (u8) params->beacon_rate / 5) || | |
3739 | nla_put(msg, NL80211_TXRATE_HT, 0, NULL) || | |
3740 | (params->freq->vht_enabled && | |
3741 | nla_put(msg, NL80211_TXRATE_VHT, sizeof(vht_rate), | |
3742 | &vht_rate))) | |
3743 | return -1; | |
3744 | ||
3745 | wpa_printf(MSG_DEBUG, " * beacon_rate = legacy:%u (* 100 kbps)", | |
3746 | params->beacon_rate); | |
3747 | break; | |
3748 | case BEACON_RATE_HT: | |
3749 | if (!(flags & WPA_DRIVER_FLAGS_BEACON_RATE_HT)) { | |
3750 | wpa_printf(MSG_INFO, | |
3751 | "nl80211: Driver does not support setting Beacon frame rate (HT)"); | |
3752 | return -1; | |
3753 | } | |
3754 | if (nla_put(msg, NL80211_TXRATE_LEGACY, 0, NULL) || | |
3755 | nla_put_u8(msg, NL80211_TXRATE_HT, params->beacon_rate) || | |
3756 | (params->freq->vht_enabled && | |
3757 | nla_put(msg, NL80211_TXRATE_VHT, sizeof(vht_rate), | |
3758 | &vht_rate))) | |
3759 | return -1; | |
3760 | wpa_printf(MSG_DEBUG, " * beacon_rate = HT-MCS %u", | |
3761 | params->beacon_rate); | |
3762 | break; | |
3763 | case BEACON_RATE_VHT: | |
3764 | if (!(flags & WPA_DRIVER_FLAGS_BEACON_RATE_VHT)) { | |
3765 | wpa_printf(MSG_INFO, | |
3766 | "nl80211: Driver does not support setting Beacon frame rate (VHT)"); | |
3767 | return -1; | |
3768 | } | |
3769 | vht_rate.mcs[0] = BIT(params->beacon_rate); | |
3770 | if (nla_put(msg, NL80211_TXRATE_LEGACY, 0, NULL)) | |
3771 | return -1; | |
3772 | if (nla_put(msg, NL80211_TXRATE_HT, 0, NULL)) | |
3773 | return -1; | |
3774 | if (nla_put(msg, NL80211_TXRATE_VHT, sizeof(vht_rate), | |
3775 | &vht_rate)) | |
3776 | return -1; | |
3777 | wpa_printf(MSG_DEBUG, " * beacon_rate = VHT-MCS %u", | |
3778 | params->beacon_rate); | |
3779 | break; | |
3780 | } | |
3781 | ||
3782 | nla_nest_end(msg, band); | |
3783 | nla_nest_end(msg, bands); | |
3784 | ||
3785 | return 0; | |
3786 | } | |
3787 | ||
3788 | ||
34f7c699 MB |
3789 | static int nl80211_set_multicast_to_unicast(struct i802_bss *bss, |
3790 | int multicast_to_unicast) | |
3791 | { | |
3792 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
3793 | struct nl_msg *msg; | |
3794 | int ret; | |
3795 | ||
3796 | msg = nl80211_bss_msg(bss, 0, NL80211_CMD_SET_MULTICAST_TO_UNICAST); | |
3797 | if (!msg || | |
3798 | (multicast_to_unicast && | |
3799 | nla_put_flag(msg, NL80211_ATTR_MULTICAST_TO_UNICAST_ENABLED))) { | |
3800 | wpa_printf(MSG_ERROR, | |
3801 | "nl80211: Failed to build NL80211_CMD_SET_MULTICAST_TO_UNICAST msg for %s", | |
3802 | bss->ifname); | |
3803 | nlmsg_free(msg); | |
3804 | return -ENOBUFS; | |
3805 | } | |
3806 | ||
3807 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); | |
3808 | ||
3809 | switch (ret) { | |
3810 | case 0: | |
3811 | wpa_printf(MSG_DEBUG, | |
3812 | "nl80211: multicast to unicast %s on interface %s", | |
3813 | multicast_to_unicast ? "enabled" : "disabled", | |
3814 | bss->ifname); | |
3815 | break; | |
3816 | case -EOPNOTSUPP: | |
3817 | if (!multicast_to_unicast) | |
3818 | break; | |
3819 | wpa_printf(MSG_INFO, | |
3820 | "nl80211: multicast to unicast not supported on interface %s", | |
3821 | bss->ifname); | |
3822 | break; | |
3823 | default: | |
3824 | wpa_printf(MSG_ERROR, | |
3825 | "nl80211: %s multicast to unicast failed with %d (%s) on interface %s", | |
3826 | multicast_to_unicast ? "enabling" : "disabling", | |
3827 | ret, strerror(-ret), bss->ifname); | |
3828 | break; | |
3829 | } | |
3830 | ||
3831 | return ret; | |
3832 | } | |
3833 | ||
3834 | ||
19c3b566 JM |
3835 | static int wpa_driver_nl80211_set_ap(void *priv, |
3836 | struct wpa_driver_ap_params *params) | |
d2440ba0 | 3837 | { |
a2e40bb6 FF |
3838 | struct i802_bss *bss = priv; |
3839 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
d2440ba0 JM |
3840 | struct nl_msg *msg; |
3841 | u8 cmd = NL80211_CMD_NEW_BEACON; | |
3842 | int ret; | |
b4fd6fab | 3843 | int beacon_set; |
b11d1d64 | 3844 | int num_suites; |
da1080d7 | 3845 | int smps_mode; |
de4ed4a8 | 3846 | u32 suites[10], suite; |
b11d1d64 | 3847 | u32 ver; |
052b8d38 MH |
3848 | #ifdef CONFIG_MESH |
3849 | struct wpa_driver_mesh_bss_params mesh_params; | |
3850 | #endif /* CONFIG_MESH */ | |
b4fd6fab | 3851 | |
f33c8606 | 3852 | beacon_set = params->reenable ? 0 : bss->beacon_set; |
d2440ba0 | 3853 | |
d2440ba0 | 3854 | wpa_printf(MSG_DEBUG, "nl80211: Set beacon (beacon_set=%d)", |
b4fd6fab JM |
3855 | beacon_set); |
3856 | if (beacon_set) | |
d2440ba0 | 3857 | cmd = NL80211_CMD_SET_BEACON; |
89fa633a DL |
3858 | else if (!drv->device_ap_sme && !drv->use_monitor && |
3859 | !nl80211_get_wiphy_data_ap(bss)) | |
a70cd0db | 3860 | return -ENOBUFS; |
d2440ba0 | 3861 | |
b92e08fc JM |
3862 | wpa_hexdump(MSG_DEBUG, "nl80211: Beacon head", |
3863 | params->head, params->head_len); | |
b92e08fc JM |
3864 | wpa_hexdump(MSG_DEBUG, "nl80211: Beacon tail", |
3865 | params->tail, params->tail_len); | |
13f83980 | 3866 | wpa_printf(MSG_DEBUG, "nl80211: ifindex=%d", bss->ifindex); |
b92e08fc | 3867 | wpa_printf(MSG_DEBUG, "nl80211: beacon_int=%d", params->beacon_int); |
d4f3003c PK |
3868 | wpa_printf(MSG_DEBUG, "nl80211: beacon_rate=%u", params->beacon_rate); |
3869 | wpa_printf(MSG_DEBUG, "nl80211: rate_type=%d", params->rate_type); | |
b92e08fc | 3870 | wpa_printf(MSG_DEBUG, "nl80211: dtim_period=%d", params->dtim_period); |
b92e08fc JM |
3871 | wpa_hexdump_ascii(MSG_DEBUG, "nl80211: ssid", |
3872 | params->ssid, params->ssid_len); | |
13f83980 | 3873 | if (!(msg = nl80211_bss_msg(bss, 0, cmd)) || |
a862e4a3 JM |
3874 | nla_put(msg, NL80211_ATTR_BEACON_HEAD, params->head_len, |
3875 | params->head) || | |
3876 | nla_put(msg, NL80211_ATTR_BEACON_TAIL, params->tail_len, | |
3877 | params->tail) || | |
85e1fad8 | 3878 | nl80211_put_beacon_int(msg, params->beacon_int) || |
d4f3003c | 3879 | nl80211_put_beacon_rate(msg, drv->capa.flags, params) || |
4ac2ea57 | 3880 | nl80211_put_dtim_period(msg, params->dtim_period) || |
a862e4a3 JM |
3881 | nla_put(msg, NL80211_ATTR_SSID, params->ssid_len, params->ssid)) |
3882 | goto fail; | |
b92e08fc JM |
3883 | if (params->proberesp && params->proberesp_len) { |
3884 | wpa_hexdump(MSG_DEBUG, "nl80211: proberesp (offload)", | |
3885 | params->proberesp, params->proberesp_len); | |
a862e4a3 JM |
3886 | if (nla_put(msg, NL80211_ATTR_PROBE_RESP, params->proberesp_len, |
3887 | params->proberesp)) | |
3888 | goto fail; | |
b92e08fc | 3889 | } |
97a7a0b5 JM |
3890 | switch (params->hide_ssid) { |
3891 | case NO_SSID_HIDING: | |
b92e08fc | 3892 | wpa_printf(MSG_DEBUG, "nl80211: hidden SSID not in use"); |
a862e4a3 JM |
3893 | if (nla_put_u32(msg, NL80211_ATTR_HIDDEN_SSID, |
3894 | NL80211_HIDDEN_SSID_NOT_IN_USE)) | |
3895 | goto fail; | |
97a7a0b5 JM |
3896 | break; |
3897 | case HIDDEN_SSID_ZERO_LEN: | |
b92e08fc | 3898 | wpa_printf(MSG_DEBUG, "nl80211: hidden SSID zero len"); |
a862e4a3 JM |
3899 | if (nla_put_u32(msg, NL80211_ATTR_HIDDEN_SSID, |
3900 | NL80211_HIDDEN_SSID_ZERO_LEN)) | |
3901 | goto fail; | |
97a7a0b5 JM |
3902 | break; |
3903 | case HIDDEN_SSID_ZERO_CONTENTS: | |
b92e08fc | 3904 | wpa_printf(MSG_DEBUG, "nl80211: hidden SSID zero contents"); |
a862e4a3 JM |
3905 | if (nla_put_u32(msg, NL80211_ATTR_HIDDEN_SSID, |
3906 | NL80211_HIDDEN_SSID_ZERO_CONTENTS)) | |
3907 | goto fail; | |
97a7a0b5 JM |
3908 | break; |
3909 | } | |
b92e08fc | 3910 | wpa_printf(MSG_DEBUG, "nl80211: privacy=%d", params->privacy); |
a862e4a3 JM |
3911 | if (params->privacy && |
3912 | nla_put_flag(msg, NL80211_ATTR_PRIVACY)) | |
3913 | goto fail; | |
b92e08fc | 3914 | wpa_printf(MSG_DEBUG, "nl80211: auth_algs=0x%x", params->auth_algs); |
b11d1d64 JM |
3915 | if ((params->auth_algs & (WPA_AUTH_ALG_OPEN | WPA_AUTH_ALG_SHARED)) == |
3916 | (WPA_AUTH_ALG_OPEN | WPA_AUTH_ALG_SHARED)) { | |
3917 | /* Leave out the attribute */ | |
a862e4a3 JM |
3918 | } else if (params->auth_algs & WPA_AUTH_ALG_SHARED) { |
3919 | if (nla_put_u32(msg, NL80211_ATTR_AUTH_TYPE, | |
3920 | NL80211_AUTHTYPE_SHARED_KEY)) | |
3921 | goto fail; | |
3922 | } else { | |
3923 | if (nla_put_u32(msg, NL80211_ATTR_AUTH_TYPE, | |
3924 | NL80211_AUTHTYPE_OPEN_SYSTEM)) | |
3925 | goto fail; | |
3926 | } | |
b11d1d64 | 3927 | |
b92e08fc | 3928 | wpa_printf(MSG_DEBUG, "nl80211: wpa_version=0x%x", params->wpa_version); |
b11d1d64 JM |
3929 | ver = 0; |
3930 | if (params->wpa_version & WPA_PROTO_WPA) | |
3931 | ver |= NL80211_WPA_VERSION_1; | |
3932 | if (params->wpa_version & WPA_PROTO_RSN) | |
3933 | ver |= NL80211_WPA_VERSION_2; | |
a862e4a3 JM |
3934 | if (ver && |
3935 | nla_put_u32(msg, NL80211_ATTR_WPA_VERSIONS, ver)) | |
3936 | goto fail; | |
b11d1d64 | 3937 | |
b92e08fc JM |
3938 | wpa_printf(MSG_DEBUG, "nl80211: key_mgmt_suites=0x%x", |
3939 | params->key_mgmt_suites); | |
b11d1d64 JM |
3940 | num_suites = 0; |
3941 | if (params->key_mgmt_suites & WPA_KEY_MGMT_IEEE8021X) | |
3aa24db9 | 3942 | suites[num_suites++] = RSN_AUTH_KEY_MGMT_UNSPEC_802_1X; |
b11d1d64 | 3943 | if (params->key_mgmt_suites & WPA_KEY_MGMT_PSK) |
3aa24db9 | 3944 | suites[num_suites++] = RSN_AUTH_KEY_MGMT_PSK_OVER_802_1X; |
a862e4a3 JM |
3945 | if (num_suites && |
3946 | nla_put(msg, NL80211_ATTR_AKM_SUITES, num_suites * sizeof(u32), | |
3947 | suites)) | |
3948 | goto fail; | |
b11d1d64 | 3949 | |
533fe09b | 3950 | if (params->key_mgmt_suites & WPA_KEY_MGMT_IEEE8021X_NO_WPA && |
e3429c0b JB |
3951 | (!params->pairwise_ciphers || |
3952 | params->pairwise_ciphers & (WPA_CIPHER_WEP104 | WPA_CIPHER_WEP40)) && | |
3953 | (nla_put_u16(msg, NL80211_ATTR_CONTROL_PORT_ETHERTYPE, ETH_P_PAE) || | |
3954 | nla_put_flag(msg, NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT))) | |
a862e4a3 | 3955 | goto fail; |
9f12614b | 3956 | |
b92e08fc JM |
3957 | wpa_printf(MSG_DEBUG, "nl80211: pairwise_ciphers=0x%x", |
3958 | params->pairwise_ciphers); | |
de4ed4a8 JM |
3959 | num_suites = wpa_cipher_to_cipher_suites(params->pairwise_ciphers, |
3960 | suites, ARRAY_SIZE(suites)); | |
a862e4a3 JM |
3961 | if (num_suites && |
3962 | nla_put(msg, NL80211_ATTR_CIPHER_SUITES_PAIRWISE, | |
3963 | num_suites * sizeof(u32), suites)) | |
3964 | goto fail; | |
b11d1d64 | 3965 | |
b92e08fc JM |
3966 | wpa_printf(MSG_DEBUG, "nl80211: group_cipher=0x%x", |
3967 | params->group_cipher); | |
de4ed4a8 | 3968 | suite = wpa_cipher_to_cipher_suite(params->group_cipher); |
a862e4a3 JM |
3969 | if (suite && |
3970 | nla_put_u32(msg, NL80211_ATTR_CIPHER_SUITE_GROUP, suite)) | |
3971 | goto fail; | |
d2440ba0 | 3972 | |
ee298f1b JM |
3973 | if (params->ht_opmode != -1) { |
3974 | switch (params->smps_mode) { | |
3975 | case HT_CAP_INFO_SMPS_DYNAMIC: | |
3976 | wpa_printf(MSG_DEBUG, "nl80211: SMPS mode - dynamic"); | |
3977 | smps_mode = NL80211_SMPS_DYNAMIC; | |
3978 | break; | |
3979 | case HT_CAP_INFO_SMPS_STATIC: | |
3980 | wpa_printf(MSG_DEBUG, "nl80211: SMPS mode - static"); | |
3981 | smps_mode = NL80211_SMPS_STATIC; | |
3982 | break; | |
3983 | default: | |
3984 | /* invalid - fallback to smps off */ | |
3985 | case HT_CAP_INFO_SMPS_DISABLED: | |
3986 | wpa_printf(MSG_DEBUG, "nl80211: SMPS mode - off"); | |
3987 | smps_mode = NL80211_SMPS_OFF; | |
3988 | break; | |
3989 | } | |
a2426829 | 3990 | if (nla_put_u8(msg, NL80211_ATTR_SMPS_MODE, smps_mode)) |
ee298f1b | 3991 | goto fail; |
da1080d7 | 3992 | } |
da1080d7 | 3993 | |
fb91db56 | 3994 | if (params->beacon_ies) { |
b92e08fc JM |
3995 | wpa_hexdump_buf(MSG_DEBUG, "nl80211: beacon_ies", |
3996 | params->beacon_ies); | |
a862e4a3 JM |
3997 | if (nla_put(msg, NL80211_ATTR_IE, |
3998 | wpabuf_len(params->beacon_ies), | |
3999 | wpabuf_head(params->beacon_ies))) | |
4000 | goto fail; | |
fb91db56 JM |
4001 | } |
4002 | if (params->proberesp_ies) { | |
b92e08fc JM |
4003 | wpa_hexdump_buf(MSG_DEBUG, "nl80211: proberesp_ies", |
4004 | params->proberesp_ies); | |
a862e4a3 JM |
4005 | if (nla_put(msg, NL80211_ATTR_IE_PROBE_RESP, |
4006 | wpabuf_len(params->proberesp_ies), | |
4007 | wpabuf_head(params->proberesp_ies))) | |
4008 | goto fail; | |
fb91db56 JM |
4009 | } |
4010 | if (params->assocresp_ies) { | |
b92e08fc JM |
4011 | wpa_hexdump_buf(MSG_DEBUG, "nl80211: assocresp_ies", |
4012 | params->assocresp_ies); | |
a862e4a3 JM |
4013 | if (nla_put(msg, NL80211_ATTR_IE_ASSOC_RESP, |
4014 | wpabuf_len(params->assocresp_ies), | |
4015 | wpabuf_head(params->assocresp_ies))) | |
4016 | goto fail; | |
fb91db56 JM |
4017 | } |
4018 | ||
a0133ee1 | 4019 | if (drv->capa.flags & WPA_DRIVER_FLAGS_INACTIVITY_TIMER) { |
b92e08fc JM |
4020 | wpa_printf(MSG_DEBUG, "nl80211: ap_max_inactivity=%d", |
4021 | params->ap_max_inactivity); | |
a862e4a3 JM |
4022 | if (nla_put_u16(msg, NL80211_ATTR_INACTIVITY_TIMEOUT, |
4023 | params->ap_max_inactivity)) | |
4024 | goto fail; | |
a0133ee1 VT |
4025 | } |
4026 | ||
abb8d08b EP |
4027 | #ifdef CONFIG_P2P |
4028 | if (params->p2p_go_ctwindow > 0) { | |
4029 | if (drv->p2p_go_ctwindow_supported) { | |
4030 | wpa_printf(MSG_DEBUG, "nl80211: P2P GO ctwindow=%d", | |
4031 | params->p2p_go_ctwindow); | |
4032 | if (nla_put_u8(msg, NL80211_ATTR_P2P_CTWINDOW, | |
4033 | params->p2p_go_ctwindow)) | |
4034 | goto fail; | |
4035 | } else { | |
4036 | wpa_printf(MSG_INFO, | |
4037 | "nl80211: Driver does not support CTWindow configuration - ignore this parameter"); | |
4038 | } | |
4039 | } | |
4040 | #endif /* CONFIG_P2P */ | |
4041 | ||
86b5c400 LD |
4042 | if (params->pbss) { |
4043 | wpa_printf(MSG_DEBUG, "nl80211: PBSS"); | |
4044 | if (nla_put_flag(msg, NL80211_ATTR_PBSS)) | |
4045 | goto fail; | |
4046 | } | |
4047 | ||
d2440ba0 JM |
4048 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
4049 | if (ret) { | |
4050 | wpa_printf(MSG_DEBUG, "nl80211: Beacon set failed: %d (%s)", | |
4051 | ret, strerror(-ret)); | |
b4fd6fab | 4052 | } else { |
b4fd6fab | 4053 | bss->beacon_set = 1; |
31357268 | 4054 | nl80211_set_bss(bss, params->cts_protect, params->preamble, |
d03e8d11 | 4055 | params->short_slot_time, params->ht_opmode, |
e5693c47 | 4056 | params->isolate, params->basic_rates); |
34f7c699 MB |
4057 | nl80211_set_multicast_to_unicast(bss, |
4058 | params->multicast_to_unicast); | |
e87ef751 PX |
4059 | if (beacon_set && params->freq && |
4060 | params->freq->bandwidth != bss->bandwidth) { | |
4061 | wpa_printf(MSG_DEBUG, | |
4062 | "nl80211: Update BSS %s bandwidth: %d -> %d", | |
4063 | bss->ifname, bss->bandwidth, | |
4064 | params->freq->bandwidth); | |
4065 | ret = nl80211_set_channel(bss, params->freq, 1); | |
4066 | if (ret) { | |
4067 | wpa_printf(MSG_DEBUG, | |
4068 | "nl80211: Frequency set failed: %d (%s)", | |
4069 | ret, strerror(-ret)); | |
4070 | } else { | |
4071 | wpa_printf(MSG_DEBUG, | |
4072 | "nl80211: Frequency set succeeded for ht2040 coex"); | |
4073 | bss->bandwidth = params->freq->bandwidth; | |
4074 | } | |
f5728d0a | 4075 | } else if (!beacon_set && params->freq) { |
e87ef751 PX |
4076 | /* |
4077 | * cfg80211 updates the driver on frequence change in AP | |
4078 | * mode only at the point when beaconing is started, so | |
4079 | * set the initial value here. | |
4080 | */ | |
4081 | bss->bandwidth = params->freq->bandwidth; | |
4082 | } | |
b4fd6fab | 4083 | } |
052b8d38 MH |
4084 | |
4085 | #ifdef CONFIG_MESH | |
4086 | if (is_mesh_interface(drv->nlmode) && params->ht_opmode != -1) { | |
4087 | os_memset(&mesh_params, 0, sizeof(mesh_params)); | |
4088 | mesh_params.flags |= WPA_DRIVER_MESH_CONF_FLAG_HT_OP_MODE; | |
4089 | mesh_params.ht_opmode = params->ht_opmode; | |
4090 | ret = nl80211_set_mesh_config(priv, &mesh_params); | |
4091 | if (ret < 0) | |
4092 | return ret; | |
4093 | } | |
4094 | #endif /* CONFIG_MESH */ | |
4095 | ||
d2440ba0 | 4096 | return ret; |
a862e4a3 | 4097 | fail: |
5883168a | 4098 | nlmsg_free(msg); |
d2440ba0 JM |
4099 | return -ENOBUFS; |
4100 | } | |
4101 | ||
4102 | ||
1c4ffa87 | 4103 | static int nl80211_put_freq_params(struct nl_msg *msg, |
72b2605f | 4104 | const struct hostapd_freq_params *freq) |
1581b38b | 4105 | { |
1fc4ab23 | 4106 | wpa_printf(MSG_DEBUG, " * freq=%d", freq->freq); |
a862e4a3 JM |
4107 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq->freq)) |
4108 | return -ENOBUFS; | |
4109 | ||
1fc4ab23 JM |
4110 | wpa_printf(MSG_DEBUG, " * vht_enabled=%d", freq->vht_enabled); |
4111 | wpa_printf(MSG_DEBUG, " * ht_enabled=%d", freq->ht_enabled); | |
4112 | ||
89b800d7 | 4113 | if (freq->vht_enabled) { |
a862e4a3 JM |
4114 | enum nl80211_chan_width cw; |
4115 | ||
1fc4ab23 | 4116 | wpa_printf(MSG_DEBUG, " * bandwidth=%d", freq->bandwidth); |
89b800d7 JB |
4117 | switch (freq->bandwidth) { |
4118 | case 20: | |
a862e4a3 | 4119 | cw = NL80211_CHAN_WIDTH_20; |
89b800d7 JB |
4120 | break; |
4121 | case 40: | |
a862e4a3 | 4122 | cw = NL80211_CHAN_WIDTH_40; |
89b800d7 JB |
4123 | break; |
4124 | case 80: | |
4125 | if (freq->center_freq2) | |
a862e4a3 | 4126 | cw = NL80211_CHAN_WIDTH_80P80; |
89b800d7 | 4127 | else |
a862e4a3 | 4128 | cw = NL80211_CHAN_WIDTH_80; |
89b800d7 JB |
4129 | break; |
4130 | case 160: | |
a862e4a3 | 4131 | cw = NL80211_CHAN_WIDTH_160; |
89b800d7 JB |
4132 | break; |
4133 | default: | |
1c4ffa87 | 4134 | return -EINVAL; |
89b800d7 | 4135 | } |
a862e4a3 | 4136 | |
1fc4ab23 JM |
4137 | wpa_printf(MSG_DEBUG, " * channel_width=%d", cw); |
4138 | wpa_printf(MSG_DEBUG, " * center_freq1=%d", | |
4139 | freq->center_freq1); | |
4140 | wpa_printf(MSG_DEBUG, " * center_freq2=%d", | |
4141 | freq->center_freq2); | |
a862e4a3 JM |
4142 | if (nla_put_u32(msg, NL80211_ATTR_CHANNEL_WIDTH, cw) || |
4143 | nla_put_u32(msg, NL80211_ATTR_CENTER_FREQ1, | |
4144 | freq->center_freq1) || | |
4145 | (freq->center_freq2 && | |
4146 | nla_put_u32(msg, NL80211_ATTR_CENTER_FREQ2, | |
4147 | freq->center_freq2))) | |
4148 | return -ENOBUFS; | |
89b800d7 | 4149 | } else if (freq->ht_enabled) { |
a862e4a3 JM |
4150 | enum nl80211_channel_type ct; |
4151 | ||
1fc4ab23 JM |
4152 | wpa_printf(MSG_DEBUG, " * sec_channel_offset=%d", |
4153 | freq->sec_channel_offset); | |
89b800d7 | 4154 | switch (freq->sec_channel_offset) { |
f019981a | 4155 | case -1: |
a862e4a3 | 4156 | ct = NL80211_CHAN_HT40MINUS; |
f019981a JM |
4157 | break; |
4158 | case 1: | |
a862e4a3 | 4159 | ct = NL80211_CHAN_HT40PLUS; |
f019981a JM |
4160 | break; |
4161 | default: | |
a862e4a3 | 4162 | ct = NL80211_CHAN_HT20; |
f019981a JM |
4163 | break; |
4164 | } | |
a862e4a3 | 4165 | |
1fc4ab23 | 4166 | wpa_printf(MSG_DEBUG, " * channel_type=%d", ct); |
a862e4a3 JM |
4167 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE, ct)) |
4168 | return -ENOBUFS; | |
3388e7b9 MH |
4169 | } else { |
4170 | wpa_printf(MSG_DEBUG, " * channel_type=%d", | |
4171 | NL80211_CHAN_NO_HT); | |
4172 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE, | |
4173 | NL80211_CHAN_NO_HT)) | |
4174 | return -ENOBUFS; | |
f019981a | 4175 | } |
1c4ffa87 | 4176 | return 0; |
1c4ffa87 AO |
4177 | } |
4178 | ||
4179 | ||
e87ef751 PX |
4180 | static int nl80211_set_channel(struct i802_bss *bss, |
4181 | struct hostapd_freq_params *freq, int set_chan) | |
1c4ffa87 AO |
4182 | { |
4183 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
4184 | struct nl_msg *msg; | |
4185 | int ret; | |
4186 | ||
4187 | wpa_printf(MSG_DEBUG, | |
4188 | "nl80211: Set freq %d (ht_enabled=%d, vht_enabled=%d, bandwidth=%d MHz, cf1=%d MHz, cf2=%d MHz)", | |
4189 | freq->freq, freq->ht_enabled, freq->vht_enabled, | |
4190 | freq->bandwidth, freq->center_freq1, freq->center_freq2); | |
1c4ffa87 | 4191 | |
9725b784 JM |
4192 | msg = nl80211_drv_msg(drv, 0, set_chan ? NL80211_CMD_SET_CHANNEL : |
4193 | NL80211_CMD_SET_WIPHY); | |
4194 | if (!msg || nl80211_put_freq_params(msg, freq) < 0) { | |
a862e4a3 JM |
4195 | nlmsg_free(msg); |
4196 | return -1; | |
4197 | } | |
1581b38b | 4198 | |
d2440ba0 | 4199 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
e4fb2167 | 4200 | if (ret == 0) { |
89b800d7 | 4201 | bss->freq = freq->freq; |
1581b38b | 4202 | return 0; |
e4fb2167 | 4203 | } |
f019981a | 4204 | wpa_printf(MSG_DEBUG, "nl80211: Failed to set channel (freq=%d): " |
89b800d7 | 4205 | "%d (%s)", freq->freq, ret, strerror(-ret)); |
1581b38b JM |
4206 | return -1; |
4207 | } | |
4208 | ||
0f4e8b4f | 4209 | |
95ab6063 AN |
4210 | static u32 sta_flags_nl80211(int flags) |
4211 | { | |
4212 | u32 f = 0; | |
4213 | ||
4214 | if (flags & WPA_STA_AUTHORIZED) | |
4215 | f |= BIT(NL80211_STA_FLAG_AUTHORIZED); | |
4216 | if (flags & WPA_STA_WMM) | |
4217 | f |= BIT(NL80211_STA_FLAG_WME); | |
4218 | if (flags & WPA_STA_SHORT_PREAMBLE) | |
4219 | f |= BIT(NL80211_STA_FLAG_SHORT_PREAMBLE); | |
4220 | if (flags & WPA_STA_MFP) | |
4221 | f |= BIT(NL80211_STA_FLAG_MFP); | |
45b722f1 AN |
4222 | if (flags & WPA_STA_TDLS_PEER) |
4223 | f |= BIT(NL80211_STA_FLAG_TDLS_PEER); | |
7a228b5c BC |
4224 | if (flags & WPA_STA_AUTHENTICATED) |
4225 | f |= BIT(NL80211_STA_FLAG_AUTHENTICATED); | |
dc55b6b6 AB |
4226 | if (flags & WPA_STA_ASSOCIATED) |
4227 | f |= BIT(NL80211_STA_FLAG_ASSOCIATED); | |
95ab6063 AN |
4228 | |
4229 | return f; | |
4230 | } | |
4231 | ||
4232 | ||
7c7e7877 BC |
4233 | #ifdef CONFIG_MESH |
4234 | static u32 sta_plink_state_nl80211(enum mesh_plink_state state) | |
4235 | { | |
4236 | switch (state) { | |
d02e5498 | 4237 | case PLINK_IDLE: |
7c7e7877 | 4238 | return NL80211_PLINK_LISTEN; |
d02e5498 | 4239 | case PLINK_OPN_SNT: |
7c7e7877 | 4240 | return NL80211_PLINK_OPN_SNT; |
d02e5498 | 4241 | case PLINK_OPN_RCVD: |
7c7e7877 BC |
4242 | return NL80211_PLINK_OPN_RCVD; |
4243 | case PLINK_CNF_RCVD: | |
4244 | return NL80211_PLINK_CNF_RCVD; | |
4245 | case PLINK_ESTAB: | |
4246 | return NL80211_PLINK_ESTAB; | |
4247 | case PLINK_HOLDING: | |
4248 | return NL80211_PLINK_HOLDING; | |
4249 | case PLINK_BLOCKED: | |
4250 | return NL80211_PLINK_BLOCKED; | |
4251 | default: | |
4252 | wpa_printf(MSG_ERROR, "nl80211: Invalid mesh plink state %d", | |
4253 | state); | |
4254 | } | |
4255 | return -1; | |
4256 | } | |
4257 | #endif /* CONFIG_MESH */ | |
4258 | ||
4259 | ||
62847751 | 4260 | static int wpa_driver_nl80211_sta_add(void *priv, |
0f4e8b4f JM |
4261 | struct hostapd_sta_add_params *params) |
4262 | { | |
a2e40bb6 FF |
4263 | struct i802_bss *bss = priv; |
4264 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
8970bae8 | 4265 | struct nl_msg *msg; |
95ab6063 | 4266 | struct nl80211_sta_flag_update upd; |
0f4e8b4f JM |
4267 | int ret = -ENOBUFS; |
4268 | ||
45b722f1 AN |
4269 | if ((params->flags & WPA_STA_TDLS_PEER) && |
4270 | !(drv->capa.flags & WPA_DRIVER_FLAGS_TDLS_SUPPORT)) | |
4271 | return -EOPNOTSUPP; | |
4272 | ||
e4dea253 JM |
4273 | wpa_printf(MSG_DEBUG, "nl80211: %s STA " MACSTR, |
4274 | params->set ? "Set" : "Add", MAC2STR(params->addr)); | |
13f83980 JM |
4275 | msg = nl80211_bss_msg(bss, 0, params->set ? NL80211_CMD_SET_STATION : |
4276 | NL80211_CMD_NEW_STATION); | |
4277 | if (!msg || nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, params->addr)) | |
a862e4a3 | 4278 | goto fail; |
5551bc9c | 4279 | |
dc55b6b6 AB |
4280 | /* |
4281 | * Set the below properties only in one of the following cases: | |
4282 | * 1. New station is added, already associated. | |
4283 | * 2. Set WPA_STA_TDLS_PEER station. | |
4284 | * 3. Set an already added unassociated station, if driver supports | |
4285 | * full AP client state. (Set these properties after station became | |
4286 | * associated will be rejected by the driver). | |
4287 | */ | |
4288 | if (!params->set || (params->flags & WPA_STA_TDLS_PEER) || | |
4289 | (params->set && FULL_AP_CLIENT_STATE_SUPP(drv->capa.flags) && | |
4290 | (params->flags & WPA_STA_ASSOCIATED))) { | |
5551bc9c BC |
4291 | wpa_hexdump(MSG_DEBUG, " * supported rates", |
4292 | params->supp_rates, params->supp_rates_len); | |
a862e4a3 JM |
4293 | wpa_printf(MSG_DEBUG, " * capability=0x%x", |
4294 | params->capability); | |
4295 | if (nla_put(msg, NL80211_ATTR_STA_SUPPORTED_RATES, | |
4296 | params->supp_rates_len, params->supp_rates) || | |
4297 | nla_put_u16(msg, NL80211_ATTR_STA_CAPABILITY, | |
4298 | params->capability)) | |
4299 | goto fail; | |
e503861f JM |
4300 | |
4301 | if (params->ht_capabilities) { | |
4302 | wpa_hexdump(MSG_DEBUG, " * ht_capabilities", | |
4303 | (u8 *) params->ht_capabilities, | |
4304 | sizeof(*params->ht_capabilities)); | |
a862e4a3 JM |
4305 | if (nla_put(msg, NL80211_ATTR_HT_CAPABILITY, |
4306 | sizeof(*params->ht_capabilities), | |
4307 | params->ht_capabilities)) | |
4308 | goto fail; | |
e503861f JM |
4309 | } |
4310 | ||
4311 | if (params->vht_capabilities) { | |
4312 | wpa_hexdump(MSG_DEBUG, " * vht_capabilities", | |
4313 | (u8 *) params->vht_capabilities, | |
4314 | sizeof(*params->vht_capabilities)); | |
a862e4a3 JM |
4315 | if (nla_put(msg, NL80211_ATTR_VHT_CAPABILITY, |
4316 | sizeof(*params->vht_capabilities), | |
4317 | params->vht_capabilities)) | |
4318 | goto fail; | |
e503861f JM |
4319 | } |
4320 | ||
e503861f JM |
4321 | if (params->ext_capab) { |
4322 | wpa_hexdump(MSG_DEBUG, " * ext_capab", | |
4323 | params->ext_capab, params->ext_capab_len); | |
a862e4a3 JM |
4324 | if (nla_put(msg, NL80211_ATTR_STA_EXT_CAPABILITY, |
4325 | params->ext_capab_len, params->ext_capab)) | |
4326 | goto fail; | |
e503861f | 4327 | } |
ae33239c AB |
4328 | |
4329 | if (is_ap_interface(drv->nlmode) && | |
4330 | nla_put_u8(msg, NL80211_ATTR_STA_SUPPORT_P2P_PS, | |
4331 | params->support_p2p_ps ? | |
4332 | NL80211_P2P_PS_SUPPORTED : | |
4333 | NL80211_P2P_PS_UNSUPPORTED)) | |
4334 | goto fail; | |
5551bc9c | 4335 | } |
45b722f1 | 4336 | if (!params->set) { |
f11b72c3 JM |
4337 | if (params->aid) { |
4338 | wpa_printf(MSG_DEBUG, " * aid=%u", params->aid); | |
a862e4a3 JM |
4339 | if (nla_put_u16(msg, NL80211_ATTR_STA_AID, params->aid)) |
4340 | goto fail; | |
f11b72c3 JM |
4341 | } else { |
4342 | /* | |
4343 | * cfg80211 validates that AID is non-zero, so we have | |
4344 | * to make this a non-zero value for the TDLS case where | |
dc55b6b6 AB |
4345 | * a dummy STA entry is used for now and for a station |
4346 | * that is still not associated. | |
f11b72c3 | 4347 | */ |
dc55b6b6 AB |
4348 | wpa_printf(MSG_DEBUG, " * aid=1 (%s workaround)", |
4349 | (params->flags & WPA_STA_TDLS_PEER) ? | |
4350 | "TDLS" : "UNASSOC_STA"); | |
a862e4a3 JM |
4351 | if (nla_put_u16(msg, NL80211_ATTR_STA_AID, 1)) |
4352 | goto fail; | |
f11b72c3 | 4353 | } |
e4dea253 JM |
4354 | wpa_printf(MSG_DEBUG, " * listen_interval=%u", |
4355 | params->listen_interval); | |
a862e4a3 JM |
4356 | if (nla_put_u16(msg, NL80211_ATTR_STA_LISTEN_INTERVAL, |
4357 | params->listen_interval)) | |
4358 | goto fail; | |
e112764e JM |
4359 | } else if (params->aid && (params->flags & WPA_STA_TDLS_PEER)) { |
4360 | wpa_printf(MSG_DEBUG, " * peer_aid=%u", params->aid); | |
a862e4a3 JM |
4361 | if (nla_put_u16(msg, NL80211_ATTR_PEER_AID, params->aid)) |
4362 | goto fail; | |
dc55b6b6 AB |
4363 | } else if (FULL_AP_CLIENT_STATE_SUPP(drv->capa.flags) && |
4364 | (params->flags & WPA_STA_ASSOCIATED)) { | |
4365 | wpa_printf(MSG_DEBUG, " * aid=%u", params->aid); | |
4366 | wpa_printf(MSG_DEBUG, " * listen_interval=%u", | |
4367 | params->listen_interval); | |
4368 | if (nla_put_u16(msg, NL80211_ATTR_STA_AID, params->aid) || | |
4369 | nla_put_u16(msg, NL80211_ATTR_STA_LISTEN_INTERVAL, | |
4370 | params->listen_interval)) | |
4371 | goto fail; | |
45b722f1 | 4372 | } |
05a8d422 | 4373 | |
8a458116 MK |
4374 | if (params->vht_opmode_enabled) { |
4375 | wpa_printf(MSG_DEBUG, " * opmode=%u", params->vht_opmode); | |
a862e4a3 JM |
4376 | if (nla_put_u8(msg, NL80211_ATTR_OPMODE_NOTIF, |
4377 | params->vht_opmode)) | |
4378 | goto fail; | |
8a458116 MK |
4379 | } |
4380 | ||
efc64886 SD |
4381 | if (params->supp_channels) { |
4382 | wpa_hexdump(MSG_DEBUG, " * supported channels", | |
4383 | params->supp_channels, params->supp_channels_len); | |
a862e4a3 JM |
4384 | if (nla_put(msg, NL80211_ATTR_STA_SUPPORTED_CHANNELS, |
4385 | params->supp_channels_len, params->supp_channels)) | |
4386 | goto fail; | |
efc64886 SD |
4387 | } |
4388 | ||
4389 | if (params->supp_oper_classes) { | |
4390 | wpa_hexdump(MSG_DEBUG, " * supported operating classes", | |
4391 | params->supp_oper_classes, | |
4392 | params->supp_oper_classes_len); | |
a862e4a3 JM |
4393 | if (nla_put(msg, NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES, |
4394 | params->supp_oper_classes_len, | |
4395 | params->supp_oper_classes)) | |
4396 | goto fail; | |
efc64886 SD |
4397 | } |
4398 | ||
95ab6063 | 4399 | os_memset(&upd, 0, sizeof(upd)); |
7e31703e BC |
4400 | upd.set = sta_flags_nl80211(params->flags); |
4401 | upd.mask = upd.set | sta_flags_nl80211(params->flags_mask); | |
dc55b6b6 AB |
4402 | |
4403 | /* | |
4404 | * If the driver doesn't support full AP client state, ignore ASSOC/AUTH | |
4405 | * flags, as nl80211 driver moves a new station, by default, into | |
4406 | * associated state. | |
4407 | * | |
4408 | * On the other hand, if the driver supports that feature and the | |
4409 | * station is added in unauthenticated state, set the | |
4410 | * authenticated/associated bits in the mask to prevent moving this | |
4411 | * station to associated state before it is actually associated. | |
4412 | * | |
4413 | * This is irrelevant for mesh mode where the station is added to the | |
4414 | * driver as authenticated already, and ASSOCIATED isn't part of the | |
4415 | * nl80211 API. | |
4416 | */ | |
4417 | if (!is_mesh_interface(drv->nlmode)) { | |
4418 | if (!FULL_AP_CLIENT_STATE_SUPP(drv->capa.flags)) { | |
4419 | wpa_printf(MSG_DEBUG, | |
4420 | "nl80211: Ignore ASSOC/AUTH flags since driver doesn't support full AP client state"); | |
4421 | upd.mask &= ~(BIT(NL80211_STA_FLAG_ASSOCIATED) | | |
4422 | BIT(NL80211_STA_FLAG_AUTHENTICATED)); | |
4423 | } else if (!params->set && | |
4424 | !(params->flags & WPA_STA_TDLS_PEER)) { | |
4425 | if (!(params->flags & WPA_STA_AUTHENTICATED)) | |
4426 | upd.mask |= BIT(NL80211_STA_FLAG_AUTHENTICATED); | |
4427 | if (!(params->flags & WPA_STA_ASSOCIATED)) | |
4428 | upd.mask |= BIT(NL80211_STA_FLAG_ASSOCIATED); | |
4429 | } | |
e347cafe MH |
4430 | #ifdef CONFIG_MESH |
4431 | } else { | |
4432 | if (params->plink_state == PLINK_ESTAB && params->peer_aid) { | |
4433 | ret = nla_put_u16(msg, NL80211_ATTR_MESH_PEER_AID, | |
4434 | params->peer_aid); | |
4435 | if (ret) | |
4436 | goto fail; | |
4437 | } | |
4438 | #endif /* CONFIG_MESH */ | |
dc55b6b6 AB |
4439 | } |
4440 | ||
e4dea253 JM |
4441 | wpa_printf(MSG_DEBUG, " * flags set=0x%x mask=0x%x", |
4442 | upd.set, upd.mask); | |
a862e4a3 JM |
4443 | if (nla_put(msg, NL80211_ATTR_STA_FLAGS2, sizeof(upd), &upd)) |
4444 | goto fail; | |
95ab6063 | 4445 | |
7c7e7877 | 4446 | #ifdef CONFIG_MESH |
a862e4a3 JM |
4447 | if (params->plink_state && |
4448 | nla_put_u8(msg, NL80211_ATTR_STA_PLINK_STATE, | |
4449 | sta_plink_state_nl80211(params->plink_state))) | |
4450 | goto fail; | |
7c7e7877 BC |
4451 | #endif /* CONFIG_MESH */ |
4452 | ||
774bfa62 | 4453 | if (params->flags & WPA_STA_WMM) { |
8970bae8 JB |
4454 | struct nlattr *wme = nla_nest_start(msg, NL80211_ATTR_STA_WME); |
4455 | ||
e4dea253 | 4456 | wpa_printf(MSG_DEBUG, " * qosinfo=0x%x", params->qosinfo); |
a862e4a3 JM |
4457 | if (!wme || |
4458 | nla_put_u8(msg, NL80211_STA_WME_UAPSD_QUEUES, | |
4459 | params->qosinfo & WMM_QOSINFO_STA_AC_MASK) || | |
4460 | nla_put_u8(msg, NL80211_STA_WME_MAX_SP, | |
4461 | (params->qosinfo >> WMM_QOSINFO_STA_SP_SHIFT) & | |
4462 | WMM_QOSINFO_STA_SP_MASK)) | |
4463 | goto fail; | |
8970bae8 | 4464 | nla_nest_end(msg, wme); |
774bfa62 EP |
4465 | } |
4466 | ||
0f4e8b4f | 4467 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
5883168a | 4468 | msg = NULL; |
0f4e8b4f | 4469 | if (ret) |
45b722f1 AN |
4470 | wpa_printf(MSG_DEBUG, "nl80211: NL80211_CMD_%s_STATION " |
4471 | "result: %d (%s)", params->set ? "SET" : "NEW", ret, | |
4472 | strerror(-ret)); | |
0f4e8b4f JM |
4473 | if (ret == -EEXIST) |
4474 | ret = 0; | |
a862e4a3 | 4475 | fail: |
5883168a | 4476 | nlmsg_free(msg); |
0f4e8b4f JM |
4477 | return ret; |
4478 | } | |
4479 | ||
4480 | ||
97ed9a06 KP |
4481 | static void rtnl_neigh_delete_fdb_entry(struct i802_bss *bss, const u8 *addr) |
4482 | { | |
4483 | #ifdef CONFIG_LIBNL3_ROUTE | |
4484 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
4485 | struct rtnl_neigh *rn; | |
4486 | struct nl_addr *nl_addr; | |
4487 | int err; | |
4488 | ||
4489 | rn = rtnl_neigh_alloc(); | |
4490 | if (!rn) | |
4491 | return; | |
4492 | ||
4493 | rtnl_neigh_set_family(rn, AF_BRIDGE); | |
4494 | rtnl_neigh_set_ifindex(rn, bss->ifindex); | |
4495 | nl_addr = nl_addr_build(AF_BRIDGE, (void *) addr, ETH_ALEN); | |
4496 | if (!nl_addr) { | |
4497 | rtnl_neigh_put(rn); | |
4498 | return; | |
4499 | } | |
4500 | rtnl_neigh_set_lladdr(rn, nl_addr); | |
4501 | ||
4502 | err = rtnl_neigh_delete(drv->rtnl_sk, rn, 0); | |
4503 | if (err < 0) { | |
4504 | wpa_printf(MSG_DEBUG, "nl80211: bridge FDB entry delete for " | |
4505 | MACSTR " ifindex=%d failed: %s", MAC2STR(addr), | |
4506 | bss->ifindex, nl_geterror(err)); | |
4507 | } else { | |
4508 | wpa_printf(MSG_DEBUG, "nl80211: deleted bridge FDB entry for " | |
4509 | MACSTR, MAC2STR(addr)); | |
4510 | } | |
4511 | ||
4512 | nl_addr_put(nl_addr); | |
4513 | rtnl_neigh_put(rn); | |
4514 | #endif /* CONFIG_LIBNL3_ROUTE */ | |
4515 | } | |
4516 | ||
4517 | ||
59d7148a JM |
4518 | static int wpa_driver_nl80211_sta_remove(struct i802_bss *bss, const u8 *addr, |
4519 | int deauth, u16 reason_code) | |
0f4e8b4f | 4520 | { |
a2e40bb6 | 4521 | struct wpa_driver_nl80211_data *drv = bss->drv; |
0f4e8b4f JM |
4522 | struct nl_msg *msg; |
4523 | int ret; | |
4524 | ||
13f83980 | 4525 | if (!(msg = nl80211_bss_msg(bss, 0, NL80211_CMD_DEL_STATION)) || |
a862e4a3 JM |
4526 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) || |
4527 | (deauth == 0 && | |
4528 | nla_put_u8(msg, NL80211_ATTR_MGMT_SUBTYPE, | |
4529 | WLAN_FC_STYPE_DISASSOC)) || | |
4530 | (deauth == 1 && | |
4531 | nla_put_u8(msg, NL80211_ATTR_MGMT_SUBTYPE, | |
4532 | WLAN_FC_STYPE_DEAUTH)) || | |
4533 | (reason_code && | |
4534 | nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason_code))) { | |
4535 | nlmsg_free(msg); | |
4536 | return -ENOBUFS; | |
4537 | } | |
0f4e8b4f JM |
4538 | |
4539 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); | |
83e7bb0e JM |
4540 | wpa_printf(MSG_DEBUG, "nl80211: sta_remove -> DEL_STATION %s " MACSTR |
4541 | " --> %d (%s)", | |
4542 | bss->ifname, MAC2STR(addr), ret, strerror(-ret)); | |
97ed9a06 KP |
4543 | |
4544 | if (drv->rtnl_sk) | |
4545 | rtnl_neigh_delete_fdb_entry(bss, addr); | |
4546 | ||
0f4e8b4f JM |
4547 | if (ret == -ENOENT) |
4548 | return 0; | |
4549 | return ret; | |
0f4e8b4f JM |
4550 | } |
4551 | ||
1581b38b | 4552 | |
f3407c66 | 4553 | void nl80211_remove_iface(struct wpa_driver_nl80211_data *drv, int ifidx) |
0915d02c JM |
4554 | { |
4555 | struct nl_msg *msg; | |
de884303 | 4556 | struct wpa_driver_nl80211_data *drv2; |
0915d02c | 4557 | |
c6e8e8e4 JM |
4558 | wpa_printf(MSG_DEBUG, "nl80211: Remove interface ifindex=%d", ifidx); |
4559 | ||
2135f224 | 4560 | /* stop listening for EAPOL on this interface */ |
de884303 JM |
4561 | dl_list_for_each(drv2, &drv->global->interfaces, |
4562 | struct wpa_driver_nl80211_data, list) | |
732b1d20 MB |
4563 | { |
4564 | del_ifidx(drv2, ifidx, IFIDX_ANY); | |
4565 | /* Remove all bridges learned for this iface */ | |
4566 | del_ifidx(drv2, IFIDX_ANY, ifidx); | |
4567 | } | |
2135f224 | 4568 | |
95376e1a | 4569 | msg = nl80211_ifindex_msg(drv, ifidx, 0, NL80211_CMD_DEL_INTERFACE); |
0915d02c JM |
4570 | if (send_and_recv_msgs(drv, msg, NULL, NULL) == 0) |
4571 | return; | |
e748062b | 4572 | wpa_printf(MSG_ERROR, "Failed to remove interface (ifidx=%d)", ifidx); |
0915d02c JM |
4573 | } |
4574 | ||
4575 | ||
cc9a2575 | 4576 | const char * nl80211_iftype_str(enum nl80211_iftype mode) |
a1922f93 JM |
4577 | { |
4578 | switch (mode) { | |
4579 | case NL80211_IFTYPE_ADHOC: | |
4580 | return "ADHOC"; | |
4581 | case NL80211_IFTYPE_STATION: | |
4582 | return "STATION"; | |
4583 | case NL80211_IFTYPE_AP: | |
4584 | return "AP"; | |
1045ec36 JM |
4585 | case NL80211_IFTYPE_AP_VLAN: |
4586 | return "AP_VLAN"; | |
4587 | case NL80211_IFTYPE_WDS: | |
4588 | return "WDS"; | |
a1922f93 JM |
4589 | case NL80211_IFTYPE_MONITOR: |
4590 | return "MONITOR"; | |
1045ec36 JM |
4591 | case NL80211_IFTYPE_MESH_POINT: |
4592 | return "MESH_POINT"; | |
a1922f93 JM |
4593 | case NL80211_IFTYPE_P2P_CLIENT: |
4594 | return "P2P_CLIENT"; | |
4595 | case NL80211_IFTYPE_P2P_GO: | |
4596 | return "P2P_GO"; | |
7aad838c NS |
4597 | case NL80211_IFTYPE_P2P_DEVICE: |
4598 | return "P2P_DEVICE"; | |
a1922f93 JM |
4599 | default: |
4600 | return "unknown"; | |
4601 | } | |
4602 | } | |
4603 | ||
4604 | ||
a35187e7 KH |
4605 | static int nl80211_create_iface_once(struct wpa_driver_nl80211_data *drv, |
4606 | const char *ifname, | |
4607 | enum nl80211_iftype iftype, | |
d6dcfcda DS |
4608 | const u8 *addr, int wds, |
4609 | int (*handler)(struct nl_msg *, void *), | |
4610 | void *arg) | |
0915d02c | 4611 | { |
8970bae8 | 4612 | struct nl_msg *msg; |
0915d02c JM |
4613 | int ifidx; |
4614 | int ret = -ENOBUFS; | |
4615 | ||
a1922f93 JM |
4616 | wpa_printf(MSG_DEBUG, "nl80211: Create interface iftype %d (%s)", |
4617 | iftype, nl80211_iftype_str(iftype)); | |
4618 | ||
56f77852 JM |
4619 | msg = nl80211_cmd_msg(drv->first_bss, 0, NL80211_CMD_NEW_INTERFACE); |
4620 | if (!msg || | |
a862e4a3 JM |
4621 | nla_put_string(msg, NL80211_ATTR_IFNAME, ifname) || |
4622 | nla_put_u32(msg, NL80211_ATTR_IFTYPE, iftype)) | |
4623 | goto fail; | |
0915d02c JM |
4624 | |
4625 | if (iftype == NL80211_IFTYPE_MONITOR) { | |
8970bae8 | 4626 | struct nlattr *flags; |
0915d02c | 4627 | |
8970bae8 | 4628 | flags = nla_nest_start(msg, NL80211_ATTR_MNTR_FLAGS); |
a862e4a3 JM |
4629 | if (!flags || |
4630 | nla_put_flag(msg, NL80211_MNTR_FLAG_COOK_FRAMES)) | |
4631 | goto fail; | |
0915d02c | 4632 | |
8970bae8 | 4633 | nla_nest_end(msg, flags); |
fbbfcbac | 4634 | } else if (wds) { |
a862e4a3 JM |
4635 | if (nla_put_u8(msg, NL80211_ATTR_4ADDR, wds)) |
4636 | goto fail; | |
0915d02c JM |
4637 | } |
4638 | ||
52f5877a IP |
4639 | /* |
4640 | * Tell cfg80211 that the interface belongs to the socket that created | |
4641 | * it, and the interface should be deleted when the socket is closed. | |
4642 | */ | |
a862e4a3 JM |
4643 | if (nla_put_flag(msg, NL80211_ATTR_IFACE_SOCKET_OWNER)) |
4644 | goto fail; | |
52f5877a | 4645 | |
d6dcfcda | 4646 | ret = send_and_recv_msgs(drv, msg, handler, arg); |
5883168a | 4647 | msg = NULL; |
0915d02c | 4648 | if (ret) { |
a862e4a3 | 4649 | fail: |
5883168a | 4650 | nlmsg_free(msg); |
a35187e7 KH |
4651 | wpa_printf(MSG_ERROR, "Failed to create interface %s: %d (%s)", |
4652 | ifname, ret, strerror(-ret)); | |
0915d02c JM |
4653 | return ret; |
4654 | } | |
4655 | ||
f632e483 | 4656 | if (iftype == NL80211_IFTYPE_P2P_DEVICE) |
6bae92e0 | 4657 | return 0; |
6bae92e0 | 4658 | |
0915d02c | 4659 | ifidx = if_nametoindex(ifname); |
c6e8e8e4 JM |
4660 | wpa_printf(MSG_DEBUG, "nl80211: New interface %s created: ifindex=%d", |
4661 | ifname, ifidx); | |
0915d02c JM |
4662 | |
4663 | if (ifidx <= 0) | |
4664 | return -1; | |
4665 | ||
147848ec JM |
4666 | /* |
4667 | * Some virtual interfaces need to process EAPOL packets and events on | |
4668 | * the parent interface. This is used mainly with hostapd. | |
4669 | */ | |
4670 | if (drv->hostapd || | |
4671 | iftype == NL80211_IFTYPE_AP_VLAN || | |
4672 | iftype == NL80211_IFTYPE_WDS || | |
4673 | iftype == NL80211_IFTYPE_MONITOR) { | |
4674 | /* start listening for EAPOL on this interface */ | |
732b1d20 | 4675 | add_ifidx(drv, ifidx, IFIDX_ANY); |
147848ec | 4676 | } |
2135f224 | 4677 | |
7bfc47c3 | 4678 | if (addr && iftype != NL80211_IFTYPE_MONITOR && |
c81eff1a | 4679 | linux_set_ifhwaddr(drv->global->ioctl_sock, ifname, addr)) { |
41d931ee JM |
4680 | nl80211_remove_iface(drv, ifidx); |
4681 | return -1; | |
2135f224 | 4682 | } |
2135f224 | 4683 | |
0915d02c JM |
4684 | return ifidx; |
4685 | } | |
22a7c9d7 JM |
4686 | |
4687 | ||
f3407c66 JM |
4688 | int nl80211_create_iface(struct wpa_driver_nl80211_data *drv, |
4689 | const char *ifname, enum nl80211_iftype iftype, | |
4690 | const u8 *addr, int wds, | |
4691 | int (*handler)(struct nl_msg *, void *), | |
4692 | void *arg, int use_existing) | |
a35187e7 KH |
4693 | { |
4694 | int ret; | |
4695 | ||
d6dcfcda DS |
4696 | ret = nl80211_create_iface_once(drv, ifname, iftype, addr, wds, handler, |
4697 | arg); | |
a35187e7 | 4698 | |
ffbf1eaa | 4699 | /* if error occurred and interface exists already */ |
a35187e7 | 4700 | if (ret == -ENFILE && if_nametoindex(ifname)) { |
2aec4f3c JM |
4701 | if (use_existing) { |
4702 | wpa_printf(MSG_DEBUG, "nl80211: Continue using existing interface %s", | |
4703 | ifname); | |
6997f8ba JM |
4704 | if (addr && iftype != NL80211_IFTYPE_MONITOR && |
4705 | linux_set_ifhwaddr(drv->global->ioctl_sock, ifname, | |
4706 | addr) < 0 && | |
4707 | (linux_set_iface_flags(drv->global->ioctl_sock, | |
4708 | ifname, 0) < 0 || | |
4709 | linux_set_ifhwaddr(drv->global->ioctl_sock, ifname, | |
4710 | addr) < 0 || | |
4711 | linux_set_iface_flags(drv->global->ioctl_sock, | |
4712 | ifname, 1) < 0)) | |
4713 | return -1; | |
2aec4f3c JM |
4714 | return -ENFILE; |
4715 | } | |
a35187e7 KH |
4716 | wpa_printf(MSG_INFO, "Try to remove and re-create %s", ifname); |
4717 | ||
4718 | /* Try to remove the interface that was already there. */ | |
4719 | nl80211_remove_iface(drv, if_nametoindex(ifname)); | |
4720 | ||
4721 | /* Try to create the interface again */ | |
fbbfcbac | 4722 | ret = nl80211_create_iface_once(drv, ifname, iftype, addr, |
d6dcfcda | 4723 | wds, handler, arg); |
a35187e7 KH |
4724 | } |
4725 | ||
3e208481 JM |
4726 | if (ret >= 0 && is_p2p_net_interface(iftype)) { |
4727 | wpa_printf(MSG_DEBUG, | |
4728 | "nl80211: Interface %s created for P2P - disable 11b rates", | |
4729 | ifname); | |
4e5cb1a3 | 4730 | nl80211_disable_11b_rates(drv, ret, 1); |
3e208481 | 4731 | } |
4e5cb1a3 | 4732 | |
a35187e7 KH |
4733 | return ret; |
4734 | } | |
0915d02c | 4735 | |
2135f224 | 4736 | |
3fd1cefb JB |
4737 | static int nl80211_setup_ap(struct i802_bss *bss) |
4738 | { | |
4739 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
4740 | ||
748c0ac0 JM |
4741 | wpa_printf(MSG_DEBUG, "nl80211: Setup AP(%s) - device_ap_sme=%d use_monitor=%d", |
4742 | bss->ifname, drv->device_ap_sme, drv->use_monitor); | |
36488c05 | 4743 | |
a11241fa JB |
4744 | /* |
4745 | * Disable Probe Request reporting unless we need it in this way for | |
4746 | * devices that include the AP SME, in the other case (unless using | |
4747 | * monitor iface) we'll get it through the nl_mgmt socket instead. | |
4748 | */ | |
4749 | if (!drv->device_ap_sme) | |
4750 | wpa_driver_nl80211_probe_req_report(bss, 0); | |
4751 | ||
4752 | if (!drv->device_ap_sme && !drv->use_monitor) | |
4753 | if (nl80211_mgmt_subscribe_ap(bss)) | |
4754 | return -1; | |
4755 | ||
a6cc0602 JM |
4756 | if (drv->device_ap_sme && !drv->use_monitor) |
4757 | if (nl80211_mgmt_subscribe_ap_dev_sme(bss)) | |
f4830bed RM |
4758 | wpa_printf(MSG_DEBUG, |
4759 | "nl80211: Failed to subscribe for mgmt frames from SME driver - trying to run without it"); | |
a6cc0602 | 4760 | |
a11241fa | 4761 | if (!drv->device_ap_sme && drv->use_monitor && |
ea19b39f RM |
4762 | nl80211_create_monitor_interface(drv) && |
4763 | !drv->device_ap_sme) | |
3fd1cefb JB |
4764 | return -1; |
4765 | ||
4766 | if (drv->device_ap_sme && | |
4767 | wpa_driver_nl80211_probe_req_report(bss, 1) < 0) { | |
4768 | wpa_printf(MSG_DEBUG, "nl80211: Failed to enable " | |
4769 | "Probe Request frame reporting in AP mode"); | |
4770 | /* Try to survive without this */ | |
4771 | } | |
4772 | ||
4773 | return 0; | |
4774 | } | |
4775 | ||
4776 | ||
4777 | static void nl80211_teardown_ap(struct i802_bss *bss) | |
4778 | { | |
4779 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
4780 | ||
748c0ac0 JM |
4781 | wpa_printf(MSG_DEBUG, "nl80211: Teardown AP(%s) - device_ap_sme=%d use_monitor=%d", |
4782 | bss->ifname, drv->device_ap_sme, drv->use_monitor); | |
a6cc0602 | 4783 | if (drv->device_ap_sme) { |
3fd1cefb | 4784 | wpa_driver_nl80211_probe_req_report(bss, 0); |
a6cc0602 JM |
4785 | if (!drv->use_monitor) |
4786 | nl80211_mgmt_unsubscribe(bss, "AP teardown (dev SME)"); | |
4787 | } else if (drv->use_monitor) | |
3fd1cefb | 4788 | nl80211_remove_monitor_interface(drv); |
a11241fa | 4789 | else |
36488c05 | 4790 | nl80211_mgmt_unsubscribe(bss, "AP teardown"); |
a11241fa | 4791 | |
a70cd0db | 4792 | nl80211_put_wiphy_data_ap(bss); |
3fd1cefb JB |
4793 | bss->beacon_set = 0; |
4794 | } | |
4795 | ||
4796 | ||
f10bfc9a JM |
4797 | static int nl80211_send_eapol_data(struct i802_bss *bss, |
4798 | const u8 *addr, const u8 *data, | |
d12dab4c | 4799 | size_t data_len) |
f10bfc9a | 4800 | { |
d12dab4c JB |
4801 | struct sockaddr_ll ll; |
4802 | int ret; | |
4803 | ||
4804 | if (bss->drv->eapol_tx_sock < 0) { | |
4805 | wpa_printf(MSG_DEBUG, "nl80211: No socket to send EAPOL"); | |
f10bfc9a JM |
4806 | return -1; |
4807 | } | |
4808 | ||
d12dab4c JB |
4809 | os_memset(&ll, 0, sizeof(ll)); |
4810 | ll.sll_family = AF_PACKET; | |
4811 | ll.sll_ifindex = bss->ifindex; | |
4812 | ll.sll_protocol = htons(ETH_P_PAE); | |
4813 | ll.sll_halen = ETH_ALEN; | |
4814 | os_memcpy(ll.sll_addr, addr, ETH_ALEN); | |
4815 | ret = sendto(bss->drv->eapol_tx_sock, data, data_len, 0, | |
4816 | (struct sockaddr *) &ll, sizeof(ll)); | |
4817 | if (ret < 0) | |
4818 | wpa_printf(MSG_ERROR, "nl80211: EAPOL TX: %s", | |
4819 | strerror(errno)); | |
4820 | ||
4821 | return ret; | |
f10bfc9a | 4822 | } |
5fb1a232 | 4823 | |
f10bfc9a | 4824 | |
db149ac9 JM |
4825 | static const u8 rfc1042_header[6] = { 0xaa, 0xaa, 0x03, 0x00, 0x00, 0x00 }; |
4826 | ||
4827 | static int wpa_driver_nl80211_hapd_send_eapol( | |
4828 | void *priv, const u8 *addr, const u8 *data, | |
4378fc14 | 4829 | size_t data_len, int encrypt, const u8 *own_addr, u32 flags) |
db149ac9 | 4830 | { |
a2e40bb6 FF |
4831 | struct i802_bss *bss = priv; |
4832 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
db149ac9 JM |
4833 | struct ieee80211_hdr *hdr; |
4834 | size_t len; | |
4835 | u8 *pos; | |
4836 | int res; | |
4378fc14 | 4837 | int qos = flags & WPA_STA_WMM; |
db149ac9 | 4838 | |
a11241fa | 4839 | if (drv->device_ap_sme || !drv->use_monitor) |
d12dab4c | 4840 | return nl80211_send_eapol_data(bss, addr, data, data_len); |
f10bfc9a | 4841 | |
db149ac9 JM |
4842 | len = sizeof(*hdr) + (qos ? 2 : 0) + sizeof(rfc1042_header) + 2 + |
4843 | data_len; | |
4844 | hdr = os_zalloc(len); | |
4845 | if (hdr == NULL) { | |
7ac3616d JM |
4846 | wpa_printf(MSG_INFO, "nl80211: Failed to allocate EAPOL buffer(len=%lu)", |
4847 | (unsigned long) len); | |
db149ac9 JM |
4848 | return -1; |
4849 | } | |
4850 | ||
4851 | hdr->frame_control = | |
4852 | IEEE80211_FC(WLAN_FC_TYPE_DATA, WLAN_FC_STYPE_DATA); | |
4853 | hdr->frame_control |= host_to_le16(WLAN_FC_FROMDS); | |
4854 | if (encrypt) | |
4855 | hdr->frame_control |= host_to_le16(WLAN_FC_ISWEP); | |
db149ac9 JM |
4856 | if (qos) { |
4857 | hdr->frame_control |= | |
4858 | host_to_le16(WLAN_FC_STYPE_QOS_DATA << 4); | |
4859 | } | |
db149ac9 JM |
4860 | |
4861 | memcpy(hdr->IEEE80211_DA_FROMDS, addr, ETH_ALEN); | |
4862 | memcpy(hdr->IEEE80211_BSSID_FROMDS, own_addr, ETH_ALEN); | |
4863 | memcpy(hdr->IEEE80211_SA_FROMDS, own_addr, ETH_ALEN); | |
4864 | pos = (u8 *) (hdr + 1); | |
4865 | ||
db149ac9 | 4866 | if (qos) { |
92d521d8 FF |
4867 | /* Set highest priority in QoS header */ |
4868 | pos[0] = 7; | |
db149ac9 JM |
4869 | pos[1] = 0; |
4870 | pos += 2; | |
4871 | } | |
db149ac9 JM |
4872 | |
4873 | memcpy(pos, rfc1042_header, sizeof(rfc1042_header)); | |
4874 | pos += sizeof(rfc1042_header); | |
4875 | WPA_PUT_BE16(pos, ETH_P_PAE); | |
4876 | pos += 2; | |
4877 | memcpy(pos, data, data_len); | |
4878 | ||
55231068 | 4879 | res = wpa_driver_nl80211_send_frame(bss, (u8 *) hdr, len, encrypt, 0, |
2d3943ce | 4880 | 0, 0, 0, 0, NULL, 0); |
db149ac9 JM |
4881 | if (res < 0) { |
4882 | wpa_printf(MSG_ERROR, "i802_send_eapol - packet len: %lu - " | |
4883 | "failed: %d (%s)", | |
4884 | (unsigned long) len, errno, strerror(errno)); | |
4885 | } | |
7bf12757 | 4886 | os_free(hdr); |
db149ac9 JM |
4887 | |
4888 | return res; | |
4889 | } | |
4890 | ||
a8d6ffa4 | 4891 | |
3234cba4 | 4892 | static int wpa_driver_nl80211_sta_set_flags(void *priv, const u8 *addr, |
f97e3ce4 JM |
4893 | unsigned int total_flags, |
4894 | unsigned int flags_or, | |
4895 | unsigned int flags_and) | |
a8d6ffa4 | 4896 | { |
a2e40bb6 | 4897 | struct i802_bss *bss = priv; |
8970bae8 JB |
4898 | struct nl_msg *msg; |
4899 | struct nlattr *flags; | |
7e76ee9c | 4900 | struct nl80211_sta_flag_update upd; |
a8d6ffa4 | 4901 | |
0cd9846c JM |
4902 | wpa_printf(MSG_DEBUG, "nl80211: Set STA flags - ifname=%s addr=" MACSTR |
4903 | " total_flags=0x%x flags_or=0x%x flags_and=0x%x authorized=%d", | |
4904 | bss->ifname, MAC2STR(addr), total_flags, flags_or, flags_and, | |
4905 | !!(total_flags & WPA_STA_AUTHORIZED)); | |
4906 | ||
13f83980 | 4907 | if (!(msg = nl80211_bss_msg(bss, 0, NL80211_CMD_SET_STATION)) || |
a862e4a3 JM |
4908 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) |
4909 | goto fail; | |
a8d6ffa4 | 4910 | |
7e76ee9c JM |
4911 | /* |
4912 | * Backwards compatibility version using NL80211_ATTR_STA_FLAGS. This | |
4913 | * can be removed eventually. | |
4914 | */ | |
8970bae8 | 4915 | flags = nla_nest_start(msg, NL80211_ATTR_STA_FLAGS); |
a862e4a3 JM |
4916 | if (!flags || |
4917 | ((total_flags & WPA_STA_AUTHORIZED) && | |
4918 | nla_put_flag(msg, NL80211_STA_FLAG_AUTHORIZED)) || | |
4919 | ((total_flags & WPA_STA_WMM) && | |
4920 | nla_put_flag(msg, NL80211_STA_FLAG_WME)) || | |
4921 | ((total_flags & WPA_STA_SHORT_PREAMBLE) && | |
4922 | nla_put_flag(msg, NL80211_STA_FLAG_SHORT_PREAMBLE)) || | |
4923 | ((total_flags & WPA_STA_MFP) && | |
4924 | nla_put_flag(msg, NL80211_STA_FLAG_MFP)) || | |
4925 | ((total_flags & WPA_STA_TDLS_PEER) && | |
4926 | nla_put_flag(msg, NL80211_STA_FLAG_TDLS_PEER))) | |
4927 | goto fail; | |
45b722f1 | 4928 | |
8970bae8 | 4929 | nla_nest_end(msg, flags); |
a8d6ffa4 | 4930 | |
7e76ee9c JM |
4931 | os_memset(&upd, 0, sizeof(upd)); |
4932 | upd.mask = sta_flags_nl80211(flags_or | ~flags_and); | |
4933 | upd.set = sta_flags_nl80211(flags_or); | |
a862e4a3 JM |
4934 | if (nla_put(msg, NL80211_ATTR_STA_FLAGS2, sizeof(upd), &upd)) |
4935 | goto fail; | |
7e76ee9c | 4936 | |
13f83980 | 4937 | return send_and_recv_msgs(bss->drv, msg, NULL, NULL); |
a862e4a3 | 4938 | fail: |
5883168a | 4939 | nlmsg_free(msg); |
a8d6ffa4 JM |
4940 | return -ENOBUFS; |
4941 | } | |
4942 | ||
0915d02c | 4943 | |
1581b38b JM |
4944 | static int wpa_driver_nl80211_ap(struct wpa_driver_nl80211_data *drv, |
4945 | struct wpa_driver_associate_params *params) | |
4946 | { | |
708bc8e0 | 4947 | enum nl80211_iftype nlmode, old_mode; |
b1f625e0 EP |
4948 | |
4949 | if (params->p2p) { | |
046b26a2 JM |
4950 | wpa_printf(MSG_DEBUG, "nl80211: Setup AP operations for P2P " |
4951 | "group (GO)"); | |
b1f625e0 EP |
4952 | nlmode = NL80211_IFTYPE_P2P_GO; |
4953 | } else | |
4954 | nlmode = NL80211_IFTYPE_AP; | |
4955 | ||
708bc8e0 | 4956 | old_mode = drv->nlmode; |
834ee56f | 4957 | if (wpa_driver_nl80211_set_mode(drv->first_bss, nlmode)) { |
708bc8e0 JM |
4958 | nl80211_remove_monitor_interface(drv); |
4959 | return -1; | |
4960 | } | |
4961 | ||
6e9023ea JM |
4962 | if (params->freq.freq && |
4963 | nl80211_set_channel(drv->first_bss, ¶ms->freq, 0)) { | |
708bc8e0 | 4964 | if (old_mode != nlmode) |
834ee56f | 4965 | wpa_driver_nl80211_set_mode(drv->first_bss, old_mode); |
460456f8 | 4966 | nl80211_remove_monitor_interface(drv); |
1581b38b | 4967 | return -1; |
0915d02c | 4968 | } |
1581b38b | 4969 | |
1581b38b JM |
4970 | return 0; |
4971 | } | |
1581b38b JM |
4972 | |
4973 | ||
666e508c JM |
4974 | static int nl80211_leave_ibss(struct wpa_driver_nl80211_data *drv, |
4975 | int reset_mode) | |
5cc4d64b JM |
4976 | { |
4977 | struct nl_msg *msg; | |
9725b784 | 4978 | int ret; |
a862e4a3 | 4979 | |
9725b784 | 4980 | msg = nl80211_drv_msg(drv, 0, NL80211_CMD_LEAVE_IBSS); |
5cc4d64b | 4981 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
5cc4d64b JM |
4982 | if (ret) { |
4983 | wpa_printf(MSG_DEBUG, "nl80211: Leave IBSS failed: ret=%d " | |
4984 | "(%s)", ret, strerror(-ret)); | |
9725b784 JM |
4985 | } else { |
4986 | wpa_printf(MSG_DEBUG, | |
4987 | "nl80211: Leave IBSS request sent successfully"); | |
5cc4d64b JM |
4988 | } |
4989 | ||
666e508c JM |
4990 | if (reset_mode && |
4991 | wpa_driver_nl80211_set_mode(drv->first_bss, | |
5d4c78fb JM |
4992 | NL80211_IFTYPE_STATION)) { |
4993 | wpa_printf(MSG_INFO, "nl80211: Failed to set interface into " | |
4994 | "station mode"); | |
4995 | } | |
4996 | ||
5cc4d64b JM |
4997 | return ret; |
4998 | } | |
4999 | ||
5000 | ||
95ff3069 JD |
5001 | static int nl80211_ht_vht_overrides(struct nl_msg *msg, |
5002 | struct wpa_driver_associate_params *params) | |
5003 | { | |
5004 | if (params->disable_ht && nla_put_flag(msg, NL80211_ATTR_DISABLE_HT)) | |
5005 | return -1; | |
5006 | ||
5007 | if (params->htcaps && params->htcaps_mask) { | |
5008 | int sz = sizeof(struct ieee80211_ht_capabilities); | |
5009 | wpa_hexdump(MSG_DEBUG, " * htcaps", params->htcaps, sz); | |
5010 | wpa_hexdump(MSG_DEBUG, " * htcaps_mask", | |
5011 | params->htcaps_mask, sz); | |
5012 | if (nla_put(msg, NL80211_ATTR_HT_CAPABILITY, sz, | |
5013 | params->htcaps) || | |
5014 | nla_put(msg, NL80211_ATTR_HT_CAPABILITY_MASK, sz, | |
5015 | params->htcaps_mask)) | |
5016 | return -1; | |
5017 | } | |
5018 | ||
5019 | #ifdef CONFIG_VHT_OVERRIDES | |
5020 | if (params->disable_vht) { | |
5021 | wpa_printf(MSG_DEBUG, " * VHT disabled"); | |
5022 | if (nla_put_flag(msg, NL80211_ATTR_DISABLE_VHT)) | |
5023 | return -1; | |
5024 | } | |
5025 | ||
5026 | if (params->vhtcaps && params->vhtcaps_mask) { | |
5027 | int sz = sizeof(struct ieee80211_vht_capabilities); | |
5028 | wpa_hexdump(MSG_DEBUG, " * vhtcaps", params->vhtcaps, sz); | |
5029 | wpa_hexdump(MSG_DEBUG, " * vhtcaps_mask", | |
5030 | params->vhtcaps_mask, sz); | |
5031 | if (nla_put(msg, NL80211_ATTR_VHT_CAPABILITY, sz, | |
5032 | params->vhtcaps) || | |
5033 | nla_put(msg, NL80211_ATTR_VHT_CAPABILITY_MASK, sz, | |
5034 | params->vhtcaps_mask)) | |
5035 | return -1; | |
5036 | } | |
5037 | #endif /* CONFIG_VHT_OVERRIDES */ | |
5038 | ||
5039 | return 0; | |
5040 | } | |
5041 | ||
5042 | ||
5cc4d64b JM |
5043 | static int wpa_driver_nl80211_ibss(struct wpa_driver_nl80211_data *drv, |
5044 | struct wpa_driver_associate_params *params) | |
5045 | { | |
5046 | struct nl_msg *msg; | |
5047 | int ret = -1; | |
5048 | int count = 0; | |
5049 | ||
5050 | wpa_printf(MSG_DEBUG, "nl80211: Join IBSS (ifindex=%d)", drv->ifindex); | |
5051 | ||
4ec68377 | 5052 | if (wpa_driver_nl80211_set_mode_ibss(drv->first_bss, ¶ms->freq)) { |
5cc4d64b JM |
5053 | wpa_printf(MSG_INFO, "nl80211: Failed to set interface into " |
5054 | "IBSS mode"); | |
5055 | return -1; | |
5056 | } | |
5057 | ||
5058 | retry: | |
9725b784 | 5059 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_JOIN_IBSS)) || |
a862e4a3 JM |
5060 | params->ssid == NULL || params->ssid_len > sizeof(drv->ssid)) |
5061 | goto fail; | |
5cc4d64b JM |
5062 | |
5063 | wpa_hexdump_ascii(MSG_DEBUG, " * SSID", | |
5064 | params->ssid, params->ssid_len); | |
a862e4a3 JM |
5065 | if (nla_put(msg, NL80211_ATTR_SSID, params->ssid_len, params->ssid)) |
5066 | goto fail; | |
5cc4d64b JM |
5067 | os_memcpy(drv->ssid, params->ssid, params->ssid_len); |
5068 | drv->ssid_len = params->ssid_len; | |
5069 | ||
85e1fad8 JM |
5070 | if (nl80211_put_freq_params(msg, ¶ms->freq) < 0 || |
5071 | nl80211_put_beacon_int(msg, params->beacon_int)) | |
a862e4a3 | 5072 | goto fail; |
5cc4d64b JM |
5073 | |
5074 | ret = nl80211_set_conn_keys(params, msg); | |
5075 | if (ret) | |
a862e4a3 | 5076 | goto fail; |
5cc4d64b | 5077 | |
913e3cf7 NC |
5078 | if (params->bssid && params->fixed_bssid) { |
5079 | wpa_printf(MSG_DEBUG, " * BSSID=" MACSTR, | |
5080 | MAC2STR(params->bssid)); | |
a862e4a3 JM |
5081 | if (nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, params->bssid)) |
5082 | goto fail; | |
913e3cf7 NC |
5083 | } |
5084 | ||
4d9e6fba JD |
5085 | if (params->fixed_freq) { |
5086 | wpa_printf(MSG_DEBUG, " * fixed_freq"); | |
5087 | if (nla_put_flag(msg, NL80211_ATTR_FREQ_FIXED)) | |
5088 | goto fail; | |
5089 | } | |
5090 | ||
4848a38d JM |
5091 | if (params->key_mgmt_suite == WPA_KEY_MGMT_IEEE8021X || |
5092 | params->key_mgmt_suite == WPA_KEY_MGMT_PSK || | |
5093 | params->key_mgmt_suite == WPA_KEY_MGMT_IEEE8021X_SHA256 || | |
5094 | params->key_mgmt_suite == WPA_KEY_MGMT_PSK_SHA256) { | |
e640888c | 5095 | wpa_printf(MSG_DEBUG, " * control port"); |
a862e4a3 JM |
5096 | if (nla_put_flag(msg, NL80211_ATTR_CONTROL_PORT)) |
5097 | goto fail; | |
e640888c AQ |
5098 | } |
5099 | ||
a95795ad JM |
5100 | if (params->wpa_ie) { |
5101 | wpa_hexdump(MSG_DEBUG, | |
5102 | " * Extra IEs for Beacon/Probe Response frames", | |
5103 | params->wpa_ie, params->wpa_ie_len); | |
a862e4a3 JM |
5104 | if (nla_put(msg, NL80211_ATTR_IE, params->wpa_ie_len, |
5105 | params->wpa_ie)) | |
5106 | goto fail; | |
a95795ad JM |
5107 | } |
5108 | ||
e15dcf6d PK |
5109 | ret = nl80211_ht_vht_overrides(msg, params); |
5110 | if (ret < 0) | |
5111 | goto fail; | |
95ff3069 | 5112 | |
5cc4d64b JM |
5113 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
5114 | msg = NULL; | |
5115 | if (ret) { | |
5116 | wpa_printf(MSG_DEBUG, "nl80211: Join IBSS failed: ret=%d (%s)", | |
5117 | ret, strerror(-ret)); | |
5118 | count++; | |
5119 | if (ret == -EALREADY && count == 1) { | |
5120 | wpa_printf(MSG_DEBUG, "nl80211: Retry IBSS join after " | |
5121 | "forced leave"); | |
666e508c | 5122 | nl80211_leave_ibss(drv, 0); |
5cc4d64b JM |
5123 | nlmsg_free(msg); |
5124 | goto retry; | |
5125 | } | |
a862e4a3 JM |
5126 | } else { |
5127 | wpa_printf(MSG_DEBUG, | |
5128 | "nl80211: Join IBSS request sent successfully"); | |
5cc4d64b | 5129 | } |
5cc4d64b | 5130 | |
a862e4a3 | 5131 | fail: |
5cc4d64b JM |
5132 | nlmsg_free(msg); |
5133 | return ret; | |
5134 | } | |
5135 | ||
5136 | ||
ad295f3b VK |
5137 | static int nl80211_put_fils_connect_params(struct wpa_driver_nl80211_data *drv, |
5138 | struct wpa_driver_associate_params *params, | |
5139 | struct nl_msg *msg) | |
5140 | { | |
5141 | if (params->fils_erp_username_len) { | |
5142 | wpa_hexdump_ascii(MSG_DEBUG, " * FILS ERP EMSKname/username", | |
5143 | params->fils_erp_username, | |
5144 | params->fils_erp_username_len); | |
5145 | if (nla_put(msg, NL80211_ATTR_FILS_ERP_USERNAME, | |
5146 | params->fils_erp_username_len, | |
5147 | params->fils_erp_username)) | |
5148 | return -1; | |
5149 | } | |
5150 | ||
5151 | if (params->fils_erp_realm_len) { | |
5152 | wpa_hexdump_ascii(MSG_DEBUG, " * FILS ERP Realm", | |
5153 | params->fils_erp_realm, | |
5154 | params->fils_erp_realm_len); | |
5155 | if (nla_put(msg, NL80211_ATTR_FILS_ERP_REALM, | |
5156 | params->fils_erp_realm_len, params->fils_erp_realm)) | |
5157 | return -1; | |
5158 | } | |
5159 | ||
5160 | wpa_printf(MSG_DEBUG, " * FILS ERP next seq %u", | |
5161 | params->fils_erp_next_seq_num); | |
5162 | if (nla_put_u16(msg, NL80211_ATTR_FILS_ERP_NEXT_SEQ_NUM, | |
5163 | params->fils_erp_next_seq_num)) | |
5164 | return -1; | |
5165 | ||
5166 | if (params->fils_erp_rrk_len) { | |
5167 | wpa_printf(MSG_DEBUG, " * FILS ERP rRK (len=%lu)", | |
5168 | (unsigned long) params->fils_erp_rrk_len); | |
5169 | if (nla_put(msg, NL80211_ATTR_FILS_ERP_RRK, | |
5170 | params->fils_erp_rrk_len, params->fils_erp_rrk)) | |
5171 | return -1; | |
5172 | } | |
5173 | ||
5174 | return 0; | |
5175 | } | |
5176 | ||
5177 | ||
a0bdd191 JM |
5178 | static int nl80211_connect_common(struct wpa_driver_nl80211_data *drv, |
5179 | struct wpa_driver_associate_params *params, | |
5180 | struct nl_msg *msg) | |
cfaab580 | 5181 | { |
c85dfc6f JM |
5182 | if (nla_put_flag(msg, NL80211_ATTR_IFACE_SOCKET_OWNER)) |
5183 | return -1; | |
5184 | ||
cfaab580 ZY |
5185 | if (params->bssid) { |
5186 | wpa_printf(MSG_DEBUG, " * bssid=" MACSTR, | |
5187 | MAC2STR(params->bssid)); | |
a862e4a3 JM |
5188 | if (nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, params->bssid)) |
5189 | return -1; | |
cfaab580 | 5190 | } |
a0bdd191 | 5191 | |
7ac7fd43 DS |
5192 | if (params->bssid_hint) { |
5193 | wpa_printf(MSG_DEBUG, " * bssid_hint=" MACSTR, | |
5194 | MAC2STR(params->bssid_hint)); | |
a862e4a3 JM |
5195 | if (nla_put(msg, NL80211_ATTR_MAC_HINT, ETH_ALEN, |
5196 | params->bssid_hint)) | |
5197 | return -1; | |
7ac7fd43 DS |
5198 | } |
5199 | ||
4ec68377 JD |
5200 | if (params->freq.freq) { |
5201 | wpa_printf(MSG_DEBUG, " * freq=%d", params->freq.freq); | |
a862e4a3 JM |
5202 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, |
5203 | params->freq.freq)) | |
5204 | return -1; | |
4ec68377 | 5205 | drv->assoc_freq = params->freq.freq; |
30158a0d SD |
5206 | } else |
5207 | drv->assoc_freq = 0; | |
a0bdd191 | 5208 | |
7ac7fd43 DS |
5209 | if (params->freq_hint) { |
5210 | wpa_printf(MSG_DEBUG, " * freq_hint=%d", params->freq_hint); | |
a862e4a3 JM |
5211 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ_HINT, |
5212 | params->freq_hint)) | |
5213 | return -1; | |
7ac7fd43 DS |
5214 | } |
5215 | ||
1f6c0ab8 BS |
5216 | if (params->bg_scan_period >= 0) { |
5217 | wpa_printf(MSG_DEBUG, " * bg scan period=%d", | |
5218 | params->bg_scan_period); | |
a862e4a3 JM |
5219 | if (nla_put_u16(msg, NL80211_ATTR_BG_SCAN_PERIOD, |
5220 | params->bg_scan_period)) | |
5221 | return -1; | |
1f6c0ab8 | 5222 | } |
a0bdd191 | 5223 | |
cfaab580 ZY |
5224 | if (params->ssid) { |
5225 | wpa_hexdump_ascii(MSG_DEBUG, " * SSID", | |
5226 | params->ssid, params->ssid_len); | |
a862e4a3 JM |
5227 | if (nla_put(msg, NL80211_ATTR_SSID, params->ssid_len, |
5228 | params->ssid)) | |
5229 | return -1; | |
cfaab580 | 5230 | if (params->ssid_len > sizeof(drv->ssid)) |
a862e4a3 | 5231 | return -1; |
cfaab580 ZY |
5232 | os_memcpy(drv->ssid, params->ssid, params->ssid_len); |
5233 | drv->ssid_len = params->ssid_len; | |
5234 | } | |
a0bdd191 | 5235 | |
cfaab580 | 5236 | wpa_hexdump(MSG_DEBUG, " * IEs", params->wpa_ie, params->wpa_ie_len); |
a862e4a3 JM |
5237 | if (params->wpa_ie && |
5238 | nla_put(msg, NL80211_ATTR_IE, params->wpa_ie_len, params->wpa_ie)) | |
5239 | return -1; | |
cfaab580 | 5240 | |
64fa840a JM |
5241 | if (params->wpa_proto) { |
5242 | enum nl80211_wpa_versions ver = 0; | |
cfaab580 | 5243 | |
64fa840a JM |
5244 | if (params->wpa_proto & WPA_PROTO_WPA) |
5245 | ver |= NL80211_WPA_VERSION_1; | |
5246 | if (params->wpa_proto & WPA_PROTO_RSN) | |
5247 | ver |= NL80211_WPA_VERSION_2; | |
cfaab580 | 5248 | |
64fa840a | 5249 | wpa_printf(MSG_DEBUG, " * WPA Versions 0x%x", ver); |
a862e4a3 JM |
5250 | if (nla_put_u32(msg, NL80211_ATTR_WPA_VERSIONS, ver)) |
5251 | return -1; | |
cfaab580 ZY |
5252 | } |
5253 | ||
4848a38d | 5254 | if (params->pairwise_suite != WPA_CIPHER_NONE) { |
a0bdd191 JM |
5255 | u32 cipher = wpa_cipher_to_cipher_suite(params->pairwise_suite); |
5256 | wpa_printf(MSG_DEBUG, " * pairwise=0x%x", cipher); | |
a862e4a3 JM |
5257 | if (nla_put_u32(msg, NL80211_ATTR_CIPHER_SUITES_PAIRWISE, |
5258 | cipher)) | |
5259 | return -1; | |
cfaab580 ZY |
5260 | } |
5261 | ||
ae6f9272 JM |
5262 | if (params->group_suite == WPA_CIPHER_GTK_NOT_USED && |
5263 | !(drv->capa.enc & WPA_DRIVER_CAPA_ENC_GTK_NOT_USED)) { | |
5264 | /* | |
5265 | * This is likely to work even though many drivers do not | |
5266 | * advertise support for operations without GTK. | |
5267 | */ | |
5268 | wpa_printf(MSG_DEBUG, " * skip group cipher configuration for GTK_NOT_USED due to missing driver support advertisement"); | |
5269 | } else if (params->group_suite != WPA_CIPHER_NONE) { | |
a0bdd191 JM |
5270 | u32 cipher = wpa_cipher_to_cipher_suite(params->group_suite); |
5271 | wpa_printf(MSG_DEBUG, " * group=0x%x", cipher); | |
a862e4a3 JM |
5272 | if (nla_put_u32(msg, NL80211_ATTR_CIPHER_SUITE_GROUP, cipher)) |
5273 | return -1; | |
cfaab580 ZY |
5274 | } |
5275 | ||
4848a38d JM |
5276 | if (params->key_mgmt_suite == WPA_KEY_MGMT_IEEE8021X || |
5277 | params->key_mgmt_suite == WPA_KEY_MGMT_PSK || | |
5278 | params->key_mgmt_suite == WPA_KEY_MGMT_FT_IEEE8021X || | |
5279 | params->key_mgmt_suite == WPA_KEY_MGMT_FT_PSK || | |
163f801e | 5280 | params->key_mgmt_suite == WPA_KEY_MGMT_CCKM || |
8802326f JJ |
5281 | params->key_mgmt_suite == WPA_KEY_MGMT_OSEN || |
5282 | params->key_mgmt_suite == WPA_KEY_MGMT_IEEE8021X_SHA256 || | |
666497c8 | 5283 | params->key_mgmt_suite == WPA_KEY_MGMT_PSK_SHA256 || |
5e3b5197 | 5284 | params->key_mgmt_suite == WPA_KEY_MGMT_IEEE8021X_SUITE_B || |
ad295f3b VK |
5285 | params->key_mgmt_suite == WPA_KEY_MGMT_IEEE8021X_SUITE_B_192 || |
5286 | params->key_mgmt_suite == WPA_KEY_MGMT_FILS_SHA256 || | |
5287 | params->key_mgmt_suite == WPA_KEY_MGMT_FILS_SHA384 || | |
5288 | params->key_mgmt_suite == WPA_KEY_MGMT_FT_FILS_SHA256 || | |
e005725a SD |
5289 | params->key_mgmt_suite == WPA_KEY_MGMT_FT_FILS_SHA384 || |
5290 | params->key_mgmt_suite == WPA_KEY_MGMT_OWE || | |
5291 | params->key_mgmt_suite == WPA_KEY_MGMT_DPP) { | |
3aa24db9 | 5292 | int mgmt = RSN_AUTH_KEY_MGMT_PSK_OVER_802_1X; |
cfaab580 ZY |
5293 | |
5294 | switch (params->key_mgmt_suite) { | |
4848a38d | 5295 | case WPA_KEY_MGMT_CCKM: |
3aa24db9 | 5296 | mgmt = RSN_AUTH_KEY_MGMT_CCKM; |
369c8d7b | 5297 | break; |
4848a38d | 5298 | case WPA_KEY_MGMT_IEEE8021X: |
3aa24db9 | 5299 | mgmt = RSN_AUTH_KEY_MGMT_UNSPEC_802_1X; |
cfaab580 | 5300 | break; |
4848a38d | 5301 | case WPA_KEY_MGMT_FT_IEEE8021X: |
3aa24db9 | 5302 | mgmt = RSN_AUTH_KEY_MGMT_FT_802_1X; |
6a1ce395 | 5303 | break; |
4848a38d | 5304 | case WPA_KEY_MGMT_FT_PSK: |
3aa24db9 | 5305 | mgmt = RSN_AUTH_KEY_MGMT_FT_PSK; |
6a1ce395 | 5306 | break; |
8802326f | 5307 | case WPA_KEY_MGMT_IEEE8021X_SHA256: |
3aa24db9 | 5308 | mgmt = RSN_AUTH_KEY_MGMT_802_1X_SHA256; |
8802326f JJ |
5309 | break; |
5310 | case WPA_KEY_MGMT_PSK_SHA256: | |
3aa24db9 | 5311 | mgmt = RSN_AUTH_KEY_MGMT_PSK_SHA256; |
8802326f | 5312 | break; |
163f801e | 5313 | case WPA_KEY_MGMT_OSEN: |
3aa24db9 | 5314 | mgmt = RSN_AUTH_KEY_MGMT_OSEN; |
163f801e | 5315 | break; |
666497c8 | 5316 | case WPA_KEY_MGMT_IEEE8021X_SUITE_B: |
3aa24db9 | 5317 | mgmt = RSN_AUTH_KEY_MGMT_802_1X_SUITE_B; |
666497c8 | 5318 | break; |
5e3b5197 | 5319 | case WPA_KEY_MGMT_IEEE8021X_SUITE_B_192: |
3aa24db9 | 5320 | mgmt = RSN_AUTH_KEY_MGMT_802_1X_SUITE_B_192; |
5e3b5197 | 5321 | break; |
ad295f3b VK |
5322 | case WPA_KEY_MGMT_FILS_SHA256: |
5323 | mgmt = RSN_AUTH_KEY_MGMT_FILS_SHA256; | |
5324 | break; | |
5325 | case WPA_KEY_MGMT_FILS_SHA384: | |
5326 | mgmt = RSN_AUTH_KEY_MGMT_FILS_SHA384; | |
5327 | break; | |
5328 | case WPA_KEY_MGMT_FT_FILS_SHA256: | |
5329 | mgmt = RSN_AUTH_KEY_MGMT_FT_FILS_SHA256; | |
5330 | break; | |
5331 | case WPA_KEY_MGMT_FT_FILS_SHA384: | |
5332 | mgmt = RSN_AUTH_KEY_MGMT_FT_FILS_SHA384; | |
5333 | break; | |
e005725a SD |
5334 | case WPA_KEY_MGMT_OWE: |
5335 | mgmt = RSN_AUTH_KEY_MGMT_OWE; | |
5336 | break; | |
5337 | case WPA_KEY_MGMT_DPP: | |
5338 | mgmt = RSN_AUTH_KEY_MGMT_DPP; | |
5339 | break; | |
4848a38d | 5340 | case WPA_KEY_MGMT_PSK: |
cfaab580 | 5341 | default: |
3aa24db9 | 5342 | mgmt = RSN_AUTH_KEY_MGMT_PSK_OVER_802_1X; |
cfaab580 ZY |
5343 | break; |
5344 | } | |
163f801e | 5345 | wpa_printf(MSG_DEBUG, " * akm=0x%x", mgmt); |
a862e4a3 JM |
5346 | if (nla_put_u32(msg, NL80211_ATTR_AKM_SUITES, mgmt)) |
5347 | return -1; | |
cfaab580 ZY |
5348 | } |
5349 | ||
a862e4a3 JM |
5350 | if (nla_put_flag(msg, NL80211_ATTR_CONTROL_PORT)) |
5351 | return -1; | |
a0bdd191 | 5352 | |
e3429c0b JB |
5353 | if (params->key_mgmt_suite == WPA_KEY_MGMT_IEEE8021X_NO_WPA && |
5354 | (params->pairwise_suite == WPA_CIPHER_NONE || | |
5355 | params->pairwise_suite == WPA_CIPHER_WEP104 || | |
5356 | params->pairwise_suite == WPA_CIPHER_WEP40) && | |
5357 | (nla_put_u16(msg, NL80211_ATTR_CONTROL_PORT_ETHERTYPE, ETH_P_PAE) || | |
5358 | nla_put_flag(msg, NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT))) | |
5359 | return -1; | |
5360 | ||
a862e4a3 JM |
5361 | if (params->mgmt_frame_protection == MGMT_FRAME_PROTECTION_REQUIRED && |
5362 | nla_put_u32(msg, NL80211_ATTR_USE_MFP, NL80211_MFP_REQUIRED)) | |
5363 | return -1; | |
a565084f | 5364 | |
58162adf AK |
5365 | if (params->rrm_used) { |
5366 | u32 drv_rrm_flags = drv->capa.rrm_flags; | |
b5d172e5 BL |
5367 | if ((!((drv_rrm_flags & |
5368 | WPA_DRIVER_FLAGS_DS_PARAM_SET_IE_IN_PROBES) && | |
5369 | (drv_rrm_flags & WPA_DRIVER_FLAGS_QUIET)) && | |
5370 | !(drv_rrm_flags & WPA_DRIVER_FLAGS_SUPPORT_RRM)) || | |
a862e4a3 JM |
5371 | nla_put_flag(msg, NL80211_ATTR_USE_RRM)) |
5372 | return -1; | |
58162adf AK |
5373 | } |
5374 | ||
95ff3069 | 5375 | if (nl80211_ht_vht_overrides(msg, params) < 0) |
a862e4a3 | 5376 | return -1; |
80e8a5ee | 5377 | |
a0bdd191 JM |
5378 | if (params->p2p) |
5379 | wpa_printf(MSG_DEBUG, " * P2P group"); | |
5380 | ||
86b5c400 LD |
5381 | if (params->pbss) { |
5382 | wpa_printf(MSG_DEBUG, " * PBSS"); | |
5383 | if (nla_put_flag(msg, NL80211_ATTR_PBSS)) | |
5384 | return -1; | |
5385 | } | |
5386 | ||
1126c078 | 5387 | drv->connect_reassoc = 0; |
00c3c4ac JM |
5388 | if (params->prev_bssid) { |
5389 | wpa_printf(MSG_DEBUG, " * prev_bssid=" MACSTR, | |
5390 | MAC2STR(params->prev_bssid)); | |
5391 | if (nla_put(msg, NL80211_ATTR_PREV_BSSID, ETH_ALEN, | |
5392 | params->prev_bssid)) | |
5393 | return -1; | |
1126c078 | 5394 | drv->connect_reassoc = 1; |
00c3c4ac JM |
5395 | } |
5396 | ||
ad295f3b VK |
5397 | if ((params->auth_alg & WPA_AUTH_ALG_FILS) && |
5398 | nl80211_put_fils_connect_params(drv, params, msg) != 0) | |
5399 | return -1; | |
5400 | ||
ba71cb82 SD |
5401 | if ((params->auth_alg & WPA_AUTH_ALG_SAE) && |
5402 | (!(drv->capa.flags & WPA_DRIVER_FLAGS_SME)) && | |
5403 | nla_put_flag(msg, NL80211_ATTR_EXTERNAL_AUTH_SUPPORT)) | |
5404 | return -1; | |
5405 | ||
a0bdd191 | 5406 | return 0; |
a0bdd191 JM |
5407 | } |
5408 | ||
5409 | ||
5410 | static int wpa_driver_nl80211_try_connect( | |
5411 | struct wpa_driver_nl80211_data *drv, | |
40a68f33 SD |
5412 | struct wpa_driver_associate_params *params, |
5413 | struct nl_handle *nl_connect) | |
a0bdd191 JM |
5414 | { |
5415 | struct nl_msg *msg; | |
5416 | enum nl80211_auth_type type; | |
5417 | int ret; | |
5418 | int algs; | |
5419 | ||
b658547d | 5420 | #ifdef CONFIG_DRIVER_NL80211_QCA |
b41f2684 CL |
5421 | if (params->req_key_mgmt_offload && params->psk && |
5422 | (params->key_mgmt_suite == WPA_KEY_MGMT_PSK || | |
5423 | params->key_mgmt_suite == WPA_KEY_MGMT_PSK_SHA256 || | |
5424 | params->key_mgmt_suite == WPA_KEY_MGMT_FT_PSK)) { | |
5425 | wpa_printf(MSG_DEBUG, "nl80211: Key management set PSK"); | |
5426 | ret = issue_key_mgmt_set_key(drv, params->psk, 32); | |
5427 | if (ret) | |
5428 | return ret; | |
5429 | } | |
b658547d | 5430 | #endif /* CONFIG_DRIVER_NL80211_QCA */ |
b41f2684 | 5431 | |
9725b784 JM |
5432 | wpa_printf(MSG_DEBUG, "nl80211: Connect (ifindex=%d)", drv->ifindex); |
5433 | msg = nl80211_drv_msg(drv, 0, NL80211_CMD_CONNECT); | |
a0bdd191 JM |
5434 | if (!msg) |
5435 | return -1; | |
5436 | ||
a0bdd191 JM |
5437 | ret = nl80211_connect_common(drv, params, msg); |
5438 | if (ret) | |
a862e4a3 | 5439 | goto fail; |
a0bdd191 JM |
5440 | |
5441 | algs = 0; | |
5442 | if (params->auth_alg & WPA_AUTH_ALG_OPEN) | |
5443 | algs++; | |
5444 | if (params->auth_alg & WPA_AUTH_ALG_SHARED) | |
5445 | algs++; | |
5446 | if (params->auth_alg & WPA_AUTH_ALG_LEAP) | |
5447 | algs++; | |
64a0a75b JM |
5448 | if (params->auth_alg & WPA_AUTH_ALG_FILS) |
5449 | algs++; | |
a0bdd191 JM |
5450 | if (algs > 1) { |
5451 | wpa_printf(MSG_DEBUG, " * Leave out Auth Type for automatic " | |
5452 | "selection"); | |
5453 | goto skip_auth_type; | |
5454 | } | |
5455 | ||
3c67e977 | 5456 | type = get_nl_auth_type(params->auth_alg); |
a0bdd191 | 5457 | wpa_printf(MSG_DEBUG, " * Auth Type %d", type); |
3c67e977 VK |
5458 | if (type == NL80211_AUTHTYPE_MAX || |
5459 | nla_put_u32(msg, NL80211_ATTR_AUTH_TYPE, type)) | |
a862e4a3 | 5460 | goto fail; |
a0bdd191 JM |
5461 | |
5462 | skip_auth_type: | |
cfaab580 ZY |
5463 | ret = nl80211_set_conn_keys(params, msg); |
5464 | if (ret) | |
a862e4a3 | 5465 | goto fail; |
cfaab580 | 5466 | |
40a68f33 SD |
5467 | if (nl_connect) |
5468 | ret = send_and_recv(drv->global, nl_connect, msg, NULL, NULL); | |
5469 | else | |
5470 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); | |
5471 | ||
cfaab580 ZY |
5472 | msg = NULL; |
5473 | if (ret) { | |
5474 | wpa_printf(MSG_DEBUG, "nl80211: MLME connect failed: ret=%d " | |
5475 | "(%s)", ret, strerror(-ret)); | |
a862e4a3 JM |
5476 | } else { |
5477 | wpa_printf(MSG_DEBUG, | |
5478 | "nl80211: Connect request send successfully"); | |
cfaab580 | 5479 | } |
cfaab580 | 5480 | |
a862e4a3 | 5481 | fail: |
cfaab580 ZY |
5482 | nlmsg_free(msg); |
5483 | return ret; | |
5484 | ||
5485 | } | |
5486 | ||
5487 | ||
a8c5b43a CW |
5488 | static int wpa_driver_nl80211_connect( |
5489 | struct wpa_driver_nl80211_data *drv, | |
40a68f33 SD |
5490 | struct wpa_driver_associate_params *params, |
5491 | struct nl_handle *nl_connect) | |
a8c5b43a | 5492 | { |
0d4e3d1d JJ |
5493 | int ret; |
5494 | ||
5495 | /* Store the connection attempted bssid for future use */ | |
5496 | if (params->bssid) | |
5497 | os_memcpy(drv->auth_attempt_bssid, params->bssid, ETH_ALEN); | |
5498 | else | |
5499 | os_memset(drv->auth_attempt_bssid, 0, ETH_ALEN); | |
5500 | ||
40a68f33 | 5501 | ret = wpa_driver_nl80211_try_connect(drv, params, nl_connect); |
a8c5b43a CW |
5502 | if (ret == -EALREADY) { |
5503 | /* | |
5504 | * cfg80211 does not currently accept new connections if | |
5505 | * we are already connected. As a workaround, force | |
5506 | * disconnection and try again. | |
5507 | */ | |
5508 | wpa_printf(MSG_DEBUG, "nl80211: Explicitly " | |
5509 | "disconnecting before reassociation " | |
5510 | "attempt"); | |
5511 | if (wpa_driver_nl80211_disconnect( | |
5512 | drv, WLAN_REASON_PREV_AUTH_NOT_VALID)) | |
5513 | return -1; | |
40a68f33 | 5514 | ret = wpa_driver_nl80211_try_connect(drv, params, nl_connect); |
a8c5b43a CW |
5515 | } |
5516 | return ret; | |
5517 | } | |
5518 | ||
5519 | ||
c2a04078 JM |
5520 | static int wpa_driver_nl80211_associate( |
5521 | void *priv, struct wpa_driver_associate_params *params) | |
5522 | { | |
a2e40bb6 FF |
5523 | struct i802_bss *bss = priv; |
5524 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
a862e4a3 | 5525 | int ret = -1; |
c2a04078 JM |
5526 | struct nl_msg *msg; |
5527 | ||
4bd71954 JM |
5528 | nl80211_unmask_11b_rates(bss); |
5529 | ||
5cc4d64b | 5530 | if (params->mode == IEEE80211_MODE_AP) |
1581b38b | 5531 | return wpa_driver_nl80211_ap(drv, params); |
1581b38b | 5532 | |
5cc4d64b JM |
5533 | if (params->mode == IEEE80211_MODE_IBSS) |
5534 | return wpa_driver_nl80211_ibss(drv, params); | |
5535 | ||
4a867032 | 5536 | if (!(drv->capa.flags & WPA_DRIVER_FLAGS_SME)) { |
b1f625e0 EP |
5537 | enum nl80211_iftype nlmode = params->p2p ? |
5538 | NL80211_IFTYPE_P2P_CLIENT : NL80211_IFTYPE_STATION; | |
40a68f33 | 5539 | struct nl_handle *nl_connect = NULL; |
b1f625e0 EP |
5540 | |
5541 | if (wpa_driver_nl80211_set_mode(priv, nlmode) < 0) | |
4a867032 | 5542 | return -1; |
40a68f33 SD |
5543 | if (params->auth_alg & WPA_AUTH_ALG_SAE) |
5544 | nl_connect = bss->nl_connect; | |
5545 | return wpa_driver_nl80211_connect(drv, params, nl_connect); | |
4a867032 | 5546 | } |
cfaab580 | 5547 | |
add9b7a4 | 5548 | nl80211_mark_disconnected(drv); |
c2a04078 | 5549 | |
c2a04078 JM |
5550 | wpa_printf(MSG_DEBUG, "nl80211: Associate (ifindex=%d)", |
5551 | drv->ifindex); | |
9725b784 JM |
5552 | msg = nl80211_drv_msg(drv, 0, NL80211_CMD_ASSOCIATE); |
5553 | if (!msg) | |
5554 | return -1; | |
c2a04078 | 5555 | |
a0bdd191 JM |
5556 | ret = nl80211_connect_common(drv, params, msg); |
5557 | if (ret) | |
a862e4a3 | 5558 | goto fail; |
01652550 | 5559 | |
40a45727 JM |
5560 | if (params->fils_kek) { |
5561 | wpa_printf(MSG_DEBUG, " * FILS KEK (len=%u)", | |
5562 | (unsigned int) params->fils_kek_len); | |
5563 | if (nla_put(msg, NL80211_ATTR_FILS_KEK, params->fils_kek_len, | |
5564 | params->fils_kek)) | |
5565 | goto fail; | |
5566 | } | |
5567 | if (params->fils_nonces) { | |
5568 | wpa_hexdump(MSG_DEBUG, " * FILS nonces (for AAD)", | |
5569 | params->fils_nonces, | |
5570 | params->fils_nonces_len); | |
5571 | if (nla_put(msg, NL80211_ATTR_FILS_NONCES, | |
5572 | params->fils_nonces_len, params->fils_nonces)) | |
5573 | goto fail; | |
5574 | } | |
5575 | ||
c2a04078 JM |
5576 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
5577 | msg = NULL; | |
5578 | if (ret) { | |
3b7ea880 BG |
5579 | wpa_dbg(drv->ctx, MSG_DEBUG, |
5580 | "nl80211: MLME command failed (assoc): ret=%d (%s)", | |
5581 | ret, strerror(-ret)); | |
8856462d | 5582 | nl80211_dump_scan(drv); |
a862e4a3 JM |
5583 | } else { |
5584 | wpa_printf(MSG_DEBUG, | |
5585 | "nl80211: Association request send successfully"); | |
c2a04078 | 5586 | } |
c2a04078 | 5587 | |
a862e4a3 | 5588 | fail: |
c2a04078 JM |
5589 | nlmsg_free(msg); |
5590 | return ret; | |
5591 | } | |
3f5285e8 JM |
5592 | |
5593 | ||
ad1e68e6 | 5594 | static int nl80211_set_mode(struct wpa_driver_nl80211_data *drv, |
a1922f93 | 5595 | int ifindex, enum nl80211_iftype mode) |
3f5285e8 | 5596 | { |
3f5285e8 | 5597 | struct nl_msg *msg; |
ad1e68e6 JM |
5598 | int ret = -ENOBUFS; |
5599 | ||
a1922f93 JM |
5600 | wpa_printf(MSG_DEBUG, "nl80211: Set mode ifindex %d iftype %d (%s)", |
5601 | ifindex, mode, nl80211_iftype_str(mode)); | |
5602 | ||
56f77852 JM |
5603 | msg = nl80211_cmd_msg(drv->first_bss, 0, NL80211_CMD_SET_INTERFACE); |
5604 | if (!msg || nla_put_u32(msg, NL80211_ATTR_IFTYPE, mode)) | |
a862e4a3 | 5605 | goto fail; |
ad1e68e6 JM |
5606 | |
5607 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); | |
5883168a | 5608 | msg = NULL; |
ad1e68e6 JM |
5609 | if (!ret) |
5610 | return 0; | |
a862e4a3 | 5611 | fail: |
5883168a | 5612 | nlmsg_free(msg); |
ad1e68e6 JM |
5613 | wpa_printf(MSG_DEBUG, "nl80211: Failed to set interface %d to mode %d:" |
5614 | " %d (%s)", ifindex, mode, ret, strerror(-ret)); | |
5615 | return ret; | |
5616 | } | |
5617 | ||
5618 | ||
3c5d34e3 CW |
5619 | static int wpa_driver_nl80211_set_mode_impl( |
5620 | struct i802_bss *bss, | |
5621 | enum nl80211_iftype nlmode, | |
5622 | struct hostapd_freq_params *desired_freq_params) | |
ad1e68e6 | 5623 | { |
a2e40bb6 | 5624 | struct wpa_driver_nl80211_data *drv = bss->drv; |
ad1e68e6 | 5625 | int ret = -1; |
26af9dca | 5626 | int i; |
86957e62 | 5627 | int was_ap = is_ap_interface(drv->nlmode); |
671a5039 | 5628 | int res; |
ebffdbc4 | 5629 | int mode_switch_res; |
1581b38b | 5630 | |
a5a187b0 JM |
5631 | if (TEST_FAIL()) |
5632 | return -1; | |
5633 | ||
ebffdbc4 CW |
5634 | mode_switch_res = nl80211_set_mode(drv, drv->ifindex, nlmode); |
5635 | if (mode_switch_res && nlmode == nl80211_get_ifmode(bss)) | |
5636 | mode_switch_res = 0; | |
8e12685c | 5637 | |
ebffdbc4 | 5638 | if (mode_switch_res == 0) { |
ad1e68e6 | 5639 | drv->nlmode = nlmode; |
460456f8 JM |
5640 | ret = 0; |
5641 | goto done; | |
ad1e68e6 | 5642 | } |
3f5285e8 | 5643 | |
ebffdbc4 | 5644 | if (mode_switch_res == -ENODEV) |
671a5039 JM |
5645 | return -1; |
5646 | ||
460456f8 | 5647 | if (nlmode == drv->nlmode) { |
c6e8e8e4 JM |
5648 | wpa_printf(MSG_DEBUG, "nl80211: Interface already in " |
5649 | "requested mode - ignore error"); | |
460456f8 JM |
5650 | ret = 0; |
5651 | goto done; /* Already in the requested mode */ | |
5652 | } | |
3f5285e8 | 5653 | |
3f5285e8 JM |
5654 | /* mac80211 doesn't allow mode changes while the device is up, so |
5655 | * take the device down, try to set the mode again, and bring the | |
5656 | * device back up. | |
5657 | */ | |
26af9dca JM |
5658 | wpa_printf(MSG_DEBUG, "nl80211: Try mode change after setting " |
5659 | "interface down"); | |
5660 | for (i = 0; i < 10; i++) { | |
91724d6f | 5661 | res = i802_set_iface_flags(bss, 0); |
6e8183d7 JM |
5662 | if (res == -EACCES || res == -ENODEV) |
5663 | break; | |
ebffdbc4 | 5664 | if (res != 0) { |
26af9dca JM |
5665 | wpa_printf(MSG_DEBUG, "nl80211: Failed to set " |
5666 | "interface down"); | |
ebffdbc4 CW |
5667 | os_sleep(0, 100000); |
5668 | continue; | |
5669 | } | |
3c5d34e3 CW |
5670 | |
5671 | /* | |
5672 | * Setting the mode will fail for some drivers if the phy is | |
5673 | * on a frequency that the mode is disallowed in. | |
5674 | */ | |
5675 | if (desired_freq_params) { | |
bdf5ccb2 | 5676 | res = nl80211_set_channel(bss, desired_freq_params, 0); |
3c5d34e3 CW |
5677 | if (res) { |
5678 | wpa_printf(MSG_DEBUG, | |
5679 | "nl80211: Failed to set frequency on interface"); | |
5680 | } | |
5681 | } | |
5682 | ||
ebffdbc4 CW |
5683 | /* Try to set the mode again while the interface is down */ |
5684 | mode_switch_res = nl80211_set_mode(drv, drv->ifindex, nlmode); | |
5685 | if (mode_switch_res == -EBUSY) { | |
5686 | wpa_printf(MSG_DEBUG, | |
5687 | "nl80211: Delaying mode set while interface going down"); | |
5688 | os_sleep(0, 100000); | |
5689 | continue; | |
5690 | } | |
5691 | ret = mode_switch_res; | |
5692 | break; | |
3f5285e8 JM |
5693 | } |
5694 | ||
c6e8e8e4 JM |
5695 | if (!ret) { |
5696 | wpa_printf(MSG_DEBUG, "nl80211: Mode change succeeded while " | |
5697 | "interface is down"); | |
ad1e68e6 | 5698 | drv->nlmode = nlmode; |
7d9c3698 | 5699 | drv->ignore_if_down_event = 1; |
c6e8e8e4 | 5700 | } |
ad1e68e6 | 5701 | |
ebffdbc4 CW |
5702 | /* Bring the interface back up */ |
5703 | res = linux_set_iface_flags(drv->global->ioctl_sock, bss->ifname, 1); | |
5704 | if (res != 0) { | |
5705 | wpa_printf(MSG_DEBUG, | |
5706 | "nl80211: Failed to set interface up after switching mode"); | |
5707 | ret = -1; | |
5708 | } | |
5709 | ||
460456f8 | 5710 | done: |
3fd1cefb JB |
5711 | if (ret) { |
5712 | wpa_printf(MSG_DEBUG, "nl80211: Interface mode change to %d " | |
5713 | "from %d failed", nlmode, drv->nlmode); | |
5714 | return ret; | |
5715 | } | |
5716 | ||
3e208481 JM |
5717 | if (is_p2p_net_interface(nlmode)) { |
5718 | wpa_printf(MSG_DEBUG, | |
5719 | "nl80211: Interface %s mode change to P2P - disable 11b rates", | |
5720 | bss->ifname); | |
edb9bfba | 5721 | nl80211_disable_11b_rates(drv, drv->ifindex, 1); |
3e208481 JM |
5722 | } else if (drv->disabled_11b_rates) { |
5723 | wpa_printf(MSG_DEBUG, | |
5724 | "nl80211: Interface %s mode changed to non-P2P - re-enable 11b rates", | |
5725 | bss->ifname); | |
1d0c6fb1 | 5726 | nl80211_disable_11b_rates(drv, drv->ifindex, 0); |
3e208481 | 5727 | } |
edb9bfba | 5728 | |
3fd1cefb | 5729 | if (is_ap_interface(nlmode)) { |
36488c05 | 5730 | nl80211_mgmt_unsubscribe(bss, "start AP"); |
460456f8 | 5731 | /* Setup additional AP mode functionality if needed */ |
3fd1cefb | 5732 | if (nl80211_setup_ap(bss)) |
460456f8 | 5733 | return -1; |
3fd1cefb | 5734 | } else if (was_ap) { |
460456f8 | 5735 | /* Remove additional AP mode functionality */ |
3fd1cefb | 5736 | nl80211_teardown_ap(bss); |
a11241fa | 5737 | } else { |
36488c05 | 5738 | nl80211_mgmt_unsubscribe(bss, "mode change"); |
460456f8 | 5739 | } |
460456f8 | 5740 | |
afb0550a BC |
5741 | if (is_mesh_interface(nlmode) && |
5742 | nl80211_mgmt_subscribe_mesh(bss)) | |
5743 | return -1; | |
5744 | ||
873d0fcf | 5745 | if (!bss->in_deinit && !is_ap_interface(nlmode) && |
afb0550a | 5746 | !is_mesh_interface(nlmode) && |
a11241fa JB |
5747 | nl80211_mgmt_subscribe_non_ap(bss) < 0) |
5748 | wpa_printf(MSG_DEBUG, "nl80211: Failed to register Action " | |
5749 | "frame processing - ignore for now"); | |
08359050 | 5750 | |
3fd1cefb | 5751 | return 0; |
3f5285e8 JM |
5752 | } |
5753 | ||
5754 | ||
f3407c66 JM |
5755 | int wpa_driver_nl80211_set_mode(struct i802_bss *bss, |
5756 | enum nl80211_iftype nlmode) | |
3c5d34e3 CW |
5757 | { |
5758 | return wpa_driver_nl80211_set_mode_impl(bss, nlmode, NULL); | |
5759 | } | |
5760 | ||
5761 | ||
4ec68377 JD |
5762 | static int wpa_driver_nl80211_set_mode_ibss(struct i802_bss *bss, |
5763 | struct hostapd_freq_params *freq) | |
3c5d34e3 | 5764 | { |
3c5d34e3 | 5765 | return wpa_driver_nl80211_set_mode_impl(bss, NL80211_IFTYPE_ADHOC, |
4ec68377 | 5766 | freq); |
3c5d34e3 | 5767 | } |
65d645ce AS |
5768 | |
5769 | ||
3f5285e8 JM |
5770 | static int wpa_driver_nl80211_get_capa(void *priv, |
5771 | struct wpa_driver_capa *capa) | |
5772 | { | |
a2e40bb6 FF |
5773 | struct i802_bss *bss = priv; |
5774 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
65d645ce | 5775 | |
3f5285e8 JM |
5776 | if (!drv->has_capability) |
5777 | return -1; | |
5778 | os_memcpy(capa, &drv->capa, sizeof(*capa)); | |
8cd6b7bc JB |
5779 | if (drv->extended_capa && drv->extended_capa_mask) { |
5780 | capa->extended_capa = drv->extended_capa; | |
5781 | capa->extended_capa_mask = drv->extended_capa_mask; | |
5782 | capa->extended_capa_len = drv->extended_capa_len; | |
5783 | } | |
851b0c55 | 5784 | |
906bc4c7 | 5785 | return 0; |
3f5285e8 JM |
5786 | } |
5787 | ||
5788 | ||
5789 | static int wpa_driver_nl80211_set_operstate(void *priv, int state) | |
5790 | { | |
a2e40bb6 FF |
5791 | struct i802_bss *bss = priv; |
5792 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
3f5285e8 | 5793 | |
90a545cc JM |
5794 | wpa_printf(MSG_DEBUG, "nl80211: Set %s operstate %d->%d (%s)", |
5795 | bss->ifname, drv->operstate, state, | |
5796 | state ? "UP" : "DORMANT"); | |
3f5285e8 | 5797 | drv->operstate = state; |
36d84860 | 5798 | return netlink_send_oper_ifla(drv->global->netlink, drv->ifindex, -1, |
e2d02c29 | 5799 | state ? IF_OPER_UP : IF_OPER_DORMANT); |
3f5285e8 JM |
5800 | } |
5801 | ||
01652550 JM |
5802 | |
5803 | static int wpa_driver_nl80211_set_supp_port(void *priv, int authorized) | |
5804 | { | |
a2e40bb6 FF |
5805 | struct i802_bss *bss = priv; |
5806 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
01652550 JM |
5807 | struct nl_msg *msg; |
5808 | struct nl80211_sta_flag_update upd; | |
a862e4a3 | 5809 | int ret; |
2eef5177 JM |
5810 | |
5811 | if (!drv->associated && is_zero_ether_addr(drv->bssid) && !authorized) { | |
5812 | wpa_printf(MSG_DEBUG, "nl80211: Skip set_supp_port(unauthorized) while not associated"); | |
5813 | return 0; | |
5814 | } | |
01652550 | 5815 | |
1ba51ec0 JM |
5816 | wpa_printf(MSG_DEBUG, "nl80211: Set supplicant port %sauthorized for " |
5817 | MACSTR, authorized ? "" : "un", MAC2STR(drv->bssid)); | |
5818 | ||
01652550 JM |
5819 | os_memset(&upd, 0, sizeof(upd)); |
5820 | upd.mask = BIT(NL80211_STA_FLAG_AUTHORIZED); | |
5821 | if (authorized) | |
5822 | upd.set = BIT(NL80211_STA_FLAG_AUTHORIZED); | |
a862e4a3 | 5823 | |
13f83980 | 5824 | if (!(msg = nl80211_bss_msg(bss, 0, NL80211_CMD_SET_STATION)) || |
a862e4a3 JM |
5825 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, drv->bssid) || |
5826 | nla_put(msg, NL80211_ATTR_STA_FLAGS2, sizeof(upd), &upd)) { | |
5827 | nlmsg_free(msg); | |
5828 | return -ENOBUFS; | |
5829 | } | |
01652550 | 5830 | |
2eef5177 | 5831 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
2eef5177 JM |
5832 | if (!ret) |
5833 | return 0; | |
2eef5177 JM |
5834 | wpa_printf(MSG_DEBUG, "nl80211: Failed to set STA flag: %d (%s)", |
5835 | ret, strerror(-ret)); | |
5836 | return ret; | |
01652550 JM |
5837 | } |
5838 | ||
3f5285e8 | 5839 | |
f07ead6a JM |
5840 | /* Set kernel driver on given frequency (MHz) */ |
5841 | static int i802_set_freq(void *priv, struct hostapd_freq_params *freq) | |
c5121837 | 5842 | { |
f07ead6a | 5843 | struct i802_bss *bss = priv; |
13a524a3 | 5844 | return nl80211_set_channel(bss, freq, 0); |
c5121837 JM |
5845 | } |
5846 | ||
f7b3920c | 5847 | |
c5121837 JM |
5848 | static inline int min_int(int a, int b) |
5849 | { | |
5850 | if (a < b) | |
5851 | return a; | |
5852 | return b; | |
5853 | } | |
5854 | ||
5855 | ||
5856 | static int get_key_handler(struct nl_msg *msg, void *arg) | |
5857 | { | |
5858 | struct nlattr *tb[NL80211_ATTR_MAX + 1]; | |
5859 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); | |
5860 | ||
5861 | nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), | |
5862 | genlmsg_attrlen(gnlh, 0), NULL); | |
5863 | ||
5864 | /* | |
5865 | * TODO: validate the key index and mac address! | |
5866 | * Otherwise, there's a race condition as soon as | |
5867 | * the kernel starts sending key notifications. | |
5868 | */ | |
5869 | ||
5870 | if (tb[NL80211_ATTR_KEY_SEQ]) | |
5871 | memcpy(arg, nla_data(tb[NL80211_ATTR_KEY_SEQ]), | |
5872 | min_int(nla_len(tb[NL80211_ATTR_KEY_SEQ]), 6)); | |
5873 | return NL_SKIP; | |
5874 | } | |
5875 | ||
5876 | ||
5877 | static int i802_get_seqnum(const char *iface, void *priv, const u8 *addr, | |
5878 | int idx, u8 *seq) | |
5879 | { | |
a2e40bb6 FF |
5880 | struct i802_bss *bss = priv; |
5881 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
c5121837 JM |
5882 | struct nl_msg *msg; |
5883 | ||
95376e1a JM |
5884 | msg = nl80211_ifindex_msg(drv, if_nametoindex(iface), 0, |
5885 | NL80211_CMD_GET_KEY); | |
5886 | if (!msg || | |
a862e4a3 | 5887 | (addr && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) || |
95376e1a | 5888 | nla_put_u8(msg, NL80211_ATTR_KEY_IDX, idx)) { |
a862e4a3 JM |
5889 | nlmsg_free(msg); |
5890 | return -ENOBUFS; | |
5891 | } | |
c5121837 JM |
5892 | |
5893 | memset(seq, 0, 6); | |
5894 | ||
5895 | return send_and_recv_msgs(drv, msg, get_key_handler, seq); | |
c5121837 JM |
5896 | } |
5897 | ||
5898 | ||
c5121837 JM |
5899 | static int i802_set_rts(void *priv, int rts) |
5900 | { | |
a2e40bb6 FF |
5901 | struct i802_bss *bss = priv; |
5902 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
ad649451 | 5903 | struct nl_msg *msg; |
a862e4a3 | 5904 | int ret; |
ad649451 | 5905 | u32 val; |
c5121837 | 5906 | |
ad649451 JM |
5907 | if (rts >= 2347) |
5908 | val = (u32) -1; | |
5909 | else | |
5910 | val = rts; | |
c5121837 | 5911 | |
9725b784 | 5912 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_SET_WIPHY)) || |
a862e4a3 JM |
5913 | nla_put_u32(msg, NL80211_ATTR_WIPHY_RTS_THRESHOLD, val)) { |
5914 | nlmsg_free(msg); | |
5915 | return -ENOBUFS; | |
5916 | } | |
ad649451 JM |
5917 | |
5918 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); | |
5919 | if (!ret) | |
5920 | return 0; | |
ad649451 JM |
5921 | wpa_printf(MSG_DEBUG, "nl80211: Failed to set RTS threshold %d: " |
5922 | "%d (%s)", rts, ret, strerror(-ret)); | |
5923 | return ret; | |
c5121837 JM |
5924 | } |
5925 | ||
5926 | ||
5927 | static int i802_set_frag(void *priv, int frag) | |
5928 | { | |
a2e40bb6 FF |
5929 | struct i802_bss *bss = priv; |
5930 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
ad649451 | 5931 | struct nl_msg *msg; |
a862e4a3 | 5932 | int ret; |
ad649451 | 5933 | u32 val; |
c5121837 | 5934 | |
ad649451 JM |
5935 | if (frag >= 2346) |
5936 | val = (u32) -1; | |
5937 | else | |
5938 | val = frag; | |
c5121837 | 5939 | |
9725b784 | 5940 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_SET_WIPHY)) || |
a862e4a3 JM |
5941 | nla_put_u32(msg, NL80211_ATTR_WIPHY_FRAG_THRESHOLD, val)) { |
5942 | nlmsg_free(msg); | |
5943 | return -ENOBUFS; | |
5944 | } | |
ad649451 JM |
5945 | |
5946 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); | |
5947 | if (!ret) | |
5948 | return 0; | |
ad649451 JM |
5949 | wpa_printf(MSG_DEBUG, "nl80211: Failed to set fragmentation threshold " |
5950 | "%d: %d (%s)", frag, ret, strerror(-ret)); | |
5951 | return ret; | |
c5121837 JM |
5952 | } |
5953 | ||
5954 | ||
c5121837 JM |
5955 | static int i802_flush(void *priv) |
5956 | { | |
a2e40bb6 | 5957 | struct i802_bss *bss = priv; |
c5121837 | 5958 | struct nl_msg *msg; |
82554b10 | 5959 | int res; |
c5121837 | 5960 | |
83e7bb0e JM |
5961 | wpa_printf(MSG_DEBUG, "nl80211: flush -> DEL_STATION %s (all)", |
5962 | bss->ifname); | |
c5121837 JM |
5963 | |
5964 | /* | |
5965 | * XXX: FIX! this needs to flush all VLANs too | |
5966 | */ | |
13f83980 JM |
5967 | msg = nl80211_bss_msg(bss, 0, NL80211_CMD_DEL_STATION); |
5968 | res = send_and_recv_msgs(bss->drv, msg, NULL, NULL); | |
82554b10 JM |
5969 | if (res) { |
5970 | wpa_printf(MSG_DEBUG, "nl80211: Station flush failed: ret=%d " | |
5971 | "(%s)", res, strerror(-res)); | |
5972 | } | |
5973 | return res; | |
c5121837 JM |
5974 | } |
5975 | ||
5976 | ||
5977 | static int get_sta_handler(struct nl_msg *msg, void *arg) | |
5978 | { | |
5979 | struct nlattr *tb[NL80211_ATTR_MAX + 1]; | |
5980 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); | |
5981 | struct hostap_sta_driver_data *data = arg; | |
5982 | struct nlattr *stats[NL80211_STA_INFO_MAX + 1]; | |
5983 | static struct nla_policy stats_policy[NL80211_STA_INFO_MAX + 1] = { | |
5984 | [NL80211_STA_INFO_INACTIVE_TIME] = { .type = NLA_U32 }, | |
5985 | [NL80211_STA_INFO_RX_BYTES] = { .type = NLA_U32 }, | |
5986 | [NL80211_STA_INFO_TX_BYTES] = { .type = NLA_U32 }, | |
5987 | [NL80211_STA_INFO_RX_PACKETS] = { .type = NLA_U32 }, | |
5988 | [NL80211_STA_INFO_TX_PACKETS] = { .type = NLA_U32 }, | |
dc7785f8 | 5989 | [NL80211_STA_INFO_TX_FAILED] = { .type = NLA_U32 }, |
43022abd NL |
5990 | [NL80211_STA_INFO_RX_BYTES64] = { .type = NLA_U64 }, |
5991 | [NL80211_STA_INFO_TX_BYTES64] = { .type = NLA_U64 }, | |
3567641e | 5992 | [NL80211_STA_INFO_SIGNAL] = { .type = NLA_U8 }, |
5993 | }; | |
5994 | struct nlattr *rate[NL80211_RATE_INFO_MAX + 1]; | |
5995 | static struct nla_policy rate_policy[NL80211_RATE_INFO_MAX + 1] = { | |
5996 | [NL80211_RATE_INFO_BITRATE] = { .type = NLA_U16 }, | |
5997 | [NL80211_RATE_INFO_BITRATE32] = { .type = NLA_U32 }, | |
5998 | [NL80211_RATE_INFO_MCS] = { .type = NLA_U8 }, | |
5999 | [NL80211_RATE_INFO_VHT_MCS] = { .type = NLA_U8 }, | |
6000 | [NL80211_RATE_INFO_SHORT_GI] = { .type = NLA_FLAG }, | |
6001 | [NL80211_RATE_INFO_VHT_NSS] = { .type = NLA_U8 }, | |
c5121837 JM |
6002 | }; |
6003 | ||
6004 | nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), | |
6005 | genlmsg_attrlen(gnlh, 0), NULL); | |
6006 | ||
6007 | /* | |
6008 | * TODO: validate the interface and mac address! | |
6009 | * Otherwise, there's a race condition as soon as | |
6010 | * the kernel starts sending station notifications. | |
6011 | */ | |
6012 | ||
6013 | if (!tb[NL80211_ATTR_STA_INFO]) { | |
6014 | wpa_printf(MSG_DEBUG, "sta stats missing!"); | |
6015 | return NL_SKIP; | |
6016 | } | |
6017 | if (nla_parse_nested(stats, NL80211_STA_INFO_MAX, | |
6018 | tb[NL80211_ATTR_STA_INFO], | |
6019 | stats_policy)) { | |
6020 | wpa_printf(MSG_DEBUG, "failed to parse nested attributes!"); | |
6021 | return NL_SKIP; | |
6022 | } | |
6023 | ||
6024 | if (stats[NL80211_STA_INFO_INACTIVE_TIME]) | |
6025 | data->inactive_msec = | |
6026 | nla_get_u32(stats[NL80211_STA_INFO_INACTIVE_TIME]); | |
43022abd | 6027 | /* For backwards compatibility, fetch the 32-bit counters first. */ |
c5121837 JM |
6028 | if (stats[NL80211_STA_INFO_RX_BYTES]) |
6029 | data->rx_bytes = nla_get_u32(stats[NL80211_STA_INFO_RX_BYTES]); | |
6030 | if (stats[NL80211_STA_INFO_TX_BYTES]) | |
6031 | data->tx_bytes = nla_get_u32(stats[NL80211_STA_INFO_TX_BYTES]); | |
43022abd NL |
6032 | if (stats[NL80211_STA_INFO_RX_BYTES64] && |
6033 | stats[NL80211_STA_INFO_TX_BYTES64]) { | |
6034 | /* | |
6035 | * The driver supports 64-bit counters, so use them to override | |
6036 | * the 32-bit values. | |
6037 | */ | |
6038 | data->rx_bytes = | |
6039 | nla_get_u64(stats[NL80211_STA_INFO_RX_BYTES64]); | |
6040 | data->tx_bytes = | |
6041 | nla_get_u64(stats[NL80211_STA_INFO_TX_BYTES64]); | |
6042 | data->bytes_64bit = 1; | |
6043 | } | |
c5121837 JM |
6044 | if (stats[NL80211_STA_INFO_RX_PACKETS]) |
6045 | data->rx_packets = | |
6046 | nla_get_u32(stats[NL80211_STA_INFO_RX_PACKETS]); | |
6047 | if (stats[NL80211_STA_INFO_TX_PACKETS]) | |
6048 | data->tx_packets = | |
6049 | nla_get_u32(stats[NL80211_STA_INFO_TX_PACKETS]); | |
dc7785f8 YZ |
6050 | if (stats[NL80211_STA_INFO_TX_FAILED]) |
6051 | data->tx_retry_failed = | |
6052 | nla_get_u32(stats[NL80211_STA_INFO_TX_FAILED]); | |
3567641e | 6053 | if (stats[NL80211_STA_INFO_SIGNAL]) |
6054 | data->signal = nla_get_u8(stats[NL80211_STA_INFO_SIGNAL]); | |
6055 | ||
6056 | if (stats[NL80211_STA_INFO_TX_BITRATE] && | |
6057 | nla_parse_nested(rate, NL80211_RATE_INFO_MAX, | |
6058 | stats[NL80211_STA_INFO_TX_BITRATE], | |
6059 | rate_policy) == 0) { | |
6060 | if (rate[NL80211_RATE_INFO_BITRATE32]) | |
6061 | data->current_tx_rate = | |
6062 | nla_get_u32(rate[NL80211_RATE_INFO_BITRATE32]); | |
6063 | else if (rate[NL80211_RATE_INFO_BITRATE]) | |
6064 | data->current_tx_rate = | |
6065 | nla_get_u16(rate[NL80211_RATE_INFO_BITRATE]); | |
6066 | ||
6067 | if (rate[NL80211_RATE_INFO_MCS]) { | |
6068 | data->tx_mcs = nla_get_u8(rate[NL80211_RATE_INFO_MCS]); | |
6069 | data->flags |= STA_DRV_DATA_TX_MCS; | |
6070 | } | |
6071 | if (rate[NL80211_RATE_INFO_VHT_MCS]) { | |
6072 | data->tx_vhtmcs = | |
6073 | nla_get_u8(rate[NL80211_RATE_INFO_VHT_MCS]); | |
6074 | data->flags |= STA_DRV_DATA_TX_VHT_MCS; | |
6075 | } | |
6076 | if (rate[NL80211_RATE_INFO_SHORT_GI]) | |
6077 | data->flags |= STA_DRV_DATA_TX_SHORT_GI; | |
6078 | if (rate[NL80211_RATE_INFO_VHT_NSS]) { | |
6079 | data->tx_vht_nss = | |
6080 | nla_get_u8(rate[NL80211_RATE_INFO_VHT_NSS]); | |
6081 | data->flags |= STA_DRV_DATA_TX_VHT_NSS; | |
6082 | } | |
6083 | } | |
6084 | ||
6085 | if (stats[NL80211_STA_INFO_RX_BITRATE] && | |
6086 | nla_parse_nested(rate, NL80211_RATE_INFO_MAX, | |
6087 | stats[NL80211_STA_INFO_RX_BITRATE], | |
6088 | rate_policy) == 0) { | |
6089 | if (rate[NL80211_RATE_INFO_BITRATE32]) | |
6090 | data->current_rx_rate = | |
6091 | nla_get_u32(rate[NL80211_RATE_INFO_BITRATE32]); | |
6092 | else if (rate[NL80211_RATE_INFO_BITRATE]) | |
6093 | data->current_rx_rate = | |
6094 | nla_get_u16(rate[NL80211_RATE_INFO_BITRATE]); | |
6095 | ||
6096 | if (rate[NL80211_RATE_INFO_MCS]) { | |
6097 | data->rx_mcs = | |
6098 | nla_get_u8(rate[NL80211_RATE_INFO_MCS]); | |
6099 | data->flags |= STA_DRV_DATA_RX_MCS; | |
6100 | } | |
6101 | if (rate[NL80211_RATE_INFO_VHT_MCS]) { | |
6102 | data->rx_vhtmcs = | |
6103 | nla_get_u8(rate[NL80211_RATE_INFO_VHT_MCS]); | |
6104 | data->flags |= STA_DRV_DATA_RX_VHT_MCS; | |
6105 | } | |
6106 | if (rate[NL80211_RATE_INFO_SHORT_GI]) | |
6107 | data->flags |= STA_DRV_DATA_RX_SHORT_GI; | |
6108 | if (rate[NL80211_RATE_INFO_VHT_NSS]) { | |
6109 | data->rx_vht_nss = | |
6110 | nla_get_u8(rate[NL80211_RATE_INFO_VHT_NSS]); | |
6111 | data->flags |= STA_DRV_DATA_RX_VHT_NSS; | |
6112 | } | |
6113 | } | |
c5121837 JM |
6114 | |
6115 | return NL_SKIP; | |
6116 | } | |
6117 | ||
9ebce9c5 JM |
6118 | static int i802_read_sta_data(struct i802_bss *bss, |
6119 | struct hostap_sta_driver_data *data, | |
c5121837 JM |
6120 | const u8 *addr) |
6121 | { | |
c5121837 JM |
6122 | struct nl_msg *msg; |
6123 | ||
13f83980 JM |
6124 | if (!(msg = nl80211_bss_msg(bss, 0, NL80211_CMD_GET_STATION)) || |
6125 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) { | |
a862e4a3 JM |
6126 | nlmsg_free(msg); |
6127 | return -ENOBUFS; | |
6128 | } | |
c5121837 | 6129 | |
13f83980 | 6130 | return send_and_recv_msgs(bss->drv, msg, get_sta_handler, data); |
c5121837 JM |
6131 | } |
6132 | ||
6133 | ||
c5121837 JM |
6134 | static int i802_set_tx_queue_params(void *priv, int queue, int aifs, |
6135 | int cw_min, int cw_max, int burst_time) | |
6136 | { | |
a2e40bb6 FF |
6137 | struct i802_bss *bss = priv; |
6138 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
c5121837 JM |
6139 | struct nl_msg *msg; |
6140 | struct nlattr *txq, *params; | |
6141 | ||
13f83980 | 6142 | msg = nl80211_bss_msg(bss, 0, NL80211_CMD_SET_WIPHY); |
c5121837 JM |
6143 | if (!msg) |
6144 | return -1; | |
6145 | ||
c5121837 JM |
6146 | txq = nla_nest_start(msg, NL80211_ATTR_WIPHY_TXQ_PARAMS); |
6147 | if (!txq) | |
a862e4a3 | 6148 | goto fail; |
c5121837 JM |
6149 | |
6150 | /* We are only sending parameters for a single TXQ at a time */ | |
6151 | params = nla_nest_start(msg, 1); | |
6152 | if (!params) | |
a862e4a3 | 6153 | goto fail; |
c5121837 | 6154 | |
7e3c1781 JM |
6155 | switch (queue) { |
6156 | case 0: | |
a862e4a3 JM |
6157 | if (nla_put_u8(msg, NL80211_TXQ_ATTR_QUEUE, NL80211_TXQ_Q_VO)) |
6158 | goto fail; | |
7e3c1781 JM |
6159 | break; |
6160 | case 1: | |
a862e4a3 JM |
6161 | if (nla_put_u8(msg, NL80211_TXQ_ATTR_QUEUE, NL80211_TXQ_Q_VI)) |
6162 | goto fail; | |
7e3c1781 JM |
6163 | break; |
6164 | case 2: | |
a862e4a3 JM |
6165 | if (nla_put_u8(msg, NL80211_TXQ_ATTR_QUEUE, NL80211_TXQ_Q_BE)) |
6166 | goto fail; | |
7e3c1781 JM |
6167 | break; |
6168 | case 3: | |
a862e4a3 JM |
6169 | if (nla_put_u8(msg, NL80211_TXQ_ATTR_QUEUE, NL80211_TXQ_Q_BK)) |
6170 | goto fail; | |
7e3c1781 JM |
6171 | break; |
6172 | } | |
c5121837 JM |
6173 | /* Burst time is configured in units of 0.1 msec and TXOP parameter in |
6174 | * 32 usec, so need to convert the value here. */ | |
a862e4a3 JM |
6175 | if (nla_put_u16(msg, NL80211_TXQ_ATTR_TXOP, |
6176 | (burst_time * 100 + 16) / 32) || | |
6177 | nla_put_u16(msg, NL80211_TXQ_ATTR_CWMIN, cw_min) || | |
6178 | nla_put_u16(msg, NL80211_TXQ_ATTR_CWMAX, cw_max) || | |
6179 | nla_put_u8(msg, NL80211_TXQ_ATTR_AIFS, aifs)) | |
6180 | goto fail; | |
c5121837 JM |
6181 | |
6182 | nla_nest_end(msg, params); | |
6183 | ||
6184 | nla_nest_end(msg, txq); | |
6185 | ||
6186 | if (send_and_recv_msgs(drv, msg, NULL, NULL) == 0) | |
6187 | return 0; | |
9e088e74 | 6188 | msg = NULL; |
a862e4a3 | 6189 | fail: |
9e088e74 | 6190 | nlmsg_free(msg); |
c5121837 JM |
6191 | return -1; |
6192 | } | |
6193 | ||
6194 | ||
9ebce9c5 | 6195 | static int i802_set_sta_vlan(struct i802_bss *bss, const u8 *addr, |
c5121837 JM |
6196 | const char *ifname, int vlan_id) |
6197 | { | |
a2e40bb6 | 6198 | struct wpa_driver_nl80211_data *drv = bss->drv; |
c5121837 | 6199 | struct nl_msg *msg; |
a862e4a3 | 6200 | int ret; |
c5121837 | 6201 | |
bbc706a3 JM |
6202 | wpa_printf(MSG_DEBUG, "nl80211: %s[%d]: set_sta_vlan(" MACSTR |
6203 | ", ifname=%s[%d], vlan_id=%d)", | |
6204 | bss->ifname, if_nametoindex(bss->ifname), | |
6205 | MAC2STR(addr), ifname, if_nametoindex(ifname), vlan_id); | |
13f83980 | 6206 | if (!(msg = nl80211_bss_msg(bss, 0, NL80211_CMD_SET_STATION)) || |
a862e4a3 JM |
6207 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) || |
6208 | nla_put_u32(msg, NL80211_ATTR_STA_VLAN, if_nametoindex(ifname))) { | |
6209 | nlmsg_free(msg); | |
6210 | return -ENOBUFS; | |
6211 | } | |
c5121837 | 6212 | |
cd1d72c1 JM |
6213 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
6214 | if (ret < 0) { | |
6215 | wpa_printf(MSG_ERROR, "nl80211: NL80211_ATTR_STA_VLAN (addr=" | |
6216 | MACSTR " ifname=%s vlan_id=%d) failed: %d (%s)", | |
6217 | MAC2STR(addr), ifname, vlan_id, ret, | |
6218 | strerror(-ret)); | |
6219 | } | |
cd1d72c1 | 6220 | return ret; |
c5121837 JM |
6221 | } |
6222 | ||
fbbfcbac | 6223 | |
c5121837 JM |
6224 | static int i802_get_inact_sec(void *priv, const u8 *addr) |
6225 | { | |
6226 | struct hostap_sta_driver_data data; | |
6227 | int ret; | |
6228 | ||
7824bf77 | 6229 | os_memset(&data, 0, sizeof(data)); |
c5121837 JM |
6230 | data.inactive_msec = (unsigned long) -1; |
6231 | ret = i802_read_sta_data(priv, &data, addr); | |
b9749bac MH |
6232 | if (ret == -ENOENT) |
6233 | return -ENOENT; | |
c5121837 JM |
6234 | if (ret || data.inactive_msec == (unsigned long) -1) |
6235 | return -1; | |
6236 | return data.inactive_msec / 1000; | |
6237 | } | |
6238 | ||
6239 | ||
6240 | static int i802_sta_clear_stats(void *priv, const u8 *addr) | |
6241 | { | |
6242 | #if 0 | |
6243 | /* TODO */ | |
6244 | #endif | |
6245 | return 0; | |
6246 | } | |
6247 | ||
6248 | ||
731723a5 JM |
6249 | static int i802_sta_deauth(void *priv, const u8 *own_addr, const u8 *addr, |
6250 | int reason) | |
c5121837 | 6251 | { |
a2e40bb6 | 6252 | struct i802_bss *bss = priv; |
e1bd4e19 | 6253 | struct wpa_driver_nl80211_data *drv = bss->drv; |
c5121837 | 6254 | struct ieee80211_mgmt mgmt; |
05e5e615 DL |
6255 | u8 channel; |
6256 | ||
6257 | if (ieee80211_freq_to_chan(bss->freq, &channel) == | |
6258 | HOSTAPD_MODE_IEEE80211AD) { | |
6259 | /* Deauthentication is not used in DMG/IEEE 802.11ad; | |
6260 | * disassociate the STA instead. */ | |
6261 | return i802_sta_disassoc(priv, own_addr, addr, reason); | |
6262 | } | |
c5121837 | 6263 | |
0d391b03 BC |
6264 | if (is_mesh_interface(drv->nlmode)) |
6265 | return -1; | |
6266 | ||
e1bd4e19 | 6267 | if (drv->device_ap_sme) |
59d7148a | 6268 | return wpa_driver_nl80211_sta_remove(bss, addr, 1, reason); |
e1bd4e19 | 6269 | |
c5121837 JM |
6270 | memset(&mgmt, 0, sizeof(mgmt)); |
6271 | mgmt.frame_control = IEEE80211_FC(WLAN_FC_TYPE_MGMT, | |
6272 | WLAN_FC_STYPE_DEAUTH); | |
6273 | memcpy(mgmt.da, addr, ETH_ALEN); | |
731723a5 JM |
6274 | memcpy(mgmt.sa, own_addr, ETH_ALEN); |
6275 | memcpy(mgmt.bssid, own_addr, ETH_ALEN); | |
c5121837 | 6276 | mgmt.u.deauth.reason_code = host_to_le16(reason); |
a2e40bb6 | 6277 | return wpa_driver_nl80211_send_mlme(bss, (u8 *) &mgmt, |
9f324b61 | 6278 | IEEE80211_HDRLEN + |
9ebce9c5 | 6279 | sizeof(mgmt.u.deauth), 0, 0, 0, 0, |
2d3943ce | 6280 | 0, NULL, 0); |
c5121837 JM |
6281 | } |
6282 | ||
6283 | ||
731723a5 JM |
6284 | static int i802_sta_disassoc(void *priv, const u8 *own_addr, const u8 *addr, |
6285 | int reason) | |
c5121837 | 6286 | { |
a2e40bb6 | 6287 | struct i802_bss *bss = priv; |
e1bd4e19 | 6288 | struct wpa_driver_nl80211_data *drv = bss->drv; |
c5121837 JM |
6289 | struct ieee80211_mgmt mgmt; |
6290 | ||
0d391b03 BC |
6291 | if (is_mesh_interface(drv->nlmode)) |
6292 | return -1; | |
6293 | ||
e1bd4e19 | 6294 | if (drv->device_ap_sme) |
59d7148a | 6295 | return wpa_driver_nl80211_sta_remove(bss, addr, 0, reason); |
e1bd4e19 | 6296 | |
c5121837 JM |
6297 | memset(&mgmt, 0, sizeof(mgmt)); |
6298 | mgmt.frame_control = IEEE80211_FC(WLAN_FC_TYPE_MGMT, | |
6299 | WLAN_FC_STYPE_DISASSOC); | |
6300 | memcpy(mgmt.da, addr, ETH_ALEN); | |
731723a5 JM |
6301 | memcpy(mgmt.sa, own_addr, ETH_ALEN); |
6302 | memcpy(mgmt.bssid, own_addr, ETH_ALEN); | |
c5121837 | 6303 | mgmt.u.disassoc.reason_code = host_to_le16(reason); |
a2e40bb6 | 6304 | return wpa_driver_nl80211_send_mlme(bss, (u8 *) &mgmt, |
9f324b61 | 6305 | IEEE80211_HDRLEN + |
9ebce9c5 | 6306 | sizeof(mgmt.u.disassoc), 0, 0, 0, 0, |
2d3943ce | 6307 | 0, NULL, 0); |
c5121837 JM |
6308 | } |
6309 | ||
6310 | ||
9b4d9c8b JM |
6311 | static void dump_ifidx(struct wpa_driver_nl80211_data *drv) |
6312 | { | |
6313 | char buf[200], *pos, *end; | |
6314 | int i, res; | |
6315 | ||
6316 | pos = buf; | |
6317 | end = pos + sizeof(buf); | |
6318 | ||
6319 | for (i = 0; i < drv->num_if_indices; i++) { | |
6320 | if (!drv->if_indices[i]) | |
6321 | continue; | |
732b1d20 MB |
6322 | res = os_snprintf(pos, end - pos, " %d(%d)", |
6323 | drv->if_indices[i], | |
6324 | drv->if_indices_reason[i]); | |
d85e1fc8 | 6325 | if (os_snprintf_error(end - pos, res)) |
9b4d9c8b JM |
6326 | break; |
6327 | pos += res; | |
6328 | } | |
6329 | *pos = '\0'; | |
6330 | ||
6331 | wpa_printf(MSG_DEBUG, "nl80211: if_indices[%d]:%s", | |
6332 | drv->num_if_indices, buf); | |
6333 | } | |
6334 | ||
6335 | ||
732b1d20 MB |
6336 | static void add_ifidx(struct wpa_driver_nl80211_data *drv, int ifidx, |
6337 | int ifidx_reason) | |
f07ead6a JM |
6338 | { |
6339 | int i; | |
732b1d20 | 6340 | int *old, *old_reason; |
f07ead6a | 6341 | |
732b1d20 MB |
6342 | wpa_printf(MSG_DEBUG, |
6343 | "nl80211: Add own interface ifindex %d (ifidx_reason %d)", | |
6344 | ifidx, ifidx_reason); | |
6345 | if (have_ifidx(drv, ifidx, ifidx_reason)) { | |
b36935be MB |
6346 | wpa_printf(MSG_DEBUG, "nl80211: ifindex %d already in the list", |
6347 | ifidx); | |
6348 | return; | |
6349 | } | |
f07ead6a JM |
6350 | for (i = 0; i < drv->num_if_indices; i++) { |
6351 | if (drv->if_indices[i] == 0) { | |
6352 | drv->if_indices[i] = ifidx; | |
732b1d20 | 6353 | drv->if_indices_reason[i] = ifidx_reason; |
9b4d9c8b | 6354 | dump_ifidx(drv); |
f07ead6a JM |
6355 | return; |
6356 | } | |
6357 | } | |
6358 | ||
6359 | if (drv->if_indices != drv->default_if_indices) | |
6360 | old = drv->if_indices; | |
6361 | else | |
6362 | old = NULL; | |
6363 | ||
732b1d20 MB |
6364 | if (drv->if_indices_reason != drv->default_if_indices_reason) |
6365 | old_reason = drv->if_indices_reason; | |
6366 | else | |
6367 | old_reason = NULL; | |
6368 | ||
067ffa26 JM |
6369 | drv->if_indices = os_realloc_array(old, drv->num_if_indices + 1, |
6370 | sizeof(int)); | |
732b1d20 MB |
6371 | drv->if_indices_reason = os_realloc_array(old_reason, |
6372 | drv->num_if_indices + 1, | |
6373 | sizeof(int)); | |
f07ead6a JM |
6374 | if (!drv->if_indices) { |
6375 | if (!old) | |
6376 | drv->if_indices = drv->default_if_indices; | |
6377 | else | |
6378 | drv->if_indices = old; | |
732b1d20 MB |
6379 | } |
6380 | if (!drv->if_indices_reason) { | |
6381 | if (!old_reason) | |
6382 | drv->if_indices_reason = drv->default_if_indices_reason; | |
6383 | else | |
29eddc3d | 6384 | drv->if_indices_reason = old_reason; |
732b1d20 MB |
6385 | } |
6386 | if (!drv->if_indices || !drv->if_indices_reason) { | |
f07ead6a JM |
6387 | wpa_printf(MSG_ERROR, "Failed to reallocate memory for " |
6388 | "interfaces"); | |
6389 | wpa_printf(MSG_ERROR, "Ignoring EAPOL on interface %d", ifidx); | |
6390 | return; | |
732b1d20 MB |
6391 | } |
6392 | if (!old) | |
f07ead6a JM |
6393 | os_memcpy(drv->if_indices, drv->default_if_indices, |
6394 | sizeof(drv->default_if_indices)); | |
732b1d20 MB |
6395 | if (!old_reason) |
6396 | os_memcpy(drv->if_indices_reason, | |
6397 | drv->default_if_indices_reason, | |
6398 | sizeof(drv->default_if_indices_reason)); | |
f07ead6a | 6399 | drv->if_indices[drv->num_if_indices] = ifidx; |
732b1d20 | 6400 | drv->if_indices_reason[drv->num_if_indices] = ifidx_reason; |
f07ead6a | 6401 | drv->num_if_indices++; |
9b4d9c8b | 6402 | dump_ifidx(drv); |
f07ead6a JM |
6403 | } |
6404 | ||
6405 | ||
732b1d20 MB |
6406 | static void del_ifidx(struct wpa_driver_nl80211_data *drv, int ifidx, |
6407 | int ifidx_reason) | |
f07ead6a JM |
6408 | { |
6409 | int i; | |
6410 | ||
6411 | for (i = 0; i < drv->num_if_indices; i++) { | |
732b1d20 MB |
6412 | if ((drv->if_indices[i] == ifidx || ifidx == IFIDX_ANY) && |
6413 | (drv->if_indices_reason[i] == ifidx_reason || | |
6414 | ifidx_reason == IFIDX_ANY)) { | |
f07ead6a JM |
6415 | drv->if_indices[i] = 0; |
6416 | break; | |
6417 | } | |
6418 | } | |
9b4d9c8b | 6419 | dump_ifidx(drv); |
f07ead6a JM |
6420 | } |
6421 | ||
6422 | ||
732b1d20 MB |
6423 | static int have_ifidx(struct wpa_driver_nl80211_data *drv, int ifidx, |
6424 | int ifidx_reason) | |
f07ead6a JM |
6425 | { |
6426 | int i; | |
6427 | ||
6428 | for (i = 0; i < drv->num_if_indices; i++) | |
732b1d20 MB |
6429 | if (drv->if_indices[i] == ifidx && |
6430 | (drv->if_indices_reason[i] == ifidx_reason || | |
6431 | ifidx_reason == IFIDX_ANY)) | |
f07ead6a JM |
6432 | return 1; |
6433 | ||
6434 | return 0; | |
6435 | } | |
6436 | ||
6437 | ||
6438 | static int i802_set_wds_sta(void *priv, const u8 *addr, int aid, int val, | |
0e80ea2c | 6439 | const char *bridge_ifname, char *ifname_wds) |
f07ead6a JM |
6440 | { |
6441 | struct i802_bss *bss = priv; | |
6442 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
6443 | char name[IFNAMSIZ + 1]; | |
6444 | ||
6445 | os_snprintf(name, sizeof(name), "%s.sta%d", bss->ifname, aid); | |
69dd2967 SM |
6446 | if (ifname_wds) |
6447 | os_strlcpy(ifname_wds, name, IFNAMSIZ + 1); | |
6448 | ||
f07ead6a JM |
6449 | wpa_printf(MSG_DEBUG, "nl80211: Set WDS STA addr=" MACSTR |
6450 | " aid=%d val=%d name=%s", MAC2STR(addr), aid, val, name); | |
6451 | if (val) { | |
6452 | if (!if_nametoindex(name)) { | |
6453 | if (nl80211_create_iface(drv, name, | |
6454 | NL80211_IFTYPE_AP_VLAN, | |
2aec4f3c JM |
6455 | bss->addr, 1, NULL, NULL, 0) < |
6456 | 0) | |
f07ead6a JM |
6457 | return -1; |
6458 | if (bridge_ifname && | |
c81eff1a BG |
6459 | linux_br_add_if(drv->global->ioctl_sock, |
6460 | bridge_ifname, name) < 0) | |
f07ead6a JM |
6461 | return -1; |
6462 | } | |
75227f3a JM |
6463 | if (linux_set_iface_flags(drv->global->ioctl_sock, name, 1)) { |
6464 | wpa_printf(MSG_ERROR, "nl80211: Failed to set WDS STA " | |
6465 | "interface %s up", name); | |
6466 | } | |
f07ead6a JM |
6467 | return i802_set_sta_vlan(priv, addr, name, 0); |
6468 | } else { | |
c34e618d FF |
6469 | if (bridge_ifname) |
6470 | linux_br_del_if(drv->global->ioctl_sock, bridge_ifname, | |
6471 | name); | |
6472 | ||
f07ead6a | 6473 | i802_set_sta_vlan(priv, addr, bss->ifname, 0); |
d0595b25 FF |
6474 | nl80211_remove_iface(drv, if_nametoindex(name)); |
6475 | return 0; | |
f07ead6a JM |
6476 | } |
6477 | } | |
6478 | ||
6479 | ||
6480 | static void handle_eapol(int sock, void *eloop_ctx, void *sock_ctx) | |
6481 | { | |
6482 | struct wpa_driver_nl80211_data *drv = eloop_ctx; | |
6483 | struct sockaddr_ll lladdr; | |
6484 | unsigned char buf[3000]; | |
6485 | int len; | |
6486 | socklen_t fromlen = sizeof(lladdr); | |
6487 | ||
6488 | len = recvfrom(sock, buf, sizeof(buf), 0, | |
6489 | (struct sockaddr *)&lladdr, &fromlen); | |
6490 | if (len < 0) { | |
7ac3616d JM |
6491 | wpa_printf(MSG_ERROR, "nl80211: EAPOL recv failed: %s", |
6492 | strerror(errno)); | |
f07ead6a JM |
6493 | return; |
6494 | } | |
6495 | ||
732b1d20 | 6496 | if (have_ifidx(drv, lladdr.sll_ifindex, IFIDX_ANY)) |
f07ead6a JM |
6497 | drv_event_eapol_rx(drv->ctx, lladdr.sll_addr, buf, len); |
6498 | } | |
6499 | ||
6500 | ||
94627f6c | 6501 | static int i802_check_bridge(struct wpa_driver_nl80211_data *drv, |
e17a2477 | 6502 | struct i802_bss *bss, |
94627f6c JM |
6503 | const char *brname, const char *ifname) |
6504 | { | |
6c6678e7 | 6505 | int br_ifindex; |
94627f6c JM |
6506 | char in_br[IFNAMSIZ]; |
6507 | ||
e17a2477 | 6508 | os_strlcpy(bss->brname, brname, IFNAMSIZ); |
6c6678e7 | 6509 | br_ifindex = if_nametoindex(brname); |
6c6678e7 | 6510 | if (br_ifindex == 0) { |
94627f6c JM |
6511 | /* |
6512 | * Bridge was configured, but the bridge device does | |
6513 | * not exist. Try to add it now. | |
6514 | */ | |
c81eff1a | 6515 | if (linux_br_add(drv->global->ioctl_sock, brname) < 0) { |
94627f6c JM |
6516 | wpa_printf(MSG_ERROR, "nl80211: Failed to add the " |
6517 | "bridge interface %s: %s", | |
6518 | brname, strerror(errno)); | |
6519 | return -1; | |
6520 | } | |
e17a2477 | 6521 | bss->added_bridge = 1; |
8997613c | 6522 | br_ifindex = if_nametoindex(brname); |
732b1d20 | 6523 | add_ifidx(drv, br_ifindex, drv->ifindex); |
94627f6c | 6524 | } |
8997613c | 6525 | bss->br_ifindex = br_ifindex; |
94627f6c JM |
6526 | |
6527 | if (linux_br_get(in_br, ifname) == 0) { | |
6528 | if (os_strcmp(in_br, brname) == 0) | |
6529 | return 0; /* already in the bridge */ | |
6530 | ||
6531 | wpa_printf(MSG_DEBUG, "nl80211: Removing interface %s from " | |
6532 | "bridge %s", ifname, in_br); | |
c81eff1a BG |
6533 | if (linux_br_del_if(drv->global->ioctl_sock, in_br, ifname) < |
6534 | 0) { | |
94627f6c JM |
6535 | wpa_printf(MSG_ERROR, "nl80211: Failed to " |
6536 | "remove interface %s from bridge " | |
6537 | "%s: %s", | |
fdbfb63e | 6538 | ifname, in_br, strerror(errno)); |
94627f6c JM |
6539 | return -1; |
6540 | } | |
6541 | } | |
6542 | ||
6543 | wpa_printf(MSG_DEBUG, "nl80211: Adding interface %s into bridge %s", | |
6544 | ifname, brname); | |
c81eff1a | 6545 | if (linux_br_add_if(drv->global->ioctl_sock, brname, ifname) < 0) { |
94627f6c JM |
6546 | wpa_printf(MSG_ERROR, "nl80211: Failed to add interface %s " |
6547 | "into bridge %s: %s", | |
6548 | ifname, brname, strerror(errno)); | |
6549 | return -1; | |
6550 | } | |
e17a2477 | 6551 | bss->added_if_into_bridge = 1; |
94627f6c JM |
6552 | |
6553 | return 0; | |
6554 | } | |
6555 | ||
6556 | ||
92f475b4 JM |
6557 | static void *i802_init(struct hostapd_data *hapd, |
6558 | struct wpa_init_params *params) | |
c5121837 JM |
6559 | { |
6560 | struct wpa_driver_nl80211_data *drv; | |
a2e40bb6 | 6561 | struct i802_bss *bss; |
c5121837 | 6562 | size_t i; |
cb05808c AN |
6563 | char master_ifname[IFNAMSIZ]; |
6564 | int ifindex, br_ifindex = 0; | |
94627f6c | 6565 | int br_added = 0; |
c5121837 | 6566 | |
0d547d5f JM |
6567 | bss = wpa_driver_nl80211_drv_init(hapd, params->ifname, |
6568 | params->global_priv, 1, | |
0ecff8d7 | 6569 | params->bssid, params->driver_params); |
a2e40bb6 | 6570 | if (bss == NULL) |
c5121837 | 6571 | return NULL; |
c5121837 | 6572 | |
a2e40bb6 | 6573 | drv = bss->drv; |
7635bfb0 | 6574 | |
cb05808c | 6575 | if (linux_br_get(master_ifname, params->ifname) == 0) { |
94627f6c | 6576 | wpa_printf(MSG_DEBUG, "nl80211: Interface %s is in bridge %s", |
cb05808c AN |
6577 | params->ifname, master_ifname); |
6578 | br_ifindex = if_nametoindex(master_ifname); | |
6579 | os_strlcpy(bss->brname, master_ifname, IFNAMSIZ); | |
6580 | } else if ((params->num_bridge == 0 || !params->bridge[0]) && | |
6581 | linux_master_get(master_ifname, params->ifname) == 0) { | |
6582 | wpa_printf(MSG_DEBUG, "nl80211: Interface %s is in master %s", | |
6583 | params->ifname, master_ifname); | |
6584 | /* start listening for EAPOL on the master interface */ | |
732b1d20 | 6585 | add_ifidx(drv, if_nametoindex(master_ifname), drv->ifindex); |
f2d6c17a DL |
6586 | |
6587 | /* check if master itself is under bridge */ | |
6588 | if (linux_br_get(master_ifname, master_ifname) == 0) { | |
6589 | wpa_printf(MSG_DEBUG, "nl80211: which is in bridge %s", | |
6590 | master_ifname); | |
6591 | br_ifindex = if_nametoindex(master_ifname); | |
6592 | os_strlcpy(bss->brname, master_ifname, IFNAMSIZ); | |
6593 | } | |
94627f6c | 6594 | } else { |
cb05808c | 6595 | master_ifname[0] = '\0'; |
94627f6c | 6596 | } |
cb05808c | 6597 | |
6c6678e7 | 6598 | bss->br_ifindex = br_ifindex; |
94627f6c | 6599 | |
92f475b4 | 6600 | for (i = 0; i < params->num_bridge; i++) { |
94627f6c JM |
6601 | if (params->bridge[i]) { |
6602 | ifindex = if_nametoindex(params->bridge[i]); | |
6603 | if (ifindex) | |
732b1d20 | 6604 | add_ifidx(drv, ifindex, drv->ifindex); |
94627f6c JM |
6605 | if (ifindex == br_ifindex) |
6606 | br_added = 1; | |
6607 | } | |
c5121837 | 6608 | } |
c5121837 | 6609 | |
ad1e68e6 | 6610 | /* start listening for EAPOL on the default AP interface */ |
732b1d20 | 6611 | add_ifidx(drv, drv->ifindex, IFIDX_ANY); |
ad1e68e6 | 6612 | |
5ef8e39f JM |
6613 | if (params->num_bridge && params->bridge[0]) { |
6614 | if (i802_check_bridge(drv, bss, params->bridge[0], | |
6615 | params->ifname) < 0) | |
6616 | goto failed; | |
cb05808c | 6617 | if (os_strcmp(params->bridge[0], master_ifname) != 0) |
5ef8e39f JM |
6618 | br_added = 1; |
6619 | } | |
6620 | ||
6621 | if (!br_added && br_ifindex && | |
6622 | (params->num_bridge == 0 || !params->bridge[0])) | |
732b1d20 | 6623 | add_ifidx(drv, br_ifindex, drv->ifindex); |
94627f6c | 6624 | |
97ed9a06 KP |
6625 | #ifdef CONFIG_LIBNL3_ROUTE |
6626 | if (bss->added_if_into_bridge) { | |
6627 | drv->rtnl_sk = nl_socket_alloc(); | |
6628 | if (drv->rtnl_sk == NULL) { | |
6629 | wpa_printf(MSG_ERROR, "nl80211: Failed to allocate nl_sock"); | |
6630 | goto failed; | |
6631 | } | |
6632 | ||
6633 | if (nl_connect(drv->rtnl_sk, NETLINK_ROUTE)) { | |
6634 | wpa_printf(MSG_ERROR, "nl80211: Failed to connect nl_sock to NETLINK_ROUTE: %s", | |
6635 | strerror(errno)); | |
6636 | goto failed; | |
6637 | } | |
6638 | } | |
6639 | #endif /* CONFIG_LIBNL3_ROUTE */ | |
6640 | ||
ad1e68e6 JM |
6641 | drv->eapol_sock = socket(PF_PACKET, SOCK_DGRAM, htons(ETH_P_PAE)); |
6642 | if (drv->eapol_sock < 0) { | |
7ac3616d JM |
6643 | wpa_printf(MSG_ERROR, "nl80211: socket(PF_PACKET, SOCK_DGRAM, ETH_P_PAE) failed: %s", |
6644 | strerror(errno)); | |
bbaf0837 | 6645 | goto failed; |
ad1e68e6 JM |
6646 | } |
6647 | ||
6648 | if (eloop_register_read_sock(drv->eapol_sock, handle_eapol, drv, NULL)) | |
6649 | { | |
7ac3616d | 6650 | wpa_printf(MSG_INFO, "nl80211: Could not register read socket for eapol"); |
c5121837 | 6651 | goto failed; |
ad1e68e6 JM |
6652 | } |
6653 | ||
c81eff1a BG |
6654 | if (linux_get_ifhwaddr(drv->global->ioctl_sock, bss->ifname, |
6655 | params->own_addr)) | |
bbaf0837 | 6656 | goto failed; |
fee354c7 | 6657 | os_memcpy(drv->perm_addr, params->own_addr, ETH_ALEN); |
c5121837 | 6658 | |
341eebee JB |
6659 | memcpy(bss->addr, params->own_addr, ETH_ALEN); |
6660 | ||
a2e40bb6 | 6661 | return bss; |
c5121837 JM |
6662 | |
6663 | failed: | |
7635bfb0 | 6664 | wpa_driver_nl80211_deinit(bss); |
bbaf0837 JM |
6665 | return NULL; |
6666 | } | |
c5121837 | 6667 | |
c5121837 | 6668 | |
bbaf0837 JM |
6669 | static void i802_deinit(void *priv) |
6670 | { | |
9ebce9c5 JM |
6671 | struct i802_bss *bss = priv; |
6672 | wpa_driver_nl80211_deinit(bss); | |
c5121837 JM |
6673 | } |
6674 | ||
c5121837 | 6675 | |
22a7c9d7 JM |
6676 | static enum nl80211_iftype wpa_driver_nl80211_if_type( |
6677 | enum wpa_driver_if_type type) | |
6678 | { | |
6679 | switch (type) { | |
6680 | case WPA_IF_STATION: | |
9f51b113 | 6681 | return NL80211_IFTYPE_STATION; |
75bde05d JM |
6682 | case WPA_IF_P2P_CLIENT: |
6683 | case WPA_IF_P2P_GROUP: | |
9f51b113 | 6684 | return NL80211_IFTYPE_P2P_CLIENT; |
22a7c9d7 JM |
6685 | case WPA_IF_AP_VLAN: |
6686 | return NL80211_IFTYPE_AP_VLAN; | |
6687 | case WPA_IF_AP_BSS: | |
6688 | return NL80211_IFTYPE_AP; | |
9f51b113 JB |
6689 | case WPA_IF_P2P_GO: |
6690 | return NL80211_IFTYPE_P2P_GO; | |
7aad838c NS |
6691 | case WPA_IF_P2P_DEVICE: |
6692 | return NL80211_IFTYPE_P2P_DEVICE; | |
5b78493f MH |
6693 | case WPA_IF_MESH: |
6694 | return NL80211_IFTYPE_MESH_POINT; | |
98342208 AK |
6695 | default: |
6696 | return -1; | |
22a7c9d7 | 6697 | } |
22a7c9d7 JM |
6698 | } |
6699 | ||
6700 | ||
f2ed8023 JM |
6701 | static int nl80211_addr_in_use(struct nl80211_global *global, const u8 *addr) |
6702 | { | |
6703 | struct wpa_driver_nl80211_data *drv; | |
6704 | dl_list_for_each(drv, &global->interfaces, | |
6705 | struct wpa_driver_nl80211_data, list) { | |
834ee56f | 6706 | if (os_memcmp(addr, drv->first_bss->addr, ETH_ALEN) == 0) |
f2ed8023 JM |
6707 | return 1; |
6708 | } | |
6709 | return 0; | |
6710 | } | |
6711 | ||
6712 | ||
5b78493f | 6713 | static int nl80211_vif_addr(struct wpa_driver_nl80211_data *drv, u8 *new_addr) |
f2ed8023 JM |
6714 | { |
6715 | unsigned int idx; | |
6716 | ||
6717 | if (!drv->global) | |
6718 | return -1; | |
6719 | ||
834ee56f | 6720 | os_memcpy(new_addr, drv->first_bss->addr, ETH_ALEN); |
f2ed8023 | 6721 | for (idx = 0; idx < 64; idx++) { |
834ee56f | 6722 | new_addr[0] = drv->first_bss->addr[0] | 0x02; |
f2ed8023 JM |
6723 | new_addr[0] ^= idx << 2; |
6724 | if (!nl80211_addr_in_use(drv->global, new_addr)) | |
6725 | break; | |
6726 | } | |
6727 | if (idx == 64) | |
6728 | return -1; | |
6729 | ||
5b78493f | 6730 | wpa_printf(MSG_DEBUG, "nl80211: Assigned new virtual interface address " |
f2ed8023 JM |
6731 | MACSTR, MAC2STR(new_addr)); |
6732 | ||
6733 | return 0; | |
6734 | } | |
6735 | ||
6736 | ||
f632e483 AS |
6737 | struct wdev_info { |
6738 | u64 wdev_id; | |
6739 | int wdev_id_set; | |
6740 | u8 macaddr[ETH_ALEN]; | |
6741 | }; | |
6742 | ||
6743 | static int nl80211_wdev_handler(struct nl_msg *msg, void *arg) | |
e472e1b4 AS |
6744 | { |
6745 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); | |
6746 | struct nlattr *tb[NL80211_ATTR_MAX + 1]; | |
f632e483 | 6747 | struct wdev_info *wi = arg; |
e472e1b4 AS |
6748 | |
6749 | nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), | |
6750 | genlmsg_attrlen(gnlh, 0), NULL); | |
6751 | if (tb[NL80211_ATTR_WDEV]) { | |
f632e483 AS |
6752 | wi->wdev_id = nla_get_u64(tb[NL80211_ATTR_WDEV]); |
6753 | wi->wdev_id_set = 1; | |
e472e1b4 AS |
6754 | } |
6755 | ||
6756 | if (tb[NL80211_ATTR_MAC]) | |
f632e483 | 6757 | os_memcpy(wi->macaddr, nla_data(tb[NL80211_ATTR_MAC]), |
e472e1b4 AS |
6758 | ETH_ALEN); |
6759 | ||
6760 | return NL_SKIP; | |
6761 | } | |
6762 | ||
6763 | ||
7ab68865 | 6764 | static int wpa_driver_nl80211_if_add(void *priv, enum wpa_driver_if_type type, |
8043e725 | 6765 | const char *ifname, const u8 *addr, |
f3585c8a | 6766 | void *bss_ctx, void **drv_priv, |
e17a2477 | 6767 | char *force_ifname, u8 *if_addr, |
d8a3b66d AS |
6768 | const char *bridge, int use_existing, |
6769 | int setup_ap) | |
22a7c9d7 | 6770 | { |
e472e1b4 | 6771 | enum nl80211_iftype nlmode; |
a2e40bb6 FF |
6772 | struct i802_bss *bss = priv; |
6773 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
22a7c9d7 | 6774 | int ifidx; |
2aec4f3c | 6775 | int added = 1; |
22a7c9d7 | 6776 | |
f3585c8a JM |
6777 | if (addr) |
6778 | os_memcpy(if_addr, addr, ETH_ALEN); | |
e472e1b4 AS |
6779 | nlmode = wpa_driver_nl80211_if_type(type); |
6780 | if (nlmode == NL80211_IFTYPE_P2P_DEVICE) { | |
f632e483 AS |
6781 | struct wdev_info p2pdev_info; |
6782 | ||
6783 | os_memset(&p2pdev_info, 0, sizeof(p2pdev_info)); | |
e472e1b4 | 6784 | ifidx = nl80211_create_iface(drv, ifname, nlmode, addr, |
f632e483 | 6785 | 0, nl80211_wdev_handler, |
2aec4f3c | 6786 | &p2pdev_info, use_existing); |
f632e483 | 6787 | if (!p2pdev_info.wdev_id_set || ifidx != 0) { |
e472e1b4 AS |
6788 | wpa_printf(MSG_ERROR, "nl80211: Failed to create a P2P Device interface %s", |
6789 | ifname); | |
e472e1b4 AS |
6790 | return -1; |
6791 | } | |
f632e483 AS |
6792 | |
6793 | drv->global->if_add_wdevid = p2pdev_info.wdev_id; | |
6794 | drv->global->if_add_wdevid_set = p2pdev_info.wdev_id_set; | |
6795 | if (!is_zero_ether_addr(p2pdev_info.macaddr)) | |
6796 | os_memcpy(if_addr, p2pdev_info.macaddr, ETH_ALEN); | |
6797 | wpa_printf(MSG_DEBUG, "nl80211: New P2P Device interface %s (0x%llx) created", | |
6798 | ifname, | |
6799 | (long long unsigned int) p2pdev_info.wdev_id); | |
e472e1b4 AS |
6800 | } else { |
6801 | ifidx = nl80211_create_iface(drv, ifname, nlmode, addr, | |
2aec4f3c JM |
6802 | 0, NULL, NULL, use_existing); |
6803 | if (use_existing && ifidx == -ENFILE) { | |
6804 | added = 0; | |
6805 | ifidx = if_nametoindex(ifname); | |
6806 | } else if (ifidx < 0) { | |
e472e1b4 AS |
6807 | return -1; |
6808 | } | |
22a7c9d7 JM |
6809 | } |
6810 | ||
ab7a1add | 6811 | if (!addr) { |
8ea8a89c | 6812 | if (nlmode == NL80211_IFTYPE_P2P_DEVICE) |
ab7a1add AS |
6813 | os_memcpy(if_addr, bss->addr, ETH_ALEN); |
6814 | else if (linux_get_ifhwaddr(drv->global->ioctl_sock, | |
8ea8a89c | 6815 | ifname, if_addr) < 0) { |
2aec4f3c JM |
6816 | if (added) |
6817 | nl80211_remove_iface(drv, ifidx); | |
ab7a1add AS |
6818 | return -1; |
6819 | } | |
c55f774d JM |
6820 | } |
6821 | ||
c55f774d JM |
6822 | if (!addr && |
6823 | (type == WPA_IF_P2P_CLIENT || type == WPA_IF_P2P_GROUP || | |
8ea8a89c JM |
6824 | type == WPA_IF_P2P_GO || type == WPA_IF_MESH || |
6825 | type == WPA_IF_STATION)) { | |
6826 | /* Enforce unique address */ | |
ab7a1add | 6827 | u8 new_addr[ETH_ALEN]; |
c55f774d | 6828 | |
ab7a1add | 6829 | if (linux_get_ifhwaddr(drv->global->ioctl_sock, ifname, |
c81eff1a | 6830 | new_addr) < 0) { |
ea39367c MK |
6831 | if (added) |
6832 | nl80211_remove_iface(drv, ifidx); | |
c55f774d JM |
6833 | return -1; |
6834 | } | |
f608081c | 6835 | if (nl80211_addr_in_use(drv->global, new_addr)) { |
c55f774d | 6836 | wpa_printf(MSG_DEBUG, "nl80211: Allocate new address " |
8ea8a89c | 6837 | "for interface %s type %d", ifname, type); |
5b78493f | 6838 | if (nl80211_vif_addr(drv, new_addr) < 0) { |
ea39367c MK |
6839 | if (added) |
6840 | nl80211_remove_iface(drv, ifidx); | |
c55f774d JM |
6841 | return -1; |
6842 | } | |
c81eff1a | 6843 | if (linux_set_ifhwaddr(drv->global->ioctl_sock, ifname, |
c55f774d | 6844 | new_addr) < 0) { |
ea39367c MK |
6845 | if (added) |
6846 | nl80211_remove_iface(drv, ifidx); | |
c55f774d JM |
6847 | return -1; |
6848 | } | |
c55f774d | 6849 | } |
f67eeb5c | 6850 | os_memcpy(if_addr, new_addr, ETH_ALEN); |
c55f774d | 6851 | } |
f3585c8a | 6852 | |
d8a3b66d | 6853 | if (type == WPA_IF_AP_BSS && setup_ap) { |
f5eb9da3 JM |
6854 | struct i802_bss *new_bss = os_zalloc(sizeof(*new_bss)); |
6855 | if (new_bss == NULL) { | |
2aec4f3c JM |
6856 | if (added) |
6857 | nl80211_remove_iface(drv, ifidx); | |
f5eb9da3 JM |
6858 | return -1; |
6859 | } | |
6860 | ||
6861 | if (bridge && | |
6862 | i802_check_bridge(drv, new_bss, bridge, ifname) < 0) { | |
6863 | wpa_printf(MSG_ERROR, "nl80211: Failed to add the new " | |
6864 | "interface %s to a bridge %s", | |
6865 | ifname, bridge); | |
2aec4f3c JM |
6866 | if (added) |
6867 | nl80211_remove_iface(drv, ifidx); | |
f5eb9da3 JM |
6868 | os_free(new_bss); |
6869 | return -1; | |
6870 | } | |
6871 | ||
c81eff1a BG |
6872 | if (linux_set_iface_flags(drv->global->ioctl_sock, ifname, 1)) |
6873 | { | |
ea39367c MK |
6874 | if (added) |
6875 | nl80211_remove_iface(drv, ifidx); | |
07179987 | 6876 | os_free(new_bss); |
22a7c9d7 JM |
6877 | return -1; |
6878 | } | |
a2e40bb6 | 6879 | os_strlcpy(new_bss->ifname, ifname, IFNAMSIZ); |
341eebee | 6880 | os_memcpy(new_bss->addr, if_addr, ETH_ALEN); |
a2e40bb6 FF |
6881 | new_bss->ifindex = ifidx; |
6882 | new_bss->drv = drv; | |
834ee56f KP |
6883 | new_bss->next = drv->first_bss->next; |
6884 | new_bss->freq = drv->first_bss->freq; | |
a5e1eb20 | 6885 | new_bss->ctx = bss_ctx; |
2aec4f3c | 6886 | new_bss->added_if = added; |
834ee56f | 6887 | drv->first_bss->next = new_bss; |
a2e40bb6 FF |
6888 | if (drv_priv) |
6889 | *drv_priv = new_bss; | |
cc7a48d1 | 6890 | nl80211_init_bss(new_bss); |
3dd1d890 YAP |
6891 | |
6892 | /* Subscribe management frames for this WPA_IF_AP_BSS */ | |
6893 | if (nl80211_setup_ap(new_bss)) | |
6894 | return -1; | |
22a7c9d7 | 6895 | } |
22a7c9d7 | 6896 | |
ff6a158b JM |
6897 | if (drv->global) |
6898 | drv->global->if_add_ifindex = ifidx; | |
6899 | ||
d1bb7aed JJ |
6900 | /* |
6901 | * Some virtual interfaces need to process EAPOL packets and events on | |
6902 | * the parent interface. This is used mainly with hostapd. | |
6903 | */ | |
6904 | if (ifidx > 0 && | |
6905 | (drv->hostapd || | |
6906 | nlmode == NL80211_IFTYPE_AP_VLAN || | |
6907 | nlmode == NL80211_IFTYPE_WDS || | |
6908 | nlmode == NL80211_IFTYPE_MONITOR)) | |
732b1d20 | 6909 | add_ifidx(drv, ifidx, IFIDX_ANY); |
b36935be | 6910 | |
22a7c9d7 JM |
6911 | return 0; |
6912 | } | |
6913 | ||
6914 | ||
9ebce9c5 | 6915 | static int wpa_driver_nl80211_if_remove(struct i802_bss *bss, |
22a7c9d7 JM |
6916 | enum wpa_driver_if_type type, |
6917 | const char *ifname) | |
6918 | { | |
a2e40bb6 | 6919 | struct wpa_driver_nl80211_data *drv = bss->drv; |
22a7c9d7 JM |
6920 | int ifindex = if_nametoindex(ifname); |
6921 | ||
2aec4f3c JM |
6922 | wpa_printf(MSG_DEBUG, "nl80211: %s(type=%d ifname=%s) ifindex=%d added_if=%d", |
6923 | __func__, type, ifname, ifindex, bss->added_if); | |
158b090c | 6924 | if (ifindex > 0 && (bss->added_if || bss->ifindex != ifindex)) |
2b72df63 | 6925 | nl80211_remove_iface(drv, ifindex); |
de884303 JM |
6926 | else if (ifindex > 0 && !bss->added_if) { |
6927 | struct wpa_driver_nl80211_data *drv2; | |
6928 | dl_list_for_each(drv2, &drv->global->interfaces, | |
732b1d20 MB |
6929 | struct wpa_driver_nl80211_data, list) { |
6930 | del_ifidx(drv2, ifindex, IFIDX_ANY); | |
6931 | del_ifidx(drv2, IFIDX_ANY, ifindex); | |
6932 | } | |
de884303 | 6933 | } |
c34e618d | 6934 | |
c34e618d FF |
6935 | if (type != WPA_IF_AP_BSS) |
6936 | return 0; | |
6937 | ||
e17a2477 | 6938 | if (bss->added_if_into_bridge) { |
c81eff1a BG |
6939 | if (linux_br_del_if(drv->global->ioctl_sock, bss->brname, |
6940 | bss->ifname) < 0) | |
e17a2477 JM |
6941 | wpa_printf(MSG_INFO, "nl80211: Failed to remove " |
6942 | "interface %s from bridge %s: %s", | |
6943 | bss->ifname, bss->brname, strerror(errno)); | |
6944 | } | |
6945 | if (bss->added_bridge) { | |
c81eff1a | 6946 | if (linux_br_del(drv->global->ioctl_sock, bss->brname) < 0) |
e17a2477 JM |
6947 | wpa_printf(MSG_INFO, "nl80211: Failed to remove " |
6948 | "bridge %s: %s", | |
6949 | bss->brname, strerror(errno)); | |
6950 | } | |
a2e40bb6 | 6951 | |
834ee56f | 6952 | if (bss != drv->first_bss) { |
8546ea19 | 6953 | struct i802_bss *tbss; |
a2e40bb6 | 6954 | |
2aec4f3c | 6955 | wpa_printf(MSG_DEBUG, "nl80211: Not the first BSS - remove it"); |
834ee56f | 6956 | for (tbss = drv->first_bss; tbss; tbss = tbss->next) { |
8546ea19 JM |
6957 | if (tbss->next == bss) { |
6958 | tbss->next = bss->next; | |
3dd1d890 YAP |
6959 | /* Unsubscribe management frames */ |
6960 | nl80211_teardown_ap(bss); | |
cc7a48d1 | 6961 | nl80211_destroy_bss(bss); |
5c9da160 MB |
6962 | if (!bss->added_if) |
6963 | i802_set_iface_flags(bss, 0); | |
8546ea19 JM |
6964 | os_free(bss); |
6965 | bss = NULL; | |
6966 | break; | |
6967 | } | |
22a7c9d7 | 6968 | } |
8546ea19 JM |
6969 | if (bss) |
6970 | wpa_printf(MSG_INFO, "nl80211: %s - could not find " | |
6971 | "BSS %p in the list", __func__, bss); | |
390e489c | 6972 | } else { |
2aec4f3c | 6973 | wpa_printf(MSG_DEBUG, "nl80211: First BSS - reassign context"); |
390e489c | 6974 | nl80211_teardown_ap(bss); |
2aec4f3c | 6975 | if (!bss->added_if && !drv->first_bss->next) |
a70cd0db | 6976 | wpa_driver_nl80211_del_beacon(bss); |
390e489c | 6977 | nl80211_destroy_bss(bss); |
2aec4f3c JM |
6978 | if (!bss->added_if) |
6979 | i802_set_iface_flags(bss, 0); | |
390e489c KP |
6980 | if (drv->first_bss->next) { |
6981 | drv->first_bss = drv->first_bss->next; | |
6982 | drv->ctx = drv->first_bss->ctx; | |
6983 | os_free(bss); | |
6984 | } else { | |
6985 | wpa_printf(MSG_DEBUG, "nl80211: No second BSS to reassign context to"); | |
6986 | } | |
22a7c9d7 | 6987 | } |
22a7c9d7 JM |
6988 | |
6989 | return 0; | |
6990 | } | |
6991 | ||
6992 | ||
55777702 JM |
6993 | static int cookie_handler(struct nl_msg *msg, void *arg) |
6994 | { | |
6995 | struct nlattr *tb[NL80211_ATTR_MAX + 1]; | |
6996 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); | |
6997 | u64 *cookie = arg; | |
6998 | nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), | |
6999 | genlmsg_attrlen(gnlh, 0), NULL); | |
7000 | if (tb[NL80211_ATTR_COOKIE]) | |
7001 | *cookie = nla_get_u64(tb[NL80211_ATTR_COOKIE]); | |
7002 | return NL_SKIP; | |
7003 | } | |
7004 | ||
7005 | ||
88df0ef7 | 7006 | static int nl80211_send_frame_cmd(struct i802_bss *bss, |
5dfca53f JB |
7007 | unsigned int freq, unsigned int wait, |
7008 | const u8 *buf, size_t buf_len, | |
88df0ef7 | 7009 | u64 *cookie_out, int no_cck, int no_ack, |
2d3943ce AO |
7010 | int offchanok, const u16 *csa_offs, |
7011 | size_t csa_offs_len) | |
9884f9cc | 7012 | { |
88df0ef7 | 7013 | struct wpa_driver_nl80211_data *drv = bss->drv; |
9884f9cc JB |
7014 | struct nl_msg *msg; |
7015 | u64 cookie; | |
7016 | int ret = -1; | |
7017 | ||
cc2ada86 | 7018 | wpa_printf(MSG_MSGDUMP, "nl80211: CMD_FRAME freq=%u wait=%u no_cck=%d " |
2e3e4566 JM |
7019 | "no_ack=%d offchanok=%d", |
7020 | freq, wait, no_cck, no_ack, offchanok); | |
c91f796f | 7021 | wpa_hexdump(MSG_MSGDUMP, "CMD_FRAME", buf, buf_len); |
9884f9cc | 7022 | |
56f77852 | 7023 | if (!(msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_FRAME)) || |
a862e4a3 JM |
7024 | (freq && nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq)) || |
7025 | (wait && nla_put_u32(msg, NL80211_ATTR_DURATION, wait)) || | |
7026 | (offchanok && ((drv->capa.flags & WPA_DRIVER_FLAGS_OFFCHANNEL_TX) || | |
7027 | drv->test_use_roc_tx) && | |
7028 | nla_put_flag(msg, NL80211_ATTR_OFFCHANNEL_TX_OK)) || | |
7029 | (no_cck && nla_put_flag(msg, NL80211_ATTR_TX_NO_CCK_RATE)) || | |
7030 | (no_ack && nla_put_flag(msg, NL80211_ATTR_DONT_WAIT_FOR_ACK)) || | |
2d3943ce AO |
7031 | (csa_offs && nla_put(msg, NL80211_ATTR_CSA_C_OFFSETS_TX, |
7032 | csa_offs_len * sizeof(u16), csa_offs)) || | |
a862e4a3 JM |
7033 | nla_put(msg, NL80211_ATTR_FRAME, buf_len, buf)) |
7034 | goto fail; | |
9884f9cc JB |
7035 | |
7036 | cookie = 0; | |
7037 | ret = send_and_recv_msgs(drv, msg, cookie_handler, &cookie); | |
7038 | msg = NULL; | |
7039 | if (ret) { | |
7040 | wpa_printf(MSG_DEBUG, "nl80211: Frame command failed: ret=%d " | |
a05225c8 JM |
7041 | "(%s) (freq=%u wait=%u)", ret, strerror(-ret), |
7042 | freq, wait); | |
a862e4a3 JM |
7043 | } else { |
7044 | wpa_printf(MSG_MSGDUMP, "nl80211: Frame TX command accepted%s; " | |
7045 | "cookie 0x%llx", no_ack ? " (no ACK)" : "", | |
7046 | (long long unsigned int) cookie); | |
9884f9cc | 7047 | |
a862e4a3 JM |
7048 | if (cookie_out) |
7049 | *cookie_out = no_ack ? (u64) -1 : cookie; | |
759a8a3a JM |
7050 | |
7051 | if (drv->num_send_action_cookies == MAX_SEND_ACTION_COOKIES) { | |
7052 | wpa_printf(MSG_DEBUG, | |
7053 | "nl80211: Drop oldest pending send action cookie 0x%llx", | |
7054 | (long long unsigned int) | |
7055 | drv->send_action_cookies[0]); | |
7056 | os_memmove(&drv->send_action_cookies[0], | |
7057 | &drv->send_action_cookies[1], | |
7058 | (MAX_SEND_ACTION_COOKIES - 1) * | |
7059 | sizeof(u64)); | |
7060 | drv->num_send_action_cookies--; | |
7061 | } | |
7062 | drv->send_action_cookies[drv->num_send_action_cookies] = cookie; | |
7063 | drv->num_send_action_cookies++; | |
a862e4a3 | 7064 | } |
9884f9cc | 7065 | |
a862e4a3 | 7066 | fail: |
9884f9cc JB |
7067 | nlmsg_free(msg); |
7068 | return ret; | |
7069 | } | |
7070 | ||
7071 | ||
9ebce9c5 JM |
7072 | static int wpa_driver_nl80211_send_action(struct i802_bss *bss, |
7073 | unsigned int freq, | |
190b9062 | 7074 | unsigned int wait_time, |
58f6fbe0 JM |
7075 | const u8 *dst, const u8 *src, |
7076 | const u8 *bssid, | |
b106173a JM |
7077 | const u8 *data, size_t data_len, |
7078 | int no_cck) | |
58f6fbe0 | 7079 | { |
a2e40bb6 | 7080 | struct wpa_driver_nl80211_data *drv = bss->drv; |
58f6fbe0 | 7081 | int ret = -1; |
58f6fbe0 JM |
7082 | u8 *buf; |
7083 | struct ieee80211_hdr *hdr; | |
58f6fbe0 | 7084 | |
5dfca53f | 7085 | wpa_printf(MSG_DEBUG, "nl80211: Send Action frame (ifindex=%d, " |
55231068 JM |
7086 | "freq=%u MHz wait=%d ms no_cck=%d)", |
7087 | drv->ifindex, freq, wait_time, no_cck); | |
58f6fbe0 JM |
7088 | |
7089 | buf = os_zalloc(24 + data_len); | |
7090 | if (buf == NULL) | |
7091 | return ret; | |
7092 | os_memcpy(buf + 24, data, data_len); | |
7093 | hdr = (struct ieee80211_hdr *) buf; | |
7094 | hdr->frame_control = | |
7095 | IEEE80211_FC(WLAN_FC_TYPE_MGMT, WLAN_FC_STYPE_ACTION); | |
7096 | os_memcpy(hdr->addr1, dst, ETH_ALEN); | |
7097 | os_memcpy(hdr->addr2, src, ETH_ALEN); | |
7098 | os_memcpy(hdr->addr3, bssid, ETH_ALEN); | |
7099 | ||
8331c9b3 VK |
7100 | if (os_memcmp(bss->addr, src, ETH_ALEN) != 0) { |
7101 | wpa_printf(MSG_DEBUG, "nl80211: Use random TA " MACSTR, | |
7102 | MAC2STR(src)); | |
7103 | os_memcpy(bss->rand_addr, src, ETH_ALEN); | |
7104 | } else { | |
7105 | os_memset(bss->rand_addr, 0, ETH_ALEN); | |
7106 | } | |
7107 | ||
f78f2785 JM |
7108 | if (is_ap_interface(drv->nlmode) && |
7109 | (!(drv->capa.flags & WPA_DRIVER_FLAGS_OFFCHANNEL_TX) || | |
7110 | (int) freq == bss->freq || drv->device_ap_sme || | |
7111 | !drv->use_monitor)) | |
9ebce9c5 JM |
7112 | ret = wpa_driver_nl80211_send_mlme(bss, buf, 24 + data_len, |
7113 | 0, freq, no_cck, 1, | |
2d3943ce | 7114 | wait_time, NULL, 0); |
9884f9cc | 7115 | else |
88df0ef7 | 7116 | ret = nl80211_send_frame_cmd(bss, freq, wait_time, buf, |
5dfca53f | 7117 | 24 + data_len, |
b106173a | 7118 | &drv->send_action_cookie, |
2d3943ce | 7119 | no_cck, 0, 1, NULL, 0); |
58f6fbe0 | 7120 | |
f8bf1421 | 7121 | os_free(buf); |
58f6fbe0 JM |
7122 | return ret; |
7123 | } | |
7124 | ||
7125 | ||
759a8a3a | 7126 | static void nl80211_frame_wait_cancel(struct i802_bss *bss, u64 cookie) |
5dfca53f | 7127 | { |
5dfca53f JB |
7128 | struct wpa_driver_nl80211_data *drv = bss->drv; |
7129 | struct nl_msg *msg; | |
7130 | int ret; | |
7131 | ||
316a9e4d | 7132 | wpa_printf(MSG_DEBUG, "nl80211: Cancel TX frame wait: cookie=0x%llx", |
759a8a3a | 7133 | (long long unsigned int) cookie); |
56f77852 | 7134 | if (!(msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_FRAME_WAIT_CANCEL)) || |
759a8a3a | 7135 | nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie)) { |
a862e4a3 JM |
7136 | nlmsg_free(msg); |
7137 | return; | |
7138 | } | |
5dfca53f JB |
7139 | |
7140 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); | |
5dfca53f JB |
7141 | if (ret) |
7142 | wpa_printf(MSG_DEBUG, "nl80211: wait cancel failed: ret=%d " | |
7143 | "(%s)", ret, strerror(-ret)); | |
5dfca53f JB |
7144 | } |
7145 | ||
7146 | ||
759a8a3a JM |
7147 | static void wpa_driver_nl80211_send_action_cancel_wait(void *priv) |
7148 | { | |
7149 | struct i802_bss *bss = priv; | |
7150 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
7151 | unsigned int i; | |
7152 | u64 cookie; | |
7153 | ||
7154 | /* Cancel the last pending TX cookie */ | |
7155 | nl80211_frame_wait_cancel(bss, drv->send_action_cookie); | |
7156 | ||
7157 | /* | |
7158 | * Cancel the other pending TX cookies, if any. This is needed since | |
7159 | * the driver may keep a list of all pending offchannel TX operations | |
7160 | * and free up the radio only once they have expired or cancelled. | |
7161 | */ | |
7162 | for (i = drv->num_send_action_cookies; i > 0; i--) { | |
7163 | cookie = drv->send_action_cookies[i - 1]; | |
7164 | if (cookie != drv->send_action_cookie) | |
7165 | nl80211_frame_wait_cancel(bss, cookie); | |
7166 | } | |
7167 | drv->num_send_action_cookies = 0; | |
7168 | } | |
7169 | ||
7170 | ||
55777702 JM |
7171 | static int wpa_driver_nl80211_remain_on_channel(void *priv, unsigned int freq, |
7172 | unsigned int duration) | |
7173 | { | |
a2e40bb6 FF |
7174 | struct i802_bss *bss = priv; |
7175 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
55777702 JM |
7176 | struct nl_msg *msg; |
7177 | int ret; | |
7178 | u64 cookie; | |
7179 | ||
56f77852 | 7180 | if (!(msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_REMAIN_ON_CHANNEL)) || |
a862e4a3 JM |
7181 | nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq) || |
7182 | nla_put_u32(msg, NL80211_ATTR_DURATION, duration)) { | |
7183 | nlmsg_free(msg); | |
7184 | return -1; | |
7185 | } | |
55777702 JM |
7186 | |
7187 | cookie = 0; | |
7188 | ret = send_and_recv_msgs(drv, msg, cookie_handler, &cookie); | |
7189 | if (ret == 0) { | |
7190 | wpa_printf(MSG_DEBUG, "nl80211: Remain-on-channel cookie " | |
7191 | "0x%llx for freq=%u MHz duration=%u", | |
7192 | (long long unsigned int) cookie, freq, duration); | |
7193 | drv->remain_on_chan_cookie = cookie; | |
531f0331 | 7194 | drv->pending_remain_on_chan = 1; |
55777702 JM |
7195 | return 0; |
7196 | } | |
7197 | wpa_printf(MSG_DEBUG, "nl80211: Failed to request remain-on-channel " | |
15ed5535 JM |
7198 | "(freq=%d duration=%u): %d (%s)", |
7199 | freq, duration, ret, strerror(-ret)); | |
55777702 JM |
7200 | return -1; |
7201 | } | |
7202 | ||
7203 | ||
7204 | static int wpa_driver_nl80211_cancel_remain_on_channel(void *priv) | |
7205 | { | |
a2e40bb6 FF |
7206 | struct i802_bss *bss = priv; |
7207 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
55777702 JM |
7208 | struct nl_msg *msg; |
7209 | int ret; | |
7210 | ||
7211 | if (!drv->pending_remain_on_chan) { | |
7212 | wpa_printf(MSG_DEBUG, "nl80211: No pending remain-on-channel " | |
7213 | "to cancel"); | |
7214 | return -1; | |
7215 | } | |
7216 | ||
7217 | wpa_printf(MSG_DEBUG, "nl80211: Cancel remain-on-channel with cookie " | |
7218 | "0x%llx", | |
7219 | (long long unsigned int) drv->remain_on_chan_cookie); | |
7220 | ||
56f77852 JM |
7221 | msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL); |
7222 | if (!msg || | |
a862e4a3 JM |
7223 | nla_put_u64(msg, NL80211_ATTR_COOKIE, drv->remain_on_chan_cookie)) { |
7224 | nlmsg_free(msg); | |
7225 | return -1; | |
7226 | } | |
55777702 JM |
7227 | |
7228 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); | |
7229 | if (ret == 0) | |
7230 | return 0; | |
7231 | wpa_printf(MSG_DEBUG, "nl80211: Failed to cancel remain-on-channel: " | |
7232 | "%d (%s)", ret, strerror(-ret)); | |
55777702 JM |
7233 | return -1; |
7234 | } | |
7235 | ||
7236 | ||
9ebce9c5 | 7237 | static int wpa_driver_nl80211_probe_req_report(struct i802_bss *bss, int report) |
504e905c | 7238 | { |
a2e40bb6 | 7239 | struct wpa_driver_nl80211_data *drv = bss->drv; |
504e905c | 7240 | |
5582a5d1 | 7241 | if (!report) { |
0d891981 | 7242 | if (bss->nl_preq && drv->device_ap_sme && |
b8d87ed2 AP |
7243 | is_ap_interface(drv->nlmode) && !bss->in_deinit && |
7244 | !bss->static_ap) { | |
0d891981 JM |
7245 | /* |
7246 | * Do not disable Probe Request reporting that was | |
7247 | * enabled in nl80211_setup_ap(). | |
7248 | */ | |
7249 | wpa_printf(MSG_DEBUG, "nl80211: Skip disabling of " | |
7250 | "Probe Request reporting nl_preq=%p while " | |
7251 | "in AP mode", bss->nl_preq); | |
7252 | } else if (bss->nl_preq) { | |
36488c05 JM |
7253 | wpa_printf(MSG_DEBUG, "nl80211: Disable Probe Request " |
7254 | "reporting nl_preq=%p", bss->nl_preq); | |
40a68f33 | 7255 | nl80211_destroy_eloop_handle(&bss->nl_preq, 0); |
5582a5d1 JB |
7256 | } |
7257 | return 0; | |
7258 | } | |
7259 | ||
481234cf | 7260 | if (bss->nl_preq) { |
5582a5d1 | 7261 | wpa_printf(MSG_DEBUG, "nl80211: Probe Request reporting " |
36488c05 | 7262 | "already on! nl_preq=%p", bss->nl_preq); |
5582a5d1 JB |
7263 | return 0; |
7264 | } | |
7265 | ||
481234cf JM |
7266 | bss->nl_preq = nl_create_handle(drv->global->nl_cb, "preq"); |
7267 | if (bss->nl_preq == NULL) | |
5582a5d1 | 7268 | return -1; |
36488c05 JM |
7269 | wpa_printf(MSG_DEBUG, "nl80211: Enable Probe Request " |
7270 | "reporting nl_preq=%p", bss->nl_preq); | |
5582a5d1 | 7271 | |
481234cf | 7272 | if (nl80211_register_frame(bss, bss->nl_preq, |
5582a5d1 JB |
7273 | (WLAN_FC_TYPE_MGMT << 2) | |
7274 | (WLAN_FC_STYPE_PROBE_REQ << 4), | |
a92dfde8 JB |
7275 | NULL, 0) < 0) |
7276 | goto out_err; | |
5582a5d1 | 7277 | |
5f65e9f7 JB |
7278 | nl80211_register_eloop_read(&bss->nl_preq, |
7279 | wpa_driver_nl80211_event_receive, | |
40a68f33 | 7280 | bss->nl_cb, 0); |
5582a5d1 | 7281 | |
504e905c | 7282 | return 0; |
5582a5d1 | 7283 | |
a92dfde8 | 7284 | out_err: |
221a59c9 | 7285 | nl_destroy_handles(&bss->nl_preq); |
5582a5d1 | 7286 | return -1; |
504e905c JM |
7287 | } |
7288 | ||
7289 | ||
4e5cb1a3 JM |
7290 | static int nl80211_disable_11b_rates(struct wpa_driver_nl80211_data *drv, |
7291 | int ifindex, int disabled) | |
7292 | { | |
7293 | struct nl_msg *msg; | |
7294 | struct nlattr *bands, *band; | |
7295 | int ret; | |
7296 | ||
3e208481 JM |
7297 | wpa_printf(MSG_DEBUG, |
7298 | "nl80211: NL80211_CMD_SET_TX_BITRATE_MASK (ifindex=%d %s)", | |
7299 | ifindex, disabled ? "NL80211_TXRATE_LEGACY=OFDM-only" : | |
7300 | "no NL80211_TXRATE_LEGACY constraint"); | |
7301 | ||
95376e1a JM |
7302 | msg = nl80211_ifindex_msg(drv, ifindex, 0, |
7303 | NL80211_CMD_SET_TX_BITRATE_MASK); | |
4e5cb1a3 JM |
7304 | if (!msg) |
7305 | return -1; | |
7306 | ||
4e5cb1a3 JM |
7307 | bands = nla_nest_start(msg, NL80211_ATTR_TX_RATES); |
7308 | if (!bands) | |
a862e4a3 | 7309 | goto fail; |
4e5cb1a3 JM |
7310 | |
7311 | /* | |
7312 | * Disable 2 GHz rates 1, 2, 5.5, 11 Mbps by masking out everything | |
7313 | * else apart from 6, 9, 12, 18, 24, 36, 48, 54 Mbps from non-MCS | |
7314 | * rates. All 5 GHz rates are left enabled. | |
7315 | */ | |
7316 | band = nla_nest_start(msg, NL80211_BAND_2GHZ); | |
a862e4a3 JM |
7317 | if (!band || |
7318 | (disabled && nla_put(msg, NL80211_TXRATE_LEGACY, 8, | |
7319 | "\x0c\x12\x18\x24\x30\x48\x60\x6c"))) | |
7320 | goto fail; | |
4e5cb1a3 JM |
7321 | nla_nest_end(msg, band); |
7322 | ||
7323 | nla_nest_end(msg, bands); | |
7324 | ||
7325 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); | |
4e5cb1a3 JM |
7326 | if (ret) { |
7327 | wpa_printf(MSG_DEBUG, "nl80211: Set TX rates failed: ret=%d " | |
7328 | "(%s)", ret, strerror(-ret)); | |
1d0c6fb1 JM |
7329 | } else |
7330 | drv->disabled_11b_rates = disabled; | |
4e5cb1a3 JM |
7331 | |
7332 | return ret; | |
7333 | ||
a862e4a3 | 7334 | fail: |
4e5cb1a3 JM |
7335 | nlmsg_free(msg); |
7336 | return -1; | |
7337 | } | |
7338 | ||
7339 | ||
af473088 JM |
7340 | static int wpa_driver_nl80211_deinit_ap(void *priv) |
7341 | { | |
a2e40bb6 FF |
7342 | struct i802_bss *bss = priv; |
7343 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
b1f625e0 | 7344 | if (!is_ap_interface(drv->nlmode)) |
af473088 | 7345 | return -1; |
a70cd0db | 7346 | wpa_driver_nl80211_del_beacon(bss); |
9bc5cfa3 | 7347 | bss->beacon_set = 0; |
60b13c20 IP |
7348 | |
7349 | /* | |
7350 | * If the P2P GO interface was dynamically added, then it is | |
7351 | * possible that the interface change to station is not possible. | |
7352 | */ | |
7353 | if (drv->nlmode == NL80211_IFTYPE_P2P_GO && bss->if_dynamic) | |
7354 | return 0; | |
7355 | ||
b1f625e0 | 7356 | return wpa_driver_nl80211_set_mode(priv, NL80211_IFTYPE_STATION); |
af473088 JM |
7357 | } |
7358 | ||
7359 | ||
695c7038 SW |
7360 | static int wpa_driver_nl80211_stop_ap(void *priv) |
7361 | { | |
7362 | struct i802_bss *bss = priv; | |
7363 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
7364 | if (!is_ap_interface(drv->nlmode)) | |
7365 | return -1; | |
a70cd0db | 7366 | wpa_driver_nl80211_del_beacon(bss); |
695c7038 SW |
7367 | bss->beacon_set = 0; |
7368 | return 0; | |
7369 | } | |
7370 | ||
7371 | ||
3c29244e EP |
7372 | static int wpa_driver_nl80211_deinit_p2p_cli(void *priv) |
7373 | { | |
7374 | struct i802_bss *bss = priv; | |
7375 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
7376 | if (drv->nlmode != NL80211_IFTYPE_P2P_CLIENT) | |
7377 | return -1; | |
60b13c20 IP |
7378 | |
7379 | /* | |
7380 | * If the P2P Client interface was dynamically added, then it is | |
7381 | * possible that the interface change to station is not possible. | |
7382 | */ | |
7383 | if (bss->if_dynamic) | |
7384 | return 0; | |
7385 | ||
3c29244e EP |
7386 | return wpa_driver_nl80211_set_mode(priv, NL80211_IFTYPE_STATION); |
7387 | } | |
7388 | ||
7389 | ||
207ef3fb JM |
7390 | static void wpa_driver_nl80211_resume(void *priv) |
7391 | { | |
a2e40bb6 | 7392 | struct i802_bss *bss = priv; |
e8dc205f | 7393 | enum nl80211_iftype nlmode = nl80211_get_ifmode(bss); |
91724d6f AS |
7394 | |
7395 | if (i802_set_iface_flags(bss, 1)) | |
7396 | wpa_printf(MSG_DEBUG, "nl80211: Failed to set interface up on resume event"); | |
e8dc205f AO |
7397 | |
7398 | if (is_p2p_net_interface(nlmode)) | |
7399 | nl80211_disable_11b_rates(bss->drv, bss->drv->ifindex, 1); | |
207ef3fb JM |
7400 | } |
7401 | ||
7402 | ||
b625473c JM |
7403 | static int nl80211_signal_monitor(void *priv, int threshold, int hysteresis) |
7404 | { | |
7405 | struct i802_bss *bss = priv; | |
7406 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
8970bae8 JB |
7407 | struct nl_msg *msg; |
7408 | struct nlattr *cqm; | |
b625473c JM |
7409 | |
7410 | wpa_printf(MSG_DEBUG, "nl80211: Signal monitor threshold=%d " | |
7411 | "hysteresis=%d", threshold, hysteresis); | |
7412 | ||
13f83980 | 7413 | if (!(msg = nl80211_bss_msg(bss, 0, NL80211_CMD_SET_CQM)) || |
a862e4a3 JM |
7414 | !(cqm = nla_nest_start(msg, NL80211_ATTR_CQM)) || |
7415 | nla_put_u32(msg, NL80211_ATTR_CQM_RSSI_THOLD, threshold) || | |
7416 | nla_put_u32(msg, NL80211_ATTR_CQM_RSSI_HYST, hysteresis)) { | |
7417 | nlmsg_free(msg); | |
7418 | return -1; | |
7419 | } | |
8970bae8 | 7420 | nla_nest_end(msg, cqm); |
21270bb4 | 7421 | |
a862e4a3 | 7422 | return send_and_recv_msgs(drv, msg, NULL, NULL); |
b625473c JM |
7423 | } |
7424 | ||
7425 | ||
2cc8d8f4 AO |
7426 | static int get_channel_width(struct nl_msg *msg, void *arg) |
7427 | { | |
7428 | struct nlattr *tb[NL80211_ATTR_MAX + 1]; | |
7429 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); | |
7430 | struct wpa_signal_info *sig_change = arg; | |
7431 | ||
7432 | nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), | |
7433 | genlmsg_attrlen(gnlh, 0), NULL); | |
7434 | ||
7435 | sig_change->center_frq1 = -1; | |
7436 | sig_change->center_frq2 = -1; | |
7437 | sig_change->chanwidth = CHAN_WIDTH_UNKNOWN; | |
7438 | ||
7439 | if (tb[NL80211_ATTR_CHANNEL_WIDTH]) { | |
7440 | sig_change->chanwidth = convert2width( | |
7441 | nla_get_u32(tb[NL80211_ATTR_CHANNEL_WIDTH])); | |
7442 | if (tb[NL80211_ATTR_CENTER_FREQ1]) | |
7443 | sig_change->center_frq1 = | |
7444 | nla_get_u32(tb[NL80211_ATTR_CENTER_FREQ1]); | |
7445 | if (tb[NL80211_ATTR_CENTER_FREQ2]) | |
7446 | sig_change->center_frq2 = | |
7447 | nla_get_u32(tb[NL80211_ATTR_CENTER_FREQ2]); | |
7448 | } | |
7449 | ||
7450 | return NL_SKIP; | |
7451 | } | |
7452 | ||
7453 | ||
7454 | static int nl80211_get_channel_width(struct wpa_driver_nl80211_data *drv, | |
7455 | struct wpa_signal_info *sig) | |
7456 | { | |
7457 | struct nl_msg *msg; | |
7458 | ||
9725b784 | 7459 | msg = nl80211_drv_msg(drv, 0, NL80211_CMD_GET_INTERFACE); |
2cc8d8f4 | 7460 | return send_and_recv_msgs(drv, msg, get_channel_width, sig); |
2cc8d8f4 AO |
7461 | } |
7462 | ||
7463 | ||
1c5c7273 PS |
7464 | static int nl80211_signal_poll(void *priv, struct wpa_signal_info *si) |
7465 | { | |
7466 | struct i802_bss *bss = priv; | |
7467 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
7468 | int res; | |
7469 | ||
7470 | os_memset(si, 0, sizeof(*si)); | |
7471 | res = nl80211_get_link_signal(drv, si); | |
1d6955e6 JM |
7472 | if (res) { |
7473 | if (drv->nlmode != NL80211_IFTYPE_ADHOC && | |
7474 | drv->nlmode != NL80211_IFTYPE_MESH_POINT) | |
7475 | return res; | |
7476 | si->current_signal = 0; | |
7477 | } | |
1c5c7273 | 7478 | |
2cc8d8f4 AO |
7479 | res = nl80211_get_channel_width(drv, si); |
7480 | if (res != 0) | |
7481 | return res; | |
7482 | ||
1c5c7273 PS |
7483 | return nl80211_get_link_noise(drv, si); |
7484 | } | |
7485 | ||
7486 | ||
b91ab76e JM |
7487 | static int nl80211_send_frame(void *priv, const u8 *data, size_t data_len, |
7488 | int encrypt) | |
7489 | { | |
7490 | struct i802_bss *bss = priv; | |
55231068 | 7491 | return wpa_driver_nl80211_send_frame(bss, data, data_len, encrypt, 0, |
2d3943ce | 7492 | 0, 0, 0, 0, NULL, 0); |
b91ab76e JM |
7493 | } |
7494 | ||
7495 | ||
c55f774d JM |
7496 | static int nl80211_set_param(void *priv, const char *param) |
7497 | { | |
ef24ad3e JM |
7498 | struct i802_bss *bss = priv; |
7499 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
7500 | ||
c55f774d JM |
7501 | if (param == NULL) |
7502 | return 0; | |
99a94f55 | 7503 | wpa_printf(MSG_DEBUG, "nl80211: driver param='%s'", param); |
c55f774d JM |
7504 | |
7505 | #ifdef CONFIG_P2P | |
7506 | if (os_strstr(param, "use_p2p_group_interface=1")) { | |
7507 | wpa_printf(MSG_DEBUG, "nl80211: Use separate P2P group " | |
7508 | "interface"); | |
7509 | drv->capa.flags |= WPA_DRIVER_FLAGS_P2P_CONCURRENT; | |
7510 | drv->capa.flags |= WPA_DRIVER_FLAGS_P2P_MGMT_AND_NON_P2P; | |
7511 | } | |
7512 | #endif /* CONFIG_P2P */ | |
7513 | ||
ef24ad3e | 7514 | if (os_strstr(param, "use_monitor=1")) |
327b01d3 | 7515 | drv->use_monitor = 1; |
327b01d3 JM |
7516 | |
7517 | if (os_strstr(param, "force_connect_cmd=1")) { | |
327b01d3 | 7518 | drv->capa.flags &= ~WPA_DRIVER_FLAGS_SME; |
b497a212 | 7519 | drv->force_connect_cmd = 1; |
327b01d3 JM |
7520 | } |
7521 | ||
ef24ad3e | 7522 | if (os_strstr(param, "force_bss_selection=1")) |
4d584d8c | 7523 | drv->capa.flags |= WPA_DRIVER_FLAGS_BSS_SELECTION; |
4d584d8c | 7524 | |
64abb725 | 7525 | if (os_strstr(param, "no_offchannel_tx=1")) { |
64abb725 JM |
7526 | drv->capa.flags &= ~WPA_DRIVER_FLAGS_OFFCHANNEL_TX; |
7527 | drv->test_use_roc_tx = 1; | |
7528 | } | |
7529 | ||
c55f774d JM |
7530 | return 0; |
7531 | } | |
7532 | ||
7533 | ||
45e3fc72 | 7534 | static void * nl80211_global_init(void *ctx) |
f2ed8023 JM |
7535 | { |
7536 | struct nl80211_global *global; | |
36d84860 BG |
7537 | struct netlink_config *cfg; |
7538 | ||
f2ed8023 JM |
7539 | global = os_zalloc(sizeof(*global)); |
7540 | if (global == NULL) | |
7541 | return NULL; | |
45e3fc72 | 7542 | global->ctx = ctx; |
c81eff1a | 7543 | global->ioctl_sock = -1; |
f2ed8023 | 7544 | dl_list_init(&global->interfaces); |
ff6a158b | 7545 | global->if_add_ifindex = -1; |
36d84860 BG |
7546 | |
7547 | cfg = os_zalloc(sizeof(*cfg)); | |
7548 | if (cfg == NULL) | |
7549 | goto err; | |
7550 | ||
7551 | cfg->ctx = global; | |
7552 | cfg->newlink_cb = wpa_driver_nl80211_event_rtm_newlink; | |
7553 | cfg->dellink_cb = wpa_driver_nl80211_event_rtm_dellink; | |
7554 | global->netlink = netlink_init(cfg); | |
7555 | if (global->netlink == NULL) { | |
7556 | os_free(cfg); | |
7557 | goto err; | |
7558 | } | |
7559 | ||
2a7b66f5 BG |
7560 | if (wpa_driver_nl80211_init_nl_global(global) < 0) |
7561 | goto err; | |
7562 | ||
c81eff1a BG |
7563 | global->ioctl_sock = socket(PF_INET, SOCK_DGRAM, 0); |
7564 | if (global->ioctl_sock < 0) { | |
7ac3616d JM |
7565 | wpa_printf(MSG_ERROR, "nl80211: socket(PF_INET,SOCK_DGRAM) failed: %s", |
7566 | strerror(errno)); | |
c81eff1a BG |
7567 | goto err; |
7568 | } | |
7569 | ||
f2ed8023 | 7570 | return global; |
36d84860 BG |
7571 | |
7572 | err: | |
7573 | nl80211_global_deinit(global); | |
7574 | return NULL; | |
f2ed8023 JM |
7575 | } |
7576 | ||
7577 | ||
7578 | static void nl80211_global_deinit(void *priv) | |
7579 | { | |
7580 | struct nl80211_global *global = priv; | |
7581 | if (global == NULL) | |
7582 | return; | |
7583 | if (!dl_list_empty(&global->interfaces)) { | |
7584 | wpa_printf(MSG_ERROR, "nl80211: %u interface(s) remain at " | |
7585 | "nl80211_global_deinit", | |
7586 | dl_list_len(&global->interfaces)); | |
7587 | } | |
36d84860 BG |
7588 | |
7589 | if (global->netlink) | |
7590 | netlink_deinit(global->netlink); | |
7591 | ||
276e2d67 BG |
7592 | nl_destroy_handles(&global->nl); |
7593 | ||
5f65e9f7 | 7594 | if (global->nl_event) |
40a68f33 | 7595 | nl80211_destroy_eloop_handle(&global->nl_event, 0); |
d6c9aab8 JB |
7596 | |
7597 | nl_cb_put(global->nl_cb); | |
2a7b66f5 | 7598 | |
c81eff1a BG |
7599 | if (global->ioctl_sock >= 0) |
7600 | close(global->ioctl_sock); | |
7601 | ||
f2ed8023 JM |
7602 | os_free(global); |
7603 | } | |
7604 | ||
7605 | ||
6859f1cb BG |
7606 | static const char * nl80211_get_radio_name(void *priv) |
7607 | { | |
7608 | struct i802_bss *bss = priv; | |
7609 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
7610 | return drv->phyname; | |
7611 | } | |
7612 | ||
7613 | ||
061a3d3d VK |
7614 | static int nl80211_pmkid(struct i802_bss *bss, int cmd, |
7615 | struct wpa_pmkid_params *params) | |
a6efc65d JM |
7616 | { |
7617 | struct nl_msg *msg; | |
7618 | ||
13f83980 | 7619 | if (!(msg = nl80211_bss_msg(bss, 0, cmd)) || |
061a3d3d VK |
7620 | (params->pmkid && |
7621 | nla_put(msg, NL80211_ATTR_PMKID, 16, params->pmkid)) || | |
7622 | (params->bssid && | |
7623 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, params->bssid)) || | |
7624 | (params->ssid_len && | |
7625 | nla_put(msg, NL80211_ATTR_SSID, params->ssid_len, params->ssid)) || | |
7626 | (params->fils_cache_id && | |
7627 | nla_put(msg, NL80211_ATTR_FILS_CACHE_ID, 2, | |
7628 | params->fils_cache_id)) || | |
7629 | (params->pmk_len && | |
7630 | nla_put(msg, NL80211_ATTR_PMK, params->pmk_len, params->pmk))) { | |
a862e4a3 JM |
7631 | nlmsg_free(msg); |
7632 | return -ENOBUFS; | |
7633 | } | |
a6efc65d JM |
7634 | |
7635 | return send_and_recv_msgs(bss->drv, msg, NULL, NULL); | |
a6efc65d JM |
7636 | } |
7637 | ||
7638 | ||
6fbb5414 | 7639 | static int nl80211_add_pmkid(void *priv, struct wpa_pmkid_params *params) |
a6efc65d JM |
7640 | { |
7641 | struct i802_bss *bss = priv; | |
061a3d3d VK |
7642 | |
7643 | if (params->bssid) | |
7644 | wpa_printf(MSG_DEBUG, "nl80211: Add PMKID for " MACSTR, | |
7645 | MAC2STR(params->bssid)); | |
7646 | else if (params->fils_cache_id && params->ssid_len) { | |
7647 | wpa_printf(MSG_DEBUG, | |
7648 | "nl80211: Add PMKSA for cache id %02x%02x SSID %s", | |
7649 | params->fils_cache_id[0], params->fils_cache_id[1], | |
7650 | wpa_ssid_txt(params->ssid, params->ssid_len)); | |
7651 | } | |
7652 | ||
7653 | return nl80211_pmkid(bss, NL80211_CMD_SET_PMKSA, params); | |
a6efc65d JM |
7654 | } |
7655 | ||
7656 | ||
6fbb5414 | 7657 | static int nl80211_remove_pmkid(void *priv, struct wpa_pmkid_params *params) |
a6efc65d JM |
7658 | { |
7659 | struct i802_bss *bss = priv; | |
061a3d3d VK |
7660 | |
7661 | if (params->bssid) | |
7662 | wpa_printf(MSG_DEBUG, "nl80211: Delete PMKID for " MACSTR, | |
7663 | MAC2STR(params->bssid)); | |
7664 | else if (params->fils_cache_id && params->ssid_len) { | |
7665 | wpa_printf(MSG_DEBUG, | |
7666 | "nl80211: Delete PMKSA for cache id %02x%02x SSID %s", | |
7667 | params->fils_cache_id[0], params->fils_cache_id[1], | |
7668 | wpa_ssid_txt(params->ssid, params->ssid_len)); | |
7669 | } | |
7670 | ||
7671 | return nl80211_pmkid(bss, NL80211_CMD_DEL_PMKSA, params); | |
a6efc65d JM |
7672 | } |
7673 | ||
7674 | ||
7675 | static int nl80211_flush_pmkid(void *priv) | |
7676 | { | |
7677 | struct i802_bss *bss = priv; | |
061a3d3d VK |
7678 | struct nl_msg *msg; |
7679 | ||
a6efc65d | 7680 | wpa_printf(MSG_DEBUG, "nl80211: Flush PMKIDs"); |
061a3d3d VK |
7681 | msg = nl80211_bss_msg(bss, 0, NL80211_CMD_FLUSH_PMKSA); |
7682 | if (!msg) | |
7683 | return -ENOBUFS; | |
7684 | return send_and_recv_msgs(bss->drv, msg, NULL, NULL); | |
a6efc65d JM |
7685 | } |
7686 | ||
7687 | ||
0185007c MK |
7688 | static void clean_survey_results(struct survey_results *survey_results) |
7689 | { | |
7690 | struct freq_survey *survey, *tmp; | |
7691 | ||
7692 | if (dl_list_empty(&survey_results->survey_list)) | |
7693 | return; | |
7694 | ||
7695 | dl_list_for_each_safe(survey, tmp, &survey_results->survey_list, | |
7696 | struct freq_survey, list) { | |
7697 | dl_list_del(&survey->list); | |
7698 | os_free(survey); | |
7699 | } | |
7700 | } | |
7701 | ||
7702 | ||
7703 | static void add_survey(struct nlattr **sinfo, u32 ifidx, | |
7704 | struct dl_list *survey_list) | |
7705 | { | |
7706 | struct freq_survey *survey; | |
7707 | ||
7708 | survey = os_zalloc(sizeof(struct freq_survey)); | |
7709 | if (!survey) | |
7710 | return; | |
7711 | ||
7712 | survey->ifidx = ifidx; | |
7713 | survey->freq = nla_get_u32(sinfo[NL80211_SURVEY_INFO_FREQUENCY]); | |
7714 | survey->filled = 0; | |
7715 | ||
7716 | if (sinfo[NL80211_SURVEY_INFO_NOISE]) { | |
7717 | survey->nf = (int8_t) | |
7718 | nla_get_u8(sinfo[NL80211_SURVEY_INFO_NOISE]); | |
7719 | survey->filled |= SURVEY_HAS_NF; | |
7720 | } | |
7721 | ||
7722 | if (sinfo[NL80211_SURVEY_INFO_CHANNEL_TIME]) { | |
7723 | survey->channel_time = | |
7724 | nla_get_u64(sinfo[NL80211_SURVEY_INFO_CHANNEL_TIME]); | |
7725 | survey->filled |= SURVEY_HAS_CHAN_TIME; | |
7726 | } | |
7727 | ||
7728 | if (sinfo[NL80211_SURVEY_INFO_CHANNEL_TIME_BUSY]) { | |
7729 | survey->channel_time_busy = | |
7730 | nla_get_u64(sinfo[NL80211_SURVEY_INFO_CHANNEL_TIME_BUSY]); | |
7731 | survey->filled |= SURVEY_HAS_CHAN_TIME_BUSY; | |
7732 | } | |
7733 | ||
7734 | if (sinfo[NL80211_SURVEY_INFO_CHANNEL_TIME_RX]) { | |
7735 | survey->channel_time_rx = | |
7736 | nla_get_u64(sinfo[NL80211_SURVEY_INFO_CHANNEL_TIME_RX]); | |
7737 | survey->filled |= SURVEY_HAS_CHAN_TIME_RX; | |
7738 | } | |
7739 | ||
7740 | if (sinfo[NL80211_SURVEY_INFO_CHANNEL_TIME_TX]) { | |
7741 | survey->channel_time_tx = | |
7742 | nla_get_u64(sinfo[NL80211_SURVEY_INFO_CHANNEL_TIME_TX]); | |
7743 | survey->filled |= SURVEY_HAS_CHAN_TIME_TX; | |
7744 | } | |
7745 | ||
7746 | 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)", | |
7747 | survey->freq, | |
7748 | survey->nf, | |
7749 | (unsigned long int) survey->channel_time, | |
7750 | (unsigned long int) survey->channel_time_busy, | |
7751 | (unsigned long int) survey->channel_time_tx, | |
7752 | (unsigned long int) survey->channel_time_rx, | |
7753 | survey->filled); | |
7754 | ||
7755 | dl_list_add_tail(survey_list, &survey->list); | |
7756 | } | |
7757 | ||
7758 | ||
7759 | static int check_survey_ok(struct nlattr **sinfo, u32 surveyed_freq, | |
7760 | unsigned int freq_filter) | |
7761 | { | |
7762 | if (!freq_filter) | |
7763 | return 1; | |
7764 | ||
7765 | return freq_filter == surveyed_freq; | |
7766 | } | |
7767 | ||
7768 | ||
7769 | static int survey_handler(struct nl_msg *msg, void *arg) | |
7770 | { | |
7771 | struct nlattr *tb[NL80211_ATTR_MAX + 1]; | |
7772 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); | |
7773 | struct nlattr *sinfo[NL80211_SURVEY_INFO_MAX + 1]; | |
7774 | struct survey_results *survey_results; | |
7775 | u32 surveyed_freq = 0; | |
7776 | u32 ifidx; | |
7777 | ||
7778 | static struct nla_policy survey_policy[NL80211_SURVEY_INFO_MAX + 1] = { | |
7779 | [NL80211_SURVEY_INFO_FREQUENCY] = { .type = NLA_U32 }, | |
7780 | [NL80211_SURVEY_INFO_NOISE] = { .type = NLA_U8 }, | |
7781 | }; | |
7782 | ||
7783 | survey_results = (struct survey_results *) arg; | |
7784 | ||
7785 | nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), | |
7786 | genlmsg_attrlen(gnlh, 0), NULL); | |
7787 | ||
e28f39b7 SJ |
7788 | if (!tb[NL80211_ATTR_IFINDEX]) |
7789 | return NL_SKIP; | |
7790 | ||
0185007c MK |
7791 | ifidx = nla_get_u32(tb[NL80211_ATTR_IFINDEX]); |
7792 | ||
7793 | if (!tb[NL80211_ATTR_SURVEY_INFO]) | |
7794 | return NL_SKIP; | |
7795 | ||
7796 | if (nla_parse_nested(sinfo, NL80211_SURVEY_INFO_MAX, | |
7797 | tb[NL80211_ATTR_SURVEY_INFO], | |
7798 | survey_policy)) | |
7799 | return NL_SKIP; | |
7800 | ||
7801 | if (!sinfo[NL80211_SURVEY_INFO_FREQUENCY]) { | |
7802 | wpa_printf(MSG_ERROR, "nl80211: Invalid survey data"); | |
7803 | return NL_SKIP; | |
7804 | } | |
7805 | ||
7806 | surveyed_freq = nla_get_u32(sinfo[NL80211_SURVEY_INFO_FREQUENCY]); | |
7807 | ||
7808 | if (!check_survey_ok(sinfo, surveyed_freq, | |
7809 | survey_results->freq_filter)) | |
7810 | return NL_SKIP; | |
7811 | ||
7812 | if (survey_results->freq_filter && | |
7813 | survey_results->freq_filter != surveyed_freq) { | |
7814 | wpa_printf(MSG_EXCESSIVE, "nl80211: Ignoring survey data for freq %d MHz", | |
7815 | surveyed_freq); | |
7816 | return NL_SKIP; | |
7817 | } | |
7818 | ||
7819 | add_survey(sinfo, ifidx, &survey_results->survey_list); | |
7820 | ||
7821 | return NL_SKIP; | |
7822 | } | |
7823 | ||
7824 | ||
7825 | static int wpa_driver_nl80211_get_survey(void *priv, unsigned int freq) | |
7826 | { | |
7827 | struct i802_bss *bss = priv; | |
7828 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
7829 | struct nl_msg *msg; | |
9725b784 | 7830 | int err; |
0185007c MK |
7831 | union wpa_event_data data; |
7832 | struct survey_results *survey_results; | |
7833 | ||
7834 | os_memset(&data, 0, sizeof(data)); | |
7835 | survey_results = &data.survey_results; | |
7836 | ||
7837 | dl_list_init(&survey_results->survey_list); | |
7838 | ||
9725b784 | 7839 | msg = nl80211_drv_msg(drv, NLM_F_DUMP, NL80211_CMD_GET_SURVEY); |
0185007c | 7840 | if (!msg) |
a862e4a3 | 7841 | return -ENOBUFS; |
0185007c | 7842 | |
0185007c MK |
7843 | if (freq) |
7844 | data.survey_results.freq_filter = freq; | |
7845 | ||
7846 | do { | |
7847 | wpa_printf(MSG_DEBUG, "nl80211: Fetch survey data"); | |
7848 | err = send_and_recv_msgs(drv, msg, survey_handler, | |
7849 | survey_results); | |
7850 | } while (err > 0); | |
7851 | ||
a862e4a3 | 7852 | if (err) |
0185007c | 7853 | wpa_printf(MSG_ERROR, "nl80211: Failed to process survey data"); |
a862e4a3 JM |
7854 | else |
7855 | wpa_supplicant_event(drv->ctx, EVENT_SURVEY, &data); | |
0185007c | 7856 | |
0185007c | 7857 | clean_survey_results(survey_results); |
0185007c MK |
7858 | return err; |
7859 | } | |
7860 | ||
7861 | ||
98cd3d1c JM |
7862 | static void nl80211_set_rekey_info(void *priv, const u8 *kek, size_t kek_len, |
7863 | const u8 *kck, size_t kck_len, | |
b14a210c JB |
7864 | const u8 *replay_ctr) |
7865 | { | |
7866 | struct i802_bss *bss = priv; | |
7867 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
7868 | struct nlattr *replay_nested; | |
7869 | struct nl_msg *msg; | |
64ae2447 | 7870 | int ret; |
b14a210c | 7871 | |
64ae2447 JM |
7872 | if (!drv->set_rekey_offload) |
7873 | return; | |
7874 | ||
7875 | wpa_printf(MSG_DEBUG, "nl80211: Set rekey offload"); | |
13f83980 | 7876 | if (!(msg = nl80211_bss_msg(bss, 0, NL80211_CMD_SET_REKEY_OFFLOAD)) || |
a862e4a3 | 7877 | !(replay_nested = nla_nest_start(msg, NL80211_ATTR_REKEY_DATA)) || |
98cd3d1c | 7878 | nla_put(msg, NL80211_REKEY_DATA_KEK, kek_len, kek) || |
b6ea7642 | 7879 | (kck_len && nla_put(msg, NL80211_REKEY_DATA_KCK, kck_len, kck)) || |
a862e4a3 JM |
7880 | nla_put(msg, NL80211_REKEY_DATA_REPLAY_CTR, NL80211_REPLAY_CTR_LEN, |
7881 | replay_ctr)) { | |
bbd89bfc | 7882 | nl80211_nlmsg_clear(msg); |
a862e4a3 JM |
7883 | nlmsg_free(msg); |
7884 | return; | |
7885 | } | |
b14a210c JB |
7886 | |
7887 | nla_nest_end(msg, replay_nested); | |
7888 | ||
64ae2447 JM |
7889 | ret = send_and_recv_msgs(drv, msg, NULL, (void *) -1); |
7890 | if (ret == -EOPNOTSUPP) { | |
7891 | wpa_printf(MSG_DEBUG, | |
7892 | "nl80211: Driver does not support rekey offload"); | |
7893 | drv->set_rekey_offload = 0; | |
7894 | } | |
b14a210c JB |
7895 | } |
7896 | ||
7897 | ||
39718852 JB |
7898 | static void nl80211_send_null_frame(struct i802_bss *bss, const u8 *own_addr, |
7899 | const u8 *addr, int qos) | |
bcf24348 | 7900 | { |
39718852 JB |
7901 | /* send data frame to poll STA and check whether |
7902 | * this frame is ACKed */ | |
bcf24348 JB |
7903 | struct { |
7904 | struct ieee80211_hdr hdr; | |
7905 | u16 qos_ctl; | |
7906 | } STRUCT_PACKED nulldata; | |
7907 | size_t size; | |
7908 | ||
7909 | /* Send data frame to poll STA and check whether this frame is ACKed */ | |
7910 | ||
7911 | os_memset(&nulldata, 0, sizeof(nulldata)); | |
7912 | ||
7913 | if (qos) { | |
7914 | nulldata.hdr.frame_control = | |
7915 | IEEE80211_FC(WLAN_FC_TYPE_DATA, | |
7916 | WLAN_FC_STYPE_QOS_NULL); | |
7917 | size = sizeof(nulldata); | |
7918 | } else { | |
7919 | nulldata.hdr.frame_control = | |
7920 | IEEE80211_FC(WLAN_FC_TYPE_DATA, | |
7921 | WLAN_FC_STYPE_NULLFUNC); | |
7922 | size = sizeof(struct ieee80211_hdr); | |
7923 | } | |
7924 | ||
7925 | nulldata.hdr.frame_control |= host_to_le16(WLAN_FC_FROMDS); | |
7926 | os_memcpy(nulldata.hdr.IEEE80211_DA_FROMDS, addr, ETH_ALEN); | |
7927 | os_memcpy(nulldata.hdr.IEEE80211_BSSID_FROMDS, own_addr, ETH_ALEN); | |
7928 | os_memcpy(nulldata.hdr.IEEE80211_SA_FROMDS, own_addr, ETH_ALEN); | |
7929 | ||
9ebce9c5 | 7930 | if (wpa_driver_nl80211_send_mlme(bss, (u8 *) &nulldata, size, 0, 0, 0, |
2d3943ce | 7931 | 0, 0, NULL, 0) < 0) |
bcf24348 JB |
7932 | wpa_printf(MSG_DEBUG, "nl80211_send_null_frame: Failed to " |
7933 | "send poll frame"); | |
7934 | } | |
7935 | ||
39718852 JB |
7936 | static void nl80211_poll_client(void *priv, const u8 *own_addr, const u8 *addr, |
7937 | int qos) | |
7938 | { | |
7939 | struct i802_bss *bss = priv; | |
7940 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
7941 | struct nl_msg *msg; | |
fc99fab7 | 7942 | int ret; |
39718852 JB |
7943 | |
7944 | if (!drv->poll_command_supported) { | |
7945 | nl80211_send_null_frame(bss, own_addr, addr, qos); | |
7946 | return; | |
7947 | } | |
7948 | ||
13f83980 | 7949 | if (!(msg = nl80211_bss_msg(bss, 0, NL80211_CMD_PROBE_CLIENT)) || |
a862e4a3 JM |
7950 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) { |
7951 | nlmsg_free(msg); | |
7952 | return; | |
7953 | } | |
39718852 | 7954 | |
fc99fab7 JM |
7955 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
7956 | if (ret < 0) { | |
7957 | wpa_printf(MSG_DEBUG, "nl80211: Client probe request for " | |
7958 | MACSTR " failed: ret=%d (%s)", | |
7959 | MAC2STR(addr), ret, strerror(-ret)); | |
7960 | } | |
39718852 JB |
7961 | } |
7962 | ||
bcf24348 | 7963 | |
29f338af JM |
7964 | static int nl80211_set_power_save(struct i802_bss *bss, int enabled) |
7965 | { | |
7966 | struct nl_msg *msg; | |
7967 | ||
13f83980 | 7968 | if (!(msg = nl80211_bss_msg(bss, 0, NL80211_CMD_SET_POWER_SAVE)) || |
a862e4a3 JM |
7969 | nla_put_u32(msg, NL80211_ATTR_PS_STATE, |
7970 | enabled ? NL80211_PS_ENABLED : NL80211_PS_DISABLED)) { | |
7971 | nlmsg_free(msg); | |
7972 | return -ENOBUFS; | |
7973 | } | |
29f338af | 7974 | return send_and_recv_msgs(bss->drv, msg, NULL, NULL); |
29f338af JM |
7975 | } |
7976 | ||
7977 | ||
7978 | static int nl80211_set_p2p_powersave(void *priv, int legacy_ps, int opp_ps, | |
7979 | int ctwindow) | |
7980 | { | |
7981 | struct i802_bss *bss = priv; | |
7982 | ||
7983 | wpa_printf(MSG_DEBUG, "nl80211: set_p2p_powersave (legacy_ps=%d " | |
7984 | "opp_ps=%d ctwindow=%d)", legacy_ps, opp_ps, ctwindow); | |
7985 | ||
0de38036 JM |
7986 | if (opp_ps != -1 || ctwindow != -1) { |
7987 | #ifdef ANDROID_P2P | |
7988 | wpa_driver_set_p2p_ps(priv, legacy_ps, opp_ps, ctwindow); | |
7989 | #else /* ANDROID_P2P */ | |
29f338af | 7990 | return -1; /* Not yet supported */ |
0de38036 JM |
7991 | #endif /* ANDROID_P2P */ |
7992 | } | |
29f338af JM |
7993 | |
7994 | if (legacy_ps == -1) | |
7995 | return 0; | |
7996 | if (legacy_ps != 0 && legacy_ps != 1) | |
7997 | return -1; /* Not yet supported */ | |
7998 | ||
7999 | return nl80211_set_power_save(bss, legacy_ps); | |
8000 | } | |
8001 | ||
8002 | ||
04e8003c JD |
8003 | static int nl80211_start_radar_detection(void *priv, |
8004 | struct hostapd_freq_params *freq) | |
f90e9c1c SW |
8005 | { |
8006 | struct i802_bss *bss = priv; | |
8007 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
8008 | struct nl_msg *msg; | |
8009 | int ret; | |
8010 | ||
04e8003c JD |
8011 | 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)", |
8012 | freq->freq, freq->ht_enabled, freq->vht_enabled, | |
8013 | freq->bandwidth, freq->center_freq1, freq->center_freq2); | |
8014 | ||
f90e9c1c SW |
8015 | if (!(drv->capa.flags & WPA_DRIVER_FLAGS_RADAR)) { |
8016 | wpa_printf(MSG_DEBUG, "nl80211: Driver does not support radar " | |
8017 | "detection"); | |
8018 | return -1; | |
8019 | } | |
8020 | ||
9725b784 | 8021 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_RADAR_DETECT)) || |
a862e4a3 JM |
8022 | nl80211_put_freq_params(msg, freq) < 0) { |
8023 | nlmsg_free(msg); | |
8024 | return -1; | |
8025 | } | |
f90e9c1c SW |
8026 | |
8027 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); | |
8028 | if (ret == 0) | |
8029 | return 0; | |
8030 | wpa_printf(MSG_DEBUG, "nl80211: Failed to start radar detection: " | |
8031 | "%d (%s)", ret, strerror(-ret)); | |
f90e9c1c SW |
8032 | return -1; |
8033 | } | |
8034 | ||
03ea1786 AN |
8035 | #ifdef CONFIG_TDLS |
8036 | ||
8037 | static int nl80211_send_tdls_mgmt(void *priv, const u8 *dst, u8 action_code, | |
8038 | u8 dialog_token, u16 status_code, | |
984dadc2 AN |
8039 | u32 peer_capab, int initiator, const u8 *buf, |
8040 | size_t len) | |
03ea1786 AN |
8041 | { |
8042 | struct i802_bss *bss = priv; | |
8043 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
8044 | struct nl_msg *msg; | |
8045 | ||
8046 | if (!(drv->capa.flags & WPA_DRIVER_FLAGS_TDLS_SUPPORT)) | |
8047 | return -EOPNOTSUPP; | |
8048 | ||
8049 | if (!dst) | |
8050 | return -EINVAL; | |
8051 | ||
9725b784 | 8052 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_TDLS_MGMT)) || |
a862e4a3 JM |
8053 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, dst) || |
8054 | nla_put_u8(msg, NL80211_ATTR_TDLS_ACTION, action_code) || | |
8055 | nla_put_u8(msg, NL80211_ATTR_TDLS_DIALOG_TOKEN, dialog_token) || | |
8056 | nla_put_u16(msg, NL80211_ATTR_STATUS_CODE, status_code)) | |
8057 | goto fail; | |
96ecea5e SD |
8058 | if (peer_capab) { |
8059 | /* | |
8060 | * The internal enum tdls_peer_capability definition is | |
8061 | * currently identical with the nl80211 enum | |
8062 | * nl80211_tdls_peer_capability, so no conversion is needed | |
8063 | * here. | |
8064 | */ | |
a862e4a3 JM |
8065 | if (nla_put_u32(msg, NL80211_ATTR_TDLS_PEER_CAPABILITY, |
8066 | peer_capab)) | |
8067 | goto fail; | |
96ecea5e | 8068 | } |
a862e4a3 JM |
8069 | if ((initiator && |
8070 | nla_put_flag(msg, NL80211_ATTR_TDLS_INITIATOR)) || | |
8071 | nla_put(msg, NL80211_ATTR_IE, len, buf)) | |
8072 | goto fail; | |
03ea1786 AN |
8073 | |
8074 | return send_and_recv_msgs(drv, msg, NULL, NULL); | |
8075 | ||
a862e4a3 | 8076 | fail: |
03ea1786 AN |
8077 | nlmsg_free(msg); |
8078 | return -ENOBUFS; | |
8079 | } | |
8080 | ||
8081 | ||
8082 | static int nl80211_tdls_oper(void *priv, enum tdls_oper oper, const u8 *peer) | |
8083 | { | |
8084 | struct i802_bss *bss = priv; | |
8085 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
8086 | struct nl_msg *msg; | |
8087 | enum nl80211_tdls_operation nl80211_oper; | |
b2442f25 | 8088 | int res; |
03ea1786 AN |
8089 | |
8090 | if (!(drv->capa.flags & WPA_DRIVER_FLAGS_TDLS_SUPPORT)) | |
8091 | return -EOPNOTSUPP; | |
8092 | ||
8093 | switch (oper) { | |
8094 | case TDLS_DISCOVERY_REQ: | |
8095 | nl80211_oper = NL80211_TDLS_DISCOVERY_REQ; | |
8096 | break; | |
8097 | case TDLS_SETUP: | |
8098 | nl80211_oper = NL80211_TDLS_SETUP; | |
8099 | break; | |
8100 | case TDLS_TEARDOWN: | |
8101 | nl80211_oper = NL80211_TDLS_TEARDOWN; | |
8102 | break; | |
8103 | case TDLS_ENABLE_LINK: | |
8104 | nl80211_oper = NL80211_TDLS_ENABLE_LINK; | |
8105 | break; | |
8106 | case TDLS_DISABLE_LINK: | |
8107 | nl80211_oper = NL80211_TDLS_DISABLE_LINK; | |
8108 | break; | |
8109 | case TDLS_ENABLE: | |
8110 | return 0; | |
8111 | case TDLS_DISABLE: | |
8112 | return 0; | |
8113 | default: | |
8114 | return -EINVAL; | |
8115 | } | |
8116 | ||
9725b784 | 8117 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_TDLS_OPER)) || |
a862e4a3 | 8118 | nla_put_u8(msg, NL80211_ATTR_TDLS_OPERATION, nl80211_oper) || |
a862e4a3 JM |
8119 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer)) { |
8120 | nlmsg_free(msg); | |
8121 | return -ENOBUFS; | |
8122 | } | |
03ea1786 | 8123 | |
b2442f25 JM |
8124 | res = send_and_recv_msgs(drv, msg, NULL, NULL); |
8125 | wpa_printf(MSG_DEBUG, "nl80211: TDLS_OPER: oper=%d mac=" MACSTR | |
8126 | " --> res=%d (%s)", nl80211_oper, MAC2STR(peer), res, | |
8127 | strerror(-res)); | |
8128 | return res; | |
03ea1786 AN |
8129 | } |
8130 | ||
72b2605f AN |
8131 | |
8132 | static int | |
8133 | nl80211_tdls_enable_channel_switch(void *priv, const u8 *addr, u8 oper_class, | |
8134 | const struct hostapd_freq_params *params) | |
8135 | { | |
8136 | struct i802_bss *bss = priv; | |
8137 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
8138 | struct nl_msg *msg; | |
8139 | int ret = -ENOBUFS; | |
8140 | ||
8141 | if (!(drv->capa.flags & WPA_DRIVER_FLAGS_TDLS_SUPPORT) || | |
8142 | !(drv->capa.flags & WPA_DRIVER_FLAGS_TDLS_CHANNEL_SWITCH)) | |
8143 | return -EOPNOTSUPP; | |
8144 | ||
8145 | wpa_printf(MSG_DEBUG, "nl80211: Enable TDLS channel switch " MACSTR | |
8146 | " oper_class=%u freq=%u", | |
8147 | MAC2STR(addr), oper_class, params->freq); | |
8148 | msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_TDLS_CHANNEL_SWITCH); | |
8149 | if (!msg || | |
8150 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) || | |
8151 | nla_put_u8(msg, NL80211_ATTR_OPER_CLASS, oper_class) || | |
8152 | (ret = nl80211_put_freq_params(msg, params))) { | |
8153 | nlmsg_free(msg); | |
8154 | wpa_printf(MSG_DEBUG, "nl80211: Could not build TDLS chan switch"); | |
8155 | return ret; | |
8156 | } | |
8157 | ||
8158 | return send_and_recv_msgs(drv, msg, NULL, NULL); | |
8159 | } | |
8160 | ||
8161 | ||
8162 | static int | |
8163 | nl80211_tdls_disable_channel_switch(void *priv, const u8 *addr) | |
8164 | { | |
8165 | struct i802_bss *bss = priv; | |
8166 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
8167 | struct nl_msg *msg; | |
8168 | ||
8169 | if (!(drv->capa.flags & WPA_DRIVER_FLAGS_TDLS_SUPPORT) || | |
8170 | !(drv->capa.flags & WPA_DRIVER_FLAGS_TDLS_CHANNEL_SWITCH)) | |
8171 | return -EOPNOTSUPP; | |
8172 | ||
8173 | wpa_printf(MSG_DEBUG, "nl80211: Disable TDLS channel switch " MACSTR, | |
8174 | MAC2STR(addr)); | |
8175 | msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_TDLS_CANCEL_CHANNEL_SWITCH); | |
8176 | if (!msg || | |
8177 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) { | |
8178 | nlmsg_free(msg); | |
8179 | wpa_printf(MSG_DEBUG, | |
8180 | "nl80211: Could not build TDLS cancel chan switch"); | |
8181 | return -ENOBUFS; | |
8182 | } | |
8183 | ||
8184 | return send_and_recv_msgs(drv, msg, NULL, NULL); | |
8185 | } | |
8186 | ||
03ea1786 AN |
8187 | #endif /* CONFIG TDLS */ |
8188 | ||
8189 | ||
9ebce9c5 JM |
8190 | static int driver_nl80211_set_key(const char *ifname, void *priv, |
8191 | enum wpa_alg alg, const u8 *addr, | |
8192 | int key_idx, int set_tx, | |
8193 | const u8 *seq, size_t seq_len, | |
8194 | const u8 *key, size_t key_len) | |
8195 | { | |
8196 | struct i802_bss *bss = priv; | |
8197 | return wpa_driver_nl80211_set_key(ifname, bss, alg, addr, key_idx, | |
8198 | set_tx, seq, seq_len, key, key_len); | |
8199 | } | |
8200 | ||
8201 | ||
8202 | static int driver_nl80211_scan2(void *priv, | |
8203 | struct wpa_driver_scan_params *params) | |
8204 | { | |
8205 | struct i802_bss *bss = priv; | |
b658547d | 8206 | #ifdef CONFIG_DRIVER_NL80211_QCA |
adcd7c4b KV |
8207 | struct wpa_driver_nl80211_data *drv = bss->drv; |
8208 | ||
8209 | /* | |
8210 | * Do a vendor specific scan if possible. If only_new_results is | |
8211 | * set, do a normal scan since a kernel (cfg80211) BSS cache flush | |
8212 | * cannot be achieved through a vendor scan. The below condition may | |
8213 | * need to be modified if new scan flags are added in the future whose | |
8214 | * functionality can only be achieved through a normal scan. | |
8215 | */ | |
8216 | if (drv->scan_vendor_cmd_avail && !params->only_new_results) | |
8217 | return wpa_driver_nl80211_vendor_scan(bss, params); | |
b658547d | 8218 | #endif /* CONFIG_DRIVER_NL80211_QCA */ |
9ebce9c5 JM |
8219 | return wpa_driver_nl80211_scan(bss, params); |
8220 | } | |
8221 | ||
8222 | ||
8223 | static int driver_nl80211_deauthenticate(void *priv, const u8 *addr, | |
8224 | int reason_code) | |
8225 | { | |
8226 | struct i802_bss *bss = priv; | |
8227 | return wpa_driver_nl80211_deauthenticate(bss, addr, reason_code); | |
8228 | } | |
8229 | ||
8230 | ||
8231 | static int driver_nl80211_authenticate(void *priv, | |
8232 | struct wpa_driver_auth_params *params) | |
8233 | { | |
8234 | struct i802_bss *bss = priv; | |
8235 | return wpa_driver_nl80211_authenticate(bss, params); | |
8236 | } | |
8237 | ||
8238 | ||
8239 | static void driver_nl80211_deinit(void *priv) | |
8240 | { | |
8241 | struct i802_bss *bss = priv; | |
8242 | wpa_driver_nl80211_deinit(bss); | |
8243 | } | |
8244 | ||
8245 | ||
8246 | static int driver_nl80211_if_remove(void *priv, enum wpa_driver_if_type type, | |
8247 | const char *ifname) | |
8248 | { | |
8249 | struct i802_bss *bss = priv; | |
8250 | return wpa_driver_nl80211_if_remove(bss, type, ifname); | |
8251 | } | |
8252 | ||
8253 | ||
8254 | static int driver_nl80211_send_mlme(void *priv, const u8 *data, | |
5d180a77 | 8255 | size_t data_len, int noack, |
2d3943ce AO |
8256 | unsigned int freq, |
8257 | const u16 *csa_offs, size_t csa_offs_len) | |
9ebce9c5 JM |
8258 | { |
8259 | struct i802_bss *bss = priv; | |
8260 | return wpa_driver_nl80211_send_mlme(bss, data, data_len, noack, | |
2d3943ce AO |
8261 | freq, 0, 0, 0, csa_offs, |
8262 | csa_offs_len); | |
9ebce9c5 JM |
8263 | } |
8264 | ||
8265 | ||
8266 | static int driver_nl80211_sta_remove(void *priv, const u8 *addr) | |
8267 | { | |
8268 | struct i802_bss *bss = priv; | |
59d7148a | 8269 | return wpa_driver_nl80211_sta_remove(bss, addr, -1, 0); |
9ebce9c5 JM |
8270 | } |
8271 | ||
8272 | ||
9ebce9c5 JM |
8273 | static int driver_nl80211_set_sta_vlan(void *priv, const u8 *addr, |
8274 | const char *ifname, int vlan_id) | |
8275 | { | |
8276 | struct i802_bss *bss = priv; | |
8277 | return i802_set_sta_vlan(bss, addr, ifname, vlan_id); | |
8278 | } | |
9ebce9c5 JM |
8279 | |
8280 | ||
8281 | static int driver_nl80211_read_sta_data(void *priv, | |
8282 | struct hostap_sta_driver_data *data, | |
8283 | const u8 *addr) | |
8284 | { | |
8285 | struct i802_bss *bss = priv; | |
7824bf77 JC |
8286 | |
8287 | os_memset(data, 0, sizeof(*data)); | |
9ebce9c5 JM |
8288 | return i802_read_sta_data(bss, data, addr); |
8289 | } | |
8290 | ||
8291 | ||
8292 | static int driver_nl80211_send_action(void *priv, unsigned int freq, | |
8293 | unsigned int wait_time, | |
8294 | const u8 *dst, const u8 *src, | |
8295 | const u8 *bssid, | |
8296 | const u8 *data, size_t data_len, | |
8297 | int no_cck) | |
8298 | { | |
8299 | struct i802_bss *bss = priv; | |
8300 | return wpa_driver_nl80211_send_action(bss, freq, wait_time, dst, src, | |
8301 | bssid, data, data_len, no_cck); | |
8302 | } | |
8303 | ||
8304 | ||
8305 | static int driver_nl80211_probe_req_report(void *priv, int report) | |
8306 | { | |
8307 | struct i802_bss *bss = priv; | |
8308 | return wpa_driver_nl80211_probe_req_report(bss, report); | |
8309 | } | |
8310 | ||
8311 | ||
6a1ce395 DG |
8312 | static int wpa_driver_nl80211_update_ft_ies(void *priv, const u8 *md, |
8313 | const u8 *ies, size_t ies_len) | |
8314 | { | |
8315 | int ret; | |
8316 | struct nl_msg *msg; | |
8317 | struct i802_bss *bss = priv; | |
8318 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
8319 | u16 mdid = WPA_GET_LE16(md); | |
8320 | ||
6a1ce395 | 8321 | wpa_printf(MSG_DEBUG, "nl80211: Updating FT IEs"); |
9725b784 | 8322 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_UPDATE_FT_IES)) || |
a862e4a3 JM |
8323 | nla_put(msg, NL80211_ATTR_IE, ies_len, ies) || |
8324 | nla_put_u16(msg, NL80211_ATTR_MDID, mdid)) { | |
8325 | nlmsg_free(msg); | |
8326 | return -ENOBUFS; | |
8327 | } | |
6a1ce395 DG |
8328 | |
8329 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); | |
8330 | if (ret) { | |
8331 | wpa_printf(MSG_DEBUG, "nl80211: update_ft_ies failed " | |
8332 | "err=%d (%s)", ret, strerror(-ret)); | |
8333 | } | |
8334 | ||
8335 | return ret; | |
6a1ce395 DG |
8336 | } |
8337 | ||
8338 | ||
47754718 | 8339 | static const u8 * wpa_driver_nl80211_get_macaddr(void *priv) |
597b94f5 AS |
8340 | { |
8341 | struct i802_bss *bss = priv; | |
8342 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
8343 | ||
8344 | if (drv->nlmode != NL80211_IFTYPE_P2P_DEVICE) | |
8345 | return NULL; | |
8346 | ||
8347 | return bss->addr; | |
8348 | } | |
8349 | ||
8350 | ||
a771c07d JM |
8351 | static const char * scan_state_str(enum scan_states scan_state) |
8352 | { | |
8353 | switch (scan_state) { | |
8354 | case NO_SCAN: | |
8355 | return "NO_SCAN"; | |
8356 | case SCAN_REQUESTED: | |
8357 | return "SCAN_REQUESTED"; | |
8358 | case SCAN_STARTED: | |
8359 | return "SCAN_STARTED"; | |
8360 | case SCAN_COMPLETED: | |
8361 | return "SCAN_COMPLETED"; | |
8362 | case SCAN_ABORTED: | |
8363 | return "SCAN_ABORTED"; | |
8364 | case SCHED_SCAN_STARTED: | |
8365 | return "SCHED_SCAN_STARTED"; | |
8366 | case SCHED_SCAN_STOPPED: | |
8367 | return "SCHED_SCAN_STOPPED"; | |
8368 | case SCHED_SCAN_RESULTS: | |
8369 | return "SCHED_SCAN_RESULTS"; | |
8370 | } | |
8371 | ||
8372 | return "??"; | |
8373 | } | |
8374 | ||
8375 | ||
8376 | static int wpa_driver_nl80211_status(void *priv, char *buf, size_t buflen) | |
8377 | { | |
8378 | struct i802_bss *bss = priv; | |
8379 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
8380 | int res; | |
8381 | char *pos, *end; | |
8382 | ||
8383 | pos = buf; | |
8384 | end = buf + buflen; | |
8385 | ||
8386 | res = os_snprintf(pos, end - pos, | |
8387 | "ifindex=%d\n" | |
8388 | "ifname=%s\n" | |
8389 | "brname=%s\n" | |
8390 | "addr=" MACSTR "\n" | |
8391 | "freq=%d\n" | |
8392 | "%s%s%s%s%s", | |
8393 | bss->ifindex, | |
8394 | bss->ifname, | |
8395 | bss->brname, | |
8396 | MAC2STR(bss->addr), | |
8397 | bss->freq, | |
8398 | bss->beacon_set ? "beacon_set=1\n" : "", | |
8399 | bss->added_if_into_bridge ? | |
8400 | "added_if_into_bridge=1\n" : "", | |
8401 | bss->added_bridge ? "added_bridge=1\n" : "", | |
8402 | bss->in_deinit ? "in_deinit=1\n" : "", | |
8403 | bss->if_dynamic ? "if_dynamic=1\n" : ""); | |
d85e1fc8 | 8404 | if (os_snprintf_error(end - pos, res)) |
a771c07d JM |
8405 | return pos - buf; |
8406 | pos += res; | |
8407 | ||
8408 | if (bss->wdev_id_set) { | |
8409 | res = os_snprintf(pos, end - pos, "wdev_id=%llu\n", | |
8410 | (unsigned long long) bss->wdev_id); | |
d85e1fc8 | 8411 | if (os_snprintf_error(end - pos, res)) |
a771c07d JM |
8412 | return pos - buf; |
8413 | pos += res; | |
8414 | } | |
8415 | ||
8416 | res = os_snprintf(pos, end - pos, | |
8417 | "phyname=%s\n" | |
fee354c7 | 8418 | "perm_addr=" MACSTR "\n" |
a771c07d JM |
8419 | "drv_ifindex=%d\n" |
8420 | "operstate=%d\n" | |
8421 | "scan_state=%s\n" | |
8422 | "auth_bssid=" MACSTR "\n" | |
8423 | "auth_attempt_bssid=" MACSTR "\n" | |
8424 | "bssid=" MACSTR "\n" | |
8425 | "prev_bssid=" MACSTR "\n" | |
8426 | "associated=%d\n" | |
8427 | "assoc_freq=%u\n" | |
8428 | "monitor_sock=%d\n" | |
8429 | "monitor_ifidx=%d\n" | |
8430 | "monitor_refcount=%d\n" | |
8431 | "last_mgmt_freq=%u\n" | |
8432 | "eapol_tx_sock=%d\n" | |
97752f79 | 8433 | "%s%s%s%s%s%s%s%s%s%s%s%s%s", |
a771c07d | 8434 | drv->phyname, |
fee354c7 | 8435 | MAC2STR(drv->perm_addr), |
a771c07d JM |
8436 | drv->ifindex, |
8437 | drv->operstate, | |
8438 | scan_state_str(drv->scan_state), | |
8439 | MAC2STR(drv->auth_bssid), | |
8440 | MAC2STR(drv->auth_attempt_bssid), | |
8441 | MAC2STR(drv->bssid), | |
8442 | MAC2STR(drv->prev_bssid), | |
8443 | drv->associated, | |
8444 | drv->assoc_freq, | |
8445 | drv->monitor_sock, | |
8446 | drv->monitor_ifidx, | |
8447 | drv->monitor_refcount, | |
8448 | drv->last_mgmt_freq, | |
8449 | drv->eapol_tx_sock, | |
8450 | drv->ignore_if_down_event ? | |
8451 | "ignore_if_down_event=1\n" : "", | |
8452 | drv->scan_complete_events ? | |
8453 | "scan_complete_events=1\n" : "", | |
8454 | drv->disabled_11b_rates ? | |
8455 | "disabled_11b_rates=1\n" : "", | |
8456 | drv->pending_remain_on_chan ? | |
8457 | "pending_remain_on_chan=1\n" : "", | |
8458 | drv->in_interface_list ? "in_interface_list=1\n" : "", | |
8459 | drv->device_ap_sme ? "device_ap_sme=1\n" : "", | |
8460 | drv->poll_command_supported ? | |
8461 | "poll_command_supported=1\n" : "", | |
8462 | drv->data_tx_status ? "data_tx_status=1\n" : "", | |
8463 | drv->scan_for_auth ? "scan_for_auth=1\n" : "", | |
8464 | drv->retry_auth ? "retry_auth=1\n" : "", | |
8465 | drv->use_monitor ? "use_monitor=1\n" : "", | |
8466 | drv->ignore_next_local_disconnect ? | |
8467 | "ignore_next_local_disconnect=1\n" : "", | |
d6a36f39 | 8468 | drv->ignore_next_local_deauth ? |
97752f79 | 8469 | "ignore_next_local_deauth=1\n" : ""); |
d85e1fc8 | 8470 | if (os_snprintf_error(end - pos, res)) |
a771c07d JM |
8471 | return pos - buf; |
8472 | pos += res; | |
8473 | ||
8474 | if (drv->has_capability) { | |
8475 | res = os_snprintf(pos, end - pos, | |
8476 | "capa.key_mgmt=0x%x\n" | |
8477 | "capa.enc=0x%x\n" | |
8478 | "capa.auth=0x%x\n" | |
24bd4e0b | 8479 | "capa.flags=0x%llx\n" |
a0a34d53 | 8480 | "capa.rrm_flags=0x%x\n" |
a771c07d JM |
8481 | "capa.max_scan_ssids=%d\n" |
8482 | "capa.max_sched_scan_ssids=%d\n" | |
8483 | "capa.sched_scan_supported=%d\n" | |
8484 | "capa.max_match_sets=%d\n" | |
8485 | "capa.max_remain_on_chan=%u\n" | |
8486 | "capa.max_stations=%u\n" | |
8487 | "capa.probe_resp_offloads=0x%x\n" | |
8488 | "capa.max_acl_mac_addrs=%u\n" | |
86056fea IP |
8489 | "capa.num_multichan_concurrent=%u\n" |
8490 | "capa.mac_addr_rand_sched_scan_supported=%d\n" | |
079a28f7 AK |
8491 | "capa.mac_addr_rand_scan_supported=%d\n" |
8492 | "capa.conc_capab=%u\n" | |
8493 | "capa.max_conc_chan_2_4=%u\n" | |
09ea4309 AS |
8494 | "capa.max_conc_chan_5_0=%u\n" |
8495 | "capa.max_sched_scan_plans=%u\n" | |
8496 | "capa.max_sched_scan_plan_interval=%u\n" | |
8497 | "capa.max_sched_scan_plan_iterations=%u\n", | |
a771c07d JM |
8498 | drv->capa.key_mgmt, |
8499 | drv->capa.enc, | |
8500 | drv->capa.auth, | |
24bd4e0b | 8501 | (unsigned long long) drv->capa.flags, |
a0a34d53 | 8502 | drv->capa.rrm_flags, |
a771c07d JM |
8503 | drv->capa.max_scan_ssids, |
8504 | drv->capa.max_sched_scan_ssids, | |
8505 | drv->capa.sched_scan_supported, | |
8506 | drv->capa.max_match_sets, | |
8507 | drv->capa.max_remain_on_chan, | |
8508 | drv->capa.max_stations, | |
8509 | drv->capa.probe_resp_offloads, | |
8510 | drv->capa.max_acl_mac_addrs, | |
86056fea IP |
8511 | drv->capa.num_multichan_concurrent, |
8512 | drv->capa.mac_addr_rand_sched_scan_supported, | |
079a28f7 AK |
8513 | drv->capa.mac_addr_rand_scan_supported, |
8514 | drv->capa.conc_capab, | |
8515 | drv->capa.max_conc_chan_2_4, | |
09ea4309 AS |
8516 | drv->capa.max_conc_chan_5_0, |
8517 | drv->capa.max_sched_scan_plans, | |
8518 | drv->capa.max_sched_scan_plan_interval, | |
8519 | drv->capa.max_sched_scan_plan_iterations); | |
d85e1fc8 | 8520 | if (os_snprintf_error(end - pos, res)) |
a771c07d JM |
8521 | return pos - buf; |
8522 | pos += res; | |
8523 | } | |
8524 | ||
8525 | return pos - buf; | |
8526 | } | |
8527 | ||
8528 | ||
1c4ffa87 AO |
8529 | static int set_beacon_data(struct nl_msg *msg, struct beacon_data *settings) |
8530 | { | |
a862e4a3 JM |
8531 | if ((settings->head && |
8532 | nla_put(msg, NL80211_ATTR_BEACON_HEAD, | |
8533 | settings->head_len, settings->head)) || | |
8534 | (settings->tail && | |
8535 | nla_put(msg, NL80211_ATTR_BEACON_TAIL, | |
8536 | settings->tail_len, settings->tail)) || | |
8537 | (settings->beacon_ies && | |
8538 | nla_put(msg, NL80211_ATTR_IE, | |
8539 | settings->beacon_ies_len, settings->beacon_ies)) || | |
8540 | (settings->proberesp_ies && | |
8541 | nla_put(msg, NL80211_ATTR_IE_PROBE_RESP, | |
8542 | settings->proberesp_ies_len, settings->proberesp_ies)) || | |
8543 | (settings->assocresp_ies && | |
8544 | nla_put(msg, NL80211_ATTR_IE_ASSOC_RESP, | |
8545 | settings->assocresp_ies_len, settings->assocresp_ies)) || | |
8546 | (settings->probe_resp && | |
8547 | nla_put(msg, NL80211_ATTR_PROBE_RESP, | |
8548 | settings->probe_resp_len, settings->probe_resp))) | |
8549 | return -ENOBUFS; | |
1c4ffa87 AO |
8550 | |
8551 | return 0; | |
1c4ffa87 AO |
8552 | } |
8553 | ||
8554 | ||
8555 | static int nl80211_switch_channel(void *priv, struct csa_settings *settings) | |
8556 | { | |
8557 | struct nl_msg *msg; | |
8558 | struct i802_bss *bss = priv; | |
8559 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
8560 | struct nlattr *beacon_csa; | |
8561 | int ret = -ENOBUFS; | |
366179d2 AO |
8562 | int csa_off_len = 0; |
8563 | int i; | |
1c4ffa87 | 8564 | |
8d1fdde7 | 8565 | wpa_printf(MSG_DEBUG, "nl80211: Channel switch request (cs_count=%u block_tx=%u freq=%d width=%d cf1=%d cf2=%d)", |
1c4ffa87 | 8566 | settings->cs_count, settings->block_tx, |
8d1fdde7 JD |
8567 | settings->freq_params.freq, settings->freq_params.bandwidth, |
8568 | settings->freq_params.center_freq1, | |
8569 | settings->freq_params.center_freq2); | |
1c4ffa87 | 8570 | |
991aa9c7 | 8571 | if (!(drv->capa.flags & WPA_DRIVER_FLAGS_AP_CSA)) { |
1c4ffa87 AO |
8572 | wpa_printf(MSG_DEBUG, "nl80211: Driver does not support channel switch command"); |
8573 | return -EOPNOTSUPP; | |
8574 | } | |
8575 | ||
8576 | if ((drv->nlmode != NL80211_IFTYPE_AP) && | |
8577 | (drv->nlmode != NL80211_IFTYPE_P2P_GO)) | |
8578 | return -EOPNOTSUPP; | |
8579 | ||
366179d2 AO |
8580 | /* |
8581 | * Remove empty counters, assuming Probe Response and Beacon frame | |
8582 | * counters match. This implementation assumes that there are only two | |
8583 | * counters. | |
8584 | */ | |
8585 | if (settings->counter_offset_beacon[0] && | |
8586 | !settings->counter_offset_beacon[1]) { | |
8587 | csa_off_len = 1; | |
8588 | } else if (settings->counter_offset_beacon[1] && | |
8589 | !settings->counter_offset_beacon[0]) { | |
8590 | csa_off_len = 1; | |
8591 | settings->counter_offset_beacon[0] = | |
8592 | settings->counter_offset_beacon[1]; | |
8593 | settings->counter_offset_presp[0] = | |
8594 | settings->counter_offset_presp[1]; | |
8595 | } else if (settings->counter_offset_beacon[1] && | |
8596 | settings->counter_offset_beacon[0]) { | |
8597 | csa_off_len = 2; | |
8598 | } else { | |
8599 | wpa_printf(MSG_ERROR, "nl80211: No CSA counters provided"); | |
8600 | return -EINVAL; | |
8601 | } | |
8602 | ||
8603 | /* Check CSA counters validity */ | |
8604 | if (drv->capa.max_csa_counters && | |
8605 | csa_off_len > drv->capa.max_csa_counters) { | |
8606 | wpa_printf(MSG_ERROR, | |
8607 | "nl80211: Too many CSA counters provided"); | |
1c4ffa87 | 8608 | return -EINVAL; |
366179d2 | 8609 | } |
1c4ffa87 | 8610 | |
366179d2 | 8611 | if (!settings->beacon_csa.tail) |
1c4ffa87 AO |
8612 | return -EINVAL; |
8613 | ||
366179d2 AO |
8614 | for (i = 0; i < csa_off_len; i++) { |
8615 | u16 csa_c_off_bcn = settings->counter_offset_beacon[i]; | |
8616 | u16 csa_c_off_presp = settings->counter_offset_presp[i]; | |
8617 | ||
8618 | if ((settings->beacon_csa.tail_len <= csa_c_off_bcn) || | |
8619 | (settings->beacon_csa.tail[csa_c_off_bcn] != | |
8620 | settings->cs_count)) | |
8621 | return -EINVAL; | |
8622 | ||
8623 | if (settings->beacon_csa.probe_resp && | |
8624 | ((settings->beacon_csa.probe_resp_len <= | |
8625 | csa_c_off_presp) || | |
8626 | (settings->beacon_csa.probe_resp[csa_c_off_presp] != | |
8627 | settings->cs_count))) | |
8628 | return -EINVAL; | |
8629 | } | |
8630 | ||
13f83980 | 8631 | if (!(msg = nl80211_bss_msg(bss, 0, NL80211_CMD_CHANNEL_SWITCH)) || |
a862e4a3 JM |
8632 | nla_put_u32(msg, NL80211_ATTR_CH_SWITCH_COUNT, |
8633 | settings->cs_count) || | |
8634 | (ret = nl80211_put_freq_params(msg, &settings->freq_params)) || | |
8635 | (settings->block_tx && | |
8636 | nla_put_flag(msg, NL80211_ATTR_CH_SWITCH_BLOCK_TX))) | |
1c4ffa87 AO |
8637 | goto error; |
8638 | ||
1c4ffa87 AO |
8639 | /* beacon_after params */ |
8640 | ret = set_beacon_data(msg, &settings->beacon_after); | |
8641 | if (ret) | |
8642 | goto error; | |
8643 | ||
8644 | /* beacon_csa params */ | |
8645 | beacon_csa = nla_nest_start(msg, NL80211_ATTR_CSA_IES); | |
8646 | if (!beacon_csa) | |
a862e4a3 | 8647 | goto fail; |
1c4ffa87 AO |
8648 | |
8649 | ret = set_beacon_data(msg, &settings->beacon_csa); | |
8650 | if (ret) | |
8651 | goto error; | |
8652 | ||
366179d2 AO |
8653 | if (nla_put(msg, NL80211_ATTR_CSA_C_OFF_BEACON, |
8654 | csa_off_len * sizeof(u16), | |
8655 | settings->counter_offset_beacon) || | |
a862e4a3 | 8656 | (settings->beacon_csa.probe_resp && |
366179d2 AO |
8657 | nla_put(msg, NL80211_ATTR_CSA_C_OFF_PRESP, |
8658 | csa_off_len * sizeof(u16), | |
8659 | settings->counter_offset_presp))) | |
a862e4a3 | 8660 | goto fail; |
1c4ffa87 AO |
8661 | |
8662 | nla_nest_end(msg, beacon_csa); | |
8663 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); | |
8664 | if (ret) { | |
8665 | wpa_printf(MSG_DEBUG, "nl80211: switch_channel failed err=%d (%s)", | |
8666 | ret, strerror(-ret)); | |
8667 | } | |
8668 | return ret; | |
8669 | ||
a862e4a3 | 8670 | fail: |
1c4ffa87 AO |
8671 | ret = -ENOBUFS; |
8672 | error: | |
8673 | nlmsg_free(msg); | |
8674 | wpa_printf(MSG_DEBUG, "nl80211: Could not build channel switch request"); | |
8675 | return ret; | |
8676 | } | |
8677 | ||
8678 | ||
dfa87878 MB |
8679 | static int nl80211_add_ts(void *priv, u8 tsid, const u8 *addr, |
8680 | u8 user_priority, u16 admitted_time) | |
8681 | { | |
8682 | struct i802_bss *bss = priv; | |
8683 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
8684 | struct nl_msg *msg; | |
8685 | int ret; | |
8686 | ||
8687 | wpa_printf(MSG_DEBUG, | |
8688 | "nl80211: add_ts request: tsid=%u admitted_time=%u up=%d", | |
8689 | tsid, admitted_time, user_priority); | |
8690 | ||
8691 | if (!is_sta_interface(drv->nlmode)) | |
8692 | return -ENOTSUP; | |
8693 | ||
56f77852 JM |
8694 | msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_ADD_TX_TS); |
8695 | if (!msg || | |
a862e4a3 JM |
8696 | nla_put_u8(msg, NL80211_ATTR_TSID, tsid) || |
8697 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) || | |
8698 | nla_put_u8(msg, NL80211_ATTR_USER_PRIO, user_priority) || | |
8699 | nla_put_u16(msg, NL80211_ATTR_ADMITTED_TIME, admitted_time)) { | |
8700 | nlmsg_free(msg); | |
8701 | return -ENOBUFS; | |
8702 | } | |
dfa87878 MB |
8703 | |
8704 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); | |
8705 | if (ret) | |
8706 | wpa_printf(MSG_DEBUG, "nl80211: add_ts failed err=%d (%s)", | |
8707 | ret, strerror(-ret)); | |
8708 | return ret; | |
dfa87878 MB |
8709 | } |
8710 | ||
8711 | ||
8712 | static int nl80211_del_ts(void *priv, u8 tsid, const u8 *addr) | |
8713 | { | |
8714 | struct i802_bss *bss = priv; | |
8715 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
8716 | struct nl_msg *msg; | |
8717 | int ret; | |
8718 | ||
8719 | wpa_printf(MSG_DEBUG, "nl80211: del_ts request: tsid=%u", tsid); | |
8720 | ||
8721 | if (!is_sta_interface(drv->nlmode)) | |
8722 | return -ENOTSUP; | |
8723 | ||
56f77852 | 8724 | if (!(msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_DEL_TX_TS)) || |
a862e4a3 JM |
8725 | nla_put_u8(msg, NL80211_ATTR_TSID, tsid) || |
8726 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) { | |
8727 | nlmsg_free(msg); | |
8728 | return -ENOBUFS; | |
8729 | } | |
dfa87878 MB |
8730 | |
8731 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); | |
8732 | if (ret) | |
8733 | wpa_printf(MSG_DEBUG, "nl80211: del_ts failed err=%d (%s)", | |
8734 | ret, strerror(-ret)); | |
8735 | return ret; | |
dfa87878 MB |
8736 | } |
8737 | ||
8738 | ||
6b9f7af6 JM |
8739 | #ifdef CONFIG_TESTING_OPTIONS |
8740 | static int cmd_reply_handler(struct nl_msg *msg, void *arg) | |
8741 | { | |
8742 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); | |
8743 | struct wpabuf *buf = arg; | |
8744 | ||
8745 | if (!buf) | |
8746 | return NL_SKIP; | |
8747 | ||
8748 | if ((size_t) genlmsg_attrlen(gnlh, 0) > wpabuf_tailroom(buf)) { | |
8749 | wpa_printf(MSG_INFO, "nl80211: insufficient buffer space for reply"); | |
8750 | return NL_SKIP; | |
8751 | } | |
8752 | ||
8753 | wpabuf_put_data(buf, genlmsg_attrdata(gnlh, 0), | |
8754 | genlmsg_attrlen(gnlh, 0)); | |
8755 | ||
8756 | return NL_SKIP; | |
8757 | } | |
8758 | #endif /* CONFIG_TESTING_OPTIONS */ | |
8759 | ||
8760 | ||
adef8948 BL |
8761 | static int vendor_reply_handler(struct nl_msg *msg, void *arg) |
8762 | { | |
8763 | struct nlattr *tb[NL80211_ATTR_MAX + 1]; | |
8764 | struct nlattr *nl_vendor_reply, *nl; | |
8765 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); | |
8766 | struct wpabuf *buf = arg; | |
8767 | int rem; | |
8768 | ||
8769 | if (!buf) | |
8770 | return NL_SKIP; | |
8771 | ||
8772 | nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), | |
8773 | genlmsg_attrlen(gnlh, 0), NULL); | |
8774 | nl_vendor_reply = tb[NL80211_ATTR_VENDOR_DATA]; | |
8775 | ||
8776 | if (!nl_vendor_reply) | |
8777 | return NL_SKIP; | |
8778 | ||
8779 | if ((size_t) nla_len(nl_vendor_reply) > wpabuf_tailroom(buf)) { | |
8780 | wpa_printf(MSG_INFO, "nl80211: Vendor command: insufficient buffer space for reply"); | |
8781 | return NL_SKIP; | |
8782 | } | |
8783 | ||
8784 | nla_for_each_nested(nl, nl_vendor_reply, rem) { | |
8785 | wpabuf_put_data(buf, nla_data(nl), nla_len(nl)); | |
8786 | } | |
8787 | ||
8788 | return NL_SKIP; | |
8789 | } | |
8790 | ||
8791 | ||
8792 | static int nl80211_vendor_cmd(void *priv, unsigned int vendor_id, | |
8793 | unsigned int subcmd, const u8 *data, | |
8794 | size_t data_len, struct wpabuf *buf) | |
8795 | { | |
8796 | struct i802_bss *bss = priv; | |
8797 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
8798 | struct nl_msg *msg; | |
8799 | int ret; | |
8800 | ||
6b9f7af6 JM |
8801 | #ifdef CONFIG_TESTING_OPTIONS |
8802 | if (vendor_id == 0xffffffff) { | |
56f77852 JM |
8803 | msg = nlmsg_alloc(); |
8804 | if (!msg) | |
8805 | return -ENOMEM; | |
8806 | ||
6b9f7af6 JM |
8807 | nl80211_cmd(drv, msg, 0, subcmd); |
8808 | if (nlmsg_append(msg, (void *) data, data_len, NLMSG_ALIGNTO) < | |
8809 | 0) | |
a862e4a3 | 8810 | goto fail; |
6b9f7af6 JM |
8811 | ret = send_and_recv_msgs(drv, msg, cmd_reply_handler, buf); |
8812 | if (ret) | |
8813 | wpa_printf(MSG_DEBUG, "nl80211: command failed err=%d", | |
8814 | ret); | |
8815 | return ret; | |
8816 | } | |
8817 | #endif /* CONFIG_TESTING_OPTIONS */ | |
8818 | ||
56f77852 | 8819 | if (!(msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_VENDOR)) || |
a862e4a3 JM |
8820 | nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, vendor_id) || |
8821 | nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD, subcmd) || | |
8822 | (data && | |
8823 | nla_put(msg, NL80211_ATTR_VENDOR_DATA, data_len, data))) | |
8824 | goto fail; | |
adef8948 BL |
8825 | |
8826 | ret = send_and_recv_msgs(drv, msg, vendor_reply_handler, buf); | |
8827 | if (ret) | |
8828 | wpa_printf(MSG_DEBUG, "nl80211: vendor command failed err=%d", | |
8829 | ret); | |
8830 | return ret; | |
8831 | ||
a862e4a3 | 8832 | fail: |
adef8948 BL |
8833 | nlmsg_free(msg); |
8834 | return -ENOBUFS; | |
8835 | } | |
8836 | ||
8837 | ||
049105b4 KP |
8838 | static int nl80211_set_qos_map(void *priv, const u8 *qos_map_set, |
8839 | u8 qos_map_set_len) | |
8840 | { | |
8841 | struct i802_bss *bss = priv; | |
8842 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
8843 | struct nl_msg *msg; | |
8844 | int ret; | |
8845 | ||
049105b4 KP |
8846 | wpa_hexdump(MSG_DEBUG, "nl80211: Setting QoS Map", |
8847 | qos_map_set, qos_map_set_len); | |
8848 | ||
9725b784 | 8849 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_SET_QOS_MAP)) || |
a862e4a3 JM |
8850 | nla_put(msg, NL80211_ATTR_QOS_MAP, qos_map_set_len, qos_map_set)) { |
8851 | nlmsg_free(msg); | |
8852 | return -ENOBUFS; | |
8853 | } | |
049105b4 KP |
8854 | |
8855 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); | |
8856 | if (ret) | |
8857 | wpa_printf(MSG_DEBUG, "nl80211: Setting QoS Map failed"); | |
8858 | ||
8859 | return ret; | |
049105b4 KP |
8860 | } |
8861 | ||
8862 | ||
e4fa8b12 EP |
8863 | static int nl80211_set_wowlan(void *priv, |
8864 | const struct wowlan_triggers *triggers) | |
8865 | { | |
8866 | struct i802_bss *bss = priv; | |
8867 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
8868 | struct nl_msg *msg; | |
8869 | struct nlattr *wowlan_triggers; | |
8870 | int ret; | |
8871 | ||
e4fa8b12 EP |
8872 | wpa_printf(MSG_DEBUG, "nl80211: Setting wowlan"); |
8873 | ||
1ac977bd | 8874 | if (!(msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_SET_WOWLAN)) || |
a862e4a3 JM |
8875 | !(wowlan_triggers = nla_nest_start(msg, |
8876 | NL80211_ATTR_WOWLAN_TRIGGERS)) || | |
8877 | (triggers->any && | |
8878 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_ANY)) || | |
8879 | (triggers->disconnect && | |
8880 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) || | |
8881 | (triggers->magic_pkt && | |
8882 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) || | |
8883 | (triggers->gtk_rekey_failure && | |
8884 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) || | |
8885 | (triggers->eap_identity_req && | |
8886 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) || | |
8887 | (triggers->four_way_handshake && | |
8888 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) || | |
8889 | (triggers->rfkill_release && | |
8890 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE))) { | |
8891 | nlmsg_free(msg); | |
8892 | return -ENOBUFS; | |
8893 | } | |
e4fa8b12 EP |
8894 | |
8895 | nla_nest_end(msg, wowlan_triggers); | |
8896 | ||
8897 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); | |
8898 | if (ret) | |
8899 | wpa_printf(MSG_DEBUG, "nl80211: Setting wowlan failed"); | |
8900 | ||
8901 | return ret; | |
e4fa8b12 EP |
8902 | } |
8903 | ||
8904 | ||
b658547d | 8905 | #ifdef CONFIG_DRIVER_NL80211_QCA |
0800f9ee JM |
8906 | static int nl80211_roaming(void *priv, int allowed, const u8 *bssid) |
8907 | { | |
8908 | struct i802_bss *bss = priv; | |
8909 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
8910 | struct nl_msg *msg; | |
8911 | struct nlattr *params; | |
8912 | ||
8913 | wpa_printf(MSG_DEBUG, "nl80211: Roaming policy: allowed=%d", allowed); | |
8914 | ||
8915 | if (!drv->roaming_vendor_cmd_avail) { | |
8916 | wpa_printf(MSG_DEBUG, | |
8917 | "nl80211: Ignore roaming policy change since driver does not provide command for setting it"); | |
8918 | return -1; | |
8919 | } | |
8920 | ||
9725b784 | 8921 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_VENDOR)) || |
a862e4a3 JM |
8922 | nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) || |
8923 | nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD, | |
8924 | QCA_NL80211_VENDOR_SUBCMD_ROAMING) || | |
8925 | !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) || | |
8926 | nla_put_u32(msg, QCA_WLAN_VENDOR_ATTR_ROAMING_POLICY, | |
8927 | allowed ? QCA_ROAMING_ALLOWED_WITHIN_ESS : | |
8928 | QCA_ROAMING_NOT_ALLOWED) || | |
8929 | (bssid && | |
8930 | nla_put(msg, QCA_WLAN_VENDOR_ATTR_MAC_ADDR, ETH_ALEN, bssid))) { | |
8931 | nlmsg_free(msg); | |
8932 | return -1; | |
8933 | } | |
0800f9ee JM |
8934 | nla_nest_end(msg, params); |
8935 | ||
8936 | return send_and_recv_msgs(drv, msg, NULL, NULL); | |
0800f9ee | 8937 | } |
b04854ce AP |
8938 | |
8939 | ||
d98038bb | 8940 | static int nl80211_disable_fils(void *priv, int disable) |
8941 | { | |
8942 | struct i802_bss *bss = priv; | |
8943 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
8944 | struct nl_msg *msg; | |
8945 | struct nlattr *params; | |
8946 | ||
8947 | wpa_printf(MSG_DEBUG, "nl80211: Disable FILS=%d", disable); | |
8948 | ||
8949 | if (!drv->set_wifi_conf_vendor_cmd_avail) | |
8950 | return -1; | |
8951 | ||
8952 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_VENDOR)) || | |
8953 | nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) || | |
8954 | nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD, | |
8955 | QCA_NL80211_VENDOR_SUBCMD_SET_WIFI_CONFIGURATION) || | |
8956 | !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) || | |
8957 | nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_CONFIG_DISABLE_FILS, | |
8958 | disable)) { | |
8959 | nlmsg_free(msg); | |
8960 | return -1; | |
8961 | } | |
8962 | nla_nest_end(msg, params); | |
8963 | ||
8964 | return send_and_recv_msgs(drv, msg, NULL, NULL); | |
8965 | } | |
8966 | ||
8967 | ||
b04854ce AP |
8968 | /* Reserved QCA_WLAN_VENDOR_ATTR_ROAMING_REQ_ID value for wpa_supplicant */ |
8969 | #define WPA_SUPPLICANT_CLIENT_ID 1 | |
8970 | ||
8971 | static int nl80211_set_bssid_blacklist(void *priv, unsigned int num_bssid, | |
8972 | const u8 *bssid) | |
8973 | { | |
8974 | struct i802_bss *bss = priv; | |
8975 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
8976 | struct nl_msg *msg; | |
8977 | struct nlattr *params, *nlbssids, *attr; | |
8978 | unsigned int i; | |
8979 | ||
8980 | wpa_printf(MSG_DEBUG, "nl80211: Set blacklist BSSID (num=%u)", | |
8981 | num_bssid); | |
8982 | ||
8983 | if (!drv->roam_vendor_cmd_avail) | |
8984 | return -1; | |
8985 | ||
8986 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_VENDOR)) || | |
8987 | nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) || | |
8988 | nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD, | |
8989 | QCA_NL80211_VENDOR_SUBCMD_ROAM) || | |
8990 | !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) || | |
8991 | nla_put_u32(msg, QCA_WLAN_VENDOR_ATTR_ROAMING_SUBCMD, | |
8992 | QCA_WLAN_VENDOR_ATTR_ROAM_SUBCMD_SET_BLACKLIST_BSSID) || | |
8993 | nla_put_u32(msg, QCA_WLAN_VENDOR_ATTR_ROAMING_REQ_ID, | |
8994 | WPA_SUPPLICANT_CLIENT_ID) || | |
8995 | nla_put_u32(msg, | |
8996 | QCA_WLAN_VENDOR_ATTR_ROAMING_PARAM_SET_BSSID_PARAMS_NUM_BSSID, | |
8997 | num_bssid)) | |
8998 | goto fail; | |
8999 | ||
9000 | nlbssids = nla_nest_start( | |
9001 | msg, QCA_WLAN_VENDOR_ATTR_ROAMING_PARAM_SET_BSSID_PARAMS); | |
9002 | if (!nlbssids) | |
9003 | goto fail; | |
9004 | ||
9005 | for (i = 0; i < num_bssid; i++) { | |
9006 | attr = nla_nest_start(msg, i); | |
9007 | if (!attr) | |
9008 | goto fail; | |
9009 | if (nla_put(msg, | |
9010 | QCA_WLAN_VENDOR_ATTR_ROAMING_PARAM_SET_BSSID_PARAMS_BSSID, | |
9011 | ETH_ALEN, &bssid[i * ETH_ALEN])) | |
9012 | goto fail; | |
9013 | wpa_printf(MSG_DEBUG, "nl80211: BSSID[%u]: " MACSTR, i, | |
9014 | MAC2STR(&bssid[i * ETH_ALEN])); | |
9015 | nla_nest_end(msg, attr); | |
9016 | } | |
9017 | nla_nest_end(msg, nlbssids); | |
9018 | nla_nest_end(msg, params); | |
9019 | ||
9020 | return send_and_recv_msgs(drv, msg, NULL, NULL); | |
9021 | ||
9022 | fail: | |
9023 | nlmsg_free(msg); | |
9024 | return -1; | |
9025 | } | |
9026 | ||
b658547d | 9027 | #endif /* CONFIG_DRIVER_NL80211_QCA */ |
0800f9ee JM |
9028 | |
9029 | ||
fee354c7 JM |
9030 | static int nl80211_set_mac_addr(void *priv, const u8 *addr) |
9031 | { | |
9032 | struct i802_bss *bss = priv; | |
9033 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
9034 | int new_addr = addr != NULL; | |
9035 | ||
9ce3e610 JM |
9036 | if (TEST_FAIL()) |
9037 | return -1; | |
9038 | ||
fee354c7 JM |
9039 | if (!addr) |
9040 | addr = drv->perm_addr; | |
9041 | ||
9042 | if (linux_set_iface_flags(drv->global->ioctl_sock, bss->ifname, 0) < 0) | |
9043 | return -1; | |
9044 | ||
9045 | if (linux_set_ifhwaddr(drv->global->ioctl_sock, bss->ifname, addr) < 0) | |
9046 | { | |
9047 | wpa_printf(MSG_DEBUG, | |
9048 | "nl80211: failed to set_mac_addr for %s to " MACSTR, | |
9049 | bss->ifname, MAC2STR(addr)); | |
9050 | if (linux_set_iface_flags(drv->global->ioctl_sock, bss->ifname, | |
9051 | 1) < 0) { | |
9052 | wpa_printf(MSG_DEBUG, | |
9053 | "nl80211: Could not restore interface UP after failed set_mac_addr"); | |
9054 | } | |
9055 | return -1; | |
9056 | } | |
9057 | ||
9058 | wpa_printf(MSG_DEBUG, "nl80211: set_mac_addr for %s to " MACSTR, | |
9059 | bss->ifname, MAC2STR(addr)); | |
9060 | drv->addr_changed = new_addr; | |
9061 | os_memcpy(bss->addr, addr, ETH_ALEN); | |
9062 | ||
9063 | if (linux_set_iface_flags(drv->global->ioctl_sock, bss->ifname, 1) < 0) | |
9064 | { | |
9065 | wpa_printf(MSG_DEBUG, | |
9066 | "nl80211: Could not restore interface UP after set_mac_addr"); | |
9067 | } | |
9068 | ||
9069 | return 0; | |
9070 | } | |
9071 | ||
9072 | ||
6c1664f6 BC |
9073 | #ifdef CONFIG_MESH |
9074 | ||
9075 | static int wpa_driver_nl80211_init_mesh(void *priv) | |
9076 | { | |
9077 | if (wpa_driver_nl80211_set_mode(priv, NL80211_IFTYPE_MESH_POINT)) { | |
9078 | wpa_printf(MSG_INFO, | |
9079 | "nl80211: Failed to set interface into mesh mode"); | |
9080 | return -1; | |
9081 | } | |
9082 | return 0; | |
9083 | } | |
9084 | ||
9085 | ||
21c74e84 JM |
9086 | static int nl80211_put_mesh_id(struct nl_msg *msg, const u8 *mesh_id, |
9087 | size_t mesh_id_len) | |
9088 | { | |
9089 | if (mesh_id) { | |
9090 | wpa_hexdump_ascii(MSG_DEBUG, " * Mesh ID (SSID)", | |
9091 | mesh_id, mesh_id_len); | |
9092 | return nla_put(msg, NL80211_ATTR_MESH_ID, mesh_id_len, mesh_id); | |
9093 | } | |
9094 | ||
9095 | return 0; | |
9096 | } | |
9097 | ||
9098 | ||
4ffb3f87 MH |
9099 | static int nl80211_put_mesh_config(struct nl_msg *msg, |
9100 | struct wpa_driver_mesh_bss_params *params) | |
9101 | { | |
9102 | struct nlattr *container; | |
9103 | ||
9104 | container = nla_nest_start(msg, NL80211_ATTR_MESH_CONFIG); | |
9105 | if (!container) | |
9106 | return -1; | |
9107 | ||
2bd62171 | 9108 | if (((params->flags & WPA_DRIVER_MESH_CONF_FLAG_AUTO_PLINKS) && |
963d3149 JM |
9109 | nla_put_u8(msg, NL80211_MESHCONF_AUTO_OPEN_PLINKS, |
9110 | params->auto_plinks)) || | |
2bd62171 MH |
9111 | ((params->flags & WPA_DRIVER_MESH_CONF_FLAG_MAX_PEER_LINKS) && |
9112 | nla_put_u16(msg, NL80211_MESHCONF_MAX_PEER_LINKS, | |
31a856a1 MH |
9113 | params->max_peer_links)) || |
9114 | ((params->flags & WPA_DRIVER_MESH_CONF_FLAG_RSSI_THRESHOLD) && | |
9115 | nla_put_u32(msg, NL80211_MESHCONF_RSSI_THRESHOLD, | |
9116 | params->rssi_threshold))) | |
4ffb3f87 MH |
9117 | return -1; |
9118 | ||
9119 | /* | |
9120 | * Set NL80211_MESHCONF_PLINK_TIMEOUT even if user mpm is used because | |
9121 | * the timer could disconnect stations even in that case. | |
9122 | */ | |
2bd62171 MH |
9123 | if ((params->flags & WPA_DRIVER_MESH_CONF_FLAG_PEER_LINK_TIMEOUT) && |
9124 | nla_put_u32(msg, NL80211_MESHCONF_PLINK_TIMEOUT, | |
4ffb3f87 MH |
9125 | params->peer_link_timeout)) { |
9126 | wpa_printf(MSG_ERROR, "nl80211: Failed to set PLINK_TIMEOUT"); | |
9127 | return -1; | |
9128 | } | |
9129 | ||
052b8d38 MH |
9130 | if ((params->flags & WPA_DRIVER_MESH_CONF_FLAG_HT_OP_MODE) && |
9131 | nla_put_u16(msg, NL80211_MESHCONF_HT_OPMODE, params->ht_opmode)) { | |
9132 | wpa_printf(MSG_ERROR, "nl80211: Failed to set HT_OP_MODE"); | |
9133 | return -1; | |
9134 | } | |
9135 | ||
4ffb3f87 MH |
9136 | nla_nest_end(msg, container); |
9137 | ||
9138 | return 0; | |
9139 | } | |
9140 | ||
9141 | ||
0cb5f8d9 | 9142 | static int nl80211_join_mesh(struct i802_bss *bss, |
6c1664f6 BC |
9143 | struct wpa_driver_mesh_join_params *params) |
9144 | { | |
6c1664f6 BC |
9145 | struct wpa_driver_nl80211_data *drv = bss->drv; |
9146 | struct nl_msg *msg; | |
9147 | struct nlattr *container; | |
7451a217 | 9148 | int ret = -1; |
6c1664f6 | 9149 | |
6c1664f6 | 9150 | wpa_printf(MSG_DEBUG, "nl80211: mesh join (ifindex=%d)", drv->ifindex); |
9725b784 | 9151 | msg = nl80211_drv_msg(drv, 0, NL80211_CMD_JOIN_MESH); |
f7e889fa JM |
9152 | if (!msg || |
9153 | nl80211_put_freq_params(msg, ¶ms->freq) || | |
21c74e84 JM |
9154 | nl80211_put_basic_rates(msg, params->basic_rates) || |
9155 | nl80211_put_mesh_id(msg, params->meshid, params->meshid_len) || | |
4ac2ea57 MH |
9156 | nl80211_put_beacon_int(msg, params->beacon_int) || |
9157 | nl80211_put_dtim_period(msg, params->dtim_period)) | |
85e1fad8 | 9158 | goto fail; |
9c58c5f7 | 9159 | |
6c1664f6 BC |
9160 | wpa_printf(MSG_DEBUG, " * flags=%08X", params->flags); |
9161 | ||
9162 | container = nla_nest_start(msg, NL80211_ATTR_MESH_SETUP); | |
9163 | if (!container) | |
a862e4a3 | 9164 | goto fail; |
6c1664f6 BC |
9165 | |
9166 | if (params->ies) { | |
9167 | wpa_hexdump(MSG_DEBUG, " * IEs", params->ies, params->ie_len); | |
a862e4a3 JM |
9168 | if (nla_put(msg, NL80211_MESH_SETUP_IE, params->ie_len, |
9169 | params->ies)) | |
9170 | goto fail; | |
6c1664f6 BC |
9171 | } |
9172 | /* WPA_DRIVER_MESH_FLAG_OPEN_AUTH is treated as default by nl80211 */ | |
9173 | if (params->flags & WPA_DRIVER_MESH_FLAG_SAE_AUTH) { | |
a862e4a3 JM |
9174 | if (nla_put_u8(msg, NL80211_MESH_SETUP_AUTH_PROTOCOL, 0x1) || |
9175 | nla_put_flag(msg, NL80211_MESH_SETUP_USERSPACE_AUTH)) | |
9176 | goto fail; | |
6c1664f6 | 9177 | } |
a862e4a3 JM |
9178 | if ((params->flags & WPA_DRIVER_MESH_FLAG_AMPE) && |
9179 | nla_put_flag(msg, NL80211_MESH_SETUP_USERSPACE_AMPE)) | |
9180 | goto fail; | |
9181 | if ((params->flags & WPA_DRIVER_MESH_FLAG_USER_MPM) && | |
9182 | nla_put_flag(msg, NL80211_MESH_SETUP_USERSPACE_MPM)) | |
9183 | goto fail; | |
6c1664f6 BC |
9184 | nla_nest_end(msg, container); |
9185 | ||
2bd62171 MH |
9186 | params->conf.flags |= WPA_DRIVER_MESH_CONF_FLAG_AUTO_PLINKS; |
9187 | params->conf.flags |= WPA_DRIVER_MESH_CONF_FLAG_PEER_LINK_TIMEOUT; | |
9188 | params->conf.flags |= WPA_DRIVER_MESH_CONF_FLAG_MAX_PEER_LINKS; | |
4ffb3f87 | 9189 | if (nl80211_put_mesh_config(msg, ¶ms->conf) < 0) |
5a2a6de6 | 9190 | goto fail; |
6c1664f6 BC |
9191 | |
9192 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); | |
9193 | msg = NULL; | |
9194 | if (ret) { | |
9195 | wpa_printf(MSG_DEBUG, "nl80211: mesh join failed: ret=%d (%s)", | |
9196 | ret, strerror(-ret)); | |
a862e4a3 | 9197 | goto fail; |
6c1664f6 BC |
9198 | } |
9199 | ret = 0; | |
92a515b8 | 9200 | drv->assoc_freq = bss->freq = params->freq.freq; |
6c1664f6 BC |
9201 | wpa_printf(MSG_DEBUG, "nl80211: mesh join request send successfully"); |
9202 | ||
a862e4a3 | 9203 | fail: |
6c1664f6 BC |
9204 | nlmsg_free(msg); |
9205 | return ret; | |
9206 | } | |
9207 | ||
9208 | ||
0cb5f8d9 MH |
9209 | static int |
9210 | wpa_driver_nl80211_join_mesh(void *priv, | |
9211 | struct wpa_driver_mesh_join_params *params) | |
9212 | { | |
9213 | struct i802_bss *bss = priv; | |
9214 | int ret, timeout; | |
9215 | ||
9216 | timeout = params->conf.peer_link_timeout; | |
9217 | ||
9218 | /* Disable kernel inactivity timer */ | |
9219 | if (params->flags & WPA_DRIVER_MESH_FLAG_USER_MPM) | |
9220 | params->conf.peer_link_timeout = 0; | |
9221 | ||
9222 | ret = nl80211_join_mesh(bss, params); | |
9223 | if (ret == -EINVAL && params->conf.peer_link_timeout == 0) { | |
9224 | wpa_printf(MSG_DEBUG, | |
9225 | "nl80211: Mesh join retry for peer_link_timeout"); | |
9226 | /* | |
9227 | * Old kernel does not support setting | |
9228 | * NL80211_MESHCONF_PLINK_TIMEOUT to zero, so set 60 seconds | |
9229 | * into future from peer_link_timeout. | |
9230 | */ | |
9231 | params->conf.peer_link_timeout = timeout + 60; | |
9232 | ret = nl80211_join_mesh(priv, params); | |
9233 | } | |
9234 | ||
9235 | params->conf.peer_link_timeout = timeout; | |
9236 | return ret; | |
9237 | } | |
9238 | ||
9239 | ||
6c1664f6 BC |
9240 | static int wpa_driver_nl80211_leave_mesh(void *priv) |
9241 | { | |
9242 | struct i802_bss *bss = priv; | |
9243 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
9244 | struct nl_msg *msg; | |
9725b784 | 9245 | int ret; |
6c1664f6 BC |
9246 | |
9247 | wpa_printf(MSG_DEBUG, "nl80211: mesh leave (ifindex=%d)", drv->ifindex); | |
9725b784 | 9248 | msg = nl80211_drv_msg(drv, 0, NL80211_CMD_LEAVE_MESH); |
6c1664f6 | 9249 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
6c1664f6 BC |
9250 | if (ret) { |
9251 | wpa_printf(MSG_DEBUG, "nl80211: mesh leave failed: ret=%d (%s)", | |
9252 | ret, strerror(-ret)); | |
a862e4a3 JM |
9253 | } else { |
9254 | wpa_printf(MSG_DEBUG, | |
9255 | "nl80211: mesh leave request send successfully"); | |
6c1664f6 | 9256 | } |
6c1664f6 | 9257 | |
f33c82d2 JM |
9258 | if (wpa_driver_nl80211_set_mode(drv->first_bss, |
9259 | NL80211_IFTYPE_STATION)) { | |
9260 | wpa_printf(MSG_INFO, | |
9261 | "nl80211: Failed to set interface into station mode"); | |
9262 | } | |
6c1664f6 BC |
9263 | return ret; |
9264 | } | |
9265 | ||
9266 | #endif /* CONFIG_MESH */ | |
9267 | ||
9268 | ||
ed4ddb6d KP |
9269 | static int wpa_driver_br_add_ip_neigh(void *priv, u8 version, |
9270 | const u8 *ipaddr, int prefixlen, | |
9271 | const u8 *addr) | |
71103bed KP |
9272 | { |
9273 | #ifdef CONFIG_LIBNL3_ROUTE | |
9274 | struct i802_bss *bss = priv; | |
9275 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
9276 | struct rtnl_neigh *rn; | |
9277 | struct nl_addr *nl_ipaddr = NULL; | |
9278 | struct nl_addr *nl_lladdr = NULL; | |
ed4ddb6d | 9279 | int family, addrsize; |
71103bed KP |
9280 | int res; |
9281 | ||
ed4ddb6d | 9282 | if (!ipaddr || prefixlen == 0 || !addr) |
71103bed KP |
9283 | return -EINVAL; |
9284 | ||
9285 | if (bss->br_ifindex == 0) { | |
9286 | wpa_printf(MSG_DEBUG, | |
9287 | "nl80211: bridge must be set before adding an ip neigh to it"); | |
9288 | return -1; | |
9289 | } | |
9290 | ||
9291 | if (!drv->rtnl_sk) { | |
9292 | wpa_printf(MSG_DEBUG, | |
9293 | "nl80211: nl_sock for NETLINK_ROUTE is not initialized"); | |
9294 | return -1; | |
9295 | } | |
9296 | ||
ed4ddb6d KP |
9297 | if (version == 4) { |
9298 | family = AF_INET; | |
9299 | addrsize = 4; | |
9300 | } else if (version == 6) { | |
9301 | family = AF_INET6; | |
9302 | addrsize = 16; | |
9303 | } else { | |
9304 | return -EINVAL; | |
9305 | } | |
9306 | ||
71103bed KP |
9307 | rn = rtnl_neigh_alloc(); |
9308 | if (rn == NULL) | |
9309 | return -ENOMEM; | |
9310 | ||
9311 | /* set the destination ip address for neigh */ | |
ed4ddb6d | 9312 | nl_ipaddr = nl_addr_build(family, (void *) ipaddr, addrsize); |
71103bed KP |
9313 | if (nl_ipaddr == NULL) { |
9314 | wpa_printf(MSG_DEBUG, "nl80211: nl_ipaddr build failed"); | |
9315 | res = -ENOMEM; | |
9316 | goto errout; | |
9317 | } | |
9318 | nl_addr_set_prefixlen(nl_ipaddr, prefixlen); | |
9319 | res = rtnl_neigh_set_dst(rn, nl_ipaddr); | |
9320 | if (res) { | |
9321 | wpa_printf(MSG_DEBUG, | |
9322 | "nl80211: neigh set destination addr failed"); | |
9323 | goto errout; | |
9324 | } | |
9325 | ||
9326 | /* set the corresponding lladdr for neigh */ | |
9327 | nl_lladdr = nl_addr_build(AF_BRIDGE, (u8 *) addr, ETH_ALEN); | |
9328 | if (nl_lladdr == NULL) { | |
9329 | wpa_printf(MSG_DEBUG, "nl80211: neigh set lladdr failed"); | |
9330 | res = -ENOMEM; | |
9331 | goto errout; | |
9332 | } | |
9333 | rtnl_neigh_set_lladdr(rn, nl_lladdr); | |
9334 | ||
9335 | rtnl_neigh_set_ifindex(rn, bss->br_ifindex); | |
9336 | rtnl_neigh_set_state(rn, NUD_PERMANENT); | |
9337 | ||
9338 | res = rtnl_neigh_add(drv->rtnl_sk, rn, NLM_F_CREATE); | |
9339 | if (res) { | |
9340 | wpa_printf(MSG_DEBUG, | |
9341 | "nl80211: Adding bridge ip neigh failed: %s", | |
9342 | strerror(errno)); | |
9343 | } | |
9344 | errout: | |
9345 | if (nl_lladdr) | |
9346 | nl_addr_put(nl_lladdr); | |
9347 | if (nl_ipaddr) | |
9348 | nl_addr_put(nl_ipaddr); | |
9349 | if (rn) | |
9350 | rtnl_neigh_put(rn); | |
9351 | return res; | |
9352 | #else /* CONFIG_LIBNL3_ROUTE */ | |
9353 | return -1; | |
9354 | #endif /* CONFIG_LIBNL3_ROUTE */ | |
9355 | } | |
9356 | ||
9357 | ||
ed4ddb6d KP |
9358 | static int wpa_driver_br_delete_ip_neigh(void *priv, u8 version, |
9359 | const u8 *ipaddr) | |
71103bed KP |
9360 | { |
9361 | #ifdef CONFIG_LIBNL3_ROUTE | |
9362 | struct i802_bss *bss = priv; | |
9363 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
9364 | struct rtnl_neigh *rn; | |
9365 | struct nl_addr *nl_ipaddr; | |
ed4ddb6d | 9366 | int family, addrsize; |
71103bed KP |
9367 | int res; |
9368 | ||
ed4ddb6d | 9369 | if (!ipaddr) |
71103bed KP |
9370 | return -EINVAL; |
9371 | ||
ed4ddb6d KP |
9372 | if (version == 4) { |
9373 | family = AF_INET; | |
9374 | addrsize = 4; | |
9375 | } else if (version == 6) { | |
9376 | family = AF_INET6; | |
9377 | addrsize = 16; | |
9378 | } else { | |
9379 | return -EINVAL; | |
9380 | } | |
9381 | ||
71103bed KP |
9382 | if (bss->br_ifindex == 0) { |
9383 | wpa_printf(MSG_DEBUG, | |
9384 | "nl80211: bridge must be set to delete an ip neigh"); | |
9385 | return -1; | |
9386 | } | |
9387 | ||
9388 | if (!drv->rtnl_sk) { | |
9389 | wpa_printf(MSG_DEBUG, | |
9390 | "nl80211: nl_sock for NETLINK_ROUTE is not initialized"); | |
9391 | return -1; | |
9392 | } | |
9393 | ||
9394 | rn = rtnl_neigh_alloc(); | |
9395 | if (rn == NULL) | |
9396 | return -ENOMEM; | |
9397 | ||
9398 | /* set the destination ip address for neigh */ | |
ed4ddb6d | 9399 | nl_ipaddr = nl_addr_build(family, (void *) ipaddr, addrsize); |
71103bed KP |
9400 | if (nl_ipaddr == NULL) { |
9401 | wpa_printf(MSG_DEBUG, "nl80211: nl_ipaddr build failed"); | |
9402 | res = -ENOMEM; | |
9403 | goto errout; | |
9404 | } | |
9405 | res = rtnl_neigh_set_dst(rn, nl_ipaddr); | |
9406 | if (res) { | |
9407 | wpa_printf(MSG_DEBUG, | |
9408 | "nl80211: neigh set destination addr failed"); | |
9409 | goto errout; | |
9410 | } | |
9411 | ||
9412 | rtnl_neigh_set_ifindex(rn, bss->br_ifindex); | |
9413 | ||
9414 | res = rtnl_neigh_delete(drv->rtnl_sk, rn, 0); | |
9415 | if (res) { | |
9416 | wpa_printf(MSG_DEBUG, | |
9417 | "nl80211: Deleting bridge ip neigh failed: %s", | |
9418 | strerror(errno)); | |
9419 | } | |
9420 | errout: | |
9421 | if (nl_ipaddr) | |
9422 | nl_addr_put(nl_ipaddr); | |
9423 | if (rn) | |
9424 | rtnl_neigh_put(rn); | |
9425 | return res; | |
9426 | #else /* CONFIG_LIBNL3_ROUTE */ | |
9427 | return -1; | |
9428 | #endif /* CONFIG_LIBNL3_ROUTE */ | |
9429 | } | |
9430 | ||
9431 | ||
73d2294f KP |
9432 | static int linux_write_system_file(const char *path, unsigned int val) |
9433 | { | |
9434 | char buf[50]; | |
9435 | int fd, len; | |
9436 | ||
9437 | len = os_snprintf(buf, sizeof(buf), "%u\n", val); | |
a9aaacbb | 9438 | if (os_snprintf_error(sizeof(buf), len)) |
73d2294f KP |
9439 | return -1; |
9440 | ||
9441 | fd = open(path, O_WRONLY); | |
9442 | if (fd < 0) | |
9443 | return -1; | |
9444 | ||
9445 | if (write(fd, buf, len) < 0) { | |
9446 | wpa_printf(MSG_DEBUG, | |
9447 | "nl80211: Failed to write Linux system file: %s with the value of %d", | |
9448 | path, val); | |
9449 | close(fd); | |
9450 | return -1; | |
9451 | } | |
9452 | close(fd); | |
9453 | ||
9454 | return 0; | |
9455 | } | |
9456 | ||
9457 | ||
9458 | static const char * drv_br_port_attr_str(enum drv_br_port_attr attr) | |
9459 | { | |
9460 | switch (attr) { | |
9461 | case DRV_BR_PORT_ATTR_PROXYARP: | |
bea8d9a3 | 9462 | return "proxyarp_wifi"; |
73d2294f KP |
9463 | case DRV_BR_PORT_ATTR_HAIRPIN_MODE: |
9464 | return "hairpin_mode"; | |
9465 | } | |
9466 | ||
9467 | return NULL; | |
9468 | } | |
9469 | ||
9470 | ||
9471 | static int wpa_driver_br_port_set_attr(void *priv, enum drv_br_port_attr attr, | |
9472 | unsigned int val) | |
9473 | { | |
9474 | struct i802_bss *bss = priv; | |
9475 | char path[128]; | |
9476 | const char *attr_txt; | |
9477 | ||
9478 | attr_txt = drv_br_port_attr_str(attr); | |
9479 | if (attr_txt == NULL) | |
9480 | return -EINVAL; | |
9481 | ||
9482 | os_snprintf(path, sizeof(path), "/sys/class/net/%s/brport/%s", | |
9483 | bss->ifname, attr_txt); | |
9484 | ||
9485 | if (linux_write_system_file(path, val)) | |
9486 | return -1; | |
9487 | ||
9488 | return 0; | |
9489 | } | |
9490 | ||
9491 | ||
7565752d KP |
9492 | static const char * drv_br_net_param_str(enum drv_br_net_param param) |
9493 | { | |
9494 | switch (param) { | |
9495 | case DRV_BR_NET_PARAM_GARP_ACCEPT: | |
9496 | return "arp_accept"; | |
60eb9e17 JM |
9497 | default: |
9498 | return NULL; | |
7565752d | 9499 | } |
7565752d KP |
9500 | } |
9501 | ||
9502 | ||
9503 | static int wpa_driver_br_set_net_param(void *priv, enum drv_br_net_param param, | |
9504 | unsigned int val) | |
9505 | { | |
9506 | struct i802_bss *bss = priv; | |
9507 | char path[128]; | |
9508 | const char *param_txt; | |
9509 | int ip_version = 4; | |
9510 | ||
60eb9e17 JM |
9511 | if (param == DRV_BR_MULTICAST_SNOOPING) { |
9512 | os_snprintf(path, sizeof(path), | |
9513 | "/sys/devices/virtual/net/%s/bridge/multicast_snooping", | |
9514 | bss->brname); | |
9515 | goto set_val; | |
9516 | } | |
9517 | ||
7565752d KP |
9518 | param_txt = drv_br_net_param_str(param); |
9519 | if (param_txt == NULL) | |
9520 | return -EINVAL; | |
9521 | ||
9522 | switch (param) { | |
9523 | case DRV_BR_NET_PARAM_GARP_ACCEPT: | |
9524 | ip_version = 4; | |
9525 | break; | |
9526 | default: | |
9527 | return -EINVAL; | |
9528 | } | |
9529 | ||
9530 | os_snprintf(path, sizeof(path), "/proc/sys/net/ipv%d/conf/%s/%s", | |
9531 | ip_version, bss->brname, param_txt); | |
9532 | ||
60eb9e17 | 9533 | set_val: |
7565752d KP |
9534 | if (linux_write_system_file(path, val)) |
9535 | return -1; | |
9536 | ||
9537 | return 0; | |
9538 | } | |
9539 | ||
9540 | ||
b658547d JM |
9541 | #ifdef CONFIG_DRIVER_NL80211_QCA |
9542 | ||
16689c7c PX |
9543 | static int hw_mode_to_qca_acs(enum hostapd_hw_mode hw_mode) |
9544 | { | |
9545 | switch (hw_mode) { | |
9546 | case HOSTAPD_MODE_IEEE80211B: | |
9547 | return QCA_ACS_MODE_IEEE80211B; | |
9548 | case HOSTAPD_MODE_IEEE80211G: | |
9549 | return QCA_ACS_MODE_IEEE80211G; | |
9550 | case HOSTAPD_MODE_IEEE80211A: | |
9551 | return QCA_ACS_MODE_IEEE80211A; | |
9552 | case HOSTAPD_MODE_IEEE80211AD: | |
9553 | return QCA_ACS_MODE_IEEE80211AD; | |
3784c058 PX |
9554 | case HOSTAPD_MODE_IEEE80211ANY: |
9555 | return QCA_ACS_MODE_IEEE80211ANY; | |
16689c7c PX |
9556 | default: |
9557 | return -1; | |
9558 | } | |
9559 | } | |
9560 | ||
9561 | ||
d0cdccd3 PX |
9562 | static int add_acs_freq_list(struct nl_msg *msg, const int *freq_list) |
9563 | { | |
9564 | int i, len, ret; | |
9565 | u32 *freqs; | |
9566 | ||
9567 | if (!freq_list) | |
9568 | return 0; | |
9569 | len = int_array_len(freq_list); | |
9570 | freqs = os_malloc(sizeof(u32) * len); | |
9571 | if (!freqs) | |
9572 | return -1; | |
9573 | for (i = 0; i < len; i++) | |
9574 | freqs[i] = freq_list[i]; | |
9575 | ret = nla_put(msg, QCA_WLAN_VENDOR_ATTR_ACS_FREQ_LIST, | |
9576 | sizeof(u32) * len, freqs); | |
9577 | os_free(freqs); | |
9578 | return ret; | |
9579 | } | |
9580 | ||
9581 | ||
16689c7c PX |
9582 | static int wpa_driver_do_acs(void *priv, struct drv_acs_params *params) |
9583 | { | |
9584 | struct i802_bss *bss = priv; | |
9585 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
9586 | struct nl_msg *msg; | |
9587 | struct nlattr *data; | |
a862e4a3 | 9588 | int ret; |
16689c7c PX |
9589 | int mode; |
9590 | ||
9591 | mode = hw_mode_to_qca_acs(params->hw_mode); | |
9592 | if (mode < 0) | |
9593 | return -1; | |
9594 | ||
9725b784 | 9595 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_VENDOR)) || |
a862e4a3 JM |
9596 | nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) || |
9597 | nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD, | |
9598 | QCA_NL80211_VENDOR_SUBCMD_DO_ACS) || | |
9599 | !(data = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) || | |
9600 | nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_ACS_HW_MODE, mode) || | |
9601 | (params->ht_enabled && | |
9602 | nla_put_flag(msg, QCA_WLAN_VENDOR_ATTR_ACS_HT_ENABLED)) || | |
9603 | (params->ht40_enabled && | |
857d9422 MM |
9604 | nla_put_flag(msg, QCA_WLAN_VENDOR_ATTR_ACS_HT40_ENABLED)) || |
9605 | (params->vht_enabled && | |
9606 | nla_put_flag(msg, QCA_WLAN_VENDOR_ATTR_ACS_VHT_ENABLED)) || | |
9607 | nla_put_u16(msg, QCA_WLAN_VENDOR_ATTR_ACS_CHWIDTH, | |
9608 | params->ch_width) || | |
9609 | (params->ch_list_len && | |
9610 | nla_put(msg, QCA_WLAN_VENDOR_ATTR_ACS_CH_LIST, params->ch_list_len, | |
d0cdccd3 PX |
9611 | params->ch_list)) || |
9612 | add_acs_freq_list(msg, params->freq_list)) { | |
a862e4a3 JM |
9613 | nlmsg_free(msg); |
9614 | return -ENOBUFS; | |
9615 | } | |
16689c7c PX |
9616 | nla_nest_end(msg, data); |
9617 | ||
857d9422 MM |
9618 | wpa_printf(MSG_DEBUG, |
9619 | "nl80211: ACS Params: HW_MODE: %d HT: %d HT40: %d VHT: %d BW: %d CH_LIST_LEN: %u", | |
9620 | params->hw_mode, params->ht_enabled, params->ht40_enabled, | |
9621 | params->vht_enabled, params->ch_width, params->ch_list_len); | |
9622 | ||
16689c7c | 9623 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
16689c7c PX |
9624 | if (ret) { |
9625 | wpa_printf(MSG_DEBUG, | |
9626 | "nl80211: Failed to invoke driver ACS function: %s", | |
9627 | strerror(errno)); | |
9628 | } | |
16689c7c PX |
9629 | return ret; |
9630 | } | |
9631 | ||
9632 | ||
844dfeb8 SD |
9633 | static int nl80211_set_band(void *priv, enum set_band band) |
9634 | { | |
9635 | struct i802_bss *bss = priv; | |
9636 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
9637 | struct nl_msg *msg; | |
9638 | struct nlattr *data; | |
9639 | int ret; | |
9640 | enum qca_set_band qca_band; | |
9641 | ||
9642 | if (!drv->setband_vendor_cmd_avail) | |
9643 | return -1; | |
9644 | ||
9645 | switch (band) { | |
9646 | case WPA_SETBAND_AUTO: | |
9647 | qca_band = QCA_SETBAND_AUTO; | |
9648 | break; | |
9649 | case WPA_SETBAND_5G: | |
9650 | qca_band = QCA_SETBAND_5G; | |
9651 | break; | |
9652 | case WPA_SETBAND_2G: | |
9653 | qca_band = QCA_SETBAND_2G; | |
9654 | break; | |
9655 | default: | |
9656 | return -1; | |
9657 | } | |
9658 | ||
9659 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_VENDOR)) || | |
9660 | nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) || | |
9661 | nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD, | |
9662 | QCA_NL80211_VENDOR_SUBCMD_SETBAND) || | |
9663 | !(data = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) || | |
9664 | nla_put_u32(msg, QCA_WLAN_VENDOR_ATTR_SETBAND_VALUE, qca_band)) { | |
9665 | nlmsg_free(msg); | |
9666 | return -ENOBUFS; | |
9667 | } | |
9668 | nla_nest_end(msg, data); | |
9669 | ||
9670 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); | |
9671 | if (ret) { | |
9672 | wpa_printf(MSG_DEBUG, | |
9673 | "nl80211: Driver setband function failed: %s", | |
9674 | strerror(errno)); | |
9675 | } | |
9676 | return ret; | |
9677 | } | |
9678 | ||
9679 | ||
98342208 AK |
9680 | struct nl80211_pcl { |
9681 | unsigned int num; | |
9682 | unsigned int *freq_list; | |
9683 | }; | |
9684 | ||
9685 | static int preferred_freq_info_handler(struct nl_msg *msg, void *arg) | |
9686 | { | |
9687 | struct nlattr *tb[NL80211_ATTR_MAX + 1]; | |
9688 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); | |
9689 | struct nl80211_pcl *param = arg; | |
9690 | struct nlattr *nl_vend, *attr; | |
9691 | enum qca_iface_type iface_type; | |
9692 | struct nlattr *tb_vendor[QCA_WLAN_VENDOR_ATTR_MAX + 1]; | |
9693 | unsigned int num, max_num; | |
9694 | u32 *freqs; | |
9695 | ||
9696 | nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), | |
9697 | genlmsg_attrlen(gnlh, 0), NULL); | |
9698 | ||
9699 | nl_vend = tb[NL80211_ATTR_VENDOR_DATA]; | |
9700 | if (!nl_vend) | |
9701 | return NL_SKIP; | |
9702 | ||
9703 | nla_parse(tb_vendor, QCA_WLAN_VENDOR_ATTR_MAX, | |
9704 | nla_data(nl_vend), nla_len(nl_vend), NULL); | |
9705 | ||
9706 | attr = tb_vendor[ | |
9707 | QCA_WLAN_VENDOR_ATTR_GET_PREFERRED_FREQ_LIST_IFACE_TYPE]; | |
9708 | if (!attr) { | |
9709 | wpa_printf(MSG_ERROR, "nl80211: iface_type couldn't be found"); | |
9710 | param->num = 0; | |
9711 | return NL_SKIP; | |
9712 | } | |
9713 | ||
9714 | iface_type = (enum qca_iface_type) nla_get_u32(attr); | |
9715 | wpa_printf(MSG_DEBUG, "nl80211: Driver returned iface_type=%d", | |
9716 | iface_type); | |
9717 | ||
9718 | attr = tb_vendor[QCA_WLAN_VENDOR_ATTR_GET_PREFERRED_FREQ_LIST]; | |
9719 | if (!attr) { | |
9720 | wpa_printf(MSG_ERROR, | |
9721 | "nl80211: preferred_freq_list couldn't be found"); | |
9722 | param->num = 0; | |
9723 | return NL_SKIP; | |
9724 | } | |
9725 | ||
9726 | /* | |
9727 | * param->num has the maximum number of entries for which there | |
9728 | * is room in the freq_list provided by the caller. | |
9729 | */ | |
9730 | freqs = nla_data(attr); | |
9731 | max_num = nla_len(attr) / sizeof(u32); | |
9732 | if (max_num > param->num) | |
9733 | max_num = param->num; | |
9734 | for (num = 0; num < max_num; num++) | |
9735 | param->freq_list[num] = freqs[num]; | |
9736 | param->num = num; | |
9737 | ||
9738 | return NL_SKIP; | |
9739 | } | |
9740 | ||
9741 | ||
9742 | static int nl80211_get_pref_freq_list(void *priv, | |
9743 | enum wpa_driver_if_type if_type, | |
9744 | unsigned int *num, | |
9745 | unsigned int *freq_list) | |
9746 | { | |
9747 | struct i802_bss *bss = priv; | |
9748 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
9749 | struct nl_msg *msg; | |
9750 | int ret; | |
9751 | unsigned int i; | |
9752 | struct nlattr *params; | |
9753 | struct nl80211_pcl param; | |
9754 | enum qca_iface_type iface_type; | |
9755 | ||
9756 | if (!drv->get_pref_freq_list) | |
9757 | return -1; | |
9758 | ||
9759 | switch (if_type) { | |
9760 | case WPA_IF_STATION: | |
9761 | iface_type = QCA_IFACE_TYPE_STA; | |
9762 | break; | |
9763 | case WPA_IF_AP_BSS: | |
9764 | iface_type = QCA_IFACE_TYPE_AP; | |
9765 | break; | |
9766 | case WPA_IF_P2P_GO: | |
9767 | iface_type = QCA_IFACE_TYPE_P2P_GO; | |
9768 | break; | |
9769 | case WPA_IF_P2P_CLIENT: | |
9770 | iface_type = QCA_IFACE_TYPE_P2P_CLIENT; | |
9771 | break; | |
9772 | case WPA_IF_IBSS: | |
9773 | iface_type = QCA_IFACE_TYPE_IBSS; | |
9774 | break; | |
9775 | case WPA_IF_TDLS: | |
9776 | iface_type = QCA_IFACE_TYPE_TDLS; | |
9777 | break; | |
9778 | default: | |
9779 | return -1; | |
9780 | } | |
9781 | ||
9782 | param.num = *num; | |
9783 | param.freq_list = freq_list; | |
9784 | ||
9785 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_VENDOR)) || | |
9786 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, drv->ifindex) || | |
9787 | nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) || | |
9788 | nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD, | |
9789 | QCA_NL80211_VENDOR_SUBCMD_GET_PREFERRED_FREQ_LIST) || | |
9790 | !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) || | |
9791 | nla_put_u32(msg, | |
9792 | QCA_WLAN_VENDOR_ATTR_GET_PREFERRED_FREQ_LIST_IFACE_TYPE, | |
9793 | iface_type)) { | |
9794 | wpa_printf(MSG_ERROR, | |
9795 | "%s: err in adding vendor_cmd and vendor_data", | |
9796 | __func__); | |
9797 | nlmsg_free(msg); | |
9798 | return -1; | |
9799 | } | |
9800 | nla_nest_end(msg, params); | |
9801 | ||
9802 | os_memset(freq_list, 0, *num * sizeof(freq_list[0])); | |
9803 | ret = send_and_recv_msgs(drv, msg, preferred_freq_info_handler, ¶m); | |
9804 | if (ret) { | |
9805 | wpa_printf(MSG_ERROR, | |
9806 | "%s: err in send_and_recv_msgs", __func__); | |
9807 | return ret; | |
9808 | } | |
9809 | ||
9810 | *num = param.num; | |
9811 | ||
9812 | for (i = 0; i < *num; i++) { | |
9813 | wpa_printf(MSG_DEBUG, "nl80211: preferred_channel_list[%d]=%d", | |
9814 | i, freq_list[i]); | |
9815 | } | |
9816 | ||
9817 | return 0; | |
9818 | } | |
9819 | ||
9820 | ||
7c813acf AK |
9821 | static int nl80211_set_prob_oper_freq(void *priv, unsigned int freq) |
9822 | { | |
9823 | struct i802_bss *bss = priv; | |
9824 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
9825 | struct nl_msg *msg; | |
9826 | int ret; | |
9827 | struct nlattr *params; | |
9828 | ||
9829 | if (!drv->set_prob_oper_freq) | |
9830 | return -1; | |
9831 | ||
9832 | wpa_printf(MSG_DEBUG, | |
9833 | "nl80211: Set P2P probable operating freq %u for ifindex %d", | |
9834 | freq, bss->ifindex); | |
9835 | ||
9836 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_VENDOR)) || | |
9837 | nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) || | |
9838 | nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD, | |
9839 | QCA_NL80211_VENDOR_SUBCMD_SET_PROBABLE_OPER_CHANNEL) || | |
9840 | !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) || | |
9841 | nla_put_u32(msg, | |
9842 | QCA_WLAN_VENDOR_ATTR_PROBABLE_OPER_CHANNEL_IFACE_TYPE, | |
9843 | QCA_IFACE_TYPE_P2P_CLIENT) || | |
9844 | nla_put_u32(msg, | |
9845 | QCA_WLAN_VENDOR_ATTR_PROBABLE_OPER_CHANNEL_FREQ, | |
9846 | freq)) { | |
9847 | wpa_printf(MSG_ERROR, | |
9848 | "%s: err in adding vendor_cmd and vendor_data", | |
9849 | __func__); | |
9850 | nlmsg_free(msg); | |
9851 | return -1; | |
9852 | } | |
9853 | nla_nest_end(msg, params); | |
9854 | ||
9855 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); | |
9856 | msg = NULL; | |
9857 | if (ret) { | |
9858 | wpa_printf(MSG_ERROR, "%s: err in send_and_recv_msgs", | |
9859 | __func__); | |
9860 | return ret; | |
9861 | } | |
9862 | nlmsg_free(msg); | |
9863 | return 0; | |
9864 | } | |
9865 | ||
a6f5b193 PX |
9866 | |
9867 | static int nl80211_p2p_lo_start(void *priv, unsigned int freq, | |
9868 | unsigned int period, unsigned int interval, | |
9869 | unsigned int count, const u8 *device_types, | |
9870 | size_t dev_types_len, | |
9871 | const u8 *ies, size_t ies_len) | |
9872 | { | |
9873 | struct i802_bss *bss = priv; | |
9874 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
9875 | struct nl_msg *msg; | |
9876 | struct nlattr *container; | |
9877 | int ret; | |
9878 | ||
9879 | wpa_printf(MSG_DEBUG, | |
9880 | "nl80211: Start P2P Listen offload: freq=%u, period=%u, interval=%u, count=%u", | |
9881 | freq, period, interval, count); | |
9882 | ||
9883 | if (!(drv->capa.flags & WPA_DRIVER_FLAGS_P2P_LISTEN_OFFLOAD)) | |
9884 | return -1; | |
9885 | ||
9886 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_VENDOR)) || | |
9887 | nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) || | |
9888 | nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD, | |
9889 | QCA_NL80211_VENDOR_SUBCMD_P2P_LISTEN_OFFLOAD_START)) | |
9890 | goto fail; | |
9891 | ||
9892 | container = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA); | |
9893 | if (!container) | |
9894 | goto fail; | |
9895 | ||
9896 | if (nla_put_u32(msg, QCA_WLAN_VENDOR_ATTR_P2P_LISTEN_OFFLOAD_CHANNEL, | |
9897 | freq) || | |
9898 | nla_put_u32(msg, QCA_WLAN_VENDOR_ATTR_P2P_LISTEN_OFFLOAD_PERIOD, | |
9899 | period) || | |
9900 | nla_put_u32(msg, QCA_WLAN_VENDOR_ATTR_P2P_LISTEN_OFFLOAD_INTERVAL, | |
9901 | interval) || | |
9902 | nla_put_u32(msg, QCA_WLAN_VENDOR_ATTR_P2P_LISTEN_OFFLOAD_COUNT, | |
9903 | count) || | |
9904 | nla_put(msg, QCA_WLAN_VENDOR_ATTR_P2P_LISTEN_OFFLOAD_DEVICE_TYPES, | |
9905 | dev_types_len, device_types) || | |
9906 | nla_put(msg, QCA_WLAN_VENDOR_ATTR_P2P_LISTEN_OFFLOAD_VENDOR_IE, | |
9907 | ies_len, ies)) | |
9908 | goto fail; | |
9909 | ||
9910 | nla_nest_end(msg, container); | |
9911 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); | |
9912 | msg = NULL; | |
9913 | if (ret) { | |
9914 | wpa_printf(MSG_DEBUG, | |
9915 | "nl80211: Failed to send P2P Listen offload vendor command"); | |
9916 | goto fail; | |
9917 | } | |
9918 | ||
9919 | return 0; | |
9920 | ||
9921 | fail: | |
9922 | nlmsg_free(msg); | |
9923 | return -1; | |
9924 | } | |
9925 | ||
9926 | ||
9927 | static int nl80211_p2p_lo_stop(void *priv) | |
9928 | { | |
9929 | struct i802_bss *bss = priv; | |
9930 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
9931 | struct nl_msg *msg; | |
9932 | ||
9933 | wpa_printf(MSG_DEBUG, "nl80211: Stop P2P Listen offload"); | |
9934 | ||
9935 | if (!(drv->capa.flags & WPA_DRIVER_FLAGS_P2P_LISTEN_OFFLOAD)) | |
9936 | return -1; | |
9937 | ||
9938 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_VENDOR)) || | |
9939 | nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) || | |
9940 | nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD, | |
9941 | QCA_NL80211_VENDOR_SUBCMD_P2P_LISTEN_OFFLOAD_STOP)) { | |
9942 | nlmsg_free(msg); | |
9943 | return -1; | |
9944 | } | |
9945 | ||
9946 | return send_and_recv_msgs(drv, msg, NULL, NULL); | |
9947 | } | |
9948 | ||
2e4e4fb7 SD |
9949 | |
9950 | static int nl80211_set_tdls_mode(void *priv, int tdls_external_control) | |
9951 | { | |
9952 | struct i802_bss *bss = priv; | |
9953 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
9954 | struct nl_msg *msg; | |
9955 | struct nlattr *params; | |
9956 | int ret; | |
9957 | u32 tdls_mode; | |
9958 | ||
9959 | wpa_printf(MSG_DEBUG, | |
9960 | "nl80211: Set TDKS mode: tdls_external_control=%d", | |
9961 | tdls_external_control); | |
9962 | ||
9963 | if (tdls_external_control == 1) | |
9964 | tdls_mode = QCA_WLAN_VENDOR_TDLS_TRIGGER_MODE_IMPLICIT | | |
9965 | QCA_WLAN_VENDOR_TDLS_TRIGGER_MODE_EXTERNAL; | |
9966 | else | |
9967 | tdls_mode = QCA_WLAN_VENDOR_TDLS_TRIGGER_MODE_EXPLICIT; | |
9968 | ||
9969 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_VENDOR)) || | |
9970 | nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) || | |
9971 | nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD, | |
9972 | QCA_NL80211_VENDOR_SUBCMD_CONFIGURE_TDLS)) | |
9973 | goto fail; | |
9974 | ||
9975 | params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA); | |
9976 | if (!params) | |
9977 | goto fail; | |
9978 | ||
9979 | if (nla_put_u32(msg, QCA_WLAN_VENDOR_ATTR_TDLS_CONFIG_TRIGGER_MODE, | |
9980 | tdls_mode)) | |
9981 | goto fail; | |
9982 | ||
9983 | nla_nest_end(msg, params); | |
9984 | ||
9985 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); | |
9986 | msg = NULL; | |
9987 | if (ret) { | |
9988 | wpa_printf(MSG_ERROR, | |
9989 | "nl80211: Set TDLS mode failed: ret=%d (%s)", | |
9990 | ret, strerror(-ret)); | |
9991 | goto fail; | |
9992 | } | |
9993 | return 0; | |
9994 | fail: | |
9995 | nlmsg_free(msg); | |
9996 | return -1; | |
9997 | } | |
9998 | ||
3ab48492 KV |
9999 | |
10000 | #ifdef CONFIG_MBO | |
10001 | ||
10002 | static enum mbo_transition_reject_reason | |
10003 | nl80211_mbo_reject_reason_mapping(enum qca_wlan_btm_candidate_status status) | |
10004 | { | |
10005 | switch (status) { | |
10006 | case QCA_STATUS_REJECT_EXCESSIVE_FRAME_LOSS_EXPECTED: | |
10007 | return MBO_TRANSITION_REJECT_REASON_FRAME_LOSS; | |
10008 | case QCA_STATUS_REJECT_EXCESSIVE_DELAY_EXPECTED: | |
10009 | return MBO_TRANSITION_REJECT_REASON_DELAY; | |
10010 | case QCA_STATUS_REJECT_INSUFFICIENT_QOS_CAPACITY: | |
10011 | return MBO_TRANSITION_REJECT_REASON_QOS_CAPACITY; | |
10012 | case QCA_STATUS_REJECT_LOW_RSSI: | |
10013 | return MBO_TRANSITION_REJECT_REASON_RSSI; | |
10014 | case QCA_STATUS_REJECT_HIGH_INTERFERENCE: | |
10015 | return MBO_TRANSITION_REJECT_REASON_INTERFERENCE; | |
10016 | case QCA_STATUS_REJECT_UNKNOWN: | |
10017 | default: | |
10018 | return MBO_TRANSITION_REJECT_REASON_UNSPECIFIED; | |
10019 | } | |
10020 | } | |
10021 | ||
10022 | ||
10023 | static void nl80211_parse_btm_candidate_info(struct candidate_list *candidate, | |
10024 | struct nlattr *tb[], int num) | |
10025 | { | |
10026 | enum qca_wlan_btm_candidate_status status; | |
10027 | char buf[50]; | |
10028 | ||
10029 | os_memcpy(candidate->bssid, | |
10030 | nla_data(tb[QCA_WLAN_VENDOR_ATTR_BTM_CANDIDATE_INFO_BSSID]), | |
10031 | ETH_ALEN); | |
10032 | ||
10033 | status = nla_get_u32( | |
10034 | tb[QCA_WLAN_VENDOR_ATTR_BTM_CANDIDATE_INFO_STATUS]); | |
10035 | candidate->is_accept = status == QCA_STATUS_ACCEPT; | |
10036 | candidate->reject_reason = nl80211_mbo_reject_reason_mapping(status); | |
10037 | ||
10038 | if (candidate->is_accept) | |
10039 | os_snprintf(buf, sizeof(buf), "Accepted"); | |
10040 | else | |
10041 | os_snprintf(buf, sizeof(buf), | |
10042 | "Rejected, Reject_reason: %d", | |
10043 | candidate->reject_reason); | |
10044 | wpa_printf(MSG_DEBUG, "nl80211: BSSID[%d]: " MACSTR " %s", | |
10045 | num, MAC2STR(candidate->bssid), buf); | |
10046 | } | |
10047 | ||
10048 | ||
10049 | static int | |
10050 | nl80211_get_bss_transition_status_handler(struct nl_msg *msg, void *arg) | |
10051 | { | |
10052 | struct wpa_bss_candidate_info *info = arg; | |
10053 | struct candidate_list *candidate = info->candidates; | |
10054 | struct nlattr *tb_msg[NL80211_ATTR_MAX + 1]; | |
10055 | struct nlattr *tb_vendor[QCA_WLAN_VENDOR_ATTR_MAX + 1]; | |
10056 | struct nlattr *tb[QCA_WLAN_VENDOR_ATTR_BTM_CANDIDATE_INFO_MAX + 1]; | |
10057 | static struct nla_policy policy[ | |
10058 | QCA_WLAN_VENDOR_ATTR_BTM_CANDIDATE_INFO_MAX + 1] = { | |
10059 | [QCA_WLAN_VENDOR_ATTR_BTM_CANDIDATE_INFO_BSSID] = { | |
10060 | .minlen = ETH_ALEN | |
10061 | }, | |
10062 | [QCA_WLAN_VENDOR_ATTR_BTM_CANDIDATE_INFO_STATUS] = { | |
10063 | .type = NLA_U32, | |
10064 | }, | |
10065 | }; | |
10066 | struct nlattr *attr; | |
10067 | int rem; | |
10068 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); | |
10069 | u8 num; | |
10070 | ||
10071 | num = info->num; /* number of candidates sent to driver */ | |
10072 | info->num = 0; | |
10073 | nla_parse(tb_msg, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), | |
10074 | genlmsg_attrlen(gnlh, 0), NULL); | |
10075 | ||
10076 | if (!tb_msg[NL80211_ATTR_VENDOR_DATA] || | |
10077 | nla_parse_nested(tb_vendor, QCA_WLAN_VENDOR_ATTR_MAX, | |
10078 | tb_msg[NL80211_ATTR_VENDOR_DATA], NULL) || | |
10079 | !tb_vendor[QCA_WLAN_VENDOR_ATTR_BTM_CANDIDATE_INFO]) | |
10080 | return NL_SKIP; | |
10081 | ||
10082 | wpa_printf(MSG_DEBUG, | |
10083 | "nl80211: WNM Candidate list received from driver"); | |
10084 | nla_for_each_nested(attr, | |
10085 | tb_vendor[QCA_WLAN_VENDOR_ATTR_BTM_CANDIDATE_INFO], | |
10086 | rem) { | |
10087 | if (info->num >= num || | |
10088 | nla_parse_nested( | |
10089 | tb, QCA_WLAN_VENDOR_ATTR_BTM_CANDIDATE_INFO_MAX, | |
10090 | attr, policy) || | |
10091 | !tb[QCA_WLAN_VENDOR_ATTR_BTM_CANDIDATE_INFO_BSSID] || | |
10092 | !tb[QCA_WLAN_VENDOR_ATTR_BTM_CANDIDATE_INFO_STATUS]) | |
10093 | break; | |
10094 | ||
10095 | nl80211_parse_btm_candidate_info(candidate, tb, info->num); | |
10096 | ||
10097 | candidate++; | |
10098 | info->num++; | |
10099 | } | |
10100 | ||
10101 | return NL_SKIP; | |
10102 | } | |
10103 | ||
10104 | ||
10105 | static struct wpa_bss_candidate_info * | |
10106 | nl80211_get_bss_transition_status(void *priv, struct wpa_bss_trans_info *params) | |
10107 | { | |
10108 | struct i802_bss *bss = priv; | |
10109 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
10110 | struct nl_msg *msg; | |
10111 | struct nlattr *attr, *attr1, *attr2; | |
10112 | struct wpa_bss_candidate_info *info; | |
10113 | u8 i; | |
10114 | int ret; | |
10115 | u8 *pos; | |
10116 | ||
10117 | if (!drv->fetch_bss_trans_status) | |
10118 | return NULL; | |
10119 | ||
10120 | info = os_zalloc(sizeof(*info)); | |
10121 | if (!info) | |
10122 | return NULL; | |
10123 | /* Allocate memory for number of candidates sent to driver */ | |
10124 | info->candidates = os_calloc(params->n_candidates, | |
10125 | sizeof(*info->candidates)); | |
10126 | if (!info->candidates) { | |
10127 | os_free(info); | |
10128 | return NULL; | |
10129 | } | |
10130 | ||
10131 | /* Copy the number of candidates being sent to driver. This is used in | |
10132 | * nl80211_get_bss_transition_status_handler() to limit the number of | |
10133 | * candidates that can be populated in info->candidates and will be | |
10134 | * later overwritten with the actual number of candidates received from | |
10135 | * the driver. | |
10136 | */ | |
10137 | info->num = params->n_candidates; | |
10138 | ||
10139 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_VENDOR)) || | |
10140 | nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) || | |
10141 | nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD, | |
10142 | QCA_NL80211_VENDOR_SUBCMD_FETCH_BSS_TRANSITION_STATUS)) | |
10143 | goto fail; | |
10144 | ||
10145 | attr = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA); | |
10146 | if (!attr) | |
10147 | goto fail; | |
10148 | ||
10149 | if (nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_BTM_MBO_TRANSITION_REASON, | |
10150 | params->mbo_transition_reason)) | |
10151 | goto fail; | |
10152 | ||
10153 | attr1 = nla_nest_start(msg, QCA_WLAN_VENDOR_ATTR_BTM_CANDIDATE_INFO); | |
10154 | if (!attr1) | |
10155 | goto fail; | |
10156 | ||
10157 | wpa_printf(MSG_DEBUG, | |
10158 | "nl80211: WNM Candidate list info sending to driver: mbo_transition_reason: %d n_candidates: %d", | |
10159 | params->mbo_transition_reason, params->n_candidates); | |
10160 | pos = params->bssid; | |
10161 | for (i = 0; i < params->n_candidates; i++) { | |
10162 | wpa_printf(MSG_DEBUG, "nl80211: BSSID[%d]: " MACSTR, i, | |
10163 | MAC2STR(pos)); | |
10164 | attr2 = nla_nest_start(msg, i); | |
10165 | if (!attr2 || | |
10166 | nla_put(msg, QCA_WLAN_VENDOR_ATTR_BTM_CANDIDATE_INFO_BSSID, | |
10167 | ETH_ALEN, pos)) | |
10168 | goto fail; | |
10169 | pos += ETH_ALEN; | |
10170 | nla_nest_end(msg, attr2); | |
10171 | } | |
10172 | ||
10173 | nla_nest_end(msg, attr1); | |
10174 | nla_nest_end(msg, attr); | |
10175 | ||
10176 | ret = send_and_recv_msgs(drv, msg, | |
10177 | nl80211_get_bss_transition_status_handler, | |
10178 | info); | |
10179 | msg = NULL; | |
10180 | if (ret) { | |
10181 | wpa_printf(MSG_ERROR, | |
10182 | "nl80211: WNM Get BSS transition status failed: ret=%d (%s)", | |
10183 | ret, strerror(-ret)); | |
10184 | goto fail; | |
10185 | } | |
10186 | return info; | |
10187 | ||
10188 | fail: | |
10189 | nlmsg_free(msg); | |
10190 | os_free(info->candidates); | |
10191 | os_free(info); | |
10192 | return NULL; | |
10193 | } | |
10194 | ||
178553b7 VK |
10195 | |
10196 | /** | |
10197 | * nl80211_ignore_assoc_disallow - Configure driver to ignore assoc_disallow | |
10198 | * @priv: Pointer to private driver data from wpa_driver_nl80211_init() | |
10199 | * @ignore_assoc_disallow: 0 to not ignore, 1 to ignore | |
10200 | * Returns: 0 on success, -1 on failure | |
10201 | */ | |
10202 | static int nl80211_ignore_assoc_disallow(void *priv, int ignore_disallow) | |
10203 | { | |
10204 | struct i802_bss *bss = priv; | |
10205 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
10206 | struct nl_msg *msg; | |
10207 | struct nlattr *attr; | |
10208 | int ret = -1; | |
10209 | ||
10210 | if (!drv->set_wifi_conf_vendor_cmd_avail) | |
10211 | return -1; | |
10212 | ||
10213 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_VENDOR)) || | |
10214 | nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) || | |
10215 | nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD, | |
10216 | QCA_NL80211_VENDOR_SUBCMD_SET_WIFI_CONFIGURATION)) | |
10217 | goto fail; | |
10218 | ||
10219 | attr = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA); | |
10220 | if (!attr) | |
10221 | goto fail; | |
10222 | ||
10223 | wpa_printf(MSG_DEBUG, "nl80211: Set ignore_assoc_disallow %d", | |
10224 | ignore_disallow); | |
10225 | if (nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_CONFIG_IGNORE_ASSOC_DISALLOWED, | |
10226 | ignore_disallow)) | |
10227 | goto fail; | |
10228 | ||
10229 | nla_nest_end(msg, attr); | |
10230 | ||
10231 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); | |
10232 | msg = NULL; | |
10233 | if (ret) { | |
10234 | wpa_printf(MSG_ERROR, | |
10235 | "nl80211: Set ignore_assoc_disallow failed: ret=%d (%s)", | |
10236 | ret, strerror(-ret)); | |
10237 | goto fail; | |
10238 | } | |
10239 | ||
10240 | fail: | |
10241 | nlmsg_free(msg); | |
10242 | return ret; | |
10243 | } | |
10244 | ||
3ab48492 KV |
10245 | #endif /* CONFIG_MBO */ |
10246 | ||
b658547d JM |
10247 | #endif /* CONFIG_DRIVER_NL80211_QCA */ |
10248 | ||
7c813acf | 10249 | |
6922d440 IP |
10250 | static int nl80211_write_to_file(const char *name, unsigned int val) |
10251 | { | |
10252 | int fd, len; | |
10253 | char tmp[128]; | |
10254 | ||
10255 | fd = open(name, O_RDWR); | |
10256 | if (fd < 0) { | |
10257 | wpa_printf(MSG_ERROR, "nl80211: Failed to open %s: %s", | |
10258 | name, strerror(errno)); | |
10259 | return fd; | |
10260 | } | |
10261 | ||
10262 | len = os_snprintf(tmp, sizeof(tmp), "%u\n", val); | |
10263 | len = write(fd, tmp, len); | |
10264 | if (len < 0) | |
10265 | wpa_printf(MSG_ERROR, "nl80211: Failed to write to %s: %s", | |
10266 | name, strerror(errno)); | |
10267 | close(fd); | |
10268 | ||
10269 | return 0; | |
10270 | } | |
10271 | ||
10272 | ||
10273 | static int nl80211_configure_data_frame_filters(void *priv, u32 filter_flags) | |
10274 | { | |
10275 | struct i802_bss *bss = priv; | |
10276 | char path[128]; | |
10277 | int ret; | |
10278 | ||
10279 | wpa_printf(MSG_DEBUG, "nl80211: Data frame filter flags=0x%x", | |
10280 | filter_flags); | |
10281 | ||
10282 | /* Configure filtering of unicast frame encrypted using GTK */ | |
10283 | ret = os_snprintf(path, sizeof(path), | |
10284 | "/proc/sys/net/ipv4/conf/%s/drop_unicast_in_l2_multicast", | |
10285 | bss->ifname); | |
bd86ea08 JM |
10286 | if (os_snprintf_error(sizeof(path), ret)) |
10287 | return -1; | |
6922d440 IP |
10288 | |
10289 | ret = nl80211_write_to_file(path, | |
10290 | !!(filter_flags & | |
10291 | WPA_DATA_FRAME_FILTER_FLAG_GTK)); | |
10292 | if (ret) { | |
10293 | wpa_printf(MSG_ERROR, | |
10294 | "nl80211: Failed to set IPv4 unicast in multicast filter"); | |
10295 | return ret; | |
10296 | } | |
10297 | ||
10298 | os_snprintf(path, sizeof(path), | |
10299 | "/proc/sys/net/ipv6/conf/%s/drop_unicast_in_l2_multicast", | |
10300 | bss->ifname); | |
10301 | ret = nl80211_write_to_file(path, | |
10302 | !!(filter_flags & | |
10303 | WPA_DATA_FRAME_FILTER_FLAG_GTK)); | |
10304 | ||
10305 | if (ret) { | |
10306 | wpa_printf(MSG_ERROR, | |
10307 | "nl80211: Failed to set IPv6 unicast in multicast filter"); | |
10308 | return ret; | |
10309 | } | |
10310 | ||
10311 | /* Configure filtering of unicast frame encrypted using GTK */ | |
10312 | os_snprintf(path, sizeof(path), | |
10313 | "/proc/sys/net/ipv4/conf/%s/drop_gratuitous_arp", | |
10314 | bss->ifname); | |
10315 | ret = nl80211_write_to_file(path, | |
10316 | !!(filter_flags & | |
10317 | WPA_DATA_FRAME_FILTER_FLAG_ARP)); | |
10318 | if (ret) { | |
10319 | wpa_printf(MSG_ERROR, | |
10320 | "nl80211: Failed set gratuitous ARP filter"); | |
10321 | return ret; | |
10322 | } | |
10323 | ||
10324 | /* Configure filtering of IPv6 NA frames */ | |
10325 | os_snprintf(path, sizeof(path), | |
10326 | "/proc/sys/net/ipv6/conf/%s/drop_unsolicited_na", | |
10327 | bss->ifname); | |
10328 | ret = nl80211_write_to_file(path, | |
10329 | !!(filter_flags & | |
10330 | WPA_DATA_FRAME_FILTER_FLAG_NA)); | |
10331 | if (ret) { | |
10332 | wpa_printf(MSG_ERROR, | |
10333 | "nl80211: Failed to set unsolicited NA filter"); | |
10334 | return ret; | |
10335 | } | |
10336 | ||
10337 | return 0; | |
10338 | } | |
10339 | ||
10340 | ||
cc9a2575 KV |
10341 | static int nl80211_get_ext_capab(void *priv, enum wpa_driver_if_type type, |
10342 | const u8 **ext_capa, const u8 **ext_capa_mask, | |
10343 | unsigned int *ext_capa_len) | |
10344 | { | |
10345 | struct i802_bss *bss = priv; | |
10346 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
10347 | enum nl80211_iftype nlmode; | |
10348 | unsigned int i; | |
10349 | ||
10350 | if (!ext_capa || !ext_capa_mask || !ext_capa_len) | |
10351 | return -1; | |
10352 | ||
10353 | nlmode = wpa_driver_nl80211_if_type(type); | |
10354 | ||
10355 | /* By default, use the per-radio values */ | |
10356 | *ext_capa = drv->extended_capa; | |
10357 | *ext_capa_mask = drv->extended_capa_mask; | |
10358 | *ext_capa_len = drv->extended_capa_len; | |
10359 | ||
10360 | /* Replace the default value if a per-interface type value exists */ | |
10361 | for (i = 0; i < drv->num_iface_ext_capa; i++) { | |
10362 | if (nlmode == drv->iface_ext_capa[i].iftype) { | |
10363 | *ext_capa = drv->iface_ext_capa[i].ext_capa; | |
10364 | *ext_capa_mask = drv->iface_ext_capa[i].ext_capa_mask; | |
10365 | *ext_capa_len = drv->iface_ext_capa[i].ext_capa_len; | |
10366 | break; | |
10367 | } | |
10368 | } | |
10369 | ||
10370 | return 0; | |
10371 | } | |
10372 | ||
10373 | ||
3c67e977 VK |
10374 | static int nl80211_update_connection_params( |
10375 | void *priv, struct wpa_driver_associate_params *params, | |
10376 | enum wpa_drv_update_connect_params_mask mask) | |
10377 | { | |
10378 | struct i802_bss *bss = priv; | |
10379 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
10380 | struct nl_msg *msg; | |
10381 | int ret = -1; | |
10382 | enum nl80211_auth_type type; | |
10383 | ||
10384 | msg = nl80211_drv_msg(drv, 0, NL80211_CMD_UPDATE_CONNECT_PARAMS); | |
10385 | if (!msg) | |
10386 | goto fail; | |
10387 | ||
10388 | wpa_printf(MSG_DEBUG, "nl80211: Update connection params (ifindex=%d)", | |
10389 | drv->ifindex); | |
10390 | ||
10391 | if ((mask & WPA_DRV_UPDATE_ASSOC_IES) && params->wpa_ie) { | |
10392 | if (nla_put(msg, NL80211_ATTR_IE, params->wpa_ie_len, | |
10393 | params->wpa_ie)) | |
10394 | goto fail; | |
10395 | wpa_hexdump(MSG_DEBUG, " * IEs", params->wpa_ie, | |
10396 | params->wpa_ie_len); | |
10397 | } | |
10398 | ||
10399 | if (mask & WPA_DRV_UPDATE_AUTH_TYPE) { | |
10400 | type = get_nl_auth_type(params->auth_alg); | |
10401 | if (type == NL80211_AUTHTYPE_MAX || | |
10402 | nla_put_u32(msg, NL80211_ATTR_AUTH_TYPE, type)) | |
10403 | goto fail; | |
10404 | wpa_printf(MSG_DEBUG, " * Auth Type %d", type); | |
10405 | } | |
10406 | ||
10407 | if ((mask & WPA_DRV_UPDATE_FILS_ERP_INFO) && | |
10408 | nl80211_put_fils_connect_params(drv, params, msg)) | |
10409 | goto fail; | |
10410 | ||
10411 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); | |
10412 | msg = NULL; | |
10413 | if (ret) | |
10414 | wpa_dbg(drv->ctx, MSG_DEBUG, | |
10415 | "nl80211: Update connect params command failed: ret=%d (%s)", | |
10416 | ret, strerror(-ret)); | |
10417 | ||
10418 | fail: | |
10419 | nlmsg_free(msg); | |
10420 | return ret; | |
10421 | } | |
10422 | ||
10423 | ||
ba71cb82 SD |
10424 | static int nl80211_send_external_auth_status(void *priv, |
10425 | struct external_auth *params) | |
10426 | { | |
10427 | struct i802_bss *bss = priv; | |
10428 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
10429 | struct nl_msg *msg = NULL; | |
10430 | int ret = -1; | |
10431 | ||
10432 | wpa_dbg(drv->ctx, MSG_DEBUG, | |
10433 | "nl80211: External auth status: %u", params->status); | |
10434 | ||
10435 | msg = nl80211_drv_msg(drv, 0, NL80211_CMD_EXTERNAL_AUTH); | |
10436 | if (!msg || | |
10437 | nla_put_u16(msg, NL80211_ATTR_STATUS_CODE, params->status) || | |
10438 | nla_put(msg, NL80211_ATTR_SSID, params->ssid_len, | |
10439 | params->ssid) || | |
10440 | nla_put(msg, NL80211_ATTR_BSSID, ETH_ALEN, params->bssid)) | |
10441 | goto fail; | |
10442 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); | |
10443 | msg = NULL; | |
10444 | if (ret) { | |
10445 | wpa_printf(MSG_DEBUG, | |
10446 | "nl80211: External Auth status update failed: ret=%d (%s)", | |
10447 | ret, strerror(-ret)); | |
10448 | goto fail; | |
10449 | } | |
10450 | fail: | |
10451 | nlmsg_free(msg); | |
10452 | return ret; | |
10453 | } | |
10454 | ||
10455 | ||
3f5285e8 JM |
10456 | const struct wpa_driver_ops wpa_driver_nl80211_ops = { |
10457 | .name = "nl80211", | |
10458 | .desc = "Linux nl80211/cfg80211", | |
10459 | .get_bssid = wpa_driver_nl80211_get_bssid, | |
10460 | .get_ssid = wpa_driver_nl80211_get_ssid, | |
9ebce9c5 JM |
10461 | .set_key = driver_nl80211_set_key, |
10462 | .scan2 = driver_nl80211_scan2, | |
d21c63b9 LC |
10463 | .sched_scan = wpa_driver_nl80211_sched_scan, |
10464 | .stop_sched_scan = wpa_driver_nl80211_stop_sched_scan, | |
3f5285e8 | 10465 | .get_scan_results2 = wpa_driver_nl80211_get_scan_results, |
4f30addb | 10466 | .abort_scan = wpa_driver_nl80211_abort_scan, |
9ebce9c5 JM |
10467 | .deauthenticate = driver_nl80211_deauthenticate, |
10468 | .authenticate = driver_nl80211_authenticate, | |
3f5285e8 | 10469 | .associate = wpa_driver_nl80211_associate, |
f2ed8023 JM |
10470 | .global_init = nl80211_global_init, |
10471 | .global_deinit = nl80211_global_deinit, | |
10472 | .init2 = wpa_driver_nl80211_init, | |
9ebce9c5 | 10473 | .deinit = driver_nl80211_deinit, |
3f5285e8 JM |
10474 | .get_capa = wpa_driver_nl80211_get_capa, |
10475 | .set_operstate = wpa_driver_nl80211_set_operstate, | |
01652550 | 10476 | .set_supp_port = wpa_driver_nl80211_set_supp_port, |
6d158490 | 10477 | .set_country = wpa_driver_nl80211_set_country, |
f0793bf1 | 10478 | .get_country = wpa_driver_nl80211_get_country, |
19c3b566 | 10479 | .set_ap = wpa_driver_nl80211_set_ap, |
3c4ca363 | 10480 | .set_acl = wpa_driver_nl80211_set_acl, |
22a7c9d7 | 10481 | .if_add = wpa_driver_nl80211_if_add, |
9ebce9c5 JM |
10482 | .if_remove = driver_nl80211_if_remove, |
10483 | .send_mlme = driver_nl80211_send_mlme, | |
0fafeb54 | 10484 | .get_hw_feature_data = nl80211_get_hw_feature_data, |
0f4e8b4f | 10485 | .sta_add = wpa_driver_nl80211_sta_add, |
9ebce9c5 | 10486 | .sta_remove = driver_nl80211_sta_remove, |
db149ac9 | 10487 | .hapd_send_eapol = wpa_driver_nl80211_hapd_send_eapol, |
a8d6ffa4 | 10488 | .sta_set_flags = wpa_driver_nl80211_sta_set_flags, |
c5121837 | 10489 | .hapd_init = i802_init, |
c5121837 | 10490 | .hapd_deinit = i802_deinit, |
f7b3920c | 10491 | .set_wds_sta = i802_set_wds_sta, |
c5121837 JM |
10492 | .get_seqnum = i802_get_seqnum, |
10493 | .flush = i802_flush, | |
c5121837 JM |
10494 | .get_inact_sec = i802_get_inact_sec, |
10495 | .sta_clear_stats = i802_sta_clear_stats, | |
c5121837 JM |
10496 | .set_rts = i802_set_rts, |
10497 | .set_frag = i802_set_frag, | |
c5121837 | 10498 | .set_tx_queue_params = i802_set_tx_queue_params, |
9ebce9c5 | 10499 | .set_sta_vlan = driver_nl80211_set_sta_vlan, |
ee7ab173 JB |
10500 | .sta_deauth = i802_sta_deauth, |
10501 | .sta_disassoc = i802_sta_disassoc, | |
9ebce9c5 | 10502 | .read_sta_data = driver_nl80211_read_sta_data, |
e3802622 | 10503 | .set_freq = i802_set_freq, |
9ebce9c5 | 10504 | .send_action = driver_nl80211_send_action, |
5dfca53f | 10505 | .send_action_cancel_wait = wpa_driver_nl80211_send_action_cancel_wait, |
55777702 JM |
10506 | .remain_on_channel = wpa_driver_nl80211_remain_on_channel, |
10507 | .cancel_remain_on_channel = | |
10508 | wpa_driver_nl80211_cancel_remain_on_channel, | |
9ebce9c5 | 10509 | .probe_req_report = driver_nl80211_probe_req_report, |
af473088 | 10510 | .deinit_ap = wpa_driver_nl80211_deinit_ap, |
3c29244e | 10511 | .deinit_p2p_cli = wpa_driver_nl80211_deinit_p2p_cli, |
207ef3fb | 10512 | .resume = wpa_driver_nl80211_resume, |
b625473c | 10513 | .signal_monitor = nl80211_signal_monitor, |
1c5c7273 | 10514 | .signal_poll = nl80211_signal_poll, |
b91ab76e | 10515 | .send_frame = nl80211_send_frame, |
c55f774d | 10516 | .set_param = nl80211_set_param, |
6859f1cb | 10517 | .get_radio_name = nl80211_get_radio_name, |
a6efc65d JM |
10518 | .add_pmkid = nl80211_add_pmkid, |
10519 | .remove_pmkid = nl80211_remove_pmkid, | |
10520 | .flush_pmkid = nl80211_flush_pmkid, | |
b14a210c | 10521 | .set_rekey_info = nl80211_set_rekey_info, |
bcf24348 | 10522 | .poll_client = nl80211_poll_client, |
29f338af | 10523 | .set_p2p_powersave = nl80211_set_p2p_powersave, |
f90e9c1c | 10524 | .start_dfs_cac = nl80211_start_radar_detection, |
695c7038 | 10525 | .stop_ap = wpa_driver_nl80211_stop_ap, |
03ea1786 AN |
10526 | #ifdef CONFIG_TDLS |
10527 | .send_tdls_mgmt = nl80211_send_tdls_mgmt, | |
10528 | .tdls_oper = nl80211_tdls_oper, | |
72b2605f AN |
10529 | .tdls_enable_channel_switch = nl80211_tdls_enable_channel_switch, |
10530 | .tdls_disable_channel_switch = nl80211_tdls_disable_channel_switch, | |
03ea1786 | 10531 | #endif /* CONFIG_TDLS */ |
6a1ce395 | 10532 | .update_ft_ies = wpa_driver_nl80211_update_ft_ies, |
597b94f5 | 10533 | .get_mac_addr = wpa_driver_nl80211_get_macaddr, |
0185007c | 10534 | .get_survey = wpa_driver_nl80211_get_survey, |
a771c07d | 10535 | .status = wpa_driver_nl80211_status, |
1c4ffa87 | 10536 | .switch_channel = nl80211_switch_channel, |
0de38036 JM |
10537 | #ifdef ANDROID_P2P |
10538 | .set_noa = wpa_driver_set_p2p_noa, | |
10539 | .get_noa = wpa_driver_get_p2p_noa, | |
10540 | .set_ap_wps_ie = wpa_driver_set_ap_wps_p2p_ie, | |
10541 | #endif /* ANDROID_P2P */ | |
5e2c3490 | 10542 | #ifdef ANDROID |
ded14ce9 | 10543 | #ifndef ANDROID_LIB_STUB |
5e2c3490 | 10544 | .driver_cmd = wpa_driver_nl80211_driver_cmd, |
ded14ce9 | 10545 | #endif /* !ANDROID_LIB_STUB */ |
5e2c3490 | 10546 | #endif /* ANDROID */ |
adef8948 | 10547 | .vendor_cmd = nl80211_vendor_cmd, |
049105b4 | 10548 | .set_qos_map = nl80211_set_qos_map, |
e4fa8b12 | 10549 | .set_wowlan = nl80211_set_wowlan, |
fee354c7 | 10550 | .set_mac_addr = nl80211_set_mac_addr, |
6c1664f6 BC |
10551 | #ifdef CONFIG_MESH |
10552 | .init_mesh = wpa_driver_nl80211_init_mesh, | |
10553 | .join_mesh = wpa_driver_nl80211_join_mesh, | |
10554 | .leave_mesh = wpa_driver_nl80211_leave_mesh, | |
10555 | #endif /* CONFIG_MESH */ | |
71103bed KP |
10556 | .br_add_ip_neigh = wpa_driver_br_add_ip_neigh, |
10557 | .br_delete_ip_neigh = wpa_driver_br_delete_ip_neigh, | |
73d2294f | 10558 | .br_port_set_attr = wpa_driver_br_port_set_attr, |
7565752d | 10559 | .br_set_net_param = wpa_driver_br_set_net_param, |
dfa87878 MB |
10560 | .add_tx_ts = nl80211_add_ts, |
10561 | .del_tx_ts = nl80211_del_ts, | |
45e3fc72 | 10562 | .get_ifindex = nl80211_get_ifindex, |
b658547d | 10563 | #ifdef CONFIG_DRIVER_NL80211_QCA |
9607a1ae | 10564 | .roaming = nl80211_roaming, |
d98038bb | 10565 | .disable_fils = nl80211_disable_fils, |
16689c7c | 10566 | .do_acs = wpa_driver_do_acs, |
844dfeb8 | 10567 | .set_band = nl80211_set_band, |
98342208 | 10568 | .get_pref_freq_list = nl80211_get_pref_freq_list, |
7c813acf | 10569 | .set_prob_oper_freq = nl80211_set_prob_oper_freq, |
a6f5b193 PX |
10570 | .p2p_lo_start = nl80211_p2p_lo_start, |
10571 | .p2p_lo_stop = nl80211_p2p_lo_stop, | |
cc9985d1 | 10572 | .set_default_scan_ies = nl80211_set_default_scan_ies, |
2e4e4fb7 | 10573 | .set_tdls_mode = nl80211_set_tdls_mode, |
3ab48492 KV |
10574 | #ifdef CONFIG_MBO |
10575 | .get_bss_transition_status = nl80211_get_bss_transition_status, | |
178553b7 | 10576 | .ignore_assoc_disallow = nl80211_ignore_assoc_disallow, |
3ab48492 | 10577 | #endif /* CONFIG_MBO */ |
b04854ce | 10578 | .set_bssid_blacklist = nl80211_set_bssid_blacklist, |
b658547d | 10579 | #endif /* CONFIG_DRIVER_NL80211_QCA */ |
6922d440 | 10580 | .configure_data_frame_filters = nl80211_configure_data_frame_filters, |
cc9a2575 | 10581 | .get_ext_capab = nl80211_get_ext_capab, |
3c67e977 | 10582 | .update_connect_params = nl80211_update_connection_params, |
ba71cb82 | 10583 | .send_external_auth_status = nl80211_send_external_auth_status, |
3f5285e8 | 10584 | }; |