]>
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 | 42 | |
b14e8ea1 JM |
43 | #ifndef NETLINK_CAP_ACK |
44 | #define NETLINK_CAP_ACK 10 | |
45 | #endif /* NETLINK_CAP_ACK */ | |
40432e6e JB |
46 | /* support for extack if compilation headers are too old */ |
47 | #ifndef NETLINK_EXT_ACK | |
48 | #define NETLINK_EXT_ACK 11 | |
49 | enum nlmsgerr_attrs { | |
50 | NLMSGERR_ATTR_UNUSED, | |
51 | NLMSGERR_ATTR_MSG, | |
52 | NLMSGERR_ATTR_OFFS, | |
53 | NLMSGERR_ATTR_COOKIE, | |
54 | ||
55 | __NLMSGERR_ATTR_MAX, | |
56 | NLMSGERR_ATTR_MAX = __NLMSGERR_ATTR_MAX - 1 | |
57 | }; | |
58 | #endif | |
59 | #ifndef NLM_F_CAPPED | |
60 | #define NLM_F_CAPPED 0x100 | |
61 | #endif | |
62 | #ifndef NLM_F_ACK_TLVS | |
63 | #define NLM_F_ACK_TLVS 0x200 | |
64 | #endif | |
65 | #ifndef SOL_NETLINK | |
66 | #define SOL_NETLINK 270 | |
67 | #endif | |
68 | ||
1474e6e9 | 69 | #ifndef CONFIG_LIBNL20 |
a65a9aed JB |
70 | /* |
71 | * libnl 1.1 has a bug, it tries to allocate socket numbers densely | |
72 | * but when you free a socket again it will mess up its bitmap and | |
73 | * and use the wrong number the next time it needs a socket ID. | |
74 | * Therefore, we wrap the handle alloc/destroy and add our own pid | |
75 | * accounting. | |
76 | */ | |
77 | static uint32_t port_bitmap[32] = { 0 }; | |
78 | ||
79 | static struct nl_handle *nl80211_handle_alloc(void *cb) | |
80 | { | |
81 | struct nl_handle *handle; | |
82 | uint32_t pid = getpid() & 0x3FFFFF; | |
83 | int i; | |
84 | ||
85 | handle = nl_handle_alloc_cb(cb); | |
86 | ||
87 | for (i = 0; i < 1024; i++) { | |
88 | if (port_bitmap[i / 32] & (1 << (i % 32))) | |
89 | continue; | |
90 | port_bitmap[i / 32] |= 1 << (i % 32); | |
91 | pid += i << 22; | |
92 | break; | |
93 | } | |
94 | ||
95 | nl_socket_set_local_port(handle, pid); | |
96 | ||
97 | return handle; | |
98 | } | |
99 | ||
100 | static void nl80211_handle_destroy(struct nl_handle *handle) | |
101 | { | |
102 | uint32_t port = nl_socket_get_local_port(handle); | |
103 | ||
104 | port >>= 22; | |
105 | port_bitmap[port / 32] &= ~(1 << (port % 32)); | |
106 | ||
107 | nl_handle_destroy(handle); | |
108 | } | |
c5121837 JM |
109 | #endif /* CONFIG_LIBNL20 */ |
110 | ||
c5121837 | 111 | |
1c6edec6 JM |
112 | #ifdef ANDROID |
113 | /* system/core/libnl_2 does not include nl_socket_set_nonblocking() */ | |
1c6edec6 JM |
114 | #undef nl_socket_set_nonblocking |
115 | #define nl_socket_set_nonblocking(h) android_nl_socket_set_nonblocking(h) | |
70a96c81 | 116 | |
1c6edec6 JM |
117 | #endif /* ANDROID */ |
118 | ||
119 | ||
481234cf | 120 | static struct nl_handle * nl_create_handle(struct nl_cb *cb, const char *dbg) |
a92dfde8 | 121 | { |
481234cf | 122 | struct nl_handle *handle; |
a92dfde8 | 123 | |
481234cf JM |
124 | handle = nl80211_handle_alloc(cb); |
125 | if (handle == NULL) { | |
a92dfde8 JB |
126 | wpa_printf(MSG_ERROR, "nl80211: Failed to allocate netlink " |
127 | "callbacks (%s)", dbg); | |
481234cf | 128 | return NULL; |
a92dfde8 JB |
129 | } |
130 | ||
481234cf | 131 | if (genl_connect(handle)) { |
a92dfde8 JB |
132 | wpa_printf(MSG_ERROR, "nl80211: Failed to connect to generic " |
133 | "netlink (%s)", dbg); | |
481234cf JM |
134 | nl80211_handle_destroy(handle); |
135 | return NULL; | |
a92dfde8 JB |
136 | } |
137 | ||
481234cf | 138 | return handle; |
a92dfde8 JB |
139 | } |
140 | ||
141 | ||
481234cf | 142 | static void nl_destroy_handles(struct nl_handle **handle) |
a92dfde8 | 143 | { |
481234cf | 144 | if (*handle == NULL) |
a92dfde8 | 145 | return; |
481234cf JM |
146 | nl80211_handle_destroy(*handle); |
147 | *handle = NULL; | |
a92dfde8 JB |
148 | } |
149 | ||
150 | ||
10b85921 JB |
151 | #if __WORDSIZE == 64 |
152 | #define ELOOP_SOCKET_INVALID (intptr_t) 0x8888888888888889ULL | |
153 | #else | |
154 | #define ELOOP_SOCKET_INVALID (intptr_t) 0x88888889ULL | |
155 | #endif | |
156 | ||
5f65e9f7 JB |
157 | static void nl80211_register_eloop_read(struct nl_handle **handle, |
158 | eloop_sock_handler handler, | |
40a68f33 | 159 | void *eloop_data, int persist) |
5f65e9f7 | 160 | { |
fa38860c | 161 | #ifdef CONFIG_LIBNL20 |
630b3230 JM |
162 | /* |
163 | * libnl uses a pretty small buffer (32 kB that gets converted to 64 kB) | |
164 | * by default. It is possible to hit that limit in some cases where | |
165 | * operations are blocked, e.g., with a burst of Deauthentication frames | |
166 | * to hostapd and STA entry deletion. Try to increase the buffer to make | |
167 | * this less likely to occur. | |
168 | */ | |
169 | if (nl_socket_set_buffer_size(*handle, 262144, 0) < 0) { | |
170 | wpa_printf(MSG_DEBUG, | |
171 | "nl80211: Could not set nl_socket RX buffer size: %s", | |
172 | strerror(errno)); | |
173 | /* continue anyway with the default (smaller) buffer */ | |
174 | } | |
fa38860c | 175 | #endif /* CONFIG_LIBNL20 */ |
630b3230 | 176 | |
10b85921 | 177 | nl_socket_set_nonblocking(*handle); |
5f65e9f7 JB |
178 | eloop_register_read_sock(nl_socket_get_fd(*handle), handler, |
179 | eloop_data, *handle); | |
40a68f33 SD |
180 | if (!persist) |
181 | *handle = (void *) (((intptr_t) *handle) ^ | |
182 | ELOOP_SOCKET_INVALID); | |
5f65e9f7 JB |
183 | } |
184 | ||
185 | ||
40a68f33 | 186 | static void nl80211_destroy_eloop_handle(struct nl_handle **handle, int persist) |
5f65e9f7 | 187 | { |
40a68f33 SD |
188 | if (!persist) |
189 | *handle = (void *) (((intptr_t) *handle) ^ | |
190 | ELOOP_SOCKET_INVALID); | |
5f65e9f7 JB |
191 | eloop_unregister_read_sock(nl_socket_get_fd(*handle)); |
192 | nl_destroy_handles(handle); | |
193 | } | |
194 | ||
195 | ||
36d84860 | 196 | static void nl80211_global_deinit(void *priv); |
f51f54a0 | 197 | static void nl80211_check_global(struct nl80211_global *global); |
36d84860 | 198 | |
9ebce9c5 | 199 | static void wpa_driver_nl80211_deinit(struct i802_bss *bss); |
4ec68377 JD |
200 | static int wpa_driver_nl80211_set_mode_ibss(struct i802_bss *bss, |
201 | struct hostapd_freq_params *freq); | |
3c5d34e3 | 202 | |
362f781e | 203 | static int |
0d547d5f | 204 | wpa_driver_nl80211_finish_drv_init(struct wpa_driver_nl80211_data *drv, |
0ecff8d7 JM |
205 | const u8 *set_addr, int first, |
206 | const char *driver_params); | |
88df0ef7 | 207 | static int nl80211_send_frame_cmd(struct i802_bss *bss, |
5dfca53f | 208 | unsigned int freq, unsigned int wait, |
b106173a | 209 | const u8 *buf, size_t buf_len, u64 *cookie, |
2d3943ce AO |
210 | int no_cck, int no_ack, int offchanok, |
211 | const u16 *csa_offs, size_t csa_offs_len); | |
9ebce9c5 JM |
212 | static int wpa_driver_nl80211_probe_req_report(struct i802_bss *bss, |
213 | int report); | |
0915d02c | 214 | |
732b1d20 MB |
215 | #define IFIDX_ANY -1 |
216 | ||
217 | static void add_ifidx(struct wpa_driver_nl80211_data *drv, int ifidx, | |
218 | int ifidx_reason); | |
219 | static void del_ifidx(struct wpa_driver_nl80211_data *drv, int ifidx, | |
220 | int ifidx_reason); | |
221 | static int have_ifidx(struct wpa_driver_nl80211_data *drv, int ifidx, | |
222 | int ifidx_reason); | |
072ad14c | 223 | |
e87ef751 PX |
224 | static int nl80211_set_channel(struct i802_bss *bss, |
225 | struct hostapd_freq_params *freq, int set_chan); | |
4e5cb1a3 JM |
226 | static int nl80211_disable_11b_rates(struct wpa_driver_nl80211_data *drv, |
227 | int ifindex, int disabled); | |
504e905c | 228 | |
666e508c JM |
229 | static int nl80211_leave_ibss(struct wpa_driver_nl80211_data *drv, |
230 | int reset_mode); | |
21bdbe38 | 231 | |
bf83eab5 | 232 | static int i802_set_iface_flags(struct i802_bss *bss, int up); |
0ecff8d7 | 233 | static int nl80211_set_param(void *priv, const char *param); |
052b8d38 MH |
234 | #ifdef CONFIG_MESH |
235 | static int nl80211_put_mesh_config(struct nl_msg *msg, | |
236 | struct wpa_driver_mesh_bss_params *params); | |
237 | #endif /* CONFIG_MESH */ | |
05e5e615 DL |
238 | static int i802_sta_disassoc(void *priv, const u8 *own_addr, const u8 *addr, |
239 | int reason); | |
bf83eab5 | 240 | |
3f5285e8 | 241 | |
8d1fdde7 | 242 | /* Converts nl80211_chan_width to a common format */ |
f3407c66 | 243 | enum chan_width convert2width(int width) |
8d1fdde7 JD |
244 | { |
245 | switch (width) { | |
246 | case NL80211_CHAN_WIDTH_20_NOHT: | |
247 | return CHAN_WIDTH_20_NOHT; | |
248 | case NL80211_CHAN_WIDTH_20: | |
249 | return CHAN_WIDTH_20; | |
250 | case NL80211_CHAN_WIDTH_40: | |
251 | return CHAN_WIDTH_40; | |
252 | case NL80211_CHAN_WIDTH_80: | |
253 | return CHAN_WIDTH_80; | |
254 | case NL80211_CHAN_WIDTH_80P80: | |
255 | return CHAN_WIDTH_80P80; | |
256 | case NL80211_CHAN_WIDTH_160: | |
257 | return CHAN_WIDTH_160; | |
258 | } | |
259 | return CHAN_WIDTH_UNKNOWN; | |
260 | } | |
261 | ||
262 | ||
f3407c66 | 263 | int is_ap_interface(enum nl80211_iftype nlmode) |
b1f625e0 | 264 | { |
0e80ea2c JM |
265 | return nlmode == NL80211_IFTYPE_AP || |
266 | nlmode == NL80211_IFTYPE_P2P_GO; | |
b1f625e0 EP |
267 | } |
268 | ||
269 | ||
477af8f8 | 270 | int is_sta_interface(enum nl80211_iftype nlmode) |
b1f625e0 | 271 | { |
0e80ea2c JM |
272 | return nlmode == NL80211_IFTYPE_STATION || |
273 | nlmode == NL80211_IFTYPE_P2P_CLIENT; | |
b1f625e0 EP |
274 | } |
275 | ||
276 | ||
6a71413e | 277 | static int is_p2p_net_interface(enum nl80211_iftype nlmode) |
b3af99d2 | 278 | { |
0e80ea2c JM |
279 | return nlmode == NL80211_IFTYPE_P2P_CLIENT || |
280 | nlmode == NL80211_IFTYPE_P2P_GO; | |
b3af99d2 JM |
281 | } |
282 | ||
283 | ||
f3407c66 JM |
284 | struct i802_bss * get_bss_ifindex(struct wpa_driver_nl80211_data *drv, |
285 | int ifindex) | |
5dfbd725 JM |
286 | { |
287 | struct i802_bss *bss; | |
288 | ||
289 | for (bss = drv->first_bss; bss; bss = bss->next) { | |
290 | if (bss->ifindex == ifindex) | |
291 | return bss; | |
292 | } | |
293 | ||
294 | return NULL; | |
295 | } | |
296 | ||
297 | ||
afb0550a BC |
298 | static int is_mesh_interface(enum nl80211_iftype nlmode) |
299 | { | |
300 | return nlmode == NL80211_IFTYPE_MESH_POINT; | |
301 | } | |
302 | ||
303 | ||
f3407c66 | 304 | void nl80211_mark_disconnected(struct wpa_driver_nl80211_data *drv) |
add9b7a4 JM |
305 | { |
306 | if (drv->associated) | |
307 | os_memcpy(drv->prev_bssid, drv->bssid, ETH_ALEN); | |
308 | drv->associated = 0; | |
309 | os_memset(drv->bssid, 0, ETH_ALEN); | |
310 | } | |
311 | ||
312 | ||
6241fcb1 JM |
313 | /* nl80211 code */ |
314 | static int ack_handler(struct nl_msg *msg, void *arg) | |
315 | { | |
316 | int *err = arg; | |
317 | *err = 0; | |
318 | return NL_STOP; | |
319 | } | |
320 | ||
321 | static int finish_handler(struct nl_msg *msg, void *arg) | |
322 | { | |
8e8df255 JM |
323 | int *ret = arg; |
324 | *ret = 0; | |
6241fcb1 JM |
325 | return NL_SKIP; |
326 | } | |
327 | ||
328 | static int error_handler(struct sockaddr_nl *nla, struct nlmsgerr *err, | |
329 | void *arg) | |
330 | { | |
40432e6e JB |
331 | struct nlmsghdr *nlh = (struct nlmsghdr *) err - 1; |
332 | int len = nlh->nlmsg_len; | |
333 | struct nlattr *attrs; | |
334 | struct nlattr *tb[NLMSGERR_ATTR_MAX + 1]; | |
6241fcb1 | 335 | int *ret = arg; |
40432e6e JB |
336 | int ack_len = sizeof(*nlh) + sizeof(int) + sizeof(*nlh); |
337 | ||
6241fcb1 | 338 | *ret = err->error; |
40432e6e JB |
339 | |
340 | if (!(nlh->nlmsg_flags & NLM_F_ACK_TLVS)) | |
341 | return NL_SKIP; | |
342 | ||
343 | if (!(nlh->nlmsg_flags & NLM_F_CAPPED)) | |
344 | ack_len += err->msg.nlmsg_len - sizeof(*nlh); | |
345 | ||
346 | if (len <= ack_len) | |
347 | return NL_STOP; | |
348 | ||
349 | attrs = (void *) ((unsigned char *) nlh + ack_len); | |
350 | len -= ack_len; | |
351 | ||
352 | nla_parse(tb, NLMSGERR_ATTR_MAX, attrs, len, NULL); | |
353 | if (tb[NLMSGERR_ATTR_MSG]) { | |
354 | len = strnlen((char *) nla_data(tb[NLMSGERR_ATTR_MSG]), | |
355 | nla_len(tb[NLMSGERR_ATTR_MSG])); | |
356 | wpa_printf(MSG_ERROR, "nl80211: kernel reports: %*s", | |
357 | len, (char *) nla_data(tb[NLMSGERR_ATTR_MSG])); | |
358 | } | |
359 | ||
6241fcb1 JM |
360 | return NL_SKIP; |
361 | } | |
362 | ||
5b7b85f6 JM |
363 | |
364 | static int no_seq_check(struct nl_msg *msg, void *arg) | |
365 | { | |
366 | return NL_OK; | |
367 | } | |
368 | ||
369 | ||
bbd89bfc JM |
370 | static void nl80211_nlmsg_clear(struct nl_msg *msg) |
371 | { | |
372 | /* | |
373 | * Clear nlmsg data, e.g., to make sure key material is not left in | |
374 | * heap memory for unnecessarily long time. | |
375 | */ | |
376 | if (msg) { | |
377 | struct nlmsghdr *hdr = nlmsg_hdr(msg); | |
378 | void *data = nlmsg_data(hdr); | |
d58ade21 JM |
379 | /* |
380 | * This would use nlmsg_datalen() or the older nlmsg_len() if | |
381 | * only libnl were to maintain a stable API.. Neither will work | |
382 | * with all released versions, so just calculate the length | |
383 | * here. | |
384 | */ | |
385 | int len = hdr->nlmsg_len - NLMSG_HDRLEN; | |
bbd89bfc JM |
386 | |
387 | os_memset(data, 0, len); | |
388 | } | |
389 | } | |
390 | ||
391 | ||
d6c9aab8 | 392 | static int send_and_recv(struct nl80211_global *global, |
58f6fbe0 JM |
393 | struct nl_handle *nl_handle, struct nl_msg *msg, |
394 | int (*valid_handler)(struct nl_msg *, void *), | |
395 | void *valid_data) | |
6241fcb1 JM |
396 | { |
397 | struct nl_cb *cb; | |
40432e6e | 398 | int err = -ENOMEM, opt; |
6241fcb1 | 399 | |
9725b784 JM |
400 | if (!msg) |
401 | return -ENOMEM; | |
402 | ||
d6c9aab8 | 403 | cb = nl_cb_clone(global->nl_cb); |
6241fcb1 JM |
404 | if (!cb) |
405 | goto out; | |
406 | ||
40432e6e JB |
407 | /* try to set NETLINK_EXT_ACK to 1, ignoring errors */ |
408 | opt = 1; | |
409 | setsockopt(nl_socket_get_fd(nl_handle), SOL_NETLINK, | |
410 | NETLINK_EXT_ACK, &opt, sizeof(opt)); | |
411 | ||
b14e8ea1 JM |
412 | /* try to set NETLINK_CAP_ACK to 1, ignoring errors */ |
413 | opt = 1; | |
414 | setsockopt(nl_socket_get_fd(nl_handle), SOL_NETLINK, | |
415 | NETLINK_CAP_ACK, &opt, sizeof(opt)); | |
416 | ||
58f6fbe0 | 417 | err = nl_send_auto_complete(nl_handle, msg); |
6241fcb1 JM |
418 | if (err < 0) |
419 | goto out; | |
420 | ||
421 | err = 1; | |
422 | ||
423 | nl_cb_err(cb, NL_CB_CUSTOM, error_handler, &err); | |
8e8df255 | 424 | nl_cb_set(cb, NL_CB_FINISH, NL_CB_CUSTOM, finish_handler, &err); |
6241fcb1 JM |
425 | nl_cb_set(cb, NL_CB_ACK, NL_CB_CUSTOM, ack_handler, &err); |
426 | ||
427 | if (valid_handler) | |
428 | nl_cb_set(cb, NL_CB_VALID, NL_CB_CUSTOM, | |
429 | valid_handler, valid_data); | |
430 | ||
34068ac3 JM |
431 | while (err > 0) { |
432 | int res = nl_recvmsgs(nl_handle, cb); | |
d3d04831 | 433 | if (res < 0) { |
34068ac3 JM |
434 | wpa_printf(MSG_INFO, |
435 | "nl80211: %s->nl_recvmsgs failed: %d", | |
436 | __func__, res); | |
437 | } | |
438 | } | |
6241fcb1 JM |
439 | out: |
440 | nl_cb_put(cb); | |
bbd89bfc JM |
441 | if (!valid_handler && valid_data == (void *) -1) |
442 | nl80211_nlmsg_clear(msg); | |
6241fcb1 JM |
443 | nlmsg_free(msg); |
444 | return err; | |
445 | } | |
446 | ||
447 | ||
f3407c66 JM |
448 | int send_and_recv_msgs(struct wpa_driver_nl80211_data *drv, |
449 | struct nl_msg *msg, | |
450 | int (*valid_handler)(struct nl_msg *, void *), | |
451 | void *valid_data) | |
58f6fbe0 | 452 | { |
481234cf | 453 | return send_and_recv(drv->global, drv->global->nl, msg, |
d6c9aab8 | 454 | valid_handler, valid_data); |
58f6fbe0 JM |
455 | } |
456 | ||
457 | ||
97865538 JM |
458 | struct family_data { |
459 | const char *group; | |
460 | int id; | |
461 | }; | |
462 | ||
463 | ||
464 | static int family_handler(struct nl_msg *msg, void *arg) | |
465 | { | |
466 | struct family_data *res = arg; | |
467 | struct nlattr *tb[CTRL_ATTR_MAX + 1]; | |
468 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); | |
469 | struct nlattr *mcgrp; | |
470 | int i; | |
471 | ||
472 | nla_parse(tb, CTRL_ATTR_MAX, genlmsg_attrdata(gnlh, 0), | |
473 | genlmsg_attrlen(gnlh, 0), NULL); | |
474 | if (!tb[CTRL_ATTR_MCAST_GROUPS]) | |
475 | return NL_SKIP; | |
476 | ||
477 | nla_for_each_nested(mcgrp, tb[CTRL_ATTR_MCAST_GROUPS], i) { | |
478 | struct nlattr *tb2[CTRL_ATTR_MCAST_GRP_MAX + 1]; | |
479 | nla_parse(tb2, CTRL_ATTR_MCAST_GRP_MAX, nla_data(mcgrp), | |
480 | nla_len(mcgrp), NULL); | |
481 | if (!tb2[CTRL_ATTR_MCAST_GRP_NAME] || | |
482 | !tb2[CTRL_ATTR_MCAST_GRP_ID] || | |
483 | os_strncmp(nla_data(tb2[CTRL_ATTR_MCAST_GRP_NAME]), | |
484 | res->group, | |
485 | nla_len(tb2[CTRL_ATTR_MCAST_GRP_NAME])) != 0) | |
486 | continue; | |
487 | res->id = nla_get_u32(tb2[CTRL_ATTR_MCAST_GRP_ID]); | |
488 | break; | |
489 | }; | |
490 | ||
491 | return NL_SKIP; | |
492 | } | |
493 | ||
494 | ||
d6c9aab8 | 495 | static int nl_get_multicast_id(struct nl80211_global *global, |
97865538 JM |
496 | const char *family, const char *group) |
497 | { | |
498 | struct nl_msg *msg; | |
a862e4a3 | 499 | int ret; |
97865538 JM |
500 | struct family_data res = { group, -ENOENT }; |
501 | ||
502 | msg = nlmsg_alloc(); | |
503 | if (!msg) | |
504 | return -ENOMEM; | |
a862e4a3 JM |
505 | if (!genlmsg_put(msg, 0, 0, genl_ctrl_resolve(global->nl, "nlctrl"), |
506 | 0, 0, CTRL_CMD_GETFAMILY, 0) || | |
507 | nla_put_string(msg, CTRL_ATTR_FAMILY_NAME, family)) { | |
508 | nlmsg_free(msg); | |
509 | return -1; | |
510 | } | |
97865538 | 511 | |
1033315f | 512 | ret = send_and_recv(global, global->nl, msg, family_handler, &res); |
97865538 JM |
513 | if (ret == 0) |
514 | ret = res.id; | |
97865538 JM |
515 | return ret; |
516 | } | |
517 | ||
518 | ||
f3407c66 JM |
519 | void * nl80211_cmd(struct wpa_driver_nl80211_data *drv, |
520 | struct nl_msg *msg, int flags, uint8_t cmd) | |
9fb04070 | 521 | { |
a5a187b0 JM |
522 | if (TEST_FAIL()) |
523 | return NULL; | |
335d42b1 | 524 | return genlmsg_put(msg, 0, 0, drv->global->nl80211_id, |
276e2d67 | 525 | 0, flags, cmd, 0); |
9fb04070 JM |
526 | } |
527 | ||
528 | ||
350acc35 JM |
529 | static int nl80211_set_iface_id(struct nl_msg *msg, struct i802_bss *bss) |
530 | { | |
531 | if (bss->wdev_id_set) | |
532 | return nla_put_u64(msg, NL80211_ATTR_WDEV, bss->wdev_id); | |
533 | return nla_put_u32(msg, NL80211_ATTR_IFINDEX, bss->ifindex); | |
534 | } | |
535 | ||
536 | ||
07c7757c JM |
537 | struct nl_msg * nl80211_cmd_msg(struct i802_bss *bss, int flags, uint8_t cmd) |
538 | { | |
539 | struct nl_msg *msg; | |
540 | ||
541 | msg = nlmsg_alloc(); | |
542 | if (!msg) | |
543 | return NULL; | |
544 | ||
545 | if (!nl80211_cmd(bss->drv, msg, flags, cmd) || | |
546 | nl80211_set_iface_id(msg, bss) < 0) { | |
547 | nlmsg_free(msg); | |
548 | return NULL; | |
549 | } | |
550 | ||
551 | return msg; | |
552 | } | |
553 | ||
554 | ||
555 | static struct nl_msg * | |
556 | nl80211_ifindex_msg(struct wpa_driver_nl80211_data *drv, int ifindex, | |
557 | int flags, uint8_t cmd) | |
558 | { | |
559 | struct nl_msg *msg; | |
560 | ||
561 | msg = nlmsg_alloc(); | |
562 | if (!msg) | |
563 | return NULL; | |
564 | ||
565 | if (!nl80211_cmd(drv, msg, flags, cmd) || | |
566 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex)) { | |
567 | nlmsg_free(msg); | |
568 | return NULL; | |
569 | } | |
570 | ||
571 | return msg; | |
572 | } | |
573 | ||
574 | ||
575 | struct nl_msg * nl80211_drv_msg(struct wpa_driver_nl80211_data *drv, int flags, | |
576 | uint8_t cmd) | |
577 | { | |
578 | return nl80211_ifindex_msg(drv, drv->ifindex, flags, cmd); | |
579 | } | |
580 | ||
581 | ||
582 | struct nl_msg * nl80211_bss_msg(struct i802_bss *bss, int flags, uint8_t cmd) | |
583 | { | |
584 | return nl80211_ifindex_msg(bss->drv, bss->ifindex, flags, cmd); | |
585 | } | |
586 | ||
587 | ||
e32ad281 JB |
588 | struct wiphy_idx_data { |
589 | int wiphy_idx; | |
01517c8b | 590 | enum nl80211_iftype nlmode; |
597b94f5 | 591 | u8 *macaddr; |
e32ad281 JB |
592 | }; |
593 | ||
594 | ||
595 | static int netdev_info_handler(struct nl_msg *msg, void *arg) | |
596 | { | |
597 | struct nlattr *tb[NL80211_ATTR_MAX + 1]; | |
598 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); | |
599 | struct wiphy_idx_data *info = arg; | |
600 | ||
601 | nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), | |
602 | genlmsg_attrlen(gnlh, 0), NULL); | |
603 | ||
604 | if (tb[NL80211_ATTR_WIPHY]) | |
605 | info->wiphy_idx = nla_get_u32(tb[NL80211_ATTR_WIPHY]); | |
606 | ||
01517c8b JB |
607 | if (tb[NL80211_ATTR_IFTYPE]) |
608 | info->nlmode = nla_get_u32(tb[NL80211_ATTR_IFTYPE]); | |
609 | ||
597b94f5 AS |
610 | if (tb[NL80211_ATTR_MAC] && info->macaddr) |
611 | os_memcpy(info->macaddr, nla_data(tb[NL80211_ATTR_MAC]), | |
612 | ETH_ALEN); | |
613 | ||
e32ad281 JB |
614 | return NL_SKIP; |
615 | } | |
616 | ||
617 | ||
f3407c66 | 618 | int nl80211_get_wiphy_index(struct i802_bss *bss) |
e32ad281 JB |
619 | { |
620 | struct nl_msg *msg; | |
621 | struct wiphy_idx_data data = { | |
622 | .wiphy_idx = -1, | |
597b94f5 | 623 | .macaddr = NULL, |
e32ad281 JB |
624 | }; |
625 | ||
56f77852 | 626 | if (!(msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_GET_INTERFACE))) |
a862e4a3 | 627 | return -1; |
e32ad281 JB |
628 | |
629 | if (send_and_recv_msgs(bss->drv, msg, netdev_info_handler, &data) == 0) | |
630 | return data.wiphy_idx; | |
e32ad281 JB |
631 | return -1; |
632 | } | |
633 | ||
634 | ||
01517c8b JB |
635 | static enum nl80211_iftype nl80211_get_ifmode(struct i802_bss *bss) |
636 | { | |
637 | struct nl_msg *msg; | |
638 | struct wiphy_idx_data data = { | |
597b94f5 AS |
639 | .nlmode = NL80211_IFTYPE_UNSPECIFIED, |
640 | .macaddr = NULL, | |
01517c8b JB |
641 | }; |
642 | ||
56f77852 | 643 | if (!(msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_GET_INTERFACE))) |
a862e4a3 | 644 | return NL80211_IFTYPE_UNSPECIFIED; |
01517c8b JB |
645 | |
646 | if (send_and_recv_msgs(bss->drv, msg, netdev_info_handler, &data) == 0) | |
647 | return data.nlmode; | |
01517c8b JB |
648 | return NL80211_IFTYPE_UNSPECIFIED; |
649 | } | |
01517c8b JB |
650 | |
651 | ||
597b94f5 AS |
652 | static int nl80211_get_macaddr(struct i802_bss *bss) |
653 | { | |
654 | struct nl_msg *msg; | |
655 | struct wiphy_idx_data data = { | |
656 | .macaddr = bss->addr, | |
657 | }; | |
658 | ||
56f77852 | 659 | if (!(msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_GET_INTERFACE))) |
a862e4a3 | 660 | return -1; |
597b94f5 | 661 | |
597b94f5 | 662 | return send_and_recv_msgs(bss->drv, msg, netdev_info_handler, &data); |
597b94f5 | 663 | } |
597b94f5 AS |
664 | |
665 | ||
e32ad281 JB |
666 | static int nl80211_register_beacons(struct wpa_driver_nl80211_data *drv, |
667 | struct nl80211_wiphy_data *w) | |
668 | { | |
669 | struct nl_msg *msg; | |
a862e4a3 | 670 | int ret; |
e32ad281 JB |
671 | |
672 | msg = nlmsg_alloc(); | |
673 | if (!msg) | |
674 | return -1; | |
675 | ||
a862e4a3 JM |
676 | if (!nl80211_cmd(drv, msg, 0, NL80211_CMD_REGISTER_BEACONS) || |
677 | nla_put_u32(msg, NL80211_ATTR_WIPHY, w->wiphy_idx)) { | |
678 | nlmsg_free(msg); | |
679 | return -1; | |
680 | } | |
e32ad281 | 681 | |
481234cf | 682 | ret = send_and_recv(drv->global, w->nl_beacons, msg, NULL, NULL); |
e32ad281 JB |
683 | if (ret) { |
684 | wpa_printf(MSG_DEBUG, "nl80211: Register beacons command " | |
685 | "failed: ret=%d (%s)", | |
686 | ret, strerror(-ret)); | |
e32ad281 | 687 | } |
e32ad281 JB |
688 | return ret; |
689 | } | |
690 | ||
691 | ||
692 | static void nl80211_recv_beacons(int sock, void *eloop_ctx, void *handle) | |
693 | { | |
694 | struct nl80211_wiphy_data *w = eloop_ctx; | |
34068ac3 | 695 | int res; |
e32ad281 | 696 | |
ee9fc67a | 697 | wpa_printf(MSG_EXCESSIVE, "nl80211: Beacon event message available"); |
e32ad281 | 698 | |
34068ac3 | 699 | res = nl_recvmsgs(handle, w->nl_cb); |
d3d04831 | 700 | if (res < 0) { |
34068ac3 JM |
701 | wpa_printf(MSG_INFO, "nl80211: %s->nl_recvmsgs failed: %d", |
702 | __func__, res); | |
703 | } | |
e32ad281 JB |
704 | } |
705 | ||
706 | ||
707 | static int process_beacon_event(struct nl_msg *msg, void *arg) | |
708 | { | |
709 | struct nl80211_wiphy_data *w = arg; | |
710 | struct wpa_driver_nl80211_data *drv; | |
711 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); | |
712 | struct nlattr *tb[NL80211_ATTR_MAX + 1]; | |
713 | union wpa_event_data event; | |
714 | ||
715 | nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), | |
716 | genlmsg_attrlen(gnlh, 0), NULL); | |
717 | ||
718 | if (gnlh->cmd != NL80211_CMD_FRAME) { | |
719 | wpa_printf(MSG_DEBUG, "nl80211: Unexpected beacon event? (%d)", | |
720 | gnlh->cmd); | |
721 | return NL_SKIP; | |
722 | } | |
723 | ||
724 | if (!tb[NL80211_ATTR_FRAME]) | |
725 | return NL_SKIP; | |
726 | ||
727 | dl_list_for_each(drv, &w->drvs, struct wpa_driver_nl80211_data, | |
728 | wiphy_list) { | |
729 | os_memset(&event, 0, sizeof(event)); | |
730 | event.rx_mgmt.frame = nla_data(tb[NL80211_ATTR_FRAME]); | |
731 | event.rx_mgmt.frame_len = nla_len(tb[NL80211_ATTR_FRAME]); | |
732 | wpa_supplicant_event(drv->ctx, EVENT_RX_MGMT, &event); | |
733 | } | |
734 | ||
735 | return NL_SKIP; | |
736 | } | |
737 | ||
738 | ||
739 | static struct nl80211_wiphy_data * | |
740 | nl80211_get_wiphy_data_ap(struct i802_bss *bss) | |
741 | { | |
742 | static DEFINE_DL_LIST(nl80211_wiphys); | |
743 | struct nl80211_wiphy_data *w; | |
744 | int wiphy_idx, found = 0; | |
745 | struct i802_bss *tmp_bss; | |
a70cd0db | 746 | u8 channel; |
e32ad281 JB |
747 | |
748 | if (bss->wiphy_data != NULL) | |
749 | return bss->wiphy_data; | |
750 | ||
751 | wiphy_idx = nl80211_get_wiphy_index(bss); | |
752 | ||
753 | dl_list_for_each(w, &nl80211_wiphys, struct nl80211_wiphy_data, list) { | |
754 | if (w->wiphy_idx == wiphy_idx) | |
755 | goto add; | |
756 | } | |
757 | ||
758 | /* alloc new one */ | |
759 | w = os_zalloc(sizeof(*w)); | |
760 | if (w == NULL) | |
761 | return NULL; | |
762 | w->wiphy_idx = wiphy_idx; | |
763 | dl_list_init(&w->bsss); | |
764 | dl_list_init(&w->drvs); | |
765 | ||
a70cd0db DL |
766 | /* Beacon frames not supported in IEEE 802.11ad */ |
767 | if (ieee80211_freq_to_chan(bss->freq, &channel) != | |
768 | HOSTAPD_MODE_IEEE80211AD) { | |
769 | w->nl_cb = nl_cb_alloc(NL_CB_DEFAULT); | |
770 | if (!w->nl_cb) { | |
771 | os_free(w); | |
772 | return NULL; | |
773 | } | |
774 | nl_cb_set(w->nl_cb, NL_CB_SEQ_CHECK, NL_CB_CUSTOM, | |
775 | no_seq_check, NULL); | |
776 | nl_cb_set(w->nl_cb, NL_CB_VALID, NL_CB_CUSTOM, | |
777 | process_beacon_event, w); | |
778 | ||
779 | w->nl_beacons = nl_create_handle(bss->drv->global->nl_cb, | |
780 | "wiphy beacons"); | |
781 | if (w->nl_beacons == NULL) { | |
782 | os_free(w); | |
783 | return NULL; | |
784 | } | |
e32ad281 | 785 | |
a70cd0db DL |
786 | if (nl80211_register_beacons(bss->drv, w)) { |
787 | nl_destroy_handles(&w->nl_beacons); | |
788 | os_free(w); | |
789 | return NULL; | |
790 | } | |
e32ad281 | 791 | |
a70cd0db | 792 | nl80211_register_eloop_read(&w->nl_beacons, |
40a68f33 | 793 | nl80211_recv_beacons, w, 0); |
e32ad281 JB |
794 | } |
795 | ||
e32ad281 JB |
796 | dl_list_add(&nl80211_wiphys, &w->list); |
797 | ||
798 | add: | |
799 | /* drv entry for this bss already there? */ | |
800 | dl_list_for_each(tmp_bss, &w->bsss, struct i802_bss, wiphy_list) { | |
801 | if (tmp_bss->drv == bss->drv) { | |
802 | found = 1; | |
803 | break; | |
804 | } | |
805 | } | |
806 | /* if not add it */ | |
807 | if (!found) | |
808 | dl_list_add(&w->drvs, &bss->drv->wiphy_list); | |
809 | ||
810 | dl_list_add(&w->bsss, &bss->wiphy_list); | |
811 | bss->wiphy_data = w; | |
812 | return w; | |
813 | } | |
814 | ||
815 | ||
816 | static void nl80211_put_wiphy_data_ap(struct i802_bss *bss) | |
817 | { | |
818 | struct nl80211_wiphy_data *w = bss->wiphy_data; | |
819 | struct i802_bss *tmp_bss; | |
820 | int found = 0; | |
821 | ||
822 | if (w == NULL) | |
823 | return; | |
824 | bss->wiphy_data = NULL; | |
825 | dl_list_del(&bss->wiphy_list); | |
826 | ||
827 | /* still any for this drv present? */ | |
828 | dl_list_for_each(tmp_bss, &w->bsss, struct i802_bss, wiphy_list) { | |
829 | if (tmp_bss->drv == bss->drv) { | |
830 | found = 1; | |
831 | break; | |
832 | } | |
833 | } | |
834 | /* if not remove it */ | |
835 | if (!found) | |
836 | dl_list_del(&bss->drv->wiphy_list); | |
837 | ||
838 | if (!dl_list_empty(&w->bsss)) | |
839 | return; | |
840 | ||
a70cd0db | 841 | if (w->nl_beacons) |
40a68f33 | 842 | nl80211_destroy_eloop_handle(&w->nl_beacons, 0); |
e32ad281 JB |
843 | |
844 | nl_cb_put(w->nl_cb); | |
e32ad281 JB |
845 | dl_list_del(&w->list); |
846 | os_free(w); | |
847 | } | |
848 | ||
849 | ||
45e3fc72 RM |
850 | static unsigned int nl80211_get_ifindex(void *priv) |
851 | { | |
852 | struct i802_bss *bss = priv; | |
853 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
854 | ||
855 | return drv->ifindex; | |
856 | } | |
857 | ||
858 | ||
3f5285e8 JM |
859 | static int wpa_driver_nl80211_get_bssid(void *priv, u8 *bssid) |
860 | { | |
a2e40bb6 FF |
861 | struct i802_bss *bss = priv; |
862 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
c2a04078 JM |
863 | if (!drv->associated) |
864 | return -1; | |
865 | os_memcpy(bssid, drv->bssid, ETH_ALEN); | |
866 | return 0; | |
3f5285e8 JM |
867 | } |
868 | ||
869 | ||
3f5285e8 JM |
870 | static int wpa_driver_nl80211_get_ssid(void *priv, u8 *ssid) |
871 | { | |
a2e40bb6 FF |
872 | struct i802_bss *bss = priv; |
873 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
fd05d64e JM |
874 | if (!drv->associated) |
875 | return -1; | |
876 | os_memcpy(ssid, drv->ssid, drv->ssid_len); | |
877 | return drv->ssid_len; | |
3f5285e8 JM |
878 | } |
879 | ||
880 | ||
90a545cc | 881 | static void wpa_driver_nl80211_event_newlink( |
45e3fc72 RM |
882 | struct nl80211_global *global, struct wpa_driver_nl80211_data *drv, |
883 | int ifindex, const char *ifname) | |
3f5285e8 JM |
884 | { |
885 | union wpa_event_data event; | |
886 | ||
45e3fc72 | 887 | if (drv && os_strcmp(drv->first_bss->ifname, ifname) == 0) { |
90a545cc JM |
888 | if (if_nametoindex(drv->first_bss->ifname) == 0) { |
889 | wpa_printf(MSG_DEBUG, "nl80211: Interface %s does not exist - ignore RTM_NEWLINK", | |
890 | drv->first_bss->ifname); | |
891 | return; | |
892 | } | |
893 | if (!drv->if_removed) | |
894 | return; | |
895 | wpa_printf(MSG_DEBUG, "nl80211: Mark if_removed=0 for %s based on RTM_NEWLINK event", | |
896 | drv->first_bss->ifname); | |
897 | drv->if_removed = 0; | |
898 | } | |
899 | ||
3f5285e8 | 900 | os_memset(&event, 0, sizeof(event)); |
45e3fc72 | 901 | event.interface_status.ifindex = ifindex; |
90a545cc JM |
902 | os_strlcpy(event.interface_status.ifname, ifname, |
903 | sizeof(event.interface_status.ifname)); | |
904 | event.interface_status.ievent = EVENT_INTERFACE_ADDED; | |
45e3fc72 RM |
905 | if (drv) |
906 | wpa_supplicant_event(drv->ctx, EVENT_INTERFACE_STATUS, &event); | |
907 | else | |
908 | wpa_supplicant_event_global(global->ctx, EVENT_INTERFACE_STATUS, | |
909 | &event); | |
90a545cc JM |
910 | } |
911 | ||
912 | ||
913 | static void wpa_driver_nl80211_event_dellink( | |
45e3fc72 RM |
914 | struct nl80211_global *global, struct wpa_driver_nl80211_data *drv, |
915 | int ifindex, const char *ifname) | |
90a545cc JM |
916 | { |
917 | union wpa_event_data event; | |
918 | ||
45e3fc72 | 919 | if (drv && os_strcmp(drv->first_bss->ifname, ifname) == 0) { |
90a545cc JM |
920 | if (drv->if_removed) { |
921 | wpa_printf(MSG_DEBUG, "nl80211: if_removed already set - ignore RTM_DELLINK event for %s", | |
922 | ifname); | |
923 | return; | |
d1f4942b | 924 | } |
90a545cc JM |
925 | wpa_printf(MSG_DEBUG, "RTM_DELLINK: Interface '%s' removed - mark if_removed=1", |
926 | ifname); | |
927 | drv->if_removed = 1; | |
928 | } else { | |
929 | wpa_printf(MSG_DEBUG, "RTM_DELLINK: Interface '%s' removed", | |
930 | ifname); | |
7524cfb1 JM |
931 | } |
932 | ||
90a545cc | 933 | os_memset(&event, 0, sizeof(event)); |
45e3fc72 | 934 | event.interface_status.ifindex = ifindex; |
90a545cc JM |
935 | os_strlcpy(event.interface_status.ifname, ifname, |
936 | sizeof(event.interface_status.ifname)); | |
937 | event.interface_status.ievent = EVENT_INTERFACE_REMOVED; | |
45e3fc72 RM |
938 | if (drv) |
939 | wpa_supplicant_event(drv->ctx, EVENT_INTERFACE_STATUS, &event); | |
940 | else | |
941 | wpa_supplicant_event_global(global->ctx, EVENT_INTERFACE_STATUS, | |
942 | &event); | |
3f5285e8 JM |
943 | } |
944 | ||
945 | ||
7524cfb1 | 946 | static int wpa_driver_nl80211_own_ifname(struct wpa_driver_nl80211_data *drv, |
62d680c3 | 947 | u8 *buf, size_t len) |
7524cfb1 | 948 | { |
62d680c3 | 949 | int attrlen, rta_len; |
7524cfb1 JM |
950 | struct rtattr *attr; |
951 | ||
62d680c3 JM |
952 | attrlen = len; |
953 | attr = (struct rtattr *) buf; | |
7524cfb1 JM |
954 | |
955 | rta_len = RTA_ALIGN(sizeof(struct rtattr)); | |
956 | while (RTA_OK(attr, attrlen)) { | |
957 | if (attr->rta_type == IFLA_IFNAME) { | |
834ee56f KP |
958 | if (os_strcmp(((char *) attr) + rta_len, |
959 | drv->first_bss->ifname) == 0) | |
7524cfb1 JM |
960 | return 1; |
961 | else | |
962 | break; | |
963 | } | |
964 | attr = RTA_NEXT(attr, attrlen); | |
965 | } | |
966 | ||
967 | return 0; | |
968 | } | |
969 | ||
970 | ||
971 | static int wpa_driver_nl80211_own_ifindex(struct wpa_driver_nl80211_data *drv, | |
62d680c3 | 972 | int ifindex, u8 *buf, size_t len) |
7524cfb1 JM |
973 | { |
974 | if (drv->ifindex == ifindex) | |
975 | return 1; | |
976 | ||
62d680c3 | 977 | if (drv->if_removed && wpa_driver_nl80211_own_ifname(drv, buf, len)) { |
f51f54a0 | 978 | nl80211_check_global(drv->global); |
7524cfb1 JM |
979 | wpa_printf(MSG_DEBUG, "nl80211: Update ifindex for a removed " |
980 | "interface"); | |
5e0c20ff JM |
981 | if (wpa_driver_nl80211_finish_drv_init(drv, NULL, 0, NULL) < 0) |
982 | return -1; | |
7524cfb1 JM |
983 | return 1; |
984 | } | |
985 | ||
986 | return 0; | |
987 | } | |
988 | ||
989 | ||
36d84860 | 990 | static struct wpa_driver_nl80211_data * |
5e0c20ff JM |
991 | nl80211_find_drv(struct nl80211_global *global, int idx, u8 *buf, size_t len, |
992 | int *init_failed) | |
36d84860 BG |
993 | { |
994 | struct wpa_driver_nl80211_data *drv; | |
5e0c20ff JM |
995 | int res; |
996 | ||
997 | if (init_failed) | |
998 | *init_failed = 0; | |
36d84860 BG |
999 | dl_list_for_each(drv, &global->interfaces, |
1000 | struct wpa_driver_nl80211_data, list) { | |
5e0c20ff JM |
1001 | res = wpa_driver_nl80211_own_ifindex(drv, idx, buf, len); |
1002 | if (res < 0) { | |
1003 | wpa_printf(MSG_DEBUG, | |
1004 | "nl80211: Found matching own interface, but failed to complete reinitialization"); | |
1005 | if (init_failed) | |
1006 | *init_failed = 1; | |
1007 | return drv; | |
1008 | } | |
1009 | if (res > 0 || have_ifidx(drv, idx, IFIDX_ANY)) | |
36d84860 BG |
1010 | return drv; |
1011 | } | |
1012 | return NULL; | |
1013 | } | |
1014 | ||
1015 | ||
290834df | 1016 | static void nl80211_refresh_mac(struct wpa_driver_nl80211_data *drv, |
77a020a1 | 1017 | int ifindex, int notify) |
290834df BG |
1018 | { |
1019 | struct i802_bss *bss; | |
1020 | u8 addr[ETH_ALEN]; | |
1021 | ||
1022 | bss = get_bss_ifindex(drv, ifindex); | |
1023 | if (bss && | |
1024 | linux_get_ifhwaddr(drv->global->ioctl_sock, | |
1025 | bss->ifname, addr) < 0) { | |
1026 | wpa_printf(MSG_DEBUG, | |
1027 | "nl80211: %s: failed to re-read MAC address", | |
1028 | bss->ifname); | |
1029 | } else if (bss && os_memcmp(addr, bss->addr, ETH_ALEN) != 0) { | |
1030 | wpa_printf(MSG_DEBUG, | |
1031 | "nl80211: Own MAC address on ifindex %d (%s) changed from " | |
1032 | MACSTR " to " MACSTR, | |
1033 | ifindex, bss->ifname, | |
1034 | MAC2STR(bss->addr), MAC2STR(addr)); | |
1035 | os_memcpy(bss->addr, addr, ETH_ALEN); | |
77a020a1 BG |
1036 | if (notify) |
1037 | wpa_supplicant_event(drv->ctx, | |
1038 | EVENT_INTERFACE_MAC_CHANGED, NULL); | |
290834df BG |
1039 | } |
1040 | } | |
1041 | ||
1042 | ||
62d680c3 JM |
1043 | static void wpa_driver_nl80211_event_rtm_newlink(void *ctx, |
1044 | struct ifinfomsg *ifi, | |
1045 | u8 *buf, size_t len) | |
3f5285e8 | 1046 | { |
36d84860 BG |
1047 | struct nl80211_global *global = ctx; |
1048 | struct wpa_driver_nl80211_data *drv; | |
90a545cc | 1049 | int attrlen; |
62d680c3 | 1050 | struct rtattr *attr; |
97cfcf64 | 1051 | u32 brid = 0; |
aef85ba2 | 1052 | char namebuf[IFNAMSIZ]; |
90a545cc JM |
1053 | char ifname[IFNAMSIZ + 1]; |
1054 | char extra[100], *pos, *end; | |
5e0c20ff | 1055 | int init_failed; |
3f5285e8 | 1056 | |
90a545cc JM |
1057 | extra[0] = '\0'; |
1058 | pos = extra; | |
1059 | end = pos + sizeof(extra); | |
1060 | ifname[0] = '\0'; | |
1061 | ||
1062 | attrlen = len; | |
1063 | attr = (struct rtattr *) buf; | |
1064 | while (RTA_OK(attr, attrlen)) { | |
1065 | switch (attr->rta_type) { | |
1066 | case IFLA_IFNAME: | |
1067 | if (RTA_PAYLOAD(attr) >= IFNAMSIZ) | |
1068 | break; | |
1069 | os_memcpy(ifname, RTA_DATA(attr), RTA_PAYLOAD(attr)); | |
1070 | ifname[RTA_PAYLOAD(attr)] = '\0'; | |
1071 | break; | |
1072 | case IFLA_MASTER: | |
1073 | brid = nla_get_u32((struct nlattr *) attr); | |
1074 | pos += os_snprintf(pos, end - pos, " master=%u", brid); | |
1075 | break; | |
1076 | case IFLA_WIRELESS: | |
1077 | pos += os_snprintf(pos, end - pos, " wext"); | |
1078 | break; | |
1079 | case IFLA_OPERSTATE: | |
1080 | pos += os_snprintf(pos, end - pos, " operstate=%u", | |
1081 | nla_get_u32((struct nlattr *) attr)); | |
1082 | break; | |
1083 | case IFLA_LINKMODE: | |
1084 | pos += os_snprintf(pos, end - pos, " linkmode=%u", | |
1085 | nla_get_u32((struct nlattr *) attr)); | |
1086 | break; | |
1087 | } | |
1088 | attr = RTA_NEXT(attr, attrlen); | |
1089 | } | |
1090 | extra[sizeof(extra) - 1] = '\0'; | |
1091 | ||
f2e90835 JM |
1092 | wpa_printf(MSG_DEBUG, "RTM_NEWLINK: ifi_index=%d ifname=%s%s ifi_family=%d ifi_flags=0x%x (%s%s%s%s)", |
1093 | ifi->ifi_index, ifname, extra, ifi->ifi_family, | |
1094 | ifi->ifi_flags, | |
3f5285e8 JM |
1095 | (ifi->ifi_flags & IFF_UP) ? "[UP]" : "", |
1096 | (ifi->ifi_flags & IFF_RUNNING) ? "[RUNNING]" : "", | |
1097 | (ifi->ifi_flags & IFF_LOWER_UP) ? "[LOWER_UP]" : "", | |
1098 | (ifi->ifi_flags & IFF_DORMANT) ? "[DORMANT]" : ""); | |
a63063b4 | 1099 | |
5e0c20ff | 1100 | drv = nl80211_find_drv(global, ifi->ifi_index, buf, len, &init_failed); |
45e3fc72 RM |
1101 | if (!drv) |
1102 | goto event_newlink; | |
5e0c20ff JM |
1103 | if (init_failed) |
1104 | return; /* do not update interface state */ | |
45e3fc72 | 1105 | |
a63063b4 | 1106 | if (!drv->if_disabled && !(ifi->ifi_flags & IFF_UP)) { |
106fa1e9 | 1107 | namebuf[0] = '\0'; |
59d24925 | 1108 | if (if_indextoname(ifi->ifi_index, namebuf) && |
106fa1e9 | 1109 | linux_iface_up(drv->global->ioctl_sock, namebuf) > 0) { |
59d24925 JM |
1110 | wpa_printf(MSG_DEBUG, "nl80211: Ignore interface down " |
1111 | "event since interface %s is up", namebuf); | |
7a94120e | 1112 | drv->ignore_if_down_event = 0; |
77a020a1 BG |
1113 | /* Re-read MAC address as it may have changed */ |
1114 | nl80211_refresh_mac(drv, ifi->ifi_index, 1); | |
59d24925 JM |
1115 | return; |
1116 | } | |
106fa1e9 JM |
1117 | wpa_printf(MSG_DEBUG, "nl80211: Interface down (%s/%s)", |
1118 | namebuf, ifname); | |
1119 | if (os_strcmp(drv->first_bss->ifname, ifname) != 0) { | |
1120 | wpa_printf(MSG_DEBUG, | |
1121 | "nl80211: Not the main interface (%s) - do not indicate interface down", | |
1122 | drv->first_bss->ifname); | |
1123 | } else if (drv->ignore_if_down_event) { | |
7d9c3698 JM |
1124 | wpa_printf(MSG_DEBUG, "nl80211: Ignore interface down " |
1125 | "event generated by mode change"); | |
1126 | drv->ignore_if_down_event = 0; | |
1127 | } else { | |
1128 | drv->if_disabled = 1; | |
1129 | wpa_supplicant_event(drv->ctx, | |
1130 | EVENT_INTERFACE_DISABLED, NULL); | |
819f096f AO |
1131 | |
1132 | /* | |
1133 | * Try to get drv again, since it may be removed as | |
1134 | * part of the EVENT_INTERFACE_DISABLED handling for | |
1135 | * dynamic interfaces | |
1136 | */ | |
1137 | drv = nl80211_find_drv(global, ifi->ifi_index, | |
5e0c20ff | 1138 | buf, len, NULL); |
819f096f AO |
1139 | if (!drv) |
1140 | return; | |
7d9c3698 | 1141 | } |
a63063b4 JM |
1142 | } |
1143 | ||
1144 | if (drv->if_disabled && (ifi->ifi_flags & IFF_UP)) { | |
8a9950f7 | 1145 | namebuf[0] = '\0'; |
aef85ba2 | 1146 | if (if_indextoname(ifi->ifi_index, namebuf) && |
106fa1e9 | 1147 | linux_iface_up(drv->global->ioctl_sock, namebuf) == 0) { |
aef85ba2 JM |
1148 | wpa_printf(MSG_DEBUG, "nl80211: Ignore interface up " |
1149 | "event since interface %s is down", | |
1150 | namebuf); | |
8a9950f7 HW |
1151 | return; |
1152 | } | |
1153 | wpa_printf(MSG_DEBUG, "nl80211: Interface up (%s/%s)", | |
1154 | namebuf, ifname); | |
1155 | if (os_strcmp(drv->first_bss->ifname, ifname) != 0) { | |
1156 | wpa_printf(MSG_DEBUG, | |
1157 | "nl80211: Not the main interface (%s) - do not indicate interface up", | |
1158 | drv->first_bss->ifname); | |
834ee56f | 1159 | } else if (if_nametoindex(drv->first_bss->ifname) == 0) { |
d1f4942b JM |
1160 | wpa_printf(MSG_DEBUG, "nl80211: Ignore interface up " |
1161 | "event since interface %s does not exist", | |
834ee56f | 1162 | drv->first_bss->ifname); |
d1f4942b JM |
1163 | } else if (drv->if_removed) { |
1164 | wpa_printf(MSG_DEBUG, "nl80211: Ignore interface up " | |
1165 | "event since interface %s is marked " | |
834ee56f | 1166 | "removed", drv->first_bss->ifname); |
aef85ba2 | 1167 | } else { |
3e0272ca | 1168 | /* Re-read MAC address as it may have changed */ |
77a020a1 | 1169 | nl80211_refresh_mac(drv, ifi->ifi_index, 0); |
3e0272ca | 1170 | |
aef85ba2 JM |
1171 | drv->if_disabled = 0; |
1172 | wpa_supplicant_event(drv->ctx, EVENT_INTERFACE_ENABLED, | |
1173 | NULL); | |
1174 | } | |
a63063b4 JM |
1175 | } |
1176 | ||
3f5285e8 JM |
1177 | /* |
1178 | * Some drivers send the association event before the operup event--in | |
1179 | * this case, lifting operstate in wpa_driver_nl80211_set_operstate() | |
1180 | * fails. This will hit us when wpa_supplicant does not need to do | |
1181 | * IEEE 802.1X authentication | |
1182 | */ | |
1183 | if (drv->operstate == 1 && | |
1184 | (ifi->ifi_flags & (IFF_LOWER_UP | IFF_DORMANT)) == IFF_LOWER_UP && | |
90a545cc JM |
1185 | !(ifi->ifi_flags & IFF_RUNNING)) { |
1186 | wpa_printf(MSG_DEBUG, "nl80211: Set IF_OPER_UP again based on ifi_flags and expected operstate"); | |
36d84860 | 1187 | netlink_send_oper_ifla(drv->global->netlink, drv->ifindex, |
e2d02c29 | 1188 | -1, IF_OPER_UP); |
3f5285e8 | 1189 | } |
97cfcf64 | 1190 | |
45e3fc72 | 1191 | event_newlink: |
90a545cc | 1192 | if (ifname[0]) |
45e3fc72 RM |
1193 | wpa_driver_nl80211_event_newlink(global, drv, ifi->ifi_index, |
1194 | ifname); | |
90a545cc | 1195 | |
45e3fc72 | 1196 | if (ifi->ifi_family == AF_BRIDGE && brid && drv) { |
392dfd37 JM |
1197 | struct i802_bss *bss; |
1198 | ||
97cfcf64 | 1199 | /* device has been added to bridge */ |
40e76396 JM |
1200 | if (!if_indextoname(brid, namebuf)) { |
1201 | wpa_printf(MSG_DEBUG, | |
1202 | "nl80211: Could not find bridge ifname for ifindex %u", | |
1203 | brid); | |
1204 | return; | |
1205 | } | |
97cfcf64 B |
1206 | wpa_printf(MSG_DEBUG, "nl80211: Add ifindex %u for bridge %s", |
1207 | brid, namebuf); | |
732b1d20 | 1208 | add_ifidx(drv, brid, ifi->ifi_index); |
392dfd37 JM |
1209 | |
1210 | for (bss = drv->first_bss; bss; bss = bss->next) { | |
1211 | if (os_strcmp(ifname, bss->ifname) == 0) { | |
1212 | os_strlcpy(bss->brname, namebuf, IFNAMSIZ); | |
1213 | break; | |
1214 | } | |
1215 | } | |
97cfcf64 | 1216 | } |
3f5285e8 JM |
1217 | } |
1218 | ||
1219 | ||
62d680c3 JM |
1220 | static void wpa_driver_nl80211_event_rtm_dellink(void *ctx, |
1221 | struct ifinfomsg *ifi, | |
1222 | u8 *buf, size_t len) | |
3f5285e8 | 1223 | { |
36d84860 BG |
1224 | struct nl80211_global *global = ctx; |
1225 | struct wpa_driver_nl80211_data *drv; | |
90a545cc | 1226 | int attrlen; |
62d680c3 | 1227 | struct rtattr *attr; |
97cfcf64 | 1228 | u32 brid = 0; |
90a545cc | 1229 | char ifname[IFNAMSIZ + 1]; |
f2e90835 | 1230 | char extra[100], *pos, *end; |
3f5285e8 | 1231 | |
f2e90835 JM |
1232 | extra[0] = '\0'; |
1233 | pos = extra; | |
1234 | end = pos + sizeof(extra); | |
90a545cc JM |
1235 | ifname[0] = '\0'; |
1236 | ||
62d680c3 JM |
1237 | attrlen = len; |
1238 | attr = (struct rtattr *) buf; | |
3f5285e8 | 1239 | while (RTA_OK(attr, attrlen)) { |
90a545cc JM |
1240 | switch (attr->rta_type) { |
1241 | case IFLA_IFNAME: | |
1242 | if (RTA_PAYLOAD(attr) >= IFNAMSIZ) | |
1243 | break; | |
1244 | os_memcpy(ifname, RTA_DATA(attr), RTA_PAYLOAD(attr)); | |
1245 | ifname[RTA_PAYLOAD(attr)] = '\0'; | |
1246 | break; | |
1247 | case IFLA_MASTER: | |
97cfcf64 | 1248 | brid = nla_get_u32((struct nlattr *) attr); |
f2e90835 JM |
1249 | pos += os_snprintf(pos, end - pos, " master=%u", brid); |
1250 | break; | |
1251 | case IFLA_OPERSTATE: | |
1252 | pos += os_snprintf(pos, end - pos, " operstate=%u", | |
1253 | nla_get_u32((struct nlattr *) attr)); | |
1254 | break; | |
1255 | case IFLA_LINKMODE: | |
1256 | pos += os_snprintf(pos, end - pos, " linkmode=%u", | |
1257 | nla_get_u32((struct nlattr *) attr)); | |
90a545cc JM |
1258 | break; |
1259 | } | |
3f5285e8 JM |
1260 | attr = RTA_NEXT(attr, attrlen); |
1261 | } | |
f2e90835 JM |
1262 | extra[sizeof(extra) - 1] = '\0'; |
1263 | ||
1264 | wpa_printf(MSG_DEBUG, "RTM_DELLINK: ifi_index=%d ifname=%s%s ifi_family=%d ifi_flags=0x%x (%s%s%s%s)", | |
1265 | ifi->ifi_index, ifname, extra, ifi->ifi_family, | |
1266 | ifi->ifi_flags, | |
1267 | (ifi->ifi_flags & IFF_UP) ? "[UP]" : "", | |
1268 | (ifi->ifi_flags & IFF_RUNNING) ? "[RUNNING]" : "", | |
1269 | (ifi->ifi_flags & IFF_LOWER_UP) ? "[LOWER_UP]" : "", | |
1270 | (ifi->ifi_flags & IFF_DORMANT) ? "[DORMANT]" : ""); | |
97cfcf64 | 1271 | |
5e0c20ff | 1272 | drv = nl80211_find_drv(global, ifi->ifi_index, buf, len, NULL); |
90a545cc | 1273 | |
45e3fc72 | 1274 | if (ifi->ifi_family == AF_BRIDGE && brid && drv) { |
97cfcf64 B |
1275 | /* device has been removed from bridge */ |
1276 | char namebuf[IFNAMSIZ]; | |
40e76396 JM |
1277 | |
1278 | if (!if_indextoname(brid, namebuf)) { | |
1279 | wpa_printf(MSG_DEBUG, | |
1280 | "nl80211: Could not find bridge ifname for ifindex %u", | |
1281 | brid); | |
1282 | } else { | |
1283 | wpa_printf(MSG_DEBUG, | |
1284 | "nl80211: Remove ifindex %u for bridge %s", | |
1285 | brid, namebuf); | |
1286 | } | |
732b1d20 | 1287 | del_ifidx(drv, brid, ifi->ifi_index); |
97cfcf64 | 1288 | } |
45e3fc72 RM |
1289 | |
1290 | if (ifi->ifi_family != AF_BRIDGE || !brid) | |
1291 | wpa_driver_nl80211_event_dellink(global, drv, ifi->ifi_index, | |
1292 | ifname); | |
3f5285e8 JM |
1293 | } |
1294 | ||
1295 | ||
a1fce391 JM |
1296 | struct nl80211_get_assoc_freq_arg { |
1297 | struct wpa_driver_nl80211_data *drv; | |
1298 | unsigned int assoc_freq; | |
1299 | unsigned int ibss_freq; | |
1300 | u8 assoc_bssid[ETH_ALEN]; | |
ed0a4ddc NW |
1301 | u8 assoc_ssid[SSID_MAX_LEN]; |
1302 | u8 assoc_ssid_len; | |
a1fce391 JM |
1303 | }; |
1304 | ||
1305 | static int nl80211_get_assoc_freq_handler(struct nl_msg *msg, void *arg) | |
1306 | { | |
1307 | struct nlattr *tb[NL80211_ATTR_MAX + 1]; | |
1308 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); | |
1309 | struct nlattr *bss[NL80211_BSS_MAX + 1]; | |
1310 | static struct nla_policy bss_policy[NL80211_BSS_MAX + 1] = { | |
1311 | [NL80211_BSS_BSSID] = { .type = NLA_UNSPEC }, | |
1312 | [NL80211_BSS_FREQUENCY] = { .type = NLA_U32 }, | |
ed0a4ddc | 1313 | [NL80211_BSS_INFORMATION_ELEMENTS] = { .type = NLA_UNSPEC }, |
a1fce391 JM |
1314 | [NL80211_BSS_STATUS] = { .type = NLA_U32 }, |
1315 | }; | |
1316 | struct nl80211_get_assoc_freq_arg *ctx = arg; | |
1317 | enum nl80211_bss_status status; | |
1318 | ||
1319 | nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), | |
1320 | genlmsg_attrlen(gnlh, 0), NULL); | |
1321 | if (!tb[NL80211_ATTR_BSS] || | |
1322 | nla_parse_nested(bss, NL80211_BSS_MAX, tb[NL80211_ATTR_BSS], | |
1323 | bss_policy) || | |
1324 | !bss[NL80211_BSS_STATUS]) | |
1325 | return NL_SKIP; | |
1326 | ||
1327 | status = nla_get_u32(bss[NL80211_BSS_STATUS]); | |
1328 | if (status == NL80211_BSS_STATUS_ASSOCIATED && | |
1329 | bss[NL80211_BSS_FREQUENCY]) { | |
1330 | ctx->assoc_freq = nla_get_u32(bss[NL80211_BSS_FREQUENCY]); | |
1331 | wpa_printf(MSG_DEBUG, "nl80211: Associated on %u MHz", | |
1332 | ctx->assoc_freq); | |
1333 | } | |
1334 | if (status == NL80211_BSS_STATUS_IBSS_JOINED && | |
1335 | bss[NL80211_BSS_FREQUENCY]) { | |
1336 | ctx->ibss_freq = nla_get_u32(bss[NL80211_BSS_FREQUENCY]); | |
1337 | wpa_printf(MSG_DEBUG, "nl80211: IBSS-joined on %u MHz", | |
1338 | ctx->ibss_freq); | |
1339 | } | |
1340 | if (status == NL80211_BSS_STATUS_ASSOCIATED && | |
1341 | bss[NL80211_BSS_BSSID]) { | |
1342 | os_memcpy(ctx->assoc_bssid, | |
1343 | nla_data(bss[NL80211_BSS_BSSID]), ETH_ALEN); | |
1344 | wpa_printf(MSG_DEBUG, "nl80211: Associated with " | |
1345 | MACSTR, MAC2STR(ctx->assoc_bssid)); | |
1346 | } | |
1347 | ||
ed0a4ddc NW |
1348 | if (status == NL80211_BSS_STATUS_ASSOCIATED && |
1349 | bss[NL80211_BSS_INFORMATION_ELEMENTS]) { | |
1350 | const u8 *ie, *ssid; | |
1351 | size_t ie_len; | |
1352 | ||
1353 | ie = nla_data(bss[NL80211_BSS_INFORMATION_ELEMENTS]); | |
1354 | ie_len = nla_len(bss[NL80211_BSS_INFORMATION_ELEMENTS]); | |
1355 | ssid = get_ie(ie, ie_len, WLAN_EID_SSID); | |
1356 | if (ssid && ssid[1] > 0 && ssid[1] <= SSID_MAX_LEN) { | |
1357 | ctx->assoc_ssid_len = ssid[1]; | |
1358 | os_memcpy(ctx->assoc_ssid, ssid + 2, ssid[1]); | |
1359 | } | |
1360 | } | |
1361 | ||
a1fce391 JM |
1362 | return NL_SKIP; |
1363 | } | |
1364 | ||
1365 | ||
ed0a4ddc NW |
1366 | int nl80211_get_assoc_ssid(struct wpa_driver_nl80211_data *drv, u8 *ssid) |
1367 | { | |
1368 | struct nl_msg *msg; | |
1369 | int ret; | |
1370 | struct nl80211_get_assoc_freq_arg arg; | |
1371 | ||
1372 | msg = nl80211_drv_msg(drv, NLM_F_DUMP, NL80211_CMD_GET_SCAN); | |
1373 | os_memset(&arg, 0, sizeof(arg)); | |
1374 | arg.drv = drv; | |
1375 | ret = send_and_recv_msgs(drv, msg, nl80211_get_assoc_freq_handler, | |
1376 | &arg); | |
1377 | if (ret == 0) { | |
1378 | os_memcpy(ssid, arg.assoc_ssid, arg.assoc_ssid_len); | |
1379 | return arg.assoc_ssid_len; | |
1380 | } | |
1381 | wpa_printf(MSG_DEBUG, "nl80211: Scan result fetch failed: ret=%d (%s)", | |
1382 | ret, strerror(-ret)); | |
1383 | return ret; | |
1384 | } | |
1385 | ||
1386 | ||
f3407c66 | 1387 | unsigned int nl80211_get_assoc_freq(struct wpa_driver_nl80211_data *drv) |
f5a8d422 JM |
1388 | { |
1389 | struct nl_msg *msg; | |
1390 | int ret; | |
a1fce391 | 1391 | struct nl80211_get_assoc_freq_arg arg; |
f5a8d422 | 1392 | |
9725b784 | 1393 | msg = nl80211_drv_msg(drv, NLM_F_DUMP, NL80211_CMD_GET_SCAN); |
f5a8d422 | 1394 | os_memset(&arg, 0, sizeof(arg)); |
f5a8d422 | 1395 | arg.drv = drv; |
a1fce391 JM |
1396 | ret = send_and_recv_msgs(drv, msg, nl80211_get_assoc_freq_handler, |
1397 | &arg); | |
f5a8d422 | 1398 | if (ret == 0) { |
c7caac56 JM |
1399 | unsigned int freq = drv->nlmode == NL80211_IFTYPE_ADHOC ? |
1400 | arg.ibss_freq : arg.assoc_freq; | |
f5a8d422 | 1401 | wpa_printf(MSG_DEBUG, "nl80211: Operating frequency for the " |
c7caac56 JM |
1402 | "associated BSS from scan results: %u MHz", freq); |
1403 | if (freq) | |
1404 | drv->assoc_freq = freq; | |
30158a0d | 1405 | return drv->assoc_freq; |
f5a8d422 JM |
1406 | } |
1407 | wpa_printf(MSG_DEBUG, "nl80211: Scan result fetch failed: ret=%d " | |
1408 | "(%s)", ret, strerror(-ret)); | |
f5a8d422 JM |
1409 | return drv->assoc_freq; |
1410 | } | |
1411 | ||
1412 | ||
60a972a6 JM |
1413 | static int get_link_signal(struct nl_msg *msg, void *arg) |
1414 | { | |
1415 | struct nlattr *tb[NL80211_ATTR_MAX + 1]; | |
1416 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); | |
1417 | struct nlattr *sinfo[NL80211_STA_INFO_MAX + 1]; | |
1418 | static struct nla_policy policy[NL80211_STA_INFO_MAX + 1] = { | |
1419 | [NL80211_STA_INFO_SIGNAL] = { .type = NLA_U8 }, | |
95783298 | 1420 | [NL80211_STA_INFO_SIGNAL_AVG] = { .type = NLA_U8 }, |
74fa78b2 | 1421 | [NL80211_STA_INFO_BEACON_SIGNAL_AVG] = { .type = NLA_U8 }, |
60a972a6 | 1422 | }; |
7ee35bf3 PS |
1423 | struct nlattr *rinfo[NL80211_RATE_INFO_MAX + 1]; |
1424 | static struct nla_policy rate_policy[NL80211_RATE_INFO_MAX + 1] = { | |
1425 | [NL80211_RATE_INFO_BITRATE] = { .type = NLA_U16 }, | |
1426 | [NL80211_RATE_INFO_MCS] = { .type = NLA_U8 }, | |
1427 | [NL80211_RATE_INFO_40_MHZ_WIDTH] = { .type = NLA_FLAG }, | |
1428 | [NL80211_RATE_INFO_SHORT_GI] = { .type = NLA_FLAG }, | |
1429 | }; | |
1c5c7273 | 1430 | struct wpa_signal_info *sig_change = arg; |
60a972a6 JM |
1431 | |
1432 | nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), | |
1433 | genlmsg_attrlen(gnlh, 0), NULL); | |
1434 | if (!tb[NL80211_ATTR_STA_INFO] || | |
1435 | nla_parse_nested(sinfo, NL80211_STA_INFO_MAX, | |
1436 | tb[NL80211_ATTR_STA_INFO], policy)) | |
1437 | return NL_SKIP; | |
1438 | if (!sinfo[NL80211_STA_INFO_SIGNAL]) | |
1439 | return NL_SKIP; | |
1440 | ||
7ee35bf3 PS |
1441 | sig_change->current_signal = |
1442 | (s8) nla_get_u8(sinfo[NL80211_STA_INFO_SIGNAL]); | |
1443 | ||
95783298 AO |
1444 | if (sinfo[NL80211_STA_INFO_SIGNAL_AVG]) |
1445 | sig_change->avg_signal = | |
1446 | (s8) nla_get_u8(sinfo[NL80211_STA_INFO_SIGNAL_AVG]); | |
1447 | else | |
1448 | sig_change->avg_signal = 0; | |
1449 | ||
74fa78b2 JM |
1450 | if (sinfo[NL80211_STA_INFO_BEACON_SIGNAL_AVG]) |
1451 | sig_change->avg_beacon_signal = | |
1452 | (s8) | |
1453 | nla_get_u8(sinfo[NL80211_STA_INFO_BEACON_SIGNAL_AVG]); | |
1454 | else | |
1455 | sig_change->avg_beacon_signal = 0; | |
1456 | ||
7ee35bf3 PS |
1457 | if (sinfo[NL80211_STA_INFO_TX_BITRATE]) { |
1458 | if (nla_parse_nested(rinfo, NL80211_RATE_INFO_MAX, | |
1459 | sinfo[NL80211_STA_INFO_TX_BITRATE], | |
1460 | rate_policy)) { | |
1461 | sig_change->current_txrate = 0; | |
1462 | } else { | |
1463 | if (rinfo[NL80211_RATE_INFO_BITRATE]) { | |
1464 | sig_change->current_txrate = | |
1465 | nla_get_u16(rinfo[ | |
1466 | NL80211_RATE_INFO_BITRATE]) * 100; | |
1467 | } | |
1468 | } | |
1469 | } | |
1470 | ||
60a972a6 JM |
1471 | return NL_SKIP; |
1472 | } | |
1473 | ||
1474 | ||
f3407c66 JM |
1475 | int nl80211_get_link_signal(struct wpa_driver_nl80211_data *drv, |
1476 | struct wpa_signal_info *sig) | |
60a972a6 JM |
1477 | { |
1478 | struct nl_msg *msg; | |
1479 | ||
941807f6 | 1480 | sig->current_signal = -WPA_INVALID_NOISE; |
7ee35bf3 | 1481 | sig->current_txrate = 0; |
60a972a6 | 1482 | |
9725b784 | 1483 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_GET_STATION)) || |
a862e4a3 JM |
1484 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, drv->bssid)) { |
1485 | nlmsg_free(msg); | |
1486 | return -ENOBUFS; | |
1487 | } | |
60a972a6 JM |
1488 | |
1489 | return send_and_recv_msgs(drv, msg, get_link_signal, sig); | |
60a972a6 JM |
1490 | } |
1491 | ||
1492 | ||
7ee35bf3 PS |
1493 | static int get_link_noise(struct nl_msg *msg, void *arg) |
1494 | { | |
1495 | struct nlattr *tb[NL80211_ATTR_MAX + 1]; | |
1496 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); | |
1497 | struct nlattr *sinfo[NL80211_SURVEY_INFO_MAX + 1]; | |
1498 | static struct nla_policy survey_policy[NL80211_SURVEY_INFO_MAX + 1] = { | |
1499 | [NL80211_SURVEY_INFO_FREQUENCY] = { .type = NLA_U32 }, | |
1500 | [NL80211_SURVEY_INFO_NOISE] = { .type = NLA_U8 }, | |
1501 | }; | |
1c5c7273 | 1502 | struct wpa_signal_info *sig_change = arg; |
7ee35bf3 PS |
1503 | |
1504 | nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), | |
1505 | genlmsg_attrlen(gnlh, 0), NULL); | |
1506 | ||
1507 | if (!tb[NL80211_ATTR_SURVEY_INFO]) { | |
1508 | wpa_printf(MSG_DEBUG, "nl80211: survey data missing!"); | |
1509 | return NL_SKIP; | |
1510 | } | |
1511 | ||
1512 | if (nla_parse_nested(sinfo, NL80211_SURVEY_INFO_MAX, | |
1513 | tb[NL80211_ATTR_SURVEY_INFO], | |
1514 | survey_policy)) { | |
1515 | wpa_printf(MSG_DEBUG, "nl80211: failed to parse nested " | |
1516 | "attributes!"); | |
1517 | return NL_SKIP; | |
1518 | } | |
1519 | ||
1520 | if (!sinfo[NL80211_SURVEY_INFO_FREQUENCY]) | |
1521 | return NL_SKIP; | |
1522 | ||
1523 | if (nla_get_u32(sinfo[NL80211_SURVEY_INFO_FREQUENCY]) != | |
1524 | sig_change->frequency) | |
1525 | return NL_SKIP; | |
1526 | ||
1527 | if (!sinfo[NL80211_SURVEY_INFO_NOISE]) | |
1528 | return NL_SKIP; | |
1529 | ||
1530 | sig_change->current_noise = | |
1531 | (s8) nla_get_u8(sinfo[NL80211_SURVEY_INFO_NOISE]); | |
1532 | ||
1533 | return NL_SKIP; | |
1534 | } | |
1535 | ||
1536 | ||
f3407c66 JM |
1537 | int nl80211_get_link_noise(struct wpa_driver_nl80211_data *drv, |
1538 | struct wpa_signal_info *sig_change) | |
7ee35bf3 PS |
1539 | { |
1540 | struct nl_msg *msg; | |
1541 | ||
941807f6 | 1542 | sig_change->current_noise = WPA_INVALID_NOISE; |
7ee35bf3 PS |
1543 | sig_change->frequency = drv->assoc_freq; |
1544 | ||
9725b784 | 1545 | msg = nl80211_drv_msg(drv, NLM_F_DUMP, NL80211_CMD_GET_SURVEY); |
7ee35bf3 | 1546 | return send_and_recv_msgs(drv, msg, get_link_noise, sig_change); |
7ee35bf3 PS |
1547 | } |
1548 | ||
1549 | ||
7f00dc6e MV |
1550 | static int get_channel_info(struct nl_msg *msg, void *arg) |
1551 | { | |
1552 | struct nlattr *tb[NL80211_ATTR_MAX + 1] = { 0 }; | |
1553 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); | |
1554 | struct wpa_channel_info *chan_info = arg; | |
1555 | ||
1556 | nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), | |
1557 | genlmsg_attrlen(gnlh, 0), NULL); | |
1558 | ||
1559 | os_memset(chan_info, 0, sizeof(struct wpa_channel_info)); | |
1560 | chan_info->chanwidth = CHAN_WIDTH_UNKNOWN; | |
1561 | ||
1562 | if (tb[NL80211_ATTR_WIPHY_FREQ]) | |
1563 | chan_info->frequency = | |
1564 | nla_get_u32(tb[NL80211_ATTR_WIPHY_FREQ]); | |
1565 | if (tb[NL80211_ATTR_CHANNEL_WIDTH]) | |
1566 | chan_info->chanwidth = convert2width( | |
1567 | nla_get_u32(tb[NL80211_ATTR_CHANNEL_WIDTH])); | |
1568 | if (tb[NL80211_ATTR_WIPHY_CHANNEL_TYPE]) { | |
1569 | enum nl80211_channel_type ct = | |
1570 | nla_get_u32(tb[NL80211_ATTR_WIPHY_CHANNEL_TYPE]); | |
1571 | ||
1572 | switch (ct) { | |
1573 | case NL80211_CHAN_HT40MINUS: | |
1574 | chan_info->sec_channel = -1; | |
1575 | break; | |
1576 | case NL80211_CHAN_HT40PLUS: | |
1577 | chan_info->sec_channel = 1; | |
1578 | break; | |
1579 | default: | |
1580 | chan_info->sec_channel = 0; | |
1581 | break; | |
1582 | } | |
1583 | } | |
1584 | if (tb[NL80211_ATTR_CENTER_FREQ1]) | |
1585 | chan_info->center_frq1 = | |
1586 | nla_get_u32(tb[NL80211_ATTR_CENTER_FREQ1]); | |
1587 | if (tb[NL80211_ATTR_CENTER_FREQ2]) | |
1588 | chan_info->center_frq2 = | |
1589 | nla_get_u32(tb[NL80211_ATTR_CENTER_FREQ2]); | |
1590 | ||
1591 | if (chan_info->center_frq2) { | |
1592 | u8 seg1_idx = 0; | |
1593 | ||
1594 | if (ieee80211_freq_to_chan(chan_info->center_frq2, &seg1_idx) != | |
1595 | NUM_HOSTAPD_MODES) | |
1596 | chan_info->seg1_idx = seg1_idx; | |
1597 | } | |
1598 | ||
1599 | return NL_SKIP; | |
1600 | } | |
1601 | ||
1602 | ||
1603 | static int nl80211_channel_info(void *priv, struct wpa_channel_info *ci) | |
1604 | { | |
1605 | struct i802_bss *bss = priv; | |
1606 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
1607 | struct nl_msg *msg; | |
1608 | ||
1609 | msg = nl80211_drv_msg(drv, 0, NL80211_CMD_GET_INTERFACE); | |
1610 | return send_and_recv_msgs(drv, msg, get_channel_info, ci); | |
1611 | } | |
1612 | ||
1613 | ||
97865538 | 1614 | static void wpa_driver_nl80211_event_receive(int sock, void *eloop_ctx, |
5582a5d1 | 1615 | void *handle) |
97865538 | 1616 | { |
a4ae123c | 1617 | struct nl_cb *cb = eloop_ctx; |
34068ac3 | 1618 | int res; |
97865538 | 1619 | |
cc2ada86 | 1620 | wpa_printf(MSG_MSGDUMP, "nl80211: Event message available"); |
97865538 | 1621 | |
34068ac3 | 1622 | res = nl_recvmsgs(handle, cb); |
d3d04831 | 1623 | if (res < 0) { |
34068ac3 JM |
1624 | wpa_printf(MSG_INFO, "nl80211: %s->nl_recvmsgs failed: %d", |
1625 | __func__, res); | |
1626 | } | |
97865538 JM |
1627 | } |
1628 | ||
1629 | ||
6d158490 LR |
1630 | /** |
1631 | * wpa_driver_nl80211_set_country - ask nl80211 to set the regulatory domain | |
1632 | * @priv: driver_nl80211 private data | |
1633 | * @alpha2_arg: country to which to switch to | |
1634 | * Returns: 0 on success, -1 on failure | |
1635 | * | |
1636 | * This asks nl80211 to set the regulatory domain for given | |
1637 | * country ISO / IEC alpha2. | |
1638 | */ | |
1639 | static int wpa_driver_nl80211_set_country(void *priv, const char *alpha2_arg) | |
1640 | { | |
a2e40bb6 FF |
1641 | struct i802_bss *bss = priv; |
1642 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
6d158490 LR |
1643 | char alpha2[3]; |
1644 | struct nl_msg *msg; | |
1645 | ||
1646 | msg = nlmsg_alloc(); | |
1647 | if (!msg) | |
e785c2ba | 1648 | return -ENOMEM; |
6d158490 LR |
1649 | |
1650 | alpha2[0] = alpha2_arg[0]; | |
1651 | alpha2[1] = alpha2_arg[1]; | |
1652 | alpha2[2] = '\0'; | |
1653 | ||
a862e4a3 JM |
1654 | if (!nl80211_cmd(drv, msg, 0, NL80211_CMD_REQ_SET_REG) || |
1655 | nla_put_string(msg, NL80211_ATTR_REG_ALPHA2, alpha2)) { | |
1656 | nlmsg_free(msg); | |
1657 | return -EINVAL; | |
1658 | } | |
6d158490 LR |
1659 | if (send_and_recv_msgs(drv, msg, NULL, NULL)) |
1660 | return -EINVAL; | |
1661 | return 0; | |
6d158490 LR |
1662 | } |
1663 | ||
1664 | ||
f0793bf1 JM |
1665 | static int nl80211_get_country(struct nl_msg *msg, void *arg) |
1666 | { | |
1667 | char *alpha2 = arg; | |
1668 | struct nlattr *tb_msg[NL80211_ATTR_MAX + 1]; | |
1669 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); | |
1670 | ||
1671 | nla_parse(tb_msg, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), | |
1672 | genlmsg_attrlen(gnlh, 0), NULL); | |
1673 | if (!tb_msg[NL80211_ATTR_REG_ALPHA2]) { | |
1674 | wpa_printf(MSG_DEBUG, "nl80211: No country information available"); | |
1675 | return NL_SKIP; | |
1676 | } | |
1677 | os_strlcpy(alpha2, nla_data(tb_msg[NL80211_ATTR_REG_ALPHA2]), 3); | |
1678 | return NL_SKIP; | |
1679 | } | |
1680 | ||
1681 | ||
1682 | static int wpa_driver_nl80211_get_country(void *priv, char *alpha2) | |
1683 | { | |
1684 | struct i802_bss *bss = priv; | |
1685 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
1686 | struct nl_msg *msg; | |
1687 | int ret; | |
1688 | ||
1689 | msg = nlmsg_alloc(); | |
1690 | if (!msg) | |
1691 | return -ENOMEM; | |
1692 | ||
1693 | nl80211_cmd(drv, msg, 0, NL80211_CMD_GET_REG); | |
1694 | alpha2[0] = '\0'; | |
1695 | ret = send_and_recv_msgs(drv, msg, nl80211_get_country, alpha2); | |
1696 | if (!alpha2[0]) | |
1697 | ret = -1; | |
1698 | ||
1699 | return ret; | |
1700 | } | |
1701 | ||
1702 | ||
2a7b66f5 BG |
1703 | static int wpa_driver_nl80211_init_nl_global(struct nl80211_global *global) |
1704 | { | |
d6c9aab8 JB |
1705 | int ret; |
1706 | ||
2a7b66f5 BG |
1707 | global->nl_cb = nl_cb_alloc(NL_CB_DEFAULT); |
1708 | if (global->nl_cb == NULL) { | |
1709 | wpa_printf(MSG_ERROR, "nl80211: Failed to allocate netlink " | |
1710 | "callbacks"); | |
1711 | return -1; | |
1712 | } | |
1713 | ||
481234cf JM |
1714 | global->nl = nl_create_handle(global->nl_cb, "nl"); |
1715 | if (global->nl == NULL) | |
d6c9aab8 | 1716 | goto err; |
276e2d67 | 1717 | |
481234cf | 1718 | global->nl80211_id = genl_ctrl_resolve(global->nl, "nl80211"); |
335d42b1 | 1719 | if (global->nl80211_id < 0) { |
276e2d67 BG |
1720 | wpa_printf(MSG_ERROR, "nl80211: 'nl80211' generic netlink not " |
1721 | "found"); | |
d6c9aab8 | 1722 | goto err; |
276e2d67 BG |
1723 | } |
1724 | ||
481234cf JM |
1725 | global->nl_event = nl_create_handle(global->nl_cb, "event"); |
1726 | if (global->nl_event == NULL) | |
d6c9aab8 | 1727 | goto err; |
9fff9fdc | 1728 | |
d6c9aab8 | 1729 | ret = nl_get_multicast_id(global, "nl80211", "scan"); |
97865538 | 1730 | if (ret >= 0) |
481234cf | 1731 | ret = nl_socket_add_membership(global->nl_event, ret); |
97865538 JM |
1732 | if (ret < 0) { |
1733 | wpa_printf(MSG_ERROR, "nl80211: Could not add multicast " | |
1734 | "membership for scan events: %d (%s)", | |
1735 | ret, strerror(-ret)); | |
d6c9aab8 | 1736 | goto err; |
97865538 | 1737 | } |
c2a04078 | 1738 | |
d6c9aab8 | 1739 | ret = nl_get_multicast_id(global, "nl80211", "mlme"); |
c2a04078 | 1740 | if (ret >= 0) |
481234cf | 1741 | ret = nl_socket_add_membership(global->nl_event, ret); |
c2a04078 JM |
1742 | if (ret < 0) { |
1743 | wpa_printf(MSG_ERROR, "nl80211: Could not add multicast " | |
1744 | "membership for mlme events: %d (%s)", | |
1745 | ret, strerror(-ret)); | |
d6c9aab8 | 1746 | goto err; |
c2a04078 | 1747 | } |
c2a04078 | 1748 | |
d6c9aab8 | 1749 | ret = nl_get_multicast_id(global, "nl80211", "regulatory"); |
33c5deb8 | 1750 | if (ret >= 0) |
481234cf | 1751 | ret = nl_socket_add_membership(global->nl_event, ret); |
33c5deb8 JM |
1752 | if (ret < 0) { |
1753 | wpa_printf(MSG_DEBUG, "nl80211: Could not add multicast " | |
1754 | "membership for regulatory events: %d (%s)", | |
1755 | ret, strerror(-ret)); | |
1756 | /* Continue without regulatory events */ | |
1757 | } | |
1758 | ||
17b79e65 JM |
1759 | ret = nl_get_multicast_id(global, "nl80211", "vendor"); |
1760 | if (ret >= 0) | |
1761 | ret = nl_socket_add_membership(global->nl_event, ret); | |
1762 | if (ret < 0) { | |
1763 | wpa_printf(MSG_DEBUG, "nl80211: Could not add multicast " | |
1764 | "membership for vendor events: %d (%s)", | |
1765 | ret, strerror(-ret)); | |
1766 | /* Continue without vendor events */ | |
1767 | } | |
1768 | ||
d6c9aab8 JB |
1769 | nl_cb_set(global->nl_cb, NL_CB_SEQ_CHECK, NL_CB_CUSTOM, |
1770 | no_seq_check, NULL); | |
1771 | nl_cb_set(global->nl_cb, NL_CB_VALID, NL_CB_CUSTOM, | |
1772 | process_global_event, global); | |
1773 | ||
5f65e9f7 JB |
1774 | nl80211_register_eloop_read(&global->nl_event, |
1775 | wpa_driver_nl80211_event_receive, | |
40a68f33 | 1776 | global->nl_cb, 0); |
d6c9aab8 JB |
1777 | |
1778 | return 0; | |
1779 | ||
1780 | err: | |
1781 | nl_destroy_handles(&global->nl_event); | |
1782 | nl_destroy_handles(&global->nl); | |
1783 | nl_cb_put(global->nl_cb); | |
671a5039 | 1784 | global->nl_cb = NULL; |
d6c9aab8 JB |
1785 | return -1; |
1786 | } | |
1787 | ||
1788 | ||
f51f54a0 JM |
1789 | static void nl80211_check_global(struct nl80211_global *global) |
1790 | { | |
1791 | struct nl_handle *handle; | |
1792 | const char *groups[] = { "scan", "mlme", "regulatory", "vendor", NULL }; | |
1793 | int ret; | |
1794 | unsigned int i; | |
1795 | ||
1796 | /* | |
1797 | * Try to re-add memberships to handle case of cfg80211 getting reloaded | |
1798 | * and all registration having been cleared. | |
1799 | */ | |
1800 | handle = (void *) (((intptr_t) global->nl_event) ^ | |
1801 | ELOOP_SOCKET_INVALID); | |
1802 | ||
1803 | for (i = 0; groups[i]; i++) { | |
1804 | ret = nl_get_multicast_id(global, "nl80211", groups[i]); | |
1805 | if (ret >= 0) | |
1806 | ret = nl_socket_add_membership(handle, ret); | |
1807 | if (ret < 0) { | |
1808 | wpa_printf(MSG_INFO, | |
1809 | "nl80211: Could not re-add multicast membership for %s events: %d (%s)", | |
1810 | groups[i], ret, strerror(-ret)); | |
1811 | } | |
1812 | } | |
1813 | } | |
1814 | ||
1815 | ||
8401a6b0 JM |
1816 | static void wpa_driver_nl80211_rfkill_blocked(void *ctx) |
1817 | { | |
6da504a1 IP |
1818 | struct wpa_driver_nl80211_data *drv = ctx; |
1819 | ||
8401a6b0 | 1820 | wpa_printf(MSG_DEBUG, "nl80211: RFKILL blocked"); |
6da504a1 | 1821 | |
a63063b4 | 1822 | /* |
6da504a1 IP |
1823 | * rtnetlink ifdown handler will report interfaces other than the P2P |
1824 | * Device interface as disabled. | |
a63063b4 | 1825 | */ |
6da504a1 IP |
1826 | if (drv->nlmode == NL80211_IFTYPE_P2P_DEVICE) |
1827 | wpa_supplicant_event(drv->ctx, EVENT_INTERFACE_DISABLED, NULL); | |
8401a6b0 JM |
1828 | } |
1829 | ||
1830 | ||
1831 | static void wpa_driver_nl80211_rfkill_unblocked(void *ctx) | |
1832 | { | |
1833 | struct wpa_driver_nl80211_data *drv = ctx; | |
1834 | wpa_printf(MSG_DEBUG, "nl80211: RFKILL unblocked"); | |
834ee56f | 1835 | if (i802_set_iface_flags(drv->first_bss, 1)) { |
8401a6b0 JM |
1836 | wpa_printf(MSG_DEBUG, "nl80211: Could not set interface UP " |
1837 | "after rfkill unblock"); | |
1838 | return; | |
1839 | } | |
e8dc205f AO |
1840 | |
1841 | if (is_p2p_net_interface(drv->nlmode)) | |
1842 | nl80211_disable_11b_rates(drv, drv->ifindex, 1); | |
1843 | ||
6da504a1 IP |
1844 | /* |
1845 | * rtnetlink ifup handler will report interfaces other than the P2P | |
1846 | * Device interface as enabled. | |
1847 | */ | |
1848 | if (drv->nlmode == NL80211_IFTYPE_P2P_DEVICE) | |
1849 | wpa_supplicant_event(drv->ctx, EVENT_INTERFACE_ENABLED, NULL); | |
8401a6b0 JM |
1850 | } |
1851 | ||
1852 | ||
32ab4855 JB |
1853 | static void wpa_driver_nl80211_handle_eapol_tx_status(int sock, |
1854 | void *eloop_ctx, | |
1855 | void *handle) | |
1856 | { | |
1857 | struct wpa_driver_nl80211_data *drv = eloop_ctx; | |
1858 | u8 data[2048]; | |
1859 | struct msghdr msg; | |
1860 | struct iovec entry; | |
cad0f50e | 1861 | u8 control[512]; |
32ab4855 JB |
1862 | struct cmsghdr *cmsg; |
1863 | int res, found_ee = 0, found_wifi = 0, acked = 0; | |
1864 | union wpa_event_data event; | |
1865 | ||
1866 | memset(&msg, 0, sizeof(msg)); | |
1867 | msg.msg_iov = &entry; | |
1868 | msg.msg_iovlen = 1; | |
1869 | entry.iov_base = data; | |
1870 | entry.iov_len = sizeof(data); | |
1871 | msg.msg_control = &control; | |
1872 | msg.msg_controllen = sizeof(control); | |
1873 | ||
1874 | res = recvmsg(sock, &msg, MSG_ERRQUEUE); | |
1875 | /* if error or not fitting 802.3 header, return */ | |
1876 | if (res < 14) | |
1877 | return; | |
1878 | ||
1879 | for (cmsg = CMSG_FIRSTHDR(&msg); cmsg; cmsg = CMSG_NXTHDR(&msg, cmsg)) | |
1880 | { | |
1881 | if (cmsg->cmsg_level == SOL_SOCKET && | |
1882 | cmsg->cmsg_type == SCM_WIFI_STATUS) { | |
1883 | int *ack; | |
1884 | ||
1885 | found_wifi = 1; | |
1886 | ack = (void *)CMSG_DATA(cmsg); | |
1887 | acked = *ack; | |
1888 | } | |
1889 | ||
1890 | if (cmsg->cmsg_level == SOL_PACKET && | |
1891 | cmsg->cmsg_type == PACKET_TX_TIMESTAMP) { | |
1892 | struct sock_extended_err *err = | |
1893 | (struct sock_extended_err *)CMSG_DATA(cmsg); | |
1894 | ||
1895 | if (err->ee_origin == SO_EE_ORIGIN_TXSTATUS) | |
1896 | found_ee = 1; | |
1897 | } | |
1898 | } | |
1899 | ||
1900 | if (!found_ee || !found_wifi) | |
1901 | return; | |
1902 | ||
1903 | memset(&event, 0, sizeof(event)); | |
1904 | event.eapol_tx_status.dst = data; | |
1905 | event.eapol_tx_status.data = data + 14; | |
1906 | event.eapol_tx_status.data_len = res - 14; | |
1907 | event.eapol_tx_status.ack = acked; | |
1908 | wpa_supplicant_event(drv->ctx, EVENT_EAPOL_TX_STATUS, &event); | |
1909 | } | |
1910 | ||
1911 | ||
cc7a48d1 JB |
1912 | static int nl80211_init_bss(struct i802_bss *bss) |
1913 | { | |
1914 | bss->nl_cb = nl_cb_alloc(NL_CB_DEFAULT); | |
1915 | if (!bss->nl_cb) | |
1916 | return -1; | |
1917 | ||
1918 | nl_cb_set(bss->nl_cb, NL_CB_SEQ_CHECK, NL_CB_CUSTOM, | |
1919 | no_seq_check, NULL); | |
1920 | nl_cb_set(bss->nl_cb, NL_CB_VALID, NL_CB_CUSTOM, | |
1921 | process_bss_event, bss); | |
1922 | ||
1923 | return 0; | |
1924 | } | |
1925 | ||
1926 | ||
1927 | static void nl80211_destroy_bss(struct i802_bss *bss) | |
1928 | { | |
1929 | nl_cb_put(bss->nl_cb); | |
1930 | bss->nl_cb = NULL; | |
1931 | } | |
1932 | ||
1933 | ||
0e92fb8f JB |
1934 | static void |
1935 | wpa_driver_nl80211_drv_init_rfkill(struct wpa_driver_nl80211_data *drv) | |
1936 | { | |
1937 | struct rfkill_config *rcfg; | |
1938 | ||
1939 | if (drv->rfkill) | |
1940 | return; | |
1941 | ||
1942 | rcfg = os_zalloc(sizeof(*rcfg)); | |
1943 | if (!rcfg) | |
1944 | return; | |
1945 | ||
1946 | rcfg->ctx = drv; | |
1947 | ||
1948 | /* rfkill uses netdev sysfs for initialization. However, P2P Device is | |
1949 | * not associated with a netdev, so use the name of some other interface | |
1950 | * sharing the same wiphy as the P2P Device interface. | |
1951 | * | |
1952 | * Note: This is valid, as a P2P Device interface is always dynamically | |
1953 | * created and is created only once another wpa_s interface was added. | |
1954 | */ | |
1955 | if (drv->nlmode == NL80211_IFTYPE_P2P_DEVICE) { | |
1956 | struct nl80211_global *global = drv->global; | |
1957 | struct wpa_driver_nl80211_data *tmp1; | |
1958 | ||
1959 | dl_list_for_each(tmp1, &global->interfaces, | |
1960 | struct wpa_driver_nl80211_data, list) { | |
1961 | if (drv == tmp1 || drv->wiphy_idx != tmp1->wiphy_idx || | |
1962 | !tmp1->rfkill) | |
1963 | continue; | |
1964 | ||
1965 | wpa_printf(MSG_DEBUG, | |
1966 | "nl80211: Use (%s) to initialize P2P Device rfkill", | |
1967 | tmp1->first_bss->ifname); | |
1968 | os_strlcpy(rcfg->ifname, tmp1->first_bss->ifname, | |
1969 | sizeof(rcfg->ifname)); | |
1970 | break; | |
1971 | } | |
1972 | } else { | |
1973 | os_strlcpy(rcfg->ifname, drv->first_bss->ifname, | |
1974 | sizeof(rcfg->ifname)); | |
1975 | } | |
1976 | ||
1977 | rcfg->blocked_cb = wpa_driver_nl80211_rfkill_blocked; | |
1978 | rcfg->unblocked_cb = wpa_driver_nl80211_rfkill_unblocked; | |
1979 | drv->rfkill = rfkill_init(rcfg); | |
1980 | if (!drv->rfkill) { | |
1981 | wpa_printf(MSG_DEBUG, "nl80211: RFKILL status not available"); | |
1982 | os_free(rcfg); | |
1983 | } | |
1984 | } | |
1985 | ||
1986 | ||
0d547d5f JM |
1987 | static void * wpa_driver_nl80211_drv_init(void *ctx, const char *ifname, |
1988 | void *global_priv, int hostapd, | |
0ecff8d7 JM |
1989 | const u8 *set_addr, |
1990 | const char *driver_params) | |
9fff9fdc | 1991 | { |
9fff9fdc | 1992 | struct wpa_driver_nl80211_data *drv; |
a2e40bb6 | 1993 | struct i802_bss *bss; |
9fff9fdc | 1994 | |
a5c696ad JM |
1995 | if (global_priv == NULL) |
1996 | return NULL; | |
9fff9fdc JM |
1997 | drv = os_zalloc(sizeof(*drv)); |
1998 | if (drv == NULL) | |
1999 | return NULL; | |
f2ed8023 | 2000 | drv->global = global_priv; |
9fff9fdc | 2001 | drv->ctx = ctx; |
0d547d5f JM |
2002 | drv->hostapd = !!hostapd; |
2003 | drv->eapol_sock = -1; | |
64ae2447 JM |
2004 | |
2005 | /* | |
2006 | * There is no driver capability flag for this, so assume it is | |
2007 | * supported and disable this on first attempt to use if the driver | |
2008 | * rejects the command due to missing support. | |
2009 | */ | |
2010 | drv->set_rekey_offload = 1; | |
2011 | ||
0d547d5f JM |
2012 | drv->num_if_indices = sizeof(drv->default_if_indices) / sizeof(int); |
2013 | drv->if_indices = drv->default_if_indices; | |
732b1d20 | 2014 | drv->if_indices_reason = drv->default_if_indices_reason; |
834ee56f KP |
2015 | |
2016 | drv->first_bss = os_zalloc(sizeof(*drv->first_bss)); | |
2017 | if (!drv->first_bss) { | |
2018 | os_free(drv); | |
2019 | return NULL; | |
2020 | } | |
2021 | bss = drv->first_bss; | |
a2e40bb6 | 2022 | bss->drv = drv; |
a5e1eb20 SE |
2023 | bss->ctx = ctx; |
2024 | ||
a2e40bb6 | 2025 | os_strlcpy(bss->ifname, ifname, sizeof(bss->ifname)); |
9fff9fdc JM |
2026 | drv->monitor_ifidx = -1; |
2027 | drv->monitor_sock = -1; | |
d12dab4c | 2028 | drv->eapol_tx_sock = -1; |
b1f625e0 | 2029 | drv->ap_scan_as_station = NL80211_IFTYPE_UNSPECIFIED; |
9fff9fdc | 2030 | |
cc7a48d1 JB |
2031 | if (nl80211_init_bss(bss)) |
2032 | goto failed; | |
2033 | ||
0ecff8d7 | 2034 | if (wpa_driver_nl80211_finish_drv_init(drv, set_addr, 1, driver_params)) |
bbaf0837 | 2035 | goto failed; |
7524cfb1 | 2036 | |
d12dab4c | 2037 | drv->eapol_tx_sock = socket(PF_PACKET, SOCK_DGRAM, 0); |
32ab4855 JB |
2038 | if (drv->eapol_tx_sock < 0) |
2039 | goto failed; | |
2040 | ||
2041 | if (drv->data_tx_status) { | |
2042 | int enabled = 1; | |
2043 | ||
2044 | if (setsockopt(drv->eapol_tx_sock, SOL_SOCKET, SO_WIFI_STATUS, | |
2045 | &enabled, sizeof(enabled)) < 0) { | |
2046 | wpa_printf(MSG_DEBUG, | |
2047 | "nl80211: wifi status sockopt failed\n"); | |
2048 | drv->data_tx_status = 0; | |
a11241fa JB |
2049 | if (!drv->use_monitor) |
2050 | drv->capa.flags &= | |
2051 | ~WPA_DRIVER_FLAGS_EAPOL_TX_STATUS; | |
32ab4855 JB |
2052 | } else { |
2053 | eloop_register_read_sock(drv->eapol_tx_sock, | |
2054 | wpa_driver_nl80211_handle_eapol_tx_status, | |
2055 | drv, NULL); | |
2056 | } | |
2057 | } | |
f10bfc9a | 2058 | |
dac12351 | 2059 | if (drv->global) { |
f51f54a0 | 2060 | nl80211_check_global(drv->global); |
c4bb8817 | 2061 | dl_list_add(&drv->global->interfaces, &drv->list); |
dac12351 BG |
2062 | drv->in_interface_list = 1; |
2063 | } | |
c4bb8817 | 2064 | |
a2e40bb6 | 2065 | return bss; |
7524cfb1 | 2066 | |
bbaf0837 | 2067 | failed: |
dac12351 | 2068 | wpa_driver_nl80211_deinit(bss); |
7524cfb1 JM |
2069 | return NULL; |
2070 | } | |
2071 | ||
2072 | ||
0d547d5f JM |
2073 | /** |
2074 | * wpa_driver_nl80211_init - Initialize nl80211 driver interface | |
2075 | * @ctx: context to be used when calling wpa_supplicant functions, | |
2076 | * e.g., wpa_supplicant_event() | |
2077 | * @ifname: interface name, e.g., wlan0 | |
2078 | * @global_priv: private driver global data from global_init() | |
2079 | * Returns: Pointer to private data, %NULL on failure | |
2080 | */ | |
2081 | static void * wpa_driver_nl80211_init(void *ctx, const char *ifname, | |
2082 | void *global_priv) | |
2083 | { | |
0ecff8d7 JM |
2084 | return wpa_driver_nl80211_drv_init(ctx, ifname, global_priv, 0, NULL, |
2085 | NULL); | |
0d547d5f JM |
2086 | } |
2087 | ||
2088 | ||
a11241fa | 2089 | static int nl80211_register_frame(struct i802_bss *bss, |
5582a5d1 | 2090 | struct nl_handle *nl_handle, |
bd94971e | 2091 | u16 type, const u8 *match, size_t match_len) |
58f6fbe0 | 2092 | { |
a11241fa | 2093 | struct wpa_driver_nl80211_data *drv = bss->drv; |
58f6fbe0 | 2094 | struct nl_msg *msg; |
a862e4a3 | 2095 | int ret; |
880de885 | 2096 | char buf[30]; |
58f6fbe0 | 2097 | |
880de885 JM |
2098 | buf[0] = '\0'; |
2099 | wpa_snprintf_hex(buf, sizeof(buf), match, match_len); | |
dedfa440 PF |
2100 | wpa_printf(MSG_DEBUG, "nl80211: Register frame type=0x%x (%s) nl_handle=%p match=%s", |
2101 | type, fc2str(type), nl_handle, buf); | |
36488c05 | 2102 | |
56f77852 | 2103 | if (!(msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_REGISTER_ACTION)) || |
a862e4a3 JM |
2104 | nla_put_u16(msg, NL80211_ATTR_FRAME_TYPE, type) || |
2105 | nla_put(msg, NL80211_ATTR_FRAME_MATCH, match_len, match)) { | |
2106 | nlmsg_free(msg); | |
2107 | return -1; | |
2108 | } | |
58f6fbe0 | 2109 | |
d6c9aab8 | 2110 | ret = send_and_recv(drv->global, nl_handle, msg, NULL, NULL); |
58f6fbe0 | 2111 | if (ret) { |
5582a5d1 JB |
2112 | wpa_printf(MSG_DEBUG, "nl80211: Register frame command " |
2113 | "failed (type=%u): ret=%d (%s)", | |
2114 | type, ret, strerror(-ret)); | |
2115 | wpa_hexdump(MSG_DEBUG, "nl80211: Register frame match", | |
58f6fbe0 | 2116 | match, match_len); |
58f6fbe0 | 2117 | } |
58f6fbe0 JM |
2118 | return ret; |
2119 | } | |
2120 | ||
2121 | ||
a11241fa JB |
2122 | static int nl80211_alloc_mgmt_handle(struct i802_bss *bss) |
2123 | { | |
481234cf | 2124 | if (bss->nl_mgmt) { |
a11241fa | 2125 | wpa_printf(MSG_DEBUG, "nl80211: Mgmt reporting " |
36488c05 | 2126 | "already on! (nl_mgmt=%p)", bss->nl_mgmt); |
a11241fa JB |
2127 | return -1; |
2128 | } | |
2129 | ||
ce20a370 | 2130 | bss->nl_mgmt = nl_create_handle(bss->nl_cb, "mgmt"); |
481234cf | 2131 | if (bss->nl_mgmt == NULL) |
a11241fa JB |
2132 | return -1; |
2133 | ||
a11241fa JB |
2134 | return 0; |
2135 | } | |
2136 | ||
2137 | ||
5f65e9f7 JB |
2138 | static void nl80211_mgmt_handle_register_eloop(struct i802_bss *bss) |
2139 | { | |
2140 | nl80211_register_eloop_read(&bss->nl_mgmt, | |
2141 | wpa_driver_nl80211_event_receive, | |
40a68f33 | 2142 | bss->nl_cb, 0); |
5f65e9f7 JB |
2143 | } |
2144 | ||
2145 | ||
a11241fa | 2146 | static int nl80211_register_action_frame(struct i802_bss *bss, |
bd94971e JB |
2147 | const u8 *match, size_t match_len) |
2148 | { | |
2149 | u16 type = (WLAN_FC_TYPE_MGMT << 2) | (WLAN_FC_STYPE_ACTION << 4); | |
481234cf | 2150 | return nl80211_register_frame(bss, bss->nl_mgmt, |
5582a5d1 | 2151 | type, match, match_len); |
bd94971e JB |
2152 | } |
2153 | ||
2154 | ||
40a68f33 SD |
2155 | static int nl80211_init_connect_handle(struct i802_bss *bss) |
2156 | { | |
2157 | if (bss->nl_connect) { | |
2158 | wpa_printf(MSG_DEBUG, | |
2159 | "nl80211: Connect handle already created (nl_connect=%p)", | |
2160 | bss->nl_connect); | |
2161 | return -1; | |
2162 | } | |
2163 | ||
2164 | bss->nl_connect = nl_create_handle(bss->nl_cb, "connect"); | |
2165 | if (!bss->nl_connect) | |
2166 | return -1; | |
2167 | nl80211_register_eloop_read(&bss->nl_connect, | |
2168 | wpa_driver_nl80211_event_receive, | |
2169 | bss->nl_cb, 1); | |
2170 | return 0; | |
2171 | } | |
2172 | ||
2173 | ||
a11241fa | 2174 | static int nl80211_mgmt_subscribe_non_ap(struct i802_bss *bss) |
58f6fbe0 | 2175 | { |
a11241fa | 2176 | struct wpa_driver_nl80211_data *drv = bss->drv; |
6f06766e | 2177 | int ret = 0; |
a11241fa JB |
2178 | |
2179 | if (nl80211_alloc_mgmt_handle(bss)) | |
2180 | return -1; | |
36488c05 JM |
2181 | wpa_printf(MSG_DEBUG, "nl80211: Subscribe to mgmt frames with non-AP " |
2182 | "handle %p", bss->nl_mgmt); | |
a11241fa | 2183 | |
ba71cb82 SD |
2184 | if (drv->nlmode == NL80211_IFTYPE_ADHOC || |
2185 | ((drv->capa.flags & WPA_DRIVER_FLAGS_SAE) && | |
2186 | !(drv->capa.flags & WPA_DRIVER_FLAGS_SME))) { | |
e8d1168b JB |
2187 | u16 type = (WLAN_FC_TYPE_MGMT << 2) | (WLAN_FC_STYPE_AUTH << 4); |
2188 | ||
2189 | /* register for any AUTH message */ | |
2190 | nl80211_register_frame(bss, bss->nl_mgmt, type, NULL, 0); | |
2191 | } | |
2192 | ||
56f5af48 JM |
2193 | #ifdef CONFIG_INTERWORKING |
2194 | /* QoS Map Configure */ | |
2195 | if (nl80211_register_action_frame(bss, (u8 *) "\x01\x04", 2) < 0) | |
6f06766e | 2196 | ret = -1; |
56f5af48 | 2197 | #endif /* CONFIG_INTERWORKING */ |
00b02149 | 2198 | #if defined(CONFIG_P2P) || defined(CONFIG_INTERWORKING) || defined(CONFIG_DPP) |
046b26a2 | 2199 | /* GAS Initial Request */ |
a11241fa | 2200 | if (nl80211_register_action_frame(bss, (u8 *) "\x04\x0a", 2) < 0) |
6f06766e | 2201 | ret = -1; |
046b26a2 | 2202 | /* GAS Initial Response */ |
a11241fa | 2203 | if (nl80211_register_action_frame(bss, (u8 *) "\x04\x0b", 2) < 0) |
6f06766e | 2204 | ret = -1; |
18708aad | 2205 | /* GAS Comeback Request */ |
a11241fa | 2206 | if (nl80211_register_action_frame(bss, (u8 *) "\x04\x0c", 2) < 0) |
6f06766e | 2207 | ret = -1; |
18708aad | 2208 | /* GAS Comeback Response */ |
a11241fa | 2209 | if (nl80211_register_action_frame(bss, (u8 *) "\x04\x0d", 2) < 0) |
6f06766e | 2210 | ret = -1; |
c5a64e2d JM |
2211 | /* Protected GAS Initial Request */ |
2212 | if (nl80211_register_action_frame(bss, (u8 *) "\x09\x0a", 2) < 0) | |
2213 | ret = -1; | |
2214 | /* Protected GAS Initial Response */ | |
2215 | if (nl80211_register_action_frame(bss, (u8 *) "\x09\x0b", 2) < 0) | |
2216 | ret = -1; | |
2217 | /* Protected GAS Comeback Request */ | |
2218 | if (nl80211_register_action_frame(bss, (u8 *) "\x09\x0c", 2) < 0) | |
2219 | ret = -1; | |
2220 | /* Protected GAS Comeback Response */ | |
2221 | if (nl80211_register_action_frame(bss, (u8 *) "\x09\x0d", 2) < 0) | |
2222 | ret = -1; | |
00b02149 | 2223 | #endif /* CONFIG_P2P || CONFIG_INTERWORKING || CONFIG_DPP */ |
4fe9fa0d | 2224 | #ifdef CONFIG_P2P |
046b26a2 | 2225 | /* P2P Public Action */ |
a11241fa | 2226 | if (nl80211_register_action_frame(bss, |
046b26a2 JM |
2227 | (u8 *) "\x04\x09\x50\x6f\x9a\x09", |
2228 | 6) < 0) | |
6f06766e | 2229 | ret = -1; |
046b26a2 | 2230 | /* P2P Action */ |
a11241fa | 2231 | if (nl80211_register_action_frame(bss, |
046b26a2 JM |
2232 | (u8 *) "\x7f\x50\x6f\x9a\x09", |
2233 | 5) < 0) | |
6f06766e | 2234 | ret = -1; |
046b26a2 | 2235 | #endif /* CONFIG_P2P */ |
00b02149 JM |
2236 | #ifdef CONFIG_DPP |
2237 | /* DPP Public Action */ | |
2238 | if (nl80211_register_action_frame(bss, | |
2239 | (u8 *) "\x04\x09\x50\x6f\x9a\x1a", | |
2240 | 6) < 0) | |
2241 | ret = -1; | |
2242 | #endif /* CONFIG_DPP */ | |
7d878ca7 | 2243 | #ifdef CONFIG_IEEE80211W |
f9da7505 MV |
2244 | #ifdef CONFIG_OCV |
2245 | /* SA Query Request */ | |
2246 | if (nl80211_register_action_frame(bss, (u8 *) "\x08\x00", 2) < 0) | |
2247 | ret = -1; | |
2248 | #endif /* CONFIG_OCV */ | |
7d878ca7 | 2249 | /* SA Query Response */ |
a11241fa | 2250 | if (nl80211_register_action_frame(bss, (u8 *) "\x08\x01", 2) < 0) |
6f06766e | 2251 | ret = -1; |
7d878ca7 | 2252 | #endif /* CONFIG_IEEE80211W */ |
35287637 AN |
2253 | #ifdef CONFIG_TDLS |
2254 | if ((drv->capa.flags & WPA_DRIVER_FLAGS_TDLS_SUPPORT)) { | |
2255 | /* TDLS Discovery Response */ | |
aa543c0c | 2256 | if (nl80211_register_action_frame(bss, (u8 *) "\x04\x0e", 2) < |
35287637 | 2257 | 0) |
6f06766e | 2258 | ret = -1; |
35287637 AN |
2259 | } |
2260 | #endif /* CONFIG_TDLS */ | |
46ab9b8c AN |
2261 | #ifdef CONFIG_FST |
2262 | /* FST Action frames */ | |
2263 | if (nl80211_register_action_frame(bss, (u8 *) "\x12", 1) < 0) | |
2264 | ret = -1; | |
2265 | #endif /* CONFIG_FST */ | |
046b26a2 | 2266 | |
7b90c16a | 2267 | /* FT Action frames */ |
a11241fa | 2268 | if (nl80211_register_action_frame(bss, (u8 *) "\x06", 1) < 0) |
6f06766e | 2269 | ret = -1; |
7b90c16a JM |
2270 | else |
2271 | drv->capa.key_mgmt |= WPA_DRIVER_CAPA_KEY_MGMT_FT | | |
2272 | WPA_DRIVER_CAPA_KEY_MGMT_FT_PSK; | |
2273 | ||
71269b37 | 2274 | /* WNM - BSS Transition Management Request */ |
a11241fa | 2275 | if (nl80211_register_action_frame(bss, (u8 *) "\x0a\x07", 2) < 0) |
6f06766e | 2276 | ret = -1; |
bd896433 JM |
2277 | /* WNM-Sleep Mode Response */ |
2278 | if (nl80211_register_action_frame(bss, (u8 *) "\x0a\x11", 2) < 0) | |
6f06766e | 2279 | ret = -1; |
d514b502 JM |
2280 | #ifdef CONFIG_WNM |
2281 | /* WNM - Collocated Interference Request */ | |
2282 | if (nl80211_register_action_frame(bss, (u8 *) "\x0a\x0b", 2) < 0) | |
2283 | ret = -1; | |
2284 | #endif /* CONFIG_WNM */ | |
a11241fa | 2285 | |
95a3ea94 JM |
2286 | #ifdef CONFIG_HS20 |
2287 | /* WNM-Notification */ | |
2288 | if (nl80211_register_action_frame(bss, (u8 *) "\x0a\x1a", 2) < 0) | |
3ee18569 | 2289 | ret = -1; |
95a3ea94 JM |
2290 | #endif /* CONFIG_HS20 */ |
2291 | ||
dfa87878 MB |
2292 | /* WMM-AC ADDTS Response */ |
2293 | if (nl80211_register_action_frame(bss, (u8 *) "\x11\x01", 2) < 0) | |
730a0d16 | 2294 | ret = -1; |
dfa87878 MB |
2295 | |
2296 | /* WMM-AC DELTS */ | |
2297 | if (nl80211_register_action_frame(bss, (u8 *) "\x11\x02", 2) < 0) | |
730a0d16 | 2298 | ret = -1; |
dfa87878 | 2299 | |
2526ccd9 AK |
2300 | /* Radio Measurement - Neighbor Report Response */ |
2301 | if (nl80211_register_action_frame(bss, (u8 *) "\x05\x05", 2) < 0) | |
2302 | ret = -1; | |
2303 | ||
864b9522 DS |
2304 | /* Radio Measurement - Radio Measurement Request */ |
2305 | if (nl80211_register_action_frame(bss, (u8 *) "\x05\x00", 2) < 0) | |
2306 | ret = -1; | |
2307 | ||
7dc03388 AO |
2308 | /* Radio Measurement - Link Measurement Request */ |
2309 | if ((drv->capa.rrm_flags & WPA_DRIVER_FLAGS_TX_POWER_INSERTION) && | |
2310 | (nl80211_register_action_frame(bss, (u8 *) "\x05\x02", 2) < 0)) | |
2311 | ret = -1; | |
2312 | ||
5f65e9f7 JB |
2313 | nl80211_mgmt_handle_register_eloop(bss); |
2314 | ||
6f06766e | 2315 | return ret; |
a11241fa JB |
2316 | } |
2317 | ||
2318 | ||
afb0550a BC |
2319 | static int nl80211_mgmt_subscribe_mesh(struct i802_bss *bss) |
2320 | { | |
2321 | int ret = 0; | |
2322 | ||
2323 | if (nl80211_alloc_mgmt_handle(bss)) | |
2324 | return -1; | |
2325 | ||
2326 | wpa_printf(MSG_DEBUG, | |
2327 | "nl80211: Subscribe to mgmt frames with mesh handle %p", | |
2328 | bss->nl_mgmt); | |
2329 | ||
2330 | /* Auth frames for mesh SAE */ | |
2331 | if (nl80211_register_frame(bss, bss->nl_mgmt, | |
2332 | (WLAN_FC_TYPE_MGMT << 2) | | |
2333 | (WLAN_FC_STYPE_AUTH << 4), | |
2334 | NULL, 0) < 0) | |
2335 | ret = -1; | |
2336 | ||
2337 | /* Mesh peering open */ | |
2338 | if (nl80211_register_action_frame(bss, (u8 *) "\x0f\x01", 2) < 0) | |
2339 | ret = -1; | |
2340 | /* Mesh peering confirm */ | |
2341 | if (nl80211_register_action_frame(bss, (u8 *) "\x0f\x02", 2) < 0) | |
2342 | ret = -1; | |
2343 | /* Mesh peering close */ | |
2344 | if (nl80211_register_action_frame(bss, (u8 *) "\x0f\x03", 2) < 0) | |
2345 | ret = -1; | |
2346 | ||
2347 | nl80211_mgmt_handle_register_eloop(bss); | |
2348 | ||
2349 | return ret; | |
2350 | } | |
2351 | ||
2352 | ||
02bb32c3 JB |
2353 | static int nl80211_register_spurious_class3(struct i802_bss *bss) |
2354 | { | |
02bb32c3 | 2355 | struct nl_msg *msg; |
a862e4a3 | 2356 | int ret; |
02bb32c3 | 2357 | |
13f83980 JM |
2358 | msg = nl80211_bss_msg(bss, 0, NL80211_CMD_UNEXPECTED_FRAME); |
2359 | ret = send_and_recv(bss->drv->global, bss->nl_mgmt, msg, NULL, NULL); | |
02bb32c3 JB |
2360 | if (ret) { |
2361 | wpa_printf(MSG_DEBUG, "nl80211: Register spurious class3 " | |
2362 | "failed: ret=%d (%s)", | |
2363 | ret, strerror(-ret)); | |
02bb32c3 | 2364 | } |
02bb32c3 JB |
2365 | return ret; |
2366 | } | |
2367 | ||
2368 | ||
4d916ed6 KV |
2369 | static int nl80211_action_subscribe_ap(struct i802_bss *bss) |
2370 | { | |
2371 | int ret = 0; | |
2372 | ||
2373 | /* Public Action frames */ | |
2374 | if (nl80211_register_action_frame(bss, (u8 *) "\x04", 1) < 0) | |
2375 | ret = -1; | |
2376 | /* RRM Measurement Report */ | |
2377 | if (nl80211_register_action_frame(bss, (u8 *) "\x05\x01", 2) < 0) | |
2378 | ret = -1; | |
e4ec6bbf JM |
2379 | /* RRM Link Measurement Report */ |
2380 | if (nl80211_register_action_frame(bss, (u8 *) "\x05\x03", 2) < 0) | |
2381 | ret = -1; | |
4d916ed6 KV |
2382 | /* RRM Neighbor Report Request */ |
2383 | if (nl80211_register_action_frame(bss, (u8 *) "\x05\x04", 2) < 0) | |
2384 | ret = -1; | |
2385 | /* FT Action frames */ | |
2386 | if (nl80211_register_action_frame(bss, (u8 *) "\x06", 1) < 0) | |
2387 | ret = -1; | |
2388 | #ifdef CONFIG_IEEE80211W | |
2389 | /* SA Query */ | |
2390 | if (nl80211_register_action_frame(bss, (u8 *) "\x08", 1) < 0) | |
2391 | ret = -1; | |
2392 | #endif /* CONFIG_IEEE80211W */ | |
2393 | /* Protected Dual of Public Action */ | |
2394 | if (nl80211_register_action_frame(bss, (u8 *) "\x09", 1) < 0) | |
2395 | ret = -1; | |
2396 | /* WNM */ | |
2397 | if (nl80211_register_action_frame(bss, (u8 *) "\x0a", 1) < 0) | |
2398 | ret = -1; | |
2399 | /* WMM */ | |
2400 | if (nl80211_register_action_frame(bss, (u8 *) "\x11", 1) < 0) | |
2401 | ret = -1; | |
2402 | #ifdef CONFIG_FST | |
2403 | /* FST Action frames */ | |
2404 | if (nl80211_register_action_frame(bss, (u8 *) "\x12", 1) < 0) | |
2405 | ret = -1; | |
2406 | #endif /* CONFIG_FST */ | |
2407 | /* Vendor-specific */ | |
2408 | if (nl80211_register_action_frame(bss, (u8 *) "\x7f", 1) < 0) | |
2409 | ret = -1; | |
2410 | ||
2411 | return ret; | |
2412 | } | |
2413 | ||
2414 | ||
a11241fa JB |
2415 | static int nl80211_mgmt_subscribe_ap(struct i802_bss *bss) |
2416 | { | |
2417 | static const int stypes[] = { | |
2418 | WLAN_FC_STYPE_AUTH, | |
2419 | WLAN_FC_STYPE_ASSOC_REQ, | |
2420 | WLAN_FC_STYPE_REASSOC_REQ, | |
2421 | WLAN_FC_STYPE_DISASSOC, | |
2422 | WLAN_FC_STYPE_DEAUTH, | |
a11241fa JB |
2423 | WLAN_FC_STYPE_PROBE_REQ, |
2424 | /* Beacon doesn't work as mac80211 doesn't currently allow | |
2425 | * it, but it wouldn't really be the right thing anyway as | |
2426 | * it isn't per interface ... maybe just dump the scan | |
2427 | * results periodically for OLBC? | |
2428 | */ | |
0e80ea2c | 2429 | /* WLAN_FC_STYPE_BEACON, */ |
a11241fa JB |
2430 | }; |
2431 | unsigned int i; | |
2432 | ||
2433 | if (nl80211_alloc_mgmt_handle(bss)) | |
71269b37 | 2434 | return -1; |
36488c05 JM |
2435 | wpa_printf(MSG_DEBUG, "nl80211: Subscribe to mgmt frames with AP " |
2436 | "handle %p", bss->nl_mgmt); | |
71269b37 | 2437 | |
e7ecab4a | 2438 | for (i = 0; i < ARRAY_SIZE(stypes); i++) { |
481234cf | 2439 | if (nl80211_register_frame(bss, bss->nl_mgmt, |
a11241fa JB |
2440 | (WLAN_FC_TYPE_MGMT << 2) | |
2441 | (stypes[i] << 4), | |
2442 | NULL, 0) < 0) { | |
2443 | goto out_err; | |
2444 | } | |
2445 | } | |
2446 | ||
4d916ed6 KV |
2447 | if (nl80211_action_subscribe_ap(bss)) |
2448 | goto out_err; | |
2449 | ||
02bb32c3 JB |
2450 | if (nl80211_register_spurious_class3(bss)) |
2451 | goto out_err; | |
2452 | ||
5f65e9f7 | 2453 | nl80211_mgmt_handle_register_eloop(bss); |
58f6fbe0 | 2454 | return 0; |
a11241fa JB |
2455 | |
2456 | out_err: | |
a11241fa JB |
2457 | nl_destroy_handles(&bss->nl_mgmt); |
2458 | return -1; | |
2459 | } | |
2460 | ||
2461 | ||
a6cc0602 JM |
2462 | static int nl80211_mgmt_subscribe_ap_dev_sme(struct i802_bss *bss) |
2463 | { | |
2464 | if (nl80211_alloc_mgmt_handle(bss)) | |
2465 | return -1; | |
2466 | wpa_printf(MSG_DEBUG, "nl80211: Subscribe to mgmt frames with AP " | |
2467 | "handle %p (device SME)", bss->nl_mgmt); | |
2468 | ||
4d916ed6 | 2469 | if (nl80211_action_subscribe_ap(bss)) |
a6cc0602 JM |
2470 | goto out_err; |
2471 | ||
5f65e9f7 | 2472 | nl80211_mgmt_handle_register_eloop(bss); |
a6cc0602 JM |
2473 | return 0; |
2474 | ||
2475 | out_err: | |
a6cc0602 JM |
2476 | nl_destroy_handles(&bss->nl_mgmt); |
2477 | return -1; | |
2478 | } | |
2479 | ||
2480 | ||
36488c05 | 2481 | static void nl80211_mgmt_unsubscribe(struct i802_bss *bss, const char *reason) |
a11241fa | 2482 | { |
481234cf | 2483 | if (bss->nl_mgmt == NULL) |
a11241fa | 2484 | return; |
36488c05 JM |
2485 | wpa_printf(MSG_DEBUG, "nl80211: Unsubscribe mgmt frames handle %p " |
2486 | "(%s)", bss->nl_mgmt, reason); | |
40a68f33 | 2487 | nl80211_destroy_eloop_handle(&bss->nl_mgmt, 0); |
7813b7c3 MH |
2488 | |
2489 | nl80211_put_wiphy_data_ap(bss); | |
58f6fbe0 JM |
2490 | } |
2491 | ||
2492 | ||
8401a6b0 JM |
2493 | static void wpa_driver_nl80211_send_rfkill(void *eloop_ctx, void *timeout_ctx) |
2494 | { | |
2495 | wpa_supplicant_event(timeout_ctx, EVENT_INTERFACE_DISABLED, NULL); | |
2496 | } | |
2497 | ||
2498 | ||
eb4582f2 AS |
2499 | static void nl80211_del_p2pdev(struct i802_bss *bss) |
2500 | { | |
eb4582f2 AS |
2501 | struct nl_msg *msg; |
2502 | int ret; | |
2503 | ||
a3249fdf JM |
2504 | msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_DEL_INTERFACE); |
2505 | ret = send_and_recv_msgs(bss->drv, msg, NULL, NULL); | |
eb4582f2 AS |
2506 | |
2507 | wpa_printf(MSG_DEBUG, "nl80211: Delete P2P Device %s (0x%llx): %s", | |
2508 | bss->ifname, (long long unsigned int) bss->wdev_id, | |
6cb4f11d | 2509 | strerror(-ret)); |
eb4582f2 AS |
2510 | } |
2511 | ||
2512 | ||
eb4582f2 | 2513 | static int nl80211_set_p2pdev(struct i802_bss *bss, int start) |
f632e483 | 2514 | { |
f632e483 | 2515 | struct nl_msg *msg; |
a862e4a3 | 2516 | int ret; |
f632e483 | 2517 | |
a3249fdf JM |
2518 | msg = nl80211_cmd_msg(bss, 0, start ? NL80211_CMD_START_P2P_DEVICE : |
2519 | NL80211_CMD_STOP_P2P_DEVICE); | |
2520 | ret = send_and_recv_msgs(bss->drv, msg, NULL, NULL); | |
f632e483 | 2521 | |
eb4582f2 AS |
2522 | wpa_printf(MSG_DEBUG, "nl80211: %s P2P Device %s (0x%llx): %s", |
2523 | start ? "Start" : "Stop", | |
2524 | bss->ifname, (long long unsigned int) bss->wdev_id, | |
6cb4f11d | 2525 | strerror(-ret)); |
f632e483 AS |
2526 | return ret; |
2527 | } | |
f632e483 AS |
2528 | |
2529 | ||
91724d6f AS |
2530 | static int i802_set_iface_flags(struct i802_bss *bss, int up) |
2531 | { | |
2532 | enum nl80211_iftype nlmode; | |
2533 | ||
2534 | nlmode = nl80211_get_ifmode(bss); | |
2535 | if (nlmode != NL80211_IFTYPE_P2P_DEVICE) { | |
2536 | return linux_set_iface_flags(bss->drv->global->ioctl_sock, | |
2537 | bss->ifname, up); | |
2538 | } | |
2539 | ||
2540 | /* P2P Device has start/stop which is equivalent */ | |
2541 | return nl80211_set_p2pdev(bss, up); | |
2542 | } | |
2543 | ||
2544 | ||
1db718b3 JM |
2545 | #ifdef CONFIG_TESTING_OPTIONS |
2546 | static int qca_vendor_test_cmd_handler(struct nl_msg *msg, void *arg) | |
2547 | { | |
2548 | /* struct wpa_driver_nl80211_data *drv = arg; */ | |
2549 | struct nlattr *tb[NL80211_ATTR_MAX + 1]; | |
2550 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); | |
2551 | ||
2552 | ||
2553 | wpa_printf(MSG_DEBUG, | |
2554 | "nl80211: QCA vendor test command response received"); | |
2555 | ||
2556 | nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), | |
2557 | genlmsg_attrlen(gnlh, 0), NULL); | |
2558 | if (!tb[NL80211_ATTR_VENDOR_DATA]) { | |
2559 | wpa_printf(MSG_DEBUG, "nl80211: No vendor data attribute"); | |
2560 | return NL_SKIP; | |
2561 | } | |
2562 | ||
2563 | wpa_hexdump(MSG_DEBUG, | |
2564 | "nl80211: Received QCA vendor test command response", | |
2565 | nla_data(tb[NL80211_ATTR_VENDOR_DATA]), | |
2566 | nla_len(tb[NL80211_ATTR_VENDOR_DATA])); | |
2567 | ||
2568 | return NL_SKIP; | |
2569 | } | |
2570 | #endif /* CONFIG_TESTING_OPTIONS */ | |
2571 | ||
2572 | ||
2573 | static void qca_vendor_test(struct wpa_driver_nl80211_data *drv) | |
2574 | { | |
2575 | #ifdef CONFIG_TESTING_OPTIONS | |
2576 | struct nl_msg *msg; | |
2577 | struct nlattr *params; | |
2578 | int ret; | |
2579 | ||
2580 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_VENDOR)) || | |
2581 | nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) || | |
2582 | nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD, | |
2583 | QCA_NL80211_VENDOR_SUBCMD_TEST) || | |
2584 | !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) || | |
2585 | nla_put_u32(msg, QCA_WLAN_VENDOR_ATTR_TEST, 123)) { | |
2586 | nlmsg_free(msg); | |
2587 | return; | |
2588 | } | |
2589 | nla_nest_end(msg, params); | |
2590 | ||
2591 | ret = send_and_recv_msgs(drv, msg, qca_vendor_test_cmd_handler, drv); | |
2592 | wpa_printf(MSG_DEBUG, | |
2593 | "nl80211: QCA vendor test command returned %d (%s)", | |
2594 | ret, strerror(-ret)); | |
2595 | #endif /* CONFIG_TESTING_OPTIONS */ | |
2596 | } | |
2597 | ||
2598 | ||
362f781e | 2599 | static int |
0d547d5f | 2600 | wpa_driver_nl80211_finish_drv_init(struct wpa_driver_nl80211_data *drv, |
0ecff8d7 JM |
2601 | const u8 *set_addr, int first, |
2602 | const char *driver_params) | |
7524cfb1 | 2603 | { |
834ee56f | 2604 | struct i802_bss *bss = drv->first_bss; |
8401a6b0 | 2605 | int send_rfkill_event = 0; |
0d547d5f | 2606 | enum nl80211_iftype nlmode; |
a2e40bb6 FF |
2607 | |
2608 | drv->ifindex = if_nametoindex(bss->ifname); | |
f632e483 AS |
2609 | bss->ifindex = drv->ifindex; |
2610 | bss->wdev_id = drv->global->if_add_wdevid; | |
2611 | bss->wdev_id_set = drv->global->if_add_wdevid_set; | |
2612 | ||
60b13c20 IP |
2613 | bss->if_dynamic = drv->ifindex == drv->global->if_add_ifindex; |
2614 | bss->if_dynamic = bss->if_dynamic || drv->global->if_add_wdevid_set; | |
f632e483 AS |
2615 | drv->global->if_add_wdevid_set = 0; |
2616 | ||
bf144cf6 AP |
2617 | if (!bss->if_dynamic && nl80211_get_ifmode(bss) == NL80211_IFTYPE_AP) |
2618 | bss->static_ap = 1; | |
2619 | ||
ef3866ab IP |
2620 | if (first && |
2621 | nl80211_get_ifmode(bss) != NL80211_IFTYPE_P2P_DEVICE && | |
2622 | linux_iface_up(drv->global->ioctl_sock, bss->ifname) > 0) | |
2623 | drv->start_iface_up = 1; | |
2624 | ||
f632e483 AS |
2625 | if (wpa_driver_nl80211_capa(drv)) |
2626 | return -1; | |
a87c9d96 | 2627 | |
0ecff8d7 JM |
2628 | if (driver_params && nl80211_set_param(bss, driver_params) < 0) |
2629 | return -1; | |
2630 | ||
5fbcb45d AS |
2631 | wpa_printf(MSG_DEBUG, "nl80211: interface %s in phy %s", |
2632 | bss->ifname, drv->phyname); | |
2633 | ||
0d547d5f JM |
2634 | if (set_addr && |
2635 | (linux_set_iface_flags(drv->global->ioctl_sock, bss->ifname, 0) || | |
2636 | linux_set_ifhwaddr(drv->global->ioctl_sock, bss->ifname, | |
2637 | set_addr))) | |
2638 | return -1; | |
2639 | ||
49b4b205 JM |
2640 | if (first && nl80211_get_ifmode(bss) == NL80211_IFTYPE_AP) |
2641 | drv->start_mode_ap = 1; | |
2642 | ||
bf144cf6 | 2643 | if (drv->hostapd || bss->static_ap) |
0d547d5f | 2644 | nlmode = NL80211_IFTYPE_AP; |
4fe726e2 FF |
2645 | else if (bss->if_dynamic || |
2646 | nl80211_get_ifmode(bss) == NL80211_IFTYPE_MESH_POINT) | |
8e12685c | 2647 | nlmode = nl80211_get_ifmode(bss); |
0d547d5f JM |
2648 | else |
2649 | nlmode = NL80211_IFTYPE_STATION; | |
f632e483 | 2650 | |
8e12685c | 2651 | if (wpa_driver_nl80211_set_mode(bss, nlmode) < 0) { |
0d547d5f | 2652 | wpa_printf(MSG_ERROR, "nl80211: Could not configure driver mode"); |
8e12685c | 2653 | return -1; |
a87c9d96 JM |
2654 | } |
2655 | ||
8c06db70 | 2656 | if (nlmode == NL80211_IFTYPE_P2P_DEVICE) |
597b94f5 | 2657 | nl80211_get_macaddr(bss); |
f632e483 | 2658 | |
0e92fb8f JB |
2659 | wpa_driver_nl80211_drv_init_rfkill(drv); |
2660 | ||
8c06db70 MB |
2661 | if (!rfkill_is_blocked(drv->rfkill)) { |
2662 | int ret = i802_set_iface_flags(bss, 1); | |
2663 | if (ret) { | |
8401a6b0 JM |
2664 | wpa_printf(MSG_ERROR, "nl80211: Could not set " |
2665 | "interface '%s' UP", bss->ifname); | |
8c06db70 | 2666 | return ret; |
8401a6b0 | 2667 | } |
e8dc205f AO |
2668 | |
2669 | if (is_p2p_net_interface(nlmode)) | |
2670 | nl80211_disable_11b_rates(bss->drv, | |
2671 | bss->drv->ifindex, 1); | |
2672 | ||
8c06db70 MB |
2673 | if (nlmode == NL80211_IFTYPE_P2P_DEVICE) |
2674 | return ret; | |
2675 | } else { | |
2676 | wpa_printf(MSG_DEBUG, "nl80211: Could not yet enable " | |
2677 | "interface '%s' due to rfkill", bss->ifname); | |
6da504a1 IP |
2678 | if (nlmode != NL80211_IFTYPE_P2P_DEVICE) |
2679 | drv->if_disabled = 1; | |
2680 | ||
8c06db70 | 2681 | send_rfkill_event = 1; |
362f781e | 2682 | } |
3f5285e8 | 2683 | |
6da504a1 | 2684 | if (!drv->hostapd && nlmode != NL80211_IFTYPE_P2P_DEVICE) |
0d547d5f JM |
2685 | netlink_send_oper_ifla(drv->global->netlink, drv->ifindex, |
2686 | 1, IF_OPER_DORMANT); | |
362f781e | 2687 | |
6da504a1 IP |
2688 | if (nlmode != NL80211_IFTYPE_P2P_DEVICE) { |
2689 | if (linux_get_ifhwaddr(drv->global->ioctl_sock, bss->ifname, | |
2690 | bss->addr)) | |
2691 | return -1; | |
2692 | os_memcpy(drv->perm_addr, bss->addr, ETH_ALEN); | |
2693 | } | |
f2ed8023 | 2694 | |
8401a6b0 JM |
2695 | if (send_rfkill_event) { |
2696 | eloop_register_timeout(0, 0, wpa_driver_nl80211_send_rfkill, | |
2697 | drv, drv->ctx); | |
2698 | } | |
2699 | ||
1db718b3 JM |
2700 | if (drv->vendor_cmd_test_avail) |
2701 | qca_vendor_test(drv); | |
2702 | ||
40a68f33 SD |
2703 | nl80211_init_connect_handle(bss); |
2704 | ||
362f781e | 2705 | return 0; |
3f5285e8 JM |
2706 | } |
2707 | ||
2708 | ||
a70cd0db | 2709 | static int wpa_driver_nl80211_del_beacon(struct i802_bss *bss) |
8a27af5c JM |
2710 | { |
2711 | struct nl_msg *msg; | |
a70cd0db | 2712 | struct wpa_driver_nl80211_data *drv = bss->drv; |
8a27af5c | 2713 | |
08e55ebb JM |
2714 | wpa_printf(MSG_DEBUG, "nl80211: Remove beacon (ifindex=%d)", |
2715 | drv->ifindex); | |
a70cd0db | 2716 | nl80211_put_wiphy_data_ap(bss); |
9725b784 | 2717 | msg = nl80211_drv_msg(drv, 0, NL80211_CMD_DEL_BEACON); |
8a27af5c | 2718 | return send_and_recv_msgs(drv, msg, NULL, NULL); |
8a27af5c | 2719 | } |
8a27af5c JM |
2720 | |
2721 | ||
3f5285e8 | 2722 | /** |
7e5ba1b9 | 2723 | * wpa_driver_nl80211_deinit - Deinitialize nl80211 driver interface |
9ebce9c5 | 2724 | * @bss: Pointer to private nl80211 data from wpa_driver_nl80211_init() |
3f5285e8 JM |
2725 | * |
2726 | * Shut down driver interface and processing of driver events. Free | |
2727 | * private data buffer if one was allocated in wpa_driver_nl80211_init(). | |
2728 | */ | |
9ebce9c5 | 2729 | static void wpa_driver_nl80211_deinit(struct i802_bss *bss) |
3f5285e8 | 2730 | { |
a2e40bb6 | 2731 | struct wpa_driver_nl80211_data *drv = bss->drv; |
cc9a2575 | 2732 | unsigned int i; |
3f5285e8 | 2733 | |
3e208481 JM |
2734 | wpa_printf(MSG_INFO, "nl80211: deinit ifname=%s disabled_11b_rates=%d", |
2735 | bss->ifname, drv->disabled_11b_rates); | |
2736 | ||
873d0fcf | 2737 | bss->in_deinit = 1; |
32ab4855 JB |
2738 | if (drv->data_tx_status) |
2739 | eloop_unregister_read_sock(drv->eapol_tx_sock); | |
d12dab4c JB |
2740 | if (drv->eapol_tx_sock >= 0) |
2741 | close(drv->eapol_tx_sock); | |
f10bfc9a | 2742 | |
481234cf | 2743 | if (bss->nl_preq) |
5582a5d1 | 2744 | wpa_driver_nl80211_probe_req_report(bss, 0); |
e17a2477 | 2745 | if (bss->added_if_into_bridge) { |
c81eff1a BG |
2746 | if (linux_br_del_if(drv->global->ioctl_sock, bss->brname, |
2747 | bss->ifname) < 0) | |
94627f6c JM |
2748 | wpa_printf(MSG_INFO, "nl80211: Failed to remove " |
2749 | "interface %s from bridge %s: %s", | |
e17a2477 | 2750 | bss->ifname, bss->brname, strerror(errno)); |
94627f6c | 2751 | } |
c809756f SM |
2752 | |
2753 | if (drv->rtnl_sk) | |
2754 | nl80211_handle_destroy(drv->rtnl_sk); | |
2755 | ||
e17a2477 | 2756 | if (bss->added_bridge) { |
f2535da8 JM |
2757 | if (linux_set_iface_flags(drv->global->ioctl_sock, bss->brname, |
2758 | 0) < 0) | |
2759 | wpa_printf(MSG_INFO, | |
2760 | "nl80211: Could not set bridge %s down", | |
2761 | bss->brname); | |
c81eff1a | 2762 | if (linux_br_del(drv->global->ioctl_sock, bss->brname) < 0) |
94627f6c JM |
2763 | wpa_printf(MSG_INFO, "nl80211: Failed to remove " |
2764 | "bridge %s: %s", | |
e17a2477 | 2765 | bss->brname, strerror(errno)); |
94627f6c JM |
2766 | } |
2767 | ||
460456f8 | 2768 | nl80211_remove_monitor_interface(drv); |
8a27af5c | 2769 | |
b1f625e0 | 2770 | if (is_ap_interface(drv->nlmode)) |
a70cd0db | 2771 | wpa_driver_nl80211_del_beacon(bss); |
0915d02c | 2772 | |
bbaf0837 JM |
2773 | if (drv->eapol_sock >= 0) { |
2774 | eloop_unregister_read_sock(drv->eapol_sock); | |
2775 | close(drv->eapol_sock); | |
2776 | } | |
2777 | ||
2778 | if (drv->if_indices != drv->default_if_indices) | |
2779 | os_free(drv->if_indices); | |
3f5285e8 | 2780 | |
732b1d20 MB |
2781 | if (drv->if_indices_reason != drv->default_if_indices_reason) |
2782 | os_free(drv->if_indices_reason); | |
2783 | ||
b3af99d2 | 2784 | if (drv->disabled_11b_rates) |
4e5cb1a3 JM |
2785 | nl80211_disable_11b_rates(drv, drv->ifindex, 0); |
2786 | ||
36d84860 BG |
2787 | netlink_send_oper_ifla(drv->global->netlink, drv->ifindex, 0, |
2788 | IF_OPER_UP); | |
e390df05 | 2789 | eloop_cancel_timeout(wpa_driver_nl80211_send_rfkill, drv, drv->ctx); |
8401a6b0 | 2790 | rfkill_deinit(drv->rfkill); |
3f5285e8 | 2791 | |
bbaf0837 JM |
2792 | eloop_cancel_timeout(wpa_driver_nl80211_scan_timeout, drv, drv->ctx); |
2793 | ||
146fa9b3 JM |
2794 | if (!drv->start_iface_up) |
2795 | (void) i802_set_iface_flags(bss, 0); | |
fee354c7 JM |
2796 | |
2797 | if (drv->addr_changed) { | |
93da0498 JM |
2798 | if (linux_set_iface_flags(drv->global->ioctl_sock, bss->ifname, |
2799 | 0) < 0) { | |
2800 | wpa_printf(MSG_DEBUG, | |
2801 | "nl80211: Could not set interface down to restore permanent MAC address"); | |
2802 | } | |
fee354c7 JM |
2803 | if (linux_set_ifhwaddr(drv->global->ioctl_sock, bss->ifname, |
2804 | drv->perm_addr) < 0) { | |
2805 | wpa_printf(MSG_DEBUG, | |
2806 | "nl80211: Could not restore permanent MAC address"); | |
2807 | } | |
2808 | } | |
2809 | ||
8e12685c | 2810 | if (drv->nlmode != NL80211_IFTYPE_P2P_DEVICE) { |
49b4b205 JM |
2811 | if (!drv->hostapd || !drv->start_mode_ap) |
2812 | wpa_driver_nl80211_set_mode(bss, | |
2813 | NL80211_IFTYPE_STATION); | |
b378c41f | 2814 | nl80211_mgmt_unsubscribe(bss, "deinit"); |
8e12685c AS |
2815 | } else { |
2816 | nl80211_mgmt_unsubscribe(bss, "deinit"); | |
eb4582f2 | 2817 | nl80211_del_p2pdev(bss); |
8e12685c | 2818 | } |
3f5285e8 | 2819 | |
40a68f33 SD |
2820 | if (bss->nl_connect) |
2821 | nl80211_destroy_eloop_handle(&bss->nl_connect, 1); | |
2822 | ||
834ee56f | 2823 | nl80211_destroy_bss(drv->first_bss); |
cc7a48d1 | 2824 | |
3812464c JM |
2825 | os_free(drv->filter_ssids); |
2826 | ||
536fd62d JM |
2827 | os_free(drv->auth_ie); |
2828 | ||
dac12351 | 2829 | if (drv->in_interface_list) |
f2ed8023 JM |
2830 | dl_list_del(&drv->list); |
2831 | ||
8cd6b7bc JB |
2832 | os_free(drv->extended_capa); |
2833 | os_free(drv->extended_capa_mask); | |
cc9a2575 KV |
2834 | for (i = 0; i < drv->num_iface_ext_capa; i++) { |
2835 | os_free(drv->iface_ext_capa[i].ext_capa); | |
2836 | os_free(drv->iface_ext_capa[i].ext_capa_mask); | |
2837 | } | |
834ee56f | 2838 | os_free(drv->first_bss); |
3f5285e8 JM |
2839 | os_free(drv); |
2840 | } | |
2841 | ||
2842 | ||
de4ed4a8 JM |
2843 | static u32 wpa_alg_to_cipher_suite(enum wpa_alg alg, size_t key_len) |
2844 | { | |
2845 | switch (alg) { | |
2846 | case WPA_ALG_WEP: | |
2847 | if (key_len == 5) | |
a042e39a JM |
2848 | return RSN_CIPHER_SUITE_WEP40; |
2849 | return RSN_CIPHER_SUITE_WEP104; | |
de4ed4a8 | 2850 | case WPA_ALG_TKIP: |
a042e39a | 2851 | return RSN_CIPHER_SUITE_TKIP; |
de4ed4a8 | 2852 | case WPA_ALG_CCMP: |
a042e39a | 2853 | return RSN_CIPHER_SUITE_CCMP; |
de4ed4a8 | 2854 | case WPA_ALG_GCMP: |
a042e39a | 2855 | return RSN_CIPHER_SUITE_GCMP; |
de4ed4a8 | 2856 | case WPA_ALG_CCMP_256: |
a042e39a | 2857 | return RSN_CIPHER_SUITE_CCMP_256; |
de4ed4a8 | 2858 | case WPA_ALG_GCMP_256: |
a042e39a | 2859 | return RSN_CIPHER_SUITE_GCMP_256; |
de4ed4a8 | 2860 | case WPA_ALG_IGTK: |
a042e39a | 2861 | return RSN_CIPHER_SUITE_AES_128_CMAC; |
de4ed4a8 | 2862 | case WPA_ALG_BIP_GMAC_128: |
a042e39a | 2863 | return RSN_CIPHER_SUITE_BIP_GMAC_128; |
de4ed4a8 | 2864 | case WPA_ALG_BIP_GMAC_256: |
a042e39a | 2865 | return RSN_CIPHER_SUITE_BIP_GMAC_256; |
de4ed4a8 | 2866 | case WPA_ALG_BIP_CMAC_256: |
a042e39a | 2867 | return RSN_CIPHER_SUITE_BIP_CMAC_256; |
de4ed4a8 | 2868 | case WPA_ALG_SMS4: |
a042e39a | 2869 | return RSN_CIPHER_SUITE_SMS4; |
de4ed4a8 | 2870 | case WPA_ALG_KRK: |
a042e39a | 2871 | return RSN_CIPHER_SUITE_KRK; |
de4ed4a8 JM |
2872 | case WPA_ALG_NONE: |
2873 | case WPA_ALG_PMK: | |
2874 | wpa_printf(MSG_ERROR, "nl80211: Unexpected encryption algorithm %d", | |
2875 | alg); | |
2876 | return 0; | |
2877 | } | |
2878 | ||
2879 | wpa_printf(MSG_ERROR, "nl80211: Unsupported encryption algorithm %d", | |
2880 | alg); | |
2881 | return 0; | |
2882 | } | |
2883 | ||
2884 | ||
2885 | static u32 wpa_cipher_to_cipher_suite(unsigned int cipher) | |
2886 | { | |
2887 | switch (cipher) { | |
2888 | case WPA_CIPHER_CCMP_256: | |
a042e39a | 2889 | return RSN_CIPHER_SUITE_CCMP_256; |
de4ed4a8 | 2890 | case WPA_CIPHER_GCMP_256: |
a042e39a | 2891 | return RSN_CIPHER_SUITE_GCMP_256; |
de4ed4a8 | 2892 | case WPA_CIPHER_CCMP: |
a042e39a | 2893 | return RSN_CIPHER_SUITE_CCMP; |
de4ed4a8 | 2894 | case WPA_CIPHER_GCMP: |
a042e39a | 2895 | return RSN_CIPHER_SUITE_GCMP; |
de4ed4a8 | 2896 | case WPA_CIPHER_TKIP: |
a042e39a | 2897 | return RSN_CIPHER_SUITE_TKIP; |
de4ed4a8 | 2898 | case WPA_CIPHER_WEP104: |
a042e39a | 2899 | return RSN_CIPHER_SUITE_WEP104; |
de4ed4a8 | 2900 | case WPA_CIPHER_WEP40: |
a042e39a | 2901 | return RSN_CIPHER_SUITE_WEP40; |
ae6f9272 | 2902 | case WPA_CIPHER_GTK_NOT_USED: |
a042e39a | 2903 | return RSN_CIPHER_SUITE_NO_GROUP_ADDRESSED; |
de4ed4a8 JM |
2904 | } |
2905 | ||
2906 | return 0; | |
2907 | } | |
2908 | ||
2909 | ||
2910 | static int wpa_cipher_to_cipher_suites(unsigned int ciphers, u32 suites[], | |
2911 | int max_suites) | |
2912 | { | |
2913 | int num_suites = 0; | |
2914 | ||
2915 | if (num_suites < max_suites && ciphers & WPA_CIPHER_CCMP_256) | |
a042e39a | 2916 | suites[num_suites++] = RSN_CIPHER_SUITE_CCMP_256; |
de4ed4a8 | 2917 | if (num_suites < max_suites && ciphers & WPA_CIPHER_GCMP_256) |
a042e39a | 2918 | suites[num_suites++] = RSN_CIPHER_SUITE_GCMP_256; |
de4ed4a8 | 2919 | if (num_suites < max_suites && ciphers & WPA_CIPHER_CCMP) |
a042e39a | 2920 | suites[num_suites++] = RSN_CIPHER_SUITE_CCMP; |
de4ed4a8 | 2921 | if (num_suites < max_suites && ciphers & WPA_CIPHER_GCMP) |
a042e39a | 2922 | suites[num_suites++] = RSN_CIPHER_SUITE_GCMP; |
de4ed4a8 | 2923 | if (num_suites < max_suites && ciphers & WPA_CIPHER_TKIP) |
a042e39a | 2924 | suites[num_suites++] = RSN_CIPHER_SUITE_TKIP; |
de4ed4a8 | 2925 | if (num_suites < max_suites && ciphers & WPA_CIPHER_WEP104) |
a042e39a | 2926 | suites[num_suites++] = RSN_CIPHER_SUITE_WEP104; |
de4ed4a8 | 2927 | if (num_suites < max_suites && ciphers & WPA_CIPHER_WEP40) |
a042e39a | 2928 | suites[num_suites++] = RSN_CIPHER_SUITE_WEP40; |
de4ed4a8 JM |
2929 | |
2930 | return num_suites; | |
2931 | } | |
2932 | ||
2933 | ||
b658547d | 2934 | #ifdef CONFIG_DRIVER_NL80211_QCA |
b41f2684 CL |
2935 | static int issue_key_mgmt_set_key(struct wpa_driver_nl80211_data *drv, |
2936 | const u8 *key, size_t key_len) | |
2937 | { | |
2938 | struct nl_msg *msg; | |
a862e4a3 | 2939 | int ret; |
b41f2684 | 2940 | |
15badebd | 2941 | if (!(drv->capa.flags & WPA_DRIVER_FLAGS_KEY_MGMT_OFFLOAD)) |
b41f2684 CL |
2942 | return 0; |
2943 | ||
9725b784 | 2944 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_VENDOR)) || |
a862e4a3 JM |
2945 | nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) || |
2946 | nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD, | |
2947 | QCA_NL80211_VENDOR_SUBCMD_KEY_MGMT_SET_KEY) || | |
2948 | nla_put(msg, NL80211_ATTR_VENDOR_DATA, key_len, key)) { | |
bbd89bfc | 2949 | nl80211_nlmsg_clear(msg); |
a862e4a3 JM |
2950 | nlmsg_free(msg); |
2951 | return -1; | |
2952 | } | |
bbd89bfc | 2953 | ret = send_and_recv_msgs(drv, msg, NULL, (void *) -1); |
b41f2684 CL |
2954 | if (ret) { |
2955 | wpa_printf(MSG_DEBUG, | |
2956 | "nl80211: Key management set key failed: ret=%d (%s)", | |
2957 | ret, strerror(-ret)); | |
2958 | } | |
2959 | ||
b41f2684 CL |
2960 | return ret; |
2961 | } | |
b658547d | 2962 | #endif /* CONFIG_DRIVER_NL80211_QCA */ |
b41f2684 CL |
2963 | |
2964 | ||
05fc7c68 AS |
2965 | static int nl80211_set_pmk(struct wpa_driver_nl80211_data *drv, |
2966 | const u8 *key, size_t key_len, | |
2967 | const u8 *addr) | |
2968 | { | |
2969 | struct nl_msg *msg = NULL; | |
2970 | int ret; | |
2971 | ||
2972 | /* | |
2973 | * If the authenticator address is not set, assume it is | |
2974 | * the current BSSID. | |
2975 | */ | |
2976 | if (!addr && drv->associated) | |
2977 | addr = drv->bssid; | |
2978 | else if (!addr) | |
2979 | return -1; | |
2980 | ||
2981 | wpa_printf(MSG_DEBUG, "nl80211: Set PMK to the driver for " MACSTR, | |
2982 | MAC2STR(addr)); | |
2983 | wpa_hexdump_key(MSG_DEBUG, "nl80211: PMK", key, key_len); | |
2984 | msg = nl80211_drv_msg(drv, 0, NL80211_CMD_SET_PMK); | |
2985 | if (!msg || | |
2986 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) || | |
2987 | nla_put(msg, NL80211_ATTR_PMK, key_len, key)) { | |
2988 | nl80211_nlmsg_clear(msg); | |
2989 | nlmsg_free(msg); | |
2990 | return -ENOBUFS; | |
2991 | } | |
2992 | ||
2993 | ret = send_and_recv_msgs(drv, msg, NULL, (void *) -1); | |
2994 | if (ret) { | |
2995 | wpa_printf(MSG_DEBUG, "nl80211: Set PMK failed: ret=%d (%s)", | |
2996 | ret, strerror(-ret)); | |
2997 | } | |
2998 | ||
2999 | return ret; | |
3000 | } | |
3001 | ||
3002 | ||
9ebce9c5 | 3003 | static int wpa_driver_nl80211_set_key(const char *ifname, struct i802_bss *bss, |
71934751 JM |
3004 | enum wpa_alg alg, const u8 *addr, |
3005 | int key_idx, int set_tx, | |
642187d6 JM |
3006 | const u8 *seq, size_t seq_len, |
3007 | const u8 *key, size_t key_len) | |
3f5285e8 | 3008 | { |
a2e40bb6 | 3009 | struct wpa_driver_nl80211_data *drv = bss->drv; |
e472e1b4 | 3010 | int ifindex; |
34651767 | 3011 | struct nl_msg *msg = NULL; |
1ad1cdc2 | 3012 | int ret; |
dc01de8a | 3013 | int tdls = 0; |
3f5285e8 | 3014 | |
e472e1b4 AS |
3015 | /* Ignore for P2P Device */ |
3016 | if (drv->nlmode == NL80211_IFTYPE_P2P_DEVICE) | |
3017 | return 0; | |
3018 | ||
3019 | ifindex = if_nametoindex(ifname); | |
8393e1a0 | 3020 | wpa_printf(MSG_DEBUG, "%s: ifindex=%d (%s) alg=%d addr=%p key_idx=%d " |
1ad1cdc2 | 3021 | "set_tx=%d seq_len=%lu key_len=%lu", |
8393e1a0 | 3022 | __func__, ifindex, ifname, alg, addr, key_idx, set_tx, |
3f5285e8 | 3023 | (unsigned long) seq_len, (unsigned long) key_len); |
8c66e185 | 3024 | #ifdef CONFIG_TDLS |
dc01de8a | 3025 | if (key_idx == -1) { |
8c66e185 | 3026 | key_idx = 0; |
dc01de8a JM |
3027 | tdls = 1; |
3028 | } | |
8c66e185 | 3029 | #endif /* CONFIG_TDLS */ |
3f5285e8 | 3030 | |
b658547d | 3031 | #ifdef CONFIG_DRIVER_NL80211_QCA |
15badebd CL |
3032 | if (alg == WPA_ALG_PMK && |
3033 | (drv->capa.flags & WPA_DRIVER_FLAGS_KEY_MGMT_OFFLOAD)) { | |
b41f2684 CL |
3034 | wpa_printf(MSG_DEBUG, "%s: calling issue_key_mgmt_set_key", |
3035 | __func__); | |
3036 | ret = issue_key_mgmt_set_key(drv, key, key_len); | |
3037 | return ret; | |
3038 | } | |
b658547d | 3039 | #endif /* CONFIG_DRIVER_NL80211_QCA */ |
b41f2684 | 3040 | |
05fc7c68 | 3041 | if (alg == WPA_ALG_PMK && |
436ee2fd | 3042 | (drv->capa.flags & WPA_DRIVER_FLAGS_4WAY_HANDSHAKE_8021X)) |
05fc7c68 AS |
3043 | return nl80211_set_pmk(drv, key, key_len, addr); |
3044 | ||
3f5285e8 | 3045 | if (alg == WPA_ALG_NONE) { |
95376e1a JM |
3046 | msg = nl80211_ifindex_msg(drv, ifindex, 0, NL80211_CMD_DEL_KEY); |
3047 | if (!msg) | |
3048 | return -ENOBUFS; | |
3f5285e8 | 3049 | } else { |
34651767 JM |
3050 | u32 suite; |
3051 | ||
3052 | suite = wpa_alg_to_cipher_suite(alg, key_len); | |
3053 | if (!suite) | |
3054 | goto fail; | |
95376e1a JM |
3055 | msg = nl80211_ifindex_msg(drv, ifindex, 0, NL80211_CMD_NEW_KEY); |
3056 | if (!msg || | |
a862e4a3 | 3057 | nla_put(msg, NL80211_ATTR_KEY_DATA, key_len, key) || |
34651767 | 3058 | nla_put_u32(msg, NL80211_ATTR_KEY_CIPHER, suite)) |
a862e4a3 | 3059 | goto fail; |
e6ef73f1 | 3060 | wpa_hexdump_key(MSG_DEBUG, "nl80211: KEY_DATA", key, key_len); |
3f5285e8 JM |
3061 | } |
3062 | ||
e6ef73f1 | 3063 | if (seq && seq_len) { |
a862e4a3 JM |
3064 | if (nla_put(msg, NL80211_ATTR_KEY_SEQ, seq_len, seq)) |
3065 | goto fail; | |
e6ef73f1 JM |
3066 | wpa_hexdump(MSG_DEBUG, "nl80211: KEY_SEQ", seq, seq_len); |
3067 | } | |
1ad1cdc2 | 3068 | |
0382097e | 3069 | if (addr && !is_broadcast_ether_addr(addr)) { |
3f5285e8 | 3070 | wpa_printf(MSG_DEBUG, " addr=" MACSTR, MAC2STR(addr)); |
a862e4a3 JM |
3071 | if (nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) |
3072 | goto fail; | |
89c38e32 JM |
3073 | |
3074 | if (alg != WPA_ALG_WEP && key_idx && !set_tx) { | |
3075 | wpa_printf(MSG_DEBUG, " RSN IBSS RX GTK"); | |
a862e4a3 JM |
3076 | if (nla_put_u32(msg, NL80211_ATTR_KEY_TYPE, |
3077 | NL80211_KEYTYPE_GROUP)) | |
3078 | goto fail; | |
89c38e32 | 3079 | } |
60ea8187 | 3080 | } else if (addr && is_broadcast_ether_addr(addr)) { |
8970bae8 JB |
3081 | struct nlattr *types; |
3082 | ||
60ea8187 | 3083 | wpa_printf(MSG_DEBUG, " broadcast key"); |
8970bae8 JB |
3084 | |
3085 | types = nla_nest_start(msg, NL80211_ATTR_KEY_DEFAULT_TYPES); | |
a862e4a3 JM |
3086 | if (!types || |
3087 | nla_put_flag(msg, NL80211_KEY_DEFAULT_TYPE_MULTICAST)) | |
3088 | goto fail; | |
8970bae8 | 3089 | nla_nest_end(msg, types); |
3f5285e8 | 3090 | } |
95376e1a | 3091 | if (nla_put_u8(msg, NL80211_ATTR_KEY_IDX, key_idx)) |
a862e4a3 | 3092 | goto fail; |
3f5285e8 | 3093 | |
bbd89bfc | 3094 | ret = send_and_recv_msgs(drv, msg, NULL, key ? (void *) -1 : NULL); |
15664ad0 | 3095 | if ((ret == -ENOENT || ret == -ENOLINK) && alg == WPA_ALG_NONE) |
1ad1cdc2 JM |
3096 | ret = 0; |
3097 | if (ret) | |
3098 | wpa_printf(MSG_DEBUG, "nl80211: set_key failed; err=%d %s)", | |
3099 | ret, strerror(-ret)); | |
3f5285e8 | 3100 | |
1ad1cdc2 JM |
3101 | /* |
3102 | * If we failed or don't need to set the default TX key (below), | |
3103 | * we're done here. | |
3104 | */ | |
dc01de8a | 3105 | if (ret || !set_tx || alg == WPA_ALG_NONE || tdls) |
1ad1cdc2 | 3106 | return ret; |
b1f625e0 | 3107 | if (is_ap_interface(drv->nlmode) && addr && |
0382097e | 3108 | !is_broadcast_ether_addr(addr)) |
de12717a | 3109 | return ret; |
3f5285e8 | 3110 | |
95376e1a JM |
3111 | msg = nl80211_ifindex_msg(drv, ifindex, 0, NL80211_CMD_SET_KEY); |
3112 | if (!msg || | |
a862e4a3 | 3113 | nla_put_u8(msg, NL80211_ATTR_KEY_IDX, key_idx) || |
86f9b1c7 JM |
3114 | nla_put_flag(msg, (alg == WPA_ALG_IGTK || |
3115 | alg == WPA_ALG_BIP_GMAC_128 || | |
3116 | alg == WPA_ALG_BIP_GMAC_256 || | |
3117 | alg == WPA_ALG_BIP_CMAC_256) ? | |
a862e4a3 JM |
3118 | NL80211_ATTR_KEY_DEFAULT_MGMT : |
3119 | NL80211_ATTR_KEY_DEFAULT)) | |
3120 | goto fail; | |
60ea8187 | 3121 | if (addr && is_broadcast_ether_addr(addr)) { |
8970bae8 JB |
3122 | struct nlattr *types; |
3123 | ||
3124 | types = nla_nest_start(msg, NL80211_ATTR_KEY_DEFAULT_TYPES); | |
a862e4a3 JM |
3125 | if (!types || |
3126 | nla_put_flag(msg, NL80211_KEY_DEFAULT_TYPE_MULTICAST)) | |
3127 | goto fail; | |
8970bae8 | 3128 | nla_nest_end(msg, types); |
60ea8187 | 3129 | } else if (addr) { |
8970bae8 JB |
3130 | struct nlattr *types; |
3131 | ||
3132 | types = nla_nest_start(msg, NL80211_ATTR_KEY_DEFAULT_TYPES); | |
a862e4a3 JM |
3133 | if (!types || |
3134 | nla_put_flag(msg, NL80211_KEY_DEFAULT_TYPE_UNICAST)) | |
3135 | goto fail; | |
8970bae8 | 3136 | nla_nest_end(msg, types); |
60ea8187 | 3137 | } |
3f5285e8 | 3138 | |
1ad1cdc2 JM |
3139 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
3140 | if (ret == -ENOENT) | |
3141 | ret = 0; | |
3142 | if (ret) | |
3143 | wpa_printf(MSG_DEBUG, "nl80211: set_key default failed; " | |
3144 | "err=%d %s)", ret, strerror(-ret)); | |
3145 | return ret; | |
3f5285e8 | 3146 | |
a862e4a3 | 3147 | fail: |
bbd89bfc | 3148 | nl80211_nlmsg_clear(msg); |
5883168a | 3149 | nlmsg_free(msg); |
6241fcb1 | 3150 | return -ENOBUFS; |
3f5285e8 JM |
3151 | } |
3152 | ||
3153 | ||
71934751 | 3154 | static int nl_add_key(struct nl_msg *msg, enum wpa_alg alg, |
0194fedb JB |
3155 | int key_idx, int defkey, |
3156 | const u8 *seq, size_t seq_len, | |
3157 | const u8 *key, size_t key_len) | |
3158 | { | |
3159 | struct nlattr *key_attr = nla_nest_start(msg, NL80211_ATTR_KEY); | |
34651767 JM |
3160 | u32 suite; |
3161 | ||
0194fedb JB |
3162 | if (!key_attr) |
3163 | return -1; | |
3164 | ||
34651767 JM |
3165 | suite = wpa_alg_to_cipher_suite(alg, key_len); |
3166 | if (!suite) | |
3167 | return -1; | |
3168 | ||
a862e4a3 JM |
3169 | if (defkey && alg == WPA_ALG_IGTK) { |
3170 | if (nla_put_flag(msg, NL80211_KEY_DEFAULT_MGMT)) | |
3171 | return -1; | |
3172 | } else if (defkey) { | |
3173 | if (nla_put_flag(msg, NL80211_KEY_DEFAULT)) | |
3174 | return -1; | |
3175 | } | |
0194fedb | 3176 | |
a862e4a3 | 3177 | if (nla_put_u8(msg, NL80211_KEY_IDX, key_idx) || |
34651767 | 3178 | nla_put_u32(msg, NL80211_KEY_CIPHER, suite) || |
a862e4a3 JM |
3179 | (seq && seq_len && |
3180 | nla_put(msg, NL80211_KEY_SEQ, seq_len, seq)) || | |
3181 | nla_put(msg, NL80211_KEY_DATA, key_len, key)) | |
3182 | return -1; | |
0194fedb JB |
3183 | |
3184 | nla_nest_end(msg, key_attr); | |
3185 | ||
3186 | return 0; | |
0194fedb JB |
3187 | } |
3188 | ||
c811d5bc | 3189 | |
cfaab580 ZY |
3190 | static int nl80211_set_conn_keys(struct wpa_driver_associate_params *params, |
3191 | struct nl_msg *msg) | |
3192 | { | |
3193 | int i, privacy = 0; | |
3194 | struct nlattr *nl_keys, *nl_key; | |
3195 | ||
3196 | for (i = 0; i < 4; i++) { | |
3197 | if (!params->wep_key[i]) | |
3198 | continue; | |
3199 | privacy = 1; | |
3200 | break; | |
3201 | } | |
ce04af5a JM |
3202 | if (params->wps == WPS_MODE_PRIVACY) |
3203 | privacy = 1; | |
3204 | if (params->pairwise_suite && | |
3205 | params->pairwise_suite != WPA_CIPHER_NONE) | |
3206 | privacy = 1; | |
3207 | ||
cfaab580 ZY |
3208 | if (!privacy) |
3209 | return 0; | |
3210 | ||
a862e4a3 JM |
3211 | if (nla_put_flag(msg, NL80211_ATTR_PRIVACY)) |
3212 | return -ENOBUFS; | |
cfaab580 ZY |
3213 | |
3214 | nl_keys = nla_nest_start(msg, NL80211_ATTR_KEYS); | |
3215 | if (!nl_keys) | |
a862e4a3 | 3216 | return -ENOBUFS; |
cfaab580 ZY |
3217 | |
3218 | for (i = 0; i < 4; i++) { | |
3219 | if (!params->wep_key[i]) | |
3220 | continue; | |
3221 | ||
3222 | nl_key = nla_nest_start(msg, i); | |
a862e4a3 JM |
3223 | if (!nl_key || |
3224 | nla_put(msg, NL80211_KEY_DATA, params->wep_key_len[i], | |
3225 | params->wep_key[i]) || | |
3226 | nla_put_u32(msg, NL80211_KEY_CIPHER, | |
3227 | params->wep_key_len[i] == 5 ? | |
a042e39a JM |
3228 | RSN_CIPHER_SUITE_WEP40 : |
3229 | RSN_CIPHER_SUITE_WEP104) || | |
a862e4a3 JM |
3230 | nla_put_u8(msg, NL80211_KEY_IDX, i) || |
3231 | (i == params->wep_tx_keyidx && | |
3232 | nla_put_flag(msg, NL80211_KEY_DEFAULT))) | |
3233 | return -ENOBUFS; | |
cfaab580 ZY |
3234 | |
3235 | nla_nest_end(msg, nl_key); | |
3236 | } | |
3237 | nla_nest_end(msg, nl_keys); | |
3238 | ||
3239 | return 0; | |
cfaab580 ZY |
3240 | } |
3241 | ||
3242 | ||
477af8f8 JM |
3243 | int wpa_driver_nl80211_mlme(struct wpa_driver_nl80211_data *drv, |
3244 | const u8 *addr, int cmd, u16 reason_code, | |
10d32e2c CI |
3245 | int local_state_change, |
3246 | struct nl_handle *nl_connect) | |
c2a04078 | 3247 | { |
a862e4a3 | 3248 | int ret; |
c2a04078 JM |
3249 | struct nl_msg *msg; |
3250 | ||
9725b784 | 3251 | if (!(msg = nl80211_drv_msg(drv, 0, cmd)) || |
a862e4a3 JM |
3252 | nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason_code) || |
3253 | (addr && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) || | |
3254 | (local_state_change && | |
3255 | nla_put_flag(msg, NL80211_ATTR_LOCAL_STATE_CHANGE))) { | |
3256 | nlmsg_free(msg); | |
3257 | return -1; | |
3258 | } | |
c2a04078 | 3259 | |
10d32e2c CI |
3260 | if (nl_connect) |
3261 | ret = send_and_recv(drv->global, nl_connect, msg, NULL, NULL); | |
3262 | else | |
3263 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); | |
c2a04078 | 3264 | if (ret) { |
3b7ea880 BG |
3265 | wpa_dbg(drv->ctx, MSG_DEBUG, |
3266 | "nl80211: MLME command failed: reason=%u ret=%d (%s)", | |
3267 | reason_code, ret, strerror(-ret)); | |
c2a04078 | 3268 | } |
c2a04078 JM |
3269 | return ret; |
3270 | } | |
3f5285e8 JM |
3271 | |
3272 | ||
cfaab580 | 3273 | static int wpa_driver_nl80211_disconnect(struct wpa_driver_nl80211_data *drv, |
10d32e2c CI |
3274 | int reason_code, |
3275 | struct nl_handle *nl_connect) | |
cfaab580 | 3276 | { |
3f53c006 | 3277 | int ret; |
b898b655 | 3278 | int drv_associated = drv->associated; |
3f53c006 | 3279 | |
817762d9 | 3280 | wpa_printf(MSG_DEBUG, "%s(reason_code=%d)", __func__, reason_code); |
add9b7a4 | 3281 | nl80211_mark_disconnected(drv); |
817762d9 | 3282 | /* Disconnect command doesn't need BSSID - it uses cached value */ |
3f53c006 | 3283 | ret = wpa_driver_nl80211_mlme(drv, NULL, NL80211_CMD_DISCONNECT, |
10d32e2c | 3284 | reason_code, 0, nl_connect); |
3f53c006 JJ |
3285 | /* |
3286 | * For locally generated disconnect, supplicant already generates a | |
3287 | * DEAUTH event, so ignore the event from NL80211. | |
3288 | */ | |
b898b655 | 3289 | drv->ignore_next_local_disconnect = drv_associated && (ret == 0); |
3f53c006 JJ |
3290 | |
3291 | return ret; | |
cfaab580 ZY |
3292 | } |
3293 | ||
3294 | ||
9ebce9c5 JM |
3295 | static int wpa_driver_nl80211_deauthenticate(struct i802_bss *bss, |
3296 | const u8 *addr, int reason_code) | |
3f5285e8 | 3297 | { |
a2e40bb6 | 3298 | struct wpa_driver_nl80211_data *drv = bss->drv; |
d6a36f39 | 3299 | int ret; |
b898b655 | 3300 | int drv_associated = drv->associated; |
9392c9be AS |
3301 | |
3302 | if (drv->nlmode == NL80211_IFTYPE_ADHOC) { | |
3303 | nl80211_mark_disconnected(drv); | |
666e508c | 3304 | return nl80211_leave_ibss(drv, 1); |
9392c9be | 3305 | } |
10d32e2c CI |
3306 | if (!(drv->capa.flags & WPA_DRIVER_FLAGS_SME)) { |
3307 | struct nl_handle *nl_connect = NULL; | |
3308 | ||
3309 | if (bss->use_nl_connect) | |
3310 | nl_connect = bss->nl_connect; | |
3311 | return wpa_driver_nl80211_disconnect(drv, reason_code, | |
3312 | nl_connect); | |
3313 | } | |
2e75a2b3 JM |
3314 | wpa_printf(MSG_DEBUG, "%s(addr=" MACSTR " reason_code=%d)", |
3315 | __func__, MAC2STR(addr), reason_code); | |
add9b7a4 | 3316 | nl80211_mark_disconnected(drv); |
d6a36f39 | 3317 | ret = wpa_driver_nl80211_mlme(drv, addr, NL80211_CMD_DEAUTHENTICATE, |
10d32e2c | 3318 | reason_code, 0, NULL); |
d6a36f39 JM |
3319 | /* |
3320 | * For locally generated deauthenticate, supplicant already generates a | |
3321 | * DEAUTH event, so ignore the event from NL80211. | |
3322 | */ | |
b898b655 HW |
3323 | drv->ignore_next_local_deauth = drv_associated && (ret == 0); |
3324 | ||
d6a36f39 | 3325 | return ret; |
3f5285e8 JM |
3326 | } |
3327 | ||
3328 | ||
536fd62d JM |
3329 | static void nl80211_copy_auth_params(struct wpa_driver_nl80211_data *drv, |
3330 | struct wpa_driver_auth_params *params) | |
3331 | { | |
3332 | int i; | |
3333 | ||
3334 | drv->auth_freq = params->freq; | |
3335 | drv->auth_alg = params->auth_alg; | |
3336 | drv->auth_wep_tx_keyidx = params->wep_tx_keyidx; | |
3337 | drv->auth_local_state_change = params->local_state_change; | |
3338 | drv->auth_p2p = params->p2p; | |
3339 | ||
3340 | if (params->bssid) | |
3341 | os_memcpy(drv->auth_bssid_, params->bssid, ETH_ALEN); | |
3342 | else | |
3343 | os_memset(drv->auth_bssid_, 0, ETH_ALEN); | |
3344 | ||
3345 | if (params->ssid) { | |
3346 | os_memcpy(drv->auth_ssid, params->ssid, params->ssid_len); | |
3347 | drv->auth_ssid_len = params->ssid_len; | |
3348 | } else | |
3349 | drv->auth_ssid_len = 0; | |
3350 | ||
3351 | ||
3352 | os_free(drv->auth_ie); | |
3353 | drv->auth_ie = NULL; | |
3354 | drv->auth_ie_len = 0; | |
3355 | if (params->ie) { | |
3356 | drv->auth_ie = os_malloc(params->ie_len); | |
3357 | if (drv->auth_ie) { | |
3358 | os_memcpy(drv->auth_ie, params->ie, params->ie_len); | |
3359 | drv->auth_ie_len = params->ie_len; | |
3360 | } | |
3361 | } | |
3362 | ||
3363 | for (i = 0; i < 4; i++) { | |
3364 | if (params->wep_key[i] && params->wep_key_len[i] && | |
3365 | params->wep_key_len[i] <= 16) { | |
3366 | os_memcpy(drv->auth_wep_key[i], params->wep_key[i], | |
3367 | params->wep_key_len[i]); | |
3368 | drv->auth_wep_key_len[i] = params->wep_key_len[i]; | |
3369 | } else | |
3370 | drv->auth_wep_key_len[i] = 0; | |
3371 | } | |
3372 | } | |
3373 | ||
3374 | ||
4bd71954 JM |
3375 | static void nl80211_unmask_11b_rates(struct i802_bss *bss) |
3376 | { | |
3377 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
3378 | ||
3379 | if (is_p2p_net_interface(drv->nlmode) || !drv->disabled_11b_rates) | |
3380 | return; | |
3381 | ||
3382 | /* | |
3383 | * Looks like we failed to unmask 11b rates previously. This could | |
3384 | * happen, e.g., if the interface was down at the point in time when a | |
3385 | * P2P group was terminated. | |
3386 | */ | |
3387 | wpa_printf(MSG_DEBUG, | |
3388 | "nl80211: Interface %s mode is for non-P2P, but 11b rates were disabled - re-enable them", | |
3389 | bss->ifname); | |
3390 | nl80211_disable_11b_rates(drv, drv->ifindex, 0); | |
3391 | } | |
3392 | ||
3393 | ||
3c67e977 VK |
3394 | static enum nl80211_auth_type get_nl_auth_type(int wpa_auth_alg) |
3395 | { | |
3396 | if (wpa_auth_alg & WPA_AUTH_ALG_OPEN) | |
3397 | return NL80211_AUTHTYPE_OPEN_SYSTEM; | |
3398 | if (wpa_auth_alg & WPA_AUTH_ALG_SHARED) | |
3399 | return NL80211_AUTHTYPE_SHARED_KEY; | |
3400 | if (wpa_auth_alg & WPA_AUTH_ALG_LEAP) | |
3401 | return NL80211_AUTHTYPE_NETWORK_EAP; | |
3402 | if (wpa_auth_alg & WPA_AUTH_ALG_FT) | |
3403 | return NL80211_AUTHTYPE_FT; | |
3404 | if (wpa_auth_alg & WPA_AUTH_ALG_SAE) | |
3405 | return NL80211_AUTHTYPE_SAE; | |
3406 | if (wpa_auth_alg & WPA_AUTH_ALG_FILS) | |
3407 | return NL80211_AUTHTYPE_FILS_SK; | |
3408 | if (wpa_auth_alg & WPA_AUTH_ALG_FILS_SK_PFS) | |
3409 | return NL80211_AUTHTYPE_FILS_SK_PFS; | |
3410 | ||
3411 | return NL80211_AUTHTYPE_MAX; | |
3412 | } | |
3413 | ||
3414 | ||
c2a04078 | 3415 | static int wpa_driver_nl80211_authenticate( |
9ebce9c5 | 3416 | struct i802_bss *bss, struct wpa_driver_auth_params *params) |
c2a04078 | 3417 | { |
a2e40bb6 | 3418 | struct wpa_driver_nl80211_data *drv = bss->drv; |
a0b2f99b | 3419 | int ret = -1, i; |
c2a04078 JM |
3420 | struct nl_msg *msg; |
3421 | enum nl80211_auth_type type; | |
2f4f73b1 | 3422 | enum nl80211_iftype nlmode; |
6d6f4bb8 | 3423 | int count = 0; |
536fd62d JM |
3424 | int is_retry; |
3425 | ||
4bd71954 JM |
3426 | nl80211_unmask_11b_rates(bss); |
3427 | ||
536fd62d JM |
3428 | is_retry = drv->retry_auth; |
3429 | drv->retry_auth = 0; | |
e8d70a73 | 3430 | drv->ignore_deauth_event = 0; |
c2a04078 | 3431 | |
add9b7a4 | 3432 | nl80211_mark_disconnected(drv); |
e6b8efeb | 3433 | os_memset(drv->auth_bssid, 0, ETH_ALEN); |
add9b7a4 JM |
3434 | if (params->bssid) |
3435 | os_memcpy(drv->auth_attempt_bssid, params->bssid, ETH_ALEN); | |
3436 | else | |
3437 | os_memset(drv->auth_attempt_bssid, 0, ETH_ALEN); | |
af473088 | 3438 | /* FIX: IBSS mode */ |
2f4f73b1 EP |
3439 | nlmode = params->p2p ? |
3440 | NL80211_IFTYPE_P2P_CLIENT : NL80211_IFTYPE_STATION; | |
3441 | if (drv->nlmode != nlmode && | |
9ebce9c5 | 3442 | wpa_driver_nl80211_set_mode(bss, nlmode) < 0) |
4a867032 JM |
3443 | return -1; |
3444 | ||
6d6f4bb8 | 3445 | retry: |
c2a04078 JM |
3446 | wpa_printf(MSG_DEBUG, "nl80211: Authenticate (ifindex=%d)", |
3447 | drv->ifindex); | |
a0b2f99b | 3448 | |
9725b784 JM |
3449 | msg = nl80211_drv_msg(drv, 0, NL80211_CMD_AUTHENTICATE); |
3450 | if (!msg) | |
3451 | goto fail; | |
0194fedb | 3452 | |
a0b2f99b JM |
3453 | for (i = 0; i < 4; i++) { |
3454 | if (!params->wep_key[i]) | |
3455 | continue; | |
9ebce9c5 | 3456 | wpa_driver_nl80211_set_key(bss->ifname, bss, WPA_ALG_WEP, |
2ea2fcc7 | 3457 | NULL, i, |
a0b2f99b JM |
3458 | i == params->wep_tx_keyidx, NULL, 0, |
3459 | params->wep_key[i], | |
3460 | params->wep_key_len[i]); | |
0194fedb JB |
3461 | if (params->wep_tx_keyidx != i) |
3462 | continue; | |
3463 | if (nl_add_key(msg, WPA_ALG_WEP, i, 1, NULL, 0, | |
9725b784 JM |
3464 | params->wep_key[i], params->wep_key_len[i])) |
3465 | goto fail; | |
a0b2f99b JM |
3466 | } |
3467 | ||
c2a04078 JM |
3468 | if (params->bssid) { |
3469 | wpa_printf(MSG_DEBUG, " * bssid=" MACSTR, | |
3470 | MAC2STR(params->bssid)); | |
a862e4a3 JM |
3471 | if (nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, params->bssid)) |
3472 | goto fail; | |
c2a04078 JM |
3473 | } |
3474 | if (params->freq) { | |
3475 | wpa_printf(MSG_DEBUG, " * freq=%d", params->freq); | |
a862e4a3 JM |
3476 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, params->freq)) |
3477 | goto fail; | |
c2a04078 JM |
3478 | } |
3479 | if (params->ssid) { | |
21cd8f83 JM |
3480 | wpa_printf(MSG_DEBUG, " * SSID=%s", |
3481 | wpa_ssid_txt(params->ssid, params->ssid_len)); | |
a862e4a3 JM |
3482 | if (nla_put(msg, NL80211_ATTR_SSID, params->ssid_len, |
3483 | params->ssid)) | |
3484 | goto fail; | |
c2a04078 JM |
3485 | } |
3486 | wpa_hexdump(MSG_DEBUG, " * IEs", params->ie, params->ie_len); | |
a862e4a3 JM |
3487 | if (params->ie && |
3488 | nla_put(msg, NL80211_ATTR_IE, params->ie_len, params->ie)) | |
3489 | goto fail; | |
ce16c489 JM |
3490 | if (params->auth_data) { |
3491 | wpa_hexdump(MSG_DEBUG, " * auth_data", params->auth_data, | |
3492 | params->auth_data_len); | |
3493 | if (nla_put(msg, NL80211_ATTR_SAE_DATA, params->auth_data_len, | |
3494 | params->auth_data)) | |
a862e4a3 | 3495 | goto fail; |
569fed90 | 3496 | } |
3c67e977 | 3497 | type = get_nl_auth_type(params->auth_alg); |
c2a04078 | 3498 | wpa_printf(MSG_DEBUG, " * Auth Type %d", type); |
3c67e977 VK |
3499 | if (type == NL80211_AUTHTYPE_MAX || |
3500 | nla_put_u32(msg, NL80211_ATTR_AUTH_TYPE, type)) | |
a862e4a3 | 3501 | goto fail; |
77339912 JM |
3502 | if (params->local_state_change) { |
3503 | wpa_printf(MSG_DEBUG, " * Local state change only"); | |
a862e4a3 JM |
3504 | if (nla_put_flag(msg, NL80211_ATTR_LOCAL_STATE_CHANGE)) |
3505 | goto fail; | |
77339912 | 3506 | } |
c2a04078 JM |
3507 | |
3508 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); | |
3509 | msg = NULL; | |
3510 | if (ret) { | |
3b7ea880 | 3511 | wpa_dbg(drv->ctx, MSG_DEBUG, |
f875da04 BG |
3512 | "nl80211: MLME command failed (auth): count=%d ret=%d (%s)", |
3513 | count, ret, strerror(-ret)); | |
6d6f4bb8 | 3514 | count++; |
f875da04 BG |
3515 | if ((ret == -EALREADY || ret == -EEXIST) && count == 1 && |
3516 | params->bssid && !params->local_state_change) { | |
6d6f4bb8 JM |
3517 | /* |
3518 | * mac80211 does not currently accept new | |
3519 | * authentication if we are already authenticated. As a | |
3520 | * workaround, force deauthentication and try again. | |
3521 | */ | |
3522 | wpa_printf(MSG_DEBUG, "nl80211: Retry authentication " | |
3523 | "after forced deauthentication"); | |
e8d70a73 | 3524 | drv->ignore_deauth_event = 1; |
6d6f4bb8 | 3525 | wpa_driver_nl80211_deauthenticate( |
5205c4f9 | 3526 | bss, params->bssid, |
6d6f4bb8 JM |
3527 | WLAN_REASON_PREV_AUTH_NOT_VALID); |
3528 | nlmsg_free(msg); | |
3529 | goto retry; | |
3530 | } | |
536fd62d JM |
3531 | |
3532 | if (ret == -ENOENT && params->freq && !is_retry) { | |
3533 | /* | |
3534 | * cfg80211 has likely expired the BSS entry even | |
3535 | * though it was previously available in our internal | |
3536 | * BSS table. To recover quickly, start a single | |
3537 | * channel scan on the specified channel. | |
3538 | */ | |
3539 | struct wpa_driver_scan_params scan; | |
3540 | int freqs[2]; | |
3541 | ||
3542 | os_memset(&scan, 0, sizeof(scan)); | |
3543 | scan.num_ssids = 1; | |
3544 | if (params->ssid) { | |
3545 | scan.ssids[0].ssid = params->ssid; | |
3546 | scan.ssids[0].ssid_len = params->ssid_len; | |
3547 | } | |
3548 | freqs[0] = params->freq; | |
3549 | freqs[1] = 0; | |
3550 | scan.freqs = freqs; | |
3551 | wpa_printf(MSG_DEBUG, "nl80211: Trigger single " | |
3552 | "channel scan to refresh cfg80211 BSS " | |
3553 | "entry"); | |
3554 | ret = wpa_driver_nl80211_scan(bss, &scan); | |
3555 | if (ret == 0) { | |
3556 | nl80211_copy_auth_params(drv, params); | |
3557 | drv->scan_for_auth = 1; | |
3558 | } | |
8c3ba078 JM |
3559 | } else if (is_retry) { |
3560 | /* | |
3561 | * Need to indicate this with an event since the return | |
3562 | * value from the retry is not delivered to core code. | |
3563 | */ | |
3564 | union wpa_event_data event; | |
3565 | wpa_printf(MSG_DEBUG, "nl80211: Authentication retry " | |
3566 | "failed"); | |
3567 | os_memset(&event, 0, sizeof(event)); | |
3568 | os_memcpy(event.timeout_event.addr, drv->auth_bssid_, | |
3569 | ETH_ALEN); | |
3570 | wpa_supplicant_event(drv->ctx, EVENT_AUTH_TIMED_OUT, | |
3571 | &event); | |
536fd62d | 3572 | } |
a862e4a3 JM |
3573 | } else { |
3574 | wpa_printf(MSG_DEBUG, | |
3575 | "nl80211: Authentication request send successfully"); | |
c2a04078 | 3576 | } |
c2a04078 | 3577 | |
a862e4a3 | 3578 | fail: |
c2a04078 JM |
3579 | nlmsg_free(msg); |
3580 | return ret; | |
3581 | } | |
3582 | ||
3583 | ||
f3407c66 | 3584 | int wpa_driver_nl80211_authenticate_retry(struct wpa_driver_nl80211_data *drv) |
536fd62d JM |
3585 | { |
3586 | struct wpa_driver_auth_params params; | |
834ee56f | 3587 | struct i802_bss *bss = drv->first_bss; |
536fd62d JM |
3588 | int i; |
3589 | ||
3590 | wpa_printf(MSG_DEBUG, "nl80211: Try to authenticate again"); | |
3591 | ||
3592 | os_memset(¶ms, 0, sizeof(params)); | |
3593 | params.freq = drv->auth_freq; | |
3594 | params.auth_alg = drv->auth_alg; | |
3595 | params.wep_tx_keyidx = drv->auth_wep_tx_keyidx; | |
3596 | params.local_state_change = drv->auth_local_state_change; | |
3597 | params.p2p = drv->auth_p2p; | |
3598 | ||
3599 | if (!is_zero_ether_addr(drv->auth_bssid_)) | |
3600 | params.bssid = drv->auth_bssid_; | |
3601 | ||
3602 | if (drv->auth_ssid_len) { | |
3603 | params.ssid = drv->auth_ssid; | |
3604 | params.ssid_len = drv->auth_ssid_len; | |
3605 | } | |
3606 | ||
3607 | params.ie = drv->auth_ie; | |
3608 | params.ie_len = drv->auth_ie_len; | |
3609 | ||
3610 | for (i = 0; i < 4; i++) { | |
3611 | if (drv->auth_wep_key_len[i]) { | |
3612 | params.wep_key[i] = drv->auth_wep_key[i]; | |
3613 | params.wep_key_len[i] = drv->auth_wep_key_len[i]; | |
3614 | } | |
3615 | } | |
3616 | ||
3617 | drv->retry_auth = 1; | |
3618 | return wpa_driver_nl80211_authenticate(bss, ¶ms); | |
3619 | } | |
3620 | ||
3621 | ||
a11241fa JB |
3622 | static int wpa_driver_nl80211_send_frame(struct i802_bss *bss, |
3623 | const void *data, size_t len, | |
55231068 JM |
3624 | int encrypt, int noack, |
3625 | unsigned int freq, int no_cck, | |
2d3943ce AO |
3626 | int offchanok, unsigned int wait_time, |
3627 | const u16 *csa_offs, | |
3628 | size_t csa_offs_len) | |
a11241fa JB |
3629 | { |
3630 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
3631 | u64 cookie; | |
41cc50d1 | 3632 | int res; |
a11241fa | 3633 | |
c7caac56 JM |
3634 | if (freq == 0 && drv->nlmode == NL80211_IFTYPE_ADHOC) { |
3635 | freq = nl80211_get_assoc_freq(drv); | |
3636 | wpa_printf(MSG_DEBUG, | |
3637 | "nl80211: send_frame - Use assoc_freq=%u for IBSS", | |
3638 | freq); | |
3639 | } | |
af964484 JM |
3640 | if (freq == 0) { |
3641 | wpa_printf(MSG_DEBUG, "nl80211: send_frame - Use bss->freq=%u", | |
3642 | bss->freq); | |
55231068 | 3643 | freq = bss->freq; |
af964484 | 3644 | } |
55231068 | 3645 | |
739faee2 | 3646 | if (drv->use_monitor) { |
981cf85a | 3647 | wpa_printf(MSG_DEBUG, "nl80211: send_frame(freq=%u bss->freq=%u) -> send_monitor", |
739faee2 | 3648 | freq, bss->freq); |
981cf85a | 3649 | return nl80211_send_monitor(drv, data, len, encrypt, noack); |
739faee2 | 3650 | } |
a11241fa | 3651 | |
739faee2 | 3652 | wpa_printf(MSG_DEBUG, "nl80211: send_frame -> send_frame_cmd"); |
41cc50d1 | 3653 | res = nl80211_send_frame_cmd(bss, freq, wait_time, data, len, |
2d3943ce AO |
3654 | &cookie, no_cck, noack, offchanok, |
3655 | csa_offs, csa_offs_len); | |
41cc50d1 JM |
3656 | if (res == 0 && !noack) { |
3657 | const struct ieee80211_mgmt *mgmt; | |
3658 | u16 fc; | |
3659 | ||
3660 | mgmt = (const struct ieee80211_mgmt *) data; | |
3661 | fc = le_to_host16(mgmt->frame_control); | |
3662 | if (WLAN_FC_GET_TYPE(fc) == WLAN_FC_TYPE_MGMT && | |
3663 | WLAN_FC_GET_STYPE(fc) == WLAN_FC_STYPE_ACTION) { | |
3664 | wpa_printf(MSG_MSGDUMP, | |
3665 | "nl80211: Update send_action_cookie from 0x%llx to 0x%llx", | |
3666 | (long long unsigned int) | |
3667 | drv->send_action_cookie, | |
3668 | (long long unsigned int) cookie); | |
3669 | drv->send_action_cookie = cookie; | |
3670 | } | |
3671 | } | |
3672 | ||
3673 | return res; | |
a11241fa JB |
3674 | } |
3675 | ||
3676 | ||
9ebce9c5 JM |
3677 | static int wpa_driver_nl80211_send_mlme(struct i802_bss *bss, const u8 *data, |
3678 | size_t data_len, int noack, | |
3679 | unsigned int freq, int no_cck, | |
3680 | int offchanok, | |
2d3943ce AO |
3681 | unsigned int wait_time, |
3682 | const u16 *csa_offs, | |
3683 | size_t csa_offs_len) | |
2c2010ac | 3684 | { |
a2e40bb6 | 3685 | struct wpa_driver_nl80211_data *drv = bss->drv; |
2c2010ac | 3686 | struct ieee80211_mgmt *mgmt; |
7a47d567 | 3687 | int encrypt = 1; |
2c2010ac JM |
3688 | u16 fc; |
3689 | ||
3690 | mgmt = (struct ieee80211_mgmt *) data; | |
3691 | fc = le_to_host16(mgmt->frame_control); | |
f95a4524 PF |
3692 | wpa_printf(MSG_DEBUG, "nl80211: send_mlme - da= " MACSTR |
3693 | " noack=%d freq=%u no_cck=%d offchanok=%d wait_time=%u fc=0x%x (%s) nlmode=%d", | |
3694 | MAC2STR(mgmt->da), noack, freq, no_cck, offchanok, wait_time, | |
3695 | fc, fc2str(fc), drv->nlmode); | |
2c2010ac | 3696 | |
8e12685c AS |
3697 | if ((is_sta_interface(drv->nlmode) || |
3698 | drv->nlmode == NL80211_IFTYPE_P2P_DEVICE) && | |
5582a5d1 JB |
3699 | WLAN_FC_GET_TYPE(fc) == WLAN_FC_TYPE_MGMT && |
3700 | WLAN_FC_GET_STYPE(fc) == WLAN_FC_STYPE_PROBE_RESP) { | |
3701 | /* | |
3702 | * The use of last_mgmt_freq is a bit of a hack, | |
3703 | * but it works due to the single-threaded nature | |
3704 | * of wpa_supplicant. | |
3705 | */ | |
af964484 JM |
3706 | if (freq == 0) { |
3707 | wpa_printf(MSG_DEBUG, "nl80211: Use last_mgmt_freq=%d", | |
3708 | drv->last_mgmt_freq); | |
55231068 | 3709 | freq = drv->last_mgmt_freq; |
af964484 | 3710 | } |
55231068 | 3711 | return nl80211_send_frame_cmd(bss, freq, 0, |
88df0ef7 | 3712 | data, data_len, NULL, 1, noack, |
2d3943ce | 3713 | 1, csa_offs, csa_offs_len); |
5582a5d1 JB |
3714 | } |
3715 | ||
61cbe2ff | 3716 | if (drv->device_ap_sme && is_ap_interface(drv->nlmode)) { |
af964484 JM |
3717 | if (freq == 0) { |
3718 | wpa_printf(MSG_DEBUG, "nl80211: Use bss->freq=%d", | |
3719 | bss->freq); | |
55231068 | 3720 | freq = bss->freq; |
af964484 | 3721 | } |
b5671498 JM |
3722 | return nl80211_send_frame_cmd(bss, freq, |
3723 | (int) freq == bss->freq ? 0 : | |
3724 | wait_time, | |
d8d6b32e DG |
3725 | data, data_len, |
3726 | &drv->send_action_cookie, | |
2d3943ce AO |
3727 | no_cck, noack, offchanok, |
3728 | csa_offs, csa_offs_len); | |
86957e62 JM |
3729 | } |
3730 | ||
2c2010ac JM |
3731 | if (WLAN_FC_GET_TYPE(fc) == WLAN_FC_TYPE_MGMT && |
3732 | WLAN_FC_GET_STYPE(fc) == WLAN_FC_STYPE_AUTH) { | |
3733 | /* | |
3734 | * Only one of the authentication frame types is encrypted. | |
3735 | * In order for static WEP encryption to work properly (i.e., | |
3736 | * to not encrypt the frame), we need to tell mac80211 about | |
3737 | * the frames that must not be encrypted. | |
3738 | */ | |
3739 | u16 auth_alg = le_to_host16(mgmt->u.auth.auth_alg); | |
3740 | u16 auth_trans = le_to_host16(mgmt->u.auth.auth_transaction); | |
7a47d567 JB |
3741 | if (auth_alg != WLAN_AUTH_SHARED_KEY || auth_trans != 3) |
3742 | encrypt = 0; | |
2c2010ac JM |
3743 | } |
3744 | ||
739faee2 | 3745 | wpa_printf(MSG_DEBUG, "nl80211: send_mlme -> send_frame"); |
a11241fa | 3746 | return wpa_driver_nl80211_send_frame(bss, data, data_len, encrypt, |
55231068 | 3747 | noack, freq, no_cck, offchanok, |
2d3943ce AO |
3748 | wait_time, csa_offs, |
3749 | csa_offs_len); | |
55231068 JM |
3750 | } |
3751 | ||
3752 | ||
cae87abd JM |
3753 | static int nl80211_put_basic_rates(struct nl_msg *msg, const int *basic_rates) |
3754 | { | |
3755 | u8 rates[NL80211_MAX_SUPP_RATES]; | |
3756 | u8 rates_len = 0; | |
3757 | int i; | |
3758 | ||
3759 | if (!basic_rates) | |
3760 | return 0; | |
3761 | ||
3762 | for (i = 0; i < NL80211_MAX_SUPP_RATES && basic_rates[i] >= 0; i++) | |
3763 | rates[rates_len++] = basic_rates[i] / 5; | |
3764 | ||
3765 | return nla_put(msg, NL80211_ATTR_BSS_BASIC_RATES, rates_len, rates); | |
3766 | } | |
3767 | ||
3768 | ||
31357268 | 3769 | static int nl80211_set_bss(struct i802_bss *bss, int cts, int preamble, |
e5693c47 | 3770 | int slot, int ht_opmode, int ap_isolate, |
cae87abd | 3771 | const int *basic_rates) |
31357268 JM |
3772 | { |
3773 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
3774 | struct nl_msg *msg; | |
3775 | ||
13f83980 | 3776 | if (!(msg = nl80211_bss_msg(bss, 0, NL80211_CMD_SET_BSS)) || |
a862e4a3 JM |
3777 | (cts >= 0 && |
3778 | nla_put_u8(msg, NL80211_ATTR_BSS_CTS_PROT, cts)) || | |
3779 | (preamble >= 0 && | |
3780 | nla_put_u8(msg, NL80211_ATTR_BSS_SHORT_PREAMBLE, preamble)) || | |
3781 | (slot >= 0 && | |
3782 | nla_put_u8(msg, NL80211_ATTR_BSS_SHORT_SLOT_TIME, slot)) || | |
3783 | (ht_opmode >= 0 && | |
3784 | nla_put_u16(msg, NL80211_ATTR_BSS_HT_OPMODE, ht_opmode)) || | |
3785 | (ap_isolate >= 0 && | |
cae87abd JM |
3786 | nla_put_u8(msg, NL80211_ATTR_AP_ISOLATE, ap_isolate)) || |
3787 | nl80211_put_basic_rates(msg, basic_rates)) { | |
3788 | nlmsg_free(msg); | |
3789 | return -ENOBUFS; | |
e5693c47 JM |
3790 | } |
3791 | ||
31357268 | 3792 | return send_and_recv_msgs(drv, msg, NULL, NULL); |
31357268 JM |
3793 | } |
3794 | ||
3795 | ||
3c4ca363 VN |
3796 | static int wpa_driver_nl80211_set_acl(void *priv, |
3797 | struct hostapd_acl_params *params) | |
3798 | { | |
3799 | struct i802_bss *bss = priv; | |
3800 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
3801 | struct nl_msg *msg; | |
f429ec44 | 3802 | struct nl_msg *acl; |
3c4ca363 | 3803 | unsigned int i; |
a862e4a3 | 3804 | int ret; |
3c4ca363 VN |
3805 | |
3806 | if (!(drv->capa.max_acl_mac_addrs)) | |
3807 | return -ENOTSUP; | |
3808 | ||
3809 | if (params->num_mac_acl > drv->capa.max_acl_mac_addrs) | |
3810 | return -ENOTSUP; | |
3811 | ||
3c4ca363 VN |
3812 | wpa_printf(MSG_DEBUG, "nl80211: Set %s ACL (num_mac_acl=%u)", |
3813 | params->acl_policy ? "Accept" : "Deny", params->num_mac_acl); | |
3814 | ||
f429ec44 JM |
3815 | acl = nlmsg_alloc(); |
3816 | if (!acl) | |
3817 | return -ENOMEM; | |
3818 | for (i = 0; i < params->num_mac_acl; i++) { | |
3819 | if (nla_put(acl, i + 1, ETH_ALEN, params->mac_acl[i].addr)) { | |
3820 | nlmsg_free(acl); | |
3821 | return -ENOMEM; | |
3822 | } | |
3823 | } | |
3824 | ||
9725b784 | 3825 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_SET_MAC_ACL)) || |
a862e4a3 JM |
3826 | nla_put_u32(msg, NL80211_ATTR_ACL_POLICY, params->acl_policy ? |
3827 | NL80211_ACL_POLICY_DENY_UNLESS_LISTED : | |
3828 | NL80211_ACL_POLICY_ACCEPT_UNLESS_LISTED) || | |
f429ec44 | 3829 | nla_put_nested(msg, NL80211_ATTR_MAC_ADDRS, acl)) { |
a862e4a3 | 3830 | nlmsg_free(msg); |
f429ec44 | 3831 | nlmsg_free(acl); |
a862e4a3 JM |
3832 | return -ENOMEM; |
3833 | } | |
f429ec44 | 3834 | nlmsg_free(acl); |
3c4ca363 VN |
3835 | |
3836 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); | |
3c4ca363 VN |
3837 | if (ret) { |
3838 | wpa_printf(MSG_DEBUG, "nl80211: Failed to set MAC ACL: %d (%s)", | |
3839 | ret, strerror(-ret)); | |
3840 | } | |
3841 | ||
3c4ca363 VN |
3842 | return ret; |
3843 | } | |
3844 | ||
3845 | ||
85e1fad8 JM |
3846 | static int nl80211_put_beacon_int(struct nl_msg *msg, int beacon_int) |
3847 | { | |
3848 | if (beacon_int > 0) { | |
3849 | wpa_printf(MSG_DEBUG, " * beacon_int=%d", beacon_int); | |
3850 | return nla_put_u32(msg, NL80211_ATTR_BEACON_INTERVAL, | |
3851 | beacon_int); | |
3852 | } | |
3853 | ||
3854 | return 0; | |
3855 | } | |
3856 | ||
3857 | ||
4ac2ea57 MH |
3858 | static int nl80211_put_dtim_period(struct nl_msg *msg, int dtim_period) |
3859 | { | |
3860 | if (dtim_period > 0) { | |
3861 | wpa_printf(MSG_DEBUG, " * dtim_period=%d", dtim_period); | |
3862 | return nla_put_u32(msg, NL80211_ATTR_DTIM_PERIOD, dtim_period); | |
3863 | } | |
3864 | ||
3865 | return 0; | |
3866 | } | |
3867 | ||
3868 | ||
052b8d38 MH |
3869 | #ifdef CONFIG_MESH |
3870 | static int nl80211_set_mesh_config(void *priv, | |
3871 | struct wpa_driver_mesh_bss_params *params) | |
3872 | { | |
3873 | struct i802_bss *bss = priv; | |
3874 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
3875 | struct nl_msg *msg; | |
3876 | int ret; | |
3877 | ||
3878 | msg = nl80211_drv_msg(drv, 0, NL80211_CMD_SET_MESH_CONFIG); | |
3879 | if (!msg) | |
3880 | return -1; | |
3881 | ||
3882 | ret = nl80211_put_mesh_config(msg, params); | |
3883 | if (ret < 0) { | |
3884 | nlmsg_free(msg); | |
3885 | return ret; | |
3886 | } | |
3887 | ||
3888 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); | |
3889 | if (ret) { | |
3890 | wpa_printf(MSG_ERROR, | |
3891 | "nl80211: Mesh config set failed: %d (%s)", | |
3892 | ret, strerror(-ret)); | |
3893 | return ret; | |
3894 | } | |
3895 | return 0; | |
3896 | } | |
3897 | #endif /* CONFIG_MESH */ | |
3898 | ||
3899 | ||
d4f3003c PK |
3900 | static int nl80211_put_beacon_rate(struct nl_msg *msg, const u64 flags, |
3901 | struct wpa_driver_ap_params *params) | |
3902 | { | |
3903 | struct nlattr *bands, *band; | |
3904 | struct nl80211_txrate_vht vht_rate; | |
3905 | ||
3906 | if (!params->freq || | |
3907 | (params->beacon_rate == 0 && | |
3908 | params->rate_type == BEACON_RATE_LEGACY)) | |
3909 | return 0; | |
3910 | ||
3911 | bands = nla_nest_start(msg, NL80211_ATTR_TX_RATES); | |
3912 | if (!bands) | |
3913 | return -1; | |
3914 | ||
3915 | switch (params->freq->mode) { | |
3916 | case HOSTAPD_MODE_IEEE80211B: | |
3917 | case HOSTAPD_MODE_IEEE80211G: | |
3918 | band = nla_nest_start(msg, NL80211_BAND_2GHZ); | |
3919 | break; | |
3920 | case HOSTAPD_MODE_IEEE80211A: | |
3921 | band = nla_nest_start(msg, NL80211_BAND_5GHZ); | |
3922 | break; | |
3923 | case HOSTAPD_MODE_IEEE80211AD: | |
3924 | band = nla_nest_start(msg, NL80211_BAND_60GHZ); | |
3925 | break; | |
3926 | default: | |
3927 | return 0; | |
3928 | } | |
3929 | ||
3930 | if (!band) | |
3931 | return -1; | |
3932 | ||
3933 | os_memset(&vht_rate, 0, sizeof(vht_rate)); | |
3934 | ||
3935 | switch (params->rate_type) { | |
3936 | case BEACON_RATE_LEGACY: | |
3937 | if (!(flags & WPA_DRIVER_FLAGS_BEACON_RATE_LEGACY)) { | |
3938 | wpa_printf(MSG_INFO, | |
3939 | "nl80211: Driver does not support setting Beacon frame rate (legacy)"); | |
3940 | return -1; | |
3941 | } | |
3942 | ||
3943 | if (nla_put_u8(msg, NL80211_TXRATE_LEGACY, | |
3944 | (u8) params->beacon_rate / 5) || | |
3945 | nla_put(msg, NL80211_TXRATE_HT, 0, NULL) || | |
3946 | (params->freq->vht_enabled && | |
3947 | nla_put(msg, NL80211_TXRATE_VHT, sizeof(vht_rate), | |
3948 | &vht_rate))) | |
3949 | return -1; | |
3950 | ||
3951 | wpa_printf(MSG_DEBUG, " * beacon_rate = legacy:%u (* 100 kbps)", | |
3952 | params->beacon_rate); | |
3953 | break; | |
3954 | case BEACON_RATE_HT: | |
3955 | if (!(flags & WPA_DRIVER_FLAGS_BEACON_RATE_HT)) { | |
3956 | wpa_printf(MSG_INFO, | |
3957 | "nl80211: Driver does not support setting Beacon frame rate (HT)"); | |
3958 | return -1; | |
3959 | } | |
3960 | if (nla_put(msg, NL80211_TXRATE_LEGACY, 0, NULL) || | |
3961 | nla_put_u8(msg, NL80211_TXRATE_HT, params->beacon_rate) || | |
3962 | (params->freq->vht_enabled && | |
3963 | nla_put(msg, NL80211_TXRATE_VHT, sizeof(vht_rate), | |
3964 | &vht_rate))) | |
3965 | return -1; | |
3966 | wpa_printf(MSG_DEBUG, " * beacon_rate = HT-MCS %u", | |
3967 | params->beacon_rate); | |
3968 | break; | |
3969 | case BEACON_RATE_VHT: | |
3970 | if (!(flags & WPA_DRIVER_FLAGS_BEACON_RATE_VHT)) { | |
3971 | wpa_printf(MSG_INFO, | |
3972 | "nl80211: Driver does not support setting Beacon frame rate (VHT)"); | |
3973 | return -1; | |
3974 | } | |
3975 | vht_rate.mcs[0] = BIT(params->beacon_rate); | |
3976 | if (nla_put(msg, NL80211_TXRATE_LEGACY, 0, NULL)) | |
3977 | return -1; | |
3978 | if (nla_put(msg, NL80211_TXRATE_HT, 0, NULL)) | |
3979 | return -1; | |
3980 | if (nla_put(msg, NL80211_TXRATE_VHT, sizeof(vht_rate), | |
3981 | &vht_rate)) | |
3982 | return -1; | |
3983 | wpa_printf(MSG_DEBUG, " * beacon_rate = VHT-MCS %u", | |
3984 | params->beacon_rate); | |
3985 | break; | |
3986 | } | |
3987 | ||
3988 | nla_nest_end(msg, band); | |
3989 | nla_nest_end(msg, bands); | |
3990 | ||
3991 | return 0; | |
3992 | } | |
3993 | ||
3994 | ||
34f7c699 MB |
3995 | static int nl80211_set_multicast_to_unicast(struct i802_bss *bss, |
3996 | int multicast_to_unicast) | |
3997 | { | |
3998 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
3999 | struct nl_msg *msg; | |
4000 | int ret; | |
4001 | ||
4002 | msg = nl80211_bss_msg(bss, 0, NL80211_CMD_SET_MULTICAST_TO_UNICAST); | |
4003 | if (!msg || | |
4004 | (multicast_to_unicast && | |
4005 | nla_put_flag(msg, NL80211_ATTR_MULTICAST_TO_UNICAST_ENABLED))) { | |
4006 | wpa_printf(MSG_ERROR, | |
4007 | "nl80211: Failed to build NL80211_CMD_SET_MULTICAST_TO_UNICAST msg for %s", | |
4008 | bss->ifname); | |
4009 | nlmsg_free(msg); | |
4010 | return -ENOBUFS; | |
4011 | } | |
4012 | ||
4013 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); | |
4014 | ||
4015 | switch (ret) { | |
4016 | case 0: | |
4017 | wpa_printf(MSG_DEBUG, | |
4018 | "nl80211: multicast to unicast %s on interface %s", | |
4019 | multicast_to_unicast ? "enabled" : "disabled", | |
4020 | bss->ifname); | |
4021 | break; | |
4022 | case -EOPNOTSUPP: | |
4023 | if (!multicast_to_unicast) | |
4024 | break; | |
4025 | wpa_printf(MSG_INFO, | |
4026 | "nl80211: multicast to unicast not supported on interface %s", | |
4027 | bss->ifname); | |
4028 | break; | |
4029 | default: | |
4030 | wpa_printf(MSG_ERROR, | |
4031 | "nl80211: %s multicast to unicast failed with %d (%s) on interface %s", | |
4032 | multicast_to_unicast ? "enabling" : "disabling", | |
4033 | ret, strerror(-ret), bss->ifname); | |
4034 | break; | |
4035 | } | |
4036 | ||
4037 | return ret; | |
4038 | } | |
4039 | ||
4040 | ||
19c3b566 JM |
4041 | static int wpa_driver_nl80211_set_ap(void *priv, |
4042 | struct wpa_driver_ap_params *params) | |
d2440ba0 | 4043 | { |
a2e40bb6 FF |
4044 | struct i802_bss *bss = priv; |
4045 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
d2440ba0 JM |
4046 | struct nl_msg *msg; |
4047 | u8 cmd = NL80211_CMD_NEW_BEACON; | |
5b82cdbe | 4048 | int ret = -ENOBUFS; |
b4fd6fab | 4049 | int beacon_set; |
b11d1d64 | 4050 | int num_suites; |
da1080d7 | 4051 | int smps_mode; |
de4ed4a8 | 4052 | u32 suites[10], suite; |
b11d1d64 | 4053 | u32 ver; |
052b8d38 MH |
4054 | #ifdef CONFIG_MESH |
4055 | struct wpa_driver_mesh_bss_params mesh_params; | |
4056 | #endif /* CONFIG_MESH */ | |
b4fd6fab | 4057 | |
f33c8606 | 4058 | beacon_set = params->reenable ? 0 : bss->beacon_set; |
d2440ba0 | 4059 | |
d2440ba0 | 4060 | wpa_printf(MSG_DEBUG, "nl80211: Set beacon (beacon_set=%d)", |
b4fd6fab JM |
4061 | beacon_set); |
4062 | if (beacon_set) | |
d2440ba0 | 4063 | cmd = NL80211_CMD_SET_BEACON; |
89fa633a DL |
4064 | else if (!drv->device_ap_sme && !drv->use_monitor && |
4065 | !nl80211_get_wiphy_data_ap(bss)) | |
a70cd0db | 4066 | return -ENOBUFS; |
d2440ba0 | 4067 | |
b92e08fc JM |
4068 | wpa_hexdump(MSG_DEBUG, "nl80211: Beacon head", |
4069 | params->head, params->head_len); | |
b92e08fc JM |
4070 | wpa_hexdump(MSG_DEBUG, "nl80211: Beacon tail", |
4071 | params->tail, params->tail_len); | |
13f83980 | 4072 | wpa_printf(MSG_DEBUG, "nl80211: ifindex=%d", bss->ifindex); |
b92e08fc | 4073 | wpa_printf(MSG_DEBUG, "nl80211: beacon_int=%d", params->beacon_int); |
d4f3003c PK |
4074 | wpa_printf(MSG_DEBUG, "nl80211: beacon_rate=%u", params->beacon_rate); |
4075 | wpa_printf(MSG_DEBUG, "nl80211: rate_type=%d", params->rate_type); | |
b92e08fc | 4076 | wpa_printf(MSG_DEBUG, "nl80211: dtim_period=%d", params->dtim_period); |
21cd8f83 JM |
4077 | wpa_printf(MSG_DEBUG, "nl80211: ssid=%s", |
4078 | wpa_ssid_txt(params->ssid, params->ssid_len)); | |
13f83980 | 4079 | if (!(msg = nl80211_bss_msg(bss, 0, cmd)) || |
a862e4a3 JM |
4080 | nla_put(msg, NL80211_ATTR_BEACON_HEAD, params->head_len, |
4081 | params->head) || | |
4082 | nla_put(msg, NL80211_ATTR_BEACON_TAIL, params->tail_len, | |
4083 | params->tail) || | |
85e1fad8 | 4084 | nl80211_put_beacon_int(msg, params->beacon_int) || |
d4f3003c | 4085 | nl80211_put_beacon_rate(msg, drv->capa.flags, params) || |
4ac2ea57 | 4086 | nl80211_put_dtim_period(msg, params->dtim_period) || |
a862e4a3 JM |
4087 | nla_put(msg, NL80211_ATTR_SSID, params->ssid_len, params->ssid)) |
4088 | goto fail; | |
b92e08fc JM |
4089 | if (params->proberesp && params->proberesp_len) { |
4090 | wpa_hexdump(MSG_DEBUG, "nl80211: proberesp (offload)", | |
4091 | params->proberesp, params->proberesp_len); | |
a862e4a3 JM |
4092 | if (nla_put(msg, NL80211_ATTR_PROBE_RESP, params->proberesp_len, |
4093 | params->proberesp)) | |
4094 | goto fail; | |
b92e08fc | 4095 | } |
97a7a0b5 JM |
4096 | switch (params->hide_ssid) { |
4097 | case NO_SSID_HIDING: | |
b92e08fc | 4098 | wpa_printf(MSG_DEBUG, "nl80211: hidden SSID not in use"); |
a862e4a3 JM |
4099 | if (nla_put_u32(msg, NL80211_ATTR_HIDDEN_SSID, |
4100 | NL80211_HIDDEN_SSID_NOT_IN_USE)) | |
4101 | goto fail; | |
97a7a0b5 JM |
4102 | break; |
4103 | case HIDDEN_SSID_ZERO_LEN: | |
b92e08fc | 4104 | wpa_printf(MSG_DEBUG, "nl80211: hidden SSID zero len"); |
a862e4a3 JM |
4105 | if (nla_put_u32(msg, NL80211_ATTR_HIDDEN_SSID, |
4106 | NL80211_HIDDEN_SSID_ZERO_LEN)) | |
4107 | goto fail; | |
97a7a0b5 JM |
4108 | break; |
4109 | case HIDDEN_SSID_ZERO_CONTENTS: | |
b92e08fc | 4110 | wpa_printf(MSG_DEBUG, "nl80211: hidden SSID zero contents"); |
a862e4a3 JM |
4111 | if (nla_put_u32(msg, NL80211_ATTR_HIDDEN_SSID, |
4112 | NL80211_HIDDEN_SSID_ZERO_CONTENTS)) | |
4113 | goto fail; | |
97a7a0b5 JM |
4114 | break; |
4115 | } | |
b92e08fc | 4116 | wpa_printf(MSG_DEBUG, "nl80211: privacy=%d", params->privacy); |
a862e4a3 JM |
4117 | if (params->privacy && |
4118 | nla_put_flag(msg, NL80211_ATTR_PRIVACY)) | |
4119 | goto fail; | |
b92e08fc | 4120 | wpa_printf(MSG_DEBUG, "nl80211: auth_algs=0x%x", params->auth_algs); |
b11d1d64 JM |
4121 | if ((params->auth_algs & (WPA_AUTH_ALG_OPEN | WPA_AUTH_ALG_SHARED)) == |
4122 | (WPA_AUTH_ALG_OPEN | WPA_AUTH_ALG_SHARED)) { | |
4123 | /* Leave out the attribute */ | |
a862e4a3 JM |
4124 | } else if (params->auth_algs & WPA_AUTH_ALG_SHARED) { |
4125 | if (nla_put_u32(msg, NL80211_ATTR_AUTH_TYPE, | |
4126 | NL80211_AUTHTYPE_SHARED_KEY)) | |
4127 | goto fail; | |
4128 | } else { | |
4129 | if (nla_put_u32(msg, NL80211_ATTR_AUTH_TYPE, | |
4130 | NL80211_AUTHTYPE_OPEN_SYSTEM)) | |
4131 | goto fail; | |
4132 | } | |
b11d1d64 | 4133 | |
b92e08fc | 4134 | wpa_printf(MSG_DEBUG, "nl80211: wpa_version=0x%x", params->wpa_version); |
b11d1d64 JM |
4135 | ver = 0; |
4136 | if (params->wpa_version & WPA_PROTO_WPA) | |
4137 | ver |= NL80211_WPA_VERSION_1; | |
4138 | if (params->wpa_version & WPA_PROTO_RSN) | |
4139 | ver |= NL80211_WPA_VERSION_2; | |
a862e4a3 JM |
4140 | if (ver && |
4141 | nla_put_u32(msg, NL80211_ATTR_WPA_VERSIONS, ver)) | |
4142 | goto fail; | |
b11d1d64 | 4143 | |
b92e08fc JM |
4144 | wpa_printf(MSG_DEBUG, "nl80211: key_mgmt_suites=0x%x", |
4145 | params->key_mgmt_suites); | |
b11d1d64 JM |
4146 | num_suites = 0; |
4147 | if (params->key_mgmt_suites & WPA_KEY_MGMT_IEEE8021X) | |
3aa24db9 | 4148 | suites[num_suites++] = RSN_AUTH_KEY_MGMT_UNSPEC_802_1X; |
b11d1d64 | 4149 | if (params->key_mgmt_suites & WPA_KEY_MGMT_PSK) |
3aa24db9 | 4150 | suites[num_suites++] = RSN_AUTH_KEY_MGMT_PSK_OVER_802_1X; |
a862e4a3 JM |
4151 | if (num_suites && |
4152 | nla_put(msg, NL80211_ATTR_AKM_SUITES, num_suites * sizeof(u32), | |
4153 | suites)) | |
4154 | goto fail; | |
b11d1d64 | 4155 | |
533fe09b | 4156 | if (params->key_mgmt_suites & WPA_KEY_MGMT_IEEE8021X_NO_WPA && |
e3429c0b JB |
4157 | (!params->pairwise_ciphers || |
4158 | params->pairwise_ciphers & (WPA_CIPHER_WEP104 | WPA_CIPHER_WEP40)) && | |
4159 | (nla_put_u16(msg, NL80211_ATTR_CONTROL_PORT_ETHERTYPE, ETH_P_PAE) || | |
4160 | nla_put_flag(msg, NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT))) | |
a862e4a3 | 4161 | goto fail; |
9f12614b | 4162 | |
b92e08fc JM |
4163 | wpa_printf(MSG_DEBUG, "nl80211: pairwise_ciphers=0x%x", |
4164 | params->pairwise_ciphers); | |
de4ed4a8 JM |
4165 | num_suites = wpa_cipher_to_cipher_suites(params->pairwise_ciphers, |
4166 | suites, ARRAY_SIZE(suites)); | |
a862e4a3 JM |
4167 | if (num_suites && |
4168 | nla_put(msg, NL80211_ATTR_CIPHER_SUITES_PAIRWISE, | |
4169 | num_suites * sizeof(u32), suites)) | |
4170 | goto fail; | |
b11d1d64 | 4171 | |
b92e08fc JM |
4172 | wpa_printf(MSG_DEBUG, "nl80211: group_cipher=0x%x", |
4173 | params->group_cipher); | |
de4ed4a8 | 4174 | suite = wpa_cipher_to_cipher_suite(params->group_cipher); |
a862e4a3 JM |
4175 | if (suite && |
4176 | nla_put_u32(msg, NL80211_ATTR_CIPHER_SUITE_GROUP, suite)) | |
4177 | goto fail; | |
d2440ba0 | 4178 | |
ee298f1b JM |
4179 | if (params->ht_opmode != -1) { |
4180 | switch (params->smps_mode) { | |
4181 | case HT_CAP_INFO_SMPS_DYNAMIC: | |
4182 | wpa_printf(MSG_DEBUG, "nl80211: SMPS mode - dynamic"); | |
4183 | smps_mode = NL80211_SMPS_DYNAMIC; | |
4184 | break; | |
4185 | case HT_CAP_INFO_SMPS_STATIC: | |
4186 | wpa_printf(MSG_DEBUG, "nl80211: SMPS mode - static"); | |
4187 | smps_mode = NL80211_SMPS_STATIC; | |
4188 | break; | |
4189 | default: | |
4190 | /* invalid - fallback to smps off */ | |
4191 | case HT_CAP_INFO_SMPS_DISABLED: | |
4192 | wpa_printf(MSG_DEBUG, "nl80211: SMPS mode - off"); | |
4193 | smps_mode = NL80211_SMPS_OFF; | |
4194 | break; | |
4195 | } | |
a2426829 | 4196 | if (nla_put_u8(msg, NL80211_ATTR_SMPS_MODE, smps_mode)) |
ee298f1b | 4197 | goto fail; |
da1080d7 | 4198 | } |
da1080d7 | 4199 | |
fb91db56 | 4200 | if (params->beacon_ies) { |
b92e08fc JM |
4201 | wpa_hexdump_buf(MSG_DEBUG, "nl80211: beacon_ies", |
4202 | params->beacon_ies); | |
a862e4a3 JM |
4203 | if (nla_put(msg, NL80211_ATTR_IE, |
4204 | wpabuf_len(params->beacon_ies), | |
4205 | wpabuf_head(params->beacon_ies))) | |
4206 | goto fail; | |
fb91db56 JM |
4207 | } |
4208 | if (params->proberesp_ies) { | |
b92e08fc JM |
4209 | wpa_hexdump_buf(MSG_DEBUG, "nl80211: proberesp_ies", |
4210 | params->proberesp_ies); | |
a862e4a3 JM |
4211 | if (nla_put(msg, NL80211_ATTR_IE_PROBE_RESP, |
4212 | wpabuf_len(params->proberesp_ies), | |
4213 | wpabuf_head(params->proberesp_ies))) | |
4214 | goto fail; | |
fb91db56 JM |
4215 | } |
4216 | if (params->assocresp_ies) { | |
b92e08fc JM |
4217 | wpa_hexdump_buf(MSG_DEBUG, "nl80211: assocresp_ies", |
4218 | params->assocresp_ies); | |
a862e4a3 JM |
4219 | if (nla_put(msg, NL80211_ATTR_IE_ASSOC_RESP, |
4220 | wpabuf_len(params->assocresp_ies), | |
4221 | wpabuf_head(params->assocresp_ies))) | |
4222 | goto fail; | |
fb91db56 JM |
4223 | } |
4224 | ||
a0133ee1 | 4225 | if (drv->capa.flags & WPA_DRIVER_FLAGS_INACTIVITY_TIMER) { |
b92e08fc JM |
4226 | wpa_printf(MSG_DEBUG, "nl80211: ap_max_inactivity=%d", |
4227 | params->ap_max_inactivity); | |
a862e4a3 JM |
4228 | if (nla_put_u16(msg, NL80211_ATTR_INACTIVITY_TIMEOUT, |
4229 | params->ap_max_inactivity)) | |
4230 | goto fail; | |
a0133ee1 VT |
4231 | } |
4232 | ||
abb8d08b EP |
4233 | #ifdef CONFIG_P2P |
4234 | if (params->p2p_go_ctwindow > 0) { | |
4235 | if (drv->p2p_go_ctwindow_supported) { | |
4236 | wpa_printf(MSG_DEBUG, "nl80211: P2P GO ctwindow=%d", | |
4237 | params->p2p_go_ctwindow); | |
4238 | if (nla_put_u8(msg, NL80211_ATTR_P2P_CTWINDOW, | |
4239 | params->p2p_go_ctwindow)) | |
4240 | goto fail; | |
4241 | } else { | |
4242 | wpa_printf(MSG_INFO, | |
4243 | "nl80211: Driver does not support CTWindow configuration - ignore this parameter"); | |
4244 | } | |
4245 | } | |
4246 | #endif /* CONFIG_P2P */ | |
4247 | ||
86b5c400 LD |
4248 | if (params->pbss) { |
4249 | wpa_printf(MSG_DEBUG, "nl80211: PBSS"); | |
4250 | if (nla_put_flag(msg, NL80211_ATTR_PBSS)) | |
4251 | goto fail; | |
4252 | } | |
4253 | ||
5b82cdbe JB |
4254 | if (params->ftm_responder) { |
4255 | struct nlattr *ftm; | |
4256 | ||
4257 | if (!(drv->capa.flags & WPA_DRIVER_FLAGS_FTM_RESPONDER)) { | |
4258 | ret = -ENOTSUP; | |
4259 | goto fail; | |
4260 | } | |
4261 | ||
4262 | ftm = nla_nest_start(msg, NL80211_ATTR_FTM_RESPONDER); | |
4263 | if (!ftm || | |
4264 | nla_put_flag(msg, NL80211_FTM_RESP_ATTR_ENABLED) || | |
4265 | (params->lci && | |
4266 | nla_put(msg, NL80211_FTM_RESP_ATTR_LCI, | |
4267 | wpabuf_len(params->lci), | |
4268 | wpabuf_head(params->lci))) || | |
4269 | (params->civic && | |
4270 | nla_put(msg, NL80211_FTM_RESP_ATTR_CIVICLOC, | |
4271 | wpabuf_len(params->civic), | |
4272 | wpabuf_head(params->civic)))) | |
4273 | goto fail; | |
4274 | nla_nest_end(msg, ftm); | |
4275 | } | |
4276 | ||
d2440ba0 JM |
4277 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
4278 | if (ret) { | |
4279 | wpa_printf(MSG_DEBUG, "nl80211: Beacon set failed: %d (%s)", | |
4280 | ret, strerror(-ret)); | |
b4fd6fab | 4281 | } else { |
b4fd6fab | 4282 | bss->beacon_set = 1; |
31357268 | 4283 | nl80211_set_bss(bss, params->cts_protect, params->preamble, |
d03e8d11 | 4284 | params->short_slot_time, params->ht_opmode, |
e5693c47 | 4285 | params->isolate, params->basic_rates); |
34f7c699 MB |
4286 | nl80211_set_multicast_to_unicast(bss, |
4287 | params->multicast_to_unicast); | |
e87ef751 PX |
4288 | if (beacon_set && params->freq && |
4289 | params->freq->bandwidth != bss->bandwidth) { | |
4290 | wpa_printf(MSG_DEBUG, | |
4291 | "nl80211: Update BSS %s bandwidth: %d -> %d", | |
4292 | bss->ifname, bss->bandwidth, | |
4293 | params->freq->bandwidth); | |
4294 | ret = nl80211_set_channel(bss, params->freq, 1); | |
4295 | if (ret) { | |
4296 | wpa_printf(MSG_DEBUG, | |
4297 | "nl80211: Frequency set failed: %d (%s)", | |
4298 | ret, strerror(-ret)); | |
4299 | } else { | |
4300 | wpa_printf(MSG_DEBUG, | |
4301 | "nl80211: Frequency set succeeded for ht2040 coex"); | |
4302 | bss->bandwidth = params->freq->bandwidth; | |
4303 | } | |
f5728d0a | 4304 | } else if (!beacon_set && params->freq) { |
e87ef751 PX |
4305 | /* |
4306 | * cfg80211 updates the driver on frequence change in AP | |
4307 | * mode only at the point when beaconing is started, so | |
4308 | * set the initial value here. | |
4309 | */ | |
4310 | bss->bandwidth = params->freq->bandwidth; | |
4311 | } | |
b4fd6fab | 4312 | } |
052b8d38 MH |
4313 | |
4314 | #ifdef CONFIG_MESH | |
4315 | if (is_mesh_interface(drv->nlmode) && params->ht_opmode != -1) { | |
4316 | os_memset(&mesh_params, 0, sizeof(mesh_params)); | |
4317 | mesh_params.flags |= WPA_DRIVER_MESH_CONF_FLAG_HT_OP_MODE; | |
4318 | mesh_params.ht_opmode = params->ht_opmode; | |
4319 | ret = nl80211_set_mesh_config(priv, &mesh_params); | |
4320 | if (ret < 0) | |
4321 | return ret; | |
4322 | } | |
4323 | #endif /* CONFIG_MESH */ | |
4324 | ||
d2440ba0 | 4325 | return ret; |
a862e4a3 | 4326 | fail: |
5883168a | 4327 | nlmsg_free(msg); |
5b82cdbe | 4328 | return ret; |
d2440ba0 JM |
4329 | } |
4330 | ||
4331 | ||
1c4ffa87 | 4332 | static int nl80211_put_freq_params(struct nl_msg *msg, |
72b2605f | 4333 | const struct hostapd_freq_params *freq) |
1581b38b | 4334 | { |
1fc4ab23 | 4335 | wpa_printf(MSG_DEBUG, " * freq=%d", freq->freq); |
a862e4a3 JM |
4336 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq->freq)) |
4337 | return -ENOBUFS; | |
4338 | ||
1fc4ab23 JM |
4339 | wpa_printf(MSG_DEBUG, " * vht_enabled=%d", freq->vht_enabled); |
4340 | wpa_printf(MSG_DEBUG, " * ht_enabled=%d", freq->ht_enabled); | |
4341 | ||
89b800d7 | 4342 | if (freq->vht_enabled) { |
a862e4a3 JM |
4343 | enum nl80211_chan_width cw; |
4344 | ||
1fc4ab23 | 4345 | wpa_printf(MSG_DEBUG, " * bandwidth=%d", freq->bandwidth); |
89b800d7 JB |
4346 | switch (freq->bandwidth) { |
4347 | case 20: | |
a862e4a3 | 4348 | cw = NL80211_CHAN_WIDTH_20; |
89b800d7 JB |
4349 | break; |
4350 | case 40: | |
a862e4a3 | 4351 | cw = NL80211_CHAN_WIDTH_40; |
89b800d7 JB |
4352 | break; |
4353 | case 80: | |
4354 | if (freq->center_freq2) | |
a862e4a3 | 4355 | cw = NL80211_CHAN_WIDTH_80P80; |
89b800d7 | 4356 | else |
a862e4a3 | 4357 | cw = NL80211_CHAN_WIDTH_80; |
89b800d7 JB |
4358 | break; |
4359 | case 160: | |
a862e4a3 | 4360 | cw = NL80211_CHAN_WIDTH_160; |
89b800d7 JB |
4361 | break; |
4362 | default: | |
1c4ffa87 | 4363 | return -EINVAL; |
89b800d7 | 4364 | } |
a862e4a3 | 4365 | |
1fc4ab23 JM |
4366 | wpa_printf(MSG_DEBUG, " * channel_width=%d", cw); |
4367 | wpa_printf(MSG_DEBUG, " * center_freq1=%d", | |
4368 | freq->center_freq1); | |
4369 | wpa_printf(MSG_DEBUG, " * center_freq2=%d", | |
4370 | freq->center_freq2); | |
a862e4a3 JM |
4371 | if (nla_put_u32(msg, NL80211_ATTR_CHANNEL_WIDTH, cw) || |
4372 | nla_put_u32(msg, NL80211_ATTR_CENTER_FREQ1, | |
4373 | freq->center_freq1) || | |
4374 | (freq->center_freq2 && | |
4375 | nla_put_u32(msg, NL80211_ATTR_CENTER_FREQ2, | |
4376 | freq->center_freq2))) | |
4377 | return -ENOBUFS; | |
89b800d7 | 4378 | } else if (freq->ht_enabled) { |
a862e4a3 JM |
4379 | enum nl80211_channel_type ct; |
4380 | ||
1fc4ab23 JM |
4381 | wpa_printf(MSG_DEBUG, " * sec_channel_offset=%d", |
4382 | freq->sec_channel_offset); | |
89b800d7 | 4383 | switch (freq->sec_channel_offset) { |
f019981a | 4384 | case -1: |
a862e4a3 | 4385 | ct = NL80211_CHAN_HT40MINUS; |
f019981a JM |
4386 | break; |
4387 | case 1: | |
a862e4a3 | 4388 | ct = NL80211_CHAN_HT40PLUS; |
f019981a JM |
4389 | break; |
4390 | default: | |
a862e4a3 | 4391 | ct = NL80211_CHAN_HT20; |
f019981a JM |
4392 | break; |
4393 | } | |
a862e4a3 | 4394 | |
1fc4ab23 | 4395 | wpa_printf(MSG_DEBUG, " * channel_type=%d", ct); |
a862e4a3 JM |
4396 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE, ct)) |
4397 | return -ENOBUFS; | |
3388e7b9 MH |
4398 | } else { |
4399 | wpa_printf(MSG_DEBUG, " * channel_type=%d", | |
4400 | NL80211_CHAN_NO_HT); | |
4401 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE, | |
4402 | NL80211_CHAN_NO_HT)) | |
4403 | return -ENOBUFS; | |
f019981a | 4404 | } |
1c4ffa87 | 4405 | return 0; |
1c4ffa87 AO |
4406 | } |
4407 | ||
4408 | ||
e87ef751 PX |
4409 | static int nl80211_set_channel(struct i802_bss *bss, |
4410 | struct hostapd_freq_params *freq, int set_chan) | |
1c4ffa87 AO |
4411 | { |
4412 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
4413 | struct nl_msg *msg; | |
4414 | int ret; | |
4415 | ||
4416 | wpa_printf(MSG_DEBUG, | |
4417 | "nl80211: Set freq %d (ht_enabled=%d, vht_enabled=%d, bandwidth=%d MHz, cf1=%d MHz, cf2=%d MHz)", | |
4418 | freq->freq, freq->ht_enabled, freq->vht_enabled, | |
4419 | freq->bandwidth, freq->center_freq1, freq->center_freq2); | |
1c4ffa87 | 4420 | |
9725b784 JM |
4421 | msg = nl80211_drv_msg(drv, 0, set_chan ? NL80211_CMD_SET_CHANNEL : |
4422 | NL80211_CMD_SET_WIPHY); | |
4423 | if (!msg || nl80211_put_freq_params(msg, freq) < 0) { | |
a862e4a3 JM |
4424 | nlmsg_free(msg); |
4425 | return -1; | |
4426 | } | |
1581b38b | 4427 | |
d2440ba0 | 4428 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
e4fb2167 | 4429 | if (ret == 0) { |
89b800d7 | 4430 | bss->freq = freq->freq; |
1581b38b | 4431 | return 0; |
e4fb2167 | 4432 | } |
f019981a | 4433 | wpa_printf(MSG_DEBUG, "nl80211: Failed to set channel (freq=%d): " |
89b800d7 | 4434 | "%d (%s)", freq->freq, ret, strerror(-ret)); |
1581b38b JM |
4435 | return -1; |
4436 | } | |
4437 | ||
0f4e8b4f | 4438 | |
95ab6063 AN |
4439 | static u32 sta_flags_nl80211(int flags) |
4440 | { | |
4441 | u32 f = 0; | |
4442 | ||
4443 | if (flags & WPA_STA_AUTHORIZED) | |
4444 | f |= BIT(NL80211_STA_FLAG_AUTHORIZED); | |
4445 | if (flags & WPA_STA_WMM) | |
4446 | f |= BIT(NL80211_STA_FLAG_WME); | |
4447 | if (flags & WPA_STA_SHORT_PREAMBLE) | |
4448 | f |= BIT(NL80211_STA_FLAG_SHORT_PREAMBLE); | |
4449 | if (flags & WPA_STA_MFP) | |
4450 | f |= BIT(NL80211_STA_FLAG_MFP); | |
45b722f1 AN |
4451 | if (flags & WPA_STA_TDLS_PEER) |
4452 | f |= BIT(NL80211_STA_FLAG_TDLS_PEER); | |
7a228b5c BC |
4453 | if (flags & WPA_STA_AUTHENTICATED) |
4454 | f |= BIT(NL80211_STA_FLAG_AUTHENTICATED); | |
dc55b6b6 AB |
4455 | if (flags & WPA_STA_ASSOCIATED) |
4456 | f |= BIT(NL80211_STA_FLAG_ASSOCIATED); | |
95ab6063 AN |
4457 | |
4458 | return f; | |
4459 | } | |
4460 | ||
4461 | ||
7c7e7877 BC |
4462 | #ifdef CONFIG_MESH |
4463 | static u32 sta_plink_state_nl80211(enum mesh_plink_state state) | |
4464 | { | |
4465 | switch (state) { | |
d02e5498 | 4466 | case PLINK_IDLE: |
7c7e7877 | 4467 | return NL80211_PLINK_LISTEN; |
d02e5498 | 4468 | case PLINK_OPN_SNT: |
7c7e7877 | 4469 | return NL80211_PLINK_OPN_SNT; |
d02e5498 | 4470 | case PLINK_OPN_RCVD: |
7c7e7877 BC |
4471 | return NL80211_PLINK_OPN_RCVD; |
4472 | case PLINK_CNF_RCVD: | |
4473 | return NL80211_PLINK_CNF_RCVD; | |
4474 | case PLINK_ESTAB: | |
4475 | return NL80211_PLINK_ESTAB; | |
4476 | case PLINK_HOLDING: | |
4477 | return NL80211_PLINK_HOLDING; | |
4478 | case PLINK_BLOCKED: | |
4479 | return NL80211_PLINK_BLOCKED; | |
4480 | default: | |
4481 | wpa_printf(MSG_ERROR, "nl80211: Invalid mesh plink state %d", | |
4482 | state); | |
4483 | } | |
4484 | return -1; | |
4485 | } | |
4486 | #endif /* CONFIG_MESH */ | |
4487 | ||
4488 | ||
62847751 | 4489 | static int wpa_driver_nl80211_sta_add(void *priv, |
0f4e8b4f JM |
4490 | struct hostapd_sta_add_params *params) |
4491 | { | |
a2e40bb6 FF |
4492 | struct i802_bss *bss = priv; |
4493 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
8970bae8 | 4494 | struct nl_msg *msg; |
95ab6063 | 4495 | struct nl80211_sta_flag_update upd; |
0f4e8b4f JM |
4496 | int ret = -ENOBUFS; |
4497 | ||
45b722f1 AN |
4498 | if ((params->flags & WPA_STA_TDLS_PEER) && |
4499 | !(drv->capa.flags & WPA_DRIVER_FLAGS_TDLS_SUPPORT)) | |
4500 | return -EOPNOTSUPP; | |
4501 | ||
e4dea253 JM |
4502 | wpa_printf(MSG_DEBUG, "nl80211: %s STA " MACSTR, |
4503 | params->set ? "Set" : "Add", MAC2STR(params->addr)); | |
13f83980 JM |
4504 | msg = nl80211_bss_msg(bss, 0, params->set ? NL80211_CMD_SET_STATION : |
4505 | NL80211_CMD_NEW_STATION); | |
4506 | if (!msg || nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, params->addr)) | |
a862e4a3 | 4507 | goto fail; |
5551bc9c | 4508 | |
dc55b6b6 AB |
4509 | /* |
4510 | * Set the below properties only in one of the following cases: | |
4511 | * 1. New station is added, already associated. | |
4512 | * 2. Set WPA_STA_TDLS_PEER station. | |
4513 | * 3. Set an already added unassociated station, if driver supports | |
4514 | * full AP client state. (Set these properties after station became | |
4515 | * associated will be rejected by the driver). | |
4516 | */ | |
4517 | if (!params->set || (params->flags & WPA_STA_TDLS_PEER) || | |
4518 | (params->set && FULL_AP_CLIENT_STATE_SUPP(drv->capa.flags) && | |
4519 | (params->flags & WPA_STA_ASSOCIATED))) { | |
5551bc9c BC |
4520 | wpa_hexdump(MSG_DEBUG, " * supported rates", |
4521 | params->supp_rates, params->supp_rates_len); | |
a862e4a3 JM |
4522 | wpa_printf(MSG_DEBUG, " * capability=0x%x", |
4523 | params->capability); | |
4524 | if (nla_put(msg, NL80211_ATTR_STA_SUPPORTED_RATES, | |
4525 | params->supp_rates_len, params->supp_rates) || | |
4526 | nla_put_u16(msg, NL80211_ATTR_STA_CAPABILITY, | |
4527 | params->capability)) | |
4528 | goto fail; | |
e503861f JM |
4529 | |
4530 | if (params->ht_capabilities) { | |
4531 | wpa_hexdump(MSG_DEBUG, " * ht_capabilities", | |
4532 | (u8 *) params->ht_capabilities, | |
4533 | sizeof(*params->ht_capabilities)); | |
a862e4a3 JM |
4534 | if (nla_put(msg, NL80211_ATTR_HT_CAPABILITY, |
4535 | sizeof(*params->ht_capabilities), | |
4536 | params->ht_capabilities)) | |
4537 | goto fail; | |
e503861f JM |
4538 | } |
4539 | ||
4540 | if (params->vht_capabilities) { | |
4541 | wpa_hexdump(MSG_DEBUG, " * vht_capabilities", | |
4542 | (u8 *) params->vht_capabilities, | |
4543 | sizeof(*params->vht_capabilities)); | |
a862e4a3 JM |
4544 | if (nla_put(msg, NL80211_ATTR_VHT_CAPABILITY, |
4545 | sizeof(*params->vht_capabilities), | |
4546 | params->vht_capabilities)) | |
4547 | goto fail; | |
e503861f JM |
4548 | } |
4549 | ||
e503861f JM |
4550 | if (params->ext_capab) { |
4551 | wpa_hexdump(MSG_DEBUG, " * ext_capab", | |
4552 | params->ext_capab, params->ext_capab_len); | |
a862e4a3 JM |
4553 | if (nla_put(msg, NL80211_ATTR_STA_EXT_CAPABILITY, |
4554 | params->ext_capab_len, params->ext_capab)) | |
4555 | goto fail; | |
e503861f | 4556 | } |
ae33239c AB |
4557 | |
4558 | if (is_ap_interface(drv->nlmode) && | |
4559 | nla_put_u8(msg, NL80211_ATTR_STA_SUPPORT_P2P_PS, | |
4560 | params->support_p2p_ps ? | |
4561 | NL80211_P2P_PS_SUPPORTED : | |
4562 | NL80211_P2P_PS_UNSUPPORTED)) | |
4563 | goto fail; | |
5551bc9c | 4564 | } |
45b722f1 | 4565 | if (!params->set) { |
f11b72c3 JM |
4566 | if (params->aid) { |
4567 | wpa_printf(MSG_DEBUG, " * aid=%u", params->aid); | |
a862e4a3 JM |
4568 | if (nla_put_u16(msg, NL80211_ATTR_STA_AID, params->aid)) |
4569 | goto fail; | |
f11b72c3 JM |
4570 | } else { |
4571 | /* | |
4572 | * cfg80211 validates that AID is non-zero, so we have | |
4573 | * to make this a non-zero value for the TDLS case where | |
dc55b6b6 AB |
4574 | * a dummy STA entry is used for now and for a station |
4575 | * that is still not associated. | |
f11b72c3 | 4576 | */ |
dc55b6b6 AB |
4577 | wpa_printf(MSG_DEBUG, " * aid=1 (%s workaround)", |
4578 | (params->flags & WPA_STA_TDLS_PEER) ? | |
4579 | "TDLS" : "UNASSOC_STA"); | |
a862e4a3 JM |
4580 | if (nla_put_u16(msg, NL80211_ATTR_STA_AID, 1)) |
4581 | goto fail; | |
f11b72c3 | 4582 | } |
e4dea253 JM |
4583 | wpa_printf(MSG_DEBUG, " * listen_interval=%u", |
4584 | params->listen_interval); | |
a862e4a3 JM |
4585 | if (nla_put_u16(msg, NL80211_ATTR_STA_LISTEN_INTERVAL, |
4586 | params->listen_interval)) | |
4587 | goto fail; | |
e112764e JM |
4588 | } else if (params->aid && (params->flags & WPA_STA_TDLS_PEER)) { |
4589 | wpa_printf(MSG_DEBUG, " * peer_aid=%u", params->aid); | |
a862e4a3 JM |
4590 | if (nla_put_u16(msg, NL80211_ATTR_PEER_AID, params->aid)) |
4591 | goto fail; | |
dc55b6b6 AB |
4592 | } else if (FULL_AP_CLIENT_STATE_SUPP(drv->capa.flags) && |
4593 | (params->flags & WPA_STA_ASSOCIATED)) { | |
4594 | wpa_printf(MSG_DEBUG, " * aid=%u", params->aid); | |
4595 | wpa_printf(MSG_DEBUG, " * listen_interval=%u", | |
4596 | params->listen_interval); | |
4597 | if (nla_put_u16(msg, NL80211_ATTR_STA_AID, params->aid) || | |
4598 | nla_put_u16(msg, NL80211_ATTR_STA_LISTEN_INTERVAL, | |
4599 | params->listen_interval)) | |
4600 | goto fail; | |
45b722f1 | 4601 | } |
05a8d422 | 4602 | |
8a458116 MK |
4603 | if (params->vht_opmode_enabled) { |
4604 | wpa_printf(MSG_DEBUG, " * opmode=%u", params->vht_opmode); | |
a862e4a3 JM |
4605 | if (nla_put_u8(msg, NL80211_ATTR_OPMODE_NOTIF, |
4606 | params->vht_opmode)) | |
4607 | goto fail; | |
8a458116 MK |
4608 | } |
4609 | ||
efc64886 SD |
4610 | if (params->supp_channels) { |
4611 | wpa_hexdump(MSG_DEBUG, " * supported channels", | |
4612 | params->supp_channels, params->supp_channels_len); | |
a862e4a3 JM |
4613 | if (nla_put(msg, NL80211_ATTR_STA_SUPPORTED_CHANNELS, |
4614 | params->supp_channels_len, params->supp_channels)) | |
4615 | goto fail; | |
efc64886 SD |
4616 | } |
4617 | ||
4618 | if (params->supp_oper_classes) { | |
4619 | wpa_hexdump(MSG_DEBUG, " * supported operating classes", | |
4620 | params->supp_oper_classes, | |
4621 | params->supp_oper_classes_len); | |
a862e4a3 JM |
4622 | if (nla_put(msg, NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES, |
4623 | params->supp_oper_classes_len, | |
4624 | params->supp_oper_classes)) | |
4625 | goto fail; | |
efc64886 SD |
4626 | } |
4627 | ||
95ab6063 | 4628 | os_memset(&upd, 0, sizeof(upd)); |
7e31703e BC |
4629 | upd.set = sta_flags_nl80211(params->flags); |
4630 | upd.mask = upd.set | sta_flags_nl80211(params->flags_mask); | |
dc55b6b6 AB |
4631 | |
4632 | /* | |
4633 | * If the driver doesn't support full AP client state, ignore ASSOC/AUTH | |
4634 | * flags, as nl80211 driver moves a new station, by default, into | |
4635 | * associated state. | |
4636 | * | |
4637 | * On the other hand, if the driver supports that feature and the | |
4638 | * station is added in unauthenticated state, set the | |
4639 | * authenticated/associated bits in the mask to prevent moving this | |
4640 | * station to associated state before it is actually associated. | |
4641 | * | |
4642 | * This is irrelevant for mesh mode where the station is added to the | |
4643 | * driver as authenticated already, and ASSOCIATED isn't part of the | |
4644 | * nl80211 API. | |
4645 | */ | |
4646 | if (!is_mesh_interface(drv->nlmode)) { | |
4647 | if (!FULL_AP_CLIENT_STATE_SUPP(drv->capa.flags)) { | |
4648 | wpa_printf(MSG_DEBUG, | |
4649 | "nl80211: Ignore ASSOC/AUTH flags since driver doesn't support full AP client state"); | |
4650 | upd.mask &= ~(BIT(NL80211_STA_FLAG_ASSOCIATED) | | |
4651 | BIT(NL80211_STA_FLAG_AUTHENTICATED)); | |
4652 | } else if (!params->set && | |
4653 | !(params->flags & WPA_STA_TDLS_PEER)) { | |
4654 | if (!(params->flags & WPA_STA_AUTHENTICATED)) | |
4655 | upd.mask |= BIT(NL80211_STA_FLAG_AUTHENTICATED); | |
4656 | if (!(params->flags & WPA_STA_ASSOCIATED)) | |
4657 | upd.mask |= BIT(NL80211_STA_FLAG_ASSOCIATED); | |
4658 | } | |
e347cafe MH |
4659 | #ifdef CONFIG_MESH |
4660 | } else { | |
4661 | if (params->plink_state == PLINK_ESTAB && params->peer_aid) { | |
4662 | ret = nla_put_u16(msg, NL80211_ATTR_MESH_PEER_AID, | |
4663 | params->peer_aid); | |
4664 | if (ret) | |
4665 | goto fail; | |
4666 | } | |
4667 | #endif /* CONFIG_MESH */ | |
dc55b6b6 AB |
4668 | } |
4669 | ||
e4dea253 JM |
4670 | wpa_printf(MSG_DEBUG, " * flags set=0x%x mask=0x%x", |
4671 | upd.set, upd.mask); | |
a862e4a3 JM |
4672 | if (nla_put(msg, NL80211_ATTR_STA_FLAGS2, sizeof(upd), &upd)) |
4673 | goto fail; | |
95ab6063 | 4674 | |
7c7e7877 | 4675 | #ifdef CONFIG_MESH |
a862e4a3 JM |
4676 | if (params->plink_state && |
4677 | nla_put_u8(msg, NL80211_ATTR_STA_PLINK_STATE, | |
4678 | sta_plink_state_nl80211(params->plink_state))) | |
4679 | goto fail; | |
7c7e7877 BC |
4680 | #endif /* CONFIG_MESH */ |
4681 | ||
6d14b98f JM |
4682 | if ((!params->set || FULL_AP_CLIENT_STATE_SUPP(drv->capa.flags)) && |
4683 | (params->flags & WPA_STA_WMM)) { | |
8970bae8 JB |
4684 | struct nlattr *wme = nla_nest_start(msg, NL80211_ATTR_STA_WME); |
4685 | ||
e4dea253 | 4686 | wpa_printf(MSG_DEBUG, " * qosinfo=0x%x", params->qosinfo); |
a862e4a3 JM |
4687 | if (!wme || |
4688 | nla_put_u8(msg, NL80211_STA_WME_UAPSD_QUEUES, | |
4689 | params->qosinfo & WMM_QOSINFO_STA_AC_MASK) || | |
4690 | nla_put_u8(msg, NL80211_STA_WME_MAX_SP, | |
4691 | (params->qosinfo >> WMM_QOSINFO_STA_SP_SHIFT) & | |
4692 | WMM_QOSINFO_STA_SP_MASK)) | |
4693 | goto fail; | |
8970bae8 | 4694 | nla_nest_end(msg, wme); |
774bfa62 EP |
4695 | } |
4696 | ||
0f4e8b4f | 4697 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
5883168a | 4698 | msg = NULL; |
0f4e8b4f | 4699 | if (ret) |
45b722f1 AN |
4700 | wpa_printf(MSG_DEBUG, "nl80211: NL80211_CMD_%s_STATION " |
4701 | "result: %d (%s)", params->set ? "SET" : "NEW", ret, | |
4702 | strerror(-ret)); | |
0f4e8b4f JM |
4703 | if (ret == -EEXIST) |
4704 | ret = 0; | |
a862e4a3 | 4705 | fail: |
5883168a | 4706 | nlmsg_free(msg); |
0f4e8b4f JM |
4707 | return ret; |
4708 | } | |
4709 | ||
4710 | ||
97ed9a06 KP |
4711 | static void rtnl_neigh_delete_fdb_entry(struct i802_bss *bss, const u8 *addr) |
4712 | { | |
4713 | #ifdef CONFIG_LIBNL3_ROUTE | |
4714 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
4715 | struct rtnl_neigh *rn; | |
4716 | struct nl_addr *nl_addr; | |
4717 | int err; | |
4718 | ||
4719 | rn = rtnl_neigh_alloc(); | |
4720 | if (!rn) | |
4721 | return; | |
4722 | ||
4723 | rtnl_neigh_set_family(rn, AF_BRIDGE); | |
4724 | rtnl_neigh_set_ifindex(rn, bss->ifindex); | |
4725 | nl_addr = nl_addr_build(AF_BRIDGE, (void *) addr, ETH_ALEN); | |
4726 | if (!nl_addr) { | |
4727 | rtnl_neigh_put(rn); | |
4728 | return; | |
4729 | } | |
4730 | rtnl_neigh_set_lladdr(rn, nl_addr); | |
4731 | ||
4732 | err = rtnl_neigh_delete(drv->rtnl_sk, rn, 0); | |
4733 | if (err < 0) { | |
4734 | wpa_printf(MSG_DEBUG, "nl80211: bridge FDB entry delete for " | |
4735 | MACSTR " ifindex=%d failed: %s", MAC2STR(addr), | |
4736 | bss->ifindex, nl_geterror(err)); | |
4737 | } else { | |
4738 | wpa_printf(MSG_DEBUG, "nl80211: deleted bridge FDB entry for " | |
4739 | MACSTR, MAC2STR(addr)); | |
4740 | } | |
4741 | ||
4742 | nl_addr_put(nl_addr); | |
4743 | rtnl_neigh_put(rn); | |
4744 | #endif /* CONFIG_LIBNL3_ROUTE */ | |
4745 | } | |
4746 | ||
4747 | ||
59d7148a JM |
4748 | static int wpa_driver_nl80211_sta_remove(struct i802_bss *bss, const u8 *addr, |
4749 | int deauth, u16 reason_code) | |
0f4e8b4f | 4750 | { |
a2e40bb6 | 4751 | struct wpa_driver_nl80211_data *drv = bss->drv; |
0f4e8b4f JM |
4752 | struct nl_msg *msg; |
4753 | int ret; | |
4754 | ||
13f83980 | 4755 | if (!(msg = nl80211_bss_msg(bss, 0, NL80211_CMD_DEL_STATION)) || |
a862e4a3 JM |
4756 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) || |
4757 | (deauth == 0 && | |
4758 | nla_put_u8(msg, NL80211_ATTR_MGMT_SUBTYPE, | |
4759 | WLAN_FC_STYPE_DISASSOC)) || | |
4760 | (deauth == 1 && | |
4761 | nla_put_u8(msg, NL80211_ATTR_MGMT_SUBTYPE, | |
4762 | WLAN_FC_STYPE_DEAUTH)) || | |
4763 | (reason_code && | |
4764 | nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason_code))) { | |
4765 | nlmsg_free(msg); | |
4766 | return -ENOBUFS; | |
4767 | } | |
0f4e8b4f JM |
4768 | |
4769 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); | |
83e7bb0e JM |
4770 | wpa_printf(MSG_DEBUG, "nl80211: sta_remove -> DEL_STATION %s " MACSTR |
4771 | " --> %d (%s)", | |
4772 | bss->ifname, MAC2STR(addr), ret, strerror(-ret)); | |
97ed9a06 KP |
4773 | |
4774 | if (drv->rtnl_sk) | |
4775 | rtnl_neigh_delete_fdb_entry(bss, addr); | |
4776 | ||
0f4e8b4f JM |
4777 | if (ret == -ENOENT) |
4778 | return 0; | |
4779 | return ret; | |
0f4e8b4f JM |
4780 | } |
4781 | ||
1581b38b | 4782 | |
f3407c66 | 4783 | void nl80211_remove_iface(struct wpa_driver_nl80211_data *drv, int ifidx) |
0915d02c JM |
4784 | { |
4785 | struct nl_msg *msg; | |
de884303 | 4786 | struct wpa_driver_nl80211_data *drv2; |
0915d02c | 4787 | |
c6e8e8e4 JM |
4788 | wpa_printf(MSG_DEBUG, "nl80211: Remove interface ifindex=%d", ifidx); |
4789 | ||
2135f224 | 4790 | /* stop listening for EAPOL on this interface */ |
de884303 JM |
4791 | dl_list_for_each(drv2, &drv->global->interfaces, |
4792 | struct wpa_driver_nl80211_data, list) | |
732b1d20 MB |
4793 | { |
4794 | del_ifidx(drv2, ifidx, IFIDX_ANY); | |
4795 | /* Remove all bridges learned for this iface */ | |
4796 | del_ifidx(drv2, IFIDX_ANY, ifidx); | |
4797 | } | |
2135f224 | 4798 | |
95376e1a | 4799 | msg = nl80211_ifindex_msg(drv, ifidx, 0, NL80211_CMD_DEL_INTERFACE); |
0915d02c JM |
4800 | if (send_and_recv_msgs(drv, msg, NULL, NULL) == 0) |
4801 | return; | |
e748062b | 4802 | wpa_printf(MSG_ERROR, "Failed to remove interface (ifidx=%d)", ifidx); |
0915d02c JM |
4803 | } |
4804 | ||
4805 | ||
cc9a2575 | 4806 | const char * nl80211_iftype_str(enum nl80211_iftype mode) |
a1922f93 JM |
4807 | { |
4808 | switch (mode) { | |
4809 | case NL80211_IFTYPE_ADHOC: | |
4810 | return "ADHOC"; | |
4811 | case NL80211_IFTYPE_STATION: | |
4812 | return "STATION"; | |
4813 | case NL80211_IFTYPE_AP: | |
4814 | return "AP"; | |
1045ec36 JM |
4815 | case NL80211_IFTYPE_AP_VLAN: |
4816 | return "AP_VLAN"; | |
4817 | case NL80211_IFTYPE_WDS: | |
4818 | return "WDS"; | |
a1922f93 JM |
4819 | case NL80211_IFTYPE_MONITOR: |
4820 | return "MONITOR"; | |
1045ec36 JM |
4821 | case NL80211_IFTYPE_MESH_POINT: |
4822 | return "MESH_POINT"; | |
a1922f93 JM |
4823 | case NL80211_IFTYPE_P2P_CLIENT: |
4824 | return "P2P_CLIENT"; | |
4825 | case NL80211_IFTYPE_P2P_GO: | |
4826 | return "P2P_GO"; | |
7aad838c NS |
4827 | case NL80211_IFTYPE_P2P_DEVICE: |
4828 | return "P2P_DEVICE"; | |
a1922f93 JM |
4829 | default: |
4830 | return "unknown"; | |
4831 | } | |
4832 | } | |
4833 | ||
4834 | ||
a35187e7 KH |
4835 | static int nl80211_create_iface_once(struct wpa_driver_nl80211_data *drv, |
4836 | const char *ifname, | |
4837 | enum nl80211_iftype iftype, | |
d6dcfcda DS |
4838 | const u8 *addr, int wds, |
4839 | int (*handler)(struct nl_msg *, void *), | |
4840 | void *arg) | |
0915d02c | 4841 | { |
8970bae8 | 4842 | struct nl_msg *msg; |
0915d02c JM |
4843 | int ifidx; |
4844 | int ret = -ENOBUFS; | |
4845 | ||
a1922f93 JM |
4846 | wpa_printf(MSG_DEBUG, "nl80211: Create interface iftype %d (%s)", |
4847 | iftype, nl80211_iftype_str(iftype)); | |
4848 | ||
56f77852 JM |
4849 | msg = nl80211_cmd_msg(drv->first_bss, 0, NL80211_CMD_NEW_INTERFACE); |
4850 | if (!msg || | |
a862e4a3 JM |
4851 | nla_put_string(msg, NL80211_ATTR_IFNAME, ifname) || |
4852 | nla_put_u32(msg, NL80211_ATTR_IFTYPE, iftype)) | |
4853 | goto fail; | |
0915d02c JM |
4854 | |
4855 | if (iftype == NL80211_IFTYPE_MONITOR) { | |
8970bae8 | 4856 | struct nlattr *flags; |
0915d02c | 4857 | |
8970bae8 | 4858 | flags = nla_nest_start(msg, NL80211_ATTR_MNTR_FLAGS); |
a862e4a3 JM |
4859 | if (!flags || |
4860 | nla_put_flag(msg, NL80211_MNTR_FLAG_COOK_FRAMES)) | |
4861 | goto fail; | |
0915d02c | 4862 | |
8970bae8 | 4863 | nla_nest_end(msg, flags); |
fbbfcbac | 4864 | } else if (wds) { |
a862e4a3 JM |
4865 | if (nla_put_u8(msg, NL80211_ATTR_4ADDR, wds)) |
4866 | goto fail; | |
0915d02c JM |
4867 | } |
4868 | ||
52f5877a IP |
4869 | /* |
4870 | * Tell cfg80211 that the interface belongs to the socket that created | |
4871 | * it, and the interface should be deleted when the socket is closed. | |
4872 | */ | |
a862e4a3 JM |
4873 | if (nla_put_flag(msg, NL80211_ATTR_IFACE_SOCKET_OWNER)) |
4874 | goto fail; | |
52f5877a | 4875 | |
d6dcfcda | 4876 | ret = send_and_recv_msgs(drv, msg, handler, arg); |
5883168a | 4877 | msg = NULL; |
0915d02c | 4878 | if (ret) { |
a862e4a3 | 4879 | fail: |
5883168a | 4880 | nlmsg_free(msg); |
a35187e7 KH |
4881 | wpa_printf(MSG_ERROR, "Failed to create interface %s: %d (%s)", |
4882 | ifname, ret, strerror(-ret)); | |
0915d02c JM |
4883 | return ret; |
4884 | } | |
4885 | ||
f632e483 | 4886 | if (iftype == NL80211_IFTYPE_P2P_DEVICE) |
6bae92e0 | 4887 | return 0; |
6bae92e0 | 4888 | |
0915d02c | 4889 | ifidx = if_nametoindex(ifname); |
c6e8e8e4 JM |
4890 | wpa_printf(MSG_DEBUG, "nl80211: New interface %s created: ifindex=%d", |
4891 | ifname, ifidx); | |
0915d02c JM |
4892 | |
4893 | if (ifidx <= 0) | |
4894 | return -1; | |
4895 | ||
147848ec JM |
4896 | /* |
4897 | * Some virtual interfaces need to process EAPOL packets and events on | |
4898 | * the parent interface. This is used mainly with hostapd. | |
4899 | */ | |
4900 | if (drv->hostapd || | |
4901 | iftype == NL80211_IFTYPE_AP_VLAN || | |
4902 | iftype == NL80211_IFTYPE_WDS || | |
4903 | iftype == NL80211_IFTYPE_MONITOR) { | |
4904 | /* start listening for EAPOL on this interface */ | |
732b1d20 | 4905 | add_ifidx(drv, ifidx, IFIDX_ANY); |
147848ec | 4906 | } |
2135f224 | 4907 | |
7bfc47c3 | 4908 | if (addr && iftype != NL80211_IFTYPE_MONITOR && |
c81eff1a | 4909 | linux_set_ifhwaddr(drv->global->ioctl_sock, ifname, addr)) { |
41d931ee JM |
4910 | nl80211_remove_iface(drv, ifidx); |
4911 | return -1; | |
2135f224 | 4912 | } |
2135f224 | 4913 | |
0915d02c JM |
4914 | return ifidx; |
4915 | } | |
22a7c9d7 JM |
4916 | |
4917 | ||
f3407c66 JM |
4918 | int nl80211_create_iface(struct wpa_driver_nl80211_data *drv, |
4919 | const char *ifname, enum nl80211_iftype iftype, | |
4920 | const u8 *addr, int wds, | |
4921 | int (*handler)(struct nl_msg *, void *), | |
4922 | void *arg, int use_existing) | |
a35187e7 KH |
4923 | { |
4924 | int ret; | |
4925 | ||
d6dcfcda DS |
4926 | ret = nl80211_create_iface_once(drv, ifname, iftype, addr, wds, handler, |
4927 | arg); | |
a35187e7 | 4928 | |
ffbf1eaa | 4929 | /* if error occurred and interface exists already */ |
a35187e7 | 4930 | if (ret == -ENFILE && if_nametoindex(ifname)) { |
2aec4f3c JM |
4931 | if (use_existing) { |
4932 | wpa_printf(MSG_DEBUG, "nl80211: Continue using existing interface %s", | |
4933 | ifname); | |
6997f8ba JM |
4934 | if (addr && iftype != NL80211_IFTYPE_MONITOR && |
4935 | linux_set_ifhwaddr(drv->global->ioctl_sock, ifname, | |
4936 | addr) < 0 && | |
4937 | (linux_set_iface_flags(drv->global->ioctl_sock, | |
4938 | ifname, 0) < 0 || | |
4939 | linux_set_ifhwaddr(drv->global->ioctl_sock, ifname, | |
4940 | addr) < 0 || | |
4941 | linux_set_iface_flags(drv->global->ioctl_sock, | |
4942 | ifname, 1) < 0)) | |
4943 | return -1; | |
2aec4f3c JM |
4944 | return -ENFILE; |
4945 | } | |
a35187e7 KH |
4946 | wpa_printf(MSG_INFO, "Try to remove and re-create %s", ifname); |
4947 | ||
4948 | /* Try to remove the interface that was already there. */ | |
4949 | nl80211_remove_iface(drv, if_nametoindex(ifname)); | |
4950 | ||
4951 | /* Try to create the interface again */ | |
fbbfcbac | 4952 | ret = nl80211_create_iface_once(drv, ifname, iftype, addr, |
d6dcfcda | 4953 | wds, handler, arg); |
a35187e7 KH |
4954 | } |
4955 | ||
3e208481 JM |
4956 | if (ret >= 0 && is_p2p_net_interface(iftype)) { |
4957 | wpa_printf(MSG_DEBUG, | |
4958 | "nl80211: Interface %s created for P2P - disable 11b rates", | |
4959 | ifname); | |
4e5cb1a3 | 4960 | nl80211_disable_11b_rates(drv, ret, 1); |
3e208481 | 4961 | } |
4e5cb1a3 | 4962 | |
a35187e7 KH |
4963 | return ret; |
4964 | } | |
0915d02c | 4965 | |
2135f224 | 4966 | |
3fd1cefb JB |
4967 | static int nl80211_setup_ap(struct i802_bss *bss) |
4968 | { | |
4969 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
4970 | ||
748c0ac0 JM |
4971 | wpa_printf(MSG_DEBUG, "nl80211: Setup AP(%s) - device_ap_sme=%d use_monitor=%d", |
4972 | bss->ifname, drv->device_ap_sme, drv->use_monitor); | |
36488c05 | 4973 | |
a11241fa JB |
4974 | /* |
4975 | * Disable Probe Request reporting unless we need it in this way for | |
4976 | * devices that include the AP SME, in the other case (unless using | |
4977 | * monitor iface) we'll get it through the nl_mgmt socket instead. | |
4978 | */ | |
4979 | if (!drv->device_ap_sme) | |
4980 | wpa_driver_nl80211_probe_req_report(bss, 0); | |
4981 | ||
4982 | if (!drv->device_ap_sme && !drv->use_monitor) | |
4983 | if (nl80211_mgmt_subscribe_ap(bss)) | |
4984 | return -1; | |
4985 | ||
a6cc0602 JM |
4986 | if (drv->device_ap_sme && !drv->use_monitor) |
4987 | if (nl80211_mgmt_subscribe_ap_dev_sme(bss)) | |
f4830bed RM |
4988 | wpa_printf(MSG_DEBUG, |
4989 | "nl80211: Failed to subscribe for mgmt frames from SME driver - trying to run without it"); | |
a6cc0602 | 4990 | |
a11241fa | 4991 | if (!drv->device_ap_sme && drv->use_monitor && |
ea19b39f RM |
4992 | nl80211_create_monitor_interface(drv) && |
4993 | !drv->device_ap_sme) | |
3fd1cefb JB |
4994 | return -1; |
4995 | ||
4996 | if (drv->device_ap_sme && | |
4997 | wpa_driver_nl80211_probe_req_report(bss, 1) < 0) { | |
4998 | wpa_printf(MSG_DEBUG, "nl80211: Failed to enable " | |
4999 | "Probe Request frame reporting in AP mode"); | |
5000 | /* Try to survive without this */ | |
5001 | } | |
5002 | ||
5003 | return 0; | |
5004 | } | |
5005 | ||
5006 | ||
5007 | static void nl80211_teardown_ap(struct i802_bss *bss) | |
5008 | { | |
5009 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
5010 | ||
748c0ac0 JM |
5011 | wpa_printf(MSG_DEBUG, "nl80211: Teardown AP(%s) - device_ap_sme=%d use_monitor=%d", |
5012 | bss->ifname, drv->device_ap_sme, drv->use_monitor); | |
a6cc0602 | 5013 | if (drv->device_ap_sme) { |
3fd1cefb | 5014 | wpa_driver_nl80211_probe_req_report(bss, 0); |
a6cc0602 JM |
5015 | if (!drv->use_monitor) |
5016 | nl80211_mgmt_unsubscribe(bss, "AP teardown (dev SME)"); | |
5017 | } else if (drv->use_monitor) | |
3fd1cefb | 5018 | nl80211_remove_monitor_interface(drv); |
a11241fa | 5019 | else |
36488c05 | 5020 | nl80211_mgmt_unsubscribe(bss, "AP teardown"); |
a11241fa | 5021 | |
a70cd0db | 5022 | nl80211_put_wiphy_data_ap(bss); |
3fd1cefb JB |
5023 | bss->beacon_set = 0; |
5024 | } | |
5025 | ||
5026 | ||
f10bfc9a JM |
5027 | static int nl80211_send_eapol_data(struct i802_bss *bss, |
5028 | const u8 *addr, const u8 *data, | |
d12dab4c | 5029 | size_t data_len) |
f10bfc9a | 5030 | { |
d12dab4c JB |
5031 | struct sockaddr_ll ll; |
5032 | int ret; | |
5033 | ||
5034 | if (bss->drv->eapol_tx_sock < 0) { | |
5035 | wpa_printf(MSG_DEBUG, "nl80211: No socket to send EAPOL"); | |
f10bfc9a JM |
5036 | return -1; |
5037 | } | |
5038 | ||
d12dab4c JB |
5039 | os_memset(&ll, 0, sizeof(ll)); |
5040 | ll.sll_family = AF_PACKET; | |
5041 | ll.sll_ifindex = bss->ifindex; | |
5042 | ll.sll_protocol = htons(ETH_P_PAE); | |
5043 | ll.sll_halen = ETH_ALEN; | |
5044 | os_memcpy(ll.sll_addr, addr, ETH_ALEN); | |
5045 | ret = sendto(bss->drv->eapol_tx_sock, data, data_len, 0, | |
5046 | (struct sockaddr *) &ll, sizeof(ll)); | |
5047 | if (ret < 0) | |
5048 | wpa_printf(MSG_ERROR, "nl80211: EAPOL TX: %s", | |
5049 | strerror(errno)); | |
5050 | ||
5051 | return ret; | |
f10bfc9a | 5052 | } |
5fb1a232 | 5053 | |
f10bfc9a | 5054 | |
db149ac9 JM |
5055 | static const u8 rfc1042_header[6] = { 0xaa, 0xaa, 0x03, 0x00, 0x00, 0x00 }; |
5056 | ||
5057 | static int wpa_driver_nl80211_hapd_send_eapol( | |
5058 | void *priv, const u8 *addr, const u8 *data, | |
4378fc14 | 5059 | size_t data_len, int encrypt, const u8 *own_addr, u32 flags) |
db149ac9 | 5060 | { |
a2e40bb6 FF |
5061 | struct i802_bss *bss = priv; |
5062 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
db149ac9 JM |
5063 | struct ieee80211_hdr *hdr; |
5064 | size_t len; | |
5065 | u8 *pos; | |
5066 | int res; | |
4378fc14 | 5067 | int qos = flags & WPA_STA_WMM; |
db149ac9 | 5068 | |
a11241fa | 5069 | if (drv->device_ap_sme || !drv->use_monitor) |
d12dab4c | 5070 | return nl80211_send_eapol_data(bss, addr, data, data_len); |
f10bfc9a | 5071 | |
db149ac9 JM |
5072 | len = sizeof(*hdr) + (qos ? 2 : 0) + sizeof(rfc1042_header) + 2 + |
5073 | data_len; | |
5074 | hdr = os_zalloc(len); | |
5075 | if (hdr == NULL) { | |
7ac3616d JM |
5076 | wpa_printf(MSG_INFO, "nl80211: Failed to allocate EAPOL buffer(len=%lu)", |
5077 | (unsigned long) len); | |
db149ac9 JM |
5078 | return -1; |
5079 | } | |
5080 | ||
5081 | hdr->frame_control = | |
5082 | IEEE80211_FC(WLAN_FC_TYPE_DATA, WLAN_FC_STYPE_DATA); | |
5083 | hdr->frame_control |= host_to_le16(WLAN_FC_FROMDS); | |
5084 | if (encrypt) | |
5085 | hdr->frame_control |= host_to_le16(WLAN_FC_ISWEP); | |
db149ac9 JM |
5086 | if (qos) { |
5087 | hdr->frame_control |= | |
5088 | host_to_le16(WLAN_FC_STYPE_QOS_DATA << 4); | |
5089 | } | |
db149ac9 JM |
5090 | |
5091 | memcpy(hdr->IEEE80211_DA_FROMDS, addr, ETH_ALEN); | |
5092 | memcpy(hdr->IEEE80211_BSSID_FROMDS, own_addr, ETH_ALEN); | |
5093 | memcpy(hdr->IEEE80211_SA_FROMDS, own_addr, ETH_ALEN); | |
5094 | pos = (u8 *) (hdr + 1); | |
5095 | ||
db149ac9 | 5096 | if (qos) { |
92d521d8 FF |
5097 | /* Set highest priority in QoS header */ |
5098 | pos[0] = 7; | |
db149ac9 JM |
5099 | pos[1] = 0; |
5100 | pos += 2; | |
5101 | } | |
db149ac9 JM |
5102 | |
5103 | memcpy(pos, rfc1042_header, sizeof(rfc1042_header)); | |
5104 | pos += sizeof(rfc1042_header); | |
5105 | WPA_PUT_BE16(pos, ETH_P_PAE); | |
5106 | pos += 2; | |
5107 | memcpy(pos, data, data_len); | |
5108 | ||
55231068 | 5109 | res = wpa_driver_nl80211_send_frame(bss, (u8 *) hdr, len, encrypt, 0, |
2d3943ce | 5110 | 0, 0, 0, 0, NULL, 0); |
db149ac9 JM |
5111 | if (res < 0) { |
5112 | wpa_printf(MSG_ERROR, "i802_send_eapol - packet len: %lu - " | |
5113 | "failed: %d (%s)", | |
5114 | (unsigned long) len, errno, strerror(errno)); | |
5115 | } | |
7bf12757 | 5116 | os_free(hdr); |
db149ac9 JM |
5117 | |
5118 | return res; | |
5119 | } | |
5120 | ||
a8d6ffa4 | 5121 | |
3234cba4 | 5122 | static int wpa_driver_nl80211_sta_set_flags(void *priv, const u8 *addr, |
f97e3ce4 JM |
5123 | unsigned int total_flags, |
5124 | unsigned int flags_or, | |
5125 | unsigned int flags_and) | |
a8d6ffa4 | 5126 | { |
a2e40bb6 | 5127 | struct i802_bss *bss = priv; |
8970bae8 JB |
5128 | struct nl_msg *msg; |
5129 | struct nlattr *flags; | |
7e76ee9c | 5130 | struct nl80211_sta_flag_update upd; |
a8d6ffa4 | 5131 | |
0cd9846c JM |
5132 | wpa_printf(MSG_DEBUG, "nl80211: Set STA flags - ifname=%s addr=" MACSTR |
5133 | " total_flags=0x%x flags_or=0x%x flags_and=0x%x authorized=%d", | |
5134 | bss->ifname, MAC2STR(addr), total_flags, flags_or, flags_and, | |
5135 | !!(total_flags & WPA_STA_AUTHORIZED)); | |
5136 | ||
13f83980 | 5137 | if (!(msg = nl80211_bss_msg(bss, 0, NL80211_CMD_SET_STATION)) || |
a862e4a3 JM |
5138 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) |
5139 | goto fail; | |
a8d6ffa4 | 5140 | |
7e76ee9c JM |
5141 | /* |
5142 | * Backwards compatibility version using NL80211_ATTR_STA_FLAGS. This | |
5143 | * can be removed eventually. | |
5144 | */ | |
8970bae8 | 5145 | flags = nla_nest_start(msg, NL80211_ATTR_STA_FLAGS); |
a862e4a3 JM |
5146 | if (!flags || |
5147 | ((total_flags & WPA_STA_AUTHORIZED) && | |
5148 | nla_put_flag(msg, NL80211_STA_FLAG_AUTHORIZED)) || | |
5149 | ((total_flags & WPA_STA_WMM) && | |
5150 | nla_put_flag(msg, NL80211_STA_FLAG_WME)) || | |
5151 | ((total_flags & WPA_STA_SHORT_PREAMBLE) && | |
5152 | nla_put_flag(msg, NL80211_STA_FLAG_SHORT_PREAMBLE)) || | |
5153 | ((total_flags & WPA_STA_MFP) && | |
5154 | nla_put_flag(msg, NL80211_STA_FLAG_MFP)) || | |
5155 | ((total_flags & WPA_STA_TDLS_PEER) && | |
5156 | nla_put_flag(msg, NL80211_STA_FLAG_TDLS_PEER))) | |
5157 | goto fail; | |
45b722f1 | 5158 | |
8970bae8 | 5159 | nla_nest_end(msg, flags); |
a8d6ffa4 | 5160 | |
7e76ee9c JM |
5161 | os_memset(&upd, 0, sizeof(upd)); |
5162 | upd.mask = sta_flags_nl80211(flags_or | ~flags_and); | |
5163 | upd.set = sta_flags_nl80211(flags_or); | |
a862e4a3 JM |
5164 | if (nla_put(msg, NL80211_ATTR_STA_FLAGS2, sizeof(upd), &upd)) |
5165 | goto fail; | |
7e76ee9c | 5166 | |
13f83980 | 5167 | return send_and_recv_msgs(bss->drv, msg, NULL, NULL); |
a862e4a3 | 5168 | fail: |
5883168a | 5169 | nlmsg_free(msg); |
a8d6ffa4 JM |
5170 | return -ENOBUFS; |
5171 | } | |
5172 | ||
0915d02c | 5173 | |
1581b38b JM |
5174 | static int wpa_driver_nl80211_ap(struct wpa_driver_nl80211_data *drv, |
5175 | struct wpa_driver_associate_params *params) | |
5176 | { | |
708bc8e0 | 5177 | enum nl80211_iftype nlmode, old_mode; |
b1f625e0 EP |
5178 | |
5179 | if (params->p2p) { | |
046b26a2 JM |
5180 | wpa_printf(MSG_DEBUG, "nl80211: Setup AP operations for P2P " |
5181 | "group (GO)"); | |
b1f625e0 EP |
5182 | nlmode = NL80211_IFTYPE_P2P_GO; |
5183 | } else | |
5184 | nlmode = NL80211_IFTYPE_AP; | |
5185 | ||
708bc8e0 | 5186 | old_mode = drv->nlmode; |
834ee56f | 5187 | if (wpa_driver_nl80211_set_mode(drv->first_bss, nlmode)) { |
708bc8e0 JM |
5188 | nl80211_remove_monitor_interface(drv); |
5189 | return -1; | |
5190 | } | |
5191 | ||
6e9023ea JM |
5192 | if (params->freq.freq && |
5193 | nl80211_set_channel(drv->first_bss, ¶ms->freq, 0)) { | |
708bc8e0 | 5194 | if (old_mode != nlmode) |
834ee56f | 5195 | wpa_driver_nl80211_set_mode(drv->first_bss, old_mode); |
460456f8 | 5196 | nl80211_remove_monitor_interface(drv); |
1581b38b | 5197 | return -1; |
0915d02c | 5198 | } |
1581b38b | 5199 | |
1581b38b JM |
5200 | return 0; |
5201 | } | |
1581b38b JM |
5202 | |
5203 | ||
666e508c JM |
5204 | static int nl80211_leave_ibss(struct wpa_driver_nl80211_data *drv, |
5205 | int reset_mode) | |
5cc4d64b JM |
5206 | { |
5207 | struct nl_msg *msg; | |
9725b784 | 5208 | int ret; |
a862e4a3 | 5209 | |
9725b784 | 5210 | msg = nl80211_drv_msg(drv, 0, NL80211_CMD_LEAVE_IBSS); |
5cc4d64b | 5211 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
5cc4d64b JM |
5212 | if (ret) { |
5213 | wpa_printf(MSG_DEBUG, "nl80211: Leave IBSS failed: ret=%d " | |
5214 | "(%s)", ret, strerror(-ret)); | |
9725b784 JM |
5215 | } else { |
5216 | wpa_printf(MSG_DEBUG, | |
5217 | "nl80211: Leave IBSS request sent successfully"); | |
5cc4d64b JM |
5218 | } |
5219 | ||
666e508c JM |
5220 | if (reset_mode && |
5221 | wpa_driver_nl80211_set_mode(drv->first_bss, | |
5d4c78fb JM |
5222 | NL80211_IFTYPE_STATION)) { |
5223 | wpa_printf(MSG_INFO, "nl80211: Failed to set interface into " | |
5224 | "station mode"); | |
5225 | } | |
5226 | ||
5cc4d64b JM |
5227 | return ret; |
5228 | } | |
5229 | ||
5230 | ||
95ff3069 JD |
5231 | static int nl80211_ht_vht_overrides(struct nl_msg *msg, |
5232 | struct wpa_driver_associate_params *params) | |
5233 | { | |
5234 | if (params->disable_ht && nla_put_flag(msg, NL80211_ATTR_DISABLE_HT)) | |
5235 | return -1; | |
5236 | ||
5237 | if (params->htcaps && params->htcaps_mask) { | |
5238 | int sz = sizeof(struct ieee80211_ht_capabilities); | |
5239 | wpa_hexdump(MSG_DEBUG, " * htcaps", params->htcaps, sz); | |
5240 | wpa_hexdump(MSG_DEBUG, " * htcaps_mask", | |
5241 | params->htcaps_mask, sz); | |
5242 | if (nla_put(msg, NL80211_ATTR_HT_CAPABILITY, sz, | |
5243 | params->htcaps) || | |
5244 | nla_put(msg, NL80211_ATTR_HT_CAPABILITY_MASK, sz, | |
5245 | params->htcaps_mask)) | |
5246 | return -1; | |
5247 | } | |
5248 | ||
5249 | #ifdef CONFIG_VHT_OVERRIDES | |
5250 | if (params->disable_vht) { | |
5251 | wpa_printf(MSG_DEBUG, " * VHT disabled"); | |
5252 | if (nla_put_flag(msg, NL80211_ATTR_DISABLE_VHT)) | |
5253 | return -1; | |
5254 | } | |
5255 | ||
5256 | if (params->vhtcaps && params->vhtcaps_mask) { | |
5257 | int sz = sizeof(struct ieee80211_vht_capabilities); | |
5258 | wpa_hexdump(MSG_DEBUG, " * vhtcaps", params->vhtcaps, sz); | |
5259 | wpa_hexdump(MSG_DEBUG, " * vhtcaps_mask", | |
5260 | params->vhtcaps_mask, sz); | |
5261 | if (nla_put(msg, NL80211_ATTR_VHT_CAPABILITY, sz, | |
5262 | params->vhtcaps) || | |
5263 | nla_put(msg, NL80211_ATTR_VHT_CAPABILITY_MASK, sz, | |
5264 | params->vhtcaps_mask)) | |
5265 | return -1; | |
5266 | } | |
5267 | #endif /* CONFIG_VHT_OVERRIDES */ | |
5268 | ||
5269 | return 0; | |
5270 | } | |
5271 | ||
5272 | ||
5cc4d64b JM |
5273 | static int wpa_driver_nl80211_ibss(struct wpa_driver_nl80211_data *drv, |
5274 | struct wpa_driver_associate_params *params) | |
5275 | { | |
5276 | struct nl_msg *msg; | |
5277 | int ret = -1; | |
5278 | int count = 0; | |
5279 | ||
5280 | wpa_printf(MSG_DEBUG, "nl80211: Join IBSS (ifindex=%d)", drv->ifindex); | |
5281 | ||
4ec68377 | 5282 | if (wpa_driver_nl80211_set_mode_ibss(drv->first_bss, ¶ms->freq)) { |
5cc4d64b JM |
5283 | wpa_printf(MSG_INFO, "nl80211: Failed to set interface into " |
5284 | "IBSS mode"); | |
5285 | return -1; | |
5286 | } | |
5287 | ||
5288 | retry: | |
9725b784 | 5289 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_JOIN_IBSS)) || |
a862e4a3 JM |
5290 | params->ssid == NULL || params->ssid_len > sizeof(drv->ssid)) |
5291 | goto fail; | |
5cc4d64b | 5292 | |
21cd8f83 JM |
5293 | wpa_printf(MSG_DEBUG, " * SSID=%s", |
5294 | wpa_ssid_txt(params->ssid, params->ssid_len)); | |
a862e4a3 JM |
5295 | if (nla_put(msg, NL80211_ATTR_SSID, params->ssid_len, params->ssid)) |
5296 | goto fail; | |
5cc4d64b JM |
5297 | os_memcpy(drv->ssid, params->ssid, params->ssid_len); |
5298 | drv->ssid_len = params->ssid_len; | |
5299 | ||
85e1fad8 JM |
5300 | if (nl80211_put_freq_params(msg, ¶ms->freq) < 0 || |
5301 | nl80211_put_beacon_int(msg, params->beacon_int)) | |
a862e4a3 | 5302 | goto fail; |
5cc4d64b JM |
5303 | |
5304 | ret = nl80211_set_conn_keys(params, msg); | |
5305 | if (ret) | |
a862e4a3 | 5306 | goto fail; |
5cc4d64b | 5307 | |
913e3cf7 NC |
5308 | if (params->bssid && params->fixed_bssid) { |
5309 | wpa_printf(MSG_DEBUG, " * BSSID=" MACSTR, | |
5310 | MAC2STR(params->bssid)); | |
a862e4a3 JM |
5311 | if (nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, params->bssid)) |
5312 | goto fail; | |
913e3cf7 NC |
5313 | } |
5314 | ||
4d9e6fba JD |
5315 | if (params->fixed_freq) { |
5316 | wpa_printf(MSG_DEBUG, " * fixed_freq"); | |
5317 | if (nla_put_flag(msg, NL80211_ATTR_FREQ_FIXED)) | |
5318 | goto fail; | |
5319 | } | |
5320 | ||
4848a38d JM |
5321 | if (params->key_mgmt_suite == WPA_KEY_MGMT_IEEE8021X || |
5322 | params->key_mgmt_suite == WPA_KEY_MGMT_PSK || | |
5323 | params->key_mgmt_suite == WPA_KEY_MGMT_IEEE8021X_SHA256 || | |
5324 | params->key_mgmt_suite == WPA_KEY_MGMT_PSK_SHA256) { | |
e640888c | 5325 | wpa_printf(MSG_DEBUG, " * control port"); |
a862e4a3 JM |
5326 | if (nla_put_flag(msg, NL80211_ATTR_CONTROL_PORT)) |
5327 | goto fail; | |
e640888c AQ |
5328 | } |
5329 | ||
a95795ad JM |
5330 | if (params->wpa_ie) { |
5331 | wpa_hexdump(MSG_DEBUG, | |
5332 | " * Extra IEs for Beacon/Probe Response frames", | |
5333 | params->wpa_ie, params->wpa_ie_len); | |
a862e4a3 JM |
5334 | if (nla_put(msg, NL80211_ATTR_IE, params->wpa_ie_len, |
5335 | params->wpa_ie)) | |
5336 | goto fail; | |
a95795ad JM |
5337 | } |
5338 | ||
e15dcf6d PK |
5339 | ret = nl80211_ht_vht_overrides(msg, params); |
5340 | if (ret < 0) | |
5341 | goto fail; | |
95ff3069 | 5342 | |
5cc4d64b JM |
5343 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
5344 | msg = NULL; | |
5345 | if (ret) { | |
5346 | wpa_printf(MSG_DEBUG, "nl80211: Join IBSS failed: ret=%d (%s)", | |
5347 | ret, strerror(-ret)); | |
5348 | count++; | |
5349 | if (ret == -EALREADY && count == 1) { | |
5350 | wpa_printf(MSG_DEBUG, "nl80211: Retry IBSS join after " | |
5351 | "forced leave"); | |
666e508c | 5352 | nl80211_leave_ibss(drv, 0); |
5cc4d64b JM |
5353 | nlmsg_free(msg); |
5354 | goto retry; | |
5355 | } | |
a862e4a3 JM |
5356 | } else { |
5357 | wpa_printf(MSG_DEBUG, | |
5358 | "nl80211: Join IBSS request sent successfully"); | |
5cc4d64b | 5359 | } |
5cc4d64b | 5360 | |
a862e4a3 | 5361 | fail: |
5cc4d64b JM |
5362 | nlmsg_free(msg); |
5363 | return ret; | |
5364 | } | |
5365 | ||
5366 | ||
ad295f3b VK |
5367 | static int nl80211_put_fils_connect_params(struct wpa_driver_nl80211_data *drv, |
5368 | struct wpa_driver_associate_params *params, | |
5369 | struct nl_msg *msg) | |
5370 | { | |
5371 | if (params->fils_erp_username_len) { | |
5372 | wpa_hexdump_ascii(MSG_DEBUG, " * FILS ERP EMSKname/username", | |
5373 | params->fils_erp_username, | |
5374 | params->fils_erp_username_len); | |
5375 | if (nla_put(msg, NL80211_ATTR_FILS_ERP_USERNAME, | |
5376 | params->fils_erp_username_len, | |
5377 | params->fils_erp_username)) | |
5378 | return -1; | |
5379 | } | |
5380 | ||
5381 | if (params->fils_erp_realm_len) { | |
5382 | wpa_hexdump_ascii(MSG_DEBUG, " * FILS ERP Realm", | |
5383 | params->fils_erp_realm, | |
5384 | params->fils_erp_realm_len); | |
5385 | if (nla_put(msg, NL80211_ATTR_FILS_ERP_REALM, | |
5386 | params->fils_erp_realm_len, params->fils_erp_realm)) | |
5387 | return -1; | |
5388 | } | |
5389 | ||
5390 | wpa_printf(MSG_DEBUG, " * FILS ERP next seq %u", | |
5391 | params->fils_erp_next_seq_num); | |
5392 | if (nla_put_u16(msg, NL80211_ATTR_FILS_ERP_NEXT_SEQ_NUM, | |
5393 | params->fils_erp_next_seq_num)) | |
5394 | return -1; | |
5395 | ||
5396 | if (params->fils_erp_rrk_len) { | |
5397 | wpa_printf(MSG_DEBUG, " * FILS ERP rRK (len=%lu)", | |
5398 | (unsigned long) params->fils_erp_rrk_len); | |
5399 | if (nla_put(msg, NL80211_ATTR_FILS_ERP_RRK, | |
5400 | params->fils_erp_rrk_len, params->fils_erp_rrk)) | |
5401 | return -1; | |
5402 | } | |
5403 | ||
5404 | return 0; | |
5405 | } | |
5406 | ||
5407 | ||
a0bdd191 JM |
5408 | static int nl80211_connect_common(struct wpa_driver_nl80211_data *drv, |
5409 | struct wpa_driver_associate_params *params, | |
5410 | struct nl_msg *msg) | |
cfaab580 | 5411 | { |
c85dfc6f JM |
5412 | if (nla_put_flag(msg, NL80211_ATTR_IFACE_SOCKET_OWNER)) |
5413 | return -1; | |
5414 | ||
cfaab580 ZY |
5415 | if (params->bssid) { |
5416 | wpa_printf(MSG_DEBUG, " * bssid=" MACSTR, | |
5417 | MAC2STR(params->bssid)); | |
a862e4a3 JM |
5418 | if (nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, params->bssid)) |
5419 | return -1; | |
cfaab580 | 5420 | } |
a0bdd191 | 5421 | |
7ac7fd43 DS |
5422 | if (params->bssid_hint) { |
5423 | wpa_printf(MSG_DEBUG, " * bssid_hint=" MACSTR, | |
5424 | MAC2STR(params->bssid_hint)); | |
a862e4a3 JM |
5425 | if (nla_put(msg, NL80211_ATTR_MAC_HINT, ETH_ALEN, |
5426 | params->bssid_hint)) | |
5427 | return -1; | |
7ac7fd43 DS |
5428 | } |
5429 | ||
4ec68377 JD |
5430 | if (params->freq.freq) { |
5431 | wpa_printf(MSG_DEBUG, " * freq=%d", params->freq.freq); | |
a862e4a3 JM |
5432 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, |
5433 | params->freq.freq)) | |
5434 | return -1; | |
4ec68377 | 5435 | drv->assoc_freq = params->freq.freq; |
30158a0d SD |
5436 | } else |
5437 | drv->assoc_freq = 0; | |
a0bdd191 | 5438 | |
7ac7fd43 DS |
5439 | if (params->freq_hint) { |
5440 | wpa_printf(MSG_DEBUG, " * freq_hint=%d", params->freq_hint); | |
a862e4a3 JM |
5441 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ_HINT, |
5442 | params->freq_hint)) | |
5443 | return -1; | |
7ac7fd43 DS |
5444 | } |
5445 | ||
1f6c0ab8 BS |
5446 | if (params->bg_scan_period >= 0) { |
5447 | wpa_printf(MSG_DEBUG, " * bg scan period=%d", | |
5448 | params->bg_scan_period); | |
a862e4a3 JM |
5449 | if (nla_put_u16(msg, NL80211_ATTR_BG_SCAN_PERIOD, |
5450 | params->bg_scan_period)) | |
5451 | return -1; | |
1f6c0ab8 | 5452 | } |
a0bdd191 | 5453 | |
cfaab580 | 5454 | if (params->ssid) { |
21cd8f83 JM |
5455 | wpa_printf(MSG_DEBUG, " * SSID=%s", |
5456 | wpa_ssid_txt(params->ssid, params->ssid_len)); | |
a862e4a3 JM |
5457 | if (nla_put(msg, NL80211_ATTR_SSID, params->ssid_len, |
5458 | params->ssid)) | |
5459 | return -1; | |
cfaab580 | 5460 | if (params->ssid_len > sizeof(drv->ssid)) |
a862e4a3 | 5461 | return -1; |
cfaab580 ZY |
5462 | os_memcpy(drv->ssid, params->ssid, params->ssid_len); |
5463 | drv->ssid_len = params->ssid_len; | |
5464 | } | |
a0bdd191 | 5465 | |
cfaab580 | 5466 | wpa_hexdump(MSG_DEBUG, " * IEs", params->wpa_ie, params->wpa_ie_len); |
a862e4a3 JM |
5467 | if (params->wpa_ie && |
5468 | nla_put(msg, NL80211_ATTR_IE, params->wpa_ie_len, params->wpa_ie)) | |
5469 | return -1; | |
cfaab580 | 5470 | |
64fa840a JM |
5471 | if (params->wpa_proto) { |
5472 | enum nl80211_wpa_versions ver = 0; | |
cfaab580 | 5473 | |
64fa840a JM |
5474 | if (params->wpa_proto & WPA_PROTO_WPA) |
5475 | ver |= NL80211_WPA_VERSION_1; | |
5476 | if (params->wpa_proto & WPA_PROTO_RSN) | |
5477 | ver |= NL80211_WPA_VERSION_2; | |
cfaab580 | 5478 | |
64fa840a | 5479 | wpa_printf(MSG_DEBUG, " * WPA Versions 0x%x", ver); |
a862e4a3 JM |
5480 | if (nla_put_u32(msg, NL80211_ATTR_WPA_VERSIONS, ver)) |
5481 | return -1; | |
cfaab580 ZY |
5482 | } |
5483 | ||
4848a38d | 5484 | if (params->pairwise_suite != WPA_CIPHER_NONE) { |
a0bdd191 JM |
5485 | u32 cipher = wpa_cipher_to_cipher_suite(params->pairwise_suite); |
5486 | wpa_printf(MSG_DEBUG, " * pairwise=0x%x", cipher); | |
a862e4a3 JM |
5487 | if (nla_put_u32(msg, NL80211_ATTR_CIPHER_SUITES_PAIRWISE, |
5488 | cipher)) | |
5489 | return -1; | |
cfaab580 ZY |
5490 | } |
5491 | ||
ae6f9272 JM |
5492 | if (params->group_suite == WPA_CIPHER_GTK_NOT_USED && |
5493 | !(drv->capa.enc & WPA_DRIVER_CAPA_ENC_GTK_NOT_USED)) { | |
5494 | /* | |
5495 | * This is likely to work even though many drivers do not | |
5496 | * advertise support for operations without GTK. | |
5497 | */ | |
5498 | wpa_printf(MSG_DEBUG, " * skip group cipher configuration for GTK_NOT_USED due to missing driver support advertisement"); | |
5499 | } else if (params->group_suite != WPA_CIPHER_NONE) { | |
a0bdd191 JM |
5500 | u32 cipher = wpa_cipher_to_cipher_suite(params->group_suite); |
5501 | wpa_printf(MSG_DEBUG, " * group=0x%x", cipher); | |
a862e4a3 JM |
5502 | if (nla_put_u32(msg, NL80211_ATTR_CIPHER_SUITE_GROUP, cipher)) |
5503 | return -1; | |
cfaab580 ZY |
5504 | } |
5505 | ||
4848a38d JM |
5506 | if (params->key_mgmt_suite == WPA_KEY_MGMT_IEEE8021X || |
5507 | params->key_mgmt_suite == WPA_KEY_MGMT_PSK || | |
5508 | params->key_mgmt_suite == WPA_KEY_MGMT_FT_IEEE8021X || | |
5509 | params->key_mgmt_suite == WPA_KEY_MGMT_FT_PSK || | |
163f801e | 5510 | params->key_mgmt_suite == WPA_KEY_MGMT_CCKM || |
8802326f JJ |
5511 | params->key_mgmt_suite == WPA_KEY_MGMT_OSEN || |
5512 | params->key_mgmt_suite == WPA_KEY_MGMT_IEEE8021X_SHA256 || | |
666497c8 | 5513 | params->key_mgmt_suite == WPA_KEY_MGMT_PSK_SHA256 || |
5e3b5197 | 5514 | params->key_mgmt_suite == WPA_KEY_MGMT_IEEE8021X_SUITE_B || |
ad295f3b VK |
5515 | params->key_mgmt_suite == WPA_KEY_MGMT_IEEE8021X_SUITE_B_192 || |
5516 | params->key_mgmt_suite == WPA_KEY_MGMT_FILS_SHA256 || | |
5517 | params->key_mgmt_suite == WPA_KEY_MGMT_FILS_SHA384 || | |
5518 | params->key_mgmt_suite == WPA_KEY_MGMT_FT_FILS_SHA256 || | |
e005725a SD |
5519 | params->key_mgmt_suite == WPA_KEY_MGMT_FT_FILS_SHA384 || |
5520 | params->key_mgmt_suite == WPA_KEY_MGMT_OWE || | |
5521 | params->key_mgmt_suite == WPA_KEY_MGMT_DPP) { | |
3aa24db9 | 5522 | int mgmt = RSN_AUTH_KEY_MGMT_PSK_OVER_802_1X; |
cfaab580 ZY |
5523 | |
5524 | switch (params->key_mgmt_suite) { | |
4848a38d | 5525 | case WPA_KEY_MGMT_CCKM: |
3aa24db9 | 5526 | mgmt = RSN_AUTH_KEY_MGMT_CCKM; |
369c8d7b | 5527 | break; |
4848a38d | 5528 | case WPA_KEY_MGMT_IEEE8021X: |
3aa24db9 | 5529 | mgmt = RSN_AUTH_KEY_MGMT_UNSPEC_802_1X; |
cfaab580 | 5530 | break; |
4848a38d | 5531 | case WPA_KEY_MGMT_FT_IEEE8021X: |
3aa24db9 | 5532 | mgmt = RSN_AUTH_KEY_MGMT_FT_802_1X; |
6a1ce395 | 5533 | break; |
4848a38d | 5534 | case WPA_KEY_MGMT_FT_PSK: |
3aa24db9 | 5535 | mgmt = RSN_AUTH_KEY_MGMT_FT_PSK; |
6a1ce395 | 5536 | break; |
8802326f | 5537 | case WPA_KEY_MGMT_IEEE8021X_SHA256: |
3aa24db9 | 5538 | mgmt = RSN_AUTH_KEY_MGMT_802_1X_SHA256; |
8802326f JJ |
5539 | break; |
5540 | case WPA_KEY_MGMT_PSK_SHA256: | |
3aa24db9 | 5541 | mgmt = RSN_AUTH_KEY_MGMT_PSK_SHA256; |
8802326f | 5542 | break; |
163f801e | 5543 | case WPA_KEY_MGMT_OSEN: |
3aa24db9 | 5544 | mgmt = RSN_AUTH_KEY_MGMT_OSEN; |
163f801e | 5545 | break; |
666497c8 | 5546 | case WPA_KEY_MGMT_IEEE8021X_SUITE_B: |
3aa24db9 | 5547 | mgmt = RSN_AUTH_KEY_MGMT_802_1X_SUITE_B; |
666497c8 | 5548 | break; |
5e3b5197 | 5549 | case WPA_KEY_MGMT_IEEE8021X_SUITE_B_192: |
3aa24db9 | 5550 | mgmt = RSN_AUTH_KEY_MGMT_802_1X_SUITE_B_192; |
5e3b5197 | 5551 | break; |
ad295f3b VK |
5552 | case WPA_KEY_MGMT_FILS_SHA256: |
5553 | mgmt = RSN_AUTH_KEY_MGMT_FILS_SHA256; | |
5554 | break; | |
5555 | case WPA_KEY_MGMT_FILS_SHA384: | |
5556 | mgmt = RSN_AUTH_KEY_MGMT_FILS_SHA384; | |
5557 | break; | |
5558 | case WPA_KEY_MGMT_FT_FILS_SHA256: | |
5559 | mgmt = RSN_AUTH_KEY_MGMT_FT_FILS_SHA256; | |
5560 | break; | |
5561 | case WPA_KEY_MGMT_FT_FILS_SHA384: | |
5562 | mgmt = RSN_AUTH_KEY_MGMT_FT_FILS_SHA384; | |
5563 | break; | |
e005725a SD |
5564 | case WPA_KEY_MGMT_OWE: |
5565 | mgmt = RSN_AUTH_KEY_MGMT_OWE; | |
5566 | break; | |
5567 | case WPA_KEY_MGMT_DPP: | |
5568 | mgmt = RSN_AUTH_KEY_MGMT_DPP; | |
5569 | break; | |
4848a38d | 5570 | case WPA_KEY_MGMT_PSK: |
cfaab580 | 5571 | default: |
3aa24db9 | 5572 | mgmt = RSN_AUTH_KEY_MGMT_PSK_OVER_802_1X; |
cfaab580 ZY |
5573 | break; |
5574 | } | |
163f801e | 5575 | wpa_printf(MSG_DEBUG, " * akm=0x%x", mgmt); |
a862e4a3 JM |
5576 | if (nla_put_u32(msg, NL80211_ATTR_AKM_SUITES, mgmt)) |
5577 | return -1; | |
cfaab580 ZY |
5578 | } |
5579 | ||
d896874f AS |
5580 | if (params->req_key_mgmt_offload && |
5581 | (drv->capa.flags & WPA_DRIVER_FLAGS_4WAY_HANDSHAKE_8021X)) { | |
5582 | wpa_printf(MSG_DEBUG, " * WANT_1X_4WAY_HS"); | |
5583 | if (nla_put_flag(msg, NL80211_ATTR_WANT_1X_4WAY_HS)) | |
5584 | return -1; | |
5585 | } | |
5586 | ||
730c5a1d EP |
5587 | /* Add PSK in case of 4-way handshake offload */ |
5588 | if (params->psk && | |
436ee2fd | 5589 | (drv->capa.flags & WPA_DRIVER_FLAGS_4WAY_HANDSHAKE_PSK)) { |
730c5a1d EP |
5590 | wpa_hexdump_key(MSG_DEBUG, " * PSK", params->psk, 32); |
5591 | if (nla_put(msg, NL80211_ATTR_PMK, 32, params->psk)) | |
5592 | return -1; | |
5593 | } | |
5594 | ||
a862e4a3 JM |
5595 | if (nla_put_flag(msg, NL80211_ATTR_CONTROL_PORT)) |
5596 | return -1; | |
a0bdd191 | 5597 | |
e3429c0b JB |
5598 | if (params->key_mgmt_suite == WPA_KEY_MGMT_IEEE8021X_NO_WPA && |
5599 | (params->pairwise_suite == WPA_CIPHER_NONE || | |
5600 | params->pairwise_suite == WPA_CIPHER_WEP104 || | |
5601 | params->pairwise_suite == WPA_CIPHER_WEP40) && | |
5602 | (nla_put_u16(msg, NL80211_ATTR_CONTROL_PORT_ETHERTYPE, ETH_P_PAE) || | |
5603 | nla_put_flag(msg, NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT))) | |
5604 | return -1; | |
5605 | ||
58162adf AK |
5606 | if (params->rrm_used) { |
5607 | u32 drv_rrm_flags = drv->capa.rrm_flags; | |
b5d172e5 BL |
5608 | if ((!((drv_rrm_flags & |
5609 | WPA_DRIVER_FLAGS_DS_PARAM_SET_IE_IN_PROBES) && | |
5610 | (drv_rrm_flags & WPA_DRIVER_FLAGS_QUIET)) && | |
5611 | !(drv_rrm_flags & WPA_DRIVER_FLAGS_SUPPORT_RRM)) || | |
a862e4a3 JM |
5612 | nla_put_flag(msg, NL80211_ATTR_USE_RRM)) |
5613 | return -1; | |
58162adf AK |
5614 | } |
5615 | ||
95ff3069 | 5616 | if (nl80211_ht_vht_overrides(msg, params) < 0) |
a862e4a3 | 5617 | return -1; |
80e8a5ee | 5618 | |
a0bdd191 JM |
5619 | if (params->p2p) |
5620 | wpa_printf(MSG_DEBUG, " * P2P group"); | |
5621 | ||
86b5c400 LD |
5622 | if (params->pbss) { |
5623 | wpa_printf(MSG_DEBUG, " * PBSS"); | |
5624 | if (nla_put_flag(msg, NL80211_ATTR_PBSS)) | |
5625 | return -1; | |
5626 | } | |
5627 | ||
1126c078 | 5628 | drv->connect_reassoc = 0; |
00c3c4ac JM |
5629 | if (params->prev_bssid) { |
5630 | wpa_printf(MSG_DEBUG, " * prev_bssid=" MACSTR, | |
5631 | MAC2STR(params->prev_bssid)); | |
5632 | if (nla_put(msg, NL80211_ATTR_PREV_BSSID, ETH_ALEN, | |
5633 | params->prev_bssid)) | |
5634 | return -1; | |
1126c078 | 5635 | drv->connect_reassoc = 1; |
00c3c4ac JM |
5636 | } |
5637 | ||
ad295f3b VK |
5638 | if ((params->auth_alg & WPA_AUTH_ALG_FILS) && |
5639 | nl80211_put_fils_connect_params(drv, params, msg) != 0) | |
5640 | return -1; | |
5641 | ||
ba71cb82 SD |
5642 | if ((params->auth_alg & WPA_AUTH_ALG_SAE) && |
5643 | (!(drv->capa.flags & WPA_DRIVER_FLAGS_SME)) && | |
5644 | nla_put_flag(msg, NL80211_ATTR_EXTERNAL_AUTH_SUPPORT)) | |
5645 | return -1; | |
5646 | ||
a0bdd191 | 5647 | return 0; |
a0bdd191 JM |
5648 | } |
5649 | ||
5650 | ||
5651 | static int wpa_driver_nl80211_try_connect( | |
5652 | struct wpa_driver_nl80211_data *drv, | |
40a68f33 SD |
5653 | struct wpa_driver_associate_params *params, |
5654 | struct nl_handle *nl_connect) | |
a0bdd191 JM |
5655 | { |
5656 | struct nl_msg *msg; | |
5657 | enum nl80211_auth_type type; | |
5658 | int ret; | |
5659 | int algs; | |
5660 | ||
b658547d | 5661 | #ifdef CONFIG_DRIVER_NL80211_QCA |
b41f2684 CL |
5662 | if (params->req_key_mgmt_offload && params->psk && |
5663 | (params->key_mgmt_suite == WPA_KEY_MGMT_PSK || | |
5664 | params->key_mgmt_suite == WPA_KEY_MGMT_PSK_SHA256 || | |
5665 | params->key_mgmt_suite == WPA_KEY_MGMT_FT_PSK)) { | |
5666 | wpa_printf(MSG_DEBUG, "nl80211: Key management set PSK"); | |
5667 | ret = issue_key_mgmt_set_key(drv, params->psk, 32); | |
5668 | if (ret) | |
5669 | return ret; | |
5670 | } | |
b658547d | 5671 | #endif /* CONFIG_DRIVER_NL80211_QCA */ |
b41f2684 | 5672 | |
9725b784 JM |
5673 | wpa_printf(MSG_DEBUG, "nl80211: Connect (ifindex=%d)", drv->ifindex); |
5674 | msg = nl80211_drv_msg(drv, 0, NL80211_CMD_CONNECT); | |
a0bdd191 JM |
5675 | if (!msg) |
5676 | return -1; | |
5677 | ||
a0bdd191 JM |
5678 | ret = nl80211_connect_common(drv, params, msg); |
5679 | if (ret) | |
a862e4a3 | 5680 | goto fail; |
a0bdd191 | 5681 | |
299d21e8 EG |
5682 | if (params->mgmt_frame_protection == MGMT_FRAME_PROTECTION_REQUIRED && |
5683 | nla_put_u32(msg, NL80211_ATTR_USE_MFP, NL80211_MFP_REQUIRED)) | |
5684 | goto fail; | |
5685 | ||
5686 | if (params->mgmt_frame_protection == MGMT_FRAME_PROTECTION_OPTIONAL && | |
5687 | (drv->capa.flags & WPA_DRIVER_FLAGS_MFP_OPTIONAL) && | |
5688 | nla_put_u32(msg, NL80211_ATTR_USE_MFP, NL80211_MFP_OPTIONAL)) | |
5689 | goto fail; | |
5690 | ||
a0bdd191 JM |
5691 | algs = 0; |
5692 | if (params->auth_alg & WPA_AUTH_ALG_OPEN) | |
5693 | algs++; | |
5694 | if (params->auth_alg & WPA_AUTH_ALG_SHARED) | |
5695 | algs++; | |
5696 | if (params->auth_alg & WPA_AUTH_ALG_LEAP) | |
5697 | algs++; | |
64a0a75b JM |
5698 | if (params->auth_alg & WPA_AUTH_ALG_FILS) |
5699 | algs++; | |
86c998d3 AM |
5700 | if (params->auth_alg & WPA_AUTH_ALG_FT) |
5701 | algs++; | |
a0bdd191 JM |
5702 | if (algs > 1) { |
5703 | wpa_printf(MSG_DEBUG, " * Leave out Auth Type for automatic " | |
5704 | "selection"); | |
5705 | goto skip_auth_type; | |
5706 | } | |
5707 | ||
3c67e977 | 5708 | type = get_nl_auth_type(params->auth_alg); |
a0bdd191 | 5709 | wpa_printf(MSG_DEBUG, " * Auth Type %d", type); |
3c67e977 VK |
5710 | if (type == NL80211_AUTHTYPE_MAX || |
5711 | nla_put_u32(msg, NL80211_ATTR_AUTH_TYPE, type)) | |
a862e4a3 | 5712 | goto fail; |
a0bdd191 JM |
5713 | |
5714 | skip_auth_type: | |
cfaab580 ZY |
5715 | ret = nl80211_set_conn_keys(params, msg); |
5716 | if (ret) | |
a862e4a3 | 5717 | goto fail; |
cfaab580 | 5718 | |
40a68f33 | 5719 | if (nl_connect) |
0fa33e05 JM |
5720 | ret = send_and_recv(drv->global, nl_connect, msg, |
5721 | NULL, (void *) -1); | |
40a68f33 | 5722 | else |
0fa33e05 | 5723 | ret = send_and_recv_msgs(drv, msg, NULL, (void *) -1); |
40a68f33 | 5724 | |
cfaab580 ZY |
5725 | msg = NULL; |
5726 | if (ret) { | |
5727 | wpa_printf(MSG_DEBUG, "nl80211: MLME connect failed: ret=%d " | |
5728 | "(%s)", ret, strerror(-ret)); | |
a862e4a3 JM |
5729 | } else { |
5730 | wpa_printf(MSG_DEBUG, | |
5731 | "nl80211: Connect request send successfully"); | |
cfaab580 | 5732 | } |
cfaab580 | 5733 | |
a862e4a3 | 5734 | fail: |
0fa33e05 | 5735 | nl80211_nlmsg_clear(msg); |
cfaab580 ZY |
5736 | nlmsg_free(msg); |
5737 | return ret; | |
5738 | ||
5739 | } | |
5740 | ||
5741 | ||
a8c5b43a CW |
5742 | static int wpa_driver_nl80211_connect( |
5743 | struct wpa_driver_nl80211_data *drv, | |
40a68f33 SD |
5744 | struct wpa_driver_associate_params *params, |
5745 | struct nl_handle *nl_connect) | |
a8c5b43a | 5746 | { |
0d4e3d1d JJ |
5747 | int ret; |
5748 | ||
5749 | /* Store the connection attempted bssid for future use */ | |
5750 | if (params->bssid) | |
5751 | os_memcpy(drv->auth_attempt_bssid, params->bssid, ETH_ALEN); | |
5752 | else | |
5753 | os_memset(drv->auth_attempt_bssid, 0, ETH_ALEN); | |
5754 | ||
40a68f33 | 5755 | ret = wpa_driver_nl80211_try_connect(drv, params, nl_connect); |
a8c5b43a CW |
5756 | if (ret == -EALREADY) { |
5757 | /* | |
5758 | * cfg80211 does not currently accept new connections if | |
5759 | * we are already connected. As a workaround, force | |
5760 | * disconnection and try again. | |
5761 | */ | |
5762 | wpa_printf(MSG_DEBUG, "nl80211: Explicitly " | |
5763 | "disconnecting before reassociation " | |
5764 | "attempt"); | |
5765 | if (wpa_driver_nl80211_disconnect( | |
10d32e2c | 5766 | drv, WLAN_REASON_PREV_AUTH_NOT_VALID, nl_connect)) |
a8c5b43a | 5767 | return -1; |
40a68f33 | 5768 | ret = wpa_driver_nl80211_try_connect(drv, params, nl_connect); |
a8c5b43a CW |
5769 | } |
5770 | return ret; | |
5771 | } | |
5772 | ||
5773 | ||
c2a04078 JM |
5774 | static int wpa_driver_nl80211_associate( |
5775 | void *priv, struct wpa_driver_associate_params *params) | |
5776 | { | |
a2e40bb6 FF |
5777 | struct i802_bss *bss = priv; |
5778 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
a862e4a3 | 5779 | int ret = -1; |
c2a04078 JM |
5780 | struct nl_msg *msg; |
5781 | ||
4bd71954 JM |
5782 | nl80211_unmask_11b_rates(bss); |
5783 | ||
5cc4d64b | 5784 | if (params->mode == IEEE80211_MODE_AP) |
1581b38b | 5785 | return wpa_driver_nl80211_ap(drv, params); |
1581b38b | 5786 | |
5cc4d64b JM |
5787 | if (params->mode == IEEE80211_MODE_IBSS) |
5788 | return wpa_driver_nl80211_ibss(drv, params); | |
5789 | ||
4a867032 | 5790 | if (!(drv->capa.flags & WPA_DRIVER_FLAGS_SME)) { |
b1f625e0 EP |
5791 | enum nl80211_iftype nlmode = params->p2p ? |
5792 | NL80211_IFTYPE_P2P_CLIENT : NL80211_IFTYPE_STATION; | |
40a68f33 | 5793 | struct nl_handle *nl_connect = NULL; |
b1f625e0 EP |
5794 | |
5795 | if (wpa_driver_nl80211_set_mode(priv, nlmode) < 0) | |
4a867032 | 5796 | return -1; |
10d32e2c | 5797 | if (params->auth_alg & WPA_AUTH_ALG_SAE) { |
40a68f33 | 5798 | nl_connect = bss->nl_connect; |
10d32e2c CI |
5799 | bss->use_nl_connect = 1; |
5800 | } else { | |
5801 | bss->use_nl_connect = 0; | |
5802 | } | |
5803 | ||
40a68f33 | 5804 | return wpa_driver_nl80211_connect(drv, params, nl_connect); |
4a867032 | 5805 | } |
cfaab580 | 5806 | |
add9b7a4 | 5807 | nl80211_mark_disconnected(drv); |
c2a04078 | 5808 | |
c2a04078 JM |
5809 | wpa_printf(MSG_DEBUG, "nl80211: Associate (ifindex=%d)", |
5810 | drv->ifindex); | |
9725b784 JM |
5811 | msg = nl80211_drv_msg(drv, 0, NL80211_CMD_ASSOCIATE); |
5812 | if (!msg) | |
5813 | return -1; | |
c2a04078 | 5814 | |
a0bdd191 JM |
5815 | ret = nl80211_connect_common(drv, params, msg); |
5816 | if (ret) | |
a862e4a3 | 5817 | goto fail; |
01652550 | 5818 | |
299d21e8 EG |
5819 | if (params->mgmt_frame_protection == MGMT_FRAME_PROTECTION_REQUIRED && |
5820 | nla_put_u32(msg, NL80211_ATTR_USE_MFP, NL80211_MFP_REQUIRED)) | |
5821 | goto fail; | |
5822 | ||
40a45727 JM |
5823 | if (params->fils_kek) { |
5824 | wpa_printf(MSG_DEBUG, " * FILS KEK (len=%u)", | |
5825 | (unsigned int) params->fils_kek_len); | |
5826 | if (nla_put(msg, NL80211_ATTR_FILS_KEK, params->fils_kek_len, | |
5827 | params->fils_kek)) | |
5828 | goto fail; | |
5829 | } | |
5830 | if (params->fils_nonces) { | |
5831 | wpa_hexdump(MSG_DEBUG, " * FILS nonces (for AAD)", | |
5832 | params->fils_nonces, | |
5833 | params->fils_nonces_len); | |
5834 | if (nla_put(msg, NL80211_ATTR_FILS_NONCES, | |
5835 | params->fils_nonces_len, params->fils_nonces)) | |
5836 | goto fail; | |
5837 | } | |
5838 | ||
c2a04078 JM |
5839 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
5840 | msg = NULL; | |
5841 | if (ret) { | |
3b7ea880 BG |
5842 | wpa_dbg(drv->ctx, MSG_DEBUG, |
5843 | "nl80211: MLME command failed (assoc): ret=%d (%s)", | |
5844 | ret, strerror(-ret)); | |
8856462d | 5845 | nl80211_dump_scan(drv); |
a862e4a3 JM |
5846 | } else { |
5847 | wpa_printf(MSG_DEBUG, | |
5848 | "nl80211: Association request send successfully"); | |
c2a04078 | 5849 | } |
c2a04078 | 5850 | |
a862e4a3 | 5851 | fail: |
c2a04078 JM |
5852 | nlmsg_free(msg); |
5853 | return ret; | |
5854 | } | |
3f5285e8 JM |
5855 | |
5856 | ||
ad1e68e6 | 5857 | static int nl80211_set_mode(struct wpa_driver_nl80211_data *drv, |
a1922f93 | 5858 | int ifindex, enum nl80211_iftype mode) |
3f5285e8 | 5859 | { |
3f5285e8 | 5860 | struct nl_msg *msg; |
ad1e68e6 JM |
5861 | int ret = -ENOBUFS; |
5862 | ||
a1922f93 JM |
5863 | wpa_printf(MSG_DEBUG, "nl80211: Set mode ifindex %d iftype %d (%s)", |
5864 | ifindex, mode, nl80211_iftype_str(mode)); | |
5865 | ||
56f77852 JM |
5866 | msg = nl80211_cmd_msg(drv->first_bss, 0, NL80211_CMD_SET_INTERFACE); |
5867 | if (!msg || nla_put_u32(msg, NL80211_ATTR_IFTYPE, mode)) | |
a862e4a3 | 5868 | goto fail; |
ad1e68e6 JM |
5869 | |
5870 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); | |
5883168a | 5871 | msg = NULL; |
ad1e68e6 JM |
5872 | if (!ret) |
5873 | return 0; | |
a862e4a3 | 5874 | fail: |
5883168a | 5875 | nlmsg_free(msg); |
ad1e68e6 JM |
5876 | wpa_printf(MSG_DEBUG, "nl80211: Failed to set interface %d to mode %d:" |
5877 | " %d (%s)", ifindex, mode, ret, strerror(-ret)); | |
5878 | return ret; | |
5879 | } | |
5880 | ||
5881 | ||
3c5d34e3 CW |
5882 | static int wpa_driver_nl80211_set_mode_impl( |
5883 | struct i802_bss *bss, | |
5884 | enum nl80211_iftype nlmode, | |
5885 | struct hostapd_freq_params *desired_freq_params) | |
ad1e68e6 | 5886 | { |
a2e40bb6 | 5887 | struct wpa_driver_nl80211_data *drv = bss->drv; |
ad1e68e6 | 5888 | int ret = -1; |
26af9dca | 5889 | int i; |
86957e62 | 5890 | int was_ap = is_ap_interface(drv->nlmode); |
671a5039 | 5891 | int res; |
ebffdbc4 | 5892 | int mode_switch_res; |
1581b38b | 5893 | |
a5a187b0 JM |
5894 | if (TEST_FAIL()) |
5895 | return -1; | |
5896 | ||
ebffdbc4 CW |
5897 | mode_switch_res = nl80211_set_mode(drv, drv->ifindex, nlmode); |
5898 | if (mode_switch_res && nlmode == nl80211_get_ifmode(bss)) | |
5899 | mode_switch_res = 0; | |
8e12685c | 5900 | |
ebffdbc4 | 5901 | if (mode_switch_res == 0) { |
ad1e68e6 | 5902 | drv->nlmode = nlmode; |
460456f8 JM |
5903 | ret = 0; |
5904 | goto done; | |
ad1e68e6 | 5905 | } |
3f5285e8 | 5906 | |
ebffdbc4 | 5907 | if (mode_switch_res == -ENODEV) |
671a5039 JM |
5908 | return -1; |
5909 | ||
460456f8 | 5910 | if (nlmode == drv->nlmode) { |
c6e8e8e4 JM |
5911 | wpa_printf(MSG_DEBUG, "nl80211: Interface already in " |
5912 | "requested mode - ignore error"); | |
460456f8 JM |
5913 | ret = 0; |
5914 | goto done; /* Already in the requested mode */ | |
5915 | } | |
3f5285e8 | 5916 | |
3f5285e8 JM |
5917 | /* mac80211 doesn't allow mode changes while the device is up, so |
5918 | * take the device down, try to set the mode again, and bring the | |
5919 | * device back up. | |
5920 | */ | |
26af9dca JM |
5921 | wpa_printf(MSG_DEBUG, "nl80211: Try mode change after setting " |
5922 | "interface down"); | |
5923 | for (i = 0; i < 10; i++) { | |
91724d6f | 5924 | res = i802_set_iface_flags(bss, 0); |
6e8183d7 JM |
5925 | if (res == -EACCES || res == -ENODEV) |
5926 | break; | |
ebffdbc4 | 5927 | if (res != 0) { |
26af9dca JM |
5928 | wpa_printf(MSG_DEBUG, "nl80211: Failed to set " |
5929 | "interface down"); | |
ebffdbc4 CW |
5930 | os_sleep(0, 100000); |
5931 | continue; | |
5932 | } | |
3c5d34e3 CW |
5933 | |
5934 | /* | |
5935 | * Setting the mode will fail for some drivers if the phy is | |
5936 | * on a frequency that the mode is disallowed in. | |
5937 | */ | |
5938 | if (desired_freq_params) { | |
bdf5ccb2 | 5939 | res = nl80211_set_channel(bss, desired_freq_params, 0); |
3c5d34e3 CW |
5940 | if (res) { |
5941 | wpa_printf(MSG_DEBUG, | |
5942 | "nl80211: Failed to set frequency on interface"); | |
5943 | } | |
5944 | } | |
5945 | ||
ebffdbc4 CW |
5946 | /* Try to set the mode again while the interface is down */ |
5947 | mode_switch_res = nl80211_set_mode(drv, drv->ifindex, nlmode); | |
5948 | if (mode_switch_res == -EBUSY) { | |
5949 | wpa_printf(MSG_DEBUG, | |
5950 | "nl80211: Delaying mode set while interface going down"); | |
5951 | os_sleep(0, 100000); | |
5952 | continue; | |
5953 | } | |
5954 | ret = mode_switch_res; | |
5955 | break; | |
3f5285e8 JM |
5956 | } |
5957 | ||
c6e8e8e4 JM |
5958 | if (!ret) { |
5959 | wpa_printf(MSG_DEBUG, "nl80211: Mode change succeeded while " | |
5960 | "interface is down"); | |
ad1e68e6 | 5961 | drv->nlmode = nlmode; |
7d9c3698 | 5962 | drv->ignore_if_down_event = 1; |
c6e8e8e4 | 5963 | } |
ad1e68e6 | 5964 | |
ebffdbc4 CW |
5965 | /* Bring the interface back up */ |
5966 | res = linux_set_iface_flags(drv->global->ioctl_sock, bss->ifname, 1); | |
5967 | if (res != 0) { | |
5968 | wpa_printf(MSG_DEBUG, | |
5969 | "nl80211: Failed to set interface up after switching mode"); | |
5970 | ret = -1; | |
5971 | } | |
5972 | ||
460456f8 | 5973 | done: |
3fd1cefb JB |
5974 | if (ret) { |
5975 | wpa_printf(MSG_DEBUG, "nl80211: Interface mode change to %d " | |
5976 | "from %d failed", nlmode, drv->nlmode); | |
5977 | return ret; | |
5978 | } | |
5979 | ||
3e208481 JM |
5980 | if (is_p2p_net_interface(nlmode)) { |
5981 | wpa_printf(MSG_DEBUG, | |
5982 | "nl80211: Interface %s mode change to P2P - disable 11b rates", | |
5983 | bss->ifname); | |
edb9bfba | 5984 | nl80211_disable_11b_rates(drv, drv->ifindex, 1); |
3e208481 JM |
5985 | } else if (drv->disabled_11b_rates) { |
5986 | wpa_printf(MSG_DEBUG, | |
5987 | "nl80211: Interface %s mode changed to non-P2P - re-enable 11b rates", | |
5988 | bss->ifname); | |
1d0c6fb1 | 5989 | nl80211_disable_11b_rates(drv, drv->ifindex, 0); |
3e208481 | 5990 | } |
edb9bfba | 5991 | |
3fd1cefb | 5992 | if (is_ap_interface(nlmode)) { |
36488c05 | 5993 | nl80211_mgmt_unsubscribe(bss, "start AP"); |
460456f8 | 5994 | /* Setup additional AP mode functionality if needed */ |
3fd1cefb | 5995 | if (nl80211_setup_ap(bss)) |
460456f8 | 5996 | return -1; |
3fd1cefb | 5997 | } else if (was_ap) { |
460456f8 | 5998 | /* Remove additional AP mode functionality */ |
3fd1cefb | 5999 | nl80211_teardown_ap(bss); |
a11241fa | 6000 | } else { |
36488c05 | 6001 | nl80211_mgmt_unsubscribe(bss, "mode change"); |
460456f8 | 6002 | } |
460456f8 | 6003 | |
afb0550a BC |
6004 | if (is_mesh_interface(nlmode) && |
6005 | nl80211_mgmt_subscribe_mesh(bss)) | |
6006 | return -1; | |
6007 | ||
873d0fcf | 6008 | if (!bss->in_deinit && !is_ap_interface(nlmode) && |
afb0550a | 6009 | !is_mesh_interface(nlmode) && |
a11241fa JB |
6010 | nl80211_mgmt_subscribe_non_ap(bss) < 0) |
6011 | wpa_printf(MSG_DEBUG, "nl80211: Failed to register Action " | |
6012 | "frame processing - ignore for now"); | |
08359050 | 6013 | |
3fd1cefb | 6014 | return 0; |
3f5285e8 JM |
6015 | } |
6016 | ||
6017 | ||
f3407c66 JM |
6018 | int wpa_driver_nl80211_set_mode(struct i802_bss *bss, |
6019 | enum nl80211_iftype nlmode) | |
3c5d34e3 CW |
6020 | { |
6021 | return wpa_driver_nl80211_set_mode_impl(bss, nlmode, NULL); | |
6022 | } | |
6023 | ||
6024 | ||
4ec68377 JD |
6025 | static int wpa_driver_nl80211_set_mode_ibss(struct i802_bss *bss, |
6026 | struct hostapd_freq_params *freq) | |
3c5d34e3 | 6027 | { |
3c5d34e3 | 6028 | return wpa_driver_nl80211_set_mode_impl(bss, NL80211_IFTYPE_ADHOC, |
4ec68377 | 6029 | freq); |
3c5d34e3 | 6030 | } |
65d645ce AS |
6031 | |
6032 | ||
3f5285e8 JM |
6033 | static int wpa_driver_nl80211_get_capa(void *priv, |
6034 | struct wpa_driver_capa *capa) | |
6035 | { | |
a2e40bb6 FF |
6036 | struct i802_bss *bss = priv; |
6037 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
65d645ce | 6038 | |
3f5285e8 JM |
6039 | if (!drv->has_capability) |
6040 | return -1; | |
6041 | os_memcpy(capa, &drv->capa, sizeof(*capa)); | |
8cd6b7bc JB |
6042 | if (drv->extended_capa && drv->extended_capa_mask) { |
6043 | capa->extended_capa = drv->extended_capa; | |
6044 | capa->extended_capa_mask = drv->extended_capa_mask; | |
6045 | capa->extended_capa_len = drv->extended_capa_len; | |
6046 | } | |
851b0c55 | 6047 | |
906bc4c7 | 6048 | return 0; |
3f5285e8 JM |
6049 | } |
6050 | ||
6051 | ||
6052 | static int wpa_driver_nl80211_set_operstate(void *priv, int state) | |
6053 | { | |
a2e40bb6 FF |
6054 | struct i802_bss *bss = priv; |
6055 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
3f5285e8 | 6056 | |
90a545cc JM |
6057 | wpa_printf(MSG_DEBUG, "nl80211: Set %s operstate %d->%d (%s)", |
6058 | bss->ifname, drv->operstate, state, | |
6059 | state ? "UP" : "DORMANT"); | |
3f5285e8 | 6060 | drv->operstate = state; |
36d84860 | 6061 | return netlink_send_oper_ifla(drv->global->netlink, drv->ifindex, -1, |
e2d02c29 | 6062 | state ? IF_OPER_UP : IF_OPER_DORMANT); |
3f5285e8 JM |
6063 | } |
6064 | ||
01652550 JM |
6065 | |
6066 | static int wpa_driver_nl80211_set_supp_port(void *priv, int authorized) | |
6067 | { | |
a2e40bb6 FF |
6068 | struct i802_bss *bss = priv; |
6069 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
01652550 JM |
6070 | struct nl_msg *msg; |
6071 | struct nl80211_sta_flag_update upd; | |
a862e4a3 | 6072 | int ret; |
2eef5177 JM |
6073 | |
6074 | if (!drv->associated && is_zero_ether_addr(drv->bssid) && !authorized) { | |
6075 | wpa_printf(MSG_DEBUG, "nl80211: Skip set_supp_port(unauthorized) while not associated"); | |
6076 | return 0; | |
6077 | } | |
01652550 | 6078 | |
1ba51ec0 JM |
6079 | wpa_printf(MSG_DEBUG, "nl80211: Set supplicant port %sauthorized for " |
6080 | MACSTR, authorized ? "" : "un", MAC2STR(drv->bssid)); | |
6081 | ||
01652550 JM |
6082 | os_memset(&upd, 0, sizeof(upd)); |
6083 | upd.mask = BIT(NL80211_STA_FLAG_AUTHORIZED); | |
6084 | if (authorized) | |
6085 | upd.set = BIT(NL80211_STA_FLAG_AUTHORIZED); | |
a862e4a3 | 6086 | |
13f83980 | 6087 | if (!(msg = nl80211_bss_msg(bss, 0, NL80211_CMD_SET_STATION)) || |
a862e4a3 JM |
6088 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, drv->bssid) || |
6089 | nla_put(msg, NL80211_ATTR_STA_FLAGS2, sizeof(upd), &upd)) { | |
6090 | nlmsg_free(msg); | |
6091 | return -ENOBUFS; | |
6092 | } | |
01652550 | 6093 | |
2eef5177 | 6094 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
2eef5177 JM |
6095 | if (!ret) |
6096 | return 0; | |
2eef5177 JM |
6097 | wpa_printf(MSG_DEBUG, "nl80211: Failed to set STA flag: %d (%s)", |
6098 | ret, strerror(-ret)); | |
6099 | return ret; | |
01652550 JM |
6100 | } |
6101 | ||
3f5285e8 | 6102 | |
f07ead6a JM |
6103 | /* Set kernel driver on given frequency (MHz) */ |
6104 | static int i802_set_freq(void *priv, struct hostapd_freq_params *freq) | |
c5121837 | 6105 | { |
f07ead6a | 6106 | struct i802_bss *bss = priv; |
13a524a3 | 6107 | return nl80211_set_channel(bss, freq, 0); |
c5121837 JM |
6108 | } |
6109 | ||
f7b3920c | 6110 | |
c5121837 JM |
6111 | static inline int min_int(int a, int b) |
6112 | { | |
6113 | if (a < b) | |
6114 | return a; | |
6115 | return b; | |
6116 | } | |
6117 | ||
6118 | ||
6119 | static int get_key_handler(struct nl_msg *msg, void *arg) | |
6120 | { | |
6121 | struct nlattr *tb[NL80211_ATTR_MAX + 1]; | |
6122 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); | |
6123 | ||
6124 | nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), | |
6125 | genlmsg_attrlen(gnlh, 0), NULL); | |
6126 | ||
6127 | /* | |
6128 | * TODO: validate the key index and mac address! | |
6129 | * Otherwise, there's a race condition as soon as | |
6130 | * the kernel starts sending key notifications. | |
6131 | */ | |
6132 | ||
6133 | if (tb[NL80211_ATTR_KEY_SEQ]) | |
6134 | memcpy(arg, nla_data(tb[NL80211_ATTR_KEY_SEQ]), | |
6135 | min_int(nla_len(tb[NL80211_ATTR_KEY_SEQ]), 6)); | |
4efade31 | 6136 | nl80211_nlmsg_clear(msg); |
c5121837 JM |
6137 | return NL_SKIP; |
6138 | } | |
6139 | ||
6140 | ||
6141 | static int i802_get_seqnum(const char *iface, void *priv, const u8 *addr, | |
6142 | int idx, u8 *seq) | |
6143 | { | |
a2e40bb6 FF |
6144 | struct i802_bss *bss = priv; |
6145 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
c5121837 JM |
6146 | struct nl_msg *msg; |
6147 | ||
95376e1a JM |
6148 | msg = nl80211_ifindex_msg(drv, if_nametoindex(iface), 0, |
6149 | NL80211_CMD_GET_KEY); | |
6150 | if (!msg || | |
a862e4a3 | 6151 | (addr && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) || |
95376e1a | 6152 | nla_put_u8(msg, NL80211_ATTR_KEY_IDX, idx)) { |
a862e4a3 JM |
6153 | nlmsg_free(msg); |
6154 | return -ENOBUFS; | |
6155 | } | |
c5121837 JM |
6156 | |
6157 | memset(seq, 0, 6); | |
6158 | ||
6159 | return send_and_recv_msgs(drv, msg, get_key_handler, seq); | |
c5121837 JM |
6160 | } |
6161 | ||
6162 | ||
c5121837 JM |
6163 | static int i802_set_rts(void *priv, int rts) |
6164 | { | |
a2e40bb6 FF |
6165 | struct i802_bss *bss = priv; |
6166 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
ad649451 | 6167 | struct nl_msg *msg; |
a862e4a3 | 6168 | int ret; |
ad649451 | 6169 | u32 val; |
c5121837 | 6170 | |
bf0021ed | 6171 | if (rts >= 2347 || rts == -1) |
ad649451 JM |
6172 | val = (u32) -1; |
6173 | else | |
6174 | val = rts; | |
c5121837 | 6175 | |
9725b784 | 6176 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_SET_WIPHY)) || |
a862e4a3 JM |
6177 | nla_put_u32(msg, NL80211_ATTR_WIPHY_RTS_THRESHOLD, val)) { |
6178 | nlmsg_free(msg); | |
6179 | return -ENOBUFS; | |
6180 | } | |
ad649451 JM |
6181 | |
6182 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); | |
6183 | if (!ret) | |
6184 | return 0; | |
ad649451 JM |
6185 | wpa_printf(MSG_DEBUG, "nl80211: Failed to set RTS threshold %d: " |
6186 | "%d (%s)", rts, ret, strerror(-ret)); | |
6187 | return ret; | |
c5121837 JM |
6188 | } |
6189 | ||
6190 | ||
6191 | static int i802_set_frag(void *priv, int frag) | |
6192 | { | |
a2e40bb6 FF |
6193 | struct i802_bss *bss = priv; |
6194 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
ad649451 | 6195 | struct nl_msg *msg; |
a862e4a3 | 6196 | int ret; |
ad649451 | 6197 | u32 val; |
c5121837 | 6198 | |
bf0021ed | 6199 | if (frag >= 2346 || frag == -1) |
ad649451 JM |
6200 | val = (u32) -1; |
6201 | else | |
6202 | val = frag; | |
c5121837 | 6203 | |
9725b784 | 6204 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_SET_WIPHY)) || |
a862e4a3 JM |
6205 | nla_put_u32(msg, NL80211_ATTR_WIPHY_FRAG_THRESHOLD, val)) { |
6206 | nlmsg_free(msg); | |
6207 | return -ENOBUFS; | |
6208 | } | |
ad649451 JM |
6209 | |
6210 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); | |
6211 | if (!ret) | |
6212 | return 0; | |
ad649451 JM |
6213 | wpa_printf(MSG_DEBUG, "nl80211: Failed to set fragmentation threshold " |
6214 | "%d: %d (%s)", frag, ret, strerror(-ret)); | |
6215 | return ret; | |
c5121837 JM |
6216 | } |
6217 | ||
6218 | ||
c5121837 JM |
6219 | static int i802_flush(void *priv) |
6220 | { | |
a2e40bb6 | 6221 | struct i802_bss *bss = priv; |
c5121837 | 6222 | struct nl_msg *msg; |
82554b10 | 6223 | int res; |
c5121837 | 6224 | |
83e7bb0e JM |
6225 | wpa_printf(MSG_DEBUG, "nl80211: flush -> DEL_STATION %s (all)", |
6226 | bss->ifname); | |
c5121837 JM |
6227 | |
6228 | /* | |
6229 | * XXX: FIX! this needs to flush all VLANs too | |
6230 | */ | |
13f83980 JM |
6231 | msg = nl80211_bss_msg(bss, 0, NL80211_CMD_DEL_STATION); |
6232 | res = send_and_recv_msgs(bss->drv, msg, NULL, NULL); | |
82554b10 JM |
6233 | if (res) { |
6234 | wpa_printf(MSG_DEBUG, "nl80211: Station flush failed: ret=%d " | |
6235 | "(%s)", res, strerror(-res)); | |
6236 | } | |
6237 | return res; | |
c5121837 JM |
6238 | } |
6239 | ||
6240 | ||
6241 | static int get_sta_handler(struct nl_msg *msg, void *arg) | |
6242 | { | |
6243 | struct nlattr *tb[NL80211_ATTR_MAX + 1]; | |
6244 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); | |
6245 | struct hostap_sta_driver_data *data = arg; | |
6246 | struct nlattr *stats[NL80211_STA_INFO_MAX + 1]; | |
6247 | static struct nla_policy stats_policy[NL80211_STA_INFO_MAX + 1] = { | |
6248 | [NL80211_STA_INFO_INACTIVE_TIME] = { .type = NLA_U32 }, | |
6249 | [NL80211_STA_INFO_RX_BYTES] = { .type = NLA_U32 }, | |
6250 | [NL80211_STA_INFO_TX_BYTES] = { .type = NLA_U32 }, | |
6251 | [NL80211_STA_INFO_RX_PACKETS] = { .type = NLA_U32 }, | |
6252 | [NL80211_STA_INFO_TX_PACKETS] = { .type = NLA_U32 }, | |
dc7785f8 | 6253 | [NL80211_STA_INFO_TX_FAILED] = { .type = NLA_U32 }, |
43022abd NL |
6254 | [NL80211_STA_INFO_RX_BYTES64] = { .type = NLA_U64 }, |
6255 | [NL80211_STA_INFO_TX_BYTES64] = { .type = NLA_U64 }, | |
3567641e | 6256 | [NL80211_STA_INFO_SIGNAL] = { .type = NLA_U8 }, |
72123a84 | 6257 | [NL80211_STA_INFO_ACK_SIGNAL] = { .type = NLA_U8 }, |
3567641e | 6258 | }; |
6259 | struct nlattr *rate[NL80211_RATE_INFO_MAX + 1]; | |
6260 | static struct nla_policy rate_policy[NL80211_RATE_INFO_MAX + 1] = { | |
6261 | [NL80211_RATE_INFO_BITRATE] = { .type = NLA_U16 }, | |
6262 | [NL80211_RATE_INFO_BITRATE32] = { .type = NLA_U32 }, | |
6263 | [NL80211_RATE_INFO_MCS] = { .type = NLA_U8 }, | |
6264 | [NL80211_RATE_INFO_VHT_MCS] = { .type = NLA_U8 }, | |
6265 | [NL80211_RATE_INFO_SHORT_GI] = { .type = NLA_FLAG }, | |
6266 | [NL80211_RATE_INFO_VHT_NSS] = { .type = NLA_U8 }, | |
c5121837 JM |
6267 | }; |
6268 | ||
6269 | nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), | |
6270 | genlmsg_attrlen(gnlh, 0), NULL); | |
6271 | ||
6272 | /* | |
6273 | * TODO: validate the interface and mac address! | |
6274 | * Otherwise, there's a race condition as soon as | |
6275 | * the kernel starts sending station notifications. | |
6276 | */ | |
6277 | ||
6278 | if (!tb[NL80211_ATTR_STA_INFO]) { | |
6279 | wpa_printf(MSG_DEBUG, "sta stats missing!"); | |
6280 | return NL_SKIP; | |
6281 | } | |
6282 | if (nla_parse_nested(stats, NL80211_STA_INFO_MAX, | |
6283 | tb[NL80211_ATTR_STA_INFO], | |
6284 | stats_policy)) { | |
6285 | wpa_printf(MSG_DEBUG, "failed to parse nested attributes!"); | |
6286 | return NL_SKIP; | |
6287 | } | |
6288 | ||
6289 | if (stats[NL80211_STA_INFO_INACTIVE_TIME]) | |
6290 | data->inactive_msec = | |
6291 | nla_get_u32(stats[NL80211_STA_INFO_INACTIVE_TIME]); | |
43022abd | 6292 | /* For backwards compatibility, fetch the 32-bit counters first. */ |
c5121837 JM |
6293 | if (stats[NL80211_STA_INFO_RX_BYTES]) |
6294 | data->rx_bytes = nla_get_u32(stats[NL80211_STA_INFO_RX_BYTES]); | |
6295 | if (stats[NL80211_STA_INFO_TX_BYTES]) | |
6296 | data->tx_bytes = nla_get_u32(stats[NL80211_STA_INFO_TX_BYTES]); | |
43022abd NL |
6297 | if (stats[NL80211_STA_INFO_RX_BYTES64] && |
6298 | stats[NL80211_STA_INFO_TX_BYTES64]) { | |
6299 | /* | |
6300 | * The driver supports 64-bit counters, so use them to override | |
6301 | * the 32-bit values. | |
6302 | */ | |
6303 | data->rx_bytes = | |
6304 | nla_get_u64(stats[NL80211_STA_INFO_RX_BYTES64]); | |
6305 | data->tx_bytes = | |
6306 | nla_get_u64(stats[NL80211_STA_INFO_TX_BYTES64]); | |
6307 | data->bytes_64bit = 1; | |
6308 | } | |
c5121837 JM |
6309 | if (stats[NL80211_STA_INFO_RX_PACKETS]) |
6310 | data->rx_packets = | |
6311 | nla_get_u32(stats[NL80211_STA_INFO_RX_PACKETS]); | |
6312 | if (stats[NL80211_STA_INFO_TX_PACKETS]) | |
6313 | data->tx_packets = | |
6314 | nla_get_u32(stats[NL80211_STA_INFO_TX_PACKETS]); | |
dc7785f8 YZ |
6315 | if (stats[NL80211_STA_INFO_TX_FAILED]) |
6316 | data->tx_retry_failed = | |
6317 | nla_get_u32(stats[NL80211_STA_INFO_TX_FAILED]); | |
3567641e | 6318 | if (stats[NL80211_STA_INFO_SIGNAL]) |
6319 | data->signal = nla_get_u8(stats[NL80211_STA_INFO_SIGNAL]); | |
72123a84 BP |
6320 | if (stats[NL80211_STA_INFO_ACK_SIGNAL]) { |
6321 | data->last_ack_rssi = | |
6322 | nla_get_u8(stats[NL80211_STA_INFO_ACK_SIGNAL]); | |
6323 | data->flags |= STA_DRV_DATA_LAST_ACK_RSSI; | |
6324 | } | |
3567641e | 6325 | |
6326 | if (stats[NL80211_STA_INFO_TX_BITRATE] && | |
6327 | nla_parse_nested(rate, NL80211_RATE_INFO_MAX, | |
6328 | stats[NL80211_STA_INFO_TX_BITRATE], | |
6329 | rate_policy) == 0) { | |
6330 | if (rate[NL80211_RATE_INFO_BITRATE32]) | |
6331 | data->current_tx_rate = | |
6332 | nla_get_u32(rate[NL80211_RATE_INFO_BITRATE32]); | |
6333 | else if (rate[NL80211_RATE_INFO_BITRATE]) | |
6334 | data->current_tx_rate = | |
6335 | nla_get_u16(rate[NL80211_RATE_INFO_BITRATE]); | |
6336 | ||
6337 | if (rate[NL80211_RATE_INFO_MCS]) { | |
6338 | data->tx_mcs = nla_get_u8(rate[NL80211_RATE_INFO_MCS]); | |
6339 | data->flags |= STA_DRV_DATA_TX_MCS; | |
6340 | } | |
6341 | if (rate[NL80211_RATE_INFO_VHT_MCS]) { | |
6342 | data->tx_vhtmcs = | |
6343 | nla_get_u8(rate[NL80211_RATE_INFO_VHT_MCS]); | |
6344 | data->flags |= STA_DRV_DATA_TX_VHT_MCS; | |
6345 | } | |
6346 | if (rate[NL80211_RATE_INFO_SHORT_GI]) | |
6347 | data->flags |= STA_DRV_DATA_TX_SHORT_GI; | |
6348 | if (rate[NL80211_RATE_INFO_VHT_NSS]) { | |
6349 | data->tx_vht_nss = | |
6350 | nla_get_u8(rate[NL80211_RATE_INFO_VHT_NSS]); | |
6351 | data->flags |= STA_DRV_DATA_TX_VHT_NSS; | |
6352 | } | |
6353 | } | |
6354 | ||
6355 | if (stats[NL80211_STA_INFO_RX_BITRATE] && | |
6356 | nla_parse_nested(rate, NL80211_RATE_INFO_MAX, | |
6357 | stats[NL80211_STA_INFO_RX_BITRATE], | |
6358 | rate_policy) == 0) { | |
6359 | if (rate[NL80211_RATE_INFO_BITRATE32]) | |
6360 | data->current_rx_rate = | |
6361 | nla_get_u32(rate[NL80211_RATE_INFO_BITRATE32]); | |
6362 | else if (rate[NL80211_RATE_INFO_BITRATE]) | |
6363 | data->current_rx_rate = | |
6364 | nla_get_u16(rate[NL80211_RATE_INFO_BITRATE]); | |
6365 | ||
6366 | if (rate[NL80211_RATE_INFO_MCS]) { | |
6367 | data->rx_mcs = | |
6368 | nla_get_u8(rate[NL80211_RATE_INFO_MCS]); | |
6369 | data->flags |= STA_DRV_DATA_RX_MCS; | |
6370 | } | |
6371 | if (rate[NL80211_RATE_INFO_VHT_MCS]) { | |
6372 | data->rx_vhtmcs = | |
6373 | nla_get_u8(rate[NL80211_RATE_INFO_VHT_MCS]); | |
6374 | data->flags |= STA_DRV_DATA_RX_VHT_MCS; | |
6375 | } | |
6376 | if (rate[NL80211_RATE_INFO_SHORT_GI]) | |
6377 | data->flags |= STA_DRV_DATA_RX_SHORT_GI; | |
6378 | if (rate[NL80211_RATE_INFO_VHT_NSS]) { | |
6379 | data->rx_vht_nss = | |
6380 | nla_get_u8(rate[NL80211_RATE_INFO_VHT_NSS]); | |
6381 | data->flags |= STA_DRV_DATA_RX_VHT_NSS; | |
6382 | } | |
6383 | } | |
c5121837 JM |
6384 | |
6385 | return NL_SKIP; | |
6386 | } | |
6387 | ||
9ebce9c5 JM |
6388 | static int i802_read_sta_data(struct i802_bss *bss, |
6389 | struct hostap_sta_driver_data *data, | |
c5121837 JM |
6390 | const u8 *addr) |
6391 | { | |
c5121837 JM |
6392 | struct nl_msg *msg; |
6393 | ||
13f83980 JM |
6394 | if (!(msg = nl80211_bss_msg(bss, 0, NL80211_CMD_GET_STATION)) || |
6395 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) { | |
a862e4a3 JM |
6396 | nlmsg_free(msg); |
6397 | return -ENOBUFS; | |
6398 | } | |
c5121837 | 6399 | |
13f83980 | 6400 | return send_and_recv_msgs(bss->drv, msg, get_sta_handler, data); |
c5121837 JM |
6401 | } |
6402 | ||
6403 | ||
c5121837 JM |
6404 | static int i802_set_tx_queue_params(void *priv, int queue, int aifs, |
6405 | int cw_min, int cw_max, int burst_time) | |
6406 | { | |
a2e40bb6 FF |
6407 | struct i802_bss *bss = priv; |
6408 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
c5121837 JM |
6409 | struct nl_msg *msg; |
6410 | struct nlattr *txq, *params; | |
bd512469 | 6411 | int res; |
c5121837 | 6412 | |
13f83980 | 6413 | msg = nl80211_bss_msg(bss, 0, NL80211_CMD_SET_WIPHY); |
c5121837 JM |
6414 | if (!msg) |
6415 | return -1; | |
6416 | ||
c5121837 JM |
6417 | txq = nla_nest_start(msg, NL80211_ATTR_WIPHY_TXQ_PARAMS); |
6418 | if (!txq) | |
a862e4a3 | 6419 | goto fail; |
c5121837 JM |
6420 | |
6421 | /* We are only sending parameters for a single TXQ at a time */ | |
6422 | params = nla_nest_start(msg, 1); | |
6423 | if (!params) | |
a862e4a3 | 6424 | goto fail; |
c5121837 | 6425 | |
7e3c1781 JM |
6426 | switch (queue) { |
6427 | case 0: | |
a862e4a3 JM |
6428 | if (nla_put_u8(msg, NL80211_TXQ_ATTR_QUEUE, NL80211_TXQ_Q_VO)) |
6429 | goto fail; | |
7e3c1781 JM |
6430 | break; |
6431 | case 1: | |
a862e4a3 JM |
6432 | if (nla_put_u8(msg, NL80211_TXQ_ATTR_QUEUE, NL80211_TXQ_Q_VI)) |
6433 | goto fail; | |
7e3c1781 JM |
6434 | break; |
6435 | case 2: | |
a862e4a3 JM |
6436 | if (nla_put_u8(msg, NL80211_TXQ_ATTR_QUEUE, NL80211_TXQ_Q_BE)) |
6437 | goto fail; | |
7e3c1781 JM |
6438 | break; |
6439 | case 3: | |
a862e4a3 JM |
6440 | if (nla_put_u8(msg, NL80211_TXQ_ATTR_QUEUE, NL80211_TXQ_Q_BK)) |
6441 | goto fail; | |
7e3c1781 JM |
6442 | break; |
6443 | } | |
c5121837 JM |
6444 | /* Burst time is configured in units of 0.1 msec and TXOP parameter in |
6445 | * 32 usec, so need to convert the value here. */ | |
a862e4a3 JM |
6446 | if (nla_put_u16(msg, NL80211_TXQ_ATTR_TXOP, |
6447 | (burst_time * 100 + 16) / 32) || | |
6448 | nla_put_u16(msg, NL80211_TXQ_ATTR_CWMIN, cw_min) || | |
6449 | nla_put_u16(msg, NL80211_TXQ_ATTR_CWMAX, cw_max) || | |
6450 | nla_put_u8(msg, NL80211_TXQ_ATTR_AIFS, aifs)) | |
6451 | goto fail; | |
c5121837 JM |
6452 | |
6453 | nla_nest_end(msg, params); | |
6454 | ||
6455 | nla_nest_end(msg, txq); | |
6456 | ||
bd512469 JM |
6457 | res = send_and_recv_msgs(drv, msg, NULL, NULL); |
6458 | wpa_printf(MSG_DEBUG, | |
6459 | "nl80211: TX queue param set: queue=%d aifs=%d cw_min=%d cw_max=%d burst_time=%d --> res=%d", | |
6460 | queue, aifs, cw_min, cw_max, burst_time, res); | |
6461 | if (res == 0) | |
c5121837 | 6462 | return 0; |
9e088e74 | 6463 | msg = NULL; |
a862e4a3 | 6464 | fail: |
9e088e74 | 6465 | nlmsg_free(msg); |
c5121837 JM |
6466 | return -1; |
6467 | } | |
6468 | ||
6469 | ||
9ebce9c5 | 6470 | static int i802_set_sta_vlan(struct i802_bss *bss, const u8 *addr, |
c5121837 JM |
6471 | const char *ifname, int vlan_id) |
6472 | { | |
a2e40bb6 | 6473 | struct wpa_driver_nl80211_data *drv = bss->drv; |
c5121837 | 6474 | struct nl_msg *msg; |
a862e4a3 | 6475 | int ret; |
c5121837 | 6476 | |
bbc706a3 JM |
6477 | wpa_printf(MSG_DEBUG, "nl80211: %s[%d]: set_sta_vlan(" MACSTR |
6478 | ", ifname=%s[%d], vlan_id=%d)", | |
6479 | bss->ifname, if_nametoindex(bss->ifname), | |
6480 | MAC2STR(addr), ifname, if_nametoindex(ifname), vlan_id); | |
13f83980 | 6481 | if (!(msg = nl80211_bss_msg(bss, 0, NL80211_CMD_SET_STATION)) || |
a862e4a3 JM |
6482 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) || |
6483 | nla_put_u32(msg, NL80211_ATTR_STA_VLAN, if_nametoindex(ifname))) { | |
6484 | nlmsg_free(msg); | |
6485 | return -ENOBUFS; | |
6486 | } | |
c5121837 | 6487 | |
cd1d72c1 JM |
6488 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
6489 | if (ret < 0) { | |
6490 | wpa_printf(MSG_ERROR, "nl80211: NL80211_ATTR_STA_VLAN (addr=" | |
6491 | MACSTR " ifname=%s vlan_id=%d) failed: %d (%s)", | |
6492 | MAC2STR(addr), ifname, vlan_id, ret, | |
6493 | strerror(-ret)); | |
6494 | } | |
cd1d72c1 | 6495 | return ret; |
c5121837 JM |
6496 | } |
6497 | ||
fbbfcbac | 6498 | |
c5121837 JM |
6499 | static int i802_get_inact_sec(void *priv, const u8 *addr) |
6500 | { | |
6501 | struct hostap_sta_driver_data data; | |
6502 | int ret; | |
6503 | ||
7824bf77 | 6504 | os_memset(&data, 0, sizeof(data)); |
c5121837 JM |
6505 | data.inactive_msec = (unsigned long) -1; |
6506 | ret = i802_read_sta_data(priv, &data, addr); | |
b9749bac MH |
6507 | if (ret == -ENOENT) |
6508 | return -ENOENT; | |
c5121837 JM |
6509 | if (ret || data.inactive_msec == (unsigned long) -1) |
6510 | return -1; | |
6511 | return data.inactive_msec / 1000; | |
6512 | } | |
6513 | ||
6514 | ||
6515 | static int i802_sta_clear_stats(void *priv, const u8 *addr) | |
6516 | { | |
6517 | #if 0 | |
6518 | /* TODO */ | |
6519 | #endif | |
6520 | return 0; | |
6521 | } | |
6522 | ||
6523 | ||
731723a5 JM |
6524 | static int i802_sta_deauth(void *priv, const u8 *own_addr, const u8 *addr, |
6525 | int reason) | |
c5121837 | 6526 | { |
a2e40bb6 | 6527 | struct i802_bss *bss = priv; |
e1bd4e19 | 6528 | struct wpa_driver_nl80211_data *drv = bss->drv; |
c5121837 | 6529 | struct ieee80211_mgmt mgmt; |
05e5e615 DL |
6530 | u8 channel; |
6531 | ||
6532 | if (ieee80211_freq_to_chan(bss->freq, &channel) == | |
6533 | HOSTAPD_MODE_IEEE80211AD) { | |
6534 | /* Deauthentication is not used in DMG/IEEE 802.11ad; | |
6535 | * disassociate the STA instead. */ | |
6536 | return i802_sta_disassoc(priv, own_addr, addr, reason); | |
6537 | } | |
c5121837 | 6538 | |
0d391b03 BC |
6539 | if (is_mesh_interface(drv->nlmode)) |
6540 | return -1; | |
6541 | ||
e1bd4e19 | 6542 | if (drv->device_ap_sme) |
59d7148a | 6543 | return wpa_driver_nl80211_sta_remove(bss, addr, 1, reason); |
e1bd4e19 | 6544 | |
c5121837 JM |
6545 | memset(&mgmt, 0, sizeof(mgmt)); |
6546 | mgmt.frame_control = IEEE80211_FC(WLAN_FC_TYPE_MGMT, | |
6547 | WLAN_FC_STYPE_DEAUTH); | |
6548 | memcpy(mgmt.da, addr, ETH_ALEN); | |
731723a5 JM |
6549 | memcpy(mgmt.sa, own_addr, ETH_ALEN); |
6550 | memcpy(mgmt.bssid, own_addr, ETH_ALEN); | |
c5121837 | 6551 | mgmt.u.deauth.reason_code = host_to_le16(reason); |
a2e40bb6 | 6552 | return wpa_driver_nl80211_send_mlme(bss, (u8 *) &mgmt, |
9f324b61 | 6553 | IEEE80211_HDRLEN + |
9ebce9c5 | 6554 | sizeof(mgmt.u.deauth), 0, 0, 0, 0, |
2d3943ce | 6555 | 0, NULL, 0); |
c5121837 JM |
6556 | } |
6557 | ||
6558 | ||
731723a5 JM |
6559 | static int i802_sta_disassoc(void *priv, const u8 *own_addr, const u8 *addr, |
6560 | int reason) | |
c5121837 | 6561 | { |
a2e40bb6 | 6562 | struct i802_bss *bss = priv; |
e1bd4e19 | 6563 | struct wpa_driver_nl80211_data *drv = bss->drv; |
c5121837 JM |
6564 | struct ieee80211_mgmt mgmt; |
6565 | ||
0d391b03 BC |
6566 | if (is_mesh_interface(drv->nlmode)) |
6567 | return -1; | |
6568 | ||
e1bd4e19 | 6569 | if (drv->device_ap_sme) |
59d7148a | 6570 | return wpa_driver_nl80211_sta_remove(bss, addr, 0, reason); |
e1bd4e19 | 6571 | |
c5121837 JM |
6572 | memset(&mgmt, 0, sizeof(mgmt)); |
6573 | mgmt.frame_control = IEEE80211_FC(WLAN_FC_TYPE_MGMT, | |
6574 | WLAN_FC_STYPE_DISASSOC); | |
6575 | memcpy(mgmt.da, addr, ETH_ALEN); | |
731723a5 JM |
6576 | memcpy(mgmt.sa, own_addr, ETH_ALEN); |
6577 | memcpy(mgmt.bssid, own_addr, ETH_ALEN); | |
c5121837 | 6578 | mgmt.u.disassoc.reason_code = host_to_le16(reason); |
a2e40bb6 | 6579 | return wpa_driver_nl80211_send_mlme(bss, (u8 *) &mgmt, |
9f324b61 | 6580 | IEEE80211_HDRLEN + |
9ebce9c5 | 6581 | sizeof(mgmt.u.disassoc), 0, 0, 0, 0, |
2d3943ce | 6582 | 0, NULL, 0); |
c5121837 JM |
6583 | } |
6584 | ||
6585 | ||
9b4d9c8b JM |
6586 | static void dump_ifidx(struct wpa_driver_nl80211_data *drv) |
6587 | { | |
6588 | char buf[200], *pos, *end; | |
6589 | int i, res; | |
6590 | ||
6591 | pos = buf; | |
6592 | end = pos + sizeof(buf); | |
6593 | ||
6594 | for (i = 0; i < drv->num_if_indices; i++) { | |
6595 | if (!drv->if_indices[i]) | |
6596 | continue; | |
732b1d20 MB |
6597 | res = os_snprintf(pos, end - pos, " %d(%d)", |
6598 | drv->if_indices[i], | |
6599 | drv->if_indices_reason[i]); | |
d85e1fc8 | 6600 | if (os_snprintf_error(end - pos, res)) |
9b4d9c8b JM |
6601 | break; |
6602 | pos += res; | |
6603 | } | |
6604 | *pos = '\0'; | |
6605 | ||
6606 | wpa_printf(MSG_DEBUG, "nl80211: if_indices[%d]:%s", | |
6607 | drv->num_if_indices, buf); | |
6608 | } | |
6609 | ||
6610 | ||
732b1d20 MB |
6611 | static void add_ifidx(struct wpa_driver_nl80211_data *drv, int ifidx, |
6612 | int ifidx_reason) | |
f07ead6a JM |
6613 | { |
6614 | int i; | |
732b1d20 | 6615 | int *old, *old_reason; |
f07ead6a | 6616 | |
732b1d20 MB |
6617 | wpa_printf(MSG_DEBUG, |
6618 | "nl80211: Add own interface ifindex %d (ifidx_reason %d)", | |
6619 | ifidx, ifidx_reason); | |
6620 | if (have_ifidx(drv, ifidx, ifidx_reason)) { | |
b36935be MB |
6621 | wpa_printf(MSG_DEBUG, "nl80211: ifindex %d already in the list", |
6622 | ifidx); | |
6623 | return; | |
6624 | } | |
f07ead6a JM |
6625 | for (i = 0; i < drv->num_if_indices; i++) { |
6626 | if (drv->if_indices[i] == 0) { | |
6627 | drv->if_indices[i] = ifidx; | |
732b1d20 | 6628 | drv->if_indices_reason[i] = ifidx_reason; |
9b4d9c8b | 6629 | dump_ifidx(drv); |
f07ead6a JM |
6630 | return; |
6631 | } | |
6632 | } | |
6633 | ||
6634 | if (drv->if_indices != drv->default_if_indices) | |
6635 | old = drv->if_indices; | |
6636 | else | |
6637 | old = NULL; | |
6638 | ||
732b1d20 MB |
6639 | if (drv->if_indices_reason != drv->default_if_indices_reason) |
6640 | old_reason = drv->if_indices_reason; | |
6641 | else | |
6642 | old_reason = NULL; | |
6643 | ||
067ffa26 JM |
6644 | drv->if_indices = os_realloc_array(old, drv->num_if_indices + 1, |
6645 | sizeof(int)); | |
732b1d20 MB |
6646 | drv->if_indices_reason = os_realloc_array(old_reason, |
6647 | drv->num_if_indices + 1, | |
6648 | sizeof(int)); | |
f07ead6a JM |
6649 | if (!drv->if_indices) { |
6650 | if (!old) | |
6651 | drv->if_indices = drv->default_if_indices; | |
6652 | else | |
6653 | drv->if_indices = old; | |
732b1d20 MB |
6654 | } |
6655 | if (!drv->if_indices_reason) { | |
6656 | if (!old_reason) | |
6657 | drv->if_indices_reason = drv->default_if_indices_reason; | |
6658 | else | |
29eddc3d | 6659 | drv->if_indices_reason = old_reason; |
732b1d20 MB |
6660 | } |
6661 | if (!drv->if_indices || !drv->if_indices_reason) { | |
f07ead6a JM |
6662 | wpa_printf(MSG_ERROR, "Failed to reallocate memory for " |
6663 | "interfaces"); | |
6664 | wpa_printf(MSG_ERROR, "Ignoring EAPOL on interface %d", ifidx); | |
6665 | return; | |
732b1d20 MB |
6666 | } |
6667 | if (!old) | |
f07ead6a JM |
6668 | os_memcpy(drv->if_indices, drv->default_if_indices, |
6669 | sizeof(drv->default_if_indices)); | |
732b1d20 MB |
6670 | if (!old_reason) |
6671 | os_memcpy(drv->if_indices_reason, | |
6672 | drv->default_if_indices_reason, | |
6673 | sizeof(drv->default_if_indices_reason)); | |
f07ead6a | 6674 | drv->if_indices[drv->num_if_indices] = ifidx; |
732b1d20 | 6675 | drv->if_indices_reason[drv->num_if_indices] = ifidx_reason; |
f07ead6a | 6676 | drv->num_if_indices++; |
9b4d9c8b | 6677 | dump_ifidx(drv); |
f07ead6a JM |
6678 | } |
6679 | ||
6680 | ||
732b1d20 MB |
6681 | static void del_ifidx(struct wpa_driver_nl80211_data *drv, int ifidx, |
6682 | int ifidx_reason) | |
f07ead6a JM |
6683 | { |
6684 | int i; | |
6685 | ||
6686 | for (i = 0; i < drv->num_if_indices; i++) { | |
732b1d20 MB |
6687 | if ((drv->if_indices[i] == ifidx || ifidx == IFIDX_ANY) && |
6688 | (drv->if_indices_reason[i] == ifidx_reason || | |
6689 | ifidx_reason == IFIDX_ANY)) { | |
f07ead6a JM |
6690 | drv->if_indices[i] = 0; |
6691 | break; | |
6692 | } | |
6693 | } | |
9b4d9c8b | 6694 | dump_ifidx(drv); |
f07ead6a JM |
6695 | } |
6696 | ||
6697 | ||
732b1d20 MB |
6698 | static int have_ifidx(struct wpa_driver_nl80211_data *drv, int ifidx, |
6699 | int ifidx_reason) | |
f07ead6a JM |
6700 | { |
6701 | int i; | |
6702 | ||
6703 | for (i = 0; i < drv->num_if_indices; i++) | |
732b1d20 MB |
6704 | if (drv->if_indices[i] == ifidx && |
6705 | (drv->if_indices_reason[i] == ifidx_reason || | |
6706 | ifidx_reason == IFIDX_ANY)) | |
f07ead6a JM |
6707 | return 1; |
6708 | ||
6709 | return 0; | |
6710 | } | |
6711 | ||
6712 | ||
6713 | static int i802_set_wds_sta(void *priv, const u8 *addr, int aid, int val, | |
0e80ea2c | 6714 | const char *bridge_ifname, char *ifname_wds) |
f07ead6a JM |
6715 | { |
6716 | struct i802_bss *bss = priv; | |
6717 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
6718 | char name[IFNAMSIZ + 1]; | |
1952b626 | 6719 | union wpa_event_data event; |
d577f7f3 AO |
6720 | int ret; |
6721 | ||
6722 | ret = os_snprintf(name, sizeof(name), "%s.sta%d", bss->ifname, aid); | |
6723 | if (ret >= (int) sizeof(name)) | |
6724 | wpa_printf(MSG_WARNING, | |
6725 | "nl80211: WDS interface name was truncated"); | |
6726 | else if (ret < 0) | |
6727 | return ret; | |
f07ead6a | 6728 | |
69dd2967 SM |
6729 | if (ifname_wds) |
6730 | os_strlcpy(ifname_wds, name, IFNAMSIZ + 1); | |
6731 | ||
f07ead6a JM |
6732 | wpa_printf(MSG_DEBUG, "nl80211: Set WDS STA addr=" MACSTR |
6733 | " aid=%d val=%d name=%s", MAC2STR(addr), aid, val, name); | |
6734 | if (val) { | |
6735 | if (!if_nametoindex(name)) { | |
6736 | if (nl80211_create_iface(drv, name, | |
6737 | NL80211_IFTYPE_AP_VLAN, | |
2aec4f3c JM |
6738 | bss->addr, 1, NULL, NULL, 0) < |
6739 | 0) | |
f07ead6a JM |
6740 | return -1; |
6741 | if (bridge_ifname && | |
c81eff1a BG |
6742 | linux_br_add_if(drv->global->ioctl_sock, |
6743 | bridge_ifname, name) < 0) | |
f07ead6a | 6744 | return -1; |
1952b626 BP |
6745 | |
6746 | os_memset(&event, 0, sizeof(event)); | |
6747 | event.wds_sta_interface.sta_addr = addr; | |
6748 | event.wds_sta_interface.ifname = name; | |
6749 | event.wds_sta_interface.istatus = INTERFACE_ADDED; | |
8bfbb295 | 6750 | wpa_supplicant_event(bss->ctx, |
1952b626 BP |
6751 | EVENT_WDS_STA_INTERFACE_STATUS, |
6752 | &event); | |
f07ead6a | 6753 | } |
75227f3a JM |
6754 | if (linux_set_iface_flags(drv->global->ioctl_sock, name, 1)) { |
6755 | wpa_printf(MSG_ERROR, "nl80211: Failed to set WDS STA " | |
6756 | "interface %s up", name); | |
6757 | } | |
f07ead6a JM |
6758 | return i802_set_sta_vlan(priv, addr, name, 0); |
6759 | } else { | |
f9052d6e JM |
6760 | if (bridge_ifname && |
6761 | linux_br_del_if(drv->global->ioctl_sock, bridge_ifname, | |
6762 | name) < 0) | |
6763 | wpa_printf(MSG_INFO, | |
6764 | "nl80211: Failed to remove interface %s from bridge %s: %s", | |
6765 | name, bridge_ifname, strerror(errno)); | |
c34e618d | 6766 | |
f07ead6a | 6767 | i802_set_sta_vlan(priv, addr, bss->ifname, 0); |
d0595b25 | 6768 | nl80211_remove_iface(drv, if_nametoindex(name)); |
1952b626 BP |
6769 | os_memset(&event, 0, sizeof(event)); |
6770 | event.wds_sta_interface.sta_addr = addr; | |
6771 | event.wds_sta_interface.ifname = name; | |
6772 | event.wds_sta_interface.istatus = INTERFACE_REMOVED; | |
8bfbb295 | 6773 | wpa_supplicant_event(bss->ctx, EVENT_WDS_STA_INTERFACE_STATUS, |
1952b626 | 6774 | &event); |
d0595b25 | 6775 | return 0; |
f07ead6a JM |
6776 | } |
6777 | } | |
6778 | ||
6779 | ||
6780 | static void handle_eapol(int sock, void *eloop_ctx, void *sock_ctx) | |
6781 | { | |
6782 | struct wpa_driver_nl80211_data *drv = eloop_ctx; | |
6783 | struct sockaddr_ll lladdr; | |
6784 | unsigned char buf[3000]; | |
6785 | int len; | |
6786 | socklen_t fromlen = sizeof(lladdr); | |
6787 | ||
6788 | len = recvfrom(sock, buf, sizeof(buf), 0, | |
6789 | (struct sockaddr *)&lladdr, &fromlen); | |
6790 | if (len < 0) { | |
7ac3616d JM |
6791 | wpa_printf(MSG_ERROR, "nl80211: EAPOL recv failed: %s", |
6792 | strerror(errno)); | |
f07ead6a JM |
6793 | return; |
6794 | } | |
6795 | ||
732b1d20 | 6796 | if (have_ifidx(drv, lladdr.sll_ifindex, IFIDX_ANY)) |
f07ead6a JM |
6797 | drv_event_eapol_rx(drv->ctx, lladdr.sll_addr, buf, len); |
6798 | } | |
6799 | ||
6800 | ||
94627f6c | 6801 | static int i802_check_bridge(struct wpa_driver_nl80211_data *drv, |
e17a2477 | 6802 | struct i802_bss *bss, |
94627f6c JM |
6803 | const char *brname, const char *ifname) |
6804 | { | |
6c6678e7 | 6805 | int br_ifindex; |
94627f6c JM |
6806 | char in_br[IFNAMSIZ]; |
6807 | ||
e17a2477 | 6808 | os_strlcpy(bss->brname, brname, IFNAMSIZ); |
6c6678e7 | 6809 | br_ifindex = if_nametoindex(brname); |
6c6678e7 | 6810 | if (br_ifindex == 0) { |
94627f6c JM |
6811 | /* |
6812 | * Bridge was configured, but the bridge device does | |
6813 | * not exist. Try to add it now. | |
6814 | */ | |
c81eff1a | 6815 | if (linux_br_add(drv->global->ioctl_sock, brname) < 0) { |
94627f6c JM |
6816 | wpa_printf(MSG_ERROR, "nl80211: Failed to add the " |
6817 | "bridge interface %s: %s", | |
6818 | brname, strerror(errno)); | |
6819 | return -1; | |
6820 | } | |
e17a2477 | 6821 | bss->added_bridge = 1; |
8997613c | 6822 | br_ifindex = if_nametoindex(brname); |
732b1d20 | 6823 | add_ifidx(drv, br_ifindex, drv->ifindex); |
94627f6c | 6824 | } |
8997613c | 6825 | bss->br_ifindex = br_ifindex; |
94627f6c JM |
6826 | |
6827 | if (linux_br_get(in_br, ifname) == 0) { | |
c809756f SM |
6828 | if (os_strcmp(in_br, brname) == 0) { |
6829 | bss->already_in_bridge = 1; | |
94627f6c | 6830 | return 0; /* already in the bridge */ |
c809756f | 6831 | } |
94627f6c JM |
6832 | |
6833 | wpa_printf(MSG_DEBUG, "nl80211: Removing interface %s from " | |
6834 | "bridge %s", ifname, in_br); | |
c81eff1a BG |
6835 | if (linux_br_del_if(drv->global->ioctl_sock, in_br, ifname) < |
6836 | 0) { | |
94627f6c JM |
6837 | wpa_printf(MSG_ERROR, "nl80211: Failed to " |
6838 | "remove interface %s from bridge " | |
6839 | "%s: %s", | |
fdbfb63e | 6840 | ifname, in_br, strerror(errno)); |
94627f6c JM |
6841 | return -1; |
6842 | } | |
6843 | } | |
6844 | ||
6845 | wpa_printf(MSG_DEBUG, "nl80211: Adding interface %s into bridge %s", | |
6846 | ifname, brname); | |
c81eff1a | 6847 | if (linux_br_add_if(drv->global->ioctl_sock, brname, ifname) < 0) { |
94627f6c JM |
6848 | wpa_printf(MSG_ERROR, "nl80211: Failed to add interface %s " |
6849 | "into bridge %s: %s", | |
6850 | ifname, brname, strerror(errno)); | |
6851 | return -1; | |
6852 | } | |
e17a2477 | 6853 | bss->added_if_into_bridge = 1; |
94627f6c JM |
6854 | |
6855 | return 0; | |
6856 | } | |
6857 | ||
6858 | ||
92f475b4 JM |
6859 | static void *i802_init(struct hostapd_data *hapd, |
6860 | struct wpa_init_params *params) | |
c5121837 JM |
6861 | { |
6862 | struct wpa_driver_nl80211_data *drv; | |
a2e40bb6 | 6863 | struct i802_bss *bss; |
c5121837 | 6864 | size_t i; |
cb05808c AN |
6865 | char master_ifname[IFNAMSIZ]; |
6866 | int ifindex, br_ifindex = 0; | |
94627f6c | 6867 | int br_added = 0; |
c5121837 | 6868 | |
0d547d5f JM |
6869 | bss = wpa_driver_nl80211_drv_init(hapd, params->ifname, |
6870 | params->global_priv, 1, | |
0ecff8d7 | 6871 | params->bssid, params->driver_params); |
a2e40bb6 | 6872 | if (bss == NULL) |
c5121837 | 6873 | return NULL; |
c5121837 | 6874 | |
a2e40bb6 | 6875 | drv = bss->drv; |
7635bfb0 | 6876 | |
cb05808c | 6877 | if (linux_br_get(master_ifname, params->ifname) == 0) { |
94627f6c | 6878 | wpa_printf(MSG_DEBUG, "nl80211: Interface %s is in bridge %s", |
cb05808c AN |
6879 | params->ifname, master_ifname); |
6880 | br_ifindex = if_nametoindex(master_ifname); | |
6881 | os_strlcpy(bss->brname, master_ifname, IFNAMSIZ); | |
6882 | } else if ((params->num_bridge == 0 || !params->bridge[0]) && | |
6883 | linux_master_get(master_ifname, params->ifname) == 0) { | |
6884 | wpa_printf(MSG_DEBUG, "nl80211: Interface %s is in master %s", | |
6885 | params->ifname, master_ifname); | |
6886 | /* start listening for EAPOL on the master interface */ | |
732b1d20 | 6887 | add_ifidx(drv, if_nametoindex(master_ifname), drv->ifindex); |
f2d6c17a DL |
6888 | |
6889 | /* check if master itself is under bridge */ | |
6890 | if (linux_br_get(master_ifname, master_ifname) == 0) { | |
6891 | wpa_printf(MSG_DEBUG, "nl80211: which is in bridge %s", | |
6892 | master_ifname); | |
6893 | br_ifindex = if_nametoindex(master_ifname); | |
6894 | os_strlcpy(bss->brname, master_ifname, IFNAMSIZ); | |
6895 | } | |
94627f6c | 6896 | } else { |
cb05808c | 6897 | master_ifname[0] = '\0'; |
94627f6c | 6898 | } |
cb05808c | 6899 | |
6c6678e7 | 6900 | bss->br_ifindex = br_ifindex; |
94627f6c | 6901 | |
92f475b4 | 6902 | for (i = 0; i < params->num_bridge; i++) { |
94627f6c JM |
6903 | if (params->bridge[i]) { |
6904 | ifindex = if_nametoindex(params->bridge[i]); | |
6905 | if (ifindex) | |
732b1d20 | 6906 | add_ifidx(drv, ifindex, drv->ifindex); |
94627f6c JM |
6907 | if (ifindex == br_ifindex) |
6908 | br_added = 1; | |
6909 | } | |
c5121837 | 6910 | } |
c5121837 | 6911 | |
ad1e68e6 | 6912 | /* start listening for EAPOL on the default AP interface */ |
732b1d20 | 6913 | add_ifidx(drv, drv->ifindex, IFIDX_ANY); |
ad1e68e6 | 6914 | |
5ef8e39f JM |
6915 | if (params->num_bridge && params->bridge[0]) { |
6916 | if (i802_check_bridge(drv, bss, params->bridge[0], | |
6917 | params->ifname) < 0) | |
6918 | goto failed; | |
cb05808c | 6919 | if (os_strcmp(params->bridge[0], master_ifname) != 0) |
5ef8e39f JM |
6920 | br_added = 1; |
6921 | } | |
6922 | ||
6923 | if (!br_added && br_ifindex && | |
6924 | (params->num_bridge == 0 || !params->bridge[0])) | |
732b1d20 | 6925 | add_ifidx(drv, br_ifindex, drv->ifindex); |
94627f6c | 6926 | |
97ed9a06 | 6927 | #ifdef CONFIG_LIBNL3_ROUTE |
c809756f | 6928 | if (bss->added_if_into_bridge || bss->already_in_bridge) { |
97ed9a06 KP |
6929 | drv->rtnl_sk = nl_socket_alloc(); |
6930 | if (drv->rtnl_sk == NULL) { | |
6931 | wpa_printf(MSG_ERROR, "nl80211: Failed to allocate nl_sock"); | |
6932 | goto failed; | |
6933 | } | |
6934 | ||
6935 | if (nl_connect(drv->rtnl_sk, NETLINK_ROUTE)) { | |
6936 | wpa_printf(MSG_ERROR, "nl80211: Failed to connect nl_sock to NETLINK_ROUTE: %s", | |
6937 | strerror(errno)); | |
6938 | goto failed; | |
6939 | } | |
6940 | } | |
6941 | #endif /* CONFIG_LIBNL3_ROUTE */ | |
6942 | ||
ad1e68e6 JM |
6943 | drv->eapol_sock = socket(PF_PACKET, SOCK_DGRAM, htons(ETH_P_PAE)); |
6944 | if (drv->eapol_sock < 0) { | |
7ac3616d JM |
6945 | wpa_printf(MSG_ERROR, "nl80211: socket(PF_PACKET, SOCK_DGRAM, ETH_P_PAE) failed: %s", |
6946 | strerror(errno)); | |
bbaf0837 | 6947 | goto failed; |
ad1e68e6 JM |
6948 | } |
6949 | ||
6950 | if (eloop_register_read_sock(drv->eapol_sock, handle_eapol, drv, NULL)) | |
6951 | { | |
7ac3616d | 6952 | wpa_printf(MSG_INFO, "nl80211: Could not register read socket for eapol"); |
c5121837 | 6953 | goto failed; |
ad1e68e6 JM |
6954 | } |
6955 | ||
c81eff1a BG |
6956 | if (linux_get_ifhwaddr(drv->global->ioctl_sock, bss->ifname, |
6957 | params->own_addr)) | |
bbaf0837 | 6958 | goto failed; |
fee354c7 | 6959 | os_memcpy(drv->perm_addr, params->own_addr, ETH_ALEN); |
c5121837 | 6960 | |
341eebee JB |
6961 | memcpy(bss->addr, params->own_addr, ETH_ALEN); |
6962 | ||
a2e40bb6 | 6963 | return bss; |
c5121837 JM |
6964 | |
6965 | failed: | |
7635bfb0 | 6966 | wpa_driver_nl80211_deinit(bss); |
bbaf0837 JM |
6967 | return NULL; |
6968 | } | |
c5121837 | 6969 | |
c5121837 | 6970 | |
bbaf0837 JM |
6971 | static void i802_deinit(void *priv) |
6972 | { | |
9ebce9c5 JM |
6973 | struct i802_bss *bss = priv; |
6974 | wpa_driver_nl80211_deinit(bss); | |
c5121837 JM |
6975 | } |
6976 | ||
c5121837 | 6977 | |
22a7c9d7 JM |
6978 | static enum nl80211_iftype wpa_driver_nl80211_if_type( |
6979 | enum wpa_driver_if_type type) | |
6980 | { | |
6981 | switch (type) { | |
6982 | case WPA_IF_STATION: | |
9f51b113 | 6983 | return NL80211_IFTYPE_STATION; |
75bde05d JM |
6984 | case WPA_IF_P2P_CLIENT: |
6985 | case WPA_IF_P2P_GROUP: | |
9f51b113 | 6986 | return NL80211_IFTYPE_P2P_CLIENT; |
22a7c9d7 JM |
6987 | case WPA_IF_AP_VLAN: |
6988 | return NL80211_IFTYPE_AP_VLAN; | |
6989 | case WPA_IF_AP_BSS: | |
6990 | return NL80211_IFTYPE_AP; | |
9f51b113 JB |
6991 | case WPA_IF_P2P_GO: |
6992 | return NL80211_IFTYPE_P2P_GO; | |
7aad838c NS |
6993 | case WPA_IF_P2P_DEVICE: |
6994 | return NL80211_IFTYPE_P2P_DEVICE; | |
5b78493f MH |
6995 | case WPA_IF_MESH: |
6996 | return NL80211_IFTYPE_MESH_POINT; | |
98342208 AK |
6997 | default: |
6998 | return -1; | |
22a7c9d7 | 6999 | } |
22a7c9d7 JM |
7000 | } |
7001 | ||
7002 | ||
f2ed8023 JM |
7003 | static int nl80211_addr_in_use(struct nl80211_global *global, const u8 *addr) |
7004 | { | |
7005 | struct wpa_driver_nl80211_data *drv; | |
7006 | dl_list_for_each(drv, &global->interfaces, | |
7007 | struct wpa_driver_nl80211_data, list) { | |
834ee56f | 7008 | if (os_memcmp(addr, drv->first_bss->addr, ETH_ALEN) == 0) |
f2ed8023 JM |
7009 | return 1; |
7010 | } | |
7011 | return 0; | |
7012 | } | |
7013 | ||
7014 | ||
5b78493f | 7015 | static int nl80211_vif_addr(struct wpa_driver_nl80211_data *drv, u8 *new_addr) |
f2ed8023 JM |
7016 | { |
7017 | unsigned int idx; | |
7018 | ||
7019 | if (!drv->global) | |
7020 | return -1; | |
7021 | ||
834ee56f | 7022 | os_memcpy(new_addr, drv->first_bss->addr, ETH_ALEN); |
f2ed8023 | 7023 | for (idx = 0; idx < 64; idx++) { |
834ee56f | 7024 | new_addr[0] = drv->first_bss->addr[0] | 0x02; |
f2ed8023 JM |
7025 | new_addr[0] ^= idx << 2; |
7026 | if (!nl80211_addr_in_use(drv->global, new_addr)) | |
7027 | break; | |
7028 | } | |
7029 | if (idx == 64) | |
7030 | return -1; | |
7031 | ||
5b78493f | 7032 | wpa_printf(MSG_DEBUG, "nl80211: Assigned new virtual interface address " |
f2ed8023 JM |
7033 | MACSTR, MAC2STR(new_addr)); |
7034 | ||
7035 | return 0; | |
7036 | } | |
7037 | ||
7038 | ||
f632e483 AS |
7039 | struct wdev_info { |
7040 | u64 wdev_id; | |
7041 | int wdev_id_set; | |
7042 | u8 macaddr[ETH_ALEN]; | |
7043 | }; | |
7044 | ||
7045 | static int nl80211_wdev_handler(struct nl_msg *msg, void *arg) | |
e472e1b4 AS |
7046 | { |
7047 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); | |
7048 | struct nlattr *tb[NL80211_ATTR_MAX + 1]; | |
f632e483 | 7049 | struct wdev_info *wi = arg; |
e472e1b4 AS |
7050 | |
7051 | nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), | |
7052 | genlmsg_attrlen(gnlh, 0), NULL); | |
7053 | if (tb[NL80211_ATTR_WDEV]) { | |
f632e483 AS |
7054 | wi->wdev_id = nla_get_u64(tb[NL80211_ATTR_WDEV]); |
7055 | wi->wdev_id_set = 1; | |
e472e1b4 AS |
7056 | } |
7057 | ||
7058 | if (tb[NL80211_ATTR_MAC]) | |
f632e483 | 7059 | os_memcpy(wi->macaddr, nla_data(tb[NL80211_ATTR_MAC]), |
e472e1b4 AS |
7060 | ETH_ALEN); |
7061 | ||
7062 | return NL_SKIP; | |
7063 | } | |
7064 | ||
7065 | ||
7ab68865 | 7066 | static int wpa_driver_nl80211_if_add(void *priv, enum wpa_driver_if_type type, |
8043e725 | 7067 | const char *ifname, const u8 *addr, |
f3585c8a | 7068 | void *bss_ctx, void **drv_priv, |
e17a2477 | 7069 | char *force_ifname, u8 *if_addr, |
d8a3b66d AS |
7070 | const char *bridge, int use_existing, |
7071 | int setup_ap) | |
22a7c9d7 | 7072 | { |
e472e1b4 | 7073 | enum nl80211_iftype nlmode; |
a2e40bb6 FF |
7074 | struct i802_bss *bss = priv; |
7075 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
22a7c9d7 | 7076 | int ifidx; |
2aec4f3c | 7077 | int added = 1; |
22a7c9d7 | 7078 | |
f3585c8a JM |
7079 | if (addr) |
7080 | os_memcpy(if_addr, addr, ETH_ALEN); | |
e472e1b4 AS |
7081 | nlmode = wpa_driver_nl80211_if_type(type); |
7082 | if (nlmode == NL80211_IFTYPE_P2P_DEVICE) { | |
f632e483 AS |
7083 | struct wdev_info p2pdev_info; |
7084 | ||
7085 | os_memset(&p2pdev_info, 0, sizeof(p2pdev_info)); | |
e472e1b4 | 7086 | ifidx = nl80211_create_iface(drv, ifname, nlmode, addr, |
f632e483 | 7087 | 0, nl80211_wdev_handler, |
2aec4f3c | 7088 | &p2pdev_info, use_existing); |
f632e483 | 7089 | if (!p2pdev_info.wdev_id_set || ifidx != 0) { |
e472e1b4 AS |
7090 | wpa_printf(MSG_ERROR, "nl80211: Failed to create a P2P Device interface %s", |
7091 | ifname); | |
e472e1b4 AS |
7092 | return -1; |
7093 | } | |
f632e483 AS |
7094 | |
7095 | drv->global->if_add_wdevid = p2pdev_info.wdev_id; | |
7096 | drv->global->if_add_wdevid_set = p2pdev_info.wdev_id_set; | |
7097 | if (!is_zero_ether_addr(p2pdev_info.macaddr)) | |
7098 | os_memcpy(if_addr, p2pdev_info.macaddr, ETH_ALEN); | |
7099 | wpa_printf(MSG_DEBUG, "nl80211: New P2P Device interface %s (0x%llx) created", | |
7100 | ifname, | |
7101 | (long long unsigned int) p2pdev_info.wdev_id); | |
e472e1b4 AS |
7102 | } else { |
7103 | ifidx = nl80211_create_iface(drv, ifname, nlmode, addr, | |
2aec4f3c JM |
7104 | 0, NULL, NULL, use_existing); |
7105 | if (use_existing && ifidx == -ENFILE) { | |
7106 | added = 0; | |
7107 | ifidx = if_nametoindex(ifname); | |
7108 | } else if (ifidx < 0) { | |
e472e1b4 AS |
7109 | return -1; |
7110 | } | |
22a7c9d7 JM |
7111 | } |
7112 | ||
ab7a1add | 7113 | if (!addr) { |
8ea8a89c | 7114 | if (nlmode == NL80211_IFTYPE_P2P_DEVICE) |
ab7a1add AS |
7115 | os_memcpy(if_addr, bss->addr, ETH_ALEN); |
7116 | else if (linux_get_ifhwaddr(drv->global->ioctl_sock, | |
8ea8a89c | 7117 | ifname, if_addr) < 0) { |
2aec4f3c JM |
7118 | if (added) |
7119 | nl80211_remove_iface(drv, ifidx); | |
ab7a1add AS |
7120 | return -1; |
7121 | } | |
c55f774d JM |
7122 | } |
7123 | ||
c55f774d JM |
7124 | if (!addr && |
7125 | (type == WPA_IF_P2P_CLIENT || type == WPA_IF_P2P_GROUP || | |
8ea8a89c JM |
7126 | type == WPA_IF_P2P_GO || type == WPA_IF_MESH || |
7127 | type == WPA_IF_STATION)) { | |
7128 | /* Enforce unique address */ | |
ab7a1add | 7129 | u8 new_addr[ETH_ALEN]; |
c55f774d | 7130 | |
ab7a1add | 7131 | if (linux_get_ifhwaddr(drv->global->ioctl_sock, ifname, |
c81eff1a | 7132 | new_addr) < 0) { |
ea39367c MK |
7133 | if (added) |
7134 | nl80211_remove_iface(drv, ifidx); | |
c55f774d JM |
7135 | return -1; |
7136 | } | |
f608081c | 7137 | if (nl80211_addr_in_use(drv->global, new_addr)) { |
c55f774d | 7138 | wpa_printf(MSG_DEBUG, "nl80211: Allocate new address " |
8ea8a89c | 7139 | "for interface %s type %d", ifname, type); |
5b78493f | 7140 | if (nl80211_vif_addr(drv, new_addr) < 0) { |
ea39367c MK |
7141 | if (added) |
7142 | nl80211_remove_iface(drv, ifidx); | |
c55f774d JM |
7143 | return -1; |
7144 | } | |
c81eff1a | 7145 | if (linux_set_ifhwaddr(drv->global->ioctl_sock, ifname, |
c55f774d | 7146 | new_addr) < 0) { |
ea39367c MK |
7147 | if (added) |
7148 | nl80211_remove_iface(drv, ifidx); | |
c55f774d JM |
7149 | return -1; |
7150 | } | |
c55f774d | 7151 | } |
f67eeb5c | 7152 | os_memcpy(if_addr, new_addr, ETH_ALEN); |
c55f774d | 7153 | } |
f3585c8a | 7154 | |
d8a3b66d | 7155 | if (type == WPA_IF_AP_BSS && setup_ap) { |
f5eb9da3 JM |
7156 | struct i802_bss *new_bss = os_zalloc(sizeof(*new_bss)); |
7157 | if (new_bss == NULL) { | |
2aec4f3c JM |
7158 | if (added) |
7159 | nl80211_remove_iface(drv, ifidx); | |
f5eb9da3 JM |
7160 | return -1; |
7161 | } | |
7162 | ||
7163 | if (bridge && | |
7164 | i802_check_bridge(drv, new_bss, bridge, ifname) < 0) { | |
7165 | wpa_printf(MSG_ERROR, "nl80211: Failed to add the new " | |
7166 | "interface %s to a bridge %s", | |
7167 | ifname, bridge); | |
2aec4f3c JM |
7168 | if (added) |
7169 | nl80211_remove_iface(drv, ifidx); | |
f5eb9da3 JM |
7170 | os_free(new_bss); |
7171 | return -1; | |
7172 | } | |
7173 | ||
c81eff1a BG |
7174 | if (linux_set_iface_flags(drv->global->ioctl_sock, ifname, 1)) |
7175 | { | |
ea39367c MK |
7176 | if (added) |
7177 | nl80211_remove_iface(drv, ifidx); | |
07179987 | 7178 | os_free(new_bss); |
22a7c9d7 JM |
7179 | return -1; |
7180 | } | |
a2e40bb6 | 7181 | os_strlcpy(new_bss->ifname, ifname, IFNAMSIZ); |
341eebee | 7182 | os_memcpy(new_bss->addr, if_addr, ETH_ALEN); |
a2e40bb6 FF |
7183 | new_bss->ifindex = ifidx; |
7184 | new_bss->drv = drv; | |
834ee56f KP |
7185 | new_bss->next = drv->first_bss->next; |
7186 | new_bss->freq = drv->first_bss->freq; | |
a5e1eb20 | 7187 | new_bss->ctx = bss_ctx; |
2aec4f3c | 7188 | new_bss->added_if = added; |
834ee56f | 7189 | drv->first_bss->next = new_bss; |
a2e40bb6 FF |
7190 | if (drv_priv) |
7191 | *drv_priv = new_bss; | |
cc7a48d1 | 7192 | nl80211_init_bss(new_bss); |
3dd1d890 YAP |
7193 | |
7194 | /* Subscribe management frames for this WPA_IF_AP_BSS */ | |
7195 | if (nl80211_setup_ap(new_bss)) | |
7196 | return -1; | |
22a7c9d7 | 7197 | } |
22a7c9d7 | 7198 | |
ff6a158b JM |
7199 | if (drv->global) |
7200 | drv->global->if_add_ifindex = ifidx; | |
7201 | ||
d1bb7aed JJ |
7202 | /* |
7203 | * Some virtual interfaces need to process EAPOL packets and events on | |
7204 | * the parent interface. This is used mainly with hostapd. | |
7205 | */ | |
7206 | if (ifidx > 0 && | |
7207 | (drv->hostapd || | |
7208 | nlmode == NL80211_IFTYPE_AP_VLAN || | |
7209 | nlmode == NL80211_IFTYPE_WDS || | |
7210 | nlmode == NL80211_IFTYPE_MONITOR)) | |
732b1d20 | 7211 | add_ifidx(drv, ifidx, IFIDX_ANY); |
b36935be | 7212 | |
22a7c9d7 JM |
7213 | return 0; |
7214 | } | |
7215 | ||
7216 | ||
9ebce9c5 | 7217 | static int wpa_driver_nl80211_if_remove(struct i802_bss *bss, |
22a7c9d7 JM |
7218 | enum wpa_driver_if_type type, |
7219 | const char *ifname) | |
7220 | { | |
a2e40bb6 | 7221 | struct wpa_driver_nl80211_data *drv = bss->drv; |
22a7c9d7 JM |
7222 | int ifindex = if_nametoindex(ifname); |
7223 | ||
2aec4f3c JM |
7224 | wpa_printf(MSG_DEBUG, "nl80211: %s(type=%d ifname=%s) ifindex=%d added_if=%d", |
7225 | __func__, type, ifname, ifindex, bss->added_if); | |
158b090c | 7226 | if (ifindex > 0 && (bss->added_if || bss->ifindex != ifindex)) |
2b72df63 | 7227 | nl80211_remove_iface(drv, ifindex); |
de884303 JM |
7228 | else if (ifindex > 0 && !bss->added_if) { |
7229 | struct wpa_driver_nl80211_data *drv2; | |
7230 | dl_list_for_each(drv2, &drv->global->interfaces, | |
732b1d20 MB |
7231 | struct wpa_driver_nl80211_data, list) { |
7232 | del_ifidx(drv2, ifindex, IFIDX_ANY); | |
7233 | del_ifidx(drv2, IFIDX_ANY, ifindex); | |
7234 | } | |
de884303 | 7235 | } |
c34e618d | 7236 | |
c34e618d FF |
7237 | if (type != WPA_IF_AP_BSS) |
7238 | return 0; | |
7239 | ||
e17a2477 | 7240 | if (bss->added_if_into_bridge) { |
c81eff1a BG |
7241 | if (linux_br_del_if(drv->global->ioctl_sock, bss->brname, |
7242 | bss->ifname) < 0) | |
e17a2477 JM |
7243 | wpa_printf(MSG_INFO, "nl80211: Failed to remove " |
7244 | "interface %s from bridge %s: %s", | |
7245 | bss->ifname, bss->brname, strerror(errno)); | |
7246 | } | |
7247 | if (bss->added_bridge) { | |
c81eff1a | 7248 | if (linux_br_del(drv->global->ioctl_sock, bss->brname) < 0) |
e17a2477 JM |
7249 | wpa_printf(MSG_INFO, "nl80211: Failed to remove " |
7250 | "bridge %s: %s", | |
7251 | bss->brname, strerror(errno)); | |
7252 | } | |
a2e40bb6 | 7253 | |
834ee56f | 7254 | if (bss != drv->first_bss) { |
8546ea19 | 7255 | struct i802_bss *tbss; |
a2e40bb6 | 7256 | |
2aec4f3c | 7257 | wpa_printf(MSG_DEBUG, "nl80211: Not the first BSS - remove it"); |
834ee56f | 7258 | for (tbss = drv->first_bss; tbss; tbss = tbss->next) { |
8546ea19 JM |
7259 | if (tbss->next == bss) { |
7260 | tbss->next = bss->next; | |
3dd1d890 YAP |
7261 | /* Unsubscribe management frames */ |
7262 | nl80211_teardown_ap(bss); | |
cc7a48d1 | 7263 | nl80211_destroy_bss(bss); |
5c9da160 MB |
7264 | if (!bss->added_if) |
7265 | i802_set_iface_flags(bss, 0); | |
8546ea19 JM |
7266 | os_free(bss); |
7267 | bss = NULL; | |
7268 | break; | |
7269 | } | |
22a7c9d7 | 7270 | } |
8546ea19 JM |
7271 | if (bss) |
7272 | wpa_printf(MSG_INFO, "nl80211: %s - could not find " | |
7273 | "BSS %p in the list", __func__, bss); | |
390e489c | 7274 | } else { |
2aec4f3c | 7275 | wpa_printf(MSG_DEBUG, "nl80211: First BSS - reassign context"); |
390e489c | 7276 | nl80211_teardown_ap(bss); |
2aec4f3c | 7277 | if (!bss->added_if && !drv->first_bss->next) |
a70cd0db | 7278 | wpa_driver_nl80211_del_beacon(bss); |
390e489c | 7279 | nl80211_destroy_bss(bss); |
2aec4f3c JM |
7280 | if (!bss->added_if) |
7281 | i802_set_iface_flags(bss, 0); | |
390e489c KP |
7282 | if (drv->first_bss->next) { |
7283 | drv->first_bss = drv->first_bss->next; | |
7284 | drv->ctx = drv->first_bss->ctx; | |
7285 | os_free(bss); | |
7286 | } else { | |
7287 | wpa_printf(MSG_DEBUG, "nl80211: No second BSS to reassign context to"); | |
7288 | } | |
22a7c9d7 | 7289 | } |
22a7c9d7 JM |
7290 | |
7291 | return 0; | |
7292 | } | |
7293 | ||
7294 | ||
55777702 JM |
7295 | static int cookie_handler(struct nl_msg *msg, void *arg) |
7296 | { | |
7297 | struct nlattr *tb[NL80211_ATTR_MAX + 1]; | |
7298 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); | |
7299 | u64 *cookie = arg; | |
7300 | nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), | |
7301 | genlmsg_attrlen(gnlh, 0), NULL); | |
7302 | if (tb[NL80211_ATTR_COOKIE]) | |
7303 | *cookie = nla_get_u64(tb[NL80211_ATTR_COOKIE]); | |
7304 | return NL_SKIP; | |
7305 | } | |
7306 | ||
7307 | ||
88df0ef7 | 7308 | static int nl80211_send_frame_cmd(struct i802_bss *bss, |
5dfca53f JB |
7309 | unsigned int freq, unsigned int wait, |
7310 | const u8 *buf, size_t buf_len, | |
88df0ef7 | 7311 | u64 *cookie_out, int no_cck, int no_ack, |
2d3943ce AO |
7312 | int offchanok, const u16 *csa_offs, |
7313 | size_t csa_offs_len) | |
9884f9cc | 7314 | { |
88df0ef7 | 7315 | struct wpa_driver_nl80211_data *drv = bss->drv; |
9884f9cc JB |
7316 | struct nl_msg *msg; |
7317 | u64 cookie; | |
7318 | int ret = -1; | |
7319 | ||
cc2ada86 | 7320 | wpa_printf(MSG_MSGDUMP, "nl80211: CMD_FRAME freq=%u wait=%u no_cck=%d " |
2e3e4566 JM |
7321 | "no_ack=%d offchanok=%d", |
7322 | freq, wait, no_cck, no_ack, offchanok); | |
c91f796f | 7323 | wpa_hexdump(MSG_MSGDUMP, "CMD_FRAME", buf, buf_len); |
9884f9cc | 7324 | |
56f77852 | 7325 | if (!(msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_FRAME)) || |
a862e4a3 JM |
7326 | (freq && nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq)) || |
7327 | (wait && nla_put_u32(msg, NL80211_ATTR_DURATION, wait)) || | |
7328 | (offchanok && ((drv->capa.flags & WPA_DRIVER_FLAGS_OFFCHANNEL_TX) || | |
7329 | drv->test_use_roc_tx) && | |
7330 | nla_put_flag(msg, NL80211_ATTR_OFFCHANNEL_TX_OK)) || | |
7331 | (no_cck && nla_put_flag(msg, NL80211_ATTR_TX_NO_CCK_RATE)) || | |
7332 | (no_ack && nla_put_flag(msg, NL80211_ATTR_DONT_WAIT_FOR_ACK)) || | |
2d3943ce AO |
7333 | (csa_offs && nla_put(msg, NL80211_ATTR_CSA_C_OFFSETS_TX, |
7334 | csa_offs_len * sizeof(u16), csa_offs)) || | |
a862e4a3 JM |
7335 | nla_put(msg, NL80211_ATTR_FRAME, buf_len, buf)) |
7336 | goto fail; | |
9884f9cc JB |
7337 | |
7338 | cookie = 0; | |
7339 | ret = send_and_recv_msgs(drv, msg, cookie_handler, &cookie); | |
7340 | msg = NULL; | |
7341 | if (ret) { | |
7342 | wpa_printf(MSG_DEBUG, "nl80211: Frame command failed: ret=%d " | |
a05225c8 JM |
7343 | "(%s) (freq=%u wait=%u)", ret, strerror(-ret), |
7344 | freq, wait); | |
a862e4a3 JM |
7345 | } else { |
7346 | wpa_printf(MSG_MSGDUMP, "nl80211: Frame TX command accepted%s; " | |
7347 | "cookie 0x%llx", no_ack ? " (no ACK)" : "", | |
7348 | (long long unsigned int) cookie); | |
9884f9cc | 7349 | |
a862e4a3 JM |
7350 | if (cookie_out) |
7351 | *cookie_out = no_ack ? (u64) -1 : cookie; | |
759a8a3a JM |
7352 | |
7353 | if (drv->num_send_action_cookies == MAX_SEND_ACTION_COOKIES) { | |
7354 | wpa_printf(MSG_DEBUG, | |
7355 | "nl80211: Drop oldest pending send action cookie 0x%llx", | |
7356 | (long long unsigned int) | |
7357 | drv->send_action_cookies[0]); | |
7358 | os_memmove(&drv->send_action_cookies[0], | |
7359 | &drv->send_action_cookies[1], | |
7360 | (MAX_SEND_ACTION_COOKIES - 1) * | |
7361 | sizeof(u64)); | |
7362 | drv->num_send_action_cookies--; | |
7363 | } | |
7364 | drv->send_action_cookies[drv->num_send_action_cookies] = cookie; | |
7365 | drv->num_send_action_cookies++; | |
a862e4a3 | 7366 | } |
9884f9cc | 7367 | |
a862e4a3 | 7368 | fail: |
9884f9cc JB |
7369 | nlmsg_free(msg); |
7370 | return ret; | |
7371 | } | |
7372 | ||
7373 | ||
9ebce9c5 JM |
7374 | static int wpa_driver_nl80211_send_action(struct i802_bss *bss, |
7375 | unsigned int freq, | |
190b9062 | 7376 | unsigned int wait_time, |
58f6fbe0 JM |
7377 | const u8 *dst, const u8 *src, |
7378 | const u8 *bssid, | |
b106173a JM |
7379 | const u8 *data, size_t data_len, |
7380 | int no_cck) | |
58f6fbe0 | 7381 | { |
a2e40bb6 | 7382 | struct wpa_driver_nl80211_data *drv = bss->drv; |
58f6fbe0 | 7383 | int ret = -1; |
58f6fbe0 JM |
7384 | u8 *buf; |
7385 | struct ieee80211_hdr *hdr; | |
58f6fbe0 | 7386 | |
5dfca53f | 7387 | wpa_printf(MSG_DEBUG, "nl80211: Send Action frame (ifindex=%d, " |
55231068 JM |
7388 | "freq=%u MHz wait=%d ms no_cck=%d)", |
7389 | drv->ifindex, freq, wait_time, no_cck); | |
58f6fbe0 JM |
7390 | |
7391 | buf = os_zalloc(24 + data_len); | |
7392 | if (buf == NULL) | |
7393 | return ret; | |
7394 | os_memcpy(buf + 24, data, data_len); | |
7395 | hdr = (struct ieee80211_hdr *) buf; | |
7396 | hdr->frame_control = | |
7397 | IEEE80211_FC(WLAN_FC_TYPE_MGMT, WLAN_FC_STYPE_ACTION); | |
7398 | os_memcpy(hdr->addr1, dst, ETH_ALEN); | |
7399 | os_memcpy(hdr->addr2, src, ETH_ALEN); | |
7400 | os_memcpy(hdr->addr3, bssid, ETH_ALEN); | |
7401 | ||
8331c9b3 VK |
7402 | if (os_memcmp(bss->addr, src, ETH_ALEN) != 0) { |
7403 | wpa_printf(MSG_DEBUG, "nl80211: Use random TA " MACSTR, | |
7404 | MAC2STR(src)); | |
7405 | os_memcpy(bss->rand_addr, src, ETH_ALEN); | |
7406 | } else { | |
7407 | os_memset(bss->rand_addr, 0, ETH_ALEN); | |
7408 | } | |
7409 | ||
f78f2785 JM |
7410 | if (is_ap_interface(drv->nlmode) && |
7411 | (!(drv->capa.flags & WPA_DRIVER_FLAGS_OFFCHANNEL_TX) || | |
7412 | (int) freq == bss->freq || drv->device_ap_sme || | |
7413 | !drv->use_monitor)) | |
9ebce9c5 JM |
7414 | ret = wpa_driver_nl80211_send_mlme(bss, buf, 24 + data_len, |
7415 | 0, freq, no_cck, 1, | |
2d3943ce | 7416 | wait_time, NULL, 0); |
9884f9cc | 7417 | else |
88df0ef7 | 7418 | ret = nl80211_send_frame_cmd(bss, freq, wait_time, buf, |
5dfca53f | 7419 | 24 + data_len, |
b106173a | 7420 | &drv->send_action_cookie, |
2d3943ce | 7421 | no_cck, 0, 1, NULL, 0); |
58f6fbe0 | 7422 | |
f8bf1421 | 7423 | os_free(buf); |
58f6fbe0 JM |
7424 | return ret; |
7425 | } | |
7426 | ||
7427 | ||
759a8a3a | 7428 | static void nl80211_frame_wait_cancel(struct i802_bss *bss, u64 cookie) |
5dfca53f | 7429 | { |
5dfca53f JB |
7430 | struct wpa_driver_nl80211_data *drv = bss->drv; |
7431 | struct nl_msg *msg; | |
7432 | int ret; | |
7433 | ||
316a9e4d | 7434 | wpa_printf(MSG_DEBUG, "nl80211: Cancel TX frame wait: cookie=0x%llx", |
759a8a3a | 7435 | (long long unsigned int) cookie); |
56f77852 | 7436 | if (!(msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_FRAME_WAIT_CANCEL)) || |
759a8a3a | 7437 | nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie)) { |
a862e4a3 JM |
7438 | nlmsg_free(msg); |
7439 | return; | |
7440 | } | |
5dfca53f JB |
7441 | |
7442 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); | |
5dfca53f JB |
7443 | if (ret) |
7444 | wpa_printf(MSG_DEBUG, "nl80211: wait cancel failed: ret=%d " | |
7445 | "(%s)", ret, strerror(-ret)); | |
5dfca53f JB |
7446 | } |
7447 | ||
7448 | ||
759a8a3a JM |
7449 | static void wpa_driver_nl80211_send_action_cancel_wait(void *priv) |
7450 | { | |
7451 | struct i802_bss *bss = priv; | |
7452 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
7453 | unsigned int i; | |
7454 | u64 cookie; | |
7455 | ||
7456 | /* Cancel the last pending TX cookie */ | |
7457 | nl80211_frame_wait_cancel(bss, drv->send_action_cookie); | |
7458 | ||
7459 | /* | |
7460 | * Cancel the other pending TX cookies, if any. This is needed since | |
7461 | * the driver may keep a list of all pending offchannel TX operations | |
7462 | * and free up the radio only once they have expired or cancelled. | |
7463 | */ | |
7464 | for (i = drv->num_send_action_cookies; i > 0; i--) { | |
7465 | cookie = drv->send_action_cookies[i - 1]; | |
7466 | if (cookie != drv->send_action_cookie) | |
7467 | nl80211_frame_wait_cancel(bss, cookie); | |
7468 | } | |
7469 | drv->num_send_action_cookies = 0; | |
7470 | } | |
7471 | ||
7472 | ||
55777702 JM |
7473 | static int wpa_driver_nl80211_remain_on_channel(void *priv, unsigned int freq, |
7474 | unsigned int duration) | |
7475 | { | |
a2e40bb6 FF |
7476 | struct i802_bss *bss = priv; |
7477 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
55777702 JM |
7478 | struct nl_msg *msg; |
7479 | int ret; | |
7480 | u64 cookie; | |
7481 | ||
56f77852 | 7482 | if (!(msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_REMAIN_ON_CHANNEL)) || |
a862e4a3 JM |
7483 | nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq) || |
7484 | nla_put_u32(msg, NL80211_ATTR_DURATION, duration)) { | |
7485 | nlmsg_free(msg); | |
7486 | return -1; | |
7487 | } | |
55777702 JM |
7488 | |
7489 | cookie = 0; | |
7490 | ret = send_and_recv_msgs(drv, msg, cookie_handler, &cookie); | |
7491 | if (ret == 0) { | |
7492 | wpa_printf(MSG_DEBUG, "nl80211: Remain-on-channel cookie " | |
7493 | "0x%llx for freq=%u MHz duration=%u", | |
7494 | (long long unsigned int) cookie, freq, duration); | |
7495 | drv->remain_on_chan_cookie = cookie; | |
531f0331 | 7496 | drv->pending_remain_on_chan = 1; |
55777702 JM |
7497 | return 0; |
7498 | } | |
7499 | wpa_printf(MSG_DEBUG, "nl80211: Failed to request remain-on-channel " | |
15ed5535 JM |
7500 | "(freq=%d duration=%u): %d (%s)", |
7501 | freq, duration, ret, strerror(-ret)); | |
55777702 JM |
7502 | return -1; |
7503 | } | |
7504 | ||
7505 | ||
7506 | static int wpa_driver_nl80211_cancel_remain_on_channel(void *priv) | |
7507 | { | |
a2e40bb6 FF |
7508 | struct i802_bss *bss = priv; |
7509 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
55777702 JM |
7510 | struct nl_msg *msg; |
7511 | int ret; | |
7512 | ||
7513 | if (!drv->pending_remain_on_chan) { | |
7514 | wpa_printf(MSG_DEBUG, "nl80211: No pending remain-on-channel " | |
7515 | "to cancel"); | |
7516 | return -1; | |
7517 | } | |
7518 | ||
7519 | wpa_printf(MSG_DEBUG, "nl80211: Cancel remain-on-channel with cookie " | |
7520 | "0x%llx", | |
7521 | (long long unsigned int) drv->remain_on_chan_cookie); | |
7522 | ||
56f77852 JM |
7523 | msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL); |
7524 | if (!msg || | |
a862e4a3 JM |
7525 | nla_put_u64(msg, NL80211_ATTR_COOKIE, drv->remain_on_chan_cookie)) { |
7526 | nlmsg_free(msg); | |
7527 | return -1; | |
7528 | } | |
55777702 JM |
7529 | |
7530 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); | |
7531 | if (ret == 0) | |
7532 | return 0; | |
7533 | wpa_printf(MSG_DEBUG, "nl80211: Failed to cancel remain-on-channel: " | |
7534 | "%d (%s)", ret, strerror(-ret)); | |
55777702 JM |
7535 | return -1; |
7536 | } | |
7537 | ||
7538 | ||
9ebce9c5 | 7539 | static int wpa_driver_nl80211_probe_req_report(struct i802_bss *bss, int report) |
504e905c | 7540 | { |
a2e40bb6 | 7541 | struct wpa_driver_nl80211_data *drv = bss->drv; |
504e905c | 7542 | |
5582a5d1 | 7543 | if (!report) { |
0d891981 | 7544 | if (bss->nl_preq && drv->device_ap_sme && |
b8d87ed2 AP |
7545 | is_ap_interface(drv->nlmode) && !bss->in_deinit && |
7546 | !bss->static_ap) { | |
0d891981 JM |
7547 | /* |
7548 | * Do not disable Probe Request reporting that was | |
7549 | * enabled in nl80211_setup_ap(). | |
7550 | */ | |
7551 | wpa_printf(MSG_DEBUG, "nl80211: Skip disabling of " | |
7552 | "Probe Request reporting nl_preq=%p while " | |
7553 | "in AP mode", bss->nl_preq); | |
7554 | } else if (bss->nl_preq) { | |
36488c05 JM |
7555 | wpa_printf(MSG_DEBUG, "nl80211: Disable Probe Request " |
7556 | "reporting nl_preq=%p", bss->nl_preq); | |
40a68f33 | 7557 | nl80211_destroy_eloop_handle(&bss->nl_preq, 0); |
5582a5d1 JB |
7558 | } |
7559 | return 0; | |
7560 | } | |
7561 | ||
481234cf | 7562 | if (bss->nl_preq) { |
5582a5d1 | 7563 | wpa_printf(MSG_DEBUG, "nl80211: Probe Request reporting " |
36488c05 | 7564 | "already on! nl_preq=%p", bss->nl_preq); |
5582a5d1 JB |
7565 | return 0; |
7566 | } | |
7567 | ||
481234cf JM |
7568 | bss->nl_preq = nl_create_handle(drv->global->nl_cb, "preq"); |
7569 | if (bss->nl_preq == NULL) | |
5582a5d1 | 7570 | return -1; |
36488c05 JM |
7571 | wpa_printf(MSG_DEBUG, "nl80211: Enable Probe Request " |
7572 | "reporting nl_preq=%p", bss->nl_preq); | |
5582a5d1 | 7573 | |
481234cf | 7574 | if (nl80211_register_frame(bss, bss->nl_preq, |
5582a5d1 JB |
7575 | (WLAN_FC_TYPE_MGMT << 2) | |
7576 | (WLAN_FC_STYPE_PROBE_REQ << 4), | |
a92dfde8 JB |
7577 | NULL, 0) < 0) |
7578 | goto out_err; | |
5582a5d1 | 7579 | |
5f65e9f7 JB |
7580 | nl80211_register_eloop_read(&bss->nl_preq, |
7581 | wpa_driver_nl80211_event_receive, | |
40a68f33 | 7582 | bss->nl_cb, 0); |
5582a5d1 | 7583 | |
504e905c | 7584 | return 0; |
5582a5d1 | 7585 | |
a92dfde8 | 7586 | out_err: |
221a59c9 | 7587 | nl_destroy_handles(&bss->nl_preq); |
5582a5d1 | 7588 | return -1; |
504e905c JM |
7589 | } |
7590 | ||
7591 | ||
4e5cb1a3 JM |
7592 | static int nl80211_disable_11b_rates(struct wpa_driver_nl80211_data *drv, |
7593 | int ifindex, int disabled) | |
7594 | { | |
7595 | struct nl_msg *msg; | |
7596 | struct nlattr *bands, *band; | |
7597 | int ret; | |
7598 | ||
3e208481 JM |
7599 | wpa_printf(MSG_DEBUG, |
7600 | "nl80211: NL80211_CMD_SET_TX_BITRATE_MASK (ifindex=%d %s)", | |
7601 | ifindex, disabled ? "NL80211_TXRATE_LEGACY=OFDM-only" : | |
7602 | "no NL80211_TXRATE_LEGACY constraint"); | |
7603 | ||
95376e1a JM |
7604 | msg = nl80211_ifindex_msg(drv, ifindex, 0, |
7605 | NL80211_CMD_SET_TX_BITRATE_MASK); | |
4e5cb1a3 JM |
7606 | if (!msg) |
7607 | return -1; | |
7608 | ||
4e5cb1a3 JM |
7609 | bands = nla_nest_start(msg, NL80211_ATTR_TX_RATES); |
7610 | if (!bands) | |
a862e4a3 | 7611 | goto fail; |
4e5cb1a3 JM |
7612 | |
7613 | /* | |
7614 | * Disable 2 GHz rates 1, 2, 5.5, 11 Mbps by masking out everything | |
7615 | * else apart from 6, 9, 12, 18, 24, 36, 48, 54 Mbps from non-MCS | |
7616 | * rates. All 5 GHz rates are left enabled. | |
7617 | */ | |
7618 | band = nla_nest_start(msg, NL80211_BAND_2GHZ); | |
a862e4a3 JM |
7619 | if (!band || |
7620 | (disabled && nla_put(msg, NL80211_TXRATE_LEGACY, 8, | |
7621 | "\x0c\x12\x18\x24\x30\x48\x60\x6c"))) | |
7622 | goto fail; | |
4e5cb1a3 JM |
7623 | nla_nest_end(msg, band); |
7624 | ||
7625 | nla_nest_end(msg, bands); | |
7626 | ||
7627 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); | |
4e5cb1a3 JM |
7628 | if (ret) { |
7629 | wpa_printf(MSG_DEBUG, "nl80211: Set TX rates failed: ret=%d " | |
7630 | "(%s)", ret, strerror(-ret)); | |
1d0c6fb1 JM |
7631 | } else |
7632 | drv->disabled_11b_rates = disabled; | |
4e5cb1a3 JM |
7633 | |
7634 | return ret; | |
7635 | ||
a862e4a3 | 7636 | fail: |
4e5cb1a3 JM |
7637 | nlmsg_free(msg); |
7638 | return -1; | |
7639 | } | |
7640 | ||
7641 | ||
af473088 JM |
7642 | static int wpa_driver_nl80211_deinit_ap(void *priv) |
7643 | { | |
a2e40bb6 FF |
7644 | struct i802_bss *bss = priv; |
7645 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
b1f625e0 | 7646 | if (!is_ap_interface(drv->nlmode)) |
af473088 | 7647 | return -1; |
a70cd0db | 7648 | wpa_driver_nl80211_del_beacon(bss); |
9bc5cfa3 | 7649 | bss->beacon_set = 0; |
60b13c20 IP |
7650 | |
7651 | /* | |
7652 | * If the P2P GO interface was dynamically added, then it is | |
7653 | * possible that the interface change to station is not possible. | |
7654 | */ | |
7655 | if (drv->nlmode == NL80211_IFTYPE_P2P_GO && bss->if_dynamic) | |
7656 | return 0; | |
7657 | ||
b1f625e0 | 7658 | return wpa_driver_nl80211_set_mode(priv, NL80211_IFTYPE_STATION); |
af473088 JM |
7659 | } |
7660 | ||
7661 | ||
695c7038 SW |
7662 | static int wpa_driver_nl80211_stop_ap(void *priv) |
7663 | { | |
7664 | struct i802_bss *bss = priv; | |
7665 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
7666 | if (!is_ap_interface(drv->nlmode)) | |
7667 | return -1; | |
a70cd0db | 7668 | wpa_driver_nl80211_del_beacon(bss); |
695c7038 SW |
7669 | bss->beacon_set = 0; |
7670 | return 0; | |
7671 | } | |
7672 | ||
7673 | ||
3c29244e EP |
7674 | static int wpa_driver_nl80211_deinit_p2p_cli(void *priv) |
7675 | { | |
7676 | struct i802_bss *bss = priv; | |
7677 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
7678 | if (drv->nlmode != NL80211_IFTYPE_P2P_CLIENT) | |
7679 | return -1; | |
60b13c20 IP |
7680 | |
7681 | /* | |
7682 | * If the P2P Client interface was dynamically added, then it is | |
7683 | * possible that the interface change to station is not possible. | |
7684 | */ | |
7685 | if (bss->if_dynamic) | |
7686 | return 0; | |
7687 | ||
3c29244e EP |
7688 | return wpa_driver_nl80211_set_mode(priv, NL80211_IFTYPE_STATION); |
7689 | } | |
7690 | ||
7691 | ||
207ef3fb JM |
7692 | static void wpa_driver_nl80211_resume(void *priv) |
7693 | { | |
a2e40bb6 | 7694 | struct i802_bss *bss = priv; |
e8dc205f | 7695 | enum nl80211_iftype nlmode = nl80211_get_ifmode(bss); |
91724d6f AS |
7696 | |
7697 | if (i802_set_iface_flags(bss, 1)) | |
7698 | wpa_printf(MSG_DEBUG, "nl80211: Failed to set interface up on resume event"); | |
e8dc205f AO |
7699 | |
7700 | if (is_p2p_net_interface(nlmode)) | |
7701 | nl80211_disable_11b_rates(bss->drv, bss->drv->ifindex, 1); | |
207ef3fb JM |
7702 | } |
7703 | ||
7704 | ||
b625473c JM |
7705 | static int nl80211_signal_monitor(void *priv, int threshold, int hysteresis) |
7706 | { | |
7707 | struct i802_bss *bss = priv; | |
7708 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
8970bae8 JB |
7709 | struct nl_msg *msg; |
7710 | struct nlattr *cqm; | |
b625473c JM |
7711 | |
7712 | wpa_printf(MSG_DEBUG, "nl80211: Signal monitor threshold=%d " | |
7713 | "hysteresis=%d", threshold, hysteresis); | |
7714 | ||
13f83980 | 7715 | if (!(msg = nl80211_bss_msg(bss, 0, NL80211_CMD_SET_CQM)) || |
a862e4a3 JM |
7716 | !(cqm = nla_nest_start(msg, NL80211_ATTR_CQM)) || |
7717 | nla_put_u32(msg, NL80211_ATTR_CQM_RSSI_THOLD, threshold) || | |
7718 | nla_put_u32(msg, NL80211_ATTR_CQM_RSSI_HYST, hysteresis)) { | |
7719 | nlmsg_free(msg); | |
7720 | return -1; | |
7721 | } | |
8970bae8 | 7722 | nla_nest_end(msg, cqm); |
21270bb4 | 7723 | |
a862e4a3 | 7724 | return send_and_recv_msgs(drv, msg, NULL, NULL); |
b625473c JM |
7725 | } |
7726 | ||
7727 | ||
2cc8d8f4 AO |
7728 | static int get_channel_width(struct nl_msg *msg, void *arg) |
7729 | { | |
7730 | struct nlattr *tb[NL80211_ATTR_MAX + 1]; | |
7731 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); | |
7732 | struct wpa_signal_info *sig_change = arg; | |
7733 | ||
7734 | nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), | |
7735 | genlmsg_attrlen(gnlh, 0), NULL); | |
7736 | ||
7737 | sig_change->center_frq1 = -1; | |
7738 | sig_change->center_frq2 = -1; | |
7739 | sig_change->chanwidth = CHAN_WIDTH_UNKNOWN; | |
7740 | ||
7741 | if (tb[NL80211_ATTR_CHANNEL_WIDTH]) { | |
7742 | sig_change->chanwidth = convert2width( | |
7743 | nla_get_u32(tb[NL80211_ATTR_CHANNEL_WIDTH])); | |
7744 | if (tb[NL80211_ATTR_CENTER_FREQ1]) | |
7745 | sig_change->center_frq1 = | |
7746 | nla_get_u32(tb[NL80211_ATTR_CENTER_FREQ1]); | |
7747 | if (tb[NL80211_ATTR_CENTER_FREQ2]) | |
7748 | sig_change->center_frq2 = | |
7749 | nla_get_u32(tb[NL80211_ATTR_CENTER_FREQ2]); | |
7750 | } | |
7751 | ||
7752 | return NL_SKIP; | |
7753 | } | |
7754 | ||
7755 | ||
7756 | static int nl80211_get_channel_width(struct wpa_driver_nl80211_data *drv, | |
7757 | struct wpa_signal_info *sig) | |
7758 | { | |
7759 | struct nl_msg *msg; | |
7760 | ||
9725b784 | 7761 | msg = nl80211_drv_msg(drv, 0, NL80211_CMD_GET_INTERFACE); |
2cc8d8f4 | 7762 | return send_and_recv_msgs(drv, msg, get_channel_width, sig); |
2cc8d8f4 AO |
7763 | } |
7764 | ||
7765 | ||
1c5c7273 PS |
7766 | static int nl80211_signal_poll(void *priv, struct wpa_signal_info *si) |
7767 | { | |
7768 | struct i802_bss *bss = priv; | |
7769 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
7770 | int res; | |
7771 | ||
7772 | os_memset(si, 0, sizeof(*si)); | |
7773 | res = nl80211_get_link_signal(drv, si); | |
1d6955e6 JM |
7774 | if (res) { |
7775 | if (drv->nlmode != NL80211_IFTYPE_ADHOC && | |
7776 | drv->nlmode != NL80211_IFTYPE_MESH_POINT) | |
7777 | return res; | |
7778 | si->current_signal = 0; | |
7779 | } | |
1c5c7273 | 7780 | |
2cc8d8f4 AO |
7781 | res = nl80211_get_channel_width(drv, si); |
7782 | if (res != 0) | |
7783 | return res; | |
7784 | ||
1c5c7273 PS |
7785 | return nl80211_get_link_noise(drv, si); |
7786 | } | |
7787 | ||
7788 | ||
b91ab76e JM |
7789 | static int nl80211_send_frame(void *priv, const u8 *data, size_t data_len, |
7790 | int encrypt) | |
7791 | { | |
7792 | struct i802_bss *bss = priv; | |
55231068 | 7793 | return wpa_driver_nl80211_send_frame(bss, data, data_len, encrypt, 0, |
2d3943ce | 7794 | 0, 0, 0, 0, NULL, 0); |
b91ab76e JM |
7795 | } |
7796 | ||
7797 | ||
c55f774d JM |
7798 | static int nl80211_set_param(void *priv, const char *param) |
7799 | { | |
ef24ad3e JM |
7800 | struct i802_bss *bss = priv; |
7801 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
7802 | ||
c55f774d JM |
7803 | if (param == NULL) |
7804 | return 0; | |
99a94f55 | 7805 | wpa_printf(MSG_DEBUG, "nl80211: driver param='%s'", param); |
c55f774d JM |
7806 | |
7807 | #ifdef CONFIG_P2P | |
7808 | if (os_strstr(param, "use_p2p_group_interface=1")) { | |
7809 | wpa_printf(MSG_DEBUG, "nl80211: Use separate P2P group " | |
7810 | "interface"); | |
7811 | drv->capa.flags |= WPA_DRIVER_FLAGS_P2P_CONCURRENT; | |
7812 | drv->capa.flags |= WPA_DRIVER_FLAGS_P2P_MGMT_AND_NON_P2P; | |
7813 | } | |
7814 | #endif /* CONFIG_P2P */ | |
7815 | ||
ef24ad3e | 7816 | if (os_strstr(param, "use_monitor=1")) |
327b01d3 | 7817 | drv->use_monitor = 1; |
327b01d3 JM |
7818 | |
7819 | if (os_strstr(param, "force_connect_cmd=1")) { | |
327b01d3 | 7820 | drv->capa.flags &= ~WPA_DRIVER_FLAGS_SME; |
b497a212 | 7821 | drv->force_connect_cmd = 1; |
327b01d3 JM |
7822 | } |
7823 | ||
ef24ad3e | 7824 | if (os_strstr(param, "force_bss_selection=1")) |
4d584d8c | 7825 | drv->capa.flags |= WPA_DRIVER_FLAGS_BSS_SELECTION; |
4d584d8c | 7826 | |
64abb725 | 7827 | if (os_strstr(param, "no_offchannel_tx=1")) { |
64abb725 JM |
7828 | drv->capa.flags &= ~WPA_DRIVER_FLAGS_OFFCHANNEL_TX; |
7829 | drv->test_use_roc_tx = 1; | |
7830 | } | |
7831 | ||
c55f774d JM |
7832 | return 0; |
7833 | } | |
7834 | ||
7835 | ||
45e3fc72 | 7836 | static void * nl80211_global_init(void *ctx) |
f2ed8023 JM |
7837 | { |
7838 | struct nl80211_global *global; | |
36d84860 BG |
7839 | struct netlink_config *cfg; |
7840 | ||
f2ed8023 JM |
7841 | global = os_zalloc(sizeof(*global)); |
7842 | if (global == NULL) | |
7843 | return NULL; | |
45e3fc72 | 7844 | global->ctx = ctx; |
c81eff1a | 7845 | global->ioctl_sock = -1; |
f2ed8023 | 7846 | dl_list_init(&global->interfaces); |
ff6a158b | 7847 | global->if_add_ifindex = -1; |
36d84860 BG |
7848 | |
7849 | cfg = os_zalloc(sizeof(*cfg)); | |
7850 | if (cfg == NULL) | |
7851 | goto err; | |
7852 | ||
7853 | cfg->ctx = global; | |
7854 | cfg->newlink_cb = wpa_driver_nl80211_event_rtm_newlink; | |
7855 | cfg->dellink_cb = wpa_driver_nl80211_event_rtm_dellink; | |
7856 | global->netlink = netlink_init(cfg); | |
7857 | if (global->netlink == NULL) { | |
7858 | os_free(cfg); | |
7859 | goto err; | |
7860 | } | |
7861 | ||
2a7b66f5 BG |
7862 | if (wpa_driver_nl80211_init_nl_global(global) < 0) |
7863 | goto err; | |
7864 | ||
c81eff1a BG |
7865 | global->ioctl_sock = socket(PF_INET, SOCK_DGRAM, 0); |
7866 | if (global->ioctl_sock < 0) { | |
7ac3616d JM |
7867 | wpa_printf(MSG_ERROR, "nl80211: socket(PF_INET,SOCK_DGRAM) failed: %s", |
7868 | strerror(errno)); | |
c81eff1a BG |
7869 | goto err; |
7870 | } | |
7871 | ||
f2ed8023 | 7872 | return global; |
36d84860 BG |
7873 | |
7874 | err: | |
7875 | nl80211_global_deinit(global); | |
7876 | return NULL; | |
f2ed8023 JM |
7877 | } |
7878 | ||
7879 | ||
7880 | static void nl80211_global_deinit(void *priv) | |
7881 | { | |
7882 | struct nl80211_global *global = priv; | |
7883 | if (global == NULL) | |
7884 | return; | |
7885 | if (!dl_list_empty(&global->interfaces)) { | |
7886 | wpa_printf(MSG_ERROR, "nl80211: %u interface(s) remain at " | |
7887 | "nl80211_global_deinit", | |
7888 | dl_list_len(&global->interfaces)); | |
7889 | } | |
36d84860 BG |
7890 | |
7891 | if (global->netlink) | |
7892 | netlink_deinit(global->netlink); | |
7893 | ||
276e2d67 BG |
7894 | nl_destroy_handles(&global->nl); |
7895 | ||
5f65e9f7 | 7896 | if (global->nl_event) |
40a68f33 | 7897 | nl80211_destroy_eloop_handle(&global->nl_event, 0); |
d6c9aab8 JB |
7898 | |
7899 | nl_cb_put(global->nl_cb); | |
2a7b66f5 | 7900 | |
c81eff1a BG |
7901 | if (global->ioctl_sock >= 0) |
7902 | close(global->ioctl_sock); | |
7903 | ||
f2ed8023 JM |
7904 | os_free(global); |
7905 | } | |
7906 | ||
7907 | ||
6859f1cb BG |
7908 | static const char * nl80211_get_radio_name(void *priv) |
7909 | { | |
7910 | struct i802_bss *bss = priv; | |
7911 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
7912 | return drv->phyname; | |
7913 | } | |
7914 | ||
7915 | ||
061a3d3d VK |
7916 | static int nl80211_pmkid(struct i802_bss *bss, int cmd, |
7917 | struct wpa_pmkid_params *params) | |
a6efc65d JM |
7918 | { |
7919 | struct nl_msg *msg; | |
0887215d | 7920 | const size_t PMK_MAX_LEN = 48; /* current cfg80211 limit */ |
a6efc65d | 7921 | |
13f83980 | 7922 | if (!(msg = nl80211_bss_msg(bss, 0, cmd)) || |
061a3d3d VK |
7923 | (params->pmkid && |
7924 | nla_put(msg, NL80211_ATTR_PMKID, 16, params->pmkid)) || | |
7925 | (params->bssid && | |
7926 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, params->bssid)) || | |
7927 | (params->ssid_len && | |
7928 | nla_put(msg, NL80211_ATTR_SSID, params->ssid_len, params->ssid)) || | |
7929 | (params->fils_cache_id && | |
7930 | nla_put(msg, NL80211_ATTR_FILS_CACHE_ID, 2, | |
7931 | params->fils_cache_id)) || | |
c6ec9759 | 7932 | (cmd != NL80211_CMD_DEL_PMKSA && |
7933 | params->pmk_len && params->pmk_len <= PMK_MAX_LEN && | |
061a3d3d | 7934 | nla_put(msg, NL80211_ATTR_PMK, params->pmk_len, params->pmk))) { |
6110753b | 7935 | nl80211_nlmsg_clear(msg); |
a862e4a3 JM |
7936 | nlmsg_free(msg); |
7937 | return -ENOBUFS; | |
7938 | } | |
a6efc65d | 7939 | |
6110753b | 7940 | return send_and_recv_msgs(bss->drv, msg, NULL, (void *) -1); |
a6efc65d JM |
7941 | } |
7942 | ||
7943 | ||
6fbb5414 | 7944 | static int nl80211_add_pmkid(void *priv, struct wpa_pmkid_params *params) |
a6efc65d JM |
7945 | { |
7946 | struct i802_bss *bss = priv; | |
e7f6e6ee | 7947 | int ret; |
061a3d3d VK |
7948 | |
7949 | if (params->bssid) | |
7950 | wpa_printf(MSG_DEBUG, "nl80211: Add PMKID for " MACSTR, | |
7951 | MAC2STR(params->bssid)); | |
7952 | else if (params->fils_cache_id && params->ssid_len) { | |
7953 | wpa_printf(MSG_DEBUG, | |
7954 | "nl80211: Add PMKSA for cache id %02x%02x SSID %s", | |
7955 | params->fils_cache_id[0], params->fils_cache_id[1], | |
7956 | wpa_ssid_txt(params->ssid, params->ssid_len)); | |
7957 | } | |
7958 | ||
e7f6e6ee JM |
7959 | ret = nl80211_pmkid(bss, NL80211_CMD_SET_PMKSA, params); |
7960 | if (ret < 0) { | |
7961 | wpa_printf(MSG_DEBUG, | |
7962 | "nl80211: NL80211_CMD_SET_PMKSA failed: %d (%s)", | |
7963 | ret, strerror(-ret)); | |
7964 | } | |
7965 | ||
7966 | return ret; | |
a6efc65d JM |
7967 | } |
7968 | ||
7969 | ||
6fbb5414 | 7970 | static int nl80211_remove_pmkid(void *priv, struct wpa_pmkid_params *params) |
a6efc65d JM |
7971 | { |
7972 | struct i802_bss *bss = priv; | |
e7f6e6ee | 7973 | int ret; |
061a3d3d VK |
7974 | |
7975 | if (params->bssid) | |
7976 | wpa_printf(MSG_DEBUG, "nl80211: Delete PMKID for " MACSTR, | |
7977 | MAC2STR(params->bssid)); | |
7978 | else if (params->fils_cache_id && params->ssid_len) { | |
7979 | wpa_printf(MSG_DEBUG, | |
7980 | "nl80211: Delete PMKSA for cache id %02x%02x SSID %s", | |
7981 | params->fils_cache_id[0], params->fils_cache_id[1], | |
7982 | wpa_ssid_txt(params->ssid, params->ssid_len)); | |
7983 | } | |
7984 | ||
e7f6e6ee JM |
7985 | ret = nl80211_pmkid(bss, NL80211_CMD_DEL_PMKSA, params); |
7986 | if (ret < 0) { | |
7987 | wpa_printf(MSG_DEBUG, | |
7988 | "nl80211: NL80211_CMD_DEL_PMKSA failed: %d (%s)", | |
7989 | ret, strerror(-ret)); | |
7990 | } | |
7991 | ||
7992 | return ret; | |
a6efc65d JM |
7993 | } |
7994 | ||
7995 | ||
7996 | static int nl80211_flush_pmkid(void *priv) | |
7997 | { | |
7998 | struct i802_bss *bss = priv; | |
061a3d3d VK |
7999 | struct nl_msg *msg; |
8000 | ||
a6efc65d | 8001 | wpa_printf(MSG_DEBUG, "nl80211: Flush PMKIDs"); |
061a3d3d VK |
8002 | msg = nl80211_bss_msg(bss, 0, NL80211_CMD_FLUSH_PMKSA); |
8003 | if (!msg) | |
8004 | return -ENOBUFS; | |
8005 | return send_and_recv_msgs(bss->drv, msg, NULL, NULL); | |
a6efc65d JM |
8006 | } |
8007 | ||
8008 | ||
0185007c MK |
8009 | static void clean_survey_results(struct survey_results *survey_results) |
8010 | { | |
8011 | struct freq_survey *survey, *tmp; | |
8012 | ||
8013 | if (dl_list_empty(&survey_results->survey_list)) | |
8014 | return; | |
8015 | ||
8016 | dl_list_for_each_safe(survey, tmp, &survey_results->survey_list, | |
8017 | struct freq_survey, list) { | |
8018 | dl_list_del(&survey->list); | |
8019 | os_free(survey); | |
8020 | } | |
8021 | } | |
8022 | ||
8023 | ||
8024 | static void add_survey(struct nlattr **sinfo, u32 ifidx, | |
8025 | struct dl_list *survey_list) | |
8026 | { | |
8027 | struct freq_survey *survey; | |
8028 | ||
8029 | survey = os_zalloc(sizeof(struct freq_survey)); | |
8030 | if (!survey) | |
8031 | return; | |
8032 | ||
8033 | survey->ifidx = ifidx; | |
8034 | survey->freq = nla_get_u32(sinfo[NL80211_SURVEY_INFO_FREQUENCY]); | |
8035 | survey->filled = 0; | |
8036 | ||
8037 | if (sinfo[NL80211_SURVEY_INFO_NOISE]) { | |
8038 | survey->nf = (int8_t) | |
8039 | nla_get_u8(sinfo[NL80211_SURVEY_INFO_NOISE]); | |
8040 | survey->filled |= SURVEY_HAS_NF; | |
8041 | } | |
8042 | ||
8043 | if (sinfo[NL80211_SURVEY_INFO_CHANNEL_TIME]) { | |
8044 | survey->channel_time = | |
8045 | nla_get_u64(sinfo[NL80211_SURVEY_INFO_CHANNEL_TIME]); | |
8046 | survey->filled |= SURVEY_HAS_CHAN_TIME; | |
8047 | } | |
8048 | ||
8049 | if (sinfo[NL80211_SURVEY_INFO_CHANNEL_TIME_BUSY]) { | |
8050 | survey->channel_time_busy = | |
8051 | nla_get_u64(sinfo[NL80211_SURVEY_INFO_CHANNEL_TIME_BUSY]); | |
8052 | survey->filled |= SURVEY_HAS_CHAN_TIME_BUSY; | |
8053 | } | |
8054 | ||
8055 | if (sinfo[NL80211_SURVEY_INFO_CHANNEL_TIME_RX]) { | |
8056 | survey->channel_time_rx = | |
8057 | nla_get_u64(sinfo[NL80211_SURVEY_INFO_CHANNEL_TIME_RX]); | |
8058 | survey->filled |= SURVEY_HAS_CHAN_TIME_RX; | |
8059 | } | |
8060 | ||
8061 | if (sinfo[NL80211_SURVEY_INFO_CHANNEL_TIME_TX]) { | |
8062 | survey->channel_time_tx = | |
8063 | nla_get_u64(sinfo[NL80211_SURVEY_INFO_CHANNEL_TIME_TX]); | |
8064 | survey->filled |= SURVEY_HAS_CHAN_TIME_TX; | |
8065 | } | |
8066 | ||
8067 | 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)", | |
8068 | survey->freq, | |
8069 | survey->nf, | |
8070 | (unsigned long int) survey->channel_time, | |
8071 | (unsigned long int) survey->channel_time_busy, | |
8072 | (unsigned long int) survey->channel_time_tx, | |
8073 | (unsigned long int) survey->channel_time_rx, | |
8074 | survey->filled); | |
8075 | ||
8076 | dl_list_add_tail(survey_list, &survey->list); | |
8077 | } | |
8078 | ||
8079 | ||
8080 | static int check_survey_ok(struct nlattr **sinfo, u32 surveyed_freq, | |
8081 | unsigned int freq_filter) | |
8082 | { | |
8083 | if (!freq_filter) | |
8084 | return 1; | |
8085 | ||
8086 | return freq_filter == surveyed_freq; | |
8087 | } | |
8088 | ||
8089 | ||
8090 | static int survey_handler(struct nl_msg *msg, void *arg) | |
8091 | { | |
8092 | struct nlattr *tb[NL80211_ATTR_MAX + 1]; | |
8093 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); | |
8094 | struct nlattr *sinfo[NL80211_SURVEY_INFO_MAX + 1]; | |
8095 | struct survey_results *survey_results; | |
8096 | u32 surveyed_freq = 0; | |
8097 | u32 ifidx; | |
8098 | ||
8099 | static struct nla_policy survey_policy[NL80211_SURVEY_INFO_MAX + 1] = { | |
8100 | [NL80211_SURVEY_INFO_FREQUENCY] = { .type = NLA_U32 }, | |
8101 | [NL80211_SURVEY_INFO_NOISE] = { .type = NLA_U8 }, | |
8102 | }; | |
8103 | ||
8104 | survey_results = (struct survey_results *) arg; | |
8105 | ||
8106 | nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), | |
8107 | genlmsg_attrlen(gnlh, 0), NULL); | |
8108 | ||
e28f39b7 SJ |
8109 | if (!tb[NL80211_ATTR_IFINDEX]) |
8110 | return NL_SKIP; | |
8111 | ||
0185007c MK |
8112 | ifidx = nla_get_u32(tb[NL80211_ATTR_IFINDEX]); |
8113 | ||
8114 | if (!tb[NL80211_ATTR_SURVEY_INFO]) | |
8115 | return NL_SKIP; | |
8116 | ||
8117 | if (nla_parse_nested(sinfo, NL80211_SURVEY_INFO_MAX, | |
8118 | tb[NL80211_ATTR_SURVEY_INFO], | |
8119 | survey_policy)) | |
8120 | return NL_SKIP; | |
8121 | ||
8122 | if (!sinfo[NL80211_SURVEY_INFO_FREQUENCY]) { | |
8123 | wpa_printf(MSG_ERROR, "nl80211: Invalid survey data"); | |
8124 | return NL_SKIP; | |
8125 | } | |
8126 | ||
8127 | surveyed_freq = nla_get_u32(sinfo[NL80211_SURVEY_INFO_FREQUENCY]); | |
8128 | ||
8129 | if (!check_survey_ok(sinfo, surveyed_freq, | |
8130 | survey_results->freq_filter)) | |
8131 | return NL_SKIP; | |
8132 | ||
8133 | if (survey_results->freq_filter && | |
8134 | survey_results->freq_filter != surveyed_freq) { | |
8135 | wpa_printf(MSG_EXCESSIVE, "nl80211: Ignoring survey data for freq %d MHz", | |
8136 | surveyed_freq); | |
8137 | return NL_SKIP; | |
8138 | } | |
8139 | ||
8140 | add_survey(sinfo, ifidx, &survey_results->survey_list); | |
8141 | ||
8142 | return NL_SKIP; | |
8143 | } | |
8144 | ||
8145 | ||
8146 | static int wpa_driver_nl80211_get_survey(void *priv, unsigned int freq) | |
8147 | { | |
8148 | struct i802_bss *bss = priv; | |
8149 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
8150 | struct nl_msg *msg; | |
9725b784 | 8151 | int err; |
0185007c MK |
8152 | union wpa_event_data data; |
8153 | struct survey_results *survey_results; | |
8154 | ||
8155 | os_memset(&data, 0, sizeof(data)); | |
8156 | survey_results = &data.survey_results; | |
8157 | ||
8158 | dl_list_init(&survey_results->survey_list); | |
8159 | ||
9725b784 | 8160 | msg = nl80211_drv_msg(drv, NLM_F_DUMP, NL80211_CMD_GET_SURVEY); |
0185007c | 8161 | if (!msg) |
a862e4a3 | 8162 | return -ENOBUFS; |
0185007c | 8163 | |
0185007c MK |
8164 | if (freq) |
8165 | data.survey_results.freq_filter = freq; | |
8166 | ||
8167 | do { | |
8168 | wpa_printf(MSG_DEBUG, "nl80211: Fetch survey data"); | |
8169 | err = send_and_recv_msgs(drv, msg, survey_handler, | |
8170 | survey_results); | |
8171 | } while (err > 0); | |
8172 | ||
a862e4a3 | 8173 | if (err) |
0185007c | 8174 | wpa_printf(MSG_ERROR, "nl80211: Failed to process survey data"); |
a862e4a3 JM |
8175 | else |
8176 | wpa_supplicant_event(drv->ctx, EVENT_SURVEY, &data); | |
0185007c | 8177 | |
0185007c | 8178 | clean_survey_results(survey_results); |
0185007c MK |
8179 | return err; |
8180 | } | |
8181 | ||
8182 | ||
98cd3d1c JM |
8183 | static void nl80211_set_rekey_info(void *priv, const u8 *kek, size_t kek_len, |
8184 | const u8 *kck, size_t kck_len, | |
b14a210c JB |
8185 | const u8 *replay_ctr) |
8186 | { | |
8187 | struct i802_bss *bss = priv; | |
8188 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
8189 | struct nlattr *replay_nested; | |
8190 | struct nl_msg *msg; | |
64ae2447 | 8191 | int ret; |
b14a210c | 8192 | |
64ae2447 JM |
8193 | if (!drv->set_rekey_offload) |
8194 | return; | |
8195 | ||
8196 | wpa_printf(MSG_DEBUG, "nl80211: Set rekey offload"); | |
13f83980 | 8197 | if (!(msg = nl80211_bss_msg(bss, 0, NL80211_CMD_SET_REKEY_OFFLOAD)) || |
a862e4a3 | 8198 | !(replay_nested = nla_nest_start(msg, NL80211_ATTR_REKEY_DATA)) || |
98cd3d1c | 8199 | nla_put(msg, NL80211_REKEY_DATA_KEK, kek_len, kek) || |
b6ea7642 | 8200 | (kck_len && nla_put(msg, NL80211_REKEY_DATA_KCK, kck_len, kck)) || |
a862e4a3 JM |
8201 | nla_put(msg, NL80211_REKEY_DATA_REPLAY_CTR, NL80211_REPLAY_CTR_LEN, |
8202 | replay_ctr)) { | |
bbd89bfc | 8203 | nl80211_nlmsg_clear(msg); |
a862e4a3 JM |
8204 | nlmsg_free(msg); |
8205 | return; | |
8206 | } | |
b14a210c JB |
8207 | |
8208 | nla_nest_end(msg, replay_nested); | |
8209 | ||
64ae2447 JM |
8210 | ret = send_and_recv_msgs(drv, msg, NULL, (void *) -1); |
8211 | if (ret == -EOPNOTSUPP) { | |
8212 | wpa_printf(MSG_DEBUG, | |
8213 | "nl80211: Driver does not support rekey offload"); | |
8214 | drv->set_rekey_offload = 0; | |
8215 | } | |
b14a210c JB |
8216 | } |
8217 | ||
8218 | ||
39718852 JB |
8219 | static void nl80211_send_null_frame(struct i802_bss *bss, const u8 *own_addr, |
8220 | const u8 *addr, int qos) | |
bcf24348 | 8221 | { |
39718852 JB |
8222 | /* send data frame to poll STA and check whether |
8223 | * this frame is ACKed */ | |
bcf24348 JB |
8224 | struct { |
8225 | struct ieee80211_hdr hdr; | |
8226 | u16 qos_ctl; | |
8227 | } STRUCT_PACKED nulldata; | |
8228 | size_t size; | |
8229 | ||
8230 | /* Send data frame to poll STA and check whether this frame is ACKed */ | |
8231 | ||
8232 | os_memset(&nulldata, 0, sizeof(nulldata)); | |
8233 | ||
8234 | if (qos) { | |
8235 | nulldata.hdr.frame_control = | |
8236 | IEEE80211_FC(WLAN_FC_TYPE_DATA, | |
8237 | WLAN_FC_STYPE_QOS_NULL); | |
8238 | size = sizeof(nulldata); | |
8239 | } else { | |
8240 | nulldata.hdr.frame_control = | |
8241 | IEEE80211_FC(WLAN_FC_TYPE_DATA, | |
8242 | WLAN_FC_STYPE_NULLFUNC); | |
8243 | size = sizeof(struct ieee80211_hdr); | |
8244 | } | |
8245 | ||
8246 | nulldata.hdr.frame_control |= host_to_le16(WLAN_FC_FROMDS); | |
8247 | os_memcpy(nulldata.hdr.IEEE80211_DA_FROMDS, addr, ETH_ALEN); | |
8248 | os_memcpy(nulldata.hdr.IEEE80211_BSSID_FROMDS, own_addr, ETH_ALEN); | |
8249 | os_memcpy(nulldata.hdr.IEEE80211_SA_FROMDS, own_addr, ETH_ALEN); | |
8250 | ||
9ebce9c5 | 8251 | if (wpa_driver_nl80211_send_mlme(bss, (u8 *) &nulldata, size, 0, 0, 0, |
2d3943ce | 8252 | 0, 0, NULL, 0) < 0) |
bcf24348 JB |
8253 | wpa_printf(MSG_DEBUG, "nl80211_send_null_frame: Failed to " |
8254 | "send poll frame"); | |
8255 | } | |
8256 | ||
39718852 JB |
8257 | static void nl80211_poll_client(void *priv, const u8 *own_addr, const u8 *addr, |
8258 | int qos) | |
8259 | { | |
8260 | struct i802_bss *bss = priv; | |
8261 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
8262 | struct nl_msg *msg; | |
fc99fab7 | 8263 | int ret; |
39718852 JB |
8264 | |
8265 | if (!drv->poll_command_supported) { | |
8266 | nl80211_send_null_frame(bss, own_addr, addr, qos); | |
8267 | return; | |
8268 | } | |
8269 | ||
13f83980 | 8270 | if (!(msg = nl80211_bss_msg(bss, 0, NL80211_CMD_PROBE_CLIENT)) || |
a862e4a3 JM |
8271 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) { |
8272 | nlmsg_free(msg); | |
8273 | return; | |
8274 | } | |
39718852 | 8275 | |
fc99fab7 JM |
8276 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
8277 | if (ret < 0) { | |
8278 | wpa_printf(MSG_DEBUG, "nl80211: Client probe request for " | |
8279 | MACSTR " failed: ret=%d (%s)", | |
8280 | MAC2STR(addr), ret, strerror(-ret)); | |
8281 | } | |
39718852 JB |
8282 | } |
8283 | ||
bcf24348 | 8284 | |
29f338af JM |
8285 | static int nl80211_set_power_save(struct i802_bss *bss, int enabled) |
8286 | { | |
8287 | struct nl_msg *msg; | |
1baa130b | 8288 | int ret; |
29f338af | 8289 | |
13f83980 | 8290 | if (!(msg = nl80211_bss_msg(bss, 0, NL80211_CMD_SET_POWER_SAVE)) || |
a862e4a3 JM |
8291 | nla_put_u32(msg, NL80211_ATTR_PS_STATE, |
8292 | enabled ? NL80211_PS_ENABLED : NL80211_PS_DISABLED)) { | |
8293 | nlmsg_free(msg); | |
8294 | return -ENOBUFS; | |
8295 | } | |
1baa130b JM |
8296 | |
8297 | ret = send_and_recv_msgs(bss->drv, msg, NULL, NULL); | |
8298 | if (ret < 0) { | |
8299 | wpa_printf(MSG_DEBUG, | |
8300 | "nl80211: Setting PS state %s failed: %d (%s)", | |
8301 | enabled ? "enabled" : "disabled", | |
8302 | ret, strerror(-ret)); | |
8303 | } | |
8304 | return ret; | |
29f338af JM |
8305 | } |
8306 | ||
8307 | ||
8308 | static int nl80211_set_p2p_powersave(void *priv, int legacy_ps, int opp_ps, | |
8309 | int ctwindow) | |
8310 | { | |
8311 | struct i802_bss *bss = priv; | |
8312 | ||
8313 | wpa_printf(MSG_DEBUG, "nl80211: set_p2p_powersave (legacy_ps=%d " | |
8314 | "opp_ps=%d ctwindow=%d)", legacy_ps, opp_ps, ctwindow); | |
8315 | ||
0de38036 JM |
8316 | if (opp_ps != -1 || ctwindow != -1) { |
8317 | #ifdef ANDROID_P2P | |
8318 | wpa_driver_set_p2p_ps(priv, legacy_ps, opp_ps, ctwindow); | |
8319 | #else /* ANDROID_P2P */ | |
29f338af | 8320 | return -1; /* Not yet supported */ |
0de38036 JM |
8321 | #endif /* ANDROID_P2P */ |
8322 | } | |
29f338af JM |
8323 | |
8324 | if (legacy_ps == -1) | |
8325 | return 0; | |
8326 | if (legacy_ps != 0 && legacy_ps != 1) | |
8327 | return -1; /* Not yet supported */ | |
8328 | ||
8329 | return nl80211_set_power_save(bss, legacy_ps); | |
8330 | } | |
8331 | ||
8332 | ||
04e8003c JD |
8333 | static int nl80211_start_radar_detection(void *priv, |
8334 | struct hostapd_freq_params *freq) | |
f90e9c1c SW |
8335 | { |
8336 | struct i802_bss *bss = priv; | |
8337 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
8338 | struct nl_msg *msg; | |
8339 | int ret; | |
8340 | ||
04e8003c JD |
8341 | 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)", |
8342 | freq->freq, freq->ht_enabled, freq->vht_enabled, | |
8343 | freq->bandwidth, freq->center_freq1, freq->center_freq2); | |
8344 | ||
f90e9c1c SW |
8345 | if (!(drv->capa.flags & WPA_DRIVER_FLAGS_RADAR)) { |
8346 | wpa_printf(MSG_DEBUG, "nl80211: Driver does not support radar " | |
8347 | "detection"); | |
8348 | return -1; | |
8349 | } | |
8350 | ||
9725b784 | 8351 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_RADAR_DETECT)) || |
a862e4a3 JM |
8352 | nl80211_put_freq_params(msg, freq) < 0) { |
8353 | nlmsg_free(msg); | |
8354 | return -1; | |
8355 | } | |
f90e9c1c SW |
8356 | |
8357 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); | |
8358 | if (ret == 0) | |
8359 | return 0; | |
8360 | wpa_printf(MSG_DEBUG, "nl80211: Failed to start radar detection: " | |
8361 | "%d (%s)", ret, strerror(-ret)); | |
f90e9c1c SW |
8362 | return -1; |
8363 | } | |
8364 | ||
03ea1786 AN |
8365 | #ifdef CONFIG_TDLS |
8366 | ||
8367 | static int nl80211_send_tdls_mgmt(void *priv, const u8 *dst, u8 action_code, | |
8368 | u8 dialog_token, u16 status_code, | |
984dadc2 AN |
8369 | u32 peer_capab, int initiator, const u8 *buf, |
8370 | size_t len) | |
03ea1786 AN |
8371 | { |
8372 | struct i802_bss *bss = priv; | |
8373 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
8374 | struct nl_msg *msg; | |
8375 | ||
8376 | if (!(drv->capa.flags & WPA_DRIVER_FLAGS_TDLS_SUPPORT)) | |
8377 | return -EOPNOTSUPP; | |
8378 | ||
8379 | if (!dst) | |
8380 | return -EINVAL; | |
8381 | ||
9725b784 | 8382 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_TDLS_MGMT)) || |
a862e4a3 JM |
8383 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, dst) || |
8384 | nla_put_u8(msg, NL80211_ATTR_TDLS_ACTION, action_code) || | |
8385 | nla_put_u8(msg, NL80211_ATTR_TDLS_DIALOG_TOKEN, dialog_token) || | |
8386 | nla_put_u16(msg, NL80211_ATTR_STATUS_CODE, status_code)) | |
8387 | goto fail; | |
96ecea5e SD |
8388 | if (peer_capab) { |
8389 | /* | |
8390 | * The internal enum tdls_peer_capability definition is | |
8391 | * currently identical with the nl80211 enum | |
8392 | * nl80211_tdls_peer_capability, so no conversion is needed | |
8393 | * here. | |
8394 | */ | |
a862e4a3 JM |
8395 | if (nla_put_u32(msg, NL80211_ATTR_TDLS_PEER_CAPABILITY, |
8396 | peer_capab)) | |
8397 | goto fail; | |
96ecea5e | 8398 | } |
a862e4a3 JM |
8399 | if ((initiator && |
8400 | nla_put_flag(msg, NL80211_ATTR_TDLS_INITIATOR)) || | |
8401 | nla_put(msg, NL80211_ATTR_IE, len, buf)) | |
8402 | goto fail; | |
03ea1786 AN |
8403 | |
8404 | return send_and_recv_msgs(drv, msg, NULL, NULL); | |
8405 | ||
a862e4a3 | 8406 | fail: |
03ea1786 AN |
8407 | nlmsg_free(msg); |
8408 | return -ENOBUFS; | |
8409 | } | |
8410 | ||
8411 | ||
8412 | static int nl80211_tdls_oper(void *priv, enum tdls_oper oper, const u8 *peer) | |
8413 | { | |
8414 | struct i802_bss *bss = priv; | |
8415 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
8416 | struct nl_msg *msg; | |
8417 | enum nl80211_tdls_operation nl80211_oper; | |
b2442f25 | 8418 | int res; |
03ea1786 AN |
8419 | |
8420 | if (!(drv->capa.flags & WPA_DRIVER_FLAGS_TDLS_SUPPORT)) | |
8421 | return -EOPNOTSUPP; | |
8422 | ||
8423 | switch (oper) { | |
8424 | case TDLS_DISCOVERY_REQ: | |
8425 | nl80211_oper = NL80211_TDLS_DISCOVERY_REQ; | |
8426 | break; | |
8427 | case TDLS_SETUP: | |
8428 | nl80211_oper = NL80211_TDLS_SETUP; | |
8429 | break; | |
8430 | case TDLS_TEARDOWN: | |
8431 | nl80211_oper = NL80211_TDLS_TEARDOWN; | |
8432 | break; | |
8433 | case TDLS_ENABLE_LINK: | |
8434 | nl80211_oper = NL80211_TDLS_ENABLE_LINK; | |
8435 | break; | |
8436 | case TDLS_DISABLE_LINK: | |
8437 | nl80211_oper = NL80211_TDLS_DISABLE_LINK; | |
8438 | break; | |
8439 | case TDLS_ENABLE: | |
8440 | return 0; | |
8441 | case TDLS_DISABLE: | |
8442 | return 0; | |
8443 | default: | |
8444 | return -EINVAL; | |
8445 | } | |
8446 | ||
9725b784 | 8447 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_TDLS_OPER)) || |
a862e4a3 | 8448 | nla_put_u8(msg, NL80211_ATTR_TDLS_OPERATION, nl80211_oper) || |
a862e4a3 JM |
8449 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer)) { |
8450 | nlmsg_free(msg); | |
8451 | return -ENOBUFS; | |
8452 | } | |
03ea1786 | 8453 | |
b2442f25 JM |
8454 | res = send_and_recv_msgs(drv, msg, NULL, NULL); |
8455 | wpa_printf(MSG_DEBUG, "nl80211: TDLS_OPER: oper=%d mac=" MACSTR | |
8456 | " --> res=%d (%s)", nl80211_oper, MAC2STR(peer), res, | |
8457 | strerror(-res)); | |
8458 | return res; | |
03ea1786 AN |
8459 | } |
8460 | ||
72b2605f AN |
8461 | |
8462 | static int | |
8463 | nl80211_tdls_enable_channel_switch(void *priv, const u8 *addr, u8 oper_class, | |
8464 | const struct hostapd_freq_params *params) | |
8465 | { | |
8466 | struct i802_bss *bss = priv; | |
8467 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
8468 | struct nl_msg *msg; | |
8469 | int ret = -ENOBUFS; | |
8470 | ||
8471 | if (!(drv->capa.flags & WPA_DRIVER_FLAGS_TDLS_SUPPORT) || | |
8472 | !(drv->capa.flags & WPA_DRIVER_FLAGS_TDLS_CHANNEL_SWITCH)) | |
8473 | return -EOPNOTSUPP; | |
8474 | ||
8475 | wpa_printf(MSG_DEBUG, "nl80211: Enable TDLS channel switch " MACSTR | |
8476 | " oper_class=%u freq=%u", | |
8477 | MAC2STR(addr), oper_class, params->freq); | |
8478 | msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_TDLS_CHANNEL_SWITCH); | |
8479 | if (!msg || | |
8480 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) || | |
8481 | nla_put_u8(msg, NL80211_ATTR_OPER_CLASS, oper_class) || | |
8482 | (ret = nl80211_put_freq_params(msg, params))) { | |
8483 | nlmsg_free(msg); | |
8484 | wpa_printf(MSG_DEBUG, "nl80211: Could not build TDLS chan switch"); | |
8485 | return ret; | |
8486 | } | |
8487 | ||
8488 | return send_and_recv_msgs(drv, msg, NULL, NULL); | |
8489 | } | |
8490 | ||
8491 | ||
8492 | static int | |
8493 | nl80211_tdls_disable_channel_switch(void *priv, const u8 *addr) | |
8494 | { | |
8495 | struct i802_bss *bss = priv; | |
8496 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
8497 | struct nl_msg *msg; | |
8498 | ||
8499 | if (!(drv->capa.flags & WPA_DRIVER_FLAGS_TDLS_SUPPORT) || | |
8500 | !(drv->capa.flags & WPA_DRIVER_FLAGS_TDLS_CHANNEL_SWITCH)) | |
8501 | return -EOPNOTSUPP; | |
8502 | ||
8503 | wpa_printf(MSG_DEBUG, "nl80211: Disable TDLS channel switch " MACSTR, | |
8504 | MAC2STR(addr)); | |
8505 | msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_TDLS_CANCEL_CHANNEL_SWITCH); | |
8506 | if (!msg || | |
8507 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) { | |
8508 | nlmsg_free(msg); | |
8509 | wpa_printf(MSG_DEBUG, | |
8510 | "nl80211: Could not build TDLS cancel chan switch"); | |
8511 | return -ENOBUFS; | |
8512 | } | |
8513 | ||
8514 | return send_and_recv_msgs(drv, msg, NULL, NULL); | |
8515 | } | |
8516 | ||
03ea1786 AN |
8517 | #endif /* CONFIG TDLS */ |
8518 | ||
8519 | ||
9ebce9c5 JM |
8520 | static int driver_nl80211_set_key(const char *ifname, void *priv, |
8521 | enum wpa_alg alg, const u8 *addr, | |
8522 | int key_idx, int set_tx, | |
8523 | const u8 *seq, size_t seq_len, | |
8524 | const u8 *key, size_t key_len) | |
8525 | { | |
8526 | struct i802_bss *bss = priv; | |
8527 | return wpa_driver_nl80211_set_key(ifname, bss, alg, addr, key_idx, | |
8528 | set_tx, seq, seq_len, key, key_len); | |
8529 | } | |
8530 | ||
8531 | ||
8532 | static int driver_nl80211_scan2(void *priv, | |
8533 | struct wpa_driver_scan_params *params) | |
8534 | { | |
8535 | struct i802_bss *bss = priv; | |
b658547d | 8536 | #ifdef CONFIG_DRIVER_NL80211_QCA |
adcd7c4b KV |
8537 | struct wpa_driver_nl80211_data *drv = bss->drv; |
8538 | ||
8539 | /* | |
8540 | * Do a vendor specific scan if possible. If only_new_results is | |
8541 | * set, do a normal scan since a kernel (cfg80211) BSS cache flush | |
8542 | * cannot be achieved through a vendor scan. The below condition may | |
8543 | * need to be modified if new scan flags are added in the future whose | |
8544 | * functionality can only be achieved through a normal scan. | |
8545 | */ | |
8546 | if (drv->scan_vendor_cmd_avail && !params->only_new_results) | |
8547 | return wpa_driver_nl80211_vendor_scan(bss, params); | |
b658547d | 8548 | #endif /* CONFIG_DRIVER_NL80211_QCA */ |
9ebce9c5 JM |
8549 | return wpa_driver_nl80211_scan(bss, params); |
8550 | } | |
8551 | ||
8552 | ||
8553 | static int driver_nl80211_deauthenticate(void *priv, const u8 *addr, | |
8554 | int reason_code) | |
8555 | { | |
8556 | struct i802_bss *bss = priv; | |
8557 | return wpa_driver_nl80211_deauthenticate(bss, addr, reason_code); | |
8558 | } | |
8559 | ||
8560 | ||
8561 | static int driver_nl80211_authenticate(void *priv, | |
8562 | struct wpa_driver_auth_params *params) | |
8563 | { | |
8564 | struct i802_bss *bss = priv; | |
8565 | return wpa_driver_nl80211_authenticate(bss, params); | |
8566 | } | |
8567 | ||
8568 | ||
8569 | static void driver_nl80211_deinit(void *priv) | |
8570 | { | |
8571 | struct i802_bss *bss = priv; | |
8572 | wpa_driver_nl80211_deinit(bss); | |
8573 | } | |
8574 | ||
8575 | ||
8576 | static int driver_nl80211_if_remove(void *priv, enum wpa_driver_if_type type, | |
8577 | const char *ifname) | |
8578 | { | |
8579 | struct i802_bss *bss = priv; | |
8580 | return wpa_driver_nl80211_if_remove(bss, type, ifname); | |
8581 | } | |
8582 | ||
8583 | ||
8584 | static int driver_nl80211_send_mlme(void *priv, const u8 *data, | |
5d180a77 | 8585 | size_t data_len, int noack, |
2d3943ce AO |
8586 | unsigned int freq, |
8587 | const u16 *csa_offs, size_t csa_offs_len) | |
9ebce9c5 JM |
8588 | { |
8589 | struct i802_bss *bss = priv; | |
8590 | return wpa_driver_nl80211_send_mlme(bss, data, data_len, noack, | |
2d3943ce AO |
8591 | freq, 0, 0, 0, csa_offs, |
8592 | csa_offs_len); | |
9ebce9c5 JM |
8593 | } |
8594 | ||
8595 | ||
8596 | static int driver_nl80211_sta_remove(void *priv, const u8 *addr) | |
8597 | { | |
8598 | struct i802_bss *bss = priv; | |
59d7148a | 8599 | return wpa_driver_nl80211_sta_remove(bss, addr, -1, 0); |
9ebce9c5 JM |
8600 | } |
8601 | ||
8602 | ||
9ebce9c5 JM |
8603 | static int driver_nl80211_set_sta_vlan(void *priv, const u8 *addr, |
8604 | const char *ifname, int vlan_id) | |
8605 | { | |
8606 | struct i802_bss *bss = priv; | |
8607 | return i802_set_sta_vlan(bss, addr, ifname, vlan_id); | |
8608 | } | |
9ebce9c5 JM |
8609 | |
8610 | ||
8611 | static int driver_nl80211_read_sta_data(void *priv, | |
8612 | struct hostap_sta_driver_data *data, | |
8613 | const u8 *addr) | |
8614 | { | |
8615 | struct i802_bss *bss = priv; | |
7824bf77 JC |
8616 | |
8617 | os_memset(data, 0, sizeof(*data)); | |
9ebce9c5 JM |
8618 | return i802_read_sta_data(bss, data, addr); |
8619 | } | |
8620 | ||
8621 | ||
8622 | static int driver_nl80211_send_action(void *priv, unsigned int freq, | |
8623 | unsigned int wait_time, | |
8624 | const u8 *dst, const u8 *src, | |
8625 | const u8 *bssid, | |
8626 | const u8 *data, size_t data_len, | |
8627 | int no_cck) | |
8628 | { | |
8629 | struct i802_bss *bss = priv; | |
8630 | return wpa_driver_nl80211_send_action(bss, freq, wait_time, dst, src, | |
8631 | bssid, data, data_len, no_cck); | |
8632 | } | |
8633 | ||
8634 | ||
8635 | static int driver_nl80211_probe_req_report(void *priv, int report) | |
8636 | { | |
8637 | struct i802_bss *bss = priv; | |
8638 | return wpa_driver_nl80211_probe_req_report(bss, report); | |
8639 | } | |
8640 | ||
8641 | ||
6a1ce395 DG |
8642 | static int wpa_driver_nl80211_update_ft_ies(void *priv, const u8 *md, |
8643 | const u8 *ies, size_t ies_len) | |
8644 | { | |
8645 | int ret; | |
8646 | struct nl_msg *msg; | |
8647 | struct i802_bss *bss = priv; | |
8648 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
8649 | u16 mdid = WPA_GET_LE16(md); | |
8650 | ||
6a1ce395 | 8651 | wpa_printf(MSG_DEBUG, "nl80211: Updating FT IEs"); |
9725b784 | 8652 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_UPDATE_FT_IES)) || |
a862e4a3 JM |
8653 | nla_put(msg, NL80211_ATTR_IE, ies_len, ies) || |
8654 | nla_put_u16(msg, NL80211_ATTR_MDID, mdid)) { | |
8655 | nlmsg_free(msg); | |
8656 | return -ENOBUFS; | |
8657 | } | |
6a1ce395 DG |
8658 | |
8659 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); | |
8660 | if (ret) { | |
8661 | wpa_printf(MSG_DEBUG, "nl80211: update_ft_ies failed " | |
8662 | "err=%d (%s)", ret, strerror(-ret)); | |
8663 | } | |
8664 | ||
8665 | return ret; | |
6a1ce395 DG |
8666 | } |
8667 | ||
8668 | ||
47754718 | 8669 | static const u8 * wpa_driver_nl80211_get_macaddr(void *priv) |
597b94f5 AS |
8670 | { |
8671 | struct i802_bss *bss = priv; | |
8672 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
8673 | ||
8674 | if (drv->nlmode != NL80211_IFTYPE_P2P_DEVICE) | |
8675 | return NULL; | |
8676 | ||
8677 | return bss->addr; | |
8678 | } | |
8679 | ||
8680 | ||
a771c07d JM |
8681 | static const char * scan_state_str(enum scan_states scan_state) |
8682 | { | |
8683 | switch (scan_state) { | |
8684 | case NO_SCAN: | |
8685 | return "NO_SCAN"; | |
8686 | case SCAN_REQUESTED: | |
8687 | return "SCAN_REQUESTED"; | |
8688 | case SCAN_STARTED: | |
8689 | return "SCAN_STARTED"; | |
8690 | case SCAN_COMPLETED: | |
8691 | return "SCAN_COMPLETED"; | |
8692 | case SCAN_ABORTED: | |
8693 | return "SCAN_ABORTED"; | |
8694 | case SCHED_SCAN_STARTED: | |
8695 | return "SCHED_SCAN_STARTED"; | |
8696 | case SCHED_SCAN_STOPPED: | |
8697 | return "SCHED_SCAN_STOPPED"; | |
8698 | case SCHED_SCAN_RESULTS: | |
8699 | return "SCHED_SCAN_RESULTS"; | |
8700 | } | |
8701 | ||
8702 | return "??"; | |
8703 | } | |
8704 | ||
8705 | ||
8706 | static int wpa_driver_nl80211_status(void *priv, char *buf, size_t buflen) | |
8707 | { | |
8708 | struct i802_bss *bss = priv; | |
8709 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
8710 | int res; | |
8711 | char *pos, *end; | |
fea49f8f JM |
8712 | struct nl_msg *msg; |
8713 | char alpha2[3] = { 0, 0, 0 }; | |
a771c07d JM |
8714 | |
8715 | pos = buf; | |
8716 | end = buf + buflen; | |
8717 | ||
8718 | res = os_snprintf(pos, end - pos, | |
8719 | "ifindex=%d\n" | |
8720 | "ifname=%s\n" | |
8721 | "brname=%s\n" | |
8722 | "addr=" MACSTR "\n" | |
8723 | "freq=%d\n" | |
c809756f | 8724 | "%s%s%s%s%s%s", |
a771c07d JM |
8725 | bss->ifindex, |
8726 | bss->ifname, | |
8727 | bss->brname, | |
8728 | MAC2STR(bss->addr), | |
8729 | bss->freq, | |
8730 | bss->beacon_set ? "beacon_set=1\n" : "", | |
8731 | bss->added_if_into_bridge ? | |
8732 | "added_if_into_bridge=1\n" : "", | |
c809756f | 8733 | bss->already_in_bridge ? "already_in_bridge=1\n" : "", |
a771c07d JM |
8734 | bss->added_bridge ? "added_bridge=1\n" : "", |
8735 | bss->in_deinit ? "in_deinit=1\n" : "", | |
8736 | bss->if_dynamic ? "if_dynamic=1\n" : ""); | |
d85e1fc8 | 8737 | if (os_snprintf_error(end - pos, res)) |
a771c07d JM |
8738 | return pos - buf; |
8739 | pos += res; | |
8740 | ||
8741 | if (bss->wdev_id_set) { | |
8742 | res = os_snprintf(pos, end - pos, "wdev_id=%llu\n", | |
8743 | (unsigned long long) bss->wdev_id); | |
d85e1fc8 | 8744 | if (os_snprintf_error(end - pos, res)) |
a771c07d JM |
8745 | return pos - buf; |
8746 | pos += res; | |
8747 | } | |
8748 | ||
8749 | res = os_snprintf(pos, end - pos, | |
8750 | "phyname=%s\n" | |
fee354c7 | 8751 | "perm_addr=" MACSTR "\n" |
a771c07d JM |
8752 | "drv_ifindex=%d\n" |
8753 | "operstate=%d\n" | |
8754 | "scan_state=%s\n" | |
8755 | "auth_bssid=" MACSTR "\n" | |
8756 | "auth_attempt_bssid=" MACSTR "\n" | |
8757 | "bssid=" MACSTR "\n" | |
8758 | "prev_bssid=" MACSTR "\n" | |
8759 | "associated=%d\n" | |
8760 | "assoc_freq=%u\n" | |
8761 | "monitor_sock=%d\n" | |
8762 | "monitor_ifidx=%d\n" | |
8763 | "monitor_refcount=%d\n" | |
8764 | "last_mgmt_freq=%u\n" | |
8765 | "eapol_tx_sock=%d\n" | |
97752f79 | 8766 | "%s%s%s%s%s%s%s%s%s%s%s%s%s", |
a771c07d | 8767 | drv->phyname, |
fee354c7 | 8768 | MAC2STR(drv->perm_addr), |
a771c07d JM |
8769 | drv->ifindex, |
8770 | drv->operstate, | |
8771 | scan_state_str(drv->scan_state), | |
8772 | MAC2STR(drv->auth_bssid), | |
8773 | MAC2STR(drv->auth_attempt_bssid), | |
8774 | MAC2STR(drv->bssid), | |
8775 | MAC2STR(drv->prev_bssid), | |
8776 | drv->associated, | |
8777 | drv->assoc_freq, | |
8778 | drv->monitor_sock, | |
8779 | drv->monitor_ifidx, | |
8780 | drv->monitor_refcount, | |
8781 | drv->last_mgmt_freq, | |
8782 | drv->eapol_tx_sock, | |
8783 | drv->ignore_if_down_event ? | |
8784 | "ignore_if_down_event=1\n" : "", | |
8785 | drv->scan_complete_events ? | |
8786 | "scan_complete_events=1\n" : "", | |
8787 | drv->disabled_11b_rates ? | |
8788 | "disabled_11b_rates=1\n" : "", | |
8789 | drv->pending_remain_on_chan ? | |
8790 | "pending_remain_on_chan=1\n" : "", | |
8791 | drv->in_interface_list ? "in_interface_list=1\n" : "", | |
8792 | drv->device_ap_sme ? "device_ap_sme=1\n" : "", | |
8793 | drv->poll_command_supported ? | |
8794 | "poll_command_supported=1\n" : "", | |
8795 | drv->data_tx_status ? "data_tx_status=1\n" : "", | |
8796 | drv->scan_for_auth ? "scan_for_auth=1\n" : "", | |
8797 | drv->retry_auth ? "retry_auth=1\n" : "", | |
8798 | drv->use_monitor ? "use_monitor=1\n" : "", | |
8799 | drv->ignore_next_local_disconnect ? | |
8800 | "ignore_next_local_disconnect=1\n" : "", | |
d6a36f39 | 8801 | drv->ignore_next_local_deauth ? |
97752f79 | 8802 | "ignore_next_local_deauth=1\n" : ""); |
d85e1fc8 | 8803 | if (os_snprintf_error(end - pos, res)) |
a771c07d JM |
8804 | return pos - buf; |
8805 | pos += res; | |
8806 | ||
8807 | if (drv->has_capability) { | |
8808 | res = os_snprintf(pos, end - pos, | |
8809 | "capa.key_mgmt=0x%x\n" | |
8810 | "capa.enc=0x%x\n" | |
8811 | "capa.auth=0x%x\n" | |
24bd4e0b | 8812 | "capa.flags=0x%llx\n" |
a0a34d53 | 8813 | "capa.rrm_flags=0x%x\n" |
a771c07d JM |
8814 | "capa.max_scan_ssids=%d\n" |
8815 | "capa.max_sched_scan_ssids=%d\n" | |
8816 | "capa.sched_scan_supported=%d\n" | |
8817 | "capa.max_match_sets=%d\n" | |
8818 | "capa.max_remain_on_chan=%u\n" | |
8819 | "capa.max_stations=%u\n" | |
8820 | "capa.probe_resp_offloads=0x%x\n" | |
8821 | "capa.max_acl_mac_addrs=%u\n" | |
86056fea IP |
8822 | "capa.num_multichan_concurrent=%u\n" |
8823 | "capa.mac_addr_rand_sched_scan_supported=%d\n" | |
079a28f7 AK |
8824 | "capa.mac_addr_rand_scan_supported=%d\n" |
8825 | "capa.conc_capab=%u\n" | |
8826 | "capa.max_conc_chan_2_4=%u\n" | |
09ea4309 AS |
8827 | "capa.max_conc_chan_5_0=%u\n" |
8828 | "capa.max_sched_scan_plans=%u\n" | |
8829 | "capa.max_sched_scan_plan_interval=%u\n" | |
8830 | "capa.max_sched_scan_plan_iterations=%u\n", | |
a771c07d JM |
8831 | drv->capa.key_mgmt, |
8832 | drv->capa.enc, | |
8833 | drv->capa.auth, | |
24bd4e0b | 8834 | (unsigned long long) drv->capa.flags, |
a0a34d53 | 8835 | drv->capa.rrm_flags, |
a771c07d JM |
8836 | drv->capa.max_scan_ssids, |
8837 | drv->capa.max_sched_scan_ssids, | |
8838 | drv->capa.sched_scan_supported, | |
8839 | drv->capa.max_match_sets, | |
8840 | drv->capa.max_remain_on_chan, | |
8841 | drv->capa.max_stations, | |
8842 | drv->capa.probe_resp_offloads, | |
8843 | drv->capa.max_acl_mac_addrs, | |
86056fea IP |
8844 | drv->capa.num_multichan_concurrent, |
8845 | drv->capa.mac_addr_rand_sched_scan_supported, | |
079a28f7 AK |
8846 | drv->capa.mac_addr_rand_scan_supported, |
8847 | drv->capa.conc_capab, | |
8848 | drv->capa.max_conc_chan_2_4, | |
09ea4309 AS |
8849 | drv->capa.max_conc_chan_5_0, |
8850 | drv->capa.max_sched_scan_plans, | |
8851 | drv->capa.max_sched_scan_plan_interval, | |
8852 | drv->capa.max_sched_scan_plan_iterations); | |
d85e1fc8 | 8853 | if (os_snprintf_error(end - pos, res)) |
a771c07d JM |
8854 | return pos - buf; |
8855 | pos += res; | |
8856 | } | |
8857 | ||
fea49f8f JM |
8858 | msg = nlmsg_alloc(); |
8859 | if (msg && | |
8860 | nl80211_cmd(drv, msg, 0, NL80211_CMD_GET_REG) && | |
8861 | nla_put_u32(msg, NL80211_ATTR_WIPHY, drv->wiphy_idx) == 0) { | |
8862 | if (send_and_recv_msgs(drv, msg, nl80211_get_country, | |
8863 | alpha2) == 0 && | |
8864 | alpha2[0]) { | |
8865 | res = os_snprintf(pos, end - pos, "country=%s\n", | |
8866 | alpha2); | |
8867 | if (os_snprintf_error(end - pos, res)) | |
8868 | return pos - buf; | |
8869 | pos += res; | |
8870 | } | |
8871 | } else { | |
8872 | nlmsg_free(msg); | |
8873 | } | |
8874 | ||
a771c07d JM |
8875 | return pos - buf; |
8876 | } | |
8877 | ||
8878 | ||
1c4ffa87 AO |
8879 | static int set_beacon_data(struct nl_msg *msg, struct beacon_data *settings) |
8880 | { | |
a862e4a3 JM |
8881 | if ((settings->head && |
8882 | nla_put(msg, NL80211_ATTR_BEACON_HEAD, | |
8883 | settings->head_len, settings->head)) || | |
8884 | (settings->tail && | |
8885 | nla_put(msg, NL80211_ATTR_BEACON_TAIL, | |
8886 | settings->tail_len, settings->tail)) || | |
8887 | (settings->beacon_ies && | |
8888 | nla_put(msg, NL80211_ATTR_IE, | |
8889 | settings->beacon_ies_len, settings->beacon_ies)) || | |
8890 | (settings->proberesp_ies && | |
8891 | nla_put(msg, NL80211_ATTR_IE_PROBE_RESP, | |
8892 | settings->proberesp_ies_len, settings->proberesp_ies)) || | |
8893 | (settings->assocresp_ies && | |
8894 | nla_put(msg, NL80211_ATTR_IE_ASSOC_RESP, | |
8895 | settings->assocresp_ies_len, settings->assocresp_ies)) || | |
8896 | (settings->probe_resp && | |
8897 | nla_put(msg, NL80211_ATTR_PROBE_RESP, | |
8898 | settings->probe_resp_len, settings->probe_resp))) | |
8899 | return -ENOBUFS; | |
1c4ffa87 AO |
8900 | |
8901 | return 0; | |
1c4ffa87 AO |
8902 | } |
8903 | ||
8904 | ||
8905 | static int nl80211_switch_channel(void *priv, struct csa_settings *settings) | |
8906 | { | |
8907 | struct nl_msg *msg; | |
8908 | struct i802_bss *bss = priv; | |
8909 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
8910 | struct nlattr *beacon_csa; | |
8911 | int ret = -ENOBUFS; | |
366179d2 AO |
8912 | int csa_off_len = 0; |
8913 | int i; | |
1c4ffa87 | 8914 | |
8d1fdde7 | 8915 | wpa_printf(MSG_DEBUG, "nl80211: Channel switch request (cs_count=%u block_tx=%u freq=%d width=%d cf1=%d cf2=%d)", |
1c4ffa87 | 8916 | settings->cs_count, settings->block_tx, |
8d1fdde7 JD |
8917 | settings->freq_params.freq, settings->freq_params.bandwidth, |
8918 | settings->freq_params.center_freq1, | |
8919 | settings->freq_params.center_freq2); | |
1c4ffa87 | 8920 | |
991aa9c7 | 8921 | if (!(drv->capa.flags & WPA_DRIVER_FLAGS_AP_CSA)) { |
1c4ffa87 AO |
8922 | wpa_printf(MSG_DEBUG, "nl80211: Driver does not support channel switch command"); |
8923 | return -EOPNOTSUPP; | |
8924 | } | |
8925 | ||
0928b629 PO |
8926 | if (drv->nlmode != NL80211_IFTYPE_AP && |
8927 | drv->nlmode != NL80211_IFTYPE_P2P_GO && | |
8928 | drv->nlmode != NL80211_IFTYPE_MESH_POINT) | |
1c4ffa87 AO |
8929 | return -EOPNOTSUPP; |
8930 | ||
366179d2 AO |
8931 | /* |
8932 | * Remove empty counters, assuming Probe Response and Beacon frame | |
8933 | * counters match. This implementation assumes that there are only two | |
8934 | * counters. | |
8935 | */ | |
8936 | if (settings->counter_offset_beacon[0] && | |
8937 | !settings->counter_offset_beacon[1]) { | |
8938 | csa_off_len = 1; | |
8939 | } else if (settings->counter_offset_beacon[1] && | |
8940 | !settings->counter_offset_beacon[0]) { | |
8941 | csa_off_len = 1; | |
8942 | settings->counter_offset_beacon[0] = | |
8943 | settings->counter_offset_beacon[1]; | |
8944 | settings->counter_offset_presp[0] = | |
8945 | settings->counter_offset_presp[1]; | |
8946 | } else if (settings->counter_offset_beacon[1] && | |
8947 | settings->counter_offset_beacon[0]) { | |
8948 | csa_off_len = 2; | |
8949 | } else { | |
8950 | wpa_printf(MSG_ERROR, "nl80211: No CSA counters provided"); | |
8951 | return -EINVAL; | |
8952 | } | |
8953 | ||
8954 | /* Check CSA counters validity */ | |
8955 | if (drv->capa.max_csa_counters && | |
8956 | csa_off_len > drv->capa.max_csa_counters) { | |
8957 | wpa_printf(MSG_ERROR, | |
8958 | "nl80211: Too many CSA counters provided"); | |
1c4ffa87 | 8959 | return -EINVAL; |
366179d2 | 8960 | } |
1c4ffa87 | 8961 | |
366179d2 | 8962 | if (!settings->beacon_csa.tail) |
1c4ffa87 AO |
8963 | return -EINVAL; |
8964 | ||
366179d2 AO |
8965 | for (i = 0; i < csa_off_len; i++) { |
8966 | u16 csa_c_off_bcn = settings->counter_offset_beacon[i]; | |
8967 | u16 csa_c_off_presp = settings->counter_offset_presp[i]; | |
8968 | ||
8969 | if ((settings->beacon_csa.tail_len <= csa_c_off_bcn) || | |
8970 | (settings->beacon_csa.tail[csa_c_off_bcn] != | |
8971 | settings->cs_count)) | |
8972 | return -EINVAL; | |
8973 | ||
8974 | if (settings->beacon_csa.probe_resp && | |
8975 | ((settings->beacon_csa.probe_resp_len <= | |
8976 | csa_c_off_presp) || | |
8977 | (settings->beacon_csa.probe_resp[csa_c_off_presp] != | |
8978 | settings->cs_count))) | |
8979 | return -EINVAL; | |
8980 | } | |
8981 | ||
13f83980 | 8982 | if (!(msg = nl80211_bss_msg(bss, 0, NL80211_CMD_CHANNEL_SWITCH)) || |
a862e4a3 JM |
8983 | nla_put_u32(msg, NL80211_ATTR_CH_SWITCH_COUNT, |
8984 | settings->cs_count) || | |
8985 | (ret = nl80211_put_freq_params(msg, &settings->freq_params)) || | |
8986 | (settings->block_tx && | |
8987 | nla_put_flag(msg, NL80211_ATTR_CH_SWITCH_BLOCK_TX))) | |
1c4ffa87 AO |
8988 | goto error; |
8989 | ||
1c4ffa87 AO |
8990 | /* beacon_after params */ |
8991 | ret = set_beacon_data(msg, &settings->beacon_after); | |
8992 | if (ret) | |
8993 | goto error; | |
8994 | ||
8995 | /* beacon_csa params */ | |
8996 | beacon_csa = nla_nest_start(msg, NL80211_ATTR_CSA_IES); | |
8997 | if (!beacon_csa) | |
a862e4a3 | 8998 | goto fail; |
1c4ffa87 AO |
8999 | |
9000 | ret = set_beacon_data(msg, &settings->beacon_csa); | |
9001 | if (ret) | |
9002 | goto error; | |
9003 | ||
366179d2 AO |
9004 | if (nla_put(msg, NL80211_ATTR_CSA_C_OFF_BEACON, |
9005 | csa_off_len * sizeof(u16), | |
9006 | settings->counter_offset_beacon) || | |
a862e4a3 | 9007 | (settings->beacon_csa.probe_resp && |
366179d2 AO |
9008 | nla_put(msg, NL80211_ATTR_CSA_C_OFF_PRESP, |
9009 | csa_off_len * sizeof(u16), | |
9010 | settings->counter_offset_presp))) | |
a862e4a3 | 9011 | goto fail; |
1c4ffa87 AO |
9012 | |
9013 | nla_nest_end(msg, beacon_csa); | |
9014 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); | |
9015 | if (ret) { | |
9016 | wpa_printf(MSG_DEBUG, "nl80211: switch_channel failed err=%d (%s)", | |
9017 | ret, strerror(-ret)); | |
9018 | } | |
9019 | return ret; | |
9020 | ||
a862e4a3 | 9021 | fail: |
1c4ffa87 AO |
9022 | ret = -ENOBUFS; |
9023 | error: | |
9024 | nlmsg_free(msg); | |
9025 | wpa_printf(MSG_DEBUG, "nl80211: Could not build channel switch request"); | |
9026 | return ret; | |
9027 | } | |
9028 | ||
9029 | ||
dfa87878 MB |
9030 | static int nl80211_add_ts(void *priv, u8 tsid, const u8 *addr, |
9031 | u8 user_priority, u16 admitted_time) | |
9032 | { | |
9033 | struct i802_bss *bss = priv; | |
9034 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
9035 | struct nl_msg *msg; | |
9036 | int ret; | |
9037 | ||
9038 | wpa_printf(MSG_DEBUG, | |
9039 | "nl80211: add_ts request: tsid=%u admitted_time=%u up=%d", | |
9040 | tsid, admitted_time, user_priority); | |
9041 | ||
9042 | if (!is_sta_interface(drv->nlmode)) | |
9043 | return -ENOTSUP; | |
9044 | ||
56f77852 JM |
9045 | msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_ADD_TX_TS); |
9046 | if (!msg || | |
a862e4a3 JM |
9047 | nla_put_u8(msg, NL80211_ATTR_TSID, tsid) || |
9048 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) || | |
9049 | nla_put_u8(msg, NL80211_ATTR_USER_PRIO, user_priority) || | |
9050 | nla_put_u16(msg, NL80211_ATTR_ADMITTED_TIME, admitted_time)) { | |
9051 | nlmsg_free(msg); | |
9052 | return -ENOBUFS; | |
9053 | } | |
dfa87878 MB |
9054 | |
9055 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); | |
9056 | if (ret) | |
9057 | wpa_printf(MSG_DEBUG, "nl80211: add_ts failed err=%d (%s)", | |
9058 | ret, strerror(-ret)); | |
9059 | return ret; | |
dfa87878 MB |
9060 | } |
9061 | ||
9062 | ||
9063 | static int nl80211_del_ts(void *priv, u8 tsid, const u8 *addr) | |
9064 | { | |
9065 | struct i802_bss *bss = priv; | |
9066 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
9067 | struct nl_msg *msg; | |
9068 | int ret; | |
9069 | ||
9070 | wpa_printf(MSG_DEBUG, "nl80211: del_ts request: tsid=%u", tsid); | |
9071 | ||
9072 | if (!is_sta_interface(drv->nlmode)) | |
9073 | return -ENOTSUP; | |
9074 | ||
56f77852 | 9075 | if (!(msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_DEL_TX_TS)) || |
a862e4a3 JM |
9076 | nla_put_u8(msg, NL80211_ATTR_TSID, tsid) || |
9077 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) { | |
9078 | nlmsg_free(msg); | |
9079 | return -ENOBUFS; | |
9080 | } | |
dfa87878 MB |
9081 | |
9082 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); | |
9083 | if (ret) | |
9084 | wpa_printf(MSG_DEBUG, "nl80211: del_ts failed err=%d (%s)", | |
9085 | ret, strerror(-ret)); | |
9086 | return ret; | |
dfa87878 MB |
9087 | } |
9088 | ||
9089 | ||
6b9f7af6 JM |
9090 | #ifdef CONFIG_TESTING_OPTIONS |
9091 | static int cmd_reply_handler(struct nl_msg *msg, void *arg) | |
9092 | { | |
9093 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); | |
9094 | struct wpabuf *buf = arg; | |
9095 | ||
9096 | if (!buf) | |
9097 | return NL_SKIP; | |
9098 | ||
9099 | if ((size_t) genlmsg_attrlen(gnlh, 0) > wpabuf_tailroom(buf)) { | |
9100 | wpa_printf(MSG_INFO, "nl80211: insufficient buffer space for reply"); | |
9101 | return NL_SKIP; | |
9102 | } | |
9103 | ||
9104 | wpabuf_put_data(buf, genlmsg_attrdata(gnlh, 0), | |
9105 | genlmsg_attrlen(gnlh, 0)); | |
9106 | ||
9107 | return NL_SKIP; | |
9108 | } | |
9109 | #endif /* CONFIG_TESTING_OPTIONS */ | |
9110 | ||
9111 | ||
adef8948 BL |
9112 | static int vendor_reply_handler(struct nl_msg *msg, void *arg) |
9113 | { | |
9114 | struct nlattr *tb[NL80211_ATTR_MAX + 1]; | |
9115 | struct nlattr *nl_vendor_reply, *nl; | |
9116 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); | |
9117 | struct wpabuf *buf = arg; | |
9118 | int rem; | |
9119 | ||
9120 | if (!buf) | |
9121 | return NL_SKIP; | |
9122 | ||
9123 | nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), | |
9124 | genlmsg_attrlen(gnlh, 0), NULL); | |
9125 | nl_vendor_reply = tb[NL80211_ATTR_VENDOR_DATA]; | |
9126 | ||
9127 | if (!nl_vendor_reply) | |
9128 | return NL_SKIP; | |
9129 | ||
9130 | if ((size_t) nla_len(nl_vendor_reply) > wpabuf_tailroom(buf)) { | |
9131 | wpa_printf(MSG_INFO, "nl80211: Vendor command: insufficient buffer space for reply"); | |
9132 | return NL_SKIP; | |
9133 | } | |
9134 | ||
9135 | nla_for_each_nested(nl, nl_vendor_reply, rem) { | |
9136 | wpabuf_put_data(buf, nla_data(nl), nla_len(nl)); | |
9137 | } | |
9138 | ||
9139 | return NL_SKIP; | |
9140 | } | |
9141 | ||
9142 | ||
9143 | static int nl80211_vendor_cmd(void *priv, unsigned int vendor_id, | |
9144 | unsigned int subcmd, const u8 *data, | |
9145 | size_t data_len, struct wpabuf *buf) | |
9146 | { | |
9147 | struct i802_bss *bss = priv; | |
9148 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
9149 | struct nl_msg *msg; | |
9150 | int ret; | |
9151 | ||
6b9f7af6 JM |
9152 | #ifdef CONFIG_TESTING_OPTIONS |
9153 | if (vendor_id == 0xffffffff) { | |
56f77852 JM |
9154 | msg = nlmsg_alloc(); |
9155 | if (!msg) | |
9156 | return -ENOMEM; | |
9157 | ||
6b9f7af6 JM |
9158 | nl80211_cmd(drv, msg, 0, subcmd); |
9159 | if (nlmsg_append(msg, (void *) data, data_len, NLMSG_ALIGNTO) < | |
9160 | 0) | |
a862e4a3 | 9161 | goto fail; |
6b9f7af6 JM |
9162 | ret = send_and_recv_msgs(drv, msg, cmd_reply_handler, buf); |
9163 | if (ret) | |
9164 | wpa_printf(MSG_DEBUG, "nl80211: command failed err=%d", | |
9165 | ret); | |
9166 | return ret; | |
9167 | } | |
9168 | #endif /* CONFIG_TESTING_OPTIONS */ | |
9169 | ||
56f77852 | 9170 | if (!(msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_VENDOR)) || |
a862e4a3 JM |
9171 | nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, vendor_id) || |
9172 | nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD, subcmd) || | |
9173 | (data && | |
9174 | nla_put(msg, NL80211_ATTR_VENDOR_DATA, data_len, data))) | |
9175 | goto fail; | |
adef8948 BL |
9176 | |
9177 | ret = send_and_recv_msgs(drv, msg, vendor_reply_handler, buf); | |
9178 | if (ret) | |
9179 | wpa_printf(MSG_DEBUG, "nl80211: vendor command failed err=%d", | |
9180 | ret); | |
9181 | return ret; | |
9182 | ||
a862e4a3 | 9183 | fail: |
adef8948 BL |
9184 | nlmsg_free(msg); |
9185 | return -ENOBUFS; | |
9186 | } | |
9187 | ||
9188 | ||
049105b4 KP |
9189 | static int nl80211_set_qos_map(void *priv, const u8 *qos_map_set, |
9190 | u8 qos_map_set_len) | |
9191 | { | |
9192 | struct i802_bss *bss = priv; | |
9193 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
9194 | struct nl_msg *msg; | |
9195 | int ret; | |
9196 | ||
049105b4 KP |
9197 | wpa_hexdump(MSG_DEBUG, "nl80211: Setting QoS Map", |
9198 | qos_map_set, qos_map_set_len); | |
9199 | ||
9725b784 | 9200 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_SET_QOS_MAP)) || |
a862e4a3 JM |
9201 | nla_put(msg, NL80211_ATTR_QOS_MAP, qos_map_set_len, qos_map_set)) { |
9202 | nlmsg_free(msg); | |
9203 | return -ENOBUFS; | |
9204 | } | |
049105b4 KP |
9205 | |
9206 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); | |
9207 | if (ret) | |
9208 | wpa_printf(MSG_DEBUG, "nl80211: Setting QoS Map failed"); | |
9209 | ||
9210 | return ret; | |
049105b4 KP |
9211 | } |
9212 | ||
9213 | ||
e4fa8b12 EP |
9214 | static int nl80211_set_wowlan(void *priv, |
9215 | const struct wowlan_triggers *triggers) | |
9216 | { | |
9217 | struct i802_bss *bss = priv; | |
9218 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
9219 | struct nl_msg *msg; | |
9220 | struct nlattr *wowlan_triggers; | |
9221 | int ret; | |
9222 | ||
e4fa8b12 EP |
9223 | wpa_printf(MSG_DEBUG, "nl80211: Setting wowlan"); |
9224 | ||
1ac977bd | 9225 | if (!(msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_SET_WOWLAN)) || |
a862e4a3 JM |
9226 | !(wowlan_triggers = nla_nest_start(msg, |
9227 | NL80211_ATTR_WOWLAN_TRIGGERS)) || | |
9228 | (triggers->any && | |
9229 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_ANY)) || | |
9230 | (triggers->disconnect && | |
9231 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) || | |
9232 | (triggers->magic_pkt && | |
9233 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) || | |
9234 | (triggers->gtk_rekey_failure && | |
9235 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) || | |
9236 | (triggers->eap_identity_req && | |
9237 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) || | |
9238 | (triggers->four_way_handshake && | |
9239 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) || | |
9240 | (triggers->rfkill_release && | |
9241 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE))) { | |
9242 | nlmsg_free(msg); | |
9243 | return -ENOBUFS; | |
9244 | } | |
e4fa8b12 EP |
9245 | |
9246 | nla_nest_end(msg, wowlan_triggers); | |
9247 | ||
9248 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); | |
9249 | if (ret) | |
9250 | wpa_printf(MSG_DEBUG, "nl80211: Setting wowlan failed"); | |
9251 | ||
9252 | return ret; | |
e4fa8b12 EP |
9253 | } |
9254 | ||
9255 | ||
b658547d | 9256 | #ifdef CONFIG_DRIVER_NL80211_QCA |
0800f9ee JM |
9257 | static int nl80211_roaming(void *priv, int allowed, const u8 *bssid) |
9258 | { | |
9259 | struct i802_bss *bss = priv; | |
9260 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
9261 | struct nl_msg *msg; | |
9262 | struct nlattr *params; | |
9263 | ||
9264 | wpa_printf(MSG_DEBUG, "nl80211: Roaming policy: allowed=%d", allowed); | |
9265 | ||
9266 | if (!drv->roaming_vendor_cmd_avail) { | |
9267 | wpa_printf(MSG_DEBUG, | |
9268 | "nl80211: Ignore roaming policy change since driver does not provide command for setting it"); | |
9269 | return -1; | |
9270 | } | |
9271 | ||
9725b784 | 9272 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_VENDOR)) || |
a862e4a3 JM |
9273 | nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) || |
9274 | nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD, | |
9275 | QCA_NL80211_VENDOR_SUBCMD_ROAMING) || | |
9276 | !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) || | |
9277 | nla_put_u32(msg, QCA_WLAN_VENDOR_ATTR_ROAMING_POLICY, | |
9278 | allowed ? QCA_ROAMING_ALLOWED_WITHIN_ESS : | |
9279 | QCA_ROAMING_NOT_ALLOWED) || | |
9280 | (bssid && | |
9281 | nla_put(msg, QCA_WLAN_VENDOR_ATTR_MAC_ADDR, ETH_ALEN, bssid))) { | |
9282 | nlmsg_free(msg); | |
9283 | return -1; | |
9284 | } | |
0800f9ee JM |
9285 | nla_nest_end(msg, params); |
9286 | ||
9287 | return send_and_recv_msgs(drv, msg, NULL, NULL); | |
0800f9ee | 9288 | } |
b04854ce AP |
9289 | |
9290 | ||
d98038bb | 9291 | static int nl80211_disable_fils(void *priv, int disable) |
9292 | { | |
9293 | struct i802_bss *bss = priv; | |
9294 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
9295 | struct nl_msg *msg; | |
9296 | struct nlattr *params; | |
9297 | ||
9298 | wpa_printf(MSG_DEBUG, "nl80211: Disable FILS=%d", disable); | |
9299 | ||
9300 | if (!drv->set_wifi_conf_vendor_cmd_avail) | |
9301 | return -1; | |
9302 | ||
9303 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_VENDOR)) || | |
9304 | nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) || | |
9305 | nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD, | |
9306 | QCA_NL80211_VENDOR_SUBCMD_SET_WIFI_CONFIGURATION) || | |
9307 | !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) || | |
9308 | nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_CONFIG_DISABLE_FILS, | |
9309 | disable)) { | |
9310 | nlmsg_free(msg); | |
9311 | return -1; | |
9312 | } | |
9313 | nla_nest_end(msg, params); | |
9314 | ||
9315 | return send_and_recv_msgs(drv, msg, NULL, NULL); | |
9316 | } | |
9317 | ||
9318 | ||
b04854ce AP |
9319 | /* Reserved QCA_WLAN_VENDOR_ATTR_ROAMING_REQ_ID value for wpa_supplicant */ |
9320 | #define WPA_SUPPLICANT_CLIENT_ID 1 | |
9321 | ||
9322 | static int nl80211_set_bssid_blacklist(void *priv, unsigned int num_bssid, | |
9323 | const u8 *bssid) | |
9324 | { | |
9325 | struct i802_bss *bss = priv; | |
9326 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
9327 | struct nl_msg *msg; | |
9328 | struct nlattr *params, *nlbssids, *attr; | |
9329 | unsigned int i; | |
9330 | ||
9331 | wpa_printf(MSG_DEBUG, "nl80211: Set blacklist BSSID (num=%u)", | |
9332 | num_bssid); | |
9333 | ||
9334 | if (!drv->roam_vendor_cmd_avail) | |
9335 | return -1; | |
9336 | ||
9337 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_VENDOR)) || | |
9338 | nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) || | |
9339 | nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD, | |
9340 | QCA_NL80211_VENDOR_SUBCMD_ROAM) || | |
9341 | !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) || | |
9342 | nla_put_u32(msg, QCA_WLAN_VENDOR_ATTR_ROAMING_SUBCMD, | |
9343 | QCA_WLAN_VENDOR_ATTR_ROAM_SUBCMD_SET_BLACKLIST_BSSID) || | |
9344 | nla_put_u32(msg, QCA_WLAN_VENDOR_ATTR_ROAMING_REQ_ID, | |
9345 | WPA_SUPPLICANT_CLIENT_ID) || | |
9346 | nla_put_u32(msg, | |
9347 | QCA_WLAN_VENDOR_ATTR_ROAMING_PARAM_SET_BSSID_PARAMS_NUM_BSSID, | |
9348 | num_bssid)) | |
9349 | goto fail; | |
9350 | ||
9351 | nlbssids = nla_nest_start( | |
9352 | msg, QCA_WLAN_VENDOR_ATTR_ROAMING_PARAM_SET_BSSID_PARAMS); | |
9353 | if (!nlbssids) | |
9354 | goto fail; | |
9355 | ||
9356 | for (i = 0; i < num_bssid; i++) { | |
9357 | attr = nla_nest_start(msg, i); | |
9358 | if (!attr) | |
9359 | goto fail; | |
9360 | if (nla_put(msg, | |
9361 | QCA_WLAN_VENDOR_ATTR_ROAMING_PARAM_SET_BSSID_PARAMS_BSSID, | |
9362 | ETH_ALEN, &bssid[i * ETH_ALEN])) | |
9363 | goto fail; | |
9364 | wpa_printf(MSG_DEBUG, "nl80211: BSSID[%u]: " MACSTR, i, | |
9365 | MAC2STR(&bssid[i * ETH_ALEN])); | |
9366 | nla_nest_end(msg, attr); | |
9367 | } | |
9368 | nla_nest_end(msg, nlbssids); | |
9369 | nla_nest_end(msg, params); | |
9370 | ||
9371 | return send_and_recv_msgs(drv, msg, NULL, NULL); | |
9372 | ||
9373 | fail: | |
9374 | nlmsg_free(msg); | |
9375 | return -1; | |
9376 | } | |
9377 | ||
b658547d | 9378 | #endif /* CONFIG_DRIVER_NL80211_QCA */ |
0800f9ee JM |
9379 | |
9380 | ||
fee354c7 JM |
9381 | static int nl80211_set_mac_addr(void *priv, const u8 *addr) |
9382 | { | |
9383 | struct i802_bss *bss = priv; | |
9384 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
9385 | int new_addr = addr != NULL; | |
9386 | ||
9ce3e610 JM |
9387 | if (TEST_FAIL()) |
9388 | return -1; | |
9389 | ||
fee354c7 JM |
9390 | if (!addr) |
9391 | addr = drv->perm_addr; | |
9392 | ||
9393 | if (linux_set_iface_flags(drv->global->ioctl_sock, bss->ifname, 0) < 0) | |
9394 | return -1; | |
9395 | ||
9396 | if (linux_set_ifhwaddr(drv->global->ioctl_sock, bss->ifname, addr) < 0) | |
9397 | { | |
9398 | wpa_printf(MSG_DEBUG, | |
9399 | "nl80211: failed to set_mac_addr for %s to " MACSTR, | |
9400 | bss->ifname, MAC2STR(addr)); | |
9401 | if (linux_set_iface_flags(drv->global->ioctl_sock, bss->ifname, | |
9402 | 1) < 0) { | |
9403 | wpa_printf(MSG_DEBUG, | |
9404 | "nl80211: Could not restore interface UP after failed set_mac_addr"); | |
9405 | } | |
9406 | return -1; | |
9407 | } | |
9408 | ||
9409 | wpa_printf(MSG_DEBUG, "nl80211: set_mac_addr for %s to " MACSTR, | |
9410 | bss->ifname, MAC2STR(addr)); | |
9411 | drv->addr_changed = new_addr; | |
9412 | os_memcpy(bss->addr, addr, ETH_ALEN); | |
9413 | ||
9414 | if (linux_set_iface_flags(drv->global->ioctl_sock, bss->ifname, 1) < 0) | |
9415 | { | |
9416 | wpa_printf(MSG_DEBUG, | |
9417 | "nl80211: Could not restore interface UP after set_mac_addr"); | |
9418 | } | |
9419 | ||
9420 | return 0; | |
9421 | } | |
9422 | ||
9423 | ||
6c1664f6 BC |
9424 | #ifdef CONFIG_MESH |
9425 | ||
9426 | static int wpa_driver_nl80211_init_mesh(void *priv) | |
9427 | { | |
9428 | if (wpa_driver_nl80211_set_mode(priv, NL80211_IFTYPE_MESH_POINT)) { | |
9429 | wpa_printf(MSG_INFO, | |
9430 | "nl80211: Failed to set interface into mesh mode"); | |
9431 | return -1; | |
9432 | } | |
9433 | return 0; | |
9434 | } | |
9435 | ||
9436 | ||
21c74e84 JM |
9437 | static int nl80211_put_mesh_id(struct nl_msg *msg, const u8 *mesh_id, |
9438 | size_t mesh_id_len) | |
9439 | { | |
9440 | if (mesh_id) { | |
21cd8f83 JM |
9441 | wpa_printf(MSG_DEBUG, " * Mesh ID (SSID)=%s", |
9442 | wpa_ssid_txt(mesh_id, mesh_id_len)); | |
21c74e84 JM |
9443 | return nla_put(msg, NL80211_ATTR_MESH_ID, mesh_id_len, mesh_id); |
9444 | } | |
9445 | ||
9446 | return 0; | |
9447 | } | |
9448 | ||
9449 | ||
4ffb3f87 MH |
9450 | static int nl80211_put_mesh_config(struct nl_msg *msg, |
9451 | struct wpa_driver_mesh_bss_params *params) | |
9452 | { | |
9453 | struct nlattr *container; | |
9454 | ||
9455 | container = nla_nest_start(msg, NL80211_ATTR_MESH_CONFIG); | |
9456 | if (!container) | |
9457 | return -1; | |
9458 | ||
2bd62171 | 9459 | if (((params->flags & WPA_DRIVER_MESH_CONF_FLAG_AUTO_PLINKS) && |
963d3149 JM |
9460 | nla_put_u8(msg, NL80211_MESHCONF_AUTO_OPEN_PLINKS, |
9461 | params->auto_plinks)) || | |
2bd62171 MH |
9462 | ((params->flags & WPA_DRIVER_MESH_CONF_FLAG_MAX_PEER_LINKS) && |
9463 | nla_put_u16(msg, NL80211_MESHCONF_MAX_PEER_LINKS, | |
31a856a1 MH |
9464 | params->max_peer_links)) || |
9465 | ((params->flags & WPA_DRIVER_MESH_CONF_FLAG_RSSI_THRESHOLD) && | |
9466 | nla_put_u32(msg, NL80211_MESHCONF_RSSI_THRESHOLD, | |
9467 | params->rssi_threshold))) | |
4ffb3f87 MH |
9468 | return -1; |
9469 | ||
9470 | /* | |
9471 | * Set NL80211_MESHCONF_PLINK_TIMEOUT even if user mpm is used because | |
9472 | * the timer could disconnect stations even in that case. | |
9473 | */ | |
2bd62171 MH |
9474 | if ((params->flags & WPA_DRIVER_MESH_CONF_FLAG_PEER_LINK_TIMEOUT) && |
9475 | nla_put_u32(msg, NL80211_MESHCONF_PLINK_TIMEOUT, | |
4ffb3f87 MH |
9476 | params->peer_link_timeout)) { |
9477 | wpa_printf(MSG_ERROR, "nl80211: Failed to set PLINK_TIMEOUT"); | |
9478 | return -1; | |
9479 | } | |
9480 | ||
052b8d38 MH |
9481 | if ((params->flags & WPA_DRIVER_MESH_CONF_FLAG_HT_OP_MODE) && |
9482 | nla_put_u16(msg, NL80211_MESHCONF_HT_OPMODE, params->ht_opmode)) { | |
9483 | wpa_printf(MSG_ERROR, "nl80211: Failed to set HT_OP_MODE"); | |
9484 | return -1; | |
9485 | } | |
9486 | ||
4ffb3f87 MH |
9487 | nla_nest_end(msg, container); |
9488 | ||
9489 | return 0; | |
9490 | } | |
9491 | ||
9492 | ||
0cb5f8d9 | 9493 | static int nl80211_join_mesh(struct i802_bss *bss, |
6c1664f6 BC |
9494 | struct wpa_driver_mesh_join_params *params) |
9495 | { | |
6c1664f6 BC |
9496 | struct wpa_driver_nl80211_data *drv = bss->drv; |
9497 | struct nl_msg *msg; | |
9498 | struct nlattr *container; | |
7451a217 | 9499 | int ret = -1; |
6c1664f6 | 9500 | |
6c1664f6 | 9501 | wpa_printf(MSG_DEBUG, "nl80211: mesh join (ifindex=%d)", drv->ifindex); |
9725b784 | 9502 | msg = nl80211_drv_msg(drv, 0, NL80211_CMD_JOIN_MESH); |
f7e889fa JM |
9503 | if (!msg || |
9504 | nl80211_put_freq_params(msg, ¶ms->freq) || | |
21c74e84 JM |
9505 | nl80211_put_basic_rates(msg, params->basic_rates) || |
9506 | nl80211_put_mesh_id(msg, params->meshid, params->meshid_len) || | |
4ac2ea57 MH |
9507 | nl80211_put_beacon_int(msg, params->beacon_int) || |
9508 | nl80211_put_dtim_period(msg, params->dtim_period)) | |
85e1fad8 | 9509 | goto fail; |
9c58c5f7 | 9510 | |
6c1664f6 BC |
9511 | wpa_printf(MSG_DEBUG, " * flags=%08X", params->flags); |
9512 | ||
9513 | container = nla_nest_start(msg, NL80211_ATTR_MESH_SETUP); | |
9514 | if (!container) | |
a862e4a3 | 9515 | goto fail; |
6c1664f6 BC |
9516 | |
9517 | if (params->ies) { | |
9518 | wpa_hexdump(MSG_DEBUG, " * IEs", params->ies, params->ie_len); | |
a862e4a3 JM |
9519 | if (nla_put(msg, NL80211_MESH_SETUP_IE, params->ie_len, |
9520 | params->ies)) | |
9521 | goto fail; | |
6c1664f6 BC |
9522 | } |
9523 | /* WPA_DRIVER_MESH_FLAG_OPEN_AUTH is treated as default by nl80211 */ | |
9524 | if (params->flags & WPA_DRIVER_MESH_FLAG_SAE_AUTH) { | |
a862e4a3 JM |
9525 | if (nla_put_u8(msg, NL80211_MESH_SETUP_AUTH_PROTOCOL, 0x1) || |
9526 | nla_put_flag(msg, NL80211_MESH_SETUP_USERSPACE_AUTH)) | |
9527 | goto fail; | |
6c1664f6 | 9528 | } |
a862e4a3 JM |
9529 | if ((params->flags & WPA_DRIVER_MESH_FLAG_AMPE) && |
9530 | nla_put_flag(msg, NL80211_MESH_SETUP_USERSPACE_AMPE)) | |
9531 | goto fail; | |
9532 | if ((params->flags & WPA_DRIVER_MESH_FLAG_USER_MPM) && | |
9533 | nla_put_flag(msg, NL80211_MESH_SETUP_USERSPACE_MPM)) | |
9534 | goto fail; | |
6c1664f6 BC |
9535 | nla_nest_end(msg, container); |
9536 | ||
2bd62171 MH |
9537 | params->conf.flags |= WPA_DRIVER_MESH_CONF_FLAG_AUTO_PLINKS; |
9538 | params->conf.flags |= WPA_DRIVER_MESH_CONF_FLAG_PEER_LINK_TIMEOUT; | |
9539 | params->conf.flags |= WPA_DRIVER_MESH_CONF_FLAG_MAX_PEER_LINKS; | |
4ffb3f87 | 9540 | if (nl80211_put_mesh_config(msg, ¶ms->conf) < 0) |
5a2a6de6 | 9541 | goto fail; |
6c1664f6 BC |
9542 | |
9543 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); | |
9544 | msg = NULL; | |
9545 | if (ret) { | |
9546 | wpa_printf(MSG_DEBUG, "nl80211: mesh join failed: ret=%d (%s)", | |
9547 | ret, strerror(-ret)); | |
a862e4a3 | 9548 | goto fail; |
6c1664f6 BC |
9549 | } |
9550 | ret = 0; | |
92a515b8 | 9551 | drv->assoc_freq = bss->freq = params->freq.freq; |
6c1664f6 BC |
9552 | wpa_printf(MSG_DEBUG, "nl80211: mesh join request send successfully"); |
9553 | ||
a862e4a3 | 9554 | fail: |
6c1664f6 BC |
9555 | nlmsg_free(msg); |
9556 | return ret; | |
9557 | } | |
9558 | ||
9559 | ||
0cb5f8d9 MH |
9560 | static int |
9561 | wpa_driver_nl80211_join_mesh(void *priv, | |
9562 | struct wpa_driver_mesh_join_params *params) | |
9563 | { | |
9564 | struct i802_bss *bss = priv; | |
9565 | int ret, timeout; | |
9566 | ||
9567 | timeout = params->conf.peer_link_timeout; | |
9568 | ||
9569 | /* Disable kernel inactivity timer */ | |
9570 | if (params->flags & WPA_DRIVER_MESH_FLAG_USER_MPM) | |
9571 | params->conf.peer_link_timeout = 0; | |
9572 | ||
9573 | ret = nl80211_join_mesh(bss, params); | |
9574 | if (ret == -EINVAL && params->conf.peer_link_timeout == 0) { | |
9575 | wpa_printf(MSG_DEBUG, | |
9576 | "nl80211: Mesh join retry for peer_link_timeout"); | |
9577 | /* | |
9578 | * Old kernel does not support setting | |
9579 | * NL80211_MESHCONF_PLINK_TIMEOUT to zero, so set 60 seconds | |
9580 | * into future from peer_link_timeout. | |
9581 | */ | |
9582 | params->conf.peer_link_timeout = timeout + 60; | |
9583 | ret = nl80211_join_mesh(priv, params); | |
9584 | } | |
9585 | ||
9586 | params->conf.peer_link_timeout = timeout; | |
9587 | return ret; | |
9588 | } | |
9589 | ||
9590 | ||
6c1664f6 BC |
9591 | static int wpa_driver_nl80211_leave_mesh(void *priv) |
9592 | { | |
9593 | struct i802_bss *bss = priv; | |
9594 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
9595 | struct nl_msg *msg; | |
9725b784 | 9596 | int ret; |
6c1664f6 BC |
9597 | |
9598 | wpa_printf(MSG_DEBUG, "nl80211: mesh leave (ifindex=%d)", drv->ifindex); | |
9725b784 | 9599 | msg = nl80211_drv_msg(drv, 0, NL80211_CMD_LEAVE_MESH); |
6c1664f6 | 9600 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
6c1664f6 BC |
9601 | if (ret) { |
9602 | wpa_printf(MSG_DEBUG, "nl80211: mesh leave failed: ret=%d (%s)", | |
9603 | ret, strerror(-ret)); | |
a862e4a3 JM |
9604 | } else { |
9605 | wpa_printf(MSG_DEBUG, | |
9606 | "nl80211: mesh leave request send successfully"); | |
6c1664f6 | 9607 | } |
6c1664f6 | 9608 | |
f33c82d2 JM |
9609 | if (wpa_driver_nl80211_set_mode(drv->first_bss, |
9610 | NL80211_IFTYPE_STATION)) { | |
9611 | wpa_printf(MSG_INFO, | |
9612 | "nl80211: Failed to set interface into station mode"); | |
9613 | } | |
6c1664f6 BC |
9614 | return ret; |
9615 | } | |
9616 | ||
9617 | #endif /* CONFIG_MESH */ | |
9618 | ||
9619 | ||
ed4ddb6d KP |
9620 | static int wpa_driver_br_add_ip_neigh(void *priv, u8 version, |
9621 | const u8 *ipaddr, int prefixlen, | |
9622 | const u8 *addr) | |
71103bed KP |
9623 | { |
9624 | #ifdef CONFIG_LIBNL3_ROUTE | |
9625 | struct i802_bss *bss = priv; | |
9626 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
9627 | struct rtnl_neigh *rn; | |
9628 | struct nl_addr *nl_ipaddr = NULL; | |
9629 | struct nl_addr *nl_lladdr = NULL; | |
ed4ddb6d | 9630 | int family, addrsize; |
71103bed KP |
9631 | int res; |
9632 | ||
ed4ddb6d | 9633 | if (!ipaddr || prefixlen == 0 || !addr) |
71103bed KP |
9634 | return -EINVAL; |
9635 | ||
9636 | if (bss->br_ifindex == 0) { | |
9637 | wpa_printf(MSG_DEBUG, | |
9638 | "nl80211: bridge must be set before adding an ip neigh to it"); | |
9639 | return -1; | |
9640 | } | |
9641 | ||
9642 | if (!drv->rtnl_sk) { | |
9643 | wpa_printf(MSG_DEBUG, | |
9644 | "nl80211: nl_sock for NETLINK_ROUTE is not initialized"); | |
9645 | return -1; | |
9646 | } | |
9647 | ||
ed4ddb6d KP |
9648 | if (version == 4) { |
9649 | family = AF_INET; | |
9650 | addrsize = 4; | |
9651 | } else if (version == 6) { | |
9652 | family = AF_INET6; | |
9653 | addrsize = 16; | |
9654 | } else { | |
9655 | return -EINVAL; | |
9656 | } | |
9657 | ||
71103bed KP |
9658 | rn = rtnl_neigh_alloc(); |
9659 | if (rn == NULL) | |
9660 | return -ENOMEM; | |
9661 | ||
9662 | /* set the destination ip address for neigh */ | |
ed4ddb6d | 9663 | nl_ipaddr = nl_addr_build(family, (void *) ipaddr, addrsize); |
71103bed KP |
9664 | if (nl_ipaddr == NULL) { |
9665 | wpa_printf(MSG_DEBUG, "nl80211: nl_ipaddr build failed"); | |
9666 | res = -ENOMEM; | |
9667 | goto errout; | |
9668 | } | |
9669 | nl_addr_set_prefixlen(nl_ipaddr, prefixlen); | |
9670 | res = rtnl_neigh_set_dst(rn, nl_ipaddr); | |
9671 | if (res) { | |
9672 | wpa_printf(MSG_DEBUG, | |
9673 | "nl80211: neigh set destination addr failed"); | |
9674 | goto errout; | |
9675 | } | |
9676 | ||
9677 | /* set the corresponding lladdr for neigh */ | |
9678 | nl_lladdr = nl_addr_build(AF_BRIDGE, (u8 *) addr, ETH_ALEN); | |
9679 | if (nl_lladdr == NULL) { | |
9680 | wpa_printf(MSG_DEBUG, "nl80211: neigh set lladdr failed"); | |
9681 | res = -ENOMEM; | |
9682 | goto errout; | |
9683 | } | |
9684 | rtnl_neigh_set_lladdr(rn, nl_lladdr); | |
9685 | ||
9686 | rtnl_neigh_set_ifindex(rn, bss->br_ifindex); | |
9687 | rtnl_neigh_set_state(rn, NUD_PERMANENT); | |
9688 | ||
9689 | res = rtnl_neigh_add(drv->rtnl_sk, rn, NLM_F_CREATE); | |
9690 | if (res) { | |
9691 | wpa_printf(MSG_DEBUG, | |
9692 | "nl80211: Adding bridge ip neigh failed: %s", | |
9693 | strerror(errno)); | |
9694 | } | |
9695 | errout: | |
9696 | if (nl_lladdr) | |
9697 | nl_addr_put(nl_lladdr); | |
9698 | if (nl_ipaddr) | |
9699 | nl_addr_put(nl_ipaddr); | |
9700 | if (rn) | |
9701 | rtnl_neigh_put(rn); | |
9702 | return res; | |
9703 | #else /* CONFIG_LIBNL3_ROUTE */ | |
9704 | return -1; | |
9705 | #endif /* CONFIG_LIBNL3_ROUTE */ | |
9706 | } | |
9707 | ||
9708 | ||
ed4ddb6d KP |
9709 | static int wpa_driver_br_delete_ip_neigh(void *priv, u8 version, |
9710 | const u8 *ipaddr) | |
71103bed KP |
9711 | { |
9712 | #ifdef CONFIG_LIBNL3_ROUTE | |
9713 | struct i802_bss *bss = priv; | |
9714 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
9715 | struct rtnl_neigh *rn; | |
9716 | struct nl_addr *nl_ipaddr; | |
ed4ddb6d | 9717 | int family, addrsize; |
71103bed KP |
9718 | int res; |
9719 | ||
ed4ddb6d | 9720 | if (!ipaddr) |
71103bed KP |
9721 | return -EINVAL; |
9722 | ||
ed4ddb6d KP |
9723 | if (version == 4) { |
9724 | family = AF_INET; | |
9725 | addrsize = 4; | |
9726 | } else if (version == 6) { | |
9727 | family = AF_INET6; | |
9728 | addrsize = 16; | |
9729 | } else { | |
9730 | return -EINVAL; | |
9731 | } | |
9732 | ||
71103bed KP |
9733 | if (bss->br_ifindex == 0) { |
9734 | wpa_printf(MSG_DEBUG, | |
9735 | "nl80211: bridge must be set to delete an ip neigh"); | |
9736 | return -1; | |
9737 | } | |
9738 | ||
9739 | if (!drv->rtnl_sk) { | |
9740 | wpa_printf(MSG_DEBUG, | |
9741 | "nl80211: nl_sock for NETLINK_ROUTE is not initialized"); | |
9742 | return -1; | |
9743 | } | |
9744 | ||
9745 | rn = rtnl_neigh_alloc(); | |
9746 | if (rn == NULL) | |
9747 | return -ENOMEM; | |
9748 | ||
9749 | /* set the destination ip address for neigh */ | |
ed4ddb6d | 9750 | nl_ipaddr = nl_addr_build(family, (void *) ipaddr, addrsize); |
71103bed KP |
9751 | if (nl_ipaddr == NULL) { |
9752 | wpa_printf(MSG_DEBUG, "nl80211: nl_ipaddr build failed"); | |
9753 | res = -ENOMEM; | |
9754 | goto errout; | |
9755 | } | |
9756 | res = rtnl_neigh_set_dst(rn, nl_ipaddr); | |
9757 | if (res) { | |
9758 | wpa_printf(MSG_DEBUG, | |
9759 | "nl80211: neigh set destination addr failed"); | |
9760 | goto errout; | |
9761 | } | |
9762 | ||
9763 | rtnl_neigh_set_ifindex(rn, bss->br_ifindex); | |
9764 | ||
9765 | res = rtnl_neigh_delete(drv->rtnl_sk, rn, 0); | |
9766 | if (res) { | |
9767 | wpa_printf(MSG_DEBUG, | |
9768 | "nl80211: Deleting bridge ip neigh failed: %s", | |
9769 | strerror(errno)); | |
9770 | } | |
9771 | errout: | |
9772 | if (nl_ipaddr) | |
9773 | nl_addr_put(nl_ipaddr); | |
9774 | if (rn) | |
9775 | rtnl_neigh_put(rn); | |
9776 | return res; | |
9777 | #else /* CONFIG_LIBNL3_ROUTE */ | |
9778 | return -1; | |
9779 | #endif /* CONFIG_LIBNL3_ROUTE */ | |
9780 | } | |
9781 | ||
9782 | ||
73d2294f KP |
9783 | static int linux_write_system_file(const char *path, unsigned int val) |
9784 | { | |
9785 | char buf[50]; | |
9786 | int fd, len; | |
9787 | ||
9788 | len = os_snprintf(buf, sizeof(buf), "%u\n", val); | |
a9aaacbb | 9789 | if (os_snprintf_error(sizeof(buf), len)) |
73d2294f KP |
9790 | return -1; |
9791 | ||
9792 | fd = open(path, O_WRONLY); | |
9793 | if (fd < 0) | |
9794 | return -1; | |
9795 | ||
9796 | if (write(fd, buf, len) < 0) { | |
9797 | wpa_printf(MSG_DEBUG, | |
9798 | "nl80211: Failed to write Linux system file: %s with the value of %d", | |
9799 | path, val); | |
9800 | close(fd); | |
9801 | return -1; | |
9802 | } | |
9803 | close(fd); | |
9804 | ||
9805 | return 0; | |
9806 | } | |
9807 | ||
9808 | ||
9809 | static const char * drv_br_port_attr_str(enum drv_br_port_attr attr) | |
9810 | { | |
9811 | switch (attr) { | |
9812 | case DRV_BR_PORT_ATTR_PROXYARP: | |
bea8d9a3 | 9813 | return "proxyarp_wifi"; |
73d2294f KP |
9814 | case DRV_BR_PORT_ATTR_HAIRPIN_MODE: |
9815 | return "hairpin_mode"; | |
9816 | } | |
9817 | ||
9818 | return NULL; | |
9819 | } | |
9820 | ||
9821 | ||
9822 | static int wpa_driver_br_port_set_attr(void *priv, enum drv_br_port_attr attr, | |
9823 | unsigned int val) | |
9824 | { | |
9825 | struct i802_bss *bss = priv; | |
9826 | char path[128]; | |
9827 | const char *attr_txt; | |
9828 | ||
9829 | attr_txt = drv_br_port_attr_str(attr); | |
9830 | if (attr_txt == NULL) | |
9831 | return -EINVAL; | |
9832 | ||
9833 | os_snprintf(path, sizeof(path), "/sys/class/net/%s/brport/%s", | |
9834 | bss->ifname, attr_txt); | |
9835 | ||
9836 | if (linux_write_system_file(path, val)) | |
9837 | return -1; | |
9838 | ||
9839 | return 0; | |
9840 | } | |
9841 | ||
9842 | ||
7565752d KP |
9843 | static const char * drv_br_net_param_str(enum drv_br_net_param param) |
9844 | { | |
9845 | switch (param) { | |
9846 | case DRV_BR_NET_PARAM_GARP_ACCEPT: | |
9847 | return "arp_accept"; | |
60eb9e17 JM |
9848 | default: |
9849 | return NULL; | |
7565752d | 9850 | } |
7565752d KP |
9851 | } |
9852 | ||
9853 | ||
9854 | static int wpa_driver_br_set_net_param(void *priv, enum drv_br_net_param param, | |
9855 | unsigned int val) | |
9856 | { | |
9857 | struct i802_bss *bss = priv; | |
9858 | char path[128]; | |
9859 | const char *param_txt; | |
9860 | int ip_version = 4; | |
9861 | ||
60eb9e17 JM |
9862 | if (param == DRV_BR_MULTICAST_SNOOPING) { |
9863 | os_snprintf(path, sizeof(path), | |
9864 | "/sys/devices/virtual/net/%s/bridge/multicast_snooping", | |
9865 | bss->brname); | |
9866 | goto set_val; | |
9867 | } | |
9868 | ||
7565752d KP |
9869 | param_txt = drv_br_net_param_str(param); |
9870 | if (param_txt == NULL) | |
9871 | return -EINVAL; | |
9872 | ||
9873 | switch (param) { | |
9874 | case DRV_BR_NET_PARAM_GARP_ACCEPT: | |
9875 | ip_version = 4; | |
9876 | break; | |
9877 | default: | |
9878 | return -EINVAL; | |
9879 | } | |
9880 | ||
9881 | os_snprintf(path, sizeof(path), "/proc/sys/net/ipv%d/conf/%s/%s", | |
9882 | ip_version, bss->brname, param_txt); | |
9883 | ||
60eb9e17 | 9884 | set_val: |
7565752d KP |
9885 | if (linux_write_system_file(path, val)) |
9886 | return -1; | |
9887 | ||
9888 | return 0; | |
9889 | } | |
9890 | ||
9891 | ||
b658547d JM |
9892 | #ifdef CONFIG_DRIVER_NL80211_QCA |
9893 | ||
16689c7c PX |
9894 | static int hw_mode_to_qca_acs(enum hostapd_hw_mode hw_mode) |
9895 | { | |
9896 | switch (hw_mode) { | |
9897 | case HOSTAPD_MODE_IEEE80211B: | |
9898 | return QCA_ACS_MODE_IEEE80211B; | |
9899 | case HOSTAPD_MODE_IEEE80211G: | |
9900 | return QCA_ACS_MODE_IEEE80211G; | |
9901 | case HOSTAPD_MODE_IEEE80211A: | |
9902 | return QCA_ACS_MODE_IEEE80211A; | |
9903 | case HOSTAPD_MODE_IEEE80211AD: | |
9904 | return QCA_ACS_MODE_IEEE80211AD; | |
3784c058 PX |
9905 | case HOSTAPD_MODE_IEEE80211ANY: |
9906 | return QCA_ACS_MODE_IEEE80211ANY; | |
16689c7c PX |
9907 | default: |
9908 | return -1; | |
9909 | } | |
9910 | } | |
9911 | ||
9912 | ||
d0cdccd3 PX |
9913 | static int add_acs_freq_list(struct nl_msg *msg, const int *freq_list) |
9914 | { | |
9915 | int i, len, ret; | |
9916 | u32 *freqs; | |
9917 | ||
9918 | if (!freq_list) | |
9919 | return 0; | |
9920 | len = int_array_len(freq_list); | |
9921 | freqs = os_malloc(sizeof(u32) * len); | |
9922 | if (!freqs) | |
9923 | return -1; | |
9924 | for (i = 0; i < len; i++) | |
9925 | freqs[i] = freq_list[i]; | |
9926 | ret = nla_put(msg, QCA_WLAN_VENDOR_ATTR_ACS_FREQ_LIST, | |
9927 | sizeof(u32) * len, freqs); | |
9928 | os_free(freqs); | |
9929 | return ret; | |
9930 | } | |
9931 | ||
9932 | ||
16689c7c PX |
9933 | static int wpa_driver_do_acs(void *priv, struct drv_acs_params *params) |
9934 | { | |
9935 | struct i802_bss *bss = priv; | |
9936 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
9937 | struct nl_msg *msg; | |
9938 | struct nlattr *data; | |
a862e4a3 | 9939 | int ret; |
16689c7c PX |
9940 | int mode; |
9941 | ||
9942 | mode = hw_mode_to_qca_acs(params->hw_mode); | |
9943 | if (mode < 0) | |
9944 | return -1; | |
9945 | ||
9725b784 | 9946 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_VENDOR)) || |
a862e4a3 JM |
9947 | nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) || |
9948 | nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD, | |
9949 | QCA_NL80211_VENDOR_SUBCMD_DO_ACS) || | |
9950 | !(data = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) || | |
9951 | nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_ACS_HW_MODE, mode) || | |
9952 | (params->ht_enabled && | |
9953 | nla_put_flag(msg, QCA_WLAN_VENDOR_ATTR_ACS_HT_ENABLED)) || | |
9954 | (params->ht40_enabled && | |
857d9422 MM |
9955 | nla_put_flag(msg, QCA_WLAN_VENDOR_ATTR_ACS_HT40_ENABLED)) || |
9956 | (params->vht_enabled && | |
9957 | nla_put_flag(msg, QCA_WLAN_VENDOR_ATTR_ACS_VHT_ENABLED)) || | |
9958 | nla_put_u16(msg, QCA_WLAN_VENDOR_ATTR_ACS_CHWIDTH, | |
9959 | params->ch_width) || | |
9960 | (params->ch_list_len && | |
9961 | nla_put(msg, QCA_WLAN_VENDOR_ATTR_ACS_CH_LIST, params->ch_list_len, | |
d0cdccd3 PX |
9962 | params->ch_list)) || |
9963 | add_acs_freq_list(msg, params->freq_list)) { | |
a862e4a3 JM |
9964 | nlmsg_free(msg); |
9965 | return -ENOBUFS; | |
9966 | } | |
16689c7c PX |
9967 | nla_nest_end(msg, data); |
9968 | ||
857d9422 MM |
9969 | wpa_printf(MSG_DEBUG, |
9970 | "nl80211: ACS Params: HW_MODE: %d HT: %d HT40: %d VHT: %d BW: %d CH_LIST_LEN: %u", | |
9971 | params->hw_mode, params->ht_enabled, params->ht40_enabled, | |
9972 | params->vht_enabled, params->ch_width, params->ch_list_len); | |
9973 | ||
16689c7c | 9974 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
16689c7c PX |
9975 | if (ret) { |
9976 | wpa_printf(MSG_DEBUG, | |
9977 | "nl80211: Failed to invoke driver ACS function: %s", | |
9978 | strerror(errno)); | |
9979 | } | |
16689c7c PX |
9980 | return ret; |
9981 | } | |
9982 | ||
9983 | ||
844dfeb8 SD |
9984 | static int nl80211_set_band(void *priv, enum set_band band) |
9985 | { | |
9986 | struct i802_bss *bss = priv; | |
9987 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
9988 | struct nl_msg *msg; | |
9989 | struct nlattr *data; | |
9990 | int ret; | |
9991 | enum qca_set_band qca_band; | |
9992 | ||
9993 | if (!drv->setband_vendor_cmd_avail) | |
9994 | return -1; | |
9995 | ||
9996 | switch (band) { | |
9997 | case WPA_SETBAND_AUTO: | |
9998 | qca_band = QCA_SETBAND_AUTO; | |
9999 | break; | |
10000 | case WPA_SETBAND_5G: | |
10001 | qca_band = QCA_SETBAND_5G; | |
10002 | break; | |
10003 | case WPA_SETBAND_2G: | |
10004 | qca_band = QCA_SETBAND_2G; | |
10005 | break; | |
10006 | default: | |
10007 | return -1; | |
10008 | } | |
10009 | ||
10010 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_VENDOR)) || | |
10011 | nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) || | |
10012 | nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD, | |
10013 | QCA_NL80211_VENDOR_SUBCMD_SETBAND) || | |
10014 | !(data = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) || | |
10015 | nla_put_u32(msg, QCA_WLAN_VENDOR_ATTR_SETBAND_VALUE, qca_band)) { | |
10016 | nlmsg_free(msg); | |
10017 | return -ENOBUFS; | |
10018 | } | |
10019 | nla_nest_end(msg, data); | |
10020 | ||
10021 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); | |
10022 | if (ret) { | |
10023 | wpa_printf(MSG_DEBUG, | |
10024 | "nl80211: Driver setband function failed: %s", | |
10025 | strerror(errno)); | |
10026 | } | |
10027 | return ret; | |
10028 | } | |
10029 | ||
10030 | ||
98342208 AK |
10031 | struct nl80211_pcl { |
10032 | unsigned int num; | |
10033 | unsigned int *freq_list; | |
10034 | }; | |
10035 | ||
10036 | static int preferred_freq_info_handler(struct nl_msg *msg, void *arg) | |
10037 | { | |
10038 | struct nlattr *tb[NL80211_ATTR_MAX + 1]; | |
10039 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); | |
10040 | struct nl80211_pcl *param = arg; | |
10041 | struct nlattr *nl_vend, *attr; | |
10042 | enum qca_iface_type iface_type; | |
10043 | struct nlattr *tb_vendor[QCA_WLAN_VENDOR_ATTR_MAX + 1]; | |
10044 | unsigned int num, max_num; | |
10045 | u32 *freqs; | |
10046 | ||
10047 | nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), | |
10048 | genlmsg_attrlen(gnlh, 0), NULL); | |
10049 | ||
10050 | nl_vend = tb[NL80211_ATTR_VENDOR_DATA]; | |
10051 | if (!nl_vend) | |
10052 | return NL_SKIP; | |
10053 | ||
10054 | nla_parse(tb_vendor, QCA_WLAN_VENDOR_ATTR_MAX, | |
10055 | nla_data(nl_vend), nla_len(nl_vend), NULL); | |
10056 | ||
10057 | attr = tb_vendor[ | |
10058 | QCA_WLAN_VENDOR_ATTR_GET_PREFERRED_FREQ_LIST_IFACE_TYPE]; | |
10059 | if (!attr) { | |
10060 | wpa_printf(MSG_ERROR, "nl80211: iface_type couldn't be found"); | |
10061 | param->num = 0; | |
10062 | return NL_SKIP; | |
10063 | } | |
10064 | ||
10065 | iface_type = (enum qca_iface_type) nla_get_u32(attr); | |
10066 | wpa_printf(MSG_DEBUG, "nl80211: Driver returned iface_type=%d", | |
10067 | iface_type); | |
10068 | ||
10069 | attr = tb_vendor[QCA_WLAN_VENDOR_ATTR_GET_PREFERRED_FREQ_LIST]; | |
10070 | if (!attr) { | |
10071 | wpa_printf(MSG_ERROR, | |
10072 | "nl80211: preferred_freq_list couldn't be found"); | |
10073 | param->num = 0; | |
10074 | return NL_SKIP; | |
10075 | } | |
10076 | ||
10077 | /* | |
10078 | * param->num has the maximum number of entries for which there | |
10079 | * is room in the freq_list provided by the caller. | |
10080 | */ | |
10081 | freqs = nla_data(attr); | |
10082 | max_num = nla_len(attr) / sizeof(u32); | |
10083 | if (max_num > param->num) | |
10084 | max_num = param->num; | |
10085 | for (num = 0; num < max_num; num++) | |
10086 | param->freq_list[num] = freqs[num]; | |
10087 | param->num = num; | |
10088 | ||
10089 | return NL_SKIP; | |
10090 | } | |
10091 | ||
10092 | ||
10093 | static int nl80211_get_pref_freq_list(void *priv, | |
10094 | enum wpa_driver_if_type if_type, | |
10095 | unsigned int *num, | |
10096 | unsigned int *freq_list) | |
10097 | { | |
10098 | struct i802_bss *bss = priv; | |
10099 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
10100 | struct nl_msg *msg; | |
10101 | int ret; | |
10102 | unsigned int i; | |
10103 | struct nlattr *params; | |
10104 | struct nl80211_pcl param; | |
10105 | enum qca_iface_type iface_type; | |
10106 | ||
10107 | if (!drv->get_pref_freq_list) | |
10108 | return -1; | |
10109 | ||
10110 | switch (if_type) { | |
10111 | case WPA_IF_STATION: | |
10112 | iface_type = QCA_IFACE_TYPE_STA; | |
10113 | break; | |
10114 | case WPA_IF_AP_BSS: | |
10115 | iface_type = QCA_IFACE_TYPE_AP; | |
10116 | break; | |
10117 | case WPA_IF_P2P_GO: | |
10118 | iface_type = QCA_IFACE_TYPE_P2P_GO; | |
10119 | break; | |
10120 | case WPA_IF_P2P_CLIENT: | |
10121 | iface_type = QCA_IFACE_TYPE_P2P_CLIENT; | |
10122 | break; | |
10123 | case WPA_IF_IBSS: | |
10124 | iface_type = QCA_IFACE_TYPE_IBSS; | |
10125 | break; | |
10126 | case WPA_IF_TDLS: | |
10127 | iface_type = QCA_IFACE_TYPE_TDLS; | |
10128 | break; | |
10129 | default: | |
10130 | return -1; | |
10131 | } | |
10132 | ||
10133 | param.num = *num; | |
10134 | param.freq_list = freq_list; | |
10135 | ||
10136 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_VENDOR)) || | |
10137 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, drv->ifindex) || | |
10138 | nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) || | |
10139 | nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD, | |
10140 | QCA_NL80211_VENDOR_SUBCMD_GET_PREFERRED_FREQ_LIST) || | |
10141 | !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) || | |
10142 | nla_put_u32(msg, | |
10143 | QCA_WLAN_VENDOR_ATTR_GET_PREFERRED_FREQ_LIST_IFACE_TYPE, | |
10144 | iface_type)) { | |
10145 | wpa_printf(MSG_ERROR, | |
10146 | "%s: err in adding vendor_cmd and vendor_data", | |
10147 | __func__); | |
10148 | nlmsg_free(msg); | |
10149 | return -1; | |
10150 | } | |
10151 | nla_nest_end(msg, params); | |
10152 | ||
10153 | os_memset(freq_list, 0, *num * sizeof(freq_list[0])); | |
10154 | ret = send_and_recv_msgs(drv, msg, preferred_freq_info_handler, ¶m); | |
10155 | if (ret) { | |
10156 | wpa_printf(MSG_ERROR, | |
10157 | "%s: err in send_and_recv_msgs", __func__); | |
10158 | return ret; | |
10159 | } | |
10160 | ||
10161 | *num = param.num; | |
10162 | ||
10163 | for (i = 0; i < *num; i++) { | |
10164 | wpa_printf(MSG_DEBUG, "nl80211: preferred_channel_list[%d]=%d", | |
10165 | i, freq_list[i]); | |
10166 | } | |
10167 | ||
10168 | return 0; | |
10169 | } | |
10170 | ||
10171 | ||
7c813acf AK |
10172 | static int nl80211_set_prob_oper_freq(void *priv, unsigned int freq) |
10173 | { | |
10174 | struct i802_bss *bss = priv; | |
10175 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
10176 | struct nl_msg *msg; | |
10177 | int ret; | |
10178 | struct nlattr *params; | |
10179 | ||
10180 | if (!drv->set_prob_oper_freq) | |
10181 | return -1; | |
10182 | ||
10183 | wpa_printf(MSG_DEBUG, | |
10184 | "nl80211: Set P2P probable operating freq %u for ifindex %d", | |
10185 | freq, bss->ifindex); | |
10186 | ||
10187 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_VENDOR)) || | |
10188 | nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) || | |
10189 | nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD, | |
10190 | QCA_NL80211_VENDOR_SUBCMD_SET_PROBABLE_OPER_CHANNEL) || | |
10191 | !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) || | |
10192 | nla_put_u32(msg, | |
10193 | QCA_WLAN_VENDOR_ATTR_PROBABLE_OPER_CHANNEL_IFACE_TYPE, | |
10194 | QCA_IFACE_TYPE_P2P_CLIENT) || | |
10195 | nla_put_u32(msg, | |
10196 | QCA_WLAN_VENDOR_ATTR_PROBABLE_OPER_CHANNEL_FREQ, | |
10197 | freq)) { | |
10198 | wpa_printf(MSG_ERROR, | |
10199 | "%s: err in adding vendor_cmd and vendor_data", | |
10200 | __func__); | |
10201 | nlmsg_free(msg); | |
10202 | return -1; | |
10203 | } | |
10204 | nla_nest_end(msg, params); | |
10205 | ||
10206 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); | |
10207 | msg = NULL; | |
10208 | if (ret) { | |
10209 | wpa_printf(MSG_ERROR, "%s: err in send_and_recv_msgs", | |
10210 | __func__); | |
10211 | return ret; | |
10212 | } | |
10213 | nlmsg_free(msg); | |
10214 | return 0; | |
10215 | } | |
10216 | ||
a6f5b193 PX |
10217 | |
10218 | static int nl80211_p2p_lo_start(void *priv, unsigned int freq, | |
10219 | unsigned int period, unsigned int interval, | |
10220 | unsigned int count, const u8 *device_types, | |
10221 | size_t dev_types_len, | |
10222 | const u8 *ies, size_t ies_len) | |
10223 | { | |
10224 | struct i802_bss *bss = priv; | |
10225 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
10226 | struct nl_msg *msg; | |
10227 | struct nlattr *container; | |
10228 | int ret; | |
10229 | ||
10230 | wpa_printf(MSG_DEBUG, | |
10231 | "nl80211: Start P2P Listen offload: freq=%u, period=%u, interval=%u, count=%u", | |
10232 | freq, period, interval, count); | |
10233 | ||
10234 | if (!(drv->capa.flags & WPA_DRIVER_FLAGS_P2P_LISTEN_OFFLOAD)) | |
10235 | return -1; | |
10236 | ||
10237 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_VENDOR)) || | |
10238 | nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) || | |
10239 | nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD, | |
10240 | QCA_NL80211_VENDOR_SUBCMD_P2P_LISTEN_OFFLOAD_START)) | |
10241 | goto fail; | |
10242 | ||
10243 | container = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA); | |
10244 | if (!container) | |
10245 | goto fail; | |
10246 | ||
10247 | if (nla_put_u32(msg, QCA_WLAN_VENDOR_ATTR_P2P_LISTEN_OFFLOAD_CHANNEL, | |
10248 | freq) || | |
10249 | nla_put_u32(msg, QCA_WLAN_VENDOR_ATTR_P2P_LISTEN_OFFLOAD_PERIOD, | |
10250 | period) || | |
10251 | nla_put_u32(msg, QCA_WLAN_VENDOR_ATTR_P2P_LISTEN_OFFLOAD_INTERVAL, | |
10252 | interval) || | |
10253 | nla_put_u32(msg, QCA_WLAN_VENDOR_ATTR_P2P_LISTEN_OFFLOAD_COUNT, | |
10254 | count) || | |
10255 | nla_put(msg, QCA_WLAN_VENDOR_ATTR_P2P_LISTEN_OFFLOAD_DEVICE_TYPES, | |
10256 | dev_types_len, device_types) || | |
10257 | nla_put(msg, QCA_WLAN_VENDOR_ATTR_P2P_LISTEN_OFFLOAD_VENDOR_IE, | |
10258 | ies_len, ies)) | |
10259 | goto fail; | |
10260 | ||
10261 | nla_nest_end(msg, container); | |
10262 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); | |
10263 | msg = NULL; | |
10264 | if (ret) { | |
10265 | wpa_printf(MSG_DEBUG, | |
10266 | "nl80211: Failed to send P2P Listen offload vendor command"); | |
10267 | goto fail; | |
10268 | } | |
10269 | ||
10270 | return 0; | |
10271 | ||
10272 | fail: | |
10273 | nlmsg_free(msg); | |
10274 | return -1; | |
10275 | } | |
10276 | ||
10277 | ||
10278 | static int nl80211_p2p_lo_stop(void *priv) | |
10279 | { | |
10280 | struct i802_bss *bss = priv; | |
10281 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
10282 | struct nl_msg *msg; | |
10283 | ||
10284 | wpa_printf(MSG_DEBUG, "nl80211: Stop P2P Listen offload"); | |
10285 | ||
10286 | if (!(drv->capa.flags & WPA_DRIVER_FLAGS_P2P_LISTEN_OFFLOAD)) | |
10287 | return -1; | |
10288 | ||
10289 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_VENDOR)) || | |
10290 | nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) || | |
10291 | nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD, | |
10292 | QCA_NL80211_VENDOR_SUBCMD_P2P_LISTEN_OFFLOAD_STOP)) { | |
10293 | nlmsg_free(msg); | |
10294 | return -1; | |
10295 | } | |
10296 | ||
10297 | return send_and_recv_msgs(drv, msg, NULL, NULL); | |
10298 | } | |
10299 | ||
2e4e4fb7 SD |
10300 | |
10301 | static int nl80211_set_tdls_mode(void *priv, int tdls_external_control) | |
10302 | { | |
10303 | struct i802_bss *bss = priv; | |
10304 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
10305 | struct nl_msg *msg; | |
10306 | struct nlattr *params; | |
10307 | int ret; | |
10308 | u32 tdls_mode; | |
10309 | ||
10310 | wpa_printf(MSG_DEBUG, | |
10311 | "nl80211: Set TDKS mode: tdls_external_control=%d", | |
10312 | tdls_external_control); | |
10313 | ||
10314 | if (tdls_external_control == 1) | |
10315 | tdls_mode = QCA_WLAN_VENDOR_TDLS_TRIGGER_MODE_IMPLICIT | | |
10316 | QCA_WLAN_VENDOR_TDLS_TRIGGER_MODE_EXTERNAL; | |
10317 | else | |
10318 | tdls_mode = QCA_WLAN_VENDOR_TDLS_TRIGGER_MODE_EXPLICIT; | |
10319 | ||
10320 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_VENDOR)) || | |
10321 | nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) || | |
10322 | nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD, | |
10323 | QCA_NL80211_VENDOR_SUBCMD_CONFIGURE_TDLS)) | |
10324 | goto fail; | |
10325 | ||
10326 | params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA); | |
10327 | if (!params) | |
10328 | goto fail; | |
10329 | ||
10330 | if (nla_put_u32(msg, QCA_WLAN_VENDOR_ATTR_TDLS_CONFIG_TRIGGER_MODE, | |
10331 | tdls_mode)) | |
10332 | goto fail; | |
10333 | ||
10334 | nla_nest_end(msg, params); | |
10335 | ||
10336 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); | |
10337 | msg = NULL; | |
10338 | if (ret) { | |
10339 | wpa_printf(MSG_ERROR, | |
10340 | "nl80211: Set TDLS mode failed: ret=%d (%s)", | |
10341 | ret, strerror(-ret)); | |
10342 | goto fail; | |
10343 | } | |
10344 | return 0; | |
10345 | fail: | |
10346 | nlmsg_free(msg); | |
10347 | return -1; | |
10348 | } | |
10349 | ||
3ab48492 KV |
10350 | |
10351 | #ifdef CONFIG_MBO | |
10352 | ||
10353 | static enum mbo_transition_reject_reason | |
10354 | nl80211_mbo_reject_reason_mapping(enum qca_wlan_btm_candidate_status status) | |
10355 | { | |
10356 | switch (status) { | |
10357 | case QCA_STATUS_REJECT_EXCESSIVE_FRAME_LOSS_EXPECTED: | |
10358 | return MBO_TRANSITION_REJECT_REASON_FRAME_LOSS; | |
10359 | case QCA_STATUS_REJECT_EXCESSIVE_DELAY_EXPECTED: | |
10360 | return MBO_TRANSITION_REJECT_REASON_DELAY; | |
10361 | case QCA_STATUS_REJECT_INSUFFICIENT_QOS_CAPACITY: | |
10362 | return MBO_TRANSITION_REJECT_REASON_QOS_CAPACITY; | |
10363 | case QCA_STATUS_REJECT_LOW_RSSI: | |
10364 | return MBO_TRANSITION_REJECT_REASON_RSSI; | |
10365 | case QCA_STATUS_REJECT_HIGH_INTERFERENCE: | |
10366 | return MBO_TRANSITION_REJECT_REASON_INTERFERENCE; | |
10367 | case QCA_STATUS_REJECT_UNKNOWN: | |
10368 | default: | |
10369 | return MBO_TRANSITION_REJECT_REASON_UNSPECIFIED; | |
10370 | } | |
10371 | } | |
10372 | ||
10373 | ||
10374 | static void nl80211_parse_btm_candidate_info(struct candidate_list *candidate, | |
10375 | struct nlattr *tb[], int num) | |
10376 | { | |
10377 | enum qca_wlan_btm_candidate_status status; | |
10378 | char buf[50]; | |
10379 | ||
10380 | os_memcpy(candidate->bssid, | |
10381 | nla_data(tb[QCA_WLAN_VENDOR_ATTR_BTM_CANDIDATE_INFO_BSSID]), | |
10382 | ETH_ALEN); | |
10383 | ||
10384 | status = nla_get_u32( | |
10385 | tb[QCA_WLAN_VENDOR_ATTR_BTM_CANDIDATE_INFO_STATUS]); | |
10386 | candidate->is_accept = status == QCA_STATUS_ACCEPT; | |
10387 | candidate->reject_reason = nl80211_mbo_reject_reason_mapping(status); | |
10388 | ||
10389 | if (candidate->is_accept) | |
10390 | os_snprintf(buf, sizeof(buf), "Accepted"); | |
10391 | else | |
10392 | os_snprintf(buf, sizeof(buf), | |
10393 | "Rejected, Reject_reason: %d", | |
10394 | candidate->reject_reason); | |
10395 | wpa_printf(MSG_DEBUG, "nl80211: BSSID[%d]: " MACSTR " %s", | |
10396 | num, MAC2STR(candidate->bssid), buf); | |
10397 | } | |
10398 | ||
10399 | ||
10400 | static int | |
10401 | nl80211_get_bss_transition_status_handler(struct nl_msg *msg, void *arg) | |
10402 | { | |
10403 | struct wpa_bss_candidate_info *info = arg; | |
10404 | struct candidate_list *candidate = info->candidates; | |
10405 | struct nlattr *tb_msg[NL80211_ATTR_MAX + 1]; | |
10406 | struct nlattr *tb_vendor[QCA_WLAN_VENDOR_ATTR_MAX + 1]; | |
10407 | struct nlattr *tb[QCA_WLAN_VENDOR_ATTR_BTM_CANDIDATE_INFO_MAX + 1]; | |
10408 | static struct nla_policy policy[ | |
10409 | QCA_WLAN_VENDOR_ATTR_BTM_CANDIDATE_INFO_MAX + 1] = { | |
10410 | [QCA_WLAN_VENDOR_ATTR_BTM_CANDIDATE_INFO_BSSID] = { | |
10411 | .minlen = ETH_ALEN | |
10412 | }, | |
10413 | [QCA_WLAN_VENDOR_ATTR_BTM_CANDIDATE_INFO_STATUS] = { | |
10414 | .type = NLA_U32, | |
10415 | }, | |
10416 | }; | |
10417 | struct nlattr *attr; | |
10418 | int rem; | |
10419 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); | |
10420 | u8 num; | |
10421 | ||
10422 | num = info->num; /* number of candidates sent to driver */ | |
10423 | info->num = 0; | |
10424 | nla_parse(tb_msg, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), | |
10425 | genlmsg_attrlen(gnlh, 0), NULL); | |
10426 | ||
10427 | if (!tb_msg[NL80211_ATTR_VENDOR_DATA] || | |
10428 | nla_parse_nested(tb_vendor, QCA_WLAN_VENDOR_ATTR_MAX, | |
10429 | tb_msg[NL80211_ATTR_VENDOR_DATA], NULL) || | |
10430 | !tb_vendor[QCA_WLAN_VENDOR_ATTR_BTM_CANDIDATE_INFO]) | |
10431 | return NL_SKIP; | |
10432 | ||
10433 | wpa_printf(MSG_DEBUG, | |
10434 | "nl80211: WNM Candidate list received from driver"); | |
10435 | nla_for_each_nested(attr, | |
10436 | tb_vendor[QCA_WLAN_VENDOR_ATTR_BTM_CANDIDATE_INFO], | |
10437 | rem) { | |
10438 | if (info->num >= num || | |
10439 | nla_parse_nested( | |
10440 | tb, QCA_WLAN_VENDOR_ATTR_BTM_CANDIDATE_INFO_MAX, | |
10441 | attr, policy) || | |
10442 | !tb[QCA_WLAN_VENDOR_ATTR_BTM_CANDIDATE_INFO_BSSID] || | |
10443 | !tb[QCA_WLAN_VENDOR_ATTR_BTM_CANDIDATE_INFO_STATUS]) | |
10444 | break; | |
10445 | ||
10446 | nl80211_parse_btm_candidate_info(candidate, tb, info->num); | |
10447 | ||
10448 | candidate++; | |
10449 | info->num++; | |
10450 | } | |
10451 | ||
10452 | return NL_SKIP; | |
10453 | } | |
10454 | ||
10455 | ||
10456 | static struct wpa_bss_candidate_info * | |
10457 | nl80211_get_bss_transition_status(void *priv, struct wpa_bss_trans_info *params) | |
10458 | { | |
10459 | struct i802_bss *bss = priv; | |
10460 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
10461 | struct nl_msg *msg; | |
10462 | struct nlattr *attr, *attr1, *attr2; | |
10463 | struct wpa_bss_candidate_info *info; | |
10464 | u8 i; | |
10465 | int ret; | |
10466 | u8 *pos; | |
10467 | ||
10468 | if (!drv->fetch_bss_trans_status) | |
10469 | return NULL; | |
10470 | ||
10471 | info = os_zalloc(sizeof(*info)); | |
10472 | if (!info) | |
10473 | return NULL; | |
10474 | /* Allocate memory for number of candidates sent to driver */ | |
10475 | info->candidates = os_calloc(params->n_candidates, | |
10476 | sizeof(*info->candidates)); | |
10477 | if (!info->candidates) { | |
10478 | os_free(info); | |
10479 | return NULL; | |
10480 | } | |
10481 | ||
10482 | /* Copy the number of candidates being sent to driver. This is used in | |
10483 | * nl80211_get_bss_transition_status_handler() to limit the number of | |
10484 | * candidates that can be populated in info->candidates and will be | |
10485 | * later overwritten with the actual number of candidates received from | |
10486 | * the driver. | |
10487 | */ | |
10488 | info->num = params->n_candidates; | |
10489 | ||
10490 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_VENDOR)) || | |
10491 | nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) || | |
10492 | nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD, | |
10493 | QCA_NL80211_VENDOR_SUBCMD_FETCH_BSS_TRANSITION_STATUS)) | |
10494 | goto fail; | |
10495 | ||
10496 | attr = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA); | |
10497 | if (!attr) | |
10498 | goto fail; | |
10499 | ||
10500 | if (nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_BTM_MBO_TRANSITION_REASON, | |
10501 | params->mbo_transition_reason)) | |
10502 | goto fail; | |
10503 | ||
10504 | attr1 = nla_nest_start(msg, QCA_WLAN_VENDOR_ATTR_BTM_CANDIDATE_INFO); | |
10505 | if (!attr1) | |
10506 | goto fail; | |
10507 | ||
10508 | wpa_printf(MSG_DEBUG, | |
10509 | "nl80211: WNM Candidate list info sending to driver: mbo_transition_reason: %d n_candidates: %d", | |
10510 | params->mbo_transition_reason, params->n_candidates); | |
10511 | pos = params->bssid; | |
10512 | for (i = 0; i < params->n_candidates; i++) { | |
10513 | wpa_printf(MSG_DEBUG, "nl80211: BSSID[%d]: " MACSTR, i, | |
10514 | MAC2STR(pos)); | |
10515 | attr2 = nla_nest_start(msg, i); | |
10516 | if (!attr2 || | |
10517 | nla_put(msg, QCA_WLAN_VENDOR_ATTR_BTM_CANDIDATE_INFO_BSSID, | |
10518 | ETH_ALEN, pos)) | |
10519 | goto fail; | |
10520 | pos += ETH_ALEN; | |
10521 | nla_nest_end(msg, attr2); | |
10522 | } | |
10523 | ||
10524 | nla_nest_end(msg, attr1); | |
10525 | nla_nest_end(msg, attr); | |
10526 | ||
10527 | ret = send_and_recv_msgs(drv, msg, | |
10528 | nl80211_get_bss_transition_status_handler, | |
10529 | info); | |
10530 | msg = NULL; | |
10531 | if (ret) { | |
10532 | wpa_printf(MSG_ERROR, | |
10533 | "nl80211: WNM Get BSS transition status failed: ret=%d (%s)", | |
10534 | ret, strerror(-ret)); | |
10535 | goto fail; | |
10536 | } | |
10537 | return info; | |
10538 | ||
10539 | fail: | |
10540 | nlmsg_free(msg); | |
10541 | os_free(info->candidates); | |
10542 | os_free(info); | |
10543 | return NULL; | |
10544 | } | |
10545 | ||
178553b7 VK |
10546 | |
10547 | /** | |
10548 | * nl80211_ignore_assoc_disallow - Configure driver to ignore assoc_disallow | |
10549 | * @priv: Pointer to private driver data from wpa_driver_nl80211_init() | |
10550 | * @ignore_assoc_disallow: 0 to not ignore, 1 to ignore | |
10551 | * Returns: 0 on success, -1 on failure | |
10552 | */ | |
10553 | static int nl80211_ignore_assoc_disallow(void *priv, int ignore_disallow) | |
10554 | { | |
10555 | struct i802_bss *bss = priv; | |
10556 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
10557 | struct nl_msg *msg; | |
10558 | struct nlattr *attr; | |
10559 | int ret = -1; | |
10560 | ||
10561 | if (!drv->set_wifi_conf_vendor_cmd_avail) | |
10562 | return -1; | |
10563 | ||
10564 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_VENDOR)) || | |
10565 | nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) || | |
10566 | nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD, | |
10567 | QCA_NL80211_VENDOR_SUBCMD_SET_WIFI_CONFIGURATION)) | |
10568 | goto fail; | |
10569 | ||
10570 | attr = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA); | |
10571 | if (!attr) | |
10572 | goto fail; | |
10573 | ||
10574 | wpa_printf(MSG_DEBUG, "nl80211: Set ignore_assoc_disallow %d", | |
10575 | ignore_disallow); | |
10576 | if (nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_CONFIG_IGNORE_ASSOC_DISALLOWED, | |
10577 | ignore_disallow)) | |
10578 | goto fail; | |
10579 | ||
10580 | nla_nest_end(msg, attr); | |
10581 | ||
10582 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); | |
10583 | msg = NULL; | |
10584 | if (ret) { | |
10585 | wpa_printf(MSG_ERROR, | |
10586 | "nl80211: Set ignore_assoc_disallow failed: ret=%d (%s)", | |
10587 | ret, strerror(-ret)); | |
10588 | goto fail; | |
10589 | } | |
10590 | ||
10591 | fail: | |
10592 | nlmsg_free(msg); | |
10593 | return ret; | |
10594 | } | |
10595 | ||
3ab48492 KV |
10596 | #endif /* CONFIG_MBO */ |
10597 | ||
b658547d JM |
10598 | #endif /* CONFIG_DRIVER_NL80211_QCA */ |
10599 | ||
7c813acf | 10600 | |
6922d440 IP |
10601 | static int nl80211_write_to_file(const char *name, unsigned int val) |
10602 | { | |
10603 | int fd, len; | |
10604 | char tmp[128]; | |
10605 | ||
10606 | fd = open(name, O_RDWR); | |
10607 | if (fd < 0) { | |
10608 | wpa_printf(MSG_ERROR, "nl80211: Failed to open %s: %s", | |
10609 | name, strerror(errno)); | |
10610 | return fd; | |
10611 | } | |
10612 | ||
10613 | len = os_snprintf(tmp, sizeof(tmp), "%u\n", val); | |
10614 | len = write(fd, tmp, len); | |
10615 | if (len < 0) | |
10616 | wpa_printf(MSG_ERROR, "nl80211: Failed to write to %s: %s", | |
10617 | name, strerror(errno)); | |
10618 | close(fd); | |
10619 | ||
10620 | return 0; | |
10621 | } | |
10622 | ||
10623 | ||
10624 | static int nl80211_configure_data_frame_filters(void *priv, u32 filter_flags) | |
10625 | { | |
10626 | struct i802_bss *bss = priv; | |
10627 | char path[128]; | |
10628 | int ret; | |
10629 | ||
10630 | wpa_printf(MSG_DEBUG, "nl80211: Data frame filter flags=0x%x", | |
10631 | filter_flags); | |
10632 | ||
10633 | /* Configure filtering of unicast frame encrypted using GTK */ | |
10634 | ret = os_snprintf(path, sizeof(path), | |
10635 | "/proc/sys/net/ipv4/conf/%s/drop_unicast_in_l2_multicast", | |
10636 | bss->ifname); | |
bd86ea08 JM |
10637 | if (os_snprintf_error(sizeof(path), ret)) |
10638 | return -1; | |
6922d440 IP |
10639 | |
10640 | ret = nl80211_write_to_file(path, | |
10641 | !!(filter_flags & | |
10642 | WPA_DATA_FRAME_FILTER_FLAG_GTK)); | |
10643 | if (ret) { | |
10644 | wpa_printf(MSG_ERROR, | |
10645 | "nl80211: Failed to set IPv4 unicast in multicast filter"); | |
10646 | return ret; | |
10647 | } | |
10648 | ||
10649 | os_snprintf(path, sizeof(path), | |
10650 | "/proc/sys/net/ipv6/conf/%s/drop_unicast_in_l2_multicast", | |
10651 | bss->ifname); | |
10652 | ret = nl80211_write_to_file(path, | |
10653 | !!(filter_flags & | |
10654 | WPA_DATA_FRAME_FILTER_FLAG_GTK)); | |
10655 | ||
10656 | if (ret) { | |
10657 | wpa_printf(MSG_ERROR, | |
10658 | "nl80211: Failed to set IPv6 unicast in multicast filter"); | |
10659 | return ret; | |
10660 | } | |
10661 | ||
10662 | /* Configure filtering of unicast frame encrypted using GTK */ | |
10663 | os_snprintf(path, sizeof(path), | |
10664 | "/proc/sys/net/ipv4/conf/%s/drop_gratuitous_arp", | |
10665 | bss->ifname); | |
10666 | ret = nl80211_write_to_file(path, | |
10667 | !!(filter_flags & | |
10668 | WPA_DATA_FRAME_FILTER_FLAG_ARP)); | |
10669 | if (ret) { | |
10670 | wpa_printf(MSG_ERROR, | |
10671 | "nl80211: Failed set gratuitous ARP filter"); | |
10672 | return ret; | |
10673 | } | |
10674 | ||
10675 | /* Configure filtering of IPv6 NA frames */ | |
10676 | os_snprintf(path, sizeof(path), | |
10677 | "/proc/sys/net/ipv6/conf/%s/drop_unsolicited_na", | |
10678 | bss->ifname); | |
10679 | ret = nl80211_write_to_file(path, | |
10680 | !!(filter_flags & | |
10681 | WPA_DATA_FRAME_FILTER_FLAG_NA)); | |
10682 | if (ret) { | |
10683 | wpa_printf(MSG_ERROR, | |
10684 | "nl80211: Failed to set unsolicited NA filter"); | |
10685 | return ret; | |
10686 | } | |
10687 | ||
10688 | return 0; | |
10689 | } | |
10690 | ||
10691 | ||
cc9a2575 KV |
10692 | static int nl80211_get_ext_capab(void *priv, enum wpa_driver_if_type type, |
10693 | const u8 **ext_capa, const u8 **ext_capa_mask, | |
10694 | unsigned int *ext_capa_len) | |
10695 | { | |
10696 | struct i802_bss *bss = priv; | |
10697 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
10698 | enum nl80211_iftype nlmode; | |
10699 | unsigned int i; | |
10700 | ||
10701 | if (!ext_capa || !ext_capa_mask || !ext_capa_len) | |
10702 | return -1; | |
10703 | ||
10704 | nlmode = wpa_driver_nl80211_if_type(type); | |
10705 | ||
10706 | /* By default, use the per-radio values */ | |
10707 | *ext_capa = drv->extended_capa; | |
10708 | *ext_capa_mask = drv->extended_capa_mask; | |
10709 | *ext_capa_len = drv->extended_capa_len; | |
10710 | ||
10711 | /* Replace the default value if a per-interface type value exists */ | |
10712 | for (i = 0; i < drv->num_iface_ext_capa; i++) { | |
10713 | if (nlmode == drv->iface_ext_capa[i].iftype) { | |
10714 | *ext_capa = drv->iface_ext_capa[i].ext_capa; | |
10715 | *ext_capa_mask = drv->iface_ext_capa[i].ext_capa_mask; | |
10716 | *ext_capa_len = drv->iface_ext_capa[i].ext_capa_len; | |
10717 | break; | |
10718 | } | |
10719 | } | |
10720 | ||
10721 | return 0; | |
10722 | } | |
10723 | ||
10724 | ||
3c67e977 VK |
10725 | static int nl80211_update_connection_params( |
10726 | void *priv, struct wpa_driver_associate_params *params, | |
10727 | enum wpa_drv_update_connect_params_mask mask) | |
10728 | { | |
10729 | struct i802_bss *bss = priv; | |
10730 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
10731 | struct nl_msg *msg; | |
10732 | int ret = -1; | |
10733 | enum nl80211_auth_type type; | |
10734 | ||
10735 | msg = nl80211_drv_msg(drv, 0, NL80211_CMD_UPDATE_CONNECT_PARAMS); | |
10736 | if (!msg) | |
10737 | goto fail; | |
10738 | ||
10739 | wpa_printf(MSG_DEBUG, "nl80211: Update connection params (ifindex=%d)", | |
10740 | drv->ifindex); | |
10741 | ||
10742 | if ((mask & WPA_DRV_UPDATE_ASSOC_IES) && params->wpa_ie) { | |
10743 | if (nla_put(msg, NL80211_ATTR_IE, params->wpa_ie_len, | |
10744 | params->wpa_ie)) | |
10745 | goto fail; | |
10746 | wpa_hexdump(MSG_DEBUG, " * IEs", params->wpa_ie, | |
10747 | params->wpa_ie_len); | |
10748 | } | |
10749 | ||
10750 | if (mask & WPA_DRV_UPDATE_AUTH_TYPE) { | |
10751 | type = get_nl_auth_type(params->auth_alg); | |
10752 | if (type == NL80211_AUTHTYPE_MAX || | |
10753 | nla_put_u32(msg, NL80211_ATTR_AUTH_TYPE, type)) | |
10754 | goto fail; | |
10755 | wpa_printf(MSG_DEBUG, " * Auth Type %d", type); | |
10756 | } | |
10757 | ||
10758 | if ((mask & WPA_DRV_UPDATE_FILS_ERP_INFO) && | |
10759 | nl80211_put_fils_connect_params(drv, params, msg)) | |
10760 | goto fail; | |
10761 | ||
10762 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); | |
10763 | msg = NULL; | |
10764 | if (ret) | |
10765 | wpa_dbg(drv->ctx, MSG_DEBUG, | |
10766 | "nl80211: Update connect params command failed: ret=%d (%s)", | |
10767 | ret, strerror(-ret)); | |
10768 | ||
10769 | fail: | |
10770 | nlmsg_free(msg); | |
10771 | return ret; | |
10772 | } | |
10773 | ||
10774 | ||
ba71cb82 SD |
10775 | static int nl80211_send_external_auth_status(void *priv, |
10776 | struct external_auth *params) | |
10777 | { | |
10778 | struct i802_bss *bss = priv; | |
10779 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
10780 | struct nl_msg *msg = NULL; | |
10781 | int ret = -1; | |
10782 | ||
10783 | wpa_dbg(drv->ctx, MSG_DEBUG, | |
10784 | "nl80211: External auth status: %u", params->status); | |
10785 | ||
10786 | msg = nl80211_drv_msg(drv, 0, NL80211_CMD_EXTERNAL_AUTH); | |
10787 | if (!msg || | |
10788 | nla_put_u16(msg, NL80211_ATTR_STATUS_CODE, params->status) || | |
10789 | nla_put(msg, NL80211_ATTR_SSID, params->ssid_len, | |
10790 | params->ssid) || | |
10791 | nla_put(msg, NL80211_ATTR_BSSID, ETH_ALEN, params->bssid)) | |
10792 | goto fail; | |
10793 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); | |
10794 | msg = NULL; | |
10795 | if (ret) { | |
10796 | wpa_printf(MSG_DEBUG, | |
10797 | "nl80211: External Auth status update failed: ret=%d (%s)", | |
10798 | ret, strerror(-ret)); | |
10799 | goto fail; | |
10800 | } | |
10801 | fail: | |
10802 | nlmsg_free(msg); | |
10803 | return ret; | |
10804 | } | |
10805 | ||
10806 | ||
5abc7823 VN |
10807 | static int nl80211_set_4addr_mode(void *priv, const char *bridge_ifname, |
10808 | int val) | |
10809 | { | |
10810 | struct i802_bss *bss = priv; | |
10811 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
10812 | struct nl_msg *msg; | |
10813 | int ret = -ENOBUFS; | |
10814 | ||
10815 | wpa_printf(MSG_DEBUG, "nl80211: %s 4addr mode (bridge_ifname: %s)", | |
10816 | val ? "Enable" : "Disable", bridge_ifname); | |
10817 | ||
10818 | msg = nl80211_cmd_msg(drv->first_bss, 0, NL80211_CMD_SET_INTERFACE); | |
10819 | if (!msg || nla_put_u8(msg, NL80211_ATTR_4ADDR, val)) | |
10820 | goto fail; | |
10821 | ||
10822 | if (bridge_ifname[0] && bss->added_if_into_bridge && !val) { | |
10823 | if (linux_br_del_if(drv->global->ioctl_sock, | |
10824 | bridge_ifname, bss->ifname)) { | |
10825 | wpa_printf(MSG_ERROR, | |
10826 | "nl80211: Failed to remove interface %s from bridge %s", | |
10827 | bss->ifname, bridge_ifname); | |
10828 | return -1; | |
10829 | } | |
10830 | bss->added_if_into_bridge = 0; | |
10831 | } | |
10832 | ||
10833 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); | |
10834 | msg = NULL; | |
10835 | if (!ret) { | |
10836 | if (bridge_ifname[0] && val && | |
10837 | i802_check_bridge(drv, bss, bridge_ifname, bss->ifname) < 0) | |
10838 | return -1; | |
10839 | return 0; | |
10840 | } | |
10841 | ||
10842 | fail: | |
10843 | nlmsg_free(msg); | |
10844 | wpa_printf(MSG_ERROR, "nl80211: Failed to enable/disable 4addr"); | |
10845 | ||
10846 | return ret; | |
10847 | } | |
10848 | ||
10849 | ||
3f5285e8 JM |
10850 | const struct wpa_driver_ops wpa_driver_nl80211_ops = { |
10851 | .name = "nl80211", | |
10852 | .desc = "Linux nl80211/cfg80211", | |
10853 | .get_bssid = wpa_driver_nl80211_get_bssid, | |
10854 | .get_ssid = wpa_driver_nl80211_get_ssid, | |
9ebce9c5 JM |
10855 | .set_key = driver_nl80211_set_key, |
10856 | .scan2 = driver_nl80211_scan2, | |
d21c63b9 LC |
10857 | .sched_scan = wpa_driver_nl80211_sched_scan, |
10858 | .stop_sched_scan = wpa_driver_nl80211_stop_sched_scan, | |
3f5285e8 | 10859 | .get_scan_results2 = wpa_driver_nl80211_get_scan_results, |
4f30addb | 10860 | .abort_scan = wpa_driver_nl80211_abort_scan, |
9ebce9c5 JM |
10861 | .deauthenticate = driver_nl80211_deauthenticate, |
10862 | .authenticate = driver_nl80211_authenticate, | |
3f5285e8 | 10863 | .associate = wpa_driver_nl80211_associate, |
f2ed8023 JM |
10864 | .global_init = nl80211_global_init, |
10865 | .global_deinit = nl80211_global_deinit, | |
10866 | .init2 = wpa_driver_nl80211_init, | |
9ebce9c5 | 10867 | .deinit = driver_nl80211_deinit, |
3f5285e8 JM |
10868 | .get_capa = wpa_driver_nl80211_get_capa, |
10869 | .set_operstate = wpa_driver_nl80211_set_operstate, | |
01652550 | 10870 | .set_supp_port = wpa_driver_nl80211_set_supp_port, |
6d158490 | 10871 | .set_country = wpa_driver_nl80211_set_country, |
f0793bf1 | 10872 | .get_country = wpa_driver_nl80211_get_country, |
19c3b566 | 10873 | .set_ap = wpa_driver_nl80211_set_ap, |
3c4ca363 | 10874 | .set_acl = wpa_driver_nl80211_set_acl, |
22a7c9d7 | 10875 | .if_add = wpa_driver_nl80211_if_add, |
9ebce9c5 JM |
10876 | .if_remove = driver_nl80211_if_remove, |
10877 | .send_mlme = driver_nl80211_send_mlme, | |
0fafeb54 | 10878 | .get_hw_feature_data = nl80211_get_hw_feature_data, |
0f4e8b4f | 10879 | .sta_add = wpa_driver_nl80211_sta_add, |
9ebce9c5 | 10880 | .sta_remove = driver_nl80211_sta_remove, |
db149ac9 | 10881 | .hapd_send_eapol = wpa_driver_nl80211_hapd_send_eapol, |
a8d6ffa4 | 10882 | .sta_set_flags = wpa_driver_nl80211_sta_set_flags, |
c5121837 | 10883 | .hapd_init = i802_init, |
c5121837 | 10884 | .hapd_deinit = i802_deinit, |
f7b3920c | 10885 | .set_wds_sta = i802_set_wds_sta, |
c5121837 JM |
10886 | .get_seqnum = i802_get_seqnum, |
10887 | .flush = i802_flush, | |
c5121837 JM |
10888 | .get_inact_sec = i802_get_inact_sec, |
10889 | .sta_clear_stats = i802_sta_clear_stats, | |
c5121837 JM |
10890 | .set_rts = i802_set_rts, |
10891 | .set_frag = i802_set_frag, | |
c5121837 | 10892 | .set_tx_queue_params = i802_set_tx_queue_params, |
9ebce9c5 | 10893 | .set_sta_vlan = driver_nl80211_set_sta_vlan, |
ee7ab173 JB |
10894 | .sta_deauth = i802_sta_deauth, |
10895 | .sta_disassoc = i802_sta_disassoc, | |
9ebce9c5 | 10896 | .read_sta_data = driver_nl80211_read_sta_data, |
e3802622 | 10897 | .set_freq = i802_set_freq, |
9ebce9c5 | 10898 | .send_action = driver_nl80211_send_action, |
5dfca53f | 10899 | .send_action_cancel_wait = wpa_driver_nl80211_send_action_cancel_wait, |
55777702 JM |
10900 | .remain_on_channel = wpa_driver_nl80211_remain_on_channel, |
10901 | .cancel_remain_on_channel = | |
10902 | wpa_driver_nl80211_cancel_remain_on_channel, | |
9ebce9c5 | 10903 | .probe_req_report = driver_nl80211_probe_req_report, |
af473088 | 10904 | .deinit_ap = wpa_driver_nl80211_deinit_ap, |
3c29244e | 10905 | .deinit_p2p_cli = wpa_driver_nl80211_deinit_p2p_cli, |
207ef3fb | 10906 | .resume = wpa_driver_nl80211_resume, |
b625473c | 10907 | .signal_monitor = nl80211_signal_monitor, |
1c5c7273 | 10908 | .signal_poll = nl80211_signal_poll, |
7f00dc6e | 10909 | .channel_info = nl80211_channel_info, |
b91ab76e | 10910 | .send_frame = nl80211_send_frame, |
c55f774d | 10911 | .set_param = nl80211_set_param, |
6859f1cb | 10912 | .get_radio_name = nl80211_get_radio_name, |
a6efc65d JM |
10913 | .add_pmkid = nl80211_add_pmkid, |
10914 | .remove_pmkid = nl80211_remove_pmkid, | |
10915 | .flush_pmkid = nl80211_flush_pmkid, | |
b14a210c | 10916 | .set_rekey_info = nl80211_set_rekey_info, |
bcf24348 | 10917 | .poll_client = nl80211_poll_client, |
29f338af | 10918 | .set_p2p_powersave = nl80211_set_p2p_powersave, |
f90e9c1c | 10919 | .start_dfs_cac = nl80211_start_radar_detection, |
695c7038 | 10920 | .stop_ap = wpa_driver_nl80211_stop_ap, |
03ea1786 AN |
10921 | #ifdef CONFIG_TDLS |
10922 | .send_tdls_mgmt = nl80211_send_tdls_mgmt, | |
10923 | .tdls_oper = nl80211_tdls_oper, | |
72b2605f AN |
10924 | .tdls_enable_channel_switch = nl80211_tdls_enable_channel_switch, |
10925 | .tdls_disable_channel_switch = nl80211_tdls_disable_channel_switch, | |
03ea1786 | 10926 | #endif /* CONFIG_TDLS */ |
6a1ce395 | 10927 | .update_ft_ies = wpa_driver_nl80211_update_ft_ies, |
597b94f5 | 10928 | .get_mac_addr = wpa_driver_nl80211_get_macaddr, |
0185007c | 10929 | .get_survey = wpa_driver_nl80211_get_survey, |
a771c07d | 10930 | .status = wpa_driver_nl80211_status, |
1c4ffa87 | 10931 | .switch_channel = nl80211_switch_channel, |
0de38036 JM |
10932 | #ifdef ANDROID_P2P |
10933 | .set_noa = wpa_driver_set_p2p_noa, | |
10934 | .get_noa = wpa_driver_get_p2p_noa, | |
10935 | .set_ap_wps_ie = wpa_driver_set_ap_wps_p2p_ie, | |
10936 | #endif /* ANDROID_P2P */ | |
5e2c3490 | 10937 | #ifdef ANDROID |
ded14ce9 | 10938 | #ifndef ANDROID_LIB_STUB |
5e2c3490 | 10939 | .driver_cmd = wpa_driver_nl80211_driver_cmd, |
ded14ce9 | 10940 | #endif /* !ANDROID_LIB_STUB */ |
5e2c3490 | 10941 | #endif /* ANDROID */ |
adef8948 | 10942 | .vendor_cmd = nl80211_vendor_cmd, |
049105b4 | 10943 | .set_qos_map = nl80211_set_qos_map, |
e4fa8b12 | 10944 | .set_wowlan = nl80211_set_wowlan, |
fee354c7 | 10945 | .set_mac_addr = nl80211_set_mac_addr, |
6c1664f6 BC |
10946 | #ifdef CONFIG_MESH |
10947 | .init_mesh = wpa_driver_nl80211_init_mesh, | |
10948 | .join_mesh = wpa_driver_nl80211_join_mesh, | |
10949 | .leave_mesh = wpa_driver_nl80211_leave_mesh, | |
10950 | #endif /* CONFIG_MESH */ | |
71103bed KP |
10951 | .br_add_ip_neigh = wpa_driver_br_add_ip_neigh, |
10952 | .br_delete_ip_neigh = wpa_driver_br_delete_ip_neigh, | |
73d2294f | 10953 | .br_port_set_attr = wpa_driver_br_port_set_attr, |
7565752d | 10954 | .br_set_net_param = wpa_driver_br_set_net_param, |
dfa87878 MB |
10955 | .add_tx_ts = nl80211_add_ts, |
10956 | .del_tx_ts = nl80211_del_ts, | |
45e3fc72 | 10957 | .get_ifindex = nl80211_get_ifindex, |
b658547d | 10958 | #ifdef CONFIG_DRIVER_NL80211_QCA |
9607a1ae | 10959 | .roaming = nl80211_roaming, |
d98038bb | 10960 | .disable_fils = nl80211_disable_fils, |
16689c7c | 10961 | .do_acs = wpa_driver_do_acs, |
844dfeb8 | 10962 | .set_band = nl80211_set_band, |
98342208 | 10963 | .get_pref_freq_list = nl80211_get_pref_freq_list, |
7c813acf | 10964 | .set_prob_oper_freq = nl80211_set_prob_oper_freq, |
a6f5b193 PX |
10965 | .p2p_lo_start = nl80211_p2p_lo_start, |
10966 | .p2p_lo_stop = nl80211_p2p_lo_stop, | |
cc9985d1 | 10967 | .set_default_scan_ies = nl80211_set_default_scan_ies, |
2e4e4fb7 | 10968 | .set_tdls_mode = nl80211_set_tdls_mode, |
3ab48492 KV |
10969 | #ifdef CONFIG_MBO |
10970 | .get_bss_transition_status = nl80211_get_bss_transition_status, | |
178553b7 | 10971 | .ignore_assoc_disallow = nl80211_ignore_assoc_disallow, |
3ab48492 | 10972 | #endif /* CONFIG_MBO */ |
b04854ce | 10973 | .set_bssid_blacklist = nl80211_set_bssid_blacklist, |
b658547d | 10974 | #endif /* CONFIG_DRIVER_NL80211_QCA */ |
6922d440 | 10975 | .configure_data_frame_filters = nl80211_configure_data_frame_filters, |
cc9a2575 | 10976 | .get_ext_capab = nl80211_get_ext_capab, |
3c67e977 | 10977 | .update_connect_params = nl80211_update_connection_params, |
ba71cb82 | 10978 | .send_external_auth_status = nl80211_send_external_auth_status, |
5abc7823 | 10979 | .set_4addr_mode = nl80211_set_4addr_mode, |
3f5285e8 | 10980 | }; |