]>
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 | 238 | static int i802_sta_disassoc(void *priv, const u8 *own_addr, const u8 *addr, |
4be17ffb | 239 | u16 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); | |
091c2277 | 310 | drv->first_bss->freq = 0; |
add9b7a4 JM |
311 | } |
312 | ||
313 | ||
6241fcb1 JM |
314 | /* nl80211 code */ |
315 | static int ack_handler(struct nl_msg *msg, void *arg) | |
316 | { | |
317 | int *err = arg; | |
318 | *err = 0; | |
319 | return NL_STOP; | |
320 | } | |
321 | ||
322 | static int finish_handler(struct nl_msg *msg, void *arg) | |
323 | { | |
8e8df255 JM |
324 | int *ret = arg; |
325 | *ret = 0; | |
6241fcb1 JM |
326 | return NL_SKIP; |
327 | } | |
328 | ||
329 | static int error_handler(struct sockaddr_nl *nla, struct nlmsgerr *err, | |
330 | void *arg) | |
331 | { | |
40432e6e JB |
332 | struct nlmsghdr *nlh = (struct nlmsghdr *) err - 1; |
333 | int len = nlh->nlmsg_len; | |
334 | struct nlattr *attrs; | |
335 | struct nlattr *tb[NLMSGERR_ATTR_MAX + 1]; | |
6241fcb1 | 336 | int *ret = arg; |
40432e6e JB |
337 | int ack_len = sizeof(*nlh) + sizeof(int) + sizeof(*nlh); |
338 | ||
6241fcb1 | 339 | *ret = err->error; |
40432e6e JB |
340 | |
341 | if (!(nlh->nlmsg_flags & NLM_F_ACK_TLVS)) | |
342 | return NL_SKIP; | |
343 | ||
344 | if (!(nlh->nlmsg_flags & NLM_F_CAPPED)) | |
345 | ack_len += err->msg.nlmsg_len - sizeof(*nlh); | |
346 | ||
347 | if (len <= ack_len) | |
348 | return NL_STOP; | |
349 | ||
350 | attrs = (void *) ((unsigned char *) nlh + ack_len); | |
351 | len -= ack_len; | |
352 | ||
353 | nla_parse(tb, NLMSGERR_ATTR_MAX, attrs, len, NULL); | |
354 | if (tb[NLMSGERR_ATTR_MSG]) { | |
355 | len = strnlen((char *) nla_data(tb[NLMSGERR_ATTR_MSG]), | |
356 | nla_len(tb[NLMSGERR_ATTR_MSG])); | |
357 | wpa_printf(MSG_ERROR, "nl80211: kernel reports: %*s", | |
358 | len, (char *) nla_data(tb[NLMSGERR_ATTR_MSG])); | |
359 | } | |
360 | ||
6241fcb1 JM |
361 | return NL_SKIP; |
362 | } | |
363 | ||
5b7b85f6 JM |
364 | |
365 | static int no_seq_check(struct nl_msg *msg, void *arg) | |
366 | { | |
367 | return NL_OK; | |
368 | } | |
369 | ||
370 | ||
bbd89bfc JM |
371 | static void nl80211_nlmsg_clear(struct nl_msg *msg) |
372 | { | |
373 | /* | |
374 | * Clear nlmsg data, e.g., to make sure key material is not left in | |
375 | * heap memory for unnecessarily long time. | |
376 | */ | |
377 | if (msg) { | |
378 | struct nlmsghdr *hdr = nlmsg_hdr(msg); | |
379 | void *data = nlmsg_data(hdr); | |
d58ade21 JM |
380 | /* |
381 | * This would use nlmsg_datalen() or the older nlmsg_len() if | |
382 | * only libnl were to maintain a stable API.. Neither will work | |
383 | * with all released versions, so just calculate the length | |
384 | * here. | |
385 | */ | |
386 | int len = hdr->nlmsg_len - NLMSG_HDRLEN; | |
bbd89bfc JM |
387 | |
388 | os_memset(data, 0, len); | |
389 | } | |
390 | } | |
391 | ||
392 | ||
d6c9aab8 | 393 | static int send_and_recv(struct nl80211_global *global, |
58f6fbe0 JM |
394 | struct nl_handle *nl_handle, struct nl_msg *msg, |
395 | int (*valid_handler)(struct nl_msg *, void *), | |
396 | void *valid_data) | |
6241fcb1 JM |
397 | { |
398 | struct nl_cb *cb; | |
40432e6e | 399 | int err = -ENOMEM, opt; |
6241fcb1 | 400 | |
9725b784 JM |
401 | if (!msg) |
402 | return -ENOMEM; | |
403 | ||
d6c9aab8 | 404 | cb = nl_cb_clone(global->nl_cb); |
6241fcb1 JM |
405 | if (!cb) |
406 | goto out; | |
407 | ||
40432e6e JB |
408 | /* try to set NETLINK_EXT_ACK to 1, ignoring errors */ |
409 | opt = 1; | |
410 | setsockopt(nl_socket_get_fd(nl_handle), SOL_NETLINK, | |
411 | NETLINK_EXT_ACK, &opt, sizeof(opt)); | |
412 | ||
b14e8ea1 JM |
413 | /* try to set NETLINK_CAP_ACK to 1, ignoring errors */ |
414 | opt = 1; | |
415 | setsockopt(nl_socket_get_fd(nl_handle), SOL_NETLINK, | |
416 | NETLINK_CAP_ACK, &opt, sizeof(opt)); | |
417 | ||
58f6fbe0 | 418 | err = nl_send_auto_complete(nl_handle, msg); |
6241fcb1 JM |
419 | if (err < 0) |
420 | goto out; | |
421 | ||
422 | err = 1; | |
423 | ||
424 | nl_cb_err(cb, NL_CB_CUSTOM, error_handler, &err); | |
8e8df255 | 425 | nl_cb_set(cb, NL_CB_FINISH, NL_CB_CUSTOM, finish_handler, &err); |
6241fcb1 JM |
426 | nl_cb_set(cb, NL_CB_ACK, NL_CB_CUSTOM, ack_handler, &err); |
427 | ||
428 | if (valid_handler) | |
429 | nl_cb_set(cb, NL_CB_VALID, NL_CB_CUSTOM, | |
430 | valid_handler, valid_data); | |
431 | ||
34068ac3 JM |
432 | while (err > 0) { |
433 | int res = nl_recvmsgs(nl_handle, cb); | |
d3d04831 | 434 | if (res < 0) { |
34068ac3 JM |
435 | wpa_printf(MSG_INFO, |
436 | "nl80211: %s->nl_recvmsgs failed: %d", | |
437 | __func__, res); | |
438 | } | |
439 | } | |
6241fcb1 JM |
440 | out: |
441 | nl_cb_put(cb); | |
bbd89bfc JM |
442 | if (!valid_handler && valid_data == (void *) -1) |
443 | nl80211_nlmsg_clear(msg); | |
6241fcb1 JM |
444 | nlmsg_free(msg); |
445 | return err; | |
446 | } | |
447 | ||
448 | ||
f3407c66 JM |
449 | int send_and_recv_msgs(struct wpa_driver_nl80211_data *drv, |
450 | struct nl_msg *msg, | |
451 | int (*valid_handler)(struct nl_msg *, void *), | |
452 | void *valid_data) | |
58f6fbe0 | 453 | { |
481234cf | 454 | return send_and_recv(drv->global, drv->global->nl, msg, |
d6c9aab8 | 455 | valid_handler, valid_data); |
58f6fbe0 JM |
456 | } |
457 | ||
458 | ||
97865538 JM |
459 | struct family_data { |
460 | const char *group; | |
461 | int id; | |
462 | }; | |
463 | ||
464 | ||
465 | static int family_handler(struct nl_msg *msg, void *arg) | |
466 | { | |
467 | struct family_data *res = arg; | |
468 | struct nlattr *tb[CTRL_ATTR_MAX + 1]; | |
469 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); | |
470 | struct nlattr *mcgrp; | |
471 | int i; | |
472 | ||
473 | nla_parse(tb, CTRL_ATTR_MAX, genlmsg_attrdata(gnlh, 0), | |
474 | genlmsg_attrlen(gnlh, 0), NULL); | |
475 | if (!tb[CTRL_ATTR_MCAST_GROUPS]) | |
476 | return NL_SKIP; | |
477 | ||
478 | nla_for_each_nested(mcgrp, tb[CTRL_ATTR_MCAST_GROUPS], i) { | |
479 | struct nlattr *tb2[CTRL_ATTR_MCAST_GRP_MAX + 1]; | |
480 | nla_parse(tb2, CTRL_ATTR_MCAST_GRP_MAX, nla_data(mcgrp), | |
481 | nla_len(mcgrp), NULL); | |
482 | if (!tb2[CTRL_ATTR_MCAST_GRP_NAME] || | |
483 | !tb2[CTRL_ATTR_MCAST_GRP_ID] || | |
484 | os_strncmp(nla_data(tb2[CTRL_ATTR_MCAST_GRP_NAME]), | |
485 | res->group, | |
486 | nla_len(tb2[CTRL_ATTR_MCAST_GRP_NAME])) != 0) | |
487 | continue; | |
488 | res->id = nla_get_u32(tb2[CTRL_ATTR_MCAST_GRP_ID]); | |
489 | break; | |
490 | }; | |
491 | ||
492 | return NL_SKIP; | |
493 | } | |
494 | ||
495 | ||
d6c9aab8 | 496 | static int nl_get_multicast_id(struct nl80211_global *global, |
97865538 JM |
497 | const char *family, const char *group) |
498 | { | |
499 | struct nl_msg *msg; | |
a862e4a3 | 500 | int ret; |
97865538 JM |
501 | struct family_data res = { group, -ENOENT }; |
502 | ||
503 | msg = nlmsg_alloc(); | |
504 | if (!msg) | |
505 | return -ENOMEM; | |
a862e4a3 JM |
506 | if (!genlmsg_put(msg, 0, 0, genl_ctrl_resolve(global->nl, "nlctrl"), |
507 | 0, 0, CTRL_CMD_GETFAMILY, 0) || | |
508 | nla_put_string(msg, CTRL_ATTR_FAMILY_NAME, family)) { | |
509 | nlmsg_free(msg); | |
510 | return -1; | |
511 | } | |
97865538 | 512 | |
1033315f | 513 | ret = send_and_recv(global, global->nl, msg, family_handler, &res); |
97865538 JM |
514 | if (ret == 0) |
515 | ret = res.id; | |
97865538 JM |
516 | return ret; |
517 | } | |
518 | ||
519 | ||
f3407c66 JM |
520 | void * nl80211_cmd(struct wpa_driver_nl80211_data *drv, |
521 | struct nl_msg *msg, int flags, uint8_t cmd) | |
9fb04070 | 522 | { |
a5a187b0 JM |
523 | if (TEST_FAIL()) |
524 | return NULL; | |
335d42b1 | 525 | return genlmsg_put(msg, 0, 0, drv->global->nl80211_id, |
276e2d67 | 526 | 0, flags, cmd, 0); |
9fb04070 JM |
527 | } |
528 | ||
529 | ||
350acc35 JM |
530 | static int nl80211_set_iface_id(struct nl_msg *msg, struct i802_bss *bss) |
531 | { | |
532 | if (bss->wdev_id_set) | |
533 | return nla_put_u64(msg, NL80211_ATTR_WDEV, bss->wdev_id); | |
534 | return nla_put_u32(msg, NL80211_ATTR_IFINDEX, bss->ifindex); | |
535 | } | |
536 | ||
537 | ||
07c7757c JM |
538 | struct nl_msg * nl80211_cmd_msg(struct i802_bss *bss, int flags, uint8_t cmd) |
539 | { | |
540 | struct nl_msg *msg; | |
541 | ||
542 | msg = nlmsg_alloc(); | |
543 | if (!msg) | |
544 | return NULL; | |
545 | ||
546 | if (!nl80211_cmd(bss->drv, msg, flags, cmd) || | |
547 | nl80211_set_iface_id(msg, bss) < 0) { | |
548 | nlmsg_free(msg); | |
549 | return NULL; | |
550 | } | |
551 | ||
552 | return msg; | |
553 | } | |
554 | ||
555 | ||
556 | static struct nl_msg * | |
557 | nl80211_ifindex_msg(struct wpa_driver_nl80211_data *drv, int ifindex, | |
558 | int flags, uint8_t cmd) | |
559 | { | |
560 | struct nl_msg *msg; | |
561 | ||
562 | msg = nlmsg_alloc(); | |
563 | if (!msg) | |
564 | return NULL; | |
565 | ||
566 | if (!nl80211_cmd(drv, msg, flags, cmd) || | |
567 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex)) { | |
568 | nlmsg_free(msg); | |
569 | return NULL; | |
570 | } | |
571 | ||
572 | return msg; | |
573 | } | |
574 | ||
575 | ||
576 | struct nl_msg * nl80211_drv_msg(struct wpa_driver_nl80211_data *drv, int flags, | |
577 | uint8_t cmd) | |
578 | { | |
579 | return nl80211_ifindex_msg(drv, drv->ifindex, flags, cmd); | |
580 | } | |
581 | ||
582 | ||
583 | struct nl_msg * nl80211_bss_msg(struct i802_bss *bss, int flags, uint8_t cmd) | |
584 | { | |
585 | return nl80211_ifindex_msg(bss->drv, bss->ifindex, flags, cmd); | |
586 | } | |
587 | ||
588 | ||
e32ad281 JB |
589 | struct wiphy_idx_data { |
590 | int wiphy_idx; | |
01517c8b | 591 | enum nl80211_iftype nlmode; |
597b94f5 | 592 | u8 *macaddr; |
e32ad281 JB |
593 | }; |
594 | ||
595 | ||
596 | static int netdev_info_handler(struct nl_msg *msg, void *arg) | |
597 | { | |
598 | struct nlattr *tb[NL80211_ATTR_MAX + 1]; | |
599 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); | |
600 | struct wiphy_idx_data *info = arg; | |
601 | ||
602 | nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), | |
603 | genlmsg_attrlen(gnlh, 0), NULL); | |
604 | ||
605 | if (tb[NL80211_ATTR_WIPHY]) | |
606 | info->wiphy_idx = nla_get_u32(tb[NL80211_ATTR_WIPHY]); | |
607 | ||
01517c8b JB |
608 | if (tb[NL80211_ATTR_IFTYPE]) |
609 | info->nlmode = nla_get_u32(tb[NL80211_ATTR_IFTYPE]); | |
610 | ||
597b94f5 AS |
611 | if (tb[NL80211_ATTR_MAC] && info->macaddr) |
612 | os_memcpy(info->macaddr, nla_data(tb[NL80211_ATTR_MAC]), | |
613 | ETH_ALEN); | |
614 | ||
e32ad281 JB |
615 | return NL_SKIP; |
616 | } | |
617 | ||
618 | ||
f3407c66 | 619 | int nl80211_get_wiphy_index(struct i802_bss *bss) |
e32ad281 JB |
620 | { |
621 | struct nl_msg *msg; | |
622 | struct wiphy_idx_data data = { | |
623 | .wiphy_idx = -1, | |
597b94f5 | 624 | .macaddr = NULL, |
e32ad281 JB |
625 | }; |
626 | ||
56f77852 | 627 | if (!(msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_GET_INTERFACE))) |
a862e4a3 | 628 | return -1; |
e32ad281 JB |
629 | |
630 | if (send_and_recv_msgs(bss->drv, msg, netdev_info_handler, &data) == 0) | |
631 | return data.wiphy_idx; | |
e32ad281 JB |
632 | return -1; |
633 | } | |
634 | ||
635 | ||
01517c8b JB |
636 | static enum nl80211_iftype nl80211_get_ifmode(struct i802_bss *bss) |
637 | { | |
638 | struct nl_msg *msg; | |
639 | struct wiphy_idx_data data = { | |
597b94f5 AS |
640 | .nlmode = NL80211_IFTYPE_UNSPECIFIED, |
641 | .macaddr = NULL, | |
01517c8b JB |
642 | }; |
643 | ||
56f77852 | 644 | if (!(msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_GET_INTERFACE))) |
a862e4a3 | 645 | return NL80211_IFTYPE_UNSPECIFIED; |
01517c8b JB |
646 | |
647 | if (send_and_recv_msgs(bss->drv, msg, netdev_info_handler, &data) == 0) | |
648 | return data.nlmode; | |
01517c8b JB |
649 | return NL80211_IFTYPE_UNSPECIFIED; |
650 | } | |
01517c8b JB |
651 | |
652 | ||
597b94f5 AS |
653 | static int nl80211_get_macaddr(struct i802_bss *bss) |
654 | { | |
655 | struct nl_msg *msg; | |
656 | struct wiphy_idx_data data = { | |
657 | .macaddr = bss->addr, | |
658 | }; | |
659 | ||
56f77852 | 660 | if (!(msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_GET_INTERFACE))) |
a862e4a3 | 661 | return -1; |
597b94f5 | 662 | |
597b94f5 | 663 | return send_and_recv_msgs(bss->drv, msg, netdev_info_handler, &data); |
597b94f5 | 664 | } |
597b94f5 AS |
665 | |
666 | ||
e32ad281 JB |
667 | static int nl80211_register_beacons(struct wpa_driver_nl80211_data *drv, |
668 | struct nl80211_wiphy_data *w) | |
669 | { | |
670 | struct nl_msg *msg; | |
a862e4a3 | 671 | int ret; |
e32ad281 JB |
672 | |
673 | msg = nlmsg_alloc(); | |
674 | if (!msg) | |
675 | return -1; | |
676 | ||
a862e4a3 JM |
677 | if (!nl80211_cmd(drv, msg, 0, NL80211_CMD_REGISTER_BEACONS) || |
678 | nla_put_u32(msg, NL80211_ATTR_WIPHY, w->wiphy_idx)) { | |
679 | nlmsg_free(msg); | |
680 | return -1; | |
681 | } | |
e32ad281 | 682 | |
481234cf | 683 | ret = send_and_recv(drv->global, w->nl_beacons, msg, NULL, NULL); |
e32ad281 JB |
684 | if (ret) { |
685 | wpa_printf(MSG_DEBUG, "nl80211: Register beacons command " | |
686 | "failed: ret=%d (%s)", | |
687 | ret, strerror(-ret)); | |
e32ad281 | 688 | } |
e32ad281 JB |
689 | return ret; |
690 | } | |
691 | ||
692 | ||
693 | static void nl80211_recv_beacons(int sock, void *eloop_ctx, void *handle) | |
694 | { | |
695 | struct nl80211_wiphy_data *w = eloop_ctx; | |
34068ac3 | 696 | int res; |
e32ad281 | 697 | |
ee9fc67a | 698 | wpa_printf(MSG_EXCESSIVE, "nl80211: Beacon event message available"); |
e32ad281 | 699 | |
34068ac3 | 700 | res = nl_recvmsgs(handle, w->nl_cb); |
d3d04831 | 701 | if (res < 0) { |
34068ac3 JM |
702 | wpa_printf(MSG_INFO, "nl80211: %s->nl_recvmsgs failed: %d", |
703 | __func__, res); | |
704 | } | |
e32ad281 JB |
705 | } |
706 | ||
707 | ||
708 | static int process_beacon_event(struct nl_msg *msg, void *arg) | |
709 | { | |
710 | struct nl80211_wiphy_data *w = arg; | |
711 | struct wpa_driver_nl80211_data *drv; | |
712 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); | |
713 | struct nlattr *tb[NL80211_ATTR_MAX + 1]; | |
714 | union wpa_event_data event; | |
715 | ||
716 | nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), | |
717 | genlmsg_attrlen(gnlh, 0), NULL); | |
718 | ||
719 | if (gnlh->cmd != NL80211_CMD_FRAME) { | |
720 | wpa_printf(MSG_DEBUG, "nl80211: Unexpected beacon event? (%d)", | |
721 | gnlh->cmd); | |
722 | return NL_SKIP; | |
723 | } | |
724 | ||
725 | if (!tb[NL80211_ATTR_FRAME]) | |
726 | return NL_SKIP; | |
727 | ||
728 | dl_list_for_each(drv, &w->drvs, struct wpa_driver_nl80211_data, | |
729 | wiphy_list) { | |
730 | os_memset(&event, 0, sizeof(event)); | |
731 | event.rx_mgmt.frame = nla_data(tb[NL80211_ATTR_FRAME]); | |
732 | event.rx_mgmt.frame_len = nla_len(tb[NL80211_ATTR_FRAME]); | |
733 | wpa_supplicant_event(drv->ctx, EVENT_RX_MGMT, &event); | |
734 | } | |
735 | ||
736 | return NL_SKIP; | |
737 | } | |
738 | ||
739 | ||
740 | static struct nl80211_wiphy_data * | |
741 | nl80211_get_wiphy_data_ap(struct i802_bss *bss) | |
742 | { | |
743 | static DEFINE_DL_LIST(nl80211_wiphys); | |
744 | struct nl80211_wiphy_data *w; | |
745 | int wiphy_idx, found = 0; | |
746 | struct i802_bss *tmp_bss; | |
a70cd0db | 747 | u8 channel; |
e32ad281 JB |
748 | |
749 | if (bss->wiphy_data != NULL) | |
750 | return bss->wiphy_data; | |
751 | ||
752 | wiphy_idx = nl80211_get_wiphy_index(bss); | |
753 | ||
754 | dl_list_for_each(w, &nl80211_wiphys, struct nl80211_wiphy_data, list) { | |
755 | if (w->wiphy_idx == wiphy_idx) | |
756 | goto add; | |
757 | } | |
758 | ||
759 | /* alloc new one */ | |
760 | w = os_zalloc(sizeof(*w)); | |
761 | if (w == NULL) | |
762 | return NULL; | |
763 | w->wiphy_idx = wiphy_idx; | |
764 | dl_list_init(&w->bsss); | |
765 | dl_list_init(&w->drvs); | |
766 | ||
a70cd0db DL |
767 | /* Beacon frames not supported in IEEE 802.11ad */ |
768 | if (ieee80211_freq_to_chan(bss->freq, &channel) != | |
769 | HOSTAPD_MODE_IEEE80211AD) { | |
770 | w->nl_cb = nl_cb_alloc(NL_CB_DEFAULT); | |
771 | if (!w->nl_cb) { | |
772 | os_free(w); | |
773 | return NULL; | |
774 | } | |
775 | nl_cb_set(w->nl_cb, NL_CB_SEQ_CHECK, NL_CB_CUSTOM, | |
776 | no_seq_check, NULL); | |
777 | nl_cb_set(w->nl_cb, NL_CB_VALID, NL_CB_CUSTOM, | |
778 | process_beacon_event, w); | |
779 | ||
780 | w->nl_beacons = nl_create_handle(bss->drv->global->nl_cb, | |
781 | "wiphy beacons"); | |
782 | if (w->nl_beacons == NULL) { | |
783 | os_free(w); | |
784 | return NULL; | |
785 | } | |
e32ad281 | 786 | |
a70cd0db DL |
787 | if (nl80211_register_beacons(bss->drv, w)) { |
788 | nl_destroy_handles(&w->nl_beacons); | |
789 | os_free(w); | |
790 | return NULL; | |
791 | } | |
e32ad281 | 792 | |
a70cd0db | 793 | nl80211_register_eloop_read(&w->nl_beacons, |
40a68f33 | 794 | nl80211_recv_beacons, w, 0); |
e32ad281 JB |
795 | } |
796 | ||
e32ad281 JB |
797 | dl_list_add(&nl80211_wiphys, &w->list); |
798 | ||
799 | add: | |
800 | /* drv entry for this bss already there? */ | |
801 | dl_list_for_each(tmp_bss, &w->bsss, struct i802_bss, wiphy_list) { | |
802 | if (tmp_bss->drv == bss->drv) { | |
803 | found = 1; | |
804 | break; | |
805 | } | |
806 | } | |
807 | /* if not add it */ | |
808 | if (!found) | |
809 | dl_list_add(&w->drvs, &bss->drv->wiphy_list); | |
810 | ||
811 | dl_list_add(&w->bsss, &bss->wiphy_list); | |
812 | bss->wiphy_data = w; | |
813 | return w; | |
814 | } | |
815 | ||
816 | ||
817 | static void nl80211_put_wiphy_data_ap(struct i802_bss *bss) | |
818 | { | |
819 | struct nl80211_wiphy_data *w = bss->wiphy_data; | |
820 | struct i802_bss *tmp_bss; | |
821 | int found = 0; | |
822 | ||
823 | if (w == NULL) | |
824 | return; | |
825 | bss->wiphy_data = NULL; | |
826 | dl_list_del(&bss->wiphy_list); | |
827 | ||
828 | /* still any for this drv present? */ | |
829 | dl_list_for_each(tmp_bss, &w->bsss, struct i802_bss, wiphy_list) { | |
830 | if (tmp_bss->drv == bss->drv) { | |
831 | found = 1; | |
832 | break; | |
833 | } | |
834 | } | |
835 | /* if not remove it */ | |
836 | if (!found) | |
837 | dl_list_del(&bss->drv->wiphy_list); | |
838 | ||
839 | if (!dl_list_empty(&w->bsss)) | |
840 | return; | |
841 | ||
a70cd0db | 842 | if (w->nl_beacons) |
40a68f33 | 843 | nl80211_destroy_eloop_handle(&w->nl_beacons, 0); |
e32ad281 JB |
844 | |
845 | nl_cb_put(w->nl_cb); | |
e32ad281 JB |
846 | dl_list_del(&w->list); |
847 | os_free(w); | |
848 | } | |
849 | ||
850 | ||
45e3fc72 RM |
851 | static unsigned int nl80211_get_ifindex(void *priv) |
852 | { | |
853 | struct i802_bss *bss = priv; | |
854 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
855 | ||
856 | return drv->ifindex; | |
857 | } | |
858 | ||
859 | ||
3f5285e8 JM |
860 | static int wpa_driver_nl80211_get_bssid(void *priv, u8 *bssid) |
861 | { | |
a2e40bb6 FF |
862 | struct i802_bss *bss = priv; |
863 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
c2a04078 JM |
864 | if (!drv->associated) |
865 | return -1; | |
866 | os_memcpy(bssid, drv->bssid, ETH_ALEN); | |
867 | return 0; | |
3f5285e8 JM |
868 | } |
869 | ||
870 | ||
3f5285e8 JM |
871 | static int wpa_driver_nl80211_get_ssid(void *priv, u8 *ssid) |
872 | { | |
a2e40bb6 FF |
873 | struct i802_bss *bss = priv; |
874 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
fd05d64e JM |
875 | if (!drv->associated) |
876 | return -1; | |
877 | os_memcpy(ssid, drv->ssid, drv->ssid_len); | |
878 | return drv->ssid_len; | |
3f5285e8 JM |
879 | } |
880 | ||
881 | ||
90a545cc | 882 | static void wpa_driver_nl80211_event_newlink( |
45e3fc72 RM |
883 | struct nl80211_global *global, struct wpa_driver_nl80211_data *drv, |
884 | int ifindex, const char *ifname) | |
3f5285e8 JM |
885 | { |
886 | union wpa_event_data event; | |
887 | ||
45e3fc72 | 888 | if (drv && os_strcmp(drv->first_bss->ifname, ifname) == 0) { |
90a545cc JM |
889 | if (if_nametoindex(drv->first_bss->ifname) == 0) { |
890 | wpa_printf(MSG_DEBUG, "nl80211: Interface %s does not exist - ignore RTM_NEWLINK", | |
891 | drv->first_bss->ifname); | |
892 | return; | |
893 | } | |
894 | if (!drv->if_removed) | |
895 | return; | |
896 | wpa_printf(MSG_DEBUG, "nl80211: Mark if_removed=0 for %s based on RTM_NEWLINK event", | |
897 | drv->first_bss->ifname); | |
898 | drv->if_removed = 0; | |
899 | } | |
900 | ||
3f5285e8 | 901 | os_memset(&event, 0, sizeof(event)); |
45e3fc72 | 902 | event.interface_status.ifindex = ifindex; |
90a545cc JM |
903 | os_strlcpy(event.interface_status.ifname, ifname, |
904 | sizeof(event.interface_status.ifname)); | |
905 | event.interface_status.ievent = EVENT_INTERFACE_ADDED; | |
45e3fc72 RM |
906 | if (drv) |
907 | wpa_supplicant_event(drv->ctx, EVENT_INTERFACE_STATUS, &event); | |
908 | else | |
909 | wpa_supplicant_event_global(global->ctx, EVENT_INTERFACE_STATUS, | |
910 | &event); | |
90a545cc JM |
911 | } |
912 | ||
913 | ||
914 | static void wpa_driver_nl80211_event_dellink( | |
45e3fc72 RM |
915 | struct nl80211_global *global, struct wpa_driver_nl80211_data *drv, |
916 | int ifindex, const char *ifname) | |
90a545cc JM |
917 | { |
918 | union wpa_event_data event; | |
919 | ||
45e3fc72 | 920 | if (drv && os_strcmp(drv->first_bss->ifname, ifname) == 0) { |
90a545cc JM |
921 | if (drv->if_removed) { |
922 | wpa_printf(MSG_DEBUG, "nl80211: if_removed already set - ignore RTM_DELLINK event for %s", | |
923 | ifname); | |
924 | return; | |
d1f4942b | 925 | } |
90a545cc JM |
926 | wpa_printf(MSG_DEBUG, "RTM_DELLINK: Interface '%s' removed - mark if_removed=1", |
927 | ifname); | |
928 | drv->if_removed = 1; | |
929 | } else { | |
930 | wpa_printf(MSG_DEBUG, "RTM_DELLINK: Interface '%s' removed", | |
931 | ifname); | |
7524cfb1 JM |
932 | } |
933 | ||
90a545cc | 934 | os_memset(&event, 0, sizeof(event)); |
45e3fc72 | 935 | event.interface_status.ifindex = ifindex; |
90a545cc JM |
936 | os_strlcpy(event.interface_status.ifname, ifname, |
937 | sizeof(event.interface_status.ifname)); | |
938 | event.interface_status.ievent = EVENT_INTERFACE_REMOVED; | |
45e3fc72 RM |
939 | if (drv) |
940 | wpa_supplicant_event(drv->ctx, EVENT_INTERFACE_STATUS, &event); | |
941 | else | |
942 | wpa_supplicant_event_global(global->ctx, EVENT_INTERFACE_STATUS, | |
943 | &event); | |
3f5285e8 JM |
944 | } |
945 | ||
946 | ||
7524cfb1 | 947 | static int wpa_driver_nl80211_own_ifname(struct wpa_driver_nl80211_data *drv, |
62d680c3 | 948 | u8 *buf, size_t len) |
7524cfb1 | 949 | { |
62d680c3 | 950 | int attrlen, rta_len; |
7524cfb1 JM |
951 | struct rtattr *attr; |
952 | ||
62d680c3 JM |
953 | attrlen = len; |
954 | attr = (struct rtattr *) buf; | |
7524cfb1 JM |
955 | |
956 | rta_len = RTA_ALIGN(sizeof(struct rtattr)); | |
957 | while (RTA_OK(attr, attrlen)) { | |
958 | if (attr->rta_type == IFLA_IFNAME) { | |
834ee56f KP |
959 | if (os_strcmp(((char *) attr) + rta_len, |
960 | drv->first_bss->ifname) == 0) | |
7524cfb1 JM |
961 | return 1; |
962 | else | |
963 | break; | |
964 | } | |
965 | attr = RTA_NEXT(attr, attrlen); | |
966 | } | |
967 | ||
968 | return 0; | |
969 | } | |
970 | ||
971 | ||
972 | static int wpa_driver_nl80211_own_ifindex(struct wpa_driver_nl80211_data *drv, | |
62d680c3 | 973 | int ifindex, u8 *buf, size_t len) |
7524cfb1 JM |
974 | { |
975 | if (drv->ifindex == ifindex) | |
976 | return 1; | |
977 | ||
62d680c3 | 978 | if (drv->if_removed && wpa_driver_nl80211_own_ifname(drv, buf, len)) { |
f51f54a0 | 979 | nl80211_check_global(drv->global); |
7524cfb1 JM |
980 | wpa_printf(MSG_DEBUG, "nl80211: Update ifindex for a removed " |
981 | "interface"); | |
5e0c20ff JM |
982 | if (wpa_driver_nl80211_finish_drv_init(drv, NULL, 0, NULL) < 0) |
983 | return -1; | |
7524cfb1 JM |
984 | return 1; |
985 | } | |
986 | ||
987 | return 0; | |
988 | } | |
989 | ||
990 | ||
36d84860 | 991 | static struct wpa_driver_nl80211_data * |
5e0c20ff JM |
992 | nl80211_find_drv(struct nl80211_global *global, int idx, u8 *buf, size_t len, |
993 | int *init_failed) | |
36d84860 BG |
994 | { |
995 | struct wpa_driver_nl80211_data *drv; | |
5e0c20ff JM |
996 | int res; |
997 | ||
998 | if (init_failed) | |
999 | *init_failed = 0; | |
36d84860 BG |
1000 | dl_list_for_each(drv, &global->interfaces, |
1001 | struct wpa_driver_nl80211_data, list) { | |
5e0c20ff JM |
1002 | res = wpa_driver_nl80211_own_ifindex(drv, idx, buf, len); |
1003 | if (res < 0) { | |
1004 | wpa_printf(MSG_DEBUG, | |
1005 | "nl80211: Found matching own interface, but failed to complete reinitialization"); | |
1006 | if (init_failed) | |
1007 | *init_failed = 1; | |
1008 | return drv; | |
1009 | } | |
1010 | if (res > 0 || have_ifidx(drv, idx, IFIDX_ANY)) | |
36d84860 BG |
1011 | return drv; |
1012 | } | |
1013 | return NULL; | |
1014 | } | |
1015 | ||
1016 | ||
290834df | 1017 | static void nl80211_refresh_mac(struct wpa_driver_nl80211_data *drv, |
77a020a1 | 1018 | int ifindex, int notify) |
290834df BG |
1019 | { |
1020 | struct i802_bss *bss; | |
1021 | u8 addr[ETH_ALEN]; | |
1022 | ||
1023 | bss = get_bss_ifindex(drv, ifindex); | |
1024 | if (bss && | |
1025 | linux_get_ifhwaddr(drv->global->ioctl_sock, | |
1026 | bss->ifname, addr) < 0) { | |
1027 | wpa_printf(MSG_DEBUG, | |
1028 | "nl80211: %s: failed to re-read MAC address", | |
1029 | bss->ifname); | |
1030 | } else if (bss && os_memcmp(addr, bss->addr, ETH_ALEN) != 0) { | |
1031 | wpa_printf(MSG_DEBUG, | |
1032 | "nl80211: Own MAC address on ifindex %d (%s) changed from " | |
1033 | MACSTR " to " MACSTR, | |
1034 | ifindex, bss->ifname, | |
1035 | MAC2STR(bss->addr), MAC2STR(addr)); | |
1036 | os_memcpy(bss->addr, addr, ETH_ALEN); | |
77a020a1 BG |
1037 | if (notify) |
1038 | wpa_supplicant_event(drv->ctx, | |
1039 | EVENT_INTERFACE_MAC_CHANGED, NULL); | |
290834df BG |
1040 | } |
1041 | } | |
1042 | ||
1043 | ||
62d680c3 JM |
1044 | static void wpa_driver_nl80211_event_rtm_newlink(void *ctx, |
1045 | struct ifinfomsg *ifi, | |
1046 | u8 *buf, size_t len) | |
3f5285e8 | 1047 | { |
36d84860 BG |
1048 | struct nl80211_global *global = ctx; |
1049 | struct wpa_driver_nl80211_data *drv; | |
90a545cc | 1050 | int attrlen; |
62d680c3 | 1051 | struct rtattr *attr; |
97cfcf64 | 1052 | u32 brid = 0; |
aef85ba2 | 1053 | char namebuf[IFNAMSIZ]; |
90a545cc JM |
1054 | char ifname[IFNAMSIZ + 1]; |
1055 | char extra[100], *pos, *end; | |
5e0c20ff | 1056 | int init_failed; |
3f5285e8 | 1057 | |
90a545cc JM |
1058 | extra[0] = '\0'; |
1059 | pos = extra; | |
1060 | end = pos + sizeof(extra); | |
1061 | ifname[0] = '\0'; | |
1062 | ||
1063 | attrlen = len; | |
1064 | attr = (struct rtattr *) buf; | |
1065 | while (RTA_OK(attr, attrlen)) { | |
1066 | switch (attr->rta_type) { | |
1067 | case IFLA_IFNAME: | |
1068 | if (RTA_PAYLOAD(attr) >= IFNAMSIZ) | |
1069 | break; | |
1070 | os_memcpy(ifname, RTA_DATA(attr), RTA_PAYLOAD(attr)); | |
1071 | ifname[RTA_PAYLOAD(attr)] = '\0'; | |
1072 | break; | |
1073 | case IFLA_MASTER: | |
1074 | brid = nla_get_u32((struct nlattr *) attr); | |
1075 | pos += os_snprintf(pos, end - pos, " master=%u", brid); | |
1076 | break; | |
1077 | case IFLA_WIRELESS: | |
1078 | pos += os_snprintf(pos, end - pos, " wext"); | |
1079 | break; | |
1080 | case IFLA_OPERSTATE: | |
1081 | pos += os_snprintf(pos, end - pos, " operstate=%u", | |
1082 | nla_get_u32((struct nlattr *) attr)); | |
1083 | break; | |
1084 | case IFLA_LINKMODE: | |
1085 | pos += os_snprintf(pos, end - pos, " linkmode=%u", | |
1086 | nla_get_u32((struct nlattr *) attr)); | |
1087 | break; | |
1088 | } | |
1089 | attr = RTA_NEXT(attr, attrlen); | |
1090 | } | |
1091 | extra[sizeof(extra) - 1] = '\0'; | |
1092 | ||
f2e90835 JM |
1093 | wpa_printf(MSG_DEBUG, "RTM_NEWLINK: ifi_index=%d ifname=%s%s ifi_family=%d ifi_flags=0x%x (%s%s%s%s)", |
1094 | ifi->ifi_index, ifname, extra, ifi->ifi_family, | |
1095 | ifi->ifi_flags, | |
3f5285e8 JM |
1096 | (ifi->ifi_flags & IFF_UP) ? "[UP]" : "", |
1097 | (ifi->ifi_flags & IFF_RUNNING) ? "[RUNNING]" : "", | |
1098 | (ifi->ifi_flags & IFF_LOWER_UP) ? "[LOWER_UP]" : "", | |
1099 | (ifi->ifi_flags & IFF_DORMANT) ? "[DORMANT]" : ""); | |
a63063b4 | 1100 | |
5e0c20ff | 1101 | drv = nl80211_find_drv(global, ifi->ifi_index, buf, len, &init_failed); |
45e3fc72 RM |
1102 | if (!drv) |
1103 | goto event_newlink; | |
5e0c20ff JM |
1104 | if (init_failed) |
1105 | return; /* do not update interface state */ | |
45e3fc72 | 1106 | |
a63063b4 | 1107 | if (!drv->if_disabled && !(ifi->ifi_flags & IFF_UP)) { |
106fa1e9 | 1108 | namebuf[0] = '\0'; |
59d24925 | 1109 | if (if_indextoname(ifi->ifi_index, namebuf) && |
106fa1e9 | 1110 | linux_iface_up(drv->global->ioctl_sock, namebuf) > 0) { |
59d24925 JM |
1111 | wpa_printf(MSG_DEBUG, "nl80211: Ignore interface down " |
1112 | "event since interface %s is up", namebuf); | |
7a94120e | 1113 | drv->ignore_if_down_event = 0; |
77a020a1 BG |
1114 | /* Re-read MAC address as it may have changed */ |
1115 | nl80211_refresh_mac(drv, ifi->ifi_index, 1); | |
59d24925 JM |
1116 | return; |
1117 | } | |
106fa1e9 JM |
1118 | wpa_printf(MSG_DEBUG, "nl80211: Interface down (%s/%s)", |
1119 | namebuf, ifname); | |
1120 | if (os_strcmp(drv->first_bss->ifname, ifname) != 0) { | |
1121 | wpa_printf(MSG_DEBUG, | |
1122 | "nl80211: Not the main interface (%s) - do not indicate interface down", | |
1123 | drv->first_bss->ifname); | |
1124 | } else if (drv->ignore_if_down_event) { | |
7d9c3698 JM |
1125 | wpa_printf(MSG_DEBUG, "nl80211: Ignore interface down " |
1126 | "event generated by mode change"); | |
1127 | drv->ignore_if_down_event = 0; | |
1128 | } else { | |
1129 | drv->if_disabled = 1; | |
1130 | wpa_supplicant_event(drv->ctx, | |
1131 | EVENT_INTERFACE_DISABLED, NULL); | |
819f096f AO |
1132 | |
1133 | /* | |
1134 | * Try to get drv again, since it may be removed as | |
1135 | * part of the EVENT_INTERFACE_DISABLED handling for | |
1136 | * dynamic interfaces | |
1137 | */ | |
1138 | drv = nl80211_find_drv(global, ifi->ifi_index, | |
5e0c20ff | 1139 | buf, len, NULL); |
819f096f AO |
1140 | if (!drv) |
1141 | return; | |
7d9c3698 | 1142 | } |
a63063b4 JM |
1143 | } |
1144 | ||
1145 | if (drv->if_disabled && (ifi->ifi_flags & IFF_UP)) { | |
8a9950f7 | 1146 | namebuf[0] = '\0'; |
aef85ba2 | 1147 | if (if_indextoname(ifi->ifi_index, namebuf) && |
106fa1e9 | 1148 | linux_iface_up(drv->global->ioctl_sock, namebuf) == 0) { |
aef85ba2 JM |
1149 | wpa_printf(MSG_DEBUG, "nl80211: Ignore interface up " |
1150 | "event since interface %s is down", | |
1151 | namebuf); | |
8a9950f7 HW |
1152 | return; |
1153 | } | |
1154 | wpa_printf(MSG_DEBUG, "nl80211: Interface up (%s/%s)", | |
1155 | namebuf, ifname); | |
1156 | if (os_strcmp(drv->first_bss->ifname, ifname) != 0) { | |
1157 | wpa_printf(MSG_DEBUG, | |
1158 | "nl80211: Not the main interface (%s) - do not indicate interface up", | |
1159 | drv->first_bss->ifname); | |
834ee56f | 1160 | } else if (if_nametoindex(drv->first_bss->ifname) == 0) { |
d1f4942b JM |
1161 | wpa_printf(MSG_DEBUG, "nl80211: Ignore interface up " |
1162 | "event since interface %s does not exist", | |
834ee56f | 1163 | drv->first_bss->ifname); |
d1f4942b JM |
1164 | } else if (drv->if_removed) { |
1165 | wpa_printf(MSG_DEBUG, "nl80211: Ignore interface up " | |
1166 | "event since interface %s is marked " | |
834ee56f | 1167 | "removed", drv->first_bss->ifname); |
aef85ba2 | 1168 | } else { |
3e0272ca | 1169 | /* Re-read MAC address as it may have changed */ |
77a020a1 | 1170 | nl80211_refresh_mac(drv, ifi->ifi_index, 0); |
3e0272ca | 1171 | |
aef85ba2 JM |
1172 | drv->if_disabled = 0; |
1173 | wpa_supplicant_event(drv->ctx, EVENT_INTERFACE_ENABLED, | |
1174 | NULL); | |
1175 | } | |
a63063b4 JM |
1176 | } |
1177 | ||
3f5285e8 JM |
1178 | /* |
1179 | * Some drivers send the association event before the operup event--in | |
1180 | * this case, lifting operstate in wpa_driver_nl80211_set_operstate() | |
1181 | * fails. This will hit us when wpa_supplicant does not need to do | |
1182 | * IEEE 802.1X authentication | |
1183 | */ | |
1184 | if (drv->operstate == 1 && | |
1185 | (ifi->ifi_flags & (IFF_LOWER_UP | IFF_DORMANT)) == IFF_LOWER_UP && | |
90a545cc JM |
1186 | !(ifi->ifi_flags & IFF_RUNNING)) { |
1187 | wpa_printf(MSG_DEBUG, "nl80211: Set IF_OPER_UP again based on ifi_flags and expected operstate"); | |
36d84860 | 1188 | netlink_send_oper_ifla(drv->global->netlink, drv->ifindex, |
e2d02c29 | 1189 | -1, IF_OPER_UP); |
3f5285e8 | 1190 | } |
97cfcf64 | 1191 | |
45e3fc72 | 1192 | event_newlink: |
90a545cc | 1193 | if (ifname[0]) |
45e3fc72 RM |
1194 | wpa_driver_nl80211_event_newlink(global, drv, ifi->ifi_index, |
1195 | ifname); | |
90a545cc | 1196 | |
45e3fc72 | 1197 | if (ifi->ifi_family == AF_BRIDGE && brid && drv) { |
392dfd37 JM |
1198 | struct i802_bss *bss; |
1199 | ||
97cfcf64 | 1200 | /* device has been added to bridge */ |
40e76396 JM |
1201 | if (!if_indextoname(brid, namebuf)) { |
1202 | wpa_printf(MSG_DEBUG, | |
1203 | "nl80211: Could not find bridge ifname for ifindex %u", | |
1204 | brid); | |
1205 | return; | |
1206 | } | |
97cfcf64 B |
1207 | wpa_printf(MSG_DEBUG, "nl80211: Add ifindex %u for bridge %s", |
1208 | brid, namebuf); | |
732b1d20 | 1209 | add_ifidx(drv, brid, ifi->ifi_index); |
392dfd37 JM |
1210 | |
1211 | for (bss = drv->first_bss; bss; bss = bss->next) { | |
1212 | if (os_strcmp(ifname, bss->ifname) == 0) { | |
1213 | os_strlcpy(bss->brname, namebuf, IFNAMSIZ); | |
1214 | break; | |
1215 | } | |
1216 | } | |
97cfcf64 | 1217 | } |
3f5285e8 JM |
1218 | } |
1219 | ||
1220 | ||
62d680c3 JM |
1221 | static void wpa_driver_nl80211_event_rtm_dellink(void *ctx, |
1222 | struct ifinfomsg *ifi, | |
1223 | u8 *buf, size_t len) | |
3f5285e8 | 1224 | { |
36d84860 BG |
1225 | struct nl80211_global *global = ctx; |
1226 | struct wpa_driver_nl80211_data *drv; | |
90a545cc | 1227 | int attrlen; |
62d680c3 | 1228 | struct rtattr *attr; |
97cfcf64 | 1229 | u32 brid = 0; |
90a545cc | 1230 | char ifname[IFNAMSIZ + 1]; |
f2e90835 | 1231 | char extra[100], *pos, *end; |
3f5285e8 | 1232 | |
f2e90835 JM |
1233 | extra[0] = '\0'; |
1234 | pos = extra; | |
1235 | end = pos + sizeof(extra); | |
90a545cc JM |
1236 | ifname[0] = '\0'; |
1237 | ||
62d680c3 JM |
1238 | attrlen = len; |
1239 | attr = (struct rtattr *) buf; | |
3f5285e8 | 1240 | while (RTA_OK(attr, attrlen)) { |
90a545cc JM |
1241 | switch (attr->rta_type) { |
1242 | case IFLA_IFNAME: | |
1243 | if (RTA_PAYLOAD(attr) >= IFNAMSIZ) | |
1244 | break; | |
1245 | os_memcpy(ifname, RTA_DATA(attr), RTA_PAYLOAD(attr)); | |
1246 | ifname[RTA_PAYLOAD(attr)] = '\0'; | |
1247 | break; | |
1248 | case IFLA_MASTER: | |
97cfcf64 | 1249 | brid = nla_get_u32((struct nlattr *) attr); |
f2e90835 JM |
1250 | pos += os_snprintf(pos, end - pos, " master=%u", brid); |
1251 | break; | |
1252 | case IFLA_OPERSTATE: | |
1253 | pos += os_snprintf(pos, end - pos, " operstate=%u", | |
1254 | nla_get_u32((struct nlattr *) attr)); | |
1255 | break; | |
1256 | case IFLA_LINKMODE: | |
1257 | pos += os_snprintf(pos, end - pos, " linkmode=%u", | |
1258 | nla_get_u32((struct nlattr *) attr)); | |
90a545cc JM |
1259 | break; |
1260 | } | |
3f5285e8 JM |
1261 | attr = RTA_NEXT(attr, attrlen); |
1262 | } | |
f2e90835 JM |
1263 | extra[sizeof(extra) - 1] = '\0'; |
1264 | ||
1265 | wpa_printf(MSG_DEBUG, "RTM_DELLINK: ifi_index=%d ifname=%s%s ifi_family=%d ifi_flags=0x%x (%s%s%s%s)", | |
1266 | ifi->ifi_index, ifname, extra, ifi->ifi_family, | |
1267 | ifi->ifi_flags, | |
1268 | (ifi->ifi_flags & IFF_UP) ? "[UP]" : "", | |
1269 | (ifi->ifi_flags & IFF_RUNNING) ? "[RUNNING]" : "", | |
1270 | (ifi->ifi_flags & IFF_LOWER_UP) ? "[LOWER_UP]" : "", | |
1271 | (ifi->ifi_flags & IFF_DORMANT) ? "[DORMANT]" : ""); | |
97cfcf64 | 1272 | |
5e0c20ff | 1273 | drv = nl80211_find_drv(global, ifi->ifi_index, buf, len, NULL); |
90a545cc | 1274 | |
45e3fc72 | 1275 | if (ifi->ifi_family == AF_BRIDGE && brid && drv) { |
97cfcf64 B |
1276 | /* device has been removed from bridge */ |
1277 | char namebuf[IFNAMSIZ]; | |
40e76396 JM |
1278 | |
1279 | if (!if_indextoname(brid, namebuf)) { | |
1280 | wpa_printf(MSG_DEBUG, | |
1281 | "nl80211: Could not find bridge ifname for ifindex %u", | |
1282 | brid); | |
1283 | } else { | |
1284 | wpa_printf(MSG_DEBUG, | |
1285 | "nl80211: Remove ifindex %u for bridge %s", | |
1286 | brid, namebuf); | |
1287 | } | |
732b1d20 | 1288 | del_ifidx(drv, brid, ifi->ifi_index); |
97cfcf64 | 1289 | } |
45e3fc72 RM |
1290 | |
1291 | if (ifi->ifi_family != AF_BRIDGE || !brid) | |
1292 | wpa_driver_nl80211_event_dellink(global, drv, ifi->ifi_index, | |
1293 | ifname); | |
3f5285e8 JM |
1294 | } |
1295 | ||
1296 | ||
a1fce391 JM |
1297 | struct nl80211_get_assoc_freq_arg { |
1298 | struct wpa_driver_nl80211_data *drv; | |
1299 | unsigned int assoc_freq; | |
1300 | unsigned int ibss_freq; | |
1301 | u8 assoc_bssid[ETH_ALEN]; | |
ed0a4ddc NW |
1302 | u8 assoc_ssid[SSID_MAX_LEN]; |
1303 | u8 assoc_ssid_len; | |
a1fce391 JM |
1304 | }; |
1305 | ||
1306 | static int nl80211_get_assoc_freq_handler(struct nl_msg *msg, void *arg) | |
1307 | { | |
1308 | struct nlattr *tb[NL80211_ATTR_MAX + 1]; | |
1309 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); | |
1310 | struct nlattr *bss[NL80211_BSS_MAX + 1]; | |
1311 | static struct nla_policy bss_policy[NL80211_BSS_MAX + 1] = { | |
1312 | [NL80211_BSS_BSSID] = { .type = NLA_UNSPEC }, | |
1313 | [NL80211_BSS_FREQUENCY] = { .type = NLA_U32 }, | |
ed0a4ddc | 1314 | [NL80211_BSS_INFORMATION_ELEMENTS] = { .type = NLA_UNSPEC }, |
a1fce391 JM |
1315 | [NL80211_BSS_STATUS] = { .type = NLA_U32 }, |
1316 | }; | |
1317 | struct nl80211_get_assoc_freq_arg *ctx = arg; | |
1318 | enum nl80211_bss_status status; | |
1319 | ||
1320 | nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), | |
1321 | genlmsg_attrlen(gnlh, 0), NULL); | |
1322 | if (!tb[NL80211_ATTR_BSS] || | |
1323 | nla_parse_nested(bss, NL80211_BSS_MAX, tb[NL80211_ATTR_BSS], | |
1324 | bss_policy) || | |
1325 | !bss[NL80211_BSS_STATUS]) | |
1326 | return NL_SKIP; | |
1327 | ||
1328 | status = nla_get_u32(bss[NL80211_BSS_STATUS]); | |
1329 | if (status == NL80211_BSS_STATUS_ASSOCIATED && | |
1330 | bss[NL80211_BSS_FREQUENCY]) { | |
1331 | ctx->assoc_freq = nla_get_u32(bss[NL80211_BSS_FREQUENCY]); | |
1332 | wpa_printf(MSG_DEBUG, "nl80211: Associated on %u MHz", | |
1333 | ctx->assoc_freq); | |
1334 | } | |
1335 | if (status == NL80211_BSS_STATUS_IBSS_JOINED && | |
1336 | bss[NL80211_BSS_FREQUENCY]) { | |
1337 | ctx->ibss_freq = nla_get_u32(bss[NL80211_BSS_FREQUENCY]); | |
1338 | wpa_printf(MSG_DEBUG, "nl80211: IBSS-joined on %u MHz", | |
1339 | ctx->ibss_freq); | |
1340 | } | |
1341 | if (status == NL80211_BSS_STATUS_ASSOCIATED && | |
1342 | bss[NL80211_BSS_BSSID]) { | |
1343 | os_memcpy(ctx->assoc_bssid, | |
1344 | nla_data(bss[NL80211_BSS_BSSID]), ETH_ALEN); | |
1345 | wpa_printf(MSG_DEBUG, "nl80211: Associated with " | |
1346 | MACSTR, MAC2STR(ctx->assoc_bssid)); | |
1347 | } | |
1348 | ||
ed0a4ddc NW |
1349 | if (status == NL80211_BSS_STATUS_ASSOCIATED && |
1350 | bss[NL80211_BSS_INFORMATION_ELEMENTS]) { | |
1351 | const u8 *ie, *ssid; | |
1352 | size_t ie_len; | |
1353 | ||
1354 | ie = nla_data(bss[NL80211_BSS_INFORMATION_ELEMENTS]); | |
1355 | ie_len = nla_len(bss[NL80211_BSS_INFORMATION_ELEMENTS]); | |
1356 | ssid = get_ie(ie, ie_len, WLAN_EID_SSID); | |
1357 | if (ssid && ssid[1] > 0 && ssid[1] <= SSID_MAX_LEN) { | |
1358 | ctx->assoc_ssid_len = ssid[1]; | |
1359 | os_memcpy(ctx->assoc_ssid, ssid + 2, ssid[1]); | |
1360 | } | |
1361 | } | |
1362 | ||
a1fce391 JM |
1363 | return NL_SKIP; |
1364 | } | |
1365 | ||
1366 | ||
ed0a4ddc NW |
1367 | int nl80211_get_assoc_ssid(struct wpa_driver_nl80211_data *drv, u8 *ssid) |
1368 | { | |
1369 | struct nl_msg *msg; | |
1370 | int ret; | |
1371 | struct nl80211_get_assoc_freq_arg arg; | |
1372 | ||
1373 | msg = nl80211_drv_msg(drv, NLM_F_DUMP, NL80211_CMD_GET_SCAN); | |
1374 | os_memset(&arg, 0, sizeof(arg)); | |
1375 | arg.drv = drv; | |
1376 | ret = send_and_recv_msgs(drv, msg, nl80211_get_assoc_freq_handler, | |
1377 | &arg); | |
1378 | if (ret == 0) { | |
1379 | os_memcpy(ssid, arg.assoc_ssid, arg.assoc_ssid_len); | |
1380 | return arg.assoc_ssid_len; | |
1381 | } | |
1382 | wpa_printf(MSG_DEBUG, "nl80211: Scan result fetch failed: ret=%d (%s)", | |
1383 | ret, strerror(-ret)); | |
1384 | return ret; | |
1385 | } | |
1386 | ||
1387 | ||
f3407c66 | 1388 | unsigned int nl80211_get_assoc_freq(struct wpa_driver_nl80211_data *drv) |
f5a8d422 JM |
1389 | { |
1390 | struct nl_msg *msg; | |
1391 | int ret; | |
a1fce391 | 1392 | struct nl80211_get_assoc_freq_arg arg; |
f5a8d422 | 1393 | |
9725b784 | 1394 | msg = nl80211_drv_msg(drv, NLM_F_DUMP, NL80211_CMD_GET_SCAN); |
f5a8d422 | 1395 | os_memset(&arg, 0, sizeof(arg)); |
f5a8d422 | 1396 | arg.drv = drv; |
a1fce391 JM |
1397 | ret = send_and_recv_msgs(drv, msg, nl80211_get_assoc_freq_handler, |
1398 | &arg); | |
f5a8d422 | 1399 | if (ret == 0) { |
c7caac56 JM |
1400 | unsigned int freq = drv->nlmode == NL80211_IFTYPE_ADHOC ? |
1401 | arg.ibss_freq : arg.assoc_freq; | |
f5a8d422 | 1402 | wpa_printf(MSG_DEBUG, "nl80211: Operating frequency for the " |
c7caac56 JM |
1403 | "associated BSS from scan results: %u MHz", freq); |
1404 | if (freq) | |
1405 | drv->assoc_freq = freq; | |
30158a0d | 1406 | return drv->assoc_freq; |
f5a8d422 JM |
1407 | } |
1408 | wpa_printf(MSG_DEBUG, "nl80211: Scan result fetch failed: ret=%d " | |
1409 | "(%s)", ret, strerror(-ret)); | |
f5a8d422 JM |
1410 | return drv->assoc_freq; |
1411 | } | |
1412 | ||
1413 | ||
60a972a6 JM |
1414 | static int get_link_signal(struct nl_msg *msg, void *arg) |
1415 | { | |
1416 | struct nlattr *tb[NL80211_ATTR_MAX + 1]; | |
1417 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); | |
1418 | struct nlattr *sinfo[NL80211_STA_INFO_MAX + 1]; | |
1419 | static struct nla_policy policy[NL80211_STA_INFO_MAX + 1] = { | |
1420 | [NL80211_STA_INFO_SIGNAL] = { .type = NLA_U8 }, | |
95783298 | 1421 | [NL80211_STA_INFO_SIGNAL_AVG] = { .type = NLA_U8 }, |
74fa78b2 | 1422 | [NL80211_STA_INFO_BEACON_SIGNAL_AVG] = { .type = NLA_U8 }, |
60a972a6 | 1423 | }; |
7ee35bf3 PS |
1424 | struct nlattr *rinfo[NL80211_RATE_INFO_MAX + 1]; |
1425 | static struct nla_policy rate_policy[NL80211_RATE_INFO_MAX + 1] = { | |
1426 | [NL80211_RATE_INFO_BITRATE] = { .type = NLA_U16 }, | |
1427 | [NL80211_RATE_INFO_MCS] = { .type = NLA_U8 }, | |
1428 | [NL80211_RATE_INFO_40_MHZ_WIDTH] = { .type = NLA_FLAG }, | |
1429 | [NL80211_RATE_INFO_SHORT_GI] = { .type = NLA_FLAG }, | |
1430 | }; | |
1c5c7273 | 1431 | struct wpa_signal_info *sig_change = arg; |
60a972a6 JM |
1432 | |
1433 | nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), | |
1434 | genlmsg_attrlen(gnlh, 0), NULL); | |
1435 | if (!tb[NL80211_ATTR_STA_INFO] || | |
1436 | nla_parse_nested(sinfo, NL80211_STA_INFO_MAX, | |
1437 | tb[NL80211_ATTR_STA_INFO], policy)) | |
1438 | return NL_SKIP; | |
1439 | if (!sinfo[NL80211_STA_INFO_SIGNAL]) | |
1440 | return NL_SKIP; | |
1441 | ||
7ee35bf3 PS |
1442 | sig_change->current_signal = |
1443 | (s8) nla_get_u8(sinfo[NL80211_STA_INFO_SIGNAL]); | |
1444 | ||
95783298 AO |
1445 | if (sinfo[NL80211_STA_INFO_SIGNAL_AVG]) |
1446 | sig_change->avg_signal = | |
1447 | (s8) nla_get_u8(sinfo[NL80211_STA_INFO_SIGNAL_AVG]); | |
1448 | else | |
1449 | sig_change->avg_signal = 0; | |
1450 | ||
74fa78b2 JM |
1451 | if (sinfo[NL80211_STA_INFO_BEACON_SIGNAL_AVG]) |
1452 | sig_change->avg_beacon_signal = | |
1453 | (s8) | |
1454 | nla_get_u8(sinfo[NL80211_STA_INFO_BEACON_SIGNAL_AVG]); | |
1455 | else | |
1456 | sig_change->avg_beacon_signal = 0; | |
1457 | ||
7ee35bf3 PS |
1458 | if (sinfo[NL80211_STA_INFO_TX_BITRATE]) { |
1459 | if (nla_parse_nested(rinfo, NL80211_RATE_INFO_MAX, | |
1460 | sinfo[NL80211_STA_INFO_TX_BITRATE], | |
1461 | rate_policy)) { | |
1462 | sig_change->current_txrate = 0; | |
1463 | } else { | |
1464 | if (rinfo[NL80211_RATE_INFO_BITRATE]) { | |
1465 | sig_change->current_txrate = | |
1466 | nla_get_u16(rinfo[ | |
1467 | NL80211_RATE_INFO_BITRATE]) * 100; | |
1468 | } | |
1469 | } | |
1470 | } | |
1471 | ||
60a972a6 JM |
1472 | return NL_SKIP; |
1473 | } | |
1474 | ||
1475 | ||
f3407c66 JM |
1476 | int nl80211_get_link_signal(struct wpa_driver_nl80211_data *drv, |
1477 | struct wpa_signal_info *sig) | |
60a972a6 JM |
1478 | { |
1479 | struct nl_msg *msg; | |
1480 | ||
941807f6 | 1481 | sig->current_signal = -WPA_INVALID_NOISE; |
7ee35bf3 | 1482 | sig->current_txrate = 0; |
60a972a6 | 1483 | |
9725b784 | 1484 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_GET_STATION)) || |
a862e4a3 JM |
1485 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, drv->bssid)) { |
1486 | nlmsg_free(msg); | |
1487 | return -ENOBUFS; | |
1488 | } | |
60a972a6 JM |
1489 | |
1490 | return send_and_recv_msgs(drv, msg, get_link_signal, sig); | |
60a972a6 JM |
1491 | } |
1492 | ||
1493 | ||
7ee35bf3 PS |
1494 | static int get_link_noise(struct nl_msg *msg, void *arg) |
1495 | { | |
1496 | struct nlattr *tb[NL80211_ATTR_MAX + 1]; | |
1497 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); | |
1498 | struct nlattr *sinfo[NL80211_SURVEY_INFO_MAX + 1]; | |
1499 | static struct nla_policy survey_policy[NL80211_SURVEY_INFO_MAX + 1] = { | |
1500 | [NL80211_SURVEY_INFO_FREQUENCY] = { .type = NLA_U32 }, | |
1501 | [NL80211_SURVEY_INFO_NOISE] = { .type = NLA_U8 }, | |
1502 | }; | |
1c5c7273 | 1503 | struct wpa_signal_info *sig_change = arg; |
7ee35bf3 PS |
1504 | |
1505 | nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), | |
1506 | genlmsg_attrlen(gnlh, 0), NULL); | |
1507 | ||
1508 | if (!tb[NL80211_ATTR_SURVEY_INFO]) { | |
1509 | wpa_printf(MSG_DEBUG, "nl80211: survey data missing!"); | |
1510 | return NL_SKIP; | |
1511 | } | |
1512 | ||
1513 | if (nla_parse_nested(sinfo, NL80211_SURVEY_INFO_MAX, | |
1514 | tb[NL80211_ATTR_SURVEY_INFO], | |
1515 | survey_policy)) { | |
1516 | wpa_printf(MSG_DEBUG, "nl80211: failed to parse nested " | |
1517 | "attributes!"); | |
1518 | return NL_SKIP; | |
1519 | } | |
1520 | ||
1521 | if (!sinfo[NL80211_SURVEY_INFO_FREQUENCY]) | |
1522 | return NL_SKIP; | |
1523 | ||
1524 | if (nla_get_u32(sinfo[NL80211_SURVEY_INFO_FREQUENCY]) != | |
1525 | sig_change->frequency) | |
1526 | return NL_SKIP; | |
1527 | ||
1528 | if (!sinfo[NL80211_SURVEY_INFO_NOISE]) | |
1529 | return NL_SKIP; | |
1530 | ||
1531 | sig_change->current_noise = | |
1532 | (s8) nla_get_u8(sinfo[NL80211_SURVEY_INFO_NOISE]); | |
1533 | ||
1534 | return NL_SKIP; | |
1535 | } | |
1536 | ||
1537 | ||
f3407c66 JM |
1538 | int nl80211_get_link_noise(struct wpa_driver_nl80211_data *drv, |
1539 | struct wpa_signal_info *sig_change) | |
7ee35bf3 PS |
1540 | { |
1541 | struct nl_msg *msg; | |
1542 | ||
941807f6 | 1543 | sig_change->current_noise = WPA_INVALID_NOISE; |
7ee35bf3 PS |
1544 | sig_change->frequency = drv->assoc_freq; |
1545 | ||
9725b784 | 1546 | msg = nl80211_drv_msg(drv, NLM_F_DUMP, NL80211_CMD_GET_SURVEY); |
7ee35bf3 | 1547 | return send_and_recv_msgs(drv, msg, get_link_noise, sig_change); |
7ee35bf3 PS |
1548 | } |
1549 | ||
1550 | ||
7f00dc6e MV |
1551 | static int get_channel_info(struct nl_msg *msg, void *arg) |
1552 | { | |
1553 | struct nlattr *tb[NL80211_ATTR_MAX + 1] = { 0 }; | |
1554 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); | |
1555 | struct wpa_channel_info *chan_info = arg; | |
1556 | ||
1557 | nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), | |
1558 | genlmsg_attrlen(gnlh, 0), NULL); | |
1559 | ||
1560 | os_memset(chan_info, 0, sizeof(struct wpa_channel_info)); | |
1561 | chan_info->chanwidth = CHAN_WIDTH_UNKNOWN; | |
1562 | ||
1563 | if (tb[NL80211_ATTR_WIPHY_FREQ]) | |
1564 | chan_info->frequency = | |
1565 | nla_get_u32(tb[NL80211_ATTR_WIPHY_FREQ]); | |
1566 | if (tb[NL80211_ATTR_CHANNEL_WIDTH]) | |
1567 | chan_info->chanwidth = convert2width( | |
1568 | nla_get_u32(tb[NL80211_ATTR_CHANNEL_WIDTH])); | |
1569 | if (tb[NL80211_ATTR_WIPHY_CHANNEL_TYPE]) { | |
1570 | enum nl80211_channel_type ct = | |
1571 | nla_get_u32(tb[NL80211_ATTR_WIPHY_CHANNEL_TYPE]); | |
1572 | ||
1573 | switch (ct) { | |
1574 | case NL80211_CHAN_HT40MINUS: | |
1575 | chan_info->sec_channel = -1; | |
1576 | break; | |
1577 | case NL80211_CHAN_HT40PLUS: | |
1578 | chan_info->sec_channel = 1; | |
1579 | break; | |
1580 | default: | |
1581 | chan_info->sec_channel = 0; | |
1582 | break; | |
1583 | } | |
1584 | } | |
1585 | if (tb[NL80211_ATTR_CENTER_FREQ1]) | |
1586 | chan_info->center_frq1 = | |
1587 | nla_get_u32(tb[NL80211_ATTR_CENTER_FREQ1]); | |
1588 | if (tb[NL80211_ATTR_CENTER_FREQ2]) | |
1589 | chan_info->center_frq2 = | |
1590 | nla_get_u32(tb[NL80211_ATTR_CENTER_FREQ2]); | |
1591 | ||
1592 | if (chan_info->center_frq2) { | |
1593 | u8 seg1_idx = 0; | |
1594 | ||
1595 | if (ieee80211_freq_to_chan(chan_info->center_frq2, &seg1_idx) != | |
1596 | NUM_HOSTAPD_MODES) | |
1597 | chan_info->seg1_idx = seg1_idx; | |
1598 | } | |
1599 | ||
1600 | return NL_SKIP; | |
1601 | } | |
1602 | ||
1603 | ||
1604 | static int nl80211_channel_info(void *priv, struct wpa_channel_info *ci) | |
1605 | { | |
1606 | struct i802_bss *bss = priv; | |
1607 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
1608 | struct nl_msg *msg; | |
1609 | ||
1610 | msg = nl80211_drv_msg(drv, 0, NL80211_CMD_GET_INTERFACE); | |
1611 | return send_and_recv_msgs(drv, msg, get_channel_info, ci); | |
1612 | } | |
1613 | ||
1614 | ||
97865538 | 1615 | static void wpa_driver_nl80211_event_receive(int sock, void *eloop_ctx, |
5582a5d1 | 1616 | void *handle) |
97865538 | 1617 | { |
a4ae123c | 1618 | struct nl_cb *cb = eloop_ctx; |
34068ac3 | 1619 | int res; |
97865538 | 1620 | |
cc2ada86 | 1621 | wpa_printf(MSG_MSGDUMP, "nl80211: Event message available"); |
97865538 | 1622 | |
34068ac3 | 1623 | res = nl_recvmsgs(handle, cb); |
d3d04831 | 1624 | if (res < 0) { |
34068ac3 JM |
1625 | wpa_printf(MSG_INFO, "nl80211: %s->nl_recvmsgs failed: %d", |
1626 | __func__, res); | |
1627 | } | |
97865538 JM |
1628 | } |
1629 | ||
1630 | ||
6d158490 LR |
1631 | /** |
1632 | * wpa_driver_nl80211_set_country - ask nl80211 to set the regulatory domain | |
1633 | * @priv: driver_nl80211 private data | |
1634 | * @alpha2_arg: country to which to switch to | |
1635 | * Returns: 0 on success, -1 on failure | |
1636 | * | |
1637 | * This asks nl80211 to set the regulatory domain for given | |
1638 | * country ISO / IEC alpha2. | |
1639 | */ | |
1640 | static int wpa_driver_nl80211_set_country(void *priv, const char *alpha2_arg) | |
1641 | { | |
a2e40bb6 FF |
1642 | struct i802_bss *bss = priv; |
1643 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
6d158490 LR |
1644 | char alpha2[3]; |
1645 | struct nl_msg *msg; | |
1646 | ||
1647 | msg = nlmsg_alloc(); | |
1648 | if (!msg) | |
e785c2ba | 1649 | return -ENOMEM; |
6d158490 LR |
1650 | |
1651 | alpha2[0] = alpha2_arg[0]; | |
1652 | alpha2[1] = alpha2_arg[1]; | |
1653 | alpha2[2] = '\0'; | |
1654 | ||
a862e4a3 JM |
1655 | if (!nl80211_cmd(drv, msg, 0, NL80211_CMD_REQ_SET_REG) || |
1656 | nla_put_string(msg, NL80211_ATTR_REG_ALPHA2, alpha2)) { | |
1657 | nlmsg_free(msg); | |
1658 | return -EINVAL; | |
1659 | } | |
6d158490 LR |
1660 | if (send_and_recv_msgs(drv, msg, NULL, NULL)) |
1661 | return -EINVAL; | |
1662 | return 0; | |
6d158490 LR |
1663 | } |
1664 | ||
1665 | ||
f0793bf1 JM |
1666 | static int nl80211_get_country(struct nl_msg *msg, void *arg) |
1667 | { | |
1668 | char *alpha2 = arg; | |
1669 | struct nlattr *tb_msg[NL80211_ATTR_MAX + 1]; | |
1670 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); | |
1671 | ||
1672 | nla_parse(tb_msg, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), | |
1673 | genlmsg_attrlen(gnlh, 0), NULL); | |
1674 | if (!tb_msg[NL80211_ATTR_REG_ALPHA2]) { | |
1675 | wpa_printf(MSG_DEBUG, "nl80211: No country information available"); | |
1676 | return NL_SKIP; | |
1677 | } | |
1678 | os_strlcpy(alpha2, nla_data(tb_msg[NL80211_ATTR_REG_ALPHA2]), 3); | |
1679 | return NL_SKIP; | |
1680 | } | |
1681 | ||
1682 | ||
1683 | static int wpa_driver_nl80211_get_country(void *priv, char *alpha2) | |
1684 | { | |
1685 | struct i802_bss *bss = priv; | |
1686 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
1687 | struct nl_msg *msg; | |
1688 | int ret; | |
1689 | ||
1690 | msg = nlmsg_alloc(); | |
1691 | if (!msg) | |
1692 | return -ENOMEM; | |
1693 | ||
1694 | nl80211_cmd(drv, msg, 0, NL80211_CMD_GET_REG); | |
1695 | alpha2[0] = '\0'; | |
1696 | ret = send_and_recv_msgs(drv, msg, nl80211_get_country, alpha2); | |
1697 | if (!alpha2[0]) | |
1698 | ret = -1; | |
1699 | ||
1700 | return ret; | |
1701 | } | |
1702 | ||
1703 | ||
2a7b66f5 BG |
1704 | static int wpa_driver_nl80211_init_nl_global(struct nl80211_global *global) |
1705 | { | |
d6c9aab8 JB |
1706 | int ret; |
1707 | ||
2a7b66f5 BG |
1708 | global->nl_cb = nl_cb_alloc(NL_CB_DEFAULT); |
1709 | if (global->nl_cb == NULL) { | |
1710 | wpa_printf(MSG_ERROR, "nl80211: Failed to allocate netlink " | |
1711 | "callbacks"); | |
1712 | return -1; | |
1713 | } | |
1714 | ||
481234cf JM |
1715 | global->nl = nl_create_handle(global->nl_cb, "nl"); |
1716 | if (global->nl == NULL) | |
d6c9aab8 | 1717 | goto err; |
276e2d67 | 1718 | |
481234cf | 1719 | global->nl80211_id = genl_ctrl_resolve(global->nl, "nl80211"); |
335d42b1 | 1720 | if (global->nl80211_id < 0) { |
276e2d67 BG |
1721 | wpa_printf(MSG_ERROR, "nl80211: 'nl80211' generic netlink not " |
1722 | "found"); | |
d6c9aab8 | 1723 | goto err; |
276e2d67 BG |
1724 | } |
1725 | ||
481234cf JM |
1726 | global->nl_event = nl_create_handle(global->nl_cb, "event"); |
1727 | if (global->nl_event == NULL) | |
d6c9aab8 | 1728 | goto err; |
9fff9fdc | 1729 | |
d6c9aab8 | 1730 | ret = nl_get_multicast_id(global, "nl80211", "scan"); |
97865538 | 1731 | if (ret >= 0) |
481234cf | 1732 | ret = nl_socket_add_membership(global->nl_event, ret); |
97865538 JM |
1733 | if (ret < 0) { |
1734 | wpa_printf(MSG_ERROR, "nl80211: Could not add multicast " | |
1735 | "membership for scan events: %d (%s)", | |
1736 | ret, strerror(-ret)); | |
d6c9aab8 | 1737 | goto err; |
97865538 | 1738 | } |
c2a04078 | 1739 | |
d6c9aab8 | 1740 | ret = nl_get_multicast_id(global, "nl80211", "mlme"); |
c2a04078 | 1741 | if (ret >= 0) |
481234cf | 1742 | ret = nl_socket_add_membership(global->nl_event, ret); |
c2a04078 JM |
1743 | if (ret < 0) { |
1744 | wpa_printf(MSG_ERROR, "nl80211: Could not add multicast " | |
1745 | "membership for mlme events: %d (%s)", | |
1746 | ret, strerror(-ret)); | |
d6c9aab8 | 1747 | goto err; |
c2a04078 | 1748 | } |
c2a04078 | 1749 | |
d6c9aab8 | 1750 | ret = nl_get_multicast_id(global, "nl80211", "regulatory"); |
33c5deb8 | 1751 | if (ret >= 0) |
481234cf | 1752 | ret = nl_socket_add_membership(global->nl_event, ret); |
33c5deb8 JM |
1753 | if (ret < 0) { |
1754 | wpa_printf(MSG_DEBUG, "nl80211: Could not add multicast " | |
1755 | "membership for regulatory events: %d (%s)", | |
1756 | ret, strerror(-ret)); | |
1757 | /* Continue without regulatory events */ | |
1758 | } | |
1759 | ||
17b79e65 JM |
1760 | ret = nl_get_multicast_id(global, "nl80211", "vendor"); |
1761 | if (ret >= 0) | |
1762 | ret = nl_socket_add_membership(global->nl_event, ret); | |
1763 | if (ret < 0) { | |
1764 | wpa_printf(MSG_DEBUG, "nl80211: Could not add multicast " | |
1765 | "membership for vendor events: %d (%s)", | |
1766 | ret, strerror(-ret)); | |
1767 | /* Continue without vendor events */ | |
1768 | } | |
1769 | ||
d6c9aab8 JB |
1770 | nl_cb_set(global->nl_cb, NL_CB_SEQ_CHECK, NL_CB_CUSTOM, |
1771 | no_seq_check, NULL); | |
1772 | nl_cb_set(global->nl_cb, NL_CB_VALID, NL_CB_CUSTOM, | |
1773 | process_global_event, global); | |
1774 | ||
5f65e9f7 JB |
1775 | nl80211_register_eloop_read(&global->nl_event, |
1776 | wpa_driver_nl80211_event_receive, | |
40a68f33 | 1777 | global->nl_cb, 0); |
d6c9aab8 JB |
1778 | |
1779 | return 0; | |
1780 | ||
1781 | err: | |
1782 | nl_destroy_handles(&global->nl_event); | |
1783 | nl_destroy_handles(&global->nl); | |
1784 | nl_cb_put(global->nl_cb); | |
671a5039 | 1785 | global->nl_cb = NULL; |
d6c9aab8 JB |
1786 | return -1; |
1787 | } | |
1788 | ||
1789 | ||
f51f54a0 JM |
1790 | static void nl80211_check_global(struct nl80211_global *global) |
1791 | { | |
1792 | struct nl_handle *handle; | |
1793 | const char *groups[] = { "scan", "mlme", "regulatory", "vendor", NULL }; | |
1794 | int ret; | |
1795 | unsigned int i; | |
1796 | ||
1797 | /* | |
1798 | * Try to re-add memberships to handle case of cfg80211 getting reloaded | |
1799 | * and all registration having been cleared. | |
1800 | */ | |
1801 | handle = (void *) (((intptr_t) global->nl_event) ^ | |
1802 | ELOOP_SOCKET_INVALID); | |
1803 | ||
1804 | for (i = 0; groups[i]; i++) { | |
1805 | ret = nl_get_multicast_id(global, "nl80211", groups[i]); | |
1806 | if (ret >= 0) | |
1807 | ret = nl_socket_add_membership(handle, ret); | |
1808 | if (ret < 0) { | |
1809 | wpa_printf(MSG_INFO, | |
1810 | "nl80211: Could not re-add multicast membership for %s events: %d (%s)", | |
1811 | groups[i], ret, strerror(-ret)); | |
1812 | } | |
1813 | } | |
1814 | } | |
1815 | ||
1816 | ||
8401a6b0 JM |
1817 | static void wpa_driver_nl80211_rfkill_blocked(void *ctx) |
1818 | { | |
6da504a1 IP |
1819 | struct wpa_driver_nl80211_data *drv = ctx; |
1820 | ||
8401a6b0 | 1821 | wpa_printf(MSG_DEBUG, "nl80211: RFKILL blocked"); |
6da504a1 | 1822 | |
a63063b4 | 1823 | /* |
6da504a1 IP |
1824 | * rtnetlink ifdown handler will report interfaces other than the P2P |
1825 | * Device interface as disabled. | |
a63063b4 | 1826 | */ |
6da504a1 IP |
1827 | if (drv->nlmode == NL80211_IFTYPE_P2P_DEVICE) |
1828 | wpa_supplicant_event(drv->ctx, EVENT_INTERFACE_DISABLED, NULL); | |
8401a6b0 JM |
1829 | } |
1830 | ||
1831 | ||
1832 | static void wpa_driver_nl80211_rfkill_unblocked(void *ctx) | |
1833 | { | |
1834 | struct wpa_driver_nl80211_data *drv = ctx; | |
1835 | wpa_printf(MSG_DEBUG, "nl80211: RFKILL unblocked"); | |
834ee56f | 1836 | if (i802_set_iface_flags(drv->first_bss, 1)) { |
8401a6b0 JM |
1837 | wpa_printf(MSG_DEBUG, "nl80211: Could not set interface UP " |
1838 | "after rfkill unblock"); | |
1839 | return; | |
1840 | } | |
e8dc205f AO |
1841 | |
1842 | if (is_p2p_net_interface(drv->nlmode)) | |
1843 | nl80211_disable_11b_rates(drv, drv->ifindex, 1); | |
1844 | ||
6da504a1 IP |
1845 | /* |
1846 | * rtnetlink ifup handler will report interfaces other than the P2P | |
1847 | * Device interface as enabled. | |
1848 | */ | |
1849 | if (drv->nlmode == NL80211_IFTYPE_P2P_DEVICE) | |
1850 | wpa_supplicant_event(drv->ctx, EVENT_INTERFACE_ENABLED, NULL); | |
8401a6b0 JM |
1851 | } |
1852 | ||
1853 | ||
32ab4855 JB |
1854 | static void wpa_driver_nl80211_handle_eapol_tx_status(int sock, |
1855 | void *eloop_ctx, | |
1856 | void *handle) | |
1857 | { | |
1858 | struct wpa_driver_nl80211_data *drv = eloop_ctx; | |
1859 | u8 data[2048]; | |
1860 | struct msghdr msg; | |
1861 | struct iovec entry; | |
cad0f50e | 1862 | u8 control[512]; |
32ab4855 JB |
1863 | struct cmsghdr *cmsg; |
1864 | int res, found_ee = 0, found_wifi = 0, acked = 0; | |
1865 | union wpa_event_data event; | |
1866 | ||
1867 | memset(&msg, 0, sizeof(msg)); | |
1868 | msg.msg_iov = &entry; | |
1869 | msg.msg_iovlen = 1; | |
1870 | entry.iov_base = data; | |
1871 | entry.iov_len = sizeof(data); | |
1872 | msg.msg_control = &control; | |
1873 | msg.msg_controllen = sizeof(control); | |
1874 | ||
1875 | res = recvmsg(sock, &msg, MSG_ERRQUEUE); | |
1876 | /* if error or not fitting 802.3 header, return */ | |
1877 | if (res < 14) | |
1878 | return; | |
1879 | ||
1880 | for (cmsg = CMSG_FIRSTHDR(&msg); cmsg; cmsg = CMSG_NXTHDR(&msg, cmsg)) | |
1881 | { | |
1882 | if (cmsg->cmsg_level == SOL_SOCKET && | |
1883 | cmsg->cmsg_type == SCM_WIFI_STATUS) { | |
1884 | int *ack; | |
1885 | ||
1886 | found_wifi = 1; | |
1887 | ack = (void *)CMSG_DATA(cmsg); | |
1888 | acked = *ack; | |
1889 | } | |
1890 | ||
1891 | if (cmsg->cmsg_level == SOL_PACKET && | |
1892 | cmsg->cmsg_type == PACKET_TX_TIMESTAMP) { | |
1893 | struct sock_extended_err *err = | |
1894 | (struct sock_extended_err *)CMSG_DATA(cmsg); | |
1895 | ||
1896 | if (err->ee_origin == SO_EE_ORIGIN_TXSTATUS) | |
1897 | found_ee = 1; | |
1898 | } | |
1899 | } | |
1900 | ||
1901 | if (!found_ee || !found_wifi) | |
1902 | return; | |
1903 | ||
1904 | memset(&event, 0, sizeof(event)); | |
1905 | event.eapol_tx_status.dst = data; | |
1906 | event.eapol_tx_status.data = data + 14; | |
1907 | event.eapol_tx_status.data_len = res - 14; | |
1908 | event.eapol_tx_status.ack = acked; | |
1909 | wpa_supplicant_event(drv->ctx, EVENT_EAPOL_TX_STATUS, &event); | |
1910 | } | |
1911 | ||
1912 | ||
cc7a48d1 JB |
1913 | static int nl80211_init_bss(struct i802_bss *bss) |
1914 | { | |
1915 | bss->nl_cb = nl_cb_alloc(NL_CB_DEFAULT); | |
1916 | if (!bss->nl_cb) | |
1917 | return -1; | |
1918 | ||
1919 | nl_cb_set(bss->nl_cb, NL_CB_SEQ_CHECK, NL_CB_CUSTOM, | |
1920 | no_seq_check, NULL); | |
1921 | nl_cb_set(bss->nl_cb, NL_CB_VALID, NL_CB_CUSTOM, | |
1922 | process_bss_event, bss); | |
1923 | ||
1924 | return 0; | |
1925 | } | |
1926 | ||
1927 | ||
1928 | static void nl80211_destroy_bss(struct i802_bss *bss) | |
1929 | { | |
1930 | nl_cb_put(bss->nl_cb); | |
1931 | bss->nl_cb = NULL; | |
1932 | } | |
1933 | ||
1934 | ||
0e92fb8f JB |
1935 | static void |
1936 | wpa_driver_nl80211_drv_init_rfkill(struct wpa_driver_nl80211_data *drv) | |
1937 | { | |
1938 | struct rfkill_config *rcfg; | |
1939 | ||
1940 | if (drv->rfkill) | |
1941 | return; | |
1942 | ||
1943 | rcfg = os_zalloc(sizeof(*rcfg)); | |
1944 | if (!rcfg) | |
1945 | return; | |
1946 | ||
1947 | rcfg->ctx = drv; | |
1948 | ||
1949 | /* rfkill uses netdev sysfs for initialization. However, P2P Device is | |
1950 | * not associated with a netdev, so use the name of some other interface | |
1951 | * sharing the same wiphy as the P2P Device interface. | |
1952 | * | |
1953 | * Note: This is valid, as a P2P Device interface is always dynamically | |
1954 | * created and is created only once another wpa_s interface was added. | |
1955 | */ | |
1956 | if (drv->nlmode == NL80211_IFTYPE_P2P_DEVICE) { | |
1957 | struct nl80211_global *global = drv->global; | |
1958 | struct wpa_driver_nl80211_data *tmp1; | |
1959 | ||
1960 | dl_list_for_each(tmp1, &global->interfaces, | |
1961 | struct wpa_driver_nl80211_data, list) { | |
1962 | if (drv == tmp1 || drv->wiphy_idx != tmp1->wiphy_idx || | |
1963 | !tmp1->rfkill) | |
1964 | continue; | |
1965 | ||
1966 | wpa_printf(MSG_DEBUG, | |
1967 | "nl80211: Use (%s) to initialize P2P Device rfkill", | |
1968 | tmp1->first_bss->ifname); | |
1969 | os_strlcpy(rcfg->ifname, tmp1->first_bss->ifname, | |
1970 | sizeof(rcfg->ifname)); | |
1971 | break; | |
1972 | } | |
1973 | } else { | |
1974 | os_strlcpy(rcfg->ifname, drv->first_bss->ifname, | |
1975 | sizeof(rcfg->ifname)); | |
1976 | } | |
1977 | ||
1978 | rcfg->blocked_cb = wpa_driver_nl80211_rfkill_blocked; | |
1979 | rcfg->unblocked_cb = wpa_driver_nl80211_rfkill_unblocked; | |
1980 | drv->rfkill = rfkill_init(rcfg); | |
1981 | if (!drv->rfkill) { | |
1982 | wpa_printf(MSG_DEBUG, "nl80211: RFKILL status not available"); | |
1983 | os_free(rcfg); | |
1984 | } | |
1985 | } | |
1986 | ||
1987 | ||
0d547d5f JM |
1988 | static void * wpa_driver_nl80211_drv_init(void *ctx, const char *ifname, |
1989 | void *global_priv, int hostapd, | |
0ecff8d7 JM |
1990 | const u8 *set_addr, |
1991 | const char *driver_params) | |
9fff9fdc | 1992 | { |
9fff9fdc | 1993 | struct wpa_driver_nl80211_data *drv; |
a2e40bb6 | 1994 | struct i802_bss *bss; |
9fff9fdc | 1995 | |
a5c696ad JM |
1996 | if (global_priv == NULL) |
1997 | return NULL; | |
9fff9fdc JM |
1998 | drv = os_zalloc(sizeof(*drv)); |
1999 | if (drv == NULL) | |
2000 | return NULL; | |
f2ed8023 | 2001 | drv->global = global_priv; |
9fff9fdc | 2002 | drv->ctx = ctx; |
0d547d5f JM |
2003 | drv->hostapd = !!hostapd; |
2004 | drv->eapol_sock = -1; | |
64ae2447 JM |
2005 | |
2006 | /* | |
2007 | * There is no driver capability flag for this, so assume it is | |
2008 | * supported and disable this on first attempt to use if the driver | |
2009 | * rejects the command due to missing support. | |
2010 | */ | |
2011 | drv->set_rekey_offload = 1; | |
2012 | ||
099224c1 | 2013 | drv->num_if_indices = ARRAY_SIZE(drv->default_if_indices); |
0d547d5f | 2014 | drv->if_indices = drv->default_if_indices; |
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 */ | |
f9da7505 MV |
2243 | #ifdef CONFIG_OCV |
2244 | /* SA Query Request */ | |
2245 | if (nl80211_register_action_frame(bss, (u8 *) "\x08\x00", 2) < 0) | |
2246 | ret = -1; | |
2247 | #endif /* CONFIG_OCV */ | |
7d878ca7 | 2248 | /* SA Query Response */ |
a11241fa | 2249 | if (nl80211_register_action_frame(bss, (u8 *) "\x08\x01", 2) < 0) |
6f06766e | 2250 | ret = -1; |
35287637 AN |
2251 | #ifdef CONFIG_TDLS |
2252 | if ((drv->capa.flags & WPA_DRIVER_FLAGS_TDLS_SUPPORT)) { | |
2253 | /* TDLS Discovery Response */ | |
aa543c0c | 2254 | if (nl80211_register_action_frame(bss, (u8 *) "\x04\x0e", 2) < |
35287637 | 2255 | 0) |
6f06766e | 2256 | ret = -1; |
35287637 AN |
2257 | } |
2258 | #endif /* CONFIG_TDLS */ | |
46ab9b8c AN |
2259 | #ifdef CONFIG_FST |
2260 | /* FST Action frames */ | |
2261 | if (nl80211_register_action_frame(bss, (u8 *) "\x12", 1) < 0) | |
2262 | ret = -1; | |
2263 | #endif /* CONFIG_FST */ | |
046b26a2 | 2264 | |
7b90c16a | 2265 | /* FT Action frames */ |
a11241fa | 2266 | if (nl80211_register_action_frame(bss, (u8 *) "\x06", 1) < 0) |
6f06766e | 2267 | ret = -1; |
7b90c16a JM |
2268 | else |
2269 | drv->capa.key_mgmt |= WPA_DRIVER_CAPA_KEY_MGMT_FT | | |
2270 | WPA_DRIVER_CAPA_KEY_MGMT_FT_PSK; | |
2271 | ||
71269b37 | 2272 | /* WNM - BSS Transition Management Request */ |
a11241fa | 2273 | if (nl80211_register_action_frame(bss, (u8 *) "\x0a\x07", 2) < 0) |
6f06766e | 2274 | ret = -1; |
bd896433 JM |
2275 | /* WNM-Sleep Mode Response */ |
2276 | if (nl80211_register_action_frame(bss, (u8 *) "\x0a\x11", 2) < 0) | |
6f06766e | 2277 | ret = -1; |
d514b502 JM |
2278 | #ifdef CONFIG_WNM |
2279 | /* WNM - Collocated Interference Request */ | |
2280 | if (nl80211_register_action_frame(bss, (u8 *) "\x0a\x0b", 2) < 0) | |
2281 | ret = -1; | |
2282 | #endif /* CONFIG_WNM */ | |
a11241fa | 2283 | |
95a3ea94 JM |
2284 | #ifdef CONFIG_HS20 |
2285 | /* WNM-Notification */ | |
2286 | if (nl80211_register_action_frame(bss, (u8 *) "\x0a\x1a", 2) < 0) | |
3ee18569 | 2287 | ret = -1; |
95a3ea94 JM |
2288 | #endif /* CONFIG_HS20 */ |
2289 | ||
dfa87878 MB |
2290 | /* WMM-AC ADDTS Response */ |
2291 | if (nl80211_register_action_frame(bss, (u8 *) "\x11\x01", 2) < 0) | |
730a0d16 | 2292 | ret = -1; |
dfa87878 MB |
2293 | |
2294 | /* WMM-AC DELTS */ | |
2295 | if (nl80211_register_action_frame(bss, (u8 *) "\x11\x02", 2) < 0) | |
730a0d16 | 2296 | ret = -1; |
dfa87878 | 2297 | |
2526ccd9 AK |
2298 | /* Radio Measurement - Neighbor Report Response */ |
2299 | if (nl80211_register_action_frame(bss, (u8 *) "\x05\x05", 2) < 0) | |
2300 | ret = -1; | |
2301 | ||
864b9522 DS |
2302 | /* Radio Measurement - Radio Measurement Request */ |
2303 | if (nl80211_register_action_frame(bss, (u8 *) "\x05\x00", 2) < 0) | |
2304 | ret = -1; | |
2305 | ||
7dc03388 AO |
2306 | /* Radio Measurement - Link Measurement Request */ |
2307 | if ((drv->capa.rrm_flags & WPA_DRIVER_FLAGS_TX_POWER_INSERTION) && | |
2308 | (nl80211_register_action_frame(bss, (u8 *) "\x05\x02", 2) < 0)) | |
2309 | ret = -1; | |
2310 | ||
5f65e9f7 JB |
2311 | nl80211_mgmt_handle_register_eloop(bss); |
2312 | ||
6f06766e | 2313 | return ret; |
a11241fa JB |
2314 | } |
2315 | ||
2316 | ||
afb0550a BC |
2317 | static int nl80211_mgmt_subscribe_mesh(struct i802_bss *bss) |
2318 | { | |
2319 | int ret = 0; | |
2320 | ||
2321 | if (nl80211_alloc_mgmt_handle(bss)) | |
2322 | return -1; | |
2323 | ||
2324 | wpa_printf(MSG_DEBUG, | |
2325 | "nl80211: Subscribe to mgmt frames with mesh handle %p", | |
2326 | bss->nl_mgmt); | |
2327 | ||
2328 | /* Auth frames for mesh SAE */ | |
2329 | if (nl80211_register_frame(bss, bss->nl_mgmt, | |
2330 | (WLAN_FC_TYPE_MGMT << 2) | | |
2331 | (WLAN_FC_STYPE_AUTH << 4), | |
2332 | NULL, 0) < 0) | |
2333 | ret = -1; | |
2334 | ||
2335 | /* Mesh peering open */ | |
2336 | if (nl80211_register_action_frame(bss, (u8 *) "\x0f\x01", 2) < 0) | |
2337 | ret = -1; | |
2338 | /* Mesh peering confirm */ | |
2339 | if (nl80211_register_action_frame(bss, (u8 *) "\x0f\x02", 2) < 0) | |
2340 | ret = -1; | |
2341 | /* Mesh peering close */ | |
2342 | if (nl80211_register_action_frame(bss, (u8 *) "\x0f\x03", 2) < 0) | |
2343 | ret = -1; | |
2344 | ||
2345 | nl80211_mgmt_handle_register_eloop(bss); | |
2346 | ||
2347 | return ret; | |
2348 | } | |
2349 | ||
2350 | ||
02bb32c3 JB |
2351 | static int nl80211_register_spurious_class3(struct i802_bss *bss) |
2352 | { | |
02bb32c3 | 2353 | struct nl_msg *msg; |
a862e4a3 | 2354 | int ret; |
02bb32c3 | 2355 | |
13f83980 JM |
2356 | msg = nl80211_bss_msg(bss, 0, NL80211_CMD_UNEXPECTED_FRAME); |
2357 | ret = send_and_recv(bss->drv->global, bss->nl_mgmt, msg, NULL, NULL); | |
02bb32c3 JB |
2358 | if (ret) { |
2359 | wpa_printf(MSG_DEBUG, "nl80211: Register spurious class3 " | |
2360 | "failed: ret=%d (%s)", | |
2361 | ret, strerror(-ret)); | |
02bb32c3 | 2362 | } |
02bb32c3 JB |
2363 | return ret; |
2364 | } | |
2365 | ||
2366 | ||
4d916ed6 KV |
2367 | static int nl80211_action_subscribe_ap(struct i802_bss *bss) |
2368 | { | |
2369 | int ret = 0; | |
2370 | ||
2371 | /* Public Action frames */ | |
2372 | if (nl80211_register_action_frame(bss, (u8 *) "\x04", 1) < 0) | |
2373 | ret = -1; | |
2374 | /* RRM Measurement Report */ | |
2375 | if (nl80211_register_action_frame(bss, (u8 *) "\x05\x01", 2) < 0) | |
2376 | ret = -1; | |
e4ec6bbf JM |
2377 | /* RRM Link Measurement Report */ |
2378 | if (nl80211_register_action_frame(bss, (u8 *) "\x05\x03", 2) < 0) | |
2379 | ret = -1; | |
4d916ed6 KV |
2380 | /* RRM Neighbor Report Request */ |
2381 | if (nl80211_register_action_frame(bss, (u8 *) "\x05\x04", 2) < 0) | |
2382 | ret = -1; | |
2383 | /* FT Action frames */ | |
2384 | if (nl80211_register_action_frame(bss, (u8 *) "\x06", 1) < 0) | |
2385 | ret = -1; | |
4d916ed6 KV |
2386 | /* SA Query */ |
2387 | if (nl80211_register_action_frame(bss, (u8 *) "\x08", 1) < 0) | |
2388 | ret = -1; | |
4d916ed6 KV |
2389 | /* Protected Dual of Public Action */ |
2390 | if (nl80211_register_action_frame(bss, (u8 *) "\x09", 1) < 0) | |
2391 | ret = -1; | |
2392 | /* WNM */ | |
2393 | if (nl80211_register_action_frame(bss, (u8 *) "\x0a", 1) < 0) | |
2394 | ret = -1; | |
2395 | /* WMM */ | |
2396 | if (nl80211_register_action_frame(bss, (u8 *) "\x11", 1) < 0) | |
2397 | ret = -1; | |
2398 | #ifdef CONFIG_FST | |
2399 | /* FST Action frames */ | |
2400 | if (nl80211_register_action_frame(bss, (u8 *) "\x12", 1) < 0) | |
2401 | ret = -1; | |
2402 | #endif /* CONFIG_FST */ | |
2403 | /* Vendor-specific */ | |
2404 | if (nl80211_register_action_frame(bss, (u8 *) "\x7f", 1) < 0) | |
2405 | ret = -1; | |
2406 | ||
2407 | return ret; | |
2408 | } | |
2409 | ||
2410 | ||
a11241fa JB |
2411 | static int nl80211_mgmt_subscribe_ap(struct i802_bss *bss) |
2412 | { | |
2413 | static const int stypes[] = { | |
2414 | WLAN_FC_STYPE_AUTH, | |
2415 | WLAN_FC_STYPE_ASSOC_REQ, | |
2416 | WLAN_FC_STYPE_REASSOC_REQ, | |
2417 | WLAN_FC_STYPE_DISASSOC, | |
2418 | WLAN_FC_STYPE_DEAUTH, | |
a11241fa JB |
2419 | WLAN_FC_STYPE_PROBE_REQ, |
2420 | /* Beacon doesn't work as mac80211 doesn't currently allow | |
2421 | * it, but it wouldn't really be the right thing anyway as | |
2422 | * it isn't per interface ... maybe just dump the scan | |
2423 | * results periodically for OLBC? | |
2424 | */ | |
0e80ea2c | 2425 | /* WLAN_FC_STYPE_BEACON, */ |
a11241fa JB |
2426 | }; |
2427 | unsigned int i; | |
2428 | ||
2429 | if (nl80211_alloc_mgmt_handle(bss)) | |
71269b37 | 2430 | return -1; |
36488c05 JM |
2431 | wpa_printf(MSG_DEBUG, "nl80211: Subscribe to mgmt frames with AP " |
2432 | "handle %p", bss->nl_mgmt); | |
71269b37 | 2433 | |
e7ecab4a | 2434 | for (i = 0; i < ARRAY_SIZE(stypes); i++) { |
481234cf | 2435 | if (nl80211_register_frame(bss, bss->nl_mgmt, |
a11241fa JB |
2436 | (WLAN_FC_TYPE_MGMT << 2) | |
2437 | (stypes[i] << 4), | |
2438 | NULL, 0) < 0) { | |
2439 | goto out_err; | |
2440 | } | |
2441 | } | |
2442 | ||
4d916ed6 KV |
2443 | if (nl80211_action_subscribe_ap(bss)) |
2444 | goto out_err; | |
2445 | ||
02bb32c3 JB |
2446 | if (nl80211_register_spurious_class3(bss)) |
2447 | goto out_err; | |
2448 | ||
5f65e9f7 | 2449 | nl80211_mgmt_handle_register_eloop(bss); |
58f6fbe0 | 2450 | return 0; |
a11241fa JB |
2451 | |
2452 | out_err: | |
a11241fa JB |
2453 | nl_destroy_handles(&bss->nl_mgmt); |
2454 | return -1; | |
2455 | } | |
2456 | ||
2457 | ||
a6cc0602 JM |
2458 | static int nl80211_mgmt_subscribe_ap_dev_sme(struct i802_bss *bss) |
2459 | { | |
2460 | if (nl80211_alloc_mgmt_handle(bss)) | |
2461 | return -1; | |
2462 | wpa_printf(MSG_DEBUG, "nl80211: Subscribe to mgmt frames with AP " | |
2463 | "handle %p (device SME)", bss->nl_mgmt); | |
2464 | ||
4d916ed6 | 2465 | if (nl80211_action_subscribe_ap(bss)) |
a6cc0602 JM |
2466 | goto out_err; |
2467 | ||
236e793e SD |
2468 | if (bss->drv->device_ap_sme) { |
2469 | u16 type = (WLAN_FC_TYPE_MGMT << 2) | (WLAN_FC_STYPE_AUTH << 4); | |
2470 | ||
2471 | /* Register for all Authentication frames */ | |
2472 | if (nl80211_register_frame(bss, bss->nl_mgmt, type, NULL, 0) | |
2473 | < 0) | |
2474 | wpa_printf(MSG_DEBUG, | |
2475 | "nl80211: Failed to subscribe to handle Authentication frames - SAE offload may not work"); | |
2476 | } | |
2477 | ||
5f65e9f7 | 2478 | nl80211_mgmt_handle_register_eloop(bss); |
a6cc0602 JM |
2479 | return 0; |
2480 | ||
2481 | out_err: | |
a6cc0602 JM |
2482 | nl_destroy_handles(&bss->nl_mgmt); |
2483 | return -1; | |
2484 | } | |
2485 | ||
2486 | ||
36488c05 | 2487 | static void nl80211_mgmt_unsubscribe(struct i802_bss *bss, const char *reason) |
a11241fa | 2488 | { |
481234cf | 2489 | if (bss->nl_mgmt == NULL) |
a11241fa | 2490 | return; |
36488c05 JM |
2491 | wpa_printf(MSG_DEBUG, "nl80211: Unsubscribe mgmt frames handle %p " |
2492 | "(%s)", bss->nl_mgmt, reason); | |
40a68f33 | 2493 | nl80211_destroy_eloop_handle(&bss->nl_mgmt, 0); |
7813b7c3 MH |
2494 | |
2495 | nl80211_put_wiphy_data_ap(bss); | |
58f6fbe0 JM |
2496 | } |
2497 | ||
2498 | ||
8401a6b0 JM |
2499 | static void wpa_driver_nl80211_send_rfkill(void *eloop_ctx, void *timeout_ctx) |
2500 | { | |
2501 | wpa_supplicant_event(timeout_ctx, EVENT_INTERFACE_DISABLED, NULL); | |
2502 | } | |
2503 | ||
2504 | ||
eb4582f2 AS |
2505 | static void nl80211_del_p2pdev(struct i802_bss *bss) |
2506 | { | |
eb4582f2 AS |
2507 | struct nl_msg *msg; |
2508 | int ret; | |
2509 | ||
a3249fdf JM |
2510 | msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_DEL_INTERFACE); |
2511 | ret = send_and_recv_msgs(bss->drv, msg, NULL, NULL); | |
eb4582f2 AS |
2512 | |
2513 | wpa_printf(MSG_DEBUG, "nl80211: Delete P2P Device %s (0x%llx): %s", | |
2514 | bss->ifname, (long long unsigned int) bss->wdev_id, | |
6cb4f11d | 2515 | strerror(-ret)); |
eb4582f2 AS |
2516 | } |
2517 | ||
2518 | ||
eb4582f2 | 2519 | static int nl80211_set_p2pdev(struct i802_bss *bss, int start) |
f632e483 | 2520 | { |
f632e483 | 2521 | struct nl_msg *msg; |
a862e4a3 | 2522 | int ret; |
f632e483 | 2523 | |
a3249fdf JM |
2524 | msg = nl80211_cmd_msg(bss, 0, start ? NL80211_CMD_START_P2P_DEVICE : |
2525 | NL80211_CMD_STOP_P2P_DEVICE); | |
2526 | ret = send_and_recv_msgs(bss->drv, msg, NULL, NULL); | |
f632e483 | 2527 | |
eb4582f2 AS |
2528 | wpa_printf(MSG_DEBUG, "nl80211: %s P2P Device %s (0x%llx): %s", |
2529 | start ? "Start" : "Stop", | |
2530 | bss->ifname, (long long unsigned int) bss->wdev_id, | |
6cb4f11d | 2531 | strerror(-ret)); |
f632e483 AS |
2532 | return ret; |
2533 | } | |
f632e483 AS |
2534 | |
2535 | ||
91724d6f AS |
2536 | static int i802_set_iface_flags(struct i802_bss *bss, int up) |
2537 | { | |
2538 | enum nl80211_iftype nlmode; | |
2539 | ||
2540 | nlmode = nl80211_get_ifmode(bss); | |
2541 | if (nlmode != NL80211_IFTYPE_P2P_DEVICE) { | |
2542 | return linux_set_iface_flags(bss->drv->global->ioctl_sock, | |
2543 | bss->ifname, up); | |
2544 | } | |
2545 | ||
2546 | /* P2P Device has start/stop which is equivalent */ | |
2547 | return nl80211_set_p2pdev(bss, up); | |
2548 | } | |
2549 | ||
2550 | ||
1db718b3 JM |
2551 | #ifdef CONFIG_TESTING_OPTIONS |
2552 | static int qca_vendor_test_cmd_handler(struct nl_msg *msg, void *arg) | |
2553 | { | |
2554 | /* struct wpa_driver_nl80211_data *drv = arg; */ | |
2555 | struct nlattr *tb[NL80211_ATTR_MAX + 1]; | |
2556 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); | |
2557 | ||
2558 | ||
2559 | wpa_printf(MSG_DEBUG, | |
2560 | "nl80211: QCA vendor test command response received"); | |
2561 | ||
2562 | nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), | |
2563 | genlmsg_attrlen(gnlh, 0), NULL); | |
2564 | if (!tb[NL80211_ATTR_VENDOR_DATA]) { | |
2565 | wpa_printf(MSG_DEBUG, "nl80211: No vendor data attribute"); | |
2566 | return NL_SKIP; | |
2567 | } | |
2568 | ||
2569 | wpa_hexdump(MSG_DEBUG, | |
2570 | "nl80211: Received QCA vendor test command response", | |
2571 | nla_data(tb[NL80211_ATTR_VENDOR_DATA]), | |
2572 | nla_len(tb[NL80211_ATTR_VENDOR_DATA])); | |
2573 | ||
2574 | return NL_SKIP; | |
2575 | } | |
2576 | #endif /* CONFIG_TESTING_OPTIONS */ | |
2577 | ||
2578 | ||
2579 | static void qca_vendor_test(struct wpa_driver_nl80211_data *drv) | |
2580 | { | |
2581 | #ifdef CONFIG_TESTING_OPTIONS | |
2582 | struct nl_msg *msg; | |
2583 | struct nlattr *params; | |
2584 | int ret; | |
2585 | ||
2586 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_VENDOR)) || | |
2587 | nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) || | |
2588 | nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD, | |
2589 | QCA_NL80211_VENDOR_SUBCMD_TEST) || | |
2590 | !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) || | |
2591 | nla_put_u32(msg, QCA_WLAN_VENDOR_ATTR_TEST, 123)) { | |
2592 | nlmsg_free(msg); | |
2593 | return; | |
2594 | } | |
2595 | nla_nest_end(msg, params); | |
2596 | ||
2597 | ret = send_and_recv_msgs(drv, msg, qca_vendor_test_cmd_handler, drv); | |
2598 | wpa_printf(MSG_DEBUG, | |
2599 | "nl80211: QCA vendor test command returned %d (%s)", | |
2600 | ret, strerror(-ret)); | |
2601 | #endif /* CONFIG_TESTING_OPTIONS */ | |
2602 | } | |
2603 | ||
2604 | ||
362f781e | 2605 | static int |
0d547d5f | 2606 | wpa_driver_nl80211_finish_drv_init(struct wpa_driver_nl80211_data *drv, |
0ecff8d7 JM |
2607 | const u8 *set_addr, int first, |
2608 | const char *driver_params) | |
7524cfb1 | 2609 | { |
834ee56f | 2610 | struct i802_bss *bss = drv->first_bss; |
8401a6b0 | 2611 | int send_rfkill_event = 0; |
0d547d5f | 2612 | enum nl80211_iftype nlmode; |
a2e40bb6 FF |
2613 | |
2614 | drv->ifindex = if_nametoindex(bss->ifname); | |
f632e483 AS |
2615 | bss->ifindex = drv->ifindex; |
2616 | bss->wdev_id = drv->global->if_add_wdevid; | |
2617 | bss->wdev_id_set = drv->global->if_add_wdevid_set; | |
2618 | ||
60b13c20 IP |
2619 | bss->if_dynamic = drv->ifindex == drv->global->if_add_ifindex; |
2620 | bss->if_dynamic = bss->if_dynamic || drv->global->if_add_wdevid_set; | |
f632e483 AS |
2621 | drv->global->if_add_wdevid_set = 0; |
2622 | ||
bf144cf6 AP |
2623 | if (!bss->if_dynamic && nl80211_get_ifmode(bss) == NL80211_IFTYPE_AP) |
2624 | bss->static_ap = 1; | |
2625 | ||
ef3866ab IP |
2626 | if (first && |
2627 | nl80211_get_ifmode(bss) != NL80211_IFTYPE_P2P_DEVICE && | |
2628 | linux_iface_up(drv->global->ioctl_sock, bss->ifname) > 0) | |
2629 | drv->start_iface_up = 1; | |
2630 | ||
f632e483 AS |
2631 | if (wpa_driver_nl80211_capa(drv)) |
2632 | return -1; | |
a87c9d96 | 2633 | |
0ecff8d7 JM |
2634 | if (driver_params && nl80211_set_param(bss, driver_params) < 0) |
2635 | return -1; | |
2636 | ||
5fbcb45d AS |
2637 | wpa_printf(MSG_DEBUG, "nl80211: interface %s in phy %s", |
2638 | bss->ifname, drv->phyname); | |
2639 | ||
0d547d5f JM |
2640 | if (set_addr && |
2641 | (linux_set_iface_flags(drv->global->ioctl_sock, bss->ifname, 0) || | |
2642 | linux_set_ifhwaddr(drv->global->ioctl_sock, bss->ifname, | |
2643 | set_addr))) | |
2644 | return -1; | |
2645 | ||
49b4b205 JM |
2646 | if (first && nl80211_get_ifmode(bss) == NL80211_IFTYPE_AP) |
2647 | drv->start_mode_ap = 1; | |
2648 | ||
bf144cf6 | 2649 | if (drv->hostapd || bss->static_ap) |
0d547d5f | 2650 | nlmode = NL80211_IFTYPE_AP; |
4fe726e2 FF |
2651 | else if (bss->if_dynamic || |
2652 | nl80211_get_ifmode(bss) == NL80211_IFTYPE_MESH_POINT) | |
8e12685c | 2653 | nlmode = nl80211_get_ifmode(bss); |
0d547d5f JM |
2654 | else |
2655 | nlmode = NL80211_IFTYPE_STATION; | |
f632e483 | 2656 | |
8e12685c | 2657 | if (wpa_driver_nl80211_set_mode(bss, nlmode) < 0) { |
0d547d5f | 2658 | wpa_printf(MSG_ERROR, "nl80211: Could not configure driver mode"); |
8e12685c | 2659 | return -1; |
a87c9d96 JM |
2660 | } |
2661 | ||
8c06db70 | 2662 | if (nlmode == NL80211_IFTYPE_P2P_DEVICE) |
597b94f5 | 2663 | nl80211_get_macaddr(bss); |
f632e483 | 2664 | |
0e92fb8f JB |
2665 | wpa_driver_nl80211_drv_init_rfkill(drv); |
2666 | ||
8c06db70 MB |
2667 | if (!rfkill_is_blocked(drv->rfkill)) { |
2668 | int ret = i802_set_iface_flags(bss, 1); | |
2669 | if (ret) { | |
8401a6b0 JM |
2670 | wpa_printf(MSG_ERROR, "nl80211: Could not set " |
2671 | "interface '%s' UP", bss->ifname); | |
8c06db70 | 2672 | return ret; |
8401a6b0 | 2673 | } |
e8dc205f AO |
2674 | |
2675 | if (is_p2p_net_interface(nlmode)) | |
2676 | nl80211_disable_11b_rates(bss->drv, | |
2677 | bss->drv->ifindex, 1); | |
2678 | ||
8c06db70 MB |
2679 | if (nlmode == NL80211_IFTYPE_P2P_DEVICE) |
2680 | return ret; | |
2681 | } else { | |
2682 | wpa_printf(MSG_DEBUG, "nl80211: Could not yet enable " | |
2683 | "interface '%s' due to rfkill", bss->ifname); | |
6da504a1 IP |
2684 | if (nlmode != NL80211_IFTYPE_P2P_DEVICE) |
2685 | drv->if_disabled = 1; | |
2686 | ||
8c06db70 | 2687 | send_rfkill_event = 1; |
362f781e | 2688 | } |
3f5285e8 | 2689 | |
6da504a1 | 2690 | if (!drv->hostapd && nlmode != NL80211_IFTYPE_P2P_DEVICE) |
0d547d5f JM |
2691 | netlink_send_oper_ifla(drv->global->netlink, drv->ifindex, |
2692 | 1, IF_OPER_DORMANT); | |
362f781e | 2693 | |
6da504a1 IP |
2694 | if (nlmode != NL80211_IFTYPE_P2P_DEVICE) { |
2695 | if (linux_get_ifhwaddr(drv->global->ioctl_sock, bss->ifname, | |
2696 | bss->addr)) | |
2697 | return -1; | |
2698 | os_memcpy(drv->perm_addr, bss->addr, ETH_ALEN); | |
2699 | } | |
f2ed8023 | 2700 | |
8401a6b0 JM |
2701 | if (send_rfkill_event) { |
2702 | eloop_register_timeout(0, 0, wpa_driver_nl80211_send_rfkill, | |
2703 | drv, drv->ctx); | |
2704 | } | |
2705 | ||
1db718b3 JM |
2706 | if (drv->vendor_cmd_test_avail) |
2707 | qca_vendor_test(drv); | |
2708 | ||
40a68f33 SD |
2709 | nl80211_init_connect_handle(bss); |
2710 | ||
362f781e | 2711 | return 0; |
3f5285e8 JM |
2712 | } |
2713 | ||
2714 | ||
a70cd0db | 2715 | static int wpa_driver_nl80211_del_beacon(struct i802_bss *bss) |
8a27af5c JM |
2716 | { |
2717 | struct nl_msg *msg; | |
a70cd0db | 2718 | struct wpa_driver_nl80211_data *drv = bss->drv; |
8a27af5c | 2719 | |
08e55ebb JM |
2720 | wpa_printf(MSG_DEBUG, "nl80211: Remove beacon (ifindex=%d)", |
2721 | drv->ifindex); | |
a70cd0db | 2722 | nl80211_put_wiphy_data_ap(bss); |
9725b784 | 2723 | msg = nl80211_drv_msg(drv, 0, NL80211_CMD_DEL_BEACON); |
8a27af5c | 2724 | return send_and_recv_msgs(drv, msg, NULL, NULL); |
8a27af5c | 2725 | } |
8a27af5c JM |
2726 | |
2727 | ||
3f5285e8 | 2728 | /** |
7e5ba1b9 | 2729 | * wpa_driver_nl80211_deinit - Deinitialize nl80211 driver interface |
9ebce9c5 | 2730 | * @bss: Pointer to private nl80211 data from wpa_driver_nl80211_init() |
3f5285e8 JM |
2731 | * |
2732 | * Shut down driver interface and processing of driver events. Free | |
2733 | * private data buffer if one was allocated in wpa_driver_nl80211_init(). | |
2734 | */ | |
9ebce9c5 | 2735 | static void wpa_driver_nl80211_deinit(struct i802_bss *bss) |
3f5285e8 | 2736 | { |
a2e40bb6 | 2737 | struct wpa_driver_nl80211_data *drv = bss->drv; |
cc9a2575 | 2738 | unsigned int i; |
3f5285e8 | 2739 | |
3e208481 JM |
2740 | wpa_printf(MSG_INFO, "nl80211: deinit ifname=%s disabled_11b_rates=%d", |
2741 | bss->ifname, drv->disabled_11b_rates); | |
2742 | ||
873d0fcf | 2743 | bss->in_deinit = 1; |
32ab4855 JB |
2744 | if (drv->data_tx_status) |
2745 | eloop_unregister_read_sock(drv->eapol_tx_sock); | |
d12dab4c JB |
2746 | if (drv->eapol_tx_sock >= 0) |
2747 | close(drv->eapol_tx_sock); | |
f10bfc9a | 2748 | |
481234cf | 2749 | if (bss->nl_preq) |
5582a5d1 | 2750 | wpa_driver_nl80211_probe_req_report(bss, 0); |
e17a2477 | 2751 | if (bss->added_if_into_bridge) { |
c81eff1a BG |
2752 | if (linux_br_del_if(drv->global->ioctl_sock, bss->brname, |
2753 | bss->ifname) < 0) | |
94627f6c JM |
2754 | wpa_printf(MSG_INFO, "nl80211: Failed to remove " |
2755 | "interface %s from bridge %s: %s", | |
e17a2477 | 2756 | bss->ifname, bss->brname, strerror(errno)); |
94627f6c | 2757 | } |
c809756f SM |
2758 | |
2759 | if (drv->rtnl_sk) | |
2760 | nl80211_handle_destroy(drv->rtnl_sk); | |
2761 | ||
e17a2477 | 2762 | if (bss->added_bridge) { |
f2535da8 JM |
2763 | if (linux_set_iface_flags(drv->global->ioctl_sock, bss->brname, |
2764 | 0) < 0) | |
2765 | wpa_printf(MSG_INFO, | |
2766 | "nl80211: Could not set bridge %s down", | |
2767 | bss->brname); | |
c81eff1a | 2768 | if (linux_br_del(drv->global->ioctl_sock, bss->brname) < 0) |
94627f6c JM |
2769 | wpa_printf(MSG_INFO, "nl80211: Failed to remove " |
2770 | "bridge %s: %s", | |
e17a2477 | 2771 | bss->brname, strerror(errno)); |
94627f6c JM |
2772 | } |
2773 | ||
460456f8 | 2774 | nl80211_remove_monitor_interface(drv); |
8a27af5c | 2775 | |
b1f625e0 | 2776 | if (is_ap_interface(drv->nlmode)) |
a70cd0db | 2777 | wpa_driver_nl80211_del_beacon(bss); |
0915d02c | 2778 | |
bbaf0837 JM |
2779 | if (drv->eapol_sock >= 0) { |
2780 | eloop_unregister_read_sock(drv->eapol_sock); | |
2781 | close(drv->eapol_sock); | |
2782 | } | |
2783 | ||
2784 | if (drv->if_indices != drv->default_if_indices) | |
2785 | os_free(drv->if_indices); | |
3f5285e8 | 2786 | |
b3af99d2 | 2787 | if (drv->disabled_11b_rates) |
4e5cb1a3 JM |
2788 | nl80211_disable_11b_rates(drv, drv->ifindex, 0); |
2789 | ||
36d84860 BG |
2790 | netlink_send_oper_ifla(drv->global->netlink, drv->ifindex, 0, |
2791 | IF_OPER_UP); | |
e390df05 | 2792 | eloop_cancel_timeout(wpa_driver_nl80211_send_rfkill, drv, drv->ctx); |
8401a6b0 | 2793 | rfkill_deinit(drv->rfkill); |
3f5285e8 | 2794 | |
bbaf0837 JM |
2795 | eloop_cancel_timeout(wpa_driver_nl80211_scan_timeout, drv, drv->ctx); |
2796 | ||
146fa9b3 JM |
2797 | if (!drv->start_iface_up) |
2798 | (void) i802_set_iface_flags(bss, 0); | |
fee354c7 JM |
2799 | |
2800 | if (drv->addr_changed) { | |
93da0498 JM |
2801 | if (linux_set_iface_flags(drv->global->ioctl_sock, bss->ifname, |
2802 | 0) < 0) { | |
2803 | wpa_printf(MSG_DEBUG, | |
2804 | "nl80211: Could not set interface down to restore permanent MAC address"); | |
2805 | } | |
fee354c7 JM |
2806 | if (linux_set_ifhwaddr(drv->global->ioctl_sock, bss->ifname, |
2807 | drv->perm_addr) < 0) { | |
2808 | wpa_printf(MSG_DEBUG, | |
2809 | "nl80211: Could not restore permanent MAC address"); | |
2810 | } | |
2811 | } | |
2812 | ||
8e12685c | 2813 | if (drv->nlmode != NL80211_IFTYPE_P2P_DEVICE) { |
49b4b205 JM |
2814 | if (!drv->hostapd || !drv->start_mode_ap) |
2815 | wpa_driver_nl80211_set_mode(bss, | |
2816 | NL80211_IFTYPE_STATION); | |
b378c41f | 2817 | nl80211_mgmt_unsubscribe(bss, "deinit"); |
8e12685c AS |
2818 | } else { |
2819 | nl80211_mgmt_unsubscribe(bss, "deinit"); | |
eb4582f2 | 2820 | nl80211_del_p2pdev(bss); |
8e12685c | 2821 | } |
3f5285e8 | 2822 | |
40a68f33 SD |
2823 | if (bss->nl_connect) |
2824 | nl80211_destroy_eloop_handle(&bss->nl_connect, 1); | |
2825 | ||
834ee56f | 2826 | nl80211_destroy_bss(drv->first_bss); |
cc7a48d1 | 2827 | |
3812464c JM |
2828 | os_free(drv->filter_ssids); |
2829 | ||
536fd62d JM |
2830 | os_free(drv->auth_ie); |
2831 | ||
dac12351 | 2832 | if (drv->in_interface_list) |
f2ed8023 JM |
2833 | dl_list_del(&drv->list); |
2834 | ||
8cd6b7bc JB |
2835 | os_free(drv->extended_capa); |
2836 | os_free(drv->extended_capa_mask); | |
cc9a2575 KV |
2837 | for (i = 0; i < drv->num_iface_ext_capa; i++) { |
2838 | os_free(drv->iface_ext_capa[i].ext_capa); | |
2839 | os_free(drv->iface_ext_capa[i].ext_capa_mask); | |
2840 | } | |
834ee56f | 2841 | os_free(drv->first_bss); |
3f5285e8 JM |
2842 | os_free(drv); |
2843 | } | |
2844 | ||
2845 | ||
de4ed4a8 JM |
2846 | static u32 wpa_alg_to_cipher_suite(enum wpa_alg alg, size_t key_len) |
2847 | { | |
2848 | switch (alg) { | |
2849 | case WPA_ALG_WEP: | |
2850 | if (key_len == 5) | |
a042e39a JM |
2851 | return RSN_CIPHER_SUITE_WEP40; |
2852 | return RSN_CIPHER_SUITE_WEP104; | |
de4ed4a8 | 2853 | case WPA_ALG_TKIP: |
a042e39a | 2854 | return RSN_CIPHER_SUITE_TKIP; |
de4ed4a8 | 2855 | case WPA_ALG_CCMP: |
a042e39a | 2856 | return RSN_CIPHER_SUITE_CCMP; |
de4ed4a8 | 2857 | case WPA_ALG_GCMP: |
a042e39a | 2858 | return RSN_CIPHER_SUITE_GCMP; |
de4ed4a8 | 2859 | case WPA_ALG_CCMP_256: |
a042e39a | 2860 | return RSN_CIPHER_SUITE_CCMP_256; |
de4ed4a8 | 2861 | case WPA_ALG_GCMP_256: |
a042e39a | 2862 | return RSN_CIPHER_SUITE_GCMP_256; |
de4ed4a8 | 2863 | case WPA_ALG_IGTK: |
a042e39a | 2864 | return RSN_CIPHER_SUITE_AES_128_CMAC; |
de4ed4a8 | 2865 | case WPA_ALG_BIP_GMAC_128: |
a042e39a | 2866 | return RSN_CIPHER_SUITE_BIP_GMAC_128; |
de4ed4a8 | 2867 | case WPA_ALG_BIP_GMAC_256: |
a042e39a | 2868 | return RSN_CIPHER_SUITE_BIP_GMAC_256; |
de4ed4a8 | 2869 | case WPA_ALG_BIP_CMAC_256: |
a042e39a | 2870 | return RSN_CIPHER_SUITE_BIP_CMAC_256; |
de4ed4a8 | 2871 | case WPA_ALG_SMS4: |
a042e39a | 2872 | return RSN_CIPHER_SUITE_SMS4; |
de4ed4a8 | 2873 | case WPA_ALG_KRK: |
a042e39a | 2874 | return RSN_CIPHER_SUITE_KRK; |
de4ed4a8 JM |
2875 | case WPA_ALG_NONE: |
2876 | case WPA_ALG_PMK: | |
2877 | wpa_printf(MSG_ERROR, "nl80211: Unexpected encryption algorithm %d", | |
2878 | alg); | |
2879 | return 0; | |
2880 | } | |
2881 | ||
2882 | wpa_printf(MSG_ERROR, "nl80211: Unsupported encryption algorithm %d", | |
2883 | alg); | |
2884 | return 0; | |
2885 | } | |
2886 | ||
2887 | ||
2888 | static u32 wpa_cipher_to_cipher_suite(unsigned int cipher) | |
2889 | { | |
2890 | switch (cipher) { | |
2891 | case WPA_CIPHER_CCMP_256: | |
a042e39a | 2892 | return RSN_CIPHER_SUITE_CCMP_256; |
de4ed4a8 | 2893 | case WPA_CIPHER_GCMP_256: |
a042e39a | 2894 | return RSN_CIPHER_SUITE_GCMP_256; |
de4ed4a8 | 2895 | case WPA_CIPHER_CCMP: |
a042e39a | 2896 | return RSN_CIPHER_SUITE_CCMP; |
de4ed4a8 | 2897 | case WPA_CIPHER_GCMP: |
a042e39a | 2898 | return RSN_CIPHER_SUITE_GCMP; |
de4ed4a8 | 2899 | case WPA_CIPHER_TKIP: |
a042e39a | 2900 | return RSN_CIPHER_SUITE_TKIP; |
de4ed4a8 | 2901 | case WPA_CIPHER_WEP104: |
a042e39a | 2902 | return RSN_CIPHER_SUITE_WEP104; |
de4ed4a8 | 2903 | case WPA_CIPHER_WEP40: |
a042e39a | 2904 | return RSN_CIPHER_SUITE_WEP40; |
ae6f9272 | 2905 | case WPA_CIPHER_GTK_NOT_USED: |
a042e39a | 2906 | return RSN_CIPHER_SUITE_NO_GROUP_ADDRESSED; |
de4ed4a8 JM |
2907 | } |
2908 | ||
2909 | return 0; | |
2910 | } | |
2911 | ||
2912 | ||
2913 | static int wpa_cipher_to_cipher_suites(unsigned int ciphers, u32 suites[], | |
2914 | int max_suites) | |
2915 | { | |
2916 | int num_suites = 0; | |
2917 | ||
2918 | if (num_suites < max_suites && ciphers & WPA_CIPHER_CCMP_256) | |
a042e39a | 2919 | suites[num_suites++] = RSN_CIPHER_SUITE_CCMP_256; |
de4ed4a8 | 2920 | if (num_suites < max_suites && ciphers & WPA_CIPHER_GCMP_256) |
a042e39a | 2921 | suites[num_suites++] = RSN_CIPHER_SUITE_GCMP_256; |
de4ed4a8 | 2922 | if (num_suites < max_suites && ciphers & WPA_CIPHER_CCMP) |
a042e39a | 2923 | suites[num_suites++] = RSN_CIPHER_SUITE_CCMP; |
de4ed4a8 | 2924 | if (num_suites < max_suites && ciphers & WPA_CIPHER_GCMP) |
a042e39a | 2925 | suites[num_suites++] = RSN_CIPHER_SUITE_GCMP; |
de4ed4a8 | 2926 | if (num_suites < max_suites && ciphers & WPA_CIPHER_TKIP) |
a042e39a | 2927 | suites[num_suites++] = RSN_CIPHER_SUITE_TKIP; |
de4ed4a8 | 2928 | if (num_suites < max_suites && ciphers & WPA_CIPHER_WEP104) |
a042e39a | 2929 | suites[num_suites++] = RSN_CIPHER_SUITE_WEP104; |
de4ed4a8 | 2930 | if (num_suites < max_suites && ciphers & WPA_CIPHER_WEP40) |
a042e39a | 2931 | suites[num_suites++] = RSN_CIPHER_SUITE_WEP40; |
de4ed4a8 JM |
2932 | |
2933 | return num_suites; | |
2934 | } | |
2935 | ||
2936 | ||
b658547d | 2937 | #ifdef CONFIG_DRIVER_NL80211_QCA |
b41f2684 CL |
2938 | static int issue_key_mgmt_set_key(struct wpa_driver_nl80211_data *drv, |
2939 | const u8 *key, size_t key_len) | |
2940 | { | |
2941 | struct nl_msg *msg; | |
a862e4a3 | 2942 | int ret; |
b41f2684 | 2943 | |
15badebd | 2944 | if (!(drv->capa.flags & WPA_DRIVER_FLAGS_KEY_MGMT_OFFLOAD)) |
b41f2684 CL |
2945 | return 0; |
2946 | ||
9725b784 | 2947 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_VENDOR)) || |
a862e4a3 JM |
2948 | nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) || |
2949 | nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD, | |
2950 | QCA_NL80211_VENDOR_SUBCMD_KEY_MGMT_SET_KEY) || | |
2951 | nla_put(msg, NL80211_ATTR_VENDOR_DATA, key_len, key)) { | |
bbd89bfc | 2952 | nl80211_nlmsg_clear(msg); |
a862e4a3 JM |
2953 | nlmsg_free(msg); |
2954 | return -1; | |
2955 | } | |
bbd89bfc | 2956 | ret = send_and_recv_msgs(drv, msg, NULL, (void *) -1); |
b41f2684 CL |
2957 | if (ret) { |
2958 | wpa_printf(MSG_DEBUG, | |
2959 | "nl80211: Key management set key failed: ret=%d (%s)", | |
2960 | ret, strerror(-ret)); | |
2961 | } | |
2962 | ||
b41f2684 CL |
2963 | return ret; |
2964 | } | |
b658547d | 2965 | #endif /* CONFIG_DRIVER_NL80211_QCA */ |
b41f2684 CL |
2966 | |
2967 | ||
05fc7c68 AS |
2968 | static int nl80211_set_pmk(struct wpa_driver_nl80211_data *drv, |
2969 | const u8 *key, size_t key_len, | |
2970 | const u8 *addr) | |
2971 | { | |
2972 | struct nl_msg *msg = NULL; | |
2973 | int ret; | |
2974 | ||
2975 | /* | |
2976 | * If the authenticator address is not set, assume it is | |
2977 | * the current BSSID. | |
2978 | */ | |
2979 | if (!addr && drv->associated) | |
2980 | addr = drv->bssid; | |
2981 | else if (!addr) | |
2982 | return -1; | |
2983 | ||
2984 | wpa_printf(MSG_DEBUG, "nl80211: Set PMK to the driver for " MACSTR, | |
2985 | MAC2STR(addr)); | |
2986 | wpa_hexdump_key(MSG_DEBUG, "nl80211: PMK", key, key_len); | |
2987 | msg = nl80211_drv_msg(drv, 0, NL80211_CMD_SET_PMK); | |
2988 | if (!msg || | |
2989 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) || | |
2990 | nla_put(msg, NL80211_ATTR_PMK, key_len, key)) { | |
2991 | nl80211_nlmsg_clear(msg); | |
2992 | nlmsg_free(msg); | |
2993 | return -ENOBUFS; | |
2994 | } | |
2995 | ||
2996 | ret = send_and_recv_msgs(drv, msg, NULL, (void *) -1); | |
2997 | if (ret) { | |
2998 | wpa_printf(MSG_DEBUG, "nl80211: Set PMK failed: ret=%d (%s)", | |
2999 | ret, strerror(-ret)); | |
3000 | } | |
3001 | ||
3002 | return ret; | |
3003 | } | |
3004 | ||
3005 | ||
9ebce9c5 | 3006 | static int wpa_driver_nl80211_set_key(const char *ifname, struct i802_bss *bss, |
71934751 JM |
3007 | enum wpa_alg alg, const u8 *addr, |
3008 | int key_idx, int set_tx, | |
642187d6 JM |
3009 | const u8 *seq, size_t seq_len, |
3010 | const u8 *key, size_t key_len) | |
3f5285e8 | 3011 | { |
a2e40bb6 | 3012 | struct wpa_driver_nl80211_data *drv = bss->drv; |
e472e1b4 | 3013 | int ifindex; |
83b83b46 AW |
3014 | struct nl_msg *msg; |
3015 | struct nl_msg *key_msg; | |
1ad1cdc2 | 3016 | int ret; |
dc01de8a | 3017 | int tdls = 0; |
3f5285e8 | 3018 | |
e472e1b4 AS |
3019 | /* Ignore for P2P Device */ |
3020 | if (drv->nlmode == NL80211_IFTYPE_P2P_DEVICE) | |
3021 | return 0; | |
3022 | ||
3023 | ifindex = if_nametoindex(ifname); | |
8393e1a0 | 3024 | wpa_printf(MSG_DEBUG, "%s: ifindex=%d (%s) alg=%d addr=%p key_idx=%d " |
1ad1cdc2 | 3025 | "set_tx=%d seq_len=%lu key_len=%lu", |
8393e1a0 | 3026 | __func__, ifindex, ifname, alg, addr, key_idx, set_tx, |
3f5285e8 | 3027 | (unsigned long) seq_len, (unsigned long) key_len); |
8c66e185 | 3028 | #ifdef CONFIG_TDLS |
dc01de8a | 3029 | if (key_idx == -1) { |
8c66e185 | 3030 | key_idx = 0; |
dc01de8a JM |
3031 | tdls = 1; |
3032 | } | |
8c66e185 | 3033 | #endif /* CONFIG_TDLS */ |
3f5285e8 | 3034 | |
b658547d | 3035 | #ifdef CONFIG_DRIVER_NL80211_QCA |
15badebd CL |
3036 | if (alg == WPA_ALG_PMK && |
3037 | (drv->capa.flags & WPA_DRIVER_FLAGS_KEY_MGMT_OFFLOAD)) { | |
b41f2684 CL |
3038 | wpa_printf(MSG_DEBUG, "%s: calling issue_key_mgmt_set_key", |
3039 | __func__); | |
3040 | ret = issue_key_mgmt_set_key(drv, key, key_len); | |
3041 | return ret; | |
3042 | } | |
b658547d | 3043 | #endif /* CONFIG_DRIVER_NL80211_QCA */ |
b41f2684 | 3044 | |
05fc7c68 | 3045 | if (alg == WPA_ALG_PMK && |
436ee2fd | 3046 | (drv->capa.flags & WPA_DRIVER_FLAGS_4WAY_HANDSHAKE_8021X)) |
05fc7c68 AS |
3047 | return nl80211_set_pmk(drv, key, key_len, addr); |
3048 | ||
83b83b46 AW |
3049 | key_msg = nlmsg_alloc(); |
3050 | if (!key_msg) | |
3051 | return -ENOBUFS; | |
3052 | ||
3f5285e8 | 3053 | if (alg == WPA_ALG_NONE) { |
95376e1a JM |
3054 | msg = nl80211_ifindex_msg(drv, ifindex, 0, NL80211_CMD_DEL_KEY); |
3055 | if (!msg) | |
83b83b46 | 3056 | goto fail2; |
3f5285e8 | 3057 | } else { |
34651767 JM |
3058 | u32 suite; |
3059 | ||
3060 | suite = wpa_alg_to_cipher_suite(alg, key_len); | |
3061 | if (!suite) | |
83b83b46 | 3062 | goto fail2; |
95376e1a | 3063 | msg = nl80211_ifindex_msg(drv, ifindex, 0, NL80211_CMD_NEW_KEY); |
83b83b46 AW |
3064 | if (!msg) |
3065 | goto fail2; | |
3066 | if (nla_put(key_msg, NL80211_KEY_DATA, key_len, key) || | |
3067 | nla_put_u32(key_msg, NL80211_KEY_CIPHER, suite)) | |
a862e4a3 | 3068 | goto fail; |
e6ef73f1 | 3069 | wpa_hexdump_key(MSG_DEBUG, "nl80211: KEY_DATA", key, key_len); |
3f5285e8 JM |
3070 | } |
3071 | ||
e6ef73f1 | 3072 | if (seq && seq_len) { |
83b83b46 | 3073 | if (nla_put(key_msg, NL80211_KEY_SEQ, seq_len, seq)) |
a862e4a3 | 3074 | goto fail; |
e6ef73f1 JM |
3075 | wpa_hexdump(MSG_DEBUG, "nl80211: KEY_SEQ", seq, seq_len); |
3076 | } | |
1ad1cdc2 | 3077 | |
0382097e | 3078 | if (addr && !is_broadcast_ether_addr(addr)) { |
3f5285e8 | 3079 | wpa_printf(MSG_DEBUG, " addr=" MACSTR, MAC2STR(addr)); |
a862e4a3 JM |
3080 | if (nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) |
3081 | goto fail; | |
89c38e32 JM |
3082 | |
3083 | if (alg != WPA_ALG_WEP && key_idx && !set_tx) { | |
3084 | wpa_printf(MSG_DEBUG, " RSN IBSS RX GTK"); | |
83b83b46 | 3085 | if (nla_put_u32(key_msg, NL80211_KEY_TYPE, |
a862e4a3 JM |
3086 | NL80211_KEYTYPE_GROUP)) |
3087 | goto fail; | |
89c38e32 | 3088 | } |
60ea8187 | 3089 | } else if (addr && is_broadcast_ether_addr(addr)) { |
8970bae8 JB |
3090 | struct nlattr *types; |
3091 | ||
60ea8187 | 3092 | wpa_printf(MSG_DEBUG, " broadcast key"); |
8970bae8 | 3093 | |
83b83b46 | 3094 | types = nla_nest_start(key_msg, NL80211_KEY_DEFAULT_TYPES); |
a862e4a3 | 3095 | if (!types || |
83b83b46 | 3096 | nla_put_flag(key_msg, NL80211_KEY_DEFAULT_TYPE_MULTICAST)) |
a862e4a3 | 3097 | goto fail; |
83b83b46 | 3098 | nla_nest_end(key_msg, types); |
3f5285e8 | 3099 | } |
83b83b46 AW |
3100 | if (nla_put_u8(key_msg, NL80211_KEY_IDX, key_idx) || |
3101 | nla_put_nested(msg, NL80211_ATTR_KEY, key_msg)) | |
a862e4a3 | 3102 | goto fail; |
83b83b46 AW |
3103 | nl80211_nlmsg_clear(key_msg); |
3104 | nlmsg_free(key_msg); | |
3105 | key_msg = NULL; | |
3f5285e8 | 3106 | |
bbd89bfc | 3107 | ret = send_and_recv_msgs(drv, msg, NULL, key ? (void *) -1 : NULL); |
15664ad0 | 3108 | if ((ret == -ENOENT || ret == -ENOLINK) && alg == WPA_ALG_NONE) |
1ad1cdc2 JM |
3109 | ret = 0; |
3110 | if (ret) | |
3111 | wpa_printf(MSG_DEBUG, "nl80211: set_key failed; err=%d %s)", | |
3112 | ret, strerror(-ret)); | |
3f5285e8 | 3113 | |
1ad1cdc2 JM |
3114 | /* |
3115 | * If we failed or don't need to set the default TX key (below), | |
3116 | * we're done here. | |
3117 | */ | |
dc01de8a | 3118 | if (ret || !set_tx || alg == WPA_ALG_NONE || tdls) |
1ad1cdc2 | 3119 | return ret; |
b1f625e0 | 3120 | if (is_ap_interface(drv->nlmode) && addr && |
0382097e | 3121 | !is_broadcast_ether_addr(addr)) |
de12717a | 3122 | return ret; |
3f5285e8 | 3123 | |
83b83b46 AW |
3124 | key_msg = nlmsg_alloc(); |
3125 | if (!key_msg) | |
3126 | return -ENOBUFS; | |
3127 | ||
95376e1a | 3128 | msg = nl80211_ifindex_msg(drv, ifindex, 0, NL80211_CMD_SET_KEY); |
83b83b46 AW |
3129 | if (!msg) |
3130 | goto fail2; | |
3131 | if (!key_msg || | |
3132 | nla_put_u8(key_msg, NL80211_KEY_IDX, key_idx) || | |
3133 | nla_put_flag(key_msg, (alg == WPA_ALG_IGTK || | |
3134 | alg == WPA_ALG_BIP_GMAC_128 || | |
3135 | alg == WPA_ALG_BIP_GMAC_256 || | |
3136 | alg == WPA_ALG_BIP_CMAC_256) ? | |
3137 | NL80211_KEY_DEFAULT_MGMT : | |
3138 | NL80211_KEY_DEFAULT)) | |
a862e4a3 | 3139 | goto fail; |
60ea8187 | 3140 | if (addr && is_broadcast_ether_addr(addr)) { |
8970bae8 JB |
3141 | struct nlattr *types; |
3142 | ||
83b83b46 | 3143 | types = nla_nest_start(key_msg, NL80211_KEY_DEFAULT_TYPES); |
a862e4a3 | 3144 | if (!types || |
83b83b46 | 3145 | nla_put_flag(key_msg, NL80211_KEY_DEFAULT_TYPE_MULTICAST)) |
a862e4a3 | 3146 | goto fail; |
83b83b46 | 3147 | nla_nest_end(key_msg, types); |
60ea8187 | 3148 | } else if (addr) { |
8970bae8 JB |
3149 | struct nlattr *types; |
3150 | ||
83b83b46 | 3151 | types = nla_nest_start(key_msg, NL80211_KEY_DEFAULT_TYPES); |
a862e4a3 | 3152 | if (!types || |
83b83b46 | 3153 | nla_put_flag(key_msg, NL80211_KEY_DEFAULT_TYPE_UNICAST)) |
a862e4a3 | 3154 | goto fail; |
83b83b46 | 3155 | nla_nest_end(key_msg, types); |
60ea8187 | 3156 | } |
3f5285e8 | 3157 | |
83b83b46 AW |
3158 | if (nla_put_nested(msg, NL80211_ATTR_KEY, key_msg)) |
3159 | goto fail; | |
3160 | nl80211_nlmsg_clear(key_msg); | |
3161 | nlmsg_free(key_msg); | |
3162 | key_msg = NULL; | |
3163 | ||
1ad1cdc2 JM |
3164 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
3165 | if (ret == -ENOENT) | |
3166 | ret = 0; | |
3167 | if (ret) | |
3168 | wpa_printf(MSG_DEBUG, "nl80211: set_key default failed; " | |
3169 | "err=%d %s)", ret, strerror(-ret)); | |
3170 | return ret; | |
3f5285e8 | 3171 | |
a862e4a3 | 3172 | fail: |
bbd89bfc | 3173 | nl80211_nlmsg_clear(msg); |
5883168a | 3174 | nlmsg_free(msg); |
83b83b46 AW |
3175 | fail2: |
3176 | nl80211_nlmsg_clear(key_msg); | |
3177 | nlmsg_free(key_msg); | |
6241fcb1 | 3178 | return -ENOBUFS; |
3f5285e8 JM |
3179 | } |
3180 | ||
3181 | ||
71934751 | 3182 | static int nl_add_key(struct nl_msg *msg, enum wpa_alg alg, |
0194fedb JB |
3183 | int key_idx, int defkey, |
3184 | const u8 *seq, size_t seq_len, | |
3185 | const u8 *key, size_t key_len) | |
3186 | { | |
3187 | struct nlattr *key_attr = nla_nest_start(msg, NL80211_ATTR_KEY); | |
34651767 JM |
3188 | u32 suite; |
3189 | ||
0194fedb JB |
3190 | if (!key_attr) |
3191 | return -1; | |
3192 | ||
34651767 JM |
3193 | suite = wpa_alg_to_cipher_suite(alg, key_len); |
3194 | if (!suite) | |
3195 | return -1; | |
3196 | ||
a862e4a3 JM |
3197 | if (defkey && alg == WPA_ALG_IGTK) { |
3198 | if (nla_put_flag(msg, NL80211_KEY_DEFAULT_MGMT)) | |
3199 | return -1; | |
3200 | } else if (defkey) { | |
3201 | if (nla_put_flag(msg, NL80211_KEY_DEFAULT)) | |
3202 | return -1; | |
3203 | } | |
0194fedb | 3204 | |
a862e4a3 | 3205 | if (nla_put_u8(msg, NL80211_KEY_IDX, key_idx) || |
34651767 | 3206 | nla_put_u32(msg, NL80211_KEY_CIPHER, suite) || |
a862e4a3 JM |
3207 | (seq && seq_len && |
3208 | nla_put(msg, NL80211_KEY_SEQ, seq_len, seq)) || | |
3209 | nla_put(msg, NL80211_KEY_DATA, key_len, key)) | |
3210 | return -1; | |
0194fedb JB |
3211 | |
3212 | nla_nest_end(msg, key_attr); | |
3213 | ||
3214 | return 0; | |
0194fedb JB |
3215 | } |
3216 | ||
c811d5bc | 3217 | |
cfaab580 ZY |
3218 | static int nl80211_set_conn_keys(struct wpa_driver_associate_params *params, |
3219 | struct nl_msg *msg) | |
3220 | { | |
3221 | int i, privacy = 0; | |
3222 | struct nlattr *nl_keys, *nl_key; | |
3223 | ||
3224 | for (i = 0; i < 4; i++) { | |
3225 | if (!params->wep_key[i]) | |
3226 | continue; | |
3227 | privacy = 1; | |
3228 | break; | |
3229 | } | |
ce04af5a JM |
3230 | if (params->wps == WPS_MODE_PRIVACY) |
3231 | privacy = 1; | |
3232 | if (params->pairwise_suite && | |
3233 | params->pairwise_suite != WPA_CIPHER_NONE) | |
3234 | privacy = 1; | |
3235 | ||
cfaab580 ZY |
3236 | if (!privacy) |
3237 | return 0; | |
3238 | ||
a862e4a3 JM |
3239 | if (nla_put_flag(msg, NL80211_ATTR_PRIVACY)) |
3240 | return -ENOBUFS; | |
cfaab580 ZY |
3241 | |
3242 | nl_keys = nla_nest_start(msg, NL80211_ATTR_KEYS); | |
3243 | if (!nl_keys) | |
a862e4a3 | 3244 | return -ENOBUFS; |
cfaab580 ZY |
3245 | |
3246 | for (i = 0; i < 4; i++) { | |
3247 | if (!params->wep_key[i]) | |
3248 | continue; | |
3249 | ||
3250 | nl_key = nla_nest_start(msg, i); | |
a862e4a3 JM |
3251 | if (!nl_key || |
3252 | nla_put(msg, NL80211_KEY_DATA, params->wep_key_len[i], | |
3253 | params->wep_key[i]) || | |
3254 | nla_put_u32(msg, NL80211_KEY_CIPHER, | |
3255 | params->wep_key_len[i] == 5 ? | |
a042e39a JM |
3256 | RSN_CIPHER_SUITE_WEP40 : |
3257 | RSN_CIPHER_SUITE_WEP104) || | |
a862e4a3 JM |
3258 | nla_put_u8(msg, NL80211_KEY_IDX, i) || |
3259 | (i == params->wep_tx_keyidx && | |
3260 | nla_put_flag(msg, NL80211_KEY_DEFAULT))) | |
3261 | return -ENOBUFS; | |
cfaab580 ZY |
3262 | |
3263 | nla_nest_end(msg, nl_key); | |
3264 | } | |
3265 | nla_nest_end(msg, nl_keys); | |
3266 | ||
3267 | return 0; | |
cfaab580 ZY |
3268 | } |
3269 | ||
3270 | ||
477af8f8 JM |
3271 | int wpa_driver_nl80211_mlme(struct wpa_driver_nl80211_data *drv, |
3272 | const u8 *addr, int cmd, u16 reason_code, | |
10d32e2c CI |
3273 | int local_state_change, |
3274 | struct nl_handle *nl_connect) | |
c2a04078 | 3275 | { |
a862e4a3 | 3276 | int ret; |
c2a04078 JM |
3277 | struct nl_msg *msg; |
3278 | ||
9725b784 | 3279 | if (!(msg = nl80211_drv_msg(drv, 0, cmd)) || |
a862e4a3 JM |
3280 | nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason_code) || |
3281 | (addr && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) || | |
3282 | (local_state_change && | |
3283 | nla_put_flag(msg, NL80211_ATTR_LOCAL_STATE_CHANGE))) { | |
3284 | nlmsg_free(msg); | |
3285 | return -1; | |
3286 | } | |
c2a04078 | 3287 | |
10d32e2c CI |
3288 | if (nl_connect) |
3289 | ret = send_and_recv(drv->global, nl_connect, msg, NULL, NULL); | |
3290 | else | |
3291 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); | |
c2a04078 | 3292 | if (ret) { |
3b7ea880 BG |
3293 | wpa_dbg(drv->ctx, MSG_DEBUG, |
3294 | "nl80211: MLME command failed: reason=%u ret=%d (%s)", | |
3295 | reason_code, ret, strerror(-ret)); | |
c2a04078 | 3296 | } |
c2a04078 JM |
3297 | return ret; |
3298 | } | |
3f5285e8 JM |
3299 | |
3300 | ||
cfaab580 | 3301 | static int wpa_driver_nl80211_disconnect(struct wpa_driver_nl80211_data *drv, |
4be17ffb | 3302 | u16 reason_code, |
10d32e2c | 3303 | struct nl_handle *nl_connect) |
cfaab580 | 3304 | { |
3f53c006 | 3305 | int ret; |
b898b655 | 3306 | int drv_associated = drv->associated; |
3f53c006 | 3307 | |
817762d9 | 3308 | wpa_printf(MSG_DEBUG, "%s(reason_code=%d)", __func__, reason_code); |
add9b7a4 | 3309 | nl80211_mark_disconnected(drv); |
817762d9 | 3310 | /* Disconnect command doesn't need BSSID - it uses cached value */ |
3f53c006 | 3311 | ret = wpa_driver_nl80211_mlme(drv, NULL, NL80211_CMD_DISCONNECT, |
10d32e2c | 3312 | reason_code, 0, nl_connect); |
3f53c006 JJ |
3313 | /* |
3314 | * For locally generated disconnect, supplicant already generates a | |
3315 | * DEAUTH event, so ignore the event from NL80211. | |
3316 | */ | |
b898b655 | 3317 | drv->ignore_next_local_disconnect = drv_associated && (ret == 0); |
3f53c006 JJ |
3318 | |
3319 | return ret; | |
cfaab580 ZY |
3320 | } |
3321 | ||
3322 | ||
9ebce9c5 | 3323 | static int wpa_driver_nl80211_deauthenticate(struct i802_bss *bss, |
4be17ffb | 3324 | const u8 *addr, u16 reason_code) |
3f5285e8 | 3325 | { |
a2e40bb6 | 3326 | struct wpa_driver_nl80211_data *drv = bss->drv; |
d6a36f39 | 3327 | int ret; |
b898b655 | 3328 | int drv_associated = drv->associated; |
9392c9be AS |
3329 | |
3330 | if (drv->nlmode == NL80211_IFTYPE_ADHOC) { | |
3331 | nl80211_mark_disconnected(drv); | |
666e508c | 3332 | return nl80211_leave_ibss(drv, 1); |
9392c9be | 3333 | } |
10d32e2c CI |
3334 | if (!(drv->capa.flags & WPA_DRIVER_FLAGS_SME)) { |
3335 | struct nl_handle *nl_connect = NULL; | |
3336 | ||
3337 | if (bss->use_nl_connect) | |
3338 | nl_connect = bss->nl_connect; | |
3339 | return wpa_driver_nl80211_disconnect(drv, reason_code, | |
3340 | nl_connect); | |
3341 | } | |
2e75a2b3 JM |
3342 | wpa_printf(MSG_DEBUG, "%s(addr=" MACSTR " reason_code=%d)", |
3343 | __func__, MAC2STR(addr), reason_code); | |
add9b7a4 | 3344 | nl80211_mark_disconnected(drv); |
d6a36f39 | 3345 | ret = wpa_driver_nl80211_mlme(drv, addr, NL80211_CMD_DEAUTHENTICATE, |
10d32e2c | 3346 | reason_code, 0, NULL); |
d6a36f39 JM |
3347 | /* |
3348 | * For locally generated deauthenticate, supplicant already generates a | |
3349 | * DEAUTH event, so ignore the event from NL80211. | |
3350 | */ | |
b898b655 HW |
3351 | drv->ignore_next_local_deauth = drv_associated && (ret == 0); |
3352 | ||
d6a36f39 | 3353 | return ret; |
3f5285e8 JM |
3354 | } |
3355 | ||
3356 | ||
536fd62d JM |
3357 | static void nl80211_copy_auth_params(struct wpa_driver_nl80211_data *drv, |
3358 | struct wpa_driver_auth_params *params) | |
3359 | { | |
3360 | int i; | |
3361 | ||
3362 | drv->auth_freq = params->freq; | |
3363 | drv->auth_alg = params->auth_alg; | |
3364 | drv->auth_wep_tx_keyidx = params->wep_tx_keyidx; | |
3365 | drv->auth_local_state_change = params->local_state_change; | |
3366 | drv->auth_p2p = params->p2p; | |
3367 | ||
3368 | if (params->bssid) | |
3369 | os_memcpy(drv->auth_bssid_, params->bssid, ETH_ALEN); | |
3370 | else | |
3371 | os_memset(drv->auth_bssid_, 0, ETH_ALEN); | |
3372 | ||
3373 | if (params->ssid) { | |
3374 | os_memcpy(drv->auth_ssid, params->ssid, params->ssid_len); | |
3375 | drv->auth_ssid_len = params->ssid_len; | |
3376 | } else | |
3377 | drv->auth_ssid_len = 0; | |
3378 | ||
3379 | ||
3380 | os_free(drv->auth_ie); | |
3381 | drv->auth_ie = NULL; | |
3382 | drv->auth_ie_len = 0; | |
3383 | if (params->ie) { | |
3384 | drv->auth_ie = os_malloc(params->ie_len); | |
3385 | if (drv->auth_ie) { | |
3386 | os_memcpy(drv->auth_ie, params->ie, params->ie_len); | |
3387 | drv->auth_ie_len = params->ie_len; | |
3388 | } | |
3389 | } | |
3390 | ||
3391 | for (i = 0; i < 4; i++) { | |
3392 | if (params->wep_key[i] && params->wep_key_len[i] && | |
3393 | params->wep_key_len[i] <= 16) { | |
3394 | os_memcpy(drv->auth_wep_key[i], params->wep_key[i], | |
3395 | params->wep_key_len[i]); | |
3396 | drv->auth_wep_key_len[i] = params->wep_key_len[i]; | |
3397 | } else | |
3398 | drv->auth_wep_key_len[i] = 0; | |
3399 | } | |
3400 | } | |
3401 | ||
3402 | ||
4bd71954 JM |
3403 | static void nl80211_unmask_11b_rates(struct i802_bss *bss) |
3404 | { | |
3405 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
3406 | ||
3407 | if (is_p2p_net_interface(drv->nlmode) || !drv->disabled_11b_rates) | |
3408 | return; | |
3409 | ||
3410 | /* | |
3411 | * Looks like we failed to unmask 11b rates previously. This could | |
3412 | * happen, e.g., if the interface was down at the point in time when a | |
3413 | * P2P group was terminated. | |
3414 | */ | |
3415 | wpa_printf(MSG_DEBUG, | |
3416 | "nl80211: Interface %s mode is for non-P2P, but 11b rates were disabled - re-enable them", | |
3417 | bss->ifname); | |
3418 | nl80211_disable_11b_rates(drv, drv->ifindex, 0); | |
3419 | } | |
3420 | ||
3421 | ||
3c67e977 VK |
3422 | static enum nl80211_auth_type get_nl_auth_type(int wpa_auth_alg) |
3423 | { | |
3424 | if (wpa_auth_alg & WPA_AUTH_ALG_OPEN) | |
3425 | return NL80211_AUTHTYPE_OPEN_SYSTEM; | |
3426 | if (wpa_auth_alg & WPA_AUTH_ALG_SHARED) | |
3427 | return NL80211_AUTHTYPE_SHARED_KEY; | |
3428 | if (wpa_auth_alg & WPA_AUTH_ALG_LEAP) | |
3429 | return NL80211_AUTHTYPE_NETWORK_EAP; | |
3430 | if (wpa_auth_alg & WPA_AUTH_ALG_FT) | |
3431 | return NL80211_AUTHTYPE_FT; | |
3432 | if (wpa_auth_alg & WPA_AUTH_ALG_SAE) | |
3433 | return NL80211_AUTHTYPE_SAE; | |
3434 | if (wpa_auth_alg & WPA_AUTH_ALG_FILS) | |
3435 | return NL80211_AUTHTYPE_FILS_SK; | |
3436 | if (wpa_auth_alg & WPA_AUTH_ALG_FILS_SK_PFS) | |
3437 | return NL80211_AUTHTYPE_FILS_SK_PFS; | |
3438 | ||
3439 | return NL80211_AUTHTYPE_MAX; | |
3440 | } | |
3441 | ||
3442 | ||
c2a04078 | 3443 | static int wpa_driver_nl80211_authenticate( |
9ebce9c5 | 3444 | struct i802_bss *bss, struct wpa_driver_auth_params *params) |
c2a04078 | 3445 | { |
a2e40bb6 | 3446 | struct wpa_driver_nl80211_data *drv = bss->drv; |
a0b2f99b | 3447 | int ret = -1, i; |
c2a04078 JM |
3448 | struct nl_msg *msg; |
3449 | enum nl80211_auth_type type; | |
2f4f73b1 | 3450 | enum nl80211_iftype nlmode; |
6d6f4bb8 | 3451 | int count = 0; |
536fd62d JM |
3452 | int is_retry; |
3453 | ||
4bd71954 JM |
3454 | nl80211_unmask_11b_rates(bss); |
3455 | ||
536fd62d JM |
3456 | is_retry = drv->retry_auth; |
3457 | drv->retry_auth = 0; | |
e8d70a73 | 3458 | drv->ignore_deauth_event = 0; |
c2a04078 | 3459 | |
add9b7a4 | 3460 | nl80211_mark_disconnected(drv); |
e6b8efeb | 3461 | os_memset(drv->auth_bssid, 0, ETH_ALEN); |
add9b7a4 JM |
3462 | if (params->bssid) |
3463 | os_memcpy(drv->auth_attempt_bssid, params->bssid, ETH_ALEN); | |
3464 | else | |
3465 | os_memset(drv->auth_attempt_bssid, 0, ETH_ALEN); | |
af473088 | 3466 | /* FIX: IBSS mode */ |
2f4f73b1 EP |
3467 | nlmode = params->p2p ? |
3468 | NL80211_IFTYPE_P2P_CLIENT : NL80211_IFTYPE_STATION; | |
3469 | if (drv->nlmode != nlmode && | |
9ebce9c5 | 3470 | wpa_driver_nl80211_set_mode(bss, nlmode) < 0) |
4a867032 JM |
3471 | return -1; |
3472 | ||
6d6f4bb8 | 3473 | retry: |
c2a04078 JM |
3474 | wpa_printf(MSG_DEBUG, "nl80211: Authenticate (ifindex=%d)", |
3475 | drv->ifindex); | |
a0b2f99b | 3476 | |
9725b784 JM |
3477 | msg = nl80211_drv_msg(drv, 0, NL80211_CMD_AUTHENTICATE); |
3478 | if (!msg) | |
3479 | goto fail; | |
0194fedb | 3480 | |
a0b2f99b JM |
3481 | for (i = 0; i < 4; i++) { |
3482 | if (!params->wep_key[i]) | |
3483 | continue; | |
9ebce9c5 | 3484 | wpa_driver_nl80211_set_key(bss->ifname, bss, WPA_ALG_WEP, |
2ea2fcc7 | 3485 | NULL, i, |
a0b2f99b JM |
3486 | i == params->wep_tx_keyidx, NULL, 0, |
3487 | params->wep_key[i], | |
3488 | params->wep_key_len[i]); | |
0194fedb JB |
3489 | if (params->wep_tx_keyidx != i) |
3490 | continue; | |
3491 | if (nl_add_key(msg, WPA_ALG_WEP, i, 1, NULL, 0, | |
9725b784 JM |
3492 | params->wep_key[i], params->wep_key_len[i])) |
3493 | goto fail; | |
a0b2f99b JM |
3494 | } |
3495 | ||
c2a04078 JM |
3496 | if (params->bssid) { |
3497 | wpa_printf(MSG_DEBUG, " * bssid=" MACSTR, | |
3498 | MAC2STR(params->bssid)); | |
a862e4a3 JM |
3499 | if (nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, params->bssid)) |
3500 | goto fail; | |
c2a04078 JM |
3501 | } |
3502 | if (params->freq) { | |
3503 | wpa_printf(MSG_DEBUG, " * freq=%d", params->freq); | |
a862e4a3 JM |
3504 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, params->freq)) |
3505 | goto fail; | |
c2a04078 JM |
3506 | } |
3507 | if (params->ssid) { | |
21cd8f83 JM |
3508 | wpa_printf(MSG_DEBUG, " * SSID=%s", |
3509 | wpa_ssid_txt(params->ssid, params->ssid_len)); | |
a862e4a3 JM |
3510 | if (nla_put(msg, NL80211_ATTR_SSID, params->ssid_len, |
3511 | params->ssid)) | |
3512 | goto fail; | |
c2a04078 JM |
3513 | } |
3514 | wpa_hexdump(MSG_DEBUG, " * IEs", params->ie, params->ie_len); | |
a862e4a3 JM |
3515 | if (params->ie && |
3516 | nla_put(msg, NL80211_ATTR_IE, params->ie_len, params->ie)) | |
3517 | goto fail; | |
ce16c489 JM |
3518 | if (params->auth_data) { |
3519 | wpa_hexdump(MSG_DEBUG, " * auth_data", params->auth_data, | |
3520 | params->auth_data_len); | |
3521 | if (nla_put(msg, NL80211_ATTR_SAE_DATA, params->auth_data_len, | |
3522 | params->auth_data)) | |
a862e4a3 | 3523 | goto fail; |
569fed90 | 3524 | } |
3c67e977 | 3525 | type = get_nl_auth_type(params->auth_alg); |
c2a04078 | 3526 | wpa_printf(MSG_DEBUG, " * Auth Type %d", type); |
3c67e977 VK |
3527 | if (type == NL80211_AUTHTYPE_MAX || |
3528 | nla_put_u32(msg, NL80211_ATTR_AUTH_TYPE, type)) | |
a862e4a3 | 3529 | goto fail; |
77339912 JM |
3530 | if (params->local_state_change) { |
3531 | wpa_printf(MSG_DEBUG, " * Local state change only"); | |
a862e4a3 JM |
3532 | if (nla_put_flag(msg, NL80211_ATTR_LOCAL_STATE_CHANGE)) |
3533 | goto fail; | |
77339912 | 3534 | } |
c2a04078 JM |
3535 | |
3536 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); | |
3537 | msg = NULL; | |
3538 | if (ret) { | |
3b7ea880 | 3539 | wpa_dbg(drv->ctx, MSG_DEBUG, |
f875da04 BG |
3540 | "nl80211: MLME command failed (auth): count=%d ret=%d (%s)", |
3541 | count, ret, strerror(-ret)); | |
6d6f4bb8 | 3542 | count++; |
f875da04 BG |
3543 | if ((ret == -EALREADY || ret == -EEXIST) && count == 1 && |
3544 | params->bssid && !params->local_state_change) { | |
6d6f4bb8 JM |
3545 | /* |
3546 | * mac80211 does not currently accept new | |
3547 | * authentication if we are already authenticated. As a | |
3548 | * workaround, force deauthentication and try again. | |
3549 | */ | |
3550 | wpa_printf(MSG_DEBUG, "nl80211: Retry authentication " | |
3551 | "after forced deauthentication"); | |
e8d70a73 | 3552 | drv->ignore_deauth_event = 1; |
6d6f4bb8 | 3553 | wpa_driver_nl80211_deauthenticate( |
5205c4f9 | 3554 | bss, params->bssid, |
6d6f4bb8 JM |
3555 | WLAN_REASON_PREV_AUTH_NOT_VALID); |
3556 | nlmsg_free(msg); | |
3557 | goto retry; | |
3558 | } | |
536fd62d JM |
3559 | |
3560 | if (ret == -ENOENT && params->freq && !is_retry) { | |
3561 | /* | |
3562 | * cfg80211 has likely expired the BSS entry even | |
3563 | * though it was previously available in our internal | |
3564 | * BSS table. To recover quickly, start a single | |
3565 | * channel scan on the specified channel. | |
3566 | */ | |
3567 | struct wpa_driver_scan_params scan; | |
3568 | int freqs[2]; | |
3569 | ||
3570 | os_memset(&scan, 0, sizeof(scan)); | |
3571 | scan.num_ssids = 1; | |
3572 | if (params->ssid) { | |
3573 | scan.ssids[0].ssid = params->ssid; | |
3574 | scan.ssids[0].ssid_len = params->ssid_len; | |
3575 | } | |
3576 | freqs[0] = params->freq; | |
3577 | freqs[1] = 0; | |
3578 | scan.freqs = freqs; | |
3579 | wpa_printf(MSG_DEBUG, "nl80211: Trigger single " | |
3580 | "channel scan to refresh cfg80211 BSS " | |
3581 | "entry"); | |
3582 | ret = wpa_driver_nl80211_scan(bss, &scan); | |
3583 | if (ret == 0) { | |
3584 | nl80211_copy_auth_params(drv, params); | |
3585 | drv->scan_for_auth = 1; | |
3586 | } | |
8c3ba078 JM |
3587 | } else if (is_retry) { |
3588 | /* | |
3589 | * Need to indicate this with an event since the return | |
3590 | * value from the retry is not delivered to core code. | |
3591 | */ | |
3592 | union wpa_event_data event; | |
3593 | wpa_printf(MSG_DEBUG, "nl80211: Authentication retry " | |
3594 | "failed"); | |
3595 | os_memset(&event, 0, sizeof(event)); | |
3596 | os_memcpy(event.timeout_event.addr, drv->auth_bssid_, | |
3597 | ETH_ALEN); | |
3598 | wpa_supplicant_event(drv->ctx, EVENT_AUTH_TIMED_OUT, | |
3599 | &event); | |
536fd62d | 3600 | } |
a862e4a3 JM |
3601 | } else { |
3602 | wpa_printf(MSG_DEBUG, | |
3603 | "nl80211: Authentication request send successfully"); | |
c2a04078 | 3604 | } |
c2a04078 | 3605 | |
a862e4a3 | 3606 | fail: |
c2a04078 JM |
3607 | nlmsg_free(msg); |
3608 | return ret; | |
3609 | } | |
3610 | ||
3611 | ||
f3407c66 | 3612 | int wpa_driver_nl80211_authenticate_retry(struct wpa_driver_nl80211_data *drv) |
536fd62d JM |
3613 | { |
3614 | struct wpa_driver_auth_params params; | |
834ee56f | 3615 | struct i802_bss *bss = drv->first_bss; |
536fd62d JM |
3616 | int i; |
3617 | ||
3618 | wpa_printf(MSG_DEBUG, "nl80211: Try to authenticate again"); | |
3619 | ||
3620 | os_memset(¶ms, 0, sizeof(params)); | |
3621 | params.freq = drv->auth_freq; | |
3622 | params.auth_alg = drv->auth_alg; | |
3623 | params.wep_tx_keyidx = drv->auth_wep_tx_keyidx; | |
3624 | params.local_state_change = drv->auth_local_state_change; | |
3625 | params.p2p = drv->auth_p2p; | |
3626 | ||
3627 | if (!is_zero_ether_addr(drv->auth_bssid_)) | |
3628 | params.bssid = drv->auth_bssid_; | |
3629 | ||
3630 | if (drv->auth_ssid_len) { | |
3631 | params.ssid = drv->auth_ssid; | |
3632 | params.ssid_len = drv->auth_ssid_len; | |
3633 | } | |
3634 | ||
3635 | params.ie = drv->auth_ie; | |
3636 | params.ie_len = drv->auth_ie_len; | |
3637 | ||
3638 | for (i = 0; i < 4; i++) { | |
3639 | if (drv->auth_wep_key_len[i]) { | |
3640 | params.wep_key[i] = drv->auth_wep_key[i]; | |
3641 | params.wep_key_len[i] = drv->auth_wep_key_len[i]; | |
3642 | } | |
3643 | } | |
3644 | ||
3645 | drv->retry_auth = 1; | |
3646 | return wpa_driver_nl80211_authenticate(bss, ¶ms); | |
3647 | } | |
3648 | ||
3649 | ||
a11241fa JB |
3650 | static int wpa_driver_nl80211_send_frame(struct i802_bss *bss, |
3651 | const void *data, size_t len, | |
55231068 JM |
3652 | int encrypt, int noack, |
3653 | unsigned int freq, int no_cck, | |
2d3943ce AO |
3654 | int offchanok, unsigned int wait_time, |
3655 | const u16 *csa_offs, | |
3656 | size_t csa_offs_len) | |
a11241fa JB |
3657 | { |
3658 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
3659 | u64 cookie; | |
41cc50d1 | 3660 | int res; |
a11241fa | 3661 | |
c7caac56 JM |
3662 | if (freq == 0 && drv->nlmode == NL80211_IFTYPE_ADHOC) { |
3663 | freq = nl80211_get_assoc_freq(drv); | |
3664 | wpa_printf(MSG_DEBUG, | |
3665 | "nl80211: send_frame - Use assoc_freq=%u for IBSS", | |
3666 | freq); | |
3667 | } | |
af964484 JM |
3668 | if (freq == 0) { |
3669 | wpa_printf(MSG_DEBUG, "nl80211: send_frame - Use bss->freq=%u", | |
3670 | bss->freq); | |
55231068 | 3671 | freq = bss->freq; |
af964484 | 3672 | } |
55231068 | 3673 | |
739faee2 | 3674 | if (drv->use_monitor) { |
981cf85a | 3675 | wpa_printf(MSG_DEBUG, "nl80211: send_frame(freq=%u bss->freq=%u) -> send_monitor", |
739faee2 | 3676 | freq, bss->freq); |
981cf85a | 3677 | return nl80211_send_monitor(drv, data, len, encrypt, noack); |
739faee2 | 3678 | } |
a11241fa | 3679 | |
739faee2 | 3680 | wpa_printf(MSG_DEBUG, "nl80211: send_frame -> send_frame_cmd"); |
41cc50d1 | 3681 | res = nl80211_send_frame_cmd(bss, freq, wait_time, data, len, |
2d3943ce AO |
3682 | &cookie, no_cck, noack, offchanok, |
3683 | csa_offs, csa_offs_len); | |
41cc50d1 JM |
3684 | if (res == 0 && !noack) { |
3685 | const struct ieee80211_mgmt *mgmt; | |
3686 | u16 fc; | |
3687 | ||
3688 | mgmt = (const struct ieee80211_mgmt *) data; | |
3689 | fc = le_to_host16(mgmt->frame_control); | |
3690 | if (WLAN_FC_GET_TYPE(fc) == WLAN_FC_TYPE_MGMT && | |
3691 | WLAN_FC_GET_STYPE(fc) == WLAN_FC_STYPE_ACTION) { | |
3692 | wpa_printf(MSG_MSGDUMP, | |
3693 | "nl80211: Update send_action_cookie from 0x%llx to 0x%llx", | |
3694 | (long long unsigned int) | |
3695 | drv->send_action_cookie, | |
3696 | (long long unsigned int) cookie); | |
3697 | drv->send_action_cookie = cookie; | |
3698 | } | |
3699 | } | |
3700 | ||
3701 | return res; | |
a11241fa JB |
3702 | } |
3703 | ||
3704 | ||
9ebce9c5 JM |
3705 | static int wpa_driver_nl80211_send_mlme(struct i802_bss *bss, const u8 *data, |
3706 | size_t data_len, int noack, | |
3707 | unsigned int freq, int no_cck, | |
3708 | int offchanok, | |
2d3943ce AO |
3709 | unsigned int wait_time, |
3710 | const u16 *csa_offs, | |
3711 | size_t csa_offs_len) | |
2c2010ac | 3712 | { |
a2e40bb6 | 3713 | struct wpa_driver_nl80211_data *drv = bss->drv; |
2c2010ac | 3714 | struct ieee80211_mgmt *mgmt; |
7a47d567 | 3715 | int encrypt = 1; |
2c2010ac JM |
3716 | u16 fc; |
3717 | ||
3718 | mgmt = (struct ieee80211_mgmt *) data; | |
3719 | fc = le_to_host16(mgmt->frame_control); | |
f95a4524 PF |
3720 | wpa_printf(MSG_DEBUG, "nl80211: send_mlme - da= " MACSTR |
3721 | " noack=%d freq=%u no_cck=%d offchanok=%d wait_time=%u fc=0x%x (%s) nlmode=%d", | |
3722 | MAC2STR(mgmt->da), noack, freq, no_cck, offchanok, wait_time, | |
3723 | fc, fc2str(fc), drv->nlmode); | |
2c2010ac | 3724 | |
8e12685c AS |
3725 | if ((is_sta_interface(drv->nlmode) || |
3726 | drv->nlmode == NL80211_IFTYPE_P2P_DEVICE) && | |
5582a5d1 JB |
3727 | WLAN_FC_GET_TYPE(fc) == WLAN_FC_TYPE_MGMT && |
3728 | WLAN_FC_GET_STYPE(fc) == WLAN_FC_STYPE_PROBE_RESP) { | |
3729 | /* | |
3730 | * The use of last_mgmt_freq is a bit of a hack, | |
3731 | * but it works due to the single-threaded nature | |
3732 | * of wpa_supplicant. | |
3733 | */ | |
af964484 JM |
3734 | if (freq == 0) { |
3735 | wpa_printf(MSG_DEBUG, "nl80211: Use last_mgmt_freq=%d", | |
3736 | drv->last_mgmt_freq); | |
55231068 | 3737 | freq = drv->last_mgmt_freq; |
af964484 | 3738 | } |
55231068 | 3739 | return nl80211_send_frame_cmd(bss, freq, 0, |
88df0ef7 | 3740 | data, data_len, NULL, 1, noack, |
2d3943ce | 3741 | 1, csa_offs, csa_offs_len); |
5582a5d1 JB |
3742 | } |
3743 | ||
61cbe2ff | 3744 | if (drv->device_ap_sme && is_ap_interface(drv->nlmode)) { |
af964484 JM |
3745 | if (freq == 0) { |
3746 | wpa_printf(MSG_DEBUG, "nl80211: Use bss->freq=%d", | |
3747 | bss->freq); | |
55231068 | 3748 | freq = bss->freq; |
af964484 | 3749 | } |
b5671498 JM |
3750 | return nl80211_send_frame_cmd(bss, freq, |
3751 | (int) freq == bss->freq ? 0 : | |
3752 | wait_time, | |
d8d6b32e DG |
3753 | data, data_len, |
3754 | &drv->send_action_cookie, | |
2d3943ce AO |
3755 | no_cck, noack, offchanok, |
3756 | csa_offs, csa_offs_len); | |
86957e62 JM |
3757 | } |
3758 | ||
2c2010ac JM |
3759 | if (WLAN_FC_GET_TYPE(fc) == WLAN_FC_TYPE_MGMT && |
3760 | WLAN_FC_GET_STYPE(fc) == WLAN_FC_STYPE_AUTH) { | |
3761 | /* | |
3762 | * Only one of the authentication frame types is encrypted. | |
3763 | * In order for static WEP encryption to work properly (i.e., | |
3764 | * to not encrypt the frame), we need to tell mac80211 about | |
3765 | * the frames that must not be encrypted. | |
3766 | */ | |
3767 | u16 auth_alg = le_to_host16(mgmt->u.auth.auth_alg); | |
3768 | u16 auth_trans = le_to_host16(mgmt->u.auth.auth_transaction); | |
7a47d567 JB |
3769 | if (auth_alg != WLAN_AUTH_SHARED_KEY || auth_trans != 3) |
3770 | encrypt = 0; | |
2c2010ac JM |
3771 | } |
3772 | ||
739faee2 | 3773 | wpa_printf(MSG_DEBUG, "nl80211: send_mlme -> send_frame"); |
a11241fa | 3774 | return wpa_driver_nl80211_send_frame(bss, data, data_len, encrypt, |
55231068 | 3775 | noack, freq, no_cck, offchanok, |
2d3943ce AO |
3776 | wait_time, csa_offs, |
3777 | csa_offs_len); | |
55231068 JM |
3778 | } |
3779 | ||
3780 | ||
cae87abd JM |
3781 | static int nl80211_put_basic_rates(struct nl_msg *msg, const int *basic_rates) |
3782 | { | |
3783 | u8 rates[NL80211_MAX_SUPP_RATES]; | |
3784 | u8 rates_len = 0; | |
3785 | int i; | |
3786 | ||
3787 | if (!basic_rates) | |
3788 | return 0; | |
3789 | ||
3790 | for (i = 0; i < NL80211_MAX_SUPP_RATES && basic_rates[i] >= 0; i++) | |
3791 | rates[rates_len++] = basic_rates[i] / 5; | |
3792 | ||
3793 | return nla_put(msg, NL80211_ATTR_BSS_BASIC_RATES, rates_len, rates); | |
3794 | } | |
3795 | ||
3796 | ||
31357268 | 3797 | static int nl80211_set_bss(struct i802_bss *bss, int cts, int preamble, |
e5693c47 | 3798 | int slot, int ht_opmode, int ap_isolate, |
cae87abd | 3799 | const int *basic_rates) |
31357268 JM |
3800 | { |
3801 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
3802 | struct nl_msg *msg; | |
3803 | ||
13f83980 | 3804 | if (!(msg = nl80211_bss_msg(bss, 0, NL80211_CMD_SET_BSS)) || |
a862e4a3 JM |
3805 | (cts >= 0 && |
3806 | nla_put_u8(msg, NL80211_ATTR_BSS_CTS_PROT, cts)) || | |
3807 | (preamble >= 0 && | |
3808 | nla_put_u8(msg, NL80211_ATTR_BSS_SHORT_PREAMBLE, preamble)) || | |
3809 | (slot >= 0 && | |
3810 | nla_put_u8(msg, NL80211_ATTR_BSS_SHORT_SLOT_TIME, slot)) || | |
3811 | (ht_opmode >= 0 && | |
3812 | nla_put_u16(msg, NL80211_ATTR_BSS_HT_OPMODE, ht_opmode)) || | |
3813 | (ap_isolate >= 0 && | |
cae87abd JM |
3814 | nla_put_u8(msg, NL80211_ATTR_AP_ISOLATE, ap_isolate)) || |
3815 | nl80211_put_basic_rates(msg, basic_rates)) { | |
3816 | nlmsg_free(msg); | |
3817 | return -ENOBUFS; | |
e5693c47 JM |
3818 | } |
3819 | ||
31357268 | 3820 | return send_and_recv_msgs(drv, msg, NULL, NULL); |
31357268 JM |
3821 | } |
3822 | ||
3823 | ||
3c4ca363 VN |
3824 | static int wpa_driver_nl80211_set_acl(void *priv, |
3825 | struct hostapd_acl_params *params) | |
3826 | { | |
3827 | struct i802_bss *bss = priv; | |
3828 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
3829 | struct nl_msg *msg; | |
f429ec44 | 3830 | struct nl_msg *acl; |
3c4ca363 | 3831 | unsigned int i; |
a862e4a3 | 3832 | int ret; |
3c4ca363 VN |
3833 | |
3834 | if (!(drv->capa.max_acl_mac_addrs)) | |
3835 | return -ENOTSUP; | |
3836 | ||
3837 | if (params->num_mac_acl > drv->capa.max_acl_mac_addrs) | |
3838 | return -ENOTSUP; | |
3839 | ||
3c4ca363 VN |
3840 | wpa_printf(MSG_DEBUG, "nl80211: Set %s ACL (num_mac_acl=%u)", |
3841 | params->acl_policy ? "Accept" : "Deny", params->num_mac_acl); | |
3842 | ||
f429ec44 JM |
3843 | acl = nlmsg_alloc(); |
3844 | if (!acl) | |
3845 | return -ENOMEM; | |
3846 | for (i = 0; i < params->num_mac_acl; i++) { | |
3847 | if (nla_put(acl, i + 1, ETH_ALEN, params->mac_acl[i].addr)) { | |
3848 | nlmsg_free(acl); | |
3849 | return -ENOMEM; | |
3850 | } | |
3851 | } | |
3852 | ||
9725b784 | 3853 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_SET_MAC_ACL)) || |
a862e4a3 JM |
3854 | nla_put_u32(msg, NL80211_ATTR_ACL_POLICY, params->acl_policy ? |
3855 | NL80211_ACL_POLICY_DENY_UNLESS_LISTED : | |
3856 | NL80211_ACL_POLICY_ACCEPT_UNLESS_LISTED) || | |
f429ec44 | 3857 | nla_put_nested(msg, NL80211_ATTR_MAC_ADDRS, acl)) { |
a862e4a3 | 3858 | nlmsg_free(msg); |
f429ec44 | 3859 | nlmsg_free(acl); |
a862e4a3 JM |
3860 | return -ENOMEM; |
3861 | } | |
f429ec44 | 3862 | nlmsg_free(acl); |
3c4ca363 VN |
3863 | |
3864 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); | |
3c4ca363 VN |
3865 | if (ret) { |
3866 | wpa_printf(MSG_DEBUG, "nl80211: Failed to set MAC ACL: %d (%s)", | |
3867 | ret, strerror(-ret)); | |
3868 | } | |
3869 | ||
3c4ca363 VN |
3870 | return ret; |
3871 | } | |
3872 | ||
3873 | ||
85e1fad8 JM |
3874 | static int nl80211_put_beacon_int(struct nl_msg *msg, int beacon_int) |
3875 | { | |
3876 | if (beacon_int > 0) { | |
3877 | wpa_printf(MSG_DEBUG, " * beacon_int=%d", beacon_int); | |
3878 | return nla_put_u32(msg, NL80211_ATTR_BEACON_INTERVAL, | |
3879 | beacon_int); | |
3880 | } | |
3881 | ||
3882 | return 0; | |
3883 | } | |
3884 | ||
3885 | ||
4ac2ea57 MH |
3886 | static int nl80211_put_dtim_period(struct nl_msg *msg, int dtim_period) |
3887 | { | |
3888 | if (dtim_period > 0) { | |
3889 | wpa_printf(MSG_DEBUG, " * dtim_period=%d", dtim_period); | |
3890 | return nla_put_u32(msg, NL80211_ATTR_DTIM_PERIOD, dtim_period); | |
3891 | } | |
3892 | ||
3893 | return 0; | |
3894 | } | |
3895 | ||
3896 | ||
052b8d38 MH |
3897 | #ifdef CONFIG_MESH |
3898 | static int nl80211_set_mesh_config(void *priv, | |
3899 | struct wpa_driver_mesh_bss_params *params) | |
3900 | { | |
3901 | struct i802_bss *bss = priv; | |
3902 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
3903 | struct nl_msg *msg; | |
3904 | int ret; | |
3905 | ||
3906 | msg = nl80211_drv_msg(drv, 0, NL80211_CMD_SET_MESH_CONFIG); | |
3907 | if (!msg) | |
3908 | return -1; | |
3909 | ||
3910 | ret = nl80211_put_mesh_config(msg, params); | |
3911 | if (ret < 0) { | |
3912 | nlmsg_free(msg); | |
3913 | return ret; | |
3914 | } | |
3915 | ||
3916 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); | |
3917 | if (ret) { | |
3918 | wpa_printf(MSG_ERROR, | |
3919 | "nl80211: Mesh config set failed: %d (%s)", | |
3920 | ret, strerror(-ret)); | |
3921 | return ret; | |
3922 | } | |
3923 | return 0; | |
3924 | } | |
3925 | #endif /* CONFIG_MESH */ | |
3926 | ||
3927 | ||
d4f3003c PK |
3928 | static int nl80211_put_beacon_rate(struct nl_msg *msg, const u64 flags, |
3929 | struct wpa_driver_ap_params *params) | |
3930 | { | |
3931 | struct nlattr *bands, *band; | |
3932 | struct nl80211_txrate_vht vht_rate; | |
3933 | ||
3934 | if (!params->freq || | |
3935 | (params->beacon_rate == 0 && | |
3936 | params->rate_type == BEACON_RATE_LEGACY)) | |
3937 | return 0; | |
3938 | ||
3939 | bands = nla_nest_start(msg, NL80211_ATTR_TX_RATES); | |
3940 | if (!bands) | |
3941 | return -1; | |
3942 | ||
3943 | switch (params->freq->mode) { | |
3944 | case HOSTAPD_MODE_IEEE80211B: | |
3945 | case HOSTAPD_MODE_IEEE80211G: | |
3946 | band = nla_nest_start(msg, NL80211_BAND_2GHZ); | |
3947 | break; | |
3948 | case HOSTAPD_MODE_IEEE80211A: | |
3949 | band = nla_nest_start(msg, NL80211_BAND_5GHZ); | |
3950 | break; | |
3951 | case HOSTAPD_MODE_IEEE80211AD: | |
3952 | band = nla_nest_start(msg, NL80211_BAND_60GHZ); | |
3953 | break; | |
3954 | default: | |
3955 | return 0; | |
3956 | } | |
3957 | ||
3958 | if (!band) | |
3959 | return -1; | |
3960 | ||
3961 | os_memset(&vht_rate, 0, sizeof(vht_rate)); | |
3962 | ||
3963 | switch (params->rate_type) { | |
3964 | case BEACON_RATE_LEGACY: | |
3965 | if (!(flags & WPA_DRIVER_FLAGS_BEACON_RATE_LEGACY)) { | |
3966 | wpa_printf(MSG_INFO, | |
3967 | "nl80211: Driver does not support setting Beacon frame rate (legacy)"); | |
3968 | return -1; | |
3969 | } | |
3970 | ||
3971 | if (nla_put_u8(msg, NL80211_TXRATE_LEGACY, | |
3972 | (u8) params->beacon_rate / 5) || | |
3973 | nla_put(msg, NL80211_TXRATE_HT, 0, NULL) || | |
3974 | (params->freq->vht_enabled && | |
3975 | nla_put(msg, NL80211_TXRATE_VHT, sizeof(vht_rate), | |
3976 | &vht_rate))) | |
3977 | return -1; | |
3978 | ||
3979 | wpa_printf(MSG_DEBUG, " * beacon_rate = legacy:%u (* 100 kbps)", | |
3980 | params->beacon_rate); | |
3981 | break; | |
3982 | case BEACON_RATE_HT: | |
3983 | if (!(flags & WPA_DRIVER_FLAGS_BEACON_RATE_HT)) { | |
3984 | wpa_printf(MSG_INFO, | |
3985 | "nl80211: Driver does not support setting Beacon frame rate (HT)"); | |
3986 | return -1; | |
3987 | } | |
3988 | if (nla_put(msg, NL80211_TXRATE_LEGACY, 0, NULL) || | |
3989 | nla_put_u8(msg, NL80211_TXRATE_HT, params->beacon_rate) || | |
3990 | (params->freq->vht_enabled && | |
3991 | nla_put(msg, NL80211_TXRATE_VHT, sizeof(vht_rate), | |
3992 | &vht_rate))) | |
3993 | return -1; | |
3994 | wpa_printf(MSG_DEBUG, " * beacon_rate = HT-MCS %u", | |
3995 | params->beacon_rate); | |
3996 | break; | |
3997 | case BEACON_RATE_VHT: | |
3998 | if (!(flags & WPA_DRIVER_FLAGS_BEACON_RATE_VHT)) { | |
3999 | wpa_printf(MSG_INFO, | |
4000 | "nl80211: Driver does not support setting Beacon frame rate (VHT)"); | |
4001 | return -1; | |
4002 | } | |
4003 | vht_rate.mcs[0] = BIT(params->beacon_rate); | |
4004 | if (nla_put(msg, NL80211_TXRATE_LEGACY, 0, NULL)) | |
4005 | return -1; | |
4006 | if (nla_put(msg, NL80211_TXRATE_HT, 0, NULL)) | |
4007 | return -1; | |
4008 | if (nla_put(msg, NL80211_TXRATE_VHT, sizeof(vht_rate), | |
4009 | &vht_rate)) | |
4010 | return -1; | |
4011 | wpa_printf(MSG_DEBUG, " * beacon_rate = VHT-MCS %u", | |
4012 | params->beacon_rate); | |
4013 | break; | |
4014 | } | |
4015 | ||
4016 | nla_nest_end(msg, band); | |
4017 | nla_nest_end(msg, bands); | |
4018 | ||
4019 | return 0; | |
4020 | } | |
4021 | ||
4022 | ||
34f7c699 MB |
4023 | static int nl80211_set_multicast_to_unicast(struct i802_bss *bss, |
4024 | int multicast_to_unicast) | |
4025 | { | |
4026 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
4027 | struct nl_msg *msg; | |
4028 | int ret; | |
4029 | ||
4030 | msg = nl80211_bss_msg(bss, 0, NL80211_CMD_SET_MULTICAST_TO_UNICAST); | |
4031 | if (!msg || | |
4032 | (multicast_to_unicast && | |
4033 | nla_put_flag(msg, NL80211_ATTR_MULTICAST_TO_UNICAST_ENABLED))) { | |
4034 | wpa_printf(MSG_ERROR, | |
4035 | "nl80211: Failed to build NL80211_CMD_SET_MULTICAST_TO_UNICAST msg for %s", | |
4036 | bss->ifname); | |
4037 | nlmsg_free(msg); | |
4038 | return -ENOBUFS; | |
4039 | } | |
4040 | ||
4041 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); | |
4042 | ||
4043 | switch (ret) { | |
4044 | case 0: | |
4045 | wpa_printf(MSG_DEBUG, | |
4046 | "nl80211: multicast to unicast %s on interface %s", | |
4047 | multicast_to_unicast ? "enabled" : "disabled", | |
4048 | bss->ifname); | |
4049 | break; | |
4050 | case -EOPNOTSUPP: | |
4051 | if (!multicast_to_unicast) | |
4052 | break; | |
4053 | wpa_printf(MSG_INFO, | |
4054 | "nl80211: multicast to unicast not supported on interface %s", | |
4055 | bss->ifname); | |
4056 | break; | |
4057 | default: | |
4058 | wpa_printf(MSG_ERROR, | |
4059 | "nl80211: %s multicast to unicast failed with %d (%s) on interface %s", | |
4060 | multicast_to_unicast ? "enabling" : "disabling", | |
4061 | ret, strerror(-ret), bss->ifname); | |
4062 | break; | |
4063 | } | |
4064 | ||
4065 | return ret; | |
4066 | } | |
4067 | ||
4068 | ||
19c3b566 JM |
4069 | static int wpa_driver_nl80211_set_ap(void *priv, |
4070 | struct wpa_driver_ap_params *params) | |
d2440ba0 | 4071 | { |
a2e40bb6 FF |
4072 | struct i802_bss *bss = priv; |
4073 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
d2440ba0 JM |
4074 | struct nl_msg *msg; |
4075 | u8 cmd = NL80211_CMD_NEW_BEACON; | |
5b82cdbe | 4076 | int ret = -ENOBUFS; |
b4fd6fab | 4077 | int beacon_set; |
b11d1d64 | 4078 | int num_suites; |
da1080d7 | 4079 | int smps_mode; |
de4ed4a8 | 4080 | u32 suites[10], suite; |
b11d1d64 | 4081 | u32 ver; |
052b8d38 MH |
4082 | #ifdef CONFIG_MESH |
4083 | struct wpa_driver_mesh_bss_params mesh_params; | |
4084 | #endif /* CONFIG_MESH */ | |
b4fd6fab | 4085 | |
f33c8606 | 4086 | beacon_set = params->reenable ? 0 : bss->beacon_set; |
d2440ba0 | 4087 | |
d2440ba0 | 4088 | wpa_printf(MSG_DEBUG, "nl80211: Set beacon (beacon_set=%d)", |
b4fd6fab JM |
4089 | beacon_set); |
4090 | if (beacon_set) | |
d2440ba0 | 4091 | cmd = NL80211_CMD_SET_BEACON; |
89fa633a DL |
4092 | else if (!drv->device_ap_sme && !drv->use_monitor && |
4093 | !nl80211_get_wiphy_data_ap(bss)) | |
a70cd0db | 4094 | return -ENOBUFS; |
d2440ba0 | 4095 | |
b92e08fc JM |
4096 | wpa_hexdump(MSG_DEBUG, "nl80211: Beacon head", |
4097 | params->head, params->head_len); | |
b92e08fc JM |
4098 | wpa_hexdump(MSG_DEBUG, "nl80211: Beacon tail", |
4099 | params->tail, params->tail_len); | |
13f83980 | 4100 | wpa_printf(MSG_DEBUG, "nl80211: ifindex=%d", bss->ifindex); |
b92e08fc | 4101 | wpa_printf(MSG_DEBUG, "nl80211: beacon_int=%d", params->beacon_int); |
d4f3003c PK |
4102 | wpa_printf(MSG_DEBUG, "nl80211: beacon_rate=%u", params->beacon_rate); |
4103 | wpa_printf(MSG_DEBUG, "nl80211: rate_type=%d", params->rate_type); | |
b92e08fc | 4104 | wpa_printf(MSG_DEBUG, "nl80211: dtim_period=%d", params->dtim_period); |
21cd8f83 JM |
4105 | wpa_printf(MSG_DEBUG, "nl80211: ssid=%s", |
4106 | wpa_ssid_txt(params->ssid, params->ssid_len)); | |
13f83980 | 4107 | if (!(msg = nl80211_bss_msg(bss, 0, cmd)) || |
a862e4a3 JM |
4108 | nla_put(msg, NL80211_ATTR_BEACON_HEAD, params->head_len, |
4109 | params->head) || | |
4110 | nla_put(msg, NL80211_ATTR_BEACON_TAIL, params->tail_len, | |
4111 | params->tail) || | |
85e1fad8 | 4112 | nl80211_put_beacon_int(msg, params->beacon_int) || |
d4f3003c | 4113 | nl80211_put_beacon_rate(msg, drv->capa.flags, params) || |
4ac2ea57 | 4114 | nl80211_put_dtim_period(msg, params->dtim_period) || |
a862e4a3 JM |
4115 | nla_put(msg, NL80211_ATTR_SSID, params->ssid_len, params->ssid)) |
4116 | goto fail; | |
b92e08fc JM |
4117 | if (params->proberesp && params->proberesp_len) { |
4118 | wpa_hexdump(MSG_DEBUG, "nl80211: proberesp (offload)", | |
4119 | params->proberesp, params->proberesp_len); | |
a862e4a3 JM |
4120 | if (nla_put(msg, NL80211_ATTR_PROBE_RESP, params->proberesp_len, |
4121 | params->proberesp)) | |
4122 | goto fail; | |
b92e08fc | 4123 | } |
97a7a0b5 JM |
4124 | switch (params->hide_ssid) { |
4125 | case NO_SSID_HIDING: | |
b92e08fc | 4126 | wpa_printf(MSG_DEBUG, "nl80211: hidden SSID not in use"); |
a862e4a3 JM |
4127 | if (nla_put_u32(msg, NL80211_ATTR_HIDDEN_SSID, |
4128 | NL80211_HIDDEN_SSID_NOT_IN_USE)) | |
4129 | goto fail; | |
97a7a0b5 JM |
4130 | break; |
4131 | case HIDDEN_SSID_ZERO_LEN: | |
b92e08fc | 4132 | wpa_printf(MSG_DEBUG, "nl80211: hidden SSID zero len"); |
a862e4a3 JM |
4133 | if (nla_put_u32(msg, NL80211_ATTR_HIDDEN_SSID, |
4134 | NL80211_HIDDEN_SSID_ZERO_LEN)) | |
4135 | goto fail; | |
97a7a0b5 JM |
4136 | break; |
4137 | case HIDDEN_SSID_ZERO_CONTENTS: | |
b92e08fc | 4138 | wpa_printf(MSG_DEBUG, "nl80211: hidden SSID zero contents"); |
a862e4a3 JM |
4139 | if (nla_put_u32(msg, NL80211_ATTR_HIDDEN_SSID, |
4140 | NL80211_HIDDEN_SSID_ZERO_CONTENTS)) | |
4141 | goto fail; | |
97a7a0b5 JM |
4142 | break; |
4143 | } | |
b92e08fc | 4144 | wpa_printf(MSG_DEBUG, "nl80211: privacy=%d", params->privacy); |
a862e4a3 JM |
4145 | if (params->privacy && |
4146 | nla_put_flag(msg, NL80211_ATTR_PRIVACY)) | |
4147 | goto fail; | |
b92e08fc | 4148 | wpa_printf(MSG_DEBUG, "nl80211: auth_algs=0x%x", params->auth_algs); |
b11d1d64 JM |
4149 | if ((params->auth_algs & (WPA_AUTH_ALG_OPEN | WPA_AUTH_ALG_SHARED)) == |
4150 | (WPA_AUTH_ALG_OPEN | WPA_AUTH_ALG_SHARED)) { | |
4151 | /* Leave out the attribute */ | |
a862e4a3 JM |
4152 | } else if (params->auth_algs & WPA_AUTH_ALG_SHARED) { |
4153 | if (nla_put_u32(msg, NL80211_ATTR_AUTH_TYPE, | |
4154 | NL80211_AUTHTYPE_SHARED_KEY)) | |
4155 | goto fail; | |
4156 | } else { | |
4157 | if (nla_put_u32(msg, NL80211_ATTR_AUTH_TYPE, | |
4158 | NL80211_AUTHTYPE_OPEN_SYSTEM)) | |
4159 | goto fail; | |
4160 | } | |
b11d1d64 | 4161 | |
b92e08fc | 4162 | wpa_printf(MSG_DEBUG, "nl80211: wpa_version=0x%x", params->wpa_version); |
b11d1d64 JM |
4163 | ver = 0; |
4164 | if (params->wpa_version & WPA_PROTO_WPA) | |
4165 | ver |= NL80211_WPA_VERSION_1; | |
4166 | if (params->wpa_version & WPA_PROTO_RSN) | |
4167 | ver |= NL80211_WPA_VERSION_2; | |
a862e4a3 JM |
4168 | if (ver && |
4169 | nla_put_u32(msg, NL80211_ATTR_WPA_VERSIONS, ver)) | |
4170 | goto fail; | |
b11d1d64 | 4171 | |
b92e08fc JM |
4172 | wpa_printf(MSG_DEBUG, "nl80211: key_mgmt_suites=0x%x", |
4173 | params->key_mgmt_suites); | |
b11d1d64 JM |
4174 | num_suites = 0; |
4175 | if (params->key_mgmt_suites & WPA_KEY_MGMT_IEEE8021X) | |
3aa24db9 | 4176 | suites[num_suites++] = RSN_AUTH_KEY_MGMT_UNSPEC_802_1X; |
b11d1d64 | 4177 | if (params->key_mgmt_suites & WPA_KEY_MGMT_PSK) |
3aa24db9 | 4178 | suites[num_suites++] = RSN_AUTH_KEY_MGMT_PSK_OVER_802_1X; |
a862e4a3 JM |
4179 | if (num_suites && |
4180 | nla_put(msg, NL80211_ATTR_AKM_SUITES, num_suites * sizeof(u32), | |
4181 | suites)) | |
4182 | goto fail; | |
b11d1d64 | 4183 | |
533fe09b | 4184 | if (params->key_mgmt_suites & WPA_KEY_MGMT_IEEE8021X_NO_WPA && |
e3429c0b JB |
4185 | (!params->pairwise_ciphers || |
4186 | params->pairwise_ciphers & (WPA_CIPHER_WEP104 | WPA_CIPHER_WEP40)) && | |
4187 | (nla_put_u16(msg, NL80211_ATTR_CONTROL_PORT_ETHERTYPE, ETH_P_PAE) || | |
4188 | nla_put_flag(msg, NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT))) | |
a862e4a3 | 4189 | goto fail; |
9f12614b | 4190 | |
c8931afe JM |
4191 | if (drv->device_ap_sme && |
4192 | (params->key_mgmt_suites & WPA_KEY_MGMT_SAE) && | |
4193 | nla_put_flag(msg, NL80211_ATTR_EXTERNAL_AUTH_SUPPORT)) | |
4194 | goto fail; | |
236e793e | 4195 | |
b92e08fc JM |
4196 | wpa_printf(MSG_DEBUG, "nl80211: pairwise_ciphers=0x%x", |
4197 | params->pairwise_ciphers); | |
de4ed4a8 JM |
4198 | num_suites = wpa_cipher_to_cipher_suites(params->pairwise_ciphers, |
4199 | suites, ARRAY_SIZE(suites)); | |
a862e4a3 JM |
4200 | if (num_suites && |
4201 | nla_put(msg, NL80211_ATTR_CIPHER_SUITES_PAIRWISE, | |
4202 | num_suites * sizeof(u32), suites)) | |
4203 | goto fail; | |
b11d1d64 | 4204 | |
b92e08fc JM |
4205 | wpa_printf(MSG_DEBUG, "nl80211: group_cipher=0x%x", |
4206 | params->group_cipher); | |
de4ed4a8 | 4207 | suite = wpa_cipher_to_cipher_suite(params->group_cipher); |
a862e4a3 JM |
4208 | if (suite && |
4209 | nla_put_u32(msg, NL80211_ATTR_CIPHER_SUITE_GROUP, suite)) | |
4210 | goto fail; | |
d2440ba0 | 4211 | |
ee298f1b JM |
4212 | if (params->ht_opmode != -1) { |
4213 | switch (params->smps_mode) { | |
4214 | case HT_CAP_INFO_SMPS_DYNAMIC: | |
4215 | wpa_printf(MSG_DEBUG, "nl80211: SMPS mode - dynamic"); | |
4216 | smps_mode = NL80211_SMPS_DYNAMIC; | |
4217 | break; | |
4218 | case HT_CAP_INFO_SMPS_STATIC: | |
4219 | wpa_printf(MSG_DEBUG, "nl80211: SMPS mode - static"); | |
4220 | smps_mode = NL80211_SMPS_STATIC; | |
4221 | break; | |
4222 | default: | |
4223 | /* invalid - fallback to smps off */ | |
4224 | case HT_CAP_INFO_SMPS_DISABLED: | |
4225 | wpa_printf(MSG_DEBUG, "nl80211: SMPS mode - off"); | |
4226 | smps_mode = NL80211_SMPS_OFF; | |
4227 | break; | |
4228 | } | |
a2426829 | 4229 | if (nla_put_u8(msg, NL80211_ATTR_SMPS_MODE, smps_mode)) |
ee298f1b | 4230 | goto fail; |
da1080d7 | 4231 | } |
da1080d7 | 4232 | |
fb91db56 | 4233 | if (params->beacon_ies) { |
b92e08fc JM |
4234 | wpa_hexdump_buf(MSG_DEBUG, "nl80211: beacon_ies", |
4235 | params->beacon_ies); | |
a862e4a3 JM |
4236 | if (nla_put(msg, NL80211_ATTR_IE, |
4237 | wpabuf_len(params->beacon_ies), | |
4238 | wpabuf_head(params->beacon_ies))) | |
4239 | goto fail; | |
fb91db56 JM |
4240 | } |
4241 | if (params->proberesp_ies) { | |
b92e08fc JM |
4242 | wpa_hexdump_buf(MSG_DEBUG, "nl80211: proberesp_ies", |
4243 | params->proberesp_ies); | |
a862e4a3 JM |
4244 | if (nla_put(msg, NL80211_ATTR_IE_PROBE_RESP, |
4245 | wpabuf_len(params->proberesp_ies), | |
4246 | wpabuf_head(params->proberesp_ies))) | |
4247 | goto fail; | |
fb91db56 JM |
4248 | } |
4249 | if (params->assocresp_ies) { | |
b92e08fc JM |
4250 | wpa_hexdump_buf(MSG_DEBUG, "nl80211: assocresp_ies", |
4251 | params->assocresp_ies); | |
a862e4a3 JM |
4252 | if (nla_put(msg, NL80211_ATTR_IE_ASSOC_RESP, |
4253 | wpabuf_len(params->assocresp_ies), | |
4254 | wpabuf_head(params->assocresp_ies))) | |
4255 | goto fail; | |
fb91db56 JM |
4256 | } |
4257 | ||
a0133ee1 | 4258 | if (drv->capa.flags & WPA_DRIVER_FLAGS_INACTIVITY_TIMER) { |
b92e08fc JM |
4259 | wpa_printf(MSG_DEBUG, "nl80211: ap_max_inactivity=%d", |
4260 | params->ap_max_inactivity); | |
a862e4a3 JM |
4261 | if (nla_put_u16(msg, NL80211_ATTR_INACTIVITY_TIMEOUT, |
4262 | params->ap_max_inactivity)) | |
4263 | goto fail; | |
a0133ee1 VT |
4264 | } |
4265 | ||
abb8d08b EP |
4266 | #ifdef CONFIG_P2P |
4267 | if (params->p2p_go_ctwindow > 0) { | |
4268 | if (drv->p2p_go_ctwindow_supported) { | |
4269 | wpa_printf(MSG_DEBUG, "nl80211: P2P GO ctwindow=%d", | |
4270 | params->p2p_go_ctwindow); | |
4271 | if (nla_put_u8(msg, NL80211_ATTR_P2P_CTWINDOW, | |
4272 | params->p2p_go_ctwindow)) | |
4273 | goto fail; | |
4274 | } else { | |
4275 | wpa_printf(MSG_INFO, | |
4276 | "nl80211: Driver does not support CTWindow configuration - ignore this parameter"); | |
4277 | } | |
4278 | } | |
4279 | #endif /* CONFIG_P2P */ | |
4280 | ||
86b5c400 LD |
4281 | if (params->pbss) { |
4282 | wpa_printf(MSG_DEBUG, "nl80211: PBSS"); | |
4283 | if (nla_put_flag(msg, NL80211_ATTR_PBSS)) | |
4284 | goto fail; | |
4285 | } | |
4286 | ||
5b82cdbe JB |
4287 | if (params->ftm_responder) { |
4288 | struct nlattr *ftm; | |
4289 | ||
4290 | if (!(drv->capa.flags & WPA_DRIVER_FLAGS_FTM_RESPONDER)) { | |
4291 | ret = -ENOTSUP; | |
4292 | goto fail; | |
4293 | } | |
4294 | ||
4295 | ftm = nla_nest_start(msg, NL80211_ATTR_FTM_RESPONDER); | |
4296 | if (!ftm || | |
4297 | nla_put_flag(msg, NL80211_FTM_RESP_ATTR_ENABLED) || | |
4298 | (params->lci && | |
4299 | nla_put(msg, NL80211_FTM_RESP_ATTR_LCI, | |
4300 | wpabuf_len(params->lci), | |
4301 | wpabuf_head(params->lci))) || | |
4302 | (params->civic && | |
4303 | nla_put(msg, NL80211_FTM_RESP_ATTR_CIVICLOC, | |
4304 | wpabuf_len(params->civic), | |
4305 | wpabuf_head(params->civic)))) | |
4306 | goto fail; | |
4307 | nla_nest_end(msg, ftm); | |
4308 | } | |
4309 | ||
a84bf443 JC |
4310 | #ifdef CONFIG_IEEE80211AX |
4311 | if (params->he_spr) { | |
4312 | struct nlattr *spr; | |
4313 | ||
4314 | spr = nla_nest_start(msg, NL80211_ATTR_HE_OBSS_PD); | |
4315 | wpa_printf(MSG_DEBUG, "nl80211: he_spr=%d", params->he_spr); | |
4316 | ||
4317 | if (nla_put_u8(msg, NL80211_HE_OBSS_PD_ATTR_MIN_OFFSET, | |
4318 | params->he_spr_srg_obss_pd_min_offset) || | |
4319 | nla_put_u8(msg, NL80211_HE_OBSS_PD_ATTR_MAX_OFFSET, | |
4320 | params->he_spr_srg_obss_pd_max_offset)) | |
4321 | goto fail; | |
4322 | ||
4323 | nla_nest_end(msg, spr); | |
4324 | } | |
4325 | #endif /* CONFIG_IEEE80211AX */ | |
4326 | ||
d2440ba0 JM |
4327 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
4328 | if (ret) { | |
4329 | wpa_printf(MSG_DEBUG, "nl80211: Beacon set failed: %d (%s)", | |
4330 | ret, strerror(-ret)); | |
b4fd6fab | 4331 | } else { |
b4fd6fab | 4332 | bss->beacon_set = 1; |
31357268 | 4333 | nl80211_set_bss(bss, params->cts_protect, params->preamble, |
d03e8d11 | 4334 | params->short_slot_time, params->ht_opmode, |
e5693c47 | 4335 | params->isolate, params->basic_rates); |
34f7c699 MB |
4336 | nl80211_set_multicast_to_unicast(bss, |
4337 | params->multicast_to_unicast); | |
e87ef751 PX |
4338 | if (beacon_set && params->freq && |
4339 | params->freq->bandwidth != bss->bandwidth) { | |
4340 | wpa_printf(MSG_DEBUG, | |
4341 | "nl80211: Update BSS %s bandwidth: %d -> %d", | |
4342 | bss->ifname, bss->bandwidth, | |
4343 | params->freq->bandwidth); | |
4344 | ret = nl80211_set_channel(bss, params->freq, 1); | |
4345 | if (ret) { | |
4346 | wpa_printf(MSG_DEBUG, | |
4347 | "nl80211: Frequency set failed: %d (%s)", | |
4348 | ret, strerror(-ret)); | |
4349 | } else { | |
4350 | wpa_printf(MSG_DEBUG, | |
4351 | "nl80211: Frequency set succeeded for ht2040 coex"); | |
4352 | bss->bandwidth = params->freq->bandwidth; | |
4353 | } | |
f5728d0a | 4354 | } else if (!beacon_set && params->freq) { |
e87ef751 PX |
4355 | /* |
4356 | * cfg80211 updates the driver on frequence change in AP | |
4357 | * mode only at the point when beaconing is started, so | |
4358 | * set the initial value here. | |
4359 | */ | |
4360 | bss->bandwidth = params->freq->bandwidth; | |
4361 | } | |
b4fd6fab | 4362 | } |
052b8d38 MH |
4363 | |
4364 | #ifdef CONFIG_MESH | |
4365 | if (is_mesh_interface(drv->nlmode) && params->ht_opmode != -1) { | |
4366 | os_memset(&mesh_params, 0, sizeof(mesh_params)); | |
4367 | mesh_params.flags |= WPA_DRIVER_MESH_CONF_FLAG_HT_OP_MODE; | |
4368 | mesh_params.ht_opmode = params->ht_opmode; | |
4369 | ret = nl80211_set_mesh_config(priv, &mesh_params); | |
4370 | if (ret < 0) | |
4371 | return ret; | |
4372 | } | |
4373 | #endif /* CONFIG_MESH */ | |
4374 | ||
d2440ba0 | 4375 | return ret; |
a862e4a3 | 4376 | fail: |
5883168a | 4377 | nlmsg_free(msg); |
5b82cdbe | 4378 | return ret; |
d2440ba0 JM |
4379 | } |
4380 | ||
4381 | ||
1c4ffa87 | 4382 | static int nl80211_put_freq_params(struct nl_msg *msg, |
72b2605f | 4383 | const struct hostapd_freq_params *freq) |
1581b38b | 4384 | { |
df4f9599 SE |
4385 | enum hostapd_hw_mode hw_mode; |
4386 | int is_24ghz; | |
4387 | u8 channel; | |
4388 | ||
1fc4ab23 | 4389 | wpa_printf(MSG_DEBUG, " * freq=%d", freq->freq); |
a862e4a3 JM |
4390 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq->freq)) |
4391 | return -ENOBUFS; | |
4392 | ||
ad9a1bfe | 4393 | wpa_printf(MSG_DEBUG, " * he_enabled=%d", freq->he_enabled); |
1fc4ab23 JM |
4394 | wpa_printf(MSG_DEBUG, " * vht_enabled=%d", freq->vht_enabled); |
4395 | wpa_printf(MSG_DEBUG, " * ht_enabled=%d", freq->ht_enabled); | |
4396 | ||
df4f9599 SE |
4397 | hw_mode = ieee80211_freq_to_chan(freq->freq, &channel); |
4398 | is_24ghz = hw_mode == HOSTAPD_MODE_IEEE80211G || | |
4399 | hw_mode == HOSTAPD_MODE_IEEE80211B; | |
4400 | ||
4401 | if (freq->vht_enabled || (freq->he_enabled && !is_24ghz)) { | |
a862e4a3 JM |
4402 | enum nl80211_chan_width cw; |
4403 | ||
1fc4ab23 | 4404 | wpa_printf(MSG_DEBUG, " * bandwidth=%d", freq->bandwidth); |
89b800d7 JB |
4405 | switch (freq->bandwidth) { |
4406 | case 20: | |
a862e4a3 | 4407 | cw = NL80211_CHAN_WIDTH_20; |
89b800d7 JB |
4408 | break; |
4409 | case 40: | |
a862e4a3 | 4410 | cw = NL80211_CHAN_WIDTH_40; |
89b800d7 JB |
4411 | break; |
4412 | case 80: | |
4413 | if (freq->center_freq2) | |
a862e4a3 | 4414 | cw = NL80211_CHAN_WIDTH_80P80; |
89b800d7 | 4415 | else |
a862e4a3 | 4416 | cw = NL80211_CHAN_WIDTH_80; |
89b800d7 JB |
4417 | break; |
4418 | case 160: | |
a862e4a3 | 4419 | cw = NL80211_CHAN_WIDTH_160; |
89b800d7 JB |
4420 | break; |
4421 | default: | |
1c4ffa87 | 4422 | return -EINVAL; |
89b800d7 | 4423 | } |
a862e4a3 | 4424 | |
1fc4ab23 JM |
4425 | wpa_printf(MSG_DEBUG, " * channel_width=%d", cw); |
4426 | wpa_printf(MSG_DEBUG, " * center_freq1=%d", | |
4427 | freq->center_freq1); | |
4428 | wpa_printf(MSG_DEBUG, " * center_freq2=%d", | |
4429 | freq->center_freq2); | |
a862e4a3 JM |
4430 | if (nla_put_u32(msg, NL80211_ATTR_CHANNEL_WIDTH, cw) || |
4431 | nla_put_u32(msg, NL80211_ATTR_CENTER_FREQ1, | |
4432 | freq->center_freq1) || | |
4433 | (freq->center_freq2 && | |
4434 | nla_put_u32(msg, NL80211_ATTR_CENTER_FREQ2, | |
4435 | freq->center_freq2))) | |
4436 | return -ENOBUFS; | |
89b800d7 | 4437 | } else if (freq->ht_enabled) { |
a862e4a3 JM |
4438 | enum nl80211_channel_type ct; |
4439 | ||
1fc4ab23 JM |
4440 | wpa_printf(MSG_DEBUG, " * sec_channel_offset=%d", |
4441 | freq->sec_channel_offset); | |
89b800d7 | 4442 | switch (freq->sec_channel_offset) { |
f019981a | 4443 | case -1: |
a862e4a3 | 4444 | ct = NL80211_CHAN_HT40MINUS; |
f019981a JM |
4445 | break; |
4446 | case 1: | |
a862e4a3 | 4447 | ct = NL80211_CHAN_HT40PLUS; |
f019981a JM |
4448 | break; |
4449 | default: | |
a862e4a3 | 4450 | ct = NL80211_CHAN_HT20; |
f019981a JM |
4451 | break; |
4452 | } | |
a862e4a3 | 4453 | |
1fc4ab23 | 4454 | wpa_printf(MSG_DEBUG, " * channel_type=%d", ct); |
a862e4a3 JM |
4455 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE, ct)) |
4456 | return -ENOBUFS; | |
dda5d9e3 AAL |
4457 | } else if (freq->edmg.channels && freq->edmg.bw_config) { |
4458 | wpa_printf(MSG_DEBUG, | |
4459 | " * EDMG configuration: channels=0x%x bw_config=%d", | |
4460 | freq->edmg.channels, freq->edmg.bw_config); | |
4461 | if (nla_put_u8(msg, NL80211_ATTR_WIPHY_EDMG_CHANNELS, | |
4462 | freq->edmg.channels) || | |
4463 | nla_put_u8(msg, NL80211_ATTR_WIPHY_EDMG_BW_CONFIG, | |
4464 | freq->edmg.bw_config)) | |
4465 | return -1; | |
3388e7b9 MH |
4466 | } else { |
4467 | wpa_printf(MSG_DEBUG, " * channel_type=%d", | |
4468 | NL80211_CHAN_NO_HT); | |
4469 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE, | |
4470 | NL80211_CHAN_NO_HT)) | |
4471 | return -ENOBUFS; | |
f019981a | 4472 | } |
1c4ffa87 | 4473 | return 0; |
1c4ffa87 AO |
4474 | } |
4475 | ||
4476 | ||
e87ef751 PX |
4477 | static int nl80211_set_channel(struct i802_bss *bss, |
4478 | struct hostapd_freq_params *freq, int set_chan) | |
1c4ffa87 AO |
4479 | { |
4480 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
4481 | struct nl_msg *msg; | |
4482 | int ret; | |
4483 | ||
4484 | wpa_printf(MSG_DEBUG, | |
ad9a1bfe JC |
4485 | "nl80211: Set freq %d (ht_enabled=%d, vht_enabled=%d, he_enabled=%d, bandwidth=%d MHz, cf1=%d MHz, cf2=%d MHz)", |
4486 | freq->freq, freq->ht_enabled, freq->vht_enabled, freq->he_enabled, | |
1c4ffa87 | 4487 | freq->bandwidth, freq->center_freq1, freq->center_freq2); |
1c4ffa87 | 4488 | |
9725b784 JM |
4489 | msg = nl80211_drv_msg(drv, 0, set_chan ? NL80211_CMD_SET_CHANNEL : |
4490 | NL80211_CMD_SET_WIPHY); | |
4491 | if (!msg || nl80211_put_freq_params(msg, freq) < 0) { | |
a862e4a3 JM |
4492 | nlmsg_free(msg); |
4493 | return -1; | |
4494 | } | |
1581b38b | 4495 | |
d2440ba0 | 4496 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
e4fb2167 | 4497 | if (ret == 0) { |
89b800d7 | 4498 | bss->freq = freq->freq; |
1581b38b | 4499 | return 0; |
e4fb2167 | 4500 | } |
f019981a | 4501 | wpa_printf(MSG_DEBUG, "nl80211: Failed to set channel (freq=%d): " |
89b800d7 | 4502 | "%d (%s)", freq->freq, ret, strerror(-ret)); |
1581b38b JM |
4503 | return -1; |
4504 | } | |
4505 | ||
0f4e8b4f | 4506 | |
95ab6063 AN |
4507 | static u32 sta_flags_nl80211(int flags) |
4508 | { | |
4509 | u32 f = 0; | |
4510 | ||
4511 | if (flags & WPA_STA_AUTHORIZED) | |
4512 | f |= BIT(NL80211_STA_FLAG_AUTHORIZED); | |
4513 | if (flags & WPA_STA_WMM) | |
4514 | f |= BIT(NL80211_STA_FLAG_WME); | |
4515 | if (flags & WPA_STA_SHORT_PREAMBLE) | |
4516 | f |= BIT(NL80211_STA_FLAG_SHORT_PREAMBLE); | |
4517 | if (flags & WPA_STA_MFP) | |
4518 | f |= BIT(NL80211_STA_FLAG_MFP); | |
45b722f1 AN |
4519 | if (flags & WPA_STA_TDLS_PEER) |
4520 | f |= BIT(NL80211_STA_FLAG_TDLS_PEER); | |
7a228b5c BC |
4521 | if (flags & WPA_STA_AUTHENTICATED) |
4522 | f |= BIT(NL80211_STA_FLAG_AUTHENTICATED); | |
dc55b6b6 AB |
4523 | if (flags & WPA_STA_ASSOCIATED) |
4524 | f |= BIT(NL80211_STA_FLAG_ASSOCIATED); | |
95ab6063 AN |
4525 | |
4526 | return f; | |
4527 | } | |
4528 | ||
4529 | ||
7c7e7877 BC |
4530 | #ifdef CONFIG_MESH |
4531 | static u32 sta_plink_state_nl80211(enum mesh_plink_state state) | |
4532 | { | |
4533 | switch (state) { | |
d02e5498 | 4534 | case PLINK_IDLE: |
7c7e7877 | 4535 | return NL80211_PLINK_LISTEN; |
d02e5498 | 4536 | case PLINK_OPN_SNT: |
7c7e7877 | 4537 | return NL80211_PLINK_OPN_SNT; |
d02e5498 | 4538 | case PLINK_OPN_RCVD: |
7c7e7877 BC |
4539 | return NL80211_PLINK_OPN_RCVD; |
4540 | case PLINK_CNF_RCVD: | |
4541 | return NL80211_PLINK_CNF_RCVD; | |
4542 | case PLINK_ESTAB: | |
4543 | return NL80211_PLINK_ESTAB; | |
4544 | case PLINK_HOLDING: | |
4545 | return NL80211_PLINK_HOLDING; | |
4546 | case PLINK_BLOCKED: | |
4547 | return NL80211_PLINK_BLOCKED; | |
4548 | default: | |
4549 | wpa_printf(MSG_ERROR, "nl80211: Invalid mesh plink state %d", | |
4550 | state); | |
4551 | } | |
4552 | return -1; | |
4553 | } | |
4554 | #endif /* CONFIG_MESH */ | |
4555 | ||
4556 | ||
62847751 | 4557 | static int wpa_driver_nl80211_sta_add(void *priv, |
0f4e8b4f JM |
4558 | struct hostapd_sta_add_params *params) |
4559 | { | |
a2e40bb6 FF |
4560 | struct i802_bss *bss = priv; |
4561 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
8970bae8 | 4562 | struct nl_msg *msg; |
95ab6063 | 4563 | struct nl80211_sta_flag_update upd; |
0f4e8b4f JM |
4564 | int ret = -ENOBUFS; |
4565 | ||
45b722f1 AN |
4566 | if ((params->flags & WPA_STA_TDLS_PEER) && |
4567 | !(drv->capa.flags & WPA_DRIVER_FLAGS_TDLS_SUPPORT)) | |
4568 | return -EOPNOTSUPP; | |
4569 | ||
e4dea253 JM |
4570 | wpa_printf(MSG_DEBUG, "nl80211: %s STA " MACSTR, |
4571 | params->set ? "Set" : "Add", MAC2STR(params->addr)); | |
13f83980 JM |
4572 | msg = nl80211_bss_msg(bss, 0, params->set ? NL80211_CMD_SET_STATION : |
4573 | NL80211_CMD_NEW_STATION); | |
4574 | if (!msg || nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, params->addr)) | |
a862e4a3 | 4575 | goto fail; |
5551bc9c | 4576 | |
dc55b6b6 AB |
4577 | /* |
4578 | * Set the below properties only in one of the following cases: | |
4579 | * 1. New station is added, already associated. | |
4580 | * 2. Set WPA_STA_TDLS_PEER station. | |
4581 | * 3. Set an already added unassociated station, if driver supports | |
4582 | * full AP client state. (Set these properties after station became | |
4583 | * associated will be rejected by the driver). | |
4584 | */ | |
4585 | if (!params->set || (params->flags & WPA_STA_TDLS_PEER) || | |
4586 | (params->set && FULL_AP_CLIENT_STATE_SUPP(drv->capa.flags) && | |
4587 | (params->flags & WPA_STA_ASSOCIATED))) { | |
5551bc9c BC |
4588 | wpa_hexdump(MSG_DEBUG, " * supported rates", |
4589 | params->supp_rates, params->supp_rates_len); | |
a862e4a3 JM |
4590 | wpa_printf(MSG_DEBUG, " * capability=0x%x", |
4591 | params->capability); | |
4592 | if (nla_put(msg, NL80211_ATTR_STA_SUPPORTED_RATES, | |
4593 | params->supp_rates_len, params->supp_rates) || | |
4594 | nla_put_u16(msg, NL80211_ATTR_STA_CAPABILITY, | |
4595 | params->capability)) | |
4596 | goto fail; | |
e503861f JM |
4597 | |
4598 | if (params->ht_capabilities) { | |
4599 | wpa_hexdump(MSG_DEBUG, " * ht_capabilities", | |
4600 | (u8 *) params->ht_capabilities, | |
4601 | sizeof(*params->ht_capabilities)); | |
a862e4a3 JM |
4602 | if (nla_put(msg, NL80211_ATTR_HT_CAPABILITY, |
4603 | sizeof(*params->ht_capabilities), | |
4604 | params->ht_capabilities)) | |
4605 | goto fail; | |
e503861f JM |
4606 | } |
4607 | ||
4608 | if (params->vht_capabilities) { | |
4609 | wpa_hexdump(MSG_DEBUG, " * vht_capabilities", | |
4610 | (u8 *) params->vht_capabilities, | |
4611 | sizeof(*params->vht_capabilities)); | |
a862e4a3 JM |
4612 | if (nla_put(msg, NL80211_ATTR_VHT_CAPABILITY, |
4613 | sizeof(*params->vht_capabilities), | |
4614 | params->vht_capabilities)) | |
4615 | goto fail; | |
e503861f JM |
4616 | } |
4617 | ||
59d9c3a1 JC |
4618 | if (params->he_capab) { |
4619 | wpa_hexdump(MSG_DEBUG, " * he_capab", | |
4620 | params->he_capab, params->he_capab_len); | |
4621 | if (nla_put(msg, NL80211_ATTR_HE_CAPABILITY, | |
4622 | params->he_capab_len, params->he_capab)) | |
4623 | goto fail; | |
4624 | } | |
4625 | ||
e503861f JM |
4626 | if (params->ext_capab) { |
4627 | wpa_hexdump(MSG_DEBUG, " * ext_capab", | |
4628 | params->ext_capab, params->ext_capab_len); | |
a862e4a3 JM |
4629 | if (nla_put(msg, NL80211_ATTR_STA_EXT_CAPABILITY, |
4630 | params->ext_capab_len, params->ext_capab)) | |
4631 | goto fail; | |
e503861f | 4632 | } |
ae33239c AB |
4633 | |
4634 | if (is_ap_interface(drv->nlmode) && | |
4635 | nla_put_u8(msg, NL80211_ATTR_STA_SUPPORT_P2P_PS, | |
4636 | params->support_p2p_ps ? | |
4637 | NL80211_P2P_PS_SUPPORTED : | |
4638 | NL80211_P2P_PS_UNSUPPORTED)) | |
4639 | goto fail; | |
5551bc9c | 4640 | } |
45b722f1 | 4641 | if (!params->set) { |
f11b72c3 JM |
4642 | if (params->aid) { |
4643 | wpa_printf(MSG_DEBUG, " * aid=%u", params->aid); | |
a862e4a3 JM |
4644 | if (nla_put_u16(msg, NL80211_ATTR_STA_AID, params->aid)) |
4645 | goto fail; | |
f11b72c3 JM |
4646 | } else { |
4647 | /* | |
4648 | * cfg80211 validates that AID is non-zero, so we have | |
4649 | * to make this a non-zero value for the TDLS case where | |
dc55b6b6 AB |
4650 | * a dummy STA entry is used for now and for a station |
4651 | * that is still not associated. | |
f11b72c3 | 4652 | */ |
dc55b6b6 AB |
4653 | wpa_printf(MSG_DEBUG, " * aid=1 (%s workaround)", |
4654 | (params->flags & WPA_STA_TDLS_PEER) ? | |
4655 | "TDLS" : "UNASSOC_STA"); | |
a862e4a3 JM |
4656 | if (nla_put_u16(msg, NL80211_ATTR_STA_AID, 1)) |
4657 | goto fail; | |
f11b72c3 | 4658 | } |
e4dea253 JM |
4659 | wpa_printf(MSG_DEBUG, " * listen_interval=%u", |
4660 | params->listen_interval); | |
a862e4a3 JM |
4661 | if (nla_put_u16(msg, NL80211_ATTR_STA_LISTEN_INTERVAL, |
4662 | params->listen_interval)) | |
4663 | goto fail; | |
e112764e JM |
4664 | } else if (params->aid && (params->flags & WPA_STA_TDLS_PEER)) { |
4665 | wpa_printf(MSG_DEBUG, " * peer_aid=%u", params->aid); | |
a862e4a3 JM |
4666 | if (nla_put_u16(msg, NL80211_ATTR_PEER_AID, params->aid)) |
4667 | goto fail; | |
dc55b6b6 AB |
4668 | } else if (FULL_AP_CLIENT_STATE_SUPP(drv->capa.flags) && |
4669 | (params->flags & WPA_STA_ASSOCIATED)) { | |
4670 | wpa_printf(MSG_DEBUG, " * aid=%u", params->aid); | |
4671 | wpa_printf(MSG_DEBUG, " * listen_interval=%u", | |
4672 | params->listen_interval); | |
4673 | if (nla_put_u16(msg, NL80211_ATTR_STA_AID, params->aid) || | |
4674 | nla_put_u16(msg, NL80211_ATTR_STA_LISTEN_INTERVAL, | |
4675 | params->listen_interval)) | |
4676 | goto fail; | |
45b722f1 | 4677 | } |
05a8d422 | 4678 | |
8a458116 MK |
4679 | if (params->vht_opmode_enabled) { |
4680 | wpa_printf(MSG_DEBUG, " * opmode=%u", params->vht_opmode); | |
a862e4a3 JM |
4681 | if (nla_put_u8(msg, NL80211_ATTR_OPMODE_NOTIF, |
4682 | params->vht_opmode)) | |
4683 | goto fail; | |
8a458116 MK |
4684 | } |
4685 | ||
efc64886 SD |
4686 | if (params->supp_channels) { |
4687 | wpa_hexdump(MSG_DEBUG, " * supported channels", | |
4688 | params->supp_channels, params->supp_channels_len); | |
a862e4a3 JM |
4689 | if (nla_put(msg, NL80211_ATTR_STA_SUPPORTED_CHANNELS, |
4690 | params->supp_channels_len, params->supp_channels)) | |
4691 | goto fail; | |
efc64886 SD |
4692 | } |
4693 | ||
4694 | if (params->supp_oper_classes) { | |
4695 | wpa_hexdump(MSG_DEBUG, " * supported operating classes", | |
4696 | params->supp_oper_classes, | |
4697 | params->supp_oper_classes_len); | |
a862e4a3 JM |
4698 | if (nla_put(msg, NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES, |
4699 | params->supp_oper_classes_len, | |
4700 | params->supp_oper_classes)) | |
4701 | goto fail; | |
efc64886 SD |
4702 | } |
4703 | ||
95ab6063 | 4704 | os_memset(&upd, 0, sizeof(upd)); |
7e31703e BC |
4705 | upd.set = sta_flags_nl80211(params->flags); |
4706 | upd.mask = upd.set | sta_flags_nl80211(params->flags_mask); | |
dc55b6b6 AB |
4707 | |
4708 | /* | |
4709 | * If the driver doesn't support full AP client state, ignore ASSOC/AUTH | |
4710 | * flags, as nl80211 driver moves a new station, by default, into | |
4711 | * associated state. | |
4712 | * | |
4713 | * On the other hand, if the driver supports that feature and the | |
4714 | * station is added in unauthenticated state, set the | |
4715 | * authenticated/associated bits in the mask to prevent moving this | |
4716 | * station to associated state before it is actually associated. | |
4717 | * | |
4718 | * This is irrelevant for mesh mode where the station is added to the | |
4719 | * driver as authenticated already, and ASSOCIATED isn't part of the | |
4720 | * nl80211 API. | |
4721 | */ | |
4722 | if (!is_mesh_interface(drv->nlmode)) { | |
4723 | if (!FULL_AP_CLIENT_STATE_SUPP(drv->capa.flags)) { | |
4724 | wpa_printf(MSG_DEBUG, | |
4725 | "nl80211: Ignore ASSOC/AUTH flags since driver doesn't support full AP client state"); | |
4726 | upd.mask &= ~(BIT(NL80211_STA_FLAG_ASSOCIATED) | | |
4727 | BIT(NL80211_STA_FLAG_AUTHENTICATED)); | |
4728 | } else if (!params->set && | |
4729 | !(params->flags & WPA_STA_TDLS_PEER)) { | |
4730 | if (!(params->flags & WPA_STA_AUTHENTICATED)) | |
4731 | upd.mask |= BIT(NL80211_STA_FLAG_AUTHENTICATED); | |
4732 | if (!(params->flags & WPA_STA_ASSOCIATED)) | |
4733 | upd.mask |= BIT(NL80211_STA_FLAG_ASSOCIATED); | |
4734 | } | |
e347cafe MH |
4735 | #ifdef CONFIG_MESH |
4736 | } else { | |
4737 | if (params->plink_state == PLINK_ESTAB && params->peer_aid) { | |
4738 | ret = nla_put_u16(msg, NL80211_ATTR_MESH_PEER_AID, | |
4739 | params->peer_aid); | |
4740 | if (ret) | |
4741 | goto fail; | |
4742 | } | |
4743 | #endif /* CONFIG_MESH */ | |
dc55b6b6 AB |
4744 | } |
4745 | ||
e4dea253 JM |
4746 | wpa_printf(MSG_DEBUG, " * flags set=0x%x mask=0x%x", |
4747 | upd.set, upd.mask); | |
a862e4a3 JM |
4748 | if (nla_put(msg, NL80211_ATTR_STA_FLAGS2, sizeof(upd), &upd)) |
4749 | goto fail; | |
95ab6063 | 4750 | |
7c7e7877 | 4751 | #ifdef CONFIG_MESH |
a862e4a3 JM |
4752 | if (params->plink_state && |
4753 | nla_put_u8(msg, NL80211_ATTR_STA_PLINK_STATE, | |
4754 | sta_plink_state_nl80211(params->plink_state))) | |
4755 | goto fail; | |
7c7e7877 BC |
4756 | #endif /* CONFIG_MESH */ |
4757 | ||
968520da SD |
4758 | if ((!params->set || (params->flags & WPA_STA_TDLS_PEER) || |
4759 | FULL_AP_CLIENT_STATE_SUPP(drv->capa.flags)) && | |
4760 | (params->flags & WPA_STA_WMM)) { | |
8970bae8 JB |
4761 | struct nlattr *wme = nla_nest_start(msg, NL80211_ATTR_STA_WME); |
4762 | ||
e4dea253 | 4763 | wpa_printf(MSG_DEBUG, " * qosinfo=0x%x", params->qosinfo); |
a862e4a3 JM |
4764 | if (!wme || |
4765 | nla_put_u8(msg, NL80211_STA_WME_UAPSD_QUEUES, | |
4766 | params->qosinfo & WMM_QOSINFO_STA_AC_MASK) || | |
4767 | nla_put_u8(msg, NL80211_STA_WME_MAX_SP, | |
4768 | (params->qosinfo >> WMM_QOSINFO_STA_SP_SHIFT) & | |
4769 | WMM_QOSINFO_STA_SP_MASK)) | |
4770 | goto fail; | |
8970bae8 | 4771 | nla_nest_end(msg, wme); |
774bfa62 EP |
4772 | } |
4773 | ||
0f4e8b4f | 4774 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
5883168a | 4775 | msg = NULL; |
0f4e8b4f | 4776 | if (ret) |
45b722f1 AN |
4777 | wpa_printf(MSG_DEBUG, "nl80211: NL80211_CMD_%s_STATION " |
4778 | "result: %d (%s)", params->set ? "SET" : "NEW", ret, | |
4779 | strerror(-ret)); | |
0f4e8b4f JM |
4780 | if (ret == -EEXIST) |
4781 | ret = 0; | |
a862e4a3 | 4782 | fail: |
5883168a | 4783 | nlmsg_free(msg); |
0f4e8b4f JM |
4784 | return ret; |
4785 | } | |
4786 | ||
4787 | ||
97ed9a06 KP |
4788 | static void rtnl_neigh_delete_fdb_entry(struct i802_bss *bss, const u8 *addr) |
4789 | { | |
4790 | #ifdef CONFIG_LIBNL3_ROUTE | |
4791 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
4792 | struct rtnl_neigh *rn; | |
4793 | struct nl_addr *nl_addr; | |
4794 | int err; | |
4795 | ||
4796 | rn = rtnl_neigh_alloc(); | |
4797 | if (!rn) | |
4798 | return; | |
4799 | ||
4800 | rtnl_neigh_set_family(rn, AF_BRIDGE); | |
4801 | rtnl_neigh_set_ifindex(rn, bss->ifindex); | |
4802 | nl_addr = nl_addr_build(AF_BRIDGE, (void *) addr, ETH_ALEN); | |
4803 | if (!nl_addr) { | |
4804 | rtnl_neigh_put(rn); | |
4805 | return; | |
4806 | } | |
4807 | rtnl_neigh_set_lladdr(rn, nl_addr); | |
4808 | ||
4809 | err = rtnl_neigh_delete(drv->rtnl_sk, rn, 0); | |
4810 | if (err < 0) { | |
4811 | wpa_printf(MSG_DEBUG, "nl80211: bridge FDB entry delete for " | |
4812 | MACSTR " ifindex=%d failed: %s", MAC2STR(addr), | |
4813 | bss->ifindex, nl_geterror(err)); | |
4814 | } else { | |
4815 | wpa_printf(MSG_DEBUG, "nl80211: deleted bridge FDB entry for " | |
4816 | MACSTR, MAC2STR(addr)); | |
4817 | } | |
4818 | ||
4819 | nl_addr_put(nl_addr); | |
4820 | rtnl_neigh_put(rn); | |
4821 | #endif /* CONFIG_LIBNL3_ROUTE */ | |
4822 | } | |
4823 | ||
4824 | ||
59d7148a JM |
4825 | static int wpa_driver_nl80211_sta_remove(struct i802_bss *bss, const u8 *addr, |
4826 | int deauth, u16 reason_code) | |
0f4e8b4f | 4827 | { |
a2e40bb6 | 4828 | struct wpa_driver_nl80211_data *drv = bss->drv; |
0f4e8b4f JM |
4829 | struct nl_msg *msg; |
4830 | int ret; | |
4831 | ||
13f83980 | 4832 | if (!(msg = nl80211_bss_msg(bss, 0, NL80211_CMD_DEL_STATION)) || |
a862e4a3 JM |
4833 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) || |
4834 | (deauth == 0 && | |
4835 | nla_put_u8(msg, NL80211_ATTR_MGMT_SUBTYPE, | |
4836 | WLAN_FC_STYPE_DISASSOC)) || | |
4837 | (deauth == 1 && | |
4838 | nla_put_u8(msg, NL80211_ATTR_MGMT_SUBTYPE, | |
4839 | WLAN_FC_STYPE_DEAUTH)) || | |
4840 | (reason_code && | |
4841 | nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason_code))) { | |
4842 | nlmsg_free(msg); | |
4843 | return -ENOBUFS; | |
4844 | } | |
0f4e8b4f JM |
4845 | |
4846 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); | |
83e7bb0e JM |
4847 | wpa_printf(MSG_DEBUG, "nl80211: sta_remove -> DEL_STATION %s " MACSTR |
4848 | " --> %d (%s)", | |
4849 | bss->ifname, MAC2STR(addr), ret, strerror(-ret)); | |
97ed9a06 KP |
4850 | |
4851 | if (drv->rtnl_sk) | |
4852 | rtnl_neigh_delete_fdb_entry(bss, addr); | |
4853 | ||
0f4e8b4f JM |
4854 | if (ret == -ENOENT) |
4855 | return 0; | |
4856 | return ret; | |
0f4e8b4f JM |
4857 | } |
4858 | ||
1581b38b | 4859 | |
f3407c66 | 4860 | void nl80211_remove_iface(struct wpa_driver_nl80211_data *drv, int ifidx) |
0915d02c JM |
4861 | { |
4862 | struct nl_msg *msg; | |
de884303 | 4863 | struct wpa_driver_nl80211_data *drv2; |
0915d02c | 4864 | |
c6e8e8e4 JM |
4865 | wpa_printf(MSG_DEBUG, "nl80211: Remove interface ifindex=%d", ifidx); |
4866 | ||
2135f224 | 4867 | /* stop listening for EAPOL on this interface */ |
de884303 JM |
4868 | dl_list_for_each(drv2, &drv->global->interfaces, |
4869 | struct wpa_driver_nl80211_data, list) | |
732b1d20 MB |
4870 | { |
4871 | del_ifidx(drv2, ifidx, IFIDX_ANY); | |
4872 | /* Remove all bridges learned for this iface */ | |
4873 | del_ifidx(drv2, IFIDX_ANY, ifidx); | |
4874 | } | |
2135f224 | 4875 | |
95376e1a | 4876 | msg = nl80211_ifindex_msg(drv, ifidx, 0, NL80211_CMD_DEL_INTERFACE); |
0915d02c JM |
4877 | if (send_and_recv_msgs(drv, msg, NULL, NULL) == 0) |
4878 | return; | |
e748062b | 4879 | wpa_printf(MSG_ERROR, "Failed to remove interface (ifidx=%d)", ifidx); |
0915d02c JM |
4880 | } |
4881 | ||
4882 | ||
cc9a2575 | 4883 | const char * nl80211_iftype_str(enum nl80211_iftype mode) |
a1922f93 JM |
4884 | { |
4885 | switch (mode) { | |
4886 | case NL80211_IFTYPE_ADHOC: | |
4887 | return "ADHOC"; | |
4888 | case NL80211_IFTYPE_STATION: | |
4889 | return "STATION"; | |
4890 | case NL80211_IFTYPE_AP: | |
4891 | return "AP"; | |
1045ec36 JM |
4892 | case NL80211_IFTYPE_AP_VLAN: |
4893 | return "AP_VLAN"; | |
4894 | case NL80211_IFTYPE_WDS: | |
4895 | return "WDS"; | |
a1922f93 JM |
4896 | case NL80211_IFTYPE_MONITOR: |
4897 | return "MONITOR"; | |
1045ec36 JM |
4898 | case NL80211_IFTYPE_MESH_POINT: |
4899 | return "MESH_POINT"; | |
a1922f93 JM |
4900 | case NL80211_IFTYPE_P2P_CLIENT: |
4901 | return "P2P_CLIENT"; | |
4902 | case NL80211_IFTYPE_P2P_GO: | |
4903 | return "P2P_GO"; | |
7aad838c NS |
4904 | case NL80211_IFTYPE_P2P_DEVICE: |
4905 | return "P2P_DEVICE"; | |
a1922f93 JM |
4906 | default: |
4907 | return "unknown"; | |
4908 | } | |
4909 | } | |
4910 | ||
4911 | ||
a35187e7 KH |
4912 | static int nl80211_create_iface_once(struct wpa_driver_nl80211_data *drv, |
4913 | const char *ifname, | |
4914 | enum nl80211_iftype iftype, | |
d6dcfcda DS |
4915 | const u8 *addr, int wds, |
4916 | int (*handler)(struct nl_msg *, void *), | |
4917 | void *arg) | |
0915d02c | 4918 | { |
8970bae8 | 4919 | struct nl_msg *msg; |
0915d02c JM |
4920 | int ifidx; |
4921 | int ret = -ENOBUFS; | |
4922 | ||
a1922f93 JM |
4923 | wpa_printf(MSG_DEBUG, "nl80211: Create interface iftype %d (%s)", |
4924 | iftype, nl80211_iftype_str(iftype)); | |
4925 | ||
56f77852 JM |
4926 | msg = nl80211_cmd_msg(drv->first_bss, 0, NL80211_CMD_NEW_INTERFACE); |
4927 | if (!msg || | |
a862e4a3 JM |
4928 | nla_put_string(msg, NL80211_ATTR_IFNAME, ifname) || |
4929 | nla_put_u32(msg, NL80211_ATTR_IFTYPE, iftype)) | |
4930 | goto fail; | |
0915d02c JM |
4931 | |
4932 | if (iftype == NL80211_IFTYPE_MONITOR) { | |
8970bae8 | 4933 | struct nlattr *flags; |
0915d02c | 4934 | |
8970bae8 | 4935 | flags = nla_nest_start(msg, NL80211_ATTR_MNTR_FLAGS); |
a862e4a3 JM |
4936 | if (!flags || |
4937 | nla_put_flag(msg, NL80211_MNTR_FLAG_COOK_FRAMES)) | |
4938 | goto fail; | |
0915d02c | 4939 | |
8970bae8 | 4940 | nla_nest_end(msg, flags); |
fbbfcbac | 4941 | } else if (wds) { |
a862e4a3 JM |
4942 | if (nla_put_u8(msg, NL80211_ATTR_4ADDR, wds)) |
4943 | goto fail; | |
0915d02c JM |
4944 | } |
4945 | ||
52f5877a IP |
4946 | /* |
4947 | * Tell cfg80211 that the interface belongs to the socket that created | |
4948 | * it, and the interface should be deleted when the socket is closed. | |
4949 | */ | |
a862e4a3 JM |
4950 | if (nla_put_flag(msg, NL80211_ATTR_IFACE_SOCKET_OWNER)) |
4951 | goto fail; | |
52f5877a | 4952 | |
d6dcfcda | 4953 | ret = send_and_recv_msgs(drv, msg, handler, arg); |
5883168a | 4954 | msg = NULL; |
0915d02c | 4955 | if (ret) { |
a862e4a3 | 4956 | fail: |
5883168a | 4957 | nlmsg_free(msg); |
a35187e7 KH |
4958 | wpa_printf(MSG_ERROR, "Failed to create interface %s: %d (%s)", |
4959 | ifname, ret, strerror(-ret)); | |
0915d02c JM |
4960 | return ret; |
4961 | } | |
4962 | ||
f632e483 | 4963 | if (iftype == NL80211_IFTYPE_P2P_DEVICE) |
6bae92e0 | 4964 | return 0; |
6bae92e0 | 4965 | |
0915d02c | 4966 | ifidx = if_nametoindex(ifname); |
c6e8e8e4 JM |
4967 | wpa_printf(MSG_DEBUG, "nl80211: New interface %s created: ifindex=%d", |
4968 | ifname, ifidx); | |
0915d02c JM |
4969 | |
4970 | if (ifidx <= 0) | |
4971 | return -1; | |
4972 | ||
147848ec JM |
4973 | /* |
4974 | * Some virtual interfaces need to process EAPOL packets and events on | |
4975 | * the parent interface. This is used mainly with hostapd. | |
4976 | */ | |
4977 | if (drv->hostapd || | |
4978 | iftype == NL80211_IFTYPE_AP_VLAN || | |
4979 | iftype == NL80211_IFTYPE_WDS || | |
4980 | iftype == NL80211_IFTYPE_MONITOR) { | |
4981 | /* start listening for EAPOL on this interface */ | |
732b1d20 | 4982 | add_ifidx(drv, ifidx, IFIDX_ANY); |
147848ec | 4983 | } |
2135f224 | 4984 | |
7bfc47c3 | 4985 | if (addr && iftype != NL80211_IFTYPE_MONITOR && |
c81eff1a | 4986 | linux_set_ifhwaddr(drv->global->ioctl_sock, ifname, addr)) { |
41d931ee JM |
4987 | nl80211_remove_iface(drv, ifidx); |
4988 | return -1; | |
2135f224 | 4989 | } |
2135f224 | 4990 | |
0915d02c JM |
4991 | return ifidx; |
4992 | } | |
22a7c9d7 JM |
4993 | |
4994 | ||
f3407c66 JM |
4995 | int nl80211_create_iface(struct wpa_driver_nl80211_data *drv, |
4996 | const char *ifname, enum nl80211_iftype iftype, | |
4997 | const u8 *addr, int wds, | |
4998 | int (*handler)(struct nl_msg *, void *), | |
4999 | void *arg, int use_existing) | |
a35187e7 KH |
5000 | { |
5001 | int ret; | |
5002 | ||
d6dcfcda DS |
5003 | ret = nl80211_create_iface_once(drv, ifname, iftype, addr, wds, handler, |
5004 | arg); | |
a35187e7 | 5005 | |
ffbf1eaa | 5006 | /* if error occurred and interface exists already */ |
a35187e7 | 5007 | if (ret == -ENFILE && if_nametoindex(ifname)) { |
2aec4f3c JM |
5008 | if (use_existing) { |
5009 | wpa_printf(MSG_DEBUG, "nl80211: Continue using existing interface %s", | |
5010 | ifname); | |
6997f8ba JM |
5011 | if (addr && iftype != NL80211_IFTYPE_MONITOR && |
5012 | linux_set_ifhwaddr(drv->global->ioctl_sock, ifname, | |
5013 | addr) < 0 && | |
5014 | (linux_set_iface_flags(drv->global->ioctl_sock, | |
5015 | ifname, 0) < 0 || | |
5016 | linux_set_ifhwaddr(drv->global->ioctl_sock, ifname, | |
5017 | addr) < 0 || | |
5018 | linux_set_iface_flags(drv->global->ioctl_sock, | |
5019 | ifname, 1) < 0)) | |
5020 | return -1; | |
2aec4f3c JM |
5021 | return -ENFILE; |
5022 | } | |
a35187e7 KH |
5023 | wpa_printf(MSG_INFO, "Try to remove and re-create %s", ifname); |
5024 | ||
5025 | /* Try to remove the interface that was already there. */ | |
5026 | nl80211_remove_iface(drv, if_nametoindex(ifname)); | |
5027 | ||
5028 | /* Try to create the interface again */ | |
fbbfcbac | 5029 | ret = nl80211_create_iface_once(drv, ifname, iftype, addr, |
d6dcfcda | 5030 | wds, handler, arg); |
a35187e7 KH |
5031 | } |
5032 | ||
3e208481 JM |
5033 | if (ret >= 0 && is_p2p_net_interface(iftype)) { |
5034 | wpa_printf(MSG_DEBUG, | |
5035 | "nl80211: Interface %s created for P2P - disable 11b rates", | |
5036 | ifname); | |
4e5cb1a3 | 5037 | nl80211_disable_11b_rates(drv, ret, 1); |
3e208481 | 5038 | } |
4e5cb1a3 | 5039 | |
a35187e7 KH |
5040 | return ret; |
5041 | } | |
0915d02c | 5042 | |
2135f224 | 5043 | |
3fd1cefb JB |
5044 | static int nl80211_setup_ap(struct i802_bss *bss) |
5045 | { | |
5046 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
5047 | ||
748c0ac0 JM |
5048 | wpa_printf(MSG_DEBUG, "nl80211: Setup AP(%s) - device_ap_sme=%d use_monitor=%d", |
5049 | bss->ifname, drv->device_ap_sme, drv->use_monitor); | |
36488c05 | 5050 | |
a11241fa JB |
5051 | /* |
5052 | * Disable Probe Request reporting unless we need it in this way for | |
5053 | * devices that include the AP SME, in the other case (unless using | |
5054 | * monitor iface) we'll get it through the nl_mgmt socket instead. | |
5055 | */ | |
5056 | if (!drv->device_ap_sme) | |
5057 | wpa_driver_nl80211_probe_req_report(bss, 0); | |
5058 | ||
5059 | if (!drv->device_ap_sme && !drv->use_monitor) | |
5060 | if (nl80211_mgmt_subscribe_ap(bss)) | |
5061 | return -1; | |
5062 | ||
a6cc0602 JM |
5063 | if (drv->device_ap_sme && !drv->use_monitor) |
5064 | if (nl80211_mgmt_subscribe_ap_dev_sme(bss)) | |
f4830bed RM |
5065 | wpa_printf(MSG_DEBUG, |
5066 | "nl80211: Failed to subscribe for mgmt frames from SME driver - trying to run without it"); | |
a6cc0602 | 5067 | |
a11241fa | 5068 | if (!drv->device_ap_sme && drv->use_monitor && |
ea19b39f RM |
5069 | nl80211_create_monitor_interface(drv) && |
5070 | !drv->device_ap_sme) | |
3fd1cefb JB |
5071 | return -1; |
5072 | ||
5073 | if (drv->device_ap_sme && | |
5074 | wpa_driver_nl80211_probe_req_report(bss, 1) < 0) { | |
5075 | wpa_printf(MSG_DEBUG, "nl80211: Failed to enable " | |
5076 | "Probe Request frame reporting in AP mode"); | |
5077 | /* Try to survive without this */ | |
5078 | } | |
5079 | ||
5080 | return 0; | |
5081 | } | |
5082 | ||
5083 | ||
5084 | static void nl80211_teardown_ap(struct i802_bss *bss) | |
5085 | { | |
5086 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
5087 | ||
748c0ac0 JM |
5088 | wpa_printf(MSG_DEBUG, "nl80211: Teardown AP(%s) - device_ap_sme=%d use_monitor=%d", |
5089 | bss->ifname, drv->device_ap_sme, drv->use_monitor); | |
a6cc0602 | 5090 | if (drv->device_ap_sme) { |
3fd1cefb | 5091 | wpa_driver_nl80211_probe_req_report(bss, 0); |
a6cc0602 JM |
5092 | if (!drv->use_monitor) |
5093 | nl80211_mgmt_unsubscribe(bss, "AP teardown (dev SME)"); | |
5094 | } else if (drv->use_monitor) | |
3fd1cefb | 5095 | nl80211_remove_monitor_interface(drv); |
a11241fa | 5096 | else |
36488c05 | 5097 | nl80211_mgmt_unsubscribe(bss, "AP teardown"); |
a11241fa | 5098 | |
a70cd0db | 5099 | nl80211_put_wiphy_data_ap(bss); |
3fd1cefb JB |
5100 | bss->beacon_set = 0; |
5101 | } | |
5102 | ||
5103 | ||
f10bfc9a JM |
5104 | static int nl80211_send_eapol_data(struct i802_bss *bss, |
5105 | const u8 *addr, const u8 *data, | |
d12dab4c | 5106 | size_t data_len) |
f10bfc9a | 5107 | { |
d12dab4c JB |
5108 | struct sockaddr_ll ll; |
5109 | int ret; | |
5110 | ||
5111 | if (bss->drv->eapol_tx_sock < 0) { | |
5112 | wpa_printf(MSG_DEBUG, "nl80211: No socket to send EAPOL"); | |
f10bfc9a JM |
5113 | return -1; |
5114 | } | |
5115 | ||
d12dab4c JB |
5116 | os_memset(&ll, 0, sizeof(ll)); |
5117 | ll.sll_family = AF_PACKET; | |
5118 | ll.sll_ifindex = bss->ifindex; | |
5119 | ll.sll_protocol = htons(ETH_P_PAE); | |
5120 | ll.sll_halen = ETH_ALEN; | |
5121 | os_memcpy(ll.sll_addr, addr, ETH_ALEN); | |
5122 | ret = sendto(bss->drv->eapol_tx_sock, data, data_len, 0, | |
5123 | (struct sockaddr *) &ll, sizeof(ll)); | |
5124 | if (ret < 0) | |
5125 | wpa_printf(MSG_ERROR, "nl80211: EAPOL TX: %s", | |
5126 | strerror(errno)); | |
5127 | ||
5128 | return ret; | |
f10bfc9a | 5129 | } |
5fb1a232 | 5130 | |
f10bfc9a | 5131 | |
db149ac9 JM |
5132 | static const u8 rfc1042_header[6] = { 0xaa, 0xaa, 0x03, 0x00, 0x00, 0x00 }; |
5133 | ||
5134 | static int wpa_driver_nl80211_hapd_send_eapol( | |
5135 | void *priv, const u8 *addr, const u8 *data, | |
4378fc14 | 5136 | size_t data_len, int encrypt, const u8 *own_addr, u32 flags) |
db149ac9 | 5137 | { |
a2e40bb6 FF |
5138 | struct i802_bss *bss = priv; |
5139 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
db149ac9 JM |
5140 | struct ieee80211_hdr *hdr; |
5141 | size_t len; | |
5142 | u8 *pos; | |
5143 | int res; | |
4378fc14 | 5144 | int qos = flags & WPA_STA_WMM; |
db149ac9 | 5145 | |
a11241fa | 5146 | if (drv->device_ap_sme || !drv->use_monitor) |
d12dab4c | 5147 | return nl80211_send_eapol_data(bss, addr, data, data_len); |
f10bfc9a | 5148 | |
db149ac9 JM |
5149 | len = sizeof(*hdr) + (qos ? 2 : 0) + sizeof(rfc1042_header) + 2 + |
5150 | data_len; | |
5151 | hdr = os_zalloc(len); | |
5152 | if (hdr == NULL) { | |
7ac3616d JM |
5153 | wpa_printf(MSG_INFO, "nl80211: Failed to allocate EAPOL buffer(len=%lu)", |
5154 | (unsigned long) len); | |
db149ac9 JM |
5155 | return -1; |
5156 | } | |
5157 | ||
5158 | hdr->frame_control = | |
5159 | IEEE80211_FC(WLAN_FC_TYPE_DATA, WLAN_FC_STYPE_DATA); | |
5160 | hdr->frame_control |= host_to_le16(WLAN_FC_FROMDS); | |
5161 | if (encrypt) | |
5162 | hdr->frame_control |= host_to_le16(WLAN_FC_ISWEP); | |
db149ac9 JM |
5163 | if (qos) { |
5164 | hdr->frame_control |= | |
5165 | host_to_le16(WLAN_FC_STYPE_QOS_DATA << 4); | |
5166 | } | |
db149ac9 JM |
5167 | |
5168 | memcpy(hdr->IEEE80211_DA_FROMDS, addr, ETH_ALEN); | |
5169 | memcpy(hdr->IEEE80211_BSSID_FROMDS, own_addr, ETH_ALEN); | |
5170 | memcpy(hdr->IEEE80211_SA_FROMDS, own_addr, ETH_ALEN); | |
5171 | pos = (u8 *) (hdr + 1); | |
5172 | ||
db149ac9 | 5173 | if (qos) { |
92d521d8 FF |
5174 | /* Set highest priority in QoS header */ |
5175 | pos[0] = 7; | |
db149ac9 JM |
5176 | pos[1] = 0; |
5177 | pos += 2; | |
5178 | } | |
db149ac9 JM |
5179 | |
5180 | memcpy(pos, rfc1042_header, sizeof(rfc1042_header)); | |
5181 | pos += sizeof(rfc1042_header); | |
5182 | WPA_PUT_BE16(pos, ETH_P_PAE); | |
5183 | pos += 2; | |
5184 | memcpy(pos, data, data_len); | |
5185 | ||
55231068 | 5186 | res = wpa_driver_nl80211_send_frame(bss, (u8 *) hdr, len, encrypt, 0, |
2d3943ce | 5187 | 0, 0, 0, 0, NULL, 0); |
db149ac9 JM |
5188 | if (res < 0) { |
5189 | wpa_printf(MSG_ERROR, "i802_send_eapol - packet len: %lu - " | |
5190 | "failed: %d (%s)", | |
5191 | (unsigned long) len, errno, strerror(errno)); | |
5192 | } | |
7bf12757 | 5193 | os_free(hdr); |
db149ac9 JM |
5194 | |
5195 | return res; | |
5196 | } | |
5197 | ||
a8d6ffa4 | 5198 | |
3234cba4 | 5199 | static int wpa_driver_nl80211_sta_set_flags(void *priv, const u8 *addr, |
f97e3ce4 JM |
5200 | unsigned int total_flags, |
5201 | unsigned int flags_or, | |
5202 | unsigned int flags_and) | |
a8d6ffa4 | 5203 | { |
a2e40bb6 | 5204 | struct i802_bss *bss = priv; |
8970bae8 JB |
5205 | struct nl_msg *msg; |
5206 | struct nlattr *flags; | |
7e76ee9c | 5207 | struct nl80211_sta_flag_update upd; |
a8d6ffa4 | 5208 | |
0cd9846c JM |
5209 | wpa_printf(MSG_DEBUG, "nl80211: Set STA flags - ifname=%s addr=" MACSTR |
5210 | " total_flags=0x%x flags_or=0x%x flags_and=0x%x authorized=%d", | |
5211 | bss->ifname, MAC2STR(addr), total_flags, flags_or, flags_and, | |
5212 | !!(total_flags & WPA_STA_AUTHORIZED)); | |
5213 | ||
13f83980 | 5214 | if (!(msg = nl80211_bss_msg(bss, 0, NL80211_CMD_SET_STATION)) || |
a862e4a3 JM |
5215 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) |
5216 | goto fail; | |
a8d6ffa4 | 5217 | |
7e76ee9c JM |
5218 | /* |
5219 | * Backwards compatibility version using NL80211_ATTR_STA_FLAGS. This | |
5220 | * can be removed eventually. | |
5221 | */ | |
8970bae8 | 5222 | flags = nla_nest_start(msg, NL80211_ATTR_STA_FLAGS); |
a862e4a3 JM |
5223 | if (!flags || |
5224 | ((total_flags & WPA_STA_AUTHORIZED) && | |
5225 | nla_put_flag(msg, NL80211_STA_FLAG_AUTHORIZED)) || | |
5226 | ((total_flags & WPA_STA_WMM) && | |
5227 | nla_put_flag(msg, NL80211_STA_FLAG_WME)) || | |
5228 | ((total_flags & WPA_STA_SHORT_PREAMBLE) && | |
5229 | nla_put_flag(msg, NL80211_STA_FLAG_SHORT_PREAMBLE)) || | |
5230 | ((total_flags & WPA_STA_MFP) && | |
5231 | nla_put_flag(msg, NL80211_STA_FLAG_MFP)) || | |
5232 | ((total_flags & WPA_STA_TDLS_PEER) && | |
5233 | nla_put_flag(msg, NL80211_STA_FLAG_TDLS_PEER))) | |
5234 | goto fail; | |
45b722f1 | 5235 | |
8970bae8 | 5236 | nla_nest_end(msg, flags); |
a8d6ffa4 | 5237 | |
7e76ee9c JM |
5238 | os_memset(&upd, 0, sizeof(upd)); |
5239 | upd.mask = sta_flags_nl80211(flags_or | ~flags_and); | |
5240 | upd.set = sta_flags_nl80211(flags_or); | |
a862e4a3 JM |
5241 | if (nla_put(msg, NL80211_ATTR_STA_FLAGS2, sizeof(upd), &upd)) |
5242 | goto fail; | |
7e76ee9c | 5243 | |
13f83980 | 5244 | return send_and_recv_msgs(bss->drv, msg, NULL, NULL); |
a862e4a3 | 5245 | fail: |
5883168a | 5246 | nlmsg_free(msg); |
a8d6ffa4 JM |
5247 | return -ENOBUFS; |
5248 | } | |
5249 | ||
0915d02c | 5250 | |
6720b948 THJ |
5251 | static int driver_nl80211_sta_set_airtime_weight(void *priv, const u8 *addr, |
5252 | unsigned int weight) | |
5253 | { | |
5254 | struct i802_bss *bss = priv; | |
5255 | struct nl_msg *msg; | |
5256 | ||
5257 | wpa_printf(MSG_DEBUG, | |
5258 | "nl80211: Set STA airtime weight - ifname=%s addr=" MACSTR | |
5259 | " weight=%u", bss->ifname, MAC2STR(addr), weight); | |
5260 | ||
5261 | if (!(msg = nl80211_bss_msg(bss, 0, NL80211_CMD_SET_STATION)) || | |
5262 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) || | |
5263 | nla_put_u16(msg, NL80211_ATTR_AIRTIME_WEIGHT, weight)) | |
5264 | goto fail; | |
5265 | ||
5266 | return send_and_recv_msgs(bss->drv, msg, NULL, NULL); | |
5267 | fail: | |
5268 | nlmsg_free(msg); | |
5269 | return -ENOBUFS; | |
5270 | } | |
5271 | ||
5272 | ||
1581b38b JM |
5273 | static int wpa_driver_nl80211_ap(struct wpa_driver_nl80211_data *drv, |
5274 | struct wpa_driver_associate_params *params) | |
5275 | { | |
708bc8e0 | 5276 | enum nl80211_iftype nlmode, old_mode; |
b1f625e0 EP |
5277 | |
5278 | if (params->p2p) { | |
046b26a2 JM |
5279 | wpa_printf(MSG_DEBUG, "nl80211: Setup AP operations for P2P " |
5280 | "group (GO)"); | |
b1f625e0 EP |
5281 | nlmode = NL80211_IFTYPE_P2P_GO; |
5282 | } else | |
5283 | nlmode = NL80211_IFTYPE_AP; | |
5284 | ||
708bc8e0 | 5285 | old_mode = drv->nlmode; |
834ee56f | 5286 | if (wpa_driver_nl80211_set_mode(drv->first_bss, nlmode)) { |
708bc8e0 JM |
5287 | nl80211_remove_monitor_interface(drv); |
5288 | return -1; | |
5289 | } | |
5290 | ||
6e9023ea JM |
5291 | if (params->freq.freq && |
5292 | nl80211_set_channel(drv->first_bss, ¶ms->freq, 0)) { | |
708bc8e0 | 5293 | if (old_mode != nlmode) |
834ee56f | 5294 | wpa_driver_nl80211_set_mode(drv->first_bss, old_mode); |
460456f8 | 5295 | nl80211_remove_monitor_interface(drv); |
1581b38b | 5296 | return -1; |
0915d02c | 5297 | } |
1581b38b | 5298 | |
1581b38b JM |
5299 | return 0; |
5300 | } | |
1581b38b JM |
5301 | |
5302 | ||
666e508c JM |
5303 | static int nl80211_leave_ibss(struct wpa_driver_nl80211_data *drv, |
5304 | int reset_mode) | |
5cc4d64b JM |
5305 | { |
5306 | struct nl_msg *msg; | |
9725b784 | 5307 | int ret; |
a862e4a3 | 5308 | |
9725b784 | 5309 | msg = nl80211_drv_msg(drv, 0, NL80211_CMD_LEAVE_IBSS); |
5cc4d64b | 5310 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
5cc4d64b JM |
5311 | if (ret) { |
5312 | wpa_printf(MSG_DEBUG, "nl80211: Leave IBSS failed: ret=%d " | |
5313 | "(%s)", ret, strerror(-ret)); | |
9725b784 JM |
5314 | } else { |
5315 | wpa_printf(MSG_DEBUG, | |
5316 | "nl80211: Leave IBSS request sent successfully"); | |
5cc4d64b JM |
5317 | } |
5318 | ||
666e508c JM |
5319 | if (reset_mode && |
5320 | wpa_driver_nl80211_set_mode(drv->first_bss, | |
5d4c78fb JM |
5321 | NL80211_IFTYPE_STATION)) { |
5322 | wpa_printf(MSG_INFO, "nl80211: Failed to set interface into " | |
5323 | "station mode"); | |
5324 | } | |
5325 | ||
5cc4d64b JM |
5326 | return ret; |
5327 | } | |
5328 | ||
5329 | ||
95ff3069 JD |
5330 | static int nl80211_ht_vht_overrides(struct nl_msg *msg, |
5331 | struct wpa_driver_associate_params *params) | |
5332 | { | |
5333 | if (params->disable_ht && nla_put_flag(msg, NL80211_ATTR_DISABLE_HT)) | |
5334 | return -1; | |
5335 | ||
5336 | if (params->htcaps && params->htcaps_mask) { | |
5337 | int sz = sizeof(struct ieee80211_ht_capabilities); | |
5338 | wpa_hexdump(MSG_DEBUG, " * htcaps", params->htcaps, sz); | |
5339 | wpa_hexdump(MSG_DEBUG, " * htcaps_mask", | |
5340 | params->htcaps_mask, sz); | |
5341 | if (nla_put(msg, NL80211_ATTR_HT_CAPABILITY, sz, | |
5342 | params->htcaps) || | |
5343 | nla_put(msg, NL80211_ATTR_HT_CAPABILITY_MASK, sz, | |
5344 | params->htcaps_mask)) | |
5345 | return -1; | |
5346 | } | |
5347 | ||
5348 | #ifdef CONFIG_VHT_OVERRIDES | |
5349 | if (params->disable_vht) { | |
5350 | wpa_printf(MSG_DEBUG, " * VHT disabled"); | |
5351 | if (nla_put_flag(msg, NL80211_ATTR_DISABLE_VHT)) | |
5352 | return -1; | |
5353 | } | |
5354 | ||
5355 | if (params->vhtcaps && params->vhtcaps_mask) { | |
5356 | int sz = sizeof(struct ieee80211_vht_capabilities); | |
5357 | wpa_hexdump(MSG_DEBUG, " * vhtcaps", params->vhtcaps, sz); | |
5358 | wpa_hexdump(MSG_DEBUG, " * vhtcaps_mask", | |
5359 | params->vhtcaps_mask, sz); | |
5360 | if (nla_put(msg, NL80211_ATTR_VHT_CAPABILITY, sz, | |
5361 | params->vhtcaps) || | |
5362 | nla_put(msg, NL80211_ATTR_VHT_CAPABILITY_MASK, sz, | |
5363 | params->vhtcaps_mask)) | |
5364 | return -1; | |
5365 | } | |
5366 | #endif /* CONFIG_VHT_OVERRIDES */ | |
5367 | ||
5368 | return 0; | |
5369 | } | |
5370 | ||
5371 | ||
5cc4d64b JM |
5372 | static int wpa_driver_nl80211_ibss(struct wpa_driver_nl80211_data *drv, |
5373 | struct wpa_driver_associate_params *params) | |
5374 | { | |
5375 | struct nl_msg *msg; | |
5376 | int ret = -1; | |
5377 | int count = 0; | |
5378 | ||
5379 | wpa_printf(MSG_DEBUG, "nl80211: Join IBSS (ifindex=%d)", drv->ifindex); | |
5380 | ||
4ec68377 | 5381 | if (wpa_driver_nl80211_set_mode_ibss(drv->first_bss, ¶ms->freq)) { |
5cc4d64b JM |
5382 | wpa_printf(MSG_INFO, "nl80211: Failed to set interface into " |
5383 | "IBSS mode"); | |
5384 | return -1; | |
5385 | } | |
5386 | ||
5387 | retry: | |
9725b784 | 5388 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_JOIN_IBSS)) || |
a862e4a3 JM |
5389 | params->ssid == NULL || params->ssid_len > sizeof(drv->ssid)) |
5390 | goto fail; | |
5cc4d64b | 5391 | |
21cd8f83 JM |
5392 | wpa_printf(MSG_DEBUG, " * SSID=%s", |
5393 | wpa_ssid_txt(params->ssid, params->ssid_len)); | |
a862e4a3 JM |
5394 | if (nla_put(msg, NL80211_ATTR_SSID, params->ssid_len, params->ssid)) |
5395 | goto fail; | |
5cc4d64b JM |
5396 | os_memcpy(drv->ssid, params->ssid, params->ssid_len); |
5397 | drv->ssid_len = params->ssid_len; | |
5398 | ||
85e1fad8 JM |
5399 | if (nl80211_put_freq_params(msg, ¶ms->freq) < 0 || |
5400 | nl80211_put_beacon_int(msg, params->beacon_int)) | |
a862e4a3 | 5401 | goto fail; |
5cc4d64b JM |
5402 | |
5403 | ret = nl80211_set_conn_keys(params, msg); | |
5404 | if (ret) | |
a862e4a3 | 5405 | goto fail; |
5cc4d64b | 5406 | |
913e3cf7 NC |
5407 | if (params->bssid && params->fixed_bssid) { |
5408 | wpa_printf(MSG_DEBUG, " * BSSID=" MACSTR, | |
5409 | MAC2STR(params->bssid)); | |
a862e4a3 JM |
5410 | if (nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, params->bssid)) |
5411 | goto fail; | |
913e3cf7 NC |
5412 | } |
5413 | ||
4d9e6fba JD |
5414 | if (params->fixed_freq) { |
5415 | wpa_printf(MSG_DEBUG, " * fixed_freq"); | |
5416 | if (nla_put_flag(msg, NL80211_ATTR_FREQ_FIXED)) | |
5417 | goto fail; | |
5418 | } | |
5419 | ||
4848a38d JM |
5420 | if (params->key_mgmt_suite == WPA_KEY_MGMT_IEEE8021X || |
5421 | params->key_mgmt_suite == WPA_KEY_MGMT_PSK || | |
5422 | params->key_mgmt_suite == WPA_KEY_MGMT_IEEE8021X_SHA256 || | |
5423 | params->key_mgmt_suite == WPA_KEY_MGMT_PSK_SHA256) { | |
e640888c | 5424 | wpa_printf(MSG_DEBUG, " * control port"); |
a862e4a3 JM |
5425 | if (nla_put_flag(msg, NL80211_ATTR_CONTROL_PORT)) |
5426 | goto fail; | |
e640888c AQ |
5427 | } |
5428 | ||
a95795ad JM |
5429 | if (params->wpa_ie) { |
5430 | wpa_hexdump(MSG_DEBUG, | |
5431 | " * Extra IEs for Beacon/Probe Response frames", | |
5432 | params->wpa_ie, params->wpa_ie_len); | |
a862e4a3 JM |
5433 | if (nla_put(msg, NL80211_ATTR_IE, params->wpa_ie_len, |
5434 | params->wpa_ie)) | |
5435 | goto fail; | |
a95795ad JM |
5436 | } |
5437 | ||
e15dcf6d PK |
5438 | ret = nl80211_ht_vht_overrides(msg, params); |
5439 | if (ret < 0) | |
5440 | goto fail; | |
95ff3069 | 5441 | |
5cc4d64b JM |
5442 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
5443 | msg = NULL; | |
5444 | if (ret) { | |
5445 | wpa_printf(MSG_DEBUG, "nl80211: Join IBSS failed: ret=%d (%s)", | |
5446 | ret, strerror(-ret)); | |
5447 | count++; | |
5448 | if (ret == -EALREADY && count == 1) { | |
5449 | wpa_printf(MSG_DEBUG, "nl80211: Retry IBSS join after " | |
5450 | "forced leave"); | |
666e508c | 5451 | nl80211_leave_ibss(drv, 0); |
5cc4d64b JM |
5452 | nlmsg_free(msg); |
5453 | goto retry; | |
5454 | } | |
a862e4a3 JM |
5455 | } else { |
5456 | wpa_printf(MSG_DEBUG, | |
5457 | "nl80211: Join IBSS request sent successfully"); | |
5cc4d64b | 5458 | } |
5cc4d64b | 5459 | |
a862e4a3 | 5460 | fail: |
5cc4d64b JM |
5461 | nlmsg_free(msg); |
5462 | return ret; | |
5463 | } | |
5464 | ||
5465 | ||
ad295f3b VK |
5466 | static int nl80211_put_fils_connect_params(struct wpa_driver_nl80211_data *drv, |
5467 | struct wpa_driver_associate_params *params, | |
5468 | struct nl_msg *msg) | |
5469 | { | |
5470 | if (params->fils_erp_username_len) { | |
5471 | wpa_hexdump_ascii(MSG_DEBUG, " * FILS ERP EMSKname/username", | |
5472 | params->fils_erp_username, | |
5473 | params->fils_erp_username_len); | |
5474 | if (nla_put(msg, NL80211_ATTR_FILS_ERP_USERNAME, | |
5475 | params->fils_erp_username_len, | |
5476 | params->fils_erp_username)) | |
5477 | return -1; | |
5478 | } | |
5479 | ||
5480 | if (params->fils_erp_realm_len) { | |
5481 | wpa_hexdump_ascii(MSG_DEBUG, " * FILS ERP Realm", | |
5482 | params->fils_erp_realm, | |
5483 | params->fils_erp_realm_len); | |
5484 | if (nla_put(msg, NL80211_ATTR_FILS_ERP_REALM, | |
5485 | params->fils_erp_realm_len, params->fils_erp_realm)) | |
5486 | return -1; | |
5487 | } | |
5488 | ||
5489 | wpa_printf(MSG_DEBUG, " * FILS ERP next seq %u", | |
5490 | params->fils_erp_next_seq_num); | |
5491 | if (nla_put_u16(msg, NL80211_ATTR_FILS_ERP_NEXT_SEQ_NUM, | |
5492 | params->fils_erp_next_seq_num)) | |
5493 | return -1; | |
5494 | ||
5495 | if (params->fils_erp_rrk_len) { | |
5496 | wpa_printf(MSG_DEBUG, " * FILS ERP rRK (len=%lu)", | |
5497 | (unsigned long) params->fils_erp_rrk_len); | |
5498 | if (nla_put(msg, NL80211_ATTR_FILS_ERP_RRK, | |
5499 | params->fils_erp_rrk_len, params->fils_erp_rrk)) | |
5500 | return -1; | |
5501 | } | |
5502 | ||
5503 | return 0; | |
5504 | } | |
5505 | ||
5506 | ||
a0bdd191 JM |
5507 | static int nl80211_connect_common(struct wpa_driver_nl80211_data *drv, |
5508 | struct wpa_driver_associate_params *params, | |
5509 | struct nl_msg *msg) | |
cfaab580 | 5510 | { |
c85dfc6f JM |
5511 | if (nla_put_flag(msg, NL80211_ATTR_IFACE_SOCKET_OWNER)) |
5512 | return -1; | |
5513 | ||
cfaab580 ZY |
5514 | if (params->bssid) { |
5515 | wpa_printf(MSG_DEBUG, " * bssid=" MACSTR, | |
5516 | MAC2STR(params->bssid)); | |
a862e4a3 JM |
5517 | if (nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, params->bssid)) |
5518 | return -1; | |
cfaab580 | 5519 | } |
a0bdd191 | 5520 | |
7ac7fd43 DS |
5521 | if (params->bssid_hint) { |
5522 | wpa_printf(MSG_DEBUG, " * bssid_hint=" MACSTR, | |
5523 | MAC2STR(params->bssid_hint)); | |
a862e4a3 JM |
5524 | if (nla_put(msg, NL80211_ATTR_MAC_HINT, ETH_ALEN, |
5525 | params->bssid_hint)) | |
5526 | return -1; | |
7ac7fd43 DS |
5527 | } |
5528 | ||
4ec68377 JD |
5529 | if (params->freq.freq) { |
5530 | wpa_printf(MSG_DEBUG, " * freq=%d", params->freq.freq); | |
a862e4a3 JM |
5531 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, |
5532 | params->freq.freq)) | |
5533 | return -1; | |
4ec68377 | 5534 | drv->assoc_freq = params->freq.freq; |
30158a0d SD |
5535 | } else |
5536 | drv->assoc_freq = 0; | |
a0bdd191 | 5537 | |
7ac7fd43 DS |
5538 | if (params->freq_hint) { |
5539 | wpa_printf(MSG_DEBUG, " * freq_hint=%d", params->freq_hint); | |
a862e4a3 JM |
5540 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ_HINT, |
5541 | params->freq_hint)) | |
5542 | return -1; | |
7ac7fd43 DS |
5543 | } |
5544 | ||
dda5d9e3 AAL |
5545 | if (params->freq.edmg.channels && params->freq.edmg.bw_config) { |
5546 | wpa_printf(MSG_DEBUG, | |
5547 | " * EDMG configuration: channels=0x%x bw_config=%d", | |
5548 | params->freq.edmg.channels, | |
5549 | params->freq.edmg.bw_config); | |
5550 | if (nla_put_u8(msg, NL80211_ATTR_WIPHY_EDMG_CHANNELS, | |
5551 | params->freq.edmg.channels) || | |
5552 | nla_put_u8(msg, NL80211_ATTR_WIPHY_EDMG_BW_CONFIG, | |
5553 | params->freq.edmg.bw_config)) | |
5554 | return -1; | |
5555 | } | |
5556 | ||
1f6c0ab8 BS |
5557 | if (params->bg_scan_period >= 0) { |
5558 | wpa_printf(MSG_DEBUG, " * bg scan period=%d", | |
5559 | params->bg_scan_period); | |
a862e4a3 JM |
5560 | if (nla_put_u16(msg, NL80211_ATTR_BG_SCAN_PERIOD, |
5561 | params->bg_scan_period)) | |
5562 | return -1; | |
1f6c0ab8 | 5563 | } |
a0bdd191 | 5564 | |
cfaab580 | 5565 | if (params->ssid) { |
21cd8f83 JM |
5566 | wpa_printf(MSG_DEBUG, " * SSID=%s", |
5567 | wpa_ssid_txt(params->ssid, params->ssid_len)); | |
a862e4a3 JM |
5568 | if (nla_put(msg, NL80211_ATTR_SSID, params->ssid_len, |
5569 | params->ssid)) | |
5570 | return -1; | |
cfaab580 | 5571 | if (params->ssid_len > sizeof(drv->ssid)) |
a862e4a3 | 5572 | return -1; |
cfaab580 ZY |
5573 | os_memcpy(drv->ssid, params->ssid, params->ssid_len); |
5574 | drv->ssid_len = params->ssid_len; | |
5575 | } | |
a0bdd191 | 5576 | |
cfaab580 | 5577 | wpa_hexdump(MSG_DEBUG, " * IEs", params->wpa_ie, params->wpa_ie_len); |
a862e4a3 JM |
5578 | if (params->wpa_ie && |
5579 | nla_put(msg, NL80211_ATTR_IE, params->wpa_ie_len, params->wpa_ie)) | |
5580 | return -1; | |
cfaab580 | 5581 | |
64fa840a JM |
5582 | if (params->wpa_proto) { |
5583 | enum nl80211_wpa_versions ver = 0; | |
cfaab580 | 5584 | |
64fa840a JM |
5585 | if (params->wpa_proto & WPA_PROTO_WPA) |
5586 | ver |= NL80211_WPA_VERSION_1; | |
5587 | if (params->wpa_proto & WPA_PROTO_RSN) | |
5588 | ver |= NL80211_WPA_VERSION_2; | |
cfaab580 | 5589 | |
64fa840a | 5590 | wpa_printf(MSG_DEBUG, " * WPA Versions 0x%x", ver); |
a862e4a3 JM |
5591 | if (nla_put_u32(msg, NL80211_ATTR_WPA_VERSIONS, ver)) |
5592 | return -1; | |
cfaab580 ZY |
5593 | } |
5594 | ||
4848a38d | 5595 | if (params->pairwise_suite != WPA_CIPHER_NONE) { |
a0bdd191 JM |
5596 | u32 cipher = wpa_cipher_to_cipher_suite(params->pairwise_suite); |
5597 | wpa_printf(MSG_DEBUG, " * pairwise=0x%x", cipher); | |
a862e4a3 JM |
5598 | if (nla_put_u32(msg, NL80211_ATTR_CIPHER_SUITES_PAIRWISE, |
5599 | cipher)) | |
5600 | return -1; | |
cfaab580 ZY |
5601 | } |
5602 | ||
ae6f9272 JM |
5603 | if (params->group_suite == WPA_CIPHER_GTK_NOT_USED && |
5604 | !(drv->capa.enc & WPA_DRIVER_CAPA_ENC_GTK_NOT_USED)) { | |
5605 | /* | |
5606 | * This is likely to work even though many drivers do not | |
5607 | * advertise support for operations without GTK. | |
5608 | */ | |
5609 | wpa_printf(MSG_DEBUG, " * skip group cipher configuration for GTK_NOT_USED due to missing driver support advertisement"); | |
5610 | } else if (params->group_suite != WPA_CIPHER_NONE) { | |
a0bdd191 JM |
5611 | u32 cipher = wpa_cipher_to_cipher_suite(params->group_suite); |
5612 | wpa_printf(MSG_DEBUG, " * group=0x%x", cipher); | |
a862e4a3 JM |
5613 | if (nla_put_u32(msg, NL80211_ATTR_CIPHER_SUITE_GROUP, cipher)) |
5614 | return -1; | |
cfaab580 ZY |
5615 | } |
5616 | ||
4848a38d JM |
5617 | if (params->key_mgmt_suite == WPA_KEY_MGMT_IEEE8021X || |
5618 | params->key_mgmt_suite == WPA_KEY_MGMT_PSK || | |
5619 | params->key_mgmt_suite == WPA_KEY_MGMT_FT_IEEE8021X || | |
5620 | params->key_mgmt_suite == WPA_KEY_MGMT_FT_PSK || | |
163f801e | 5621 | params->key_mgmt_suite == WPA_KEY_MGMT_CCKM || |
8802326f JJ |
5622 | params->key_mgmt_suite == WPA_KEY_MGMT_OSEN || |
5623 | params->key_mgmt_suite == WPA_KEY_MGMT_IEEE8021X_SHA256 || | |
666497c8 | 5624 | params->key_mgmt_suite == WPA_KEY_MGMT_PSK_SHA256 || |
005585d6 AB |
5625 | params->key_mgmt_suite == WPA_KEY_MGMT_SAE || |
5626 | params->key_mgmt_suite == WPA_KEY_MGMT_FT_SAE || | |
5e3b5197 | 5627 | params->key_mgmt_suite == WPA_KEY_MGMT_IEEE8021X_SUITE_B || |
ad295f3b | 5628 | params->key_mgmt_suite == WPA_KEY_MGMT_IEEE8021X_SUITE_B_192 || |
005585d6 | 5629 | params->key_mgmt_suite == WPA_KEY_MGMT_FT_IEEE8021X_SHA384 || |
ad295f3b VK |
5630 | params->key_mgmt_suite == WPA_KEY_MGMT_FILS_SHA256 || |
5631 | params->key_mgmt_suite == WPA_KEY_MGMT_FILS_SHA384 || | |
5632 | params->key_mgmt_suite == WPA_KEY_MGMT_FT_FILS_SHA256 || | |
e005725a SD |
5633 | params->key_mgmt_suite == WPA_KEY_MGMT_FT_FILS_SHA384 || |
5634 | params->key_mgmt_suite == WPA_KEY_MGMT_OWE || | |
5635 | params->key_mgmt_suite == WPA_KEY_MGMT_DPP) { | |
3aa24db9 | 5636 | int mgmt = RSN_AUTH_KEY_MGMT_PSK_OVER_802_1X; |
cfaab580 ZY |
5637 | |
5638 | switch (params->key_mgmt_suite) { | |
4848a38d | 5639 | case WPA_KEY_MGMT_CCKM: |
3aa24db9 | 5640 | mgmt = RSN_AUTH_KEY_MGMT_CCKM; |
369c8d7b | 5641 | break; |
4848a38d | 5642 | case WPA_KEY_MGMT_IEEE8021X: |
3aa24db9 | 5643 | mgmt = RSN_AUTH_KEY_MGMT_UNSPEC_802_1X; |
cfaab580 | 5644 | break; |
4848a38d | 5645 | case WPA_KEY_MGMT_FT_IEEE8021X: |
3aa24db9 | 5646 | mgmt = RSN_AUTH_KEY_MGMT_FT_802_1X; |
6a1ce395 | 5647 | break; |
4848a38d | 5648 | case WPA_KEY_MGMT_FT_PSK: |
3aa24db9 | 5649 | mgmt = RSN_AUTH_KEY_MGMT_FT_PSK; |
6a1ce395 | 5650 | break; |
8802326f | 5651 | case WPA_KEY_MGMT_IEEE8021X_SHA256: |
3aa24db9 | 5652 | mgmt = RSN_AUTH_KEY_MGMT_802_1X_SHA256; |
8802326f JJ |
5653 | break; |
5654 | case WPA_KEY_MGMT_PSK_SHA256: | |
3aa24db9 | 5655 | mgmt = RSN_AUTH_KEY_MGMT_PSK_SHA256; |
8802326f | 5656 | break; |
163f801e | 5657 | case WPA_KEY_MGMT_OSEN: |
3aa24db9 | 5658 | mgmt = RSN_AUTH_KEY_MGMT_OSEN; |
163f801e | 5659 | break; |
005585d6 AB |
5660 | case WPA_KEY_MGMT_SAE: |
5661 | mgmt = RSN_AUTH_KEY_MGMT_SAE; | |
5662 | break; | |
5663 | case WPA_KEY_MGMT_FT_SAE: | |
5664 | mgmt = RSN_AUTH_KEY_MGMT_FT_SAE; | |
5665 | break; | |
666497c8 | 5666 | case WPA_KEY_MGMT_IEEE8021X_SUITE_B: |
3aa24db9 | 5667 | mgmt = RSN_AUTH_KEY_MGMT_802_1X_SUITE_B; |
666497c8 | 5668 | break; |
5e3b5197 | 5669 | case WPA_KEY_MGMT_IEEE8021X_SUITE_B_192: |
3aa24db9 | 5670 | mgmt = RSN_AUTH_KEY_MGMT_802_1X_SUITE_B_192; |
5e3b5197 | 5671 | break; |
005585d6 AB |
5672 | case WPA_KEY_MGMT_FT_IEEE8021X_SHA384: |
5673 | mgmt = RSN_AUTH_KEY_MGMT_FT_802_1X_SHA384; | |
5674 | break; | |
ad295f3b VK |
5675 | case WPA_KEY_MGMT_FILS_SHA256: |
5676 | mgmt = RSN_AUTH_KEY_MGMT_FILS_SHA256; | |
5677 | break; | |
5678 | case WPA_KEY_MGMT_FILS_SHA384: | |
5679 | mgmt = RSN_AUTH_KEY_MGMT_FILS_SHA384; | |
5680 | break; | |
5681 | case WPA_KEY_MGMT_FT_FILS_SHA256: | |
5682 | mgmt = RSN_AUTH_KEY_MGMT_FT_FILS_SHA256; | |
5683 | break; | |
5684 | case WPA_KEY_MGMT_FT_FILS_SHA384: | |
5685 | mgmt = RSN_AUTH_KEY_MGMT_FT_FILS_SHA384; | |
5686 | break; | |
e005725a SD |
5687 | case WPA_KEY_MGMT_OWE: |
5688 | mgmt = RSN_AUTH_KEY_MGMT_OWE; | |
5689 | break; | |
5690 | case WPA_KEY_MGMT_DPP: | |
5691 | mgmt = RSN_AUTH_KEY_MGMT_DPP; | |
5692 | break; | |
4848a38d | 5693 | case WPA_KEY_MGMT_PSK: |
cfaab580 | 5694 | default: |
3aa24db9 | 5695 | mgmt = RSN_AUTH_KEY_MGMT_PSK_OVER_802_1X; |
cfaab580 ZY |
5696 | break; |
5697 | } | |
163f801e | 5698 | wpa_printf(MSG_DEBUG, " * akm=0x%x", mgmt); |
a862e4a3 JM |
5699 | if (nla_put_u32(msg, NL80211_ATTR_AKM_SUITES, mgmt)) |
5700 | return -1; | |
cfaab580 ZY |
5701 | } |
5702 | ||
cb28bd52 | 5703 | if (params->req_handshake_offload && |
d896874f AS |
5704 | (drv->capa.flags & WPA_DRIVER_FLAGS_4WAY_HANDSHAKE_8021X)) { |
5705 | wpa_printf(MSG_DEBUG, " * WANT_1X_4WAY_HS"); | |
5706 | if (nla_put_flag(msg, NL80211_ATTR_WANT_1X_4WAY_HS)) | |
5707 | return -1; | |
5708 | } | |
5709 | ||
730c5a1d EP |
5710 | /* Add PSK in case of 4-way handshake offload */ |
5711 | if (params->psk && | |
436ee2fd | 5712 | (drv->capa.flags & WPA_DRIVER_FLAGS_4WAY_HANDSHAKE_PSK)) { |
730c5a1d EP |
5713 | wpa_hexdump_key(MSG_DEBUG, " * PSK", params->psk, 32); |
5714 | if (nla_put(msg, NL80211_ATTR_PMK, 32, params->psk)) | |
5715 | return -1; | |
5716 | } | |
5717 | ||
a862e4a3 JM |
5718 | if (nla_put_flag(msg, NL80211_ATTR_CONTROL_PORT)) |
5719 | return -1; | |
a0bdd191 | 5720 | |
e3429c0b JB |
5721 | if (params->key_mgmt_suite == WPA_KEY_MGMT_IEEE8021X_NO_WPA && |
5722 | (params->pairwise_suite == WPA_CIPHER_NONE || | |
5723 | params->pairwise_suite == WPA_CIPHER_WEP104 || | |
5724 | params->pairwise_suite == WPA_CIPHER_WEP40) && | |
5725 | (nla_put_u16(msg, NL80211_ATTR_CONTROL_PORT_ETHERTYPE, ETH_P_PAE) || | |
5726 | nla_put_flag(msg, NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT))) | |
5727 | return -1; | |
5728 | ||
58162adf AK |
5729 | if (params->rrm_used) { |
5730 | u32 drv_rrm_flags = drv->capa.rrm_flags; | |
b5d172e5 BL |
5731 | if ((!((drv_rrm_flags & |
5732 | WPA_DRIVER_FLAGS_DS_PARAM_SET_IE_IN_PROBES) && | |
5733 | (drv_rrm_flags & WPA_DRIVER_FLAGS_QUIET)) && | |
5734 | !(drv_rrm_flags & WPA_DRIVER_FLAGS_SUPPORT_RRM)) || | |
a862e4a3 JM |
5735 | nla_put_flag(msg, NL80211_ATTR_USE_RRM)) |
5736 | return -1; | |
58162adf AK |
5737 | } |
5738 | ||
95ff3069 | 5739 | if (nl80211_ht_vht_overrides(msg, params) < 0) |
a862e4a3 | 5740 | return -1; |
80e8a5ee | 5741 | |
a0bdd191 JM |
5742 | if (params->p2p) |
5743 | wpa_printf(MSG_DEBUG, " * P2P group"); | |
5744 | ||
86b5c400 LD |
5745 | if (params->pbss) { |
5746 | wpa_printf(MSG_DEBUG, " * PBSS"); | |
5747 | if (nla_put_flag(msg, NL80211_ATTR_PBSS)) | |
5748 | return -1; | |
5749 | } | |
5750 | ||
1126c078 | 5751 | drv->connect_reassoc = 0; |
00c3c4ac JM |
5752 | if (params->prev_bssid) { |
5753 | wpa_printf(MSG_DEBUG, " * prev_bssid=" MACSTR, | |
5754 | MAC2STR(params->prev_bssid)); | |
5755 | if (nla_put(msg, NL80211_ATTR_PREV_BSSID, ETH_ALEN, | |
5756 | params->prev_bssid)) | |
5757 | return -1; | |
1126c078 | 5758 | drv->connect_reassoc = 1; |
00c3c4ac JM |
5759 | } |
5760 | ||
ad295f3b VK |
5761 | if ((params->auth_alg & WPA_AUTH_ALG_FILS) && |
5762 | nl80211_put_fils_connect_params(drv, params, msg) != 0) | |
5763 | return -1; | |
5764 | ||
ba71cb82 SD |
5765 | if ((params->auth_alg & WPA_AUTH_ALG_SAE) && |
5766 | (!(drv->capa.flags & WPA_DRIVER_FLAGS_SME)) && | |
5767 | nla_put_flag(msg, NL80211_ATTR_EXTERNAL_AUTH_SUPPORT)) | |
5768 | return -1; | |
5769 | ||
a0bdd191 | 5770 | return 0; |
a0bdd191 JM |
5771 | } |
5772 | ||
5773 | ||
5774 | static int wpa_driver_nl80211_try_connect( | |
5775 | struct wpa_driver_nl80211_data *drv, | |
40a68f33 SD |
5776 | struct wpa_driver_associate_params *params, |
5777 | struct nl_handle *nl_connect) | |
a0bdd191 JM |
5778 | { |
5779 | struct nl_msg *msg; | |
5780 | enum nl80211_auth_type type; | |
5781 | int ret; | |
5782 | int algs; | |
5783 | ||
b658547d | 5784 | #ifdef CONFIG_DRIVER_NL80211_QCA |
b41f2684 CL |
5785 | if (params->req_key_mgmt_offload && params->psk && |
5786 | (params->key_mgmt_suite == WPA_KEY_MGMT_PSK || | |
5787 | params->key_mgmt_suite == WPA_KEY_MGMT_PSK_SHA256 || | |
5788 | params->key_mgmt_suite == WPA_KEY_MGMT_FT_PSK)) { | |
5789 | wpa_printf(MSG_DEBUG, "nl80211: Key management set PSK"); | |
5790 | ret = issue_key_mgmt_set_key(drv, params->psk, 32); | |
5791 | if (ret) | |
5792 | return ret; | |
5793 | } | |
b658547d | 5794 | #endif /* CONFIG_DRIVER_NL80211_QCA */ |
b41f2684 | 5795 | |
9725b784 JM |
5796 | wpa_printf(MSG_DEBUG, "nl80211: Connect (ifindex=%d)", drv->ifindex); |
5797 | msg = nl80211_drv_msg(drv, 0, NL80211_CMD_CONNECT); | |
a0bdd191 JM |
5798 | if (!msg) |
5799 | return -1; | |
5800 | ||
a0bdd191 JM |
5801 | ret = nl80211_connect_common(drv, params, msg); |
5802 | if (ret) | |
a862e4a3 | 5803 | goto fail; |
a0bdd191 | 5804 | |
299d21e8 EG |
5805 | if (params->mgmt_frame_protection == MGMT_FRAME_PROTECTION_REQUIRED && |
5806 | nla_put_u32(msg, NL80211_ATTR_USE_MFP, NL80211_MFP_REQUIRED)) | |
5807 | goto fail; | |
5808 | ||
5809 | if (params->mgmt_frame_protection == MGMT_FRAME_PROTECTION_OPTIONAL && | |
5810 | (drv->capa.flags & WPA_DRIVER_FLAGS_MFP_OPTIONAL) && | |
5811 | nla_put_u32(msg, NL80211_ATTR_USE_MFP, NL80211_MFP_OPTIONAL)) | |
5812 | goto fail; | |
5813 | ||
a0bdd191 JM |
5814 | algs = 0; |
5815 | if (params->auth_alg & WPA_AUTH_ALG_OPEN) | |
5816 | algs++; | |
5817 | if (params->auth_alg & WPA_AUTH_ALG_SHARED) | |
5818 | algs++; | |
5819 | if (params->auth_alg & WPA_AUTH_ALG_LEAP) | |
5820 | algs++; | |
64a0a75b JM |
5821 | if (params->auth_alg & WPA_AUTH_ALG_FILS) |
5822 | algs++; | |
86c998d3 AM |
5823 | if (params->auth_alg & WPA_AUTH_ALG_FT) |
5824 | algs++; | |
a0bdd191 JM |
5825 | if (algs > 1) { |
5826 | wpa_printf(MSG_DEBUG, " * Leave out Auth Type for automatic " | |
5827 | "selection"); | |
5828 | goto skip_auth_type; | |
5829 | } | |
5830 | ||
3c67e977 | 5831 | type = get_nl_auth_type(params->auth_alg); |
a0bdd191 | 5832 | wpa_printf(MSG_DEBUG, " * Auth Type %d", type); |
3c67e977 VK |
5833 | if (type == NL80211_AUTHTYPE_MAX || |
5834 | nla_put_u32(msg, NL80211_ATTR_AUTH_TYPE, type)) | |
a862e4a3 | 5835 | goto fail; |
a0bdd191 JM |
5836 | |
5837 | skip_auth_type: | |
cfaab580 ZY |
5838 | ret = nl80211_set_conn_keys(params, msg); |
5839 | if (ret) | |
a862e4a3 | 5840 | goto fail; |
cfaab580 | 5841 | |
40a68f33 | 5842 | if (nl_connect) |
0fa33e05 JM |
5843 | ret = send_and_recv(drv->global, nl_connect, msg, |
5844 | NULL, (void *) -1); | |
40a68f33 | 5845 | else |
0fa33e05 | 5846 | ret = send_and_recv_msgs(drv, msg, NULL, (void *) -1); |
40a68f33 | 5847 | |
cfaab580 ZY |
5848 | msg = NULL; |
5849 | if (ret) { | |
5850 | wpa_printf(MSG_DEBUG, "nl80211: MLME connect failed: ret=%d " | |
5851 | "(%s)", ret, strerror(-ret)); | |
a862e4a3 JM |
5852 | } else { |
5853 | wpa_printf(MSG_DEBUG, | |
5854 | "nl80211: Connect request send successfully"); | |
cfaab580 | 5855 | } |
cfaab580 | 5856 | |
a862e4a3 | 5857 | fail: |
0fa33e05 | 5858 | nl80211_nlmsg_clear(msg); |
cfaab580 ZY |
5859 | nlmsg_free(msg); |
5860 | return ret; | |
5861 | ||
5862 | } | |
5863 | ||
5864 | ||
a8c5b43a CW |
5865 | static int wpa_driver_nl80211_connect( |
5866 | struct wpa_driver_nl80211_data *drv, | |
40a68f33 SD |
5867 | struct wpa_driver_associate_params *params, |
5868 | struct nl_handle *nl_connect) | |
a8c5b43a | 5869 | { |
0d4e3d1d JJ |
5870 | int ret; |
5871 | ||
5872 | /* Store the connection attempted bssid for future use */ | |
5873 | if (params->bssid) | |
5874 | os_memcpy(drv->auth_attempt_bssid, params->bssid, ETH_ALEN); | |
5875 | else | |
5876 | os_memset(drv->auth_attempt_bssid, 0, ETH_ALEN); | |
5877 | ||
40a68f33 | 5878 | ret = wpa_driver_nl80211_try_connect(drv, params, nl_connect); |
a8c5b43a CW |
5879 | if (ret == -EALREADY) { |
5880 | /* | |
5881 | * cfg80211 does not currently accept new connections if | |
5882 | * we are already connected. As a workaround, force | |
5883 | * disconnection and try again. | |
5884 | */ | |
5885 | wpa_printf(MSG_DEBUG, "nl80211: Explicitly " | |
5886 | "disconnecting before reassociation " | |
5887 | "attempt"); | |
5888 | if (wpa_driver_nl80211_disconnect( | |
10d32e2c | 5889 | drv, WLAN_REASON_PREV_AUTH_NOT_VALID, nl_connect)) |
a8c5b43a | 5890 | return -1; |
40a68f33 | 5891 | ret = wpa_driver_nl80211_try_connect(drv, params, nl_connect); |
a8c5b43a CW |
5892 | } |
5893 | return ret; | |
5894 | } | |
5895 | ||
5896 | ||
c2a04078 JM |
5897 | static int wpa_driver_nl80211_associate( |
5898 | void *priv, struct wpa_driver_associate_params *params) | |
5899 | { | |
a2e40bb6 FF |
5900 | struct i802_bss *bss = priv; |
5901 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
a862e4a3 | 5902 | int ret = -1; |
c2a04078 JM |
5903 | struct nl_msg *msg; |
5904 | ||
4bd71954 JM |
5905 | nl80211_unmask_11b_rates(bss); |
5906 | ||
5cc4d64b | 5907 | if (params->mode == IEEE80211_MODE_AP) |
1581b38b | 5908 | return wpa_driver_nl80211_ap(drv, params); |
1581b38b | 5909 | |
5cc4d64b JM |
5910 | if (params->mode == IEEE80211_MODE_IBSS) |
5911 | return wpa_driver_nl80211_ibss(drv, params); | |
5912 | ||
4a867032 | 5913 | if (!(drv->capa.flags & WPA_DRIVER_FLAGS_SME)) { |
b1f625e0 EP |
5914 | enum nl80211_iftype nlmode = params->p2p ? |
5915 | NL80211_IFTYPE_P2P_CLIENT : NL80211_IFTYPE_STATION; | |
40a68f33 | 5916 | struct nl_handle *nl_connect = NULL; |
b1f625e0 EP |
5917 | |
5918 | if (wpa_driver_nl80211_set_mode(priv, nlmode) < 0) | |
4a867032 | 5919 | return -1; |
10d32e2c | 5920 | if (params->auth_alg & WPA_AUTH_ALG_SAE) { |
40a68f33 | 5921 | nl_connect = bss->nl_connect; |
10d32e2c CI |
5922 | bss->use_nl_connect = 1; |
5923 | } else { | |
5924 | bss->use_nl_connect = 0; | |
5925 | } | |
5926 | ||
40a68f33 | 5927 | return wpa_driver_nl80211_connect(drv, params, nl_connect); |
4a867032 | 5928 | } |
cfaab580 | 5929 | |
add9b7a4 | 5930 | nl80211_mark_disconnected(drv); |
c2a04078 | 5931 | |
c2a04078 JM |
5932 | wpa_printf(MSG_DEBUG, "nl80211: Associate (ifindex=%d)", |
5933 | drv->ifindex); | |
9725b784 JM |
5934 | msg = nl80211_drv_msg(drv, 0, NL80211_CMD_ASSOCIATE); |
5935 | if (!msg) | |
5936 | return -1; | |
c2a04078 | 5937 | |
a0bdd191 JM |
5938 | ret = nl80211_connect_common(drv, params, msg); |
5939 | if (ret) | |
a862e4a3 | 5940 | goto fail; |
01652550 | 5941 | |
299d21e8 EG |
5942 | if (params->mgmt_frame_protection == MGMT_FRAME_PROTECTION_REQUIRED && |
5943 | nla_put_u32(msg, NL80211_ATTR_USE_MFP, NL80211_MFP_REQUIRED)) | |
5944 | goto fail; | |
5945 | ||
40a45727 JM |
5946 | if (params->fils_kek) { |
5947 | wpa_printf(MSG_DEBUG, " * FILS KEK (len=%u)", | |
5948 | (unsigned int) params->fils_kek_len); | |
5949 | if (nla_put(msg, NL80211_ATTR_FILS_KEK, params->fils_kek_len, | |
5950 | params->fils_kek)) | |
5951 | goto fail; | |
5952 | } | |
5953 | if (params->fils_nonces) { | |
5954 | wpa_hexdump(MSG_DEBUG, " * FILS nonces (for AAD)", | |
5955 | params->fils_nonces, | |
5956 | params->fils_nonces_len); | |
5957 | if (nla_put(msg, NL80211_ATTR_FILS_NONCES, | |
5958 | params->fils_nonces_len, params->fils_nonces)) | |
5959 | goto fail; | |
5960 | } | |
5961 | ||
c2a04078 JM |
5962 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
5963 | msg = NULL; | |
5964 | if (ret) { | |
3b7ea880 BG |
5965 | wpa_dbg(drv->ctx, MSG_DEBUG, |
5966 | "nl80211: MLME command failed (assoc): ret=%d (%s)", | |
5967 | ret, strerror(-ret)); | |
8856462d | 5968 | nl80211_dump_scan(drv); |
a862e4a3 JM |
5969 | } else { |
5970 | wpa_printf(MSG_DEBUG, | |
5971 | "nl80211: Association request send successfully"); | |
c2a04078 | 5972 | } |
c2a04078 | 5973 | |
a862e4a3 | 5974 | fail: |
c2a04078 JM |
5975 | nlmsg_free(msg); |
5976 | return ret; | |
5977 | } | |
3f5285e8 JM |
5978 | |
5979 | ||
ad1e68e6 | 5980 | static int nl80211_set_mode(struct wpa_driver_nl80211_data *drv, |
a1922f93 | 5981 | int ifindex, enum nl80211_iftype mode) |
3f5285e8 | 5982 | { |
3f5285e8 | 5983 | struct nl_msg *msg; |
ad1e68e6 JM |
5984 | int ret = -ENOBUFS; |
5985 | ||
a1922f93 JM |
5986 | wpa_printf(MSG_DEBUG, "nl80211: Set mode ifindex %d iftype %d (%s)", |
5987 | ifindex, mode, nl80211_iftype_str(mode)); | |
5988 | ||
56f77852 JM |
5989 | msg = nl80211_cmd_msg(drv->first_bss, 0, NL80211_CMD_SET_INTERFACE); |
5990 | if (!msg || nla_put_u32(msg, NL80211_ATTR_IFTYPE, mode)) | |
a862e4a3 | 5991 | goto fail; |
ad1e68e6 JM |
5992 | |
5993 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); | |
5883168a | 5994 | msg = NULL; |
ad1e68e6 JM |
5995 | if (!ret) |
5996 | return 0; | |
a862e4a3 | 5997 | fail: |
5883168a | 5998 | nlmsg_free(msg); |
ad1e68e6 JM |
5999 | wpa_printf(MSG_DEBUG, "nl80211: Failed to set interface %d to mode %d:" |
6000 | " %d (%s)", ifindex, mode, ret, strerror(-ret)); | |
6001 | return ret; | |
6002 | } | |
6003 | ||
6004 | ||
3c5d34e3 CW |
6005 | static int wpa_driver_nl80211_set_mode_impl( |
6006 | struct i802_bss *bss, | |
6007 | enum nl80211_iftype nlmode, | |
6008 | struct hostapd_freq_params *desired_freq_params) | |
ad1e68e6 | 6009 | { |
a2e40bb6 | 6010 | struct wpa_driver_nl80211_data *drv = bss->drv; |
ad1e68e6 | 6011 | int ret = -1; |
26af9dca | 6012 | int i; |
86957e62 | 6013 | int was_ap = is_ap_interface(drv->nlmode); |
671a5039 | 6014 | int res; |
ebffdbc4 | 6015 | int mode_switch_res; |
1581b38b | 6016 | |
a5a187b0 JM |
6017 | if (TEST_FAIL()) |
6018 | return -1; | |
6019 | ||
ebffdbc4 CW |
6020 | mode_switch_res = nl80211_set_mode(drv, drv->ifindex, nlmode); |
6021 | if (mode_switch_res && nlmode == nl80211_get_ifmode(bss)) | |
6022 | mode_switch_res = 0; | |
8e12685c | 6023 | |
ebffdbc4 | 6024 | if (mode_switch_res == 0) { |
ad1e68e6 | 6025 | drv->nlmode = nlmode; |
460456f8 JM |
6026 | ret = 0; |
6027 | goto done; | |
ad1e68e6 | 6028 | } |
3f5285e8 | 6029 | |
ebffdbc4 | 6030 | if (mode_switch_res == -ENODEV) |
671a5039 JM |
6031 | return -1; |
6032 | ||
460456f8 | 6033 | if (nlmode == drv->nlmode) { |
c6e8e8e4 JM |
6034 | wpa_printf(MSG_DEBUG, "nl80211: Interface already in " |
6035 | "requested mode - ignore error"); | |
460456f8 JM |
6036 | ret = 0; |
6037 | goto done; /* Already in the requested mode */ | |
6038 | } | |
3f5285e8 | 6039 | |
3f5285e8 JM |
6040 | /* mac80211 doesn't allow mode changes while the device is up, so |
6041 | * take the device down, try to set the mode again, and bring the | |
6042 | * device back up. | |
6043 | */ | |
26af9dca JM |
6044 | wpa_printf(MSG_DEBUG, "nl80211: Try mode change after setting " |
6045 | "interface down"); | |
6046 | for (i = 0; i < 10; i++) { | |
91724d6f | 6047 | res = i802_set_iface_flags(bss, 0); |
6e8183d7 JM |
6048 | if (res == -EACCES || res == -ENODEV) |
6049 | break; | |
ebffdbc4 | 6050 | if (res != 0) { |
26af9dca JM |
6051 | wpa_printf(MSG_DEBUG, "nl80211: Failed to set " |
6052 | "interface down"); | |
ebffdbc4 CW |
6053 | os_sleep(0, 100000); |
6054 | continue; | |
6055 | } | |
3c5d34e3 CW |
6056 | |
6057 | /* | |
6058 | * Setting the mode will fail for some drivers if the phy is | |
6059 | * on a frequency that the mode is disallowed in. | |
6060 | */ | |
6061 | if (desired_freq_params) { | |
bdf5ccb2 | 6062 | res = nl80211_set_channel(bss, desired_freq_params, 0); |
3c5d34e3 CW |
6063 | if (res) { |
6064 | wpa_printf(MSG_DEBUG, | |
6065 | "nl80211: Failed to set frequency on interface"); | |
6066 | } | |
6067 | } | |
6068 | ||
ebffdbc4 CW |
6069 | /* Try to set the mode again while the interface is down */ |
6070 | mode_switch_res = nl80211_set_mode(drv, drv->ifindex, nlmode); | |
6071 | if (mode_switch_res == -EBUSY) { | |
6072 | wpa_printf(MSG_DEBUG, | |
6073 | "nl80211: Delaying mode set while interface going down"); | |
6074 | os_sleep(0, 100000); | |
6075 | continue; | |
6076 | } | |
6077 | ret = mode_switch_res; | |
6078 | break; | |
3f5285e8 JM |
6079 | } |
6080 | ||
c6e8e8e4 JM |
6081 | if (!ret) { |
6082 | wpa_printf(MSG_DEBUG, "nl80211: Mode change succeeded while " | |
6083 | "interface is down"); | |
ad1e68e6 | 6084 | drv->nlmode = nlmode; |
7d9c3698 | 6085 | drv->ignore_if_down_event = 1; |
c6e8e8e4 | 6086 | } |
ad1e68e6 | 6087 | |
ebffdbc4 CW |
6088 | /* Bring the interface back up */ |
6089 | res = linux_set_iface_flags(drv->global->ioctl_sock, bss->ifname, 1); | |
6090 | if (res != 0) { | |
6091 | wpa_printf(MSG_DEBUG, | |
6092 | "nl80211: Failed to set interface up after switching mode"); | |
6093 | ret = -1; | |
6094 | } | |
6095 | ||
460456f8 | 6096 | done: |
3fd1cefb JB |
6097 | if (ret) { |
6098 | wpa_printf(MSG_DEBUG, "nl80211: Interface mode change to %d " | |
6099 | "from %d failed", nlmode, drv->nlmode); | |
6100 | return ret; | |
6101 | } | |
6102 | ||
3e208481 JM |
6103 | if (is_p2p_net_interface(nlmode)) { |
6104 | wpa_printf(MSG_DEBUG, | |
6105 | "nl80211: Interface %s mode change to P2P - disable 11b rates", | |
6106 | bss->ifname); | |
edb9bfba | 6107 | nl80211_disable_11b_rates(drv, drv->ifindex, 1); |
3e208481 JM |
6108 | } else if (drv->disabled_11b_rates) { |
6109 | wpa_printf(MSG_DEBUG, | |
6110 | "nl80211: Interface %s mode changed to non-P2P - re-enable 11b rates", | |
6111 | bss->ifname); | |
1d0c6fb1 | 6112 | nl80211_disable_11b_rates(drv, drv->ifindex, 0); |
3e208481 | 6113 | } |
edb9bfba | 6114 | |
3fd1cefb | 6115 | if (is_ap_interface(nlmode)) { |
36488c05 | 6116 | nl80211_mgmt_unsubscribe(bss, "start AP"); |
460456f8 | 6117 | /* Setup additional AP mode functionality if needed */ |
3fd1cefb | 6118 | if (nl80211_setup_ap(bss)) |
460456f8 | 6119 | return -1; |
3fd1cefb | 6120 | } else if (was_ap) { |
460456f8 | 6121 | /* Remove additional AP mode functionality */ |
3fd1cefb | 6122 | nl80211_teardown_ap(bss); |
a11241fa | 6123 | } else { |
36488c05 | 6124 | nl80211_mgmt_unsubscribe(bss, "mode change"); |
460456f8 | 6125 | } |
460456f8 | 6126 | |
afb0550a BC |
6127 | if (is_mesh_interface(nlmode) && |
6128 | nl80211_mgmt_subscribe_mesh(bss)) | |
6129 | return -1; | |
6130 | ||
873d0fcf | 6131 | if (!bss->in_deinit && !is_ap_interface(nlmode) && |
afb0550a | 6132 | !is_mesh_interface(nlmode) && |
a11241fa JB |
6133 | nl80211_mgmt_subscribe_non_ap(bss) < 0) |
6134 | wpa_printf(MSG_DEBUG, "nl80211: Failed to register Action " | |
6135 | "frame processing - ignore for now"); | |
08359050 | 6136 | |
3fd1cefb | 6137 | return 0; |
3f5285e8 JM |
6138 | } |
6139 | ||
6140 | ||
f3407c66 JM |
6141 | int wpa_driver_nl80211_set_mode(struct i802_bss *bss, |
6142 | enum nl80211_iftype nlmode) | |
3c5d34e3 CW |
6143 | { |
6144 | return wpa_driver_nl80211_set_mode_impl(bss, nlmode, NULL); | |
6145 | } | |
6146 | ||
6147 | ||
4ec68377 JD |
6148 | static int wpa_driver_nl80211_set_mode_ibss(struct i802_bss *bss, |
6149 | struct hostapd_freq_params *freq) | |
3c5d34e3 | 6150 | { |
3c5d34e3 | 6151 | return wpa_driver_nl80211_set_mode_impl(bss, NL80211_IFTYPE_ADHOC, |
4ec68377 | 6152 | freq); |
3c5d34e3 | 6153 | } |
65d645ce AS |
6154 | |
6155 | ||
3f5285e8 JM |
6156 | static int wpa_driver_nl80211_get_capa(void *priv, |
6157 | struct wpa_driver_capa *capa) | |
6158 | { | |
a2e40bb6 FF |
6159 | struct i802_bss *bss = priv; |
6160 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
65d645ce | 6161 | |
3f5285e8 JM |
6162 | if (!drv->has_capability) |
6163 | return -1; | |
6164 | os_memcpy(capa, &drv->capa, sizeof(*capa)); | |
8cd6b7bc JB |
6165 | if (drv->extended_capa && drv->extended_capa_mask) { |
6166 | capa->extended_capa = drv->extended_capa; | |
6167 | capa->extended_capa_mask = drv->extended_capa_mask; | |
6168 | capa->extended_capa_len = drv->extended_capa_len; | |
6169 | } | |
851b0c55 | 6170 | |
906bc4c7 | 6171 | return 0; |
3f5285e8 JM |
6172 | } |
6173 | ||
6174 | ||
6175 | static int wpa_driver_nl80211_set_operstate(void *priv, int state) | |
6176 | { | |
a2e40bb6 FF |
6177 | struct i802_bss *bss = priv; |
6178 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
3f5285e8 | 6179 | |
90a545cc JM |
6180 | wpa_printf(MSG_DEBUG, "nl80211: Set %s operstate %d->%d (%s)", |
6181 | bss->ifname, drv->operstate, state, | |
6182 | state ? "UP" : "DORMANT"); | |
3f5285e8 | 6183 | drv->operstate = state; |
36d84860 | 6184 | return netlink_send_oper_ifla(drv->global->netlink, drv->ifindex, -1, |
e2d02c29 | 6185 | state ? IF_OPER_UP : IF_OPER_DORMANT); |
3f5285e8 JM |
6186 | } |
6187 | ||
01652550 JM |
6188 | |
6189 | static int wpa_driver_nl80211_set_supp_port(void *priv, int authorized) | |
6190 | { | |
a2e40bb6 FF |
6191 | struct i802_bss *bss = priv; |
6192 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
01652550 JM |
6193 | struct nl_msg *msg; |
6194 | struct nl80211_sta_flag_update upd; | |
a862e4a3 | 6195 | int ret; |
2eef5177 JM |
6196 | |
6197 | if (!drv->associated && is_zero_ether_addr(drv->bssid) && !authorized) { | |
6198 | wpa_printf(MSG_DEBUG, "nl80211: Skip set_supp_port(unauthorized) while not associated"); | |
6199 | return 0; | |
6200 | } | |
01652550 | 6201 | |
1ba51ec0 JM |
6202 | wpa_printf(MSG_DEBUG, "nl80211: Set supplicant port %sauthorized for " |
6203 | MACSTR, authorized ? "" : "un", MAC2STR(drv->bssid)); | |
6204 | ||
01652550 JM |
6205 | os_memset(&upd, 0, sizeof(upd)); |
6206 | upd.mask = BIT(NL80211_STA_FLAG_AUTHORIZED); | |
6207 | if (authorized) | |
6208 | upd.set = BIT(NL80211_STA_FLAG_AUTHORIZED); | |
a862e4a3 | 6209 | |
13f83980 | 6210 | if (!(msg = nl80211_bss_msg(bss, 0, NL80211_CMD_SET_STATION)) || |
a862e4a3 JM |
6211 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, drv->bssid) || |
6212 | nla_put(msg, NL80211_ATTR_STA_FLAGS2, sizeof(upd), &upd)) { | |
6213 | nlmsg_free(msg); | |
6214 | return -ENOBUFS; | |
6215 | } | |
01652550 | 6216 | |
2eef5177 | 6217 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
2eef5177 JM |
6218 | if (!ret) |
6219 | return 0; | |
2eef5177 JM |
6220 | wpa_printf(MSG_DEBUG, "nl80211: Failed to set STA flag: %d (%s)", |
6221 | ret, strerror(-ret)); | |
6222 | return ret; | |
01652550 JM |
6223 | } |
6224 | ||
3f5285e8 | 6225 | |
f07ead6a JM |
6226 | /* Set kernel driver on given frequency (MHz) */ |
6227 | static int i802_set_freq(void *priv, struct hostapd_freq_params *freq) | |
c5121837 | 6228 | { |
f07ead6a | 6229 | struct i802_bss *bss = priv; |
13a524a3 | 6230 | return nl80211_set_channel(bss, freq, 0); |
c5121837 JM |
6231 | } |
6232 | ||
f7b3920c | 6233 | |
c5121837 JM |
6234 | static inline int min_int(int a, int b) |
6235 | { | |
6236 | if (a < b) | |
6237 | return a; | |
6238 | return b; | |
6239 | } | |
6240 | ||
6241 | ||
6242 | static int get_key_handler(struct nl_msg *msg, void *arg) | |
6243 | { | |
6244 | struct nlattr *tb[NL80211_ATTR_MAX + 1]; | |
6245 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); | |
6246 | ||
6247 | nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), | |
6248 | genlmsg_attrlen(gnlh, 0), NULL); | |
6249 | ||
6250 | /* | |
6251 | * TODO: validate the key index and mac address! | |
6252 | * Otherwise, there's a race condition as soon as | |
6253 | * the kernel starts sending key notifications. | |
6254 | */ | |
6255 | ||
6256 | if (tb[NL80211_ATTR_KEY_SEQ]) | |
6257 | memcpy(arg, nla_data(tb[NL80211_ATTR_KEY_SEQ]), | |
6258 | min_int(nla_len(tb[NL80211_ATTR_KEY_SEQ]), 6)); | |
4efade31 | 6259 | nl80211_nlmsg_clear(msg); |
c5121837 JM |
6260 | return NL_SKIP; |
6261 | } | |
6262 | ||
6263 | ||
6264 | static int i802_get_seqnum(const char *iface, void *priv, const u8 *addr, | |
6265 | int idx, u8 *seq) | |
6266 | { | |
a2e40bb6 FF |
6267 | struct i802_bss *bss = priv; |
6268 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
c5121837 JM |
6269 | struct nl_msg *msg; |
6270 | ||
95376e1a JM |
6271 | msg = nl80211_ifindex_msg(drv, if_nametoindex(iface), 0, |
6272 | NL80211_CMD_GET_KEY); | |
6273 | if (!msg || | |
a862e4a3 | 6274 | (addr && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) || |
95376e1a | 6275 | nla_put_u8(msg, NL80211_ATTR_KEY_IDX, idx)) { |
a862e4a3 JM |
6276 | nlmsg_free(msg); |
6277 | return -ENOBUFS; | |
6278 | } | |
c5121837 JM |
6279 | |
6280 | memset(seq, 0, 6); | |
6281 | ||
6282 | return send_and_recv_msgs(drv, msg, get_key_handler, seq); | |
c5121837 JM |
6283 | } |
6284 | ||
6285 | ||
c5121837 JM |
6286 | static int i802_set_rts(void *priv, int rts) |
6287 | { | |
a2e40bb6 FF |
6288 | struct i802_bss *bss = priv; |
6289 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
ad649451 | 6290 | struct nl_msg *msg; |
a862e4a3 | 6291 | int ret; |
ad649451 | 6292 | u32 val; |
c5121837 | 6293 | |
bf0021ed | 6294 | if (rts >= 2347 || rts == -1) |
ad649451 JM |
6295 | val = (u32) -1; |
6296 | else | |
6297 | val = rts; | |
c5121837 | 6298 | |
9725b784 | 6299 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_SET_WIPHY)) || |
a862e4a3 JM |
6300 | nla_put_u32(msg, NL80211_ATTR_WIPHY_RTS_THRESHOLD, val)) { |
6301 | nlmsg_free(msg); | |
6302 | return -ENOBUFS; | |
6303 | } | |
ad649451 JM |
6304 | |
6305 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); | |
6306 | if (!ret) | |
6307 | return 0; | |
ad649451 JM |
6308 | wpa_printf(MSG_DEBUG, "nl80211: Failed to set RTS threshold %d: " |
6309 | "%d (%s)", rts, ret, strerror(-ret)); | |
6310 | return ret; | |
c5121837 JM |
6311 | } |
6312 | ||
6313 | ||
6314 | static int i802_set_frag(void *priv, int frag) | |
6315 | { | |
a2e40bb6 FF |
6316 | struct i802_bss *bss = priv; |
6317 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
ad649451 | 6318 | struct nl_msg *msg; |
a862e4a3 | 6319 | int ret; |
ad649451 | 6320 | u32 val; |
c5121837 | 6321 | |
bf0021ed | 6322 | if (frag >= 2346 || frag == -1) |
ad649451 JM |
6323 | val = (u32) -1; |
6324 | else | |
6325 | val = frag; | |
c5121837 | 6326 | |
9725b784 | 6327 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_SET_WIPHY)) || |
a862e4a3 JM |
6328 | nla_put_u32(msg, NL80211_ATTR_WIPHY_FRAG_THRESHOLD, val)) { |
6329 | nlmsg_free(msg); | |
6330 | return -ENOBUFS; | |
6331 | } | |
ad649451 JM |
6332 | |
6333 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); | |
6334 | if (!ret) | |
6335 | return 0; | |
ad649451 JM |
6336 | wpa_printf(MSG_DEBUG, "nl80211: Failed to set fragmentation threshold " |
6337 | "%d: %d (%s)", frag, ret, strerror(-ret)); | |
6338 | return ret; | |
c5121837 JM |
6339 | } |
6340 | ||
6341 | ||
c5121837 JM |
6342 | static int i802_flush(void *priv) |
6343 | { | |
a2e40bb6 | 6344 | struct i802_bss *bss = priv; |
c5121837 | 6345 | struct nl_msg *msg; |
82554b10 | 6346 | int res; |
c5121837 | 6347 | |
83e7bb0e JM |
6348 | wpa_printf(MSG_DEBUG, "nl80211: flush -> DEL_STATION %s (all)", |
6349 | bss->ifname); | |
c5121837 JM |
6350 | |
6351 | /* | |
6352 | * XXX: FIX! this needs to flush all VLANs too | |
6353 | */ | |
13f83980 JM |
6354 | msg = nl80211_bss_msg(bss, 0, NL80211_CMD_DEL_STATION); |
6355 | res = send_and_recv_msgs(bss->drv, msg, NULL, NULL); | |
82554b10 JM |
6356 | if (res) { |
6357 | wpa_printf(MSG_DEBUG, "nl80211: Station flush failed: ret=%d " | |
6358 | "(%s)", res, strerror(-res)); | |
6359 | } | |
6360 | return res; | |
c5121837 JM |
6361 | } |
6362 | ||
6363 | ||
1d6f6385 THJ |
6364 | static void get_sta_tid_stats(struct hostap_sta_driver_data *data, |
6365 | struct nlattr *attr) | |
6366 | { | |
6367 | struct nlattr *tid_stats[NL80211_TID_STATS_MAX + 1], *tidattr; | |
6368 | struct nlattr *txq_stats[NL80211_TXQ_STATS_MAX + 1]; | |
6369 | static struct nla_policy txq_stats_policy[NL80211_TXQ_STATS_MAX + 1] = { | |
6370 | [NL80211_TXQ_STATS_BACKLOG_BYTES] = { .type = NLA_U32 }, | |
6371 | [NL80211_TXQ_STATS_BACKLOG_PACKETS] = { .type = NLA_U32 }, | |
6372 | }; | |
6373 | int rem; | |
6374 | ||
6375 | nla_for_each_nested(tidattr, attr, rem) { | |
6376 | if (nla_parse_nested(tid_stats, NL80211_TID_STATS_MAX, | |
6377 | tidattr, NULL) != 0 || | |
6378 | !tid_stats[NL80211_TID_STATS_TXQ_STATS] || | |
6379 | nla_parse_nested(txq_stats, NL80211_TXQ_STATS_MAX, | |
6380 | tid_stats[NL80211_TID_STATS_TXQ_STATS], | |
6381 | txq_stats_policy) != 0) | |
6382 | continue; | |
6383 | /* sum the backlogs over all TIDs for station */ | |
6384 | if (txq_stats[NL80211_TXQ_STATS_BACKLOG_BYTES]) | |
6385 | data->backlog_bytes += nla_get_u32( | |
6386 | txq_stats[NL80211_TXQ_STATS_BACKLOG_BYTES]); | |
6387 | if (txq_stats[NL80211_TXQ_STATS_BACKLOG_PACKETS]) | |
6388 | data->backlog_bytes += nla_get_u32( | |
6389 | txq_stats[NL80211_TXQ_STATS_BACKLOG_PACKETS]); | |
6390 | } | |
6391 | } | |
6392 | ||
6393 | ||
c5121837 JM |
6394 | static int get_sta_handler(struct nl_msg *msg, void *arg) |
6395 | { | |
6396 | struct nlattr *tb[NL80211_ATTR_MAX + 1]; | |
6397 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); | |
6398 | struct hostap_sta_driver_data *data = arg; | |
6399 | struct nlattr *stats[NL80211_STA_INFO_MAX + 1]; | |
6400 | static struct nla_policy stats_policy[NL80211_STA_INFO_MAX + 1] = { | |
6401 | [NL80211_STA_INFO_INACTIVE_TIME] = { .type = NLA_U32 }, | |
6402 | [NL80211_STA_INFO_RX_BYTES] = { .type = NLA_U32 }, | |
6403 | [NL80211_STA_INFO_TX_BYTES] = { .type = NLA_U32 }, | |
6404 | [NL80211_STA_INFO_RX_PACKETS] = { .type = NLA_U32 }, | |
6405 | [NL80211_STA_INFO_TX_PACKETS] = { .type = NLA_U32 }, | |
dc7785f8 | 6406 | [NL80211_STA_INFO_TX_FAILED] = { .type = NLA_U32 }, |
43022abd NL |
6407 | [NL80211_STA_INFO_RX_BYTES64] = { .type = NLA_U64 }, |
6408 | [NL80211_STA_INFO_TX_BYTES64] = { .type = NLA_U64 }, | |
3567641e | 6409 | [NL80211_STA_INFO_SIGNAL] = { .type = NLA_U8 }, |
72123a84 | 6410 | [NL80211_STA_INFO_ACK_SIGNAL] = { .type = NLA_U8 }, |
58d4c236 THJ |
6411 | [NL80211_STA_INFO_RX_DURATION] = { .type = NLA_U64 }, |
6412 | [NL80211_STA_INFO_TX_DURATION] = { .type = NLA_U64 }, | |
3567641e | 6413 | }; |
6414 | struct nlattr *rate[NL80211_RATE_INFO_MAX + 1]; | |
6415 | static struct nla_policy rate_policy[NL80211_RATE_INFO_MAX + 1] = { | |
6416 | [NL80211_RATE_INFO_BITRATE] = { .type = NLA_U16 }, | |
6417 | [NL80211_RATE_INFO_BITRATE32] = { .type = NLA_U32 }, | |
6418 | [NL80211_RATE_INFO_MCS] = { .type = NLA_U8 }, | |
6419 | [NL80211_RATE_INFO_VHT_MCS] = { .type = NLA_U8 }, | |
6420 | [NL80211_RATE_INFO_SHORT_GI] = { .type = NLA_FLAG }, | |
6421 | [NL80211_RATE_INFO_VHT_NSS] = { .type = NLA_U8 }, | |
c5121837 JM |
6422 | }; |
6423 | ||
6424 | nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), | |
6425 | genlmsg_attrlen(gnlh, 0), NULL); | |
6426 | ||
6427 | /* | |
6428 | * TODO: validate the interface and mac address! | |
6429 | * Otherwise, there's a race condition as soon as | |
6430 | * the kernel starts sending station notifications. | |
6431 | */ | |
6432 | ||
6433 | if (!tb[NL80211_ATTR_STA_INFO]) { | |
6434 | wpa_printf(MSG_DEBUG, "sta stats missing!"); | |
6435 | return NL_SKIP; | |
6436 | } | |
6437 | if (nla_parse_nested(stats, NL80211_STA_INFO_MAX, | |
6438 | tb[NL80211_ATTR_STA_INFO], | |
6439 | stats_policy)) { | |
6440 | wpa_printf(MSG_DEBUG, "failed to parse nested attributes!"); | |
6441 | return NL_SKIP; | |
6442 | } | |
6443 | ||
6444 | if (stats[NL80211_STA_INFO_INACTIVE_TIME]) | |
6445 | data->inactive_msec = | |
6446 | nla_get_u32(stats[NL80211_STA_INFO_INACTIVE_TIME]); | |
43022abd | 6447 | /* For backwards compatibility, fetch the 32-bit counters first. */ |
c5121837 JM |
6448 | if (stats[NL80211_STA_INFO_RX_BYTES]) |
6449 | data->rx_bytes = nla_get_u32(stats[NL80211_STA_INFO_RX_BYTES]); | |
6450 | if (stats[NL80211_STA_INFO_TX_BYTES]) | |
6451 | data->tx_bytes = nla_get_u32(stats[NL80211_STA_INFO_TX_BYTES]); | |
43022abd NL |
6452 | if (stats[NL80211_STA_INFO_RX_BYTES64] && |
6453 | stats[NL80211_STA_INFO_TX_BYTES64]) { | |
6454 | /* | |
6455 | * The driver supports 64-bit counters, so use them to override | |
6456 | * the 32-bit values. | |
6457 | */ | |
6458 | data->rx_bytes = | |
6459 | nla_get_u64(stats[NL80211_STA_INFO_RX_BYTES64]); | |
6460 | data->tx_bytes = | |
6461 | nla_get_u64(stats[NL80211_STA_INFO_TX_BYTES64]); | |
6462 | data->bytes_64bit = 1; | |
6463 | } | |
c5121837 JM |
6464 | if (stats[NL80211_STA_INFO_RX_PACKETS]) |
6465 | data->rx_packets = | |
6466 | nla_get_u32(stats[NL80211_STA_INFO_RX_PACKETS]); | |
6467 | if (stats[NL80211_STA_INFO_TX_PACKETS]) | |
6468 | data->tx_packets = | |
6469 | nla_get_u32(stats[NL80211_STA_INFO_TX_PACKETS]); | |
58d4c236 THJ |
6470 | if (stats[NL80211_STA_INFO_RX_DURATION]) |
6471 | data->rx_airtime = | |
6472 | nla_get_u64(stats[NL80211_STA_INFO_RX_DURATION]); | |
6473 | if (stats[NL80211_STA_INFO_TX_DURATION]) | |
6474 | data->tx_airtime = | |
6475 | nla_get_u64(stats[NL80211_STA_INFO_TX_DURATION]); | |
dc7785f8 YZ |
6476 | if (stats[NL80211_STA_INFO_TX_FAILED]) |
6477 | data->tx_retry_failed = | |
6478 | nla_get_u32(stats[NL80211_STA_INFO_TX_FAILED]); | |
3567641e | 6479 | if (stats[NL80211_STA_INFO_SIGNAL]) |
6480 | data->signal = nla_get_u8(stats[NL80211_STA_INFO_SIGNAL]); | |
72123a84 BP |
6481 | if (stats[NL80211_STA_INFO_ACK_SIGNAL]) { |
6482 | data->last_ack_rssi = | |
6483 | nla_get_u8(stats[NL80211_STA_INFO_ACK_SIGNAL]); | |
6484 | data->flags |= STA_DRV_DATA_LAST_ACK_RSSI; | |
6485 | } | |
3567641e | 6486 | |
6487 | if (stats[NL80211_STA_INFO_TX_BITRATE] && | |
6488 | nla_parse_nested(rate, NL80211_RATE_INFO_MAX, | |
6489 | stats[NL80211_STA_INFO_TX_BITRATE], | |
6490 | rate_policy) == 0) { | |
6491 | if (rate[NL80211_RATE_INFO_BITRATE32]) | |
6492 | data->current_tx_rate = | |
6493 | nla_get_u32(rate[NL80211_RATE_INFO_BITRATE32]); | |
6494 | else if (rate[NL80211_RATE_INFO_BITRATE]) | |
6495 | data->current_tx_rate = | |
6496 | nla_get_u16(rate[NL80211_RATE_INFO_BITRATE]); | |
6497 | ||
6498 | if (rate[NL80211_RATE_INFO_MCS]) { | |
6499 | data->tx_mcs = nla_get_u8(rate[NL80211_RATE_INFO_MCS]); | |
6500 | data->flags |= STA_DRV_DATA_TX_MCS; | |
6501 | } | |
6502 | if (rate[NL80211_RATE_INFO_VHT_MCS]) { | |
6503 | data->tx_vhtmcs = | |
6504 | nla_get_u8(rate[NL80211_RATE_INFO_VHT_MCS]); | |
6505 | data->flags |= STA_DRV_DATA_TX_VHT_MCS; | |
6506 | } | |
6507 | if (rate[NL80211_RATE_INFO_SHORT_GI]) | |
6508 | data->flags |= STA_DRV_DATA_TX_SHORT_GI; | |
6509 | if (rate[NL80211_RATE_INFO_VHT_NSS]) { | |
6510 | data->tx_vht_nss = | |
6511 | nla_get_u8(rate[NL80211_RATE_INFO_VHT_NSS]); | |
6512 | data->flags |= STA_DRV_DATA_TX_VHT_NSS; | |
6513 | } | |
6514 | } | |
6515 | ||
6516 | if (stats[NL80211_STA_INFO_RX_BITRATE] && | |
6517 | nla_parse_nested(rate, NL80211_RATE_INFO_MAX, | |
6518 | stats[NL80211_STA_INFO_RX_BITRATE], | |
6519 | rate_policy) == 0) { | |
6520 | if (rate[NL80211_RATE_INFO_BITRATE32]) | |
6521 | data->current_rx_rate = | |
6522 | nla_get_u32(rate[NL80211_RATE_INFO_BITRATE32]); | |
6523 | else if (rate[NL80211_RATE_INFO_BITRATE]) | |
6524 | data->current_rx_rate = | |
6525 | nla_get_u16(rate[NL80211_RATE_INFO_BITRATE]); | |
6526 | ||
6527 | if (rate[NL80211_RATE_INFO_MCS]) { | |
6528 | data->rx_mcs = | |
6529 | nla_get_u8(rate[NL80211_RATE_INFO_MCS]); | |
6530 | data->flags |= STA_DRV_DATA_RX_MCS; | |
6531 | } | |
6532 | if (rate[NL80211_RATE_INFO_VHT_MCS]) { | |
6533 | data->rx_vhtmcs = | |
6534 | nla_get_u8(rate[NL80211_RATE_INFO_VHT_MCS]); | |
6535 | data->flags |= STA_DRV_DATA_RX_VHT_MCS; | |
6536 | } | |
6537 | if (rate[NL80211_RATE_INFO_SHORT_GI]) | |
6538 | data->flags |= STA_DRV_DATA_RX_SHORT_GI; | |
6539 | if (rate[NL80211_RATE_INFO_VHT_NSS]) { | |
6540 | data->rx_vht_nss = | |
6541 | nla_get_u8(rate[NL80211_RATE_INFO_VHT_NSS]); | |
6542 | data->flags |= STA_DRV_DATA_RX_VHT_NSS; | |
6543 | } | |
6544 | } | |
c5121837 | 6545 | |
1d6f6385 THJ |
6546 | if (stats[NL80211_STA_INFO_TID_STATS]) |
6547 | get_sta_tid_stats(data, stats[NL80211_STA_INFO_TID_STATS]); | |
6548 | ||
c5121837 JM |
6549 | return NL_SKIP; |
6550 | } | |
6551 | ||
9ebce9c5 JM |
6552 | static int i802_read_sta_data(struct i802_bss *bss, |
6553 | struct hostap_sta_driver_data *data, | |
c5121837 JM |
6554 | const u8 *addr) |
6555 | { | |
c5121837 JM |
6556 | struct nl_msg *msg; |
6557 | ||
13f83980 JM |
6558 | if (!(msg = nl80211_bss_msg(bss, 0, NL80211_CMD_GET_STATION)) || |
6559 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) { | |
a862e4a3 JM |
6560 | nlmsg_free(msg); |
6561 | return -ENOBUFS; | |
6562 | } | |
c5121837 | 6563 | |
13f83980 | 6564 | return send_and_recv_msgs(bss->drv, msg, get_sta_handler, data); |
c5121837 JM |
6565 | } |
6566 | ||
6567 | ||
c5121837 JM |
6568 | static int i802_set_tx_queue_params(void *priv, int queue, int aifs, |
6569 | int cw_min, int cw_max, int burst_time) | |
6570 | { | |
a2e40bb6 FF |
6571 | struct i802_bss *bss = priv; |
6572 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
c5121837 JM |
6573 | struct nl_msg *msg; |
6574 | struct nlattr *txq, *params; | |
bd512469 | 6575 | int res; |
c5121837 | 6576 | |
13f83980 | 6577 | msg = nl80211_bss_msg(bss, 0, NL80211_CMD_SET_WIPHY); |
c5121837 JM |
6578 | if (!msg) |
6579 | return -1; | |
6580 | ||
c5121837 JM |
6581 | txq = nla_nest_start(msg, NL80211_ATTR_WIPHY_TXQ_PARAMS); |
6582 | if (!txq) | |
a862e4a3 | 6583 | goto fail; |
c5121837 JM |
6584 | |
6585 | /* We are only sending parameters for a single TXQ at a time */ | |
6586 | params = nla_nest_start(msg, 1); | |
6587 | if (!params) | |
a862e4a3 | 6588 | goto fail; |
c5121837 | 6589 | |
7e3c1781 JM |
6590 | switch (queue) { |
6591 | case 0: | |
a862e4a3 JM |
6592 | if (nla_put_u8(msg, NL80211_TXQ_ATTR_QUEUE, NL80211_TXQ_Q_VO)) |
6593 | goto fail; | |
7e3c1781 JM |
6594 | break; |
6595 | case 1: | |
a862e4a3 JM |
6596 | if (nla_put_u8(msg, NL80211_TXQ_ATTR_QUEUE, NL80211_TXQ_Q_VI)) |
6597 | goto fail; | |
7e3c1781 JM |
6598 | break; |
6599 | case 2: | |
a862e4a3 JM |
6600 | if (nla_put_u8(msg, NL80211_TXQ_ATTR_QUEUE, NL80211_TXQ_Q_BE)) |
6601 | goto fail; | |
7e3c1781 JM |
6602 | break; |
6603 | case 3: | |
a862e4a3 JM |
6604 | if (nla_put_u8(msg, NL80211_TXQ_ATTR_QUEUE, NL80211_TXQ_Q_BK)) |
6605 | goto fail; | |
7e3c1781 JM |
6606 | break; |
6607 | } | |
c5121837 JM |
6608 | /* Burst time is configured in units of 0.1 msec and TXOP parameter in |
6609 | * 32 usec, so need to convert the value here. */ | |
a862e4a3 JM |
6610 | if (nla_put_u16(msg, NL80211_TXQ_ATTR_TXOP, |
6611 | (burst_time * 100 + 16) / 32) || | |
6612 | nla_put_u16(msg, NL80211_TXQ_ATTR_CWMIN, cw_min) || | |
6613 | nla_put_u16(msg, NL80211_TXQ_ATTR_CWMAX, cw_max) || | |
6614 | nla_put_u8(msg, NL80211_TXQ_ATTR_AIFS, aifs)) | |
6615 | goto fail; | |
c5121837 JM |
6616 | |
6617 | nla_nest_end(msg, params); | |
6618 | ||
6619 | nla_nest_end(msg, txq); | |
6620 | ||
bd512469 JM |
6621 | res = send_and_recv_msgs(drv, msg, NULL, NULL); |
6622 | wpa_printf(MSG_DEBUG, | |
6623 | "nl80211: TX queue param set: queue=%d aifs=%d cw_min=%d cw_max=%d burst_time=%d --> res=%d", | |
6624 | queue, aifs, cw_min, cw_max, burst_time, res); | |
6625 | if (res == 0) | |
c5121837 | 6626 | return 0; |
9e088e74 | 6627 | msg = NULL; |
a862e4a3 | 6628 | fail: |
9e088e74 | 6629 | nlmsg_free(msg); |
c5121837 JM |
6630 | return -1; |
6631 | } | |
6632 | ||
6633 | ||
9ebce9c5 | 6634 | static int i802_set_sta_vlan(struct i802_bss *bss, const u8 *addr, |
c5121837 JM |
6635 | const char *ifname, int vlan_id) |
6636 | { | |
a2e40bb6 | 6637 | struct wpa_driver_nl80211_data *drv = bss->drv; |
c5121837 | 6638 | struct nl_msg *msg; |
a862e4a3 | 6639 | int ret; |
c5121837 | 6640 | |
bbc706a3 JM |
6641 | wpa_printf(MSG_DEBUG, "nl80211: %s[%d]: set_sta_vlan(" MACSTR |
6642 | ", ifname=%s[%d], vlan_id=%d)", | |
6643 | bss->ifname, if_nametoindex(bss->ifname), | |
6644 | MAC2STR(addr), ifname, if_nametoindex(ifname), vlan_id); | |
13f83980 | 6645 | if (!(msg = nl80211_bss_msg(bss, 0, NL80211_CMD_SET_STATION)) || |
a862e4a3 JM |
6646 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) || |
6647 | nla_put_u32(msg, NL80211_ATTR_STA_VLAN, if_nametoindex(ifname))) { | |
6648 | nlmsg_free(msg); | |
6649 | return -ENOBUFS; | |
6650 | } | |
c5121837 | 6651 | |
cd1d72c1 JM |
6652 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
6653 | if (ret < 0) { | |
6654 | wpa_printf(MSG_ERROR, "nl80211: NL80211_ATTR_STA_VLAN (addr=" | |
6655 | MACSTR " ifname=%s vlan_id=%d) failed: %d (%s)", | |
6656 | MAC2STR(addr), ifname, vlan_id, ret, | |
6657 | strerror(-ret)); | |
6658 | } | |
cd1d72c1 | 6659 | return ret; |
c5121837 JM |
6660 | } |
6661 | ||
fbbfcbac | 6662 | |
c5121837 JM |
6663 | static int i802_get_inact_sec(void *priv, const u8 *addr) |
6664 | { | |
6665 | struct hostap_sta_driver_data data; | |
6666 | int ret; | |
6667 | ||
7824bf77 | 6668 | os_memset(&data, 0, sizeof(data)); |
c5121837 JM |
6669 | data.inactive_msec = (unsigned long) -1; |
6670 | ret = i802_read_sta_data(priv, &data, addr); | |
b9749bac MH |
6671 | if (ret == -ENOENT) |
6672 | return -ENOENT; | |
c5121837 JM |
6673 | if (ret || data.inactive_msec == (unsigned long) -1) |
6674 | return -1; | |
6675 | return data.inactive_msec / 1000; | |
6676 | } | |
6677 | ||
6678 | ||
6679 | static int i802_sta_clear_stats(void *priv, const u8 *addr) | |
6680 | { | |
6681 | #if 0 | |
6682 | /* TODO */ | |
6683 | #endif | |
6684 | return 0; | |
6685 | } | |
6686 | ||
6687 | ||
731723a5 | 6688 | static int i802_sta_deauth(void *priv, const u8 *own_addr, const u8 *addr, |
4be17ffb | 6689 | u16 reason) |
c5121837 | 6690 | { |
a2e40bb6 | 6691 | struct i802_bss *bss = priv; |
e1bd4e19 | 6692 | struct wpa_driver_nl80211_data *drv = bss->drv; |
c5121837 | 6693 | struct ieee80211_mgmt mgmt; |
05e5e615 DL |
6694 | u8 channel; |
6695 | ||
6696 | if (ieee80211_freq_to_chan(bss->freq, &channel) == | |
6697 | HOSTAPD_MODE_IEEE80211AD) { | |
6698 | /* Deauthentication is not used in DMG/IEEE 802.11ad; | |
6699 | * disassociate the STA instead. */ | |
6700 | return i802_sta_disassoc(priv, own_addr, addr, reason); | |
6701 | } | |
c5121837 | 6702 | |
0d391b03 BC |
6703 | if (is_mesh_interface(drv->nlmode)) |
6704 | return -1; | |
6705 | ||
e1bd4e19 | 6706 | if (drv->device_ap_sme) |
59d7148a | 6707 | return wpa_driver_nl80211_sta_remove(bss, addr, 1, reason); |
e1bd4e19 | 6708 | |
c5121837 JM |
6709 | memset(&mgmt, 0, sizeof(mgmt)); |
6710 | mgmt.frame_control = IEEE80211_FC(WLAN_FC_TYPE_MGMT, | |
6711 | WLAN_FC_STYPE_DEAUTH); | |
6712 | memcpy(mgmt.da, addr, ETH_ALEN); | |
731723a5 JM |
6713 | memcpy(mgmt.sa, own_addr, ETH_ALEN); |
6714 | memcpy(mgmt.bssid, own_addr, ETH_ALEN); | |
c5121837 | 6715 | mgmt.u.deauth.reason_code = host_to_le16(reason); |
a2e40bb6 | 6716 | return wpa_driver_nl80211_send_mlme(bss, (u8 *) &mgmt, |
9f324b61 | 6717 | IEEE80211_HDRLEN + |
9ebce9c5 | 6718 | sizeof(mgmt.u.deauth), 0, 0, 0, 0, |
2d3943ce | 6719 | 0, NULL, 0); |
c5121837 JM |
6720 | } |
6721 | ||
6722 | ||
731723a5 | 6723 | static int i802_sta_disassoc(void *priv, const u8 *own_addr, const u8 *addr, |
4be17ffb | 6724 | u16 reason) |
c5121837 | 6725 | { |
a2e40bb6 | 6726 | struct i802_bss *bss = priv; |
e1bd4e19 | 6727 | struct wpa_driver_nl80211_data *drv = bss->drv; |
c5121837 JM |
6728 | struct ieee80211_mgmt mgmt; |
6729 | ||
0d391b03 BC |
6730 | if (is_mesh_interface(drv->nlmode)) |
6731 | return -1; | |
6732 | ||
e1bd4e19 | 6733 | if (drv->device_ap_sme) |
59d7148a | 6734 | return wpa_driver_nl80211_sta_remove(bss, addr, 0, reason); |
e1bd4e19 | 6735 | |
c5121837 JM |
6736 | memset(&mgmt, 0, sizeof(mgmt)); |
6737 | mgmt.frame_control = IEEE80211_FC(WLAN_FC_TYPE_MGMT, | |
6738 | WLAN_FC_STYPE_DISASSOC); | |
6739 | memcpy(mgmt.da, addr, ETH_ALEN); | |
731723a5 JM |
6740 | memcpy(mgmt.sa, own_addr, ETH_ALEN); |
6741 | memcpy(mgmt.bssid, own_addr, ETH_ALEN); | |
c5121837 | 6742 | mgmt.u.disassoc.reason_code = host_to_le16(reason); |
a2e40bb6 | 6743 | return wpa_driver_nl80211_send_mlme(bss, (u8 *) &mgmt, |
9f324b61 | 6744 | IEEE80211_HDRLEN + |
9ebce9c5 | 6745 | sizeof(mgmt.u.disassoc), 0, 0, 0, 0, |
2d3943ce | 6746 | 0, NULL, 0); |
c5121837 JM |
6747 | } |
6748 | ||
6749 | ||
9b4d9c8b JM |
6750 | static void dump_ifidx(struct wpa_driver_nl80211_data *drv) |
6751 | { | |
6752 | char buf[200], *pos, *end; | |
6753 | int i, res; | |
6754 | ||
6755 | pos = buf; | |
6756 | end = pos + sizeof(buf); | |
6757 | ||
6758 | for (i = 0; i < drv->num_if_indices; i++) { | |
099224c1 | 6759 | if (!drv->if_indices[i].ifindex) |
9b4d9c8b | 6760 | continue; |
732b1d20 | 6761 | res = os_snprintf(pos, end - pos, " %d(%d)", |
099224c1 JM |
6762 | drv->if_indices[i].ifindex, |
6763 | drv->if_indices[i].reason); | |
d85e1fc8 | 6764 | if (os_snprintf_error(end - pos, res)) |
9b4d9c8b JM |
6765 | break; |
6766 | pos += res; | |
6767 | } | |
6768 | *pos = '\0'; | |
6769 | ||
6770 | wpa_printf(MSG_DEBUG, "nl80211: if_indices[%d]:%s", | |
6771 | drv->num_if_indices, buf); | |
6772 | } | |
6773 | ||
6774 | ||
732b1d20 MB |
6775 | static void add_ifidx(struct wpa_driver_nl80211_data *drv, int ifidx, |
6776 | int ifidx_reason) | |
f07ead6a JM |
6777 | { |
6778 | int i; | |
099224c1 | 6779 | struct drv_nl80211_if_info *old; |
f07ead6a | 6780 | |
732b1d20 MB |
6781 | wpa_printf(MSG_DEBUG, |
6782 | "nl80211: Add own interface ifindex %d (ifidx_reason %d)", | |
6783 | ifidx, ifidx_reason); | |
6784 | if (have_ifidx(drv, ifidx, ifidx_reason)) { | |
b36935be MB |
6785 | wpa_printf(MSG_DEBUG, "nl80211: ifindex %d already in the list", |
6786 | ifidx); | |
6787 | return; | |
6788 | } | |
f07ead6a | 6789 | for (i = 0; i < drv->num_if_indices; i++) { |
099224c1 JM |
6790 | if (drv->if_indices[i].ifindex == 0) { |
6791 | drv->if_indices[i].ifindex = ifidx; | |
6792 | drv->if_indices[i].reason = ifidx_reason; | |
9b4d9c8b | 6793 | dump_ifidx(drv); |
f07ead6a JM |
6794 | return; |
6795 | } | |
6796 | } | |
6797 | ||
6798 | if (drv->if_indices != drv->default_if_indices) | |
6799 | old = drv->if_indices; | |
6800 | else | |
6801 | old = NULL; | |
6802 | ||
067ffa26 | 6803 | drv->if_indices = os_realloc_array(old, drv->num_if_indices + 1, |
099224c1 | 6804 | sizeof(*old)); |
f07ead6a JM |
6805 | if (!drv->if_indices) { |
6806 | if (!old) | |
6807 | drv->if_indices = drv->default_if_indices; | |
6808 | else | |
6809 | drv->if_indices = old; | |
6810 | wpa_printf(MSG_ERROR, "Failed to reallocate memory for " | |
6811 | "interfaces"); | |
6812 | wpa_printf(MSG_ERROR, "Ignoring EAPOL on interface %d", ifidx); | |
6813 | return; | |
732b1d20 MB |
6814 | } |
6815 | if (!old) | |
f07ead6a JM |
6816 | os_memcpy(drv->if_indices, drv->default_if_indices, |
6817 | sizeof(drv->default_if_indices)); | |
099224c1 JM |
6818 | drv->if_indices[drv->num_if_indices].ifindex = ifidx; |
6819 | drv->if_indices[drv->num_if_indices].reason = ifidx_reason; | |
f07ead6a | 6820 | drv->num_if_indices++; |
9b4d9c8b | 6821 | dump_ifidx(drv); |
f07ead6a JM |
6822 | } |
6823 | ||
6824 | ||
732b1d20 MB |
6825 | static void del_ifidx(struct wpa_driver_nl80211_data *drv, int ifidx, |
6826 | int ifidx_reason) | |
f07ead6a JM |
6827 | { |
6828 | int i; | |
6829 | ||
6830 | for (i = 0; i < drv->num_if_indices; i++) { | |
099224c1 JM |
6831 | if ((drv->if_indices[i].ifindex == ifidx || |
6832 | ifidx == IFIDX_ANY) && | |
6833 | (drv->if_indices[i].reason == ifidx_reason || | |
732b1d20 | 6834 | ifidx_reason == IFIDX_ANY)) { |
099224c1 JM |
6835 | drv->if_indices[i].ifindex = 0; |
6836 | drv->if_indices[i].reason = 0; | |
f07ead6a JM |
6837 | break; |
6838 | } | |
6839 | } | |
9b4d9c8b | 6840 | dump_ifidx(drv); |
f07ead6a JM |
6841 | } |
6842 | ||
6843 | ||
732b1d20 MB |
6844 | static int have_ifidx(struct wpa_driver_nl80211_data *drv, int ifidx, |
6845 | int ifidx_reason) | |
f07ead6a JM |
6846 | { |
6847 | int i; | |
6848 | ||
6849 | for (i = 0; i < drv->num_if_indices; i++) | |
099224c1 JM |
6850 | if (drv->if_indices[i].ifindex == ifidx && |
6851 | (drv->if_indices[i].reason == ifidx_reason || | |
732b1d20 | 6852 | ifidx_reason == IFIDX_ANY)) |
f07ead6a JM |
6853 | return 1; |
6854 | ||
6855 | return 0; | |
6856 | } | |
6857 | ||
6858 | ||
6859 | static int i802_set_wds_sta(void *priv, const u8 *addr, int aid, int val, | |
0e80ea2c | 6860 | const char *bridge_ifname, char *ifname_wds) |
f07ead6a JM |
6861 | { |
6862 | struct i802_bss *bss = priv; | |
6863 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
6864 | char name[IFNAMSIZ + 1]; | |
1952b626 | 6865 | union wpa_event_data event; |
d577f7f3 AO |
6866 | int ret; |
6867 | ||
6868 | ret = os_snprintf(name, sizeof(name), "%s.sta%d", bss->ifname, aid); | |
6869 | if (ret >= (int) sizeof(name)) | |
6870 | wpa_printf(MSG_WARNING, | |
6871 | "nl80211: WDS interface name was truncated"); | |
6872 | else if (ret < 0) | |
6873 | return ret; | |
f07ead6a | 6874 | |
69dd2967 SM |
6875 | if (ifname_wds) |
6876 | os_strlcpy(ifname_wds, name, IFNAMSIZ + 1); | |
6877 | ||
f07ead6a JM |
6878 | wpa_printf(MSG_DEBUG, "nl80211: Set WDS STA addr=" MACSTR |
6879 | " aid=%d val=%d name=%s", MAC2STR(addr), aid, val, name); | |
6880 | if (val) { | |
6881 | if (!if_nametoindex(name)) { | |
6882 | if (nl80211_create_iface(drv, name, | |
6883 | NL80211_IFTYPE_AP_VLAN, | |
2aec4f3c JM |
6884 | bss->addr, 1, NULL, NULL, 0) < |
6885 | 0) | |
f07ead6a JM |
6886 | return -1; |
6887 | if (bridge_ifname && | |
c81eff1a BG |
6888 | linux_br_add_if(drv->global->ioctl_sock, |
6889 | bridge_ifname, name) < 0) | |
f07ead6a | 6890 | return -1; |
1952b626 BP |
6891 | |
6892 | os_memset(&event, 0, sizeof(event)); | |
6893 | event.wds_sta_interface.sta_addr = addr; | |
6894 | event.wds_sta_interface.ifname = name; | |
6895 | event.wds_sta_interface.istatus = INTERFACE_ADDED; | |
8bfbb295 | 6896 | wpa_supplicant_event(bss->ctx, |
1952b626 BP |
6897 | EVENT_WDS_STA_INTERFACE_STATUS, |
6898 | &event); | |
f07ead6a | 6899 | } |
75227f3a JM |
6900 | if (linux_set_iface_flags(drv->global->ioctl_sock, name, 1)) { |
6901 | wpa_printf(MSG_ERROR, "nl80211: Failed to set WDS STA " | |
6902 | "interface %s up", name); | |
6903 | } | |
f07ead6a JM |
6904 | return i802_set_sta_vlan(priv, addr, name, 0); |
6905 | } else { | |
f9052d6e JM |
6906 | if (bridge_ifname && |
6907 | linux_br_del_if(drv->global->ioctl_sock, bridge_ifname, | |
6908 | name) < 0) | |
6909 | wpa_printf(MSG_INFO, | |
6910 | "nl80211: Failed to remove interface %s from bridge %s: %s", | |
6911 | name, bridge_ifname, strerror(errno)); | |
c34e618d | 6912 | |
f07ead6a | 6913 | i802_set_sta_vlan(priv, addr, bss->ifname, 0); |
d0595b25 | 6914 | nl80211_remove_iface(drv, if_nametoindex(name)); |
1952b626 BP |
6915 | os_memset(&event, 0, sizeof(event)); |
6916 | event.wds_sta_interface.sta_addr = addr; | |
6917 | event.wds_sta_interface.ifname = name; | |
6918 | event.wds_sta_interface.istatus = INTERFACE_REMOVED; | |
8bfbb295 | 6919 | wpa_supplicant_event(bss->ctx, EVENT_WDS_STA_INTERFACE_STATUS, |
1952b626 | 6920 | &event); |
d0595b25 | 6921 | return 0; |
f07ead6a JM |
6922 | } |
6923 | } | |
6924 | ||
6925 | ||
6926 | static void handle_eapol(int sock, void *eloop_ctx, void *sock_ctx) | |
6927 | { | |
6928 | struct wpa_driver_nl80211_data *drv = eloop_ctx; | |
6929 | struct sockaddr_ll lladdr; | |
6930 | unsigned char buf[3000]; | |
6931 | int len; | |
6932 | socklen_t fromlen = sizeof(lladdr); | |
6933 | ||
6934 | len = recvfrom(sock, buf, sizeof(buf), 0, | |
6935 | (struct sockaddr *)&lladdr, &fromlen); | |
6936 | if (len < 0) { | |
7ac3616d JM |
6937 | wpa_printf(MSG_ERROR, "nl80211: EAPOL recv failed: %s", |
6938 | strerror(errno)); | |
f07ead6a JM |
6939 | return; |
6940 | } | |
6941 | ||
732b1d20 | 6942 | if (have_ifidx(drv, lladdr.sll_ifindex, IFIDX_ANY)) |
f07ead6a JM |
6943 | drv_event_eapol_rx(drv->ctx, lladdr.sll_addr, buf, len); |
6944 | } | |
6945 | ||
6946 | ||
94627f6c | 6947 | static int i802_check_bridge(struct wpa_driver_nl80211_data *drv, |
e17a2477 | 6948 | struct i802_bss *bss, |
94627f6c JM |
6949 | const char *brname, const char *ifname) |
6950 | { | |
6c6678e7 | 6951 | int br_ifindex; |
94627f6c JM |
6952 | char in_br[IFNAMSIZ]; |
6953 | ||
e17a2477 | 6954 | os_strlcpy(bss->brname, brname, IFNAMSIZ); |
6c6678e7 | 6955 | br_ifindex = if_nametoindex(brname); |
6c6678e7 | 6956 | if (br_ifindex == 0) { |
94627f6c JM |
6957 | /* |
6958 | * Bridge was configured, but the bridge device does | |
6959 | * not exist. Try to add it now. | |
6960 | */ | |
c81eff1a | 6961 | if (linux_br_add(drv->global->ioctl_sock, brname) < 0) { |
94627f6c JM |
6962 | wpa_printf(MSG_ERROR, "nl80211: Failed to add the " |
6963 | "bridge interface %s: %s", | |
6964 | brname, strerror(errno)); | |
6965 | return -1; | |
6966 | } | |
e17a2477 | 6967 | bss->added_bridge = 1; |
8997613c | 6968 | br_ifindex = if_nametoindex(brname); |
732b1d20 | 6969 | add_ifidx(drv, br_ifindex, drv->ifindex); |
94627f6c | 6970 | } |
8997613c | 6971 | bss->br_ifindex = br_ifindex; |
94627f6c JM |
6972 | |
6973 | if (linux_br_get(in_br, ifname) == 0) { | |
c809756f SM |
6974 | if (os_strcmp(in_br, brname) == 0) { |
6975 | bss->already_in_bridge = 1; | |
94627f6c | 6976 | return 0; /* already in the bridge */ |
c809756f | 6977 | } |
94627f6c JM |
6978 | |
6979 | wpa_printf(MSG_DEBUG, "nl80211: Removing interface %s from " | |
6980 | "bridge %s", ifname, in_br); | |
c81eff1a BG |
6981 | if (linux_br_del_if(drv->global->ioctl_sock, in_br, ifname) < |
6982 | 0) { | |
94627f6c JM |
6983 | wpa_printf(MSG_ERROR, "nl80211: Failed to " |
6984 | "remove interface %s from bridge " | |
6985 | "%s: %s", | |
fdbfb63e | 6986 | ifname, in_br, strerror(errno)); |
94627f6c JM |
6987 | return -1; |
6988 | } | |
6989 | } | |
6990 | ||
6991 | wpa_printf(MSG_DEBUG, "nl80211: Adding interface %s into bridge %s", | |
6992 | ifname, brname); | |
c81eff1a | 6993 | if (linux_br_add_if(drv->global->ioctl_sock, brname, ifname) < 0) { |
94627f6c JM |
6994 | wpa_printf(MSG_ERROR, "nl80211: Failed to add interface %s " |
6995 | "into bridge %s: %s", | |
6996 | ifname, brname, strerror(errno)); | |
6997 | return -1; | |
6998 | } | |
e17a2477 | 6999 | bss->added_if_into_bridge = 1; |
94627f6c JM |
7000 | |
7001 | return 0; | |
7002 | } | |
7003 | ||
7004 | ||
92f475b4 JM |
7005 | static void *i802_init(struct hostapd_data *hapd, |
7006 | struct wpa_init_params *params) | |
c5121837 JM |
7007 | { |
7008 | struct wpa_driver_nl80211_data *drv; | |
a2e40bb6 | 7009 | struct i802_bss *bss; |
c5121837 | 7010 | size_t i; |
cb05808c AN |
7011 | char master_ifname[IFNAMSIZ]; |
7012 | int ifindex, br_ifindex = 0; | |
94627f6c | 7013 | int br_added = 0; |
c5121837 | 7014 | |
0d547d5f JM |
7015 | bss = wpa_driver_nl80211_drv_init(hapd, params->ifname, |
7016 | params->global_priv, 1, | |
0ecff8d7 | 7017 | params->bssid, params->driver_params); |
a2e40bb6 | 7018 | if (bss == NULL) |
c5121837 | 7019 | return NULL; |
c5121837 | 7020 | |
a2e40bb6 | 7021 | drv = bss->drv; |
7635bfb0 | 7022 | |
cb05808c | 7023 | if (linux_br_get(master_ifname, params->ifname) == 0) { |
94627f6c | 7024 | wpa_printf(MSG_DEBUG, "nl80211: Interface %s is in bridge %s", |
cb05808c AN |
7025 | params->ifname, master_ifname); |
7026 | br_ifindex = if_nametoindex(master_ifname); | |
7027 | os_strlcpy(bss->brname, master_ifname, IFNAMSIZ); | |
7028 | } else if ((params->num_bridge == 0 || !params->bridge[0]) && | |
7029 | linux_master_get(master_ifname, params->ifname) == 0) { | |
7030 | wpa_printf(MSG_DEBUG, "nl80211: Interface %s is in master %s", | |
7031 | params->ifname, master_ifname); | |
7032 | /* start listening for EAPOL on the master interface */ | |
732b1d20 | 7033 | add_ifidx(drv, if_nametoindex(master_ifname), drv->ifindex); |
f2d6c17a DL |
7034 | |
7035 | /* check if master itself is under bridge */ | |
7036 | if (linux_br_get(master_ifname, master_ifname) == 0) { | |
7037 | wpa_printf(MSG_DEBUG, "nl80211: which is in bridge %s", | |
7038 | master_ifname); | |
7039 | br_ifindex = if_nametoindex(master_ifname); | |
7040 | os_strlcpy(bss->brname, master_ifname, IFNAMSIZ); | |
7041 | } | |
94627f6c | 7042 | } else { |
cb05808c | 7043 | master_ifname[0] = '\0'; |
94627f6c | 7044 | } |
cb05808c | 7045 | |
6c6678e7 | 7046 | bss->br_ifindex = br_ifindex; |
94627f6c | 7047 | |
92f475b4 | 7048 | for (i = 0; i < params->num_bridge; i++) { |
94627f6c JM |
7049 | if (params->bridge[i]) { |
7050 | ifindex = if_nametoindex(params->bridge[i]); | |
7051 | if (ifindex) | |
732b1d20 | 7052 | add_ifidx(drv, ifindex, drv->ifindex); |
94627f6c JM |
7053 | if (ifindex == br_ifindex) |
7054 | br_added = 1; | |
7055 | } | |
c5121837 | 7056 | } |
c5121837 | 7057 | |
ad1e68e6 | 7058 | /* start listening for EAPOL on the default AP interface */ |
732b1d20 | 7059 | add_ifidx(drv, drv->ifindex, IFIDX_ANY); |
ad1e68e6 | 7060 | |
5ef8e39f JM |
7061 | if (params->num_bridge && params->bridge[0]) { |
7062 | if (i802_check_bridge(drv, bss, params->bridge[0], | |
7063 | params->ifname) < 0) | |
7064 | goto failed; | |
cb05808c | 7065 | if (os_strcmp(params->bridge[0], master_ifname) != 0) |
5ef8e39f JM |
7066 | br_added = 1; |
7067 | } | |
7068 | ||
7069 | if (!br_added && br_ifindex && | |
7070 | (params->num_bridge == 0 || !params->bridge[0])) | |
732b1d20 | 7071 | add_ifidx(drv, br_ifindex, drv->ifindex); |
94627f6c | 7072 | |
97ed9a06 | 7073 | #ifdef CONFIG_LIBNL3_ROUTE |
c809756f | 7074 | if (bss->added_if_into_bridge || bss->already_in_bridge) { |
97ed9a06 KP |
7075 | drv->rtnl_sk = nl_socket_alloc(); |
7076 | if (drv->rtnl_sk == NULL) { | |
7077 | wpa_printf(MSG_ERROR, "nl80211: Failed to allocate nl_sock"); | |
7078 | goto failed; | |
7079 | } | |
7080 | ||
7081 | if (nl_connect(drv->rtnl_sk, NETLINK_ROUTE)) { | |
7082 | wpa_printf(MSG_ERROR, "nl80211: Failed to connect nl_sock to NETLINK_ROUTE: %s", | |
7083 | strerror(errno)); | |
7084 | goto failed; | |
7085 | } | |
7086 | } | |
7087 | #endif /* CONFIG_LIBNL3_ROUTE */ | |
7088 | ||
ad1e68e6 JM |
7089 | drv->eapol_sock = socket(PF_PACKET, SOCK_DGRAM, htons(ETH_P_PAE)); |
7090 | if (drv->eapol_sock < 0) { | |
7ac3616d JM |
7091 | wpa_printf(MSG_ERROR, "nl80211: socket(PF_PACKET, SOCK_DGRAM, ETH_P_PAE) failed: %s", |
7092 | strerror(errno)); | |
bbaf0837 | 7093 | goto failed; |
ad1e68e6 JM |
7094 | } |
7095 | ||
7096 | if (eloop_register_read_sock(drv->eapol_sock, handle_eapol, drv, NULL)) | |
7097 | { | |
7ac3616d | 7098 | wpa_printf(MSG_INFO, "nl80211: Could not register read socket for eapol"); |
c5121837 | 7099 | goto failed; |
ad1e68e6 JM |
7100 | } |
7101 | ||
c81eff1a BG |
7102 | if (linux_get_ifhwaddr(drv->global->ioctl_sock, bss->ifname, |
7103 | params->own_addr)) | |
bbaf0837 | 7104 | goto failed; |
fee354c7 | 7105 | os_memcpy(drv->perm_addr, params->own_addr, ETH_ALEN); |
c5121837 | 7106 | |
341eebee JB |
7107 | memcpy(bss->addr, params->own_addr, ETH_ALEN); |
7108 | ||
a2e40bb6 | 7109 | return bss; |
c5121837 JM |
7110 | |
7111 | failed: | |
7635bfb0 | 7112 | wpa_driver_nl80211_deinit(bss); |
bbaf0837 JM |
7113 | return NULL; |
7114 | } | |
c5121837 | 7115 | |
c5121837 | 7116 | |
bbaf0837 JM |
7117 | static void i802_deinit(void *priv) |
7118 | { | |
9ebce9c5 JM |
7119 | struct i802_bss *bss = priv; |
7120 | wpa_driver_nl80211_deinit(bss); | |
c5121837 JM |
7121 | } |
7122 | ||
c5121837 | 7123 | |
22a7c9d7 JM |
7124 | static enum nl80211_iftype wpa_driver_nl80211_if_type( |
7125 | enum wpa_driver_if_type type) | |
7126 | { | |
7127 | switch (type) { | |
7128 | case WPA_IF_STATION: | |
9f51b113 | 7129 | return NL80211_IFTYPE_STATION; |
75bde05d JM |
7130 | case WPA_IF_P2P_CLIENT: |
7131 | case WPA_IF_P2P_GROUP: | |
9f51b113 | 7132 | return NL80211_IFTYPE_P2P_CLIENT; |
22a7c9d7 JM |
7133 | case WPA_IF_AP_VLAN: |
7134 | return NL80211_IFTYPE_AP_VLAN; | |
7135 | case WPA_IF_AP_BSS: | |
7136 | return NL80211_IFTYPE_AP; | |
9f51b113 JB |
7137 | case WPA_IF_P2P_GO: |
7138 | return NL80211_IFTYPE_P2P_GO; | |
7aad838c NS |
7139 | case WPA_IF_P2P_DEVICE: |
7140 | return NL80211_IFTYPE_P2P_DEVICE; | |
5b78493f MH |
7141 | case WPA_IF_MESH: |
7142 | return NL80211_IFTYPE_MESH_POINT; | |
98342208 AK |
7143 | default: |
7144 | return -1; | |
22a7c9d7 | 7145 | } |
22a7c9d7 JM |
7146 | } |
7147 | ||
7148 | ||
f2ed8023 JM |
7149 | static int nl80211_addr_in_use(struct nl80211_global *global, const u8 *addr) |
7150 | { | |
7151 | struct wpa_driver_nl80211_data *drv; | |
7152 | dl_list_for_each(drv, &global->interfaces, | |
7153 | struct wpa_driver_nl80211_data, list) { | |
834ee56f | 7154 | if (os_memcmp(addr, drv->first_bss->addr, ETH_ALEN) == 0) |
f2ed8023 JM |
7155 | return 1; |
7156 | } | |
7157 | return 0; | |
7158 | } | |
7159 | ||
7160 | ||
5b78493f | 7161 | static int nl80211_vif_addr(struct wpa_driver_nl80211_data *drv, u8 *new_addr) |
f2ed8023 JM |
7162 | { |
7163 | unsigned int idx; | |
7164 | ||
7165 | if (!drv->global) | |
7166 | return -1; | |
7167 | ||
834ee56f | 7168 | os_memcpy(new_addr, drv->first_bss->addr, ETH_ALEN); |
f2ed8023 | 7169 | for (idx = 0; idx < 64; idx++) { |
834ee56f | 7170 | new_addr[0] = drv->first_bss->addr[0] | 0x02; |
f2ed8023 JM |
7171 | new_addr[0] ^= idx << 2; |
7172 | if (!nl80211_addr_in_use(drv->global, new_addr)) | |
7173 | break; | |
7174 | } | |
7175 | if (idx == 64) | |
7176 | return -1; | |
7177 | ||
5b78493f | 7178 | wpa_printf(MSG_DEBUG, "nl80211: Assigned new virtual interface address " |
f2ed8023 JM |
7179 | MACSTR, MAC2STR(new_addr)); |
7180 | ||
7181 | return 0; | |
7182 | } | |
7183 | ||
7184 | ||
f632e483 AS |
7185 | struct wdev_info { |
7186 | u64 wdev_id; | |
7187 | int wdev_id_set; | |
7188 | u8 macaddr[ETH_ALEN]; | |
7189 | }; | |
7190 | ||
7191 | static int nl80211_wdev_handler(struct nl_msg *msg, void *arg) | |
e472e1b4 AS |
7192 | { |
7193 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); | |
7194 | struct nlattr *tb[NL80211_ATTR_MAX + 1]; | |
f632e483 | 7195 | struct wdev_info *wi = arg; |
e472e1b4 AS |
7196 | |
7197 | nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), | |
7198 | genlmsg_attrlen(gnlh, 0), NULL); | |
7199 | if (tb[NL80211_ATTR_WDEV]) { | |
f632e483 AS |
7200 | wi->wdev_id = nla_get_u64(tb[NL80211_ATTR_WDEV]); |
7201 | wi->wdev_id_set = 1; | |
e472e1b4 AS |
7202 | } |
7203 | ||
7204 | if (tb[NL80211_ATTR_MAC]) | |
f632e483 | 7205 | os_memcpy(wi->macaddr, nla_data(tb[NL80211_ATTR_MAC]), |
e472e1b4 AS |
7206 | ETH_ALEN); |
7207 | ||
7208 | return NL_SKIP; | |
7209 | } | |
7210 | ||
7211 | ||
7ab68865 | 7212 | static int wpa_driver_nl80211_if_add(void *priv, enum wpa_driver_if_type type, |
8043e725 | 7213 | const char *ifname, const u8 *addr, |
f3585c8a | 7214 | void *bss_ctx, void **drv_priv, |
e17a2477 | 7215 | char *force_ifname, u8 *if_addr, |
d8a3b66d AS |
7216 | const char *bridge, int use_existing, |
7217 | int setup_ap) | |
22a7c9d7 | 7218 | { |
e472e1b4 | 7219 | enum nl80211_iftype nlmode; |
a2e40bb6 FF |
7220 | struct i802_bss *bss = priv; |
7221 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
22a7c9d7 | 7222 | int ifidx; |
2aec4f3c | 7223 | int added = 1; |
22a7c9d7 | 7224 | |
f3585c8a JM |
7225 | if (addr) |
7226 | os_memcpy(if_addr, addr, ETH_ALEN); | |
e472e1b4 AS |
7227 | nlmode = wpa_driver_nl80211_if_type(type); |
7228 | if (nlmode == NL80211_IFTYPE_P2P_DEVICE) { | |
f632e483 AS |
7229 | struct wdev_info p2pdev_info; |
7230 | ||
7231 | os_memset(&p2pdev_info, 0, sizeof(p2pdev_info)); | |
e472e1b4 | 7232 | ifidx = nl80211_create_iface(drv, ifname, nlmode, addr, |
f632e483 | 7233 | 0, nl80211_wdev_handler, |
2aec4f3c | 7234 | &p2pdev_info, use_existing); |
f632e483 | 7235 | if (!p2pdev_info.wdev_id_set || ifidx != 0) { |
e472e1b4 AS |
7236 | wpa_printf(MSG_ERROR, "nl80211: Failed to create a P2P Device interface %s", |
7237 | ifname); | |
e472e1b4 AS |
7238 | return -1; |
7239 | } | |
f632e483 AS |
7240 | |
7241 | drv->global->if_add_wdevid = p2pdev_info.wdev_id; | |
7242 | drv->global->if_add_wdevid_set = p2pdev_info.wdev_id_set; | |
7243 | if (!is_zero_ether_addr(p2pdev_info.macaddr)) | |
7244 | os_memcpy(if_addr, p2pdev_info.macaddr, ETH_ALEN); | |
7245 | wpa_printf(MSG_DEBUG, "nl80211: New P2P Device interface %s (0x%llx) created", | |
7246 | ifname, | |
7247 | (long long unsigned int) p2pdev_info.wdev_id); | |
e472e1b4 AS |
7248 | } else { |
7249 | ifidx = nl80211_create_iface(drv, ifname, nlmode, addr, | |
2aec4f3c JM |
7250 | 0, NULL, NULL, use_existing); |
7251 | if (use_existing && ifidx == -ENFILE) { | |
7252 | added = 0; | |
7253 | ifidx = if_nametoindex(ifname); | |
7254 | } else if (ifidx < 0) { | |
e472e1b4 AS |
7255 | return -1; |
7256 | } | |
22a7c9d7 JM |
7257 | } |
7258 | ||
ab7a1add | 7259 | if (!addr) { |
8ea8a89c | 7260 | if (nlmode == NL80211_IFTYPE_P2P_DEVICE) |
ab7a1add AS |
7261 | os_memcpy(if_addr, bss->addr, ETH_ALEN); |
7262 | else if (linux_get_ifhwaddr(drv->global->ioctl_sock, | |
8ea8a89c | 7263 | ifname, if_addr) < 0) { |
2aec4f3c JM |
7264 | if (added) |
7265 | nl80211_remove_iface(drv, ifidx); | |
ab7a1add AS |
7266 | return -1; |
7267 | } | |
c55f774d JM |
7268 | } |
7269 | ||
c55f774d JM |
7270 | if (!addr && |
7271 | (type == WPA_IF_P2P_CLIENT || type == WPA_IF_P2P_GROUP || | |
8ea8a89c JM |
7272 | type == WPA_IF_P2P_GO || type == WPA_IF_MESH || |
7273 | type == WPA_IF_STATION)) { | |
7274 | /* Enforce unique address */ | |
ab7a1add | 7275 | u8 new_addr[ETH_ALEN]; |
c55f774d | 7276 | |
ab7a1add | 7277 | if (linux_get_ifhwaddr(drv->global->ioctl_sock, ifname, |
c81eff1a | 7278 | new_addr) < 0) { |
ea39367c MK |
7279 | if (added) |
7280 | nl80211_remove_iface(drv, ifidx); | |
c55f774d JM |
7281 | return -1; |
7282 | } | |
f608081c | 7283 | if (nl80211_addr_in_use(drv->global, new_addr)) { |
c55f774d | 7284 | wpa_printf(MSG_DEBUG, "nl80211: Allocate new address " |
8ea8a89c | 7285 | "for interface %s type %d", ifname, type); |
5b78493f | 7286 | if (nl80211_vif_addr(drv, new_addr) < 0) { |
ea39367c MK |
7287 | if (added) |
7288 | nl80211_remove_iface(drv, ifidx); | |
c55f774d JM |
7289 | return -1; |
7290 | } | |
c81eff1a | 7291 | if (linux_set_ifhwaddr(drv->global->ioctl_sock, ifname, |
c55f774d | 7292 | new_addr) < 0) { |
ea39367c MK |
7293 | if (added) |
7294 | nl80211_remove_iface(drv, ifidx); | |
c55f774d JM |
7295 | return -1; |
7296 | } | |
c55f774d | 7297 | } |
f67eeb5c | 7298 | os_memcpy(if_addr, new_addr, ETH_ALEN); |
c55f774d | 7299 | } |
f3585c8a | 7300 | |
d8a3b66d | 7301 | if (type == WPA_IF_AP_BSS && setup_ap) { |
f5eb9da3 JM |
7302 | struct i802_bss *new_bss = os_zalloc(sizeof(*new_bss)); |
7303 | if (new_bss == NULL) { | |
2aec4f3c JM |
7304 | if (added) |
7305 | nl80211_remove_iface(drv, ifidx); | |
f5eb9da3 JM |
7306 | return -1; |
7307 | } | |
7308 | ||
7309 | if (bridge && | |
7310 | i802_check_bridge(drv, new_bss, bridge, ifname) < 0) { | |
7311 | wpa_printf(MSG_ERROR, "nl80211: Failed to add the new " | |
7312 | "interface %s to a bridge %s", | |
7313 | ifname, bridge); | |
2aec4f3c JM |
7314 | if (added) |
7315 | nl80211_remove_iface(drv, ifidx); | |
f5eb9da3 JM |
7316 | os_free(new_bss); |
7317 | return -1; | |
7318 | } | |
7319 | ||
c81eff1a BG |
7320 | if (linux_set_iface_flags(drv->global->ioctl_sock, ifname, 1)) |
7321 | { | |
ea39367c MK |
7322 | if (added) |
7323 | nl80211_remove_iface(drv, ifidx); | |
07179987 | 7324 | os_free(new_bss); |
22a7c9d7 JM |
7325 | return -1; |
7326 | } | |
a2e40bb6 | 7327 | os_strlcpy(new_bss->ifname, ifname, IFNAMSIZ); |
341eebee | 7328 | os_memcpy(new_bss->addr, if_addr, ETH_ALEN); |
a2e40bb6 FF |
7329 | new_bss->ifindex = ifidx; |
7330 | new_bss->drv = drv; | |
834ee56f KP |
7331 | new_bss->next = drv->first_bss->next; |
7332 | new_bss->freq = drv->first_bss->freq; | |
a5e1eb20 | 7333 | new_bss->ctx = bss_ctx; |
2aec4f3c | 7334 | new_bss->added_if = added; |
834ee56f | 7335 | drv->first_bss->next = new_bss; |
a2e40bb6 FF |
7336 | if (drv_priv) |
7337 | *drv_priv = new_bss; | |
cc7a48d1 | 7338 | nl80211_init_bss(new_bss); |
3dd1d890 YAP |
7339 | |
7340 | /* Subscribe management frames for this WPA_IF_AP_BSS */ | |
7341 | if (nl80211_setup_ap(new_bss)) | |
7342 | return -1; | |
22a7c9d7 | 7343 | } |
22a7c9d7 | 7344 | |
ff6a158b JM |
7345 | if (drv->global) |
7346 | drv->global->if_add_ifindex = ifidx; | |
7347 | ||
d1bb7aed JJ |
7348 | /* |
7349 | * Some virtual interfaces need to process EAPOL packets and events on | |
7350 | * the parent interface. This is used mainly with hostapd. | |
7351 | */ | |
7352 | if (ifidx > 0 && | |
7353 | (drv->hostapd || | |
7354 | nlmode == NL80211_IFTYPE_AP_VLAN || | |
7355 | nlmode == NL80211_IFTYPE_WDS || | |
7356 | nlmode == NL80211_IFTYPE_MONITOR)) | |
732b1d20 | 7357 | add_ifidx(drv, ifidx, IFIDX_ANY); |
b36935be | 7358 | |
22a7c9d7 JM |
7359 | return 0; |
7360 | } | |
7361 | ||
7362 | ||
9ebce9c5 | 7363 | static int wpa_driver_nl80211_if_remove(struct i802_bss *bss, |
22a7c9d7 JM |
7364 | enum wpa_driver_if_type type, |
7365 | const char *ifname) | |
7366 | { | |
a2e40bb6 | 7367 | struct wpa_driver_nl80211_data *drv = bss->drv; |
22a7c9d7 JM |
7368 | int ifindex = if_nametoindex(ifname); |
7369 | ||
2aec4f3c JM |
7370 | wpa_printf(MSG_DEBUG, "nl80211: %s(type=%d ifname=%s) ifindex=%d added_if=%d", |
7371 | __func__, type, ifname, ifindex, bss->added_if); | |
158b090c | 7372 | if (ifindex > 0 && (bss->added_if || bss->ifindex != ifindex)) |
2b72df63 | 7373 | nl80211_remove_iface(drv, ifindex); |
de884303 JM |
7374 | else if (ifindex > 0 && !bss->added_if) { |
7375 | struct wpa_driver_nl80211_data *drv2; | |
7376 | dl_list_for_each(drv2, &drv->global->interfaces, | |
732b1d20 MB |
7377 | struct wpa_driver_nl80211_data, list) { |
7378 | del_ifidx(drv2, ifindex, IFIDX_ANY); | |
7379 | del_ifidx(drv2, IFIDX_ANY, ifindex); | |
7380 | } | |
de884303 | 7381 | } |
c34e618d | 7382 | |
c34e618d FF |
7383 | if (type != WPA_IF_AP_BSS) |
7384 | return 0; | |
7385 | ||
e17a2477 | 7386 | if (bss->added_if_into_bridge) { |
c81eff1a BG |
7387 | if (linux_br_del_if(drv->global->ioctl_sock, bss->brname, |
7388 | bss->ifname) < 0) | |
e17a2477 JM |
7389 | wpa_printf(MSG_INFO, "nl80211: Failed to remove " |
7390 | "interface %s from bridge %s: %s", | |
7391 | bss->ifname, bss->brname, strerror(errno)); | |
7392 | } | |
7393 | if (bss->added_bridge) { | |
c81eff1a | 7394 | if (linux_br_del(drv->global->ioctl_sock, bss->brname) < 0) |
e17a2477 JM |
7395 | wpa_printf(MSG_INFO, "nl80211: Failed to remove " |
7396 | "bridge %s: %s", | |
7397 | bss->brname, strerror(errno)); | |
7398 | } | |
a2e40bb6 | 7399 | |
834ee56f | 7400 | if (bss != drv->first_bss) { |
8546ea19 | 7401 | struct i802_bss *tbss; |
a2e40bb6 | 7402 | |
2aec4f3c | 7403 | wpa_printf(MSG_DEBUG, "nl80211: Not the first BSS - remove it"); |
834ee56f | 7404 | for (tbss = drv->first_bss; tbss; tbss = tbss->next) { |
8546ea19 JM |
7405 | if (tbss->next == bss) { |
7406 | tbss->next = bss->next; | |
3dd1d890 YAP |
7407 | /* Unsubscribe management frames */ |
7408 | nl80211_teardown_ap(bss); | |
cc7a48d1 | 7409 | nl80211_destroy_bss(bss); |
5c9da160 MB |
7410 | if (!bss->added_if) |
7411 | i802_set_iface_flags(bss, 0); | |
8546ea19 JM |
7412 | os_free(bss); |
7413 | bss = NULL; | |
7414 | break; | |
7415 | } | |
22a7c9d7 | 7416 | } |
8546ea19 JM |
7417 | if (bss) |
7418 | wpa_printf(MSG_INFO, "nl80211: %s - could not find " | |
7419 | "BSS %p in the list", __func__, bss); | |
390e489c | 7420 | } else { |
2aec4f3c | 7421 | wpa_printf(MSG_DEBUG, "nl80211: First BSS - reassign context"); |
390e489c | 7422 | nl80211_teardown_ap(bss); |
2aec4f3c | 7423 | if (!bss->added_if && !drv->first_bss->next) |
a70cd0db | 7424 | wpa_driver_nl80211_del_beacon(bss); |
390e489c | 7425 | nl80211_destroy_bss(bss); |
2aec4f3c JM |
7426 | if (!bss->added_if) |
7427 | i802_set_iface_flags(bss, 0); | |
390e489c KP |
7428 | if (drv->first_bss->next) { |
7429 | drv->first_bss = drv->first_bss->next; | |
7430 | drv->ctx = drv->first_bss->ctx; | |
7431 | os_free(bss); | |
7432 | } else { | |
7433 | wpa_printf(MSG_DEBUG, "nl80211: No second BSS to reassign context to"); | |
7434 | } | |
22a7c9d7 | 7435 | } |
22a7c9d7 JM |
7436 | |
7437 | return 0; | |
7438 | } | |
7439 | ||
7440 | ||
55777702 JM |
7441 | static int cookie_handler(struct nl_msg *msg, void *arg) |
7442 | { | |
7443 | struct nlattr *tb[NL80211_ATTR_MAX + 1]; | |
7444 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); | |
7445 | u64 *cookie = arg; | |
7446 | nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), | |
7447 | genlmsg_attrlen(gnlh, 0), NULL); | |
7448 | if (tb[NL80211_ATTR_COOKIE]) | |
7449 | *cookie = nla_get_u64(tb[NL80211_ATTR_COOKIE]); | |
7450 | return NL_SKIP; | |
7451 | } | |
7452 | ||
7453 | ||
88df0ef7 | 7454 | static int nl80211_send_frame_cmd(struct i802_bss *bss, |
5dfca53f JB |
7455 | unsigned int freq, unsigned int wait, |
7456 | const u8 *buf, size_t buf_len, | |
88df0ef7 | 7457 | u64 *cookie_out, int no_cck, int no_ack, |
2d3943ce AO |
7458 | int offchanok, const u16 *csa_offs, |
7459 | size_t csa_offs_len) | |
9884f9cc | 7460 | { |
88df0ef7 | 7461 | struct wpa_driver_nl80211_data *drv = bss->drv; |
9884f9cc JB |
7462 | struct nl_msg *msg; |
7463 | u64 cookie; | |
7464 | int ret = -1; | |
7465 | ||
cc2ada86 | 7466 | wpa_printf(MSG_MSGDUMP, "nl80211: CMD_FRAME freq=%u wait=%u no_cck=%d " |
2e3e4566 JM |
7467 | "no_ack=%d offchanok=%d", |
7468 | freq, wait, no_cck, no_ack, offchanok); | |
c91f796f | 7469 | wpa_hexdump(MSG_MSGDUMP, "CMD_FRAME", buf, buf_len); |
9884f9cc | 7470 | |
56f77852 | 7471 | if (!(msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_FRAME)) || |
a862e4a3 JM |
7472 | (freq && nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq)) || |
7473 | (wait && nla_put_u32(msg, NL80211_ATTR_DURATION, wait)) || | |
7474 | (offchanok && ((drv->capa.flags & WPA_DRIVER_FLAGS_OFFCHANNEL_TX) || | |
7475 | drv->test_use_roc_tx) && | |
7476 | nla_put_flag(msg, NL80211_ATTR_OFFCHANNEL_TX_OK)) || | |
7477 | (no_cck && nla_put_flag(msg, NL80211_ATTR_TX_NO_CCK_RATE)) || | |
7478 | (no_ack && nla_put_flag(msg, NL80211_ATTR_DONT_WAIT_FOR_ACK)) || | |
2d3943ce AO |
7479 | (csa_offs && nla_put(msg, NL80211_ATTR_CSA_C_OFFSETS_TX, |
7480 | csa_offs_len * sizeof(u16), csa_offs)) || | |
a862e4a3 JM |
7481 | nla_put(msg, NL80211_ATTR_FRAME, buf_len, buf)) |
7482 | goto fail; | |
9884f9cc JB |
7483 | |
7484 | cookie = 0; | |
7485 | ret = send_and_recv_msgs(drv, msg, cookie_handler, &cookie); | |
7486 | msg = NULL; | |
7487 | if (ret) { | |
7488 | wpa_printf(MSG_DEBUG, "nl80211: Frame command failed: ret=%d " | |
a05225c8 JM |
7489 | "(%s) (freq=%u wait=%u)", ret, strerror(-ret), |
7490 | freq, wait); | |
a862e4a3 JM |
7491 | } else { |
7492 | wpa_printf(MSG_MSGDUMP, "nl80211: Frame TX command accepted%s; " | |
7493 | "cookie 0x%llx", no_ack ? " (no ACK)" : "", | |
7494 | (long long unsigned int) cookie); | |
9884f9cc | 7495 | |
a862e4a3 JM |
7496 | if (cookie_out) |
7497 | *cookie_out = no_ack ? (u64) -1 : cookie; | |
759a8a3a JM |
7498 | |
7499 | if (drv->num_send_action_cookies == MAX_SEND_ACTION_COOKIES) { | |
7500 | wpa_printf(MSG_DEBUG, | |
7501 | "nl80211: Drop oldest pending send action cookie 0x%llx", | |
7502 | (long long unsigned int) | |
7503 | drv->send_action_cookies[0]); | |
7504 | os_memmove(&drv->send_action_cookies[0], | |
7505 | &drv->send_action_cookies[1], | |
7506 | (MAX_SEND_ACTION_COOKIES - 1) * | |
7507 | sizeof(u64)); | |
7508 | drv->num_send_action_cookies--; | |
7509 | } | |
7510 | drv->send_action_cookies[drv->num_send_action_cookies] = cookie; | |
7511 | drv->num_send_action_cookies++; | |
a862e4a3 | 7512 | } |
9884f9cc | 7513 | |
a862e4a3 | 7514 | fail: |
9884f9cc JB |
7515 | nlmsg_free(msg); |
7516 | return ret; | |
7517 | } | |
7518 | ||
7519 | ||
9ebce9c5 JM |
7520 | static int wpa_driver_nl80211_send_action(struct i802_bss *bss, |
7521 | unsigned int freq, | |
190b9062 | 7522 | unsigned int wait_time, |
58f6fbe0 JM |
7523 | const u8 *dst, const u8 *src, |
7524 | const u8 *bssid, | |
b106173a JM |
7525 | const u8 *data, size_t data_len, |
7526 | int no_cck) | |
58f6fbe0 | 7527 | { |
a2e40bb6 | 7528 | struct wpa_driver_nl80211_data *drv = bss->drv; |
58f6fbe0 | 7529 | int ret = -1; |
58f6fbe0 JM |
7530 | u8 *buf; |
7531 | struct ieee80211_hdr *hdr; | |
58f6fbe0 | 7532 | |
5dfca53f | 7533 | wpa_printf(MSG_DEBUG, "nl80211: Send Action frame (ifindex=%d, " |
55231068 JM |
7534 | "freq=%u MHz wait=%d ms no_cck=%d)", |
7535 | drv->ifindex, freq, wait_time, no_cck); | |
58f6fbe0 JM |
7536 | |
7537 | buf = os_zalloc(24 + data_len); | |
7538 | if (buf == NULL) | |
7539 | return ret; | |
7540 | os_memcpy(buf + 24, data, data_len); | |
7541 | hdr = (struct ieee80211_hdr *) buf; | |
7542 | hdr->frame_control = | |
7543 | IEEE80211_FC(WLAN_FC_TYPE_MGMT, WLAN_FC_STYPE_ACTION); | |
7544 | os_memcpy(hdr->addr1, dst, ETH_ALEN); | |
7545 | os_memcpy(hdr->addr2, src, ETH_ALEN); | |
7546 | os_memcpy(hdr->addr3, bssid, ETH_ALEN); | |
7547 | ||
8331c9b3 VK |
7548 | if (os_memcmp(bss->addr, src, ETH_ALEN) != 0) { |
7549 | wpa_printf(MSG_DEBUG, "nl80211: Use random TA " MACSTR, | |
7550 | MAC2STR(src)); | |
7551 | os_memcpy(bss->rand_addr, src, ETH_ALEN); | |
7552 | } else { | |
7553 | os_memset(bss->rand_addr, 0, ETH_ALEN); | |
7554 | } | |
7555 | ||
f78f2785 JM |
7556 | if (is_ap_interface(drv->nlmode) && |
7557 | (!(drv->capa.flags & WPA_DRIVER_FLAGS_OFFCHANNEL_TX) || | |
7558 | (int) freq == bss->freq || drv->device_ap_sme || | |
7559 | !drv->use_monitor)) | |
9ebce9c5 JM |
7560 | ret = wpa_driver_nl80211_send_mlme(bss, buf, 24 + data_len, |
7561 | 0, freq, no_cck, 1, | |
2d3943ce | 7562 | wait_time, NULL, 0); |
9884f9cc | 7563 | else |
88df0ef7 | 7564 | ret = nl80211_send_frame_cmd(bss, freq, wait_time, buf, |
5dfca53f | 7565 | 24 + data_len, |
b106173a | 7566 | &drv->send_action_cookie, |
2d3943ce | 7567 | no_cck, 0, 1, NULL, 0); |
58f6fbe0 | 7568 | |
f8bf1421 | 7569 | os_free(buf); |
58f6fbe0 JM |
7570 | return ret; |
7571 | } | |
7572 | ||
7573 | ||
759a8a3a | 7574 | static void nl80211_frame_wait_cancel(struct i802_bss *bss, u64 cookie) |
5dfca53f | 7575 | { |
5dfca53f JB |
7576 | struct wpa_driver_nl80211_data *drv = bss->drv; |
7577 | struct nl_msg *msg; | |
7578 | int ret; | |
7579 | ||
316a9e4d | 7580 | wpa_printf(MSG_DEBUG, "nl80211: Cancel TX frame wait: cookie=0x%llx", |
759a8a3a | 7581 | (long long unsigned int) cookie); |
56f77852 | 7582 | if (!(msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_FRAME_WAIT_CANCEL)) || |
759a8a3a | 7583 | nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie)) { |
a862e4a3 JM |
7584 | nlmsg_free(msg); |
7585 | return; | |
7586 | } | |
5dfca53f JB |
7587 | |
7588 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); | |
5dfca53f JB |
7589 | if (ret) |
7590 | wpa_printf(MSG_DEBUG, "nl80211: wait cancel failed: ret=%d " | |
7591 | "(%s)", ret, strerror(-ret)); | |
5dfca53f JB |
7592 | } |
7593 | ||
7594 | ||
759a8a3a JM |
7595 | static void wpa_driver_nl80211_send_action_cancel_wait(void *priv) |
7596 | { | |
7597 | struct i802_bss *bss = priv; | |
7598 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
7599 | unsigned int i; | |
7600 | u64 cookie; | |
7601 | ||
7602 | /* Cancel the last pending TX cookie */ | |
7603 | nl80211_frame_wait_cancel(bss, drv->send_action_cookie); | |
7604 | ||
7605 | /* | |
7606 | * Cancel the other pending TX cookies, if any. This is needed since | |
7607 | * the driver may keep a list of all pending offchannel TX operations | |
7608 | * and free up the radio only once they have expired or cancelled. | |
7609 | */ | |
7610 | for (i = drv->num_send_action_cookies; i > 0; i--) { | |
7611 | cookie = drv->send_action_cookies[i - 1]; | |
7612 | if (cookie != drv->send_action_cookie) | |
7613 | nl80211_frame_wait_cancel(bss, cookie); | |
7614 | } | |
7615 | drv->num_send_action_cookies = 0; | |
7616 | } | |
7617 | ||
7618 | ||
55777702 JM |
7619 | static int wpa_driver_nl80211_remain_on_channel(void *priv, unsigned int freq, |
7620 | unsigned int duration) | |
7621 | { | |
a2e40bb6 FF |
7622 | struct i802_bss *bss = priv; |
7623 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
55777702 JM |
7624 | struct nl_msg *msg; |
7625 | int ret; | |
7626 | u64 cookie; | |
7627 | ||
56f77852 | 7628 | if (!(msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_REMAIN_ON_CHANNEL)) || |
a862e4a3 JM |
7629 | nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq) || |
7630 | nla_put_u32(msg, NL80211_ATTR_DURATION, duration)) { | |
7631 | nlmsg_free(msg); | |
7632 | return -1; | |
7633 | } | |
55777702 JM |
7634 | |
7635 | cookie = 0; | |
7636 | ret = send_and_recv_msgs(drv, msg, cookie_handler, &cookie); | |
7637 | if (ret == 0) { | |
7638 | wpa_printf(MSG_DEBUG, "nl80211: Remain-on-channel cookie " | |
7639 | "0x%llx for freq=%u MHz duration=%u", | |
7640 | (long long unsigned int) cookie, freq, duration); | |
7641 | drv->remain_on_chan_cookie = cookie; | |
531f0331 | 7642 | drv->pending_remain_on_chan = 1; |
55777702 JM |
7643 | return 0; |
7644 | } | |
7645 | wpa_printf(MSG_DEBUG, "nl80211: Failed to request remain-on-channel " | |
15ed5535 JM |
7646 | "(freq=%d duration=%u): %d (%s)", |
7647 | freq, duration, ret, strerror(-ret)); | |
55777702 JM |
7648 | return -1; |
7649 | } | |
7650 | ||
7651 | ||
7652 | static int wpa_driver_nl80211_cancel_remain_on_channel(void *priv) | |
7653 | { | |
a2e40bb6 FF |
7654 | struct i802_bss *bss = priv; |
7655 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
55777702 JM |
7656 | struct nl_msg *msg; |
7657 | int ret; | |
7658 | ||
7659 | if (!drv->pending_remain_on_chan) { | |
7660 | wpa_printf(MSG_DEBUG, "nl80211: No pending remain-on-channel " | |
7661 | "to cancel"); | |
7662 | return -1; | |
7663 | } | |
7664 | ||
7665 | wpa_printf(MSG_DEBUG, "nl80211: Cancel remain-on-channel with cookie " | |
7666 | "0x%llx", | |
7667 | (long long unsigned int) drv->remain_on_chan_cookie); | |
7668 | ||
56f77852 JM |
7669 | msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL); |
7670 | if (!msg || | |
a862e4a3 JM |
7671 | nla_put_u64(msg, NL80211_ATTR_COOKIE, drv->remain_on_chan_cookie)) { |
7672 | nlmsg_free(msg); | |
7673 | return -1; | |
7674 | } | |
55777702 JM |
7675 | |
7676 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); | |
7677 | if (ret == 0) | |
7678 | return 0; | |
7679 | wpa_printf(MSG_DEBUG, "nl80211: Failed to cancel remain-on-channel: " | |
7680 | "%d (%s)", ret, strerror(-ret)); | |
55777702 JM |
7681 | return -1; |
7682 | } | |
7683 | ||
7684 | ||
9ebce9c5 | 7685 | static int wpa_driver_nl80211_probe_req_report(struct i802_bss *bss, int report) |
504e905c | 7686 | { |
a2e40bb6 | 7687 | struct wpa_driver_nl80211_data *drv = bss->drv; |
504e905c | 7688 | |
5582a5d1 | 7689 | if (!report) { |
0d891981 | 7690 | if (bss->nl_preq && drv->device_ap_sme && |
b8d87ed2 AP |
7691 | is_ap_interface(drv->nlmode) && !bss->in_deinit && |
7692 | !bss->static_ap) { | |
0d891981 JM |
7693 | /* |
7694 | * Do not disable Probe Request reporting that was | |
7695 | * enabled in nl80211_setup_ap(). | |
7696 | */ | |
7697 | wpa_printf(MSG_DEBUG, "nl80211: Skip disabling of " | |
7698 | "Probe Request reporting nl_preq=%p while " | |
7699 | "in AP mode", bss->nl_preq); | |
7700 | } else if (bss->nl_preq) { | |
36488c05 JM |
7701 | wpa_printf(MSG_DEBUG, "nl80211: Disable Probe Request " |
7702 | "reporting nl_preq=%p", bss->nl_preq); | |
40a68f33 | 7703 | nl80211_destroy_eloop_handle(&bss->nl_preq, 0); |
5582a5d1 JB |
7704 | } |
7705 | return 0; | |
7706 | } | |
7707 | ||
481234cf | 7708 | if (bss->nl_preq) { |
5582a5d1 | 7709 | wpa_printf(MSG_DEBUG, "nl80211: Probe Request reporting " |
36488c05 | 7710 | "already on! nl_preq=%p", bss->nl_preq); |
5582a5d1 JB |
7711 | return 0; |
7712 | } | |
7713 | ||
481234cf JM |
7714 | bss->nl_preq = nl_create_handle(drv->global->nl_cb, "preq"); |
7715 | if (bss->nl_preq == NULL) | |
5582a5d1 | 7716 | return -1; |
36488c05 JM |
7717 | wpa_printf(MSG_DEBUG, "nl80211: Enable Probe Request " |
7718 | "reporting nl_preq=%p", bss->nl_preq); | |
5582a5d1 | 7719 | |
481234cf | 7720 | if (nl80211_register_frame(bss, bss->nl_preq, |
5582a5d1 JB |
7721 | (WLAN_FC_TYPE_MGMT << 2) | |
7722 | (WLAN_FC_STYPE_PROBE_REQ << 4), | |
a92dfde8 JB |
7723 | NULL, 0) < 0) |
7724 | goto out_err; | |
5582a5d1 | 7725 | |
5f65e9f7 JB |
7726 | nl80211_register_eloop_read(&bss->nl_preq, |
7727 | wpa_driver_nl80211_event_receive, | |
40a68f33 | 7728 | bss->nl_cb, 0); |
5582a5d1 | 7729 | |
504e905c | 7730 | return 0; |
5582a5d1 | 7731 | |
a92dfde8 | 7732 | out_err: |
221a59c9 | 7733 | nl_destroy_handles(&bss->nl_preq); |
5582a5d1 | 7734 | return -1; |
504e905c JM |
7735 | } |
7736 | ||
7737 | ||
4e5cb1a3 JM |
7738 | static int nl80211_disable_11b_rates(struct wpa_driver_nl80211_data *drv, |
7739 | int ifindex, int disabled) | |
7740 | { | |
7741 | struct nl_msg *msg; | |
7742 | struct nlattr *bands, *band; | |
7743 | int ret; | |
7744 | ||
3e208481 JM |
7745 | wpa_printf(MSG_DEBUG, |
7746 | "nl80211: NL80211_CMD_SET_TX_BITRATE_MASK (ifindex=%d %s)", | |
7747 | ifindex, disabled ? "NL80211_TXRATE_LEGACY=OFDM-only" : | |
7748 | "no NL80211_TXRATE_LEGACY constraint"); | |
7749 | ||
95376e1a JM |
7750 | msg = nl80211_ifindex_msg(drv, ifindex, 0, |
7751 | NL80211_CMD_SET_TX_BITRATE_MASK); | |
4e5cb1a3 JM |
7752 | if (!msg) |
7753 | return -1; | |
7754 | ||
4e5cb1a3 JM |
7755 | bands = nla_nest_start(msg, NL80211_ATTR_TX_RATES); |
7756 | if (!bands) | |
a862e4a3 | 7757 | goto fail; |
4e5cb1a3 JM |
7758 | |
7759 | /* | |
7760 | * Disable 2 GHz rates 1, 2, 5.5, 11 Mbps by masking out everything | |
7761 | * else apart from 6, 9, 12, 18, 24, 36, 48, 54 Mbps from non-MCS | |
7762 | * rates. All 5 GHz rates are left enabled. | |
7763 | */ | |
7764 | band = nla_nest_start(msg, NL80211_BAND_2GHZ); | |
a862e4a3 JM |
7765 | if (!band || |
7766 | (disabled && nla_put(msg, NL80211_TXRATE_LEGACY, 8, | |
7767 | "\x0c\x12\x18\x24\x30\x48\x60\x6c"))) | |
7768 | goto fail; | |
4e5cb1a3 JM |
7769 | nla_nest_end(msg, band); |
7770 | ||
7771 | nla_nest_end(msg, bands); | |
7772 | ||
7773 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); | |
4e5cb1a3 JM |
7774 | if (ret) { |
7775 | wpa_printf(MSG_DEBUG, "nl80211: Set TX rates failed: ret=%d " | |
7776 | "(%s)", ret, strerror(-ret)); | |
1d0c6fb1 JM |
7777 | } else |
7778 | drv->disabled_11b_rates = disabled; | |
4e5cb1a3 JM |
7779 | |
7780 | return ret; | |
7781 | ||
a862e4a3 | 7782 | fail: |
4e5cb1a3 JM |
7783 | nlmsg_free(msg); |
7784 | return -1; | |
7785 | } | |
7786 | ||
7787 | ||
af473088 JM |
7788 | static int wpa_driver_nl80211_deinit_ap(void *priv) |
7789 | { | |
a2e40bb6 FF |
7790 | struct i802_bss *bss = priv; |
7791 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
b1f625e0 | 7792 | if (!is_ap_interface(drv->nlmode)) |
af473088 | 7793 | return -1; |
a70cd0db | 7794 | wpa_driver_nl80211_del_beacon(bss); |
9bc5cfa3 | 7795 | bss->beacon_set = 0; |
60b13c20 IP |
7796 | |
7797 | /* | |
7798 | * If the P2P GO interface was dynamically added, then it is | |
7799 | * possible that the interface change to station is not possible. | |
7800 | */ | |
7801 | if (drv->nlmode == NL80211_IFTYPE_P2P_GO && bss->if_dynamic) | |
7802 | return 0; | |
7803 | ||
b1f625e0 | 7804 | return wpa_driver_nl80211_set_mode(priv, NL80211_IFTYPE_STATION); |
af473088 JM |
7805 | } |
7806 | ||
7807 | ||
695c7038 SW |
7808 | static int wpa_driver_nl80211_stop_ap(void *priv) |
7809 | { | |
7810 | struct i802_bss *bss = priv; | |
7811 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
7812 | if (!is_ap_interface(drv->nlmode)) | |
7813 | return -1; | |
a70cd0db | 7814 | wpa_driver_nl80211_del_beacon(bss); |
695c7038 SW |
7815 | bss->beacon_set = 0; |
7816 | return 0; | |
7817 | } | |
7818 | ||
7819 | ||
3c29244e EP |
7820 | static int wpa_driver_nl80211_deinit_p2p_cli(void *priv) |
7821 | { | |
7822 | struct i802_bss *bss = priv; | |
7823 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
7824 | if (drv->nlmode != NL80211_IFTYPE_P2P_CLIENT) | |
7825 | return -1; | |
60b13c20 IP |
7826 | |
7827 | /* | |
7828 | * If the P2P Client interface was dynamically added, then it is | |
7829 | * possible that the interface change to station is not possible. | |
7830 | */ | |
7831 | if (bss->if_dynamic) | |
7832 | return 0; | |
7833 | ||
3c29244e EP |
7834 | return wpa_driver_nl80211_set_mode(priv, NL80211_IFTYPE_STATION); |
7835 | } | |
7836 | ||
7837 | ||
207ef3fb JM |
7838 | static void wpa_driver_nl80211_resume(void *priv) |
7839 | { | |
a2e40bb6 | 7840 | struct i802_bss *bss = priv; |
e8dc205f | 7841 | enum nl80211_iftype nlmode = nl80211_get_ifmode(bss); |
91724d6f AS |
7842 | |
7843 | if (i802_set_iface_flags(bss, 1)) | |
7844 | wpa_printf(MSG_DEBUG, "nl80211: Failed to set interface up on resume event"); | |
e8dc205f AO |
7845 | |
7846 | if (is_p2p_net_interface(nlmode)) | |
7847 | nl80211_disable_11b_rates(bss->drv, bss->drv->ifindex, 1); | |
207ef3fb JM |
7848 | } |
7849 | ||
7850 | ||
b625473c JM |
7851 | static int nl80211_signal_monitor(void *priv, int threshold, int hysteresis) |
7852 | { | |
7853 | struct i802_bss *bss = priv; | |
7854 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
8970bae8 JB |
7855 | struct nl_msg *msg; |
7856 | struct nlattr *cqm; | |
b625473c JM |
7857 | |
7858 | wpa_printf(MSG_DEBUG, "nl80211: Signal monitor threshold=%d " | |
7859 | "hysteresis=%d", threshold, hysteresis); | |
7860 | ||
13f83980 | 7861 | if (!(msg = nl80211_bss_msg(bss, 0, NL80211_CMD_SET_CQM)) || |
a862e4a3 JM |
7862 | !(cqm = nla_nest_start(msg, NL80211_ATTR_CQM)) || |
7863 | nla_put_u32(msg, NL80211_ATTR_CQM_RSSI_THOLD, threshold) || | |
7864 | nla_put_u32(msg, NL80211_ATTR_CQM_RSSI_HYST, hysteresis)) { | |
7865 | nlmsg_free(msg); | |
7866 | return -1; | |
7867 | } | |
8970bae8 | 7868 | nla_nest_end(msg, cqm); |
21270bb4 | 7869 | |
a862e4a3 | 7870 | return send_and_recv_msgs(drv, msg, NULL, NULL); |
b625473c JM |
7871 | } |
7872 | ||
7873 | ||
2cc8d8f4 AO |
7874 | static int get_channel_width(struct nl_msg *msg, void *arg) |
7875 | { | |
7876 | struct nlattr *tb[NL80211_ATTR_MAX + 1]; | |
7877 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); | |
7878 | struct wpa_signal_info *sig_change = arg; | |
7879 | ||
7880 | nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), | |
7881 | genlmsg_attrlen(gnlh, 0), NULL); | |
7882 | ||
7883 | sig_change->center_frq1 = -1; | |
7884 | sig_change->center_frq2 = -1; | |
7885 | sig_change->chanwidth = CHAN_WIDTH_UNKNOWN; | |
7886 | ||
7887 | if (tb[NL80211_ATTR_CHANNEL_WIDTH]) { | |
7888 | sig_change->chanwidth = convert2width( | |
7889 | nla_get_u32(tb[NL80211_ATTR_CHANNEL_WIDTH])); | |
7890 | if (tb[NL80211_ATTR_CENTER_FREQ1]) | |
7891 | sig_change->center_frq1 = | |
7892 | nla_get_u32(tb[NL80211_ATTR_CENTER_FREQ1]); | |
7893 | if (tb[NL80211_ATTR_CENTER_FREQ2]) | |
7894 | sig_change->center_frq2 = | |
7895 | nla_get_u32(tb[NL80211_ATTR_CENTER_FREQ2]); | |
7896 | } | |
7897 | ||
7898 | return NL_SKIP; | |
7899 | } | |
7900 | ||
7901 | ||
7902 | static int nl80211_get_channel_width(struct wpa_driver_nl80211_data *drv, | |
7903 | struct wpa_signal_info *sig) | |
7904 | { | |
7905 | struct nl_msg *msg; | |
7906 | ||
9725b784 | 7907 | msg = nl80211_drv_msg(drv, 0, NL80211_CMD_GET_INTERFACE); |
2cc8d8f4 | 7908 | return send_and_recv_msgs(drv, msg, get_channel_width, sig); |
2cc8d8f4 AO |
7909 | } |
7910 | ||
7911 | ||
1c5c7273 PS |
7912 | static int nl80211_signal_poll(void *priv, struct wpa_signal_info *si) |
7913 | { | |
7914 | struct i802_bss *bss = priv; | |
7915 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
7916 | int res; | |
7917 | ||
7918 | os_memset(si, 0, sizeof(*si)); | |
7919 | res = nl80211_get_link_signal(drv, si); | |
1d6955e6 JM |
7920 | if (res) { |
7921 | if (drv->nlmode != NL80211_IFTYPE_ADHOC && | |
7922 | drv->nlmode != NL80211_IFTYPE_MESH_POINT) | |
7923 | return res; | |
7924 | si->current_signal = 0; | |
7925 | } | |
1c5c7273 | 7926 | |
2cc8d8f4 AO |
7927 | res = nl80211_get_channel_width(drv, si); |
7928 | if (res != 0) | |
7929 | return res; | |
7930 | ||
1c5c7273 PS |
7931 | return nl80211_get_link_noise(drv, si); |
7932 | } | |
7933 | ||
7934 | ||
b91ab76e JM |
7935 | static int nl80211_send_frame(void *priv, const u8 *data, size_t data_len, |
7936 | int encrypt) | |
7937 | { | |
7938 | struct i802_bss *bss = priv; | |
55231068 | 7939 | return wpa_driver_nl80211_send_frame(bss, data, data_len, encrypt, 0, |
2d3943ce | 7940 | 0, 0, 0, 0, NULL, 0); |
b91ab76e JM |
7941 | } |
7942 | ||
7943 | ||
c55f774d JM |
7944 | static int nl80211_set_param(void *priv, const char *param) |
7945 | { | |
ef24ad3e JM |
7946 | struct i802_bss *bss = priv; |
7947 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
7948 | ||
c55f774d JM |
7949 | if (param == NULL) |
7950 | return 0; | |
99a94f55 | 7951 | wpa_printf(MSG_DEBUG, "nl80211: driver param='%s'", param); |
c55f774d JM |
7952 | |
7953 | #ifdef CONFIG_P2P | |
7954 | if (os_strstr(param, "use_p2p_group_interface=1")) { | |
7955 | wpa_printf(MSG_DEBUG, "nl80211: Use separate P2P group " | |
7956 | "interface"); | |
7957 | drv->capa.flags |= WPA_DRIVER_FLAGS_P2P_CONCURRENT; | |
7958 | drv->capa.flags |= WPA_DRIVER_FLAGS_P2P_MGMT_AND_NON_P2P; | |
7959 | } | |
7960 | #endif /* CONFIG_P2P */ | |
7961 | ||
ef24ad3e | 7962 | if (os_strstr(param, "use_monitor=1")) |
327b01d3 | 7963 | drv->use_monitor = 1; |
327b01d3 JM |
7964 | |
7965 | if (os_strstr(param, "force_connect_cmd=1")) { | |
327b01d3 | 7966 | drv->capa.flags &= ~WPA_DRIVER_FLAGS_SME; |
b497a212 | 7967 | drv->force_connect_cmd = 1; |
327b01d3 JM |
7968 | } |
7969 | ||
ef24ad3e | 7970 | if (os_strstr(param, "force_bss_selection=1")) |
4d584d8c | 7971 | drv->capa.flags |= WPA_DRIVER_FLAGS_BSS_SELECTION; |
4d584d8c | 7972 | |
64abb725 | 7973 | if (os_strstr(param, "no_offchannel_tx=1")) { |
64abb725 JM |
7974 | drv->capa.flags &= ~WPA_DRIVER_FLAGS_OFFCHANNEL_TX; |
7975 | drv->test_use_roc_tx = 1; | |
7976 | } | |
7977 | ||
c55f774d JM |
7978 | return 0; |
7979 | } | |
7980 | ||
7981 | ||
45e3fc72 | 7982 | static void * nl80211_global_init(void *ctx) |
f2ed8023 JM |
7983 | { |
7984 | struct nl80211_global *global; | |
36d84860 BG |
7985 | struct netlink_config *cfg; |
7986 | ||
f2ed8023 JM |
7987 | global = os_zalloc(sizeof(*global)); |
7988 | if (global == NULL) | |
7989 | return NULL; | |
45e3fc72 | 7990 | global->ctx = ctx; |
c81eff1a | 7991 | global->ioctl_sock = -1; |
f2ed8023 | 7992 | dl_list_init(&global->interfaces); |
ff6a158b | 7993 | global->if_add_ifindex = -1; |
36d84860 BG |
7994 | |
7995 | cfg = os_zalloc(sizeof(*cfg)); | |
7996 | if (cfg == NULL) | |
7997 | goto err; | |
7998 | ||
7999 | cfg->ctx = global; | |
8000 | cfg->newlink_cb = wpa_driver_nl80211_event_rtm_newlink; | |
8001 | cfg->dellink_cb = wpa_driver_nl80211_event_rtm_dellink; | |
8002 | global->netlink = netlink_init(cfg); | |
8003 | if (global->netlink == NULL) { | |
8004 | os_free(cfg); | |
8005 | goto err; | |
8006 | } | |
8007 | ||
2a7b66f5 BG |
8008 | if (wpa_driver_nl80211_init_nl_global(global) < 0) |
8009 | goto err; | |
8010 | ||
c81eff1a BG |
8011 | global->ioctl_sock = socket(PF_INET, SOCK_DGRAM, 0); |
8012 | if (global->ioctl_sock < 0) { | |
7ac3616d JM |
8013 | wpa_printf(MSG_ERROR, "nl80211: socket(PF_INET,SOCK_DGRAM) failed: %s", |
8014 | strerror(errno)); | |
c81eff1a BG |
8015 | goto err; |
8016 | } | |
8017 | ||
f2ed8023 | 8018 | return global; |
36d84860 BG |
8019 | |
8020 | err: | |
8021 | nl80211_global_deinit(global); | |
8022 | return NULL; | |
f2ed8023 JM |
8023 | } |
8024 | ||
8025 | ||
8026 | static void nl80211_global_deinit(void *priv) | |
8027 | { | |
8028 | struct nl80211_global *global = priv; | |
8029 | if (global == NULL) | |
8030 | return; | |
8031 | if (!dl_list_empty(&global->interfaces)) { | |
8032 | wpa_printf(MSG_ERROR, "nl80211: %u interface(s) remain at " | |
8033 | "nl80211_global_deinit", | |
8034 | dl_list_len(&global->interfaces)); | |
8035 | } | |
36d84860 BG |
8036 | |
8037 | if (global->netlink) | |
8038 | netlink_deinit(global->netlink); | |
8039 | ||
276e2d67 BG |
8040 | nl_destroy_handles(&global->nl); |
8041 | ||
5f65e9f7 | 8042 | if (global->nl_event) |
40a68f33 | 8043 | nl80211_destroy_eloop_handle(&global->nl_event, 0); |
d6c9aab8 JB |
8044 | |
8045 | nl_cb_put(global->nl_cb); | |
2a7b66f5 | 8046 | |
c81eff1a BG |
8047 | if (global->ioctl_sock >= 0) |
8048 | close(global->ioctl_sock); | |
8049 | ||
f2ed8023 JM |
8050 | os_free(global); |
8051 | } | |
8052 | ||
8053 | ||
6859f1cb BG |
8054 | static const char * nl80211_get_radio_name(void *priv) |
8055 | { | |
8056 | struct i802_bss *bss = priv; | |
8057 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
8058 | return drv->phyname; | |
8059 | } | |
8060 | ||
8061 | ||
061a3d3d VK |
8062 | static int nl80211_pmkid(struct i802_bss *bss, int cmd, |
8063 | struct wpa_pmkid_params *params) | |
a6efc65d JM |
8064 | { |
8065 | struct nl_msg *msg; | |
0887215d | 8066 | const size_t PMK_MAX_LEN = 48; /* current cfg80211 limit */ |
a6efc65d | 8067 | |
13f83980 | 8068 | if (!(msg = nl80211_bss_msg(bss, 0, cmd)) || |
061a3d3d VK |
8069 | (params->pmkid && |
8070 | nla_put(msg, NL80211_ATTR_PMKID, 16, params->pmkid)) || | |
8071 | (params->bssid && | |
8072 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, params->bssid)) || | |
8073 | (params->ssid_len && | |
8074 | nla_put(msg, NL80211_ATTR_SSID, params->ssid_len, params->ssid)) || | |
8075 | (params->fils_cache_id && | |
8076 | nla_put(msg, NL80211_ATTR_FILS_CACHE_ID, 2, | |
8077 | params->fils_cache_id)) || | |
c6ec9759 | 8078 | (cmd != NL80211_CMD_DEL_PMKSA && |
8079 | params->pmk_len && params->pmk_len <= PMK_MAX_LEN && | |
061a3d3d | 8080 | nla_put(msg, NL80211_ATTR_PMK, params->pmk_len, params->pmk))) { |
6110753b | 8081 | nl80211_nlmsg_clear(msg); |
a862e4a3 JM |
8082 | nlmsg_free(msg); |
8083 | return -ENOBUFS; | |
8084 | } | |
a6efc65d | 8085 | |
6110753b | 8086 | return send_and_recv_msgs(bss->drv, msg, NULL, (void *) -1); |
a6efc65d JM |
8087 | } |
8088 | ||
8089 | ||
6fbb5414 | 8090 | static int nl80211_add_pmkid(void *priv, struct wpa_pmkid_params *params) |
a6efc65d JM |
8091 | { |
8092 | struct i802_bss *bss = priv; | |
e7f6e6ee | 8093 | int ret; |
061a3d3d VK |
8094 | |
8095 | if (params->bssid) | |
8096 | wpa_printf(MSG_DEBUG, "nl80211: Add PMKID for " MACSTR, | |
8097 | MAC2STR(params->bssid)); | |
8098 | else if (params->fils_cache_id && params->ssid_len) { | |
8099 | wpa_printf(MSG_DEBUG, | |
8100 | "nl80211: Add PMKSA for cache id %02x%02x SSID %s", | |
8101 | params->fils_cache_id[0], params->fils_cache_id[1], | |
8102 | wpa_ssid_txt(params->ssid, params->ssid_len)); | |
8103 | } | |
8104 | ||
e7f6e6ee JM |
8105 | ret = nl80211_pmkid(bss, NL80211_CMD_SET_PMKSA, params); |
8106 | if (ret < 0) { | |
8107 | wpa_printf(MSG_DEBUG, | |
8108 | "nl80211: NL80211_CMD_SET_PMKSA failed: %d (%s)", | |
8109 | ret, strerror(-ret)); | |
8110 | } | |
8111 | ||
8112 | return ret; | |
a6efc65d JM |
8113 | } |
8114 | ||
8115 | ||
6fbb5414 | 8116 | static int nl80211_remove_pmkid(void *priv, struct wpa_pmkid_params *params) |
a6efc65d JM |
8117 | { |
8118 | struct i802_bss *bss = priv; | |
e7f6e6ee | 8119 | int ret; |
061a3d3d VK |
8120 | |
8121 | if (params->bssid) | |
8122 | wpa_printf(MSG_DEBUG, "nl80211: Delete PMKID for " MACSTR, | |
8123 | MAC2STR(params->bssid)); | |
8124 | else if (params->fils_cache_id && params->ssid_len) { | |
8125 | wpa_printf(MSG_DEBUG, | |
8126 | "nl80211: Delete PMKSA for cache id %02x%02x SSID %s", | |
8127 | params->fils_cache_id[0], params->fils_cache_id[1], | |
8128 | wpa_ssid_txt(params->ssid, params->ssid_len)); | |
8129 | } | |
8130 | ||
e7f6e6ee JM |
8131 | ret = nl80211_pmkid(bss, NL80211_CMD_DEL_PMKSA, params); |
8132 | if (ret < 0) { | |
8133 | wpa_printf(MSG_DEBUG, | |
8134 | "nl80211: NL80211_CMD_DEL_PMKSA failed: %d (%s)", | |
8135 | ret, strerror(-ret)); | |
8136 | } | |
8137 | ||
8138 | return ret; | |
a6efc65d JM |
8139 | } |
8140 | ||
8141 | ||
8142 | static int nl80211_flush_pmkid(void *priv) | |
8143 | { | |
8144 | struct i802_bss *bss = priv; | |
061a3d3d VK |
8145 | struct nl_msg *msg; |
8146 | ||
a6efc65d | 8147 | wpa_printf(MSG_DEBUG, "nl80211: Flush PMKIDs"); |
061a3d3d VK |
8148 | msg = nl80211_bss_msg(bss, 0, NL80211_CMD_FLUSH_PMKSA); |
8149 | if (!msg) | |
8150 | return -ENOBUFS; | |
8151 | return send_and_recv_msgs(bss->drv, msg, NULL, NULL); | |
a6efc65d JM |
8152 | } |
8153 | ||
8154 | ||
0185007c MK |
8155 | static void clean_survey_results(struct survey_results *survey_results) |
8156 | { | |
8157 | struct freq_survey *survey, *tmp; | |
8158 | ||
8159 | if (dl_list_empty(&survey_results->survey_list)) | |
8160 | return; | |
8161 | ||
8162 | dl_list_for_each_safe(survey, tmp, &survey_results->survey_list, | |
8163 | struct freq_survey, list) { | |
8164 | dl_list_del(&survey->list); | |
8165 | os_free(survey); | |
8166 | } | |
8167 | } | |
8168 | ||
8169 | ||
8170 | static void add_survey(struct nlattr **sinfo, u32 ifidx, | |
8171 | struct dl_list *survey_list) | |
8172 | { | |
8173 | struct freq_survey *survey; | |
8174 | ||
8175 | survey = os_zalloc(sizeof(struct freq_survey)); | |
8176 | if (!survey) | |
8177 | return; | |
8178 | ||
8179 | survey->ifidx = ifidx; | |
8180 | survey->freq = nla_get_u32(sinfo[NL80211_SURVEY_INFO_FREQUENCY]); | |
8181 | survey->filled = 0; | |
8182 | ||
8183 | if (sinfo[NL80211_SURVEY_INFO_NOISE]) { | |
8184 | survey->nf = (int8_t) | |
8185 | nla_get_u8(sinfo[NL80211_SURVEY_INFO_NOISE]); | |
8186 | survey->filled |= SURVEY_HAS_NF; | |
8187 | } | |
8188 | ||
8189 | if (sinfo[NL80211_SURVEY_INFO_CHANNEL_TIME]) { | |
8190 | survey->channel_time = | |
8191 | nla_get_u64(sinfo[NL80211_SURVEY_INFO_CHANNEL_TIME]); | |
8192 | survey->filled |= SURVEY_HAS_CHAN_TIME; | |
8193 | } | |
8194 | ||
8195 | if (sinfo[NL80211_SURVEY_INFO_CHANNEL_TIME_BUSY]) { | |
8196 | survey->channel_time_busy = | |
8197 | nla_get_u64(sinfo[NL80211_SURVEY_INFO_CHANNEL_TIME_BUSY]); | |
8198 | survey->filled |= SURVEY_HAS_CHAN_TIME_BUSY; | |
8199 | } | |
8200 | ||
8201 | if (sinfo[NL80211_SURVEY_INFO_CHANNEL_TIME_RX]) { | |
8202 | survey->channel_time_rx = | |
8203 | nla_get_u64(sinfo[NL80211_SURVEY_INFO_CHANNEL_TIME_RX]); | |
8204 | survey->filled |= SURVEY_HAS_CHAN_TIME_RX; | |
8205 | } | |
8206 | ||
8207 | if (sinfo[NL80211_SURVEY_INFO_CHANNEL_TIME_TX]) { | |
8208 | survey->channel_time_tx = | |
8209 | nla_get_u64(sinfo[NL80211_SURVEY_INFO_CHANNEL_TIME_TX]); | |
8210 | survey->filled |= SURVEY_HAS_CHAN_TIME_TX; | |
8211 | } | |
8212 | ||
8213 | 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)", | |
8214 | survey->freq, | |
8215 | survey->nf, | |
8216 | (unsigned long int) survey->channel_time, | |
8217 | (unsigned long int) survey->channel_time_busy, | |
8218 | (unsigned long int) survey->channel_time_tx, | |
8219 | (unsigned long int) survey->channel_time_rx, | |
8220 | survey->filled); | |
8221 | ||
8222 | dl_list_add_tail(survey_list, &survey->list); | |
8223 | } | |
8224 | ||
8225 | ||
8226 | static int check_survey_ok(struct nlattr **sinfo, u32 surveyed_freq, | |
8227 | unsigned int freq_filter) | |
8228 | { | |
8229 | if (!freq_filter) | |
8230 | return 1; | |
8231 | ||
8232 | return freq_filter == surveyed_freq; | |
8233 | } | |
8234 | ||
8235 | ||
8236 | static int survey_handler(struct nl_msg *msg, void *arg) | |
8237 | { | |
8238 | struct nlattr *tb[NL80211_ATTR_MAX + 1]; | |
8239 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); | |
8240 | struct nlattr *sinfo[NL80211_SURVEY_INFO_MAX + 1]; | |
8241 | struct survey_results *survey_results; | |
8242 | u32 surveyed_freq = 0; | |
8243 | u32 ifidx; | |
8244 | ||
8245 | static struct nla_policy survey_policy[NL80211_SURVEY_INFO_MAX + 1] = { | |
8246 | [NL80211_SURVEY_INFO_FREQUENCY] = { .type = NLA_U32 }, | |
8247 | [NL80211_SURVEY_INFO_NOISE] = { .type = NLA_U8 }, | |
8248 | }; | |
8249 | ||
8250 | survey_results = (struct survey_results *) arg; | |
8251 | ||
8252 | nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), | |
8253 | genlmsg_attrlen(gnlh, 0), NULL); | |
8254 | ||
e28f39b7 SJ |
8255 | if (!tb[NL80211_ATTR_IFINDEX]) |
8256 | return NL_SKIP; | |
8257 | ||
0185007c MK |
8258 | ifidx = nla_get_u32(tb[NL80211_ATTR_IFINDEX]); |
8259 | ||
8260 | if (!tb[NL80211_ATTR_SURVEY_INFO]) | |
8261 | return NL_SKIP; | |
8262 | ||
8263 | if (nla_parse_nested(sinfo, NL80211_SURVEY_INFO_MAX, | |
8264 | tb[NL80211_ATTR_SURVEY_INFO], | |
8265 | survey_policy)) | |
8266 | return NL_SKIP; | |
8267 | ||
8268 | if (!sinfo[NL80211_SURVEY_INFO_FREQUENCY]) { | |
8269 | wpa_printf(MSG_ERROR, "nl80211: Invalid survey data"); | |
8270 | return NL_SKIP; | |
8271 | } | |
8272 | ||
8273 | surveyed_freq = nla_get_u32(sinfo[NL80211_SURVEY_INFO_FREQUENCY]); | |
8274 | ||
8275 | if (!check_survey_ok(sinfo, surveyed_freq, | |
8276 | survey_results->freq_filter)) | |
8277 | return NL_SKIP; | |
8278 | ||
8279 | if (survey_results->freq_filter && | |
8280 | survey_results->freq_filter != surveyed_freq) { | |
8281 | wpa_printf(MSG_EXCESSIVE, "nl80211: Ignoring survey data for freq %d MHz", | |
8282 | surveyed_freq); | |
8283 | return NL_SKIP; | |
8284 | } | |
8285 | ||
8286 | add_survey(sinfo, ifidx, &survey_results->survey_list); | |
8287 | ||
8288 | return NL_SKIP; | |
8289 | } | |
8290 | ||
8291 | ||
8292 | static int wpa_driver_nl80211_get_survey(void *priv, unsigned int freq) | |
8293 | { | |
8294 | struct i802_bss *bss = priv; | |
8295 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
8296 | struct nl_msg *msg; | |
9725b784 | 8297 | int err; |
0185007c MK |
8298 | union wpa_event_data data; |
8299 | struct survey_results *survey_results; | |
8300 | ||
8301 | os_memset(&data, 0, sizeof(data)); | |
8302 | survey_results = &data.survey_results; | |
8303 | ||
8304 | dl_list_init(&survey_results->survey_list); | |
8305 | ||
9725b784 | 8306 | msg = nl80211_drv_msg(drv, NLM_F_DUMP, NL80211_CMD_GET_SURVEY); |
0185007c | 8307 | if (!msg) |
a862e4a3 | 8308 | return -ENOBUFS; |
0185007c | 8309 | |
0185007c MK |
8310 | if (freq) |
8311 | data.survey_results.freq_filter = freq; | |
8312 | ||
8313 | do { | |
8314 | wpa_printf(MSG_DEBUG, "nl80211: Fetch survey data"); | |
8315 | err = send_and_recv_msgs(drv, msg, survey_handler, | |
8316 | survey_results); | |
8317 | } while (err > 0); | |
8318 | ||
a862e4a3 | 8319 | if (err) |
0185007c | 8320 | wpa_printf(MSG_ERROR, "nl80211: Failed to process survey data"); |
a862e4a3 JM |
8321 | else |
8322 | wpa_supplicant_event(drv->ctx, EVENT_SURVEY, &data); | |
0185007c | 8323 | |
0185007c | 8324 | clean_survey_results(survey_results); |
0185007c MK |
8325 | return err; |
8326 | } | |
8327 | ||
8328 | ||
98cd3d1c JM |
8329 | static void nl80211_set_rekey_info(void *priv, const u8 *kek, size_t kek_len, |
8330 | const u8 *kck, size_t kck_len, | |
b14a210c JB |
8331 | const u8 *replay_ctr) |
8332 | { | |
8333 | struct i802_bss *bss = priv; | |
8334 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
8335 | struct nlattr *replay_nested; | |
8336 | struct nl_msg *msg; | |
64ae2447 | 8337 | int ret; |
b14a210c | 8338 | |
64ae2447 JM |
8339 | if (!drv->set_rekey_offload) |
8340 | return; | |
8341 | ||
8342 | wpa_printf(MSG_DEBUG, "nl80211: Set rekey offload"); | |
13f83980 | 8343 | if (!(msg = nl80211_bss_msg(bss, 0, NL80211_CMD_SET_REKEY_OFFLOAD)) || |
a862e4a3 | 8344 | !(replay_nested = nla_nest_start(msg, NL80211_ATTR_REKEY_DATA)) || |
98cd3d1c | 8345 | nla_put(msg, NL80211_REKEY_DATA_KEK, kek_len, kek) || |
b6ea7642 | 8346 | (kck_len && nla_put(msg, NL80211_REKEY_DATA_KCK, kck_len, kck)) || |
a862e4a3 JM |
8347 | nla_put(msg, NL80211_REKEY_DATA_REPLAY_CTR, NL80211_REPLAY_CTR_LEN, |
8348 | replay_ctr)) { | |
bbd89bfc | 8349 | nl80211_nlmsg_clear(msg); |
a862e4a3 JM |
8350 | nlmsg_free(msg); |
8351 | return; | |
8352 | } | |
b14a210c JB |
8353 | |
8354 | nla_nest_end(msg, replay_nested); | |
8355 | ||
64ae2447 JM |
8356 | ret = send_and_recv_msgs(drv, msg, NULL, (void *) -1); |
8357 | if (ret == -EOPNOTSUPP) { | |
8358 | wpa_printf(MSG_DEBUG, | |
8359 | "nl80211: Driver does not support rekey offload"); | |
8360 | drv->set_rekey_offload = 0; | |
8361 | } | |
b14a210c JB |
8362 | } |
8363 | ||
8364 | ||
39718852 JB |
8365 | static void nl80211_send_null_frame(struct i802_bss *bss, const u8 *own_addr, |
8366 | const u8 *addr, int qos) | |
bcf24348 | 8367 | { |
39718852 JB |
8368 | /* send data frame to poll STA and check whether |
8369 | * this frame is ACKed */ | |
bcf24348 JB |
8370 | struct { |
8371 | struct ieee80211_hdr hdr; | |
8372 | u16 qos_ctl; | |
8373 | } STRUCT_PACKED nulldata; | |
8374 | size_t size; | |
8375 | ||
8376 | /* Send data frame to poll STA and check whether this frame is ACKed */ | |
8377 | ||
8378 | os_memset(&nulldata, 0, sizeof(nulldata)); | |
8379 | ||
8380 | if (qos) { | |
8381 | nulldata.hdr.frame_control = | |
8382 | IEEE80211_FC(WLAN_FC_TYPE_DATA, | |
8383 | WLAN_FC_STYPE_QOS_NULL); | |
8384 | size = sizeof(nulldata); | |
8385 | } else { | |
8386 | nulldata.hdr.frame_control = | |
8387 | IEEE80211_FC(WLAN_FC_TYPE_DATA, | |
8388 | WLAN_FC_STYPE_NULLFUNC); | |
8389 | size = sizeof(struct ieee80211_hdr); | |
8390 | } | |
8391 | ||
8392 | nulldata.hdr.frame_control |= host_to_le16(WLAN_FC_FROMDS); | |
8393 | os_memcpy(nulldata.hdr.IEEE80211_DA_FROMDS, addr, ETH_ALEN); | |
8394 | os_memcpy(nulldata.hdr.IEEE80211_BSSID_FROMDS, own_addr, ETH_ALEN); | |
8395 | os_memcpy(nulldata.hdr.IEEE80211_SA_FROMDS, own_addr, ETH_ALEN); | |
8396 | ||
9ebce9c5 | 8397 | if (wpa_driver_nl80211_send_mlme(bss, (u8 *) &nulldata, size, 0, 0, 0, |
2d3943ce | 8398 | 0, 0, NULL, 0) < 0) |
bcf24348 JB |
8399 | wpa_printf(MSG_DEBUG, "nl80211_send_null_frame: Failed to " |
8400 | "send poll frame"); | |
8401 | } | |
8402 | ||
39718852 JB |
8403 | static void nl80211_poll_client(void *priv, const u8 *own_addr, const u8 *addr, |
8404 | int qos) | |
8405 | { | |
8406 | struct i802_bss *bss = priv; | |
8407 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
8408 | struct nl_msg *msg; | |
323a51cc | 8409 | u64 cookie; |
fc99fab7 | 8410 | int ret; |
39718852 JB |
8411 | |
8412 | if (!drv->poll_command_supported) { | |
8413 | nl80211_send_null_frame(bss, own_addr, addr, qos); | |
8414 | return; | |
8415 | } | |
8416 | ||
13f83980 | 8417 | if (!(msg = nl80211_bss_msg(bss, 0, NL80211_CMD_PROBE_CLIENT)) || |
a862e4a3 JM |
8418 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) { |
8419 | nlmsg_free(msg); | |
8420 | return; | |
8421 | } | |
39718852 | 8422 | |
323a51cc | 8423 | ret = send_and_recv_msgs(drv, msg, cookie_handler, &cookie); |
fc99fab7 JM |
8424 | if (ret < 0) { |
8425 | wpa_printf(MSG_DEBUG, "nl80211: Client probe request for " | |
8426 | MACSTR " failed: ret=%d (%s)", | |
8427 | MAC2STR(addr), ret, strerror(-ret)); | |
323a51cc IP |
8428 | } else { |
8429 | wpa_printf(MSG_DEBUG, | |
8430 | "nl80211: Client probe request addr=" MACSTR | |
8431 | " cookie=%llu", MAC2STR(addr), | |
8432 | (long long unsigned int) cookie); | |
fc99fab7 | 8433 | } |
39718852 JB |
8434 | } |
8435 | ||
bcf24348 | 8436 | |
29f338af JM |
8437 | static int nl80211_set_power_save(struct i802_bss *bss, int enabled) |
8438 | { | |
8439 | struct nl_msg *msg; | |
1baa130b | 8440 | int ret; |
29f338af | 8441 | |
13f83980 | 8442 | if (!(msg = nl80211_bss_msg(bss, 0, NL80211_CMD_SET_POWER_SAVE)) || |
a862e4a3 JM |
8443 | nla_put_u32(msg, NL80211_ATTR_PS_STATE, |
8444 | enabled ? NL80211_PS_ENABLED : NL80211_PS_DISABLED)) { | |
8445 | nlmsg_free(msg); | |
8446 | return -ENOBUFS; | |
8447 | } | |
1baa130b JM |
8448 | |
8449 | ret = send_and_recv_msgs(bss->drv, msg, NULL, NULL); | |
8450 | if (ret < 0) { | |
8451 | wpa_printf(MSG_DEBUG, | |
8452 | "nl80211: Setting PS state %s failed: %d (%s)", | |
8453 | enabled ? "enabled" : "disabled", | |
8454 | ret, strerror(-ret)); | |
8455 | } | |
8456 | return ret; | |
29f338af JM |
8457 | } |
8458 | ||
8459 | ||
8460 | static int nl80211_set_p2p_powersave(void *priv, int legacy_ps, int opp_ps, | |
8461 | int ctwindow) | |
8462 | { | |
8463 | struct i802_bss *bss = priv; | |
8464 | ||
8465 | wpa_printf(MSG_DEBUG, "nl80211: set_p2p_powersave (legacy_ps=%d " | |
8466 | "opp_ps=%d ctwindow=%d)", legacy_ps, opp_ps, ctwindow); | |
8467 | ||
0de38036 JM |
8468 | if (opp_ps != -1 || ctwindow != -1) { |
8469 | #ifdef ANDROID_P2P | |
8470 | wpa_driver_set_p2p_ps(priv, legacy_ps, opp_ps, ctwindow); | |
8471 | #else /* ANDROID_P2P */ | |
29f338af | 8472 | return -1; /* Not yet supported */ |
0de38036 JM |
8473 | #endif /* ANDROID_P2P */ |
8474 | } | |
29f338af JM |
8475 | |
8476 | if (legacy_ps == -1) | |
8477 | return 0; | |
8478 | if (legacy_ps != 0 && legacy_ps != 1) | |
8479 | return -1; /* Not yet supported */ | |
8480 | ||
8481 | return nl80211_set_power_save(bss, legacy_ps); | |
8482 | } | |
8483 | ||
8484 | ||
04e8003c JD |
8485 | static int nl80211_start_radar_detection(void *priv, |
8486 | struct hostapd_freq_params *freq) | |
f90e9c1c SW |
8487 | { |
8488 | struct i802_bss *bss = priv; | |
8489 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
8490 | struct nl_msg *msg; | |
8491 | int ret; | |
8492 | ||
ad9a1bfe JC |
8493 | wpa_printf(MSG_DEBUG, "nl80211: Start radar detection (CAC) %d MHz (ht_enabled=%d, vht_enabled=%d, he_enabled=%d, bandwidth=%d MHz, cf1=%d MHz, cf2=%d MHz)", |
8494 | freq->freq, freq->ht_enabled, freq->vht_enabled, freq->he_enabled, | |
04e8003c JD |
8495 | freq->bandwidth, freq->center_freq1, freq->center_freq2); |
8496 | ||
f90e9c1c SW |
8497 | if (!(drv->capa.flags & WPA_DRIVER_FLAGS_RADAR)) { |
8498 | wpa_printf(MSG_DEBUG, "nl80211: Driver does not support radar " | |
8499 | "detection"); | |
8500 | return -1; | |
8501 | } | |
8502 | ||
9725b784 | 8503 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_RADAR_DETECT)) || |
a862e4a3 JM |
8504 | nl80211_put_freq_params(msg, freq) < 0) { |
8505 | nlmsg_free(msg); | |
8506 | return -1; | |
8507 | } | |
f90e9c1c SW |
8508 | |
8509 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); | |
8510 | if (ret == 0) | |
8511 | return 0; | |
8512 | wpa_printf(MSG_DEBUG, "nl80211: Failed to start radar detection: " | |
8513 | "%d (%s)", ret, strerror(-ret)); | |
f90e9c1c SW |
8514 | return -1; |
8515 | } | |
8516 | ||
03ea1786 AN |
8517 | #ifdef CONFIG_TDLS |
8518 | ||
8519 | static int nl80211_send_tdls_mgmt(void *priv, const u8 *dst, u8 action_code, | |
8520 | u8 dialog_token, u16 status_code, | |
984dadc2 AN |
8521 | u32 peer_capab, int initiator, const u8 *buf, |
8522 | size_t len) | |
03ea1786 AN |
8523 | { |
8524 | struct i802_bss *bss = priv; | |
8525 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
8526 | struct nl_msg *msg; | |
8527 | ||
8528 | if (!(drv->capa.flags & WPA_DRIVER_FLAGS_TDLS_SUPPORT)) | |
8529 | return -EOPNOTSUPP; | |
8530 | ||
8531 | if (!dst) | |
8532 | return -EINVAL; | |
8533 | ||
9725b784 | 8534 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_TDLS_MGMT)) || |
a862e4a3 JM |
8535 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, dst) || |
8536 | nla_put_u8(msg, NL80211_ATTR_TDLS_ACTION, action_code) || | |
8537 | nla_put_u8(msg, NL80211_ATTR_TDLS_DIALOG_TOKEN, dialog_token) || | |
8538 | nla_put_u16(msg, NL80211_ATTR_STATUS_CODE, status_code)) | |
8539 | goto fail; | |
96ecea5e SD |
8540 | if (peer_capab) { |
8541 | /* | |
8542 | * The internal enum tdls_peer_capability definition is | |
8543 | * currently identical with the nl80211 enum | |
8544 | * nl80211_tdls_peer_capability, so no conversion is needed | |
8545 | * here. | |
8546 | */ | |
a862e4a3 JM |
8547 | if (nla_put_u32(msg, NL80211_ATTR_TDLS_PEER_CAPABILITY, |
8548 | peer_capab)) | |
8549 | goto fail; | |
96ecea5e | 8550 | } |
a862e4a3 JM |
8551 | if ((initiator && |
8552 | nla_put_flag(msg, NL80211_ATTR_TDLS_INITIATOR)) || | |
8553 | nla_put(msg, NL80211_ATTR_IE, len, buf)) | |
8554 | goto fail; | |
03ea1786 AN |
8555 | |
8556 | return send_and_recv_msgs(drv, msg, NULL, NULL); | |
8557 | ||
a862e4a3 | 8558 | fail: |
03ea1786 AN |
8559 | nlmsg_free(msg); |
8560 | return -ENOBUFS; | |
8561 | } | |
8562 | ||
8563 | ||
8564 | static int nl80211_tdls_oper(void *priv, enum tdls_oper oper, const u8 *peer) | |
8565 | { | |
8566 | struct i802_bss *bss = priv; | |
8567 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
8568 | struct nl_msg *msg; | |
8569 | enum nl80211_tdls_operation nl80211_oper; | |
b2442f25 | 8570 | int res; |
03ea1786 AN |
8571 | |
8572 | if (!(drv->capa.flags & WPA_DRIVER_FLAGS_TDLS_SUPPORT)) | |
8573 | return -EOPNOTSUPP; | |
8574 | ||
8575 | switch (oper) { | |
8576 | case TDLS_DISCOVERY_REQ: | |
8577 | nl80211_oper = NL80211_TDLS_DISCOVERY_REQ; | |
8578 | break; | |
8579 | case TDLS_SETUP: | |
8580 | nl80211_oper = NL80211_TDLS_SETUP; | |
8581 | break; | |
8582 | case TDLS_TEARDOWN: | |
8583 | nl80211_oper = NL80211_TDLS_TEARDOWN; | |
8584 | break; | |
8585 | case TDLS_ENABLE_LINK: | |
8586 | nl80211_oper = NL80211_TDLS_ENABLE_LINK; | |
8587 | break; | |
8588 | case TDLS_DISABLE_LINK: | |
8589 | nl80211_oper = NL80211_TDLS_DISABLE_LINK; | |
8590 | break; | |
8591 | case TDLS_ENABLE: | |
8592 | return 0; | |
8593 | case TDLS_DISABLE: | |
8594 | return 0; | |
8595 | default: | |
8596 | return -EINVAL; | |
8597 | } | |
8598 | ||
9725b784 | 8599 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_TDLS_OPER)) || |
a862e4a3 | 8600 | nla_put_u8(msg, NL80211_ATTR_TDLS_OPERATION, nl80211_oper) || |
a862e4a3 JM |
8601 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer)) { |
8602 | nlmsg_free(msg); | |
8603 | return -ENOBUFS; | |
8604 | } | |
03ea1786 | 8605 | |
b2442f25 JM |
8606 | res = send_and_recv_msgs(drv, msg, NULL, NULL); |
8607 | wpa_printf(MSG_DEBUG, "nl80211: TDLS_OPER: oper=%d mac=" MACSTR | |
8608 | " --> res=%d (%s)", nl80211_oper, MAC2STR(peer), res, | |
8609 | strerror(-res)); | |
8610 | return res; | |
03ea1786 AN |
8611 | } |
8612 | ||
72b2605f AN |
8613 | |
8614 | static int | |
8615 | nl80211_tdls_enable_channel_switch(void *priv, const u8 *addr, u8 oper_class, | |
8616 | const struct hostapd_freq_params *params) | |
8617 | { | |
8618 | struct i802_bss *bss = priv; | |
8619 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
8620 | struct nl_msg *msg; | |
8621 | int ret = -ENOBUFS; | |
8622 | ||
8623 | if (!(drv->capa.flags & WPA_DRIVER_FLAGS_TDLS_SUPPORT) || | |
8624 | !(drv->capa.flags & WPA_DRIVER_FLAGS_TDLS_CHANNEL_SWITCH)) | |
8625 | return -EOPNOTSUPP; | |
8626 | ||
8627 | wpa_printf(MSG_DEBUG, "nl80211: Enable TDLS channel switch " MACSTR | |
8628 | " oper_class=%u freq=%u", | |
8629 | MAC2STR(addr), oper_class, params->freq); | |
8630 | msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_TDLS_CHANNEL_SWITCH); | |
8631 | if (!msg || | |
8632 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) || | |
8633 | nla_put_u8(msg, NL80211_ATTR_OPER_CLASS, oper_class) || | |
8634 | (ret = nl80211_put_freq_params(msg, params))) { | |
8635 | nlmsg_free(msg); | |
8636 | wpa_printf(MSG_DEBUG, "nl80211: Could not build TDLS chan switch"); | |
8637 | return ret; | |
8638 | } | |
8639 | ||
8640 | return send_and_recv_msgs(drv, msg, NULL, NULL); | |
8641 | } | |
8642 | ||
8643 | ||
8644 | static int | |
8645 | nl80211_tdls_disable_channel_switch(void *priv, const u8 *addr) | |
8646 | { | |
8647 | struct i802_bss *bss = priv; | |
8648 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
8649 | struct nl_msg *msg; | |
8650 | ||
8651 | if (!(drv->capa.flags & WPA_DRIVER_FLAGS_TDLS_SUPPORT) || | |
8652 | !(drv->capa.flags & WPA_DRIVER_FLAGS_TDLS_CHANNEL_SWITCH)) | |
8653 | return -EOPNOTSUPP; | |
8654 | ||
8655 | wpa_printf(MSG_DEBUG, "nl80211: Disable TDLS channel switch " MACSTR, | |
8656 | MAC2STR(addr)); | |
8657 | msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_TDLS_CANCEL_CHANNEL_SWITCH); | |
8658 | if (!msg || | |
8659 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) { | |
8660 | nlmsg_free(msg); | |
8661 | wpa_printf(MSG_DEBUG, | |
8662 | "nl80211: Could not build TDLS cancel chan switch"); | |
8663 | return -ENOBUFS; | |
8664 | } | |
8665 | ||
8666 | return send_and_recv_msgs(drv, msg, NULL, NULL); | |
8667 | } | |
8668 | ||
03ea1786 AN |
8669 | #endif /* CONFIG TDLS */ |
8670 | ||
8671 | ||
9ebce9c5 JM |
8672 | static int driver_nl80211_set_key(const char *ifname, void *priv, |
8673 | enum wpa_alg alg, const u8 *addr, | |
8674 | int key_idx, int set_tx, | |
8675 | const u8 *seq, size_t seq_len, | |
8676 | const u8 *key, size_t key_len) | |
8677 | { | |
8678 | struct i802_bss *bss = priv; | |
8679 | return wpa_driver_nl80211_set_key(ifname, bss, alg, addr, key_idx, | |
8680 | set_tx, seq, seq_len, key, key_len); | |
8681 | } | |
8682 | ||
8683 | ||
8684 | static int driver_nl80211_scan2(void *priv, | |
8685 | struct wpa_driver_scan_params *params) | |
8686 | { | |
8687 | struct i802_bss *bss = priv; | |
b658547d | 8688 | #ifdef CONFIG_DRIVER_NL80211_QCA |
adcd7c4b KV |
8689 | struct wpa_driver_nl80211_data *drv = bss->drv; |
8690 | ||
8691 | /* | |
8692 | * Do a vendor specific scan if possible. If only_new_results is | |
8693 | * set, do a normal scan since a kernel (cfg80211) BSS cache flush | |
8694 | * cannot be achieved through a vendor scan. The below condition may | |
8695 | * need to be modified if new scan flags are added in the future whose | |
8696 | * functionality can only be achieved through a normal scan. | |
8697 | */ | |
8698 | if (drv->scan_vendor_cmd_avail && !params->only_new_results) | |
8699 | return wpa_driver_nl80211_vendor_scan(bss, params); | |
b658547d | 8700 | #endif /* CONFIG_DRIVER_NL80211_QCA */ |
9ebce9c5 JM |
8701 | return wpa_driver_nl80211_scan(bss, params); |
8702 | } | |
8703 | ||
8704 | ||
8705 | static int driver_nl80211_deauthenticate(void *priv, const u8 *addr, | |
4be17ffb | 8706 | u16 reason_code) |
9ebce9c5 JM |
8707 | { |
8708 | struct i802_bss *bss = priv; | |
8709 | return wpa_driver_nl80211_deauthenticate(bss, addr, reason_code); | |
8710 | } | |
8711 | ||
8712 | ||
8713 | static int driver_nl80211_authenticate(void *priv, | |
8714 | struct wpa_driver_auth_params *params) | |
8715 | { | |
8716 | struct i802_bss *bss = priv; | |
8717 | return wpa_driver_nl80211_authenticate(bss, params); | |
8718 | } | |
8719 | ||
8720 | ||
8721 | static void driver_nl80211_deinit(void *priv) | |
8722 | { | |
8723 | struct i802_bss *bss = priv; | |
8724 | wpa_driver_nl80211_deinit(bss); | |
8725 | } | |
8726 | ||
8727 | ||
8728 | static int driver_nl80211_if_remove(void *priv, enum wpa_driver_if_type type, | |
8729 | const char *ifname) | |
8730 | { | |
8731 | struct i802_bss *bss = priv; | |
8732 | return wpa_driver_nl80211_if_remove(bss, type, ifname); | |
8733 | } | |
8734 | ||
8735 | ||
8736 | static int driver_nl80211_send_mlme(void *priv, const u8 *data, | |
5d180a77 | 8737 | size_t data_len, int noack, |
2d3943ce AO |
8738 | unsigned int freq, |
8739 | const u16 *csa_offs, size_t csa_offs_len) | |
9ebce9c5 JM |
8740 | { |
8741 | struct i802_bss *bss = priv; | |
8742 | return wpa_driver_nl80211_send_mlme(bss, data, data_len, noack, | |
2d3943ce AO |
8743 | freq, 0, 0, 0, csa_offs, |
8744 | csa_offs_len); | |
9ebce9c5 JM |
8745 | } |
8746 | ||
8747 | ||
8748 | static int driver_nl80211_sta_remove(void *priv, const u8 *addr) | |
8749 | { | |
8750 | struct i802_bss *bss = priv; | |
59d7148a | 8751 | return wpa_driver_nl80211_sta_remove(bss, addr, -1, 0); |
9ebce9c5 JM |
8752 | } |
8753 | ||
8754 | ||
9ebce9c5 JM |
8755 | static int driver_nl80211_set_sta_vlan(void *priv, const u8 *addr, |
8756 | const char *ifname, int vlan_id) | |
8757 | { | |
8758 | struct i802_bss *bss = priv; | |
8759 | return i802_set_sta_vlan(bss, addr, ifname, vlan_id); | |
8760 | } | |
9ebce9c5 JM |
8761 | |
8762 | ||
8763 | static int driver_nl80211_read_sta_data(void *priv, | |
8764 | struct hostap_sta_driver_data *data, | |
8765 | const u8 *addr) | |
8766 | { | |
8767 | struct i802_bss *bss = priv; | |
7824bf77 JC |
8768 | |
8769 | os_memset(data, 0, sizeof(*data)); | |
9ebce9c5 JM |
8770 | return i802_read_sta_data(bss, data, addr); |
8771 | } | |
8772 | ||
8773 | ||
8774 | static int driver_nl80211_send_action(void *priv, unsigned int freq, | |
8775 | unsigned int wait_time, | |
8776 | const u8 *dst, const u8 *src, | |
8777 | const u8 *bssid, | |
8778 | const u8 *data, size_t data_len, | |
8779 | int no_cck) | |
8780 | { | |
8781 | struct i802_bss *bss = priv; | |
8782 | return wpa_driver_nl80211_send_action(bss, freq, wait_time, dst, src, | |
8783 | bssid, data, data_len, no_cck); | |
8784 | } | |
8785 | ||
8786 | ||
8787 | static int driver_nl80211_probe_req_report(void *priv, int report) | |
8788 | { | |
8789 | struct i802_bss *bss = priv; | |
8790 | return wpa_driver_nl80211_probe_req_report(bss, report); | |
8791 | } | |
8792 | ||
8793 | ||
6a1ce395 DG |
8794 | static int wpa_driver_nl80211_update_ft_ies(void *priv, const u8 *md, |
8795 | const u8 *ies, size_t ies_len) | |
8796 | { | |
8797 | int ret; | |
8798 | struct nl_msg *msg; | |
8799 | struct i802_bss *bss = priv; | |
8800 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
8801 | u16 mdid = WPA_GET_LE16(md); | |
8802 | ||
6a1ce395 | 8803 | wpa_printf(MSG_DEBUG, "nl80211: Updating FT IEs"); |
9725b784 | 8804 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_UPDATE_FT_IES)) || |
a862e4a3 JM |
8805 | nla_put(msg, NL80211_ATTR_IE, ies_len, ies) || |
8806 | nla_put_u16(msg, NL80211_ATTR_MDID, mdid)) { | |
8807 | nlmsg_free(msg); | |
8808 | return -ENOBUFS; | |
8809 | } | |
6a1ce395 DG |
8810 | |
8811 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); | |
8812 | if (ret) { | |
8813 | wpa_printf(MSG_DEBUG, "nl80211: update_ft_ies failed " | |
8814 | "err=%d (%s)", ret, strerror(-ret)); | |
8815 | } | |
8816 | ||
8817 | return ret; | |
6a1ce395 DG |
8818 | } |
8819 | ||
8820 | ||
d1836e23 LD |
8821 | static int nl80211_update_dh_ie(void *priv, const u8 *peer_mac, |
8822 | u16 reason_code, const u8 *ie, size_t ie_len) | |
8823 | { | |
8824 | int ret; | |
8825 | struct nl_msg *msg; | |
8826 | struct i802_bss *bss = priv; | |
8827 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
8828 | ||
8829 | wpa_printf(MSG_DEBUG, "nl80211: Updating DH IE peer: " MACSTR | |
8830 | " reason %u", MAC2STR(peer_mac), reason_code); | |
8831 | if (!(msg = nl80211_bss_msg(bss, 0, NL80211_CMD_UPDATE_OWE_INFO)) || | |
8832 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer_mac) || | |
8833 | nla_put_u16(msg, NL80211_ATTR_STATUS_CODE, reason_code) || | |
8834 | (ie && nla_put(msg, NL80211_ATTR_IE, ie_len, ie))) { | |
8835 | nlmsg_free(msg); | |
8836 | return -ENOBUFS; | |
8837 | } | |
8838 | ||
8839 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); | |
8840 | if (ret) { | |
8841 | wpa_printf(MSG_DEBUG, | |
8842 | "nl80211: update_dh_ie failed err=%d (%s)", | |
8843 | ret, strerror(-ret)); | |
8844 | } | |
8845 | ||
8846 | return ret; | |
8847 | } | |
8848 | ||
8849 | ||
47754718 | 8850 | static const u8 * wpa_driver_nl80211_get_macaddr(void *priv) |
597b94f5 AS |
8851 | { |
8852 | struct i802_bss *bss = priv; | |
8853 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
8854 | ||
8855 | if (drv->nlmode != NL80211_IFTYPE_P2P_DEVICE) | |
8856 | return NULL; | |
8857 | ||
8858 | return bss->addr; | |
8859 | } | |
8860 | ||
8861 | ||
a771c07d JM |
8862 | static const char * scan_state_str(enum scan_states scan_state) |
8863 | { | |
8864 | switch (scan_state) { | |
8865 | case NO_SCAN: | |
8866 | return "NO_SCAN"; | |
8867 | case SCAN_REQUESTED: | |
8868 | return "SCAN_REQUESTED"; | |
8869 | case SCAN_STARTED: | |
8870 | return "SCAN_STARTED"; | |
8871 | case SCAN_COMPLETED: | |
8872 | return "SCAN_COMPLETED"; | |
8873 | case SCAN_ABORTED: | |
8874 | return "SCAN_ABORTED"; | |
8875 | case SCHED_SCAN_STARTED: | |
8876 | return "SCHED_SCAN_STARTED"; | |
8877 | case SCHED_SCAN_STOPPED: | |
8878 | return "SCHED_SCAN_STOPPED"; | |
8879 | case SCHED_SCAN_RESULTS: | |
8880 | return "SCHED_SCAN_RESULTS"; | |
8881 | } | |
8882 | ||
8883 | return "??"; | |
8884 | } | |
8885 | ||
8886 | ||
8887 | static int wpa_driver_nl80211_status(void *priv, char *buf, size_t buflen) | |
8888 | { | |
8889 | struct i802_bss *bss = priv; | |
8890 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
8891 | int res; | |
8892 | char *pos, *end; | |
fea49f8f JM |
8893 | struct nl_msg *msg; |
8894 | char alpha2[3] = { 0, 0, 0 }; | |
a771c07d JM |
8895 | |
8896 | pos = buf; | |
8897 | end = buf + buflen; | |
8898 | ||
8899 | res = os_snprintf(pos, end - pos, | |
8900 | "ifindex=%d\n" | |
8901 | "ifname=%s\n" | |
8902 | "brname=%s\n" | |
8903 | "addr=" MACSTR "\n" | |
8904 | "freq=%d\n" | |
c809756f | 8905 | "%s%s%s%s%s%s", |
a771c07d JM |
8906 | bss->ifindex, |
8907 | bss->ifname, | |
8908 | bss->brname, | |
8909 | MAC2STR(bss->addr), | |
8910 | bss->freq, | |
8911 | bss->beacon_set ? "beacon_set=1\n" : "", | |
8912 | bss->added_if_into_bridge ? | |
8913 | "added_if_into_bridge=1\n" : "", | |
c809756f | 8914 | bss->already_in_bridge ? "already_in_bridge=1\n" : "", |
a771c07d JM |
8915 | bss->added_bridge ? "added_bridge=1\n" : "", |
8916 | bss->in_deinit ? "in_deinit=1\n" : "", | |
8917 | bss->if_dynamic ? "if_dynamic=1\n" : ""); | |
d85e1fc8 | 8918 | if (os_snprintf_error(end - pos, res)) |
a771c07d JM |
8919 | return pos - buf; |
8920 | pos += res; | |
8921 | ||
8922 | if (bss->wdev_id_set) { | |
8923 | res = os_snprintf(pos, end - pos, "wdev_id=%llu\n", | |
8924 | (unsigned long long) bss->wdev_id); | |
d85e1fc8 | 8925 | if (os_snprintf_error(end - pos, res)) |
a771c07d JM |
8926 | return pos - buf; |
8927 | pos += res; | |
8928 | } | |
8929 | ||
8930 | res = os_snprintf(pos, end - pos, | |
8931 | "phyname=%s\n" | |
fee354c7 | 8932 | "perm_addr=" MACSTR "\n" |
a771c07d JM |
8933 | "drv_ifindex=%d\n" |
8934 | "operstate=%d\n" | |
8935 | "scan_state=%s\n" | |
8936 | "auth_bssid=" MACSTR "\n" | |
8937 | "auth_attempt_bssid=" MACSTR "\n" | |
8938 | "bssid=" MACSTR "\n" | |
8939 | "prev_bssid=" MACSTR "\n" | |
8940 | "associated=%d\n" | |
8941 | "assoc_freq=%u\n" | |
8942 | "monitor_sock=%d\n" | |
8943 | "monitor_ifidx=%d\n" | |
8944 | "monitor_refcount=%d\n" | |
8945 | "last_mgmt_freq=%u\n" | |
8946 | "eapol_tx_sock=%d\n" | |
97752f79 | 8947 | "%s%s%s%s%s%s%s%s%s%s%s%s%s", |
a771c07d | 8948 | drv->phyname, |
fee354c7 | 8949 | MAC2STR(drv->perm_addr), |
a771c07d JM |
8950 | drv->ifindex, |
8951 | drv->operstate, | |
8952 | scan_state_str(drv->scan_state), | |
8953 | MAC2STR(drv->auth_bssid), | |
8954 | MAC2STR(drv->auth_attempt_bssid), | |
8955 | MAC2STR(drv->bssid), | |
8956 | MAC2STR(drv->prev_bssid), | |
8957 | drv->associated, | |
8958 | drv->assoc_freq, | |
8959 | drv->monitor_sock, | |
8960 | drv->monitor_ifidx, | |
8961 | drv->monitor_refcount, | |
8962 | drv->last_mgmt_freq, | |
8963 | drv->eapol_tx_sock, | |
8964 | drv->ignore_if_down_event ? | |
8965 | "ignore_if_down_event=1\n" : "", | |
8966 | drv->scan_complete_events ? | |
8967 | "scan_complete_events=1\n" : "", | |
8968 | drv->disabled_11b_rates ? | |
8969 | "disabled_11b_rates=1\n" : "", | |
8970 | drv->pending_remain_on_chan ? | |
8971 | "pending_remain_on_chan=1\n" : "", | |
8972 | drv->in_interface_list ? "in_interface_list=1\n" : "", | |
8973 | drv->device_ap_sme ? "device_ap_sme=1\n" : "", | |
8974 | drv->poll_command_supported ? | |
8975 | "poll_command_supported=1\n" : "", | |
8976 | drv->data_tx_status ? "data_tx_status=1\n" : "", | |
8977 | drv->scan_for_auth ? "scan_for_auth=1\n" : "", | |
8978 | drv->retry_auth ? "retry_auth=1\n" : "", | |
8979 | drv->use_monitor ? "use_monitor=1\n" : "", | |
8980 | drv->ignore_next_local_disconnect ? | |
8981 | "ignore_next_local_disconnect=1\n" : "", | |
d6a36f39 | 8982 | drv->ignore_next_local_deauth ? |
97752f79 | 8983 | "ignore_next_local_deauth=1\n" : ""); |
d85e1fc8 | 8984 | if (os_snprintf_error(end - pos, res)) |
a771c07d JM |
8985 | return pos - buf; |
8986 | pos += res; | |
8987 | ||
8988 | if (drv->has_capability) { | |
8989 | res = os_snprintf(pos, end - pos, | |
8990 | "capa.key_mgmt=0x%x\n" | |
8991 | "capa.enc=0x%x\n" | |
8992 | "capa.auth=0x%x\n" | |
24bd4e0b | 8993 | "capa.flags=0x%llx\n" |
a0a34d53 | 8994 | "capa.rrm_flags=0x%x\n" |
a771c07d JM |
8995 | "capa.max_scan_ssids=%d\n" |
8996 | "capa.max_sched_scan_ssids=%d\n" | |
8997 | "capa.sched_scan_supported=%d\n" | |
8998 | "capa.max_match_sets=%d\n" | |
8999 | "capa.max_remain_on_chan=%u\n" | |
9000 | "capa.max_stations=%u\n" | |
9001 | "capa.probe_resp_offloads=0x%x\n" | |
9002 | "capa.max_acl_mac_addrs=%u\n" | |
86056fea IP |
9003 | "capa.num_multichan_concurrent=%u\n" |
9004 | "capa.mac_addr_rand_sched_scan_supported=%d\n" | |
079a28f7 AK |
9005 | "capa.mac_addr_rand_scan_supported=%d\n" |
9006 | "capa.conc_capab=%u\n" | |
9007 | "capa.max_conc_chan_2_4=%u\n" | |
09ea4309 AS |
9008 | "capa.max_conc_chan_5_0=%u\n" |
9009 | "capa.max_sched_scan_plans=%u\n" | |
9010 | "capa.max_sched_scan_plan_interval=%u\n" | |
9011 | "capa.max_sched_scan_plan_iterations=%u\n", | |
a771c07d JM |
9012 | drv->capa.key_mgmt, |
9013 | drv->capa.enc, | |
9014 | drv->capa.auth, | |
24bd4e0b | 9015 | (unsigned long long) drv->capa.flags, |
a0a34d53 | 9016 | drv->capa.rrm_flags, |
a771c07d JM |
9017 | drv->capa.max_scan_ssids, |
9018 | drv->capa.max_sched_scan_ssids, | |
9019 | drv->capa.sched_scan_supported, | |
9020 | drv->capa.max_match_sets, | |
9021 | drv->capa.max_remain_on_chan, | |
9022 | drv->capa.max_stations, | |
9023 | drv->capa.probe_resp_offloads, | |
9024 | drv->capa.max_acl_mac_addrs, | |
86056fea IP |
9025 | drv->capa.num_multichan_concurrent, |
9026 | drv->capa.mac_addr_rand_sched_scan_supported, | |
079a28f7 AK |
9027 | drv->capa.mac_addr_rand_scan_supported, |
9028 | drv->capa.conc_capab, | |
9029 | drv->capa.max_conc_chan_2_4, | |
09ea4309 AS |
9030 | drv->capa.max_conc_chan_5_0, |
9031 | drv->capa.max_sched_scan_plans, | |
9032 | drv->capa.max_sched_scan_plan_interval, | |
9033 | drv->capa.max_sched_scan_plan_iterations); | |
d85e1fc8 | 9034 | if (os_snprintf_error(end - pos, res)) |
a771c07d JM |
9035 | return pos - buf; |
9036 | pos += res; | |
9037 | } | |
9038 | ||
fea49f8f JM |
9039 | msg = nlmsg_alloc(); |
9040 | if (msg && | |
9041 | nl80211_cmd(drv, msg, 0, NL80211_CMD_GET_REG) && | |
9042 | nla_put_u32(msg, NL80211_ATTR_WIPHY, drv->wiphy_idx) == 0) { | |
9043 | if (send_and_recv_msgs(drv, msg, nl80211_get_country, | |
9044 | alpha2) == 0 && | |
9045 | alpha2[0]) { | |
9046 | res = os_snprintf(pos, end - pos, "country=%s\n", | |
9047 | alpha2); | |
9048 | if (os_snprintf_error(end - pos, res)) | |
9049 | return pos - buf; | |
9050 | pos += res; | |
9051 | } | |
9052 | } else { | |
9053 | nlmsg_free(msg); | |
9054 | } | |
9055 | ||
a771c07d JM |
9056 | return pos - buf; |
9057 | } | |
9058 | ||
9059 | ||
1c4ffa87 AO |
9060 | static int set_beacon_data(struct nl_msg *msg, struct beacon_data *settings) |
9061 | { | |
a862e4a3 JM |
9062 | if ((settings->head && |
9063 | nla_put(msg, NL80211_ATTR_BEACON_HEAD, | |
9064 | settings->head_len, settings->head)) || | |
9065 | (settings->tail && | |
9066 | nla_put(msg, NL80211_ATTR_BEACON_TAIL, | |
9067 | settings->tail_len, settings->tail)) || | |
9068 | (settings->beacon_ies && | |
9069 | nla_put(msg, NL80211_ATTR_IE, | |
9070 | settings->beacon_ies_len, settings->beacon_ies)) || | |
9071 | (settings->proberesp_ies && | |
9072 | nla_put(msg, NL80211_ATTR_IE_PROBE_RESP, | |
9073 | settings->proberesp_ies_len, settings->proberesp_ies)) || | |
9074 | (settings->assocresp_ies && | |
9075 | nla_put(msg, NL80211_ATTR_IE_ASSOC_RESP, | |
9076 | settings->assocresp_ies_len, settings->assocresp_ies)) || | |
9077 | (settings->probe_resp && | |
9078 | nla_put(msg, NL80211_ATTR_PROBE_RESP, | |
9079 | settings->probe_resp_len, settings->probe_resp))) | |
9080 | return -ENOBUFS; | |
1c4ffa87 AO |
9081 | |
9082 | return 0; | |
1c4ffa87 AO |
9083 | } |
9084 | ||
9085 | ||
9086 | static int nl80211_switch_channel(void *priv, struct csa_settings *settings) | |
9087 | { | |
9088 | struct nl_msg *msg; | |
9089 | struct i802_bss *bss = priv; | |
9090 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
9091 | struct nlattr *beacon_csa; | |
9092 | int ret = -ENOBUFS; | |
366179d2 AO |
9093 | int csa_off_len = 0; |
9094 | int i; | |
1c4ffa87 | 9095 | |
8d1fdde7 | 9096 | wpa_printf(MSG_DEBUG, "nl80211: Channel switch request (cs_count=%u block_tx=%u freq=%d width=%d cf1=%d cf2=%d)", |
1c4ffa87 | 9097 | settings->cs_count, settings->block_tx, |
8d1fdde7 JD |
9098 | settings->freq_params.freq, settings->freq_params.bandwidth, |
9099 | settings->freq_params.center_freq1, | |
9100 | settings->freq_params.center_freq2); | |
1c4ffa87 | 9101 | |
991aa9c7 | 9102 | if (!(drv->capa.flags & WPA_DRIVER_FLAGS_AP_CSA)) { |
1c4ffa87 AO |
9103 | wpa_printf(MSG_DEBUG, "nl80211: Driver does not support channel switch command"); |
9104 | return -EOPNOTSUPP; | |
9105 | } | |
9106 | ||
0928b629 PO |
9107 | if (drv->nlmode != NL80211_IFTYPE_AP && |
9108 | drv->nlmode != NL80211_IFTYPE_P2P_GO && | |
9109 | drv->nlmode != NL80211_IFTYPE_MESH_POINT) | |
1c4ffa87 AO |
9110 | return -EOPNOTSUPP; |
9111 | ||
366179d2 AO |
9112 | /* |
9113 | * Remove empty counters, assuming Probe Response and Beacon frame | |
9114 | * counters match. This implementation assumes that there are only two | |
9115 | * counters. | |
9116 | */ | |
9117 | if (settings->counter_offset_beacon[0] && | |
9118 | !settings->counter_offset_beacon[1]) { | |
9119 | csa_off_len = 1; | |
9120 | } else if (settings->counter_offset_beacon[1] && | |
9121 | !settings->counter_offset_beacon[0]) { | |
9122 | csa_off_len = 1; | |
9123 | settings->counter_offset_beacon[0] = | |
9124 | settings->counter_offset_beacon[1]; | |
9125 | settings->counter_offset_presp[0] = | |
9126 | settings->counter_offset_presp[1]; | |
9127 | } else if (settings->counter_offset_beacon[1] && | |
9128 | settings->counter_offset_beacon[0]) { | |
9129 | csa_off_len = 2; | |
9130 | } else { | |
9131 | wpa_printf(MSG_ERROR, "nl80211: No CSA counters provided"); | |
9132 | return -EINVAL; | |
9133 | } | |
9134 | ||
9135 | /* Check CSA counters validity */ | |
9136 | if (drv->capa.max_csa_counters && | |
9137 | csa_off_len > drv->capa.max_csa_counters) { | |
9138 | wpa_printf(MSG_ERROR, | |
9139 | "nl80211: Too many CSA counters provided"); | |
1c4ffa87 | 9140 | return -EINVAL; |
366179d2 | 9141 | } |
1c4ffa87 | 9142 | |
366179d2 | 9143 | if (!settings->beacon_csa.tail) |
1c4ffa87 AO |
9144 | return -EINVAL; |
9145 | ||
366179d2 AO |
9146 | for (i = 0; i < csa_off_len; i++) { |
9147 | u16 csa_c_off_bcn = settings->counter_offset_beacon[i]; | |
9148 | u16 csa_c_off_presp = settings->counter_offset_presp[i]; | |
9149 | ||
9150 | if ((settings->beacon_csa.tail_len <= csa_c_off_bcn) || | |
9151 | (settings->beacon_csa.tail[csa_c_off_bcn] != | |
9152 | settings->cs_count)) | |
9153 | return -EINVAL; | |
9154 | ||
9155 | if (settings->beacon_csa.probe_resp && | |
9156 | ((settings->beacon_csa.probe_resp_len <= | |
9157 | csa_c_off_presp) || | |
9158 | (settings->beacon_csa.probe_resp[csa_c_off_presp] != | |
9159 | settings->cs_count))) | |
9160 | return -EINVAL; | |
9161 | } | |
9162 | ||
13f83980 | 9163 | if (!(msg = nl80211_bss_msg(bss, 0, NL80211_CMD_CHANNEL_SWITCH)) || |
a862e4a3 JM |
9164 | nla_put_u32(msg, NL80211_ATTR_CH_SWITCH_COUNT, |
9165 | settings->cs_count) || | |
9166 | (ret = nl80211_put_freq_params(msg, &settings->freq_params)) || | |
9167 | (settings->block_tx && | |
9168 | nla_put_flag(msg, NL80211_ATTR_CH_SWITCH_BLOCK_TX))) | |
1c4ffa87 AO |
9169 | goto error; |
9170 | ||
1c4ffa87 AO |
9171 | /* beacon_after params */ |
9172 | ret = set_beacon_data(msg, &settings->beacon_after); | |
9173 | if (ret) | |
9174 | goto error; | |
9175 | ||
9176 | /* beacon_csa params */ | |
9177 | beacon_csa = nla_nest_start(msg, NL80211_ATTR_CSA_IES); | |
9178 | if (!beacon_csa) | |
a862e4a3 | 9179 | goto fail; |
1c4ffa87 AO |
9180 | |
9181 | ret = set_beacon_data(msg, &settings->beacon_csa); | |
9182 | if (ret) | |
9183 | goto error; | |
9184 | ||
366179d2 AO |
9185 | if (nla_put(msg, NL80211_ATTR_CSA_C_OFF_BEACON, |
9186 | csa_off_len * sizeof(u16), | |
9187 | settings->counter_offset_beacon) || | |
a862e4a3 | 9188 | (settings->beacon_csa.probe_resp && |
366179d2 AO |
9189 | nla_put(msg, NL80211_ATTR_CSA_C_OFF_PRESP, |
9190 | csa_off_len * sizeof(u16), | |
9191 | settings->counter_offset_presp))) | |
a862e4a3 | 9192 | goto fail; |
1c4ffa87 AO |
9193 | |
9194 | nla_nest_end(msg, beacon_csa); | |
9195 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); | |
9196 | if (ret) { | |
9197 | wpa_printf(MSG_DEBUG, "nl80211: switch_channel failed err=%d (%s)", | |
9198 | ret, strerror(-ret)); | |
9199 | } | |
9200 | return ret; | |
9201 | ||
a862e4a3 | 9202 | fail: |
1c4ffa87 AO |
9203 | ret = -ENOBUFS; |
9204 | error: | |
9205 | nlmsg_free(msg); | |
9206 | wpa_printf(MSG_DEBUG, "nl80211: Could not build channel switch request"); | |
9207 | return ret; | |
9208 | } | |
9209 | ||
9210 | ||
dfa87878 MB |
9211 | static int nl80211_add_ts(void *priv, u8 tsid, const u8 *addr, |
9212 | u8 user_priority, u16 admitted_time) | |
9213 | { | |
9214 | struct i802_bss *bss = priv; | |
9215 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
9216 | struct nl_msg *msg; | |
9217 | int ret; | |
9218 | ||
9219 | wpa_printf(MSG_DEBUG, | |
9220 | "nl80211: add_ts request: tsid=%u admitted_time=%u up=%d", | |
9221 | tsid, admitted_time, user_priority); | |
9222 | ||
9223 | if (!is_sta_interface(drv->nlmode)) | |
9224 | return -ENOTSUP; | |
9225 | ||
56f77852 JM |
9226 | msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_ADD_TX_TS); |
9227 | if (!msg || | |
a862e4a3 JM |
9228 | nla_put_u8(msg, NL80211_ATTR_TSID, tsid) || |
9229 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) || | |
9230 | nla_put_u8(msg, NL80211_ATTR_USER_PRIO, user_priority) || | |
9231 | nla_put_u16(msg, NL80211_ATTR_ADMITTED_TIME, admitted_time)) { | |
9232 | nlmsg_free(msg); | |
9233 | return -ENOBUFS; | |
9234 | } | |
dfa87878 MB |
9235 | |
9236 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); | |
9237 | if (ret) | |
9238 | wpa_printf(MSG_DEBUG, "nl80211: add_ts failed err=%d (%s)", | |
9239 | ret, strerror(-ret)); | |
9240 | return ret; | |
dfa87878 MB |
9241 | } |
9242 | ||
9243 | ||
9244 | static int nl80211_del_ts(void *priv, u8 tsid, const u8 *addr) | |
9245 | { | |
9246 | struct i802_bss *bss = priv; | |
9247 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
9248 | struct nl_msg *msg; | |
9249 | int ret; | |
9250 | ||
9251 | wpa_printf(MSG_DEBUG, "nl80211: del_ts request: tsid=%u", tsid); | |
9252 | ||
9253 | if (!is_sta_interface(drv->nlmode)) | |
9254 | return -ENOTSUP; | |
9255 | ||
56f77852 | 9256 | if (!(msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_DEL_TX_TS)) || |
a862e4a3 JM |
9257 | nla_put_u8(msg, NL80211_ATTR_TSID, tsid) || |
9258 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) { | |
9259 | nlmsg_free(msg); | |
9260 | return -ENOBUFS; | |
9261 | } | |
dfa87878 MB |
9262 | |
9263 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); | |
9264 | if (ret) | |
9265 | wpa_printf(MSG_DEBUG, "nl80211: del_ts failed err=%d (%s)", | |
9266 | ret, strerror(-ret)); | |
9267 | return ret; | |
dfa87878 MB |
9268 | } |
9269 | ||
9270 | ||
6b9f7af6 JM |
9271 | #ifdef CONFIG_TESTING_OPTIONS |
9272 | static int cmd_reply_handler(struct nl_msg *msg, void *arg) | |
9273 | { | |
9274 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); | |
9275 | struct wpabuf *buf = arg; | |
9276 | ||
9277 | if (!buf) | |
9278 | return NL_SKIP; | |
9279 | ||
9280 | if ((size_t) genlmsg_attrlen(gnlh, 0) > wpabuf_tailroom(buf)) { | |
9281 | wpa_printf(MSG_INFO, "nl80211: insufficient buffer space for reply"); | |
9282 | return NL_SKIP; | |
9283 | } | |
9284 | ||
9285 | wpabuf_put_data(buf, genlmsg_attrdata(gnlh, 0), | |
9286 | genlmsg_attrlen(gnlh, 0)); | |
9287 | ||
9288 | return NL_SKIP; | |
9289 | } | |
9290 | #endif /* CONFIG_TESTING_OPTIONS */ | |
9291 | ||
9292 | ||
adef8948 BL |
9293 | static int vendor_reply_handler(struct nl_msg *msg, void *arg) |
9294 | { | |
9295 | struct nlattr *tb[NL80211_ATTR_MAX + 1]; | |
9296 | struct nlattr *nl_vendor_reply, *nl; | |
9297 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); | |
9298 | struct wpabuf *buf = arg; | |
9299 | int rem; | |
9300 | ||
9301 | if (!buf) | |
9302 | return NL_SKIP; | |
9303 | ||
9304 | nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), | |
9305 | genlmsg_attrlen(gnlh, 0), NULL); | |
9306 | nl_vendor_reply = tb[NL80211_ATTR_VENDOR_DATA]; | |
9307 | ||
9308 | if (!nl_vendor_reply) | |
9309 | return NL_SKIP; | |
9310 | ||
9311 | if ((size_t) nla_len(nl_vendor_reply) > wpabuf_tailroom(buf)) { | |
9312 | wpa_printf(MSG_INFO, "nl80211: Vendor command: insufficient buffer space for reply"); | |
9313 | return NL_SKIP; | |
9314 | } | |
9315 | ||
9316 | nla_for_each_nested(nl, nl_vendor_reply, rem) { | |
9317 | wpabuf_put_data(buf, nla_data(nl), nla_len(nl)); | |
9318 | } | |
9319 | ||
9320 | return NL_SKIP; | |
9321 | } | |
9322 | ||
9323 | ||
9324 | static int nl80211_vendor_cmd(void *priv, unsigned int vendor_id, | |
9325 | unsigned int subcmd, const u8 *data, | |
9326 | size_t data_len, struct wpabuf *buf) | |
9327 | { | |
9328 | struct i802_bss *bss = priv; | |
9329 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
9330 | struct nl_msg *msg; | |
9331 | int ret; | |
9332 | ||
6b9f7af6 JM |
9333 | #ifdef CONFIG_TESTING_OPTIONS |
9334 | if (vendor_id == 0xffffffff) { | |
56f77852 JM |
9335 | msg = nlmsg_alloc(); |
9336 | if (!msg) | |
9337 | return -ENOMEM; | |
9338 | ||
6b9f7af6 JM |
9339 | nl80211_cmd(drv, msg, 0, subcmd); |
9340 | if (nlmsg_append(msg, (void *) data, data_len, NLMSG_ALIGNTO) < | |
9341 | 0) | |
a862e4a3 | 9342 | goto fail; |
6b9f7af6 JM |
9343 | ret = send_and_recv_msgs(drv, msg, cmd_reply_handler, buf); |
9344 | if (ret) | |
9345 | wpa_printf(MSG_DEBUG, "nl80211: command failed err=%d", | |
9346 | ret); | |
9347 | return ret; | |
9348 | } | |
9349 | #endif /* CONFIG_TESTING_OPTIONS */ | |
9350 | ||
56f77852 | 9351 | if (!(msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_VENDOR)) || |
a862e4a3 JM |
9352 | nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, vendor_id) || |
9353 | nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD, subcmd) || | |
9354 | (data && | |
9355 | nla_put(msg, NL80211_ATTR_VENDOR_DATA, data_len, data))) | |
9356 | goto fail; | |
adef8948 BL |
9357 | |
9358 | ret = send_and_recv_msgs(drv, msg, vendor_reply_handler, buf); | |
9359 | if (ret) | |
9360 | wpa_printf(MSG_DEBUG, "nl80211: vendor command failed err=%d", | |
9361 | ret); | |
9362 | return ret; | |
9363 | ||
a862e4a3 | 9364 | fail: |
adef8948 BL |
9365 | nlmsg_free(msg); |
9366 | return -ENOBUFS; | |
9367 | } | |
9368 | ||
9369 | ||
049105b4 KP |
9370 | static int nl80211_set_qos_map(void *priv, const u8 *qos_map_set, |
9371 | u8 qos_map_set_len) | |
9372 | { | |
9373 | struct i802_bss *bss = priv; | |
9374 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
9375 | struct nl_msg *msg; | |
9376 | int ret; | |
9377 | ||
049105b4 KP |
9378 | wpa_hexdump(MSG_DEBUG, "nl80211: Setting QoS Map", |
9379 | qos_map_set, qos_map_set_len); | |
9380 | ||
9725b784 | 9381 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_SET_QOS_MAP)) || |
a862e4a3 JM |
9382 | nla_put(msg, NL80211_ATTR_QOS_MAP, qos_map_set_len, qos_map_set)) { |
9383 | nlmsg_free(msg); | |
9384 | return -ENOBUFS; | |
9385 | } | |
049105b4 KP |
9386 | |
9387 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); | |
9388 | if (ret) | |
9389 | wpa_printf(MSG_DEBUG, "nl80211: Setting QoS Map failed"); | |
9390 | ||
9391 | return ret; | |
049105b4 KP |
9392 | } |
9393 | ||
9394 | ||
e4fa8b12 EP |
9395 | static int nl80211_set_wowlan(void *priv, |
9396 | const struct wowlan_triggers *triggers) | |
9397 | { | |
9398 | struct i802_bss *bss = priv; | |
9399 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
9400 | struct nl_msg *msg; | |
9401 | struct nlattr *wowlan_triggers; | |
9402 | int ret; | |
9403 | ||
e4fa8b12 EP |
9404 | wpa_printf(MSG_DEBUG, "nl80211: Setting wowlan"); |
9405 | ||
1ac977bd | 9406 | if (!(msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_SET_WOWLAN)) || |
a862e4a3 JM |
9407 | !(wowlan_triggers = nla_nest_start(msg, |
9408 | NL80211_ATTR_WOWLAN_TRIGGERS)) || | |
9409 | (triggers->any && | |
9410 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_ANY)) || | |
9411 | (triggers->disconnect && | |
9412 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) || | |
9413 | (triggers->magic_pkt && | |
9414 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) || | |
9415 | (triggers->gtk_rekey_failure && | |
9416 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) || | |
9417 | (triggers->eap_identity_req && | |
9418 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) || | |
9419 | (triggers->four_way_handshake && | |
9420 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) || | |
9421 | (triggers->rfkill_release && | |
9422 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE))) { | |
9423 | nlmsg_free(msg); | |
9424 | return -ENOBUFS; | |
9425 | } | |
e4fa8b12 EP |
9426 | |
9427 | nla_nest_end(msg, wowlan_triggers); | |
9428 | ||
9429 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); | |
9430 | if (ret) | |
9431 | wpa_printf(MSG_DEBUG, "nl80211: Setting wowlan failed"); | |
9432 | ||
9433 | return ret; | |
e4fa8b12 EP |
9434 | } |
9435 | ||
9436 | ||
b658547d | 9437 | #ifdef CONFIG_DRIVER_NL80211_QCA |
0800f9ee JM |
9438 | static int nl80211_roaming(void *priv, int allowed, const u8 *bssid) |
9439 | { | |
9440 | struct i802_bss *bss = priv; | |
9441 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
9442 | struct nl_msg *msg; | |
9443 | struct nlattr *params; | |
9444 | ||
9445 | wpa_printf(MSG_DEBUG, "nl80211: Roaming policy: allowed=%d", allowed); | |
9446 | ||
9447 | if (!drv->roaming_vendor_cmd_avail) { | |
9448 | wpa_printf(MSG_DEBUG, | |
9449 | "nl80211: Ignore roaming policy change since driver does not provide command for setting it"); | |
9450 | return -1; | |
9451 | } | |
9452 | ||
9725b784 | 9453 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_VENDOR)) || |
a862e4a3 JM |
9454 | nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) || |
9455 | nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD, | |
9456 | QCA_NL80211_VENDOR_SUBCMD_ROAMING) || | |
9457 | !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) || | |
9458 | nla_put_u32(msg, QCA_WLAN_VENDOR_ATTR_ROAMING_POLICY, | |
9459 | allowed ? QCA_ROAMING_ALLOWED_WITHIN_ESS : | |
9460 | QCA_ROAMING_NOT_ALLOWED) || | |
9461 | (bssid && | |
9462 | nla_put(msg, QCA_WLAN_VENDOR_ATTR_MAC_ADDR, ETH_ALEN, bssid))) { | |
9463 | nlmsg_free(msg); | |
9464 | return -1; | |
9465 | } | |
0800f9ee JM |
9466 | nla_nest_end(msg, params); |
9467 | ||
9468 | return send_and_recv_msgs(drv, msg, NULL, NULL); | |
0800f9ee | 9469 | } |
b04854ce AP |
9470 | |
9471 | ||
d98038bb | 9472 | static int nl80211_disable_fils(void *priv, int disable) |
9473 | { | |
9474 | struct i802_bss *bss = priv; | |
9475 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
9476 | struct nl_msg *msg; | |
9477 | struct nlattr *params; | |
9478 | ||
9479 | wpa_printf(MSG_DEBUG, "nl80211: Disable FILS=%d", disable); | |
9480 | ||
9481 | if (!drv->set_wifi_conf_vendor_cmd_avail) | |
9482 | return -1; | |
9483 | ||
9484 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_VENDOR)) || | |
9485 | nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) || | |
9486 | nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD, | |
9487 | QCA_NL80211_VENDOR_SUBCMD_SET_WIFI_CONFIGURATION) || | |
9488 | !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) || | |
9489 | nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_CONFIG_DISABLE_FILS, | |
9490 | disable)) { | |
9491 | nlmsg_free(msg); | |
9492 | return -1; | |
9493 | } | |
9494 | nla_nest_end(msg, params); | |
9495 | ||
9496 | return send_and_recv_msgs(drv, msg, NULL, NULL); | |
9497 | } | |
9498 | ||
9499 | ||
b04854ce AP |
9500 | /* Reserved QCA_WLAN_VENDOR_ATTR_ROAMING_REQ_ID value for wpa_supplicant */ |
9501 | #define WPA_SUPPLICANT_CLIENT_ID 1 | |
9502 | ||
9503 | static int nl80211_set_bssid_blacklist(void *priv, unsigned int num_bssid, | |
9504 | const u8 *bssid) | |
9505 | { | |
9506 | struct i802_bss *bss = priv; | |
9507 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
9508 | struct nl_msg *msg; | |
9509 | struct nlattr *params, *nlbssids, *attr; | |
9510 | unsigned int i; | |
9511 | ||
9512 | wpa_printf(MSG_DEBUG, "nl80211: Set blacklist BSSID (num=%u)", | |
9513 | num_bssid); | |
9514 | ||
9515 | if (!drv->roam_vendor_cmd_avail) | |
9516 | return -1; | |
9517 | ||
9518 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_VENDOR)) || | |
9519 | nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) || | |
9520 | nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD, | |
9521 | QCA_NL80211_VENDOR_SUBCMD_ROAM) || | |
9522 | !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) || | |
9523 | nla_put_u32(msg, QCA_WLAN_VENDOR_ATTR_ROAMING_SUBCMD, | |
1425caac | 9524 | QCA_WLAN_VENDOR_ROAMING_SUBCMD_SET_BLACKLIST_BSSID) || |
b04854ce AP |
9525 | nla_put_u32(msg, QCA_WLAN_VENDOR_ATTR_ROAMING_REQ_ID, |
9526 | WPA_SUPPLICANT_CLIENT_ID) || | |
9527 | nla_put_u32(msg, | |
9528 | QCA_WLAN_VENDOR_ATTR_ROAMING_PARAM_SET_BSSID_PARAMS_NUM_BSSID, | |
9529 | num_bssid)) | |
9530 | goto fail; | |
9531 | ||
9532 | nlbssids = nla_nest_start( | |
9533 | msg, QCA_WLAN_VENDOR_ATTR_ROAMING_PARAM_SET_BSSID_PARAMS); | |
9534 | if (!nlbssids) | |
9535 | goto fail; | |
9536 | ||
9537 | for (i = 0; i < num_bssid; i++) { | |
9538 | attr = nla_nest_start(msg, i); | |
9539 | if (!attr) | |
9540 | goto fail; | |
9541 | if (nla_put(msg, | |
9542 | QCA_WLAN_VENDOR_ATTR_ROAMING_PARAM_SET_BSSID_PARAMS_BSSID, | |
9543 | ETH_ALEN, &bssid[i * ETH_ALEN])) | |
9544 | goto fail; | |
9545 | wpa_printf(MSG_DEBUG, "nl80211: BSSID[%u]: " MACSTR, i, | |
9546 | MAC2STR(&bssid[i * ETH_ALEN])); | |
9547 | nla_nest_end(msg, attr); | |
9548 | } | |
9549 | nla_nest_end(msg, nlbssids); | |
9550 | nla_nest_end(msg, params); | |
9551 | ||
9552 | return send_and_recv_msgs(drv, msg, NULL, NULL); | |
9553 | ||
9554 | fail: | |
9555 | nlmsg_free(msg); | |
9556 | return -1; | |
9557 | } | |
9558 | ||
b658547d | 9559 | #endif /* CONFIG_DRIVER_NL80211_QCA */ |
0800f9ee JM |
9560 | |
9561 | ||
fee354c7 JM |
9562 | static int nl80211_set_mac_addr(void *priv, const u8 *addr) |
9563 | { | |
9564 | struct i802_bss *bss = priv; | |
9565 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
9566 | int new_addr = addr != NULL; | |
9567 | ||
9ce3e610 JM |
9568 | if (TEST_FAIL()) |
9569 | return -1; | |
9570 | ||
fee354c7 JM |
9571 | if (!addr) |
9572 | addr = drv->perm_addr; | |
9573 | ||
9574 | if (linux_set_iface_flags(drv->global->ioctl_sock, bss->ifname, 0) < 0) | |
9575 | return -1; | |
9576 | ||
9577 | if (linux_set_ifhwaddr(drv->global->ioctl_sock, bss->ifname, addr) < 0) | |
9578 | { | |
9579 | wpa_printf(MSG_DEBUG, | |
9580 | "nl80211: failed to set_mac_addr for %s to " MACSTR, | |
9581 | bss->ifname, MAC2STR(addr)); | |
9582 | if (linux_set_iface_flags(drv->global->ioctl_sock, bss->ifname, | |
9583 | 1) < 0) { | |
9584 | wpa_printf(MSG_DEBUG, | |
9585 | "nl80211: Could not restore interface UP after failed set_mac_addr"); | |
9586 | } | |
9587 | return -1; | |
9588 | } | |
9589 | ||
9590 | wpa_printf(MSG_DEBUG, "nl80211: set_mac_addr for %s to " MACSTR, | |
9591 | bss->ifname, MAC2STR(addr)); | |
9592 | drv->addr_changed = new_addr; | |
9593 | os_memcpy(bss->addr, addr, ETH_ALEN); | |
9594 | ||
9595 | if (linux_set_iface_flags(drv->global->ioctl_sock, bss->ifname, 1) < 0) | |
9596 | { | |
9597 | wpa_printf(MSG_DEBUG, | |
9598 | "nl80211: Could not restore interface UP after set_mac_addr"); | |
9599 | } | |
9600 | ||
9601 | return 0; | |
9602 | } | |
9603 | ||
9604 | ||
6c1664f6 BC |
9605 | #ifdef CONFIG_MESH |
9606 | ||
9607 | static int wpa_driver_nl80211_init_mesh(void *priv) | |
9608 | { | |
9609 | if (wpa_driver_nl80211_set_mode(priv, NL80211_IFTYPE_MESH_POINT)) { | |
9610 | wpa_printf(MSG_INFO, | |
9611 | "nl80211: Failed to set interface into mesh mode"); | |
9612 | return -1; | |
9613 | } | |
9614 | return 0; | |
9615 | } | |
9616 | ||
9617 | ||
21c74e84 JM |
9618 | static int nl80211_put_mesh_id(struct nl_msg *msg, const u8 *mesh_id, |
9619 | size_t mesh_id_len) | |
9620 | { | |
9621 | if (mesh_id) { | |
21cd8f83 JM |
9622 | wpa_printf(MSG_DEBUG, " * Mesh ID (SSID)=%s", |
9623 | wpa_ssid_txt(mesh_id, mesh_id_len)); | |
21c74e84 JM |
9624 | return nla_put(msg, NL80211_ATTR_MESH_ID, mesh_id_len, mesh_id); |
9625 | } | |
9626 | ||
9627 | return 0; | |
9628 | } | |
9629 | ||
9630 | ||
4ffb3f87 MH |
9631 | static int nl80211_put_mesh_config(struct nl_msg *msg, |
9632 | struct wpa_driver_mesh_bss_params *params) | |
9633 | { | |
9634 | struct nlattr *container; | |
9635 | ||
9636 | container = nla_nest_start(msg, NL80211_ATTR_MESH_CONFIG); | |
9637 | if (!container) | |
9638 | return -1; | |
9639 | ||
2bd62171 | 9640 | if (((params->flags & WPA_DRIVER_MESH_CONF_FLAG_AUTO_PLINKS) && |
963d3149 JM |
9641 | nla_put_u8(msg, NL80211_MESHCONF_AUTO_OPEN_PLINKS, |
9642 | params->auto_plinks)) || | |
2bd62171 MH |
9643 | ((params->flags & WPA_DRIVER_MESH_CONF_FLAG_MAX_PEER_LINKS) && |
9644 | nla_put_u16(msg, NL80211_MESHCONF_MAX_PEER_LINKS, | |
31a856a1 MH |
9645 | params->max_peer_links)) || |
9646 | ((params->flags & WPA_DRIVER_MESH_CONF_FLAG_RSSI_THRESHOLD) && | |
9647 | nla_put_u32(msg, NL80211_MESHCONF_RSSI_THRESHOLD, | |
9648 | params->rssi_threshold))) | |
4ffb3f87 MH |
9649 | return -1; |
9650 | ||
9651 | /* | |
9652 | * Set NL80211_MESHCONF_PLINK_TIMEOUT even if user mpm is used because | |
9653 | * the timer could disconnect stations even in that case. | |
9654 | */ | |
2bd62171 MH |
9655 | if ((params->flags & WPA_DRIVER_MESH_CONF_FLAG_PEER_LINK_TIMEOUT) && |
9656 | nla_put_u32(msg, NL80211_MESHCONF_PLINK_TIMEOUT, | |
4ffb3f87 MH |
9657 | params->peer_link_timeout)) { |
9658 | wpa_printf(MSG_ERROR, "nl80211: Failed to set PLINK_TIMEOUT"); | |
9659 | return -1; | |
9660 | } | |
9661 | ||
052b8d38 MH |
9662 | if ((params->flags & WPA_DRIVER_MESH_CONF_FLAG_HT_OP_MODE) && |
9663 | nla_put_u16(msg, NL80211_MESHCONF_HT_OPMODE, params->ht_opmode)) { | |
9664 | wpa_printf(MSG_ERROR, "nl80211: Failed to set HT_OP_MODE"); | |
9665 | return -1; | |
9666 | } | |
9667 | ||
4ffb3f87 MH |
9668 | nla_nest_end(msg, container); |
9669 | ||
9670 | return 0; | |
9671 | } | |
9672 | ||
9673 | ||
0cb5f8d9 | 9674 | static int nl80211_join_mesh(struct i802_bss *bss, |
6c1664f6 BC |
9675 | struct wpa_driver_mesh_join_params *params) |
9676 | { | |
6c1664f6 BC |
9677 | struct wpa_driver_nl80211_data *drv = bss->drv; |
9678 | struct nl_msg *msg; | |
9679 | struct nlattr *container; | |
7451a217 | 9680 | int ret = -1; |
6c1664f6 | 9681 | |
6c1664f6 | 9682 | wpa_printf(MSG_DEBUG, "nl80211: mesh join (ifindex=%d)", drv->ifindex); |
9725b784 | 9683 | msg = nl80211_drv_msg(drv, 0, NL80211_CMD_JOIN_MESH); |
f7e889fa JM |
9684 | if (!msg || |
9685 | nl80211_put_freq_params(msg, ¶ms->freq) || | |
21c74e84 JM |
9686 | nl80211_put_basic_rates(msg, params->basic_rates) || |
9687 | nl80211_put_mesh_id(msg, params->meshid, params->meshid_len) || | |
4ac2ea57 MH |
9688 | nl80211_put_beacon_int(msg, params->beacon_int) || |
9689 | nl80211_put_dtim_period(msg, params->dtim_period)) | |
85e1fad8 | 9690 | goto fail; |
9c58c5f7 | 9691 | |
6c1664f6 BC |
9692 | wpa_printf(MSG_DEBUG, " * flags=%08X", params->flags); |
9693 | ||
9694 | container = nla_nest_start(msg, NL80211_ATTR_MESH_SETUP); | |
9695 | if (!container) | |
a862e4a3 | 9696 | goto fail; |
6c1664f6 BC |
9697 | |
9698 | if (params->ies) { | |
9699 | wpa_hexdump(MSG_DEBUG, " * IEs", params->ies, params->ie_len); | |
a862e4a3 JM |
9700 | if (nla_put(msg, NL80211_MESH_SETUP_IE, params->ie_len, |
9701 | params->ies)) | |
9702 | goto fail; | |
6c1664f6 BC |
9703 | } |
9704 | /* WPA_DRIVER_MESH_FLAG_OPEN_AUTH is treated as default by nl80211 */ | |
9705 | if (params->flags & WPA_DRIVER_MESH_FLAG_SAE_AUTH) { | |
a862e4a3 JM |
9706 | if (nla_put_u8(msg, NL80211_MESH_SETUP_AUTH_PROTOCOL, 0x1) || |
9707 | nla_put_flag(msg, NL80211_MESH_SETUP_USERSPACE_AUTH)) | |
9708 | goto fail; | |
6c1664f6 | 9709 | } |
a862e4a3 JM |
9710 | if ((params->flags & WPA_DRIVER_MESH_FLAG_AMPE) && |
9711 | nla_put_flag(msg, NL80211_MESH_SETUP_USERSPACE_AMPE)) | |
9712 | goto fail; | |
9713 | if ((params->flags & WPA_DRIVER_MESH_FLAG_USER_MPM) && | |
9714 | nla_put_flag(msg, NL80211_MESH_SETUP_USERSPACE_MPM)) | |
9715 | goto fail; | |
6c1664f6 BC |
9716 | nla_nest_end(msg, container); |
9717 | ||
2bd62171 MH |
9718 | params->conf.flags |= WPA_DRIVER_MESH_CONF_FLAG_AUTO_PLINKS; |
9719 | params->conf.flags |= WPA_DRIVER_MESH_CONF_FLAG_PEER_LINK_TIMEOUT; | |
9720 | params->conf.flags |= WPA_DRIVER_MESH_CONF_FLAG_MAX_PEER_LINKS; | |
4ffb3f87 | 9721 | if (nl80211_put_mesh_config(msg, ¶ms->conf) < 0) |
5a2a6de6 | 9722 | goto fail; |
6c1664f6 BC |
9723 | |
9724 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); | |
9725 | msg = NULL; | |
9726 | if (ret) { | |
9727 | wpa_printf(MSG_DEBUG, "nl80211: mesh join failed: ret=%d (%s)", | |
9728 | ret, strerror(-ret)); | |
a862e4a3 | 9729 | goto fail; |
6c1664f6 BC |
9730 | } |
9731 | ret = 0; | |
92a515b8 | 9732 | drv->assoc_freq = bss->freq = params->freq.freq; |
6c1664f6 BC |
9733 | wpa_printf(MSG_DEBUG, "nl80211: mesh join request send successfully"); |
9734 | ||
a862e4a3 | 9735 | fail: |
6c1664f6 BC |
9736 | nlmsg_free(msg); |
9737 | return ret; | |
9738 | } | |
9739 | ||
9740 | ||
0cb5f8d9 MH |
9741 | static int |
9742 | wpa_driver_nl80211_join_mesh(void *priv, | |
9743 | struct wpa_driver_mesh_join_params *params) | |
9744 | { | |
9745 | struct i802_bss *bss = priv; | |
9746 | int ret, timeout; | |
9747 | ||
9748 | timeout = params->conf.peer_link_timeout; | |
9749 | ||
9750 | /* Disable kernel inactivity timer */ | |
9751 | if (params->flags & WPA_DRIVER_MESH_FLAG_USER_MPM) | |
9752 | params->conf.peer_link_timeout = 0; | |
9753 | ||
9754 | ret = nl80211_join_mesh(bss, params); | |
9755 | if (ret == -EINVAL && params->conf.peer_link_timeout == 0) { | |
9756 | wpa_printf(MSG_DEBUG, | |
9757 | "nl80211: Mesh join retry for peer_link_timeout"); | |
9758 | /* | |
9759 | * Old kernel does not support setting | |
9760 | * NL80211_MESHCONF_PLINK_TIMEOUT to zero, so set 60 seconds | |
9761 | * into future from peer_link_timeout. | |
9762 | */ | |
9763 | params->conf.peer_link_timeout = timeout + 60; | |
9764 | ret = nl80211_join_mesh(priv, params); | |
9765 | } | |
9766 | ||
9767 | params->conf.peer_link_timeout = timeout; | |
9768 | return ret; | |
9769 | } | |
9770 | ||
9771 | ||
6c1664f6 BC |
9772 | static int wpa_driver_nl80211_leave_mesh(void *priv) |
9773 | { | |
9774 | struct i802_bss *bss = priv; | |
9775 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
9776 | struct nl_msg *msg; | |
9725b784 | 9777 | int ret; |
6c1664f6 BC |
9778 | |
9779 | wpa_printf(MSG_DEBUG, "nl80211: mesh leave (ifindex=%d)", drv->ifindex); | |
9725b784 | 9780 | msg = nl80211_drv_msg(drv, 0, NL80211_CMD_LEAVE_MESH); |
6c1664f6 | 9781 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
6c1664f6 BC |
9782 | if (ret) { |
9783 | wpa_printf(MSG_DEBUG, "nl80211: mesh leave failed: ret=%d (%s)", | |
9784 | ret, strerror(-ret)); | |
a862e4a3 JM |
9785 | } else { |
9786 | wpa_printf(MSG_DEBUG, | |
9787 | "nl80211: mesh leave request send successfully"); | |
6c1664f6 | 9788 | } |
6c1664f6 | 9789 | |
f33c82d2 JM |
9790 | if (wpa_driver_nl80211_set_mode(drv->first_bss, |
9791 | NL80211_IFTYPE_STATION)) { | |
9792 | wpa_printf(MSG_INFO, | |
9793 | "nl80211: Failed to set interface into station mode"); | |
9794 | } | |
6c1664f6 BC |
9795 | return ret; |
9796 | } | |
9797 | ||
c36109e4 PKC |
9798 | |
9799 | static int nl80211_probe_mesh_link(void *priv, const u8 *addr, const u8 *eth, | |
9800 | size_t len) | |
9801 | { | |
9802 | struct i802_bss *bss = priv; | |
9803 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
9804 | struct nl_msg *msg; | |
9805 | int ret; | |
9806 | ||
9807 | msg = nl80211_drv_msg(drv, 0, NL80211_CMD_PROBE_MESH_LINK); | |
9808 | if (!msg || | |
9809 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) || | |
9810 | nla_put(msg, NL80211_ATTR_FRAME, len, eth)) { | |
9811 | nlmsg_free(msg); | |
9812 | return -ENOBUFS; | |
9813 | } | |
9814 | ||
9815 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); | |
9816 | if (ret) { | |
9817 | wpa_printf(MSG_DEBUG, "nl80211: mesh link probe to " MACSTR | |
9818 | " failed: ret=%d (%s)", | |
9819 | MAC2STR(addr), ret, strerror(-ret)); | |
9820 | } else { | |
9821 | wpa_printf(MSG_DEBUG, "nl80211: Mesh link to " MACSTR | |
9822 | " probed successfully", MAC2STR(addr)); | |
9823 | } | |
9824 | ||
9825 | return ret; | |
9826 | } | |
9827 | ||
6c1664f6 BC |
9828 | #endif /* CONFIG_MESH */ |
9829 | ||
9830 | ||
ed4ddb6d KP |
9831 | static int wpa_driver_br_add_ip_neigh(void *priv, u8 version, |
9832 | const u8 *ipaddr, int prefixlen, | |
9833 | const u8 *addr) | |
71103bed KP |
9834 | { |
9835 | #ifdef CONFIG_LIBNL3_ROUTE | |
9836 | struct i802_bss *bss = priv; | |
9837 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
9838 | struct rtnl_neigh *rn; | |
9839 | struct nl_addr *nl_ipaddr = NULL; | |
9840 | struct nl_addr *nl_lladdr = NULL; | |
ed4ddb6d | 9841 | int family, addrsize; |
71103bed KP |
9842 | int res; |
9843 | ||
ed4ddb6d | 9844 | if (!ipaddr || prefixlen == 0 || !addr) |
71103bed KP |
9845 | return -EINVAL; |
9846 | ||
9847 | if (bss->br_ifindex == 0) { | |
9848 | wpa_printf(MSG_DEBUG, | |
9849 | "nl80211: bridge must be set before adding an ip neigh to it"); | |
9850 | return -1; | |
9851 | } | |
9852 | ||
9853 | if (!drv->rtnl_sk) { | |
9854 | wpa_printf(MSG_DEBUG, | |
9855 | "nl80211: nl_sock for NETLINK_ROUTE is not initialized"); | |
9856 | return -1; | |
9857 | } | |
9858 | ||
ed4ddb6d KP |
9859 | if (version == 4) { |
9860 | family = AF_INET; | |
9861 | addrsize = 4; | |
9862 | } else if (version == 6) { | |
9863 | family = AF_INET6; | |
9864 | addrsize = 16; | |
9865 | } else { | |
9866 | return -EINVAL; | |
9867 | } | |
9868 | ||
71103bed KP |
9869 | rn = rtnl_neigh_alloc(); |
9870 | if (rn == NULL) | |
9871 | return -ENOMEM; | |
9872 | ||
9873 | /* set the destination ip address for neigh */ | |
ed4ddb6d | 9874 | nl_ipaddr = nl_addr_build(family, (void *) ipaddr, addrsize); |
71103bed KP |
9875 | if (nl_ipaddr == NULL) { |
9876 | wpa_printf(MSG_DEBUG, "nl80211: nl_ipaddr build failed"); | |
9877 | res = -ENOMEM; | |
9878 | goto errout; | |
9879 | } | |
9880 | nl_addr_set_prefixlen(nl_ipaddr, prefixlen); | |
9881 | res = rtnl_neigh_set_dst(rn, nl_ipaddr); | |
9882 | if (res) { | |
9883 | wpa_printf(MSG_DEBUG, | |
9884 | "nl80211: neigh set destination addr failed"); | |
9885 | goto errout; | |
9886 | } | |
9887 | ||
9888 | /* set the corresponding lladdr for neigh */ | |
9889 | nl_lladdr = nl_addr_build(AF_BRIDGE, (u8 *) addr, ETH_ALEN); | |
9890 | if (nl_lladdr == NULL) { | |
9891 | wpa_printf(MSG_DEBUG, "nl80211: neigh set lladdr failed"); | |
9892 | res = -ENOMEM; | |
9893 | goto errout; | |
9894 | } | |
9895 | rtnl_neigh_set_lladdr(rn, nl_lladdr); | |
9896 | ||
9897 | rtnl_neigh_set_ifindex(rn, bss->br_ifindex); | |
9898 | rtnl_neigh_set_state(rn, NUD_PERMANENT); | |
9899 | ||
9900 | res = rtnl_neigh_add(drv->rtnl_sk, rn, NLM_F_CREATE); | |
9901 | if (res) { | |
9902 | wpa_printf(MSG_DEBUG, | |
9903 | "nl80211: Adding bridge ip neigh failed: %s", | |
9904 | strerror(errno)); | |
9905 | } | |
9906 | errout: | |
9907 | if (nl_lladdr) | |
9908 | nl_addr_put(nl_lladdr); | |
9909 | if (nl_ipaddr) | |
9910 | nl_addr_put(nl_ipaddr); | |
9911 | if (rn) | |
9912 | rtnl_neigh_put(rn); | |
9913 | return res; | |
9914 | #else /* CONFIG_LIBNL3_ROUTE */ | |
9915 | return -1; | |
9916 | #endif /* CONFIG_LIBNL3_ROUTE */ | |
9917 | } | |
9918 | ||
9919 | ||
ed4ddb6d KP |
9920 | static int wpa_driver_br_delete_ip_neigh(void *priv, u8 version, |
9921 | const u8 *ipaddr) | |
71103bed KP |
9922 | { |
9923 | #ifdef CONFIG_LIBNL3_ROUTE | |
9924 | struct i802_bss *bss = priv; | |
9925 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
9926 | struct rtnl_neigh *rn; | |
9927 | struct nl_addr *nl_ipaddr; | |
ed4ddb6d | 9928 | int family, addrsize; |
71103bed KP |
9929 | int res; |
9930 | ||
ed4ddb6d | 9931 | if (!ipaddr) |
71103bed KP |
9932 | return -EINVAL; |
9933 | ||
ed4ddb6d KP |
9934 | if (version == 4) { |
9935 | family = AF_INET; | |
9936 | addrsize = 4; | |
9937 | } else if (version == 6) { | |
9938 | family = AF_INET6; | |
9939 | addrsize = 16; | |
9940 | } else { | |
9941 | return -EINVAL; | |
9942 | } | |
9943 | ||
71103bed KP |
9944 | if (bss->br_ifindex == 0) { |
9945 | wpa_printf(MSG_DEBUG, | |
9946 | "nl80211: bridge must be set to delete an ip neigh"); | |
9947 | return -1; | |
9948 | } | |
9949 | ||
9950 | if (!drv->rtnl_sk) { | |
9951 | wpa_printf(MSG_DEBUG, | |
9952 | "nl80211: nl_sock for NETLINK_ROUTE is not initialized"); | |
9953 | return -1; | |
9954 | } | |
9955 | ||
9956 | rn = rtnl_neigh_alloc(); | |
9957 | if (rn == NULL) | |
9958 | return -ENOMEM; | |
9959 | ||
9960 | /* set the destination ip address for neigh */ | |
ed4ddb6d | 9961 | nl_ipaddr = nl_addr_build(family, (void *) ipaddr, addrsize); |
71103bed KP |
9962 | if (nl_ipaddr == NULL) { |
9963 | wpa_printf(MSG_DEBUG, "nl80211: nl_ipaddr build failed"); | |
9964 | res = -ENOMEM; | |
9965 | goto errout; | |
9966 | } | |
9967 | res = rtnl_neigh_set_dst(rn, nl_ipaddr); | |
9968 | if (res) { | |
9969 | wpa_printf(MSG_DEBUG, | |
9970 | "nl80211: neigh set destination addr failed"); | |
9971 | goto errout; | |
9972 | } | |
9973 | ||
9974 | rtnl_neigh_set_ifindex(rn, bss->br_ifindex); | |
9975 | ||
9976 | res = rtnl_neigh_delete(drv->rtnl_sk, rn, 0); | |
9977 | if (res) { | |
9978 | wpa_printf(MSG_DEBUG, | |
9979 | "nl80211: Deleting bridge ip neigh failed: %s", | |
9980 | strerror(errno)); | |
9981 | } | |
9982 | errout: | |
9983 | if (nl_ipaddr) | |
9984 | nl_addr_put(nl_ipaddr); | |
9985 | if (rn) | |
9986 | rtnl_neigh_put(rn); | |
9987 | return res; | |
9988 | #else /* CONFIG_LIBNL3_ROUTE */ | |
9989 | return -1; | |
9990 | #endif /* CONFIG_LIBNL3_ROUTE */ | |
9991 | } | |
9992 | ||
9993 | ||
73d2294f KP |
9994 | static int linux_write_system_file(const char *path, unsigned int val) |
9995 | { | |
9996 | char buf[50]; | |
9997 | int fd, len; | |
9998 | ||
9999 | len = os_snprintf(buf, sizeof(buf), "%u\n", val); | |
a9aaacbb | 10000 | if (os_snprintf_error(sizeof(buf), len)) |
73d2294f KP |
10001 | return -1; |
10002 | ||
10003 | fd = open(path, O_WRONLY); | |
10004 | if (fd < 0) | |
10005 | return -1; | |
10006 | ||
10007 | if (write(fd, buf, len) < 0) { | |
10008 | wpa_printf(MSG_DEBUG, | |
10009 | "nl80211: Failed to write Linux system file: %s with the value of %d", | |
10010 | path, val); | |
10011 | close(fd); | |
10012 | return -1; | |
10013 | } | |
10014 | close(fd); | |
10015 | ||
10016 | return 0; | |
10017 | } | |
10018 | ||
10019 | ||
10020 | static const char * drv_br_port_attr_str(enum drv_br_port_attr attr) | |
10021 | { | |
10022 | switch (attr) { | |
10023 | case DRV_BR_PORT_ATTR_PROXYARP: | |
bea8d9a3 | 10024 | return "proxyarp_wifi"; |
73d2294f KP |
10025 | case DRV_BR_PORT_ATTR_HAIRPIN_MODE: |
10026 | return "hairpin_mode"; | |
10027 | } | |
10028 | ||
10029 | return NULL; | |
10030 | } | |
10031 | ||
10032 | ||
10033 | static int wpa_driver_br_port_set_attr(void *priv, enum drv_br_port_attr attr, | |
10034 | unsigned int val) | |
10035 | { | |
10036 | struct i802_bss *bss = priv; | |
10037 | char path[128]; | |
10038 | const char *attr_txt; | |
10039 | ||
10040 | attr_txt = drv_br_port_attr_str(attr); | |
10041 | if (attr_txt == NULL) | |
10042 | return -EINVAL; | |
10043 | ||
10044 | os_snprintf(path, sizeof(path), "/sys/class/net/%s/brport/%s", | |
10045 | bss->ifname, attr_txt); | |
10046 | ||
10047 | if (linux_write_system_file(path, val)) | |
10048 | return -1; | |
10049 | ||
10050 | return 0; | |
10051 | } | |
10052 | ||
10053 | ||
7565752d KP |
10054 | static const char * drv_br_net_param_str(enum drv_br_net_param param) |
10055 | { | |
10056 | switch (param) { | |
10057 | case DRV_BR_NET_PARAM_GARP_ACCEPT: | |
10058 | return "arp_accept"; | |
60eb9e17 JM |
10059 | default: |
10060 | return NULL; | |
7565752d | 10061 | } |
7565752d KP |
10062 | } |
10063 | ||
10064 | ||
10065 | static int wpa_driver_br_set_net_param(void *priv, enum drv_br_net_param param, | |
10066 | unsigned int val) | |
10067 | { | |
10068 | struct i802_bss *bss = priv; | |
10069 | char path[128]; | |
10070 | const char *param_txt; | |
10071 | int ip_version = 4; | |
10072 | ||
60eb9e17 JM |
10073 | if (param == DRV_BR_MULTICAST_SNOOPING) { |
10074 | os_snprintf(path, sizeof(path), | |
10075 | "/sys/devices/virtual/net/%s/bridge/multicast_snooping", | |
10076 | bss->brname); | |
10077 | goto set_val; | |
10078 | } | |
10079 | ||
7565752d KP |
10080 | param_txt = drv_br_net_param_str(param); |
10081 | if (param_txt == NULL) | |
10082 | return -EINVAL; | |
10083 | ||
10084 | switch (param) { | |
10085 | case DRV_BR_NET_PARAM_GARP_ACCEPT: | |
10086 | ip_version = 4; | |
10087 | break; | |
10088 | default: | |
10089 | return -EINVAL; | |
10090 | } | |
10091 | ||
10092 | os_snprintf(path, sizeof(path), "/proc/sys/net/ipv%d/conf/%s/%s", | |
10093 | ip_version, bss->brname, param_txt); | |
10094 | ||
60eb9e17 | 10095 | set_val: |
7565752d KP |
10096 | if (linux_write_system_file(path, val)) |
10097 | return -1; | |
10098 | ||
10099 | return 0; | |
10100 | } | |
10101 | ||
10102 | ||
b658547d JM |
10103 | #ifdef CONFIG_DRIVER_NL80211_QCA |
10104 | ||
16689c7c PX |
10105 | static int hw_mode_to_qca_acs(enum hostapd_hw_mode hw_mode) |
10106 | { | |
10107 | switch (hw_mode) { | |
10108 | case HOSTAPD_MODE_IEEE80211B: | |
10109 | return QCA_ACS_MODE_IEEE80211B; | |
10110 | case HOSTAPD_MODE_IEEE80211G: | |
10111 | return QCA_ACS_MODE_IEEE80211G; | |
10112 | case HOSTAPD_MODE_IEEE80211A: | |
10113 | return QCA_ACS_MODE_IEEE80211A; | |
10114 | case HOSTAPD_MODE_IEEE80211AD: | |
10115 | return QCA_ACS_MODE_IEEE80211AD; | |
3784c058 PX |
10116 | case HOSTAPD_MODE_IEEE80211ANY: |
10117 | return QCA_ACS_MODE_IEEE80211ANY; | |
16689c7c PX |
10118 | default: |
10119 | return -1; | |
10120 | } | |
10121 | } | |
10122 | ||
10123 | ||
d0cdccd3 PX |
10124 | static int add_acs_freq_list(struct nl_msg *msg, const int *freq_list) |
10125 | { | |
10126 | int i, len, ret; | |
10127 | u32 *freqs; | |
10128 | ||
10129 | if (!freq_list) | |
10130 | return 0; | |
10131 | len = int_array_len(freq_list); | |
10132 | freqs = os_malloc(sizeof(u32) * len); | |
10133 | if (!freqs) | |
10134 | return -1; | |
10135 | for (i = 0; i < len; i++) | |
10136 | freqs[i] = freq_list[i]; | |
10137 | ret = nla_put(msg, QCA_WLAN_VENDOR_ATTR_ACS_FREQ_LIST, | |
10138 | sizeof(u32) * len, freqs); | |
10139 | os_free(freqs); | |
10140 | return ret; | |
10141 | } | |
10142 | ||
10143 | ||
16689c7c PX |
10144 | static int wpa_driver_do_acs(void *priv, struct drv_acs_params *params) |
10145 | { | |
10146 | struct i802_bss *bss = priv; | |
10147 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
10148 | struct nl_msg *msg; | |
10149 | struct nlattr *data; | |
a862e4a3 | 10150 | int ret; |
16689c7c PX |
10151 | int mode; |
10152 | ||
10153 | mode = hw_mode_to_qca_acs(params->hw_mode); | |
10154 | if (mode < 0) | |
10155 | return -1; | |
10156 | ||
9725b784 | 10157 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_VENDOR)) || |
a862e4a3 JM |
10158 | nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) || |
10159 | nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD, | |
10160 | QCA_NL80211_VENDOR_SUBCMD_DO_ACS) || | |
10161 | !(data = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) || | |
10162 | nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_ACS_HW_MODE, mode) || | |
10163 | (params->ht_enabled && | |
10164 | nla_put_flag(msg, QCA_WLAN_VENDOR_ATTR_ACS_HT_ENABLED)) || | |
10165 | (params->ht40_enabled && | |
857d9422 MM |
10166 | nla_put_flag(msg, QCA_WLAN_VENDOR_ATTR_ACS_HT40_ENABLED)) || |
10167 | (params->vht_enabled && | |
10168 | nla_put_flag(msg, QCA_WLAN_VENDOR_ATTR_ACS_VHT_ENABLED)) || | |
10169 | nla_put_u16(msg, QCA_WLAN_VENDOR_ATTR_ACS_CHWIDTH, | |
10170 | params->ch_width) || | |
10171 | (params->ch_list_len && | |
10172 | nla_put(msg, QCA_WLAN_VENDOR_ATTR_ACS_CH_LIST, params->ch_list_len, | |
d0cdccd3 PX |
10173 | params->ch_list)) || |
10174 | add_acs_freq_list(msg, params->freq_list)) { | |
a862e4a3 JM |
10175 | nlmsg_free(msg); |
10176 | return -ENOBUFS; | |
10177 | } | |
16689c7c PX |
10178 | nla_nest_end(msg, data); |
10179 | ||
857d9422 MM |
10180 | wpa_printf(MSG_DEBUG, |
10181 | "nl80211: ACS Params: HW_MODE: %d HT: %d HT40: %d VHT: %d BW: %d CH_LIST_LEN: %u", | |
10182 | params->hw_mode, params->ht_enabled, params->ht40_enabled, | |
10183 | params->vht_enabled, params->ch_width, params->ch_list_len); | |
10184 | ||
16689c7c | 10185 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
16689c7c PX |
10186 | if (ret) { |
10187 | wpa_printf(MSG_DEBUG, | |
10188 | "nl80211: Failed to invoke driver ACS function: %s", | |
10189 | strerror(errno)); | |
10190 | } | |
16689c7c PX |
10191 | return ret; |
10192 | } | |
10193 | ||
10194 | ||
844dfeb8 SD |
10195 | static int nl80211_set_band(void *priv, enum set_band band) |
10196 | { | |
10197 | struct i802_bss *bss = priv; | |
10198 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
10199 | struct nl_msg *msg; | |
10200 | struct nlattr *data; | |
10201 | int ret; | |
10202 | enum qca_set_band qca_band; | |
10203 | ||
10204 | if (!drv->setband_vendor_cmd_avail) | |
10205 | return -1; | |
10206 | ||
10207 | switch (band) { | |
10208 | case WPA_SETBAND_AUTO: | |
10209 | qca_band = QCA_SETBAND_AUTO; | |
10210 | break; | |
10211 | case WPA_SETBAND_5G: | |
10212 | qca_band = QCA_SETBAND_5G; | |
10213 | break; | |
10214 | case WPA_SETBAND_2G: | |
10215 | qca_band = QCA_SETBAND_2G; | |
10216 | break; | |
10217 | default: | |
10218 | return -1; | |
10219 | } | |
10220 | ||
10221 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_VENDOR)) || | |
10222 | nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) || | |
10223 | nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD, | |
10224 | QCA_NL80211_VENDOR_SUBCMD_SETBAND) || | |
10225 | !(data = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) || | |
10226 | nla_put_u32(msg, QCA_WLAN_VENDOR_ATTR_SETBAND_VALUE, qca_band)) { | |
10227 | nlmsg_free(msg); | |
10228 | return -ENOBUFS; | |
10229 | } | |
10230 | nla_nest_end(msg, data); | |
10231 | ||
10232 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); | |
10233 | if (ret) { | |
10234 | wpa_printf(MSG_DEBUG, | |
10235 | "nl80211: Driver setband function failed: %s", | |
10236 | strerror(errno)); | |
10237 | } | |
10238 | return ret; | |
10239 | } | |
10240 | ||
10241 | ||
98342208 AK |
10242 | struct nl80211_pcl { |
10243 | unsigned int num; | |
10244 | unsigned int *freq_list; | |
10245 | }; | |
10246 | ||
10247 | static int preferred_freq_info_handler(struct nl_msg *msg, void *arg) | |
10248 | { | |
10249 | struct nlattr *tb[NL80211_ATTR_MAX + 1]; | |
10250 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); | |
10251 | struct nl80211_pcl *param = arg; | |
10252 | struct nlattr *nl_vend, *attr; | |
10253 | enum qca_iface_type iface_type; | |
10254 | struct nlattr *tb_vendor[QCA_WLAN_VENDOR_ATTR_MAX + 1]; | |
10255 | unsigned int num, max_num; | |
10256 | u32 *freqs; | |
10257 | ||
10258 | nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), | |
10259 | genlmsg_attrlen(gnlh, 0), NULL); | |
10260 | ||
10261 | nl_vend = tb[NL80211_ATTR_VENDOR_DATA]; | |
10262 | if (!nl_vend) | |
10263 | return NL_SKIP; | |
10264 | ||
10265 | nla_parse(tb_vendor, QCA_WLAN_VENDOR_ATTR_MAX, | |
10266 | nla_data(nl_vend), nla_len(nl_vend), NULL); | |
10267 | ||
10268 | attr = tb_vendor[ | |
10269 | QCA_WLAN_VENDOR_ATTR_GET_PREFERRED_FREQ_LIST_IFACE_TYPE]; | |
10270 | if (!attr) { | |
10271 | wpa_printf(MSG_ERROR, "nl80211: iface_type couldn't be found"); | |
10272 | param->num = 0; | |
10273 | return NL_SKIP; | |
10274 | } | |
10275 | ||
10276 | iface_type = (enum qca_iface_type) nla_get_u32(attr); | |
10277 | wpa_printf(MSG_DEBUG, "nl80211: Driver returned iface_type=%d", | |
10278 | iface_type); | |
10279 | ||
10280 | attr = tb_vendor[QCA_WLAN_VENDOR_ATTR_GET_PREFERRED_FREQ_LIST]; | |
10281 | if (!attr) { | |
10282 | wpa_printf(MSG_ERROR, | |
10283 | "nl80211: preferred_freq_list couldn't be found"); | |
10284 | param->num = 0; | |
10285 | return NL_SKIP; | |
10286 | } | |
10287 | ||
10288 | /* | |
10289 | * param->num has the maximum number of entries for which there | |
10290 | * is room in the freq_list provided by the caller. | |
10291 | */ | |
10292 | freqs = nla_data(attr); | |
10293 | max_num = nla_len(attr) / sizeof(u32); | |
10294 | if (max_num > param->num) | |
10295 | max_num = param->num; | |
10296 | for (num = 0; num < max_num; num++) | |
10297 | param->freq_list[num] = freqs[num]; | |
10298 | param->num = num; | |
10299 | ||
10300 | return NL_SKIP; | |
10301 | } | |
10302 | ||
10303 | ||
10304 | static int nl80211_get_pref_freq_list(void *priv, | |
10305 | enum wpa_driver_if_type if_type, | |
10306 | unsigned int *num, | |
10307 | unsigned int *freq_list) | |
10308 | { | |
10309 | struct i802_bss *bss = priv; | |
10310 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
10311 | struct nl_msg *msg; | |
10312 | int ret; | |
10313 | unsigned int i; | |
10314 | struct nlattr *params; | |
10315 | struct nl80211_pcl param; | |
10316 | enum qca_iface_type iface_type; | |
10317 | ||
10318 | if (!drv->get_pref_freq_list) | |
10319 | return -1; | |
10320 | ||
10321 | switch (if_type) { | |
10322 | case WPA_IF_STATION: | |
10323 | iface_type = QCA_IFACE_TYPE_STA; | |
10324 | break; | |
10325 | case WPA_IF_AP_BSS: | |
10326 | iface_type = QCA_IFACE_TYPE_AP; | |
10327 | break; | |
10328 | case WPA_IF_P2P_GO: | |
10329 | iface_type = QCA_IFACE_TYPE_P2P_GO; | |
10330 | break; | |
10331 | case WPA_IF_P2P_CLIENT: | |
10332 | iface_type = QCA_IFACE_TYPE_P2P_CLIENT; | |
10333 | break; | |
10334 | case WPA_IF_IBSS: | |
10335 | iface_type = QCA_IFACE_TYPE_IBSS; | |
10336 | break; | |
10337 | case WPA_IF_TDLS: | |
10338 | iface_type = QCA_IFACE_TYPE_TDLS; | |
10339 | break; | |
10340 | default: | |
10341 | return -1; | |
10342 | } | |
10343 | ||
10344 | param.num = *num; | |
10345 | param.freq_list = freq_list; | |
10346 | ||
10347 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_VENDOR)) || | |
10348 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, drv->ifindex) || | |
10349 | nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) || | |
10350 | nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD, | |
10351 | QCA_NL80211_VENDOR_SUBCMD_GET_PREFERRED_FREQ_LIST) || | |
10352 | !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) || | |
10353 | nla_put_u32(msg, | |
10354 | QCA_WLAN_VENDOR_ATTR_GET_PREFERRED_FREQ_LIST_IFACE_TYPE, | |
10355 | iface_type)) { | |
10356 | wpa_printf(MSG_ERROR, | |
10357 | "%s: err in adding vendor_cmd and vendor_data", | |
10358 | __func__); | |
10359 | nlmsg_free(msg); | |
10360 | return -1; | |
10361 | } | |
10362 | nla_nest_end(msg, params); | |
10363 | ||
10364 | os_memset(freq_list, 0, *num * sizeof(freq_list[0])); | |
10365 | ret = send_and_recv_msgs(drv, msg, preferred_freq_info_handler, ¶m); | |
10366 | if (ret) { | |
10367 | wpa_printf(MSG_ERROR, | |
10368 | "%s: err in send_and_recv_msgs", __func__); | |
10369 | return ret; | |
10370 | } | |
10371 | ||
10372 | *num = param.num; | |
10373 | ||
10374 | for (i = 0; i < *num; i++) { | |
10375 | wpa_printf(MSG_DEBUG, "nl80211: preferred_channel_list[%d]=%d", | |
10376 | i, freq_list[i]); | |
10377 | } | |
10378 | ||
10379 | return 0; | |
10380 | } | |
10381 | ||
10382 | ||
7c813acf AK |
10383 | static int nl80211_set_prob_oper_freq(void *priv, unsigned int freq) |
10384 | { | |
10385 | struct i802_bss *bss = priv; | |
10386 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
10387 | struct nl_msg *msg; | |
10388 | int ret; | |
10389 | struct nlattr *params; | |
10390 | ||
10391 | if (!drv->set_prob_oper_freq) | |
10392 | return -1; | |
10393 | ||
10394 | wpa_printf(MSG_DEBUG, | |
10395 | "nl80211: Set P2P probable operating freq %u for ifindex %d", | |
10396 | freq, bss->ifindex); | |
10397 | ||
10398 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_VENDOR)) || | |
10399 | nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) || | |
10400 | nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD, | |
10401 | QCA_NL80211_VENDOR_SUBCMD_SET_PROBABLE_OPER_CHANNEL) || | |
10402 | !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) || | |
10403 | nla_put_u32(msg, | |
10404 | QCA_WLAN_VENDOR_ATTR_PROBABLE_OPER_CHANNEL_IFACE_TYPE, | |
10405 | QCA_IFACE_TYPE_P2P_CLIENT) || | |
10406 | nla_put_u32(msg, | |
10407 | QCA_WLAN_VENDOR_ATTR_PROBABLE_OPER_CHANNEL_FREQ, | |
10408 | freq)) { | |
10409 | wpa_printf(MSG_ERROR, | |
10410 | "%s: err in adding vendor_cmd and vendor_data", | |
10411 | __func__); | |
10412 | nlmsg_free(msg); | |
10413 | return -1; | |
10414 | } | |
10415 | nla_nest_end(msg, params); | |
10416 | ||
10417 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); | |
10418 | msg = NULL; | |
10419 | if (ret) { | |
10420 | wpa_printf(MSG_ERROR, "%s: err in send_and_recv_msgs", | |
10421 | __func__); | |
10422 | return ret; | |
10423 | } | |
10424 | nlmsg_free(msg); | |
10425 | return 0; | |
10426 | } | |
10427 | ||
a6f5b193 PX |
10428 | |
10429 | static int nl80211_p2p_lo_start(void *priv, unsigned int freq, | |
10430 | unsigned int period, unsigned int interval, | |
10431 | unsigned int count, const u8 *device_types, | |
10432 | size_t dev_types_len, | |
10433 | const u8 *ies, size_t ies_len) | |
10434 | { | |
10435 | struct i802_bss *bss = priv; | |
10436 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
10437 | struct nl_msg *msg; | |
10438 | struct nlattr *container; | |
10439 | int ret; | |
10440 | ||
10441 | wpa_printf(MSG_DEBUG, | |
10442 | "nl80211: Start P2P Listen offload: freq=%u, period=%u, interval=%u, count=%u", | |
10443 | freq, period, interval, count); | |
10444 | ||
10445 | if (!(drv->capa.flags & WPA_DRIVER_FLAGS_P2P_LISTEN_OFFLOAD)) | |
10446 | return -1; | |
10447 | ||
10448 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_VENDOR)) || | |
10449 | nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) || | |
10450 | nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD, | |
10451 | QCA_NL80211_VENDOR_SUBCMD_P2P_LISTEN_OFFLOAD_START)) | |
10452 | goto fail; | |
10453 | ||
10454 | container = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA); | |
10455 | if (!container) | |
10456 | goto fail; | |
10457 | ||
10458 | if (nla_put_u32(msg, QCA_WLAN_VENDOR_ATTR_P2P_LISTEN_OFFLOAD_CHANNEL, | |
10459 | freq) || | |
10460 | nla_put_u32(msg, QCA_WLAN_VENDOR_ATTR_P2P_LISTEN_OFFLOAD_PERIOD, | |
10461 | period) || | |
10462 | nla_put_u32(msg, QCA_WLAN_VENDOR_ATTR_P2P_LISTEN_OFFLOAD_INTERVAL, | |
10463 | interval) || | |
10464 | nla_put_u32(msg, QCA_WLAN_VENDOR_ATTR_P2P_LISTEN_OFFLOAD_COUNT, | |
10465 | count) || | |
10466 | nla_put(msg, QCA_WLAN_VENDOR_ATTR_P2P_LISTEN_OFFLOAD_DEVICE_TYPES, | |
10467 | dev_types_len, device_types) || | |
10468 | nla_put(msg, QCA_WLAN_VENDOR_ATTR_P2P_LISTEN_OFFLOAD_VENDOR_IE, | |
10469 | ies_len, ies)) | |
10470 | goto fail; | |
10471 | ||
10472 | nla_nest_end(msg, container); | |
10473 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); | |
10474 | msg = NULL; | |
10475 | if (ret) { | |
10476 | wpa_printf(MSG_DEBUG, | |
10477 | "nl80211: Failed to send P2P Listen offload vendor command"); | |
10478 | goto fail; | |
10479 | } | |
10480 | ||
10481 | return 0; | |
10482 | ||
10483 | fail: | |
10484 | nlmsg_free(msg); | |
10485 | return -1; | |
10486 | } | |
10487 | ||
10488 | ||
10489 | static int nl80211_p2p_lo_stop(void *priv) | |
10490 | { | |
10491 | struct i802_bss *bss = priv; | |
10492 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
10493 | struct nl_msg *msg; | |
10494 | ||
10495 | wpa_printf(MSG_DEBUG, "nl80211: Stop P2P Listen offload"); | |
10496 | ||
10497 | if (!(drv->capa.flags & WPA_DRIVER_FLAGS_P2P_LISTEN_OFFLOAD)) | |
10498 | return -1; | |
10499 | ||
10500 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_VENDOR)) || | |
10501 | nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) || | |
10502 | nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD, | |
10503 | QCA_NL80211_VENDOR_SUBCMD_P2P_LISTEN_OFFLOAD_STOP)) { | |
10504 | nlmsg_free(msg); | |
10505 | return -1; | |
10506 | } | |
10507 | ||
10508 | return send_and_recv_msgs(drv, msg, NULL, NULL); | |
10509 | } | |
10510 | ||
2e4e4fb7 SD |
10511 | |
10512 | static int nl80211_set_tdls_mode(void *priv, int tdls_external_control) | |
10513 | { | |
10514 | struct i802_bss *bss = priv; | |
10515 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
10516 | struct nl_msg *msg; | |
10517 | struct nlattr *params; | |
10518 | int ret; | |
10519 | u32 tdls_mode; | |
10520 | ||
10521 | wpa_printf(MSG_DEBUG, | |
10522 | "nl80211: Set TDKS mode: tdls_external_control=%d", | |
10523 | tdls_external_control); | |
10524 | ||
10525 | if (tdls_external_control == 1) | |
10526 | tdls_mode = QCA_WLAN_VENDOR_TDLS_TRIGGER_MODE_IMPLICIT | | |
10527 | QCA_WLAN_VENDOR_TDLS_TRIGGER_MODE_EXTERNAL; | |
10528 | else | |
10529 | tdls_mode = QCA_WLAN_VENDOR_TDLS_TRIGGER_MODE_EXPLICIT; | |
10530 | ||
10531 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_VENDOR)) || | |
10532 | nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) || | |
10533 | nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD, | |
10534 | QCA_NL80211_VENDOR_SUBCMD_CONFIGURE_TDLS)) | |
10535 | goto fail; | |
10536 | ||
10537 | params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA); | |
10538 | if (!params) | |
10539 | goto fail; | |
10540 | ||
10541 | if (nla_put_u32(msg, QCA_WLAN_VENDOR_ATTR_TDLS_CONFIG_TRIGGER_MODE, | |
10542 | tdls_mode)) | |
10543 | goto fail; | |
10544 | ||
10545 | nla_nest_end(msg, params); | |
10546 | ||
10547 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); | |
10548 | msg = NULL; | |
10549 | if (ret) { | |
10550 | wpa_printf(MSG_ERROR, | |
10551 | "nl80211: Set TDLS mode failed: ret=%d (%s)", | |
10552 | ret, strerror(-ret)); | |
10553 | goto fail; | |
10554 | } | |
10555 | return 0; | |
10556 | fail: | |
10557 | nlmsg_free(msg); | |
10558 | return -1; | |
10559 | } | |
10560 | ||
3ab48492 KV |
10561 | |
10562 | #ifdef CONFIG_MBO | |
10563 | ||
10564 | static enum mbo_transition_reject_reason | |
10565 | nl80211_mbo_reject_reason_mapping(enum qca_wlan_btm_candidate_status status) | |
10566 | { | |
10567 | switch (status) { | |
10568 | case QCA_STATUS_REJECT_EXCESSIVE_FRAME_LOSS_EXPECTED: | |
10569 | return MBO_TRANSITION_REJECT_REASON_FRAME_LOSS; | |
10570 | case QCA_STATUS_REJECT_EXCESSIVE_DELAY_EXPECTED: | |
10571 | return MBO_TRANSITION_REJECT_REASON_DELAY; | |
10572 | case QCA_STATUS_REJECT_INSUFFICIENT_QOS_CAPACITY: | |
10573 | return MBO_TRANSITION_REJECT_REASON_QOS_CAPACITY; | |
10574 | case QCA_STATUS_REJECT_LOW_RSSI: | |
10575 | return MBO_TRANSITION_REJECT_REASON_RSSI; | |
10576 | case QCA_STATUS_REJECT_HIGH_INTERFERENCE: | |
10577 | return MBO_TRANSITION_REJECT_REASON_INTERFERENCE; | |
10578 | case QCA_STATUS_REJECT_UNKNOWN: | |
10579 | default: | |
10580 | return MBO_TRANSITION_REJECT_REASON_UNSPECIFIED; | |
10581 | } | |
10582 | } | |
10583 | ||
10584 | ||
10585 | static void nl80211_parse_btm_candidate_info(struct candidate_list *candidate, | |
10586 | struct nlattr *tb[], int num) | |
10587 | { | |
10588 | enum qca_wlan_btm_candidate_status status; | |
10589 | char buf[50]; | |
10590 | ||
10591 | os_memcpy(candidate->bssid, | |
10592 | nla_data(tb[QCA_WLAN_VENDOR_ATTR_BTM_CANDIDATE_INFO_BSSID]), | |
10593 | ETH_ALEN); | |
10594 | ||
10595 | status = nla_get_u32( | |
10596 | tb[QCA_WLAN_VENDOR_ATTR_BTM_CANDIDATE_INFO_STATUS]); | |
10597 | candidate->is_accept = status == QCA_STATUS_ACCEPT; | |
10598 | candidate->reject_reason = nl80211_mbo_reject_reason_mapping(status); | |
10599 | ||
10600 | if (candidate->is_accept) | |
10601 | os_snprintf(buf, sizeof(buf), "Accepted"); | |
10602 | else | |
10603 | os_snprintf(buf, sizeof(buf), | |
10604 | "Rejected, Reject_reason: %d", | |
10605 | candidate->reject_reason); | |
10606 | wpa_printf(MSG_DEBUG, "nl80211: BSSID[%d]: " MACSTR " %s", | |
10607 | num, MAC2STR(candidate->bssid), buf); | |
10608 | } | |
10609 | ||
10610 | ||
10611 | static int | |
10612 | nl80211_get_bss_transition_status_handler(struct nl_msg *msg, void *arg) | |
10613 | { | |
10614 | struct wpa_bss_candidate_info *info = arg; | |
10615 | struct candidate_list *candidate = info->candidates; | |
10616 | struct nlattr *tb_msg[NL80211_ATTR_MAX + 1]; | |
10617 | struct nlattr *tb_vendor[QCA_WLAN_VENDOR_ATTR_MAX + 1]; | |
10618 | struct nlattr *tb[QCA_WLAN_VENDOR_ATTR_BTM_CANDIDATE_INFO_MAX + 1]; | |
10619 | static struct nla_policy policy[ | |
10620 | QCA_WLAN_VENDOR_ATTR_BTM_CANDIDATE_INFO_MAX + 1] = { | |
10621 | [QCA_WLAN_VENDOR_ATTR_BTM_CANDIDATE_INFO_BSSID] = { | |
10622 | .minlen = ETH_ALEN | |
10623 | }, | |
10624 | [QCA_WLAN_VENDOR_ATTR_BTM_CANDIDATE_INFO_STATUS] = { | |
10625 | .type = NLA_U32, | |
10626 | }, | |
10627 | }; | |
10628 | struct nlattr *attr; | |
10629 | int rem; | |
10630 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); | |
10631 | u8 num; | |
10632 | ||
10633 | num = info->num; /* number of candidates sent to driver */ | |
10634 | info->num = 0; | |
10635 | nla_parse(tb_msg, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), | |
10636 | genlmsg_attrlen(gnlh, 0), NULL); | |
10637 | ||
10638 | if (!tb_msg[NL80211_ATTR_VENDOR_DATA] || | |
10639 | nla_parse_nested(tb_vendor, QCA_WLAN_VENDOR_ATTR_MAX, | |
10640 | tb_msg[NL80211_ATTR_VENDOR_DATA], NULL) || | |
10641 | !tb_vendor[QCA_WLAN_VENDOR_ATTR_BTM_CANDIDATE_INFO]) | |
10642 | return NL_SKIP; | |
10643 | ||
10644 | wpa_printf(MSG_DEBUG, | |
10645 | "nl80211: WNM Candidate list received from driver"); | |
10646 | nla_for_each_nested(attr, | |
10647 | tb_vendor[QCA_WLAN_VENDOR_ATTR_BTM_CANDIDATE_INFO], | |
10648 | rem) { | |
10649 | if (info->num >= num || | |
10650 | nla_parse_nested( | |
10651 | tb, QCA_WLAN_VENDOR_ATTR_BTM_CANDIDATE_INFO_MAX, | |
10652 | attr, policy) || | |
10653 | !tb[QCA_WLAN_VENDOR_ATTR_BTM_CANDIDATE_INFO_BSSID] || | |
10654 | !tb[QCA_WLAN_VENDOR_ATTR_BTM_CANDIDATE_INFO_STATUS]) | |
10655 | break; | |
10656 | ||
10657 | nl80211_parse_btm_candidate_info(candidate, tb, info->num); | |
10658 | ||
10659 | candidate++; | |
10660 | info->num++; | |
10661 | } | |
10662 | ||
10663 | return NL_SKIP; | |
10664 | } | |
10665 | ||
10666 | ||
10667 | static struct wpa_bss_candidate_info * | |
10668 | nl80211_get_bss_transition_status(void *priv, struct wpa_bss_trans_info *params) | |
10669 | { | |
10670 | struct i802_bss *bss = priv; | |
10671 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
10672 | struct nl_msg *msg; | |
10673 | struct nlattr *attr, *attr1, *attr2; | |
10674 | struct wpa_bss_candidate_info *info; | |
10675 | u8 i; | |
10676 | int ret; | |
10677 | u8 *pos; | |
10678 | ||
10679 | if (!drv->fetch_bss_trans_status) | |
10680 | return NULL; | |
10681 | ||
10682 | info = os_zalloc(sizeof(*info)); | |
10683 | if (!info) | |
10684 | return NULL; | |
10685 | /* Allocate memory for number of candidates sent to driver */ | |
10686 | info->candidates = os_calloc(params->n_candidates, | |
10687 | sizeof(*info->candidates)); | |
10688 | if (!info->candidates) { | |
10689 | os_free(info); | |
10690 | return NULL; | |
10691 | } | |
10692 | ||
10693 | /* Copy the number of candidates being sent to driver. This is used in | |
10694 | * nl80211_get_bss_transition_status_handler() to limit the number of | |
10695 | * candidates that can be populated in info->candidates and will be | |
10696 | * later overwritten with the actual number of candidates received from | |
10697 | * the driver. | |
10698 | */ | |
10699 | info->num = params->n_candidates; | |
10700 | ||
10701 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_VENDOR)) || | |
10702 | nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) || | |
10703 | nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD, | |
10704 | QCA_NL80211_VENDOR_SUBCMD_FETCH_BSS_TRANSITION_STATUS)) | |
10705 | goto fail; | |
10706 | ||
10707 | attr = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA); | |
10708 | if (!attr) | |
10709 | goto fail; | |
10710 | ||
10711 | if (nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_BTM_MBO_TRANSITION_REASON, | |
10712 | params->mbo_transition_reason)) | |
10713 | goto fail; | |
10714 | ||
10715 | attr1 = nla_nest_start(msg, QCA_WLAN_VENDOR_ATTR_BTM_CANDIDATE_INFO); | |
10716 | if (!attr1) | |
10717 | goto fail; | |
10718 | ||
10719 | wpa_printf(MSG_DEBUG, | |
10720 | "nl80211: WNM Candidate list info sending to driver: mbo_transition_reason: %d n_candidates: %d", | |
10721 | params->mbo_transition_reason, params->n_candidates); | |
10722 | pos = params->bssid; | |
10723 | for (i = 0; i < params->n_candidates; i++) { | |
10724 | wpa_printf(MSG_DEBUG, "nl80211: BSSID[%d]: " MACSTR, i, | |
10725 | MAC2STR(pos)); | |
10726 | attr2 = nla_nest_start(msg, i); | |
10727 | if (!attr2 || | |
10728 | nla_put(msg, QCA_WLAN_VENDOR_ATTR_BTM_CANDIDATE_INFO_BSSID, | |
10729 | ETH_ALEN, pos)) | |
10730 | goto fail; | |
10731 | pos += ETH_ALEN; | |
10732 | nla_nest_end(msg, attr2); | |
10733 | } | |
10734 | ||
10735 | nla_nest_end(msg, attr1); | |
10736 | nla_nest_end(msg, attr); | |
10737 | ||
10738 | ret = send_and_recv_msgs(drv, msg, | |
10739 | nl80211_get_bss_transition_status_handler, | |
10740 | info); | |
10741 | msg = NULL; | |
10742 | if (ret) { | |
10743 | wpa_printf(MSG_ERROR, | |
10744 | "nl80211: WNM Get BSS transition status failed: ret=%d (%s)", | |
10745 | ret, strerror(-ret)); | |
10746 | goto fail; | |
10747 | } | |
10748 | return info; | |
10749 | ||
10750 | fail: | |
10751 | nlmsg_free(msg); | |
10752 | os_free(info->candidates); | |
10753 | os_free(info); | |
10754 | return NULL; | |
10755 | } | |
10756 | ||
178553b7 VK |
10757 | |
10758 | /** | |
10759 | * nl80211_ignore_assoc_disallow - Configure driver to ignore assoc_disallow | |
10760 | * @priv: Pointer to private driver data from wpa_driver_nl80211_init() | |
10761 | * @ignore_assoc_disallow: 0 to not ignore, 1 to ignore | |
10762 | * Returns: 0 on success, -1 on failure | |
10763 | */ | |
10764 | static int nl80211_ignore_assoc_disallow(void *priv, int ignore_disallow) | |
10765 | { | |
10766 | struct i802_bss *bss = priv; | |
10767 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
10768 | struct nl_msg *msg; | |
10769 | struct nlattr *attr; | |
10770 | int ret = -1; | |
10771 | ||
10772 | if (!drv->set_wifi_conf_vendor_cmd_avail) | |
10773 | return -1; | |
10774 | ||
10775 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_VENDOR)) || | |
10776 | nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) || | |
10777 | nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD, | |
10778 | QCA_NL80211_VENDOR_SUBCMD_SET_WIFI_CONFIGURATION)) | |
10779 | goto fail; | |
10780 | ||
10781 | attr = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA); | |
10782 | if (!attr) | |
10783 | goto fail; | |
10784 | ||
10785 | wpa_printf(MSG_DEBUG, "nl80211: Set ignore_assoc_disallow %d", | |
10786 | ignore_disallow); | |
10787 | if (nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_CONFIG_IGNORE_ASSOC_DISALLOWED, | |
10788 | ignore_disallow)) | |
10789 | goto fail; | |
10790 | ||
10791 | nla_nest_end(msg, attr); | |
10792 | ||
10793 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); | |
10794 | msg = NULL; | |
10795 | if (ret) { | |
10796 | wpa_printf(MSG_ERROR, | |
10797 | "nl80211: Set ignore_assoc_disallow failed: ret=%d (%s)", | |
10798 | ret, strerror(-ret)); | |
10799 | goto fail; | |
10800 | } | |
10801 | ||
10802 | fail: | |
10803 | nlmsg_free(msg); | |
10804 | return ret; | |
10805 | } | |
10806 | ||
3ab48492 KV |
10807 | #endif /* CONFIG_MBO */ |
10808 | ||
b658547d JM |
10809 | #endif /* CONFIG_DRIVER_NL80211_QCA */ |
10810 | ||
7c813acf | 10811 | |
6922d440 IP |
10812 | static int nl80211_write_to_file(const char *name, unsigned int val) |
10813 | { | |
10814 | int fd, len; | |
10815 | char tmp[128]; | |
3b726df8 | 10816 | int ret = 0; |
6922d440 IP |
10817 | |
10818 | fd = open(name, O_RDWR); | |
10819 | if (fd < 0) { | |
3b726df8 BN |
10820 | int level; |
10821 | /* | |
10822 | * Flags may not exist on older kernels, or while we're tearing | |
10823 | * down a disappearing device. | |
10824 | */ | |
10825 | if (errno == ENOENT) { | |
10826 | ret = 0; | |
10827 | level = MSG_DEBUG; | |
10828 | } else { | |
10829 | ret = -1; | |
10830 | level = MSG_ERROR; | |
10831 | } | |
10832 | wpa_printf(level, "nl80211: Failed to open %s: %s", | |
6922d440 | 10833 | name, strerror(errno)); |
3b726df8 | 10834 | return ret; |
6922d440 IP |
10835 | } |
10836 | ||
10837 | len = os_snprintf(tmp, sizeof(tmp), "%u\n", val); | |
10838 | len = write(fd, tmp, len); | |
3b726df8 BN |
10839 | if (len < 0) { |
10840 | ret = -1; | |
6922d440 IP |
10841 | wpa_printf(MSG_ERROR, "nl80211: Failed to write to %s: %s", |
10842 | name, strerror(errno)); | |
3b726df8 | 10843 | } |
6922d440 IP |
10844 | close(fd); |
10845 | ||
3b726df8 | 10846 | return ret; |
6922d440 IP |
10847 | } |
10848 | ||
10849 | ||
10850 | static int nl80211_configure_data_frame_filters(void *priv, u32 filter_flags) | |
10851 | { | |
10852 | struct i802_bss *bss = priv; | |
10853 | char path[128]; | |
10854 | int ret; | |
10855 | ||
10856 | wpa_printf(MSG_DEBUG, "nl80211: Data frame filter flags=0x%x", | |
10857 | filter_flags); | |
10858 | ||
10859 | /* Configure filtering of unicast frame encrypted using GTK */ | |
10860 | ret = os_snprintf(path, sizeof(path), | |
10861 | "/proc/sys/net/ipv4/conf/%s/drop_unicast_in_l2_multicast", | |
10862 | bss->ifname); | |
bd86ea08 JM |
10863 | if (os_snprintf_error(sizeof(path), ret)) |
10864 | return -1; | |
6922d440 IP |
10865 | |
10866 | ret = nl80211_write_to_file(path, | |
10867 | !!(filter_flags & | |
10868 | WPA_DATA_FRAME_FILTER_FLAG_GTK)); | |
10869 | if (ret) { | |
10870 | wpa_printf(MSG_ERROR, | |
10871 | "nl80211: Failed to set IPv4 unicast in multicast filter"); | |
10872 | return ret; | |
10873 | } | |
10874 | ||
10875 | os_snprintf(path, sizeof(path), | |
10876 | "/proc/sys/net/ipv6/conf/%s/drop_unicast_in_l2_multicast", | |
10877 | bss->ifname); | |
10878 | ret = nl80211_write_to_file(path, | |
10879 | !!(filter_flags & | |
10880 | WPA_DATA_FRAME_FILTER_FLAG_GTK)); | |
10881 | ||
10882 | if (ret) { | |
10883 | wpa_printf(MSG_ERROR, | |
10884 | "nl80211: Failed to set IPv6 unicast in multicast filter"); | |
10885 | return ret; | |
10886 | } | |
10887 | ||
10888 | /* Configure filtering of unicast frame encrypted using GTK */ | |
10889 | os_snprintf(path, sizeof(path), | |
10890 | "/proc/sys/net/ipv4/conf/%s/drop_gratuitous_arp", | |
10891 | bss->ifname); | |
10892 | ret = nl80211_write_to_file(path, | |
10893 | !!(filter_flags & | |
10894 | WPA_DATA_FRAME_FILTER_FLAG_ARP)); | |
10895 | if (ret) { | |
10896 | wpa_printf(MSG_ERROR, | |
10897 | "nl80211: Failed set gratuitous ARP filter"); | |
10898 | return ret; | |
10899 | } | |
10900 | ||
10901 | /* Configure filtering of IPv6 NA frames */ | |
10902 | os_snprintf(path, sizeof(path), | |
10903 | "/proc/sys/net/ipv6/conf/%s/drop_unsolicited_na", | |
10904 | bss->ifname); | |
10905 | ret = nl80211_write_to_file(path, | |
10906 | !!(filter_flags & | |
10907 | WPA_DATA_FRAME_FILTER_FLAG_NA)); | |
10908 | if (ret) { | |
10909 | wpa_printf(MSG_ERROR, | |
10910 | "nl80211: Failed to set unsolicited NA filter"); | |
10911 | return ret; | |
10912 | } | |
10913 | ||
10914 | return 0; | |
10915 | } | |
10916 | ||
10917 | ||
cc9a2575 KV |
10918 | static int nl80211_get_ext_capab(void *priv, enum wpa_driver_if_type type, |
10919 | const u8 **ext_capa, const u8 **ext_capa_mask, | |
10920 | unsigned int *ext_capa_len) | |
10921 | { | |
10922 | struct i802_bss *bss = priv; | |
10923 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
10924 | enum nl80211_iftype nlmode; | |
10925 | unsigned int i; | |
10926 | ||
10927 | if (!ext_capa || !ext_capa_mask || !ext_capa_len) | |
10928 | return -1; | |
10929 | ||
10930 | nlmode = wpa_driver_nl80211_if_type(type); | |
10931 | ||
10932 | /* By default, use the per-radio values */ | |
10933 | *ext_capa = drv->extended_capa; | |
10934 | *ext_capa_mask = drv->extended_capa_mask; | |
10935 | *ext_capa_len = drv->extended_capa_len; | |
10936 | ||
10937 | /* Replace the default value if a per-interface type value exists */ | |
10938 | for (i = 0; i < drv->num_iface_ext_capa; i++) { | |
10939 | if (nlmode == drv->iface_ext_capa[i].iftype) { | |
10940 | *ext_capa = drv->iface_ext_capa[i].ext_capa; | |
10941 | *ext_capa_mask = drv->iface_ext_capa[i].ext_capa_mask; | |
10942 | *ext_capa_len = drv->iface_ext_capa[i].ext_capa_len; | |
10943 | break; | |
10944 | } | |
10945 | } | |
10946 | ||
10947 | return 0; | |
10948 | } | |
10949 | ||
10950 | ||
3c67e977 VK |
10951 | static int nl80211_update_connection_params( |
10952 | void *priv, struct wpa_driver_associate_params *params, | |
10953 | enum wpa_drv_update_connect_params_mask mask) | |
10954 | { | |
10955 | struct i802_bss *bss = priv; | |
10956 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
10957 | struct nl_msg *msg; | |
10958 | int ret = -1; | |
10959 | enum nl80211_auth_type type; | |
10960 | ||
c574a3ff SD |
10961 | /* Update Connection Params is intended for drivers that implement |
10962 | * internal SME and expect these updated connection params from | |
10963 | * wpa_supplicant. Do not send this request for the drivers using | |
10964 | * SME from wpa_supplicant. | |
10965 | */ | |
10966 | if (drv->capa.flags & WPA_DRIVER_FLAGS_SME) | |
10967 | return 0; | |
10968 | ||
3c67e977 VK |
10969 | msg = nl80211_drv_msg(drv, 0, NL80211_CMD_UPDATE_CONNECT_PARAMS); |
10970 | if (!msg) | |
10971 | goto fail; | |
10972 | ||
10973 | wpa_printf(MSG_DEBUG, "nl80211: Update connection params (ifindex=%d)", | |
10974 | drv->ifindex); | |
10975 | ||
10976 | if ((mask & WPA_DRV_UPDATE_ASSOC_IES) && params->wpa_ie) { | |
10977 | if (nla_put(msg, NL80211_ATTR_IE, params->wpa_ie_len, | |
10978 | params->wpa_ie)) | |
10979 | goto fail; | |
10980 | wpa_hexdump(MSG_DEBUG, " * IEs", params->wpa_ie, | |
10981 | params->wpa_ie_len); | |
10982 | } | |
10983 | ||
10984 | if (mask & WPA_DRV_UPDATE_AUTH_TYPE) { | |
10985 | type = get_nl_auth_type(params->auth_alg); | |
10986 | if (type == NL80211_AUTHTYPE_MAX || | |
10987 | nla_put_u32(msg, NL80211_ATTR_AUTH_TYPE, type)) | |
10988 | goto fail; | |
10989 | wpa_printf(MSG_DEBUG, " * Auth Type %d", type); | |
10990 | } | |
10991 | ||
10992 | if ((mask & WPA_DRV_UPDATE_FILS_ERP_INFO) && | |
10993 | nl80211_put_fils_connect_params(drv, params, msg)) | |
10994 | goto fail; | |
10995 | ||
10996 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); | |
10997 | msg = NULL; | |
10998 | if (ret) | |
10999 | wpa_dbg(drv->ctx, MSG_DEBUG, | |
11000 | "nl80211: Update connect params command failed: ret=%d (%s)", | |
11001 | ret, strerror(-ret)); | |
11002 | ||
11003 | fail: | |
11004 | nlmsg_free(msg); | |
11005 | return ret; | |
11006 | } | |
11007 | ||
11008 | ||
ba71cb82 SD |
11009 | static int nl80211_send_external_auth_status(void *priv, |
11010 | struct external_auth *params) | |
11011 | { | |
11012 | struct i802_bss *bss = priv; | |
11013 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
11014 | struct nl_msg *msg = NULL; | |
11015 | int ret = -1; | |
11016 | ||
236e793e SD |
11017 | /* External auth command/status is intended for drivers that implement |
11018 | * intenral SME but want to offload authentication processing (e.g., | |
11019 | * SAE) to hostapd/wpa_supplicant. Do nott send the status to drivers | |
11020 | * which do not support AP SME or use wpa_supplicant/hostapd SME. | |
11021 | */ | |
2552a373 | 11022 | if ((is_ap_interface(drv->nlmode) && !bss->drv->device_ap_sme) || |
236e793e SD |
11023 | (drv->capa.flags & WPA_DRIVER_FLAGS_SME)) |
11024 | return -1; | |
11025 | ||
ba71cb82 SD |
11026 | wpa_dbg(drv->ctx, MSG_DEBUG, |
11027 | "nl80211: External auth status: %u", params->status); | |
11028 | ||
11029 | msg = nl80211_drv_msg(drv, 0, NL80211_CMD_EXTERNAL_AUTH); | |
11030 | if (!msg || | |
11031 | nla_put_u16(msg, NL80211_ATTR_STATUS_CODE, params->status) || | |
dd1a8cef | 11032 | (params->ssid && params->ssid_len && |
236e793e SD |
11033 | nla_put(msg, NL80211_ATTR_SSID, params->ssid_len, params->ssid)) || |
11034 | (params->pmkid && | |
11035 | nla_put(msg, NL80211_ATTR_PMKID, PMKID_LEN, params->pmkid)) || | |
dd1a8cef JM |
11036 | (params->bssid && |
11037 | nla_put(msg, NL80211_ATTR_BSSID, ETH_ALEN, params->bssid))) | |
ba71cb82 SD |
11038 | goto fail; |
11039 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); | |
11040 | msg = NULL; | |
11041 | if (ret) { | |
11042 | wpa_printf(MSG_DEBUG, | |
11043 | "nl80211: External Auth status update failed: ret=%d (%s)", | |
11044 | ret, strerror(-ret)); | |
11045 | goto fail; | |
11046 | } | |
11047 | fail: | |
11048 | nlmsg_free(msg); | |
11049 | return ret; | |
11050 | } | |
11051 | ||
11052 | ||
5abc7823 VN |
11053 | static int nl80211_set_4addr_mode(void *priv, const char *bridge_ifname, |
11054 | int val) | |
11055 | { | |
11056 | struct i802_bss *bss = priv; | |
11057 | struct wpa_driver_nl80211_data *drv = bss->drv; | |
11058 | struct nl_msg *msg; | |
11059 | int ret = -ENOBUFS; | |
11060 | ||
11061 | wpa_printf(MSG_DEBUG, "nl80211: %s 4addr mode (bridge_ifname: %s)", | |
11062 | val ? "Enable" : "Disable", bridge_ifname); | |
11063 | ||
11064 | msg = nl80211_cmd_msg(drv->first_bss, 0, NL80211_CMD_SET_INTERFACE); | |
11065 | if (!msg || nla_put_u8(msg, NL80211_ATTR_4ADDR, val)) | |
11066 | goto fail; | |
11067 | ||
11068 | if (bridge_ifname[0] && bss->added_if_into_bridge && !val) { | |
11069 | if (linux_br_del_if(drv->global->ioctl_sock, | |
11070 | bridge_ifname, bss->ifname)) { | |
11071 | wpa_printf(MSG_ERROR, | |
11072 | "nl80211: Failed to remove interface %s from bridge %s", | |
11073 | bss->ifname, bridge_ifname); | |
11074 | return -1; | |
11075 | } | |
11076 | bss->added_if_into_bridge = 0; | |
11077 | } | |
11078 | ||
11079 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); | |
11080 | msg = NULL; | |
11081 | if (!ret) { | |
11082 | if (bridge_ifname[0] && val && | |
11083 | i802_check_bridge(drv, bss, bridge_ifname, bss->ifname) < 0) | |
11084 | return -1; | |
11085 | return 0; | |
11086 | } | |
11087 | ||
11088 | fail: | |
11089 | nlmsg_free(msg); | |
11090 | wpa_printf(MSG_ERROR, "nl80211: Failed to enable/disable 4addr"); | |
11091 | ||
11092 | return ret; | |
11093 | } | |
11094 | ||
11095 | ||
3f5285e8 JM |
11096 | const struct wpa_driver_ops wpa_driver_nl80211_ops = { |
11097 | .name = "nl80211", | |
11098 | .desc = "Linux nl80211/cfg80211", | |
11099 | .get_bssid = wpa_driver_nl80211_get_bssid, | |
11100 | .get_ssid = wpa_driver_nl80211_get_ssid, | |
9ebce9c5 JM |
11101 | .set_key = driver_nl80211_set_key, |
11102 | .scan2 = driver_nl80211_scan2, | |
d21c63b9 LC |
11103 | .sched_scan = wpa_driver_nl80211_sched_scan, |
11104 | .stop_sched_scan = wpa_driver_nl80211_stop_sched_scan, | |
3f5285e8 | 11105 | .get_scan_results2 = wpa_driver_nl80211_get_scan_results, |
4f30addb | 11106 | .abort_scan = wpa_driver_nl80211_abort_scan, |
9ebce9c5 JM |
11107 | .deauthenticate = driver_nl80211_deauthenticate, |
11108 | .authenticate = driver_nl80211_authenticate, | |
3f5285e8 | 11109 | .associate = wpa_driver_nl80211_associate, |
f2ed8023 JM |
11110 | .global_init = nl80211_global_init, |
11111 | .global_deinit = nl80211_global_deinit, | |
11112 | .init2 = wpa_driver_nl80211_init, | |
9ebce9c5 | 11113 | .deinit = driver_nl80211_deinit, |
3f5285e8 JM |
11114 | .get_capa = wpa_driver_nl80211_get_capa, |
11115 | .set_operstate = wpa_driver_nl80211_set_operstate, | |
01652550 | 11116 | .set_supp_port = wpa_driver_nl80211_set_supp_port, |
6d158490 | 11117 | .set_country = wpa_driver_nl80211_set_country, |
f0793bf1 | 11118 | .get_country = wpa_driver_nl80211_get_country, |
19c3b566 | 11119 | .set_ap = wpa_driver_nl80211_set_ap, |
3c4ca363 | 11120 | .set_acl = wpa_driver_nl80211_set_acl, |
22a7c9d7 | 11121 | .if_add = wpa_driver_nl80211_if_add, |
9ebce9c5 JM |
11122 | .if_remove = driver_nl80211_if_remove, |
11123 | .send_mlme = driver_nl80211_send_mlme, | |
0fafeb54 | 11124 | .get_hw_feature_data = nl80211_get_hw_feature_data, |
0f4e8b4f | 11125 | .sta_add = wpa_driver_nl80211_sta_add, |
9ebce9c5 | 11126 | .sta_remove = driver_nl80211_sta_remove, |
db149ac9 | 11127 | .hapd_send_eapol = wpa_driver_nl80211_hapd_send_eapol, |
a8d6ffa4 | 11128 | .sta_set_flags = wpa_driver_nl80211_sta_set_flags, |
1d6f6385 | 11129 | .sta_set_airtime_weight = driver_nl80211_sta_set_airtime_weight, |
c5121837 | 11130 | .hapd_init = i802_init, |
c5121837 | 11131 | .hapd_deinit = i802_deinit, |
f7b3920c | 11132 | .set_wds_sta = i802_set_wds_sta, |
c5121837 JM |
11133 | .get_seqnum = i802_get_seqnum, |
11134 | .flush = i802_flush, | |
c5121837 JM |
11135 | .get_inact_sec = i802_get_inact_sec, |
11136 | .sta_clear_stats = i802_sta_clear_stats, | |
c5121837 JM |
11137 | .set_rts = i802_set_rts, |
11138 | .set_frag = i802_set_frag, | |
c5121837 | 11139 | .set_tx_queue_params = i802_set_tx_queue_params, |
9ebce9c5 | 11140 | .set_sta_vlan = driver_nl80211_set_sta_vlan, |
ee7ab173 JB |
11141 | .sta_deauth = i802_sta_deauth, |
11142 | .sta_disassoc = i802_sta_disassoc, | |
9ebce9c5 | 11143 | .read_sta_data = driver_nl80211_read_sta_data, |
e3802622 | 11144 | .set_freq = i802_set_freq, |
9ebce9c5 | 11145 | .send_action = driver_nl80211_send_action, |
5dfca53f | 11146 | .send_action_cancel_wait = wpa_driver_nl80211_send_action_cancel_wait, |
55777702 JM |
11147 | .remain_on_channel = wpa_driver_nl80211_remain_on_channel, |
11148 | .cancel_remain_on_channel = | |
11149 | wpa_driver_nl80211_cancel_remain_on_channel, | |
9ebce9c5 | 11150 | .probe_req_report = driver_nl80211_probe_req_report, |
af473088 | 11151 | .deinit_ap = wpa_driver_nl80211_deinit_ap, |
3c29244e | 11152 | .deinit_p2p_cli = wpa_driver_nl80211_deinit_p2p_cli, |
207ef3fb | 11153 | .resume = wpa_driver_nl80211_resume, |
b625473c | 11154 | .signal_monitor = nl80211_signal_monitor, |
1c5c7273 | 11155 | .signal_poll = nl80211_signal_poll, |
7f00dc6e | 11156 | .channel_info = nl80211_channel_info, |
b91ab76e | 11157 | .send_frame = nl80211_send_frame, |
c55f774d | 11158 | .set_param = nl80211_set_param, |
6859f1cb | 11159 | .get_radio_name = nl80211_get_radio_name, |
a6efc65d JM |
11160 | .add_pmkid = nl80211_add_pmkid, |
11161 | .remove_pmkid = nl80211_remove_pmkid, | |
11162 | .flush_pmkid = nl80211_flush_pmkid, | |
b14a210c | 11163 | .set_rekey_info = nl80211_set_rekey_info, |
bcf24348 | 11164 | .poll_client = nl80211_poll_client, |
29f338af | 11165 | .set_p2p_powersave = nl80211_set_p2p_powersave, |
f90e9c1c | 11166 | .start_dfs_cac = nl80211_start_radar_detection, |
695c7038 | 11167 | .stop_ap = wpa_driver_nl80211_stop_ap, |
03ea1786 AN |
11168 | #ifdef CONFIG_TDLS |
11169 | .send_tdls_mgmt = nl80211_send_tdls_mgmt, | |
11170 | .tdls_oper = nl80211_tdls_oper, | |
72b2605f AN |
11171 | .tdls_enable_channel_switch = nl80211_tdls_enable_channel_switch, |
11172 | .tdls_disable_channel_switch = nl80211_tdls_disable_channel_switch, | |
03ea1786 | 11173 | #endif /* CONFIG_TDLS */ |
6a1ce395 | 11174 | .update_ft_ies = wpa_driver_nl80211_update_ft_ies, |
d1836e23 | 11175 | .update_dh_ie = nl80211_update_dh_ie, |
597b94f5 | 11176 | .get_mac_addr = wpa_driver_nl80211_get_macaddr, |
0185007c | 11177 | .get_survey = wpa_driver_nl80211_get_survey, |
a771c07d | 11178 | .status = wpa_driver_nl80211_status, |
1c4ffa87 | 11179 | .switch_channel = nl80211_switch_channel, |
0de38036 JM |
11180 | #ifdef ANDROID_P2P |
11181 | .set_noa = wpa_driver_set_p2p_noa, | |
11182 | .get_noa = wpa_driver_get_p2p_noa, | |
11183 | .set_ap_wps_ie = wpa_driver_set_ap_wps_p2p_ie, | |
11184 | #endif /* ANDROID_P2P */ | |
5e2c3490 | 11185 | #ifdef ANDROID |
ded14ce9 | 11186 | #ifndef ANDROID_LIB_STUB |
5e2c3490 | 11187 | .driver_cmd = wpa_driver_nl80211_driver_cmd, |
ded14ce9 | 11188 | #endif /* !ANDROID_LIB_STUB */ |
5e2c3490 | 11189 | #endif /* ANDROID */ |
adef8948 | 11190 | .vendor_cmd = nl80211_vendor_cmd, |
049105b4 | 11191 | .set_qos_map = nl80211_set_qos_map, |
e4fa8b12 | 11192 | .set_wowlan = nl80211_set_wowlan, |
fee354c7 | 11193 | .set_mac_addr = nl80211_set_mac_addr, |
6c1664f6 BC |
11194 | #ifdef CONFIG_MESH |
11195 | .init_mesh = wpa_driver_nl80211_init_mesh, | |
11196 | .join_mesh = wpa_driver_nl80211_join_mesh, | |
11197 | .leave_mesh = wpa_driver_nl80211_leave_mesh, | |
c36109e4 | 11198 | .probe_mesh_link = nl80211_probe_mesh_link, |
6c1664f6 | 11199 | #endif /* CONFIG_MESH */ |
71103bed KP |
11200 | .br_add_ip_neigh = wpa_driver_br_add_ip_neigh, |
11201 | .br_delete_ip_neigh = wpa_driver_br_delete_ip_neigh, | |
73d2294f | 11202 | .br_port_set_attr = wpa_driver_br_port_set_attr, |
7565752d | 11203 | .br_set_net_param = wpa_driver_br_set_net_param, |
dfa87878 MB |
11204 | .add_tx_ts = nl80211_add_ts, |
11205 | .del_tx_ts = nl80211_del_ts, | |
45e3fc72 | 11206 | .get_ifindex = nl80211_get_ifindex, |
b658547d | 11207 | #ifdef CONFIG_DRIVER_NL80211_QCA |
9607a1ae | 11208 | .roaming = nl80211_roaming, |
d98038bb | 11209 | .disable_fils = nl80211_disable_fils, |
16689c7c | 11210 | .do_acs = wpa_driver_do_acs, |
844dfeb8 | 11211 | .set_band = nl80211_set_band, |
98342208 | 11212 | .get_pref_freq_list = nl80211_get_pref_freq_list, |
7c813acf | 11213 | .set_prob_oper_freq = nl80211_set_prob_oper_freq, |
a6f5b193 PX |
11214 | .p2p_lo_start = nl80211_p2p_lo_start, |
11215 | .p2p_lo_stop = nl80211_p2p_lo_stop, | |
cc9985d1 | 11216 | .set_default_scan_ies = nl80211_set_default_scan_ies, |
2e4e4fb7 | 11217 | .set_tdls_mode = nl80211_set_tdls_mode, |
3ab48492 KV |
11218 | #ifdef CONFIG_MBO |
11219 | .get_bss_transition_status = nl80211_get_bss_transition_status, | |
178553b7 | 11220 | .ignore_assoc_disallow = nl80211_ignore_assoc_disallow, |
3ab48492 | 11221 | #endif /* CONFIG_MBO */ |
b04854ce | 11222 | .set_bssid_blacklist = nl80211_set_bssid_blacklist, |
b658547d | 11223 | #endif /* CONFIG_DRIVER_NL80211_QCA */ |
6922d440 | 11224 | .configure_data_frame_filters = nl80211_configure_data_frame_filters, |
cc9a2575 | 11225 | .get_ext_capab = nl80211_get_ext_capab, |
3c67e977 | 11226 | .update_connect_params = nl80211_update_connection_params, |
ba71cb82 | 11227 | .send_external_auth_status = nl80211_send_external_auth_status, |
5abc7823 | 11228 | .set_4addr_mode = nl80211_set_4addr_mode, |
3f5285e8 | 11229 | }; |